EstateTests.cs 20 KB

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