~ubuntu-branches/ubuntu/karmic/gnupg2/karmic-updates

« back to all changes in this revision

Viewing changes to common/t-gettime.c

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-10-04 10:25:53 UTC
  • mfrom: (5.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081004102553-fv62pp8dsitxli47
Tags: 2.0.9-3.1
* Non-maintainer upload.
* agent/gpg-agent.c: Deinit the threading library before exec'ing
  the command to run in --daemon mode. And because that still doesn't
  restore the sigprocmask, do that manually. Closes: #499569

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* t-gettime.c - Module test for gettime.c
 
2
 *      Copyright (C) 2007 Free Software Foundation, Inc.
 
3
 *
 
4
 * This file is part of GnuPG.
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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/>.
 
18
 */
 
19
 
 
20
#include <config.h>
 
21
#include <stdio.h>
 
22
#include <stdlib.h>
 
23
 
 
24
#include "util.h"
 
25
 
 
26
#define pass()  do { ; } while(0)
 
27
#define fail(a)  do { fprintf (stderr, "%s:%d: test %d failed\n",\
 
28
                               __FILE__,__LINE__, (a));          \
 
29
                     errcount++;                                 \
 
30
                   } while(0)
 
31
 
 
32
static int verbose;
 
33
static int errcount;
 
34
#define INVALID ((time_t)(-1))
 
35
 
 
36
 
 
37
static void
 
38
test_isotime2epoch (void)
 
39
{
 
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 },
 
47
    { "",                 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 },
 
57
    { NULL, 0 }
 
58
  };
 
59
  int idx;
 
60
  time_t val;
 
61
  gnupg_isotime_t tbuf;
 
62
 
 
63
  for (idx=0; array[idx].string; idx++)
 
64
    {
 
65
      val = isotime2epoch (array[idx].string);
 
66
      if (val != array[idx].expected )
 
67
        {
 
68
          fail (idx);
 
69
          if (verbose)
 
70
            fprintf (stderr, "string `%s' exp: %ld got: %ld\n",
 
71
                     array[idx].string, (long)array[idx].expected, 
 
72
                     (long)val);
 
73
        }
 
74
      if (array[idx].expected != INVALID)
 
75
        {
 
76
          epoch2isotime (tbuf, val);
 
77
          if (strlen (tbuf) != 15)
 
78
            fail (idx);
 
79
          if (strncmp (array[idx].string, tbuf, 15))
 
80
            fail (idx);
 
81
        }
 
82
    }
 
83
}
 
84
 
 
85
 
 
86
 
 
87
 
 
88
int
 
89
main (int argc, char **argv)
 
90
{
 
91
  if (argc > 1 && !strcmp (argv[1], "--verbose"))
 
92
    verbose = 1;
 
93
 
 
94
  test_isotime2epoch ();
 
95
 
 
96
  return !!errcount;
 
97
}
 
98