X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=platform%2Fexample%2Ffunctions%2F_PDCLIB%2Frename.c;h=849f872946476beae89d24f890e20f34f1a4721f;hb=67cb1ca6543f8c00240597d140675bd1a66df90f;hp=6b7ecf19d4a2e8ef91c0d0c2ad65b9a7215cdb1f;hpb=e814d98512182702c60ba26236b14774e8ee88cc;p=pdclib.old diff --git a/platform/example/functions/_PDCLIB/rename.c b/platform/example/functions/_PDCLIB/rename.c index 6b7ecf1..849f872 100644 --- a/platform/example/functions/_PDCLIB/rename.c +++ b/platform/example/functions/_PDCLIB/rename.c @@ -34,9 +34,40 @@ 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[] = "touch testfile1"; + char filename2[] = "testfile2"; + /* 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; }