~ubuntu-branches/ubuntu/utopic/coreutils/utopic-proposed

« back to all changes in this revision

Viewing changes to gnulib-tests/test-parse-datetime.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-11-28 03:03:42 UTC
  • mfrom: (8.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20121128030342-21zanj8354gas5gr
Tags: 8.20-3ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Make 'uname -i -p' return the real processor/hardware, instead of
    unknown.
  - Build-depend on gettext:any instead of on gettext, so that apt-get can
    properly resolve build-dependencies on the tool when cross-building.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- buffer-read-only: t -*- vi: set ro: */
2
 
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3
1
/* Test of parse_datetime() function.
4
 
   Copyright (C) 2008-2011 Free Software Foundation, Inc.
 
2
   Copyright (C) 2008-2012 Free Software Foundation, Inc.
5
3
 
6
4
   This program is free software; you can redistribute it and/or modify
7
5
   it under the terms of the GNU General Public License as published by
14
12
   GNU General Public License for more details.
15
13
 
16
14
   You should have received a copy of the GNU General Public License
17
 
   along with this program; if not, write to the Free Software Foundation,
18
 
   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
 
15
   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
19
16
 
20
17
/* Written by Simon Josefsson <simon@josefsson.org>, 2008.  */
21
18
 
32
29
 
33
30
#ifdef DEBUG
34
31
#define LOG(str, now, res)                                              \
35
 
  printf ("string `%s' diff %d %d\n",                   \
 
32
  printf ("string '%s' diff %d %d\n",                                 \
36
33
          str, res.tv_sec - now.tv_sec, res.tv_nsec - now.tv_nsec);
37
34
#else
38
35
#define LOG(str, now, res) (void) 0
96
93
#endif /* ! HAVE_TM_GMTOFF */
97
94
 
98
95
static long
99
 
gmt_offset ()
 
96
gmt_offset (time_t s)
100
97
{
101
 
  time_t now;
102
98
  long gmtoff;
103
99
 
104
 
  time (&now);
105
 
 
106
100
#if !HAVE_TM_GMTOFF
107
 
  struct tm tm_local = *localtime (&now);
108
 
  struct tm tm_gmt   = *gmtime (&now);
 
101
  struct tm tm_local = *localtime (&s);
 
102
  struct tm tm_gmt   = *gmtime (&s);
109
103
 
110
104
  gmtoff = tm_diff (&tm_local, &tm_gmt);
111
105
#else
112
 
  gmtoff = localtime (&now)->tm_gmtoff;
 
106
  gmtoff = localtime (&s)->tm_gmtoff;
113
107
#endif
114
108
 
115
109
  return gmtoff;
125
119
  const char *p;
126
120
  int i;
127
121
  long gmtoff;
 
122
  time_t ref_time = 1304250918;
128
123
 
129
124
  set_program_name (argv[0]);
130
125
 
131
 
  gmtoff = gmt_offset ();
 
126
  /* Set the time zone to US Eastern time with the 2012 rules.  This
 
127
     should disable any leap second support.  Otherwise, there will be
 
128
     a problem with glibc on sites that default to leap seconds; see
 
129
     <http://bugs.gnu.org/12206>.  */
 
130
  setenv ("TZ", "EST5EDT,M3.2.0,M11.1.0", 1);
 
131
 
 
132
  gmtoff = gmt_offset (ref_time);
132
133
 
133
134
 
134
135
  /* ISO 8601 extended date and time of day representation,
135
136
     'T' separator, local time zone */
136
137
  p = "2011-05-01T11:55:18";
137
 
  expected.tv_sec = 1304250918 - gmtoff;
 
138
  expected.tv_sec = ref_time - gmtoff;
138
139
  expected.tv_nsec = 0;
139
140
  ASSERT (parse_datetime (&result, p, 0));
140
141
  LOG (p, expected, result);
144
145
  /* ISO 8601 extended date and time of day representation,
145
146
     ' ' separator, local time zone */
146
147
  p = "2011-05-01 11:55:18";
147
 
  expected.tv_sec = 1304250918 - gmtoff;
 
148
  expected.tv_sec = ref_time - gmtoff;
148
149
  expected.tv_nsec = 0;
149
150
  ASSERT (parse_datetime (&result, p, 0));
150
151
  LOG (p, expected, result);
155
156
  /* ISO 8601, extended date and time of day representation,
156
157
     'T' separator, UTC */
157
158
  p = "2011-05-01T11:55:18Z";
158
 
  expected.tv_sec = 1304250918;
 
159
  expected.tv_sec = ref_time;
159
160
  expected.tv_nsec = 0;
160
161
  ASSERT (parse_datetime (&result, p, 0));
161
162
  LOG (p, expected, result);
165
166
  /* ISO 8601, extended date and time of day representation,
166
167
     ' ' separator, UTC */
167
168
  p = "2011-05-01 11:55:18Z";
168
 
  expected.tv_sec = 1304250918;
 
169
  expected.tv_sec = ref_time;
169
170
  expected.tv_nsec = 0;
170
171
  ASSERT (parse_datetime (&result, p, 0));
171
172
  LOG (p, expected, result);
329
330
  ASSERT (!parse_datetime (&result, p, &now));
330
331
  p = "UTC+4:00 tomorrow ago";
331
332
  ASSERT (!parse_datetime (&result, p, &now));
 
333
  p = "UTC+4:00 tomorrow hence";
 
334
  ASSERT (!parse_datetime (&result, p, &now));
332
335
  p = "UTC+4:00 40 now ago";
333
336
  ASSERT (!parse_datetime (&result, p, &now));
334
337
  p = "UTC+4:00 last tomorrow";
347
350
  LOG (p, now, result2);
348
351
  ASSERT (result.tv_sec == result2.tv_sec
349
352
          && result.tv_nsec == result2.tv_nsec);
 
353
  p = "UTC+400 1 day hence";
 
354
  ASSERT (parse_datetime (&result2, p, &now));
 
355
  LOG (p, now, result2);
 
356
  ASSERT (result.tv_sec == result2.tv_sec
 
357
          && result.tv_nsec == result2.tv_nsec);
350
358
  now.tv_sec = 4711;
351
359
  now.tv_nsec = 1267;
352
360
  p = "UTC+400 yesterday";
407
415
  ASSERT (result.tv_sec == 24 * 3600
408
416
          && result.tv_nsec == now.tv_nsec);
409
417
 
 
418
  /* Exercise a sign-extension bug.  Before July 2012, an input
 
419
     starting with a high-bit-set byte would be treated like "0".  */
 
420
  ASSERT ( ! parse_datetime (&result, "\xb0", &now));
 
421
 
410
422
  return 0;
411
423
}