-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNAVFoundation.Assert.axi
More file actions
1325 lines (1147 loc) · 43.7 KB
/
NAVFoundation.Assert.axi
File metadata and controls
1325 lines (1147 loc) · 43.7 KB
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
PROGRAM_NAME='NAVFoundation.Assert'
/*
_ _ _ ___ __
| \ | | ___ _ __ __ _ __ _| |_ ___ / \ \ / /
| \| |/ _ \| '__/ _` |/ _` | __/ _ \ / _ \ \ / /
| |\ | (_) | | | (_| | (_| | || __// ___ \ V /
|_| \_|\___/|_| \__, |\__,_|\__\___/_/ \_\_/
|___/
MIT License
Copyright (c) 2010-2026 Norgate AV
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#IF_NOT_DEFINED __NAV_FOUNDATION_ASSERT__
#DEFINE __NAV_FOUNDATION_ASSERT__ 'NAVFoundation.Assert'
#include 'NAVFoundation.Int64.h.axi'
#include 'NAVFoundation.ErrorLogUtils.axi'
/**
* @function NAVAssertCharEqual
* @description Test if two char values are equal and log the result
*
* @param {char[]} testName - Name of the test
* @param {char} expected - Expected value
* @param {char} actual - Actual value
*
* @returns {char} true if equal, false otherwise
*/
define_function char NAVAssertCharEqual(char testName[], char expected, char actual) {
if (expected == actual) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected: ', itoa(expected)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : ', itoa(actual)")
return false
}
}
/**
* @function NAVAssertWideCharEqual
* @description Test if two widechar values are equal and log the result
*
* @param {char[]} testName - Name of the test
* @param {widechar} expected - Expected value
* @param {widechar} actual - Actual value
*
* @returns {char} true if equal, false otherwise
*/
define_function char NAVAssertWideCharEqual(char testName[], widechar expected, widechar actual) {
if (expected == actual) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected: ', itoa(expected)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : ', itoa(actual)")
return false
}
}
/**
* @function NAVAssertIntegerEqual
* @description Test if two integer values are equal and log the result
*
* @param {char[]} testName - Name of the test
* @param {integer} expected - Expected value
* @param {integer} actual - Actual value
*
* @returns {char} true if equal, false otherwise
*/
define_function char NAVAssertIntegerEqual(char testName[], integer expected, integer actual) {
if (expected == actual) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected: ', itoa(expected)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : ', itoa(actual)")
return false
}
}
/**
* @function NAVAssertSignedIntegerEqual
* @description Test if two signed integer values are equal and log the result
*
* @param {char[]} testName - Name of the test
* @param {sinteger} expected - Expected value
* @param {sinteger} actual - Actual value
*
* @returns {char} true if equal, false otherwise
*/
define_function char NAVAssertSignedIntegerEqual(char testName[], sinteger expected, sinteger actual) {
if (expected == actual) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected: ', itoa(expected)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : ', itoa(actual)")
return false
}
}
/**
* @function NAVAssertLongEqual
* @description Test if two long values are equal and log the result
*
* @param {char[]} testName - Name of the test
* @param {long} expected - Expected value
* @param {long} actual - Actual value
*
* @returns {char} true if equal, false otherwise
*/
define_function char NAVAssertLongEqual(char testName[], long expected, long actual) {
if (expected == actual) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected: ', itoa(expected)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : ', itoa(actual)")
return false
}
}
/**
* @function NAVAssertSignedLongEqual
* @description Test if two signed long values are equal and log the result
*
* @param {char[]} testName - Name of the test
* @param {slong} expected - Expected value
* @param {slong} actual - Actual value
*
* @returns {char} true if equal, false otherwise
*/
define_function char NAVAssertSignedLongEqual(char testName[], slong expected, slong actual) {
if (expected == actual) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected: ', itoa(expected)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : ', itoa(actual)")
return false
}
}
/**
* @function NAVAssertFloatEqual
* @description Test if two float values are equal and log the result
*
* @param {char[]} testName - Name of the test
* @param {float} expected - Expected value
* @param {float} actual - Actual value
*
* @returns {char} true if equal, false otherwise
*/
define_function char NAVAssertFloatEqual(char testName[], float expected, float actual) {
if (expected == actual) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected: ', ftoa(expected)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : ', ftoa(actual)")
return false
}
}
/**
* @function NAVAssertDoubleEqual
* @description Test if two double values are equal and log the result
*
* @param {char[]} testName - Name of the test
* @param {double} expected - Expected value
* @param {double} actual - Actual value
*
* @returns {char} true if equal, false otherwise
*/
define_function char NAVAssertDoubleEqual(char testName[], double expected, double actual) {
if (expected == actual) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected: ', ftoa(expected)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : ', ftoa(actual)")
return false
}
}
/**
* @function NAVAssertBooleanEqual
* @description Test if two boolean values are equal and log the result.
* This is an alias for NAVAssertCharEqual for better readability.
*
* @param {char[]} testName - Name of the test
* @param {char} expected - Expected boolean value (0 or 1)
* @param {char} actual - Actual boolean value (0 or 1)
*
* @returns {char} true if equal, false otherwise
*/
define_function char NAVAssertBooleanEqual(char testName[], char expected, char actual) {
return NAVAssertCharEqual(testName, expected, actual)
}
/**
* @function NAVAssertStringEqual
* @description Test if two string values are equal and log the result
*
* @param {char[]} testName - Name of the test
* @param {char[]} expected - Expected string
* @param {char[]} actual - Actual string
*
* @returns {char} true if equal, false otherwise
*/
define_function char NAVAssertStringEqual(char testName[], char expected[], char actual[]) {
if (expected == actual) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected: "', expected, '"'")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : "', actual, '"'")
return false
}
}
/**
* @function NAVAssertInt64Equal
* @description Test if two Int64 values are equal and log the result
*
* @param {char[]} testName - Name of the test
* @param {_NAVInt64} expected - Expected value
* @param {_NAVInt64} actual - Actual value
*
* @returns {char} true if equal, false otherwise
*/
define_function char NAVAssertInt64Equal(char testName[], _NAVInt64 expected, _NAVInt64 actual) {
if (expected.Hi == actual.Hi && expected.Lo == actual.Lo) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected $', format('%08x', expected.Hi), format('%08x', expected.Lo)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got $', format('%08x', actual.Hi), format('%08x', actual.Lo)")
return false
}
}
/**
* @function NAVAssertStringNotEqual
* @description Test if two string values are not equal and log the result
*
* @param {char[]} testName - Name of the test
* @param {char[]} expected - Value that should not match
* @param {char[]} actual - Actual value
*
* @returns {char} true if not equal (test passed), false otherwise
*/
define_function char NAVAssertStringNotEqual(char testName[], char expected[], char actual[]) {
if (expected != actual) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected different from: "', expected, '"'")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : "', actual, '"'")
return false
}
}
/**
* @function NAVAssertIntegerNotEqual
* @description Test if two integer values are not equal and log the result
*
* @param {char[]} testName - Name of the test
* @param {integer} expected - Value that should not match
* @param {integer} actual - Actual value
*
* @returns {char} true if not equal (test passed), false otherwise
*/
define_function char NAVAssertIntegerNotEqual(char testName[], integer expected, integer actual) {
if (expected != actual) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected different from: ', itoa(expected)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : ', itoa(actual)")
return false
}
}
/**
* @function NAVAssertIntegerGreaterThan
* @description Test if actual integer value is greater than expected value and log the result
*
* @param {char[]} testName - Name of the test
* @param {integer} expected - Value that actual should be greater than
* @param {integer} actual - Actual value
*
* @returns {char} true if actual > expected (test passed), false otherwise
*/
define_function char NAVAssertIntegerGreaterThan(char testName[], integer expected, integer actual) {
if (actual > expected) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected greater than: ', itoa(expected)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : ', itoa(actual)")
return false
}
}
/**
* @function NAVAssertIntegerLessThan
* @description Test if actual integer value is less than expected value and log the result
*
* @param {char[]} testName - Name of the test
* @param {integer} expected - Value that actual should be less than
* @param {integer} actual - Actual value
*
* @returns {char} true if actual < expected (test passed), false otherwise
*/
define_function char NAVAssertIntegerLessThan(char testName[], integer expected, integer actual) {
if (actual < expected) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected less than: ', itoa(expected)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : ', itoa(actual)")
return false
}
}
/**
* @function NAVAssertIntegerGreaterThanOrEqual
* @description Test if actual integer value is greater than or equal to expected value and log the result
*
* @param {char[]} testName - Name of the test
* @param {integer} expected - Value that actual should be greater than or equal to
* @param {integer} actual - Actual value
*
* @returns {char} true if actual >= expected (test passed), false otherwise
*/
define_function char NAVAssertIntegerGreaterThanOrEqual(char testName[], integer expected, integer actual) {
if (actual >= expected) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected greater than or equal to: ', itoa(expected)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : ', itoa(actual)")
return false
}
}
/**
* @function NAVAssertIntegerLessThanOrEqual
* @description Test if actual integer value is less than or equal to expected value and log the result
*
* @param {char[]} testName - Name of the test
* @param {integer} expected - Value that actual should be less than or equal to
* @param {integer} actual - Actual value
*
* @returns {char} true if actual <= expected (test passed), false otherwise
*/
define_function char NAVAssertIntegerLessThanOrEqual(char testName[], integer expected, integer actual) {
if (actual <= expected) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected less than or equal to: ', itoa(expected)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : ', itoa(actual)")
return false
}
}
/**
* @function NAVAssertFloatNotEqual
* @description Test if two float values are not equal and log the result
*
* @param {char[]} testName - Name of the test
* @param {float} expected - Value that should not match
* @param {float} actual - Actual value
*
* @returns {char} true if not equal (test passed), false otherwise
*/
define_function char NAVAssertFloatNotEqual(char testName[], float expected, float actual) {
if (expected != actual) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected different from: ', ftoa(expected)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : ', ftoa(actual)")
return false
}
}
/**
* @function NAVAssertFloatGreaterThan
* @description Test if actual float value is greater than expected value and log the result
*
* @param {char[]} testName - Name of the test
* @param {float} expected - Value that actual should be greater than
* @param {float} actual - Actual value
*
* @returns {char} true if actual > expected (test passed), false otherwise
*/
define_function char NAVAssertFloatGreaterThan(char testName[], float expected, float actual) {
if (actual > expected) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected greater than: ', ftoa(expected)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : ', ftoa(actual)")
return false
}
}
/**
* @function NAVAssertFloatLessThan
* @description Test if actual float value is less than expected value and log the result
*
* @param {char[]} testName - Name of the test
* @param {float} expected - Value that actual should be less than
* @param {float} actual - Actual value
*
* @returns {char} true if actual < expected (test passed), false otherwise
*/
define_function char NAVAssertFloatLessThan(char testName[], float expected, float actual) {
if (actual < expected) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected less than: ', ftoa(expected)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : ', ftoa(actual)")
return false
}
}
/**
* @function NAVAssertFloatGreaterThanOrEqual
* @description Test if actual float value is greater than or equal to expected value and log the result
*
* @param {char[]} testName - Name of the test
* @param {float} expected - Value that actual should be greater than or equal to
* @param {float} actual - Actual value
*
* @returns {char} true if actual >= expected (test passed), false otherwise
*/
define_function char NAVAssertFloatGreaterThanOrEqual(char testName[], float expected, float actual) {
if (actual >= expected) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected greater than or equal to: ', ftoa(expected)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : ', ftoa(actual)")
return false
}
}
/**
* @function NAVAssertFloatLessThanOrEqual
* @description Test if actual float value is less than or equal to expected value and log the result
*
* @param {char[]} testName - Name of the test
* @param {float} expected - Value that actual should be less than or equal to
* @param {float} actual - Actual value
*
* @returns {char} true if actual <= expected (test passed), false otherwise
*/
define_function char NAVAssertFloatLessThanOrEqual(char testName[], float expected, float actual) {
if (actual <= expected) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected less than or equal to: ', ftoa(expected)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : ', ftoa(actual)")
return false
}
}
/**
* @function NAVAssertTrue
* @description Test if a condition is true
*
* @param {char[]} testName - Name of the test
* @param {char} condition - Condition to test
*
* @returns {char} true if condition is true, false otherwise
*/
define_function char NAVAssertTrue(char testName[], char condition) {
if (condition == true) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected: true'")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : false'")
return false
}
}
/**
* @function NAVAssertFalse
* @description Test if a condition is false
*
* @param {char[]} testName - Name of the test
* @param {char} condition - Condition to test
*
* @returns {char} true if condition is false, false otherwise
*/
define_function char NAVAssertFalse(char testName[], char condition) {
if (condition == false) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected: false'")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : true'")
return false
}
}
/**
* @function NAVAssertCharNotEqual
* @description Test if two char values are not equal and log the result
*
* @param {char[]} testName - Name of the test
* @param {char} expected - Value that should not match
* @param {char} actual - Actual value
*
* @returns {char} true if not equal (test passed), false otherwise
*/
define_function char NAVAssertCharNotEqual(char testName[], char expected, char actual) {
if (expected != actual) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected different from: ', itoa(expected)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : ', itoa(actual)")
return false
}
}
/**
* @function NAVAssertWideCharNotEqual
* @description Test if two widechar values are not equal and log the result
*
* @param {char[]} testName - Name of the test
* @param {widechar} expected - Value that should not match
* @param {widechar} actual - Actual value
*
* @returns {char} true if not equal (test passed), false otherwise
*/
define_function char NAVAssertWideCharNotEqual(char testName[], widechar expected, widechar actual) {
if (expected != actual) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected different from: ', itoa(expected)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : ', itoa(actual)")
return false
}
}
/**
* @function NAVAssertSignedIntegerNotEqual
* @description Test if two signed integer values are not equal and log the result
*
* @param {char[]} testName - Name of the test
* @param {sinteger} expected - Value that should not match
* @param {sinteger} actual - Actual value
*
* @returns {char} true if not equal (test passed), false otherwise
*/
define_function char NAVAssertSignedIntegerNotEqual(char testName[], sinteger expected, sinteger actual) {
if (expected != actual) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected different from: ', itoa(expected)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : ', itoa(actual)")
return false
}
}
/**
* @function NAVAssertInt64NotEqual
* @description Test if two Int64 values are not equal and log the result
*
* @param {char[]} testName - Name of the test
* @param {_NAVInt64} expected - Value that should not match
* @param {_NAVInt64} actual - Actual value
*
* @returns {char} true if not equal (test passed), false otherwise
*/
define_function char NAVAssertInt64NotEqual(char testName[], _NAVInt64 expected, _NAVInt64 actual) {
if (expected.Hi != actual.Hi || expected.Lo != actual.Lo) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected different from $', format('%08x', expected.Hi), format('%08x', expected.Lo)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got $', format('%08x', actual.Hi), format('%08x', actual.Lo)")
return false
}
}
/**
* @function NAVAssertStringContains
* @description Test if a string contains a substring
*
* @param {char[]} testName - Name of the test
* @param {char[]} searchString - String to find
* @param {char[]} stringToSearch - String to search in
*
* @returns {char} true if stringToSearch contains searchString, false otherwise
*/
define_function char NAVAssertStringContains(char testName[], char searchString[], char stringToSearch[]) {
if (find_string(stringToSearch, searchString, 1) > 0) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected to find: "', searchString, '"'")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'In string : "', stringToSearch, '"'")
return false
}
}
/**
* @function NAVAssertStringStartsWith
* @description Test if a string starts with the specified prefix
*
* @param {char[]} testName - Name of the test
* @param {char[]} prefix - Expected prefix
* @param {char[]} str - String to test
*
* @returns {char} true if str starts with prefix, false otherwise
*/
define_function char NAVAssertStringStartsWith(char testName[], char prefix[], char str[]) {
if (length_array(prefix) <= length_array(str) &&
left_string(str, length_array(prefix)) == prefix) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected to start with: "', prefix, '"'")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got string : "', str, '"'")
return false
}
}
/**
* @function NAVAssertStringEndsWith
* @description Test if a string ends with the specified suffix
*
* @param {char[]} testName - Name of the test
* @param {char[]} suffix - Expected suffix
* @param {char[]} str - String to test
*
* @returns {char} true if str ends with suffix, false otherwise
*/
define_function char NAVAssertStringEndsWith(char testName[], char suffix[], char str[]) {
if (length_array(suffix) <= length_array(str) &&
right_string(str, length_array(suffix)) == suffix) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected to end with: "', suffix, '"'")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got string : "', str, '"'")
return false
}
}
/**
* @function NAVAssertFloatAlmostEqual
* @description Test if two float values are almost equal within a given epsilon
*
* @param {char[]} testName - Name of the test
* @param {float} expected - Expected value
* @param {float} actual - Actual value
* @param {float} epsilon - Maximum allowed difference
*
* @returns {char} true if |expected-actual| <= epsilon, false otherwise
*/
define_function char NAVAssertFloatAlmostEqual(char testName[], float expected, float actual, float epsilon) {
stack_var float diff
// Calculate absolute difference
diff = expected - actual
if (diff < 0) {
diff = -diff
}
if (diff <= epsilon) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected: ', ftoa(expected), ' ±', ftoa(epsilon)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got : ', ftoa(actual), ' (diff: ', ftoa(diff), ')'")
return false
}
}
/**
* @function NAVAssertStringArrayEqual
* @description Test if two string arrays are equal (same length and all elements match) and log the result
*
* @param {char[]} testName - Name of the test
* @param {char[][]} expected - Expected string array
* @param {char[][]} actual - Actual string array
*
* @returns {char} true if arrays are equal, false otherwise
*/
define_function char NAVAssertStringArrayEqual(char testName[], char expected[][], char actual[][]) {
stack_var integer expectedCount
stack_var integer actualCount
stack_var integer i
expectedCount = length_array(expected)
actualCount = length_array(actual)
if (expectedCount != actualCount) {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected array length: ', itoa(expectedCount)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got array length : ', itoa(actualCount)")
return false
}
for (i = 1; i <= expectedCount; i++) {
if (expected[i] != actual[i]) {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Mismatch at index ', itoa(i), ':'")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "' Expected: "', expected[i], '"'")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "' Got : "', actual[i], '"'")
return false
}
}
return true
}
/**
* @function NAVAssertStringArrayNotEqual
* @description Test if two string arrays are not equal (different lengths or any element differs) and log the result
*
* @param {char[]} testName - Name of the test
* @param {char[][]} expected - Expected string array (should differ from actual)
* @param {char[][]} actual - Actual string array
*
* @returns {char} true if arrays are different, false if they are equal
*/
define_function char NAVAssertStringArrayNotEqual(char testName[], char expected[][], char actual[][]) {
stack_var integer expectedCount
stack_var integer actualCount
stack_var integer i
expectedCount = length_array(expected)
actualCount = length_array(actual)
if (expectedCount != actualCount) {
return true
}
for (i = 1; i <= expectedCount; i++) {
if (expected[i] != actual[i]) {
return true
}
}
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected arrays to be different but they are equal.'")
return false
}
/**
* @function NAVAssertStringArrayContains
* @description Test if a string array contains a specific string and log the result
*
* @param {char[]} testName - Name of the test
* @param {char[]} searchString - String to search for in the array
* @param {char[][]} stringArray - String array to search in
*
* @returns {char} true if string is found in array, false otherwise
*/
define_function char NAVAssertStringArrayContains(char testName[], char searchString[], char stringArray[][]) {
stack_var integer i
stack_var integer arrayLength
arrayLength = length_array(stringArray)
for (i = 1; i <= arrayLength; i++) {
if (stringArray[i] == searchString) {
return true
}
}
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected to find: "', searchString, '"'")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'In string array but it was not found.'")
return false
}
/**
* @function NAVAssertStringArrayNotContains
* @description Test if a string array does not contain a specific string and log the result
*
* @param {char[]} testName - Name of the test
* @param {char[]} searchString - String that should not be in the array
* @param {char[][]} stringArray - String array to check
*
* @returns {char} true if string is not found in array, false if it is found
*/
define_function char NAVAssertStringArrayNotContains(char testName[], char searchString[], char stringArray[][]) {
stack_var integer i
stack_var integer arrayLength
arrayLength = length_array(stringArray)
for (i = 1; i <= arrayLength; i++) {
if (stringArray[i] == searchString) {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected not to find: "', searchString, '"'")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'But it was found in the string array.'")
return false
}
}
return true
}
/**
* @function NAVAssertStringArrayLengthEqual
* @description Test if a string array has the expected length and log the result
*
* @param {char[]} testName - Name of the test
* @param {char[][]} stringArray - String array to check
* @param {integer} expectedLength - Expected array length
*
* @returns {char} true if array length matches expected, false otherwise
*/
define_function char NAVAssertStringArrayLengthEqual(char testName[], char stringArray[][], integer expectedLength) {
stack_var integer actualLength
actualLength = length_array(stringArray)
if (actualLength == expectedLength) {
return true
} else {
if (length_array(testName) > 0) {
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "testName")
}
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Expected array length: ', itoa(expectedLength)")
NAVErrorLog(NAV_LOG_LEVEL_DEBUG, "'Got array length : ', itoa(actualLength)")
return false
}
}
/**
* @function NAVAssertStringArrayLengthNotEqual
* @description Test if a string array does not have the specified length and log the result
*
* @param {char[]} testName - Name of the test