[common] Added assert.h
authorGrzegorz Rynkowski <g.rynkowski@samsung.com>
Wed, 25 Feb 2015 17:55:03 +0000 (18:55 +0100)
committerPawel Sikorski <p.sikorski@samsung.com>
Fri, 27 Feb 2015 14:27:36 +0000 (23:27 +0900)
Problem: Using plain assert does not print any information about the
         source of assertion.

Change-Id: I66192909d6fe5836b098b0e2225a79ec1de86f8d
Signed-off-by: Grzegorz Rynkowski <g.rynkowski@samsung.com>
src/common/assert.h [new file with mode: 0644]
src/common/common.gypi

diff --git a/src/common/assert.h b/src/common/assert.h
new file mode 100644 (file)
index 0000000..f56ba79
--- /dev/null
@@ -0,0 +1,23 @@
+// Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMMON_ASSERT_H_
+#define COMMON_ASSERT_H_
+
+#include <cassert>
+
+#include "common/logger.h"
+
+#define AssertMsg(condition, message)                                          \
+  do {                                                                         \
+    std::string msg(message);                                                  \
+    if (!(condition))                                                          \
+      LoggerE("assert(%s)%s", #condition,                                      \
+            !msg.empty() ? std::string(", message: " + msg).c_str() : "");     \
+    assert(!!(condition) && message);                                          \
+  } while(0)
+
+#define Assert(condition) AssertMsg(condition, "")
+
+#endif  // COMMON_ASSERT_H_
\ No newline at end of file
index 260a0fbfcb22f6dfda72dc9bd4dec073bf5b2974..d7698dffe6dd1242774aa1dc009187d33b598ca0 100644 (file)
       #'multi_callback_user_data.cc',
       #'multi_callback_user_data.h',
       'platform_result.cc',
-      'platform_result.h'
+      'platform_result.h',
+      'assert.h'
     ],
     'cflags': [
       '-std=c++0x',