Mercurial > hg > th-libs
annotate tests.c @ 340:cde5415c4201
Fix 64bit int tests.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 23 Feb 2016 17:39:14 +0200 |
parents | 46a0fab6ca1f |
children | 09c2f6abf694 |
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" |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 #define SET_BUF_SIZE 128 |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
8 #define SET_MAX_TESTS 64 |
291 | 9 #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
|
10 |
291 | 11 |
303 | 12 typedef struct |
13 { | |
14 char *header, *res; | |
15 } test_ctx; | |
16 | |
17 | |
291 | 18 // Globals |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
19 int tests_failed, tests_passed, tests_total, tests_sets, tests_nenabled; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
20 int tests_enabled[SET_MAX_TESTS]; |
259 | 21 |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 char buf1[SET_BUF_SIZE+2], buf2[SET_BUF_SIZE+2]; |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 |
274
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
25 // Define option arguments |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
26 static const th_optarg_t arg_opts[] = |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
27 { |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
28 { 0, '?', "help", "Show this help", OPT_NONE }, |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
29 { 1, 'v', "verbose", "Be more verbose", OPT_NONE }, |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
30 { 2, 't', "tests", "Perform tests -t <set>[,<set2>..]", OPT_ARGREQ }, |
274
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
31 }; |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
32 |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
33 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
|
34 |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
35 |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
36 void tprintv(const int level, const char *fmt, va_list ap) |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
37 { |
311
31668615083e
Fix test printing function :S
Matti Hamalainen <ccr@tnsp.org>
parents:
306
diff
changeset
|
38 if (level <= th_verbosityLevel) |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
39 vfprintf(stdout, fmt, ap); |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
40 } |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
41 |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
42 |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
43 void tprint(const int level, const char *fmt, ...) |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
44 { |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
45 va_list ap; |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
46 va_start(ap, fmt); |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
47 tprintv(level, fmt, ap); |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
48 va_end(ap); |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
49 } |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
50 |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
51 |
274
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
52 void arg_show_help(void) |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
53 { |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
54 th_print_banner(stdout, th_prog_name, "[options]"); |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
55 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
|
56 } |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
57 |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
58 |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
59 BOOL arg_handle_opt(const int optN, char *optArg, char *currArg) |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
60 { |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
61 switch (optN) |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
62 { |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
63 case 0: |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
64 arg_show_help(); |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
65 exit(0); |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
66 break; |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
67 |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
68 case 1: |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
69 th_verbosityLevel++; |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
70 break; |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
71 |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
72 case 2: |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
73 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
74 BOOL ret = TRUE; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
75 char *pos, *pstr, *next; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
76 pos = pstr = th_strdup(optArg); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
77 memset(tests_enabled, 0, sizeof(tests_enabled)); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
78 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
79 do { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
80 next = strchr(pos, ','); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
81 if (next != NULL) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
82 *next = 0; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
83 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
84 char *tmp = th_strdup_trim(pos, TH_TRIM_BOTH); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
85 if (tmp != NULL) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
86 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
87 int val = atoi(tmp); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
88 if (val > 0 && val <= SET_MAX_TESTS) |
300
385d0b40a6c8
Fix -t option handling, had a off-by one in value handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
296
diff
changeset
|
89 tests_enabled[val - 1] = 1; |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
90 else |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
91 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
92 THERR("Invalid test number #%d, out of range [%d .. %d]\n", val, 1, SET_MAX_TESTS); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
93 ret = FALSE; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
94 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
95 th_free(tmp); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
96 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
97 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
98 if (next != NULL) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
99 pos = next + 1; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
100 } while (next != NULL); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
101 th_free(pstr); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
102 return ret; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
103 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
104 break; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
105 |
274
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
106 default: |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
107 THERR("Unknown option '%s'.\n", currArg); |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
108 return FALSE; |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
109 } |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
110 |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
111 return TRUE; |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
112 } |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
113 |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
114 |
303 | 115 void test_init(test_ctx *ctx) |
116 { | |
117 memset(ctx, 0, sizeof(test_ctx)); | |
118 } | |
119 | |
120 | |
121 void test_start_v(test_ctx *ctx, const char *fmt, va_list ap) | |
259 | 122 { |
123 tests_total++; | |
124 | |
303 | 125 th_free_r(&ctx->header); |
126 th_free_r(&ctx->res); | |
259 | 127 |
303 | 128 ctx->header = th_strdup_vprintf(fmt, ap); |
259 | 129 } |
130 | |
131 | |
303 | 132 void test_start(test_ctx *ctx, const char *fmt, ...) |
259 | 133 { |
134 va_list ap; | |
135 va_start(ap, fmt); | |
303 | 136 test_start_v(ctx, fmt, ap); |
259 | 137 va_end(ap); |
138 } | |
139 | |
140 | |
303 | 141 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
|
142 { |
259 | 143 if (check) |
144 { | |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
145 tprint(2, "%s: OK\n", ctx->header); |
259 | 146 tests_passed++; |
147 } | |
148 else | |
149 { | |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
150 tprint(0, "%s: FAIL\n", ctx->header); |
259 | 151 if (fmt != NULL) |
263 | 152 { |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
153 tprint(0, " - "); |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
154 tprintv(0, fmt, ap); |
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
155 tprint(0, "\n"); |
263 | 156 } |
303 | 157 if (ctx->res != NULL) |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
158 tprint(0, "%s\n", ctx->res); |
259 | 159 tests_failed++; |
160 } | |
161 } | |
162 | |
163 | |
305
5afd918cbd79
Have a return value for test result functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
304
diff
changeset
|
164 BOOL test_result_msg(test_ctx *ctx, BOOL check, const char *fmt, ...) |
259 | 165 { |
166 va_list ap; | |
167 va_start(ap, fmt); | |
303 | 168 test_result_msg_v(ctx, check, fmt, ap); |
259 | 169 va_end(ap); |
305
5afd918cbd79
Have a return value for test result functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
304
diff
changeset
|
170 return check; |
259 | 171 } |
172 | |
173 | |
305
5afd918cbd79
Have a return value for test result functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
304
diff
changeset
|
174 BOOL test_result(test_ctx *ctx, BOOL check) |
259 | 175 { |
303 | 176 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
|
177 return check; |
259 | 178 } |
179 | |
180 | |
181 | |
319 | 182 void test_snprintf_do(size_t len, const char *msg, const char *fmt, va_list ap) |
259 | 183 { |
184 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
|
185 va_list tmp; |
303 | 186 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
|
187 |
263 | 188 // Test basic *printf() functionality |
303 | 189 test_init(&ctx); |
319 | 190 test_start(&ctx, "th_vsnprintf(%" TH_PRIu_SIZE_T ", \"%s\", %s)", len, fmt, msg); |
259 | 191 |
192 memset(buf1, SET_SENTINEL_BYTE, SET_BUF_SIZE+2); buf1[SET_BUF_SIZE+1] = 0; | |
193 memset(buf2, SET_SENTINEL_BYTE, SET_BUF_SIZE+2); buf2[SET_BUF_SIZE+1] = 0; | |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 |
339
46a0fab6ca1f
Fix snprintf() test running.
Matti Hamalainen <ccr@tnsp.org>
parents:
338
diff
changeset
|
195 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
|
196 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
|
197 |
303 | 198 test_result_msg(&ctx, ret1 == ret2, "retval mismatch %d [th] != %d [libc]", ret1, ret2); |
199 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
|
200 |
303 | 201 test_result_msg(&ctx, (unsigned char) buf1[len] == SET_SENTINEL_BYTE, "buffer #1 overflow, sentinel 0x%02x", buf1[len]); |
202 test_result_msg(&ctx, (unsigned char) buf2[len] == SET_SENTINEL_BYTE, "buffer #2 overflow, sentinel 0x%02x", buf2[len]); | |
261 | 203 |
263 | 204 // Test th_strdup_vprintf() |
303 | 205 test_start(&ctx, "th_strdup_vprintf('%s')", fmt); |
339
46a0fab6ca1f
Fix snprintf() test running.
Matti Hamalainen <ccr@tnsp.org>
parents:
338
diff
changeset
|
206 va_copy(tmp, ap); |
46a0fab6ca1f
Fix snprintf() test running.
Matti Hamalainen <ccr@tnsp.org>
parents:
338
diff
changeset
|
207 char *str = th_strdup_vprintf(fmt, tmp); |
303 | 208 test_result_msg(&ctx, str != NULL, "result NULL"); |
261 | 209 th_free(str); |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
210 } |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
211 |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
212 |
319 | 213 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
|
214 { |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
215 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
|
216 va_start(ap, fmt); |
319 | 217 va_copy(tmp, ap); test_snprintf_do(0, msg, fmt, tmp); |
218 va_copy(tmp, ap); test_snprintf_do(1, msg, fmt, tmp); | |
219 va_copy(tmp, ap); test_snprintf_do(2, msg, fmt, tmp); | |
220 va_copy(tmp, ap); test_snprintf_do(16, msg, fmt, tmp); | |
221 va_copy(tmp, ap); test_snprintf_do(SET_BUF_SIZE, msg, fmt, tmp); | |
255 | 222 va_end(ap); |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
223 tprint(2, |
291 | 224 "-----------------------------------------------------\n"); |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
225 } |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
226 |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
227 |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
228 BOOL test_set_start(const char *str) |
264
9b6fd2953d8c
Add test header printing function.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
229 { |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
230 if (tests_enabled[tests_sets++]) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
231 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
232 tests_nenabled++; |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
233 tprint(1, |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
234 "======================================================\n" |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
235 " Set #%d : %s tests\n" |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
236 "======================================================\n", |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
237 tests_sets, str); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
238 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
239 return TRUE; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
240 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
241 else |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
242 return FALSE; |
264
9b6fd2953d8c
Add test header printing function.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
243 } |
9b6fd2953d8c
Add test header printing function.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
244 |
9b6fd2953d8c
Add test header printing function.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
245 |
327
b0f9f806c8c9
Implement NCOUNT() macro for getting array element counts (sizeof(arr) / sizeof(arr[0]))
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
246 #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
|
247 |
b0f9f806c8c9
Implement NCOUNT() macro for getting array element counts (sizeof(arr) / sizeof(arr[0]))
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
248 |
263 | 249 #define TEST2(fun, str1, str2, ret) do { \ |
303 | 250 test_ctx ctx; test_init(&ctx); \ |
251 test_start(&ctx, # fun "('%s', '%s')", str1, str2); \ | |
252 test_result(&ctx, ( fun (str1, str2) == 0) == ret); \ | |
263 | 253 } while (0) |
254 | |
266 | 255 #define TEST2B(fun, str1, str2, ret) do { \ |
303 | 256 test_ctx ctx; test_init(&ctx); \ |
257 test_start(&ctx, # fun "('%s', '%s')", str1, str2); \ | |
258 test_result(&ctx, fun (str1, str2) == ret); \ | |
266 | 259 } while (0) |
260 | |
263 | 261 #define TEST3(fun, str1, str2, len, ret) do { \ |
303 | 262 test_ctx ctx; test_init(&ctx); \ |
263 test_start(&ctx, # fun "('%s', '%s', %d)", str1, str2, len); \ | |
264 test_result(&ctx, ( fun (str1, str2, len) == 0) == ret); \ | |
263 | 265 } while (0) |
266 | |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
267 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
268 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
269 int main(int argc, char *argv[]) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
270 { |
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
|
271 size_t i1, i2, i3, i4; |
326
75b22d6f8a71
Simplify and improve integer sprintf() tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
272 char buf[64], buf2[64]; |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
273 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
274 // |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
275 // Initialization |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
276 // |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
277 th_init("th-test", "th-libs unit tests", "0.0.1", NULL, NULL); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
278 th_verbosityLevel = 0; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
279 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
280 if (sizeof(char) != sizeof(unsigned char)) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
281 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
282 THERR("sizeof(char) != sizeof(unsigned char)???\n"); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
283 return -1; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
284 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
285 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
286 tests_failed = tests_passed = tests_total = tests_sets = tests_nenabled = 0; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
287 for (i1 = 0; i1 < SET_MAX_TESTS; i1++) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
288 tests_enabled[i1] = 1; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
289 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
290 // |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
291 // Parse command line arguments |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
292 // |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
293 if (!th_args_process(argc, argv, arg_opts, arg_nopts, |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
294 arg_handle_opt, NULL, 0)) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
295 return 0; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
296 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
297 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
298 // |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
299 // Test series #1 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
300 // |
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
|
301 char *i_fmts[] = { "", "05", "5", "5", ".5", "5.5", "05.5", "3", "3.2", "3", }; |
b90173719330
Add more tests (some of which will fail for now due to unimplemented features).
Matti Hamalainen <ccr@tnsp.org>
parents:
333
diff
changeset
|
302 char *i_mods[] = { "", "-", "+", "#", }; |
333 | 303 char *i_types[] = { "d", "x", "X", "o", }; |
295 | 304 if (test_set_start("printf() integer")) |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
305 { |
312 | 306 int i_vals[] = { 0, -0, -1, 2, -2, 612342, -612342, 0x1fff, 0x8000000, }; |
315 | 307 |
327
b0f9f806c8c9
Implement NCOUNT() macro for getting array element counts (sizeof(arr) / sizeof(arr[0]))
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
308 for (i1 = 0; i1 < NCOUNT(i_vals); i1++) |
315 | 309 { |
319 | 310 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
|
311 |
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
|
312 for (i4 = 0; i4 < NCOUNT(i_mods); i4++) |
332 | 313 for (i3 = 0; i3 < NCOUNT(i_types); i3++) |
314 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
|
315 { |
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
|
316 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
|
317 test_snprintf(buf, buf2, i_vals[i1]); |
75b22d6f8a71
Simplify and improve integer sprintf() tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
319
diff
changeset
|
318 } |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
319 } |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
320 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
321 |
331
6e42d50c08c4
Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
322 if (test_set_start("printf() integer 64bit")) |
6e42d50c08c4
Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
323 { |
333 | 324 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
|
325 |
333 | 326 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
|
327 { |
338 | 328 snprintf(buf, sizeof(buf), "%" TH_PRId64, i_vals64[i1]); |
331
6e42d50c08c4
Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
329 |
340 | 330 for (i4 = 0; i4 < NCOUNT(i_mods); i4++) |
332 | 331 for (i3 = 0; i3 < NCOUNT(i_types); i3++) |
332 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
|
333 { |
340 | 334 snprintf(buf2, sizeof(buf2), "%s%sll%s", i_mods[i4], i_fmts[i2], i_types[i3]); |
333 | 335 test_snprintf(buf, buf2, i_vals64[i1]); |
331
6e42d50c08c4
Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
336 } |
6e42d50c08c4
Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
337 } |
6e42d50c08c4
Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
338 } |
6e42d50c08c4
Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
328
diff
changeset
|
339 |
296
ec8357d02a52
Add floating point tests (which will fail for now).
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
340 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
|
341 { |
317
c532088b4f05
Fix float tests (type was int) :D
Matti Hamalainen <ccr@tnsp.org>
parents:
315
diff
changeset
|
342 double f_vals[] = { 2.02, 612342.234, -2.07, -612342.12, 437692.9876543219, 0x1fff, 0x8000000, }; |
315 | 343 char *f_fmts[] = { "%f", "%1.1f", "%5.5f", "%5f", "%-5f", "", "%-2.2f", "%05.5f" }; |
296
ec8357d02a52
Add floating point tests (which will fail for now).
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
344 |
327
b0f9f806c8c9
Implement NCOUNT() macro for getting array element counts (sizeof(arr) / sizeof(arr[0]))
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
345 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
|
346 { |
319 | 347 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
|
348 for (i2 = 0; i2 < NCOUNT(f_fmts); i2++) |
319 | 349 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
|
350 } |
296
ec8357d02a52
Add floating point tests (which will fail for now).
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
351 } |
ec8357d02a52
Add floating point tests (which will fail for now).
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
352 |
295 | 353 if (test_set_start("printf() string")) |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
354 { |
289 | 355 char *s_vals[] = { "", "XYZXYZ", "xxx yyy zzz ppp fff", NULL, "X", "abcde", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", }; |
301 | 356 char *s_fmts[] = { "%s", "%2s", "%-2s", "%5s", "%-5s", "%16s", "%-16s", "%1s", "%-1s", "% 2s", "%03s", "% -12s", "% 03s", "%-.15s", "%.8s" }; |
265 | 357 |
327
b0f9f806c8c9
Implement NCOUNT() macro for getting array element counts (sizeof(arr) / sizeof(arr[0]))
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
358 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
|
359 { |
327
b0f9f806c8c9
Implement NCOUNT() macro for getting array element counts (sizeof(arr) / sizeof(arr[0]))
Matti Hamalainen <ccr@tnsp.org>
parents:
326
diff
changeset
|
360 for (i2 = 0; i2 < NCOUNT(s_fmts); i2++) |
319 | 361 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
|
362 } |
288 | 363 } |
364 | |
295 | 365 if (test_set_start("printf() char")) |
288 | 366 { |
319 | 367 const char c_val = 'x'; |
368 const char *c_msg = "x"; | |
328
0146aa9a9524
Simplify char printf tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
327
diff
changeset
|
369 char *c_fmts[] = { "a%cBC", "%c", "", "%0c", "%1c", "% c", "%-3c", "%3c", "%.3c", "%-.3c", "%-3.3c", "%.c" }; |
0146aa9a9524
Simplify char printf tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
327
diff
changeset
|
370 |
0146aa9a9524
Simplify char printf tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
327
diff
changeset
|
371 for (i1 = 0; i1 < NCOUNT(c_fmts); i1++) |
0146aa9a9524
Simplify char printf tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
327
diff
changeset
|
372 test_snprintf(c_msg, c_fmts[i1], c_val); |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
373 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
374 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
375 // |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
376 // String matching functions |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
377 // |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
378 if (test_set_start("String matching #1")) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
379 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
380 TEST2(th_strcasecmp, "aSdFq", "asdfq", TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
381 TEST2(th_strcasecmp, "aSdFq", "asFfq", FALSE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
382 TEST2(th_strcasecmp, "abcde", "abcde", TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
383 TEST2(th_strcasecmp, "öäå", "öäå", TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
384 TEST2(th_strcasecmp, "aöäå", "aöäå", TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
385 } |
255 | 386 |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
387 if (test_set_start("String matching #2")) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
388 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
389 TEST3(th_strncasecmp, "aSdFq", "asFfq", 4, FALSE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
390 TEST3(th_strncasecmp, "aSdFq", "asFfq", 2, TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
391 TEST3(th_strncasecmp, "aSdFq", "asDfq", 3, TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
392 TEST3(th_strncasecmp, "aSdFq", "asDfq", 2, TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
393 TEST3(th_strncasecmp, "aSdFq", "asDfq", 0, TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
394 TEST3(th_strncasecmp, "aSdFq", "QsDfq", 0, TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
395 TEST3(th_strncasecmp, "aSdFq", "QsDfq", 1, FALSE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
396 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
397 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
398 if (test_set_start("String matching #3")) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
399 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
400 TEST2B(th_strmatch, "abba ABBAkukka lol", "*lol", TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
401 TEST2B(th_strmatch, "abba ABBAkukka lol", "*lo*", TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
402 TEST2B(th_strmatch, "abba ABBAkukka lol", "*lo", FALSE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
403 TEST2B(th_strmatch, "abba ABBAkukka lol", "abba", FALSE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
404 TEST2B(th_strmatch, "abba ABBAkukka lol", "abba*", TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
405 TEST2B(th_strmatch, "abba ABBAkukka lol", "abbak*", FALSE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
406 TEST2B(th_strmatch, "abba ABBAöökukka lol", "*abbaö?", FALSE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
407 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
408 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
409 if (test_set_start("String matching #4")) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
410 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
411 TEST2B(th_strcasematch, "abba ABBAkukka lol", "abbak*", FALSE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
412 TEST2B(th_strcasematch, "abba ABBAkukka lol", "*abbak*", TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
413 TEST2B(th_strcasematch, "abba ABBAkukka lol", "*abbak?", FALSE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
414 TEST2B(th_strcasematch, "abba ABBAkukka lol", "?bba?abba*", TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
415 } |
266 | 416 |
265 | 417 // Tests that test for things that do not work correctly yet |
418 // Unicode / multibyte UTF-8 causes problems here | |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
419 if (test_set_start("Invalid")) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
420 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
421 TEST2(th_strcasecmp, "ÖÄÅ", "öäå", FALSE); // SHOULD match |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
422 TEST3(th_strncasecmp, "Aäöå", "aöå", 2, TRUE); // should NOT match |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
423 TEST2B(th_strmatch, "öriÖRI! lol", "?ri?RI!*", FALSE); // should match |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
424 } |
266 | 425 |
255 | 426 // |
427 // Print summary and exit | |
428 // | |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
429 tprint(1, |
276
56b0de9f9d44
Improve tests output per verbosity level.
Matti Hamalainen <ccr@tnsp.org>
parents:
274
diff
changeset
|
430 "======================================================\n"); |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
431 |
304
3fcf42cce43d
Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents:
303
diff
changeset
|
432 tprint(0, |
312 | 433 "%d tests failed, %d passed (%d main tests), %d test sets of %d sets total.\n\n", |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
434 tests_failed, tests_passed, tests_total, tests_nenabled, tests_sets); |
255 | 435 |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
436 return 0; |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
437 } |