mirror of
https://github.com/troglobit/libite.git
synced 2026-11-12 16:51:16 +00:00
Update tempfile() unit test to detect failed write + read
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
9f5e852084
commit
6ec2a31042
1 file changed
+13
-2
+13
-2
@@ -8,18 +8,29 @@
|
|||||||
#warning O_TMPFILE is missing, either too old GLIBC, Linux, or non-Linux system
|
#warning O_TMPFILE is missing, either too old GLIBC, Linux, or non-Linux system
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define READBACK "Reality is frequently inaccurate.\n"
|
||||||
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
char buf[80] = "";
|
||||||
|
|
||||||
printf("Before tempfile():\n");
|
printf("Before tempfile():\n");
|
||||||
system("ls -lrt " _PATH_TMP " | tail -3");
|
ret = system("ls -lrt " _PATH_TMP " | tail -3");
|
||||||
|
|
||||||
fp = tempfile();
|
fp = tempfile();
|
||||||
fail_unless(fp != NULL);
|
fail_unless(fp != NULL);
|
||||||
|
|
||||||
|
ret = fputs(READBACK, fp);
|
||||||
|
rewind(fp);
|
||||||
|
if (fgets(buf, sizeof(buf), fp))
|
||||||
|
fprintf(stderr, "\nRead-back from tempfile: %s", buf);
|
||||||
|
fail_unless(!strcmp(buf, READBACK));
|
||||||
|
|
||||||
printf("\nAfter tempfile(), should be same list:\n");
|
printf("\nAfter tempfile(), should be same list:\n");
|
||||||
system("ls -lrt " _PATH_TMP " | tail -3");
|
ret = system("ls -lrt " _PATH_TMP " | tail -3");
|
||||||
|
|
||||||
return fclose(fp);
|
return fclose(fp);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user