1 /* $NetBSD: t_atoi.c,v 1.2 2012/03/29 05:56:36 jruoho Exp $ */
4 * Copyright (c) 2012 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __RCSID("$NetBSD: t_atoi.c,v 1.2 2012/03/29 05:56:36 jruoho Exp $");
41 ATF_TC_HEAD(atof_strtod
, tc
)
43 atf_tc_set_md_var(tc
, "descr",
44 "Test that atof(3) matches the corresponding strtod(3) call");
47 ATF_TC_BODY(atof_strtod
, tc
)
51 (void)snprintf(buf
, sizeof(buf
), "%f\n", DBL_MAX
);
53 ATF_REQUIRE(atof("0") == strtod("0", NULL
));
54 ATF_REQUIRE(atof("-1") == strtod("-1", NULL
));
55 ATF_REQUIRE(atof(buf
) == strtod(buf
, NULL
));
59 ATF_TC_HEAD(atoi_strtol
, tc
)
61 atf_tc_set_md_var(tc
, "descr",
62 "Test that atoi(3) matches the corresponding strtol(3) call");
65 ATF_TC_BODY(atoi_strtol
, tc
)
69 (void)snprintf(buf
, sizeof(buf
), "%d\n", INT_MAX
);
71 ATF_REQUIRE(atoi("0") == strtol("0", NULL
, 10));
72 ATF_REQUIRE(atoi("-1") == strtol("-1", NULL
, 10));
73 ATF_REQUIRE(atoi(buf
) == strtol(buf
, NULL
, 10));
77 ATF_TC_HEAD(atol_strtol
, tc
)
79 atf_tc_set_md_var(tc
, "descr",
80 "Test that atol(3) matches the corresponding strtol(3) call");
83 ATF_TC_BODY(atol_strtol
, tc
)
87 (void)snprintf(buf
, sizeof(buf
), "%ld\n", LONG_MAX
);
89 ATF_REQUIRE(atol("0") == strtol("0", NULL
, 10));
90 ATF_REQUIRE(atol("-1") == strtol("-1", NULL
, 10));
91 ATF_REQUIRE(atol(buf
) == strtol(buf
, NULL
, 10));
94 ATF_TC(atoll_strtoll
);
95 ATF_TC_HEAD(atoll_strtoll
, tc
)
97 atf_tc_set_md_var(tc
, "descr",
98 "Test that atoll(3) matches the corresponding strtoll(3) call");
101 ATF_TC_BODY(atoll_strtoll
, tc
)
105 (void)snprintf(buf
, sizeof(buf
), "%lld\n", LLONG_MAX
);
107 ATF_REQUIRE(atoll("0") == strtoll("0", NULL
, 10));
108 ATF_REQUIRE(atoll("-1") == strtoll("-1", NULL
, 10));
109 ATF_REQUIRE(atoll(buf
) == strtoll(buf
, NULL
, 10));
115 ATF_TP_ADD_TC(tp
, atof_strtod
);
116 ATF_TP_ADD_TC(tp
, atoi_strtol
);
117 ATF_TP_ADD_TC(tp
, atol_strtol
);
118 ATF_TP_ADD_TC(tp
, atoll_strtoll
);
120 return atf_no_error();