Using constants for testfile names
[fw/pdclib] / testing / _PDCLIB_test.h
1 /* $Id$ */
2
3 /* PDCLib testing suite <_PDCLIB_test.h>
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 /* -------------------------------------------------------------------------- */
10 /* Helper macros for test drivers                                             */
11 /* -------------------------------------------------------------------------- */
12
13 #include <stdio.h>
14
15 /* Some strings used for <string.h> and <stdlib.h> testing. */
16 static char const abcde[] = "abcde";
17 static char const abcdx[] = "abcdx";
18 static char const teststring[] = "1234567890\nABCDEFGHIJKLMNOPQRSTUVWXYZ\nabcdefghijklmnopqrstuvwxyz\n";
19
20 /* Temporary file names */
21 static char const testfile[]="testing/testfile";
22 static char const testfile1[]="testing/testfile1";
23 static char const testfile2[]="testing/testfile2";
24
25 #define NO_TESTDRIVER 0
26
27 static int TEST_RESULTS = 0;
28
29 /* TESTCASE() - generic test */
30 #define TESTCASE( x ) if ( x ) {} \
31                       else { TEST_RESULTS += 1; printf( "FAILED: " __FILE__ ", line %d - %s\n", __LINE__, #x ); }
32
33 /* TESTCASE_NOREG() - PDCLib-only test */
34 #ifndef REGTEST
35 #define TESTCASE_NOREG( x ) TESTCASE( x )
36 #else
37 #define TESTCASE_NOREG( x )
38 #endif
39
40 /* ...printf() tests */
41 #if defined( FPRINTF_FUNCTION )
42 static char result_buffer[ 1000 ];
43 #define RESULT_MISMATCH( act, exp ) \
44     rewind( act ), \
45     result_buffer[ fread( result_buffer, 1, strlen( exp ) + 1, act ) ] = '\0', \
46     rewind( act ), \
47     memcmp( result_buffer, exp, strlen( exp ) )
48 #define RESULT_STRING( tgt ) result_buffer
49 #elif defined( SPRINTF_FUNCTION )
50 #define RESULT_MISMATCH( act, exp ) strcmp( act, exp ) != 0
51 #define RESULT_STRING( tgt ) tgt
52 #endif
53
54 #define PRINTF_TEST( expected_rc, expected_string, format, ... ) { \
55         int actual_rc = testprintf( target, format, __VA_ARGS__ ); \
56         if ( ( actual_rc != expected_rc ) || \
57              ( RESULT_MISMATCH( target, expected_string ) ) ) \
58         { \
59             ++TEST_RESULTS; \
60             fprintf( stderr, "FAILED: " __FILE__ " (" _PDCLIB_FILEID "), line %d\n        expected %2d, \"%s\"\n        actual   %2d, \"%s\"\n", __LINE__, expected_rc, expected_string, actual_rc, RESULT_STRING( target ) ); \
61         } \
62     } while ( 0 )
63
64 /* ...scanf() tests */
65 /* TODO: t.b.d. */