assertions.h revision 1.2.6.2 1 1.2.6.2 christos /* $NetBSD: assertions.h,v 1.2.6.2 2008/06/21 20:41:49 christos Exp $ */
2 1.2.6.2 christos
3 1.2.6.2 christos /*
4 1.2.6.2 christos * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
5 1.2.6.2 christos * Copyright (c) 1997-1999 by Internet Software Consortium.
6 1.2.6.2 christos *
7 1.2.6.2 christos * Permission to use, copy, modify, and distribute this software for any
8 1.2.6.2 christos * purpose with or without fee is hereby granted, provided that the above
9 1.2.6.2 christos * copyright notice and this permission notice appear in all copies.
10 1.2.6.2 christos *
11 1.2.6.2 christos * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
12 1.2.6.2 christos * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 1.2.6.2 christos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
14 1.2.6.2 christos * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 1.2.6.2 christos * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 1.2.6.2 christos * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
17 1.2.6.2 christos * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 1.2.6.2 christos */
19 1.2.6.2 christos
20 1.2.6.2 christos /*
21 1.2.6.2 christos * Id: assertions.h,v 1.3 2005/04/27 04:56:17 sra Exp
22 1.2.6.2 christos */
23 1.2.6.2 christos
24 1.2.6.2 christos #ifndef ASSERTIONS_H
25 1.2.6.2 christos #define ASSERTIONS_H 1
26 1.2.6.2 christos
27 1.2.6.2 christos typedef enum {
28 1.2.6.2 christos assert_require, assert_ensure, assert_insist, assert_invariant
29 1.2.6.2 christos } assertion_type;
30 1.2.6.2 christos
31 1.2.6.2 christos typedef void (*assertion_failure_callback)(const char *, int, assertion_type,
32 1.2.6.2 christos const char *, int);
33 1.2.6.2 christos
34 1.2.6.2 christos extern assertion_failure_callback __assertion_failed;
35 1.2.6.2 christos void set_assertion_failure_callback(assertion_failure_callback f);
36 1.2.6.2 christos const char *assertion_type_to_text(assertion_type type);
37 1.2.6.2 christos
38 1.2.6.2 christos #ifdef CHECK_ALL
39 1.2.6.2 christos #define CHECK_REQUIRE 1
40 1.2.6.2 christos #define CHECK_ENSURE 1
41 1.2.6.2 christos #define CHECK_INSIST 1
42 1.2.6.2 christos #define CHECK_INVARIANT 1
43 1.2.6.2 christos #endif
44 1.2.6.2 christos
45 1.2.6.2 christos #ifdef CHECK_NONE
46 1.2.6.2 christos #define CHECK_REQUIRE 0
47 1.2.6.2 christos #define CHECK_ENSURE 0
48 1.2.6.2 christos #define CHECK_INSIST 0
49 1.2.6.2 christos #define CHECK_INVARIANT 0
50 1.2.6.2 christos #endif
51 1.2.6.2 christos
52 1.2.6.2 christos #ifndef CHECK_REQUIRE
53 1.2.6.2 christos #define CHECK_REQUIRE 1
54 1.2.6.2 christos #endif
55 1.2.6.2 christos
56 1.2.6.2 christos #ifndef CHECK_ENSURE
57 1.2.6.2 christos #define CHECK_ENSURE 1
58 1.2.6.2 christos #endif
59 1.2.6.2 christos
60 1.2.6.2 christos #ifndef CHECK_INSIST
61 1.2.6.2 christos #define CHECK_INSIST 1
62 1.2.6.2 christos #endif
63 1.2.6.2 christos
64 1.2.6.2 christos #ifndef CHECK_INVARIANT
65 1.2.6.2 christos #define CHECK_INVARIANT 1
66 1.2.6.2 christos #endif
67 1.2.6.2 christos
68 1.2.6.2 christos #if CHECK_REQUIRE != 0
69 1.2.6.2 christos #define REQUIRE(cond) \
70 1.2.6.2 christos ((void) ((cond) || \
71 1.2.6.2 christos ((__assertion_failed)(__FILE__, __LINE__, assert_require, \
72 1.2.6.2 christos #cond, 0), 0)))
73 1.2.6.2 christos #define REQUIRE_ERR(cond) \
74 1.2.6.2 christos ((void) ((cond) || \
75 1.2.6.2 christos ((__assertion_failed)(__FILE__, __LINE__, assert_require, \
76 1.2.6.2 christos #cond, 1), 0)))
77 1.2.6.2 christos #else
78 1.2.6.2 christos #define REQUIRE(cond) ((void) (cond))
79 1.2.6.2 christos #define REQUIRE_ERR(cond) ((void) (cond))
80 1.2.6.2 christos #endif /* CHECK_REQUIRE */
81 1.2.6.2 christos
82 1.2.6.2 christos #if CHECK_ENSURE != 0
83 1.2.6.2 christos #define ENSURE(cond) \
84 1.2.6.2 christos ((void) ((cond) || \
85 1.2.6.2 christos ((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \
86 1.2.6.2 christos #cond, 0), 0)))
87 1.2.6.2 christos #define ENSURE_ERR(cond) \
88 1.2.6.2 christos ((void) ((cond) || \
89 1.2.6.2 christos ((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \
90 1.2.6.2 christos #cond, 1), 0)))
91 1.2.6.2 christos #else
92 1.2.6.2 christos #define ENSURE(cond) ((void) (cond))
93 1.2.6.2 christos #define ENSURE_ERR(cond) ((void) (cond))
94 1.2.6.2 christos #endif /* CHECK_ENSURE */
95 1.2.6.2 christos
96 1.2.6.2 christos #if CHECK_INSIST != 0
97 1.2.6.2 christos #define INSIST(cond) \
98 1.2.6.2 christos ((void) ((cond) || \
99 1.2.6.2 christos ((__assertion_failed)(__FILE__, __LINE__, assert_insist, \
100 1.2.6.2 christos #cond, 0), 0)))
101 1.2.6.2 christos #define INSIST_ERR(cond) \
102 1.2.6.2 christos ((void) ((cond) || \
103 1.2.6.2 christos ((__assertion_failed)(__FILE__, __LINE__, assert_insist, \
104 1.2.6.2 christos #cond, 1), 0)))
105 1.2.6.2 christos #else
106 1.2.6.2 christos #define INSIST(cond) ((void) (cond))
107 1.2.6.2 christos #define INSIST_ERR(cond) ((void) (cond))
108 1.2.6.2 christos #endif /* CHECK_INSIST */
109 1.2.6.2 christos
110 1.2.6.2 christos #if CHECK_INVARIANT != 0
111 1.2.6.2 christos #define INVARIANT(cond) \
112 1.2.6.2 christos ((void) ((cond) || \
113 1.2.6.2 christos ((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \
114 1.2.6.2 christos #cond, 0), 0)))
115 1.2.6.2 christos #define INVARIANT_ERR(cond) \
116 1.2.6.2 christos ((void) ((cond) || \
117 1.2.6.2 christos ((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \
118 1.2.6.2 christos #cond, 1), 0)))
119 1.2.6.2 christos #else
120 1.2.6.2 christos #define INVARIANT(cond) ((void) (cond))
121 1.2.6.2 christos #define INVARIANT_ERR(cond) ((void) (cond))
122 1.2.6.2 christos #endif /* CHECK_INVARIANT */
123 1.2.6.2 christos #endif /* ASSERTIONS_H */
124 1.2.6.2 christos /*! \file */
125