1 martin 1.11 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.12 //
|
3 martin 1.11 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.12 //
|
10 martin 1.11 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.12 //
|
17 martin 1.11 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.12 //
|
20 martin 1.11 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.12 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.11 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.12 //
|
28 martin 1.11 //////////////////////////////////////////////////////////////////////////
|
29 jim.wunderlich 1.1 //
30 //%/////////////////////////////////////////////////////////////////////////////
31 #ifndef Pegasus_Assert_h
32 #define Pegasus_Assert_h
33
|
34 thilo.boehm 1.10 #ifdef PEGASUS_OS_ZOS
35 // zOS specific implementation of assert macros.
36 # include <Pegasus/Common/PegasusAssertZOS.h>
|
37 kumpf 1.7
|
38 kumpf 1.13 #else
|
39 kumpf 1.7 // NOTE:
|
40 jim.wunderlich 1.2 //
|
41 thilo.boehm 1.10 // This is the common implementation for the assert macros.
|
42 kumpf 1.13 // If platform specific implementation are needed they have to
|
43 thilo.boehm 1.10 // be placed in a platform specific include file and included before.
44 //
|
45 kumpf 1.7 // All built and tested OK with <assert.h>
|
46 jim.wunderlich 1.2 // but <cassert> is more appropriate for c++ files
|
47 kumpf 1.7 // however if this should be a problem for any c fileswithin the tree
48 // it is possible to revert back to assert.h
|
49 jim.wunderlich 1.2 // J Wunderlich 11/21/2005
50 //
|
51 jim.wunderlich 1.4
52 #if (__cplusplus)
|
53 jim.wunderlich 1.2 #include <cassert>
|
54 jim.wunderlich 1.4 #else
55 #include <assert.h>
56 #endif
|
57 jim.wunderlich 1.1
|
58 jim.wunderlich 1.3 /** define PEGASUS_ASSERT assertion statement. This statement tests the
59 condition defined by the parameters and if not True executes an
60
|
61 kumpf 1.7 It only generates code if NDEBUG is not defined.
|
62 jim.wunderlich 1.3 See also the man page for assert().
63
|
64 kumpf 1.7 NOTE: if NDEBUG is set then the assert() macro will generate no code,
65 and hence do nothing at all.
|
66 jim.wunderlich 1.3
67 <pre>
68 assert()
69 </pre>
70
71 defining the file, line and condition that was tested.
72 */
73
|
74 marek 1.9 #define PEGASUS_ASSERT(COND) assert(COND)
75
|
76 jim.wunderlich 1.1
77 /* define PEGASUS_DEBUG_ASSERT() assertion statement. This statement tests the
|
78 kumpf 1.7 condition defined by the parameters and if not True executes an assert.
|
79 jim.wunderlich 1.1 It only generates code if PEGASUS_DEBUG is defined and NDEBUG is not
|
80 kumpf 1.7 defined.
|
81 jim.wunderlich 1.1 See also the man page for assert().
82
|
83 kumpf 1.7 NOTE: if NDEBUG is set then the assert() macro will generate no code,
84 and hence do nothing at all.
|
85 jim.wunderlich 1.1
86 */
87
88 #ifdef PEGASUS_DEBUG
|
89 marek 1.9 # define PEGASUS_DEBUG_ASSERT(COND) assert(COND)
|
90 jim.wunderlich 1.1 #else
|
91 kumpf 1.7 # define PEGASUS_DEBUG_ASSERT(COND)
|
92 jim.wunderlich 1.1 #endif
93
|
94 kumpf 1.7 #define PEGASUS_TEST_ASSERT(COND) \
95 do \
96 { \
97 if (!(COND)) \
98 { \
99 printf("PEGASUS_TEST_ASSERT failed in file %s at line %d\n", \
100 __FILE__, __LINE__); \
101 abort(); \
102 } \
103 } while (0)
|
104 jim.wunderlich 1.2
|
105 karl 1.14 # endif /* PEGASUS_OS_ZOS */
106
|
107 marek 1.15
108 /* define PEGASUS_FCT_EXECUTE_AND_ASSERT assertion statement.
109
110 Use this macro to avoid unused variables instead of PEGASUS_ASSERT when
111 the return value of a function is only used to do an assert check.
112
113 This statement compares the return value of function against VALUE for
114 equalness but only if assertion is enabled. The Function FCT will always be
115 called (equal if assertion is enabled or disabled).
116
117 Do this:
118
119 PEGASUS_FCT_EXECUTE_AND_ASSERT(true, f());
120
121 Not this:
122 bool returnCode = f();
123 PEGASUS_ASSERT(true == returnCode);
124 */
125 #if defined(PEGASUS_NOASSERTS) || defined(NDEBUG)
126 # define PEGASUS_FCT_EXECUTE_AND_ASSERT(VALUE,FCT) FCT
127 #else
128 marek 1.15 # define PEGASUS_FCT_EXECUTE_AND_ASSERT(VALUE,FCT) PEGASUS_ASSERT(VALUE == FCT)
129 #endif
130
|
131 karl 1.14 /**
132 Defines PEGASUS_DISABLED_TEST_ASSERT(COND) assertion statement.
133 This assert generates an error message and executes an exit(0) so that
134 the tests may continue.
135 Used for tests that we want to become permanent but today they may fail
136 It generates code independent of PEGASUS_DEBUG.
137 This macro is to be used ONLY by pegasus test components to temporarily
138 bypass asserts for tests that are defined but do not currently work
139 correctly.
140
141 See also the man page for assert().
142
143 NOTE: This macro is not linked to NDEBUG and also independent of
144 platform definition
145 */
146
147 #define PEGASUS_DISABLED_TEST_ASSERT(COND) \
148 do \
149 { \
150 if (!(COND)) \
151 { \
152 karl 1.14 printf("PEGASUS_DISABLED_TEST_ASSERT failed in file %s" \
153 " line %d.\n Exit 0 from program so tests can continue\n", \
154 __FILE__, __LINE__); \
155 exit(0); \
156 } \
157 } while (0)
158
159 /**
160 * Same as PEGASUS_DISABLED_TEST_ASSERT except that this macro does not
161 * exit the program, simply generates a message and lets the program
162 * continue.
163 */
164 #define PEGASUS_DISABLED_TEST_ASSERT_CONTINUE(COND) \
165 do \
166 { \
167 if (!(COND)) \
168 { \
169 printf("PEGASUS_DISABLED_TEST_ASSERT failed in file %s" \
170 " line %d.\n Exit 0 from program so tests can continue\n", \
171 __FILE__, __LINE__); \
172 } \
173 karl 1.14 } while (0)
|
174 jim.wunderlich 1.1 #endif /* Pegasus_Assert_h */
|