aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/Tests/RegionTests.cs
diff options
context:
space:
mode:
authorMelanie2010-05-26 10:38:46 +0100
committerMelanie2010-05-26 10:56:24 +0100
commit1c7f60ab493dffe44ab0517e4a6101fe5d909e28 (patch)
tree72b6a478d32d968ad7f5f3d6d11955bee9662926 /OpenSim/Data/Tests/RegionTests.cs
parentChange the way alpha is interpreted on prim text. Manris #4723 (diff)
parentMinor correction to AssetTests.cs (diff)
downloadopensim-SC_OLD-1c7f60ab493dffe44ab0517e4a6101fe5d909e28.zip
opensim-SC_OLD-1c7f60ab493dffe44ab0517e4a6101fe5d909e28.tar.gz
opensim-SC_OLD-1c7f60ab493dffe44ab0517e4a6101fe5d909e28.tar.bz2
opensim-SC_OLD-1c7f60ab493dffe44ab0517e4a6101fe5d909e28.tar.xz
Merge branch 'unitests'
Signed-off-by: Melanie <melanie@t-data.com>
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/Tests/RegionTests.cs (renamed from OpenSim/Data/Tests/BasicRegionTest.cs)221
1 files changed, 147 insertions, 74 deletions
diff --git a/OpenSim/Data/Tests/BasicRegionTest.cs b/OpenSim/Data/Tests/RegionTests.cs
index dfbf522..1f654d3 100644
--- a/OpenSim/Data/Tests/BasicRegionTest.cs
+++ b/OpenSim/Data/Tests/RegionTests.cs
@@ -38,59 +38,112 @@ using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.Framework.Scenes; 38using OpenSim.Region.Framework.Scenes;
39using log4net; 39using log4net;
40using System.Reflection; 40using System.Reflection;
41using System.Data.Common;
42
43#if !NUNIT25
44using NUnit.Framework.SyntaxHelpers;
45#endif
46
47// DBMS-specific:
48using MySql.Data.MySqlClient;
49using OpenSim.Data.MySQL;
50
51using System.Data.SqlClient;
52using OpenSim.Data.MSSQL;
53
54using Mono.Data.Sqlite;
55using OpenSim.Data.SQLite;
41 56
42namespace OpenSim.Data.Tests 57namespace OpenSim.Data.Tests
43{ 58{
44 public class BasicRegionTest 59#if NUNIT25
60
61 [TestFixture(typeof(SqliteConnection), typeof(SQLiteRegionData), Description = "Region store tests (SQLite)")]
62 [TestFixture(typeof(MySqlConnection), typeof(MySqlRegionData), Description = "Region store tests (MySQL)")]
63 [TestFixture(typeof(SqlConnection), typeof(MSSQLRegionData), Description = "Region store tests (MS SQL Server)")]
64
65#else
66
67 [TestFixture(Description = "Region store tests (SQLite)")]
68 public class SQLiteRegionTests : RegionTests<SqliteConnection, SQLiteRegionData>
69 {
70 }
71
72 [TestFixture(Description = "Region store tests (MySQL)")]
73 public class MySqlRegionTests : RegionTests<MySqlConnection, MySQLDataStore>
45 { 74 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 75 }
76
77 [TestFixture(Description = "Region store tests (MS SQL Server)")]
78 public class MSSQLRegionTests : RegionTests<SqlConnection, MSSQLRegionDataStore>
79 {
80 }
81
82#endif
83
84 public class RegionTests<TConn, TRegStore> : BasicDataServiceTest<TConn, TRegStore>
85 where TConn : DbConnection, new()
86 where TRegStore : class, IRegionDataStore, new()
87 {
88 bool m_rebuildDB;
89
47 public IRegionDataStore db; 90 public IRegionDataStore db;
48 public UUID zero = UUID.Zero; 91 public UUID zero = UUID.Zero;
49 public UUID region1; 92 public UUID region1 = UUID.Random();
50 public UUID region2; 93 public UUID region2 = UUID.Random();
51 public UUID region3; 94 public UUID region3 = UUID.Random();
52 public UUID region4; 95 public UUID region4 = UUID.Random();
53 public UUID prim1; 96 public UUID prim1 = UUID.Random();
54 public UUID prim2; 97 public UUID prim2 = UUID.Random();
55 public UUID prim3; 98 public UUID prim3 = UUID.Random();
56 public UUID prim4; 99 public UUID prim4 = UUID.Random();
57 public UUID prim5; 100 public UUID prim5 = UUID.Random();
58 public UUID prim6; 101 public UUID prim6 = UUID.Random();
59 public UUID item1; 102 public UUID item1 = UUID.Random();
60 public UUID item2; 103 public UUID item2 = UUID.Random();
61 public UUID item3; 104 public UUID item3 = UUID.Random();
62 105
63 public static Random random; 106 public static Random random = new Random();
64 107
65 public string itemname1 = "item1"; 108 public string itemname1 = "item1";
66 109
67 public uint localID; 110 public uint localID = 1;
68 111
69 public double height1; 112 public double height1 = 20;
70 public double height2; 113 public double height2 = 100;
71 114
72 public void SuperInit() 115 public RegionTests(string conn, bool rebuild)
116 : base(conn)
73 { 117 {
74 OpenSim.Tests.Common.TestLogging.LogToConsole(); 118 m_rebuildDB = rebuild;
75
76 region1 = UUID.Random();
77 region3 = UUID.Random();
78 region4 = UUID.Random();
79 prim1 = UUID.Random();
80 prim2 = UUID.Random();
81 prim3 = UUID.Random();
82 prim4 = UUID.Random();
83 prim5 = UUID.Random();
84 prim6 = UUID.Random();
85 item1 = UUID.Random();
86 item2 = UUID.Random();
87 item3 = UUID.Random();
88 random = new Random();
89 localID = 1;
90 height1 = 20;
91 height2 = 100;
92 } 119 }
93 120
121 public RegionTests() : this("", true) { }
122 public RegionTests(string conn) : this(conn, true) {}
123 public RegionTests(bool rebuild): this("", rebuild) {}
124
125
126 protected override void InitService(object service)
127 {
128 ClearDB();
129 db = (IRegionDataStore)service;
130 db.Initialise(m_connStr);
131 }
132
133 private void ClearDB()
134 {
135 string[] reg_tables = new string[] {
136 "prims", "primshapes", "primitems", "terrain", "land", "landaccesslist", "regionban", "regionsettings"
137 };
138 if (m_rebuildDB)
139 {
140 DropTables(reg_tables);
141 ResetMigrations("RegionStore");
142 }else
143 ClearTables(reg_tables);
144 }
145
146
94 // Test Plan 147 // Test Plan
95 // Prims 148 // Prims
96 // - empty test - 001 149 // - empty test - 001
@@ -580,68 +633,88 @@ namespace OpenSim.Data.Tests
580 .IgnoreProperty(x=>x.PassCollision) 633 .IgnoreProperty(x=>x.PassCollision)
581 .IgnoreProperty(x=>x.RootPart)); 634 .IgnoreProperty(x=>x.RootPart));
582 } 635 }
636
637
638 private SceneObjectGroup GetMySOG(string name)
639 {
640 SceneObjectGroup sog = FindSOG(name, region1);
641 if (sog == null)
642 {
643 sog = NewSOG(name, prim1, region1);
644 db.StoreObject(sog, region1);
645 }
646 return sog;
647 }
583 648
649
650 // NOTE: it is a bad practice to rely on some of the previous tests having been run before.
651 // If the tests are run manually, one at a time, each starts with full class init (DB cleared).
652 // Even when all tests are run, NUnit 2.5+ no longer guarantee a specific test order.
653 // We shouldn't expect to find anything in the DB if we haven't put it there *in the same test*!
654
584 [Test] 655 [Test]
585 public void T020_PrimInventoryEmpty() 656 public void T020_PrimInventoryEmpty()
586 { 657 {
587 SceneObjectGroup sog = FindSOG("object1", region1); 658 SceneObjectGroup sog = GetMySOG("object1");
588 TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1); 659 TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
589 Assert.That(t, Is.Null); 660 Assert.That(t, Is.Null);
590 } 661 }
591 662
592 [Test] 663 // TODO: Is there any point to call StorePrimInventory on a list, rather than on the prim itself?
593 public void T021_PrimInventoryStore()
594 {
595 SceneObjectGroup sog = FindSOG("object1", region1);
596 InventoryItemBase i = NewItem(item1, zero, zero, itemname1, zero);
597
598 Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, i, zero), Is.True);
599 TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
600 Assert.That(t.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))");
601
602 // TODO: seriously??? this is the way we need to loop to get this?
603 664
665 private void StoreInventory(SceneObjectGroup sog)
666 {
604 List<TaskInventoryItem> list = new List<TaskInventoryItem>(); 667 List<TaskInventoryItem> list = new List<TaskInventoryItem>();
668 // TODO: seriously??? this is the way we need to loop to get this?
605 foreach (UUID uuid in sog.RootPart.Inventory.GetInventoryList()) 669 foreach (UUID uuid in sog.RootPart.Inventory.GetInventoryList())
606 { 670 {
607 list.Add(sog.GetInventoryItem(sog.RootPart.LocalId, uuid)); 671 list.Add(sog.GetInventoryItem(sog.RootPart.LocalId, uuid));
608 } 672 }
609 673
610 db.StorePrimInventory(prim1, list); 674 db.StorePrimInventory(sog.RootPart.UUID, list);
611 } 675 }
612 676
613 [Test]
614 public void T022_PrimInventoryRetrieve()
615 {
616 SceneObjectGroup sog = FindSOG("object1", region1);
617 TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
618 677
619 Assert.That(t.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))");
620 }
621
622 [Test] 678 [Test]
623 public void T023_PrimInventoryUpdate() 679 public void T021_PrimInventoryBasic()
624 { 680 {
625 SceneObjectGroup sog = FindSOG("object1", region1); 681 SceneObjectGroup sog = GetMySOG("object1");
682 InventoryItemBase i = NewItem(item1, zero, zero, itemname1, zero);
683
684 Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, i, zero), Is.True);
626 TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1); 685 TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
686 Assert.That(t.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))");
627 687
628 t.Name = "My New Name"; 688 StoreInventory(sog);
629 sog.UpdateInventoryItem(t);
630 689
631 Assert.That(t.Name, Is.EqualTo("My New Name"), "Assert.That(t.Name, Is.EqualTo(\"My New Name\"))"); 690 SceneObjectGroup sog1 = FindSOG("object1", region1);
691 Assert.That(sog1, Is.Not.Null);
632 692
633 } 693 TaskInventoryItem t1 = sog1.GetInventoryItem(sog1.RootPart.LocalId, item1);
694 Assert.That(t1, Is.Not.Null);
695 Assert.That(t1.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))");
696
697 // Updating inventory
698 t1.Name = "My New Name";
699 sog1.UpdateInventoryItem(t1);
700
701 StoreInventory(sog1);
702
703 SceneObjectGroup sog2 = FindSOG("object1", region1);
704 TaskInventoryItem t2 = sog2.GetInventoryItem(sog2.RootPart.LocalId, item1);
705 Assert.That(t2.Name, Is.EqualTo("My New Name"), "Assert.That(t.Name, Is.EqualTo(\"My New Name\"))");
706
707 // Removing inventory
634 708
635 [Test]
636 public void T024_PrimInventoryRemove()
637 {
638 List<TaskInventoryItem> list = new List<TaskInventoryItem>(); 709 List<TaskInventoryItem> list = new List<TaskInventoryItem>();
639 db.StorePrimInventory(prim1, list); 710 db.StorePrimInventory(prim1, list);
640 711
641 SceneObjectGroup sog = FindSOG("object1", region1); 712 sog = FindSOG("object1", region1);
642 TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1); 713 t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
643 Assert.That(t, Is.Null); 714 Assert.That(t, Is.Null);
715
644 } 716 }
717
645 718
646 [Test] 719 [Test]
647 public void T025_PrimInventoryPersistency() 720 public void T025_PrimInventoryPersistency()
@@ -685,7 +758,7 @@ namespace OpenSim.Data.Tests
685 int creationd = random.Next(); 758 int creationd = random.Next();
686 i.CreationDate = creationd; 759 i.CreationDate = creationd;
687 760
688 SceneObjectGroup sog = FindSOG("object1", region1); 761 SceneObjectGroup sog = GetMySOG("object1");
689 Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, i, zero), Is.True); 762 Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, i, zero), Is.True);
690 TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, id); 763 TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, id);
691 764