From 73493a095ae4802cd3e1222b22321454db17b988 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 4 Sep 2006 13:28:54 +0000 Subject: [PATCH] r18043: added strlcpy() test (This used to be commit a68b3395199d2d47af3b23959e6da7109a9c5193) --- source4/lib/replace/test/testsuite.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/source4/lib/replace/test/testsuite.c b/source4/lib/replace/test/testsuite.c index c00e2a788fd..5d20c345f8a 100644 --- a/source4/lib/replace/test/testsuite.c +++ b/source4/lib/replace/test/testsuite.c @@ -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(); -- 2.34.1