-#define TEST(r, f, x, m) ( \
- ((r) = (f)) == (x) || \
- (error("%s failed (" m ")\n", #f, r, x), 0) )
+static void tm2sec(struct tm *tm, int big, char *m)
+{
+ struct tm *r;
+ time_t t;
+ int overflow = big && (time_t)LLONG_MAX!=LLONG_MAX;
+
+ errno = 0;
+ t = mktime(tm);
+ if (overflow && t != -1)
+ t_error("%s: mktime(%s) expected -1, got (time_t)%ld\n",
+ m, tm_str(*tm), (long)t);
+ if (overflow && errno != EOVERFLOW)
+ t_error("%s: mktime(%s) expected EOVERFLOW (%s), got (%s)\n",
+ m, tm_str(*tm), strerror(EOVERFLOW), strerror(errno));
+ if (!overflow && t == -1)
+ t_error("%s: mktime(%s) expected success, got (time_t)-1\n",
+ m, tm_str(*tm));
+ if (!overflow && errno)
+ t_error("%s: mktime(%s) expected no error, got (%s)\n",
+ m, tm_str(*tm), strerror(errno));
+ r = gmtime(&t);
+ if (!overflow && tm_cmp(*r, *tm))
+ t_error("%s: gmtime(mktime(%s)) roundtrip failed: got %s\n",
+ m, tm_str(*tm), tm_str(*r));
+}