diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2008-10-11 23:25:35 +0200 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2008-10-11 23:25:35 +0200 |
commit | 75a36a9a5491b86aaa3b0983d5a2bd5d024f783a (patch) | |
tree | dd01216180a2e01081afb23f5d357cd2112bce86 | |
parent | bb33097fb79021c1a47bb4bc45c132020c47d6e4 (diff) | |
download | samba-75a36a9a5491b86aaa3b0983d5a2bd5d024f783a.tar.gz samba-75a36a9a5491b86aaa3b0983d5a2bd5d024f783a.tar.bz2 samba-75a36a9a5491b86aaa3b0983d5a2bd5d024f783a.zip |
Add some simple tests for lib/util/time.c
-rw-r--r-- | lib/util/tests/time.c | 75 | ||||
-rw-r--r-- | source4/torture/local/config.mk | 1 | ||||
-rw-r--r-- | source4/torture/local/local.c | 1 |
3 files changed, 77 insertions, 0 deletions
diff --git a/lib/util/tests/time.c b/lib/util/tests/time.c new file mode 100644 index 0000000000..4a31566b42 --- /dev/null +++ b/lib/util/tests/time.c @@ -0,0 +1,75 @@ +/* + Unix SMB/CIFS implementation. + + util time testing + + Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" +#include "torture/torture.h" + +static bool test_null_time(struct torture_context *tctx) +{ + torture_assert(tctx, null_time(0), "0"); + torture_assert(tctx, null_time(0xFFFFFFFF), "0xFFFFFFFF"); + torture_assert(tctx, null_time(-1), "-1"); + torture_assert(tctx, !null_time(42), "42"); + return true; +} + +static bool test_null_nttime(struct torture_context *tctx) +{ + torture_assert(tctx, null_nttime(-1), "-1"); + torture_assert(tctx, null_nttime(-1), "-1"); + torture_assert(tctx, !null_nttime(42), "42"); + return true; +} + + +static bool test_http_timestring(struct torture_context *tctx) +{ + const char *start = "Thu, 01 Jan 1970"; + torture_assert(tctx, !strncmp(start, http_timestring(tctx, 42), + strlen(start)), "42"); + torture_assert_str_equal(tctx, "never", + http_timestring(tctx, get_time_t_max()), "42"); + return true; +} + +static bool test_timestring(struct torture_context *tctx) +{ + const char *start = "Thu Jan 1"; + torture_assert(tctx, !strncmp(start, timestring(tctx, 42), strlen(start)), + "42"); + return true; +} + + + +struct torture_suite *torture_local_util_time(TALLOC_CTX *mem_ctx) +{ + struct torture_suite *suite = torture_suite_create(mem_ctx, "TIME"); + + torture_suite_add_simple_test(suite, "null_time", test_null_time); + torture_suite_add_simple_test(suite, "null_nttime", test_null_nttime); + torture_suite_add_simple_test(suite, "http_timestring", + test_http_timestring); + torture_suite_add_simple_test(suite, "timestring", + test_timestring); + + return suite; +} diff --git a/source4/torture/local/config.mk b/source4/torture/local/config.mk index 1f87912e8b..79df834525 100644 --- a/source4/torture/local/config.mk +++ b/source4/torture/local/config.mk @@ -34,6 +34,7 @@ TORTURE_LOCAL_OBJ_FILES = \ $(torturesrcdir)/../libcli/resolve/testsuite.o \ $(torturesrcdir)/../../lib/util/tests/strlist.o \ $(torturesrcdir)/../../lib/util/tests/str.o \ + $(torturesrcdir)/../../lib/util/tests/time.o \ $(torturesrcdir)/../../lib/util/tests/file.o \ $(torturesrcdir)/../../lib/util/tests/genrand.o \ $(torturesrcdir)/../../lib/compression/testsuite.o \ diff --git a/source4/torture/local/local.c b/source4/torture/local/local.c index fdefbbe131..9f390975ee 100644 --- a/source4/torture/local/local.c +++ b/source4/torture/local/local.c @@ -36,6 +36,7 @@ torture_local_util_strlist, torture_local_util_file, torture_local_util_str, + torture_local_util_time, torture_local_idtree, torture_local_genrand, torture_local_iconv, |