![]() |
User Manual, Developers Guide and API Documentation |
![]() |
#include <WNS/Exception.hpp>#include <WNS/TypeInfo.hpp>#include <cassert>#include <sstream>#include <iostream>#include <string>#include <csignal>

Go to the source code of this file.
Namespaces | |
| namespace | wns |
Classes | |
| class | wns::Assure |
| Pseudo class grouping the assure functionality. More... | |
| class | wns::Assure::Exception |
| Thrown by assure. More... | |
| class | wns::NullException |
| Thrown by assureNotNull. More... | |
Defines | |
| #define | assure(expr, reason) |
| An extended assert. | |
| #define | assureNotNull(pointer) |
| Assure pointer is not NULL. | |
| #define | assureType(pointer, T) |
| Assure "pointer" is of type T. | |
| #define | assureWithExceptionType(expr, reason, type) |
| This assure allows to specifiy the exception type to be thrown. | |
| #define | WNS_ASSURE_THROWS_EXCEPTION 1 |
| #define assure | ( | expr, | |||
| reason | ) |
Value:
if (!(expr)) \ { \ std::stringstream s; \ s.precision(10); \ s<<reason; \ wns::Assure::expression<wns::Assure::Exception>(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__, (s.str())); \ } \ else \ void()
1.) Additionally to the expression to be checked a reason in case the expression evaluates to "false" can be provided. Example:
assure(container.find(x) != container.end(), "x is not contained in container");
2.) The assure is configurable at three levels:
Use WNS_ASSERT_ASSURE_EXCEPTION and WNS_ASSERT_ASSURE_NOT_NULL_EXCEPTION instead of CPPUNIT_ASSERT_THROW to prevent, that your test fails in opt flavours.
If you have other code, that depends on an exception thrown by an assure, enclose this code with an ifdef:
#ifdef WNS_ASSURE_THROWS_EXCEPTION yourCode; #endif.
Definition at line 121 of file Assure.hpp.
| #define assureNotNull | ( | pointer | ) |
Value:
assureWithExceptionType(NULL != pointer, \ "Pointer " + std::string(#pointer) + " invalid (NULL)", wns::NullException)
assure (NULL != pointer);
Definition at line 175 of file Assure.hpp.
| #define assureType | ( | pointer, | |||
| T | ) |
Value:
assure(dynamic_cast<T>(pointer), \ std::string(#pointer) + " is not of type " + wns::TypeInfo::create<T>().toString() + \ " but of Type: " + wns::TypeInfo::create(*pointer).toString()+"*")
Baz* foo = getBaz(); assureType(foo, Bar*);
Provides the following error message if pointer is NOT of type T:
foo is not of type wns::Bar* but of type wns::Baz*
Definition at line 159 of file Assure.hpp.
| #define assureWithExceptionType | ( | expr, | |||
| reason, | |||||
| type | ) |
Value:
if (!(expr)) \ { \ std::stringstream s; \ s.precision(10); \ s<<reason; wns::Assure::expression<type>(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__, (s.str())); \ } else \ void()
Definition at line 132 of file Assure.hpp.
| #define WNS_ASSURE_THROWS_EXCEPTION 1 |
Definition at line 141 of file Assure.hpp.
1.5.5