Fixed definitions of TTTOOLINFOA/W_V1_SIZE and
[wine] / dlls / msvcrt / tests / scanf.c
1 /*
2  * Unit test suite for *scanf functions.
3  *
4  * Copyright 2002 Uwe Bonnes
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <stdio.h>
22
23 #include "wine/test.h"
24
25 static void test_sscanf( void )
26 {
27     char buffer[100], buffer1[100];
28     char format[20];
29     int result, ret;
30     float res1= -82.6267, res2= 27.76, res11, res12;
31     char pname[]=" St. Petersburg, Florida\n";
32     
33
34     /* check EOF */
35     strcpy(buffer,"");
36     ret = sscanf(buffer, "%d", &result);
37     ok( ret == EOF,"sscanf returns %x instead of %x", ret, EOF );
38                 
39     /* check %x */
40     strcpy(buffer,"0x519");
41     ok( sscanf(buffer, "%x", &result) == 1, "sscanf failed"  );
42     ok( result == 0x519,"sscanf reads %x instead of %x", result, 0x519 );
43
44     strcpy(buffer,"0x51a");
45     ok( sscanf(buffer, "%x", &result) == 1, "sscanf failed" );
46     ok( result == 0x51a ,"sscanf reads %x instead of %x", result, 0x51a );
47
48     strcpy(buffer,"0x51g");
49     ok( sscanf(buffer, "%x", &result) == 1, "sscanf failed" );
50     ok( result == 0x51, "sscanf reads %x instead of %x", result, 0x51 );
51
52     /* check % followed by any char */
53     strcpy(buffer,"\"%12@");
54     strcpy(format,"%\"%%%d%@");  /* work around gcc format check */
55     ok( sscanf(buffer, format, &result) == 1, "sscanf failed" );
56     ok( result == 12, "sscanf reads %x instead of %x", result, 12 );
57
58     /*Check float */
59     ret = sprintf(buffer,"%f %f",res1, res2);
60     ret = sscanf(buffer,"%f%f",&res11, &res12);
61     ok( (res11 == res1) && (res12 == res2), "Error reading floats");
62     ret = sprintf(buffer," %s", pname);
63     ret = sscanf(buffer,"%*c%[^\n]",buffer1);
64     ok( ret = 1, "Error with format \"%s\"","%*c%[^\n]");
65     ok( strncmp(pname,buffer1,strlen(buffer1)) == 0, "Error with \"%s\" \"%s\"",pname, buffer1);
66     
67 }
68
69
70 START_TEST(scanf)
71 {
72     test_sscanf();
73 }