Mercurial > hg > th-libs
comparison tests.c @ 735:31bc1ed07cf5
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 07 Dec 2022 12:14:39 +0200 |
parents | 388d72f4189d |
children | e2873f764b63 |
comparison
equal
deleted
inserted
replaced
734:2ae1045f6c18 | 735:31bc1ed07cf5 |
---|---|
28 | 28 |
29 | 29 |
30 typedef struct | 30 typedef struct |
31 { | 31 { |
32 char *header; | 32 char *header; |
33 BOOL | 33 bool |
34 shown, // Has test result value been shown? | 34 shown, // Has test result value been shown? |
35 failed; // Did the test fail? (used by some tests to show extra info) | 35 failed; // Did the test fail? (used by some tests to show extra info) |
36 } test_ctx; | 36 } test_ctx; |
37 | 37 |
38 | 38 |
63 }; | 63 }; |
64 | 64 |
65 static const int arg_nopts = sizeof(arg_opts) / sizeof(arg_opts[0]); | 65 static const int arg_nopts = sizeof(arg_opts) / sizeof(arg_opts[0]); |
66 | 66 |
67 | 67 |
68 BOOL tprintv(const int level, const char *fmt, va_list ap) | 68 bool tprintv(const int level, const char *fmt, va_list ap) |
69 { | 69 { |
70 if (level <= th_verbosity) | 70 if (level <= th_verbosity) |
71 { | 71 { |
72 vfprintf(stdout, fmt, ap); | 72 vfprintf(stdout, fmt, ap); |
73 return TRUE; | 73 return true; |
74 } | 74 } |
75 else | 75 else |
76 return FALSE; | 76 return false; |
77 } | 77 } |
78 | 78 |
79 | 79 |
80 BOOL tprint(const int level, const char *fmt, ...) | 80 bool tprint(const int level, const char *fmt, ...) |
81 { | 81 { |
82 BOOL retv; | 82 bool retv; |
83 va_list ap; | 83 va_list ap; |
84 va_start(ap, fmt); | 84 va_start(ap, fmt); |
85 retv = tprintv(level, fmt, ap); | 85 retv = tprintv(level, fmt, ap); |
86 va_end(ap); | 86 va_end(ap); |
87 return retv; | 87 return retv; |
93 th_print_banner(stdout, th_prog_name, "[options]"); | 93 th_print_banner(stdout, th_prog_name, "[options]"); |
94 th_args_help(stdout, arg_opts, arg_nopts, 0, 80 - 2); | 94 th_args_help(stdout, arg_opts, arg_nopts, 0, 80 - 2); |
95 } | 95 } |
96 | 96 |
97 | 97 |
98 BOOL arg_handle_opt(const int optN, char *optArg, char *currArg) | 98 bool arg_handle_opt(const int optN, char *optArg, char *currArg) |
99 { | 99 { |
100 switch (optN) | 100 switch (optN) |
101 { | 101 { |
102 case 0: | 102 case 0: |
103 arg_show_help(); | 103 arg_show_help(); |
108 th_verbosity++; | 108 th_verbosity++; |
109 break; | 109 break; |
110 | 110 |
111 case 2: | 111 case 2: |
112 { | 112 { |
113 BOOL ret = TRUE; | 113 bool ret = true; |
114 char *pos, *pstr, *next; | 114 char *pos, *pstr, *next; |
115 pos = pstr = th_strdup(optArg); | 115 pos = pstr = th_strdup(optArg); |
116 memset(sets_enabled, 0, sizeof(sets_enabled)); | 116 memset(sets_enabled, 0, sizeof(sets_enabled)); |
117 | 117 |
118 do { | 118 do { |
126 if (val > 0 && val <= SET_MAX_TESTS) | 126 if (val > 0 && val <= SET_MAX_TESTS) |
127 sets_enabled[val - 1] = 1; | 127 sets_enabled[val - 1] = 1; |
128 else | 128 else |
129 { | 129 { |
130 THERR("Invalid test number #%d, out of range [%d .. %d]\n", val, 1, SET_MAX_TESTS); | 130 THERR("Invalid test number #%d, out of range [%d .. %d]\n", val, 1, SET_MAX_TESTS); |
131 ret = FALSE; | 131 ret = false; |
132 } | 132 } |
133 th_free(tmp); | 133 th_free(tmp); |
134 } | 134 } |
135 | 135 |
136 if (next != NULL) | 136 if (next != NULL) |
145 optFlags = atoi(optArg); | 145 optFlags = atoi(optArg); |
146 break; | 146 break; |
147 | 147 |
148 default: | 148 default: |
149 THERR("Unknown option '%s'.\n", currArg); | 149 THERR("Unknown option '%s'.\n", currArg); |
150 return FALSE; | 150 return false; |
151 } | 151 } |
152 | 152 |
153 return TRUE; | 153 return true; |
154 } | 154 } |
155 | 155 |
156 | 156 |
157 void test_end(test_ctx *ctx) | 157 void test_end(test_ctx *ctx) |
158 { | 158 { |
175 test_start_v(ctx, fmt, ap); | 175 test_start_v(ctx, fmt, ap); |
176 va_end(ap); | 176 va_end(ap); |
177 } | 177 } |
178 | 178 |
179 | 179 |
180 void test_result_msg_v(test_ctx *ctx, BOOL check, const char *fmt, va_list ap) | 180 void test_result_msg_v(test_ctx *ctx, bool check, const char *fmt, va_list ap) |
181 { | 181 { |
182 if (check) | 182 if (check) |
183 { | 183 { |
184 if (!ctx->shown && tprint(2, "%s: OK\n", ctx->header)) | 184 if (!ctx->shown && tprint(2, "%s: OK\n", ctx->header)) |
185 ctx->shown = TRUE; | 185 ctx->shown = true; |
186 | 186 |
187 tests_passed++; | 187 tests_passed++; |
188 } | 188 } |
189 else | 189 else |
190 { | 190 { |
191 if (!ctx->shown && tprint(0, "%s: FAIL\n", ctx->header)) | 191 if (!ctx->shown && tprint(0, "%s: FAIL\n", ctx->header)) |
192 ctx->shown = TRUE; | 192 ctx->shown = true; |
193 | 193 |
194 if (fmt != NULL) | 194 if (fmt != NULL) |
195 { | 195 { |
196 tprint(0, " - "); | 196 tprint(0, " - "); |
197 tprintv(0, fmt, ap); | 197 tprintv(0, fmt, ap); |
198 tprint(0, "\n"); | 198 tprint(0, "\n"); |
199 } | 199 } |
200 tests_failed++; | 200 tests_failed++; |
201 | 201 |
202 ctx->failed = TRUE; | 202 ctx->failed = true; |
203 } | 203 } |
204 } | 204 } |
205 | 205 |
206 | 206 |
207 BOOL test_result_msg(test_ctx *ctx, BOOL check, const char *fmt, ...) | 207 bool test_result_msg(test_ctx *ctx, bool check, const char *fmt, ...) |
208 { | 208 { |
209 va_list ap; | 209 va_list ap; |
210 va_start(ap, fmt); | 210 va_start(ap, fmt); |
211 test_result_msg_v(ctx, check, fmt, ap); | 211 test_result_msg_v(ctx, check, fmt, ap); |
212 va_end(ap); | 212 va_end(ap); |
213 return check; | 213 return check; |
214 } | 214 } |
215 | 215 |
216 | 216 |
217 BOOL test_result(test_ctx *ctx, BOOL check) | 217 bool test_result(test_ctx *ctx, bool check) |
218 { | 218 { |
219 test_result_msg_v(ctx, check, NULL, NULL); | 219 test_result_msg_v(ctx, check, NULL, NULL); |
220 return check; | 220 return check; |
221 } | 221 } |
222 | 222 |
249 test_result_msg(&ctx, (unsigned char) buf2[len] == SET_SENTINEL_BYTE, "buffer #2 overflow, sentinel 0x%02x", buf2[len]); | 249 test_result_msg(&ctx, (unsigned char) buf2[len] == SET_SENTINEL_BYTE, "buffer #2 overflow, sentinel 0x%02x", buf2[len]); |
250 } | 250 } |
251 | 251 |
252 if (ctx.failed && !th_printf_debug && th_verbosity >= 1) | 252 if (ctx.failed && !th_printf_debug && th_verbosity >= 1) |
253 { | 253 { |
254 th_printf_debug = TRUE; | 254 th_printf_debug = true; |
255 va_copy(tmp, ap); ret1 = th_vsnprintf(buf1, len, fmt, tmp); | 255 va_copy(tmp, ap); ret1 = th_vsnprintf(buf1, len, fmt, tmp); |
256 va_copy(tmp, ap); ret2 = vsnprintf(buf2, len, fmt, tmp); | 256 va_copy(tmp, ap); ret2 = vsnprintf(buf2, len, fmt, tmp); |
257 } | 257 } |
258 | 258 |
259 test_end(&ctx); | 259 test_end(&ctx); |
291 tprint(2, | 291 tprint(2, |
292 "-----------------------------------------------------\n"); | 292 "-----------------------------------------------------\n"); |
293 } | 293 } |
294 | 294 |
295 | 295 |
296 BOOL test_set_start(const char *str) | 296 bool test_set_start(const char *str) |
297 { | 297 { |
298 if (sets_enabled[sets_total++]) | 298 if (sets_enabled[sets_total++]) |
299 { | 299 { |
300 sets_nenabled++; | 300 sets_nenabled++; |
301 tprint(1, | 301 tprint(1, |
302 "======================================================\n" | 302 "======================================================\n" |
303 " Set #%d : %s tests\n" | 303 " Set #%d : %s tests\n" |
304 "======================================================\n", | 304 "======================================================\n", |
305 sets_total, str); | 305 sets_total, str); |
306 | 306 |
307 return TRUE; | 307 return true; |
308 } | 308 } |
309 else | 309 else |
310 return FALSE; | 310 return false; |
311 } | 311 } |
312 | 312 |
313 | 313 |
314 #define TEST_ASSERT(xcond) do { \ | 314 #define TEST_ASSERT(xcond) do { \ |
315 if (!(xcond)) \ | 315 if (!(xcond)) \ |
496 th_ioctx *fh = NULL; | 496 th_ioctx *fh = NULL; |
497 th_cfgitem_t *sect1, *sect2, *cfg = NULL, *item; | 497 th_cfgitem_t *sect1, *sect2, *cfg = NULL, *item; |
498 char *v_str1 = NULL; | 498 char *v_str1 = NULL; |
499 unsigned int v_uint1; | 499 unsigned int v_uint1; |
500 int v_int1; | 500 int v_int1; |
501 BOOL v_bool1, v_bool2; | 501 bool v_bool1, v_bool2; |
502 th_llist_t *v_str_list = NULL; | 502 th_llist_t *v_str_list = NULL; |
503 | 503 |
504 // Create v_str_list | 504 // Create v_str_list |
505 for (size_t n = 0; n < NCOUNT(test_config_strings); n++) | 505 for (size_t n = 0; n < NCOUNT(test_config_strings); n++) |
506 th_llist_append(&v_str_list, th_strdup(test_config_strings[n])); | 506 th_llist_append(&v_str_list, th_strdup(test_config_strings[n])); |
513 | 513 |
514 th_cfg_add_comment(§1, "Hex triplet value setting"); | 514 th_cfg_add_comment(§1, "Hex triplet value setting"); |
515 th_cfg_add_hexvalue(§1, "hexval", &v_uint1, 0x11223344); | 515 th_cfg_add_hexvalue(§1, "hexval", &v_uint1, 0x11223344); |
516 | 516 |
517 th_cfg_add_comment(§1, "A boolean value"); | 517 th_cfg_add_comment(§1, "A boolean value"); |
518 th_cfg_add_bool(§1, "boolval", &v_bool1, FALSE); | 518 th_cfg_add_bool(§1, "boolval", &v_bool1, false); |
519 | 519 |
520 th_cfg_add_comment(§1, "A string list"); | 520 th_cfg_add_comment(§1, "A string list"); |
521 th_cfg_add_string_list(§1, "string_list", &v_str_list); | 521 th_cfg_add_string_list(§1, "string_list", &v_str_list); |
522 | 522 |
523 th_cfg_add_section(&cfg, "general", sect1); | 523 th_cfg_add_section(&cfg, "general", sect1); |
524 | 524 |
525 sect1 = NULL; | 525 sect1 = NULL; |
526 th_cfg_add_comment(§1, "Another section"); | 526 th_cfg_add_comment(§1, "Another section"); |
527 th_cfg_add_bool(§1, "boolval", &v_bool2, TRUE); | 527 th_cfg_add_bool(§1, "boolval", &v_bool2, true); |
528 | 528 |
529 sect2 = NULL; | 529 sect2 = NULL; |
530 th_cfg_add_comment(§2, "Section inside a section"); | 530 th_cfg_add_comment(§2, "Section inside a section"); |
531 th_cfg_add_int(§2, "intval", &v_int1, 112); | 531 th_cfg_add_int(§2, "intval", &v_int1, 112); |
532 th_cfg_add_section(§1, "inside_sect", sect2); | 532 th_cfg_add_section(§1, "inside_sect", sect2); |
589 const int flags; | 589 const int flags; |
590 const th_char_t *expected[4]; | 590 const th_char_t *expected[4]; |
591 } test_regex_def2; | 591 } test_regex_def2; |
592 | 592 |
593 | 593 |
594 BOOL test_regex_list_matches(const th_char_t *str, | 594 bool test_regex_list_matches(const th_char_t *str, |
595 const th_regex_match_t *matches, | 595 const th_regex_match_t *matches, |
596 const th_char_t * const *expected, | 596 const th_char_t * const *expected, |
597 const BOOL testOnly) | 597 const bool testOnly) |
598 { | 598 { |
599 size_t nmatch = 0; | 599 size_t nmatch = 0; |
600 char *match = NULL; | 600 char *match = NULL; |
601 | 601 |
602 for (const th_regex_match_t *mt = matches; | 602 for (const th_regex_match_t *mt = matches; |
616 | 616 |
617 goto error; | 617 goto error; |
618 } | 618 } |
619 else | 619 else |
620 { | 620 { |
621 BOOL seqMatch = strcmp(match, expected[nmatch]) == 0; | 621 bool seqMatch = strcmp(match, expected[nmatch]) == 0; |
622 if (testOnly && !seqMatch) | 622 if (testOnly && !seqMatch) |
623 goto error; | 623 goto error; |
624 | 624 |
625 if (th_verbosity >= 1 || !seqMatch) | 625 if (th_verbosity >= 1 || !seqMatch) |
626 { | 626 { |
634 } | 634 } |
635 | 635 |
636 th_free(match); | 636 th_free(match); |
637 } | 637 } |
638 | 638 |
639 return TRUE; | 639 return true; |
640 | 640 |
641 error: | 641 error: |
642 th_free(match); | 642 th_free(match); |
643 return FALSE; | 643 return false; |
644 } | 644 } |
645 | 645 |
646 | 646 |
647 void test_regex_list1(const test_regex_def1 *list, const th_char_t *pattern) | 647 void test_regex_list1(const test_regex_def1 *list, const th_char_t *pattern) |
648 { | 648 { |
665 th_regex_dump(&testio, 1, expr); | 665 th_regex_dump(&testio, 1, expr); |
666 | 666 |
667 for (const test_regex_def1 *def = list; def->str != NULL; def++) | 667 for (const test_regex_def1 *def = list; def->str != NULL; def++) |
668 { | 668 { |
669 size_t nmatches; | 669 size_t nmatches; |
670 BOOL matchOK; | 670 bool matchOK; |
671 | 671 |
672 tprint(3, "\n----------------------------------------\n"); | 672 tprint(3, "\n----------------------------------------\n"); |
673 if ((res = th_regex_match(expr, def->str, | 673 if ((res = th_regex_match(expr, def->str, |
674 &nmatches, &matches, -1, def->flags)) != THERR_OK) | 674 &nmatches, &matches, -1, def->flags)) != THERR_OK) |
675 { | 675 { |
677 th_error_str(res)); | 677 th_error_str(res)); |
678 | 678 |
679 goto out; | 679 goto out; |
680 } | 680 } |
681 | 681 |
682 matchOK = test_regex_list_matches(def->str, matches, def->expected, TRUE); | 682 matchOK = test_regex_list_matches(def->str, matches, def->expected, true); |
683 if (th_verbosity < 1 && !matchOK) | 683 if (th_verbosity < 1 && !matchOK) |
684 { | 684 { |
685 tprint(0, | 685 tprint(0, |
686 "\n----------------------------------------\n" | 686 "\n----------------------------------------\n" |
687 " \"%s\" vs \"%s\" failures:\n", | 687 " \"%s\" vs \"%s\" failures:\n", |
701 th_regex_match(expr, def->str, NULL, NULL, -1, def->flags); | 701 th_regex_match(expr, def->str, NULL, NULL, -1, def->flags); |
702 th_dbg_fh = NULL; | 702 th_dbg_fh = NULL; |
703 } | 703 } |
704 #endif | 704 #endif |
705 | 705 |
706 test_regex_list_matches(def->str, matches, def->expected, FALSE); | 706 test_regex_list_matches(def->str, matches, def->expected, false); |
707 | 707 |
708 th_regex_free_matches(matches); | 708 th_regex_free_matches(matches); |
709 matches = NULL; | 709 matches = NULL; |
710 } | 710 } |
711 | 711 |
747 | 747 |
748 tprint(1, "\"%s\" vs \"%s\": matched %" PRIu_SIZE_T " time(s)\n", | 748 tprint(1, "\"%s\" vs \"%s\": matched %" PRIu_SIZE_T " time(s)\n", |
749 def->pattern, def->str, | 749 def->pattern, def->str, |
750 nmatches); | 750 nmatches); |
751 | 751 |
752 test_regex_list_matches(def->str, matches, def->expected, FALSE); | 752 test_regex_list_matches(def->str, matches, def->expected, false); |
753 | 753 |
754 out: | 754 out: |
755 th_regex_free_matches(matches); | 755 th_regex_free_matches(matches); |
756 th_regex_free(expr); | 756 th_regex_free(expr); |
757 } | 757 } |
929 // | 929 // |
930 // String matching functions | 930 // String matching functions |
931 // | 931 // |
932 if (test_set_start("String compare #1")) | 932 if (test_set_start("String compare #1")) |
933 { | 933 { |
934 TEST2(th_strcasecmp, "aSdFq", "asdfq", TRUE); | 934 TEST2(th_strcasecmp, "aSdFq", "asdfq", true); |
935 TEST2(th_strcasecmp, "aSdFq", "asFfq", FALSE); | 935 TEST2(th_strcasecmp, "aSdFq", "asFfq", false); |
936 TEST2(th_strcasecmp, "abcde", "abcde", TRUE); | 936 TEST2(th_strcasecmp, "abcde", "abcde", true); |
937 TEST2(th_strcasecmp, "öäå", "öäå", TRUE); | 937 TEST2(th_strcasecmp, "öäå", "öäå", true); |
938 TEST2(th_strcasecmp, "aöäå", "aöäå", TRUE); | 938 TEST2(th_strcasecmp, "aöäå", "aöäå", true); |
939 } | 939 } |
940 | 940 |
941 if (test_set_start("String compare #2")) | 941 if (test_set_start("String compare #2")) |
942 { | 942 { |
943 TEST3(th_strncasecmp, "aSdFq", "asFfqB", 4, FALSE); | 943 TEST3(th_strncasecmp, "aSdFq", "asFfqB", 4, false); |
944 TEST3(th_strncasecmp, "aSdFq", "asFfqQ", 2, TRUE); | 944 TEST3(th_strncasecmp, "aSdFq", "asFfqQ", 2, true); |
945 TEST3(th_strncasecmp, "aSdFq", "asDfq", 3, TRUE); | 945 TEST3(th_strncasecmp, "aSdFq", "asDfq", 3, true); |
946 TEST3(th_strncasecmp, "aSdFq", "asDfq", 2, TRUE); | 946 TEST3(th_strncasecmp, "aSdFq", "asDfq", 2, true); |
947 TEST3(th_strncasecmp, "aSdFq", "asDfq", 0, TRUE); | 947 TEST3(th_strncasecmp, "aSdFq", "asDfq", 0, true); |
948 TEST3(th_strncasecmp, "aSdFq", "QsDfq", 0, TRUE); | 948 TEST3(th_strncasecmp, "aSdFq", "QsDfq", 0, true); |
949 TEST3(th_strncasecmp, "aSdFq", "QsDfq", 1, FALSE); | 949 TEST3(th_strncasecmp, "aSdFq", "QsDfq", 1, false); |
950 TEST3(th_strncasecmp, "max=", "max=4", 4, true); | |
951 TEST3(th_strncasecmp, "max=", "max", 4, false); | |
950 } | 952 } |
951 | 953 |
952 if (test_set_start("String compare #3")) | 954 if (test_set_start("String compare #3")) |
953 { | 955 { |
954 TEST2C(th_strrcasecmp, "foo aSdFq", " asdfq", TRUE); | 956 TEST2C(th_strrcasecmp, "foo aSdFq", " asdfq", true); |
955 TEST2C(th_strrcasecmp, "aSdFq", " asdfq", FALSE); | 957 TEST2C(th_strrcasecmp, "aSdFq", " asdfq", false); |
956 TEST2C(th_strrcasecmp, "foo aSdFq baz", "asdfq", FALSE); | 958 TEST2C(th_strrcasecmp, "foo aSdFq baz", "asdfq", false); |
957 } | 959 } |
958 | 960 |
959 if (test_set_start("String matching #1")) | 961 if (test_set_start("String matching #1")) |
960 { | 962 { |
961 TEST2B(th_strmatch, "abba ABBAkukka lol", "*lol", TRUE); | 963 TEST2B(th_strmatch, "abba ABBAkukka lol", "*lol", true); |
962 TEST2B(th_strmatch, "abba ABBAkukka lol", "*lo*", TRUE); | 964 TEST2B(th_strmatch, "abba ABBAkukka lol", "*lo*", true); |
963 TEST2B(th_strmatch, "abba ABBAkukka lol", "*lo", FALSE); | 965 TEST2B(th_strmatch, "abba ABBAkukka lol", "*lo", false); |
964 TEST2B(th_strmatch, "abba ABBAkukka lol", "abba", FALSE); | 966 TEST2B(th_strmatch, "abba ABBAkukka lol", "abba", false); |
965 TEST2B(th_strmatch, "abba ABBAkukka lol", "*bba*", TRUE); | 967 TEST2B(th_strmatch, "abba ABBAkukka lol", "*bba*", true); |
966 TEST2B(th_strmatch, "abba ABBAkukka lol", "abba*", TRUE); | 968 TEST2B(th_strmatch, "abba ABBAkukka lol", "abba*", true); |
967 TEST2B(th_strmatch, "abba ABBAkukka lol", "abbak*", FALSE); | 969 TEST2B(th_strmatch, "abba ABBAkukka lol", "abbak*", false); |
968 TEST2B(th_strmatch, "abba ABBAöökukka lol", "*abbaö?", FALSE); | 970 TEST2B(th_strmatch, "abba ABBAöökukka lol", "*abbaö?", false); |
969 } | 971 } |
970 | 972 |
971 if (test_set_start("String matching #2")) | 973 if (test_set_start("String matching #2")) |
972 { | 974 { |
973 TEST2B(th_strcasematch, "abba ABBAkukka lol", "abbak*", FALSE); | 975 TEST2B(th_strcasematch, "abba ABBAkukka lol", "abbak*", false); |
974 TEST2B(th_strcasematch, "abba ABBAkukka lol", "*abbak*", TRUE); | 976 TEST2B(th_strcasematch, "abba ABBAkukka lol", "*abbak*", true); |
975 TEST2B(th_strcasematch, "abba ABBAkukka lol", "*ab?ak*", TRUE); | 977 TEST2B(th_strcasematch, "abba ABBAkukka lol", "*ab?ak*", true); |
976 TEST2B(th_strcasematch, "abba ABBAkukka lol", "*abbak?", FALSE); | 978 TEST2B(th_strcasematch, "abba ABBAkukka lol", "*abbak?", false); |
977 TEST2B(th_strcasematch, "abba ABBAkukka lol", "?bba?abba*", TRUE); | 979 TEST2B(th_strcasematch, "abba ABBAkukka lol", "?bba?abba*", true); |
978 } | 980 } |
979 | 981 |
980 // Tests that test for things that do not work correctly yet | 982 // Tests that test for things that do not work correctly yet |
981 // Unicode / multibyte UTF-8 causes problems here | 983 // Unicode / multibyte UTF-8 causes problems here |
982 if ((optFlags & TST_BROKEN) && | 984 if ((optFlags & TST_BROKEN) && |
983 test_set_start("Invalid UTF-8 handling")) | 985 test_set_start("Invalid UTF-8 handling")) |
984 { | 986 { |
985 TEST2(th_strcasecmp, "ÖÄÅ", "öäå", FALSE); // SHOULD match | 987 TEST2(th_strcasecmp, "ÖÄÅ", "öäå", false); // SHOULD match |
986 TEST3(th_strncasecmp, "Aäöå", "aöå", 2, TRUE); // should NOT match | 988 TEST3(th_strncasecmp, "Aäöå", "aöå", 2, true); // should NOT match |
987 TEST2B(th_strmatch, "öriÖRI! lol", "?ri?RI!*", FALSE); // should match | 989 TEST2B(th_strmatch, "öriÖRI! lol", "?ri?RI!*", false); // should match |
988 } | 990 } |
989 | 991 |
990 // | 992 // |
991 // printf() PRI* format specifiers, also a compile time test | 993 // printf() PRI* format specifiers, also a compile time test |
992 // | 994 // |
1004 # error Unsupported TH_ARCH value. | 1006 # error Unsupported TH_ARCH value. |
1005 #endif | 1007 #endif |
1006 | 1008 |
1007 snprintf(tmp, sizeof(tmp), "%16" PRIx_SIZE_T "h", usiz); | 1009 snprintf(tmp, sizeof(tmp), "%16" PRIx_SIZE_T "h", usiz); |
1008 #if TH_ARCH == 32 | 1010 #if TH_ARCH == 32 |
1009 TEST2(strcmp, tmp, "0000000011223344h", TRUE); | 1011 TEST2(strcmp, tmp, "0000000011223344h", true); |
1010 #else | 1012 #else |
1011 TEST2(strcmp, tmp, "aabbccdd11223344h", TRUE); | 1013 TEST2(strcmp, tmp, "aabbccdd11223344h", true); |
1012 #endif | 1014 #endif |
1013 | 1015 |
1014 snprintf(tmp, sizeof(tmp), "%08" PRIx32 "h", u32); | 1016 snprintf(tmp, sizeof(tmp), "%08" PRIx32 "h", u32); |
1015 TEST2(strcmp, tmp, "aabbccddh", TRUE); | 1017 TEST2(strcmp, tmp, "aabbccddh", true); |
1016 snprintf(tmp, sizeof(tmp), "%16" PRIx64 "h", u64); | 1018 snprintf(tmp, sizeof(tmp), "%16" PRIx64 "h", u64); |
1017 TEST2(strcmp, tmp, "aabbccdd11223344h", TRUE); | 1019 TEST2(strcmp, tmp, "aabbccdd11223344h", true); |
1018 } | 1020 } |
1019 | 1021 |
1020 // | 1022 // |
1021 // Configuration file handling | 1023 // Configuration file handling |
1022 // | 1024 // |
1030 // | 1032 // |
1031 if (test_set_start("String functions")) | 1033 if (test_set_start("String functions")) |
1032 { | 1034 { |
1033 unsigned int tmpUint; | 1035 unsigned int tmpUint; |
1034 | 1036 |
1035 TEST1(th_get_hex_triplet("0fac11", &tmpUint) == TRUE); | 1037 TEST1(th_get_hex_triplet("0fac11", &tmpUint) == true); |
1036 TEST1A("0x%06x", tmpUint, ==, 0x0fac11); | 1038 TEST1A("0x%06x", tmpUint, ==, 0x0fac11); |
1037 TEST1(th_get_hex_triplet("120fac11", &tmpUint) == TRUE); | 1039 TEST1(th_get_hex_triplet("120fac11", &tmpUint) == true); |
1038 TEST1A("0x%06x", tmpUint, ==, 0x120fac11); | 1040 TEST1A("0x%06x", tmpUint, ==, 0x120fac11); |
1039 TEST1(th_get_hex_triplet("x120fac11", &tmpUint) == FALSE); | 1041 TEST1(th_get_hex_triplet("x120fac11", &tmpUint) == false); |
1040 } | 1042 } |
1041 | 1043 |
1042 // | 1044 // |
1043 // Regular expressions | 1045 // Regular expressions |
1044 // | 1046 // |