Ejemplo n.º 1
0
        public void DeserializeNestedComposite()
        {
            LLSD llsdNested = LLSDParser.DeserializeBinary(binaryNested);

            Assert.AreEqual(LLSDType.Array, llsdNested.Type);
            LLSDArray llsdArray = (LLSDArray)llsdNested;

            Assert.AreEqual(3, llsdArray.Count);

            LLSDMap llsdMap = (LLSDMap)llsdArray[0];

            Assert.AreEqual(LLSDType.Map, llsdMap.Type);
            Assert.AreEqual(2, llsdMap.Count);

            LLSDArray llsdNestedArray = (LLSDArray)llsdMap["t0st"];

            Assert.AreEqual(LLSDType.Array, llsdNestedArray.Type);
            LLSDInteger llsdNestedIntOne = (LLSDInteger)llsdNestedArray[0];

            Assert.AreEqual(LLSDType.Integer, llsdNestedIntOne.Type);
            Assert.AreEqual(1, llsdNestedIntOne.AsInteger());
            LLSDInteger llsdNestedIntTwo = (LLSDInteger)llsdNestedArray[1];

            Assert.AreEqual(LLSDType.Integer, llsdNestedIntTwo.Type);
            Assert.AreEqual(2, llsdNestedIntTwo.AsInteger());

            LLSDString llsdString = (LLSDString)llsdMap["test"];

            Assert.AreEqual(LLSDType.String, llsdString.Type);
            Assert.AreEqual("what", llsdString.AsString());

            LLSDInteger llsdIntOne = (LLSDInteger)llsdArray[1];

            Assert.AreEqual(LLSDType.Integer, llsdIntOne.Type);
            Assert.AreEqual(124, llsdIntOne.AsInteger());
            LLSDInteger llsdIntTwo = (LLSDInteger)llsdArray[2];

            Assert.AreEqual(LLSDType.Integer, llsdIntTwo.Type);
            Assert.AreEqual(987, llsdIntTwo.AsInteger());
        }
Ejemplo n.º 2
0
        public void DeserializeStrings()
        {
            LLSD       theLLSD = null;
            LLSDArray  array   = null;
            LLSDString tempStr = null;

            String testLLSD = @"<?xml version='1.0' encoding='UTF-8'?>
            <llsd>
                <array>
                    <string>Kissling</string>
                    <string>Attack ships on fire off the shoulder of Orion</string>
                    <string>&lt; &gt; &amp; &apos; &quot;</string>
                    <string/>
                </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.String, array[0].Type);
            tempStr = (LLSDString)array[0];
            Assert.AreEqual("Kissling", tempStr.AsString());

            Assert.AreEqual(LLSDType.String, array[1].Type);
            tempStr = (LLSDString)array[1];
            Assert.AreEqual("Attack ships on fire off the shoulder of Orion", tempStr.AsString());

            Assert.AreEqual(LLSDType.String, array[2].Type);
            tempStr = (LLSDString)array[2];
            Assert.AreEqual("< > & \' \"", tempStr.AsString());

            Assert.AreEqual(LLSDType.String, array[3].Type);
            tempStr = (LLSDString)array[3];
            Assert.AreEqual("", tempStr.AsString());
        }
Ejemplo n.º 3
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());
        }