summaryrefslogtreecommitdiffstats
path: root/common/t-gettime.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2007-07-05 18:58:19 +0200
committerWerner Koch <wk@gnupg.org>2007-07-05 18:58:19 +0200
commit4631bc8ddf86b3917bf786c315273d8b1c7798e8 (patch)
tree2022343674f6703aefb41f2e142765ba319dbf5f /common/t-gettime.c
parent2007-07-05 Marcus Brinkmann <marcus@g10code.de> (diff)
downloadgnupg2-4631bc8ddf86b3917bf786c315273d8b1c7798e8.tar.xz
gnupg2-4631bc8ddf86b3917bf786c315273d8b1c7798e8.zip
Fixed card key generation of gpg2.
Reveal less information about timings while generating a key.
Diffstat (limited to 'common/t-gettime.c')
-rw-r--r--common/t-gettime.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/common/t-gettime.c b/common/t-gettime.c
new file mode 100644
index 000000000..495de37bd
--- /dev/null
+++ b/common/t-gettime.c
@@ -0,0 +1,98 @@
+/* t-gettime.c - Module test for gettime.c
+ * Copyright (C) 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "util.h"
+
+#define pass() do { ; } while(0)
+#define fail(a) do { fprintf (stderr, "%s:%d: test %d failed\n",\
+ __FILE__,__LINE__, (a)); \
+ errcount++; \
+ } while(0)
+
+static int verbose;
+static int errcount;
+#define INVALID ((time_t)(-1))
+
+
+static void
+test_isotime2epoch (void)
+{
+ struct { const char *string; time_t expected; } array [] = {
+ { "19700101T000001", 1 },
+ { "19700101T235959", 86399 },
+ { "19980815T143712", 903191832 },
+ { "19700101T000000", 0 },
+ { "19691231T235959", INVALID },
+ { "19000101T000000", INVALID },
+ { "", INVALID },
+ { "19000101T00000", INVALID },
+ { "20010101t123456", INVALID },
+ { "20010101T123456", 978352496 },
+ { "20070629T160000", 1183132800 },
+ { "20070629T160000:", 1183132800 },
+ { "20070629T160000,", 1183132800 },
+ { "20070629T160000 ", 1183132800 },
+ { "20070629T160000\n", 1183132800 },
+ { "20070629T160000.", INVALID },
+ { NULL, 0 }
+ };
+ int idx;
+ u32 val;
+ gnupg_isotime_t tbuf;
+
+ for (idx=0; array[idx].string; idx++)
+ {
+ val = isotime2epoch (array[idx].string);
+ if (val != array[idx].expected )
+ {
+ fail (idx);
+ if (verbose)
+ fprintf (stderr, "string `%s' exp: %ld got: %ld\n",
+ array[idx].string, (long)array[idx].expected,
+ (long)val);
+ }
+ if (array[idx].expected != INVALID)
+ {
+ epoch2isotime (tbuf, val);
+ if (strlen (tbuf) != 15)
+ fail (idx);
+ if (strncmp (array[idx].string, tbuf, 15))
+ fail (idx);
+ }
+ }
+}
+
+
+
+
+int
+main (int argc, char **argv)
+{
+ if (argc > 1 && !strcmp (argv[1], "--verbose"))
+ verbose = 1;
+
+ test_isotime2epoch ();
+
+ return !!errcount;
+}
+