From afef1ac191d32e9c1514c294b17e404b1d4ae217 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Thu, 5 Nov 2009 13:10:58 -0800 Subject: Changing the AssetBase constructors to avoid initializing assets with an unknown asset type, and log an error if it ever does happen --- OpenSim/Data/MSSQL/MSSQLAssetData.cs | 9 +++++---- OpenSim/Data/MySQL/MySQLAssetData.cs | 5 +---- OpenSim/Data/SQLite/SQLiteAssetData.cs | 9 +++++---- OpenSim/Data/Tests/BasicAssetTest.cs | 6 +++--- OpenSim/Data/Tests/PropertyCompareConstraint.cs | 12 ++++++------ OpenSim/Data/Tests/PropertyScrambler.cs | 5 ++--- 6 files changed, 22 insertions(+), 24 deletions(-) (limited to 'OpenSim/Data') diff --git a/OpenSim/Data/MSSQL/MSSQLAssetData.cs b/OpenSim/Data/MSSQL/MSSQLAssetData.cs index 25f7cf0..1ce4abf 100644 --- a/OpenSim/Data/MSSQL/MSSQLAssetData.cs +++ b/OpenSim/Data/MSSQL/MSSQLAssetData.cs @@ -132,12 +132,13 @@ namespace OpenSim.Data.MSSQL { if (reader.Read()) { - AssetBase asset = new AssetBase(); + AssetBase asset = new AssetBase( + new UUID((Guid)reader["id"]), + (string)reader["name"], + Convert.ToSByte(reader["assetType"]) + ); // Region Main - asset.FullID = new UUID((Guid)reader["id"]); - asset.Name = (string)reader["name"]; asset.Description = (string)reader["description"]; - asset.Type = Convert.ToSByte(reader["assetType"]); asset.Local = Convert.ToBoolean(reader["local"]); asset.Temporary = Convert.ToBoolean(reader["temporary"]); asset.Data = (byte[])reader["data"]; diff --git a/OpenSim/Data/MySQL/MySQLAssetData.cs b/OpenSim/Data/MySQL/MySQLAssetData.cs index 1fe6d29..6a4ccd7 100644 --- a/OpenSim/Data/MySQL/MySQLAssetData.cs +++ b/OpenSim/Data/MySQL/MySQLAssetData.cs @@ -151,10 +151,9 @@ namespace OpenSim.Data.MySQL { if (dbReader.Read()) { - asset = new AssetBase(); + asset = new AssetBase(assetID, (string)dbReader["name"], (sbyte)dbReader["assetType"]); asset.Data = (byte[]) dbReader["data"]; asset.Description = (string) dbReader["description"]; - asset.FullID = assetID; string local = dbReader["local"].ToString(); if (local.Equals("1") || local.Equals("true", StringComparison.InvariantCultureIgnoreCase)) @@ -162,8 +161,6 @@ namespace OpenSim.Data.MySQL else asset.Local = false; - asset.Name = (string) dbReader["name"]; - asset.Type = (sbyte) dbReader["assetType"]; asset.Temporary = Convert.ToBoolean(dbReader["temporary"]); } dbReader.Close(); diff --git a/OpenSim/Data/SQLite/SQLiteAssetData.cs b/OpenSim/Data/SQLite/SQLiteAssetData.cs index 49275cb..11be28e 100644 --- a/OpenSim/Data/SQLite/SQLiteAssetData.cs +++ b/OpenSim/Data/SQLite/SQLiteAssetData.cs @@ -231,12 +231,13 @@ namespace OpenSim.Data.SQLite // TODO: this doesn't work yet because something more // interesting has to be done to actually get these values // back out. Not enough time to figure it out yet. - AssetBase asset = new AssetBase(); + AssetBase asset = new AssetBase( + new UUID((String)row["UUID"]), + (String)row["Name"], + Convert.ToSByte(row["Type"]) + ); - asset.FullID = new UUID((String) row["UUID"]); - asset.Name = (String) row["Name"]; asset.Description = (String) row["Description"]; - asset.Type = Convert.ToSByte(row["Type"]); asset.Local = Convert.ToBoolean(row["Local"]); asset.Temporary = Convert.ToBoolean(row["Temporary"]); asset.Data = (byte[]) row["Data"]; diff --git a/OpenSim/Data/Tests/BasicAssetTest.cs b/OpenSim/Data/Tests/BasicAssetTest.cs index 1969d76..25aed61 100644 --- a/OpenSim/Data/Tests/BasicAssetTest.cs +++ b/OpenSim/Data/Tests/BasicAssetTest.cs @@ -66,9 +66,9 @@ namespace OpenSim.Data.Tests [Test] public void T010_StoreSimpleAsset() { - AssetBase a1 = new AssetBase(uuid1, "asset one"); - AssetBase a2 = new AssetBase(uuid2, "asset two"); - AssetBase a3 = new AssetBase(uuid3, "asset three"); + AssetBase a1 = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture); + AssetBase a2 = new AssetBase(uuid2, "asset two", (sbyte)AssetType.Texture); + AssetBase a3 = new AssetBase(uuid3, "asset three", (sbyte)AssetType.Texture); a1.Data = asset1; a2.Data = asset1; a3.Data = asset1; diff --git a/OpenSim/Data/Tests/PropertyCompareConstraint.cs b/OpenSim/Data/Tests/PropertyCompareConstraint.cs index 06ca53e..5b1f935 100644 --- a/OpenSim/Data/Tests/PropertyCompareConstraint.cs +++ b/OpenSim/Data/Tests/PropertyCompareConstraint.cs @@ -297,8 +297,8 @@ namespace OpenSim.Data.Tests public void AssetShouldMatch() { UUID uuid1 = UUID.Random(); - AssetBase actual = new AssetBase(uuid1, "asset one"); - AssetBase expected = new AssetBase(uuid1, "asset one"); + AssetBase actual = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture); + AssetBase expected = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture); var constraint = Constraints.PropertyCompareConstraint(expected); @@ -309,8 +309,8 @@ namespace OpenSim.Data.Tests public void AssetShouldNotMatch() { UUID uuid1 = UUID.Random(); - AssetBase actual = new AssetBase(uuid1, "asset one"); - AssetBase expected = new AssetBase(UUID.Random(), "asset one"); + AssetBase actual = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture); + AssetBase expected = new AssetBase(UUID.Random(), "asset one", (sbyte)AssetType.Texture); var constraint = Constraints.PropertyCompareConstraint(expected); @@ -321,8 +321,8 @@ namespace OpenSim.Data.Tests public void AssetShouldNotMatch2() { UUID uuid1 = UUID.Random(); - AssetBase actual = new AssetBase(uuid1, "asset one"); - AssetBase expected = new AssetBase(uuid1, "asset two"); + AssetBase actual = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture); + AssetBase expected = new AssetBase(uuid1, "asset two", (sbyte)AssetType.Texture); var constraint = Constraints.PropertyCompareConstraint(expected); diff --git a/OpenSim/Data/Tests/PropertyScrambler.cs b/OpenSim/Data/Tests/PropertyScrambler.cs index 72aaff1..c968364 100644 --- a/OpenSim/Data/Tests/PropertyScrambler.cs +++ b/OpenSim/Data/Tests/PropertyScrambler.cs @@ -165,7 +165,7 @@ namespace OpenSim.Data.Tests [Test] public void TestScramble() { - AssetBase actual = new AssetBase(UUID.Random(), "asset one"); + AssetBase actual = new AssetBase(UUID.Random(), "asset one", (sbyte)AssetType.Texture); new PropertyScrambler().Scramble(actual); } @@ -173,8 +173,7 @@ namespace OpenSim.Data.Tests public void DontScramble() { UUID uuid = UUID.Random(); - AssetBase asset = new AssetBase(); - asset.FullID = uuid; + AssetBase asset = new AssetBase(uuid, "asset", (sbyte)AssetType.Texture); new PropertyScrambler() .DontScramble(x => x.Metadata) .DontScramble(x => x.FullID) -- cgit v1.1