rooibos-roku 4.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -0
  3. package/dist/lib/framework/BaseTestReporter.bs +27 -0
  4. package/dist/lib/framework/BaseTestSuite.bs +2131 -0
  5. package/dist/lib/framework/CommonUtils.bs +732 -0
  6. package/dist/lib/framework/ConsoleTestReporter.bs +200 -0
  7. package/dist/lib/framework/Coverage.bs +51 -0
  8. package/dist/lib/framework/Matchers.bs +28 -0
  9. package/dist/lib/framework/Rooibos.bs +83 -0
  10. package/dist/lib/framework/RooibosScene.xml +50 -0
  11. package/dist/lib/framework/RuntimeConfig.bs +20 -0
  12. package/dist/lib/framework/Stats.bs +46 -0
  13. package/dist/lib/framework/Test.bs +109 -0
  14. package/dist/lib/framework/TestGroup.bs +109 -0
  15. package/dist/lib/framework/TestResult.bs +74 -0
  16. package/dist/lib/framework/TestRunner.bs +187 -0
  17. package/dist/lib/framework/Utils.bs +63 -0
  18. package/dist/lib/framework/unused/CodeCoverage.brs +35 -0
  19. package/dist/lib/framework/unused/CodeCoverage.xml +13 -0
  20. package/dist/lib/framework/unused/CodeCoverageSupport.brs +56 -0
  21. package/dist/lib/rooibos/Annotation.js +187 -0
  22. package/dist/lib/rooibos/Annotation.js.map +1 -0
  23. package/dist/lib/rooibos/CodeCoverageProcessor.js +114 -0
  24. package/dist/lib/rooibos/CodeCoverageProcessor.js.map +1 -0
  25. package/dist/lib/rooibos/CodeCoverageProcessor.spec.js +62 -0
  26. package/dist/lib/rooibos/CodeCoverageProcessor.spec.js.map +1 -0
  27. package/dist/lib/rooibos/CodeCoverageType.js +11 -0
  28. package/dist/lib/rooibos/CodeCoverageType.js.map +1 -0
  29. package/dist/lib/rooibos/FileFactory.js +92 -0
  30. package/dist/lib/rooibos/FileFactory.js.map +1 -0
  31. package/dist/lib/rooibos/RawCodeStatement.js +21 -0
  32. package/dist/lib/rooibos/RawCodeStatement.js.map +1 -0
  33. package/dist/lib/rooibos/RooibosConfig.js +11 -0
  34. package/dist/lib/rooibos/RooibosConfig.js.map +1 -0
  35. package/dist/lib/rooibos/RooibosSession.js +151 -0
  36. package/dist/lib/rooibos/RooibosSession.js.map +1 -0
  37. package/dist/lib/rooibos/RooibosSessionInfo.js +181 -0
  38. package/dist/lib/rooibos/RooibosSessionInfo.js.map +1 -0
  39. package/dist/lib/rooibos/TestCase.js +65 -0
  40. package/dist/lib/rooibos/TestCase.js.map +1 -0
  41. package/dist/lib/rooibos/TestGroup.js +86 -0
  42. package/dist/lib/rooibos/TestGroup.js.map +1 -0
  43. package/dist/lib/rooibos/TestSuite.js +118 -0
  44. package/dist/lib/rooibos/TestSuite.js.map +1 -0
  45. package/dist/lib/rooibos/TestSuiteBuilder.js +192 -0
  46. package/dist/lib/rooibos/TestSuiteBuilder.js.map +1 -0
  47. package/dist/lib/rooibos/TestSuiteBuilder.spec.js +1126 -0
  48. package/dist/lib/rooibos/TestSuiteBuilder.spec.js.map +1 -0
  49. package/dist/lib/rooibos/Utils.js +173 -0
  50. package/dist/lib/rooibos/Utils.js.map +1 -0
  51. package/dist/lib/utils/Diagnostics.js +116 -0
  52. package/dist/lib/utils/Diagnostics.js.map +1 -0
  53. package/dist/lib/utils/testHelpers.spec.js +24 -0
  54. package/dist/lib/utils/testHelpers.spec.js.map +1 -0
  55. package/dist/plugin.js +116 -0
  56. package/dist/plugin.js.map +1 -0
  57. package/package.json +110 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 George Cook
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,12 @@
1
+ <p align="center">
2
+ <img src="https://github.com/georgejecook/rooibos/raw/master/images/logo.png" alt="Rooibos test framework" width="200" height="200"/>
3
+ </p>
4
+
5
+ [![build](https://img.shields.io/github/workflow/status/georgejecook/rooibos/build.svg?logo=github)](https://github.com/georgejecook/rooibos/actions?query=workflow%3Abuild)
6
+ [![GitHub](https://img.shields.io/github/release/georgejecook/rooibos.svg?style=flat-square)](https://github.com/georgejecook/rooibos/releases)
7
+ [![NPM Version](https://badge.fury.io/js/rooibos-roku.svg?style=flat)](https://npmjs.org/package/rooibos-roku)
8
+
9
+ ## Links
10
+ - **[Documentation](https://github.com/georgejecook/rooibos/blob/master/docs/index.md)**
11
+ - **[API Documentation](https://georgejecook.github.io/rooibos)**
12
+ - \#roku channel on the [roku developer's slack](https://join.slack.com/t/rokudevelopers/shared_invite/enQtMzgyODg0ODY0NDM5LTc2ZDdhZWI2MDBmYjcwYTk5MmE1MTYwMTA2NGVjZmJiNWM4ZWY2MjY1MDY0MmViNmQ1ZWRmMWUzYTVhNzJiY2M)
@@ -0,0 +1,27 @@
1
+ namespace rooibos
2
+ class BaseTestReporter
3
+
4
+ public testRunner = invalid
5
+ public config = invalid
6
+ public allStats = invalid
7
+
8
+ function new(testRunner)
9
+ m.testRunner = testRunner
10
+ m.config = testRunner.config
11
+ m.allStats = testRunner.stats
12
+ end function
13
+
14
+ function reportResults(allStats)
15
+ 'override me
16
+ end function
17
+
18
+ function testLogInfo(text)
19
+ 'override me
20
+ end function
21
+
22
+ function testLogError(text)
23
+ 'override me
24
+ end function
25
+
26
+ end class
27
+ end namespace
@@ -0,0 +1,2131 @@
1
+ namespace rooibos
2
+ ' /**
3
+ ' * @module TestSuite
4
+ ' * @description All brs files that include `'@TestSuite` annotations automatically extend the TestSuite.
5
+ ' * The base test suite contains all of the assertions, and utility methods required to writey our tests, as well as being responsible for tracking the state of the tests and groups.
6
+ ' */
7
+ class BaseTestSuite
8
+
9
+ 'test state
10
+ protected name = "BaseTestSuite" 'set the name to the name of your test
11
+ protected filePath = invalid
12
+ protected pkgPath = invalid
13
+ protected isValid = false
14
+ protected hasSoloTests = false
15
+ protected hasIgnoredTests = false
16
+ protected isSolo = false
17
+ protected isIgnored = false
18
+ protected noCatch = false
19
+ protected isNodeTest = false
20
+ protected nodeName = invalid
21
+ protected lineNumber = 1
22
+ protected groups = []
23
+ protected groupsData = []
24
+ protected stats = invalid
25
+ protected currentAssertLineNumber = -1
26
+ protected valid = false
27
+ protected hasFailures = false
28
+ protected hasSoloGroups = false
29
+ protected isFailingFast = false
30
+ protected stubs = invalid
31
+ protected mocks = invalid
32
+ protected __stubId = -1
33
+ protected __mockId = -1
34
+ protected __mockTargetId = -1
35
+
36
+ 'special values
37
+ protected invalidValue = "#ROIBOS#INVALID_VALUE" ' special value used in mock arguments
38
+ protected ignoreValue = "#ROIBOS#IGNORE_VALUE" ' special value used in mock arguments
39
+
40
+ 'built in any matchers
41
+ protected anyStringMatcher = { "matcher": Rooibos_Matcher_anyString }
42
+ protected anyBoolMatcher = { "matcher": Rooibos_Matcher_anyBool }
43
+ protected anyNumberMatcher = { "matcher": Rooibos_Matcher_anyNumber }
44
+ protected anyAAMatcher = { "matcher": Rooibos_Matcher_anyAA }
45
+ protected anyArrayMatcher = { "matcher": Rooibos_Matcher_anyArray }
46
+ protected anyNodeMatcher = { "matcher": Rooibos_Matcher_anyNode }
47
+ protected allowNonExistingMethodsOnMocks = true
48
+ protected isAutoAssertingMocks = true
49
+
50
+ protected currentResult = invalid
51
+
52
+ protected global = invalid
53
+ protected catchCrashes = false
54
+
55
+ '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
56
+ '++ base methods to override
57
+ '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
58
+ function new()
59
+ data = m.getTestSuitedata()
60
+ if data = invalid
61
+ ? "ERROR RETRIEVING TEST SUITE DATA!! this is a rooibos BUG - please report the suite that resulted in a corrupt test. Thanks"
62
+ else
63
+ m.name = data.name
64
+ m.filePath = data.filePath
65
+ m.pkgPath = data.pkgPath
66
+ m.valid = data.valid
67
+ m.hasFailures = data.hasFailures
68
+ m.hasSoloTests = data.hasSoloTests
69
+ m.hasIgnoredTests = data.hasIgnoredTests
70
+ m.hasSoloGroups = data.hasSoloGroups
71
+ m.isSolo = data.isSolo
72
+ m.isIgnored = data.isIgnored
73
+ m.noCatch = data.noCatch
74
+ m.groupsData = data.testGroups
75
+ m.lineNumber = data.lineNumber
76
+ m.isNodeTest = data.isNodeTest
77
+ m.nodeName = data.nodeName
78
+ m.isFailingFast = false
79
+ m.stats = new Stats()
80
+ end if
81
+ end function
82
+
83
+ function getTestSuiteData()
84
+ 'this will be injected by the plugin
85
+ end function
86
+
87
+ '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
88
+ '++ used for entire suite - use annotations to use elsewhere
89
+ '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
90
+
91
+ protected function setup()
92
+ end function
93
+
94
+ protected function tearDown()
95
+ end function
96
+
97
+ protected function beforeEach()
98
+ end function
99
+
100
+ protected function afterEach()
101
+ end function
102
+
103
+ '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
104
+ '++ running
105
+ '++++++++++++++++++++++++++++++++++++?+++++++++++++++++++++++++
106
+
107
+ function run()
108
+ for each groupData in m.groupsData
109
+ 'bs:disable-next-line
110
+
111
+ group = new TestGroup(m, groupData)
112
+ ? ""
113
+ ? rooibos.common.fillText(">>>> Describe: " + group.name, ">", 80)
114
+ ? ` Location: file://${group.testSuite.filePath.trim()}:${group.lineNumber}`
115
+ ? ""
116
+
117
+ m.groups.push(group)
118
+ group.run()
119
+
120
+ m.stats.merge(group.stats)
121
+
122
+ if m.stats.hasFailures and m.isFailingFast = true
123
+ ? "Terminating suite due to failed group"
124
+ exit for
125
+ end if
126
+
127
+ end for
128
+ end function
129
+
130
+ function runTest(test)
131
+ ? ""
132
+ ? rooibos.common.fillText(">>>>>> It: " + test.name, ">", 80)
133
+ ? ` Location: file://${test.testSuite.filePath.trim()}:${test.lineNumber}`
134
+ ? ""
135
+
136
+ m.currentResult = test.result
137
+ if m.catchCrashes and not test.noCatch and not m.noCatch
138
+ try
139
+ test.run()
140
+ if m.isAutoAssertingMocks = true
141
+ m.AssertMocks()
142
+ m.CleanMocks()
143
+ m.CleanStubs()
144
+ end if
145
+ catch error
146
+ m.currentResult.crash("test crashed!", error)
147
+ end try
148
+ else
149
+ test.run()
150
+ if m.isAutoAssertingMocks = true
151
+ m.AssertMocks()
152
+ m.CleanMocks()
153
+ m.CleanStubs()
154
+ end if
155
+ end if
156
+
157
+ ? rooibos.common.fillText("<<<< END It: " + test.name + " (" + m.currentResult.getStatusText() + ") ", "<", 80)
158
+
159
+ end function
160
+
161
+ '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
162
+ '++ Assertions
163
+ '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
164
+
165
+ ' /**
166
+ ' * @memberof module:BaseTestSuite
167
+ ' * @name fail
168
+ ' * @function
169
+ ' * @instance
170
+ ' * @description Fail immediately, with the given message
171
+ ' * @param {Dynamic} [msg=""] - message to display in the test report
172
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
173
+ ' */
174
+ function fail(msg = "Error") as dynamic
175
+ if m.currentResult.isFail then return false
176
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
177
+ return false
178
+ end function
179
+
180
+ ' /**
181
+ ' * @memberof module:BaseTestSuite
182
+ ' * @name assertFalse
183
+ ' * @function
184
+ ' * @instance
185
+ ' * @description Fail the test if the expression is true.
186
+ ' * @param {Dynamic} expr - An expression to evaluate.
187
+ ' * @param {Dynamic} [msg=""] - alternate error message
188
+ ' Default value: "Expression evaluates to true"' * @returns {boolean} - true if the assert was satisfied, false otherwise
189
+ ' */
190
+ function assertFalse(expr, msg = "Expression evaluates to true") as dynamic
191
+ if m.currentResult.isFail then return false
192
+ try
193
+ if Rooibos.Common.isBoolean(expr)
194
+ if expr
195
+ return m.fail(msg)
196
+ end if
197
+ else
198
+ return m.fail("value was not a boolean")
199
+ end if
200
+ return true
201
+ catch error
202
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
203
+ end try
204
+ end function
205
+
206
+ ' /**
207
+ ' * @memberof module:BaseTestSuite
208
+ ' * @name assertTrue
209
+ ' * @function
210
+ ' * @instance
211
+ ' * @description Fail the test unless the expression is true.
212
+ ' * @param {Dynamic} expr - An expression to evaluate.
213
+ ' * @param {Dynamic} [msg=""] - alternate error message
214
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
215
+ ' */
216
+ function assertTrue(expr, msg = "Expression evaluates to false")
217
+ if m.currentResult.isFail then return false
218
+ try
219
+ if Rooibos.Common.isBoolean(expr)
220
+ if not expr
221
+ return m.fail(msg)
222
+ end if
223
+ else
224
+ return m.fail("value was not a boolean")
225
+ end if
226
+
227
+ return true
228
+ catch error
229
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
230
+ end try
231
+ end function
232
+
233
+ ' /**
234
+ ' * @memberof module:BaseTestSuite
235
+ ' * @name assertEqual
236
+ ' * @function
237
+ ' * @instance
238
+ ' * @description Fail if the two objects are unequal as determined by the '<>' operator.
239
+ ' * @param {Dynamic} first - first object to compare
240
+ ' * @param {Dynamic} second - second object to compare
241
+ ' * @param {Dynamic} [msg=""] - alternate error message
242
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
243
+ ' */
244
+ function assertEqual(first, second, msg = "") as dynamic
245
+ if m.currentResult.isFail then return false
246
+ try
247
+ if not Rooibos.Common.eqValues(first, second)
248
+ if msg = ""
249
+ first_as_string = Rooibos.Common.asString(first)
250
+ second_as_string = Rooibos.Common.asString(second)
251
+ msg = first_as_string + " != " + second_as_string
252
+ end if
253
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
254
+ return false
255
+ end if
256
+ return true
257
+ catch error
258
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
259
+ end try
260
+
261
+ end function
262
+
263
+ ' /**
264
+ ' * @memberof module:BaseTestSuite
265
+ ' * @name assertLike
266
+ ' * @function
267
+ ' * @instance
268
+ ' * @description does a fuzzy comparison
269
+ ' * @param {Dynamic} first - first object to compare
270
+ ' * @param {Dynamic} second - second object to compare
271
+ ' * @param {Dynamic} [msg=""] - alternate error message
272
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
273
+ ' */
274
+ function assertLike(first, second, msg = "") as dynamic
275
+ if m.currentResult.isFail then return false
276
+ try
277
+ if first <> second
278
+ if msg = ""
279
+ first_as_string = Rooibos.Common.asString(first)
280
+ second_as_string = Rooibos.Common.asString(second)
281
+ msg = first_as_string + " != " + second_as_string
282
+ end if
283
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
284
+ return false
285
+ end if
286
+ return true
287
+ catch error
288
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
289
+ end try
290
+
291
+ end function
292
+
293
+ ' /**
294
+ ' * @memberof module:BaseTestSuite
295
+ ' * @name assertNotEqual
296
+ ' * @function
297
+ ' * @instance
298
+ ' * @description Fail if the two objects are equal as determined by the '=' operator.
299
+ ' * @param {Dynamic} first - first object to compare
300
+ ' * @param {Dynamic} second - second object to compare
301
+ ' * @param {Dynamic} [msg=""] - alternate error message
302
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
303
+ ' */
304
+ function assertNotEqual(first, second, msg = "") as dynamic
305
+ if m.currentResult.isFail then return false
306
+ try
307
+ if Rooibos.Common.eqValues(first, second)
308
+ if msg = ""
309
+ first_as_string = Rooibos.Common.asString(first)
310
+ second_as_string = Rooibos.Common.asString(second)
311
+ msg = first_as_string + " == " + second_as_string
312
+ end if
313
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
314
+ return false
315
+ end if
316
+ return true
317
+ catch error
318
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
319
+ end try
320
+
321
+ end function
322
+
323
+ ' /**
324
+ ' * @memberof module:BaseTestSuite
325
+ ' * @name assertInvalid
326
+ ' * @function
327
+ ' * @instance
328
+ ' * @description Fail if the value is not invalid.
329
+ ' * @param {Dynamic} value - value to check - value to check for
330
+ ' * @param {Dynamic} [msg=""] - alternate error message
331
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
332
+ ' */
333
+ function assertInvalid(value, msg = "") as dynamic
334
+ if m.currentResult.isFail then return false
335
+
336
+ try
337
+ if value <> invalid
338
+ if msg = ""
339
+ expr_as_string = Rooibos.Common.asString(value)
340
+ msg = expr_as_string + " <> Invalid"
341
+ end if
342
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
343
+ return false
344
+ end if
345
+ return true
346
+ catch error
347
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
348
+ end try
349
+
350
+ end function
351
+
352
+ ' /**
353
+ ' * @memberof module:BaseTestSuite
354
+ ' * @name assertNotInvalid
355
+ ' * @function
356
+ ' * @instance
357
+ ' * @description Fail if the value is invalid.
358
+ ' * @param {Dynamic} value - value to check - value to check for
359
+ ' * @param {Dynamic} [msg=""] - alternate error message
360
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
361
+ ' */
362
+ function assertNotInvalid(value, msg = "") as dynamic
363
+ if m.currentResult.isFail then return false
364
+ try
365
+ if value = invalid
366
+ if msg = ""
367
+ expr_as_string = Rooibos.Common.asString(value)
368
+ msg = expr_as_string + " = Invalid"
369
+ end if
370
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
371
+ return false
372
+ end if
373
+ return true
374
+ catch error
375
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
376
+ end try
377
+
378
+ end function
379
+
380
+ ' /**
381
+ ' * @memberof module:BaseTestSuite
382
+ ' * @name assertAAHasKey
383
+ ' * @function
384
+ ' * @instance
385
+ ' * @description Fail if the array doesn't have the key.
386
+ ' * @param {Dynamic} array - target array
387
+ ' * @param {Dynamic} key - key name
388
+ ' * @param {Dynamic} [msg=""] - alternate error message
389
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
390
+ ' */
391
+ function assertAAHasKey(array, key, msg = "") as dynamic
392
+ if m.currentResult.isFail then return false
393
+ try
394
+ if Rooibos.Common.isAssociativeArray(array)
395
+ if not array.DoesExist(key)
396
+ if msg = ""
397
+ msg = "Array doesn't have the '" + key + "' key."
398
+ end if
399
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
400
+ return false
401
+ end if
402
+ else
403
+ msg = "Input value is not an Associative Array."
404
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
405
+ return false
406
+ end if
407
+ return true
408
+ catch error
409
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
410
+ end try
411
+
412
+ end function
413
+
414
+ ' /**
415
+ ' * @memberof module:BaseTestSuite
416
+ ' * @name assertAANotHasKey
417
+ ' * @function
418
+ ' * @instance
419
+ ' * @description Fail if the array has the key.
420
+ ' * @param {Dynamic} array - target array
421
+ ' * @param {Dynamic} key - key name
422
+ ' * @param {Dynamic} [msg=""] - alternate error message
423
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
424
+ ' */
425
+ function assertAANotHasKey(array, key, msg = "") as dynamic
426
+ if m.currentResult.isFail then return false
427
+
428
+ try
429
+ if Rooibos.Common.isAssociativeArray(array)
430
+ if array.DoesExist(key)
431
+ if msg = ""
432
+ msg = "Array has the '" + key + "' key."
433
+ end if
434
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
435
+ return false
436
+ end if
437
+ else
438
+ msg = "Input value is not an Associative Array."
439
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
440
+ return false
441
+ end if
442
+ return true
443
+ catch error
444
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
445
+ end try
446
+
447
+ end function
448
+
449
+ ' /**
450
+ ' * @memberof module:BaseTestSuite
451
+ ' * @name assertAAHasKeys
452
+ ' * @function
453
+ ' * @instance
454
+ ' * @description Fail if the array doesn't have the keys list.
455
+ ' * @param {Dynamic} array - A target associative array.
456
+ ' * @param {Dynamic} keys - Array of key names.
457
+ ' * @param {Dynamic} [msg=""] - alternate error message
458
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
459
+ ' */
460
+ function assertAAHasKeys(array, keys, msg = "") as dynamic
461
+ if m.currentResult.isFail then return false
462
+
463
+ try
464
+ if Rooibos.Common.isAssociativeArray(array) and Rooibos.Common.isArray(keys)
465
+ for each key in keys
466
+ if not array.DoesExist(key)
467
+ if msg = ""
468
+ msg = "Array doesn't have the '" + key + "' key."
469
+ end if
470
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
471
+ return false
472
+ end if
473
+ end for
474
+ else
475
+ msg = "Input value is not an Associative Array."
476
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
477
+ return false
478
+ end if
479
+ return true
480
+ catch error
481
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
482
+ end try
483
+
484
+ end function
485
+
486
+ ' /**
487
+ ' * @memberof module:BaseTestSuite
488
+ ' * @name assertAANotHasKeys
489
+ ' * @function
490
+ ' * @instance
491
+ ' * @description Fail if the array has the keys list.
492
+ ' * @param {Dynamic} array - A target associative array.
493
+ ' * @param {Dynamic} keys - Array of key names.
494
+ ' * @param {Dynamic} [msg=""] - alternate error message
495
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
496
+ ' */
497
+ function assertAANotHasKeys(array, keys, msg = "") as dynamic
498
+ if m.currentResult.isFail then return false
499
+ try
500
+ if Rooibos.Common.isAssociativeArray(array) and Rooibos.Common.isArray(keys)
501
+ for each key in keys
502
+ if array.DoesExist(key)
503
+ if msg = ""
504
+ msg = "Array has the '" + key + "' key."
505
+ end if
506
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
507
+ return false
508
+ end if
509
+ end for
510
+ else
511
+ msg = "Input value is not an Associative Array."
512
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
513
+ return false
514
+ end if
515
+ return true
516
+ catch error
517
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
518
+ end try
519
+
520
+ end function
521
+
522
+
523
+
524
+ ' /**
525
+ ' * @memberof module:BaseTestSuite
526
+ ' * @name assertArrayContains
527
+ ' * @function
528
+ ' * @instance
529
+ ' * @description Fail if the array doesn't have the item.
530
+ ' * @param {Dynamic} array - target array
531
+ ' * @param {Dynamic} value - value to check - value to check for
532
+ ' * @param {Dynamic} key - key name in associative array
533
+ ' * @param {Dynamic} [msg=""] - alternate error message
534
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
535
+ ' */
536
+ function assertArrayContains(array, value, key = invalid, msg = "") as dynamic
537
+ if m.currentResult.isFail then return false
538
+ try
539
+ if Rooibos.Common.isAssociativeArray(array) or Rooibos.Common.isArray(array)
540
+ if not Rooibos.Common.arrayContains(array, value, key)
541
+ msg = "Array doesn't have the '" + Rooibos.Common.asString(value) + "' value."
542
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
543
+ return false
544
+ end if
545
+ else
546
+ msg = "Input value is not an Array."
547
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
548
+ return false
549
+ end if
550
+ return true
551
+ catch error
552
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
553
+ end try
554
+
555
+ end function
556
+
557
+ ' /**
558
+ ' * @memberof module:BaseTestSuite
559
+ ' * @name assertArrayContainsAAs
560
+ ' * @function
561
+ ' * @instance
562
+ ' * @description Fail if the array does not contain all of the aa's in the values array.
563
+ ' * @param {Dynamic} array - target array
564
+ ' * @param {Dynamic} values - array of aas to look for in target array
565
+ ' * @param {Dynamic} [msg=""] - alternate error message
566
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
567
+ ' */
568
+ function assertArrayContainsAAs(array, values, msg = "") as dynamic
569
+ if m.currentResult.isFail then return false
570
+ try
571
+ if not Rooibos.Common.isArray(values)
572
+ msg = "values to search for are not an Array."
573
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
574
+ return false
575
+ end if
576
+
577
+ if Rooibos.Common.isArray(array)
578
+ for each value in values
579
+ isMatched = false
580
+ if not Rooibos.Common.isAssociativeArray(value)
581
+ msg = "Value to search for was not associativeArray " + Rooibos.Common.asString(value)
582
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
583
+ return false
584
+ end if
585
+ for each item in array
586
+ if Rooibos.Common.IsAssociativeArray(item)
587
+ isValueMatched = true
588
+ for each key in value
589
+ fieldValue = value[key]
590
+ itemValue = item[key]
591
+ if not Rooibos.Common.eqValues(fieldValue, itemValue)
592
+ isValueMatched = false
593
+ exit for
594
+ end if
595
+ end for
596
+ if isValueMatched
597
+ isMatched = true
598
+ exit for
599
+ end if
600
+ end if
601
+ end for ' items in array
602
+
603
+ if not isMatched
604
+ msg = "array missing value: " + Rooibos.Common.asString(value)
605
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
606
+ return false
607
+ end if
608
+
609
+ end for 'values to match
610
+ else
611
+ msg = "Input value is not an Array."
612
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
613
+ return false
614
+ end if
615
+ return true
616
+ catch error
617
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
618
+ end try
619
+
620
+ end function
621
+
622
+ ' /**
623
+ ' * @memberof module:BaseTestSuite
624
+ ' * @name assertArrayNotContains
625
+ ' * @function
626
+ ' * @instance
627
+ ' * @description Fail if the array has the item.
628
+ ' * @param {Dynamic} array - target array
629
+ ' * @param {Dynamic} array - target array
630
+ ' * @param {Dynamic} value - value to check - Value to check for
631
+ ' * @param {Dynamic} key - A key name for associative array.
632
+ ' * @param {Dynamic} [msg=""] - alternate error message
633
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
634
+ ' */
635
+ function assertArrayNotContains(array, value, key = invalid, msg = "") as dynamic
636
+ if m.currentResult.isFail then return false
637
+ try
638
+ if Rooibos.Common.isAssociativeArray(array) or Rooibos.Common.isArray(array)
639
+ if Rooibos.Common.arrayContains(array, value, key)
640
+ msg = "Array has the '" + Rooibos.Common.asString(value) + "' value."
641
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
642
+ return false
643
+ end if
644
+ else
645
+ msg = "Input value is not an Array."
646
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
647
+ return false
648
+ end if
649
+ return true
650
+ catch error
651
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
652
+ end try
653
+
654
+ end function
655
+
656
+ ' /**
657
+ ' * @memberof module:BaseTestSuite
658
+ ' * @name assertArrayContainsSubset
659
+ ' * @function
660
+ ' * @instance
661
+ ' * @description Fail if the array doesn't have the item subset.
662
+ ' * @param {Dynamic} array - target array
663
+ ' * @param {Dynamic} subset - items to check presnece of
664
+ ' * @param {Dynamic} [msg=""] - alternate error message
665
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
666
+ ' */
667
+ function assertArrayContainsSubset(array, subset, msg = "") as dynamic
668
+ if m.currentResult.isFail then return false
669
+ try
670
+ if (Rooibos.Common.isAssociativeArray(array) and Rooibos.Common.isAssociativeArray(subset)) or (Rooibos.Common.isArray(array) and Rooibos.Common.isArray(subset))
671
+ isAA = Rooibos.Common.isAssociativeArray(subset)
672
+ for each item in subset
673
+ key = invalid
674
+ value = item
675
+ if isAA
676
+ key = item
677
+ value = subset[key]
678
+ end if
679
+ if not Rooibos.Common.arrayContains(array, value, key)
680
+ msg = "Array doesn't have the '" + Rooibos.Common.asString(value) + "' value."
681
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
682
+ return false
683
+ end if
684
+ end for
685
+ else
686
+ msg = "Input value is not an Array."
687
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
688
+ return false
689
+ end if
690
+ return true
691
+ catch error
692
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
693
+ end try
694
+
695
+ end function
696
+
697
+ ' /**
698
+ ' * @memberof module:BaseTestSuite
699
+ ' * @name assertArrayNotContainsSubset
700
+ ' * @function
701
+ ' * @instance
702
+ ' * @description Fail if the array have the item from subset.
703
+ ' * @param {Dynamic} array - target array
704
+ ' * @param {Dynamic} subset - items to check presnece of
705
+ ' * @param {Dynamic} [msg=""] - alternate error message
706
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
707
+ ' */
708
+ function assertArrayNotContainsSubset(array, subset, msg = "") as dynamic
709
+ if m.currentResult.isFail then return false
710
+ try
711
+ if (Rooibos.Common.isAssociativeArray(array) and Rooibos.Common.isAssociativeArray(subset)) or (Rooibos.Common.isArray(array) and Rooibos.Common.isArray(subset))
712
+ isAA = Rooibos.Common.isAssociativeArray(subset)
713
+ for each item in subset
714
+ key = invalid
715
+ value = item
716
+ if isAA
717
+ key = item
718
+ value = item[key]
719
+ end if
720
+ if Rooibos.Common.arrayContains(array, value, key)
721
+ msg = "Array has the '" + Rooibos.Common.asString(value) + "' value."
722
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
723
+ return false
724
+ end if
725
+ end for
726
+ else
727
+ msg = "Input value is not an Array."
728
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
729
+ return false
730
+ end if
731
+ return true
732
+ catch error
733
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
734
+ end try
735
+
736
+ end function
737
+
738
+ ' /**
739
+ ' * @memberof module:BaseTestSuite
740
+ ' * @name assertArrayCount
741
+ ' * @function
742
+ ' * @instance
743
+ ' * @description Fail if the array items count <> expected count
744
+ ' * @param {Dynamic} array - target array
745
+ ' * @param {Dynamic} count - An expected array items count
746
+ ' * @param {Dynamic} [msg=""] - alternate error message
747
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
748
+ ' */
749
+ function assertArrayCount(array, count, msg = "") as dynamic
750
+ if m.currentResult.isFail then return false
751
+ try
752
+ if Rooibos.Common.isAssociativeArray(array) or Rooibos.Common.isArray(array)
753
+ if array.Count() <> count
754
+ msg = "Array items count " + Rooibos.Common.asString(array.Count()) + " <> " + Rooibos.Common.asString(count) + "."
755
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
756
+ return false
757
+ end if
758
+ else
759
+ msg = "Input value is not an Array."
760
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
761
+ return false
762
+ end if
763
+ return true
764
+ catch error
765
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
766
+ end try
767
+
768
+ end function
769
+
770
+ ' /**
771
+ ' * @memberof module:BaseTestSuite
772
+ ' * @name assertArrayNotCount
773
+ ' * @function
774
+ ' * @instance
775
+ ' * @description Fail if the array items count = expected count.
776
+ ' * @param {Dynamic} array - target array
777
+ ' * @param {Dynamic} count - An expected array items count.
778
+ ' * @param {Dynamic} [msg=""] - alternate error message
779
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
780
+ ' */
781
+ function assertArrayNotCount(array, count, msg = "") as dynamic
782
+ if m.currentResult.isFail then return false
783
+ try
784
+ if Rooibos.Common.isAssociativeArray(array) or Rooibos.Common.isArray(array)
785
+ if array.Count() = count
786
+ msg = "Array items count = " + Rooibos.Common.asString(count) + "."
787
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
788
+ return false
789
+ end if
790
+ else
791
+ msg = "Input value is not an Array."
792
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
793
+ return false
794
+ end if
795
+ return true
796
+ catch error
797
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
798
+ end try
799
+
800
+ end function
801
+
802
+ ' /**
803
+ ' * @memberof module:BaseTestSuite
804
+ ' * @name assertEmpty
805
+ ' * @function
806
+ ' * @instance
807
+ ' * @description Fail if the item is not empty array or string.
808
+ ' * @param {Dynamic} item - item to check
809
+ ' * @param {Dynamic} [msg=""] - alternate error message
810
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
811
+ ' */
812
+ function assertEmpty(item, msg = "") as dynamic
813
+ if m.currentResult.isFail then return false
814
+ try
815
+ if Rooibos.Common.isAssociativeArray(item) or Rooibos.Common.isArray(item)
816
+ if item.count() > 0
817
+ msg = "Array is not empty."
818
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
819
+ return false
820
+ end if
821
+ else if Rooibos.Common.isString(item)
822
+ if Rooibos.Common.asString(item) <> ""
823
+ msg = "Input value is not empty."
824
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
825
+ return false
826
+ end if
827
+ else
828
+ msg = "AssertEmpty: Input value was not an array or a string"
829
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
830
+ return false
831
+ end if
832
+ return true
833
+ catch error
834
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
835
+ end try
836
+
837
+ end function
838
+
839
+ ' /**
840
+ ' * @memberof module:BaseTestSuite
841
+ ' * @name assertNotEmpty
842
+ ' * @function
843
+ ' * @instance
844
+ ' * @description Fail if the item is empty array or string.
845
+ ' * @param {Dynamic} item - item to check
846
+ ' * @param {Dynamic} [msg=""] - alternate error message
847
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
848
+ ' */
849
+ function assertNotEmpty(item, msg = "") as dynamic
850
+ if m.currentResult.isFail then return false
851
+ try
852
+ if Rooibos.Common.isAssociativeArray(item) or Rooibos.Common.isArray(item)
853
+ if item.count() = 0
854
+ msg = "Array is empty."
855
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
856
+ return false
857
+ end if
858
+ else if Rooibos.Common.isString(item)
859
+ if item = ""
860
+ msg = "Input value is empty."
861
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
862
+ return false
863
+ end if
864
+ else
865
+ msg = "Input value is not a string or array."
866
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
867
+ return false
868
+ end if
869
+ return true
870
+ catch error
871
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
872
+ end try
873
+
874
+ end function
875
+
876
+ ' /**
877
+ ' * @memberof module:BaseTestSuite
878
+ ' * @name assertArrayContainsOnlyValuesOfType
879
+ ' * @function
880
+ ' * @instance
881
+ ' * @description Fail if the array doesn't contains items of specific type only.
882
+ ' * @param {Dynamic} array - target array
883
+ ' * @param {Dynamic} typeStr - type name - must be String, Array, Boolean, or AssociativeArray
884
+ ' * @param {Dynamic} [msg=""] - alternate error message
885
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
886
+ ' */
887
+ function assertArrayContainsOnlyValuesOfType(array, typeStr, msg = "") as dynamic
888
+ if m.currentResult.isFail then return false
889
+ try
890
+
891
+ if typeStr <> "String" and typeStr <> "Integer" and typeStr <> "Boolean" and typeStr <> "Array" and typeStr <> "AssociativeArray"
892
+ msg = "Type must be Boolean, String, Array, Integer, or AssociativeArray"
893
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
894
+ return false
895
+ end if
896
+
897
+ if Rooibos.Common.isAssociativeArray(array) or Rooibos.Common.isArray(array)
898
+ methodName = "Rooibos_Common_Is" + typeStr
899
+ typeCheckFunction = m.getIsTypeFunction(methodName)
900
+ if typeCheckFunction <> invalid
901
+ for each item in array
902
+ if not typeCheckFunction(item)
903
+ msg = Rooibos.Common.asString(item) + "is not a '" + typeStr + "' type."
904
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
905
+ return false
906
+ end if
907
+ end for
908
+ else
909
+ msg = "could not find comparator for type '" + typeStr + "' type."
910
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
911
+ return false
912
+ end if
913
+ else
914
+ msg = "Input value is not an Array."
915
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
916
+ return false
917
+ end if
918
+ return true
919
+ catch error
920
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
921
+ end try
922
+
923
+ end function
924
+
925
+ function getIsTypeFunction(name)
926
+ if name = "Rooibos_Common_IsFunction"
927
+ return Rooibos.Common.isFunction
928
+ else if name = "Rooibos_Common_IsXmlElement"
929
+ return Rooibos.Common.isXmlElement
930
+ else if name = "Rooibos_Common_IsInteger"
931
+ return Rooibos.Common.isInteger
932
+ else if name = "Rooibos_Common_IsBoolean"
933
+ return Rooibos.Common.isBoolean
934
+ else if name = "Rooibos_Common_IsFloat"
935
+ return Rooibos.Common.isFloat
936
+ else if name = "Rooibos_Common_IsDouble"
937
+ return Rooibos.Common.isDouble
938
+ else if name = "Rooibos_Common_IsLongInteger"
939
+ return Rooibos.Common.isLongInteger
940
+ else if name = "Rooibos_Common_IsNumber"
941
+ return Rooibos.Common.isNumber
942
+ else if name = "Rooibos_Common_IsList"
943
+ return Rooibos.Common.isList
944
+ else if name = "Rooibos_Common_IsArray"
945
+ return Rooibos.Common.isArray
946
+ else if name = "Rooibos_Common_IsAssociativeArray"
947
+ return Rooibos.Common.isAssociativeArray
948
+ else if name = "Rooibos_Common_IsSGNode"
949
+ return Rooibos.Common.isSGNode
950
+ else if name = "Rooibos_Common_IsString"
951
+ return Rooibos.Common.isString
952
+ else if name = "Rooibos_Common_IsDateTime"
953
+ return Rooibos.Common.isDateTime
954
+ else if name = "Rooibos_Common_IsUndefined"
955
+ return Rooibos.Common.isUndefined
956
+ else
957
+ return invalid
958
+ end if
959
+ end function
960
+
961
+ ' /**
962
+ ' * @memberof module:BaseTestSuite
963
+ ' * @name assertType
964
+ ' * @function
965
+ ' * @instance
966
+ ' * @description Asserts that the value is a node of designated type
967
+ ' * @param {Dynamic} value - value to check - target node
968
+ ' * @param {Dynamic} typeStr - type name
969
+ ' * @param {Dynamic} [msg=""] - alternate error message
970
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
971
+ ' */
972
+ function assertType(value, typeStr, msg = "") as dynamic
973
+ if m.currentResult.isFail then return false
974
+ try
975
+ if type(value) <> typeStr
976
+ if msg = ""
977
+ expr_as_string = Rooibos.Common.asString(value)
978
+ msg = expr_as_string + " was not expected type " + typeStr
979
+ end if
980
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
981
+ return false
982
+ end if
983
+ return true
984
+ catch error
985
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
986
+ end try
987
+
988
+ end function
989
+
990
+ ' /**
991
+ ' * @memberof module:BaseTestSuite
992
+ ' * @name assertSubType
993
+ ' * @function
994
+ ' * @instance
995
+ ' * @description Asserts that the value is a node of designated subtype
996
+ ' * @param {Dynamic} value - value to check - target node
997
+ ' * @param {Dynamic} typeStr - type name
998
+ ' * @param {Dynamic} [msg=""] - alternate error message
999
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
1000
+ ' */
1001
+ function assertSubType(value, typeStr, msg = "") as dynamic
1002
+ if m.currentResult.isFail then return false
1003
+ try
1004
+ if type(value) <> "roSGNode"
1005
+ if msg = ""
1006
+ expr_as_string = Rooibos.Common.asString(value)
1007
+ msg = expr_as_string + " was not a node, so could not match subtype " + typeStr
1008
+ end if
1009
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
1010
+ return false
1011
+ else if value.subType() <> typeStr
1012
+ if msg = ""
1013
+ expr_as_string = Rooibos.Common.asString(value)
1014
+ msg = expr_as_string + "( type : " + value.subType() + ") was not of subType " + typeStr
1015
+ end if
1016
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
1017
+ return false
1018
+ end if
1019
+ return true
1020
+ catch error
1021
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
1022
+ end try
1023
+
1024
+ end function
1025
+
1026
+ function assertClass(value, typeStr, msg = "") as dynamic
1027
+ if m.currentResult.isFail then return false
1028
+ try
1029
+ if not Rooibos.Common.isAssociativeArray(value)
1030
+ if msg = ""
1031
+ expr_as_string = Rooibos.Common.asString(value)
1032
+ msg = expr_as_string + " was not an aa, so could not match Class " + typeStr
1033
+ end if
1034
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
1035
+ return false
1036
+ end if
1037
+ className = Rooibos.Common.asString(value.__classname)
1038
+ if className <> typeStr
1039
+ if msg = ""
1040
+ msg = "Expected class: " + typeStr + ", got " + classNAme
1041
+ end if
1042
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
1043
+ return false
1044
+ end if
1045
+ return true
1046
+ catch error
1047
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
1048
+ end try
1049
+
1050
+ end function
1051
+
1052
+
1053
+ '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1054
+ '++ NEW NODE ASSERTS
1055
+ '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1056
+
1057
+ ' /**
1058
+ ' * @memberof module:BaseTestSuite
1059
+ ' * @name assertNodeCount
1060
+ ' * @function
1061
+ ' * @instance
1062
+ ' * @description Asserts that the node contains the desginated number of children
1063
+ ' * @param {Dynamic} node - target node
1064
+ ' * @param {Dynamic} count - expected number of child items
1065
+ ' * @param {Dynamic} [msg=""] - alternate error message
1066
+ ' * @returns {boolean} - true if the assert w, false otherwise
1067
+ ' */
1068
+ function assertNodeCount(node, count, msg = "") as dynamic
1069
+ if m.currentResult.isFail then return false
1070
+ try
1071
+ if type(node) = "roSGNode"
1072
+ if node.getChildCount() <> count
1073
+ msg = "node items count <> " + Rooibos.Common.asString(count) + ". Received " + Rooibos.Common.asString(node.getChildCount())
1074
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
1075
+ return false
1076
+ end if
1077
+ else
1078
+ msg = "Input value is not an node."
1079
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
1080
+ return false
1081
+ end if
1082
+ return true
1083
+ catch error
1084
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
1085
+ end try
1086
+
1087
+ end function
1088
+
1089
+ ' /**
1090
+ ' * @memberof module:BaseTestSuite
1091
+ ' * @name assertNodeNotCount
1092
+ ' * @function
1093
+ ' * @instance
1094
+ ' * @description Fail if the node items count = expected count.
1095
+ ' * @param {Dynamic} node - A target node
1096
+ ' * @param {Dynamic} count - Expected item count
1097
+ ' * @param {Dynamic} [msg=""] - alternate error message
1098
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
1099
+ ' */
1100
+ function assertNodeNotCount(node, count, msg = "") as dynamic
1101
+ if m.currentResult.isFail then return false
1102
+ try
1103
+ if type(node) = "roSGNode"
1104
+ if node.getChildCount() = count
1105
+ msg = "node items count = " + Rooibos.Common.asString(count) + "."
1106
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
1107
+ return false
1108
+ end if
1109
+ else
1110
+ msg = "Input value is not an node."
1111
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
1112
+ return false
1113
+ end if
1114
+ return true
1115
+ catch error
1116
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
1117
+ end try
1118
+
1119
+ end function
1120
+
1121
+ ' /**
1122
+ ' * @memberof module:BaseTestSuite
1123
+ ' * @name assertNodeEmpty
1124
+ ' * @function
1125
+ ' * @instance
1126
+ ' * @description Asserts the node has no children
1127
+ ' * @param {Dynamic} node - a node to check
1128
+ ' * @param {Dynamic} [msg=""] - alternate error message
1129
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
1130
+ ' */
1131
+ function assertNodeEmpty(node, msg = "") as dynamic
1132
+ if m.currentResult.isFail then return false
1133
+ try
1134
+ if type(node) = "roSGNode"
1135
+ if node.getChildCount() > 0
1136
+ msg = "node is not empty."
1137
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
1138
+ return false
1139
+ end if
1140
+ end if
1141
+ return true
1142
+ catch error
1143
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
1144
+ end try
1145
+
1146
+ end function
1147
+
1148
+ ' /**
1149
+ ' * @memberof module:BaseTestSuite
1150
+ ' * @name assertNodeNotEmpty
1151
+ ' * @function
1152
+ ' * @instance
1153
+ ' * @description Asserts the node has children
1154
+ ' * @param {Dynamic} node - a node to check
1155
+ ' * @param {Dynamic} [msg=""] - alternate error message
1156
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
1157
+ ' */
1158
+ function assertNodeNotEmpty(node, msg = "") as dynamic
1159
+ if m.currentResult.isFail then return false
1160
+ try
1161
+ if type(node) = "roSGNode"
1162
+ if node.Count() = 0
1163
+ msg = "Array is empty."
1164
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
1165
+ return false
1166
+ end if
1167
+ end if
1168
+ return true
1169
+ catch error
1170
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
1171
+ end try
1172
+
1173
+ end function
1174
+
1175
+ ' /**
1176
+ ' * @memberof module:BaseTestSuite
1177
+ ' * @name assertNodeContains
1178
+ ' * @function
1179
+ ' * @instance
1180
+ ' * @description Asserts the node contains the child _value_
1181
+ ' * @param {Dynamic} node - a node to check
1182
+ ' * @param {Dynamic} value - value to check - value to look for
1183
+ ' * @param {Dynamic} [msg=""] - alternate error message
1184
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
1185
+ ' */
1186
+ function assertNodeContains(node, value, msg = "") as dynamic
1187
+ if m.currentResult.isFail then return false
1188
+ try
1189
+ if type(node) = "roSGNode"
1190
+ if not Rooibos.Common.nodeContains(node, value)
1191
+ msg = "Node doesn't have the '" + Rooibos.Common.asString(value) + "' value."
1192
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
1193
+ return false
1194
+ end if
1195
+ else
1196
+ msg = "Input value is not an Node."
1197
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
1198
+ return false
1199
+ end if
1200
+ return true
1201
+ catch error
1202
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
1203
+ end try
1204
+
1205
+ end function
1206
+
1207
+ ' /**
1208
+ ' * @memberof module:BaseTestSuite
1209
+ ' * @name assertNodeContainsOnly
1210
+ ' * @function
1211
+ ' * @instance
1212
+ ' * @description Asserts the node contains only the child _value_
1213
+ ' * @param {Dynamic} node - a node to check
1214
+ ' * @param {Dynamic} value - value to check - value to look for
1215
+ ' * @param {Dynamic} [msg=""] - alternate error message
1216
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
1217
+ ' */
1218
+ function assertNodeContainsOnly(node, value, msg = "") as dynamic
1219
+ if m.currentResult.isFail then return false
1220
+ try
1221
+ if type(node) = "roSGNode"
1222
+ if not Rooibos.Common.nodeContains(node, value)
1223
+ msg = "Node doesn't have the '" + Rooibos.Common.asString(value) + "' value."
1224
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
1225
+ return false
1226
+ else if node.getChildCount() <> 1
1227
+ msg = "Node Contains speicified value; but other values as well"
1228
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
1229
+ return false
1230
+ end if
1231
+ else
1232
+ msg = "Input value is not an Node."
1233
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
1234
+ return false
1235
+ end if
1236
+ return true
1237
+ catch error
1238
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
1239
+ end try
1240
+
1241
+ end function
1242
+
1243
+
1244
+ ' /**
1245
+ ' * @memberof module:BaseTestSuite
1246
+ ' * @name assertNodeNotContains
1247
+ ' * @function
1248
+ ' * @instance
1249
+ ' * @description Fail if the node h item.
1250
+ ' * @param {Dynamic} node - A target node
1251
+ ' * @param {Dynamic} value - value to check - a node child
1252
+ ' * @param {Dynamic} [msg=""] - alternate error message
1253
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
1254
+ ' */
1255
+ function assertNodeNotContains(node, value, msg = "") as dynamic
1256
+ if m.currentResult.isFail then return false
1257
+ try
1258
+ if type(node) = "roSGNode"
1259
+ if Rooibos.Common.nodeContains(node, value)
1260
+ msg = "Node has the '" + Rooibos.Common.asString(value) + "' value."
1261
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
1262
+ return false
1263
+ end if
1264
+ else
1265
+ msg = "Input value is not an Node."
1266
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
1267
+ return false
1268
+ end if
1269
+ return true
1270
+ catch error
1271
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
1272
+ end try
1273
+
1274
+ end function
1275
+
1276
+ ' /**
1277
+ ' * @memberof module:BaseTestSuite
1278
+ ' * @name assertNodeContainsFields
1279
+ ' * @function
1280
+ ' * @instance
1281
+ ' * @description Fail if the node doesn't have the item subset.
1282
+ ' * @param {Dynamic} node - A target node
1283
+ ' * @param {Dynamic} subset - items to check
1284
+ ' * @param {Dynamic} [msg=""] - alternate error message
1285
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
1286
+ ' */
1287
+ function assertNodeContainsFields(node, subset, ignoredFields = invalid, msg = "") as dynamic
1288
+ if m.currentResult.isFail then return false
1289
+ try
1290
+ if (type(node) = "roSGNode" and Rooibos.Common.isAssociativeArray(subset)) or (type(node) = "roSGNode" and Rooibos.Common.isArray(subset))
1291
+ isAA = Rooibos.Common.isAssociativeArray(subset)
1292
+ isIgnoredFields = Rooibos.Common.isArray(ignoredFields)
1293
+ for each key in subset
1294
+ if key <> ""
1295
+ if not isIgnoredFields or not Rooibos.Common.arrayContains(ignoredFields, key)
1296
+ subsetValue = subset[key]
1297
+ nodeValue = node[key]
1298
+ if not Rooibos.Common.eqValues(nodeValue, subsetValue)
1299
+ msg = key + ": Expected '" + Rooibos.Common.asString(subsetValue) + "', got '" + Rooibos.Common.asString(nodeValue) + "'"
1300
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
1301
+ return false
1302
+ end if
1303
+ end if
1304
+ else
1305
+ ? "Found empty key!"
1306
+ end if
1307
+ end for
1308
+ else
1309
+ msg = "Input value is not an Node."
1310
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
1311
+ return false
1312
+ end if
1313
+ return true
1314
+ catch error
1315
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
1316
+ end try
1317
+
1318
+ end function
1319
+
1320
+ ' /**
1321
+ ' * @memberof module:BaseTestSuite
1322
+ ' * @name assertNodeNotContainsFields
1323
+ ' * @function
1324
+ ' * @instance
1325
+ ' * @description Fail if the node have the item from subset.
1326
+ ' * @param {Dynamic} node - A target node
1327
+ ' * @param {Dynamic} subset - the items to check for
1328
+ ' * @param {Dynamic} [msg=""] - alternate error message
1329
+ ' * @returns {boolean} - true if the assert w, false otherwise
1330
+ ' */
1331
+ function assertNodeNotContainsFields(node, subset, msg = "") as dynamic
1332
+ if m.currentResult.isFail then return false
1333
+ try
1334
+ if (type(node) = "roSGNode" and Rooibos.Common.isAssociativeArray(subset)) or (type(node) = "roSGNode" and Rooibos.Common.isArray(subset))
1335
+ isAA = Rooibos.Common.isAssociativeArray(subset)
1336
+ for each item in subset
1337
+ key = invalid
1338
+ value = item
1339
+ if isAA
1340
+ key = item
1341
+ value = item[key]
1342
+ end if
1343
+ if Rooibos.Common.nodeContains(node, value)
1344
+ msg = "Node has the '" + Rooibos.Common.asString(value) + "' value."
1345
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
1346
+ return false
1347
+ end if
1348
+ end for
1349
+ else
1350
+ msg = "Input value is not an Node."
1351
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
1352
+ return false
1353
+ end if
1354
+ return true
1355
+ catch error
1356
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
1357
+ end try
1358
+
1359
+ end function
1360
+
1361
+ '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1362
+ '++ END NODE ASSERTS
1363
+ '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1364
+
1365
+ ' /**
1366
+ ' * @memberof module:BaseTestSuite
1367
+ ' * @name assertAAContainsSubset
1368
+ ' * @function
1369
+ ' * @instance
1370
+ ' * @description Asserts the associative array contains the fields contained in subset; while ignoring the fields in the ignoredFields array
1371
+ ' * @param {assocarray} array - associative array to check
1372
+ ' * @param {assocarray} subset - associative array of values to check for
1373
+ ' * @param {array} ignoredFields - array of fieldnames to ignore while comparing
1374
+ ' * @param {string} [msg=""] - alternate error message
1375
+ ' * @returns {boolean} - true if the assert was satisfied, false otherwise
1376
+ ' */
1377
+ function assertAAContainsSubset(array, subset, ignoredFields = invalid, msg = "") as dynamic
1378
+ if m.currentResult.isFail then return false
1379
+ try
1380
+ if Rooibos.Common.isAssociativeArray(array) and Rooibos.Common.isAssociativeArray(subset)
1381
+ isAA = Rooibos.Common.isAssociativeArray(subset)
1382
+ isIgnoredFields = Rooibos.Common.isArray(ignoredFields)
1383
+ for each key in subset
1384
+ if key <> ""
1385
+ if not isIgnoredFields or not Rooibos.Common.arrayContains(ignoredFields, key)
1386
+ subsetValue = subset[key]
1387
+ arrayValue = array[key]
1388
+ if not Rooibos.Common.eqValues(arrayValue, subsetValue)
1389
+ msg = key + ": Expected '" + Rooibos.Common.asString(subsetValue) + "', got '" + Rooibos.Common.asString(arrayValue) + "'"
1390
+ m.currentResult.fail(msg, m.currentAssertLineNumber)
1391
+ return false
1392
+ end if
1393
+ end if
1394
+ else
1395
+ ? "Found empty key!"
1396
+ end if
1397
+ end for
1398
+ else
1399
+ msg = "Input values are not an Associative Array."
1400
+ m.currentResult.fail("Assert failed: " + msg, m.currentAssertLineNumber)
1401
+ return false
1402
+ end if
1403
+ return true
1404
+ catch error
1405
+ m.currentResult.fail("Assert failed: " + error.message, m.currentAssertLineNumber)
1406
+ end try
1407
+
1408
+ end function
1409
+
1410
+
1411
+ '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1412
+ '++ Stubbing helpers
1413
+ '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1414
+
1415
+ ' /**
1416
+ ' * @memberof module:BaseTestSuite
1417
+ ' * @name stub
1418
+ ' * @function
1419
+ ' * @instance
1420
+ ' * @description Creates a stub to replace a real method with
1421
+ ' * @param {Dynamic} target - object on which the method to be stubbed is found
1422
+ ' * @param {Dynamic} methodName - name of method to stub
1423
+ ' * @param {Dynamic} [returnValue=invalid] - value that the stub method will return when invoked
1424
+ ' * @param {boolean} [allowNonExistingMethods=false] - if true, then rooibos will only warn if the method did not exist prior to faking
1425
+ ' * @returns {Object} - stub that was wired into the real method
1426
+ ' */
1427
+ function stub(target, methodName, returnValue = invalid, allowNonExistingMethods = false) as object
1428
+ if type(target) <> "roAssociativeArray"
1429
+ m.fail("could not create Stub provided target was null")
1430
+ return {}
1431
+ end if
1432
+
1433
+ if m.stubs = invalid
1434
+ m.__stubId = -1
1435
+ m.stubs = {}
1436
+ end if
1437
+ m.__stubId++
1438
+
1439
+ if m.__stubId > 5
1440
+ ? "ERROR ONLY 6 STUBS PER TEST ARE SUPPORTED!!"
1441
+ return invalid
1442
+ end if
1443
+
1444
+ id = stri(m.__stubId).trim()
1445
+
1446
+ fake = m.createFake(id, target, methodName, 1, invalid, returnValue)
1447
+ m.stubs[id] = fake
1448
+ allowNonExisting = m.allowNonExistingMethodsOnMocks = true or allowNonExistingMethods
1449
+ isMethodPresent = type(target[methodName]) = "Function" or type(target[methodName]) = "roFunction"
1450
+ if isMethodPresent or allowNonExisting
1451
+ target[methodName] = m["StubCallback" + id]
1452
+ target.__stubs = m.stubs
1453
+
1454
+ if not isMethodPresent
1455
+ ? "WARNING - stubbing call " ; methodName; " which did not exist on target object"
1456
+ end if
1457
+ else
1458
+ ? "ERROR - could not create Stub : method not found "; target ; "." ; methodName
1459
+ end if
1460
+
1461
+ return fake
1462
+ end function
1463
+
1464
+ ' /**
1465
+ ' * @memberof module:BaseTestSuite
1466
+ ' * @name expectOnce
1467
+ ' * @function
1468
+ ' * @instance
1469
+ ' * @description Creates a stub to replace a real method with, which the framework will track. If it was invoked the wrong number of times, or with wrong arguments, it will result in test failure
1470
+ ' * @param {Dynamic} target - object on which the method to be stubbed is found
1471
+ ' * @param {Dynamic} methodName - name of method to stub
1472
+ ' * @param {Dynamic} [expectedArgs=invalid] - array containing the arguments we expect the method to be invoked with
1473
+ ' * @param {Dynamic} [returnValue=invalid] - value that the stub method will return when invoked
1474
+ ' * @param {boolean} [allowNonExistingMethods=false] - if true, then rooibos will only warn if the method did not exist prior to faking
1475
+ ' * @returns {Object} - mock that was wired into the real method
1476
+ ' */
1477
+ function expectOnce(target, methodName, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object
1478
+ try
1479
+ return m.mock(target, methodName, 1, expectedArgs, returnValue, allowNonExistingMethods)
1480
+ catch error
1481
+ m.currentResult.fail("Setting up mock failed: " + error.message, m.currentAssertLineNumber)
1482
+ return invalid
1483
+ end try
1484
+ end function
1485
+
1486
+ ' /**
1487
+ ' * @memberof module:BaseTestSuite
1488
+ ' * @name expectOnceOrNone
1489
+ ' * @function
1490
+ ' * @instance
1491
+ ' * @description Toggles between expectOnce and expectNone, to allow for easy paremeterized expect behaviour
1492
+ ' * @param {Dynamic} target - object on which the method to be stubbed is found
1493
+ ' * @param {Dynamic} methodName - name of method to stub
1494
+ ' * @param {Dynamic} isExpected - if true, then this is the same as expectOnce, if false, then this is the same as expectNone
1495
+ ' * @param {Dynamic} [expectedArgs=invalid] - array containing the arguments we expect the method to be invoked with
1496
+ ' * @param {Dynamic} [returnValue=invalid] - value that the stub method will return when invoked
1497
+ ' * @param {boolean} [allowNonExistingMethods=false] - if true, then rooibos will only warn if the method did not exist prior to faking
1498
+ ' * @returns {Object} - mock that was wired into the real method
1499
+ ' */
1500
+ function expectOnceOrNone(target, methodName, isExpected, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object
1501
+ try
1502
+ if isExpected
1503
+ return m.expectOnce(target, methodName, expectedArgs, returnValue, allowNonExistingMethods)
1504
+ else
1505
+ return m.expectNone(target, methodName, allowNonExistingMethods)
1506
+ end if
1507
+ catch error
1508
+ m.currentResult.fail("Setting up mock failed: " + error.message, m.currentAssertLineNumber)
1509
+ return invalid
1510
+ end try
1511
+ end function
1512
+
1513
+ ' /**
1514
+ ' * @memberof module:BaseTestSuite
1515
+ ' * @name expectNone
1516
+ ' * @function
1517
+ ' * @instance
1518
+ ' * @description Creates a stub to replace a real method with, which the framework will track. If it was invoked, it will result in test failure
1519
+ ' * @param {Dynamic} target - object on which the method to be stubbed is found
1520
+ ' * @param {Dynamic} methodName - name of method to stub
1521
+ ' * @param {boolean} [allowNonExistingMethods=false] - if true, then rooibos will only warn if the method did not exist prior to faking
1522
+ ' * @returns {Object} - mock that was wired into the real method
1523
+ ' */
1524
+ function expectNone(target, methodName, allowNonExistingMethods = false) as object
1525
+ try
1526
+ return m.mock(target, methodName, 0, invalid, invalid, allowNonExistingMethods)
1527
+ catch error
1528
+ m.currentResult.fail("Setting up mock failed: " + error.message, m.currentAssertLineNumber)
1529
+ return invalid
1530
+ end try
1531
+
1532
+ end function
1533
+
1534
+ ' /**
1535
+ ' * @memberof module:BaseTestSuite
1536
+ ' * @name expect
1537
+ ' * @function
1538
+ ' * @instance
1539
+ ' * @description Creates a stub to replace a real method with, which the framework will track. If it was invoked the wrong number of times, or with wrong arguments, it will result in test failure
1540
+ ' * @param {Dynamic} target - object on which the method to be stubbed is found
1541
+ ' * @param {Dynamic} methodName - name of method to stub
1542
+ ' * @param {Dynamic} [expectedInvocations=1] - number of invocations we expect
1543
+ ' * @param {Dynamic} [expectedArgs=invalid] - array containing the arguments we expect the method to be invoked with
1544
+ ' * @param {Dynamic} [returnValue=invalid] - value that the stub method will return when invoked
1545
+ ' * @param {boolean} [allowNonExistingMethods=false] - if true, then rooibos will only warn if the method did not exist prior to faking
1546
+ ' * @returns {Object} - mock that was wired into the real method
1547
+ ' */
1548
+ function expect(target, methodName, expectedInvocations = 1, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object
1549
+ try
1550
+ return m.mock(target, methodName, expectedInvocations, expectedArgs, returnValue, allowNonExistingMethods)
1551
+ catch error
1552
+ m.currentResult.fail("Setting up mock failed: " + error.message, m.currentAssertLineNumber)
1553
+ return invalid
1554
+ end try
1555
+ end function
1556
+
1557
+ ' /**
1558
+ ' * @memberof module:BaseTestSuite
1559
+ ' * @name mock
1560
+ ' * @function
1561
+ ' * @instance
1562
+ ' * @description Creates a stub to replace a real method with, which the framework will track. If it was invoked the wrong number of times, or with wrong arguments, it will result in test failure
1563
+ ' * @param {Dynamic} target - object on which the method to be stubbed is found
1564
+ ' * @param {Dynamic} methodName - name of method to stub
1565
+ ' * @param {Dynamic} expectedInvocations - number of invocations we expect
1566
+ ' * @param {Dynamic} [expectedArgs=invalid] - array containing the arguments we expect the method to be invoked with
1567
+ ' * @param {Dynamic} [returnValue=invalid] - value that the stub method will return when invoked
1568
+ ' * @param {boolean} [allowNonExistingMethods=false] - if true, then rooibos will only warn if the method did not exist prior to faking
1569
+ ' * @returns {Object} - mock that was wired into the real method
1570
+ ' */
1571
+ function mock(target, methodName, expectedInvocations = 1, expectedArgs = invalid, returnValue = invalid, allowNonExistingMethods = false) as object
1572
+ lineNumber = m.currentAssertLineNumber
1573
+ 'check params
1574
+ if not Rooibos.Common.isAssociativeArray(target)
1575
+ methodName = ""
1576
+ m.mockFail(lineNumber, "", "mock args: target was not an AA")
1577
+ else if not Rooibos.Common.isString(methodName)
1578
+ methodName = ""
1579
+ m.mockFail(lineNumber, "", "mock args: methodName was not a string")
1580
+ else if not Rooibos.Common.isNumber(expectedInvocations)
1581
+ m.mockFail(lineNumber, methodName, "mock args: expectedInvocations was not an int")
1582
+ else if not Rooibos.Common.isArray(expectedArgs) and Rooibos.Common.isValid(expectedArgs)
1583
+ m.mockFail(lineNumber, methodName, "mock args: expectedArgs was not invalid or an array of args")
1584
+ else if Rooibos.Common.isUndefined(expectedArgs)
1585
+ m.mockFail(lineNumber, methodName, "mock args: expectedArgs undefined")
1586
+ else if Rooibos.Common.isUndefined(returnValue)
1587
+ m.mockFail(lineNumber, methodName, "mock args: returnValue undefined")
1588
+ end if
1589
+
1590
+ if m.currentResult.isFail
1591
+ ? "ERROR! Cannot create MOCK. method " ; methodName ;" " str(lineNumber) ; " "; m.currentResult.message
1592
+ return {}
1593
+ end if
1594
+
1595
+ if m.mocks = invalid
1596
+ m.__mockId = -1
1597
+ m.__mockTargetId = -1
1598
+ m.mocks = {}
1599
+ end if
1600
+
1601
+ fake = invalid
1602
+ if not target.doesExist("__rooibosTargetId")
1603
+ m.__mockTargetId++
1604
+ target["__rooibosTargetId"] = m.__mockTargetId
1605
+ end if
1606
+ 'ascertain if mock already exists
1607
+ for i = 0 to m.__mockId
1608
+ id = stri(i).trim()
1609
+ mock = m.mocks[id]
1610
+ if mock <> invalid and mock.methodName = methodName and mock.target.__rooibosTargetId = target.__rooibosTargetId
1611
+ fake = mock
1612
+ fake.lineNumbers.push(lineNumber)
1613
+ exit for
1614
+ end if
1615
+ end for
1616
+ if fake = invalid
1617
+ m.__mockId++
1618
+ id = stri(m.__mockId).trim()
1619
+ if m.__mockId > 25
1620
+ ? "ERROR ONLY 25 MOCKS PER TEST ARE SUPPORTED!! you're on # " ; m.__mockId
1621
+ ? " Method was " ; methodName
1622
+ return invalid
1623
+ end if
1624
+
1625
+ fake = m.createFake(id, target, methodName, expectedInvocations, expectedArgs, returnValue)
1626
+ m.mocks[id] = fake 'this will bind it to m
1627
+ allowNonExisting = m.allowNonExistingMethodsOnMocks = true or allowNonExistingMethods
1628
+ isMethodPresent = type(target[methodName]) = "Function" or type(target[methodName]) = "roFunction"
1629
+ if isMethodPresent or allowNonExisting
1630
+ target[methodName] = m["MockCallback" + id]
1631
+ target.__mocks = m.mocks
1632
+
1633
+ if not isMethodPresent
1634
+ ' ? "WARNING - mocking call " ; methodName; " which did not exist on target object"
1635
+ end if
1636
+ else
1637
+ ? "ERROR - could not create Mock : method not found "; target ; "." ; methodName
1638
+ end if
1639
+ else
1640
+ m.combineFakes(fake, m.createFake(id, target, methodName, expectedInvocations, expectedArgs, returnValue))
1641
+ end if
1642
+ return fake
1643
+ end function
1644
+
1645
+ ' /**
1646
+ ' * @memberof module:BaseTestSuite
1647
+ ' * @name createFake
1648
+ ' * @function
1649
+ ' * @instance
1650
+ ' * @description Creates a stub to replace a real method with. This is used internally.
1651
+ ' * @param {Dynamic} target - object on which the method to be stubbed is found
1652
+ ' * @param {Dynamic} methodName - name of method to stub
1653
+ ' * @param {Dynamic} [expectedInvocations=1] - number of invocations we expect
1654
+ ' * @param {Dynamic} [expectedArgs=invalid] - array containing the arguments we expect the method to be invoked with
1655
+ ' * @param {Dynamic} [returnValue=invalid] - value that the stub method will return when invoked
1656
+ ' * @returns {Object} - stub that was wired into the real method
1657
+ ' */
1658
+ function createFake(id, target, methodName, expectedInvocations = 1, expectedArgs = invalid, returnValue = invalid) as object
1659
+ expectedArgsValues = []
1660
+ lineNumber = m.currentAssertLineNumber
1661
+ hasArgs = Rooibos.Common.isArray(expectedArgs)
1662
+ if hasArgs
1663
+ defaultValue = m.invalidValue
1664
+ else
1665
+ defaultValue = m.ignoreValue
1666
+ expectedArgs = []
1667
+ end if
1668
+ lineNumbers = [lineNumber]
1669
+
1670
+ for i = 0 to 9
1671
+ if hasArgs and expectedArgs.count() > i
1672
+ 'guard against bad values
1673
+ value = expectedArgs[i]
1674
+ if not Rooibos.Common.isUndefined(value)
1675
+ if Rooibos.Common.isAssociativeArray(value) and Rooibos.Common.isValid(value.matcher)
1676
+ if not Rooibos.Common.isFunction(value.matcher)
1677
+ ? "[ERROR] you have specified a matching function; but it is not in scope!"
1678
+ expectedArgsValues.push("#ERR-OUT_OF_SCOPE_MATCHER!")
1679
+ else
1680
+ expectedArgsValues.push(expectedArgs[i])
1681
+ end if
1682
+ else
1683
+ expectedArgsValues.push(expectedArgs[i])
1684
+ end if
1685
+ else
1686
+ expectedArgsValues.push("#ERR-UNDEFINED!")
1687
+ end if
1688
+ else
1689
+ expectedArgsValues.push(defaultValue)
1690
+ end if
1691
+ end for
1692
+ fake = {
1693
+ id: id,
1694
+ target: target,
1695
+ methodName: methodName,
1696
+ returnValue: returnValue,
1697
+ lineNumbers: lineNumbers,
1698
+ isCalled: false,
1699
+ invocations: 0,
1700
+ invokedArgs: [invalid, invalid, invalid, invalid, invalid, invalid, invalid, invalid, invalid],
1701
+ expectedArgs: expectedArgsValues,
1702
+ expectedInvocations: expectedInvocations,
1703
+ callback: function(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
1704
+ ' ? "FAKE CALLBACK CALLED FOR " ; m.methodName
1705
+ 'bs:disable-next-line
1706
+ if m.allInvokedArgs = invalid
1707
+ 'bs:disable-next-line
1708
+ m.allInvokedArgs = []
1709
+ end if
1710
+ 'bs:disable-next-line
1711
+ m.invokedArgs = [arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15]
1712
+ 'bs:disable-next-line
1713
+ m.allInvokedArgs.push ([arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15])
1714
+ 'bs:disable-next-line
1715
+ m.isCalled = true
1716
+ 'bs:disable-next-line
1717
+ m.invocations++
1718
+
1719
+ 'bs:disable-next-line
1720
+ if type(m.returnValue) = "roAssociativeArray" and m.returnValue.doesExist("multiResult")
1721
+ 'bs:disable-next-line
1722
+ returnValues = m.returnValue["multiResult"]
1723
+ 'bs:disable-next-line
1724
+ returnIndex = m.invocations - 1
1725
+
1726
+ if type(returnValues) = "roArray" and returnValues.count() > 0
1727
+
1728
+ 'bs:disable-next-line
1729
+ if returnValues.count() <= m.invocations
1730
+ returnIndex = returnValues.count() - 1
1731
+ print "Multi return values all used up - repeating last value"
1732
+ end if
1733
+ return returnValues[returnIndex]
1734
+ else
1735
+ ? "Multi return value was specified; but no array of results were found"
1736
+ return invalid
1737
+ end if
1738
+ else
1739
+ 'bs:disable-next-line
1740
+ return m.returnValue
1741
+ end if
1742
+ end function
1743
+ }
1744
+ return fake
1745
+ end function
1746
+
1747
+ function combineFakes(fake, otherFake)
1748
+ 'add on the expected invoked args
1749
+ lineNumber = m.currentAssertLineNumber
1750
+ if type(fake.expectedArgs) <> "roAssociativeArray" or not fake.expectedArgs.doesExist("multiInvoke")
1751
+ currentExpectedArgsArgs = fake.expectedArgs
1752
+ fake.expectedArgs = {
1753
+ "multiInvoke": [currentExpectedArgsArgs]
1754
+ }
1755
+ end if
1756
+ fake.expectedArgs.multiInvoke.push(otherFake.expectedArgs)
1757
+
1758
+ 'add on the expected return values
1759
+ if type(fake.returnValue) <> "roAssociativeArray" or not fake.returnValue.doesExist("multiResult")
1760
+ currentReturnValue = fake.returnValue
1761
+ fake.returnValue = {
1762
+ "multiResult": [currentReturnValue]
1763
+ }
1764
+ end if
1765
+ fake.returnValue.multiResult.push(otherFake.returnValue)
1766
+ fake.lineNumbers.push(lineNumber)
1767
+ fake.expectedInvocations++
1768
+ end function
1769
+ ' /**
1770
+ ' * @memberof module:BaseTestSuite
1771
+ ' * @name assertMocks
1772
+ ' * @function
1773
+ ' * @instance
1774
+ ' * @description Will check all mocks that have been created to ensure they were invoked the expected amount of times, with the expected args.
1775
+ ' */
1776
+ function assertMocks() as void
1777
+ if m.__mockId = invalid or not Rooibos.Common.isAssociativeArray(m.mocks)
1778
+ return
1779
+ end if
1780
+
1781
+ lastId = int(m.__mockId)
1782
+ for each id in m.mocks
1783
+ mock = m.mocks[id]
1784
+ methodName = mock.methodName
1785
+ if mock.expectedInvocations <> mock.invocations
1786
+ m.mockFail(mock.lineNumbers[0], methodName, "Wrong number of calls. (" + stri(mock.invocations).trim() + " / " + stri(mock.expectedInvocations).trim() + ")")
1787
+ m.cleanMocks()
1788
+ return
1789
+ else if mock.expectedInvocations > 0 and (Rooibos.Common.isArray(mock.expectedArgs) or (type(mock.expectedArgs) = "roAssociativeArray" and Rooibos.Common.isArray(mock.expectedArgs.multiInvoke)))
1790
+ isMultiArgsSupported = type(mock.expectedArgs) = "roAssociativeArray" and Rooibos.Common.isArray(mock.expectedArgs.multiInvoke)
1791
+
1792
+ for invocationIndex = 0 to mock.invocations - 1
1793
+ invokedArgs = mock.allInvokedArgs[invocationIndex]
1794
+ if isMultiArgsSupported
1795
+ expectedArgs = mock.expectedArgs.multiInvoke[invocationIndex]
1796
+ else
1797
+ expectedArgs = mock.expectedArgs
1798
+ end if
1799
+ for i = 0 to expectedArgs.count() - 1
1800
+ value = invokedArgs[i]
1801
+ expected = expectedArgs[i]
1802
+ didNotExpectArg = Rooibos.Common.isString(expected) and expected = m.invalidValue
1803
+ if didNotExpectArg
1804
+ expected = invalid
1805
+ end if
1806
+
1807
+ isUsingMatcher = Rooibos.Common.isAssociativeArray(expected) and Rooibos.Common.isFunction(expected.matcher)
1808
+
1809
+ if isUsingMatcher
1810
+ if not expected.matcher(value)
1811
+ m.mockFail(mock.lineNumbers[invocationIndex], methodName, "on Invocation #" + stri(invocationIndex).trim() + ", expected arg #" + stri(i).trim() + " to match matching function '" + Rooibos.Common.asString(expected.matcher) + "' got '" + Rooibos.Common.asString(value) + "')")
1812
+ m.cleanMocks()
1813
+ end if
1814
+ else
1815
+ if not (Rooibos.Common.isString(expected) and expected = m.ignoreValue) and not Rooibos.Common.eqValues(value, expected)
1816
+ if expected = invalid
1817
+ expected = "[INVALID]"
1818
+ end if
1819
+
1820
+ m.mockFail(mock.lineNumbers[invocationIndex], methodName, "on Invocation #" + stri(invocationIndex).trim() + ", expected arg #" + stri(i).trim() + " to be '" + Rooibos.Common.asString(expected) + "' got '" + Rooibos.Common.asString(value) + "')")
1821
+ m.cleanMocks()
1822
+ return
1823
+ end if
1824
+ end if
1825
+ end for
1826
+ end for
1827
+ end if
1828
+ end for
1829
+
1830
+ m.cleanMocks()
1831
+ end function
1832
+
1833
+ ' /**
1834
+ ' * @memberof module:BaseTestSuite
1835
+ ' * @name cleanMocks
1836
+ ' * @function
1837
+ ' * @instance
1838
+ ' * @description Cleans up all tracking data associated with mocks
1839
+ ' */
1840
+ function cleanMocks() as void
1841
+ if m.mocks = invalid then return
1842
+ for each id in m.mocks
1843
+ mock = m.mocks[id]
1844
+ mock.target.__mocks = invalid
1845
+ end for
1846
+ m.mocks = invalid
1847
+ end function
1848
+
1849
+ ' /**
1850
+ ' * @memberof module:BaseTestSuite
1851
+ ' * @name cleanStubs
1852
+ ' * @function
1853
+ ' * @instance
1854
+ ' * @description Cleans up all tracking data associated with stubs
1855
+ ' */
1856
+ function cleanStubs() as void
1857
+ if m.stubs = invalid then return
1858
+ for each id in m.stubs
1859
+ stub = m.stubs[id]
1860
+ stub.target.__stubs = invalid
1861
+ end for
1862
+ m.stubs = invalid
1863
+ end function
1864
+
1865
+
1866
+ function mockFail(lineNumber, methodName, message) as dynamic
1867
+ if m.currentResult.isFail then return false
1868
+ m.currentResult.fail("mock failure on '" + methodName + "' : " + message, lineNumber)
1869
+ return false
1870
+ end function
1871
+
1872
+
1873
+ '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1874
+ '++ Fake Stub callback functions - this is required to get scope
1875
+ '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1876
+
1877
+ function stubCallback0(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
1878
+ 'bs:disable-next-line
1879
+ fake = m.__Stubs["0"]
1880
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
1881
+ end function
1882
+
1883
+ function stubCallback1(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
1884
+ 'bs:disable-next-line
1885
+ fake = m.__Stubs["1"]
1886
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
1887
+ end function
1888
+
1889
+ function stubCallback2(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
1890
+ 'bs:disable-next-line
1891
+ fake = m.__Stubs["2"]
1892
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
1893
+ end function
1894
+
1895
+
1896
+ function stubCallback3(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
1897
+ 'bs:disable-next-line
1898
+ fake = m.__Stubs["3"]
1899
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
1900
+ end function
1901
+
1902
+
1903
+ function stubCallback4(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
1904
+ 'bs:disable-next-line
1905
+ fake = m.__Stubs["4"]
1906
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
1907
+ end function
1908
+
1909
+
1910
+ function stubCallback5(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
1911
+ 'bs:disable-next-line
1912
+ fake = m.__Stubs["5"]
1913
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
1914
+ end function
1915
+
1916
+ '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1917
+ '++ Fake Mock callback functions - this is required to get scope
1918
+ '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1919
+
1920
+ function mockCallback0(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
1921
+ 'bs:disable-next-line
1922
+ fake = m.__mocks["0"]
1923
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
1924
+ end function
1925
+
1926
+ function mockCallback1(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
1927
+ 'bs:disable-next-line
1928
+ fake = m.__mocks["1"]
1929
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
1930
+ end function
1931
+
1932
+ function mockCallback2(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
1933
+ 'bs:disable-next-line
1934
+ fake = m.__mocks["2"]
1935
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
1936
+ end function
1937
+
1938
+ function mockCallback3(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
1939
+ 'bs:disable-next-line
1940
+ fake = m.__mocks["3"]
1941
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
1942
+ end function
1943
+
1944
+ function mockCallback4(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
1945
+ 'bs:disable-next-line
1946
+ fake = m.__mocks["4"]
1947
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
1948
+ end function
1949
+
1950
+ function mockCallback5(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
1951
+ 'bs:disable-next-line
1952
+ fake = m.__mocks["5"]
1953
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
1954
+ end function
1955
+
1956
+ function mockCallback6(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
1957
+ 'bs:disable-next-line
1958
+ fake = m.__mocks["6"]
1959
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
1960
+ end function
1961
+
1962
+ function mockCallback7(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
1963
+ 'bs:disable-next-line
1964
+ fake = m.__mocks["7"]
1965
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
1966
+ end function
1967
+
1968
+ function mockCallback8(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
1969
+ 'bs:disable-next-line
1970
+ fake = m.__mocks["8"]
1971
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
1972
+ end function
1973
+
1974
+ function mockCallback9(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
1975
+ 'bs:disable-next-line
1976
+ fake = m.__mocks["9"]
1977
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
1978
+ end function
1979
+
1980
+ function mockCallback10(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
1981
+ 'bs:disable-next-line
1982
+ fake = m.__mocks["10"]
1983
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
1984
+ end function
1985
+
1986
+ function mockCallback11(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
1987
+ 'bs:disable-next-line
1988
+ fake = m.__mocks["11"]
1989
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
1990
+ end function
1991
+
1992
+ function mockCallback12(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
1993
+ 'bs:disable-next-line
1994
+ fake = m.__mocks["12"]
1995
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
1996
+ end function
1997
+
1998
+ function mockCallback13(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
1999
+ 'bs:disable-next-line
2000
+ fake = m.__mocks["13"]
2001
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
2002
+ end function
2003
+
2004
+ function mockCallback14(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
2005
+ 'bs:disable-next-line
2006
+ fake = m.__mocks["14"]
2007
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
2008
+ end function
2009
+
2010
+ function mockCallback15(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
2011
+ 'bs:disable-next-line
2012
+ fake = m.__mocks["15"]
2013
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
2014
+ end function
2015
+
2016
+ function mockCallback16(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
2017
+ 'bs:disable-next-line
2018
+ fake = m.__mocks["16"]
2019
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
2020
+ end function
2021
+
2022
+ function mockCallback17(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
2023
+ 'bs:disable-next-line
2024
+ fake = m.__mocks["17"]
2025
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
2026
+ end function
2027
+
2028
+ function mockCallback18(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
2029
+ 'bs:disable-next-line
2030
+ fake = m.__mocks["18"]
2031
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
2032
+ end function
2033
+
2034
+ function mockCallback19(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
2035
+ 'bs:disable-next-line
2036
+ fake = m.__mocks["19"]
2037
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
2038
+ end function
2039
+
2040
+ function mockCallback20(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
2041
+ 'bs:disable-next-line
2042
+ fake = m.__mocks["20"]
2043
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
2044
+ end function
2045
+
2046
+ function mockCallback21(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
2047
+ 'bs:disable-next-line
2048
+ fake = m.__mocks["21"]
2049
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
2050
+ end function
2051
+
2052
+ function mockCallback22(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
2053
+ 'bs:disable-next-line
2054
+ fake = m.__mocks["22"]
2055
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
2056
+ end function
2057
+
2058
+ function mockCallback23(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
2059
+ 'bs:disable-next-line
2060
+ fake = m.__mocks["23"]
2061
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
2062
+ end function
2063
+
2064
+ function mockCallback24(arg1 = invalid, arg2 = invalid, arg3 = invalid, arg4 = invalid, arg5 = invalid, arg6 = invalid, arg7 = invalid, arg8 = invalid, arg9 = invalid, arg10 = invalid, arg11 = invalid, arg12 = invalid, arg13 = invalid, arg14 = invalid, arg15 = invalid)as dynamic
2065
+ 'bs:disable-next-line
2066
+ fake = m.__mocks["24"]
2067
+ return fake.callback(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15)
2068
+ end function
2069
+
2070
+ '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2071
+ '++ crude async support
2072
+ '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2073
+
2074
+ ' /**
2075
+ ' * @member waitForField
2076
+ ' * @memberof module:TestUtils
2077
+ ' * @instance
2078
+ ' * @function
2079
+ ' * @description observeField doesn't work in regular unit tests, so we have to wait for the result. We can use this to wait for a network task, foe example, and pass the result directly to a handler. Note - we wait for the value TO CHANGE - so make sure that will be the case, or you'll get stuck forever :)
2080
+ ' * @param {any} target to observe
2081
+ ' * @param {string} field to observe
2082
+ ' * @param {int} delay for each wait
2083
+ ' * @param {int} max attempts
2084
+ ' */
2085
+ function waitForField(target, fieldName, delay = 500, maxAttempts = 10)
2086
+ attempts = 0
2087
+ if target = invalid
2088
+ return false
2089
+ end if
2090
+
2091
+ initialValue = target[fieldName]
2092
+ while target[fieldName] = initialValue
2093
+ port = CreateObject("roMessagePort")
2094
+ wait(delay, port)
2095
+ attempts++
2096
+ if attempts = maxAttempts
2097
+ return false
2098
+ end if
2099
+ ? "waiting for signal field '" ; fieldName "' - " ; attempts
2100
+ end while
2101
+
2102
+ return true
2103
+ end function
2104
+
2105
+ function wait(delay = 1)
2106
+ port = CreateObject("roMessagePort")
2107
+ wait(delay, port)
2108
+ end function
2109
+
2110
+ function assertAsyncField(target, fieldName, delay = 500, maxAttempts = 10)
2111
+ try
2112
+ if m.currentResult.isFail then return false
2113
+ if target = invalid
2114
+ m.fail("Target was invalid")
2115
+ end if
2116
+
2117
+ result = m.waitForField(target, fieldName, delay, maxAttempts)
2118
+ if not result
2119
+ return m.fail("Timeout waiting for targetField " + fieldName + " to be set on target")
2120
+ end if
2121
+
2122
+ return true
2123
+ catch error
2124
+ m.currentResult.fail("Error while waiting: " + error.message, m.currentAssertLineNumber)
2125
+ end try
2126
+
2127
+ end function
2128
+
2129
+ end class
2130
+
2131
+ end namespace