rooibos-roku 4.4.2 → 4.5.3

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