t_scanf.c revision 1.3
11.3Sjruoho/* $NetBSD: t_scanf.c,v 1.3 2012/03/18 07:00:51 jruoho Exp $ */ 21.1Sjruoho 31.1Sjruoho/*- 41.1Sjruoho * Copyright (c) 2010 The NetBSD Foundation, Inc. 51.1Sjruoho * All rights reserved. 61.1Sjruoho * 71.1Sjruoho * Redistribution and use in source and binary forms, with or without 81.1Sjruoho * modification, are permitted provided that the following conditions 91.1Sjruoho * are met: 101.1Sjruoho * 1. Redistributions of source code must retain the above copyright 111.1Sjruoho * notice, this list of conditions and the following disclaimer. 121.1Sjruoho * 2. Redistributions in binary form must reproduce the above copyright 131.1Sjruoho * notice, this list of conditions and the following disclaimer in the 141.1Sjruoho * documentation and/or other materials provided with the distribution. 151.1Sjruoho * 161.1Sjruoho * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 171.1Sjruoho * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 181.1Sjruoho * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 191.1Sjruoho * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 201.1Sjruoho * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 211.1Sjruoho * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 221.1Sjruoho * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 231.1Sjruoho * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 241.1Sjruoho * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 251.1Sjruoho * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 261.1Sjruoho * POSSIBILITY OF SUCH DAMAGE. 271.1Sjruoho */ 281.1Sjruoho 291.1Sjruoho#include <atf-c.h> 301.1Sjruoho#include <math.h> 311.1Sjruoho#include <stdio.h> 321.1Sjruoho#include <string.h> 331.1Sjruoho 341.1Sjruoho#define NUM -0x1234 351.1Sjruoho#define STRNUM ___STRING(NUM) 361.1Sjruoho 371.1SjruohoATF_TC(sscanf_neghex); 381.1SjruohoATF_TC_HEAD(sscanf_neghex, tc) 391.1Sjruoho{ 401.3Sjruoho atf_tc_set_md_var(tc, "descr", 411.2Sjoerg "PR lib/21691: %%i and %%x fail with negative hex numbers"); 421.1Sjruoho} 431.1Sjruoho 441.1SjruohoATF_TC_BODY(sscanf_neghex, tc) 451.1Sjruoho{ 461.1Sjruoho int i; 471.1Sjruoho 481.1Sjruoho sscanf(STRNUM, "%i", &i); 491.1Sjruoho ATF_REQUIRE(i == NUM); 501.1Sjruoho 511.1Sjruoho sscanf(STRNUM, "%x", &i); 521.1Sjruoho ATF_REQUIRE(i == NUM); 531.1Sjruoho} 541.1Sjruoho 551.1SjruohoATF_TC(sscanf_whitespace); 561.1SjruohoATF_TC_HEAD(sscanf_whitespace, tc) 571.1Sjruoho{ 581.1Sjruoho 591.1Sjruoho atf_tc_set_md_var(tc, "descr", "verify sscanf skips all whitespace"); 601.1Sjruoho} 611.1Sjruoho 621.1SjruohoATF_TC_BODY(sscanf_whitespace, tc) 631.1Sjruoho{ 641.1Sjruoho const char str[] = "\f\n\r\t\v%z"; 651.1Sjruoho char c; 661.1Sjruoho 671.1Sjruoho /* set of "white space" symbols from isspace(3) */ 681.1Sjruoho c = 0; 691.1Sjruoho (void)sscanf(str, "%%%c", &c); 701.1Sjruoho ATF_REQUIRE(c == 'z'); 711.1Sjruoho} 721.1Sjruoho 731.1Sjruoho 741.1SjruohoATF_TP_ADD_TCS(tp) 751.1Sjruoho{ 761.1Sjruoho 771.1Sjruoho ATF_TP_ADD_TC(tp, sscanf_neghex); 781.1Sjruoho ATF_TP_ADD_TC(tp, sscanf_whitespace); 791.1Sjruoho 801.1Sjruoho return atf_no_error(); 811.1Sjruoho} 82