1 /******************************************************************************
2  *
3  *  Copyright (C) 2014 The Android Open Source Project
4  *  Copyright 2002 - 2004 Open Interface North America, Inc. All rights reserved.
5  *
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at:
9  *
10  *  http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  ******************************************************************************/
19 #ifndef _OI_ASSERT_H
20 #define _OI_ASSERT_H
21 /** @file
22   This file provides macros and functions for compile-time and run-time assertions.
23 
24   When the OI_DEBUG preprocessor value is defined, the macro OI_ASSERT is compiled into
25   the program, providing for a runtime assertion failure check.
26   C_ASSERT is a macro that can be used to perform compile time checks.
27 */
28 /**********************************************************************************
29   $Revision: #1 $
30 ***********************************************************************************/
31 
32 
33 /** \addtogroup Debugging Debugging APIs */
34 /**@{*/
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 
41 #ifdef OI_DEBUG
42 
43 /** The macro OI_ASSERT takes a condition argument. If the asserted condition
44     does not evaluate to true, the OI_ASSERT macro calls the host-dependent function,
45     OI_AssertFail(), which reports the failure and generates a runtime error.
46 */
47 void OI_AssertFail(char* file, int line, char* reason);
48 
49 
50 #define OI_ASSERT(condition) \
51     { if (!(condition)) OI_AssertFail(__FILE__, __LINE__, #condition); }
52 
53 #define OI_ASSERT_FAIL(msg) \
54     { OI_AssertFail(__FILE__, __LINE__, msg); }
55 
56 #else
57 
58 
59 #define OI_ASSERT(condition)
60 #define OI_ASSERT_FAIL(msg)
61 
62 #endif
63 
64 
65 /**
66    C_ASSERT() can be used to perform many compile-time assertions: type sizes, field offsets, etc.
67    An assertion failure results in compile time error C2118: negative subscript.
68    Unfortunately, this elegant macro doesn't work with GCC, so it's all commented out
69    for now. Perhaps later.....
70 */
71 
72 #ifndef C_ASSERT
73 // #define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1]
74 // #define C_ASSERT(e)
75 #endif
76 
77 
78 /*****************************************************************************/
79 #ifdef __cplusplus
80 }
81 #endif
82 
83 /**@}*/
84 
85 #endif /* _OI_ASSERT_H */
86 
87