diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-05-11 18:20:55 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-05-11 18:20:55 +0300 |
commit | db084a1b2fc7f73b38375c4e2ab5398c19a5d712 (patch) | |
tree | 3775d75326f0e9a2b62c7743f5054124ce6c4a14 | |
parent | ece98b5c7baefc8fe0326bdfea8de4fe14ed0bf2 (diff) | |
download | mv-db084a1b2fc7f73b38375c4e2ab5398c19a5d712.tar.gz mv-db084a1b2fc7f73b38375c4e2ab5398c19a5d712.tar.bz2 mv-db084a1b2fc7f73b38375c4e2ab5398c19a5d712.tar.xz mv-db084a1b2fc7f73b38375c4e2ab5398c19a5d712.zip |
Add new assert macro: reportAlways and failAlways
-rw-r--r-- | src/utils/checkutils.h | 17 | ||||
-rw-r--r-- | src/utils/checkutils_unittest.cc | 27 |
2 files changed, 44 insertions, 0 deletions
diff --git a/src/utils/checkutils.h b/src/utils/checkutils.h index 23b1fc965..0210747c3 100644 --- a/src/utils/checkutils.h +++ b/src/utils/checkutils.h @@ -31,6 +31,10 @@ (val ? (reportStack(__FILE__, __LINE__, __func__, \ "Detected false value", #val), true) : false) +#define reportAlwaysReal(val) \ + reportStack(__FILE__, __LINE__, __func__, \ + "Detected false value", val); + #define returnFalseVReal(val) \ if (!val) \ { \ @@ -137,6 +141,13 @@ throw new std::exception(); \ } +#define failAlways(val) \ + { \ + reportStack(__FILE__, __LINE__, __func__, \ + "Detected false value", val); \ + throw new std::exception(); \ + } + void reportStack(const char *const file, const unsigned int line, const char *const func, @@ -148,6 +159,8 @@ void reportStack(const char *const file, #define reportFalseReal(val) (val) #define reportTrueReal(val) (val) +#define reportAlwaysReal(val) ; + #define returnFalseVReal(val) \ if (!val) \ return; @@ -199,11 +212,14 @@ void reportStack(const char *const file, if ((val) == nullptr) \ return ret; +#define failAlways(val) ; + #endif // ENABLE_ASSERTS #ifdef UNITTESTS #define reportFalse(val) failFalse(val) #define reportTrue(val) failTrue(val) +#define reportAlways(val) failAlways(val) #define returnFalseV(val) returnFailFalseV(val) #define returnTrueV(val) returnFailTrueV(val) #define returnFalse(ret, val) returnFailFalse(ret, val) @@ -213,6 +229,7 @@ void reportStack(const char *const file, #else // UNITTESTS #define reportFalse(val) reportFalseReal(val) #define reportTrue(val) reportTrueReal(val) +#define reportAlways(val) reportAlwaysReal(val) #define returnFalseV(val) returnFalseVReal(val) #define returnTrueV(val) returnTrueVReal(val) #define returnFalse(ret, val) returnFalseReal(ret, val) diff --git a/src/utils/checkutils_unittest.cc b/src/utils/checkutils_unittest.cc index cbf26fa7b..39bb2a737 100644 --- a/src/utils/checkutils_unittest.cc +++ b/src/utils/checkutils_unittest.cc @@ -71,6 +71,18 @@ static void testReturnNullptrV(void *val) flag = true; } +static bool testFailAlways1() +{ + failAlways("test fail"); + return false; +} + +static bool testFailAlways2() +{ + reportAlways("test fail"); + return false; +} + TEST_CASE("CheckUtils") { logger = new Logger; @@ -87,16 +99,31 @@ TEST_CASE("CheckUtils") REQUIRE(reportTrueReal(true) == true); } + SECTION("reportAlways") + { + reportAlwaysReal("test report"); + } + SECTION("failFalse") { REQUIRE_THROWS(failFalse(false) == false); REQUIRE(failFalse(true) == true); + REQUIRE_THROWS(reportFalse(false) == false); + REQUIRE(reportFalse(true) == true); } SECTION("failTrue") { REQUIRE(failTrue(false) == false); REQUIRE_THROWS(failTrue(true) == true); + REQUIRE(reportTrue(false) == false); + REQUIRE_THROWS(reportTrue(true) == true); + } + + SECTION("failAlways") + { + REQUIRE_THROWS(testFailAlways1() == true); + REQUIRE_THROWS(testFailAlways2() == true); } SECTION("returnFalseV") |