From 305c3e668a36f8a53582d57a0eee79084c62a280 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Fri, 29 Aug 2014 18:06:29 +0100 Subject: [PATCH] Add regression test for deserializing xml objects with more than one non-root part. --- .../World/Serialiser/Tests/SerialiserTests.cs | 531 +++++++++++++----- 1 file changed, 405 insertions(+), 126 deletions(-) diff --git a/OpenSim/Region/CoreModules/World/Serialiser/Tests/SerialiserTests.cs b/OpenSim/Region/CoreModules/World/Serialiser/Tests/SerialiserTests.cs index 66059fb8bb..52203f76cc 100644 --- a/OpenSim/Region/CoreModules/World/Serialiser/Tests/SerialiserTests.cs +++ b/OpenSim/Region/CoreModules/World/Serialiser/Tests/SerialiserTests.cs @@ -27,6 +27,7 @@ using System.Collections.Generic; using System.IO; +using System.Text; using System.Xml; using log4net.Config; using NUnit.Framework; @@ -42,128 +43,351 @@ namespace OpenSim.Region.CoreModules.World.Serialiser.Tests [TestFixture] public class SerialiserTests : OpenSimTestCase { - private string xml = @" - - - - false - a6dacf01-4636-4bb9-8a97-30609438af9d - e6a5a05e-e8cc-4816-8701-04165e335790 - 1 - - 0 - e6a5a05e-e8cc-4816-8701-04165e335790 - 2698615125 - PrimMyRide - 0 - false - 1099511628032000 - 0 - 147.2392.69822.78084 - 000 - -4.371139E-08-1-4.371139E-080 - 000 - 000 - 000 - 000 - - - - - - 0 - 0 - - 1 - AAAAAAAAERGZmQAAAAAABQCVlZUAAAAAQEAAAABAQAAAAAAAAAAAAAAAAAAAAA== - AA== - 0 - 16 - 0 - 0 - 0 - 100 - 100 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 9 - 0 - 0 - 0 - 10100.5 - 0 - Square - Same - 00000000-0000-0000-0000-000000000000 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 1 - 0 - 0 - 0 - 1 - false - false - false - - 10100.5 - 0 - 0001 - 000 - 000 - 0001 - 0 - 1211330445 - 0 - 0 - 0 - 0 - 00000000-0000-0000-0000-000000000000 - a6dacf01-4636-4bb9-8a97-30609438af9d - a6dacf01-4636-4bb9-8a97-30609438af9d - 2147483647 - 2147483647 - 0 - 0 - 2147483647 - None - 00000000-0000-0000-0000-000000000000 - 0 - - - - MyNamespace - - MyStore - - the answer - 42 - - + private const string ObjectRootPartStubXml = +@" + + + false + a6dacf01-4636-4bb9-8a97-30609438af9d + e6a5a05e-e8cc-4816-8701-04165e335790 + 1 + + 0 + e6a5a05e-e8cc-4816-8701-04165e335790 + 2698615125 + PrimMyRide + 0 + false + 1099511628032000 + 0 + 147.2392.69822.78084 + 000 + -4.371139E-08-1-4.371139E-080 + 000 + 000 + 000 + 000 + + + + + + 0 + 0 + + 1 + AAAAAAAAERGZmQAAAAAABQCVlZUAAAAAQEAAAABAQAAAAAAAAAAAAAAAAAAAAA== + AA== + 0 + 16 + 0 + 0 + 0 + 100 + 100 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 9 + 0 + 0 + 0 + 10100.5 + 0 + Square + Same + 00000000-0000-0000-0000-000000000000 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 1 + false + false + false + + 10100.5 + 0 + 0001 + 000 + 000 + 0001 + 0 + 1211330445 + 0 + 0 + 0 + 0 + 00000000-0000-0000-0000-000000000000 + a6dacf01-4636-4bb9-8a97-30609438af9d + a6dacf01-4636-4bb9-8a97-30609438af9d + 2147483647 + 2147483647 + 0 + 0 + 2147483647 + None + 00000000-0000-0000-0000-000000000000 + 0 + + + + MyNamespace + + MyStore + + the answer + 42 - - - - - - "; + + + + + + "; - private string badFloatsXml = @" + private const string ObjectWithNoOtherPartsXml = ObjectRootPartStubXml + +@" + +"; + + private const string ObjectWithOtherPartsXml = ObjectRootPartStubXml + +@" + + + + false + a6dacf01-4636-4bb9-8a97-30609438af9d + 9958feb1-02a6-49e4-a4ce-eba6f578ee13 + 3 + 9958feb1-02a6-49e4-a4ce-eba6f578ee13 + 1154704500 + Alien Head 1 + 3 + false + false + 21990232560640000 + 0 + 125.5655127.34622.48036 + -0.21719360.10839840.0009994507 + -0.51221060.4851225-0.49574540.5064908 + 000 + 000 + 000 + (No Description) + 000255 + + + + 253 + 0 + + 5 + Vw3dpvgTRUOiIUOGsnpWlAB/f38AAAAAgL8AAACAPwAAAAAAAAAF4ABAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AA== + 0 + 32 + 0 + 0 + 0 + 100 + 100 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 9 + 0 + 0 + 0 + 9 + 0 + HalfCircle + Same + 00000000-0000-0000-0000-000000000000 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 1 + false + false + false + + 0.11481950.01438910.02768878 + 0001 + 000 + 000 + 0001 + 1154704499 + 1256611042 + 0 + 10 + 0 + 0 + 00000000-0000-0000-0000-000000000000 + 7b2022f0-5f19-488c-b7e5-829d8f96b448 + 7b2022f0-5f19-488c-b7e5-829d8f96b448 + 647168 + 647168 + 0 + 0 + 581632 + None + 00000000-0000-0000-0000-000000000000 + 0 + 000 + + + -2 + -2 + -2 + -2 + -2 + + + + + false + a6dacf01-4636-4bb9-8a97-30609438af9d + 674b6b86-f5aa-439a-8e00-0d75bc08c80a + 3 + 674b6b86-f5aa-439a-8e00-0d75bc08c80a + 1154704501 + Alien Head 2 + 3 + false + false + 21990232560640000 + 0 + 125.5655127.34622.48036 + -0.24909970.085201260.0009002686 + -0.47653680.5194498-0.53013720.4712104 + 000 + 000 + 000 + (No Description) + 000255 + + + + 252 + 0 + + 0 + Vw3dpvgTRUOiIUOGsnpWlAB/f38AAAAAgL8AAACAPwAAAAAAAAAF4ABAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AA== + 0 + 32 + 0 + 0 + 0 + 100 + 150 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 9 + 0 + 0 + 0 + 9 + 0 + Circle + Same + 00000000-0000-0000-0000-000000000000 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 1 + false + false + false + + 0.035743850.059580320.04764182 + 0001 + 000 + 000 + 0001 + 1154704499 + 1256611042 + 0 + 10 + 0 + 0 + 00000000-0000-0000-0000-000000000000 + 7b2022f0-5f19-488c-b7e5-829d8f96b448 + 7b2022f0-5f19-488c-b7e5-829d8f96b448 + 647168 + 647168 + 0 + 0 + 581632 + None + 00000000-0000-0000-0000-000000000000 + 0 + 000 + + + -2 + -2 + -2 + -2 + -2 + + + +"; + + private const string ObjectWithBadFloatsXml = @" @@ -270,7 +494,7 @@ namespace OpenSim.Region.CoreModules.World.Serialiser.Tests "; - private string xml2 = @" + private const string ObjectWithNoPartsXml2 = @" b46ef588-411e-4a8b-a284-d7dcfe8e74ef @@ -377,12 +601,12 @@ namespace OpenSim.Region.CoreModules.World.Serialiser.Tests } [Test] - public void TestDeserializeXml() + public void TestDeserializeXmlObjectWithNoOtherParts() { TestHelpers.InMethod(); - //log4net.Config.XmlConfigurator.Configure(); + TestHelpers.EnableLogging(); - SceneObjectGroup so = SceneObjectSerializer.FromOriginalXmlFormat(xml); + SceneObjectGroup so = SceneObjectSerializer.FromOriginalXmlFormat(ObjectWithNoOtherPartsXml); SceneObjectPart rootPart = so.RootPart; Assert.That(rootPart.UUID, Is.EqualTo(new UUID("e6a5a05e-e8cc-4816-8701-04165e335790"))); @@ -394,13 +618,68 @@ namespace OpenSim.Region.CoreModules.World.Serialiser.Tests // TODO: Check other properties } + [Test] + public void TestDeserializeXmlObjectWithOtherParts() + { + TestHelpers.InMethod(); + TestHelpers.EnableLogging(); + + // We need to do this to get rid of whitespace between elements. + // TODO: Ultimately OpenSimulator xml parser should be set to ignore this but this means a bit of + // rejigging to replace old new XmlTextReader() with the post .NET 2.0 XmlReader.Create() calls + XmlDocument xdoc = new XmlDocument(); + xdoc.LoadXml(ObjectWithOtherPartsXml); + + StringBuilder sb = new StringBuilder(); + using (StringWriter sw = new StringWriter(sb)) + { + using (XmlTextWriter xtw = new XmlTextWriter(sw)) + { + xtw.Formatting = Formatting.Indented; + xdoc.WriteTo(xtw); + } + } + + SceneObjectGroup so = SceneObjectSerializer.FromOriginalXmlFormat(sb.ToString()); + SceneObjectPart[] parts = so.Parts; + Assert.AreEqual(3, so.Parts.Length); + + { + SceneObjectPart part = parts[0]; + + Assert.That(part.UUID, Is.EqualTo(new UUID("e6a5a05e-e8cc-4816-8701-04165e335790"))); + Assert.That(part.CreatorID, Is.EqualTo(new UUID("a6dacf01-4636-4bb9-8a97-30609438af9d"))); + Assert.That(part.Name, Is.EqualTo("PrimMyRide")); + OSDMap store = part.DynAttrs.GetStore("MyNamespace", "MyStore"); + Assert.AreEqual(42, store["the answer"].AsInteger()); + } + + { + SceneObjectPart part = parts[1]; + + Assert.That(part.UUID, Is.EqualTo(new UUID("9958feb1-02a6-49e4-a4ce-eba6f578ee13"))); + Assert.That(part.CreatorID, Is.EqualTo(new UUID("a6dacf01-4636-4bb9-8a97-30609438af9d"))); + Assert.That(part.Name, Is.EqualTo("Alien Head 1")); + } + + { + SceneObjectPart part = parts[2]; + + Assert.That(part.UUID, Is.EqualTo(new UUID("674b6b86-f5aa-439a-8e00-0d75bc08c80a"))); + Assert.That(part.CreatorID, Is.EqualTo(new UUID("a6dacf01-4636-4bb9-8a97-30609438af9d"))); + Assert.That(part.Name, Is.EqualTo("Alien Head 2")); + } + + // TODO: Check other properties + } + [Test] public void TestDeserializeBadFloatsXml() { TestHelpers.InMethod(); // log4net.Config.XmlConfigurator.Configure(); - SceneObjectGroup so = SceneObjectSerializer.FromOriginalXmlFormat(badFloatsXml); + SceneObjectGroup so = SceneObjectSerializer.FromOriginalXmlFormat(ObjectWithBadFloatsXml); SceneObjectPart rootPart = so.RootPart; Assert.That(rootPart.UUID, Is.EqualTo(new UUID("e6a5a05e-e8cc-4816-8701-04165e335790"))); @@ -517,7 +796,7 @@ namespace OpenSim.Region.CoreModules.World.Serialiser.Tests TestHelpers.InMethod(); //log4net.Config.XmlConfigurator.Configure(); - SceneObjectGroup so = m_serialiserModule.DeserializeGroupFromXml2(xml2); + SceneObjectGroup so = m_serialiserModule.DeserializeGroupFromXml2(ObjectWithNoPartsXml2); SceneObjectPart rootPart = so.RootPart; Assert.That(rootPart.UUID, Is.EqualTo(new UUID("9be68fdd-f740-4a0f-9675-dfbbb536b946")));