annotate tests.c @ 296:ec8357d02a52

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