lib/tls: Change default supported TLS versions.
[Samba.git] / lib / util / tests / time.c
blobfce0eef5e2ed357b40d1244e65d3eeead270aae8
1 /*
2 Unix SMB/CIFS implementation.
4 util time testing
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/>.
22 #include "includes.h"
23 #include "torture/torture.h"
24 #include "torture/local/proto.h"
26 static bool test_null_time(struct torture_context *tctx)
28 torture_assert(tctx, null_time(0), "0");
29 torture_assert(tctx, null_time(0xFFFFFFFF), "0xFFFFFFFF");
30 torture_assert(tctx, null_time(-1), "-1");
31 torture_assert(tctx, !null_time(42), "42");
32 return true;
35 static bool test_null_nttime(struct torture_context *tctx)
37 torture_assert(tctx, null_nttime(-1), "-1");
38 torture_assert(tctx, null_nttime(-1), "-1");
39 torture_assert(tctx, !null_nttime(42), "42");
40 return true;
44 static bool test_http_timestring(struct torture_context *tctx)
46 const char *start = "Thu, 01 Jan 1970";
47 char *result;
49 * Correct test for negative UTC offset. Without the correction, the
50 * test fails when run on hosts with negative UTC offsets, as the date
51 * returned is back in 1969 (pre-epoch).
53 time_t now = time(NULL);
54 struct tm local = *localtime(&now);
55 struct tm gmt = *gmtime(&now);
56 time_t utc_offset = mktime(&local) - mktime(&gmt);
58 result = http_timestring(tctx, 42 - (utc_offset < 0 ? utc_offset : 0));
59 torture_assert(tctx, !strncmp(start, result,
60 strlen(start)), result);
61 torture_assert_str_equal(tctx, "never",
62 http_timestring(tctx, get_time_t_max()), "42");
63 return true;
66 static bool test_timestring(struct torture_context *tctx)
68 const char *start = "Thu Jan 1";
69 char *result;
71 * Correct test for negative UTC offset. Without the correction, the
72 * test fails when run on hosts with negative UTC offsets, as the date
73 * returned is back in 1969 (pre-epoch).
75 time_t now = time(NULL);
76 struct tm local = *localtime(&now);
77 struct tm gmt = *gmtime(&now);
78 time_t utc_offset = mktime(&local) - mktime(&gmt);
80 result = timestring(tctx, 42 - (utc_offset < 0 ? utc_offset : 0));
81 torture_assert(tctx, !strncmp(start, result, strlen(start)), result);
82 return true;
85 struct torture_suite *torture_local_util_time(TALLOC_CTX *mem_ctx)
87 struct torture_suite *suite = torture_suite_create(mem_ctx, "time");
89 torture_suite_add_simple_test(suite, "null_time", test_null_time);
90 torture_suite_add_simple_test(suite, "null_nttime", test_null_nttime);
91 torture_suite_add_simple_test(suite, "http_timestring",
92 test_http_timestring);
93 torture_suite_add_simple_test(suite, "timestring",
94 test_timestring);
96 return suite;