annotate src/lib-test/test-common.h @ 22656:1789bf2a1e01

director: Make sure HOST-RESET-USERS isn't used with max_moving_users=0 The reset command would just hang in that case. doveadm would never have sent this, so this is just an extra sanity check.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Sun, 05 Nov 2017 23:51:56 +0200
parents 5be9ee567034
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9258
665ea7a8d26e Tests are now run on "make check". Added initial tests for lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1 #ifndef TEST_COMMON_H
665ea7a8d26e Tests are now run on "make check". Added initial tests for lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2 #define TEST_COMMON_H
665ea7a8d26e Tests are now run on "make check". Added initial tests for lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3
665ea7a8d26e Tests are now run on "make check". Added initial tests for lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 struct istream *test_istream_create(const char *data);
10185
7c3605774b93 lib-test: Added test_istream_create().
Timo Sirainen <tss@iki.fi>
parents: 9792
diff changeset
5 struct istream *test_istream_create_data(const void *data, size_t size);
9258
665ea7a8d26e Tests are now run on "make check". Added initial tests for lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 void test_istream_set_size(struct istream *input, uoff_t size);
665ea7a8d26e Tests are now run on "make check". Added initial tests for lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 void test_istream_set_allow_eof(struct istream *input, bool allow);
9792
0287c38ba6bf lib-test: Added test_istream_set_max_buffer_size().
Timo Sirainen <tss@iki.fi>
parents: 9555
diff changeset
8 void test_istream_set_max_buffer_size(struct istream *input, size_t size);
9258
665ea7a8d26e Tests are now run on "make check". Added initial tests for lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9
20810
5856fd118fb3 lib-test: Added test_ostream for testing nonblocking ostreams.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20713
diff changeset
10 struct ostream *test_ostream_create(buffer_t *output);
5856fd118fb3 lib-test: Added test_ostream for testing nonblocking ostreams.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20713
diff changeset
11 struct ostream *test_ostream_create_nonblocking(buffer_t *output,
5856fd118fb3 lib-test: Added test_ostream for testing nonblocking ostreams.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20713
diff changeset
12 size_t max_internal_buffer_size);
5856fd118fb3 lib-test: Added test_ostream for testing nonblocking ostreams.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20713
diff changeset
13 /* When output->used reaches max_size, start buffering output internally.
5856fd118fb3 lib-test: Added test_ostream for testing nonblocking ostreams.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20713
diff changeset
14 When internal buffer reaches max_internal_buffer_size, start returning 0 for
5856fd118fb3 lib-test: Added test_ostream for testing nonblocking ostreams.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20713
diff changeset
15 o_stream_send*(). */
5856fd118fb3 lib-test: Added test_ostream for testing nonblocking ostreams.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20713
diff changeset
16 void test_ostream_set_max_output_size(struct ostream *output, size_t max_size);
5856fd118fb3 lib-test: Added test_ostream for testing nonblocking ostreams.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20713
diff changeset
17
9258
665ea7a8d26e Tests are now run on "make check". Added initial tests for lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 void test_begin(const char *name);
665ea7a8d26e Tests are now run on "make check". Added initial tests for lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 #define test_assert(code) STMT_START { \
665ea7a8d26e Tests are now run on "make check". Added initial tests for lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 if (!(code)) test_assert_failed(#code, __FILE__, __LINE__); \
665ea7a8d26e Tests are now run on "make check". Added initial tests for lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 } STMT_END
17448
ed9e50227250 lib-test: test_assert helper for loops
Phil Carmody <phil@dovecot.fi>
parents: 14629
diff changeset
22 /* Additional parameter may be int or unsigned int, to indicate which of
ed9e50227250 lib-test: test_assert helper for loops
Phil Carmody <phil@dovecot.fi>
parents: 14629
diff changeset
23 * a barrage of tests have failed (such as in a loop).
ed9e50227250 lib-test: test_assert helper for loops
Phil Carmody <phil@dovecot.fi>
parents: 14629
diff changeset
24 */
ed9e50227250 lib-test: test_assert helper for loops
Phil Carmody <phil@dovecot.fi>
parents: 14629
diff changeset
25 #define test_assert_idx(code, i) STMT_START { \
ed9e50227250 lib-test: test_assert helper for loops
Phil Carmody <phil@dovecot.fi>
parents: 14629
diff changeset
26 if (!(code)) test_assert_failed_idx(#code, __FILE__, __LINE__, i); \
ed9e50227250 lib-test: test_assert helper for loops
Phil Carmody <phil@dovecot.fi>
parents: 14629
diff changeset
27 } STMT_END
20382
b70723e0bfb7 lib-test: add test_assert_failed_strcmp to expose strings.
Baofeng Wang <baofeng.wang@dovecot.fi>
parents: 18853
diff changeset
28 /* Additional parameters are s1 (source) and s2 (destination) string
b70723e0bfb7 lib-test: add test_assert_failed_strcmp to expose strings.
Baofeng Wang <baofeng.wang@dovecot.fi>
parents: 18853
diff changeset
29 * in strcmp().
b70723e0bfb7 lib-test: add test_assert_failed_strcmp to expose strings.
Baofeng Wang <baofeng.wang@dovecot.fi>
parents: 18853
diff changeset
30 */
b70723e0bfb7 lib-test: add test_assert_failed_strcmp to expose strings.
Baofeng Wang <baofeng.wang@dovecot.fi>
parents: 18853
diff changeset
31 #define test_assert_strcmp(s1, s2) STMT_START { \
b70723e0bfb7 lib-test: add test_assert_failed_strcmp to expose strings.
Baofeng Wang <baofeng.wang@dovecot.fi>
parents: 18853
diff changeset
32 if ((strcmp(s1,s2) != 0)) test_assert_failed_strcmp("strcmp(" #s1 "," #s2 ")", __FILE__, __LINE__, s1, s2); \
b70723e0bfb7 lib-test: add test_assert_failed_strcmp to expose strings.
Baofeng Wang <baofeng.wang@dovecot.fi>
parents: 18853
diff changeset
33 } STMT_END
b70723e0bfb7 lib-test: add test_assert_failed_strcmp to expose strings.
Baofeng Wang <baofeng.wang@dovecot.fi>
parents: 18853
diff changeset
34
9258
665ea7a8d26e Tests are now run on "make check". Added initial tests for lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 void test_assert_failed(const char *code, const char *file, unsigned int line);
17448
ed9e50227250 lib-test: test_assert helper for loops
Phil Carmody <phil@dovecot.fi>
parents: 14629
diff changeset
36 void test_assert_failed_idx(const char *code, const char *file, unsigned int line, long long i);
20382
b70723e0bfb7 lib-test: add test_assert_failed_strcmp to expose strings.
Baofeng Wang <baofeng.wang@dovecot.fi>
parents: 18853
diff changeset
37 void test_assert_failed_strcmp(const char *code, const char *file, unsigned int line,
b70723e0bfb7 lib-test: add test_assert_failed_strcmp to expose strings.
Baofeng Wang <baofeng.wang@dovecot.fi>
parents: 18853
diff changeset
38 const char * src, const char * dst);
17525
e1686f44f2e7 lib-test: Enable looped tests to abort early on first failure
Phil Carmody <phil@dovecot.fi>
parents: 17448
diff changeset
39 bool test_has_failed(void);
18852
3275eee3613b lib-test: let tests invoke i_warning/i_error behaviour
Phil Carmody <phil@dovecot.fi>
parents: 17669
diff changeset
40 /* If you're testing nasty cases which you want to warn, surround the noisy op with these */
3275eee3613b lib-test: let tests invoke i_warning/i_error behaviour
Phil Carmody <phil@dovecot.fi>
parents: 17669
diff changeset
41 void test_expect_errors(unsigned int expected);
18853
8739d201898c lib-test: test_expect_error_string() to match a single known message
Phil Carmody <phil@dovecot.fi>
parents: 18852
diff changeset
42 void test_expect_error_string(const char *substr); /* expect just 1 message matching the printf format */
18852
3275eee3613b lib-test: let tests invoke i_warning/i_error behaviour
Phil Carmody <phil@dovecot.fi>
parents: 17669
diff changeset
43 void test_expect_no_more_errors(void);
20711
966f41e7b975 lib-test: improve expected error handling
Phil Carmody <phil@dovecot.fi>
parents: 20382
diff changeset
44 /* Note that test_expect_error{s,_string}() effectively begin with a check equivalent
966f41e7b975 lib-test: improve expected error handling
Phil Carmody <phil@dovecot.fi>
parents: 20382
diff changeset
45 to test_expect_no_more_errors(), so you don't need the latter explicitly if following
966f41e7b975 lib-test: improve expected error handling
Phil Carmody <phil@dovecot.fi>
parents: 20382
diff changeset
46 it with either of the former.*/
966f41e7b975 lib-test: improve expected error handling
Phil Carmody <phil@dovecot.fi>
parents: 20382
diff changeset
47
9258
665ea7a8d26e Tests are now run on "make check". Added initial tests for lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48 void test_end(void);
665ea7a8d26e Tests are now run on "make check". Added initial tests for lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49
665ea7a8d26e Tests are now run on "make check". Added initial tests for lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50 void test_out(const char *name, bool success);
17571
36d07648cec8 lib-test: test-common - add test_out_quiet() to reduce verbosity
Phil Carmody <phil@dovecot.fi>
parents: 17525
diff changeset
51 void test_out_quiet(const char *name, bool success); /* only prints failures */
14629
c93ca5e46a8a Marked functions parameters that are allowed to be NULL. Some APIs were also changed.
Timo Sirainen <tss@iki.fi>
parents: 10185
diff changeset
52 void test_out_reason(const char *name, bool success, const char *reason)
c93ca5e46a8a Marked functions parameters that are allowed to be NULL. Some APIs were also changed.
Timo Sirainen <tss@iki.fi>
parents: 10185
diff changeset
53 ATTR_NULL(3);
9258
665ea7a8d26e Tests are now run on "make check". Added initial tests for lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54
665ea7a8d26e Tests are now run on "make check". Added initial tests for lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 int test_run(void (*test_functions[])(void));
20712
8730e4b4ec11 lib-test: enable naming of tests, such that only a subset is run
Phil Carmody <phil@dovecot.fi>
parents: 20711
diff changeset
56 struct named_test {
8730e4b4ec11 lib-test: enable naming of tests, such that only a subset is run
Phil Carmody <phil@dovecot.fi>
parents: 20711
diff changeset
57 const char *name;
8730e4b4ec11 lib-test: enable naming of tests, such that only a subset is run
Phil Carmody <phil@dovecot.fi>
parents: 20711
diff changeset
58 void (*func)(void);
8730e4b4ec11 lib-test: enable naming of tests, such that only a subset is run
Phil Carmody <phil@dovecot.fi>
parents: 20711
diff changeset
59 };
8730e4b4ec11 lib-test: enable naming of tests, such that only a subset is run
Phil Carmody <phil@dovecot.fi>
parents: 20711
diff changeset
60 int test_run_named(struct named_test tests[], const char *match);
8730e4b4ec11 lib-test: enable naming of tests, such that only a subset is run
Phil Carmody <phil@dovecot.fi>
parents: 20711
diff changeset
61
8730e4b4ec11 lib-test: enable naming of tests, such that only a subset is run
Phil Carmody <phil@dovecot.fi>
parents: 20711
diff changeset
62 #define TEST_DECL(x) void x(void);
8730e4b4ec11 lib-test: enable naming of tests, such that only a subset is run
Phil Carmody <phil@dovecot.fi>
parents: 20711
diff changeset
63 #define TEST_NAMELESS(x) x, /* Were you to want to use the X trick but not name the tests */
8730e4b4ec11 lib-test: enable naming of tests, such that only a subset is run
Phil Carmody <phil@dovecot.fi>
parents: 20711
diff changeset
64 #define TEST_NAMED(x) { .name = #x , .func = x },
9258
665ea7a8d26e Tests are now run on "make check". Added initial tests for lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65
17669
aeb6520c0ae9 lib-test: permit tests of fatal conditions
Phil Carmody <phil@dovecot.fi>
parents: 17656
diff changeset
66 enum fatal_test_state {
aeb6520c0ae9 lib-test: permit tests of fatal conditions
Phil Carmody <phil@dovecot.fi>
parents: 17656
diff changeset
67 FATAL_TEST_FINISHED, /* no more test stages, don't call again */
aeb6520c0ae9 lib-test: permit tests of fatal conditions
Phil Carmody <phil@dovecot.fi>
parents: 17656
diff changeset
68 FATAL_TEST_FAILURE, /* single stage has failed, continue */
aeb6520c0ae9 lib-test: permit tests of fatal conditions
Phil Carmody <phil@dovecot.fi>
parents: 17656
diff changeset
69 FATAL_TEST_ABORT, /* something's gone horrifically wrong */
aeb6520c0ae9 lib-test: permit tests of fatal conditions
Phil Carmody <phil@dovecot.fi>
parents: 17656
diff changeset
70 };
21297
083846b77c3b lib-test: Introduce test_fatal_func_t as typedef and comment how it works.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20810
diff changeset
71 /* The fatal function is called first with stage=0. After each call the stage
083846b77c3b lib-test: Introduce test_fatal_func_t as typedef and comment how it works.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20810
diff changeset
72 is increased by 1. The idea is that each stage would be running an
083846b77c3b lib-test: Introduce test_fatal_func_t as typedef and comment how it works.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20810
diff changeset
73 individual test that is supposed to crash. The function is called until
083846b77c3b lib-test: Introduce test_fatal_func_t as typedef and comment how it works.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20810
diff changeset
74 FATAL_TEST_FINISHED or FATAL_TEST_ABORT is returned. */
21299
5be9ee567034 lib-test: Change test_fatal_func_t to take unsigned int stage as parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21298
diff changeset
75 typedef enum fatal_test_state test_fatal_func_t(unsigned int stage);
21297
083846b77c3b lib-test: Introduce test_fatal_func_t as typedef and comment how it works.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20810
diff changeset
76
20712
8730e4b4ec11 lib-test: enable naming of tests, such that only a subset is run
Phil Carmody <phil@dovecot.fi>
parents: 20711
diff changeset
77 struct named_fatal {
8730e4b4ec11 lib-test: enable naming of tests, such that only a subset is run
Phil Carmody <phil@dovecot.fi>
parents: 20711
diff changeset
78 const char *name;
21297
083846b77c3b lib-test: Introduce test_fatal_func_t as typedef and comment how it works.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20810
diff changeset
79 test_fatal_func_t *func;
20712
8730e4b4ec11 lib-test: enable naming of tests, such that only a subset is run
Phil Carmody <phil@dovecot.fi>
parents: 20711
diff changeset
80 };
17669
aeb6520c0ae9 lib-test: permit tests of fatal conditions
Phil Carmody <phil@dovecot.fi>
parents: 17656
diff changeset
81 int test_run_with_fatals(void (*test_functions[])(void),
21298
e99464c82e52 lib-test: test_run_with_fatals() now takes a const array
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21297
diff changeset
82 test_fatal_func_t *const fatal_functions[]);
20712
8730e4b4ec11 lib-test: enable naming of tests, such that only a subset is run
Phil Carmody <phil@dovecot.fi>
parents: 20711
diff changeset
83 int test_run_named_with_fatals(const char *match, struct named_test tests[],
8730e4b4ec11 lib-test: enable naming of tests, such that only a subset is run
Phil Carmody <phil@dovecot.fi>
parents: 20711
diff changeset
84 struct named_fatal fatals[]);
8730e4b4ec11 lib-test: enable naming of tests, such that only a subset is run
Phil Carmody <phil@dovecot.fi>
parents: 20711
diff changeset
85
21299
5be9ee567034 lib-test: Change test_fatal_func_t to take unsigned int stage as parameter.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21298
diff changeset
86 #define FATAL_DECL(x) enum fatal_test_state x(unsigned int);
20712
8730e4b4ec11 lib-test: enable naming of tests, such that only a subset is run
Phil Carmody <phil@dovecot.fi>
parents: 20711
diff changeset
87 #define FATAL_NAMELESS(x) x, /* Were you to want to use the X trick but not name the tests */
8730e4b4ec11 lib-test: enable naming of tests, such that only a subset is run
Phil Carmody <phil@dovecot.fi>
parents: 20711
diff changeset
88 #define FATAL_NAMED(x) { .name = #x , .func = x },
17669
aeb6520c0ae9 lib-test: permit tests of fatal conditions
Phil Carmody <phil@dovecot.fi>
parents: 17656
diff changeset
89
20713
3d0aecd0b2bc lib-test: test-exit helper to stop valgrind complaining about fork()s
Phil Carmody <phil@dovecot.fi>
parents: 20712
diff changeset
90 /* If a fork() wants to exit(), then this will avoid valgrind leak errors */
3d0aecd0b2bc lib-test: test-exit helper to stop valgrind complaining about fork()s
Phil Carmody <phil@dovecot.fi>
parents: 20712
diff changeset
91 void test_exit(int status) ATTR_NORETURN;
3d0aecd0b2bc lib-test: test-exit helper to stop valgrind complaining about fork()s
Phil Carmody <phil@dovecot.fi>
parents: 20712
diff changeset
92
9258
665ea7a8d26e Tests are now run on "make check". Added initial tests for lib-index.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93 #endif