LandDataSerializerTests.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 OpenSim.Framework;
  30. using OpenSim.Framework.Serialization.External;
  31. using OpenMetaverse;
  32. using OpenMetaverse.StructuredData;
  33. using NUnit.Framework;
  34. namespace OpenSim.Framework.Serialization.Tests
  35. {
  36. [TestFixture]
  37. public class LandDataSerializerTest
  38. {
  39. private LandData land;
  40. private LandData landWithParcelAccessList;
  41. 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>";
  42. 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>2009-10-01T00:00:00</Time>\n <AccessList>2</AccessList>\n </ParcelAccessEntry>\n <ParcelAccessEntry>\n <AgentID>ec2a8d18-2378-4fe0-8b68-2a31b57c481e</AgentID>\n <Time>2010-10-20T00:00:00</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>";
  43. [SetUp]
  44. public void setup()
  45. {
  46. // setup LandData object
  47. this.land = new LandData();
  48. this.land.AABBMax = new Vector3(0, 0, 0);
  49. this.land.AABBMin = new Vector3(128, 128, 128);
  50. this.land.Area = 128;
  51. this.land.AuctionID = 0;
  52. this.land.AuthBuyerID = new UUID();
  53. this.land.Category = ParcelCategory.Residential;
  54. this.land.ClaimDate = 0;
  55. this.land.ClaimPrice = 0;
  56. this.land.GlobalID = new UUID("54ff9641-dd40-4a2c-b1f1-47dd3af24e50");
  57. this.land.GroupID = new UUID("d740204e-bbbf-44aa-949d-02c7d739f6a5");
  58. this.land.GroupPrims = 0;
  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. ParcelManager.ParcelAccessEntry pae0 = new ParcelManager.ParcelAccessEntry();
  72. pae0.AgentID = new UUID("62d65d45-c91a-4f77-862c-46557d978b6c");
  73. pae0.Flags = AccessList.Ban;
  74. pae0.Time = new DateTime(2009, 10, 01);
  75. this.landWithParcelAccessList.ParcelAccessList.Add(pae0);
  76. ParcelManager.ParcelAccessEntry pae1 = new ParcelManager.ParcelAccessEntry();
  77. pae1.AgentID = new UUID("ec2a8d18-2378-4fe0-8b68-2a31b57c481e");
  78. pae1.Flags = AccessList.Access;
  79. pae1.Time = new DateTime(2010, 10, 20);
  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. string serialized = LandDataSerializer.Serialize(this.land);
  89. Assert.That(serialized.Length > 0, "Serialize(LandData) returned empty string");
  90. Assert.That(serialized == LandDataSerializerTest.preSerialized,
  91. "result of Serialize(LandData) does not match expected result");
  92. string serializedWithParcelAccessList = LandDataSerializer.Serialize(this.landWithParcelAccessList);
  93. Assert.That(serializedWithParcelAccessList.Length > 0,
  94. "Serialize(LandData) returned empty string for LandData object with ParcelAccessList");
  95. Assert.That(serializedWithParcelAccessList == LandDataSerializerTest.preSerializedWithParcelAccessList,
  96. "result of Serialize(LandData) does not match expected result (pre-serialized with parcel access list");
  97. }
  98. /// <summary>
  99. /// Test the LandDataSerializer.Deserialize() method
  100. /// </summary>
  101. [Test]
  102. public void TestLandDataSerializerDeserializeFromStringTest()
  103. {
  104. LandData reifiedLandData = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerialized);
  105. Assert.That(reifiedLandData != null, "Deserialize(string) returned null");
  106. Assert.That(reifiedLandData.GlobalID == this.land.GlobalID, "Reified LandData.GlobalID != original LandData.GlobalID");
  107. Assert.That(reifiedLandData.Name == this.land.Name, "Reified LandData.Name != original LandData.Name");
  108. LandData reifiedLandDataWithParcelAccessList = LandDataSerializer.Deserialize(LandDataSerializerTest.preSerializedWithParcelAccessList);
  109. Assert.That(reifiedLandDataWithParcelAccessList != null,
  110. "Deserialize(string) returned null (pre-serialized with parcel access list)");
  111. Assert.That(reifiedLandDataWithParcelAccessList.GlobalID == this.landWithParcelAccessList.GlobalID,
  112. "Reified LandData.GlobalID != original LandData.GlobalID (pre-serialized with parcel access list)");
  113. Assert.That(reifiedLandDataWithParcelAccessList.Name == this.landWithParcelAccessList.Name,
  114. "Reified LandData.Name != original LandData.Name (pre-serialized with parcel access list)");
  115. }
  116. }
  117. }