aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Scripting/JsonStore
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting/JsonStore')
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs233
1 files changed, 218 insertions, 15 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs
index eb4bc22..f25f290 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs
@@ -135,6 +135,15 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
135 string value = (string)InvokeOp("JsonGetValue", storeId, "Hello"); 135 string value = (string)InvokeOp("JsonGetValue", storeId, "Hello");
136 Assert.That(value, Is.EqualTo("42.15")); 136 Assert.That(value, Is.EqualTo("42.15"));
137 } 137 }
138
139 // Test with an array as the root node
140 {
141 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "[ 'one', 'two', 'three' ]");
142 Assert.That(storeId, Is.Not.EqualTo(UUID.Zero));
143
144 string value = (string)InvokeOp("JsonGetValue", storeId, "[1]");
145 Assert.That(value, Is.EqualTo("two"));
146 }
138 } 147 }
139 148
140 [Test] 149 [Test]
@@ -260,25 +269,69 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
260 TestHelpers.InMethod(); 269 TestHelpers.InMethod();
261// TestHelpers.EnableLogging(); 270// TestHelpers.EnableLogging();
262 271
263 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : 'World' }"); 272 // Test remove of node in object pointing to a string
273 {
274 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : 'World' }");
275
276 int returnValue = (int)InvokeOp( "JsonRemoveValue", storeId, "Hello");
277 Assert.That(returnValue, Is.EqualTo(1));
278
279 int result = (int)InvokeOp("JsonTestPath", storeId, "Hello");
280 Assert.That(result, Is.EqualTo(0));
281
282 string returnValue2 = (string)InvokeOp("JsonGetValue", storeId, "Hello");
283 Assert.That(returnValue2, Is.EqualTo(""));
284 }
285
286 // Test remove of node in object pointing to another object
287 {
288 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : 'Wally' } }");
289
290 int returnValue = (int)InvokeOp( "JsonRemoveValue", storeId, "Hello");
291 Assert.That(returnValue, Is.EqualTo(1));
264 292
265 int returnValue = (int)InvokeOp( "JsonRemoveValue", storeId, "Hello"); 293 int result = (int)InvokeOp("JsonTestPath", storeId, "Hello");
266 Assert.That(returnValue, Is.EqualTo(1)); 294 Assert.That(result, Is.EqualTo(0));
295
296 string returnValue2 = (string)InvokeOp("JsonGetValueJson", storeId, "Hello");
297 Assert.That(returnValue2, Is.EqualTo(""));
298 }
267 299
268 int result = (int)InvokeOp("JsonTestPath", storeId, "Hello"); 300 // Test remove of node in an array
269 Assert.That(result, Is.EqualTo(0)); 301 {
302 UUID storeId
303 = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : [ 'value1', 'value2' ] }");
304
305 int returnValue = (int)InvokeOp( "JsonRemoveValue", storeId, "Hello[0]");
306 Assert.That(returnValue, Is.EqualTo(1));
270 307
271 string returnValue2 = (string)InvokeOp("JsonGetValue", storeId, "Hello"); 308 int result = (int)InvokeOp("JsonTestPath", storeId, "Hello[0]");
272 Assert.That(returnValue2, Is.EqualTo("")); 309 Assert.That(result, Is.EqualTo(1));
310
311 result = (int)InvokeOp("JsonTestPath", storeId, "Hello[1]");
312 Assert.That(result, Is.EqualTo(0));
313
314 string stringReturnValue = (string)InvokeOp("JsonGetValue", storeId, "Hello[0]");
315 Assert.That(stringReturnValue, Is.EqualTo("value2"));
316
317 stringReturnValue = (string)InvokeOp("JsonGetValueJson", storeId, "Hello[1]");
318 Assert.That(stringReturnValue, Is.EqualTo(""));
319 }
273 320
274 // Test remove of non-existing value 321 // Test remove of non-existing value
275 int fakeValueRemove = (int)InvokeOp("JsonRemoveValue", storeId, "Hello"); 322 {
276 Assert.That(fakeValueRemove, Is.EqualTo(0)); 323 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : 'World' }");
277 324
278 // Test get from non-existing store 325 int fakeValueRemove = (int)InvokeOp("JsonRemoveValue", storeId, "Cheese");
279 UUID fakeStoreId = TestHelpers.ParseTail(0x500); 326 Assert.That(fakeValueRemove, Is.EqualTo(0));
280 int fakeStoreValueRemove = (int)InvokeOp("JsonRemoveValue", fakeStoreId, "Hello"); 327 }
281 Assert.That(fakeStoreValueRemove, Is.EqualTo(0)); 328
329 {
330 // Test get from non-existing store
331 UUID fakeStoreId = TestHelpers.ParseTail(0x500);
332 int fakeStoreValueRemove = (int)InvokeOp("JsonRemoveValue", fakeStoreId, "Hello");
333 Assert.That(fakeStoreValueRemove, Is.EqualTo(0));
334 }
282 } 335 }
283 336
284 [Test] 337 [Test]
@@ -352,7 +405,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
352// TestHelpers.EnableLogging(); 405// TestHelpers.EnableLogging();
353 406
354 { 407 {
355 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ }"); 408 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
356 409
357 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun", "Times"); 410 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun", "Times");
358 Assert.That(result, Is.EqualTo(1)); 411 Assert.That(result, Is.EqualTo(1));
@@ -361,9 +414,159 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
361 Assert.That(value, Is.EqualTo("Times")); 414 Assert.That(value, Is.EqualTo("Times"));
362 } 415 }
363 416
417 // Commented out as this currently unexpectedly fails.
418 // Test setting a key containing periods with delineation
419// {
420// UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
421//
422// int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun.Circus}", "Times");
423// Assert.That(result, Is.EqualTo(1));
424//
425// string value = (string)InvokeOp("JsonGetValue", storeId, "{Fun.Circus}");
426// Assert.That(value, Is.EqualTo("Times"));
427// }
428
429 // *** Test [] ***
430
431 // Test setting a key containing unbalanced ] without delineation. Expecting failure
432 {
433 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
434
435 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun]Circus", "Times");
436 Assert.That(result, Is.EqualTo(0));
437
438 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun]Circus");
439 Assert.That(value, Is.EqualTo(""));
440 }
441
442 // Test setting a key containing unbalanced [ without delineation. Expecting failure
443 {
444 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
445
446 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun[Circus", "Times");
447 Assert.That(result, Is.EqualTo(0));
448
449 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun[Circus");
450 Assert.That(value, Is.EqualTo(""));
451 }
452
453 // Test setting a key containing unbalanced [] without delineation. Expecting failure
454 {
455 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
456
457 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun[]Circus", "Times");
458 Assert.That(result, Is.EqualTo(0));
459
460 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun[]Circus");
461 Assert.That(value, Is.EqualTo(""));
462 }
463
464 // Test setting a key containing unbalanced ] with delineation
465 {
466 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
467
468 int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun]Circus}", "Times");
469 Assert.That(result, Is.EqualTo(1));
470
471 string value = (string)InvokeOp("JsonGetValue", storeId, "{Fun]Circus}");
472 Assert.That(value, Is.EqualTo("Times"));
473 }
474
475 // Test setting a key containing unbalanced [ with delineation
476 {
477 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
478
479 int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun[Circus}", "Times");
480 Assert.That(result, Is.EqualTo(1));
481
482 string value = (string)InvokeOp("JsonGetValue", storeId, "{Fun[Circus}");
483 Assert.That(value, Is.EqualTo("Times"));
484 }
485
486 // Test setting a key containing empty balanced [] with delineation
487 {
488 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
489
490 int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun[]Circus}", "Times");
491 Assert.That(result, Is.EqualTo(1));
492
493 string value = (string)InvokeOp("JsonGetValue", storeId, "{Fun[]Circus}");
494 Assert.That(value, Is.EqualTo("Times"));
495 }
496
497 // Commented out as this currently unexpectedly fails.
498// // Test setting a key containing brackets around an integer with delineation
499// {
500// UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
501//
502// int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun[0]Circus}", "Times");
503// Assert.That(result, Is.EqualTo(1));
504//
505// string value = (string)InvokeOp("JsonGetValue", storeId, "{Fun[]Circus}");
506// Assert.That(value, Is.EqualTo("Times"));
507// }
508
509 // *** Test {} ***
510
511 // Test setting a key containing unbalanced } without delineation. Expecting failure (?)
512 {
513 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
514
515 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun}Circus", "Times");
516 Assert.That(result, Is.EqualTo(0));
517
518 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun}Circus");
519 Assert.That(value, Is.EqualTo(""));
520 }
521
522 // Test setting a key containing unbalanced { without delineation. Expecting failure (?)
523 {
524 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
525
526 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun{Circus", "Times");
527 Assert.That(result, Is.EqualTo(0));
528
529 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun}Circus");
530 Assert.That(value, Is.EqualTo(""));
531 }
532
533 // Commented out as this currently unexpectedly fails.
534// // Test setting a key containing unbalanced }
535// {
536// UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
537//
538// int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun}Circus}", "Times");
539// Assert.That(result, Is.EqualTo(1));
540//
541// string value = (string)InvokeOp("JsonGetValue", storeId, "{Fun}Circus}");
542// Assert.That(value, Is.EqualTo("Times"));
543// }
544
545 // Test setting a key containing unbalanced { with delineation
546 {
547 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
548
549 int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun{Circus}", "Times");
550 Assert.That(result, Is.EqualTo(1));
551
552 string value = (string)InvokeOp("JsonGetValue", storeId, "{Fun{Circus}");
553 Assert.That(value, Is.EqualTo("Times"));
554 }
555
556 // Test setting a key containing balanced {} with delineation. This should fail.
557 {
558 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
559
560 int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun{Filled}Circus}", "Times");
561 Assert.That(result, Is.EqualTo(0));
562
563 string value = (string)InvokeOp("JsonGetValue", storeId, "{Fun{Filled}Circus}");
564 Assert.That(value, Is.EqualTo(""));
565 }
566
364 // Test setting to location that does not exist. This should fail. 567 // Test setting to location that does not exist. This should fail.
365 { 568 {
366 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ }"); 569 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
367 570
368 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun.Circus", "Times"); 571 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun.Circus", "Times");
369 Assert.That(result, Is.EqualTo(0)); 572 Assert.That(result, Is.EqualTo(0));