From 2b630470b064bc4d0fe84210839409f3c7bf5823 Mon Sep 17 00:00:00 2001 From: Jeff Ames Date: Sun, 16 Aug 2009 17:30:13 +0900 Subject: Add copyright headers. Formatting cleanup. --- OpenSim/Data/Tests/PropertyCompareConstraint.cs | 29 ++++++++++++++++++++++- OpenSim/Data/Tests/ScrambleForTesting.cs | 31 +++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 3 deletions(-) (limited to 'OpenSim/Data/Tests') diff --git a/OpenSim/Data/Tests/PropertyCompareConstraint.cs b/OpenSim/Data/Tests/PropertyCompareConstraint.cs index 678501e..063267b 100644 --- a/OpenSim/Data/Tests/PropertyCompareConstraint.cs +++ b/OpenSim/Data/Tests/PropertyCompareConstraint.cs @@ -1,3 +1,30 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + using System; using System.Collections; using System.Collections.Generic; @@ -52,7 +79,7 @@ namespace OpenSim.Data.Tests return false; } - if(actual.GetType() == typeof(Color)) + if (actual.GetType() == typeof(Color)) { Color actualColor = (Color) actual; Color expectedColor = (Color) expected; diff --git a/OpenSim/Data/Tests/ScrambleForTesting.cs b/OpenSim/Data/Tests/ScrambleForTesting.cs index c6e467f..3a22347 100644 --- a/OpenSim/Data/Tests/ScrambleForTesting.cs +++ b/OpenSim/Data/Tests/ScrambleForTesting.cs @@ -1,3 +1,30 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + using System; using System.Collections; using System.Reflection; @@ -18,7 +45,7 @@ namespace OpenSim.Data.Tests { //Skip indexers of classes. We will assume that everything that has an indexer // is also IEnumberable. May not always be true, but should be true normally. - if(property.GetIndexParameters().Length > 0) + if (property.GetIndexParameters().Length > 0) continue; RandomizeProperty(obj, property, null); @@ -26,7 +53,7 @@ namespace OpenSim.Data.Tests //Now if it implments IEnumberable, it's probably some kind of list, so we should randomize // everything inside of it. IEnumerable enumerable = obj as IEnumerable; - if(enumerable != null) + if (enumerable != null) { foreach (object value in enumerable) { -- cgit v1.1 From 23d478f2fa06d1dedabfb24cf6ff763b586173ce Mon Sep 17 00:00:00 2001 From: Kunnis Date: Sun, 9 Aug 2009 02:01:21 -0500 Subject: Adding in Reflection-based testing, to ensure that all properties are covered. --- OpenSim/Data/Tests/BasicAssetTest.cs | 19 +++++--- OpenSim/Data/Tests/BasicEstateTest.cs | 18 ++++++++ OpenSim/Data/Tests/BasicGridTest.cs | 79 ++++++-------------------------- OpenSim/Data/Tests/BasicInventoryTest.cs | 37 ++++++++++----- OpenSim/Data/Tests/BasicRegionTest.cs | 47 +++++++++++++++++++ OpenSim/Data/Tests/BasicUserTest.cs | 30 +++++++++--- 6 files changed, 140 insertions(+), 90 deletions(-) (limited to 'OpenSim/Data/Tests') diff --git a/OpenSim/Data/Tests/BasicAssetTest.cs b/OpenSim/Data/Tests/BasicAssetTest.cs index e85a6a7..eddb999 100644 --- a/OpenSim/Data/Tests/BasicAssetTest.cs +++ b/OpenSim/Data/Tests/BasicAssetTest.cs @@ -32,7 +32,6 @@ using NUnit.Framework.SyntaxHelpers; using OpenMetaverse; using OpenSim.Framework; using log4net; -using System.Reflection; namespace OpenSim.Data.Tests { @@ -77,25 +76,31 @@ namespace OpenSim.Data.Tests AssetBase a1 = new AssetBase(uuid1, "asset one"); AssetBase a2 = new AssetBase(uuid2, "asset two"); AssetBase a3 = new AssetBase(uuid3, "asset three"); + + ScrambleForTesting.Scramble(a1); + ScrambleForTesting.Scramble(a2); + ScrambleForTesting.Scramble(a3); + a1.Data = asset1; a2.Data = asset1; a3.Data = asset1; + a1.FullID = uuid1; + a2.FullID = uuid2; + a3.FullID = uuid3; + db.CreateAsset(a1); db.CreateAsset(a2); db.CreateAsset(a3); AssetBase a1a = db.FetchAsset(uuid1); - Assert.That(a1.ID, Is.EqualTo(a1a.ID), "Assert.That(a1.ID, Is.EqualTo(a1a.ID))"); - Assert.That(a1.Name, Is.EqualTo(a1a.Name), "Assert.That(a1.Name, Is.EqualTo(a1a.Name))"); + Assert.That(a1, Constraints.PropertyCompareConstraint(a1a)); AssetBase a2a = db.FetchAsset(uuid2); - Assert.That(a2.ID, Is.EqualTo(a2a.ID), "Assert.That(a2.ID, Is.EqualTo(a2a.ID))"); - Assert.That(a2.Name, Is.EqualTo(a2a.Name), "Assert.That(a2.Name, Is.EqualTo(a2a.Name))"); + Assert.That(a2, Constraints.PropertyCompareConstraint(a2a)); AssetBase a3a = db.FetchAsset(uuid3); - Assert.That(a3.ID, Is.EqualTo(a3a.ID), "Assert.That(a3.ID, Is.EqualTo(a3a.ID))"); - Assert.That(a3.Name, Is.EqualTo(a3a.Name), "Assert.That(a3.Name, Is.EqualTo(a3a.Name))"); + Assert.That(a3, Constraints.PropertyCompareConstraint(a3a)); } [Test] diff --git a/OpenSim/Data/Tests/BasicEstateTest.cs b/OpenSim/Data/Tests/BasicEstateTest.cs index a0266b3..b702e2a 100644 --- a/OpenSim/Data/Tests/BasicEstateTest.cs +++ b/OpenSim/Data/Tests/BasicEstateTest.cs @@ -163,6 +163,24 @@ namespace OpenSim.Data.Tests } [Test] + private void T012_EstateSettingsRandomStorage() + { + + // Letting estate store generate rows to database for us + EstateSettings originalSettings = db.LoadEstateSettings(REGION_ID); + ScrambleForTesting.Scramble(originalSettings); + + // Saving settings. + db.StoreEstateSettings(originalSettings); + + // Loading settings to another instance variable. + EstateSettings loadedSettings = db.LoadEstateSettings(REGION_ID); + + // Checking that loaded values are correct. + Assert.That(loadedSettings, Constraints.PropertyCompareConstraint(originalSettings)); + } + + [Test] public void T020_EstateSettingsManagerList() { // Letting estate store generate rows to database for us diff --git a/OpenSim/Data/Tests/BasicGridTest.cs b/OpenSim/Data/Tests/BasicGridTest.cs index 85273c5..b0ee4a0 100644 --- a/OpenSim/Data/Tests/BasicGridTest.cs +++ b/OpenSim/Data/Tests/BasicGridTest.cs @@ -49,9 +49,13 @@ namespace OpenSim.Data.Tests public void removeAllRegions() { // Clean up all the regions. - foreach (RegionProfileData region in db.GetRegionsByName("", 100)) + List regions = db.GetRegionsByName("", 100); + if(regions != null) { - db.DeleteProfile(region.Uuid.ToString()); + foreach (RegionProfileData region in regions) + { + db.DeleteProfile(region.Uuid.ToString()); + } } } @@ -74,35 +78,9 @@ namespace OpenSim.Data.Tests protected RegionProfileData createRegion(UUID regionUUID, string regionName) { RegionProfileData reg = new RegionProfileData(); + ScrambleForTesting.Scramble(reg); reg.Uuid = regionUUID; reg.RegionName = regionName; - reg.RegionHandle = (ulong) random.Next(); - reg.RegionLocX = (uint) random.Next(); - reg.RegionLocY = (uint) random.Next(); - reg.RegionLocZ = (uint) random.Next(); - reg.RegionSendKey = RandomName(); - reg.RegionRecvKey = RandomName(); - reg.RegionSecret = RandomName(); - reg.RegionOnline = false; - reg.ServerIP = RandomName(); - reg.ServerPort = (uint) random.Next(); - reg.ServerURI = RandomName(); - reg.ServerHttpPort = (uint) random.Next(); - reg.ServerRemotingPort = (uint) random.Next(); - reg.NorthOverrideHandle = (ulong) random.Next(); - reg.SouthOverrideHandle = (ulong) random.Next(); - reg.EastOverrideHandle = (ulong) random.Next(); - reg.WestOverrideHandle = (ulong) random.Next(); - reg.RegionDataURI = RandomName(); - reg.RegionAssetURI = RandomName(); - reg.RegionAssetSendKey = RandomName(); - reg.RegionAssetRecvKey = RandomName(); - reg.RegionUserURI = RandomName(); - reg.RegionUserSendKey = RandomName(); - reg.RegionUserRecvKey = RandomName(); - reg.RegionMapTextureID = UUID.Random(); - reg.Owner_uuid = UUID.Random(); - reg.OriginUUID = UUID.Random(); db.AddProfile(reg); @@ -119,47 +97,12 @@ namespace OpenSim.Data.Tests } [Test] - public void T999_StillNull() - { - Assert.That(db.GetProfileByUUID(zero),Is.Null); - } - - [Test] public void T011_AddRetrieveCompleteTest() { RegionProfileData newreg = createRegion(region2, "||"); RegionProfileData retreg = db.GetProfileByUUID(region2); - Assert.That(retreg.RegionName, Is.EqualTo(newreg.RegionName), "Assert.That(retreg.RegionName, Is.EqualTo(newreg.RegionName))"); - Assert.That(retreg.Uuid, Is.EqualTo(region2), "Assert.That(retreg.Uuid, Is.EqualTo(region2))"); - Assert.That(retreg.RegionHandle, Is.EqualTo(newreg.RegionHandle), "Assert.That(retreg.RegionHandle, Is.EqualTo(newreg.RegionHandle))"); - Assert.That(retreg.RegionLocX, Is.EqualTo(newreg.RegionLocX), "Assert.That(retreg.RegionLocX, Is.EqualTo(newreg.RegionLocX))"); - Assert.That(retreg.RegionLocY, Is.EqualTo(newreg.RegionLocY), "Assert.That(retreg.RegionLocY, Is.EqualTo(newreg.RegionLocY))"); - Assert.That(retreg.RegionLocZ, Is.EqualTo(newreg.RegionLocZ), "Assert.That(retreg.RegionLocZ, Is.EqualTo(newreg.RegionLocZ))"); - Assert.That(retreg.RegionSendKey, Is.EqualTo(newreg.RegionSendKey), "Assert.That(retreg.RegionSendKey, Is.EqualTo(newreg.RegionSendKey))"); - Assert.That(retreg.RegionRecvKey, Is.EqualTo(newreg.RegionRecvKey), "Assert.That(retreg.RegionRecvKey, Is.EqualTo(newreg.RegionRecvKey))"); - Assert.That(retreg.RegionSecret, Is.EqualTo(newreg.RegionSecret), "Assert.That(retreg.RegionSecret, Is.EqualTo(newreg.RegionSecret))"); - Assert.That(retreg.RegionOnline, Is.EqualTo(newreg.RegionOnline), "Assert.That(retreg.RegionOnline, Is.EqualTo(newreg.RegionOnline))"); - Assert.That(retreg.OriginUUID, Is.EqualTo(newreg.OriginUUID), "Assert.That(retreg.OriginUUID, Is.EqualTo(newreg.OriginUUID))"); - Assert.That(retreg.ServerIP, Is.EqualTo(newreg.ServerIP), "Assert.That(retreg.ServerIP, Is.EqualTo(newreg.ServerIP))"); - Assert.That(retreg.ServerPort, Is.EqualTo(newreg.ServerPort), "Assert.That(retreg.ServerPort, Is.EqualTo(newreg.ServerPort))"); - Assert.That(retreg.ServerURI, Is.EqualTo(newreg.ServerURI), "Assert.That(retreg.ServerURI, Is.EqualTo(newreg.ServerURI))"); - Assert.That(retreg.ServerHttpPort, Is.EqualTo(newreg.ServerHttpPort), "Assert.That(retreg.ServerHttpPort, Is.EqualTo(newreg.ServerHttpPort))"); - Assert.That(retreg.ServerRemotingPort, Is.EqualTo(newreg.ServerRemotingPort), "Assert.That(retreg.ServerRemotingPort, Is.EqualTo(newreg.ServerRemotingPort))"); - Assert.That(retreg.NorthOverrideHandle, Is.EqualTo(newreg.NorthOverrideHandle), "Assert.That(retreg.NorthOverrideHandle, Is.EqualTo(newreg.NorthOverrideHandle))"); - Assert.That(retreg.SouthOverrideHandle, Is.EqualTo(newreg.SouthOverrideHandle), "Assert.That(retreg.SouthOverrideHandle, Is.EqualTo(newreg.SouthOverrideHandle))"); - Assert.That(retreg.EastOverrideHandle, Is.EqualTo(newreg.EastOverrideHandle), "Assert.That(retreg.EastOverrideHandle, Is.EqualTo(newreg.EastOverrideHandle))"); - Assert.That(retreg.WestOverrideHandle, Is.EqualTo(newreg.WestOverrideHandle), "Assert.That(retreg.WestOverrideHandle, Is.EqualTo(newreg.WestOverrideHandle))"); - Assert.That(retreg.RegionDataURI, Is.EqualTo(newreg.RegionDataURI), "Assert.That(retreg.RegionDataURI, Is.EqualTo(newreg.RegionDataURI))"); - Assert.That(retreg.RegionAssetURI, Is.EqualTo(newreg.RegionAssetURI), "Assert.That(retreg.RegionAssetURI, Is.EqualTo(newreg.RegionAssetURI))"); - Assert.That(retreg.RegionAssetSendKey, Is.EqualTo(newreg.RegionAssetSendKey), "Assert.That(retreg.RegionAssetSendKey, Is.EqualTo(newreg.RegionAssetSendKey))"); - Assert.That(retreg.RegionAssetRecvKey, Is.EqualTo(newreg.RegionAssetRecvKey), "Assert.That(retreg.RegionAssetRecvKey, Is.EqualTo(newreg.RegionAssetRecvKey))"); - Assert.That(retreg.RegionUserURI, Is.EqualTo(newreg.RegionUserURI), "Assert.That(retreg.RegionUserURI, Is.EqualTo(newreg.RegionUserURI))"); - Assert.That(retreg.RegionUserSendKey, Is.EqualTo(newreg.RegionUserSendKey), "Assert.That(retreg.RegionUserSendKey, Is.EqualTo(newreg.RegionUserSendKey))"); - Assert.That(retreg.RegionUserRecvKey, Is.EqualTo(newreg.RegionUserRecvKey), "Assert.That(retreg.RegionUserRecvKey, Is.EqualTo(newreg.RegionUserRecvKey))"); - Assert.That(retreg.RegionMapTextureID, Is.EqualTo(newreg.RegionMapTextureID), "Assert.That(retreg.RegionMapTextureID, Is.EqualTo(newreg.RegionMapTextureID))"); - Assert.That(retreg.Owner_uuid, Is.EqualTo(newreg.Owner_uuid), "Assert.That(retreg.Owner_uuid, Is.EqualTo(newreg.Owner_uuid))"); - Assert.That(retreg.OriginUUID, Is.EqualTo(newreg.OriginUUID), "Assert.That(retreg.OriginUUID, Is.EqualTo(newreg.OriginUUID))"); + Assert.That(retreg, Constraints.PropertyCompareConstraint(newreg).IgnoreProperty(x => x.RegionOnline)); retreg = db.GetProfileByHandle(newreg.RegionHandle); Assert.That(retreg.Uuid, Is.EqualTo(region2), "Assert.That(retreg.Uuid, Is.EqualTo(region2))"); @@ -220,6 +163,12 @@ namespace OpenSim.Data.Tests Assert.That(listreg[1].Uuid, Is.EqualTo(region1) | Is.EqualTo(region2), "Assert.That(listreg[1].Uuid, Is.EqualTo(region1) | Is.EqualTo(region2))"); } + [Test] + public void T999_StillNull() + { + Assert.That(db.GetProfileByUUID(zero), Is.Null); + } + protected static string RandomName() { StringBuilder name = new StringBuilder(); diff --git a/OpenSim/Data/Tests/BasicInventoryTest.cs b/OpenSim/Data/Tests/BasicInventoryTest.cs index e13ed89..3c33bb4 100644 --- a/OpenSim/Data/Tests/BasicInventoryTest.cs +++ b/OpenSim/Data/Tests/BasicInventoryTest.cs @@ -115,16 +115,6 @@ namespace OpenSim.Data.Tests Assert.That(db.getUserRootFolder(owner1), Is.Null); } - [Test] - public void T999_StillNull() - { - // After all tests are run, these should still return no results - Assert.That(db.getInventoryFolder(zero), Is.Null); - Assert.That(db.getInventoryItem(zero), Is.Null); - Assert.That(db.getUserRootFolder(zero), Is.Null); - Assert.That(db.getInventoryInFolder(zero).Count, Is.EqualTo(0), "Assert.That(db.getInventoryInFolder(zero).Count, Is.EqualTo(0))"); - } - // 01x - folder tests [Test] public void T010_FolderNonParent() @@ -248,7 +238,7 @@ namespace OpenSim.Data.Tests } [Test] - public void T103UpdateItem() + public void T103_UpdateItem() { // TODO: probably shouldn't have the ability to have an // owner of an item in a folder not owned by the user @@ -265,6 +255,31 @@ namespace OpenSim.Data.Tests Assert.That(i1.Owner, Is.EqualTo(owner2), "Assert.That(i1.Owner, Is.EqualTo(owner2))"); } + [Test] + public void T104_RandomUpdateItem() + { + InventoryItemBase expected = db.getInventoryItem(item1); + ScrambleForTesting.Scramble(expected); + expected.ID = item1; + db.updateInventoryItem(expected); + + InventoryItemBase actual = db.getInventoryItem(item1); + Assert.That(actual, Constraints.PropertyCompareConstraint(expected) + .IgnoreProperty(x=>x.InvType) + .IgnoreProperty(x=>x.Description) + .IgnoreProperty(x=>x.CreatorId)); + } + + [Test] + public void T999_StillNull() + { + // After all tests are run, these should still return no results + Assert.That(db.getInventoryFolder(zero), Is.Null); + Assert.That(db.getInventoryItem(zero), Is.Null); + Assert.That(db.getUserRootFolder(zero), Is.Null); + Assert.That(db.getInventoryInFolder(zero).Count, Is.EqualTo(0), "Assert.That(db.getInventoryInFolder(zero).Count, Is.EqualTo(0))"); + } + private InventoryItemBase NewItem(UUID id, UUID parent, UUID owner, string name, UUID asset) { InventoryItemBase i = new InventoryItemBase(); diff --git a/OpenSim/Data/Tests/BasicRegionTest.cs b/OpenSim/Data/Tests/BasicRegionTest.cs index 836da78..a746ef0 100644 --- a/OpenSim/Data/Tests/BasicRegionTest.cs +++ b/OpenSim/Data/Tests/BasicRegionTest.cs @@ -532,6 +532,53 @@ namespace OpenSim.Data.Tests Assert.That(cursop.Acceleration,Is.EqualTo(parts[i].Acceleration), "Assert.That(cursop.Acceleration,Is.EqualTo(parts[i].Acceleration))"); } } + + [Test] + public void T016_RandomSogWithSceneParts() + { + UUID tmpSog = UUID.Random(); + UUID tmp1 = UUID.Random(); + UUID tmp2 = UUID.Random(); + UUID tmp3 = UUID.Random(); + UUID newregion = UUID.Random(); + SceneObjectPart p1 = new SceneObjectPart(); + SceneObjectPart p2 = new SceneObjectPart(); + SceneObjectPart p3 = new SceneObjectPart(); + p1.Shape = PrimitiveBaseShape.Default; + p2.Shape = PrimitiveBaseShape.Default; + p3.Shape = PrimitiveBaseShape.Default; + ScrambleForTesting.Scramble(p1); + ScrambleForTesting.Scramble(p2); + ScrambleForTesting.Scramble(p3); + p1.UUID = tmp1; + p2.UUID = tmp2; + p3.UUID = tmp3; + SceneObjectGroup sog = NewSOG("Sop 0", tmpSog, newregion); + ScrambleForTesting.Scramble(sog); + sog.UUID = tmpSog; + sog.AddPart(p1); + sog.AddPart(p2); + sog.AddPart(p3); + + SceneObjectPart[] parts = sog.GetParts(); + Assert.That(parts.Length, Is.EqualTo(4), "Assert.That(parts.Length,Is.EqualTo(4))"); + + db.StoreObject(sog, newregion); + List sogs = db.LoadObjects(newregion); + Assert.That(sogs.Count, Is.EqualTo(1), "Assert.That(sogs.Count,Is.EqualTo(1))"); + SceneObjectGroup newsog = sogs[0]; + + SceneObjectPart[] newparts = newsog.GetParts(); + Assert.That(newparts.Length, Is.EqualTo(4), "Assert.That(newparts.Length,Is.EqualTo(4))"); + + Assert.That(newsog, Constraints.PropertyCompareConstraint(sog) + .IgnoreProperty(x=>x.LocalId) + .IgnoreProperty(x=>x.HasGroupChanged) + .IgnoreProperty(x=>x.IsSelected) + .IgnoreProperty(x=>x.RegionHandle) + .IgnoreProperty(x=>x.Scene) + .IgnoreProperty(x=>x.RootPart.InventorySerial)); + } [Test] public void T020_PrimInventoryEmpty() diff --git a/OpenSim/Data/Tests/BasicUserTest.cs b/OpenSim/Data/Tests/BasicUserTest.cs index 4e4ddc8..21d1a7e 100644 --- a/OpenSim/Data/Tests/BasicUserTest.cs +++ b/OpenSim/Data/Tests/BasicUserTest.cs @@ -118,13 +118,6 @@ namespace OpenSim.Data.Tests } [Test] - public void T999_StillNull() - { - Assert.That(db.GetUserByUUID(zero), Is.Null); - Assert.That(db.GetAgentByUUID(zero), Is.Null); - } - - [Test] public void T010_CreateUser() { UserProfileData u1 = NewUser(user1,fname1,lname1); @@ -396,6 +389,22 @@ namespace OpenSim.Data.Tests Assert.That(customtype,Is.EqualTo(u1a.CustomType), "Assert.That(customtype,Is.EqualTo(u1a.CustomType))"); Assert.That(partner,Is.EqualTo(u1a.Partner), "Assert.That(partner,Is.EqualTo(u1a.Partner))"); } + + [Test] + public void T017_UserUpdateRandomPersistency() + { + UUID id = user5; + UserProfileData u = db.GetUserByUUID(id); + ScrambleForTesting.Scramble(u); + u.ID = id; + + db.UpdateUserProfile(u); + UserProfileData u1a = db.GetUserByUUID(id); + Assert.That(u1a, Constraints.PropertyCompareConstraint(u) + .IgnoreProperty(x=>x.HomeRegionX) + .IgnoreProperty(x=>x.HomeRegionY) + ); + } [Test] public void T020_CreateAgent() @@ -660,6 +669,13 @@ namespace OpenSim.Data.Tests Assert.That(avatarheight,Is.EqualTo(app.AvatarHeight), "Assert.That(avatarheight,Is.EqualTo(app.AvatarHeight))"); } + [Test] + public void T999_StillNull() + { + Assert.That(db.GetUserByUUID(zero), Is.Null); + Assert.That(db.GetAgentByUUID(zero), Is.Null); + } + public UserProfileData NewUser(UUID id,string fname,string lname) { UserProfileData u = new UserProfileData(); -- cgit v1.1 From f6251ce810e0bebe68d08a8e4b20a9dfc3fe1af6 Mon Sep 17 00:00:00 2001 From: Kunnis Date: Sat, 15 Aug 2009 06:08:36 -0500 Subject: * Modified SQLite/SQLiteInventoryStore.cs to not throw if the inventory row does not exist, to match the mysql behavior. * Modified SQLite/SQLiteRegionData.cs to only persist temporary items following the same rules mysql uses. * Added another ignore to the inventory test that was missing. * Added a few more ignores to the RegionTest that the first version of my test were missing. * Added ignoring the root Folder ID, which is set by the inventory system. * Added several improvements to the PropertyCompareConstraint: Protection against infinite loops, added IComparable (for UUID) and moved IComparable before the property matching. * Fixed a bug where I was saving the inside of the ignore expression instead of the outside of it. --- OpenSim/Data/Tests/BasicInventoryTest.cs | 1 + OpenSim/Data/Tests/BasicRegionTest.cs | 4 +- OpenSim/Data/Tests/BasicUserTest.cs | 1 + OpenSim/Data/Tests/PropertyCompareConstraint.cs | 180 ++++++++++++++++++------ 4 files changed, 140 insertions(+), 46 deletions(-) (limited to 'OpenSim/Data/Tests') diff --git a/OpenSim/Data/Tests/BasicInventoryTest.cs b/OpenSim/Data/Tests/BasicInventoryTest.cs index 3c33bb4..967c6e7 100644 --- a/OpenSim/Data/Tests/BasicInventoryTest.cs +++ b/OpenSim/Data/Tests/BasicInventoryTest.cs @@ -266,6 +266,7 @@ namespace OpenSim.Data.Tests InventoryItemBase actual = db.getInventoryItem(item1); Assert.That(actual, Constraints.PropertyCompareConstraint(expected) .IgnoreProperty(x=>x.InvType) + .IgnoreProperty(x=>x.CreatorIdAsUuid) .IgnoreProperty(x=>x.Description) .IgnoreProperty(x=>x.CreatorId)); } diff --git a/OpenSim/Data/Tests/BasicRegionTest.cs b/OpenSim/Data/Tests/BasicRegionTest.cs index a746ef0..8373922 100644 --- a/OpenSim/Data/Tests/BasicRegionTest.cs +++ b/OpenSim/Data/Tests/BasicRegionTest.cs @@ -576,8 +576,10 @@ namespace OpenSim.Data.Tests .IgnoreProperty(x=>x.HasGroupChanged) .IgnoreProperty(x=>x.IsSelected) .IgnoreProperty(x=>x.RegionHandle) + .IgnoreProperty(x=>x.RegionUUID) .IgnoreProperty(x=>x.Scene) - .IgnoreProperty(x=>x.RootPart.InventorySerial)); + .IgnoreProperty(x=>x.Children) + .IgnoreProperty(x=>x.RootPart)); } [Test] diff --git a/OpenSim/Data/Tests/BasicUserTest.cs b/OpenSim/Data/Tests/BasicUserTest.cs index 21d1a7e..a3c125d 100644 --- a/OpenSim/Data/Tests/BasicUserTest.cs +++ b/OpenSim/Data/Tests/BasicUserTest.cs @@ -403,6 +403,7 @@ namespace OpenSim.Data.Tests Assert.That(u1a, Constraints.PropertyCompareConstraint(u) .IgnoreProperty(x=>x.HomeRegionX) .IgnoreProperty(x=>x.HomeRegionY) + .IgnoreProperty(x=>x.RootInventoryFolderID) ); } diff --git a/OpenSim/Data/Tests/PropertyCompareConstraint.cs b/OpenSim/Data/Tests/PropertyCompareConstraint.cs index 063267b..5f53725 100644 --- a/OpenSim/Data/Tests/PropertyCompareConstraint.cs +++ b/OpenSim/Data/Tests/PropertyCompareConstraint.cs @@ -69,6 +69,15 @@ namespace OpenSim.Data.Tests private bool ObjectCompare(object expected, object actual, Stack propertyNames) { + //prevent loops... + if(propertyNames.Count > 50) + { + failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); + failingActual = actual; + failingExpected = expected; + return false; + } + if (actual.GetType() != expected.GetType()) { propertyNames.Push("GetType()"); @@ -122,6 +131,60 @@ namespace OpenSim.Data.Tests return true; } + IComparable comp = actual as IComparable; + if (comp != null) + { + if (comp.CompareTo(expected) != 0) + { + failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); + failingActual = actual; + failingExpected = expected; + return false; + } + return true; + } + + //Now try the much more annoying IComparable + Type icomparableInterface = actual.GetType().GetInterface("IComparable`1"); + if (icomparableInterface != null) + { + int result = (int)icomparableInterface.GetMethod("CompareTo").Invoke(actual, new[] { expected }); + if (result != 0) + { + failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); + failingActual = actual; + failingExpected = expected; + return false; + } + return true; + } + + IEnumerable arr = actual as IEnumerable; + if (arr != null) + { + List actualList = arr.Cast().ToList(); + List expectedList = ((IEnumerable)expected).Cast().ToList(); + if (actualList.Count != expectedList.Count) + { + propertyNames.Push("Count"); + failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); + failingActual = actualList.Count; + failingExpected = expectedList.Count; + propertyNames.Pop(); + return false; + } + //actualList and expectedList should be the same size. + for (int i = 0; i < actualList.Count; i++) + { + propertyNames.Push("[" + i + "]"); + if (!ObjectCompare(expectedList[i], actualList[i], propertyNames)) + return false; + propertyNames.Pop(); + } + //Everything seems okay... + return true; + } + //Skip static properties. I had a nasty problem comparing colors because of all of the public static colors. PropertyInfo[] properties = expected.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (var property in properties) @@ -147,41 +210,6 @@ namespace OpenSim.Data.Tests return false; } - IComparable comp = actualValue as IComparable; - if (comp != null) - { - if (comp.CompareTo(expectedValue) != 0) - { - propertyNames.Push(property.Name); - failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); - propertyNames.Pop(); - failingActual = actualValue; - failingExpected = expectedValue; - return false; - } - continue; - } - - IEnumerable arr = actualValue as IEnumerable; - if (arr != null) - { - List actualList = arr.Cast().ToList(); - List expectedList = ((IEnumerable)expectedValue).Cast().ToList(); - if (actualList.Count != expectedList.Count) - { - propertyNames.Push(property.Name); - propertyNames.Push("Count"); - failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); - failingActual = actualList.Count; - failingExpected = expectedList.Count; - propertyNames.Pop(); - propertyNames.Pop(); - } - //Todo: A value-wise comparison of all of the values. - //Everything seems okay... - continue; - } - propertyNames.Push(property.Name); if (!ObjectCompare(expectedValue, actualValue, propertyNames)) return false; @@ -223,15 +251,7 @@ namespace OpenSim.Data.Tests { //If the inside of the lambda is the access to x, we've hit the end of the chain. // We should track by the fully scoped parameter name, but this is the first rev of doing this. - if (((MemberExpression)express).Expression is ParameterExpression) - { - ignores.Add(((MemberExpression)express).Member.Name); - } - else - { - //Otherwise there could be more parameters inside... - PullApartExpression(((MemberExpression)express).Expression); - } + ignores.Add(((MemberExpression)express).Member.Name); } } } @@ -270,7 +290,7 @@ namespace OpenSim.Data.Tests { HasInt actual = new HasInt { TheValue = 5 }; HasInt expected = new HasInt { TheValue = 4 }; - var constraint = Constraints.PropertyCompareConstraint(expected).IgnoreProperty(x=>x.TheValue); + var constraint = Constraints.PropertyCompareConstraint(expected).IgnoreProperty(x => x.TheValue); Assert.That(constraint.Matches(actual), Is.True); } @@ -312,6 +332,28 @@ namespace OpenSim.Data.Tests } [Test] + public void UUIDShouldMatch() + { + UUID uuid1 = UUID.Random(); + UUID uuid2 = UUID.Parse(uuid1.ToString()); + + var constraint = Constraints.PropertyCompareConstraint(uuid1); + + Assert.That(constraint.Matches(uuid2), Is.True); + } + + [Test] + public void UUIDShouldNotMatch() + { + UUID uuid1 = UUID.Random(); + UUID uuid2 = UUID.Random(); + + var constraint = Constraints.PropertyCompareConstraint(uuid1); + + Assert.That(constraint.Matches(uuid2), Is.False); + } + + [Test] public void TestColors() { Color actual = Color.Red; @@ -321,5 +363,53 @@ namespace OpenSim.Data.Tests Assert.That(constraint.Matches(actual), Is.True); } + + [Test] + public void ShouldCompareLists() + { + List expected = new List { 1, 2, 3 }; + List actual = new List { 1, 2, 3 }; + + var constraint = Constraints.PropertyCompareConstraint(expected); + Assert.That(constraint.Matches(actual), Is.True); + } + + + [Test] + public void ShouldFailToCompareListsThatAreDifferent() + { + List expected = new List { 1, 2, 3 }; + List actual = new List { 1, 2, 4 }; + + var constraint = Constraints.PropertyCompareConstraint(expected); + Assert.That(constraint.Matches(actual), Is.False); + } + + [Test] + public void ShouldFailToCompareListsThatAreDifferentLengths() + { + List expected = new List { 1, 2, 3 }; + List actual = new List { 1, 2 }; + + var constraint = Constraints.PropertyCompareConstraint(expected); + Assert.That(constraint.Matches(actual), Is.False); + } + + public class Recursive + { + public Recursive Other { get; set; } + } + + [Test] + public void ErrorsOutOnRecursive() + { + Recursive parent = new Recursive(); + Recursive child = new Recursive(); + parent.Other = child; + child.Other = parent; + + var constraint = Constraints.PropertyCompareConstraint(child); + Assert.That(constraint.Matches(child), Is.False); + } } } \ No newline at end of file -- cgit v1.1 From d2e5380cb2325ad42917c528c52a8ad42ec0176f Mon Sep 17 00:00:00 2001 From: Kunnis Date: Sat, 15 Aug 2009 10:54:48 -0500 Subject: * Fixed MySQL/MySQLAssetData.cs to properly do updates * Removed an extra parameter from MySQL/MySQLInventoryData.cs * Fixed a bug in SQLite/SQLiteAssetData.cs that was causing a NRE when updating an asset. * Improved the BasicAssetTest.cs to do full create/update/get testing * Improved the BasicInventoryTest.cs to do full create/update/get of both a folder and an item * Moved the null ref tests to the start of the PropertyCompareConstraint.cs, so that it doesn't throw when passing in a null item --- OpenSim/Data/Tests/BasicAssetTest.cs | 35 +++++++++++++--- OpenSim/Data/Tests/BasicInventoryTest.cs | 56 +++++++++++++++++++++---- OpenSim/Data/Tests/PropertyCompareConstraint.cs | 28 ++++++------- 3 files changed, 92 insertions(+), 27 deletions(-) (limited to 'OpenSim/Data/Tests') diff --git a/OpenSim/Data/Tests/BasicAssetTest.cs b/OpenSim/Data/Tests/BasicAssetTest.cs index eddb999..91b613a 100644 --- a/OpenSim/Data/Tests/BasicAssetTest.cs +++ b/OpenSim/Data/Tests/BasicAssetTest.cs @@ -84,7 +84,7 @@ namespace OpenSim.Data.Tests a1.Data = asset1; a2.Data = asset1; a3.Data = asset1; - + a1.FullID = uuid1; a2.FullID = uuid2; a3.FullID = uuid3; @@ -92,15 +92,40 @@ namespace OpenSim.Data.Tests db.CreateAsset(a1); db.CreateAsset(a2); db.CreateAsset(a3); - + AssetBase a1a = db.FetchAsset(uuid1); - Assert.That(a1, Constraints.PropertyCompareConstraint(a1a)); + Assert.That(a1a, Constraints.PropertyCompareConstraint(a1)); AssetBase a2a = db.FetchAsset(uuid2); - Assert.That(a2, Constraints.PropertyCompareConstraint(a2a)); + Assert.That(a2a, Constraints.PropertyCompareConstraint(a2)); AssetBase a3a = db.FetchAsset(uuid3); - Assert.That(a3, Constraints.PropertyCompareConstraint(a3a)); + Assert.That(a3a, Constraints.PropertyCompareConstraint(a3)); + + ScrambleForTesting.Scramble(a1a); + ScrambleForTesting.Scramble(a2a); + ScrambleForTesting.Scramble(a3a); + + a1a.Data = asset1; + a2a.Data = asset1; + a3a.Data = asset1; + + a1a.FullID = uuid1; + a2a.FullID = uuid2; + a3a.FullID = uuid3; + + db.UpdateAsset(a1a); + db.UpdateAsset(a2a); + db.UpdateAsset(a3a); + + AssetBase a1b = db.FetchAsset(uuid1); + Assert.That(a1b, Constraints.PropertyCompareConstraint(a1a)); + + AssetBase a2b = db.FetchAsset(uuid2); + Assert.That(a2b, Constraints.PropertyCompareConstraint(a2a)); + + AssetBase a3b = db.FetchAsset(uuid3); + Assert.That(a3b, Constraints.PropertyCompareConstraint(a3a)); } [Test] diff --git a/OpenSim/Data/Tests/BasicInventoryTest.cs b/OpenSim/Data/Tests/BasicInventoryTest.cs index 967c6e7..21552c8 100644 --- a/OpenSim/Data/Tests/BasicInventoryTest.cs +++ b/OpenSim/Data/Tests/BasicInventoryTest.cs @@ -258,17 +258,59 @@ namespace OpenSim.Data.Tests [Test] public void T104_RandomUpdateItem() { - InventoryItemBase expected = db.getInventoryItem(item1); + UUID owner = UUID.Random(); + UUID folder = UUID.Random(); + UUID rootId = UUID.Random(); + UUID rootAsset = UUID.Random(); + InventoryFolderBase f1 = NewFolder(folder, zero, owner, name1); + ScrambleForTesting.Scramble(f1); + f1.Owner = owner; + f1.ParentID = zero; + f1.ID = folder; + + // succeed with true + db.addInventoryFolder(f1); + InventoryFolderBase f1a = db.getUserRootFolder(owner); + Assert.That(f1a, Constraints.PropertyCompareConstraint(f1)); + + ScrambleForTesting.Scramble(f1a); + f1a.Owner = owner; + f1a.ParentID = zero; + f1a.ID = folder; + db.updateInventoryFolder(f1a); + + InventoryFolderBase f1b = db.getUserRootFolder(owner); + Assert.That(f1b, Constraints.PropertyCompareConstraint(f1a)); + + //Now we have a valid folder to insert into, we can insert the item. + InventoryItemBase root = NewItem(rootId, folder, owner, iname1, rootAsset); + ScrambleForTesting.Scramble(root); + root.ID = rootId; + root.AssetID = rootAsset; + root.Owner = owner; + root.Folder = folder; + db.addInventoryItem(root); + + InventoryItemBase expected = db.getInventoryItem(rootId); + Assert.That(expected, Constraints.PropertyCompareConstraint(root) + .IgnoreProperty(x => x.InvType) + .IgnoreProperty(x => x.CreatorIdAsUuid) + .IgnoreProperty(x => x.Description) + .IgnoreProperty(x => x.CreatorId)); + ScrambleForTesting.Scramble(expected); - expected.ID = item1; + expected.ID = rootId; + expected.AssetID = rootAsset; + expected.Owner = owner; + expected.Folder = folder; db.updateInventoryItem(expected); - InventoryItemBase actual = db.getInventoryItem(item1); + InventoryItemBase actual = db.getInventoryItem(rootId); Assert.That(actual, Constraints.PropertyCompareConstraint(expected) - .IgnoreProperty(x=>x.InvType) - .IgnoreProperty(x=>x.CreatorIdAsUuid) - .IgnoreProperty(x=>x.Description) - .IgnoreProperty(x=>x.CreatorId)); + .IgnoreProperty(x => x.InvType) + .IgnoreProperty(x => x.CreatorIdAsUuid) + .IgnoreProperty(x => x.Description) + .IgnoreProperty(x => x.CreatorId)); } [Test] diff --git a/OpenSim/Data/Tests/PropertyCompareConstraint.cs b/OpenSim/Data/Tests/PropertyCompareConstraint.cs index 5f53725..d64a51e 100644 --- a/OpenSim/Data/Tests/PropertyCompareConstraint.cs +++ b/OpenSim/Data/Tests/PropertyCompareConstraint.cs @@ -69,6 +69,19 @@ namespace OpenSim.Data.Tests private bool ObjectCompare(object expected, object actual, Stack propertyNames) { + //If they are both null, they are equal + if (actual == null && expected == null) + return true; + + //If only one is null, then they aren't + if (actual == null || expected == null) + { + failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); + failingActual = actual; + failingExpected = expected; + return false; + } + //prevent loops... if(propertyNames.Count > 50) { @@ -195,21 +208,6 @@ namespace OpenSim.Data.Tests object actualValue = property.GetValue(actual, null); object expectedValue = property.GetValue(expected, null); - //If they are both null, they are equal - if (actualValue == null && expectedValue == null) - continue; - - //If only one is null, then they aren't - if (actualValue == null || expectedValue == null) - { - propertyNames.Push(property.Name); - failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); - propertyNames.Pop(); - failingActual = actualValue; - failingExpected = expectedValue; - return false; - } - propertyNames.Push(property.Name); if (!ObjectCompare(expectedValue, actualValue, propertyNames)) return false; -- cgit v1.1 From 5dde4a4cfae106805b480ae4e22e2f6c79ef3fa5 Mon Sep 17 00:00:00 2001 From: Kunnis Date: Sat, 15 Aug 2009 23:43:52 -0500 Subject: * More improvements to BasicAssetTest.cs --- OpenSim/Data/Tests/BasicAssetTest.cs | 38 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 26 deletions(-) (limited to 'OpenSim/Data/Tests') diff --git a/OpenSim/Data/Tests/BasicAssetTest.cs b/OpenSim/Data/Tests/BasicAssetTest.cs index 91b613a..23041ad 100644 --- a/OpenSim/Data/Tests/BasicAssetTest.cs +++ b/OpenSim/Data/Tests/BasicAssetTest.cs @@ -26,6 +26,7 @@ */ using System; +using System.Collections.Generic; using log4net.Config; using NUnit.Framework; using NUnit.Framework.SyntaxHelpers; @@ -37,8 +38,7 @@ namespace OpenSim.Data.Tests { public class BasicAssetTest { - //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - public AssetDataBase db; + public IAssetDataPlugin db; public UUID uuid1; public UUID uuid2; public UUID uuid3; @@ -46,14 +46,7 @@ namespace OpenSim.Data.Tests public void SuperInit() { - try - { - XmlConfigurator.Configure(); - } - catch (Exception) - { - // I don't care, just leave log4net off - } + OpenSim.Tests.Common.TestLogging.LogToConsole(); uuid1 = UUID.Random(); uuid2 = UUID.Random(); @@ -126,26 +119,19 @@ namespace OpenSim.Data.Tests AssetBase a3b = db.FetchAsset(uuid3); Assert.That(a3b, Constraints.PropertyCompareConstraint(a3a)); - } - [Test] - public void T011_ExistsSimpleAsset() - { Assert.That(db.ExistsAsset(uuid1), Is.True); Assert.That(db.ExistsAsset(uuid2), Is.True); Assert.That(db.ExistsAsset(uuid3), Is.True); - } - // this has questionable use, but it is in the interface at the moment. - // [Test] - // public void T012_DeleteAsset() - // { - // db.DeleteAsset(uuid1); - // db.DeleteAsset(uuid2); - // db.DeleteAsset(uuid3); - // Assert.That(db.ExistsAsset(uuid1), Is.False); - // Assert.That(db.ExistsAsset(uuid2), Is.False); - // Assert.That(db.ExistsAsset(uuid3), Is.False); - // } + List metadatas = db.FetchAssetMetadataSet(0, 1000); + + AssetMetadata metadata = metadatas.Find(x => x.FullID == uuid1); + Assert.That(metadata.Name, Is.EqualTo(a1b.Name)); + Assert.That(metadata.Description, Is.EqualTo(a1b.Description)); + Assert.That(metadata.Type, Is.EqualTo(a1b.Type)); + Assert.That(metadata.Temporary, Is.EqualTo(a1b.Temporary)); + Assert.That(metadata.FullID, Is.EqualTo(a1b.FullID)); + } } } -- cgit v1.1 From dd78c250aed0924d06e28a826c2ad565ca232045 Mon Sep 17 00:00:00 2001 From: Kunnis Date: Sun, 16 Aug 2009 03:35:31 -0500 Subject: * Added Expression based ignores to the PropertyScrambler, which makes a lot of the tests clearer because I'm not constantly resetting properties. --- OpenSim/Data/Tests/BasicAssetTest.cs | 34 +++---- OpenSim/Data/Tests/BasicEstateTest.cs | 12 +-- OpenSim/Data/Tests/BasicGridTest.cs | 20 +--- OpenSim/Data/Tests/BasicInventoryTest.cs | 44 ++++----- OpenSim/Data/Tests/BasicRegionTest.cs | 24 ++--- OpenSim/Data/Tests/BasicUserTest.cs | 12 +-- OpenSim/Data/Tests/PropertyScrambler.cs | 159 +++++++++++++++++++++++++++++++ OpenSim/Data/Tests/ScrambleForTesting.cs | 129 ------------------------- 8 files changed, 210 insertions(+), 224 deletions(-) create mode 100644 OpenSim/Data/Tests/PropertyScrambler.cs delete mode 100644 OpenSim/Data/Tests/ScrambleForTesting.cs (limited to 'OpenSim/Data/Tests') diff --git a/OpenSim/Data/Tests/BasicAssetTest.cs b/OpenSim/Data/Tests/BasicAssetTest.cs index 23041ad..09131c1 100644 --- a/OpenSim/Data/Tests/BasicAssetTest.cs +++ b/OpenSim/Data/Tests/BasicAssetTest.cs @@ -69,18 +69,20 @@ namespace OpenSim.Data.Tests AssetBase a1 = new AssetBase(uuid1, "asset one"); AssetBase a2 = new AssetBase(uuid2, "asset two"); AssetBase a3 = new AssetBase(uuid3, "asset three"); - - ScrambleForTesting.Scramble(a1); - ScrambleForTesting.Scramble(a2); - ScrambleForTesting.Scramble(a3); - a1.Data = asset1; a2.Data = asset1; a3.Data = asset1; - - a1.FullID = uuid1; - a2.FullID = uuid2; - a3.FullID = uuid3; + + PropertyScrambler scrambler = new PropertyScrambler() + .DontScramble(x => x.Data) + .DontScramble(x => x.ID) + .DontScramble(x => x.FullID) + .DontScramble(x => x.Metadata.ID) + .DontScramble(x => x.Metadata.FullID); + + scrambler.Scramble(a1); + scrambler.Scramble(a2); + scrambler.Scramble(a3); db.CreateAsset(a1); db.CreateAsset(a2); @@ -95,17 +97,9 @@ namespace OpenSim.Data.Tests AssetBase a3a = db.FetchAsset(uuid3); Assert.That(a3a, Constraints.PropertyCompareConstraint(a3)); - ScrambleForTesting.Scramble(a1a); - ScrambleForTesting.Scramble(a2a); - ScrambleForTesting.Scramble(a3a); - - a1a.Data = asset1; - a2a.Data = asset1; - a3a.Data = asset1; - - a1a.FullID = uuid1; - a2a.FullID = uuid2; - a3a.FullID = uuid3; + scrambler.Scramble(a1a); + scrambler.Scramble(a2a); + scrambler.Scramble(a3a); db.UpdateAsset(a1a); db.UpdateAsset(a2a); diff --git a/OpenSim/Data/Tests/BasicEstateTest.cs b/OpenSim/Data/Tests/BasicEstateTest.cs index b702e2a..284d066 100644 --- a/OpenSim/Data/Tests/BasicEstateTest.cs +++ b/OpenSim/Data/Tests/BasicEstateTest.cs @@ -40,7 +40,6 @@ namespace OpenSim.Data.Tests { public class BasicEstateTest { - //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); public IEstateDataStore db; public IRegionDataStore regionDb; @@ -57,14 +56,7 @@ namespace OpenSim.Data.Tests public void SuperInit() { - try - { - XmlConfigurator.Configure(); - } - catch (Exception) - { - // I don't care, just leave log4net off - } + OpenSim.Tests.Common.TestLogging.LogToConsole(); } #region 0Tests @@ -168,7 +160,7 @@ namespace OpenSim.Data.Tests // Letting estate store generate rows to database for us EstateSettings originalSettings = db.LoadEstateSettings(REGION_ID); - ScrambleForTesting.Scramble(originalSettings); + new PropertyScrambler().Scramble(originalSettings); // Saving settings. db.StoreEstateSettings(originalSettings); diff --git a/OpenSim/Data/Tests/BasicGridTest.cs b/OpenSim/Data/Tests/BasicGridTest.cs index b0ee4a0..a25b736 100644 --- a/OpenSim/Data/Tests/BasicGridTest.cs +++ b/OpenSim/Data/Tests/BasicGridTest.cs @@ -28,22 +28,18 @@ using System; using System.Collections.Generic; using System.Text; -using log4net.Config; using NUnit.Framework; using NUnit.Framework.SyntaxHelpers; using OpenMetaverse; -using log4net; -using System.Reflection; namespace OpenSim.Data.Tests { public class BasicGridTest { - //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - public GridDataBase db; + public IGridDataPlugin db; public UUID region1, region2, region3; public UUID zero = UUID.Zero; - public static Random random; + public static Random random = new Random(); [TearDown] public void removeAllRegions() @@ -61,24 +57,16 @@ namespace OpenSim.Data.Tests public void SuperInit() { - try - { - XmlConfigurator.Configure(); - } - catch (Exception) - { - // I don't care, just leave log4net off - } + OpenSim.Tests.Common.TestLogging.LogToConsole(); region1 = UUID.Random(); region2 = UUID.Random(); region3 = UUID.Random(); - random = new Random(); } protected RegionProfileData createRegion(UUID regionUUID, string regionName) { RegionProfileData reg = new RegionProfileData(); - ScrambleForTesting.Scramble(reg); + new PropertyScrambler().Scramble(reg); reg.Uuid = regionUUID; reg.RegionName = regionName; diff --git a/OpenSim/Data/Tests/BasicInventoryTest.cs b/OpenSim/Data/Tests/BasicInventoryTest.cs index 21552c8..900186b 100644 --- a/OpenSim/Data/Tests/BasicInventoryTest.cs +++ b/OpenSim/Data/Tests/BasicInventoryTest.cs @@ -66,14 +66,7 @@ namespace OpenSim.Data.Tests public void SuperInit() { - try - { - XmlConfigurator.Configure(); - } - catch (Exception) - { - // I don't care, just leave log4net off - } + OpenSim.Tests.Common.TestLogging.LogToConsole(); folder1 = UUID.Random(); folder2 = UUID.Random(); @@ -258,37 +251,38 @@ namespace OpenSim.Data.Tests [Test] public void T104_RandomUpdateItem() { + PropertyScrambler folderScrambler = + new PropertyScrambler() + .DontScramble(x => x.Owner) + .DontScramble(x => x.ParentID) + .DontScramble(x => x.ID); UUID owner = UUID.Random(); UUID folder = UUID.Random(); UUID rootId = UUID.Random(); UUID rootAsset = UUID.Random(); InventoryFolderBase f1 = NewFolder(folder, zero, owner, name1); - ScrambleForTesting.Scramble(f1); - f1.Owner = owner; - f1.ParentID = zero; - f1.ID = folder; + folderScrambler.Scramble(f1); - // succeed with true db.addInventoryFolder(f1); InventoryFolderBase f1a = db.getUserRootFolder(owner); Assert.That(f1a, Constraints.PropertyCompareConstraint(f1)); - ScrambleForTesting.Scramble(f1a); - f1a.Owner = owner; - f1a.ParentID = zero; - f1a.ID = folder; + folderScrambler.Scramble(f1a); + db.updateInventoryFolder(f1a); InventoryFolderBase f1b = db.getUserRootFolder(owner); Assert.That(f1b, Constraints.PropertyCompareConstraint(f1a)); //Now we have a valid folder to insert into, we can insert the item. + PropertyScrambler inventoryScrambler = + new PropertyScrambler() + .DontScramble(x => x.ID) + .DontScramble(x => x.AssetID) + .DontScramble(x => x.Owner) + .DontScramble(x => x.Folder); InventoryItemBase root = NewItem(rootId, folder, owner, iname1, rootAsset); - ScrambleForTesting.Scramble(root); - root.ID = rootId; - root.AssetID = rootAsset; - root.Owner = owner; - root.Folder = folder; + inventoryScrambler.Scramble(root); db.addInventoryItem(root); InventoryItemBase expected = db.getInventoryItem(rootId); @@ -298,11 +292,7 @@ namespace OpenSim.Data.Tests .IgnoreProperty(x => x.Description) .IgnoreProperty(x => x.CreatorId)); - ScrambleForTesting.Scramble(expected); - expected.ID = rootId; - expected.AssetID = rootAsset; - expected.Owner = owner; - expected.Folder = folder; + inventoryScrambler.Scramble(expected); db.updateInventoryItem(expected); InventoryItemBase actual = db.getInventoryItem(rootId); diff --git a/OpenSim/Data/Tests/BasicRegionTest.cs b/OpenSim/Data/Tests/BasicRegionTest.cs index 8373922..8474921 100644 --- a/OpenSim/Data/Tests/BasicRegionTest.cs +++ b/OpenSim/Data/Tests/BasicRegionTest.cs @@ -71,14 +71,7 @@ namespace OpenSim.Data.Tests public void SuperInit() { - try - { - XmlConfigurator.Configure(); - } - catch (Exception) - { - // I don't care, just leave log4net off - } + OpenSim.Tests.Common.TestLogging.LogToConsole(); region1 = UUID.Random(); region3 = UUID.Random(); @@ -536,6 +529,9 @@ namespace OpenSim.Data.Tests [Test] public void T016_RandomSogWithSceneParts() { + PropertyScrambler scrambler = + new PropertyScrambler() + .DontScramble(x => x.UUID); UUID tmpSog = UUID.Random(); UUID tmp1 = UUID.Random(); UUID tmp2 = UUID.Random(); @@ -547,14 +543,18 @@ namespace OpenSim.Data.Tests p1.Shape = PrimitiveBaseShape.Default; p2.Shape = PrimitiveBaseShape.Default; p3.Shape = PrimitiveBaseShape.Default; - ScrambleForTesting.Scramble(p1); - ScrambleForTesting.Scramble(p2); - ScrambleForTesting.Scramble(p3); p1.UUID = tmp1; p2.UUID = tmp2; p3.UUID = tmp3; + scrambler.Scramble(p1); + scrambler.Scramble(p2); + scrambler.Scramble(p3); + SceneObjectGroup sog = NewSOG("Sop 0", tmpSog, newregion); - ScrambleForTesting.Scramble(sog); + PropertyScrambler sogScrambler = + new PropertyScrambler() + .DontScramble(x => x.UUID); + sogScrambler.Scramble(sog); sog.UUID = tmpSog; sog.AddPart(p1); sog.AddPart(p2); diff --git a/OpenSim/Data/Tests/BasicUserTest.cs b/OpenSim/Data/Tests/BasicUserTest.cs index a3c125d..f9feb9b 100644 --- a/OpenSim/Data/Tests/BasicUserTest.cs +++ b/OpenSim/Data/Tests/BasicUserTest.cs @@ -71,14 +71,7 @@ namespace OpenSim.Data.Tests public void SuperInit() { - try - { - XmlConfigurator.Configure(); - } - catch (Exception) - { - // I don't care, just leave log4net off - } + OpenSim.Tests.Common.TestLogging.LogToConsole(); random = new Random(); user1 = UUID.Random(); user2 = UUID.Random(); @@ -395,8 +388,7 @@ namespace OpenSim.Data.Tests { UUID id = user5; UserProfileData u = db.GetUserByUUID(id); - ScrambleForTesting.Scramble(u); - u.ID = id; + new PropertyScrambler().DontScramble(x=>x.ID).Scramble(u); db.UpdateUserProfile(u); UserProfileData u1a = db.GetUserByUUID(id); diff --git a/OpenSim/Data/Tests/PropertyScrambler.cs b/OpenSim/Data/Tests/PropertyScrambler.cs new file mode 100644 index 0000000..c56c10f --- /dev/null +++ b/OpenSim/Data/Tests/PropertyScrambler.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq.Expressions; +using System.Reflection; +using System.Text; +using NUnit.Framework; +using NUnit.Framework.SyntaxHelpers; +using OpenMetaverse; +using OpenSim.Framework; + +namespace OpenSim.Data.Tests +{ + + //This is generic so that the lambda expressions will work right in IDEs. + public class PropertyScrambler + { + readonly System.Collections.Generic.List membersToNotScramble = new List(); + + private void AddExpressionToNotScrableList(Expression expression) + { + UnaryExpression unaryExpression = expression as UnaryExpression; + if(unaryExpression != null) + { + AddExpressionToNotScrableList(unaryExpression.Operand); + return; + } + + MemberExpression memberExpression = expression as MemberExpression; + if (memberExpression != null) + { + if (!(memberExpression.Member is PropertyInfo)) + { + throw new NotImplementedException("I don't know how deal with a MemberExpression that is a " + expression.Type); + } + membersToNotScramble.Add(memberExpression.Member.Name); + return; + } + + throw new NotImplementedException("I don't know how to parse a " + expression.Type); + } + + public PropertyScrambler DontScramble(Expression> expression) + { + AddExpressionToNotScrableList(expression.Body); + return this; + } + + public void Scramble(T obj) + { + internalScramble(obj); + } + + private void internalScramble(object obj) + { + PropertyInfo[] properties = obj.GetType().GetProperties(); + foreach (var property in properties) + { + //Skip indexers of classes. We will assume that everything that has an indexer + // is also IEnumberable. May not always be true, but should be true normally. + if(property.GetIndexParameters().Length > 0) + continue; + + RandomizeProperty(obj, property, null); + } + //Now if it implments IEnumberable, it's probably some kind of list, so we should randomize + // everything inside of it. + IEnumerable enumerable = obj as IEnumerable; + if(enumerable != null) + { + foreach (object value in enumerable) + { + internalScramble(value); + } + } + } + + private readonly Random random = new Random(); + private void RandomizeProperty(object obj, PropertyInfo property, object[] index) + {//I'd like a better way to compare, but I had lots of problems with InventoryFolderBase because the ID is inherited. + if(membersToNotScramble.Contains(property.Name)) + return; + Type t = property.PropertyType; + if (!property.CanWrite) + return; + object value = property.GetValue(obj, index); + if (value == null) + return; + + if (t == typeof(string)) + property.SetValue(obj, RandomName(), index); + else if (t == typeof(UUID)) + property.SetValue(obj, UUID.Random(), index); + else if (t == typeof(sbyte)) + property.SetValue(obj, (sbyte)random.Next(sbyte.MinValue, sbyte.MaxValue), index); + else if (t == typeof(short)) + property.SetValue(obj, (short)random.Next(short.MinValue, short.MaxValue), index); + else if (t == typeof(int)) + property.SetValue(obj, random.Next(), index); + else if (t == typeof(long)) + property.SetValue(obj, random.Next() * int.MaxValue, index); + else if (t == typeof(byte)) + property.SetValue(obj, (byte)random.Next(byte.MinValue, byte.MaxValue), index); + else if (t == typeof(ushort)) + property.SetValue(obj, (ushort)random.Next(ushort.MinValue, ushort.MaxValue), index); + else if (t == typeof(uint)) + property.SetValue(obj, Convert.ToUInt32(random.Next()), index); + else if (t == typeof(ulong)) + property.SetValue(obj, Convert.ToUInt64(random.Next()) * Convert.ToUInt64(UInt32.MaxValue), index); + else if (t == typeof(bool)) + property.SetValue(obj, true, index); + else if (t == typeof(byte[])) + { + byte[] bytes = new byte[30]; + random.NextBytes(bytes); + property.SetValue(obj, bytes, index); + } + else + internalScramble(value); + } + + private string RandomName() + { + StringBuilder name = new StringBuilder(); + int size = random.Next(5, 12); + for (int i = 0; i < size; i++) + { + char ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))); + name.Append(ch); + } + return name.ToString(); + } + } + + [TestFixture] + public class PropertyScramblerTests + { + [Test] + public void TestScramble() + { + AssetBase actual = new AssetBase(UUID.Random(), "asset one"); + new PropertyScrambler().Scramble(actual); + } + + [Test] + public void DontScramble() + { + UUID uuid = UUID.Random(); + AssetBase asset = new AssetBase(); + asset.FullID = uuid; + new PropertyScrambler() + .DontScramble(x => x.Metadata) + .DontScramble(x => x.FullID) + .DontScramble(x => x.ID) + .Scramble(asset); + Assert.That(asset.FullID, Is.EqualTo(uuid)); + } + } +} \ No newline at end of file diff --git a/OpenSim/Data/Tests/ScrambleForTesting.cs b/OpenSim/Data/Tests/ScrambleForTesting.cs deleted file mode 100644 index 3a22347..0000000 --- a/OpenSim/Data/Tests/ScrambleForTesting.cs +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Collections; -using System.Reflection; -using System.Text; -using NUnit.Framework; -using OpenMetaverse; -using OpenSim.Framework; - -namespace OpenSim.Data.Tests -{ - public static class ScrambleForTesting - { - private static readonly Random random = new Random(); - public static void Scramble(object obj) - { - PropertyInfo[] properties = obj.GetType().GetProperties(); - foreach (var property in properties) - { - //Skip indexers of classes. We will assume that everything that has an indexer - // is also IEnumberable. May not always be true, but should be true normally. - if (property.GetIndexParameters().Length > 0) - continue; - - RandomizeProperty(obj, property, null); - } - //Now if it implments IEnumberable, it's probably some kind of list, so we should randomize - // everything inside of it. - IEnumerable enumerable = obj as IEnumerable; - if (enumerable != null) - { - foreach (object value in enumerable) - { - Scramble(value); - } - } - } - - private static void RandomizeProperty(object obj, PropertyInfo property, object[] index) - { - Type t = property.PropertyType; - if (!property.CanWrite) - return; - object value = property.GetValue(obj, index); - if (value == null) - return; - - if (t == typeof (string)) - property.SetValue(obj, RandomName(), index); - else if (t == typeof (UUID)) - property.SetValue(obj, UUID.Random(), index); - else if (t == typeof (sbyte)) - property.SetValue(obj, (sbyte)random.Next(sbyte.MinValue, sbyte.MaxValue), index); - else if (t == typeof (short)) - property.SetValue(obj, (short)random.Next(short.MinValue, short.MaxValue), index); - else if (t == typeof (int)) - property.SetValue(obj, random.Next(), index); - else if (t == typeof (long)) - property.SetValue(obj, random.Next() * int.MaxValue, index); - else if (t == typeof (byte)) - property.SetValue(obj, (byte)random.Next(byte.MinValue, byte.MaxValue), index); - else if (t == typeof (ushort)) - property.SetValue(obj, (ushort)random.Next(ushort.MinValue, ushort.MaxValue), index); - else if (t == typeof (uint)) - property.SetValue(obj, Convert.ToUInt32(random.Next()), index); - else if (t == typeof (ulong)) - property.SetValue(obj, Convert.ToUInt64(random.Next()) * Convert.ToUInt64(UInt32.MaxValue), index); - else if (t == typeof (bool)) - property.SetValue(obj, true, index); - else if (t == typeof (byte[])) - { - byte[] bytes = new byte[30]; - random.NextBytes(bytes); - property.SetValue(obj, bytes, index); - } - else - Scramble(value); - } - - private static string RandomName() - { - StringBuilder name = new StringBuilder(); - int size = random.Next(5, 12); - for (int i = 0; i < size; i++) - { - char ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))); - name.Append(ch); - } - return name.ToString(); - } - } - - [TestFixture] - public class ScrableForTestingTest - { - [Test] - public void TestScramble() - { - AssetBase actual = new AssetBase(UUID.Random(), "asset one"); - ScrambleForTesting.Scramble(actual); - } - } -} \ No newline at end of file -- cgit v1.1 From 82c888fc6c103ec345bf656cd469f4260b678bcb Mon Sep 17 00:00:00 2001 From: Jeff Ames Date: Mon, 17 Aug 2009 10:29:06 +0900 Subject: Add copyright headers. Formatting cleanup. Fix a compiler warning. --- OpenSim/Data/Tests/BasicGridTest.cs | 2 +- OpenSim/Data/Tests/PropertyCompareConstraint.cs | 2 +- OpenSim/Data/Tests/PropertyScrambler.cs | 35 ++++++++++++++++++++++--- 3 files changed, 33 insertions(+), 6 deletions(-) (limited to 'OpenSim/Data/Tests') diff --git a/OpenSim/Data/Tests/BasicGridTest.cs b/OpenSim/Data/Tests/BasicGridTest.cs index a25b736..de8fb48 100644 --- a/OpenSim/Data/Tests/BasicGridTest.cs +++ b/OpenSim/Data/Tests/BasicGridTest.cs @@ -46,7 +46,7 @@ namespace OpenSim.Data.Tests { // Clean up all the regions. List regions = db.GetRegionsByName("", 100); - if(regions != null) + if (regions != null) { foreach (RegionProfileData region in regions) { diff --git a/OpenSim/Data/Tests/PropertyCompareConstraint.cs b/OpenSim/Data/Tests/PropertyCompareConstraint.cs index d64a51e..06ca53e 100644 --- a/OpenSim/Data/Tests/PropertyCompareConstraint.cs +++ b/OpenSim/Data/Tests/PropertyCompareConstraint.cs @@ -83,7 +83,7 @@ namespace OpenSim.Data.Tests } //prevent loops... - if(propertyNames.Count > 50) + if (propertyNames.Count > 50) { failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); failingActual = actual; diff --git a/OpenSim/Data/Tests/PropertyScrambler.cs b/OpenSim/Data/Tests/PropertyScrambler.cs index c56c10f..72aaff1 100644 --- a/OpenSim/Data/Tests/PropertyScrambler.cs +++ b/OpenSim/Data/Tests/PropertyScrambler.cs @@ -1,3 +1,30 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + using System; using System.Collections; using System.Collections.Generic; @@ -20,7 +47,7 @@ namespace OpenSim.Data.Tests private void AddExpressionToNotScrableList(Expression expression) { UnaryExpression unaryExpression = expression as UnaryExpression; - if(unaryExpression != null) + if (unaryExpression != null) { AddExpressionToNotScrableList(unaryExpression.Operand); return; @@ -58,7 +85,7 @@ namespace OpenSim.Data.Tests { //Skip indexers of classes. We will assume that everything that has an indexer // is also IEnumberable. May not always be true, but should be true normally. - if(property.GetIndexParameters().Length > 0) + if (property.GetIndexParameters().Length > 0) continue; RandomizeProperty(obj, property, null); @@ -66,7 +93,7 @@ namespace OpenSim.Data.Tests //Now if it implments IEnumberable, it's probably some kind of list, so we should randomize // everything inside of it. IEnumerable enumerable = obj as IEnumerable; - if(enumerable != null) + if (enumerable != null) { foreach (object value in enumerable) { @@ -78,7 +105,7 @@ namespace OpenSim.Data.Tests private readonly Random random = new Random(); private void RandomizeProperty(object obj, PropertyInfo property, object[] index) {//I'd like a better way to compare, but I had lots of problems with InventoryFolderBase because the ID is inherited. - if(membersToNotScramble.Contains(property.Name)) + if (membersToNotScramble.Contains(property.Name)) return; Type t = property.PropertyType; if (!property.CanWrite) -- cgit v1.1