Go to the documentation of this file.
14 #ifndef CLIPM_TESTLIB_DEFINES_H
15 #define CLIPM_TESTLIB_DEFINES_H
30 #if (defined HAVE_DECL___FUNC__ && !HAVE_DECL___FUNC__)
34 #define __func__ __FUNC__
36 #define __func__ "unspecified func"
42 #define __file__ __FILE__
46 #define clipm_testlib_image_save_if_verbose_nr(image, descriptor, nr) \
48 _clipm_testlib_image_save_if_verbose( image, \
56 #define clipm_testlib_image_save_if_verbose(image, descriptor) \
58 _clipm_testlib_image_save_if_verbose( image, \
66 #define CLIPM_TRY_TESTLIB_ASSERT( CONDITION) \
70 clipm_testlib_msg_error( \
71 "Not fulfilling condition \"%s\"", #CONDITION); \
72 CLIPM_TRY_EXIT_WITH_ERROR( CPL_ERROR_ILLEGAL_OUTPUT); \
76 cpl_msg_indent_more(); \
77 clipm_testlib_msg_debug("Assert: "#CONDITION); \
78 cpl_msg_indent_less(); \
84 #define CLIPM_TRY_TESTLIB_ASSERT_ZERO( VALUE, \
89 val = (double)(VALUE); \
90 tol = (double)(TOLERANCE); \
91 if (!(fabs(val) <= tol)) \
94 clipm_testlib_msg_error( \
95 "Not fulfilling condition \"fabs(%s) == %s\"", \
99 clipm_testlib_msg_error( \
100 "Not fulfilling condition \"fabs(%s) < %s\"", \
103 clipm_testlib_msg_error( \
104 "Residual is %g", val); \
105 CLIPM_TRY_EXIT_WITH_ERROR( CPL_ERROR_ILLEGAL_OUTPUT); \
109 cpl_msg_indent_more(); \
111 clipm_testlib_msg_debug( "Assert: \"%s == %s\"", \
115 clipm_testlib_msg_debug( "Assert: \"fabs(%s) <= %s\"", \
118 cpl_msg_indent_less(); \
125 #if CLIPM_GET_INSTALLED_CPL_VERSION >= 4
126 #define clipm_testlib_expected_message(EXPECTED, GOT_CODE) \
128 clipm_testlib_msg_error( \
129 "-> expected error %d (%s),", \
131 cpl_error_get_message_default(EXPECTED)); \
132 clipm_testlib_msg_error( \
133 " got error %d (%s),", \
135 cpl_error_get_message_default(GOT_CODE)); \
136 clipm_testlib_msg_error( \
142 #define clipm_testlib_expected_message(EXPECTED, GOT_CODE) \
144 clipm_testlib_msg_error( \
145 "-> expected error %d,", \
147 clipm_testlib_msg_error( \
150 clipm_testlib_msg_error( \
159 #if CLIPM_GET_INSTALLED_CPL_VERSION >= 4
160 #define CLIPM_TRY_TESTLIB_CHECK_RETURN_ERROR_AND_RECOVER( \
165 cpl_error_code error; \
166 cpl_errorstate state; \
167 state = cpl_errorstate_get(); \
168 clipm_testlib_msg_info("Checking clean abort with error code %d", \
171 cpl_msg_indent_more(); \
172 if (cpl_errorstate_is_equal(state)) \
175 cpl_msg_info( __func__, \
177 cpl_error_get_message(), \
178 cpl_error_get_function()); \
182 if (error != cpl_error_get_code()) \
183 cpl_error_set_message(__func__, CPL_ERROR_ILLEGAL_OUTPUT, \
184 "return error does not match" \
186 cpl_errorstate_dump( state, \
188 clipm_testlib_errorstate_dump_one); \
190 cpl_msg_indent_less(); \
191 if (error != (CODE)) \
193 clipm_testlib_expected_message( CODE, error); \
194 CLIPM_TRY_CHECK_ERROR_STATE(); \
195 CLIPM_TRY_EXIT_WITH_ERROR( CPL_ERROR_ILLEGAL_OUTPUT); \
198 CLIPM_TRY_TESTLIB_ASSERT(OTHER_CONDITION); \
200 CLIPM_ERROR_RECOVER_TRYSTATE(); \
204 #define CLIPM_TRY_TESTLIB_CHECK_RETURN_ERROR_AND_RECOVER( \
209 cpl_error_code error; \
210 clipm_testlib_msg_info("Checking clean abort with error code %d", \
213 cpl_msg_indent_more(); \
214 if (error == CPL_ERROR_NONE && cpl_error_get_code() == CPL_ERROR_NONE) \
215 clipm_testlib_msg_info("Successful."); \
218 clipm_testlib_msg_error( "\"%s\" in %s", \
219 cpl_error_get_message(), \
220 cpl_error_get_where()); \
221 if (error != cpl_error_get_code()) \
223 cpl_error_set(__func__, CPL_ERROR_ILLEGAL_OUTPUT); \
224 clipm_testlib_msg_error( "return error does not match" \
228 cpl_msg_indent_less(); \
229 if (error != (CODE)) \
231 clipm_testlib_expected_message( CODE, error); \
232 CLIPM_TRY_CHECK_ERROR_STATE(); \
233 CLIPM_TRY_EXIT_WITH_ERROR( CPL_ERROR_ILLEGAL_OUTPUT); \
236 CLIPM_TRY_TESTLIB_ASSERT(OTHER_CONDITION); \
238 CLIPM_ERROR_RECOVER_TRYSTATE(); \
246 #define CLIPM_TRY_TESTLIB_DONT_CHECK( CODE ) \
247 clipm_testlib_msg_info( \
248 "Note: check for error code %d not implemented/possible", \