74 lines
2.4 KiB
C
74 lines
2.4 KiB
C
/*
|
|
* Unit test suite for *scanf functions.
|
|
*
|
|
* Copyright 2002 Uwe Bonnes
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "wine/test.h"
|
|
|
|
static void test_sscanf( void )
|
|
{
|
|
char buffer[100], buffer1[100];
|
|
char format[20];
|
|
int result, ret;
|
|
float res1= -82.6267, res2= 27.76, res11, res12;
|
|
char pname[]=" St. Petersburg, Florida\n";
|
|
|
|
|
|
/* check EOF */
|
|
strcpy(buffer,"");
|
|
ret = sscanf(buffer, "%d", &result);
|
|
ok( ret == EOF,"sscanf returns %x instead of %x", ret, EOF );
|
|
|
|
/* check %x */
|
|
strcpy(buffer,"0x519");
|
|
ok( sscanf(buffer, "%x", &result) == 1, "sscanf failed" );
|
|
ok( result == 0x519,"sscanf reads %x instead of %x", result, 0x519 );
|
|
|
|
strcpy(buffer,"0x51a");
|
|
ok( sscanf(buffer, "%x", &result) == 1, "sscanf failed" );
|
|
ok( result == 0x51a ,"sscanf reads %x instead of %x", result, 0x51a );
|
|
|
|
strcpy(buffer,"0x51g");
|
|
ok( sscanf(buffer, "%x", &result) == 1, "sscanf failed" );
|
|
ok( result == 0x51, "sscanf reads %x instead of %x", result, 0x51 );
|
|
|
|
/* check % followed by any char */
|
|
strcpy(buffer,"\"%12@");
|
|
strcpy(format,"%\"%%%d%@"); /* work around gcc format check */
|
|
ok( sscanf(buffer, format, &result) == 1, "sscanf failed" );
|
|
ok( result == 12, "sscanf reads %x instead of %x", result, 12 );
|
|
|
|
/*Check float */
|
|
ret = sprintf(buffer,"%f %f",res1, res2);
|
|
ret = sscanf(buffer,"%f%f",&res11, &res12);
|
|
ok( (res11 == res1) && (res12 == res2), "Error reading floats");
|
|
ret = sprintf(buffer," %s", pname);
|
|
ret = sscanf(buffer,"%*c%[^\n]",buffer1);
|
|
ok( ret = 1, "Error with format \"%s\"","%*c%[^\n]");
|
|
ok( strncmp(pname,buffer1,strlen(buffer1)) == 0, "Error with \"%s\" \"%s\"",pname, buffer1);
|
|
|
|
}
|
|
|
|
|
|
START_TEST(scanf)
|
|
{
|
|
test_sscanf();
|
|
}
|