r18043: added strlcpy() test
authorAndrew Tridgell <tridge@samba.org>
Mon, 4 Sep 2006 13:28:54 +0000 (13:28 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:17:07 +0000 (14:17 -0500)
(This used to be commit a68b3395199d2d47af3b23959e6da7109a9c5193)

source4/lib/replace/test/testsuite.c

index c00e2a788fdd5b7fecaa5736b5300b9d96c16824..5d20c345f8a3ddc3b9527547900264dd9e70d396 100644 (file)
@@ -75,9 +75,31 @@ static int test_ftruncate()
        return true;
 }
 
+/*
+  test strlcpy() function.
+  see http://www.gratisoft.us/todd/papers/strlcpy.html
+ */
 static int test_strlcpy()
 {
-       /* FIXME */
+       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");
+                       return false;
+               }
+       }
        return true;
 }
 
@@ -347,7 +369,6 @@ static int test_MAX()
 int torture_local_replace()
 {
        int ret = true;
-;
        ret &= test_ftruncate();
        ret &= test_strlcpy();
        ret &= test_strlcat();