From 42bbbcf0bf71d93b6dff9d86e96a2791da1383be Mon Sep 17 00:00:00 2001 From: solar Date: Fri, 2 Jun 2006 11:59:11 +0000 Subject: [PATCH] Added testdriver for _PDCLIB_rename(). --- Makefile | 2 +- platform/example/functions/_PDCLIB/rename.c | 35 ++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index dc040ac..ba245f3 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ SRCFILES := $(shell find $(PROJDIRS) -mindepth 1 -maxdepth 3 -name "*.c") # All header files of the project HDRFILES := $(shell find $(PROJDIRS) -mindepth 1 -maxdepth 3 -name "*.h") # All .c files in functions/_PDCLIB that do not have a regression test driver -INTFILES := _Exit atomax digits open print rename seed stdinit strtox_main strtox_prelim +INTFILES := _Exit atomax digits open print remove rename seed stdinit strtox_main strtox_prelim # All object files in the library OBJFILES := $(patsubst %.c,%.o,$(SRCFILES)) # All test drivers (.t) diff --git a/platform/example/functions/_PDCLIB/rename.c b/platform/example/functions/_PDCLIB/rename.c index 6b7ecf1..ab1a75d 100644 --- a/platform/example/functions/_PDCLIB/rename.c +++ b/platform/example/functions/_PDCLIB/rename.c @@ -34,9 +34,42 @@ int _PDCLIB_rename( const char * old, const char * new ) #undef SEEK_SET #include <_PDCLIB_test.h> +#include + int main( void ) { - TESTCASE( NO_TESTDRIVER ); + char filename1[ L_tmpnam + 6 ] = "touch "; + char filename2[ L_tmpnam ]; + tmpnam( filename1 + 6 ); + tmpnam( filename2); + /* check that neither file exists */ + TESTCASE( fopen( filename1 + 6, "r" ) == NULL ); + TESTCASE( fopen( filename2, "r" ) == NULL ); + /* rename file 1 to file 2 - expected to fail */ + TESTCASE( _PDCLIB_rename( filename1 + 6, filename2 ) == -1 ); + /* create file 1 */ + system( filename1 ); + /* check that file 1 exists */ + TESTCASE( fopen( filename1 + 6, "r" ) != NULL ); + /* rename file 1 to file 2 */ + TESTCASE( _PDCLIB_rename( filename1 + 6, filename2 ) == 0 ); + /* check that file 2 exists, file 1 does not */ + TESTCASE( fopen( filename1 + 6, "r" ) == NULL ); + TESTCASE( fopen( filename2, "r" ) != NULL ); + /* create another file 1 */ + system( filename1 ); + /* check that file 1 exists */ + TESTCASE( fopen( filename1 + 6, "r" ) != NULL ); + /* rename file 1 to file 2 - expected to fail, see comment in + _PDCLIB_rename() itself. + */ + TESTCASE( _PDCLIB_rename( filename1 + 6, filename2 ) == -1 ); + /* remove both files */ + remove( filename1 + 6 ); + remove( filename2 ); + /* check that they're gone */ + TESTCASE( fopen( filename1 + 6, "r" ) == NULL ); + TESTCASE( fopen( filename2, "r" ) == NULL ); return TEST_RESULTS; } -- 2.40.0