X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=platform%2Fexample%2Ffunctions%2F_PDCLIB%2Frename.c;h=849f872946476beae89d24f890e20f34f1a4721f;hb=67cb1ca6543f8c00240597d140675bd1a66df90f;hp=90b2290fd60126fff8bbad4dff77f656c9c5e4ce;hpb=d9dcf16664c81809258992e1653ecb68c8079974;p=pdclib.old diff --git a/platform/example/functions/_PDCLIB/rename.c b/platform/example/functions/_PDCLIB/rename.c index 90b2290..849f872 100644 --- a/platform/example/functions/_PDCLIB/rename.c +++ b/platform/example/functions/_PDCLIB/rename.c @@ -30,11 +30,44 @@ int _PDCLIB_rename( const char * old, const char * new ) #endif #ifdef TEST +/* TODO: Work around the following undef */ +#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; }