BasicUserTest.cs 29 KB

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