aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/Tests
diff options
context:
space:
mode:
authorUbitUmarov2015-09-01 11:43:07 +0100
committerUbitUmarov2015-09-01 11:43:07 +0100
commitfb78b182520fc9bb0f971afd0322029c70278ea6 (patch)
treeb4e30d383938fdeef8c92d1d1c2f44bb61d329bd /OpenSim/Data/Tests
parentlixo (diff)
parentMantis #7713: fixed bug introduced by 1st MOSES patch. (diff)
downloadopensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.zip
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.gz
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.bz2
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.xz
Merge remote-tracking branch 'os/master'
Diffstat (limited to 'OpenSim/Data/Tests')
-rw-r--r--OpenSim/Data/Tests/AssetTests.cs206
-rw-r--r--OpenSim/Data/Tests/BasicDataServiceTest.cs271
-rw-r--r--OpenSim/Data/Tests/DataTestUtil.cs88
-rw-r--r--OpenSim/Data/Tests/DefaultTestConns.cs90
-rw-r--r--OpenSim/Data/Tests/EstateTests.cs521
-rw-r--r--OpenSim/Data/Tests/InventoryTests.cs381
-rw-r--r--OpenSim/Data/Tests/PropertyCompareConstraint.cs413
-rw-r--r--OpenSim/Data/Tests/PropertyScrambler.cs184
-rw-r--r--OpenSim/Data/Tests/RegionTests.cs1129
-rw-r--r--OpenSim/Data/Tests/Resources/TestDataConnections.ini24
10 files changed, 3307 insertions, 0 deletions
diff --git a/OpenSim/Data/Tests/AssetTests.cs b/OpenSim/Data/Tests/AssetTests.cs
new file mode 100644
index 0000000..5d7b169
--- /dev/null
+++ b/OpenSim/Data/Tests/AssetTests.cs
@@ -0,0 +1,206 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using log4net.Config;
31using NUnit.Framework;
32using NUnit.Framework.Constraints;
33using OpenMetaverse;
34using OpenSim.Framework;
35using OpenSim.Tests.Common;
36using System.Data.Common;
37using log4net;
38
39// DBMS-specific:
40using MySql.Data.MySqlClient;
41using OpenSim.Data.MySQL;
42
43using Mono.Data.Sqlite;
44using OpenSim.Data.SQLite;
45
46namespace OpenSim.Data.Tests
47{
48 [TestFixture(Description = "Asset store tests (SQLite)")]
49 public class SQLiteAssetTests : AssetTests<SqliteConnection, SQLiteAssetData>
50 {
51 }
52
53 [TestFixture(Description = "Asset store tests (MySQL)")]
54 public class MySqlAssetTests : AssetTests<MySqlConnection, MySQLAssetData>
55 {
56 }
57
58 public class AssetTests<TConn, TAssetData> : BasicDataServiceTest<TConn, TAssetData>
59 where TConn : DbConnection, new()
60 where TAssetData : AssetDataBase, new()
61 {
62 TAssetData m_db;
63
64 public UUID uuid1 = UUID.Random();
65 public UUID uuid2 = UUID.Random();
66 public UUID uuid3 = UUID.Random();
67
68 public string critter1 = UUID.Random().ToString();
69 public string critter2 = UUID.Random().ToString();
70 public string critter3 = UUID.Random().ToString();
71
72 public byte[] data1 = new byte[100];
73
74 PropertyScrambler<AssetBase> scrambler = new PropertyScrambler<AssetBase>()
75 .DontScramble(x => x.ID)
76 .DontScramble(x => x.Type)
77 .DontScramble(x => x.FullID)
78 .DontScramble(x => x.Metadata.ID)
79 .DontScramble(x => x.Metadata.CreatorID)
80 .DontScramble(x => x.Metadata.ContentType)
81 .DontScramble(x => x.Metadata.FullID)
82 .DontScramble(x => x.Data);
83
84 protected override void InitService(object service)
85 {
86 ClearDB();
87 m_db = (TAssetData)service;
88 m_db.Initialise(m_connStr);
89 }
90
91 private void ClearDB()
92 {
93 DropTables("assets");
94 ResetMigrations("AssetStore");
95 }
96
97
98 [Test]
99 public void T001_LoadEmpty()
100 {
101 TestHelpers.InMethod();
102
103 bool[] exist = m_db.AssetsExist(new[] { uuid1, uuid2, uuid3 });
104 Assert.IsFalse(exist[0]);
105 Assert.IsFalse(exist[1]);
106 Assert.IsFalse(exist[2]);
107 }
108
109 [Test]
110 public void T010_StoreReadVerifyAssets()
111 {
112 TestHelpers.InMethod();
113
114 AssetBase a1 = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture, critter1.ToString());
115 AssetBase a2 = new AssetBase(uuid2, "asset two", (sbyte)AssetType.Texture, critter2.ToString());
116 AssetBase a3 = new AssetBase(uuid3, "asset three", (sbyte)AssetType.Texture, critter3.ToString());
117 a1.Data = data1;
118 a2.Data = data1;
119 a3.Data = data1;
120
121 scrambler.Scramble(a1);
122 scrambler.Scramble(a2);
123 scrambler.Scramble(a3);
124
125 m_db.StoreAsset(a1);
126 m_db.StoreAsset(a2);
127 m_db.StoreAsset(a3);
128
129 AssetBase a1a = m_db.GetAsset(uuid1);
130 Assert.That(a1a, Constraints.PropertyCompareConstraint(a1));
131
132 AssetBase a2a = m_db.GetAsset(uuid2);
133 Assert.That(a2a, Constraints.PropertyCompareConstraint(a2));
134
135 AssetBase a3a = m_db.GetAsset(uuid3);
136 Assert.That(a3a, Constraints.PropertyCompareConstraint(a3));
137
138 scrambler.Scramble(a1a);
139 scrambler.Scramble(a2a);
140 scrambler.Scramble(a3a);
141
142 m_db.StoreAsset(a1a);
143 m_db.StoreAsset(a2a);
144 m_db.StoreAsset(a3a);
145
146 AssetBase a1b = m_db.GetAsset(uuid1);
147 Assert.That(a1b, Constraints.PropertyCompareConstraint(a1a));
148
149 AssetBase a2b = m_db.GetAsset(uuid2);
150 Assert.That(a2b, Constraints.PropertyCompareConstraint(a2a));
151
152 AssetBase a3b = m_db.GetAsset(uuid3);
153 Assert.That(a3b, Constraints.PropertyCompareConstraint(a3a));
154
155 bool[] exist = m_db.AssetsExist(new[] { uuid1, uuid2, uuid3 });
156 Assert.IsTrue(exist[0]);
157 Assert.IsTrue(exist[1]);
158 Assert.IsTrue(exist[2]);
159
160 List<AssetMetadata> metadatas = m_db.FetchAssetMetadataSet(0, 1000);
161
162 Assert.That(metadatas.Count >= 3, "FetchAssetMetadataSet() should have returned at least 3 assets!");
163
164 // It is possible that the Asset table is filled with data, in which case we don't try to find "our"
165 // assets there:
166 if (metadatas.Count < 1000)
167 {
168 AssetMetadata metadata = metadatas.Find(x => x.FullID == uuid1);
169 Assert.That(metadata.Name, Is.EqualTo(a1b.Name));
170 Assert.That(metadata.Description, Is.EqualTo(a1b.Description));
171 Assert.That(metadata.Type, Is.EqualTo(a1b.Type));
172 Assert.That(metadata.Temporary, Is.EqualTo(a1b.Temporary));
173 Assert.That(metadata.FullID, Is.EqualTo(a1b.FullID));
174 }
175 }
176
177 [Test]
178 public void T020_CheckForWeirdCreatorID()
179 {
180 TestHelpers.InMethod();
181
182 // It is expected that eventually the CreatorID might be an arbitrary string (an URI)
183 // rather than a valid UUID (?). This test is to make sure that the database layer does not
184 // attempt to convert CreatorID to GUID, but just passes it both ways as a string.
185 AssetBase a1 = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture, critter1);
186 AssetBase a2 = new AssetBase(uuid2, "asset two", (sbyte)AssetType.Texture, "This is not a GUID!");
187 AssetBase a3 = new AssetBase(uuid3, "asset three", (sbyte)AssetType.Texture, "");
188 a1.Data = data1;
189 a2.Data = data1;
190 a3.Data = data1;
191
192 m_db.StoreAsset(a1);
193 m_db.StoreAsset(a2);
194 m_db.StoreAsset(a3);
195
196 AssetBase a1a = m_db.GetAsset(uuid1);
197 Assert.That(a1a, Constraints.PropertyCompareConstraint(a1));
198
199 AssetBase a2a = m_db.GetAsset(uuid2);
200 Assert.That(a2a, Constraints.PropertyCompareConstraint(a2));
201
202 AssetBase a3a = m_db.GetAsset(uuid3);
203 Assert.That(a3a, Constraints.PropertyCompareConstraint(a3));
204 }
205 }
206} \ No newline at end of file
diff --git a/OpenSim/Data/Tests/BasicDataServiceTest.cs b/OpenSim/Data/Tests/BasicDataServiceTest.cs
new file mode 100644
index 0000000..acfebd0
--- /dev/null
+++ b/OpenSim/Data/Tests/BasicDataServiceTest.cs
@@ -0,0 +1,271 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.IO;
30using System.Collections.Generic;
31using log4net.Config;
32using NUnit.Framework;
33using NUnit.Framework.Constraints;
34using OpenMetaverse;
35using OpenSim.Framework;
36using OpenSim.Tests.Common;
37using log4net;
38using System.Data;
39using System.Data.Common;
40using System.Reflection;
41
42namespace OpenSim.Data.Tests
43{
44 /// <summary>This is a base class for testing any Data service for any DBMS.
45 /// Requires NUnit 2.5 or better (to support the generics).
46 /// </summary>
47 /// <remarks>
48 /// FIXME: Should extend OpenSimTestCase but compile on mono 2.4.3 currently fails with
49 /// AssetTests`2 : System.MemberAccessException : Cannot create an instance of OpenSim.Data.Tests.AssetTests`2[TConn,TAssetData] because Type.ContainsGenericParameters is true.
50 /// and similar on EstateTests, InventoryTests and RegionTests.
51 /// Runs fine with mono 2.10.8.1, so easiest thing is to wait until min Mono version uplifts.
52 /// </remarks>
53 /// <typeparam name="TConn"></typeparam>
54 /// <typeparam name="TService"></typeparam>
55 public class BasicDataServiceTest<TConn, TService>
56 where TConn : DbConnection, new()
57 where TService : class, new()
58 {
59 protected string m_connStr;
60 private TService m_service;
61 private string m_file;
62
63 // TODO: Is this in the right place here?
64 // Later: apparently it's not, but does it matter here?
65// protected static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
66
67 protected ILog m_log; // doesn't matter here that it's not static, init to correct type in instance .ctor
68
69 public BasicDataServiceTest()
70 : this("")
71 {
72 }
73
74 public BasicDataServiceTest(string conn)
75 {
76 m_connStr = !String.IsNullOrEmpty(conn) ? conn : DefaultTestConns.Get(typeof(TConn));
77
78 m_log = LogManager.GetLogger(this.GetType());
79 OpenSim.Tests.Common.TestLogging.LogToConsole(); // TODO: Is that right?
80 }
81
82 /// <summary>
83 /// To be overridden in derived classes. Do whatever init with the m_service, like setting the conn string to it.
84 /// You'd probably want to to cast the 'service' to a more specific type and store it in a member var.
85 /// This framework takes care of disposing it, if it's disposable.
86 /// </summary>
87 /// <param name="service">The service being tested</param>
88 protected virtual void InitService(object service)
89 {
90 }
91
92 [TestFixtureSetUp]
93 public void Init()
94 {
95 // Sorry, some SQLite-specific stuff goes here (not a big deal, as its just some file ops)
96 if (typeof(TConn).Name.StartsWith("Sqlite"))
97 {
98 // SQLite doesn't work on power or z linux
99 if (Directory.Exists("/proc/ppc64") || Directory.Exists("/proc/dasd"))
100 Assert.Ignore();
101
102 if (Util.IsWindows())
103 Util.LoadArchSpecificWindowsDll("sqlite3.dll");
104
105 // for SQLite, if no explicit conn string is specified, use a temp file
106 if (String.IsNullOrEmpty(m_connStr))
107 {
108 m_file = Path.GetTempFileName() + ".db";
109 m_connStr = "URI=file:" + m_file + ",version=3";
110 }
111 }
112
113 if (String.IsNullOrEmpty(m_connStr))
114 {
115 string msg = String.Format("Connection string for {0} is not defined, ignoring tests", typeof(TConn).Name);
116 m_log.Warn(msg);
117 Assert.Ignore(msg);
118 }
119
120 // Try the connection, ignore tests if Open() fails
121 using (TConn conn = new TConn())
122 {
123 conn.ConnectionString = m_connStr;
124 try
125 {
126 conn.Open();
127 conn.Close();
128 }
129 catch
130 {
131 string msg = String.Format("{0} is unable to connect to the database, ignoring tests", typeof(TConn).Name);
132 m_log.Warn(msg);
133 Assert.Ignore(msg);
134 }
135 }
136
137 // If we manage to connect to the database with the user
138 // and password above it is our test database, and run
139 // these tests. If anything goes wrong, ignore these
140 // tests.
141 try
142 {
143 m_service = new TService();
144 InitService(m_service);
145 }
146 catch (Exception e)
147 {
148 m_log.Error(e.ToString());
149 Assert.Ignore();
150 }
151 }
152
153 [TestFixtureTearDown]
154 public void Cleanup()
155 {
156 if (m_service != null)
157 {
158 if (m_service is IDisposable)
159 ((IDisposable)m_service).Dispose();
160 m_service = null;
161 }
162
163 if (!String.IsNullOrEmpty(m_file) && File.Exists(m_file))
164 File.Delete(m_file);
165 }
166
167 protected virtual DbConnection Connect()
168 {
169 DbConnection cnn = new TConn();
170 cnn.ConnectionString = m_connStr;
171 cnn.Open();
172 return cnn;
173 }
174
175 protected virtual void ExecuteSql(string sql)
176 {
177 using (DbConnection dbcon = Connect())
178 {
179 using (DbCommand cmd = dbcon.CreateCommand())
180 {
181 cmd.CommandText = sql;
182 cmd.ExecuteNonQuery();
183 }
184 }
185 }
186
187 protected delegate bool ProcessRow(IDataReader reader);
188
189 protected virtual int ExecQuery(string sql, bool bSingleRow, ProcessRow action)
190 {
191 int nRecs = 0;
192 using (DbConnection dbcon = Connect())
193 {
194 using (DbCommand cmd = dbcon.CreateCommand())
195 {
196 cmd.CommandText = sql;
197 CommandBehavior cb = bSingleRow ? CommandBehavior.SingleRow : CommandBehavior.Default;
198 using (DbDataReader rdr = cmd.ExecuteReader(cb))
199 {
200 while (rdr.Read())
201 {
202 nRecs++;
203 if (!action(rdr))
204 break;
205 }
206 }
207 }
208 }
209 return nRecs;
210 }
211
212 /// <summary>Drop tables (listed as parameters). There is no "DROP IF EXISTS" syntax common for all
213 /// databases, so we just DROP and ignore an exception.
214 /// </summary>
215 /// <param name="tables"></param>
216 protected virtual void DropTables(params string[] tables)
217 {
218 foreach (string tbl in tables)
219 {
220 try
221 {
222 ExecuteSql("DROP TABLE " + tbl + ";");
223 }catch
224 {
225 }
226 }
227 }
228
229 /// <summary>Clear tables listed as parameters (without dropping them).
230 /// </summary>
231 /// <param name="tables"></param>
232 protected virtual void ResetMigrations(params string[] stores)
233 {
234 string lst = "";
235 foreach (string store in stores)
236 {
237 string s = "'" + store + "'";
238 if (lst == "")
239 lst = s;
240 else
241 lst += ", " + s;
242 }
243
244 string sCond = stores.Length > 1 ? ("in (" + lst + ")") : ("=" + lst);
245 try
246 {
247 ExecuteSql("DELETE FROM migrations where name " + sCond);
248 }
249 catch
250 {
251 }
252 }
253
254 /// <summary>Clear tables listed as parameters (without dropping them).
255 /// </summary>
256 /// <param name="tables"></param>
257 protected virtual void ClearTables(params string[] tables)
258 {
259 foreach (string tbl in tables)
260 {
261 try
262 {
263 ExecuteSql("DELETE FROM " + tbl + ";");
264 }
265 catch
266 {
267 }
268 }
269 }
270 }
271}
diff --git a/OpenSim/Data/Tests/DataTestUtil.cs b/OpenSim/Data/Tests/DataTestUtil.cs
new file mode 100644
index 0000000..5393529
--- /dev/null
+++ b/OpenSim/Data/Tests/DataTestUtil.cs
@@ -0,0 +1,88 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Text;
31using OpenMetaverse;
32using NUnit.Framework;
33
34namespace OpenSim.Data.Tests
35{
36 /// <summary>
37 /// Shared constants and methods for database unit tests.
38 /// </summary>
39 public class DataTestUtil
40 {
41 public const uint UNSIGNED_INTEGER_MIN = uint.MinValue;
42 //public const uint UNSIGNED_INTEGER_MAX = uint.MaxValue;
43 public const uint UNSIGNED_INTEGER_MAX = INTEGER_MAX;
44
45 public const int INTEGER_MIN = int.MinValue + 1; // Postgresql requires +1 to .NET int.MinValue
46 public const int INTEGER_MAX = int.MaxValue;
47
48 public const float FLOAT_MIN = float.MinValue * (1 - FLOAT_PRECISSION);
49 public const float FLOAT_MAX = float.MaxValue * (1 - FLOAT_PRECISSION);
50 public const float FLOAT_ACCURATE = 1.234567890123456789012f;
51 public const float FLOAT_PRECISSION = 1E-5f; // Native MySQL is severly limited with floating accuracy
52
53 public const double DOUBLE_MIN = -1E52 * (1 - DOUBLE_PRECISSION);
54 public const double DOUBLE_MAX = 1E52 * (1 - DOUBLE_PRECISSION);
55 public const double DOUBLE_ACCURATE = 1.2345678901234567890123456789012345678901234567890123f;
56 public const double DOUBLE_PRECISSION = 1E-14; // Native MySQL is severly limited with double accuracy
57
58 public const string STRING_MIN = "";
59 public static string STRING_MAX(int length)
60 {
61 StringBuilder stringBuilder = new StringBuilder();
62 for (int i = 0; i < length; i++)
63 {
64 stringBuilder.Append(i % 10);
65 }
66 return stringBuilder.ToString();
67 }
68
69 public static UUID UUID_MIN = new UUID("00000000-0000-0000-0000-000000000000");
70 public static UUID UUID_MAX = new UUID("ffffffff-ffff-ffff-ffff-ffffffffffff");
71
72 public const bool BOOLEAN_MIN = false;
73 public const bool BOOLEAN_MAX = true;
74
75 public static void AssertFloatEqualsWithTolerance(float expectedValue, float actualValue)
76 {
77 Assert.GreaterOrEqual(actualValue, expectedValue - Math.Abs(expectedValue) * FLOAT_PRECISSION);
78 Assert.LessOrEqual(actualValue, expectedValue + Math.Abs(expectedValue) * FLOAT_PRECISSION);
79 }
80
81 public static void AssertDoubleEqualsWithTolerance(double expectedValue, double actualValue)
82 {
83 Assert.GreaterOrEqual(actualValue, expectedValue - Math.Abs(expectedValue) * DOUBLE_PRECISSION);
84 Assert.LessOrEqual(actualValue, expectedValue + Math.Abs(expectedValue) * DOUBLE_PRECISSION);
85 }
86 }
87}
88
diff --git a/OpenSim/Data/Tests/DefaultTestConns.cs b/OpenSim/Data/Tests/DefaultTestConns.cs
new file mode 100644
index 0000000..7c47bdd
--- /dev/null
+++ b/OpenSim/Data/Tests/DefaultTestConns.cs
@@ -0,0 +1,90 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Linq;
31using System.Text;
32using System.Reflection;
33using System.IO;
34using Nini.Config;
35
36namespace OpenSim.Data.Tests
37{
38 /// <summary>This static class looks for TestDataConnections.ini file in the /bin directory to obtain
39 /// a connection string for testing one of the supported databases.
40 /// The connections must be in the section [TestConnections] with names matching the connection class
41 /// name for the specific database, e.g.:
42 ///
43 /// [TestConnections]
44 /// MySqlConnection="..."
45 /// SqlConnection="..."
46 /// SqliteConnection="..."
47 ///
48 /// Note that the conn string may also be set explicitly in the [TestCase()] attribute of test classes
49 /// based on BasicDataServiceTest.cs.
50 /// </summary>
51
52 static class DefaultTestConns
53 {
54 private static Dictionary<Type, string> conns = new Dictionary<Type, string>();
55
56 public static string Get(Type connType)
57 {
58 string sConn;
59
60 if (conns.TryGetValue(connType, out sConn))
61 return sConn;
62
63 Assembly asm = Assembly.GetExecutingAssembly();
64 string sType = connType.Name;
65
66 // Note: when running from NUnit, the DLL is located in some temp dir, so how do we get
67 // to the INI file? Ok, so put it into the resources!
68 // string iniName = Path.Combine(Path.GetDirectoryName(asm.Location), "TestDataConnections.ini");
69
70 string[] allres = asm.GetManifestResourceNames();
71 string sResFile = Array.Find(allres, s => s.Contains("TestDataConnections.ini"));
72
73 if (String.IsNullOrEmpty(sResFile))
74 throw new Exception(String.Format("Please add resource TestDataConnections.ini, with section [TestConnections] and settings like {0}=\"...\"",
75 sType));
76
77 using (Stream resource = asm.GetManifestResourceStream(sResFile))
78 {
79 IConfigSource source = new IniConfigSource(resource);
80 var cfg = source.Configs["TestConnections"];
81 sConn = cfg.Get(sType, "");
82 }
83
84 if (!String.IsNullOrEmpty(sConn))
85 conns[connType] = sConn;
86
87 return sConn;
88 }
89 }
90}
diff --git a/OpenSim/Data/Tests/EstateTests.cs b/OpenSim/Data/Tests/EstateTests.cs
new file mode 100644
index 0000000..e2b2d12
--- /dev/null
+++ b/OpenSim/Data/Tests/EstateTests.cs
@@ -0,0 +1,521 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using log4net.Config;
30using NUnit.Framework;
31using OpenMetaverse;
32using OpenSim.Framework;
33using OpenSim.Region.Framework.Interfaces;
34using OpenSim.Tests.Common;
35using System.Text;
36using log4net;
37using System.Reflection;
38using System.Data.Common;
39
40// DBMS-specific:
41using MySql.Data.MySqlClient;
42using OpenSim.Data.MySQL;
43
44using Mono.Data.Sqlite;
45using OpenSim.Data.SQLite;
46
47namespace OpenSim.Data.Tests
48{
49 [TestFixture(Description = "Estate store tests (SQLite)")]
50 public class SQLiteEstateTests : EstateTests<SqliteConnection, SQLiteEstateStore>
51 {
52 }
53
54 [TestFixture(Description = "Estate store tests (MySQL)")]
55 public class MySqlEstateTests : EstateTests<MySqlConnection, MySQLEstateStore>
56 {
57 }
58
59 public class EstateTests<TConn, TEstateStore> : BasicDataServiceTest<TConn, TEstateStore>
60 where TConn : DbConnection, new()
61 where TEstateStore : class, IEstateDataStore, new()
62 {
63 public IEstateDataStore db;
64
65 public static UUID REGION_ID = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed7");
66
67 public static UUID USER_ID_1 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed1");
68 public static UUID USER_ID_2 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed2");
69
70 public static UUID MANAGER_ID_1 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed3");
71 public static UUID MANAGER_ID_2 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed4");
72
73 public static UUID GROUP_ID_1 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed5");
74 public static UUID GROUP_ID_2 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed6");
75
76 protected override void InitService(object service)
77 {
78 ClearDB();
79 db = (IEstateDataStore)service;
80 db.Initialise(m_connStr);
81 }
82
83 private void ClearDB()
84 {
85 // if a new table is added, it has to be dropped here
86 DropTables(
87 "estate_managers",
88 "estate_groups",
89 "estate_users",
90 "estateban",
91 "estate_settings",
92 "estate_map"
93 );
94 ResetMigrations("EstateStore");
95 }
96
97 #region 0Tests
98
99 [Test]
100 public void T010_EstateSettingsSimpleStorage_MinimumParameterSet()
101 {
102 TestHelpers.InMethod();
103
104 EstateSettingsSimpleStorage(
105 REGION_ID,
106 DataTestUtil.STRING_MIN,
107 DataTestUtil.UNSIGNED_INTEGER_MIN,
108 DataTestUtil.FLOAT_MIN,
109 DataTestUtil.INTEGER_MIN,
110 DataTestUtil.INTEGER_MIN,
111 DataTestUtil.INTEGER_MIN,
112 DataTestUtil.BOOLEAN_MIN,
113 DataTestUtil.BOOLEAN_MIN,
114 DataTestUtil.DOUBLE_MIN,
115 DataTestUtil.BOOLEAN_MIN,
116 DataTestUtil.BOOLEAN_MIN,
117 DataTestUtil.BOOLEAN_MIN,
118 DataTestUtil.BOOLEAN_MIN,
119 DataTestUtil.BOOLEAN_MIN,
120 DataTestUtil.BOOLEAN_MIN,
121 DataTestUtil.BOOLEAN_MIN,
122 DataTestUtil.BOOLEAN_MIN,
123 DataTestUtil.BOOLEAN_MIN,
124 DataTestUtil.BOOLEAN_MIN,
125 DataTestUtil.BOOLEAN_MIN,
126 DataTestUtil.BOOLEAN_MIN,
127 DataTestUtil.STRING_MIN,
128 DataTestUtil.UUID_MIN
129 );
130 }
131
132 [Test]
133 public void T011_EstateSettingsSimpleStorage_MaximumParameterSet()
134 {
135 TestHelpers.InMethod();
136
137 EstateSettingsSimpleStorage(
138 REGION_ID,
139 DataTestUtil.STRING_MAX(64),
140 DataTestUtil.UNSIGNED_INTEGER_MAX,
141 DataTestUtil.FLOAT_MAX,
142 DataTestUtil.INTEGER_MAX,
143 DataTestUtil.INTEGER_MAX,
144 DataTestUtil.INTEGER_MAX,
145 DataTestUtil.BOOLEAN_MAX,
146 DataTestUtil.BOOLEAN_MAX,
147 DataTestUtil.DOUBLE_MAX,
148 DataTestUtil.BOOLEAN_MAX,
149 DataTestUtil.BOOLEAN_MAX,
150 DataTestUtil.BOOLEAN_MAX,
151 DataTestUtil.BOOLEAN_MAX,
152 DataTestUtil.BOOLEAN_MAX,
153 DataTestUtil.BOOLEAN_MAX,
154 DataTestUtil.BOOLEAN_MAX,
155 DataTestUtil.BOOLEAN_MAX,
156 DataTestUtil.BOOLEAN_MAX,
157 DataTestUtil.BOOLEAN_MAX,
158 DataTestUtil.BOOLEAN_MAX,
159 DataTestUtil.BOOLEAN_MAX,
160 DataTestUtil.STRING_MAX(255),
161 DataTestUtil.UUID_MAX
162 );
163 }
164
165 [Test]
166 public void T012_EstateSettingsSimpleStorage_AccurateParameterSet()
167 {
168 TestHelpers.InMethod();
169
170 EstateSettingsSimpleStorage(
171 REGION_ID,
172 DataTestUtil.STRING_MAX(1),
173 DataTestUtil.UNSIGNED_INTEGER_MIN,
174 DataTestUtil.FLOAT_ACCURATE,
175 DataTestUtil.INTEGER_MIN,
176 DataTestUtil.INTEGER_MIN,
177 DataTestUtil.INTEGER_MIN,
178 DataTestUtil.BOOLEAN_MIN,
179 DataTestUtil.BOOLEAN_MIN,
180 DataTestUtil.DOUBLE_ACCURATE,
181 DataTestUtil.BOOLEAN_MIN,
182 DataTestUtil.BOOLEAN_MIN,
183 DataTestUtil.BOOLEAN_MIN,
184 DataTestUtil.BOOLEAN_MIN,
185 DataTestUtil.BOOLEAN_MIN,
186 DataTestUtil.BOOLEAN_MIN,
187 DataTestUtil.BOOLEAN_MIN,
188 DataTestUtil.BOOLEAN_MIN,
189 DataTestUtil.BOOLEAN_MIN,
190 DataTestUtil.BOOLEAN_MIN,
191 DataTestUtil.BOOLEAN_MIN,
192 DataTestUtil.BOOLEAN_MIN,
193 DataTestUtil.STRING_MAX(1),
194 DataTestUtil.UUID_MIN
195 );
196 }
197
198 [Test]
199 public void T012_EstateSettingsRandomStorage()
200 {
201 TestHelpers.InMethod();
202
203 // Letting estate store generate rows to database for us
204 EstateSettings originalSettings = db.LoadEstateSettings(REGION_ID, true);
205 new PropertyScrambler<EstateSettings>()
206 .DontScramble(x=>x.EstateID)
207 .Scramble(originalSettings);
208
209 // Saving settings.
210 db.StoreEstateSettings(originalSettings);
211
212 // Loading settings to another instance variable.
213 EstateSettings loadedSettings = db.LoadEstateSettings(REGION_ID, true);
214
215 // Checking that loaded values are correct.
216 Assert.That(loadedSettings, Constraints.PropertyCompareConstraint(originalSettings));
217 }
218
219 [Test]
220 public void T020_EstateSettingsManagerList()
221 {
222 TestHelpers.InMethod();
223
224 // Letting estate store generate rows to database for us
225 EstateSettings originalSettings = db.LoadEstateSettings(REGION_ID, true);
226
227 originalSettings.EstateManagers = new UUID[] { MANAGER_ID_1, MANAGER_ID_2 };
228
229 // Saving settings.
230 db.StoreEstateSettings(originalSettings);
231
232 // Loading settings to another instance variable.
233 EstateSettings loadedSettings = db.LoadEstateSettings(REGION_ID, true);
234
235 Assert.AreEqual(2, loadedSettings.EstateManagers.Length);
236 Assert.AreEqual(MANAGER_ID_1, loadedSettings.EstateManagers[0]);
237 Assert.AreEqual(MANAGER_ID_2, loadedSettings.EstateManagers[1]);
238 }
239
240 [Test]
241 public void T021_EstateSettingsUserList()
242 {
243 TestHelpers.InMethod();
244
245 // Letting estate store generate rows to database for us
246 EstateSettings originalSettings = db.LoadEstateSettings(REGION_ID, true);
247
248 originalSettings.EstateAccess = new UUID[] { USER_ID_1, USER_ID_2 };
249
250 // Saving settings.
251 db.StoreEstateSettings(originalSettings);
252
253 // Loading settings to another instance variable.
254 EstateSettings loadedSettings = db.LoadEstateSettings(REGION_ID, true);
255
256 Assert.AreEqual(2, loadedSettings.EstateAccess.Length);
257 Assert.AreEqual(USER_ID_1, loadedSettings.EstateAccess[0]);
258 Assert.AreEqual(USER_ID_2, loadedSettings.EstateAccess[1]);
259 }
260
261 [Test]
262 public void T022_EstateSettingsGroupList()
263 {
264 TestHelpers.InMethod();
265
266 // Letting estate store generate rows to database for us
267 EstateSettings originalSettings = db.LoadEstateSettings(REGION_ID, true);
268
269 originalSettings.EstateGroups = new UUID[] { GROUP_ID_1, GROUP_ID_2 };
270
271 // Saving settings.
272 db.StoreEstateSettings(originalSettings);
273
274 // Loading settings to another instance variable.
275 EstateSettings loadedSettings = db.LoadEstateSettings(REGION_ID, true);
276
277 Assert.AreEqual(2, loadedSettings.EstateAccess.Length);
278 Assert.AreEqual(GROUP_ID_1, loadedSettings.EstateGroups[0]);
279 Assert.AreEqual(GROUP_ID_2, loadedSettings.EstateGroups[1]);
280 }
281
282 [Test]
283 public void T022_EstateSettingsBanList()
284 {
285 TestHelpers.InMethod();
286
287 // Letting estate store generate rows to database for us
288 EstateSettings originalSettings = db.LoadEstateSettings(REGION_ID, true);
289
290 EstateBan estateBan1 = new EstateBan();
291 estateBan1.BannedUserID = DataTestUtil.UUID_MIN;
292
293 EstateBan estateBan2 = new EstateBan();
294 estateBan2.BannedUserID = DataTestUtil.UUID_MAX;
295
296 originalSettings.EstateBans = new EstateBan[] { estateBan1, estateBan2 };
297
298 // Saving settings.
299 db.StoreEstateSettings(originalSettings);
300
301 // Loading settings to another instance variable.
302 EstateSettings loadedSettings = db.LoadEstateSettings(REGION_ID, true);
303
304 Assert.AreEqual(2, loadedSettings.EstateBans.Length);
305 Assert.AreEqual(DataTestUtil.UUID_MIN, loadedSettings.EstateBans[0].BannedUserID);
306
307 Assert.AreEqual(DataTestUtil.UUID_MAX, loadedSettings.EstateBans[1].BannedUserID);
308
309 }
310
311 #endregion
312
313 #region Parametrizable Test Implementations
314
315 private void EstateSettingsSimpleStorage(
316 UUID regionId,
317 string estateName,
318 uint parentEstateID,
319 float billableFactor,
320 int pricePerMeter,
321 int redirectGridX,
322 int redirectGridY,
323 bool useGlobalTime,
324 bool fixedSun,
325 double sunPosition,
326 bool allowVoice,
327 bool allowDirectTeleport,
328 bool resetHomeOnTeleport,
329 bool denyAnonymous,
330 bool denyIdentified,
331 bool denyTransacted,
332 bool denyMinors,
333 bool abuseEmailToEstateOwner,
334 bool blockDwell,
335 bool estateSkipScripts,
336 bool taxFree,
337 bool publicAccess,
338 string abuseEmail,
339 UUID estateOwner
340 )
341 {
342
343 // Letting estate store generate rows to database for us
344 EstateSettings originalSettings = db.LoadEstateSettings(regionId, true);
345
346 SetEstateSettings(originalSettings,
347 estateName,
348 parentEstateID,
349 billableFactor,
350 pricePerMeter,
351 redirectGridX,
352 redirectGridY,
353 useGlobalTime,
354 fixedSun,
355 sunPosition,
356 allowVoice,
357 allowDirectTeleport,
358 resetHomeOnTeleport,
359 denyAnonymous,
360 denyIdentified,
361 denyTransacted,
362 denyMinors,
363 abuseEmailToEstateOwner,
364 blockDwell,
365 estateSkipScripts,
366 taxFree,
367 publicAccess,
368 abuseEmail,
369 estateOwner
370 );
371
372 // Saving settings.
373 db.StoreEstateSettings(originalSettings);
374
375 // Loading settings to another instance variable.
376 EstateSettings loadedSettings = db.LoadEstateSettings(regionId, true);
377
378 // Checking that loaded values are correct.
379 ValidateEstateSettings(loadedSettings,
380 estateName,
381 parentEstateID,
382 billableFactor,
383 pricePerMeter,
384 redirectGridX,
385 redirectGridY,
386 useGlobalTime,
387 fixedSun,
388 sunPosition,
389 allowVoice,
390 allowDirectTeleport,
391 resetHomeOnTeleport,
392 denyAnonymous,
393 denyIdentified,
394 denyTransacted,
395 denyMinors,
396 abuseEmailToEstateOwner,
397 blockDwell,
398 estateSkipScripts,
399 taxFree,
400 publicAccess,
401 abuseEmail,
402 estateOwner
403 );
404
405 }
406
407 #endregion
408
409 #region EstateSetting Initialization and Validation Methods
410
411 private void SetEstateSettings(
412 EstateSettings estateSettings,
413 string estateName,
414 uint parentEstateID,
415 float billableFactor,
416 int pricePerMeter,
417 int redirectGridX,
418 int redirectGridY,
419 bool useGlobalTime,
420 bool fixedSun,
421 double sunPosition,
422 bool allowVoice,
423 bool allowDirectTeleport,
424 bool resetHomeOnTeleport,
425 bool denyAnonymous,
426 bool denyIdentified,
427 bool denyTransacted,
428 bool denyMinors,
429 bool abuseEmailToEstateOwner,
430 bool blockDwell,
431 bool estateSkipScripts,
432 bool taxFree,
433 bool publicAccess,
434 string abuseEmail,
435 UUID estateOwner
436 )
437 {
438 estateSettings.EstateName = estateName;
439 estateSettings.ParentEstateID = parentEstateID;
440 estateSettings.BillableFactor = billableFactor;
441 estateSettings.PricePerMeter = pricePerMeter;
442 estateSettings.RedirectGridX = redirectGridX;
443 estateSettings.RedirectGridY = redirectGridY;
444 estateSettings.UseGlobalTime = useGlobalTime;
445 estateSettings.FixedSun = fixedSun;
446 estateSettings.SunPosition = sunPosition;
447 estateSettings.AllowVoice = allowVoice;
448 estateSettings.AllowDirectTeleport = allowDirectTeleport;
449 estateSettings.ResetHomeOnTeleport = resetHomeOnTeleport;
450 estateSettings.DenyAnonymous = denyAnonymous;
451 estateSettings.DenyIdentified = denyIdentified;
452 estateSettings.DenyTransacted = denyTransacted;
453 estateSettings.DenyMinors = denyMinors;
454 estateSettings.AbuseEmailToEstateOwner = abuseEmailToEstateOwner;
455 estateSettings.BlockDwell = blockDwell;
456 estateSettings.EstateSkipScripts = estateSkipScripts;
457 estateSettings.TaxFree = taxFree;
458 estateSettings.PublicAccess = publicAccess;
459 estateSettings.AbuseEmail = abuseEmail;
460 estateSettings.EstateOwner = estateOwner;
461 }
462
463 private void ValidateEstateSettings(
464 EstateSettings estateSettings,
465 string estateName,
466 uint parentEstateID,
467 float billableFactor,
468 int pricePerMeter,
469 int redirectGridX,
470 int redirectGridY,
471 bool useGlobalTime,
472 bool fixedSun,
473 double sunPosition,
474 bool allowVoice,
475 bool allowDirectTeleport,
476 bool resetHomeOnTeleport,
477 bool denyAnonymous,
478 bool denyIdentified,
479 bool denyTransacted,
480 bool denyMinors,
481 bool abuseEmailToEstateOwner,
482 bool blockDwell,
483 bool estateSkipScripts,
484 bool taxFree,
485 bool publicAccess,
486 string abuseEmail,
487 UUID estateOwner
488 )
489 {
490 Assert.AreEqual(estateName, estateSettings.EstateName);
491 Assert.AreEqual(parentEstateID, estateSettings.ParentEstateID);
492
493 DataTestUtil.AssertFloatEqualsWithTolerance(billableFactor, estateSettings.BillableFactor);
494
495 Assert.AreEqual(pricePerMeter, estateSettings.PricePerMeter);
496 Assert.AreEqual(redirectGridX, estateSettings.RedirectGridX);
497 Assert.AreEqual(redirectGridY, estateSettings.RedirectGridY);
498 Assert.AreEqual(useGlobalTime, estateSettings.UseGlobalTime);
499 Assert.AreEqual(fixedSun, estateSettings.FixedSun);
500
501 DataTestUtil.AssertDoubleEqualsWithTolerance(sunPosition, estateSettings.SunPosition);
502
503 Assert.AreEqual(allowVoice, estateSettings.AllowVoice);
504 Assert.AreEqual(allowDirectTeleport, estateSettings.AllowDirectTeleport);
505 Assert.AreEqual(resetHomeOnTeleport, estateSettings.ResetHomeOnTeleport);
506 Assert.AreEqual(denyAnonymous, estateSettings.DenyAnonymous);
507 Assert.AreEqual(denyIdentified, estateSettings.DenyIdentified);
508 Assert.AreEqual(denyTransacted, estateSettings.DenyTransacted);
509 Assert.AreEqual(denyMinors, estateSettings.DenyMinors);
510 Assert.AreEqual(abuseEmailToEstateOwner, estateSettings.AbuseEmailToEstateOwner);
511 Assert.AreEqual(blockDwell, estateSettings.BlockDwell);
512 Assert.AreEqual(estateSkipScripts, estateSettings.EstateSkipScripts);
513 Assert.AreEqual(taxFree, estateSettings.TaxFree);
514 Assert.AreEqual(publicAccess, estateSettings.PublicAccess);
515 Assert.AreEqual(abuseEmail, estateSettings.AbuseEmail);
516 Assert.AreEqual(estateOwner, estateSettings.EstateOwner);
517 }
518
519 #endregion
520 }
521} \ No newline at end of file
diff --git a/OpenSim/Data/Tests/InventoryTests.cs b/OpenSim/Data/Tests/InventoryTests.cs
new file mode 100644
index 0000000..3edf89d
--- /dev/null
+++ b/OpenSim/Data/Tests/InventoryTests.cs
@@ -0,0 +1,381 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using log4net.Config;
30using NUnit.Framework;
31using OpenMetaverse;
32using OpenSim.Framework;
33using OpenSim.Tests.Common;
34using log4net;
35using System.Reflection;
36using System.Data.Common;
37
38// DBMS-specific:
39using MySql.Data.MySqlClient;
40using OpenSim.Data.MySQL;
41
42using Mono.Data.Sqlite;
43using OpenSim.Data.SQLite;
44
45namespace OpenSim.Data.Tests
46{
47 [TestFixture(Description = "Inventory store tests (SQLite)")]
48 public class SQLiteInventoryTests : InventoryTests<SqliteConnection, SQLiteInventoryStore>
49 {
50 }
51
52 [TestFixture(Description = "Inventory store tests (MySQL)")]
53 public class MySqlInventoryTests : InventoryTests<MySqlConnection, MySQLInventoryData>
54 {
55 }
56
57 public class InventoryTests<TConn, TInvStore> : BasicDataServiceTest<TConn, TInvStore>
58 where TConn : DbConnection, new()
59 where TInvStore : class, IInventoryDataPlugin, new()
60 {
61 public IInventoryDataPlugin db;
62
63 public UUID zero = UUID.Zero;
64
65 public UUID folder1 = UUID.Random();
66 public UUID folder2 = UUID.Random();
67 public UUID folder3 = UUID.Random();
68 public UUID owner1 = UUID.Random();
69 public UUID owner2 = UUID.Random();
70 public UUID owner3 = UUID.Random();
71
72 public UUID item1 = UUID.Random();
73 public UUID item2 = UUID.Random();
74 public UUID item3 = UUID.Random();
75 public UUID asset1 = UUID.Random();
76 public UUID asset2 = UUID.Random();
77 public UUID asset3 = UUID.Random();
78
79 public string name1;
80 public string name2 = "First Level folder";
81 public string name3 = "First Level folder 2";
82 public string niname1 = "My Shirt";
83 public string iname1 = "Shirt";
84 public string iname2 = "Text Board";
85 public string iname3 = "No Pants Barrel";
86
87 public InventoryTests(string conn) : base(conn)
88 {
89 name1 = "Root Folder for " + owner1.ToString();
90 }
91 public InventoryTests() : this("") { }
92
93 protected override void InitService(object service)
94 {
95 ClearDB();
96 db = (IInventoryDataPlugin)service;
97 db.Initialise(m_connStr);
98 }
99
100 private void ClearDB()
101 {
102 DropTables("inventoryitems", "inventoryfolders");
103 ResetMigrations("InventoryStore");
104 }
105
106 [Test]
107 public void T001_LoadEmpty()
108 {
109 TestHelpers.InMethod();
110
111 Assert.That(db.getInventoryFolder(zero), Is.Null);
112 Assert.That(db.getInventoryFolder(folder1), Is.Null);
113 Assert.That(db.getInventoryFolder(folder2), Is.Null);
114 Assert.That(db.getInventoryFolder(folder3), Is.Null);
115
116 Assert.That(db.getInventoryItem(zero), Is.Null);
117 Assert.That(db.getInventoryItem(item1), Is.Null);
118 Assert.That(db.getInventoryItem(item2), Is.Null);
119 Assert.That(db.getInventoryItem(item3), Is.Null);
120
121 Assert.That(db.getUserRootFolder(zero), Is.Null);
122 Assert.That(db.getUserRootFolder(owner1), Is.Null);
123 }
124
125 // 01x - folder tests
126 [Test]
127 public void T010_FolderNonParent()
128 {
129 TestHelpers.InMethod();
130
131 InventoryFolderBase f1 = NewFolder(folder2, folder1, owner1, name2);
132 // the folder will go in
133 db.addInventoryFolder(f1);
134 InventoryFolderBase f1a = db.getUserRootFolder(owner1);
135 Assert.That(f1a, Is.Null);
136 }
137
138 [Test]
139 public void T011_FolderCreate()
140 {
141 TestHelpers.InMethod();
142
143 InventoryFolderBase f1 = NewFolder(folder1, zero, owner1, name1);
144 // TODO: this is probably wrong behavior, but is what we have
145 // db.updateInventoryFolder(f1);
146 // InventoryFolderBase f1a = db.getUserRootFolder(owner1);
147 // Assert.That(uuid1, Is.EqualTo(f1a.ID))
148 // Assert.That(name1, Text.Matches(f1a.Name), "Assert.That(name1, Text.Matches(f1a.Name))");
149 // Assert.That(db.getUserRootFolder(owner1), Is.Null);
150
151 // succeed with true
152 db.addInventoryFolder(f1);
153 InventoryFolderBase f1a = db.getUserRootFolder(owner1);
154 Assert.That(folder1, Is.EqualTo(f1a.ID), "Assert.That(folder1, Is.EqualTo(f1a.ID))");
155 Assert.That(name1, Is.StringMatching(f1a.Name), "Assert.That(name1, Text.Matches(f1a.Name))");
156 }
157
158 // we now have the following tree
159 // folder1
160 // +--- folder2
161 // +--- folder3
162
163 [Test]
164 public void T012_FolderList()
165 {
166 TestHelpers.InMethod();
167
168 InventoryFolderBase f2 = NewFolder(folder3, folder1, owner1, name3);
169 db.addInventoryFolder(f2);
170
171 Assert.That(db.getInventoryFolders(zero).Count, Is.EqualTo(1), "Assert.That(db.getInventoryFolders(zero).Count, Is.EqualTo(1))");
172 Assert.That(db.getInventoryFolders(folder1).Count, Is.EqualTo(2), "Assert.That(db.getInventoryFolders(folder1).Count, Is.EqualTo(2))");
173 Assert.That(db.getInventoryFolders(folder2).Count, Is.EqualTo(0), "Assert.That(db.getInventoryFolders(folder2).Count, Is.EqualTo(0))");
174 Assert.That(db.getInventoryFolders(folder3).Count, Is.EqualTo(0), "Assert.That(db.getInventoryFolders(folder3).Count, Is.EqualTo(0))");
175 Assert.That(db.getInventoryFolders(UUID.Random()).Count, Is.EqualTo(0), "Assert.That(db.getInventoryFolders(UUID.Random()).Count, Is.EqualTo(0))");
176
177 }
178
179 [Test]
180 public void T013_FolderHierarchy()
181 {
182 TestHelpers.InMethod();
183
184 int n = db.getFolderHierarchy(zero).Count; // (for dbg - easier to see what's returned)
185 Assert.That(n, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(zero).Count, Is.EqualTo(0))");
186 n = db.getFolderHierarchy(folder1).Count;
187 Assert.That(n, Is.EqualTo(2), "Assert.That(db.getFolderHierarchy(folder1).Count, Is.EqualTo(2))");
188 Assert.That(db.getFolderHierarchy(folder2).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(folder2).Count, Is.EqualTo(0))");
189 Assert.That(db.getFolderHierarchy(folder3).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(folder3).Count, Is.EqualTo(0))");
190 Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0))");
191 }
192
193
194 [Test]
195 public void T014_MoveFolder()
196 {
197 TestHelpers.InMethod();
198
199 InventoryFolderBase f2 = db.getInventoryFolder(folder2);
200 f2.ParentID = folder3;
201 db.moveInventoryFolder(f2);
202
203 Assert.That(db.getInventoryFolders(zero).Count, Is.EqualTo(1), "Assert.That(db.getInventoryFolders(zero).Count, Is.EqualTo(1))");
204 Assert.That(db.getInventoryFolders(folder1).Count, Is.EqualTo(1), "Assert.That(db.getInventoryFolders(folder1).Count, Is.EqualTo(1))");
205 Assert.That(db.getInventoryFolders(folder2).Count, Is.EqualTo(0), "Assert.That(db.getInventoryFolders(folder2).Count, Is.EqualTo(0))");
206 Assert.That(db.getInventoryFolders(folder3).Count, Is.EqualTo(1), "Assert.That(db.getInventoryFolders(folder3).Count, Is.EqualTo(1))");
207 Assert.That(db.getInventoryFolders(UUID.Random()).Count, Is.EqualTo(0), "Assert.That(db.getInventoryFolders(UUID.Random()).Count, Is.EqualTo(0))");
208 }
209
210 [Test]
211 public void T015_FolderHierarchy()
212 {
213 TestHelpers.InMethod();
214
215 Assert.That(db.getFolderHierarchy(zero).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(zero).Count, Is.EqualTo(0))");
216 Assert.That(db.getFolderHierarchy(folder1).Count, Is.EqualTo(2), "Assert.That(db.getFolderHierarchy(folder1).Count, Is.EqualTo(2))");
217 Assert.That(db.getFolderHierarchy(folder2).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(folder2).Count, Is.EqualTo(0))");
218 Assert.That(db.getFolderHierarchy(folder3).Count, Is.EqualTo(1), "Assert.That(db.getFolderHierarchy(folder3).Count, Is.EqualTo(1))");
219 Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0))");
220 }
221
222 // Item tests
223 [Test]
224 public void T100_NoItems()
225 {
226 TestHelpers.InMethod();
227
228 Assert.That(db.getInventoryInFolder(zero).Count, Is.EqualTo(0), "Assert.That(db.getInventoryInFolder(zero).Count, Is.EqualTo(0))");
229 Assert.That(db.getInventoryInFolder(folder1).Count, Is.EqualTo(0), "Assert.That(db.getInventoryInFolder(folder1).Count, Is.EqualTo(0))");
230 Assert.That(db.getInventoryInFolder(folder2).Count, Is.EqualTo(0), "Assert.That(db.getInventoryInFolder(folder2).Count, Is.EqualTo(0))");
231 Assert.That(db.getInventoryInFolder(folder3).Count, Is.EqualTo(0), "Assert.That(db.getInventoryInFolder(folder3).Count, Is.EqualTo(0))");
232 }
233
234 // TODO: Feeding a bad inventory item down the data path will
235 // crash the system. This is largely due to the builder
236 // routines. That should be fixed and tested for.
237 [Test]
238 public void T101_CreatItems()
239 {
240 TestHelpers.InMethod();
241
242 db.addInventoryItem(NewItem(item1, folder3, owner1, iname1, asset1));
243 db.addInventoryItem(NewItem(item2, folder3, owner1, iname2, asset2));
244 db.addInventoryItem(NewItem(item3, folder3, owner1, iname3, asset3));
245 Assert.That(db.getInventoryInFolder(folder3).Count, Is.EqualTo(3), "Assert.That(db.getInventoryInFolder(folder3).Count, Is.EqualTo(3))");
246 }
247
248 [Test]
249 public void T102_CompareItems()
250 {
251 TestHelpers.InMethod();
252
253 InventoryItemBase i1 = db.getInventoryItem(item1);
254 InventoryItemBase i2 = db.getInventoryItem(item2);
255 InventoryItemBase i3 = db.getInventoryItem(item3);
256 Assert.That(i1.Name, Is.EqualTo(iname1), "Assert.That(i1.Name, Is.EqualTo(iname1))");
257 Assert.That(i2.Name, Is.EqualTo(iname2), "Assert.That(i2.Name, Is.EqualTo(iname2))");
258 Assert.That(i3.Name, Is.EqualTo(iname3), "Assert.That(i3.Name, Is.EqualTo(iname3))");
259 Assert.That(i1.Owner, Is.EqualTo(owner1), "Assert.That(i1.Owner, Is.EqualTo(owner1))");
260 Assert.That(i2.Owner, Is.EqualTo(owner1), "Assert.That(i2.Owner, Is.EqualTo(owner1))");
261 Assert.That(i3.Owner, Is.EqualTo(owner1), "Assert.That(i3.Owner, Is.EqualTo(owner1))");
262 Assert.That(i1.AssetID, Is.EqualTo(asset1), "Assert.That(i1.AssetID, Is.EqualTo(asset1))");
263 Assert.That(i2.AssetID, Is.EqualTo(asset2), "Assert.That(i2.AssetID, Is.EqualTo(asset2))");
264 Assert.That(i3.AssetID, Is.EqualTo(asset3), "Assert.That(i3.AssetID, Is.EqualTo(asset3))");
265 }
266
267 [Test]
268 public void T103_UpdateItem()
269 {
270 TestHelpers.InMethod();
271
272 // TODO: probably shouldn't have the ability to have an
273 // owner of an item in a folder not owned by the user
274
275 InventoryItemBase i1 = db.getInventoryItem(item1);
276 i1.Name = niname1;
277 i1.Description = niname1;
278 i1.Owner = owner2;
279 db.updateInventoryItem(i1);
280
281 i1 = db.getInventoryItem(item1);
282 Assert.That(i1.Name, Is.EqualTo(niname1), "Assert.That(i1.Name, Is.EqualTo(niname1))");
283 Assert.That(i1.Description, Is.EqualTo(niname1), "Assert.That(i1.Description, Is.EqualTo(niname1))");
284 Assert.That(i1.Owner, Is.EqualTo(owner2), "Assert.That(i1.Owner, Is.EqualTo(owner2))");
285 }
286
287 [Test]
288 public void T104_RandomUpdateItem()
289 {
290 TestHelpers.InMethod();
291
292 PropertyScrambler<InventoryFolderBase> folderScrambler =
293 new PropertyScrambler<InventoryFolderBase>()
294 .DontScramble(x => x.Owner)
295 .DontScramble(x => x.ParentID)
296 .DontScramble(x => x.ID);
297 UUID owner = UUID.Random();
298 UUID folder = UUID.Random();
299 UUID rootId = UUID.Random();
300 UUID rootAsset = UUID.Random();
301 InventoryFolderBase f1 = NewFolder(folder, zero, owner, name1);
302 folderScrambler.Scramble(f1);
303
304 db.addInventoryFolder(f1);
305 InventoryFolderBase f1a = db.getUserRootFolder(owner);
306 Assert.That(f1a, Constraints.PropertyCompareConstraint(f1));
307
308 folderScrambler.Scramble(f1a);
309
310 db.updateInventoryFolder(f1a);
311
312 InventoryFolderBase f1b = db.getUserRootFolder(owner);
313 Assert.That(f1b, Constraints.PropertyCompareConstraint(f1a));
314
315 //Now we have a valid folder to insert into, we can insert the item.
316 PropertyScrambler<InventoryItemBase> inventoryScrambler =
317 new PropertyScrambler<InventoryItemBase>()
318 .DontScramble(x => x.ID)
319 .DontScramble(x => x.AssetID)
320 .DontScramble(x => x.Owner)
321 .DontScramble(x => x.Folder);
322 InventoryItemBase root = NewItem(rootId, folder, owner, iname1, rootAsset);
323 inventoryScrambler.Scramble(root);
324 db.addInventoryItem(root);
325
326 InventoryItemBase expected = db.getInventoryItem(rootId);
327 Assert.That(expected, Constraints.PropertyCompareConstraint(root)
328 .IgnoreProperty(x => x.InvType)
329 .IgnoreProperty(x => x.CreatorIdAsUuid)
330 .IgnoreProperty(x => x.Description)
331 .IgnoreProperty(x => x.CreatorIdentification)
332 .IgnoreProperty(x => x.CreatorData));
333
334 inventoryScrambler.Scramble(expected);
335 db.updateInventoryItem(expected);
336
337 InventoryItemBase actual = db.getInventoryItem(rootId);
338 Assert.That(actual, Constraints.PropertyCompareConstraint(expected)
339 .IgnoreProperty(x => x.InvType)
340 .IgnoreProperty(x => x.CreatorIdAsUuid)
341 .IgnoreProperty(x => x.Description)
342 .IgnoreProperty(x => x.CreatorIdentification)
343 .IgnoreProperty(x => x.CreatorData));
344 }
345
346 [Test]
347 public void T999_StillNull()
348 {
349 TestHelpers.InMethod();
350
351 // After all tests are run, these should still return no results
352 Assert.That(db.getInventoryFolder(zero), Is.Null);
353 Assert.That(db.getInventoryItem(zero), Is.Null);
354 Assert.That(db.getUserRootFolder(zero), Is.Null);
355 Assert.That(db.getInventoryInFolder(zero).Count, Is.EqualTo(0), "Assert.That(db.getInventoryInFolder(zero).Count, Is.EqualTo(0))");
356 }
357
358 private InventoryItemBase NewItem(UUID id, UUID parent, UUID owner, string name, UUID asset)
359 {
360 InventoryItemBase i = new InventoryItemBase();
361 i.ID = id;
362 i.Folder = parent;
363 i.Owner = owner;
364 i.CreatorId = owner.ToString();
365 i.Name = name;
366 i.Description = name;
367 i.AssetID = asset;
368 return i;
369 }
370
371 private InventoryFolderBase NewFolder(UUID id, UUID parent, UUID owner, string name)
372 {
373 InventoryFolderBase f = new InventoryFolderBase();
374 f.ID = id;
375 f.ParentID = parent;
376 f.Owner = owner;
377 f.Name = name;
378 return f;
379 }
380 }
381}
diff --git a/OpenSim/Data/Tests/PropertyCompareConstraint.cs b/OpenSim/Data/Tests/PropertyCompareConstraint.cs
new file mode 100644
index 0000000..b99525a
--- /dev/null
+++ b/OpenSim/Data/Tests/PropertyCompareConstraint.cs
@@ -0,0 +1,413 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Drawing;
32using System.Linq;
33using System.Linq.Expressions;
34using System.Reflection;
35using NUnit.Framework;
36using NUnit.Framework.Constraints;
37using OpenMetaverse;
38using OpenSim.Framework;
39using OpenSim.Tests.Common;
40
41namespace OpenSim.Data.Tests
42{
43 public static class Constraints
44 {
45 //This is here because C# has a gap in the language, you can't infer type from a constructor
46 public static PropertyCompareConstraint<T> PropertyCompareConstraint<T>(T expected)
47 {
48 return new PropertyCompareConstraint<T>(expected);
49 }
50 }
51
52 public class PropertyCompareConstraint<T> : NUnit.Framework.Constraints.Constraint
53 {
54 private readonly object _expected;
55 //the reason everywhere uses propertyNames.Reverse().ToArray() is because the stack is backwards of the order we want to display the properties in.
56 private string failingPropertyName = string.Empty;
57 private object failingExpected;
58 private object failingActual;
59
60 public PropertyCompareConstraint(T expected)
61 {
62 _expected = expected;
63 }
64
65 public override bool Matches(object actual)
66 {
67 return ObjectCompare(_expected, actual, new Stack<string>());
68 }
69
70 private bool ObjectCompare(object expected, object actual, Stack<string> propertyNames)
71 {
72 //If they are both null, they are equal
73 if (actual == null && expected == null)
74 return true;
75
76 //If only one is null, then they aren't
77 if (actual == null || expected == null)
78 {
79 failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray());
80 failingActual = actual;
81 failingExpected = expected;
82 return false;
83 }
84
85 //prevent loops...
86 if (propertyNames.Count > 50)
87 {
88 failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray());
89 failingActual = actual;
90 failingExpected = expected;
91 return false;
92 }
93
94 if (actual.GetType() != expected.GetType())
95 {
96 propertyNames.Push("GetType()");
97 failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray());
98 propertyNames.Pop();
99 failingActual = actual.GetType();
100 failingExpected = expected.GetType();
101 return false;
102 }
103
104 if (actual.GetType() == typeof(Color))
105 {
106 Color actualColor = (Color) actual;
107 Color expectedColor = (Color) expected;
108 if (actualColor.R != expectedColor.R)
109 {
110 propertyNames.Push("R");
111 failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray());
112 propertyNames.Pop();
113 failingActual = actualColor.R;
114 failingExpected = expectedColor.R;
115 return false;
116 }
117 if (actualColor.G != expectedColor.G)
118 {
119 propertyNames.Push("G");
120 failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray());
121 propertyNames.Pop();
122 failingActual = actualColor.G;
123 failingExpected = expectedColor.G;
124 return false;
125 }
126 if (actualColor.B != expectedColor.B)
127 {
128 propertyNames.Push("B");
129 failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray());
130 propertyNames.Pop();
131 failingActual = actualColor.B;
132 failingExpected = expectedColor.B;
133 return false;
134 }
135 if (actualColor.A != expectedColor.A)
136 {
137 propertyNames.Push("A");
138 failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray());
139 propertyNames.Pop();
140 failingActual = actualColor.A;
141 failingExpected = expectedColor.A;
142 return false;
143 }
144 return true;
145 }
146
147 IComparable comp = actual as IComparable;
148 if (comp != null)
149 {
150 if (comp.CompareTo(expected) != 0)
151 {
152 failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray());
153 failingActual = actual;
154 failingExpected = expected;
155 return false;
156 }
157 return true;
158 }
159
160 //Now try the much more annoying IComparable<T>
161 Type icomparableInterface = actual.GetType().GetInterface("IComparable`1");
162 if (icomparableInterface != null)
163 {
164 int result = (int)icomparableInterface.GetMethod("CompareTo").Invoke(actual, new[] { expected });
165 if (result != 0)
166 {
167 failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray());
168 failingActual = actual;
169 failingExpected = expected;
170 return false;
171 }
172 return true;
173 }
174
175 IEnumerable arr = actual as IEnumerable;
176 if (arr != null)
177 {
178 List<object> actualList = arr.Cast<object>().ToList();
179 List<object> expectedList = ((IEnumerable)expected).Cast<object>().ToList();
180 if (actualList.Count != expectedList.Count)
181 {
182 propertyNames.Push("Count");
183 failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray());
184 failingActual = actualList.Count;
185 failingExpected = expectedList.Count;
186 propertyNames.Pop();
187 return false;
188 }
189 //actualList and expectedList should be the same size.
190 for (int i = 0; i < actualList.Count; i++)
191 {
192 propertyNames.Push("[" + i + "]");
193 if (!ObjectCompare(expectedList[i], actualList[i], propertyNames))
194 return false;
195 propertyNames.Pop();
196 }
197 //Everything seems okay...
198 return true;
199 }
200
201 //Skip static properties. I had a nasty problem comparing colors because of all of the public static colors.
202 PropertyInfo[] properties = expected.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
203 foreach (var property in properties)
204 {
205 if (ignores.Contains(property.Name))
206 continue;
207
208 object actualValue = property.GetValue(actual, null);
209 object expectedValue = property.GetValue(expected, null);
210
211 propertyNames.Push(property.Name);
212 if (!ObjectCompare(expectedValue, actualValue, propertyNames))
213 return false;
214 propertyNames.Pop();
215 }
216
217 return true;
218 }
219
220 public override void WriteDescriptionTo(MessageWriter writer)
221 {
222 writer.WriteExpectedValue(failingExpected);
223 }
224
225 public override void WriteActualValueTo(MessageWriter writer)
226 {
227 writer.WriteActualValue(failingActual);
228 writer.WriteLine();
229 writer.Write(" On Property: " + failingPropertyName);
230 }
231
232 //These notes assume the lambda: (x=>x.Parent.Value)
233 //ignores should really contain like a fully dotted version of the property name, but I'm starting with small steps
234 readonly List<string> ignores = new List<string>();
235 public PropertyCompareConstraint<T> IgnoreProperty(Expression<Func<T, object>> func)
236 {
237 Expression express = func.Body;
238 PullApartExpression(express);
239
240 return this;
241 }
242
243 private void PullApartExpression(Expression express)
244 {
245 //This deals with any casts... like implicit casts to object. Not all UnaryExpression are casts, but this is a first attempt.
246 if (express is UnaryExpression)
247 PullApartExpression(((UnaryExpression)express).Operand);
248 if (express is MemberExpression)
249 {
250 //If the inside of the lambda is the access to x, we've hit the end of the chain.
251 // We should track by the fully scoped parameter name, but this is the first rev of doing this.
252 ignores.Add(((MemberExpression)express).Member.Name);
253 }
254 }
255 }
256
257 [TestFixture]
258 public class PropertyCompareConstraintTest : OpenSimTestCase
259 {
260 public class HasInt
261 {
262 public int TheValue { get; set; }
263 }
264
265 [Test]
266 public void IntShouldMatch()
267 {
268 HasInt actual = new HasInt { TheValue = 5 };
269 HasInt expected = new HasInt { TheValue = 5 };
270 var constraint = Constraints.PropertyCompareConstraint(expected);
271
272 Assert.That(constraint.Matches(actual), Is.True);
273 }
274
275 [Test]
276 public void IntShouldNotMatch()
277 {
278 HasInt actual = new HasInt { TheValue = 5 };
279 HasInt expected = new HasInt { TheValue = 4 };
280 var constraint = Constraints.PropertyCompareConstraint(expected);
281
282 Assert.That(constraint.Matches(actual), Is.False);
283 }
284
285
286 [Test]
287 public void IntShouldIgnore()
288 {
289 HasInt actual = new HasInt { TheValue = 5 };
290 HasInt expected = new HasInt { TheValue = 4 };
291 var constraint = Constraints.PropertyCompareConstraint(expected).IgnoreProperty(x => x.TheValue);
292
293 Assert.That(constraint.Matches(actual), Is.True);
294 }
295
296 [Test]
297 public void AssetShouldMatch()
298 {
299 UUID uuid1 = UUID.Random();
300 AssetBase actual = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture, UUID.Zero.ToString());
301 AssetBase expected = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture, UUID.Zero.ToString());
302
303 var constraint = Constraints.PropertyCompareConstraint(expected);
304
305 Assert.That(constraint.Matches(actual), Is.True);
306 }
307
308 [Test]
309 public void AssetShouldNotMatch()
310 {
311 UUID uuid1 = UUID.Random();
312 AssetBase actual = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture, UUID.Zero.ToString());
313 AssetBase expected = new AssetBase(UUID.Random(), "asset one", (sbyte)AssetType.Texture, UUID.Zero.ToString());
314
315 var constraint = Constraints.PropertyCompareConstraint(expected);
316
317 Assert.That(constraint.Matches(actual), Is.False);
318 }
319
320 [Test]
321 public void AssetShouldNotMatch2()
322 {
323 UUID uuid1 = UUID.Random();
324 AssetBase actual = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture, UUID.Zero.ToString());
325 AssetBase expected = new AssetBase(uuid1, "asset two", (sbyte)AssetType.Texture, UUID.Zero.ToString());
326
327 var constraint = Constraints.PropertyCompareConstraint(expected);
328
329 Assert.That(constraint.Matches(actual), Is.False);
330 }
331
332 [Test]
333 public void UUIDShouldMatch()
334 {
335 UUID uuid1 = UUID.Random();
336 UUID uuid2 = UUID.Parse(uuid1.ToString());
337
338 var constraint = Constraints.PropertyCompareConstraint(uuid1);
339
340 Assert.That(constraint.Matches(uuid2), Is.True);
341 }
342
343 [Test]
344 public void UUIDShouldNotMatch()
345 {
346 UUID uuid1 = UUID.Random();
347 UUID uuid2 = UUID.Random();
348
349 var constraint = Constraints.PropertyCompareConstraint(uuid1);
350
351 Assert.That(constraint.Matches(uuid2), Is.False);
352 }
353
354 [Test]
355 public void TestColors()
356 {
357 Color actual = Color.Red;
358 Color expected = Color.FromArgb(actual.A, actual.R, actual.G, actual.B);
359
360 var constraint = Constraints.PropertyCompareConstraint(expected);
361
362 Assert.That(constraint.Matches(actual), Is.True);
363 }
364
365 [Test]
366 public void ShouldCompareLists()
367 {
368 List<int> expected = new List<int> { 1, 2, 3 };
369 List<int> actual = new List<int> { 1, 2, 3 };
370
371 var constraint = Constraints.PropertyCompareConstraint(expected);
372 Assert.That(constraint.Matches(actual), Is.True);
373 }
374
375
376 [Test]
377 public void ShouldFailToCompareListsThatAreDifferent()
378 {
379 List<int> expected = new List<int> { 1, 2, 3 };
380 List<int> actual = new List<int> { 1, 2, 4 };
381
382 var constraint = Constraints.PropertyCompareConstraint(expected);
383 Assert.That(constraint.Matches(actual), Is.False);
384 }
385
386 [Test]
387 public void ShouldFailToCompareListsThatAreDifferentLengths()
388 {
389 List<int> expected = new List<int> { 1, 2, 3 };
390 List<int> actual = new List<int> { 1, 2 };
391
392 var constraint = Constraints.PropertyCompareConstraint(expected);
393 Assert.That(constraint.Matches(actual), Is.False);
394 }
395
396 public class Recursive
397 {
398 public Recursive Other { get; set; }
399 }
400
401 [Test]
402 public void ErrorsOutOnRecursive()
403 {
404 Recursive parent = new Recursive();
405 Recursive child = new Recursive();
406 parent.Other = child;
407 child.Other = parent;
408
409 var constraint = Constraints.PropertyCompareConstraint(child);
410 Assert.That(constraint.Matches(child), Is.False);
411 }
412 }
413} \ No newline at end of file
diff --git a/OpenSim/Data/Tests/PropertyScrambler.cs b/OpenSim/Data/Tests/PropertyScrambler.cs
new file mode 100644
index 0000000..e0f5862
--- /dev/null
+++ b/OpenSim/Data/Tests/PropertyScrambler.cs
@@ -0,0 +1,184 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Linq.Expressions;
32using System.Reflection;
33using System.Text;
34using NUnit.Framework;
35using OpenMetaverse;
36using OpenSim.Framework;
37using OpenSim.Tests.Common;
38
39namespace OpenSim.Data.Tests
40{
41 //This is generic so that the lambda expressions will work right in IDEs.
42 public class PropertyScrambler<T>
43 {
44 readonly System.Collections.Generic.List<string> membersToNotScramble = new List<string>();
45
46 private void AddExpressionToNotScrableList(Expression expression)
47 {
48 UnaryExpression unaryExpression = expression as UnaryExpression;
49 if (unaryExpression != null)
50 {
51 AddExpressionToNotScrableList(unaryExpression.Operand);
52 return;
53 }
54
55 MemberExpression memberExpression = expression as MemberExpression;
56 if (memberExpression != null)
57 {
58 if (!(memberExpression.Member is PropertyInfo))
59 {
60 throw new NotImplementedException("I don't know how deal with a MemberExpression that is a " + expression.Type);
61 }
62 membersToNotScramble.Add(memberExpression.Member.Name);
63 return;
64 }
65
66 throw new NotImplementedException("I don't know how to parse a " + expression.Type);
67 }
68
69 public PropertyScrambler<T> DontScramble(Expression<Func<T, object>> expression)
70 {
71 AddExpressionToNotScrableList(expression.Body);
72 return this;
73 }
74
75 public void Scramble(T obj)
76 {
77 internalScramble(obj);
78 }
79
80 private void internalScramble(object obj)
81 {
82 PropertyInfo[] properties = obj.GetType().GetProperties();
83 foreach (var property in properties)
84 {
85 //Skip indexers of classes. We will assume that everything that has an indexer
86 // is also IEnumberable. May not always be true, but should be true normally.
87 if (property.GetIndexParameters().Length > 0)
88 continue;
89
90 RandomizeProperty(obj, property, null);
91 }
92 //Now if it implments IEnumberable, it's probably some kind of list, so we should randomize
93 // everything inside of it.
94 IEnumerable enumerable = obj as IEnumerable;
95 if (enumerable != null)
96 {
97 foreach (object value in enumerable)
98 {
99 internalScramble(value);
100 }
101 }
102 }
103
104 private readonly Random random = new Random();
105 private void RandomizeProperty(object obj, PropertyInfo property, object[] index)
106 {//I'd like a better way to compare, but I had lots of problems with InventoryFolderBase because the ID is inherited.
107 if (membersToNotScramble.Contains(property.Name))
108 return;
109 Type t = property.PropertyType;
110 if (!property.CanWrite)
111 return;
112 object value = property.GetValue(obj, index);
113 if (value == null)
114 return;
115
116 if (t == typeof(string))
117 property.SetValue(obj, RandomName(), index);
118 else if (t == typeof(UUID))
119 property.SetValue(obj, UUID.Random(), index);
120 else if (t == typeof(sbyte))
121 property.SetValue(obj, (sbyte)random.Next(sbyte.MinValue, sbyte.MaxValue), index);
122 else if (t == typeof(short))
123 property.SetValue(obj, (short)random.Next(short.MinValue, short.MaxValue), index);
124 else if (t == typeof(int))
125 property.SetValue(obj, random.Next(), index);
126 else if (t == typeof(long))
127 property.SetValue(obj, random.Next() * int.MaxValue, index);
128 else if (t == typeof(byte))
129 property.SetValue(obj, (byte)random.Next(byte.MinValue, byte.MaxValue), index);
130 else if (t == typeof(ushort))
131 property.SetValue(obj, (ushort)random.Next(ushort.MinValue, ushort.MaxValue), index);
132 else if (t == typeof(uint))
133 property.SetValue(obj, Convert.ToUInt32(random.Next()), index);
134 else if (t == typeof(ulong))
135 property.SetValue(obj, Convert.ToUInt64(random.Next()) * Convert.ToUInt64(UInt32.MaxValue), index);
136 else if (t == typeof(bool))
137 property.SetValue(obj, true, index);
138 else if (t == typeof(byte[]))
139 {
140 byte[] bytes = new byte[30];
141 random.NextBytes(bytes);
142 property.SetValue(obj, bytes, index);
143 }
144 else
145 internalScramble(value);
146 }
147
148 private string RandomName()
149 {
150 StringBuilder name = new StringBuilder();
151 int size = random.Next(5, 12);
152 for (int i = 0; i < size; i++)
153 {
154 char ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
155 name.Append(ch);
156 }
157 return name.ToString();
158 }
159 }
160
161 [TestFixture]
162 public class PropertyScramblerTests : OpenSimTestCase
163 {
164 [Test]
165 public void TestScramble()
166 {
167 AssetBase actual = new AssetBase(UUID.Random(), "asset one", (sbyte)AssetType.Texture, UUID.Zero.ToString());
168 new PropertyScrambler<AssetBase>().Scramble(actual);
169 }
170
171 [Test]
172 public void DontScramble()
173 {
174 UUID uuid = UUID.Random();
175 AssetBase asset = new AssetBase(uuid, "asset", (sbyte)AssetType.Texture, UUID.Zero.ToString());
176 new PropertyScrambler<AssetBase>()
177 .DontScramble(x => x.Metadata)
178 .DontScramble(x => x.FullID)
179 .DontScramble(x => x.ID)
180 .Scramble(asset);
181 Assert.That(asset.FullID, Is.EqualTo(uuid));
182 }
183 }
184} \ No newline at end of file
diff --git a/OpenSim/Data/Tests/RegionTests.cs b/OpenSim/Data/Tests/RegionTests.cs
new file mode 100644
index 0000000..8d4249a
--- /dev/null
+++ b/OpenSim/Data/Tests/RegionTests.cs
@@ -0,0 +1,1129 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Drawing;
31using System.Text;
32using log4net.Config;
33using NUnit.Framework;
34using OpenMetaverse;
35using OpenSim.Framework;
36using OpenSim.Region.Framework.Interfaces;
37using OpenSim.Region.Framework.Scenes;
38using OpenSim.Tests.Common;
39using log4net;
40using System.Reflection;
41using System.Data.Common;
42
43// DBMS-specific:
44using MySql.Data.MySqlClient;
45using OpenSim.Data.MySQL;
46
47using Mono.Data.Sqlite;
48using OpenSim.Data.SQLite;
49
50namespace OpenSim.Data.Tests
51{
52 [TestFixture(Description = "Region store tests (SQLite)")]
53 public class SQLiteRegionTests : RegionTests<SqliteConnection, SQLiteSimulationData>
54 {
55 }
56
57 [TestFixture(Description = "Region store tests (MySQL)")]
58 public class MySqlRegionTests : RegionTests<MySqlConnection, MySQLSimulationData>
59 {
60 }
61
62 public class RegionTests<TConn, TRegStore> : BasicDataServiceTest<TConn, TRegStore>
63 where TConn : DbConnection, new()
64 where TRegStore : class, ISimulationDataStore, new()
65 {
66 bool m_rebuildDB;
67
68 public ISimulationDataStore db;
69 public UUID zero = UUID.Zero;
70 public UUID region1 = UUID.Random();
71 public UUID region2 = UUID.Random();
72 public UUID region3 = UUID.Random();
73 public UUID region4 = UUID.Random();
74 public UUID prim1 = UUID.Random();
75 public UUID prim2 = UUID.Random();
76 public UUID prim3 = UUID.Random();
77 public UUID prim4 = UUID.Random();
78 public UUID prim5 = UUID.Random();
79 public UUID prim6 = UUID.Random();
80 public UUID item1 = UUID.Random();
81 public UUID item2 = UUID.Random();
82 public UUID item3 = UUID.Random();
83
84 public static Random random = new Random();
85
86 public string itemname1 = "item1";
87
88 public uint localID = 1;
89
90 public double height1 = 20;
91 public double height2 = 100;
92
93 public RegionTests(string conn, bool rebuild)
94 : base(conn)
95 {
96 m_rebuildDB = rebuild;
97 }
98
99 public RegionTests() : this("", true) { }
100 public RegionTests(string conn) : this(conn, true) {}
101 public RegionTests(bool rebuild): this("", rebuild) {}
102
103
104 protected override void InitService(object service)
105 {
106 ClearDB();
107 db = (ISimulationDataStore)service;
108 db.Initialise(m_connStr);
109 }
110
111 private void ClearDB()
112 {
113 string[] reg_tables = new string[] {
114 "prims", "primshapes", "primitems", "terrain", "land", "landaccesslist", "regionban", "regionsettings"
115 };
116
117 if (m_rebuildDB)
118 {
119 DropTables(reg_tables);
120 ResetMigrations("RegionStore");
121 }
122 else
123 {
124 ClearTables(reg_tables);
125 }
126 }
127
128 // Test Plan
129 // Prims
130 // - empty test - 001
131 // - store / retrieve basic prims (most minimal we can make) - 010, 011
132 // - store / retrieve parts in a scenegroup 012
133 // - store a prim with complete information for consistency check 013
134 // - update existing prims, make sure it sticks - 014
135 // - tests empty inventory - 020
136 // - add inventory items to prims make - 021
137 // - retrieves the added item - 022
138 // - update inventory items to prims - 023
139 // - remove inventory items make sure it sticks - 024
140 // - checks if all parameters are persistent - 025
141 // - adds many items and see if it is handled correctly - 026
142
143 [Test]
144 public void T001_LoadEmpty()
145 {
146 TestHelpers.InMethod();
147
148 List<SceneObjectGroup> objs = db.LoadObjects(region1);
149 List<SceneObjectGroup> objs3 = db.LoadObjects(region3);
150 List<LandData> land = db.LoadLandObjects(region1);
151
152 Assert.That(objs.Count, Is.EqualTo(0), "Assert.That(objs.Count, Is.EqualTo(0))");
153 Assert.That(objs3.Count, Is.EqualTo(0), "Assert.That(objs3.Count, Is.EqualTo(0))");
154 Assert.That(land.Count, Is.EqualTo(0), "Assert.That(land.Count, Is.EqualTo(0))");
155 }
156
157 // SOG round trips
158 // * store objects, make sure they save
159 // * update
160
161 [Test]
162 public void T010_StoreSimpleObject()
163 {
164 TestHelpers.InMethod();
165
166 SceneObjectGroup sog = NewSOG("object1", prim1, region1);
167 SceneObjectGroup sog2 = NewSOG("object2", prim2, region1);
168
169 // in case the objects don't store
170 try
171 {
172 db.StoreObject(sog, region1);
173 }
174 catch (Exception e)
175 {
176 m_log.Error(e.ToString());
177 Assert.Fail();
178 }
179
180 try
181 {
182 db.StoreObject(sog2, region1);
183 }
184 catch (Exception e)
185 {
186 m_log.Error(e.ToString());
187 Assert.Fail();
188 }
189
190 // This tests the ADO.NET driver
191 List<SceneObjectGroup> objs = db.LoadObjects(region1);
192
193 Assert.That(objs.Count, Is.EqualTo(2), "Assert.That(objs.Count, Is.EqualTo(2))");
194 }
195
196 [Test]
197 public void T011_ObjectNames()
198 {
199 TestHelpers.InMethod();
200
201 List<SceneObjectGroup> objs = db.LoadObjects(region1);
202 foreach (SceneObjectGroup sog in objs)
203 {
204 SceneObjectPart p = sog.RootPart;
205 Assert.That("", Is.Not.EqualTo(p.Name), "Assert.That(\"\", Is.Not.EqualTo(p.Name))");
206 Assert.That(p.Name, Is.EqualTo(p.Description), "Assert.That(p.Name, Is.EqualTo(p.Description))");
207 }
208 }
209
210 [Test]
211 public void T012_SceneParts()
212 {
213 TestHelpers.InMethod();
214
215 UUID tmp0 = UUID.Random();
216 UUID tmp1 = UUID.Random();
217 UUID tmp2 = UUID.Random();
218 UUID tmp3 = UUID.Random();
219 UUID newregion = UUID.Random();
220 SceneObjectPart p1 = NewSOP("SoP 1",tmp1);
221 SceneObjectPart p2 = NewSOP("SoP 2",tmp2);
222 SceneObjectPart p3 = NewSOP("SoP 3",tmp3);
223 SceneObjectGroup sog = NewSOG("Sop 0", tmp0, newregion);
224 sog.AddPart(p1);
225 sog.AddPart(p2);
226 sog.AddPart(p3);
227
228 SceneObjectPart[] parts = sog.Parts;
229 Assert.That(parts.Length,Is.EqualTo(4), "Assert.That(parts.Length,Is.EqualTo(4))");
230
231 db.StoreObject(sog, newregion);
232 List<SceneObjectGroup> sogs = db.LoadObjects(newregion);
233 Assert.That(sogs.Count,Is.EqualTo(1), "Assert.That(sogs.Count,Is.EqualTo(1))");
234 SceneObjectGroup newsog = sogs[0];
235
236 SceneObjectPart[] newparts = newsog.Parts;
237 Assert.That(newparts.Length,Is.EqualTo(4), "Assert.That(newparts.Length,Is.EqualTo(4))");
238
239 Assert.That(newsog.ContainsPart(tmp0), "Assert.That(newsog.ContainsPart(tmp0))");
240 Assert.That(newsog.ContainsPart(tmp1), "Assert.That(newsog.ContainsPart(tmp1))");
241 Assert.That(newsog.ContainsPart(tmp2), "Assert.That(newsog.ContainsPart(tmp2))");
242 Assert.That(newsog.ContainsPart(tmp3), "Assert.That(newsog.ContainsPart(tmp3))");
243 }
244
245 [Test]
246 public void T013_DatabasePersistency()
247 {
248 TestHelpers.InMethod();
249
250 // Sets all ScenePart parameters, stores and retrieves them, then check for consistency with initial data
251 // The commented Asserts are the ones that are unchangeable (when storing on the database, their "Set" values are ignored
252 // The ObjectFlags is an exception, if it is entered incorrectly, the object IS REJECTED on the database silently.
253 UUID creator,uuid = new UUID();
254 creator = UUID.Random();
255 uint iserial = (uint)random.Next();
256 TaskInventoryDictionary dic = new TaskInventoryDictionary();
257 uint objf = (uint) random.Next();
258 uuid = prim4;
259 uint localid = localID+1;
260 localID = localID + 1;
261 string name = "Adam West";
262 byte material = (byte) random.Next(127);
263 ulong regionh = (ulong)random.NextDouble() * (ulong)random.Next();
264 int pin = random.Next();
265 Byte[] partsys = new byte[8];
266 Byte[] textani = new byte[8];
267 random.NextBytes(textani);
268 random.NextBytes(partsys);
269 DateTime expires = new DateTime(2008, 12, 20);
270 DateTime rezzed = new DateTime(2009, 07, 15);
271 Vector3 groupos = new Vector3(random.Next(),random.Next(),random.Next());
272 Vector3 offset = new Vector3(random.Next(),random.Next(),random.Next());
273 Quaternion rotoff = new Quaternion(random.Next(),random.Next(),random.Next(),random.Next());
274 Vector3 velocity = new Vector3(random.Next(),random.Next(),random.Next());
275 Vector3 angvelo = new Vector3(random.Next(),random.Next(),random.Next());
276 Vector3 accel = new Vector3(random.Next(),random.Next(),random.Next());
277 string description = name;
278 Color color = Color.FromArgb(255, 165, 50, 100);
279 string text = "All Your Base Are Belong to Us";
280 string sitname = "SitName";
281 string touchname = "TouchName";
282 int linknum = random.Next();
283 byte clickaction = (byte) random.Next(127);
284 PrimitiveBaseShape pbshap = new PrimitiveBaseShape();
285 pbshap = PrimitiveBaseShape.Default;
286 pbshap.PathBegin = ushort.MaxValue;
287 pbshap.PathEnd = ushort.MaxValue;
288 pbshap.ProfileBegin = ushort.MaxValue;
289 pbshap.ProfileEnd = ushort.MaxValue;
290 pbshap.ProfileHollow = ushort.MaxValue;
291 Vector3 scale = new Vector3(random.Next(),random.Next(),random.Next());
292
293 RegionInfo regionInfo = new RegionInfo();
294 regionInfo.RegionID = region3;
295 regionInfo.RegionLocX = 0;
296 regionInfo.RegionLocY = 0;
297
298 SceneObjectPart sop = new SceneObjectPart();
299 SceneObjectGroup sog = new SceneObjectGroup(sop);
300
301 sop.RegionHandle = regionh;
302 sop.UUID = uuid;
303 sop.LocalId = localid;
304 sop.Shape = pbshap;
305 sop.GroupPosition = groupos;
306 sop.RotationOffset = rotoff;
307 sop.CreatorID = creator;
308 sop.InventorySerial = iserial;
309 sop.TaskInventory = dic;
310 sop.Flags = (PrimFlags)objf;
311 sop.Name = name;
312 sop.Material = material;
313 sop.ScriptAccessPin = pin;
314 sop.TextureAnimation = textani;
315 sop.ParticleSystem = partsys;
316 sop.Expires = expires;
317 sop.Rezzed = rezzed;
318 sop.OffsetPosition = offset;
319 sop.Velocity = velocity;
320 sop.AngularVelocity = angvelo;
321 sop.Acceleration = accel;
322 sop.Description = description;
323 sop.Color = color;
324 sop.Text = text;
325 sop.SitName = sitname;
326 sop.TouchName = touchname;
327 sop.LinkNum = linknum;
328 sop.ClickAction = clickaction;
329 sop.Scale = scale;
330
331 //Tests if local part accepted the parameters:
332 Assert.That(regionh,Is.EqualTo(sop.RegionHandle), "Assert.That(regionh,Is.EqualTo(sop.RegionHandle))");
333 Assert.That(localid,Is.EqualTo(sop.LocalId), "Assert.That(localid,Is.EqualTo(sop.LocalId))");
334 Assert.That(groupos,Is.EqualTo(sop.GroupPosition), "Assert.That(groupos,Is.EqualTo(sop.GroupPosition))");
335 Assert.That(name,Is.EqualTo(sop.Name), "Assert.That(name,Is.EqualTo(sop.Name))");
336 Assert.That(rotoff,Is.EqualTo(sop.RotationOffset), "Assert.That(rotoff,Is.EqualTo(sop.RotationOffset))");
337 Assert.That(uuid,Is.EqualTo(sop.UUID), "Assert.That(uuid,Is.EqualTo(sop.UUID))");
338 Assert.That(creator,Is.EqualTo(sop.CreatorID), "Assert.That(creator,Is.EqualTo(sop.CreatorID))");
339 // Modified in-class
340 // Assert.That(iserial,Is.EqualTo(sop.InventorySerial), "Assert.That(iserial,Is.EqualTo(sop.InventorySerial))");
341 Assert.That(dic,Is.EqualTo(sop.TaskInventory), "Assert.That(dic,Is.EqualTo(sop.TaskInventory))");
342 Assert.That(objf, Is.EqualTo((uint)sop.Flags), "Assert.That(objf,Is.EqualTo(sop.Flags))");
343 Assert.That(name,Is.EqualTo(sop.Name), "Assert.That(name,Is.EqualTo(sop.Name))");
344 Assert.That(material,Is.EqualTo(sop.Material), "Assert.That(material,Is.EqualTo(sop.Material))");
345 Assert.That(pin,Is.EqualTo(sop.ScriptAccessPin), "Assert.That(pin,Is.EqualTo(sop.ScriptAccessPin))");
346 Assert.That(textani,Is.EqualTo(sop.TextureAnimation), "Assert.That(textani,Is.EqualTo(sop.TextureAnimation))");
347 Assert.That(partsys,Is.EqualTo(sop.ParticleSystem), "Assert.That(partsys,Is.EqualTo(sop.ParticleSystem))");
348 Assert.That(expires,Is.EqualTo(sop.Expires), "Assert.That(expires,Is.EqualTo(sop.Expires))");
349 Assert.That(rezzed,Is.EqualTo(sop.Rezzed), "Assert.That(rezzed,Is.EqualTo(sop.Rezzed))");
350 Assert.That(offset,Is.EqualTo(sop.OffsetPosition), "Assert.That(offset,Is.EqualTo(sop.OffsetPosition))");
351 Assert.That(velocity,Is.EqualTo(sop.Velocity), "Assert.That(velocity,Is.EqualTo(sop.Velocity))");
352 Assert.That(angvelo,Is.EqualTo(sop.AngularVelocity), "Assert.That(angvelo,Is.EqualTo(sop.AngularVelocity))");
353 Assert.That(accel,Is.EqualTo(sop.Acceleration), "Assert.That(accel,Is.EqualTo(sop.Acceleration))");
354 Assert.That(description,Is.EqualTo(sop.Description), "Assert.That(description,Is.EqualTo(sop.Description))");
355 Assert.That(color,Is.EqualTo(sop.Color), "Assert.That(color,Is.EqualTo(sop.Color))");
356 Assert.That(text,Is.EqualTo(sop.Text), "Assert.That(text,Is.EqualTo(sop.Text))");
357 Assert.That(sitname,Is.EqualTo(sop.SitName), "Assert.That(sitname,Is.EqualTo(sop.SitName))");
358 Assert.That(touchname,Is.EqualTo(sop.TouchName), "Assert.That(touchname,Is.EqualTo(sop.TouchName))");
359 Assert.That(linknum,Is.EqualTo(sop.LinkNum), "Assert.That(linknum,Is.EqualTo(sop.LinkNum))");
360 Assert.That(clickaction,Is.EqualTo(sop.ClickAction), "Assert.That(clickaction,Is.EqualTo(sop.ClickAction))");
361 Assert.That(scale,Is.EqualTo(sop.Scale), "Assert.That(scale,Is.EqualTo(sop.Scale))");
362
363 // This is necessary or object will not be inserted in DB
364 sop.Flags = PrimFlags.None;
365
366 // Inserts group in DB
367 db.StoreObject(sog,region3);
368 List<SceneObjectGroup> sogs = db.LoadObjects(region3);
369 Assert.That(sogs.Count, Is.EqualTo(1), "Assert.That(sogs.Count, Is.EqualTo(1))");
370 // Makes sure there are no double insertions:
371 db.StoreObject(sog,region3);
372 sogs = db.LoadObjects(region3);
373 Assert.That(sogs.Count, Is.EqualTo(1), "Assert.That(sogs.Count, Is.EqualTo(1))");
374
375
376 // Tests if the parameters were inserted correctly
377 SceneObjectPart p = sogs[0].RootPart;
378 Assert.That(regionh,Is.EqualTo(p.RegionHandle), "Assert.That(regionh,Is.EqualTo(p.RegionHandle))");
379 //Assert.That(localid,Is.EqualTo(p.LocalId), "Assert.That(localid,Is.EqualTo(p.LocalId))");
380 Assert.That(groupos,Is.EqualTo(p.GroupPosition), "Assert.That(groupos,Is.EqualTo(p.GroupPosition))");
381 Assert.That(name,Is.EqualTo(p.Name), "Assert.That(name,Is.EqualTo(p.Name))");
382 Assert.That(rotoff,Is.EqualTo(p.RotationOffset), "Assert.That(rotoff,Is.EqualTo(p.RotationOffset))");
383 Assert.That(uuid,Is.EqualTo(p.UUID), "Assert.That(uuid,Is.EqualTo(p.UUID))");
384 Assert.That(creator,Is.EqualTo(p.CreatorID), "Assert.That(creator,Is.EqualTo(p.CreatorID))");
385 //Assert.That(iserial,Is.EqualTo(p.InventorySerial), "Assert.That(iserial,Is.EqualTo(p.InventorySerial))");
386 Assert.That(dic,Is.EqualTo(p.TaskInventory), "Assert.That(dic,Is.EqualTo(p.TaskInventory))");
387 //Assert.That(objf, Is.EqualTo((uint)p.Flags), "Assert.That(objf,Is.EqualTo(p.Flags))");
388 Assert.That(name,Is.EqualTo(p.Name), "Assert.That(name,Is.EqualTo(p.Name))");
389 Assert.That(material,Is.EqualTo(p.Material), "Assert.That(material,Is.EqualTo(p.Material))");
390 Assert.That(pin,Is.EqualTo(p.ScriptAccessPin), "Assert.That(pin,Is.EqualTo(p.ScriptAccessPin))");
391 Assert.That(textani,Is.EqualTo(p.TextureAnimation), "Assert.That(textani,Is.EqualTo(p.TextureAnimation))");
392 Assert.That(partsys,Is.EqualTo(p.ParticleSystem), "Assert.That(partsys,Is.EqualTo(p.ParticleSystem))");
393 //Assert.That(expires,Is.EqualTo(p.Expires), "Assert.That(expires,Is.EqualTo(p.Expires))");
394 //Assert.That(rezzed,Is.EqualTo(p.Rezzed), "Assert.That(rezzed,Is.EqualTo(p.Rezzed))");
395 Assert.That(offset,Is.EqualTo(p.OffsetPosition), "Assert.That(offset,Is.EqualTo(p.OffsetPosition))");
396 Assert.That(velocity,Is.EqualTo(p.Velocity), "Assert.That(velocity,Is.EqualTo(p.Velocity))");
397 Assert.That(angvelo,Is.EqualTo(p.AngularVelocity), "Assert.That(angvelo,Is.EqualTo(p.AngularVelocity))");
398 Assert.That(accel,Is.EqualTo(p.Acceleration), "Assert.That(accel,Is.EqualTo(p.Acceleration))");
399 Assert.That(description,Is.EqualTo(p.Description), "Assert.That(description,Is.EqualTo(p.Description))");
400 Assert.That(color,Is.EqualTo(p.Color), "Assert.That(color,Is.EqualTo(p.Color))");
401 Assert.That(text,Is.EqualTo(p.Text), "Assert.That(text,Is.EqualTo(p.Text))");
402 Assert.That(sitname,Is.EqualTo(p.SitName), "Assert.That(sitname,Is.EqualTo(p.SitName))");
403 Assert.That(touchname,Is.EqualTo(p.TouchName), "Assert.That(touchname,Is.EqualTo(p.TouchName))");
404 //Assert.That(linknum,Is.EqualTo(p.LinkNum), "Assert.That(linknum,Is.EqualTo(p.LinkNum))");
405 Assert.That(clickaction,Is.EqualTo(p.ClickAction), "Assert.That(clickaction,Is.EqualTo(p.ClickAction))");
406 Assert.That(scale,Is.EqualTo(p.Scale), "Assert.That(scale,Is.EqualTo(p.Scale))");
407
408 //Assert.That(updatef,Is.EqualTo(p.UpdateFlag), "Assert.That(updatef,Is.EqualTo(p.UpdateFlag))");
409
410 Assert.That(pbshap.PathBegin, Is.EqualTo(p.Shape.PathBegin), "Assert.That(pbshap.PathBegin, Is.EqualTo(p.Shape.PathBegin))");
411 Assert.That(pbshap.PathEnd, Is.EqualTo(p.Shape.PathEnd), "Assert.That(pbshap.PathEnd, Is.EqualTo(p.Shape.PathEnd))");
412 Assert.That(pbshap.ProfileBegin, Is.EqualTo(p.Shape.ProfileBegin), "Assert.That(pbshap.ProfileBegin, Is.EqualTo(p.Shape.ProfileBegin))");
413 Assert.That(pbshap.ProfileEnd, Is.EqualTo(p.Shape.ProfileEnd), "Assert.That(pbshap.ProfileEnd, Is.EqualTo(p.Shape.ProfileEnd))");
414 Assert.That(pbshap.ProfileHollow, Is.EqualTo(p.Shape.ProfileHollow), "Assert.That(pbshap.ProfileHollow, Is.EqualTo(p.Shape.ProfileHollow))");
415 }
416
417 [Test]
418 public void T014_UpdateObject()
419 {
420 TestHelpers.InMethod();
421
422 string text1 = "object1 text";
423 SceneObjectGroup sog = FindSOG("object1", region1);
424 sog.RootPart.Text = text1;
425 db.StoreObject(sog, region1);
426
427 sog = FindSOG("object1", region1);
428 Assert.That(text1, Is.EqualTo(sog.RootPart.Text), "Assert.That(text1, Is.EqualTo(sog.RootPart.Text))");
429
430 // Creates random values
431 UUID creator = new UUID();
432 creator = UUID.Random();
433 TaskInventoryDictionary dic = new TaskInventoryDictionary();
434 localID = localID + 1;
435 string name = "West Adam";
436 byte material = (byte) random.Next(127);
437 ulong regionh = (ulong)random.NextDouble() * (ulong)random.Next();
438 int pin = random.Next();
439 Byte[] partsys = new byte[8];
440 Byte[] textani = new byte[8];
441 random.NextBytes(textani);
442 random.NextBytes(partsys);
443 DateTime expires = new DateTime(2010, 12, 20);
444 DateTime rezzed = new DateTime(2005, 07, 15);
445 Vector3 groupos = new Vector3(random.Next(),random.Next(),random.Next());
446 Vector3 offset = new Vector3(random.Next(),random.Next(),random.Next());
447 Quaternion rotoff = new Quaternion(random.Next(),random.Next(),random.Next(),random.Next());
448 Vector3 velocity = new Vector3(random.Next(),random.Next(),random.Next());
449 Vector3 angvelo = new Vector3(random.Next(),random.Next(),random.Next());
450 Vector3 accel = new Vector3(random.Next(),random.Next(),random.Next());
451 string description = name;
452 Color color = Color.FromArgb(255, 255, 255, 0);
453 string text = "What You Say?{]\vz~";
454 string sitname = RandomName();
455 string touchname = RandomName();
456 int linknum = random.Next();
457 byte clickaction = (byte) random.Next(127);
458 PrimitiveBaseShape pbshap = new PrimitiveBaseShape();
459 pbshap = PrimitiveBaseShape.Default;
460 Vector3 scale = new Vector3(random.Next(),random.Next(),random.Next());
461
462 // Updates the region with new values
463 SceneObjectGroup sog2 = FindSOG("Adam West", region3);
464 Assert.That(sog2,Is.Not.Null);
465 sog2.RootPart.RegionHandle = regionh;
466 sog2.RootPart.Shape = pbshap;
467 sog2.RootPart.GroupPosition = groupos;
468 sog2.RootPart.RotationOffset = rotoff;
469 sog2.RootPart.CreatorID = creator;
470 sog2.RootPart.TaskInventory = dic;
471 sog2.RootPart.Name = name;
472 sog2.RootPart.Material = material;
473 sog2.RootPart.ScriptAccessPin = pin;
474 sog2.RootPart.TextureAnimation = textani;
475 sog2.RootPart.ParticleSystem = partsys;
476 sog2.RootPart.Expires = expires;
477 sog2.RootPart.Rezzed = rezzed;
478 sog2.RootPart.OffsetPosition = offset;
479 sog2.RootPart.Velocity = velocity;
480 sog2.RootPart.AngularVelocity = angvelo;
481 sog2.RootPart.Acceleration = accel;
482 sog2.RootPart.Description = description;
483 sog2.RootPart.Color = color;
484 sog2.RootPart.Text = text;
485 sog2.RootPart.SitName = sitname;
486 sog2.RootPart.TouchName = touchname;
487 sog2.RootPart.LinkNum = linknum;
488 sog2.RootPart.ClickAction = clickaction;
489 sog2.RootPart.Scale = scale;
490
491 db.StoreObject(sog2, region3);
492 List<SceneObjectGroup> sogs = db.LoadObjects(region3);
493 Assert.That(sogs.Count, Is.EqualTo(1), "Assert.That(sogs.Count, Is.EqualTo(1))");
494
495 SceneObjectGroup retsog = FindSOG("West Adam", region3);
496 Assert.That(retsog,Is.Not.Null);
497 SceneObjectPart p = retsog.RootPart;
498 Assert.That(regionh,Is.EqualTo(p.RegionHandle), "Assert.That(regionh,Is.EqualTo(p.RegionHandle))");
499 Assert.That(groupos,Is.EqualTo(p.GroupPosition), "Assert.That(groupos,Is.EqualTo(p.GroupPosition))");
500 Assert.That(name,Is.EqualTo(p.Name), "Assert.That(name,Is.EqualTo(p.Name))");
501 Assert.That(rotoff,Is.EqualTo(p.RotationOffset), "Assert.That(rotoff,Is.EqualTo(p.RotationOffset))");
502 Assert.That(creator,Is.EqualTo(p.CreatorID), "Assert.That(creator,Is.EqualTo(p.CreatorID))");
503 Assert.That(dic,Is.EqualTo(p.TaskInventory), "Assert.That(dic,Is.EqualTo(p.TaskInventory))");
504 Assert.That(name,Is.EqualTo(p.Name), "Assert.That(name,Is.EqualTo(p.Name))");
505 Assert.That(material,Is.EqualTo(p.Material), "Assert.That(material,Is.EqualTo(p.Material))");
506 Assert.That(pin,Is.EqualTo(p.ScriptAccessPin), "Assert.That(pin,Is.EqualTo(p.ScriptAccessPin))");
507 Assert.That(textani,Is.EqualTo(p.TextureAnimation), "Assert.That(textani,Is.EqualTo(p.TextureAnimation))");
508 Assert.That(partsys,Is.EqualTo(p.ParticleSystem), "Assert.That(partsys,Is.EqualTo(p.ParticleSystem))");
509 Assert.That(offset,Is.EqualTo(p.OffsetPosition), "Assert.That(offset,Is.EqualTo(p.OffsetPosition))");
510 Assert.That(velocity,Is.EqualTo(p.Velocity), "Assert.That(velocity,Is.EqualTo(p.Velocity))");
511 Assert.That(angvelo,Is.EqualTo(p.AngularVelocity), "Assert.That(angvelo,Is.EqualTo(p.AngularVelocity))");
512 Assert.That(accel,Is.EqualTo(p.Acceleration), "Assert.That(accel,Is.EqualTo(p.Acceleration))");
513 Assert.That(description,Is.EqualTo(p.Description), "Assert.That(description,Is.EqualTo(p.Description))");
514 Assert.That(color,Is.EqualTo(p.Color), "Assert.That(color,Is.EqualTo(p.Color))");
515 Assert.That(text,Is.EqualTo(p.Text), "Assert.That(text,Is.EqualTo(p.Text))");
516 Assert.That(sitname,Is.EqualTo(p.SitName), "Assert.That(sitname,Is.EqualTo(p.SitName))");
517 Assert.That(touchname,Is.EqualTo(p.TouchName), "Assert.That(touchname,Is.EqualTo(p.TouchName))");
518 Assert.That(clickaction,Is.EqualTo(p.ClickAction), "Assert.That(clickaction,Is.EqualTo(p.ClickAction))");
519 Assert.That(scale,Is.EqualTo(p.Scale), "Assert.That(scale,Is.EqualTo(p.Scale))");
520 }
521
522 /// <summary>
523 /// Test storage and retrieval of a scene object with a large number of parts.
524 /// </summary>
525 [Test]
526 public void T015_LargeSceneObjects()
527 {
528 TestHelpers.InMethod();
529
530 UUID id = UUID.Random();
531 Dictionary<UUID, SceneObjectPart> mydic = new Dictionary<UUID, SceneObjectPart>();
532 SceneObjectGroup sog = NewSOG("Test SOG", id, region4);
533 mydic.Add(sog.RootPart.UUID,sog.RootPart);
534 for (int i = 0; i < 30; i++)
535 {
536 UUID tmp = UUID.Random();
537 SceneObjectPart sop = NewSOP(("Test SOP " + i.ToString()),tmp);
538 Vector3 groupos = new Vector3(random.Next(),random.Next(),random.Next());
539 Vector3 offset = new Vector3(random.Next(),random.Next(),random.Next());
540 Quaternion rotoff = new Quaternion(random.Next(),random.Next(),random.Next(),random.Next());
541 Vector3 velocity = new Vector3(random.Next(),random.Next(),random.Next());
542 Vector3 angvelo = new Vector3(random.Next(),random.Next(),random.Next());
543 Vector3 accel = new Vector3(random.Next(),random.Next(),random.Next());
544
545 sop.GroupPosition = groupos;
546 sop.RotationOffset = rotoff;
547 sop.OffsetPosition = offset;
548 sop.Velocity = velocity;
549 sop.AngularVelocity = angvelo;
550 sop.Acceleration = accel;
551
552 mydic.Add(tmp,sop);
553 sog.AddPart(sop);
554 }
555
556 db.StoreObject(sog, region4);
557
558 SceneObjectGroup retsog = FindSOG("Test SOG", region4);
559 SceneObjectPart[] parts = retsog.Parts;
560 for (int i = 0; i < 30; i++)
561 {
562 SceneObjectPart cursop = mydic[parts[i].UUID];
563 Assert.That(cursop.GroupPosition,Is.EqualTo(parts[i].GroupPosition), "Assert.That(cursop.GroupPosition,Is.EqualTo(parts[i].GroupPosition))");
564 Assert.That(cursop.RotationOffset,Is.EqualTo(parts[i].RotationOffset), "Assert.That(cursop.RotationOffset,Is.EqualTo(parts[i].RotationOffset))");
565 Assert.That(cursop.OffsetPosition,Is.EqualTo(parts[i].OffsetPosition), "Assert.That(cursop.OffsetPosition,Is.EqualTo(parts[i].OffsetPosition))");
566 Assert.That(cursop.Velocity,Is.EqualTo(parts[i].Velocity), "Assert.That(cursop.Velocity,Is.EqualTo(parts[i].Velocity))");
567 Assert.That(cursop.AngularVelocity,Is.EqualTo(parts[i].AngularVelocity), "Assert.That(cursop.AngularVelocity,Is.EqualTo(parts[i].AngularVelocity))");
568 Assert.That(cursop.Acceleration,Is.EqualTo(parts[i].Acceleration), "Assert.That(cursop.Acceleration,Is.EqualTo(parts[i].Acceleration))");
569 }
570 }
571
572 //[Test]
573 public void T016_RandomSogWithSceneParts()
574 {
575 TestHelpers.InMethod();
576
577 PropertyScrambler<SceneObjectPart> scrambler =
578 new PropertyScrambler<SceneObjectPart>()
579 .DontScramble(x => x.UUID);
580 UUID tmpSog = UUID.Random();
581 UUID tmp1 = UUID.Random();
582 UUID tmp2 = UUID.Random();
583 UUID tmp3 = UUID.Random();
584 UUID newregion = UUID.Random();
585 SceneObjectPart p1 = new SceneObjectPart();
586 SceneObjectPart p2 = new SceneObjectPart();
587 SceneObjectPart p3 = new SceneObjectPart();
588 p1.Shape = PrimitiveBaseShape.Default;
589 p2.Shape = PrimitiveBaseShape.Default;
590 p3.Shape = PrimitiveBaseShape.Default;
591 p1.UUID = tmp1;
592 p2.UUID = tmp2;
593 p3.UUID = tmp3;
594 scrambler.Scramble(p1);
595 scrambler.Scramble(p2);
596 scrambler.Scramble(p3);
597
598 SceneObjectGroup sog = NewSOG("Sop 0", tmpSog, newregion);
599 PropertyScrambler<SceneObjectGroup> sogScrambler =
600 new PropertyScrambler<SceneObjectGroup>()
601 .DontScramble(x => x.UUID);
602 sogScrambler.Scramble(sog);
603 sog.UUID = tmpSog;
604 sog.AddPart(p1);
605 sog.AddPart(p2);
606 sog.AddPart(p3);
607
608 SceneObjectPart[] parts = sog.Parts;
609 Assert.That(parts.Length, Is.EqualTo(4), "Assert.That(parts.Length,Is.EqualTo(4))");
610
611 db.StoreObject(sog, newregion);
612 List<SceneObjectGroup> sogs = db.LoadObjects(newregion);
613 Assert.That(sogs.Count, Is.EqualTo(1), "Assert.That(sogs.Count,Is.EqualTo(1))");
614 SceneObjectGroup newsog = sogs[0];
615
616 SceneObjectPart[] newparts = newsog.Parts;
617 Assert.That(newparts.Length, Is.EqualTo(4), "Assert.That(newparts.Length,Is.EqualTo(4))");
618
619 Assert.That(newsog, Constraints.PropertyCompareConstraint(sog)
620 .IgnoreProperty(x=>x.LocalId)
621 .IgnoreProperty(x=>x.HasGroupChanged)
622 .IgnoreProperty(x=>x.IsSelected)
623 .IgnoreProperty(x=>x.RegionHandle)
624 .IgnoreProperty(x=>x.RegionUUID)
625 .IgnoreProperty(x=>x.Scene)
626 .IgnoreProperty(x=>x.Parts)
627 .IgnoreProperty(x=>x.RootPart));
628 }
629
630
631 private SceneObjectGroup GetMySOG(string name)
632 {
633 SceneObjectGroup sog = FindSOG(name, region1);
634 if (sog == null)
635 {
636 sog = NewSOG(name, prim1, region1);
637 db.StoreObject(sog, region1);
638 }
639 return sog;
640 }
641
642 // NOTE: it is a bad practice to rely on some of the previous tests having been run before.
643 // If the tests are run manually, one at a time, each starts with full class init (DB cleared).
644 // Even when all tests are run, NUnit 2.5+ no longer guarantee a specific test order.
645 // We shouldn't expect to find anything in the DB if we haven't put it there *in the same test*!
646
647 [Test]
648 public void T020_PrimInventoryEmpty()
649 {
650 TestHelpers.InMethod();
651
652 SceneObjectGroup sog = GetMySOG("object1");
653 TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
654 Assert.That(t, Is.Null);
655 }
656
657 // TODO: Is there any point to call StorePrimInventory on a list, rather than on the prim itself?
658
659 private void StoreInventory(SceneObjectGroup sog)
660 {
661 List<TaskInventoryItem> list = new List<TaskInventoryItem>();
662 // TODO: seriously??? this is the way we need to loop to get this?
663 foreach (UUID uuid in sog.RootPart.Inventory.GetInventoryList())
664 {
665 list.Add(sog.GetInventoryItem(sog.RootPart.LocalId, uuid));
666 }
667
668 db.StorePrimInventory(sog.RootPart.UUID, list);
669 }
670
671 [Test]
672 public void T021_PrimInventoryBasic()
673 {
674 TestHelpers.InMethod();
675
676 SceneObjectGroup sog = GetMySOG("object1");
677 InventoryItemBase i = NewItem(item1, zero, zero, itemname1, zero);
678
679 Assert.That(sog.AddInventoryItem(zero, sog.RootPart.LocalId, i, zero), Is.True);
680 TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
681 Assert.That(t.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))");
682
683 StoreInventory(sog);
684
685 SceneObjectGroup sog1 = FindSOG("object1", region1);
686 Assert.That(sog1, Is.Not.Null);
687
688 TaskInventoryItem t1 = sog1.GetInventoryItem(sog1.RootPart.LocalId, item1);
689 Assert.That(t1, Is.Not.Null);
690 Assert.That(t1.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))");
691
692 // Updating inventory
693 t1.Name = "My New Name";
694 sog1.UpdateInventoryItem(t1);
695
696 StoreInventory(sog1);
697
698 SceneObjectGroup sog2 = FindSOG("object1", region1);
699 TaskInventoryItem t2 = sog2.GetInventoryItem(sog2.RootPart.LocalId, item1);
700 Assert.That(t2.Name, Is.EqualTo("My New Name"), "Assert.That(t.Name, Is.EqualTo(\"My New Name\"))");
701
702 // Removing inventory
703 List<TaskInventoryItem> list = new List<TaskInventoryItem>();
704 db.StorePrimInventory(prim1, list);
705
706 sog = FindSOG("object1", region1);
707 t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
708 Assert.That(t, Is.Null);
709 }
710
711 [Test]
712 public void T025_PrimInventoryPersistency()
713 {
714 TestHelpers.InMethod();
715
716 InventoryItemBase i = new InventoryItemBase();
717 UUID id = UUID.Random();
718 i.ID = id;
719 UUID folder = UUID.Random();
720 i.Folder = folder;
721 UUID owner = UUID.Random();
722 i.Owner = owner;
723 UUID creator = UUID.Random();
724 i.CreatorId = creator.ToString();
725 string name = RandomName();
726 i.Name = name;
727 i.Description = name;
728 UUID assetid = UUID.Random();
729 i.AssetID = assetid;
730 int invtype = random.Next();
731 i.InvType = invtype;
732 uint nextperm = (uint) random.Next();
733 i.NextPermissions = nextperm;
734 uint curperm = (uint) random.Next();
735 i.CurrentPermissions = curperm;
736 uint baseperm = (uint) random.Next();
737 i.BasePermissions = baseperm;
738 uint eoperm = (uint) random.Next();
739 i.EveryOnePermissions = eoperm;
740 int assettype = random.Next();
741 i.AssetType = assettype;
742 UUID groupid = UUID.Random();
743 i.GroupID = groupid;
744 bool groupown = true;
745 i.GroupOwned = groupown;
746 int saleprice = random.Next();
747 i.SalePrice = saleprice;
748 byte saletype = (byte) random.Next(127);
749 i.SaleType = saletype;
750 uint flags = (uint) random.Next();
751 i.Flags = flags;
752 int creationd = random.Next();
753 i.CreationDate = creationd;
754
755 SceneObjectGroup sog = GetMySOG("object1");
756 Assert.That(sog.AddInventoryItem(zero, sog.RootPart.LocalId, i, zero), Is.True);
757 TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, id);
758
759 Assert.That(t.Name, Is.EqualTo(name), "Assert.That(t.Name, Is.EqualTo(name))");
760 Assert.That(t.AssetID,Is.EqualTo(assetid), "Assert.That(t.AssetID,Is.EqualTo(assetid))");
761 Assert.That(t.BasePermissions,Is.EqualTo(baseperm), "Assert.That(t.BasePermissions,Is.EqualTo(baseperm))");
762 Assert.That(t.CreationDate,Is.EqualTo(creationd), "Assert.That(t.CreationDate,Is.EqualTo(creationd))");
763 Assert.That(t.CreatorID,Is.EqualTo(creator), "Assert.That(t.CreatorID,Is.EqualTo(creator))");
764 Assert.That(t.Description,Is.EqualTo(name), "Assert.That(t.Description,Is.EqualTo(name))");
765 Assert.That(t.EveryonePermissions,Is.EqualTo(eoperm), "Assert.That(t.EveryonePermissions,Is.EqualTo(eoperm))");
766 Assert.That(t.Flags,Is.EqualTo(flags), "Assert.That(t.Flags,Is.EqualTo(flags))");
767 Assert.That(t.GroupID,Is.EqualTo(sog.RootPart.GroupID), "Assert.That(t.GroupID,Is.EqualTo(sog.RootPart.GroupID))");
768 // Where is this group permissions??
769 // Assert.That(t.GroupPermissions,Is.EqualTo(), "Assert.That(t.GroupPermissions,Is.EqualTo())");
770 Assert.That(t.Type,Is.EqualTo(assettype), "Assert.That(t.Type,Is.EqualTo(assettype))");
771 Assert.That(t.InvType, Is.EqualTo(invtype), "Assert.That(t.InvType, Is.EqualTo(invtype))");
772 Assert.That(t.ItemID, Is.EqualTo(id), "Assert.That(t.ItemID, Is.EqualTo(id))");
773 Assert.That(t.LastOwnerID, Is.EqualTo(sog.RootPart.LastOwnerID), "Assert.That(t.LastOwnerID, Is.EqualTo(sog.RootPart.LastOwnerID))");
774 Assert.That(t.NextPermissions, Is.EqualTo(nextperm), "Assert.That(t.NextPermissions, Is.EqualTo(nextperm))");
775 // Ownership changes when you drop an object into an object
776 // owned by someone else
777 Assert.That(t.OwnerID,Is.EqualTo(sog.RootPart.OwnerID), "Assert.That(t.OwnerID,Is.EqualTo(sog.RootPart.OwnerID))");
778// Assert.That(t.CurrentPermissions, Is.EqualTo(curperm | 16), "Assert.That(t.CurrentPermissions, Is.EqualTo(curperm | 8))");
779 Assert.That(t.ParentID,Is.EqualTo(sog.RootPart.FolderID), "Assert.That(t.ParentID,Is.EqualTo(sog.RootPart.FolderID))");
780 Assert.That(t.ParentPartID,Is.EqualTo(sog.RootPart.UUID), "Assert.That(t.ParentPartID,Is.EqualTo(sog.RootPart.UUID))");
781 }
782
783 [Test]
784 [ExpectedException(typeof(ArgumentException))]
785 public void T026_PrimInventoryMany()
786 {
787 TestHelpers.InMethod();
788
789 UUID i1,i2,i3,i4;
790 i1 = UUID.Random();
791 i2 = UUID.Random();
792 i3 = UUID.Random();
793 i4 = i3;
794 InventoryItemBase ib1 = NewItem(i1, zero, zero, RandomName(), zero);
795 InventoryItemBase ib2 = NewItem(i2, zero, zero, RandomName(), zero);
796 InventoryItemBase ib3 = NewItem(i3, zero, zero, RandomName(), zero);
797 InventoryItemBase ib4 = NewItem(i4, zero, zero, RandomName(), zero);
798
799 SceneObjectGroup sog = FindSOG("object1", region1);
800
801 Assert.That(sog.AddInventoryItem(zero, sog.RootPart.LocalId, ib1, zero), Is.True);
802 Assert.That(sog.AddInventoryItem(zero, sog.RootPart.LocalId, ib2, zero), Is.True);
803 Assert.That(sog.AddInventoryItem(zero, sog.RootPart.LocalId, ib3, zero), Is.True);
804 Assert.That(sog.AddInventoryItem(zero, sog.RootPart.LocalId, ib4, zero), Is.True);
805
806 TaskInventoryItem t1 = sog.GetInventoryItem(sog.RootPart.LocalId, i1);
807 Assert.That(t1.Name, Is.EqualTo(ib1.Name), "Assert.That(t1.Name, Is.EqualTo(ib1.Name))");
808 TaskInventoryItem t2 = sog.GetInventoryItem(sog.RootPart.LocalId, i2);
809 Assert.That(t2.Name, Is.EqualTo(ib2.Name), "Assert.That(t2.Name, Is.EqualTo(ib2.Name))");
810 TaskInventoryItem t3 = sog.GetInventoryItem(sog.RootPart.LocalId, i3);
811 Assert.That(t3.Name, Is.EqualTo(ib3.Name), "Assert.That(t3.Name, Is.EqualTo(ib3.Name))");
812 TaskInventoryItem t4 = sog.GetInventoryItem(sog.RootPart.LocalId, i4);
813 Assert.That(t4, Is.Null);
814 }
815
816 [Test]
817 public void T052_RemoveObject()
818 {
819 TestHelpers.InMethod();
820
821 db.RemoveObject(prim1, region1);
822 SceneObjectGroup sog = FindSOG("object1", region1);
823 Assert.That(sog, Is.Null);
824 }
825
826 [Test]
827 public void T100_DefaultRegionInfo()
828 {
829 TestHelpers.InMethod();
830
831 RegionSettings r1 = db.LoadRegionSettings(region1);
832 Assert.That(r1.RegionUUID, Is.EqualTo(region1), "Assert.That(r1.RegionUUID, Is.EqualTo(region1))");
833
834 RegionSettings r2 = db.LoadRegionSettings(region2);
835 Assert.That(r2.RegionUUID, Is.EqualTo(region2), "Assert.That(r2.RegionUUID, Is.EqualTo(region2))");
836 }
837
838 [Test]
839 public void T101_UpdateRegionInfo()
840 {
841 TestHelpers.InMethod();
842
843 int agentlimit = random.Next();
844 double objectbonus = random.Next();
845 int maturity = random.Next();
846 UUID tertex1 = UUID.Random();
847 UUID tertex2 = UUID.Random();
848 UUID tertex3 = UUID.Random();
849 UUID tertex4 = UUID.Random();
850 double elev1nw = random.Next();
851 double elev2nw = random.Next();
852 double elev1ne = random.Next();
853 double elev2ne = random.Next();
854 double elev1se = random.Next();
855 double elev2se = random.Next();
856 double elev1sw = random.Next();
857 double elev2sw = random.Next();
858 double waterh = random.Next();
859 double terrainraise = random.Next();
860 double terrainlower = random.Next();
861 Vector3 sunvector = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5));
862 UUID terimgid = UUID.Random();
863 double sunpos = random.Next();
864 UUID cov = UUID.Random();
865
866 RegionSettings r1 = db.LoadRegionSettings(region1);
867 r1.BlockTerraform = true;
868 r1.BlockFly = true;
869 r1.AllowDamage = true;
870 r1.RestrictPushing = true;
871 r1.AllowLandResell = false;
872 r1.AllowLandJoinDivide = false;
873 r1.BlockShowInSearch = true;
874 r1.AgentLimit = agentlimit;
875 r1.ObjectBonus = objectbonus;
876 r1.Maturity = maturity;
877 r1.DisableScripts = true;
878 r1.DisableCollisions = true;
879 r1.DisablePhysics = true;
880 r1.TerrainTexture1 = tertex1;
881 r1.TerrainTexture2 = tertex2;
882 r1.TerrainTexture3 = tertex3;
883 r1.TerrainTexture4 = tertex4;
884 r1.Elevation1NW = elev1nw;
885 r1.Elevation2NW = elev2nw;
886 r1.Elevation1NE = elev1ne;
887 r1.Elevation2NE = elev2ne;
888 r1.Elevation1SE = elev1se;
889 r1.Elevation2SE = elev2se;
890 r1.Elevation1SW = elev1sw;
891 r1.Elevation2SW = elev2sw;
892 r1.WaterHeight = waterh;
893 r1.TerrainRaiseLimit = terrainraise;
894 r1.TerrainLowerLimit = terrainlower;
895 r1.UseEstateSun = false;
896 r1.Sandbox = true;
897 r1.SunVector = sunvector;
898 r1.TerrainImageID = terimgid;
899 r1.FixedSun = true;
900 r1.SunPosition = sunpos;
901 r1.Covenant = cov;
902
903 db.StoreRegionSettings(r1);
904
905 RegionSettings r1a = db.LoadRegionSettings(region1);
906 Assert.That(r1a.RegionUUID, Is.EqualTo(region1), "Assert.That(r1a.RegionUUID, Is.EqualTo(region1))");
907 Assert.That(r1a.BlockTerraform,Is.True);
908 Assert.That(r1a.BlockFly,Is.True);
909 Assert.That(r1a.AllowDamage,Is.True);
910 Assert.That(r1a.RestrictPushing,Is.True);
911 Assert.That(r1a.AllowLandResell,Is.False);
912 Assert.That(r1a.AllowLandJoinDivide,Is.False);
913 Assert.That(r1a.BlockShowInSearch,Is.True);
914 Assert.That(r1a.AgentLimit,Is.EqualTo(agentlimit), "Assert.That(r1a.AgentLimit,Is.EqualTo(agentlimit))");
915 Assert.That(r1a.ObjectBonus,Is.EqualTo(objectbonus), "Assert.That(r1a.ObjectBonus,Is.EqualTo(objectbonus))");
916 Assert.That(r1a.Maturity,Is.EqualTo(maturity), "Assert.That(r1a.Maturity,Is.EqualTo(maturity))");
917 Assert.That(r1a.DisableScripts,Is.True);
918 Assert.That(r1a.DisableCollisions,Is.True);
919 Assert.That(r1a.DisablePhysics,Is.True);
920 Assert.That(r1a.TerrainTexture1,Is.EqualTo(tertex1), "Assert.That(r1a.TerrainTexture1,Is.EqualTo(tertex1))");
921 Assert.That(r1a.TerrainTexture2,Is.EqualTo(tertex2), "Assert.That(r1a.TerrainTexture2,Is.EqualTo(tertex2))");
922 Assert.That(r1a.TerrainTexture3,Is.EqualTo(tertex3), "Assert.That(r1a.TerrainTexture3,Is.EqualTo(tertex3))");
923 Assert.That(r1a.TerrainTexture4,Is.EqualTo(tertex4), "Assert.That(r1a.TerrainTexture4,Is.EqualTo(tertex4))");
924 Assert.That(r1a.Elevation1NW,Is.EqualTo(elev1nw), "Assert.That(r1a.Elevation1NW,Is.EqualTo(elev1nw))");
925 Assert.That(r1a.Elevation2NW,Is.EqualTo(elev2nw), "Assert.That(r1a.Elevation2NW,Is.EqualTo(elev2nw))");
926 Assert.That(r1a.Elevation1NE,Is.EqualTo(elev1ne), "Assert.That(r1a.Elevation1NE,Is.EqualTo(elev1ne))");
927 Assert.That(r1a.Elevation2NE,Is.EqualTo(elev2ne), "Assert.That(r1a.Elevation2NE,Is.EqualTo(elev2ne))");
928 Assert.That(r1a.Elevation1SE,Is.EqualTo(elev1se), "Assert.That(r1a.Elevation1SE,Is.EqualTo(elev1se))");
929 Assert.That(r1a.Elevation2SE,Is.EqualTo(elev2se), "Assert.That(r1a.Elevation2SE,Is.EqualTo(elev2se))");
930 Assert.That(r1a.Elevation1SW,Is.EqualTo(elev1sw), "Assert.That(r1a.Elevation1SW,Is.EqualTo(elev1sw))");
931 Assert.That(r1a.Elevation2SW,Is.EqualTo(elev2sw), "Assert.That(r1a.Elevation2SW,Is.EqualTo(elev2sw))");
932 Assert.That(r1a.WaterHeight,Is.EqualTo(waterh), "Assert.That(r1a.WaterHeight,Is.EqualTo(waterh))");
933 Assert.That(r1a.TerrainRaiseLimit,Is.EqualTo(terrainraise), "Assert.That(r1a.TerrainRaiseLimit,Is.EqualTo(terrainraise))");
934 Assert.That(r1a.TerrainLowerLimit,Is.EqualTo(terrainlower), "Assert.That(r1a.TerrainLowerLimit,Is.EqualTo(terrainlower))");
935 Assert.That(r1a.UseEstateSun,Is.False);
936 Assert.That(r1a.Sandbox,Is.True);
937 Assert.That(r1a.SunVector,Is.EqualTo(sunvector), "Assert.That(r1a.SunVector,Is.EqualTo(sunvector))");
938 //Assert.That(r1a.TerrainImageID,Is.EqualTo(terimgid), "Assert.That(r1a.TerrainImageID,Is.EqualTo(terimgid))");
939 Assert.That(r1a.FixedSun,Is.True);
940 Assert.That(r1a.SunPosition, Is.EqualTo(sunpos), "Assert.That(r1a.SunPosition, Is.EqualTo(sunpos))");
941 Assert.That(r1a.Covenant, Is.EqualTo(cov), "Assert.That(r1a.Covenant, Is.EqualTo(cov))");
942 }
943
944 [Test]
945 public void T300_NoTerrain()
946 {
947 TestHelpers.InMethod();
948
949 Assert.That(db.LoadTerrain(zero), Is.Null);
950 Assert.That(db.LoadTerrain(region1), Is.Null);
951 Assert.That(db.LoadTerrain(region2), Is.Null);
952 Assert.That(db.LoadTerrain(UUID.Random()), Is.Null);
953 }
954
955 [Test]
956 public void T301_CreateTerrain()
957 {
958 TestHelpers.InMethod();
959
960 double[,] t1 = GenTerrain(height1);
961 db.StoreTerrain(t1, region1);
962
963 Assert.That(db.LoadTerrain(zero), Is.Null);
964 Assert.That(db.LoadTerrain(region1), Is.Not.Null);
965 Assert.That(db.LoadTerrain(region2), Is.Null);
966 Assert.That(db.LoadTerrain(UUID.Random()), Is.Null);
967 }
968
969 [Test]
970 public void T302_FetchTerrain()
971 {
972 TestHelpers.InMethod();
973
974 double[,] baseterrain1 = GenTerrain(height1);
975 double[,] baseterrain2 = GenTerrain(height2);
976 double[,] t1 = db.LoadTerrain(region1);
977 Assert.That(CompareTerrain(t1, baseterrain1), Is.True);
978 Assert.That(CompareTerrain(t1, baseterrain2), Is.False);
979 }
980
981 [Test]
982 public void T303_UpdateTerrain()
983 {
984 TestHelpers.InMethod();
985
986 double[,] baseterrain1 = GenTerrain(height1);
987 double[,] baseterrain2 = GenTerrain(height2);
988 db.StoreTerrain(baseterrain2, region1);
989
990 double[,] t1 = db.LoadTerrain(region1);
991 Assert.That(CompareTerrain(t1, baseterrain1), Is.False);
992 Assert.That(CompareTerrain(t1, baseterrain2), Is.True);
993 }
994
995 [Test]
996 public void T400_EmptyLand()
997 {
998 TestHelpers.InMethod();
999
1000 Assert.That(db.LoadLandObjects(zero).Count, Is.EqualTo(0), "Assert.That(db.LoadLandObjects(zero).Count, Is.EqualTo(0))");
1001 Assert.That(db.LoadLandObjects(region1).Count, Is.EqualTo(0), "Assert.That(db.LoadLandObjects(region1).Count, Is.EqualTo(0))");
1002 Assert.That(db.LoadLandObjects(region2).Count, Is.EqualTo(0), "Assert.That(db.LoadLandObjects(region2).Count, Is.EqualTo(0))");
1003 Assert.That(db.LoadLandObjects(UUID.Random()).Count, Is.EqualTo(0), "Assert.That(db.LoadLandObjects(UUID.Random()).Count, Is.EqualTo(0))");
1004 }
1005
1006 // TODO: we should have real land tests, but Land is so
1007 // intermingled with scene that you can't test it without a
1008 // valid scene. That requires some disagregation.
1009
1010
1011 //************************************************************************************//
1012 // Extra private methods
1013
1014 private double[,] GenTerrain(double value)
1015 {
1016 double[,] terret = new double[Constants.RegionSize, Constants.RegionSize];
1017 terret.Initialize();
1018 for (int x = 0; x < Constants.RegionSize; x++)
1019 for (int y = 0; y < Constants.RegionSize; y++)
1020 terret[x,y] = value;
1021
1022 return terret;
1023 }
1024
1025 private bool CompareTerrain(double[,] one, double[,] two)
1026 {
1027 for (int x = 0; x < Constants.RegionSize; x++)
1028 for (int y = 0; y < Constants.RegionSize; y++)
1029 if (one[x,y] != two[x,y])
1030 return false;
1031
1032 return true;
1033 }
1034
1035 private SceneObjectGroup FindSOG(string name, UUID r)
1036 {
1037 List<SceneObjectGroup> objs = db.LoadObjects(r);
1038 foreach (SceneObjectGroup sog in objs)
1039 if (sog.Name == name)
1040 return sog;
1041
1042 return null;
1043 }
1044
1045 // This builds a minimalistic Prim, 1 SOG with 1 root SOP. A
1046 // common failure case is people adding new fields that aren't
1047 // initialized, but have non-null db constraints. We should
1048 // honestly be passing more and more null things in here.
1049 //
1050 // Please note that in Sqlite.BuildPrim there is a commented out inline version
1051 // of this so you can debug and step through the build process and check the fields
1052 //
1053 // Real World Value: Tests for situation where extending a SceneObjectGroup/SceneObjectPart
1054 // causes the application to crash at the database layer because of null values
1055 // in NOT NULL fields
1056 //
1057 private SceneObjectGroup NewSOG(string name, UUID uuid, UUID regionId)
1058 {
1059 RegionInfo regionInfo = new RegionInfo();
1060 regionInfo.RegionID = regionId;
1061 regionInfo.RegionLocX = 0;
1062 regionInfo.RegionLocY = 0;
1063
1064 SceneObjectPart sop = new SceneObjectPart();
1065 sop.Name = name;
1066 sop.Description = name;
1067 sop.Text = RandomName();
1068 sop.SitName = RandomName();
1069 sop.TouchName = RandomName();
1070 sop.UUID = uuid;
1071 sop.Shape = PrimitiveBaseShape.Default;
1072
1073 SceneObjectGroup sog = new SceneObjectGroup(sop);
1074// sog.SetScene(scene);
1075
1076 return sog;
1077 }
1078
1079 private SceneObjectPart NewSOP(string name, UUID uuid)
1080 {
1081 SceneObjectPart sop = new SceneObjectPart();
1082 sop.Name = name;
1083 sop.Description = name;
1084 sop.Text = RandomName();
1085 sop.SitName = RandomName();
1086 sop.TouchName = RandomName();
1087 sop.UUID = uuid;
1088 sop.Shape = PrimitiveBaseShape.Default;
1089 return sop;
1090 }
1091
1092 // These are copied from the Inventory Item tests
1093
1094 private InventoryItemBase NewItem(UUID id, UUID parent, UUID owner, string name, UUID asset)
1095 {
1096 InventoryItemBase i = new InventoryItemBase();
1097 i.ID = id;
1098 i.Folder = parent;
1099 i.Owner = owner;
1100 i.CreatorId = owner.ToString();
1101 i.Name = name;
1102 i.Description = name;
1103 i.AssetID = asset;
1104 return i;
1105 }
1106
1107 private static string RandomName()
1108 {
1109 StringBuilder name = new StringBuilder();
1110 int size = random.Next(5,12);
1111 char ch ;
1112 for (int i=0; i<size; i++)
1113 {
1114 ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ;
1115 name.Append(ch);
1116 }
1117 return name.ToString();
1118 }
1119// private InventoryFolderBase NewFolder(UUID id, UUID parent, UUID owner, string name)
1120// {
1121// InventoryFolderBase f = new InventoryFolderBase();
1122// f.ID = id;
1123// f.ParentID = parent;
1124// f.Owner = owner;
1125// f.Name = name;
1126// return f;
1127// }
1128 }
1129}
diff --git a/OpenSim/Data/Tests/Resources/TestDataConnections.ini b/OpenSim/Data/Tests/Resources/TestDataConnections.ini
new file mode 100644
index 0000000..7b55467
--- /dev/null
+++ b/OpenSim/Data/Tests/Resources/TestDataConnections.ini
@@ -0,0 +1,24 @@
1; The default connections to the test databases. Used by all data tests based on BasicDataServiceTest.cs.
2; This is read by code in DefaultTestConns.cs.
3
4; NOTE that this INI file is currently loaded as a embedded RESOURCE, which is weird and has a
5; disadvantage of having to rebuild the Tests whenever the conn strings are changed.
6; The only reason is that I couldn't figure out a reliable way to put this INI into the correct
7; dir at runtime. If somebody can do it, that would be cool.
8
9; I'm using a local MSDE server for testing. Obviously, you'll have to modify
10; the conn string to whatever MS SQL server is available to you.
11
12; If any of the conn strings is commented out, emty or not valid on your system,
13; the relevant tests will be ignored, rather than fail.
14
15; As to SQLite, if the conn string here is empty, it will work anyway using a temporary
16; file for the DB. If you want the resulting DB to persist (e.g. for performance testing,
17; when filling up the tables can take a long time), explicitly specify a conn string like this:
18
19; SqliteConnection="URI=file:<path_to_your_file>,version=3"
20
21[TestConnections]
22MySqlConnection="Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;"
23SqlConnection="Server=.\SQL2008;Database=opensim-nunit;Trusted_Connection=True;"
24SqliteConnection="URI=file:opensim-nunit.db,version=3" \ No newline at end of file