BasicUserTest.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  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. // TODO: Money Transfer, Inventory Transfer and UpdateUserRegion once they exist
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Text;
  31. using log4net.Config;
  32. using NUnit.Framework;
  33. using NUnit.Framework.SyntaxHelpers;
  34. using OpenMetaverse;
  35. using OpenSim.Framework;
  36. using log4net;
  37. using System.Reflection;
  38. namespace OpenSim.Data.Tests
  39. {
  40. public class BasicUserTest
  41. {
  42. //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  43. public IUserDataPlugin db;
  44. public UUID user1;
  45. public UUID user2;
  46. public UUID user3;
  47. public UUID user4;
  48. public UUID user5;
  49. public UUID webkey;
  50. public UUID zero = UUID.Zero;
  51. public static Random random;
  52. public UUID agent1;
  53. public UUID agent2;
  54. public UUID agent3;
  55. public UUID agent4;
  56. public UUID region1;
  57. public string fname0;
  58. public string lname0;
  59. public string fname1;
  60. public string lname1;
  61. public string fname2;
  62. public string lname2;
  63. public string fname3;
  64. public string lname3;
  65. public void SuperInit()
  66. {
  67. OpenSim.Tests.Common.TestLogging.LogToConsole();
  68. random = new Random();
  69. user1 = UUID.Random();
  70. user2 = UUID.Random();
  71. user3 = UUID.Random();
  72. user4 = UUID.Random();
  73. user5 = UUID.Random();
  74. agent1 = UUID.Random();
  75. agent2 = UUID.Random();
  76. agent3 = UUID.Random();
  77. agent4 = UUID.Random();
  78. webkey = UUID.Random();
  79. region1 = UUID.Random();
  80. fname0 = RandomName();
  81. lname0 = RandomName();
  82. fname1 = RandomName();
  83. lname1 = RandomName();
  84. fname2 = RandomName();
  85. lname2 = RandomName();
  86. fname3 = RandomName();
  87. lname3 = RandomName();
  88. }
  89. [Test]
  90. public void T001_LoadEmpty()
  91. {
  92. Assert.That(db.GetUserByUUID(zero), Is.Null);
  93. Assert.That(db.GetUserByUUID(user1), Is.Null);
  94. Assert.That(db.GetUserByUUID(user2), Is.Null);
  95. Assert.That(db.GetUserByUUID(user3), Is.Null);
  96. Assert.That(db.GetUserByUUID(UUID.Random()), Is.Null);
  97. Assert.That(db.GetAgentByUUID(zero), Is.Null);
  98. Assert.That(db.GetAgentByUUID(agent1), Is.Null);
  99. Assert.That(db.GetAgentByUUID(agent2), Is.Null);
  100. Assert.That(db.GetAgentByUUID(agent3), Is.Null);
  101. Assert.That(db.GetAgentByUUID(UUID.Random()), Is.Null);
  102. }
  103. [Test]
  104. public void T010_CreateUser()
  105. {
  106. UserProfileData u1 = NewUser(user1,fname1,lname1);
  107. UserProfileData u2 = NewUser(user2,fname2,lname2);
  108. UserProfileData u3 = NewUser(user3,fname3,lname3);
  109. // this is used to check whether null works here
  110. u3.Email = null;
  111. db.AddNewUserProfile(u1);
  112. db.AddNewUserProfile(u2);
  113. db.AddNewUserProfile(u3);
  114. UserProfileData u1a = db.GetUserByUUID(user1);
  115. UserProfileData u2a = db.GetUserByUUID(user2);
  116. UserProfileData u3a = db.GetUserByUUID(user3);
  117. Assert.That(user1,Is.EqualTo(u1a.ID), "Assert.That(user1,Is.EqualTo(u1a.ID))");
  118. Assert.That(user2,Is.EqualTo(u2a.ID), "Assert.That(user2,Is.EqualTo(u2a.ID))");
  119. Assert.That(user3,Is.EqualTo(u3a.ID), "Assert.That(user3,Is.EqualTo(u3a.ID))");
  120. // and one email test
  121. Assert.That(u3.Email, Is.Null);
  122. }
  123. [Test]
  124. public void T011_FetchUserByName()
  125. {
  126. UserProfileData u1 = db.GetUserByName(fname1,lname1);
  127. UserProfileData u2 = db.GetUserByName(fname2,lname2);
  128. UserProfileData u3 = db.GetUserByName(fname3,lname3);
  129. Assert.That(user1,Is.EqualTo(u1.ID), "Assert.That(user1,Is.EqualTo(u1.ID))");
  130. Assert.That(user2,Is.EqualTo(u2.ID), "Assert.That(user2,Is.EqualTo(u2.ID))");
  131. Assert.That(user3,Is.EqualTo(u3.ID), "Assert.That(user3,Is.EqualTo(u3.ID))");
  132. }
  133. [Test]
  134. public void T012_UpdateUserProfile()
  135. {
  136. UserProfileData u1 = db.GetUserByUUID(user1);
  137. Assert.That(fname1,Is.EqualTo(u1.FirstName), "Assert.That(fname1,Is.EqualTo(u1.FirstName))");
  138. u1.FirstName = "Ugly";
  139. db.UpdateUserProfile(u1);
  140. Assert.That("Ugly",Is.EqualTo(u1.FirstName), "Assert.That(\"Ugly\",Is.EqualTo(u1.FirstName))");
  141. }
  142. [Test]
  143. public void T013_StoreUserWebKey()
  144. {
  145. UserProfileData u1 = db.GetUserByUUID(user1);
  146. Assert.That(u1.WebLoginKey,Is.EqualTo(zero), "Assert.That(u1.WebLoginKey,Is.EqualTo(zero))");
  147. db.StoreWebLoginKey(user1, webkey);
  148. u1 = db.GetUserByUUID(user1);
  149. Assert.That(u1.WebLoginKey,Is.EqualTo(webkey), "Assert.That(u1.WebLoginKey,Is.EqualTo(webkey))");
  150. }
  151. [Test]
  152. public void T014_ExpectedNullReferenceReturns()
  153. {
  154. UserProfileData u0 = NewUser(zero,fname0,lname0);
  155. UserProfileData u4 = NewUser(user4,fname2,lname2);
  156. db.AddNewUserProfile(u0); //UserID 0 should fail to save.
  157. db.AddNewUserProfile(u4); //The first name and last name are already in use (from T010), so this should fail too
  158. Assert.That(db.GetUserByUUID(zero),Is.Null);
  159. Assert.That(db.GetUserByUUID(user4),Is.Null);
  160. }
  161. [Test]
  162. public void T015_UserPersistency()
  163. {
  164. UserProfileData u = new UserProfileData();
  165. UUID id = user5;
  166. string fname = RandomName();
  167. string lname = RandomName();
  168. string email = RandomName();
  169. string passhash = RandomName();
  170. string passsalt = RandomName();
  171. UUID homeregion = UUID.Random();
  172. UUID webloginkey = UUID.Random();
  173. uint homeregx = (uint) random.Next();
  174. uint homeregy = (uint) random.Next();
  175. Vector3 homeloc
  176. = new Vector3(
  177. (float)Math.Round(random.NextDouble(), 5),
  178. (float)Math.Round(random.NextDouble(), 5),
  179. (float)Math.Round(random.NextDouble(), 5));
  180. Vector3 homelookat
  181. = new Vector3(
  182. (float)Math.Round(random.NextDouble(), 5),
  183. (float)Math.Round(random.NextDouble(), 5),
  184. (float)Math.Round(random.NextDouble(), 5));
  185. int created = random.Next();
  186. int lastlogin = random.Next();
  187. string userinvuri = RandomName();
  188. string userasseturi = RandomName();
  189. uint candomask = (uint) random.Next();
  190. uint wantdomask = (uint) random.Next();
  191. string abouttext = RandomName();
  192. string flabouttext = RandomName();
  193. UUID image = UUID.Random();
  194. UUID firstimage = UUID.Random();
  195. UserAgentData agent = NewAgent(id,UUID.Random());
  196. int userflags = random.Next();
  197. int godlevel = random.Next();
  198. string customtype = RandomName();
  199. UUID partner = UUID.Random();
  200. //HomeRegionX and HomeRegionY must only use 24 bits
  201. homeregx = ((homeregx << 8) >> 8);
  202. homeregy = ((homeregy << 8) >> 8);
  203. u.ID = id;
  204. u.WebLoginKey = webloginkey;
  205. u.HomeRegionID = homeregion;
  206. u.FirstName = fname;
  207. u.SurName = lname;
  208. u.Email = email;
  209. u.PasswordHash = passhash;
  210. u.PasswordSalt = passsalt;
  211. u.HomeRegionX = homeregx;
  212. u.HomeRegionY = homeregy;
  213. ulong homereg = u.HomeRegion;
  214. u.HomeLocation = homeloc;
  215. u.HomeLookAt = homelookat;
  216. u.Created = created;
  217. u.LastLogin = lastlogin;
  218. u.UserInventoryURI = userinvuri;
  219. u.UserAssetURI = userasseturi;
  220. u.CanDoMask = candomask;
  221. u.WantDoMask = wantdomask;
  222. u.AboutText = abouttext;
  223. u.FirstLifeAboutText = flabouttext;
  224. u.Image = image;
  225. u.FirstLifeImage = firstimage;
  226. u.CurrentAgent = agent;
  227. u.UserFlags = userflags;
  228. u.GodLevel = godlevel;
  229. u.CustomType = customtype;
  230. u.Partner = partner;
  231. db.AddNewUserProfile(u);
  232. UserProfileData u1a = db.GetUserByUUID(id);
  233. Assert.That(u1a,Is.Not.Null);
  234. Assert.That(id,Is.EqualTo(u1a.ID), "Assert.That(id,Is.EqualTo(u1a.ID))");
  235. Assert.That(homeregion,Is.EqualTo(u1a.HomeRegionID), "Assert.That(homeregion,Is.EqualTo(u1a.HomeRegionID))");
  236. Assert.That(webloginkey,Is.EqualTo(u1a.WebLoginKey), "Assert.That(webloginkey,Is.EqualTo(u1a.WebLoginKey))");
  237. Assert.That(fname,Is.EqualTo(u1a.FirstName), "Assert.That(fname,Is.EqualTo(u1a.FirstName))");
  238. Assert.That(lname,Is.EqualTo(u1a.SurName), "Assert.That(lname,Is.EqualTo(u1a.SurName))");
  239. Assert.That(email,Is.EqualTo(u1a.Email), "Assert.That(email,Is.EqualTo(u1a.Email))");
  240. Assert.That(passhash,Is.EqualTo(u1a.PasswordHash), "Assert.That(passhash,Is.EqualTo(u1a.PasswordHash))");
  241. Assert.That(passsalt,Is.EqualTo(u1a.PasswordSalt), "Assert.That(passsalt,Is.EqualTo(u1a.PasswordSalt))");
  242. Assert.That(homeregx,Is.EqualTo(u1a.HomeRegionX), "Assert.That(homeregx,Is.EqualTo(u1a.HomeRegionX))");
  243. Assert.That(homeregy,Is.EqualTo(u1a.HomeRegionY), "Assert.That(homeregy,Is.EqualTo(u1a.HomeRegionY))");
  244. Assert.That(homereg,Is.EqualTo(u1a.HomeRegion), "Assert.That(homereg,Is.EqualTo(u1a.HomeRegion))");
  245. Assert.That(homeloc,Is.EqualTo(u1a.HomeLocation), "Assert.That(homeloc,Is.EqualTo(u1a.HomeLocation))");
  246. Assert.That(homelookat,Is.EqualTo(u1a.HomeLookAt), "Assert.That(homelookat,Is.EqualTo(u1a.HomeLookAt))");
  247. Assert.That(created,Is.EqualTo(u1a.Created), "Assert.That(created,Is.EqualTo(u1a.Created))");
  248. Assert.That(lastlogin,Is.EqualTo(u1a.LastLogin), "Assert.That(lastlogin,Is.EqualTo(u1a.LastLogin))");
  249. Assert.That(userinvuri,Is.EqualTo(u1a.UserInventoryURI), "Assert.That(userinvuri,Is.EqualTo(u1a.UserInventoryURI))");
  250. Assert.That(userasseturi,Is.EqualTo(u1a.UserAssetURI), "Assert.That(userasseturi,Is.EqualTo(u1a.UserAssetURI))");
  251. Assert.That(candomask,Is.EqualTo(u1a.CanDoMask), "Assert.That(candomask,Is.EqualTo(u1a.CanDoMask))");
  252. Assert.That(wantdomask,Is.EqualTo(u1a.WantDoMask), "Assert.That(wantdomask,Is.EqualTo(u1a.WantDoMask))");
  253. Assert.That(abouttext,Is.EqualTo(u1a.AboutText), "Assert.That(abouttext,Is.EqualTo(u1a.AboutText))");
  254. Assert.That(flabouttext,Is.EqualTo(u1a.FirstLifeAboutText), "Assert.That(flabouttext,Is.EqualTo(u1a.FirstLifeAboutText))");
  255. Assert.That(image,Is.EqualTo(u1a.Image), "Assert.That(image,Is.EqualTo(u1a.Image))");
  256. Assert.That(firstimage,Is.EqualTo(u1a.FirstLifeImage), "Assert.That(firstimage,Is.EqualTo(u1a.FirstLifeImage))");
  257. Assert.That(u1a.CurrentAgent,Is.Null);
  258. Assert.That(userflags,Is.EqualTo(u1a.UserFlags), "Assert.That(userflags,Is.EqualTo(u1a.UserFlags))");
  259. Assert.That(godlevel,Is.EqualTo(u1a.GodLevel), "Assert.That(godlevel,Is.EqualTo(u1a.GodLevel))");
  260. Assert.That(customtype,Is.EqualTo(u1a.CustomType), "Assert.That(customtype,Is.EqualTo(u1a.CustomType))");
  261. Assert.That(partner,Is.EqualTo(u1a.Partner), "Assert.That(partner,Is.EqualTo(u1a.Partner))");
  262. }
  263. [Test]
  264. public void T016_UserUpdatePersistency()
  265. {
  266. UUID id = user5;
  267. UserProfileData u = db.GetUserByUUID(id);
  268. string fname = RandomName();
  269. string lname = RandomName();
  270. string email = RandomName();
  271. string passhash = RandomName();
  272. string passsalt = RandomName();
  273. UUID homeregionid = UUID.Random();
  274. UUID webloginkey = UUID.Random();
  275. uint homeregx = (uint) random.Next();
  276. uint homeregy = (uint) random.Next();
  277. Vector3 homeloc = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5));
  278. Vector3 homelookat = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5));
  279. int created = random.Next();
  280. int lastlogin = random.Next();
  281. string userinvuri = RandomName();
  282. string userasseturi = RandomName();
  283. uint candomask = (uint) random.Next();
  284. uint wantdomask = (uint) random.Next();
  285. string abouttext = RandomName();
  286. string flabouttext = RandomName();
  287. UUID image = UUID.Random();
  288. UUID firstimage = UUID.Random();
  289. UserAgentData agent = NewAgent(id,UUID.Random());
  290. int userflags = random.Next();
  291. int godlevel = random.Next();
  292. string customtype = RandomName();
  293. UUID partner = UUID.Random();
  294. //HomeRegionX and HomeRegionY must only use 24 bits
  295. homeregx = ((homeregx << 8) >> 8);
  296. homeregy = ((homeregy << 8) >> 8);
  297. u.WebLoginKey = webloginkey;
  298. u.HomeRegionID = homeregionid;
  299. u.FirstName = fname;
  300. u.SurName = lname;
  301. u.Email = email;
  302. u.PasswordHash = passhash;
  303. u.PasswordSalt = passsalt;
  304. u.HomeRegionX = homeregx;
  305. u.HomeRegionY = homeregy;
  306. ulong homereg = u.HomeRegion;
  307. u.HomeLocation = homeloc;
  308. u.HomeLookAt = homelookat;
  309. u.Created = created;
  310. u.LastLogin = lastlogin;
  311. u.UserInventoryURI = userinvuri;
  312. u.UserAssetURI = userasseturi;
  313. u.CanDoMask = candomask;
  314. u.WantDoMask = wantdomask;
  315. u.AboutText = abouttext;
  316. u.FirstLifeAboutText = flabouttext;
  317. u.Image = image;
  318. u.FirstLifeImage = firstimage;
  319. u.CurrentAgent = agent;
  320. u.UserFlags = userflags;
  321. u.GodLevel = godlevel;
  322. u.CustomType = customtype;
  323. u.Partner = partner;
  324. db.UpdateUserProfile(u);
  325. UserProfileData u1a = db.GetUserByUUID(id);
  326. Assert.That(u1a,Is.Not.Null);
  327. Assert.That(id,Is.EqualTo(u1a.ID), "Assert.That(id,Is.EqualTo(u1a.ID))");
  328. Assert.That(homeregionid,Is.EqualTo(u1a.HomeRegionID), "Assert.That(homeregionid,Is.EqualTo(u1a.HomeRegionID))");
  329. Assert.That(webloginkey,Is.EqualTo(u1a.WebLoginKey), "Assert.That(webloginkey,Is.EqualTo(u1a.WebLoginKey))");
  330. Assert.That(fname,Is.EqualTo(u1a.FirstName), "Assert.That(fname,Is.EqualTo(u1a.FirstName))");
  331. Assert.That(lname,Is.EqualTo(u1a.SurName), "Assert.That(lname,Is.EqualTo(u1a.SurName))");
  332. Assert.That(email,Is.EqualTo(u1a.Email), "Assert.That(email,Is.EqualTo(u1a.Email))");
  333. Assert.That(passhash,Is.EqualTo(u1a.PasswordHash), "Assert.That(passhash,Is.EqualTo(u1a.PasswordHash))");
  334. Assert.That(passsalt,Is.EqualTo(u1a.PasswordSalt), "Assert.That(passsalt,Is.EqualTo(u1a.PasswordSalt))");
  335. Assert.That(homereg,Is.EqualTo(u1a.HomeRegion), "Assert.That(homereg,Is.EqualTo(u1a.HomeRegion))");
  336. Assert.That(homeregx,Is.EqualTo(u1a.HomeRegionX), "Assert.That(homeregx,Is.EqualTo(u1a.HomeRegionX))");
  337. Assert.That(homeregy,Is.EqualTo(u1a.HomeRegionY), "Assert.That(homeregy,Is.EqualTo(u1a.HomeRegionY))");
  338. Assert.That(homereg,Is.EqualTo(u1a.HomeRegion), "Assert.That(homereg,Is.EqualTo(u1a.HomeRegion))");
  339. Assert.That(homeloc,Is.EqualTo(u1a.HomeLocation), "Assert.That(homeloc,Is.EqualTo(u1a.HomeLocation))");
  340. Assert.That(homelookat,Is.EqualTo(u1a.HomeLookAt), "Assert.That(homelookat,Is.EqualTo(u1a.HomeLookAt))");
  341. Assert.That(created,Is.EqualTo(u1a.Created), "Assert.That(created,Is.EqualTo(u1a.Created))");
  342. Assert.That(lastlogin,Is.EqualTo(u1a.LastLogin), "Assert.That(lastlogin,Is.EqualTo(u1a.LastLogin))");
  343. Assert.That(userasseturi,Is.EqualTo(u1a.UserAssetURI), "Assert.That(userasseturi,Is.EqualTo(u1a.UserAssetURI))");
  344. Assert.That(candomask,Is.EqualTo(u1a.CanDoMask), "Assert.That(candomask,Is.EqualTo(u1a.CanDoMask))");
  345. Assert.That(wantdomask,Is.EqualTo(u1a.WantDoMask), "Assert.That(wantdomask,Is.EqualTo(u1a.WantDoMask))");
  346. Assert.That(abouttext,Is.EqualTo(u1a.AboutText), "Assert.That(abouttext,Is.EqualTo(u1a.AboutText))");
  347. Assert.That(flabouttext,Is.EqualTo(u1a.FirstLifeAboutText), "Assert.That(flabouttext,Is.EqualTo(u1a.FirstLifeAboutText))");
  348. Assert.That(image,Is.EqualTo(u1a.Image), "Assert.That(image,Is.EqualTo(u1a.Image))");
  349. Assert.That(firstimage,Is.EqualTo(u1a.FirstLifeImage), "Assert.That(firstimage,Is.EqualTo(u1a.FirstLifeImage))");
  350. Assert.That(u1a.CurrentAgent,Is.Null);
  351. Assert.That(userflags,Is.EqualTo(u1a.UserFlags), "Assert.That(userflags,Is.EqualTo(u1a.UserFlags))");
  352. Assert.That(godlevel,Is.EqualTo(u1a.GodLevel), "Assert.That(godlevel,Is.EqualTo(u1a.GodLevel))");
  353. Assert.That(customtype,Is.EqualTo(u1a.CustomType), "Assert.That(customtype,Is.EqualTo(u1a.CustomType))");
  354. Assert.That(partner,Is.EqualTo(u1a.Partner), "Assert.That(partner,Is.EqualTo(u1a.Partner))");
  355. }
  356. [Test]
  357. public void T017_UserUpdateRandomPersistency()
  358. {
  359. UUID id = user5;
  360. UserProfileData u = db.GetUserByUUID(id);
  361. new PropertyScrambler<UserProfileData>().DontScramble(x=>x.ID).Scramble(u);
  362. db.UpdateUserProfile(u);
  363. UserProfileData u1a = db.GetUserByUUID(id);
  364. Assert.That(u1a, Constraints.PropertyCompareConstraint(u)
  365. .IgnoreProperty(x=>x.HomeRegionX)
  366. .IgnoreProperty(x=>x.HomeRegionY)
  367. );
  368. }
  369. [Test]
  370. public void T020_CreateAgent()
  371. {
  372. UserAgentData a1 = NewAgent(user1,agent1);
  373. UserAgentData a2 = NewAgent(user2,agent2);
  374. UserAgentData a3 = NewAgent(user3,agent3);
  375. db.AddNewUserAgent(a1);
  376. db.AddNewUserAgent(a2);
  377. db.AddNewUserAgent(a3);
  378. UserAgentData a1a = db.GetAgentByUUID(user1);
  379. UserAgentData a2a = db.GetAgentByUUID(user2);
  380. UserAgentData a3a = db.GetAgentByUUID(user3);
  381. Assert.That(agent1,Is.EqualTo(a1a.SessionID), "Assert.That(agent1,Is.EqualTo(a1a.SessionID))");
  382. Assert.That(user1,Is.EqualTo(a1a.ProfileID), "Assert.That(user1,Is.EqualTo(a1a.ProfileID))");
  383. Assert.That(agent2,Is.EqualTo(a2a.SessionID), "Assert.That(agent2,Is.EqualTo(a2a.SessionID))");
  384. Assert.That(user2,Is.EqualTo(a2a.ProfileID), "Assert.That(user2,Is.EqualTo(a2a.ProfileID))");
  385. Assert.That(agent3,Is.EqualTo(a3a.SessionID), "Assert.That(agent3,Is.EqualTo(a3a.SessionID))");
  386. Assert.That(user3,Is.EqualTo(a3a.ProfileID), "Assert.That(user3,Is.EqualTo(a3a.ProfileID))");
  387. }
  388. [Test]
  389. public void T021_FetchAgentByName()
  390. {
  391. String name3 = fname3 + " " + lname3;
  392. UserAgentData a2 = db.GetAgentByName(fname2,lname2);
  393. UserAgentData a3 = db.GetAgentByName(name3);
  394. Assert.That(user2,Is.EqualTo(a2.ProfileID), "Assert.That(user2,Is.EqualTo(a2.ProfileID))");
  395. Assert.That(user3,Is.EqualTo(a3.ProfileID), "Assert.That(user3,Is.EqualTo(a3.ProfileID))");
  396. }
  397. [Test]
  398. public void T022_ExceptionalCases()
  399. {
  400. UserAgentData a0 = NewAgent(user4,zero);
  401. UserAgentData a4 = NewAgent(zero,agent4);
  402. db.AddNewUserAgent(a0);
  403. db.AddNewUserAgent(a4);
  404. Assert.That(db.GetAgentByUUID(user4),Is.Null);
  405. Assert.That(db.GetAgentByUUID(zero),Is.Null);
  406. }
  407. [Test]
  408. public void T023_AgentPersistency()
  409. {
  410. UUID user = user4;
  411. UUID agent = agent4;
  412. UUID secureagent = UUID.Random();
  413. string agentip = RandomName();
  414. uint agentport = (uint)random.Next();
  415. bool agentonline = (random.NextDouble() > 0.5);
  416. int logintime = random.Next();
  417. int logouttime = random.Next();
  418. UUID regionid = UUID.Random();
  419. ulong regionhandle = (ulong) random.Next();
  420. Vector3 currentpos = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5));
  421. Vector3 currentlookat = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5));
  422. UUID orgregionid = UUID.Random();
  423. UserAgentData a = new UserAgentData();
  424. a.ProfileID = user;
  425. a.SessionID = agent;
  426. a.SecureSessionID = secureagent;
  427. a.AgentIP = agentip;
  428. a.AgentPort = agentport;
  429. a.AgentOnline = agentonline;
  430. a.LoginTime = logintime;
  431. a.LogoutTime = logouttime;
  432. a.Region = regionid;
  433. a.Handle = regionhandle;
  434. a.Position = currentpos;
  435. a.LookAt = currentlookat;
  436. a.InitialRegion = orgregionid;
  437. db.AddNewUserAgent(a);
  438. UserAgentData a1 = db.GetAgentByUUID(user4);
  439. Assert.That(user,Is.EqualTo(a1.ProfileID), "Assert.That(user,Is.EqualTo(a1.ProfileID))");
  440. Assert.That(agent,Is.EqualTo(a1.SessionID), "Assert.That(agent,Is.EqualTo(a1.SessionID))");
  441. Assert.That(secureagent,Is.EqualTo(a1.SecureSessionID), "Assert.That(secureagent,Is.EqualTo(a1.SecureSessionID))");
  442. Assert.That(agentip,Is.EqualTo(a1.AgentIP), "Assert.That(agentip,Is.EqualTo(a1.AgentIP))");
  443. Assert.That(agentport,Is.EqualTo(a1.AgentPort), "Assert.That(agentport,Is.EqualTo(a1.AgentPort))");
  444. Assert.That(agentonline,Is.EqualTo(a1.AgentOnline), "Assert.That(agentonline,Is.EqualTo(a1.AgentOnline))");
  445. Assert.That(logintime,Is.EqualTo(a1.LoginTime), "Assert.That(logintime,Is.EqualTo(a1.LoginTime))");
  446. Assert.That(logouttime,Is.EqualTo(a1.LogoutTime), "Assert.That(logouttime,Is.EqualTo(a1.LogoutTime))");
  447. Assert.That(regionid,Is.EqualTo(a1.Region), "Assert.That(regionid,Is.EqualTo(a1.Region))");
  448. Assert.That(regionhandle,Is.EqualTo(a1.Handle), "Assert.That(regionhandle,Is.EqualTo(a1.Handle))");
  449. Assert.That(currentpos,Is.EqualTo(a1.Position), "Assert.That(currentpos,Is.EqualTo(a1.Position))");
  450. Assert.That(currentlookat,Is.EqualTo(a1.LookAt), "Assert.That(currentlookat,Is.EqualTo(a1.LookAt))");
  451. }
  452. [Test]
  453. public void T030_CreateFriendList()
  454. {
  455. Dictionary<UUID, uint> perms = new Dictionary<UUID,uint>();
  456. Dictionary<UUID, int> friends = new Dictionary<UUID,int>();
  457. uint temp;
  458. int tempu1, tempu2;
  459. db.AddNewUserFriend(user1,user2, 1);
  460. db.AddNewUserFriend(user1,user3, 2);
  461. db.AddNewUserFriend(user1,user2, 4);
  462. List<FriendListItem> fl1 = db.GetUserFriendList(user1);
  463. Assert.That(fl1.Count,Is.EqualTo(2), "Assert.That(fl1.Count,Is.EqualTo(2))");
  464. perms.Add(user2,1);
  465. perms.Add(user3,2);
  466. for (int i = 0; i < fl1.Count; i++)
  467. {
  468. Assert.That(user1,Is.EqualTo(fl1[i].FriendListOwner), "Assert.That(user1,Is.EqualTo(fl1[i].FriendListOwner))");
  469. friends.Add(fl1[i].Friend,1);
  470. temp = perms[fl1[i].Friend];
  471. Assert.That(temp,Is.EqualTo(fl1[i].FriendPerms), "Assert.That(temp,Is.EqualTo(fl1[i].FriendPerms))");
  472. }
  473. tempu1 = friends[user2];
  474. tempu2 = friends[user3];
  475. Assert.That(1,Is.EqualTo(tempu1) & Is.EqualTo(tempu2), "Assert.That(1,Is.EqualTo(tempu1) & Is.EqualTo(tempu2))");
  476. }
  477. [Test]
  478. public void T031_RemoveUserFriend()
  479. // user1 has 2 friends, user2 and user3.
  480. {
  481. List<FriendListItem> fl1 = db.GetUserFriendList(user1);
  482. List<FriendListItem> fl2 = db.GetUserFriendList(user2);
  483. Assert.That(fl1.Count,Is.EqualTo(2), "Assert.That(fl1.Count,Is.EqualTo(2))");
  484. Assert.That(fl1[0].Friend,Is.EqualTo(user2) | Is.EqualTo(user3), "Assert.That(fl1[0].Friend,Is.EqualTo(user2) | Is.EqualTo(user3))");
  485. Assert.That(fl2[0].Friend,Is.EqualTo(user1), "Assert.That(fl2[0].Friend,Is.EqualTo(user1))");
  486. db.RemoveUserFriend(user2, user1);
  487. fl1 = db.GetUserFriendList(user1);
  488. fl2 = db.GetUserFriendList(user2);
  489. Assert.That(fl1.Count,Is.EqualTo(1), "Assert.That(fl1.Count,Is.EqualTo(1))");
  490. Assert.That(fl1[0].Friend, Is.EqualTo(user3), "Assert.That(fl1[0].Friend, Is.EqualTo(user3))");
  491. Assert.That(fl2, Is.Empty);
  492. }
  493. [Test]
  494. public void T032_UpdateFriendPerms()
  495. // user1 has 1 friend, user3, who has permission 2 in T030.
  496. {
  497. List<FriendListItem> fl1 = db.GetUserFriendList(user1);
  498. Assert.That(fl1[0].FriendPerms,Is.EqualTo(2), "Assert.That(fl1[0].FriendPerms,Is.EqualTo(2))");
  499. db.UpdateUserFriendPerms(user1, user3, 4);
  500. fl1 = db.GetUserFriendList(user1);
  501. Assert.That(fl1[0].FriendPerms,Is.EqualTo(4), "Assert.That(fl1[0].FriendPerms,Is.EqualTo(4))");
  502. }
  503. [Test]
  504. public void T040_UserAppearance()
  505. {
  506. AvatarAppearance appear = new AvatarAppearance();
  507. appear.Owner = user1;
  508. db.UpdateUserAppearance(user1, appear);
  509. AvatarAppearance user1app = db.GetUserAppearance(user1);
  510. Assert.That(user1,Is.EqualTo(user1app.Owner), "Assert.That(user1,Is.EqualTo(user1app.Owner))");
  511. }
  512. [Test]
  513. public void T041_UserAppearancePersistency()
  514. {
  515. AvatarAppearance appear = new AvatarAppearance();
  516. UUID owner = UUID.Random();
  517. int serial = random.Next();
  518. byte[] visualp = new byte[218];
  519. random.NextBytes(visualp);
  520. UUID bodyitem = UUID.Random();
  521. UUID bodyasset = UUID.Random();
  522. UUID skinitem = UUID.Random();
  523. UUID skinasset = UUID.Random();
  524. UUID hairitem = UUID.Random();
  525. UUID hairasset = UUID.Random();
  526. UUID eyesitem = UUID.Random();
  527. UUID eyesasset = UUID.Random();
  528. UUID shirtitem = UUID.Random();
  529. UUID shirtasset = UUID.Random();
  530. UUID pantsitem = UUID.Random();
  531. UUID pantsasset = UUID.Random();
  532. UUID shoesitem = UUID.Random();
  533. UUID shoesasset = UUID.Random();
  534. UUID socksitem = UUID.Random();
  535. UUID socksasset = UUID.Random();
  536. UUID jacketitem = UUID.Random();
  537. UUID jacketasset = UUID.Random();
  538. UUID glovesitem = UUID.Random();
  539. UUID glovesasset = UUID.Random();
  540. UUID ushirtitem = UUID.Random();
  541. UUID ushirtasset = UUID.Random();
  542. UUID upantsitem = UUID.Random();
  543. UUID upantsasset = UUID.Random();
  544. UUID skirtitem = UUID.Random();
  545. UUID skirtasset = UUID.Random();
  546. Primitive.TextureEntry texture = AvatarAppearance.GetDefaultTexture();
  547. float avatarheight = (float) (Math.Round(random.NextDouble(),5));
  548. appear.Owner = owner;
  549. appear.Serial = serial;
  550. appear.VisualParams = visualp;
  551. appear.BodyItem = bodyitem;
  552. appear.BodyAsset = bodyasset;
  553. appear.SkinItem = skinitem;
  554. appear.SkinAsset = skinasset;
  555. appear.HairItem = hairitem;
  556. appear.HairAsset = hairasset;
  557. appear.EyesItem = eyesitem;
  558. appear.EyesAsset = eyesasset;
  559. appear.ShirtItem = shirtitem;
  560. appear.ShirtAsset = shirtasset;
  561. appear.PantsItem = pantsitem;
  562. appear.PantsAsset = pantsasset;
  563. appear.ShoesItem = shoesitem;
  564. appear.ShoesAsset = shoesasset;
  565. appear.SocksItem = socksitem;
  566. appear.SocksAsset = socksasset;
  567. appear.JacketItem = jacketitem;
  568. appear.JacketAsset = jacketasset;
  569. appear.GlovesItem = glovesitem;
  570. appear.GlovesAsset = glovesasset;
  571. appear.UnderShirtItem = ushirtitem;
  572. appear.UnderShirtAsset = ushirtasset;
  573. appear.UnderPantsItem = upantsitem;
  574. appear.UnderPantsAsset = upantsasset;
  575. appear.SkirtItem = skirtitem;
  576. appear.SkirtAsset = skirtasset;
  577. appear.Texture = texture;
  578. appear.AvatarHeight = avatarheight;
  579. db.UpdateUserAppearance(owner, appear);
  580. AvatarAppearance app = db.GetUserAppearance(owner);
  581. Assert.That(owner,Is.EqualTo(app.Owner), "Assert.That(owner,Is.EqualTo(app.Owner))");
  582. Assert.That(serial,Is.EqualTo(app.Serial), "Assert.That(serial,Is.EqualTo(app.Serial))");
  583. Assert.That(visualp,Is.EqualTo(app.VisualParams), "Assert.That(visualp,Is.EqualTo(app.VisualParams))");
  584. Assert.That(bodyitem,Is.EqualTo(app.BodyItem), "Assert.That(bodyitem,Is.EqualTo(app.BodyItem))");
  585. Assert.That(bodyasset,Is.EqualTo(app.BodyAsset), "Assert.That(bodyasset,Is.EqualTo(app.BodyAsset))");
  586. Assert.That(skinitem,Is.EqualTo(app.SkinItem), "Assert.That(skinitem,Is.EqualTo(app.SkinItem))");
  587. Assert.That(skinasset,Is.EqualTo(app.SkinAsset), "Assert.That(skinasset,Is.EqualTo(app.SkinAsset))");
  588. Assert.That(hairitem,Is.EqualTo(app.HairItem), "Assert.That(hairitem,Is.EqualTo(app.HairItem))");
  589. Assert.That(hairasset,Is.EqualTo(app.HairAsset), "Assert.That(hairasset,Is.EqualTo(app.HairAsset))");
  590. Assert.That(eyesitem,Is.EqualTo(app.EyesItem), "Assert.That(eyesitem,Is.EqualTo(app.EyesItem))");
  591. Assert.That(eyesasset,Is.EqualTo(app.EyesAsset), "Assert.That(eyesasset,Is.EqualTo(app.EyesAsset))");
  592. Assert.That(shirtitem,Is.EqualTo(app.ShirtItem), "Assert.That(shirtitem,Is.EqualTo(app.ShirtItem))");
  593. Assert.That(shirtasset,Is.EqualTo(app.ShirtAsset), "Assert.That(shirtasset,Is.EqualTo(app.ShirtAsset))");
  594. Assert.That(pantsitem,Is.EqualTo(app.PantsItem), "Assert.That(pantsitem,Is.EqualTo(app.PantsItem))");
  595. Assert.That(pantsasset,Is.EqualTo(app.PantsAsset), "Assert.That(pantsasset,Is.EqualTo(app.PantsAsset))");
  596. Assert.That(shoesitem,Is.EqualTo(app.ShoesItem), "Assert.That(shoesitem,Is.EqualTo(app.ShoesItem))");
  597. Assert.That(shoesasset,Is.EqualTo(app.ShoesAsset), "Assert.That(shoesasset,Is.EqualTo(app.ShoesAsset))");
  598. Assert.That(socksitem,Is.EqualTo(app.SocksItem), "Assert.That(socksitem,Is.EqualTo(app.SocksItem))");
  599. Assert.That(socksasset,Is.EqualTo(app.SocksAsset), "Assert.That(socksasset,Is.EqualTo(app.SocksAsset))");
  600. Assert.That(jacketitem,Is.EqualTo(app.JacketItem), "Assert.That(jacketitem,Is.EqualTo(app.JacketItem))");
  601. Assert.That(jacketasset,Is.EqualTo(app.JacketAsset), "Assert.That(jacketasset,Is.EqualTo(app.JacketAsset))");
  602. Assert.That(glovesitem,Is.EqualTo(app.GlovesItem), "Assert.That(glovesitem,Is.EqualTo(app.GlovesItem))");
  603. Assert.That(glovesasset,Is.EqualTo(app.GlovesAsset), "Assert.That(glovesasset,Is.EqualTo(app.GlovesAsset))");
  604. Assert.That(ushirtitem,Is.EqualTo(app.UnderShirtItem), "Assert.That(ushirtitem,Is.EqualTo(app.UnderShirtItem))");
  605. Assert.That(ushirtasset,Is.EqualTo(app.UnderShirtAsset), "Assert.That(ushirtasset,Is.EqualTo(app.UnderShirtAsset))");
  606. Assert.That(upantsitem,Is.EqualTo(app.UnderPantsItem), "Assert.That(upantsitem,Is.EqualTo(app.UnderPantsItem))");
  607. Assert.That(upantsasset,Is.EqualTo(app.UnderPantsAsset), "Assert.That(upantsasset,Is.EqualTo(app.UnderPantsAsset))");
  608. Assert.That(skirtitem,Is.EqualTo(app.SkirtItem), "Assert.That(skirtitem,Is.EqualTo(app.SkirtItem))");
  609. Assert.That(skirtasset,Is.EqualTo(app.SkirtAsset), "Assert.That(skirtasset,Is.EqualTo(app.SkirtAsset))");
  610. Assert.That(texture.ToString(),Is.EqualTo(app.Texture.ToString()), "Assert.That(texture.ToString(),Is.EqualTo(app.Texture.ToString()))");
  611. Assert.That(avatarheight,Is.EqualTo(app.AvatarHeight), "Assert.That(avatarheight,Is.EqualTo(app.AvatarHeight))");
  612. }
  613. [Test]
  614. public void T999_StillNull()
  615. {
  616. Assert.That(db.GetUserByUUID(zero), Is.Null);
  617. Assert.That(db.GetAgentByUUID(zero), Is.Null);
  618. }
  619. public UserProfileData NewUser(UUID id,string fname,string lname)
  620. {
  621. UserProfileData u = new UserProfileData();
  622. u.ID = id;
  623. u.FirstName = fname;
  624. u.SurName = lname;
  625. u.PasswordHash = "NOTAHASH";
  626. u.PasswordSalt = "NOTSALT";
  627. // MUST specify at least these 5 parameters or an exception is raised
  628. return u;
  629. }
  630. public UserAgentData NewAgent(UUID user_profile, UUID agent)
  631. {
  632. UserAgentData a = new UserAgentData();
  633. a.ProfileID = user_profile;
  634. a.SessionID = agent;
  635. a.SecureSessionID = UUID.Random();
  636. a.AgentIP = RandomName();
  637. return a;
  638. }
  639. public static string RandomName()
  640. {
  641. StringBuilder name = new StringBuilder();
  642. int size = random.Next(5,12);
  643. char ch ;
  644. for (int i=0; i<size; i++)
  645. {
  646. ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ;
  647. name.Append(ch);
  648. }
  649. return name.ToString();
  650. }
  651. }
  652. }