BasicUserTest.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  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);
  157. db.AddNewUserProfile(u4);
  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. // RootInventoryFolderID is not tested because it is saved in SQLite,
  250. // but not in MySQL
  251. Assert.That(userinvuri,Is.EqualTo(u1a.UserInventoryURI), "Assert.That(userinvuri,Is.EqualTo(u1a.UserInventoryURI))");
  252. Assert.That(userasseturi,Is.EqualTo(u1a.UserAssetURI), "Assert.That(userasseturi,Is.EqualTo(u1a.UserAssetURI))");
  253. Assert.That(candomask,Is.EqualTo(u1a.CanDoMask), "Assert.That(candomask,Is.EqualTo(u1a.CanDoMask))");
  254. Assert.That(wantdomask,Is.EqualTo(u1a.WantDoMask), "Assert.That(wantdomask,Is.EqualTo(u1a.WantDoMask))");
  255. Assert.That(abouttext,Is.EqualTo(u1a.AboutText), "Assert.That(abouttext,Is.EqualTo(u1a.AboutText))");
  256. Assert.That(flabouttext,Is.EqualTo(u1a.FirstLifeAboutText), "Assert.That(flabouttext,Is.EqualTo(u1a.FirstLifeAboutText))");
  257. Assert.That(image,Is.EqualTo(u1a.Image), "Assert.That(image,Is.EqualTo(u1a.Image))");
  258. Assert.That(firstimage,Is.EqualTo(u1a.FirstLifeImage), "Assert.That(firstimage,Is.EqualTo(u1a.FirstLifeImage))");
  259. Assert.That(u1a.CurrentAgent,Is.Null);
  260. Assert.That(userflags,Is.EqualTo(u1a.UserFlags), "Assert.That(userflags,Is.EqualTo(u1a.UserFlags))");
  261. Assert.That(godlevel,Is.EqualTo(u1a.GodLevel), "Assert.That(godlevel,Is.EqualTo(u1a.GodLevel))");
  262. Assert.That(customtype,Is.EqualTo(u1a.CustomType), "Assert.That(customtype,Is.EqualTo(u1a.CustomType))");
  263. Assert.That(partner,Is.EqualTo(u1a.Partner), "Assert.That(partner,Is.EqualTo(u1a.Partner))");
  264. }
  265. [Test]
  266. public void T016_UserUpdatePersistency()
  267. {
  268. UUID id = user5;
  269. UserProfileData u = db.GetUserByUUID(id);
  270. string fname = RandomName();
  271. string lname = RandomName();
  272. string email = RandomName();
  273. string passhash = RandomName();
  274. string passsalt = RandomName();
  275. UUID homeregionid = UUID.Random();
  276. UUID webloginkey = UUID.Random();
  277. uint homeregx = (uint) random.Next();
  278. uint homeregy = (uint) random.Next();
  279. Vector3 homeloc = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5));
  280. Vector3 homelookat = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5));
  281. int created = random.Next();
  282. int lastlogin = random.Next();
  283. string userinvuri = RandomName();
  284. string userasseturi = RandomName();
  285. uint candomask = (uint) random.Next();
  286. uint wantdomask = (uint) random.Next();
  287. string abouttext = RandomName();
  288. string flabouttext = RandomName();
  289. UUID image = UUID.Random();
  290. UUID firstimage = UUID.Random();
  291. UserAgentData agent = NewAgent(id,UUID.Random());
  292. int userflags = random.Next();
  293. int godlevel = random.Next();
  294. string customtype = RandomName();
  295. UUID partner = UUID.Random();
  296. //HomeRegionX and HomeRegionY must only use 24 bits
  297. homeregx = ((homeregx << 8) >> 8);
  298. homeregy = ((homeregy << 8) >> 8);
  299. u.WebLoginKey = webloginkey;
  300. u.HomeRegionID = homeregionid;
  301. u.FirstName = fname;
  302. u.SurName = lname;
  303. u.Email = email;
  304. u.PasswordHash = passhash;
  305. u.PasswordSalt = passsalt;
  306. u.HomeRegionX = homeregx;
  307. u.HomeRegionY = homeregy;
  308. ulong homereg = u.HomeRegion;
  309. u.HomeLocation = homeloc;
  310. u.HomeLookAt = homelookat;
  311. u.Created = created;
  312. u.LastLogin = lastlogin;
  313. u.UserInventoryURI = userinvuri;
  314. u.UserAssetURI = userasseturi;
  315. u.CanDoMask = candomask;
  316. u.WantDoMask = wantdomask;
  317. u.AboutText = abouttext;
  318. u.FirstLifeAboutText = flabouttext;
  319. u.Image = image;
  320. u.FirstLifeImage = firstimage;
  321. u.CurrentAgent = agent;
  322. u.UserFlags = userflags;
  323. u.GodLevel = godlevel;
  324. u.CustomType = customtype;
  325. u.Partner = partner;
  326. db.UpdateUserProfile(u);
  327. UserProfileData u1a = db.GetUserByUUID(id);
  328. Assert.That(u1a,Is.Not.Null);
  329. Assert.That(id,Is.EqualTo(u1a.ID), "Assert.That(id,Is.EqualTo(u1a.ID))");
  330. Assert.That(homeregionid,Is.EqualTo(u1a.HomeRegionID), "Assert.That(homeregionid,Is.EqualTo(u1a.HomeRegionID))");
  331. Assert.That(webloginkey,Is.EqualTo(u1a.WebLoginKey), "Assert.That(webloginkey,Is.EqualTo(u1a.WebLoginKey))");
  332. Assert.That(fname,Is.EqualTo(u1a.FirstName), "Assert.That(fname,Is.EqualTo(u1a.FirstName))");
  333. Assert.That(lname,Is.EqualTo(u1a.SurName), "Assert.That(lname,Is.EqualTo(u1a.SurName))");
  334. Assert.That(email,Is.EqualTo(u1a.Email), "Assert.That(email,Is.EqualTo(u1a.Email))");
  335. Assert.That(passhash,Is.EqualTo(u1a.PasswordHash), "Assert.That(passhash,Is.EqualTo(u1a.PasswordHash))");
  336. Assert.That(passsalt,Is.EqualTo(u1a.PasswordSalt), "Assert.That(passsalt,Is.EqualTo(u1a.PasswordSalt))");
  337. Assert.That(homereg,Is.EqualTo(u1a.HomeRegion), "Assert.That(homereg,Is.EqualTo(u1a.HomeRegion))");
  338. Assert.That(homeregx,Is.EqualTo(u1a.HomeRegionX), "Assert.That(homeregx,Is.EqualTo(u1a.HomeRegionX))");
  339. Assert.That(homeregy,Is.EqualTo(u1a.HomeRegionY), "Assert.That(homeregy,Is.EqualTo(u1a.HomeRegionY))");
  340. Assert.That(homereg,Is.EqualTo(u1a.HomeRegion), "Assert.That(homereg,Is.EqualTo(u1a.HomeRegion))");
  341. Assert.That(homeloc,Is.EqualTo(u1a.HomeLocation), "Assert.That(homeloc,Is.EqualTo(u1a.HomeLocation))");
  342. Assert.That(homelookat,Is.EqualTo(u1a.HomeLookAt), "Assert.That(homelookat,Is.EqualTo(u1a.HomeLookAt))");
  343. Assert.That(created,Is.EqualTo(u1a.Created), "Assert.That(created,Is.EqualTo(u1a.Created))");
  344. Assert.That(lastlogin,Is.EqualTo(u1a.LastLogin), "Assert.That(lastlogin,Is.EqualTo(u1a.LastLogin))");
  345. // RootInventoryFolderID is not tested because it is saved in SQLite,
  346. // but not in MySQL
  347. Assert.That(userasseturi,Is.EqualTo(u1a.UserAssetURI), "Assert.That(userasseturi,Is.EqualTo(u1a.UserAssetURI))");
  348. Assert.That(candomask,Is.EqualTo(u1a.CanDoMask), "Assert.That(candomask,Is.EqualTo(u1a.CanDoMask))");
  349. Assert.That(wantdomask,Is.EqualTo(u1a.WantDoMask), "Assert.That(wantdomask,Is.EqualTo(u1a.WantDoMask))");
  350. Assert.That(abouttext,Is.EqualTo(u1a.AboutText), "Assert.That(abouttext,Is.EqualTo(u1a.AboutText))");
  351. Assert.That(flabouttext,Is.EqualTo(u1a.FirstLifeAboutText), "Assert.That(flabouttext,Is.EqualTo(u1a.FirstLifeAboutText))");
  352. Assert.That(image,Is.EqualTo(u1a.Image), "Assert.That(image,Is.EqualTo(u1a.Image))");
  353. Assert.That(firstimage,Is.EqualTo(u1a.FirstLifeImage), "Assert.That(firstimage,Is.EqualTo(u1a.FirstLifeImage))");
  354. Assert.That(u1a.CurrentAgent,Is.Null);
  355. Assert.That(userflags,Is.EqualTo(u1a.UserFlags), "Assert.That(userflags,Is.EqualTo(u1a.UserFlags))");
  356. Assert.That(godlevel,Is.EqualTo(u1a.GodLevel), "Assert.That(godlevel,Is.EqualTo(u1a.GodLevel))");
  357. Assert.That(customtype,Is.EqualTo(u1a.CustomType), "Assert.That(customtype,Is.EqualTo(u1a.CustomType))");
  358. Assert.That(partner,Is.EqualTo(u1a.Partner), "Assert.That(partner,Is.EqualTo(u1a.Partner))");
  359. }
  360. [Test]
  361. public void T017_UserUpdateRandomPersistency()
  362. {
  363. UUID id = user5;
  364. UserProfileData u = db.GetUserByUUID(id);
  365. new PropertyScrambler<UserProfileData>().DontScramble(x=>x.ID).Scramble(u);
  366. db.UpdateUserProfile(u);
  367. UserProfileData u1a = db.GetUserByUUID(id);
  368. Assert.That(u1a, Constraints.PropertyCompareConstraint(u)
  369. .IgnoreProperty(x=>x.HomeRegionX)
  370. .IgnoreProperty(x=>x.HomeRegionY)
  371. .IgnoreProperty(x=>x.RootInventoryFolderID)
  372. );
  373. }
  374. [Test]
  375. public void T020_CreateAgent()
  376. {
  377. UserAgentData a1 = NewAgent(user1,agent1);
  378. UserAgentData a2 = NewAgent(user2,agent2);
  379. UserAgentData a3 = NewAgent(user3,agent3);
  380. db.AddNewUserAgent(a1);
  381. db.AddNewUserAgent(a2);
  382. db.AddNewUserAgent(a3);
  383. UserAgentData a1a = db.GetAgentByUUID(user1);
  384. UserAgentData a2a = db.GetAgentByUUID(user2);
  385. UserAgentData a3a = db.GetAgentByUUID(user3);
  386. Assert.That(agent1,Is.EqualTo(a1a.SessionID), "Assert.That(agent1,Is.EqualTo(a1a.SessionID))");
  387. Assert.That(user1,Is.EqualTo(a1a.ProfileID), "Assert.That(user1,Is.EqualTo(a1a.ProfileID))");
  388. Assert.That(agent2,Is.EqualTo(a2a.SessionID), "Assert.That(agent2,Is.EqualTo(a2a.SessionID))");
  389. Assert.That(user2,Is.EqualTo(a2a.ProfileID), "Assert.That(user2,Is.EqualTo(a2a.ProfileID))");
  390. Assert.That(agent3,Is.EqualTo(a3a.SessionID), "Assert.That(agent3,Is.EqualTo(a3a.SessionID))");
  391. Assert.That(user3,Is.EqualTo(a3a.ProfileID), "Assert.That(user3,Is.EqualTo(a3a.ProfileID))");
  392. }
  393. [Test]
  394. public void T021_FetchAgentByName()
  395. {
  396. String name3 = fname3 + " " + lname3;
  397. UserAgentData a2 = db.GetAgentByName(fname2,lname2);
  398. UserAgentData a3 = db.GetAgentByName(name3);
  399. Assert.That(user2,Is.EqualTo(a2.ProfileID), "Assert.That(user2,Is.EqualTo(a2.ProfileID))");
  400. Assert.That(user3,Is.EqualTo(a3.ProfileID), "Assert.That(user3,Is.EqualTo(a3.ProfileID))");
  401. }
  402. [Test]
  403. public void T022_ExceptionalCases()
  404. {
  405. UserAgentData a0 = NewAgent(user4,zero);
  406. UserAgentData a4 = NewAgent(zero,agent4);
  407. db.AddNewUserAgent(a0);
  408. db.AddNewUserAgent(a4);
  409. Assert.That(db.GetAgentByUUID(user4),Is.Null);
  410. Assert.That(db.GetAgentByUUID(zero),Is.Null);
  411. }
  412. [Test]
  413. public void T023_AgentPersistency()
  414. {
  415. UUID user = user4;
  416. UUID agent = agent4;
  417. UUID secureagent = UUID.Random();
  418. string agentip = RandomName();
  419. uint agentport = (uint)random.Next();
  420. bool agentonline = (random.NextDouble() > 0.5);
  421. int logintime = random.Next();
  422. int logouttime = random.Next();
  423. UUID regionid = UUID.Random();
  424. ulong regionhandle = (ulong) random.Next();
  425. Vector3 currentpos = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5));
  426. Vector3 currentlookat = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5));
  427. UUID orgregionid = UUID.Random();
  428. UserAgentData a = new UserAgentData();
  429. a.ProfileID = user;
  430. a.SessionID = agent;
  431. a.SecureSessionID = secureagent;
  432. a.AgentIP = agentip;
  433. a.AgentPort = agentport;
  434. a.AgentOnline = agentonline;
  435. a.LoginTime = logintime;
  436. a.LogoutTime = logouttime;
  437. a.Region = regionid;
  438. a.Handle = regionhandle;
  439. a.Position = currentpos;
  440. a.LookAt = currentlookat;
  441. a.InitialRegion = orgregionid;
  442. db.AddNewUserAgent(a);
  443. UserAgentData a1 = db.GetAgentByUUID(user4);
  444. Assert.That(user,Is.EqualTo(a1.ProfileID), "Assert.That(user,Is.EqualTo(a1.ProfileID))");
  445. Assert.That(agent,Is.EqualTo(a1.SessionID), "Assert.That(agent,Is.EqualTo(a1.SessionID))");
  446. Assert.That(secureagent,Is.EqualTo(a1.SecureSessionID), "Assert.That(secureagent,Is.EqualTo(a1.SecureSessionID))");
  447. Assert.That(agentip,Is.EqualTo(a1.AgentIP), "Assert.That(agentip,Is.EqualTo(a1.AgentIP))");
  448. Assert.That(agentport,Is.EqualTo(a1.AgentPort), "Assert.That(agentport,Is.EqualTo(a1.AgentPort))");
  449. Assert.That(agentonline,Is.EqualTo(a1.AgentOnline), "Assert.That(agentonline,Is.EqualTo(a1.AgentOnline))");
  450. Assert.That(logintime,Is.EqualTo(a1.LoginTime), "Assert.That(logintime,Is.EqualTo(a1.LoginTime))");
  451. Assert.That(logouttime,Is.EqualTo(a1.LogoutTime), "Assert.That(logouttime,Is.EqualTo(a1.LogoutTime))");
  452. Assert.That(regionid,Is.EqualTo(a1.Region), "Assert.That(regionid,Is.EqualTo(a1.Region))");
  453. Assert.That(regionhandle,Is.EqualTo(a1.Handle), "Assert.That(regionhandle,Is.EqualTo(a1.Handle))");
  454. Assert.That(currentpos,Is.EqualTo(a1.Position), "Assert.That(currentpos,Is.EqualTo(a1.Position))");
  455. Assert.That(currentlookat,Is.EqualTo(a1.LookAt), "Assert.That(currentlookat,Is.EqualTo(a1.LookAt))");
  456. }
  457. [Test]
  458. public void T030_CreateFriendList()
  459. {
  460. Dictionary<UUID, uint> perms = new Dictionary<UUID,uint>();
  461. Dictionary<UUID, int> friends = new Dictionary<UUID,int>();
  462. uint temp;
  463. int tempu1, tempu2;
  464. db.AddNewUserFriend(user1,user2, 1);
  465. db.AddNewUserFriend(user1,user3, 2);
  466. db.AddNewUserFriend(user1,user2, 4);
  467. List<FriendListItem> fl1 = db.GetUserFriendList(user1);
  468. Assert.That(fl1.Count,Is.EqualTo(2), "Assert.That(fl1.Count,Is.EqualTo(2))");
  469. perms.Add(user2,1);
  470. perms.Add(user3,2);
  471. for (int i = 0; i < fl1.Count; i++)
  472. {
  473. Assert.That(user1,Is.EqualTo(fl1[i].FriendListOwner), "Assert.That(user1,Is.EqualTo(fl1[i].FriendListOwner))");
  474. friends.Add(fl1[i].Friend,1);
  475. temp = perms[fl1[i].Friend];
  476. Assert.That(temp,Is.EqualTo(fl1[i].FriendPerms), "Assert.That(temp,Is.EqualTo(fl1[i].FriendPerms))");
  477. }
  478. tempu1 = friends[user2];
  479. tempu2 = friends[user3];
  480. Assert.That(1,Is.EqualTo(tempu1) & Is.EqualTo(tempu2), "Assert.That(1,Is.EqualTo(tempu1) & Is.EqualTo(tempu2))");
  481. }
  482. [Test]
  483. public void T031_RemoveUserFriend()
  484. // user1 has 2 friends, user2 and user3.
  485. {
  486. List<FriendListItem> fl1 = db.GetUserFriendList(user1);
  487. List<FriendListItem> fl2 = db.GetUserFriendList(user2);
  488. Assert.That(fl1.Count,Is.EqualTo(2), "Assert.That(fl1.Count,Is.EqualTo(2))");
  489. Assert.That(fl1[0].Friend,Is.EqualTo(user2) | Is.EqualTo(user3), "Assert.That(fl1[0].Friend,Is.EqualTo(user2) | Is.EqualTo(user3))");
  490. Assert.That(fl2[0].Friend,Is.EqualTo(user1), "Assert.That(fl2[0].Friend,Is.EqualTo(user1))");
  491. db.RemoveUserFriend(user2, user1);
  492. fl1 = db.GetUserFriendList(user1);
  493. fl2 = db.GetUserFriendList(user2);
  494. Assert.That(fl1.Count,Is.EqualTo(1), "Assert.That(fl1.Count,Is.EqualTo(1))");
  495. Assert.That(fl1[0].Friend, Is.EqualTo(user3), "Assert.That(fl1[0].Friend, Is.EqualTo(user3))");
  496. Assert.That(fl2, Is.Empty);
  497. }
  498. [Test]
  499. public void T032_UpdateFriendPerms()
  500. // user1 has 1 friend, user3, who has permission 2 in T030.
  501. {
  502. List<FriendListItem> fl1 = db.GetUserFriendList(user1);
  503. Assert.That(fl1[0].FriendPerms,Is.EqualTo(2), "Assert.That(fl1[0].FriendPerms,Is.EqualTo(2))");
  504. db.UpdateUserFriendPerms(user1, user3, 4);
  505. fl1 = db.GetUserFriendList(user1);
  506. Assert.That(fl1[0].FriendPerms,Is.EqualTo(4), "Assert.That(fl1[0].FriendPerms,Is.EqualTo(4))");
  507. }
  508. [Test]
  509. public void T040_UserAppearance()
  510. {
  511. AvatarAppearance appear = new AvatarAppearance();
  512. appear.Owner = user1;
  513. db.UpdateUserAppearance(user1, appear);
  514. AvatarAppearance user1app = db.GetUserAppearance(user1);
  515. Assert.That(user1,Is.EqualTo(user1app.Owner), "Assert.That(user1,Is.EqualTo(user1app.Owner))");
  516. }
  517. [Test]
  518. public void T041_UserAppearancePersistency()
  519. {
  520. AvatarAppearance appear = new AvatarAppearance();
  521. UUID owner = UUID.Random();
  522. int serial = random.Next();
  523. byte[] visualp = new byte[218];
  524. random.NextBytes(visualp);
  525. UUID bodyitem = UUID.Random();
  526. UUID bodyasset = UUID.Random();
  527. UUID skinitem = UUID.Random();
  528. UUID skinasset = UUID.Random();
  529. UUID hairitem = UUID.Random();
  530. UUID hairasset = UUID.Random();
  531. UUID eyesitem = UUID.Random();
  532. UUID eyesasset = UUID.Random();
  533. UUID shirtitem = UUID.Random();
  534. UUID shirtasset = UUID.Random();
  535. UUID pantsitem = UUID.Random();
  536. UUID pantsasset = UUID.Random();
  537. UUID shoesitem = UUID.Random();
  538. UUID shoesasset = UUID.Random();
  539. UUID socksitem = UUID.Random();
  540. UUID socksasset = UUID.Random();
  541. UUID jacketitem = UUID.Random();
  542. UUID jacketasset = UUID.Random();
  543. UUID glovesitem = UUID.Random();
  544. UUID glovesasset = UUID.Random();
  545. UUID ushirtitem = UUID.Random();
  546. UUID ushirtasset = UUID.Random();
  547. UUID upantsitem = UUID.Random();
  548. UUID upantsasset = UUID.Random();
  549. UUID skirtitem = UUID.Random();
  550. UUID skirtasset = UUID.Random();
  551. Primitive.TextureEntry texture = AvatarAppearance.GetDefaultTexture();
  552. float avatarheight = (float) (Math.Round(random.NextDouble(),5));
  553. appear.Owner = owner;
  554. appear.Serial = serial;
  555. appear.VisualParams = visualp;
  556. appear.BodyItem = bodyitem;
  557. appear.BodyAsset = bodyasset;
  558. appear.SkinItem = skinitem;
  559. appear.SkinAsset = skinasset;
  560. appear.HairItem = hairitem;
  561. appear.HairAsset = hairasset;
  562. appear.EyesItem = eyesitem;
  563. appear.EyesAsset = eyesasset;
  564. appear.ShirtItem = shirtitem;
  565. appear.ShirtAsset = shirtasset;
  566. appear.PantsItem = pantsitem;
  567. appear.PantsAsset = pantsasset;
  568. appear.ShoesItem = shoesitem;
  569. appear.ShoesAsset = shoesasset;
  570. appear.SocksItem = socksitem;
  571. appear.SocksAsset = socksasset;
  572. appear.JacketItem = jacketitem;
  573. appear.JacketAsset = jacketasset;
  574. appear.GlovesItem = glovesitem;
  575. appear.GlovesAsset = glovesasset;
  576. appear.UnderShirtItem = ushirtitem;
  577. appear.UnderShirtAsset = ushirtasset;
  578. appear.UnderPantsItem = upantsitem;
  579. appear.UnderPantsAsset = upantsasset;
  580. appear.SkirtItem = skirtitem;
  581. appear.SkirtAsset = skirtasset;
  582. appear.Texture = texture;
  583. appear.AvatarHeight = avatarheight;
  584. db.UpdateUserAppearance(owner, appear);
  585. AvatarAppearance app = db.GetUserAppearance(owner);
  586. Assert.That(owner,Is.EqualTo(app.Owner), "Assert.That(owner,Is.EqualTo(app.Owner))");
  587. Assert.That(serial,Is.EqualTo(app.Serial), "Assert.That(serial,Is.EqualTo(app.Serial))");
  588. Assert.That(visualp,Is.EqualTo(app.VisualParams), "Assert.That(visualp,Is.EqualTo(app.VisualParams))");
  589. Assert.That(bodyitem,Is.EqualTo(app.BodyItem), "Assert.That(bodyitem,Is.EqualTo(app.BodyItem))");
  590. Assert.That(bodyasset,Is.EqualTo(app.BodyAsset), "Assert.That(bodyasset,Is.EqualTo(app.BodyAsset))");
  591. Assert.That(skinitem,Is.EqualTo(app.SkinItem), "Assert.That(skinitem,Is.EqualTo(app.SkinItem))");
  592. Assert.That(skinasset,Is.EqualTo(app.SkinAsset), "Assert.That(skinasset,Is.EqualTo(app.SkinAsset))");
  593. Assert.That(hairitem,Is.EqualTo(app.HairItem), "Assert.That(hairitem,Is.EqualTo(app.HairItem))");
  594. Assert.That(hairasset,Is.EqualTo(app.HairAsset), "Assert.That(hairasset,Is.EqualTo(app.HairAsset))");
  595. Assert.That(eyesitem,Is.EqualTo(app.EyesItem), "Assert.That(eyesitem,Is.EqualTo(app.EyesItem))");
  596. Assert.That(eyesasset,Is.EqualTo(app.EyesAsset), "Assert.That(eyesasset,Is.EqualTo(app.EyesAsset))");
  597. Assert.That(shirtitem,Is.EqualTo(app.ShirtItem), "Assert.That(shirtitem,Is.EqualTo(app.ShirtItem))");
  598. Assert.That(shirtasset,Is.EqualTo(app.ShirtAsset), "Assert.That(shirtasset,Is.EqualTo(app.ShirtAsset))");
  599. Assert.That(pantsitem,Is.EqualTo(app.PantsItem), "Assert.That(pantsitem,Is.EqualTo(app.PantsItem))");
  600. Assert.That(pantsasset,Is.EqualTo(app.PantsAsset), "Assert.That(pantsasset,Is.EqualTo(app.PantsAsset))");
  601. Assert.That(shoesitem,Is.EqualTo(app.ShoesItem), "Assert.That(shoesitem,Is.EqualTo(app.ShoesItem))");
  602. Assert.That(shoesasset,Is.EqualTo(app.ShoesAsset), "Assert.That(shoesasset,Is.EqualTo(app.ShoesAsset))");
  603. Assert.That(socksitem,Is.EqualTo(app.SocksItem), "Assert.That(socksitem,Is.EqualTo(app.SocksItem))");
  604. Assert.That(socksasset,Is.EqualTo(app.SocksAsset), "Assert.That(socksasset,Is.EqualTo(app.SocksAsset))");
  605. Assert.That(jacketitem,Is.EqualTo(app.JacketItem), "Assert.That(jacketitem,Is.EqualTo(app.JacketItem))");
  606. Assert.That(jacketasset,Is.EqualTo(app.JacketAsset), "Assert.That(jacketasset,Is.EqualTo(app.JacketAsset))");
  607. Assert.That(glovesitem,Is.EqualTo(app.GlovesItem), "Assert.That(glovesitem,Is.EqualTo(app.GlovesItem))");
  608. Assert.That(glovesasset,Is.EqualTo(app.GlovesAsset), "Assert.That(glovesasset,Is.EqualTo(app.GlovesAsset))");
  609. Assert.That(ushirtitem,Is.EqualTo(app.UnderShirtItem), "Assert.That(ushirtitem,Is.EqualTo(app.UnderShirtItem))");
  610. Assert.That(ushirtasset,Is.EqualTo(app.UnderShirtAsset), "Assert.That(ushirtasset,Is.EqualTo(app.UnderShirtAsset))");
  611. Assert.That(upantsitem,Is.EqualTo(app.UnderPantsItem), "Assert.That(upantsitem,Is.EqualTo(app.UnderPantsItem))");
  612. Assert.That(upantsasset,Is.EqualTo(app.UnderPantsAsset), "Assert.That(upantsasset,Is.EqualTo(app.UnderPantsAsset))");
  613. Assert.That(skirtitem,Is.EqualTo(app.SkirtItem), "Assert.That(skirtitem,Is.EqualTo(app.SkirtItem))");
  614. Assert.That(skirtasset,Is.EqualTo(app.SkirtAsset), "Assert.That(skirtasset,Is.EqualTo(app.SkirtAsset))");
  615. Assert.That(texture.ToString(),Is.EqualTo(app.Texture.ToString()), "Assert.That(texture.ToString(),Is.EqualTo(app.Texture.ToString()))");
  616. Assert.That(avatarheight,Is.EqualTo(app.AvatarHeight), "Assert.That(avatarheight,Is.EqualTo(app.AvatarHeight))");
  617. }
  618. [Test]
  619. public void T999_StillNull()
  620. {
  621. Assert.That(db.GetUserByUUID(zero), Is.Null);
  622. Assert.That(db.GetAgentByUUID(zero), Is.Null);
  623. }
  624. public UserProfileData NewUser(UUID id,string fname,string lname)
  625. {
  626. UserProfileData u = new UserProfileData();
  627. u.ID = id;
  628. u.FirstName = fname;
  629. u.SurName = lname;
  630. u.PasswordHash = "NOTAHASH";
  631. u.PasswordSalt = "NOTSALT";
  632. // MUST specify at least these 5 parameters or an exception is raised
  633. return u;
  634. }
  635. public UserAgentData NewAgent(UUID user_profile, UUID agent)
  636. {
  637. UserAgentData a = new UserAgentData();
  638. a.ProfileID = user_profile;
  639. a.SessionID = agent;
  640. a.SecureSessionID = UUID.Random();
  641. a.AgentIP = RandomName();
  642. return a;
  643. }
  644. public static string RandomName()
  645. {
  646. StringBuilder name = new StringBuilder();
  647. int size = random.Next(5,12);
  648. char ch ;
  649. for (int i=0; i<size; i++)
  650. {
  651. ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ;
  652. name.Append(ch);
  653. }
  654. return name.ToString();
  655. }
  656. }
  657. }