Initialize Tizen 2.3
[framework/web/wrt-commons.git] / modules / core / 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 <stdio.h>
23 #include <cstdlib>
24 #include <sstream>
25 #include <stddef.h>
26 #include <dpl/assert.h>
27 #include <dpl/colors.h>
28 #include <dpl/exception.h>
29 #include <dpl/log/wrt_log.h>
30
31 namespace DPL {
32 void AssertProc(const char *condition,
33                 const char *file,
34                 int line,
35                 const char *function)
36 {
37
38 #define INTERNAL_LOG(message)                  \
39 do {                                           \
40         std::ostringstream platformLog;        \
41         platformLog << message;                \
42     WrtLogE("%s", platformLog.str().c_str());  \
43 } while (0)
44
45     // Try to log failed assertion to log system
46     Try {
47         INTERNAL_LOG("########################################################################");
48         INTERNAL_LOG("###                      DPL assertion failed!                       ###");
49         INTERNAL_LOG("########################################################################");
50         INTERNAL_LOG("### Condition: " << condition);
51         INTERNAL_LOG("### File: " << file);
52         INTERNAL_LOG("### Line: " << line);
53         INTERNAL_LOG("### Function: " << function);
54         INTERNAL_LOG("########################################################################");
55     } catch (Exception) {
56         // Just ignore possible double errors
57     }
58
59     // print assertion message to stderr
60     fprintf(stderr, "Assert!! [%s:%s] %s\n", file, function, condition);
61
62     // Fail with c-library abort
63     abort();
64 }
65 } // namespace DPL