// S : tags libc c stdio // S : expect --result valid // S : cc -o test.bc -D_PDCLIB_BUILD -DTEST $file // S : verify -o nofail:malloc test.bc #include #include #include "_PDCLIB_test.h" #include int main( void ) { #ifndef REGTEST FILE * file; remove( testfile1 ); remove( testfile2 ); /* check that neither file exists */ TESTCASE( fopen( testfile1, "r" ) == NULL ); TESTCASE( fopen( testfile2, "r" ) == NULL ); /* rename file 1 to file 2 - expected to fail */ TESTCASE( _PDCLIB_rename( testfile1, testfile2 ) == -1 ); /* create file 1 */ TESTCASE( ( file = fopen( testfile1, "w" ) ) != NULL ); TESTCASE( fputc( 'x', file ) == 'x' ); TESTCASE( fclose( file ) == 0 ); /* check that file 1 exists */ TESTCASE( ( file = fopen( testfile1, "r" ) ) != NULL ); TESTCASE( fclose( file ) == 0 ); /* rename file 1 to file 2 */ TESTCASE( _PDCLIB_rename( testfile1, testfile2 ) == 0 ); /* check that file 2 exists, file 1 does not */ TESTCASE( fopen( testfile1, "r" ) == NULL ); TESTCASE( ( file = fopen( testfile2, "r" ) ) != NULL ); TESTCASE( fclose( file ) == 0 ); /* create another file 1 */ TESTCASE( ( file = fopen( testfile1, "w" ) ) != NULL ); TESTCASE( fputc( 'x', file ) == 'x' ); TESTCASE( fclose( file ) == 0 ); /* check that file 1 exists */ TESTCASE( ( file = fopen( testfile1, "r" ) ) != NULL ); TESTCASE( fclose( file ) == 0 ); /* rename file 1 to file 2 - expected to fail, see comment in _PDCLIB_rename() itself. */ TESTCASE( _PDCLIB_rename( testfile1, testfile2 ) == -1 ); /* remove both files */ remove( testfile1 ); remove( testfile2 ); #endif return TEST_RESULTS; }