clockwerk-opensim-stable – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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 OpenSim 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.Collections.Generic;
29 using System.IO;
30 using System.Xml;
31 using log4net.Config;
32 using NUnit.Framework;
33 using OpenMetaverse;
34 using OpenSim.Framework;
35 using OpenSim.Region.Framework.Scenes;
36 using OpenSim.Region.Framework.Scenes.Serialization;
37 using OpenSim.Tests.Common;
38 using OpenMetaverse.StructuredData;
39  
40 namespace OpenSim.Region.CoreModules.World.Serialiser.Tests
41 {
42 [TestFixture]
43 public class SerialiserTests : OpenSimTestCase
44 {
45 private string xml = @"
46 <SceneObjectGroup>
47 <RootPart>
48 <SceneObjectPart xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
49 <AllowedDrop>false</AllowedDrop>
50 <CreatorID><Guid>a6dacf01-4636-4bb9-8a97-30609438af9d</Guid></CreatorID>
51 <FolderID><Guid>e6a5a05e-e8cc-4816-8701-04165e335790</Guid></FolderID>
52 <InventorySerial>1</InventorySerial>
53 <TaskInventory />
54 <ObjectFlags>0</ObjectFlags>
55 <UUID><Guid>e6a5a05e-e8cc-4816-8701-04165e335790</Guid></UUID>
56 <LocalId>2698615125</LocalId>
57 <Name>PrimMyRide</Name>
58 <Material>0</Material>
59 <PassTouches>false</PassTouches>
60 <RegionHandle>1099511628032000</RegionHandle>
61 <ScriptAccessPin>0</ScriptAccessPin>
62 <GroupPosition><X>147.23</X><Y>92.698</Y><Z>22.78084</Z></GroupPosition>
63 <OffsetPosition><X>0</X><Y>0</Y><Z>0</Z></OffsetPosition>
64 <RotationOffset><X>-4.371139E-08</X><Y>-1</Y><Z>-4.371139E-08</Z><W>0</W></RotationOffset>
65 <Velocity><X>0</X><Y>0</Y><Z>0</Z></Velocity>
66 <RotationalVelocity><X>0</X><Y>0</Y><Z>0</Z></RotationalVelocity>
67 <AngularVelocity><X>0</X><Y>0</Y><Z>0</Z></AngularVelocity>
68 <Acceleration><X>0</X><Y>0</Y><Z>0</Z></Acceleration>
69 <Description />
70 <Color />
71 <Text />
72 <SitName />
73 <TouchName />
74 <LinkNum>0</LinkNum>
75 <ClickAction>0</ClickAction>
76 <Shape>
77 <ProfileCurve>1</ProfileCurve>
78 <TextureEntry>AAAAAAAAERGZmQAAAAAABQCVlZUAAAAAQEAAAABAQAAAAAAAAAAAAAAAAAAAAA==</TextureEntry>
79 <ExtraParams>AA==</ExtraParams>
80 <PathBegin>0</PathBegin>
81 <PathCurve>16</PathCurve>
82 <PathEnd>0</PathEnd>
83 <PathRadiusOffset>0</PathRadiusOffset>
84 <PathRevolutions>0</PathRevolutions>
85 <PathScaleX>100</PathScaleX>
86 <PathScaleY>100</PathScaleY>
87 <PathShearX>0</PathShearX>
88 <PathShearY>0</PathShearY>
89 <PathSkew>0</PathSkew>
90 <PathTaperX>0</PathTaperX>
91 <PathTaperY>0</PathTaperY>
92 <PathTwist>0</PathTwist>
93 <PathTwistBegin>0</PathTwistBegin>
94 <PCode>9</PCode>
95 <ProfileBegin>0</ProfileBegin>
96 <ProfileEnd>0</ProfileEnd>
97 <ProfileHollow>0</ProfileHollow>
98 <Scale><X>10</X><Y>10</Y><Z>0.5</Z></Scale>
99 <State>0</State>
100 <ProfileShape>Square</ProfileShape>
101 <HollowShape>Same</HollowShape>
102 <SculptTexture><Guid>00000000-0000-0000-0000-000000000000</Guid></SculptTexture>
103 <SculptType>0</SculptType><SculptData />
104 <FlexiSoftness>0</FlexiSoftness>
105 <FlexiTension>0</FlexiTension>
106 <FlexiDrag>0</FlexiDrag>
107 <FlexiGravity>0</FlexiGravity>
108 <FlexiWind>0</FlexiWind>
109 <FlexiForceX>0</FlexiForceX>
110 <FlexiForceY>0</FlexiForceY>
111 <FlexiForceZ>0</FlexiForceZ>
112 <LightColorR>0</LightColorR>
113 <LightColorG>0</LightColorG>
114 <LightColorB>0</LightColorB>
115 <LightColorA>1</LightColorA>
116 <LightRadius>0</LightRadius>
117 <LightCutoff>0</LightCutoff>
118 <LightFalloff>0</LightFalloff>
119 <LightIntensity>1</LightIntensity>
120 <FlexiEntry>false</FlexiEntry>
121 <LightEntry>false</LightEntry>
122 <SculptEntry>false</SculptEntry>
123 </Shape>
124 <Scale><X>10</X><Y>10</Y><Z>0.5</Z></Scale>
125 <UpdateFlag>0</UpdateFlag>
126 <SitTargetOrientation><X>0</X><Y>0</Y><Z>0</Z><W>1</W></SitTargetOrientation>
127 <SitTargetPosition><X>0</X><Y>0</Y><Z>0</Z></SitTargetPosition>
128 <SitTargetPositionLL><X>0</X><Y>0</Y><Z>0</Z></SitTargetPositionLL>
129 <SitTargetOrientationLL><X>0</X><Y>0</Y><Z>0</Z><W>1</W></SitTargetOrientationLL>
130 <ParentID>0</ParentID>
131 <CreationDate>1211330445</CreationDate>
132 <Category>0</Category>
133 <SalePrice>0</SalePrice>
134 <ObjectSaleType>0</ObjectSaleType>
135 <OwnershipCost>0</OwnershipCost>
136 <GroupID><Guid>00000000-0000-0000-0000-000000000000</Guid></GroupID>
137 <OwnerID><Guid>a6dacf01-4636-4bb9-8a97-30609438af9d</Guid></OwnerID>
138 <LastOwnerID><Guid>a6dacf01-4636-4bb9-8a97-30609438af9d</Guid></LastOwnerID>
139 <BaseMask>2147483647</BaseMask>
140 <OwnerMask>2147483647</OwnerMask>
141 <GroupMask>0</GroupMask>
142 <EveryoneMask>0</EveryoneMask>
143 <NextOwnerMask>2147483647</NextOwnerMask>
144 <Flags>None</Flags>
145 <CollisionSound><Guid>00000000-0000-0000-0000-000000000000</Guid></CollisionSound>
146 <CollisionSoundVolume>0</CollisionSoundVolume>
147 <DynAttrs>
148 <llsd>
149 <map>
150 <key>MyNamespace</key>
151 <map>
152 <key>MyStore</key>
153 <map>
154 <key>the answer</key>
155 <integer>42</integer>
156 </map>
157 </map>
158 </map>
159 </llsd>
160 </DynAttrs>
161 </SceneObjectPart>
162 </RootPart>
163 <OtherParts />
164 </SceneObjectGroup>";
165  
166 private string badFloatsXml = @"
167 <SceneObjectGroup>
168 <RootPart>
169 <SceneObjectPart xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
170 <AllowedDrop>false</AllowedDrop>
171 <CreatorID><Guid>a6dacf01-4636-4bb9-8a97-30609438af9d</Guid></CreatorID>
172 <FolderID><Guid>e6a5a05e-e8cc-4816-8701-04165e335790</Guid></FolderID>
173 <InventorySerial>1</InventorySerial>
174 <TaskInventory />
175 <ObjectFlags>0</ObjectFlags>
176 <UUID><Guid>e6a5a05e-e8cc-4816-8701-04165e335790</Guid></UUID>
177 <LocalId>2698615125</LocalId>
178 <Name>NaughtyPrim</Name>
179 <Material>0</Material>
180 <PassTouches>false</PassTouches>
181 <RegionHandle>1099511628032000</RegionHandle>
182 <ScriptAccessPin>0</ScriptAccessPin>
183 <GroupPosition><X>147.23</X><Y>92.698</Y><Z>22.78084</Z></GroupPosition>
184 <OffsetPosition><X>0</X><Y>0</Y><Z>0</Z></OffsetPosition>
185 <RotationOffset><X>-4.371139E-08</X><Y>-1</Y><Z>-4.371139E-08</Z><W>0</W></RotationOffset>
186 <Velocity><X>0</X><Y>0</Y><Z>0</Z></Velocity>
187 <RotationalVelocity><X>0</X><Y>0</Y><Z>0</Z></RotationalVelocity>
188 <AngularVelocity><X>0</X><Y>0</Y><Z>0</Z></AngularVelocity>
189 <Acceleration><X>0</X><Y>0</Y><Z>0</Z></Acceleration>
190 <Description />
191 <Color />
192 <Text />
193 <SitName />
194 <TouchName />
195 <LinkNum>0</LinkNum>
196 <ClickAction>0</ClickAction>
197 <Shape>
198 <ProfileCurve>1</ProfileCurve>
199 <TextureEntry>AAAAAAAAERGZmQAAAAAABQCVlZUAAAAAQEAAAABAQAAAAAAAAAAAAAAAAAAAAA==</TextureEntry>
200 <ExtraParams>AA==</ExtraParams>
201 <PathBegin>0</PathBegin>
202 <PathCurve>16</PathCurve>
203 <PathEnd>0</PathEnd>
204 <PathRadiusOffset>0</PathRadiusOffset>
205 <PathRevolutions>0</PathRevolutions>
206 <PathScaleX>100</PathScaleX>
207 <PathScaleY>100</PathScaleY>
208 <PathShearX>0</PathShearX>
209 <PathShearY>0</PathShearY>
210 <PathSkew>0</PathSkew>
211 <PathTaperX>0</PathTaperX>
212 <PathTaperY>0</PathTaperY>
213 <PathTwist>0</PathTwist>
214 <PathTwistBegin>0</PathTwistBegin>
215 <PCode>9</PCode>
216 <ProfileBegin>0</ProfileBegin>
217 <ProfileEnd>0</ProfileEnd>
218 <ProfileHollow>0</ProfileHollow>
219 <Scale><X>10</X><Y>10</Y><Z>0.5</Z></Scale>
220 <State>0</State>
221 <ProfileShape>Square</ProfileShape>
222 <HollowShape>Same</HollowShape>
223 <SculptTexture><Guid>00000000-0000-0000-0000-000000000000</Guid></SculptTexture>
224 <SculptType>0</SculptType><SculptData />
225 <FlexiSoftness>0</FlexiSoftness>
226 <FlexiTension>0,5</FlexiTension>
227 <FlexiDrag>yo mamma</FlexiDrag>
228 <FlexiGravity>0</FlexiGravity>
229 <FlexiWind>0</FlexiWind>
230 <FlexiForceX>0</FlexiForceX>
231 <FlexiForceY>0</FlexiForceY>
232 <FlexiForceZ>0</FlexiForceZ>
233 <LightColorR>0</LightColorR>
234 <LightColorG>0</LightColorG>
235 <LightColorB>0</LightColorB>
236 <LightColorA>1</LightColorA>
237 <LightRadius>0</LightRadius>
238 <LightCutoff>0</LightCutoff>
239 <LightFalloff>0</LightFalloff>
240 <LightIntensity>1</LightIntensity>
241 <FlexiEntry>false</FlexiEntry>
242 <LightEntry>false</LightEntry>
243 <SculptEntry>false</SculptEntry>
244 </Shape>
245 <Scale><X>10</X><Y>10</Y><Z>0.5</Z></Scale>
246 <UpdateFlag>0</UpdateFlag>
247 <SitTargetOrientation><X>0</X><Y>0</Y><Z>0</Z><W>1</W></SitTargetOrientation>
248 <SitTargetPosition><X>0</X><Y>0</Y><Z>0</Z></SitTargetPosition>
249 <SitTargetPositionLL><X>0</X><Y>0</Y><Z>0</Z></SitTargetPositionLL>
250 <SitTargetOrientationLL><X>0</X><Y>0</Y><Z>0</Z><W>1</W></SitTargetOrientationLL>
251 <ParentID>0</ParentID>
252 <CreationDate>1211330445</CreationDate>
253 <Category>0</Category>
254 <SalePrice>0</SalePrice>
255 <ObjectSaleType>0</ObjectSaleType>
256 <OwnershipCost>0</OwnershipCost>
257 <GroupID><Guid>00000000-0000-0000-0000-000000000000</Guid></GroupID>
258 <OwnerID><Guid>a6dacf01-4636-4bb9-8a97-30609438af9d</Guid></OwnerID>
259 <LastOwnerID><Guid>a6dacf01-4636-4bb9-8a97-30609438af9d</Guid></LastOwnerID>
260 <BaseMask>2147483647</BaseMask>
261 <OwnerMask>2147483647</OwnerMask>
262 <GroupMask>0</GroupMask>
263 <EveryoneMask>0</EveryoneMask>
264 <NextOwnerMask>2147483647</NextOwnerMask>
265 <Flags>None</Flags>
266 <CollisionSound><Guid>00000000-0000-0000-0000-000000000000</Guid></CollisionSound>
267 <CollisionSoundVolume>0</CollisionSoundVolume>
268 </SceneObjectPart>
269 </RootPart>
270 <OtherParts />
271 </SceneObjectGroup>";
272  
273 private string xml2 = @"
274 <SceneObjectGroup>
275 <SceneObjectPart xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
276 <CreatorID><UUID>b46ef588-411e-4a8b-a284-d7dcfe8e74ef</UUID></CreatorID>
277 <FolderID><UUID>9be68fdd-f740-4a0f-9675-dfbbb536b946</UUID></FolderID>
278 <InventorySerial>0</InventorySerial>
279 <TaskInventory />
280 <ObjectFlags>0</ObjectFlags>
281 <UUID><UUID>9be68fdd-f740-4a0f-9675-dfbbb536b946</UUID></UUID>
282 <LocalId>720005</LocalId>
283 <Name>PrimFun</Name>
284 <Material>0</Material>
285 <RegionHandle>1099511628032000</RegionHandle>
286 <ScriptAccessPin>0</ScriptAccessPin>
287 <GroupPosition><X>153.9854</X><Y>121.4908</Y><Z>62.21781</Z></GroupPosition>
288 <OffsetPosition><X>0</X><Y>0</Y><Z>0</Z></OffsetPosition>
289 <RotationOffset><X>0</X><Y>0</Y><Z>0</Z><W>1</W></RotationOffset>
290 <Velocity><X>0</X><Y>0</Y><Z>0</Z></Velocity>
291 <RotationalVelocity><X>0</X><Y>0</Y><Z>0</Z></RotationalVelocity>
292 <AngularVelocity><X>0</X><Y>0</Y><Z>0</Z></AngularVelocity>
293 <Acceleration><X>0</X><Y>0</Y><Z>0</Z></Acceleration>
294 <Description />
295 <Color />
296 <Text />
297 <SitName />
298 <TouchName />
299 <LinkNum>0</LinkNum>
300 <ClickAction>0</ClickAction>
301 <Shape>
302 <PathBegin>0</PathBegin>
303 <PathCurve>16</PathCurve>
304 <PathEnd>0</PathEnd>
305 <PathRadiusOffset>0</PathRadiusOffset>
306 <PathRevolutions>0</PathRevolutions>
307 <PathScaleX>200</PathScaleX>
308 <PathScaleY>200</PathScaleY>
309 <PathShearX>0</PathShearX>
310 <PathShearY>0</PathShearY>
311 <PathSkew>0</PathSkew>
312 <PathTaperX>0</PathTaperX>
313 <PathTaperY>0</PathTaperY>
314 <PathTwist>0</PathTwist>
315 <PathTwistBegin>0</PathTwistBegin>
316 <PCode>9</PCode>
317 <ProfileBegin>0</ProfileBegin>
318 <ProfileEnd>0</ProfileEnd>
319 <ProfileHollow>0</ProfileHollow>
320 <Scale><X>1.283131</X><Y>5.903858</Y><Z>4.266288</Z></Scale>
321 <State>0</State>
322 <ProfileShape>Circle</ProfileShape>
323 <HollowShape>Same</HollowShape>
324 <ProfileCurve>0</ProfileCurve>
325 <TextureEntry>iVVnRyTLQ+2SC0fK7RVGXwJ6yc/SU4RDA5nhJbLUw3R1AAAAAAAAaOw8QQOhPSRAAKE9JEAAAAAAAAAAAAAAAAAAAAA=</TextureEntry>
326 <ExtraParams>AA==</ExtraParams>
327 </Shape>
328 <Scale><X>1.283131</X><Y>5.903858</Y><Z>4.266288</Z></Scale>
329 <UpdateFlag>0</UpdateFlag>
330 <SitTargetOrientation><w>0</w><x>0</x><y>0</y><z>1</z></SitTargetOrientation>
331 <SitTargetPosition><x>0</x><y>0</y><z>0</z></SitTargetPosition>
332 <SitTargetPositionLL><X>0</X><Y>0</Y><Z>0</Z></SitTargetPositionLL>
333 <SitTargetOrientationLL><X>0</X><Y>0</Y><Z>1</Z><W>0</W></SitTargetOrientationLL>
334 <ParentID>0</ParentID>
335 <CreationDate>1216066902</CreationDate>
336 <Category>0</Category>
337 <SalePrice>0</SalePrice>
338 <ObjectSaleType>0</ObjectSaleType>
339 <OwnershipCost>0</OwnershipCost>
340 <GroupID><UUID>00000000-0000-0000-0000-000000000000</UUID></GroupID>
341 <OwnerID><UUID>b46ef588-411e-4a8b-a284-d7dcfe8e74ef</UUID></OwnerID>
342 <LastOwnerID><UUID>b46ef588-411e-4a8b-a284-d7dcfe8e74ef</UUID></LastOwnerID>
343 <BaseMask>2147483647</BaseMask>
344 <OwnerMask>2147483647</OwnerMask>
345 <GroupMask>0</GroupMask>
346 <EveryoneMask>0</EveryoneMask>
347 <NextOwnerMask>2147483647</NextOwnerMask>
348 <Flags>None</Flags>
349 <DynAttrs>
350 <llsd>
351 <map>
352 <key>MyNamespace</key>
353 <map>
354 <key>MyStore</key>
355 <map>
356 <key>last words</key>
357 <string>Rosebud</string>
358 </map>
359 </map>
360 </map>
361 </llsd>
362 </DynAttrs>
363 <SitTargetAvatar><UUID>00000000-0000-0000-0000-000000000000</UUID></SitTargetAvatar>
364 </SceneObjectPart>
365 <OtherParts />
366 </SceneObjectGroup>";
367  
368 protected Scene m_scene;
369 protected SerialiserModule m_serialiserModule;
370  
371 [TestFixtureSetUp]
372 public void Init()
373 {
374 m_serialiserModule = new SerialiserModule();
375 m_scene = new SceneHelpers().SetupScene();
376 SceneHelpers.SetupSceneModules(m_scene, m_serialiserModule);
377 }
378  
379 [Test]
380 public void TestDeserializeXml()
381 {
382 TestHelpers.InMethod();
383 //log4net.Config.XmlConfigurator.Configure();
384  
385 SceneObjectGroup so = SceneObjectSerializer.FromOriginalXmlFormat(xml);
386 SceneObjectPart rootPart = so.RootPart;
387  
388 Assert.That(rootPart.UUID, Is.EqualTo(new UUID("e6a5a05e-e8cc-4816-8701-04165e335790")));
389 Assert.That(rootPart.CreatorID, Is.EqualTo(new UUID("a6dacf01-4636-4bb9-8a97-30609438af9d")));
390 Assert.That(rootPart.Name, Is.EqualTo("PrimMyRide"));
391 OSDMap store = rootPart.DynAttrs.GetStore("MyNamespace", "MyStore");
392 Assert.AreEqual(42, store["the answer"].AsInteger());
393  
394 // TODO: Check other properties
395 }
396  
397 [Test]
398 public void TestDeserializeBadFloatsXml()
399 {
400 TestHelpers.InMethod();
401 // log4net.Config.XmlConfigurator.Configure();
402  
403 SceneObjectGroup so = SceneObjectSerializer.FromOriginalXmlFormat(badFloatsXml);
404 SceneObjectPart rootPart = so.RootPart;
405  
406 Assert.That(rootPart.UUID, Is.EqualTo(new UUID("e6a5a05e-e8cc-4816-8701-04165e335790")));
407 Assert.That(rootPart.CreatorID, Is.EqualTo(new UUID("a6dacf01-4636-4bb9-8a97-30609438af9d")));
408 Assert.That(rootPart.Name, Is.EqualTo("NaughtyPrim"));
409  
410 // This terminates the deserialization earlier if couldn't be parsed.
411 // TODO: Need to address this
412 Assert.That(rootPart.GroupPosition.X, Is.EqualTo(147.23f));
413  
414 Assert.That(rootPart.Shape.PathCurve, Is.EqualTo(16));
415  
416 // Defaults for bad parses
417 Assert.That(rootPart.Shape.FlexiTension, Is.EqualTo(0));
418 Assert.That(rootPart.Shape.FlexiDrag, Is.EqualTo(0));
419  
420 // TODO: Check other properties
421 }
422  
423 [Test]
424 public void TestSerializeXml()
425 {
426 TestHelpers.InMethod();
427 //log4net.Config.XmlConfigurator.Configure();
428  
429 string rpName = "My Little Donkey";
430 UUID rpUuid = UUID.Parse("00000000-0000-0000-0000-000000000964");
431 UUID rpCreatorId = UUID.Parse("00000000-0000-0000-0000-000000000915");
432 PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere();
433 // Vector3 groupPosition = new Vector3(10, 20, 30);
434 // Quaternion rotationOffset = new Quaternion(20, 30, 40, 50);
435 // Vector3 offsetPosition = new Vector3(5, 10, 15);
436  
437 SceneObjectPart rp = new SceneObjectPart();
438 rp.UUID = rpUuid;
439 rp.Name = rpName;
440 rp.CreatorID = rpCreatorId;
441 rp.Shape = shape;
442  
443 string daNamespace = "MyNamespace";
444 string daStoreName = "MyStore";
445 string daKey = "foo";
446 string daValue = "bar";
447 OSDMap myStore = new OSDMap();
448 myStore.Add(daKey, daValue);
449 rp.DynAttrs = new DAMap();
450 rp.DynAttrs.SetStore(daNamespace, daStoreName, myStore);
451  
452 SceneObjectGroup so = new SceneObjectGroup(rp);
453  
454 // Need to add the object to the scene so that the request to get script state succeeds
455 m_scene.AddSceneObject(so);
456  
457 string xml = SceneObjectSerializer.ToOriginalXmlFormat(so);
458  
459 XmlTextReader xtr = new XmlTextReader(new StringReader(xml));
460 xtr.ReadStartElement("SceneObjectGroup");
461 xtr.ReadStartElement("RootPart");
462 xtr.ReadStartElement("SceneObjectPart");
463  
464 UUID uuid = UUID.Zero;
465 string name = null;
466 UUID creatorId = UUID.Zero;
467 DAMap daMap = null;
468  
469 while (xtr.Read() && xtr.Name != "SceneObjectPart")
470 {
471 if (xtr.NodeType != XmlNodeType.Element)
472 continue;
473  
474 switch (xtr.Name)
475 {
476 case "UUID":
477 xtr.ReadStartElement("UUID");
478 try
479 {
480 uuid = UUID.Parse(xtr.ReadElementString("UUID"));
481 xtr.ReadEndElement();
482 }
483 catch { } // ignore everything but <UUID><UUID>...</UUID></UUID>
484 break;
485 case "Name":
486 name = xtr.ReadElementContentAsString();
487 break;
488 case "CreatorID":
489 xtr.ReadStartElement("CreatorID");
490 creatorId = UUID.Parse(xtr.ReadElementString("UUID"));
491 xtr.ReadEndElement();
492 break;
493 case "DynAttrs":
494 daMap = new DAMap();
495 daMap.ReadXml(xtr);
496 break;
497 }
498 }
499  
500 xtr.ReadEndElement();
501 xtr.ReadEndElement();
502 xtr.ReadStartElement("OtherParts");
503 xtr.ReadEndElement();
504 xtr.Close();
505  
506 // TODO: More checks
507 Assert.That(uuid, Is.EqualTo(rpUuid));
508 Assert.That(name, Is.EqualTo(rpName));
509 Assert.That(creatorId, Is.EqualTo(rpCreatorId));
510 Assert.NotNull(daMap);
511 Assert.AreEqual(daValue, daMap.GetStore(daNamespace, daStoreName)[daKey].AsString());
512 }
513  
514 [Test]
515 public void TestDeserializeXml2()
516 {
517 TestHelpers.InMethod();
518 //log4net.Config.XmlConfigurator.Configure();
519  
520 SceneObjectGroup so = m_serialiserModule.DeserializeGroupFromXml2(xml2);
521 SceneObjectPart rootPart = so.RootPart;
522  
523 Assert.That(rootPart.UUID, Is.EqualTo(new UUID("9be68fdd-f740-4a0f-9675-dfbbb536b946")));
524 Assert.That(rootPart.CreatorID, Is.EqualTo(new UUID("b46ef588-411e-4a8b-a284-d7dcfe8e74ef")));
525 Assert.That(rootPart.Name, Is.EqualTo("PrimFun"));
526 OSDMap store = rootPart.DynAttrs.GetStore("MyNamespace", "MyStore");
527 Assert.AreEqual("Rosebud", store["last words"].AsString());
528  
529 // TODO: Check other properties
530 }
531  
532 [Test]
533 public void TestSerializeXml2()
534 {
535 TestHelpers.InMethod();
536 //log4net.Config.XmlConfigurator.Configure();
537  
538 string rpName = "My Little Pony";
539 UUID rpUuid = UUID.Parse("00000000-0000-0000-0000-000000000064");
540 UUID rpCreatorId = UUID.Parse("00000000-0000-0000-0000-000000000015");
541 PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere();
542 // Vector3 groupPosition = new Vector3(10, 20, 30);
543 // Quaternion rotationOffset = new Quaternion(20, 30, 40, 50);
544 // Vector3 offsetPosition = new Vector3(5, 10, 15);
545  
546 SceneObjectPart rp = new SceneObjectPart();
547 rp.UUID = rpUuid;
548 rp.Name = rpName;
549 rp.CreatorID = rpCreatorId;
550 rp.Shape = shape;
551  
552 string daNamespace = "MyNamespace";
553 string daStoreName = "MyStore";
554 string daKey = "foo";
555 string daValue = "bar";
556 OSDMap myStore = new OSDMap();
557 myStore.Add(daKey, daValue);
558 rp.DynAttrs = new DAMap();
559 rp.DynAttrs.SetStore(daNamespace, daStoreName, myStore);
560  
561 SceneObjectGroup so = new SceneObjectGroup(rp);
562  
563 // Need to add the object to the scene so that the request to get script state succeeds
564 m_scene.AddSceneObject(so);
565  
566 Dictionary<string, object> options = new Dictionary<string, object>();
567 options["old-guids"] = true;
568 string xml2 = m_serialiserModule.SerializeGroupToXml2(so, options);
569  
570 XmlTextReader xtr = new XmlTextReader(new StringReader(xml2));
571 xtr.ReadStartElement("SceneObjectGroup");
572 xtr.ReadStartElement("SceneObjectPart");
573  
574 UUID uuid = UUID.Zero;
575 string name = null;
576 UUID creatorId = UUID.Zero;
577 DAMap daMap = null;
578  
579 while (xtr.Read() && xtr.Name != "SceneObjectPart")
580 {
581 if (xtr.NodeType != XmlNodeType.Element)
582 continue;
583  
584 switch (xtr.Name)
585 {
586 case "UUID":
587 xtr.ReadStartElement("UUID");
588 uuid = UUID.Parse(xtr.ReadElementString("Guid"));
589 xtr.ReadEndElement();
590 break;
591 case "Name":
592 name = xtr.ReadElementContentAsString();
593 break;
594 case "CreatorID":
595 xtr.ReadStartElement("CreatorID");
596 creatorId = UUID.Parse(xtr.ReadElementString("Guid"));
597 xtr.ReadEndElement();
598 break;
599 case "DynAttrs":
600 daMap = new DAMap();
601 daMap.ReadXml(xtr);
602 break;
603 }
604 }
605  
606 xtr.ReadEndElement();
607 xtr.ReadStartElement("OtherParts");
608 xtr.ReadEndElement();
609 xtr.Close();
610  
611 // TODO: More checks
612 Assert.That(uuid, Is.EqualTo(rpUuid));
613 Assert.That(name, Is.EqualTo(rpName));
614 Assert.That(creatorId, Is.EqualTo(rpCreatorId));
615 Assert.NotNull(daMap);
616 Assert.AreEqual(daValue, daMap.GetStore(daNamespace, daStoreName)[daKey].AsString());
617 }
618 }
619 }