ifw-odp 5.1.1
 
Loading...
Searching...
No Matches
clipm_testlib_defines.h
Go to the documentation of this file.
1
5
6#ifndef CLIPM_TESTLIB_DEFINES_H
7#define CLIPM_TESTLIB_DEFINES_H
8
9/*-----------------------------------------------------------------------------
10 Includes
11 -----------------------------------------------------------------------------*/
12
13#include <cpl.h>
16#include <string.h>
17
18/*-----------------------------------------------------------------------------
19 Defines
20 -----------------------------------------------------------------------------*/
21
22#if (defined HAVE_DECL___FUNC__ && !HAVE_DECL___FUNC__)
23
24#ifndef __func__
25#ifdef __FUNC__
26#define __func__ __FUNC__
27#else
28#define __func__ "unspecified func"
29#endif
30#endif
31
32#endif
33
34#define __file__ __FILE__
35
36/*----------------------------------------------------------------------------*/
37/*----------------------------------------------------------------------------*/
38#define clipm_testlib_image_save_if_verbose_nr(image, descriptor, nr) \
39do { \
40 _clipm_testlib_image_save_if_verbose( image, \
41 __func__, \
42 descriptor, \
43 nr); \
44} while (0)
45
46/*----------------------------------------------------------------------------*/
47/*----------------------------------------------------------------------------*/
48#define clipm_testlib_image_save_if_verbose(image, descriptor) \
49do { \
50 _clipm_testlib_image_save_if_verbose( image, \
51 __func__, \
52 descriptor, \
53 -1); \
54} while (0)
55
56/*----------------------------------------------------------------------------*/
57/*----------------------------------------------------------------------------*/
58#define CLIPM_TRY_TESTLIB_ASSERT( CONDITION) \
59do { \
60 if (!(CONDITION)) \
61 { \
62 clipm_testlib_msg_error( \
63 "Not fulfilling condition \"%s\"", #CONDITION); \
64 CLIPM_TRY_EXIT_WITH_ERROR( CPL_ERROR_ILLEGAL_OUTPUT); \
65 } \
66 else \
67 { \
68 cpl_msg_indent_more(); \
69 clipm_testlib_msg_debug("Assert: "#CONDITION); \
70 cpl_msg_indent_less(); \
71 } \
72} while (0)
73
74/*----------------------------------------------------------------------------*/
75/*----------------------------------------------------------------------------*/
76#define CLIPM_TRY_TESTLIB_ASSERT_ZERO( VALUE, \
77 TOLERANCE) \
78do { \
79 double val, \
80 tol; \
81 val = (double)(VALUE); \
82 tol = (double)(TOLERANCE); \
83 if (!(fabs(val) <= tol)) \
84 { \
85 if (tol == 0.0) \
86 clipm_testlib_msg_error( \
87 "Not fulfilling condition \"fabs(%s) == %s\"", \
88 #VALUE, \
89 #TOLERANCE); \
90 else \
91 clipm_testlib_msg_error( \
92 "Not fulfilling condition \"fabs(%s) < %s\"", \
93 #VALUE, \
94 #TOLERANCE); \
95 clipm_testlib_msg_error( \
96 "Residual is %g", val); \
97 CLIPM_TRY_EXIT_WITH_ERROR( CPL_ERROR_ILLEGAL_OUTPUT); \
98 } \
99 else \
100 { \
101 cpl_msg_indent_more(); \
102 if (tol == 0.0) \
103 clipm_testlib_msg_debug( "Assert: \"%s == %s\"", \
104 #VALUE, \
105 #TOLERANCE); \
106 else \
107 clipm_testlib_msg_debug( "Assert: \"fabs(%s) <= %s\"", \
108 #VALUE, \
109 #TOLERANCE); \
110 cpl_msg_indent_less(); \
111 } \
112} while (0)
113
114/*----------------------------------------------------------------------------*/
115/* different messages for different CPL versions are allowed, because it should
116 * anyway only be used when there is an error */
117#if CLIPM_GET_INSTALLED_CPL_VERSION >= 4
118 #define clipm_testlib_expected_message(EXPECTED, GOT_CODE) \
119 do { \
120 clipm_testlib_msg_error( \
121 "-> expected error %d (%s),", \
122 EXPECTED, \
123 cpl_error_get_message_default(EXPECTED)); \
124 clipm_testlib_msg_error( \
125 " got error %d (%s),", \
126 GOT_CODE, \
127 cpl_error_get_message_default(GOT_CODE)); \
128 clipm_testlib_msg_error( \
129 " in %s: line %d", \
130 __func__, \
131 __LINE__); \
132 } while (0)
133#else
134 #define clipm_testlib_expected_message(EXPECTED, GOT_CODE) \
135 do { \
136 clipm_testlib_msg_error( \
137 "-> expected error %d,", \
138 EXPECTED); \
139 clipm_testlib_msg_error( \
140 " got error %d,", \
141 GOT_CODE); \
142 clipm_testlib_msg_error( \
143 " in %s: line %d", \
144 __func__, \
145 __LINE__); \
146 } while (0)
147#endif
148
149/*----------------------------------------------------------------------------*/
150/*----------------------------------------------------------------------------*/
151#if CLIPM_GET_INSTALLED_CPL_VERSION >= 4
152#define CLIPM_TRY_TESTLIB_CHECK_RETURN_ERROR_AND_RECOVER( \
153 FUNC, \
154 CODE, \
155 OTHER_CONDITION ) \
156do { \
157 cpl_error_code error; \
158 cpl_errorstate state; \
159 state = cpl_errorstate_get(); \
160 clipm_testlib_msg_info("Checking clean abort with error code %d", \
161 (CODE)); \
162 error = FUNC; \
163 cpl_msg_indent_more(); \
164 if (cpl_errorstate_is_equal(state)) /* FUNC might not be call but value */ \
165 { \
166 /*clipm_priv_testlib_msg_success();*/ \
167 cpl_msg_info( __func__, \
168 "%s\n in %s()", \
169 cpl_error_get_message(), \
170 cpl_error_get_function()); \
171 } \
172 else \
173 { \
174 if (error != cpl_error_get_code()) \
175 cpl_error_set_message(__func__, CPL_ERROR_ILLEGAL_OUTPUT, \
176 "return error does not match" \
177 " error state"); \
178 cpl_errorstate_dump( state, \
179 CPL_FALSE, \
180 clipm_testlib_errorstate_dump_one); \
181 } \
182 cpl_msg_indent_less(); \
183 if (error != (CODE)) \
184 { \
185 clipm_testlib_expected_message( CODE, error); \
186 CLIPM_TRY_CHECK_ERROR_STATE(); \
187 CLIPM_TRY_EXIT_WITH_ERROR( CPL_ERROR_ILLEGAL_OUTPUT); \
188 } \
189 \
190 CLIPM_TRY_TESTLIB_ASSERT(OTHER_CONDITION); \
191 \
192 CLIPM_ERROR_RECOVER_TRYSTATE(); \
193 \
194} while (0)
195#else
196#define CLIPM_TRY_TESTLIB_CHECK_RETURN_ERROR_AND_RECOVER( \
197 FUNC, \
198 CODE, \
199 OTHER_CONDITION ) \
200do { \
201 cpl_error_code error; \
202 clipm_testlib_msg_info("Checking clean abort with error code %d", \
203 (CODE)); \
204 error = FUNC; \
205 cpl_msg_indent_more(); \
206 if (error == CPL_ERROR_NONE && cpl_error_get_code() == CPL_ERROR_NONE) \
207 clipm_testlib_msg_info("Successful."); \
208 else \
209 { \
210 clipm_testlib_msg_error( "\"%s\" in %s", \
211 cpl_error_get_message(), \
212 cpl_error_get_where()); \
213 if (error != cpl_error_get_code()) \
214 { \
215 cpl_error_set(__func__, CPL_ERROR_ILLEGAL_OUTPUT); \
216 clipm_testlib_msg_error( "return error does not match" \
217 " error state"); \
218 } \
219 } \
220 cpl_msg_indent_less(); \
221 if (error != (CODE)) \
222 { \
223 clipm_testlib_expected_message( CODE, error); \
224 CLIPM_TRY_CHECK_ERROR_STATE(); \
225 CLIPM_TRY_EXIT_WITH_ERROR( CPL_ERROR_ILLEGAL_OUTPUT); \
226 } \
227 \
228 CLIPM_TRY_TESTLIB_ASSERT(OTHER_CONDITION); \
229 \
230 CLIPM_ERROR_RECOVER_TRYSTATE(); \
231 \
232} while (0)
233#endif
234
235
236/*----------------------------------------------------------------------------*/
237/*----------------------------------------------------------------------------*/
238#define CLIPM_TRY_TESTLIB_DONT_CHECK( CODE ) \
239 clipm_testlib_msg_info( \
240 "Note: check for error code %d not implemented/possible", \
241 (CODE));
242
243/*----------------------------------------------------------------------------*/
244#endif /* CLIPM_TESTLIB_DEFINES_H */