From 4c4e6a9a1c7c433095183662c673bbd48299da5c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 4 Sep 2006 13:10:49 +0000 Subject: r18041: started on the bodies of the testsuite functions for libreplace (This used to be commit a2a6782ec721312e329cd16b609fb3eff8ad284d) --- source4/lib/replace/test/testsuite.c | 44 +++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'source4/lib/replace/test') diff --git a/source4/lib/replace/test/testsuite.c b/source4/lib/replace/test/testsuite.c index 83da05ce45..c00e2a788f 100644 --- a/source4/lib/replace/test/testsuite.c +++ b/source4/lib/replace/test/testsuite.c @@ -27,9 +27,51 @@ #include "../replace.h" #include +#if HAVE_STDLIB_H +#include +#endif + +#if HAVE_TYPES_H +#include +#endif + +#if HAVE_SYS_STAT_H +#include +#endif + +#include +#include + +#define TESTFILE "testfile.dat" + +/* + test ftruncate() function + */ static int test_ftruncate() { - /* FIXME */ + struct stat st; + int fd, i; + const int size; + printf("testing ftruncate\n"); + unlink(TESTFILE); + fd = open(TESTFILE, O_RDWR|O_CREAT, 0600); + if (fd == -1) { + printf("creating '%s' failed - %s\n", TESTFILE, strerror(errno)); + return false; + } + if (ftruncate(fd, size) != 0) { + printf("ftruncate failed - %s\n", strerror(errno)); + return false; + } + if (fstat(fd, &st) != 0) { + printf("fstat failed - %s\n", strerror(errno)); + return false; + } + if (st.st_size != size) { + printf("ftruncate gave wrong size %d - expected %d\n", + (int)st.st_size, size); + return false; + } return true; } -- cgit