Back to index

glibc  2.9
test-tz.c
Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include <time.h>
00003 #include <string.h>
00004 #include <stdio.h>
00005 
00006 struct {
00007   const char *       env;
00008   time_t      expected;
00009 } tests[] = {
00010   {"MST",     832935315},
00011   {"",        832910115},
00012   {":UTC",    832910115},
00013   {"UTC",     832910115},
00014   {"UTC0",    832910115}
00015 };
00016 
00017 
00018 int
00019 main (int argc, char ** argv)
00020 {
00021   int errors = 0;
00022   struct tm tm;
00023   time_t t;
00024   unsigned int i;
00025 
00026   memset (&tm, 0, sizeof (tm));
00027   tm.tm_isdst = 0;
00028   tm.tm_year  = 96;  /* years since 1900 */
00029   tm.tm_mon   = 4;
00030   tm.tm_mday  = 24;
00031   tm.tm_hour  =  3;
00032   tm.tm_min   = 55;
00033   tm.tm_sec   = 15;
00034 
00035   for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i)
00036     {
00037       setenv ("TZ", tests[i].env, 1);
00038       t = mktime (&tm);
00039       if (t != tests[i].expected)
00040        {
00041          printf ("%s: flunked test %u (expected %lu, got %lu)\n",
00042                 argv[0], i, (long) tests[i].expected, (long) t);
00043          ++errors;
00044        }
00045     }
00046   if (errors == 0)
00047     {
00048       puts ("No errors.");
00049       return EXIT_SUCCESS;
00050     }
00051   else
00052     {
00053       printf ("%d errors.\n", errors);
00054       return EXIT_FAILURE;
00055     }
00056 }