diff options
author | AlexRa | 2010-05-18 14:33:57 +0300 |
---|---|---|
committer | AlexRa | 2010-05-23 11:47:54 +0300 |
commit | 94f4c20866a5ddee99c555bec347fbc68b3a99fd (patch) | |
tree | 0a1df1b419b48766d8457083debbd4528376f45a /OpenSim | |
parent | Minor corrections in BasicDataServiceTest.cs (diff) | |
download | opensim-SC-94f4c20866a5ddee99c555bec347fbc68b3a99fd.zip opensim-SC-94f4c20866a5ddee99c555bec347fbc68b3a99fd.tar.gz opensim-SC-94f4c20866a5ddee99c555bec347fbc68b3a99fd.tar.bz2 opensim-SC-94f4c20866a5ddee99c555bec347fbc68b3a99fd.tar.xz |
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.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/Tests/RegionTests.cs | 123 |
1 files changed, 75 insertions, 48 deletions
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 | |||
60 | where TConn : DbConnection, new() | 60 | where TConn : DbConnection, new() |
61 | where TRegStore : class, IRegionDataStore, new() | 61 | where TRegStore : class, IRegionDataStore, new() |
62 | { | 62 | { |
63 | bool m_rebuildDB; | ||
64 | |||
63 | public IRegionDataStore db; | 65 | public IRegionDataStore db; |
64 | public UUID zero = UUID.Zero; | 66 | public UUID zero = UUID.Zero; |
65 | public UUID region1 = UUID.Random(); | 67 | public UUID region1 = UUID.Random(); |
@@ -85,6 +87,16 @@ namespace OpenSim.Data.Tests | |||
85 | public double height1 = 20; | 87 | public double height1 = 20; |
86 | public double height2 = 100; | 88 | public double height2 = 100; |
87 | 89 | ||
90 | public RegionTests(string conn, bool rebuild) | ||
91 | : base(conn) | ||
92 | { | ||
93 | m_rebuildDB = rebuild; | ||
94 | } | ||
95 | |||
96 | public RegionTests() : this("", false) { } | ||
97 | public RegionTests(string conn) : this(conn, false) {} | ||
98 | public RegionTests(bool rebuild): this("", rebuild) {} | ||
99 | |||
88 | 100 | ||
89 | protected override void InitService(object service) | 101 | protected override void InitService(object service) |
90 | { | 102 | { |
@@ -93,22 +105,17 @@ namespace OpenSim.Data.Tests | |||
93 | ClearDB(); | 105 | ClearDB(); |
94 | } | 106 | } |
95 | 107 | ||
96 | |||
97 | private void ClearDB() | 108 | private void ClearDB() |
98 | { | 109 | { |
99 | // if a new table is added, it has to be dropped here | 110 | string[] reg_tables = new string[] { |
100 | ExecuteSql("delete from migrations where name='RegionStore';"); | 111 | "prims", "primshapes", "primitems", "terrain", "land", "landaccesslist", "regionban", "regionsettings" |
101 | 112 | }; | |
102 | DropTables( | 113 | if (m_rebuildDB) |
103 | "prims", | 114 | { |
104 | "primshapes", | 115 | DropTables(reg_tables); |
105 | "primitems", | 116 | ResetMigrations("RegionStore"); |
106 | "terrain", | 117 | }else |
107 | "land", | 118 | ClearTables(reg_tables); |
108 | "landaccesslist", | ||
109 | "regionban", | ||
110 | "regionsettings" | ||
111 | ); | ||
112 | } | 119 | } |
113 | 120 | ||
114 | 121 | ||
@@ -601,68 +608,88 @@ namespace OpenSim.Data.Tests | |||
601 | .IgnoreProperty(x=>x.PassCollision) | 608 | .IgnoreProperty(x=>x.PassCollision) |
602 | .IgnoreProperty(x=>x.RootPart)); | 609 | .IgnoreProperty(x=>x.RootPart)); |
603 | } | 610 | } |
611 | |||
612 | |||
613 | private SceneObjectGroup GetMySOG(string name) | ||
614 | { | ||
615 | SceneObjectGroup sog = FindSOG(name, region1); | ||
616 | if (sog == null) | ||
617 | { | ||
618 | sog = NewSOG(name, prim1, region1); | ||
619 | db.StoreObject(sog, region1); | ||
620 | } | ||
621 | return sog; | ||
622 | } | ||
604 | 623 | ||
624 | |||
625 | // NOTE: it is a bad practice to rely on some of the previous tests having been run before. | ||
626 | // If the tests are run manually, one at a time, each starts with full class init (DB cleared). | ||
627 | // Even when all tests are run, NUnit 2.5+ no longer guarantee a specific test order. | ||
628 | // We shouldn't expect to find anything in the DB if we haven't put it there *in the same test*! | ||
629 | |||
605 | [Test] | 630 | [Test] |
606 | public void T020_PrimInventoryEmpty() | 631 | public void T020_PrimInventoryEmpty() |
607 | { | 632 | { |
608 | SceneObjectGroup sog = FindSOG("object1", region1); | 633 | SceneObjectGroup sog = GetMySOG("object1"); |
609 | TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1); | 634 | TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1); |
610 | Assert.That(t, Is.Null); | 635 | Assert.That(t, Is.Null); |
611 | } | 636 | } |
612 | 637 | ||
613 | [Test] | 638 | // TODO: Is there any point to call StorePrimInventory on a list, rather than on the prim itself? |
614 | public void T021_PrimInventoryStore() | ||
615 | { | ||
616 | SceneObjectGroup sog = FindSOG("object1", region1); | ||
617 | InventoryItemBase i = NewItem(item1, zero, zero, itemname1, zero); | ||
618 | |||
619 | Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, i, zero), Is.True); | ||
620 | TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1); | ||
621 | Assert.That(t.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))"); | ||
622 | |||
623 | // TODO: seriously??? this is the way we need to loop to get this? | ||
624 | 639 | ||
640 | private void StoreInventory(SceneObjectGroup sog) | ||
641 | { | ||
625 | List<TaskInventoryItem> list = new List<TaskInventoryItem>(); | 642 | List<TaskInventoryItem> list = new List<TaskInventoryItem>(); |
643 | // TODO: seriously??? this is the way we need to loop to get this? | ||
626 | foreach (UUID uuid in sog.RootPart.Inventory.GetInventoryList()) | 644 | foreach (UUID uuid in sog.RootPart.Inventory.GetInventoryList()) |
627 | { | 645 | { |
628 | list.Add(sog.GetInventoryItem(sog.RootPart.LocalId, uuid)); | 646 | list.Add(sog.GetInventoryItem(sog.RootPart.LocalId, uuid)); |
629 | } | 647 | } |
630 | 648 | ||
631 | db.StorePrimInventory(prim1, list); | 649 | db.StorePrimInventory(sog.RootPart.UUID, list); |
632 | } | 650 | } |
633 | 651 | ||
634 | [Test] | ||
635 | public void T022_PrimInventoryRetrieve() | ||
636 | { | ||
637 | SceneObjectGroup sog = FindSOG("object1", region1); | ||
638 | TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1); | ||
639 | 652 | ||
640 | Assert.That(t.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))"); | ||
641 | } | ||
642 | |||
643 | [Test] | 653 | [Test] |
644 | public void T023_PrimInventoryUpdate() | 654 | public void T021_PrimInventoryBasic() |
645 | { | 655 | { |
646 | SceneObjectGroup sog = FindSOG("object1", region1); | 656 | SceneObjectGroup sog = GetMySOG("object1"); |
657 | InventoryItemBase i = NewItem(item1, zero, zero, itemname1, zero); | ||
658 | |||
659 | Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, i, zero), Is.True); | ||
647 | TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1); | 660 | TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1); |
661 | Assert.That(t.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))"); | ||
648 | 662 | ||
649 | t.Name = "My New Name"; | 663 | StoreInventory(sog); |
650 | sog.UpdateInventoryItem(t); | ||
651 | 664 | ||
652 | Assert.That(t.Name, Is.EqualTo("My New Name"), "Assert.That(t.Name, Is.EqualTo(\"My New Name\"))"); | 665 | SceneObjectGroup sog1 = FindSOG("object1", region1); |
666 | Assert.That(sog1, Is.Not.Null); | ||
653 | 667 | ||
654 | } | 668 | TaskInventoryItem t1 = sog1.GetInventoryItem(sog1.RootPart.LocalId, item1); |
669 | Assert.That(t1, Is.Not.Null); | ||
670 | Assert.That(t1.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))"); | ||
671 | |||
672 | // Updating inventory | ||
673 | t1.Name = "My New Name"; | ||
674 | sog1.UpdateInventoryItem(t1); | ||
675 | |||
676 | StoreInventory(sog1); | ||
677 | |||
678 | SceneObjectGroup sog2 = FindSOG("object1", region1); | ||
679 | TaskInventoryItem t2 = sog2.GetInventoryItem(sog2.RootPart.LocalId, item1); | ||
680 | Assert.That(t2.Name, Is.EqualTo("My New Name"), "Assert.That(t.Name, Is.EqualTo(\"My New Name\"))"); | ||
681 | |||
682 | // Removing inventory | ||
655 | 683 | ||
656 | [Test] | ||
657 | public void T024_PrimInventoryRemove() | ||
658 | { | ||
659 | List<TaskInventoryItem> list = new List<TaskInventoryItem>(); | 684 | List<TaskInventoryItem> list = new List<TaskInventoryItem>(); |
660 | db.StorePrimInventory(prim1, list); | 685 | db.StorePrimInventory(prim1, list); |
661 | 686 | ||
662 | SceneObjectGroup sog = FindSOG("object1", region1); | 687 | sog = FindSOG("object1", region1); |
663 | TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1); | 688 | t = sog.GetInventoryItem(sog.RootPart.LocalId, item1); |
664 | Assert.That(t, Is.Null); | 689 | Assert.That(t, Is.Null); |
690 | |||
665 | } | 691 | } |
692 | |||
666 | 693 | ||
667 | [Test] | 694 | [Test] |
668 | public void T025_PrimInventoryPersistency() | 695 | public void T025_PrimInventoryPersistency() |
@@ -706,7 +733,7 @@ namespace OpenSim.Data.Tests | |||
706 | int creationd = random.Next(); | 733 | int creationd = random.Next(); |
707 | i.CreationDate = creationd; | 734 | i.CreationDate = creationd; |
708 | 735 | ||
709 | SceneObjectGroup sog = FindSOG("object1", region1); | 736 | SceneObjectGroup sog = GetMySOG("object1"); |
710 | Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, i, zero), Is.True); | 737 | Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, i, zero), Is.True); |
711 | TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, id); | 738 | TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, id); |
712 | 739 | ||