Back to index

glibc  2.9
tst-mktime3.c
Go to the documentation of this file.
00001 /* Test program for mktime bugs with out-of-range tm_sec values.  */
00002 
00003 #include <stdlib.h>
00004 #include <stdio.h>
00005 #include <time.h>
00006 
00007 struct tm tests[] =
00008 {
00009   { .tm_sec = -1, .tm_mday = 1, .tm_year = 104 },
00010   { .tm_sec = 65, .tm_min = 59, .tm_hour = 23, .tm_mday = 31,
00011     .tm_mon = 11, .tm_year = 101 }
00012 };
00013 struct tm expected[] =
00014 {
00015   { .tm_sec = 59, .tm_min = 59, .tm_hour = 23, .tm_mday = 31,
00016     .tm_mon = 11, .tm_year = 103, .tm_wday = 3, .tm_yday = 364 },
00017   { .tm_sec = 5, .tm_mday = 1, .tm_year = 102, .tm_wday = 2 }
00018 };
00019 
00020 int
00021 main (void)
00022 {
00023   setenv ("TZ", "UTC", 1);
00024   int i;
00025   for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i)
00026     {
00027       if (mktime (&tests[i]) < 0)
00028        {
00029          printf ("mktime %d failed\n", i);
00030          return 1;
00031        }
00032 #define CHECK(name) \
00033       if (tests[i].name != expected[i].name)                   \
00034        {                                                \
00035          printf ("test %d " #name " got %d expected %d\n",     \
00036                 i, tests[i].name, expected[i].name);           \
00037          return 1;                                      \
00038        }
00039       CHECK (tm_sec)
00040       CHECK (tm_min)
00041       CHECK (tm_hour)
00042       CHECK (tm_mday)
00043       CHECK (tm_mon)
00044       CHECK (tm_year)
00045       CHECK (tm_wday)
00046       CHECK (tm_yday)
00047       CHECK (tm_isdst)
00048     }
00049   return 0;
00050 }