aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/Tests')
-rw-r--r--OpenSim/Data/Tests/BasicAssetTest.cs78
-rw-r--r--OpenSim/Data/Tests/BasicEstateTest.cs28
-rw-r--r--OpenSim/Data/Tests/BasicGridTest.cs97
-rw-r--r--OpenSim/Data/Tests/BasicInventoryTest.cs86
-rw-r--r--OpenSim/Data/Tests/BasicRegionTest.cs65
-rw-r--r--OpenSim/Data/Tests/BasicUserTest.cs39
-rw-r--r--OpenSim/Data/Tests/PropertyCompareConstraint.cs229
-rw-r--r--OpenSim/Data/Tests/PropertyScrambler.cs186
-rw-r--r--OpenSim/Data/Tests/ScrambleForTesting.cs102
9 files changed, 586 insertions, 324 deletions
diff --git a/OpenSim/Data/Tests/BasicAssetTest.cs b/OpenSim/Data/Tests/BasicAssetTest.cs
index e85a6a7..09131c1 100644
--- a/OpenSim/Data/Tests/BasicAssetTest.cs
+++ b/OpenSim/Data/Tests/BasicAssetTest.cs
@@ -26,20 +26,19 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections.Generic;
29using log4net.Config; 30using log4net.Config;
30using NUnit.Framework; 31using NUnit.Framework;
31using NUnit.Framework.SyntaxHelpers; 32using NUnit.Framework.SyntaxHelpers;
32using OpenMetaverse; 33using OpenMetaverse;
33using OpenSim.Framework; 34using OpenSim.Framework;
34using log4net; 35using log4net;
35using System.Reflection;
36 36
37namespace OpenSim.Data.Tests 37namespace OpenSim.Data.Tests
38{ 38{
39 public class BasicAssetTest 39 public class BasicAssetTest
40 { 40 {
41 //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 41 public IAssetDataPlugin db;
42 public AssetDataBase db;
43 public UUID uuid1; 42 public UUID uuid1;
44 public UUID uuid2; 43 public UUID uuid2;
45 public UUID uuid3; 44 public UUID uuid3;
@@ -47,14 +46,7 @@ namespace OpenSim.Data.Tests
47 46
48 public void SuperInit() 47 public void SuperInit()
49 { 48 {
50 try 49 OpenSim.Tests.Common.TestLogging.LogToConsole();
51 {
52 XmlConfigurator.Configure();
53 }
54 catch (Exception)
55 {
56 // I don't care, just leave log4net off
57 }
58 50
59 uuid1 = UUID.Random(); 51 uuid1 = UUID.Random();
60 uuid2 = UUID.Random(); 52 uuid2 = UUID.Random();
@@ -81,41 +73,59 @@ namespace OpenSim.Data.Tests
81 a2.Data = asset1; 73 a2.Data = asset1;
82 a3.Data = asset1; 74 a3.Data = asset1;
83 75
76 PropertyScrambler<AssetBase> scrambler = new PropertyScrambler<AssetBase>()
77 .DontScramble(x => x.Data)
78 .DontScramble(x => x.ID)
79 .DontScramble(x => x.FullID)
80 .DontScramble(x => x.Metadata.ID)
81 .DontScramble(x => x.Metadata.FullID);
82
83 scrambler.Scramble(a1);
84 scrambler.Scramble(a2);
85 scrambler.Scramble(a3);
86
84 db.CreateAsset(a1); 87 db.CreateAsset(a1);
85 db.CreateAsset(a2); 88 db.CreateAsset(a2);
86 db.CreateAsset(a3); 89 db.CreateAsset(a3);
87 90
88 AssetBase a1a = db.FetchAsset(uuid1); 91 AssetBase a1a = db.FetchAsset(uuid1);
89 Assert.That(a1.ID, Is.EqualTo(a1a.ID), "Assert.That(a1.ID, Is.EqualTo(a1a.ID))"); 92 Assert.That(a1a, Constraints.PropertyCompareConstraint(a1));
90 Assert.That(a1.Name, Is.EqualTo(a1a.Name), "Assert.That(a1.Name, Is.EqualTo(a1a.Name))");
91 93
92 AssetBase a2a = db.FetchAsset(uuid2); 94 AssetBase a2a = db.FetchAsset(uuid2);
93 Assert.That(a2.ID, Is.EqualTo(a2a.ID), "Assert.That(a2.ID, Is.EqualTo(a2a.ID))"); 95 Assert.That(a2a, Constraints.PropertyCompareConstraint(a2));
94 Assert.That(a2.Name, Is.EqualTo(a2a.Name), "Assert.That(a2.Name, Is.EqualTo(a2a.Name))");
95 96
96 AssetBase a3a = db.FetchAsset(uuid3); 97 AssetBase a3a = db.FetchAsset(uuid3);
97 Assert.That(a3.ID, Is.EqualTo(a3a.ID), "Assert.That(a3.ID, Is.EqualTo(a3a.ID))"); 98 Assert.That(a3a, Constraints.PropertyCompareConstraint(a3));
98 Assert.That(a3.Name, Is.EqualTo(a3a.Name), "Assert.That(a3.Name, Is.EqualTo(a3a.Name))"); 99
99 } 100 scrambler.Scramble(a1a);
101 scrambler.Scramble(a2a);
102 scrambler.Scramble(a3a);
103
104 db.UpdateAsset(a1a);
105 db.UpdateAsset(a2a);
106 db.UpdateAsset(a3a);
107
108 AssetBase a1b = db.FetchAsset(uuid1);
109 Assert.That(a1b, Constraints.PropertyCompareConstraint(a1a));
110
111 AssetBase a2b = db.FetchAsset(uuid2);
112 Assert.That(a2b, Constraints.PropertyCompareConstraint(a2a));
113
114 AssetBase a3b = db.FetchAsset(uuid3);
115 Assert.That(a3b, Constraints.PropertyCompareConstraint(a3a));
100 116
101 [Test]
102 public void T011_ExistsSimpleAsset()
103 {
104 Assert.That(db.ExistsAsset(uuid1), Is.True); 117 Assert.That(db.ExistsAsset(uuid1), Is.True);
105 Assert.That(db.ExistsAsset(uuid2), Is.True); 118 Assert.That(db.ExistsAsset(uuid2), Is.True);
106 Assert.That(db.ExistsAsset(uuid3), Is.True); 119 Assert.That(db.ExistsAsset(uuid3), Is.True);
107 }
108 120
109 // this has questionable use, but it is in the interface at the moment. 121 List<AssetMetadata> metadatas = db.FetchAssetMetadataSet(0, 1000);
110 // [Test] 122
111 // public void T012_DeleteAsset() 123 AssetMetadata metadata = metadatas.Find(x => x.FullID == uuid1);
112 // { 124 Assert.That(metadata.Name, Is.EqualTo(a1b.Name));
113 // db.DeleteAsset(uuid1); 125 Assert.That(metadata.Description, Is.EqualTo(a1b.Description));
114 // db.DeleteAsset(uuid2); 126 Assert.That(metadata.Type, Is.EqualTo(a1b.Type));
115 // db.DeleteAsset(uuid3); 127 Assert.That(metadata.Temporary, Is.EqualTo(a1b.Temporary));
116 // Assert.That(db.ExistsAsset(uuid1), Is.False); 128 Assert.That(metadata.FullID, Is.EqualTo(a1b.FullID));
117 // Assert.That(db.ExistsAsset(uuid2), Is.False); 129 }
118 // Assert.That(db.ExistsAsset(uuid3), Is.False);
119 // }
120 } 130 }
121} 131}
diff --git a/OpenSim/Data/Tests/BasicEstateTest.cs b/OpenSim/Data/Tests/BasicEstateTest.cs
index a0266b3..284d066 100644
--- a/OpenSim/Data/Tests/BasicEstateTest.cs
+++ b/OpenSim/Data/Tests/BasicEstateTest.cs
@@ -40,7 +40,6 @@ namespace OpenSim.Data.Tests
40{ 40{
41 public class BasicEstateTest 41 public class BasicEstateTest
42 { 42 {
43 //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44 public IEstateDataStore db; 43 public IEstateDataStore db;
45 public IRegionDataStore regionDb; 44 public IRegionDataStore regionDb;
46 45
@@ -57,14 +56,7 @@ namespace OpenSim.Data.Tests
57 56
58 public void SuperInit() 57 public void SuperInit()
59 { 58 {
60 try 59 OpenSim.Tests.Common.TestLogging.LogToConsole();
61 {
62 XmlConfigurator.Configure();
63 }
64 catch (Exception)
65 {
66 // I don't care, just leave log4net off
67 }
68 } 60 }
69 61
70 #region 0Tests 62 #region 0Tests
@@ -163,6 +155,24 @@ namespace OpenSim.Data.Tests
163 } 155 }
164 156
165 [Test] 157 [Test]
158 private void T012_EstateSettingsRandomStorage()
159 {
160
161 // Letting estate store generate rows to database for us
162 EstateSettings originalSettings = db.LoadEstateSettings(REGION_ID);
163 new PropertyScrambler<EstateSettings>().Scramble(originalSettings);
164
165 // Saving settings.
166 db.StoreEstateSettings(originalSettings);
167
168 // Loading settings to another instance variable.
169 EstateSettings loadedSettings = db.LoadEstateSettings(REGION_ID);
170
171 // Checking that loaded values are correct.
172 Assert.That(loadedSettings, Constraints.PropertyCompareConstraint(originalSettings));
173 }
174
175 [Test]
166 public void T020_EstateSettingsManagerList() 176 public void T020_EstateSettingsManagerList()
167 { 177 {
168 // Letting estate store generate rows to database for us 178 // Letting estate store generate rows to database for us
diff --git a/OpenSim/Data/Tests/BasicGridTest.cs b/OpenSim/Data/Tests/BasicGridTest.cs
index 85273c5..de8fb48 100644
--- a/OpenSim/Data/Tests/BasicGridTest.cs
+++ b/OpenSim/Data/Tests/BasicGridTest.cs
@@ -28,81 +28,47 @@
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Text; 30using System.Text;
31using log4net.Config;
32using NUnit.Framework; 31using NUnit.Framework;
33using NUnit.Framework.SyntaxHelpers; 32using NUnit.Framework.SyntaxHelpers;
34using OpenMetaverse; 33using OpenMetaverse;
35using log4net;
36using System.Reflection;
37 34
38namespace OpenSim.Data.Tests 35namespace OpenSim.Data.Tests
39{ 36{
40 public class BasicGridTest 37 public class BasicGridTest
41 { 38 {
42 //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 39 public IGridDataPlugin db;
43 public GridDataBase db;
44 public UUID region1, region2, region3; 40 public UUID region1, region2, region3;
45 public UUID zero = UUID.Zero; 41 public UUID zero = UUID.Zero;
46 public static Random random; 42 public static Random random = new Random();
47 43
48 [TearDown] 44 [TearDown]
49 public void removeAllRegions() 45 public void removeAllRegions()
50 { 46 {
51 // Clean up all the regions. 47 // Clean up all the regions.
52 foreach (RegionProfileData region in db.GetRegionsByName("", 100)) 48 List<RegionProfileData> regions = db.GetRegionsByName("", 100);
49 if (regions != null)
53 { 50 {
54 db.DeleteProfile(region.Uuid.ToString()); 51 foreach (RegionProfileData region in regions)
52 {
53 db.DeleteProfile(region.Uuid.ToString());
54 }
55 } 55 }
56 } 56 }
57 57
58 public void SuperInit() 58 public void SuperInit()
59 { 59 {
60 try 60 OpenSim.Tests.Common.TestLogging.LogToConsole();
61 {
62 XmlConfigurator.Configure();
63 }
64 catch (Exception)
65 {
66 // I don't care, just leave log4net off
67 }
68 region1 = UUID.Random(); 61 region1 = UUID.Random();
69 region2 = UUID.Random(); 62 region2 = UUID.Random();
70 region3 = UUID.Random(); 63 region3 = UUID.Random();
71 random = new Random();
72 } 64 }
73 65
74 protected RegionProfileData createRegion(UUID regionUUID, string regionName) 66 protected RegionProfileData createRegion(UUID regionUUID, string regionName)
75 { 67 {
76 RegionProfileData reg = new RegionProfileData(); 68 RegionProfileData reg = new RegionProfileData();
69 new PropertyScrambler<RegionProfileData>().Scramble(reg);
77 reg.Uuid = regionUUID; 70 reg.Uuid = regionUUID;
78 reg.RegionName = regionName; 71 reg.RegionName = regionName;
79 reg.RegionHandle = (ulong) random.Next();
80 reg.RegionLocX = (uint) random.Next();
81 reg.RegionLocY = (uint) random.Next();
82 reg.RegionLocZ = (uint) random.Next();
83 reg.RegionSendKey = RandomName();
84 reg.RegionRecvKey = RandomName();
85 reg.RegionSecret = RandomName();
86 reg.RegionOnline = false;
87 reg.ServerIP = RandomName();
88 reg.ServerPort = (uint) random.Next();
89 reg.ServerURI = RandomName();
90 reg.ServerHttpPort = (uint) random.Next();
91 reg.ServerRemotingPort = (uint) random.Next();
92 reg.NorthOverrideHandle = (ulong) random.Next();
93 reg.SouthOverrideHandle = (ulong) random.Next();
94 reg.EastOverrideHandle = (ulong) random.Next();
95 reg.WestOverrideHandle = (ulong) random.Next();
96 reg.RegionDataURI = RandomName();
97 reg.RegionAssetURI = RandomName();
98 reg.RegionAssetSendKey = RandomName();
99 reg.RegionAssetRecvKey = RandomName();
100 reg.RegionUserURI = RandomName();
101 reg.RegionUserSendKey = RandomName();
102 reg.RegionUserRecvKey = RandomName();
103 reg.RegionMapTextureID = UUID.Random();
104 reg.Owner_uuid = UUID.Random();
105 reg.OriginUUID = UUID.Random();
106 72
107 db.AddProfile(reg); 73 db.AddProfile(reg);
108 74
@@ -119,47 +85,12 @@ namespace OpenSim.Data.Tests
119 } 85 }
120 86
121 [Test] 87 [Test]
122 public void T999_StillNull()
123 {
124 Assert.That(db.GetProfileByUUID(zero),Is.Null);
125 }
126
127 [Test]
128 public void T011_AddRetrieveCompleteTest() 88 public void T011_AddRetrieveCompleteTest()
129 { 89 {
130 RegionProfileData newreg = createRegion(region2, "|<Goth@m Ci1y>|"); 90 RegionProfileData newreg = createRegion(region2, "|<Goth@m Ci1y>|");
131 RegionProfileData retreg = db.GetProfileByUUID(region2); 91 RegionProfileData retreg = db.GetProfileByUUID(region2);
132 92
133 Assert.That(retreg.RegionName, Is.EqualTo(newreg.RegionName), "Assert.That(retreg.RegionName, Is.EqualTo(newreg.RegionName))"); 93 Assert.That(retreg, Constraints.PropertyCompareConstraint(newreg).IgnoreProperty(x => x.RegionOnline));
134 Assert.That(retreg.Uuid, Is.EqualTo(region2), "Assert.That(retreg.Uuid, Is.EqualTo(region2))");
135 Assert.That(retreg.RegionHandle, Is.EqualTo(newreg.RegionHandle), "Assert.That(retreg.RegionHandle, Is.EqualTo(newreg.RegionHandle))");
136 Assert.That(retreg.RegionLocX, Is.EqualTo(newreg.RegionLocX), "Assert.That(retreg.RegionLocX, Is.EqualTo(newreg.RegionLocX))");
137 Assert.That(retreg.RegionLocY, Is.EqualTo(newreg.RegionLocY), "Assert.That(retreg.RegionLocY, Is.EqualTo(newreg.RegionLocY))");
138 Assert.That(retreg.RegionLocZ, Is.EqualTo(newreg.RegionLocZ), "Assert.That(retreg.RegionLocZ, Is.EqualTo(newreg.RegionLocZ))");
139 Assert.That(retreg.RegionSendKey, Is.EqualTo(newreg.RegionSendKey), "Assert.That(retreg.RegionSendKey, Is.EqualTo(newreg.RegionSendKey))");
140 Assert.That(retreg.RegionRecvKey, Is.EqualTo(newreg.RegionRecvKey), "Assert.That(retreg.RegionRecvKey, Is.EqualTo(newreg.RegionRecvKey))");
141 Assert.That(retreg.RegionSecret, Is.EqualTo(newreg.RegionSecret), "Assert.That(retreg.RegionSecret, Is.EqualTo(newreg.RegionSecret))");
142 Assert.That(retreg.RegionOnline, Is.EqualTo(newreg.RegionOnline), "Assert.That(retreg.RegionOnline, Is.EqualTo(newreg.RegionOnline))");
143 Assert.That(retreg.OriginUUID, Is.EqualTo(newreg.OriginUUID), "Assert.That(retreg.OriginUUID, Is.EqualTo(newreg.OriginUUID))");
144 Assert.That(retreg.ServerIP, Is.EqualTo(newreg.ServerIP), "Assert.That(retreg.ServerIP, Is.EqualTo(newreg.ServerIP))");
145 Assert.That(retreg.ServerPort, Is.EqualTo(newreg.ServerPort), "Assert.That(retreg.ServerPort, Is.EqualTo(newreg.ServerPort))");
146 Assert.That(retreg.ServerURI, Is.EqualTo(newreg.ServerURI), "Assert.That(retreg.ServerURI, Is.EqualTo(newreg.ServerURI))");
147 Assert.That(retreg.ServerHttpPort, Is.EqualTo(newreg.ServerHttpPort), "Assert.That(retreg.ServerHttpPort, Is.EqualTo(newreg.ServerHttpPort))");
148 Assert.That(retreg.ServerRemotingPort, Is.EqualTo(newreg.ServerRemotingPort), "Assert.That(retreg.ServerRemotingPort, Is.EqualTo(newreg.ServerRemotingPort))");
149 Assert.That(retreg.NorthOverrideHandle, Is.EqualTo(newreg.NorthOverrideHandle), "Assert.That(retreg.NorthOverrideHandle, Is.EqualTo(newreg.NorthOverrideHandle))");
150 Assert.That(retreg.SouthOverrideHandle, Is.EqualTo(newreg.SouthOverrideHandle), "Assert.That(retreg.SouthOverrideHandle, Is.EqualTo(newreg.SouthOverrideHandle))");
151 Assert.That(retreg.EastOverrideHandle, Is.EqualTo(newreg.EastOverrideHandle), "Assert.That(retreg.EastOverrideHandle, Is.EqualTo(newreg.EastOverrideHandle))");
152 Assert.That(retreg.WestOverrideHandle, Is.EqualTo(newreg.WestOverrideHandle), "Assert.That(retreg.WestOverrideHandle, Is.EqualTo(newreg.WestOverrideHandle))");
153 Assert.That(retreg.RegionDataURI, Is.EqualTo(newreg.RegionDataURI), "Assert.That(retreg.RegionDataURI, Is.EqualTo(newreg.RegionDataURI))");
154 Assert.That(retreg.RegionAssetURI, Is.EqualTo(newreg.RegionAssetURI), "Assert.That(retreg.RegionAssetURI, Is.EqualTo(newreg.RegionAssetURI))");
155 Assert.That(retreg.RegionAssetSendKey, Is.EqualTo(newreg.RegionAssetSendKey), "Assert.That(retreg.RegionAssetSendKey, Is.EqualTo(newreg.RegionAssetSendKey))");
156 Assert.That(retreg.RegionAssetRecvKey, Is.EqualTo(newreg.RegionAssetRecvKey), "Assert.That(retreg.RegionAssetRecvKey, Is.EqualTo(newreg.RegionAssetRecvKey))");
157 Assert.That(retreg.RegionUserURI, Is.EqualTo(newreg.RegionUserURI), "Assert.That(retreg.RegionUserURI, Is.EqualTo(newreg.RegionUserURI))");
158 Assert.That(retreg.RegionUserSendKey, Is.EqualTo(newreg.RegionUserSendKey), "Assert.That(retreg.RegionUserSendKey, Is.EqualTo(newreg.RegionUserSendKey))");
159 Assert.That(retreg.RegionUserRecvKey, Is.EqualTo(newreg.RegionUserRecvKey), "Assert.That(retreg.RegionUserRecvKey, Is.EqualTo(newreg.RegionUserRecvKey))");
160 Assert.That(retreg.RegionMapTextureID, Is.EqualTo(newreg.RegionMapTextureID), "Assert.That(retreg.RegionMapTextureID, Is.EqualTo(newreg.RegionMapTextureID))");
161 Assert.That(retreg.Owner_uuid, Is.EqualTo(newreg.Owner_uuid), "Assert.That(retreg.Owner_uuid, Is.EqualTo(newreg.Owner_uuid))");
162 Assert.That(retreg.OriginUUID, Is.EqualTo(newreg.OriginUUID), "Assert.That(retreg.OriginUUID, Is.EqualTo(newreg.OriginUUID))");
163 94
164 retreg = db.GetProfileByHandle(newreg.RegionHandle); 95 retreg = db.GetProfileByHandle(newreg.RegionHandle);
165 Assert.That(retreg.Uuid, Is.EqualTo(region2), "Assert.That(retreg.Uuid, Is.EqualTo(region2))"); 96 Assert.That(retreg.Uuid, Is.EqualTo(region2), "Assert.That(retreg.Uuid, Is.EqualTo(region2))");
@@ -220,6 +151,12 @@ namespace OpenSim.Data.Tests
220 Assert.That(listreg[1].Uuid, Is.EqualTo(region1) | Is.EqualTo(region2), "Assert.That(listreg[1].Uuid, Is.EqualTo(region1) | Is.EqualTo(region2))"); 151 Assert.That(listreg[1].Uuid, Is.EqualTo(region1) | Is.EqualTo(region2), "Assert.That(listreg[1].Uuid, Is.EqualTo(region1) | Is.EqualTo(region2))");
221 } 152 }
222 153
154 [Test]
155 public void T999_StillNull()
156 {
157 Assert.That(db.GetProfileByUUID(zero), Is.Null);
158 }
159
223 protected static string RandomName() 160 protected static string RandomName()
224 { 161 {
225 StringBuilder name = new StringBuilder(); 162 StringBuilder name = new StringBuilder();
diff --git a/OpenSim/Data/Tests/BasicInventoryTest.cs b/OpenSim/Data/Tests/BasicInventoryTest.cs
index e13ed89..900186b 100644
--- a/OpenSim/Data/Tests/BasicInventoryTest.cs
+++ b/OpenSim/Data/Tests/BasicInventoryTest.cs
@@ -66,14 +66,7 @@ namespace OpenSim.Data.Tests
66 66
67 public void SuperInit() 67 public void SuperInit()
68 { 68 {
69 try 69 OpenSim.Tests.Common.TestLogging.LogToConsole();
70 {
71 XmlConfigurator.Configure();
72 }
73 catch (Exception)
74 {
75 // I don't care, just leave log4net off
76 }
77 70
78 folder1 = UUID.Random(); 71 folder1 = UUID.Random();
79 folder2 = UUID.Random(); 72 folder2 = UUID.Random();
@@ -115,16 +108,6 @@ namespace OpenSim.Data.Tests
115 Assert.That(db.getUserRootFolder(owner1), Is.Null); 108 Assert.That(db.getUserRootFolder(owner1), Is.Null);
116 } 109 }
117 110
118 [Test]
119 public void T999_StillNull()
120 {
121 // After all tests are run, these should still return no results
122 Assert.That(db.getInventoryFolder(zero), Is.Null);
123 Assert.That(db.getInventoryItem(zero), Is.Null);
124 Assert.That(db.getUserRootFolder(zero), Is.Null);
125 Assert.That(db.getInventoryInFolder(zero).Count, Is.EqualTo(0), "Assert.That(db.getInventoryInFolder(zero).Count, Is.EqualTo(0))");
126 }
127
128 // 01x - folder tests 111 // 01x - folder tests
129 [Test] 112 [Test]
130 public void T010_FolderNonParent() 113 public void T010_FolderNonParent()
@@ -248,7 +231,7 @@ namespace OpenSim.Data.Tests
248 } 231 }
249 232
250 [Test] 233 [Test]
251 public void T103UpdateItem() 234 public void T103_UpdateItem()
252 { 235 {
253 // TODO: probably shouldn't have the ability to have an 236 // TODO: probably shouldn't have the ability to have an
254 // owner of an item in a folder not owned by the user 237 // owner of an item in a folder not owned by the user
@@ -265,6 +248,71 @@ namespace OpenSim.Data.Tests
265 Assert.That(i1.Owner, Is.EqualTo(owner2), "Assert.That(i1.Owner, Is.EqualTo(owner2))"); 248 Assert.That(i1.Owner, Is.EqualTo(owner2), "Assert.That(i1.Owner, Is.EqualTo(owner2))");
266 } 249 }
267 250
251 [Test]
252 public void T104_RandomUpdateItem()
253 {
254 PropertyScrambler<InventoryFolderBase> folderScrambler =
255 new PropertyScrambler<InventoryFolderBase>()
256 .DontScramble(x => x.Owner)
257 .DontScramble(x => x.ParentID)
258 .DontScramble(x => x.ID);
259 UUID owner = UUID.Random();
260 UUID folder = UUID.Random();
261 UUID rootId = UUID.Random();
262 UUID rootAsset = UUID.Random();
263 InventoryFolderBase f1 = NewFolder(folder, zero, owner, name1);
264 folderScrambler.Scramble(f1);
265
266 db.addInventoryFolder(f1);
267 InventoryFolderBase f1a = db.getUserRootFolder(owner);
268 Assert.That(f1a, Constraints.PropertyCompareConstraint(f1));
269
270 folderScrambler.Scramble(f1a);
271
272 db.updateInventoryFolder(f1a);
273
274 InventoryFolderBase f1b = db.getUserRootFolder(owner);
275 Assert.That(f1b, Constraints.PropertyCompareConstraint(f1a));
276
277 //Now we have a valid folder to insert into, we can insert the item.
278 PropertyScrambler<InventoryItemBase> inventoryScrambler =
279 new PropertyScrambler<InventoryItemBase>()
280 .DontScramble(x => x.ID)
281 .DontScramble(x => x.AssetID)
282 .DontScramble(x => x.Owner)
283 .DontScramble(x => x.Folder);
284 InventoryItemBase root = NewItem(rootId, folder, owner, iname1, rootAsset);
285 inventoryScrambler.Scramble(root);
286 db.addInventoryItem(root);
287
288 InventoryItemBase expected = db.getInventoryItem(rootId);
289 Assert.That(expected, Constraints.PropertyCompareConstraint(root)
290 .IgnoreProperty(x => x.InvType)
291 .IgnoreProperty(x => x.CreatorIdAsUuid)
292 .IgnoreProperty(x => x.Description)
293 .IgnoreProperty(x => x.CreatorId));
294
295 inventoryScrambler.Scramble(expected);
296 db.updateInventoryItem(expected);
297
298 InventoryItemBase actual = db.getInventoryItem(rootId);
299 Assert.That(actual, Constraints.PropertyCompareConstraint(expected)
300 .IgnoreProperty(x => x.InvType)
301 .IgnoreProperty(x => x.CreatorIdAsUuid)
302 .IgnoreProperty(x => x.Description)
303 .IgnoreProperty(x => x.CreatorId));
304 }
305
306 [Test]
307 public void T999_StillNull()
308 {
309 // After all tests are run, these should still return no results
310 Assert.That(db.getInventoryFolder(zero), Is.Null);
311 Assert.That(db.getInventoryItem(zero), Is.Null);
312 Assert.That(db.getUserRootFolder(zero), Is.Null);
313 Assert.That(db.getInventoryInFolder(zero).Count, Is.EqualTo(0), "Assert.That(db.getInventoryInFolder(zero).Count, Is.EqualTo(0))");
314 }
315
268 private InventoryItemBase NewItem(UUID id, UUID parent, UUID owner, string name, UUID asset) 316 private InventoryItemBase NewItem(UUID id, UUID parent, UUID owner, string name, UUID asset)
269 { 317 {
270 InventoryItemBase i = new InventoryItemBase(); 318 InventoryItemBase i = new InventoryItemBase();
diff --git a/OpenSim/Data/Tests/BasicRegionTest.cs b/OpenSim/Data/Tests/BasicRegionTest.cs
index 836da78..8474921 100644
--- a/OpenSim/Data/Tests/BasicRegionTest.cs
+++ b/OpenSim/Data/Tests/BasicRegionTest.cs
@@ -71,14 +71,7 @@ namespace OpenSim.Data.Tests
71 71
72 public void SuperInit() 72 public void SuperInit()
73 { 73 {
74 try 74 OpenSim.Tests.Common.TestLogging.LogToConsole();
75 {
76 XmlConfigurator.Configure();
77 }
78 catch (Exception)
79 {
80 // I don't care, just leave log4net off
81 }
82 75
83 region1 = UUID.Random(); 76 region1 = UUID.Random();
84 region3 = UUID.Random(); 77 region3 = UUID.Random();
@@ -532,6 +525,62 @@ namespace OpenSim.Data.Tests
532 Assert.That(cursop.Acceleration,Is.EqualTo(parts[i].Acceleration), "Assert.That(cursop.Acceleration,Is.EqualTo(parts[i].Acceleration))"); 525 Assert.That(cursop.Acceleration,Is.EqualTo(parts[i].Acceleration), "Assert.That(cursop.Acceleration,Is.EqualTo(parts[i].Acceleration))");
533 } 526 }
534 } 527 }
528
529 [Test]
530 public void T016_RandomSogWithSceneParts()
531 {
532 PropertyScrambler<SceneObjectPart> scrambler =
533 new PropertyScrambler<SceneObjectPart>()
534 .DontScramble(x => x.UUID);
535 UUID tmpSog = UUID.Random();
536 UUID tmp1 = UUID.Random();
537 UUID tmp2 = UUID.Random();
538 UUID tmp3 = UUID.Random();
539 UUID newregion = UUID.Random();
540 SceneObjectPart p1 = new SceneObjectPart();
541 SceneObjectPart p2 = new SceneObjectPart();
542 SceneObjectPart p3 = new SceneObjectPart();
543 p1.Shape = PrimitiveBaseShape.Default;
544 p2.Shape = PrimitiveBaseShape.Default;
545 p3.Shape = PrimitiveBaseShape.Default;
546 p1.UUID = tmp1;
547 p2.UUID = tmp2;
548 p3.UUID = tmp3;
549 scrambler.Scramble(p1);
550 scrambler.Scramble(p2);
551 scrambler.Scramble(p3);
552
553 SceneObjectGroup sog = NewSOG("Sop 0", tmpSog, newregion);
554 PropertyScrambler<SceneObjectGroup> sogScrambler =
555 new PropertyScrambler<SceneObjectGroup>()
556 .DontScramble(x => x.UUID);
557 sogScrambler.Scramble(sog);
558 sog.UUID = tmpSog;
559 sog.AddPart(p1);
560 sog.AddPart(p2);
561 sog.AddPart(p3);
562
563 SceneObjectPart[] parts = sog.GetParts();
564 Assert.That(parts.Length, Is.EqualTo(4), "Assert.That(parts.Length,Is.EqualTo(4))");
565
566 db.StoreObject(sog, newregion);
567 List<SceneObjectGroup> sogs = db.LoadObjects(newregion);
568 Assert.That(sogs.Count, Is.EqualTo(1), "Assert.That(sogs.Count,Is.EqualTo(1))");
569 SceneObjectGroup newsog = sogs[0];
570
571 SceneObjectPart[] newparts = newsog.GetParts();
572 Assert.That(newparts.Length, Is.EqualTo(4), "Assert.That(newparts.Length,Is.EqualTo(4))");
573
574 Assert.That(newsog, Constraints.PropertyCompareConstraint(sog)
575 .IgnoreProperty(x=>x.LocalId)
576 .IgnoreProperty(x=>x.HasGroupChanged)
577 .IgnoreProperty(x=>x.IsSelected)
578 .IgnoreProperty(x=>x.RegionHandle)
579 .IgnoreProperty(x=>x.RegionUUID)
580 .IgnoreProperty(x=>x.Scene)
581 .IgnoreProperty(x=>x.Children)
582 .IgnoreProperty(x=>x.RootPart));
583 }
535 584
536 [Test] 585 [Test]
537 public void T020_PrimInventoryEmpty() 586 public void T020_PrimInventoryEmpty()
diff --git a/OpenSim/Data/Tests/BasicUserTest.cs b/OpenSim/Data/Tests/BasicUserTest.cs
index 4e4ddc8..f9feb9b 100644
--- a/OpenSim/Data/Tests/BasicUserTest.cs
+++ b/OpenSim/Data/Tests/BasicUserTest.cs
@@ -71,14 +71,7 @@ namespace OpenSim.Data.Tests
71 71
72 public void SuperInit() 72 public void SuperInit()
73 { 73 {
74 try 74 OpenSim.Tests.Common.TestLogging.LogToConsole();
75 {
76 XmlConfigurator.Configure();
77 }
78 catch (Exception)
79 {
80 // I don't care, just leave log4net off
81 }
82 random = new Random(); 75 random = new Random();
83 user1 = UUID.Random(); 76 user1 = UUID.Random();
84 user2 = UUID.Random(); 77 user2 = UUID.Random();
@@ -118,13 +111,6 @@ namespace OpenSim.Data.Tests
118 } 111 }
119 112
120 [Test] 113 [Test]
121 public void T999_StillNull()
122 {
123 Assert.That(db.GetUserByUUID(zero), Is.Null);
124 Assert.That(db.GetAgentByUUID(zero), Is.Null);
125 }
126
127 [Test]
128 public void T010_CreateUser() 114 public void T010_CreateUser()
129 { 115 {
130 UserProfileData u1 = NewUser(user1,fname1,lname1); 116 UserProfileData u1 = NewUser(user1,fname1,lname1);
@@ -396,6 +382,22 @@ namespace OpenSim.Data.Tests
396 Assert.That(customtype,Is.EqualTo(u1a.CustomType), "Assert.That(customtype,Is.EqualTo(u1a.CustomType))"); 382 Assert.That(customtype,Is.EqualTo(u1a.CustomType), "Assert.That(customtype,Is.EqualTo(u1a.CustomType))");
397 Assert.That(partner,Is.EqualTo(u1a.Partner), "Assert.That(partner,Is.EqualTo(u1a.Partner))"); 383 Assert.That(partner,Is.EqualTo(u1a.Partner), "Assert.That(partner,Is.EqualTo(u1a.Partner))");
398 } 384 }
385
386 [Test]
387 public void T017_UserUpdateRandomPersistency()
388 {
389 UUID id = user5;
390 UserProfileData u = db.GetUserByUUID(id);
391 new PropertyScrambler<UserProfileData>().DontScramble(x=>x.ID).Scramble(u);
392
393 db.UpdateUserProfile(u);
394 UserProfileData u1a = db.GetUserByUUID(id);
395 Assert.That(u1a, Constraints.PropertyCompareConstraint(u)
396 .IgnoreProperty(x=>x.HomeRegionX)
397 .IgnoreProperty(x=>x.HomeRegionY)
398 .IgnoreProperty(x=>x.RootInventoryFolderID)
399 );
400 }
399 401
400 [Test] 402 [Test]
401 public void T020_CreateAgent() 403 public void T020_CreateAgent()
@@ -660,6 +662,13 @@ namespace OpenSim.Data.Tests
660 Assert.That(avatarheight,Is.EqualTo(app.AvatarHeight), "Assert.That(avatarheight,Is.EqualTo(app.AvatarHeight))"); 662 Assert.That(avatarheight,Is.EqualTo(app.AvatarHeight), "Assert.That(avatarheight,Is.EqualTo(app.AvatarHeight))");
661 } 663 }
662 664
665 [Test]
666 public void T999_StillNull()
667 {
668 Assert.That(db.GetUserByUUID(zero), Is.Null);
669 Assert.That(db.GetAgentByUUID(zero), Is.Null);
670 }
671
663 public UserProfileData NewUser(UUID id,string fname,string lname) 672 public UserProfileData NewUser(UUID id,string fname,string lname)
664 { 673 {
665 UserProfileData u = new UserProfileData(); 674 UserProfileData u = new UserProfileData();
diff --git a/OpenSim/Data/Tests/PropertyCompareConstraint.cs b/OpenSim/Data/Tests/PropertyCompareConstraint.cs
index 678501e..06ca53e 100644
--- a/OpenSim/Data/Tests/PropertyCompareConstraint.cs
+++ b/OpenSim/Data/Tests/PropertyCompareConstraint.cs
@@ -1,3 +1,30 @@
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
1using System; 28using System;
2using System.Collections; 29using System.Collections;
3using System.Collections.Generic; 30using System.Collections.Generic;
@@ -42,6 +69,28 @@ namespace OpenSim.Data.Tests
42 69
43 private bool ObjectCompare(object expected, object actual, Stack<string> propertyNames) 70 private bool ObjectCompare(object expected, object actual, Stack<string> propertyNames)
44 { 71 {
72 //If they are both null, they are equal
73 if (actual == null && expected == null)
74 return true;
75
76 //If only one is null, then they aren't
77 if (actual == null || expected == null)
78 {
79 failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray());
80 failingActual = actual;
81 failingExpected = expected;
82 return false;
83 }
84
85 //prevent loops...
86 if (propertyNames.Count > 50)
87 {
88 failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray());
89 failingActual = actual;
90 failingExpected = expected;
91 return false;
92 }
93
45 if (actual.GetType() != expected.GetType()) 94 if (actual.GetType() != expected.GetType())
46 { 95 {
47 propertyNames.Push("GetType()"); 96 propertyNames.Push("GetType()");
@@ -52,7 +101,7 @@ namespace OpenSim.Data.Tests
52 return false; 101 return false;
53 } 102 }
54 103
55 if(actual.GetType() == typeof(Color)) 104 if (actual.GetType() == typeof(Color))
56 { 105 {
57 Color actualColor = (Color) actual; 106 Color actualColor = (Color) actual;
58 Color expectedColor = (Color) expected; 107 Color expectedColor = (Color) expected;
@@ -95,65 +144,69 @@ namespace OpenSim.Data.Tests
95 return true; 144 return true;
96 } 145 }
97 146
98 //Skip static properties. I had a nasty problem comparing colors because of all of the public static colors. 147 IComparable comp = actual as IComparable;
99 PropertyInfo[] properties = expected.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); 148 if (comp != null)
100 foreach (var property in properties)
101 { 149 {
102 if (ignores.Contains(property.Name)) 150 if (comp.CompareTo(expected) != 0)
103 continue; 151 {
104 152 failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray());
105 object actualValue = property.GetValue(actual, null); 153 failingActual = actual;
106 object expectedValue = property.GetValue(expected, null); 154 failingExpected = expected;
155 return false;
156 }
157 return true;
158 }
107 159
108 //If they are both null, they are equal 160 //Now try the much more annoying IComparable<T>
109 if (actualValue == null && expectedValue == null) 161 Type icomparableInterface = actual.GetType().GetInterface("IComparable`1");
110 continue; 162 if (icomparableInterface != null)
163 {
164 int result = (int)icomparableInterface.GetMethod("CompareTo").Invoke(actual, new[] { expected });
165 if (result != 0)
166 {
167 failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray());
168 failingActual = actual;
169 failingExpected = expected;
170 return false;
171 }
172 return true;
173 }
111 174
112 //If only one is null, then they aren't 175 IEnumerable arr = actual as IEnumerable;
113 if (actualValue == null || expectedValue == null) 176 if (arr != null)
177 {
178 List<object> actualList = arr.Cast<object>().ToList();
179 List<object> expectedList = ((IEnumerable)expected).Cast<object>().ToList();
180 if (actualList.Count != expectedList.Count)
114 { 181 {
115 propertyNames.Push(property.Name); 182 propertyNames.Push("Count");
116 failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); 183 failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray());
184 failingActual = actualList.Count;
185 failingExpected = expectedList.Count;
117 propertyNames.Pop(); 186 propertyNames.Pop();
118 failingActual = actualValue;
119 failingExpected = expectedValue;
120 return false; 187 return false;
121 } 188 }
122 189 //actualList and expectedList should be the same size.
123 IComparable comp = actualValue as IComparable; 190 for (int i = 0; i < actualList.Count; i++)
124 if (comp != null)
125 { 191 {
126 if (comp.CompareTo(expectedValue) != 0) 192 propertyNames.Push("[" + i + "]");
127 { 193 if (!ObjectCompare(expectedList[i], actualList[i], propertyNames))
128 propertyNames.Push(property.Name);
129 failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray());
130 propertyNames.Pop();
131 failingActual = actualValue;
132 failingExpected = expectedValue;
133 return false; 194 return false;
134 } 195 propertyNames.Pop();
135 continue;
136 } 196 }
197 //Everything seems okay...
198 return true;
199 }
137 200
138 IEnumerable arr = actualValue as IEnumerable; 201 //Skip static properties. I had a nasty problem comparing colors because of all of the public static colors.
139 if (arr != null) 202 PropertyInfo[] properties = expected.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
140 { 203 foreach (var property in properties)
141 List<object> actualList = arr.Cast<object>().ToList(); 204 {
142 List<object> expectedList = ((IEnumerable)expectedValue).Cast<object>().ToList(); 205 if (ignores.Contains(property.Name))
143 if (actualList.Count != expectedList.Count)
144 {
145 propertyNames.Push(property.Name);
146 propertyNames.Push("Count");
147 failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray());
148 failingActual = actualList.Count;
149 failingExpected = expectedList.Count;
150 propertyNames.Pop();
151 propertyNames.Pop();
152 }
153 //Todo: A value-wise comparison of all of the values.
154 //Everything seems okay...
155 continue; 206 continue;
156 } 207
208 object actualValue = property.GetValue(actual, null);
209 object expectedValue = property.GetValue(expected, null);
157 210
158 propertyNames.Push(property.Name); 211 propertyNames.Push(property.Name);
159 if (!ObjectCompare(expectedValue, actualValue, propertyNames)) 212 if (!ObjectCompare(expectedValue, actualValue, propertyNames))
@@ -196,15 +249,7 @@ namespace OpenSim.Data.Tests
196 { 249 {
197 //If the inside of the lambda is the access to x, we've hit the end of the chain. 250 //If the inside of the lambda is the access to x, we've hit the end of the chain.
198 // We should track by the fully scoped parameter name, but this is the first rev of doing this. 251 // We should track by the fully scoped parameter name, but this is the first rev of doing this.
199 if (((MemberExpression)express).Expression is ParameterExpression) 252 ignores.Add(((MemberExpression)express).Member.Name);
200 {
201 ignores.Add(((MemberExpression)express).Member.Name);
202 }
203 else
204 {
205 //Otherwise there could be more parameters inside...
206 PullApartExpression(((MemberExpression)express).Expression);
207 }
208 } 253 }
209 } 254 }
210 } 255 }
@@ -243,7 +288,7 @@ namespace OpenSim.Data.Tests
243 { 288 {
244 HasInt actual = new HasInt { TheValue = 5 }; 289 HasInt actual = new HasInt { TheValue = 5 };
245 HasInt expected = new HasInt { TheValue = 4 }; 290 HasInt expected = new HasInt { TheValue = 4 };
246 var constraint = Constraints.PropertyCompareConstraint(expected).IgnoreProperty(x=>x.TheValue); 291 var constraint = Constraints.PropertyCompareConstraint(expected).IgnoreProperty(x => x.TheValue);
247 292
248 Assert.That(constraint.Matches(actual), Is.True); 293 Assert.That(constraint.Matches(actual), Is.True);
249 } 294 }
@@ -285,6 +330,28 @@ namespace OpenSim.Data.Tests
285 } 330 }
286 331
287 [Test] 332 [Test]
333 public void UUIDShouldMatch()
334 {
335 UUID uuid1 = UUID.Random();
336 UUID uuid2 = UUID.Parse(uuid1.ToString());
337
338 var constraint = Constraints.PropertyCompareConstraint(uuid1);
339
340 Assert.That(constraint.Matches(uuid2), Is.True);
341 }
342
343 [Test]
344 public void UUIDShouldNotMatch()
345 {
346 UUID uuid1 = UUID.Random();
347 UUID uuid2 = UUID.Random();
348
349 var constraint = Constraints.PropertyCompareConstraint(uuid1);
350
351 Assert.That(constraint.Matches(uuid2), Is.False);
352 }
353
354 [Test]
288 public void TestColors() 355 public void TestColors()
289 { 356 {
290 Color actual = Color.Red; 357 Color actual = Color.Red;
@@ -294,5 +361,53 @@ namespace OpenSim.Data.Tests
294 361
295 Assert.That(constraint.Matches(actual), Is.True); 362 Assert.That(constraint.Matches(actual), Is.True);
296 } 363 }
364
365 [Test]
366 public void ShouldCompareLists()
367 {
368 List<int> expected = new List<int> { 1, 2, 3 };
369 List<int> actual = new List<int> { 1, 2, 3 };
370
371 var constraint = Constraints.PropertyCompareConstraint(expected);
372 Assert.That(constraint.Matches(actual), Is.True);
373 }
374
375
376 [Test]
377 public void ShouldFailToCompareListsThatAreDifferent()
378 {
379 List<int> expected = new List<int> { 1, 2, 3 };
380 List<int> actual = new List<int> { 1, 2, 4 };
381
382 var constraint = Constraints.PropertyCompareConstraint(expected);
383 Assert.That(constraint.Matches(actual), Is.False);
384 }
385
386 [Test]
387 public void ShouldFailToCompareListsThatAreDifferentLengths()
388 {
389 List<int> expected = new List<int> { 1, 2, 3 };
390 List<int> actual = new List<int> { 1, 2 };
391
392 var constraint = Constraints.PropertyCompareConstraint(expected);
393 Assert.That(constraint.Matches(actual), Is.False);
394 }
395
396 public class Recursive
397 {
398 public Recursive Other { get; set; }
399 }
400
401 [Test]
402 public void ErrorsOutOnRecursive()
403 {
404 Recursive parent = new Recursive();
405 Recursive child = new Recursive();
406 parent.Other = child;
407 child.Other = parent;
408
409 var constraint = Constraints.PropertyCompareConstraint(child);
410 Assert.That(constraint.Matches(child), Is.False);
411 }
297 } 412 }
298} \ No newline at end of file 413} \ No newline at end of file
diff --git a/OpenSim/Data/Tests/PropertyScrambler.cs b/OpenSim/Data/Tests/PropertyScrambler.cs
new file mode 100644
index 0000000..72aaff1
--- /dev/null
+++ b/OpenSim/Data/Tests/PropertyScrambler.cs
@@ -0,0 +1,186 @@
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;
30using System.Collections.Generic;
31using System.Linq.Expressions;
32using System.Reflection;
33using System.Text;
34using NUnit.Framework;
35using NUnit.Framework.SyntaxHelpers;
36using OpenMetaverse;
37using OpenSim.Framework;
38
39namespace OpenSim.Data.Tests
40{
41
42 //This is generic so that the lambda expressions will work right in IDEs.
43 public class PropertyScrambler<T>
44 {
45 readonly System.Collections.Generic.List<string> membersToNotScramble = new List<string>();
46
47 private void AddExpressionToNotScrableList(Expression expression)
48 {
49 UnaryExpression unaryExpression = expression as UnaryExpression;
50 if (unaryExpression != null)
51 {
52 AddExpressionToNotScrableList(unaryExpression.Operand);
53 return;
54 }
55
56 MemberExpression memberExpression = expression as MemberExpression;
57 if (memberExpression != null)
58 {
59 if (!(memberExpression.Member is PropertyInfo))
60 {
61 throw new NotImplementedException("I don't know how deal with a MemberExpression that is a " + expression.Type);
62 }
63 membersToNotScramble.Add(memberExpression.Member.Name);
64 return;
65 }
66
67 throw new NotImplementedException("I don't know how to parse a " + expression.Type);
68 }
69
70 public PropertyScrambler<T> DontScramble(Expression<Func<T, object>> expression)
71 {
72 AddExpressionToNotScrableList(expression.Body);
73 return this;
74 }
75
76 public void Scramble(T obj)
77 {
78 internalScramble(obj);
79 }
80
81 private void internalScramble(object obj)
82 {
83 PropertyInfo[] properties = obj.GetType().GetProperties();
84 foreach (var property in properties)
85 {
86 //Skip indexers of classes. We will assume that everything that has an indexer
87 // is also IEnumberable. May not always be true, but should be true normally.
88 if (property.GetIndexParameters().Length > 0)
89 continue;
90
91 RandomizeProperty(obj, property, null);
92 }
93 //Now if it implments IEnumberable, it's probably some kind of list, so we should randomize
94 // everything inside of it.
95 IEnumerable enumerable = obj as IEnumerable;
96 if (enumerable != null)
97 {
98 foreach (object value in enumerable)
99 {
100 internalScramble(value);
101 }
102 }
103 }
104
105 private readonly Random random = new Random();
106 private void RandomizeProperty(object obj, PropertyInfo property, object[] index)
107 {//I'd like a better way to compare, but I had lots of problems with InventoryFolderBase because the ID is inherited.
108 if (membersToNotScramble.Contains(property.Name))
109 return;
110 Type t = property.PropertyType;
111 if (!property.CanWrite)
112 return;
113 object value = property.GetValue(obj, index);
114 if (value == null)
115 return;
116
117 if (t == typeof(string))
118 property.SetValue(obj, RandomName(), index);
119 else if (t == typeof(UUID))
120 property.SetValue(obj, UUID.Random(), index);
121 else if (t == typeof(sbyte))
122 property.SetValue(obj, (sbyte)random.Next(sbyte.MinValue, sbyte.MaxValue), index);
123 else if (t == typeof(short))
124 property.SetValue(obj, (short)random.Next(short.MinValue, short.MaxValue), index);
125 else if (t == typeof(int))
126 property.SetValue(obj, random.Next(), index);
127 else if (t == typeof(long))
128 property.SetValue(obj, random.Next() * int.MaxValue, index);
129 else if (t == typeof(byte))
130 property.SetValue(obj, (byte)random.Next(byte.MinValue, byte.MaxValue), index);
131 else if (t == typeof(ushort))
132 property.SetValue(obj, (ushort)random.Next(ushort.MinValue, ushort.MaxValue), index);
133 else if (t == typeof(uint))
134 property.SetValue(obj, Convert.ToUInt32(random.Next()), index);
135 else if (t == typeof(ulong))
136 property.SetValue(obj, Convert.ToUInt64(random.Next()) * Convert.ToUInt64(UInt32.MaxValue), index);
137 else if (t == typeof(bool))
138 property.SetValue(obj, true, index);
139 else if (t == typeof(byte[]))
140 {
141 byte[] bytes = new byte[30];
142 random.NextBytes(bytes);
143 property.SetValue(obj, bytes, index);
144 }
145 else
146 internalScramble(value);
147 }
148
149 private string RandomName()
150 {
151 StringBuilder name = new StringBuilder();
152 int size = random.Next(5, 12);
153 for (int i = 0; i < size; i++)
154 {
155 char ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
156 name.Append(ch);
157 }
158 return name.ToString();
159 }
160 }
161
162 [TestFixture]
163 public class PropertyScramblerTests
164 {
165 [Test]
166 public void TestScramble()
167 {
168 AssetBase actual = new AssetBase(UUID.Random(), "asset one");
169 new PropertyScrambler<AssetBase>().Scramble(actual);
170 }
171
172 [Test]
173 public void DontScramble()
174 {
175 UUID uuid = UUID.Random();
176 AssetBase asset = new AssetBase();
177 asset.FullID = uuid;
178 new PropertyScrambler<AssetBase>()
179 .DontScramble(x => x.Metadata)
180 .DontScramble(x => x.FullID)
181 .DontScramble(x => x.ID)
182 .Scramble(asset);
183 Assert.That(asset.FullID, Is.EqualTo(uuid));
184 }
185 }
186} \ No newline at end of file
diff --git a/OpenSim/Data/Tests/ScrambleForTesting.cs b/OpenSim/Data/Tests/ScrambleForTesting.cs
deleted file mode 100644
index c6e467f..0000000
--- a/OpenSim/Data/Tests/ScrambleForTesting.cs
+++ /dev/null
@@ -1,102 +0,0 @@
1using System;
2using System.Collections;
3using System.Reflection;
4using System.Text;
5using NUnit.Framework;
6using OpenMetaverse;
7using OpenSim.Framework;
8
9namespace OpenSim.Data.Tests
10{
11 public static class ScrambleForTesting
12 {
13 private static readonly Random random = new Random();
14 public static void Scramble(object obj)
15 {
16 PropertyInfo[] properties = obj.GetType().GetProperties();
17 foreach (var property in properties)
18 {
19 //Skip indexers of classes. We will assume that everything that has an indexer
20 // is also IEnumberable. May not always be true, but should be true normally.
21 if(property.GetIndexParameters().Length > 0)
22 continue;
23
24 RandomizeProperty(obj, property, null);
25 }
26 //Now if it implments IEnumberable, it's probably some kind of list, so we should randomize
27 // everything inside of it.
28 IEnumerable enumerable = obj as IEnumerable;
29 if(enumerable != null)
30 {
31 foreach (object value in enumerable)
32 {
33 Scramble(value);
34 }
35 }
36 }
37
38 private static void RandomizeProperty(object obj, PropertyInfo property, object[] index)
39 {
40 Type t = property.PropertyType;
41 if (!property.CanWrite)
42 return;
43 object value = property.GetValue(obj, index);
44 if (value == null)
45 return;
46
47 if (t == typeof (string))
48 property.SetValue(obj, RandomName(), index);
49 else if (t == typeof (UUID))
50 property.SetValue(obj, UUID.Random(), index);
51 else if (t == typeof (sbyte))
52 property.SetValue(obj, (sbyte)random.Next(sbyte.MinValue, sbyte.MaxValue), index);
53 else if (t == typeof (short))
54 property.SetValue(obj, (short)random.Next(short.MinValue, short.MaxValue), index);
55 else if (t == typeof (int))
56 property.SetValue(obj, random.Next(), index);
57 else if (t == typeof (long))
58 property.SetValue(obj, random.Next() * int.MaxValue, index);
59 else if (t == typeof (byte))
60 property.SetValue(obj, (byte)random.Next(byte.MinValue, byte.MaxValue), index);
61 else if (t == typeof (ushort))
62 property.SetValue(obj, (ushort)random.Next(ushort.MinValue, ushort.MaxValue), index);
63 else if (t == typeof (uint))
64 property.SetValue(obj, Convert.ToUInt32(random.Next()), index);
65 else if (t == typeof (ulong))
66 property.SetValue(obj, Convert.ToUInt64(random.Next()) * Convert.ToUInt64(UInt32.MaxValue), index);
67 else if (t == typeof (bool))
68 property.SetValue(obj, true, index);
69 else if (t == typeof (byte[]))
70 {
71 byte[] bytes = new byte[30];
72 random.NextBytes(bytes);
73 property.SetValue(obj, bytes, index);
74 }
75 else
76 Scramble(value);
77 }
78
79 private static string RandomName()
80 {
81 StringBuilder name = new StringBuilder();
82 int size = random.Next(5, 12);
83 for (int i = 0; i < size; i++)
84 {
85 char ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
86 name.Append(ch);
87 }
88 return name.ToString();
89 }
90 }
91
92 [TestFixture]
93 public class ScrableForTestingTest
94 {
95 [Test]
96 public void TestScramble()
97 {
98 AssetBase actual = new AssetBase(UUID.Random(), "asset one");
99 ScrambleForTesting.Scramble(actual);
100 }
101 }
102} \ No newline at end of file