00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef ASSERTIONS_H
00023 #define ASSERTIONS_H 1
00024
00025 typedef enum {
00026 assert_require, assert_ensure, assert_insist, assert_invariant
00027 } assertion_type;
00028
00029 typedef void (*assertion_failure_callback)(char *, int, assertion_type, char *,
00030 int);
00031
00032 extern assertion_failure_callback __assertion_failed;
00033 void set_assertion_failure_callback(assertion_failure_callback f);
00034 char *assertion_type_to_text(assertion_type type);
00035
00036 #ifdef CHECK_ALL
00037 #define CHECK_REQUIRE 1
00038 #define CHECK_ENSURE 1
00039 #define CHECK_INSIST 1
00040 #define CHECK_INVARIANT 1
00041 #endif
00042
00043 #ifdef CHECK_NONE
00044 #define CHECK_REQUIRE 0
00045 #define CHECK_ENSURE 0
00046 #define CHECK_INSIST 0
00047 #define CHECK_INVARIANT 0
00048 #endif
00049
00050 #ifndef CHECK_REQUIRE
00051 #define CHECK_REQUIRE 1
00052 #endif
00053
00054 #ifndef CHECK_ENSURE
00055 #define CHECK_ENSURE 1
00056 #endif
00057
00058 #ifndef CHECK_INSIST
00059 #define CHECK_INSIST 1
00060 #endif
00061
00062 #ifndef CHECK_INVARIANT
00063 #define CHECK_INVARIANT 1
00064 #endif
00065
00066 #if CHECK_REQUIRE != 0
00067 #define REQUIRE(cond) \
00068 ((void) ((cond) || \
00069 ((__assertion_failed)(__FILE__, __LINE__, assert_require, \
00070 #cond, 0), 0)))
00071 #define REQUIRE_ERR(cond) \
00072 ((void) ((cond) || \
00073 ((__assertion_failed)(__FILE__, __LINE__, assert_require, \
00074 #cond, 1), 0)))
00075 #else
00076 #define REQUIRE(cond) ((void) 0)
00077 #define REQUIRE_ERR(cond) ((void) 0)
00078 #endif
00079
00080 #if CHECK_ENSURE != 0
00081 #define ENSURE(cond) \
00082 ((void) ((cond) || \
00083 ((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \
00084 #cond, 0), 0)))
00085 #define ENSURE_ERR(cond) \
00086 ((void) ((cond) || \
00087 ((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \
00088 #cond, 1), 0)))
00089 #else
00090 #define ENSURE(cond) ((void) 0)
00091 #define ENSURE_ERR(cond) ((void) 0)
00092 #endif
00093
00094 #if CHECK_INSIST != 0
00095 #define INSIST(cond) \
00096 ((void) ((cond) || \
00097 ((__assertion_failed)(__FILE__, __LINE__, assert_insist, \
00098 #cond, 0), 0)))
00099 #define INSIST_ERR(cond) \
00100 ((void) ((cond) || \
00101 ((__assertion_failed)(__FILE__, __LINE__, assert_insist, \
00102 #cond, 1), 0)))
00103 #else
00104 #define INSIST(cond) ((void) 0)
00105 #define INSIST_ERR(cond) ((void) 0)
00106 #endif
00107
00108 #if CHECK_INVARIANT != 0
00109 #define INVARIANT(cond) \
00110 ((void) ((cond) || \
00111 ((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \
00112 #cond, 0), 0)))
00113 #define INVARIANT_ERR(cond) \
00114 ((void) ((cond) || \
00115 ((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \
00116 #cond, 1), 0)))
00117 #else
00118 #define INVARIANT(cond) ((void) 0)
00119 #define INVARIANT_ERR(cond) ((void) 0)
00120 #endif
00121
00122 #endif