2 * Copyright (C) 2004, 2005, 2008 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1997-2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
19 * $Id: assertions.h,v 1.5 2008/11/14 02:36:51 marka Exp $
23 #define ASSERTIONS_H 1
26 assert_require
, assert_ensure
, assert_insist
, assert_invariant
29 typedef void (*assertion_failure_callback
)(const char *, int, assertion_type
,
33 extern assertion_failure_callback __assertion_failed
;
34 void set_assertion_failure_callback(assertion_failure_callback f
);
35 const char *assertion_type_to_text(assertion_type type
);
37 #if defined(CHECK_ALL) || defined(__COVERITY__)
38 #define CHECK_REQUIRE 1
39 #define CHECK_ENSURE 1
40 #define CHECK_INSIST 1
41 #define CHECK_INVARIANT 1
44 #if defined(CHECK_NONE) && !defined(__COVERITY__)
45 #define CHECK_REQUIRE 0
46 #define CHECK_ENSURE 0
47 #define CHECK_INSIST 0
48 #define CHECK_INVARIANT 0
52 #define CHECK_REQUIRE 1
56 #define CHECK_ENSURE 1
60 #define CHECK_INSIST 1
63 #ifndef CHECK_INVARIANT
64 #define CHECK_INVARIANT 1
67 #if CHECK_REQUIRE != 0
68 #define REQUIRE(cond) \
70 ((__assertion_failed)(__FILE__, __LINE__, assert_require, \
72 #define REQUIRE_ERR(cond) \
74 ((__assertion_failed)(__FILE__, __LINE__, assert_require, \
77 #define REQUIRE(cond) ((void) (cond))
78 #define REQUIRE_ERR(cond) ((void) (cond))
79 #endif /* CHECK_REQUIRE */
82 #define ENSURE(cond) \
84 ((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \
86 #define ENSURE_ERR(cond) \
88 ((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \
91 #define ENSURE(cond) ((void) (cond))
92 #define ENSURE_ERR(cond) ((void) (cond))
93 #endif /* CHECK_ENSURE */
96 #define INSIST(cond) \
98 ((__assertion_failed)(__FILE__, __LINE__, assert_insist, \
100 #define INSIST_ERR(cond) \
102 ((__assertion_failed)(__FILE__, __LINE__, assert_insist, \
105 #define INSIST(cond) ((void) (cond))
106 #define INSIST_ERR(cond) ((void) (cond))
107 #endif /* CHECK_INSIST */
109 #if CHECK_INVARIANT != 0
110 #define INVARIANT(cond) \
112 ((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \
114 #define INVARIANT_ERR(cond) \
116 ((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \
119 #define INVARIANT(cond) ((void) (cond))
120 #define INVARIANT_ERR(cond) ((void) (cond))
121 #endif /* CHECK_INVARIANT */
122 #endif /* ASSERTIONS_H */