28 #ifndef PT_UNIT_ASSERTION_H
29 #define PT_UNIT_ASSERTION_H
31 #include <Pt/Unit/Api.h>
32 #include "Pt/SourceInfo.h"
79 const char* what()
const {
return _what.c_str(); }
86 namespace {
bool testCond =
false; }
88 inline bool getFalse()
91 #define PT_UNIT_ASSERT(cond) \
94 throw Pt::Unit::Assertion(#cond, PT_SOURCEINFO); \
95 } while (::Pt::Unit::testCond)
97 #define PT_UNIT_ASSERT_MSG(cond, what) \
101 std::ostringstream _pt_msg; \
103 throw Pt::Unit::Assertion(_pt_msg.str(), PT_SOURCEINFO); \
105 } while (::Pt::Unit::testCond)
108 #define PT_UNIT_ASSERT_EQUALS(value1, value2) \
110 if( ! ((value1) == (value2)) ) \
112 std::ostringstream _pt_msg; \
113 _pt_msg << "not equal: value1 (" #value1 ")=<" << value1 << "> value2 (" #value2 ")=<" << value2 << '>'; \
114 throw Pt::Unit::Assertion(_pt_msg.str(), PT_SOURCEINFO); \
116 } while (::Pt::Unit::testCond)
118 #define PT_UNIT_ASSERT_EQUAL(value1, value2) \
120 if( ! ((value1) == (value2)) ) \
122 std::ostringstream _pt_msg; \
123 _pt_msg << "not equal: (" #value1 ")=<" << value1 << ">, (" #value2 ")=<" << value2 << '>'; \
124 throw Pt::Unit::Assertion(_pt_msg.str(), PT_SOURCEINFO); \
126 } while (::Pt::Unit::testCond)
128 #define PT_UNIT_ASSERT_THROW(cond, EX) \
136 catch(const _pt_ex &) \
138 std::ostringstream _pt_msg; \
139 _pt_msg << "exception of type " #EX " expected in " #cond; \
140 throw Pt::Unit::Assertion(_pt_msg.str(), PT_SOURCEINFO); \
144 } while (::Pt::Unit::testCond)
146 #define PT_UNIT_ASSERT_NOTHROW(cond) \
152 catch(const std::exception& e) \
154 throw Pt::Unit::Assertion( \
155 std::string("unexpected exception of type ") + typeid(e).name() + ": " + e.what(), \
160 throw Pt::Unit::Assertion("unexpected exception." , PT_SOURCEINFO); \
162 } while (::Pt::Unit::testCond)
164 #define PT_UNIT_FAIL(what) \
166 std::ostringstream _pt_msg; \
168 throw Pt::Unit::Assertion(_pt_msg.str(), PT_SOURCEINFO); \
169 } while (::Pt::Unit::testCond)
175 #endif // PTV_UNIT_ASSERTION_H
Test Assertion exception
Definition: Assertion.h:60
Source code info class.
Definition: SourceInfo.h:100