mirror of
https://github.com/troglobit/libite.git
synced 2026-10-24 11:44:37 +00:00
Add unit test for tempfile()
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
86b883e2af
commit
5b786ce221
4 files changed
+28
-14
No files matched your search
+1
-10
@@ -1,6 +1,6 @@
|
|||||||
/* A secure tmpfile() replacement.
|
/* A secure tmpfile() replacement.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2015 Joachim Nilsson <troglobit@gmail.com>
|
* Copyright (c) 2015-2016 Joachim Nilsson <troglobit@gmail.com>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and/or distribute this software for any
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -51,17 +51,8 @@ FILE *tempfile(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef UNITTEST
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
FILE *fp = tempfile(); system("ls -lrt "
|
|
||||||
_PATH_TMP " | tail -10"); return fclose(fp);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Local Variables:
|
* Local Variables:
|
||||||
* compile-command: "make V=1 -f tempfile.mk"
|
|
||||||
* indent-tabs-mode: t
|
* indent-tabs-mode: t
|
||||||
* c-file-style: "linux"
|
* c-file-style: "linux"
|
||||||
* End:
|
* End:
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
OBJS =
|
|
||||||
TARGET = tempfile.test clean
|
|
||||||
|
|
||||||
include rules.mk
|
|
||||||
@@ -4,10 +4,12 @@ CLEANFILES = *~ *.trs *.log
|
|||||||
TESTS =
|
TESTS =
|
||||||
TESTS += makepath
|
TESTS += makepath
|
||||||
TESTS += pidfile
|
TESTS += pidfile
|
||||||
|
TESTS += tempfile
|
||||||
TESTS += tree
|
TESTS += tree
|
||||||
|
|
||||||
check_PROGRAMS = $(TESTS)
|
check_PROGRAMS = $(TESTS)
|
||||||
|
|
||||||
# Ignore warnings about unused result, in e.g. write()
|
# Ignore warnings about unused result, in e.g. write()
|
||||||
CFLAGS = -W -Wall -Wextra -Wno-unused-result
|
CFLAGS = -W -Wall -Wextra -Wno-unused-result
|
||||||
|
CPPFLAGS = -D_GNU_SOURCE
|
||||||
LDADD = -L../ ../libite.la
|
LDADD = -L../ ../libite.la
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user