QP/C
qassert.h
Go to the documentation of this file.
00001 /*****************************************************************************
00002 * Product:  QP/C/C++
00003 * Last Updated for Version: 4.4.00
00004 * Date of the Last Update:  Jan 26, 2012
00005 *
00006 *                    Q u a n t u m     L e a P s
00007 *                    ---------------------------
00008 *                    innovating embedded systems
00009 *
00010 * Copyright (C) 2002-2012 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 
00071     typedef int int_t;
00072 
00081     void Q_onAssert(char_t const Q_ROM * const Q_ROM_VAR file, int_t line);
00082 
00083     #ifdef __cplusplus
00084         }
00085     #endif
00086 
00091     #define Q_DEFINE_THIS_FILE \
00092         static char_t const Q_ROM Q_ROM_VAR l_this_file[] = __FILE__;
00093 
00098     #define Q_DEFINE_THIS_MODULE(name_) \
00099         static char_t const Q_ROM Q_ROM_VAR l_this_file[] = name_;
00100 
00108     #define Q_ASSERT(test_) \
00109         ((test_) ? (void)0 : Q_onAssert(&l_this_file[0], (int_t)__LINE__))
00110 
00121     #define Q_ASSERT_ID(id_, test_) \
00122         ((test_) ? (void)0 : Q_onAssert(&l_this_file[0], (int_t)(id_))
00123 
00133     #define Q_ALLEGE(test_)    Q_ASSERT(test_)
00134 
00146     #define Q_ALLEGE_ID(id_, test_) Q_ASSERT_ID(id_, test_)
00147 
00153     #define Q_ERROR() \
00154         Q_onAssert(l_this_file, (int_t)__LINE__)
00155 
00163     #define Q_ERROR_ID(id_) \
00164         Q_onAssert(l_this_file, (int_t)(id_))
00165 
00166 #endif                                                         /* Q_NASSERT */
00167 
00173 #define Q_REQUIRE(test_)         Q_ASSERT(test_)
00174 
00180 #define Q_REQUIRE_ID(id_, test_) Q_ASSERT_ID(id_, test_)
00181 
00187 #define Q_ENSURE(test_)          Q_ASSERT(test_)
00188 
00194 #define Q_ENSURE_ID(id_, test_)  Q_ASSERT_ID(id_, test_)
00195 
00201 #define Q_INVARIANT(test_)       Q_ASSERT(test_)
00202 
00208 #define Q_INVARIANT_ID(id_, test_) Q_ASSERT_ID(id_, test_)
00209 
00215 #define Q_ASSERT_COMPILE(test_) \
00216     extern char_t Q_assert_compile[(test_) ? 1 : -1]
00217 
00218 #endif                                                         /* qassert_h */