Rev | Line | |
---|
[4] | 1 | #ifndef __TEST_BASE_H__ |
---|
| 2 | #define __TEST_BASE_H__ |
---|
| 3 | #include <exception> |
---|
| 4 | #include <string> |
---|
| 5 | #include <sstream> |
---|
| 6 | |
---|
| 7 | void assertTick(); |
---|
| 8 | |
---|
| 9 | class TestFailed : public std::exception |
---|
| 10 | { |
---|
| 11 | public: |
---|
| 12 | TestFailed(const std::string& message) throw(); |
---|
| 13 | virtual ~TestFailed() throw(); |
---|
| 14 | virtual const char* what() const throw(); |
---|
| 15 | private: |
---|
| 16 | std::string message; |
---|
| 17 | }; |
---|
| 18 | |
---|
| 19 | template<typename T> |
---|
| 20 | void assertEq(T val1, T val2, const std::string& errorMessage) |
---|
| 21 | { |
---|
| 22 | if (val1 != val2) |
---|
| 23 | { |
---|
| 24 | throw TestFailed(errorMessage); |
---|
| 25 | } |
---|
| 26 | assertTick(); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | class StringStream : public std::stringstream |
---|
| 30 | { |
---|
| 31 | public: |
---|
| 32 | StringStream& empty(); |
---|
| 33 | }; |
---|
| 34 | |
---|
| 35 | template<typename TException> |
---|
| 36 | class assertException |
---|
| 37 | { |
---|
| 38 | public: |
---|
| 39 | template<typename TFun> |
---|
| 40 | static void thrown(TFun fun, const std::string& errorMessage) |
---|
| 41 | { |
---|
| 42 | try |
---|
| 43 | { |
---|
| 44 | fun(); |
---|
| 45 | throw TestFailed(errorMessage); |
---|
| 46 | } |
---|
| 47 | catch (TException& ex) { |
---|
| 48 | assertTick(); |
---|
| 49 | } |
---|
| 50 | } |
---|
| 51 | }; |
---|
| 52 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.