From ddc340b8ebc7da1b3e5083dc2a8542f4a13683f3 Mon Sep 17 00:00:00 2001 From: solar Date: Fri, 2 Jun 2006 09:34:57 +0000 Subject: [PATCH] Added testdriver for _PDCLIB_remove(). --- Makefile | 2 +- platform/example/functions/_PDCLIB/remove.c | 25 +++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f9f99e0..dc040ac 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 remove seed stdinit strtox_main strtox_prelim +INTFILES := _Exit atomax digits open print 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/remove.c b/platform/example/functions/_PDCLIB/remove.c index 970db6a..609ddbe 100644 --- a/platform/example/functions/_PDCLIB/remove.c +++ b/platform/example/functions/_PDCLIB/remove.c @@ -22,7 +22,7 @@ int _PDCLIB_remove( const char * filename ) int prev_errno = errno; int rc; errno = 0; - if ( ( ( rc = unlink( filename ) ) != 0 ) && ( errno == EPERM ) ) + if ( ( ( rc = unlink( filename ) ) != 0 ) && ( errno == EISDIR ) ) { rc = rmdir( filename ); } @@ -37,9 +37,30 @@ int _PDCLIB_remove( const char * filename ) #undef SEEK_SET #include <_PDCLIB_test.h> +#include +#include + int main( void ) { - TESTCASE( NO_TESTDRIVER ); + char filename[ L_tmpnam + 6 ] = "touch "; + tmpnam( filename + 6 ); + /* create file */ + system( filename ); + /* file is actually readable */ + TESTCASE( fopen( filename + 6, "r" ) != NULL ); + /* remove function does not return error */ + TESTCASE( _PDCLIB_remove( filename + 6 ) == 0 ); + /* file is no longer readable */ + TESTCASE( fopen( filename + 6, "r" ) == NULL ); + /* remove function does return error */ + TESTCASE( _PDCLIB_remove( filename + 6 ) != 0 ); + memcpy( filename, "mkdir", 5 ); + /* create directory */ + system( filename ); + /* remove function does not return error */ + TESTCASE( _PDCLIB_remove( filename + 6 ) == 0 ); + /* remove function does return error */ + TESTCASE( _PDCLIB_remove( filename + 6 ) != 0 ); return TEST_RESULTS; } -- 2.40.0