rooibos-roku 4.3.2 → 4.5.0

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