# 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)
#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;
}