-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathUnitTestFramework.brs
2867 lines (2407 loc) · 102 KB
/
UnitTestFramework.brs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'*****************************************************************
'* Roku Unit Testing Framework
'* Automating test suites for Roku channels.
'*
'* Build Version: 2.1.1
'* Build Date: 05/06/2019
'*
'* Public Documentation is avaliable on GitHub:
'* https://github.com/rokudev/unit-testing-framework
'*
'*****************************************************************
'*****************************************************************
'* Copyright Roku 2011-2019
'* All Rights Reserved
'*****************************************************************
' Functions in this file:
' BaseTestSuite
' BTS__AddTest
' BTS__CreateTest
' BTS__Fail
' BTS__AssertFalse
' BTS__AssertTrue
' BTS__AssertEqual
' BTS__AssertNotEqual
' BTS__AssertInvalid
' BTS__AssertNotInvalid
' BTS__AssertAAHasKey
' BTS__AssertAANotHasKey
' BTS__AssertAAHasKeys
' BTS__AssertAANotHasKeys
' BTS__AssertArrayContains
' BTS__AssertArrayNotContains
' BTS__AssertArrayContainsSubset
' BTS__AssertArrayNotContainsSubset
' BTS__AssertArrayCount
' BTS__AssertArrayNotCount
' BTS__AssertEmpty
' BTS__AssertNotEmpty
' ----------------------------------------------------------------
' Main function. Create BaseTestSuite object.
' @return A BaseTestSuite object.
' ----------------------------------------------------------------
function BaseTestSuite()
this = {}
this.Name = "BaseTestSuite"
this.SKIP_TEST_MESSAGE_PREFIX = "SKIP_TEST_MESSAGE_PREFIX__"
' Test Cases methods
this.testCases = []
this.IS_NEW_APPROACH = false
this.addTest = BTS__AddTest
this.createTest = BTS__CreateTest
this.StorePerformanceData = BTS__StorePerformanceData
' Assertion methods which determine test failure or skipping
this.skip = BTS__Skip
this.fail = BTS__Fail
this.assertFalse = BTS__AssertFalse
this.assertTrue = BTS__AssertTrue
this.assertEqual = BTS__AssertEqual
this.assertNotEqual = BTS__AssertNotEqual
this.assertInvalid = BTS__AssertInvalid
this.assertNotInvalid = BTS__AssertNotInvalid
this.assertAAHasKey = BTS__AssertAAHasKey
this.assertAANotHasKey = BTS__AssertAANotHasKey
this.assertAAHasKeys = BTS__AssertAAHasKeys
this.assertAANotHasKeys = BTS__AssertAANotHasKeys
this.assertArrayContains = BTS__AssertArrayContains
this.assertArrayNotContains = BTS__AssertArrayNotContains
this.assertArrayContainsSubset = BTS__AssertArrayContainsSubset
this.assertArrayNotContainsSubset = BTS__AssertArrayNotContainsSubset
this.assertArrayCount = BTS__AssertArrayCount
this.assertArrayNotCount = BTS__AssertArrayNotCount
this.assertEmpty = BTS__AssertEmpty
this.assertNotEmpty = BTS__AssertNotEmpty
' Type Comparison Functionality
this.eqValues = TF_Utils__EqValues
this.eqAssocArrays = TF_Utils__EqAssocArray
this.eqArrays = TF_Utils__EqArray
this.baseComparator = TF_Utils__BaseComparator
return this
end function
' ----------------------------------------------------------------
' Add a test to a suite's test cases array.
' @param name (string) A test name.
' @param func (object) A pointer to test function.
' @param setup (object) A pointer to setup function.
' @param teardown (object) A pointer to teardown function.
' @param arg (dynamic) A test function arguments.
' @param hasArgs (boolean) True if test function has parameters.
' @param skip (boolean) Skip test run.
' ----------------------------------------------------------------
sub BTS__AddTest(name as String, func as Object, setup = invalid as Object, teardown = invalid as Object, arg = invalid as Dynamic, hasArgs = false as Boolean, skip = false as Boolean)
m.testCases.Push(m.createTest(name, func, setup, teardown, arg, hasArgs, skip))
end sub
' ----------------------------------------------------------------
' Create a test object.
' @param name (string) A test name.
' @param func (object) A pointer to test function.
' @param setup (object) A pointer to setup function.
' @param teardown (object) A pointer to teardown function.
' @param arg (dynamic) A test function arguments.
' @param hasArgs (boolean) True if test function has parameters.
' @param skip (boolean) Skip test run.
'
' @return TestCase object.
' ----------------------------------------------------------------
function BTS__CreateTest(name as String, func as Object, setup = invalid as Object, teardown = invalid as Object, arg = invalid as Dynamic, hasArgs = false as Boolean, skip = false as Boolean) as Object
return {
Name: name
Func: func
SetUp: setup
TearDown: teardown
perfData: {}
hasArguments: hasArgs
arg: arg
skip: skip
}
end function
'----------------------------------------------------------------
' Store performance data to current test instance.
'
' @param name (string) A property name.
' @param value (Object) A value of data.
'----------------------------------------------------------------
Sub BTS__StorePerformanceData(name as String, value as Object)
timestamp = StrI(CreateObject("roDateTime").AsSeconds())
m.testInstance.perfData.Append({
name: {
"value" : value
"timestamp": timestamp
}
})
' print performance data to console
? "PERF_DATA: " + m.testInstance.Name + ": " + timestamp + ": " + name + "|" + TF_Utils__AsString(value)
End Sub
' ----------------------------------------------------------------
' Assertion methods which determine test failure or skipping
' ----------------------------------------------------------------
' ----------------------------------------------------------------
' Should be used to skip test cases. To skip test you must return the result of this method invocation.
' @param message (string) Optional skip message.
' Default value: "".
' @return A skip message, with a specific prefix added, in order to runner know that this test should be skipped.
' ----------------------------------------------------------------
function BTS__Skip(message = "" as String) as String
' add prefix so we know that this test is skipped, but not failed
return m.SKIP_TEST_MESSAGE_PREFIX + message
end function
' ----------------------------------------------------------------
' Fail immediately, with the given message
' @param msg (string) An error message.
' Default value: "Error".
' @return An error message.
' ----------------------------------------------------------------
function BTS__Fail(msg = "Error" as String) as String
return msg
end function
' ----------------------------------------------------------------
' Fail the test if the expression is true.
' @param expr (dynamic) An expression to evaluate.
' @param msg (string) An error message.
' Default value: "Expression evaluates to true"
' @return An error message.
' ----------------------------------------------------------------
function BTS__AssertFalse(expr as Dynamic, msg = "Expression evaluates to true" as String) as String
if not TF_Utils__IsBoolean(expr) or expr
return BTS__Fail(msg)
end if
return ""
end function
' ----------------------------------------------------------------
' Fail the test unless the expression is true.
' @param expr (dynamic) An expression to evaluate.
' @param msg (string) An error message.
' Default value: "Expression evaluates to false"
' @return An error message.
' ----------------------------------------------------------------
function BTS__AssertTrue(expr as Dynamic, msg = "Expression evaluates to false" as String) as String
if not TF_Utils__IsBoolean(expr) or not expr then
return msg
end if
return ""
end function
' ----------------------------------------------------------------
' Fail if the two objects are unequal as determined by the '<>' operator.
' @param first (dynamic) A first object to compare.
' @param second (dynamic) A second object to compare.
' @param msg (string) An error message.
' Default value: ""
' @return An error message.
' ----------------------------------------------------------------
function BTS__AssertEqual(first as Dynamic, second as Dynamic, msg = "" as String) as String
if not TF_Utils__EqValues(first, second)
if msg = ""
first_as_string = TF_Utils__AsString(first)
second_as_string = TF_Utils__AsString(second)
msg = first_as_string + " != " + second_as_string
end if
return msg
end if
return ""
end function
' ----------------------------------------------------------------
' Fail if the two objects are equal as determined by the '=' operator.
' @param first (dynamic) A first object to compare.
' @param second (dynamic) A second object to compare.
' @param msg (string) An error message.
' Default value: ""
' @return An error message.
' ----------------------------------------------------------------
function BTS__AssertNotEqual(first as Dynamic, second as Dynamic, msg = "" as String) as String
if TF_Utils__EqValues(first, second)
if msg = ""
first_as_string = TF_Utils__AsString(first)
second_as_string = TF_Utils__AsString(second)
msg = first_as_string + " == " + second_as_string
end if
return msg
end if
return ""
end function
' ----------------------------------------------------------------
' Fail if the value is not invalid.
' @param value (dynamic) A value to check.
' @param msg (string) An error message.
' Default value: ""
' @return An error message.
' ----------------------------------------------------------------
function BTS__AssertInvalid(value as Dynamic, msg = "" as String) as String
if TF_Utils__IsValid(value)
if msg = ""
expr_as_string = TF_Utils__AsString(value)
msg = expr_as_string + " <> Invalid"
end if
return msg
end if
return ""
end function
' ----------------------------------------------------------------
' Fail if the value is invalid.
' @param value (dynamic) A value to check.
' @param msg (string) An error message.
' Default value: ""
' @return An error message.
' ----------------------------------------------------------------
function BTS__AssertNotInvalid(value as Dynamic, msg = "" as String) as String
if not TF_Utils__IsValid(value)
if msg = ""
if LCase(Type(value)) = "<uninitialized>" then value = invalid
expr_as_string = TF_Utils__AsString(value)
msg = expr_as_string + " = Invalid"
end if
return msg
end if
return ""
end function
' ----------------------------------------------------------------
' Fail if the array doesn't have the key.
' @param array (dynamic) A target array.
' @param key (string) A key name.
' @param msg (string) An error message.
' Default value: ""
' @return An error message.
' ----------------------------------------------------------------
function BTS__AssertAAHasKey(array as Dynamic, key as Dynamic, msg = "" as String) as String
if not TF_Utils__IsString(key)
return "Key value has invalid type."
end if
if TF_Utils__IsAssociativeArray(array)
if not array.DoesExist(key)
if msg = ""
msg = "Array doesn't have the '" + key + "' key."
end if
return msg
end if
else
msg = "Input value is not an Associative Array."
return msg
end if
return ""
end function
' ----------------------------------------------------------------
' Fail if the array has the key.
' @param array (dynamic) A target array.
' @param key (string) A key name.
' @param msg (string) An error message.
' Default value: ""
' @return An error message.
' ----------------------------------------------------------------
function BTS__AssertAANotHasKey(array as Dynamic, key as Dynamic, msg = "" as String) as String
if not TF_Utils__IsString(key)
return "Key value has invalid type."
end if
if TF_Utils__IsAssociativeArray(array)
if array.DoesExist(key)
if msg = ""
msg = "Array has the '" + key + "' key."
end if
return msg
end if
else
msg = "Input value is not an Associative Array."
return msg
end if
return ""
end function
' ----------------------------------------------------------------
' Fail if the array doesn't have the keys list.
' @param array (dynamic) A target associative array.
' @param keys (object) A key names array.
' @param msg (string) An error message.
' Default value: ""
' @return An error message.
' ----------------------------------------------------------------
function BTS__AssertAAHasKeys(array as Dynamic, keys as Object, msg = "" as String) as String
if not TF_Utils__IsAssociativeArray(array)
return "Input value is not an Associative Array."
end if
if not TF_Utils__IsArray(keys) or keys.Count() = 0
return "Keys value is not an Array or is empty."
end if
if TF_Utils__IsAssociativeArray(array) and TF_Utils__IsArray(keys)
for each key in keys
if not TF_Utils__IsString(key)
return "Key value has invalid type."
end if
if not array.DoesExist(key)
if msg = ""
msg = "Array doesn't have the '" + key + "' key."
end if
return msg
end if
end for
else
msg = "Input value is not an Associative Array."
return msg
end if
return ""
end function
' ----------------------------------------------------------------
' Fail if the array has the keys list.
' @param array (dynamic) A target associative array.
' @param keys (object) A key names array.
' @param msg (string) An error message.
' Default value: ""
' @return An error message.
' ----------------------------------------------------------------
function BTS__AssertAANotHasKeys(array as Dynamic, keys as Object, msg = "" as String) as String
if not TF_Utils__IsAssociativeArray(array)
return "Input value is not an Associative Array."
end if
if not TF_Utils__IsArray(keys) or keys.Count() = 0
return "Keys value is not an Array or is empty."
end if
if TF_Utils__IsAssociativeArray(array) and TF_Utils__IsArray(keys)
for each key in keys
if not TF_Utils__IsString(key)
return "Key value has invalid type."
end if
if array.DoesExist(key)
if msg = ""
msg = "Array has the '" + key + "' key."
end if
return msg
end if
end for
else
msg = "Input value is not an Associative Array."
return msg
end if
return ""
end function
' ----------------------------------------------------------------
' Fail if the array doesn't have the item.
' @param array (dynamic) A target array.
' @param value (dynamic) A value to check.
' @param key (object) A key name for associative array.
' @param msg (string) An error message.
' Default value: ""
' @return An error message.
' ----------------------------------------------------------------
function BTS__AssertArrayContains(array as Dynamic, value as Dynamic, key = invalid as Dynamic, msg = "" as String) as String
if key <> invalid and not TF_Utils__IsString(key)
return "Key value has invalid type."
end if
if TF_Utils__IsAssociativeArray(array) or TF_Utils__IsArray(array)
if not TF_Utils__ArrayContains(array, value, key)
msg = "Array doesn't have the '" + TF_Utils__AsString(value) + "' value."
return msg
end if
else
msg = "Input value is not an Array."
return msg
end if
return ""
end function
' ----------------------------------------------------------------
' Fail if the array has the item.
' @param array (dynamic) A target array.
' @param value (dynamic) A value to check.
' @param key (object) A key name for associative array.
' @param msg (string) An error message.
' Default value: ""
' @return An error message.
' ----------------------------------------------------------------
function BTS__AssertArrayNotContains(array as Dynamic, value as Dynamic, key = invalid as Dynamic, msg = "" as String) as String
if key <> invalid and not TF_Utils__IsString(key)
return "Key value has invalid type."
end if
if TF_Utils__IsAssociativeArray(array) or TF_Utils__IsArray(array)
if TF_Utils__ArrayContains(array, value, key)
msg = "Array has the '" + TF_Utils__AsString(value) + "' value."
return msg
end if
else
msg = "Input value is not an Array."
return msg
end if
return ""
end function
' ----------------------------------------------------------------
' Fail if the array doesn't have the item subset.
' @param array (dynamic) A target array.
' @param subset (dynamic) An items array to check.
' @param msg (string) An error message.
' Default value: ""
' @return An error message.
' ----------------------------------------------------------------
function BTS__AssertArrayContainsSubset(array as Dynamic, subset as Dynamic, msg = "" as String) as String
if (TF_Utils__IsAssociativeArray(array) and TF_Utils__IsAssociativeArray(subset)) or (TF_Utils__IsArray(array) and TF_Utils__IsArray(subset))
isAA = TF_Utils__IsAssociativeArray(subset)
for each item in subset
key = invalid
value = item
if isAA
key = item
value = subset[key]
end if
if not TF_Utils__ArrayContains(array, value, key)
msg = "Array doesn't have the '" + TF_Utils__AsString(value) + "' value."
return msg
end if
end for
else
msg = "Input value is not an Array."
return msg
end if
return ""
end function
' ----------------------------------------------------------------
' Fail if the array have the item from subset.
' @param array (dynamic) A target array.
' @param subset (dynamic) A items array to check.
' @param msg (string) An error message.
' Default value: ""
' @return An error message.
' ----------------------------------------------------------------
function BTS__AssertArrayNotContainsSubset(array as Dynamic, subset as Dynamic, msg = "" as String) as String
if (TF_Utils__IsAssociativeArray(array) and TF_Utils__IsAssociativeArray(subset)) or (TF_Utils__IsArray(array) and TF_Utils__IsArray(subset))
isAA = TF_Utils__IsAssociativeArray(subset)
for each item in subset
key = invalid
value = item
if isAA
key = item
value = subset[key]
end if
if TF_Utils__ArrayContains(array, value, key)
msg = "Array has the '" + TF_Utils__AsString(value) + "' value."
return msg
end if
end for
else
msg = "Input value is not an Array."
return msg
end if
return ""
end function
' ----------------------------------------------------------------
' Fail if the array items count <> expected count
' @param array (dynamic) A target array.
' @param count (integer) An expected array items count.
' @param msg (string) An error message.
' Default value: ""
' @return An error message.
' ----------------------------------------------------------------
function BTS__AssertArrayCount(array as Dynamic, count as Dynamic, msg = "" as String) as String
if not TF_Utils__IsInteger(count)
return "Count value should be an integer."
end if
if TF_Utils__IsAssociativeArray(array) or TF_Utils__IsArray(array)
if array.Count() <> count
msg = "Array items count <> " + TF_Utils__AsString(count) + "."
return msg
end if
else
msg = "Input value is not an Array."
return msg
end if
return ""
end function
' ----------------------------------------------------------------
' Fail if the array items count = expected count.
' @param array (dynamic) A target array.
' @param count (integer) An expected array items count.
' @param msg (string) An error message.
' Default value: ""
' @return An error message.
' ----------------------------------------------------------------
function BTS__AssertArrayNotCount(array as Dynamic, count as Dynamic, msg = "" as String) as String
if not TF_Utils__IsInteger(count)
return "Count value should be an integer."
end if
if TF_Utils__IsAssociativeArray(array) or TF_Utils__IsArray(array)
if array.Count() = count
msg = "Array items count = " + TF_Utils__AsString(count) + "."
return msg
end if
else
msg = "Input value is not an Array."
return msg
end if
return ""
end function
' ----------------------------------------------------------------
' Fail if the item is not empty array or string.
' @param item (dynamic) An array or string to check.
' @param msg (string) An error message.
' Default value: ""
' @return An error message.
' ----------------------------------------------------------------
function BTS__AssertEmpty(item as Dynamic, msg = "" as String) as String
if TF_Utils__IsAssociativeArray(item) or TF_Utils__IsArray(item)
if item.Count() > 0
msg = "Array is not empty."
return msg
end if
else if TF_Utils__IsString(item)
if Len(item) <> 0
msg = "Input value is not empty."
return msg
end if
else
msg = "Input value is not an Array, AssociativeArray or String."
return msg
end if
return ""
end function
' ----------------------------------------------------------------
' Fail if the item is empty array or string.
' @param item (dynamic) An array or string to check.
' @param msg (string) An error message.
' Default value: ""
' @return An error message.
' ----------------------------------------------------------------
function BTS__AssertNotEmpty(item as Dynamic, msg = "" as String) as String
if TF_Utils__IsAssociativeArray(item) or TF_Utils__IsArray(item)
if item.Count() = 0
msg = "Array is empty."
return msg
end if
else if TF_Utils__IsString(item)
if Len(item) = 0
msg = "Input value is empty."
return msg
end if
else
msg = "Input value is not an Array, AssociativeArray or String."
return msg
end if
return ""
end function
'*****************************************************************
'* Copyright Roku 2011-2019
'* All Rights Reserved
'*****************************************************************
' Functions in this file:
' ItemGenerator
' IG_GetItem
' IG_GetAssocArray
' IG_GetArray
' IG_GetSimpleType
' IG_GetBoolean
' IG_GetInteger
' IG_GetFloat
' IG_GetString
' ----------------------------------------------------------------
' Main function to generate object according to specified scheme.
' @param scheme (object) A scheme with desired object structure. Can be
' any simple type, array of types or associative array in form
' { propertyName1 : "propertyType1"
' propertyName2 : "propertyType2"
' ...
' propertyNameN : "propertyTypeN" }
' @return An object according to specified scheme or invalid,
' if scheme is not valid.
' ----------------------------------------------------------------
function ItemGenerator(scheme as Object) as Object
this = {}
this.getItem = IG_GetItem
this.getAssocArray = IG_GetAssocArray
this.getArray = IG_GetArray
this.getSimpleType = IG_GetSimpleType
this.getInteger = IG_GetInteger
this.getFloat = IG_GetFloat
this.getString = IG_GetString
this.getBoolean = IG_GetBoolean
if not TF_Utils__IsValid(scheme)
return invalid
end if
return this.getItem(scheme)
end function
' TODO: Create IG_GetInvalidItem function with random type fields
' ----------------------------------------------------------------
' Generate object according to specified scheme.
' @param scheme (object) A scheme with desired object structure.
' Can be any simple type, array of types or associative array.
' @return An object according to specified scheme or invalid,
' if scheme is not one of simple type, array or
' associative array.
' ----------------------------------------------------------------
function IG_GetItem(scheme as Object) as Object
item = invalid
if TF_Utils__IsAssociativeArray(scheme)
item = IG_GetAssocArray(scheme)
else if TF_Utils__IsArray(scheme)
item = IG_GetArray(scheme)
else if TF_Utils__IsString(scheme)
item = IG_GetSimpleType(LCase(scheme))
end if
return item
end function
' ----------------------------------------------------------------
' Generates associative array according to specified scheme.
' @param scheme (object) An associative array with desired
' object structure in form
' { propertyName1 : "propertyType1"
' propertyName2 : "propertyType2"
' ...
' propertyNameN : "propertyTypeN" }
' @return An associative array according to specified scheme.
' ----------------------------------------------------------------
function IG_GetAssocArray(scheme as Object) as Object
item = {}
for each key in scheme
if not item.DoesExist(key)
item[key] = IG_GetItem(scheme[key])
end if
end for
return item
end function
' ----------------------------------------------------------------
' Generates array according to specified scheme.
' @param scheme (object) An array with desired object types.
' @return An array according to specified scheme.
' ----------------------------------------------------------------
function IG_GetArray(scheme as Object) as Object
item = []
for each key in scheme
item.Push(IG_GetItem(key))
end for
return item
end function
' ----------------------------------------------------------------
' Generates random value of specified type.
' @param typeStr (string) A name of desired object type.
' @return A simple type object or invalid if type is not supported.
' ----------------------------------------------------------------
function IG_GetSimpleType(typeStr as String) as Object
item = invalid
if typeStr = "integer" or typeStr = "int" or typeStr = "roint"
item = IG_GetInteger()
else if typeStr = "float" or typeStr = "rofloat"
item = IG_GetFloat()
else if typeStr = "string" or typeStr = "rostring"
item = IG_GetString(10)
else if typeStr = "boolean" or typeStr = "roboolean"
item = IG_GetBoolean()
end if
return item
end function
' ----------------------------------------------------------------
' Generates random boolean value.
' @return A random boolean value.
' ----------------------------------------------------------------
function IG_GetBoolean() as Boolean
return TF_Utils__AsBoolean(Rnd(2) \ Rnd(2))
end function
' ----------------------------------------------------------------
' Generates random integer value from 1 to specified seed value.
' @param seed (integer) A seed value for Rnd function.
' Default value: 100.
' @return A random integer value.
' ----------------------------------------------------------------
function IG_GetInteger(seed = 100 as Integer) as Integer
return Rnd(seed)
end function
' ----------------------------------------------------------------
' Generates random float value.
' @return A random float value.
' ----------------------------------------------------------------
function IG_GetFloat() as Float
return Rnd(0)
end function
' ----------------------------------------------------------------
' Generates random string with specified length.
' @param seed (integer) A string length.
' @return A random string value or empty string if seed is 0.
' ----------------------------------------------------------------
function IG_GetString(seed as Integer) as String
item = ""
if seed > 0
stringLength = Rnd(seed)
for i = 0 to stringLength
chType = Rnd(3)
if chType = 1 ' Chr(48-57) - numbers
chNumber = 47 + Rnd(10)
else if chType = 2 ' Chr(65-90) - Uppercase Letters
chNumber = 64 + Rnd(26)
else ' Chr(97-122) - Lowercase Letters
chNumber = 96 + Rnd(26)
end if
item = item + Chr(chNumber)
end for
end if
return item
end function
'*****************************************************************
'* Copyright Roku 2011-2019
'* All Rights Reserved
'*****************************************************************
' Functions in this file:
' Logger
' Logger__SetVerbosity
' Logger__SetEcho
' Logger__SetServerURL
' Logger__PrintStatistic
' Logger__SendToServer
' Logger__CreateTotalStatistic
' Logger__CreateSuiteStatistic
' Logger__CreateTestStatistic
' Logger__AppendSuiteStatistic
' Logger__AppendTestStatistic
' Logger__PrintSuiteStatistic
' Logger__PrintTestStatistic
' Logger__PrintStart
' Logger__PrintEnd
' Logger__PrintSuiteSetUp
' Logger__PrintSuiteStart
' Logger__PrintSuiteEnd
' Logger__PrintSuiteTearDown
' Logger__PrintTestSetUp
' Logger__PrintTestStart
' Logger__PrintTestEnd
' Logger__PrintTestTearDown
' ----------------------------------------------------------------
' Main function. Create Logger object.
' @return A Logger object.
' ----------------------------------------------------------------
function Logger() as Object
this = {}
this.verbosityLevel = {
basic: 0
normal: 1
verboseFailed: 2
verbose: 3
}
' Internal properties
this.verbosity = this.verbosityLevel.normal
this.echoEnabled = false
this.serverURL = ""
this.jUnitEnabled = false
' Interface
this.SetVerbosity = Logger__SetVerbosity
this.SetEcho = Logger__SetEcho
this.SetJUnit = Logger__SetJUnit
this.SetServer = Logger__SetServer
this.SetServerURL = Logger__SetServerURL ' Deprecated. Use Logger__SetServer instead.
this.PrintStatistic = Logger__PrintStatistic
this.SendToServer = Logger__SendToServer
this.CreateTotalStatistic = Logger__CreateTotalStatistic
this.CreateSuiteStatistic = Logger__CreateSuiteStatistic
this.CreateTestStatistic = Logger__CreateTestStatistic
this.AppendSuiteStatistic = Logger__AppendSuiteStatistic
this.AppendTestStatistic = Logger__AppendTestStatistic
' Internal functions
this.PrintSuiteStatistic = Logger__PrintSuiteStatistic
this.PrintTestStatistic = Logger__PrintTestStatistic
this.PrintStart = Logger__PrintStart
this.PrintEnd = Logger__PrintEnd
this.PrintSuiteSetUp = Logger__PrintSuiteSetUp
this.PrintSuiteStart = Logger__PrintSuiteStart
this.PrintSuiteEnd = Logger__PrintSuiteEnd
this.PrintSuiteTearDown = Logger__PrintSuiteTearDown
this.PrintTestSetUp = Logger__PrintTestSetUp
this.PrintTestStart = Logger__PrintTestStart
this.PrintTestEnd = Logger__PrintTestEnd
this.PrintTestTearDown = Logger__PrintTestTearDown
this.PrintJUnitFormat = Logger__PrintJUnitFormat
return this
end function
' ----------------------------------------------------------------
' Set logging verbosity parameter.
' @param verbosity (integer) A verbosity level.
' Posible values:
' 0 - basic
' 1 - normal
' 2 - verbose failed tests
' 3 - verbose
' Default level: 1
' ----------------------------------------------------------------
sub Logger__SetVerbosity(verbosity = m.verbosityLevel.normal as Integer)
if verbosity >= m.verbosityLevel.basic and verbosity <= m.verbosityLevel.verbose
m.verbosity = verbosity
end if
end sub
' ----------------------------------------------------------------
' Set logging echo parameter.
' @param enable (boolean) A echo trigger.
' Posible values: true or false
' Default value: false
' ----------------------------------------------------------------
sub Logger__SetEcho(enable = false as Boolean)
m.echoEnabled = enable
end sub