Merge branch 'master' of ssh://git.samba.org/data/git/samba into regsrv
[kai/samba-autobuild/.git] / lib / util / tests / time.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    util time testing
5
6    Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "includes.h"
23 #include "torture/torture.h"
24
25 static bool test_null_time(struct torture_context *tctx)
26 {
27         torture_assert(tctx, null_time(0), "0");
28         torture_assert(tctx, null_time(0xFFFFFFFF), "0xFFFFFFFF");
29         torture_assert(tctx, null_time(-1), "-1");
30         torture_assert(tctx, !null_time(42), "42");
31         return true;
32 }
33
34 static bool test_null_nttime(struct torture_context *tctx)
35 {
36         torture_assert(tctx, null_nttime(-1), "-1");
37         torture_assert(tctx, null_nttime(-1), "-1");
38         torture_assert(tctx, !null_nttime(42), "42");
39         return true;
40 }
41
42
43 static bool test_http_timestring(struct torture_context *tctx)
44 {
45         const char *start = "Thu, 01 Jan 1970";
46         torture_assert(tctx, !strncmp(start, http_timestring(tctx, 42), 
47                                                                                  strlen(start)), "42");
48         torture_assert_str_equal(tctx, "never", 
49                                                          http_timestring(tctx, get_time_t_max()), "42");
50         return true;
51 }
52
53 static bool test_timestring(struct torture_context *tctx)
54 {
55         const char *start = "Thu Jan  1";
56         torture_assert(tctx, !strncmp(start, timestring(tctx, 42), strlen(start)),
57                                    "42");
58         return true;
59 }
60
61
62
63 struct torture_suite *torture_local_util_time(TALLOC_CTX *mem_ctx)
64 {
65         struct torture_suite *suite = torture_suite_create(mem_ctx, "TIME");
66
67         torture_suite_add_simple_test(suite, "null_time", test_null_time);
68         torture_suite_add_simple_test(suite, "null_nttime", test_null_nttime);
69         torture_suite_add_simple_test(suite, "http_timestring", 
70                                                                   test_http_timestring);
71         torture_suite_add_simple_test(suite, "timestring", 
72                                                                   test_timestring);
73
74         return suite;
75 }