annotate tests.c @ 613:2e3b81ae8c8a

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