From 8f153c6128dd15fb132d8ddb1752e793bd6a5985 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 18 Sep 2006 22:49:20 +0000 Subject: r18644: bring in libreplace in lib/replace metze (This used to be commit 596cbe73dd268742acf456fccd8a234376fb0c97) --- source3/lib/replace/test/testsuite.c | 435 +++++++++++++++++++++++++++++++++++ 1 file changed, 435 insertions(+) create mode 100644 source3/lib/replace/test/testsuite.c (limited to 'source3/lib/replace/test/testsuite.c') diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c new file mode 100644 index 0000000000..6644fce6bd --- /dev/null +++ b/source3/lib/replace/test/testsuite.c @@ -0,0 +1,435 @@ +/* + Unix SMB/CIFS implementation. + + libreplace tests + + Copyright (C) Jelmer Vernooij 2006 + + ** NOTE! The following LGPL license applies to the talloc + ** library. This does NOT imply that all of Samba is released + ** under the LGPL + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "replace.h" + +/* + we include all the system/ 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; +} + +/* + 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; +} + +static int test_strlcat(void) +{ + /* FIXME */ + return true; +} + +static int test_mktime(void) +{ + /* FIXME */ + return true; +} + +static int test_innetgr(void) +{ + /* FIXME */ + return true; +} + +static int test_initgroups(void) +{ + /* FIXME */ + return true; +} + +static int test_memmove(void) +{ + /* FIXME */ + return true; +} + +static int test_strdup(void) +{ + /* FIXME */ + return true; +} + +static int test_setlinebuf(void) +{ + printf("testing setlinebuf\n"); + setlinebuf(stdout); + return true; +} + +static int test_vsyslog(void) +{ + /* FIXME */ + return true; +} + +static int test_timegm(void) +{ + /* FIXME */ + return true; +} + +static int test_setenv(void) +{ + /* FIXME */ + return true; +} + +static int test_strndup(void) +{ + /* FIXME */ + return true; +} + +static int test_strnlen(void) +{ + /* FIXME */ + return true; +} + +static int test_waitpid(void) +{ + /* FIXME */ + return true; +} + +static int test_seteuid(void) +{ + /* FIXME */ + return true; +} + +static int test_setegid(void) +{ + /* FIXME */ + return true; +} + +static int test_asprintf(void) +{ + /* FIXME */ + return true; +} + +static int test_snprintf(void) +{ + /* FIXME */ + return true; +} + +static int test_vasprintf(void) +{ + /* FIXME */ + return true; +} + +static int test_vsnprintf(void) +{ + /* FIXME */ + return true; +} + +static int test_opendir(void) +{ + /* FIXME */ + return true; +} + +extern int test_readdir_os2_delete(void); + +static bool test_readdir(void) +{ + printf("testing readdir\n"); + if (test_readdir_os2_delete() != 0) { + return false; + } + + /* FIXME */ + return true; +} + +static int test_telldir(void) +{ + /* FIXME */ + return true; +} + +static int test_seekdir(void) +{ + /* FIXME */ + return true; +} + +static int test_dlopen(void) +{ + /* FIXME: test dlopen, dlsym, dlclose, dlerror */ + return true; +} + + +static int test_chroot(void) +{ + /* FIXME: chroot() */ + return true; +} + +static int test_bzero(void) +{ + /* FIXME: bzero */ + return true; +} + +static int test_strerror(void) +{ + /* FIXME */ + return true; +} + +static int test_errno(void) +{ + /* FIXME */ + return true; +} + +static int test_mkdtemp(void) +{ + /* FIXME */ + return true; +} + +static int test_mkstemp(void) +{ + /* FIXME */ + return true; +} + +static int test_pread(void) +{ + /* FIXME */ + return true; +} + +static int test_pwrite(void) +{ + /* FIXME */ + return true; +} + +static int test_getpass(void) +{ + /* FIXME */ + return true; +} + +static int test_inet_ntoa(void) +{ + /* FIXME */ + return true; +} + +static int test_strtoll(void) +{ + /* FIXME */ + return true; +} + +static int test_strtoull(void) +{ + /* FIXME */ + return true; +} + +/* +FIXME: +Types: +bool +socklen_t +uint_t +uint{8,16,32,64}_t +int{8,16,32,64}_t +intptr_t + +Constants: +PATH_NAME_MAX +UINT{16,32,64}_MAX +INT32_MAX +*/ + +static int test_va_copy(void) +{ + /* FIXME */ + return true; +} + +static int test_FUNCTION(void) +{ + /* FIXME: test __FUNCTION__ macro */ + return true; +} + +static int test_MIN(void) +{ + /* FIXME */ + return true; +} + +static int test_MAX(void) +{ + /* FIXME */ + return true; +} + +int torture_local_replace(void *ctx) +{ + int ret = true; + ret &= test_ftruncate(); + ret &= test_strlcpy(); + ret &= test_strlcat(); + ret &= test_mktime(); + ret &= test_innetgr(); + ret &= test_initgroups(); + ret &= test_memmove(); + ret &= test_strdup(); + ret &= test_setlinebuf(); + ret &= test_vsyslog(); + ret &= test_timegm(); + ret &= test_setenv(); + ret &= test_strndup(); + ret &= test_strnlen(); + ret &= test_waitpid(); + ret &= test_seteuid(); + ret &= test_setegid(); + ret &= test_asprintf(); + ret &= test_snprintf(); + ret &= test_vasprintf(); + ret &= test_vsnprintf(); + ret &= test_opendir(); + ret &= test_readdir() ; + ret &= test_telldir(); + ret &= test_seekdir(); + ret &= test_dlopen(); + ret &= test_chroot(); + ret &= test_bzero(); + ret &= test_strerror(); + ret &= test_errno(); + ret &= test_mkdtemp(); + ret &= test_mkstemp(); + ret &= test_pread(); + ret &= test_pwrite(); + ret &= test_getpass(); + ret &= test_inet_ntoa(); + ret &= test_strtoll(); + ret &= test_strtoll(); + ret &= test_strtoull(); + ret &= test_va_copy(); + ret &= test_FUNCTION(); + ret &= test_MIN(); + ret &= test_MAX(); + + return ret; +} + +#if !defined(_SAMBA_BUILD_) || ((SAMBA_VERSION_MAJOR==3)&&(SAMBA_VERSION_MINOR<9)) +int main(void) +{ + if (!torture_local_replace(NULL)) { + printf("ERROR: TESTSUITE FAILED\n"); + return -1; + } + return 0; +} +#endif -- cgit From 7e310277ff5cb8fcef17e28422db2a99cf3841d3 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 2 Oct 2006 10:37:17 +0000 Subject: r19034: merge from samba4: prepare libreplace testsuite for usage in smbtorture metze (This used to be commit 281677084e022336877dd141befd508a0b5c08a9) --- source3/lib/replace/test/testsuite.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source3/lib/replace/test/testsuite.c') diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c index 6644fce6bd..fa5265f66f 100644 --- a/source3/lib/replace/test/testsuite.c +++ b/source3/lib/replace/test/testsuite.c @@ -89,7 +89,7 @@ static int test_strlcpy(void) char buf[4]; const struct { const char *src; - int result; + size_t result; } tests[] = { { "abc", 3 }, { "abcdef", 6 }, @@ -373,9 +373,11 @@ static int test_MAX(void) return true; } -int torture_local_replace(void *ctx) +struct torture_context; + +bool torture_local_replace(struct torture_context *torture) { - int ret = true; + bool ret = true; ret &= test_ftruncate(); ret &= test_strlcpy(); ret &= test_strlcat(); @@ -423,7 +425,7 @@ int torture_local_replace(void *ctx) return ret; } -#if !defined(_SAMBA_BUILD_) || ((SAMBA_VERSION_MAJOR==3)&&(SAMBA_VERSION_MINOR<9)) +#if _SAMBA_BUILD_<4 int main(void) { if (!torture_local_replace(NULL)) { -- cgit From 803d33a3266497f89edd9bfae92875a9afdd0df2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 6 Oct 2006 12:00:23 +0000 Subject: r19125: merge from samba4 (This used to be commit 65e1500ae6b5ca6334a63f4a18272568202bc048) --- source3/lib/replace/test/testsuite.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source3/lib/replace/test/testsuite.c') diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c index fa5265f66f..d45304103f 100644 --- a/source3/lib/replace/test/testsuite.c +++ b/source3/lib/replace/test/testsuite.c @@ -231,14 +231,12 @@ static int test_opendir(void) extern int test_readdir_os2_delete(void); -static bool test_readdir(void) +static int test_readdir(void) { printf("testing readdir\n"); if (test_readdir_os2_delete() != 0) { return false; } - - /* FIXME */ return true; } @@ -400,7 +398,7 @@ bool torture_local_replace(struct torture_context *torture) ret &= test_vasprintf(); ret &= test_vsnprintf(); ret &= test_opendir(); - ret &= test_readdir() ; + ret &= test_readdir(); ret &= test_telldir(); ret &= test_seekdir(); ret &= test_dlopen(); -- cgit From 55ed1d59455566d90a03e7123fbf7a05a4bd4539 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Tue, 19 Dec 2006 20:16:52 +0000 Subject: r20261: merge 20260 from samba_3_0_24 clean up a bunch of no previous prototype warnings (This used to be commit c60687db112405262adf26dbf267804b04074e67) --- source3/lib/replace/test/testsuite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/replace/test/testsuite.c') diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c index d45304103f..c10a220d7b 100644 --- a/source3/lib/replace/test/testsuite.c +++ b/source3/lib/replace/test/testsuite.c @@ -373,7 +373,7 @@ static int test_MAX(void) struct torture_context; -bool torture_local_replace(struct torture_context *torture) +static bool torture_local_replace(struct torture_context *torture) { bool ret = true; ret &= test_ftruncate(); -- cgit From 2f66beb8adf679ed1e2e36f9c808c43f095e23cf Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 15 Jan 2007 19:10:54 +0000 Subject: r20817: sync lib/replace with samba4 metze (This used to be commit 352ee730308bbc151a742938818c9b8b3a6e8014) --- source3/lib/replace/test/testsuite.c | 79 ++++++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 17 deletions(-) (limited to 'source3/lib/replace/test/testsuite.c') diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c index c10a220d7b..8a9fb9ab87 100644 --- a/source3/lib/replace/test/testsuite.c +++ b/source3/lib/replace/test/testsuite.c @@ -57,26 +57,29 @@ static int test_ftruncate(void) struct stat st; int fd; const int size = 1234; - printf("testing ftruncate\n"); + printf("test: ftruncate\n"); unlink(TESTFILE); fd = open(TESTFILE, O_RDWR|O_CREAT, 0600); if (fd == -1) { - printf("creating '%s' failed - %s\n", TESTFILE, strerror(errno)); + printf("failure: ftruncate [\n" + "creating '%s' failed - %s\n]\n", TESTFILE, strerror(errno)); return false; } if (ftruncate(fd, size) != 0) { - printf("ftruncate failed - %s\n", strerror(errno)); + printf("failure: ftruncate [\n%s\n]\n", strerror(errno)); return false; } if (fstat(fd, &st) != 0) { - printf("fstat failed - %s\n", strerror(errno)); + printf("failure: ftruncate [\nfstat failed - %s\n]\n", strerror(errno)); return false; } if (st.st_size != size) { - printf("ftruncate gave wrong size %d - expected %d\n", + printf("failure: ftruncate [\ngave wrong size %d - expected %d\n]\n", (int)st.st_size, size); return false; } + unlink(TESTFILE); + printf("success: ftruncate\n"); return true; } @@ -98,13 +101,14 @@ static int test_strlcpy(void) { NULL, 0 } }; int i; - printf("testing strlcpy\n"); + printf("test: 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); + printf("failure: strlcpy [\ntest %d failed\n]\n", i); return false; } } + printf("success: strlcpy\n"); return true; } @@ -146,8 +150,9 @@ static int test_strdup(void) static int test_setlinebuf(void) { - printf("testing setlinebuf\n"); + printf("test: setlinebuf\n"); setlinebuf(stdout); + printf("success: setlinebuf\n"); return true; } @@ -233,10 +238,11 @@ extern int test_readdir_os2_delete(void); static int test_readdir(void) { - printf("testing readdir\n"); + printf("test: readdir\n"); if (test_readdir_os2_delete() != 0) { return false; } + printf("success: readdir\n"); return true; } @@ -371,9 +377,48 @@ static int test_MAX(void) return true; } -struct torture_context; +static int test_socketpair(void) +{ + int sock[2]; + char buf[20]; + + printf("test: socketpair\n"); + + if (socketpair(AF_UNIX, SOCK_STREAM, 0, sock) == -1) { + printf("failure: socketpair [\n" + "socketpair() failed\n" + "]\n"); + return false; + } + + if (write(sock[1], "automatisch", 12) == -1) { + printf("failure: socketpair [\n" + "write() failed: %s\n" + "]\n", strerror(errno)); + return false; + } + + if (read(sock[0], buf, 12) == -1) { + printf("failure: socketpair [\n" + "read() failed: %s\n" + "]\n", strerror(errno)); + return false; + } + + if (strcmp(buf, "automatisch") != 0) { + printf("failure: socketpair [\n" + "expected: automatisch, got: %s\n" + "]\n", buf); + return false; + } + + printf("success: socketpair\n"); -static bool torture_local_replace(struct torture_context *torture) + return true; +} + +struct torture_context; +bool torture_local_replace(struct torture_context *ctx) { bool ret = true; ret &= test_ftruncate(); @@ -419,17 +464,17 @@ static bool torture_local_replace(struct torture_context *torture) ret &= test_FUNCTION(); ret &= test_MIN(); ret &= test_MAX(); + ret &= test_socketpair(); return ret; } #if _SAMBA_BUILD_<4 -int main(void) +int main() { - if (!torture_local_replace(NULL)) { - printf("ERROR: TESTSUITE FAILED\n"); - return -1; - } - return 0; + bool ret = torture_local_replace(NULL); + if (ret) + return 0; + return -1; } #endif -- cgit From 14ddce8b64b559e0db25e2b79dd16d8f3d9aff26 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 15 Jan 2007 19:28:02 +0000 Subject: r20820: merge from samba4: - include system/aio.h - use full prototype for main - use ifdef instead if metze (This used to be commit 024dd7d7c95bcf8d77914dc2063f16220358e690) --- source3/lib/replace/test/testsuite.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/lib/replace/test/testsuite.c') diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c index 8a9fb9ab87..effbdb13ef 100644 --- a/source3/lib/replace/test/testsuite.c +++ b/source3/lib/replace/test/testsuite.c @@ -46,6 +46,7 @@ #include "system/terminal.h" #include "system/time.h" #include "system/wait.h" +#include "system/aio.h" #define TESTFILE "testfile.dat" @@ -470,7 +471,7 @@ bool torture_local_replace(struct torture_context *ctx) } #if _SAMBA_BUILD_<4 -int main() +int main(void) { bool ret = torture_local_replace(NULL); if (ret) -- cgit From 1ec9de1104f4563a5f3dbb96d41908d219e5b889 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 10 Apr 2007 15:59:39 +0000 Subject: r22151: remove netgr functions from libreplace they're not used in samba4 currently and samba3 has explicit configure checks for them. should fix bug #4496 metze (This used to be commit 7f61b3f0095efed81adc9022ba44e5c7df84d2f2) --- source3/lib/replace/test/testsuite.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'source3/lib/replace/test/testsuite.c') diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c index effbdb13ef..293ea84946 100644 --- a/source3/lib/replace/test/testsuite.c +++ b/source3/lib/replace/test/testsuite.c @@ -125,12 +125,6 @@ static int test_mktime(void) return true; } -static int test_innetgr(void) -{ - /* FIXME */ - return true; -} - static int test_initgroups(void) { /* FIXME */ @@ -426,7 +420,6 @@ bool torture_local_replace(struct torture_context *ctx) ret &= test_strlcpy(); ret &= test_strlcat(); ret &= test_mktime(); - ret &= test_innetgr(); ret &= test_initgroups(); ret &= test_memmove(); ret &= test_strdup(); -- cgit From 2f1aafa2a7e36298cc1e0e593b30fac1ab278596 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sun, 15 Apr 2007 20:12:09 +0000 Subject: r22221: merge from samba4: - libreplace unsetenv() and strptime() replacements metze (This used to be commit 057c1c04d09b48c713ebc0b334cabcefc02561e9) --- source3/lib/replace/test/testsuite.c | 226 +++++++++++++++++++++++++++++++++-- 1 file changed, 214 insertions(+), 12 deletions(-) (limited to 'source3/lib/replace/test/testsuite.c') diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c index 293ea84946..7d45feec6b 100644 --- a/source3/lib/replace/test/testsuite.c +++ b/source3/lib/replace/test/testsuite.c @@ -115,7 +115,27 @@ static int test_strlcpy(void) static int test_strlcat(void) { - /* FIXME */ + char tmp[10]; + printf("test: strlcat\n"); + strcpy(tmp, ""); + if (strlcat(tmp, "bla", 3) != 3) { + printf("failure: strlcat [\ninvalid return code\n]\n"); + return false; + } + if (strcmp(tmp, "bl") != 0) { + printf("failure: strlcat [\nexpected \"bl\", got \"%s\"\n]\n", + tmp); + return false; + } + + strcpy(tmp, "da"); + if (strlcat(tmp, "me", 4) != 4) { + printf("failure: strlcat [\nexpected \"dam\", got \"%s\"\n]\n", + tmp); + return false; + } + + printf("success: strlcat\n"); return true; } @@ -139,7 +159,16 @@ static int test_memmove(void) static int test_strdup(void) { - /* FIXME */ + char *x; + printf("test: strdup\n"); + x = strdup("bla"); + if (strcmp("bla", x) != 0) { + printf("failure: strdup [\nfailed: expected \"bla\", got \"%s\"\n]\n", + x); + return false; + } + free(x); + printf("success: strdup\n"); return true; } @@ -165,19 +194,109 @@ static int test_timegm(void) static int test_setenv(void) { - /* FIXME */ +#define TEST_SETENV(key, value, overwrite, result) do { \ + int _ret; \ + char *_v; \ + _ret = setenv(key, value, overwrite); \ + if (_ret != 0) { \ + printf("failure: setenv [\n" \ + "setenv(%s, %s, %d) failed\n" \ + "]\n", \ + key, value, overwrite); \ + return false; \ + } \ + _v=getenv(key); \ + if (!_v) { \ + printf("failure: setenv [\n" \ + "getenv(%s) returned NULL\n" \ + "]\n", \ + key); \ + return false; \ + } \ + if (strcmp(result, _v) != 0) { \ + printf("failure: setenv [\n" \ + "getenv(%s): '%s' != '%s'\n" \ + "]\n", \ + key, result, _v); \ + return false; \ + } \ +} while(0) + +#define TEST_UNSETENV(key) do { \ + char *_v; \ + unsetenv(key); \ + _v=getenv(key); \ + if (_v) { \ + printf("failure: setenv [\n" \ + "getenv(%s): NULL != '%s'\n" \ + "]\n", \ + SETENVTEST_KEY, _v); \ + return false; \ + } \ +} while (0) + +#define SETENVTEST_KEY "SETENVTESTKEY" +#define SETENVTEST_VAL "SETENVTESTVAL" + + printf("test: setenv\n"); + TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"1", 0, SETENVTEST_VAL"1"); + TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"2", 0, SETENVTEST_VAL"1"); + TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"3", 1, SETENVTEST_VAL"3"); + TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"4", 1, SETENVTEST_VAL"4"); + TEST_UNSETENV(SETENVTEST_KEY); + TEST_UNSETENV(SETENVTEST_KEY); + TEST_SETENV(SETENVTEST_KEY, SETENVTEST_VAL"5", 0, SETENVTEST_VAL"5"); + TEST_UNSETENV(SETENVTEST_KEY); + TEST_UNSETENV(SETENVTEST_KEY); + printf("success: setenv\n"); return true; } static int test_strndup(void) { - /* FIXME */ + char *x; + printf("test: strndup\n"); + x = strndup("bla", 0); + if (strcmp(x, "") != 0) { + printf("failure: strndup [\ninvalid\n]\n"); + return false; + } + free(x); + x = strndup("bla", 2); + if (strcmp(x, "bl") != 0) { + printf("failure: strndup [\ninvalid\n]\n"); + return false; + } + free(x); + x = strndup("bla", 10); + if (strcmp(x, "bla") != 0) { + printf("failure: strndup [\ninvalid\n]\n"); + return false; + } + free(x); + printf("success: strndup\n"); return true; } static int test_strnlen(void) { - /* FIXME */ + printf("test: strnlen\n"); + if (strnlen("bla", 2) != 2) { + printf("failure: strnlen [\nunexpected length\n]\n"); + return false; + } + + if (strnlen("some text\n", 0) != 0) { + printf("failure: strnlen [\nunexpected length\n]\n"); + return false; + } + + if (strnlen("some text", 20) != 9) { + printf("failure: strnlen [\nunexpected length\n]\n"); + return false; + } + + printf("success: strnlen\n"); return true; } @@ -201,13 +320,43 @@ static int test_setegid(void) static int test_asprintf(void) { - /* FIXME */ + char *x; + printf("test: asprintf\n"); + if (asprintf(&x, "%d", 9) != 1) { + printf("failure: asprintf [\ngenerate asprintf\n]\n"); + return false; + } + if (strcmp(x, "9") != 0) { + printf("failure: asprintf [\ngenerate asprintf\n]\n"); + return false; + } + if (asprintf(&x, "dat%s", "a") != 4) { + printf("failure: asprintf [\ngenerate asprintf\n]\n"); + return false; + } + if (strcmp(x, "data") != 0) { + printf("failure: asprintf [\ngenerate asprintf\n]\n"); + return false; + } + printf("success: asprintf\n"); return true; } static int test_snprintf(void) { - /* FIXME */ + char tmp[10]; + printf("test: snprintf\n"); + if (snprintf(tmp, 3, "foo%d", 9) != 4) { + printf("failure: snprintf [\nsnprintf return code failed\n]\n"); + return false; + } + + if (strcmp(tmp, "fo") != 0) { + printf("failure: snprintf [\nsnprintf failed\n]\n"); + return false; + } + + printf("success: snprintf\n"); return true; } @@ -274,13 +423,22 @@ static int test_bzero(void) static int test_strerror(void) { + printf("test: strerror\n"); /* FIXME */ + printf("failure: sterror\n"); return true; } static int test_errno(void) { - /* FIXME */ + printf("test: errno\n"); + errno = 3; + if (errno != 3) { + printf("failure: errno [\nerrno failed\n]\n"); + return false; + } + + printf("success: errno\n"); return true; } @@ -322,7 +480,20 @@ static int test_inet_ntoa(void) static int test_strtoll(void) { - /* FIXME */ + printf("test: strtoll\n"); + if (strtoll("15", NULL, 10) != 15) { + printf("failure: strtoll [\nstrtoll failed\n]\n"); + return false; + } + if (strtoll("10", NULL, 16) != 16) { + printf("failure: strtoll [\nstrtoll hex failed\n]\n"); + return false; + } + if (strtoll("11", NULL, 2) != 3) { + printf("failure: strtoll [\nstrtoll binary failed\n]\n"); + return false; + } + printf("success: strtoll\n"); return true; } @@ -356,19 +527,42 @@ static int test_va_copy(void) static int test_FUNCTION(void) { - /* FIXME: test __FUNCTION__ macro */ + printf("test: FUNCTION\n"); + if (strcmp(__FUNCTION__, "test_FUNCTION") != 0) { + printf("failure: FAILURE [\nFAILURE invalid\n]\n"); + return false; + } + printf("success: FUNCTION\n"); return true; } static int test_MIN(void) { - /* FIXME */ + printf("test: MIN\n"); + if (MIN(20, 1) != 1) { + printf("failure: MIN [\nMIN invalid\n]\n"); + return false; + } + if (MIN(1, 20) != 1) { + printf("failure: MIN [\nMIN invalid\n]\n"); + return false; + } + printf("success: MIN\n"); return true; } static int test_MAX(void) { - /* FIXME */ + printf("test: MAX\n"); + if (MAX(20, 1) != 20) { + printf("failure: MAX [\nMAX invalid\n]\n"); + return false; + } + if (MAX(1, 20) != 20) { + printf("failure: MAX [\nMAX invalid\n]\n"); + return false; + } + printf("success: MAX\n"); return true; } @@ -412,6 +606,13 @@ static int test_socketpair(void) return true; } +extern int libreplace_test_strptime(void); + +static int test_strptime(void) +{ + return libreplace_test_strptime(); +} + struct torture_context; bool torture_local_replace(struct torture_context *ctx) { @@ -459,6 +660,7 @@ bool torture_local_replace(struct torture_context *ctx) ret &= test_MIN(); ret &= test_MAX(); ret &= test_socketpair(); + ret &= test_strptime(); return ret; } -- cgit From fb72736e6e067b2a2b469d498c0c62c328dbf82d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 16 Apr 2007 06:08:43 +0000 Subject: r22240: merge from samba4: use strlcpy instead of strcpy to make the IBM checker happy metze (This used to be commit fe4be25c3056260049a8052e072500756bf14fce) --- source3/lib/replace/test/testsuite.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/replace/test/testsuite.c') diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c index 7d45feec6b..165d222261 100644 --- a/source3/lib/replace/test/testsuite.c +++ b/source3/lib/replace/test/testsuite.c @@ -117,7 +117,7 @@ static int test_strlcat(void) { char tmp[10]; printf("test: strlcat\n"); - strcpy(tmp, ""); + strlcpy(tmp, "", sizeof(tmp)); if (strlcat(tmp, "bla", 3) != 3) { printf("failure: strlcat [\ninvalid return code\n]\n"); return false; @@ -128,7 +128,7 @@ static int test_strlcat(void) return false; } - strcpy(tmp, "da"); + strlcpy(tmp, "da", sizeof(tmp)); if (strlcat(tmp, "me", 4) != 4) { printf("failure: strlcat [\nexpected \"dam\", got \"%s\"\n]\n", tmp); -- cgit From 9cda609e86963f7a0e5aea6701d1a06d7780685b Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 16 Apr 2007 06:30:08 +0000 Subject: r22244: merge from samba4: remove useless printf's metze (This used to be commit cf7c57eae5671cd15f0cee0173c7b05a8a8ba055) --- source3/lib/replace/test/testsuite.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/lib/replace/test/testsuite.c') diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c index 165d222261..4c21de7aa3 100644 --- a/source3/lib/replace/test/testsuite.c +++ b/source3/lib/replace/test/testsuite.c @@ -423,9 +423,7 @@ static int test_bzero(void) static int test_strerror(void) { - printf("test: strerror\n"); /* FIXME */ - printf("failure: sterror\n"); return true; } -- cgit From 38bbe9a5da132b078f9a290a4145cb6c7a666259 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 16 Apr 2007 07:41:01 +0000 Subject: r22247: merge from samba4: only test strtoll once metze (This used to be commit 17088fd644ef68ac2e96ed1246339b65943d63d0) --- source3/lib/replace/test/testsuite.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/lib/replace/test/testsuite.c') diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c index 4c21de7aa3..a394810f61 100644 --- a/source3/lib/replace/test/testsuite.c +++ b/source3/lib/replace/test/testsuite.c @@ -651,7 +651,6 @@ bool torture_local_replace(struct torture_context *ctx) ret &= test_getpass(); ret &= test_inet_ntoa(); ret &= test_strtoll(); - ret &= test_strtoll(); ret &= test_strtoull(); ret &= test_va_copy(); ret &= test_FUNCTION(); -- cgit From b97c8658d530381ffe6bcab87173b9362c756d4b Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 16 Apr 2007 09:44:00 +0000 Subject: r22254: merge from samba4: - make the strtoll tests more verbose - add initial strtoull tests metze (This used to be commit 9865d3165d629c56a24d9fa5ee993f4b04ba12de) --- source3/lib/replace/test/testsuite.c | 63 ++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 7 deletions(-) (limited to 'source3/lib/replace/test/testsuite.c') diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c index a394810f61..025e5256f9 100644 --- a/source3/lib/replace/test/testsuite.c +++ b/source3/lib/replace/test/testsuite.c @@ -478,26 +478,75 @@ static int test_inet_ntoa(void) static int test_strtoll(void) { + int64_t v; + printf("test: strtoll\n"); - if (strtoll("15", NULL, 10) != 15) { - printf("failure: strtoll [\nstrtoll failed\n]\n"); + + v = strtoll("15", NULL, 10); + if (v != 15) { + printf("failure: strtoll [\n" + "strtoll failed: %lld != 15\n" + "]\n", + v); return false; } - if (strtoll("10", NULL, 16) != 16) { - printf("failure: strtoll [\nstrtoll hex failed\n]\n"); + + v = strtoll("10", NULL, 16); + if (v != 16) { + printf("failure: strtoll [\n" + "strtoll hex failed: %lld != 16\n" + "]\n", + v); return false; } - if (strtoll("11", NULL, 2) != 3) { - printf("failure: strtoll [\nstrtoll binary failed\n]\n"); + + v = strtoll("11", NULL, 2); + if (v != 3) { + printf("failure: strtoll [\n" + "strtoll binary failed: %lld != 3\n" + "]\n", + v); return false; } + printf("success: strtoll\n"); return true; } static int test_strtoull(void) { - /* FIXME */ + uint64_t v; + + printf("test: strtoull\n"); + + v = strtoull("15", NULL, 10); + if (v != 15) { + printf("failure: strtoull [\n" + "strtoull failed: %llu != 15\n" + "]\n", + v); + return false; + } + + v = strtoull("10", NULL, 16); + if (v != 16) { + printf("failure: strtoull [\n" + "strtoull hex failed: %llu != 16\n" + "]\n", + v); + return false; + } + + v = strtoull("11", NULL, 2); + if (v != 3) { + printf("failure: strtoull [\n" + "strtoull binary failed: %llu != 3\n" + "]\n", + v); + return false; + } + + printf("success: strtuoll\n"); return true; } -- cgit From 5a22df2a5c088791116bedcbee3d33b1d7f42746 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 16 Apr 2007 19:56:42 +0000 Subject: r22280: merge from samba4: add a lot more detailed strtoll() and strtoull() tests metze (This used to be commit 737b445007109e3005e4c5fb278b56f00b8c157d) --- source3/lib/replace/test/testsuite.c | 310 ++++++++++++++++++++++++++++------- 1 file changed, 254 insertions(+), 56 deletions(-) (limited to 'source3/lib/replace/test/testsuite.c') diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c index 025e5256f9..2d068c559f 100644 --- a/source3/lib/replace/test/testsuite.c +++ b/source3/lib/replace/test/testsuite.c @@ -476,38 +476,140 @@ static int test_inet_ntoa(void) return true; } +#define TEST_STRTO_X(type,fmt,func,str,base,res,diff,rrnoo) do {\ + type _v; \ + char _s[64]; \ + char *_p = NULL;\ + char *_ep = NULL; \ + strlcpy(_s, str, sizeof(_s));\ + if (diff >= 0) { \ + _ep = &_s[diff]; \ + } \ + errno = 0; \ + _v = func(_s, &_p, base); \ + if (errno != rrnoo) { \ + printf("failure: %s [\n" \ + "\t%s\n" \ + "\t%s(\"%s\",%d,%d): " fmt " (=/!)= " fmt "\n" \ + "\terrno: %d != %d\n" \ + "]\n", \ + __STRING(func), __location__, __STRING(func), \ + str, diff, base, res, _v, rrnoo, errno); \ + return false; \ + } else if (_v != res) { \ + printf("failure: %s [\n" \ + "\t%s\n" \ + "\t%s(\"%s\",%d,%d): " fmt " != " fmt "\n" \ + "]\n", \ + __STRING(func), __location__, __STRING(func), \ + str, diff, base, res, _v); \ + return false; \ + } else if (_p != _ep) { \ + printf("failure: %s [\n" \ + "\t%s\n" \ + "\t%s(\"%s\",%d,%d): " fmt " (=/!)= " fmt "\n" \ + "\tptr: %p - %p = %d != %d\n" \ + "]\n", \ + __STRING(func), __location__, __STRING(func), \ + str, diff, base, res, _v, _ep, _p, diff - (_ep - _p), diff); \ + return false; \ + } \ +} while (0) + static int test_strtoll(void) { - int64_t v; - printf("test: strtoll\n"); - v = strtoll("15", NULL, 10); - if (v != 15) { - printf("failure: strtoll [\n" - "strtoll failed: %lld != 15\n" - "]\n", - v); - return false; - } - - v = strtoll("10", NULL, 16); - if (v != 16) { - printf("failure: strtoll [\n" - "strtoll hex failed: %lld != 16\n" - "]\n", - v); - return false; - } - - v = strtoll("11", NULL, 2); - if (v != 3) { - printf("failure: strtoll [\n" - "strtoll binary failed: %lld != 3\n" - "]\n", - v); - return false; - } +#define TEST_STRTOLL(str,base,res,diff,errnoo) TEST_STRTO_X(int64_t, "%lld", strtoll,str,base,res,diff,errnoo) + + TEST_STRTOLL("15", 10, 15LL, 2, 0); + TEST_STRTOLL(" 15", 10, 15LL, 4, 0); + TEST_STRTOLL("15", 0, 15LL, 2, 0); + TEST_STRTOLL(" 15 ", 0, 15LL, 3, 0); + TEST_STRTOLL("+15", 10, 15LL, 3, 0); + TEST_STRTOLL(" +15", 10, 15LL, 5, 0); + TEST_STRTOLL("+15", 0, 15LL, 3, 0); + TEST_STRTOLL(" +15 ", 0, 15LL, 4, 0); + TEST_STRTOLL("-15", 10, -15LL, 3, 0); + TEST_STRTOLL(" -15", 10, -15LL, 5, 0); + TEST_STRTOLL("-15", 0, -15LL, 3, 0); + TEST_STRTOLL(" -15 ", 0, -15LL, 4, 0); + TEST_STRTOLL("015", 10, 15LL, 3, 0); + TEST_STRTOLL(" 015", 10, 15LL, 5, 0); + TEST_STRTOLL("015", 0, 13LL, 3, 0); + TEST_STRTOLL(" 015", 0, 13LL, 5, 0); + TEST_STRTOLL("0x15", 10, 0LL, 1, 0); + TEST_STRTOLL(" 0x15", 10, 0LL, 3, 0); + TEST_STRTOLL("0x15", 0, 21LL, 4, 0); + TEST_STRTOLL(" 0x15", 0, 21LL, 6, 0); + + TEST_STRTOLL("10", 16, 16LL, 2, 0); + TEST_STRTOLL(" 10 ", 16, 16LL, 4, 0); + TEST_STRTOLL("0x10", 16, 16LL, 4, 0); + TEST_STRTOLL("0x10", 0, 16LL, 4, 0); + TEST_STRTOLL(" 0x10 ", 0, 16LL, 5, 0); + TEST_STRTOLL("+10", 16, 16LL, 3, 0); + TEST_STRTOLL(" +10 ", 16, 16LL, 5, 0); + TEST_STRTOLL("+0x10", 16, 16LL, 5, 0); + TEST_STRTOLL("+0x10", 0, 16LL, 5, 0); + TEST_STRTOLL(" +0x10 ", 0, 16LL, 6, 0); + TEST_STRTOLL("-10", 16, -16LL, 3, 0); + TEST_STRTOLL(" -10 ", 16, -16LL, 5, 0); + TEST_STRTOLL("-0x10", 16, -16LL, 5, 0); + TEST_STRTOLL("-0x10", 0, -16LL, 5, 0); + TEST_STRTOLL(" -0x10 ", 0, -16LL, 6, 0); + TEST_STRTOLL("010", 16, 16LL, 3, 0); + TEST_STRTOLL(" 010 ", 16, 16LL, 5, 0); + TEST_STRTOLL("-010", 16, -16LL, 4, 0); + + TEST_STRTOLL("11", 8, 9LL, 2, 0); + TEST_STRTOLL("011", 8, 9LL, 3, 0); + TEST_STRTOLL("011", 0, 9LL, 3, 0); + TEST_STRTOLL("-11", 8, -9LL, 3, 0); + TEST_STRTOLL("-011", 8, -9LL, 4, 0); + TEST_STRTOLL("-011", 0, -9LL, 4, 0); + + TEST_STRTOLL("011", 8, 9LL, 3, 0); + TEST_STRTOLL("011", 0, 9LL, 3, 0); + TEST_STRTOLL("-11", 8, -9LL, 3, 0); + TEST_STRTOLL("-011", 8, -9LL, 4, 0); + TEST_STRTOLL("-011", 0, -9LL, 4, 0); + + TEST_STRTOLL("Text", 0, 0LL, 0, 0); + + TEST_STRTOLL("9223372036854775807", 10, 9223372036854775807LL, 19, 0); + TEST_STRTOLL("9223372036854775807", 0, 9223372036854775807LL, 19, 0); + TEST_STRTOLL("9223372036854775808", 0, 9223372036854775807LL, 19, ERANGE); + TEST_STRTOLL("9223372036854775808", 10, 9223372036854775807LL, 19, ERANGE); + TEST_STRTOLL("0x7FFFFFFFFFFFFFFF", 0, 9223372036854775807LL, 18, 0); + TEST_STRTOLL("0x7FFFFFFFFFFFFFFF", 16, 9223372036854775807LL, 18, 0); + TEST_STRTOLL("7FFFFFFFFFFFFFFF", 16, 9223372036854775807LL, 16, 0); + TEST_STRTOLL("0x8000000000000000", 0, 9223372036854775807LL, 18, ERANGE); + TEST_STRTOLL("0x8000000000000000", 16, 9223372036854775807LL, 18, ERANGE); + TEST_STRTOLL("80000000000000000", 16, 9223372036854775807LL, 17, ERANGE); + TEST_STRTOLL("0777777777777777777777", 0, 9223372036854775807LL, 22, 0); + TEST_STRTOLL("0777777777777777777777", 8, 9223372036854775807LL, 22, 0); + TEST_STRTOLL("777777777777777777777", 8, 9223372036854775807LL, 21, 0); + TEST_STRTOLL("01000000000000000000000", 0, 9223372036854775807LL, 23, ERANGE); + TEST_STRTOLL("01000000000000000000000", 8, 9223372036854775807LL, 23, ERANGE); + TEST_STRTOLL("1000000000000000000000", 8, 9223372036854775807LL, 22, ERANGE); + + TEST_STRTOLL("-9223372036854775808", 10, -9223372036854775807LL -1, 20, 0); + TEST_STRTOLL("-9223372036854775808", 0, -9223372036854775807LL -1, 20, 0); + TEST_STRTOLL("-9223372036854775809", 0, -9223372036854775807LL -1, 20, ERANGE); + TEST_STRTOLL("-9223372036854775809", 10, -9223372036854775807LL -1, 20, ERANGE); + TEST_STRTOLL("-0x8000000000000000", 0, -9223372036854775807LL -1, 19, 0); + TEST_STRTOLL("-0x8000000000000000", 16, -9223372036854775807LL -1, 19, 0); + TEST_STRTOLL("-8000000000000000", 16, -9223372036854775807LL -1, 17, 0); + TEST_STRTOLL("-0x8000000000000001", 0, -9223372036854775807LL -1, 19, ERANGE); + TEST_STRTOLL("-0x8000000000000001", 16, -9223372036854775807LL -1, 19, ERANGE); + TEST_STRTOLL("-80000000000000001", 16, -9223372036854775807LL -1, 18, ERANGE); + TEST_STRTOLL("-01000000000000000000000",0, -9223372036854775807LL -1, 24, 0); + TEST_STRTOLL("-01000000000000000000000",8, -9223372036854775807LL -1, 24, 0); + TEST_STRTOLL("-1000000000000000000000", 8, -9223372036854775807LL -1, 23, 0); + TEST_STRTOLL("-01000000000000000000001",0, -9223372036854775807LL -1, 24, ERANGE); + TEST_STRTOLL("-01000000000000000000001",8, -9223372036854775807LL -1, 24, ERANGE); + TEST_STRTOLL("-1000000000000000000001", 8, -9223372036854775807LL -1, 23, ERANGE); printf("success: strtoll\n"); return true; @@ -515,36 +617,132 @@ static int test_strtoll(void) static int test_strtoull(void) { - uint64_t v; - printf("test: strtoull\n"); - v = strtoull("15", NULL, 10); - if (v != 15) { - printf("failure: strtoull [\n" - "strtoull failed: %llu != 15\n" - "]\n", - v); - return false; - } - - v = strtoull("10", NULL, 16); - if (v != 16) { - printf("failure: strtoull [\n" - "strtoull hex failed: %llu != 16\n" - "]\n", - v); - return false; - } - - v = strtoull("11", NULL, 2); - if (v != 3) { - printf("failure: strtoull [\n" - "strtoull binary failed: %llu != 3\n" - "]\n", - v); - return false; - } +#define TEST_STRTOULL(str,base,res,diff,errnoo) TEST_STRTO_X(uint64_t,"%llu",strtoull,str,base,res,diff,errnoo) + + TEST_STRTOULL("15", 10, 15LLU, 2, 0); + TEST_STRTOULL(" 15", 10, 15LLU, 4, 0); + TEST_STRTOULL("15", 0, 15LLU, 2, 0); + TEST_STRTOULL(" 15 ", 0, 15LLU, 3, 0); + TEST_STRTOULL("+15", 10, 15LLU, 3, 0); + TEST_STRTOULL(" +15", 10, 15LLU, 5, 0); + TEST_STRTOULL("+15", 0, 15LLU, 3, 0); + TEST_STRTOULL(" +15 ", 0, 15LLU, 4, 0); + TEST_STRTOULL("-15", 10, 18446744073709551601LLU, 3, 0); + TEST_STRTOULL(" -15", 10, 18446744073709551601LLU, 5, 0); + TEST_STRTOULL("-15", 0, 18446744073709551601LLU, 3, 0); + TEST_STRTOULL(" -15 ", 0, 18446744073709551601LLU, 4, 0); + TEST_STRTOULL("015", 10, 15LLU, 3, 0); + TEST_STRTOULL(" 015", 10, 15LLU, 5, 0); + TEST_STRTOULL("015", 0, 13LLU, 3, 0); + TEST_STRTOULL(" 015", 0, 13LLU, 5, 0); + TEST_STRTOULL("0x15", 10, 0LLU, 1, 0); + TEST_STRTOULL(" 0x15", 10, 0LLU, 3, 0); + TEST_STRTOULL("0x15", 0, 21LLU, 4, 0); + TEST_STRTOULL(" 0x15", 0, 21LLU, 6, 0); + + TEST_STRTOULL("10", 16, 16LLU, 2, 0); + TEST_STRTOULL(" 10 ", 16, 16LLU, 4, 0); + TEST_STRTOULL("0x10", 16, 16LLU, 4, 0); + TEST_STRTOULL("0x10", 0, 16LLU, 4, 0); + TEST_STRTOULL(" 0x10 ", 0, 16LLU, 5, 0); + TEST_STRTOULL("+10", 16, 16LLU, 3, 0); + TEST_STRTOULL(" +10 ", 16, 16LLU, 5, 0); + TEST_STRTOULL("+0x10", 16, 16LLU, 5, 0); + TEST_STRTOULL("+0x10", 0, 16LLU, 5, 0); + TEST_STRTOULL(" +0x10 ", 0, 16LLU, 6, 0); + TEST_STRTOULL("-10", 16, -16LLU, 3, 0); + TEST_STRTOULL(" -10 ", 16, -16LLU, 5, 0); + TEST_STRTOULL("-0x10", 16, -16LLU, 5, 0); + TEST_STRTOULL("-0x10", 0, -16LLU, 5, 0); + TEST_STRTOULL(" -0x10 ", 0, -16LLU, 6, 0); + TEST_STRTOULL("010", 16, 16LLU, 3, 0); + TEST_STRTOULL(" 010 ", 16, 16LLU, 5, 0); + TEST_STRTOULL("-010", 16, -16LLU, 4, 0); + + TEST_STRTOULL("11", 8, 9LLU, 2, 0); + TEST_STRTOULL("011", 8, 9LLU, 3, 0); + TEST_STRTOULL("011", 0, 9LLU, 3, 0); + TEST_STRTOULL("-11", 8, -9LLU, 3, 0); + TEST_STRTOULL("-011", 8, -9LLU, 4, 0); + TEST_STRTOULL("-011", 0, -9LLU, 4, 0); + + TEST_STRTOULL("011", 8, 9LLU, 3, 0); + TEST_STRTOULL("011", 0, 9LLU, 3, 0); + TEST_STRTOULL("-11", 8, -9LLU, 3, 0); + TEST_STRTOULL("-011", 8, -9LLU, 4, 0); + TEST_STRTOULL("-011", 0, -9LLU, 4, 0); + + TEST_STRTOULL("Text", 0, 0LLU, 0, 0); + + TEST_STRTOULL("9223372036854775807", 10, 9223372036854775807LLU, 19, 0); + TEST_STRTOULL("9223372036854775807", 0, 9223372036854775807LLU, 19, 0); + TEST_STRTOULL("9223372036854775808", 0, 9223372036854775808LLU, 19, 0); + TEST_STRTOULL("9223372036854775808", 10, 9223372036854775808LLU, 19, 0); + TEST_STRTOULL("0x7FFFFFFFFFFFFFFF", 0, 9223372036854775807LLU, 18, 0); + TEST_STRTOULL("0x7FFFFFFFFFFFFFFF", 16, 9223372036854775807LLU, 18, 0); + TEST_STRTOULL("7FFFFFFFFFFFFFFF", 16, 9223372036854775807LLU, 16, 0); + TEST_STRTOULL("0x8000000000000000", 0, 9223372036854775808LLU, 18, 0); + TEST_STRTOULL("0x8000000000000000", 16, 9223372036854775808LLU, 18, 0); + TEST_STRTOULL("8000000000000000", 16, 9223372036854775808LLU, 16, 0); + TEST_STRTOULL("0777777777777777777777", 0, 9223372036854775807LLU, 22, 0); + TEST_STRTOULL("0777777777777777777777", 8, 9223372036854775807LLU, 22, 0); + TEST_STRTOULL("777777777777777777777", 8, 9223372036854775807LLU, 21, 0); + TEST_STRTOULL("01000000000000000000000",0, 9223372036854775808LLU, 23, 0); + TEST_STRTOULL("01000000000000000000000",8, 9223372036854775808LLU, 23, 0); + TEST_STRTOULL("1000000000000000000000", 8, 9223372036854775808LLU, 22, 0); + + TEST_STRTOULL("-9223372036854775808", 10, 9223372036854775808LLU, 20, 0); + TEST_STRTOULL("-9223372036854775808", 0, 9223372036854775808LLU, 20, 0); + TEST_STRTOULL("-9223372036854775809", 0, 9223372036854775807LLU, 20, 0); + TEST_STRTOULL("-9223372036854775809", 10, 9223372036854775807LLU, 20, 0); + TEST_STRTOULL("-0x8000000000000000", 0, 9223372036854775808LLU, 19, 0); + TEST_STRTOULL("-0x8000000000000000", 16, 9223372036854775808LLU, 19, 0); + TEST_STRTOULL("-8000000000000000", 16, 9223372036854775808LLU, 17, 0); + TEST_STRTOULL("-0x8000000000000001", 0, 9223372036854775807LLU, 19, 0); + TEST_STRTOULL("-0x8000000000000001", 16, 9223372036854775807LLU, 19, 0); + TEST_STRTOULL("-8000000000000001", 16, 9223372036854775807LLU, 17, 0); + TEST_STRTOULL("-01000000000000000000000",0, 9223372036854775808LLU, 24, 0); + TEST_STRTOULL("-01000000000000000000000",8, 9223372036854775808LLU, 24, 0); + TEST_STRTOULL("-1000000000000000000000",8, 9223372036854775808LLU, 23, 0); + TEST_STRTOULL("-01000000000000000000001",0, 9223372036854775807LLU, 24, 0); + TEST_STRTOULL("-01000000000000000000001",8, 9223372036854775807LLU, 24, 0); + TEST_STRTOULL("-1000000000000000000001",8, 9223372036854775807LLU, 23, 0); + + TEST_STRTOULL("18446744073709551615", 0, 18446744073709551615LLU, 20, 0); + TEST_STRTOULL("18446744073709551615", 10, 18446744073709551615LLU, 20, 0); + TEST_STRTOULL("18446744073709551616", 0, 18446744073709551615LLU, 20, ERANGE); + TEST_STRTOULL("18446744073709551616", 10, 18446744073709551615LLU, 20, ERANGE); + TEST_STRTOULL("0xFFFFFFFFFFFFFFFF", 0, 18446744073709551615LLU, 18, 0); + TEST_STRTOULL("0xFFFFFFFFFFFFFFFF", 16, 18446744073709551615LLU, 18, 0); + TEST_STRTOULL("FFFFFFFFFFFFFFFF", 16, 18446744073709551615LLU, 16, 0); + TEST_STRTOULL("0x10000000000000000", 0, 18446744073709551615LLU, 19, ERANGE); + TEST_STRTOULL("0x10000000000000000", 16, 18446744073709551615LLU, 19, ERANGE); + TEST_STRTOULL("10000000000000000", 16, 18446744073709551615LLU, 17, ERANGE); + TEST_STRTOULL("01777777777777777777777",0, 18446744073709551615LLU, 23, 0); + TEST_STRTOULL("01777777777777777777777",8, 18446744073709551615LLU, 23, 0); + TEST_STRTOULL("1777777777777777777777", 8, 18446744073709551615LLU, 22, 0); + TEST_STRTOULL("02000000000000000000000",0, 18446744073709551615LLU, 23, ERANGE); + TEST_STRTOULL("02000000000000000000000",8, 18446744073709551615LLU, 23, ERANGE); + TEST_STRTOULL("2000000000000000000000", 8, 18446744073709551615LLU, 22, ERANGE); + + TEST_STRTOULL("-18446744073709551615", 0, 1LLU, 21, 0); + TEST_STRTOULL("-18446744073709551615", 10, 1LLU, 21, 0); + TEST_STRTOULL("-18446744073709551616", 0, 18446744073709551615LLU, 21, ERANGE); + TEST_STRTOULL("-18446744073709551616", 10, 18446744073709551615LLU, 21, ERANGE); + TEST_STRTOULL("-0xFFFFFFFFFFFFFFFF", 0, 1LLU, 19, 0); + TEST_STRTOULL("-0xFFFFFFFFFFFFFFFF", 16, 1LLU, 19, 0); + TEST_STRTOULL("-FFFFFFFFFFFFFFFF", 16, 1LLU, 17, 0); + TEST_STRTOULL("-0x10000000000000000", 0, 18446744073709551615LLU, 20, ERANGE); + TEST_STRTOULL("-0x10000000000000000", 16, 18446744073709551615LLU, 20, ERANGE); + TEST_STRTOULL("-10000000000000000", 16, 18446744073709551615LLU, 18, ERANGE); + TEST_STRTOULL("-01777777777777777777777",0, 1LLU, 24, 0); + TEST_STRTOULL("-01777777777777777777777",8, 1LLU, 24, 0); + TEST_STRTOULL("-1777777777777777777777",8, 1LLU, 23, 0); + TEST_STRTOULL("-02000000000000000000000",0, 18446744073709551615LLU, 24, ERANGE); + TEST_STRTOULL("-02000000000000000000000",8, 18446744073709551615LLU, 24, ERANGE); + TEST_STRTOULL("-2000000000000000000000",8, 18446744073709551615LLU, 23, ERANGE); printf("success: strtuoll\n"); return true; -- cgit From c5bcb4b31a1bb6eb14910318abff99f7fff9ba78 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 4 May 2007 06:59:26 +0000 Subject: r22659: merge from SAMBA_4_0: - add AC_GNU_SOURCE macro for systems which don't have it (sles8) - fix compiler warning on some systems metze (This used to be commit cb785d9bed23fdf930bbd059eeeba5bde04af829) --- source3/lib/replace/test/testsuite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/replace/test/testsuite.c') diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c index 2d068c559f..54ffd6a66d 100644 --- a/source3/lib/replace/test/testsuite.c +++ b/source3/lib/replace/test/testsuite.c @@ -511,7 +511,7 @@ static int test_inet_ntoa(void) "\tptr: %p - %p = %d != %d\n" \ "]\n", \ __STRING(func), __location__, __STRING(func), \ - str, diff, base, res, _v, _ep, _p, diff - (_ep - _p), diff); \ + str, diff, base, res, _v, _ep, _p, (int)(diff - (_ep - _p)), diff); \ return false; \ } \ } while (0) -- cgit From 2c09988e46d4e917b1c53c9bda3f81a48bba4952 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 01:44:42 +0000 Subject: r23790: LGPLv3+ conversion for our LGPLv2+ library code (This used to be commit 1b78cace504f60c0f525765fbf59d9cc6506cd4d) --- source3/lib/replace/test/testsuite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/replace/test/testsuite.c') diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c index 54ffd6a66d..48d597ce89 100644 --- a/source3/lib/replace/test/testsuite.c +++ b/source3/lib/replace/test/testsuite.c @@ -12,7 +12,7 @@ This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. + version 3 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -- cgit From 9fa1c63578733077c0aaaeeb2fc97c3b191089cc Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 03:42:26 +0000 Subject: r23798: updated old Temple Place FSF addresses to new URL (This used to be commit c676a971142d7176fd5dbf21405fca14515a0a76) --- source3/lib/replace/test/testsuite.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/replace/test/testsuite.c') diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c index 48d597ce89..9b684f31bb 100644 --- a/source3/lib/replace/test/testsuite.c +++ b/source3/lib/replace/test/testsuite.c @@ -20,8 +20,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + License along with this library; if not, see . */ #include "replace.h" -- cgit From 63acef8e46bee853b8c110984db974460f6e1beb Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 26 Jul 2007 07:48:14 +0000 Subject: r24054: Fix some warnings (This used to be commit ed84540bb2825dfaca25649a1cfb9342b68c3068) --- source3/lib/replace/test/testsuite.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/replace/test/testsuite.c') diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c index 9b684f31bb..8584bcaa66 100644 --- a/source3/lib/replace/test/testsuite.c +++ b/source3/lib/replace/test/testsuite.c @@ -519,7 +519,7 @@ static int test_strtoll(void) { printf("test: strtoll\n"); -#define TEST_STRTOLL(str,base,res,diff,errnoo) TEST_STRTO_X(int64_t, "%lld", strtoll,str,base,res,diff,errnoo) +#define TEST_STRTOLL(str,base,res,diff,errnoo) TEST_STRTO_X(long long int, "%lld", strtoll,str,base,res,diff,errnoo) TEST_STRTOLL("15", 10, 15LL, 2, 0); TEST_STRTOLL(" 15", 10, 15LL, 4, 0); @@ -618,7 +618,7 @@ static int test_strtoull(void) { printf("test: strtoull\n"); -#define TEST_STRTOULL(str,base,res,diff,errnoo) TEST_STRTO_X(uint64_t,"%llu",strtoull,str,base,res,diff,errnoo) +#define TEST_STRTOULL(str,base,res,diff,errnoo) TEST_STRTO_X(long long unsigned int,"%llu",strtoull,str,base,res,diff,errnoo) TEST_STRTOULL("15", 10, 15LLU, 2, 0); TEST_STRTOULL(" 15", 10, 15LLU, 4, 0); -- cgit From 68edc3a5c5a3cfeed222a95bbe75dadd41dbb5ea Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 19 Sep 2007 14:57:20 +0000 Subject: r25232: sync lib/replace with SAMBA_4_0 metze (This used to be commit 828d2ca0610ab5ee3b96d187b3432b9b4fea72f8) --- source3/lib/replace/test/testsuite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/replace/test/testsuite.c') diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c index 8584bcaa66..269a2ff5d6 100644 --- a/source3/lib/replace/test/testsuite.c +++ b/source3/lib/replace/test/testsuite.c @@ -743,7 +743,7 @@ static int test_strtoull(void) TEST_STRTOULL("-02000000000000000000000",8, 18446744073709551615LLU, 24, ERANGE); TEST_STRTOULL("-2000000000000000000000",8, 18446744073709551615LLU, 23, ERANGE); - printf("success: strtuoll\n"); + printf("success: strtoull\n"); return true; } -- cgit From a2bfb1749ca7bc0c713d3508c1324799245c7d1a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 22 Nov 2007 14:42:14 +0100 Subject: r26102: libreplace: remove system/printing.h as it only contains samba3 stuff metze (cherry picked from commit 1ecb4ec01b0506c95a5f90a62040329e7a39ee93) (This used to be commit ff8a001f0d3f2655efafed41f2f0b14552a5c7e7) --- source3/lib/replace/test/testsuite.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/lib/replace/test/testsuite.c') diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c index 269a2ff5d6..5b95ae395c 100644 --- a/source3/lib/replace/test/testsuite.c +++ b/source3/lib/replace/test/testsuite.c @@ -37,7 +37,6 @@ #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" -- cgit From d0d4fc5f5412bcf2977afc01edee92107e995c80 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 16 Dec 2007 02:49:52 +0100 Subject: r26468: Match getifaddrs more closely, add trivial test. (cherry picked from commit 92898c043b5a2649a2e423d02bcdaea78ae55737) (This used to be commit 3f9c0c210022905c7811b2e07b3b655929daf930) --- source3/lib/replace/test/testsuite.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'source3/lib/replace/test/testsuite.c') diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c index 5b95ae395c..c9f3301005 100644 --- a/source3/lib/replace/test/testsuite.c +++ b/source3/lib/replace/test/testsuite.c @@ -856,6 +856,25 @@ static int test_strptime(void) return libreplace_test_strptime(); } +static int test_getifaddrs(void) +{ + struct ifaddrs *ifa; + int ret; + + printf("test: getifaddrs\n"); + + ret = getifaddrs(&ifa); + if (ret != 0) { + printf("failure: getifaddrs\n"); + return false; + } + + freeifaddrs(ifa); + + printf("success: getifaddrs\n"); + return true; +} + struct torture_context; bool torture_local_replace(struct torture_context *ctx) { @@ -903,6 +922,7 @@ bool torture_local_replace(struct torture_context *ctx) ret &= test_MAX(); ret &= test_socketpair(); ret &= test_strptime(); + ret &= test_getifaddrs(); return ret; } -- cgit From d24f3b8a9367cb3903e1d76fa66a14389554da33 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 28 Feb 2008 21:43:06 +0100 Subject: libreplace: add extended getifaddrs test that prints out the interfaces. Michael cherry-picked from libreplace-part of 9d2bab09aac22c00fe23f1e1265a2dbd0901e9ce and adapted replacetort creation (This used to be commit 52d79ad4872a20cf55f31aba97629c2561bfc16c) --- source3/lib/replace/test/testsuite.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'source3/lib/replace/test/testsuite.c') diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c index c9f3301005..b538360365 100644 --- a/source3/lib/replace/test/testsuite.c +++ b/source3/lib/replace/test/testsuite.c @@ -856,21 +856,18 @@ static int test_strptime(void) return libreplace_test_strptime(); } +extern int getifaddrs_test(void); + static int test_getifaddrs(void) { - struct ifaddrs *ifa; - int ret; printf("test: getifaddrs\n"); - ret = getifaddrs(&ifa); - if (ret != 0) { + if (getifaddrs_test() != 0) { printf("failure: getifaddrs\n"); return false; } - freeifaddrs(ifa); - printf("success: getifaddrs\n"); return true; } -- cgit From db4ab7aae3b44b22b70013f13da370b74d429553 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 7 May 2008 13:10:31 +0200 Subject: libreplace: always provide utime() and utimes() I'd like to also provide futimes(), but it seems that some systems doesn't support a it at kernel level. If someone knows how to write a portable replacement for futimes() please tell me... metze (cherry picked from commit a9604fe4a323dccb537cf02ea7594437b4995803) (This used to be commit 8a241cf150fba787c82cbcb03730083ced442fbb) --- source3/lib/replace/test/testsuite.c | 145 +++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) (limited to 'source3/lib/replace/test/testsuite.c') diff --git a/source3/lib/replace/test/testsuite.c b/source3/lib/replace/test/testsuite.c index b538360365..1e8290906e 100644 --- a/source3/lib/replace/test/testsuite.c +++ b/source3/lib/replace/test/testsuite.c @@ -872,6 +872,149 @@ static int test_getifaddrs(void) return true; } +static int test_utime(void) +{ + struct utimbuf u; + struct stat st1, st2, st3; + int fd; + + printf("test: utime\n"); + unlink(TESTFILE); + + fd = open(TESTFILE, O_RDWR|O_CREAT, 0600); + if (fd == -1) { + printf("failure: utime [\n" + "creating '%s' failed - %s\n]\n", + TESTFILE, strerror(errno)); + return false; + } + + if (fstat(fd, &st1) != 0) { + printf("failure: utime [\n" + "fstat (1) failed - %s\n]\n", + strerror(errno)); + return false; + } + + u.actime = st1.st_atime + 300; + u.modtime = st1.st_mtime - 300; + if (utime(TESTFILE, &u) != 0) { + printf("failure: utime [\n" + "utime(&u) failed - %s\n]\n", + strerror(errno)); + return false; + } + + if (fstat(fd, &st2) != 0) { + printf("failure: utime [\n" + "fstat (2) failed - %s\n]\n", + strerror(errno)); + return false; + } + + if (utime(TESTFILE, NULL) != 0) { + printf("failure: utime [\n" + "utime(NULL) failed - %s\n]\n", + strerror(errno)); + return false; + } + + if (fstat(fd, &st3) != 0) { + printf("failure: utime [\n" + "fstat (3) failed - %s\n]\n", + strerror(errno)); + return false; + } + +#define CMP_VAL(a,c,b) do { \ + if (a c b) { \ + printf("failure: utime [\n" \ + "%s: %s(%d) %s %s(%d)\n]\n", \ + __location__, \ + #a, (int)a, #c, #b, (int)b); \ + return false; \ + } \ +} while(0) +#define EQUAL_VAL(a,b) CMP_VAL(a,!=,b) +#define GREATER_VAL(a,b) CMP_VAL(a,<=,b) +#define LESSER_VAL(a,b) CMP_VAL(a,>=,b) + + EQUAL_VAL(st2.st_atime, st1.st_atime + 300); + EQUAL_VAL(st2.st_mtime, st1.st_mtime - 300); + LESSER_VAL(st3.st_atime, st2.st_atime); + GREATER_VAL(st3.st_mtime, st2.st_mtime); + +#undef CMP_VAL +#undef EQUAL_VAL +#undef GREATER_VAL +#undef LESSER_VAL + + unlink(TESTFILE); + printf("success: utime\n"); + return true; +} + +static int test_utimes(void) +{ + struct timeval tv[2]; + struct stat st1, st2; + int fd; + + printf("test: utimes\n"); + unlink(TESTFILE); + + fd = open(TESTFILE, O_RDWR|O_CREAT, 0600); + if (fd == -1) { + printf("failure: utimes [\n" + "creating '%s' failed - %s\n]\n", + TESTFILE, strerror(errno)); + return false; + } + + if (fstat(fd, &st1) != 0) { + printf("failure: utimes [\n" + "fstat (1) failed - %s\n]\n", + strerror(errno)); + return false; + } + + ZERO_STRUCT(tv); + tv[0].tv_sec = st1.st_atime + 300; + tv[1].tv_sec = st1.st_mtime - 300; + if (utimes(TESTFILE, tv) != 0) { + printf("failure: utimes [\n" + "utimes(tv) failed - %s\n]\n", + strerror(errno)); + return false; + } + + if (fstat(fd, &st2) != 0) { + printf("failure: utimes [\n" + "fstat (2) failed - %s\n]\n", + strerror(errno)); + return false; + } + +#define EQUAL_VAL(a,b) do { \ + if (a != b) { \ + printf("failure: utimes [\n" \ + "%s: %s(%d) != %s(%d)\n]\n", \ + __location__, \ + #a, (int)a, #b, (int)b); \ + return false; \ + } \ +} while(0) + + EQUAL_VAL(st2.st_atime, st1.st_atime + 300); + EQUAL_VAL(st2.st_mtime, st1.st_mtime - 300); + +#undef EQUAL_VAL + + unlink(TESTFILE); + printf("success: utimes\n"); + return true; +} + struct torture_context; bool torture_local_replace(struct torture_context *ctx) { @@ -920,6 +1063,8 @@ bool torture_local_replace(struct torture_context *ctx) ret &= test_socketpair(); ret &= test_strptime(); ret &= test_getifaddrs(); + ret &= test_utime(); + ret &= test_utimes(); return ret; } -- cgit