#include "files.h"
int main (int argc, char *argv[])
{
int cr, ttwait, timeout;
if (argc != 4)
{
fprintf (stderr, "\nUsage: timeout_file.test <timeout file> <timeout> <time to wait>\n");
return 1;
}
if (access (argv[1], F_OK) != 0)
{
fprintf (stdout, "\nSet timeout file"); fflush(stdout);
cr = set_timeout_file (argv[1]);
switch (cr)
{
case SET_TIMEOUT_FILE_OPEN_ERROR:
fprintf (stderr, "\nCan not open timeout file - set_timeout_file() failed\n");
return 1;
case SET_TIMEOUT_FILE_WRITE_ERROR:
fprintf (stderr, "\nCan not write into timeout file - set_timeout_file() failed\n");
return 1;
default: ;
}
}
timeout = atoi(argv[2]);
ttwait = atoi(argv[3]);
fprintf (stdout, "\nWait %d seconds", ttwait); fflush(stdout);
sleep(ttwait);
fprintf (stdout, "\nTest timeout now"); fflush(stdout);
cr = test_timeout_file (argv[1], timeout);
switch (cr)
{
case TEST_TIMEOUT_FILE_TIMEOUT_ELLAPSED:
fprintf (stdout, "\ntimeout ellapsed");
break;
case TEST_TIMEOUT_FILE_READ_ERROR:
fprintf (stdout, "\nError while reading timeout file\n\n");
return 1;
case TEST_TIMEOUT_FILE_TIMEOUT_NOT_ELLAPSED:
fprintf (stdout, "\ntimeout not ellapsed yet - you may have to wait");
break;
case TEST_TIMEOUT_FILE_UNLINK_FAILED:
fprintf (stdout, "\nCould not delete the timeout file\n\n");
return 1;
default: fprintf (stdout, "\nInternal error\n\n"); return 1;
}
return 0;
}