diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-05-03 00:22:11 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-05-03 00:22:11 +0300 |
commit | 972a7923355b87f7570bae37306d9ec8121c86da (patch) | |
tree | 332cac6474d3c33c8e032d21b32f293b69921a5d | |
parent | 9ffe81e93fe8561d01a4985e565d2f9664431338 (diff) | |
download | mv-972a7923355b87f7570bae37306d9ec8121c86da.tar.gz mv-972a7923355b87f7570bae37306d9ec8121c86da.tar.bz2 mv-972a7923355b87f7570bae37306d9ec8121c86da.tar.xz mv-972a7923355b87f7570bae37306d9ec8121c86da.zip |
Add functions failFalse and failTrue and tests.
-rw-r--r-- | src/utils/checkutils.cpp | 28 | ||||
-rw-r--r-- | src/utils/checkutils.h | 20 | ||||
-rw-r--r-- | src/utils/checkutils_unittest.cc | 12 |
3 files changed, 60 insertions, 0 deletions
diff --git a/src/utils/checkutils.cpp b/src/utils/checkutils.cpp index 4953314e1..3161c8f46 100644 --- a/src/utils/checkutils.cpp +++ b/src/utils/checkutils.cpp @@ -52,6 +52,34 @@ bool reportTrueReal(const bool val, return val; } +bool failFalseReal(const bool val, + const char *const text, + const char *const file, + const unsigned line, + const char *const func) +{ + if (!val) + { + reportStack(file, line, func, "Detected false value", text); + throw new std::exception; + } + return val; +} + +bool failTrueReal(const bool val, + const char *const text, + const char *const file, + const unsigned line, + const char *const func) +{ + if (val) + { + reportStack(file, line, func, "Detected true value", text); + throw new std::exception; + } + return val; +} + void reportStack(const char *const file, const unsigned int line, const char *const func, diff --git a/src/utils/checkutils.h b/src/utils/checkutils.h index 539614a7a..fea0a0f67 100644 --- a/src/utils/checkutils.h +++ b/src/utils/checkutils.h @@ -29,6 +29,12 @@ #define reportTrue(val) \ reportTrueReal(val, #val, __FILE__, __LINE__, __func__) +#define failFalse(val) \ + failFalseReal(val, #val, __FILE__, __LINE__, __func__) + +#define failTrue(val) \ + failTrueReal(val, #val, __FILE__, __LINE__, __func__) + bool reportFalseReal(const bool val, const char *const text, const char *const file, @@ -41,6 +47,18 @@ bool reportTrueReal(const bool val, const unsigned line, const char *const func); +bool failFalseReal(const bool val, + const char *const text, + const char *const file, + const unsigned line, + const char *const func); + +bool failTrueReal(const bool val, + const char *const text, + const char *const file, + const unsigned line, + const char *const func); + void reportStack(const char *const file, const unsigned int line, const char *const func, @@ -51,6 +69,8 @@ void reportStack(const char *const file, #define reportFalse(val) (val) #define reportTrue(val) (val) +#define failFalse(val) (val) +#define failTrue(val) (val) #endif // ENABLE_ASSERTS #endif // UTILS_CHECKUTILS_H diff --git a/src/utils/checkutils_unittest.cc b/src/utils/checkutils_unittest.cc index 2e98daf47..a9b2db798 100644 --- a/src/utils/checkutils_unittest.cc +++ b/src/utils/checkutils_unittest.cc @@ -43,5 +43,17 @@ TEST_CASE("CheckUtils") REQUIRE(reportTrue(true) == true); } + SECTION("failFalse") + { + REQUIRE_THROWS(failFalse(false) == false); + REQUIRE(failFalse(true) == true); + } + + SECTION("failTrue") + { + REQUIRE(failTrue(false) == false); + REQUIRE_THROWS(failTrue(true) == true); + } + delete2(logger); } |