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