From 95cfffa53760942c3ccf6abc18b81f48d03a3ff6 Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 14 Feb 2011 12:21:48 +0000 Subject: Reenable unit test. --- server/src/exception.cc | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) (limited to 'server/src') 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 + +#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*/ -- cgit v1.2.3