Removed W->A from DEFWND_ImmIsUIMessageW.
[wine] / dlls / msvcrt / tests / printf.c
1 /*
2  * Conformance tests for *printf functions.
3  *
4  * Copyright 2002 Uwe Bonnes
5  * Copyright 2004 Aneurin Price
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21  
22 #include <stdio.h>
23
24 #include "wine/test.h"
25
26 static void test_sprintf( void )
27 {
28     char buffer[100];
29     const char *I64d = "%I64d";
30     const char *O4c = "%04c";
31     const char *O4s = "%04s";
32     const char *hash012p = "%#012p";
33     double pnumber=789456123;
34 /**    WCHAR widestring[]={'w','i','d','e','s','t','r','i','n','g',0};**/
35     sprintf(buffer,"%+#23.15e",pnumber);
36     todo_wine
37       {
38         ok(strstr(buffer,"e+008") != 0,"Sprintf different \"%s\"\n",buffer);
39       }
40     sprintf(buffer,I64d,((ULONGLONG)0xffffffff)*0xffffffff);
41     todo_wine
42       {
43         ok(strlen(buffer) == 11,"Problem with long long \"%s\"\n",buffer);
44       }
45     sprintf(buffer,"%lld",((ULONGLONG)0xffffffff)*0xffffffff);
46     todo_wine
47       {
48         ok(strlen(buffer) == 1,"Problem with \"ll\" interpretation \"%s\"\n",buffer);
49       }
50 /** This one actually crashes WINE at the moment, when using builtin msvcrt.dll.
51     sprintf(buffer,"%S",widestring);
52     todo_wine
53       {
54         ok(strlen(buffer) == 10,"Problem with \"%%S\" interpretation \"%s\"\n",buffer);
55       }
56  **/
57     sprintf(buffer,O4c,'1');
58     todo_wine
59       {
60         ok(!strcmp(buffer,"0001"),"Character not zero-prefixed \"%s\"\n",buffer);
61       }
62     sprintf(buffer,"%p",(void *)57);
63     todo_wine
64       {
65         ok(!strcmp(buffer,"00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer);
66       }
67     sprintf(buffer,hash012p,(void *)57);
68     todo_wine
69       {
70         ok(!strcmp(buffer,"  0X00000039"),"Pointer formatted incorrectly \"%s\"\n",buffer);
71       }
72     sprintf(buffer,O4s,"foo");/**Warning again**/
73     todo_wine
74       {
75         ok(!strcmp(buffer,"0foo"),"String not zero-prefixed \"%s\"\n",buffer);
76       }
77 }
78
79 static void test_swprintf( void )
80 {
81     wchar_t buffer[100];
82     const wchar_t I64d[] = {'%','I','6','4','d',0};
83     double pnumber=789456123;
84     const wchar_t TwentyThreePoint15e[]= {'%','+','#','2','3','.','1','5','e',0};
85     const wchar_t e008[] = {'e','+','0','0','8',0};
86     const char string[]={'s','t','r','i','n','g',0};
87     const wchar_t S[]={'%','S',0};
88     swprintf(buffer,TwentyThreePoint15e,pnumber);
89     todo_wine
90       {
91         ok(wcsstr(buffer,e008) != 0,"Sprintf different\n");
92       }
93     swprintf(buffer,I64d,((ULONGLONG)0xffffffff)*0xffffffff);
94     todo_wine
95       {
96         ok(wcslen(buffer) == 11,"Problem with long long\n");
97       }
98     swprintf(buffer,S,string);
99       ok(wcslen(buffer) == 6,"Problem with \"%%S\" interpretation\n");
100 }
101
102 static void test_fwprintf( void )
103 {
104     const char *string="not a wide string";
105     todo_wine
106       {
107         ok(fwprintf(fopen("/dev/null","r+"),(wchar_t *)string) == -1,"Non-wide string should not be printed by fwprintf\n");
108       }
109 }
110
111 static void test_snprintf (void)
112 {
113     struct snprintf_test {
114         const char *format;
115         int expected;
116         struct {
117             int retval;
118             int render;
119         } todo;
120     };
121     /* Pre-2.1 libc behaviour, not C99 compliant. */
122     const struct snprintf_test tests[] = {{"short", 5, {0, 0}},
123                                           {"justfit", 7, {0, 0}},
124                                           {"justfits", 8, {0, 1}},
125                                           {"muchlonger", -1, {1, 1}}};
126     char buffer[8];
127     const int bufsiz = sizeof buffer;
128     unsigned int i;
129
130     for (i = 0; i < sizeof tests / sizeof tests[0]; i++) {
131         const char *fmt  = tests[i].format;
132         const int expect = tests[i].expected;
133         const int n      = _snprintf (buffer, bufsiz, fmt);
134         const int valid  = n < 0 ? bufsiz : (n == bufsiz ? n : n+1);
135
136         todo (tests[i].todo.retval ? "wine" : "none")
137             ok (n == expect, "\"%s\": expected %d, returned %d\n",
138                 fmt, expect, n);
139         todo (tests[i].todo.render ? "wine" : "none")
140             ok (!memcmp (fmt, buffer, valid),
141                 "\"%s\": rendered \"%.*s\"\n", fmt, valid, buffer);
142     };
143 }
144
145 START_TEST(printf)
146 {
147     test_sprintf();
148     test_swprintf();
149     test_fwprintf();
150     test_snprintf();
151 }