]> pd.if.org Git - pdclib/commitdiff
Added testdriver for _PDCLIB_rename().
authorsolar <unknown>
Fri, 2 Jun 2006 11:59:11 +0000 (11:59 +0000)
committersolar <unknown>
Fri, 2 Jun 2006 11:59:11 +0000 (11:59 +0000)
Makefile
platform/example/functions/_PDCLIB/rename.c

index dc040ac964e795b350b72434cc09a64c82e27d6b..ba245f386dbe6696e9ee178f2619d1c12498b681 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 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)
index 6b7ecf19d4a2e8ef91c0d0c2ad65b9a7215cdb1f..ab1a75d6a51ebd6edf6d4a91e730b6fff033975e 100644 (file)
@@ -34,9 +34,42 @@ int _PDCLIB_rename( const char * old, const char * new )
 #undef SEEK_SET
 #include <_PDCLIB_test.h>
 
+#include <stdlib.h>
+
 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;
 }