aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/Tests/EstateTests.cs
diff options
context:
space:
mode:
authorMelanie2010-05-26 17:19:02 +0100
committerMelanie2010-05-26 17:19:02 +0100
commit97501495eb2f54912b862d9dd544ca467e8b9d1e (patch)
tree3fed12f5c6bcc514368b40b16a0a0f165ab9aac1 /OpenSim/Data/Tests/EstateTests.cs
parentMerge branch 'master' into careminster-presence-refactor (diff)
parentMerge branch 'master' of melanie@opensimulator.org:/var/git/opensim (diff)
downloadopensim-SC-97501495eb2f54912b862d9dd544ca467e8b9d1e.zip
opensim-SC-97501495eb2f54912b862d9dd544ca467e8b9d1e.tar.gz
opensim-SC-97501495eb2f54912b862d9dd544ca467e8b9d1e.tar.bz2
opensim-SC-97501495eb2f54912b862d9dd544ca467e8b9d1e.tar.xz
Merge branch 'master' into careminster-presence-refactor
Diffstat (limited to 'OpenSim/Data/Tests/EstateTests.cs')
-rw-r--r--OpenSim/Data/Tests/EstateTests.cs531
1 files changed, 531 insertions, 0 deletions
diff --git a/OpenSim/Data/Tests/EstateTests.cs b/OpenSim/Data/Tests/EstateTests.cs
new file mode 100644
index 0000000..d6eed3d
--- /dev/null
+++ b/OpenSim/Data/Tests/EstateTests.cs
@@ -0,0 +1,531 @@
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 NUnit.Framework.SyntaxHelpers;
32using OpenMetaverse;
33using OpenSim.Framework;
34using OpenSim.Region.Framework.Interfaces;
35using System.Text;
36using log4net;
37using System.Reflection;
38using System.Data.Common;
39
40#if !NUNIT25
41using NUnit.Framework.SyntaxHelpers;
42#endif
43
44
45// DBMS-specific:
46using MySql.Data.MySqlClient;
47using OpenSim.Data.MySQL;
48
49using System.Data.SqlClient;
50using OpenSim.Data.MSSQL;
51
52using Mono.Data.Sqlite;
53using OpenSim.Data.SQLite;
54
55
56namespace OpenSim.Data.Tests
57{
58
59#if NUNIT25
60
61 [TestFixture(typeof(MySqlConnection), typeof(MySQLEstateStore), Description = "Estate store tests (MySQL)")]
62 [TestFixture(typeof(SqlConnection), typeof(MSSQLEstateStore), Description = "Estate store tests (MS SQL Server)")]
63 [TestFixture(typeof(SqliteConnection), typeof(SQLiteEstateStore), Description = "Estate store tests (SQLite)")]
64
65#else
66
67 [TestFixture(Description = "Estate store tests (SQLite)")]
68 public class SQLiteEstateTests : EstateTests<SqliteConnection, SQLiteEstateStore>
69 {
70 }
71
72 [TestFixture(Description = "Estate store tests (MySQL)")]
73 public class MySqlEstateTests : EstateTests<MySqlConnection, MySQLEstateStore>
74 {
75 }
76
77 [TestFixture(Description = "Estate store tests (MS SQL Server)")]
78 public class MSSQLEstateTests : EstateTests<SqlConnection, MSSQLEstateStore>
79 {
80 }
81
82#endif
83
84 public class EstateTests<TConn, TEstateStore> : BasicDataServiceTest<TConn, TEstateStore>
85 where TConn : DbConnection, new()
86 where TEstateStore : class, IEstateDataStore, new()
87 {
88 public IEstateDataStore db;
89
90 public static UUID REGION_ID = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed7");
91
92 public static UUID USER_ID_1 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed1");
93 public static UUID USER_ID_2 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed2");
94
95 public static UUID MANAGER_ID_1 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed3");
96 public static UUID MANAGER_ID_2 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed4");
97
98 public static UUID GROUP_ID_1 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed5");
99 public static UUID GROUP_ID_2 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed6");
100
101 protected override void InitService(object service)
102 {
103 ClearDB();
104 db = (IEstateDataStore)service;
105 db.Initialise(m_connStr);
106 }
107
108 private void ClearDB()
109 {
110 // if a new table is added, it has to be dropped here
111 DropTables(
112 "estate_managers",
113 "estate_groups",
114 "estate_users",
115 "estateban",
116 "estate_settings",
117 "estate_map"
118 );
119 ResetMigrations("EstateStore");
120 }
121
122 #region 0Tests
123
124 [Test]
125 public void T010_EstateSettingsSimpleStorage_MinimumParameterSet()
126 {
127 EstateSettingsSimpleStorage(
128 REGION_ID,
129 DataTestUtil.STRING_MIN,
130 DataTestUtil.UNSIGNED_INTEGER_MIN,
131 DataTestUtil.FLOAT_MIN,
132 DataTestUtil.INTEGER_MIN,
133 DataTestUtil.INTEGER_MIN,
134 DataTestUtil.INTEGER_MIN,
135 DataTestUtil.BOOLEAN_MIN,
136 DataTestUtil.BOOLEAN_MIN,
137 DataTestUtil.DOUBLE_MIN,
138 DataTestUtil.BOOLEAN_MIN,
139 DataTestUtil.BOOLEAN_MIN,
140 DataTestUtil.BOOLEAN_MIN,
141 DataTestUtil.BOOLEAN_MIN,
142 DataTestUtil.BOOLEAN_MIN,
143 DataTestUtil.BOOLEAN_MIN,
144 DataTestUtil.BOOLEAN_MIN,
145 DataTestUtil.BOOLEAN_MIN,
146 DataTestUtil.BOOLEAN_MIN,
147 DataTestUtil.BOOLEAN_MIN,
148 DataTestUtil.BOOLEAN_MIN,
149 DataTestUtil.BOOLEAN_MIN,
150 DataTestUtil.STRING_MIN,
151 DataTestUtil.UUID_MIN
152 );
153 }
154
155 [Test]
156 public void T011_EstateSettingsSimpleStorage_MaximumParameterSet()
157 {
158 EstateSettingsSimpleStorage(
159 REGION_ID,
160 DataTestUtil.STRING_MAX(64),
161 DataTestUtil.UNSIGNED_INTEGER_MAX,
162 DataTestUtil.FLOAT_MAX,
163 DataTestUtil.INTEGER_MAX,
164 DataTestUtil.INTEGER_MAX,
165 DataTestUtil.INTEGER_MAX,
166 DataTestUtil.BOOLEAN_MAX,
167 DataTestUtil.BOOLEAN_MAX,
168 DataTestUtil.DOUBLE_MAX,
169 DataTestUtil.BOOLEAN_MAX,
170 DataTestUtil.BOOLEAN_MAX,
171 DataTestUtil.BOOLEAN_MAX,
172 DataTestUtil.BOOLEAN_MAX,
173 DataTestUtil.BOOLEAN_MAX,
174 DataTestUtil.BOOLEAN_MAX,
175 DataTestUtil.BOOLEAN_MAX,
176 DataTestUtil.BOOLEAN_MAX,
177 DataTestUtil.BOOLEAN_MAX,
178 DataTestUtil.BOOLEAN_MAX,
179 DataTestUtil.BOOLEAN_MAX,
180 DataTestUtil.BOOLEAN_MAX,
181 DataTestUtil.STRING_MAX(255),
182 DataTestUtil.UUID_MAX
183 );
184 }
185
186 [Test]
187 public void T012_EstateSettingsSimpleStorage_AccurateParameterSet()
188 {
189 EstateSettingsSimpleStorage(
190 REGION_ID,
191 DataTestUtil.STRING_MAX(1),
192 DataTestUtil.UNSIGNED_INTEGER_MIN,
193 DataTestUtil.FLOAT_ACCURATE,
194 DataTestUtil.INTEGER_MIN,
195 DataTestUtil.INTEGER_MIN,
196 DataTestUtil.INTEGER_MIN,
197 DataTestUtil.BOOLEAN_MIN,
198 DataTestUtil.BOOLEAN_MIN,
199 DataTestUtil.DOUBLE_ACCURATE,
200 DataTestUtil.BOOLEAN_MIN,
201 DataTestUtil.BOOLEAN_MIN,
202 DataTestUtil.BOOLEAN_MIN,
203 DataTestUtil.BOOLEAN_MIN,
204 DataTestUtil.BOOLEAN_MIN,
205 DataTestUtil.BOOLEAN_MIN,
206 DataTestUtil.BOOLEAN_MIN,
207 DataTestUtil.BOOLEAN_MIN,
208 DataTestUtil.BOOLEAN_MIN,
209 DataTestUtil.BOOLEAN_MIN,
210 DataTestUtil.BOOLEAN_MIN,
211 DataTestUtil.BOOLEAN_MIN,
212 DataTestUtil.STRING_MAX(1),
213 DataTestUtil.UUID_MIN
214 );
215 }
216
217 [Test]
218 public void T012_EstateSettingsRandomStorage()
219 {
220 // Letting estate store generate rows to database for us
221 EstateSettings originalSettings = db.LoadEstateSettings(REGION_ID, true);
222 new PropertyScrambler<EstateSettings>()
223 .DontScramble(x=>x.EstateID)
224 .Scramble(originalSettings);
225
226 // Saving settings.
227 db.StoreEstateSettings(originalSettings);
228
229 // Loading settings to another instance variable.
230 EstateSettings loadedSettings = db.LoadEstateSettings(REGION_ID, true);
231
232 // Checking that loaded values are correct.
233 Assert.That(loadedSettings, Constraints.PropertyCompareConstraint(originalSettings));
234 }
235
236 [Test]
237 public void T020_EstateSettingsManagerList()
238 {
239 // Letting estate store generate rows to database for us
240 EstateSettings originalSettings = db.LoadEstateSettings(REGION_ID, true);
241
242 originalSettings.EstateManagers = new UUID[] { MANAGER_ID_1, MANAGER_ID_2 };
243
244 // Saving settings.
245 db.StoreEstateSettings(originalSettings);
246
247 // Loading settings to another instance variable.
248 EstateSettings loadedSettings = db.LoadEstateSettings(REGION_ID, true);
249
250 Assert.AreEqual(2, loadedSettings.EstateManagers.Length);
251 Assert.AreEqual(MANAGER_ID_1, loadedSettings.EstateManagers[0]);
252 Assert.AreEqual(MANAGER_ID_2, loadedSettings.EstateManagers[1]);
253 }
254
255 [Test]
256 public void T021_EstateSettingsUserList()
257 {
258 // Letting estate store generate rows to database for us
259 EstateSettings originalSettings = db.LoadEstateSettings(REGION_ID, true);
260
261 originalSettings.EstateAccess = new UUID[] { USER_ID_1, USER_ID_2 };
262
263 // Saving settings.
264 db.StoreEstateSettings(originalSettings);
265
266 // Loading settings to another instance variable.
267 EstateSettings loadedSettings = db.LoadEstateSettings(REGION_ID, true);
268
269 Assert.AreEqual(2, loadedSettings.EstateAccess.Length);
270 Assert.AreEqual(USER_ID_1, loadedSettings.EstateAccess[0]);
271 Assert.AreEqual(USER_ID_2, loadedSettings.EstateAccess[1]);
272 }
273
274 [Test]
275 public void T022_EstateSettingsGroupList()
276 {
277 // Letting estate store generate rows to database for us
278 EstateSettings originalSettings = db.LoadEstateSettings(REGION_ID, true);
279
280 originalSettings.EstateGroups = new UUID[] { GROUP_ID_1, GROUP_ID_2 };
281
282 // Saving settings.
283 db.StoreEstateSettings(originalSettings);
284
285 // Loading settings to another instance variable.
286 EstateSettings loadedSettings = db.LoadEstateSettings(REGION_ID, true);
287
288 Assert.AreEqual(2, loadedSettings.EstateAccess.Length);
289 Assert.AreEqual(GROUP_ID_1, loadedSettings.EstateGroups[0]);
290 Assert.AreEqual(GROUP_ID_2, loadedSettings.EstateGroups[1]);
291 }
292
293 [Test]
294 public void T022_EstateSettingsBanList()
295 {
296 // Letting estate store generate rows to database for us
297 EstateSettings originalSettings = db.LoadEstateSettings(REGION_ID, true);
298
299 EstateBan estateBan1 = new EstateBan();
300 estateBan1.BannedUserID = DataTestUtil.UUID_MIN;
301
302 EstateBan estateBan2 = new EstateBan();
303 estateBan2.BannedUserID = DataTestUtil.UUID_MAX;
304
305 originalSettings.EstateBans = new EstateBan[] { estateBan1, estateBan2 };
306
307 // Saving settings.
308 db.StoreEstateSettings(originalSettings);
309
310 // Loading settings to another instance variable.
311 EstateSettings loadedSettings = db.LoadEstateSettings(REGION_ID, true);
312
313 Assert.AreEqual(2, loadedSettings.EstateBans.Length);
314 Assert.AreEqual(DataTestUtil.UUID_MIN, loadedSettings.EstateBans[0].BannedUserID);
315
316 Assert.AreEqual(DataTestUtil.UUID_MAX, loadedSettings.EstateBans[1].BannedUserID);
317
318 }
319
320 #endregion
321
322 #region Parametrizable Test Implementations
323
324 private void EstateSettingsSimpleStorage(
325 UUID regionId,
326 string estateName,
327 uint parentEstateID,
328 float billableFactor,
329 int pricePerMeter,
330 int redirectGridX,
331 int redirectGridY,
332 bool useGlobalTime,
333 bool fixedSun,
334 double sunPosition,
335 bool allowVoice,
336 bool allowDirectTeleport,
337 bool resetHomeOnTeleport,
338 bool denyAnonymous,
339 bool denyIdentified,
340 bool denyTransacted,
341 bool denyMinors,
342 bool abuseEmailToEstateOwner,
343 bool blockDwell,
344 bool estateSkipScripts,
345 bool taxFree,
346 bool publicAccess,
347 string abuseEmail,
348 UUID estateOwner
349 )
350 {
351
352 // Letting estate store generate rows to database for us
353 EstateSettings originalSettings = db.LoadEstateSettings(regionId, true);
354
355 SetEstateSettings(originalSettings,
356 estateName,
357 parentEstateID,
358 billableFactor,
359 pricePerMeter,
360 redirectGridX,
361 redirectGridY,
362 useGlobalTime,
363 fixedSun,
364 sunPosition,
365 allowVoice,
366 allowDirectTeleport,
367 resetHomeOnTeleport,
368 denyAnonymous,
369 denyIdentified,
370 denyTransacted,
371 denyMinors,
372 abuseEmailToEstateOwner,
373 blockDwell,
374 estateSkipScripts,
375 taxFree,
376 publicAccess,
377 abuseEmail,
378 estateOwner
379 );
380
381 // Saving settings.
382 db.StoreEstateSettings(originalSettings);
383
384 // Loading settings to another instance variable.
385 EstateSettings loadedSettings = db.LoadEstateSettings(regionId, true);
386
387 // Checking that loaded values are correct.
388 ValidateEstateSettings(loadedSettings,
389 estateName,
390 parentEstateID,
391 billableFactor,
392 pricePerMeter,
393 redirectGridX,
394 redirectGridY,
395 useGlobalTime,
396 fixedSun,
397 sunPosition,
398 allowVoice,
399 allowDirectTeleport,
400 resetHomeOnTeleport,
401 denyAnonymous,
402 denyIdentified,
403 denyTransacted,
404 denyMinors,
405 abuseEmailToEstateOwner,
406 blockDwell,
407 estateSkipScripts,
408 taxFree,
409 publicAccess,
410 abuseEmail,
411 estateOwner
412 );
413
414 }
415
416 #endregion
417
418 #region EstateSetting Initialization and Validation Methods
419
420 private void SetEstateSettings(
421 EstateSettings estateSettings,
422 string estateName,
423 uint parentEstateID,
424 float billableFactor,
425 int pricePerMeter,
426 int redirectGridX,
427 int redirectGridY,
428 bool useGlobalTime,
429 bool fixedSun,
430 double sunPosition,
431 bool allowVoice,
432 bool allowDirectTeleport,
433 bool resetHomeOnTeleport,
434 bool denyAnonymous,
435 bool denyIdentified,
436 bool denyTransacted,
437 bool denyMinors,
438 bool abuseEmailToEstateOwner,
439 bool blockDwell,
440 bool estateSkipScripts,
441 bool taxFree,
442 bool publicAccess,
443 string abuseEmail,
444 UUID estateOwner
445 )
446 {
447 estateSettings.EstateName = estateName;
448 estateSettings.ParentEstateID = parentEstateID;
449 estateSettings.BillableFactor = billableFactor;
450 estateSettings.PricePerMeter = pricePerMeter;
451 estateSettings.RedirectGridX = redirectGridX;
452 estateSettings.RedirectGridY = redirectGridY;
453 estateSettings.UseGlobalTime = useGlobalTime;
454 estateSettings.FixedSun = fixedSun;
455 estateSettings.SunPosition = sunPosition;
456 estateSettings.AllowVoice = allowVoice;
457 estateSettings.AllowDirectTeleport = allowDirectTeleport;
458 estateSettings.ResetHomeOnTeleport = resetHomeOnTeleport;
459 estateSettings.DenyAnonymous = denyAnonymous;
460 estateSettings.DenyIdentified = denyIdentified;
461 estateSettings.DenyTransacted = denyTransacted;
462 estateSettings.DenyMinors = denyMinors;
463 estateSettings.AbuseEmailToEstateOwner = abuseEmailToEstateOwner;
464 estateSettings.BlockDwell = blockDwell;
465 estateSettings.EstateSkipScripts = estateSkipScripts;
466 estateSettings.TaxFree = taxFree;
467 estateSettings.PublicAccess = publicAccess;
468 estateSettings.AbuseEmail = abuseEmail;
469 estateSettings.EstateOwner = estateOwner;
470 }
471
472 private void ValidateEstateSettings(
473 EstateSettings estateSettings,
474 string estateName,
475 uint parentEstateID,
476 float billableFactor,
477 int pricePerMeter,
478 int redirectGridX,
479 int redirectGridY,
480 bool useGlobalTime,
481 bool fixedSun,
482 double sunPosition,
483 bool allowVoice,
484 bool allowDirectTeleport,
485 bool resetHomeOnTeleport,
486 bool denyAnonymous,
487 bool denyIdentified,
488 bool denyTransacted,
489 bool denyMinors,
490 bool abuseEmailToEstateOwner,
491 bool blockDwell,
492 bool estateSkipScripts,
493 bool taxFree,
494 bool publicAccess,
495 string abuseEmail,
496 UUID estateOwner
497 )
498 {
499 Assert.AreEqual(estateName, estateSettings.EstateName);
500 Assert.AreEqual(parentEstateID, estateSettings.ParentEstateID);
501
502 DataTestUtil.AssertFloatEqualsWithTolerance(billableFactor, estateSettings.BillableFactor);
503
504 Assert.AreEqual(pricePerMeter, estateSettings.PricePerMeter);
505 Assert.AreEqual(redirectGridX, estateSettings.RedirectGridX);
506 Assert.AreEqual(redirectGridY, estateSettings.RedirectGridY);
507 Assert.AreEqual(useGlobalTime, estateSettings.UseGlobalTime);
508 Assert.AreEqual(fixedSun, estateSettings.FixedSun);
509
510 DataTestUtil.AssertDoubleEqualsWithTolerance(sunPosition, estateSettings.SunPosition);
511
512 Assert.AreEqual(allowVoice, estateSettings.AllowVoice);
513 Assert.AreEqual(allowDirectTeleport, estateSettings.AllowDirectTeleport);
514 Assert.AreEqual(resetHomeOnTeleport, estateSettings.ResetHomeOnTeleport);
515 Assert.AreEqual(denyAnonymous, estateSettings.DenyAnonymous);
516 Assert.AreEqual(denyIdentified, estateSettings.DenyIdentified);
517 Assert.AreEqual(denyTransacted, estateSettings.DenyTransacted);
518 Assert.AreEqual(denyMinors, estateSettings.DenyMinors);
519 Assert.AreEqual(abuseEmailToEstateOwner, estateSettings.AbuseEmailToEstateOwner);
520 Assert.AreEqual(blockDwell, estateSettings.BlockDwell);
521 Assert.AreEqual(estateSkipScripts, estateSettings.EstateSkipScripts);
522 Assert.AreEqual(taxFree, estateSettings.TaxFree);
523 Assert.AreEqual(publicAccess, estateSettings.PublicAccess);
524 Assert.AreEqual(abuseEmail, estateSettings.AbuseEmail);
525 Assert.AreEqual(estateOwner, estateSettings.EstateOwner);
526 }
527
528 #endregion
529
530 }
531}