QP/C  6.9.3
Real-Time Embedded Framework
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], __LINE__))
138 
155  #define Q_ASSERT_ID(id_, test_) ((test_) \
156  ? (void)0 : Q_onAssert(&Q_this_module_[0], (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], __LINE__)
197 
211  #define Q_ERROR_ID(id_) \
212  Q_onAssert(&Q_this_module_[0], (id_))
213 
214 #endif /* Q_NASSERT */
215 
216 /****************************************************************************/
217 #ifdef __cplusplus
218  extern "C" {
219 #endif
220 
221 #ifndef Q_NORETURN
223  #define Q_NORETURN void
224 #endif /* Q_NORETURN */
225 
254 Q_NORETURN Q_onAssert(char_t const * const module, int_t const location);
255 
256 #ifdef __cplusplus
257  }
258 #endif
259 
268 #define Q_REQUIRE(test_) Q_ASSERT(test_)
269 
279 #define Q_REQUIRE_ID(id_, test_) Q_ASSERT_ID((id_), (test_))
280 
287 #define Q_ENSURE(test_) Q_ASSERT(test_)
288 
298 #define Q_ENSURE_ID(id_, test_) Q_ASSERT_ID((id_), (test_))
299 
308 #define Q_INVARIANT(test_) Q_ASSERT(test_)
309 
319 #define Q_INVARIANT_ID(id_, test_) Q_ASSERT_ID((id_), (test_))
320 
331 #define Q_ASSERT_STATIC(test_) \
332  extern int_t Q_assert_static[(test_) ? 1 : -1]
333 
334 #define Q_ASSERT_COMPILE(test_) Q_ASSERT_STATIC(test_)
335 
337 #define Q_DIM(array_) (sizeof(array_) / sizeof((array_)[0U]))
338 
339 #endif /* QASSERT_H */
340 
#define Q_NORETURN
Definition: qassert.h:223
char char_t
Definition: qassert.h:77
Q_NORETURN Q_onAssert(char_t const *const module, int_t const location)
Definition: qutest.c:437
int int_t
Definition: qassert.h:86