1
0

LandDataSerializerTests.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. using System;
  28. using System.Collections.Generic;
  29. using OpenMetaverse;
  30. using OpenMetaverse.StructuredData;
  31. using NUnit.Framework;
  32. using OpenSim.Framework;
  33. using OpenSim.Framework.Serialization.External;
  34. using OpenSim.Tests.Common;
  35. namespace OpenSim.Framework.Serialization.Tests
  36. {
  37. [TestFixture]
  38. public class LandDataSerializerTest : OpenSimTestCase
  39. {
  40. private LandData land;
  41. private LandData landWithParcelAccessList;
  42. // private static string preSerialized = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\n<LandData>\n <Area>128</Area>\n <AuctionID>0</AuctionID>\n <AuthBuyerID>00000000-0000-0000-0000-000000000000</AuthBuyerID>\n <Category>10</Category>\n <ClaimDate>0</ClaimDate>\n <ClaimPrice>0</ClaimPrice>\n <GlobalID>54ff9641-dd40-4a2c-b1f1-47dd3af24e50</GlobalID>\n <GroupID>d740204e-bbbf-44aa-949d-02c7d739f6a5</GroupID>\n <IsGroupOwned>False</IsGroupOwned>\n <Bitmap>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</Bitmap>\n <Description>land data to test LandDataSerializer</Description>\n <Flags>536870944</Flags>\n <LandingType>2</LandingType>\n <Name>LandDataSerializerTest Land</Name>\n <Status>0</Status>\n <LocalID>0</LocalID>\n <MediaAutoScale>1</MediaAutoScale>\n <MediaID>d4452578-2f25-4b97-a81b-819af559cfd7</MediaID>\n <MediaURL>http://videos.opensimulator.org/bumblebee.mp4</MediaURL>\n <MusicURL />\n <OwnerID>1b8eedf9-6d15-448b-8015-24286f1756bf</OwnerID>\n <ParcelAccessList />\n <PassHours>0</PassHours>\n <PassPrice>0</PassPrice>\n <SalePrice>0</SalePrice>\n <SnapshotID>00000000-0000-0000-0000-000000000000</SnapshotID>\n <UserLocation>&lt;0, 0, 0&gt;</UserLocation>\n <UserLookAt>&lt;0, 0, 0&gt;</UserLookAt>\n <Dwell>0</Dwell>\n <OtherCleanTime>0</OtherCleanTime>\n</LandData>";
  43. private static string preSerializedWithParcelAccessList
  44. = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\n<LandData>\n <Area>128</Area>\n <AuctionID>0</AuctionID>\n <AuthBuyerID>00000000-0000-0000-0000-000000000000</AuthBuyerID>\n <Category>10</Category>\n <ClaimDate>0</ClaimDate>\n <ClaimPrice>0</ClaimPrice>\n <GlobalID>54ff9641-dd40-4a2c-b1f1-47dd3af24e50</GlobalID>\n <GroupID>d740204e-bbbf-44aa-949d-02c7d739f6a5</GroupID>\n <IsGroupOwned>False</IsGroupOwned>\n <Bitmap>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</Bitmap>\n <Description>land data to test LandDataSerializer</Description>\n <Flags>536870944</Flags>\n <LandingType>2</LandingType>\n <Name>LandDataSerializerTest Land</Name>\n <Status>0</Status>\n <LocalID>0</LocalID>\n <MediaAutoScale>1</MediaAutoScale>\n <MediaID>d4452578-2f25-4b97-a81b-819af559cfd7</MediaID>\n <MediaURL>http://videos.opensimulator.org/bumblebee.mp4</MediaURL>\n <MusicURL />\n <OwnerID>1b8eedf9-6d15-448b-8015-24286f1756bf</OwnerID>\n <ParcelAccessList>\n <ParcelAccessEntry>\n <AgentID>62d65d45-c91a-4f77-862c-46557d978b6c</AgentID>\n <Time>0</Time>\n <AccessList>2</AccessList>\n </ParcelAccessEntry>\n <ParcelAccessEntry>\n <AgentID>ec2a8d18-2378-4fe0-8b68-2a31b57c481e</AgentID>\n <Time>0</Time>\n <AccessList>1</AccessList>\n </ParcelAccessEntry>\n </ParcelAccessList>\n <PassHours>0</PassHours>\n <PassPrice>0</PassPrice>\n <SalePrice>0</SalePrice>\n <SnapshotID>00000000-0000-0000-0000-000000000000</SnapshotID>\n <UserLocation>&lt;0, 0, 0&gt;</UserLocation>\n <UserLookAt>&lt;0, 0, 0&gt;</UserLookAt>\n <Dwell>0</Dwell>\n <OtherCleanTime>0</OtherCleanTime>\n</LandData>";
  45. [SetUp]
  46. public void setup()
  47. {
  48. // setup LandData object
  49. this.land = new LandData();
  50. this.land.AABBMax = new Vector3(1, 2, 3);
  51. this.land.AABBMin = new Vector3(129, 130, 131);
  52. this.land.Area = 128;
  53. this.land.AuctionID = 4;
  54. this.land.AuthBuyerID = new UUID("7176df0c-6c50-45db-8a37-5e78be56a0cd");
  55. this.land.Category = ParcelCategory.Residential;
  56. this.land.ClaimDate = 1;
  57. this.land.ClaimPrice = 2;
  58. this.land.GlobalID = new UUID("54ff9641-dd40-4a2c-b1f1-47dd3af24e50");
  59. this.land.GroupID = new UUID("d740204e-bbbf-44aa-949d-02c7d739f6a5");
  60. this.land.Description = "land data to test LandDataSerializer";
  61. this.land.Flags = (uint)(ParcelFlags.AllowDamage | ParcelFlags.AllowVoiceChat);
  62. this.land.LandingType = (byte)LandingType.Direct;
  63. this.land.Name = "LandDataSerializerTest Land";
  64. this.land.Status = ParcelStatus.Leased;
  65. this.land.LocalID = 1;
  66. this.land.MediaAutoScale = (byte)0x01;
  67. this.land.MediaID = new UUID("d4452578-2f25-4b97-a81b-819af559cfd7");
  68. this.land.MediaURL = "http://videos.opensimulator.org/bumblebee.mp4";
  69. this.land.OwnerID = new UUID("1b8eedf9-6d15-448b-8015-24286f1756bf");
  70. this.landWithParcelAccessList = this.land.Copy();
  71. this.landWithParcelAccessList.ParcelAccessList.Clear();
  72. LandAccessEntry pae0 = new LandAccessEntry();
  73. pae0.AgentID = new UUID("62d65d45-c91a-4f77-862c-46557d978b6c");
  74. pae0.Flags = AccessList.Ban;
  75. pae0.Expires = 0;
  76. this.landWithParcelAccessList.ParcelAccessList.Add(pae0);
  77. LandAccessEntry pae1 = new LandAccessEntry();
  78. pae1.AgentID = new UUID("ec2a8d18-2378-4fe0-8b68-2a31b57c481e");
  79. pae1.Flags = AccessList.Access;
  80. pae1.Expires = 0;
  81. this.landWithParcelAccessList.ParcelAccessList.Add(pae1);
  82. }
  83. /// <summary>
  84. /// Test the LandDataSerializer.Serialize() method
  85. /// </summary>
  86. // [Test]
  87. // public void LandDataSerializerSerializeTest()
  88. // {
  89. // TestHelpers.InMethod();
  90. //
  91. // string serialized = LandDataSerializer.Serialize(this.land).Replace("\r\n", "\n");
  92. // Assert.That(serialized.Length > 0, "Serialize(LandData) returned empty string");
  93. //
  94. // // adding a simple boolean variable because resharper nUnit integration doesn't like this
  95. // // XML data in the Assert.That statement. Not sure why.
  96. // bool result = (serialized == preSerialized);
  97. // Assert.That(result, "result of Serialize LandData does not match expected result");
  98. //
  99. // string serializedWithParcelAccessList = LandDataSerializer.Serialize(this.landWithParcelAccessList).Replace("\r\n", "\n");
  100. // Assert.That(serializedWithParcelAccessList.Length > 0,
  101. // "Serialize(LandData) returned empty string for LandData object with ParcelAccessList");
  102. // result = (serializedWithParcelAccessList == preSerializedWithParcelAccessList);
  103. // Assert.That(result,
  104. // "result of Serialize(LandData) does not match expected result (pre-serialized with parcel access list");
  105. // }
  106. /// <summary>
  107. /// Test the LandDataSerializer.Deserialize() method
  108. /// </summary>
  109. [Test]
  110. public void TestLandDataDeserializeNoAccessLists()
  111. {
  112. TestHelpers.InMethod();
  113. // log4net.Config.XmlConfigurator.Configure();
  114. Dictionary<string, object> options = new Dictionary<string, object>();
  115. LandData ld = LandDataSerializer.Deserialize(LandDataSerializer.Serialize(this.land, options));
  116. Assert.That(ld, Is.Not.Null, "Deserialize(string) returned null");
  117. // Assert.That(ld.AABBMax, Is.EqualTo(land.AABBMax));
  118. // Assert.That(ld.AABBMin, Is.EqualTo(land.AABBMin));
  119. Assert.That(ld.Area, Is.EqualTo(land.Area));
  120. Assert.That(ld.AuctionID, Is.EqualTo(land.AuctionID));
  121. Assert.That(ld.AuthBuyerID, Is.EqualTo(land.AuthBuyerID));
  122. Assert.That(ld.Category, Is.EqualTo(land.Category));
  123. Assert.That(ld.ClaimDate, Is.EqualTo(land.ClaimDate));
  124. Assert.That(ld.ClaimPrice, Is.EqualTo(land.ClaimPrice));
  125. Assert.That(ld.GlobalID, Is.EqualTo(land.GlobalID), "Reified LandData.GlobalID != original LandData.GlobalID");
  126. Assert.That(ld.GroupID, Is.EqualTo(land.GroupID));
  127. Assert.That(ld.Description, Is.EqualTo(land.Description));
  128. Assert.That(ld.Flags, Is.EqualTo(land.Flags));
  129. Assert.That(ld.LandingType, Is.EqualTo(land.LandingType));
  130. Assert.That(ld.Name, Is.EqualTo(land.Name), "Reified LandData.Name != original LandData.Name");
  131. Assert.That(ld.Status, Is.EqualTo(land.Status));
  132. Assert.That(ld.LocalID, Is.EqualTo(land.LocalID));
  133. Assert.That(ld.MediaAutoScale, Is.EqualTo(land.MediaAutoScale));
  134. Assert.That(ld.MediaID, Is.EqualTo(land.MediaID));
  135. Assert.That(ld.MediaURL, Is.EqualTo(land.MediaURL));
  136. Assert.That(ld.OwnerID, Is.EqualTo(land.OwnerID));
  137. }
  138. [Test]
  139. public void TestLandDataDeserializeWithAccessLists()
  140. {
  141. TestHelpers.InMethod();
  142. // log4net.Config.XmlConfigurator.Configure();
  143. LandData ld = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerializedWithParcelAccessList);
  144. Assert.That(ld != null,
  145. "Deserialize(string) returned null (pre-serialized with parcel access list)");
  146. Assert.That(ld.GlobalID == this.landWithParcelAccessList.GlobalID,
  147. "Reified LandData.GlobalID != original LandData.GlobalID (pre-serialized with parcel access list)");
  148. Assert.That(ld.Name == this.landWithParcelAccessList.Name,
  149. "Reified LandData.Name != original LandData.Name (pre-serialized with parcel access list)");
  150. Assert.That(ld.ParcelAccessList.Count, Is.EqualTo(2));
  151. Assert.That(ld.ParcelAccessList[0].AgentID, Is.EqualTo(UUID.Parse("62d65d45-c91a-4f77-862c-46557d978b6c")));
  152. }
  153. }
  154. }