-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathzmsq_selftest.c
154 lines (138 loc) · 4.93 KB
/
zmsq_selftest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* =========================================================================
zmsq_selftest.c - run selftests
Runs all selftests.
-------------------------------------------------------------------------
Copyright (c) the Contributors as noted in the AUTHORS file.
This file is part of the Malamute Project.
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
################################################################################
# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
# Read the zproject/README.md for information about making permanent changes. #
################################################################################
=========================================================================
*/
#include "zmsq_classes.h"
typedef struct {
const char *testname;
void (*test) (bool);
} test_item_t;
static test_item_t
all_tests [] = {
#ifdef ZMSQ_BUILD_DRAFT_API
// Tests for draft public classes:
{ "zmosq_client", zmosq_client_test },
{ "zmosq_server", zmosq_server_test },
#endif // ZMSQ_BUILD_DRAFT_API
#ifdef ZMSQ_BUILD_DRAFT_API
{ "private_classes", zmsq_private_selftest },
#endif // ZMSQ_BUILD_DRAFT_API
{0, 0} // Sentinel
};
// -------------------------------------------------------------------------
// Test whether a test is available.
// Return a pointer to a test_item_t if available, NULL otherwise.
//
test_item_t *
test_available (const char *testname)
{
test_item_t *item;
for (item = all_tests; item->test; item++) {
if (streq (testname, item->testname))
return item;
}
return NULL;
}
// -------------------------------------------------------------------------
// Run all tests.
//
static void
test_runall (bool verbose)
{
test_item_t *item;
printf ("Running zmosq selftests...\n");
for (item = all_tests; item->test; item++)
item->test (verbose);
printf ("Tests passed OK\n");
}
int
main (int argc, char **argv)
{
bool verbose = false;
test_item_t *test = 0;
int argn;
for (argn = 1; argn < argc; argn++) {
if (streq (argv [argn], "--help")
|| streq (argv [argn], "-h")) {
puts ("zmsq_selftest.c [options] ...");
puts (" --verbose / -v verbose test output");
puts (" --number / -n report number of tests");
puts (" --list / -l list all tests");
puts (" --test / -t [name] run only test 'name'");
puts (" --continue / -c continue on exception (on Windows)");
return 0;
}
if (streq (argv [argn], "--verbose")
|| streq (argv [argn], "-v"))
verbose = true;
else
if (streq (argv [argn], "--number")
|| streq (argv [argn], "-n")) {
puts ("2");
return 0;
}
else
if (streq (argv [argn], "--list")
|| streq (argv [argn], "-l")) {
puts ("Available tests:");
puts (" zmosq_client\t\t- draft");
puts (" zmosq_server\t\t- draft");
puts (" private_classes\t- draft");
return 0;
}
else
if (streq (argv [argn], "--test")
|| streq (argv [argn], "-t")) {
argn++;
if (argn >= argc) {
fprintf (stderr, "--test needs an argument\n");
return 1;
}
test = test_available (argv [argn]);
if (!test) {
fprintf (stderr, "%s not valid, use --list to show tests\n", argv [argn]);
return 1;
}
}
else
if (streq (argv [argn], "--continue")
|| streq (argv [argn], "-c")) {
#ifdef _MSC_VER
// When receiving an abort signal, only print to stderr (no dialog)
_set_abort_behavior (0, _WRITE_ABORT_MSG);
#endif
}
else {
printf ("Unknown option: %s\n", argv [argn]);
return 1;
}
}
#ifdef NDEBUG
printf(" !!! 'assert' macro is disabled, remove NDEBUG from your compilation definitions.\n");
printf(" tests will be meaningless.\n");
#endif //
if (test) {
printf ("Running zmosq test '%s'...\n", test->testname);
test->test (verbose);
}
else
test_runall (verbose);
return 0;
}
/*
################################################################################
# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
# Read the zproject/README.md for information about making permanent changes. #
################################################################################
*/