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