QP-nano
qassert.h
Go to the documentation of this file.
00001 /*****************************************************************************
00002 * Product:  QP-nano
00003 * Last Updated for Version: 4.2.01
00004 * Date of the Last Update:  Aug 12, 2011
00005 *
00006 *                    Q u a n t u m     L e a P s
00007 *                    ---------------------------
00008 *                    innovating embedded systems
00009 *
00010 * Copyright (C) 2002-2011 Quantum Leaps, LLC. All rights reserved.
00011 *
00012 * This software may be distributed and modified under the terms of the GNU
00013 * General Public License version 2 (GPL) as published by the Free Software
00014 * Foundation and appearing in the file GPL.TXT included in the packaging of
00015 * this file. Please note that GPL Section 2[b] requires that all works based
00016 * on this software must also be made publicly available under the terms of
00017 * the GPL ("Copyleft").
00018 *
00019 * Alternatively, this software may be distributed and modified under the
00020 * terms of Quantum Leaps commercial licenses, which expressly supersede
00021 * the GPL and are specifically designed for licensees interested in
00022 * retaining the proprietary status of their code.
00023 *
00024 * Contact information:
00025 * Quantum Leaps Web site:  http://www.quantum-leaps.com
00026 * e-mail:                  info@quantum-leaps.com
00027 *****************************************************************************/
00028 #ifndef qassert_h
00029 #define qassert_h
00030 
00048 #ifdef Q_NASSERT          /* Q_NASSERT defined--assertion checking disabled */
00049 
00050     #define Q_DEFINE_THIS_FILE
00051     #define Q_DEFINE_THIS_MODULE(name_)
00052     #define Q_ASSERT(test_)             ((void)0)
00053     #define Q_ASSERT_ID(id_, test_)     ((void)0)
00054     #define Q_ALLEGE(test_)             ((void)(test_))
00055     #define Q_ALLEGE_ID(id_, test_)     ((void)(test_))
00056     #define Q_ERROR()                   ((void)0)
00057     #define Q_ERROR_ID(id_)             ((void)0)
00058 
00059 #else                  /* Q_NASSERT not defined--assertion checking enabled */
00060 
00061     #ifdef __cplusplus
00062         extern "C" {
00063     #endif
00064 
00073     /*lint -sem(Q_onAssert, r_no)                Q_onAssert() never returns */
00074     void Q_onAssert(char const Q_ROM * const Q_ROM_VAR file, int line);
00075 
00076     #ifdef __cplusplus
00077         }
00078     #endif
00079 
00084     #define Q_DEFINE_THIS_FILE \
00085         static char const Q_ROM Q_ROM_VAR l_this_file[] = __FILE__;
00086 
00091     #define Q_DEFINE_THIS_MODULE(name_) \
00092         static char const Q_ROM Q_ROM_VAR l_this_file[] = #name_;
00093 
00101     #define Q_ASSERT(test_) \
00102         if (test_) { \
00103         } \
00104         else (Q_onAssert(&l_this_file[0], __LINE__))
00105 
00116     #define Q_ASSERT_ID(id_, test_) \
00117         if (test_) { \
00118         } \
00119         else (Q_onAssert(&l_this_file[0], (id_)))
00120 
00130     #define Q_ALLEGE(test_)    Q_ASSERT(test_)
00131 
00143     #define Q_ALLEGE_ID(id_, test_) Q_ASSERT_ID(id_, test_)
00144 
00150     #define Q_ERROR() \
00151         (Q_onAssert(l_this_file, __LINE__))
00152 
00160     #define Q_ERROR_ID(id_) \
00161         (Q_onAssert(l_this_file, (id_)))
00162 
00163 
00164 #endif                                                         /* Q_NASSERT */
00165 
00171 #define Q_REQUIRE(test_)         Q_ASSERT(test_)
00172 
00178 #define Q_REQUIRE_ID(id_, test_) Q_ASSERT_ID(id_, test_)
00179 
00185 #define Q_ENSURE(test_)          Q_ASSERT(test_)
00186 
00192 #define Q_ENSURE_ID(id_, test_)  Q_ASSERT_ID(id_, test_)
00193 
00199 #define Q_INVARIANT(test_)       Q_ASSERT(test_)
00200 
00206 #define Q_INVARIANT_ID(id_, test_) Q_ASSERT_ID(id_, test_)
00207 
00213 #define Q_ASSERT_COMPILE(test_) \
00214     extern char Q_assert_compile[(test_) ? 1 : -1]
00215 
00216 #endif                                                         /* qassert_h */