test-tz.c 1020 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <stdlib.h>
  2. #include <time.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. struct {
  6. const char * env;
  7. time_t expected;
  8. } tests[] = {
  9. {"MST", 832935315},
  10. {"", 832910115},
  11. {":UTC", 832910115},
  12. {"UTC", 832910115},
  13. {"UTC0", 832910115}
  14. };
  15. int
  16. main (int argc, char ** argv)
  17. {
  18. int errors = 0;
  19. struct tm tm;
  20. time_t t;
  21. unsigned int i;
  22. memset (&tm, 0, sizeof (tm));
  23. tm.tm_isdst = 0;
  24. tm.tm_year = 96; /* years since 1900 */
  25. tm.tm_mon = 4;
  26. tm.tm_mday = 24;
  27. tm.tm_hour = 3;
  28. tm.tm_min = 55;
  29. tm.tm_sec = 15;
  30. for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i)
  31. {
  32. setenv ("TZ", tests[i].env, 1);
  33. t = mktime (&tm);
  34. if (t != tests[i].expected)
  35. {
  36. printf ("%s: flunked test %u (expected %lu, got %lu)\n",
  37. argv[0], i, (long) tests[i].expected, (long) t);
  38. ++errors;
  39. }
  40. }
  41. if (errors == 0)
  42. {
  43. puts ("No errors.");
  44. return EXIT_SUCCESS;
  45. }
  46. else
  47. {
  48. printf ("%d errors.\n", errors);
  49. return EXIT_FAILURE;
  50. }
  51. }