1
/* t-gettime.c - Module test for gettime.c
2
* Copyright (C) 2007 Free Software Foundation, Inc.
4
* This file is part of GnuPG.
6
* GnuPG is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 3 of the License, or
9
* (at your option) any later version.
11
* GnuPG is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, see <http://www.gnu.org/licenses/>.
26
#define pass() do { ; } while(0)
27
#define fail(a) do { fprintf (stderr, "%s:%d: test %d failed\n",\
28
__FILE__,__LINE__, (a)); \
34
#define INVALID ((time_t)(-1))
38
test_isotime2epoch (void)
40
struct { const char *string; time_t expected; } array [] = {
41
{ "19700101T000001", 1 },
42
{ "19700101T235959", 86399 },
43
{ "19980815T143712", 903191832 },
44
{ "19700101T000000", 0 },
45
{ "19691231T235959", INVALID },
46
{ "19000101T000000", INVALID },
48
{ "19000101T00000", INVALID },
49
{ "20010101t123456", INVALID },
50
{ "20010101T123456", 978352496 },
51
{ "20070629T160000", 1183132800 },
52
{ "20070629T160000:", 1183132800 },
53
{ "20070629T160000,", 1183132800 },
54
{ "20070629T160000 ", 1183132800 },
55
{ "20070629T160000\n", 1183132800 },
56
{ "20070629T160000.", INVALID },
63
for (idx=0; array[idx].string; idx++)
65
val = isotime2epoch (array[idx].string);
66
if (val != array[idx].expected )
70
fprintf (stderr, "string `%s' exp: %ld got: %ld\n",
71
array[idx].string, (long)array[idx].expected,
74
if (array[idx].expected != INVALID)
76
epoch2isotime (tbuf, val);
77
if (strlen (tbuf) != 15)
79
if (strncmp (array[idx].string, tbuf, 15))
89
main (int argc, char **argv)
91
if (argc > 1 && !strcmp (argv[1], "--verbose"))
94
test_isotime2epoch ();