]> pd.if.org Git - pdclib/blob - functions/_PDCLIB/assert.c
Porting current working set from CVS.
[pdclib] / functions / _PDCLIB / assert.c
1 /* $Id$ */
2
3 /* Release $Name$ */
4
5 /* _PDCLIB_assert( char const * )
6
7    This file is part of the Public Domain C Library (PDCLib).
8    Permission is granted to use, modify, and / or redistribute at will.
9 */
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <assert.h>
14
15 #ifndef REGTEST
16
17 #ifndef _PDCLIB_AUX_H
18 #define _PDCLIB_AUX_H _PDCLIB_AUX_H
19 #include <_PDCLIB_aux.h>
20 #endif
21
22 #if _PDCLIB_C_VERSION == 99
23 void _PDCLIB_assert( char const * const message1, char const * const function, char const * const message2 )
24 {
25     fputs( message1, stderr );
26     fputs( function, stderr );
27     fputs( message2, stderr );
28     abort();
29 }
30 #else
31 void _PDCLIB_assert( char const * const message )
32 {
33     fputs( message, stderr );
34     abort();
35 }
36 #endif
37
38 #endif
39
40 #ifdef TEST
41 #include <_PDCLIB_test.h>
42 #include <signal.h>
43
44 static int EXPECTED_ABORT = 0;
45 static int UNEXPECTED_ABORT = 1;
46
47 static void aborthandler( int sig )
48 {
49     TESTCASE( ! EXPECTED_ABORT );
50     exit( (signed int)rc );
51 }
52
53 #define NDEBUG
54 #include <assert.h>
55
56 static int disabled_test( void )
57 {
58     int i = 0;
59     assert( i == 0 ); /* NDEBUG set, condition met */
60     assert( i == 1 ); /* NDEBUG set, condition fails */
61     return i;
62 }
63
64 #undef NDEBUG
65 #include <assert.h>
66
67 int main( void )
68 {
69     TESTCASE( signal( SIGABRT, &aborthandler ) != SIG_ERR );
70     TESTCASE( disabled_test() == 0 );
71     assert( UNEXPECTED_ABORT ); /* NDEBUG not set, condition met */
72     assert( EXPECTED_ABORT ); /* NDEBUG not set, condition fails - should abort */
73     return TEST_RESULTS;
74 }
75
76 #endif