summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/checkutils.h36
-rw-r--r--src/utils/checkutils_unittest.cc59
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);
}