opensim-development – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 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 | |||
28 | using System; |
||
29 | using System.Collections.Generic; |
||
30 | using System.Reflection; |
||
31 | using System.Text; |
||
32 | using log4net; |
||
33 | using Nini.Config; |
||
34 | using NUnit.Framework; |
||
35 | using OpenMetaverse; |
||
36 | using OpenSim.Framework; |
||
37 | using OpenSim.Region.CoreModules.Scripting.ScriptModuleComms; |
||
38 | using OpenSim.Region.Framework.Scenes; |
||
39 | using OpenSim.Region.ScriptEngine.Shared; |
||
40 | using OpenSim.Region.ScriptEngine.Shared.Api; |
||
41 | using OpenSim.Services.Interfaces; |
||
42 | using OpenSim.Tests.Common; |
||
43 | using OpenSim.Tests.Common.Mock; |
||
44 | |||
45 | namespace OpenSim.Region.OptionalModules.Scripting.JsonStore.Tests |
||
46 | { |
||
47 | /// <summary> |
||
48 | /// Tests for inventory functions in LSL |
||
49 | /// </summary> |
||
50 | [TestFixture] |
||
51 | public class JsonStoreScriptModuleTests : OpenSimTestCase |
||
52 | { |
||
53 | private Scene m_scene; |
||
54 | private MockScriptEngine m_engine; |
||
55 | private ScriptModuleCommsModule m_smcm; |
||
56 | private JsonStoreScriptModule m_jssm; |
||
57 | |||
58 | [TestFixtureSetUp] |
||
59 | public void FixtureInit() |
||
60 | { |
||
61 | // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread. |
||
62 | Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest; |
||
63 | } |
||
64 | |||
65 | [TestFixtureTearDown] |
||
66 | public void TearDown() |
||
67 | { |
||
68 | // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple |
||
69 | // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression |
||
70 | // tests really shouldn't). |
||
71 | Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod; |
||
72 | } |
||
73 | |||
74 | [SetUp] |
||
75 | public override void SetUp() |
||
76 | { |
||
77 | base.SetUp(); |
||
78 | |||
79 | IConfigSource configSource = new IniConfigSource(); |
||
80 | IConfig jsonStoreConfig = configSource.AddConfig("JsonStore"); |
||
81 | jsonStoreConfig.Set("Enabled", "true"); |
||
82 | |||
83 | m_engine = new MockScriptEngine(); |
||
84 | m_smcm = new ScriptModuleCommsModule(); |
||
85 | JsonStoreModule jsm = new JsonStoreModule(); |
||
86 | m_jssm = new JsonStoreScriptModule(); |
||
87 | |||
88 | m_scene = new SceneHelpers().SetupScene(); |
||
89 | SceneHelpers.SetupSceneModules(m_scene, configSource, m_engine, m_smcm, jsm, m_jssm); |
||
90 | |||
91 | try |
||
92 | { |
||
93 | m_smcm.RegisterScriptInvocation(this, "DummyTestMethod"); |
||
94 | } |
||
95 | catch (ArgumentException) |
||
96 | { |
||
97 | Assert.Ignore("Ignoring test since running on .NET 3.5 or earlier."); |
||
98 | } |
||
99 | |||
100 | // XXX: Unfortunately, ICommsModule currently has no way of deregistering methods. |
||
101 | } |
||
102 | |||
103 | private object InvokeOp(string name, params object[] args) |
||
104 | { |
||
105 | return InvokeOpOnHost(name, UUID.Zero, args); |
||
106 | } |
||
107 | |||
108 | private object InvokeOpOnHost(string name, UUID hostId, params object[] args) |
||
109 | { |
||
110 | return m_smcm.InvokeOperation(hostId, UUID.Zero, name, args); |
||
111 | } |
||
112 | |||
113 | [Test] |
||
114 | public void TestJsonCreateStore() |
||
115 | { |
||
116 | TestHelpers.InMethod(); |
||
117 | // TestHelpers.EnableLogging(); |
||
118 | |||
119 | // Test blank store |
||
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 | } |
||
148 | } |
||
149 | |||
150 | [Test] |
||
151 | public void TestJsonDestroyStore() |
||
152 | { |
||
153 | TestHelpers.InMethod(); |
||
154 | // TestHelpers.EnableLogging(); |
||
155 | |||
156 | UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : 'World' }"); |
||
157 | int dsrv = (int)InvokeOp("JsonDestroyStore", storeId); |
||
158 | |||
159 | Assert.That(dsrv, Is.EqualTo(1)); |
||
160 | |||
161 | int tprv = (int)InvokeOp("JsonGetNodeType", storeId, "Hello"); |
||
162 | Assert.That(tprv, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_UNDEF)); |
||
163 | } |
||
164 | |||
165 | [Test] |
||
166 | public void TestJsonDestroyStoreNotExists() |
||
167 | { |
||
168 | TestHelpers.InMethod(); |
||
169 | // TestHelpers.EnableLogging(); |
||
170 | |||
171 | UUID fakeStoreId = TestHelpers.ParseTail(0x500); |
||
172 | |||
173 | int dsrv = (int)InvokeOp("JsonDestroyStore", fakeStoreId); |
||
174 | |||
175 | Assert.That(dsrv, Is.EqualTo(0)); |
||
176 | } |
||
177 | |||
178 | [Test] |
||
179 | public void TestJsonGetValue() |
||
180 | { |
||
181 | TestHelpers.InMethod(); |
||
182 | // TestHelpers.EnableLogging(); |
||
183 | |||
184 | UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : 'Two' } }"); |
||
185 | |||
186 | { |
||
187 | string value = (string)InvokeOp("JsonGetValue", storeId, "Hello.World"); |
||
188 | Assert.That(value, Is.EqualTo("Two")); |
||
189 | } |
||
190 | |||
191 | // Test get of path section instead of leaf |
||
192 | { |
||
193 | string value = (string)InvokeOp("JsonGetValue", storeId, "Hello"); |
||
194 | Assert.That(value, Is.EqualTo("")); |
||
195 | } |
||
196 | |||
197 | // Test get of non-existing value |
||
198 | { |
||
199 | string fakeValueGet = (string)InvokeOp("JsonGetValue", storeId, "foo"); |
||
200 | Assert.That(fakeValueGet, Is.EqualTo("")); |
||
201 | } |
||
202 | |||
203 | // Test get from non-existing store |
||
204 | { |
||
205 | UUID fakeStoreId = TestHelpers.ParseTail(0x500); |
||
206 | string fakeStoreValueGet = (string)InvokeOp("JsonGetValue", fakeStoreId, "Hello"); |
||
207 | Assert.That(fakeStoreValueGet, Is.EqualTo("")); |
||
208 | } |
||
209 | } |
||
210 | |||
211 | [Test] |
||
212 | public void TestJsonGetJson() |
||
213 | { |
||
214 | TestHelpers.InMethod(); |
||
215 | // TestHelpers.EnableLogging(); |
||
216 | |||
217 | UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : 'Two' } }"); |
||
218 | |||
219 | { |
||
220 | string value = (string)InvokeOp("JsonGetJson", storeId, "Hello.World"); |
||
221 | Assert.That(value, Is.EqualTo("'Two'")); |
||
222 | } |
||
223 | |||
224 | // Test get of path section instead of leaf |
||
225 | { |
||
226 | string value = (string)InvokeOp("JsonGetJson", storeId, "Hello"); |
||
227 | Assert.That(value, Is.EqualTo("{\"World\":\"Two\"}")); |
||
228 | } |
||
229 | |||
230 | // Test get of non-existing value |
||
231 | { |
||
232 | string fakeValueGet = (string)InvokeOp("JsonGetJson", storeId, "foo"); |
||
233 | Assert.That(fakeValueGet, Is.EqualTo("")); |
||
234 | } |
||
235 | |||
236 | // Test get from non-existing store |
||
237 | { |
||
238 | UUID fakeStoreId = TestHelpers.ParseTail(0x500); |
||
239 | string fakeStoreValueGet = (string)InvokeOp("JsonGetJson", fakeStoreId, "Hello"); |
||
240 | Assert.That(fakeStoreValueGet, Is.EqualTo("")); |
||
241 | } |
||
242 | } |
||
243 | |||
244 | // [Test] |
||
245 | // public void TestJsonTakeValue() |
||
246 | // { |
||
247 | // TestHelpers.InMethod(); |
||
248 | //// TestHelpers.EnableLogging(); |
||
249 | // |
||
250 | // UUID storeId |
||
251 | // = (UUID)m_smcm.InvokeOperation( |
||
252 | // UUID.Zero, UUID.Zero, "JsonCreateStore", new object[] { "{ 'Hello' : 'World' }" }); |
||
253 | // |
||
254 | // string value |
||
255 | // = (string)m_smcm.InvokeOperation( |
||
256 | // UUID.Zero, UUID.Zero, "JsonTakeValue", new object[] { storeId, "Hello" }); |
||
257 | // |
||
258 | // Assert.That(value, Is.EqualTo("World")); |
||
259 | // |
||
260 | // string value2 |
||
261 | // = (string)m_smcm.InvokeOperation( |
||
262 | // UUID.Zero, UUID.Zero, "JsonGetValue", new object[] { storeId, "Hello" }); |
||
263 | // |
||
264 | // Assert.That(value, Is.Null); |
||
265 | // } |
||
266 | |||
267 | [Test] |
||
268 | public void TestJsonRemoveValue() |
||
269 | { |
||
270 | TestHelpers.InMethod(); |
||
271 | // TestHelpers.EnableLogging(); |
||
272 | |||
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("JsonGetNodeType", storeId, "Hello"); |
||
281 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_UNDEF)); |
||
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("JsonGetNodeType", storeId, "Hello"); |
||
295 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_UNDEF)); |
||
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)); |
||
308 | |||
309 | int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello[0]"); |
||
310 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_VALUE)); |
||
311 | |||
312 | result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello[1]"); |
||
313 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_UNDEF)); |
||
314 | |||
315 | string stringReturnValue = (string)InvokeOp("JsonGetValue", storeId, "Hello[0]"); |
||
316 | Assert.That(stringReturnValue, Is.EqualTo("value2")); |
||
317 | |||
318 | stringReturnValue = (string)InvokeOp("JsonGetJson", storeId, "Hello[1]"); |
||
319 | Assert.That(stringReturnValue, Is.EqualTo("")); |
||
320 | } |
||
321 | |||
322 | // Test remove of non-existing value |
||
323 | { |
||
324 | UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : 'World' }"); |
||
325 | |||
326 | int fakeValueRemove = (int)InvokeOp("JsonRemoveValue", storeId, "Cheese"); |
||
327 | Assert.That(fakeValueRemove, Is.EqualTo(0)); |
||
328 | } |
||
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 | } |
||
336 | } |
||
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 | |||
402 | [Test] |
||
403 | public void TestJsonGetArrayLength() |
||
404 | { |
||
405 | TestHelpers.InMethod(); |
||
406 | // TestHelpers.EnableLogging(); |
||
407 | |||
408 | UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : [ 'one', 2 ] } }"); |
||
409 | |||
410 | { |
||
411 | int result = (int)InvokeOp("JsonGetArrayLength", storeId, "Hello.World"); |
||
412 | Assert.That(result, Is.EqualTo(2)); |
||
413 | } |
||
414 | |||
415 | // Test path which is not an array |
||
416 | { |
||
417 | int result = (int)InvokeOp("JsonGetArrayLength", storeId, "Hello"); |
||
418 | Assert.That(result, Is.EqualTo(-1)); |
||
419 | } |
||
420 | |||
421 | // Test fake path |
||
422 | { |
||
423 | int result = (int)InvokeOp("JsonGetArrayLength", storeId, "foo"); |
||
424 | Assert.That(result, Is.EqualTo(-1)); |
||
425 | } |
||
426 | |||
427 | // Test fake store |
||
428 | { |
||
429 | UUID fakeStoreId = TestHelpers.ParseTail(0x500); |
||
430 | int result = (int)InvokeOp("JsonGetArrayLength", fakeStoreId, "Hello.World"); |
||
431 | Assert.That(result, Is.EqualTo(-1)); |
||
432 | } |
||
433 | } |
||
434 | |||
435 | [Test] |
||
436 | public void TestJsonGetNodeType() |
||
437 | { |
||
438 | TestHelpers.InMethod(); |
||
439 | // TestHelpers.EnableLogging(); |
||
440 | |||
441 | UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello' : { 'World' : [ 'one', 2 ] } }"); |
||
442 | |||
443 | { |
||
444 | int result = (int)InvokeOp("JsonGetNodeType", storeId, "."); |
||
445 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_OBJECT)); |
||
446 | } |
||
447 | |||
448 | { |
||
449 | int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello"); |
||
450 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_OBJECT)); |
||
451 | } |
||
452 | |||
453 | { |
||
454 | int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello.World"); |
||
455 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_ARRAY)); |
||
456 | } |
||
457 | |||
458 | { |
||
459 | int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello.World[0]"); |
||
460 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_VALUE)); |
||
461 | } |
||
462 | |||
463 | { |
||
464 | int result = (int)InvokeOp("JsonGetNodeType", storeId, "Hello.World[1]"); |
||
465 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_VALUE)); |
||
466 | } |
||
467 | |||
468 | // Test for non-existant path |
||
469 | { |
||
470 | int result = (int)InvokeOp("JsonGetNodeType", storeId, "foo"); |
||
471 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_UNDEF)); |
||
472 | } |
||
473 | |||
474 | // Test for non-existant store |
||
475 | { |
||
476 | UUID fakeStoreId = TestHelpers.ParseTail(0x500); |
||
477 | int result = (int)InvokeOp("JsonGetNodeType", fakeStoreId, "."); |
||
478 | Assert.That(result, Is.EqualTo(JsonStoreScriptModule.JSON_NODETYPE_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}")); |
||
503 | } |
||
504 | } |
||
505 | |||
506 | [Test] |
||
507 | public void TestJsonSetValue() |
||
508 | { |
||
509 | TestHelpers.InMethod(); |
||
510 | // TestHelpers.EnableLogging(); |
||
511 | |||
512 | { |
||
513 | UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}"); |
||
514 | |||
515 | int result = (int)InvokeOp("JsonSetValue", storeId, "Fun", "Times"); |
||
516 | Assert.That(result, Is.EqualTo(1)); |
||
517 | |||
518 | string value = (string)InvokeOp("JsonGetValue", storeId, "Fun"); |
||
519 | Assert.That(value, Is.EqualTo("Times")); |
||
520 | } |
||
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 | |||
668 | // Test setting to location that does not exist. This should fail. |
||
669 | { |
||
670 | UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{}"); |
||
671 | |||
672 | int result = (int)InvokeOp("JsonSetValue", storeId, "Fun.Circus", "Times"); |
||
673 | Assert.That(result, Is.EqualTo(0)); |
||
674 | |||
675 | string value = (string)InvokeOp("JsonGetValue", storeId, "Fun.Circus"); |
||
676 | Assert.That(value, Is.EqualTo("")); |
||
677 | } |
||
678 | |||
679 | // Test with fake store |
||
680 | { |
||
681 | UUID fakeStoreId = TestHelpers.ParseTail(0x500); |
||
682 | int fakeStoreValueSet = (int)InvokeOp("JsonSetValue", fakeStoreId, "Hello", "World"); |
||
683 | Assert.That(fakeStoreValueSet, Is.EqualTo(0)); |
||
684 | } |
||
685 | } |
||
686 | |||
687 | [Test] |
||
688 | public void TestJsonSetJson() |
||
689 | { |
||
690 | TestHelpers.InMethod(); |
||
691 | // TestHelpers.EnableLogging(); |
||
692 | |||
693 | // Single quoted token case |
||
694 | { |
||
695 | UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ }"); |
||
696 | |||
697 | int result = (int)InvokeOp("JsonSetJson", storeId, "Fun", "'Times'"); |
||
698 | Assert.That(result, Is.EqualTo(1)); |
||
699 | |||
700 | string value = (string)InvokeOp("JsonGetValue", storeId, "Fun"); |
||
701 | Assert.That(value, Is.EqualTo("Times")); |
||
702 | } |
||
703 | |||
704 | // Sub-tree case |
||
705 | { |
||
706 | UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ }"); |
||
707 | |||
708 | int result = (int)InvokeOp("JsonSetJson", storeId, "Fun", "{ 'Filled' : 'Times' }"); |
||
709 | Assert.That(result, Is.EqualTo(1)); |
||
710 | |||
711 | string value = (string)InvokeOp("JsonGetValue", storeId, "Fun.Filled"); |
||
712 | Assert.That(value, Is.EqualTo("Times")); |
||
713 | } |
||
714 | |||
715 | // If setting single strings in JsonSetValueJson, these must be single quoted tokens, not bare strings. |
||
716 | { |
||
717 | UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ }"); |
||
718 | |||
719 | int result = (int)InvokeOp("JsonSetJson", storeId, "Fun", "Times"); |
||
720 | Assert.That(result, Is.EqualTo(0)); |
||
721 | |||
722 | string value = (string)InvokeOp("JsonGetValue", storeId, "Fun"); |
||
723 | Assert.That(value, Is.EqualTo("")); |
||
724 | } |
||
725 | |||
726 | // Test setting to location that does not exist. This should fail. |
||
727 | { |
||
728 | UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ }"); |
||
729 | |||
730 | int result = (int)InvokeOp("JsonSetJson", storeId, "Fun.Circus", "'Times'"); |
||
731 | Assert.That(result, Is.EqualTo(0)); |
||
732 | |||
733 | string value = (string)InvokeOp("JsonGetValue", storeId, "Fun.Circus"); |
||
734 | Assert.That(value, Is.EqualTo("")); |
||
735 | } |
||
736 | |||
737 | // Test with fake store |
||
738 | { |
||
739 | UUID fakeStoreId = TestHelpers.ParseTail(0x500); |
||
740 | int fakeStoreValueSet = (int)InvokeOp("JsonSetJson", fakeStoreId, "Hello", "'World'"); |
||
741 | Assert.That(fakeStoreValueSet, Is.EqualTo(0)); |
||
742 | } |
||
743 | } |
||
744 | |||
745 | /// <summary> |
||
746 | /// Test for writing json to a notecard |
||
747 | /// </summary> |
||
748 | /// <remarks> |
||
749 | /// TODO: Really needs to test correct receipt of the link_message event. Could do this by directly fetching |
||
750 | /// it via the MockScriptEngine or perhaps by a dummy script instance. |
||
751 | /// </remarks> |
||
752 | [Test] |
||
753 | public void TestJsonWriteNotecard() |
||
754 | { |
||
755 | TestHelpers.InMethod(); |
||
756 | // TestHelpers.EnableLogging(); |
||
757 | |||
758 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, TestHelpers.ParseTail(0x1)); |
||
759 | m_scene.AddSceneObject(so); |
||
760 | |||
761 | UUID storeId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello':'World' }"); |
||
762 | |||
763 | { |
||
764 | string notecardName = "nc1"; |
||
765 | |||
766 | // Write notecard |
||
767 | UUID writeNotecardRequestId = (UUID)InvokeOpOnHost("JsonWriteNotecard", so.UUID, storeId, "", notecardName); |
||
768 | Assert.That(writeNotecardRequestId, Is.Not.EqualTo(UUID.Zero)); |
||
769 | |||
770 | TaskInventoryItem nc1Item = so.RootPart.Inventory.GetInventoryItem(notecardName); |
||
771 | Assert.That(nc1Item, Is.Not.Null); |
||
772 | |||
773 | // TODO: Should independently check the contents. |
||
774 | } |
||
775 | |||
776 | // TODO: Write partial test |
||
777 | |||
778 | { |
||
779 | // Try to write notecard for a bad path |
||
780 | // In this case we do get a request id but no notecard is written. |
||
781 | string badPathNotecardName = "badPathNotecardName"; |
||
782 | |||
783 | UUID writeNotecardBadPathRequestId |
||
784 | = (UUID)InvokeOpOnHost("JsonWriteNotecard", so.UUID, storeId, "flibble", badPathNotecardName); |
||
785 | Assert.That(writeNotecardBadPathRequestId, Is.Not.EqualTo(UUID.Zero)); |
||
786 | |||
787 | TaskInventoryItem badPathItem = so.RootPart.Inventory.GetInventoryItem(badPathNotecardName); |
||
788 | Assert.That(badPathItem, Is.Null); |
||
789 | } |
||
790 | |||
791 | { |
||
792 | // Test with fake store |
||
793 | // In this case we do get a request id but no notecard is written. |
||
794 | string fakeStoreNotecardName = "fakeStoreNotecardName"; |
||
795 | |||
796 | UUID fakeStoreId = TestHelpers.ParseTail(0x500); |
||
797 | UUID fakeStoreWriteNotecardValue |
||
798 | = (UUID)InvokeOpOnHost("JsonWriteNotecard", so.UUID, fakeStoreId, "", fakeStoreNotecardName); |
||
799 | Assert.That(fakeStoreWriteNotecardValue, Is.Not.EqualTo(UUID.Zero)); |
||
800 | |||
801 | TaskInventoryItem fakeStoreItem = so.RootPart.Inventory.GetInventoryItem(fakeStoreNotecardName); |
||
802 | Assert.That(fakeStoreItem, Is.Null); |
||
803 | } |
||
804 | } |
||
805 | |||
806 | /// <summary> |
||
807 | /// Test for reading json from a notecard |
||
808 | /// </summary> |
||
809 | /// <remarks> |
||
810 | /// TODO: Really needs to test correct receipt of the link_message event. Could do this by directly fetching |
||
811 | /// it via the MockScriptEngine or perhaps by a dummy script instance. |
||
812 | /// </remarks> |
||
813 | [Test] |
||
814 | public void TestJsonReadNotecard() |
||
815 | { |
||
816 | TestHelpers.InMethod(); |
||
817 | // TestHelpers.EnableLogging(); |
||
818 | |||
819 | string notecardName = "nc1"; |
||
820 | |||
821 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, TestHelpers.ParseTail(0x1)); |
||
822 | m_scene.AddSceneObject(so); |
||
823 | |||
824 | UUID creatingStoreId = (UUID)InvokeOp("JsonCreateStore", "{ 'Hello':'World' }"); |
||
825 | |||
826 | // Write notecard |
||
827 | InvokeOpOnHost("JsonWriteNotecard", so.UUID, creatingStoreId, "", notecardName); |
||
828 | |||
829 | { |
||
830 | // Read notecard |
||
831 | UUID receivingStoreId = (UUID)InvokeOp("JsonCreateStore", "{}"); |
||
832 | UUID readNotecardRequestId = (UUID)InvokeOpOnHost("JsonReadNotecard", so.UUID, receivingStoreId, "", notecardName); |
||
833 | Assert.That(readNotecardRequestId, Is.Not.EqualTo(UUID.Zero)); |
||
834 | |||
835 | string value = (string)InvokeOp("JsonGetValue", receivingStoreId, "Hello"); |
||
836 | Assert.That(value, Is.EqualTo("World")); |
||
837 | } |
||
838 | |||
839 | { |
||
840 | // Read notecard to new single component path |
||
841 | UUID receivingStoreId = (UUID)InvokeOp("JsonCreateStore", "{}"); |
||
842 | UUID readNotecardRequestId = (UUID)InvokeOpOnHost("JsonReadNotecard", so.UUID, receivingStoreId, "make", notecardName); |
||
843 | Assert.That(readNotecardRequestId, Is.Not.EqualTo(UUID.Zero)); |
||
844 | |||
845 | string value = (string)InvokeOp("JsonGetValue", receivingStoreId, "Hello"); |
||
846 | Assert.That(value, Is.EqualTo("")); |
||
847 | |||
848 | value = (string)InvokeOp("JsonGetValue", receivingStoreId, "make.Hello"); |
||
849 | Assert.That(value, Is.EqualTo("World")); |
||
850 | } |
||
851 | |||
852 | { |
||
853 | // Read notecard to new multi-component path. This should not work. |
||
854 | UUID receivingStoreId = (UUID)InvokeOp("JsonCreateStore", "{}"); |
||
855 | UUID readNotecardRequestId = (UUID)InvokeOpOnHost("JsonReadNotecard", so.UUID, receivingStoreId, "make.it", notecardName); |
||
856 | Assert.That(readNotecardRequestId, Is.Not.EqualTo(UUID.Zero)); |
||
857 | |||
858 | string value = (string)InvokeOp("JsonGetValue", receivingStoreId, "Hello"); |
||
859 | Assert.That(value, Is.EqualTo("")); |
||
860 | |||
861 | value = (string)InvokeOp("JsonGetValue", receivingStoreId, "make.it.Hello"); |
||
862 | Assert.That(value, Is.EqualTo("")); |
||
863 | } |
||
864 | |||
865 | { |
||
866 | // Read notecard to existing multi-component path. This should work |
||
867 | UUID receivingStoreId = (UUID)InvokeOp("JsonCreateStore", "{ 'make' : { 'it' : 'so' } }"); |
||
868 | UUID readNotecardRequestId = (UUID)InvokeOpOnHost("JsonReadNotecard", so.UUID, receivingStoreId, "make.it", notecardName); |
||
869 | Assert.That(readNotecardRequestId, Is.Not.EqualTo(UUID.Zero)); |
||
870 | |||
871 | string value = (string)InvokeOp("JsonGetValue", receivingStoreId, "Hello"); |
||
872 | Assert.That(value, Is.EqualTo("")); |
||
873 | |||
874 | value = (string)InvokeOp("JsonGetValue", receivingStoreId, "make.it.Hello"); |
||
875 | Assert.That(value, Is.EqualTo("World")); |
||
876 | } |
||
877 | |||
878 | { |
||
879 | // Read notecard to invalid path. This should not work. |
||
880 | UUID receivingStoreId = (UUID)InvokeOp("JsonCreateStore", "{ 'make' : { 'it' : 'so' } }"); |
||
881 | UUID readNotecardRequestId = (UUID)InvokeOpOnHost("JsonReadNotecard", so.UUID, receivingStoreId, "/", notecardName); |
||
882 | Assert.That(readNotecardRequestId, Is.Not.EqualTo(UUID.Zero)); |
||
883 | |||
884 | string value = (string)InvokeOp("JsonGetValue", receivingStoreId, "Hello"); |
||
885 | Assert.That(value, Is.EqualTo("")); |
||
886 | } |
||
887 | |||
888 | { |
||
889 | // Try read notecard to fake store. |
||
890 | UUID fakeStoreId = TestHelpers.ParseTail(0x500); |
||
891 | UUID readNotecardRequestId = (UUID)InvokeOpOnHost("JsonReadNotecard", so.UUID, fakeStoreId, "", notecardName); |
||
892 | Assert.That(readNotecardRequestId, Is.Not.EqualTo(UUID.Zero)); |
||
893 | |||
894 | string value = (string)InvokeOp("JsonGetValue", fakeStoreId, "Hello"); |
||
895 | Assert.That(value, Is.EqualTo("")); |
||
896 | } |
||
897 | } |
||
898 | |||
899 | public object DummyTestMethod(object o1, object o2, object o3, object o4, object o5) { return null; } |
||
900 | } |
||
901 | } |