From 94f4c20866a5ddee99c555bec347fbc68b3a99fd Mon Sep 17 00:00:00 2001
From: AlexRa
Date: Tue, 18 May 2010 14:33:57 +0300
Subject: Corrections in RegionTests.cs. It now fully works!

The problem was that some tests relied on prior tests
to leave the DB in a particular state, but the test class
cleared the DB every time. The affected tests have been
merged into one to remove the dependencies.

tested on all 3 Dbs, all tests green.
---
 OpenSim/Data/Tests/RegionTests.cs | 123 +++++++++++++++++++++++---------------
 1 file changed, 75 insertions(+), 48 deletions(-)

(limited to 'OpenSim/Data/Tests')

diff --git a/OpenSim/Data/Tests/RegionTests.cs b/OpenSim/Data/Tests/RegionTests.cs
index 2a97368..2451ef0 100644
--- a/OpenSim/Data/Tests/RegionTests.cs
+++ b/OpenSim/Data/Tests/RegionTests.cs
@@ -60,6 +60,8 @@ namespace OpenSim.Data.Tests
         where TConn : DbConnection, new()
         where TRegStore : class, IRegionDataStore, new()
     {
+        bool m_rebuildDB;
+
         public IRegionDataStore db;
         public UUID zero = UUID.Zero;
         public UUID region1 = UUID.Random();
@@ -85,6 +87,16 @@ namespace OpenSim.Data.Tests
         public double height1 = 20;
         public double height2 = 100;
 
+        public RegionTests(string conn, bool rebuild)
+            : base(conn)
+        {
+            m_rebuildDB = rebuild;
+        }
+
+        public RegionTests() : this("", false) { }
+        public RegionTests(string conn) : this(conn, false) {}
+        public RegionTests(bool rebuild): this("", rebuild) {}
+
 
         protected override void InitService(object service)
         {
@@ -93,22 +105,17 @@ namespace OpenSim.Data.Tests
             ClearDB();
         }
 
-
         private void ClearDB()
         {
-            // if a new table is added, it has to be dropped here
-            ExecuteSql("delete from migrations where name='RegionStore';");
-
-            DropTables(
-                "prims",
-                "primshapes",
-                "primitems",
-                "terrain",
-                "land",
-                "landaccesslist",
-                "regionban",
-                "regionsettings"
-            );
+            string[] reg_tables = new string[] { 
+                "prims", "primshapes", "primitems", "terrain", "land", "landaccesslist", "regionban", "regionsettings" 
+            };
+            if (m_rebuildDB)
+            {
+                DropTables(reg_tables);
+                ResetMigrations("RegionStore");
+            }else
+                ClearTables(reg_tables);
         }
 
 
@@ -601,68 +608,88 @@ namespace OpenSim.Data.Tests
                 .IgnoreProperty(x=>x.PassCollision)
                 .IgnoreProperty(x=>x.RootPart));
         }
+
+
+        private SceneObjectGroup GetMySOG(string name)
+        {
+            SceneObjectGroup sog = FindSOG(name, region1);
+            if (sog == null)
+            {
+                sog = NewSOG(name, prim1, region1); 
+                db.StoreObject(sog, region1);
+            }
+            return sog;
+        }
         
+
+        // NOTE: it is a bad practice to rely on some of the previous tests having been run before.
+        // If the tests are run manually, one at a time, each starts with full class init (DB cleared).
+        // Even when all tests are run, NUnit 2.5+ no longer guarantee a specific test order.
+        // We shouldn't expect to find anything in the DB if we haven't put it there *in the same test*!
+
         [Test]
         public void T020_PrimInventoryEmpty()
         {
-            SceneObjectGroup sog = FindSOG("object1", region1);
+            SceneObjectGroup sog = GetMySOG("object1");
             TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
             Assert.That(t, Is.Null);
         }
 
-        [Test]
-        public void T021_PrimInventoryStore()
-        {
-            SceneObjectGroup sog = FindSOG("object1", region1);
-            InventoryItemBase i = NewItem(item1, zero, zero, itemname1, zero);
-
-            Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, i, zero), Is.True);
-            TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
-            Assert.That(t.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))");
-            
-            // TODO: seriously??? this is the way we need to loop to get this?
+        // TODO: Is there any point to call StorePrimInventory on a list, rather than on the prim itself?
 
+        private void StoreInventory(SceneObjectGroup sog)
+        {
             List<TaskInventoryItem> list = new List<TaskInventoryItem>();
+            // TODO: seriously??? this is the way we need to loop to get this?
             foreach (UUID uuid in sog.RootPart.Inventory.GetInventoryList())
             {
                 list.Add(sog.GetInventoryItem(sog.RootPart.LocalId, uuid));
             }
-            
-            db.StorePrimInventory(prim1, list);
+
+            db.StorePrimInventory(sog.RootPart.UUID, list);
         }
 
-        [Test]
-        public void T022_PrimInventoryRetrieve()
-        {
-            SceneObjectGroup sog = FindSOG("object1", region1);
-            TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
 
-            Assert.That(t.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))");
-        }
-        
         [Test]
-        public void T023_PrimInventoryUpdate()
+        public void T021_PrimInventoryBasic()
         {
-            SceneObjectGroup sog = FindSOG("object1", region1);
+            SceneObjectGroup sog = GetMySOG("object1");
+            InventoryItemBase i = NewItem(item1, zero, zero, itemname1, zero);
+
+            Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, i, zero), Is.True);
             TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
+            Assert.That(t.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))");
             
-            t.Name = "My New Name";
-            sog.UpdateInventoryItem(t);
+            StoreInventory(sog);
 
-            Assert.That(t.Name, Is.EqualTo("My New Name"), "Assert.That(t.Name, Is.EqualTo(\"My New Name\"))");
+            SceneObjectGroup sog1 = FindSOG("object1", region1);
+            Assert.That(sog1, Is.Not.Null);
 
-        }
+            TaskInventoryItem t1 = sog1.GetInventoryItem(sog1.RootPart.LocalId, item1);
+            Assert.That(t1, Is.Not.Null);
+            Assert.That(t1.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))");
+
+            // Updating inventory
+            t1.Name = "My New Name";
+            sog1.UpdateInventoryItem(t1);
+
+            StoreInventory(sog1);
+
+            SceneObjectGroup sog2 = FindSOG("object1", region1);
+            TaskInventoryItem t2 = sog2.GetInventoryItem(sog2.RootPart.LocalId, item1);
+            Assert.That(t2.Name, Is.EqualTo("My New Name"), "Assert.That(t.Name, Is.EqualTo(\"My New Name\"))");
+
+            // Removing inventory
 
-        [Test]
-        public void T024_PrimInventoryRemove()
-        {
             List<TaskInventoryItem> list = new List<TaskInventoryItem>();
             db.StorePrimInventory(prim1, list);
 
-            SceneObjectGroup sog = FindSOG("object1", region1);
-            TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
+            sog = FindSOG("object1", region1);
+            t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
             Assert.That(t, Is.Null);
+
         }
+
         
         [Test]
         public void T025_PrimInventoryPersistency()
@@ -706,7 +733,7 @@ namespace OpenSim.Data.Tests
             int creationd = random.Next();
             i.CreationDate = creationd;
             
-            SceneObjectGroup sog = FindSOG("object1", region1);
+            SceneObjectGroup sog = GetMySOG("object1");
             Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, i, zero), Is.True);
             TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, id);
             
-- 
cgit v1.1