1 /* $NetBSD: t_mktime.c,v 1.5 2012/03/18 07:33:58 jruoho Exp $ */
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
36 ATF_TC(localtime_r_gmt
);
37 ATF_TC_HEAD(localtime_r_gmt
, tc
)
39 atf_tc_set_md_var(tc
, "descr", "Test that localtime_r(3) "
40 "returns localtime, not GMT (PR lib/28324)");
43 ATF_TC_BODY(localtime_r_gmt
, tc
)
53 if (t
->tm_sec
!= tt
.tm_sec
|| t
->tm_min
!= tt
.tm_min
||
54 t
->tm_hour
!= tt
.tm_hour
|| t
->tm_mday
!= tt
.tm_mday
)
55 atf_tc_fail("inconsistencies between "
56 "localtime(3) and localtime_r(3)");
59 ATF_TC(mktime_negyear
);
60 ATF_TC_HEAD(mktime_negyear
, tc
)
62 atf_tc_set_md_var(tc
, "descr", "Test mktime(3) with negative year");
65 ATF_TC_BODY(mktime_negyear
, tc
)
70 (void)memset(&tms
, 0, sizeof(tms
));
75 ATF_REQUIRE_ERRNO(0, t
!= (time_t)-1);
79 ATF_TC_HEAD(timegm_epoch
, tc
)
81 atf_tc_set_md_var(tc
, "descr", "Test timegm(3) close to the epoch");
84 ATF_TC_BODY(timegm_epoch
, tc
)
89 /* midnight on 1 Jan 1970 */
90 (void)memset(&tms
, 0, sizeof(tms
));
92 tms
.tm_year
= 1970 - 1900;
95 ATF_REQUIRE_ERRNO(0, t
== (time_t)0);
97 /* one second after midnight on 1 Jan 1970 */
98 (void)memset(&tms
, 0, sizeof(tms
));
100 tms
.tm_year
= 1970 - 1900;
104 ATF_REQUIRE_ERRNO(0, t
== (time_t)1);
107 * 1969-12-31 23:59:59 = one second before the epoch.
108 * Result should be -1 with errno = 0.
110 (void)memset(&tms
, 0, sizeof(tms
));
112 tms
.tm_year
= 1969 - 1900;
119 ATF_REQUIRE_ERRNO(0, t
== (time_t)-1);
122 * Another way of getting one second before the epoch:
123 * Set date to 1 Jan 1970, and time to -1 second.
125 (void)memset(&tms
, 0, sizeof(tms
));
127 tms
.tm_year
= 1970 - 1900;
131 ATF_REQUIRE_ERRNO(0, t
== (time_t)-1);
134 * Two seconds before the epoch.
136 (void)memset(&tms
, 0, sizeof(tms
));
138 tms
.tm_year
= 1970 - 1900;
142 ATF_REQUIRE_ERRNO(0, t
== (time_t)-2);
150 ATF_TP_ADD_TC(tp
, localtime_r_gmt
);
151 ATF_TP_ADD_TC(tp
, mktime_negyear
);
152 ATF_TP_ADD_TC(tp
, timegm_epoch
);
154 return atf_no_error();