1 /* Unit test suite for FormatMessageA/W
3 * Copyright 2002 Mike McCormack for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/test.h"
27 static DWORD __cdecl
doit(DWORD flags
, LPCVOID src
, DWORD msg_id
, DWORD lang_id
,
28 LPSTR out
, DWORD outsize
, ... )
33 __ms_va_start(list
, outsize
);
34 r
= FormatMessageA(flags
, src
, msg_id
,
35 lang_id
, out
, outsize
, &list
);
40 static DWORD __cdecl
doitW(DWORD flags
, LPCVOID src
, DWORD msg_id
, DWORD lang_id
,
41 LPWSTR out
, DWORD outsize
, ... )
46 __ms_va_start(list
, outsize
);
47 r
= FormatMessageW(flags
, src
, msg_id
,
48 lang_id
, out
, outsize
, &list
);
53 static void test_message_from_string_wide(void)
55 static const WCHAR test
[] = {'t','e','s','t',0};
56 static const WCHAR empty
[] = {0};
57 static const WCHAR te
[] = {'t','e',0};
58 static const WCHAR st
[] = {'s','t',0};
59 static const WCHAR t
[] = {'t',0};
60 static const WCHAR e
[] = {'e',0};
61 static const WCHAR s
[] = {'s',0};
62 static const WCHAR fmt_null
[] = {'%',0};
63 static const WCHAR fmt_tnull
[] = {'t','e','s','t','%',0};
64 static const WCHAR fmt_1
[] = {'%','1',0};
65 static const WCHAR fmt_12
[] = {'%','1','%','2',0};
66 static const WCHAR fmt_123
[] = {'%','1','%','3','%','2','%','1',0};
67 static const WCHAR fmt_123c
[] = {'%','1','!','c','!','%','2','!','c','!','%','3','!','c','!','%','1','!','c','!',0};
68 static const WCHAR fmt_123lc
[] = {'%','1','!','l','c','!','%','2','!','l','c','!','%','3','!','l','c','!','%','1','!','l','c','!',0};
69 static const WCHAR fmt_123wc
[] = {'%','1','!','w','c','!','%','2','!','w','c','!','%','3','!','w','c','!','%','1','!','w','c','!',0};
70 static const WCHAR fmt_123C
[] = {'%','1','!','C','!','%','2','!','C','!','%','3','!','C','!','%','1','!','C','!',0};
71 static const WCHAR fmt_123d
[] = {'%','1','!','d','!','%','2','!','d','!','%','3','!','d','!',0};
72 static const WCHAR fmt_1s
[] = {'%','1','!','s','!',0};
73 static const WCHAR fmt_s
[] = {'%','!','s','!',0};
74 static const WCHAR fmt_ls
[] = {'%','!','l','s','!',0};
75 static const WCHAR fmt_ws
[] = {'%','!','w','s','!',0};
76 static const WCHAR fmt_S
[] = {'%','!','S','!',0};
77 static const WCHAR fmt_14d
[] = {'%','1','!','4','d','!',0};
78 static const WCHAR fmt_14x
[] = {'%','1','!','4','x','!',0};
79 static const WCHAR fmt_14X
[] = {'%','1','!','4','X','!',0};
80 static const WCHAR fmt_1_4X
[] = {'%','1','!','-','4','X','!',0};
81 static const WCHAR fmt_1_4d
[] = {'%','1','!','-','4','d','!',0};
82 static const WCHAR fmt_2pct
[] = {' ','%','%','%','%',' ',0};
83 static const WCHAR fmt_2dot1d
[] = {' ', '%','.','%','.',' ',' ','%','1','!','d','!',0};
84 static const WCHAR fmt_t0t
[] = {'t','e','s','t','%','0','t','e','s','t',0};
85 static const WCHAR fmt_yah
[] = {'y','a','h','%','!','%','0',' ',' ',' ',0};
86 static const WCHAR fmt_space
[] = {'%',' ','%',' ',' ',' ',0};
87 static const WCHAR fmt_nrt
[] = {'%','n','%','r','%','t',0};
88 static const WCHAR fmt_hi_lf
[] = {'h','i','\n',0};
89 static const WCHAR fmt_hi_crlf
[] = {'h','i','\r','\n',0};
90 static const WCHAR fmt_cr
[] = {'\r',0};
91 static const WCHAR fmt_crcrlf
[] = {'\r','\r','\n',0};
92 static const WCHAR fmt_13s
[] = {'%','1','!','3','s','!',0};
93 static const WCHAR fmt_1os
[] = {'%','1','!','*','s','!',0};
94 static const WCHAR fmt_142u
[] = {'%','1','!','4','.','2','u','!',0};
95 static const WCHAR fmt_1oou
[] = {'%','1','!','*','.','*','u','!',0};
96 static const WCHAR fmt_1oou1oou
[] = {'%','1','!','*','.','*','u','!',',','%','1','!','*','.','*','u','!',0};
97 static const WCHAR fmt_1oou3oou
[] = {'%','1','!','*','.','*','u','!',',','%','3','!','*','.','*','u','!',0};
98 static const WCHAR fmt_1oou4oou
[] = {'%','1','!','*','.','*','u','!',',','%','4','!','*','.','*','u','!',0};
100 static const WCHAR s_123d
[] = {'1','2','3',0};
101 static const WCHAR s_14d
[] = {' ',' ',' ','1',0};
102 static const WCHAR s_14x
[] = {' ',' ',' ','b',0};
103 static const WCHAR s_14X
[] = {' ',' ',' ','B',0};
104 static const WCHAR s_1_4X
[] = {'B',' ',' ',' ',0};
105 static const WCHAR s_14d2
[] = {' ',' ','1','1',0};
106 static const WCHAR s_1_4d
[] = {'1',' ',' ',' ',0};
107 static const WCHAR s_1AB
[] = {' ','1','A','B',0};
108 static const WCHAR s_2pct
[] = {' ','%','%',' ',0};
109 static const WCHAR s_2dot147
[] = {' ','.','.',' ',' ','4','2','7',0};
110 static const WCHAR s_yah
[] = {'y','a','h','!',0};
111 static const WCHAR s_space
[] = {' ',' ',' ',' ',0};
112 static const WCHAR s_nrt
[] = {'\r','\n','\r','\t',0};
113 static const WCHAR s_hi_crlf
[] = {'h','i','\r','\n',0};
114 static const WCHAR s_crlf
[] = {'\r','\n',0};
115 static const WCHAR s_crlfcrlf
[] = {'\r','\n','\r','\n',0};
116 static const WCHAR s_hi_sp
[] = {'h','i',' ',0};
117 static const WCHAR s_sp
[] = {' ',0};
118 static const WCHAR s_2sp
[] = {' ',' ',0};
119 static const WCHAR s_spt
[] = {' ',' ','t',0};
120 static const WCHAR s_sp3t
[] = {' ',' ',' ','t',0};
121 static const WCHAR s_sp03
[] = {' ',' ','0','3',0};
122 static const WCHAR s_sp001
[] = {' ',' ','0','0','1',0};
123 static const WCHAR s_sp001002
[] = {' ',' ','0','0','1',',',' ','0','0','0','2',0};
124 static const WCHAR s_sp001sp002
[] = {' ',' ','0','0','1',',',' ',' ','0','0','0','2',0};
125 static const WCHAR s_sp002sp001
[] = {' ',' ','0','0','0','2',',',' ',' ','0','0','1',0};
126 static const WCHAR s_sp002sp003
[] = {' ',' ','0','0','0','2',',',' ','0','0','0','0','3',0};
127 static const WCHAR s_sp001004
[] = {' ',' ','0','0','1',',','0','0','0','0','0','4',0};
128 static const WCHAR s_null
[] = {'(','n','u','l','l',')',0};
130 static const WCHAR init_buf
[] = {'x', 'x', 'x', 'x', 'x', 'x'};
131 static const WCHAR broken_buf
[] = {'t','e','s','t','x','x'};
133 WCHAR out
[0x100] = {0};
137 r
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
, test
, 0,
138 0, out
, sizeof(out
)/sizeof(WCHAR
), NULL
);
139 ok(!lstrcmpW(test
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
140 ok(r
==4, "failed: r=%d\n", r
);
142 /* null string, crashes on Windows */
145 SetLastError(0xdeadbeef);
146 memcpy(out
, init_buf
, sizeof(init_buf
));
147 FormatMessageW(FORMAT_MESSAGE_FROM_STRING
, NULL
, 0,
148 0, out
, sizeof(out
)/sizeof(WCHAR
), NULL
);
152 SetLastError(0xdeadbeef);
153 memcpy(out
, init_buf
, sizeof(init_buf
));
154 r
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
, empty
, 0,
155 0, out
, sizeof(out
)/sizeof(WCHAR
), NULL
);
156 error
= GetLastError();
157 ok(!lstrcmpW(empty
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
158 ok(r
==0, "succeeded: r=%d\n", r
);
159 ok(error
==0xdeadbeef, "last error %u\n", error
);
161 /* format placeholder with no specifier */
162 SetLastError(0xdeadbeef);
163 memcpy(out
, init_buf
, sizeof(init_buf
));
164 r
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
, fmt_null
, 0,
165 0, out
, sizeof(out
)/sizeof(WCHAR
), NULL
);
166 error
= GetLastError();
167 ok(!memcmp(out
, init_buf
, sizeof(init_buf
)),
168 "Expected the buffer to be unchanged\n");
169 ok(r
==0, "succeeded: r=%d\n", r
);
170 ok(error
==ERROR_INVALID_PARAMETER
, "last error %u\n", error
);
172 /* test string with format placeholder with no specifier */
173 SetLastError(0xdeadbeef);
174 memcpy(out
, init_buf
, sizeof(init_buf
));
175 r
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
, fmt_tnull
, 0,
176 0, out
, sizeof(out
)/sizeof(WCHAR
), NULL
);
177 error
= GetLastError();
178 ok(!memcmp(out
, init_buf
, sizeof(init_buf
)) ||
179 broken(!memcmp(out
, broken_buf
, sizeof(broken_buf
))), /* W2K3+ */
180 "Expected the buffer to be unchanged\n");
181 ok(r
==0, "succeeded: r=%d\n", r
);
182 ok(error
==ERROR_INVALID_PARAMETER
, "last error %u\n", error
);
184 /* insertion with no variadic arguments */
185 SetLastError(0xdeadbeef);
186 memcpy(out
, init_buf
, sizeof(init_buf
));
187 r
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
, fmt_1
, 0,
188 0, out
, sizeof(out
)/sizeof(WCHAR
), NULL
);
189 error
= GetLastError();
190 ok(!memcmp(out
, init_buf
, sizeof(init_buf
)),
191 "Expected the buffer to be unchanged\n");
192 ok(r
==0, "succeeded: r=%d\n", r
);
193 ok(error
==ERROR_INVALID_PARAMETER
, "last error %u\n", error
);
195 SetLastError(0xdeadbeef);
196 memcpy(out
, init_buf
, sizeof(init_buf
));
197 r
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_ARGUMENT_ARRAY
, fmt_1
, 0,
198 0, out
, sizeof(out
)/sizeof(WCHAR
), NULL
);
199 error
= GetLastError();
200 ok(!memcmp(out
, init_buf
, sizeof(init_buf
)),
201 "Expected the buffer to be unchanged\n");
202 ok(r
==0, "succeeded: r=%d\n", r
);
203 ok(error
==ERROR_INVALID_PARAMETER
, "last error %u\n", error
);
205 /* using the format feature */
206 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_1s
, 0,
207 0, out
, sizeof(out
)/sizeof(WCHAR
), test
);
208 ok(!lstrcmpW(test
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
209 ok(r
==4,"failed: r=%d\n", r
);
212 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_1
, 0,
213 0, out
, sizeof(out
)/sizeof(WCHAR
), test
);
214 ok(!lstrcmpW(test
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
215 ok(r
==4,"failed: r=%d\n", r
);
218 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_12
, 0,
219 0, out
, sizeof(out
)/sizeof(WCHAR
), te
, st
);
220 ok(!lstrcmpW(test
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
221 ok(r
==4,"failed: r=%d\n", r
);
224 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_123
, 0,
225 0, out
, sizeof(out
)/sizeof(WCHAR
), t
, s
, e
);
226 ok(!lstrcmpW(test
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
227 ok(r
==4,"failed: r=%d\n", r
);
229 /* s doesn't seem to work in format strings */
230 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_s
, 0,
231 0, out
, sizeof(out
)/sizeof(WCHAR
), test
);
232 ok(!lstrcmpW(&fmt_s
[1], out
), "failed out=%s\n", wine_dbgstr_w(out
));
233 ok(r
==3, "failed: r=%d\n", r
);
236 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_ls
, 0,
237 0, out
, sizeof(out
)/sizeof(WCHAR
), test
);
238 ok(!lstrcmpW(&fmt_ls
[1], out
), "failed out=%s\n", wine_dbgstr_w(out
));
239 ok(r
==4, "failed: r=%d\n", r
);
242 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_S
, 0,
243 0, out
, sizeof(out
)/sizeof(WCHAR
), test
);
244 ok(!lstrcmpW(&fmt_S
[1], out
), "failed out=%s\n", wine_dbgstr_w(out
));
245 ok(r
==3, "failed: r=%d\n", r
);
248 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_ws
, 0,
249 0, out
, sizeof(out
)/sizeof(WCHAR
), test
);
250 ok(!lstrcmpW(&fmt_ws
[1], out
), "failed out=%s\n", wine_dbgstr_w(out
));
251 ok(r
==4, "failed: r=%d\n", r
);
254 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_123c
, 0,
255 0, out
, sizeof(out
)/sizeof(WCHAR
), 't', 'e', 's');
256 ok(!lstrcmpW(test
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
257 ok(r
==4,"failed: r=%d\n", r
);
260 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_123lc
, 0,
261 0, out
, sizeof(out
)/sizeof(WCHAR
), 't', 'e', 's');
262 ok(!lstrcmpW(test
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
263 ok(r
==4,"failed: r=%d\n", r
);
266 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_123wc
, 0,
267 0, out
, sizeof(out
)/sizeof(WCHAR
), 't', 'e', 's');
268 ok(!lstrcmpW(test
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
269 ok(r
==4,"failed: r=%d\n", r
);
272 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_123C
, 0,
273 0, out
, sizeof(out
)/sizeof(WCHAR
), 't', 'e', 's');
274 ok(!lstrcmpW(test
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
275 ok(r
==4,"failed: r=%d\n", r
);
278 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_123d
, 0,
279 0, out
, sizeof(out
)/sizeof(WCHAR
), 1, 2, 3);
280 ok(!lstrcmpW(s_123d
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
281 ok(r
==3,"failed: r=%d\n", r
);
283 /* a single digit with some spacing */
284 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_14d
, 0,
285 0, out
, sizeof(out
)/sizeof(WCHAR
), 1);
286 ok(!lstrcmpW(s_14d
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
287 ok(r
==4,"failed: r=%d\n", r
);
289 /* a single digit, left justified */
290 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_1_4d
, 0,
291 0, out
, sizeof(out
)/sizeof(CHAR
), 1);
292 ok(!lstrcmpW(s_1_4d
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
293 ok(r
==4,"failed: r=%d\n", r
);
295 /* two digit decimal number */
296 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_14d
, 0,
297 0, out
, sizeof(out
)/sizeof(WCHAR
), 11);
298 ok(!lstrcmpW(s_14d2
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
299 ok(r
==4,"failed: r=%d\n", r
);
302 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_14x
, 0,
303 0, out
, sizeof(out
)/sizeof(WCHAR
), 11);
304 ok(!lstrcmpW(s_14x
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
305 ok(r
==4,"failed: r=%d\n", r
);
307 /* a hex number, upper case */
308 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_14X
, 0,
309 0, out
, sizeof(out
)/sizeof(WCHAR
), 11);
310 ok(!lstrcmpW(s_14X
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
311 ok(r
==4,"failed: r=%d\n", r
);
313 /* a hex number, upper case, left justified */
314 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_1_4X
, 0,
315 0, out
, sizeof(out
)/sizeof(WCHAR
), 11);
316 ok(!lstrcmpW(s_1_4X
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
317 ok(r
==4,"failed: r=%d\n", r
);
319 /* a long hex number, upper case */
320 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_14X
, 0,
321 0, out
, sizeof(out
)/sizeof(WCHAR
), 0x1ab);
322 ok(!lstrcmpW(s_1AB
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
323 ok(r
==4,"failed: r=%d\n", r
);
326 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_2pct
, 0,
327 0, out
, sizeof(out
)/sizeof(WCHAR
));
328 ok(!lstrcmpW(s_2pct
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
329 ok(r
==4,"failed: r=%d\n", r
);
331 /* periods are special cases */
332 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_2dot1d
, 0,
333 0, out
, sizeof(out
)/sizeof(WCHAR
), 0x1ab);
334 ok(!lstrcmpW(s_2dot147
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
335 ok(r
==8,"failed: r=%d\n", r
);
337 /* %0 ends the line */
338 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_t0t
, 0,
339 0, out
, sizeof(out
)/sizeof(WCHAR
));
340 ok(!lstrcmpW(test
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
341 ok(r
==4,"failed: r=%d\n", r
);
343 /* %! prints an exclamation */
344 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_yah
, 0,
345 0, out
, sizeof(out
)/sizeof(WCHAR
));
346 ok(!lstrcmpW(s_yah
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
347 ok(r
==4,"failed: r=%d\n", r
);
350 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_space
, 0,
351 0, out
, sizeof(out
)/sizeof(WCHAR
));
352 ok(!lstrcmpW(s_space
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
353 ok(r
==4,"failed: r=%d\n", r
);
355 /* %n yields \r\n, %r yields \r, %t yields \t */
356 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_nrt
, 0,
357 0, out
, sizeof(out
)/sizeof(WCHAR
));
358 ok(!lstrcmpW(s_nrt
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
359 ok(r
==4,"failed: r=%d\n", r
);
362 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_hi_lf
, 0,
363 0, out
, sizeof(out
)/sizeof(WCHAR
));
364 ok(!lstrcmpW(s_hi_crlf
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
365 ok(r
==4,"failed: r=%d\n", r
);
367 /* carriage return line feed */
368 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_hi_crlf
, 0,
369 0, out
, sizeof(out
)/sizeof(WCHAR
));
370 ok(!lstrcmpW(s_hi_crlf
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
371 ok(r
==4,"failed: r=%d\n", r
);
373 /* carriage return */
374 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_cr
, 0,
375 0, out
, sizeof(out
)/sizeof(WCHAR
));
376 ok(!lstrcmpW(s_crlf
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
377 ok(r
==2,"failed: r=%d\n", r
);
379 /* double carriage return line feed */
380 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_crcrlf
, 0,
381 0, out
, sizeof(out
)/sizeof(WCHAR
));
382 ok(!lstrcmpW(s_crlfcrlf
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
383 ok(r
==4,"failed: r=%d\n", r
);
385 /* null string as argument */
386 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_1
, 0,
387 0, out
, sizeof(out
)/sizeof(WCHAR
), NULL
);
388 ok(!lstrcmpW(s_null
, out
),"failed out=[%s]\n", wine_dbgstr_w(out
));
389 ok(r
==6,"failed: r=%d\n",r
);
391 /* precision and width */
393 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_13s
,
394 0, 0, out
, sizeof(out
)/sizeof(WCHAR
), t
);
395 ok(!lstrcmpW(s_spt
, out
),"failed out=[%s]\n", wine_dbgstr_w(out
));
396 ok(r
==3, "failed: r=%d\n",r
);
397 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_1os
,
398 0, 0, out
, sizeof(out
)/sizeof(WCHAR
), 4, t
);
399 ok(!lstrcmpW( s_sp3t
, out
),"failed out=[%s]\n", wine_dbgstr_w(out
));
400 ok(r
==4,"failed: r=%d\n",r
);
401 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_142u
,
402 0, 0, out
, sizeof(out
)/sizeof(WCHAR
), 3 );
403 ok(!lstrcmpW( s_sp03
, out
),"failed out=[%s]\n", wine_dbgstr_w(out
));
404 ok(r
==4,"failed: r=%d\n",r
);
405 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_1oou
,
406 0, 0, out
, sizeof(out
)/sizeof(WCHAR
), 5, 3, 1 );
407 ok(!lstrcmpW( s_sp001
, out
),"failed out=[%s]\n", wine_dbgstr_w(out
));
408 ok(r
==5,"failed: r=%d\n",r
);
409 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_1oou1oou
,
410 0, 0, out
, sizeof(out
)/sizeof(WCHAR
), 5, 3, 1, 4, 2 );
411 ok(!lstrcmpW( s_sp001002
, out
),"failed out=[%s]\n", wine_dbgstr_w(out
));
412 ok(r
==11,"failed: r=%d\n",r
);
413 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_1oou3oou
,
414 0, 0, out
, sizeof(out
)/sizeof(WCHAR
), 5, 3, 1, 6, 4, 2 );
415 ok(!lstrcmpW( s_sp001sp002
, out
) ||
416 broken(!lstrcmpW(s_sp001004
, out
)), /* NT4/Win2k */
417 "failed out=[%s]\n", wine_dbgstr_w(out
));
418 ok(r
==12,"failed: r=%d\n",r
);
419 /* args are not counted the same way with an argument array */
421 ULONG_PTR args
[] = { 6, 4, 2, 5, 3, 1 };
422 r
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_ARGUMENT_ARRAY
, fmt_1oou1oou
,
423 0, 0, out
, sizeof(out
)/sizeof(WCHAR
), (__ms_va_list
*)args
);
424 ok(!lstrcmpW(s_sp002sp003
, out
),"failed out=[%s]\n", wine_dbgstr_w(out
));
425 ok(r
==13,"failed: r=%d\n",r
);
426 r
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_ARGUMENT_ARRAY
, fmt_1oou4oou
,
427 0, 0, out
, sizeof(out
)/sizeof(WCHAR
), (__ms_va_list
*)args
);
428 ok(!lstrcmpW(s_sp002sp001
, out
),"failed out=[%s]\n", wine_dbgstr_w(out
));
429 ok(r
==12,"failed: r=%d\n",r
);
432 /* change of pace... test the low byte of dwflags */
435 r
= doitW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_MAX_WIDTH_MASK
, fmt_hi_lf
, 0,
436 0, out
, sizeof(out
)/sizeof(WCHAR
));
437 ok(!lstrcmpW(s_hi_sp
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
438 ok(r
==3,"failed: r=%d\n", r
);
440 /* carriage return line feed */
441 r
= doitW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_MAX_WIDTH_MASK
, fmt_hi_crlf
, 0,
442 0, out
, sizeof(out
)/sizeof(WCHAR
));
443 ok(!lstrcmpW(s_hi_sp
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
444 ok(r
==3,"failed: r=%d\n", r
);
446 /* carriage return */
447 r
= doitW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_MAX_WIDTH_MASK
, fmt_cr
, 0,
448 0, out
, sizeof(out
)/sizeof(WCHAR
));
449 ok(!lstrcmpW(s_sp
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
450 ok(r
==1,"failed: r=%d\n", r
);
452 /* double carriage return line feed */
453 r
= doitW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_MAX_WIDTH_MASK
, fmt_crcrlf
, 0,
454 0, out
, sizeof(out
)/sizeof(WCHAR
));
455 ok(!lstrcmpW(s_2sp
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
456 ok(r
==2,"failed: r=%d\n", r
);
459 static void test_message_from_string(void)
461 CHAR out
[0x100] = {0};
463 static const char init_buf
[] = {'x', 'x', 'x', 'x', 'x', 'x'};
464 static const WCHAR szwTest
[] = { 't','e','s','t',0};
467 r
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
, "test", 0,
468 0, out
, sizeof(out
)/sizeof(CHAR
),NULL
);
469 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
470 ok(r
==4,"failed: r=%d\n",r
);
472 /* null string, crashes on Windows */
475 SetLastError(0xdeadbeef);
476 memcpy(out
, init_buf
, sizeof(init_buf
));
477 FormatMessageA(FORMAT_MESSAGE_FROM_STRING
, NULL
, 0,
478 0, out
, sizeof(out
)/sizeof(CHAR
), NULL
);
482 SetLastError(0xdeadbeef);
483 memcpy(out
, init_buf
, sizeof(init_buf
));
484 r
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
, "", 0,
485 0, out
, sizeof(out
)/sizeof(CHAR
), NULL
);
486 ok(!memcmp(out
, init_buf
, sizeof(init_buf
)), "Expected the buffer to be untouched\n");
487 ok(r
==0, "succeeded: r=%d\n", r
);
488 ok(GetLastError()==0xdeadbeef,
489 "last error %u\n", GetLastError());
491 /* format placeholder with no specifier */
492 SetLastError(0xdeadbeef);
493 memcpy(out
, init_buf
, sizeof(init_buf
));
494 r
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
, "%", 0,
495 0, out
, sizeof(out
)/sizeof(CHAR
), NULL
);
496 ok(!memcmp(out
, init_buf
, sizeof(init_buf
)),
497 "Expected the buffer to be untouched\n");
498 ok(r
==0, "succeeded: r=%d\n", r
);
499 ok(GetLastError()==ERROR_INVALID_PARAMETER
,
500 "last error %u\n", GetLastError());
502 /* test string with format placeholder with no specifier */
503 SetLastError(0xdeadbeef);
504 memcpy(out
, init_buf
, sizeof(init_buf
));
505 r
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
, "test%", 0,
506 0, out
, sizeof(out
)/sizeof(CHAR
), NULL
);
507 ok(!memcmp(out
, init_buf
, sizeof(init_buf
)),
508 "Expected the buffer to be untouched\n");
509 ok(r
==0, "succeeded: r=%d\n", r
);
510 ok(GetLastError()==ERROR_INVALID_PARAMETER
,
511 "last error %u\n", GetLastError());
513 /* insertion with no variadic arguments */
514 SetLastError(0xdeadbeef);
515 memcpy(out
, init_buf
, sizeof(init_buf
));
516 r
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
, "%1", 0,
517 0, out
, sizeof(out
)/sizeof(CHAR
), NULL
);
518 ok(!memcmp(out
, init_buf
, sizeof(init_buf
)), "Expected the buffer to be untouched\n");
519 ok(r
==0, "succeeded: r=%d\n", r
);
520 ok(GetLastError()==ERROR_INVALID_PARAMETER
, "last error %u\n", GetLastError());
522 SetLastError(0xdeadbeef);
523 memcpy(out
, init_buf
, sizeof(init_buf
));
524 r
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_ARGUMENT_ARRAY
, "%1", 0,
525 0, out
, sizeof(out
)/sizeof(CHAR
), NULL
);
526 ok(!memcmp(out
, init_buf
, sizeof(init_buf
)), "Expected the buffer to be untouched\n");
527 ok(r
==0, "succeeded: r=%d\n", r
);
528 ok(GetLastError()==ERROR_INVALID_PARAMETER
, "last error %u\n", GetLastError());
530 /* using the format feature */
531 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!s!", 0,
532 0, out
, sizeof(out
)/sizeof(CHAR
), "test");
533 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
534 ok(r
==4,"failed: r=%d\n",r
);
537 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1", 0,
538 0, out
, sizeof(out
)/sizeof(CHAR
), "test");
539 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
540 ok(r
==4,"failed: r=%d\n",r
);
543 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1%2", 0,
544 0, out
, sizeof(out
)/sizeof(CHAR
), "te","st");
545 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
546 ok(r
==4,"failed: r=%d\n",r
);
549 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1%3%2%1", 0,
550 0, out
, sizeof(out
)/sizeof(CHAR
), "t","s","e");
551 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
552 ok(r
==4,"failed: r=%d\n",r
);
554 /* s doesn't seem to work in format strings */
555 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%!s!", 0,
556 0, out
, sizeof(out
)/sizeof(CHAR
), "test");
557 ok(!strcmp("!s!", out
),"failed out=[%s]\n",out
);
558 ok(r
==3,"failed: r=%d\n",r
);
561 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!ls!", 0,
562 0, out
, sizeof(out
)/sizeof(CHAR
), szwTest
);
563 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
564 ok(r
==4,"failed: r=%d\n",r
);
567 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!S!", 0,
568 0, out
, sizeof(out
)/sizeof(CHAR
), szwTest
);
569 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
570 ok(r
==4,"failed: r=%d\n",r
);
573 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!ws!", 0,
574 0, out
, sizeof(out
)/sizeof(CHAR
), szwTest
);
575 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
576 ok(r
==4,"failed: r=%d\n",r
);
579 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!c!%2!c!%3!c!%1!c!", 0,
580 0, out
, sizeof(out
)/sizeof(CHAR
), 't','e','s');
581 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
582 ok(r
==4,"failed: r=%d\n",r
);
585 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!lc!%2!lc!%3!lc!%1!lc!", 0,
586 0, out
, sizeof(out
)/sizeof(CHAR
), 't','e','s');
587 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
588 ok(r
==4,"failed: r=%d\n",r
);
591 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!wc!%2!wc!%3!wc!%1!wc!", 0,
592 0, out
, sizeof(out
)/sizeof(CHAR
), 't','e','s');
593 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
594 ok(r
==4,"failed: r=%d\n",r
);
597 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!C!%2!C!%3!C!%1!C!", 0,
598 0, out
, sizeof(out
)/sizeof(CHAR
), 't','e','s');
599 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
600 ok(r
==4,"failed: r=%d\n",r
);
603 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!d!%2!d!%3!d!", 0,
604 0, out
, sizeof(out
)/sizeof(CHAR
), 1,2,3);
605 ok(!strcmp("123", out
),"failed out=[%s]\n",out
);
606 ok(r
==3,"failed: r=%d\n",r
);
608 /* a single digit with some spacing */
609 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!4d!", 0,
610 0, out
, sizeof(out
)/sizeof(CHAR
), 1);
611 ok(!strcmp(" 1", out
),"failed out=[%s]\n",out
);
612 ok(r
==4,"failed: r=%d\n",r
);
614 /* a single digit, left justified */
615 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!-4d!", 0,
616 0, out
, sizeof(out
)/sizeof(CHAR
), 1);
617 ok(!strcmp("1 ", out
),"failed out=[%s]\n",out
);
618 ok(r
==4,"failed: r=%d\n",r
);
620 /* two digit decimal number */
621 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!4d!", 0,
622 0, out
, sizeof(out
)/sizeof(CHAR
), 11);
623 ok(!strcmp(" 11", out
),"failed out=[%s]\n",out
);
624 ok(r
==4,"failed: r=%d\n",r
);
627 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!4x!", 0,
628 0, out
, sizeof(out
)/sizeof(CHAR
), 11);
629 ok(!strcmp(" b", out
),"failed out=[%s]\n",out
);
630 ok(r
==4,"failed: r=%d\n",r
);
632 /* a hex number, upper case */
633 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!4X!", 0,
634 0, out
, sizeof(out
)/sizeof(CHAR
), 11);
635 ok(!strcmp(" B", out
),"failed out=[%s]\n",out
);
636 ok(r
==4,"failed: r=%d\n",r
);
638 /* a hex number, upper case, left justified */
639 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!-4X!", 0,
640 0, out
, sizeof(out
)/sizeof(CHAR
), 11);
641 ok(!strcmp("B ", out
),"failed out=[%s]\n",out
);
642 ok(r
==4,"failed: r=%d\n",r
);
644 /* a long hex number, upper case */
645 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!4X!", 0,
646 0, out
, sizeof(out
)/sizeof(CHAR
), 0x1ab);
647 ok(!strcmp(" 1AB", out
),"failed out=[%s]\n",out
);
648 ok(r
==4,"failed: r=%d\n",r
);
651 r
= doit(FORMAT_MESSAGE_FROM_STRING
, " %%%% ", 0,
652 0, out
, sizeof(out
)/sizeof(CHAR
));
653 ok(!strcmp(" %% ", out
),"failed out=[%s]\n",out
);
654 ok(r
==4,"failed: r=%d\n",r
);
656 /* periods are special cases */
657 r
= doit(FORMAT_MESSAGE_FROM_STRING
, " %.%. %1!d!", 0,
658 0, out
, sizeof(out
)/sizeof(CHAR
), 0x1ab);
659 ok(!strcmp(" .. 427", out
),"failed out=[%s]\n",out
);
660 ok(r
==7,"failed: r=%d\n",r
);
662 /* %0 ends the line */
663 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "test%0test", 0,
664 0, out
, sizeof(out
)/sizeof(CHAR
));
665 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
666 ok(r
==4,"failed: r=%d\n",r
);
668 /* %! prints an exclamation */
669 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "yah%!%0 ", 0,
670 0, out
, sizeof(out
)/sizeof(CHAR
));
671 ok(!strcmp("yah!", out
),"failed out=[%s]\n",out
);
672 ok(r
==4,"failed: r=%d\n",r
);
675 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "% % ", 0,
676 0, out
, sizeof(out
)/sizeof(CHAR
));
677 ok(!strcmp(" ", out
),"failed out=[%s]\n",out
);
678 ok(r
==4,"failed: r=%d\n",r
);
680 /* %n yields \r\n, %r yields \r, %t yields \t */
681 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%n%r%t", 0,
682 0, out
, sizeof(out
)/sizeof(CHAR
));
683 ok(!strcmp("\r\n\r\t", out
),"failed out=[%s]\n",out
);
684 ok(r
==4,"failed: r=%d\n",r
);
687 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "hi\n", 0,
688 0, out
, sizeof(out
)/sizeof(CHAR
));
689 ok(!strcmp("hi\r\n", out
),"failed out=[%s]\n",out
);
690 ok(r
==4,"failed: r=%d\n",r
);
692 /* carriage return line feed */
693 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "hi\r\n", 0,
694 0, out
, sizeof(out
)/sizeof(CHAR
));
695 ok(!strcmp("hi\r\n", out
),"failed out=[%s]\n",out
);
696 ok(r
==4,"failed: r=%d\n",r
);
698 /* carriage return */
699 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "\r", 0,
700 0, out
, sizeof(out
)/sizeof(CHAR
));
701 ok(!strcmp("\r\n", out
),"failed out=[%s]\n",out
);
702 ok(r
==2,"failed: r=%d\n",r
);
704 /* double carriage return line feed */
705 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "\r\r\n", 0,
706 0, out
, sizeof(out
)/sizeof(CHAR
));
707 ok(!strcmp("\r\n\r\n", out
),"failed out=[%s]\n",out
);
708 ok(r
==4,"failed: r=%d\n",r
);
710 /* null string as argument */
711 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1", 0,
712 0, out
, sizeof(out
)/sizeof(CHAR
), NULL
);
713 ok(!strcmp("(null)", out
),"failed out=[%s]\n",out
);
714 ok(r
==6,"failed: r=%d\n",r
);
716 /* precision and width */
718 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!3s!",
719 0, 0, out
, sizeof(out
), "t" );
720 ok(!strcmp(" t", out
),"failed out=[%s]\n",out
);
721 ok(r
==3, "failed: r=%d\n",r
);
722 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!*s!",
723 0, 0, out
, sizeof(out
), 4, "t");
724 if (!strcmp("*s",out
)) win_skip( "width/precision not supported\n" );
727 ok(!strcmp( " t", out
),"failed out=[%s]\n",out
);
728 ok(r
==4,"failed: r=%d\n",r
);
729 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!4.2u!",
730 0, 0, out
, sizeof(out
), 3 );
731 ok(!strcmp( " 03", out
),"failed out=[%s]\n",out
);
732 ok(r
==4,"failed: r=%d\n",r
);
733 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!*.*u!",
734 0, 0, out
, sizeof(out
), 5, 3, 1 );
735 ok(!strcmp( " 001", out
),"failed out=[%s]\n",out
);
736 ok(r
==5,"failed: r=%d\n",r
);
737 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!*.*u!,%1!*.*u!",
738 0, 0, out
, sizeof(out
), 5, 3, 1, 4, 2 );
739 ok(!strcmp( " 001, 0002", out
),"failed out=[%s]\n",out
);
740 ok(r
==11,"failed: r=%d\n",r
);
741 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!*.*u!,%3!*.*u!",
742 0, 0, out
, sizeof(out
), 5, 3, 1, 6, 4, 2 );
743 /* older Win versions marked as broken even though this is arguably the correct behavior */
744 /* but the new (brain-damaged) behavior is specified on MSDN */
745 ok(!strcmp( " 001, 0002", out
) ||
746 broken(!strcmp(" 001,000004", out
)), /* NT4/Win2k */
747 "failed out=[%s]\n",out
);
748 ok(r
==12,"failed: r=%d\n",r
);
749 /* args are not counted the same way with an argument array */
751 ULONG_PTR args
[] = { 6, 4, 2, 5, 3, 1 };
752 r
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_ARGUMENT_ARRAY
,
753 "%1!*.*u!,%1!*.*u!", 0, 0, out
, sizeof(out
), (__ms_va_list
*)args
);
754 ok(!strcmp(" 0002, 00003", out
),"failed out=[%s]\n",out
);
755 ok(r
==13,"failed: r=%d\n",r
);
756 r
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_ARGUMENT_ARRAY
,
757 "%1!*.*u!,%4!*.*u!", 0, 0, out
, sizeof(out
), (__ms_va_list
*)args
);
758 ok(!strcmp(" 0002, 001", out
),"failed out=[%s]\n",out
);
759 ok(r
==12,"failed: r=%d\n",r
);
763 /* change of pace... test the low byte of dwflags */
766 r
= doit(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_MAX_WIDTH_MASK
, "hi\n", 0,
767 0, out
, sizeof(out
)/sizeof(CHAR
));
768 ok(!strcmp("hi ", out
), "failed out=[%s]\n",out
);
769 ok(r
==3, "failed: r=%d\n",r
);
771 /* carriage return line feed */
772 r
= doit(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_MAX_WIDTH_MASK
, "hi\r\n", 0,
773 0, out
, sizeof(out
)/sizeof(CHAR
));
774 ok(!strcmp("hi ", out
),"failed out=[%s]\n",out
);
775 ok(r
==3,"failed: r=%d\n",r
);
777 /* carriage return */
778 r
= doit(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_MAX_WIDTH_MASK
, "\r", 0,
779 0, out
, sizeof(out
)/sizeof(CHAR
));
780 ok(!strcmp(" ", out
),"failed out=[%s]\n",out
);
781 ok(r
==1,"failed: r=%d\n",r
);
783 /* double carriage return line feed */
784 r
= doit(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_MAX_WIDTH_MASK
, "\r\r\n", 0,
785 0, out
, sizeof(out
)/sizeof(CHAR
));
786 ok(!strcmp(" ", out
),"failed out=[%s]\n",out
);
787 ok(r
==2,"failed: r=%d\n",r
);
790 static void test_message_ignore_inserts(void)
792 static const char init_buf
[] = {'x', 'x', 'x', 'x', 'x'};
797 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
, "test", 0, 0, out
,
798 sizeof(out
)/sizeof(CHAR
), NULL
);
799 ok(ret
== 4, "Expected FormatMessageA to return 4, got %d\n", ret
);
800 ok(!strcmp("test", out
), "Expected output string \"test\", got %s\n", out
);
802 /* The %0 escape sequence is handled. */
803 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
, "test%0", 0, 0, out
,
804 sizeof(out
)/sizeof(CHAR
), NULL
);
805 ok(ret
== 4, "Expected FormatMessageA to return 4, got %d\n", ret
);
806 ok(!strcmp("test", out
), "Expected output string \"test\", got %s\n", out
);
808 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
, "test%0test", 0, 0, out
,
809 sizeof(out
)/sizeof(CHAR
), NULL
);
810 ok(ret
== 4, "Expected FormatMessageA to return 4, got %d\n", ret
);
811 ok(!strcmp("test", out
), "Expected output string \"test\", got %s\n", out
);
813 /* While FormatMessageA returns 0 in this case, no last error code is set. */
814 SetLastError(0xdeadbeef);
815 memcpy(out
, init_buf
, sizeof(init_buf
));
816 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
, "%0test", 0, 0, out
,
817 sizeof(out
)/sizeof(CHAR
), NULL
);
818 ok(ret
== 0, "Expected FormatMessageA to return 0, got %d\n", ret
);
819 ok(!memcmp(out
, init_buf
, sizeof(init_buf
)), "Expected the output buffer to be untouched\n");
820 ok(GetLastError() == 0xdeadbeef, "Expected GetLastError() to return 0xdeadbeef, got %u\n", GetLastError());
822 /* Insert sequences are ignored. */
823 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
, "test%1%2!*.*s!%99", 0, 0, out
,
824 sizeof(out
)/sizeof(CHAR
), NULL
);
825 ok(ret
== 17, "Expected FormatMessageA to return 17, got %d\n", ret
);
826 ok(!strcmp("test%1%2!*.*s!%99", out
), "Expected output string \"test%%1%%2!*.*s!%%99\", got %s\n", out
);
828 /* Only the "%n", "%r", and "%t" escape sequences are processed. */
829 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
, "%%% %.%!", 0, 0, out
,
830 sizeof(out
)/sizeof(CHAR
), NULL
);
831 ok(ret
== 8, "Expected FormatMessageA to return 8, got %d\n", ret
);
832 ok(!strcmp("%%% %.%!", out
), "Expected output string \"%%%%%% %%.%%!\", got %s\n", out
);
834 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
, "%n%r%t", 0, 0, out
,
835 sizeof(out
)/sizeof(CHAR
), NULL
);
836 ok(ret
== 4, "Expected FormatMessageA to return 4, got %d\n", ret
);
837 ok(!strcmp("\r\n\r\t", out
), "Expected output string \"\\r\\n\\r\\t\", got %s\n", out
);
839 /* CRLF characters are processed normally. */
840 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
, "hi\n", 0, 0, out
,
841 sizeof(out
)/sizeof(CHAR
), NULL
);
842 ok(ret
== 4, "Expected FormatMessageA to return 4, got %d\n", ret
);
843 ok(!strcmp("hi\r\n", out
), "Expected output string \"hi\\r\\n\", got %s\n", out
);
845 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
, "hi\r\n", 0, 0, out
,
846 sizeof(out
)/sizeof(CHAR
), NULL
);
847 ok(ret
== 4, "Expected FormatMessageA to return 4, got %d\n", ret
);
848 ok(!strcmp("hi\r\n", out
), "Expected output string \"hi\\r\\n\", got %s\n", out
);
850 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
, "\r", 0, 0, out
,
851 sizeof(out
)/sizeof(CHAR
), NULL
);
852 ok(ret
== 2, "Expected FormatMessageA to return 2, got %d\n", ret
);
853 ok(!strcmp("\r\n", out
), "Expected output string \"\\r\\n\", got %s\n", out
);
855 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
, "\r\r\n", 0, 0, out
,
856 sizeof(out
)/sizeof(CHAR
), NULL
);
857 ok(ret
== 4, "Expected FormatMessageA to return 4, got %d\n", ret
);
858 ok(!strcmp("\r\n\r\n", out
), "Expected output string \"\\r\\n\\r\\n\", got %s\n", out
);
860 /* The width parameter is handled the same also. */
861 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
|
862 FORMAT_MESSAGE_MAX_WIDTH_MASK
, "hi\n", 0, 0, out
,
863 sizeof(out
)/sizeof(CHAR
), NULL
);
864 ok(!strcmp("hi ", out
), "Expected output string \"hi \", got %s\n", out
);
865 ok(ret
== 3, "Expected FormatMessageA to return 3, got %d\n", ret
);
867 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
|
868 FORMAT_MESSAGE_MAX_WIDTH_MASK
, "hi\r\n", 0, 0, out
,
869 sizeof(out
)/sizeof(CHAR
), NULL
);
870 ok(ret
== 3, "Expected FormatMessageA to return 3, got %d\n", ret
);
871 ok(!strcmp("hi ", out
), "Expected output string \"hi \", got %s\n", out
);
873 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
|
874 FORMAT_MESSAGE_MAX_WIDTH_MASK
, "\r", 0, 0, out
,
875 sizeof(out
)/sizeof(CHAR
), NULL
);
876 ok(ret
== 1, "Expected FormatMessageA to return 1, got %d\n", ret
);
877 ok(!strcmp(" ", out
), "Expected output string \" \", got %s\n", out
);
879 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
|
880 FORMAT_MESSAGE_MAX_WIDTH_MASK
, "\r\r\n", 0, 0, out
,
881 sizeof(out
)/sizeof(CHAR
), NULL
);
882 ok(ret
== 2, "Expected FormatMessageA to return 2, got %d\n", ret
);
883 ok(!strcmp(" ", out
), "Expected output string \" \", got %s\n", out
);
886 static void test_message_ignore_inserts_wide(void)
888 static const WCHAR test
[] = {'t','e','s','t',0};
889 static const WCHAR empty
[] = {0};
890 static const WCHAR fmt_t0
[] = {'t','e','s','t','%','0',0};
891 static const WCHAR fmt_t0t
[] = {'t','e','s','t','%','0','t','e','s','t',0};
892 static const WCHAR fmt_0t
[] = {'%','0','t','e','s','t',0};
893 static const WCHAR fmt_t12oos99
[] = {'t','e','s','t','%','1','%','2','!','*','.','*','s','!','%','9','9',0};
894 static const WCHAR fmt_pctspacedot
[] = {'%','%','%',' ','%','.','%','!',0};
895 static const WCHAR fmt_nrt
[] = {'%','n','%','r','%','t',0};
896 static const WCHAR fmt_hi_lf
[] = {'h','i','\n',0};
897 static const WCHAR fmt_hi_crlf
[] = {'h','i','\r','\n',0};
898 static const WCHAR fmt_cr
[] = {'\r',0};
899 static const WCHAR fmt_crcrlf
[] = {'\r','\r','\n',0};
901 static const WCHAR s_nrt
[] = {'\r','\n','\r','\t',0};
902 static const WCHAR s_hi_crlf
[] = {'h','i','\r','\n',0};
903 static const WCHAR s_crlf
[] = {'\r','\n',0};
904 static const WCHAR s_crlfcrlf
[] = {'\r','\n','\r','\n',0};
905 static const WCHAR s_hi_sp
[] = {'h','i',' ',0};
906 static const WCHAR s_sp
[] = {' ',0};
907 static const WCHAR s_2sp
[] = {' ',' ',0};
912 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
, test
, 0, 0, out
,
913 sizeof(out
)/sizeof(WCHAR
), NULL
);
914 ok(ret
== 4, "Expected FormatMessageW to return 4, got %d\n", ret
);
915 ok(!lstrcmpW(test
, out
), "Expected output string \"test\", got %s\n", wine_dbgstr_w(out
));
917 /* The %0 escape sequence is handled. */
918 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
, fmt_t0
, 0, 0, out
,
919 sizeof(out
)/sizeof(WCHAR
), NULL
);
920 ok(ret
== 4, "Expected FormatMessageW to return 4, got %d\n", ret
);
921 ok(!lstrcmpW(test
, out
), "Expected output string \"test\", got %s\n", wine_dbgstr_w(out
));
923 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
, fmt_t0t
, 0, 0, out
,
924 sizeof(out
)/sizeof(WCHAR
), NULL
);
925 ok(ret
== 4, "Expected FormatMessageW to return 4, got %d\n", ret
);
926 ok(!lstrcmpW(test
, out
), "Expected output string \"test\", got %s\n", wine_dbgstr_w(out
));
928 /* While FormatMessageA returns 0 in this case, no last error code is set. */
929 SetLastError(0xdeadbeef);
930 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
, fmt_0t
, 0, 0, out
,
931 sizeof(out
)/sizeof(WCHAR
), NULL
);
932 ok(ret
== 0, "Expected FormatMessageW to return 0, got %d\n", ret
);
933 ok(!lstrcmpW(empty
, out
), "Expected the output buffer to be the empty string, got %s\n", wine_dbgstr_w(out
));
934 ok(GetLastError() == 0xdeadbeef, "Expected GetLastError() to return 0xdeadbeef, got %u\n", GetLastError());
936 /* Insert sequences are ignored. */
937 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
, fmt_t12oos99
, 0, 0, out
,
938 sizeof(out
)/sizeof(WCHAR
), NULL
);
939 ok(ret
== 17, "Expected FormatMessageW to return 17, got %d\n", ret
);
940 ok(!lstrcmpW(fmt_t12oos99
, out
), "Expected output string \"test%%1%%2!*.*s!%%99\", got %s\n", wine_dbgstr_w(out
));
942 /* Only the "%n", "%r", and "%t" escape sequences are processed. */
943 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
, fmt_pctspacedot
, 0, 0, out
,
944 sizeof(out
)/sizeof(WCHAR
), NULL
);
945 ok(ret
== 8, "Expected FormatMessageW to return 8, got %d\n", ret
);
946 ok(!lstrcmpW(fmt_pctspacedot
, out
), "Expected output string \"%%%%%% %%.%%!\", got %s\n", wine_dbgstr_w(out
));
948 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
, fmt_nrt
, 0, 0, out
,
949 sizeof(out
)/sizeof(WCHAR
), NULL
);
950 ok(ret
== 4, "Expected FormatMessageW to return 4, got %d\n", ret
);
951 ok(!lstrcmpW(s_nrt
, out
), "Expected output string \"\\r\\n\\r\\t\", got %s\n", wine_dbgstr_w(out
));
953 /* CRLF characters are processed normally. */
954 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
, fmt_hi_lf
, 0, 0, out
,
955 sizeof(out
)/sizeof(WCHAR
), NULL
);
956 ok(ret
== 4, "Expected FormatMessageW to return 4, got %d\n", ret
);
957 ok(!lstrcmpW(s_hi_crlf
, out
), "Expected output string \"hi\\r\\n\", got %s\n", wine_dbgstr_w(out
));
959 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
, fmt_hi_crlf
, 0, 0, out
,
960 sizeof(out
)/sizeof(WCHAR
), NULL
);
961 ok(ret
== 4, "Expected FormatMessageW to return 4, got %d\n", ret
);
962 ok(!lstrcmpW(s_hi_crlf
, out
), "Expected output string \"hi\\r\\n\", got %s\n", wine_dbgstr_w(out
));
964 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
, fmt_cr
, 0, 0, out
,
965 sizeof(out
)/sizeof(WCHAR
), NULL
);
966 ok(ret
== 2, "Expected FormatMessageW to return 2, got %d\n", ret
);
967 ok(!lstrcmpW(s_crlf
, out
), "Expected output string \"\\r\\n\", got %s\n", wine_dbgstr_w(out
));
969 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
, fmt_crcrlf
, 0, 0, out
,
970 sizeof(out
)/sizeof(WCHAR
), NULL
);
971 ok(ret
== 4, "Expected FormatMessageW to return 4, got %d\n", ret
);
972 ok(!lstrcmpW(s_crlfcrlf
, out
), "Expected output string \"\\r\\n\\r\\n\", got %s\n", wine_dbgstr_w(out
));
974 /* The width parameter is handled the same also. */
975 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
|
976 FORMAT_MESSAGE_MAX_WIDTH_MASK
, fmt_hi_lf
, 0, 0, out
,
977 sizeof(out
)/sizeof(WCHAR
), NULL
);
978 ok(ret
== 3, "Expected FormatMessageW to return 3, got %d\n", ret
);
979 ok(!lstrcmpW(s_hi_sp
, out
), "Expected output string \"hi \", got %s\n", wine_dbgstr_w(out
));
981 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
|
982 FORMAT_MESSAGE_MAX_WIDTH_MASK
, fmt_hi_crlf
, 0, 0, out
,
983 sizeof(out
)/sizeof(WCHAR
), NULL
);
984 ok(ret
== 3, "Expected FormatMessageW to return 3, got %d\n", ret
);
985 ok(!lstrcmpW(s_hi_sp
, out
), "Expected output string \"hi \", got %s\n", wine_dbgstr_w(out
));
987 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
|
988 FORMAT_MESSAGE_MAX_WIDTH_MASK
, fmt_cr
, 0, 0, out
,
989 sizeof(out
)/sizeof(WCHAR
), NULL
);
990 ok(ret
== 1, "Expected FormatMessageW to return 1, got %d\n", ret
);
991 ok(!lstrcmpW(s_sp
, out
), "Expected output string \" \", got %s\n", wine_dbgstr_w(out
));
993 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
|
994 FORMAT_MESSAGE_MAX_WIDTH_MASK
, fmt_crcrlf
, 0, 0, out
,
995 sizeof(out
)/sizeof(WCHAR
), NULL
);
996 ok(ret
== 2, "Expected FormatMessageW to return 2, got %d\n", ret
);
997 ok(!lstrcmpW(s_2sp
, out
), "Expected output string \" \", got %s\n", wine_dbgstr_w(out
));
1000 static void test_message_wrap(void)
1004 CHAR in
[300], out
[300], ref
[300];
1006 /* No need for wrapping */
1007 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| 20,
1008 "short long line", 0, 0, out
, sizeof(out
), NULL
);
1009 ok(ret
== 15, "Expected FormatMessageW to return 15, got %d\n", ret
);
1010 ok(!strcmp("short long line", out
),"failed out=[%s]\n",out
);
1012 /* Wrap the last word */
1013 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| 11,
1014 "short long line", 0, 0, out
, sizeof(out
), NULL
);
1015 todo_wine
ok(ret
== 16, "Expected FormatMessageW to return 16, got %d\n", ret
);
1016 todo_wine
ok(!strcmp("short long\r\nline", out
),"failed out=[%s]\n",out
);
1018 /* Strictly less than 10 characters per line! */
1019 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| 10,
1020 "short long line", 0, 0, out
, sizeof(out
), NULL
);
1021 todo_wine
ok(ret
== 16, "Expected FormatMessageW to return 16, got %d\n", ret
);
1022 todo_wine
ok(!strcmp("short\r\nlong line", out
),"failed out=[%s]\n",out
);
1024 /* Word longer than the line */
1025 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| 8,
1026 "shortlongline", 0, 0, out
, sizeof(out
), NULL
);
1027 todo_wine
ok(ret
== 15, "Expected FormatMessageW to return 15, got %d\n", ret
);
1028 todo_wine
ok(!strcmp("shortlon\r\ngline", out
),"failed out=[%s]\n",out
);
1030 /* Wrap the line multiple times */
1031 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| 7,
1032 "short long line", 0, 0, out
, sizeof(out
), NULL
);
1033 todo_wine
ok(ret
== 17, "Expected FormatMessageW to return 17, got %d\n", ret
);
1034 todo_wine
ok(!strcmp("short\r\nlong\r\nline", out
),"failed out=[%s]\n",out
);
1036 /* '\n's in the source are ignored */
1037 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| 11,
1038 "short\nlong line", 0, 0, out
, sizeof(out
), NULL
);
1039 todo_wine
ok(ret
== 16, "Expected FormatMessageW to return 16, got %d\n", ret
);
1040 todo_wine
ok(!strcmp("short long\r\nline", out
),"failed out=[%s]\n",out
);
1042 /* '%n's are converted into line feeds */
1043 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| 11,
1044 "short%n%nlong line", 0, 0, out
, sizeof(out
), NULL
);
1045 ok(ret
== 18, "Expected FormatMessageW to return 18, got %d\n", ret
);
1046 ok(!strcmp("short\r\n\r\nlong line", out
),"failed out=[%s]\n",out
);
1048 /* '%n's count as starting a new line and combine with line wrapping */
1049 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| 10,
1050 "short%nlong line", 0, 0, out
, sizeof(out
), NULL
);
1051 ok(ret
== 16, "Expected FormatMessageW to return 16, got %d\n", ret
);
1052 ok(!strcmp("short\r\nlong line", out
),"failed out=[%s]\n",out
);
1054 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| 8,
1055 "short%nlong line", 0, 0, out
, sizeof(out
), NULL
);
1056 todo_wine
ok(ret
== 17, "Expected FormatMessageW to return 17, got %d\n", ret
);
1057 todo_wine
ok(!strcmp("short\r\nlong\r\nline", out
),"failed out=[%s]\n",out
);
1059 /* '%r's also count as starting a new line and all */
1060 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| 10,
1061 "short%rlong line", 0, 0, out
, sizeof(out
), NULL
);
1062 ok(ret
== 15, "Expected FormatMessageW to return 15, got %d\n", ret
);
1063 ok(!strcmp("short\rlong line", out
),"failed out=[%s]\n",out
);
1065 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| 8,
1066 "short%rlong line", 0, 0, out
, sizeof(out
), NULL
);
1067 todo_wine
ok(ret
== 16, "Expected FormatMessageW to return 16, got %d\n", ret
);
1068 todo_wine
ok(!strcmp("short\rlong\r\nline", out
),"failed out=[%s]\n",out
);
1070 /* IGNORE_INSERTS does not prevent line wrapping or disable '%n' */
1071 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_IGNORE_INSERTS
| 8,
1072 "short%nlong line%1", 0, 0, out
, sizeof(out
), NULL
);
1073 todo_wine
ok(ret
== 19, "Expected FormatMessageW to return 19, got %d\n", ret
);
1074 todo_wine
ok(!strcmp("short\r\nlong\r\nline%1", out
),"failed out=[%s]\n",out
);
1076 /* MAX_WIDTH_MASK is the same as specifying an infinite line width */
1077 strcpy(in
, "first line%n");
1078 strcpy(ref
, "first line\r\n");
1079 for (i
=0; i
< 26; i
++)
1081 strcat(in
, "123456789 ");
1082 strcat(ref
, "123456789 ");
1084 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_MAX_WIDTH_MASK
,
1085 in
, 0, 0, out
, sizeof(out
), NULL
);
1086 ok(ret
== 272, "Expected FormatMessageW to return 272, got %d\n", ret
);
1087 ok(!strcmp(ref
, out
),"failed out=[%s]\n",out
);
1089 /* Wrapping and non-space characters */
1090 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| 11,
1091 "short long\tline", 0, 0, out
, sizeof(out
), NULL
);
1092 todo_wine
ok(ret
== 16, "Expected FormatMessageW to return 16, got %d\n", ret
);
1093 todo_wine
ok(!strcmp("short\r\nlong\tline", out
),"failed out=[%s]\n",out
);
1095 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| 11,
1096 "short long-line", 0, 0, out
, sizeof(out
), NULL
);
1097 todo_wine
ok(ret
== 16, "Expected FormatMessageW to return 16, got %d\n", ret
);
1098 todo_wine
ok(!strcmp("short\r\nlong-line", out
),"failed out=[%s]\n",out
);
1100 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| 11,
1101 "short long_line", 0, 0, out
, sizeof(out
), NULL
);
1102 todo_wine
ok(ret
== 16, "Expected FormatMessageW to return 16, got %d\n", ret
);
1103 todo_wine
ok(!strcmp("short\r\nlong_line", out
),"failed out=[%s]\n",out
);
1105 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| 11,
1106 "short long.line", 0, 0, out
, sizeof(out
), NULL
);
1107 todo_wine
ok(ret
== 16, "Expected FormatMessageW to return 16, got %d\n", ret
);
1108 todo_wine
ok(!strcmp("short\r\nlong.line", out
),"failed out=[%s]\n",out
);
1110 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| 11,
1111 "short long,line", 0, 0, out
, sizeof(out
), NULL
);
1112 todo_wine
ok(ret
== 16, "Expected FormatMessageW to return 16, got %d\n", ret
);
1113 todo_wine
ok(!strcmp("short\r\nlong,line", out
),"failed out=[%s]\n",out
);
1115 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| 11,
1116 "short long!line", 0, 0, out
, sizeof(out
), NULL
);
1117 todo_wine
ok(ret
== 16, "Expected FormatMessageW to return 16, got %d\n", ret
);
1118 todo_wine
ok(!strcmp("short\r\nlong!line", out
),"failed out=[%s]\n",out
);
1120 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| 11,
1121 "short long?line", 0, 0, out
, sizeof(out
), NULL
);
1122 todo_wine
ok(ret
== 16, "Expected FormatMessageW to return 16, got %d\n", ret
);
1123 todo_wine
ok(!strcmp("short\r\nlong?line", out
),"failed out=[%s]\n",out
);
1126 static void test_message_insufficient_buffer(void)
1128 static const char init_buf
[] = {'x', 'x', 'x', 'x', 'x'};
1129 static const char expected_buf
[] = {'x', 'x', 'x', 'x', 'x'};
1133 SetLastError(0xdeadbeef);
1134 memcpy(out
, init_buf
, sizeof(init_buf
));
1135 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
, "test", 0, 0, out
, 0, NULL
);
1136 ok(ret
== 0, "Expected FormatMessageA to return 0, got %u\n", ret
);
1137 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
1138 "Expected GetLastError() to return ERROR_INSUFFICIENT_BUFFER, got %u\n",
1140 ok(!memcmp(expected_buf
, out
, sizeof(expected_buf
)),
1141 "Expected the buffer to be untouched\n");
1143 SetLastError(0xdeadbeef);
1144 memcpy(out
, init_buf
, sizeof(init_buf
));
1145 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
, "test", 0, 0, out
, 1, NULL
);
1146 ok(ret
== 0, "Expected FormatMessageA to return 0, got %u\n", ret
);
1147 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
1148 "Expected GetLastError() to return ERROR_INSUFFICIENT_BUFFER, got %u\n",
1150 ok(!memcmp(expected_buf
, out
, sizeof(expected_buf
)),
1151 "Expected the buffer to be untouched\n");
1153 SetLastError(0xdeadbeef);
1154 memcpy(out
, init_buf
, sizeof(init_buf
));
1155 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
, "test", 0, 0, out
, sizeof(out
)/sizeof(out
[0]) - 1, NULL
);
1156 ok(ret
== 0, "Expected FormatMessageA to return 0, got %u\n", ret
);
1157 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
1158 "Expected GetLastError() to return ERROR_INSUFFICIENT_BUFFER, got %u\n",
1160 ok(!memcmp(expected_buf
, out
, sizeof(expected_buf
)),
1161 "Expected the buffer to be untouched\n");
1164 static void test_message_insufficient_buffer_wide(void)
1166 static const WCHAR test
[] = {'t','e','s','t',0};
1167 static const WCHAR init_buf
[] = {'x', 'x', 'x', 'x', 'x'};
1168 static const WCHAR expected_buf
[] = {'x', 'x', 'x', 'x', 'x'};
1169 static const WCHAR broken_buf
[] = {0, 'x', 'x', 'x', 'x'};
1170 static const WCHAR broken2_buf
[] = {'t','e','s',0,'x'};
1175 SetLastError(0xdeadbeef);
1176 memcpy(out
, init_buf
, sizeof(init_buf
));
1177 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
, test
, 0, 0, out
, 0, NULL
);
1178 ok(ret
== 0, "Expected FormatMessageA to return 0, got %u\n", ret
);
1179 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
1180 "Expected GetLastError() to return ERROR_INSUFFICIENT_BUFFER, got %u\n",
1182 ok(!memcmp(expected_buf
, out
, sizeof(expected_buf
)),
1183 "Expected the buffer to be untouched\n");
1185 /* Windows Server 2003 and newer report failure but copy a
1186 * truncated string to the buffer for non-zero buffer sizes. */
1187 SetLastError(0xdeadbeef);
1188 memcpy(out
, init_buf
, sizeof(init_buf
));
1189 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
, test
, 0, 0, out
, 1, NULL
);
1190 ok(ret
== 0, "Expected FormatMessageA to return 0, got %u\n", ret
);
1191 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
1192 "Expected GetLastError() to return ERROR_INSUFFICIENT_BUFFER, got %u\n",
1194 ok(!memcmp(expected_buf
, out
, sizeof(expected_buf
)) ||
1195 broken(!memcmp(broken_buf
, out
, sizeof(broken_buf
))), /* W2K3+ */
1196 "Expected the buffer to be untouched\n");
1198 SetLastError(0xdeadbeef);
1199 memcpy(out
, init_buf
, sizeof(init_buf
));
1200 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
, test
, 0, 0, out
, sizeof(out
)/sizeof(out
[0]) - 1, NULL
);
1201 ok(ret
== 0, "Expected FormatMessageA to return 0, got %u\n", ret
);
1202 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
1203 "Expected GetLastError() to return ERROR_INSUFFICIENT_BUFFER, got %u\n",
1205 ok(!memcmp(expected_buf
, out
, sizeof(expected_buf
)) ||
1206 broken(!memcmp(broken2_buf
, out
, sizeof(broken2_buf
))), /* W2K3+ */
1207 "Expected the buffer to be untouched\n");
1210 static void test_message_null_buffer(void)
1214 /* Without FORMAT_MESSAGE_ALLOCATE_BUFFER, only the specified buffer size is checked. */
1215 SetLastError(0xdeadbeef);
1216 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, 0, 0, NULL
, 0, NULL
);
1217 error
= GetLastError();
1218 ok(!ret
, "FormatMessageA returned %u\n", ret
);
1219 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "last error %u\n", error
);
1221 SetLastError(0xdeadbeef);
1222 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, 0, 0, NULL
, 1, NULL
);
1223 error
= GetLastError();
1224 ok(!ret
, "FormatMessageA returned %u\n", ret
);
1225 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "last error %u\n", error
);
1227 if (0) /* crashes on Windows */
1229 SetLastError(0xdeadbeef);
1230 FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, 0, 0, NULL
, 256, NULL
);
1233 SetLastError(0xdeadbeef);
1234 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_ALLOCATE_BUFFER
, NULL
, 0, 0, NULL
, 0, NULL
);
1235 error
= GetLastError();
1236 ok(!ret
, "FormatMessageA returned %u\n", ret
);
1237 ok(error
== ERROR_NOT_ENOUGH_MEMORY
, "last error %u\n", error
);
1239 SetLastError(0xdeadbeef);
1240 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_ALLOCATE_BUFFER
, NULL
, 0, 0, NULL
, 1, NULL
);
1241 error
= GetLastError();
1242 ok(!ret
, "FormatMessageA returned %u\n", ret
);
1243 ok(error
== ERROR_NOT_ENOUGH_MEMORY
, "last error %u\n", error
);
1245 SetLastError(0xdeadbeef);
1246 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_ALLOCATE_BUFFER
, NULL
, 0, 0, NULL
, 256, NULL
);
1247 error
= GetLastError();
1248 ok(!ret
, "FormatMessageA returned %u\n", ret
);
1249 ok(error
== ERROR_NOT_ENOUGH_MEMORY
, "last error %u\n", error
);
1252 static void test_message_null_buffer_wide(void)
1256 SetLastError(0xdeadbeef);
1257 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, 0, 0, NULL
, 0, NULL
);
1258 error
= GetLastError();
1259 ok(!ret
, "FormatMessageW returned %u\n", ret
);
1260 ok(error
== ERROR_INVALID_PARAMETER
, "last error %u\n", error
);
1262 SetLastError(0xdeadbeef);
1263 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, 0, 0, NULL
, 1, NULL
);
1264 error
= GetLastError();
1265 ok(!ret
, "FormatMessageW returned %u\n", ret
);
1266 ok(error
== ERROR_INVALID_PARAMETER
, "last error %u\n", error
);
1268 SetLastError(0xdeadbeef);
1269 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, 0, 0, NULL
, 256, NULL
);
1270 error
= GetLastError();
1271 ok(!ret
, "FormatMessageW returned %u\n", ret
);
1272 ok(error
== ERROR_INVALID_PARAMETER
, "last error %u\n", error
);
1274 SetLastError(0xdeadbeef);
1275 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_ALLOCATE_BUFFER
, NULL
, 0, 0, NULL
, 0, NULL
);
1276 error
= GetLastError();
1277 ok(!ret
, "FormatMessageW returned %u\n", ret
);
1278 ok(error
== ERROR_INVALID_PARAMETER
, "last error %u\n", error
);
1280 SetLastError(0xdeadbeef);
1281 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_ALLOCATE_BUFFER
, NULL
, 0, 0, NULL
, 1, NULL
);
1282 error
= GetLastError();
1283 ok(!ret
, "FormatMessageW returned %u\n", ret
);
1284 ok(error
== ERROR_INVALID_PARAMETER
, "last error %u\n", error
);
1286 SetLastError(0xdeadbeef);
1287 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_ALLOCATE_BUFFER
, NULL
, 0, 0, NULL
, 256, NULL
);
1288 error
= GetLastError();
1289 ok(!ret
, "FormatMessageW returned %u\n", ret
);
1290 ok(error
== ERROR_INVALID_PARAMETER
, "last error %u\n", error
);
1293 static void test_message_allocate_buffer(void)
1298 /* While MSDN suggests that FormatMessageA allocates a buffer whose size is
1299 * the larger of the output string and the requested buffer size, the tests
1300 * will not try to determine the actual size of the buffer allocated, as
1301 * the return value of LocalSize cannot be trusted for the purpose, and it should
1302 * in any case be safe for FormatMessageA to allocate in the manner that
1305 SetLastError(0xdeadbeef);
1306 buf
= (char *)0xdeadbeef;
1307 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_ALLOCATE_BUFFER
,
1308 "", 0, 0, (char *)&buf
, 0, NULL
);
1309 ok(ret
== 0, "Expected FormatMessageA to return 0, got %u\n", ret
);
1310 ok(buf
== NULL
, "Expected output buffer pointer to be NULL\n");
1311 ok(GetLastError() == 0xdeadbeef,
1312 "Expected last error to be untouched, got %u\n", GetLastError());
1314 buf
= (char *)0xdeadbeef;
1315 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_ALLOCATE_BUFFER
,
1316 "test", 0, 0, (char *)&buf
, 0, NULL
);
1317 ok(ret
== 4, "Expected FormatMessageA to return 4, got %u\n", ret
);
1318 ok(buf
!= NULL
&& buf
!= (char *)0xdeadbeef,
1319 "Expected output buffer pointer to be valid\n");
1320 if (buf
!= NULL
&& buf
!= (char *)0xdeadbeef)
1322 ok(!strcmp("test", buf
),
1323 "Expected buffer to contain \"test\", got %s\n", buf
);
1327 buf
= (char *)0xdeadbeef;
1328 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_ALLOCATE_BUFFER
,
1329 "test", 0, 0, (char *)&buf
, strlen("test"), NULL
);
1330 ok(ret
== 4, "Expected FormatMessageA to return 4, got %u\n", ret
);
1331 ok(buf
!= NULL
&& buf
!= (char *)0xdeadbeef,
1332 "Expected output buffer pointer to be valid\n");
1333 if (buf
!= NULL
&& buf
!= (char *)0xdeadbeef)
1335 ok(!strcmp("test", buf
),
1336 "Expected buffer to contain \"test\", got %s\n", buf
);
1340 buf
= (char *)0xdeadbeef;
1341 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_ALLOCATE_BUFFER
,
1342 "test", 0, 0, (char *)&buf
, strlen("test") + 1, NULL
);
1343 ok(ret
== 4, "Expected FormatMessageA to return 4, got %u\n", ret
);
1344 ok(buf
!= NULL
&& buf
!= (char *)0xdeadbeef,
1345 "Expected output buffer pointer to be valid\n");
1346 if (buf
!= NULL
&& buf
!= (char *)0xdeadbeef)
1348 ok(!strcmp("test", buf
),
1349 "Expected buffer to contain \"test\", got %s\n", buf
);
1353 buf
= (char *)0xdeadbeef;
1354 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_ALLOCATE_BUFFER
,
1355 "test", 0, 0, (char *)&buf
, strlen("test") + 2, NULL
);
1356 ok(ret
== 4, "Expected FormatMessageA to return 4, got %u\n", ret
);
1357 ok(buf
!= NULL
&& buf
!= (char *)0xdeadbeef,
1358 "Expected output buffer pointer to be valid\n");
1359 if (buf
!= NULL
&& buf
!= (char *)0xdeadbeef)
1361 ok(!strcmp("test", buf
),
1362 "Expected buffer to contain \"test\", got %s\n", buf
);
1366 buf
= (char *)0xdeadbeef;
1367 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_ALLOCATE_BUFFER
,
1368 "test", 0, 0, (char *)&buf
, 1024, NULL
);
1369 ok(ret
== 4, "Expected FormatMessageA to return 4, got %u\n", ret
);
1370 ok(buf
!= NULL
&& buf
!= (char *)0xdeadbeef,
1371 "Expected output buffer pointer to be valid\n");
1372 if (buf
!= NULL
&& buf
!= (char *)0xdeadbeef)
1374 ok(!strcmp("test", buf
),
1375 "Expected buffer to contain \"test\", got %s\n", buf
);
1380 static void test_message_allocate_buffer_wide(void)
1382 static const WCHAR empty
[] = {0};
1383 static const WCHAR test
[] = {'t','e','s','t',0};
1388 /* While MSDN suggests that FormatMessageW allocates a buffer whose size is
1389 * the larger of the output string and the requested buffer size, the tests
1390 * will not try to determine the actual size of the buffer allocated, as
1391 * the return value of LocalSize cannot be trusted for the purpose, and it should
1392 * in any case be safe for FormatMessageW to allocate in the manner that
1395 if (0) /* crashes on Windows */
1397 buf
= (WCHAR
*)0xdeadbeef;
1398 FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_ALLOCATE_BUFFER
,
1399 NULL
, 0, 0, (WCHAR
*)&buf
, 0, NULL
);
1402 SetLastError(0xdeadbeef);
1403 buf
= (WCHAR
*)0xdeadbeef;
1404 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_ALLOCATE_BUFFER
,
1405 empty
, 0, 0, (WCHAR
*)&buf
, 0, NULL
);
1406 ok(ret
== 0, "Expected FormatMessageW to return 0, got %u\n", ret
);
1407 ok(buf
== NULL
, "Expected output buffer pointer to be NULL\n");
1408 ok(GetLastError() == 0xdeadbeef,
1409 "Expected last error to be untouched, got %u\n", GetLastError());
1411 buf
= (WCHAR
*)0xdeadbeef;
1412 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_ALLOCATE_BUFFER
,
1413 test
, 0, 0, (WCHAR
*)&buf
, 0, NULL
);
1414 ok(ret
== 4, "Expected FormatMessageA to return 4, got %u\n", ret
);
1415 ok(buf
!= NULL
&& buf
!= (WCHAR
*)0xdeadbeef,
1416 "Expected output buffer pointer to be valid\n");
1417 if (buf
!= NULL
&& buf
!= (WCHAR
*)0xdeadbeef)
1419 ok(!lstrcmpW(test
, buf
),
1420 "Expected buffer to contain \"test\", got %s\n", wine_dbgstr_w(buf
));
1424 buf
= (WCHAR
*)0xdeadbeef;
1425 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_ALLOCATE_BUFFER
,
1426 test
, 0, 0, (WCHAR
*)&buf
, sizeof(test
)/sizeof(WCHAR
) - 1, NULL
);
1427 ok(ret
== 4, "Expected FormatMessageA to return 4, got %u\n", ret
);
1428 ok(buf
!= NULL
&& buf
!= (WCHAR
*)0xdeadbeef,
1429 "Expected output buffer pointer to be valid\n");
1430 if (buf
!= NULL
&& buf
!= (WCHAR
*)0xdeadbeef)
1432 ok(!lstrcmpW(test
, buf
),
1433 "Expected buffer to contain \"test\", got %s\n", wine_dbgstr_w(buf
));
1437 buf
= (WCHAR
*)0xdeadbeef;
1438 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_ALLOCATE_BUFFER
,
1439 test
, 0, 0, (WCHAR
*)&buf
, sizeof(test
)/sizeof(WCHAR
), NULL
);
1440 ok(ret
== 4, "Expected FormatMessageA to return 4, got %u\n", ret
);
1441 ok(buf
!= NULL
&& buf
!= (WCHAR
*)0xdeadbeef,
1442 "Expected output buffer pointer to be valid\n");
1443 if (buf
!= NULL
&& buf
!= (WCHAR
*)0xdeadbeef)
1445 ok(!lstrcmpW(test
, buf
),
1446 "Expected buffer to contain \"test\", got %s\n", wine_dbgstr_w(buf
));
1450 buf
= (WCHAR
*)0xdeadbeef;
1451 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_ALLOCATE_BUFFER
,
1452 test
, 0, 0, (WCHAR
*)&buf
, sizeof(test
)/sizeof(WCHAR
) + 1, NULL
);
1453 ok(ret
== 4, "Expected FormatMessageA to return 4, got %u\n", ret
);
1454 ok(buf
!= NULL
&& buf
!= (WCHAR
*)0xdeadbeef,
1455 "Expected output buffer pointer to be valid\n");
1456 if (buf
!= NULL
&& buf
!= (WCHAR
*)0xdeadbeef)
1458 ok(!lstrcmpW(test
, buf
),
1459 "Expected buffer to contain \"test\", got %s\n", wine_dbgstr_w(buf
));
1463 buf
= (WCHAR
*)0xdeadbeef;
1464 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_ALLOCATE_BUFFER
,
1465 test
, 0, 0, (WCHAR
*)&buf
, 1024, NULL
);
1466 ok(ret
== 4, "Expected FormatMessageA to return 4, got %u\n", ret
);
1467 ok(buf
!= NULL
&& buf
!= (WCHAR
*)0xdeadbeef,
1468 "Expected output buffer pointer to be valid\n");
1469 if (buf
!= NULL
&& buf
!= (WCHAR
*)0xdeadbeef)
1471 ok(!lstrcmpW(test
, buf
),
1472 "Expected buffer to contain \"test\", got %s\n", wine_dbgstr_w(buf
));
1477 static void test_message_from_hmodule(void)
1481 CHAR out
[0x100] = {0};
1483 h
= GetModuleHandle("kernel32.dll");
1484 ok(h
!= 0, "GetModuleHandle failed\n");
1486 /*Test existing messageID; as the message strings from wine's kernel32 differ from windows' kernel32 we don't compare
1487 the strings but only test that FormatMessage doesn't return 0*/
1488 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_FROM_HMODULE
, h
, 7/*=ERROR_ARENA_TRASHED*/,
1489 MAKELANGID(LANG_NEUTRAL
, SUBLANG_NEUTRAL
), out
, sizeof(out
)/sizeof(CHAR
), NULL
);
1490 ok(ret
!= 0, "FormatMessageA returned 0\n");
1492 /* Test a message string with an insertion without passing any variadic arguments. */
1493 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_FROM_HMODULE
, h
, 193 /* ERROR_BAD_EXE_FORMAT */,
1494 MAKELANGID(LANG_NEUTRAL
, SUBLANG_NEUTRAL
), out
, sizeof(out
)/sizeof(CHAR
), NULL
);
1495 ok(ret
== 0, "FormatMessageA returned non-zero\n");
1497 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_FROM_HMODULE
|
1498 FORMAT_MESSAGE_ARGUMENT_ARRAY
, h
, 193 /* ERROR_BAD_EXE_FORMAT */,
1499 MAKELANGID(LANG_NEUTRAL
, SUBLANG_NEUTRAL
), out
, sizeof(out
)/sizeof(CHAR
), NULL
);
1500 ok(ret
== 0, "FormatMessageA returned non-zero\n");
1502 /*Test nonexistent messageID with varying language IDs Note: FormatMessageW behaves the same*/
1503 SetLastError(0xdeadbeef);
1504 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_FROM_HMODULE
, h
, 3044,
1505 MAKELANGID(LANG_NEUTRAL
, SUBLANG_NEUTRAL
), out
, sizeof(out
)/sizeof(CHAR
), NULL
);
1506 error
= GetLastError();
1507 ok(ret
== 0, "FormatMessageA returned %u instead of 0\n", ret
);
1508 ok(error
== ERROR_MR_MID_NOT_FOUND
|| error
== ERROR_MUI_FILE_NOT_FOUND
, "last error %u\n", error
);
1510 SetLastError(0xdeadbeef);
1511 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_FROM_HMODULE
, h
, 3044,
1512 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), out
, sizeof(out
)/sizeof(CHAR
), NULL
);
1513 error
= GetLastError();
1514 ok(ret
== 0, "FormatMessageA returned %u instead of 0\n", ret
);
1515 ok(error
== ERROR_MR_MID_NOT_FOUND
|| error
== ERROR_MUI_FILE_NOT_LOADED
, "last error %u\n", error
);
1517 SetLastError(0xdeadbeef);
1518 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_FROM_HMODULE
, h
, 3044,
1519 MAKELANGID(LANG_NEUTRAL
, SUBLANG_SYS_DEFAULT
), out
, sizeof(out
)/sizeof(CHAR
), NULL
);
1520 error
= GetLastError();
1521 ok(ret
== 0, "FormatMessageA returned %u instead of 0\n", ret
);
1522 ok(error
== ERROR_MR_MID_NOT_FOUND
|| error
== ERROR_MUI_FILE_NOT_LOADED
, "last error %u\n", error
);
1524 SetLastError(0xdeadbeef);
1525 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_FROM_HMODULE
, h
, 3044,
1526 MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_US
), out
, sizeof(out
)/sizeof(CHAR
), NULL
);
1527 error
= GetLastError();
1528 ok(ret
== 0, "FormatMessageA returned %u instead of 0\n", ret
);
1529 ok(error
== ERROR_RESOURCE_LANG_NOT_FOUND
||
1530 error
== ERROR_MR_MID_NOT_FOUND
||
1531 error
== ERROR_MUI_FILE_NOT_FOUND
||
1532 error
== ERROR_MUI_FILE_NOT_LOADED
,
1533 "last error %u\n", error
);
1535 SetLastError(0xdeadbeef);
1536 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_FROM_HMODULE
, h
, 3044,
1537 MAKELANGID(LANG_ENGLISH
, SUBLANG_ENGLISH_UK
), out
, sizeof(out
)/sizeof(CHAR
), NULL
);
1538 error
= GetLastError();
1539 ok(ret
== 0, "FormatMessageA returned %u instead of 0\n", ret
);
1540 ok(error
== ERROR_RESOURCE_LANG_NOT_FOUND
||
1541 error
== ERROR_MR_MID_NOT_FOUND
||
1542 error
== ERROR_MUI_FILE_NOT_FOUND
||
1543 error
== ERROR_MUI_FILE_NOT_LOADED
,
1544 "last error %u\n", error
);
1547 static void test_message_invalid_flags(void)
1549 static const char init_buf
[] = {'x', 'x', 'x', 'x', 'x'};
1555 SetLastError(0xdeadbeef);
1556 memcpy(out
, init_buf
, sizeof(init_buf
));
1557 ret
= FormatMessageA(0, "test", 0, 0, out
, sizeof(out
)/sizeof(CHAR
), NULL
);
1558 ok(ret
== 0, "Expected FormatMessageA to return 0, got %u\n", ret
);
1559 ok(!memcmp(out
, init_buf
, sizeof(init_buf
)),
1560 "Expected the output buffer to be untouched\n");
1561 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
1562 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
1565 SetLastError(0xdeadbeef);
1566 ptr
= (char *)0xdeadbeef;
1567 ret
= FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER
, "test", 0, 0, (char *)&ptr
, 0, NULL
);
1568 ok(ret
== 0, "Expected FormatMessageA to return 0, got %u\n", ret
);
1569 ok(ptr
== NULL
, "Expected output pointer to be initialized to NULL, got %p\n", ptr
);
1570 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
1571 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
1574 SetLastError(0xdeadbeef);
1575 memcpy(out
, init_buf
, sizeof(init_buf
));
1576 ret
= FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS
, "test", 0, 0, out
, sizeof(out
)/sizeof(CHAR
), NULL
);
1577 ok(ret
== 0, "Expected FormatMessageA to return 0, got %u\n", ret
);
1578 ok(!memcmp(out
, init_buf
, sizeof(init_buf
)),
1579 "Expected the output buffer to be untouched\n");
1580 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
1581 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
1584 SetLastError(0xdeadbeef);
1585 memcpy(out
, init_buf
, sizeof(init_buf
));
1586 ret
= FormatMessageA(FORMAT_MESSAGE_ARGUMENT_ARRAY
, "test", 0, 0, out
, sizeof(out
)/sizeof(CHAR
), NULL
);
1587 ok(ret
== 0, "Expected FormatMessageA to return 0, got %u\n", ret
);
1588 ok(!memcmp(out
, init_buf
, sizeof(init_buf
)),
1589 "Expected the output buffer to be untouched\n");
1590 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
1591 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
1594 SetLastError(0xdeadbeef);
1595 memcpy(out
, init_buf
, sizeof(init_buf
));
1596 ret
= FormatMessageA(FORMAT_MESSAGE_MAX_WIDTH_MASK
, "test", 0, 0, out
, sizeof(out
)/sizeof(CHAR
), NULL
);
1597 ok(ret
== 0, "Expected FormatMessageA to return 0, got %u\n", ret
);
1598 ok(!memcmp(out
, init_buf
, sizeof(init_buf
)),
1599 "Expected the output buffer to be untouched\n");
1600 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
1601 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
1604 /* Simultaneously setting FORMAT_MESSAGE_FROM_STRING with other source
1605 * flags is apparently permissible, and FORMAT_MESSAGE_FROM_STRING takes
1606 * precedence in this case. */
1608 memcpy(out
, init_buf
, sizeof(init_buf
));
1609 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_FROM_SYSTEM
,
1610 "test", 0, 0, out
, sizeof(out
)/sizeof(CHAR
), NULL
);
1611 ok(ret
== 4, "Expected FormatMessageA to return 4, got %u\n", ret
);
1612 ok(!strcmp("test", out
),
1613 "Expected the output buffer to be untouched\n");
1615 memcpy(out
, init_buf
, sizeof(init_buf
));
1616 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_FROM_HMODULE
,
1617 "test", 0, 0, out
, sizeof(out
)/sizeof(CHAR
), NULL
);
1618 ok(ret
== 4, "Expected FormatMessageA to return 4, got %u\n", ret
);
1619 ok(!strcmp("test", out
),
1620 "Expected the output buffer to be untouched\n");
1622 memcpy(out
, init_buf
, sizeof(init_buf
));
1623 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_FROM_HMODULE
|
1624 FORMAT_MESSAGE_FROM_SYSTEM
, "test", 0, 0, out
,
1625 sizeof(out
)/sizeof(CHAR
), NULL
);
1626 ok(ret
== 4, "Expected FormatMessageA to return 4, got %u\n", ret
);
1627 ok(!strcmp("test", out
),
1628 "Expected the output buffer to be untouched\n");
1631 static void test_message_invalid_flags_wide(void)
1633 static const WCHAR init_buf
[] = {'x', 'x', 'x', 'x', 'x'};
1634 static const WCHAR test
[] = {'t','e','s','t',0};
1640 SetLastError(0xdeadbeef);
1641 memcpy(out
, init_buf
, sizeof(init_buf
));
1642 ret
= FormatMessageW(0, test
, 0, 0, out
, sizeof(out
)/sizeof(WCHAR
), NULL
);
1643 ok(ret
== 0, "Expected FormatMessageW to return 0, got %u\n", ret
);
1644 ok(!memcmp(out
, init_buf
, sizeof(init_buf
)),
1645 "Expected the output buffer to be untouched\n");
1646 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
1647 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
1650 SetLastError(0xdeadbeef);
1651 ptr
= (WCHAR
*)0xdeadbeef;
1652 ret
= FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
, test
, 0, 0, (WCHAR
*)&ptr
, 0, NULL
);
1653 ok(ret
== 0, "Expected FormatMessageW to return 0, got %u\n", ret
);
1654 ok(ptr
== NULL
, "Expected output pointer to be initialized to NULL, got %p\n", ptr
);
1655 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
1656 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
1659 SetLastError(0xdeadbeef);
1660 memcpy(out
, init_buf
, sizeof(init_buf
));
1661 ret
= FormatMessageW(FORMAT_MESSAGE_IGNORE_INSERTS
, test
, 0, 0, out
, sizeof(out
)/sizeof(WCHAR
), NULL
);
1662 ok(ret
== 0, "Expected FormatMessageW to return 0, got %u\n", ret
);
1663 ok(!memcmp(out
, init_buf
, sizeof(init_buf
)),
1664 "Expected the output buffer to be untouched\n");
1665 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
1666 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
1669 SetLastError(0xdeadbeef);
1670 memcpy(out
, init_buf
, sizeof(init_buf
));
1671 ret
= FormatMessageW(FORMAT_MESSAGE_ARGUMENT_ARRAY
, test
, 0, 0, out
, sizeof(out
)/sizeof(WCHAR
), NULL
);
1672 ok(ret
== 0, "Expected FormatMessageW to return 0, got %u\n", ret
);
1673 ok(!memcmp(out
, init_buf
, sizeof(init_buf
)),
1674 "Expected the output buffer to be untouched\n");
1675 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
1676 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
1679 SetLastError(0xdeadbeef);
1680 memcpy(out
, init_buf
, sizeof(init_buf
));
1681 ret
= FormatMessageW(FORMAT_MESSAGE_MAX_WIDTH_MASK
, test
, 0, 0, out
, sizeof(out
)/sizeof(WCHAR
), NULL
);
1682 ok(ret
== 0, "Expected FormatMessageW to return 0, got %u\n", ret
);
1683 ok(!memcmp(out
, init_buf
, sizeof(init_buf
)),
1684 "Expected the output buffer to be untouched\n");
1685 ok(GetLastError() == ERROR_INVALID_PARAMETER
,
1686 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
1689 /* Simultaneously setting FORMAT_MESSAGE_FROM_STRING with other source
1690 * flags is apparently permissible, and FORMAT_MESSAGE_FROM_STRING takes
1691 * precedence in this case. */
1693 memcpy(out
, init_buf
, sizeof(init_buf
));
1694 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_FROM_SYSTEM
,
1695 test
, 0, 0, out
, sizeof(out
)/sizeof(WCHAR
), NULL
);
1696 ok(ret
== 4, "Expected FormatMessageW to return 4, got %u\n", ret
);
1697 ok(!lstrcmpW(test
, out
),
1698 "Expected the output buffer to be untouched\n");
1700 memcpy(out
, init_buf
, sizeof(init_buf
));
1701 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_FROM_HMODULE
,
1702 test
, 0, 0, out
, sizeof(out
)/sizeof(WCHAR
), NULL
);
1703 ok(ret
== 4, "Expected FormatMessageW to return 4, got %u\n", ret
);
1704 ok(!lstrcmpW(test
, out
),
1705 "Expected the output buffer to be untouched\n");
1707 memcpy(out
, init_buf
, sizeof(init_buf
));
1708 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_FROM_HMODULE
|
1709 FORMAT_MESSAGE_FROM_SYSTEM
, test
, 0, 0, out
,
1710 sizeof(out
)/sizeof(WCHAR
), NULL
);
1711 ok(ret
== 4, "Expected FormatMessageW to return 4, got %u\n", ret
);
1712 ok(!lstrcmpW(test
, out
),
1713 "Expected the output buffer to be untouched\n");
1716 START_TEST(format_msg
)
1720 test_message_from_string();
1721 test_message_ignore_inserts();
1722 test_message_wrap();
1723 test_message_insufficient_buffer();
1724 test_message_null_buffer();
1725 test_message_allocate_buffer();
1726 test_message_from_hmodule();
1727 test_message_invalid_flags();
1729 SetLastError(0xdeadbeef);
1730 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
, NULL
, 0, 0, NULL
, 0, NULL
);
1731 if (!ret
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1733 win_skip("FormatMessageW is not implemented\n");
1737 test_message_from_string_wide();
1738 test_message_ignore_inserts_wide();
1739 test_message_insufficient_buffer_wide();
1740 test_message_null_buffer_wide();
1741 test_message_allocate_buffer_wide();
1742 test_message_invalid_flags_wide();