Add unit test for tempfile()

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2016-06-06 17:07:14 +02:00
parent 86b883e2af
commit 5b786ce221
4 changed files with 28 additions and 14 deletions
+2
View File
@@ -4,10 +4,12 @@ CLEANFILES = *~ *.trs *.log
TESTS =
TESTS += makepath
TESTS += pidfile
TESTS += tempfile
TESTS += tree
check_PROGRAMS = $(TESTS)
# Ignore warnings about unused result, in e.g. write()
CFLAGS = -W -Wall -Wextra -Wno-unused-result
CPPFLAGS = -D_GNU_SOURCE
LDADD = -L../ ../libite.la
+25
View File
@@ -0,0 +1,25 @@
#include <fcntl.h> /* O_TMPFILE requires -D_GNU_SOURCE */
#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
#include "check.h"
#ifndef O_TMPFILE
#warning O_TMPFILE is missing, either too old GLIBC, Linux, or non-Linux system
#endif
int main(void)
{
FILE *fp;
printf("Before tempfile():\n");
system("ls -lrt " _PATH_TMP " | tail -3");
fp = tempfile();
fail_unless(fp != NULL);
printf("\nAfter tempfile(), should be same list:\n");
system("ls -lrt " _PATH_TMP " | tail -3");
return fclose(fp);
}