OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
SceneObjectSerializationTests.cs
Go to the documentation of this file.
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.Region.Framework.Scenes;
40 using OpenSim.Region.Framework.Scenes.Serialization;
41 using OpenSim.Services.Interfaces;
42 using OpenSim.Tests.Common;
43 
44 namespace OpenSim.Region.Framework.Scenes.Tests
45 {
49  [TestFixture]
51  {
52 
56  [Test]
57  public void TestSerialDeserial()
58  {
59  TestHelpers.InMethod();
60 
61  Scene scene = new SceneHelpers().SetupScene();
62  int partsToTestCount = 3;
63 
65  = SceneHelpers.CreateSceneObject(partsToTestCount, TestHelpers.ParseTail(0x1), "obj1", 0x10);
66  SceneObjectPart[] parts = so.Parts;
67  so.Name = "obj1";
68  so.Description = "xpto";
69 
70  string xml = SceneObjectSerializer.ToXml2Format(so);
71  Assert.That(!string.IsNullOrEmpty(xml), "SOG serialization resulted in empty or null string");
72 
73  XmlDocument doc = new XmlDocument();
74  doc.LoadXml(xml);
75  XmlNodeList nodes = doc.GetElementsByTagName("SceneObjectPart");
76  Assert.That(nodes.Count, Is.EqualTo(3), "SOG serialization resulted in wrong number of SOPs");
77 
78  SceneObjectGroup so2 = SceneObjectSerializer.FromXml2Format(xml);
79  Assert.IsNotNull(so2, "SOG deserialization resulted in null object");
80  Assert.That(so2.Name == so.Name, "Name of deserialized object does not match original name");
81  Assert.That(so2.Description == so.Description, "Description of deserialized object does not match original name");
82  }
83 
87  [Test]
88  public void TestNamespaceAttribute()
89  {
90  TestHelpers.InMethod();
91 
92  Scene scene = new SceneHelpers().SetupScene();
93  UserAccount account = new UserAccount(UUID.Zero, UUID.Random(), "Test", "User", string.Empty);
94  scene.UserAccountService.StoreUserAccount(account);
95  int partsToTestCount = 1;
96 
98  = SceneHelpers.CreateSceneObject(partsToTestCount, TestHelpers.ParseTail(0x1), "obj1", 0x10);
99  SceneObjectPart[] parts = so.Parts;
100  so.Name = "obj1";
101  so.Description = "xpto";
102  so.OwnerID = account.PrincipalID;
103  so.RootPart.CreatorID = so.OwnerID;
104 
105  string xml = SceneObjectSerializer.ToXml2Format(so);
106  Assert.That(!string.IsNullOrEmpty(xml), "SOG serialization resulted in empty or null string");
107 
108  xml = ExternalRepresentationUtils.RewriteSOP(xml, "Test Scene", "http://localhost", scene.UserAccountService, UUID.Zero);
109  //Console.WriteLine(xml);
110 
111  XmlDocument doc = new XmlDocument();
112  doc.LoadXml(xml);
113 
114  XmlNodeList nodes = doc.GetElementsByTagName("SceneObjectPart");
115  Assert.That(nodes.Count, Is.GreaterThan(0), "SOG serialization resulted in no SOPs");
116  foreach (XmlAttribute a in nodes[0].Attributes)
117  {
118  int count = a.Name.Count(c => c == ':');
119  Assert.That(count, Is.EqualTo(1), "Cannot have multiple ':' in attribute name in SOP");
120  }
121  nodes = doc.GetElementsByTagName("CreatorData");
122  Assert.That(nodes.Count, Is.GreaterThan(0), "SOG serialization resulted in no CreatorData");
123  foreach (XmlAttribute a in nodes[0].Attributes)
124  {
125  int count = a.Name.Count(c => c == ':');
126  Assert.That(count, Is.EqualTo(1), "Cannot have multiple ':' in attribute name in CreatorData");
127  }
128 
129  SceneObjectGroup so2 = SceneObjectSerializer.FromXml2Format(xml);
130  Assert.IsNotNull(so2, "SOG deserialization resulted in null object");
131  Assert.AreNotEqual(so.RootPart.CreatorIdentification, so2.RootPart.CreatorIdentification, "RewriteSOP failed to transform CreatorData.");
132  Assert.That(so2.RootPart.CreatorIdentification.Contains("http://"), "RewriteSOP failed to add the homeURL to CreatorData");
133  }
134  }
135 }
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60
void TestNamespaceAttribute()
This checks for a bug reported in mantis #7514