LandDataSerializerTests.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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
  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 = "<?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>";
  44. [SetUp]
  45. public void setup()
  46. {
  47. // setup LandData object
  48. this.land = new LandData();
  49. this.land.AABBMax = new Vector3(0, 0, 0);
  50. this.land.AABBMin = new Vector3(128, 128, 128);
  51. this.land.Area = 128;
  52. this.land.AuctionID = 0;
  53. this.land.AuthBuyerID = new UUID();
  54. this.land.Category = ParcelCategory.Residential;
  55. this.land.ClaimDate = 0;
  56. this.land.ClaimPrice = 0;
  57. this.land.GlobalID = new UUID("54ff9641-dd40-4a2c-b1f1-47dd3af24e50");
  58. this.land.GroupID = new UUID("d740204e-bbbf-44aa-949d-02c7d739f6a5");
  59. this.land.Description = "land data to test LandDataSerializer";
  60. this.land.Flags = (uint)(ParcelFlags.AllowDamage | ParcelFlags.AllowVoiceChat);
  61. this.land.LandingType = (byte)LandingType.Direct;
  62. this.land.Name = "LandDataSerializerTest Land";
  63. this.land.Status = ParcelStatus.Leased;
  64. this.land.LocalID = 0;
  65. this.land.MediaAutoScale = (byte)0x01;
  66. this.land.MediaID = new UUID("d4452578-2f25-4b97-a81b-819af559cfd7");
  67. this.land.MediaURL = "http://videos.opensimulator.org/bumblebee.mp4";
  68. this.land.OwnerID = new UUID("1b8eedf9-6d15-448b-8015-24286f1756bf");
  69. this.landWithParcelAccessList = this.land.Copy();
  70. this.landWithParcelAccessList.ParcelAccessList.Clear();
  71. LandAccessEntry pae0 = new LandAccessEntry();
  72. pae0.AgentID = new UUID("62d65d45-c91a-4f77-862c-46557d978b6c");
  73. pae0.Flags = AccessList.Ban;
  74. pae0.Expires = 0;
  75. this.landWithParcelAccessList.ParcelAccessList.Add(pae0);
  76. LandAccessEntry pae1 = new LandAccessEntry();
  77. pae1.AgentID = new UUID("ec2a8d18-2378-4fe0-8b68-2a31b57c481e");
  78. pae1.Flags = AccessList.Access;
  79. pae1.Expires = 0;
  80. this.landWithParcelAccessList.ParcelAccessList.Add(pae1);
  81. }
  82. /// <summary>
  83. /// Test the LandDataSerializer.Serialize() method
  84. /// </summary>
  85. [Test]
  86. public void LandDataSerializerSerializeTest()
  87. {
  88. TestHelpers.InMethod();
  89. string serialized = LandDataSerializer.Serialize(this.land).Replace("\r\n", "\n");
  90. Assert.That(serialized.Length > 0, "Serialize(LandData) returned empty string");
  91. // adding a simple boolean variable because resharper nUnit integration doesn't like this
  92. // XML data in the Assert.That statement. Not sure why.
  93. bool result = (serialized == preSerialized);
  94. Assert.That(result, "result of Serialize LandData does not match expected result");
  95. string serializedWithParcelAccessList = LandDataSerializer.Serialize(this.landWithParcelAccessList).Replace("\r\n", "\n");
  96. Assert.That(serializedWithParcelAccessList.Length > 0,
  97. "Serialize(LandData) returned empty string for LandData object with ParcelAccessList");
  98. result = (serializedWithParcelAccessList == preSerializedWithParcelAccessList);
  99. Assert.That(result,
  100. "result of Serialize(LandData) does not match expected result (pre-serialized with parcel access list");
  101. }
  102. /// <summary>
  103. /// Test the LandDataSerializer.Deserialize() method
  104. /// </summary>
  105. [Test]
  106. public void TestLandDataDeserializeNoAccessLists()
  107. {
  108. TestHelpers.InMethod();
  109. // log4net.Config.XmlConfigurator.Configure();
  110. LandData ld = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerialized);
  111. Assert.That(ld != null, "Deserialize(string) returned null");
  112. Assert.That(ld.GlobalID == this.land.GlobalID, "Reified LandData.GlobalID != original LandData.GlobalID");
  113. Assert.That(ld.Name == this.land.Name, "Reified LandData.Name != original LandData.Name");
  114. }
  115. [Test]
  116. public void TestLandDataDeserializeWithAccessLists()
  117. {
  118. TestHelpers.InMethod();
  119. // log4net.Config.XmlConfigurator.Configure();
  120. LandData ld = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerializedWithParcelAccessList);
  121. Assert.That(ld != null,
  122. "Deserialize(string) returned null (pre-serialized with parcel access list)");
  123. Assert.That(ld.GlobalID == this.landWithParcelAccessList.GlobalID,
  124. "Reified LandData.GlobalID != original LandData.GlobalID (pre-serialized with parcel access list)");
  125. Assert.That(ld.Name == this.landWithParcelAccessList.Name,
  126. "Reified LandData.Name != original LandData.Name (pre-serialized with parcel access list)");
  127. Assert.That(ld.ParcelAccessList.Count, Is.EqualTo(2));
  128. Assert.That(ld.ParcelAccessList[0].AgentID, Is.EqualTo(UUID.Parse("62d65d45-c91a-4f77-862c-46557d978b6c")));
  129. }
  130. }
  131. }