1 /* $NetBSD: assertions.h,v 1.1.1.1 2004/05/20 19:49:41 christos Exp $ */
4 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (c) 1997-1999 by Internet Software Consortium.
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
17 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 * Id: assertions.h,v 1.1.206.1 2004/03/09 08:33:30 marka Exp
25 * This version of this file is derived from Android 2.3 "Gingerbread",
26 * which contains uncredited changes by Android/Google developers. It has
27 * been modified in 2011 for use in the Android build of Mozilla Firefox by
28 * Mozilla contributors (including Michael Edwards <m.k.edwards@gmail.com>,
29 * and Steve Workman <sjhworkman@gmail.com>).
30 * These changes are offered under the same license as the original NetBSD
31 * file, whose copyright and license are unchanged above.
35 #define ASSERTIONS_H 1
38 assert_require
, assert_ensure
, assert_insist
, assert_invariant
41 typedef void (*assertion_failure_callback
)(const char *, int, assertion_type
,
44 extern assertion_failure_callback __assertion_failed
;
45 void set_assertion_failure_callback(assertion_failure_callback f
);
46 const char *assertion_type_to_text(assertion_type type
);
49 #define CHECK_REQUIRE 1
50 #define CHECK_ENSURE 1
51 #define CHECK_INSIST 1
52 #define CHECK_INVARIANT 1
56 #define CHECK_REQUIRE 0
57 #define CHECK_ENSURE 0
58 #define CHECK_INSIST 0
59 #define CHECK_INVARIANT 0
63 #define CHECK_REQUIRE 1
67 #define CHECK_ENSURE 1
71 #define CHECK_INSIST 1
74 #ifndef CHECK_INVARIANT
75 #define CHECK_INVARIANT 1
78 #if CHECK_REQUIRE != 0
79 #define REQUIRE(cond) \
81 ((__assertion_failed)(__FILE__, __LINE__, assert_require, \
83 #define REQUIRE_ERR(cond) \
85 ((__assertion_failed)(__FILE__, __LINE__, assert_require, \
88 #define REQUIRE(cond) ((void) (cond))
89 #define REQUIRE_ERR(cond) ((void) (cond))
90 #endif /* CHECK_REQUIRE */
93 #define ENSURE(cond) \
95 ((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \
97 #define ENSURE_ERR(cond) \
99 ((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \
102 #define ENSURE(cond) ((void) (cond))
103 #define ENSURE_ERR(cond) ((void) (cond))
104 #endif /* CHECK_ENSURE */
106 #if CHECK_INSIST != 0
107 #define INSIST(cond) \
109 ((__assertion_failed)(__FILE__, __LINE__, assert_insist, \
111 #define INSIST_ERR(cond) \
113 ((__assertion_failed)(__FILE__, __LINE__, assert_insist, \
116 #define INSIST(cond) ((void) (cond))
117 #define INSIST_ERR(cond) ((void) (cond))
118 #endif /* CHECK_INSIST */
120 #if CHECK_INVARIANT != 0
121 #define INVARIANT(cond) \
123 ((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \
125 #define INVARIANT_ERR(cond) \
127 ((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \
130 #define INVARIANT(cond) ((void) (cond))
131 #define INVARIANT_ERR(cond) ((void) (cond))
132 #endif /* CHECK_INVARIANT */
134 #endif /* ASSERTIONS_H */