BasicGridTest.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 OpenSim 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 OpenSim.Data;
  33. using OpenSim.Framework;
  34. using OpenSim.Region.Environment.Scenes;
  35. using OpenMetaverse;
  36. namespace OpenSim.Data.Tests
  37. {
  38. public class BasicGridTest
  39. {
  40. public GridDataBase db;
  41. public UUID region1, region2, region3;
  42. public UUID zero = UUID.Zero;
  43. public static Random random;
  44. public void SuperInit()
  45. {
  46. try
  47. {
  48. log4net.Config.XmlConfigurator.Configure();
  49. }
  50. catch (Exception)
  51. {
  52. // I don't care, just leave log4net off
  53. }
  54. region1 = UUID.Random();
  55. region2 = UUID.Random();
  56. region3 = UUID.Random();
  57. random = new Random();
  58. }
  59. [Test]
  60. public void T001_LoadEmpty()
  61. {
  62. Assert.That(db.GetProfileByUUID(region1),Is.Null);
  63. Assert.That(db.GetProfileByUUID(region2),Is.Null);
  64. Assert.That(db.GetProfileByUUID(region3),Is.Null);
  65. Assert.That(db.GetProfileByUUID(zero),Is.Null);
  66. }
  67. [Test]
  68. public void T999_StillNull()
  69. {
  70. Assert.That(db.GetProfileByUUID(zero),Is.Null);
  71. }
  72. [Test]
  73. public void T010_SimpleAddRetrieveProfile()
  74. {
  75. RegionProfileData reg = new RegionProfileData();
  76. reg.Uuid = region1;
  77. reg.RegionName = "My new Region";
  78. reg.RegionHandle = (ulong) random.Next();
  79. reg.RegionLocX = 1000;
  80. reg.RegionLocY = 1000;
  81. reg.RegionLocZ = 0;
  82. db.AddProfile(reg);
  83. RegionProfileData retreg = db.GetProfileByUUID(region1);
  84. Assert.That(retreg.RegionName, Is.EqualTo("My new Region"));
  85. Assert.That(retreg.Uuid, Is.EqualTo(region1));
  86. }
  87. [Test]
  88. public void T011_AddRetrieveCompleteTest()
  89. {
  90. string regionname = "|<Goth@m Ci1y>|";
  91. ulong regionhandle = (ulong) random.Next();
  92. uint regionlocx = (uint) random.Next();
  93. uint regionlocy = (uint) random.Next();
  94. uint regionlocz = (uint) random.Next();
  95. string regionsendkey = RandomName();
  96. string regionrecvkey = RandomName();
  97. string regionsecret = RandomName();
  98. bool regiononline = false;
  99. string serverip = RandomName();
  100. uint serverport = (uint) random.Next();
  101. string serveruri = RandomName();
  102. uint serverhttpport = (uint) random.Next();
  103. uint serverremotingport = (uint) random.Next();
  104. ulong northovrhandle = (ulong) random.Next();
  105. ulong southovrhandle = (ulong) random.Next();
  106. ulong eastovrhandle = (ulong) random.Next();
  107. ulong westovrhandle = (ulong) random.Next();
  108. string regiondatauri = RandomName();
  109. string regionasseturi = RandomName();
  110. string regionassetsendkey = RandomName();
  111. string regionassetrcvkey = RandomName();
  112. string regionuseruri = RandomName();
  113. string regionusersendkey = RandomName();
  114. string regionuserrcvkey = RandomName();
  115. UUID regionmaptextureid = UUID.Random();
  116. UUID owner_uuid = UUID.Random();
  117. UUID originuuid = UUID.Random();
  118. RegionProfileData reg = new RegionProfileData();
  119. reg.Uuid = region2;
  120. reg.RegionName = regionname;
  121. reg.RegionHandle = regionhandle;
  122. reg.RegionLocX = regionlocx;
  123. reg.RegionLocY = regionlocy;
  124. reg.RegionLocZ = regionlocz;
  125. reg.RegionSendKey = regionsendkey;
  126. reg.RegionRecvKey = regionrecvkey;
  127. reg.RegionSecret = regionsecret;
  128. reg.RegionOnline = regiononline;
  129. reg.OriginUUID = originuuid;
  130. reg.ServerIP = serverip;
  131. reg.ServerPort = serverport;
  132. reg.ServerURI = serveruri;
  133. reg.ServerHttpPort = serverhttpport;
  134. reg.ServerRemotingPort = serverremotingport;
  135. reg.NorthOverrideHandle = northovrhandle;
  136. reg.SouthOverrideHandle = southovrhandle;
  137. reg.EastOverrideHandle = eastovrhandle;
  138. reg.WestOverrideHandle = westovrhandle;
  139. reg.RegionDataURI = regiondatauri;
  140. reg.RegionAssetURI = regionasseturi;
  141. reg.RegionAssetSendKey = regionassetsendkey;
  142. reg.RegionAssetRecvKey = regionassetrcvkey;
  143. reg.RegionUserURI = regionuseruri;
  144. reg.RegionUserSendKey = regionusersendkey;
  145. reg.RegionUserRecvKey = regionuserrcvkey;
  146. reg.RegionMapTextureID = regionmaptextureid;
  147. reg.Owner_uuid = owner_uuid;
  148. reg.OriginUUID = originuuid;
  149. db.AddProfile(reg);
  150. RegionProfileData retreg = db.GetProfileByUUID(region2);
  151. Assert.That(retreg.RegionName, Is.EqualTo(regionname));
  152. Assert.That(retreg.Uuid, Is.EqualTo(region2));
  153. Assert.That(retreg.RegionHandle, Is.EqualTo(regionhandle));
  154. Assert.That(retreg.RegionLocX, Is.EqualTo(regionlocx));
  155. Assert.That(retreg.RegionLocY, Is.EqualTo(regionlocy));
  156. Assert.That(retreg.RegionLocZ, Is.EqualTo(regionlocz));
  157. Assert.That(retreg.RegionSendKey, Is.EqualTo(regionsendkey));
  158. Assert.That(retreg.RegionRecvKey, Is.EqualTo(regionrecvkey));
  159. Assert.That(retreg.RegionSecret, Is.EqualTo(regionsecret));
  160. Assert.That(retreg.RegionOnline, Is.EqualTo(regiononline));
  161. Assert.That(retreg.OriginUUID, Is.EqualTo(originuuid));
  162. Assert.That(retreg.ServerIP, Is.EqualTo(serverip));
  163. Assert.That(retreg.ServerPort, Is.EqualTo(serverport));
  164. Assert.That(retreg.ServerURI, Is.EqualTo(serveruri));
  165. Assert.That(retreg.ServerHttpPort, Is.EqualTo(serverhttpport));
  166. Assert.That(retreg.ServerRemotingPort, Is.EqualTo(serverremotingport));
  167. Assert.That(retreg.NorthOverrideHandle, Is.EqualTo(northovrhandle));
  168. Assert.That(retreg.SouthOverrideHandle, Is.EqualTo(southovrhandle));
  169. Assert.That(retreg.EastOverrideHandle, Is.EqualTo(eastovrhandle));
  170. Assert.That(retreg.WestOverrideHandle, Is.EqualTo(westovrhandle));
  171. Assert.That(retreg.RegionDataURI, Is.EqualTo(regiondatauri));
  172. Assert.That(retreg.RegionAssetURI, Is.EqualTo(regionasseturi));
  173. Assert.That(retreg.RegionAssetSendKey, Is.EqualTo(regionassetsendkey));
  174. Assert.That(retreg.RegionAssetRecvKey, Is.EqualTo(regionassetrcvkey));
  175. Assert.That(retreg.RegionUserURI, Is.EqualTo(regionuseruri));
  176. Assert.That(retreg.RegionUserSendKey, Is.EqualTo(regionusersendkey));
  177. Assert.That(retreg.RegionUserRecvKey, Is.EqualTo(regionuserrcvkey));
  178. Assert.That(retreg.RegionMapTextureID, Is.EqualTo(regionmaptextureid));
  179. Assert.That(retreg.Owner_uuid, Is.EqualTo(owner_uuid));
  180. Assert.That(retreg.OriginUUID, Is.EqualTo(originuuid));
  181. retreg = db.GetProfileByHandle(regionhandle);
  182. Assert.That(retreg.Uuid, Is.EqualTo(region2));
  183. retreg = db.GetProfileByString(regionname);
  184. Assert.That(retreg.Uuid, Is.EqualTo(region2));
  185. RegionProfileData[] retregs = db.GetProfilesInRange(regionlocx,regionlocy,regionlocx,regionlocy);
  186. Assert.That(retregs[0].Uuid, Is.EqualTo(region2));
  187. }
  188. [Test]
  189. public void T012_DeleteProfile()
  190. {
  191. db.DeleteProfile(region1.ToString());
  192. RegionProfileData retreg = db.GetProfileByUUID(region1);
  193. Assert.That(retreg,Is.Null);
  194. }
  195. [Test]
  196. public void T013_UpdateProfile()
  197. {
  198. RegionProfileData retreg = db.GetProfileByUUID(region2);
  199. retreg.regionName = "Gotham City";
  200. db.UpdateProfile(retreg);
  201. retreg = db.GetProfileByUUID(region2);
  202. Assert.That(retreg.RegionName, Is.EqualTo("Gotham City"));
  203. }
  204. [Test]
  205. public void T014_RegionList()
  206. {
  207. RegionProfileData retreg = db.GetProfileByUUID(region2);
  208. retreg.RegionName = "Gotham Town";
  209. retreg.Uuid = region1;
  210. db.AddProfile(retreg);
  211. retreg = db.GetProfileByUUID(region2);
  212. retreg.RegionName = "Gothan Town";
  213. retreg.Uuid = region3;
  214. db.AddProfile(retreg);
  215. List<RegionProfileData> listreg = db.GetRegionsByName("Gotham",10);
  216. Assert.That(listreg.Count,Is.EqualTo(2));
  217. Assert.That(listreg[0].Uuid,Is.Not.EqualTo(listreg[1].Uuid));
  218. Assert.That(listreg[0].Uuid, Is.EqualTo(region1) | Is.EqualTo(region2));
  219. Assert.That(listreg[1].Uuid, Is.EqualTo(region1) | Is.EqualTo(region2));
  220. }
  221. [Test]
  222. public static string RandomName()
  223. {
  224. StringBuilder name = new StringBuilder();
  225. int size = random.Next(5,12);
  226. char ch ;
  227. for (int i=0; i<size; i++)
  228. {
  229. ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ;
  230. name.Append(ch);
  231. }
  232. return name.ToString();
  233. }
  234. }
  235. }