aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Scripting
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting')
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs76
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs65
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs40
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs446
4 files changed, 546 insertions, 81 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
index 82a4da7..ca3989a 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs
@@ -68,14 +68,11 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
68 protected List<TakeValueCallbackClass> m_TakeStore; 68 protected List<TakeValueCallbackClass> m_TakeStore;
69 protected List<TakeValueCallbackClass> m_ReadStore; 69 protected List<TakeValueCallbackClass> m_ReadStore;
70 70
71 // add separators for quoted paths 71 // add separators for quoted paths and array references
72 protected static Regex m_ParsePassOne = new Regex("{[^}]+}"); 72 protected static Regex m_ParsePassOne = new Regex("({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])");
73
74 // add separators for array references
75 protected static Regex m_ParsePassTwo = new Regex("(\\[[0-9]+\\]|\\[\\+\\])");
76 73
77 // add quotes to bare identifiers which are limited to alphabetic characters 74 // add quotes to bare identifiers which are limited to alphabetic characters
78 protected static Regex m_ParsePassThree = new Regex("\\.([a-zA-Z]+)"); 75 protected static Regex m_ParsePassThree = new Regex("(?<!{[^}]*)\\.([a-zA-Z]+)(?=\\.)");
79 76
80 // remove extra separator characters 77 // remove extra separator characters
81 protected static Regex m_ParsePassFour = new Regex("\\.+"); 78 protected static Regex m_ParsePassFour = new Regex("\\.+");
@@ -84,7 +81,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
84 protected static Regex m_ValidatePath = new Regex("^\\.(({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])\\.)*$"); 81 protected static Regex m_ValidatePath = new Regex("^\\.(({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])\\.)*$");
85 82
86 // expression used to match path components 83 // expression used to match path components
87 protected static Regex m_PathComponent = new Regex("\\.({[^}]+}|\\[[0-9]+\\]|\\[\\+\\]+)"); 84 protected static Regex m_PathComponent = new Regex("\\.({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])");
88 85
89 // extract the internals of an array reference 86 // extract the internals of an array reference
90 protected static Regex m_SimpleArrayPattern = new Regex("\\[([0-9]+)\\]"); 87 protected static Regex m_SimpleArrayPattern = new Regex("\\[([0-9]+)\\]");
@@ -131,15 +128,46 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
131 m_TakeStore = new List<TakeValueCallbackClass>(); 128 m_TakeStore = new List<TakeValueCallbackClass>();
132 m_ReadStore = new List<TakeValueCallbackClass>(); 129 m_ReadStore = new List<TakeValueCallbackClass>();
133 } 130 }
134 131
135 public JsonStore(string value) : this() 132 public JsonStore(string value) : this()
136 { 133 {
134 // This is going to throw an exception if the value is not
135 // a valid JSON chunk. Calling routines should catch the
136 // exception and handle it appropriately
137 if (String.IsNullOrEmpty(value)) 137 if (String.IsNullOrEmpty(value))
138 ValueStore = new OSDMap(); 138 ValueStore = new OSDMap();
139 else 139 else
140 ValueStore = OSDParser.DeserializeJson(value); 140 ValueStore = OSDParser.DeserializeJson(value);
141 } 141 }
142
143 // -----------------------------------------------------------------
144 /// <summary>
145 ///
146 /// </summary>
147 // -----------------------------------------------------------------
148 public JsonStoreNodeType PathType(string expr)
149 {
150 Stack<string> path;
151 if (! ParsePathExpression(expr,out path))
152 return JsonStoreNodeType.Undefined;
153
154 OSD result = ProcessPathExpression(ValueStore,path);
142 155
156 if (result == null)
157 return JsonStoreNodeType.Undefined;
158
159 if (result is OSDMap)
160 return JsonStoreNodeType.Object;
161
162 if (result is OSDArray)
163 return JsonStoreNodeType.Array;
164
165 if (OSDBaseType(result.Type))
166 return JsonStoreNodeType.Value;
167
168 return JsonStoreNodeType.Undefined;
169 }
170
143 // ----------------------------------------------------------------- 171 // -----------------------------------------------------------------
144 /// <summary> 172 /// <summary>
145 /// 173 ///
@@ -167,6 +195,27 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
167 /// 195 ///
168 /// </summary> 196 /// </summary>
169 // ----------------------------------------------------------------- 197 // -----------------------------------------------------------------
198 public int ArrayLength(string expr)
199 {
200 Stack<string> path;
201 if (! ParsePathExpression(expr,out path))
202 return -1;
203
204 OSD result = ProcessPathExpression(ValueStore,path);
205 if (result != null && result.Type == OSDType.Array)
206 {
207 OSDArray arr = result as OSDArray;
208 return arr.Count;
209 }
210
211 return -1;
212 }
213
214 // -----------------------------------------------------------------
215 /// <summary>
216 ///
217 /// </summary>
218 // -----------------------------------------------------------------
170 public bool GetValue(string expr, out string value, bool useJson) 219 public bool GetValue(string expr, out string value, bool useJson)
171 { 220 {
172 Stack<string> path; 221 Stack<string> path;
@@ -462,11 +511,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
462 // add front and rear separators 511 // add front and rear separators
463 expr = "." + expr + "."; 512 expr = "." + expr + ".";
464 513
465 // add separators for quoted exprs 514 // add separators for quoted exprs and array references
466 expr = m_ParsePassOne.Replace(expr,".$0.",-1,0); 515 expr = m_ParsePassOne.Replace(expr,".$1.",-1,0);
467
468 // add separators for array references
469 expr = m_ParsePassTwo.Replace(expr,".$0.",-1,0);
470 516
471 // add quotes to bare identifier 517 // add quotes to bare identifier
472 expr = m_ParsePassThree.Replace(expr,".{$1}",-1,0); 518 expr = m_ParsePassThree.Replace(expr,".{$1}",-1,0);
@@ -574,14 +620,14 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
574 // The path pointed to an intermediate hash structure 620 // The path pointed to an intermediate hash structure
575 if (result.Type == OSDType.Map) 621 if (result.Type == OSDType.Map)
576 { 622 {
577 value = OSDParser.SerializeJsonString(result as OSDMap); 623 value = OSDParser.SerializeJsonString(result as OSDMap,true);
578 return true; 624 return true;
579 } 625 }
580 626
581 // The path pointed to an intermediate hash structure 627 // The path pointed to an intermediate hash structure
582 if (result.Type == OSDType.Array) 628 if (result.Type == OSDType.Array)
583 { 629 {
584 value = OSDParser.SerializeJsonString(result as OSDArray); 630 value = OSDParser.SerializeJsonString(result as OSDArray,true);
585 return true; 631 return true;
586 } 632 }
587 633
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs
index f1ce856..fb35068 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs
@@ -227,7 +227,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
227 } 227 }
228 catch (Exception e) 228 catch (Exception e)
229 { 229 {
230 m_log.Error(string.Format("[JsonStore]: Unable to initialize store from {0}", value), e); 230 m_log.ErrorFormat("[JsonStore]: Unable to initialize store from {0}", value);
231 return false; 231 return false;
232 } 232 }
233 233
@@ -270,6 +270,38 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
270 /// 270 ///
271 /// </summary> 271 /// </summary>
272 // ----------------------------------------------------------------- 272 // -----------------------------------------------------------------
273 public JsonStoreNodeType GetPathType(UUID storeID, string path)
274 {
275 if (! m_enabled) return JsonStoreNodeType.Undefined;
276
277 JsonStore map = null;
278 lock (m_JsonValueStore)
279 {
280 if (! m_JsonValueStore.TryGetValue(storeID,out map))
281 {
282 m_log.InfoFormat("[JsonStore] Missing store {0}",storeID);
283 return JsonStoreNodeType.Undefined;
284 }
285 }
286
287 try
288 {
289 lock (map)
290 return map.PathType(path);
291 }
292 catch (Exception e)
293 {
294 m_log.Error(string.Format("[JsonStore]: Path test failed for {0} in {1}", path, storeID), e);
295 }
296
297 return JsonStoreNodeType.Undefined;
298 }
299
300 // -----------------------------------------------------------------
301 /// <summary>
302 ///
303 /// </summary>
304 // -----------------------------------------------------------------
273 public bool TestPath(UUID storeID, string path, bool useJson) 305 public bool TestPath(UUID storeID, string path, bool useJson)
274 { 306 {
275 if (! m_enabled) return false; 307 if (! m_enabled) return false;
@@ -375,6 +407,37 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
375 /// 407 ///
376 /// </summary> 408 /// </summary>
377 // ----------------------------------------------------------------- 409 // -----------------------------------------------------------------
410 public int GetArrayLength(UUID storeID, string path)
411 {
412 if (! m_enabled) return -1;
413
414 JsonStore map = null;
415 lock (m_JsonValueStore)
416 {
417 if (! m_JsonValueStore.TryGetValue(storeID,out map))
418 return -1;
419 }
420
421 try
422 {
423 lock (map)
424 {
425 return map.ArrayLength(path);
426 }
427 }
428 catch (Exception e)
429 {
430 m_log.Error("[JsonStore]: unable to retrieve value", e);
431 }
432
433 return -1;
434 }
435
436 // -----------------------------------------------------------------
437 /// <summary>
438 ///
439 /// </summary>
440 // -----------------------------------------------------------------
378 public bool GetValue(UUID storeID, string path, bool useJson, out string value) 441 public bool GetValue(UUID storeID, string path, bool useJson, out string value)
379 { 442 {
380 value = String.Empty; 443 value = String.Empty;
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
index e436304..ef08c05 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
@@ -167,7 +167,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
167 try 167 try
168 { 168 {
169 m_comms.RegisterScriptInvocations(this); 169 m_comms.RegisterScriptInvocations(this);
170 170 m_comms.RegisterConstants(this);
171
171 // m_comms.RegisterScriptInvocation(this, "JsonCreateStore"); 172 // m_comms.RegisterScriptInvocation(this, "JsonCreateStore");
172 // m_comms.RegisterScriptInvocation(this, "JsonAttachObjectStore"); 173 // m_comms.RegisterScriptInvocation(this, "JsonAttachObjectStore");
173 // m_comms.RegisterScriptInvocation(this, "JsonDestroyStore"); 174 // m_comms.RegisterScriptInvocation(this, "JsonDestroyStore");
@@ -214,6 +215,22 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
214 215
215#endregion 216#endregion
216 217
218#region ScriptConstantsInterface
219
220 [ScriptConstant]
221 public static readonly int JSON_TYPE_UNDEF = (int)JsonStoreNodeType.Undefined;
222
223 [ScriptConstant]
224 public static readonly int JSON_TYPE_OBJECT = (int)JsonStoreNodeType.Object;
225
226 [ScriptConstant]
227 public static readonly int JSON_TYPE_ARRAY = (int)JsonStoreNodeType.Array;
228
229 [ScriptConstant]
230 public static readonly int JSON_TYPE_VALUE = (int)JsonStoreNodeType.Value;
231
232#endregion
233
217#region ScriptInvocationInteface 234#region ScriptInvocationInteface
218 // ----------------------------------------------------------------- 235 // -----------------------------------------------------------------
219 /// <summary> 236 /// <summary>
@@ -319,6 +336,12 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
319 /// </summary> 336 /// </summary>
320 // ----------------------------------------------------------------- 337 // -----------------------------------------------------------------
321 [ScriptInvocation] 338 [ScriptInvocation]
339 public int JsonGetPathType(UUID hostID, UUID scriptID, UUID storeID, string path)
340 {
341 return (int)m_store.GetPathType(storeID,path);
342 }
343
344 [ScriptInvocation]
322 public int JsonTestPath(UUID hostID, UUID scriptID, UUID storeID, string path) 345 public int JsonTestPath(UUID hostID, UUID scriptID, UUID storeID, string path)
323 { 346 {
324 return m_store.TestPath(storeID,path,false) ? 1 : 0; 347 return m_store.TestPath(storeID,path,false) ? 1 : 0;
@@ -342,7 +365,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
342 } 365 }
343 366
344 [ScriptInvocation] 367 [ScriptInvocation]
345 public int JsonSetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path, string value) 368 public int JsonSetJson(UUID hostID, UUID scriptID, UUID storeID, string path, string value)
346 { 369 {
347 return m_store.SetValue(storeID,path,value,true) ? 1 : 0; 370 return m_store.SetValue(storeID,path,value,true) ? 1 : 0;
348 } 371 }
@@ -364,6 +387,17 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
364 /// </summary> 387 /// </summary>
365 // ----------------------------------------------------------------- 388 // -----------------------------------------------------------------
366 [ScriptInvocation] 389 [ScriptInvocation]
390 public int JsonGetArrayLength(UUID hostID, UUID scriptID, UUID storeID, string path)
391 {
392 return m_store.GetArrayLength(storeID,path);
393 }
394
395 // -----------------------------------------------------------------
396 /// <summary>
397 ///
398 /// </summary>
399 // -----------------------------------------------------------------
400 [ScriptInvocation]
367 public string JsonGetValue(UUID hostID, UUID scriptID, UUID storeID, string path) 401 public string JsonGetValue(UUID hostID, UUID scriptID, UUID storeID, string path)
368 { 402 {
369 string value = String.Empty; 403 string value = String.Empty;
@@ -372,7 +406,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
372 } 406 }
373 407
374 [ScriptInvocation] 408 [ScriptInvocation]
375 public string JsonGetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path) 409 public string JsonGetJson(UUID hostID, UUID scriptID, UUID storeID, string path)
376 { 410 {
377 string value = String.Empty; 411 string value = String.Empty;
378 m_store.GetValue(storeID,path,true, out value); 412 m_store.GetValue(storeID,path,true, out value);
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs
index 717484c..3d9ad16 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/Tests/JsonStoreScriptModuleTests.cs
@@ -53,6 +53,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
53 private Scene m_scene; 53 private Scene m_scene;
54 private MockScriptEngine m_engine; 54 private MockScriptEngine m_engine;
55 private ScriptModuleCommsModule m_smcm; 55 private ScriptModuleCommsModule m_smcm;
56 private JsonStoreScriptModule m_jssm;
56 57
57 [TestFixtureSetUp] 58 [TestFixtureSetUp]
58 public void FixtureInit() 59 public void FixtureInit()
@@ -82,10 +83,10 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
82 m_engine = new MockScriptEngine(); 83 m_engine = new MockScriptEngine();
83 m_smcm = new ScriptModuleCommsModule(); 84 m_smcm = new ScriptModuleCommsModule();
84 JsonStoreModule jsm = new JsonStoreModule(); 85 JsonStoreModule jsm = new JsonStoreModule();
85 JsonStoreScriptModule jssm = new JsonStoreScriptModule(); 86 m_jssm = new JsonStoreScriptModule();
86 87
87 m_scene = new SceneHelpers().SetupScene(); 88 m_scene = new SceneHelpers().SetupScene();
88 SceneHelpers.SetupSceneModules(m_scene, configSource, m_engine, m_smcm, jsm, jssm); 89 SceneHelpers.SetupSceneModules(m_scene, configSource, m_engine, m_smcm, jsm, m_jssm);
89 90
90 try 91 try
91 { 92 {
@@ -115,8 +116,35 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
115 TestHelpers.InMethod(); 116 TestHelpers.InMethod();
116// TestHelpers.EnableLogging(); 117// TestHelpers.EnableLogging();
117 118
118 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}"); 119 // Test blank store
119 Assert.That(storeId, Is.Not.EqualTo(UUID.Zero)); 120 {
121 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
122 Assert.That(storeId, Is.Not.EqualTo(UUID.Zero));
123 }
124
125 // Test single element store
126 {
127 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : 'World' }");
128 Assert.That(storeId, Is.Not.EqualTo(UUID.Zero));
129 }
130
131 // Test with an integer value
132 {
133 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : 42.15 }");
134 Assert.That(storeId, Is.Not.EqualTo(UUID.Zero));
135
136 string value = (string)InvokeOp("JsonGetValue", storeId, "Hello");
137 Assert.That(value, Is.EqualTo("42.15"));
138 }
139
140 // Test with an array as the root node
141 {
142 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "[ 'one', 'two', 'three' ]");
143 Assert.That(storeId, Is.Not.EqualTo(UUID.Zero));
144
145 string value = (string)InvokeOp("JsonGetValue", storeId, "[1]");
146 Assert.That(value, Is.EqualTo("two"));
147 }
120 } 148 }
121 149
122 [Test] 150 [Test]
@@ -181,7 +209,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
181 } 209 }
182 210
183 [Test] 211 [Test]
184 public void TestJsonGetValueJson() 212 public void TestJsonGetJson()
185 { 213 {
186 TestHelpers.InMethod(); 214 TestHelpers.InMethod();
187// TestHelpers.EnableLogging(); 215// TestHelpers.EnableLogging();
@@ -189,26 +217,26 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
189 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : 'Two' } }"); 217 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : 'Two' } }");
190 218
191 { 219 {
192 string value = (string)InvokeOp("JsonGetValueJson", storeId, "Hello.World"); 220 string value = (string)InvokeOp("JsonGetJson", storeId, "Hello.World");
193 Assert.That(value, Is.EqualTo("'Two'")); 221 Assert.That(value, Is.EqualTo("'Two'"));
194 } 222 }
195 223
196 // Test get of path section instead of leaf 224 // Test get of path section instead of leaf
197 { 225 {
198 string value = (string)InvokeOp("JsonGetValueJson", storeId, "Hello"); 226 string value = (string)InvokeOp("JsonGetJson", storeId, "Hello");
199 Assert.That(value, Is.EqualTo("{\"World\":\"Two\"}")); 227 Assert.That(value, Is.EqualTo("{\"World\":\"Two\"}"));
200 } 228 }
201 229
202 // Test get of non-existing value 230 // Test get of non-existing value
203 { 231 {
204 string fakeValueGet = (string)InvokeOp("JsonGetValueJson", storeId, "foo"); 232 string fakeValueGet = (string)InvokeOp("JsonGetJson", storeId, "foo");
205 Assert.That(fakeValueGet, Is.EqualTo("")); 233 Assert.That(fakeValueGet, Is.EqualTo(""));
206 } 234 }
207 235
208 // Test get from non-existing store 236 // Test get from non-existing store
209 { 237 {
210 UUID fakeStoreId = TestHelpers.ParseTail(0x500); 238 UUID fakeStoreId = TestHelpers.ParseTail(0x500);
211 string fakeStoreValueGet = (string)InvokeOp("JsonGetValueJson", fakeStoreId, "Hello"); 239 string fakeStoreValueGet = (string)InvokeOp("JsonGetJson", fakeStoreId, "Hello");
212 Assert.That(fakeStoreValueGet, Is.EqualTo("")); 240 Assert.That(fakeStoreValueGet, Is.EqualTo(""));
213 } 241 }
214 } 242 }
@@ -242,88 +270,236 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
242 TestHelpers.InMethod(); 270 TestHelpers.InMethod();
243// TestHelpers.EnableLogging(); 271// TestHelpers.EnableLogging();
244 272
245 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : 'World' }"); 273 // Test remove of node in object pointing to a string
274 {
275 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : 'World' }");
276
277 int returnValue = (int)InvokeOp( "JsonRemoveValue", storeId, "Hello");
278 Assert.That(returnValue, Is.EqualTo(1));
279
280 int result = (int)InvokeOp("JsonTestPath", storeId, "Hello");
281 Assert.That(result, Is.EqualTo(0));
282
283 string returnValue2 = (string)InvokeOp("JsonGetValue", storeId, "Hello");
284 Assert.That(returnValue2, Is.EqualTo(""));
285 }
286
287 // Test remove of node in object pointing to another object
288 {
289 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : 'Wally' } }");
290
291 int returnValue = (int)InvokeOp( "JsonRemoveValue", storeId, "Hello");
292 Assert.That(returnValue, Is.EqualTo(1));
293
294 int result = (int)InvokeOp("JsonTestPath", storeId, "Hello");
295 Assert.That(result, Is.EqualTo(0));
296
297 string returnValue2 = (string)InvokeOp("JsonGetJson", storeId, "Hello");
298 Assert.That(returnValue2, Is.EqualTo(""));
299 }
300
301 // Test remove of node in an array
302 {
303 UUID storeId
304 = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : [ 'value1', 'value2' ] }");
305
306 int returnValue = (int)InvokeOp( "JsonRemoveValue", storeId, "Hello[0]");
307 Assert.That(returnValue, Is.EqualTo(1));
246 308
247 int returnValue = (int)InvokeOp( "JsonRemoveValue", storeId, "Hello"); 309 int result = (int)InvokeOp("JsonTestPath", storeId, "Hello[0]");
248 Assert.That(returnValue, Is.EqualTo(1)); 310 Assert.That(result, Is.EqualTo(1));
311
312 result = (int)InvokeOp("JsonTestPath", storeId, "Hello[1]");
313 Assert.That(result, Is.EqualTo(0));
249 314
250 int result = (int)InvokeOp("JsonTestPath", storeId, "Hello"); 315 string stringReturnValue = (string)InvokeOp("JsonGetValue", storeId, "Hello[0]");
251 Assert.That(result, Is.EqualTo(0)); 316 Assert.That(stringReturnValue, Is.EqualTo("value2"));
252 317
253 string returnValue2 = (string)InvokeOp("JsonGetValue", storeId, "Hello"); 318 stringReturnValue = (string)InvokeOp("JsonGetJson", storeId, "Hello[1]");
254 Assert.That(returnValue2, Is.EqualTo("")); 319 Assert.That(stringReturnValue, Is.EqualTo(""));
320 }
255 321
256 // Test remove of non-existing value 322 // Test remove of non-existing value
257 int fakeValueRemove = (int)InvokeOp("JsonRemoveValue", storeId, "Hello"); 323 {
258 Assert.That(fakeValueRemove, Is.EqualTo(0)); 324 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : 'World' }");
259 325
260 // Test get from non-existing store 326 int fakeValueRemove = (int)InvokeOp("JsonRemoveValue", storeId, "Cheese");
261 UUID fakeStoreId = TestHelpers.ParseTail(0x500); 327 Assert.That(fakeValueRemove, Is.EqualTo(0));
262 int fakeStoreValueRemove = (int)InvokeOp("JsonRemoveValue", fakeStoreId, "Hello"); 328 }
263 Assert.That(fakeStoreValueRemove, Is.EqualTo(0)); 329
330 {
331 // Test get from non-existing store
332 UUID fakeStoreId = TestHelpers.ParseTail(0x500);
333 int fakeStoreValueRemove = (int)InvokeOp("JsonRemoveValue", fakeStoreId, "Hello");
334 Assert.That(fakeStoreValueRemove, Is.EqualTo(0));
335 }
264 } 336 }
265 337
338// [Test]
339// public void TestJsonTestPath()
340// {
341// TestHelpers.InMethod();
342//// TestHelpers.EnableLogging();
343//
344// UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : 'One' } }");
345//
346// {
347// int result = (int)InvokeOp("JsonTestPath", storeId, "Hello.World");
348// Assert.That(result, Is.EqualTo(1));
349// }
350//
351// // Test for path which does not resolve to a value.
352// {
353// int result = (int)InvokeOp("JsonTestPath", storeId, "Hello");
354// Assert.That(result, Is.EqualTo(0));
355// }
356//
357// {
358// int result2 = (int)InvokeOp("JsonTestPath", storeId, "foo");
359// Assert.That(result2, Is.EqualTo(0));
360// }
361//
362// // Test with fake store
363// {
364// UUID fakeStoreId = TestHelpers.ParseTail(0x500);
365// int fakeStoreValueRemove = (int)InvokeOp("JsonTestPath", fakeStoreId, "Hello");
366// Assert.That(fakeStoreValueRemove, Is.EqualTo(0));
367// }
368// }
369
370// [Test]
371// public void TestJsonTestPathJson()
372// {
373// TestHelpers.InMethod();
374//// TestHelpers.EnableLogging();
375//
376// UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : 'One' } }");
377//
378// {
379// int result = (int)InvokeOp("JsonTestPathJson", storeId, "Hello.World");
380// Assert.That(result, Is.EqualTo(1));
381// }
382//
383// // Test for path which does not resolve to a value.
384// {
385// int result = (int)InvokeOp("JsonTestPathJson", storeId, "Hello");
386// Assert.That(result, Is.EqualTo(1));
387// }
388//
389// {
390// int result2 = (int)InvokeOp("JsonTestPathJson", storeId, "foo");
391// Assert.That(result2, Is.EqualTo(0));
392// }
393//
394// // Test with fake store
395// {
396// UUID fakeStoreId = TestHelpers.ParseTail(0x500);
397// int fakeStoreValueRemove = (int)InvokeOp("JsonTestPathJson", fakeStoreId, "Hello");
398// Assert.That(fakeStoreValueRemove, Is.EqualTo(0));
399// }
400// }
401
266 [Test] 402 [Test]
267 public void TestJsonTestPath() 403 public void TestGetArrayLength()
268 { 404 {
269 TestHelpers.InMethod(); 405 TestHelpers.InMethod();
270// TestHelpers.EnableLogging(); 406// TestHelpers.EnableLogging();
271 407
272 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : 'One' } }"); 408 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : [ 'one', 2 ] } }");
273 409
274 { 410 {
275 int result = (int)InvokeOp("JsonTestPath", storeId, "Hello.World"); 411 int result = (int)InvokeOp("JsonGetArrayLength", storeId, "Hello.World");
276 Assert.That(result, Is.EqualTo(1)); 412 Assert.That(result, Is.EqualTo(2));
277 } 413 }
278 414
279 // Test for path which does not resolve to a value. 415 // Test path which is not an array
280 { 416 {
281 int result = (int)InvokeOp("JsonTestPath", storeId, "Hello"); 417 int result = (int)InvokeOp("JsonGetArrayLength", storeId, "Hello");
282 Assert.That(result, Is.EqualTo(0)); 418 Assert.That(result, Is.EqualTo(-1));
283 } 419 }
284 420
421 // Test fake path
285 { 422 {
286 int result2 = (int)InvokeOp("JsonTestPath", storeId, "foo"); 423 int result = (int)InvokeOp("JsonGetArrayLength", storeId, "foo");
287 Assert.That(result2, Is.EqualTo(0)); 424 Assert.That(result, Is.EqualTo(-1));
288 } 425 }
289 426
290 // Test with fake store 427 // Test fake store
291 { 428 {
292 UUID fakeStoreId = TestHelpers.ParseTail(0x500); 429 UUID fakeStoreId = TestHelpers.ParseTail(0x500);
293 int fakeStoreValueRemove = (int)InvokeOp("JsonTestPath", fakeStoreId, "Hello"); 430 int result = (int)InvokeOp("JsonGetArrayLength", fakeStoreId, "Hello.World");
294 Assert.That(fakeStoreValueRemove, Is.EqualTo(0)); 431 Assert.That(result, Is.EqualTo(-1));
295 } 432 }
296 } 433 }
297 434
298 [Test] 435 [Test]
299 public void TestJsonTestPathJson() 436 public void TestJsonGetPathType()
300 { 437 {
301 TestHelpers.InMethod(); 438 TestHelpers.InMethod();
302// TestHelpers.EnableLogging(); 439// TestHelpers.EnableLogging();
303 440
304 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : 'One' } }"); 441 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : [ 'one', 2 ] } }");
305 442
306 { 443 {
307 int result = (int)InvokeOp("JsonTestPathJson", storeId, "Hello.World"); 444 int result = (int)InvokeOp("JsonGetPathType", storeId, ".");
308 Assert.That(result, Is.EqualTo(1)); 445 Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_OBJECT));
309 } 446 }
310 447
311 // Test for path which does not resolve to a value.
312 { 448 {
313 int result = (int)InvokeOp("JsonTestPathJson", storeId, "Hello"); 449 int result = (int)InvokeOp("JsonGetPathType", storeId, "Hello");
314 Assert.That(result, Is.EqualTo(1)); 450 Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_OBJECT));
315 } 451 }
316 452
317 { 453 {
318 int result2 = (int)InvokeOp("JsonTestPathJson", storeId, "foo"); 454 int result = (int)InvokeOp("JsonGetPathType", storeId, "Hello.World");
319 Assert.That(result2, Is.EqualTo(0)); 455 Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_ARRAY));
320 } 456 }
321 457
322 // Test with fake store 458 {
459 int result = (int)InvokeOp("JsonGetPathType", storeId, "Hello.World[0]");
460 Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_VALUE));
461 }
462
463 {
464 int result = (int)InvokeOp("JsonGetPathType", storeId, "Hello.World[1]");
465 Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_VALUE));
466 }
467
468 // Test for non-existant path
469 {
470 int result = (int)InvokeOp("JsonGetPathType", storeId, "foo");
471 Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_UNDEF));
472 }
473
474 // Test for non-existant store
323 { 475 {
324 UUID fakeStoreId = TestHelpers.ParseTail(0x500); 476 UUID fakeStoreId = TestHelpers.ParseTail(0x500);
325 int fakeStoreValueRemove = (int)InvokeOp("JsonTestPathJson", fakeStoreId, "Hello"); 477 int result = (int)InvokeOp("JsonGetPathType", fakeStoreId, ".");
326 Assert.That(fakeStoreValueRemove, Is.EqualTo(0)); 478 Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_TYPE_UNDEF));
479 }
480 }
481
482 [Test]
483 public void TestJsonList2Path()
484 {
485 TestHelpers.InMethod();
486// TestHelpers.EnableLogging();
487
488 // Invoking these methods directly since I just couldn't get comms module invocation to work for some reason
489 // - some confusion with the methods that take a params object[] invocation.
490 {
491 string result = m_jssm.JsonList2Path(UUID.Zero, UUID.Zero, new object[] { "foo" });
492 Assert.That(result, Is.EqualTo("{foo}"));
493 }
494
495 {
496 string result = m_jssm.JsonList2Path(UUID.Zero, UUID.Zero, new object[] { "foo", "bar" });
497 Assert.That(result, Is.EqualTo("{foo}.{bar}"));
498 }
499
500 {
501 string result = m_jssm.JsonList2Path(UUID.Zero, UUID.Zero, new object[] { "foo", 1, "bar" });
502 Assert.That(result, Is.EqualTo("{foo}.[1].{bar}"));
327 } 503 }
328 } 504 }
329 505
@@ -334,7 +510,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
334// TestHelpers.EnableLogging(); 510// TestHelpers.EnableLogging();
335 511
336 { 512 {
337 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ }"); 513 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
338 514
339 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun", "Times"); 515 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun", "Times");
340 Assert.That(result, Is.EqualTo(1)); 516 Assert.That(result, Is.EqualTo(1));
@@ -343,9 +519,155 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
343 Assert.That(value, Is.EqualTo("Times")); 519 Assert.That(value, Is.EqualTo("Times"));
344 } 520 }
345 521
522 // Test setting a key containing periods with delineation
523 {
524 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
525
526 int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun.Circus}", "Times");
527 Assert.That(result, Is.EqualTo(1));
528
529 string value = (string)InvokeOp("JsonGetValue", storeId, "{Fun.Circus}");
530 Assert.That(value, Is.EqualTo("Times"));
531 }
532
533 // *** Test [] ***
534
535 // Test setting a key containing unbalanced ] without delineation. Expecting failure
536 {
537 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
538
539 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun]Circus", "Times");
540 Assert.That(result, Is.EqualTo(0));
541
542 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun]Circus");
543 Assert.That(value, Is.EqualTo(""));
544 }
545
546 // Test setting a key containing unbalanced [ without delineation. Expecting failure
547 {
548 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
549
550 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun[Circus", "Times");
551 Assert.That(result, Is.EqualTo(0));
552
553 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun[Circus");
554 Assert.That(value, Is.EqualTo(""));
555 }
556
557 // Test setting a key containing unbalanced [] without delineation. Expecting failure
558 {
559 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
560
561 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun[]Circus", "Times");
562 Assert.That(result, Is.EqualTo(0));
563
564 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun[]Circus");
565 Assert.That(value, Is.EqualTo(""));
566 }
567
568 // Test setting a key containing unbalanced ] with delineation
569 {
570 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
571
572 int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun]Circus}", "Times");
573 Assert.That(result, Is.EqualTo(1));
574
575 string value = (string)InvokeOp("JsonGetValue", storeId, "{Fun]Circus}");
576 Assert.That(value, Is.EqualTo("Times"));
577 }
578
579 // Test setting a key containing unbalanced [ with delineation
580 {
581 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
582
583 int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun[Circus}", "Times");
584 Assert.That(result, Is.EqualTo(1));
585
586 string value = (string)InvokeOp("JsonGetValue", storeId, "{Fun[Circus}");
587 Assert.That(value, Is.EqualTo("Times"));
588 }
589
590 // Test setting a key containing empty balanced [] with delineation
591 {
592 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
593
594 int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun[]Circus}", "Times");
595 Assert.That(result, Is.EqualTo(1));
596
597 string value = (string)InvokeOp("JsonGetValue", storeId, "{Fun[]Circus}");
598 Assert.That(value, Is.EqualTo("Times"));
599 }
600
601// // Commented out as this currently unexpectedly fails.
602// // Test setting a key containing brackets around an integer with delineation
603// {
604// UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
605//
606// int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun[0]Circus}", "Times");
607// Assert.That(result, Is.EqualTo(1));
608//
609// string value = (string)InvokeOp("JsonGetValue", storeId, "{Fun[0]Circus}");
610// Assert.That(value, Is.EqualTo("Times"));
611// }
612
613 // *** Test {} ***
614
615 // Test setting a key containing unbalanced } without delineation. Expecting failure (?)
616 {
617 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
618
619 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun}Circus", "Times");
620 Assert.That(result, Is.EqualTo(0));
621
622 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun}Circus");
623 Assert.That(value, Is.EqualTo(""));
624 }
625
626 // Test setting a key containing unbalanced { without delineation. Expecting failure (?)
627 {
628 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
629
630 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun{Circus", "Times");
631 Assert.That(result, Is.EqualTo(0));
632
633 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun}Circus");
634 Assert.That(value, Is.EqualTo(""));
635 }
636
637// // Commented out as this currently unexpectedly fails.
638// // Test setting a key containing unbalanced }
639// {
640// UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
641//
642// int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun}Circus}", "Times");
643// Assert.That(result, Is.EqualTo(0));
644// }
645
646 // Test setting a key containing unbalanced { with delineation
647 {
648 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
649
650 int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun{Circus}", "Times");
651 Assert.That(result, Is.EqualTo(1));
652
653 string value = (string)InvokeOp("JsonGetValue", storeId, "{Fun{Circus}");
654 Assert.That(value, Is.EqualTo("Times"));
655 }
656
657 // Test setting a key containing balanced {} with delineation. This should fail.
658 {
659 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
660
661 int result = (int)InvokeOp("JsonSetValue", storeId, "{Fun{Filled}Circus}", "Times");
662 Assert.That(result, Is.EqualTo(0));
663
664 string value = (string)InvokeOp("JsonGetValue", storeId, "{Fun{Filled}Circus}");
665 Assert.That(value, Is.EqualTo(""));
666 }
667
346 // Test setting to location that does not exist. This should fail. 668 // Test setting to location that does not exist. This should fail.
347 { 669 {
348 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ }"); 670 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}");
349 671
350 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun.Circus", "Times"); 672 int result = (int)InvokeOp("JsonSetValue", storeId, "Fun.Circus", "Times");
351 Assert.That(result, Is.EqualTo(0)); 673 Assert.That(result, Is.EqualTo(0));
@@ -363,27 +685,27 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
363 } 685 }
364 686
365 [Test] 687 [Test]
366 public void TestJsonSetValueJson() 688 public void TestJsonSetJson()
367 { 689 {
368 TestHelpers.InMethod(); 690 TestHelpers.InMethod();
369// TestHelpers.EnableLogging(); 691// TestHelpers.EnableLogging();
370 692
371 // Single quoted token case 693 // Single quoted token case
372// { 694 {
373// UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ }"); 695 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ }");
374// 696
375// int result = (int)InvokeOp("JsonSetValueJson", storeId, "Fun", "'Times'"); 697 int result = (int)InvokeOp("JsonSetJson", storeId, "Fun", "'Times'");
376// Assert.That(result, Is.EqualTo(1)); 698 Assert.That(result, Is.EqualTo(1));
377// 699
378// string value = (string)InvokeOp("JsonGetValue", storeId, "Fun"); 700 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun");
379// Assert.That(value, Is.EqualTo("Times")); 701 Assert.That(value, Is.EqualTo("Times"));
380// } 702 }
381 703
382 // Sub-tree case 704 // Sub-tree case
383 { 705 {
384 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ }"); 706 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ }");
385 707
386 int result = (int)InvokeOp("JsonSetValueJson", storeId, "Fun", "{ 'Filled' : 'Times' }"); 708 int result = (int)InvokeOp("JsonSetJson", storeId, "Fun", "{ 'Filled' : 'Times' }");
387 Assert.That(result, Is.EqualTo(1)); 709 Assert.That(result, Is.EqualTo(1));
388 710
389 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun.Filled"); 711 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun.Filled");
@@ -394,7 +716,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
394 { 716 {
395 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ }"); 717 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ }");
396 718
397 int result = (int)InvokeOp("JsonSetValueJson", storeId, "Fun", "Times"); 719 int result = (int)InvokeOp("JsonSetJson", storeId, "Fun", "Times");
398 Assert.That(result, Is.EqualTo(0)); 720 Assert.That(result, Is.EqualTo(0));
399 721
400 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun"); 722 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun");
@@ -405,7 +727,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
405 { 727 {
406 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ }"); 728 UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ }");
407 729
408 int result = (int)InvokeOp("JsonSetValueJson", storeId, "Fun.Circus", "'Times'"); 730 int result = (int)InvokeOp("JsonSetJson", storeId, "Fun.Circus", "'Times'");
409 Assert.That(result, Is.EqualTo(0)); 731 Assert.That(result, Is.EqualTo(0));
410 732
411 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun.Circus"); 733 string value = (string)InvokeOp("JsonGetValue", storeId, "Fun.Circus");
@@ -415,7 +737,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests
415 // Test with fake store 737 // Test with fake store
416 { 738 {
417 UUID fakeStoreId = TestHelpers.ParseTail(0x500); 739 UUID fakeStoreId = TestHelpers.ParseTail(0x500);
418 int fakeStoreValueSet = (int)InvokeOp("JsonSetValueJson", fakeStoreId, "Hello", "'World'"); 740 int fakeStoreValueSet = (int)InvokeOp("JsonSetJson", fakeStoreId, "Hello", "'World'");
419 Assert.That(fakeStoreValueSet, Is.EqualTo(0)); 741 Assert.That(fakeStoreValueSet, Is.EqualTo(0));
420 } 742 }
421 } 743 }