diff options
-rw-r--r-- | server/src/exception.cc | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/server/src/exception.cc b/server/src/exception.cc index 09c6918..a2bbf95 100644 --- a/server/src/exception.cc +++ b/server/src/exception.cc @@ -42,8 +42,16 @@ const char* Exception::what() const throw() return _what.c_str(); } - #ifdef TEST_EXCEPTION +//deps: log.cc +//cflags: -I.. +//libs: + +#undef TEST_EXCEPTION // 'fix' redefined test macro. +#include <test.h> + +#define PRE "MyExtException has been thrown: " +#define MSG "Hello World!" class MyException : public Exception { public: @@ -54,30 +62,27 @@ public: class MyExtException : public Exception { public: MyExtException(std::string thingy) : - Exception("MyExtException has been thrown: " + thingy) {} + Exception(PRE + thingy) {} }; -int main() +void throwit() { - try { - throw MyException(); - } catch( MyException &e ) { - printf("%s\n", e.what()); - goto on; - } - return 1; - on: - - try { - throw MyExtException("Yeaaah!"); - } catch( MyExtException &e ) { - printf("%s\n", e.what()); - goto onandon; - } - return 1; - onandon: - - return 0; + throw MyException(); } +TEST_BEGIN; + +TEST_EXCEPTION(throwit(), MyException, "Throw it."); + +std::string w; +try { + throw MyExtException(MSG); +} catch( MyExtException &e ) { + w = e.what(); +} + +TEST_EQUAL_STR(w, PRE MSG, "We got a 'what'."); + +TEST_END; + #endif/*TEST_EXCEPTION*/ |