opensim – Blame information for rev 1

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