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