1
0

BasicGridTest.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 System.Collections.Generic;
  29. using System.Text;
  30. using NUnit.Framework;
  31. using NUnit.Framework.SyntaxHelpers;
  32. using OpenMetaverse;
  33. namespace OpenSim.Data.Tests
  34. {
  35. public class BasicGridTest
  36. {
  37. public IGridDataPlugin db;
  38. public UUID region1, region2, region3;
  39. public UUID zero = UUID.Zero;
  40. public static Random random = new Random();
  41. [TearDown]
  42. public void removeAllRegions()
  43. {
  44. // Clean up all the regions.
  45. List<RegionProfileData> regions = db.GetRegionsByName("", 100);
  46. if (regions != null)
  47. {
  48. foreach (RegionProfileData region in regions)
  49. {
  50. db.DeleteProfile(region.Uuid.ToString());
  51. }
  52. }
  53. }
  54. public void SuperInit()
  55. {
  56. OpenSim.Tests.Common.TestLogging.LogToConsole();
  57. region1 = UUID.Random();
  58. region2 = UUID.Random();
  59. region3 = UUID.Random();
  60. }
  61. protected RegionProfileData createRegion(UUID regionUUID, string regionName)
  62. {
  63. RegionProfileData reg = new RegionProfileData();
  64. new PropertyScrambler<RegionProfileData>().Scramble(reg);
  65. reg.Uuid = regionUUID;
  66. reg.RegionName = regionName;
  67. db.StoreProfile(reg);
  68. return reg;
  69. }
  70. [Test]
  71. public void T001_LoadEmpty()
  72. {
  73. Assert.That(db.GetProfileByUUID(region1),Is.Null);
  74. Assert.That(db.GetProfileByUUID(region2),Is.Null);
  75. Assert.That(db.GetProfileByUUID(region3),Is.Null);
  76. Assert.That(db.GetProfileByUUID(zero),Is.Null);
  77. }
  78. [Test]
  79. public void T011_AddRetrieveCompleteTest()
  80. {
  81. RegionProfileData newreg = createRegion(region2, "|<Goth@m Ci1y>|");
  82. RegionProfileData retreg = db.GetProfileByUUID(region2);
  83. Assert.That(retreg, Constraints.PropertyCompareConstraint(newreg).IgnoreProperty(x => x.RegionOnline));
  84. retreg = db.GetProfileByHandle(newreg.RegionHandle);
  85. Assert.That(retreg.Uuid, Is.EqualTo(region2), "Assert.That(retreg.Uuid, Is.EqualTo(region2))");
  86. retreg = db.GetProfileByString(newreg.RegionName);
  87. Assert.That(retreg.Uuid, Is.EqualTo(region2), "Assert.That(retreg.Uuid, Is.EqualTo(region2))");
  88. RegionProfileData[] retregs = db.GetProfilesInRange(newreg.RegionLocX,newreg.RegionLocY,newreg.RegionLocX,newreg.RegionLocY);
  89. Assert.That(retregs[0].Uuid, Is.EqualTo(region2), "Assert.That(retregs[0].Uuid, Is.EqualTo(region2))");
  90. }
  91. [Test]
  92. public void T012_DeleteProfile()
  93. {
  94. createRegion(region1, "doesn't matter");
  95. db.DeleteProfile(region1.ToString());
  96. RegionProfileData retreg = db.GetProfileByUUID(region1);
  97. Assert.That(retreg,Is.Null);
  98. }
  99. [Test]
  100. public void T013_UpdateProfile()
  101. {
  102. createRegion(region2, "|<Goth@m Ci1y>|");
  103. RegionProfileData retreg = db.GetProfileByUUID(region2);
  104. retreg.regionName = "Gotham City";
  105. db.StoreProfile(retreg);
  106. retreg = db.GetProfileByUUID(region2);
  107. Assert.That(retreg.RegionName, Is.EqualTo("Gotham City"), "Assert.That(retreg.RegionName, Is.EqualTo(\"Gotham City\"))");
  108. }
  109. [Test]
  110. public void T014_RegionList()
  111. {
  112. createRegion(region2, "Gotham City");
  113. RegionProfileData retreg = db.GetProfileByUUID(region2);
  114. retreg.RegionName = "Gotham Town";
  115. retreg.Uuid = region1;
  116. db.StoreProfile(retreg);
  117. retreg = db.GetProfileByUUID(region2);
  118. retreg.RegionName = "Gothan Town";
  119. retreg.Uuid = region3;
  120. db.StoreProfile(retreg);
  121. List<RegionProfileData> listreg = db.GetRegionsByName("Gotham",10);
  122. Assert.That(listreg.Count,Is.EqualTo(2), "Assert.That(listreg.Count,Is.EqualTo(2))");
  123. Assert.That(listreg[0].Uuid,Is.Not.EqualTo(listreg[1].Uuid), "Assert.That(listreg[0].Uuid,Is.Not.EqualTo(listreg[1].Uuid))");
  124. Assert.That(listreg[0].Uuid, Is.EqualTo(region1) | Is.EqualTo(region2), "Assert.That(listreg[0].Uuid, Is.EqualTo(region1) | Is.EqualTo(region2))");
  125. Assert.That(listreg[1].Uuid, Is.EqualTo(region1) | Is.EqualTo(region2), "Assert.That(listreg[1].Uuid, Is.EqualTo(region1) | Is.EqualTo(region2))");
  126. }
  127. [Test]
  128. public void T999_StillNull()
  129. {
  130. Assert.That(db.GetProfileByUUID(zero), Is.Null);
  131. }
  132. protected static string RandomName()
  133. {
  134. StringBuilder name = new StringBuilder();
  135. int size = random.Next(5,12);
  136. char ch ;
  137. for (int i=0; i<size; i++)
  138. {
  139. ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ;
  140. name.Append(ch);
  141. }
  142. return name.ToString();
  143. }
  144. }
  145. }