Add some helper macros for testing precondition
We usually do TEST_AND_RETURN_FALSE(x == y), but that macro doesn't
print the exact values of x and y on failure. Add a set of macros which
do that.
Test: th
Change-Id: Ia84093d6adc34e99a634c5d62ba4f21a6bd51046
diff --git a/common/utils.h b/common/utils.h
index c1820ee..003455d 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -534,4 +534,22 @@
} \
} while (0)
+#define TEST_OP(_x, _y, op) \
+ do { \
+ const auto& x = _x; \
+ const auto& y = _y; \
+ if (!(x op y)) { \
+ LOG(ERROR) << #_x " " #op " " #_y << " failed: " << x << " " #op " " \
+ << y; \
+ return {}; \
+ } \
+ } while (0)
+
+#define TEST_EQ(_x, _y) TEST_OP(_x, _y, ==)
+#define TEST_NE(_x, _y) TEST_OP(_x, _y, !=)
+#define TEST_LE(_x, _y) TEST_OP(_x, _y, <=)
+#define TEST_GE(_x, _y) TEST_OP(_x, _y, >=)
+#define TEST_LT(_x, _y) TEST_OP(_x, _y, <)
+#define TEST_GT(_x, _y) TEST_OP(_x, _y, >)
+
#endif // UPDATE_ENGINE_COMMON_UTILS_H_