assertion.h File Reference
#include "cxxtools/sourceinfo.h"
#include <stdexcept>
#include <iostream>
#include <sstream>

Go to the source code of this file.

Classes

class  cxxtools::unit::Assertion
 Test Assertion exceptionAssertions are modeled as an exception type, which is thrown by Unit tests when an assertion has failed. More...

Namespaces

namespace  cxxtools
namespace  cxxtools::unit

Macros

#define CXXTOOLS_UNIT_ASSERT(cond)
#define CXXTOOLS_UNIT_ASSERT_MSG(cond, what)
#define CXXTOOLS_UNIT_ASSERT_EQUALS(value1, value2)
#define CXXTOOLS_UNIT_ASSERT_THROW(cond, EX)
#define CXXTOOLS_UNIT_ASSERT_NOTHROW(cond)
#define CXXTOOLS_UNIT_FAIL(what)

Macro Definition Documentation

#define CXXTOOLS_UNIT_ASSERT (   cond)
Value:
do { \
if( !(cond) ) \
} while (false)
#define CXXTOOLS_UNIT_ASSERT_EQUALS (   value1,
  value2 
)
Value:
do { \
if( ! ((value1) == (value2)) ) \
{ \
std::ostringstream _cxxtools_msg; \
_cxxtools_msg << "not equal:\n\tvalue1 (" #value1 ")=\n\t\t<" << value1 << ">\n\tvalue2 (" #value2 ")=\n\t\t<" << value2 << '>'; \
throw cxxtools::unit::Assertion(_cxxtools_msg.str(), CXXTOOLS_SOURCEINFO); \
} \
} while (false)
#define CXXTOOLS_UNIT_ASSERT_MSG (   cond,
  what 
)
Value:
do { \
if( !(cond) ) \
{ \
std::ostringstream _cxxtools_msg; \
_cxxtools_msg << what; \
throw cxxtools::unit::Assertion(_cxxtools_msg.str(), CXXTOOLS_SOURCEINFO); \
} \
} while (false)
#define CXXTOOLS_UNIT_ASSERT_NOTHROW (   cond)
Value:
do { \
try { \
\
cond; \
} \
catch(const std::exception& e) \
{ \
std::string("unexpected exception of type ") + typeid(e).name() + ": " + e.what(), \
CXXTOOLS_SOURCEINFO); \
} \
catch(const cxxtools::unit::Assertion&) \
{ \
throw; \
} \
catch(...) \
{ \
throw cxxtools::unit::Assertion("unexpected exception." , CXXTOOLS_SOURCEINFO); \
} \
} while (false)
#define CXXTOOLS_UNIT_ASSERT_THROW (   cond,
  EX 
)
Value:
do { \
struct _cxxtools_ex { }; \
try \
{ \
cond; \
throw _cxxtools_ex(); \
} \
catch(const _cxxtools_ex &) \
{ \
std::ostringstream _cxxtools_msg; \
_cxxtools_msg << "exception of type " #EX " expected in " #cond; \
throw cxxtools::unit::Assertion(_cxxtools_msg.str(), CXXTOOLS_SOURCEINFO); \
} \
catch(const EX &) \
{} \
} while (false)
#define CXXTOOLS_UNIT_FAIL (   what)
Value:
do { \
std::ostringstream _cxxtools_msg; \
_cxxtools_msg << what; \
throw cxxtools::unit::Assertion(_cxxtools_msg.str(), CXXTOOLS_SOURCEINFO); \
} while (false)