summaryrefslogtreecommitdiff
path: root/tests/test.hpp
diff options
context:
space:
mode:
authorarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2009-10-10 21:36:03 +0000
committerarseny.kapoulkine <arseny.kapoulkine@99668b35-9821-0410-8761-19e4c4f06640>2009-10-10 21:36:03 +0000
commit6db04f4320cd5d24ae625dbc1df5a8a71b93e51d (patch)
treee6e5c79464b4d4c05c75fd6dbb8f4d3e800edbcc /tests/test.hpp
parentab28c3b45e611b5d49a03024bd6ae7b184d37d4a (diff)
tests: Added simple test framework, added a couple of tests
git-svn-id: http://pugixml.googlecode.com/svn/trunk@140 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests/test.hpp')
-rw-r--r--tests/test.hpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/test.hpp b/tests/test.hpp
new file mode 100644
index 0000000..09d7024
--- /dev/null
+++ b/tests/test.hpp
@@ -0,0 +1,59 @@
+#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