24 #ifndef OM_HGUARD_TESTSUITE_H 25 #define OM_HGUARD_TESTSUITE_H 29 #ifndef XAPIAN_UNITTEST 31 # define UNITTEST_CHECK_EXCEPTION 56 #define THROW_TEST_(EXCEPTION, MSG) \ 59 tout << __FILE__ ":" STRINGIZE(__LINE__) ": " << MSG << '\n'; \ 68 #define FAIL_TEST(MSG) THROW_TEST_(TestFail, MSG) 74 #define SKIP_TEST(MSG) THROW_TEST_(TestSkip, MSG) 105 extern std::ostringstream
tout;
110 void write_and_clear_tout();
118 unsigned int succeeded = 0;
121 unsigned int failed = 0;
124 unsigned int skipped = 0;
130 unsigned int xfailed = 0;
136 unsigned int xpassed = 0;
164 static void add_command_line_option(
const std::string &l,
char s,
172 static void parse_command_line(
int argc,
char **argv);
174 XAPIAN_NORETURN(
static void usage());
190 result run_tests(std::vector<std::string>::const_iterator b,
191 std::vector<std::string>::const_iterator e);
196 static std::string get_srcdir();
213 XPASS = 3,
XFAIL = 2, PASS = 1, FAIL = 0, SKIP = -1
237 result do_run_tests(std::vector<std::string>::const_iterator b,
238 std::vector<std::string>::const_iterator e);
256 static std::string col_red, col_green,
col_yellow, col_reset;
267 #define TEST_AND_EXPLAIN(a, b) do {\ 268 bool test_and_explain_fail_ = !(a);\ 269 UNITTEST_CHECK_EXCEPTION\ 270 if (test_and_explain_fail_)\ 271 FAIL_TEST(STRINGIZE(a) << '\n' << b << '\n');\ 275 #define TEST(a) TEST_AND_EXPLAIN(a, "") 278 #define TEST_EQUAL(a, b) TEST_AND_EXPLAIN(((a) == (b)), \ 279 "Expected '" STRINGIZE(a) "' and '" STRINGIZE(b) "' to be equal:" \ 280 " were " << (a) << " and " << (b)) 287 #define TEST_STRINGS_EQUAL(a, b) TEST_AND_EXPLAIN(((a) == (b)), \ 288 "Expected " STRINGIZE(a) " and " STRINGIZE(b) " to be equal, were:\n\"" \ 289 << (a) << "\"\n\"" << (b) << '"') 295 #define TEST_EQUAL_DOUBLE(a, b) TEST_AND_EXPLAIN(TEST_EQUAL_DOUBLE_((a), (b)), \ 296 "Expected '" STRINGIZE(a) "' and '" STRINGIZE(b) "' to be (nearly) equal:" \ 297 " were " << setprecision(DBL_DIG) << (a) << " and " << (b) << ")" << setprecision(6)) 300 #define TEST_NOT_EQUAL_DOUBLE(a, b) TEST_AND_EXPLAIN(!TEST_EQUAL_DOUBLE_((a), (b)), \ 301 "Expected '" STRINGIZE(a) "' and '" STRINGIZE(b) "' not to be (nearly) equal:" \ 302 " were " << setprecision(DBL_DIG) << (a) << " and " << (b) << ")" << setprecision(6)) 305 #define TEST_NOT_EQUAL(a, b) TEST_AND_EXPLAIN(((a) != (b)), \ 306 "Expected '" STRINGIZE(a) "' and '" STRINGIZE(b) "' not to be equal:" \ 307 " were " << (a) << " and " << (b)) 309 #define DEFINE_TESTCASE(S,COND) void test_##S() 332 inline void XFAIL(
const char* msg) {
336 #endif // OM_HGUARD_TESTSUITE_H
Define the XAPIAN_NORETURN macro.
std::ostream operator<< template for Xapian objects
unsigned int xfailed
Number of tests with result XFAIL.
static std::string col_yellow
Class which is thrown when a test case fails.
bool TEST_EQUAL_DOUBLE_(double a, double b)
Helper function for TEST_EQUAL_DOUBLE macro.
unsigned int xpassed
Number of tests with result XFAIL.
const char * expected_failure
Set to a string explanation for testcases expected to fail.
static std::map< int, std::string * > short_opts
const char * expected_exception
The exception type we were expecting in TEST_EXCEPTION.
Macros for testing conditions hold.
unsigned int succeeded
The number of tests which succeeded.
void XFAIL(const char *msg)
Mark a testcase as expected to fail.
unsigned int failed
The number of tests which failed.
static const test_desc tests[]
The lists of tests to perform.
static std::string opt_help
static std::vector< std::string > test_names
static bool abort_on_error
int verbose
The global verbose flag.
std::ostringstream tout
The output stream.
Various handy helpers which std::string really should provide.
A structure used to report the summary of tests passed and failed.
Structure holding a description of a test.
result & operator+=(const result &o)
The test driver. This class takes care of running the tests.
const char * name
The name of the test.
unsigned int skipped
The number of tests which were skipped.
Class which is thrown when a test case is to be skipped.