Testdriver for tmpfile().
authorsolar <solar@546481bc-9713-0410-bf18-d3337bbf4a3e>
Thu, 2 Dec 2010 07:36:59 +0000 (07:36 +0000)
committersolar <solar@546481bc-9713-0410-bf18-d3337bbf4a3e>
Thu, 2 Dec 2010 07:36:59 +0000 (07:36 +0000)
git-svn-id: https://srv7.svn-repos.de/dev34/pdclib/trunk@476 546481bc-9713-0410-bf18-d3337bbf4a3e

platform/example/functions/stdio/tmpfile.c
platform/example_cygwin/functions/stdio/tmpfile.c

index 44b975d36b13a96f2bf8d63717cd680ec230201f..b2c099b0c580d6b6d8cf552ad23349e0aceb1f85 100644 (file)
@@ -89,10 +89,23 @@ struct _PDCLIB_file_t * tmpfile( void )
 
 #ifdef TEST
 #include <_PDCLIB_test.h>
+#include <string.h>
 
 int main()
 {
-    TESTCASE( NO_TESTDRIVER );
+    FILE * fh;
+    char filename[ L_tmpnam ];
+    FILE * fhtest;
+    TESTCASE( ( fh = tmpfile() ) != NULL );
+    TESTCASE( fputc( 'x', fh ) == 'x' );
+    /* Checking that file is actually there */
+    TESTCASE_NOREG( strcpy( filename, fh->filename ) == filename );
+    TESTCASE_NOREG( ( fhtest = fopen( filename, "r" ) ) != NULL );
+    TESTCASE_NOREG( fclose( fhtest ) == 0 );
+    /* Closing tmpfile */
+    TESTCASE( fclose( fh ) == 0 );
+    /* Checking that file was deleted */
+    TESTCASE_NOREG( fopen( filename, "r" ) == NULL );
     return TEST_RESULTS;
 }
 
index 255a35eb75721d58d352cd1279a1dd7f3fdda622..9e6a325df6fefae6763314c322cea28b1d2e7d4d 100644 (file)
@@ -23,7 +23,19 @@ struct _PDCLIB_file_t * tmpfile( void )
 
 int main()
 {
-    TESTCASE( NO_TESTDRIVER );
+    FILE * fh;
+    char filename[ L_tmpnam ];
+    FILE * fhtest;
+    TESTCASE( ( fh = tmpfile() ) != NULL );
+    TESTCASE( fputc( 'x', fh ) == 'x' );
+    /* Checking that file is actually there */
+    TESTCASE_NOREG( strcpy( filename, fh->filename ) == filename );
+    TESTCASE_NOREG( ( fhtest = fopen( filename, "r" ) ) != NULL );
+    TESTCASE_NOREG( fclose( fhtest ) == 0 );
+    /* Closing tmpfile */
+    TESTCASE( fclose( fh ) == 0 );
+    /* Checking that file was deleted */
+    TESTCASE_NOREG( fopen( filename, "r" ) == NULL );
     return TEST_RESULTS;
 }