]> pd.if.org Git - pdclib/blobdiff - functions/stdio/clearerr.c
Cleaned up the testing a bit.
[pdclib] / functions / stdio / clearerr.c
index 6d80c8aeb381639c62b9fbf0a4194ff68b083bc7..810e62d7606d99f79613df9faa97ec520f13819d 100644 (file)
@@ -22,8 +22,33 @@ void clearerr( struct _PDCLIB_file_t * stream )
 
 int main( void )
 {
-    TESTCASE( NO_TESTDRIVER );
+    FILE * fh;
+    remove( "testing/testfile" );
+    TESTCASE( ( fh = fopen( "testing/testfile", "w+" ) ) != NULL );
+    /* Flags should be clear */
+    TESTCASE( ! ferror( fh ) );
+    TESTCASE( ! feof( fh ) );
+    /* Reading from input stream - should provoke error */
+    TESTCASE( fgetc( fh ) == EOF );
+    TESTCASE( ferror( fh ) );
+    TESTCASE( ! feof( fh ) );
+    /* clearerr() should clear flags */
+    clearerr( fh );
+    TESTCASE( ! ferror( fh ) );
+    TESTCASE( ! feof( fh ) );
+    /* Reading from empty stream - should provoke EOF */
+    rewind( fh );
+    TESTCASE( fgetc( fh ) == EOF );
+    TESTCASE( ! ferror( fh ) );
+    TESTCASE( feof( fh ) );
+    /* clearerr() should clear flags */
+    clearerr( fh );
+    TESTCASE( ! ferror( fh ) );
+    TESTCASE( ! feof( fh ) );
+    TESTCASE( fclose( fh ) == 0 );
+    remove( "testing/testfile" );
     return TEST_RESULTS;
 }
 
 #endif
+