BasicUserTest.cs 29 KB

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