|
20 | 20 |
|
21 | 21 | #include <atf-c.h>
|
22 | 22 |
|
| 23 | +static const struct tzcase { |
| 24 | + const char *tzfn; |
| 25 | + const char *expect; |
| 26 | +} tzcases[] = { |
| 27 | + /* |
| 28 | + * A handful of time zones and the expected result of |
| 29 | + * strftime("%z (%Z)", tm) when that time zone is active |
| 30 | + * and tm represents a date in the summer of 2025. |
| 31 | + */ |
| 32 | + { "America/Vancouver", "-0700 (PDT)" }, |
| 33 | + { "America/New_York", "-0400 (EDT)" }, |
| 34 | + { "Europe/London", "+0100 (BST)" }, |
| 35 | + { "Europe/Paris", "+0200 (CEST)" }, |
| 36 | + { "Asia/Kolkata", "+0530 (IST)" }, |
| 37 | + { "Asia/Tokyo", "+0900 (JST)" }, |
| 38 | + { "Australia/Canberra", "+1000 (AEST)" }, |
| 39 | + { "UTC", "+0000 (UTC)" }, |
| 40 | + { 0 }, |
| 41 | +}; |
| 42 | + |
23 | 43 | static const time_t then = 1751328000; /* 2025-07-01 00:00:00 UTC */
|
24 | 44 | static const char *tz_change_interval_sym = "__tz_change_interval";
|
25 | 45 | static int *tz_change_interval_p;
|
@@ -91,25 +111,6 @@ ATF_TC_HEAD(detect_tz_changes, tc)
|
91 | 111 | }
|
92 | 112 | ATF_TC_BODY(detect_tz_changes, tc)
|
93 | 113 | {
|
94 |
| - static const struct tzcase { |
95 |
| - const char *tzfn; |
96 |
| - const char *expect; |
97 |
| - } tzcases[] = { |
98 |
| - /* |
99 |
| - * A handful of time zones and the expected result of |
100 |
| - * strftime("%z (%Z)", tm) when that time zone is active |
101 |
| - * and tm represents a date in the summer of 2025. |
102 |
| - */ |
103 |
| - { "America/Vancouver", "-0700 (PDT)" }, |
104 |
| - { "America/New_York", "-0400 (EDT)" }, |
105 |
| - { "Europe/London", "+0100 (BST)" }, |
106 |
| - { "Europe/Paris", "+0200 (CEST)" }, |
107 |
| - { "Asia/Kolkata", "+0530 (IST)" }, |
108 |
| - { "Asia/Tokyo", "+0900 (JST)" }, |
109 |
| - { "Australia/Canberra", "+1000 (AEST)" }, |
110 |
| - { "UTC", "+0000 (UTC)" }, |
111 |
| - { 0 }, |
112 |
| - }; |
113 | 114 | char obuf[1024] = "";
|
114 | 115 | char ebuf[1024] = "";
|
115 | 116 | struct pollfd fds[3];
|
@@ -272,10 +273,32 @@ ATF_TC_BODY(detect_tz_changes, tc)
|
272 | 273 | ATF_REQUIRE_EQ(0, WEXITSTATUS(status));
|
273 | 274 | }
|
274 | 275 |
|
| 276 | +ATF_TC(tz_env); |
| 277 | +ATF_TC_HEAD(tz_env, tc) |
| 278 | +{ |
| 279 | + atf_tc_set_md_var(tc, "descr", "Test TZ environment variable"); |
| 280 | +} |
| 281 | +ATF_TC_BODY(tz_env, tc) |
| 282 | +{ |
| 283 | + char buf[128]; |
| 284 | + const struct tzcase *tzcase = NULL; |
| 285 | + struct tm *tm; |
| 286 | + size_t len; |
| 287 | + |
| 288 | + for (tzcase = tzcases; tzcase->tzfn != NULL; tzcase++) { |
| 289 | + setenv("TZ", tzcase->tzfn, 1); |
| 290 | + ATF_REQUIRE((tm = localtime(&then)) != NULL); |
| 291 | + len = strftime(buf, sizeof(buf), "%z (%Z)", tm); |
| 292 | + ATF_REQUIRE(len > 0); |
| 293 | + ATF_REQUIRE_STREQ(tzcase->expect, buf); |
| 294 | + } |
| 295 | +} |
| 296 | + |
275 | 297 | ATF_TP_ADD_TCS(tp)
|
276 | 298 | {
|
277 | 299 | debugging = !getenv("__RUNNING_INSIDE_ATF_RUN") &&
|
278 | 300 | isatty(STDERR_FILENO);
|
279 | 301 | ATF_TP_ADD_TC(tp, detect_tz_changes);
|
| 302 | + ATF_TP_ADD_TC(tp, tz_env); |
280 | 303 | return (atf_no_error());
|
281 | 304 | }
|
0 commit comments