test-common.h revision 440f9bf580c42860f741560cbc3789be959cf777
#ifndef TEST_COMMON_H
#define TEST_COMMON_H
/* When output->used reaches max_size, start buffering output internally.
When internal buffer reaches max_internal_buffer_size, start returning 0 for
o_stream_send*(). */
void test_begin(const char *name);
} STMT_END
/* Additional parameter may be int or unsigned int, to indicate which of
* a barrage of tests have failed (such as in a loop).
*/
} STMT_END
/* Additional parameters are s1 (source) and s2 (destination) string
* in strcmp().
*/
if ((strcmp(s1,s2) != 0)) test_assert_failed_strcmp("strcmp(" #s1 "," #s2 ")", __FILE__, __LINE__, s1, s2); \
} STMT_END
bool test_has_failed(void);
/* If you're testing nasty cases which you want to warn, surround the noisy op with these */
void test_expect_errors(unsigned int expected);
void test_expect_error_string(const char *substr); /* expect just 1 message matching the printf format */
void test_expect_no_more_errors(void);
/* Note that test_expect_error{s,_string}() effectively begin with a check equivalent
to test_expect_no_more_errors(), so you don't need the latter explicitly if following
it with either of the former.*/
void test_end(void);
ATTR_NULL(3);
int test_run(void (*const test_functions[])(void));
struct named_test {
const char *name;
void (*func)(void);
};
#define TEST_DECL(x) void x(void);
#define TEST_NAMELESS(x) x, /* Were you to want to use the X trick but not name the tests */
enum fatal_test_state {
FATAL_TEST_FINISHED, /* no more test stages, don't call again */
FATAL_TEST_FAILURE, /* single stage has failed, continue */
FATAL_TEST_ABORT, /* something's gone horrifically wrong */
};
/* The fatal function is called first with stage=0. After each call the stage
is increased by 1. The idea is that each stage would be running an
individual test that is supposed to crash. The function is called until
FATAL_TEST_FINISHED or FATAL_TEST_ABORT is returned. */
struct named_fatal {
const char *name;
};
int test_run_with_fatals(void (*const test_functions[])(void),
test_fatal_func_t *const fatal_functions[]);
const struct named_fatal fatals[]);
#define FATAL_DECL(x) enum fatal_test_state x(unsigned int);
#define FATAL_NAMELESS(x) x, /* Were you to want to use the X trick but not name the tests */
/* If a fork() wants to exit(), then this will avoid valgrind leak errors */
#endif