2 Unix SMB/CIFS implementation.
6 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2008
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.
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.
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/>.
23 #include "torture/torture.h"
25 static bool test_null_time(struct torture_context
*tctx
)
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");
34 static bool test_null_nttime(struct torture_context
*tctx
)
36 torture_assert(tctx
, null_nttime(-1), "-1");
37 torture_assert(tctx
, null_nttime(-1), "-1");
38 torture_assert(tctx
, !null_nttime(42), "42");
43 static bool test_http_timestring(struct torture_context
*tctx
)
45 const char *start
= "Thu, 01 Jan 1970";
47 result
= http_timestring(tctx
, 42);
48 torture_assert(tctx
, !strncmp(start
, result
,
49 strlen(start
)), result
);
50 torture_assert_str_equal(tctx
, "never",
51 http_timestring(tctx
, get_time_t_max()), "42");
55 static bool test_timestring(struct torture_context
*tctx
)
57 const char *start
= "Thu Jan 1";
58 char *result
= timestring(tctx
, 42);
59 torture_assert(tctx
, !strncmp(start
, result
, strlen(start
)),
64 static bool test_get_time_zone(struct torture_context
*tctx
)
66 time_t t
= time(NULL
);
67 int old_extra_time_offset
= extra_time_offset
;
68 int old_offset
, new_offset
;
69 /* test that extra_time_offset works */
71 old_offset
= get_time_zone(t
);
72 extra_time_offset
= 42;
73 new_offset
= get_time_zone(t
);
74 extra_time_offset
= old_extra_time_offset
;
75 torture_assert_int_equal(tctx
, old_offset
+60*42, new_offset
,
76 "time offset not used");
81 struct torture_suite
*torture_local_util_time(TALLOC_CTX
*mem_ctx
)
83 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "TIME");
85 torture_suite_add_simple_test(suite
, "null_time", test_null_time
);
86 torture_suite_add_simple_test(suite
, "get_time_zone", test_get_time_zone
);
87 torture_suite_add_simple_test(suite
, "null_nttime", test_null_nttime
);
88 torture_suite_add_simple_test(suite
, "http_timestring",
89 test_http_timestring
);
90 torture_suite_add_simple_test(suite
, "timestring",