1
0

LandDataSerializerTests.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. LandData ld = LandDataSerializer.Deserialize(LandDataSerializer.Serialize(this.land, null));
  115. Assert.That(ld, Is.Not.Null, "Deserialize(string) returned null");
  116. // Assert.That(ld.AABBMax, Is.EqualTo(land.AABBMax));
  117. // Assert.That(ld.AABBMin, Is.EqualTo(land.AABBMin));
  118. Assert.That(ld.Area, Is.EqualTo(land.Area));
  119. Assert.That(ld.AuctionID, Is.EqualTo(land.AuctionID));
  120. Assert.That(ld.AuthBuyerID, Is.EqualTo(land.AuthBuyerID));
  121. Assert.That(ld.Category, Is.EqualTo(land.Category));
  122. Assert.That(ld.ClaimDate, Is.EqualTo(land.ClaimDate));
  123. Assert.That(ld.ClaimPrice, Is.EqualTo(land.ClaimPrice));
  124. Assert.That(ld.GlobalID, Is.EqualTo(land.GlobalID), "Reified LandData.GlobalID != original LandData.GlobalID");
  125. Assert.That(ld.GroupID, Is.EqualTo(land.GroupID));
  126. Assert.That(ld.Description, Is.EqualTo(land.Description));
  127. Assert.That(ld.Flags, Is.EqualTo(land.Flags));
  128. Assert.That(ld.LandingType, Is.EqualTo(land.LandingType));
  129. Assert.That(ld.Name, Is.EqualTo(land.Name), "Reified LandData.Name != original LandData.Name");
  130. Assert.That(ld.Status, Is.EqualTo(land.Status));
  131. Assert.That(ld.LocalID, Is.EqualTo(land.LocalID));
  132. Assert.That(ld.MediaAutoScale, Is.EqualTo(land.MediaAutoScale));
  133. Assert.That(ld.MediaID, Is.EqualTo(land.MediaID));
  134. Assert.That(ld.MediaURL, Is.EqualTo(land.MediaURL));
  135. Assert.That(ld.OwnerID, Is.EqualTo(land.OwnerID));
  136. }
  137. [Test]
  138. public void TestLandDataDeserializeWithAccessLists()
  139. {
  140. TestHelpers.InMethod();
  141. // log4net.Config.XmlConfigurator.Configure();
  142. LandData ld = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerializedWithParcelAccessList);
  143. Assert.That(ld != null,
  144. "Deserialize(string) returned null (pre-serialized with parcel access list)");
  145. Assert.That(ld.GlobalID == this.landWithParcelAccessList.GlobalID,
  146. "Reified LandData.GlobalID != original LandData.GlobalID (pre-serialized with parcel access list)");
  147. Assert.That(ld.Name == this.landWithParcelAccessList.Name,
  148. "Reified LandData.Name != original LandData.Name (pre-serialized with parcel access list)");
  149. Assert.That(ld.ParcelAccessList.Count, Is.EqualTo(2));
  150. Assert.That(ld.ParcelAccessList[0].AgentID, Is.EqualTo(UUID.Parse("62d65d45-c91a-4f77-862c-46557d978b6c")));
  151. }
  152. }
  153. }