Test drivers for fgetpos, fsetpos, and perror. Cannot really test closeall().
authorsolar <solar@546481bc-9713-0410-bf18-d3337bbf4a3e>
Mon, 6 Dec 2010 21:21:45 +0000 (21:21 +0000)
committersolar <solar@546481bc-9713-0410-bf18-d3337bbf4a3e>
Mon, 6 Dec 2010 21:21:45 +0000 (21:21 +0000)
git-svn-id: https://srv7.svn-repos.de/dev34/pdclib/trunk@480 546481bc-9713-0410-bf18-d3337bbf4a3e

functions/_PDCLIB/closeall.c
functions/stdio/fgetpos.c
functions/stdio/fsetpos.c
functions/stdio/perror.c

index 3523f8c0fe5013f34f625abbd0146ff9627e25df..71f600790f32d944fabb47263517eb137d20d1b8 100644 (file)
@@ -27,7 +27,7 @@ void _PDCLIB_closeall( void )
 
 int main( void )
 {
-    TESTCASE( NO_TESTDRIVER );
+    /* No testdriver */
     return TEST_RESULTS;
 }
 
index 0d5de428280995afc9a63f3f0934b434274faa57..7e5fbe7068c23ab67d69a589693140d69b13b875 100644 (file)
@@ -22,10 +22,22 @@ int fgetpos( struct _PDCLIB_file_t * _PDCLIB_restrict stream, struct _PDCLIB_fpo
 
 #ifdef TEST
 #include <_PDCLIB_test.h>
+#include <string.h>
 
 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;
 }
 
index 1c39c498071abb9a24ab19edc9ec76f1b43be789..2082b4824a74dddfc4ced451b53879a79c4cb3e4 100644 (file)
@@ -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;
 }
 
index 609562a8e46a783a89420808117163d6d8ce5c5e..fc6ff87a4dc4c5ec15cd260e4270874a1057698a 100644 (file)
@@ -27,10 +27,24 @@ void perror( const char * s )
 
 #ifdef TEST
 #include <_PDCLIB_test.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
 
 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;
 }