diff options
author | Diva Canto | 2015-05-05 20:59:09 -0700 |
---|---|---|
committer | Diva Canto | 2015-05-05 20:59:09 -0700 |
commit | 1abbad71b4603245e5481c11e3ce55f57b64935f (patch) | |
tree | 694b750495216edbb16a2822a546e7617eff2c66 /OpenSim/Region/Framework/Scenes/Tests/SceneObjectSerializationTests.cs | |
parent | Revert "Patch llCastRay fully-simplified to V2." for further review. (diff) | |
download | opensim-SC_OLD-1abbad71b4603245e5481c11e3ce55f57b64935f.zip opensim-SC_OLD-1abbad71b4603245e5481c11e3ce55f57b64935f.tar.gz opensim-SC_OLD-1abbad71b4603245e5481c11e3ce55f57b64935f.tar.bz2 opensim-SC_OLD-1abbad71b4603245e5481c11e3ce55f57b64935f.tar.xz |
Refactored some code that is used in two different dlls related to SOP rewriting. Also added some unit tests that relate to mantis #7514
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Tests/SceneObjectSerializationTests.cs | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSerializationTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSerializationTests.cs new file mode 100644 index 0000000..927d8e8 --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Tests/SceneObjectSerializationTests.cs | |||
@@ -0,0 +1,136 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Threading; | ||
32 | using System.Xml; | ||
33 | using System.Linq; | ||
34 | using Nini.Config; | ||
35 | using NUnit.Framework; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Serialization.External; | ||
39 | using OpenSim.Framework.Communications; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | using OpenSim.Region.Framework.Scenes.Serialization; | ||
42 | using OpenSim.Services.Interfaces; | ||
43 | using OpenSim.Tests.Common; | ||
44 | |||
45 | namespace OpenSim.Region.Framework.Scenes.Tests | ||
46 | { | ||
47 | /// <summary> | ||
48 | /// Basic scene object serialization tests. | ||
49 | /// </summary> | ||
50 | [TestFixture] | ||
51 | public class SceneObjectSerializationTests : OpenSimTestCase | ||
52 | { | ||
53 | |||
54 | /// <summary> | ||
55 | /// Serialize and deserialize. | ||
56 | /// </summary> | ||
57 | [Test] | ||
58 | public void TestSerialDeserial() | ||
59 | { | ||
60 | TestHelpers.InMethod(); | ||
61 | |||
62 | Scene scene = new SceneHelpers().SetupScene(); | ||
63 | int partsToTestCount = 3; | ||
64 | |||
65 | SceneObjectGroup so | ||
66 | = SceneHelpers.CreateSceneObject(partsToTestCount, TestHelpers.ParseTail(0x1), "obj1", 0x10); | ||
67 | SceneObjectPart[] parts = so.Parts; | ||
68 | so.Name = "obj1"; | ||
69 | so.Description = "xpto"; | ||
70 | |||
71 | string xml = SceneObjectSerializer.ToXml2Format(so); | ||
72 | Assert.That(!string.IsNullOrEmpty(xml), "SOG serialization resulted in empty or null string"); | ||
73 | |||
74 | XmlDocument doc = new XmlDocument(); | ||
75 | doc.LoadXml(xml); | ||
76 | XmlNodeList nodes = doc.GetElementsByTagName("SceneObjectPart"); | ||
77 | Assert.That(nodes.Count, Is.EqualTo(3), "SOG serialization resulted in wrong number of SOPs"); | ||
78 | |||
79 | SceneObjectGroup so2 = SceneObjectSerializer.FromXml2Format(xml); | ||
80 | Assert.IsNotNull(so2, "SOG deserialization resulted in null object"); | ||
81 | Assert.That(so2.Name == so.Name, "Name of deserialized object does not match original name"); | ||
82 | Assert.That(so2.Description == so.Description, "Description of deserialized object does not match original name"); | ||
83 | } | ||
84 | |||
85 | /// <summary> | ||
86 | /// This checks for a bug reported in mantis #7514 | ||
87 | /// </summary> | ||
88 | [Test] | ||
89 | public void TestNamespaceAttribute() | ||
90 | { | ||
91 | TestHelpers.InMethod(); | ||
92 | |||
93 | Scene scene = new SceneHelpers().SetupScene(); | ||
94 | UserAccount account = new UserAccount(UUID.Zero, UUID.Random(), "Test", "User", string.Empty); | ||
95 | scene.UserAccountService.StoreUserAccount(account); | ||
96 | int partsToTestCount = 1; | ||
97 | |||
98 | SceneObjectGroup so | ||
99 | = SceneHelpers.CreateSceneObject(partsToTestCount, TestHelpers.ParseTail(0x1), "obj1", 0x10); | ||
100 | SceneObjectPart[] parts = so.Parts; | ||
101 | so.Name = "obj1"; | ||
102 | so.Description = "xpto"; | ||
103 | so.OwnerID = account.PrincipalID; | ||
104 | so.RootPart.CreatorID = so.OwnerID; | ||
105 | |||
106 | string xml = SceneObjectSerializer.ToXml2Format(so); | ||
107 | Assert.That(!string.IsNullOrEmpty(xml), "SOG serialization resulted in empty or null string"); | ||
108 | |||
109 | xml = ExternalRepresentationUtils.RewriteSOP(xml, "Test Scene", "http://localhost", scene.UserAccountService, UUID.Zero); | ||
110 | //Console.WriteLine(xml); | ||
111 | |||
112 | XmlDocument doc = new XmlDocument(); | ||
113 | doc.LoadXml(xml); | ||
114 | |||
115 | XmlNodeList nodes = doc.GetElementsByTagName("SceneObjectPart"); | ||
116 | Assert.That(nodes.Count, Is.GreaterThan(0), "SOG serialization resulted in no SOPs"); | ||
117 | foreach (XmlAttribute a in nodes[0].Attributes) | ||
118 | { | ||
119 | int count = a.Name.Count(c => c == ':'); | ||
120 | Assert.That(count, Is.EqualTo(1), "Cannot have multiple ':' in attribute name in SOP"); | ||
121 | } | ||
122 | nodes = doc.GetElementsByTagName("CreatorData"); | ||
123 | Assert.That(nodes.Count, Is.GreaterThan(0), "SOG serialization resulted in no CreatorData"); | ||
124 | foreach (XmlAttribute a in nodes[0].Attributes) | ||
125 | { | ||
126 | int count = a.Name.Count(c => c == ':'); | ||
127 | Assert.That(count, Is.EqualTo(1), "Cannot have multiple ':' in attribute name in CreatorData"); | ||
128 | } | ||
129 | |||
130 | SceneObjectGroup so2 = SceneObjectSerializer.FromXml2Format(xml); | ||
131 | Assert.IsNotNull(so2, "SOG deserialization resulted in null object"); | ||
132 | Assert.AreNotEqual(so.RootPart.CreatorIdentification, so2.RootPart.CreatorIdentification, "RewriteSOP failed to transform CreatorData."); | ||
133 | Assert.That(so2.RootPart.CreatorIdentification.Contains("http://"), "RewriteSOP failed to add the homeURL to CreatorData"); | ||
134 | } | ||
135 | } | ||
136 | } \ No newline at end of file | ||