public void DeserializeReals() { OSD theSD = null; OSDArray array = null; OSDReal tempReal = null; String testSD = @"<?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(testSD); theSD = OSDParser.DeserializeLLSDXml(bytes); Assert.IsTrue(theSD is OSDArray); array = (OSDArray)theSD; Assert.AreEqual(OSDType.Real, array[0].Type); tempReal = (OSDReal)array[0]; Assert.AreEqual(44.38898d, tempReal.AsReal()); Assert.AreEqual(OSDType.Real, array[1].Type); tempReal = (OSDReal)array[1]; Assert.AreEqual(Double.NaN, tempReal.AsReal()); Assert.AreEqual(OSDType.Real, array[2].Type); tempReal = (OSDReal)array[2]; Assert.AreEqual(4.0d, tempReal.AsReal()); Assert.AreEqual(OSDType.Real, array[3].Type); tempReal = (OSDReal)array[3]; Assert.AreEqual(-13.333d, tempReal.AsReal()); Assert.AreEqual(OSDType.Real, array[4].Type); tempReal = (OSDReal)array[4]; Assert.AreEqual(0d, tempReal.AsReal()); }
public void DeserializeLLSDSample() { OSD theSD = null; OSDMap map = null; OSD tempSD = null; OSDUUID tempUUID = null; OSDString tempStr = null; OSDReal tempReal = null; String testSD = @"<?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(testSD); theSD = OSDParser.DeserializeLLSDXml(bytes); //Confirm the contents Assert.IsNotNull(theSD); Assert.IsTrue(theSD is OSDMap); Assert.IsTrue(theSD.Type == OSDType.Map); map = (OSDMap)theSD; tempSD = map["region_id"]; Assert.IsNotNull(tempSD); Assert.IsTrue(tempSD is OSDUUID); Assert.IsTrue(tempSD.Type == OSDType.UUID); tempUUID = (OSDUUID)tempSD; Assert.AreEqual(new UUID("67153d5b-3659-afb4-8510-adda2c034649"), tempUUID.AsUUID()); tempSD = map["scale"]; Assert.IsNotNull(tempSD); Assert.IsTrue(tempSD is OSDString); Assert.IsTrue(tempSD.Type == OSDType.String); tempStr = (OSDString)tempSD; Assert.AreEqual("one minute", tempStr.AsString()); tempSD = map["simulator statistics"]; Assert.IsNotNull(tempSD); Assert.IsTrue(tempSD is OSDMap); Assert.IsTrue(tempSD.Type == OSDType.Map); map = (OSDMap)tempSD; tempSD = map["time dilation"]; Assert.IsNotNull(tempSD); Assert.IsTrue(tempSD is OSDReal); Assert.IsTrue(tempSD.Type == OSDType.Real); tempReal = (OSDReal)tempSD; Assert.AreEqual(0.9878624d, tempReal.AsReal()); //TODO - figure out any relevant rounding variability for 64 bit reals tempSD = map["sim fps"]; Assert.IsNotNull(tempSD); Assert.IsTrue(tempSD is OSDReal); Assert.IsTrue(tempSD.Type == OSDType.Real); tempReal = (OSDReal)tempSD; Assert.AreEqual(44.38898d, tempReal.AsReal()); tempSD = map["agent updates per second"]; Assert.IsNotNull(tempSD); Assert.IsTrue(tempSD is OSDReal); Assert.IsTrue(tempSD.Type == OSDType.Real); tempReal = (OSDReal)tempSD; Assert.AreEqual(Double.NaN, tempSD.AsReal()); tempSD = map["total task count"]; Assert.IsNotNull(tempSD); Assert.IsTrue(tempSD is OSDReal); Assert.IsTrue(tempSD.Type == OSDType.Real); tempReal = (OSDReal)tempSD; Assert.AreEqual(4.0d, tempReal.AsReal()); tempSD = map["active task count"]; Assert.IsNotNull(tempSD); Assert.IsTrue(tempSD is OSDReal); Assert.IsTrue(tempSD.Type == OSDType.Real); tempReal = (OSDReal)tempSD; Assert.AreEqual(0.0d, tempReal.AsReal()); tempSD = map["pending uploads"]; Assert.IsNotNull(tempSD); Assert.IsTrue(tempSD is OSDReal); Assert.IsTrue(tempSD.Type == OSDType.Real); tempReal = (OSDReal)tempSD; Assert.AreEqual(0.0001096525d, tempReal.AsReal()); }