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/BasicInventoryTest.cs | 37 ++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'OpenSim/Data/Tests/BasicInventoryTest.cs') 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(); -- 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 + 1 file changed, 1 insertion(+) (limited to 'OpenSim/Data/Tests/BasicInventoryTest.cs') 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)); } -- 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/BasicInventoryTest.cs | 56 ++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 7 deletions(-) (limited to 'OpenSim/Data/Tests/BasicInventoryTest.cs') 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] -- 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/BasicInventoryTest.cs | 44 ++++++++++++-------------------- 1 file changed, 17 insertions(+), 27 deletions(-) (limited to 'OpenSim/Data/Tests/BasicInventoryTest.cs') 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); -- cgit v1.1