summaryrefslogtreecommitdiffstats
path: root/src/lib/test-utc-mktime.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:51:24 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:51:24 +0000
commitf7548d6d28c313cf80e6f3ef89aed16a19815df1 (patch)
treea3f6f2a3f247293bee59ecd28e8cd8ceb6ca064a /src/lib/test-utc-mktime.c
parentInitial commit. (diff)
downloaddovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.tar.xz
dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.zip
Adding upstream version 1:2.3.19.1+dfsg1.upstream/1%2.3.19.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/lib/test-utc-mktime.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/lib/test-utc-mktime.c b/src/lib/test-utc-mktime.c
new file mode 100644
index 0000000..157179b
--- /dev/null
+++ b/src/lib/test-utc-mktime.c
@@ -0,0 +1,61 @@
+/* Copyright (c) 2007-2018 Dovecot authors, see the included COPYING file */
+
+#include "test-lib.h"
+#include "utc-mktime.h"
+
+struct test_utc_mktime {
+ int year, month, day, hour, min, sec;
+ time_t out;
+};
+
+void test_utc_mktime(void)
+{
+ static const struct test_utc_mktime tests[] = {
+#ifdef TIME_T_SIGNED
+ { 1969, 12, 31, 23, 59, 59, -1 },
+ { 1901, 12, 13, 20, 45, 53, -2147483647 },
+#endif
+#if (TIME_T_MAX_BITS > 32 || !defined(TIME_T_SIGNED))
+ { 2106, 2, 7, 6, 28, 15, 4294967295 },
+ { 2038, 1, 19, 3, 14, 8, 2147483648 },
+#endif
+ { 2007, 11, 7, 1, 7, 20, 1194397640 },
+ { 1970, 1, 1, 0, 0, 0, 0 },
+ { 2038, 1, 19, 3, 14, 7, 2147483647 },
+ { INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, -1 },
+#if TIME_T_MAX_BITS > 32
+ { 2106, 2, 7, 6, 28, 16, 4294967296 },
+#endif
+ /* June leap second */
+ { 2015, 6, 30, 23, 59, 59, 1435708799 },
+ { 2015, 6, 30, 23, 59, 60, 1435708799 },
+ { 2015, 7, 1, 0, 0, 0, 1435708800 },
+ /* Invalid leap second */
+ { 2017, 1, 24, 16, 40, 60, 1485276059 },
+ /* Dec leap second */
+ { 2016, 12, 31, 23, 59, 59, 1483228799 },
+ { 2016, 12, 31, 23, 59, 60, 1483228799 },
+ { 2017, 1, 1, 0, 0, 0, 1483228800 },
+ };
+ struct tm tm;
+ unsigned int i;
+ time_t t;
+ bool success;
+
+ for (i = 0; i < N_ELEMENTS(tests); i++) {
+ const struct test_utc_mktime *test = &tests[i];
+ i_zero(&tm);
+ tm.tm_year = test->year - 1900;
+ tm.tm_mon = test->month - 1;
+ tm.tm_mday = test->day;
+ tm.tm_hour = test->hour;
+ tm.tm_min = test->min;
+ tm.tm_sec = test->sec;
+
+ t = utc_mktime(&tm);
+ success = t == test->out;
+ test_out_reason(t_strdup_printf("utc_mktime(%d)", i), success,
+ success ? NULL : t_strdup_printf("%ld != %ld",
+ (long)t, (long)test->out));
+ }
+}