SerialiserTests.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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. using log4net.Config;
  28. using NUnit.Framework;
  29. using NUnit.Framework.SyntaxHelpers;
  30. using OpenMetaverse;
  31. using OpenSim.Framework;
  32. using OpenSim.Region.Framework.Scenes;
  33. using OpenSim.Region.Framework.Scenes.Serialization;
  34. using OpenSim.Tests.Common;
  35. using OpenSim.Tests.Common.Setup;
  36. using System.IO;
  37. using System.Xml;
  38. namespace OpenSim.Region.CoreModules.World.Serialiser.Tests
  39. {
  40. [TestFixture]
  41. public class SerialiserTests
  42. {
  43. private string xml = @"
  44. <SceneObjectGroup>
  45. <RootPart>
  46. <SceneObjectPart xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
  47. <AllowedDrop>false</AllowedDrop>
  48. <CreatorID><Guid>a6dacf01-4636-4bb9-8a97-30609438af9d</Guid></CreatorID>
  49. <FolderID><Guid>e6a5a05e-e8cc-4816-8701-04165e335790</Guid></FolderID>
  50. <InventorySerial>1</InventorySerial>
  51. <TaskInventory />
  52. <ObjectFlags>0</ObjectFlags>
  53. <UUID><Guid>e6a5a05e-e8cc-4816-8701-04165e335790</Guid></UUID>
  54. <LocalId>2698615125</LocalId>
  55. <Name>PrimMyRide</Name>
  56. <Material>0</Material>
  57. <PassTouches>false</PassTouches>
  58. <RegionHandle>1099511628032000</RegionHandle>
  59. <ScriptAccessPin>0</ScriptAccessPin>
  60. <GroupPosition><X>147.23</X><Y>92.698</Y><Z>22.78084</Z></GroupPosition>
  61. <OffsetPosition><X>0</X><Y>0</Y><Z>0</Z></OffsetPosition>
  62. <RotationOffset><X>-4.371139E-08</X><Y>-1</Y><Z>-4.371139E-08</Z><W>0</W></RotationOffset>
  63. <Velocity><X>0</X><Y>0</Y><Z>0</Z></Velocity>
  64. <RotationalVelocity><X>0</X><Y>0</Y><Z>0</Z></RotationalVelocity>
  65. <AngularVelocity><X>0</X><Y>0</Y><Z>0</Z></AngularVelocity>
  66. <Acceleration><X>0</X><Y>0</Y><Z>0</Z></Acceleration>
  67. <Description />
  68. <Color />
  69. <Text />
  70. <SitName />
  71. <TouchName />
  72. <LinkNum>0</LinkNum>
  73. <ClickAction>0</ClickAction>
  74. <Shape>
  75. <ProfileCurve>1</ProfileCurve>
  76. <TextureEntry>AAAAAAAAERGZmQAAAAAABQCVlZUAAAAAQEAAAABAQAAAAAAAAAAAAAAAAAAAAA==</TextureEntry>
  77. <ExtraParams>AA==</ExtraParams>
  78. <PathBegin>0</PathBegin>
  79. <PathCurve>16</PathCurve>
  80. <PathEnd>0</PathEnd>
  81. <PathRadiusOffset>0</PathRadiusOffset>
  82. <PathRevolutions>0</PathRevolutions>
  83. <PathScaleX>100</PathScaleX>
  84. <PathScaleY>100</PathScaleY>
  85. <PathShearX>0</PathShearX>
  86. <PathShearY>0</PathShearY>
  87. <PathSkew>0</PathSkew>
  88. <PathTaperX>0</PathTaperX>
  89. <PathTaperY>0</PathTaperY>
  90. <PathTwist>0</PathTwist>
  91. <PathTwistBegin>0</PathTwistBegin>
  92. <PCode>9</PCode>
  93. <ProfileBegin>0</ProfileBegin>
  94. <ProfileEnd>0</ProfileEnd>
  95. <ProfileHollow>0</ProfileHollow>
  96. <Scale><X>10</X><Y>10</Y><Z>0.5</Z></Scale>
  97. <State>0</State>
  98. <ProfileShape>Square</ProfileShape>
  99. <HollowShape>Same</HollowShape>
  100. <SculptTexture><Guid>00000000-0000-0000-0000-000000000000</Guid></SculptTexture>
  101. <SculptType>0</SculptType><SculptData />
  102. <FlexiSoftness>0</FlexiSoftness>
  103. <FlexiTension>0</FlexiTension>
  104. <FlexiDrag>0</FlexiDrag>
  105. <FlexiGravity>0</FlexiGravity>
  106. <FlexiWind>0</FlexiWind>
  107. <FlexiForceX>0</FlexiForceX>
  108. <FlexiForceY>0</FlexiForceY>
  109. <FlexiForceZ>0</FlexiForceZ>
  110. <LightColorR>0</LightColorR>
  111. <LightColorG>0</LightColorG>
  112. <LightColorB>0</LightColorB>
  113. <LightColorA>1</LightColorA>
  114. <LightRadius>0</LightRadius>
  115. <LightCutoff>0</LightCutoff>
  116. <LightFalloff>0</LightFalloff>
  117. <LightIntensity>1</LightIntensity>
  118. <FlexiEntry>false</FlexiEntry>
  119. <LightEntry>false</LightEntry>
  120. <SculptEntry>false</SculptEntry>
  121. </Shape>
  122. <Scale><X>10</X><Y>10</Y><Z>0.5</Z></Scale>
  123. <UpdateFlag>0</UpdateFlag>
  124. <SitTargetOrientation><X>0</X><Y>0</Y><Z>0</Z><W>1</W></SitTargetOrientation>
  125. <SitTargetPosition><X>0</X><Y>0</Y><Z>0</Z></SitTargetPosition>
  126. <SitTargetPositionLL><X>0</X><Y>0</Y><Z>0</Z></SitTargetPositionLL>
  127. <SitTargetOrientationLL><X>0</X><Y>0</Y><Z>0</Z><W>1</W></SitTargetOrientationLL>
  128. <ParentID>0</ParentID>
  129. <CreationDate>1211330445</CreationDate>
  130. <Category>0</Category>
  131. <SalePrice>0</SalePrice>
  132. <ObjectSaleType>0</ObjectSaleType>
  133. <OwnershipCost>0</OwnershipCost>
  134. <GroupID><Guid>00000000-0000-0000-0000-000000000000</Guid></GroupID>
  135. <OwnerID><Guid>a6dacf01-4636-4bb9-8a97-30609438af9d</Guid></OwnerID>
  136. <LastOwnerID><Guid>a6dacf01-4636-4bb9-8a97-30609438af9d</Guid></LastOwnerID>
  137. <BaseMask>2147483647</BaseMask>
  138. <OwnerMask>2147483647</OwnerMask>
  139. <GroupMask>0</GroupMask>
  140. <EveryoneMask>0</EveryoneMask>
  141. <NextOwnerMask>2147483647</NextOwnerMask>
  142. <Flags>None</Flags>
  143. <CollisionSound><Guid>00000000-0000-0000-0000-000000000000</Guid></CollisionSound>
  144. <CollisionSoundVolume>0</CollisionSoundVolume>
  145. </SceneObjectPart>
  146. </RootPart>
  147. <OtherParts />
  148. </SceneObjectGroup>";
  149. private string xml2 = @"
  150. <SceneObjectGroup>
  151. <SceneObjectPart xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
  152. <CreatorID><UUID>b46ef588-411e-4a8b-a284-d7dcfe8e74ef</UUID></CreatorID>
  153. <FolderID><UUID>9be68fdd-f740-4a0f-9675-dfbbb536b946</UUID></FolderID>
  154. <InventorySerial>0</InventorySerial>
  155. <TaskInventory />
  156. <ObjectFlags>0</ObjectFlags>
  157. <UUID><UUID>9be68fdd-f740-4a0f-9675-dfbbb536b946</UUID></UUID>
  158. <LocalId>720005</LocalId>
  159. <Name>PrimFun</Name>
  160. <Material>0</Material>
  161. <RegionHandle>1099511628032000</RegionHandle>
  162. <ScriptAccessPin>0</ScriptAccessPin>
  163. <GroupPosition><X>153.9854</X><Y>121.4908</Y><Z>62.21781</Z></GroupPosition>
  164. <OffsetPosition><X>0</X><Y>0</Y><Z>0</Z></OffsetPosition>
  165. <RotationOffset><X>0</X><Y>0</Y><Z>0</Z><W>1</W></RotationOffset>
  166. <Velocity><X>0</X><Y>0</Y><Z>0</Z></Velocity>
  167. <RotationalVelocity><X>0</X><Y>0</Y><Z>0</Z></RotationalVelocity>
  168. <AngularVelocity><X>0</X><Y>0</Y><Z>0</Z></AngularVelocity>
  169. <Acceleration><X>0</X><Y>0</Y><Z>0</Z></Acceleration>
  170. <Description />
  171. <Color />
  172. <Text />
  173. <SitName />
  174. <TouchName />
  175. <LinkNum>0</LinkNum>
  176. <ClickAction>0</ClickAction>
  177. <Shape>
  178. <PathBegin>0</PathBegin>
  179. <PathCurve>16</PathCurve>
  180. <PathEnd>0</PathEnd>
  181. <PathRadiusOffset>0</PathRadiusOffset>
  182. <PathRevolutions>0</PathRevolutions>
  183. <PathScaleX>200</PathScaleX>
  184. <PathScaleY>200</PathScaleY>
  185. <PathShearX>0</PathShearX>
  186. <PathShearY>0</PathShearY>
  187. <PathSkew>0</PathSkew>
  188. <PathTaperX>0</PathTaperX>
  189. <PathTaperY>0</PathTaperY>
  190. <PathTwist>0</PathTwist>
  191. <PathTwistBegin>0</PathTwistBegin>
  192. <PCode>9</PCode>
  193. <ProfileBegin>0</ProfileBegin>
  194. <ProfileEnd>0</ProfileEnd>
  195. <ProfileHollow>0</ProfileHollow>
  196. <Scale><X>1.283131</X><Y>5.903858</Y><Z>4.266288</Z></Scale>
  197. <State>0</State>
  198. <ProfileShape>Circle</ProfileShape>
  199. <HollowShape>Same</HollowShape>
  200. <ProfileCurve>0</ProfileCurve>
  201. <TextureEntry>iVVnRyTLQ+2SC0fK7RVGXwJ6yc/SU4RDA5nhJbLUw3R1AAAAAAAAaOw8QQOhPSRAAKE9JEAAAAAAAAAAAAAAAAAAAAA=</TextureEntry>
  202. <ExtraParams>AA==</ExtraParams>
  203. </Shape>
  204. <Scale><X>1.283131</X><Y>5.903858</Y><Z>4.266288</Z></Scale>
  205. <UpdateFlag>0</UpdateFlag>
  206. <SitTargetOrientation><w>0</w><x>0</x><y>0</y><z>1</z></SitTargetOrientation>
  207. <SitTargetPosition><x>0</x><y>0</y><z>0</z></SitTargetPosition>
  208. <SitTargetPositionLL><X>0</X><Y>0</Y><Z>0</Z></SitTargetPositionLL>
  209. <SitTargetOrientationLL><X>0</X><Y>0</Y><Z>1</Z><W>0</W></SitTargetOrientationLL>
  210. <ParentID>0</ParentID>
  211. <CreationDate>1216066902</CreationDate>
  212. <Category>0</Category>
  213. <SalePrice>0</SalePrice>
  214. <ObjectSaleType>0</ObjectSaleType>
  215. <OwnershipCost>0</OwnershipCost>
  216. <GroupID><UUID>00000000-0000-0000-0000-000000000000</UUID></GroupID>
  217. <OwnerID><UUID>b46ef588-411e-4a8b-a284-d7dcfe8e74ef</UUID></OwnerID>
  218. <LastOwnerID><UUID>b46ef588-411e-4a8b-a284-d7dcfe8e74ef</UUID></LastOwnerID>
  219. <BaseMask>2147483647</BaseMask>
  220. <OwnerMask>2147483647</OwnerMask>
  221. <GroupMask>0</GroupMask>
  222. <EveryoneMask>0</EveryoneMask>
  223. <NextOwnerMask>2147483647</NextOwnerMask>
  224. <Flags>None</Flags>
  225. <SitTargetAvatar><UUID>00000000-0000-0000-0000-000000000000</UUID></SitTargetAvatar>
  226. </SceneObjectPart>
  227. <OtherParts />
  228. </SceneObjectGroup>";
  229. protected Scene m_scene;
  230. protected SerialiserModule m_serialiserModule;
  231. [TestFixtureSetUp]
  232. public void Init()
  233. {
  234. m_serialiserModule = new SerialiserModule();
  235. m_scene = SceneSetupHelpers.SetupScene("");
  236. SceneSetupHelpers.SetupSceneModules(m_scene, m_serialiserModule);
  237. }
  238. [Test]
  239. public void TestDeserializeXml()
  240. {
  241. TestHelper.InMethod();
  242. //log4net.Config.XmlConfigurator.Configure();
  243. SceneObjectGroup so = SceneObjectSerializer.FromOriginalXmlFormat(xml);
  244. SceneObjectPart rootPart = so.RootPart;
  245. Assert.That(rootPart.UUID, Is.EqualTo(new UUID("e6a5a05e-e8cc-4816-8701-04165e335790")));
  246. Assert.That(rootPart.CreatorID, Is.EqualTo(new UUID("a6dacf01-4636-4bb9-8a97-30609438af9d")));
  247. Assert.That(rootPart.Name, Is.EqualTo("PrimMyRide"));
  248. // TODO: Check other properties
  249. }
  250. [Test]
  251. public void TestSerializeXml()
  252. {
  253. TestHelper.InMethod();
  254. //log4net.Config.XmlConfigurator.Configure();
  255. string rpName = "My Little Donkey";
  256. UUID rpUuid = UUID.Parse("00000000-0000-0000-0000-000000000964");
  257. UUID rpCreatorId = UUID.Parse("00000000-0000-0000-0000-000000000915");
  258. PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere();
  259. // Vector3 groupPosition = new Vector3(10, 20, 30);
  260. // Quaternion rotationOffset = new Quaternion(20, 30, 40, 50);
  261. // Vector3 offsetPosition = new Vector3(5, 10, 15);
  262. SceneObjectPart rp = new SceneObjectPart();
  263. rp.UUID = rpUuid;
  264. rp.Name = rpName;
  265. rp.CreatorID = rpCreatorId;
  266. rp.Shape = shape;
  267. SceneObjectGroup so = new SceneObjectGroup(rp);
  268. // Need to add the object to the scene so that the request to get script state succeeds
  269. m_scene.AddSceneObject(so);
  270. string xml = SceneObjectSerializer.ToOriginalXmlFormat(so);
  271. XmlTextReader xtr = new XmlTextReader(new StringReader(xml));
  272. xtr.ReadStartElement("SceneObjectGroup");
  273. xtr.ReadStartElement("RootPart");
  274. xtr.ReadStartElement("SceneObjectPart");
  275. UUID uuid = UUID.Zero;
  276. string name = null;
  277. UUID creatorId = UUID.Zero;
  278. while (xtr.Read() && xtr.Name != "SceneObjectPart")
  279. {
  280. if (xtr.NodeType != XmlNodeType.Element)
  281. continue;
  282. switch (xtr.Name)
  283. {
  284. case "UUID":
  285. xtr.ReadStartElement("UUID");
  286. uuid = UUID.Parse(xtr.ReadElementString("Guid"));
  287. xtr.ReadEndElement();
  288. break;
  289. case "Name":
  290. name = xtr.ReadElementContentAsString();
  291. break;
  292. case "CreatorID":
  293. xtr.ReadStartElement("CreatorID");
  294. creatorId = UUID.Parse(xtr.ReadElementString("Guid"));
  295. xtr.ReadEndElement();
  296. break;
  297. }
  298. }
  299. xtr.ReadEndElement();
  300. xtr.ReadEndElement();
  301. xtr.ReadStartElement("OtherParts");
  302. xtr.ReadEndElement();
  303. xtr.Close();
  304. // TODO: More checks
  305. Assert.That(uuid, Is.EqualTo(rpUuid));
  306. Assert.That(name, Is.EqualTo(rpName));
  307. Assert.That(creatorId, Is.EqualTo(rpCreatorId));
  308. }
  309. [Test]
  310. public void TestDeserializeXml2()
  311. {
  312. TestHelper.InMethod();
  313. //log4net.Config.XmlConfigurator.Configure();
  314. SceneObjectGroup so = m_serialiserModule.DeserializeGroupFromXml2(xml2);
  315. SceneObjectPart rootPart = so.RootPart;
  316. Assert.That(rootPart.UUID, Is.EqualTo(new UUID("9be68fdd-f740-4a0f-9675-dfbbb536b946")));
  317. Assert.That(rootPart.CreatorID, Is.EqualTo(new UUID("b46ef588-411e-4a8b-a284-d7dcfe8e74ef")));
  318. Assert.That(rootPart.Name, Is.EqualTo("PrimFun"));
  319. // TODO: Check other properties
  320. }
  321. [Test]
  322. public void TestSerializeXml2()
  323. {
  324. TestHelper.InMethod();
  325. //log4net.Config.XmlConfigurator.Configure();
  326. string rpName = "My Little Pony";
  327. UUID rpUuid = UUID.Parse("00000000-0000-0000-0000-000000000064");
  328. UUID rpCreatorId = UUID.Parse("00000000-0000-0000-0000-000000000015");
  329. PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere();
  330. // Vector3 groupPosition = new Vector3(10, 20, 30);
  331. // Quaternion rotationOffset = new Quaternion(20, 30, 40, 50);
  332. // Vector3 offsetPosition = new Vector3(5, 10, 15);
  333. SceneObjectPart rp = new SceneObjectPart();
  334. rp.UUID = rpUuid;
  335. rp.Name = rpName;
  336. rp.CreatorID = rpCreatorId;
  337. rp.Shape = shape;
  338. SceneObjectGroup so = new SceneObjectGroup(rp);
  339. // Need to add the object to the scene so that the request to get script state succeeds
  340. m_scene.AddSceneObject(so);
  341. string xml2 = m_serialiserModule.SerializeGroupToXml2(so);
  342. XmlTextReader xtr = new XmlTextReader(new StringReader(xml2));
  343. xtr.ReadStartElement("SceneObjectGroup");
  344. xtr.ReadStartElement("SceneObjectPart");
  345. UUID uuid = UUID.Zero;
  346. string name = null;
  347. UUID creatorId = UUID.Zero;
  348. while (xtr.Read() && xtr.Name != "SceneObjectPart")
  349. {
  350. if (xtr.NodeType != XmlNodeType.Element)
  351. continue;
  352. switch (xtr.Name)
  353. {
  354. case "UUID":
  355. xtr.ReadStartElement("UUID");
  356. uuid = UUID.Parse(xtr.ReadElementString("Guid"));
  357. xtr.ReadEndElement();
  358. break;
  359. case "Name":
  360. name = xtr.ReadElementContentAsString();
  361. break;
  362. case "CreatorID":
  363. xtr.ReadStartElement("CreatorID");
  364. creatorId = UUID.Parse(xtr.ReadElementString("Guid"));
  365. xtr.ReadEndElement();
  366. break;
  367. }
  368. }
  369. xtr.ReadEndElement();
  370. xtr.ReadStartElement("OtherParts");
  371. xtr.ReadEndElement();
  372. xtr.Close();
  373. // TODO: More checks
  374. Assert.That(uuid, Is.EqualTo(rpUuid));
  375. Assert.That(name, Is.EqualTo(rpName));
  376. Assert.That(creatorId, Is.EqualTo(rpCreatorId));
  377. }
  378. }
  379. }