1 /* Test program from Paul Eggert and Tony Leneis. */
8 /* True if the arithmetic type T is signed. */
9 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
11 /* The maximum and minimum values for the integer type T. These
12 macros have undefined behavior if T is signed and has padding bits.
13 If this is a problem for you, please let us know how to fix it for
15 #define TYPE_MINIMUM(t) \
16 ((t) (! TYPE_SIGNED (t) \
18 : ~ TYPE_MAXIMUM (t)))
19 #define TYPE_MAXIMUM(t) \
20 ((t) (! TYPE_SIGNED (t) \
22 : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
25 # define TIME_T_MIN TYPE_MINIMUM (time_t)
28 # define TIME_T_MAX TYPE_MAXIMUM (time_t)
31 /* Values we'll use to set the TZ environment variable. */
32 static const char *tz_strings
[] =
34 (const char *) 0, "GMT0", "JST-9",
35 "EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00"
37 #define N_STRINGS ((int) (sizeof (tz_strings) / sizeof (tz_strings[0])))
39 /* Fail if mktime fails to convert a date in the spring-forward gap.
40 Based on a problem report from Andreas Jaeger. */
42 spring_forward_gap (void)
44 /* glibc (up to about 1998-10-07) failed this test. */
47 /* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0"
48 instead of "TZ=America/Vancouver" in order to detect the bug even
49 on systems that don't support the Olson extension, or don't have the
50 full zoneinfo tables installed. */
51 setenv ("TZ", "PST8PDT,M4.1.0,M10.5.0", 1);
60 if (mktime (&tm
) == (time_t)-1)
65 mktime_test1 (time_t now
)
67 struct tm
*lt
= localtime (&now
);
68 if (lt
&& mktime (lt
) != now
)
73 mktime_test (time_t now
)
76 mktime_test1 ((time_t) (TIME_T_MAX
- now
));
77 mktime_test1 ((time_t) (TIME_T_MIN
+ now
));
83 /* Based on code from Ariel Faigon. */
93 if (tm
.tm_mon
!= 2 || tm
.tm_mday
!= 31)
102 tm
.tm_year
= tm
.tm_mon
= tm
.tm_mday
= tm
.tm_hour
= tm
.tm_min
= tm
.tm_sec
= j
;
105 if (now
!= (time_t) -1)
107 struct tm
*lt
= localtime (&now
);
109 && lt
->tm_year
== tm
.tm_year
110 && lt
->tm_mon
== tm
.tm_mon
111 && lt
->tm_mday
== tm
.tm_mday
112 && lt
->tm_hour
== tm
.tm_hour
113 && lt
->tm_min
== tm
.tm_min
114 && lt
->tm_sec
== tm
.tm_sec
115 && lt
->tm_yday
== tm
.tm_yday
116 && lt
->tm_wday
== tm
.tm_wday
117 && ((lt
->tm_isdst
< 0 ? -1 : 0 < lt
->tm_isdst
)
118 == (tm
.tm_isdst
< 0 ? -1 : 0 < tm
.tm_isdst
))))
130 setenv ("TZ", "America/Sao_Paulo", 1);
131 /* This test makes some buggy mktime implementations loop.
132 Give up after 60 seconds; a mktime slower than that
133 isn't worth using anyway. */
136 delta
= TIME_T_MAX
/ 997; /* a suitable prime number */
137 for (i
= 0; i
< N_STRINGS
; i
++)
140 setenv ("TZ", tz_strings
[i
], 1);
142 for (t
= 0; t
<= TIME_T_MAX
- delta
; t
+= delta
)
144 mktime_test ((time_t) 1);
145 mktime_test ((time_t) (60 * 60));
146 mktime_test ((time_t) (60 * 60 * 24));
148 for (j
= 1; j
<= INT_MAX
; j
*= 2)
150 bigtime_test (j
- 1);
153 spring_forward_gap ();
157 #define TEST_FUNCTION do_test ()
158 #include "../test-skeleton.c"