diff options
author | Kunnis | 2009-08-15 06:08:36 -0500 |
---|---|---|
committer | Teravus Ovares (Dan Olivares) | 2009-08-16 14:15:59 -0400 |
commit | f6251ce810e0bebe68d08a8e4b20a9dfc3fe1af6 (patch) | |
tree | 667e7744e3a28c0a611fc1f71b4a1a56b71980c8 /OpenSim | |
parent | Adding in Reflection-based testing, to ensure that all properties are covered. (diff) | |
download | opensim-SC_OLD-f6251ce810e0bebe68d08a8e4b20a9dfc3fe1af6.zip opensim-SC_OLD-f6251ce810e0bebe68d08a8e4b20a9dfc3fe1af6.tar.gz opensim-SC_OLD-f6251ce810e0bebe68d08a8e4b20a9dfc3fe1af6.tar.bz2 opensim-SC_OLD-f6251ce810e0bebe68d08a8e4b20a9dfc3fe1af6.tar.xz |
* Modified SQLite/SQLiteInventoryStore.cs to not throw if the inventory row does not exist, to match the mysql behavior. * Modified SQLite/SQLiteRegionData.cs to only persist temporary items following the same rules mysql uses. * Added another ignore to the inventory test that was missing. * Added a few more ignores to the RegionTest that the first version of my test were missing. * Added ignoring the root Folder ID, which is set by the inventory system. * Added several improvements to the PropertyCompareConstraint: Protection against infinite loops, added IComparable<T> (for UUID) and moved IComparable before the property matching. * Fixed a bug where I was saving the inside of the ignore expression instead of the outside of it.
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Data/SQLite/SQLiteInventoryStore.cs | 3 | ||||
-rw-r--r-- | OpenSim/Data/SQLite/SQLiteRegionData.cs | 29 | ||||
-rw-r--r-- | OpenSim/Data/Tests/BasicInventoryTest.cs | 1 | ||||
-rw-r--r-- | OpenSim/Data/Tests/BasicRegionTest.cs | 4 | ||||
-rw-r--r-- | OpenSim/Data/Tests/BasicUserTest.cs | 1 | ||||
-rw-r--r-- | OpenSim/Data/Tests/PropertyCompareConstraint.cs | 180 |
6 files changed, 154 insertions, 64 deletions
diff --git a/OpenSim/Data/SQLite/SQLiteInventoryStore.cs b/OpenSim/Data/SQLite/SQLiteInventoryStore.cs index 97c40ba..557dec7 100644 --- a/OpenSim/Data/SQLite/SQLiteInventoryStore.cs +++ b/OpenSim/Data/SQLite/SQLiteInventoryStore.cs | |||
@@ -301,7 +301,8 @@ namespace OpenSim.Data.SQLite | |||
301 | DataTable inventoryFolderTable = ds.Tables["inventoryfolders"]; | 301 | DataTable inventoryFolderTable = ds.Tables["inventoryfolders"]; |
302 | 302 | ||
303 | inventoryRow = inventoryFolderTable.Rows.Find(item.Folder.ToString()); | 303 | inventoryRow = inventoryFolderTable.Rows.Find(item.Folder.ToString()); |
304 | inventoryRow["version"] = (int)inventoryRow["version"] + 1; | 304 | if(inventoryRow != null) //MySQL doesn't throw an exception here, so sqlite shouldn't either. |
305 | inventoryRow["version"] = (int)inventoryRow["version"] + 1; | ||
305 | 306 | ||
306 | invFoldersDa.Update(ds, "inventoryfolders"); | 307 | invFoldersDa.Update(ds, "inventoryfolders"); |
307 | } | 308 | } |
diff --git a/OpenSim/Data/SQLite/SQLiteRegionData.cs b/OpenSim/Data/SQLite/SQLiteRegionData.cs index d2548c2..0259ac5 100644 --- a/OpenSim/Data/SQLite/SQLiteRegionData.cs +++ b/OpenSim/Data/SQLite/SQLiteRegionData.cs | |||
@@ -307,26 +307,21 @@ namespace OpenSim.Data.SQLite | |||
307 | /// <param name="regionUUID">the region UUID</param> | 307 | /// <param name="regionUUID">the region UUID</param> |
308 | public void StoreObject(SceneObjectGroup obj, UUID regionUUID) | 308 | public void StoreObject(SceneObjectGroup obj, UUID regionUUID) |
309 | { | 309 | { |
310 | uint flags = obj.RootPart.GetEffectiveObjectFlags(); | ||
311 | |||
312 | // Eligibility check | ||
313 | // | ||
314 | if ((flags & (uint)PrimFlags.Temporary) != 0) | ||
315 | return; | ||
316 | if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0) | ||
317 | return; | ||
318 | |||
310 | lock (ds) | 319 | lock (ds) |
311 | { | 320 | { |
312 | foreach (SceneObjectPart prim in obj.Children.Values) | 321 | foreach (SceneObjectPart prim in obj.Children.Values) |
313 | { | 322 | { |
314 | if ((prim.GetEffectiveObjectFlags() & (uint)PrimFlags.Temporary) == 0 | 323 | m_log.Info("[REGION DB]: Adding obj: " + obj.UUID + " to region: " + regionUUID); |
315 | && (prim.GetEffectiveObjectFlags() & (uint)PrimFlags.TemporaryOnRez) == 0) | 324 | addPrim(prim, obj.UUID, regionUUID); |
316 | { | ||
317 | m_log.Info("[REGION DB]: Adding obj: " + obj.UUID + " to region: " + regionUUID); | ||
318 | addPrim(prim, obj.UUID, regionUUID); | ||
319 | } | ||
320 | else if (prim.Stopped) | ||
321 | { | ||
322 | //m_log.Info("[DATASTORE]: " + | ||
323 | //"Adding stopped obj: " + obj.UUID + " to region: " + regionUUID); | ||
324 | //addPrim(prim, obj.UUID.ToString(), regionUUID.ToString()); | ||
325 | } | ||
326 | else | ||
327 | { | ||
328 | // m_log.Info("[DATASTORE]: Ignoring Physical obj: " + obj.UUID + " in region: " + regionUUID); | ||
329 | } | ||
330 | } | 325 | } |
331 | } | 326 | } |
332 | 327 | ||
@@ -1130,7 +1125,7 @@ namespace OpenSim.Data.SQLite | |||
1130 | // explicit conversion of integers is required, which sort | 1125 | // explicit conversion of integers is required, which sort |
1131 | // of sucks. No idea if there is a shortcut here or not. | 1126 | // of sucks. No idea if there is a shortcut here or not. |
1132 | prim.CreationDate = Convert.ToInt32(row["CreationDate"]); | 1127 | prim.CreationDate = Convert.ToInt32(row["CreationDate"]); |
1133 | prim.Name = (String) row["Name"]; | 1128 | prim.Name = row["Name"] == DBNull.Value ? string.Empty : (string)row["Name"]; |
1134 | // various text fields | 1129 | // various text fields |
1135 | prim.Text = (String) row["Text"]; | 1130 | prim.Text = (String) row["Text"]; |
1136 | prim.Color = Color.FromArgb(Convert.ToInt32(row["ColorA"]), | 1131 | prim.Color = Color.FromArgb(Convert.ToInt32(row["ColorA"]), |
diff --git a/OpenSim/Data/Tests/BasicInventoryTest.cs b/OpenSim/Data/Tests/BasicInventoryTest.cs index 3c33bb4..967c6e7 100644 --- a/OpenSim/Data/Tests/BasicInventoryTest.cs +++ b/OpenSim/Data/Tests/BasicInventoryTest.cs | |||
@@ -266,6 +266,7 @@ namespace OpenSim.Data.Tests | |||
266 | InventoryItemBase actual = db.getInventoryItem(item1); | 266 | InventoryItemBase actual = db.getInventoryItem(item1); |
267 | Assert.That(actual, Constraints.PropertyCompareConstraint(expected) | 267 | Assert.That(actual, Constraints.PropertyCompareConstraint(expected) |
268 | .IgnoreProperty(x=>x.InvType) | 268 | .IgnoreProperty(x=>x.InvType) |
269 | .IgnoreProperty(x=>x.CreatorIdAsUuid) | ||
269 | .IgnoreProperty(x=>x.Description) | 270 | .IgnoreProperty(x=>x.Description) |
270 | .IgnoreProperty(x=>x.CreatorId)); | 271 | .IgnoreProperty(x=>x.CreatorId)); |
271 | } | 272 | } |
diff --git a/OpenSim/Data/Tests/BasicRegionTest.cs b/OpenSim/Data/Tests/BasicRegionTest.cs index a746ef0..8373922 100644 --- a/OpenSim/Data/Tests/BasicRegionTest.cs +++ b/OpenSim/Data/Tests/BasicRegionTest.cs | |||
@@ -576,8 +576,10 @@ namespace OpenSim.Data.Tests | |||
576 | .IgnoreProperty(x=>x.HasGroupChanged) | 576 | .IgnoreProperty(x=>x.HasGroupChanged) |
577 | .IgnoreProperty(x=>x.IsSelected) | 577 | .IgnoreProperty(x=>x.IsSelected) |
578 | .IgnoreProperty(x=>x.RegionHandle) | 578 | .IgnoreProperty(x=>x.RegionHandle) |
579 | .IgnoreProperty(x=>x.RegionUUID) | ||
579 | .IgnoreProperty(x=>x.Scene) | 580 | .IgnoreProperty(x=>x.Scene) |
580 | .IgnoreProperty(x=>x.RootPart.InventorySerial)); | 581 | .IgnoreProperty(x=>x.Children) |
582 | .IgnoreProperty(x=>x.RootPart)); | ||
581 | } | 583 | } |
582 | 584 | ||
583 | [Test] | 585 | [Test] |
diff --git a/OpenSim/Data/Tests/BasicUserTest.cs b/OpenSim/Data/Tests/BasicUserTest.cs index 21d1a7e..a3c125d 100644 --- a/OpenSim/Data/Tests/BasicUserTest.cs +++ b/OpenSim/Data/Tests/BasicUserTest.cs | |||
@@ -403,6 +403,7 @@ namespace OpenSim.Data.Tests | |||
403 | Assert.That(u1a, Constraints.PropertyCompareConstraint(u) | 403 | Assert.That(u1a, Constraints.PropertyCompareConstraint(u) |
404 | .IgnoreProperty(x=>x.HomeRegionX) | 404 | .IgnoreProperty(x=>x.HomeRegionX) |
405 | .IgnoreProperty(x=>x.HomeRegionY) | 405 | .IgnoreProperty(x=>x.HomeRegionY) |
406 | .IgnoreProperty(x=>x.RootInventoryFolderID) | ||
406 | ); | 407 | ); |
407 | } | 408 | } |
408 | 409 | ||
diff --git a/OpenSim/Data/Tests/PropertyCompareConstraint.cs b/OpenSim/Data/Tests/PropertyCompareConstraint.cs index 063267b..5f53725 100644 --- a/OpenSim/Data/Tests/PropertyCompareConstraint.cs +++ b/OpenSim/Data/Tests/PropertyCompareConstraint.cs | |||
@@ -69,6 +69,15 @@ namespace OpenSim.Data.Tests | |||
69 | 69 | ||
70 | private bool ObjectCompare(object expected, object actual, Stack<string> propertyNames) | 70 | private bool ObjectCompare(object expected, object actual, Stack<string> propertyNames) |
71 | { | 71 | { |
72 | //prevent loops... | ||
73 | if(propertyNames.Count > 50) | ||
74 | { | ||
75 | failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); | ||
76 | failingActual = actual; | ||
77 | failingExpected = expected; | ||
78 | return false; | ||
79 | } | ||
80 | |||
72 | if (actual.GetType() != expected.GetType()) | 81 | if (actual.GetType() != expected.GetType()) |
73 | { | 82 | { |
74 | propertyNames.Push("GetType()"); | 83 | propertyNames.Push("GetType()"); |
@@ -122,6 +131,60 @@ namespace OpenSim.Data.Tests | |||
122 | return true; | 131 | return true; |
123 | } | 132 | } |
124 | 133 | ||
134 | IComparable comp = actual as IComparable; | ||
135 | if (comp != null) | ||
136 | { | ||
137 | if (comp.CompareTo(expected) != 0) | ||
138 | { | ||
139 | failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); | ||
140 | failingActual = actual; | ||
141 | failingExpected = expected; | ||
142 | return false; | ||
143 | } | ||
144 | return true; | ||
145 | } | ||
146 | |||
147 | //Now try the much more annoying IComparable<T> | ||
148 | Type icomparableInterface = actual.GetType().GetInterface("IComparable`1"); | ||
149 | if (icomparableInterface != null) | ||
150 | { | ||
151 | int result = (int)icomparableInterface.GetMethod("CompareTo").Invoke(actual, new[] { expected }); | ||
152 | if (result != 0) | ||
153 | { | ||
154 | failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); | ||
155 | failingActual = actual; | ||
156 | failingExpected = expected; | ||
157 | return false; | ||
158 | } | ||
159 | return true; | ||
160 | } | ||
161 | |||
162 | IEnumerable arr = actual as IEnumerable; | ||
163 | if (arr != null) | ||
164 | { | ||
165 | List<object> actualList = arr.Cast<object>().ToList(); | ||
166 | List<object> expectedList = ((IEnumerable)expected).Cast<object>().ToList(); | ||
167 | if (actualList.Count != expectedList.Count) | ||
168 | { | ||
169 | propertyNames.Push("Count"); | ||
170 | failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); | ||
171 | failingActual = actualList.Count; | ||
172 | failingExpected = expectedList.Count; | ||
173 | propertyNames.Pop(); | ||
174 | return false; | ||
175 | } | ||
176 | //actualList and expectedList should be the same size. | ||
177 | for (int i = 0; i < actualList.Count; i++) | ||
178 | { | ||
179 | propertyNames.Push("[" + i + "]"); | ||
180 | if (!ObjectCompare(expectedList[i], actualList[i], propertyNames)) | ||
181 | return false; | ||
182 | propertyNames.Pop(); | ||
183 | } | ||
184 | //Everything seems okay... | ||
185 | return true; | ||
186 | } | ||
187 | |||
125 | //Skip static properties. I had a nasty problem comparing colors because of all of the public static colors. | 188 | //Skip static properties. I had a nasty problem comparing colors because of all of the public static colors. |
126 | PropertyInfo[] properties = expected.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); | 189 | PropertyInfo[] properties = expected.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); |
127 | foreach (var property in properties) | 190 | foreach (var property in properties) |
@@ -147,41 +210,6 @@ namespace OpenSim.Data.Tests | |||
147 | return false; | 210 | return false; |
148 | } | 211 | } |
149 | 212 | ||
150 | IComparable comp = actualValue as IComparable; | ||
151 | if (comp != null) | ||
152 | { | ||
153 | if (comp.CompareTo(expectedValue) != 0) | ||
154 | { | ||
155 | propertyNames.Push(property.Name); | ||
156 | failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); | ||
157 | propertyNames.Pop(); | ||
158 | failingActual = actualValue; | ||
159 | failingExpected = expectedValue; | ||
160 | return false; | ||
161 | } | ||
162 | continue; | ||
163 | } | ||
164 | |||
165 | IEnumerable arr = actualValue as IEnumerable; | ||
166 | if (arr != null) | ||
167 | { | ||
168 | List<object> actualList = arr.Cast<object>().ToList(); | ||
169 | List<object> expectedList = ((IEnumerable)expectedValue).Cast<object>().ToList(); | ||
170 | if (actualList.Count != expectedList.Count) | ||
171 | { | ||
172 | propertyNames.Push(property.Name); | ||
173 | propertyNames.Push("Count"); | ||
174 | failingPropertyName = string.Join(".", propertyNames.Reverse().ToArray()); | ||
175 | failingActual = actualList.Count; | ||
176 | failingExpected = expectedList.Count; | ||
177 | propertyNames.Pop(); | ||
178 | propertyNames.Pop(); | ||
179 | } | ||
180 | //Todo: A value-wise comparison of all of the values. | ||
181 | //Everything seems okay... | ||
182 | continue; | ||
183 | } | ||
184 | |||
185 | propertyNames.Push(property.Name); | 213 | propertyNames.Push(property.Name); |
186 | if (!ObjectCompare(expectedValue, actualValue, propertyNames)) | 214 | if (!ObjectCompare(expectedValue, actualValue, propertyNames)) |
187 | return false; | 215 | return false; |
@@ -223,15 +251,7 @@ namespace OpenSim.Data.Tests | |||
223 | { | 251 | { |
224 | //If the inside of the lambda is the access to x, we've hit the end of the chain. | 252 | //If the inside of the lambda is the access to x, we've hit the end of the chain. |
225 | // We should track by the fully scoped parameter name, but this is the first rev of doing this. | 253 | // We should track by the fully scoped parameter name, but this is the first rev of doing this. |
226 | if (((MemberExpression)express).Expression is ParameterExpression) | 254 | ignores.Add(((MemberExpression)express).Member.Name); |
227 | { | ||
228 | ignores.Add(((MemberExpression)express).Member.Name); | ||
229 | } | ||
230 | else | ||
231 | { | ||
232 | //Otherwise there could be more parameters inside... | ||
233 | PullApartExpression(((MemberExpression)express).Expression); | ||
234 | } | ||
235 | } | 255 | } |
236 | } | 256 | } |
237 | } | 257 | } |
@@ -270,7 +290,7 @@ namespace OpenSim.Data.Tests | |||
270 | { | 290 | { |
271 | HasInt actual = new HasInt { TheValue = 5 }; | 291 | HasInt actual = new HasInt { TheValue = 5 }; |
272 | HasInt expected = new HasInt { TheValue = 4 }; | 292 | HasInt expected = new HasInt { TheValue = 4 }; |
273 | var constraint = Constraints.PropertyCompareConstraint(expected).IgnoreProperty(x=>x.TheValue); | 293 | var constraint = Constraints.PropertyCompareConstraint(expected).IgnoreProperty(x => x.TheValue); |
274 | 294 | ||
275 | Assert.That(constraint.Matches(actual), Is.True); | 295 | Assert.That(constraint.Matches(actual), Is.True); |
276 | } | 296 | } |
@@ -312,6 +332,28 @@ namespace OpenSim.Data.Tests | |||
312 | } | 332 | } |
313 | 333 | ||
314 | [Test] | 334 | [Test] |
335 | public void UUIDShouldMatch() | ||
336 | { | ||
337 | UUID uuid1 = UUID.Random(); | ||
338 | UUID uuid2 = UUID.Parse(uuid1.ToString()); | ||
339 | |||
340 | var constraint = Constraints.PropertyCompareConstraint(uuid1); | ||
341 | |||
342 | Assert.That(constraint.Matches(uuid2), Is.True); | ||
343 | } | ||
344 | |||
345 | [Test] | ||
346 | public void UUIDShouldNotMatch() | ||
347 | { | ||
348 | UUID uuid1 = UUID.Random(); | ||
349 | UUID uuid2 = UUID.Random(); | ||
350 | |||
351 | var constraint = Constraints.PropertyCompareConstraint(uuid1); | ||
352 | |||
353 | Assert.That(constraint.Matches(uuid2), Is.False); | ||
354 | } | ||
355 | |||
356 | [Test] | ||
315 | public void TestColors() | 357 | public void TestColors() |
316 | { | 358 | { |
317 | Color actual = Color.Red; | 359 | Color actual = Color.Red; |
@@ -321,5 +363,53 @@ namespace OpenSim.Data.Tests | |||
321 | 363 | ||
322 | Assert.That(constraint.Matches(actual), Is.True); | 364 | Assert.That(constraint.Matches(actual), Is.True); |
323 | } | 365 | } |
366 | |||
367 | [Test] | ||
368 | public void ShouldCompareLists() | ||
369 | { | ||
370 | List<int> expected = new List<int> { 1, 2, 3 }; | ||
371 | List<int> actual = new List<int> { 1, 2, 3 }; | ||
372 | |||
373 | var constraint = Constraints.PropertyCompareConstraint(expected); | ||
374 | Assert.That(constraint.Matches(actual), Is.True); | ||
375 | } | ||
376 | |||
377 | |||
378 | [Test] | ||
379 | public void ShouldFailToCompareListsThatAreDifferent() | ||
380 | { | ||
381 | List<int> expected = new List<int> { 1, 2, 3 }; | ||
382 | List<int> actual = new List<int> { 1, 2, 4 }; | ||
383 | |||
384 | var constraint = Constraints.PropertyCompareConstraint(expected); | ||
385 | Assert.That(constraint.Matches(actual), Is.False); | ||
386 | } | ||
387 | |||
388 | [Test] | ||
389 | public void ShouldFailToCompareListsThatAreDifferentLengths() | ||
390 | { | ||
391 | List<int> expected = new List<int> { 1, 2, 3 }; | ||
392 | List<int> actual = new List<int> { 1, 2 }; | ||
393 | |||
394 | var constraint = Constraints.PropertyCompareConstraint(expected); | ||
395 | Assert.That(constraint.Matches(actual), Is.False); | ||
396 | } | ||
397 | |||
398 | public class Recursive | ||
399 | { | ||
400 | public Recursive Other { get; set; } | ||
401 | } | ||
402 | |||
403 | [Test] | ||
404 | public void ErrorsOutOnRecursive() | ||
405 | { | ||
406 | Recursive parent = new Recursive(); | ||
407 | Recursive child = new Recursive(); | ||
408 | parent.Other = child; | ||
409 | child.Other = parent; | ||
410 | |||
411 | var constraint = Constraints.PropertyCompareConstraint(child); | ||
412 | Assert.That(constraint.Matches(child), Is.False); | ||
413 | } | ||
324 | } | 414 | } |
325 | } \ No newline at end of file | 415 | } \ No newline at end of file |