diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-05-11 17:21:45 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-05-11 17:21:45 +0300 |
commit | 7f5f2394d3f3dccf2e6a07a466f3840dafed8e04 (patch) | |
tree | 5a239f75c18d6a8f959409f4714d6b9ec861e253 /src/utils | |
parent | 5b5f27a70fd8b3c421f350c39d7fe05f692df2ed (diff) | |
download | mv-7f5f2394d3f3dccf2e6a07a466f3840dafed8e04.tar.gz mv-7f5f2394d3f3dccf2e6a07a466f3840dafed8e04.tar.bz2 mv-7f5f2394d3f3dccf2e6a07a466f3840dafed8e04.tar.xz mv-7f5f2394d3f3dccf2e6a07a466f3840dafed8e04.zip |
In checkutils with unit tests enabled, any failed assert will throw exception.
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/checkutils.h | 87 | ||||
-rw-r--r-- | src/utils/checkutils_unittest.cc | 20 |
2 files changed, 95 insertions, 12 deletions
diff --git a/src/utils/checkutils.h b/src/utils/checkutils.h index 9966203dc..23b1fc965 100644 --- a/src/utils/checkutils.h +++ b/src/utils/checkutils.h @@ -89,6 +89,54 @@ "Detected false value", #val), \ throw new std::exception(), true) : false) +#define returnFailFalseV(val) \ + if (!val) \ + { \ + reportStack(__FILE__, __LINE__, __func__, \ + "Detected false value", #val); \ + throw new std::exception(); \ + } + +#define returnFailTrueV(val) \ + if (val) \ + { \ + reportStack(__FILE__, __LINE__, __func__, \ + "Detected true value", #val); \ + throw new std::exception(); \ + } + +#define returnFailFalse(ret, val) \ + if (!val) \ + { \ + reportStack(__FILE__, __LINE__, __func__, \ + "Detected false value", #val); \ + throw new std::exception(); \ + } + +#define returnFailTrue(ret, val) \ + if (val) \ + { \ + reportStack(__FILE__, __LINE__, __func__, \ + "Detected true value", #val); \ + throw new std::exception(); \ + } + +#define returnFailNullptrV(val) \ + if ((val) == nullptr) \ + { \ + reportStack(__FILE__, __LINE__, __func__, \ + "Detected null value", #val); \ + throw new std::exception(); \ + } + +#define returnFailNullptr(ret, val) \ + if ((val) == nullptr) \ + { \ + reportStack(__FILE__, __LINE__, __func__, \ + "Detected null value", #val); \ + throw new std::exception(); \ + } + void reportStack(const char *const file, const unsigned int line, const char *const func, @@ -118,17 +166,51 @@ void reportStack(const char *const file, #define returnNullptrVReal(val) \ if ((val) == nullptr) \ - return; \ + return; #define returnNullptrReal(ret, val) \ if ((val) == nullptr) \ - return ret; \ + return ret; #define failFalse(val) (val) #define failTrue(val) (val) +#define returnFailFalseV(val) \ + if (!val) \ + return; + +#define returnFailTrueV(val) \ + if (val) \ + return; + +#define returnFailFalse(ret, val) \ + if (!val) \ + return ret; + +#define returnFailTrue(ret, val) \ + if (val) \ + return ret; + +#define returnFailNullptrV(val) \ + if ((val) == nullptr) \ + return; + +#define returnFailNullptr(ret, val) \ + if ((val) == nullptr) \ + return ret; + #endif // ENABLE_ASSERTS +#ifdef UNITTESTS +#define reportFalse(val) failFalse(val) +#define reportTrue(val) failTrue(val) +#define returnFalseV(val) returnFailFalseV(val) +#define returnTrueV(val) returnFailTrueV(val) +#define returnFalse(ret, val) returnFailFalse(ret, val) +#define returnTrue(ret, val) returnFailTrue(ret, val) +#define returnNullptrV(val) returnFailNullptrV(val) +#define returnNullptr(ret, val) returnFailNullptr(ret, val) +#else // UNITTESTS #define reportFalse(val) reportFalseReal(val) #define reportTrue(val) reportTrueReal(val) #define returnFalseV(val) returnFalseVReal(val) @@ -137,5 +219,6 @@ void reportStack(const char *const file, #define returnTrue(ret, val) returnTrueReal(ret, val) #define returnNullptrV(val) returnNullptrVReal(val) #define returnNullptr(ret, val) returnNullptrReal(ret, val) +#endif // UNITTESTS #endif // UTILS_CHECKUTILS_H diff --git a/src/utils/checkutils_unittest.cc b/src/utils/checkutils_unittest.cc index 0d09143c3..cbf26fa7b 100644 --- a/src/utils/checkutils_unittest.cc +++ b/src/utils/checkutils_unittest.cc @@ -35,39 +35,39 @@ namespace static void testReturnFalseV(const bool val) { flag = false; - returnFalseV(val); + returnFalseVReal(val); flag = true; } static void testReturnTrueV(const bool val) { flag = false; - returnTrueV(val); + returnTrueVReal(val); flag = true; } static int testReturnFalse(const bool val) { - returnFalse(0, val); + returnFalseReal(0, val); return 1; } static int testReturnTrue(const bool val) { - returnTrue(0, val); + returnTrueReal(0, val); return 1; } static int testReturnNullptr(void *val) { - returnNullptr(0, val); + returnNullptrReal(0, val); return 1; } static void testReturnNullptrV(void *val) { flag = false; - returnNullptrV(val); + returnNullptrVReal(val); flag = true; } @@ -77,14 +77,14 @@ TEST_CASE("CheckUtils") SECTION("reportFalse") { - REQUIRE(reportFalse(false) == false); - REQUIRE(reportFalse(true) == true); + REQUIRE(reportFalseReal(false) == false); + REQUIRE(reportFalseReal(true) == true); } SECTION("reportTrue") { - REQUIRE(reportTrue(false) == false); - REQUIRE(reportTrue(true) == true); + REQUIRE(reportTrueReal(false) == false); + REQUIRE(reportTrueReal(true) == true); } SECTION("failFalse") |