diff --git a/Assets/Plugins/Catnip.meta b/Assets/Plugins/Catnip.meta new file mode 100644 index 0000000..b827153 --- /dev/null +++ b/Assets/Plugins/Catnip.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5517ceddb63c378498db7ef3905c90f3 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index a282c7f..872481a 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -291,9 +291,9 @@ RectTransform: m_Father: {fileID: 1999675308} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 0, y: 0} - m_AnchoredPosition: {x: 0, y: 0} + m_AnchorMin: {x: 0, y: 1} + m_AnchorMax: {x: 0, y: 1} + m_AnchoredPosition: {x: 235, y: -89.28295} m_SizeDelta: {x: 450, y: 158.5659} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &159306965 @@ -809,7 +809,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &432150340 RectTransform: m_ObjectHideFlags: 0 @@ -829,7 +829,7 @@ RectTransform: m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 0, y: 0} + m_SizeDelta: {x: -1450, y: -733.8941} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &432150341 MonoBehaviour: @@ -1507,8 +1507,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 200, y: 50} + m_AnchoredPosition: {x: -96.12402, y: 28.63269} + m_SizeDelta: {x: 392.248, y: 107.2654} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &703123636 MonoBehaviour: @@ -1530,7 +1530,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_text: New Text + m_text: Logged in! m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} @@ -1557,8 +1557,8 @@ MonoBehaviour: m_faceColor: serializedVersion: 2 rgba: 4294967295 - m_fontSize: 36 - m_fontSizeBase: 36 + m_fontSize: 63.96 + m_fontSizeBase: 63.96 m_fontWeight: 400 m_enableAutoSizing: 0 m_fontSizeMin: 18 @@ -1889,9 +1889,9 @@ RectTransform: m_Father: {fileID: 1999675308} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 0, y: 0} - m_AnchoredPosition: {x: 0, y: 0} + m_AnchorMin: {x: 0, y: 1} + m_AnchorMax: {x: 0, y: 1} + m_AnchoredPosition: {x: 235, y: -256.82092} m_SizeDelta: {x: 450, y: 158.57} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &853334012 @@ -3248,9 +3248,9 @@ RectTransform: m_Father: {fileID: 432150340} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 0, y: 0} - m_AnchoredPosition: {x: 0, y: 0} + m_AnchorMin: {x: 0, y: 1} + m_AnchorMax: {x: 0, y: 1} + m_AnchoredPosition: {x: 235, y: -89.28295} m_SizeDelta: {x: 450, y: 158.5659} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1356808779 @@ -3457,9 +3457,9 @@ RectTransform: m_Father: {fileID: 432150340} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 0, y: 0} - m_AnchoredPosition: {x: 0, y: 0} + m_AnchorMin: {x: 0, y: 1} + m_AnchorMax: {x: 0, y: 1} + m_AnchoredPosition: {x: 235, y: -256.82092} m_SizeDelta: {x: 450, y: 158.57} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1418630377 @@ -4606,7 +4606,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &1999675308 RectTransform: m_ObjectHideFlags: 0 @@ -4626,7 +4626,7 @@ RectTransform: m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 0, y: 0} + m_SizeDelta: {x: -1450, y: -733.8941} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1999675309 MonoBehaviour: diff --git a/Assets/Tests/BinarySDTests.cs b/Assets/Tests/BinarySDTests.cs new file mode 100644 index 0000000..c1b3062 --- /dev/null +++ b/Assets/Tests/BinarySDTests.cs @@ -0,0 +1,748 @@ +/* + * Copyright (c) 2006-2016, openmetaverse.co + * All rights reserved. + * + * - Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * - Neither the name of the openmetaverse.co nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * + * This tests are based upon the description at + * + * http://wiki.secondlife.com/wiki/LLSD + * + * and (partially) generated by the (supposed) reference implementation at + * + * http://svn.secondlife.com/svn/linden/release/indra/lib/python/indra/base/llsd.py + * + */ + +using System; +using System.IO; +using System.Text; +using System.Xml; +using NUnit.Framework; +using OpenMetaverse.StructuredData; + +namespace OpenMetaverse.Tests +{ + + [TestFixture()] + public class BinarySDTests + { + private static readonly byte[] binaryHead = Encoding.ASCII.GetBytes("\n"); + + [Test()] + 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); + + stream.Position = 0L; + bool result = OSDParser.FindString(stream, "this"); + Assert.AreEqual(true, result); + Assert.AreEqual(4L, stream.Position); + + stream.Position = 10L; + result = OSDParser.FindString(stream, "teststring"); + Assert.AreEqual(true, result); + Assert.AreEqual(20L, stream.Position); + + stream.Position = 25L; + result = OSDParser.FindString(stream, "notfound"); + Assert.AreEqual(false, result); + Assert.AreEqual(25L, stream.Position); + + stream.Position = 60L; + result = OSDParser.FindString(stream, "beginningAndMore"); + Assert.AreEqual(false, result); + Assert.AreEqual(60L, stream.Position); + + byte[] sFrontWhiteSpace = Encoding.ASCII.GetBytes(" \t\t\n\rtest"); + MemoryStream streamTwo = new MemoryStream(sFrontWhiteSpace); + OSDParser.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; + OSDParser.SkipWhiteSpace(streamThree); + Assert.AreEqual(9L, streamThree.Position); + + byte[] sNoWhiteSpace = Encoding.ASCII.GetBytes("testtesttest"); + MemoryStream streamFour = new MemoryStream(sNoWhiteSpace); + OSDParser.SkipWhiteSpace(streamFour); + Assert.AreEqual(0L, streamFour.Position); + + } + + // Testvalues for Undef: + private static byte[] binaryUndefValue = { 0x21 }; + private static byte[] binaryUndef = (byte[])ConcatenateArrays(binaryHead, binaryUndefValue); + + [Test()] + public void DeserializeUndef() + { + OSD llsdUndef = OSDParser.DeserializeLLSDBinary(binaryUndef); + Assert.AreEqual(OSDType.Unknown, llsdUndef.Type); + } + + [Test()] + public void SerializeUndef() + { + OSD llsdUndef = new OSD(); + byte[] binaryUndefSerialized = OSDParser.SerializeLLSDBinary(llsdUndef); + Assert.AreEqual(binaryUndef, binaryUndefSerialized); + } + + private static byte[] binaryTrueValue = { 0x31 }; + private static byte[] binaryTrue = (byte[])ConcatenateArrays(binaryHead, binaryTrueValue); + + + private static byte[] binaryFalseValue = { 0x30 }; + private static byte[] binaryFalse = (byte[])ConcatenateArrays(binaryHead, binaryFalseValue); + + [Test()] + public void DeserializeBool() + { + OSD llsdTrue = OSDParser.DeserializeLLSDBinary(binaryTrue); + Assert.AreEqual(OSDType.Boolean, llsdTrue.Type); + Assert.AreEqual(true, llsdTrue.AsBoolean()); + + OSD llsdFalse = OSDParser.DeserializeLLSDBinary(binaryFalse); + Assert.AreEqual(OSDType.Boolean, llsdFalse.Type); + Assert.AreEqual(false, llsdFalse.AsBoolean()); + } + + [Test()] + public void SerializeBool() + { + OSD llsdTrue = OSD.FromBoolean(true); + byte[] binaryTrueSerialized = OSDParser.SerializeLLSDBinary(llsdTrue); + Assert.AreEqual(binaryTrue, binaryTrueSerialized); + + OSD llsdFalse = OSD.FromBoolean(false); + byte[] binaryFalseSerialized = OSDParser.SerializeLLSDBinary(llsdFalse); + Assert.AreEqual(binaryFalse, binaryFalseSerialized); + } + + private static byte[] binaryZeroIntValue = { 0x69, 0x0, 0x0, 0x0, 0x0 }; + private static byte[] binaryZeroInt = (byte[])ConcatenateArrays(binaryHead, binaryZeroIntValue); + + private static byte[] binaryAnIntValue = { 0x69, 0x0, 0x12, 0xd7, 0x9b }; + private static byte[] binaryAnInt = (byte[])ConcatenateArrays(binaryHead, binaryAnIntValue); + + [Test()] + public void DeserializeInteger() + { + OSD llsdZeroInteger = OSDParser.DeserializeLLSDBinary(binaryZeroInt); + Assert.AreEqual(OSDType.Integer, llsdZeroInteger.Type); + Assert.AreEqual(0, llsdZeroInteger.AsInteger()); + + + OSD llsdAnInteger = OSDParser.DeserializeLLSDBinary(binaryAnInt); + Assert.AreEqual(OSDType.Integer, llsdAnInteger.Type); + Assert.AreEqual(1234843, llsdAnInteger.AsInteger()); + } + + [Test()] + public void SerializeInteger() + { + OSD llsdZeroInt = OSD.FromInteger(0); + byte[] binaryZeroIntSerialized = OSDParser.SerializeLLSDBinary(llsdZeroInt); + Assert.AreEqual(binaryZeroInt, binaryZeroIntSerialized); + + binaryZeroIntSerialized = OSDParser.SerializeLLSDBinary(llsdZeroInt, false); + Assert.AreEqual(binaryZeroIntValue, binaryZeroIntSerialized); + + OSD llsdAnInt = OSD.FromInteger(1234843); + byte[] binaryAnIntSerialized = OSDParser.SerializeLLSDBinary(llsdAnInt); + Assert.AreEqual(binaryAnInt, binaryAnIntSerialized); + + binaryAnIntSerialized = OSDParser.SerializeLLSDBinary(llsdAnInt, false); + Assert.AreEqual(binaryAnIntValue, binaryAnIntSerialized); + } + + private static byte[] binaryRealValue = { 0x72, 0x41, 0x2c, 0xec, 0xf6, 0x77, 0xce, 0xd9, 0x17 }; + private static byte[] binaryReal = (byte[])ConcatenateArrays(binaryHead, binaryRealValue); + + [Test()] + public void DeserializeReal() + { + OSD llsdReal = OSDParser.DeserializeLLSDBinary(binaryReal); + Assert.AreEqual(OSDType.Real, llsdReal.Type); + Assert.AreEqual(947835.234d, llsdReal.AsReal()); + } + + [Test()] + public void SerializeReal() + { + OSD llsdReal = OSD.FromReal(947835.234d); + byte[] binaryRealSerialized = OSDParser.SerializeLLSDBinary(llsdReal); + Assert.AreEqual(binaryReal, binaryRealSerialized); + + binaryRealSerialized = OSDParser.SerializeLLSDBinary(llsdReal); + Assert.AreEqual(binaryReal, binaryRealSerialized); + } + + private static byte[] binaryAUUIDValue = { 0x75, 0x97, 0xf4, 0xae, 0xca, 0x88, 0xa1, 0x42, 0xa1, + 0xb3, 0x85, 0xb9, 0x7b, 0x18, 0xab, 0xb2, 0x55 }; + private static byte[] binaryAUUID = (byte[])ConcatenateArrays(binaryHead, binaryAUUIDValue); + + private static byte[] binaryZeroUUIDValue = { 0x75, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; + private static byte[] binaryZeroUUID = (byte[])ConcatenateArrays(binaryHead, binaryZeroUUIDValue); + + + [Test()] + public void DeserializeUUID() + { + OSD llsdAUUID = OSDParser.DeserializeLLSDBinary(binaryAUUID); + Assert.AreEqual(OSDType.UUID, llsdAUUID.Type); + Assert.AreEqual("97f4aeca-88a1-42a1-b385-b97b18abb255", llsdAUUID.AsString()); + + OSD llsdZeroUUID = OSDParser.DeserializeLLSDBinary(binaryZeroUUID); + Assert.AreEqual(OSDType.UUID, llsdZeroUUID.Type); + Assert.AreEqual("00000000-0000-0000-0000-000000000000", llsdZeroUUID.AsString()); + + } + + [Test()] + public void SerializeUUID() + { + OSD llsdAUUID = OSD.FromUUID(new UUID("97f4aeca-88a1-42a1-b385-b97b18abb255")); + byte[] binaryAUUIDSerialized = OSDParser.SerializeLLSDBinary(llsdAUUID); + Assert.AreEqual(binaryAUUID, binaryAUUIDSerialized); + + binaryAUUIDSerialized = OSDParser.SerializeLLSDBinary(llsdAUUID); + Assert.AreEqual(binaryAUUID, binaryAUUIDSerialized); + + OSD llsdZeroUUID = OSD.FromUUID(new UUID("00000000-0000-0000-0000-000000000000")); + byte[] binaryZeroUUIDSerialized = OSDParser.SerializeLLSDBinary(llsdZeroUUID); + Assert.AreEqual(binaryZeroUUID, binaryZeroUUIDSerialized); + + binaryZeroUUIDSerialized = OSDParser.SerializeLLSDBinary(llsdZeroUUID); + Assert.AreEqual(binaryZeroUUID, binaryZeroUUIDSerialized); + } + + private static byte[] binaryBinStringValue = { 0x62, 0x0, 0x0, 0x0, 0x34, // this line is the encoding header + 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x73, + 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x62, 0x69, 0x6e, 0x61, 0x72, 0x79, 0x20, 0x63, 0x6f, + 0x6e, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x74, 0x68, + 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0xa, 0xd }; + private static byte[] binaryBinString = (byte[])ConcatenateArrays(binaryHead, binaryBinStringValue); + + [Test()] + public void DeserializeLLSDBinary() + { + OSD llsdBytes = OSDParser.DeserializeLLSDBinary(binaryBinString); + Assert.AreEqual(OSDType.Binary, llsdBytes.Type); + byte[] contentBinString = { 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x73, + 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x62, 0x69, 0x6e, 0x61, 0x72, 0x79, 0x20, 0x63, 0x6f, + 0x6e, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x74, 0x68, + 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0xa, 0xd }; + Assert.AreEqual(contentBinString, llsdBytes.AsBinary()); + } + + [Test()] + public void SerializeLLSDBinary() + { + byte[] contentBinString = { 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x61, 0x20, 0x73, + 0x69, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x62, 0x69, 0x6e, 0x61, 0x72, 0x79, 0x20, 0x63, 0x6f, + 0x6e, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x74, 0x68, + 0x69, 0x73, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0xa, 0xd }; + OSD llsdBinary = OSD.FromBinary(contentBinString); + byte[] binaryBinarySerialized = OSDParser.SerializeLLSDBinary(llsdBinary); + Assert.AreEqual(binaryBinString, binaryBinarySerialized); + } + + private static byte[] binaryEmptyStringValue = { 0x73, 0x0, 0x0, 0x0, 0x0 }; + private static byte[] binaryEmptyString = (byte[])ConcatenateArrays(binaryHead, binaryEmptyStringValue); + private static byte[] binaryLongStringValue = { 0x73, 0x0, 0x0, 0x0, 0x25, + 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, + 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, + 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, + 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, + 0x79, 0x7a, 0x30, 0x31, 0x32, 0x33, + 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30 }; + private static byte[] binaryLongString = (byte[])ConcatenateArrays(binaryHead, binaryLongStringValue); + + [Test()] + public void DeserializeString() + { + OSD llsdEmptyString = OSDParser.DeserializeLLSDBinary(binaryEmptyString); + Assert.AreEqual(OSDType.String, llsdEmptyString.Type); + string contentEmptyString = ""; + Assert.AreEqual(contentEmptyString, llsdEmptyString.AsString()); + + OSD llsdLongString = OSDParser.DeserializeLLSDBinary(binaryLongString); + Assert.AreEqual(OSDType.String, llsdLongString.Type); + string contentLongString = "abcdefghijklmnopqrstuvwxyz01234567890"; + Assert.AreEqual(contentLongString, llsdLongString.AsString()); + } + + [Test()] + public void SerializeString() + { + OSD llsdString = OSD.FromString("abcdefghijklmnopqrstuvwxyz01234567890"); + byte[] binaryLongStringSerialized = OSDParser.SerializeLLSDBinary(llsdString); + Assert.AreEqual(binaryLongString, binaryLongStringSerialized); + + // A test with some utf8 characters + string contentAStringXML = "ƖȔȠȨɆɒ"; + byte[] bytes = Encoding.UTF8.GetBytes(contentAStringXML); + XmlTextReader xtr = new XmlTextReader(new MemoryStream(bytes, false)); + xtr.Read(); + xtr.Read(); + + string contentAString = xtr.ReadString(); + OSD llsdAString = OSD.FromString(contentAString); + byte[] binaryAString = OSDParser.SerializeLLSDBinary(llsdAString); + OSD llsdAStringDS = OSDParser.DeserializeLLSDBinary(binaryAString); + Assert.AreEqual(OSDType.String, llsdAStringDS.Type); + Assert.AreEqual(contentAString, llsdAStringDS.AsString()); + + // we also test for a 4byte character. + string xml = "𐄷"; + byte[] bytesTwo = Encoding.UTF8.GetBytes(xml); + XmlTextReader xtrTwo = new XmlTextReader(new MemoryStream(bytesTwo, false)); + xtrTwo.Read(); + xtrTwo.Read(); + string content = xtrTwo.ReadString(); + + OSD llsdStringOne = OSD.FromString(content); + byte[] binaryAStringOneSerialized = OSDParser.SerializeLLSDBinary(llsdStringOne); + OSD llsdStringOneDS = OSDParser.DeserializeLLSDBinary(binaryAStringOneSerialized); + Assert.AreEqual(OSDType.String, llsdStringOneDS.Type); + Assert.AreEqual(content, llsdStringOneDS.AsString()); + + } + + // Be careful. The current and above mentioned reference implementation has a bug that + // doesnt allow proper binary Uri encoding. + // We compare here to a fixed version of Uri encoding + private static byte[] binaryURIValue = { 0x6c, 0x0, 0x0, 0x0, 0x18, // this line is the encoding header + 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x74, + 0x65, 0x73, 0x74, 0x75, 0x72, 0x6c, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x2f }; + private static byte[] binaryURI = (byte[])ConcatenateArrays(binaryHead, binaryURIValue); + + [Test()] + public void DeserializeURI() + { + OSD llsdURI = OSDParser.DeserializeLLSDBinary(binaryURI); + Assert.AreEqual(OSDType.URI, llsdURI.Type); + Uri uri = new Uri("http://www.testurl.test/"); + Assert.AreEqual(uri, llsdURI.AsUri()); + + } + + [Test()] + public void SerializeURI() + { + OSD llsdUri = OSD.FromUri(new Uri("http://www.testurl.test/")); + byte[] binaryURISerialized = OSDParser.SerializeLLSDBinary(llsdUri); + Assert.AreEqual(binaryURI, binaryURISerialized); + } + + // Here is a problem. + // The reference implementation does serialize to a local timestamp and not to a universal timestamp, + // which means, this implementation and the reference implementation only work the same in the universal + // timezone. Therefore this binaryDateTimeValue is generated in the UTC timezone by the reference + // implementation. + private static byte[] binaryDateTimeValue = { 100, 0, 0, 192, 141, 167, 222, 209, 65 }; + private static byte[] binaryDateTime = (byte[])ConcatenateArrays(binaryHead, binaryDateTimeValue); + + [Test()] + public void DeserializeDateTime() + { + OSD llsdDateTime = OSDParser.DeserializeLLSDBinary(binaryDateTime); + Assert.AreEqual(OSDType.Date, llsdDateTime.Type); + DateTime dt = new DateTime(2008, 1, 1, 20, 10, 31, 0, DateTimeKind.Utc); + DateTime dateLocal = llsdDateTime.AsDate(); + Assert.AreEqual(dt, dateLocal.ToUniversalTime()); + } + + [Test()] + public void SerializeDateTime() + { + DateTime dt = new DateTime(2008, 1, 1, 20, 10, 31, 0, DateTimeKind.Utc); + OSD llsdDate = OSD.FromDate(dt); + byte[] binaryDateSerialized = OSDParser.SerializeLLSDBinary(llsdDate); + Assert.AreEqual(binaryDateTime, binaryDateSerialized); + + // check if a *local* time can be serialized and deserialized + DateTime dtOne = new DateTime(2009, 12, 30, 8, 25, 10, DateTimeKind.Local); + OSD llsdDateOne = OSD.FromDate(dtOne); + byte[] binaryDateOneSerialized = OSDParser.SerializeLLSDBinary(llsdDateOne); + OSD llsdDateOneDS = OSDParser.DeserializeLLSDBinary(binaryDateOneSerialized); + Assert.AreEqual(OSDType.Date, llsdDateOneDS.Type); + Assert.AreEqual(dtOne, llsdDateOneDS.AsDate()); + + DateTime dtTwo = new DateTime(2010, 11, 11, 10, 8, 20, DateTimeKind.Utc); + OSD llsdDateTwo = OSD.FromDate(dtTwo); + byte[] binaryDateTwoSerialized = OSDParser.SerializeLLSDBinary(llsdDateTwo); + OSD llsdDateTwoDS = OSDParser.DeserializeLLSDBinary(binaryDateTwoSerialized); + Assert.AreEqual(OSDType.Date, llsdDateOneDS.Type); + Assert.AreEqual(dtTwo.ToLocalTime(), llsdDateTwoDS.AsDate()); + } + + // Data for empty array { } + private static byte[] binaryEmptyArrayValue = { 0x5b, 0x0, 0x0, 0x0, 0x0, 0x5d }; + // Encoding header + num of elements + tail + private static byte[] binaryEmptyArray = (byte[])ConcatenateArrays(binaryHead, binaryEmptyArrayValue); + // Data for simple array { 0 } + private static byte[] binarySimpleArrayValue = { 0x5b, 0x0, 0x0, 0x0, 0x1, // Encoding header + num of elements + 0x69, 0x0, 0x0, 0x0, 0x0, 0x5d }; + private static byte[] binarySimpleArray = (byte[])ConcatenateArrays(binaryHead, binarySimpleArrayValue); + + // Data for simple array { 0, 0 } + private static byte[] binarySimpleArrayTwoValue = { 0x5b, 0x0, 0x0, 0x0, 0x2, // Encoding header + num of elements + 0x69, 0x0, 0x0, 0x0, 0x0, + 0x69, 0x0, 0x0, 0x0, 0x0, 0x5d }; + private static byte[] binarySimpleArrayTwo = (byte[])ConcatenateArrays(binaryHead, binarySimpleArrayTwoValue); + + [Test()] + public void DeserializeArray() + { + OSD llsdEmptyArray = OSDParser.DeserializeLLSDBinary(binaryEmptyArray); + Assert.AreEqual(OSDType.Array, llsdEmptyArray.Type); + OSDArray llsdEmptyArrayArray = (OSDArray)llsdEmptyArray; + Assert.AreEqual(0, llsdEmptyArrayArray.Count); + + + OSD llsdSimpleArray = OSDParser.DeserializeLLSDBinary(binarySimpleArray); + Assert.AreEqual(OSDType.Array, llsdSimpleArray.Type); + OSDArray llsdArray = (OSDArray)llsdSimpleArray; + Assert.AreEqual(OSDType.Integer, llsdArray[0].Type); + Assert.AreEqual(0, llsdArray[0].AsInteger()); + + + OSD llsdSimpleArrayTwo = OSDParser.DeserializeLLSDBinary(binarySimpleArrayTwo); + Assert.AreEqual(OSDType.Array, llsdSimpleArrayTwo.Type); + OSDArray llsdArrayTwo = (OSDArray)llsdSimpleArrayTwo; + Assert.AreEqual(2, llsdArrayTwo.Count); + + Assert.AreEqual(OSDType.Integer, llsdArrayTwo[0].Type); + Assert.AreEqual(0, llsdArrayTwo[0].AsInteger()); + Assert.AreEqual(OSDType.Integer, llsdArrayTwo[1].Type); + Assert.AreEqual(0, llsdArrayTwo[1].AsInteger()); + } + + [Test()] + public void SerializeArray() + { + OSDArray llsdEmptyArray = new OSDArray(); + byte[] binaryEmptyArraySerialized = OSDParser.SerializeLLSDBinary(llsdEmptyArray); + Assert.AreEqual(binaryEmptyArray, binaryEmptyArraySerialized); + + binaryEmptyArraySerialized = OSDParser.SerializeLLSDBinary(llsdEmptyArray, false); + Assert.AreEqual(binaryEmptyArrayValue, binaryEmptyArraySerialized); + + OSDArray llsdSimpleArray = new OSDArray(); + llsdSimpleArray.Add(OSD.FromInteger(0)); + byte[] binarySimpleArraySerialized = OSDParser.SerializeLLSDBinary(llsdSimpleArray); + Assert.AreEqual(binarySimpleArray, binarySimpleArraySerialized); + + binarySimpleArraySerialized = OSDParser.SerializeLLSDBinary(llsdSimpleArray, false); + Assert.AreEqual(binarySimpleArrayValue, binarySimpleArraySerialized); + + OSDArray llsdSimpleArrayTwo = new OSDArray(); + llsdSimpleArrayTwo.Add(OSD.FromInteger(0)); + llsdSimpleArrayTwo.Add(OSD.FromInteger(0)); + byte[] binarySimpleArrayTwoSerialized = OSDParser.SerializeLLSDBinary(llsdSimpleArrayTwo); + Assert.AreEqual(binarySimpleArrayTwo, binarySimpleArrayTwoSerialized); + + binarySimpleArrayTwoSerialized = OSDParser.SerializeLLSDBinary(llsdSimpleArrayTwo, false); + Assert.AreEqual(binarySimpleArrayTwoValue, binarySimpleArrayTwoSerialized); + } + + // Data for empty dictionary { } + private static byte[] binaryEmptyMapValue = { 0x7b, 0x0, 0x0, 0x0, 0x0, 0x7d }; + private static byte[] binaryEmptyMap = (byte[])ConcatenateArrays(binaryHead, binaryEmptyMapValue); + + // Data for simple dictionary { test = 0 } + private static byte[] binarySimpleMapValue = { 0x7b, 0x0, 0x0, 0x0, 0x1, // Encoding header + num of elements + 0x6b, 0x0, 0x0, 0x0, 0x4, // 'k' + keylength + 0x74, 0x65, 0x73, 0x74, // key 'test' + 0x69, 0x0, 0x0, 0x0, 0x0, // i + '0' + 0x7d }; + private static byte[] binarySimpleMap = (byte[])ConcatenateArrays(binaryHead, binarySimpleMapValue); + + // Data for simple dictionary { t0st = 241, tes1 = "aha", test = undef } + private static byte[] binarySimpleMapTwoValue = { 0x7b, 0x0, 0x0, 0x0, 0x3, // Encoding header + num of elements + 0x6b, 0x0, 0x0, 0x0, 0x4, // 'k' + keylength + 0x74, 0x65, 0x73, 0x74, // key 'test' + 0x21, // undef + 0x6b, 0x0, 0x0, 0x0, 0x4, // k + keylength + 0x74, 0x65, 0x73, 0x31, // key 'tes1' + 0x73, 0x0, 0x0, 0x0, 0x3, // string head + length + 0x61, 0x68, 0x61, // 'aha' + 0x6b, 0x0, 0x0, 0x0, 0x4, // k + keylength + 0x74, 0x30, 0x73, 0x74, // key 't0st' + 0x69, 0x0, 0x0, 0x0, 0xf1, // integer 241 + 0x7d }; + private static byte[] binarySimpleMapTwo = (byte[])ConcatenateArrays(binaryHead, binarySimpleMapTwoValue); + + [Test()] + public void DeserializeDictionary() + { + OSDMap llsdEmptyMap = (OSDMap)OSDParser.DeserializeLLSDBinary(binaryEmptyMap); + Assert.AreEqual(OSDType.Map, llsdEmptyMap.Type); + Assert.AreEqual(0, llsdEmptyMap.Count); + + OSDMap llsdSimpleMap = (OSDMap)OSDParser.DeserializeLLSDBinary(binarySimpleMap); + Assert.AreEqual(OSDType.Map, llsdSimpleMap.Type); + Assert.AreEqual(1, llsdSimpleMap.Count); + Assert.AreEqual(OSDType.Integer, llsdSimpleMap["test"].Type); + Assert.AreEqual(0, llsdSimpleMap["test"].AsInteger()); + + OSDMap llsdSimpleMapTwo = (OSDMap)OSDParser.DeserializeLLSDBinary(binarySimpleMapTwo); + Assert.AreEqual(OSDType.Map, llsdSimpleMapTwo.Type); + Assert.AreEqual(3, llsdSimpleMapTwo.Count); + Assert.AreEqual(OSDType.Unknown, llsdSimpleMapTwo["test"].Type); + Assert.AreEqual(OSDType.String, llsdSimpleMapTwo["tes1"].Type); + Assert.AreEqual("aha", llsdSimpleMapTwo["tes1"].AsString()); + Assert.AreEqual(OSDType.Integer, llsdSimpleMapTwo["t0st"].Type); + Assert.AreEqual(241, llsdSimpleMapTwo["t0st"].AsInteger()); + + + } + + [Test()] + public void SerializeDictionary() + { + OSDMap llsdEmptyMap = new OSDMap(); + byte[] binaryEmptyMapSerialized = OSDParser.SerializeLLSDBinary(llsdEmptyMap); + Assert.AreEqual(binaryEmptyMap, binaryEmptyMapSerialized); + + OSDMap llsdSimpleMap = new OSDMap(); + llsdSimpleMap["test"] = OSD.FromInteger(0); + byte[] binarySimpleMapSerialized = OSDParser.SerializeLLSDBinary(llsdSimpleMap); + Assert.AreEqual(binarySimpleMap, binarySimpleMapSerialized); + + OSDMap llsdSimpleMapTwo = new OSDMap(); + llsdSimpleMapTwo["t0st"] = OSD.FromInteger(241); + llsdSimpleMapTwo["tes1"] = OSD.FromString("aha"); + llsdSimpleMapTwo["test"] = new OSD(); + byte[] binarySimpleMapTwoSerialized = OSDParser.SerializeLLSDBinary(llsdSimpleMapTwo); + + // We dont compare here to the original serialized value, because, as maps dont preserve order, + // the original serialized value is not *exactly* the same. Instead we compare to a deserialized + // version created by this deserializer. + OSDMap llsdSimpleMapDeserialized = (OSDMap)OSDParser.DeserializeLLSDBinary(binarySimpleMapTwoSerialized); + Assert.AreEqual(OSDType.Map, llsdSimpleMapDeserialized.Type); + Assert.AreEqual(3, llsdSimpleMapDeserialized.Count); + Assert.AreEqual(OSDType.Integer, llsdSimpleMapDeserialized["t0st"].Type); + Assert.AreEqual(241, llsdSimpleMapDeserialized["t0st"].AsInteger()); + Assert.AreEqual(OSDType.String, llsdSimpleMapDeserialized["tes1"].Type); + Assert.AreEqual("aha", llsdSimpleMapDeserialized["tes1"].AsString()); + Assert.AreEqual(OSDType.Unknown, llsdSimpleMapDeserialized["test"].Type); + + // we also test for a 4byte key character. + string xml = "𐄷"; + byte[] bytes = Encoding.UTF8.GetBytes(xml); + XmlTextReader xtr = new XmlTextReader(new MemoryStream(bytes, false)); + xtr.Read(); + xtr.Read(); + string content = xtr.ReadString(); + + OSDMap llsdSimpleMapThree = new OSDMap(); + OSD llsdSimpleValue = OSD.FromString(content); + llsdSimpleMapThree[content] = llsdSimpleValue; + Assert.AreEqual(content, llsdSimpleMapThree[content].AsString()); + + byte[] binarySimpleMapThree = OSDParser.SerializeLLSDBinary(llsdSimpleMapThree); + OSDMap llsdSimpleMapThreeDS = (OSDMap)OSDParser.DeserializeLLSDBinary(binarySimpleMapThree); + Assert.AreEqual(OSDType.Map, llsdSimpleMapThreeDS.Type); + Assert.AreEqual(1, llsdSimpleMapThreeDS.Count); + Assert.AreEqual(content, llsdSimpleMapThreeDS[content].AsString()); + + } + + private static byte[] binaryNestedValue = { 0x5b, 0x0, 0x0, 0x0, 0x3, + 0x7b, 0x0, 0x0, 0x0, 0x2, + 0x6b, 0x0, 0x0, 0x0, 0x4, + 0x74, 0x65, 0x73, 0x74, + 0x73, 0x0, 0x0, 0x0, 0x4, + 0x77, 0x68, 0x61, 0x74, + 0x6b, 0x0, 0x0, 0x0, 0x4, + 0x74, 0x30, 0x73, + 0x74, 0x5b, 0x0, 0x0, 0x0, 0x2, + 0x69, 0x0, 0x0, 0x0, 0x1, + 0x69, 0x0, 0x0, 0x0, 0x2, + 0x5d, 0x7d, 0x69, 0x0, 0x0, 0x0, + 0x7c, 0x69, 0x0, 0x0, 0x3, 0xdb, + 0x5d }; + private static byte[] binaryNested = (byte[])ConcatenateArrays(binaryHead, binaryNestedValue); + + [Test()] + public void DeserializeNestedComposite() + { + OSD llsdNested = OSDParser.DeserializeLLSDBinary(binaryNested); + Assert.AreEqual(OSDType.Array, llsdNested.Type); + OSDArray llsdArray = (OSDArray)llsdNested; + Assert.AreEqual(3, llsdArray.Count); + + OSDMap llsdMap = (OSDMap)llsdArray[0]; + Assert.AreEqual(OSDType.Map, llsdMap.Type); + Assert.AreEqual(2, llsdMap.Count); + + OSDArray llsdNestedArray = (OSDArray)llsdMap["t0st"]; + Assert.AreEqual(OSDType.Array, llsdNestedArray.Type); + OSDInteger llsdNestedIntOne = (OSDInteger)llsdNestedArray[0]; + Assert.AreEqual(OSDType.Integer, llsdNestedIntOne.Type); + Assert.AreEqual(1, llsdNestedIntOne.AsInteger()); + OSDInteger llsdNestedIntTwo = (OSDInteger)llsdNestedArray[1]; + Assert.AreEqual(OSDType.Integer, llsdNestedIntTwo.Type); + Assert.AreEqual(2, llsdNestedIntTwo.AsInteger()); + + OSDString llsdString = (OSDString)llsdMap["test"]; + Assert.AreEqual(OSDType.String, llsdString.Type); + Assert.AreEqual("what", llsdString.AsString()); + + OSDInteger llsdIntOne = (OSDInteger)llsdArray[1]; + Assert.AreEqual(OSDType.Integer, llsdIntOne.Type); + Assert.AreEqual(124, llsdIntOne.AsInteger()); + OSDInteger llsdIntTwo = (OSDInteger)llsdArray[2]; + Assert.AreEqual(OSDType.Integer, llsdIntTwo.Type); + Assert.AreEqual(987, llsdIntTwo.AsInteger()); + + } + + [Test()] + public void SerializeNestedComposite() + { + OSDArray llsdNested = new OSDArray(); + OSDMap llsdMap = new OSDMap(); + OSDArray llsdArray = new OSDArray(); + llsdArray.Add(OSD.FromInteger(1)); + llsdArray.Add(OSD.FromInteger(2)); + llsdMap["t0st"] = llsdArray; + llsdMap["test"] = OSD.FromString("what"); + llsdNested.Add(llsdMap); + llsdNested.Add(OSD.FromInteger(124)); + llsdNested.Add(OSD.FromInteger(987)); + + byte[] binaryNestedSerialized = OSDParser.SerializeLLSDBinary(llsdNested); + // Because maps don't preserve order, we compare here to a deserialized value. + OSDArray llsdNestedDeserialized = (OSDArray)OSDParser.DeserializeLLSDBinary(binaryNestedSerialized); + Assert.AreEqual(OSDType.Array, llsdNestedDeserialized.Type); + Assert.AreEqual(3, llsdNestedDeserialized.Count); + + OSDMap llsdMapDeserialized = (OSDMap)llsdNestedDeserialized[0]; + Assert.AreEqual(OSDType.Map, llsdMapDeserialized.Type); + Assert.AreEqual(2, llsdMapDeserialized.Count); + Assert.AreEqual(OSDType.Array, llsdMapDeserialized["t0st"].Type); + + OSDArray llsdNestedArray = (OSDArray)llsdMapDeserialized["t0st"]; + Assert.AreEqual(OSDType.Array, llsdNestedArray.Type); + Assert.AreEqual(2, llsdNestedArray.Count); + Assert.AreEqual(OSDType.Integer, llsdNestedArray[0].Type); + Assert.AreEqual(1, llsdNestedArray[0].AsInteger()); + Assert.AreEqual(OSDType.Integer, llsdNestedArray[1].Type); + Assert.AreEqual(2, llsdNestedArray[1].AsInteger()); + + Assert.AreEqual(OSDType.String, llsdMapDeserialized["test"].Type); + Assert.AreEqual("what", llsdMapDeserialized["test"].AsString()); + + Assert.AreEqual(OSDType.Integer, llsdNestedDeserialized[1].Type); + Assert.AreEqual(124, llsdNestedDeserialized[1].AsInteger()); + + Assert.AreEqual(OSDType.Integer, llsdNestedDeserialized[2].Type); + Assert.AreEqual(987, llsdNestedDeserialized[2].AsInteger()); + + } + + [Test()] + public void SerializeLongMessage() + { + // each 80 chars + string sOne = "asdklfjasadlfkjaerotiudfgjkhsdklgjhsdklfghasdfklhjasdfkjhasdfkljahsdfjklaasdfkj8"; + string sTwo = "asdfkjlaaweoiugsdfjkhsdfg,.mnasdgfkljhrtuiohfglökajsdfoiwghjkdlaaaaseldkfjgheus9"; + + OSD stringOne = OSD.FromString(sOne); + OSD stringTwo = OSD.FromString(sTwo); + + OSDMap llsdMap = new OSDMap(); + 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 = OSDParser.SerializeLLSDBinary(llsdMap); + + OSDMap llsdMapDS = (OSDMap)OSDParser.DeserializeLLSDBinary(binaryData); + Assert.AreEqual(OSDType.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()); + } + + + static Array ConcatenateArrays(params Array[] arrays) + { + if (arrays == null) + { + throw new ArgumentNullException(nameof(arrays)); + } + if (arrays.Length == 0) + { + throw new ArgumentException("No arrays specified"); + } + + Type type = arrays[0].GetType().GetElementType(); + int totalLength = arrays[0].Length; + for (int i = 1; i < arrays.Length; i++) + { + if (arrays[i].GetType().GetElementType() != type) + { + throw new ArgumentException("Arrays must all be of the same type"); + } + totalLength += arrays[i].Length; + } + + Array ret = Array.CreateInstance(type, totalLength); + int index = 0; + foreach (Array array in arrays) + { + Array.Copy(array, 0, ret, index, array.Length); + index += array.Length; + } + return ret; + } + } +} diff --git a/Assets/Tests/Test_LibreMetaverse.cs.meta b/Assets/Tests/BinarySDTests.cs.meta similarity index 100% rename from Assets/Tests/Test_LibreMetaverse.cs.meta rename to Assets/Tests/BinarySDTests.cs.meta diff --git a/Assets/Tests/MessageTests.cs b/Assets/Tests/MessageTests.cs new file mode 100644 index 0000000..a8ecc2a --- /dev/null +++ b/Assets/Tests/MessageTests.cs @@ -0,0 +1,1630 @@ +/* + * Copyright (c) 2006-2016, openmetaverse.co + * All rights reserved. + * + * - Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * - Neither the name of the openmetaverse.co nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.IO; +using System.Net; +using System.Collections.Generic; +using System.Runtime.Serialization.Formatters.Binary; +using System.Text; +using System.Xml.Serialization; +using OpenMetaverse; +using OpenMetaverse.Packets; +using OpenMetaverse.StructuredData; +using OpenMetaverse.Messages.Linden; +using NUnit.Framework; + +namespace OpenMetaverse.Tests +{ + /// + /// These unit tests specifically test the Message class can serialize and deserialize its own data properly + /// a passed test does not necessarily indicate the formatting is correct in the resulting OSD to be handled + /// by the simulator. + /// + [TestFixture] + public class MessageTests : Assert + { + private Uri testURI = new Uri("https://sim3187.agni.lindenlab.com:12043/cap/6028fc44-c1e5-80a1-f902-19bde114458b"); + private IPAddress testIP = IPAddress.Parse("127.0.0.1"); + private ulong testHandle = 1106108697797888; + + [Test] + public void AgentGroupDataUpdateMessage() + { + AgentGroupDataUpdateMessage s = new AgentGroupDataUpdateMessage(); + s.AgentID = UUID.Random(); + + + + AgentGroupDataUpdateMessage.GroupData[] blocks = new AgentGroupDataUpdateMessage.GroupData[2]; + AgentGroupDataUpdateMessage.GroupData g1 = new AgentGroupDataUpdateMessage.GroupData(); + + g1.AcceptNotices = false; + g1.Contribution = 1024; + g1.GroupID = UUID.Random(); + g1.GroupInsigniaID = UUID.Random(); + g1.GroupName = "Group Name Test 1"; + g1.GroupPowers = GroupPowers.Accountable | GroupPowers.AllowLandmark | GroupPowers.AllowSetHome; + blocks[0] = g1; + + AgentGroupDataUpdateMessage.GroupData g2 = new AgentGroupDataUpdateMessage.GroupData(); + g2.AcceptNotices = false; + g2.Contribution = 16; + g2.GroupID = UUID.Random(); + g2.GroupInsigniaID = UUID.Random(); + g2.GroupName = "Group Name Test 2"; + g2.GroupPowers = GroupPowers.ChangeActions | GroupPowers.DeedObject; + blocks[1] = g2; + + s.GroupDataBlock = blocks; + + AgentGroupDataUpdateMessage.NewGroupData[] nblocks = new AgentGroupDataUpdateMessage.NewGroupData[2]; + + AgentGroupDataUpdateMessage.NewGroupData ng1 = new AgentGroupDataUpdateMessage.NewGroupData(); + ng1.ListInProfile = false; + nblocks[0] = ng1; + + AgentGroupDataUpdateMessage.NewGroupData ng2 = new AgentGroupDataUpdateMessage.NewGroupData(); + ng2.ListInProfile = true; + nblocks[1] = ng2; + + s.NewGroupDataBlock = nblocks; + + OSDMap map = s.Serialize(); + + AgentGroupDataUpdateMessage t = new AgentGroupDataUpdateMessage(); + t.Deserialize(map); + + Assert.AreEqual(s.AgentID, t.AgentID); + + for (int i = 0; i < t.GroupDataBlock.Length; i++) + { + Assert.AreEqual(s.GroupDataBlock[i].AcceptNotices, t.GroupDataBlock[i].AcceptNotices); + Assert.AreEqual(s.GroupDataBlock[i].Contribution, t.GroupDataBlock[i].Contribution); + Assert.AreEqual(s.GroupDataBlock[i].GroupID, t.GroupDataBlock[i].GroupID); + Assert.AreEqual(s.GroupDataBlock[i].GroupInsigniaID, t.GroupDataBlock[i].GroupInsigniaID); + Assert.AreEqual(s.GroupDataBlock[i].GroupName, t.GroupDataBlock[i].GroupName); + Assert.AreEqual(s.GroupDataBlock[i].GroupPowers, t.GroupDataBlock[i].GroupPowers); + } + + for (int i = 0; i < t.NewGroupDataBlock.Length; i++) + { + Assert.AreEqual(s.NewGroupDataBlock[i].ListInProfile, t.NewGroupDataBlock[i].ListInProfile); + } + } + + [Test] + public void TeleportFinishMessage() + { + TeleportFinishMessage s = new TeleportFinishMessage(); + s.AgentID = UUID.Random(); + s.Flags = TeleportFlags.ViaLocation | TeleportFlags.IsFlying; + s.IP = testIP; + s.LocationID = 32767; + s.Port = 3000; + s.RegionHandle = testHandle; + s.SeedCapability = testURI; + s.SimAccess = SimAccess.Mature; + + OSDMap map = s.Serialize(); + + TeleportFinishMessage t = new TeleportFinishMessage(); + t.Deserialize(map); + + Assert.AreEqual(s.AgentID, t.AgentID); + Assert.AreEqual(s.Flags, t.Flags); + Assert.AreEqual(s.IP, t.IP); + Assert.AreEqual(s.LocationID, t.LocationID); + Assert.AreEqual(s.Port, t.Port); + Assert.AreEqual(s.RegionHandle, t.RegionHandle); + Assert.AreEqual(s.SeedCapability, t.SeedCapability); + Assert.AreEqual(s.SimAccess, t.SimAccess); + } + + [Test] + public void EstablishAgentCommunicationMessage() + { + EstablishAgentCommunicationMessage s = new EstablishAgentCommunicationMessage(); + s.Address = testIP; + s.AgentID = UUID.Random(); + s.Port = 3000; + s.SeedCapability = testURI; + + OSDMap map = s.Serialize(); + + EstablishAgentCommunicationMessage t = new EstablishAgentCommunicationMessage(); + t.Deserialize(map); + + Assert.AreEqual(s.Address, t.Address); + Assert.AreEqual(s.AgentID, t.AgentID); + Assert.AreEqual(s.Port, t.Port); + Assert.AreEqual(s.SeedCapability, t.SeedCapability); + } + + [Test] + public void ParcelObjectOwnersMessage() + { + ParcelObjectOwnersReplyMessage s = new ParcelObjectOwnersReplyMessage(); + s.PrimOwnersBlock = new ParcelObjectOwnersReplyMessage.PrimOwner[2]; + + ParcelObjectOwnersReplyMessage.PrimOwner obj = new ParcelObjectOwnersReplyMessage.PrimOwner(); + obj.OwnerID = UUID.Random(); + obj.Count = 10; + obj.IsGroupOwned = true; + obj.OnlineStatus = false; + obj.TimeStamp = new DateTime(2010, 4, 13, 7, 19, 43); + s.PrimOwnersBlock[0] = obj; + + ParcelObjectOwnersReplyMessage.PrimOwner obj1 = new ParcelObjectOwnersReplyMessage.PrimOwner(); + obj1.OwnerID = UUID.Random(); + obj1.Count = 0; + obj1.IsGroupOwned = false; + obj1.OnlineStatus = false; + obj1.TimeStamp = new DateTime(1991, 1, 31, 3, 13, 31); + s.PrimOwnersBlock[1] = obj1; + + OSDMap map = s.Serialize(); + + ParcelObjectOwnersReplyMessage t = new ParcelObjectOwnersReplyMessage(); + t.Deserialize(map); + + for (int i = 0; i < t.PrimOwnersBlock.Length; i++) + { + Assert.AreEqual(s.PrimOwnersBlock[i].Count, t.PrimOwnersBlock[i].Count); + Assert.AreEqual(s.PrimOwnersBlock[i].IsGroupOwned, t.PrimOwnersBlock[i].IsGroupOwned); + Assert.AreEqual(s.PrimOwnersBlock[i].OnlineStatus, t.PrimOwnersBlock[i].OnlineStatus); + Assert.AreEqual(s.PrimOwnersBlock[i].OwnerID, t.PrimOwnersBlock[i].OwnerID); + Assert.AreEqual(s.PrimOwnersBlock[i].TimeStamp, t.PrimOwnersBlock[i].TimeStamp); + } + } + + [Test] + public void ChatterBoxInvitationMessage() + { + ChatterBoxInvitationMessage s = new ChatterBoxInvitationMessage(); + s.BinaryBucket = Utils.EmptyBytes; + s.Dialog = InstantMessageDialog.InventoryOffered; + s.FromAgentID = UUID.Random(); + s.FromAgentName = "Prokofy Neva"; + s.GroupIM = false; + s.IMSessionID = s.FromAgentID ^ UUID.Random(); + s.Message = "Test Test Test"; + s.Offline = InstantMessageOnline.Online; + s.ParentEstateID = 1; + s.Position = Vector3.One; + s.RegionID = UUID.Random(); + s.Timestamp = DateTime.UtcNow; + s.ToAgentID = UUID.Random(); + + OSDMap map = s.Serialize(); + + ChatterBoxInvitationMessage t = new ChatterBoxInvitationMessage(); + t.Deserialize(map); + + Assert.AreEqual(s.BinaryBucket, t.BinaryBucket); + Assert.AreEqual(s.Dialog, t.Dialog); + Assert.AreEqual(s.FromAgentID, t.FromAgentID); + Assert.AreEqual(s.FromAgentName, t.FromAgentName); + Assert.AreEqual(s.GroupIM, t.GroupIM); + Assert.AreEqual(s.IMSessionID, t.IMSessionID); + Assert.AreEqual(s.Message, t.Message); + Assert.AreEqual(s.Offline, t.Offline); + Assert.AreEqual(s.ParentEstateID, t.ParentEstateID); + Assert.AreEqual(s.Position, t.Position); + Assert.AreEqual(s.RegionID, t.RegionID); + Assert.AreEqual(s.Timestamp, t.Timestamp); + Assert.AreEqual(s.ToAgentID, t.ToAgentID); + } + + [Test] + public void ChatterboxSessionEventReplyMessage() + { + ChatterboxSessionEventReplyMessage s = new ChatterboxSessionEventReplyMessage(); + s.SessionID = UUID.Random(); + s.Success = true; + + OSDMap map = s.Serialize(); + + ChatterboxSessionEventReplyMessage t = new ChatterboxSessionEventReplyMessage(); + t.Deserialize(map); + + Assert.AreEqual(s.SessionID, t.SessionID); + Assert.AreEqual(s.Success, t.Success); + } + + [Test] + public void ChatterBoxSessionStartReplyMessage() + { + ChatterBoxSessionStartReplyMessage s = new ChatterBoxSessionStartReplyMessage(); + s.ModeratedVoice = true; + s.SessionID = UUID.Random(); + s.SessionName = "Test Session"; + s.Success = true; + s.TempSessionID = UUID.Random(); + s.Type = 1; + s.VoiceEnabled = true; + + OSDMap map = s.Serialize(); + + ChatterBoxSessionStartReplyMessage t = new ChatterBoxSessionStartReplyMessage(); + t.Deserialize(map); + + Assert.AreEqual(s.ModeratedVoice, t.ModeratedVoice); + Assert.AreEqual(s.SessionID, t.SessionID); + Assert.AreEqual(s.SessionName, t.SessionName); + Assert.AreEqual(s.Success, t.Success); + Assert.AreEqual(s.TempSessionID, t.TempSessionID); + Assert.AreEqual(s.Type, t.Type); + Assert.AreEqual(s.VoiceEnabled, t.VoiceEnabled); + } + + [Test] + public void ChatterBoxSessionAgentListUpdatesMessage() + { + ChatterBoxSessionAgentListUpdatesMessage s = new ChatterBoxSessionAgentListUpdatesMessage(); + s.SessionID = UUID.Random(); + s.Updates = new ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock[1]; + + ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock block1 = new ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock(); + block1.AgentID = UUID.Random(); + block1.CanVoiceChat = true; + block1.IsModerator = true; + block1.MuteText = true; + block1.MuteVoice = true; + block1.Transition = "ENTER"; + + ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock block2 = new ChatterBoxSessionAgentListUpdatesMessage.AgentUpdatesBlock(); + block2.AgentID = UUID.Random(); + block2.CanVoiceChat = true; + block2.IsModerator = true; + block2.MuteText = true; + block2.MuteVoice = true; + block2.Transition = "LEAVE"; + + s.Updates[0] = block1; + // s.Updates[1] = block2; + + OSDMap map = s.Serialize(); + + ChatterBoxSessionAgentListUpdatesMessage t = new ChatterBoxSessionAgentListUpdatesMessage(); + t.Deserialize(map); + + Assert.AreEqual(s.SessionID, t.SessionID); + for (int i = 0; i < t.Updates.Length; i++) + { + Assert.AreEqual(s.Updates[i].AgentID, t.Updates[i].AgentID); + Assert.AreEqual(s.Updates[i].CanVoiceChat, t.Updates[i].CanVoiceChat); + Assert.AreEqual(s.Updates[i].IsModerator, t.Updates[i].IsModerator); + Assert.AreEqual(s.Updates[i].MuteText, t.Updates[i].MuteText); + Assert.AreEqual(s.Updates[i].MuteVoice, t.Updates[i].MuteVoice); + Assert.AreEqual(s.Updates[i].Transition, t.Updates[i].Transition); + } + } + + [Test] + public void ViewerStatsMessage() + { + ViewerStatsMessage s = new ViewerStatsMessage(); + + s.AgentFPS = 45.5f; + s.AgentsInView = 1; + s.SystemCPU = "Intel 80286"; + s.StatsDropped = 2; + s.StatsFailedResends = 3; + s.SystemGPU = "Vesa VGA+"; + s.SystemGPUClass = 4; + s.SystemGPUVendor = "China"; + s.SystemGPUVersion = String.Empty; + s.InCompressedPackets = 5000; + s.InKbytes = 6000; + s.InPackets = 22000; + s.InSavings = 19; + s.MiscInt1 = 5; + s.MiscInt2 = 6; + s.FailuresInvalid = 20; + s.AgentLanguage = "en"; + s.AgentMemoryUsed = 12878728; + s.MetersTraveled = 9999123; + s.object_kbytes = 70001; + s.FailuresOffCircuit = 201; + s.SystemOS = "Palm OS 3.1"; + s.OutCompressedPackets = 8000; + s.OutKbytes = 9000999; + s.OutPackets = 21000210; + s.OutSavings = 181; + s.AgentPing = 135579; + s.SystemInstalledRam = 4000000; + s.RegionsVisited = 4579; + s.FailuresResent = 9; + s.AgentRuntime = 360023; + s.FailuresSendPacket = 565; + s.SessionID = UUID.Random(); + s.SimulatorFPS = 454; + s.AgentStartTime = new DateTime(1973, 1, 16, 5, 23, 33); + s.MiscString1 = "Unused String"; + s.texture_kbytes = 9367498382; + s.AgentVersion = "1"; + s.MiscVersion = 1; + s.VertexBuffersEnabled = true; + s.world_kbytes = 232344439; + + OSDMap map = s.Serialize(); + ViewerStatsMessage t = new ViewerStatsMessage(); + t.Deserialize(map); + + Assert.AreEqual(s.AgentFPS, t.AgentFPS); + Assert.AreEqual(s.AgentsInView, t.AgentsInView); + Assert.AreEqual(s.SystemCPU, t.SystemCPU); + Assert.AreEqual(s.StatsDropped, t.StatsDropped); + Assert.AreEqual(s.StatsFailedResends, t.StatsFailedResends); + Assert.AreEqual(s.SystemGPU, t.SystemGPU); + Assert.AreEqual(s.SystemGPUClass, t.SystemGPUClass); + Assert.AreEqual(s.SystemGPUVendor, t.SystemGPUVendor); + Assert.AreEqual(s.SystemGPUVersion, t.SystemGPUVersion); + Assert.AreEqual(s.InCompressedPackets, t.InCompressedPackets); + Assert.AreEqual(s.InKbytes, t.InKbytes); + Assert.AreEqual(s.InPackets, t.InPackets); + Assert.AreEqual(s.InSavings, t.InSavings); + Assert.AreEqual(s.MiscInt1, t.MiscInt1); + Assert.AreEqual(s.MiscInt2, t.MiscInt2); + Assert.AreEqual(s.FailuresInvalid, t.FailuresInvalid); + Assert.AreEqual(s.AgentLanguage, t.AgentLanguage); + Assert.AreEqual(s.AgentMemoryUsed, t.AgentMemoryUsed); + Assert.AreEqual(s.MetersTraveled, t.MetersTraveled); + Assert.AreEqual(s.object_kbytes, t.object_kbytes); + Assert.AreEqual(s.FailuresOffCircuit, t.FailuresOffCircuit); + Assert.AreEqual(s.SystemOS, t.SystemOS); + Assert.AreEqual(s.OutCompressedPackets, t.OutCompressedPackets); + Assert.AreEqual(s.OutKbytes, t.OutKbytes); + Assert.AreEqual(s.OutPackets, t.OutPackets); + Assert.AreEqual(s.OutSavings, t.OutSavings); + Assert.AreEqual(s.AgentPing, t.AgentPing); + Assert.AreEqual(s.SystemInstalledRam, t.SystemInstalledRam); + Assert.AreEqual(s.RegionsVisited, t.RegionsVisited); + Assert.AreEqual(s.FailuresResent, t.FailuresResent); + Assert.AreEqual(s.AgentRuntime, t.AgentRuntime); + Assert.AreEqual(s.FailuresSendPacket, t.FailuresSendPacket); + Assert.AreEqual(s.SessionID, t.SessionID); + Assert.AreEqual(s.SimulatorFPS, t.SimulatorFPS); + Assert.AreEqual(s.AgentStartTime, t.AgentStartTime); + Assert.AreEqual(s.MiscString1, t.MiscString1); + Assert.AreEqual(s.texture_kbytes, t.texture_kbytes); + Assert.AreEqual(s.AgentVersion, t.AgentVersion); + Assert.AreEqual(s.MiscVersion, t.MiscVersion); + Assert.AreEqual(s.VertexBuffersEnabled, t.VertexBuffersEnabled); + Assert.AreEqual(s.world_kbytes, t.world_kbytes); + + + } + + [Test] + public void ParcelVoiceInfoRequestMessage() + { + ParcelVoiceInfoRequestMessage s = new ParcelVoiceInfoRequestMessage(); + s.SipChannelUri = testURI; + s.ParcelID = 1; + s.RegionName = "Hooper"; + + OSDMap map = s.Serialize(); + + ParcelVoiceInfoRequestMessage t = new ParcelVoiceInfoRequestMessage(); + t.Deserialize(map); + + Assert.AreEqual(s.SipChannelUri, t.SipChannelUri); + Assert.AreEqual(s.ParcelID, t.ParcelID); + Assert.AreEqual(s.RegionName, t.RegionName); + } + + [Test] + public void ScriptRunningReplyMessage() + { + ScriptRunningReplyMessage s = new ScriptRunningReplyMessage(); + s.ItemID = UUID.Random(); + s.Mono = true; + s.Running = true; + s.ObjectID = UUID.Random(); + + OSDMap map = s.Serialize(); + + ScriptRunningReplyMessage t = new ScriptRunningReplyMessage(); + t.Deserialize(map); + + Assert.AreEqual(s.ItemID, t.ItemID); + Assert.AreEqual(s.Mono, t.Mono); + Assert.AreEqual(s.ObjectID, t.ObjectID); + Assert.AreEqual(s.Running, t.Running); + + } + + [Test] + public void MapLayerMessage() + { + + MapLayerReplyVariant s = new MapLayerReplyVariant(); + s.Flags = 1; + + MapLayerReplyVariant.LayerData[] blocks = new MapLayerReplyVariant.LayerData[2]; + + MapLayerReplyVariant.LayerData block = new MapLayerReplyVariant.LayerData(); + block.ImageID = UUID.Random(); + block.Bottom = 1; + block.Top = 2; + block.Left = 3; + block.Right = 4; + + + + blocks[0] = block; + + block.ImageID = UUID.Random(); + block.Bottom = 5; + block.Top = 6; + block.Left = 7; + block.Right = 9; + + blocks[1] = block; + + s.LayerDataBlocks = blocks; + + OSDMap map = s.Serialize(); + + MapLayerReplyVariant t = new MapLayerReplyVariant(); + + t.Deserialize(map); + + Assert.AreEqual(s.Flags, t.Flags); + + + for (int i = 0; i < s.LayerDataBlocks.Length; i++) + { + Assert.AreEqual(s.LayerDataBlocks[i].ImageID, t.LayerDataBlocks[i].ImageID); + Assert.AreEqual(s.LayerDataBlocks[i].Top, t.LayerDataBlocks[i].Top); + Assert.AreEqual(s.LayerDataBlocks[i].Left, t.LayerDataBlocks[i].Left); + Assert.AreEqual(s.LayerDataBlocks[i].Right, t.LayerDataBlocks[i].Right); + Assert.AreEqual(s.LayerDataBlocks[i].Bottom, t.LayerDataBlocks[i].Bottom); + } + } + + [Test] // VARIANT A + public void ChatSessionRequestStartConference() + { + ChatSessionRequestStartConference s = new ChatSessionRequestStartConference(); + s.SessionID = UUID.Random(); + s.AgentsBlock = new UUID[2]; + s.AgentsBlock[0] = UUID.Random(); + s.AgentsBlock[0] = UUID.Random(); + + OSDMap map = s.Serialize(); + + ChatSessionRequestStartConference t = new ChatSessionRequestStartConference(); + t.Deserialize(map); + + Assert.AreEqual(s.SessionID, t.SessionID); + Assert.AreEqual(s.Method, t.Method); + for (int i = 0; i < t.AgentsBlock.Length; i++) + { + Assert.AreEqual(s.AgentsBlock[i], t.AgentsBlock[i]); + } + } + + [Test] + public void ChatSessionRequestMuteUpdate() + { + ChatSessionRequestMuteUpdate s = new ChatSessionRequestMuteUpdate(); + s.AgentID = UUID.Random(); + s.RequestKey = "text"; + s.RequestValue = true; + s.SessionID = UUID.Random(); + + OSDMap map = s.Serialize(); + + ChatSessionRequestMuteUpdate t = new ChatSessionRequestMuteUpdate(); + t.Deserialize(map); + + Assert.AreEqual(s.AgentID, t.AgentID); + Assert.AreEqual(s.Method, t.Method); + Assert.AreEqual(s.RequestKey, t.RequestKey); + Assert.AreEqual(s.RequestValue, t.RequestValue); + Assert.AreEqual(s.SessionID, t.SessionID); + } + + [Test] + public void ChatSessionAcceptInvitation() + { + ChatSessionAcceptInvitation s = new ChatSessionAcceptInvitation(); + s.SessionID = UUID.Random(); + + OSDMap map = s.Serialize(); + + ChatSessionAcceptInvitation t = new ChatSessionAcceptInvitation(); + t.Deserialize(map); + + Assert.AreEqual(s.Method, t.Method); + Assert.AreEqual(s.SessionID, t.SessionID); + } + + [Test] + public void RequiredVoiceVersionMessage() + { + RequiredVoiceVersionMessage s = new RequiredVoiceVersionMessage(); + s.MajorVersion = 1; + s.MinorVersion = 0; + s.RegionName = "Hooper"; + + OSDMap map = s.Serialize(); + + RequiredVoiceVersionMessage t = new RequiredVoiceVersionMessage(); + t.Deserialize(map); + + Assert.AreEqual(s.MajorVersion, t.MajorVersion); + Assert.AreEqual(s.MinorVersion, t.MinorVersion); + Assert.AreEqual(s.RegionName, t.RegionName); + } + + [Test] + public void CopyInventoryFromNotecardMessage() + { + CopyInventoryFromNotecardMessage s = new CopyInventoryFromNotecardMessage(); + s.CallbackID = 1; + s.FolderID = UUID.Random(); + s.ItemID = UUID.Random(); + s.NotecardID = UUID.Random(); + s.ObjectID = UUID.Random(); + + OSDMap map = s.Serialize(); + + CopyInventoryFromNotecardMessage t = new CopyInventoryFromNotecardMessage(); + t.Deserialize(map); + + Assert.AreEqual(s.CallbackID, t.CallbackID); + Assert.AreEqual(s.FolderID, t.FolderID); + Assert.AreEqual(s.ItemID, t.ItemID); + Assert.AreEqual(s.NotecardID, t.NotecardID); + Assert.AreEqual(s.ObjectID, t.ObjectID); + } + + [Test] + public void ProvisionVoiceAccountRequestMessage() + { + ProvisionVoiceAccountRequestMessage s = new ProvisionVoiceAccountRequestMessage(); + s.Username = "username"; + s.Password = "password"; + + OSDMap map = s.Serialize(); + + ProvisionVoiceAccountRequestMessage t = new ProvisionVoiceAccountRequestMessage(); + t.Deserialize(map); + + Assert.AreEqual(s.Password, t.Password); + Assert.AreEqual(s.Username, t.Username); + } + + [Test] + public void UpdateAgentLanguageMessage() + { + UpdateAgentLanguageMessage s = new UpdateAgentLanguageMessage(); + s.Language = "en"; + s.LanguagePublic = false; + + OSDMap map = s.Serialize(); + + UpdateAgentLanguageMessage t = new UpdateAgentLanguageMessage(); + t.Deserialize(map); + + Assert.AreEqual(s.Language, t.Language); + Assert.AreEqual(s.LanguagePublic, t.LanguagePublic); + + } + + [Test] + public void ParcelPropertiesMessage() + { + ParcelPropertiesMessage s = new ParcelPropertiesMessage(); + s.AABBMax = Vector3.Parse("<1,2,3>"); + s.AABBMin = Vector3.Parse("<2,3,1>"); + s.Area = 1024; + s.AuctionID = uint.MaxValue; + s.AuthBuyerID = UUID.Random(); + s.Bitmap = Utils.EmptyBytes; + s.Category = ParcelCategory.Educational; + s.ClaimDate = new DateTime(2008, 12, 25, 3, 15, 22); + s.ClaimPrice = 1000; + s.Desc = "Test Description"; + s.GroupID = UUID.Random(); + s.GroupPrims = 50; + s.IsGroupOwned = false; + s.LandingType = LandingType.None; + s.LocalID = 1; + s.MaxPrims = 234; + s.MediaAutoScale = false; + s.MediaDesc = "Example Media Description"; + s.MediaHeight = 480; + s.MediaID = UUID.Random(); + s.MediaLoop = false; + s.MediaType = "text/html"; + s.MediaURL = "http://www.openmetaverse.co"; + s.MediaWidth = 640; + s.MusicURL = "http://scfire-ntc-aa04.stream.aol.com:80/stream/1075"; // Yee Haw + s.Name = "Test Name"; + s.ObscureMedia = false; + s.ObscureMusic = false; + s.OtherCleanTime = 5; + s.OtherCount = 200; + s.OtherPrims = 300; + s.OwnerID = UUID.Random(); + s.OwnerPrims = 0; + s.ParcelFlags = ParcelFlags.AllowDamage | ParcelFlags.AllowGroupScripts | ParcelFlags.AllowVoiceChat; + s.ParcelPrimBonus = 0f; + s.PassHours = 1.5f; + s.PassPrice = 10; + s.PublicCount = 20; + s.RegionDenyAgeUnverified = false; + s.RegionDenyAnonymous = false; + s.RegionPushOverride = true; + s.RentPrice = 0; + s.RequestResult = ParcelResult.Single; + s.SalePrice = 9999; + s.SelectedPrims = 1; + s.SelfCount = 2; + s.SequenceID = -4000; + s.SimWideMaxPrims = 937; + s.SimWideTotalPrims = 117; + s.SnapSelection = false; + s.SnapshotID = UUID.Random(); + s.Status = ParcelStatus.Leased; + s.TotalPrims = 219; + s.UserLocation = Vector3.Parse("<3,4,5>"); + s.UserLookAt = Vector3.Parse("<5,4,3>"); + + OSDMap map = s.Serialize(); + ParcelPropertiesMessage t = new ParcelPropertiesMessage(); + + t.Deserialize(map); + + Assert.AreEqual(s.AABBMax, t.AABBMax); + Assert.AreEqual(s.AABBMin, t.AABBMin); + Assert.AreEqual(s.Area, t.Area); + Assert.AreEqual(s.AuctionID, t.AuctionID); + Assert.AreEqual(s.AuthBuyerID, t.AuthBuyerID); + Assert.AreEqual(s.Bitmap, t.Bitmap); + Assert.AreEqual(s.Category, t.Category); + Assert.AreEqual(s.ClaimDate, t.ClaimDate); + Assert.AreEqual(s.ClaimPrice, t.ClaimPrice); + Assert.AreEqual(s.Desc, t.Desc); + Assert.AreEqual(s.GroupID, t.GroupID); + Assert.AreEqual(s.GroupPrims, t.GroupPrims); + Assert.AreEqual(s.IsGroupOwned, t.IsGroupOwned); + Assert.AreEqual(s.LandingType, t.LandingType); + Assert.AreEqual(s.LocalID, t.LocalID); + Assert.AreEqual(s.MaxPrims, t.MaxPrims); + Assert.AreEqual(s.MediaAutoScale, t.MediaAutoScale); + Assert.AreEqual(s.MediaDesc, t.MediaDesc); + Assert.AreEqual(s.MediaHeight, t.MediaHeight); + Assert.AreEqual(s.MediaID, t.MediaID); + Assert.AreEqual(s.MediaLoop, t.MediaLoop); + Assert.AreEqual(s.MediaType, t.MediaType); + Assert.AreEqual(s.MediaURL, t.MediaURL); + Assert.AreEqual(s.MediaWidth, t.MediaWidth); + Assert.AreEqual(s.MusicURL, t.MusicURL); + Assert.AreEqual(s.Name, t.Name); + Assert.AreEqual(s.ObscureMedia, t.ObscureMedia); + Assert.AreEqual(s.ObscureMusic, t.ObscureMusic); + Assert.AreEqual(s.OtherCleanTime, t.OtherCleanTime); + Assert.AreEqual(s.OtherCount, t.OtherCount); + Assert.AreEqual(s.OtherPrims, t.OtherPrims); + Assert.AreEqual(s.OwnerID, t.OwnerID); + Assert.AreEqual(s.OwnerPrims, t.OwnerPrims); + Assert.AreEqual(s.ParcelFlags, t.ParcelFlags); + Assert.AreEqual(s.ParcelPrimBonus, t.ParcelPrimBonus); + Assert.AreEqual(s.PassHours, t.PassHours); + Assert.AreEqual(s.PassPrice, t.PassPrice); + Assert.AreEqual(s.PublicCount, t.PublicCount); + Assert.AreEqual(s.RegionDenyAgeUnverified, t.RegionDenyAgeUnverified); + Assert.AreEqual(s.RegionDenyAnonymous, t.RegionDenyAnonymous); + Assert.AreEqual(s.RegionPushOverride, t.RegionPushOverride); + Assert.AreEqual(s.RentPrice, t.RentPrice); + Assert.AreEqual(s.RequestResult, t.RequestResult); + Assert.AreEqual(s.SalePrice, t.SalePrice); + Assert.AreEqual(s.SelectedPrims, t.SelectedPrims); + Assert.AreEqual(s.SelfCount, t.SelfCount); + Assert.AreEqual(s.SequenceID, t.SequenceID); + Assert.AreEqual(s.SimWideMaxPrims, t.SimWideMaxPrims); + Assert.AreEqual(s.SimWideTotalPrims, t.SimWideTotalPrims); + Assert.AreEqual(s.SnapSelection, t.SnapSelection); + Assert.AreEqual(s.SnapshotID, t.SnapshotID); + Assert.AreEqual(s.Status, t.Status); + Assert.AreEqual(s.TotalPrims, t.TotalPrims); + Assert.AreEqual(s.UserLocation, t.UserLocation); + Assert.AreEqual(s.UserLookAt, t.UserLookAt); + } + + [Test] + public void ParcelPropertiesUpdateMessage() + { + ParcelPropertiesUpdateMessage s = new ParcelPropertiesUpdateMessage(); + s.AuthBuyerID = UUID.Random(); + s.Category = ParcelCategory.Gaming; + s.Desc = "Example Description"; + s.GroupID = UUID.Random(); + s.Landing = LandingType.LandingPoint; + s.LocalID = 160; + s.MediaAutoScale = true; + s.MediaDesc = "Example Media Description"; + s.MediaHeight = 600; + s.MediaID = UUID.Random(); + s.MediaLoop = false; + s.MediaType = "image/jpeg"; + s.MediaURL = "http://www.openmetaverse.co/test.jpeg"; + s.MediaWidth = 800; + s.MusicURL = "http://scfire-ntc-aa04.stream.aol.com:80/stream/1075"; + s.Name = "Example Parcel Description"; + s.ObscureMedia = true; + s.ObscureMusic = true; + s.ParcelFlags = ParcelFlags.AllowVoiceChat | ParcelFlags.ContributeWithDeed; + s.PassHours = 5.5f; + s.PassPrice = 100; + s.SalePrice = 99; + s.SnapshotID = UUID.Random(); + s.UserLocation = Vector3.Parse("<128,128,128>"); + s.UserLookAt = Vector3.Parse("<256,256,256>"); + + OSDMap map = s.Serialize(); + + ParcelPropertiesUpdateMessage t = new ParcelPropertiesUpdateMessage(); + + t.Deserialize(map); + + Assert.AreEqual(s.AuthBuyerID, t.AuthBuyerID); + Assert.AreEqual(s.Category, t.Category); + Assert.AreEqual(s.Desc, t.Desc); + Assert.AreEqual(s.GroupID, t.GroupID); + Assert.AreEqual(s.Landing, t.Landing); + Assert.AreEqual(s.LocalID, t.LocalID); + Assert.AreEqual(s.MediaAutoScale, t.MediaAutoScale); + Assert.AreEqual(s.MediaDesc, t.MediaDesc); + Assert.AreEqual(s.MediaHeight, t.MediaHeight); + Assert.AreEqual(s.MediaID, t.MediaID); + Assert.AreEqual(s.MediaLoop, t.MediaLoop); + Assert.AreEqual(s.MediaType, t.MediaType); + Assert.AreEqual(s.MediaURL, t.MediaURL); + Assert.AreEqual(s.MediaWidth, t.MediaWidth); + Assert.AreEqual(s.MusicURL, t.MusicURL); + Assert.AreEqual(s.Name, t.Name); + Assert.AreEqual(s.ObscureMedia, t.ObscureMedia); + Assert.AreEqual(s.ObscureMusic, t.ObscureMusic); + Assert.AreEqual(s.ParcelFlags, t.ParcelFlags); + Assert.AreEqual(s.PassHours, t.PassHours); + Assert.AreEqual(s.PassPrice, t.PassPrice); + Assert.AreEqual(s.SalePrice, t.SalePrice); + Assert.AreEqual(s.SnapshotID, t.SnapshotID); + Assert.AreEqual(s.UserLocation, t.UserLocation); + Assert.AreEqual(s.UserLookAt, t.UserLookAt); + } + [Test] + public void EnableSimulatorMessage() + { + EnableSimulatorMessage s = new EnableSimulatorMessage(); + s.Simulators = new EnableSimulatorMessage.SimulatorInfoBlock[2]; + + EnableSimulatorMessage.SimulatorInfoBlock block1 = new EnableSimulatorMessage.SimulatorInfoBlock(); + block1.IP = testIP; + block1.Port = 3000; + block1.RegionHandle = testHandle; + s.Simulators[0] = block1; + + EnableSimulatorMessage.SimulatorInfoBlock block2 = new EnableSimulatorMessage.SimulatorInfoBlock(); + block2.IP = testIP; + block2.Port = 3001; + block2.RegionHandle = testHandle; + s.Simulators[1] = block2; + + OSDMap map = s.Serialize(); + + EnableSimulatorMessage t = new EnableSimulatorMessage(); + t.Deserialize(map); + + for (int i = 0; i < t.Simulators.Length; i++) + { + Assert.AreEqual(s.Simulators[i].IP, t.Simulators[i].IP); + Assert.AreEqual(s.Simulators[i].Port, t.Simulators[i].Port); + Assert.AreEqual(s.Simulators[i].RegionHandle, t.Simulators[i].RegionHandle); + } + } + + [Test] + public void RemoteParcelRequestReply() + { + RemoteParcelRequestReply s = new RemoteParcelRequestReply(); + s.ParcelID = UUID.Random(); + OSDMap map = s.Serialize(); + + RemoteParcelRequestReply t = new RemoteParcelRequestReply(); + t.Deserialize(map); + + Assert.AreEqual(s.ParcelID, t.ParcelID); + } + + [Test] + public void UpdateScriptTaskMessage() + { + UpdateScriptTaskUpdateMessage s = new UpdateScriptTaskUpdateMessage(); + s.TaskID = UUID.Random(); + s.Target = "mono"; + s.ScriptRunning = true; + s.ItemID = UUID.Random(); + + OSDMap map = s.Serialize(); + UpdateScriptTaskUpdateMessage t = new UpdateScriptTaskUpdateMessage(); + t.Deserialize(map); + + Assert.AreEqual(s.ItemID, t.ItemID); + Assert.AreEqual(s.ScriptRunning, t.ScriptRunning); + Assert.AreEqual(s.Target, t.Target); + Assert.AreEqual(s.TaskID, t.TaskID); + } + + [Test] + public void UpdateScriptAgentMessage() + { + UpdateScriptAgentRequestMessage s = new UpdateScriptAgentRequestMessage(); + s.ItemID = UUID.Random(); + s.Target = "lsl2"; + + OSDMap map = s.Serialize(); + + UpdateScriptAgentRequestMessage t = new UpdateScriptAgentRequestMessage(); + t.Deserialize(map); + + Assert.AreEqual(s.ItemID, t.ItemID); + Assert.AreEqual(s.Target, t.Target); + } + + [Test] + public void SendPostcardMessage() + { + SendPostcardMessage s = new SendPostcardMessage(); + s.FromEmail = "contact@openmetaverse.co"; + s.FromName = "Jim Radford"; + s.GlobalPosition = Vector3.One; + s.Message = "Hello, How are you today?"; + s.Subject = "Postcard from the edge"; + s.ToEmail = "test1@example.com"; + + OSDMap map = s.Serialize(); + + SendPostcardMessage t = new SendPostcardMessage(); + t.Deserialize(map); + + Assert.AreEqual(s.FromEmail, t.FromEmail); + Assert.AreEqual(s.FromName, t.FromName); + Assert.AreEqual(s.GlobalPosition, t.GlobalPosition); + Assert.AreEqual(s.Message, t.Message); + Assert.AreEqual(s.Subject, t.Subject); + Assert.AreEqual(s.ToEmail, t.ToEmail); + } + + [Test] + public void UpdateNotecardAgentInventoryMessage() + { + UpdateAgentInventoryRequestMessage s = new UpdateAgentInventoryRequestMessage(); + s.ItemID = UUID.Random(); + + OSDMap map = s.Serialize(); + + UpdateAgentInventoryRequestMessage t = new UpdateAgentInventoryRequestMessage(); + t.Deserialize(map); + + Assert.AreEqual(s.ItemID, t.ItemID); + } + + [Test] + public void LandStatReplyMessage() + { + LandStatReplyMessage s = new LandStatReplyMessage(); + s.ReportType = 22; + s.RequestFlags = 44; + s.TotalObjectCount = 2; + s.ReportDataBlocks = new LandStatReplyMessage.ReportDataBlock[2]; + + LandStatReplyMessage.ReportDataBlock block1 = new LandStatReplyMessage.ReportDataBlock(); + block1.Location = Vector3.One; + block1.MonoScore = 99; + block1.OwnerName = "Profoky Neva"; + block1.Score = 10; + block1.TaskID = UUID.Random(); + block1.TaskLocalID = 987341; + block1.TaskName = "Verbal Flogging"; + block1.TimeStamp = new DateTime(2009, 5, 23, 4, 30, 0); + s.ReportDataBlocks[0] = block1; + + LandStatReplyMessage.ReportDataBlock block2 = new LandStatReplyMessage.ReportDataBlock(); + block2.Location = Vector3.One; + block2.MonoScore = 1; + block2.OwnerName = "Philip Linden"; + block2.Score = 5; + block2.TaskID = UUID.Random(); + block2.TaskLocalID = 987342; + block2.TaskName = "Happy Ant"; + block2.TimeStamp = new DateTime(2008, 4, 22, 3, 29, 55); + s.ReportDataBlocks[1] = block2; + + OSDMap map = s.Serialize(); + + LandStatReplyMessage t = new LandStatReplyMessage(); + t.Deserialize(map); + + Assert.AreEqual(s.ReportType, t.ReportType); + Assert.AreEqual(s.RequestFlags, t.RequestFlags); + Assert.AreEqual(s.TotalObjectCount, t.TotalObjectCount); + + for (int i = 0; i < t.ReportDataBlocks.Length; i++) + { + Assert.AreEqual(s.ReportDataBlocks[i].Location, t.ReportDataBlocks[i].Location); + Assert.AreEqual(s.ReportDataBlocks[i].MonoScore, t.ReportDataBlocks[i].MonoScore); + Assert.AreEqual(s.ReportDataBlocks[i].OwnerName, t.ReportDataBlocks[i].OwnerName); + Assert.AreEqual(s.ReportDataBlocks[i].Score, t.ReportDataBlocks[i].Score); + Assert.AreEqual(s.ReportDataBlocks[i].TaskID, t.ReportDataBlocks[i].TaskID); + Assert.AreEqual(s.ReportDataBlocks[i].TaskLocalID, t.ReportDataBlocks[i].TaskLocalID); + Assert.AreEqual(s.ReportDataBlocks[i].TaskName, t.ReportDataBlocks[i].TaskName); + Assert.AreEqual(s.ReportDataBlocks[i].TimeStamp, t.ReportDataBlocks[i].TimeStamp); + } + } + + [Test] + public void TelportFailedMessage() + { + TeleportFailedMessage s = new TeleportFailedMessage(); + s.AgentID = UUID.Random(); + s.MessageKey = "Key"; + s.Reason = "Unable To Teleport for some unspecified reason"; + s.ExtraParams = String.Empty; + + OSDMap map = s.Serialize(); + + TeleportFailedMessage t = new TeleportFailedMessage(); + t.Deserialize(map); + + Assert.AreEqual(s.AgentID, t.AgentID); + Assert.AreEqual(s.ExtraParams, t.ExtraParams); + Assert.AreEqual(s.MessageKey, t.MessageKey); + Assert.AreEqual(s.Reason, t.Reason); + + } + + [Test] + public void UpdateAgentInformationMessage() + { + UpdateAgentInformationMessage s = new UpdateAgentInformationMessage(); + s.MaxAccess = "PG"; + OSDMap map = s.Serialize(); + + UpdateAgentInformationMessage t = new UpdateAgentInformationMessage(); + t.Deserialize(map); + + Assert.AreEqual(s.MaxAccess, t.MaxAccess); + } + + [Test] + public void PlacesReplyMessage() + { + PlacesReplyMessage s = new PlacesReplyMessage(); + s.TransactionID = UUID.Random(); + s.AgentID = UUID.Random(); + s.QueryID = UUID.Random(); + s.QueryDataBlocks = new PlacesReplyMessage.QueryData[2]; + + PlacesReplyMessage.QueryData q1 = new PlacesReplyMessage.QueryData(); + q1.ActualArea = 1024; + q1.BillableArea = 768; + q1.Description = "Test Description Q1"; + q1.Dwell = 1435.4f; + q1.Flags = 1 << 6; + q1.GlobalX = 1; + q1.GlobalY = 2; + q1.GlobalZ = 3; + q1.Name = "Test Name Q1"; + q1.OwnerID = UUID.Random(); + q1.Price = 1; + q1.ProductSku = "021"; + q1.SimName = "Hooper"; + q1.SnapShotID = UUID.Random(); + + s.QueryDataBlocks[0] = q1; + + PlacesReplyMessage.QueryData q2 = new PlacesReplyMessage.QueryData(); + q2.ActualArea = 512; + q2.BillableArea = 384; + q2.Description = "Test Description Q2"; + q2.Dwell = 1; + q2.Flags = 1 << 4; + q2.GlobalX = 4; + q2.GlobalY = 5; + q2.GlobalZ = 6; + q2.Name = "Test Name Q2"; + q2.OwnerID = UUID.Random(); + q2.Price = 2; + q2.ProductSku = "022"; + q2.SimName = "Tethys"; + q2.SnapShotID = UUID.Random(); + + s.QueryDataBlocks[1] = q2; + + OSDMap map = s.Serialize(); + + PlacesReplyMessage t = new PlacesReplyMessage(); + t.Deserialize(map); + + Assert.AreEqual(s.AgentID, t.AgentID); + Assert.AreEqual(s.TransactionID, t.TransactionID); + Assert.AreEqual(s.QueryID, t.QueryID); + + for (int i = 0; i < s.QueryDataBlocks.Length; i++) + { + Assert.AreEqual(s.QueryDataBlocks[i].ActualArea, t.QueryDataBlocks[i].ActualArea); + Assert.AreEqual(s.QueryDataBlocks[i].BillableArea, t.QueryDataBlocks[i].BillableArea); + Assert.AreEqual(s.QueryDataBlocks[i].Description, t.QueryDataBlocks[i].Description); + Assert.AreEqual(s.QueryDataBlocks[i].Dwell, t.QueryDataBlocks[i].Dwell); + Assert.AreEqual(s.QueryDataBlocks[i].Flags, t.QueryDataBlocks[i].Flags); + Assert.AreEqual(s.QueryDataBlocks[i].GlobalX, t.QueryDataBlocks[i].GlobalX); + Assert.AreEqual(s.QueryDataBlocks[i].GlobalY, t.QueryDataBlocks[i].GlobalY); + Assert.AreEqual(s.QueryDataBlocks[i].GlobalZ, t.QueryDataBlocks[i].GlobalZ); + Assert.AreEqual(s.QueryDataBlocks[i].Name, t.QueryDataBlocks[i].Name); + Assert.AreEqual(s.QueryDataBlocks[i].OwnerID, t.QueryDataBlocks[i].OwnerID); + Assert.AreEqual(s.QueryDataBlocks[i].Price, t.QueryDataBlocks[i].Price); + Assert.AreEqual(s.QueryDataBlocks[i].ProductSku, t.QueryDataBlocks[i].ProductSku); + Assert.AreEqual(s.QueryDataBlocks[i].SimName, t.QueryDataBlocks[i].SimName); + Assert.AreEqual(s.QueryDataBlocks[i].SnapShotID, t.QueryDataBlocks[i].SnapShotID); + } + } + + [Test] + public void DirLandReplyMessage() + { + DirLandReplyMessage s = new DirLandReplyMessage(); + s.AgentID = UUID.Random(); + s.QueryID = UUID.Random(); + s.QueryReplies = new DirLandReplyMessage.QueryReply[2]; + + DirLandReplyMessage.QueryReply q1 = new DirLandReplyMessage.QueryReply(); + q1.ActualArea = 1024; + q1.Auction = true; + q1.ForSale = true; + q1.Name = "For Sale Parcel Q1"; + q1.ProductSku = "023"; + q1.SalePrice = 2193; + q1.ParcelID = UUID.Random(); + + s.QueryReplies[0] = q1; + + DirLandReplyMessage.QueryReply q2 = new DirLandReplyMessage.QueryReply(); + q2.ActualArea = 512; + q2.Auction = true; + q2.ForSale = true; + q2.Name = "For Sale Parcel Q2"; + q2.ProductSku = "023"; + q2.SalePrice = 22193; + q2.ParcelID = UUID.Random(); + + s.QueryReplies[1] = q2; + + OSDMap map = s.Serialize(); + + DirLandReplyMessage t = new DirLandReplyMessage(); + t.Deserialize(map); + + Assert.AreEqual(s.AgentID, t.AgentID); + Assert.AreEqual(s.QueryID, t.QueryID); + + for (int i = 0; i < s.QueryReplies.Length; i++) + { + Assert.AreEqual(s.QueryReplies[i].ActualArea, t.QueryReplies[i].ActualArea); + Assert.AreEqual(s.QueryReplies[i].Auction, t.QueryReplies[i].Auction); + Assert.AreEqual(s.QueryReplies[i].ForSale, t.QueryReplies[i].ForSale); + Assert.AreEqual(s.QueryReplies[i].Name, t.QueryReplies[i].Name); + Assert.AreEqual(s.QueryReplies[i].ProductSku, t.QueryReplies[i].ProductSku); + Assert.AreEqual(s.QueryReplies[i].ParcelID, t.QueryReplies[i].ParcelID); + Assert.AreEqual(s.QueryReplies[i].SalePrice, t.QueryReplies[i].SalePrice); + } + } + #region Performance Testing + + private const int TEST_ITER = 100000; + + [Test] + [Category("Benchmark")] + public void ReflectionPerformanceRemoteParcelResponse() + { + DateTime messageTestTime = DateTime.UtcNow; + for (int x = 0; x < TEST_ITER; x++) + { + RemoteParcelRequestReply s = new RemoteParcelRequestReply(); + s.ParcelID = UUID.Random(); + OSDMap map = s.Serialize(); + + RemoteParcelRequestReply t = new RemoteParcelRequestReply(); + t.Deserialize(map); + + Assert.AreEqual(s.ParcelID, t.ParcelID); + } + TimeSpan duration = DateTime.UtcNow - messageTestTime; + Console.WriteLine("RemoteParcelRequestReply: OMV Message System Serialization/Deserialization Passes: {0} Total time: {1}", TEST_ITER, duration); + + BinaryFormatter formatter = new BinaryFormatter(); + DateTime xmlTestTime = DateTime.UtcNow; + for (int x = 0; x < TEST_ITER; x++) + { + RemoteParcelRequestReply s = new RemoteParcelRequestReply(); + s.ParcelID = UUID.Random(); + + MemoryStream stream = new MemoryStream(); + + formatter.Serialize(stream, s); + + stream.Seek(0, SeekOrigin.Begin); + RemoteParcelRequestReply t = (RemoteParcelRequestReply)formatter.Deserialize(stream); + + Assert.AreEqual(s.ParcelID, t.ParcelID); + } + TimeSpan durationxml = DateTime.UtcNow - xmlTestTime; + Console.WriteLine("RemoteParcelRequestReply: .NET BinarySerialization/Deserialization Passes: {0} Total time: {1}", TEST_ITER, durationxml); + } + + + [Test] + [Category("Benchmark")] + public void ReflectionPerformanceDirLandReply() + { + + DateTime messageTestTime = DateTime.UtcNow; + for (int x = 0; x < TEST_ITER; x++) + { + DirLandReplyMessage s = new DirLandReplyMessage(); + s.AgentID = UUID.Random(); + s.QueryID = UUID.Random(); + s.QueryReplies = new DirLandReplyMessage.QueryReply[2]; + + DirLandReplyMessage.QueryReply q1 = new DirLandReplyMessage.QueryReply(); + q1.ActualArea = 1024; + q1.Auction = true; + q1.ForSale = true; + q1.Name = "For Sale Parcel Q1"; + q1.ProductSku = "023"; + q1.SalePrice = 2193; + q1.ParcelID = UUID.Random(); + + s.QueryReplies[0] = q1; + + DirLandReplyMessage.QueryReply q2 = new DirLandReplyMessage.QueryReply(); + q2.ActualArea = 512; + q2.Auction = true; + q2.ForSale = true; + q2.Name = "For Sale Parcel Q2"; + q2.ProductSku = "023"; + q2.SalePrice = 22193; + q2.ParcelID = UUID.Random(); + + s.QueryReplies[1] = q2; + + OSDMap map = s.Serialize(); + DirLandReplyMessage t = new DirLandReplyMessage(); + + t.Deserialize(map); + Assert.AreEqual(s.AgentID, t.AgentID); + Assert.AreEqual(s.QueryID, t.QueryID); + + for (int i = 0; i < s.QueryReplies.Length; i++) + { + Assert.AreEqual(s.QueryReplies[i].ActualArea, t.QueryReplies[i].ActualArea); + Assert.AreEqual(s.QueryReplies[i].Auction, t.QueryReplies[i].Auction); + Assert.AreEqual(s.QueryReplies[i].ForSale, t.QueryReplies[i].ForSale); + Assert.AreEqual(s.QueryReplies[i].Name, t.QueryReplies[i].Name); + Assert.AreEqual(s.QueryReplies[i].ProductSku, t.QueryReplies[i].ProductSku); + Assert.AreEqual(s.QueryReplies[i].ParcelID, t.QueryReplies[i].ParcelID); + Assert.AreEqual(s.QueryReplies[i].SalePrice, t.QueryReplies[i].SalePrice); + } + } + TimeSpan duration = DateTime.UtcNow - messageTestTime; + Console.WriteLine("DirLandReplyMessage: OMV Message System Serialization/Deserialization Passes: {0} Total time: {1}", TEST_ITER, duration); + + BinaryFormatter formatter = new BinaryFormatter(); + DateTime xmlTestTime = DateTime.UtcNow; + for (int x = 0; x < TEST_ITER; x++) + { + DirLandReplyMessage s = new DirLandReplyMessage(); + s.AgentID = UUID.Random(); + s.QueryID = UUID.Random(); + s.QueryReplies = new DirLandReplyMessage.QueryReply[2]; + + DirLandReplyMessage.QueryReply q1 = new DirLandReplyMessage.QueryReply(); + q1.ActualArea = 1024; + q1.Auction = true; + q1.ForSale = true; + q1.Name = "For Sale Parcel Q1"; + q1.ProductSku = "023"; + q1.SalePrice = 2193; + q1.ParcelID = UUID.Random(); + + s.QueryReplies[0] = q1; + + DirLandReplyMessage.QueryReply q2 = new DirLandReplyMessage.QueryReply(); + q2.ActualArea = 512; + q2.Auction = true; + q2.ForSale = true; + q2.Name = "For Sale Parcel Q2"; + q2.ProductSku = "023"; + q2.SalePrice = 22193; + q2.ParcelID = UUID.Random(); + + s.QueryReplies[1] = q2; + + MemoryStream stream = new MemoryStream(); + + formatter.Serialize(stream, s); + + stream.Seek(0, SeekOrigin.Begin); + DirLandReplyMessage t = (DirLandReplyMessage)formatter.Deserialize(stream); + + Assert.AreEqual(s.AgentID, t.AgentID); + Assert.AreEqual(s.QueryID, t.QueryID); + + for (int i = 0; i < s.QueryReplies.Length; i++) + { + Assert.AreEqual(s.QueryReplies[i].ActualArea, t.QueryReplies[i].ActualArea); + Assert.AreEqual(s.QueryReplies[i].Auction, t.QueryReplies[i].Auction); + Assert.AreEqual(s.QueryReplies[i].ForSale, t.QueryReplies[i].ForSale); + Assert.AreEqual(s.QueryReplies[i].Name, t.QueryReplies[i].Name); + Assert.AreEqual(s.QueryReplies[i].ProductSku, t.QueryReplies[i].ProductSku); + Assert.AreEqual(s.QueryReplies[i].ParcelID, t.QueryReplies[i].ParcelID); + Assert.AreEqual(s.QueryReplies[i].SalePrice, t.QueryReplies[i].SalePrice); + } + } + TimeSpan durationxml = DateTime.UtcNow - xmlTestTime; + Console.WriteLine("DirLandReplyMessage: .NET BinarySerialization/Deserialization Passes: {0} Total time: {1}", TEST_ITER, durationxml); + } + + [Test] + [Category("Benchmark")] + public void ReflectionPerformanceDirLandReply2() + { + XmlSerializer xmlSerializer = new XmlSerializer(typeof(DirLandReplyMessage)); + + DirLandReplyMessage s = new DirLandReplyMessage(); + s.AgentID = UUID.Random(); + s.QueryID = UUID.Random(); + s.QueryReplies = new DirLandReplyMessage.QueryReply[2]; + + DirLandReplyMessage.QueryReply q1 = new DirLandReplyMessage.QueryReply(); + q1.ActualArea = 1024; + q1.Auction = true; + q1.ForSale = true; + q1.Name = "For Sale Parcel Q1"; + q1.ProductSku = "023"; + q1.SalePrice = 2193; + q1.ParcelID = UUID.Random(); + + s.QueryReplies[0] = q1; + + DirLandReplyMessage.QueryReply q2 = new DirLandReplyMessage.QueryReply(); + q2.ActualArea = 512; + q2.Auction = true; + q2.ForSale = true; + q2.Name = "For Sale Parcel Q2"; + q2.ProductSku = "023"; + q2.SalePrice = 22193; + q2.ParcelID = UUID.Random(); + + s.QueryReplies[1] = q2; + + System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch(); + timer.Start(); + for (int i = 0; i < TEST_ITER; ++i) + { + MemoryStream stream = new MemoryStream(); + OSDMap map = s.Serialize(); + byte[] jsonData = Encoding.UTF8.GetBytes(OSDParser.SerializeJsonString(map)); + stream.Write(jsonData, 0, jsonData.Length); + stream.Flush(); + stream.Close(); + } + timer.Stop(); + Console.WriteLine("OMV Message System Serialization/Deserialization Passes: {0} Total time: {1}", TEST_ITER, timer.Elapsed.TotalSeconds); + + timer.Reset(); + timer.Start(); + for (int i = 0; i < TEST_ITER; ++i) + { + MemoryStream stream = new MemoryStream(); + xmlSerializer.Serialize(stream, s); + stream.Flush(); + stream.Close(); + } + timer.Stop(); + Console.WriteLine(".NET BinarySerialization/Deserialization Passes: {0} Total time: {1}", TEST_ITER, timer.Elapsed.TotalSeconds); + } + + [Test] + [Category("Benchmark")] + public void ReflectionPerformanceParcelProperties() + { + DateTime messageTestTime = DateTime.UtcNow; + for (int x = 0; x < TEST_ITER; x++) + { + ParcelPropertiesMessage s = new ParcelPropertiesMessage(); + s.AABBMax = Vector3.Parse("<1,2,3>"); + s.AABBMin = Vector3.Parse("<2,3,1>"); + s.Area = 1024; + s.AuctionID = uint.MaxValue; + s.AuthBuyerID = UUID.Random(); + s.Bitmap = Utils.EmptyBytes; + s.Category = ParcelCategory.Educational; + s.ClaimDate = new DateTime(2008, 12, 25, 3, 15, 22); + s.ClaimPrice = 1000; + s.Desc = "Test Description"; + s.GroupID = UUID.Random(); + s.GroupPrims = 50; + s.IsGroupOwned = false; + s.LandingType = LandingType.None; + s.LocalID = 1; + s.MaxPrims = 234; + s.MediaAutoScale = false; + s.MediaDesc = "Example Media Description"; + s.MediaHeight = 480; + s.MediaID = UUID.Random(); + s.MediaLoop = false; + s.MediaType = "text/html"; + s.MediaURL = "http://www.openmetaverse.co"; + s.MediaWidth = 640; + s.MusicURL = "http://scfire-ntc-aa04.stream.aol.com:80/stream/1075"; // Yee Haw + s.Name = "Test Name"; + s.ObscureMedia = false; + s.ObscureMusic = false; + s.OtherCleanTime = 5; + s.OtherCount = 200; + s.OtherPrims = 300; + s.OwnerID = UUID.Random(); + s.OwnerPrims = 0; + s.ParcelFlags = ParcelFlags.AllowDamage | ParcelFlags.AllowGroupScripts | ParcelFlags.AllowVoiceChat; + s.ParcelPrimBonus = 0f; + s.PassHours = 1.5f; + s.PassPrice = 10; + s.PublicCount = 20; + s.RegionDenyAgeUnverified = false; + s.RegionDenyAnonymous = false; + s.RegionPushOverride = true; + s.RentPrice = 0; + s.RequestResult = ParcelResult.Single; + s.SalePrice = 9999; + s.SelectedPrims = 1; + s.SelfCount = 2; + s.SequenceID = -4000; + s.SimWideMaxPrims = 937; + s.SimWideTotalPrims = 117; + s.SnapSelection = false; + s.SnapshotID = UUID.Random(); + s.Status = ParcelStatus.Leased; + s.TotalPrims = 219; + s.UserLocation = Vector3.Parse("<3,4,5>"); + s.UserLookAt = Vector3.Parse("<5,4,3>"); + + OSDMap map = s.Serialize(); + ParcelPropertiesMessage t = new ParcelPropertiesMessage(); + + t.Deserialize(map); + + Assert.AreEqual(s.AABBMax, t.AABBMax); + Assert.AreEqual(s.AABBMin, t.AABBMin); + Assert.AreEqual(s.Area, t.Area); + Assert.AreEqual(s.AuctionID, t.AuctionID); + Assert.AreEqual(s.AuthBuyerID, t.AuthBuyerID); + Assert.AreEqual(s.Bitmap, t.Bitmap); + Assert.AreEqual(s.Category, t.Category); + Assert.AreEqual(s.ClaimDate, t.ClaimDate); + Assert.AreEqual(s.ClaimPrice, t.ClaimPrice); + Assert.AreEqual(s.Desc, t.Desc); + Assert.AreEqual(s.GroupID, t.GroupID); + Assert.AreEqual(s.GroupPrims, t.GroupPrims); + Assert.AreEqual(s.IsGroupOwned, t.IsGroupOwned); + Assert.AreEqual(s.LandingType, t.LandingType); + Assert.AreEqual(s.LocalID, t.LocalID); + Assert.AreEqual(s.MaxPrims, t.MaxPrims); + Assert.AreEqual(s.MediaAutoScale, t.MediaAutoScale); + Assert.AreEqual(s.MediaDesc, t.MediaDesc); + Assert.AreEqual(s.MediaHeight, t.MediaHeight); + Assert.AreEqual(s.MediaID, t.MediaID); + Assert.AreEqual(s.MediaLoop, t.MediaLoop); + Assert.AreEqual(s.MediaType, t.MediaType); + Assert.AreEqual(s.MediaURL, t.MediaURL); + Assert.AreEqual(s.MediaWidth, t.MediaWidth); + Assert.AreEqual(s.MusicURL, t.MusicURL); + Assert.AreEqual(s.Name, t.Name); + Assert.AreEqual(s.ObscureMedia, t.ObscureMedia); + Assert.AreEqual(s.ObscureMusic, t.ObscureMusic); + Assert.AreEqual(s.OtherCleanTime, t.OtherCleanTime); + Assert.AreEqual(s.OtherCount, t.OtherCount); + Assert.AreEqual(s.OtherPrims, t.OtherPrims); + Assert.AreEqual(s.OwnerID, t.OwnerID); + Assert.AreEqual(s.OwnerPrims, t.OwnerPrims); + Assert.AreEqual(s.ParcelFlags, t.ParcelFlags); + Assert.AreEqual(s.ParcelPrimBonus, t.ParcelPrimBonus); + Assert.AreEqual(s.PassHours, t.PassHours); + Assert.AreEqual(s.PassPrice, t.PassPrice); + Assert.AreEqual(s.PublicCount, t.PublicCount); + Assert.AreEqual(s.RegionDenyAgeUnverified, t.RegionDenyAgeUnverified); + Assert.AreEqual(s.RegionDenyAnonymous, t.RegionDenyAnonymous); + Assert.AreEqual(s.RegionPushOverride, t.RegionPushOverride); + Assert.AreEqual(s.RentPrice, t.RentPrice); + Assert.AreEqual(s.RequestResult, t.RequestResult); + Assert.AreEqual(s.SalePrice, t.SalePrice); + Assert.AreEqual(s.SelectedPrims, t.SelectedPrims); + Assert.AreEqual(s.SelfCount, t.SelfCount); + Assert.AreEqual(s.SequenceID, t.SequenceID); + Assert.AreEqual(s.SimWideMaxPrims, t.SimWideMaxPrims); + Assert.AreEqual(s.SimWideTotalPrims, t.SimWideTotalPrims); + Assert.AreEqual(s.SnapSelection, t.SnapSelection); + Assert.AreEqual(s.SnapshotID, t.SnapshotID); + Assert.AreEqual(s.Status, t.Status); + Assert.AreEqual(s.TotalPrims, t.TotalPrims); + Assert.AreEqual(s.UserLocation, t.UserLocation); + Assert.AreEqual(s.UserLookAt, t.UserLookAt); + } + TimeSpan duration = DateTime.UtcNow - messageTestTime; + Console.WriteLine("ParcelPropertiesMessage: OMV Message System Serialization/Deserialization Passes: {0} Total time: {1}", TEST_ITER, duration); + + BinaryFormatter formatter = new BinaryFormatter(); + + DateTime xmlTestTime = DateTime.UtcNow; + for (int x = 0; x < TEST_ITER; x++) + { + + ParcelPropertiesMessage s = new ParcelPropertiesMessage(); + s.AABBMax = Vector3.Parse("<1,2,3>"); + s.AABBMin = Vector3.Parse("<2,3,1>"); + s.Area = 1024; + s.AuctionID = uint.MaxValue; + s.AuthBuyerID = UUID.Random(); + s.Bitmap = Utils.EmptyBytes; + s.Category = ParcelCategory.Educational; + s.ClaimDate = new DateTime(2008, 12, 25, 3, 15, 22); + s.ClaimPrice = 1000; + s.Desc = "Test Description"; + s.GroupID = UUID.Random(); + s.GroupPrims = 50; + s.IsGroupOwned = false; + s.LandingType = LandingType.None; + s.LocalID = 1; + s.MaxPrims = 234; + s.MediaAutoScale = false; + s.MediaDesc = "Example Media Description"; + s.MediaHeight = 480; + s.MediaID = UUID.Random(); + s.MediaLoop = false; + s.MediaType = "text/html"; + s.MediaURL = "http://www.openmetaverse.co"; + s.MediaWidth = 640; + s.MusicURL = "http://scfire-ntc-aa04.stream.aol.com:80/stream/1075"; // Yee Haw + s.Name = "Test Name"; + s.ObscureMedia = false; + s.ObscureMusic = false; + s.OtherCleanTime = 5; + s.OtherCount = 200; + s.OtherPrims = 300; + s.OwnerID = UUID.Random(); + s.OwnerPrims = 0; + s.ParcelFlags = ParcelFlags.AllowDamage | ParcelFlags.AllowGroupScripts | ParcelFlags.AllowVoiceChat; + s.ParcelPrimBonus = 0f; + s.PassHours = 1.5f; + s.PassPrice = 10; + s.PublicCount = 20; + s.RegionDenyAgeUnverified = false; + s.RegionDenyAnonymous = false; + s.RegionPushOverride = true; + s.RentPrice = 0; + s.RequestResult = ParcelResult.Single; + s.SalePrice = 9999; + s.SelectedPrims = 1; + s.SelfCount = 2; + s.SequenceID = -4000; + s.SimWideMaxPrims = 937; + s.SimWideTotalPrims = 117; + s.SnapSelection = false; + s.SnapshotID = UUID.Random(); + s.Status = ParcelStatus.Leased; + s.TotalPrims = 219; + s.UserLocation = Vector3.Parse("<3,4,5>"); + s.UserLookAt = Vector3.Parse("<5,4,3>"); + + MemoryStream stream = new MemoryStream(); + + formatter.Serialize(stream, s); + + stream.Seek(0, SeekOrigin.Begin); + + ParcelPropertiesMessage t = (ParcelPropertiesMessage)formatter.Deserialize(stream); + + Assert.AreEqual(s.AABBMax, t.AABBMax); + Assert.AreEqual(s.AABBMin, t.AABBMin); + Assert.AreEqual(s.Area, t.Area); + Assert.AreEqual(s.AuctionID, t.AuctionID); + Assert.AreEqual(s.AuthBuyerID, t.AuthBuyerID); + Assert.AreEqual(s.Bitmap, t.Bitmap); + Assert.AreEqual(s.Category, t.Category); + Assert.AreEqual(s.ClaimDate, t.ClaimDate); + Assert.AreEqual(s.ClaimPrice, t.ClaimPrice); + Assert.AreEqual(s.Desc, t.Desc); + Assert.AreEqual(s.GroupID, t.GroupID); + Assert.AreEqual(s.GroupPrims, t.GroupPrims); + Assert.AreEqual(s.IsGroupOwned, t.IsGroupOwned); + Assert.AreEqual(s.LandingType, t.LandingType); + Assert.AreEqual(s.LocalID, t.LocalID); + Assert.AreEqual(s.MaxPrims, t.MaxPrims); + Assert.AreEqual(s.MediaAutoScale, t.MediaAutoScale); + Assert.AreEqual(s.MediaDesc, t.MediaDesc); + Assert.AreEqual(s.MediaHeight, t.MediaHeight); + Assert.AreEqual(s.MediaID, t.MediaID); + Assert.AreEqual(s.MediaLoop, t.MediaLoop); + Assert.AreEqual(s.MediaType, t.MediaType); + Assert.AreEqual(s.MediaURL, t.MediaURL); + Assert.AreEqual(s.MediaWidth, t.MediaWidth); + Assert.AreEqual(s.MusicURL, t.MusicURL); + Assert.AreEqual(s.Name, t.Name); + Assert.AreEqual(s.ObscureMedia, t.ObscureMedia); + Assert.AreEqual(s.ObscureMusic, t.ObscureMusic); + Assert.AreEqual(s.OtherCleanTime, t.OtherCleanTime); + Assert.AreEqual(s.OtherCount, t.OtherCount); + Assert.AreEqual(s.OtherPrims, t.OtherPrims); + Assert.AreEqual(s.OwnerID, t.OwnerID); + Assert.AreEqual(s.OwnerPrims, t.OwnerPrims); + Assert.AreEqual(s.ParcelFlags, t.ParcelFlags); + Assert.AreEqual(s.ParcelPrimBonus, t.ParcelPrimBonus); + Assert.AreEqual(s.PassHours, t.PassHours); + Assert.AreEqual(s.PassPrice, t.PassPrice); + Assert.AreEqual(s.PublicCount, t.PublicCount); + Assert.AreEqual(s.RegionDenyAgeUnverified, t.RegionDenyAgeUnverified); + Assert.AreEqual(s.RegionDenyAnonymous, t.RegionDenyAnonymous); + Assert.AreEqual(s.RegionPushOverride, t.RegionPushOverride); + Assert.AreEqual(s.RentPrice, t.RentPrice); + Assert.AreEqual(s.RequestResult, t.RequestResult); + Assert.AreEqual(s.SalePrice, t.SalePrice); + Assert.AreEqual(s.SelectedPrims, t.SelectedPrims); + Assert.AreEqual(s.SelfCount, t.SelfCount); + Assert.AreEqual(s.SequenceID, t.SequenceID); + Assert.AreEqual(s.SimWideMaxPrims, t.SimWideMaxPrims); + Assert.AreEqual(s.SimWideTotalPrims, t.SimWideTotalPrims); + Assert.AreEqual(s.SnapSelection, t.SnapSelection); + Assert.AreEqual(s.SnapshotID, t.SnapshotID); + Assert.AreEqual(s.Status, t.Status); + Assert.AreEqual(s.TotalPrims, t.TotalPrims); + Assert.AreEqual(s.UserLocation, t.UserLocation); + Assert.AreEqual(s.UserLookAt, t.UserLookAt); + } + TimeSpan durationxml = DateTime.UtcNow - xmlTestTime; + Console.WriteLine("ParcelPropertiesMessage: .NET BinarySerialization/Deserialization Passes: {0} Total time: {1}", TEST_ITER, durationxml); + } + + #endregion + } +} + diff --git a/Assets/Tests/MessageTests.cs.meta b/Assets/Tests/MessageTests.cs.meta new file mode 100644 index 0000000..af8a98f --- /dev/null +++ b/Assets/Tests/MessageTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f42872409e992134cab2a63f1f023d77 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/NetworkTests.cs b/Assets/Tests/NetworkTests.cs new file mode 100644 index 0000000..4361083 --- /dev/null +++ b/Assets/Tests/NetworkTests.cs @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2006-2016, openmetaverse.co + * All rights reserved. + * + * - Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * - Neither the name of the openmetaverse.co nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using System.Net; +using OpenMetaverse; +using OpenMetaverse.Packets; +using NUnit.Framework; + +namespace OpenMetaverse.Tests +{ + [TestFixture] + [Category("Network")] + public class NetworkTests : Assert + { + GridClient Client; + + //ulong CurrentRegionHandle = 0; + //ulong AhernRegionHandle = 1096213093149184; + //ulong MorrisRegionHandle = 1096213093149183; + //ulong DoreRegionHandle = 1095113581521408; + //ulong HooperRegionHandle = 1106108697797888; + bool DetectedObject = false; + + public NetworkTests() + { + Client = new GridClient(); + Client.Self.Movement.Fly = true; + // Register callbacks + Client.Network.RegisterCallback(PacketType.ObjectUpdate, ObjectUpdateHandler); + //Client.Self.OnTeleport += new MainAvatar.TeleportCallback(OnTeleportHandler) + } + + [OneTimeSetUp] + public void Init() + { + var fullusername = "***REMOVED*** resident";//Environment.GetEnvironmentVariable("LMVTestAgentUsername"); + var password = "***REMOVED***";// Environment.GetEnvironmentVariable("LMVTestAgentPassword"); + Assert.IsFalse(string.IsNullOrWhiteSpace(fullusername), "LMVTestAgentUsername is empty. Live NetworkTests cannot be performed."); + Assert.IsFalse(string.IsNullOrWhiteSpace(password), "LMVTestAgentPassword is empty. Live NetworkTests cannot be performed."); + var username = fullusername.Split(' '); + + Console.Write($"Logging in {fullusername}..."); + // Connect to the grid + string startLoc = NetworkManager.StartLocation("Hooper", 179, 18, 32); + Assert.IsTrue(Client.Network.Login(username[0], username[1], password, "Unit Test Framework", startLoc, + "contact@openmetaverse.co"), "Client failed to login, reason: " + Client.Network.LoginMessage); + Console.WriteLine("Done"); + + Assert.IsTrue(Client.Network.Connected, "Client is not connected to the grid"); + + //int start = Environment.TickCount; + + Assert.AreEqual("hooper", Client.Network.CurrentSim.Name.ToLower(), "Logged in to sim " + + Client.Network.CurrentSim.Name + " instead of hooper"); + } + + [Test] + public void DetectObjects() + { + int start = Environment.TickCount; + while (!DetectedObject) + { + if (Environment.TickCount - start > 20000) + { + Assert.Fail("Timeout waiting for an ObjectUpdate packet"); + } + } + } + + /* + [Test] + public void U64Receive() + { + int start = Environment.TickCount; + while (CurrentRegionHandle == 0) + { + if (Environment.TickCount - start > 10000) + { + Assert.Fail("Timeout waiting for an ObjectUpdate packet"); + } + } + + Assert.IsTrue(CurrentRegionHandle == HooperRegionHandle, "Current region is " + + CurrentRegionHandle + " (" + Client.Network.CurrentSim.Name + ")" + " when we were expecting " + HooperRegionHandle + " (Dore), possible endian issue"); + } + */ + /*[Test] + public void Teleport() + { + // test in-sim teleports + Assert.IsTrue(CapsQueueRunning(), "CAPS Event queue is not running in " + Client.Network.CurrentSim.Name); + string localSimName = Client.Network.CurrentSim.Name; + Assert.IsTrue(Client.Self.Teleport(Client.Network.CurrentSim.Handle, new Vector3(121, 13, 41)), + "Teleport In-Sim Failed " + Client.Network.CurrentSim.Name); + + // Assert that we really did make it to our scheduled destination + Assert.AreEqual(localSimName, Client.Network.CurrentSim.Name, + "Expected to teleport to " + localSimName + ", ended up in " + Client.Network.CurrentSim.Name + + ". Possibly region full or offline?"); + + Assert.IsTrue(CapsQueueRunning(), "CAPS Event queue is not running in " + Client.Network.CurrentSim.Name); + Assert.IsTrue(Client.Self.Teleport(DoreRegionHandle, new Vector3(128, 128, 32)), + "Teleport to Dore failed"); + + // Assert that we really did make it to our scheduled destination + Assert.AreEqual("dore", Client.Network.CurrentSim.Name.ToLower(), + "Expected to teleport to Dore, ended up in " + Client.Network.CurrentSim.Name + + ". Possibly region full or offline?"); + + Assert.IsTrue(CapsQueueRunning(), "CAPS Event queue is not running in " + Client.Network.CurrentSim.Name); + Assert.IsTrue(Client.Self.Teleport(HooperRegionHandle, new Vector3(179, 18, 32)), + "Teleport to Hooper failed"); + + // Assert that we really did make it to our scheduled destination + Assert.AreEqual("hooper", Client.Network.CurrentSim.Name.ToLower(), + "Expected to teleport to Hooper, ended up in " + Client.Network.CurrentSim.Name + + ". Possibly region full or offline?"); + }*/ + + [Test] + public void CapsQueue() + { + Assert.IsTrue(CapsQueueRunning(), "CAPS Event Queue is not running and failed to start"); + } + + public bool CapsQueueRunning() + { + if (Client.Network.CurrentSim.Caps.IsEventQueueRunning) + return true; + + bool Success = false; + // make sure caps event queue is running + System.Threading.AutoResetEvent waitforCAPS = new System.Threading.AutoResetEvent(false); + EventHandler capsRunning = delegate(object sender, EventQueueRunningEventArgs e) + { + waitforCAPS.Set(); + }; + + Client.Network.EventQueueRunning += capsRunning; + if (waitforCAPS.WaitOne(10000, false)) + { + Success = true; + } + else + { + Success = false; + Assert.Fail("Timeout waiting for event Queue to startup"); + } + Client.Network.EventQueueRunning -= capsRunning; + return Success; + } + + private void ObjectUpdateHandler(object sender, PacketReceivedEventArgs e) + { + //ObjectUpdatePacket update = (ObjectUpdatePacket)packet; + + DetectedObject = true; + //CurrentRegionHandle = update.RegionData.RegionHandle; + } + + [OneTimeTearDown] + public void Shutdown() + { + Console.Write("Logging out..."); + Client.Network.Logout(); + Console.WriteLine("Done"); + } + } +} diff --git a/Assets/Tests/NetworkTests.cs.meta b/Assets/Tests/NetworkTests.cs.meta new file mode 100644 index 0000000..09b9d0c --- /dev/null +++ b/Assets/Tests/NetworkTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dde2dfcd7dfdc9447aca63af64be81c8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/NotationLLSDTests.cs b/Assets/Tests/NotationLLSDTests.cs new file mode 100644 index 0000000..8b2bf12 --- /dev/null +++ b/Assets/Tests/NotationLLSDTests.cs @@ -0,0 +1,746 @@ +/* + * Copyright (c) 2006-2016, openmetaverse.co + * All rights reserved. + * + * - Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * - Neither the name of the openmetaverse.co nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * + * This tests are based upon the description at + * + * http://wiki.secondlife.com/wiki/SD + * + * and (partially) generated by the (supposed) reference implementation at + * + * http://svn.secondlife.com/svn/linden/release/indra/lib/python/indra/base/llsd.py + * + */ + +using System; +using System.IO; +using System.Text; +using System.Xml; +using NUnit.Framework; +using OpenMetaverse.StructuredData; + +namespace OpenMetaverse.Tests +{ + + [TestFixture()] + public class NotationSDTests + { + [Test()] + public void HelperFunctions() + { + StringReader reader = new StringReader("test1tast2test3"); + + char[] charsOne = { 't', 'e', 's', 't' }; + int resultOne = OSDParser.BufferCharactersEqual(reader, charsOne, 0); + Assert.AreEqual(charsOne.Length, resultOne); + + char[] charsTwo = { '1', 't', 'e' }; + int resultTwo = OSDParser.BufferCharactersEqual(reader, charsTwo, 0); + Assert.AreEqual(2, resultTwo); + + char[] charsThree = { 'a', 's', 't', '2', 't', 'e', 's' }; + int resultThree = OSDParser.BufferCharactersEqual(reader, charsThree, 1); + Assert.AreEqual(1, resultThree); + + int resultFour = OSDParser.BufferCharactersEqual(reader, charsThree, 0); + Assert.AreEqual(charsThree.Length, resultFour); + + char[] charsFive = { 't', '3', 'a', 'a' }; + int resultFive = OSDParser.BufferCharactersEqual(reader, charsFive, 0); + Assert.AreEqual(2, resultFive); + + + } + + [Test()] + public void DeserializeUndef() + { + String s = "!"; + OSD llsd = OSDParser.DeserializeLLSDNotation(s); + Assert.AreEqual(OSDType.Unknown, llsd.Type); + } + + [Test()] + public void SerializeUndef() + { + OSD llsd = new OSD(); + string s = OSDParser.SerializeLLSDNotation(llsd); + + OSD llsdDS = OSDParser.DeserializeLLSDNotation(s); + Assert.AreEqual(OSDType.Unknown, llsdDS.Type); + } + + [Test()] + public void DeserializeBoolean() + { + String t = "true"; + OSD llsdT = OSDParser.DeserializeLLSDNotation(t); + Assert.AreEqual(OSDType.Boolean, llsdT.Type); + Assert.AreEqual(true, llsdT.AsBoolean()); + + String tTwo = "t"; + OSD llsdTTwo = OSDParser.DeserializeLLSDNotation(tTwo); + Assert.AreEqual(OSDType.Boolean, llsdTTwo.Type); + Assert.AreEqual(true, llsdTTwo.AsBoolean()); + + String tThree = "TRUE"; + OSD llsdTThree = OSDParser.DeserializeLLSDNotation(tThree); + Assert.AreEqual(OSDType.Boolean, llsdTThree.Type); + Assert.AreEqual(true, llsdTThree.AsBoolean()); + + String tFour = "T"; + OSD llsdTFour = OSDParser.DeserializeLLSDNotation(tFour); + Assert.AreEqual(OSDType.Boolean, llsdTFour.Type); + Assert.AreEqual(true, llsdTFour.AsBoolean()); + + String tFive = "1"; + OSD llsdTFive = OSDParser.DeserializeLLSDNotation(tFive); + Assert.AreEqual(OSDType.Boolean, llsdTFive.Type); + Assert.AreEqual(true, llsdTFive.AsBoolean()); + + String f = "false"; + OSD llsdF = OSDParser.DeserializeLLSDNotation(f); + Assert.AreEqual(OSDType.Boolean, llsdF.Type); + Assert.AreEqual(false, llsdF.AsBoolean()); + + String fTwo = "f"; + OSD llsdFTwo = OSDParser.DeserializeLLSDNotation(fTwo); + Assert.AreEqual(OSDType.Boolean, llsdFTwo.Type); + Assert.AreEqual(false, llsdFTwo.AsBoolean()); + + String fThree = "FALSE"; + OSD llsdFThree = OSDParser.DeserializeLLSDNotation(fThree); + Assert.AreEqual(OSDType.Boolean, llsdFThree.Type); + Assert.AreEqual(false, llsdFThree.AsBoolean()); + + String fFour = "F"; + OSD llsdFFour = OSDParser.DeserializeLLSDNotation(fFour); + Assert.AreEqual(OSDType.Boolean, llsdFFour.Type); + Assert.AreEqual(false, llsdFFour.AsBoolean()); + + String fFive = "0"; + OSD llsdFFive = OSDParser.DeserializeLLSDNotation(fFive); + Assert.AreEqual(OSDType.Boolean, llsdFFive.Type); + Assert.AreEqual(false, llsdFFive.AsBoolean()); + } + + [Test()] + public void SerializeBoolean() + { + OSD llsdTrue = OSD.FromBoolean(true); + string sTrue = OSDParser.SerializeLLSDNotation(llsdTrue); + OSD llsdTrueDS = OSDParser.DeserializeLLSDNotation(sTrue); + Assert.AreEqual(OSDType.Boolean, llsdTrueDS.Type); + Assert.AreEqual(true, llsdTrueDS.AsBoolean()); + + OSD llsdFalse = OSD.FromBoolean(false); + string sFalse = OSDParser.SerializeLLSDNotation(llsdFalse); + OSD llsdFalseDS = OSDParser.DeserializeLLSDNotation(sFalse); + Assert.AreEqual(OSDType.Boolean, llsdFalseDS.Type); + Assert.AreEqual(false, llsdFalseDS.AsBoolean()); + } + + [Test()] + public void DeserializeInteger() + { + string integerOne = "i12319423"; + OSD llsdOne = OSDParser.DeserializeLLSDNotation(integerOne); + Assert.AreEqual(OSDType.Integer, llsdOne.Type); + Assert.AreEqual(12319423, llsdOne.AsInteger()); + + string integerTwo = "i-489234"; + OSD llsdTwo = OSDParser.DeserializeLLSDNotation(integerTwo); + Assert.AreEqual(OSDType.Integer, llsdTwo.Type); + Assert.AreEqual(-489234, llsdTwo.AsInteger()); + } + + [Test()] + public void SerializeInteger() + { + OSD llsdOne = OSD.FromInteger(12319423); + string sOne = OSDParser.SerializeLLSDNotation(llsdOne); + OSD llsdOneDS = OSDParser.DeserializeLLSDNotation(sOne); + Assert.AreEqual(OSDType.Integer, llsdOneDS.Type); + Assert.AreEqual(12319423, llsdOne.AsInteger()); + + OSD llsdTwo = OSD.FromInteger(-71892034); + string sTwo = OSDParser.SerializeLLSDNotation(llsdTwo); + OSD llsdTwoDS = OSDParser.DeserializeLLSDNotation(sTwo); + Assert.AreEqual(OSDType.Integer, llsdTwoDS.Type); + Assert.AreEqual(-71892034, llsdTwoDS.AsInteger()); + } + + [Test()] + public void DeserializeReal() + { + String realOne = "r1123412345.465711"; + OSD llsdOne = OSDParser.DeserializeLLSDNotation(realOne); + Assert.AreEqual(OSDType.Real, llsdOne.Type); + Assert.AreEqual(1123412345.465711d, llsdOne.AsReal()); + + String realTwo = "r-11234684.923411"; + OSD llsdTwo = OSDParser.DeserializeLLSDNotation(realTwo); + Assert.AreEqual(OSDType.Real, llsdTwo.Type); + Assert.AreEqual(-11234684.923411d, llsdTwo.AsReal()); + + String realThree = "r1"; + OSD llsdThree = OSDParser.DeserializeLLSDNotation(realThree); + Assert.AreEqual(OSDType.Real, llsdThree.Type); + Assert.AreEqual(1d, llsdThree.AsReal()); + + String realFour = "r2.0193899999999998204e-06"; + OSD llsdFour = OSDParser.DeserializeLLSDNotation(realFour); + Assert.AreEqual(OSDType.Real, llsdFour.Type); + Assert.AreEqual(2.0193899999999998204e-06d, llsdFour.AsReal()); + + String realFive = "r0"; + OSD llsdFive = OSDParser.DeserializeLLSDNotation(realFive); + Assert.AreEqual(OSDType.Real, llsdFive.Type); + Assert.AreEqual(0d, llsdFive.AsReal()); + } + + [Test()] + public void SerializeReal() + { + OSD llsdOne = OSD.FromReal(12987234.723847d); + string sOne = OSDParser.SerializeLLSDNotation(llsdOne); + OSD llsdOneDS = OSDParser.DeserializeLLSDNotation(sOne); + Assert.AreEqual(OSDType.Real, llsdOneDS.Type); + Assert.AreEqual(12987234.723847d, llsdOneDS.AsReal()); + + OSD llsdTwo = OSD.FromReal(-32347892.234234d); + string sTwo = OSDParser.SerializeLLSDNotation(llsdTwo); + OSD llsdTwoDS = OSDParser.DeserializeLLSDNotation(sTwo); + Assert.AreEqual(OSDType.Real, llsdTwoDS.Type); + Assert.AreEqual(-32347892.234234d, llsdTwoDS.AsReal()); + + OSD llsdThree = OSD.FromReal( Double.MaxValue ); + string sThree = OSDParser.SerializeLLSDNotation( llsdThree ); + OSD llsdThreeDS = OSDParser.DeserializeLLSDNotation( sThree ); + Assert.AreEqual( OSDType.Real, llsdThreeDS.Type ); + Assert.AreEqual( Double.MaxValue, llsdThreeDS.AsReal()); + + OSD llsdFour = OSD.FromReal(Double.MinValue); + string sFour = OSDParser.SerializeLLSDNotation(llsdFour); + OSD llsdFourDS = OSDParser.DeserializeLLSDNotation(sFour); + Assert.AreEqual(OSDType.Real, llsdFourDS.Type); + Assert.AreEqual(Double.MinValue, llsdFourDS.AsReal()); + + OSD llsdFive = OSD.FromReal(-1.1123123E+50d); + string sFive = OSDParser.SerializeLLSDNotation(llsdFive); + OSD llsdFiveDS = OSDParser.DeserializeLLSDNotation(sFive); + Assert.AreEqual(OSDType.Real, llsdFiveDS.Type); + Assert.AreEqual(-1.1123123E+50d, llsdFiveDS.AsReal()); + + OSD llsdSix = OSD.FromReal(2.0193899999999998204e-06); + string sSix = OSDParser.SerializeLLSDNotation(llsdSix); + OSD llsdSixDS = OSDParser.DeserializeLLSDNotation(sSix); + Assert.AreEqual(OSDType.Real, llsdSixDS.Type); + Assert.AreEqual(2.0193899999999998204e-06, llsdSixDS.AsReal()); + } + + [Test()] + public void DeserializeUUID() + { + String uuidOne = "u97f4aeca-88a1-42a1-b385-b97b18abb255"; + OSD llsdOne = OSDParser.DeserializeLLSDNotation(uuidOne); + Assert.AreEqual(OSDType.UUID, llsdOne.Type); + Assert.AreEqual("97f4aeca-88a1-42a1-b385-b97b18abb255", llsdOne.AsString()); + + String uuidTwo = "u00000000-0000-0000-0000-000000000000"; + OSD llsdTwo = OSDParser.DeserializeLLSDNotation(uuidTwo); + Assert.AreEqual(OSDType.UUID, llsdTwo.Type); + Assert.AreEqual("00000000-0000-0000-0000-000000000000", llsdTwo.AsString()); + } + + [Test()] + public void SerializeUUID() + { + OSD llsdOne = OSD.FromUUID(new UUID("97f4aeca-88a1-42a1-b385-b97b18abb255")); + string sOne = OSDParser.SerializeLLSDNotation(llsdOne); + OSD llsdOneDS = OSDParser.DeserializeLLSDNotation(sOne); + Assert.AreEqual(OSDType.UUID, llsdOneDS.Type); + Assert.AreEqual("97f4aeca-88a1-42a1-b385-b97b18abb255", llsdOneDS.AsString()); + + OSD llsdTwo = OSD.FromUUID(new UUID("00000000-0000-0000-0000-000000000000")); + string sTwo = OSDParser.SerializeLLSDNotation(llsdTwo); + OSD llsdTwoDS = OSDParser.DeserializeLLSDNotation(sTwo); + Assert.AreEqual(OSDType.UUID, llsdTwoDS.Type); + Assert.AreEqual("00000000-0000-0000-0000-000000000000", llsdTwoDS.AsString()); + } + + public void DeserializeString() + { + string sOne = "''"; + OSD llsdOne = OSDParser.DeserializeLLSDNotation(sOne); + Assert.AreEqual(OSDType.String, llsdOne.Type); + Assert.AreEqual("", llsdOne.AsString()); + + // This is double escaping. Once for the encoding, and once for csharp. + string sTwo = "'test\\'\"test'"; + OSD llsdTwo = OSDParser.DeserializeLLSDNotation(sTwo); + Assert.AreEqual(OSDType.String, llsdTwo.Type); + Assert.AreEqual("test'\"test", llsdTwo.AsString()); + + // "test \\lest" + char[] cThree = { (char)0x27, (char)0x74, (char)0x65, (char)0x73, (char)0x74, (char)0x20, (char)0x5c, + (char)0x5c, (char)0x6c, (char)0x65, (char)0x73, (char)0x74, (char)0x27 }; + string sThree = new string(cThree); + + OSD llsdThree = OSDParser.DeserializeLLSDNotation(sThree); + Assert.AreEqual(OSDType.String, llsdThree.Type); + Assert.AreEqual("test \\lest", llsdThree.AsString()); + + string sFour = "'aa\t la'"; + OSD llsdFour = OSDParser.DeserializeLLSDNotation(sFour); + Assert.AreEqual(OSDType.String, llsdFour.Type); + Assert.AreEqual("aa\t la", llsdFour.AsString()); + + char[] cFive = { (char)0x27, (char)0x5c, (char)0x5c, (char)0x27 }; + string sFive = new String(cFive); + OSD llsdFive = OSDParser.DeserializeLLSDNotation(sFive); + Assert.AreEqual(OSDType.String, llsdFive.Type); + Assert.AreEqual("\\", llsdFive.AsString()); + + + string sSix = "s(10)\"1234567890\""; + OSD llsdSix = OSDParser.DeserializeLLSDNotation(sSix); + Assert.AreEqual(OSDType.String, llsdSix.Type); + Assert.AreEqual("1234567890", llsdSix.AsString()); + + string sSeven = "s(5)\"\\\\\\\\\\\""; + OSD llsdSeven = OSDParser.DeserializeLLSDNotation(sSeven); + Assert.AreEqual(OSDType.String, llsdSeven.Type); + Assert.AreEqual("\\\\\\\\\\", llsdSeven.AsString()); + + string sEight = "\"aouAOUhsdjklfghskldjfghqeiurtzwieortzaslxfjkgh\""; + OSD llsdEight = OSDParser.DeserializeLLSDNotation(sEight); + Assert.AreEqual(OSDType.String, llsdEight.Type); + Assert.AreEqual("aouAOUhsdjklfghskldjfghqeiurtzwieortzaslxfjkgh", llsdEight.AsString()); + + + + } + + public void DoSomeStringSerializingActionsAndAsserts(string s) + { + OSD llsdOne = OSD.FromString(s); + string sOne = OSDParser.SerializeLLSDNotation(llsdOne); + OSD llsdOneDS = OSDParser.DeserializeLLSDNotation(sOne); + Assert.AreEqual(OSDType.String, llsdOne.Type); + Assert.AreEqual(s, llsdOneDS.AsString()); + } + + + [Test()] + public void SerializeString() + { + DoSomeStringSerializingActionsAndAsserts(""); + + DoSomeStringSerializingActionsAndAsserts("\\"); + + DoSomeStringSerializingActionsAndAsserts("\"\""); + + DoSomeStringSerializingActionsAndAsserts("ÄÖÜäöü-these-should-be-some-german-umlauts"); + + DoSomeStringSerializingActionsAndAsserts("\t\n\r"); + + DoSomeStringSerializingActionsAndAsserts("asdkjfhaksldjfhalskdjfhaklsjdfhaklsjdhjgzqeuiowrtzserghsldfg" + + "asdlkfhqeiortzsdkfjghslkdrjtzsoidklghuisoehiguhsierughaishdl" + + "asdfkjhueiorthsgsdkfughaslkdfjshldkfjghsldkjghsldkfghsdklghs" + + "wopeighisdjfghklasdfjghsdklfgjhsdklfgjshdlfkgjshdlfkgjshdlfk"); + + DoSomeStringSerializingActionsAndAsserts("all is N\"\\'othing and n'oting is all"); + + DoSomeStringSerializingActionsAndAsserts("very\"british is this."); + + // We test here also for 4byte characters + string xml = "𐄷"; + byte[] bytes = Encoding.UTF8.GetBytes(xml); + XmlTextReader xtr = new XmlTextReader(new MemoryStream(bytes, false)); + xtr.Read(); + xtr.Read(); + string content = xtr.ReadString(); + + DoSomeStringSerializingActionsAndAsserts(content); + + } + + [Test()] + public void DeserializeURI() + { + string sUriOne = "l\"http://test.com/test test>\\\"/&yes\""; + OSD llsdOne = OSDParser.DeserializeLLSDNotation(sUriOne); + Assert.AreEqual(OSDType.URI, llsdOne.Type); + Assert.AreEqual("http://test.com/test%20test%3E%22/&yes", llsdOne.AsString()); + + string sUriTwo = "l\"test/test/test?test=1&toast=2\""; + OSD llsdTwo = OSDParser.DeserializeLLSDNotation(sUriTwo); + Assert.AreEqual(OSDType.URI, llsdTwo.Type); + Assert.AreEqual("test/test/test?test=1&toast=2", llsdTwo.AsString()); + } + + [Test()] + public void SerializeURI() + { + Uri uriOne = new Uri("http://test.org/test test>\\\"/&yes\"", UriKind.RelativeOrAbsolute); + OSD llsdOne = OSD.FromUri(uriOne); + string sUriOne = OSDParser.SerializeLLSDNotation(llsdOne); + OSD llsdOneDS = OSDParser.DeserializeLLSDNotation(sUriOne); + Assert.AreEqual(OSDType.URI, llsdOneDS.Type); + Assert.AreEqual(uriOne, llsdOneDS.AsUri()); + + Uri uriTwo = new Uri("test/test/near/the/end?test=1", UriKind.RelativeOrAbsolute); + OSD llsdTwo = OSD.FromUri(uriTwo); + string sUriTwo = OSDParser.SerializeLLSDNotation(llsdTwo); + OSD llsdTwoDS = OSDParser.DeserializeLLSDNotation(sUriTwo); + Assert.AreEqual(OSDType.URI, llsdTwoDS.Type); + Assert.AreEqual(uriTwo, llsdTwoDS.AsUri()); + } + + [Test()] + public void DeserializeDate() + { + string sDateOne = "d\"2007-12-31T20:49:10Z\""; + OSD llsdOne = OSDParser.DeserializeLLSDNotation(sDateOne); + Assert.AreEqual(OSDType.Date, llsdOne.Type); + DateTime dt = new DateTime(2007, 12, 31, 20, 49, 10, 0, DateTimeKind.Utc); + DateTime dtDS = llsdOne.AsDate(); + Assert.AreEqual(dt, dtDS.ToUniversalTime()); + } + + [Test()] + public void SerializeDate() + { + DateTime dtOne = new DateTime(2005, 8, 10, 11, 23, 4, DateTimeKind.Utc); + OSD llsdOne = OSD.FromDate(dtOne); + string sDtOne = OSDParser.SerializeLLSDNotation(llsdOne); + OSD llsdOneDS = OSDParser.DeserializeLLSDNotation(sDtOne); + Assert.AreEqual(OSDType.Date, llsdOneDS.Type); + DateTime dtOneDS = llsdOneDS.AsDate(); + Assert.AreEqual(dtOne, dtOneDS.ToUniversalTime()); + + DateTime dtTwo = new DateTime(2010, 10, 11, 23, 00, 10, 100, DateTimeKind.Utc); + OSD llsdTwo = OSD.FromDate(dtTwo); + string sDtTwo = OSDParser.SerializeLLSDNotation(llsdTwo); + OSD llsdTwoDS = OSDParser.DeserializeLLSDNotation(sDtTwo); + Assert.AreEqual(OSDType.Date, llsdTwoDS.Type); + DateTime dtTwoDS = llsdTwoDS.AsDate(); + Assert.AreEqual(dtTwo, dtTwoDS.ToUniversalTime()); + + // check if a *local* time can be serialized and deserialized + DateTime dtThree = new DateTime(2009, 12, 30, 8, 25, 10, DateTimeKind.Local); + OSD llsdDateThree = OSD.FromDate(dtThree); + string sDateThreeSerialized = OSDParser.SerializeLLSDNotation(llsdDateThree); + OSD llsdDateThreeDS = OSDParser.DeserializeLLSDNotation(sDateThreeSerialized); + Assert.AreEqual(OSDType.Date, llsdDateThreeDS.Type); + Assert.AreEqual(dtThree, llsdDateThreeDS.AsDate()); + } + + [Test()] + public void SerializeBinary() + { + byte[] binary = { 0x0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0b, + 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; + + OSD llsdBinary = OSD.FromBinary(binary); + string sBinarySerialized = OSDParser.SerializeLLSDNotation(llsdBinary); + OSD llsdBinaryDS = OSDParser.DeserializeLLSDNotation(sBinarySerialized); + Assert.AreEqual(OSDType.Binary, llsdBinaryDS.Type); + Assert.AreEqual(binary, llsdBinaryDS.AsBinary()); + } + + [Test()] + public void DeserializeArray() + { + string sArrayOne = "[]"; + OSDArray llsdArrayOne = (OSDArray)OSDParser.DeserializeLLSDNotation(sArrayOne); + Assert.AreEqual(OSDType.Array, llsdArrayOne.Type); + Assert.AreEqual(0, llsdArrayOne.Count); + + string sArrayTwo = "[ i0 ]"; + OSDArray llsdArrayTwo = (OSDArray)OSDParser.DeserializeLLSDNotation(sArrayTwo); + Assert.AreEqual(OSDType.Array, llsdArrayTwo.Type); + Assert.AreEqual(1, llsdArrayTwo.Count); + OSDInteger llsdIntOne = (OSDInteger)llsdArrayTwo[0]; + Assert.AreEqual(OSDType.Integer, llsdIntOne.Type); + Assert.AreEqual(0, llsdIntOne.AsInteger()); + + string sArrayThree = "[ i0, i1 ]"; + OSDArray llsdArrayThree = (OSDArray)OSDParser.DeserializeLLSDNotation(sArrayThree); + Assert.AreEqual(OSDType.Array, llsdArrayThree.Type); + Assert.AreEqual(2, llsdArrayThree.Count); + OSDInteger llsdIntTwo = (OSDInteger)llsdArrayThree[0]; + Assert.AreEqual(OSDType.Integer, llsdIntTwo.Type); + Assert.AreEqual(0, llsdIntTwo.AsInteger()); + OSDInteger llsdIntThree = (OSDInteger)llsdArrayThree[1]; + Assert.AreEqual(OSDType.Integer, llsdIntThree.Type); + Assert.AreEqual(1, llsdIntThree.AsInteger()); + + string sArrayFour = " [ \"testtest\", \"aha\",t,f,i1, r1.2, [ i1] ] "; + OSDArray llsdArrayFour = (OSDArray)OSDParser.DeserializeLLSDNotation(sArrayFour); + Assert.AreEqual(OSDType.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(OSDType.Array, llsdArrayFour[6].Type); + OSDArray llsdArrayFive = (OSDArray)llsdArrayFour[6]; + Assert.AreEqual(1, llsdArrayFive[0].AsInteger()); + + } + + [Test()] + public void SerializeArray() + { + OSDArray llsdOne = new OSDArray(); + string sOne = OSDParser.SerializeLLSDNotation(llsdOne); + OSDArray llsdOneDS = (OSDArray)OSDParser.DeserializeLLSDNotation(sOne); + Assert.AreEqual(OSDType.Array, llsdOneDS.Type); + Assert.AreEqual(0, llsdOneDS.Count); + + OSD llsdTwo = OSD.FromInteger(123234); + OSD llsdThree = OSD.FromString("asedkfjhaqweiurohzasdf"); + OSDArray llsdFour = new OSDArray(); + llsdFour.Add(llsdTwo); + llsdFour.Add(llsdThree); + + llsdOne.Add(llsdTwo); + llsdOne.Add(llsdThree); + llsdOne.Add(llsdFour); + + string sFive = OSDParser.SerializeLLSDNotation(llsdOne); + OSDArray llsdFive = (OSDArray)OSDParser.DeserializeLLSDNotation(sFive); + Assert.AreEqual(OSDType.Array, llsdFive.Type); + Assert.AreEqual(3, llsdFive.Count); + Assert.AreEqual(OSDType.Integer, llsdFive[0].Type); + Assert.AreEqual(123234, llsdFive[0].AsInteger()); + Assert.AreEqual(OSDType.String, llsdFive[1].Type); + Assert.AreEqual("asedkfjhaqweiurohzasdf", llsdFive[1].AsString()); + + OSDArray llsdSix = (OSDArray)llsdFive[2]; + Assert.AreEqual(OSDType.Array, llsdSix.Type); + Assert.AreEqual(2, llsdSix.Count); + Assert.AreEqual(OSDType.Integer, llsdSix[0].Type); + Assert.AreEqual(123234, llsdSix[0].AsInteger()); + Assert.AreEqual(OSDType.String, llsdSix[1].Type); + Assert.AreEqual("asedkfjhaqweiurohzasdf", llsdSix[1].AsString()); + } + + [Test()] + public void DeserializeMap() + { + string sMapOne = " { } "; + OSDMap llsdMapOne = (OSDMap)OSDParser.DeserializeLLSDNotation(sMapOne); + Assert.AreEqual(OSDType.Map, llsdMapOne.Type); + Assert.AreEqual(0, llsdMapOne.Count); + + string sMapTwo = " { \"test\":i2 } "; + OSDMap llsdMapTwo = (OSDMap)OSDParser.DeserializeLLSDNotation(sMapTwo); + Assert.AreEqual(OSDType.Map, llsdMapTwo.Type); + Assert.AreEqual(1, llsdMapTwo.Count); + Assert.AreEqual(OSDType.Integer, llsdMapTwo["test"].Type); + Assert.AreEqual(2, llsdMapTwo["test"].AsInteger()); + + string sMapThree = " { 'test':\"testtesttest\", 'aha':\"muahahaha\" , \"anywhere\":! } "; + OSDMap llsdMapThree = (OSDMap)OSDParser.DeserializeLLSDNotation(sMapThree); + Assert.AreEqual(OSDType.Map, llsdMapThree.Type); + Assert.AreEqual(3, llsdMapThree.Count); + Assert.AreEqual(OSDType.String, llsdMapThree["test"].Type); + Assert.AreEqual("testtesttest", llsdMapThree["test"].AsString()); + Assert.AreEqual(OSDType.String, llsdMapThree["test"].Type); + Assert.AreEqual("muahahaha", llsdMapThree["aha"].AsString()); + Assert.AreEqual(OSDType.Unknown, llsdMapThree["self"].Type); + + string sMapFour = " { 'test' : { 'test' : i1, 't0st' : r2.5 }, 'tist' : \"hello world!\", 'tast' : \"last\" } "; + OSDMap llsdMapFour = (OSDMap)OSDParser.DeserializeLLSDNotation(sMapFour); + Assert.AreEqual(OSDType.Map, llsdMapFour.Type); + Assert.AreEqual(3, llsdMapFour.Count); + Assert.AreEqual("hello world!", llsdMapFour["tist"].AsString()); + Assert.AreEqual("last", llsdMapFour["tast"].AsString()); + OSDMap llsdMapFive = (OSDMap)llsdMapFour["test"]; + Assert.AreEqual(OSDType.Map, llsdMapFive.Type); + Assert.AreEqual(2, llsdMapFive.Count); + Assert.AreEqual(OSDType.Integer, llsdMapFive["test"].Type); + Assert.AreEqual(1, llsdMapFive["test"].AsInteger()); + Assert.AreEqual(OSDType.Real, llsdMapFive["t0st"].Type); + Assert.AreEqual(2.5d, llsdMapFive["t0st"].AsReal()); + + } + + [Test()] + public void SerializeMap() + { + OSDMap llsdOne = new OSDMap(); + string sOne = OSDParser.SerializeLLSDNotation(llsdOne); + OSDMap llsdOneDS = (OSDMap)OSDParser.DeserializeLLSDNotation(sOne); + Assert.AreEqual(OSDType.Map, llsdOneDS.Type); + Assert.AreEqual(0, llsdOneDS.Count); + + OSD llsdTwo = OSD.FromInteger(123234); + OSD llsdThree = OSD.FromString("asedkfjhaqweiurohzasdf"); + OSDMap llsdFour = new OSDMap(); + llsdFour["test0"] = llsdTwo; + llsdFour["test1"] = llsdThree; + + llsdOne["test0"] = llsdTwo; + llsdOne["test1"] = llsdThree; + llsdOne["test2"] = llsdFour; + + string sFive = OSDParser.SerializeLLSDNotation(llsdOne); + OSDMap llsdFive = (OSDMap)OSDParser.DeserializeLLSDNotation(sFive); + Assert.AreEqual(OSDType.Map, llsdFive.Type); + Assert.AreEqual(3, llsdFive.Count); + Assert.AreEqual(OSDType.Integer, llsdFive["test0"].Type); + Assert.AreEqual(123234, llsdFive["test0"].AsInteger()); + Assert.AreEqual(OSDType.String, llsdFive["test1"].Type); + Assert.AreEqual("asedkfjhaqweiurohzasdf", llsdFive["test1"].AsString()); + + OSDMap llsdSix = (OSDMap)llsdFive["test2"]; + Assert.AreEqual(OSDType.Map, llsdSix.Type); + Assert.AreEqual(2, llsdSix.Count); + Assert.AreEqual(OSDType.Integer, llsdSix["test0"].Type); + Assert.AreEqual(123234, llsdSix["test0"].AsInteger()); + Assert.AreEqual(OSDType.String, llsdSix["test1"].Type); + Assert.AreEqual("asedkfjhaqweiurohzasdf", llsdSix["test1"].AsString()); + + // We test here also for 4byte characters as map keys + string xml = "𐄷"; + byte[] bytes = Encoding.UTF8.GetBytes(xml); + XmlTextReader xtr = new XmlTextReader(new MemoryStream(bytes, false)); + xtr.Read(); + xtr.Read(); + string content = xtr.ReadString(); + + OSDMap llsdSeven = new OSDMap(); + llsdSeven[content] = OSD.FromString(content); + string sSeven = OSDParser.SerializeLLSDNotation(llsdSeven); + OSDMap llsdSevenDS = (OSDMap)OSDParser.DeserializeLLSDNotation(sSeven); + Assert.AreEqual(OSDType.Map, llsdSevenDS.Type); + Assert.AreEqual(1, llsdSevenDS.Count); + Assert.AreEqual(content, llsdSevenDS[content].AsString()); + } + + [Test()] + public void DeserializeRealWorldExamples() + { + string realWorldExample = @" +[ + {'destination':'http://secondlife.com'}, + {'version':i1}, + { + 'agent_id':u3c115e51-04f4-523c-9fa6-98aff1034730, + 'session_id':u2c585cec-038c-40b0-b42e-a25ebab4d132, + 'circuit_code':i1075, + 'first_name':'Phoenix', + 'last_name':'Linden', + 'position':[r70.9247,r254.378,r38.7304], + 'look_at':[r-0.043753,r-0.999042,r0], + 'granters':[ua2e76fcd-9360-4f6d-a924-000000000003], + 'attachment_data': + [ + { + 'attachment_point':i2, + 'item_id':ud6852c11-a74e-309a-0462-50533f1ef9b3, + 'asset_id':uc69b29b1-8944-58ae-a7c5-2ca7b23e22fb + }, + { + 'attachment_point':i10, + 'item_id':uff852c22-a74e-309a-0462-50533f1ef900, + 'asset_id':u5868dd20-c25a-47bd-8b4c-dedc99ef9479 + } + ] + } +]"; + // We dont do full testing here. We are fine if a few values are right + // and the parser doesnt throw an exception + OSDArray llsdArray = (OSDArray)OSDParser.DeserializeLLSDNotation(realWorldExample); + Assert.AreEqual(OSDType.Array, llsdArray.Type); + Assert.AreEqual(3, llsdArray.Count); + + OSDMap llsdMapOne = (OSDMap)llsdArray[0]; + Assert.AreEqual(OSDType.Map, llsdMapOne.Type); + Assert.AreEqual("http://secondlife.com", llsdMapOne["destination"].AsString()); + + OSDMap llsdMapTwo = (OSDMap)llsdArray[1]; + Assert.AreEqual(OSDType.Map, llsdMapTwo.Type); + Assert.AreEqual(OSDType.Integer, llsdMapTwo["version"].Type); + Assert.AreEqual(1, llsdMapTwo["version"].AsInteger()); + + OSDMap llsdMapThree = (OSDMap)llsdArray[2]; + Assert.AreEqual(OSDType.UUID, llsdMapThree["session_id"].Type); + Assert.AreEqual("2c585cec-038c-40b0-b42e-a25ebab4d132", llsdMapThree["session_id"].AsString()); + Assert.AreEqual(OSDType.UUID, llsdMapThree["agent_id"].Type); + Assert.AreEqual("3c115e51-04f4-523c-9fa6-98aff1034730", llsdMapThree["agent_id"].AsString()); + + } + + [Test()] + public void SerializeFormattedTest() + { + // This is not a real test. Instead look at the console.out tab for how formatted notation looks like. + OSDArray llsdArray = new OSDArray(); + OSD llsdOne = OSD.FromInteger(1); + OSD llsdTwo = OSD.FromInteger(1); + llsdArray.Add(llsdOne); + llsdArray.Add(llsdTwo); + + OSDMap llsdMap = new OSDMap(); + OSD llsdThree = OSD.FromInteger(2); + llsdMap["test1"] = llsdThree; + OSD llsdFour = OSD.FromInteger(2); + llsdMap["test2"] = llsdFour; + + llsdArray.Add(llsdMap); + + OSDArray llsdArrayTwo = new OSDArray(); + OSD llsdFive = OSD.FromString("asdflkhjasdhj"); + OSD llsdSix = OSD.FromString("asdkfhasjkldfghsd"); + llsdArrayTwo.Add(llsdFive); + llsdArrayTwo.Add(llsdSix); + + llsdMap["test3"] = llsdArrayTwo; + + string sThree = OSDParser.SerializeLLSDNotationFormatted(llsdArray); + + // we also try to parse this... and look a little at the results + OSDArray llsdSeven = (OSDArray)OSDParser.DeserializeLLSDNotation(sThree); + Assert.AreEqual(OSDType.Array, llsdSeven.Type); + Assert.AreEqual(3, llsdSeven.Count); + Assert.AreEqual(OSDType.Integer, llsdSeven[0].Type); + Assert.AreEqual(1, llsdSeven[0].AsInteger()); + Assert.AreEqual(OSDType.Integer, llsdSeven[1].Type); + Assert.AreEqual(1, llsdSeven[1].AsInteger()); + + Assert.AreEqual(OSDType.Map, llsdSeven[2].Type); + // thats enough for now. + } + } +} diff --git a/Assets/Tests/NotationLLSDTests.cs.meta b/Assets/Tests/NotationLLSDTests.cs.meta new file mode 100644 index 0000000..38112c3 --- /dev/null +++ b/Assets/Tests/NotationLLSDTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 39041f92f42f0ae4ba5d13b5e7c5a56c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/PacketTests.cs b/Assets/Tests/PacketTests.cs new file mode 100644 index 0000000..ac84a36 --- /dev/null +++ b/Assets/Tests/PacketTests.cs @@ -0,0 +1,216 @@ +/* + * Copyright (c) 2006-2016, openmetaverse.co + * All rights reserved. + * + * - Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * - Neither the name of the openmetaverse.co nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using OpenMetaverse; +using OpenMetaverse.Packets; +using NUnit.Framework; + +namespace OpenMetaverse.Tests +{ + [TestFixture] + public class PacketTests : Assert + { + [Test] + public void HeaderFlags() + { + TestMessagePacket packet = new TestMessagePacket(); + + packet.Header.AppendedAcks = false; + packet.Header.Reliable = false; + packet.Header.Resent = false; + packet.Header.Zerocoded = false; + + Assert.IsFalse(packet.Header.AppendedAcks, "AppendedAcks: Failed to initially set the flag to false"); + Assert.IsFalse(packet.Header.Reliable, "Reliable: Failed to initially set the flag to false"); + Assert.IsFalse(packet.Header.Resent, "Resent: Failed to initially set the flag to false"); + Assert.IsFalse(packet.Header.Zerocoded, "Zerocoded: Failed to initially set the flag to false"); + + packet.Header.AppendedAcks = false; + packet.Header.Reliable = false; + packet.Header.Resent = false; + packet.Header.Zerocoded = false; + + Assert.IsFalse(packet.Header.AppendedAcks, "AppendedAcks: Failed to set the flag to false a second time"); + Assert.IsFalse(packet.Header.Reliable, "Reliable: Failed to set the flag to false a second time"); + Assert.IsFalse(packet.Header.Resent, "Resent: Failed to set the flag to false a second time"); + Assert.IsFalse(packet.Header.Zerocoded, "Zerocoded: Failed to set the flag to false a second time"); + + packet.Header.AppendedAcks = true; + packet.Header.Reliable = true; + packet.Header.Resent = true; + packet.Header.Zerocoded = true; + + Assert.IsTrue(packet.Header.AppendedAcks, "AppendedAcks: Failed to set the flag to true"); + Assert.IsTrue(packet.Header.Reliable, "Reliable: Failed to set the flag to true"); + Assert.IsTrue(packet.Header.Resent, "Resent: Failed to set the flag to true"); + Assert.IsTrue(packet.Header.Zerocoded, "Zerocoded: Failed to set the flag to true"); + + packet.Header.AppendedAcks = true; + packet.Header.Reliable = true; + packet.Header.Resent = true; + packet.Header.Zerocoded = true; + + Assert.IsTrue(packet.Header.AppendedAcks, "AppendedAcks: Failed to set the flag to true a second time"); + Assert.IsTrue(packet.Header.Reliable, "Reliable: Failed to set the flag to true a second time"); + Assert.IsTrue(packet.Header.Resent, "Resent: Failed to set the flag to true a second time"); + Assert.IsTrue(packet.Header.Zerocoded, "Zerocoded: Failed to set the flag to true a second time"); + + packet.Header.AppendedAcks = false; + packet.Header.Reliable = false; + packet.Header.Resent = false; + packet.Header.Zerocoded = false; + + Assert.IsFalse(packet.Header.AppendedAcks, "AppendedAcks: Failed to set the flag back to false"); + Assert.IsFalse(packet.Header.Reliable, "Reliable: Failed to set the flag back to false"); + Assert.IsFalse(packet.Header.Resent, "Resent: Failed to set the flag back to false"); + Assert.IsFalse(packet.Header.Zerocoded, "Zerocoded: Failed to set the flag back to false"); + } + + [Test] + public void ToBytesMultiple() + { + UUID testID = UUID.Random(); + + DirPlacesReplyPacket bigPacket = new DirPlacesReplyPacket(); + bigPacket.Header.Zerocoded = false; + bigPacket.Header.Sequence = 42; + bigPacket.Header.AppendedAcks = true; + bigPacket.Header.AckList = new uint[50]; + for (int i = 0; i < bigPacket.Header.AckList.Length; i++) { bigPacket.Header.AckList[i] = (uint)i; } + bigPacket.AgentData.AgentID = testID; + bigPacket.QueryData = new DirPlacesReplyPacket.QueryDataBlock[100]; + for (int i = 0; i < bigPacket.QueryData.Length; i++) + { + bigPacket.QueryData[i] = new DirPlacesReplyPacket.QueryDataBlock(); + bigPacket.QueryData[i].QueryID = testID; + } + bigPacket.QueryReplies = new DirPlacesReplyPacket.QueryRepliesBlock[100]; + for (int i = 0; i < bigPacket.QueryReplies.Length; i++) + { + bigPacket.QueryReplies[i] = new DirPlacesReplyPacket.QueryRepliesBlock(); + bigPacket.QueryReplies[i].Auction = (i & 1) == 0; + bigPacket.QueryReplies[i].Dwell = (float)i; + bigPacket.QueryReplies[i].ForSale = (i & 1) == 0; + bigPacket.QueryReplies[i].Name = Utils.StringToBytes("DirPlacesReply Test String"); + bigPacket.QueryReplies[i].ParcelID = testID; + } + bigPacket.StatusData = new DirPlacesReplyPacket.StatusDataBlock[100]; + for (int i = 0; i < bigPacket.StatusData.Length; i++) + { + bigPacket.StatusData[i] = new DirPlacesReplyPacket.StatusDataBlock(); + bigPacket.StatusData[i].Status = (uint)i; + } + + byte[][] splitPackets = bigPacket.ToBytesMultiple(); + + int queryDataCount = 0; + int queryRepliesCount = 0; + int statusDataCount = 0; + for (int i = 0; i < splitPackets.Length; i++) + { + byte[] packetData = splitPackets[i]; + int len = packetData.Length - 1; + DirPlacesReplyPacket packet = (DirPlacesReplyPacket)Packet.BuildPacket(packetData, ref len, packetData); + + Assert.IsTrue(packet.AgentData.AgentID == bigPacket.AgentData.AgentID); + + for (int j = 0; j < packet.QueryReplies.Length; j++) + { + Assert.IsTrue(packet.QueryReplies[j].Dwell == (float)(queryRepliesCount + j), + "Expected Dwell of " + (float)(queryRepliesCount + j) + " but got " + packet.QueryReplies[j].Dwell); + Assert.IsTrue(packet.QueryReplies[j].ParcelID == testID); + } + + queryDataCount += packet.QueryData.Length; + queryRepliesCount += packet.QueryReplies.Length; + statusDataCount += packet.StatusData.Length; + } + + Assert.IsTrue(queryDataCount == bigPacket.QueryData.Length); + Assert.IsTrue(queryRepliesCount == bigPacket.QueryData.Length); + Assert.IsTrue(statusDataCount == bigPacket.StatusData.Length); + + ScriptDialogPacket scriptDialogPacket = new ScriptDialogPacket(); + scriptDialogPacket.Data.ChatChannel = 0; + scriptDialogPacket.Data.FirstName = Utils.EmptyBytes; + scriptDialogPacket.Data.ImageID = UUID.Zero; + scriptDialogPacket.Data.LastName = Utils.EmptyBytes; + scriptDialogPacket.Data.Message = Utils.EmptyBytes; + scriptDialogPacket.Data.ObjectID = UUID.Zero; + scriptDialogPacket.Data.ObjectName = Utils.EmptyBytes; + scriptDialogPacket.Buttons = new ScriptDialogPacket.ButtonsBlock[0]; + scriptDialogPacket.OwnerData = new ScriptDialogPacket.OwnerDataBlock[1]; + scriptDialogPacket.OwnerData[0] = new ScriptDialogPacket.OwnerDataBlock(); + scriptDialogPacket.OwnerData[0].OwnerID = UUID.Zero; + + byte[][] splitPacket = scriptDialogPacket.ToBytesMultiple(); + + Assert.IsNotNull(splitPacket); + Assert.IsTrue(splitPacket.Length == 1, "Expected ScriptDialog packet to split into 1 packet but got " + splitPacket.Length); + + ParcelReturnObjectsPacket proPacket = new ParcelReturnObjectsPacket(); + proPacket.AgentData.AgentID = UUID.Zero; + proPacket.AgentData.SessionID = UUID.Zero; + proPacket.ParcelData.LocalID = 0; + proPacket.ParcelData.ReturnType = 0; + proPacket.TaskIDs = new ParcelReturnObjectsPacket.TaskIDsBlock[0]; + proPacket.OwnerIDs = new ParcelReturnObjectsPacket.OwnerIDsBlock[1]; + proPacket.OwnerIDs[0] = new ParcelReturnObjectsPacket.OwnerIDsBlock(); + proPacket.OwnerIDs[0].OwnerID = UUID.Zero; + + splitPacket = proPacket.ToBytesMultiple(); + + Assert.IsNotNull(splitPacket); + Assert.IsTrue(splitPacket.Length == 1, "Expected ParcelReturnObjectsPacket packet to split into 1 packet but got " + splitPacket.Length); + + InventoryDescendentsPacket invPacket = new InventoryDescendentsPacket(); + invPacket.FolderData = new InventoryDescendentsPacket.FolderDataBlock[1]; + invPacket.FolderData[0] = new InventoryDescendentsPacket.FolderDataBlock(); + invPacket.FolderData[0].Name = Utils.EmptyBytes; + invPacket.ItemData = new InventoryDescendentsPacket.ItemDataBlock[5]; + for (int i = 0; i < 5; i++) + { + invPacket.ItemData[i] = new InventoryDescendentsPacket.ItemDataBlock(); + invPacket.ItemData[i].Description = Utils.StringToBytes("Unit Test Item Description"); + invPacket.ItemData[i].Name = Utils.StringToBytes("Unit Test Item Name"); + } + + splitPacket = invPacket.ToBytesMultiple(); + + Assert.IsNotNull(splitPacket); + Assert.IsTrue(splitPacket.Length == 1, "Split InventoryDescendents packet into " + splitPacket.Length + " instead of 1 packet"); + + int x = 0; + int y = splitPacket[0].Length - 1; + invPacket.FromBytes(splitPacket[0], ref x, ref y, null); + + Assert.IsTrue(invPacket.FolderData.Length == 1, "InventoryDescendents packet came back with " + invPacket.FolderData.Length + " FolderData blocks"); + Assert.IsTrue(invPacket.ItemData.Length == 5, "InventoryDescendents packet came back with " + invPacket.ItemData.Length + " ItemData blocks"); + } + } +} diff --git a/Assets/Tests/PacketTests.cs.meta b/Assets/Tests/PacketTests.cs.meta new file mode 100644 index 0000000..583781b --- /dev/null +++ b/Assets/Tests/PacketTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b96829043dde76b4fba18c205d2ac390 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/PrimObjectTests.cs b/Assets/Tests/PrimObjectTests.cs new file mode 100644 index 0000000..018dc5a --- /dev/null +++ b/Assets/Tests/PrimObjectTests.cs @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2006-2016, openmetaverse.co + * All rights reserved. + * + * - Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * - Neither the name of the openmetaverse.co nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using System.Net; +using OpenMetaverse; +using OpenMetaverse.Packets; +using NUnit.Framework; + +namespace OpenMetaverse.Tests +{ + [TestFixture] + public class PrimObjectTests : Assert + { + [Test] + public void PathBegin() + { + for (byte i = 0; i < byte.MaxValue; i++) + { + float floatValue = Primitive.UnpackBeginCut(i); + ushort result = Primitive.PackBeginCut(floatValue); + + Assert.IsTrue(result == i, "Started with " + i + ", float value was " + floatValue + + ", and ended up with " + result); + } + } + + [Test] + public void PathEnd() + { + for (byte i = 0; i < byte.MaxValue; i++) + { + float floatValue = Primitive.UnpackEndCut(i); + ushort result = Primitive.PackEndCut(floatValue); + + Assert.IsTrue(result == i, "Started with " + i + ", float value was " + floatValue + + ", and ended up with " + result); + } + } + + [Test] + public void PathRevolutions() + { + for (byte i = 0; i < byte.MaxValue; i++) + { + float floatValue = Primitive.UnpackPathRevolutions(i); + byte result = Primitive.PackPathRevolutions(floatValue); + + Assert.IsTrue(result == i, "Started with " + i + ", float value was " + floatValue + + ", and ended up with " + result); + } + } + + [Test] + public void PathScale() + { + for (byte i = 0; i < byte.MaxValue; i++) + { + float floatValue = Primitive.UnpackPathScale(i); + byte result = Primitive.PackPathScale(floatValue); + + Assert.IsTrue(result == i, "Started with " + i + ", float value was " + floatValue + + ", and ended up with " + result); + } + } + + //[Test] + //public void PathShear() + //{ + // for (byte i = 0; i < byte.MaxValue; i++) + // { + // float floatValue = Primitive.UnpackPathShear(i); + // byte result = Primitive.PackPathShear(floatValue); + + // Assert.IsTrue(result == i, "Started with " + i + ", float value was " + floatValue + + // ", and ended up with " + result); + // } + //} + + [Test] + public void PathTaper() + { + for (sbyte i = sbyte.MinValue; i < sbyte.MaxValue; i++) + { + float floatValue = Primitive.UnpackPathTaper(i); + sbyte result = Primitive.PackPathTaper(floatValue); + + Assert.IsTrue(result == i, "Started with " + i + ", float value was " + floatValue + + ", and ended up with " + result); + } + } + + [Test] + public void TextureEntryOffsets() + { + for (float i = -1.0f; i <= 1.0f; i += 0.001f) + { + i = (float)Math.Round(i, 3); + + short offset = Helpers.TEOffsetShort(i); + float foffset = Helpers.TEOffsetFloat(BitConverter.GetBytes(offset), 0); + foffset = (float)Math.Round(foffset, 3); + + Assert.IsTrue(foffset - i < Single.Epsilon, foffset + " is not equal to " + i); + } + } + + [Test] + public void TextureEntry() + { + Primitive.TextureEntry te = new Primitive.TextureEntry(UUID.Random()); + Primitive.TextureEntryFace face = te.CreateFace(0); + face.Bump = Bumpiness.Concrete; + face.Fullbright = true; + face.MediaFlags = true; + face.OffsetU = 0.5f; + face.OffsetV = -0.5f; + face.RepeatU = 3.0f; + face.RepeatV = 4.0f; + face.RGBA = new Color4(0f, 0.25f, 0.75f, 1f); + face.Rotation = 1.5f; + face.Shiny = Shininess.Medium; + face.TexMapType = MappingType.Planar; + face.TextureID = UUID.Random(); + + byte[] teBytes = te.GetBytes(); + + Primitive.TextureEntry te2 = new Primitive.TextureEntry(teBytes, 0, teBytes.Length); + + byte[] teBytes2 = te2.GetBytes(); + + Assert.IsTrue(teBytes.Length == teBytes2.Length); + + for (int i = 0; i < teBytes.Length; i++) + { + Assert.IsTrue(teBytes[i] == teBytes2[i], "Byte " + i + " is not equal"); + } + } + } +} diff --git a/Assets/Tests/PrimObjectTests.cs.meta b/Assets/Tests/PrimObjectTests.cs.meta new file mode 100644 index 0000000..9e061f8 --- /dev/null +++ b/Assets/Tests/PrimObjectTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 91415889acfec554da86a1e988370310 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/Test_LibreMetaverse.cs b/Assets/Tests/Test_LibreMetaverse.cs deleted file mode 100644 index 41a8a31..0000000 --- a/Assets/Tests/Test_LibreMetaverse.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using NUnit.Framework; -using UnityEngine; -using UnityEngine.TestTools; - -public class Test_LibreMetaverse -{ - // A Test behaves as an ordinary method - [Test] - public void Test_LibreMetaverseSimplePasses() - { - // Use the Assert class to test conditions - } - - // A UnityTest behaves like a coroutine in Play Mode. In Edit Mode you can use - // `yield return null;` to skip a frame. - [UnityTest] - public IEnumerator Test_LibreMetaverseWithEnumeratorPasses() - { - // Use the Assert class to test conditions. - // Use yield to skip a frame. - yield return null; - } -} diff --git a/Assets/Tests/TypeTests.cs b/Assets/Tests/TypeTests.cs new file mode 100644 index 0000000..5a7bace --- /dev/null +++ b/Assets/Tests/TypeTests.cs @@ -0,0 +1,368 @@ +/* + * Copyright (c) 2006-2016, openmetaverse.co + * All rights reserved. + * + * - Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * - Neither the name of the openmetaverse.co nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections; +using System.Collections.Generic; +using OpenMetaverse; +using OpenMetaverse.Packets; +using OpenMetaverse.StructuredData; +using NUnit.Framework; + +namespace OpenMetaverse.Tests +{ + [TestFixture] + public class TypeTests : Assert + { + [Test] + public void UUIDs() + { + // Creation + UUID a = new UUID(); + byte[] bytes = a.GetBytes(); + for (int i = 0; i < 16; i++) + Assert.IsTrue(bytes[i] == 0x00); + + // Comparison + a = new UUID(new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, + 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF }, 0); + UUID b = new UUID(new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, + 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }, 0); + + Assert.IsTrue(a == b, "UUID comparison operator failed, " + a.ToString() + " should equal " + + b.ToString()); + + // From string + a = new UUID(new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, + 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }, 0); + string zeroonetwo = "00010203-0405-0607-0809-0a0b0c0d0e0f"; + b = new UUID(zeroonetwo); + + Assert.IsTrue(a == b, "UUID hyphenated string constructor failed, should have " + a.ToString() + + " but we got " + b.ToString()); + + // ToString() + Assert.IsTrue(a == b); + Assert.IsTrue(a == (UUID)zeroonetwo); + + // TODO: CRC test + } + + [Test] + public void Vector3ApproxEquals() + { + Vector3 a = new Vector3(1f, 0f, 0f); + Vector3 b = new Vector3(0f, 0f, 0f); + + Assert.IsFalse(a.ApproxEquals(b, 0.9f), "ApproxEquals failed (1)"); + Assert.IsTrue(a.ApproxEquals(b, 1.0f), "ApproxEquals failed (2)"); + + a = new Vector3(-1f, 0f, 0f); + b = new Vector3(1f, 0f, 0f); + + Assert.IsFalse(a.ApproxEquals(b, 1.9f), "ApproxEquals failed (3)"); + Assert.IsTrue(a.ApproxEquals(b, 2.0f), "ApproxEquals failed (4)"); + + a = new Vector3(0f, -1f, 0f); + b = new Vector3(0f, -1.1f, 0f); + + Assert.IsFalse(a.ApproxEquals(b, 0.09f), "ApproxEquals failed (5)"); + Assert.IsTrue(a.ApproxEquals(b, 0.11f), "ApproxEquals failed (6)"); + + a = new Vector3(0f, 0f, 0.00001f); + b = new Vector3(0f, 0f, 0f); + + Assert.IsFalse(b.ApproxEquals(a, Single.Epsilon), "ApproxEquals failed (6)"); + Assert.IsTrue(b.ApproxEquals(a, 0.0001f), "ApproxEquals failed (7)"); + } + + [Test] + public void VectorCasting() + { + Dictionary testNumbers; + testNumbers = new Dictionary(); + testNumbers["1.0"] = 1.0; + testNumbers["1.1"] = 1.1; + testNumbers["1.01"] = 1.01; + testNumbers["1.001"] = 1.001; + testNumbers["1.0001"] = 1.0001; + testNumbers["1.00001"] = 1.00001; + testNumbers["1.000001"] = 1.000001; + testNumbers["1.0000001"] = 1.0000001; + testNumbers["1.00000001"] = 1.00000001; + + foreach (KeyValuePair kvp in testNumbers) + { + double testNumber = kvp.Value; + double testNumber2 = (double)((float)testNumber); + bool noPrecisionLoss = testNumber == testNumber2; + + Vector3 a = new Vector3( + (float)testNumber, + (float)testNumber, (float)testNumber); + Vector3d b = new Vector3d(testNumber, testNumber, testNumber); + + Vector3 c = (Vector3)b; + Vector3d d = a; + + if (noPrecisionLoss) + { + Console.Error.WriteLine("Unsuitable test value used-" + + " test number should have precision loss when" + + " cast to float ({0}).", kvp.Key); + } + else + { + Assert.IsFalse(a == b, string.Format( + "Vector casting failed, precision loss should" + + " have occurred. " + + "{0}: {1}, {2}", kvp.Key, a.X, b.X)); + Assert.IsFalse(b == d, string.Format( + "Vector casting failed, explicit cast of double" + + " to float should result in precision loss" + + " whichwas should not magically disappear when" + + " Vector3 is implicitly cast to Vector3d." + + " {0}: {1}, {2}", kvp.Key, b.X, d.X)); + } + Assert.IsTrue(a == c, string.Format( + "Vector casting failed, Vector3 compared to" + + " explicit cast of Vector3d to Vector3 should" + + " result in identical precision loss." + + " {0}: {1}, {2}", kvp.Key, a.X, c.X)); + Assert.IsTrue(a == d, string.Format( + "Vector casting failed, implicit cast of Vector3" + + " to Vector3d should not result in precision loss." + + " {0}: {1}, {2}", kvp.Key, a.X, d.X)); + } + } + + [Test] + public void Quaternions() + { + Quaternion a = new Quaternion(1, 0, 0, 0); + Quaternion b = new Quaternion(1, 0, 0, 0); + + Assert.IsTrue(a == b, "Quaternion comparison operator failed"); + + Quaternion expected = new Quaternion(0, 0, 0, -1); + Quaternion result = a * b; + + Assert.IsTrue(result == expected, a.ToString() + " * " + b.ToString() + " produced " + result.ToString() + + " instead of " + expected.ToString()); + + a = new Quaternion(1, 0, 0, 0); + b = new Quaternion(0, 1, 0, 0); + expected = new Quaternion(0, 0, 1, 0); + result = a * b; + + Assert.IsTrue(result == expected, a.ToString() + " * " + b.ToString() + " produced " + result.ToString() + + " instead of " + expected.ToString()); + + a = new Quaternion(0, 0, 1, 0); + b = new Quaternion(0, 1, 0, 0); + expected = new Quaternion(-1, 0, 0, 0); + result = a * b; + + Assert.IsTrue(result == expected, a.ToString() + " * " + b.ToString() + " produced " + result.ToString() + + " instead of " + expected.ToString()); + } + + [Test] + public void testMatrix() + { + Matrix4 matrix = new Matrix4(0, 0, 74, 1, + 0, 435, 0, 1, + 345, 0, 34, 1, + 0, 0, 0, 0); + + /* determinant of singular matrix returns zero */ + Assert.AreEqual(0d, (double)matrix.Determinant(), 0.001d); + + /* inverse of identity matrix is the identity matrix */ + Assert.IsTrue(Matrix4.Identity == Matrix4.Inverse(Matrix4.Identity)); + + /* inverse of non-singular matrix returns True And InverseMatrix */ + matrix = new Matrix4(1, 1, 0, 0, + 1, 1, 1, 0, + 0, 1, 1, 0, + 0, 0, 0, 1); + Matrix4 expectedInverse = new Matrix4(0, 1,-1, 0, + 1,-1, 1, 0, + -1, 1, 0, 0, + 0, 0, 0, 1); + Assert.AreEqual(expectedInverse, Matrix4.Inverse(matrix)); + } + + //[Test] + //public void VectorQuaternionMath() + //{ + // // Convert a vector to a quaternion and back + // Vector3 a = new Vector3(1f, 0.5f, 0.75f); + // Quaternion b = a.ToQuaternion(); + // Vector3 c; + // b.GetEulerAngles(out c.X, out c.Y, out c.Z); + + // Assert.IsTrue(a == c, c.ToString() + " does not equal " + a.ToString()); + //} + + [Test] + public void FloatsToTerseStrings() + { + float f = 1.20f; + string a = String.Empty; + string b = "1.2"; + + a = Helpers.FloatToTerseString(f); + Assert.IsTrue(a == b, f.ToString() + " converted to " + a + ", expecting " + b); + + f = 24.00f; + b = "24"; + + a = Helpers.FloatToTerseString(f); + Assert.IsTrue(a == b, f.ToString() + " converted to " + a + ", expecting " + b); + + f = -0.59f; + b = "-.59"; + + a = Helpers.FloatToTerseString(f); + Assert.IsTrue(a == b, f.ToString() + " converted to " + a + ", expecting " + b); + + f = 0.59f; + b = ".59"; + + a = Helpers.FloatToTerseString(f); + Assert.IsTrue(a == b, f.ToString() + " converted to " + a + ", expecting " + b); + } + + [Test] + public void BitUnpacking() + { + byte[] data = new byte[] { 0x80, 0x00, 0x0F, 0x50, 0x83, 0x7D }; + BitPack bitpacker = new BitPack(data, 0); + + int b = bitpacker.UnpackBits(1); + Assert.IsTrue(b == 1, "Unpacked " + b + " instead of 1"); + + b = bitpacker.UnpackBits(1); + Assert.IsTrue(b == 0, "Unpacked " + b + " instead of 0"); + + bitpacker = new BitPack(data, 2); + + b = bitpacker.UnpackBits(4); + Assert.IsTrue(b == 0, "Unpacked " + b + " instead of 0"); + + b = bitpacker.UnpackBits(8); + Assert.IsTrue(b == 0xF5, "Unpacked " + b + " instead of 0xF5"); + + b = bitpacker.UnpackBits(4); + Assert.IsTrue(b == 0, "Unpacked " + b + " instead of 0"); + + b = bitpacker.UnpackBits(10); + Assert.IsTrue(b == 0x0183, "Unpacked " + b + " instead of 0x0183"); + } + + [Test] + public void BitPacking() + { + byte[] packedBytes = new byte[12]; + BitPack bitpacker = new BitPack(packedBytes, 0); + + bitpacker.PackBits(0x0ABBCCDD, 32); + bitpacker.PackBits(25, 5); + bitpacker.PackFloat(123.321f); + bitpacker.PackBits(1000, 16); + + bitpacker = new BitPack(packedBytes, 0); + + int b = bitpacker.UnpackBits(32); + Assert.IsTrue(b == 0x0ABBCCDD, "Unpacked " + b + " instead of 2864434397"); + + b = bitpacker.UnpackBits(5); + Assert.IsTrue(b == 25, "Unpacked " + b + " instead of 25"); + + float f = bitpacker.UnpackFloat(); + Assert.IsTrue(f == 123.321f, "Unpacked " + f + " instead of 123.321"); + + b = bitpacker.UnpackBits(16); + Assert.IsTrue(b == 1000, "Unpacked " + b + " instead of 1000"); + + packedBytes = new byte[1]; + bitpacker = new BitPack(packedBytes, 0); + bitpacker.PackBit(true); + + bitpacker = new BitPack(packedBytes, 0); + b = bitpacker.UnpackBits(1); + Assert.IsTrue(b == 1, "Unpacked " + b + " instead of 1"); + + packedBytes = new byte[1] { Byte.MaxValue }; + bitpacker = new BitPack(packedBytes, 0); + bitpacker.PackBit(false); + + bitpacker = new BitPack(packedBytes, 0); + b = bitpacker.UnpackBits(1); + Assert.IsTrue(b == 0, "Unpacked " + b + " instead of 0"); + } + + [Test] + public void LLSDTerseParsing() + { + string testOne = "[r0.99967899999999998428,r-0.025334599999999998787,r0]"; + string testTwo = "[[r1,r1,r1],r0]"; + string testThree = "{'region_handle':[r255232, r256512], 'position':[r33.6, r33.71, r43.13], 'look_at':[r34.6, r33.71, r43.13]}"; + + OSD obj = OSDParser.DeserializeLLSDNotation(testOne); + Assert.IsInstanceOf(obj, "Expected SDArray, got " + obj.GetType().ToString()); + OSDArray array = (OSDArray)obj; + Assert.IsTrue(array.Count == 3, "Expected three contained objects, got " + array.Count); + Assert.IsTrue(array[0].AsReal() > 0.9d && array[0].AsReal() < 1.0d, "Unexpected value for first real " + array[0].AsReal()); + Assert.IsTrue(array[1].AsReal() < 0.0d && array[1].AsReal() > -0.03d, "Unexpected value for second real " + array[1].AsReal()); + Assert.IsTrue(array[2].AsReal() == 0.0d, "Unexpected value for third real " + array[2].AsReal()); + + obj = OSDParser.DeserializeLLSDNotation(testTwo); + Assert.IsInstanceOf(obj, "Expected SDArray, got " + obj.GetType().ToString()); + array = (OSDArray)obj; + Assert.IsTrue(array.Count == 2, "Expected two contained objects, got " + array.Count); + Assert.IsTrue(array[1].AsReal() == 0.0d, "Unexpected value for real " + array[1].AsReal()); + obj = array[0]; + Assert.IsInstanceOf(obj, "Expected ArrayList, got " + obj.GetType().ToString()); + array = (OSDArray)obj; + Assert.IsTrue(array[0].AsReal() == 1.0d && array[1].AsReal() == 1.0d && array[2].AsReal() == 1.0d, + "Unexpected value(s) for nested array: " + array[0].AsReal() + ", " + array[1].AsReal() + ", " + + array[2].AsReal()); + + obj = OSDParser.DeserializeLLSDNotation(testThree); + Assert.IsInstanceOf(obj, "Expected LLSDMap, got " + obj.GetType().ToString()); + OSDMap hashtable = (OSDMap)obj; + Assert.IsTrue(hashtable.Count == 3, "Expected three contained objects, got " + hashtable.Count); + Assert.IsInstanceOf(hashtable["region_handle"]); + Assert.IsTrue(((OSDArray)hashtable["region_handle"]).Count == 2); + Assert.IsInstanceOf(hashtable["position"]); + Assert.IsTrue(((OSDArray)hashtable["position"]).Count == 3); + Assert.IsInstanceOf(hashtable["look_at"]); + Assert.IsTrue(((OSDArray)hashtable["look_at"]).Count == 3); + } + } +} diff --git a/Assets/Tests/TypeTests.cs.meta b/Assets/Tests/TypeTests.cs.meta new file mode 100644 index 0000000..6e052ef --- /dev/null +++ b/Assets/Tests/TypeTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bcce836b577a95548976d7b43a93e604 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tests/XmlLLSDTests.cs b/Assets/Tests/XmlLLSDTests.cs new file mode 100644 index 0000000..82cad32 --- /dev/null +++ b/Assets/Tests/XmlLLSDTests.cs @@ -0,0 +1,618 @@ +/* + * Copyright (c) 2006-2016, openmetaverse.co + * All rights reserved. + * + * - Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * - Neither the name of the openmetaverse.co nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections.Generic; +using System.Text; +using NUnit.Framework; +using System.Collections; +using OpenMetaverse.StructuredData; + +namespace OpenMetaverse.Tests +{ + /// + /// XmlSDTests is a suite of tests for libsl implementation of the SD XML format. + /// + /// + [TestFixture] + public class XmlSDTests + { + /// + /// Test that the sample LLSD supplied by Linden Lab is properly deserialized. + /// The LLSD string in the test is a pared down version of the sample on the blog. + /// http://wiki.secondlife.com/wiki/LLSD + /// + [Test] + public void DeserializeLLSDSample() + { + OSD theSD = null; + OSDMap map = null; + OSD tempSD = null; + OSDUUID tempUUID = null; + OSDString tempStr = null; + OSDReal tempReal = null; + + String testSD = @" + + + region_id + 67153d5b-3659-afb4-8510-adda2c034649 + scale + one minute + simulator statistics + + time dilation + 0.9878624 + sim fps + 44.38898 + agent updates per second + nan + total task count + 4 + active task count + 0 + pending uploads + 0.0001096525 + + + "; + + //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()); + + } + + /// + /// Test that various Real representations are parsed correctly. + /// + [Test] + public void DeserializeReals() + { + OSD theSD = null; + OSDArray array = null; + OSDReal tempReal = null; + + String testSD = @" + + + 44.38898 + nan + 4 + -13.333 + + + "; + //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()); + } + + /// + /// Test that various String representations are parsed correctly. + /// + [Test] + public void DeserializeStrings() + { + OSD theSD = null; + OSDArray array = null; + OSDString tempStr = null; + + String testSD = @" + + + Kissling + Attack ships on fire off the shoulder of Orion + < > & ' " + + + "; + //Deserialize the string + byte[] bytes = Encoding.UTF8.GetBytes(testSD); + theSD = OSDParser.DeserializeLLSDXml(bytes); + + Assert.IsTrue(theSD is OSDArray); + array = (OSDArray)theSD; + + Assert.AreEqual(OSDType.String, array[0].Type); + tempStr = (OSDString)array[0]; + Assert.AreEqual("Kissling", tempStr.AsString()); + + Assert.AreEqual(OSDType.String, array[1].Type); + tempStr = (OSDString)array[1]; + Assert.AreEqual("Attack ships on fire off the shoulder of Orion", tempStr.AsString()); + + Assert.AreEqual(OSDType.String, array[2].Type); + tempStr = (OSDString)array[2]; + Assert.AreEqual("< > & \' \"", tempStr.AsString()); + + Assert.AreEqual(OSDType.String, array[3].Type); + tempStr = (OSDString)array[3]; + Assert.AreEqual("", tempStr.AsString()); + + } + + /// + /// Test that various Integer representations are parsed correctly. + /// These tests currently only test for values within the range of a + /// 32 bit signed integer, even though the SD specification says + /// the type is a 64 bit signed integer, because LLSInteger is currently + /// implemented using int, a.k.a. Int32. Not testing Int64 range until + /// it's understood if there was a design reason for the Int32. + /// + [Test] + public void DeserializeIntegers() + { + OSD theSD = null; + OSDArray array = null; + OSDInteger tempInt = null; + + String testSD = @" + + + 2147483647 + -2147483648 + 0 + 013 + + + "; + //Deserialize the string + byte[] bytes = Encoding.UTF8.GetBytes(testSD); + theSD = OSDParser.DeserializeLLSDXml(bytes); + + Assert.IsTrue(theSD is OSDArray); + array = (OSDArray)theSD; + + Assert.AreEqual(OSDType.Integer, array[0].Type); + tempInt = (OSDInteger)array[0]; + Assert.AreEqual(2147483647, tempInt.AsInteger()); + + Assert.AreEqual(OSDType.Integer, array[1].Type); + tempInt = (OSDInteger)array[1]; + Assert.AreEqual(-2147483648, tempInt.AsInteger()); + + Assert.AreEqual(OSDType.Integer, array[2].Type); + tempInt = (OSDInteger)array[2]; + Assert.AreEqual(0, tempInt.AsInteger()); + + Assert.AreEqual(OSDType.Integer, array[3].Type); + tempInt = (OSDInteger)array[3]; + Assert.AreEqual(13, tempInt.AsInteger()); + + Assert.AreEqual(OSDType.Integer, array[4].Type); + tempInt = (OSDInteger)array[4]; + Assert.AreEqual(0, tempInt.AsInteger()); + } + + /// + /// Test that various UUID representations are parsed correctly. + /// + [Test] + public void DeserializeUUID() + { + OSD theSD = null; + OSDArray array = null; + OSDUUID tempUUID = null; + + String testSD = @" + + + d7f4aeca-88f1-42a1-b385-b9db18abb255 + + + "; + //Deserialize the string + byte[] bytes = Encoding.UTF8.GetBytes(testSD); + theSD = OSDParser.DeserializeLLSDXml(bytes); + + Assert.IsTrue(theSD is OSDArray); + array = (OSDArray)theSD; + + Assert.AreEqual(OSDType.UUID, array[0].Type); + tempUUID = (OSDUUID)array[0]; + Assert.AreEqual(new UUID("d7f4aeca-88f1-42a1-b385-b9db18abb255"), tempUUID.AsUUID()); + + Assert.AreEqual(OSDType.UUID, array[1].Type); + tempUUID = (OSDUUID)array[1]; + Assert.AreEqual(UUID.Zero, tempUUID.AsUUID()); + } + + /// + /// Test that various date representations are parsed correctly. + /// + [Test] + public void DeserializeDates() + { + OSD theSD = null; + OSDArray array = null; + OSDDate tempDate = null; + DateTime testDate; + + String testSD = @" + + + 2006-02-01T14:29:53Z + 1999-01-01T00:00:00Z + + + "; + //Deserialize the string + byte[] bytes = Encoding.UTF8.GetBytes(testSD); + theSD = OSDParser.DeserializeLLSDXml(bytes); + + Assert.IsTrue(theSD is OSDArray); + array = (OSDArray)theSD; + + Assert.AreEqual(OSDType.Date, array[0].Type); + tempDate = (OSDDate)array[0]; + DateTime.TryParse("2006-02-01T14:29:53Z", out testDate); + Assert.AreEqual(testDate, tempDate.AsDate()); + + Assert.AreEqual(OSDType.Date, array[1].Type); + tempDate = (OSDDate)array[1]; + DateTime.TryParse("1999-01-01T00:00:00Z", out testDate); + Assert.AreEqual(testDate, tempDate.AsDate()); + + Assert.AreEqual(OSDType.Date, array[2].Type); + tempDate = (OSDDate)array[2]; + Assert.AreEqual(Utils.Epoch, tempDate.AsDate()); + } + + /// + /// Test that various Boolean representations are parsed correctly. + /// + [Test] + public void DeserializeBoolean() + { + OSD theSD = null; + OSDArray array = null; + OSDBoolean tempBool = null; + + String testSD = @" + + + 1 + true + 0 + false + + + "; + //Deserialize the string + byte[] bytes = Encoding.UTF8.GetBytes(testSD); + theSD = OSDParser.DeserializeLLSDXml(bytes); + + Assert.IsTrue(theSD is OSDArray); + array = (OSDArray)theSD; + + Assert.AreEqual(OSDType.Boolean, array[0].Type); + tempBool = (OSDBoolean)array[0]; + Assert.AreEqual(true, tempBool.AsBoolean()); + + Assert.AreEqual(OSDType.Boolean, array[1].Type); + tempBool = (OSDBoolean)array[1]; + Assert.AreEqual(true, tempBool.AsBoolean()); + + Assert.AreEqual(OSDType.Boolean, array[2].Type); + tempBool = (OSDBoolean)array[2]; + Assert.AreEqual(false, tempBool.AsBoolean()); + + Assert.AreEqual(OSDType.Boolean, array[3].Type); + tempBool = (OSDBoolean)array[3]; + Assert.AreEqual(false, tempBool.AsBoolean()); + + Assert.AreEqual(OSDType.Boolean, array[4].Type); + tempBool = (OSDBoolean)array[4]; + Assert.AreEqual(false, tempBool.AsBoolean()); + } + + /// + /// Test that binary elements are parsed correctly. + /// + [Test] + public void DeserializeBinary() + { + OSD theSD = null; + OSDArray array = null; + OSDBinary tempBinary = null; + + String testSD = @" + + + cmFuZG9t + dGhlIHF1aWNrIGJyb3duIGZveA== + + + "; + + //Deserialize the string + byte[] bytes = Encoding.UTF8.GetBytes(testSD); + theSD = OSDParser.DeserializeLLSDXml(bytes); + + Assert.IsTrue(theSD is OSDArray); + array = (OSDArray)theSD; + + Assert.AreEqual(OSDType.Binary, array[0].Type); + tempBinary = (OSDBinary)array[0]; + byte[] testData1 = {114, 97, 110, 100, 111, 109}; + TestHelper.TestBinary(tempBinary, testData1); + + Assert.AreEqual(OSDType.Binary, array[1].Type); + tempBinary = (OSDBinary)array[1]; + byte[] testData2 = {116, 104, 101, 32, 113, 117, 105, 99, 107, 32, 98, + 114, 111, 119, 110, 32, 102, 111, 120}; + TestHelper.TestBinary(tempBinary, testData2); + + Assert.AreEqual(OSDType.Binary, array[1].Type); + tempBinary = (OSDBinary)array[2]; + Assert.AreEqual(0, tempBinary.AsBinary().Length); + } + + /// + /// Test that undefened elements are parsed correctly. + /// Currently this just checks that there is no error since undefined has no + /// value and there is no SD child class for Undefined elements - the + /// current implementation generates an instance of SD + /// + [Test] + public void DeserializeUndef() + { + OSD theSD = null; + + String testSD = @" + + + "; + //Deserialize the string + byte[] bytes = Encoding.UTF8.GetBytes(testSD); + theSD = OSDParser.DeserializeLLSDXml(bytes); + + Assert.IsTrue(theSD != null); + } + + /// + /// Test that various URI representations are parsed correctly. + /// + [Test] + public void DeserializeURI() + { + OSD theSD = null; + OSDArray array = null; + OSDUri tempURI = null; + + String testSD = @" + + + http://sim956.agni.lindenlab.com:12035/runtime/agents + + + "; + //Deserialize the string + byte[] bytes = Encoding.UTF8.GetBytes(testSD); + theSD = OSDParser.DeserializeLLSDXml(bytes); + + Assert.IsTrue(theSD is OSDArray); + array = (OSDArray)theSD; + + Assert.AreEqual(OSDType.URI, array[0].Type); + tempURI = (OSDUri)array[0]; + Uri testURI = new Uri(@"http://sim956.agni.lindenlab.com:12035/runtime/agents"); + Assert.AreEqual(testURI, tempURI.AsUri()); + + Assert.AreEqual(OSDType.URI, array[1].Type); + tempURI = (OSDUri)array[1]; + Assert.AreEqual("", tempURI.AsUri().ToString()); + } + + /// + /// Test some nested containers. This is not a very deep or complicated SD graph + /// but it should reveal basic nesting issues. + /// + [Test] + public void DeserializeNestedContainers() + { + OSD theSD = null; + OSDArray array = null; + OSDMap map = null; + OSD tempSD = null; + + String testSD = @" + + + + Map One + + Array One + + 1 + 2 + + + + + A + B + + 1 + 4 + 9 + + + + "; + //Deserialize the string + byte[] bytes = Encoding.UTF8.GetBytes(testSD); + theSD = OSDParser.DeserializeLLSDXml(bytes); + + Assert.IsTrue(theSD is OSDArray); + array = (OSDArray)theSD; + Assert.AreEqual(2, array.Count); + + //The first element of top level array, a map + Assert.AreEqual(OSDType.Map, array[0].Type); + map = (OSDMap)array[0]; + //First nested map + tempSD = map["Map One"]; + Assert.IsNotNull(tempSD); + Assert.AreEqual(OSDType.Map, tempSD.Type); + map = (OSDMap)tempSD; + //First nested array + tempSD = map["Array One"]; + Assert.IsNotNull(tempSD); + Assert.AreEqual(OSDType.Array, tempSD.Type); + array = (OSDArray)tempSD; + Assert.AreEqual(2, array.Count); + + array = (OSDArray)theSD; + //Second element of top level array, an array + tempSD = array[1]; + Assert.AreEqual(OSDType.Array, tempSD.Type); + array = (OSDArray)tempSD; + Assert.AreEqual(3, array.Count); + //Nested array + tempSD = array[2]; + Assert.AreEqual(OSDType.Array, tempSD.Type); + array = (OSDArray)tempSD; + Assert.AreEqual(3, array.Count); + } + } + + internal static class TestHelper + { + /// + /// Asserts that the contents of the SDBinary match the values and length + /// of the supplied byte array + /// + /// + /// + internal static void TestBinary(OSDBinary inBinary, byte[] inExpected) + { + byte[] binary = inBinary.AsBinary(); + Assert.AreEqual(inExpected.Length, binary.Length); + for (int i = 0; i < inExpected.Length; i++) + { + if (inExpected[i] != binary[i]) + { + Assert.Fail("Expected " + inExpected[i].ToString() + " at position " + i.ToString() + + " but saw " + binary[i].ToString()); + } + } + } + } +} diff --git a/Assets/Tests/XmlLLSDTests.cs.meta b/Assets/Tests/XmlLLSDTests.cs.meta new file mode 100644 index 0000000..e3585f7 --- /dev/null +++ b/Assets/Tests/XmlLLSDTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2966952cbe165bb44816526cae987cf1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Unity/RaindropViewManager.cs b/Assets/Unity/RaindropViewManager.cs index 6c707a7..5ca122b 100644 --- a/Assets/Unity/RaindropViewManager.cs +++ b/Assets/Unity/RaindropViewManager.cs @@ -20,7 +20,7 @@ namespace Raindrop //manages all child Viewmodels public RaindropViewManager() { - Debug.Log("VM manager setup ok"); + //Debug.Log("VM manager setup ok"); //subscribe all events from raindropclient Global.MainRaindropInstance.LoginCompleted += MainRaindropInstance_LoginCompleted; @@ -42,7 +42,7 @@ namespace Raindrop private void MainRaindropInstance_LoginFailed() { - showFailedLoginModal(); + Debug.Log("failed login TODO: why?"); } private void showFailedLoginModal() @@ -53,7 +53,8 @@ namespace Raindrop private void MainRaindropInstance_LoginCompleted() { cm.popCanvas(); - showSuccessLoginModal(); + cm.pushCanvas(CanvasType.Game); + //showSuccessLoginModal(); } private void removeLoginView() diff --git a/Assets/Unity/UI/CanvasManager.cs b/Assets/Unity/UI/CanvasManager.cs index b5c7ac6..848362d 100644 --- a/Assets/Unity/UI/CanvasManager.cs +++ b/Assets/Unity/UI/CanvasManager.cs @@ -45,6 +45,7 @@ public class CanvasManager : Singleton { if (activeCanvasStack.Count() == 0) { + Debug.LogWarning("tried to pop empty canvas stack."); return; } @@ -52,6 +53,7 @@ public class CanvasManager : Singleton if (lastActiveCanvas != null) { lastActiveCanvas.gameObject.SetActive(false); + activeCanvasStack.Pop(); }