aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorMelanie2010-05-26 10:38:46 +0100
committerMelanie2010-05-26 10:56:24 +0100
commit1c7f60ab493dffe44ab0517e4a6101fe5d909e28 (patch)
tree72b6a478d32d968ad7f5f3d6d11955bee9662926
parentChange the way alpha is interpreted on prim text. Manris #4723 (diff)
parentMinor correction to AssetTests.cs (diff)
downloadopensim-SC_OLD-1c7f60ab493dffe44ab0517e4a6101fe5d909e28.zip
opensim-SC_OLD-1c7f60ab493dffe44ab0517e4a6101fe5d909e28.tar.gz
opensim-SC_OLD-1c7f60ab493dffe44ab0517e4a6101fe5d909e28.tar.bz2
opensim-SC_OLD-1c7f60ab493dffe44ab0517e4a6101fe5d909e28.tar.xz
Merge branch 'unitests'
Signed-off-by: Melanie <melanie@t-data.com>
-rw-r--r--OpenSim/Data/MSSQL/MSSQLAssetData.cs106
-rw-r--r--OpenSim/Data/MSSQL/MSSQLEstateData.cs2
-rw-r--r--OpenSim/Data/MSSQL/MSSQLInventoryData.cs51
-rw-r--r--OpenSim/Data/MSSQL/Resources/AssetStore.migrations6
-rw-r--r--OpenSim/Data/MSSQL/Resources/AvatarAppearance.sql0
-rw-r--r--OpenSim/Data/MSSQL/Resources/CreateAssetsTable.sql0
-rw-r--r--OpenSim/Data/MSSQL/Resources/CreateFoldersTable.sql0
-rw-r--r--OpenSim/Data/MSSQL/Resources/CreateItemsTable.sql0
-rw-r--r--OpenSim/Data/MSSQL/Resources/CreateUserFriendsTable.sql0
-rw-r--r--OpenSim/Data/MSSQL/Resources/InventoryStore.migrations70
-rw-r--r--OpenSim/Data/MSSQL/Resources/Mssql-agents.sql0
-rw-r--r--OpenSim/Data/MSSQL/Resources/Mssql-logs.sql0
-rw-r--r--OpenSim/Data/MSSQL/Resources/Mssql-regions.sql0
-rw-r--r--OpenSim/Data/MSSQL/Resources/Mssql-users.sql0
-rw-r--r--OpenSim/Data/MySQL/Resources/EstateStore.migrations81
-rw-r--r--OpenSim/Data/MySQL/Resources/RegionStore.migrations84
-rw-r--r--OpenSim/Data/MySQL/Tests/MySQLAssetTest.cs92
-rw-r--r--OpenSim/Data/MySQL/Tests/MySQLEstateTest.cs116
-rw-r--r--OpenSim/Data/MySQL/Tests/MySQLInventoryTest.cs99
-rw-r--r--OpenSim/Data/MySQL/Tests/MySQLRegionTest.cs112
-rw-r--r--OpenSim/Data/SQLite/Resources/EstateStore.migrations88
-rw-r--r--OpenSim/Data/SQLite/Resources/RegionStore.migrations25
-rw-r--r--OpenSim/Data/SQLite/Tests/SQLiteAssetTest.cs64
-rw-r--r--OpenSim/Data/SQLite/Tests/SQLiteEstateTest.cs65
-rw-r--r--OpenSim/Data/SQLite/Tests/SQLiteInventoryTest.cs66
-rw-r--r--OpenSim/Data/SQLite/Tests/SQLiteRegionTest.cs64
-rw-r--r--OpenSim/Data/Tests/AssetTests.cs221
-rw-r--r--OpenSim/Data/Tests/BasicAssetTest.cs166
-rw-r--r--OpenSim/Data/Tests/BasicDataServiceTest.cs234
-rw-r--r--OpenSim/Data/Tests/DefaultTestConns.cs63
-rw-r--r--OpenSim/Data/Tests/EstateTests.cs (renamed from OpenSim/Data/Tests/BasicEstateTest.cs)98
-rw-r--r--OpenSim/Data/Tests/InventoryTests.cs (renamed from OpenSim/Data/Tests/BasicInventoryTest.cs)127
-rw-r--r--OpenSim/Data/Tests/RegionTests.cs (renamed from OpenSim/Data/Tests/BasicRegionTest.cs)221
-rw-r--r--OpenSim/Data/Tests/Resources/TestDataConnections.ini24
-rw-r--r--prebuild.xml77
35 files changed, 1154 insertions, 1268 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLAssetData.cs b/OpenSim/Data/MSSQL/MSSQLAssetData.cs
index 8475b22..c7488d8 100644
--- a/OpenSim/Data/MSSQL/MSSQLAssetData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLAssetData.cs
@@ -121,15 +121,16 @@ namespace OpenSim.Data.MSSQL
121 if (reader.Read()) 121 if (reader.Read())
122 { 122 {
123 AssetBase asset = new AssetBase( 123 AssetBase asset = new AssetBase(
124 new UUID((Guid)reader["id"]), 124 DBGuid.FromDB(reader["id"]),
125 (string)reader["name"], 125 (string)reader["name"],
126 Convert.ToSByte(reader["assetType"]), 126 Convert.ToSByte(reader["assetType"]),
127 String.Empty 127 reader["creatorid"].ToString()
128 ); 128 );
129 // Region Main 129 // Region Main
130 asset.Description = (string)reader["description"]; 130 asset.Description = (string)reader["description"];
131 asset.Local = Convert.ToBoolean(reader["local"]); 131 asset.Local = Convert.ToBoolean(reader["local"]);
132 asset.Temporary = Convert.ToBoolean(reader["temporary"]); 132 asset.Temporary = Convert.ToBoolean(reader["temporary"]);
133 asset.Flags = (AssetFlags)(Convert.ToInt32(reader["asset_flags"]));
133 asset.Data = (byte[])reader["data"]; 134 asset.Data = (byte[])reader["data"];
134 return asset; 135 return asset;
135 } 136 }
@@ -144,26 +145,19 @@ namespace OpenSim.Data.MSSQL
144 /// <param name="asset">the asset</param> 145 /// <param name="asset">the asset</param>
145 override public void StoreAsset(AssetBase asset) 146 override public void StoreAsset(AssetBase asset)
146 { 147 {
147 if (ExistsAsset(asset.FullID)) 148
148 UpdateAsset(asset); 149 string sql =
149 else 150 @"IF EXISTS(SELECT * FROM assets WHERE id=@id)
150 InsertAsset(asset); 151 UPDATE assets set name = @name, description = @description, assetType = @assetType,
151 } 152 local = @local, temporary = @temporary, creatorid = @creatorid, data = @data
152 153 WHERE id=@id
153 154 ELSE
154 private void InsertAsset(AssetBase asset) 155 INSERT INTO assets
155 { 156 ([id], [name], [description], [assetType], [local],
156 if (ExistsAsset(asset.FullID)) 157 [temporary], [create_time], [access_time], [creatorid], [asset_flags], [data])
157 { 158 VALUES
158 return; 159 (@id, @name, @description, @assetType, @local,
159 } 160 @temporary, @create_time, @access_time, @creatorid, @asset_flags, @data)";
160
161 string sql = @"INSERT INTO assets
162 ([id], [name], [description], [assetType], [local],
163 [temporary], [create_time], [access_time], [data])
164 VALUES
165 (@id, @name, @description, @assetType, @local,
166 @temporary, @create_time, @access_time, @data)";
167 161
168 string assetName = asset.Name; 162 string assetName = asset.Name;
169 if (asset.Name.Length > 64) 163 if (asset.Name.Length > 64)
@@ -191,6 +185,8 @@ namespace OpenSim.Data.MSSQL
191 command.Parameters.Add(m_database.CreateParameter("temporary", asset.Temporary)); 185 command.Parameters.Add(m_database.CreateParameter("temporary", asset.Temporary));
192 command.Parameters.Add(m_database.CreateParameter("access_time", now)); 186 command.Parameters.Add(m_database.CreateParameter("access_time", now));
193 command.Parameters.Add(m_database.CreateParameter("create_time", now)); 187 command.Parameters.Add(m_database.CreateParameter("create_time", now));
188 command.Parameters.Add(m_database.CreateParameter("asset_flags", (int)asset.Flags));
189 command.Parameters.Add(m_database.CreateParameter("creatorid", asset.Metadata.CreatorID));
194 command.Parameters.Add(m_database.CreateParameter("data", asset.Data)); 190 command.Parameters.Add(m_database.CreateParameter("data", asset.Data));
195 conn.Open(); 191 conn.Open();
196 try 192 try
@@ -199,57 +195,11 @@ namespace OpenSim.Data.MSSQL
199 } 195 }
200 catch(Exception e) 196 catch(Exception e)
201 { 197 {
202 m_log.Error("[ASSET DB]: Error inserting item :" + e.Message); 198 m_log.Error("[ASSET DB]: Error storing item :" + e.Message);
203 } 199 }
204 } 200 }
205 } 201 }
206 202
207 /// <summary>
208 /// Update asset in m_database
209 /// </summary>
210 /// <param name="asset">the asset</param>
211 private void UpdateAsset(AssetBase asset)
212 {
213 string sql = @"UPDATE assets set id = @id, name = @name, description = @description, assetType = @assetType,
214 local = @local, temporary = @temporary, data = @data
215 WHERE id = @keyId;";
216
217 string assetName = asset.Name;
218 if (asset.Name.Length > 64)
219 {
220 assetName = asset.Name.Substring(0, 64);
221 m_log.Warn("[ASSET DB]: Name field truncated from " + asset.Name.Length + " to " + assetName.Length + " characters on update");
222 }
223
224 string assetDescription = asset.Description;
225 if (asset.Description.Length > 64)
226 {
227 assetDescription = asset.Description.Substring(0, 64);
228 m_log.Warn("[ASSET DB]: Description field truncated from " + asset.Description.Length + " to " + assetDescription.Length + " characters on update");
229 }
230
231 using (SqlConnection conn = new SqlConnection(m_connectionString))
232 using (SqlCommand command = new SqlCommand(sql, conn))
233 {
234 command.Parameters.Add(m_database.CreateParameter("id", asset.FullID));
235 command.Parameters.Add(m_database.CreateParameter("name", assetName));
236 command.Parameters.Add(m_database.CreateParameter("description", assetDescription));
237 command.Parameters.Add(m_database.CreateParameter("assetType", asset.Type));
238 command.Parameters.Add(m_database.CreateParameter("local", asset.Local));
239 command.Parameters.Add(m_database.CreateParameter("temporary", asset.Temporary));
240 command.Parameters.Add(m_database.CreateParameter("data", asset.Data));
241 command.Parameters.Add(m_database.CreateParameter("@keyId", asset.FullID));
242 conn.Open();
243 try
244 {
245 command.ExecuteNonQuery();
246 }
247 catch (Exception e)
248 {
249 m_log.Error(e.ToString());
250 }
251 }
252 }
253 203
254// Commented out since currently unused - this probably should be called in GetAsset() 204// Commented out since currently unused - this probably should be called in GetAsset()
255// private void UpdateAccessTime(AssetBase asset) 205// private void UpdateAccessTime(AssetBase asset)
@@ -295,26 +245,34 @@ namespace OpenSim.Data.MSSQL
295 public override List<AssetMetadata> FetchAssetMetadataSet(int start, int count) 245 public override List<AssetMetadata> FetchAssetMetadataSet(int start, int count)
296 { 246 {
297 List<AssetMetadata> retList = new List<AssetMetadata>(count); 247 List<AssetMetadata> retList = new List<AssetMetadata>(count);
298 string sql = @"SELECT (name,description,assetType,temporary,id), Row = ROW_NUMBER() 248 string sql = @"WITH OrderedAssets AS
299 OVER (ORDER BY (some column to order by)) 249 (
300 WHERE Row >= @Start AND Row < @Start + @Count"; 250 SELECT id, name, description, assetType, temporary, creatorid,
251 RowNumber = ROW_NUMBER() OVER (ORDER BY id)
252 FROM assets
253 )
254 SELECT *
255 FROM OrderedAssets
256 WHERE RowNumber BETWEEN @start AND @stop;";
301 257
302 using (SqlConnection conn = new SqlConnection(m_connectionString)) 258 using (SqlConnection conn = new SqlConnection(m_connectionString))
303 using (SqlCommand cmd = new SqlCommand(sql, conn)) 259 using (SqlCommand cmd = new SqlCommand(sql, conn))
304 { 260 {
305 cmd.Parameters.Add(m_database.CreateParameter("start", start)); 261 cmd.Parameters.Add(m_database.CreateParameter("start", start));
306 cmd.Parameters.Add(m_database.CreateParameter("count", count)); 262 cmd.Parameters.Add(m_database.CreateParameter("stop", start + count - 1));
307 conn.Open(); 263 conn.Open();
308 using (SqlDataReader reader = cmd.ExecuteReader()) 264 using (SqlDataReader reader = cmd.ExecuteReader())
309 { 265 {
310 while (reader.Read()) 266 while (reader.Read())
311 { 267 {
312 AssetMetadata metadata = new AssetMetadata(); 268 AssetMetadata metadata = new AssetMetadata();
313 metadata.FullID = new UUID((Guid)reader["id"]); 269 metadata.FullID = DBGuid.FromDB(reader["id"]);
314 metadata.Name = (string)reader["name"]; 270 metadata.Name = (string)reader["name"];
315 metadata.Description = (string)reader["description"]; 271 metadata.Description = (string)reader["description"];
316 metadata.Type = Convert.ToSByte(reader["assetType"]); 272 metadata.Type = Convert.ToSByte(reader["assetType"]);
317 metadata.Temporary = Convert.ToBoolean(reader["temporary"]); 273 metadata.Temporary = Convert.ToBoolean(reader["temporary"]);
274 metadata.CreatorID = (string)reader["creatorid"];
275 retList.Add(metadata);
318 } 276 }
319 } 277 }
320 } 278 }
diff --git a/OpenSim/Data/MSSQL/MSSQLEstateData.cs b/OpenSim/Data/MSSQL/MSSQLEstateData.cs
index 66931e2..80bf106 100644
--- a/OpenSim/Data/MSSQL/MSSQLEstateData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLEstateData.cs
@@ -37,7 +37,7 @@ using OpenSim.Region.Framework.Interfaces;
37 37
38namespace OpenSim.Data.MSSQL 38namespace OpenSim.Data.MSSQL
39{ 39{
40 public class MSSQLEstateData : IEstateDataStore 40 public class MSSQLEstateStore : IEstateDataStore
41 { 41 {
42 private const string _migrationStore = "EstateStore"; 42 private const string _migrationStore = "EstateStore";
43 43
diff --git a/OpenSim/Data/MSSQL/MSSQLInventoryData.cs b/OpenSim/Data/MSSQL/MSSQLInventoryData.cs
index 4815700..4d06377 100644
--- a/OpenSim/Data/MSSQL/MSSQLInventoryData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLInventoryData.cs
@@ -111,6 +111,9 @@ namespace OpenSim.Data.MSSQL
111 /// <returns>A list of folder objects</returns> 111 /// <returns>A list of folder objects</returns>
112 public List<InventoryFolderBase> getUserRootFolders(UUID user) 112 public List<InventoryFolderBase> getUserRootFolders(UUID user)
113 { 113 {
114 if (user == UUID.Zero)
115 return new List<InventoryFolderBase>();
116
114 return getInventoryFolders(UUID.Zero, user); 117 return getInventoryFolders(UUID.Zero, user);
115 } 118 }
116 119
@@ -184,7 +187,19 @@ namespace OpenSim.Data.MSSQL
184 //Note maybe change this to use a Dataset that loading in all folders of a user and then go throw it that way. 187 //Note maybe change this to use a Dataset that loading in all folders of a user and then go throw it that way.
185 //Note this is changed so it opens only one connection to the database and not everytime it wants to get data. 188 //Note this is changed so it opens only one connection to the database and not everytime it wants to get data.
186 189
190 /* NOTE: the implementation below is very inefficient (makes a separate request to get subfolders for
191 * every found folder, recursively). Inventory code for other DBs has been already rewritten to get ALL
192 * inventory for a specific user at once.
193 *
194 * Meanwhile, one little thing is corrected: getFolderHierarchy(UUID.Zero) doesn't make sense and should never
195 * be used, so check for that and return an empty list.
196 */
197
187 List<InventoryFolderBase> folders = new List<InventoryFolderBase>(); 198 List<InventoryFolderBase> folders = new List<InventoryFolderBase>();
199
200 if (parentID == UUID.Zero)
201 return folders;
202
188 string sql = "SELECT * FROM inventoryfolders WHERE parentFolderID = @parentID"; 203 string sql = "SELECT * FROM inventoryfolders WHERE parentFolderID = @parentID";
189 using (SqlConnection conn = new SqlConnection(m_connectionString)) 204 using (SqlConnection conn = new SqlConnection(m_connectionString))
190 using (SqlCommand cmd = new SqlCommand(sql, conn)) 205 using (SqlCommand cmd = new SqlCommand(sql, conn))
@@ -249,13 +264,12 @@ namespace OpenSim.Data.MSSQL
249 /// <param name="folder">Folder to update</param> 264 /// <param name="folder">Folder to update</param>
250 public void updateInventoryFolder(InventoryFolderBase folder) 265 public void updateInventoryFolder(InventoryFolderBase folder)
251 { 266 {
252 string sql = @"UPDATE inventoryfolders SET folderID = @folderID, 267 string sql = @"UPDATE inventoryfolders SET agentID = @agentID,
253 agentID = @agentID,
254 parentFolderID = @parentFolderID, 268 parentFolderID = @parentFolderID,
255 folderName = @folderName, 269 folderName = @folderName,
256 type = @type, 270 type = @type,
257 version = @version 271 version = @version
258 WHERE folderID = @keyFolderID"; 272 WHERE folderID = @folderID";
259 273
260 string folderName = folder.Name; 274 string folderName = folder.Name;
261 if (folderName.Length > 64) 275 if (folderName.Length > 64)
@@ -272,7 +286,6 @@ namespace OpenSim.Data.MSSQL
272 cmd.Parameters.Add(database.CreateParameter("folderName", folderName)); 286 cmd.Parameters.Add(database.CreateParameter("folderName", folderName));
273 cmd.Parameters.Add(database.CreateParameter("type", folder.Type)); 287 cmd.Parameters.Add(database.CreateParameter("type", folder.Type));
274 cmd.Parameters.Add(database.CreateParameter("version", folder.Version)); 288 cmd.Parameters.Add(database.CreateParameter("version", folder.Version));
275 cmd.Parameters.Add(database.CreateParameter("@keyFolderID", folder.ID));
276 conn.Open(); 289 conn.Open();
277 try 290 try
278 { 291 {
@@ -296,7 +309,7 @@ namespace OpenSim.Data.MSSQL
296 using (SqlCommand cmd = new SqlCommand(sql, conn)) 309 using (SqlCommand cmd = new SqlCommand(sql, conn))
297 { 310 {
298 cmd.Parameters.Add(database.CreateParameter("parentFolderID", folder.ParentID)); 311 cmd.Parameters.Add(database.CreateParameter("parentFolderID", folder.ParentID));
299 cmd.Parameters.Add(database.CreateParameter("@folderID", folder.ID)); 312 cmd.Parameters.Add(database.CreateParameter("folderID", folder.ID));
300 conn.Open(); 313 conn.Open();
301 try 314 try
302 { 315 {
@@ -489,8 +502,7 @@ namespace OpenSim.Data.MSSQL
489 /// <param name="item">Inventory item to update</param> 502 /// <param name="item">Inventory item to update</param>
490 public void updateInventoryItem(InventoryItemBase item) 503 public void updateInventoryItem(InventoryItemBase item)
491 { 504 {
492 string sql = @"UPDATE inventoryitems SET inventoryID = @inventoryID, 505 string sql = @"UPDATE inventoryitems SET assetID = @assetID,
493 assetID = @assetID,
494 assetType = @assetType, 506 assetType = @assetType,
495 parentFolderID = @parentFolderID, 507 parentFolderID = @parentFolderID,
496 avatarID = @avatarID, 508 avatarID = @avatarID,
@@ -502,13 +514,14 @@ namespace OpenSim.Data.MSSQL
502 creatorID = @creatorID, 514 creatorID = @creatorID,
503 inventoryBasePermissions = @inventoryBasePermissions, 515 inventoryBasePermissions = @inventoryBasePermissions,
504 inventoryEveryOnePermissions = @inventoryEveryOnePermissions, 516 inventoryEveryOnePermissions = @inventoryEveryOnePermissions,
517 inventoryGroupPermissions = @inventoryGroupPermissions,
505 salePrice = @salePrice, 518 salePrice = @salePrice,
506 saleType = @saleType, 519 saleType = @saleType,
507 creationDate = @creationDate, 520 creationDate = @creationDate,
508 groupID = @groupID, 521 groupID = @groupID,
509 groupOwned = @groupOwned, 522 groupOwned = @groupOwned,
510 flags = @flags 523 flags = @flags
511 WHERE inventoryID = @keyInventoryID"; 524 WHERE inventoryID = @inventoryID";
512 525
513 string itemName = item.Name; 526 string itemName = item.Name;
514 if (item.Name.Length > 64) 527 if (item.Name.Length > 64)
@@ -537,16 +550,16 @@ namespace OpenSim.Data.MSSQL
537 command.Parameters.Add(database.CreateParameter("inventoryNextPermissions", item.NextPermissions)); 550 command.Parameters.Add(database.CreateParameter("inventoryNextPermissions", item.NextPermissions));
538 command.Parameters.Add(database.CreateParameter("inventoryCurrentPermissions", item.CurrentPermissions)); 551 command.Parameters.Add(database.CreateParameter("inventoryCurrentPermissions", item.CurrentPermissions));
539 command.Parameters.Add(database.CreateParameter("invType", item.InvType)); 552 command.Parameters.Add(database.CreateParameter("invType", item.InvType));
540 command.Parameters.Add(database.CreateParameter("creatorID", item.CreatorIdAsUuid)); 553 command.Parameters.Add(database.CreateParameter("creatorID", item.CreatorId));
541 command.Parameters.Add(database.CreateParameter("inventoryBasePermissions", item.BasePermissions)); 554 command.Parameters.Add(database.CreateParameter("inventoryBasePermissions", item.BasePermissions));
542 command.Parameters.Add(database.CreateParameter("inventoryEveryOnePermissions", item.EveryOnePermissions)); 555 command.Parameters.Add(database.CreateParameter("inventoryEveryOnePermissions", item.EveryOnePermissions));
556 command.Parameters.Add(database.CreateParameter("inventoryGroupPermissions", item.GroupPermissions));
543 command.Parameters.Add(database.CreateParameter("salePrice", item.SalePrice)); 557 command.Parameters.Add(database.CreateParameter("salePrice", item.SalePrice));
544 command.Parameters.Add(database.CreateParameter("saleType", item.SaleType)); 558 command.Parameters.Add(database.CreateParameter("saleType", item.SaleType));
545 command.Parameters.Add(database.CreateParameter("creationDate", item.CreationDate)); 559 command.Parameters.Add(database.CreateParameter("creationDate", item.CreationDate));
546 command.Parameters.Add(database.CreateParameter("groupID", item.GroupID)); 560 command.Parameters.Add(database.CreateParameter("groupID", item.GroupID));
547 command.Parameters.Add(database.CreateParameter("groupOwned", item.GroupOwned)); 561 command.Parameters.Add(database.CreateParameter("groupOwned", item.GroupOwned));
548 command.Parameters.Add(database.CreateParameter("flags", item.Flags)); 562 command.Parameters.Add(database.CreateParameter("flags", item.Flags));
549 command.Parameters.Add(database.CreateParameter("keyInventoryID", item.ID));
550 conn.Open(); 563 conn.Open();
551 try 564 try
552 { 565 {
@@ -732,9 +745,9 @@ namespace OpenSim.Data.MSSQL
732 try 745 try
733 { 746 {
734 InventoryFolderBase folder = new InventoryFolderBase(); 747 InventoryFolderBase folder = new InventoryFolderBase();
735 folder.Owner = new UUID((Guid)reader["agentID"]); 748 folder.Owner = DBGuid.FromDB(reader["agentID"]);
736 folder.ParentID = new UUID((Guid)reader["parentFolderID"]); 749 folder.ParentID = DBGuid.FromDB(reader["parentFolderID"]);
737 folder.ID = new UUID((Guid)reader["folderID"]); 750 folder.ID = DBGuid.FromDB(reader["folderID"]);
738 folder.Name = (string)reader["folderName"]; 751 folder.Name = (string)reader["folderName"];
739 folder.Type = (short)reader["type"]; 752 folder.Type = (short)reader["type"];
740 folder.Version = Convert.ToUInt16(reader["version"]); 753 folder.Version = Convert.ToUInt16(reader["version"]);
@@ -760,24 +773,24 @@ namespace OpenSim.Data.MSSQL
760 { 773 {
761 InventoryItemBase item = new InventoryItemBase(); 774 InventoryItemBase item = new InventoryItemBase();
762 775
763 item.ID = new UUID((Guid)reader["inventoryID"]); 776 item.ID = DBGuid.FromDB(reader["inventoryID"]);
764 item.AssetID = new UUID((Guid)reader["assetID"]); 777 item.AssetID = DBGuid.FromDB(reader["assetID"]);
765 item.AssetType = Convert.ToInt32(reader["assetType"].ToString()); 778 item.AssetType = Convert.ToInt32(reader["assetType"].ToString());
766 item.Folder = new UUID((Guid)reader["parentFolderID"]); 779 item.Folder = DBGuid.FromDB(reader["parentFolderID"]);
767 item.Owner = new UUID((Guid)reader["avatarID"]); 780 item.Owner = DBGuid.FromDB(reader["avatarID"]);
768 item.Name = reader["inventoryName"].ToString(); 781 item.Name = reader["inventoryName"].ToString();
769 item.Description = reader["inventoryDescription"].ToString(); 782 item.Description = reader["inventoryDescription"].ToString();
770 item.NextPermissions = Convert.ToUInt32(reader["inventoryNextPermissions"]); 783 item.NextPermissions = Convert.ToUInt32(reader["inventoryNextPermissions"]);
771 item.CurrentPermissions = Convert.ToUInt32(reader["inventoryCurrentPermissions"]); 784 item.CurrentPermissions = Convert.ToUInt32(reader["inventoryCurrentPermissions"]);
772 item.InvType = Convert.ToInt32(reader["invType"].ToString()); 785 item.InvType = Convert.ToInt32(reader["invType"].ToString());
773 item.CreatorId = ((Guid)reader["creatorID"]).ToString(); 786 item.CreatorId = reader["creatorID"].ToString();
774 item.BasePermissions = Convert.ToUInt32(reader["inventoryBasePermissions"]); 787 item.BasePermissions = Convert.ToUInt32(reader["inventoryBasePermissions"]);
775 item.EveryOnePermissions = Convert.ToUInt32(reader["inventoryEveryOnePermissions"]); 788 item.EveryOnePermissions = Convert.ToUInt32(reader["inventoryEveryOnePermissions"]);
776 item.GroupPermissions = Convert.ToUInt32(reader["inventoryGroupPermissions"]); 789 item.GroupPermissions = Convert.ToUInt32(reader["inventoryGroupPermissions"]);
777 item.SalePrice = Convert.ToInt32(reader["salePrice"]); 790 item.SalePrice = Convert.ToInt32(reader["salePrice"]);
778 item.SaleType = Convert.ToByte(reader["saleType"]); 791 item.SaleType = Convert.ToByte(reader["saleType"]);
779 item.CreationDate = Convert.ToInt32(reader["creationDate"]); 792 item.CreationDate = Convert.ToInt32(reader["creationDate"]);
780 item.GroupID = new UUID((Guid)reader["groupID"]); 793 item.GroupID = DBGuid.FromDB(reader["groupID"]);
781 item.GroupOwned = Convert.ToBoolean(reader["groupOwned"]); 794 item.GroupOwned = Convert.ToBoolean(reader["groupOwned"]);
782 item.Flags = Convert.ToUInt32(reader["flags"]); 795 item.Flags = Convert.ToUInt32(reader["flags"]);
783 796
diff --git a/OpenSim/Data/MSSQL/Resources/AssetStore.migrations b/OpenSim/Data/MSSQL/Resources/AssetStore.migrations
index beb82b9..8664ce9 100644
--- a/OpenSim/Data/MSSQL/Resources/AssetStore.migrations
+++ b/OpenSim/Data/MSSQL/Resources/AssetStore.migrations
@@ -97,4 +97,10 @@ COMMIT
97 97
98DELETE FROM assets WHERE id = 'dc4b9f0b-d008-45c6-96a4-01dd947ac621'; 98DELETE FROM assets WHERE id = 'dc4b9f0b-d008-45c6-96a4-01dd947ac621';
99 99
100:VERSION 6
100 101
102ALTER TABLE assets ADD asset_flags INTEGER NOT NULL DEFAULT 0;
103
104:VERSION 7
105
106alter table assets add creatorid varchar(36) not null default '';
diff --git a/OpenSim/Data/MSSQL/Resources/AvatarAppearance.sql b/OpenSim/Data/MSSQL/Resources/AvatarAppearance.sql
deleted file mode 100644
index e69de29..0000000
--- a/OpenSim/Data/MSSQL/Resources/AvatarAppearance.sql
+++ /dev/null
diff --git a/OpenSim/Data/MSSQL/Resources/CreateAssetsTable.sql b/OpenSim/Data/MSSQL/Resources/CreateAssetsTable.sql
deleted file mode 100644
index e69de29..0000000
--- a/OpenSim/Data/MSSQL/Resources/CreateAssetsTable.sql
+++ /dev/null
diff --git a/OpenSim/Data/MSSQL/Resources/CreateFoldersTable.sql b/OpenSim/Data/MSSQL/Resources/CreateFoldersTable.sql
deleted file mode 100644
index e69de29..0000000
--- a/OpenSim/Data/MSSQL/Resources/CreateFoldersTable.sql
+++ /dev/null
diff --git a/OpenSim/Data/MSSQL/Resources/CreateItemsTable.sql b/OpenSim/Data/MSSQL/Resources/CreateItemsTable.sql
deleted file mode 100644
index e69de29..0000000
--- a/OpenSim/Data/MSSQL/Resources/CreateItemsTable.sql
+++ /dev/null
diff --git a/OpenSim/Data/MSSQL/Resources/CreateUserFriendsTable.sql b/OpenSim/Data/MSSQL/Resources/CreateUserFriendsTable.sql
deleted file mode 100644
index e69de29..0000000
--- a/OpenSim/Data/MSSQL/Resources/CreateUserFriendsTable.sql
+++ /dev/null
diff --git a/OpenSim/Data/MSSQL/Resources/InventoryStore.migrations b/OpenSim/Data/MSSQL/Resources/InventoryStore.migrations
index cd5dfdc..e2a8d57 100644
--- a/OpenSim/Data/MSSQL/Resources/InventoryStore.migrations
+++ b/OpenSim/Data/MSSQL/Resources/InventoryStore.migrations
@@ -171,4 +171,74 @@ CREATE NONCLUSTERED INDEX folder ON dbo.inventoryitems
171 171
172COMMIT 172COMMIT
173 173
174:VERSION 5
175
176# It would be totally crazy to have to recreate the whole table just to change one column type,
177# just because MS SQL treats each DEFAULT as a constraint object that must be dropped
178# before anything can be done to the column. Since all defaults here are unnamed, there is
179# no easy way to drop them! The hairy piece of code below removes all DEFAULT constraints
180# from InventoryItems.
181
182# SO: anything that's NULLable is by default NULL, so please don't declare DEFAULT(NULL),
183# they do nothing but prevent changes to the columns. If you really
184# need to have DEFAULTs or other constraints, give them names so they can be dropped when needed!
185
186BEGIN TRANSACTION
187DECLARE @nm varchar(80);
188DECLARE x CURSOR LOCAL FORWARD_ONLY READ_ONLY
189 FOR SELECT name FROM sys.default_constraints where parent_object_id = OBJECT_ID('inventoryitems');
190OPEN x;
191FETCH NEXT FROM x INTO @nm;
192WHILE @@FETCH_STATUS = 0
193BEGIN
194 EXEC('alter table inventoryitems drop ' + @nm);
195 FETCH NEXT FROM x INTO @nm;
196END
197CLOSE x
198DEALLOCATE x
199COMMIT
200
201# all DEFAULTs dropped!
202
203:GO
204
205BEGIN TRANSACTION
206
207# Restoring defaults:
208# NOTE: [inventoryID] does NOT need one: it's NOT NULL PK and a unique Guid must be provided every time anyway!
209
210alter table inventoryitems
211 add constraint def_baseperm default 0 for inventoryBasePermissions
212alter table inventoryitems
213 add constraint def_allperm default 0 for inventoryEveryOnePermissions
214alter table inventoryitems
215 add constraint def_grpperm default 0 for inventoryGroupPermissions
216
217COMMIT
218
219:VERSION 7
220
221BEGIN TRANSACTION
222
223# CreatorID goes back to VARCHAR(36) (???)
224
225exec sp_rename 'inventoryitems.CreatorID', 'cr_old', 'COLUMN'
226
227:GO
228
229alter table inventoryitems
230 add creatorID varchar(36) NULL
231
232:GO
233
234update inventoryitems set creatorID = CONVERT(VARCHAR(36), cr_old)
235
236alter table inventoryitems
237 drop column cr_old
238
239COMMIT
240
241
242
243
174 244
diff --git a/OpenSim/Data/MSSQL/Resources/Mssql-agents.sql b/OpenSim/Data/MSSQL/Resources/Mssql-agents.sql
deleted file mode 100644
index e69de29..0000000
--- a/OpenSim/Data/MSSQL/Resources/Mssql-agents.sql
+++ /dev/null
diff --git a/OpenSim/Data/MSSQL/Resources/Mssql-logs.sql b/OpenSim/Data/MSSQL/Resources/Mssql-logs.sql
deleted file mode 100644
index e69de29..0000000
--- a/OpenSim/Data/MSSQL/Resources/Mssql-logs.sql
+++ /dev/null
diff --git a/OpenSim/Data/MSSQL/Resources/Mssql-regions.sql b/OpenSim/Data/MSSQL/Resources/Mssql-regions.sql
deleted file mode 100644
index e69de29..0000000
--- a/OpenSim/Data/MSSQL/Resources/Mssql-regions.sql
+++ /dev/null
diff --git a/OpenSim/Data/MSSQL/Resources/Mssql-users.sql b/OpenSim/Data/MSSQL/Resources/Mssql-users.sql
deleted file mode 100644
index e69de29..0000000
--- a/OpenSim/Data/MSSQL/Resources/Mssql-users.sql
+++ /dev/null
diff --git a/OpenSim/Data/MySQL/Resources/EstateStore.migrations b/OpenSim/Data/MySQL/Resources/EstateStore.migrations
new file mode 100644
index 0000000..df82a2e
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/EstateStore.migrations
@@ -0,0 +1,81 @@
1:VERSION 13
2
3# The estate migrations used to be in Region store
4# here they will do nothing (bad) if the tables are already there,
5# just update the store version.
6
7BEGIN;
8
9CREATE TABLE IF NOT EXISTS `estate_managers` (
10 `EstateID` int(10) unsigned NOT NULL,
11 `uuid` char(36) NOT NULL,
12 KEY `EstateID` (`EstateID`)
13) ENGINE=InnoDB;
14
15CREATE TABLE IF NOT EXISTS `estate_groups` (
16 `EstateID` int(10) unsigned NOT NULL,
17 `uuid` char(36) NOT NULL,
18 KEY `EstateID` (`EstateID`)
19) ENGINE=InnoDB;
20
21CREATE TABLE IF NOT EXISTS `estate_users` (
22 `EstateID` int(10) unsigned NOT NULL,
23 `uuid` char(36) NOT NULL,
24 KEY `EstateID` (`EstateID`)
25) ENGINE=InnoDB;
26
27CREATE TABLE IF NOT EXISTS `estateban` (
28 `EstateID` int(10) unsigned NOT NULL,
29 `bannedUUID` varchar(36) NOT NULL,
30 `bannedIp` varchar(16) NOT NULL,
31 `bannedIpHostMask` varchar(16) NOT NULL,
32 `bannedNameMask` varchar(64) default NULL,
33 KEY `estateban_EstateID` (`EstateID`)
34) ENGINE=InnoDB;
35
36CREATE TABLE IF NOT EXISTS `estate_settings` (
37 `EstateID` int(10) unsigned NOT NULL auto_increment,
38 `EstateName` varchar(64) default NULL,
39 `AbuseEmailToEstateOwner` tinyint(4) NOT NULL,
40 `DenyAnonymous` tinyint(4) NOT NULL,
41 `ResetHomeOnTeleport` tinyint(4) NOT NULL,
42 `FixedSun` tinyint(4) NOT NULL,
43 `DenyTransacted` tinyint(4) NOT NULL,
44 `BlockDwell` tinyint(4) NOT NULL,
45 `DenyIdentified` tinyint(4) NOT NULL,
46 `AllowVoice` tinyint(4) NOT NULL,
47 `UseGlobalTime` tinyint(4) NOT NULL,
48 `PricePerMeter` int(11) NOT NULL,
49 `TaxFree` tinyint(4) NOT NULL,
50 `AllowDirectTeleport` tinyint(4) NOT NULL,
51 `RedirectGridX` int(11) NOT NULL,
52 `RedirectGridY` int(11) NOT NULL,
53 `ParentEstateID` int(10) unsigned NOT NULL,
54 `SunPosition` double NOT NULL,
55 `EstateSkipScripts` tinyint(4) NOT NULL,
56 `BillableFactor` float NOT NULL,
57 `PublicAccess` tinyint(4) NOT NULL,
58 `AbuseEmail` varchar(255) not null,
59 `EstateOwner` varchar(36) not null,
60 `DenyMinors` tinyint not null,
61
62 PRIMARY KEY (`EstateID`)
63) ENGINE=InnoDB AUTO_INCREMENT=100;
64
65CREATE TABLE IF NOT EXISTS `estate_map` (
66 `RegionID` char(36) NOT NULL default '00000000-0000-0000-0000-000000000000',
67 `EstateID` int(11) NOT NULL,
68 PRIMARY KEY (`RegionID`),
69 KEY `EstateID` (`EstateID`)
70) ENGINE=InnoDB;
71
72COMMIT;
73
74:VERSION 32 #--------------------- (moved from RegionStore migr, just in case)
75
76BEGIN;
77ALTER TABLE estate_settings AUTO_INCREMENT = 100;
78COMMIT;
79
80
81
diff --git a/OpenSim/Data/MySQL/Resources/RegionStore.migrations b/OpenSim/Data/MySQL/Resources/RegionStore.migrations
index baeeedd..d8a279d 100644
--- a/OpenSim/Data/MySQL/Resources/RegionStore.migrations
+++ b/OpenSim/Data/MySQL/Resources/RegionStore.migrations
@@ -386,84 +386,6 @@ CREATE TABLE `regionsettings` (
386 PRIMARY KEY (`regionUUID`) 386 PRIMARY KEY (`regionUUID`)
387) ENGINE=InnoDB; 387) ENGINE=InnoDB;
388 388
389CREATE TABLE `estate_managers` (
390 `EstateID` int(10) unsigned NOT NULL,
391 `uuid` char(36) NOT NULL,
392 KEY `EstateID` (`EstateID`)
393) ENGINE=InnoDB;
394
395CREATE TABLE `estate_groups` (
396 `EstateID` int(10) unsigned NOT NULL,
397 `uuid` char(36) NOT NULL,
398 KEY `EstateID` (`EstateID`)
399) ENGINE=InnoDB;
400
401CREATE TABLE `estate_users` (
402 `EstateID` int(10) unsigned NOT NULL,
403 `uuid` char(36) NOT NULL,
404 KEY `EstateID` (`EstateID`)
405) ENGINE=InnoDB;
406
407CREATE TABLE `estateban` (
408 `EstateID` int(10) unsigned NOT NULL,
409 `bannedUUID` varchar(36) NOT NULL,
410 `bannedIp` varchar(16) NOT NULL,
411 `bannedIpHostMask` varchar(16) NOT NULL,
412 `bannedNameMask` varchar(64) default NULL,
413 KEY `estateban_EstateID` (`EstateID`)
414) ENGINE=InnoDB;
415
416CREATE TABLE `estate_settings` (
417 `EstateID` int(10) unsigned NOT NULL auto_increment,
418 `EstateName` varchar(64) default NULL,
419 `AbuseEmailToEstateOwner` tinyint(4) NOT NULL,
420 `DenyAnonymous` tinyint(4) NOT NULL,
421 `ResetHomeOnTeleport` tinyint(4) NOT NULL,
422 `FixedSun` tinyint(4) NOT NULL,
423 `DenyTransacted` tinyint(4) NOT NULL,
424 `BlockDwell` tinyint(4) NOT NULL,
425 `DenyIdentified` tinyint(4) NOT NULL,
426 `AllowVoice` tinyint(4) NOT NULL,
427 `UseGlobalTime` tinyint(4) NOT NULL,
428 `PricePerMeter` int(11) NOT NULL,
429 `TaxFree` tinyint(4) NOT NULL,
430 `AllowDirectTeleport` tinyint(4) NOT NULL,
431 `RedirectGridX` int(11) NOT NULL,
432 `RedirectGridY` int(11) NOT NULL,
433 `ParentEstateID` int(10) unsigned NOT NULL,
434 `SunPosition` double NOT NULL,
435 `EstateSkipScripts` tinyint(4) NOT NULL,
436 `BillableFactor` float NOT NULL,
437 `PublicAccess` tinyint(4) NOT NULL,
438 PRIMARY KEY (`EstateID`)
439) ENGINE=InnoDB AUTO_INCREMENT=100;
440
441CREATE TABLE `estate_map` (
442 `RegionID` char(36) NOT NULL default '00000000-0000-0000-0000-000000000000',
443 `EstateID` int(11) NOT NULL,
444 PRIMARY KEY (`RegionID`),
445 KEY `EstateID` (`EstateID`)
446) ENGINE=InnoDB;
447
448commit;
449
450:VERSION 14 #---------------------
451
452begin;
453
454alter table estate_settings add column AbuseEmail varchar(255) not null;
455
456alter table estate_settings add column EstateOwner varchar(36) not null;
457
458commit;
459
460
461:VERSION 15 #---------------------
462
463begin;
464
465alter table estate_settings add column DenyMinors tinyint not null;
466
467commit; 389commit;
468 390
469:VERSION 16 #--------------------- 391:VERSION 16 #---------------------
@@ -795,12 +717,6 @@ ALTER TABLE regionsettings ADD COLUMN loaded_creation_datetime int unsigned NOT
795 717
796COMMIT; 718COMMIT;
797 719
798:VERSION 32 #---------------------
799
800BEGIN;
801ALTER TABLE estate_settings AUTO_INCREMENT = 100;
802COMMIT;
803
804:VERSION 33 #--------------------- 720:VERSION 33 #---------------------
805 721
806BEGIN; 722BEGIN;
diff --git a/OpenSim/Data/MySQL/Tests/MySQLAssetTest.cs b/OpenSim/Data/MySQL/Tests/MySQLAssetTest.cs
deleted file mode 100644
index a46fdf8..0000000
--- a/OpenSim/Data/MySQL/Tests/MySQLAssetTest.cs
+++ /dev/null
@@ -1,92 +0,0 @@
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 OpenSimulator 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
28using System;
29using NUnit.Framework;
30using OpenSim.Data.Tests;
31using log4net;
32using System.Reflection;
33using OpenSim.Tests.Common;
34using MySql.Data.MySqlClient;
35
36namespace OpenSim.Data.MySQL.Tests
37{
38 [TestFixture, DatabaseTest]
39 public class MySQLAssetTest : BasicAssetTest
40 {
41 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42 public string file;
43 private string m_connectionString;
44 public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;";
45
46 [TestFixtureSetUp]
47 public void Init()
48 {
49 SuperInit();
50 // If we manage to connect to the database with the user
51 // and password above it is our test database, and run
52 // these tests. If anything goes wrong, ignore these
53 // tests.
54 try
55 {
56 db = new MySQLAssetData();
57 db.Initialise(connect);
58 }
59 catch (Exception e)
60 {
61 m_log.Error(e.ToString());
62 Assert.Ignore();
63 }
64 }
65
66 [TestFixtureTearDown]
67 public void Cleanup()
68 {
69 if (db != null)
70 {
71 db.Dispose();
72 }
73 ExecuteSql("drop table migrations");
74 ExecuteSql("drop table assets");
75 }
76
77 /// <summary>
78 /// Execute a MySqlCommand
79 /// </summary>
80 /// <param name="sql">sql string to execute</param>
81 private void ExecuteSql(string sql)
82 {
83 using (MySqlConnection dbcon = new MySqlConnection(connect))
84 {
85 dbcon.Open();
86
87 MySqlCommand cmd = new MySqlCommand(sql, dbcon);
88 cmd.ExecuteNonQuery();
89 }
90 }
91 }
92}
diff --git a/OpenSim/Data/MySQL/Tests/MySQLEstateTest.cs b/OpenSim/Data/MySQL/Tests/MySQLEstateTest.cs
deleted file mode 100644
index 01afcae..0000000
--- a/OpenSim/Data/MySQL/Tests/MySQLEstateTest.cs
+++ /dev/null
@@ -1,116 +0,0 @@
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 OpenSimulator 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
28using System;
29using NUnit.Framework;
30using OpenSim.Data.Tests;
31using log4net;
32using System.Reflection;
33using OpenSim.Tests.Common;
34using MySql.Data.MySqlClient;
35
36
37namespace OpenSim.Data.MySQL.Tests
38{
39 [TestFixture, DatabaseTest]
40 public class MySQLEstateTest : BasicEstateTest
41 {
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43 public string file;
44 public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;";
45
46 [TestFixtureSetUp]
47 public void Init()
48 {
49 SuperInit();
50 // If we manage to connect to the database with the user
51 // and password above it is our test database, and run
52 // these tests. If anything goes wrong, ignore these
53 // tests.
54 try
55 {
56 // clear db incase to ensure we are in a clean state
57 ClearDB();
58
59 regionDb = new MySQLDataStore();
60 regionDb.Initialise(connect);
61 db = new MySQLEstateStore();
62 db.Initialise(connect);
63 }
64 catch (Exception e)
65 {
66 m_log.Error("Exception {0}", e);
67 Assert.Ignore();
68 }
69 }
70
71 [TestFixtureTearDown]
72 public void Cleanup()
73 {
74 if (regionDb != null)
75 {
76 regionDb.Dispose();
77 }
78 ClearDB();
79 }
80
81 private void ClearDB()
82 {
83 // if a new table is added, it has to be dropped here
84 ExecuteSql("drop table if exists migrations");
85 ExecuteSql("drop table if exists prims");
86 ExecuteSql("drop table if exists primshapes");
87 ExecuteSql("drop table if exists primitems");
88 ExecuteSql("drop table if exists terrain");
89 ExecuteSql("drop table if exists land");
90 ExecuteSql("drop table if exists landaccesslist");
91 ExecuteSql("drop table if exists regionban");
92 ExecuteSql("drop table if exists regionsettings");
93 ExecuteSql("drop table if exists estate_managers");
94 ExecuteSql("drop table if exists estate_groups");
95 ExecuteSql("drop table if exists estate_users");
96 ExecuteSql("drop table if exists estateban");
97 ExecuteSql("drop table if exists estate_settings");
98 ExecuteSql("drop table if exists estate_map");
99 }
100
101 /// <summary>
102 /// Execute a MySqlCommand
103 /// </summary>
104 /// <param name="sql">sql string to execute</param>
105 private void ExecuteSql(string sql)
106 {
107 using (MySqlConnection dbcon = new MySqlConnection(connect))
108 {
109 dbcon.Open();
110
111 MySqlCommand cmd = new MySqlCommand(sql, dbcon);
112 cmd.ExecuteNonQuery();
113 }
114 }
115 }
116}
diff --git a/OpenSim/Data/MySQL/Tests/MySQLInventoryTest.cs b/OpenSim/Data/MySQL/Tests/MySQLInventoryTest.cs
deleted file mode 100644
index 4575493..0000000
--- a/OpenSim/Data/MySQL/Tests/MySQLInventoryTest.cs
+++ /dev/null
@@ -1,99 +0,0 @@
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 OpenSimulator 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
28using System;
29using NUnit.Framework;
30using OpenSim.Data.Tests;
31using log4net;
32using System.Reflection;
33using OpenSim.Tests.Common;
34using MySql.Data.MySqlClient;
35
36
37namespace OpenSim.Data.MySQL.Tests
38{
39 [TestFixture, DatabaseTest]
40 public class MySQLInventoryTest : BasicInventoryTest
41 {
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43 public string file;
44 public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;";
45
46 [TestFixtureSetUp]
47 public void Init()
48 {
49 SuperInit();
50 // If we manage to connect to the database with the user
51 // and password above it is our test database, and run
52 // these tests. If anything goes wrong, ignore these
53 // tests.
54 try
55 {
56 DropTables();
57 db = new MySQLInventoryData();
58 db.Initialise(connect);
59 }
60 catch (Exception e)
61 {
62 m_log.Error("Exception {0}", e);
63 Assert.Ignore();
64 }
65 }
66
67 [TestFixtureTearDown]
68 public void Cleanup()
69 {
70 if (db != null)
71 {
72 db.Dispose();
73 }
74 DropTables();
75 }
76
77 private void DropTables()
78 {
79 ExecuteSql("drop table IF EXISTS inventoryitems");
80 ExecuteSql("drop table IF EXISTS inventoryfolders");
81 ExecuteSql("drop table IF EXISTS migrations");
82 }
83
84 /// <summary>
85 /// Execute a MySqlCommand
86 /// </summary>
87 /// <param name="sql">sql string to execute</param>
88 private void ExecuteSql(string sql)
89 {
90 using (MySqlConnection dbcon = new MySqlConnection(connect))
91 {
92 dbcon.Open();
93
94 MySqlCommand cmd = new MySqlCommand(sql, dbcon);
95 cmd.ExecuteNonQuery();
96 }
97 }
98 }
99}
diff --git a/OpenSim/Data/MySQL/Tests/MySQLRegionTest.cs b/OpenSim/Data/MySQL/Tests/MySQLRegionTest.cs
deleted file mode 100644
index e7e57e4..0000000
--- a/OpenSim/Data/MySQL/Tests/MySQLRegionTest.cs
+++ /dev/null
@@ -1,112 +0,0 @@
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 OpenSimulator 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
28using System;
29using NUnit.Framework;
30using OpenSim.Data.Tests;
31using log4net;
32using System.Reflection;
33using OpenSim.Tests.Common;
34using MySql.Data.MySqlClient;
35
36namespace OpenSim.Data.MySQL.Tests
37{
38 [TestFixture, DatabaseTest]
39 public class MySQLRegionTest : BasicRegionTest
40 {
41 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42 public string file;
43 public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;";
44
45 [TestFixtureSetUp]
46 public void Init()
47 {
48 SuperInit();
49 // If we manage to connect to the database with the user
50 // and password above it is our test database, and run
51 // these tests. If anything goes wrong, ignore these
52 // tests.
53 try
54 {
55 // this is important in case a previous run ended badly
56 ClearDB();
57
58 db = new MySQLDataStore();
59 db.Initialise(connect);
60 }
61 catch (Exception e)
62 {
63 m_log.Error("Exception {0}", e);
64 Assert.Ignore();
65 }
66 }
67
68 [TestFixtureTearDown]
69 public void Cleanup()
70 {
71 if (db != null)
72 {
73 db.Dispose();
74 }
75 ClearDB();
76 }
77
78 private void ClearDB()
79 {
80 ExecuteSql("drop table if exists migrations");
81 ExecuteSql("drop table if exists prims");
82 ExecuteSql("drop table if exists primshapes");
83 ExecuteSql("drop table if exists primitems");
84 ExecuteSql("drop table if exists terrain");
85 ExecuteSql("drop table if exists land");
86 ExecuteSql("drop table if exists landaccesslist");
87 ExecuteSql("drop table if exists regionban");
88 ExecuteSql("drop table if exists regionsettings");
89 ExecuteSql("drop table if exists estate_managers");
90 ExecuteSql("drop table if exists estate_groups");
91 ExecuteSql("drop table if exists estate_users");
92 ExecuteSql("drop table if exists estateban");
93 ExecuteSql("drop table if exists estate_settings");
94 ExecuteSql("drop table if exists estate_map");
95 }
96
97 /// <summary>
98 /// Execute a MySqlCommand
99 /// </summary>
100 /// <param name="sql">sql string to execute</param>
101 private void ExecuteSql(string sql)
102 {
103 using (MySqlConnection dbcon = new MySqlConnection(connect))
104 {
105 dbcon.Open();
106
107 MySqlCommand cmd = new MySqlCommand(sql, dbcon);
108 cmd.ExecuteNonQuery();
109 }
110 }
111 }
112}
diff --git a/OpenSim/Data/SQLite/Resources/EstateStore.migrations b/OpenSim/Data/SQLite/Resources/EstateStore.migrations
new file mode 100644
index 0000000..62f6464
--- /dev/null
+++ b/OpenSim/Data/SQLite/Resources/EstateStore.migrations
@@ -0,0 +1,88 @@
1:VERSION 6
2
3BEGIN TRANSACTION;
4
5CREATE TABLE estate_groups (
6 EstateID int(10) NOT NULL,
7 uuid char(36) NOT NULL
8);
9
10CREATE TABLE estate_managers (
11 EstateID int(10) NOT NULL,
12 uuid char(36) NOT NULL
13);
14
15CREATE TABLE estate_map (
16 RegionID char(36) NOT NULL default '00000000-0000-0000-0000-000000000000',
17 EstateID int(11) NOT NULL
18);
19
20CREATE TABLE estate_settings (
21 EstateID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
22 EstateName varchar(64) default NULL,
23 AbuseEmailToEstateOwner tinyint(4) NOT NULL,
24 DenyAnonymous tinyint(4) NOT NULL,
25 ResetHomeOnTeleport tinyint(4) NOT NULL,
26 FixedSun tinyint(4) NOT NULL,
27 DenyTransacted tinyint(4) NOT NULL,
28 BlockDwell tinyint(4) NOT NULL,
29 DenyIdentified tinyint(4) NOT NULL,
30 AllowVoice tinyint(4) NOT NULL,
31 UseGlobalTime tinyint(4) NOT NULL,
32 PricePerMeter int(11) NOT NULL,
33 TaxFree tinyint(4) NOT NULL,
34 AllowDirectTeleport tinyint(4) NOT NULL,
35 RedirectGridX int(11) NOT NULL,
36 RedirectGridY int(11) NOT NULL,
37 ParentEstateID int(10) NOT NULL,
38 SunPosition double NOT NULL,
39 EstateSkipScripts tinyint(4) NOT NULL,
40 BillableFactor float NOT NULL,
41 PublicAccess tinyint(4) NOT NULL
42);
43
44insert into estate_settings (
45 EstateID,EstateName,AbuseEmailToEstateOwner,DenyAnonymous,ResetHomeOnTeleport,FixedSun,DenyTransacted,BlockDwell,DenyIdentified,AllowVoice,UseGlobalTime,PricePerMeter,TaxFree,AllowDirectTeleport,RedirectGridX,RedirectGridY,ParentEstateID,SunPosition,PublicAccess,EstateSkipScripts,BillableFactor)
46 values ( 99, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '');
47delete from estate_settings;
48
49CREATE TABLE estate_users (
50 EstateID int(10) NOT NULL,
51 uuid char(36) NOT NULL
52);
53
54CREATE TABLE estateban (
55 EstateID int(10) NOT NULL,
56 bannedUUID varchar(36) NOT NULL,
57 bannedIp varchar(16) NOT NULL,
58 bannedIpHostMask varchar(16) NOT NULL,
59 bannedNameMask varchar(64) default NULL
60);
61
62CREATE INDEX estate_ban_estate_id on estateban(EstateID);
63CREATE INDEX estate_groups_estate_id on estate_groups(EstateID);
64CREATE INDEX estate_managers_estate_id on estate_managers(EstateID);
65CREATE INDEX estate_map_estate_id on estate_map(EstateID);
66CREATE UNIQUE INDEX estate_map_region_id on estate_map(RegionID);
67CREATE INDEX estate_users_estate_id on estate_users(EstateID);
68
69COMMIT;
70
71
72:VERSION 7
73
74begin;
75
76alter table estate_settings add column AbuseEmail varchar(255) not null default '';
77
78alter table estate_settings add column EstateOwner varchar(36) not null default '';
79
80commit;
81
82:VERSION 8
83
84begin;
85
86alter table estate_settings add column DenyMinors tinyint not null default 0;
87
88commit;
diff --git a/OpenSim/Data/SQLite/Resources/RegionStore.migrations b/OpenSim/Data/SQLite/Resources/RegionStore.migrations
index 7b27378..c47a85d 100644
--- a/OpenSim/Data/SQLite/Resources/RegionStore.migrations
+++ b/OpenSim/Data/SQLite/Resources/RegionStore.migrations
@@ -311,33 +311,8 @@ CREATE TABLE regionsettings (
311 PRIMARY KEY (regionUUID) 311 PRIMARY KEY (regionUUID)
312); 312);
313 313
314CREATE INDEX estate_ban_estate_id on estateban(EstateID);
315CREATE INDEX estate_groups_estate_id on estate_groups(EstateID);
316CREATE INDEX estate_managers_estate_id on estate_managers(EstateID);
317CREATE INDEX estate_map_estate_id on estate_map(EstateID);
318CREATE UNIQUE INDEX estate_map_region_id on estate_map(RegionID);
319CREATE INDEX estate_users_estate_id on estate_users(EstateID);
320
321COMMIT; 314COMMIT;
322 315
323:VERSION 7
324
325begin;
326
327alter table estate_settings add column AbuseEmail varchar(255) not null default '';
328
329alter table estate_settings add column EstateOwner varchar(36) not null default '';
330
331commit;
332
333:VERSION 8
334
335begin;
336
337alter table estate_settings add column DenyMinors tinyint not null default 0;
338
339commit;
340
341:VERSION 9 316:VERSION 9
342 317
343BEGIN; 318BEGIN;
diff --git a/OpenSim/Data/SQLite/Tests/SQLiteAssetTest.cs b/OpenSim/Data/SQLite/Tests/SQLiteAssetTest.cs
deleted file mode 100644
index 0c2f5df..0000000
--- a/OpenSim/Data/SQLite/Tests/SQLiteAssetTest.cs
+++ /dev/null
@@ -1,64 +0,0 @@
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 OpenSimulator 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
28using System.IO;
29using NUnit.Framework;
30using OpenSim.Data.Tests;
31using OpenSim.Tests.Common;
32
33namespace OpenSim.Data.SQLite.Tests
34{
35 [TestFixture, DatabaseTest]
36 public class SQLiteAssetTest : BasicAssetTest
37 {
38 public string file;
39 public string connect;
40
41 [TestFixtureSetUp]
42 public void Init()
43 {
44 // SQLite doesn't work on power or z linux
45 if (Directory.Exists("/proc/ppc64") || Directory.Exists("/proc/dasd"))
46 {
47 Assert.Ignore();
48 }
49
50 SuperInit();
51 file = Path.GetTempFileName() + ".db";
52 connect = "URI=file:" + file + ",version=3";
53 db = new SQLiteAssetData();
54 db.Initialise(connect);
55 }
56
57 [TestFixtureTearDown]
58 public void Cleanup()
59 {
60 db.Dispose();
61 File.Delete(file);
62 }
63 }
64}
diff --git a/OpenSim/Data/SQLite/Tests/SQLiteEstateTest.cs b/OpenSim/Data/SQLite/Tests/SQLiteEstateTest.cs
deleted file mode 100644
index 30f6641..0000000
--- a/OpenSim/Data/SQLite/Tests/SQLiteEstateTest.cs
+++ /dev/null
@@ -1,65 +0,0 @@
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 OpenSimulator 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
28using System.IO;
29using NUnit.Framework;
30using OpenSim.Data.Tests;
31using OpenSim.Tests.Common;
32
33namespace OpenSim.Data.SQLite.Tests
34{
35 [TestFixture, DatabaseTest]
36 public class SQLiteEstateTest : BasicEstateTest
37 {
38 public string file = "regiontest.db";
39 public string connect;
40
41 [TestFixtureSetUp]
42 public void Init()
43 {
44 // SQLite doesn't work on power or z linux
45 if (Directory.Exists("/proc/ppc64") || Directory.Exists("/proc/dasd"))
46 {
47 Assert.Ignore();
48 }
49
50 SuperInit();
51 file = Path.GetTempFileName() + ".db";
52 connect = "URI=file:" + file + ",version=3";
53 db = new SQLiteEstateStore();
54 db.Initialise(connect);
55 regionDb = new SQLiteRegionData();
56 regionDb.Initialise(connect);
57 }
58
59 [TestFixtureTearDown]
60 public void Cleanup()
61 {
62 regionDb.Dispose();
63 }
64 }
65}
diff --git a/OpenSim/Data/SQLite/Tests/SQLiteInventoryTest.cs b/OpenSim/Data/SQLite/Tests/SQLiteInventoryTest.cs
deleted file mode 100644
index 98458a3..0000000
--- a/OpenSim/Data/SQLite/Tests/SQLiteInventoryTest.cs
+++ /dev/null
@@ -1,66 +0,0 @@
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 OpenSimulator 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
28using System.IO;
29using NUnit.Framework;
30using OpenSim.Data.Tests;
31using OpenSim.Tests.Common;
32
33namespace OpenSim.Data.SQLite.Tests
34{
35 [TestFixture, DatabaseTest]
36 public class SQLiteInventoryTest : BasicInventoryTest
37 {
38 public string file;
39 public string connect;
40
41 [TestFixtureSetUp]
42 public void Init()
43 {
44 // SQLite doesn't work on power or z linux
45 if (Directory.Exists("/proc/ppc64") || Directory.Exists("/proc/dasd"))
46 {
47 Assert.Ignore();
48 }
49
50 SuperInit();
51
52 file = Path.GetTempFileName() + ".db";
53 connect = "URI=file:" + file + ",version=3";
54
55 db = new SQLiteInventoryStore();
56 db.Initialise(connect);
57 }
58
59 [TestFixtureTearDown]
60 public void Cleanup()
61 {
62 db.Dispose();
63 File.Delete(file);
64 }
65 }
66}
diff --git a/OpenSim/Data/SQLite/Tests/SQLiteRegionTest.cs b/OpenSim/Data/SQLite/Tests/SQLiteRegionTest.cs
deleted file mode 100644
index abb97cf..0000000
--- a/OpenSim/Data/SQLite/Tests/SQLiteRegionTest.cs
+++ /dev/null
@@ -1,64 +0,0 @@
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 OpenSimulator 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
28using System.IO;
29using NUnit.Framework;
30using OpenSim.Data.Tests;
31using OpenSim.Tests.Common;
32
33namespace OpenSim.Data.SQLite.Tests
34{
35 [TestFixture, DatabaseTest]
36 public class SQLiteRegionTest : BasicRegionTest
37 {
38 public string file = "regiontest.db";
39 public string connect;
40
41 [TestFixtureSetUp]
42 public void Init()
43 {
44 // SQLite doesn't work on power or z linux
45 if (Directory.Exists("/proc/ppc64") || Directory.Exists("/proc/dasd"))
46 {
47 Assert.Ignore();
48 }
49
50 SuperInit();
51 file = Path.GetTempFileName() + ".db";
52 connect = "URI=file:" + file + ",version=3";
53 db = new SQLiteRegionData();
54 db.Initialise(connect);
55 }
56
57 [TestFixtureTearDown]
58 public void Cleanup()
59 {
60 db.Dispose();
61 File.Delete(file);
62 }
63 }
64}
diff --git a/OpenSim/Data/Tests/AssetTests.cs b/OpenSim/Data/Tests/AssetTests.cs
new file mode 100644
index 0000000..800b9bf
--- /dev/null
+++ b/OpenSim/Data/Tests/AssetTests.cs
@@ -0,0 +1,221 @@
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 OpenSimulator 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
28using System;
29using System.Collections.Generic;
30using log4net.Config;
31using NUnit.Framework;
32using NUnit.Framework.Constraints;
33using OpenMetaverse;
34using OpenSim.Framework;
35using System.Data.Common;
36using log4net;
37
38#if !NUNIT25
39using NUnit.Framework.SyntaxHelpers;
40#endif
41
42// DBMS-specific:
43using MySql.Data.MySqlClient;
44using OpenSim.Data.MySQL;
45
46using System.Data.SqlClient;
47using OpenSim.Data.MSSQL;
48
49using Mono.Data.Sqlite;
50using OpenSim.Data.SQLite;
51
52namespace OpenSim.Data.Tests
53{
54
55#if NUNIT25
56
57 [TestFixture(typeof(MySqlConnection), typeof(MySQLAssetData), Description="Basic Asset store tests (MySQL)")]
58 [TestFixture(typeof(SqlConnection), typeof(MSSQLAssetData), Description = "Basic Asset store tests (MS SQL Server)")]
59 [TestFixture(typeof(SqliteConnection), typeof(SQLiteAssetData), Description = "Basic Asset store tests (SQLite)")]
60
61#else
62
63 [TestFixture(Description = "Asset store tests (SQLite)")]
64 public class SQLiteAssetTests : AssetTests<SqliteConnection, SQLiteAssetData>
65 {
66 }
67
68 [TestFixture(Description = "Asset store tests (MySQL)")]
69 public class MySqlAssetTests : AssetTests<MySqlConnection, MySQLAssetData>
70 {
71 }
72
73 [TestFixture(Description = "Asset store tests (MS SQL Server)")]
74 public class MSSQLAssetTests : AssetTests<SqlConnection, MSSQLAssetData>
75 {
76 }
77
78#endif
79
80
81 public class AssetTests<TConn, TAssetData> : BasicDataServiceTest<TConn, TAssetData>
82 where TConn : DbConnection, new()
83 where TAssetData : AssetDataBase, new()
84 {
85 TAssetData m_db;
86
87 public UUID uuid1 = UUID.Random();
88 public UUID uuid2 = UUID.Random();
89 public UUID uuid3 = UUID.Random();
90
91 public string critter1 = UUID.Random().ToString();
92 public string critter2 = UUID.Random().ToString();
93 public string critter3 = UUID.Random().ToString();
94
95 public byte[] data1 = new byte[100];
96
97 PropertyScrambler<AssetBase> scrambler = new PropertyScrambler<AssetBase>()
98 .DontScramble(x => x.ID)
99 .DontScramble(x => x.Type)
100 .DontScramble(x => x.FullID)
101 .DontScramble(x => x.Metadata.ID)
102 .DontScramble(x => x.Metadata.CreatorID)
103 .DontScramble(x => x.Metadata.ContentType)
104 .DontScramble(x => x.Metadata.FullID)
105 .DontScramble(x => x.Data);
106
107 protected override void InitService(object service)
108 {
109 ClearDB();
110 m_db = (TAssetData)service;
111 m_db.Initialise(m_connStr);
112 }
113
114 private void ClearDB()
115 {
116 DropTables("assets");
117 ResetMigrations("AssetStore");
118 }
119
120
121 [Test]
122 public void T001_LoadEmpty()
123 {
124 Assert.That(m_db.ExistsAsset(uuid1), Is.False);
125 Assert.That(m_db.ExistsAsset(uuid2), Is.False);
126 Assert.That(m_db.ExistsAsset(uuid3), Is.False);
127 }
128
129 [Test]
130 public void T010_StoreReadVerifyAssets()
131 {
132 AssetBase a1 = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture, critter1.ToString());
133 AssetBase a2 = new AssetBase(uuid2, "asset two", (sbyte)AssetType.Texture, critter2.ToString());
134 AssetBase a3 = new AssetBase(uuid3, "asset three", (sbyte)AssetType.Texture, critter3.ToString());
135 a1.Data = data1;
136 a2.Data = data1;
137 a3.Data = data1;
138
139 scrambler.Scramble(a1);
140 scrambler.Scramble(a2);
141 scrambler.Scramble(a3);
142
143 m_db.StoreAsset(a1);
144 m_db.StoreAsset(a2);
145 m_db.StoreAsset(a3);
146
147 AssetBase a1a = m_db.GetAsset(uuid1);
148 Assert.That(a1a, Constraints.PropertyCompareConstraint(a1));
149
150 AssetBase a2a = m_db.GetAsset(uuid2);
151 Assert.That(a2a, Constraints.PropertyCompareConstraint(a2));
152
153 AssetBase a3a = m_db.GetAsset(uuid3);
154 Assert.That(a3a, Constraints.PropertyCompareConstraint(a3));
155
156 scrambler.Scramble(a1a);
157 scrambler.Scramble(a2a);
158 scrambler.Scramble(a3a);
159
160 m_db.StoreAsset(a1a);
161 m_db.StoreAsset(a2a);
162 m_db.StoreAsset(a3a);
163
164 AssetBase a1b = m_db.GetAsset(uuid1);
165 Assert.That(a1b, Constraints.PropertyCompareConstraint(a1a));
166
167 AssetBase a2b = m_db.GetAsset(uuid2);
168 Assert.That(a2b, Constraints.PropertyCompareConstraint(a2a));
169
170 AssetBase a3b = m_db.GetAsset(uuid3);
171 Assert.That(a3b, Constraints.PropertyCompareConstraint(a3a));
172
173 Assert.That(m_db.ExistsAsset(uuid1), Is.True);
174 Assert.That(m_db.ExistsAsset(uuid2), Is.True);
175 Assert.That(m_db.ExistsAsset(uuid3), Is.True);
176
177 List<AssetMetadata> metadatas = m_db.FetchAssetMetadataSet(0, 1000);
178
179 Assert.That(metadatas.Count >= 3, "FetchAssetMetadataSet() should have returned at least 3 assets!");
180
181 // It is possible that the Asset table is filled with data, in which case we don't try to find "our"
182 // assets there:
183 if (metadatas.Count < 1000)
184 {
185 AssetMetadata metadata = metadatas.Find(x => x.FullID == uuid1);
186 Assert.That(metadata.Name, Is.EqualTo(a1b.Name));
187 Assert.That(metadata.Description, Is.EqualTo(a1b.Description));
188 Assert.That(metadata.Type, Is.EqualTo(a1b.Type));
189 Assert.That(metadata.Temporary, Is.EqualTo(a1b.Temporary));
190 Assert.That(metadata.FullID, Is.EqualTo(a1b.FullID));
191 }
192 }
193
194 [Test]
195 public void T020_CheckForWeirdCreatorID()
196 {
197 // It is expected that eventually the CreatorID might be an arbitrary string (an URI)
198 // rather than a valid UUID (?). This test is to make sure that the database layer does not
199 // attempt to convert CreatorID to GUID, but just passes it both ways as a string.
200 AssetBase a1 = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture, critter1);
201 AssetBase a2 = new AssetBase(uuid2, "asset two", (sbyte)AssetType.Texture, "This is not a GUID!");
202 AssetBase a3 = new AssetBase(uuid3, "asset three", (sbyte)AssetType.Texture, "");
203 a1.Data = data1;
204 a2.Data = data1;
205 a3.Data = data1;
206
207 m_db.StoreAsset(a1);
208 m_db.StoreAsset(a2);
209 m_db.StoreAsset(a3);
210
211 AssetBase a1a = m_db.GetAsset(uuid1);
212 Assert.That(a1a, Constraints.PropertyCompareConstraint(a1));
213
214 AssetBase a2a = m_db.GetAsset(uuid2);
215 Assert.That(a2a, Constraints.PropertyCompareConstraint(a2));
216
217 AssetBase a3a = m_db.GetAsset(uuid3);
218 Assert.That(a3a, Constraints.PropertyCompareConstraint(a3));
219 }
220 }
221}
diff --git a/OpenSim/Data/Tests/BasicAssetTest.cs b/OpenSim/Data/Tests/BasicAssetTest.cs
deleted file mode 100644
index 71d6314..0000000
--- a/OpenSim/Data/Tests/BasicAssetTest.cs
+++ /dev/null
@@ -1,166 +0,0 @@
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 OpenSimulator 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
28using System;
29using System.Collections.Generic;
30using log4net.Config;
31using NUnit.Framework;
32using NUnit.Framework.SyntaxHelpers;
33using OpenMetaverse;
34using OpenSim.Framework;
35using log4net;
36
37namespace OpenSim.Data.Tests
38{
39 public class BasicAssetTest
40 {
41 public IAssetDataPlugin db;
42 public UUID uuid1;
43 public UUID uuid2;
44 public UUID uuid3;
45 public string critter1 = UUID.Random().ToString();
46 public string critter2 = UUID.Random().ToString();
47 public string critter3 = UUID.Random().ToString();
48 public byte[] asset1;
49 PropertyScrambler<AssetBase> scrambler;
50
51 public void SuperInit()
52 {
53 OpenSim.Tests.Common.TestLogging.LogToConsole();
54
55 uuid1 = UUID.Random();
56 uuid2 = UUID.Random();
57 uuid3 = UUID.Random();
58 asset1 = new byte[100];
59 asset1.Initialize();
60
61
62 scrambler = new PropertyScrambler<AssetBase>()
63 .DontScramble(x => x.ID)
64 .DontScramble(x => x.FullID)
65 .DontScramble(x => x.Metadata.ID)
66 .DontScramble(x => x.Metadata.Type)
67 .DontScramble(x => x.Metadata.CreatorID)
68 .DontScramble(x => x.Metadata.ContentType)
69 .DontScramble(x => x.Metadata.FullID);
70 }
71
72 [Test]
73 public void T001_LoadEmpty()
74 {
75 Assert.That(db.ExistsAsset(uuid1), Is.False);
76 Assert.That(db.ExistsAsset(uuid2), Is.False);
77 Assert.That(db.ExistsAsset(uuid3), Is.False);
78 }
79
80 [Test]
81 public void T010_StoreSimpleAsset()
82 {
83 AssetBase a1 = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture, critter1);
84 AssetBase a2 = new AssetBase(uuid2, "asset two", (sbyte)AssetType.Texture, critter2);
85 AssetBase a3 = new AssetBase(uuid3, "asset three", (sbyte)AssetType.Texture, critter3);
86 a1.Data = asset1;
87 a2.Data = asset1;
88 a3.Data = asset1;
89
90 scrambler.Scramble(a1);
91 scrambler.Scramble(a2);
92 scrambler.Scramble(a3);
93
94 db.StoreAsset(a1);
95 db.StoreAsset(a2);
96 db.StoreAsset(a3);
97
98 AssetBase a1a = db.GetAsset(uuid1);
99 Assert.That(a1a, Constraints.PropertyCompareConstraint(a1));
100
101 AssetBase a2a = db.GetAsset(uuid2);
102 Assert.That(a2a, Constraints.PropertyCompareConstraint(a2));
103
104 AssetBase a3a = db.GetAsset(uuid3);
105 Assert.That(a3a, Constraints.PropertyCompareConstraint(a3));
106
107 scrambler.Scramble(a1a);
108 scrambler.Scramble(a2a);
109 scrambler.Scramble(a3a);
110
111 db.StoreAsset(a1a);
112 db.StoreAsset(a2a);
113 db.StoreAsset(a3a);
114
115 AssetBase a1b = db.GetAsset(uuid1);
116 Assert.That(a1b, Constraints.PropertyCompareConstraint(a1a));
117
118 AssetBase a2b = db.GetAsset(uuid2);
119 Assert.That(a2b, Constraints.PropertyCompareConstraint(a2a));
120
121 AssetBase a3b = db.GetAsset(uuid3);
122 Assert.That(a3b, Constraints.PropertyCompareConstraint(a3a));
123
124 Assert.That(db.ExistsAsset(uuid1), Is.True);
125 Assert.That(db.ExistsAsset(uuid2), Is.True);
126 Assert.That(db.ExistsAsset(uuid3), Is.True);
127
128 List<AssetMetadata> metadatas = db.FetchAssetMetadataSet(0, 1000);
129
130 AssetMetadata metadata = metadatas.Find(x => x.FullID == uuid1);
131 Assert.That(metadata.Name, Is.EqualTo(a1b.Name));
132 Assert.That(metadata.Description, Is.EqualTo(a1b.Description));
133 Assert.That(metadata.Type, Is.EqualTo(a1b.Type));
134 Assert.That(metadata.Temporary, Is.EqualTo(a1b.Temporary));
135 Assert.That(metadata.FullID, Is.EqualTo(a1b.FullID));
136 }
137
138
139 [Test]
140 public void T020_CheckForWeirdCreatorID()
141 {
142 // It is expected that eventually the CreatorID might be an arbitrary string (an URI)
143 // rather than a valid UUID (?). This test is to make sure that the database layer does not
144 // attempt to convert CreatorID to GUID, but just passes it both ways as a string.
145 AssetBase a1 = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture, critter1);
146 AssetBase a2 = new AssetBase(uuid2, "asset two", (sbyte)AssetType.Texture, "This is not a GUID!");
147 AssetBase a3 = new AssetBase(uuid3, "asset three", (sbyte)AssetType.Texture, "");
148 a1.Data = asset1;
149 a2.Data = asset1;
150 a3.Data = asset1;
151
152 db.StoreAsset(a1);
153 db.StoreAsset(a2);
154 db.StoreAsset(a3);
155
156 AssetBase a1a = db.GetAsset(uuid1);
157 Assert.That(a1a, Constraints.PropertyCompareConstraint(a1));
158
159 AssetBase a2a = db.GetAsset(uuid2);
160 Assert.That(a2a, Constraints.PropertyCompareConstraint(a2));
161
162 AssetBase a3a = db.GetAsset(uuid3);
163 Assert.That(a3a, Constraints.PropertyCompareConstraint(a3));
164 }
165 }
166}
diff --git a/OpenSim/Data/Tests/BasicDataServiceTest.cs b/OpenSim/Data/Tests/BasicDataServiceTest.cs
new file mode 100644
index 0000000..c261126
--- /dev/null
+++ b/OpenSim/Data/Tests/BasicDataServiceTest.cs
@@ -0,0 +1,234 @@
1using System;
2using System.IO;
3using System.Collections.Generic;
4using log4net.Config;
5using NUnit.Framework;
6using NUnit.Framework.Constraints;
7using OpenMetaverse;
8using OpenSim.Framework;
9using log4net;
10using System.Data;
11using System.Data.Common;
12using System.Reflection;
13
14namespace OpenSim.Data.Tests
15{
16 /// <summary>This is a base class for testing any Data service for any DBMS.
17 /// Requires NUnit 2.5 or better (to support the generics).
18 /// </summary>
19 /// <typeparam name="TConn"></typeparam>
20 /// <typeparam name="TService"></typeparam>
21 public class BasicDataServiceTest<TConn, TService>
22 where TConn : DbConnection, new()
23 where TService : class, new()
24 {
25 protected string m_connStr;
26 private TService m_service;
27 private string m_file;
28
29 // TODO: Is this in the right place here?
30 // Later: apparently it's not, but does it matter here?
31// protected static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
32
33 protected ILog m_log; // doesn't matter here that it's not static, init to correct type in instance .ctor
34
35 public BasicDataServiceTest()
36 : this("")
37 {
38 }
39
40 public BasicDataServiceTest(string conn)
41 {
42 m_connStr = !String.IsNullOrEmpty(conn) ? conn : DefaultTestConns.Get(typeof(TConn));
43
44 m_log = LogManager.GetLogger(this.GetType());
45 OpenSim.Tests.Common.TestLogging.LogToConsole(); // TODO: Is that right?
46 }
47
48 /// <summary>
49 /// To be overridden in derived classes. Do whatever init with the m_service, like setting the conn string to it.
50 /// You'd probably want to to cast the 'service' to a more specific type and store it in a member var.
51 /// This framework takes care of disposing it, if it's disposable.
52 /// </summary>
53 /// <param name="service">The service being tested</param>
54 protected virtual void InitService(object service)
55 {
56 }
57
58 [TestFixtureSetUp]
59 public void Init()
60 {
61 // Sorry, some SQLite-specific stuff goes here (not a big deal, as its just some file ops)
62 if (typeof(TConn).Name.StartsWith("Sqlite"))
63 {
64 // SQLite doesn't work on power or z linux
65 if (Directory.Exists("/proc/ppc64") || Directory.Exists("/proc/dasd"))
66 Assert.Ignore();
67
68 // for SQLite, if no explicit conn string is specified, use a temp file
69 if (String.IsNullOrEmpty(m_connStr))
70 {
71 m_file = Path.GetTempFileName() + ".db";
72 m_connStr = "URI=file:" + m_file + ",version=3";
73 }
74 }
75
76 if (String.IsNullOrEmpty(m_connStr))
77 {
78 string msg = String.Format("Connection string for {0} is not defined, ignoring tests", typeof(TConn).Name);
79 m_log.Warn(msg);
80 Assert.Ignore(msg);
81 }
82
83 // Try the connection, ignore tests if Open() fails
84 using (TConn conn = new TConn())
85 {
86 conn.ConnectionString = m_connStr;
87 try
88 {
89 conn.Open();
90 conn.Close();
91 }
92 catch
93 {
94 string msg = String.Format("{0} is unable to connect to the database, ignoring tests", typeof(TConn).Name);
95 m_log.Warn(msg);
96 Assert.Ignore(msg);
97 }
98 }
99
100 // If we manage to connect to the database with the user
101 // and password above it is our test database, and run
102 // these tests. If anything goes wrong, ignore these
103 // tests.
104 try
105 {
106 m_service = new TService();
107 InitService(m_service);
108 }
109 catch (Exception e)
110 {
111 m_log.Error(e.ToString());
112 Assert.Ignore();
113 }
114 }
115
116 [TestFixtureTearDown]
117 public void Cleanup()
118 {
119 if (m_service != null)
120 {
121 if( m_service is IDisposable)
122 ((IDisposable)m_service).Dispose();
123 m_service = null;
124 }
125
126 if( !String.IsNullOrEmpty(m_file) && File.Exists(m_file) )
127 File.Delete(m_file);
128 }
129
130 protected virtual DbConnection Connect()
131 {
132 DbConnection cnn = new TConn();
133 cnn.ConnectionString = m_connStr;
134 cnn.Open();
135 return cnn;
136 }
137
138 protected virtual void ExecuteSql(string sql)
139 {
140 using (DbConnection dbcon = Connect())
141 {
142 using (DbCommand cmd = dbcon.CreateCommand())
143 {
144 cmd.CommandText = sql;
145 cmd.ExecuteNonQuery();
146 }
147 }
148 }
149
150 protected delegate bool ProcessRow(IDataReader reader);
151
152 protected virtual int ExecQuery(string sql, bool bSingleRow, ProcessRow action)
153 {
154 int nRecs = 0;
155 using (DbConnection dbcon = Connect())
156 {
157 using (DbCommand cmd = dbcon.CreateCommand())
158 {
159 cmd.CommandText = sql;
160 CommandBehavior cb = bSingleRow ? CommandBehavior.SingleRow : CommandBehavior.Default;
161 using (DbDataReader rdr = cmd.ExecuteReader(cb))
162 {
163 while (rdr.Read())
164 {
165 nRecs++;
166 if (!action(rdr))
167 break;
168 }
169 }
170 }
171 }
172 return nRecs;
173 }
174
175 /// <summary>Drop tables (listed as parameters). There is no "DROP IF EXISTS" syntax common for all
176 /// databases, so we just DROP and ignore an exception.
177 /// </summary>
178 /// <param name="tables"></param>
179 protected virtual void DropTables(params string[] tables)
180 {
181 foreach (string tbl in tables)
182 {
183 try
184 {
185 ExecuteSql("DROP TABLE " + tbl + ";");
186 }catch
187 {
188 }
189 }
190 }
191
192 /// <summary>Clear tables listed as parameters (without dropping them).
193 /// </summary>
194 /// <param name="tables"></param>
195 protected virtual void ResetMigrations(params string[] stores)
196 {
197 string lst = "";
198 foreach (string store in stores)
199 {
200 string s = "'" + store + "'";
201 if (lst == "")
202 lst = s;
203 else
204 lst += ", " + s;
205 }
206
207 string sCond = stores.Length > 1 ? ("in (" + lst + ")") : ("=" + lst);
208 try
209 {
210 ExecuteSql("DELETE FROM migrations where name " + sCond);
211 }
212 catch
213 {
214 }
215 }
216
217 /// <summary>Clear tables listed as parameters (without dropping them).
218 /// </summary>
219 /// <param name="tables"></param>
220 protected virtual void ClearTables(params string[] tables)
221 {
222 foreach (string tbl in tables)
223 {
224 try
225 {
226 ExecuteSql("DELETE FROM " + tbl + ";");
227 }
228 catch
229 {
230 }
231 }
232 }
233 }
234}
diff --git a/OpenSim/Data/Tests/DefaultTestConns.cs b/OpenSim/Data/Tests/DefaultTestConns.cs
new file mode 100644
index 0000000..7b52af5
--- /dev/null
+++ b/OpenSim/Data/Tests/DefaultTestConns.cs
@@ -0,0 +1,63 @@
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Reflection;
6using System.IO;
7using Nini.Config;
8
9namespace OpenSim.Data.Tests
10{
11 /// <summary>This static class looks for TestDataConnections.ini file in the /bin directory to obtain
12 /// a connection string for testing one of the supported databases.
13 /// The connections must be in the section [TestConnections] with names matching the connection class
14 /// name for the specific database, e.g.:
15 ///
16 /// [TestConnections]
17 /// MySqlConnection="..."
18 /// SqlConnection="..."
19 /// SqliteConnection="..."
20 ///
21 /// Note that the conn string may also be set explicitly in the [TestCase()] attribute of test classes
22 /// based on BasicDataServiceTest.cs.
23 /// </summary>
24
25 static class DefaultTestConns
26 {
27 private static Dictionary<Type, string> conns = new Dictionary<Type, string>();
28
29 public static string Get(Type connType)
30 {
31 string sConn;
32
33 if (conns.TryGetValue(connType, out sConn))
34 return sConn;
35
36 Assembly asm = Assembly.GetExecutingAssembly();
37 string sType = connType.Name;
38
39 // Note: when running from NUnit, the DLL is located in some temp dir, so how do we get
40 // to the INI file? Ok, so put it into the resources!
41 // string iniName = Path.Combine(Path.GetDirectoryName(asm.Location), "TestDataConnections.ini");
42
43 string[] allres = asm.GetManifestResourceNames();
44 string sResFile = Array.Find(allres, s => s.Contains("TestDataConnections.ini"));
45
46 if (String.IsNullOrEmpty(sResFile))
47 throw new Exception(String.Format("Please add resource TestDataConnections.ini, with section [TestConnections] and settings like {0}=\"...\"",
48 sType));
49
50 using (Stream resource = asm.GetManifestResourceStream(sResFile))
51 {
52 IConfigSource source = new IniConfigSource(resource);
53 var cfg = source.Configs["TestConnections"];
54 sConn = cfg.Get(sType, "");
55 }
56
57 if (!String.IsNullOrEmpty(sConn))
58 conns[connType] = sConn;
59
60 return sConn;
61 }
62 }
63}
diff --git a/OpenSim/Data/Tests/BasicEstateTest.cs b/OpenSim/Data/Tests/EstateTests.cs
index d14d405..d6eed3d 100644
--- a/OpenSim/Data/Tests/BasicEstateTest.cs
+++ b/OpenSim/Data/Tests/EstateTests.cs
@@ -35,13 +35,57 @@ using OpenSim.Region.Framework.Interfaces;
35using System.Text; 35using System.Text;
36using log4net; 36using log4net;
37using System.Reflection; 37using System.Reflection;
38using System.Data.Common;
39
40#if !NUNIT25
41using NUnit.Framework.SyntaxHelpers;
42#endif
43
44
45// DBMS-specific:
46using MySql.Data.MySqlClient;
47using OpenSim.Data.MySQL;
48
49using System.Data.SqlClient;
50using OpenSim.Data.MSSQL;
51
52using Mono.Data.Sqlite;
53using OpenSim.Data.SQLite;
54
38 55
39namespace OpenSim.Data.Tests 56namespace OpenSim.Data.Tests
40{ 57{
41 public class BasicEstateTest 58
59#if NUNIT25
60
61 [TestFixture(typeof(MySqlConnection), typeof(MySQLEstateStore), Description = "Estate store tests (MySQL)")]
62 [TestFixture(typeof(SqlConnection), typeof(MSSQLEstateStore), Description = "Estate store tests (MS SQL Server)")]
63 [TestFixture(typeof(SqliteConnection), typeof(SQLiteEstateStore), Description = "Estate store tests (SQLite)")]
64
65#else
66
67 [TestFixture(Description = "Estate store tests (SQLite)")]
68 public class SQLiteEstateTests : EstateTests<SqliteConnection, SQLiteEstateStore>
69 {
70 }
71
72 [TestFixture(Description = "Estate store tests (MySQL)")]
73 public class MySqlEstateTests : EstateTests<MySqlConnection, MySQLEstateStore>
74 {
75 }
76
77 [TestFixture(Description = "Estate store tests (MS SQL Server)")]
78 public class MSSQLEstateTests : EstateTests<SqlConnection, MSSQLEstateStore>
79 {
80 }
81
82#endif
83
84 public class EstateTests<TConn, TEstateStore> : BasicDataServiceTest<TConn, TEstateStore>
85 where TConn : DbConnection, new()
86 where TEstateStore : class, IEstateDataStore, new()
42 { 87 {
43 public IEstateDataStore db; 88 public IEstateDataStore db;
44 public IRegionDataStore regionDb;
45 89
46 public static UUID REGION_ID = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed7"); 90 public static UUID REGION_ID = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed7");
47 91
@@ -54,9 +98,25 @@ namespace OpenSim.Data.Tests
54 public static UUID GROUP_ID_1 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed5"); 98 public static UUID GROUP_ID_1 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed5");
55 public static UUID GROUP_ID_2 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed6"); 99 public static UUID GROUP_ID_2 = new UUID("250d214e-1c7e-4f9b-a488-87c5e53feed6");
56 100
57 public void SuperInit() 101 protected override void InitService(object service)
102 {
103 ClearDB();
104 db = (IEstateDataStore)service;
105 db.Initialise(m_connStr);
106 }
107
108 private void ClearDB()
58 { 109 {
59 OpenSim.Tests.Common.TestLogging.LogToConsole(); 110 // if a new table is added, it has to be dropped here
111 DropTables(
112 "estate_managers",
113 "estate_groups",
114 "estate_users",
115 "estateban",
116 "estate_settings",
117 "estate_map"
118 );
119 ResetMigrations("EstateStore");
60 } 120 }
61 121
62 #region 0Tests 122 #region 0Tests
@@ -292,8 +352,7 @@ namespace OpenSim.Data.Tests
292 // Letting estate store generate rows to database for us 352 // Letting estate store generate rows to database for us
293 EstateSettings originalSettings = db.LoadEstateSettings(regionId, true); 353 EstateSettings originalSettings = db.LoadEstateSettings(regionId, true);
294 354
295 SetEstateSettings( 355 SetEstateSettings(originalSettings,
296 originalSettings,
297 estateName, 356 estateName,
298 parentEstateID, 357 parentEstateID,
299 billableFactor, 358 billableFactor,
@@ -319,30 +378,6 @@ namespace OpenSim.Data.Tests
319 estateOwner 378 estateOwner
320 ); 379 );
321 380
322 originalSettings.EstateName = estateName;
323 originalSettings.ParentEstateID = parentEstateID;
324 originalSettings.BillableFactor = billableFactor;
325 originalSettings.PricePerMeter = pricePerMeter;
326 originalSettings.RedirectGridX = redirectGridX;
327 originalSettings.RedirectGridY = redirectGridY;
328 originalSettings.UseGlobalTime = useGlobalTime;
329 originalSettings.FixedSun = fixedSun;
330 originalSettings.SunPosition = sunPosition;
331 originalSettings.AllowVoice = allowVoice;
332 originalSettings.AllowDirectTeleport = allowDirectTeleport;
333 originalSettings.ResetHomeOnTeleport = resetHomeOnTeleport;
334 originalSettings.DenyAnonymous = denyAnonymous;
335 originalSettings.DenyIdentified = denyIdentified;
336 originalSettings.DenyTransacted = denyTransacted;
337 originalSettings.DenyMinors = denyMinors;
338 originalSettings.AbuseEmailToEstateOwner = abuseEmailToEstateOwner;
339 originalSettings.BlockDwell = blockDwell;
340 originalSettings.EstateSkipScripts = estateSkipScripts;
341 originalSettings.TaxFree = taxFree;
342 originalSettings.PublicAccess = publicAccess;
343 originalSettings.AbuseEmail = abuseEmail;
344 originalSettings.EstateOwner = estateOwner;
345
346 // Saving settings. 381 // Saving settings.
347 db.StoreEstateSettings(originalSettings); 382 db.StoreEstateSettings(originalSettings);
348 383
@@ -350,8 +385,7 @@ namespace OpenSim.Data.Tests
350 EstateSettings loadedSettings = db.LoadEstateSettings(regionId, true); 385 EstateSettings loadedSettings = db.LoadEstateSettings(regionId, true);
351 386
352 // Checking that loaded values are correct. 387 // Checking that loaded values are correct.
353 ValidateEstateSettings( 388 ValidateEstateSettings(loadedSettings,
354 loadedSettings,
355 estateName, 389 estateName,
356 parentEstateID, 390 parentEstateID,
357 billableFactor, 391 billableFactor,
diff --git a/OpenSim/Data/Tests/BasicInventoryTest.cs b/OpenSim/Data/Tests/InventoryTests.cs
index 900186b..c22e26c 100644
--- a/OpenSim/Data/Tests/BasicInventoryTest.cs
+++ b/OpenSim/Data/Tests/InventoryTests.cs
@@ -25,6 +25,8 @@
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// #define NUNIT25
29
28using System; 30using System;
29using log4net.Config; 31using log4net.Config;
30using NUnit.Framework; 32using NUnit.Framework;
@@ -33,62 +35,95 @@ using OpenMetaverse;
33using OpenSim.Framework; 35using OpenSim.Framework;
34using log4net; 36using log4net;
35using System.Reflection; 37using System.Reflection;
38using System.Data.Common;
39
40#if !NUNIT25
41using NUnit.Framework.SyntaxHelpers;
42#endif
43
44// DBMS-specific:
45using MySql.Data.MySqlClient;
46using OpenSim.Data.MySQL;
47
48using System.Data.SqlClient;
49using OpenSim.Data.MSSQL;
50
51using Mono.Data.Sqlite;
52using OpenSim.Data.SQLite;
36 53
37namespace OpenSim.Data.Tests 54namespace OpenSim.Data.Tests
38{ 55{
39 public class BasicInventoryTest 56#if NUNIT25
57
58 [TestFixture(typeof(SqliteConnection), typeof(SQLiteInventoryStore), Description = "Inventory store tests (SQLite)")]
59 [TestFixture(typeof(MySqlConnection), typeof(MySQLInventoryData), Description = "Inventory store tests (MySQL)")]
60 [TestFixture(typeof(SqlConnection), typeof(MSSQLInventoryData), Description = "Inventory store tests (MS SQL Server)")]
61
62#else
63
64 [TestFixture(Description = "Inventory store tests (SQLite)")]
65 public class SQLiteInventoryTests : InventoryTests<SqliteConnection, SQLiteInventoryStore>
66 {
67 }
68
69 [TestFixture(Description = "Inventory store tests (MySQL)")]
70 public class MySqlInventoryTests : InventoryTests<MySqlConnection, MySQLInventoryData>
71 {
72 }
73
74 [TestFixture(Description = "Inventory store tests (MS SQL Server)")]
75 public class MSSQLInventoryTests : InventoryTests<SqlConnection, MSSQLInventoryData>
76 {
77 }
78#endif
79
80 public class InventoryTests<TConn, TInvStore> : BasicDataServiceTest<TConn, TInvStore>
81 where TConn : DbConnection, new()
82 where TInvStore : class, IInventoryDataPlugin, new()
40 { 83 {
41 //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
42 public IInventoryDataPlugin db; 84 public IInventoryDataPlugin db;
85
43 public UUID zero = UUID.Zero; 86 public UUID zero = UUID.Zero;
44 87
45 public UUID folder1; 88 public UUID folder1 = UUID.Random();
46 public UUID folder2; 89 public UUID folder2 = UUID.Random();
47 public UUID folder3; 90 public UUID folder3 = UUID.Random();
48 public UUID owner1; 91 public UUID owner1 = UUID.Random();
49 public UUID owner2; 92 public UUID owner2 = UUID.Random();
50 public UUID owner3; 93 public UUID owner3 = UUID.Random();
51 94
52 public UUID item1; 95 public UUID item1 = UUID.Random();
53 public UUID item2; 96 public UUID item2 = UUID.Random();
54 public UUID item3; 97 public UUID item3 = UUID.Random();
55 public UUID asset1; 98 public UUID asset1 = UUID.Random();
56 public UUID asset2; 99 public UUID asset2 = UUID.Random();
57 public UUID asset3; 100 public UUID asset3 = UUID.Random();
58 101
59 public string name1; 102 public string name1;
60 public string name2; 103 public string name2 = "First Level folder";
61 public string name3; 104 public string name3 = "First Level folder 2";
62 public string niname1; 105 public string niname1 = "My Shirt";
63 public string iname1; 106 public string iname1 = "Shirt";
64 public string iname2; 107 public string iname2 = "Text Board";
65 public string iname3; 108 public string iname3 = "No Pants Barrel";
66 109
67 public void SuperInit() 110 public InventoryTests(string conn) : base(conn)
68 { 111 {
69 OpenSim.Tests.Common.TestLogging.LogToConsole();
70
71 folder1 = UUID.Random();
72 folder2 = UUID.Random();
73 folder3 = UUID.Random();
74 owner1 = UUID.Random();
75 owner2 = UUID.Random();
76 owner3 = UUID.Random();
77 item1 = UUID.Random();
78 item2 = UUID.Random();
79 item3 = UUID.Random();
80 asset1 = UUID.Random();
81 asset2 = UUID.Random();
82 asset3 = UUID.Random();
83
84 name1 = "Root Folder for " + owner1.ToString(); 112 name1 = "Root Folder for " + owner1.ToString();
85 name2 = "First Level folder"; 113 }
86 name3 = "First Level folder 2"; 114 public InventoryTests() : this("") { }
87 niname1 = "My Shirt";
88 iname1 = "Shirt";
89 iname2 = "Text Board";
90 iname3 = "No Pants Barrel";
91 115
116 protected override void InitService(object service)
117 {
118 ClearDB();
119 db = (IInventoryDataPlugin)service;
120 db.Initialise(m_connStr);
121 }
122
123 private void ClearDB()
124 {
125 DropTables("inventoryitems", "inventoryfolders");
126 ResetMigrations("InventoryStore");
92 } 127 }
93 128
94 [Test] 129 [Test]
@@ -159,8 +194,10 @@ namespace OpenSim.Data.Tests
159 [Test] 194 [Test]
160 public void T013_FolderHierarchy() 195 public void T013_FolderHierarchy()
161 { 196 {
162 Assert.That(db.getFolderHierarchy(zero).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(zero).Count, Is.EqualTo(0))"); 197 int n = db.getFolderHierarchy(zero).Count; // (for dbg - easier to see what's returned)
163 Assert.That(db.getFolderHierarchy(folder1).Count, Is.EqualTo(2), "Assert.That(db.getFolderHierarchy(folder1).Count, Is.EqualTo(2))"); 198 Assert.That(n, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(zero).Count, Is.EqualTo(0))");
199 n = db.getFolderHierarchy(folder1).Count;
200 Assert.That(n, Is.EqualTo(2), "Assert.That(db.getFolderHierarchy(folder1).Count, Is.EqualTo(2))");
164 Assert.That(db.getFolderHierarchy(folder2).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(folder2).Count, Is.EqualTo(0))"); 201 Assert.That(db.getFolderHierarchy(folder2).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(folder2).Count, Is.EqualTo(0))");
165 Assert.That(db.getFolderHierarchy(folder3).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(folder3).Count, Is.EqualTo(0))"); 202 Assert.That(db.getFolderHierarchy(folder3).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(folder3).Count, Is.EqualTo(0))");
166 Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0))"); 203 Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0), "Assert.That(db.getFolderHierarchy(UUID.Random()).Count, Is.EqualTo(0))");
diff --git a/OpenSim/Data/Tests/BasicRegionTest.cs b/OpenSim/Data/Tests/RegionTests.cs
index dfbf522..1f654d3 100644
--- a/OpenSim/Data/Tests/BasicRegionTest.cs
+++ b/OpenSim/Data/Tests/RegionTests.cs
@@ -38,59 +38,112 @@ using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.Framework.Scenes; 38using OpenSim.Region.Framework.Scenes;
39using log4net; 39using log4net;
40using System.Reflection; 40using System.Reflection;
41using System.Data.Common;
42
43#if !NUNIT25
44using NUnit.Framework.SyntaxHelpers;
45#endif
46
47// DBMS-specific:
48using MySql.Data.MySqlClient;
49using OpenSim.Data.MySQL;
50
51using System.Data.SqlClient;
52using OpenSim.Data.MSSQL;
53
54using Mono.Data.Sqlite;
55using OpenSim.Data.SQLite;
41 56
42namespace OpenSim.Data.Tests 57namespace OpenSim.Data.Tests
43{ 58{
44 public class BasicRegionTest 59#if NUNIT25
60
61 [TestFixture(typeof(SqliteConnection), typeof(SQLiteRegionData), Description = "Region store tests (SQLite)")]
62 [TestFixture(typeof(MySqlConnection), typeof(MySqlRegionData), Description = "Region store tests (MySQL)")]
63 [TestFixture(typeof(SqlConnection), typeof(MSSQLRegionData), Description = "Region store tests (MS SQL Server)")]
64
65#else
66
67 [TestFixture(Description = "Region store tests (SQLite)")]
68 public class SQLiteRegionTests : RegionTests<SqliteConnection, SQLiteRegionData>
69 {
70 }
71
72 [TestFixture(Description = "Region store tests (MySQL)")]
73 public class MySqlRegionTests : RegionTests<MySqlConnection, MySQLDataStore>
45 { 74 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 75 }
76
77 [TestFixture(Description = "Region store tests (MS SQL Server)")]
78 public class MSSQLRegionTests : RegionTests<SqlConnection, MSSQLRegionDataStore>
79 {
80 }
81
82#endif
83
84 public class RegionTests<TConn, TRegStore> : BasicDataServiceTest<TConn, TRegStore>
85 where TConn : DbConnection, new()
86 where TRegStore : class, IRegionDataStore, new()
87 {
88 bool m_rebuildDB;
89
47 public IRegionDataStore db; 90 public IRegionDataStore db;
48 public UUID zero = UUID.Zero; 91 public UUID zero = UUID.Zero;
49 public UUID region1; 92 public UUID region1 = UUID.Random();
50 public UUID region2; 93 public UUID region2 = UUID.Random();
51 public UUID region3; 94 public UUID region3 = UUID.Random();
52 public UUID region4; 95 public UUID region4 = UUID.Random();
53 public UUID prim1; 96 public UUID prim1 = UUID.Random();
54 public UUID prim2; 97 public UUID prim2 = UUID.Random();
55 public UUID prim3; 98 public UUID prim3 = UUID.Random();
56 public UUID prim4; 99 public UUID prim4 = UUID.Random();
57 public UUID prim5; 100 public UUID prim5 = UUID.Random();
58 public UUID prim6; 101 public UUID prim6 = UUID.Random();
59 public UUID item1; 102 public UUID item1 = UUID.Random();
60 public UUID item2; 103 public UUID item2 = UUID.Random();
61 public UUID item3; 104 public UUID item3 = UUID.Random();
62 105
63 public static Random random; 106 public static Random random = new Random();
64 107
65 public string itemname1 = "item1"; 108 public string itemname1 = "item1";
66 109
67 public uint localID; 110 public uint localID = 1;
68 111
69 public double height1; 112 public double height1 = 20;
70 public double height2; 113 public double height2 = 100;
71 114
72 public void SuperInit() 115 public RegionTests(string conn, bool rebuild)
116 : base(conn)
73 { 117 {
74 OpenSim.Tests.Common.TestLogging.LogToConsole(); 118 m_rebuildDB = rebuild;
75
76 region1 = UUID.Random();
77 region3 = UUID.Random();
78 region4 = UUID.Random();
79 prim1 = UUID.Random();
80 prim2 = UUID.Random();
81 prim3 = UUID.Random();
82 prim4 = UUID.Random();
83 prim5 = UUID.Random();
84 prim6 = UUID.Random();
85 item1 = UUID.Random();
86 item2 = UUID.Random();
87 item3 = UUID.Random();
88 random = new Random();
89 localID = 1;
90 height1 = 20;
91 height2 = 100;
92 } 119 }
93 120
121 public RegionTests() : this("", true) { }
122 public RegionTests(string conn) : this(conn, true) {}
123 public RegionTests(bool rebuild): this("", rebuild) {}
124
125
126 protected override void InitService(object service)
127 {
128 ClearDB();
129 db = (IRegionDataStore)service;
130 db.Initialise(m_connStr);
131 }
132
133 private void ClearDB()
134 {
135 string[] reg_tables = new string[] {
136 "prims", "primshapes", "primitems", "terrain", "land", "landaccesslist", "regionban", "regionsettings"
137 };
138 if (m_rebuildDB)
139 {
140 DropTables(reg_tables);
141 ResetMigrations("RegionStore");
142 }else
143 ClearTables(reg_tables);
144 }
145
146
94 // Test Plan 147 // Test Plan
95 // Prims 148 // Prims
96 // - empty test - 001 149 // - empty test - 001
@@ -580,68 +633,88 @@ namespace OpenSim.Data.Tests
580 .IgnoreProperty(x=>x.PassCollision) 633 .IgnoreProperty(x=>x.PassCollision)
581 .IgnoreProperty(x=>x.RootPart)); 634 .IgnoreProperty(x=>x.RootPart));
582 } 635 }
636
637
638 private SceneObjectGroup GetMySOG(string name)
639 {
640 SceneObjectGroup sog = FindSOG(name, region1);
641 if (sog == null)
642 {
643 sog = NewSOG(name, prim1, region1);
644 db.StoreObject(sog, region1);
645 }
646 return sog;
647 }
583 648
649
650 // NOTE: it is a bad practice to rely on some of the previous tests having been run before.
651 // If the tests are run manually, one at a time, each starts with full class init (DB cleared).
652 // Even when all tests are run, NUnit 2.5+ no longer guarantee a specific test order.
653 // We shouldn't expect to find anything in the DB if we haven't put it there *in the same test*!
654
584 [Test] 655 [Test]
585 public void T020_PrimInventoryEmpty() 656 public void T020_PrimInventoryEmpty()
586 { 657 {
587 SceneObjectGroup sog = FindSOG("object1", region1); 658 SceneObjectGroup sog = GetMySOG("object1");
588 TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1); 659 TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
589 Assert.That(t, Is.Null); 660 Assert.That(t, Is.Null);
590 } 661 }
591 662
592 [Test] 663 // TODO: Is there any point to call StorePrimInventory on a list, rather than on the prim itself?
593 public void T021_PrimInventoryStore()
594 {
595 SceneObjectGroup sog = FindSOG("object1", region1);
596 InventoryItemBase i = NewItem(item1, zero, zero, itemname1, zero);
597
598 Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, i, zero), Is.True);
599 TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
600 Assert.That(t.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))");
601
602 // TODO: seriously??? this is the way we need to loop to get this?
603 664
665 private void StoreInventory(SceneObjectGroup sog)
666 {
604 List<TaskInventoryItem> list = new List<TaskInventoryItem>(); 667 List<TaskInventoryItem> list = new List<TaskInventoryItem>();
668 // TODO: seriously??? this is the way we need to loop to get this?
605 foreach (UUID uuid in sog.RootPart.Inventory.GetInventoryList()) 669 foreach (UUID uuid in sog.RootPart.Inventory.GetInventoryList())
606 { 670 {
607 list.Add(sog.GetInventoryItem(sog.RootPart.LocalId, uuid)); 671 list.Add(sog.GetInventoryItem(sog.RootPart.LocalId, uuid));
608 } 672 }
609 673
610 db.StorePrimInventory(prim1, list); 674 db.StorePrimInventory(sog.RootPart.UUID, list);
611 } 675 }
612 676
613 [Test]
614 public void T022_PrimInventoryRetrieve()
615 {
616 SceneObjectGroup sog = FindSOG("object1", region1);
617 TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
618 677
619 Assert.That(t.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))");
620 }
621
622 [Test] 678 [Test]
623 public void T023_PrimInventoryUpdate() 679 public void T021_PrimInventoryBasic()
624 { 680 {
625 SceneObjectGroup sog = FindSOG("object1", region1); 681 SceneObjectGroup sog = GetMySOG("object1");
682 InventoryItemBase i = NewItem(item1, zero, zero, itemname1, zero);
683
684 Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, i, zero), Is.True);
626 TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1); 685 TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
686 Assert.That(t.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))");
627 687
628 t.Name = "My New Name"; 688 StoreInventory(sog);
629 sog.UpdateInventoryItem(t);
630 689
631 Assert.That(t.Name, Is.EqualTo("My New Name"), "Assert.That(t.Name, Is.EqualTo(\"My New Name\"))"); 690 SceneObjectGroup sog1 = FindSOG("object1", region1);
691 Assert.That(sog1, Is.Not.Null);
632 692
633 } 693 TaskInventoryItem t1 = sog1.GetInventoryItem(sog1.RootPart.LocalId, item1);
694 Assert.That(t1, Is.Not.Null);
695 Assert.That(t1.Name, Is.EqualTo(itemname1), "Assert.That(t.Name, Is.EqualTo(itemname1))");
696
697 // Updating inventory
698 t1.Name = "My New Name";
699 sog1.UpdateInventoryItem(t1);
700
701 StoreInventory(sog1);
702
703 SceneObjectGroup sog2 = FindSOG("object1", region1);
704 TaskInventoryItem t2 = sog2.GetInventoryItem(sog2.RootPart.LocalId, item1);
705 Assert.That(t2.Name, Is.EqualTo("My New Name"), "Assert.That(t.Name, Is.EqualTo(\"My New Name\"))");
706
707 // Removing inventory
634 708
635 [Test]
636 public void T024_PrimInventoryRemove()
637 {
638 List<TaskInventoryItem> list = new List<TaskInventoryItem>(); 709 List<TaskInventoryItem> list = new List<TaskInventoryItem>();
639 db.StorePrimInventory(prim1, list); 710 db.StorePrimInventory(prim1, list);
640 711
641 SceneObjectGroup sog = FindSOG("object1", region1); 712 sog = FindSOG("object1", region1);
642 TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, item1); 713 t = sog.GetInventoryItem(sog.RootPart.LocalId, item1);
643 Assert.That(t, Is.Null); 714 Assert.That(t, Is.Null);
715
644 } 716 }
717
645 718
646 [Test] 719 [Test]
647 public void T025_PrimInventoryPersistency() 720 public void T025_PrimInventoryPersistency()
@@ -685,7 +758,7 @@ namespace OpenSim.Data.Tests
685 int creationd = random.Next(); 758 int creationd = random.Next();
686 i.CreationDate = creationd; 759 i.CreationDate = creationd;
687 760
688 SceneObjectGroup sog = FindSOG("object1", region1); 761 SceneObjectGroup sog = GetMySOG("object1");
689 Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, i, zero), Is.True); 762 Assert.That(sog.AddInventoryItem(null, sog.RootPart.LocalId, i, zero), Is.True);
690 TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, id); 763 TaskInventoryItem t = sog.GetInventoryItem(sog.RootPart.LocalId, id);
691 764
diff --git a/OpenSim/Data/Tests/Resources/TestDataConnections.ini b/OpenSim/Data/Tests/Resources/TestDataConnections.ini
new file mode 100644
index 0000000..5e68ab0
--- /dev/null
+++ b/OpenSim/Data/Tests/Resources/TestDataConnections.ini
@@ -0,0 +1,24 @@
1; The default connections to the test databases. Used by all data tests based on BasicDataServiceTest.cs.
2; This is read by code in DefaultTestConns.cs.
3
4; NOTE that this INI file is currently loaded as a embedded RESOURCE, which is weird and has a
5; disadvantage of having to rebuild the Tests whenever the conn strings are changed.
6; The only reason is that I couldn't figure out a reliable way to put this INI into the correct
7; dir at runtime. If somebody can do it, that would be cool.
8
9; I'm using a local MSDE server for testing. Obviously, you'll have to modify
10; the conn string to whatever MS SQL server is available to you.
11
12; If any of the conn strings is commented out, emty or not valid on your system,
13; the relevant tests will be ignored, rather than fail.
14
15; As to SQLite, if the conn string here is empty, it will work anyway using a temporary
16; file for the DB. If you want the resulting DB to persist (e.g. for performance testing,
17; when filling up the tables can take a long time), explicitly specify a conn string like this:
18
19; SqliteConnection="URI=file:<path_to_your_file>,version=3"
20
21[TestConnections]
22MySqlConnection="Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;"
23SqlConnection="Server=.\SQL2008;Database=opensim-nunit;Trusted_Connection=True;"
24SqliteConnection="" \ No newline at end of file
diff --git a/prebuild.xml b/prebuild.xml
index 870826c..c0e06bf 100644
--- a/prebuild.xml
+++ b/prebuild.xml
@@ -2825,83 +2825,20 @@
2825 <Reference name="log4net.dll"/> 2825 <Reference name="log4net.dll"/>
2826 <Reference name="Mono.Addins.dll" /> 2826 <Reference name="Mono.Addins.dll" />
2827 <Reference name="nunit.framework.dll" /> 2827 <Reference name="nunit.framework.dll" />
2828 <Files> 2828 <Reference name="Nini.dll" />
2829 <Match pattern="*.cs" recurse="true"/>
2830 </Files>
2831 </Project>
2832
2833 <Project frameworkVersion="v3_5" name="OpenSim.Data.MySQL.Tests" path="OpenSim/Data/MySQL/Tests" type="Library">
2834 <Configuration name="Debug">
2835 <Options>
2836 <OutputPath>../../../../bin/</OutputPath>
2837 </Options>
2838 </Configuration>
2839 <Configuration name="Release">
2840 <Options>
2841 <OutputPath>../../../../bin/</OutputPath>
2842 </Options>
2843 </Configuration>
2844 2829
2845 <ReferencePath>../../../../bin/</ReferencePath>
2846 <Reference name="System"/>
2847 <Reference name="System.Xml"/>
2848 <Reference name="System.Data"/>
2849 <Reference name="System.Drawing"/>
2850 <Reference name="OpenSim.Framework"/>
2851 <Reference name="OpenSim.Data"/>
2852 <Reference name="OpenMetaverseTypes.dll"/>
2853 <Reference name="OpenMetaverse.dll"/>
2854 <Reference name="MySql.Data.dll"/>
2855 <Reference name="OpenSim.Tests.Common"/>
2856 <Reference name="OpenSim.Data.Tests"/>
2857 <Reference name="OpenSim.Data.MySQL"/> 2830 <Reference name="OpenSim.Data.MySQL"/>
2858 <Reference name="OpenSim.Framework.Console"/> 2831 <Reference name="OpenSim.Data.MSSQL"/>
2859 <Reference name="OpenSim.Region.Framework"/> 2832 <Reference name="OpenSim.Data.SQLite"/>
2860 <Reference name="log4net.dll"/> 2833
2861 <Reference name="nunit.framework.dll" /> 2834 <Reference name="MySql.Data.dll"/>
2862 <Reference name="Mono.Addins.dll" /> 2835 <Reference name="Mono.Data.Sqlite.dll"/>
2863
2864 <Files> 2836 <Files>
2865 <Match pattern="*.cs" recurse="true"/> 2837 <Match pattern="*.cs" recurse="true"/>
2838 <Match path="Resources" pattern="*.ini" buildAction="EmbeddedResource"/>
2866 </Files> 2839 </Files>
2867 </Project> 2840 </Project>
2868 2841
2869 <Project frameworkVersion="v3_5" name="OpenSim.Data.SQLite.Tests" path="OpenSim/Data/SQLite/Tests" type="Library">
2870 <Configuration name="Debug">
2871 <Options>
2872 <OutputPath>../../../../bin/</OutputPath>
2873 </Options>
2874 </Configuration>
2875 <Configuration name="Release">
2876 <Options>
2877 <OutputPath>../../../../bin/</OutputPath>
2878 </Options>
2879 </Configuration>
2880
2881 <ReferencePath>../../../../bin/</ReferencePath>
2882 <Reference name="System"/>
2883 <Reference name="System.Xml"/>
2884 <Reference name="System.Data"/>
2885 <Reference name="System.Data.SQLite.dll"/>
2886 <Reference name="OpenSim.Data"/>
2887 <Reference name="OpenSim.Data.Tests"/>
2888 <Reference name="OpenSim.Tests.Common"/>
2889 <Reference name="OpenSim.Data.SQLite" />
2890 <Reference name="System.Drawing"/>
2891 <Reference name="OpenSim.Framework"/>
2892 <Reference name="OpenSim.Framework.Console"/>
2893 <Reference name="OpenSim.Region.Framework"/>
2894 <Reference name="OpenMetaverseTypes.dll"/>
2895 <Reference name="OpenMetaverse.dll"/>
2896 <Reference name="Mono.Data.SqliteClient"/>
2897 <Reference name="Mono.Addins.dll" />
2898 <Reference name="log4net.dll"/>
2899 <Reference name="nunit.framework.dll" />
2900
2901 <Files>
2902 <Match pattern="*.cs" recurse="true"/>
2903 </Files>
2904 </Project>
2905 2842
2906 <Project frameworkVersion="v3_5" name="OpenSim.Framework.Tests" path="OpenSim/Framework/Tests" type="Library"> 2843 <Project frameworkVersion="v3_5" name="OpenSim.Framework.Tests" path="OpenSim/Framework/Tests" type="Library">
2907 <Configuration name="Debug"> 2844 <Configuration name="Debug">