Mercurial > hg > th-libs
annotate tests.c @ 303:54ea7a73e5fa
Implement test contexts.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 22 Feb 2016 19:39:14 +0200 |
parents | 5a758be2769e |
children | 3fcf42cce43d |
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 |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
36 void arg_show_help(void) |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
37 { |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
38 th_print_banner(stdout, th_prog_name, "[options]"); |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
39 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
|
40 } |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
41 |
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 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
|
44 { |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
45 switch (optN) |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
46 { |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
47 case 0: |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
48 arg_show_help(); |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
49 exit(0); |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
50 break; |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
51 |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
52 case 1: |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
53 th_verbosityLevel++; |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
54 break; |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
55 |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
56 case 2: |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
57 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
58 BOOL ret = TRUE; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
59 char *pos, *pstr, *next; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
60 pos = pstr = th_strdup(optArg); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
61 memset(tests_enabled, 0, sizeof(tests_enabled)); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
62 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
63 do { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
64 next = strchr(pos, ','); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
65 if (next != NULL) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
66 *next = 0; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
67 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
68 char *tmp = th_strdup_trim(pos, TH_TRIM_BOTH); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
69 if (tmp != NULL) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
70 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
71 int val = atoi(tmp); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
72 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
|
73 tests_enabled[val - 1] = 1; |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
74 else |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
75 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
76 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
|
77 ret = FALSE; |
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 th_free(tmp); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
80 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
81 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
82 if (next != NULL) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
83 pos = next + 1; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
84 } while (next != NULL); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
85 th_free(pstr); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
86 return ret; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
87 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
88 break; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
89 |
274
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
90 default: |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
91 THERR("Unknown option '%s'.\n", currArg); |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
92 return FALSE; |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
93 } |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
94 |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
95 return TRUE; |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
96 } |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
97 |
f875db8634b6
Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents:
272
diff
changeset
|
98 |
303 | 99 void test_init(test_ctx *ctx) |
100 { | |
101 memset(ctx, 0, sizeof(test_ctx)); | |
102 } | |
103 | |
104 | |
105 void test_start_v(test_ctx *ctx, const char *fmt, va_list ap) | |
259 | 106 { |
107 tests_total++; | |
108 | |
303 | 109 th_free_r(&ctx->header); |
110 th_free_r(&ctx->res); | |
259 | 111 |
303 | 112 ctx->header = th_strdup_vprintf(fmt, ap); |
259 | 113 } |
114 | |
115 | |
303 | 116 void test_start(test_ctx *ctx, const char *fmt, ...) |
259 | 117 { |
118 va_list ap; | |
119 va_start(ap, fmt); | |
303 | 120 test_start_v(ctx, fmt, ap); |
259 | 121 va_end(ap); |
122 } | |
123 | |
124 | |
303 | 125 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
|
126 { |
259 | 127 if (check) |
128 { | |
303 | 129 THPRINT(2, "%s: OK\n", ctx->header); |
259 | 130 tests_passed++; |
131 } | |
132 else | |
133 { | |
303 | 134 THPRINT(0, "%s: FAIL\n", ctx->header); |
259 | 135 if (fmt != NULL) |
263 | 136 { |
137 THPRINT(0, " - "); | |
259 | 138 THPRINT_V(0, fmt, ap); |
263 | 139 THPRINT(0, "\n"); |
140 } | |
303 | 141 if (ctx->res != NULL) |
142 THPRINT(0, "%s\n", ctx->res); | |
259 | 143 tests_failed++; |
144 } | |
145 } | |
146 | |
147 | |
303 | 148 void test_result_msg(test_ctx *ctx, BOOL check, const char *fmt, ...) |
259 | 149 { |
150 va_list ap; | |
151 va_start(ap, fmt); | |
303 | 152 test_result_msg_v(ctx, check, fmt, ap); |
259 | 153 va_end(ap); |
154 } | |
155 | |
156 | |
303 | 157 void test_result(test_ctx *ctx, BOOL check) |
259 | 158 { |
303 | 159 test_result_msg_v(ctx, check, NULL, NULL); |
259 | 160 } |
161 | |
162 | |
163 | |
164 void test_snprintf_do(size_t len, const char *fmt, va_list ap, const char *msg) | |
165 { | |
166 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
|
167 va_list tmp; |
303 | 168 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
|
169 |
263 | 170 // Test basic *printf() functionality |
303 | 171 test_init(&ctx); |
172 test_start(&ctx, "th_vsnprintf('%s', %s)", fmt, msg); | |
259 | 173 |
174 memset(buf1, SET_SENTINEL_BYTE, SET_BUF_SIZE+2); buf1[SET_BUF_SIZE+1] = 0; | |
175 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
|
176 |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 va_copy(tmp, ap); |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
179 ret1 = th_vsnprintf(buf1, len, fmt, ap); |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
180 ret2 = vsnprintf(buf2, len, fmt, tmp); |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 |
303 | 182 test_result_msg(&ctx, ret1 == ret2, "retval mismatch %d [th] != %d [libc]", ret1, ret2); |
183 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
|
184 |
303 | 185 test_result_msg(&ctx, (unsigned char) buf1[len] == SET_SENTINEL_BYTE, "buffer #1 overflow, sentinel 0x%02x", buf1[len]); |
186 test_result_msg(&ctx, (unsigned char) buf2[len] == SET_SENTINEL_BYTE, "buffer #2 overflow, sentinel 0x%02x", buf2[len]); | |
261 | 187 |
263 | 188 // Test th_strdup_vprintf() |
303 | 189 test_start(&ctx, "th_strdup_vprintf('%s')", fmt); |
261 | 190 char *str = th_strdup_vprintf(fmt, ap); |
303 | 191 test_result_msg(&ctx, str != NULL, "result NULL"); |
261 | 192 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
|
193 } |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 void test_snprintf(const char *fmt, ...) |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
197 { |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
198 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
|
199 va_start(ap, fmt); |
259 | 200 va_copy(tmp, ap); test_snprintf_do(0, fmt, tmp, "0"); |
201 va_copy(tmp, ap); test_snprintf_do(1, fmt, tmp, "1"); | |
202 va_copy(tmp, ap); test_snprintf_do(2, fmt, tmp, "2"); | |
203 va_copy(tmp, ap); test_snprintf_do(16, fmt, tmp, "16"); | |
204 va_copy(tmp, ap); test_snprintf_do(SET_BUF_SIZE, fmt, tmp, "SET_BUF_SIZE"); | |
255 | 205 va_end(ap); |
291 | 206 THPRINT(2, |
207 "-----------------------------------------------------\n"); | |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
208 } |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
209 |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
210 |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
211 BOOL test_set_start(const char *str) |
264
9b6fd2953d8c
Add test header printing function.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
212 { |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
213 if (tests_enabled[tests_sets++]) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
214 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
215 tests_nenabled++; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
216 THPRINT(1, |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
217 "======================================================\n" |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
218 " Set #%d : %s tests\n" |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
219 "======================================================\n", |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
220 tests_sets, str); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
221 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
222 return TRUE; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
223 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
224 else |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
225 return FALSE; |
264
9b6fd2953d8c
Add test header printing function.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
226 } |
9b6fd2953d8c
Add test header printing function.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
227 |
9b6fd2953d8c
Add test header printing function.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
228 |
263 | 229 #define TEST2(fun, str1, str2, ret) do { \ |
303 | 230 test_ctx ctx; test_init(&ctx); \ |
231 test_start(&ctx, # fun "('%s', '%s')", str1, str2); \ | |
232 test_result(&ctx, ( fun (str1, str2) == 0) == ret); \ | |
263 | 233 } while (0) |
234 | |
266 | 235 #define TEST2B(fun, str1, str2, ret) do { \ |
303 | 236 test_ctx ctx; test_init(&ctx); \ |
237 test_start(&ctx, # fun "('%s', '%s')", str1, str2); \ | |
238 test_result(&ctx, fun (str1, str2) == ret); \ | |
266 | 239 } while (0) |
240 | |
263 | 241 #define TEST3(fun, str1, str2, len, ret) do { \ |
303 | 242 test_ctx ctx; test_init(&ctx); \ |
243 test_start(&ctx, # fun "('%s', '%s', %d)", str1, str2, len); \ | |
244 test_result(&ctx, ( fun (str1, str2, len) == 0) == ret); \ | |
263 | 245 } while (0) |
246 | |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
247 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
248 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
249 int main(int argc, char *argv[]) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
250 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
251 size_t i1, i2; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
252 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
253 // |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
254 // Initialization |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
255 // |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
256 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
|
257 th_verbosityLevel = 0; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
258 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
259 if (sizeof(char) != sizeof(unsigned char)) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
260 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
261 THERR("sizeof(char) != sizeof(unsigned char)???\n"); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
262 return -1; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
263 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
264 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
265 tests_failed = tests_passed = tests_total = tests_sets = tests_nenabled = 0; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
266 for (i1 = 0; i1 < SET_MAX_TESTS; i1++) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
267 tests_enabled[i1] = 1; |
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 // |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
270 // Parse command line arguments |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
271 // |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
272 if (!th_args_process(argc, argv, arg_opts, arg_nopts, |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
273 arg_handle_opt, NULL, 0)) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
274 return 0; |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
275 |
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 // |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
278 // Test series #1 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
279 // |
295 | 280 if (test_set_start("printf() integer")) |
282
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 int i_vals[] = { 2, 612342, -2, -612342, 0x1fff, 0x8000000, }; |
290 | 283 char *i_fmts[] = { "%d", "%x", "%05d", "%5d", "%-5d", "%05x", "%5x", "", "% 3d", "% 3o", "%+3o", "%+3d", }; |
282
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 for (i1 = 0; i1 < sizeof(i_vals) / sizeof(i_vals[0]); i1++) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
286 for (i2 = 0; i2 < sizeof(i_fmts) / sizeof(i_fmts[0]); i2++) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
287 test_snprintf(i_fmts[i2], i_vals); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
288 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
289 |
296
ec8357d02a52
Add floating point tests (which will fail for now).
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
290 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
|
291 { |
ec8357d02a52
Add floating point tests (which will fail for now).
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
292 int f_vals[] = { 2.02, 612342.234, -2.07, -612342.12, 0x1fff, 0x8000000, }; |
ec8357d02a52
Add floating point tests (which will fail for now).
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
293 char *f_fmts[] = { "%f", "%1.1f", "%5.5f", "%5f", "%-5f", "", }; |
ec8357d02a52
Add floating point tests (which will fail for now).
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
294 |
ec8357d02a52
Add floating point tests (which will fail for now).
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
295 for (i1 = 0; i1 < sizeof(f_vals) / sizeof(f_vals[0]); i1++) |
ec8357d02a52
Add floating point tests (which will fail for now).
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
296 for (i2 = 0; i2 < sizeof(f_fmts) / sizeof(f_fmts[0]); i2++) |
ec8357d02a52
Add floating point tests (which will fail for now).
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
297 test_snprintf(f_fmts[i2], f_vals); |
ec8357d02a52
Add floating point tests (which will fail for now).
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
298 } |
ec8357d02a52
Add floating point tests (which will fail for now).
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
299 |
295 | 300 if (test_set_start("printf() string")) |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
301 { |
289 | 302 char *s_vals[] = { "", "XYZXYZ", "xxx yyy zzz ppp fff", NULL, "X", "abcde", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", }; |
301 | 303 char *s_fmts[] = { "%s", "%2s", "%-2s", "%5s", "%-5s", "%16s", "%-16s", "%1s", "%-1s", "% 2s", "%03s", "% -12s", "% 03s", "%-.15s", "%.8s" }; |
265 | 304 |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
305 for (i1 = 0; i1 < sizeof(s_vals) / sizeof(s_vals[0]); i1++) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
306 for (i2 = 0; i2 < sizeof(s_fmts) / sizeof(s_fmts[0]); i2++) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
307 test_snprintf(s_fmts[i2], s_vals); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
308 |
288 | 309 } |
310 | |
295 | 311 if (test_set_start("printf() char")) |
288 | 312 { |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
313 test_snprintf("a%cBC", 'x'); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
314 test_snprintf("%c", 'x'); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
315 test_snprintf("", 'x'); |
288 | 316 test_snprintf("%0c", 'x'); |
317 test_snprintf("%1c", 'x'); | |
318 test_snprintf("% c", 'x'); | |
319 test_snprintf("%-3c", 'x'); | |
320 test_snprintf("%3c", 'x'); | |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
321 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
322 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
323 // |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
324 // String matching functions |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
325 // |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
326 if (test_set_start("String matching #1")) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
327 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
328 TEST2(th_strcasecmp, "aSdFq", "asdfq", TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
329 TEST2(th_strcasecmp, "aSdFq", "asFfq", FALSE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
330 TEST2(th_strcasecmp, "abcde", "abcde", TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
331 TEST2(th_strcasecmp, "öäå", "öäå", TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
332 TEST2(th_strcasecmp, "aöäå", "aöäå", TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
333 } |
255 | 334 |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
335 if (test_set_start("String matching #2")) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
336 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
337 TEST3(th_strncasecmp, "aSdFq", "asFfq", 4, FALSE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
338 TEST3(th_strncasecmp, "aSdFq", "asFfq", 2, TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
339 TEST3(th_strncasecmp, "aSdFq", "asDfq", 3, TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
340 TEST3(th_strncasecmp, "aSdFq", "asDfq", 2, TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
341 TEST3(th_strncasecmp, "aSdFq", "asDfq", 0, TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
342 TEST3(th_strncasecmp, "aSdFq", "QsDfq", 0, TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
343 TEST3(th_strncasecmp, "aSdFq", "QsDfq", 1, FALSE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
344 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
345 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
346 if (test_set_start("String matching #3")) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
347 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
348 TEST2B(th_strmatch, "abba ABBAkukka lol", "*lol", TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
349 TEST2B(th_strmatch, "abba ABBAkukka lol", "*lo*", TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
350 TEST2B(th_strmatch, "abba ABBAkukka lol", "*lo", FALSE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
351 TEST2B(th_strmatch, "abba ABBAkukka lol", "abba", FALSE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
352 TEST2B(th_strmatch, "abba ABBAkukka lol", "abba*", TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
353 TEST2B(th_strmatch, "abba ABBAkukka lol", "abbak*", FALSE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
354 TEST2B(th_strmatch, "abba ABBAöökukka lol", "*abbaö?", FALSE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
355 } |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
356 |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
357 if (test_set_start("String matching #4")) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
358 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
359 TEST2B(th_strcasematch, "abba ABBAkukka lol", "abbak*", FALSE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
360 TEST2B(th_strcasematch, "abba ABBAkukka lol", "*abbak*", TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
361 TEST2B(th_strcasematch, "abba ABBAkukka lol", "*abbak?", FALSE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
362 TEST2B(th_strcasematch, "abba ABBAkukka lol", "?bba?abba*", TRUE); |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
363 } |
266 | 364 |
265 | 365 // Tests that test for things that do not work correctly yet |
366 // Unicode / multibyte UTF-8 causes problems here | |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
367 if (test_set_start("Invalid")) |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
368 { |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
369 TEST2(th_strcasecmp, "ÖÄÅ", "öäå", FALSE); // SHOULD match |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
370 TEST3(th_strncasecmp, "Aäöå", "aöå", 2, TRUE); // should NOT match |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
371 TEST2B(th_strmatch, "öriÖRI! lol", "?ri?RI!*", FALSE); // should match |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
372 } |
266 | 373 |
255 | 374 // |
375 // Print summary and exit | |
376 // | |
276
56b0de9f9d44
Improve tests output per verbosity level.
Matti Hamalainen <ccr@tnsp.org>
parents:
274
diff
changeset
|
377 THPRINT(1, |
56b0de9f9d44
Improve tests output per verbosity level.
Matti Hamalainen <ccr@tnsp.org>
parents:
274
diff
changeset
|
378 "======================================================\n"); |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
379 |
272 | 380 THPRINT(0, |
282
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
381 "%d tests failed, %d passed (%d main tests), %d test sets of %d sets total.\n", |
f0cb48b34463
Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents:
276
diff
changeset
|
382 tests_failed, tests_passed, tests_total, tests_nenabled, tests_sets); |
255 | 383 |
254
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
384 return 0; |
3d1e2af4e4e6
Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
385 } |