Пример #1
0
        public void DeserializeReals()
        {
            LLSD      theLLSD  = null;
            LLSDArray array    = null;
            LLSDReal  tempReal = null;

            String testLLSD = @"<?xml version='1.0' encoding='UTF-8'?>
            <llsd>
                <array>
                    <real>44.38898</real>
		            <real>nan</real>
		            <real>4</real>
                    <real>-13.333</real>
                    <real/>
                </array>
            </llsd>";

            //Deserialize the string
            byte[] bytes = Encoding.UTF8.GetBytes(testLLSD);
            theLLSD = LLSDParser.DeserializeXml(bytes);

            Assert.IsTrue(theLLSD is LLSDArray);
            array = (LLSDArray)theLLSD;

            Assert.AreEqual(LLSDType.Real, array[0].Type);
            tempReal = (LLSDReal)array[0];
            Assert.AreEqual(44.38898d, tempReal.AsReal());

            Assert.AreEqual(LLSDType.Real, array[1].Type);
            tempReal = (LLSDReal)array[1];
            Assert.AreEqual(Double.NaN, tempReal.AsReal());

            Assert.AreEqual(LLSDType.Real, array[2].Type);
            tempReal = (LLSDReal)array[2];
            Assert.AreEqual(4.0d, tempReal.AsReal());

            Assert.AreEqual(LLSDType.Real, array[3].Type);
            tempReal = (LLSDReal)array[3];
            Assert.AreEqual(-13.333d, tempReal.AsReal());

            Assert.AreEqual(LLSDType.Real, array[4].Type);
            tempReal = (LLSDReal)array[4];
            Assert.AreEqual(0d, tempReal.AsReal());
        }
Пример #2
0
        public void DeserializeLLSDSample()
        {
            LLSD       theLLSD  = null;
            LLSDMap    map      = null;
            LLSD       tempLLSD = null;
            LLSDUUID   tempUUID = null;
            LLSDString tempStr  = null;
            LLSDReal   tempReal = null;

            String testLLSD = @"<?xml version='1.0' encoding='UTF-8'?>
            <llsd>
                <map>
	                <key>region_id</key>
	                <uuid>67153d5b-3659-afb4-8510-adda2c034649</uuid>
	                <key>scale</key>
	                <string>one minute</string>
	                <key>simulator statistics</key>
	                <map>
		                <key>time dilation</key>
		                <real>0.9878624</real>
		                <key>sim fps</key>
		                <real>44.38898</real>
		                <key>agent updates per second</key>
		                <real>nan</real>
		                <key>total task count</key>
		                <real>4</real>
		                <key>active task count</key>
		                <real>0</real>
		                <key>pending uploads</key>
		                <real>0.0001096525</real>
	                </map>
                </map>
            </llsd>";

            //Deserialize the string
            byte[] bytes = Encoding.UTF8.GetBytes(testLLSD);
            theLLSD = LLSDParser.DeserializeXml(bytes);

            //Confirm the contents
            Assert.IsNotNull(theLLSD);
            Assert.IsTrue(theLLSD is LLSDMap);
            Assert.IsTrue(theLLSD.Type == LLSDType.Map);
            map = (LLSDMap)theLLSD;

            tempLLSD = map["region_id"];
            Assert.IsNotNull(tempLLSD);
            Assert.IsTrue(tempLLSD is LLSDUUID);
            Assert.IsTrue(tempLLSD.Type == LLSDType.UUID);
            tempUUID = (LLSDUUID)tempLLSD;
            Assert.AreEqual(new LLUUID("67153d5b-3659-afb4-8510-adda2c034649"), tempUUID.AsUUID());

            tempLLSD = map["scale"];
            Assert.IsNotNull(tempLLSD);
            Assert.IsTrue(tempLLSD is LLSDString);
            Assert.IsTrue(tempLLSD.Type == LLSDType.String);
            tempStr = (LLSDString)tempLLSD;
            Assert.AreEqual("one minute", tempStr.AsString());

            tempLLSD = map["simulator statistics"];
            Assert.IsNotNull(tempLLSD);
            Assert.IsTrue(tempLLSD is LLSDMap);
            Assert.IsTrue(tempLLSD.Type == LLSDType.Map);
            map = (LLSDMap)tempLLSD;

            tempLLSD = map["time dilation"];
            Assert.IsNotNull(tempLLSD);
            Assert.IsTrue(tempLLSD is LLSDReal);
            Assert.IsTrue(tempLLSD.Type == LLSDType.Real);
            tempReal = (LLSDReal)tempLLSD;

            Assert.AreEqual(0.9878624d, tempReal.AsReal());
            //TODO - figure out any relevant rounding variability for 64 bit reals
            tempLLSD = map["sim fps"];
            Assert.IsNotNull(tempLLSD);
            Assert.IsTrue(tempLLSD is LLSDReal);
            Assert.IsTrue(tempLLSD.Type == LLSDType.Real);
            tempReal = (LLSDReal)tempLLSD;
            Assert.AreEqual(44.38898d, tempReal.AsReal());

            tempLLSD = map["agent updates per second"];
            Assert.IsNotNull(tempLLSD);
            Assert.IsTrue(tempLLSD is LLSDReal);
            Assert.IsTrue(tempLLSD.Type == LLSDType.Real);
            tempReal = (LLSDReal)tempLLSD;
            Assert.AreEqual(Double.NaN, tempLLSD.AsReal());

            tempLLSD = map["total task count"];
            Assert.IsNotNull(tempLLSD);
            Assert.IsTrue(tempLLSD is LLSDReal);
            Assert.IsTrue(tempLLSD.Type == LLSDType.Real);
            tempReal = (LLSDReal)tempLLSD;
            Assert.AreEqual(4.0d, tempReal.AsReal());

            tempLLSD = map["active task count"];
            Assert.IsNotNull(tempLLSD);
            Assert.IsTrue(tempLLSD is LLSDReal);
            Assert.IsTrue(tempLLSD.Type == LLSDType.Real);
            tempReal = (LLSDReal)tempLLSD;
            Assert.AreEqual(0.0d, tempReal.AsReal());

            tempLLSD = map["pending uploads"];
            Assert.IsNotNull(tempLLSD);
            Assert.IsTrue(tempLLSD is LLSDReal);
            Assert.IsTrue(tempLLSD.Type == LLSDType.Real);
            tempReal = (LLSDReal)tempLLSD;
            Assert.AreEqual(0.0001096525d, tempReal.AsReal());
        }