mirror of
https://github.com/zeux/pugixml.git
synced 2025-01-14 09:57:57 +08:00
60 lines
1.1 KiB
C++
60 lines
1.1 KiB
C++
|
#ifndef HEADER_TEST_HPP
|
||
|
#define HEADER_TEST_HPP
|
||
|
|
||
|
struct test_runner
|
||
|
{
|
||
|
test_runner(const char* name)
|
||
|
{
|
||
|
_name = name;
|
||
|
_next = _tests;
|
||
|
_tests = this;
|
||
|
}
|
||
|
|
||
|
virtual ~test_runner() {}
|
||
|
|
||
|
virtual void run() = 0;
|
||
|
|
||
|
const char* _name;
|
||
|
test_runner* _next;
|
||
|
|
||
|
static test_runner* _tests;
|
||
|
};
|
||
|
|
||
|
struct dummy_fixture {};
|
||
|
|
||
|
#define TEST_FIXTURE(name, fixture) \
|
||
|
struct test_runner_helper_##name: fixture \
|
||
|
{ \
|
||
|
void run(); \
|
||
|
}; \
|
||
|
static struct test_runner_##name: test_runner \
|
||
|
{ \
|
||
|
test_runner_##name(): test_runner(#name) {} \
|
||
|
\
|
||
|
virtual void run() \
|
||
|
{ \
|
||
|
test_runner_helper_##name helper; \
|
||
|
helper.run(); \
|
||
|
} \
|
||
|
} test_runner_instance_##name; \
|
||
|
void test_runner_helper_##name::run()
|
||
|
|
||
|
#define TEST(name) TEST_FIXTURE(name, dummy_fixture)
|
||
|
|
||
|
#define TEST_XML(name, xml) \
|
||
|
struct test_fixture_##name \
|
||
|
{ \
|
||
|
pugi::xml_document doc; \
|
||
|
\
|
||
|
test_fixture_##name() \
|
||
|
{ \
|
||
|
CHECK(doc.load(xml)); \
|
||
|
} \
|
||
|
}; \
|
||
|
\
|
||
|
TEST_FIXTURE(name, test_fixture_##name)
|
||
|
|
||
|
#define CHECK(condition) if (condition) ; else throw #condition " is false"
|
||
|
|
||
|
#endif
|