|
Elm
2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
|
21 #ifndef ELM_UTIL_TEST_H
22 #define ELM_UTIL_TEST_H
24 #include <elm/string.h>
26 #include <elm/util/Initializer.h>
27 #include <elm/data/List.h>
48 CString text,
const T& result,
const U& reference) {
49 bool test = result == reference;
52 cout <<
'\t' << result <<
" != " << reference <<
"\n";
59 inline bool hasFailed(
void)
const {
return errors != 0; }
88 #define ELM_CHECK_BEGIN(name) { elm::TestCase __case(name); __case.prepare();
89 #define ELM_CHECK(tst) __case.check(__FILE__, __LINE__, #tst, tst)
90 #define ELM_CHECK_MSG(msg, res) __case.check(__FILE__, __LINE__, msg, res)
91 #define ELM_CHECK_END __case.complete(); }
92 #define ELM_CHECK_RETURN __case.complete(); if(__case.isSuccessful()) return 0; else return 1; }
93 #define ELM_REQUIRE(tst, action) if(!__case.require(__FILE__, __LINE__, #tst, tst)) action
94 #define ELM_CHECK_EQUAL(res, ref) __case.check_equal(__FILE__, __LINE__, #res " == " #ref, res, ref)
95 #define ELM_CHECK_EXCEPTION(exn, stat) { __case.test(__FILE__, __LINE__, #stat); \
96 try { stat; __case.failed(); } catch(const exn&) { __case.succeeded(); } }
97 #define ELM_FAIL_ON_EXCEPTION(exn, stat) { __case.test(__FILE__, __LINE__, #stat); \
98 try { stat; __case.succeeded(); } \
99 catch(exn& e) { __case.failed(); cerr << "exception = " << e.message() << elm::io::endl; } }
100 #define ELM_TEST_BEGIN(name) \
101 static class name##Test: public elm::TestCase { \
103 name##Test(void): elm::TestCase(#name) { } \
105 virtual void execute(void) {
106 #define ELM_TEST_END \
111 #ifndef ELM_NO_SHORTCUT
112 # define CHECK_BEGIN(name) ELM_CHECK_BEGIN(name)
113 # define CHECK(tst) ELM_CHECK(tst)
114 # define CHECK_MSG(msg, res) ELM_CHECK_MSG(msg, res)
115 # define REQUIRE(tst, action) ELM_REQUIRE(tst, action)
116 # define CHECK_EQUAL(res, ref) ELM_CHECK_EQUAL(res, ref)
117 # define CHECK_END ELM_CHECK_END
118 # define CHECK_EXCEPTION(exn, stat) ELM_CHECK_EXCEPTION(exn, stat)
119 # define FAIL_ON_EXCEPTION(exn, stat) ELM_FAIL_ON_EXCEPTION(exn, stat)
120 # define TEST_BEGIN(name) ELM_TEST_BEGIN(name)
121 # define TEST_END ELM_TEST_END
122 # define CHECK_RETURN ELM_CHECK_RETURN
127 #endif // ELM_UTIL_TEST_H
cstring name(void)
Definition: test.h:40
void setFullPath(bool x)
Definition: test.h:61
static TestSet def
Definition: test.h:70
void complete(void)
Definition: util_test.cpp:239
bool full_path
Definition: test.h:65
void perform(void)
Definition: util_test.cpp:287
TestCase(CString name)
Definition: util_test.cpp:147
void failed(void)
Definition: util_test.cpp:189
Iterator(const TestSet &set)
Definition: test.h:76
void test(CString file, int line, CString text)
Definition: util_test.cpp:176
virtual void execute(void)
Definition: util_test.cpp:280
Iter(void)
Definition: List.h:67
bool require(CString file, int line, CString text, bool result)
Definition: util_test.cpp:265
void succeeded(void)
Definition: util_test.cpp:202
void prepare(void)
Definition: util_test.cpp:161
bool isFullPath() const
Definition: test.h:60
bool isSuccessful(void) const
Definition: test.h:58
Definition: Initializer.h:14
void check(CString file, int line, CString text, bool result)
Definition: util_test.cpp:218
void perform(void)
Definition: util_test.cpp:328
bool hasFailed(void) const
Definition: test.h:59
TestCase & __case
Definition: test.h:64
void check_equal(CString file, int line, CString text, const T &result, const U &reference)
Definition: test.h:47
void initialize(void)
Definition: util_test.cpp:231
virtual ~TestCase(void)
Definition: util_test.cpp:298