2017-04-14 02:51:35 +08:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-14 10:38:26 +08:00
|
|
|
#include <cmath>
|
2017-04-14 02:51:35 +08:00
|
|
|
#include <exception>
|
2018-07-05 16:46:32 +08:00
|
|
|
#include <xlnt/utils/exceptions.hpp>
|
2017-04-14 02:51:35 +08:00
|
|
|
|
2018-06-18 14:43:36 +08:00
|
|
|
#define XLNT_STRINGIFYX(x) #x
|
|
|
|
#define XLNT_STRINGIFY(x) XLNT_STRINGIFYX(x)
|
|
|
|
|
|
|
|
#define xlnt_assert(expression) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
try \
|
|
|
|
{ \
|
|
|
|
if (expression) break; \
|
|
|
|
} \
|
|
|
|
catch (std::exception & ex) \
|
|
|
|
{ \
|
|
|
|
throw ex; \
|
|
|
|
} \
|
|
|
|
catch (...) \
|
|
|
|
{ \
|
|
|
|
} \
|
2018-06-18 15:27:27 +08:00
|
|
|
throw xlnt::exception( \
|
|
|
|
"assert failed at L:" XLNT_STRINGIFY(__LINE__) "\n" XLNT_STRINGIFY(expression)); \
|
2017-04-14 02:51:35 +08:00
|
|
|
} while (false)
|
|
|
|
|
2018-06-18 14:43:36 +08:00
|
|
|
#define xlnt_assert_throws_nothing(expression) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
try \
|
|
|
|
{ \
|
|
|
|
expression; \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
catch (...) \
|
|
|
|
{ \
|
|
|
|
} \
|
2018-06-18 15:27:27 +08:00
|
|
|
throw xlnt::exception("assert throws nothing failed at L:" XLNT_STRINGIFY(__LINE__) "\n" XLNT_STRINGIFY(expression)); \
|
2017-04-14 02:51:35 +08:00
|
|
|
} while (false)
|
|
|
|
|
2018-06-18 14:43:36 +08:00
|
|
|
#define xlnt_assert_throws(expression, exception_type) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
try \
|
|
|
|
{ \
|
|
|
|
expression; \
|
|
|
|
} \
|
|
|
|
catch (exception_type) \
|
|
|
|
{ \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
catch (...) \
|
|
|
|
{ \
|
|
|
|
} \
|
2018-06-18 15:27:27 +08:00
|
|
|
throw xlnt::exception("assert throws failed at L:" XLNT_STRINGIFY(__LINE__) "\n" XLNT_STRINGIFY(expression)); \
|
2017-04-14 02:51:35 +08:00
|
|
|
} while (false)
|
|
|
|
|
2018-06-18 15:12:02 +08:00
|
|
|
#define xlnt_assert_equals(left, right) xlnt_assert((left) == (right))
|
|
|
|
#define xlnt_assert_differs(left, right) xlnt_assert((left) != (right))
|
|
|
|
#define xlnt_assert_delta(left, right, delta) xlnt_assert(std::abs((left) - (right)) <= (delta))
|