]> pd.if.org Git - pdclib/blob - functions/_PDCLIB/assert.c
Added 'void' to empty parameter lists.
[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
14 #ifndef _PDCLIB_AUX_H
15 #define _PDCLIB_AUX_H _PDCLIB_AUX_H
16 #include <_PDCLIB_aux.h>
17 #endif
18
19 #if _PDCLIB_C_VERSION == 99
20 void _PDCLIB_assert( char const * const message1, char const * const function, char const * const message2 )
21 {
22     fputs( message1, stderr );
23     fputs( function, stderr );
24     fputs( message2, stderr );
25     abort();
26 }
27 #else
28 void _PDCLIB_assert( char const * const message )
29 {
30     fputs( message, stderr );
31     abort();
32 }
33 #endif
34
35
36 #ifdef TEST
37 #include <_PDCLIB_test.h>
38 #include <signal.h>
39
40 static int rc = 0;
41 static int EXPECTED_ABORT = 0;
42 static int UNEXPECTED_ABORT = 1;
43
44 void aborthandler( int signal )
45 {
46     TESTCASE( ! EXPECTED_ABORT );
47     exit( rc );
48 }
49
50 #define NDEBUG
51 #include <assert.h>
52
53 int disabled_test()
54 {
55     int i = 0;
56     assert( i == 0 ); /* NDEBUG set, condition met */
57     assert( i == 1 ); /* NDEBUG set, condition fails */
58     return i;
59 }
60
61 #undef NDEBUG
62 #include <assert.h>
63
64 int main()
65 {
66     BEGIN_TESTS;
67     TESTCASE( signal( SIGABRT, &aborthandler ) != SIG_ERR );
68     assert( UNEXPECTED_ABORT ); /* NDEBUG not set, condition met */
69     assert( EXPECTED_ABORT ); /* NDEBUG not set, condition fails - should abort */
70     return TEST_RESULTS;
71 }
72
73 #endif