diff options
author | Sean Dague | 2008-10-14 19:00:43 +0000 |
---|---|---|
committer | Sean Dague | 2008-10-14 19:00:43 +0000 |
commit | a27352010a0d0ae13b5beeac0132474e3ca6ac03 (patch) | |
tree | 74cf66a9e34b8ca6353e4b18ecd818e903fa21bd /OpenSim/Data/Tests/BasicUserTest.cs | |
parent | * minor: change m_debug to m_debugPacketLevel since that's what it is (diff) | |
download | opensim-SC_OLD-a27352010a0d0ae13b5beeac0132474e3ca6ac03.zip opensim-SC_OLD-a27352010a0d0ae13b5beeac0132474e3ca6ac03.tar.gz opensim-SC_OLD-a27352010a0d0ae13b5beeac0132474e3ca6ac03.tar.bz2 opensim-SC_OLD-a27352010a0d0ae13b5beeac0132474e3ca6ac03.tar.xz |
Merge commit 'arthur/master'
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/Tests/BasicUserTest.cs | 257 |
1 files changed, 244 insertions, 13 deletions
diff --git a/OpenSim/Data/Tests/BasicUserTest.cs b/OpenSim/Data/Tests/BasicUserTest.cs index 9587d86..ef62a7d 100644 --- a/OpenSim/Data/Tests/BasicUserTest.cs +++ b/OpenSim/Data/Tests/BasicUserTest.cs | |||
@@ -25,8 +25,11 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | // TODO: Money Transfer, Inventory Transfer and UpdateUserRegion once they exist | ||
29 | |||
28 | using System; | 30 | using System; |
29 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
32 | using System.Text; | ||
30 | using NUnit.Framework; | 33 | using NUnit.Framework; |
31 | using NUnit.Framework.SyntaxHelpers; | 34 | using NUnit.Framework.SyntaxHelpers; |
32 | using OpenSim.Data; | 35 | using OpenSim.Data; |
@@ -38,10 +41,27 @@ namespace OpenSim.Data.Tests | |||
38 | { | 41 | { |
39 | public class BasicUserTest | 42 | public class BasicUserTest |
40 | { | 43 | { |
41 | public UserDataBase db; | 44 | //public UserDataBase db; |
42 | public UUID uuid1; | 45 | public IUserDataPlugin db; |
43 | public UUID uuid2; | 46 | public UUID user1; |
44 | public UUID uuid3; | 47 | public UUID user2; |
48 | public UUID user3; | ||
49 | public UUID webkey; | ||
50 | public UUID zero = UUID.Zero; | ||
51 | public Random random; | ||
52 | |||
53 | public UUID agent1; | ||
54 | public UUID agent2; | ||
55 | public UUID agent3; | ||
56 | |||
57 | public UUID region1; | ||
58 | |||
59 | public string fname1; | ||
60 | public string lname1; | ||
61 | public string fname2; | ||
62 | public string lname2; | ||
63 | public string fname3; | ||
64 | public string lname3; | ||
45 | 65 | ||
46 | public void SuperInit() | 66 | public void SuperInit() |
47 | { | 67 | { |
@@ -53,20 +73,231 @@ namespace OpenSim.Data.Tests | |||
53 | { | 73 | { |
54 | // I don't care, just leave log4net off | 74 | // I don't care, just leave log4net off |
55 | } | 75 | } |
56 | 76 | random = new Random(); | |
57 | uuid1 = UUID.Random(); | 77 | user1 = UUID.Random(); |
58 | uuid2 = UUID.Random(); | 78 | user2 = UUID.Random(); |
59 | uuid3 = UUID.Random(); | 79 | user3 = UUID.Random(); |
80 | agent1 = UUID.Random(); | ||
81 | agent2 = UUID.Random(); | ||
82 | agent3 = UUID.Random(); | ||
83 | webkey = UUID.Random(); | ||
84 | region1 = UUID.Random(); | ||
85 | fname1 = RandomName(random); | ||
86 | lname1 = RandomName(random); | ||
87 | fname2 = RandomName(random); | ||
88 | lname2 = RandomName(random); | ||
89 | fname3 = RandomName(random); | ||
90 | lname3 = RandomName(random); | ||
60 | } | 91 | } |
61 | 92 | ||
62 | [Test] | 93 | [Test] |
63 | public void T001_LoadEmpty() | 94 | public void T001_LoadEmpty() |
64 | { | 95 | { |
65 | Assert.That(db.GetUserByUUID(UUID.Zero), Is.Null); | 96 | Assert.That(db.GetUserByUUID(zero), Is.Null); |
66 | Assert.That(db.GetUserByUUID(uuid1), Is.Null); | 97 | Assert.That(db.GetUserByUUID(user1), Is.Null); |
67 | Assert.That(db.GetUserByUUID(uuid2), Is.Null); | 98 | Assert.That(db.GetUserByUUID(user2), Is.Null); |
68 | Assert.That(db.GetUserByUUID(uuid3), Is.Null); | 99 | Assert.That(db.GetUserByUUID(user3), Is.Null); |
69 | Assert.That(db.GetUserByUUID(UUID.Random()), Is.Null); | 100 | Assert.That(db.GetUserByUUID(UUID.Random()), Is.Null); |
101 | |||
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 | |||
109 | [Test] | ||
110 | public void T999_StillNull() | ||
111 | { | ||
112 | Assert.That(db.GetUserByUUID(zero), Is.Null); | ||
113 | Assert.That(db.GetAgentByUUID(zero), Is.Null); | ||
114 | } | ||
115 | |||
116 | [Test] | ||
117 | public void T010_CreateUser() | ||
118 | { | ||
119 | UserProfileData u1 = NewUser(user1,fname1,lname1); // Must first and last names be unique? | ||
120 | //UserProfileData u0 = NewUser(zero,fname1,lname1); // Zero causes some weird behaviors | ||
121 | UserProfileData u2 = NewUser(user2,fname2,lname2); | ||
122 | UserProfileData u3 = NewUser(user3,fname3,lname3); | ||
123 | //db.AddNewUserProfile(u0); | ||
124 | db.AddNewUserProfile(u1); | ||
125 | db.AddNewUserProfile(u2); | ||
126 | db.AddNewUserProfile(u3); | ||
127 | //UserProfileData u1z = db.GetUserByUUID(zero); | ||
128 | UserProfileData u1a = db.GetUserByUUID(user1); | ||
129 | UserProfileData u2a = db.GetUserByUUID(user2); | ||
130 | UserProfileData u3a = db.GetUserByUUID(user3); | ||
131 | //Assert.That(zero,Is.EqualTo(u1z.ID)); | ||
132 | Assert.That(user1,Is.EqualTo(u1a.ID)); | ||
133 | Assert.That(user2,Is.EqualTo(u2a.ID)); | ||
134 | Assert.That(user3,Is.EqualTo(u3a.ID)); | ||
135 | } | ||
136 | |||
137 | [Test] | ||
138 | public void T011_FetchUserByName() | ||
139 | { | ||
140 | UserProfileData u1 = db.GetUserByName(fname1,lname1); | ||
141 | UserProfileData u2 = db.GetUserByName(fname2,lname2); | ||
142 | UserProfileData u3 = db.GetUserByName(fname3,lname3); | ||
143 | Assert.That(user1,Is.EqualTo(u1.ID)); //?? | ||
144 | Assert.That(user2,Is.EqualTo(u2.ID)); | ||
145 | Assert.That(user3,Is.EqualTo(u3.ID)); | ||
146 | } | ||
147 | |||
148 | [Test] | ||
149 | public void T012_UpdateUserProfile() | ||
150 | { | ||
151 | UserProfileData u1 = db.GetUserByUUID(user1); | ||
152 | Assert.That(fname1,Is.EqualTo(u1.FirstName)); | ||
153 | u1.FirstName = "Ugly"; | ||
154 | |||
155 | db.UpdateUserProfile(u1); | ||
156 | Assert.That("Ugly",Is.EqualTo(u1.FirstName)); | ||
157 | } | ||
158 | |||
159 | [Test] | ||
160 | public void T013_StoreUserWebKey() | ||
161 | { | ||
162 | UserProfileData u1 = db.GetUserByUUID(user1); | ||
163 | Assert.That(u1.WebLoginKey,Is.EqualTo(zero)); | ||
164 | db.StoreWebLoginKey(user1, webkey); | ||
165 | u1 = db.GetUserByUUID(user1); | ||
166 | Assert.That(u1.WebLoginKey,Is.EqualTo(webkey)); | ||
167 | } | ||
168 | |||
169 | [Test] | ||
170 | public void T020_CreateAgent() | ||
171 | { | ||
172 | UserAgentData a1 = NewAgent(user1,agent1); | ||
173 | UserAgentData a2 = NewAgent(user2,agent2); | ||
174 | UserAgentData a3 = NewAgent(user3,agent3); | ||
175 | db.AddNewUserAgent(a1); | ||
176 | db.AddNewUserAgent(a2); | ||
177 | db.AddNewUserAgent(a3); | ||
178 | UserAgentData a1a = db.GetAgentByUUID(user1); | ||
179 | UserAgentData a2a = db.GetAgentByUUID(user2); | ||
180 | UserAgentData a3a = db.GetAgentByUUID(user3); | ||
181 | Assert.That(agent1,Is.EqualTo(a1a.SessionID)); | ||
182 | Assert.That(user1,Is.EqualTo(a1a.ProfileID)); | ||
183 | Assert.That(agent2,Is.EqualTo(a2a.SessionID)); | ||
184 | Assert.That(user2,Is.EqualTo(a2a.ProfileID)); | ||
185 | Assert.That(agent3,Is.EqualTo(a3a.SessionID)); | ||
186 | Assert.That(user3,Is.EqualTo(a3a.ProfileID)); | ||
187 | } | ||
188 | |||
189 | [Test] | ||
190 | public void T021_FetchAgentByName() | ||
191 | { | ||
192 | String name3 = fname3 + " " + lname3; | ||
193 | UserAgentData a2 = db.GetAgentByName(fname2,lname2); | ||
194 | UserAgentData a3 = db.GetAgentByName(name3); | ||
195 | Assert.That(user2,Is.EqualTo(a2.ProfileID)); | ||
196 | Assert.That(user3,Is.EqualTo(a3.ProfileID)); | ||
197 | } | ||
198 | |||
199 | [Test] | ||
200 | public void T030_CreateFriendList() | ||
201 | { | ||
202 | Dictionary<UUID, uint> perms = new Dictionary<UUID,uint>(); | ||
203 | Dictionary<UUID, int> friends = new Dictionary<UUID,int>(); | ||
204 | uint temp; | ||
205 | int tempu1, tempu2; | ||
206 | db.AddNewUserFriend(user1,user2, 1); | ||
207 | db.AddNewUserFriend(user1,user3, 2); | ||
208 | db.AddNewUserFriend(user1,user2, 4); //FAILS uniqueness in SQLite | ||
209 | List<FriendListItem> fl1 = db.GetUserFriendList(user1); | ||
210 | Assert.That(fl1.Count,Is.EqualTo(2)); | ||
211 | perms.Add(user2,1); | ||
212 | perms.Add(user3,2); | ||
213 | for (int i = 0; i < fl1.Count; i++) | ||
214 | { | ||
215 | Assert.That(user1,Is.EqualTo(fl1[i].FriendListOwner)); | ||
216 | // MySQL does not guarantee insertion order will be mantained | ||
217 | friends.Add(fl1[i].Friend,1); | ||
218 | temp = perms[fl1[i].Friend]; | ||
219 | Assert.That(temp,Is.EqualTo(fl1[i].FriendPerms)); | ||
220 | } | ||
221 | tempu1 = friends[user2]; | ||
222 | tempu2 = friends[user3]; | ||
223 | Assert.That(1,Is.EqualTo(tempu1) & Is.EqualTo(tempu2)); | ||
224 | } | ||
225 | |||
226 | [Test] | ||
227 | public void T031_RemoveUserFriend() | ||
228 | // user1 has 2 friends, user2 and user3. | ||
229 | { | ||
230 | List<FriendListItem> fl1 = db.GetUserFriendList(user1); | ||
231 | List<FriendListItem> fl2 = db.GetUserFriendList(user2); | ||
232 | |||
233 | Assert.That(fl1.Count,Is.EqualTo(2)); | ||
234 | Assert.That(fl1[0].Friend,Is.EqualTo(user2) | Is.EqualTo(user3)); | ||
235 | Assert.That(fl2[0].Friend,Is.EqualTo(user1)); | ||
236 | db.RemoveUserFriend(user2, user1); | ||
237 | |||
238 | fl1 = db.GetUserFriendList(user1); | ||
239 | fl2 = db.GetUserFriendList(user2); | ||
240 | Assert.That(fl1.Count,Is.EqualTo(1)); | ||
241 | Assert.That(fl1[0].Friend, Is.EqualTo(user3)); | ||
242 | Assert.That(fl2, Is.Empty); | ||
243 | } | ||
244 | |||
245 | [Test] | ||
246 | public void T032_UpdateFriendPerms() | ||
247 | { | ||
248 | List<FriendListItem> fl1 = db.GetUserFriendList(user1); | ||
249 | Assert.That(fl1[0].FriendPerms,Is.EqualTo(2)); | ||
250 | db.UpdateUserFriendPerms(user1, user3, 4); | ||
251 | |||
252 | fl1 = db.GetUserFriendList(user1); | ||
253 | Assert.That(fl1[0].FriendPerms,Is.EqualTo(4)); | ||
254 | } | ||
255 | |||
256 | public UserProfileData NewUser(UUID id,string fname,string lname) | ||
257 | { | ||
258 | UserProfileData u = new UserProfileData(); | ||
259 | u.ID = id; | ||
260 | u.FirstName = fname; | ||
261 | u.SurName = lname; | ||
262 | u.PasswordHash = "NOTAHASH"; | ||
263 | u.PasswordSalt = "NOTSALT"; | ||
264 | // MUST specify at least these 5 parameters or an exception is raised | ||
265 | |||
266 | return u; | ||
267 | } | ||
268 | |||
269 | public UserAgentData NewAgent(UUID user_profile, UUID agent) | ||
270 | { | ||
271 | UserAgentData a = new UserAgentData(); | ||
272 | a.ProfileID = user_profile; | ||
273 | a.SessionID = agent; | ||
274 | a.SecureSessionID = UUID.Random(); | ||
275 | a.AgentIP = RandomName(random); | ||
276 | return a; | ||
277 | } | ||
278 | |||
279 | public static string RandomName(Random random) | ||
280 | { | ||
281 | StringBuilder name = new StringBuilder(); | ||
282 | int size = random.Next(5,12); | ||
283 | char ch ; | ||
284 | for(int i=0; i<size; i++) | ||
285 | { | ||
286 | ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ; | ||
287 | name.Append(ch); | ||
288 | } | ||
289 | return name.ToString(); | ||
290 | } | ||
291 | |||
292 | public void PrintFriendsList(List<FriendListItem> fl) | ||
293 | { | ||
294 | Console.WriteLine("Friends {0} and {1} and {2}", agent1, agent2, agent3); | ||
295 | Console.WriteLine("List owner is {0}",fl[0].FriendListOwner); | ||
296 | for (int i = 0; i < fl.Count; i++) | ||
297 | { | ||
298 | Console.WriteLine("Friend {0}",fl[i].Friend); | ||
299 | } | ||
300 | |||
70 | } | 301 | } |
71 | } | 302 | } |
72 | } \ No newline at end of file | 303 | } |