EstateTests.cs 20 KB

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