annotate src/lib/test-utc-mktime.c @ 22955:812e5c961328

fts: Indexing virtual mailbox didn't always index the last mails
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 03 May 2018 18:33:00 +0300
parents cb108f786fb4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22713
cb108f786fb4 Updated copyright notices to include the year 2018.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21668
diff changeset
1 /* Copyright (c) 2007-2018 Dovecot authors, see the included COPYING file */
9425
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "test-lib.h"
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "utc-mktime.h"
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5
21662
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
6 struct test_utc_mktime {
9425
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 int year, month, day, hour, min, sec;
21662
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
8 time_t out;
9425
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 };
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 void test_utc_mktime(void)
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 {
21662
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
13 static const struct test_utc_mktime tests[] = {
9425
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 #ifdef TIME_T_SIGNED
21662
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
15 { 1969, 12, 31, 23, 59, 59, -1 },
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
16 { 1901, 12, 13, 20, 45, 53, -2147483647 },
9425
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 #endif
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 #if (TIME_T_MAX_BITS > 32 || !defined(TIME_T_SIGNED))
21662
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
19 { 2106, 2, 7, 6, 28, 15, 4294967295 },
21668
e26f2729d135 lib: Fix again test-utc-mktime with 32bit time_t
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21664
diff changeset
20 { 2038, 1, 19, 3, 14, 8, 2147483648 },
9425
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 #endif
21662
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
22 { 2007, 11, 7, 1, 7, 20, 1194397640 },
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
23 { 1970, 1, 1, 0, 0, 0, 0 },
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
24 { 2038, 1, 19, 3, 14, 7, 2147483647 },
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
25 { INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, INT_MAX, -1 },
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
26 { 2106, 2, 7, 6, 28, 15, 4294967295 },
21664
1cfecca4693d lib: Fix test-utc-mktime with 32bit time_t
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21662
diff changeset
27 #if TIME_T_MAX_BITS > 32
21662
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
28 { 2106, 2, 7, 6, 28, 16, 4294967296 },
21664
1cfecca4693d lib: Fix test-utc-mktime with 32bit time_t
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21662
diff changeset
29 #endif
21661
c4584d7dc07e lib: Accept leap second in utc_mktime
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21390
diff changeset
30 /* June leap second */
21662
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
31 { 2015, 6, 30, 23, 59, 59, 1435708799 },
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
32 { 2015, 6, 30, 23, 59, 60, 1435708799 },
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
33 { 2015, 7, 1, 0, 0, 0, 1435708800 },
21661
c4584d7dc07e lib: Accept leap second in utc_mktime
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21390
diff changeset
34 /* Invalid leap second */
21662
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
35 { 2017, 1, 24, 16, 40, 60, 1485276059 },
21661
c4584d7dc07e lib: Accept leap second in utc_mktime
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21390
diff changeset
36 /* Dec leap second */
21662
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
37 { 2016, 12, 31, 23, 59, 59, 1483228799 },
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
38 { 2016, 12, 31, 23, 59, 60, 1483228799 },
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
39 { 2017, 1, 1, 0, 0, 0, 1483228800 },
9425
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40 };
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 struct tm tm;
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42 unsigned int i;
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
43 time_t t;
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 bool success;
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45
21662
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
46 for (i = 0; i < N_ELEMENTS(tests); i++) {
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
47 const struct test_utc_mktime *test = &tests[i];
21389
59437f8764c6 global: Replaced all instances of memset(p, 0, sizeof(*p)) with the new i_zero() macro.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 19552
diff changeset
48 i_zero(&tm);
21662
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
49 tm.tm_year = test->year - 1900;
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
50 tm.tm_mon = test->month - 1;
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
51 tm.tm_mday = test->day;
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
52 tm.tm_hour = test->hour;
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
53 tm.tm_min = test->min;
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
54 tm.tm_sec = test->sec;
9425
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56 t = utc_mktime(&tm);
21662
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
57 success = t == test->out;
9425
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58 test_out_reason(t_strdup_printf("utc_mktime(%d)", i), success,
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59 success ? NULL : t_strdup_printf("%ld != %ld",
21662
4f63ef17d9dc lib: Place input/output of utc_mktime tests in one struct
Martti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
parents: 21661
diff changeset
60 (long)t, (long)test->out));
9425
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 }
810e36796e3d liblib unit tests are now split to separate files.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 }