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