1272343Sngie/* $NetBSD: t_atoi.c,v 1.2 2012/03/29 05:56:36 jruoho Exp $ */ 2272343Sngie 3272343Sngie/*- 4272343Sngie * Copyright (c) 2012 The NetBSD Foundation, Inc. 5272343Sngie * All rights reserved. 6272343Sngie * 7272343Sngie * This code is derived from software contributed to The NetBSD Foundation 8272343Sngie * by Jukka Ruohonen. 9272343Sngie * 10272343Sngie * Redistribution and use in source and binary forms, with or without 11272343Sngie * modification, are permitted provided that the following conditions 12272343Sngie * are met: 13272343Sngie * 1. Redistributions of source code must retain the above copyright 14272343Sngie * notice, this list of conditions and the following disclaimer. 15272343Sngie * 2. Redistributions in binary form must reproduce the above copyright 16272343Sngie * notice, this list of conditions and the following disclaimer in the 17272343Sngie * documentation and/or other materials provided with the distribution. 18272343Sngie * 19272343Sngie * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20272343Sngie * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21272343Sngie * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22272343Sngie * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23272343Sngie * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24272343Sngie * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25272343Sngie * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26272343Sngie * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27272343Sngie * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28272343Sngie * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29272343Sngie * POSSIBILITY OF SUCH DAMAGE. 30272343Sngie */ 31272343Sngie#include <sys/cdefs.h> 32272343Sngie__RCSID("$NetBSD: t_atoi.c,v 1.2 2012/03/29 05:56:36 jruoho Exp $"); 33272343Sngie 34272343Sngie#include <atf-c.h> 35272343Sngie#include <float.h> 36272343Sngie#include <limits.h> 37272343Sngie#include <stdio.h> 38272343Sngie#include <stdlib.h> 39272343Sngie 40272343SngieATF_TC(atof_strtod); 41272343SngieATF_TC_HEAD(atof_strtod, tc) 42272343Sngie{ 43272343Sngie atf_tc_set_md_var(tc, "descr", 44272343Sngie "Test that atof(3) matches the corresponding strtod(3) call"); 45272343Sngie} 46272343Sngie 47272343SngieATF_TC_BODY(atof_strtod, tc) 48272343Sngie{ 49272343Sngie char buf[128]; 50272343Sngie 51272343Sngie (void)snprintf(buf, sizeof(buf), "%f\n", DBL_MAX); 52272343Sngie 53272343Sngie ATF_REQUIRE(atof("0") == strtod("0", NULL)); 54272343Sngie ATF_REQUIRE(atof("-1") == strtod("-1", NULL)); 55272343Sngie ATF_REQUIRE(atof(buf) == strtod(buf, NULL)); 56272343Sngie} 57272343Sngie 58272343SngieATF_TC(atoi_strtol); 59272343SngieATF_TC_HEAD(atoi_strtol, tc) 60272343Sngie{ 61272343Sngie atf_tc_set_md_var(tc, "descr", 62272343Sngie "Test that atoi(3) matches the corresponding strtol(3) call"); 63272343Sngie} 64272343Sngie 65272343SngieATF_TC_BODY(atoi_strtol, tc) 66272343Sngie{ 67272343Sngie char buf[64]; 68272343Sngie 69272343Sngie (void)snprintf(buf, sizeof(buf), "%d\n", INT_MAX); 70272343Sngie 71272343Sngie ATF_REQUIRE(atoi("0") == strtol("0", NULL, 10)); 72272343Sngie ATF_REQUIRE(atoi("-1") == strtol("-1", NULL, 10)); 73272343Sngie ATF_REQUIRE(atoi(buf) == strtol(buf, NULL, 10)); 74272343Sngie} 75272343Sngie 76272343SngieATF_TC(atol_strtol); 77272343SngieATF_TC_HEAD(atol_strtol, tc) 78272343Sngie{ 79272343Sngie atf_tc_set_md_var(tc, "descr", 80272343Sngie "Test that atol(3) matches the corresponding strtol(3) call"); 81272343Sngie} 82272343Sngie 83272343SngieATF_TC_BODY(atol_strtol, tc) 84272343Sngie{ 85272343Sngie char buf[64]; 86272343Sngie 87272343Sngie (void)snprintf(buf, sizeof(buf), "%ld\n", LONG_MAX); 88272343Sngie 89272343Sngie ATF_REQUIRE(atol("0") == strtol("0", NULL, 10)); 90272343Sngie ATF_REQUIRE(atol("-1") == strtol("-1", NULL, 10)); 91272343Sngie ATF_REQUIRE(atol(buf) == strtol(buf, NULL, 10)); 92272343Sngie} 93272343Sngie 94272343SngieATF_TC(atoll_strtoll); 95272343SngieATF_TC_HEAD(atoll_strtoll, tc) 96272343Sngie{ 97272343Sngie atf_tc_set_md_var(tc, "descr", 98272343Sngie "Test that atoll(3) matches the corresponding strtoll(3) call"); 99272343Sngie} 100272343Sngie 101272343SngieATF_TC_BODY(atoll_strtoll, tc) 102272343Sngie{ 103272343Sngie char buf[128]; 104272343Sngie 105272343Sngie (void)snprintf(buf, sizeof(buf), "%lld\n", LLONG_MAX); 106272343Sngie 107272343Sngie ATF_REQUIRE(atoll("0") == strtoll("0", NULL, 10)); 108272343Sngie ATF_REQUIRE(atoll("-1") == strtoll("-1", NULL, 10)); 109272343Sngie ATF_REQUIRE(atoll(buf) == strtoll(buf, NULL, 10)); 110272343Sngie} 111272343Sngie 112272343SngieATF_TP_ADD_TCS(tp) 113272343Sngie{ 114272343Sngie 115272343Sngie ATF_TP_ADD_TC(tp, atof_strtod); 116272343Sngie ATF_TP_ADD_TC(tp, atoi_strtol); 117272343Sngie ATF_TP_ADD_TC(tp, atol_strtol); 118272343Sngie ATF_TP_ADD_TC(tp, atoll_strtoll); 119272343Sngie 120272343Sngie return atf_no_error(); 121272343Sngie} 122