Mercurial > hg > th-libs
annotate tests.c @ 521:77495c646208
Fix parsing and writing of strings with simple escape sequences in config files.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 26 Dec 2019 13:34:19 +0200 |
parents | 80185b9901ba |
children | 9acbbfea68a9 |
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" |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
6 #include "th_config.h" |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 |
364 | 8 |
9 #define SET_BUF_SIZE 128 | |
365 | 10 #define SET_BUF_SIZE_2 ((SET_BUF_SIZE) + 32) |
364 | 11 #define SET_MAX_TESTS 64 |
12 #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
|
13 |
291 | 14 |
365 | 15 enum |
16 { | |
17 TST_SUPERFLUOUS = 0x0001, | |
18 TST_CORNERCASE = 0x0002, | |
19 TST_OVERFLOW = 0x0004, | |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
20 TST_BROKEN = 0x1000, |
365 | 21 TST_ALL = 0xffff, |
22 }; | |
23 | |
24 | |
303 | 25 typedef struct |
26 { | |
502
ebf89497305a
Remove some unused functionality for simplification.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
27 char *header; |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
28 BOOL shown; |
303 | 29 } test_ctx; |
30 | |
31 | |
291 | 32 // Globals |
365 | 33 int tests_failed, tests_passed, tests_total, sets_total, sets_nenabled; |
34 int sets_enabled[SET_MAX_TESTS]; | |
259 | 35 |
365 | 36 char buf1[SET_BUF_SIZE_2], buf2[SET_BUF_SIZE_2]; |
37 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
|
38 |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 |
274
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
40 // Define option arguments |
380
ac10155d2b4a
Rename th_optarg_t to t_optarg. API break.
Matti Hamalainen <ccr@tnsp.org>
parents:
366
diff
changeset
|
41 static const th_optarg arg_opts[] = |
274
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
42 { |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
43 { 0, '?', "help", "Show this help", OPT_NONE }, |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
44 { 1, 'v', "verbose", "Be more verbose", OPT_NONE }, |
365 | 45 { 2, 's', "sets", "Perform test sets -s <set>[,<set2>..]", OPT_ARGREQ }, |
46 { 3, 't', "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
|
47 }; |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
48 |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
49 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
|
50 |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
51 |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
52 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
|
53 { |
469
fe5b803ae449
Rename the global variable th_verbosityLevel to th_verbosity.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
54 if (level <= th_verbosity) |
363 | 55 { |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
56 vfprintf(stdout, fmt, ap); |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
57 return TRUE; |
363 | 58 } |
59 else | |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
60 return FALSE; |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
61 } |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
62 |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
63 |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
64 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
|
65 { |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
66 BOOL retv; |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
67 va_list ap; |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
68 va_start(ap, fmt); |
363 | 69 retv = tprintv(level, fmt, ap); |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
70 va_end(ap); |
363 | 71 return retv; |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
72 } |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
73 |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
74 |
274
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
75 void arg_show_help(void) |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
76 { |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
77 th_print_banner(stdout, th_prog_name, "[options]"); |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
78 th_args_help(stdout, arg_opts, arg_nopts, 0); |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
79 } |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
80 |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
81 |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
82 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
|
83 { |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
84 switch (optN) |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
85 { |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
86 case 0: |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
87 arg_show_help(); |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
88 exit(0); |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
89 break; |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
90 |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
91 case 1: |
469
fe5b803ae449
Rename the global variable th_verbosityLevel to th_verbosity.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
92 th_verbosity++; |
274
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
93 break; |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
94 |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
95 case 2: |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
96 { |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
97 BOOL ret = TRUE; |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
98 char *pos, *pstr, *next; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
99 pos = pstr = th_strdup(optArg); |
365 | 100 memset(sets_enabled, 0, sizeof(sets_enabled)); |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
101 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
102 do { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
103 next = strchr(pos, ','); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
104 if (next != NULL) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
105 *next = 0; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
106 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
107 char *tmp = th_strdup_trim(pos, TH_TRIM_BOTH); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
108 if (tmp != NULL) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
109 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
110 int val = atoi(tmp); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
111 if (val > 0 && val <= SET_MAX_TESTS) |
365 | 112 sets_enabled[val - 1] = 1; |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
113 else |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
114 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
115 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
|
116 ret = FALSE; |
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 th_free(tmp); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
119 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
120 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
121 if (next != NULL) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
122 pos = next + 1; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
123 } while (next != NULL); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
124 th_free(pstr); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
125 return ret; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
126 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
127 break; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
128 |
365 | 129 case 3: |
366
21bbb2dc4fac
Actually parse the -t option argument.
Matti Hamalainen <ccr@tnsp.org>
parents:
365
diff
changeset
|
130 optFlags = atoi(optArg); |
365 | 131 break; |
132 | |
274
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
133 default: |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
134 THERR("Unknown option '%s'.\n", currArg); |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
135 return FALSE; |
274
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
136 } |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
137 |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
138 return TRUE; |
274
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
139 } |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
140 |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
141 |
342
09c2f6abf694
Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
142 void test_end(test_ctx *ctx) |
09c2f6abf694
Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
143 { |
09c2f6abf694
Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
144 th_free_r(&ctx->header); |
09c2f6abf694
Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
145 } |
09c2f6abf694
Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
146 |
09c2f6abf694
Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
147 |
303 | 148 void test_start_v(test_ctx *ctx, const char *fmt, va_list ap) |
259 | 149 { |
150 tests_total++; | |
502
ebf89497305a
Remove some unused functionality for simplification.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
151 memset(ctx, 0, sizeof(test_ctx)); |
303 | 152 ctx->header = th_strdup_vprintf(fmt, ap); |
259 | 153 } |
154 | |
155 | |
303 | 156 void test_start(test_ctx *ctx, const char *fmt, ...) |
259 | 157 { |
158 va_list ap; | |
159 va_start(ap, fmt); | |
303 | 160 test_start_v(ctx, fmt, ap); |
259 | 161 va_end(ap); |
162 } | |
163 | |
164 | |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
165 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
|
166 { |
259 | 167 if (check) |
168 { | |
363 | 169 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
|
170 ctx->shown = TRUE; |
363 | 171 |
259 | 172 tests_passed++; |
173 } | |
174 else | |
175 { | |
363 | 176 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
|
177 ctx->shown = TRUE; |
363 | 178 |
259 | 179 if (fmt != NULL) |
263 | 180 { |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
181 tprint(0, " - "); |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
182 tprintv(0, fmt, ap); |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
183 tprint(0, "\n"); |
263 | 184 } |
259 | 185 tests_failed++; |
186 } | |
187 } | |
188 | |
189 | |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
190 BOOL test_result_msg(test_ctx *ctx, BOOL check, const char *fmt, ...) |
259 | 191 { |
192 va_list ap; | |
193 va_start(ap, fmt); | |
303 | 194 test_result_msg_v(ctx, check, fmt, ap); |
259 | 195 va_end(ap); |
305
5afd918cbd79
Have a return value for test result functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
304
diff
changeset
|
196 return check; |
259 | 197 } |
198 | |
199 | |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
200 BOOL test_result(test_ctx *ctx, BOOL check) |
259 | 201 { |
303 | 202 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
|
203 return check; |
259 | 204 } |
205 | |
206 | |
319 | 207 void test_snprintf_do(size_t len, const char *msg, const char *fmt, va_list ap) |
259 | 208 { |
209 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
|
210 va_list tmp; |
303 | 211 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
|
212 |
263 | 213 // Test basic *printf() functionality |
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
|
214 test_start(&ctx, "th_vsnprintf(%" PRIu_SIZE_T ", \"%s\", %s)", len, fmt, msg); |
259 | 215 |
365 | 216 memset(buf1, SET_SENTINEL_BYTE, SET_BUF_SIZE_2); buf1[SET_BUF_SIZE_2-1] = 0; |
217 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
|
218 |
339
46a0fab6ca1f
Fix snprintf() test running.
Matti Hamalainen <ccr@tnsp.org>
parents:
338
diff
changeset
|
219 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
|
220 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
|
221 |
303 | 222 test_result_msg(&ctx, ret1 == ret2, "retval mismatch %d [th] != %d [libc]", ret1, ret2); |
223 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
|
224 |
365 | 225 if (optFlags & TST_OVERFLOW) |
226 { | |
303 | 227 test_result_msg(&ctx, (unsigned char) buf1[len] == SET_SENTINEL_BYTE, "buffer #1 overflow, sentinel 0x%02x", buf1[len]); |
228 test_result_msg(&ctx, (unsigned char) buf2[len] == SET_SENTINEL_BYTE, "buffer #2 overflow, sentinel 0x%02x", buf2[len]); | |
365 | 229 } |
261 | 230 |
342
09c2f6abf694
Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
231 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
|
232 } |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
233 |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
234 |
319 | 235 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
|
236 { |
362 | 237 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
|
238 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
|
239 va_start(ap, fmt); |
365 | 240 |
241 if (optFlags & TST_CORNERCASE) | |
242 { | |
243 va_copy(tmp, ap); test_snprintf_do(0, msg, fmt, tmp); | |
244 va_copy(tmp, ap); test_snprintf_do(1, msg, fmt, tmp); | |
245 va_copy(tmp, ap); test_snprintf_do(2, msg, fmt, tmp); | |
246 va_copy(tmp, ap); test_snprintf_do(16, msg, fmt, tmp); | |
247 } | |
248 | |
319 | 249 va_copy(tmp, ap); test_snprintf_do(SET_BUF_SIZE, msg, fmt, tmp); |
362 | 250 |
251 // Test th_strdup_vprintf() | |
365 | 252 if (optFlags & TST_SUPERFLUOUS) |
253 { | |
254 test_start(&ctx, "th_strdup_vprintf('%s')", fmt); | |
255 va_copy(tmp, ap); | |
256 char *str = th_strdup_vprintf(fmt, tmp); | |
257 test_result_msg(&ctx, str != NULL, "result NULL"); | |
258 th_free(str); | |
259 test_end(&ctx); | |
260 } | |
362 | 261 |
441
2991e6b52d95
Get rid of trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
412
diff
changeset
|
262 va_end(ap); |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
263 tprint(2, |
291 | 264 "-----------------------------------------------------\n"); |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
265 } |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
266 |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
267 |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
268 BOOL test_set_start(const char *str) |
264
9b6fd2953d8c
Add test header printing function.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
269 { |
365 | 270 if (sets_enabled[sets_total++]) |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
271 { |
365 | 272 sets_nenabled++; |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
273 tprint(1, |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
274 "======================================================\n" |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
275 " Set #%d : %s tests\n" |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
276 "======================================================\n", |
365 | 277 sets_total, str); |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
278 |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
279 return TRUE; |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
280 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
281 else |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
282 return FALSE; |
264
9b6fd2953d8c
Add test header printing function.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
283 } |
9b6fd2953d8c
Add test header printing function.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
284 |
9b6fd2953d8c
Add test header printing function.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
285 |
327
b0f9f806c8c9
Implement NCOUNT() macro for getting array element counts (sizeof(arr) / sizeof(arr[0]))
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
286 #define NCOUNT(xxx) (sizeof(xxx) / sizeof(xxx[0])) |
b0f9f806c8c9
Implement NCOUNT() macro for getting array element counts (sizeof(arr) / sizeof(arr[0]))
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
287 |
b0f9f806c8c9
Implement NCOUNT() macro for getting array element counts (sizeof(arr) / sizeof(arr[0]))
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
288 |
263 | 289 #define TEST2(fun, str1, str2, ret) do { \ |
502
ebf89497305a
Remove some unused functionality for simplification.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
290 test_ctx ctx; \ |
303 | 291 test_start(&ctx, # fun "('%s', '%s')", str1, str2); \ |
292 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
|
293 test_end(&ctx); \ |
263 | 294 } while (0) |
295 | |
266 | 296 #define TEST2B(fun, str1, str2, ret) do { \ |
502
ebf89497305a
Remove some unused functionality for simplification.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
297 test_ctx ctx; \ |
303 | 298 test_start(&ctx, # fun "('%s', '%s')", str1, str2); \ |
299 test_result(&ctx, fun (str1, str2) == ret); \ | |
342
09c2f6abf694
Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents:
340
diff
changeset
|
300 test_end(&ctx); \ |
266 | 301 } while (0) |
302 | |
465 | 303 #define TEST2C(fun, str1, str2, ret) do { \ |
502
ebf89497305a
Remove some unused functionality for simplification.
Matti Hamalainen <ccr@tnsp.org>
parents:
501
diff
changeset
|
304 test_ctx ctx; \ |
465 | 305 test_start(&ctx, # fun "('%s', '%s')", str1, str2); \ |
306 test_result(&ctx, (fun (str1, str2) != NULL) == ret); \ | |
307 test_end(&ctx); \ | |
308 } while (0) | |
309 | |
263 | 310 #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
|
311 test_ctx ctx; \ |
303 | 312 test_start(&ctx, # fun "('%s', '%s', %d)", str1, str2, len); \ |
313 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
|
314 test_end(&ctx); \ |
263 | 315 } while (0) |
316 | |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
317 |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
318 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
|
319 { |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
320 th_cfgitem_t *item; |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
321 int nsubtest = 0; |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
322 test_ctx ctx; |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
323 |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
324 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
|
325 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
|
326 test_end(&ctx); |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
327 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
|
328 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
|
329 test_end(&ctx); |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
330 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
|
331 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
|
332 test_end(&ctx); |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
333 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
|
334 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
|
335 test_end(&ctx); |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
336 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
|
337 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
|
338 test_end(&ctx); |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
339 test_start(&ctx, "Test configuration value search #%d", ++nsubtest); |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
340 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
|
341 test_end(&ctx); |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
342 } |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
343 |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
344 |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
345 void test_free(th_llist_t *node) |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
346 { |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
347 th_free_r(&node->data); |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
348 } |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
349 |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
350 |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
351 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
|
352 { |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
353 (void) fh; |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
354 (void) val; |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
355 tprint(0, "IOCTX ERROR: %s", msg); |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
356 } |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
357 |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
358 |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
359 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
|
360 { |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
361 (void) fh; |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
362 (void) val; |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
363 tprint(1, "IOCTX MSG: %s", msg); |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
364 } |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
365 |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
366 |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
367 int test_strcmp(const void *v1, const void *v2) |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
368 { |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
369 return strcmp((const char *) v1, (const char *) v2); |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
370 } |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
371 |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
372 |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
373 static const char *test_strings[] = |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
374 { |
521
77495c646208
Fix parsing and writing of strings with simple escape sequences in config files.
Matti Hamalainen <ccr@tnsp.org>
parents:
517
diff
changeset
|
375 "zoo", "foo", "b\"ar", |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
376 }; |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
377 |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
378 static const int ntest_strings = sizeof(test_strings) / sizeof(test_strings[0]); |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
379 |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
380 |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
381 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
|
382 { |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
383 int nsubtest; |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
384 th_ioctx *fh = NULL; |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
385 test_ctx ctx; |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
386 th_cfgitem_t *item; |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
387 |
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
|
388 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
|
389 |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
390 // Attempt to read the previously written file |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
391 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
|
392 { |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
393 int err = th_get_error(); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
394 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
|
395 filename, err, th_error_str(err)); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
396 goto out; |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
397 } |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
398 |
516 | 399 th_io_set_handlers(fh, test_ioctx_error, test_ioctx_msg); |
400 | |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
401 th_cfg_read(fh, cfg); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
402 |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
403 // Test read values against expected values |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
404 test_config_values(cfg); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
405 |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
406 // Additional tests |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
407 item = th_cfg_find(cfg, NULL, "string_list", -1); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
408 test_result(&ctx, item != NULL); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
409 if (item != NULL) |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
410 { |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
411 static const char *nostr = "not to be found"; |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
412 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
|
413 |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
414 for (nsubtest = 0; nsubtest < ntest_strings; nsubtest++) |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
415 { |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
416 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
|
417 nsubtest + 1, test_strings[nsubtest]); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
418 |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
419 test_result(&ctx, |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
420 th_llist_find_func(*plist, |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
421 test_strings[nsubtest], test_strcmp) != NULL); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
422 test_end(&ctx); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
423 } |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
424 |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
425 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
|
426 ++nsubtest, nostr); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
427 test_result(&ctx, th_llist_find_func(*plist, nostr, test_strcmp) == NULL); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
428 test_end(&ctx); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
429 |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
430 th_llist_free_func_node(*plist, test_free); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
431 *plist = NULL; |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
432 } |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
433 |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
434 out: |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
435 th_io_free(fh); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
436 } |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
437 |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
438 |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
439 void test_config(void) |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
440 { |
513
e412a39e2b7a
Add another test for configuration parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
512
diff
changeset
|
441 static const char *filename = "cfg.temp"; |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
442 test_ctx ctx; |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
443 th_ioctx *fh = NULL; |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
444 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
|
445 char *v_str1 = NULL; |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
446 unsigned int v_uint1; |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
447 int v_int1; |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
448 BOOL v_bool1, v_bool2; |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
449 th_llist_t *v_str_list = NULL; |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
450 |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
451 // Create v_str_list |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
452 for (int n = 0; n < ntest_strings; n++) |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
453 th_llist_append(&v_str_list, th_strdup(test_strings[n])); |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
454 |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
455 // Create the configuration structure |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
456 tprint(2, "Creating configuration structure\n"); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
457 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
|
458 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
|
459 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
|
460 |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
461 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
|
462 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
|
463 |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
464 th_cfg_add_comment(§1, "A boolean value"); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
465 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
|
466 |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
467 th_cfg_add_comment(§1, "A string list"); |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
468 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
|
469 |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
470 th_cfg_add_section(&cfg, "general", sect1); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
471 |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
472 sect1 = NULL; |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
473 th_cfg_add_comment(§1, "Another section"); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
474 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
|
475 |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
476 sect2 = NULL; |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
477 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
|
478 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
|
479 th_cfg_add_section(§1, "inside_sect", sect2); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
480 |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
481 th_cfg_add_section(&cfg, "another_sect", sect1); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
482 |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
483 // Test ptr |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
484 test_start(&ctx, "Test configuration string list ptr"); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
485 test_result(&ctx, (item = th_cfg_find(cfg, NULL, "string_list", -1)) != NULL && item->v.list == &v_str_list); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
486 test_end(&ctx); |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
487 |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
488 // Test value finding |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
489 test_config_values(cfg); |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
490 |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
491 // Attempt to write the file |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
492 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
|
493 { |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
494 int err = th_get_error(); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
495 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
|
496 filename, err, th_error_str(err)); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
497 goto out; |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
498 } |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
499 |
516 | 500 th_io_set_handlers(fh, test_ioctx_error, test_ioctx_msg); |
501 | |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
502 th_cfg_write(fh, cfg); |
515
d512555bdd0f
Close written test config file before trying to read it.
Matti Hamalainen <ccr@tnsp.org>
parents:
513
diff
changeset
|
503 th_io_free(fh); |
d512555bdd0f
Close written test config file before trying to read it.
Matti Hamalainen <ccr@tnsp.org>
parents:
513
diff
changeset
|
504 fh = NULL; |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
505 |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
506 // Test against written configuration file |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
507 test_config_read(cfg, filename); |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
508 |
513
e412a39e2b7a
Add another test for configuration parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
512
diff
changeset
|
509 // Test against manually edited configuration file |
e412a39e2b7a
Add another test for configuration parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
512
diff
changeset
|
510 test_config_read(cfg, "cfg.test01"); |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
511 |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
512 out: |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
513 // Free the data for v_str_list |
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
514 th_io_free(fh); |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
515 th_llist_free_func_node(v_str_list, test_free); |
512
5c3bfe034915
Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
509
diff
changeset
|
516 v_str_list = NULL; |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
517 } |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
518 |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
519 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
520 int main(int argc, char *argv[]) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
521 { |
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
|
522 size_t i1, i2, i3, i4; |
326
75b22d6f8a71
Simplify and improve integer sprintf() tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
523 char buf[64], buf2[64]; |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
524 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
525 // |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
526 // Initialization |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
527 // |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
528 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
|
529 th_verbosity = 0; |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
530 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
531 if (sizeof(char) != sizeof(unsigned char)) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
532 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
533 THERR("sizeof(char) != sizeof(unsigned char)???\n"); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
534 return -1; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
535 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
536 |
365 | 537 tests_failed = tests_passed = tests_total = sets_total = sets_nenabled = 0; |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
538 for (i1 = 0; i1 < SET_MAX_TESTS; i1++) |
365 | 539 sets_enabled[i1] = 1; |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
540 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
541 // |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
542 // Parse command line arguments |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
543 // |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
544 if (!th_args_process(argc, argv, arg_opts, arg_nopts, |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
545 arg_handle_opt, NULL, 0)) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
546 return 0; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
547 |
365 | 548 tprint(1, "Enabled test types are 0x%04x.\n", optFlags); |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
549 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
550 // |
405 | 551 // Test series for printf() |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
552 // |
404 | 553 char *i_fmts[] = { "", "05", "5", ".5", "8.5", "08.5", "3", "3.2", "3", ".0", "0" }; |
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
|
554 char *i_mods[] = { "", "-", "+", "#", }; |
343 | 555 char *i_types[] = { "d", "u", "i", "x", "X", "o", }; |
295 | 556 if (test_set_start("printf() integer")) |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
557 { |
403 | 558 int i_vals[] = { 0, -0, -1, 2, -2, 512, -1024, 612342, -612342, 0x1fff, 0x8000000, -123456789 }; |
315 | 559 |
327
b0f9f806c8c9
Implement NCOUNT() macro for getting array element counts (sizeof(arr) / sizeof(arr[0]))
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
560 for (i1 = 0; i1 < NCOUNT(i_vals); i1++) |
315 | 561 { |
319 | 562 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
|
563 |
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
|
564 for (i4 = 0; i4 < NCOUNT(i_mods); i4++) |
332 | 565 for (i3 = 0; i3 < NCOUNT(i_types); i3++) |
566 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
|
567 { |
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
|
568 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
|
569 test_snprintf(buf, buf2, i_vals[i1]); |
75b22d6f8a71
Simplify and improve integer sprintf() tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
570 } |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
571 } |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
572 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
573 |
331
6e42d50c08c4
Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
574 if (test_set_start("printf() integer 64bit")) |
6e42d50c08c4
Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
575 { |
333 | 576 int64_t i_vals64[] = { 0, -0, -1, 2, -2, 612342, -612342, 0x3342344341fff, 0x1f8000000, }; |
331
6e42d50c08c4
Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
577 |
333 | 578 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
|
579 { |
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
|
580 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
|
581 |
340 | 582 for (i4 = 0; i4 < NCOUNT(i_mods); i4++) |
332 | 583 for (i3 = 0; i3 < NCOUNT(i_types); i3++) |
584 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
|
585 { |
402 | 586 snprintf(buf2, sizeof(buf2), "%%%s%sll%s", i_mods[i4], i_fmts[i2], i_types[i3]); |
333 | 587 test_snprintf(buf, buf2, i_vals64[i1]); |
331
6e42d50c08c4
Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
588 } |
6e42d50c08c4
Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
589 } |
6e42d50c08c4
Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
590 } |
6e42d50c08c4
Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
591 |
296
ec8357d02a52
Add floating point tests (which will fail for now).
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
592 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
|
593 { |
345 | 594 double f_vals[] = { 1, 2, 3, 2.02, 612342.234, -2.07, -612342.12, 437692.9876543219, 0x1fff, 0x8000000, 0.15625 }; |
404 | 595 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
|
596 |
327
b0f9f806c8c9
Implement NCOUNT() macro for getting array element counts (sizeof(arr) / sizeof(arr[0]))
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
597 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
|
598 { |
319 | 599 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
|
600 for (i2 = 0; i2 < NCOUNT(f_fmts); i2++) |
319 | 601 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
|
602 } |
296
ec8357d02a52
Add floating point tests (which will fail for now).
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
603 } |
ec8357d02a52
Add floating point tests (which will fail for now).
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
604 |
295 | 605 if (test_set_start("printf() string")) |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
606 { |
407 | 607 char *s_vals[] = { "", "XYZXYZ", "xxx yyy zzz ppp fff", NULL, "X", "abcde", "dx", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", }; |
301 | 608 char *s_fmts[] = { "%s", "%2s", "%-2s", "%5s", "%-5s", "%16s", "%-16s", "%1s", "%-1s", "% 2s", "%03s", "% -12s", "% 03s", "%-.15s", "%.8s" }; |
265 | 609 |
327
b0f9f806c8c9
Implement NCOUNT() macro for getting array element counts (sizeof(arr) / sizeof(arr[0]))
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
610 for (i1 = 0; i1 < NCOUNT(s_vals); i1++) |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
611 { |
327
b0f9f806c8c9
Implement NCOUNT() macro for getting array element counts (sizeof(arr) / sizeof(arr[0]))
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
612 for (i2 = 0; i2 < NCOUNT(s_fmts); i2++) |
319 | 613 test_snprintf(s_vals[i1], s_fmts[i2], s_vals[i1]); |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
614 } |
288 | 615 } |
616 | |
295 | 617 if (test_set_start("printf() char")) |
288 | 618 { |
319 | 619 const char c_val = 'x'; |
620 const char *c_msg = "x"; | |
352 | 621 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
|
622 |
0146aa9a9524
Simplify char printf tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
327
diff
changeset
|
623 for (i1 = 0; i1 < NCOUNT(c_fmts); i1++) |
0146aa9a9524
Simplify char printf tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
327
diff
changeset
|
624 test_snprintf(c_msg, c_fmts[i1], c_val); |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
625 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
626 |
356
d7f43fce0dce
Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
627 if (test_set_start("printf() pointers")) |
d7f43fce0dce
Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
628 { |
407 | 629 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
|
630 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
|
631 |
d7f43fce0dce
Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
632 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
|
633 { |
d7f43fce0dce
Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
634 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
|
635 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
|
636 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
|
637 } |
d7f43fce0dce
Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
638 } |
d7f43fce0dce
Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents:
352
diff
changeset
|
639 |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
640 // |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
641 // String matching functions |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
642 // |
465 | 643 if (test_set_start("String compare #1")) |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
644 { |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
645 TEST2(th_strcasecmp, "aSdFq", "asdfq", TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
646 TEST2(th_strcasecmp, "aSdFq", "asFfq", FALSE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
647 TEST2(th_strcasecmp, "abcde", "abcde", TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
648 TEST2(th_strcasecmp, "öäå", "öäå", TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
649 TEST2(th_strcasecmp, "aöäå", "aöäå", TRUE); |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
650 } |
255 | 651 |
465 | 652 if (test_set_start("String compare #2")) |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
653 { |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
654 TEST3(th_strncasecmp, "aSdFq", "asFfqB", 4, FALSE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
655 TEST3(th_strncasecmp, "aSdFq", "asFfqQ", 2, TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
656 TEST3(th_strncasecmp, "aSdFq", "asDfq", 3, TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
657 TEST3(th_strncasecmp, "aSdFq", "asDfq", 2, TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
658 TEST3(th_strncasecmp, "aSdFq", "asDfq", 0, TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
659 TEST3(th_strncasecmp, "aSdFq", "QsDfq", 0, TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
660 TEST3(th_strncasecmp, "aSdFq", "QsDfq", 1, FALSE); |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
661 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
662 |
465 | 663 if (test_set_start("String compare #3")) |
664 { | |
665 TEST2C(th_strrcasecmp, "foo aSdFq", " asdfq", TRUE); | |
666 TEST2C(th_strrcasecmp, "aSdFq", " asdfq", FALSE); | |
667 TEST2C(th_strrcasecmp, "foo aSdFq baz", "asdfq", FALSE); | |
668 } | |
669 | |
670 if (test_set_start("String matching #1")) | |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
671 { |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
672 TEST2B(th_strmatch, "abba ABBAkukka lol", "*lol", TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
673 TEST2B(th_strmatch, "abba ABBAkukka lol", "*lo*", TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
674 TEST2B(th_strmatch, "abba ABBAkukka lol", "*lo", FALSE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
675 TEST2B(th_strmatch, "abba ABBAkukka lol", "abba", FALSE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
676 TEST2B(th_strmatch, "abba ABBAkukka lol", "*bba*", TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
677 TEST2B(th_strmatch, "abba ABBAkukka lol", "abba*", TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
678 TEST2B(th_strmatch, "abba ABBAkukka lol", "abbak*", FALSE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
679 TEST2B(th_strmatch, "abba ABBAöökukka lol", "*abbaö?", FALSE); |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
680 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
681 |
465 | 682 if (test_set_start("String matching #2")) |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
683 { |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
684 TEST2B(th_strcasematch, "abba ABBAkukka lol", "abbak*", FALSE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
685 TEST2B(th_strcasematch, "abba ABBAkukka lol", "*abbak*", TRUE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
686 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
|
687 TEST2B(th_strcasematch, "abba ABBAkukka lol", "*abbak?", FALSE); |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
688 TEST2B(th_strcasematch, "abba ABBAkukka lol", "?bba?abba*", TRUE); |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
689 } |
266 | 690 |
265 | 691 // Tests that test for things that do not work correctly yet |
692 // Unicode / multibyte UTF-8 causes problems here | |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
693 if ((optFlags & TST_BROKEN) && |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
694 test_set_start("Invalid UTF-8 handling")) |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
695 { |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
696 TEST2(th_strcasecmp, "ÖÄÅ", "öäå", FALSE); // SHOULD match |
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
697 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
|
698 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
|
699 } |
266 | 700 |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
701 // |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
702 // printf() PRI* format specifiers, also a compile time test |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
703 // |
501 | 704 if (test_set_start("PRI* specifiers")) |
492
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
705 { |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
706 char tmp[32]; |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
707 uint32_t u32 = 0xaabbccdd; |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
708 uint64_t u64 = 0xaabbccdd11223344; |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
709 size_t usiz = |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
710 #if TH_ARCH == 32 |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
711 0x11223344; |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
712 #elif TH_ARCH == 64 |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
713 0xaabbccdd11223344; |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
714 #else |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
715 #error Unsupported TH_ARCH value. |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
716 #endif |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
717 |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
718 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
|
719 #if TH_ARCH == 32 |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
720 TEST2(strcmp, tmp, "0000000011223344h", TRUE); |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
721 #else |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
722 TEST2(strcmp, tmp, "aabbccdd11223344h", TRUE); |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
723 #endif |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
724 |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
725 snprintf(tmp, sizeof(tmp), "%08" PRIx32 "h", u32); |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
726 TEST2(strcmp, tmp, "aabbccddh", TRUE); |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
727 snprintf(tmp, sizeof(tmp), "%16" PRIx64 "h", u64); |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
728 TEST2(strcmp, tmp, "aabbccdd11223344h", TRUE); |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
729 } |
185a6ea03fea
Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
730 |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
731 |
508
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
732 // |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
733 // Configuration file handling |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
734 // |
fe5e7bf704e5
Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
506
diff
changeset
|
735 if (test_set_start("Config file handling")) |
505
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
736 { |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
737 test_config(); |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
738 } |
50d71fc84831
Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents:
502
diff
changeset
|
739 |
255 | 740 // |
741 // Print summary and exit | |
742 // | |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
743 tprint(1, |
276
56b0de9f9d44
Improve tests output per verbosity level.
Matti Hamalainen <ccr@tnsp.org>
parents:
274
diff
changeset
|
744 "======================================================\n"); |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
745 |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
746 tprint(0, |
312 | 747 "%d tests failed, %d passed (%d main tests), %d test sets of %d sets total.\n\n", |
365 | 748 tests_failed, tests_passed, tests_total, sets_nenabled, sets_total); |
255 | 749 |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
750 return 0; |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
751 } |