Mercurial > hg > th-libs
annotate tests.c @ 724:388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 18 Oct 2021 01:56:09 +0300 |
parents | 3ea040bb0dca |
children | 31bc1ed07cf5 |
rev | line source |
---|---|
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 #include "th_types.h" |
274
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
2 #include "th_args.h" |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 #include "th_util.h" |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 #include "th_string.h" |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 #include "th_crypto.h" |
651 | 6 #include "th_ioctx.h" |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
7 #include "th_config.h" |
605
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
8 #include "th_regex.h" |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 |
364 | 10 |
11 #define SET_BUF_SIZE 128 | |
365 | 12 #define SET_BUF_SIZE_2 ((SET_BUF_SIZE) + 32) |
364 | 13 #define SET_MAX_TESTS 64 |
14 #define SET_SENTINEL_BYTE 0x0e5 | |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 |
291 | 16 |
552 | 17 #define NCOUNT(xxx) (sizeof(xxx) / sizeof(xxx[0])) |
18 | |
19 | |
365 | 20 enum |
21 { | |
22 TST_SUPERFLUOUS = 0x0001, | |
23 TST_CORNERCASE = 0x0002, | |
24 TST_OVERFLOW = 0x0004, | |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
25 TST_BROKEN = 0x1000, |
365 | 26 TST_ALL = 0xffff, |
27 }; | |
28 | |
29 | |
303 | 30 typedef struct |
31 { | |
502
ebf89497305a
Remove some unused functionality for simplification.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
32 char *header; |
551 | 33 BOOL |
34 shown, // Has test result value been shown? | |
35 failed; // Did the test fail? (used by some tests to show extra info) | |
303 | 36 } test_ctx; |
37 | |
38 | |
551 | 39 // Global variables |
40 int tests_failed, // Total number of tests failed | |
41 tests_passed, // Total number of tests passed | |
42 tests_total, // Total number of tests RUN | |
43 sets_total, // Number of test sets | |
44 sets_nenabled; // Number of test sets enabled | |
45 | |
365 | 46 int sets_enabled[SET_MAX_TESTS]; |
259 | 47 |
551 | 48 char buf1[SET_BUF_SIZE_2], |
49 buf2[SET_BUF_SIZE_2]; | |
50 | |
365 | 51 int optFlags = TST_ALL; |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 |
651 | 53 th_ioctx testio; |
54 | |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 |
274
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
56 // Define option arguments |
380
ac10155d2b4a
Rename th_optarg_t to t_optarg. API break.
Matti Hamalainen <ccr@tnsp.org>
parents:
366
diff
changeset
|
57 static const th_optarg arg_opts[] = |
274
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
58 { |
587
98812eb78d8e
Add new compile-time optional th_optarg struct field o_arg for specifying the option argument description/name. TH_USE_OPT_ARG must be defined at compile time.
Matti Hamalainen <ccr@tnsp.org>
parents:
563
diff
changeset
|
59 { 0, '?', "help" , NULL, "Show this help", OPT_NONE }, |
98812eb78d8e
Add new compile-time optional th_optarg struct field o_arg for specifying the option argument description/name. TH_USE_OPT_ARG must be defined at compile time.
Matti Hamalainen <ccr@tnsp.org>
parents:
563
diff
changeset
|
60 { 1, 'v', "verbose" , NULL, "Be more verbose", OPT_NONE }, |
602 | 61 { 2, 's', "sets" , "sets", "Perform test sets -s <set>[,<set2>..]", OPT_ARGREQ }, |
62 { 3, 't', "tests" , "tests", "Perform only tests (see below)", OPT_ARGREQ }, | |
274
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
63 }; |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
64 |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
65 static const int arg_nopts = sizeof(arg_opts) / sizeof(arg_opts[0]); |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
66 |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
67 |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
68 BOOL tprintv(const int level, const char *fmt, va_list ap) |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
69 { |
469
fe5b803ae449
Rename the global variable th_verbosityLevel to th_verbosity.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
70 if (level <= th_verbosity) |
363 | 71 { |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
72 vfprintf(stdout, fmt, ap); |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
73 return TRUE; |
363 | 74 } |
75 else | |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
76 return FALSE; |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
77 } |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
78 |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
79 |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
80 BOOL tprint(const int level, const char *fmt, ...) |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
81 { |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
82 BOOL retv; |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
83 va_list ap; |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
84 va_start(ap, fmt); |
363 | 85 retv = tprintv(level, fmt, ap); |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
86 va_end(ap); |
363 | 87 return retv; |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
88 } |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
89 |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
90 |
274
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
91 void arg_show_help(void) |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
92 { |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
93 th_print_banner(stdout, th_prog_name, "[options]"); |
592
4fd6ee473d1b
Fix tests.c after the addition of the width argument to th_args_help().
Matti Hamalainen <ccr@tnsp.org>
parents:
587
diff
changeset
|
94 th_args_help(stdout, arg_opts, arg_nopts, 0, 80 - 2); |
274
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
95 } |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
96 |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
97 |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
98 BOOL arg_handle_opt(const int optN, char *optArg, char *currArg) |
274
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
99 { |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
100 switch (optN) |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
101 { |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
102 case 0: |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
103 arg_show_help(); |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
104 exit(0); |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
105 break; |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
106 |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
107 case 1: |
469
fe5b803ae449
Rename the global variable th_verbosityLevel to th_verbosity.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
108 th_verbosity++; |
274
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
109 break; |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
110 |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
111 case 2: |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
112 { |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
113 BOOL ret = TRUE; |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
114 char *pos, *pstr, *next; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
115 pos = pstr = th_strdup(optArg); |
365 | 116 memset(sets_enabled, 0, sizeof(sets_enabled)); |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
117 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
118 do { |
552 | 119 if ((next = strchr(pos, ',')) != NULL) |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
120 *next = 0; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
121 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
122 char *tmp = th_strdup_trim(pos, TH_TRIM_BOTH); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
123 if (tmp != NULL) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
124 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
125 int val = atoi(tmp); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
126 if (val > 0 && val <= SET_MAX_TESTS) |
365 | 127 sets_enabled[val - 1] = 1; |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
128 else |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
129 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
130 THERR("Invalid test number #%d, out of range [%d .. %d]\n", val, 1, SET_MAX_TESTS); |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
131 ret = FALSE; |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
132 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
133 th_free(tmp); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
134 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
135 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
136 if (next != NULL) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
137 pos = next + 1; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
138 } while (next != NULL); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
139 th_free(pstr); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
140 return ret; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
141 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
142 break; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
143 |
365 | 144 case 3: |
366
21bbb2dc4fac
Actually parse the -t option argument.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
145 optFlags = atoi(optArg); |
365 | 146 break; |
147 | |
274
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
148 default: |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
149 THERR("Unknown option '%s'.\n", currArg); |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
150 return FALSE; |
274
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
151 } |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
152 |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
153 return TRUE; |
274
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
154 } |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
155 |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
156 |
342
09c2f6abf694
Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
157 void test_end(test_ctx *ctx) |
09c2f6abf694
Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
158 { |
09c2f6abf694
Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
159 th_free_r(&ctx->header); |
09c2f6abf694
Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
160 } |
09c2f6abf694
Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
161 |
09c2f6abf694
Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
162 |
303 | 163 void test_start_v(test_ctx *ctx, const char *fmt, va_list ap) |
259 | 164 { |
165 tests_total++; | |
502
ebf89497305a
Remove some unused functionality for simplification.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
166 memset(ctx, 0, sizeof(test_ctx)); |
303 | 167 ctx->header = th_strdup_vprintf(fmt, ap); |
259 | 168 } |
169 | |
170 | |
303 | 171 void test_start(test_ctx *ctx, const char *fmt, ...) |
259 | 172 { |
173 va_list ap; | |
174 va_start(ap, fmt); | |
303 | 175 test_start_v(ctx, fmt, ap); |
259 | 176 va_end(ap); |
177 } | |
178 | |
179 | |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
180 void test_result_msg_v(test_ctx *ctx, BOOL check, const char *fmt, va_list ap) |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 { |
259 | 182 if (check) |
183 { | |
363 | 184 if (!ctx->shown && tprint(2, "%s: OK\n", ctx->header)) |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
185 ctx->shown = TRUE; |
363 | 186 |
259 | 187 tests_passed++; |
188 } | |
189 else | |
190 { | |
363 | 191 if (!ctx->shown && tprint(0, "%s: FAIL\n", ctx->header)) |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
192 ctx->shown = TRUE; |
363 | 193 |
259 | 194 if (fmt != NULL) |
263 | 195 { |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
196 tprint(0, " - "); |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
197 tprintv(0, fmt, ap); |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
198 tprint(0, "\n"); |
263 | 199 } |
259 | 200 tests_failed++; |
529
c44ebf5b08fd
Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
527
diff
changeset
|
201 |
c44ebf5b08fd
Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
527
diff
changeset
|
202 ctx->failed = TRUE; |
259 | 203 } |
204 } | |
205 | |
206 | |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
207 BOOL test_result_msg(test_ctx *ctx, BOOL check, const char *fmt, ...) |
259 | 208 { |
209 va_list ap; | |
210 va_start(ap, fmt); | |
303 | 211 test_result_msg_v(ctx, check, fmt, ap); |
259 | 212 va_end(ap); |
305
5afd918cbd79
Have a return value for test result functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
304
diff
changeset
|
213 return check; |
259 | 214 } |
215 | |
216 | |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
217 BOOL test_result(test_ctx *ctx, BOOL check) |
259 | 218 { |
303 | 219 test_result_msg_v(ctx, check, NULL, NULL); |
305
5afd918cbd79
Have a return value for test result functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
304
diff
changeset
|
220 return check; |
259 | 221 } |
222 | |
223 | |
319 | 224 void test_snprintf_do(size_t len, const char *msg, const char *fmt, va_list ap) |
259 | 225 { |
226 int ret1, ret2; | |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
227 va_list tmp; |
303 | 228 test_ctx ctx; |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
229 |
529
c44ebf5b08fd
Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
527
diff
changeset
|
230 // Setup printf debug value |
c44ebf5b08fd
Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
527
diff
changeset
|
231 th_printf_debug = th_verbosity >= 3; |
c44ebf5b08fd
Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
527
diff
changeset
|
232 th_printf_debug_prefix = " - "; |
c44ebf5b08fd
Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
527
diff
changeset
|
233 |
263 | 234 // Test basic *printf() functionality |
530
94d4130cc29c
Clarify printf test output slightly.
Matti Hamalainen <ccr@tnsp.org>
parents:
529
diff
changeset
|
235 test_start(&ctx, "th_vsnprintf(buflen=%" PRIu_SIZE_T ", \"%s\", %s)", len, fmt, msg); |
259 | 236 |
365 | 237 memset(buf1, SET_SENTINEL_BYTE, SET_BUF_SIZE_2); buf1[SET_BUF_SIZE_2-1] = 0; |
238 memset(buf2, SET_SENTINEL_BYTE, SET_BUF_SIZE_2); buf2[SET_BUF_SIZE_2-1] = 0; | |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
239 |
339
46a0fab6ca1f
Fix snprintf() test running.
Matti Hamalainen <ccr@tnsp.org>
parents:
338
diff
changeset
|
240 va_copy(tmp, ap); ret1 = th_vsnprintf(buf1, len, fmt, tmp); |
46a0fab6ca1f
Fix snprintf() test running.
Matti Hamalainen <ccr@tnsp.org>
parents:
338
diff
changeset
|
241 va_copy(tmp, ap); ret2 = vsnprintf(buf2, len, fmt, tmp); |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
242 |
303 | 243 test_result_msg(&ctx, ret1 == ret2, "retval mismatch %d [th] != %d [libc]", ret1, ret2); |
244 test_result_msg(&ctx, strcmp(buf1, buf2) == 0, "result mismatch '%s' [th] != '%s' [libc]", buf1, buf2); | |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
245 |
365 | 246 if (optFlags & TST_OVERFLOW) |
247 { | |
303 | 248 test_result_msg(&ctx, (unsigned char) buf1[len] == SET_SENTINEL_BYTE, "buffer #1 overflow, sentinel 0x%02x", buf1[len]); |
249 test_result_msg(&ctx, (unsigned char) buf2[len] == SET_SENTINEL_BYTE, "buffer #2 overflow, sentinel 0x%02x", buf2[len]); | |
365 | 250 } |
261 | 251 |
529
c44ebf5b08fd
Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
527
diff
changeset
|
252 if (ctx.failed && !th_printf_debug && th_verbosity >= 1) |
c44ebf5b08fd
Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
527
diff
changeset
|
253 { |
c44ebf5b08fd
Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
527
diff
changeset
|
254 th_printf_debug = TRUE; |
c44ebf5b08fd
Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
527
diff
changeset
|
255 va_copy(tmp, ap); ret1 = th_vsnprintf(buf1, len, fmt, tmp); |
c44ebf5b08fd
Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
527
diff
changeset
|
256 va_copy(tmp, ap); ret2 = vsnprintf(buf2, len, fmt, tmp); |
c44ebf5b08fd
Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
527
diff
changeset
|
257 } |
c44ebf5b08fd
Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
527
diff
changeset
|
258 |
342
09c2f6abf694
Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
259 test_end(&ctx); |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
260 } |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
261 |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
262 |
319 | 263 void test_snprintf(const char *msg, const char *fmt, ...) |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
264 { |
362 | 265 test_ctx ctx; |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
266 va_list ap, tmp; |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
267 va_start(ap, fmt); |
365 | 268 |
269 if (optFlags & TST_CORNERCASE) | |
270 { | |
271 va_copy(tmp, ap); test_snprintf_do(0, msg, fmt, tmp); | |
272 va_copy(tmp, ap); test_snprintf_do(1, msg, fmt, tmp); | |
273 va_copy(tmp, ap); test_snprintf_do(2, msg, fmt, tmp); | |
274 va_copy(tmp, ap); test_snprintf_do(16, msg, fmt, tmp); | |
275 } | |
276 | |
319 | 277 va_copy(tmp, ap); test_snprintf_do(SET_BUF_SIZE, msg, fmt, tmp); |
362 | 278 |
279 // Test th_strdup_vprintf() | |
365 | 280 if (optFlags & TST_SUPERFLUOUS) |
281 { | |
282 test_start(&ctx, "th_strdup_vprintf('%s')", fmt); | |
283 va_copy(tmp, ap); | |
284 char *str = th_strdup_vprintf(fmt, tmp); | |
285 test_result_msg(&ctx, str != NULL, "result NULL"); | |
286 th_free(str); | |
287 test_end(&ctx); | |
288 } | |
362 | 289 |
441
2991e6b52d95
Get rid of trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
412
diff
changeset
|
290 va_end(ap); |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
291 tprint(2, |
291 | 292 "-----------------------------------------------------\n"); |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
293 } |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
294 |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
295 |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
296 BOOL test_set_start(const char *str) |
264
9b6fd2953d8c
Add test header printing function.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
297 { |
365 | 298 if (sets_enabled[sets_total++]) |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
299 { |
365 | 300 sets_nenabled++; |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
301 tprint(1, |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
302 "======================================================\n" |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
303 " Set #%d : %s tests\n" |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
304 "======================================================\n", |
365 | 305 sets_total, str); |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
306 |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
307 return TRUE; |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
308 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
309 else |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
310 return FALSE; |
264
9b6fd2953d8c
Add test header printing function.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
311 } |
9b6fd2953d8c
Add test header printing function.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
312 |
9b6fd2953d8c
Add test header printing function.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
313 |
603
be957142ab37
Add TEST_ASSERT() and test sizes of some types before doing anything else.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
314 #define TEST_ASSERT(xcond) do { \ |
be957142ab37
Add TEST_ASSERT() and test sizes of some types before doing anything else.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
315 if (!(xcond)) \ |
be957142ab37
Add TEST_ASSERT() and test sizes of some types before doing anything else.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
316 { \ |
be957142ab37
Add TEST_ASSERT() and test sizes of some types before doing anything else.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
317 THERR("Assertion '" # xcond "' failed.\n"); \ |
be957142ab37
Add TEST_ASSERT() and test sizes of some types before doing anything else.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
318 return -1; \ |
be957142ab37
Add TEST_ASSERT() and test sizes of some types before doing anything else.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
319 } \ |
be957142ab37
Add TEST_ASSERT() and test sizes of some types before doing anything else.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
320 } while (0) |
be957142ab37
Add TEST_ASSERT() and test sizes of some types before doing anything else.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
321 |
524
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
322 #define TEST1(fun) do { \ |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
323 test_ctx ctx; \ |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
324 test_start(&ctx, # fun ); \ |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
325 test_result(&ctx, fun); \ |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
326 test_end(&ctx); \ |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
327 } while (0) |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
328 |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
329 #define TEST1A(fmt, fun, fcmp, fres) do { \ |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
330 test_ctx ctx; \ |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
331 test_start(&ctx, #fun " " #fcmp " " fmt " (" fmt ")", fres, fun); \ |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
332 test_result(&ctx, fun fcmp fres ); \ |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
333 test_end(&ctx); \ |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
334 } while (0) |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
335 |
263 | 336 #define TEST2(fun, str1, str2, ret) do { \ |
502
ebf89497305a
Remove some unused functionality for simplification.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
337 test_ctx ctx; \ |
303 | 338 test_start(&ctx, # fun "('%s', '%s')", str1, str2); \ |
339 test_result(&ctx, ( fun (str1, str2) == 0) == ret); \ | |
342
09c2f6abf694
Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
340 test_end(&ctx); \ |
263 | 341 } while (0) |
342 | |
266 | 343 #define TEST2B(fun, str1, str2, ret) do { \ |
502
ebf89497305a
Remove some unused functionality for simplification.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
344 test_ctx ctx; \ |
303 | 345 test_start(&ctx, # fun "('%s', '%s')", str1, str2); \ |
346 test_result(&ctx, fun (str1, str2) == ret); \ | |
342
09c2f6abf694
Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
347 test_end(&ctx); \ |
266 | 348 } while (0) |
349 | |
465 | 350 #define TEST2C(fun, str1, str2, ret) do { \ |
502
ebf89497305a
Remove some unused functionality for simplification.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
351 test_ctx ctx; \ |
465 | 352 test_start(&ctx, # fun "('%s', '%s')", str1, str2); \ |
353 test_result(&ctx, (fun (str1, str2) != NULL) == ret); \ | |
354 test_end(&ctx); \ | |
355 } while (0) | |
356 | |
263 | 357 #define TEST3(fun, str1, str2, len, ret) do { \ |
502
ebf89497305a
Remove some unused functionality for simplification.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
358 test_ctx ctx; \ |
303 | 359 test_start(&ctx, # fun "('%s', '%s', %d)", str1, str2, len); \ |
360 test_result(&ctx, ( fun (str1, str2, len) == 0) == ret); \ | |
342
09c2f6abf694
Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
361 test_end(&ctx); \ |
263 | 362 } while (0) |
363 | |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
364 |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
365 void test_config_values(th_cfgitem_t *cfg) |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
366 { |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
367 th_cfgitem_t *item; |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
368 int nsubtest = 0; |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
369 test_ctx ctx; |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
370 |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
371 test_start(&ctx, "Test configuration value search #%d", ++nsubtest); |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
372 test_result(&ctx, (item = th_cfg_find(cfg, "inside_sect", "intval", -1)) != NULL && *item->v.val_int == 112); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
373 test_end(&ctx); |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
374 test_start(&ctx, "Test configuration value search #%d", ++nsubtest); |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
375 test_result(&ctx, (item = th_cfg_find(cfg, "another_sect", "boolval", -1)) != NULL && *item->v.val_bool); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
376 test_end(&ctx); |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
377 test_start(&ctx, "Test configuration value search #%d", ++nsubtest); |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
378 test_result(&ctx, th_cfg_find(cfg, "no_match", NULL, -1) == NULL); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
379 test_end(&ctx); |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
380 test_start(&ctx, "Test configuration value search #%d", ++nsubtest); |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
381 test_result(&ctx, th_cfg_find(cfg, NULL, "no_match", -1) == NULL); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
382 test_end(&ctx); |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
383 test_start(&ctx, "Test configuration value search #%d", ++nsubtest); |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
384 test_result(&ctx, (item = th_cfg_find(cfg, NULL, "hexval", -1)) != NULL && *item->v.val_uint == 0x11223344); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
385 test_end(&ctx); |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
386 test_start(&ctx, "Test configuration value search #%d", ++nsubtest); |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
387 test_result(&ctx, (item = th_cfg_find(cfg, NULL, "a_string_setting", -1)) != NULL && strcmp(*item->v.val_str, "v_str1") == 0); |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
388 test_end(&ctx); |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
389 } |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
390 |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
391 |
709
905d30063e45
Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents:
703
diff
changeset
|
392 void test_config_free(th_cfgitem_t *node) |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
393 { |
709
905d30063e45
Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents:
703
diff
changeset
|
394 switch (node->type) |
905d30063e45
Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents:
703
diff
changeset
|
395 { |
905d30063e45
Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents:
703
diff
changeset
|
396 case ITEM_STRING: |
905d30063e45
Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents:
703
diff
changeset
|
397 th_free(*(node->v.val_str)); |
905d30063e45
Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents:
703
diff
changeset
|
398 break; |
905d30063e45
Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents:
703
diff
changeset
|
399 |
905d30063e45
Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents:
703
diff
changeset
|
400 case ITEM_STRING_LIST: |
905d30063e45
Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents:
703
diff
changeset
|
401 break; |
905d30063e45
Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents:
703
diff
changeset
|
402 } |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
403 } |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
404 |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
405 |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
406 void test_ioctx_error(th_ioctx *fh, const int val, const char *msg) |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
407 { |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
408 (void) fh; |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
409 (void) val; |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
410 tprint(0, "IOCTX ERROR: %s", msg); |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
411 } |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
412 |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
413 |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
414 void test_ioctx_msg(th_ioctx *fh, const int val, const char *msg) |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
415 { |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
416 (void) fh; |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
417 (void) val; |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
418 tprint(1, "IOCTX MSG: %s", msg); |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
419 } |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
420 |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
421 |
552 | 422 int test_config_strcmp(const void *v1, const void *v2) |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
423 { |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
424 return strcmp((const char *) v1, (const char *) v2); |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
425 } |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
426 |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
427 |
552 | 428 static const char *test_config_strings[] = |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
429 { |
521
77495c646208
Fix parsing and writing of strings with simple escape sequences in config files.
Matti Hamalainen <ccr@tnsp.org>
parents:
517
diff
changeset
|
430 "zoo", "foo", "b\"ar", |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
431 }; |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
432 |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
433 |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
434 void test_config_read(th_cfgitem_t *cfg, const char *filename) |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
435 { |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
436 int nsubtest; |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
437 th_ioctx *fh = NULL; |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
438 test_ctx ctx; |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
439 th_cfgitem_t *item; |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
440 |
517
80185b9901ba
Be more informative about which config file we are trying to read while testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
441 tprint(1, "Reading configuration from '%s'.\n", filename); |
80185b9901ba
Be more informative about which config file we are trying to read while testing.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
442 |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
443 // Attempt to read the previously written file |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
444 if (th_io_fopen(&fh, &th_stdio_io_ops, filename, "r") != THERR_OK) |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
445 { |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
446 int err = th_get_error(); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
447 THERR("Could not open configuration file '%s', %d: %s\n", |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
448 filename, err, th_error_str(err)); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
449 goto out; |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
450 } |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
451 |
516 | 452 th_io_set_handlers(fh, test_ioctx_error, test_ioctx_msg); |
453 | |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
454 th_cfg_read(fh, cfg); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
455 |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
456 // Test read values against expected values |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
457 test_config_values(cfg); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
458 |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
459 // Additional tests |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
460 item = th_cfg_find(cfg, NULL, "string_list", -1); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
461 test_result(&ctx, item != NULL); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
462 if (item != NULL) |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
463 { |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
464 static const char *nostr = "not to be found"; |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
465 th_llist_t **plist = (th_llist_t **) item->v.list; |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
466 |
552 | 467 for (nsubtest = 0; nsubtest < (int) NCOUNT(test_config_strings); nsubtest++) |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
468 { |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
469 test_start(&ctx, "Test configuration string list values #%d: '%s'", |
552 | 470 nsubtest + 1, test_config_strings[nsubtest]); |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
471 |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
472 test_result(&ctx, |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
473 th_llist_find_func(*plist, |
552 | 474 test_config_strings[nsubtest], test_config_strcmp) != NULL); |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
475 test_end(&ctx); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
476 } |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
477 |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
478 test_start(&ctx, "Test configuration string list values #%d: '%s'", |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
479 ++nsubtest, nostr); |
552 | 480 test_result(&ctx, th_llist_find_func(*plist, nostr, test_config_strcmp) == NULL); |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
481 test_end(&ctx); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
482 |
709
905d30063e45
Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents:
703
diff
changeset
|
483 th_llist_free_func_data(*plist, th_free); |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
484 *plist = NULL; |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
485 } |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
486 |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
487 out: |
650
24cbab6e88c6
Remove th_io_free(), merge the functionality to th_io_close(). Add flags
Matti Hamalainen <ccr@tnsp.org>
parents:
649
diff
changeset
|
488 th_io_close(fh); |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
489 } |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
490 |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
491 |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
492 void test_config(void) |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
493 { |
513
e412a39e2b7a
Add another test for configuration parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
512
diff
changeset
|
494 static const char *filename = "cfg.temp"; |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
495 test_ctx ctx; |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
496 th_ioctx *fh = NULL; |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
497 th_cfgitem_t *sect1, *sect2, *cfg = NULL, *item; |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
498 char *v_str1 = NULL; |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
499 unsigned int v_uint1; |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
500 int v_int1; |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
501 BOOL v_bool1, v_bool2; |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
502 th_llist_t *v_str_list = NULL; |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
503 |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
504 // Create v_str_list |
552 | 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])); | |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
507 |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
508 // Create the configuration structure |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
509 tprint(2, "Creating configuration structure\n"); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
510 sect1 = NULL; |
509
b506bff0a7ab
Some cleanup work and refactoring on the configuration file parser and writer.
Matti Hamalainen <ccr@tnsp.org>
parents:
508
diff
changeset
|
511 th_cfg_add_comment(§1, "A comment that\nspans multiple\nlines automatically"); |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
512 th_cfg_add_string(§1, "a_string_setting", &v_str1, "v_str1"); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
513 |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
514 th_cfg_add_comment(§1, "Hex triplet value setting"); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
515 th_cfg_add_hexvalue(§1, "hexval", &v_uint1, 0x11223344); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
516 |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
517 th_cfg_add_comment(§1, "A boolean value"); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
518 th_cfg_add_bool(§1, "boolval", &v_bool1, FALSE); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
519 |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
520 th_cfg_add_comment(§1, "A string list"); |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
521 th_cfg_add_string_list(§1, "string_list", &v_str_list); |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
522 |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
523 th_cfg_add_section(&cfg, "general", sect1); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
524 |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
525 sect1 = NULL; |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
526 th_cfg_add_comment(§1, "Another section"); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
527 th_cfg_add_bool(§1, "boolval", &v_bool2, TRUE); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
528 |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
529 sect2 = NULL; |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
530 th_cfg_add_comment(§2, "Section inside a section"); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
531 th_cfg_add_int(§2, "intval", &v_int1, 112); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
532 th_cfg_add_section(§1, "inside_sect", sect2); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
533 |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
534 th_cfg_add_section(&cfg, "another_sect", sect1); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
535 |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
536 // Test ptr |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
537 test_start(&ctx, "Test configuration string list ptr"); |
613 | 538 test_result(&ctx, |
539 (item = th_cfg_find(cfg, NULL, "string_list", -1)) != NULL && | |
540 item->v.list == &v_str_list); | |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
541 test_end(&ctx); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
542 |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
543 // Test value finding |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
544 test_config_values(cfg); |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
545 |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
546 // Attempt to write the file |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
547 if (th_io_fopen(&fh, &th_stdio_io_ops, filename, "w") != THERR_OK) |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
548 { |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
549 int err = th_get_error(); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
550 THERR("Could not create configuration to file '%s', %d: %s\n", |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
551 filename, err, th_error_str(err)); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
552 goto out; |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
553 } |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
554 |
516 | 555 th_io_set_handlers(fh, test_ioctx_error, test_ioctx_msg); |
556 | |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
557 th_cfg_write(fh, cfg); |
650
24cbab6e88c6
Remove th_io_free(), merge the functionality to th_io_close(). Add flags
Matti Hamalainen <ccr@tnsp.org>
parents:
649
diff
changeset
|
558 th_io_close(fh); |
515
d512555bdd0f
Close written test config file before trying to read it.
Matti Hamalainen <ccr@tnsp.org>
parents:
513
diff
changeset
|
559 fh = NULL; |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
560 |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
561 // Test against written configuration file |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
562 test_config_read(cfg, filename); |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
563 |
513
e412a39e2b7a
Add another test for configuration parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
512
diff
changeset
|
564 // Test against manually edited configuration file |
e412a39e2b7a
Add another test for configuration parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
512
diff
changeset
|
565 test_config_read(cfg, "cfg.test01"); |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
566 |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
567 out: |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
568 // Free the data for v_str_list |
650
24cbab6e88c6
Remove th_io_free(), merge the functionality to th_io_close(). Add flags
Matti Hamalainen <ccr@tnsp.org>
parents:
649
diff
changeset
|
569 th_io_close(fh); |
709
905d30063e45
Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents:
703
diff
changeset
|
570 th_llist_free_func_data(v_str_list, th_free); |
905d30063e45
Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents:
703
diff
changeset
|
571 th_cfg_free(cfg, test_config_free); |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
572 } |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
573 |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
574 |
614
afcaf5e38f56
Disable regex stuff from normal builds.
Matti Hamalainen <ccr@tnsp.org>
parents:
613
diff
changeset
|
575 #ifdef TH_EXPERIMENTAL_REGEX |
afcaf5e38f56
Disable regex stuff from normal builds.
Matti Hamalainen <ccr@tnsp.org>
parents:
613
diff
changeset
|
576 |
605
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
577 typedef struct |
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
578 { |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
579 const th_char_t *str; |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
580 const int flags; |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
581 const th_char_t *expected[4]; |
647 | 582 } test_regex_def1; |
583 | |
584 | |
585 typedef struct | |
586 { | |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
587 const th_char_t *pattern; |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
588 const th_char_t *str; |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
589 const int flags; |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
590 const th_char_t *expected[4]; |
647 | 591 } test_regex_def2; |
605
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
592 |
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
593 |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
594 BOOL test_regex_list_matches(const th_char_t *str, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
595 const th_regex_match_t *matches, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
596 const th_char_t * const *expected, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
597 const BOOL testOnly) |
645
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
598 { |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
599 size_t nmatch = 0; |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
600 char *match = NULL; |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
601 |
645
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
602 for (const th_regex_match_t *mt = matches; |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
603 mt != NULL; |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
604 mt = (th_regex_match_t *) mt->node.next, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
605 nmatch++) |
645
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
606 { |
710
c1c37f6ca133
Fix a silly memory leak in tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
709
diff
changeset
|
607 match = th_strndup(str + mt->start, mt->len); |
c1c37f6ca133
Fix a silly memory leak in tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
709
diff
changeset
|
608 |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
609 if (expected[nmatch] == NULL) |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
610 { |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
611 if (!testOnly) |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
612 { |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
613 THERR("Expected[%" PRIu_SIZE_T "] == NULL, but match '%s' returned.\n", |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
614 nmatch, match); |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
615 } |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
616 |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
617 goto error; |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
618 } |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
619 else |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
620 { |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
621 BOOL seqMatch = strcmp(match, expected[nmatch]) == 0; |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
622 if (testOnly && !seqMatch) |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
623 goto error; |
645
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
624 |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
625 if (th_verbosity >= 1 || !seqMatch) |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
626 { |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
627 tprint(0, " [%3" PRIu_SIZE_T " ++ %3" PRIu_SIZE_T "]: '%s' == '%s': %s\n", |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
628 mt->start, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
629 mt->len, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
630 match, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
631 expected[nmatch], |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
632 seqMatch ? "YES" : "NO!"); |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
633 } |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
634 } |
645
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
635 |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
636 th_free(match); |
645
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
637 } |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
638 |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
639 return TRUE; |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
640 |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
641 error: |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
642 th_free(match); |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
643 return FALSE; |
645
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
644 } |
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
645 |
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
646 |
664
c5aa9ada1051
s/th_regex_char_t/th_char_t/g
Matti Hamalainen <ccr@tnsp.org>
parents:
651
diff
changeset
|
647 void test_regex_list1(const test_regex_def1 *list, const th_char_t *pattern) |
605
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
648 { |
713
3ea040bb0dca
Fix a memory leak in regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
710
diff
changeset
|
649 th_regex_match_t *matches = NULL; |
645
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
650 th_regex_t *expr = NULL; |
605
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
651 int res; |
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
652 |
645
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
653 if ((res = th_regex_compile(&expr, pattern)) != THERR_OK) |
605
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
654 { |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
655 THERR("Regex \"%s\" compilation failed: %s\n", |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
656 pattern, |
605
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
657 th_error_str(res)); |
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
658 goto out; |
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
659 } |
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
660 |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
661 tprint(1, "\n----------------------------------------\n" |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
662 "\"%s\"\n", pattern); |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
663 |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
664 if (th_verbosity >= 2) |
651 | 665 th_regex_dump(&testio, 1, expr); |
645
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
666 |
647 | 667 for (const test_regex_def1 *def = list; def->str != NULL; def++) |
605
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
668 { |
610
a0e8d9c6300b
A bit more work on the regex stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
605
diff
changeset
|
669 size_t nmatches; |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
670 BOOL matchOK; |
605
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
671 |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
672 tprint(3, "\n----------------------------------------\n"); |
645
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
673 if ((res = th_regex_match(expr, def->str, |
613 | 674 &nmatches, &matches, -1, def->flags)) != THERR_OK) |
605
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
675 { |
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
676 THERR("Regex match returned error: %s\n", |
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
677 th_error_str(res)); |
713
3ea040bb0dca
Fix a memory leak in regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
710
diff
changeset
|
678 |
605
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
679 goto out; |
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
680 } |
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
681 |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
682 matchOK = test_regex_list_matches(def->str, matches, def->expected, TRUE); |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
683 if (th_verbosity < 1 && !matchOK) |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
684 { |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
685 tprint(0, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
686 "\n----------------------------------------\n" |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
687 " \"%s\" vs \"%s\" failures:\n", |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
688 def->str, pattern); |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
689 } |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
690 else |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
691 { |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
692 tprint(1, " \"%s\": matched %" PRIu_SIZE_T " time(s)\n", |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
693 def->str, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
694 nmatches); |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
695 } |
610
a0e8d9c6300b
A bit more work on the regex stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
605
diff
changeset
|
696 |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
697 #ifdef TH_EXPERIMENTAL_REGEX_DEBUG |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
698 if (!matchOK && th_dbg_fh == NULL) |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
699 { |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
700 th_dbg_fh = &testio; |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
701 th_regex_match(expr, def->str, NULL, NULL, -1, def->flags); |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
702 th_dbg_fh = NULL; |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
703 } |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
704 #endif |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
705 |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
706 test_regex_list_matches(def->str, matches, def->expected, FALSE); |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
707 |
610
a0e8d9c6300b
A bit more work on the regex stuff.
Matti Hamalainen <ccr@tnsp.org>
parents:
605
diff
changeset
|
708 th_regex_free_matches(matches); |
713
3ea040bb0dca
Fix a memory leak in regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
710
diff
changeset
|
709 matches = NULL; |
605
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
710 } |
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
711 |
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
712 out: |
713
3ea040bb0dca
Fix a memory leak in regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
710
diff
changeset
|
713 th_regex_free_matches(matches); |
645
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
714 th_regex_free(expr); |
605
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
715 } |
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
716 |
649 | 717 |
647 | 718 void test_regex_list2(const test_regex_def2 *list) |
719 { | |
720 for (const test_regex_def2 *def = list; def->str != NULL; def++) | |
721 { | |
722 th_regex_t *expr = NULL; | |
723 th_regex_match_t *matches = NULL; | |
724 size_t nmatches; | |
725 int res; | |
726 | |
727 if ((res = th_regex_compile(&expr, def->pattern)) != THERR_OK) | |
728 { | |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
729 THERR("Regex \"%s\" compilation failed: %s\n", |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
730 def->pattern, |
647 | 731 th_error_str(res)); |
732 goto out; | |
733 } | |
734 | |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
735 if (th_verbosity >= 2) |
651 | 736 th_regex_dump(&testio, 1, expr); |
647 | 737 |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
738 tprint(3, "----------------------------------------\n"); |
647 | 739 |
740 if ((res = th_regex_match(expr, def->str, | |
741 &nmatches, &matches, -1, def->flags)) != THERR_OK) | |
742 { | |
743 THERR("Regex match returned error: %s\n", | |
744 th_error_str(res)); | |
745 goto out; | |
746 } | |
747 | |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
748 tprint(1, "\"%s\" vs \"%s\": matched %" PRIu_SIZE_T " time(s)\n", |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
749 def->pattern, def->str, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
750 nmatches); |
647 | 751 |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
752 test_regex_list_matches(def->str, matches, def->expected, FALSE); |
647 | 753 |
754 out: | |
755 th_regex_free_matches(matches); | |
756 th_regex_free(expr); | |
757 } | |
758 } | |
759 | |
614
afcaf5e38f56
Disable regex stuff from normal builds.
Matti Hamalainen <ccr@tnsp.org>
parents:
613
diff
changeset
|
760 #endif |
afcaf5e38f56
Disable regex stuff from normal builds.
Matti Hamalainen <ccr@tnsp.org>
parents:
613
diff
changeset
|
761 |
605
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
762 |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
763 int main(int argc, char *argv[]) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
764 { |
334
b90173719330
Add more tests (some of which will fail for now due to unimplemented features).
Matti Hamalainen <ccr@tnsp.org>
parents:
333
diff
changeset
|
765 size_t i1, i2, i3, i4; |
326
75b22d6f8a71
Simplify and improve integer sprintf() tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
766 char buf[64], buf2[64]; |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
767 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
768 // |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
769 // Initialization |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
770 // |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
771 th_init("th-test", "th-libs unit tests", "0.2", NULL, NULL); |
469
fe5b803ae449
Rename the global variable th_verbosityLevel to th_verbosity.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
772 th_verbosity = 0; |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
773 |
603
be957142ab37
Add TEST_ASSERT() and test sizes of some types before doing anything else.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
774 TEST_ASSERT(sizeof(char) == sizeof(unsigned char)); |
be957142ab37
Add TEST_ASSERT() and test sizes of some types before doing anything else.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
775 TEST_ASSERT(sizeof(char) == 1); |
be957142ab37
Add TEST_ASSERT() and test sizes of some types before doing anything else.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
776 TEST_ASSERT(sizeof(uint16_t) == 2); |
be957142ab37
Add TEST_ASSERT() and test sizes of some types before doing anything else.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
777 TEST_ASSERT(sizeof(uint32_t) == 4); |
be957142ab37
Add TEST_ASSERT() and test sizes of some types before doing anything else.
Matti Hamalainen <ccr@tnsp.org>
parents:
602
diff
changeset
|
778 TEST_ASSERT(sizeof(uint64_t) == 8); |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
779 |
523 | 780 tests_failed = tests_passed = tests_total = |
781 sets_total = sets_nenabled = 0; | |
782 | |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
783 for (i1 = 0; i1 < SET_MAX_TESTS; i1++) |
365 | 784 sets_enabled[i1] = 1; |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
785 |
651 | 786 th_io_init_stdio(&testio, stdout); |
787 | |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
788 // |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
789 // Parse command line arguments |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
790 // |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
791 if (!th_args_process(argc, argv, arg_opts, arg_nopts, |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
792 arg_handle_opt, NULL, 0)) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
793 return 0; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
794 |
365 | 795 tprint(1, "Enabled test types are 0x%04x.\n", optFlags); |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
796 |
525
59b8f15c5334
Add (compile-time enabled via TH_PRINTF_DEBUG define) global variable for
Matti Hamalainen <ccr@tnsp.org>
parents:
524
diff
changeset
|
797 |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
798 // |
405 | 799 // Test series for printf() |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
800 // |
544
619e7fcff486
Add more printf() format tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
801 char *i_fmts[] = { "", "05", "6", ".4", "1.1", "1.0", "8.5", "08.5", "3", "2.1", "3", "1", "18", "018", ".0", "0" }; |
596
4ea7b0e9dcba
Improve string printf() tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
592
diff
changeset
|
802 char *i_mods[] = { "", "-", "+", "#", " ", }; |
343 | 803 char *i_types[] = { "d", "u", "i", "x", "X", "o", }; |
544
619e7fcff486
Add more printf() format tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
804 |
295 | 805 if (test_set_start("printf() integer")) |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
806 { |
526
32245648f0f0
More printf() format specifier tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
525
diff
changeset
|
807 int i_vals[] = { |
532
ad64c3f7cf64
Adjust printf int formatting test values and format specifiers.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
808 0, -0, 1, -1, 10, -10, 512, -512, -1024, |
ad64c3f7cf64
Adjust printf int formatting test values and format specifiers.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
809 612342, -612342, 0x1fff, 0x8000000, -123456789, |
563
7cb58b683677
Fix integer overflow in the test values of 32bit ints.
Matti Hamalainen <ccr@tnsp.org>
parents:
552
diff
changeset
|
810 2147483647, -2147483648 }; |
315 | 811 |
327
b0f9f806c8c9
Implement NCOUNT() macro for getting array element counts (sizeof(arr) / sizeof(arr[0]))
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
812 for (i1 = 0; i1 < NCOUNT(i_vals); i1++) |
315 | 813 { |
319 | 814 snprintf(buf, sizeof(buf), "%d", i_vals[i1]); |
326
75b22d6f8a71
Simplify and improve integer sprintf() tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
815 |
334
b90173719330
Add more tests (some of which will fail for now due to unimplemented features).
Matti Hamalainen <ccr@tnsp.org>
parents:
333
diff
changeset
|
816 for (i4 = 0; i4 < NCOUNT(i_mods); i4++) |
332 | 817 for (i3 = 0; i3 < NCOUNT(i_types); i3++) |
818 for (i2 = 0; i2 < NCOUNT(i_fmts); i2++) | |
326
75b22d6f8a71
Simplify and improve integer sprintf() tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
819 { |
334
b90173719330
Add more tests (some of which will fail for now due to unimplemented features).
Matti Hamalainen <ccr@tnsp.org>
parents:
333
diff
changeset
|
820 snprintf(buf2, sizeof(buf2), "%%%s%s%s", i_mods[i4], i_fmts[i2], i_types[i3]); |
326
75b22d6f8a71
Simplify and improve integer sprintf() tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
821 test_snprintf(buf, buf2, i_vals[i1]); |
75b22d6f8a71
Simplify and improve integer sprintf() tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
822 } |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
823 } |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
824 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
825 |
724
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
826 if (test_set_start("printf() integer 64bit generic")) |
331
6e42d50c08c4
Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
827 { |
532
ad64c3f7cf64
Adjust printf int formatting test values and format specifiers.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
828 int64_t i_vals64[] = { |
544
619e7fcff486
Add more printf() format tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
829 0, -0, 1, -1, 10, -10, 512, -512, -1024, |
619e7fcff486
Add more printf() format tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
830 612342, -612342, 0x1fff, 0x8000000, -123456789, |
619e7fcff486
Add more printf() format tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
831 4294967295, -2147483648, |
532
ad64c3f7cf64
Adjust printf int formatting test values and format specifiers.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
832 0x3342344341fff, 0x1f8000000, }; |
331
6e42d50c08c4
Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
833 |
333 | 834 for (i1 = 0; i1 < NCOUNT(i_vals64); i1++) |
331
6e42d50c08c4
Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
835 { |
395
bffd3caf2d2c
Rename TH_PRI{u,d,x}* macros to match with standard ISO C99 inttypes.h PRI*.
Matti Hamalainen <ccr@tnsp.org>
parents:
380
diff
changeset
|
836 snprintf(buf, sizeof(buf), "%" PRId64, i_vals64[i1]); |
331
6e42d50c08c4
Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
837 |
340 | 838 for (i4 = 0; i4 < NCOUNT(i_mods); i4++) |
332 | 839 for (i3 = 0; i3 < NCOUNT(i_types); i3++) |
840 for (i2 = 0; i2 < NCOUNT(i_fmts); i2++) | |
331
6e42d50c08c4
Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
841 { |
402 | 842 snprintf(buf2, sizeof(buf2), "%%%s%sll%s", i_mods[i4], i_fmts[i2], i_types[i3]); |
333 | 843 test_snprintf(buf, buf2, i_vals64[i1]); |
331
6e42d50c08c4
Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
844 } |
6e42d50c08c4
Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
845 } |
6e42d50c08c4
Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
846 } |
6e42d50c08c4
Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
847 |
724
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
848 if (test_set_start("printf() integer 64bit PRI* specifiers")) |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
849 { |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
850 int64_t i_vals64[] = { |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
851 0, -0, 1, -1, 10, -10, 512, -512, -1024, |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
852 612342, -612342, 0x1fff, 0x8000000, -123456789, |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
853 4294967295, -2147483648, |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
854 0x3342344341fff, 0x1f8000000, }; |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
855 |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
856 for (i1 = 0; i1 < NCOUNT(i_vals64); i1++) |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
857 { |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
858 snprintf(buf, sizeof(buf), "%" PRId64, i_vals64[i1]); |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
859 |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
860 for (i4 = 0; i3 < NCOUNT(i_mods); i3++) |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
861 for (i2 = 0; i2 < NCOUNT(i_fmts); i2++) |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
862 { |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
863 snprintf(buf2, sizeof(buf2), "%%%s%s" PRId64, i_mods[i3], i_fmts[i2]); |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
864 test_snprintf(buf, buf2, i_vals64[i1]); |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
865 |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
866 snprintf(buf2, sizeof(buf2), "%%%s%s" PRIx64, i_mods[i3], i_fmts[i2]); |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
867 test_snprintf(buf, buf2, i_vals64[i1]); |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
868 |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
869 snprintf(buf2, sizeof(buf2), "%%%s%s" PRIX64, i_mods[i3], i_fmts[i2]); |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
870 test_snprintf(buf, buf2, i_vals64[i1]); |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
871 } |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
872 } |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
873 } |
388d72f4189d
Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
713
diff
changeset
|
874 |
533
ef0d732fabe0
Disable floating point printf implementation tests as the support is not
Matti Hamalainen <ccr@tnsp.org>
parents:
532
diff
changeset
|
875 #ifdef TH_WIP_FLOAT_SUPPORT |
296
ec8357d02a52
Add floating point tests (which will fail for now).
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
876 if (test_set_start("printf() float")) |
ec8357d02a52
Add floating point tests (which will fail for now).
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
877 { |
544
619e7fcff486
Add more printf() format tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
878 double f_vals[] = { 0, 1, 2, 3, 2.02, 612342.234, -2.07, -612342.12, 437692.9876543219, 0x1fff, 0x8000000, 0.15625 }; |
404 | 879 char *f_fmts[] = { "%f", "%1.1f", "%8.5f", "%5f", "%-5f", "", "%-5.2f", "%08.5f" }; |
296
ec8357d02a52
Add floating point tests (which will fail for now).
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
880 |
327
b0f9f806c8c9
Implement NCOUNT() macro for getting array element counts (sizeof(arr) / sizeof(arr[0]))
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
881 for (i1 = 0; i1 < NCOUNT(f_vals); i1++) |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
882 { |
319 | 883 snprintf(buf, sizeof(buf), "%f", f_vals[i1]); |
327
b0f9f806c8c9
Implement NCOUNT() macro for getting array element counts (sizeof(arr) / sizeof(arr[0]))
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
884 for (i2 = 0; i2 < NCOUNT(f_fmts); i2++) |
319 | 885 test_snprintf(buf, f_fmts[i2], f_vals[i1]); |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
886 } |
296
ec8357d02a52
Add floating point tests (which will fail for now).
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
887 } |
533
ef0d732fabe0
Disable floating point printf implementation tests as the support is not
Matti Hamalainen <ccr@tnsp.org>
parents:
532
diff
changeset
|
888 #endif |
296
ec8357d02a52
Add floating point tests (which will fail for now).
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
889 |
295 | 890 if (test_set_start("printf() string")) |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
891 { |
407 | 892 char *s_vals[] = { "", "XYZXYZ", "xxx yyy zzz ppp fff", NULL, "X", "abcde", "dx", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", }; |
596
4ea7b0e9dcba
Improve string printf() tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
592
diff
changeset
|
893 // char *s_fmts[] = { "%s", "%2s", "%-2s", "%5s", "%-5s", "%16s", "%-16s", "%1s", "%-1s", "% 2s", "%03s", "% -12s", "% 03s", "%-.15s", "%.8s" }; |
4ea7b0e9dcba
Improve string printf() tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
592
diff
changeset
|
894 char *s_fmts[] = { "", "-" " ", "0", " 0", ".", "-.", }; |
4ea7b0e9dcba
Improve string printf() tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
592
diff
changeset
|
895 int s_widths[] = { 0, 1, 2, 5, 16, }; |
265 | 896 |
327
b0f9f806c8c9
Implement NCOUNT() macro for getting array element counts (sizeof(arr) / sizeof(arr[0]))
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
897 for (i1 = 0; i1 < NCOUNT(s_vals); i1++) |
596
4ea7b0e9dcba
Improve string printf() tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
592
diff
changeset
|
898 for (i2 = 0; i2 < NCOUNT(s_fmts); i2++) |
4ea7b0e9dcba
Improve string printf() tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
592
diff
changeset
|
899 for (i3 = 0; i3 < NCOUNT(s_widths); i3++) |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
900 { |
596
4ea7b0e9dcba
Improve string printf() tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
592
diff
changeset
|
901 snprintf(buf, sizeof(buf), "%%%s%ds", s_fmts[i2], s_widths[i3]); |
4ea7b0e9dcba
Improve string printf() tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
592
diff
changeset
|
902 test_snprintf(s_vals[i1], buf, s_vals[i1]); |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
903 } |
288 | 904 } |
905 | |
295 | 906 if (test_set_start("printf() char")) |
288 | 907 { |
319 | 908 const char c_val = 'x'; |
909 const char *c_msg = "x"; | |
352 | 910 char *c_fmts[] = { "a%cBC", "%c", "", "%0c", "%1c", "% c", "%-3c", "%3c", "%.3c", "%-.3c", "%-3.3c", "%.c", "%05c", "%-05c", }; |
328
0146aa9a9524
Simplify char printf tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
327
diff
changeset
|
911 |
0146aa9a9524
Simplify char printf tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
327
diff
changeset
|
912 for (i1 = 0; i1 < NCOUNT(c_fmts); i1++) |
0146aa9a9524
Simplify char printf tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
327
diff
changeset
|
913 test_snprintf(c_msg, c_fmts[i1], c_val); |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
914 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
915 |
356
d7f43fce0dce
Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
916 if (test_set_start("printf() pointers")) |
d7f43fce0dce
Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
917 { |
407 | 918 char *p_fmts[] = { "%p", "%2p", "%.2p", "%03p", "%04p", "%-3p", "%0.3p", "%8p", "%32p", "%032p", "%-32p", "%-032p", "%16.8p", "%016.8p" }; |
356
d7f43fce0dce
Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
919 void *p_vals[] = { NULL, (void *) 1, &p_fmts, }; |
d7f43fce0dce
Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
920 |
d7f43fce0dce
Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
921 for (i1 = 0; i1 < NCOUNT(p_vals); i1++) |
d7f43fce0dce
Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
922 { |
d7f43fce0dce
Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
923 snprintf(buf, sizeof(buf), "%p", p_vals[i1]); |
d7f43fce0dce
Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
924 for (i2 = 0; i2 < NCOUNT(p_fmts); i2++) |
d7f43fce0dce
Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
925 test_snprintf(buf, p_fmts[i2], p_vals[i1]); |
d7f43fce0dce
Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
926 } |
d7f43fce0dce
Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
927 } |
d7f43fce0dce
Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
928 |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
929 // |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
930 // String matching functions |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
931 // |
465 | 932 if (test_set_start("String compare #1")) |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
933 { |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
934 TEST2(th_strcasecmp, "aSdFq", "asdfq", TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
935 TEST2(th_strcasecmp, "aSdFq", "asFfq", FALSE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
936 TEST2(th_strcasecmp, "abcde", "abcde", TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
937 TEST2(th_strcasecmp, "öäå", "öäå", TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
938 TEST2(th_strcasecmp, "aöäå", "aöäå", TRUE); |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
939 } |
255 | 940 |
465 | 941 if (test_set_start("String compare #2")) |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
942 { |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
943 TEST3(th_strncasecmp, "aSdFq", "asFfqB", 4, FALSE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
944 TEST3(th_strncasecmp, "aSdFq", "asFfqQ", 2, TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
945 TEST3(th_strncasecmp, "aSdFq", "asDfq", 3, TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
946 TEST3(th_strncasecmp, "aSdFq", "asDfq", 2, TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
947 TEST3(th_strncasecmp, "aSdFq", "asDfq", 0, TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
948 TEST3(th_strncasecmp, "aSdFq", "QsDfq", 0, TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
949 TEST3(th_strncasecmp, "aSdFq", "QsDfq", 1, FALSE); |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
950 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
951 |
465 | 952 if (test_set_start("String compare #3")) |
953 { | |
954 TEST2C(th_strrcasecmp, "foo aSdFq", " asdfq", TRUE); | |
955 TEST2C(th_strrcasecmp, "aSdFq", " asdfq", FALSE); | |
956 TEST2C(th_strrcasecmp, "foo aSdFq baz", "asdfq", FALSE); | |
957 } | |
958 | |
959 if (test_set_start("String matching #1")) | |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
960 { |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
961 TEST2B(th_strmatch, "abba ABBAkukka lol", "*lol", TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
962 TEST2B(th_strmatch, "abba ABBAkukka lol", "*lo*", TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
963 TEST2B(th_strmatch, "abba ABBAkukka lol", "*lo", FALSE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
964 TEST2B(th_strmatch, "abba ABBAkukka lol", "abba", FALSE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
965 TEST2B(th_strmatch, "abba ABBAkukka lol", "*bba*", TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
966 TEST2B(th_strmatch, "abba ABBAkukka lol", "abba*", TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
967 TEST2B(th_strmatch, "abba ABBAkukka lol", "abbak*", FALSE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
968 TEST2B(th_strmatch, "abba ABBAöökukka lol", "*abbaö?", FALSE); |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
969 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
970 |
465 | 971 if (test_set_start("String matching #2")) |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
972 { |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
973 TEST2B(th_strcasematch, "abba ABBAkukka lol", "abbak*", FALSE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
974 TEST2B(th_strcasematch, "abba ABBAkukka lol", "*abbak*", TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
975 TEST2B(th_strcasematch, "abba ABBAkukka lol", "*ab?ak*", TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
976 TEST2B(th_strcasematch, "abba ABBAkukka lol", "*abbak?", FALSE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
977 TEST2B(th_strcasematch, "abba ABBAkukka lol", "?bba?abba*", TRUE); |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
978 } |
266 | 979 |
265 | 980 // Tests that test for things that do not work correctly yet |
981 // Unicode / multibyte UTF-8 causes problems here | |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
982 if ((optFlags & TST_BROKEN) && |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
983 test_set_start("Invalid UTF-8 handling")) |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
984 { |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
985 TEST2(th_strcasecmp, "ÖÄÅ", "öäå", FALSE); // SHOULD match |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
986 TEST3(th_strncasecmp, "Aäöå", "aöå", 2, TRUE); // should NOT match |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
987 TEST2B(th_strmatch, "öriÖRI! lol", "?ri?RI!*", FALSE); // should match |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
988 } |
266 | 989 |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
990 // |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
991 // printf() PRI* format specifiers, also a compile time test |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
992 // |
501 | 993 if (test_set_start("PRI* specifiers")) |
492
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
994 { |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
995 char tmp[32]; |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
996 uint32_t u32 = 0xaabbccdd; |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
997 uint64_t u64 = 0xaabbccdd11223344; |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
998 size_t usiz = |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
999 #if TH_ARCH == 32 |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
1000 0x11223344; |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
1001 #elif TH_ARCH == 64 |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
1002 0xaabbccdd11223344; |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
1003 #else |
613 | 1004 # error Unsupported TH_ARCH value. |
492
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
1005 #endif |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
1006 |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
1007 snprintf(tmp, sizeof(tmp), "%16" PRIx_SIZE_T "h", usiz); |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
1008 #if TH_ARCH == 32 |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
1009 TEST2(strcmp, tmp, "0000000011223344h", TRUE); |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
1010 #else |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
1011 TEST2(strcmp, tmp, "aabbccdd11223344h", TRUE); |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
1012 #endif |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
1013 |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
1014 snprintf(tmp, sizeof(tmp), "%08" PRIx32 "h", u32); |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
1015 TEST2(strcmp, tmp, "aabbccddh", TRUE); |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
1016 snprintf(tmp, sizeof(tmp), "%16" PRIx64 "h", u64); |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
1017 TEST2(strcmp, tmp, "aabbccdd11223344h", TRUE); |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
1018 } |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
1019 |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
1020 // |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
1021 // Configuration file handling |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
1022 // |
523 | 1023 if (test_set_start("Configuration file handling")) |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
1024 { |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
1025 test_config(); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
1026 } |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
1027 |
255 | 1028 // |
524
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
1029 // String functions |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
1030 // |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
1031 if (test_set_start("String functions")) |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
1032 { |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
1033 unsigned int tmpUint; |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
1034 |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
1035 TEST1(th_get_hex_triplet("0fac11", &tmpUint) == TRUE); |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
1036 TEST1A("0x%06x", tmpUint, ==, 0x0fac11); |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
1037 TEST1(th_get_hex_triplet("120fac11", &tmpUint) == TRUE); |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
1038 TEST1A("0x%06x", tmpUint, ==, 0x120fac11); |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
1039 TEST1(th_get_hex_triplet("x120fac11", &tmpUint) == FALSE); |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
1040 } |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
1041 |
19dc326dcdad
Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents:
523
diff
changeset
|
1042 // |
605
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
1043 // Regular expressions |
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
1044 // |
614
afcaf5e38f56
Disable regex stuff from normal builds.
Matti Hamalainen <ccr@tnsp.org>
parents:
613
diff
changeset
|
1045 #ifdef TH_EXPERIMENTAL_REGEX |
605
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
1046 if (test_set_start("Regular expressions")) |
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
1047 { |
635
d191ded8a790
Improve the experimental regex matching debugging macros.
Matti Hamalainen <ccr@tnsp.org>
parents:
614
diff
changeset
|
1048 #ifdef TH_EXPERIMENTAL_REGEX_DEBUG |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1049 th_dbg_fh = (th_verbosity >= 3) ? &testio : NULL; |
635
d191ded8a790
Improve the experimental regex matching debugging macros.
Matti Hamalainen <ccr@tnsp.org>
parents:
614
diff
changeset
|
1050 #endif |
d191ded8a790
Improve the experimental regex matching debugging macros.
Matti Hamalainen <ccr@tnsp.org>
parents:
614
diff
changeset
|
1051 |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1052 if (1) |
645
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
1053 { |
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
1054 const char *str = "z*k+abba fabboa? [a-zA-Z_-] \\{\\} k{4} ([0-9]+ yay){1,2} foo(bar|zoo)?"; |
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
1055 th_regex_t *expr = NULL; |
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
1056 int res = th_regex_compile(&expr, str); |
666 | 1057 |
645
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
1058 printf("REGEX: \"%s\"\n", str); |
666 | 1059 |
645
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
1060 if (res == THERR_OK) |
651 | 1061 th_regex_dump(&testio, 1, expr); |
645
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
1062 else |
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
1063 printf("ERROR: %s\n", th_error_str(res)); |
666 | 1064 |
645
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
1065 th_regex_free(expr); |
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
1066 } |
b897995101b7
More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents:
643
diff
changeset
|
1067 |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1068 if (1) |
640
9e1f9e1d1487
Aaand some more work. Still just a broken concept.
Matti Hamalainen <ccr@tnsp.org>
parents:
635
diff
changeset
|
1069 { |
647 | 1070 static const test_regex_def1 tlist[] = |
613 | 1071 { |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1072 { "abcfoabcccg" , 0, { "abcfoabcccg", } }, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1073 { "sabcbcfoabcccgz" , 0, { "abcbcfoabcccg", } }, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1074 { "abcbcfoabccg abcbcfoabccccg" , 0, { "abcbcfoabccg", "abcbcfoabccccg" } }, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1075 { NULL , 0, { NULL } } |
613 | 1076 }; |
1077 | |
647 | 1078 test_regex_list1(tlist, "a(bc){1,2}fo[oab]*cc?g"); |
613 | 1079 } |
1080 | |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1081 if (1) |
605
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
1082 { |
647 | 1083 static const test_regex_def1 tlist[] = |
613 | 1084 { |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1085 { "abcfoabccg" , 0, { "abcfoabccg", } }, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1086 { "abcbcfoabccg" , 0, { "abcbcfoabccg", } }, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1087 { "abcbcfoabccgabcbcfoabccg" , 0, { "abcbcfoabccg", } }, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1088 { "ffdsafS abcbcfoabccg zasdf" , 0, { NULL } }, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1089 { NULL , 0, { NULL } } |
613 | 1090 }; |
1091 | |
647 | 1092 test_regex_list1(tlist, "^a(bc){1,2}fo[oab]*cc?g"); |
613 | 1093 } |
605
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
1094 |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1095 if (1) |
613 | 1096 { |
647 | 1097 static const test_regex_def1 tlist[] = |
613 | 1098 { |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1099 { "cg" , 0, { "g", } }, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1100 { "g" , 0, { "g", } }, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1101 { "" , 0, { NULL, } }, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1102 { "c" , 0, { NULL, } }, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1103 { NULL , 0, { NULL } } |
613 | 1104 }; |
1105 | |
647 | 1106 test_regex_list1(tlist, "g$"); |
613 | 1107 } |
1108 | |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1109 if (1) |
613 | 1110 { |
647 | 1111 static const test_regex_def1 tlist[] = |
613 | 1112 { |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1113 { "kzoobarzz" , 0, { "zoobar", } }, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1114 { "hehzoo lol baromg" , 0, { "zoo lol bar", } }, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1115 { "hoho zoo lol lol bar bar f" , 0, { "zoo lol lol bar", } }, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1116 { "hoho zoobar bar heh" , 0, { "zoobar", } }, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1117 { NULL , 0, { NULL } } |
613 | 1118 }; |
1119 | |
647 | 1120 test_regex_list1(tlist, "zoo.*?bar"); |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1121 } |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1122 |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1123 if (1) |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1124 { |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1125 static const test_regex_def1 tlist[] = |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1126 { |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1127 { "kzoobarzz" , 0, { "zoobar", } }, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1128 { "hehzoo lol baromg" , 0, { "zoo lol bar", } }, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1129 { "hoho zoo lol lol bar bar f" , 0, { "zoo lol lol bar bar", } }, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1130 { "hoho zoobar bar heh" , 0, { "zoobar bar", } }, |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1131 { NULL , 0, { NULL } } |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1132 }; |
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1133 |
666 | 1134 test_regex_list1(tlist, "zoo.*bar"); |
613 | 1135 } |
668
48e8820bc625
Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
666
diff
changeset
|
1136 |
605
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
1137 } |
614
afcaf5e38f56
Disable regex stuff from normal builds.
Matti Hamalainen <ccr@tnsp.org>
parents:
613
diff
changeset
|
1138 #endif |
605
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
1139 |
566e6ef41f9d
Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents:
603
diff
changeset
|
1140 // |
255 | 1141 // Print summary and exit |
1142 // | |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
1143 tprint(1, |
276
56b0de9f9d44
Improve tests output per verbosity level.
Matti Hamalainen <ccr@tnsp.org>
parents:
274
diff
changeset
|
1144 "======================================================\n"); |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
1145 |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
1146 tprint(0, |
312 | 1147 "%d tests failed, %d passed (%d main tests), %d test sets of %d sets total.\n\n", |
365 | 1148 tests_failed, tests_passed, tests_total, sets_nenabled, sets_total); |
255 | 1149 |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1150 return 0; |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1151 } |