From: solar Date: Mon, 6 Dec 2010 21:21:45 +0000 (+0000) Subject: Test drivers for fgetpos, fsetpos, and perror. Cannot really test closeall(). X-Git-Url: https://git.gag.com/?p=fw%2Fpdclib;a=commitdiff_plain;h=fba3dbaded374d4a73d405770491779bc92289b7 Test drivers for fgetpos, fsetpos, and perror. Cannot really test closeall(). git-svn-id: https://srv7.svn-repos.de/dev34/pdclib/trunk@480 546481bc-9713-0410-bf18-d3337bbf4a3e --- diff --git a/functions/_PDCLIB/closeall.c b/functions/_PDCLIB/closeall.c index 3523f8c..71f6007 100644 --- a/functions/_PDCLIB/closeall.c +++ b/functions/_PDCLIB/closeall.c @@ -27,7 +27,7 @@ void _PDCLIB_closeall( void ) int main( void ) { - TESTCASE( NO_TESTDRIVER ); + /* No testdriver */ return TEST_RESULTS; } diff --git a/functions/stdio/fgetpos.c b/functions/stdio/fgetpos.c index 0d5de42..7e5fbe7 100644 --- a/functions/stdio/fgetpos.c +++ b/functions/stdio/fgetpos.c @@ -22,10 +22,22 @@ int fgetpos( struct _PDCLIB_file_t * _PDCLIB_restrict stream, struct _PDCLIB_fpo #ifdef TEST #include <_PDCLIB_test.h> +#include int main( void ) { - TESTCASE( NO_TESTDRIVER ); + FILE * fh; + fpos_t pos1, pos2; + TESTCASE( ( fh = fopen( testfile, "wb+" ) ) != NULL ); + TESTCASE( fgetpos( fh, &pos1 ) == 0 ); + TESTCASE( fwrite( teststring, 1, strlen( teststring ), fh ) == strlen( teststring ) ); + TESTCASE( fgetpos( fh, &pos2 ) == 0 ); + TESTCASE( fsetpos( fh, &pos1 ) == 0 ); + TESTCASE( ftell( fh ) == 0 ); + 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/fsetpos.c b/functions/stdio/fsetpos.c index 1c39c49..2082b48 100644 --- a/functions/stdio/fsetpos.c +++ b/functions/stdio/fsetpos.c @@ -36,7 +36,7 @@ int fsetpos( struct _PDCLIB_file_t * stream, const struct _PDCLIB_fpos_t * pos ) int main( void ) { - TESTCASE( NO_TESTDRIVER ); + /* fsetpos() tested together with fsetpos(). */ return TEST_RESULTS; } diff --git a/functions/stdio/perror.c b/functions/stdio/perror.c index 609562a..fc6ff87 100644 --- a/functions/stdio/perror.c +++ b/functions/stdio/perror.c @@ -27,10 +27,24 @@ void perror( const char * s ) #ifdef TEST #include <_PDCLIB_test.h> +#include +#include +#include int main( void ) { - TESTCASE( NO_TESTDRIVER ); + FILE * fh; + unsigned long long max = ULLONG_MAX; + char buffer[100]; + sprintf( buffer, "%llu", max ); + TESTCASE( ( fh = freopen( testfile, "wb+", stderr ) ) != NULL ); + TESTCASE( strtol( buffer, NULL, 10 ) == LONG_MAX ); + perror( "Test" ); + rewind( fh ); + TESTCASE( fread( buffer, 1, 7, fh ) == 7 ); + TESTCASE( memcmp( buffer, "Test: ", 6 ) == 0 ); + TESTCASE( fclose( fh ) == 0 ); + remove( testfile ); return TEST_RESULTS; }