From 2612fba05258dfde899375db0aa88e65c337395d Mon Sep 17 00:00:00 2001 From: solar Date: Wed, 8 Dec 2010 05:53:09 +0000 Subject: [PATCH] Reworked scanf() testing. General cleanups. git-svn-id: https://srv7.svn-repos.de/dev34/pdclib/trunk@481 546481bc-9713-0410-bf18-d3337bbf4a3e --- Makefile | 1 + functions/_PDCLIB/print.c | 8 +- functions/_PDCLIB/scan.c | 26 +- functions/_PDCLIB/stdarg.c | 14 +- functions/stdio/clearerr.c | 1 + functions/stdio/fclose.c | 4 +- functions/stdio/fgetpos.c | 3 +- functions/stdio/fgets.c | 2 +- functions/stdio/fopen.c | 2 +- functions/stdio/fprintf.c | 7 +- functions/stdio/freopen.c | 4 +- functions/stdio/fscanf.c | 12 +- functions/stdio/fseek.c | 3 +- functions/stdio/gets.c | 3 +- functions/stdio/perror.c | 2 +- functions/stdio/printf.c | 7 +- functions/stdio/rename.c | 4 +- functions/stdio/scanf.c | 11 +- functions/stdio/snprintf.c | 8 +- functions/stdio/sprintf.c | 8 +- functions/stdio/sscanf.c | 10 +- functions/stdio/vfprintf.c | 8 +- functions/stdio/vfscanf.c | 13 +- functions/stdio/vprintf.c | 7 +- functions/stdio/vscanf.c | 19 +- functions/stdio/vsnprintf.c | 9 +- functions/stdio/vsprintf.c | 9 +- functions/stdio/vsscanf.c | 11 +- platform/example/functions/stdio/tmpfile.c | 2 + testing/_PDCLIB_test.h | 58 +- testing/fscan_sources.incl | 67 - ...intf_testcases.incl => printf_testcases.h} | 0 testing/scan_test.h | 13 - testing/scanf_testcases.h | 8 + testing/scanf_testcases.incl | 1181 ----------------- testing/sscan_sources.incl | 43 - 36 files changed, 182 insertions(+), 1406 deletions(-) delete mode 100644 testing/fscan_sources.incl rename testing/{printf_testcases.incl => printf_testcases.h} (100%) delete mode 100644 testing/scan_test.h create mode 100644 testing/scanf_testcases.h delete mode 100644 testing/scanf_testcases.incl delete mode 100644 testing/sscan_sources.incl diff --git a/Makefile b/Makefile index 1d90200..bfa74c6 100644 --- a/Makefile +++ b/Makefile @@ -61,6 +61,7 @@ pdclib.a: $(OBJFILES) @echo test: functions/$(FILE) + echo $(TSTDEPFILES) functions/$(FILE) tests: testdrivers diff --git a/functions/_PDCLIB/print.c b/functions/_PDCLIB/print.c index 1f46a99..5027c5f 100644 --- a/functions/_PDCLIB/print.c +++ b/functions/_PDCLIB/print.c @@ -508,11 +508,9 @@ const char * _PDCLIB_print( const char * spec, struct _PDCLIB_status_t * status #ifdef TEST #define _PDCLIB_FILEID "_PDCLIB/print.c" -#define SPRINTF_FUNCTION -#include <_PDCLIB_test.h> +#define _PDCLIB_STRINGIO -#include -#include +#include <_PDCLIB_test.h> static int testprintf( char * buffer, const char * format, ... ) { @@ -543,7 +541,7 @@ static int testprintf( char * buffer, const char * format, ... ) int main( void ) { char target[100]; -#include "printf_testcases.incl" +#include "printf_testcases.h" return TEST_RESULTS; } diff --git a/functions/_PDCLIB/scan.c b/functions/_PDCLIB/scan.c index ce1dac7..b346ffc 100644 --- a/functions/_PDCLIB/scan.c +++ b/functions/_PDCLIB/scan.c @@ -564,14 +564,34 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status ) #ifdef TEST +#define _PDCLIB_FILEID "_PDCLIB/scan.c" +#define _PDCLIB_STRINGIO + #include <_PDCLIB_test.h> -#include +static int testscanf( char const * s, char const * format, ... ) +{ + struct _PDCLIB_status_t status; + status.n = 0; + status.i = 0; + status.s = (char *)s; + status.stream = NULL; + va_start( status.arg, format ); + if ( *(_PDCLIB_scan( format, &status )) != '\0' ) + { + printf( "_PDCLIB_scan() did not return end-of-specifier on '%s'.\n", format ); + ++TEST_RESULTS; + } + va_end( status.arg ); + return status.n; +} + +#define TEST_CONVERSION_ONLY - int main( void ) { - /* Testing covered by fscanf.c */ + char source[100]; +#include "scanf_testcases.h" return TEST_RESULTS; } diff --git a/functions/_PDCLIB/stdarg.c b/functions/_PDCLIB/stdarg.c index e187c76..fb3f4d6 100644 --- a/functions/_PDCLIB/stdarg.c +++ b/functions/_PDCLIB/stdarg.c @@ -27,6 +27,11 @@ enum tag_t TAG_FUNCPTR }; +static int dummy( void ) +{ + return INT_MAX; +} + static int test( enum tag_t s, ... ) { enum tag_t tag = s; @@ -80,7 +85,9 @@ static int test( enum tag_t s, ... ) } case TAG_FUNCPTR: { - TESTCASE( (va_arg( ap, intfunc_t ))() == INT_MAX ); + intfunc_t function; + TESTCASE( ( function = va_arg( ap, intfunc_t ) ) == dummy ); + TESTCASE( function() == INT_MAX ); tag = va_arg( ap, enum tag_t ); break; } @@ -93,11 +100,6 @@ static int test( enum tag_t s, ... ) } } -static int dummy( void ) -{ - return INT_MAX; -} - int main( void ) { int x = INT_MAX; diff --git a/functions/stdio/clearerr.c b/functions/stdio/clearerr.c index af25029..af50f14 100644 --- a/functions/stdio/clearerr.c +++ b/functions/stdio/clearerr.c @@ -28,6 +28,7 @@ int main( void ) TESTCASE( ! ferror( fh ) ); TESTCASE( ! feof( fh ) ); /* Reading from input stream - should provoke error */ + /* FIXME: Apparently glibc disagrees on this assumption. How to provoke error on glibc? */ TESTCASE( fgetc( fh ) == EOF ); TESTCASE( ferror( fh ) ); TESTCASE( ! feof( fh ) ); diff --git a/functions/stdio/fclose.c b/functions/stdio/fclose.c index cfea902..3a25b52 100644 --- a/functions/stdio/fclose.c +++ b/functions/stdio/fclose.c @@ -87,8 +87,8 @@ int main( void ) TESTCASE( _PDCLIB_filelist == file2 ); TESTCASE( fclose( file2 ) == 0 ); TESTCASE( _PDCLIB_filelist == stdin ); - remove( testfile1 ); - remove( testfile2 ); + TESTCASE( remove( testfile1 ) == 0 ); + TESTCASE( remove( testfile2 ) == 0 ); #else puts( " NOTEST fclose() test driver is PDCLib-specific." ); #endif diff --git a/functions/stdio/fgetpos.c b/functions/stdio/fgetpos.c index 7e5fbe7..248fb35 100644 --- a/functions/stdio/fgetpos.c +++ b/functions/stdio/fgetpos.c @@ -28,7 +28,7 @@ int main( void ) { FILE * fh; fpos_t pos1, pos2; - TESTCASE( ( fh = fopen( testfile, "wb+" ) ) != NULL ); + TESTCASE( ( fh = tmpfile() ) != NULL ); TESTCASE( fgetpos( fh, &pos1 ) == 0 ); TESTCASE( fwrite( teststring, 1, strlen( teststring ), fh ) == strlen( teststring ) ); TESTCASE( fgetpos( fh, &pos2 ) == 0 ); @@ -37,7 +37,6 @@ int main( void ) TESTCASE( fsetpos( fh, &pos2 ) == 0 ); TESTCASE( (size_t)ftell( fh ) == strlen( teststring ) ); TESTCASE( fclose( fh ) == 0 ); - remove( testfile ); return TEST_RESULTS; } diff --git a/functions/stdio/fgets.c b/functions/stdio/fgets.c index 1afd79f..7d5801b 100644 --- a/functions/stdio/fgets.c +++ b/functions/stdio/fgets.c @@ -82,7 +82,7 @@ int main( void ) TESTCASE( fgets( buffer, 2, fh ) == NULL ); TESTCASE( feof( fh ) ); TESTCASE( fclose( fh ) == 0 ); - remove( testfile ); + TESTCASE( remove( testfile ) == 0 ); return TEST_RESULTS; } diff --git a/functions/stdio/fopen.c b/functions/stdio/fopen.c index 32a66a1..7c0b81a 100644 --- a/functions/stdio/fopen.c +++ b/functions/stdio/fopen.c @@ -94,7 +94,7 @@ int main( void ) TESTCASE_NOREG( fopen( testfile, "wr" ) == NULL ); /* Undefined mode */ TESTCASE( ( fh = fopen( testfile, "w" ) ) != NULL ); TESTCASE( fclose( fh ) == 0 ); - remove( testfile ); + TESTCASE( remove( testfile ) == 0 ); return TEST_RESULTS; } diff --git a/functions/stdio/fprintf.c b/functions/stdio/fprintf.c index bac19bc..62bff89 100644 --- a/functions/stdio/fprintf.c +++ b/functions/stdio/fprintf.c @@ -25,10 +25,8 @@ int fprintf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, const char * _PDCL #ifdef TEST #define _PDCLIB_FILEID "stdio/fprintf.c" -#define FPRINTF_FUNCTION 1 +#define _PDCLIB_FILEIO -#include -#include #include <_PDCLIB_test.h> #define testprintf( stream, format, ... ) fprintf( stream, format, __VA_ARGS__ ) @@ -37,9 +35,10 @@ int main( void ) { FILE * target; TESTCASE( ( target = tmpfile() ) != NULL ); -#include "printf_testcases.incl" +#include "printf_testcases.h" TESTCASE( fclose( target ) == 0 ); return TEST_RESULTS; } #endif + diff --git a/functions/stdio/freopen.c b/functions/stdio/freopen.c index 2d900fd..682e3c6 100644 --- a/functions/stdio/freopen.c +++ b/functions/stdio/freopen.c @@ -96,8 +96,8 @@ int main( void ) TESTCASE( fclose( fin ) == 0 ); TESTCASE( fclose( fout ) == 0 ); - remove( testfile1 ); - remove( testfile2 ); + TESTCASE( remove( testfile1 ) == 0 ); + TESTCASE( remove( testfile2 ) == 0 ); return TEST_RESULTS; } diff --git a/functions/stdio/fscanf.c b/functions/stdio/fscanf.c index b560448..6c0c70b 100644 --- a/functions/stdio/fscanf.c +++ b/functions/stdio/fscanf.c @@ -24,15 +24,19 @@ int fscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format #endif #ifdef TEST +#define _PDCLIB_FILEID "stdio/fscanf.c" +#define _PDCLIB_FILEIO + #include <_PDCLIB_test.h> -#include "scan_test.h" +#define testscanf( stream, format, ... ) fscanf( stream, format, __VA_ARGS__ ) int main( void ) { -#define SCANFUNC( source, format, ... ) fscanf( source, format, __VA_ARGS__ ) -#include "fscan_sources.incl" -#include "scanf_testcases.incl" + FILE * source; + TESTCASE( ( source = tmpfile() ) != NULL ); +#include "scanf_testcases.h" + TESTCASE( fclose( source ) == 0 ); return TEST_RESULTS; } diff --git a/functions/stdio/fseek.c b/functions/stdio/fseek.c index d74d552..ab6679b 100644 --- a/functions/stdio/fseek.c +++ b/functions/stdio/fseek.c @@ -38,7 +38,7 @@ int fseek( struct _PDCLIB_file_t * stream, long offset, int whence ) int main( void ) { FILE * fh; - TESTCASE( ( fh = fopen( testfile, "wb+" ) ) != NULL ); + TESTCASE( ( fh = tmpfile() ) != NULL ); TESTCASE( fwrite( teststring, 1, strlen( teststring ), fh ) == strlen( teststring ) ); /* General functionality */ TESTCASE( fseek( fh, -1, SEEK_END ) == 0 ); @@ -79,7 +79,6 @@ int main( void ) TESTCASE( fseek( fh, -5, SEEK_SET ) == -1 ); TESTCASE( fseek( fh, 0, SEEK_END ) == 0 ); TESTCASE( fclose( fh ) == 0 ); - remove( testfile ); return TEST_RESULTS; } diff --git a/functions/stdio/gets.c b/functions/stdio/gets.c index 6cefc48..ac93e97 100644 --- a/functions/stdio/gets.c +++ b/functions/stdio/gets.c @@ -63,7 +63,8 @@ int main( void ) TESTCASE( feof( fh ) ); TESTCASE( fseek( fh, 0, SEEK_END ) == 0 ); TESTCASE( gets( buffer ) == NULL ); - // remove( testfile ); + TESTCASE( fclose( fh ) == 0 ); + TESTCASE( remove( testfile ) == 0 ); return TEST_RESULTS; } diff --git a/functions/stdio/perror.c b/functions/stdio/perror.c index fc6ff87..bf3b3af 100644 --- a/functions/stdio/perror.c +++ b/functions/stdio/perror.c @@ -44,7 +44,7 @@ int main( void ) TESTCASE( fread( buffer, 1, 7, fh ) == 7 ); TESTCASE( memcmp( buffer, "Test: ", 6 ) == 0 ); TESTCASE( fclose( fh ) == 0 ); - remove( testfile ); + TESTCASE( remove( testfile ) == 0 ); return TEST_RESULTS; } diff --git a/functions/stdio/printf.c b/functions/stdio/printf.c index aa772ec..23536dd 100644 --- a/functions/stdio/printf.c +++ b/functions/stdio/printf.c @@ -25,9 +25,8 @@ int printf( const char * _PDCLIB_restrict format, ... ) #ifdef TEST #define _PDCLIB_FILEID "stdio/printf.c" -#define FPRINTF_FUNCTION -#include -#include +#define _PDCLIB_FILEIO + #include <_PDCLIB_test.h> #define testprintf( stream, format, ... ) printf( format, __VA_ARGS__ ) @@ -36,7 +35,7 @@ int main( void ) { FILE * target; TESTCASE( ( target = freopen( testfile, "wb+", stdout ) ) != NULL ); -#include "printf_testcases.incl" +#include "printf_testcases.h" TESTCASE( fclose( target ) == 0 ); TESTCASE( remove( testfile ) == 0 ); return TEST_RESULTS; diff --git a/functions/stdio/rename.c b/functions/stdio/rename.c index 409005f..6b1e1b5 100644 --- a/functions/stdio/rename.c +++ b/functions/stdio/rename.c @@ -73,8 +73,8 @@ int main( void ) /* NOREG as glibc overwrites existing destination file. */ TESTCASE_NOREG( rename( testfile1, testfile2 ) == -1 ); /* remove both files */ - remove( testfile1 ); - remove( testfile2 ); + TESTCASE( remove( testfile1 ) == 0 ); + TESTCASE( remove( testfile2 ) == 0 ); /* check that they're gone */ TESTCASE( fopen( testfile1, "r" ) == NULL ); TESTCASE( fopen( testfile2, "r" ) == NULL ); diff --git a/functions/stdio/scanf.c b/functions/stdio/scanf.c index cafdf58..41501bc 100644 --- a/functions/stdio/scanf.c +++ b/functions/stdio/scanf.c @@ -21,11 +21,20 @@ int scanf( const char * _PDCLIB_restrict format, ... ) #endif #ifdef TEST +#define _PDCLIB_FILEID "stdio/scanf.c" +#define _PDCLIB_FILEIO + #include <_PDCLIB_test.h> +#define testscanf( stream, format, ... ) scanf( format, __VA_ARGS__ ) + int main( void ) { - TESTCASE( NO_TESTDRIVER ); + FILE * source; + TESTCASE( ( source = freopen( testfile, "wb+", stdin ) ) != NULL ); +#include "scanf_testcases.h" + TESTCASE( fclose( source ) == 0 ); + TESTCASE( remove( testfile ) == 0 ); return TEST_RESULTS; } diff --git a/functions/stdio/snprintf.c b/functions/stdio/snprintf.c index 4435713..6dd3967 100644 --- a/functions/stdio/snprintf.c +++ b/functions/stdio/snprintf.c @@ -25,18 +25,16 @@ int snprintf( char * _PDCLIB_restrict s, size_t n, const char * _PDCLIB_restrict #ifdef TEST #define _PDCLIB_FILEID "stdio/snprintf.c" -#define SPRINTF_FUNCTION -#include <_PDCLIB_test.h> +#define _PDCLIB_STRINGIO -#include -#include +#include <_PDCLIB_test.h> #define testprintf( s, format, ... ) snprintf( s, 100, format, __VA_ARGS__ ) int main( void ) { char target[100]; -#include "printf_testcases.incl" +#include "printf_testcases.h" return TEST_RESULTS; } diff --git a/functions/stdio/sprintf.c b/functions/stdio/sprintf.c index 1c1d666..887c6fc 100644 --- a/functions/stdio/sprintf.c +++ b/functions/stdio/sprintf.c @@ -26,18 +26,16 @@ int sprintf( char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, .. #ifdef TEST #define _PDCLIB_FILEID "stdio/sprintf.c" -#define SPRINTF_FUNCTION -#include <_PDCLIB_test.h> +#define _PDCLIB_STRINGIO -#include -#include +#include <_PDCLIB_test.h> #define testprintf( s, format, ... ) sprintf( s, format, __VA_ARGS__ ) int main( void ) { char target[100]; -#include "printf_testcases.incl" +#include "printf_testcases.h" return TEST_RESULTS; } diff --git a/functions/stdio/sscanf.c b/functions/stdio/sscanf.c index d40b14e..dc343b8 100644 --- a/functions/stdio/sscanf.c +++ b/functions/stdio/sscanf.c @@ -24,15 +24,17 @@ int sscanf( const char * _PDCLIB_restrict s, const char * _PDCLIB_restrict forma #endif #ifdef TEST +#define _PDCLIB_FILEID "stdio/sscanf.c" +#define _PDCLIB_STRINGIO + #include <_PDCLIB_test.h> -#include "scan_test.h" +#define testscanf( s, format, ... ) sscanf( s, format, __VA_ARGS__ ) int main() { -#define SCANFUNC( source, format, ... ) sscanf( source, format, __VA_ARGS__ ) -#include "sscan_sources.incl" -#include "scanf_testcases.incl" + char source[100]; +#include "scanf_testcases.h" return TEST_RESULTS; } diff --git a/functions/stdio/vfprintf.c b/functions/stdio/vfprintf.c index 44c8635..cc6e7a6 100644 --- a/functions/stdio/vfprintf.c +++ b/functions/stdio/vfprintf.c @@ -50,10 +50,8 @@ int vfprintf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, const char * _PDC #ifdef TEST #define _PDCLIB_FILEID "stdio/vfprintf.c" -#define FPRINTF_FUNCTION -#include -#include -#include +#define _PDCLIB_FILEIO + #include <_PDCLIB_test.h> static int testprintf( FILE * stream, const char * format, ... ) @@ -70,7 +68,7 @@ int main( void ) { FILE * target; TESTCASE( ( target = tmpfile() ) != NULL ); -#include "printf_testcases.incl" +#include "printf_testcases.h" TESTCASE( fclose( target ) == 0 ); return TEST_RESULTS; } diff --git a/functions/stdio/vfscanf.c b/functions/stdio/vfscanf.c index e1c8b4b..fbf5356 100644 --- a/functions/stdio/vfscanf.c +++ b/functions/stdio/vfscanf.c @@ -88,11 +88,12 @@ int vfscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict forma #endif #ifdef TEST -#include <_PDCLIB_test.h> +#define _PDCLIB_FILEID "stdio/vfscanf.c" +#define _PDCLIB_FILEIO -#include "scan_test.h" +#include <_PDCLIB_test.h> -static int SCANFUNC( FILE * stream, char const * format, ... ) +static int testscanf( FILE * stream, char const * format, ... ) { va_list ap; va_start( ap, format ); @@ -103,8 +104,10 @@ static int SCANFUNC( FILE * stream, char const * format, ... ) int main( void ) { -#include "fscan_sources.incl" -#include "scanf_testcases.incl" + FILE * source; + TESTCASE( ( source = tmpfile() ) != NULL ); +#include "scanf_testcases.h" + TESTCASE( fclose( source ) == 0 ); return TEST_RESULTS; } diff --git a/functions/stdio/vprintf.c b/functions/stdio/vprintf.c index 4cb5af3..48ad557 100644 --- a/functions/stdio/vprintf.c +++ b/functions/stdio/vprintf.c @@ -20,9 +20,8 @@ int vprintf( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ) #ifdef TEST #define _PDCLIB_FILEID "stdio/vprintf.c" -#define FPRINTF_FUNCTION -#include -#include +#define _PDCLIB_FILEIO + #include <_PDCLIB_test.h> static int testprintf( FILE * stream, const char * format, ... ) @@ -39,7 +38,7 @@ int main( void ) { FILE * target; TESTCASE( ( target = freopen( testfile, "wb+", stdout ) ) != NULL ); -#include "printf_testcases.incl" +#include "printf_testcases.h" TESTCASE( fclose( target ) == 0 ); TESTCASE( remove( testfile ) == 0 ); return TEST_RESULTS; diff --git a/functions/stdio/vscanf.c b/functions/stdio/vscanf.c index d81d523..0b9189d 100644 --- a/functions/stdio/vscanf.c +++ b/functions/stdio/vscanf.c @@ -19,11 +19,28 @@ int vscanf( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ) #endif #ifdef TEST +#define _PDCLIB_FILEID "stdio/vscanf.c" +#define _PDCLIB_FILEIO + #include <_PDCLIB_test.h> +static int testscanf( FILE * stream, const char * format, ... ) +{ + int i; + va_list arg; + va_start( arg, format ); + i = vscanf( format, arg ); + va_end( arg ); + return i; +} + int main( void ) { - /* Simple wrapper to vfscanf(), no seperate testing. */ + FILE * source; + TESTCASE( ( source = freopen( testfile, "wb+", stdin ) ) != NULL ); +#include "scanf_testcases.h" + TESTCASE( fclose( source ) == 0 ); + TESTCASE( remove( testfile ) == 0 ); return TEST_RESULTS; } diff --git a/functions/stdio/vsnprintf.c b/functions/stdio/vsnprintf.c index 9c0258c..9eb869e 100644 --- a/functions/stdio/vsnprintf.c +++ b/functions/stdio/vsnprintf.c @@ -49,12 +49,9 @@ int vsnprintf( char * _PDCLIB_restrict s, size_t n, const char * _PDCLIB_restric #ifdef TEST #define _PDCLIB_FILEID "stdio/vsnprintf.c" -#define SPRINTF_FUNCTION -#include <_PDCLIB_test.h> +#define _PDCLIB_STRINGIO -#include -#include -#include +#include <_PDCLIB_test.h> static int testprintf( char * s, const char * format, ... ) { @@ -69,7 +66,7 @@ static int testprintf( char * s, const char * format, ... ) int main( void ) { char target[100]; -#include "printf_testcases.incl" +#include "printf_testcases.h" return TEST_RESULTS; } diff --git a/functions/stdio/vsprintf.c b/functions/stdio/vsprintf.c index 7515a6f..3dfe3c2 100644 --- a/functions/stdio/vsprintf.c +++ b/functions/stdio/vsprintf.c @@ -21,12 +21,9 @@ int vsprintf( char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, v #ifdef TEST #define _PDCLIB_FILEID "stdio/vsprintf.c" -#define SPRINTF_FUNCTION -#include <_PDCLIB_test.h> +#define _PDCLIB_STRINGIO -#include -#include -#include +#include <_PDCLIB_test.h> static int testprintf( char * s, const char * format, ... ) { @@ -41,7 +38,7 @@ static int testprintf( char * s, const char * format, ... ) int main( void ) { char target[100]; -#include "printf_testcases.incl" +#include "printf_testcases.h" return TEST_RESULTS; } diff --git a/functions/stdio/vsscanf.c b/functions/stdio/vsscanf.c index be9bf61..4300a3e 100644 --- a/functions/stdio/vsscanf.c +++ b/functions/stdio/vsscanf.c @@ -86,11 +86,12 @@ int vsscanf( const char * _PDCLIB_restrict s, const char * _PDCLIB_restrict form #endif #ifdef TEST -#include <_PDCLIB_test.h> +#define _PDCLIB_FILEID "stdio/vsscanf.c" +#define _PDCLIB_STRINGIO -#include "scan_test.h" +#include <_PDCLIB_test.h> -static int SCANFUNC( char const * stream, char const * format, ... ) +static int testscanf( char const * stream, char const * format, ... ) { va_list ap; va_start( ap, format ); @@ -101,8 +102,8 @@ static int SCANFUNC( char const * stream, char const * format, ... ) int main( void ) { -#include "sscan_sources.incl" -#include "scanf_testcases.incl" + char source[100]; +#include "scanf_testcases.h" return TEST_RESULTS; } diff --git a/platform/example/functions/stdio/tmpfile.c b/platform/example/functions/stdio/tmpfile.c index b2c099b..b778f3f 100644 --- a/platform/example/functions/stdio/tmpfile.c +++ b/platform/example/functions/stdio/tmpfile.c @@ -94,8 +94,10 @@ struct _PDCLIB_file_t * tmpfile( void ) int main() { FILE * fh; +#ifndef REGTEST char filename[ L_tmpnam ]; FILE * fhtest; +#endif TESTCASE( ( fh = tmpfile() ) != NULL ); TESTCASE( fputc( 'x', fh ) == 'x' ); /* Checking that file is actually there */ diff --git a/testing/_PDCLIB_test.h b/testing/_PDCLIB_test.h index aacd704..e6c0c75 100644 --- a/testing/_PDCLIB_test.h +++ b/testing/_PDCLIB_test.h @@ -11,6 +11,8 @@ /* -------------------------------------------------------------------------- */ #include +#include +#include /* Some strings used for and testing. */ static char const abcde[] = "abcde"; @@ -32,26 +34,32 @@ static int TEST_RESULTS = 0; /* TESTCASE_NOREG() - PDCLib-only test */ #ifndef REGTEST -#define TESTCASE_NOREG( x ) TESTCASE( x ) + #define TESTCASE_NOREG( x ) TESTCASE( x ) #else -#define TESTCASE_NOREG( x ) + #define TESTCASE_NOREG( x ) #endif /* ...printf() tests */ -#if defined( FPRINTF_FUNCTION ) -static char result_buffer[ 1000 ]; -#define RESULT_MISMATCH( act, exp ) \ - rewind( act ), \ - result_buffer[ fread( result_buffer, 1, strlen( exp ) + 1, act ) ] = '\0', \ - rewind( act ), \ - memcmp( result_buffer, exp, strlen( exp ) ) -#define RESULT_STRING( tgt ) result_buffer -#elif defined( SPRINTF_FUNCTION ) -#define RESULT_MISMATCH( act, exp ) strcmp( act, exp ) != 0 -#define RESULT_STRING( tgt ) tgt +#if defined( _PDCLIB_FILEIO ) + #define RESULT_MISMATCH( act, exp ) \ + rewind( act ), \ + result_buffer[ fread( result_buffer, 1, strlen( exp ) + 1, act ) ] = '\0', \ + rewind( act ), \ + memcmp( result_buffer, exp, strlen( exp ) ) + #define RESULT_STRING( tgt ) result_buffer +#elif defined( _PDCLIB_STRINGIO ) + #define RESULT_MISMATCH( act, exp ) strcmp( act, exp ) != 0 + #define RESULT_STRING( tgt ) tgt #endif -#define PRINTF_TEST( expected_rc, expected_string, format, ... ) { \ +#ifdef _PDCLIB_FILEIO +#define PREP_RESULT_BUFFER char result_buffer[100]; +#else +#define PREP_RESULT_BUFFER +#endif + +#define PRINTF_TEST( expected_rc, expected_string, format, ... ) do { \ + PREP_RESULT_BUFFER \ int actual_rc = testprintf( target, format, __VA_ARGS__ ); \ if ( ( actual_rc != expected_rc ) || \ ( RESULT_MISMATCH( target, expected_string ) ) ) \ @@ -62,4 +70,24 @@ static char result_buffer[ 1000 ]; } while ( 0 ) /* ...scanf() tests */ -/* TODO: t.b.d. */ +#if defined( _PDCLIB_FILEIO ) + #define PREPARE_SOURCE( input_string ) \ + rewind( source ); \ + fwrite( input_string, 1, sizeof( input_string ), source ); \ + rewind( source ); +#elif defined( _PDCLIB_STRINGIO ) + #define PREPARE_SOURCE( input_string ) \ + memcpy( source, input_string, sizeof( input_string ) ); +#endif + +#define SCANF_TEST( expected_rc, input_string, format, ... ) do { \ + int actual_rc; \ + PREPARE_SOURCE( input_string ); \ + actual_rc = testscanf( source, format, __VA_ARGS__ ); \ + if ( actual_rc != expected_rc ) \ + { \ + ++TEST_RESULTS; \ + fprintf( stderr, "FAILED: " __FILE__ " (" _PDCLIB_FILEID "), line %d\n expected %2d, actual %2d\n", __LINE__, expected_rc, actual_rc ); \ + } \ + } while ( 0 ) + diff --git a/testing/fscan_sources.incl b/testing/fscan_sources.incl deleted file mode 100644 index 243a17d..0000000 --- a/testing/fscan_sources.incl +++ /dev/null @@ -1,67 +0,0 @@ - FILE * general = fopen( "testing/scanf_testdata_general", "wb+" ); - TESTCASE( general != NULL ); - TESTCASE( fwrite( "12345678901\0003-5+7\0009\3772 4 6 8 0\3771 \011 5%% 0", 1, 40, general ) == 40 ); - rewind( general ); - - FILE * decimal = fopen( "testing/scanf_testdata_decimal", "wb+" ); - TESTCASE( decimal != NULL ); - TESTCASE( fwrite( "-0 +0 -128 +127 +255 -32768 +32767 +65535\n" - "-2147483648 +2147483647 +4294967295\n" - "-9223372036854775808 +9223372036854775807\n" - "+18446744073709551615\n", 1, 142, decimal ) == 142 ); - rewind( decimal ); - - FILE * hexadecimal = fopen( "testing/scanf_testdata_hexadecimal", "wb+" ); - TESTCASE( hexadecimal != NULL ); - TESTCASE( fwrite( "-0x0 -0x000 -0x7f -0x80 0xff -0x7fff -0x8000\n" - "0xffff -0x7fffffff -0x80000000 0xffffffff\n" - "-0x7fffffffffffffff -0x8000000000000000\n" - "0xffffffffffffffff\n", 1, 146, hexadecimal ) == 146 ); - rewind( hexadecimal ); - - FILE * octal = fopen( "testing/scanf_testdata_octal", "wb+" ); - TESTCASE( octal != NULL ); - TESTCASE( fwrite( "+0000 -0000 +0177 +0377 -0377 +077777 +0177777\n" - "-0177777 +017777777777 +037777777777\n" - "-037777777777 +0777777777777777777777\n" - "+01777777777777777777777\n" - "-01777777777777777777777\n", 1, 172, octal ) == 172 ); - rewind( octal ); - - FILE * alpha = fopen( "testing/scanf_testdata_alpha", "wb+" ); - TESTCASE( alpha != NULL ); - TESTCASE( fwrite( "abcdefgh-ijklmnop[qrs%uvw]xyz", 1, 29, alpha ) == 29 ); - rewind( alpha ); - -#ifndef REGTEST - FILE * special = fopen( "testing/scanf_testdata_special", "wb+" ); - TESTCASE( special != NULL ); - TESTCASE( fwrite( "-0xz\n", 1, 5, special ) == 5 ); - rewind( special ); -#endif - - -/* fscan */ -#define TESTSCAN( result, count, source, offset, ... ) \ - do \ - { \ - int n = -1; \ - TESTCASE( fseek( source, offset, SEEK_SET ) == 0 ); \ - int res = SCANFUNC( source, __VA_ARGS__ ); \ - if ( res != result ) \ - { \ - TEST_RESULTS += 1; \ - printf( "FAILED: " __FILE__ ", line %d - expected result %d, got %d\n", __LINE__, result, res ); \ - } \ - if ( n != count ) \ - { \ - TEST_RESULTS += 1; \ - printf( "FAILED: " __FILE__ ", line %d - expected count %d, got %d\n", __LINE__, count, n ); \ - } \ - } while ( 0 ) - -#define SCAN( format ) format "%n", &n -#define SCANPARMS( format, ... ) format "%n", __VA_ARGS__, &n - -#define _PDCLIB_FSCAN - diff --git a/testing/printf_testcases.incl b/testing/printf_testcases.h similarity index 100% rename from testing/printf_testcases.incl rename to testing/printf_testcases.h diff --git a/testing/scan_test.h b/testing/scan_test.h deleted file mode 100644 index 85d471b..0000000 --- a/testing/scan_test.h +++ /dev/null @@ -1,13 +0,0 @@ -/* $Id$ */ - -/* scan test header - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#define CHECK_FEQUAL( a, b, T, F ) do { T x = a; T y = b; TESTCASE( x == y ); } while ( 0 ) - diff --git a/testing/scanf_testcases.h b/testing/scanf_testcases.h new file mode 100644 index 0000000..4cb662e --- /dev/null +++ b/testing/scanf_testcases.h @@ -0,0 +1,8 @@ +{ + char buffer[100]; +#ifndef TEST_CONVERSION_ONLY + SCANF_TEST( 0, "foo", "foo", NULL ); +#endif + SCANF_TEST( 1, "foo", "%3c", buffer ); + TESTCASE( memcmp( buffer, "foo", 3 ) == 0 ); +} diff --git a/testing/scanf_testcases.incl b/testing/scanf_testcases.incl deleted file mode 100644 index b7d7646..0000000 --- a/testing/scanf_testcases.incl +++ /dev/null @@ -1,1181 +0,0 @@ - // ----------------------------------------------------------------------- - // Literal matching - // ----------------------------------------------------------------------- - { - // matching six characters literally - // should report six characters read - TESTSCAN( 0, 6, general, 0, SCAN( "123456" ) ); - } - { - // matching a character, three whitespace chars, and another character - // should report five characters read - TESTSCAN( 0, 5, general, 30, SCAN( "1 5" ) ); - } - { - // matching three characters, not matching whitespaces, and matching another three characters - // should report six characters matched - TESTSCAN( 0, 6, general, 0, SCAN( "123 456" ) ); - } - { - // matching a character, two '%' characters, and two whitespaces - // should report five characters matched - TESTSCAN( 0, 5, general, 34, SCAN( "5%%%% " ) ); - } - { - // seeking to last character in file, trying to match that char and a whitespace - // should report one character matched and EOF - TESTSCAN( 0, 1, general, 39, SCAN( "0 " ) ); - } - { - // seeking to end of file, trying to match a -1 - // should report error, not executing %n - TESTSCAN( -1, -1, general, 40, SCAN( "\377" ) ); /* FIXME */ - } - - // ----------------------------------------------------------------------- - // Character matching ('%c') - // ----------------------------------------------------------------------- - { - // reading a char array of specified width, including zero bytes - // should report the characters read up to first zero - char buffer[ 8 ]; -#ifdef _PDCLIB_SSCAN - int count = 1; - char expected[] = "1\177\177\177\177\177\177\177"; -#else - int count = 7; - char expected[] = "1\0003-5+7"; -#endif - memset( buffer, '\177', 8 ); - TESTSCAN( 1, count, general, 10, SCANPARMS( "%7c", buffer ) ); - TESTCASE( memcmp( buffer, expected, 7 ) == 0 ); - } - { - // reading a char array of unspecified width when positioned at -1 value - // should default to width one, read the -1 value, no zero termination of the array - char buffer[ 2 ]; - memset( buffer, '\177', 2 ); - TESTSCAN( 1, 1, general, 19, SCANPARMS( "%c", buffer ) ); - TESTCASE( memcmp( buffer, "\377\177", 2 ) == 0 ); - } - { - // reading a char array of specified width 1 when positioned at (non-space) whitespace - // should read the whitespace (literally), no zero termination of the array - char buffer[ 2 ]; - memset( buffer, '\177', 2 ); - TESTSCAN( 1, 1, general, 32, SCANPARMS( "%1c", buffer ) ); - TESTCASE( memcmp( buffer, "\011\177", 2 ) == 0 ); - } - { - // reading a char array of specified width 2 when positioned at last char of file - // should read the character, and report EOF - char buffer[ 2 ]; - memset( buffer, '\177', 2 ); - TESTSCAN( 1, 1, general, 39, SCANPARMS( "%2c", buffer ) ); - TESTCASE( memcmp( buffer, "0\177", 2 ) == 0 ); - } - { - // reading a char array of specified width 1 when positioned at last char of file - // should read the character, and NOT report EOF - char buffer[ 2 ]; - memset( buffer, '\177', 2 ); - TESTSCAN( 1, 1, general, 39, SCANPARMS( "%1c", buffer ) ); - TESTCASE( memcmp( buffer, "0\177", 2 ) == 0 ); - } - { - // reading a char array of specified width 1 when positioned at EOF - // should report input error before any conversion (-1) - char buffer[ 2 ]; - memset( buffer, '\177', 2 ); - TESTSCAN( -1, -1, general, 40, SCANPARMS( "%1c", buffer ) ); - TESTCASE( memcmp( buffer, "\177\177", 2 ) == 0 ); - } - - // ----------------------------------------------------------------------- - // Integer matching ('%d') - // ----------------------------------------------------------------------- - { - // reading a whitespace-terminated integer - int i; - TESTSCAN( 1, 1, general, 20, SCANPARMS( "%d", &i ) ); - TESTCASE( i == 2 ); - } - { - // reading a -1 terminated integer - int i; - TESTSCAN( 1, 1, general, 18, SCANPARMS( "%d", &i ) ); - TESTCASE( i == 9 ); - } - { - // reading a EOF terminated integer - int i = -1; - TESTSCAN( 1, 1, general, 39, SCANPARMS( "%d", &i ) ); - TESTCASE( i == 0 ); - } - { - // trying to read an integer when positioned at whitespace - // should skip whitespaces - int i = -1; - TESTSCAN( 1, 3, general, 32, SCANPARMS( "%d", &i ) ); - TESTCASE( i == 5 ); - } - { - // trying to read an integer when positioned at -1 value - // should report matching failure - int i = 0; - TESTSCAN( 0, -1, general, 19, SCANPARMS( "%d", &i ) ); - TESTCASE( i == 0 ); - } - { - // trying to read an integer when positioned at EOF - // should report reading failure - int i = 0; - TESTSCAN( -1, -1, general, 40, SCANPARMS( "%d", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading a '-'-prefixed integer - int i; - TESTSCAN( 1, 2, general, 13, SCANPARMS( "%d", &i ) ); - TESTCASE( i == -5 ); - } - { - // reading a '+'-prefixed integer - int i; - TESTSCAN( 1, 2, general, 15, SCANPARMS( "%d", &i ) ); - TESTCASE( i == 7 ); - } - - // decimal integer matches - { - // reading 0, d - signed char i = -1; - TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%hhd", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading -0, d - signed char i = -1; - TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%hhd", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading +0, d - signed char i = -1; - TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%hhd", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading -128, d - signed char i = -1; - TESTSCAN( 1, 4, decimal, 6, SCANPARMS( "%hhd", &i ) ); - TESTCASE( i == -128 ); - } - { - // reading 127, d - signed char i = -1; - TESTSCAN( 1, 3, decimal, 12, SCANPARMS( "%hhd", &i ) ); - TESTCASE( i == 127 ); - } - { - // reading +127, d - signed char i = -1; - TESTSCAN( 1, 4, decimal, 11, SCANPARMS( "%hhd", &i ) ); - TESTCASE( i == 127 ); - } - { - // reading 0, u - unsigned char i = -1; - TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%hhu", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading -0, u - unsigned char i = -1; - TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%hhu", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading +0, u - unsigned char i = -1; - TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%hhu", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading 127, u - unsigned char i = -1; - TESTSCAN( 1, 3, decimal, 12, SCANPARMS( "%hhu", &i ) ); - TESTCASE( i == 127 ); - } - { - // reading +127, u - unsigned char i = -1; - TESTSCAN( 1, 4, decimal, 11, SCANPARMS( "%hhu", &i ) ); - TESTCASE( i == 127 ); - } - { - // reading 255, u - unsigned char i = 0; - TESTSCAN( 1, 3, decimal, 17, SCANPARMS( "%hhu", &i ) ); - TESTCASE( i == 255 ); - } - { - // reading +255, u - unsigned char i = 0; - TESTSCAN( 1, 4, decimal, 16, SCANPARMS( "%hhu", &i ) ); - TESTCASE( i == 255 ); - } - { - // reading 0, i - signed char i = -1; - TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%hhi", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading -0, i - signed char i = -1; - TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%hhi", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading +0, i - signed char i = -1; - TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%hhi", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading -128, i - signed char i = -1; - TESTSCAN( 1, 4, decimal, 6, SCANPARMS( "%hhi", &i ) ); - TESTCASE( i == -128 ); - } - { - // reading 127, i - signed char i = -1; - TESTSCAN( 1, 3, decimal, 12, SCANPARMS( "%hhi", &i ) ); - TESTCASE( i == 127 ); - } - { - // reading +127, i - signed char i = -1; - TESTSCAN( 1, 4, decimal, 11, SCANPARMS( "%hhi", &i ) ); - TESTCASE( i == 127 ); - } - { - // reading 0, d - signed short i = -1; - TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%hd", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading -0, d - signed short i = -1; - TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%hd", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading +0, d - signed short i = -1; - TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%hd", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading -32768, d - signed short i = -1; - TESTSCAN( 1, 6, decimal, 21, SCANPARMS( "%hd", &i ) ); - TESTCASE( i == -32768 ); - } - { - // reading 32767, d - signed short i = -1; - TESTSCAN( 1, 5, decimal, 29, SCANPARMS( "%hd", &i ) ); - TESTCASE( i == 32767 ); - } - { - // reading +32767, d - signed short i = -1; - TESTSCAN( 1, 6, decimal, 28, SCANPARMS( "%hd", &i ) ); - TESTCASE( i == 32767 ); - } - { - // reading 0, u - unsigned short i = -1; - TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%hu", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading -0, u - unsigned short i = -1; - TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%hu", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading +0, u - unsigned short i = -1; - TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%hu", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading 32767, u - unsigned short i = -1; - TESTSCAN( 1, 5, decimal, 29, SCANPARMS( "%hu", &i ) ); - TESTCASE( i == 32767 ); - } - { - // reading +32767, u - unsigned short i = -1; - TESTSCAN( 1, 6, decimal, 28, SCANPARMS( "%hu", &i ) ); - TESTCASE( i == 32767 ); - } - { - // reading 65535, u - unsigned short i = 0; - TESTSCAN( 1, 5, decimal, 36, SCANPARMS( "%hu", &i ) ); - TESTCASE( i == 65535 ); - } - { - // reading +65535, u - unsigned short i = 0; - TESTSCAN( 1, 6, decimal, 35, SCANPARMS( "%hu", &i ) ); - TESTCASE( i == 65535 ); - } - { - // reading 0, i - signed short i = -1; - TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%hi", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading -0, i - signed short i = -1; - TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%hi", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading +0, i - signed short i = -1; - TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%hi", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading -32768, i - signed short i = -1; - TESTSCAN( 1, 6, decimal, 21, SCANPARMS( "%hi", &i ) ); - TESTCASE( i == -32768 ); - } - { - // reading 32767, i - signed short i = -1; - TESTSCAN( 1, 5, decimal, 29, SCANPARMS( "%hi", &i ) ); - TESTCASE( i == 32767 ); - } - { - // reading +32767, i - signed short i = -1; - TESTSCAN( 1, 6, decimal, 28, SCANPARMS( "%hi", &i ) ); - TESTCASE( i == 32767 ); - } - { - // reading 0, d - signed int i = -1; - TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%d", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading -0, d - signed int i = -1; - TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%d", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading +0, d - signed int i = -1; - TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%d", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading -2147483648, d - signed int i = -1; - TESTSCAN( 1, 11, decimal, 42, SCANPARMS( "%d", &i ) ); - TESTCASE( i == -2147483648 ); - } - { - // reading 2147483647, d - signed int i = -1; - TESTSCAN( 1, 10, decimal, 55, SCANPARMS( "%d", &i ) ); - TESTCASE( i == 2147483647 ); - } - { - // reading +2147483647, d - signed int i = -1; - TESTSCAN( 1, 11, decimal, 54, SCANPARMS( "%d", &i ) ); - TESTCASE( i == 2147483647 ); - } - { - // reading 0, u - unsigned int i = -1; - TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%u", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading -0, u - unsigned int i = -1; - TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%u", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading +0, u - unsigned int i = -1; - TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%u", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading 2147483647, u - unsigned int i = -1; - TESTSCAN( 1, 10, decimal, 55, SCANPARMS( "%u", &i ) ); - TESTCASE( i == 2147483647 ); - } - { - // reading +2147483647, u - unsigned int i = -1; - TESTSCAN( 1, 11, decimal, 54, SCANPARMS( "%u", &i ) ); - TESTCASE( i == 2147483647 ); - } - { - // reading 4294967295, u - unsigned int i = 0; - TESTSCAN( 1, 10, decimal, 67, SCANPARMS( "%u", &i ) ); - CHECK_FEQUAL( i, 4294967295, unsigned int, "%u" ); - } - { - // reading +4294967295, u - unsigned int i = 0; - TESTSCAN( 1, 11, decimal, 66, SCANPARMS( "%u", &i ) ); - CHECK_FEQUAL( i, 4294967295, unsigned int, "%u" ); - } - { - // reading 0, i - signed int i = -1; - TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%i", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading -0, i - signed int i = -1; - TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%i", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading +0, i - signed int i = -1; - TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%i", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading -2147483648, i - signed int i = -1; - TESTSCAN( 1, 11, decimal, 42, SCANPARMS( "%i", &i ) ); - TESTCASE( i == -2147483648 ); - } - { - // reading 2147483647, i - signed int i = -1; - TESTSCAN( 1, 10, decimal, 55, SCANPARMS( "%i", &i ) ); - TESTCASE( i == 2147483647 ); - } - { - // reading +2147483647, i - signed int i = -1; - TESTSCAN( 1, 11, decimal, 54, SCANPARMS( "%i", &i ) ); - TESTCASE( i == 2147483647 ); - } - { - // reading 0, d - signed long i = -1; - TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%ld", &i ) ); - TESTCASE( i == 0l ); - } - { - // reading -0, d - signed long i = -1; - TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%ld", &i ) ); - TESTCASE( i == 0l ); - } - { - // reading +0, d - signed long i = -1; - TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%ld", &i ) ); - TESTCASE( i == 0l ); - } - { - // reading -2147483648, d - signed long i = -1; - TESTSCAN( 1, 11, decimal, 42, SCANPARMS( "%ld", &i ) ); - TESTCASE( i == -2147483648l ); - } - { - // reading 2147483647, d - signed long i = -1; - TESTSCAN( 1, 10, decimal, 55, SCANPARMS( "%ld", &i ) ); - TESTCASE( i == 2147483647l ); - } - { - // reading +2147483647, d - signed long i = -1; - TESTSCAN( 1, 11, decimal, 54, SCANPARMS( "%ld", &i ) ); - TESTCASE( i == 2147483647l ); - } - { - // reading 0, u - unsigned long i = -1; - TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%lu", &i ) ); - TESTCASE( i == 0ul ); - } - { - // reading -0, u - unsigned long i = -1; - TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%lu", &i ) ); - TESTCASE( i == 0ul ); - } - { - // reading +0, u - unsigned long i = -1; - TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%lu", &i ) ); - TESTCASE( i == 0ul ); - } - { - // reading 2147483647, u - unsigned long i = -1; - TESTSCAN( 1, 10, decimal, 55, SCANPARMS( "%lu", &i ) ); - TESTCASE( i == 2147483647ul ); - } - { - // reading +2147483647, u - unsigned long i = -1; - TESTSCAN( 1, 11, decimal, 54, SCANPARMS( "%lu", &i ) ); - TESTCASE( i == 2147483647ul ); - } - { - // reading 4294967295, u - unsigned long i = 0; - TESTSCAN( 1, 10, decimal, 67, SCANPARMS( "%lu", &i ) ); - CHECK_FEQUAL( i, 4294967295ul, unsigned long, "%lu" ); - } - { - // reading +4294967295, u - unsigned long i = 0; - TESTSCAN( 1, 11, decimal, 66, SCANPARMS( "%lu", &i ) ); - CHECK_FEQUAL( i, 4294967295ul, unsigned long, "%lu" ); - } - { - // reading 0, i - signed long i = -1; - TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%li", &i ) ); - TESTCASE( i == 0l ); - } - { - // reading -0, i - signed long i = -1; - TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%li", &i ) ); - TESTCASE( i == 0l ); - } - { - // reading +0, i - signed long i = -1; - TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%li", &i ) ); - TESTCASE( i == 0l ); - } - { - // reading -2147483648, i - signed long i = -1; - TESTSCAN( 1, 11, decimal, 42, SCANPARMS( "%li", &i ) ); - TESTCASE( i == -2147483648l ); - } - { - // reading 2147483647, i - signed long i = -1; - TESTSCAN( 1, 10, decimal, 55, SCANPARMS( "%li", &i ) ); - TESTCASE( i == 2147483647l ); - } - { - // reading +2147483647, i - signed long i = -1; - TESTSCAN( 1, 11, decimal, 54, SCANPARMS( "%li", &i ) ); - TESTCASE( i == 2147483647l ); - } - { - // reading 0, d - signed long long i = -1; - TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%lld", &i ) ); - TESTCASE( i == 0ll ); - } - { - // reading -0, d - signed long long i = -1; - TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%lld", &i ) ); - TESTCASE( i == 0ll ); - } - { - // reading +0, d - signed long long i = -1; - TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%lld", &i ) ); - TESTCASE( i == 0ll ); - } - { - // reading -9223372036854775808, d - signed long long i = -1; - TESTSCAN( 1, 20, decimal, 78, SCANPARMS( "%lli", &i ) ); - CHECK_FEQUAL( i, LLONG_MIN, signed long long, "%lli" ); // should be literal -9223372036854775808ll but GCC balks. - TESTCASE( i < 0ll ); - } - { - // reading +9223372036854775807, d - signed long long i = -1; - TESTSCAN( 1, 20, decimal, 99, SCANPARMS( "%lld", &i ) ); - CHECK_FEQUAL( i, 9223372036854775807ll, signed long long, "%lld" ); - } - { - // reading 0, u - unsigned long long i = -1; - TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%llu", &i ) ); - TESTCASE( i == 0ull ); - } - { - // reading -0, u - unsigned long long i = -1; - TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%llu", &i ) ); - TESTCASE( i == 0ull ); - } - { - // reading +0, u - unsigned long long i = -1; - TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%llu", &i ) ); - TESTCASE( i == 0ull ); - } - { - // reading 9223372036854775807, u - unsigned long long i = -1; - TESTSCAN( 1, 19, decimal, 100, SCANPARMS( "%llu", &i ) ); - CHECK_FEQUAL( i, 9223372036854775807ull, unsigned long long, "%llu" ); - } - { - // reading +9223372036854775807, u - unsigned long long i = -1; - TESTSCAN( 1, 20, decimal, 99, SCANPARMS( "%llu", &i ) ); - CHECK_FEQUAL( i, 9223372036854775807ull, unsigned long long, "%llu" ); - } - { - // reading 18446744073709551615, u - unsigned long long i = 0; - TESTSCAN( 1, 20, decimal, 121, SCANPARMS( "%llu", &i ) ); - CHECK_FEQUAL( i, 18446744073709551615ull, unsigned long long, "%llu" ); - } - { - // reading +18446744073709551615, u - unsigned long long i = 0; - TESTSCAN( 1, 21, decimal, 120, SCANPARMS( "%llu", &i ) ); - CHECK_FEQUAL( i, 18446744073709551615ull, unsigned long long, "%llu" ); - } - { - // reading 0, i - signed long long i = -1; - TESTSCAN( 1, 1, decimal, 1, SCANPARMS( "%lli", &i ) ); - TESTCASE( i == 0ll ); - } - { - // reading -0, i - signed long long i = -1; - TESTSCAN( 1, 2, decimal, 0, SCANPARMS( "%lli", &i ) ); - TESTCASE( i == 0ll ); - } - { - // reading +0, i - signed long long i = -1; - TESTSCAN( 1, 2, decimal, 3, SCANPARMS( "%lli", &i ) ); - TESTCASE( i == 0ll ); - } - { - // reading -9223372036854775808, i - signed long long i = -1; - TESTSCAN( 1, 20, decimal, 78, SCANPARMS( "%lli", &i ) ); - CHECK_FEQUAL( i, LLONG_MIN, signed long long, "%lli" ); // should be literal -9223372036854775808ll but GCC balks. - TESTCASE( i < 0ll ); - } - { - // reading 9223372036854775807, i - signed long long i = -1; - TESTSCAN( 1, 19, decimal, 100, SCANPARMS( "%lli", &i ) ); - CHECK_FEQUAL( i, 9223372036854775807ll, signed long long, "%lli" ); - } - { - // reading +9223372036854775807, i - signed long long i = -1; - TESTSCAN( 1, 20, decimal, 99, SCANPARMS( "%lli", &i ) ); - CHECK_FEQUAL( i, 9223372036854775807ll, signed long long, "%lli" ); - } - - // hexadecimal integer matches - { - // reading 0, x - unsigned char i = -1; - TESTSCAN( 1, 1, hexadecimal, 3, SCANPARMS( "%hhx", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading -0x0, x - unsigned char i = -1; - TESTSCAN( 1, 4, hexadecimal, 0, SCANPARMS( "%hhx", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading 0x000, x - unsigned char i = -1; - TESTSCAN( 1, 6, hexadecimal, 5, SCANPARMS( "%hhx", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading 0x0, i - signed char i = -1; - TESTSCAN( 1, 4, hexadecimal, 0, SCANPARMS( "%hhi", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading 7f, x - unsigned char i = -1; - TESTSCAN( 1, 2, hexadecimal, 15, SCANPARMS( "%hhx", &i ) ); - TESTCASE( i == 127 ); - } - { - // reading -0x7f, x - unsigned char i = -1; - TESTSCAN( 1, 5, hexadecimal, 12, SCANPARMS( "%hhx", &i ) ); - CHECK_FEQUAL( i, -127, unsigned char, "%hhu" ); - } - { - // reading -0x80, i - signed char i = -1; - TESTSCAN( 1, 5, hexadecimal, 18, SCANPARMS( "%hhi", &i ) ); - CHECK_FEQUAL( i, -128, signed char, "%hhd" ); - } - { - // reading ff, x - unsigned char i = -1; - TESTSCAN( 1, 2, hexadecimal, 26, SCANPARMS( "%hhx", &i ) ); - TESTCASE( i == 0xff ); - } - { - // reading 0xff, x - unsigned char i = -1; - TESTSCAN( 1, 4, hexadecimal, 24, SCANPARMS( "%hhx", &i ) ); - TESTCASE( i == 255 ); - } - { - // reading 0xff, i - signed char i = 0; - TESTSCAN( 1, 4, hexadecimal, 24, SCANPARMS( "%hhi", &i ) ); - TESTCASE( i == -1 ); - } - { - // reading 0, x - unsigned short i = -1; - TESTSCAN( 1, 1, hexadecimal, 3, SCANPARMS( "%hx", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading -0x0, x - unsigned short i = -1; - TESTSCAN( 1, 4, hexadecimal, 0, SCANPARMS( "%hx", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading 0x000, x - unsigned short i = -1; - TESTSCAN( 1, 6, hexadecimal, 5, SCANPARMS( "%hx", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading 0x0, i - signed short i = -1; - TESTSCAN( 1, 4, hexadecimal, 0, SCANPARMS( "%hi", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading 7fff, x - unsigned short i = -1; - TESTSCAN( 1, 4, hexadecimal, 32, SCANPARMS( "%hx", &i ) ); - TESTCASE( i == 32767 ); - } - { - // reading -0x7fff, x - unsigned short i = -1; - TESTSCAN( 1, 7, hexadecimal, 29, SCANPARMS( "%hx", &i ) ); - CHECK_FEQUAL( i, -32767, unsigned short, "%hu" ); - } - { - // reading -0x8000, i - signed short i = -1; - TESTSCAN( 1, 7, hexadecimal, 37, SCANPARMS( "%hi", &i ) ); - CHECK_FEQUAL( i, -32768, signed short, "%hd" ); - } - { - // reading ffff, x - unsigned short i = -1; - TESTSCAN( 1, 4, hexadecimal, 47, SCANPARMS( "%hx", &i ) ); - TESTCASE( i == 65535 ); - } - { - // reading 0xffff, x - unsigned short i = -1; - TESTSCAN( 1, 6, hexadecimal, 45, SCANPARMS( "%hx", &i ) ); - TESTCASE( i == 65535 ); - } - { - // reading 0xffff, i - signed short i = 0; - TESTSCAN( 1, 6, hexadecimal, 45, SCANPARMS( "%hi", &i ) ); - CHECK_FEQUAL( i, -1, signed short, "%hd" ); - } - { - // reading 0, x - unsigned int i = -1; - TESTSCAN( 1, 1, hexadecimal, 3, SCANPARMS( "%x", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading -0x0, x - unsigned int i = -1; - TESTSCAN( 1, 4, hexadecimal, 0, SCANPARMS( "%x", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading 0x000, x - unsigned int i = -1; - TESTSCAN( 1, 6, hexadecimal, 5, SCANPARMS( "%x", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading 0x0, i - signed int i = -1; - TESTSCAN( 1, 4, hexadecimal, 0, SCANPARMS( "%i", &i ) ); - TESTCASE( i == 0 ); - } - { - // reading 7fffffff, x - unsigned int i = -1; - TESTSCAN( 1, 8, hexadecimal, 55, SCANPARMS( "%x", &i ) ); - TESTCASE( i == 2147483647 ); - } - { - // reading -0x7fffffff, x - unsigned int i = -1; - TESTSCAN( 1, 11, hexadecimal, 52, SCANPARMS( "%x", &i ) ); - CHECK_FEQUAL( i, -2147483647, unsigned int, "%u" ); - } - { - // reading -0x80000000, i - signed int i = -1; - TESTSCAN( 1, 11, hexadecimal, 64, SCANPARMS( "%i", &i ) ); - CHECK_FEQUAL( i, -2147483648, signed int, "%d" ); /* FIXME */ - } - { - // reading ffffffff, x - unsigned int i = -1; - TESTSCAN( 1, 8, hexadecimal, 78, SCANPARMS( "%x", &i ) ); - CHECK_FEQUAL( i, 4294967295, unsigned int, "%d" ); - } - { - // reading 0xffffffff, x - unsigned int i = -1; - TESTSCAN( 1, 10, hexadecimal, 76, SCANPARMS( "%x", &i ) ); - CHECK_FEQUAL( i, 4294967295, unsigned int, "%d" ); - } - - // octal integer matches - { - // reading 0, o - unsigned char i = -1; - TESTSCAN( 1, 1, octal, 4, SCANPARMS( "%hho", &i ) ); - TESTCASE( i == 0u ); - } - { - // reading +0000, o - unsigned char i = -1; - TESTSCAN( 1, 5, octal, 0, SCANPARMS( "%hho", &i ) ); - TESTCASE( i == 0u ); - } - { - // reading -0000, o - unsigned char i = -1; - TESTSCAN( 1, 5, octal, 6, SCANPARMS( "%hho", &i ) ); - TESTCASE( i == 0u ); - } - { - // reading 0177, o - unsigned char i = -1; - TESTSCAN( 1, 4, octal, 13, SCANPARMS( "%hho", &i ) ); - TESTCASE( i == 127u ); - } - { - // reading +0177, o - unsigned char i = -1; - TESTSCAN( 1, 5, octal, 12, SCANPARMS( "%hho", &i ) ); - TESTCASE( i == 127u ); - } - { - // reading 0377, o - unsigned char i = -1; - TESTSCAN( 1, 4, octal, 19, SCANPARMS( "%hho", &i ) ); - CHECK_FEQUAL( i, 255u, unsigned char, "%hhu" ); - } - { - // reading +0377, o - unsigned char i = -1; - TESTSCAN( 1, 5, octal, 18, SCANPARMS( "%hho", &i ) ); - CHECK_FEQUAL( i, 255u, unsigned char, "%hhu" ); - } - { - // reading -0377, o - unsigned char i = -1; - TESTSCAN( 1, 5, octal, 24, SCANPARMS( "%hho", &i ) ); - CHECK_FEQUAL( i, 1u, unsigned char, "%hhu" ); - } - { - // reading 077777, o - unsigned short i = -1; - TESTSCAN( 1, 6, octal, 31, SCANPARMS( "%ho", &i ) ); - TESTCASE( i == 32767u ); - } - { - // reading +077777, o - unsigned short i = -1; - TESTSCAN( 1, 7, octal, 30, SCANPARMS( "%ho", &i ) ); - TESTCASE( i == 32767u ); - } - { - // reading 0177777, o - unsigned short i = -1; - TESTSCAN( 1, 7, octal, 39, SCANPARMS( "%ho", &i ) ); - CHECK_FEQUAL( i, 65535u, unsigned short, "%hu" ); - } - { - // reading +0177777, o - unsigned short i = -1; - TESTSCAN( 1, 8, octal, 38, SCANPARMS( "%ho", &i ) ); - CHECK_FEQUAL( i, 65535u, unsigned short, "%hu" ); - } - { - // reading -0177777, o - unsigned short i = -1; - TESTSCAN( 1, 8, octal, 47, SCANPARMS( "%ho", &i ) ); - CHECK_FEQUAL( i, 1u, unsigned short, "%hu" ); - } - { - // reading 017777777777, o - unsigned int i = -1; - TESTSCAN( 1, 12, octal, 57, SCANPARMS( "%o", &i ) ); - TESTCASE( i == 2147483647u ); - } - { - // reading +017777777777, o - unsigned int i = -1; - TESTSCAN( 1, 13, octal, 56, SCANPARMS( "%o", &i ) ); - TESTCASE( i == 2147483647u ); - } - { - // reading 037777777777, o - unsigned int i = -1; - TESTSCAN( 1, 12, octal, 71, SCANPARMS( "%o", &i ) ); - CHECK_FEQUAL( i, 4294967295u, unsigned int, "%u" ); - } - { - // reading +037777777777, o - unsigned int i = -1; - TESTSCAN( 1, 13, octal, 70, SCANPARMS( "%o", &i ) ); - CHECK_FEQUAL( i, 4294967295u, unsigned int, "%u" ); - } - { - // reading -037777777777, o - unsigned int i = -1; - TESTSCAN( 1, 13, octal, 84, SCANPARMS( "%o", &i ) ); - CHECK_FEQUAL( i, 1u, unsigned int, "%u" ); - } - { - // reading 017777777777, o - unsigned long i = -1; - TESTSCAN( 1, 12, octal, 57, SCANPARMS( "%lo", &i ) ); - TESTCASE( i == 2147483647lu ); - } - { - // reading +017777777777, o - unsigned long i = -1; - TESTSCAN( 1, 13, octal, 56, SCANPARMS( "%lo", &i ) ); - TESTCASE( i == 2147483647lu ); - } - { - // reading 037777777777, o - unsigned long i = -1; - TESTSCAN( 1, 12, octal, 71, SCANPARMS( "%lo", &i ) ); - CHECK_FEQUAL( i, 4294967295lu, unsigned long, "%lu" ); - } - { - // reading +037777777777, o - unsigned long i = -1; - TESTSCAN( 1, 13, octal, 70, SCANPARMS( "%lo", &i ) ); - CHECK_FEQUAL( i, 4294967295lu, unsigned long, "%lu" ); - } - { - // reading -037777777777, o - unsigned long i = -1; - TESTSCAN( 1, 13, octal, 84, SCANPARMS( "%lo", &i ) ); - CHECK_FEQUAL( i, 1lu, unsigned long, "%lu" ); - } - { - // reading 0777777777777777777777, o - unsigned long long i = -1; - TESTSCAN( 1, 22, octal, 99, SCANPARMS( "%llo", &i ) ); - CHECK_FEQUAL( i, 9223372036854775807llu, unsigned long long, "%llu" ); - } - { - // reading +0777777777777777777777, o - unsigned long long i = -1; - TESTSCAN( 1, 23, octal, 98, SCANPARMS( "%llo", &i ) ); - CHECK_FEQUAL( i, 9223372036854775807llu, unsigned long long, "%llu" ); - } - { - // reading 01777777777777777777777, o - unsigned long long i = -1; - TESTSCAN( 1, 23, octal, 123, SCANPARMS( "%llo", &i ) ); - CHECK_FEQUAL( i, 18446744073709551615llu, unsigned long long, "%llu" ); - } - { - // reading +01777777777777777777777, o - unsigned long long i = -1; - TESTSCAN( 1, 24, octal, 122, SCANPARMS( "%llo", &i ) ); - CHECK_FEQUAL( i, 18446744073709551615llu, unsigned long long, "%llu" ); - } - { - // reading -01777777777777777777777, o - unsigned long long i = -1; - TESTSCAN( 1, 24, octal, 147, SCANPARMS( "%llo", &i ) ); - CHECK_FEQUAL( i, 1llu, unsigned long long, "%llu" ); - } - - // string matches - size_t const BUFSIZE = 1000; - char buffer[BUFSIZE]; - { - // reading abc - memset( buffer, '\0', BUFSIZE ); - TESTSCAN( 1, 3, alpha, 0, SCANPARMS( "%[abc]", buffer ) ); - TESTCASE( memcmp( buffer, "abc", 4 ) == 0 ); - } - { - // reading a-c - memset( buffer, '\0', BUFSIZE ); - TESTSCAN( 1, 3, alpha, 0, SCANPARMS( "%[a-c]", buffer ) ); - TESTCASE( memcmp( buffer, "abc", 4 ) == 0 ); - } - { - // reading a-h - memset( buffer, '\0', BUFSIZE ); - TESTSCAN( 1, 8, alpha, 0, SCANPARMS( "%[a-h]", buffer ) ); - TESTCASE( memcmp( buffer, "abcdefgh", 9 ) == 0 ); - } - { - // reading o-r, including [, seperate char - memset( buffer, '\0', BUFSIZE ); - TESTSCAN( 1, 5, alpha, 15, SCANPARMS( "%[[o-qr]", buffer ) ); - TESTCASE( memcmp( buffer, "op[qr", 6 ) == 0 ); - } - { - // reading v-y, including ], two groups - memset( buffer, '\0', BUFSIZE ); - TESTSCAN( 1, 5, alpha, 23, SCANPARMS( "%[]v-wx-y]", buffer ) ); - TESTCASE( memcmp( buffer, "vw]xy", 6 ) == 0 ); - } - { - // missing on first character - memset( buffer, '\0', BUFSIZE ); - TESTSCAN( 0, -1, alpha, 0, SCANPARMS( "%[b]", buffer ) ); - TESTCASE( memcmp( buffer, "", 1 ) == 0 ); - } - { - // eof while reading, two groups - memset( buffer, '\0', BUFSIZE ); - TESTSCAN( 1, 2, alpha, 27, SCANPARMS( "%[a-zA-Z]", buffer ) ); - TESTCASE( memcmp( buffer, "yz", 3 ) == 0 ); - } - { - // eof before reading - memset( buffer, '\0', BUFSIZE ); - TESTSCAN( -1, -1, alpha, 29, SCANPARMS( "%[a-z]", buffer ) ); - TESTCASE( memcmp( buffer, "", 1 ) == 0 ); - } - { - // negation - [^...] - memset( buffer, '\0', BUFSIZE ); - TESTSCAN( 1, 3, alpha, 0, SCANPARMS( "%[^d-f]", buffer ) ); - TESTCASE( memcmp( buffer, "abc", 4 ) == 0 ); - } - -#ifndef REGTEST - // special bordercase - /* Most existing libraries disagree with this test case, so a little - explanation of why PDCLib chose the implementation it did might be - necessary. All references are from ISO/IEC 9899:1999 "Programming - languages - C". Wording critical to the explanation is in UPPERCASE. - Input stream holds "-0xz". - 6.4.4.1 Integer constants - states that '0' is a valid (hexa)decimal - constant, whereas '0x' IS NOT. - 7.19.6.2 The fscanf function - states... - ...in paragraph 9 that "an INPUT ITEM is defined as the longest - sequence of input characters [...] which is, OR IS A PREFIX OF, - a matching input sequence". - ...in paragraph 10 that "if the INPUT ITEM is not a matching - sequence, the execution of THE DIRECTIVE FAILS; this condition - is a matching failure". - ...in footnote 242) that "fscanf pushes back AT MOST ONE input - character onto the input stream." - ...in paragraph 12 that either of the conversion specifiers d, i, - o, u, or x "matches an [...] integer whose format is the same as - expected for THE SUBJECT SEQUENCE of the [strtol|strtoul] - function". - 7.20.1.4 The strtol, strtoll, strtoul, and strtoull functions - states - in paragraph 3 that "the EXPECTED FORM OF THE SUBJECT SEQUENCE is - that of an integer constant AS DESCRIBED IN 6.4.4.1". - These parts of the standard result in the following reasoning: - - The longest sequence of input characters which is a prefix of a - matching input sequence is "-0x" (negative sign, hexadecimal-prefix). - The 'z' is the first character remaining unread as "-0xz" is not a - (prefix of a) matching input sequence. This is according to 7.19.6.2 - paragraph 9. - - "0x", without a valid hexadecimal digit following it, is not a valid - integer constant according to 6.4.4.1. - - "0x" is thus also not of the expected form for a strto[u]l subject - sequence according to 7.20.1.4 paragraph 3. (strto[u]l() would parse - it as zero, but leave the "x" in the final string, i.e. outside the - subject sequence.) - - "0x" is therefore also not a matching sequence to the i or x - conversion specifier according to 7.19.6.2 paragraph 12. - - The conversion should therefore result in a matching failure - according to 7.19.6.2 paragraph 10. - */ - { - // reading -0x, x - unsigned char i = 1; - TESTSCAN( 0, -1, special, 0, SCANPARMS( "%hhx", &i ) ); - TESTCASE( i == 1 ); /* FIXME */ - } - { - // reading -0x, x - unsigned short i = 1; - TESTSCAN( 0, -1, special, 0, SCANPARMS( "%hx", &i ) ); - TESTCASE( i == 1 ); /* FIXME */ - } - { - // reading -0x, x - unsigned int i = 1; - TESTSCAN( 0, -1, special, 0, SCANPARMS( "%x", &i ) ); - TESTCASE( i == 1 ); /* FIXME */ - } -#endif diff --git a/testing/sscan_sources.incl b/testing/sscan_sources.incl deleted file mode 100644 index 027935c..0000000 --- a/testing/sscan_sources.incl +++ /dev/null @@ -1,43 +0,0 @@ - char const * general = "12345678901\0003-5+7\0009\3772 4 6 8 0\3771 \011 5%% 0"; - char const * decimal = "-0 +0 -128 +127 +255 -32768 +32767 +65535\n" - "-2147483648 +2147483647 +4294967295\n" - "-9223372036854775808 +9223372036854775807\n" - "+18446744073709551615\n"; - char const * hexadecimal = "-0x0 -0x000 -0x7f -0x80 0xff -0x7fff -0x8000\n" - "0xffff -0x7fffffff -0x80000000 0xffffffff\n" - "-0x7fffffffffffffff -0x8000000000000000\n" - "0xffffffffffffffff\n"; - char const * octal = "+0000 -0000 +0177 +0377 -0377 +077777 +0177777\n" - "-0177777 +017777777777 +037777777777\n" - "-037777777777 +0777777777777777777777\n" - "+01777777777777777777777\n" - "-01777777777777777777777\n"; - char const * alpha = "abcdefgh-ijklmnop[qrs%uvw]xyz"; -#ifndef REGTEST - char const * special = "-0xz\n"; -#endif - - -/* sscan */ -#define TESTSCAN( result, count, source, offset, ... ) \ - do \ - { \ - int n = -1; \ - int res = SCANFUNC( source + offset, __VA_ARGS__ ); \ - if ( res != result ) \ - { \ - TEST_RESULTS += 1; \ - printf( "FAILED: " __FILE__ ", line %d - expected result %d, got %d\n", __LINE__, result, res ); \ - } \ - if ( n != count ) \ - { \ - TEST_RESULTS += 1; \ - printf( "FAILED: " __FILE__ ", line %d - expected count %d, got %d\n", __LINE__, count, n ); \ - } \ - } while ( 0 ) - -#define SCAN( format ) format "%n", &n -#define SCANPARMS( format, ... ) format "%n", __VA_ARGS__, &n - -#define _PDCLIB_SSCAN - -- 2.30.2