QP/C  6.6.0
qassert.h
Go to the documentation of this file.
1 
39 #ifndef QASSERT_H
40 #define QASSERT_H
41 
52 #ifdef Q_NASSERT /* Q_NASSERT defined--assertion checking disabled */
53 
54  /* provide dummy (empty) definitions that don't generate any code... */
55  #define Q_DEFINE_THIS_FILE
56  #define Q_DEFINE_THIS_MODULE(name_)
57  #define Q_ASSERT(test_) ((void)0)
58  #define Q_ASSERT_ID(id_, test_) ((void)0)
59  #define Q_ALLEGE(test_) ((void)(test_))
60  #define Q_ALLEGE_ID(id_, test_) ((void)(test_))
61  #define Q_ERROR() ((void)0)
62  #define Q_ERROR_ID(id_) ((void)0)
63 
64 #else /* Q_NASSERT not defined--assertion checking enabled */
65 
66 #ifndef QP_VERSION /* is quassert.h used outside QP? */
67 
68  /* provide typedefs so that qassert.h could be used "standalone"... */
69 
77  typedef char char_t;
78 
86  typedef int int_t;
87 
88 #endif
89 
104  #define Q_DEFINE_THIS_FILE \
105  static char_t const Q_this_module_[] = __FILE__;
106 
120  #define Q_DEFINE_THIS_MODULE(name_) \
121  static char_t const Q_this_module_[] = name_;
122 
136  #define Q_ASSERT(test_) ((test_) \
137  ? (void)0 : Q_onAssert(&Q_this_module_[0], (int_t)__LINE__))
138 
155  #define Q_ASSERT_ID(id_, test_) ((test_) \
156  ? (void)0 : Q_onAssert(&Q_this_module_[0], (int_t)(id_)))
157 
171  #define Q_ALLEGE(test_) Q_ASSERT(test_)
172 
186  #define Q_ALLEGE_ID(id_, test_) Q_ASSERT_ID((id_), (test_))
187 
195  #define Q_ERROR() \
196  Q_onAssert(&Q_this_module_[0], (int_t)__LINE__)
197 
211  #define Q_ERROR_ID(id_) \
212  Q_onAssert(&Q_this_module_[0], (int_t)(id_))
213 
214 #endif /* Q_NASSERT */
215 
216 #ifdef __cplusplus
217  extern "C" {
218 #endif
219 
248 void Q_onAssert(char_t const * const module, int_t location);
249 
250 #ifdef __cplusplus
251  }
252 #endif
253 
262 #define Q_REQUIRE(test_) Q_ASSERT(test_)
263 
273 #define Q_REQUIRE_ID(id_, test_) Q_ASSERT_ID((id_), (test_))
274 
281 #define Q_ENSURE(test_) Q_ASSERT(test_)
282 
292 #define Q_ENSURE_ID(id_, test_) Q_ASSERT_ID((id_), (test_))
293 
302 #define Q_INVARIANT(test_) Q_ASSERT(test_)
303 
313 #define Q_INVARIANT_ID(id_, test_) Q_ASSERT_ID((id_), (test_))
314 
325 #define Q_ASSERT_STATIC(test_) \
326  extern int_t Q_assert_static[(test_) ? 1 : -1]
327 
328 #define Q_ASSERT_COMPILE(test_) Q_ASSERT_STATIC(test_)
329 
331 #define Q_DIM(array_) (sizeof(array_) / sizeof((array_)[0]))
332 
333 #endif /* QASSERT_H */
334 
Q_onAssert
void Q_onAssert(char_t const *const module, int_t location)
Callback function invoked in case of any assertion failure.
Definition: qutest.c:415
char_t
char char_t
typedef for character strings.
Definition: qassert.h:77
int_t
int int_t
typedef for assertions-ids and line numbers in assertions.
Definition: qassert.h:86