From 05da73c300b8ed2105febb8de8f2d302b8dbe599 Mon Sep 17 00:00:00 2001 From: dr scofield (aka dirk husemann) Date: Thu, 1 Oct 2009 12:01:41 +0200 Subject: fixing LandDataSerializer (yeah! for testcases) --- .../Serialization/External/LandDataSerializer.cs | 36 +++++++++++++--------- .../Serialization/Tests/LandDataSerializerTests.cs | 12 +++++--- 2 files changed, 29 insertions(+), 19 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs index e9af2ca..e980945 100644 --- a/OpenSim/Framework/Serialization/External/LandDataSerializer.cs +++ b/OpenSim/Framework/Serialization/External/LandDataSerializer.cs @@ -91,20 +91,26 @@ namespace OpenSim.Framework.Serialization.External landData.OwnerID = UUID.Parse( xtr.ReadElementString("OwnerID")); landData.ParcelAccessList = new List(); - xtr.ReadStartElement("ParcelAccessList"); - while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) - { - ParcelManager.ParcelAccessEntry pae; + xtr.Read(); + if (xtr.Name != "ParcelAccessList") + throw new XmlException(String.Format("Expected \"ParcelAccessList\" element but got \"{0}\"", xtr.Name)); - xtr.ReadStartElement("ParcelAccessEntry"); - pae.AgentID = UUID.Parse( xtr.ReadElementString("AgentID")); - pae.Time = Convert.ToDateTime( xtr.ReadElementString("Time")); - pae.Flags = (AccessList)Convert.ToUInt32( xtr.ReadElementString("AccessList")); - xtr.ReadEndElement(); + if (!xtr.IsEmptyElement) + { + while (xtr.Read() && xtr.NodeType != XmlNodeType.EndElement) + { + ParcelManager.ParcelAccessEntry pae; - landData.ParcelAccessList.Add(pae); + xtr.ReadStartElement("ParcelAccessEntry"); + pae.AgentID = UUID.Parse( xtr.ReadElementString("AgentID")); + pae.Time = Convert.ToDateTime( xtr.ReadElementString("Time")); + pae.Flags = (AccessList)Convert.ToUInt32( xtr.ReadElementString("AccessList")); + xtr.ReadEndElement(); + + landData.ParcelAccessList.Add(pae); + } } - xtr.ReadEndElement(); + xtr.Read(); landData.PassHours = Convert.ToSingle( xtr.ReadElementString("PassHours")); landData.PassPrice = Convert.ToInt32( xtr.ReadElementString("PassPrice")); @@ -135,7 +141,7 @@ namespace OpenSim.Framework.Serialization.External xtw.WriteElementString("Area", Convert.ToString(landData.Area)); xtw.WriteElementString("AuctionID", Convert.ToString(landData.AuctionID)); xtw.WriteElementString("AuthBuyerID", landData.AuthBuyerID.ToString()); - xtw.WriteElementString("Category", Convert.ToString(landData.Category)); + xtw.WriteElementString("Category", Convert.ToString((sbyte)landData.Category)); xtw.WriteElementString("ClaimDate", Convert.ToString(landData.ClaimDate)); xtw.WriteElementString("ClaimPrice", Convert.ToString(landData.ClaimPrice)); xtw.WriteElementString("GlobalID", landData.GlobalID.ToString()); @@ -143,10 +149,10 @@ namespace OpenSim.Framework.Serialization.External xtw.WriteElementString("IsGroupOwned", Convert.ToString(landData.IsGroupOwned)); xtw.WriteElementString("Bitmap", Convert.ToBase64String(landData.Bitmap)); xtw.WriteElementString("Description", landData.Description); - xtw.WriteElementString("Flags", Convert.ToString(landData.Flags)); - xtw.WriteElementString("LandingType", Convert.ToString(landData.LandingType)); + xtw.WriteElementString("Flags", Convert.ToString((uint)landData.Flags)); + xtw.WriteElementString("LandingType", Convert.ToString((byte)landData.LandingType)); xtw.WriteElementString("Name", landData.Name); - xtw.WriteElementString("Status", Convert.ToString(landData.Status)); + xtw.WriteElementString("Status", Convert.ToString((sbyte)landData.Status)); xtw.WriteElementString("LocalID", landData.LocalID.ToString()); xtw.WriteElementString("MediaAutoScale", Convert.ToString(landData.MediaAutoScale)); xtw.WriteElementString("MediaID", landData.MediaID.ToString()); diff --git a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs index d0e3fc8..06ec047 100644 --- a/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs +++ b/OpenSim/Framework/Serialization/Tests/LandDataSerializerTests.cs @@ -39,7 +39,7 @@ namespace OpenSim.Framework.Serialization.Tests public class LandDataSerializerTest { private LandData land; - private string preSerialized = "\n\n 128\n 0\n 00000000-0000-0000-0000-000000000000\n Residential\n 0\n 0\n 54ff9641-dd40-4a2c-b1f1-47dd3af24e50\n d740204e-bbbf-44aa-949d-02c7d739f6a5\n False\n AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\n land data to test LandDataSerializer\n 536870944\n 2\n LandDataSerializerTest Land\n Leased\n 0\n 1\n d4452578-2f25-4b97-a81b-819af559cfd7\n http://videos.opensimulator.org/bumblebee.mp4\n \n 1b8eedf9-6d15-448b-8015-24286f1756bf\n \n 0\n 0\n 0\n 00000000-0000-0000-0000-000000000000\n <0, 0, 0>\n <0, 0, 0>\n 0\n 0\n"; + private string preSerialized = "\n\n 128\n 0\n 00000000-0000-0000-0000-000000000000\n 10\n 0\n 0\n 54ff9641-dd40-4a2c-b1f1-47dd3af24e50\n d740204e-bbbf-44aa-949d-02c7d739f6a5\n False\n AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\n land data to test LandDataSerializer\n 536870944\n 2\n LandDataSerializerTest Land\n 0\n 0\n 1\n d4452578-2f25-4b97-a81b-819af559cfd7\n http://videos.opensimulator.org/bumblebee.mp4\n \n 1b8eedf9-6d15-448b-8015-24286f1756bf\n \n 0\n 0\n 0\n 00000000-0000-0000-0000-000000000000\n <0, 0, 0>\n <0, 0, 0>\n 0\n 0\n"; [SetUp] public void setup() @@ -75,15 +75,19 @@ namespace OpenSim.Framework.Serialization.Tests public void LandDataSerializerSerializeTest() { string serialized = LandDataSerializer.Serialize(this.land); - Assert.That(serialized.Length > 0); - Assert.That(serialized == this.preSerialized); + Assert.That(serialized.Length > 0, "Serialize(LandData) returned empty string"); + Assert.That(serialized == this.preSerialized, "result of Serialize(LandData) does not match expected result"); } /// /// [Test] - public void TestLandDataSerializerDeserializeTest() + public void TestLandDataSerializerDeserializeFromStringTest() { + LandData reifiedLandData = LandDataSerializer.Deserialize(this.preSerialized); + Assert.That(reifiedLandData != null, "Deserialize(string) returned null"); + Assert.That(reifiedLandData.GlobalID == this.land.GlobalID, "Reified LandData.GlobalID != original LandData.GlobalID"); + Assert.That(reifiedLandData.Name == this.land.Name, "Reified LandData.Name != original LandData.Name"); } } } -- cgit v1.1