BasicGridTest.cs 11 KB

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