annotate tests.c @ 789:d61d3eb29053 default tip

Bump copyright.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 08 Mar 2024 15:26:24 +0200
parents c51f056f3557
children
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"
651
18fe45e61b2b Moar re-work.
Matti Hamalainen <ccr@tnsp.org>
parents: 650
diff changeset
6 #include "th_ioctx.h"
505
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
7 #include "th_config.h"
743
e2873f764b63 Add few simplistic tests of th_file module functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
8 #include "th_file.h"
605
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
9 #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
10
364
f2e6e3352f2d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 363
diff changeset
11
f2e6e3352f2d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 363
diff changeset
12 #define SET_BUF_SIZE 128
365
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
13 #define SET_BUF_SIZE_2 ((SET_BUF_SIZE) + 32)
364
f2e6e3352f2d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 363
diff changeset
14 #define SET_MAX_TESTS 64
f2e6e3352f2d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 363
diff changeset
15 #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
16
291
886a42023415 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
17
552
22f6204c4208 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 551
diff changeset
18 #define NCOUNT(xxx) (sizeof(xxx) / sizeof(xxx[0]))
22f6204c4208 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 551
diff changeset
19
22f6204c4208 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 551
diff changeset
20
365
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
21 enum
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
22 {
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
23 TST_SUPERFLUOUS = 0x0001,
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
24 TST_CORNERCASE = 0x0002,
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
25 TST_OVERFLOW = 0x0004,
508
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
26 TST_BROKEN = 0x1000,
365
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
27 TST_ALL = 0xffff,
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
28 };
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
29
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
30
303
54ea7a73e5fa Implement test contexts.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
31 typedef struct
54ea7a73e5fa Implement test contexts.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
32 {
502
ebf89497305a Remove some unused functionality for simplification.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
33 char *header;
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
34 bool
551
2fbf5c2a662c Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 544
diff changeset
35 shown, // Has test result value been shown?
2fbf5c2a662c Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 544
diff changeset
36 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
37 } test_ctx;
54ea7a73e5fa Implement test contexts.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
38
54ea7a73e5fa Implement test contexts.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
39
551
2fbf5c2a662c Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 544
diff changeset
40 // Global variables
2fbf5c2a662c Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 544
diff changeset
41 int tests_failed, // Total number of tests failed
2fbf5c2a662c Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 544
diff changeset
42 tests_passed, // Total number of tests passed
2fbf5c2a662c Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 544
diff changeset
43 tests_total, // Total number of tests RUN
2fbf5c2a662c Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 544
diff changeset
44 sets_total, // Number of test sets
2fbf5c2a662c Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 544
diff changeset
45 sets_nenabled; // Number of test sets enabled
2fbf5c2a662c Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 544
diff changeset
46
365
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
47 int sets_enabled[SET_MAX_TESTS];
259
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
48
551
2fbf5c2a662c Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 544
diff changeset
49 char buf1[SET_BUF_SIZE_2],
2fbf5c2a662c Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 544
diff changeset
50 buf2[SET_BUF_SIZE_2];
2fbf5c2a662c Add few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 544
diff changeset
51
365
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
52 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
53
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 768
diff changeset
54 th_ioctx_t testio;
651
18fe45e61b2b Moar re-work.
Matti Hamalainen <ccr@tnsp.org>
parents: 650
diff changeset
55
254
3d1e2af4e4e6 Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
274
f875db8634b6 Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
57 // Define option arguments
380
ac10155d2b4a Rename th_optarg_t to t_optarg. API break.
Matti Hamalainen <ccr@tnsp.org>
parents: 366
diff changeset
58 static const th_optarg arg_opts[] =
274
f875db8634b6 Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
59 {
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
60 { 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
61 { 1, 'v', "verbose" , NULL, "Be more verbose", OPT_NONE },
602
aec713767482 Cosmetic fix in help.
Matti Hamalainen <ccr@tnsp.org>
parents: 596
diff changeset
62 { 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
63 { 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
64 };
f875db8634b6 Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
65
f875db8634b6 Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
66 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
67
f875db8634b6 Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
68
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
69 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
70 {
469
fe5b803ae449 Rename the global variable th_verbosityLevel to th_verbosity.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
71 if (level <= th_verbosity)
363
68e8ad3327b8 Improve tests output.
Matti Hamalainen <ccr@tnsp.org>
parents: 362
diff changeset
72 {
304
3fcf42cce43d Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
73 vfprintf(stdout, fmt, ap);
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
74 return true;
363
68e8ad3327b8 Improve tests output.
Matti Hamalainen <ccr@tnsp.org>
parents: 362
diff changeset
75 }
68e8ad3327b8 Improve tests output.
Matti Hamalainen <ccr@tnsp.org>
parents: 362
diff changeset
76 else
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
77 return false;
304
3fcf42cce43d Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
78 }
3fcf42cce43d Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
79
3fcf42cce43d Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
80
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
81 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
82 {
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
83 bool retv;
304
3fcf42cce43d Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
84 va_list ap;
3fcf42cce43d Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
85 va_start(ap, fmt);
363
68e8ad3327b8 Improve tests output.
Matti Hamalainen <ccr@tnsp.org>
parents: 362
diff changeset
86 retv = tprintv(level, fmt, ap);
304
3fcf42cce43d Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
87 va_end(ap);
363
68e8ad3327b8 Improve tests output.
Matti Hamalainen <ccr@tnsp.org>
parents: 362
diff changeset
88 return retv;
304
3fcf42cce43d Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
89 }
3fcf42cce43d Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
90
3fcf42cce43d Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
91
274
f875db8634b6 Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
92 void arg_show_help(void)
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 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
95 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
96 }
f875db8634b6 Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
97
f875db8634b6 Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
98
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
99 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
100 {
f875db8634b6 Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
101 switch (optN)
f875db8634b6 Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
102 {
f875db8634b6 Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
103 case 0:
f875db8634b6 Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
104 arg_show_help();
f875db8634b6 Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
105 exit(0);
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
f875db8634b6 Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
108 case 1:
469
fe5b803ae449 Rename the global variable th_verbosityLevel to th_verbosity.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
109 th_verbosity++;
274
f875db8634b6 Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
110 break;
f875db8634b6 Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
111
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
112 case 2:
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
113 {
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
114 bool ret = true;
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
115 char *pos, *pstr, *next;
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
116 pos = pstr = th_strdup(optArg);
365
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
117 memset(sets_enabled, 0, sizeof(sets_enabled));
282
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 do {
552
22f6204c4208 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 551
diff changeset
120 if ((next = strchr(pos, ',')) != NULL)
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
121 *next = 0;
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
122
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
123 char *tmp = th_strdup_trim(pos, TH_TRIM_BOTH);
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
124 if (tmp != NULL)
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
125 {
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
126 int val = atoi(tmp);
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
127 if (val > 0 && val <= SET_MAX_TESTS)
365
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
128 sets_enabled[val - 1] = 1;
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
129 else
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
130 {
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
131 THERR("Invalid test number #%d, out of range [%d .. %d]\n", val, 1, SET_MAX_TESTS);
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
132 ret = false;
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
133 }
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
134 th_free(tmp);
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
135 }
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
136
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
137 if (next != NULL)
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
138 pos = next + 1;
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
139 } while (next != NULL);
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
140 th_free(pstr);
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
141 return ret;
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
142 }
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
143 break;
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
144
365
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
145 case 3:
366
21bbb2dc4fac Actually parse the -t option argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 365
diff changeset
146 optFlags = atoi(optArg);
365
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
147 break;
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
148
274
f875db8634b6 Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
149 default:
f875db8634b6 Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
150 THERR("Unknown option '%s'.\n", currArg);
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
151 return false;
274
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
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
154 return true;
274
f875db8634b6 Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
155 }
f875db8634b6 Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
156
f875db8634b6 Implement commandline options for test driver.
Matti Hamalainen <ccr@tnsp.org>
parents: 272
diff changeset
157
342
09c2f6abf694 Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
158 void test_end(test_ctx *ctx)
09c2f6abf694 Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
159 {
09c2f6abf694 Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
160 th_free_r(&ctx->header);
09c2f6abf694 Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
161 }
09c2f6abf694 Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
162
09c2f6abf694 Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
163
303
54ea7a73e5fa Implement test contexts.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
164 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
165 {
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
166 tests_total++;
502
ebf89497305a Remove some unused functionality for simplification.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
167 memset(ctx, 0, sizeof(test_ctx));
303
54ea7a73e5fa Implement test contexts.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
168 ctx->header = th_strdup_vprintf(fmt, ap);
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
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
171
303
54ea7a73e5fa Implement test contexts.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
172 void test_start(test_ctx *ctx, const char *fmt, ...)
259
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
173 {
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
174 va_list ap;
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
175 va_start(ap, fmt);
303
54ea7a73e5fa Implement test contexts.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
176 test_start_v(ctx, fmt, ap);
259
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
177 va_end(ap);
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
178 }
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
179
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
180
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
181 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
182 {
259
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
183 if (check)
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
184 {
363
68e8ad3327b8 Improve tests output.
Matti Hamalainen <ccr@tnsp.org>
parents: 362
diff changeset
185 if (!ctx->shown && tprint(2, "%s: OK\n", ctx->header))
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
186 ctx->shown = true;
363
68e8ad3327b8 Improve tests output.
Matti Hamalainen <ccr@tnsp.org>
parents: 362
diff changeset
187
259
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
188 tests_passed++;
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
189 }
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
190 else
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
191 {
363
68e8ad3327b8 Improve tests output.
Matti Hamalainen <ccr@tnsp.org>
parents: 362
diff changeset
192 if (!ctx->shown && tprint(0, "%s: FAIL\n", ctx->header))
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
193 ctx->shown = true;
363
68e8ad3327b8 Improve tests output.
Matti Hamalainen <ccr@tnsp.org>
parents: 362
diff changeset
194
259
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
195 if (fmt != NULL)
263
423771158575 Add more tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
196 {
304
3fcf42cce43d Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
197 tprint(0, " - ");
3fcf42cce43d Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
198 tprintv(0, fmt, ap);
3fcf42cce43d Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
199 tprint(0, "\n");
263
423771158575 Add more tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
200 }
259
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
201 tests_failed++;
529
c44ebf5b08fd Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 527
diff changeset
202
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
203 ctx->failed = true;
259
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
204 }
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
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
207
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
208 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
209 {
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
210 va_list ap;
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
211 va_start(ap, fmt);
303
54ea7a73e5fa Implement test contexts.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
212 test_result_msg_v(ctx, check, fmt, ap);
259
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
213 va_end(ap);
305
5afd918cbd79 Have a return value for test result functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 304
diff changeset
214 return check;
259
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
215 }
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
216
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
217
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
218 bool test_result(test_ctx *ctx, bool check)
259
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
219 {
303
54ea7a73e5fa Implement test contexts.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
220 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
221 return check;
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
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
224
319
f2af6049d958 Improve testing.
Matti Hamalainen <ccr@tnsp.org>
parents: 317
diff changeset
225 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
226 {
33652234f162 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 257
diff changeset
227 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
228 va_list tmp;
303
54ea7a73e5fa Implement test contexts.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
229 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
230
529
c44ebf5b08fd Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 527
diff changeset
231 // Setup printf debug value
c44ebf5b08fd Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 527
diff changeset
232 th_printf_debug = th_verbosity >= 3;
c44ebf5b08fd Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 527
diff changeset
233 th_printf_debug_prefix = " - ";
c44ebf5b08fd Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 527
diff changeset
234
263
423771158575 Add more tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
235 // Test basic *printf() functionality
530
94d4130cc29c Clarify printf test output slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
236 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
237
365
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
238 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
239 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
240
339
46a0fab6ca1f Fix snprintf() test running.
Matti Hamalainen <ccr@tnsp.org>
parents: 338
diff changeset
241 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
242 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
243
303
54ea7a73e5fa Implement test contexts.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
244 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
245 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
246
365
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
247 if (optFlags & TST_OVERFLOW)
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
248 {
303
54ea7a73e5fa Implement test contexts.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
249 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
250 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
251 }
261
f1decaee6157 Improve tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 259
diff changeset
252
529
c44ebf5b08fd Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 527
diff changeset
253 if (ctx.failed && !th_printf_debug && th_verbosity >= 1)
c44ebf5b08fd Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 527
diff changeset
254 {
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
255 th_printf_debug = true;
529
c44ebf5b08fd Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 527
diff changeset
256 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
257 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
258 }
c44ebf5b08fd Improve printf debugging in tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 527
diff changeset
259
342
09c2f6abf694 Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
260 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
261 }
3d1e2af4e4e6 Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262
3d1e2af4e4e6 Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263
319
f2af6049d958 Improve testing.
Matti Hamalainen <ccr@tnsp.org>
parents: 317
diff changeset
264 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
265 {
362
a688d34c11d4 Sanitize test_snprintf().
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
266 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
267 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
268 va_start(ap, fmt);
365
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
269
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
270 if (optFlags & TST_CORNERCASE)
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
271 {
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
272 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
273 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
274 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
275 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
276 }
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
277
319
f2af6049d958 Improve testing.
Matti Hamalainen <ccr@tnsp.org>
parents: 317
diff changeset
278 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
279
a688d34c11d4 Sanitize test_snprintf().
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
280 // Test th_strdup_vprintf()
365
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
281 if (optFlags & TST_SUPERFLUOUS)
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
282 {
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
283 test_start(&ctx, "th_strdup_vprintf('%s')", fmt);
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
284 va_copy(tmp, ap);
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
285 char *str = th_strdup_vprintf(fmt, tmp);
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
286 test_result_msg(&ctx, str != NULL, "result NULL");
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
287 th_free(str);
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
288 test_end(&ctx);
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
289 }
362
a688d34c11d4 Sanitize test_snprintf().
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
290
441
2991e6b52d95 Get rid of trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 412
diff changeset
291 va_end(ap);
304
3fcf42cce43d Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
292 tprint(2,
291
886a42023415 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
293 "-----------------------------------------------------\n");
254
3d1e2af4e4e6 Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 }
3d1e2af4e4e6 Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295
3d1e2af4e4e6 Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
297 bool test_set_start(const char *str)
264
9b6fd2953d8c Add test header printing function.
Matti Hamalainen <ccr@tnsp.org>
parents: 263
diff changeset
298 {
365
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
299 if (sets_enabled[sets_total++])
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
300 {
365
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
301 sets_nenabled++;
304
3fcf42cce43d Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
302 tprint(1,
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
303 "======================================================\n"
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
304 " Set #%d : %s tests\n"
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
305 "======================================================\n",
365
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
306 sets_total, str);
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
307
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
308 return true;
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
309 }
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
310 else
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
311 return false;
264
9b6fd2953d8c Add test header printing function.
Matti Hamalainen <ccr@tnsp.org>
parents: 263
diff changeset
312 }
9b6fd2953d8c Add test header printing function.
Matti Hamalainen <ccr@tnsp.org>
parents: 263
diff changeset
313
9b6fd2953d8c Add test header printing function.
Matti Hamalainen <ccr@tnsp.org>
parents: 263
diff changeset
314
603
be957142ab37 Add TEST_ASSERT() and test sizes of some types before doing anything else.
Matti Hamalainen <ccr@tnsp.org>
parents: 602
diff changeset
315 #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
316 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
317 { \
be957142ab37 Add TEST_ASSERT() and test sizes of some types before doing anything else.
Matti Hamalainen <ccr@tnsp.org>
parents: 602
diff changeset
318 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
319 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
320 } \
be957142ab37 Add TEST_ASSERT() and test sizes of some types before doing anything else.
Matti Hamalainen <ccr@tnsp.org>
parents: 602
diff changeset
321 } 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
322
764
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
323 #define TEST_1A(fun) do { \
524
19dc326dcdad Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 523
diff changeset
324 test_ctx ctx; \
19dc326dcdad Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 523
diff changeset
325 test_start(&ctx, # fun ); \
19dc326dcdad Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 523
diff changeset
326 test_result(&ctx, fun); \
19dc326dcdad Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 523
diff changeset
327 test_end(&ctx); \
19dc326dcdad Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 523
diff changeset
328 } while (0)
19dc326dcdad Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 523
diff changeset
329
764
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
330 #define TEST_1B(fmt, fun, fcmp, fres) do { \
524
19dc326dcdad Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 523
diff changeset
331 test_ctx ctx; \
19dc326dcdad Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 523
diff changeset
332 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
333 test_result(&ctx, fun fcmp fres ); \
19dc326dcdad Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 523
diff changeset
334 test_end(&ctx); \
19dc326dcdad Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 523
diff changeset
335 } while (0)
19dc326dcdad Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 523
diff changeset
336
764
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
337 #define TEST_2A(fun, str1, str2, ret) do { \
502
ebf89497305a Remove some unused functionality for simplification.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
338 test_ctx ctx; \
303
54ea7a73e5fa Implement test contexts.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
339 test_start(&ctx, # fun "('%s', '%s')", str1, str2); \
54ea7a73e5fa Implement test contexts.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
340 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
341 test_end(&ctx); \
263
423771158575 Add more tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
342 } while (0)
423771158575 Add more tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
343
764
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
344 #define TEST_2B(fun, str1, str2, ret) do { \
502
ebf89497305a Remove some unused functionality for simplification.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
345 test_ctx ctx; \
303
54ea7a73e5fa Implement test contexts.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
346 test_start(&ctx, # fun "('%s', '%s')", str1, str2); \
54ea7a73e5fa Implement test contexts.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
347 test_result(&ctx, fun (str1, str2) == ret); \
342
09c2f6abf694 Fix memory leaks in test suite.
Matti Hamalainen <ccr@tnsp.org>
parents: 340
diff changeset
348 test_end(&ctx); \
266
3a020aa05f28 More tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 265
diff changeset
349 } while (0)
3a020aa05f28 More tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 265
diff changeset
350
764
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
351 #define TEST_2C(fun, str1, str2, ret) do { \
502
ebf89497305a Remove some unused functionality for simplification.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
352 test_ctx ctx; \
465
6d44592cdab1 Improve tests slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 457
diff changeset
353 test_start(&ctx, # fun "('%s', '%s')", str1, str2); \
6d44592cdab1 Improve tests slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 457
diff changeset
354 test_result(&ctx, (fun (str1, str2) != NULL) == ret); \
6d44592cdab1 Improve tests slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 457
diff changeset
355 test_end(&ctx); \
6d44592cdab1 Improve tests slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 457
diff changeset
356 } while (0)
6d44592cdab1 Improve tests slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 457
diff changeset
357
764
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
358 #define TEST_3A(fun, str1, str2, len, ret) do { \
502
ebf89497305a Remove some unused functionality for simplification.
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
359 test_ctx ctx; \
303
54ea7a73e5fa Implement test contexts.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
360 test_start(&ctx, # fun "('%s', '%s', %d)", str1, str2, len); \
54ea7a73e5fa Implement test contexts.
Matti Hamalainen <ccr@tnsp.org>
parents: 301
diff changeset
361 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
362 test_end(&ctx); \
263
423771158575 Add more tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
363 } while (0)
423771158575 Add more tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 261
diff changeset
364
764
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
365 #define TEST_3B(fun, str1, str2, sbool, ret) do { \
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
366 test_ctx ctx; \
768
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
367 test_start(&ctx, # fun "('%s', '%s', %s) == %s", str1, str2, sbool ? "true" : "false", ret ? "true" : "false"); \
764
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
368 test_result(&ctx, fun (str1, str2, sbool) == ret); \
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
369 test_end(&ctx); \
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
370 } while (0)
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
371
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
372
512
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
373 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
374 {
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
375 th_cfgitem_t *item;
512
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
376 int nsubtest = 0;
508
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
377 test_ctx ctx;
505
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
378
512
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
379 test_start(&ctx, "Test configuration value search #%d", ++nsubtest);
781
4cc514343376 Rename th_cfg_find() to th_cfg_item_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
380 test_result(&ctx, (item = th_cfg_item_find(cfg, "inside_sect", "intval", -1)) != NULL && *item->v.val_int == 112);
505
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
381 test_end(&ctx);
512
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
382 test_start(&ctx, "Test configuration value search #%d", ++nsubtest);
781
4cc514343376 Rename th_cfg_find() to th_cfg_item_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
383 test_result(&ctx, (item = th_cfg_item_find(cfg, "another_sect", "boolval", -1)) != NULL && *item->v.val_bool);
505
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
384 test_end(&ctx);
512
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
385 test_start(&ctx, "Test configuration value search #%d", ++nsubtest);
781
4cc514343376 Rename th_cfg_find() to th_cfg_item_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
386 test_result(&ctx, th_cfg_item_find(cfg, "no_match", NULL, -1) == NULL);
505
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
387 test_end(&ctx);
512
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
388 test_start(&ctx, "Test configuration value search #%d", ++nsubtest);
781
4cc514343376 Rename th_cfg_find() to th_cfg_item_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
389 test_result(&ctx, th_cfg_item_find(cfg, NULL, "no_match", -1) == NULL);
505
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
390 test_end(&ctx);
512
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
391 test_start(&ctx, "Test configuration value search #%d", ++nsubtest);
781
4cc514343376 Rename th_cfg_find() to th_cfg_item_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
392 test_result(&ctx, (item = th_cfg_item_find(cfg, NULL, "hexval", -1)) != NULL && *item->v.val_uint == 0x11223344);
505
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
393 test_end(&ctx);
512
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
394 test_start(&ctx, "Test configuration value search #%d", ++nsubtest);
781
4cc514343376 Rename th_cfg_find() to th_cfg_item_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
395 test_result(&ctx, (item = th_cfg_item_find(cfg, NULL, "a_string_setting", -1)) != NULL && strcmp(*item->v.val_str, "v_str1") == 0);
508
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
396 test_end(&ctx);
505
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
397 }
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
398
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
399
709
905d30063e45 Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
400 void test_config_free(th_cfgitem_t *node)
508
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
401 {
709
905d30063e45 Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
402 switch (node->type)
905d30063e45 Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
403 {
774
08bbfb5239fc s/ITEM_/CFG_ITEM_/g'
Matti Hamalainen <ccr@tnsp.org>
parents: 771
diff changeset
404 case CFG_ITEM_STRING:
709
905d30063e45 Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
405 th_free(*(node->v.val_str));
905d30063e45 Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
406 break;
905d30063e45 Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
407
774
08bbfb5239fc s/ITEM_/CFG_ITEM_/g'
Matti Hamalainen <ccr@tnsp.org>
parents: 771
diff changeset
408 case CFG_ITEM_STRING_LIST:
709
905d30063e45 Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
409 break;
905d30063e45 Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
410 }
508
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
411 }
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
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 768
diff changeset
414 void test_ioctx_error(th_ioctx_t *fh, const int val, const char *msg)
508
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 (void) fh;
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
417 (void) val;
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
418 tprint(0, "IOCTX ERROR: %s", msg);
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
419 }
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
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 768
diff changeset
422 void test_ioctx_msg(th_ioctx_t *fh, const int val, const char *msg)
508
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
423 {
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
424 (void) fh;
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
425 (void) val;
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
426 tprint(1, "IOCTX MSG: %s", msg);
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
427 }
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
428
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
429
552
22f6204c4208 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 551
diff changeset
430 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
431 {
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
432 return strcmp((const char *) v1, (const char *) v2);
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
433 }
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
434
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
435
552
22f6204c4208 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 551
diff changeset
436 static const char *test_config_strings[] =
508
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
437 {
521
77495c646208 Fix parsing and writing of strings with simple escape sequences in config files.
Matti Hamalainen <ccr@tnsp.org>
parents: 517
diff changeset
438 "zoo", "foo", "b\"ar",
508
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
439 };
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
440
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
441
512
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
442 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
443 {
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
444 int nsubtest;
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 768
diff changeset
445 th_ioctx_t *fh = NULL;
512
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
446 test_ctx ctx;
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
447 th_cfgitem_t *item;
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
448
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
449 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
450
512
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
451 // Attempt to read the previously written file
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
452 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
453 {
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
454 int err = th_get_error();
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
455 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
456 filename, err, th_error_str(err));
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
457 goto out;
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
458 }
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
459
516
cfd536d654a6 Fix ioctx handlers setup.
Matti Hamalainen <ccr@tnsp.org>
parents: 515
diff changeset
460 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
461
512
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
462 th_cfg_read(fh, cfg);
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
463
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
464 // Test read values against expected values
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
465 test_config_values(cfg);
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 // Additional tests
786
c51f056f3557 Fix a test.
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
468 test_start(&ctx, "Additional config tests");
781
4cc514343376 Rename th_cfg_find() to th_cfg_item_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
469 item = th_cfg_item_find(cfg, NULL, "string_list", -1);
512
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
470 test_result(&ctx, item != NULL);
786
c51f056f3557 Fix a test.
Matti Hamalainen <ccr@tnsp.org>
parents: 785
diff changeset
471 test_end(&ctx);
512
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
472 if (item != NULL)
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
473 {
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
474 static const char *nostr = "not to be found";
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
475 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
476
552
22f6204c4208 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 551
diff changeset
477 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
478 {
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
479 test_start(&ctx, "Test configuration string list values #%d: '%s'",
552
22f6204c4208 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 551
diff changeset
480 nsubtest + 1, test_config_strings[nsubtest]);
512
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
481
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
482 test_result(&ctx,
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
483 th_llist_find_func(*plist,
552
22f6204c4208 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 551
diff changeset
484 test_config_strings[nsubtest], test_config_strcmp) != NULL);
512
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
485 test_end(&ctx);
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
486 }
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
487
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
488 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
489 ++nsubtest, nostr);
552
22f6204c4208 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 551
diff changeset
490 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
491 test_end(&ctx);
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
492
709
905d30063e45 Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
493 th_llist_free_func_data(*plist, th_free);
512
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
494 *plist = NULL;
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
495 }
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
496
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
497 out:
650
24cbab6e88c6 Remove th_io_free(), merge the functionality to th_io_close(). Add flags
Matti Hamalainen <ccr@tnsp.org>
parents: 649
diff changeset
498 th_io_close(fh);
512
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
499 }
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
500
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
501
760
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
502 void test_config_file(void)
505
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
503 {
513
e412a39e2b7a Add another test for configuration parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
504 static const char *filename = "cfg.temp";
508
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
505 test_ctx ctx;
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 768
diff changeset
506 th_ioctx_t *fh = NULL;
508
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
507 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
508 char *v_str1 = NULL;
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
509 unsigned int v_uint1;
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
510 int v_int1;
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
511 bool v_bool1, v_bool2;
505
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
512 th_llist_t *v_str_list = NULL;
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
513
508
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
514 // Create v_str_list
552
22f6204c4208 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 551
diff changeset
515 for (size_t n = 0; n < NCOUNT(test_config_strings); n++)
22f6204c4208 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 551
diff changeset
516 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
517
505
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
518 // Create the configuration structure
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
519 tprint(2, "Creating configuration structure\n");
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
520 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
521 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
522 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
523
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
524 th_cfg_add_comment(&sect1, "Hex triplet value setting");
777
484853471eaf Rename th_cfg_add_hexvalue() to th_cfg_add_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 774
diff changeset
525 th_cfg_add_hex_triplet(&sect1, "hexval", &v_uint1, 0x11223344);
505
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
526
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
527 th_cfg_add_comment(&sect1, "A boolean value");
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
528 th_cfg_add_bool(&sect1, "boolval", &v_bool1, false);
505
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
529
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
530 th_cfg_add_comment(&sect1, "A string list");
508
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
531 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
532
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
533 th_cfg_add_section(&cfg, "general", sect1);
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 sect1 = NULL;
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
536 th_cfg_add_comment(&sect1, "Another section");
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
537 th_cfg_add_bool(&sect1, "boolval", &v_bool2, true);
505
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
538
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
539 sect2 = NULL;
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
540 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
541 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
542 th_cfg_add_section(&sect1, "inside_sect", sect2);
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
543
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
544 th_cfg_add_section(&cfg, "another_sect", sect1);
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
545
512
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
546 // Test ptr
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
547 test_start(&ctx, "Test configuration string list ptr");
613
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
548 test_result(&ctx,
781
4cc514343376 Rename th_cfg_find() to th_cfg_item_find().
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
549 (item = th_cfg_item_find(cfg, NULL, "string_list", -1)) != NULL &&
613
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
550 item->v.list == &v_str_list);
512
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
551 test_end(&ctx);
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
552
505
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
553 // Test value finding
512
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
554 test_config_values(cfg);
505
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
555
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
556 // Attempt to write the file
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
557 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
558 {
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
559 int err = th_get_error();
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
560 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
561 filename, err, th_error_str(err));
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
562 goto out;
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
563 }
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
564
516
cfd536d654a6 Fix ioctx handlers setup.
Matti Hamalainen <ccr@tnsp.org>
parents: 515
diff changeset
565 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
566
505
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
567 th_cfg_write(fh, cfg);
650
24cbab6e88c6 Remove th_io_free(), merge the functionality to th_io_close(). Add flags
Matti Hamalainen <ccr@tnsp.org>
parents: 649
diff changeset
568 th_io_close(fh);
515
d512555bdd0f Close written test config file before trying to read it.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
569 fh = NULL;
505
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
570
512
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
571 // Test against written configuration file
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
572 test_config_read(cfg, filename);
508
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
573
513
e412a39e2b7a Add another test for configuration parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
574 // Test against manually edited configuration file
e412a39e2b7a Add another test for configuration parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 512
diff changeset
575 test_config_read(cfg, "cfg.test01");
508
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
576
505
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
577 out:
512
5c3bfe034915 Improve config file handling tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
578 // Free the data for v_str_list
650
24cbab6e88c6 Remove th_io_free(), merge the functionality to th_io_close(). Add flags
Matti Hamalainen <ccr@tnsp.org>
parents: 649
diff changeset
579 th_io_close(fh);
709
905d30063e45 Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
580 th_llist_free_func_data(v_str_list, th_free);
905d30063e45 Use the th_cfg_free() deallocator.
Matti Hamalainen <ccr@tnsp.org>
parents: 703
diff changeset
581 th_cfg_free(cfg, test_config_free);
505
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
582 }
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
583
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
584
760
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
585 bool test_linked_list_length(th_llist_t *list, const size_t n)
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
586 {
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
587 test_ctx ctx;
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
588 bool ok = th_llist_length(list) == n;
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
589
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
590 test_start(&ctx, "Test list length matching");
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
591 test_result(&ctx, ok);
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
592 test_end(&ctx);
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
593
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
594 return ok;
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
595 }
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
596
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
597
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
598 bool test_linked_list_validity(th_llist_t *list, const size_t nstart, const ssize_t ndelta)
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
599 {
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
600 test_ctx ctx;
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
601 th_llist_t *node;
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
602 size_t n;
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
603 bool ok = true;
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
604
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
605 for (n = nstart, node = list; node != NULL; node = node->next, n += ndelta)
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
606 {
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
607 if ((size_t) node->data != n)
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
608 {
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
609 ok = false;
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
610 break;
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
611 }
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
612 }
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
613
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
614 test_start(&ctx, "Test list data contents");
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
615 test_result_msg(&ctx, ok, "failure at index #%d", n);
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
616 test_end(&ctx);
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
617
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
618 return ok;
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
619 }
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
620
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
621
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
622 int test_llist_sortfunc(const th_llist_t *lnode, const th_llist_t *rnode, void *userdata)
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
623 {
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
624 (void) userdata;
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
625 return lnode->data <= rnode->data;
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
626 }
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
627
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
628
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
629 void test_linked_lists(void)
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
630 {
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
631 th_llist_t *list = NULL, *node;
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
632 size_t nnodes = 128, n;
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
633
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
634 tprint(2, "Creating linked list\n");
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
635 for (n = 0; n < nnodes; n++)
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
636 {
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
637 if ((node = th_llist_append(&list, (void *) n)) == NULL)
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
638 {
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
639 THERR("Error allocating memory.\n");
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
640 goto out;
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
641 }
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
642 }
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
643
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
644 // Test
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
645 test_linked_list_length(list, nnodes);
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
646 test_linked_list_validity(list, 0, 1);
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
647
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
648 // Reverse
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
649 th_llist_reverse(&list);
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
650
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
651 test_linked_list_length(list, nnodes);
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
652 test_linked_list_validity(list, nnodes - 1, -1);
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
653
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
654 // Sort
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
655 th_llist_mergesort(&list, test_llist_sortfunc, NULL);
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
656
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
657 // Test count
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
658 test_linked_list_length(list, nnodes);
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
659 test_linked_list_validity(list, 0, 1);
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
660
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
661 // Prepend
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
662 tprint(2, "Prepend node to list\n");
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
663 for (size_t k = 0; k < 16; k++)
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
664 {
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
665 if ((node = th_llist_prepend(&list, (void *) n)) == NULL)
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
666 {
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
667 THERR("Error allocating memory.\n");
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
668 goto out;
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
669 }
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
670 nnodes++;
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
671 n++;
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
672 }
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
673
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
674 // Test count
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
675 test_linked_list_length(list, nnodes);
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
676
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
677 // Sort
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
678 th_llist_mergesort(&list, test_llist_sortfunc, NULL);
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
679 test_linked_list_validity(list, 0, 1);
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
680
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
681 // Delete
785
bca32201868e Plug another memory leak in tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 784
diff changeset
682 node = list;
bca32201868e Plug another memory leak in tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 784
diff changeset
683 th_llist_delete_node(&list, node);
760
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
684 test_linked_list_length(list, nnodes - 1);
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
685 test_linked_list_validity(list, 1, 1);
785
bca32201868e Plug another memory leak in tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 784
diff changeset
686 th_free(node);
760
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
687
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
688 out:
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
689 th_llist_free(list);
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
690 }
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
691
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
692
614
afcaf5e38f56 Disable regex stuff from normal builds.
Matti Hamalainen <ccr@tnsp.org>
parents: 613
diff changeset
693 #ifdef TH_EXPERIMENTAL_REGEX
afcaf5e38f56 Disable regex stuff from normal builds.
Matti Hamalainen <ccr@tnsp.org>
parents: 613
diff changeset
694
605
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
695 typedef struct
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
696 {
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
697 const th_char_t *str;
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
698 const int flags;
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
699 const th_char_t *expected[4];
647
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
700 } test_regex_def1;
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
701
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
702
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
703 typedef struct
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
704 {
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
705 const th_char_t *pattern;
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
706 const th_char_t *str;
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
707 const int flags;
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
708 const th_char_t *expected[4];
647
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
709 } test_regex_def2;
605
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
710
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
711
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
712 bool test_regex_list_matches(const th_char_t *str,
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
713 const th_regex_match_t *matches,
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
714 const th_char_t * const *expected,
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
715 const bool testOnly)
645
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
716 {
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
717 size_t nmatch = 0;
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
718 char *match = NULL;
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
719
645
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
720 for (const th_regex_match_t *mt = matches;
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
721 mt != NULL;
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
722 mt = (th_regex_match_t *) mt->node.next,
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
723 nmatch++)
645
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
724 {
710
c1c37f6ca133 Fix a silly memory leak in tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 709
diff changeset
725 match = th_strndup(str + mt->start, mt->len);
c1c37f6ca133 Fix a silly memory leak in tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 709
diff changeset
726
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
727 if (expected[nmatch] == NULL)
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
728 {
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
729 if (!testOnly)
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
730 {
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
731 THERR("Expected[%" PRIu_SIZE_T "] == NULL, but match '%s' returned.\n",
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
732 nmatch, match);
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
733 }
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
734
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
735 goto error;
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
736 }
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
737 else
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
738 {
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
739 bool seqMatch = strcmp(match, expected[nmatch]) == 0;
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
740 if (testOnly && !seqMatch)
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
741 goto error;
645
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
742
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
743 if (th_verbosity >= 1 || !seqMatch)
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
744 {
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
745 tprint(0, " [%3" PRIu_SIZE_T " ++ %3" PRIu_SIZE_T "]: '%s' == '%s': %s\n",
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
746 mt->start,
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
747 mt->len,
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
748 match,
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
749 expected[nmatch],
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
750 seqMatch ? "YES" : "NO!");
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
751 }
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
752 }
645
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
753
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
754 th_free(match);
645
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
755 }
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
756
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
757 return true;
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
758
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
759 error:
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
760 th_free(match);
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
761 return false;
645
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
762 }
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
763
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
764
664
c5aa9ada1051 s/th_regex_char_t/th_char_t/g
Matti Hamalainen <ccr@tnsp.org>
parents: 651
diff changeset
765 void test_regex_list1(const test_regex_def1 *list, const th_char_t *pattern)
605
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
766 {
713
3ea040bb0dca Fix a memory leak in regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
767 th_regex_match_t *matches = NULL;
645
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
768 th_regex_t *expr = NULL;
605
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
769 int res;
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
770
645
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
771 if ((res = th_regex_compile(&expr, pattern)) != THERR_OK)
605
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
772 {
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
773 THERR("Regex \"%s\" compilation failed: %s\n",
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
774 pattern,
605
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
775 th_error_str(res));
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
776 goto out;
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
777 }
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
778
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
779 tprint(1, "\n----------------------------------------\n"
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
780 "\"%s\"\n", pattern);
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
781
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
782 if (th_verbosity >= 2)
651
18fe45e61b2b Moar re-work.
Matti Hamalainen <ccr@tnsp.org>
parents: 650
diff changeset
783 th_regex_dump(&testio, 1, expr);
645
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
784
647
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
785 for (const test_regex_def1 *def = list; def->str != NULL; def++)
605
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
786 {
610
a0e8d9c6300b A bit more work on the regex stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 605
diff changeset
787 size_t nmatches;
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
788 bool matchOK;
605
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
789
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
790 tprint(3, "\n----------------------------------------\n");
645
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
791 if ((res = th_regex_match(expr, def->str,
613
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
792 &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
793 {
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
794 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
795 th_error_str(res));
713
3ea040bb0dca Fix a memory leak in regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
796
605
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
797 goto out;
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
798 }
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
799
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
800 matchOK = test_regex_list_matches(def->str, matches, def->expected, true);
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
801 if (th_verbosity < 1 && !matchOK)
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
802 {
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
803 tprint(0,
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
804 "\n----------------------------------------\n"
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
805 " \"%s\" vs \"%s\" failures:\n",
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
806 def->str, pattern);
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
807 }
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
808 else
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
809 {
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
810 tprint(1, " \"%s\": matched %" PRIu_SIZE_T " time(s)\n",
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
811 def->str,
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
812 nmatches);
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
813 }
610
a0e8d9c6300b A bit more work on the regex stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 605
diff changeset
814
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
815 #ifdef TH_EXPERIMENTAL_REGEX_DEBUG
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
816 if (!matchOK && th_dbg_fh == NULL)
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
817 {
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
818 th_dbg_fh = &testio;
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
819 th_regex_match(expr, def->str, NULL, NULL, -1, def->flags);
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
820 th_dbg_fh = NULL;
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
821 }
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
822 #endif
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
823
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
824 test_regex_list_matches(def->str, matches, def->expected, false);
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
825
610
a0e8d9c6300b A bit more work on the regex stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 605
diff changeset
826 th_regex_free_matches(matches);
713
3ea040bb0dca Fix a memory leak in regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
827 matches = NULL;
605
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
828 }
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
829
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
830 out:
713
3ea040bb0dca Fix a memory leak in regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 710
diff changeset
831 th_regex_free_matches(matches);
645
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
832 th_regex_free(expr);
605
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
833 }
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
834
649
2c9260f5cf44 Tweedle.
Matti Hamalainen <ccr@tnsp.org>
parents: 647
diff changeset
835
647
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
836 void test_regex_list2(const test_regex_def2 *list)
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
837 {
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
838 for (const test_regex_def2 *def = list; def->str != NULL; def++)
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
839 {
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
840 th_regex_t *expr = NULL;
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
841 th_regex_match_t *matches = NULL;
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
842 size_t nmatches;
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
843 int res;
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
844
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
845 if ((res = th_regex_compile(&expr, def->pattern)) != THERR_OK)
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
846 {
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
847 THERR("Regex \"%s\" compilation failed: %s\n",
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
848 def->pattern,
647
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
849 th_error_str(res));
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
850 goto out;
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
851 }
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
852
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
853 if (th_verbosity >= 2)
651
18fe45e61b2b Moar re-work.
Matti Hamalainen <ccr@tnsp.org>
parents: 650
diff changeset
854 th_regex_dump(&testio, 1, expr);
647
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
855
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
856 tprint(3, "----------------------------------------\n");
647
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
857
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
858 if ((res = th_regex_match(expr, def->str,
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
859 &nmatches, &matches, -1, def->flags)) != THERR_OK)
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
860 {
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
861 THERR("Regex match returned error: %s\n",
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
862 th_error_str(res));
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
863 goto out;
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
864 }
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
865
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
866 tprint(1, "\"%s\" vs \"%s\": matched %" PRIu_SIZE_T " time(s)\n",
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
867 def->pattern, def->str,
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
868 nmatches);
647
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
869
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 724
diff changeset
870 test_regex_list_matches(def->str, matches, def->expected, false);
647
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
871
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
872 out:
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
873 th_regex_free_matches(matches);
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
874 th_regex_free(expr);
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
875 }
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
876 }
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
877
614
afcaf5e38f56 Disable regex stuff from normal builds.
Matti Hamalainen <ccr@tnsp.org>
parents: 613
diff changeset
878 #endif
afcaf5e38f56 Disable regex stuff from normal builds.
Matti Hamalainen <ccr@tnsp.org>
parents: 613
diff changeset
879
605
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
880
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
881 int main(int argc, char *argv[])
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
882 {
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
883 size_t i1, i2, i3, i4;
326
75b22d6f8a71 Simplify and improve integer sprintf() tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 319
diff changeset
884 char buf[64], buf2[64];
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
885
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
886 //
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
887 // Initialization
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
888 //
505
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
889 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
890 th_verbosity = 0;
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
891
603
be957142ab37 Add TEST_ASSERT() and test sizes of some types before doing anything else.
Matti Hamalainen <ccr@tnsp.org>
parents: 602
diff changeset
892 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
893 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
894 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
895 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
896 TEST_ASSERT(sizeof(uint64_t) == 8);
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
897
523
9acbbfea68a9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 521
diff changeset
898 tests_failed = tests_passed = tests_total =
9acbbfea68a9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 521
diff changeset
899 sets_total = sets_nenabled = 0;
9acbbfea68a9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 521
diff changeset
900
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
901 for (i1 = 0; i1 < SET_MAX_TESTS; i1++)
365
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
902 sets_enabled[i1] = 1;
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
903
651
18fe45e61b2b Moar re-work.
Matti Hamalainen <ccr@tnsp.org>
parents: 650
diff changeset
904 th_io_init_stdio(&testio, stdout);
18fe45e61b2b Moar re-work.
Matti Hamalainen <ccr@tnsp.org>
parents: 650
diff changeset
905
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
906 //
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
907 // Parse command line arguments
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
908 //
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
909 if (!th_args_process(argc, argv, arg_opts, arg_nopts,
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
910 arg_handle_opt, NULL, 0))
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
911 return 0;
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
912
365
c39f8e22ca1c Refactor testing a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 364
diff changeset
913 tprint(1, "Enabled test types are 0x%04x.\n", optFlags);
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
914
743
e2873f764b63 Add few simplistic tests of th_file module functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
915 //
e2873f764b63 Add few simplistic tests of th_file module functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
916 // File functions
e2873f764b63 Add few simplistic tests of th_file module functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
917 //
e2873f764b63 Add few simplistic tests of th_file module functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
918 if (test_set_start("file functions"))
e2873f764b63 Add few simplistic tests of th_file module functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
919 {
e2873f764b63 Add few simplistic tests of th_file module functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
920 char *home = th_get_home_dir(), *cfg = th_get_config_dir();
e2873f764b63 Add few simplistic tests of th_file module functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
921 th_stat_data stat;
748
3f59c5ab7fea Add #ifdef to avoid unused variable warning.
Matti Hamalainen <ccr@tnsp.org>
parents: 745
diff changeset
922 #ifdef TH_PLAT_UNIX
743
e2873f764b63 Add few simplistic tests of th_file module functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
923 int res;
748
3f59c5ab7fea Add #ifdef to avoid unused variable warning.
Matti Hamalainen <ccr@tnsp.org>
parents: 745
diff changeset
924 #endif
743
e2873f764b63 Add few simplistic tests of th_file module functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
925
764
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
926 TEST_1B("%s", home, !=, NULL);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
927 TEST_1B("%s", cfg, !=, NULL);
743
e2873f764b63 Add few simplistic tests of th_file module functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
928
764
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
929 TEST_1A(th_stat_path(home, &stat) == true);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
930 TEST_1B("%d", (stat.flags & TH_IS_DIR), !=, 0);
743
e2873f764b63 Add few simplistic tests of th_file module functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
931
745
0c90dd46c49f Only do certain th_file tests if we are compiled for *NIX (Win/DOS specific
Matti Hamalainen <ccr@tnsp.org>
parents: 743
diff changeset
932 #ifdef TH_PLAT_UNIX
764
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
933 TEST_1A(th_stat_path("/nonexist", &stat) == false);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
934 TEST_1A(th_stat_path("/root", &stat) == true);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
935 TEST_1B("%d", (stat.flags & TH_IS_WRITABLE), ==, 0);
743
e2873f764b63 Add few simplistic tests of th_file module functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
936
764
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
937 TEST_1A((res = th_mkdir_path("/tmp/thlibtest/foobar/baz", 0)) == THERR_OK);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
938 TEST_1B("%d", res, ==, THERR_OK);
743
e2873f764b63 Add few simplistic tests of th_file module functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
939 if (res == THERR_OK)
e2873f764b63 Add few simplistic tests of th_file module functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
940 {
764
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
941 TEST_1A(th_stat_path("/tmp/thlibtest/foobar/baz", &stat) == true);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
942 TEST_1B("%d", (stat.flags & TH_IS_DIR), !=, 0);
743
e2873f764b63 Add few simplistic tests of th_file module functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
943 }
745
0c90dd46c49f Only do certain th_file tests if we are compiled for *NIX (Win/DOS specific
Matti Hamalainen <ccr@tnsp.org>
parents: 743
diff changeset
944 #endif
784
1db55c733f7d Fix memory leaks in tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 781
diff changeset
945 th_free(home);
1db55c733f7d Fix memory leaks in tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 781
diff changeset
946 th_free(cfg);
743
e2873f764b63 Add few simplistic tests of th_file module functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
947 }
525
59b8f15c5334 Add (compile-time enabled via TH_PRINTF_DEBUG define) global variable for
Matti Hamalainen <ccr@tnsp.org>
parents: 524
diff changeset
948
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
949 //
405
4e8f26a49e27 Update comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 404
diff changeset
950 // Test series for printf()
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
951 //
544
619e7fcff486 Add more printf() format tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
952 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
953 char *i_mods[] = { "", "-", "+", "#", " ", };
343
2b58dd3f5e6c Add more tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 342
diff changeset
954 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
955
295
bd69fdaad70a Rename test sets.
Matti Hamalainen <ccr@tnsp.org>
parents: 293
diff changeset
956 if (test_set_start("printf() integer"))
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
957 {
526
32245648f0f0 More printf() format specifier tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 525
diff changeset
958 int i_vals[] = {
532
ad64c3f7cf64 Adjust printf int formatting test values and format specifiers.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
959 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
960 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
961 2147483647, -2147483648 };
315
2b657dcf346e More tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 312
diff changeset
962
327
b0f9f806c8c9 Implement NCOUNT() macro for getting array element counts (sizeof(arr) / sizeof(arr[0]))
Matti Hamalainen <ccr@tnsp.org>
parents: 326
diff changeset
963 for (i1 = 0; i1 < NCOUNT(i_vals); i1++)
315
2b657dcf346e More tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 312
diff changeset
964 {
319
f2af6049d958 Improve testing.
Matti Hamalainen <ccr@tnsp.org>
parents: 317
diff changeset
965 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
966
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
967 for (i4 = 0; i4 < NCOUNT(i_mods); i4++)
332
799e38f867da Use NCOUNT().
Matti Hamalainen <ccr@tnsp.org>
parents: 331
diff changeset
968 for (i3 = 0; i3 < NCOUNT(i_types); i3++)
799e38f867da Use NCOUNT().
Matti Hamalainen <ccr@tnsp.org>
parents: 331
diff changeset
969 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
970 {
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
971 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
972 test_snprintf(buf, buf2, i_vals[i1]);
75b22d6f8a71 Simplify and improve integer sprintf() tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 319
diff changeset
973 }
304
3fcf42cce43d Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
974 }
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
975 }
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
976
724
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
977 if (test_set_start("printf() integer 64bit generic"))
331
6e42d50c08c4 Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
978 {
532
ad64c3f7cf64 Adjust printf int formatting test values and format specifiers.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
979 int64_t i_vals64[] = {
544
619e7fcff486 Add more printf() format tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
980 0, -0, 1, -1, 10, -10, 512, -512, -1024,
619e7fcff486 Add more printf() format tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
981 612342, -612342, 0x1fff, 0x8000000, -123456789,
619e7fcff486 Add more printf() format tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
982 4294967295, -2147483648,
532
ad64c3f7cf64 Adjust printf int formatting test values and format specifiers.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
983 0x3342344341fff, 0x1f8000000, };
331
6e42d50c08c4 Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
984
333
a705d21ca25b Simplify tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 332
diff changeset
985 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
986 {
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
987 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
988
340
cde5415c4201 Fix 64bit int tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 339
diff changeset
989 for (i4 = 0; i4 < NCOUNT(i_mods); i4++)
332
799e38f867da Use NCOUNT().
Matti Hamalainen <ccr@tnsp.org>
parents: 331
diff changeset
990 for (i3 = 0; i3 < NCOUNT(i_types); i3++)
799e38f867da Use NCOUNT().
Matti Hamalainen <ccr@tnsp.org>
parents: 331
diff changeset
991 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
992 {
402
ec4c395aadb8 Fix some tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 395
diff changeset
993 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
994 test_snprintf(buf, buf2, i_vals64[i1]);
331
6e42d50c08c4 Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
995 }
6e42d50c08c4 Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
996 }
6e42d50c08c4 Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
997 }
6e42d50c08c4 Add tests for 64bit int prints.
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
998
724
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
999 if (test_set_start("printf() integer 64bit PRI* specifiers"))
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1000 {
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1001 int64_t i_vals64[] = {
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1002 0, -0, 1, -1, 10, -10, 512, -512, -1024,
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1003 612342, -612342, 0x1fff, 0x8000000, -123456789,
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1004 4294967295, -2147483648,
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1005 0x3342344341fff, 0x1f8000000, };
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1006
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1007 for (i1 = 0; i1 < NCOUNT(i_vals64); i1++)
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1008 {
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1009 snprintf(buf, sizeof(buf), "%" PRId64, i_vals64[i1]);
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1010
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1011 for (i4 = 0; i3 < NCOUNT(i_mods); i3++)
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1012 for (i2 = 0; i2 < NCOUNT(i_fmts); i2++)
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1013 {
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1014 snprintf(buf2, sizeof(buf2), "%%%s%s" PRId64, i_mods[i3], i_fmts[i2]);
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1015 test_snprintf(buf, buf2, i_vals64[i1]);
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1016
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1017 snprintf(buf2, sizeof(buf2), "%%%s%s" PRIx64, i_mods[i3], i_fmts[i2]);
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1018 test_snprintf(buf, buf2, i_vals64[i1]);
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1019
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1020 snprintf(buf2, sizeof(buf2), "%%%s%s" PRIX64, i_mods[i3], i_fmts[i2]);
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1021 test_snprintf(buf, buf2, i_vals64[i1]);
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1022 }
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1023 }
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1024 }
388d72f4189d Add some tests for PRI* printf specifiers to test 64bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 713
diff changeset
1025
533
ef0d732fabe0 Disable floating point printf implementation tests as the support is not
Matti Hamalainen <ccr@tnsp.org>
parents: 532
diff changeset
1026 #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
1027 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
1028 {
544
619e7fcff486 Add more printf() format tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
1029 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
1030 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
1031
327
b0f9f806c8c9 Implement NCOUNT() macro for getting array element counts (sizeof(arr) / sizeof(arr[0]))
Matti Hamalainen <ccr@tnsp.org>
parents: 326
diff changeset
1032 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
1033 {
319
f2af6049d958 Improve testing.
Matti Hamalainen <ccr@tnsp.org>
parents: 317
diff changeset
1034 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
1035 for (i2 = 0; i2 < NCOUNT(f_fmts); i2++)
319
f2af6049d958 Improve testing.
Matti Hamalainen <ccr@tnsp.org>
parents: 317
diff changeset
1036 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
1037 }
296
ec8357d02a52 Add floating point tests (which will fail for now).
Matti Hamalainen <ccr@tnsp.org>
parents: 295
diff changeset
1038 }
533
ef0d732fabe0 Disable floating point printf implementation tests as the support is not
Matti Hamalainen <ccr@tnsp.org>
parents: 532
diff changeset
1039 #endif
296
ec8357d02a52 Add floating point tests (which will fail for now).
Matti Hamalainen <ccr@tnsp.org>
parents: 295
diff changeset
1040
295
bd69fdaad70a Rename test sets.
Matti Hamalainen <ccr@tnsp.org>
parents: 293
diff changeset
1041 if (test_set_start("printf() string"))
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
1042 {
407
d1a06a38a958 Add some more tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 405
diff changeset
1043 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
1044 // char *s_fmts[] = { "%s", "%2s", "%-2s", "%5s", "%-5s", "%16s", "%-16s", "%1s", "%-1s", "% 2s", "%03s", "% -12s", "% 03s", "%-.15s", "%.8s" };
749
feadd3678d2e Oops, typofix, missing comma separator between string elements :O
Matti Hamalainen <ccr@tnsp.org>
parents: 748
diff changeset
1045 char *s_fmts[] = { "", "-", " ", "0", " 0", ".", "-.", };
596
4ea7b0e9dcba Improve string printf() tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 592
diff changeset
1046 int s_widths[] = { 0, 1, 2, 5, 16, };
265
effb2786f6a6 More work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
1047
327
b0f9f806c8c9 Implement NCOUNT() macro for getting array element counts (sizeof(arr) / sizeof(arr[0]))
Matti Hamalainen <ccr@tnsp.org>
parents: 326
diff changeset
1048 for (i1 = 0; i1 < NCOUNT(s_vals); i1++)
596
4ea7b0e9dcba Improve string printf() tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 592
diff changeset
1049 for (i2 = 0; i2 < NCOUNT(s_fmts); i2++)
4ea7b0e9dcba Improve string printf() tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 592
diff changeset
1050 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
1051 {
596
4ea7b0e9dcba Improve string printf() tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 592
diff changeset
1052 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
1053 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
1054 }
288
89c7696acb82 Add some tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 282
diff changeset
1055 }
89c7696acb82 Add some tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 282
diff changeset
1056
295
bd69fdaad70a Rename test sets.
Matti Hamalainen <ccr@tnsp.org>
parents: 293
diff changeset
1057 if (test_set_start("printf() char"))
288
89c7696acb82 Add some tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 282
diff changeset
1058 {
319
f2af6049d958 Improve testing.
Matti Hamalainen <ccr@tnsp.org>
parents: 317
diff changeset
1059 const char c_val = 'x';
f2af6049d958 Improve testing.
Matti Hamalainen <ccr@tnsp.org>
parents: 317
diff changeset
1060 const char *c_msg = "x";
352
75b20d9bef64 Add few more tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 347
diff changeset
1061 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
1062
0146aa9a9524 Simplify char printf tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
1063 for (i1 = 0; i1 < NCOUNT(c_fmts); i1++)
0146aa9a9524 Simplify char printf tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 327
diff changeset
1064 test_snprintf(c_msg, c_fmts[i1], c_val);
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
1065 }
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
1066
356
d7f43fce0dce Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents: 352
diff changeset
1067 if (test_set_start("printf() pointers"))
d7f43fce0dce Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents: 352
diff changeset
1068 {
407
d1a06a38a958 Add some more tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 405
diff changeset
1069 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
1070 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
1071
d7f43fce0dce Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents: 352
diff changeset
1072 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
1073 {
d7f43fce0dce Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents: 352
diff changeset
1074 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
1075 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
1076 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
1077 }
d7f43fce0dce Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents: 352
diff changeset
1078 }
d7f43fce0dce Add tests for printing pointers (%p formatters).
Matti Hamalainen <ccr@tnsp.org>
parents: 352
diff changeset
1079
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
1080 //
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
1081 // String matching functions
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
1082 //
465
6d44592cdab1 Improve tests slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 457
diff changeset
1083 if (test_set_start("String compare #1"))
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
1084 {
764
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1085 TEST_2A(th_strcasecmp, "aSdFq" , "asdfq" , true);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1086 TEST_2A(th_strcasecmp, "aSdFq" , "asFfq" , false);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1087 TEST_2A(th_strcasecmp, "abcde" , "abcde" , true);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1088 TEST_2A(th_strcasecmp, "öäå" , "öäå" , true);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1089 TEST_2A(th_strcasecmp, "aöäå" , "aöäå" , true);
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
1090 }
255
7549e279fe18 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
1091
465
6d44592cdab1 Improve tests slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 457
diff changeset
1092 if (test_set_start("String compare #2"))
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
1093 {
764
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1094 TEST_3A(th_strncasecmp, "aSdFq" , "asFfqB" , 4, false);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1095 TEST_3A(th_strncasecmp, "aSdFq" , "asFfqQ" , 2, true);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1096 TEST_3A(th_strncasecmp, "aSdFq" , "asDfq" , 3, true);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1097 TEST_3A(th_strncasecmp, "aSdFq" , "asDfq" , 2, true);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1098 TEST_3A(th_strncasecmp, "aSdFq" , "asDfq" , 0, true);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1099 TEST_3A(th_strncasecmp, "aSdFq" , "QsDfq" , 0, true);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1100 TEST_3A(th_strncasecmp, "aSdFq" , "QsDfq" , 1, false);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1101 TEST_3A(th_strncasecmp, "max=" , "max=4" , 4, true);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1102 TEST_3A(th_strncasecmp, "max=" , "max" , 4, false);
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
1103 }
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
1104
465
6d44592cdab1 Improve tests slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 457
diff changeset
1105 if (test_set_start("String compare #3"))
6d44592cdab1 Improve tests slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 457
diff changeset
1106 {
764
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1107 TEST_2C(th_strrcasecmp, "foo aSdFq", " asdfq", true);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1108 TEST_2C(th_strrcasecmp, "aSdFq", " asdfq", false);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1109 TEST_2C(th_strrcasecmp, "foo aSdFq baz", "asdfq", false);
465
6d44592cdab1 Improve tests slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 457
diff changeset
1110 }
6d44592cdab1 Improve tests slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 457
diff changeset
1111
768
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1112 if (test_set_start("String matching #1 (case-sensitive)"))
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
1113 {
768
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1114 TEST_3B(th_strmatch, "abba ABBAkukka lol" , "*lol" , false, true);
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1115 TEST_3B(th_strmatch, "abba ABBAkukka lol" , "*lo*" , false, true);
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1116 TEST_3B(th_strmatch, "abba ABBAkukka lol" , "*lo" , false, false);
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1117 TEST_3B(th_strmatch, "abba ABBAkukka lol" , "abba" , false, false);
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1118 TEST_3B(th_strmatch, "abba ABBAkukka lol" , "*bba*" , false, true);
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1119 TEST_3B(th_strmatch, "abba ABBAkukka lol" , "abba*" , false, true);
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1120 TEST_3B(th_strmatch, "abba ABBAkukka lol" , "abbak*" , false, false);
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1121 TEST_3B(th_strmatch, "abba ABBAöökukka lol" , "*abbaö?" , false, false);
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
1122 }
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
1123
768
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1124 if (test_set_start("String matching #2 (case-insensitive)"))
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
1125 {
768
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1126 TEST_3B(th_strcasematch, "abba ABBAkukka lol" , "abbak*" , false, false);
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1127 TEST_3B(th_strcasematch, "abba ABBAkukka lol" , "*abbak*" , false, true);
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1128 TEST_3B(th_strcasematch, "abba ABBAkukka lol" , "*ab?ak*" , false, true);
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1129 TEST_3B(th_strcasematch, "abba ABBAkukka lol" , "*abbak?" , false, false);
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1130 TEST_3B(th_strcasematch, "abba ABBAkukka lol" , "?bba?abba*" , false, true);
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1131 }
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1132
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1133 if (test_set_start("String matching #3 (escapes)"))
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1134 {
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1135 TEST_3B(th_strcasematch, "abba ABBA*kukka lol" , "*abba\\*ku*" , true, true);
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1136 TEST_3B(th_strcasematch, "abba ABBAkuk?ka lol" , "*kuk\\?ka*" , true, true);
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1137 TEST_3B(th_strcasematch, "abba ABBA*kukka lol" , "*abba*ku*" , true, true);
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1138 TEST_3B(th_strcasematch, "abba ABBAkuk?ka lol" , "*kuk?ka*" , true, true);
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1139 TEST_3B(th_strcasematch, "abba ABBAkuk?ka lol" , "*kuk?ka\\*" , true, false);
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1140 TEST_3B(th_strcasematch, "abba ABBAkuk\\ka lol" , "*kuk\\\\ka*" , true, true);
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
1141 }
266
3a020aa05f28 More tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 265
diff changeset
1142
265
effb2786f6a6 More work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 264
diff changeset
1143 // 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
1144 // Unicode / multibyte UTF-8 causes problems here
508
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
1145 if ((optFlags & TST_BROKEN) &&
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
1146 test_set_start("Invalid UTF-8 handling"))
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
1147 {
764
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1148 TEST_2A(th_strcasecmp, "ÖÄÅ", "öäå", false); // if it worked, SHOULD match
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1149 TEST_3A(th_strncasecmp, "Aäöå", "aöå", 2, true); // if worked, it should NOT match
768
600a3c08747f Add handle_escapes parameter to th_str{case}match() functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 764
diff changeset
1150 TEST_3B(th_strmatch, "öriÖRI! lol", "?ri?RI!*", false, false); // should match
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
1151 }
266
3a020aa05f28 More tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 265
diff changeset
1152
508
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
1153 //
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
1154 // printf() PRI* format specifiers, also a compile time test
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
1155 //
501
d42574b3dc00 Adjust two test names.
Matti Hamalainen <ccr@tnsp.org>
parents: 492
diff changeset
1156 if (test_set_start("PRI* specifiers"))
492
185a6ea03fea Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents: 469
diff changeset
1157 {
185a6ea03fea Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents: 469
diff changeset
1158 char tmp[32];
185a6ea03fea Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents: 469
diff changeset
1159 uint32_t u32 = 0xaabbccdd;
185a6ea03fea Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents: 469
diff changeset
1160 uint64_t u64 = 0xaabbccdd11223344;
185a6ea03fea Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents: 469
diff changeset
1161 size_t usiz =
185a6ea03fea Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents: 469
diff changeset
1162 #if TH_ARCH == 32
185a6ea03fea Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents: 469
diff changeset
1163 0x11223344;
185a6ea03fea Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents: 469
diff changeset
1164 #elif TH_ARCH == 64
185a6ea03fea Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents: 469
diff changeset
1165 0xaabbccdd11223344;
185a6ea03fea Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents: 469
diff changeset
1166 #else
613
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
1167 # error Unsupported TH_ARCH value.
492
185a6ea03fea Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents: 469
diff changeset
1168 #endif
185a6ea03fea Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents: 469
diff changeset
1169
185a6ea03fea Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents: 469
diff changeset
1170 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
1171 #if TH_ARCH == 32
764
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1172 TEST_2A(strcmp, tmp, "0000000011223344h", true);
492
185a6ea03fea Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents: 469
diff changeset
1173 #else
764
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1174 TEST_2A(strcmp, tmp, "aabbccdd11223344h", true);
492
185a6ea03fea Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents: 469
diff changeset
1175 #endif
185a6ea03fea Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents: 469
diff changeset
1176
185a6ea03fea Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents: 469
diff changeset
1177 snprintf(tmp, sizeof(tmp), "%08" PRIx32 "h", u32);
764
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1178 TEST_2A(strcmp, tmp, "aabbccddh", true);
492
185a6ea03fea Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents: 469
diff changeset
1179 snprintf(tmp, sizeof(tmp), "%16" PRIx64 "h", u64);
764
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1180 TEST_2A(strcmp, tmp, "aabbccdd11223344h", true);
492
185a6ea03fea Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents: 469
diff changeset
1181 }
185a6ea03fea Add some tests for PRI* types.
Matti Hamalainen <ccr@tnsp.org>
parents: 469
diff changeset
1182
508
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
1183 //
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
1184 // Configuration file handling
fe5e7bf704e5 Improvements to config tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 506
diff changeset
1185 //
523
9acbbfea68a9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 521
diff changeset
1186 if (test_set_start("Configuration file handling"))
505
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
1187 {
760
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
1188 test_config_file();
505
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
1189 }
50d71fc84831 Add simple tests for th_config.
Matti Hamalainen <ccr@tnsp.org>
parents: 502
diff changeset
1190
255
7549e279fe18 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
1191 //
760
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
1192 // Linked lists
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
1193 //
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
1194 if (test_set_start("Linked lists"))
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
1195 {
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
1196 test_linked_lists();
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
1197 }
1cb9454ec569 Add some simple tests for linked lists.
Matti Hamalainen <ccr@tnsp.org>
parents: 749
diff changeset
1198 //
524
19dc326dcdad Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 523
diff changeset
1199 // String functions
19dc326dcdad Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 523
diff changeset
1200 //
19dc326dcdad Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 523
diff changeset
1201 if (test_set_start("String functions"))
19dc326dcdad Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 523
diff changeset
1202 {
19dc326dcdad Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 523
diff changeset
1203 unsigned int tmpUint;
19dc326dcdad Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 523
diff changeset
1204
764
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1205 TEST_1A(th_get_hex_triplet("0fac11", &tmpUint) == true);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1206 TEST_1B("0x%06x", tmpUint, ==, 0x0fac11);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1207 TEST_1A(th_get_hex_triplet("120fac11", &tmpUint) == true);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1208 TEST_1B("0x%06x", tmpUint, ==, 0x120fac11);
0abba6091bd1 Clean up the tests a bit, rename macros, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 760
diff changeset
1209 TEST_1A(th_get_hex_triplet("x120fac11", &tmpUint) == false);
524
19dc326dcdad Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 523
diff changeset
1210 }
19dc326dcdad Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 523
diff changeset
1211
19dc326dcdad Add few tests for th_get_hex_triplet().
Matti Hamalainen <ccr@tnsp.org>
parents: 523
diff changeset
1212 //
605
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
1213 // Regular expressions
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
1214 //
614
afcaf5e38f56 Disable regex stuff from normal builds.
Matti Hamalainen <ccr@tnsp.org>
parents: 613
diff changeset
1215 #ifdef TH_EXPERIMENTAL_REGEX
605
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
1216 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
1217 {
635
d191ded8a790 Improve the experimental regex matching debugging macros.
Matti Hamalainen <ccr@tnsp.org>
parents: 614
diff changeset
1218 #ifdef TH_EXPERIMENTAL_REGEX_DEBUG
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1219 th_dbg_fh = (th_verbosity >= 3) ? &testio : NULL;
635
d191ded8a790 Improve the experimental regex matching debugging macros.
Matti Hamalainen <ccr@tnsp.org>
parents: 614
diff changeset
1220 #endif
d191ded8a790 Improve the experimental regex matching debugging macros.
Matti Hamalainen <ccr@tnsp.org>
parents: 614
diff changeset
1221
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1222 if (1)
645
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
1223 {
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
1224 const char *str = "z*k+abba fabboa? [a-zA-Z_-] \\{\\} k{4} ([0-9]+ yay){1,2} foo(bar|zoo)?";
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
1225 th_regex_t *expr = NULL;
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
1226 int res = th_regex_compile(&expr, str);
666
e1d27caf0dbd More work on regex stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 664
diff changeset
1227
645
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
1228 printf("REGEX: \"%s\"\n", str);
666
e1d27caf0dbd More work on regex stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 664
diff changeset
1229
645
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
1230 if (res == THERR_OK)
651
18fe45e61b2b Moar re-work.
Matti Hamalainen <ccr@tnsp.org>
parents: 650
diff changeset
1231 th_regex_dump(&testio, 1, expr);
645
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
1232 else
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
1233 printf("ERROR: %s\n", th_error_str(res));
666
e1d27caf0dbd More work on regex stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 664
diff changeset
1234
645
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
1235 th_regex_free(expr);
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
1236 }
b897995101b7 More fiddling and twiddling. Add parsing to string nodes instead of separate character nodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 643
diff changeset
1237
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1238 if (1)
640
9e1f9e1d1487 Aaand some more work. Still just a broken concept.
Matti Hamalainen <ccr@tnsp.org>
parents: 635
diff changeset
1239 {
647
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
1240 static const test_regex_def1 tlist[] =
613
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
1241 {
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1242 { "abcfoabcccg" , 0, { "abcfoabcccg", } },
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1243 { "sabcbcfoabcccgz" , 0, { "abcbcfoabcccg", } },
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1244 { "abcbcfoabccg abcbcfoabccccg" , 0, { "abcbcfoabccg", "abcbcfoabccccg" } },
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1245 { NULL , 0, { NULL } }
613
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
1246 };
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
1247
647
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
1248 test_regex_list1(tlist, "a(bc){1,2}fo[oab]*cc?g");
613
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
1249 }
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
1250
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1251 if (1)
605
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
1252 {
647
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
1253 static const test_regex_def1 tlist[] =
613
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
1254 {
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1255 { "abcfoabccg" , 0, { "abcfoabccg", } },
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1256 { "abcbcfoabccg" , 0, { "abcbcfoabccg", } },
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1257 { "abcbcfoabccgabcbcfoabccg" , 0, { "abcbcfoabccg", } },
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1258 { "ffdsafS abcbcfoabccg zasdf" , 0, { NULL } },
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1259 { NULL , 0, { NULL } }
613
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
1260 };
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
1261
647
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
1262 test_regex_list1(tlist, "^a(bc){1,2}fo[oab]*cc?g");
613
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
1263 }
605
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
1264
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1265 if (1)
613
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
1266 {
647
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
1267 static const test_regex_def1 tlist[] =
613
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
1268 {
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1269 { "cg" , 0, { "g", } },
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1270 { "g" , 0, { "g", } },
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1271 { "" , 0, { NULL, } },
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1272 { "c" , 0, { NULL, } },
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1273 { NULL , 0, { NULL } }
613
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
1274 };
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
1275
647
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
1276 test_regex_list1(tlist, "g$");
613
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
1277 }
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
1278
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1279 if (1)
613
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
1280 {
647
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
1281 static const test_regex_def1 tlist[] =
613
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
1282 {
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1283 { "kzoobarzz" , 0, { "zoobar", } },
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1284 { "hehzoo lol baromg" , 0, { "zoo lol bar", } },
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1285 { "hoho zoo lol lol bar bar f" , 0, { "zoo lol lol bar", } },
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1286 { "hoho zoobar bar heh" , 0, { "zoobar", } },
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1287 { NULL , 0, { NULL } }
613
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
1288 };
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
1289
647
1e7e3f96632e And some more work.
Matti Hamalainen <ccr@tnsp.org>
parents: 645
diff changeset
1290 test_regex_list1(tlist, "zoo.*?bar");
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1291 }
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1292
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1293 if (1)
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1294 {
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1295 static const test_regex_def1 tlist[] =
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1296 {
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1297 { "kzoobarzz" , 0, { "zoobar", } },
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1298 { "hehzoo lol baromg" , 0, { "zoo lol bar", } },
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1299 { "hoho zoo lol lol bar bar f" , 0, { "zoo lol lol bar bar", } },
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1300 { "hoho zoobar bar heh" , 0, { "zoobar bar", } },
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1301 { NULL , 0, { NULL } }
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1302 };
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1303
666
e1d27caf0dbd More work on regex stuff.
Matti Hamalainen <ccr@tnsp.org>
parents: 664
diff changeset
1304 test_regex_list1(tlist, "zoo.*bar");
613
2e3b81ae8c8a More work on regexes.
Matti Hamalainen <ccr@tnsp.org>
parents: 610
diff changeset
1305 }
668
48e8820bc625 Some work on the regex tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 666
diff changeset
1306
605
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
1307 }
614
afcaf5e38f56 Disable regex stuff from normal builds.
Matti Hamalainen <ccr@tnsp.org>
parents: 613
diff changeset
1308 #endif
605
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
1309
566e6ef41f9d Initial commit of the highly experimental and unfinished regular expression
Matti Hamalainen <ccr@tnsp.org>
parents: 603
diff changeset
1310 //
255
7549e279fe18 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
1311 // Print summary and exit
7549e279fe18 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
1312 //
304
3fcf42cce43d Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
1313 tprint(1,
276
56b0de9f9d44 Improve tests output per verbosity level.
Matti Hamalainen <ccr@tnsp.org>
parents: 274
diff changeset
1314 "======================================================\n");
282
f0cb48b34463 Implement selectable tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 276
diff changeset
1315
304
3fcf42cce43d Fix some tests and use stdout for output.
Matti Hamalainen <ccr@tnsp.org>
parents: 303
diff changeset
1316 tprint(0,
312
f1dfabd89a13 Improve tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 311
diff changeset
1317 "%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
1318 tests_failed, tests_passed, tests_total, sets_nenabled, sets_total);
255
7549e279fe18 Work on tests.
Matti Hamalainen <ccr@tnsp.org>
parents: 254
diff changeset
1319
254
3d1e2af4e4e6 Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1320 return 0;
3d1e2af4e4e6 Start of a very simplistic unit test suite. Initially handling just printf()
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1321 }