public void SerializeBinary() { byte[] binary = { 0x0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0b, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; LLSD llsdBinary = LLSD.FromBinary(binary); string sBinarySerialized = LLSDParser.SerializeNotation(llsdBinary); LLSD llsdBinaryDS = LLSDParser.DeserializeNotation(sBinarySerialized); Assert.AreEqual(LLSDType.Binary, llsdBinaryDS.Type); Assert.AreEqual(binary, llsdBinaryDS.AsBinary()); }
public void DeserializeUUID() { LLSD llsdAUUID = LLSDParser.DeserializeBinary(binaryAUUID); Assert.AreEqual(LLSDType.UUID, llsdAUUID.Type); Assert.AreEqual("97f4aeca-88a1-42a1-b385-b97b18abb255", llsdAUUID.AsString()); LLSD llsdZeroUUID = LLSDParser.DeserializeBinary(binaryZeroUUID); Assert.AreEqual(LLSDType.UUID, llsdZeroUUID.Type); Assert.AreEqual("00000000-0000-0000-0000-000000000000", llsdZeroUUID.AsString()); }
public void SerializeBool() { LLSD llsdTrue = LLSD.FromBoolean(true); byte[] binaryTrueSerialized = LLSDParser.SerializeBinary(llsdTrue); Assert.AreEqual(binaryTrue, binaryTrueSerialized); LLSD llsdFalse = LLSD.FromBoolean(false); byte[] binaryFalseSerialized = LLSDParser.SerializeBinary(llsdFalse); Assert.AreEqual(binaryFalse, binaryFalseSerialized); }
public void SerializeInteger() { LLSD llsdZeroInt = LLSD.FromInteger(0); byte[] binaryZeroIntSerialized = LLSDParser.SerializeBinary(llsdZeroInt); Assert.AreEqual(binaryZeroInt, binaryZeroIntSerialized); LLSD llsdAnInt = LLSD.FromInteger(1234843); byte[] binaryAnIntSerialized = LLSDParser.SerializeBinary(llsdAnInt); Assert.AreEqual(binaryAnInt, binaryAnIntSerialized); }
public void SerializeUUID() { LLSD llsdAUUID = LLSD.FromUUID(new LLUUID("97f4aeca-88a1-42a1-b385-b97b18abb255")); byte[] binaryAUUIDSerialized = LLSDParser.SerializeBinary(llsdAUUID); Assert.AreEqual(binaryAUUID, binaryAUUIDSerialized); LLSD llsdZeroUUID = LLSD.FromUUID(new LLUUID("00000000-0000-0000-0000-000000000000")); byte[] binaryZeroUUIDSerialized = LLSDParser.SerializeBinary(llsdZeroUUID); Assert.AreEqual(binaryZeroUUID, binaryZeroUUIDSerialized); }
public void DeserializeBool() { LLSD llsdTrue = LLSDParser.DeserializeBinary(binaryTrue); Assert.AreEqual(LLSDType.Boolean, llsdTrue.Type); Assert.AreEqual(true, llsdTrue.AsBoolean()); LLSD llsdFalse = LLSDParser.DeserializeBinary(binaryFalse); Assert.AreEqual(LLSDType.Boolean, llsdFalse.Type); Assert.AreEqual(false, llsdFalse.AsBoolean()); }
private void Client_DownloadStringCompleted(object sender, CapsBase.DownloadStringCompletedEventArgs e) { if (OnComplete != null && !e.Cancelled) { if (e.Error == null) { LLSD result = LLSDParser.DeserializeXml(e.Result); try { OnComplete(this, result, e.Error); } catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, ex); } } else { // Some error occurred, try to figure out what happened HttpStatusCode code = HttpStatusCode.OK; if (e.Error is WebException && ((WebException)e.Error).Response != null) { code = ((HttpWebResponse)((WebException)e.Error).Response).StatusCode; } if (code == HttpStatusCode.BadGateway) { // This is not good (server) protocol design, but it's normal. // The CAPS server is a proxy that connects to a Squid // cache which will time out periodically. The CAPS server // interprets this as a generic error and returns a 502 to us // that we ignore StartRequest(_PostData, _ContentType); } else if (code != HttpStatusCode.OK) { // Status code was set to something unknown, this is a failure Logger.DebugLog(String.Format("Caps error at {0}: {1}", _Client.Location, code)); try { OnComplete(this, null, e.Error); } catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, ex); } } else { // Status code was not set, some other error occurred. This is a failure Logger.DebugLog(String.Format("Caps error at {0}: {1}", _Client.Location, e.Error.Message)); try { OnComplete(this, null, e.Error); } catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, ex); } } } } else if (e.Cancelled) { Logger.DebugLog("Capability action at " + _Client.Location + " cancelled"); } }
public void DeserializeInteger() { LLSD llsdZeroInteger = LLSDParser.DeserializeBinary(binaryZeroInt); Assert.AreEqual(LLSDType.Integer, llsdZeroInteger.Type); Assert.AreEqual(0, llsdZeroInteger.AsInteger()); LLSD llsdAnInteger = LLSDParser.DeserializeBinary(binaryAnInt); Assert.AreEqual(LLSDType.Integer, llsdAnInteger.Type); Assert.AreEqual(1234843, llsdAnInteger.AsInteger()); }
public void HelperFunctions() { string s = "this is a teststring so that we can find something from the beginning"; byte[] sBinary = Encoding.ASCII.GetBytes(s); MemoryStream stream = new MemoryStream(sBinary); byte[] sFirstFind = Encoding.ASCII.GetBytes("this"); stream.Position = 0L; bool result = LLSDParser.FindByteArray(stream, sFirstFind); Assert.AreEqual(true, result); Assert.AreEqual(4L, stream.Position); stream.Position = 10L; byte[] sSecondFind = Encoding.ASCII.GetBytes("teststring"); result = LLSDParser.FindByteArray(stream, sSecondFind); Assert.AreEqual(true, result); Assert.AreEqual(20L, stream.Position); stream.Position = 25L; byte[] sThirdNotFind = Encoding.ASCII.GetBytes("notfound"); result = LLSDParser.FindByteArray(stream, sThirdNotFind); Assert.AreEqual(false, result); Assert.AreEqual(25L, stream.Position); stream.Position = 60L; byte[] sFourthNotFound = Encoding.ASCII.GetBytes("beginningAndMore"); result = LLSDParser.FindByteArray(stream, sFourthNotFound); Assert.AreEqual(false, result); Assert.AreEqual(60L, stream.Position); byte[] sFrontWhiteSpace = Encoding.ASCII.GetBytes(" \t\t\n\rtest"); MemoryStream streamTwo = new MemoryStream(sFrontWhiteSpace); LLSDParser.SkipWhiteSpace(streamTwo); Assert.AreEqual(7L, streamTwo.Position); byte[] sMiddleWhiteSpace = Encoding.ASCII.GetBytes("test \t\t\n\rtest"); MemoryStream streamThree = new MemoryStream(sMiddleWhiteSpace); streamThree.Position = 4L; LLSDParser.SkipWhiteSpace(streamThree); Assert.AreEqual(9L, streamThree.Position); byte[] sNoWhiteSpace = Encoding.ASCII.GetBytes("testtesttest"); MemoryStream streamFour = new MemoryStream(sNoWhiteSpace); LLSDParser.SkipWhiteSpace(streamFour); Assert.AreEqual(0L, streamFour.Position); }
public void DeserializeURI() { string sUriOne = "l\"http://test.com/test test>\\\"/&yes\""; LLSD llsdOne = LLSDParser.DeserializeNotation(sUriOne); Assert.AreEqual(LLSDType.URI, llsdOne.Type); Assert.AreEqual("http://test.com/test test>\"/&yes", llsdOne.AsString()); string sUriTwo = "l\"test/test/test?test=1&toast=2\""; LLSD llsdTwo = LLSDParser.DeserializeNotation(sUriTwo); Assert.AreEqual(LLSDType.URI, llsdTwo.Type); Assert.AreEqual("test/test/test?test=1&toast=2", llsdTwo.AsString()); }
public void DeserializeUUID() { String uuidOne = "u97f4aeca-88a1-42a1-b385-b97b18abb255"; LLSD llsdOne = LLSDParser.DeserializeNotation(uuidOne); Assert.AreEqual(LLSDType.UUID, llsdOne.Type); Assert.AreEqual("97f4aeca-88a1-42a1-b385-b97b18abb255", llsdOne.AsString()); String uuidTwo = "u00000000-0000-0000-0000-000000000000"; LLSD llsdTwo = LLSDParser.DeserializeNotation(uuidTwo); Assert.AreEqual(LLSDType.UUID, llsdTwo.Type); Assert.AreEqual("00000000-0000-0000-0000-000000000000", llsdTwo.AsString()); }
public void DeserializeInteger() { string integerOne = "i12319423"; LLSD llsdOne = LLSDParser.DeserializeNotation(integerOne); Assert.AreEqual(LLSDType.Integer, llsdOne.Type); Assert.AreEqual(12319423, llsdOne.AsInteger()); string integerTwo = "i-489234"; LLSD llsdTwo = LLSDParser.DeserializeNotation(integerTwo); Assert.AreEqual(LLSDType.Integer, llsdTwo.Type); Assert.AreEqual(-489234, llsdTwo.AsInteger()); }
public void DeserializeUndef() { LLSD theLLSD = null; String testLLSD = @"<?xml version='1.0' encoding='UTF-8'?> <llsd> <undef/> </llsd>"; //Deserialize the string byte[] bytes = Encoding.UTF8.GetBytes(testLLSD); theLLSD = LLSDParser.DeserializeXml(bytes); Assert.IsTrue(theLLSD is LLSD); }
public void DeserializeArray() { string sArrayOne = "[]"; LLSDArray llsdArrayOne = (LLSDArray)LLSDParser.DeserializeNotation(sArrayOne); Assert.AreEqual(LLSDType.Array, llsdArrayOne.Type); Assert.AreEqual(0, llsdArrayOne.Count); string sArrayTwo = "[ i0 ]"; LLSDArray llsdArrayTwo = (LLSDArray)LLSDParser.DeserializeNotation(sArrayTwo); Assert.AreEqual(LLSDType.Array, llsdArrayTwo.Type); Assert.AreEqual(1, llsdArrayTwo.Count); LLSDInteger llsdIntOne = (LLSDInteger)llsdArrayTwo[0]; Assert.AreEqual(LLSDType.Integer, llsdIntOne.Type); Assert.AreEqual(0, llsdIntOne.AsInteger()); string sArrayThree = "[ i0, i1 ]"; LLSDArray llsdArrayThree = (LLSDArray)LLSDParser.DeserializeNotation(sArrayThree); Assert.AreEqual(LLSDType.Array, llsdArrayThree.Type); Assert.AreEqual(2, llsdArrayThree.Count); LLSDInteger llsdIntTwo = (LLSDInteger)llsdArrayThree[0]; Assert.AreEqual(LLSDType.Integer, llsdIntTwo.Type); Assert.AreEqual(0, llsdIntTwo.AsInteger()); LLSDInteger llsdIntThree = (LLSDInteger)llsdArrayThree[1]; Assert.AreEqual(LLSDType.Integer, llsdIntThree.Type); Assert.AreEqual(1, llsdIntThree.AsInteger()); string sArrayFour = " [ \"testtest\", \"aha\",t,f,i1, r1.2, [ i1] ] "; LLSDArray llsdArrayFour = (LLSDArray)LLSDParser.DeserializeNotation(sArrayFour); Assert.AreEqual(LLSDType.Array, llsdArrayFour.Type); Assert.AreEqual(7, llsdArrayFour.Count); Assert.AreEqual("testtest", llsdArrayFour[0].AsString()); Assert.AreEqual("aha", llsdArrayFour[1].AsString()); Assert.AreEqual(true, llsdArrayFour[2].AsBoolean()); Assert.AreEqual(false, llsdArrayFour[3].AsBoolean()); Assert.AreEqual(1, llsdArrayFour[4].AsInteger()); Assert.AreEqual(1.2d, llsdArrayFour[5].AsReal()); Assert.AreEqual(LLSDType.Array, llsdArrayFour[6].Type); LLSDArray llsdArrayFive = (LLSDArray)llsdArrayFour[6]; Assert.AreEqual(1, llsdArrayFive[0].AsInteger()); }
public void SerializeBoolean() { LLSD llsdTrue = LLSD.FromBoolean(true); string sTrue = LLSDParser.SerializeNotation(llsdTrue); LLSD llsdTrueDS = LLSDParser.DeserializeNotation(sTrue); Assert.AreEqual(LLSDType.Boolean, llsdTrueDS.Type); Assert.AreEqual(true, llsdTrueDS.AsBoolean()); LLSD llsdFalse = LLSD.FromBoolean(false); string sFalse = LLSDParser.SerializeNotation(llsdFalse); LLSD llsdFalseDS = LLSDParser.DeserializeNotation(sFalse); Assert.AreEqual(LLSDType.Boolean, llsdFalseDS.Type); Assert.AreEqual(false, llsdFalseDS.AsBoolean()); }
public void DeserializeString() { LLSD llsdEmptyString = LLSDParser.DeserializeBinary(binaryEmptyString); Assert.AreEqual(LLSDType.String, llsdEmptyString.Type); string contentEmptyString = ""; Assert.AreEqual(contentEmptyString, llsdEmptyString.AsString()); LLSD llsdLongString = LLSDParser.DeserializeBinary(binaryLongString); Assert.AreEqual(LLSDType.String, llsdLongString.Type); string contentLongString = "abcdefghijklmnopqrstuvwxyz01234567890"; Assert.AreEqual(contentLongString, llsdLongString.AsString()); }
public void SerializeUUID() { LLSD llsdOne = LLSD.FromUUID(new LLUUID("97f4aeca-88a1-42a1-b385-b97b18abb255")); string sOne = LLSDParser.SerializeNotation(llsdOne); LLSD llsdOneDS = LLSDParser.DeserializeNotation(sOne); Assert.AreEqual(LLSDType.UUID, llsdOneDS.Type); Assert.AreEqual("97f4aeca-88a1-42a1-b385-b97b18abb255", llsdOneDS.AsString()); LLSD llsdTwo = LLSD.FromUUID(new LLUUID("00000000-0000-0000-0000-000000000000")); string sTwo = LLSDParser.SerializeNotation(llsdTwo); LLSD llsdTwoDS = LLSDParser.DeserializeNotation(sTwo); Assert.AreEqual(LLSDType.UUID, llsdTwoDS.Type); Assert.AreEqual("00000000-0000-0000-0000-000000000000", llsdTwoDS.AsString()); }
public void SerializeInteger() { LLSD llsdOne = LLSD.FromInteger(12319423); string sOne = LLSDParser.SerializeNotation(llsdOne); LLSD llsdOneDS = LLSDParser.DeserializeNotation(sOne); Assert.AreEqual(LLSDType.Integer, llsdOneDS.Type); Assert.AreEqual(12319423, llsdOne.AsInteger()); LLSD llsdTwo = LLSD.FromInteger(-71892034); string sTwo = LLSDParser.SerializeNotation(llsdTwo); LLSD llsdTwoDS = LLSDParser.DeserializeNotation(sTwo); Assert.AreEqual(LLSDType.Integer, llsdTwoDS.Type); Assert.AreEqual(-71892034, llsdTwoDS.AsInteger()); }
public void SerializeNestedComposite() { LLSDArray llsdNested = new LLSDArray(); LLSDMap llsdMap = new LLSDMap(); LLSDArray llsdArray = new LLSDArray(); llsdArray.Add(LLSD.FromInteger(1)); llsdArray.Add(LLSD.FromInteger(2)); llsdMap["t0st"] = llsdArray; llsdMap["test"] = LLSD.FromString("what"); llsdNested.Add(llsdMap); llsdNested.Add(LLSD.FromInteger(124)); llsdNested.Add(LLSD.FromInteger(987)); byte[] binaryNestedSerialized = LLSDParser.SerializeBinary(llsdNested); // Because maps don't preserve order, we compare here to a deserialized value. LLSDArray llsdNestedDeserialized = (LLSDArray)LLSDParser.DeserializeBinary(binaryNestedSerialized); Assert.AreEqual(LLSDType.Array, llsdNestedDeserialized.Type); Assert.AreEqual(3, llsdNestedDeserialized.Count); LLSDMap llsdMapDeserialized = (LLSDMap)llsdNestedDeserialized[0]; Assert.AreEqual(LLSDType.Map, llsdMapDeserialized.Type); Assert.AreEqual(2, llsdMapDeserialized.Count); Assert.AreEqual(LLSDType.Array, llsdMapDeserialized["t0st"].Type); LLSDArray llsdNestedArray = (LLSDArray)llsdMapDeserialized["t0st"]; Assert.AreEqual(LLSDType.Array, llsdNestedArray.Type); Assert.AreEqual(2, llsdNestedArray.Count); Assert.AreEqual(LLSDType.Integer, llsdNestedArray[0].Type); Assert.AreEqual(1, llsdNestedArray[0].AsInteger()); Assert.AreEqual(LLSDType.Integer, llsdNestedArray[1].Type); Assert.AreEqual(2, llsdNestedArray[1].AsInteger()); Assert.AreEqual(LLSDType.String, llsdMapDeserialized["test"].Type); Assert.AreEqual("what", llsdMapDeserialized["test"].AsString()); Assert.AreEqual(LLSDType.Integer, llsdNestedDeserialized[1].Type); Assert.AreEqual(124, llsdNestedDeserialized[1].AsInteger()); Assert.AreEqual(LLSDType.Integer, llsdNestedDeserialized[2].Type); Assert.AreEqual(987, llsdNestedDeserialized[2].AsInteger()); }
public void SerializeReal() { LLSD llsdOne = LLSD.FromReal(12987234.723847d); string sOne = LLSDParser.SerializeNotation(llsdOne); LLSD llsdOneDS = LLSDParser.DeserializeNotation(sOne); Assert.AreEqual(LLSDType.Real, llsdOneDS.Type); Assert.AreEqual(12987234.723847d, llsdOneDS.AsReal()); LLSD llsdTwo = LLSD.FromReal(-32347892.234234d); string sTwo = LLSDParser.SerializeNotation(llsdTwo); LLSD llsdTwoDS = LLSDParser.DeserializeNotation(sTwo); Assert.AreEqual(LLSDType.Real, llsdTwoDS.Type); Assert.AreEqual(-32347892.234234d, llsdTwoDS.AsReal()); /* The following two tests don't pass on mono 1.9, as * mono isnt able to parse its own Double.Max/MinValue. */ // LLSD llsdThree = LLSD.FromReal( Double.MaxValue ); // string sThree = LLSDParser.SerializeNotation( llsdThree ); // LLSD llsdThreeDS = LLSDParser.DeserializeNotation( sThree ); // Assert.AreEqual( LLSDType.Real, llsdThreeDS.Type ); // Assert.AreEqual( Double.MaxValue, llsdThreeDS.AsReal()); // // LLSD llsdFour = LLSD.FromReal( Double.MinValue ); // string sFour = LLSDParser.SerializeNotation( llsdFour ); // LLSD llsdFourDS = LLSDParser.DeserializeNotation( sFour ); // Assert.AreEqual( LLSDType.Real, llsdFourDS.Type ); // Assert.AreEqual( Double.MinValue, llsdFourDS.AsReal()); LLSD llsdFive = LLSD.FromReal(-1.1123123E+50d); string sFive = LLSDParser.SerializeNotation(llsdFive); LLSD llsdFiveDS = LLSDParser.DeserializeNotation(sFive); Assert.AreEqual(LLSDType.Real, llsdFiveDS.Type); Assert.AreEqual(-1.1123123E+50d, llsdFiveDS.AsReal()); LLSD llsdSix = LLSD.FromReal(2.0193899999999998204e-06); string sSix = LLSDParser.SerializeNotation(llsdSix); LLSD llsdSixDS = LLSDParser.DeserializeNotation(sSix); Assert.AreEqual(LLSDType.Real, llsdSixDS.Type); Assert.AreEqual(2.0193899999999998204e-06, llsdSixDS.AsReal()); }
public void SerializeURI() { Uri uriOne = new Uri("http://test.org/test test>\\\"/&yes\"", UriKind.RelativeOrAbsolute); LLSD llsdOne = LLSD.FromUri(uriOne); string sUriOne = LLSDParser.SerializeNotation(llsdOne); LLSD llsdOneDS = LLSDParser.DeserializeNotation(sUriOne); Assert.AreEqual(LLSDType.URI, llsdOneDS.Type); Assert.AreEqual(uriOne, llsdOneDS.AsUri()); Uri uriTwo = new Uri("test/test/near/the/end?test=1", UriKind.RelativeOrAbsolute); LLSD llsdTwo = LLSD.FromUri(uriTwo); string sUriTwo = LLSDParser.SerializeNotation(llsdTwo); LLSD llsdTwoDS = LLSDParser.DeserializeNotation(sUriTwo); Assert.AreEqual(LLSDType.URI, llsdTwoDS.Type); Assert.AreEqual(uriTwo, llsdTwoDS.AsUri()); }
public void DeserializeIntegers() { LLSD theLLSD = null; LLSDArray array = null; LLSDInteger tempInt = null; String testLLSD = @"<?xml version='1.0' encoding='UTF-8'?> <llsd> <array> <integer>2147483647</integer> <integer>-2147483648</integer> <integer>0</integer> <integer>013</integer> <integer/> </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.Integer, array[0].Type); tempInt = (LLSDInteger)array[0]; Assert.AreEqual(2147483647, tempInt.AsInteger()); Assert.AreEqual(LLSDType.Integer, array[1].Type); tempInt = (LLSDInteger)array[1]; Assert.AreEqual(-2147483648, tempInt.AsInteger()); Assert.AreEqual(LLSDType.Integer, array[2].Type); tempInt = (LLSDInteger)array[2]; Assert.AreEqual(0, tempInt.AsInteger()); Assert.AreEqual(LLSDType.Integer, array[3].Type); tempInt = (LLSDInteger)array[3]; Assert.AreEqual(13, tempInt.AsInteger()); Assert.AreEqual(LLSDType.Integer, array[4].Type); tempInt = (LLSDInteger)array[4]; Assert.AreEqual(0, tempInt.AsInteger()); }
public void DeserializeBoolean() { LLSD theLLSD = null; LLSDArray array = null; LLSDBoolean tempBool = null; String testLLSD = @"<?xml version='1.0' encoding='UTF-8'?> <llsd> <array> <boolean>1</boolean> <boolean>true</boolean> <boolean>0</boolean> <boolean>false</boolean> <boolean/> </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.Boolean, array[0].Type); tempBool = (LLSDBoolean)array[0]; Assert.AreEqual(true, tempBool.AsBoolean()); Assert.AreEqual(LLSDType.Boolean, array[1].Type); tempBool = (LLSDBoolean)array[1]; Assert.AreEqual(true, tempBool.AsBoolean()); Assert.AreEqual(LLSDType.Boolean, array[2].Type); tempBool = (LLSDBoolean)array[2]; Assert.AreEqual(false, tempBool.AsBoolean()); Assert.AreEqual(LLSDType.Boolean, array[3].Type); tempBool = (LLSDBoolean)array[3]; Assert.AreEqual(false, tempBool.AsBoolean()); Assert.AreEqual(LLSDType.Boolean, array[4].Type); tempBool = (LLSDBoolean)array[4]; Assert.AreEqual(false, tempBool.AsBoolean()); }
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()); }
public void Start(Simian server) { this.server = server; LLSD llsd; try { XmlTextReader reader = new XmlTextReader(File.OpenRead(server.DataDir + "simiandata.xml")); llsd = LLSDParser.DeserializeXml(reader); reader.Close(); } catch (FileNotFoundException) { return; } catch (Exception ex) { Logger.Log("Failed to load saved data: " + ex.Message, Helpers.LogLevel.Error); return; } if (llsd is LLSDMap) { LLSDMap dictionary = (LLSDMap)llsd; for (int i = 0; i < server.PersistentExtensions.Count; i++) { IPersistable persistable = server.PersistentExtensions[i]; LLSD savedData; if (dictionary.TryGetValue(persistable.ToString(), out savedData)) { Logger.DebugLog("Loading saved data for " + persistable.ToString()); persistable.Deserialize(savedData); } else { Logger.DebugLog("No saved data found for " + persistable.ToString()); } } } }
public void SerializeString() { LLSD llsdString = LLSD.FromString("abcdefghijklmnopqrstuvwxyz01234567890"); byte[] binaryLongStringSerialized = LLSDParser.SerializeBinary(llsdString); Assert.AreEqual(binaryLongString, binaryLongStringSerialized); // A test with some utf8 characters string contentAStringXML = "<x>ƖȔȠȨɆɒ</x>"; byte[] bytes = Encoding.UTF8.GetBytes(contentAStringXML); XmlTextReader xtr = new XmlTextReader(new MemoryStream(bytes, false)); xtr.Read(); xtr.Read(); string contentAString = xtr.ReadString(); LLSD llsdAString = LLSD.FromString(contentAString); byte[] binaryAString = LLSDParser.SerializeBinary(llsdAString); LLSD llsdAStringDS = LLSDParser.DeserializeBinary(binaryAString); Assert.AreEqual(LLSDType.String, llsdAStringDS.Type); Assert.AreEqual(contentAString, llsdAStringDS.AsString()); // we also test for a 4byte character. string xml = "<x>𐄷</x>"; byte[] bytesTwo = Encoding.UTF8.GetBytes(xml); XmlTextReader xtrTwo = new XmlTextReader(new MemoryStream(bytesTwo, false)); xtrTwo.Read(); xtrTwo.Read(); string content = xtrTwo.ReadString(); LLSD llsdStringOne = LLSD.FromString(content); byte[] binaryAStringOneSerialized = LLSDParser.SerializeBinary(llsdStringOne); LLSD llsdStringOneDS = LLSDParser.DeserializeBinary(binaryAStringOneSerialized); Assert.AreEqual(LLSDType.String, llsdStringOneDS.Type); Assert.AreEqual(content, llsdStringOneDS.AsString()); }
public static Vector3 ParseVector3(string key, LLSDMap reply) { LLSD llsd; if (reply.TryGetValue(key, out llsd)) { if (llsd.Type == LLSDType.Array) { return(((LLSDArray)llsd).AsVector3()); } else if (llsd.Type == LLSDType.String) { LLSDArray array = (LLSDArray)LLSDParser.DeserializeNotation(llsd.AsString()); return(array.AsVector3()); } } return(Vector3.Zero); }
public void DeserializeMap() { string sMapOne = " { } "; LLSDMap llsdMapOne = (LLSDMap)LLSDParser.DeserializeNotation(sMapOne); Assert.AreEqual(LLSDType.Map, llsdMapOne.Type); Assert.AreEqual(0, llsdMapOne.Count); string sMapTwo = " { \"test\":i2 } "; LLSDMap llsdMapTwo = (LLSDMap)LLSDParser.DeserializeNotation(sMapTwo); Assert.AreEqual(LLSDType.Map, llsdMapTwo.Type); Assert.AreEqual(1, llsdMapTwo.Count); Assert.AreEqual(LLSDType.Integer, llsdMapTwo["test"].Type); Assert.AreEqual(2, llsdMapTwo["test"].AsInteger()); string sMapThree = " { 'test':\"testtesttest\", 'aha':\"muahahaha\" , \"anywhere\":! } "; LLSDMap llsdMapThree = (LLSDMap)LLSDParser.DeserializeNotation(sMapThree); Assert.AreEqual(LLSDType.Map, llsdMapThree.Type); Assert.AreEqual(3, llsdMapThree.Count); Assert.AreEqual(LLSDType.String, llsdMapThree["test"].Type); Assert.AreEqual("testtesttest", llsdMapThree["test"].AsString()); Assert.AreEqual(LLSDType.String, llsdMapThree["test"].Type); Assert.AreEqual("muahahaha", llsdMapThree["aha"].AsString()); Assert.AreEqual(LLSDType.Unknown, llsdMapThree["self"].Type); string sMapFour = " { 'test' : { 'test' : i1, 't0st' : r2.5 }, 'tist' : \"hello world!\", 'tast' : \"last\" } "; LLSDMap llsdMapFour = (LLSDMap)LLSDParser.DeserializeNotation(sMapFour); Assert.AreEqual(LLSDType.Map, llsdMapFour.Type); Assert.AreEqual(3, llsdMapFour.Count); Assert.AreEqual("hello world!", llsdMapFour["tist"].AsString()); Assert.AreEqual("last", llsdMapFour["tast"].AsString()); LLSDMap llsdMapFive = (LLSDMap)llsdMapFour["test"]; Assert.AreEqual(LLSDType.Map, llsdMapFive.Type); Assert.AreEqual(2, llsdMapFive.Count); Assert.AreEqual(LLSDType.Integer, llsdMapFive["test"].Type); Assert.AreEqual(1, llsdMapFive["test"].AsInteger()); Assert.AreEqual(LLSDType.Real, llsdMapFive["t0st"].Type); Assert.AreEqual(2.5d, llsdMapFive["t0st"].AsReal()); }
public void SerializeArray() { LLSDArray llsdEmptyArray = new LLSDArray(); byte[] binaryEmptyArraySerialized = LLSDParser.SerializeBinary(llsdEmptyArray); Assert.AreEqual(binaryEmptyArray, binaryEmptyArraySerialized); LLSDArray llsdSimpleArray = new LLSDArray(); llsdSimpleArray.Add(LLSD.FromInteger(0)); byte[] binarySimpleArraySerialized = LLSDParser.SerializeBinary(llsdSimpleArray); Assert.AreEqual(binarySimpleArray, binarySimpleArraySerialized); LLSDArray llsdSimpleArrayTwo = new LLSDArray(); llsdSimpleArrayTwo.Add(LLSD.FromInteger(0)); llsdSimpleArrayTwo.Add(LLSD.FromInteger(0)); byte[] binarySimpleArrayTwoSerialized = LLSDParser.SerializeBinary(llsdSimpleArrayTwo); Assert.AreEqual(binarySimpleArrayTwo, binarySimpleArrayTwoSerialized); }
public void SerializeLongMessage() { // each 80 chars string sOne = "asdklfjasadlfkjaerotiudfgjkhsdklgjhsdklfghasdfklhjasdfkjhasdfkljahsdfjklaasdfkj8"; string sTwo = "asdfkjlaaweoiugsdfjkhsdfg,.mnasdgfkljhrtuiohfglökajsdfoiwghjkdlaaaaseldkfjgheus9"; LLSD stringOne = LLSD.FromString(sOne); LLSD stringTwo = LLSD.FromString(sTwo); LLSDMap llsdMap = new LLSDMap(); llsdMap["testOne"] = stringOne; llsdMap["testTwo"] = stringTwo; llsdMap["testThree"] = stringOne; llsdMap["testFour"] = stringTwo; llsdMap["testFive"] = stringOne; llsdMap["testSix"] = stringTwo; llsdMap["testSeven"] = stringOne; llsdMap["testEight"] = stringTwo; llsdMap["testNine"] = stringOne; llsdMap["testTen"] = stringTwo; byte[] binaryData = LLSDParser.SerializeBinary(llsdMap); LLSDMap llsdMapDS = (LLSDMap)LLSDParser.DeserializeBinary(binaryData); Assert.AreEqual(LLSDType.Map, llsdMapDS.Type); Assert.AreEqual(10, llsdMapDS.Count); Assert.AreEqual(sOne, llsdMapDS["testOne"].AsString()); Assert.AreEqual(sTwo, llsdMapDS["testTwo"].AsString()); Assert.AreEqual(sOne, llsdMapDS["testThree"].AsString()); Assert.AreEqual(sTwo, llsdMapDS["testFour"].AsString()); Assert.AreEqual(sOne, llsdMapDS["testFive"].AsString()); Assert.AreEqual(sTwo, llsdMapDS["testSix"].AsString()); Assert.AreEqual(sOne, llsdMapDS["testSeven"].AsString()); Assert.AreEqual(sTwo, llsdMapDS["testEight"].AsString()); Assert.AreEqual(sOne, llsdMapDS["testNine"].AsString()); Assert.AreEqual(sTwo, llsdMapDS["testTen"].AsString()); }