1
0

EstateTests.cs 20 KB

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