From 46492f3c1182d68139f914bfe89c81ca8dae1733 Mon Sep 17 00:00:00 2001
From: Sean Dague
Date: Thu, 6 Nov 2008 17:07:08 +0000
Subject: From: arthursv@linux.vnet.ibm.com
Add more unit tests for user cases
Persist more user fields into mysql that already had columns
defined but weren't getting passed to the mysql manager.
---
OpenSim/Data/MySQL/MySQLManager.cs | 38 ++++----
OpenSim/Data/MySQL/MySQLUserData.cs | 4 +-
OpenSim/Data/Tests/BasicUserTest.cs | 172 +++++++++++++++++++++++++++++-------
3 files changed, 162 insertions(+), 52 deletions(-)
diff --git a/OpenSim/Data/MySQL/MySQLManager.cs b/OpenSim/Data/MySQL/MySQLManager.cs
index c584eb9..a54c020 100644
--- a/OpenSim/Data/MySQL/MySQLManager.cs
+++ b/OpenSim/Data/MySQL/MySQLManager.cs
@@ -561,7 +561,7 @@ namespace OpenSim.Data.MySQL
retval.Created = Convert.ToInt32(reader["created"].ToString());
retval.LastLogin = Convert.ToInt32(reader["lastLogin"].ToString());
-
+
retval.UserInventoryURI = (string) reader["userInventoryURI"];
retval.UserAssetURI = (string) reader["userAssetURI"];
@@ -751,6 +751,7 @@ namespace OpenSim.Data.MySQL
/// A salted hash of the users password
/// The salt used for the password hash
/// A regionHandle of the users home region
+ /// The UUID of the user's home region
/// Home region position vector
/// Home region position vector
/// Home region position vector
@@ -770,22 +771,22 @@ namespace OpenSim.Data.MySQL
/// Ignored
/// Success?
public bool insertUserRow(UUID uuid, string username, string lastname, string email, string passwordHash,
- string passwordSalt, UInt64 homeRegion, float homeLocX, float homeLocY, float homeLocZ,
+ string passwordSalt, UInt64 homeRegion, UUID homeRegionID, float homeLocX, float homeLocY, float homeLocZ,
float homeLookAtX, float homeLookAtY, float homeLookAtZ, int created, int lastlogin,
string inventoryURI, string assetURI, uint canDoMask, uint wantDoMask,
string aboutText, string firstText,
- UUID profileImage, UUID firstImage, UUID webLoginKey)
+ UUID profileImage, UUID firstImage, UUID webLoginKey, int userFlags, int godLevel, string customType, UUID partner)
{
m_log.Debug("[MySQLManager]: Fetching profile for " + uuid.ToString());
string sql =
- "INSERT INTO users (`UUID`, `username`, `lastname`, `email`, `passwordHash`, `passwordSalt`, `homeRegion`, ";
+ "INSERT INTO users (`UUID`, `username`, `lastname`, `email`, `passwordHash`, `passwordSalt`, `homeRegion`, `homeRegionID`, ";
sql +=
"`homeLocationX`, `homeLocationY`, `homeLocationZ`, `homeLookAtX`, `homeLookAtY`, `homeLookAtZ`, `created`, ";
sql +=
"`lastLogin`, `userInventoryURI`, `userAssetURI`, `profileCanDoMask`, `profileWantDoMask`, `profileAboutText`, ";
sql += "`profileFirstText`, `profileImage`, `profileFirstImage`, `webLoginKey`, `userFlags`, `godLevel`, `customType`, `partner`) VALUES ";
- sql += "(?UUID, ?username, ?lastname, ?email, ?passwordHash, ?passwordSalt, ?homeRegion, ";
+ sql += "(?UUID, ?username, ?lastname, ?email, ?passwordHash, ?passwordSalt, ?homeRegion, ?homeRegionID, ";
sql +=
"?homeLocationX, ?homeLocationY, ?homeLocationZ, ?homeLookAtX, ?homeLookAtY, ?homeLookAtZ, ?created, ";
sql +=
@@ -800,6 +801,7 @@ namespace OpenSim.Data.MySQL
parameters["?passwordHash"] = passwordHash;
parameters["?passwordSalt"] = passwordSalt;
parameters["?homeRegion"] = homeRegion.ToString();
+ parameters["?homeRegionID"] = homeRegionID.ToString();
parameters["?homeLocationX"] = homeLocX.ToString();
parameters["?homeLocationY"] = homeLocY.ToString();
parameters["?homeLocationZ"] = homeLocZ.ToString();
@@ -808,23 +810,21 @@ namespace OpenSim.Data.MySQL
parameters["?homeLookAtZ"] = homeLookAtZ.ToString();
parameters["?created"] = created.ToString();
parameters["?lastLogin"] = lastlogin.ToString();
- parameters["?userInventoryURI"] = String.Empty;
- parameters["?userAssetURI"] = String.Empty;
- parameters["?profileCanDoMask"] = "0";
- parameters["?profileWantDoMask"] = "0";
+ parameters["?userInventoryURI"] = inventoryURI;
+ parameters["?userAssetURI"] = assetURI;
+ parameters["?profileCanDoMask"] = canDoMask.ToString();
+ parameters["?profileWantDoMask"] = wantDoMask.ToString();
parameters["?profileAboutText"] = aboutText;
parameters["?profileFirstText"] = firstText;
parameters["?profileImage"] = profileImage.ToString();
parameters["?profileFirstImage"] = firstImage.ToString();
- parameters["?webLoginKey"] = string.Empty;
- parameters["?userFlags"] = "0";
- parameters["?godLevel"] = "0";
- parameters["?customType"] = "";
- parameters["?partner"] = "";
-
-
+ parameters["?webLoginKey"] = webLoginKey.ToString();
+ parameters["?userFlags"] = userFlags.ToString();
+ parameters["?godLevel"] = godLevel.ToString();
+ parameters["?customType"] = customType == null ? "" : customType;
+ parameters["?partner"] = partner.ToString();
bool returnval = false;
-
+
try
{
IDbCommand result = Query(sql, parameters);
@@ -911,8 +911,8 @@ namespace OpenSim.Data.MySQL
parameters["?lastLogin"] = lastlogin.ToString();
parameters["?userInventoryURI"] = inventoryURI;
parameters["?userAssetURI"] = assetURI;
- parameters["?profileCanDoMask"] = "0";
- parameters["?profileWantDoMask"] = "0";
+ parameters["?profileCanDoMask"] = canDoMask.ToString();
+ parameters["?profileWantDoMask"] = wantDoMask.ToString();
parameters["?profileAboutText"] = aboutText;
parameters["?profileFirstText"] = firstText;
parameters["?profileImage"] = profileImage.ToString();
diff --git a/OpenSim/Data/MySQL/MySQLUserData.cs b/OpenSim/Data/MySQL/MySQLUserData.cs
index 47670d2..82b5bbc 100644
--- a/OpenSim/Data/MySQL/MySQLUserData.cs
+++ b/OpenSim/Data/MySQL/MySQLUserData.cs
@@ -643,13 +643,13 @@ namespace OpenSim.Data.MySQL
try
{
dbm.Manager.insertUserRow(user.ID, user.FirstName, user.SurName, user.Email, user.PasswordHash, user.PasswordSalt,
- user.HomeRegion, user.HomeLocation.X, user.HomeLocation.Y,
+ user.HomeRegion, user.HomeRegionID, user.HomeLocation.X, user.HomeLocation.Y,
user.HomeLocation.Z,
user.HomeLookAt.X, user.HomeLookAt.Y, user.HomeLookAt.Z, user.Created,
user.LastLogin, user.UserInventoryURI, user.UserAssetURI,
user.CanDoMask, user.WantDoMask,
user.AboutText, user.FirstLifeAboutText, user.Image,
- user.FirstLifeImage, user.WebLoginKey);
+ user.FirstLifeImage, user.WebLoginKey, user.UserFlags, user.GodLevel, user.CustomType, user.Partner);
}
catch (Exception e)
{
diff --git a/OpenSim/Data/Tests/BasicUserTest.cs b/OpenSim/Data/Tests/BasicUserTest.cs
index ba6da68..e9e61d0 100644
--- a/OpenSim/Data/Tests/BasicUserTest.cs
+++ b/OpenSim/Data/Tests/BasicUserTest.cs
@@ -46,6 +46,7 @@ namespace OpenSim.Data.Tests
public UUID user2;
public UUID user3;
public UUID user4;
+ public UUID user5;
public UUID webkey;
public UUID zero = UUID.Zero;
public static Random random;
@@ -81,6 +82,7 @@ namespace OpenSim.Data.Tests
user2 = UUID.Random();
user3 = UUID.Random();
user4 = UUID.Random();
+ user5 = UUID.Random();
agent1 = UUID.Random();
agent2 = UUID.Random();
agent3 = UUID.Random();
@@ -191,20 +193,20 @@ namespace OpenSim.Data.Tests
public void T015_UserPersistency()
{
UserProfileData u = new UserProfileData();
- UUID id = UUID.Random();
+ UUID id = user5;
string fname = RandomName();
string lname = RandomName();
+ string email = RandomName();
string passhash = RandomName();
string passsalt = RandomName();
UUID homeregion = UUID.Random();
UUID webloginkey = UUID.Random();
uint homeregx = (uint) random.Next();
uint homeregy = (uint) random.Next();
- Vector3 homeloc = new Vector3((float) random.NextDouble(),(float) random.NextDouble(),(float) random.NextDouble());
- Vector3 homelookat = new Vector3((float)random.NextDouble(),(float)random.NextDouble(),(float)random.NextDouble());
+ Vector3 homeloc = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5));
+ Vector3 homelookat = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5));
int created = random.Next();
int lastlogin = random.Next();
- UUID rootinvfolder = UUID.Random();
string userinvuri = RandomName();
string userasseturi = RandomName();
uint candomask = (uint) random.Next();
@@ -219,20 +221,25 @@ namespace OpenSim.Data.Tests
string customtype = RandomName();
UUID partner = UUID.Random();
+ //HomeRegionX and HomeRegionY must only use 24 bits
+ homeregx = ((homeregx << 8) >> 8);
+ homeregy = ((homeregy << 8) >> 8);
+
u.ID = id;
u.WebLoginKey = webloginkey;
u.HomeRegionID = homeregion;
u.FirstName = fname;
u.SurName = lname;
+ u.Email = email;
u.PasswordHash = passhash;
u.PasswordSalt = passsalt;
u.HomeRegionX = homeregx;
u.HomeRegionY = homeregy;
+ ulong homereg = u.HomeRegion;
u.HomeLocation = homeloc;
u.HomeLookAt = homelookat;
u.Created = created;
u.LastLogin = lastlogin;
- u.RootInventoryFolderID = rootinvfolder;
u.UserInventoryURI = userinvuri;
u.UserAssetURI = userasseturi;
u.CanDoMask = candomask;
@@ -250,34 +257,138 @@ namespace OpenSim.Data.Tests
db.AddNewUserProfile(u);
UserProfileData u1a = db.GetUserByUUID(id);
Assert.That(u1a,Is.Not.Null);
- Assert.That(homeregion,Is.EqualTo(u.HomeRegionID));
- Assert.That(webloginkey,Is.EqualTo(u.WebLoginKey));
- Assert.That(fname,Is.EqualTo(u.FirstName));
- Assert.That(lname,Is.EqualTo(u.SurName));
- Assert.That(passhash,Is.EqualTo(u.PasswordHash));
- Assert.That(passsalt,Is.EqualTo(u.PasswordSalt));
- Assert.That(homeregx,Is.EqualTo(u.HomeRegionX));
- Assert.That(homeregy,Is.EqualTo(u.HomeRegionY));
- Assert.That(homeloc,Is.EqualTo(u.HomeLocation));
- Assert.That(homelookat,Is.EqualTo(u.HomeLookAt));
- Assert.That(created,Is.EqualTo(u.Created));
- Assert.That(lastlogin,Is.EqualTo(u.LastLogin));
- Assert.That(rootinvfolder,Is.EqualTo(u.RootInventoryFolderID));
- Assert.That(userinvuri,Is.EqualTo(u.UserInventoryURI));
- Assert.That(userasseturi,Is.EqualTo(u.UserAssetURI));
- Assert.That(candomask,Is.EqualTo(u.CanDoMask));
- Assert.That(abouttext,Is.EqualTo(u.AboutText));
- Assert.That(flabouttext,Is.EqualTo(u.FirstLifeAboutText));
- Assert.That(image,Is.EqualTo(u.Image));
- Assert.That(firstimage,Is.EqualTo(u.FirstLifeImage));
- Assert.That(agent,Is.EqualTo(u.CurrentAgent));
- Assert.That(userflags,Is.EqualTo(u.UserFlags));
- Assert.That(godlevel,Is.EqualTo(u.GodLevel));
- Assert.That(customtype,Is.EqualTo(u.CustomType));
- Assert.That(partner,Is.EqualTo(u.Partner));
+ Assert.That(id,Is.EqualTo(u1a.ID));
+ Assert.That(homeregion,Is.EqualTo(u1a.HomeRegionID));
+ Assert.That(webloginkey,Is.EqualTo(u1a.WebLoginKey));
+ Assert.That(fname,Is.EqualTo(u1a.FirstName));
+ Assert.That(lname,Is.EqualTo(u1a.SurName));
+ Assert.That(email,Is.EqualTo(u1a.Email));
+ Assert.That(passhash,Is.EqualTo(u1a.PasswordHash));
+ Assert.That(passsalt,Is.EqualTo(u1a.PasswordSalt));
+ Assert.That(homeregx,Is.EqualTo(u1a.HomeRegionX));
+ Assert.That(homeregy,Is.EqualTo(u1a.HomeRegionY));
+ Assert.That(homereg,Is.EqualTo(u1a.HomeRegion));
+ Assert.That(homeloc,Is.EqualTo(u1a.HomeLocation));
+ Assert.That(homelookat,Is.EqualTo(u1a.HomeLookAt));
+ Assert.That(created,Is.EqualTo(u1a.Created));
+ Assert.That(lastlogin,Is.EqualTo(u1a.LastLogin));
+ // RootInventoryFolderID is not tested because it is saved in SQLite,
+ // but not in MySQL
+ Assert.That(userinvuri,Is.EqualTo(u1a.UserInventoryURI));
+ Assert.That(userasseturi,Is.EqualTo(u1a.UserAssetURI));
+ Assert.That(candomask,Is.EqualTo(u1a.CanDoMask));
+ Assert.That(wantdomask,Is.EqualTo(u1a.WantDoMask));
+ Assert.That(abouttext,Is.EqualTo(u1a.AboutText));
+ Assert.That(flabouttext,Is.EqualTo(u1a.FirstLifeAboutText));
+ Assert.That(image,Is.EqualTo(u1a.Image));
+ Assert.That(firstimage,Is.EqualTo(u1a.FirstLifeImage));
+ Assert.That(u1a.CurrentAgent,Is.Null);
+ Assert.That(userflags,Is.EqualTo(u1a.UserFlags));
+ Assert.That(godlevel,Is.EqualTo(u1a.GodLevel));
+ Assert.That(customtype,Is.EqualTo(u1a.CustomType));
+ Assert.That(partner,Is.EqualTo(u1a.Partner));
}
[Test]
+ public void T016_UserUpdatePersistency()
+ {
+ UUID id = user5;
+ UserProfileData u = db.GetUserByUUID(id);
+ string fname = RandomName();
+ string lname = RandomName();
+ string email = RandomName();
+ string passhash = RandomName();
+ string passsalt = RandomName();
+ UUID homeregionid = UUID.Random();
+ UUID webloginkey = UUID.Random();
+ uint homeregx = (uint) random.Next();
+ uint homeregy = (uint) random.Next();
+ Vector3 homeloc = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5));
+ Vector3 homelookat = new Vector3((float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5),(float)Math.Round(random.NextDouble(),5));
+ int created = random.Next();
+ int lastlogin = random.Next();
+ string userinvuri = RandomName();
+ string userasseturi = RandomName();
+ uint candomask = (uint) random.Next();
+ uint wantdomask = (uint) random.Next();
+ string abouttext = RandomName();
+ string flabouttext = RandomName();
+ UUID image = UUID.Random();
+ UUID firstimage = UUID.Random();
+ UserAgentData agent = NewAgent(id,UUID.Random());
+ int userflags = random.Next();
+ int godlevel = random.Next();
+ string customtype = RandomName();
+ UUID partner = UUID.Random();
+
+ //HomeRegionX and HomeRegionY must only use 24 bits
+ homeregx = ((homeregx << 8) >> 8);
+ homeregy = ((homeregy << 8) >> 8);
+
+ u.WebLoginKey = webloginkey;
+ u.HomeRegionID = homeregionid;
+ u.FirstName = fname;
+ u.SurName = lname;
+ u.Email = email;
+ u.PasswordHash = passhash;
+ u.PasswordSalt = passsalt;
+ u.HomeRegionX = homeregx;
+ u.HomeRegionY = homeregy;
+ ulong homereg = u.HomeRegion;
+ u.HomeLocation = homeloc;
+ u.HomeLookAt = homelookat;
+ u.Created = created;
+ u.LastLogin = lastlogin;
+ u.UserInventoryURI = userinvuri;
+ u.UserAssetURI = userasseturi;
+ u.CanDoMask = candomask;
+ u.WantDoMask = wantdomask;
+ u.AboutText = abouttext;
+ u.FirstLifeAboutText = flabouttext;
+ u.Image = image;
+ u.FirstLifeImage = firstimage;
+ u.CurrentAgent = agent;
+ u.UserFlags = userflags;
+ u.GodLevel = godlevel;
+ u.CustomType = customtype;
+ u.Partner = partner;
+
+ db.UpdateUserProfile(u);
+ UserProfileData u1a = db.GetUserByUUID(id);
+ Assert.That(u1a,Is.Not.Null);
+ Assert.That(id,Is.EqualTo(u1a.ID));
+ Assert.That(homeregionid,Is.EqualTo(u1a.HomeRegionID));
+ Assert.That(webloginkey,Is.EqualTo(u1a.WebLoginKey));
+ Assert.That(fname,Is.EqualTo(u1a.FirstName));
+ Assert.That(lname,Is.EqualTo(u1a.SurName));
+ Assert.That(email,Is.EqualTo(u1a.Email));
+ Assert.That(passhash,Is.EqualTo(u1a.PasswordHash));
+ Assert.That(passsalt,Is.EqualTo(u1a.PasswordSalt));
+ Assert.That(homereg,Is.EqualTo(u1a.HomeRegion));
+ Assert.That(homeregx,Is.EqualTo(u1a.HomeRegionX));
+ Assert.That(homeregy,Is.EqualTo(u1a.HomeRegionY));
+ Assert.That(homereg,Is.EqualTo(u1a.HomeRegion));
+ Assert.That(homeloc,Is.EqualTo(u1a.HomeLocation));
+ Assert.That(homelookat,Is.EqualTo(u1a.HomeLookAt));
+ Assert.That(created,Is.EqualTo(u1a.Created));
+ Assert.That(lastlogin,Is.EqualTo(u1a.LastLogin));
+ // RootInventoryFolderID is not tested because it is saved in SQLite,
+ // but not in MySQL
+ Assert.That(userasseturi,Is.EqualTo(u1a.UserAssetURI));
+ Assert.That(candomask,Is.EqualTo(u1a.CanDoMask));
+ Assert.That(wantdomask,Is.EqualTo(u1a.WantDoMask));
+ Assert.That(abouttext,Is.EqualTo(u1a.AboutText));
+ Assert.That(flabouttext,Is.EqualTo(u1a.FirstLifeAboutText));
+ Assert.That(image,Is.EqualTo(u1a.Image));
+ Assert.That(firstimage,Is.EqualTo(u1a.FirstLifeImage));
+ Assert.That(u1a.CurrentAgent,Is.Null);
+ Assert.That(userflags,Is.EqualTo(u1a.UserFlags));
+ Assert.That(godlevel,Is.EqualTo(u1a.GodLevel));
+ Assert.That(customtype,Is.EqualTo(u1a.CustomType));
+ Assert.That(partner,Is.EqualTo(u1a.Partner));
+ }
+
+ [Test]
public void T020_CreateAgent()
{
UserAgentData a1 = NewAgent(user1,agent1);
@@ -394,7 +505,6 @@ namespace OpenSim.Data.Tests
u.SurName = lname;
u.PasswordHash = "NOTAHASH";
u.PasswordSalt = "NOTSALT";
- u.Email = "nobody@nodomain.nocc";
// MUST specify at least these 5 parameters or an exception is raised
return u;
--
cgit v1.1