r18129: moved the system includes into libreplace - this gives much more
[jelmer/samba4-debian.git] / source / lib / replace / test / testsuite.c
index 2c68fd666418fcc8ca3e891cbaf22859cee1da42..9dddc017be81275b5b1075e4c0e93d8c16aff710 100644 (file)
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
-#include "../replace.h"
-#include <stdio.h>
+#include "replace.h"
 
-int test_ftruncate()
-{
-       /* FIXME */
+/*
+  we include all the system/*.h include files here so that libreplace tests
+  them in the build farm
+*/
+#include "system/capability.h"
+#include "system/dir.h"
+#include "system/filesys.h"
+#include "system/glob.h"
+#include "system/iconv.h"
+#include "system/locale.h"
+#include "system/network.h"
+#include "system/passwd.h"
+#include "system/printing.h"
+#include "system/readline.h"
+#include "system/select.h"
+#include "system/shmem.h"
+#include "system/syslog.h"
+#include "system/terminal.h"
+#include "system/time.h"
+#include "system/wait.h"
+
+#define TESTFILE "testfile.dat"
+
+/*
+  test ftruncate() function
+ */
+static int test_ftruncate(void)
+{
+       struct stat st;
+       int fd;
+       const int size = 1234;
+       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;
 }
 
-int test_strlcpy()
-{
-       /* FIXME */
+/*
+  test strlcpy() function.
+  see http://www.gratisoft.us/todd/papers/strlcpy.html
+ */
+static int test_strlcpy(void)
+{
+       char buf[4];
+       const struct {
+               const char *src;
+               int result;
+       } tests[] = {
+               { "abc", 3 },
+               { "abcdef", 6 },
+               { "abcd", 4 },
+               { "", 0 },
+               { NULL, 0 }
+       };
+       int i;
+       printf("testing strlcpy\n");
+       for (i=0;tests[i].src;i++) {
+               if (strlcpy(buf, tests[i].src, sizeof(buf)) != tests[i].result) {
+                       printf("strlcpy test %d failed\n", i);
+                       return false;
+               }
+       }
        return true;
 }
 
-int test_strlcat()
+static int test_strlcat(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_mktime()
+static int test_mktime(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_rename()
+static int test_rename(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_innetgr()
+static int test_innetgr(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_initgroups()
+static int test_initgroups(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_memmove()
+static int test_memmove(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_strdup()
+static int test_strdup(void)
 {
        /* FIXME */
        return true;
 }      
 
-int test_setlinebuf()
+static int test_setlinebuf(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_vsyslog()
+static int test_vsyslog(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_timegm()
+static int test_timegm(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_setenv()
+static int test_setenv(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_strndup()
+static int test_strndup(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_strnlen()
+static int test_strnlen(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_waitpid()
+static int test_waitpid(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_seteuid()
+static int test_seteuid(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_setegid()
+static int test_setegid(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_asprintf()
+static int test_asprintf(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_snprintf()
+static int test_snprintf(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_vasprintf()
+static int test_vasprintf(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_vsnprintf()
+static int test_vsnprintf(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_opendir()
+static int test_opendir(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_readdir()
+static int test_readdir(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_telldir()
+static int test_telldir(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_seekdir()
+static int test_seekdir(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_dlopen()
+static int test_dlopen(void)
 {
        /* FIXME: test dlopen, dlsym, dlclose, dlerror */
        return true;
 }
 
 
-int test_chroot()
+static int test_chroot(void)
 {
        /* FIXME: chroot() */
        return true;
 }
 
-int test_bzero()
+static int test_bzero(void)
 {
        /* FIXME: bzero */
        return true;
 }
 
-int test_strerror()
+static int test_strerror(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_errno()
+static int test_errno(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_mkdtemp()
+static int test_mkdtemp(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_mkstemp()
+static int test_mkstemp(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_pread()
+static int test_pread(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_pwrite()
+static int test_pwrite(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_getpass()
+static int test_getpass(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_inet_ntoa()
+static int test_inet_ntoa(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_strtoll()
+static int test_strtoll(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_strtoull()
+static int test_strtoull(void)
 {
        /* FIXME */
        return true;
@@ -278,34 +347,33 @@ UINT{16,32,64}_MAX
 INT32_MAX
 */
 
-int test_va_copy()
+static int test_va_copy(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_FUNCTION()
+static int test_FUNCTION(void)
 {
        /* FIXME: test __FUNCTION__ macro */
        return true;
 }
 
-int test_MIN()
+static int test_MIN(void)
 {
        /* FIXME */
        return true;
 }
 
-int test_MAX()
+static int test_MAX(void)
 {
        /* FIXME */
        return true;
 }
 
-int torture_local_replace()
+int torture_local_replace(void *ctx)
 {
        int ret = true;
-;
        ret &= test_ftruncate();
        ret &= test_strlcpy();
        ret &= test_strlcat();