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