]> pd.if.org Git - pdclib/commitdiff
Added testdriver for _PDCLIB_remove().
authorsolar <unknown>
Fri, 2 Jun 2006 09:34:57 +0000 (09:34 +0000)
committersolar <unknown>
Fri, 2 Jun 2006 09:34:57 +0000 (09:34 +0000)
Makefile
platform/example/functions/_PDCLIB/remove.c

index f9f99e0e291c76bb204b2cf9c0f9f83b779fee83..dc040ac964e795b350b72434cc09a64c82e27d6b 100644 (file)
--- 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)
index 970db6add911607e9a430d3d5a87cc1a5c31807d..609ddbe4b49d70b3a722e29fe6838fb8b73c1cb5 100644 (file)
@@ -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 <stdlib.h>
+#include <string.h>
+
 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;
 }