1
0

EstateTests.cs 19 KB

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