From a27352010a0d0ae13b5beeac0132474e3ca6ac03 Mon Sep 17 00:00:00 2001
From: Sean Dague
Date: Tue, 14 Oct 2008 19:00:43 +0000
Subject: Merge commit 'arthur/master'
---
OpenSim/Data/SQLite/SQLiteUserData.cs | 14 +-
OpenSim/Data/Tests/BasicUserTest.cs | 257 ++++++++++++++++++++++++++++++++--
2 files changed, 254 insertions(+), 17 deletions(-)
(limited to 'OpenSim/Data')
diff --git a/OpenSim/Data/SQLite/SQLiteUserData.cs b/OpenSim/Data/SQLite/SQLiteUserData.cs
index f847ba9..4beae07 100644
--- a/OpenSim/Data/SQLite/SQLiteUserData.cs
+++ b/OpenSim/Data/SQLite/SQLiteUserData.cs
@@ -117,6 +117,13 @@ namespace OpenSim.Data.SQLite
setupUserFriendsCommands(daf, conn);
daf.Fill(ds.Tables["userfriends"]);
+
+ string Unique = "create unique index friend_unique on userfriends (ownerID,friendID)";
+ using (SqliteCommand cmd = new SqliteCommand(Unique, g_conn))
+ {
+ cmd.ExecuteNonQuery();
+ }
+
}
return;
@@ -210,8 +217,7 @@ namespace OpenSim.Data.SQLite
/// permission flag
override public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms)
{
- string InsertFriends = "insert into userfriends(ownerID, friendID, friendPerms) values(:ownerID, :friendID, :perms)";
-
+ string InsertFriends = "insert or ignore into userfriends(ownerID, friendID, friendPerms) values(:ownerID, :friendID, :perms)";
using (SqliteCommand cmd = new SqliteCommand(InsertFriends, g_conn))
{
cmd.Parameters.Add(new SqliteParameter(":ownerID", friendlistowner.ToString()));
@@ -235,7 +241,7 @@ namespace OpenSim.Data.SQLite
/// UUID of the friend to remove
override public void RemoveUserFriend(UUID friendlistowner, UUID friend)
{
- string DeletePerms = "delete from friendlist where (ownerID=:ownerID and friendID=:friendID) or (ownerID=:friendID and friendID=:ownerID)";
+ string DeletePerms = "delete from userfriends where (ownerID=:ownerID and friendID=:friendID) or (ownerID=:friendID and friendID=:ownerID)";
using (SqliteCommand cmd = new SqliteCommand(DeletePerms, g_conn))
{
cmd.Parameters.Add(new SqliteParameter(":ownerID", friendlistowner.ToString()));
@@ -252,7 +258,7 @@ namespace OpenSim.Data.SQLite
/// updated permission flag
override public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms)
{
- string UpdatePerms = "update friendlist set perms=:perms where ownerID=:ownerID and friendID=:friendID";
+ string UpdatePerms = "update userfriends set friendPerms=:perms where ownerID=:ownerID and friendID=:friendID";
using (SqliteCommand cmd = new SqliteCommand(UpdatePerms, g_conn))
{
cmd.Parameters.Add(new SqliteParameter(":perms", perms));
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 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+// TODO: Money Transfer, Inventory Transfer and UpdateUserRegion once they exist
+
using System;
using System.Collections.Generic;
+using System.Text;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using OpenSim.Data;
@@ -38,10 +41,27 @@ namespace OpenSim.Data.Tests
{
public class BasicUserTest
{
- public UserDataBase db;
- public UUID uuid1;
- public UUID uuid2;
- public UUID uuid3;
+ //public UserDataBase db;
+ public IUserDataPlugin db;
+ public UUID user1;
+ public UUID user2;
+ public UUID user3;
+ public UUID webkey;
+ public UUID zero = UUID.Zero;
+ public Random random;
+
+ public UUID agent1;
+ public UUID agent2;
+ public UUID agent3;
+
+ public UUID region1;
+
+ public string fname1;
+ public string lname1;
+ public string fname2;
+ public string lname2;
+ public string fname3;
+ public string lname3;
public void SuperInit()
{
@@ -53,20 +73,231 @@ namespace OpenSim.Data.Tests
{
// I don't care, just leave log4net off
}
-
- uuid1 = UUID.Random();
- uuid2 = UUID.Random();
- uuid3 = UUID.Random();
+ random = new Random();
+ user1 = UUID.Random();
+ user2 = UUID.Random();
+ user3 = UUID.Random();
+ agent1 = UUID.Random();
+ agent2 = UUID.Random();
+ agent3 = UUID.Random();
+ webkey = UUID.Random();
+ region1 = UUID.Random();
+ fname1 = RandomName(random);
+ lname1 = RandomName(random);
+ fname2 = RandomName(random);
+ lname2 = RandomName(random);
+ fname3 = RandomName(random);
+ lname3 = RandomName(random);
}
[Test]
public void T001_LoadEmpty()
{
- Assert.That(db.GetUserByUUID(UUID.Zero), Is.Null);
- Assert.That(db.GetUserByUUID(uuid1), Is.Null);
- Assert.That(db.GetUserByUUID(uuid2), Is.Null);
- Assert.That(db.GetUserByUUID(uuid3), Is.Null);
+ Assert.That(db.GetUserByUUID(zero), Is.Null);
+ Assert.That(db.GetUserByUUID(user1), Is.Null);
+ Assert.That(db.GetUserByUUID(user2), Is.Null);
+ Assert.That(db.GetUserByUUID(user3), Is.Null);
Assert.That(db.GetUserByUUID(UUID.Random()), Is.Null);
+
+ Assert.That(db.GetAgentByUUID(zero), Is.Null);
+ Assert.That(db.GetAgentByUUID(agent1), Is.Null);
+ Assert.That(db.GetAgentByUUID(agent2), Is.Null);
+ Assert.That(db.GetAgentByUUID(agent3), Is.Null);
+ Assert.That(db.GetAgentByUUID(UUID.Random()), Is.Null);
+ }
+
+ [Test]
+ public void T999_StillNull()
+ {
+ Assert.That(db.GetUserByUUID(zero), Is.Null);
+ Assert.That(db.GetAgentByUUID(zero), Is.Null);
+ }
+
+ [Test]
+ public void T010_CreateUser()
+ {
+ UserProfileData u1 = NewUser(user1,fname1,lname1); // Must first and last names be unique?
+ //UserProfileData u0 = NewUser(zero,fname1,lname1); // Zero causes some weird behaviors
+ UserProfileData u2 = NewUser(user2,fname2,lname2);
+ UserProfileData u3 = NewUser(user3,fname3,lname3);
+ //db.AddNewUserProfile(u0);
+ db.AddNewUserProfile(u1);
+ db.AddNewUserProfile(u2);
+ db.AddNewUserProfile(u3);
+ //UserProfileData u1z = db.GetUserByUUID(zero);
+ UserProfileData u1a = db.GetUserByUUID(user1);
+ UserProfileData u2a = db.GetUserByUUID(user2);
+ UserProfileData u3a = db.GetUserByUUID(user3);
+ //Assert.That(zero,Is.EqualTo(u1z.ID));
+ Assert.That(user1,Is.EqualTo(u1a.ID));
+ Assert.That(user2,Is.EqualTo(u2a.ID));
+ Assert.That(user3,Is.EqualTo(u3a.ID));
+ }
+
+ [Test]
+ public void T011_FetchUserByName()
+ {
+ UserProfileData u1 = db.GetUserByName(fname1,lname1);
+ UserProfileData u2 = db.GetUserByName(fname2,lname2);
+ UserProfileData u3 = db.GetUserByName(fname3,lname3);
+ Assert.That(user1,Is.EqualTo(u1.ID)); //??
+ Assert.That(user2,Is.EqualTo(u2.ID));
+ Assert.That(user3,Is.EqualTo(u3.ID));
+ }
+
+ [Test]
+ public void T012_UpdateUserProfile()
+ {
+ UserProfileData u1 = db.GetUserByUUID(user1);
+ Assert.That(fname1,Is.EqualTo(u1.FirstName));
+ u1.FirstName = "Ugly";
+
+ db.UpdateUserProfile(u1);
+ Assert.That("Ugly",Is.EqualTo(u1.FirstName));
+ }
+
+ [Test]
+ public void T013_StoreUserWebKey()
+ {
+ UserProfileData u1 = db.GetUserByUUID(user1);
+ Assert.That(u1.WebLoginKey,Is.EqualTo(zero));
+ db.StoreWebLoginKey(user1, webkey);
+ u1 = db.GetUserByUUID(user1);
+ Assert.That(u1.WebLoginKey,Is.EqualTo(webkey));
+ }
+
+ [Test]
+ public void T020_CreateAgent()
+ {
+ UserAgentData a1 = NewAgent(user1,agent1);
+ UserAgentData a2 = NewAgent(user2,agent2);
+ UserAgentData a3 = NewAgent(user3,agent3);
+ db.AddNewUserAgent(a1);
+ db.AddNewUserAgent(a2);
+ db.AddNewUserAgent(a3);
+ UserAgentData a1a = db.GetAgentByUUID(user1);
+ UserAgentData a2a = db.GetAgentByUUID(user2);
+ UserAgentData a3a = db.GetAgentByUUID(user3);
+ Assert.That(agent1,Is.EqualTo(a1a.SessionID));
+ Assert.That(user1,Is.EqualTo(a1a.ProfileID));
+ Assert.That(agent2,Is.EqualTo(a2a.SessionID));
+ Assert.That(user2,Is.EqualTo(a2a.ProfileID));
+ Assert.That(agent3,Is.EqualTo(a3a.SessionID));
+ Assert.That(user3,Is.EqualTo(a3a.ProfileID));
+ }
+
+ [Test]
+ public void T021_FetchAgentByName()
+ {
+ String name3 = fname3 + " " + lname3;
+ UserAgentData a2 = db.GetAgentByName(fname2,lname2);
+ UserAgentData a3 = db.GetAgentByName(name3);
+ Assert.That(user2,Is.EqualTo(a2.ProfileID));
+ Assert.That(user3,Is.EqualTo(a3.ProfileID));
+ }
+
+ [Test]
+ public void T030_CreateFriendList()
+ {
+ Dictionary perms = new Dictionary();
+ Dictionary friends = new Dictionary();
+ uint temp;
+ int tempu1, tempu2;
+ db.AddNewUserFriend(user1,user2, 1);
+ db.AddNewUserFriend(user1,user3, 2);
+ db.AddNewUserFriend(user1,user2, 4); //FAILS uniqueness in SQLite
+ List fl1 = db.GetUserFriendList(user1);
+ Assert.That(fl1.Count,Is.EqualTo(2));
+ perms.Add(user2,1);
+ perms.Add(user3,2);
+ for (int i = 0; i < fl1.Count; i++)
+ {
+ Assert.That(user1,Is.EqualTo(fl1[i].FriendListOwner));
+ // MySQL does not guarantee insertion order will be mantained
+ friends.Add(fl1[i].Friend,1);
+ temp = perms[fl1[i].Friend];
+ Assert.That(temp,Is.EqualTo(fl1[i].FriendPerms));
+ }
+ tempu1 = friends[user2];
+ tempu2 = friends[user3];
+ Assert.That(1,Is.EqualTo(tempu1) & Is.EqualTo(tempu2));
+ }
+
+ [Test]
+ public void T031_RemoveUserFriend()
+ // user1 has 2 friends, user2 and user3.
+ {
+ List fl1 = db.GetUserFriendList(user1);
+ List fl2 = db.GetUserFriendList(user2);
+
+ Assert.That(fl1.Count,Is.EqualTo(2));
+ Assert.That(fl1[0].Friend,Is.EqualTo(user2) | Is.EqualTo(user3));
+ Assert.That(fl2[0].Friend,Is.EqualTo(user1));
+ db.RemoveUserFriend(user2, user1);
+
+ fl1 = db.GetUserFriendList(user1);
+ fl2 = db.GetUserFriendList(user2);
+ Assert.That(fl1.Count,Is.EqualTo(1));
+ Assert.That(fl1[0].Friend, Is.EqualTo(user3));
+ Assert.That(fl2, Is.Empty);
+ }
+
+ [Test]
+ public void T032_UpdateFriendPerms()
+ {
+ List fl1 = db.GetUserFriendList(user1);
+ Assert.That(fl1[0].FriendPerms,Is.EqualTo(2));
+ db.UpdateUserFriendPerms(user1, user3, 4);
+
+ fl1 = db.GetUserFriendList(user1);
+ Assert.That(fl1[0].FriendPerms,Is.EqualTo(4));
+ }
+
+ public UserProfileData NewUser(UUID id,string fname,string lname)
+ {
+ UserProfileData u = new UserProfileData();
+ u.ID = id;
+ u.FirstName = fname;
+ u.SurName = lname;
+ u.PasswordHash = "NOTAHASH";
+ u.PasswordSalt = "NOTSALT";
+ // MUST specify at least these 5 parameters or an exception is raised
+
+ return u;
+ }
+
+ public UserAgentData NewAgent(UUID user_profile, UUID agent)
+ {
+ UserAgentData a = new UserAgentData();
+ a.ProfileID = user_profile;
+ a.SessionID = agent;
+ a.SecureSessionID = UUID.Random();
+ a.AgentIP = RandomName(random);
+ return a;
+ }
+
+ public static string RandomName(Random random)
+ {
+ StringBuilder name = new StringBuilder();
+ int size = random.Next(5,12);
+ char ch ;
+ for(int i=0; i fl)
+ {
+ Console.WriteLine("Friends {0} and {1} and {2}", agent1, agent2, agent3);
+ Console.WriteLine("List owner is {0}",fl[0].FriendListOwner);
+ for (int i = 0; i < fl.Count; i++)
+ {
+ Console.WriteLine("Friend {0}",fl[i].Friend);
+ }
+
}
}
-}
\ No newline at end of file
+}
--
cgit v1.1