From 461c14e844895045a451ade4a8b70929f5d57ae9 Mon Sep 17 00:00:00 2001 From: Grzegorz Rynkowski Date: Wed, 25 Feb 2015 18:55:03 +0100 Subject: [PATCH] [common] Added assert.h Problem: Using plain assert does not print any information about the source of assertion. Change-Id: I66192909d6fe5836b098b0e2225a79ec1de86f8d Signed-off-by: Grzegorz Rynkowski --- src/common/assert.h | 23 +++++++++++++++++++++++ src/common/common.gypi | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/common/assert.h diff --git a/src/common/assert.h b/src/common/assert.h new file mode 100644 index 00000000..f56ba791 --- /dev/null +++ b/src/common/assert.h @@ -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 + +#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 diff --git a/src/common/common.gypi b/src/common/common.gypi index 260a0fbf..d7698dff 100644 --- a/src/common/common.gypi +++ b/src/common/common.gypi @@ -101,7 +101,8 @@ #'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', -- 2.34.1