From 98263bcb0de07459069c5a39867a4fd3d6a08da7 Mon Sep 17 00:00:00 2001 From: solar Date: Thu, 2 Dec 2010 07:36:59 +0000 Subject: [PATCH] Testdriver for tmpfile(). git-svn-id: https://srv7.svn-repos.de/dev34/pdclib/trunk@476 546481bc-9713-0410-bf18-d3337bbf4a3e --- platform/example/functions/stdio/tmpfile.c | 15 ++++++++++++++- platform/example_cygwin/functions/stdio/tmpfile.c | 14 +++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/platform/example/functions/stdio/tmpfile.c b/platform/example/functions/stdio/tmpfile.c index 44b975d..b2c099b 100644 --- a/platform/example/functions/stdio/tmpfile.c +++ b/platform/example/functions/stdio/tmpfile.c @@ -89,10 +89,23 @@ struct _PDCLIB_file_t * tmpfile( void ) #ifdef TEST #include <_PDCLIB_test.h> +#include 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; } diff --git a/platform/example_cygwin/functions/stdio/tmpfile.c b/platform/example_cygwin/functions/stdio/tmpfile.c index 255a35e..9e6a325 100644 --- a/platform/example_cygwin/functions/stdio/tmpfile.c +++ b/platform/example_cygwin/functions/stdio/tmpfile.c @@ -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; } -- 2.30.2