summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2006-09-04 13:10:49 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:17:07 -0500
commit4c4e6a9a1c7c433095183662c673bbd48299da5c (patch)
tree1b4401a320fb53cb1b6b1c3693232255f7f38419 /source4/lib
parentc90a12781be9f38ba2f03e903205e347733ff4a9 (diff)
downloadsamba-4c4e6a9a1c7c433095183662c673bbd48299da5c.tar.gz
samba-4c4e6a9a1c7c433095183662c673bbd48299da5c.tar.bz2
samba-4c4e6a9a1c7c433095183662c673bbd48299da5c.zip
r18041: started on the bodies of the testsuite functions for libreplace
(This used to be commit a2a6782ec721312e329cd16b609fb3eff8ad284d)
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/replace/Makefile.in2
-rw-r--r--source4/lib/replace/test/testsuite.c44
2 files changed, 44 insertions, 2 deletions
diff --git a/source4/lib/replace/Makefile.in b/source4/lib/replace/Makefile.in
index a53a1271ef..2f13b97836 100644
--- a/source4/lib/replace/Makefile.in
+++ b/source4/lib/replace/Makefile.in
@@ -13,7 +13,7 @@ CFLAGS=-I. -I$(srcdir) @CFLAGS@
OBJS = dlfcn.o getpass.o replace.o snprintf.o
-all: libreplace.a
+all: libreplace.a testsuite
install: all
mkdir -p $(libdir)
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 <stdio.h>
+#if HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#if HAVE_TYPES_H
+#include <sys/types.h>
+#endif
+
+#if HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+#include <fcntl.h>
+#include <errno.h>
+
+#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;
}