summaryrefslogtreecommitdiff
path: root/src/components/include/utils/macro.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/include/utils/macro.h')
-rw-r--r--src/components/include/utils/macro.h56
1 files changed, 52 insertions, 4 deletions
diff --git a/src/components/include/utils/macro.h b/src/components/include/utils/macro.h
index bf34b199b..bfd13411f 100644
--- a/src/components/include/utils/macro.h
+++ b/src/components/include/utils/macro.h
@@ -32,8 +32,12 @@
#ifndef SRC_COMPONENTS_INCLUDE_UTILS_MACRO_H_
#define SRC_COMPONENTS_INCLUDE_UTILS_MACRO_H_
+#ifdef DEBUG
#include <assert.h>
+#else // RELEASE
#include <stdio.h>
+#endif
+#include "logger.h"
@@ -54,14 +58,53 @@
#define FRIEND_DELETER_DESTRUCTOR(TypeName) \
friend utils::deleters::Deleter<TypeName>::~Deleter()
+#ifdef DEBUG
+ #define ASSERT(condition) \
+ do { \
+ DEINIT_LOGGER(); \
+ assert(condition); \
+ } while (false)
+#else // RELEASE
+ #define ASSERT(condition) \
+ fprintf(stderr, "Failed condition \"" #condition "\" [%s:%d][%s]\n\n", \
+ __FILE__, __LINE__, __FUNCTION__)
+#endif
+
#define DCHECK(condition) \
if (!(condition)) { \
- printf("\nDCHECK [%s:%d][%s]", __FILE__, __LINE__, __FUNCTION__); \
- printf("[Check failed: " #condition "]\n\n"); \
- assert(false); \
+ CREATE_LOGGERPTR_LOCAL(logger_, "assert"); \
+ LOG4CXX_FATAL(logger_, "DCHECK failed with \"" << #condition \
+ << "\" [" << __FUNCTION__ << "][" << __FILE__ << ':' << __LINE__ << ']'); \
+ ASSERT((condition)); \
+ }
+
+/*
+ * Will cauch assert on debug version,
+ * Will return return_value in release build
+ */
+#define DCHECK_OR_RETURN(condition, return_value) \
+ if (!(condition)) { \
+ CREATE_LOGGERPTR_LOCAL(logger_, "assert"); \
+ LOG4CXX_FATAL(logger_, "DCHECK failed with \"" << #condition \
+ << "\" [" << __FUNCTION__ << "][" << __FILE__ << ':' << __LINE__ << ']' ); \
+ ASSERT((condition)); \
+ return (return_value); \
+ }
+/*
+ * Will cauch assert on debug version,
+ * Will return return_value in release build
+ */
+#define DCHECK_OR_RETURN_VOID(condition) \
+ if (!(condition)) { \
+ CREATE_LOGGERPTR_LOCAL(logger_, "assert"); \
+ LOG4CXX_FATAL(logger_, "DCHECK failed with \"" << #condition \
+ << "\" [" << __FUNCTION__ << "][" << __FILE__ << ':' << __LINE__ << ']' ); \
+ ASSERT((condition)); \
+ return ; \
}
-#define NOTREACHED() DCHECK(false)
+
+#define NOTREACHED() DCHECK(!"Unreachable code")
// Allows to perform static check that virtual function from base class is
// actually being overriden if compiler support is available
@@ -79,4 +122,9 @@
*/
#define ARRAYSIZE(arr) sizeof (arr) / sizeof(*arr)
+#ifdef BUILD_TESTS
+#define FRIEND_TEST(test_case_name, test_name)\
+friend class test_case_name##_##test_name##_Test
+#endif
+
#endif // SRC_COMPONENTS_INCLUDE_UTILS_MACRO_H_