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...
class  cxxtools::unit::Skip

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)   cxxtools::unit::assertEquals(#value1, (value1), #value2, (value2), CXXTOOLS_SOURCEINFO)
#define CXXTOOLS_UNIT_ASSERT_EQUALS2(value1, value2, outputFn)   cxxtools::unit::assertEquals(#value1, (value1), #value2, (value2), outputFn, CXXTOOLS_SOURCEINFO)
#define CXXTOOLS_UNIT_ASSERT_THROW(cond, EX)
#define CXXTOOLS_UNIT_ASSERT_NOTHROW(cond)
#define CXXTOOLS_UNIT_SKIP()   throw cxxtools::unit::Skip()
#define CXXTOOLS_UNIT_FAIL(what)

Functions

template<typename A , typename B >
void cxxtools::unit::assertEquals (const char *cond1, const A &value1, const char *cond2, const B &value2, const SourceInfo &si)
template<typename A , typename B , typename C >
void cxxtools::unit::assertEquals (const char *cond1, const A &value1, const char *cond2, const B &value2, C outputFn, const SourceInfo &si)

Macro Definition Documentation

#define CXXTOOLS_UNIT_ASSERT (   cond)
Value:
do { \
if( !(cond) ) \
} while (false)
#define CXXTOOLS_UNIT_ASSERT_EQUALS (   value1,
  value2 
)    cxxtools::unit::assertEquals(#value1, (value1), #value2, (value2), CXXTOOLS_SOURCEINFO)
#define CXXTOOLS_UNIT_ASSERT_EQUALS2 (   value1,
  value2,
  outputFn 
)    cxxtools::unit::assertEquals(#value1, (value1), #value2, (value2), outputFn, CXXTOOLS_SOURCEINFO)
#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 { \
try \
{ \
cond; \
\
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)
#define CXXTOOLS_UNIT_SKIP ( )    throw cxxtools::unit::Skip()