Merging tizen into ckm. Stage 1.
[platform/core/test/security-tests.git] / src / framework / src / assert.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /*
17  * @file        assert.cpp
18  * @author      Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
19  * @version     1.0
20  * @brief       This file is the implementation file of assert
21  */
22 #include <stddef.h>
23 #include <dpl/assert.h>
24 #include <dpl/colors.h>
25 #include <dpl/exception.h>
26 #include <dpl/log/log.h>
27 #include <cstdlib>
28
29 namespace DPL {
30 void AssertProc(const char *condition,
31                 const char *file,
32                 int line,
33                 const char *function)
34 {
35 #define INTERNAL_LOG(message)                                          \
36     do                                                                 \
37     {                                                                  \
38         std::ostringstream platformLog;                                \
39         platformLog << message;                                        \
40         DPL::Log::LogSystemSingleton::Instance().Pedantic(             \
41             platformLog.str().c_str(),                                 \
42             __FILE__, __LINE__, __FUNCTION__);                         \
43     } \
44     while (0)
45
46     // Try to log failed assertion to log system
47     Try
48     {
49         INTERNAL_LOG(
50             "################################################################################");
51         INTERNAL_LOG(
52             "###                          DPL assertion failed!                           ###");
53         INTERNAL_LOG(
54             "################################################################################");
55         INTERNAL_LOG("### Condition: " << condition);
56         INTERNAL_LOG("### File: " << file);
57         INTERNAL_LOG("### Line: " << line);
58         INTERNAL_LOG("### Function: " << function);
59         INTERNAL_LOG(
60             "################################################################################");
61     } catch (Exception) {
62         // Just ignore possible double errors
63     }
64
65     // Fail with c-library abort
66     abort();
67 }
68 } // namespace DPL