summaryrefslogtreecommitdiff
path: root/common/t-gettime.c
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2021-02-09 15:59:53 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2021-02-09 15:59:53 +0900
commit929e941c10903b80c933e483a1610240bd52286d (patch)
tree60316c32d86e29c55a03306f7b44eb0c18ca2921 /common/t-gettime.c
parentf65267827a88ffd96a41c708e90f4a38b2bc15d3 (diff)
downloadgpg2-929e941c10903b80c933e483a1610240bd52286d.tar.gz
gpg2-929e941c10903b80c933e483a1610240bd52286d.tar.bz2
gpg2-929e941c10903b80c933e483a1610240bd52286d.zip
Imported Upstream version 2.1.0upstream/2.1.0
Diffstat (limited to 'common/t-gettime.c')
-rw-r--r--common/t-gettime.c94
1 files changed, 89 insertions, 5 deletions
diff --git a/common/t-gettime.c b/common/t-gettime.c
index a4401d8..5d554ee 100644
--- a/common/t-gettime.c
+++ b/common/t-gettime.c
@@ -1,5 +1,5 @@
/* t-gettime.c - Module test for gettime.c
- * Copyright (C) 2007 Free Software Foundation, Inc.
+ * Copyright (C) 2007, 2011 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -67,8 +67,8 @@ test_isotime2epoch (void)
{
fail (idx);
if (verbose)
- fprintf (stderr, "string `%s' exp: %ld got: %ld\n",
- array[idx].string, (long)array[idx].expected,
+ fprintf (stderr, "string '%s' exp: %ld got: %ld\n",
+ array[idx].string, (long)array[idx].expected,
(long)val);
}
if (array[idx].expected != INVALID)
@@ -77,7 +77,7 @@ test_isotime2epoch (void)
if (strlen (tbuf) != 15)
{
if (verbose)
- fprintf (stderr, "string `%s', time-t %ld, revert: `%s'\n",
+ fprintf (stderr, "string '%s', time-t %ld, revert: '%s'\n",
array[idx].string, (long)val, tbuf);
fail (idx);
}
@@ -89,6 +89,90 @@ test_isotime2epoch (void)
+static void
+test_string2isotime (void)
+{
+ struct {
+ const char *string;
+ size_t result;
+ const char *expected;
+ } array [] = {
+ { "19700101T000001", 15, "19700101T000001" },
+ { "19700101T235959", 15, "19700101T235959" },
+ { "19980815T143712", 15, "19980815T143712" },
+ { "19700101T000000", 15, "19700101T000000" },
+ { "19691231T235959", 15, "19691231T235959" },
+ { "19000101T000000", 15, "19000101T000000" },
+ { "", 0, "" },
+ { "19000101T00000", 0, "" },
+ { "20010101t123456", 0, "" },
+ { "20010101T123456", 15, "20010101T123456" },
+ { "20070629T160000", 15, "20070629T160000" },
+ { "20070629T160000:", 15, "20070629T160000" },
+ { "20070629T160000,", 15, "20070629T160000" },
+ { "20070629T160000 ", 15, "20070629T160000" },
+ { "20070629T160000\n", 15,"20070629T160000" },
+ { "20070629T160000.", 0, "" },
+ { "1066-03-20", 10, "10660320T000000" },
+ { "1066-03-20,", 10, "10660320T000000" },
+ { "1066-03-20:", 0, "" },
+ { "1066-03-20 00", 13, "10660320T000000" },
+ { "1066-03-20 01", 13, "10660320T010000" },
+ { "1066-03-20 23", 13, "10660320T230000" },
+ { "1066-03-20 24", 0, "" },
+ { "1066-03-20 00:", 0, "" },
+ { "1066-03-20 00:3", 0, "" },
+ { "1066-03-20 00:31", 16, "10660320T003100" },
+ { "1066-03-20 00:31:47", 19, "10660320T003147" },
+ { "1066-03-20 00:31:47 ", 19, "10660320T003147" },
+ { "1066-03-20 00:31:47,", 19, "10660320T003147" },
+ { "1066-03-20 00:31:47:", 0, "" },
+ { "1-03-20 00:31:47:", 0, "" },
+ { "10-03-20 00:31:47:", 0, "" },
+ { "106-03-20 00:31:47:", 0, "" },
+ { "1066-23-20 00:31:47:", 0, "" },
+ { "1066-00-20 00:31:47:", 0, "" },
+ { "1066-0-20 00:31:47:", 0, "" },
+ { "1066-01-2 00:31:47:", 0, "" },
+ { "1066-01-2 00:31:47:", 0, "" },
+ { "1066-01-32 00:31:47:", 0, "" },
+ { "1066-01-00 00:31:47:", 0, "" },
+ { "1066-03-20 00:31:47:",11, "10660320T000000" },
+ { "1066-03-2000:31:47:", 0, "" },
+ { "10666-03-20 00:31:47:", 0, "" },
+ { NULL, 0 }
+ };
+ int idx;
+ size_t result;
+ gnupg_isotime_t tbuf;
+
+ for (idx=0; array[idx].string; idx++)
+ {
+ result = string2isotime (tbuf, array[idx].string);
+ if (result != array[idx].result)
+ {
+ fail (idx);
+ if (verbose)
+ fprintf (stderr, "string '%s' expected: %d, got: %d\n",
+ array[idx].string, (int)array[idx].result, (int)result);
+ }
+ else if (result && strlen (tbuf) != 15)
+ {
+ fail (idx);
+ if (verbose)
+ fprintf (stderr, "string '%s' invalid isotime returned\n",
+ array[idx].string);
+ }
+ else if (result && strcmp (array[idx].expected, tbuf))
+ {
+ fail (idx);
+ if (verbose)
+ fprintf (stderr, "string '%s' bad isotime '%s' returned\n",
+ array[idx].string, tbuf);
+ }
+ }
+}
+
int
main (int argc, char **argv)
@@ -97,7 +181,7 @@ main (int argc, char **argv)
verbose = 1;
test_isotime2epoch ();
+ test_string2isotime ();
return !!errcount;
}
-