diff options
author | Andrei Karas <akaras@inbox.ru> | 2016-05-04 15:38:52 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2016-05-04 15:38:52 +0300 |
commit | d0da3a7489670a202901ac32ca6e4bffb16d485b (patch) | |
tree | 77a04d9e7f318a171eb51289f82e16975c17e93d | |
parent | 972a7923355b87f7570bae37306d9ec8121c86da (diff) | |
download | manaverse-d0da3a7489670a202901ac32ca6e4bffb16d485b.tar.gz manaverse-d0da3a7489670a202901ac32ca6e4bffb16d485b.tar.bz2 manaverse-d0da3a7489670a202901ac32ca6e4bffb16d485b.tar.xz manaverse-d0da3a7489670a202901ac32ca6e4bffb16d485b.zip |
Add macroses returnFalseV, returnTrueV, returnFalse, returnTrue.
-rw-r--r-- | src/utils/checkutils.h | 36 | ||||
-rw-r--r-- | src/utils/checkutils_unittest.cc | 59 |
2 files changed, 95 insertions, 0 deletions
diff --git a/src/utils/checkutils.h b/src/utils/checkutils.h index fea0a0f67..713ac305f 100644 --- a/src/utils/checkutils.h +++ b/src/utils/checkutils.h @@ -35,6 +35,38 @@ #define failTrue(val) \ failTrueReal(val, #val, __FILE__, __LINE__, __func__) +#define returnFalseV(val) \ + if (!val) \ + { \ + reportStack(__FILE__, __LINE__, __func__, \ + "Detected false value", #val); \ + return; \ + } + +#define returnTrueV(val) \ + if (val) \ + { \ + reportStack(__FILE__, __LINE__, __func__, \ + "Detected true value", #val); \ + return; \ + } + +#define returnFalse(ret, val) \ + if (!val) \ + { \ + reportStack(__FILE__, __LINE__, __func__, \ + "Detected false value", #val); \ + return ret; \ + } + +#define returnTrue(ret, val) \ + if (val) \ + { \ + reportStack(__FILE__, __LINE__, __func__, \ + "Detected true value", #val); \ + return ret; \ + } + bool reportFalseReal(const bool val, const char *const text, const char *const file, @@ -71,6 +103,10 @@ void reportStack(const char *const file, #define reportTrue(val) (val) #define failFalse(val) (val) #define failTrue(val) (val) +#define returnTrueV(val) +#define returnFalseV(val) +#define returnTrue(val) +#define returnFalse(val) #endif // ENABLE_ASSERTS #endif // UTILS_CHECKUTILS_H diff --git a/src/utils/checkutils_unittest.cc b/src/utils/checkutils_unittest.cc index a9b2db798..4cce96725 100644 --- a/src/utils/checkutils_unittest.cc +++ b/src/utils/checkutils_unittest.cc @@ -27,6 +27,37 @@ #include "debug.h" +namespace +{ + bool flag = false; +} // namespace + +static void testReturnFalseV(const bool val) +{ + flag = false; + returnFalseV(val); + flag = true; +} + +static void testReturnTrueV(const bool val) +{ + flag = false; + returnTrueV(val); + flag = true; +} + +static int testReturnFalse(const bool val) +{ + returnFalse(0, val); + return 1; +} + +static int testReturnTrue(const bool val) +{ + returnTrue(0, val); + return 1; +} + TEST_CASE("CheckUtils") { logger = new Logger; @@ -55,5 +86,33 @@ TEST_CASE("CheckUtils") REQUIRE_THROWS(failTrue(true) == true); } + SECTION("returnFalseV") + { + testReturnFalseV(false); + REQUIRE(flag == false); + testReturnFalseV(true); + REQUIRE(flag == true); + } + + SECTION("returnTrueV") + { + testReturnTrueV(false); + REQUIRE(flag == true); + testReturnTrueV(true); + REQUIRE(flag == false); + } + + SECTION("returnFalse") + { + REQUIRE(testReturnFalse(false) == 0); + REQUIRE(testReturnFalse(true) == 1); + } + + SECTION("returnTrue") + { + REQUIRE(testReturnTrue(false) == 1); + REQUIRE(testReturnTrue(true) == 0); + } + delete2(logger); } |