]> git.stg.codes - stg.git/blob - tests/tut/tut_macros.hpp
Moved SERVER_INFO parser from global scope.
[stg.git] / tests / tut / tut_macros.hpp
1 #ifndef TUT_MACROS_HPP
2 #define TUT_MACROS_HPP
3
4 #include <tut/tut.hpp>
5
6 #ifdef ensure_THROW
7 #error ensure_THROW macro is already defined
8 #endif
9
10 /** Helper macros to ensure that a call throws exception.
11  * \code
12  *  #include <tut_macros.h>
13  *  ensure_THROW( this_function_should_throw_bad_alloc(), std::bad_alloc );
14  * \endcode
15  */
16 #define ensure_THROW( x, e ) \
17 try         \
18 {           \
19     x;      \
20     fail(#x " has not thrown expected exception " #e); \
21 }                \
22 catch(const e &) \
23 {                \
24 }                \
25 catch(const std::exception &ex)  \
26 {           \
27     fail( std::string(#x " has thrown unexpected exception ")+tut::type_name(ex)+": "+ex.what()); \
28 } \
29 catch(...)       \
30 {                \
31     fail(#x " has thrown unexpected unknown exception"); \
32 }
33
34 #ifdef ensure_NO_THROW
35 #error ensure_NO_THROW macro is already defined
36 #endif
37
38 /** Helper macro to ensure a call does not throw any exceptions.
39  * \code
40  *  #include <tut_macros.h>
41  *  ensure_NO_THROW( this_function_should_never_throw() );
42  * \endcode
43  */
44 #define ensure_NO_THROW( x ) \
45 try         \
46 {           \
47     x;      \
48 }           \
49 catch(const std::exception &ex)  \
50 {           \
51     fail( std::string(#x " has thrown unexpected exception ")+tut::type_name(ex)+": "+ex.what()); \
52 } \
53 catch(...)  \
54 {           \
55     fail(#x " has thrown unexpected unknown exception"); \
56 }
57
58 #ifdef __COUNTER__
59 #define TUT_TESTCASE(object) template<> template<> void object::test<__COUNTER__>()
60 #endif
61
62 #endif
63