mirror of
https://github.com/RaindropViewer/RaindropViewer.git
synced 2026-07-27 22:11:39 +00:00
added original LMV tests
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5517ceddb63c378498db7ef3905c90f3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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:
|
||||
|
||||
@@ -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("<?llsd/binary?>\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 = "<x>ƖȔȠȨɆɒ</x>";
|
||||
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 = "<x>𐄷</x>";
|
||||
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 = "<x>𐄷</x>";
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f42872409e992134cab2a63f1f023d77
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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<EventQueueRunningEventArgs> 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dde2dfcd7dfdc9447aca63af64be81c8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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 = "<x>𐄷</x>";
|
||||
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 = "<x>𐄷</x>";
|
||||
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.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 39041f92f42f0ae4ba5d13b5e7c5a56c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b96829043dde76b4fba18c205d2ac390
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 91415889acfec554da86a1e988370310
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<string, double> testNumbers;
|
||||
testNumbers = new Dictionary<string, double>();
|
||||
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<string, double> 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<OSDArray>(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<OSDArray>(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<OSDArray>(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<OSDMap>(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<OSDArray>(hashtable["region_handle"]);
|
||||
Assert.IsTrue(((OSDArray)hashtable["region_handle"]).Count == 2);
|
||||
Assert.IsInstanceOf<OSDArray>(hashtable["position"]);
|
||||
Assert.IsTrue(((OSDArray)hashtable["position"]).Count == 3);
|
||||
Assert.IsInstanceOf<OSDArray>(hashtable["look_at"]);
|
||||
Assert.IsTrue(((OSDArray)hashtable["look_at"]).Count == 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bcce836b577a95548976d7b43a93e604
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// XmlSDTests is a suite of tests for libsl implementation of the SD XML format.
|
||||
///
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public class XmlSDTests
|
||||
{
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void DeserializeLLSDSample()
|
||||
{
|
||||
OSD theSD = null;
|
||||
OSDMap map = null;
|
||||
OSD tempSD = null;
|
||||
OSDUUID tempUUID = null;
|
||||
OSDString tempStr = null;
|
||||
OSDReal tempReal = null;
|
||||
|
||||
String testSD = @"<?xml version='1.0' encoding='UTF-8'?>
|
||||
<llsd>
|
||||
<map>
|
||||
<key>region_id</key>
|
||||
<uuid>67153d5b-3659-afb4-8510-adda2c034649</uuid>
|
||||
<key>scale</key>
|
||||
<string>one minute</string>
|
||||
<key>simulator statistics</key>
|
||||
<map>
|
||||
<key>time dilation</key>
|
||||
<real>0.9878624</real>
|
||||
<key>sim fps</key>
|
||||
<real>44.38898</real>
|
||||
<key>agent updates per second</key>
|
||||
<real>nan</real>
|
||||
<key>total task count</key>
|
||||
<real>4</real>
|
||||
<key>active task count</key>
|
||||
<real>0</real>
|
||||
<key>pending uploads</key>
|
||||
<real>0.0001096525</real>
|
||||
</map>
|
||||
</map>
|
||||
</llsd>";
|
||||
|
||||
//Deserialize the string
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(testSD);
|
||||
theSD = OSDParser.DeserializeLLSDXml(bytes);
|
||||
|
||||
//Confirm the contents
|
||||
Assert.IsNotNull(theSD);
|
||||
Assert.IsTrue(theSD is OSDMap);
|
||||
Assert.IsTrue(theSD.Type == OSDType.Map);
|
||||
map = (OSDMap)theSD;
|
||||
|
||||
tempSD = map["region_id"];
|
||||
Assert.IsNotNull(tempSD);
|
||||
Assert.IsTrue(tempSD is OSDUUID);
|
||||
Assert.IsTrue(tempSD.Type == OSDType.UUID);
|
||||
tempUUID = (OSDUUID)tempSD;
|
||||
Assert.AreEqual(new UUID("67153d5b-3659-afb4-8510-adda2c034649"), tempUUID.AsUUID());
|
||||
|
||||
tempSD = map["scale"];
|
||||
Assert.IsNotNull(tempSD);
|
||||
Assert.IsTrue(tempSD is OSDString);
|
||||
Assert.IsTrue(tempSD.Type == OSDType.String);
|
||||
tempStr = (OSDString)tempSD;
|
||||
Assert.AreEqual("one minute", tempStr.AsString());
|
||||
|
||||
tempSD = map["simulator statistics"];
|
||||
Assert.IsNotNull(tempSD);
|
||||
Assert.IsTrue(tempSD is OSDMap);
|
||||
Assert.IsTrue(tempSD.Type == OSDType.Map);
|
||||
map = (OSDMap)tempSD;
|
||||
|
||||
tempSD = map["time dilation"];
|
||||
Assert.IsNotNull(tempSD);
|
||||
Assert.IsTrue(tempSD is OSDReal);
|
||||
Assert.IsTrue(tempSD.Type == OSDType.Real);
|
||||
tempReal = (OSDReal)tempSD;
|
||||
|
||||
Assert.AreEqual(0.9878624d, tempReal.AsReal());
|
||||
//TODO - figure out any relevant rounding variability for 64 bit reals
|
||||
tempSD = map["sim fps"];
|
||||
Assert.IsNotNull(tempSD);
|
||||
Assert.IsTrue(tempSD is OSDReal);
|
||||
Assert.IsTrue(tempSD.Type == OSDType.Real);
|
||||
tempReal = (OSDReal)tempSD;
|
||||
Assert.AreEqual(44.38898d, tempReal.AsReal());
|
||||
|
||||
tempSD = map["agent updates per second"];
|
||||
Assert.IsNotNull(tempSD);
|
||||
Assert.IsTrue(tempSD is OSDReal);
|
||||
Assert.IsTrue(tempSD.Type == OSDType.Real);
|
||||
tempReal = (OSDReal)tempSD;
|
||||
Assert.AreEqual(Double.NaN, tempSD.AsReal());
|
||||
|
||||
tempSD = map["total task count"];
|
||||
Assert.IsNotNull(tempSD);
|
||||
Assert.IsTrue(tempSD is OSDReal);
|
||||
Assert.IsTrue(tempSD.Type == OSDType.Real);
|
||||
tempReal = (OSDReal)tempSD;
|
||||
Assert.AreEqual(4.0d, tempReal.AsReal());
|
||||
|
||||
tempSD = map["active task count"];
|
||||
Assert.IsNotNull(tempSD);
|
||||
Assert.IsTrue(tempSD is OSDReal);
|
||||
Assert.IsTrue(tempSD.Type == OSDType.Real);
|
||||
tempReal = (OSDReal)tempSD;
|
||||
Assert.AreEqual(0.0d, tempReal.AsReal());
|
||||
|
||||
tempSD = map["pending uploads"];
|
||||
Assert.IsNotNull(tempSD);
|
||||
Assert.IsTrue(tempSD is OSDReal);
|
||||
Assert.IsTrue(tempSD.Type == OSDType.Real);
|
||||
tempReal = (OSDReal)tempSD;
|
||||
Assert.AreEqual(0.0001096525d, tempReal.AsReal());
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test that various Real representations are parsed correctly.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void DeserializeReals()
|
||||
{
|
||||
OSD theSD = null;
|
||||
OSDArray array = null;
|
||||
OSDReal tempReal = null;
|
||||
|
||||
String testSD = @"<?xml version='1.0' encoding='UTF-8'?>
|
||||
<llsd>
|
||||
<array>
|
||||
<real>44.38898</real>
|
||||
<real>nan</real>
|
||||
<real>4</real>
|
||||
<real>-13.333</real>
|
||||
<real/>
|
||||
</array>
|
||||
</llsd>";
|
||||
//Deserialize the string
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(testSD);
|
||||
theSD = OSDParser.DeserializeLLSDXml(bytes);
|
||||
|
||||
Assert.IsTrue(theSD is OSDArray);
|
||||
array = (OSDArray)theSD;
|
||||
|
||||
Assert.AreEqual(OSDType.Real, array[0].Type);
|
||||
tempReal = (OSDReal)array[0];
|
||||
Assert.AreEqual(44.38898d, tempReal.AsReal());
|
||||
|
||||
Assert.AreEqual(OSDType.Real, array[1].Type);
|
||||
tempReal = (OSDReal)array[1];
|
||||
Assert.AreEqual(Double.NaN, tempReal.AsReal());
|
||||
|
||||
Assert.AreEqual(OSDType.Real, array[2].Type);
|
||||
tempReal = (OSDReal)array[2];
|
||||
Assert.AreEqual(4.0d, tempReal.AsReal());
|
||||
|
||||
Assert.AreEqual(OSDType.Real, array[3].Type);
|
||||
tempReal = (OSDReal)array[3];
|
||||
Assert.AreEqual(-13.333d, tempReal.AsReal());
|
||||
|
||||
Assert.AreEqual(OSDType.Real, array[4].Type);
|
||||
tempReal = (OSDReal)array[4];
|
||||
Assert.AreEqual(0d, tempReal.AsReal());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test that various String representations are parsed correctly.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void DeserializeStrings()
|
||||
{
|
||||
OSD theSD = null;
|
||||
OSDArray array = null;
|
||||
OSDString tempStr = null;
|
||||
|
||||
String testSD = @"<?xml version='1.0' encoding='UTF-8'?>
|
||||
<llsd>
|
||||
<array>
|
||||
<string>Kissling</string>
|
||||
<string>Attack ships on fire off the shoulder of Orion</string>
|
||||
<string>< > & ' "</string>
|
||||
<string/>
|
||||
</array>
|
||||
</llsd>";
|
||||
//Deserialize the string
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(testSD);
|
||||
theSD = OSDParser.DeserializeLLSDXml(bytes);
|
||||
|
||||
Assert.IsTrue(theSD is OSDArray);
|
||||
array = (OSDArray)theSD;
|
||||
|
||||
Assert.AreEqual(OSDType.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());
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void DeserializeIntegers()
|
||||
{
|
||||
OSD theSD = null;
|
||||
OSDArray array = null;
|
||||
OSDInteger tempInt = null;
|
||||
|
||||
String testSD = @"<?xml version='1.0' encoding='UTF-8'?>
|
||||
<llsd>
|
||||
<array>
|
||||
<integer>2147483647</integer>
|
||||
<integer>-2147483648</integer>
|
||||
<integer>0</integer>
|
||||
<integer>013</integer>
|
||||
<integer/>
|
||||
</array>
|
||||
</llsd>";
|
||||
//Deserialize the string
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(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());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test that various UUID representations are parsed correctly.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void DeserializeUUID()
|
||||
{
|
||||
OSD theSD = null;
|
||||
OSDArray array = null;
|
||||
OSDUUID tempUUID = null;
|
||||
|
||||
String testSD = @"<?xml version='1.0' encoding='UTF-8'?>
|
||||
<llsd>
|
||||
<array>
|
||||
<uuid>d7f4aeca-88f1-42a1-b385-b9db18abb255</uuid>
|
||||
<uuid/>
|
||||
</array>
|
||||
</llsd>";
|
||||
//Deserialize the string
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(testSD);
|
||||
theSD = OSDParser.DeserializeLLSDXml(bytes);
|
||||
|
||||
Assert.IsTrue(theSD is OSDArray);
|
||||
array = (OSDArray)theSD;
|
||||
|
||||
Assert.AreEqual(OSDType.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());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test that various date representations are parsed correctly.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void DeserializeDates()
|
||||
{
|
||||
OSD theSD = null;
|
||||
OSDArray array = null;
|
||||
OSDDate tempDate = null;
|
||||
DateTime testDate;
|
||||
|
||||
String testSD = @"<?xml version='1.0' encoding='UTF-8'?>
|
||||
<llsd>
|
||||
<array>
|
||||
<date>2006-02-01T14:29:53Z</date>
|
||||
<date>1999-01-01T00:00:00Z</date>
|
||||
<date/>
|
||||
</array>
|
||||
</llsd>";
|
||||
//Deserialize the string
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(testSD);
|
||||
theSD = OSDParser.DeserializeLLSDXml(bytes);
|
||||
|
||||
Assert.IsTrue(theSD is OSDArray);
|
||||
array = (OSDArray)theSD;
|
||||
|
||||
Assert.AreEqual(OSDType.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());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test that various Boolean representations are parsed correctly.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void DeserializeBoolean()
|
||||
{
|
||||
OSD theSD = null;
|
||||
OSDArray array = null;
|
||||
OSDBoolean tempBool = null;
|
||||
|
||||
String testSD = @"<?xml version='1.0' encoding='UTF-8'?>
|
||||
<llsd>
|
||||
<array>
|
||||
<boolean>1</boolean>
|
||||
<boolean>true</boolean>
|
||||
<boolean>0</boolean>
|
||||
<boolean>false</boolean>
|
||||
<boolean/>
|
||||
</array>
|
||||
</llsd>";
|
||||
//Deserialize the string
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(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());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test that binary elements are parsed correctly.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void DeserializeBinary()
|
||||
{
|
||||
OSD theSD = null;
|
||||
OSDArray array = null;
|
||||
OSDBinary tempBinary = null;
|
||||
|
||||
String testSD = @"<?xml version='1.0' encoding='UTF-8'?>
|
||||
<llsd>
|
||||
<array>
|
||||
<binary encoding='base64'>cmFuZG9t</binary>
|
||||
<binary>dGhlIHF1aWNrIGJyb3duIGZveA==</binary>
|
||||
<binary/>
|
||||
</array>
|
||||
</llsd>";
|
||||
|
||||
//Deserialize the string
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(testSD);
|
||||
theSD = OSDParser.DeserializeLLSDXml(bytes);
|
||||
|
||||
Assert.IsTrue(theSD is OSDArray);
|
||||
array = (OSDArray)theSD;
|
||||
|
||||
Assert.AreEqual(OSDType.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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void DeserializeUndef()
|
||||
{
|
||||
OSD theSD = null;
|
||||
|
||||
String testSD = @"<?xml version='1.0' encoding='UTF-8'?>
|
||||
<llsd>
|
||||
<undef/>
|
||||
</llsd>";
|
||||
//Deserialize the string
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(testSD);
|
||||
theSD = OSDParser.DeserializeLLSDXml(bytes);
|
||||
|
||||
Assert.IsTrue(theSD != null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test that various URI representations are parsed correctly.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void DeserializeURI()
|
||||
{
|
||||
OSD theSD = null;
|
||||
OSDArray array = null;
|
||||
OSDUri tempURI = null;
|
||||
|
||||
String testSD = @"<?xml version='1.0' encoding='UTF-8'?>
|
||||
<llsd>
|
||||
<array>
|
||||
<uri>http://sim956.agni.lindenlab.com:12035/runtime/agents</uri>
|
||||
<uri/>
|
||||
</array>
|
||||
</llsd>";
|
||||
//Deserialize the string
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(testSD);
|
||||
theSD = OSDParser.DeserializeLLSDXml(bytes);
|
||||
|
||||
Assert.IsTrue(theSD is OSDArray);
|
||||
array = (OSDArray)theSD;
|
||||
|
||||
Assert.AreEqual(OSDType.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());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test some nested containers. This is not a very deep or complicated SD graph
|
||||
/// but it should reveal basic nesting issues.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void DeserializeNestedContainers()
|
||||
{
|
||||
OSD theSD = null;
|
||||
OSDArray array = null;
|
||||
OSDMap map = null;
|
||||
OSD tempSD = null;
|
||||
|
||||
String testSD = @"<?xml version='1.0' encoding='UTF-8'?>
|
||||
<llsd>
|
||||
<array>
|
||||
<map>
|
||||
<key>Map One</key>
|
||||
<map>
|
||||
<key>Array One</key>
|
||||
<array>
|
||||
<integer>1</integer>
|
||||
<integer>2</integer>
|
||||
</array>
|
||||
</map>
|
||||
</map>
|
||||
<array>
|
||||
<string>A</string>
|
||||
<string>B</string>
|
||||
<array>
|
||||
<integer>1</integer>
|
||||
<integer>4</integer>
|
||||
<integer>9</integer>
|
||||
</array>
|
||||
</array>
|
||||
</array>
|
||||
</llsd>";
|
||||
//Deserialize the string
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(testSD);
|
||||
theSD = OSDParser.DeserializeLLSDXml(bytes);
|
||||
|
||||
Assert.IsTrue(theSD is OSDArray);
|
||||
array = (OSDArray)theSD;
|
||||
Assert.AreEqual(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
|
||||
{
|
||||
/// <summary>
|
||||
/// Asserts that the contents of the SDBinary match the values and length
|
||||
/// of the supplied byte array
|
||||
/// </summary>
|
||||
/// <param name="inBinary"></param>
|
||||
/// <param name="inExpected"></param>
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2966952cbe165bb44816526cae987cf1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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()
|
||||
|
||||
@@ -45,6 +45,7 @@ public class CanvasManager : Singleton<CanvasManager>
|
||||
{
|
||||
if (activeCanvasStack.Count() == 0)
|
||||
{
|
||||
Debug.LogWarning("tried to pop empty canvas stack.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -52,6 +53,7 @@ public class CanvasManager : Singleton<CanvasManager>
|
||||
if (lastActiveCanvas != null)
|
||||
{
|
||||
lastActiveCanvas.gameObject.SetActive(false);
|
||||
activeCanvasStack.Pop();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user