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};
129 static const WCHAR init_buf[] = {'x', 'x', 'x', 'x', 'x', 'x'};
130 static const WCHAR broken_buf[] = {'t','e','s','t','x','x'};
132 WCHAR out[0x100] = {0};
136 r = FormatMessageW(FORMAT_MESSAGE_FROM_STRING, test, 0,
137 0, out, sizeof(out)/sizeof(WCHAR), NULL);
138 ok(!lstrcmpW(test, out), "failed out=%s\n", wine_dbgstr_w(out));
139 ok(r==4, "failed: r=%d\n", r);
141 /* null string, crashes on Windows */
144 SetLastError(0xdeadbeef);
145 memcpy(out, init_buf, sizeof(init_buf));
146 FormatMessageW(FORMAT_MESSAGE_FROM_STRING, NULL, 0,
147 0, out, sizeof(out)/sizeof(WCHAR), NULL);
151 SetLastError(0xdeadbeef);
152 memcpy(out, init_buf, sizeof(init_buf));
153 r = FormatMessageW(FORMAT_MESSAGE_FROM_STRING, empty, 0,
154 0, out, sizeof(out)/sizeof(WCHAR), NULL);
155 error = GetLastError();
156 ok(!lstrcmpW(empty, out), "failed out=%s\n", wine_dbgstr_w(out));
157 ok(r==0, "succeeded: r=%d\n", r);
158 ok(error==0xdeadbeef, "last error %u\n", error);
160 /* format placeholder with no specifier */
161 SetLastError(0xdeadbeef);
162 memcpy(out, init_buf, sizeof(init_buf));
163 r = FormatMessageW(FORMAT_MESSAGE_FROM_STRING, fmt_null, 0,
164 0, out, sizeof(out)/sizeof(WCHAR), NULL);
165 error = GetLastError();
166 ok(!memcmp(out, init_buf, sizeof(init_buf)),
167 "Expected the buffer to be unchanged\n");
168 ok(r==0, "succeeded: r=%d\n", r);
169 ok(error==ERROR_INVALID_PARAMETER, "last error %u\n", error);
171 /* test string with format placeholder with no specifier */
172 SetLastError(0xdeadbeef);
173 memcpy(out, init_buf, sizeof(init_buf));
174 r = FormatMessageW(FORMAT_MESSAGE_FROM_STRING, fmt_tnull, 0,
175 0, out, sizeof(out)/sizeof(WCHAR), NULL);
176 error = GetLastError();
177 ok(!memcmp(out, init_buf, sizeof(init_buf)) ||
178 broken(!memcmp(out, broken_buf, sizeof(broken_buf))), /* W2K3+ */
179 "Expected the buffer to be unchanged\n");
180 ok(r==0, "succeeded: r=%d\n", r);
181 ok(error==ERROR_INVALID_PARAMETER, "last error %u\n", error);
183 /* insertion with no variadic arguments */
184 SetLastError(0xdeadbeef);
185 memcpy(out, init_buf, sizeof(init_buf));
186 r = FormatMessageW(FORMAT_MESSAGE_FROM_STRING, fmt_1, 0,
187 0, out, sizeof(out)/sizeof(WCHAR), NULL);
188 error = GetLastError();
189 ok(!memcmp(out, init_buf, sizeof(init_buf)),
190 "Expected the buffer to be unchanged\n");
191 ok(r==0, "succeeded: r=%d\n", r);
192 ok(error==ERROR_INVALID_PARAMETER, "last error %u\n", error);
194 SetLastError(0xdeadbeef);
195 memcpy(out, init_buf, sizeof(init_buf));
196 r = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, fmt_1, 0,
197 0, out, sizeof(out)/sizeof(WCHAR), NULL);
198 error = GetLastError();
199 ok(!memcmp(out, init_buf, sizeof(init_buf)),
200 "Expected the buffer to be unchanged\n");
201 ok(r==0, "succeeded: r=%d\n", r);
202 ok(error==ERROR_INVALID_PARAMETER, "last error %u\n", error);
204 /* using the format feature */
205 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_1s, 0,
206 0, out, sizeof(out)/sizeof(WCHAR), test);
207 ok(!lstrcmpW(test, out), "failed out=%s\n", wine_dbgstr_w(out));
208 ok(r==4,"failed: r=%d\n", r);
211 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_1, 0,
212 0, out, sizeof(out)/sizeof(WCHAR), test);
213 ok(!lstrcmpW(test, out), "failed out=%s\n", wine_dbgstr_w(out));
214 ok(r==4,"failed: r=%d\n", r);
217 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_12, 0,
218 0, out, sizeof(out)/sizeof(WCHAR), te, st);
219 ok(!lstrcmpW(test, out), "failed out=%s\n", wine_dbgstr_w(out));
220 ok(r==4,"failed: r=%d\n", r);
223 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_123, 0,
224 0, out, sizeof(out)/sizeof(WCHAR), t, s, e);
225 ok(!lstrcmpW(test, out), "failed out=%s\n", wine_dbgstr_w(out));
226 ok(r==4,"failed: r=%d\n", r);
228 /* s doesn't seem to work in format strings */
229 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_s, 0,
230 0, out, sizeof(out)/sizeof(WCHAR), test);
231 ok(!lstrcmpW(&fmt_s[1], out), "failed out=%s\n", wine_dbgstr_w(out));
232 ok(r==3, "failed: r=%d\n", r);
235 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_ls, 0,
236 0, out, sizeof(out)/sizeof(WCHAR), test);
237 ok(!lstrcmpW(&fmt_ls[1], out), "failed out=%s\n", wine_dbgstr_w(out));
238 ok(r==4, "failed: r=%d\n", r);
241 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_S, 0,
242 0, out, sizeof(out)/sizeof(WCHAR), test);
243 ok(!lstrcmpW(&fmt_S[1], out), "failed out=%s\n", wine_dbgstr_w(out));
244 ok(r==3, "failed: r=%d\n", r);
247 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_ws, 0,
248 0, out, sizeof(out)/sizeof(WCHAR), test);
249 ok(!lstrcmpW(&fmt_ws[1], out), "failed out=%s\n", wine_dbgstr_w(out));
250 ok(r==4, "failed: r=%d\n", r);
253 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_123c, 0,
254 0, out, sizeof(out)/sizeof(WCHAR), 't', 'e', 's');
255 ok(!lstrcmpW(test, out), "failed out=%s\n", wine_dbgstr_w(out));
256 ok(r==4,"failed: r=%d\n", r);
259 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_123lc, 0,
260 0, out, sizeof(out)/sizeof(WCHAR), 't', 'e', 's');
261 ok(!lstrcmpW(test, out), "failed out=%s\n", wine_dbgstr_w(out));
262 ok(r==4,"failed: r=%d\n", r);
265 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_123wc, 0,
266 0, out, sizeof(out)/sizeof(WCHAR), 't', 'e', 's');
267 ok(!lstrcmpW(test, out), "failed out=%s\n", wine_dbgstr_w(out));
268 ok(r==4,"failed: r=%d\n", r);
271 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_123C, 0,
272 0, out, sizeof(out)/sizeof(WCHAR), 't', 'e', 's');
273 ok(!lstrcmpW(test, out), "failed out=%s\n", wine_dbgstr_w(out));
274 ok(r==4,"failed: r=%d\n", r);
277 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_123d, 0,
278 0, out, sizeof(out)/sizeof(WCHAR), 1, 2, 3);
279 ok(!lstrcmpW(s_123d, out), "failed out=%s\n", wine_dbgstr_w(out));
280 ok(r==3,"failed: r=%d\n", r);
282 /* a single digit with some spacing */
283 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_14d, 0,
284 0, out, sizeof(out)/sizeof(WCHAR), 1);
285 ok(!lstrcmpW(s_14d, out), "failed out=%s\n", wine_dbgstr_w(out));
286 ok(r==4,"failed: r=%d\n", r);
288 /* a single digit, left justified */
289 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_1_4d, 0,
290 0, out, sizeof(out)/sizeof(CHAR), 1);
291 ok(!lstrcmpW(s_1_4d, out), "failed out=%s\n", wine_dbgstr_w(out));
292 ok(r==4,"failed: r=%d\n", r);
294 /* two digit decimal number */
295 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_14d, 0,
296 0, out, sizeof(out)/sizeof(WCHAR), 11);
297 ok(!lstrcmpW(s_14d2, out), "failed out=%s\n", wine_dbgstr_w(out));
298 ok(r==4,"failed: r=%d\n", r);
301 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_14x, 0,
302 0, out, sizeof(out)/sizeof(WCHAR), 11);
303 ok(!lstrcmpW(s_14x, out), "failed out=%s\n", wine_dbgstr_w(out));
304 ok(r==4,"failed: r=%d\n", r);
306 /* a hex number, upper case */
307 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_14X, 0,
308 0, out, sizeof(out)/sizeof(WCHAR), 11);
309 ok(!lstrcmpW(s_14X, out), "failed out=%s\n", wine_dbgstr_w(out));
310 ok(r==4,"failed: r=%d\n", r);
312 /* a hex number, upper case, left justified */
313 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_1_4X, 0,
314 0, out, sizeof(out)/sizeof(WCHAR), 11);
315 ok(!lstrcmpW(s_1_4X, out), "failed out=%s\n", wine_dbgstr_w(out));
316 ok(r==4,"failed: r=%d\n", r);
318 /* a long hex number, upper case */
319 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_14X, 0,
320 0, out, sizeof(out)/sizeof(WCHAR), 0x1ab);
321 ok(!lstrcmpW(s_1AB, out), "failed out=%s\n", wine_dbgstr_w(out));
322 ok(r==4,"failed: r=%d\n", r);
325 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_2pct, 0,
326 0, out, sizeof(out)/sizeof(WCHAR));
327 ok(!lstrcmpW(s_2pct, out), "failed out=%s\n", wine_dbgstr_w(out));
328 ok(r==4,"failed: r=%d\n", r);
330 /* periods are special cases */
331 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_2dot1d, 0,
332 0, out, sizeof(out)/sizeof(WCHAR), 0x1ab);
333 ok(!lstrcmpW(s_2dot147, out), "failed out=%s\n", wine_dbgstr_w(out));
334 ok(r==8,"failed: r=%d\n", r);
336 /* %0 ends the line */
337 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_t0t, 0,
338 0, out, sizeof(out)/sizeof(WCHAR));
339 ok(!lstrcmpW(test, out), "failed out=%s\n", wine_dbgstr_w(out));
340 ok(r==4,"failed: r=%d\n", r);
342 /* %! prints an exclamation */
343 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_yah, 0,
344 0, out, sizeof(out)/sizeof(WCHAR));
345 ok(!lstrcmpW(s_yah, out), "failed out=%s\n", wine_dbgstr_w(out));
346 ok(r==4,"failed: r=%d\n", r);
349 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_space, 0,
350 0, out, sizeof(out)/sizeof(WCHAR));
351 ok(!lstrcmpW(s_space, out), "failed out=%s\n", wine_dbgstr_w(out));
352 ok(r==4,"failed: r=%d\n", r);
354 /* %n yields \r\n, %r yields \r, %t yields \t */
355 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_nrt, 0,
356 0, out, sizeof(out)/sizeof(WCHAR));
357 ok(!lstrcmpW(s_nrt, out), "failed out=%s\n", wine_dbgstr_w(out));
358 ok(r==4,"failed: r=%d\n", r);
361 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_hi_lf, 0,
362 0, out, sizeof(out)/sizeof(WCHAR));
363 ok(!lstrcmpW(s_hi_crlf, out), "failed out=%s\n", wine_dbgstr_w(out));
364 ok(r==4,"failed: r=%d\n", r);
366 /* carriage return line feed */
367 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_hi_crlf, 0,
368 0, out, sizeof(out)/sizeof(WCHAR));
369 ok(!lstrcmpW(s_hi_crlf, out), "failed out=%s\n", wine_dbgstr_w(out));
370 ok(r==4,"failed: r=%d\n", r);
372 /* carriage return */
373 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_cr, 0,
374 0, out, sizeof(out)/sizeof(WCHAR));
375 ok(!lstrcmpW(s_crlf, out), "failed out=%s\n", wine_dbgstr_w(out));
376 ok(r==2,"failed: r=%d\n", r);
378 /* double carriage return line feed */
379 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_crcrlf, 0,
380 0, out, sizeof(out)/sizeof(WCHAR));
381 ok(!lstrcmpW(s_crlfcrlf, out), "failed out=%s\n", wine_dbgstr_w(out));
382 ok(r==4,"failed: r=%d\n", r);
384 /* precision and width */
386 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_13s,
387 0, 0, out, sizeof(out)/sizeof(WCHAR), t );
388 ok(!lstrcmpW(s_spt, out),"failed out=[%s]\n", wine_dbgstr_w(out));
389 ok(r==3, "failed: r=%d\n",r);
390 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_1os,
391 0, 0, out, sizeof(out)/sizeof(WCHAR), 4, t );
392 ok(!lstrcmpW( s_sp3t, out),"failed out=[%s]\n", wine_dbgstr_w(out));
393 ok(r==4,"failed: r=%d\n",r);
394 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_142u,
395 0, 0, out, sizeof(out)/sizeof(WCHAR), 3 );
396 ok(!lstrcmpW( s_sp03, out),"failed out=[%s]\n", wine_dbgstr_w(out));
397 ok(r==4,"failed: r=%d\n",r);
398 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_1oou,
399 0, 0, out, sizeof(out)/sizeof(WCHAR), 5, 3, 1 );
400 ok(!lstrcmpW( s_sp001, out),"failed out=[%s]\n", wine_dbgstr_w(out));
401 ok(r==5,"failed: r=%d\n",r);
402 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_1oou1oou,
403 0, 0, out, sizeof(out)/sizeof(WCHAR), 5, 3, 1, 4, 2 );
404 ok(!lstrcmpW( s_sp001002, out),"failed out=[%s]\n", wine_dbgstr_w(out));
405 ok(r==11,"failed: r=%d\n",r);
406 r = doitW(FORMAT_MESSAGE_FROM_STRING, fmt_1oou3oou,
407 0, 0, out, sizeof(out)/sizeof(WCHAR), 5, 3, 1, 6, 4, 2 );
408 ok(!lstrcmpW( s_sp001sp002, out) ||
409 broken(!lstrcmpW(s_sp001004, out)), /* NT4/Win2k */
410 "failed out=[%s]\n", wine_dbgstr_w(out));
411 ok(r==12,"failed: r=%d\n",r);
412 /* args are not counted the same way with an argument array */
414 ULONG_PTR args[] = { 6, 4, 2, 5, 3, 1 };
415 r = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, fmt_1oou1oou,
416 0, 0, out, sizeof(out)/sizeof(WCHAR), (__ms_va_list *)args );
417 ok(!lstrcmpW(s_sp002sp003, out),"failed out=[%s]\n", wine_dbgstr_w(out));
418 ok(r==13,"failed: r=%d\n",r);
419 r = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, fmt_1oou4oou,
420 0, 0, out, sizeof(out)/sizeof(WCHAR), (__ms_va_list *)args );
421 ok(!lstrcmpW(s_sp002sp001, out),"failed out=[%s]\n", wine_dbgstr_w(out));
422 ok(r==12,"failed: r=%d\n",r);
425 /* change of pace... test the low byte of dwflags */
428 r = doitW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_MAX_WIDTH_MASK, fmt_hi_lf, 0,
429 0, out, sizeof(out)/sizeof(WCHAR));
430 ok(!lstrcmpW(s_hi_sp, out), "failed out=%s\n", wine_dbgstr_w(out));
431 ok(r==3,"failed: r=%d\n", r);
433 /* carriage return line feed */
434 r = doitW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_MAX_WIDTH_MASK, fmt_hi_crlf, 0,
435 0, out, sizeof(out)/sizeof(WCHAR));
436 ok(!lstrcmpW(s_hi_sp, out), "failed out=%s\n", wine_dbgstr_w(out));
437 ok(r==3,"failed: r=%d\n", r);
439 /* carriage return */
440 r = doitW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_MAX_WIDTH_MASK, fmt_cr, 0,
441 0, out, sizeof(out)/sizeof(WCHAR));
442 ok(!lstrcmpW(s_sp, out), "failed out=%s\n", wine_dbgstr_w(out));
443 ok(r==1,"failed: r=%d\n", r);
445 /* double carriage return line feed */
446 r = doitW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_MAX_WIDTH_MASK, fmt_crcrlf, 0,
447 0, out, sizeof(out)/sizeof(WCHAR));
448 ok(!lstrcmpW(s_2sp, out), "failed out=%s\n", wine_dbgstr_w(out));
449 ok(r==2,"failed: r=%d\n", r);
452 static void test_message_from_string(void)
454 CHAR out[0x100] = {0};
456 static const char init_buf[] = {'x', 'x', 'x', 'x', 'x', 'x'};
457 static const WCHAR szwTest[] = { 't','e','s','t',0};
460 r = FormatMessageA(FORMAT_MESSAGE_FROM_STRING, "test", 0,
461 0, out, sizeof(out)/sizeof(CHAR),NULL);
462 ok(!strcmp("test", out),"failed out=[%s]\n",out);
463 ok(r==4,"failed: r=%d\n",r);
465 /* null string, crashes on Windows */
468 SetLastError(0xdeadbeef);
469 memcpy(out, init_buf, sizeof(init_buf));
470 FormatMessageA(FORMAT_MESSAGE_FROM_STRING, NULL, 0,
471 0, out, sizeof(out)/sizeof(CHAR), NULL);
475 SetLastError(0xdeadbeef);
476 memcpy(out, init_buf, sizeof(init_buf));
477 r = FormatMessageA(FORMAT_MESSAGE_FROM_STRING, "", 0,
478 0, out, sizeof(out)/sizeof(CHAR), NULL);
479 ok(!memcmp(out, init_buf, sizeof(init_buf)), "Expected the buffer to be untouched\n");
480 ok(r==0, "succeeded: r=%d\n", r);
481 ok(GetLastError()==0xdeadbeef,
482 "last error %u\n", GetLastError());
484 /* format placeholder with no specifier */
485 SetLastError(0xdeadbeef);
486 memcpy(out, init_buf, sizeof(init_buf));
487 r = FormatMessageA(FORMAT_MESSAGE_FROM_STRING, "%", 0,
488 0, out, sizeof(out)/sizeof(CHAR), NULL);
489 ok(!memcmp(out, init_buf, sizeof(init_buf)),
490 "Expected the buffer to be untouched\n");
491 ok(r==0, "succeeded: r=%d\n", r);
492 ok(GetLastError()==ERROR_INVALID_PARAMETER,
493 "last error %u\n", GetLastError());
495 /* test string with format placeholder with no specifier */
496 SetLastError(0xdeadbeef);
497 memcpy(out, init_buf, sizeof(init_buf));
498 r = FormatMessageA(FORMAT_MESSAGE_FROM_STRING, "test%", 0,
499 0, out, sizeof(out)/sizeof(CHAR), NULL);
500 ok(!memcmp(out, init_buf, sizeof(init_buf)),
501 "Expected the buffer to be untouched\n");
502 ok(r==0, "succeeded: r=%d\n", r);
503 ok(GetLastError()==ERROR_INVALID_PARAMETER,
504 "last error %u\n", GetLastError());
506 /* insertion with no variadic arguments */
507 SetLastError(0xdeadbeef);
508 memcpy(out, init_buf, sizeof(init_buf));
509 r = FormatMessageA(FORMAT_MESSAGE_FROM_STRING, "%1", 0,
510 0, out, sizeof(out)/sizeof(CHAR), NULL);
511 ok(!memcmp(out, init_buf, sizeof(init_buf)), "Expected the buffer to be untouched\n");
512 ok(r==0, "succeeded: r=%d\n", r);
513 ok(GetLastError()==ERROR_INVALID_PARAMETER, "last error %u\n", GetLastError());
515 SetLastError(0xdeadbeef);
516 memcpy(out, init_buf, sizeof(init_buf));
517 r = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY, "%1", 0,
518 0, out, sizeof(out)/sizeof(CHAR), NULL);
519 ok(!memcmp(out, init_buf, sizeof(init_buf)), "Expected the buffer to be untouched\n");
520 ok(r==0, "succeeded: r=%d\n", r);
521 ok(GetLastError()==ERROR_INVALID_PARAMETER, "last error %u\n", GetLastError());
523 /* using the format feature */
524 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!s!", 0,
525 0, out, sizeof(out)/sizeof(CHAR), "test");
526 ok(!strcmp("test", out),"failed out=[%s]\n",out);
527 ok(r==4,"failed: r=%d\n",r);
530 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1", 0,
531 0, out, sizeof(out)/sizeof(CHAR), "test");
532 ok(!strcmp("test", out),"failed out=[%s]\n",out);
533 ok(r==4,"failed: r=%d\n",r);
536 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1%2", 0,
537 0, out, sizeof(out)/sizeof(CHAR), "te","st");
538 ok(!strcmp("test", out),"failed out=[%s]\n",out);
539 ok(r==4,"failed: r=%d\n",r);
542 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1%3%2%1", 0,
543 0, out, sizeof(out)/sizeof(CHAR), "t","s","e");
544 ok(!strcmp("test", out),"failed out=[%s]\n",out);
545 ok(r==4,"failed: r=%d\n",r);
547 /* s doesn't seem to work in format strings */
548 r = doit(FORMAT_MESSAGE_FROM_STRING, "%!s!", 0,
549 0, out, sizeof(out)/sizeof(CHAR), "test");
550 ok(!strcmp("!s!", out),"failed out=[%s]\n",out);
551 ok(r==3,"failed: r=%d\n",r);
554 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!ls!", 0,
555 0, out, sizeof(out)/sizeof(CHAR), szwTest);
556 ok(!strcmp("test", out),"failed out=[%s]\n",out);
557 ok(r==4,"failed: r=%d\n",r);
560 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!S!", 0,
561 0, out, sizeof(out)/sizeof(CHAR), szwTest);
562 ok(!strcmp("test", out),"failed out=[%s]\n",out);
563 ok(r==4,"failed: r=%d\n",r);
566 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!ws!", 0,
567 0, out, sizeof(out)/sizeof(CHAR), szwTest);
568 ok(!strcmp("test", out),"failed out=[%s]\n",out);
569 ok(r==4,"failed: r=%d\n",r);
572 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!c!%2!c!%3!c!%1!c!", 0,
573 0, out, sizeof(out)/sizeof(CHAR), 't','e','s');
574 ok(!strcmp("test", out),"failed out=[%s]\n",out);
575 ok(r==4,"failed: r=%d\n",r);
578 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!lc!%2!lc!%3!lc!%1!lc!", 0,
579 0, out, sizeof(out)/sizeof(CHAR), 't','e','s');
580 ok(!strcmp("test", out),"failed out=[%s]\n",out);
581 ok(r==4,"failed: r=%d\n",r);
584 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!wc!%2!wc!%3!wc!%1!wc!", 0,
585 0, out, sizeof(out)/sizeof(CHAR), 't','e','s');
586 ok(!strcmp("test", out),"failed out=[%s]\n",out);
587 ok(r==4,"failed: r=%d\n",r);
590 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!C!%2!C!%3!C!%1!C!", 0,
591 0, out, sizeof(out)/sizeof(CHAR), 't','e','s');
592 ok(!strcmp("test", out),"failed out=[%s]\n",out);
593 ok(r==4,"failed: r=%d\n",r);
596 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!d!%2!d!%3!d!", 0,
597 0, out, sizeof(out)/sizeof(CHAR), 1,2,3);
598 ok(!strcmp("123", out),"failed out=[%s]\n",out);
599 ok(r==3,"failed: r=%d\n",r);
601 /* a single digit with some spacing */
602 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!4d!", 0,
603 0, out, sizeof(out)/sizeof(CHAR), 1);
604 ok(!strcmp(" 1", out),"failed out=[%s]\n",out);
605 ok(r==4,"failed: r=%d\n",r);
607 /* a single digit, left justified */
608 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!-4d!", 0,
609 0, out, sizeof(out)/sizeof(CHAR), 1);
610 ok(!strcmp("1 ", out),"failed out=[%s]\n",out);
611 ok(r==4,"failed: r=%d\n",r);
613 /* two digit decimal number */
614 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!4d!", 0,
615 0, out, sizeof(out)/sizeof(CHAR), 11);
616 ok(!strcmp(" 11", out),"failed out=[%s]\n",out);
617 ok(r==4,"failed: r=%d\n",r);
620 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!4x!", 0,
621 0, out, sizeof(out)/sizeof(CHAR), 11);
622 ok(!strcmp(" b", out),"failed out=[%s]\n",out);
623 ok(r==4,"failed: r=%d\n",r);
625 /* a hex number, upper case */
626 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!4X!", 0,
627 0, out, sizeof(out)/sizeof(CHAR), 11);
628 ok(!strcmp(" B", out),"failed out=[%s]\n",out);
629 ok(r==4,"failed: r=%d\n",r);
631 /* a hex number, upper case, left justified */
632 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!-4X!", 0,
633 0, out, sizeof(out)/sizeof(CHAR), 11);
634 ok(!strcmp("B ", out),"failed out=[%s]\n",out);
635 ok(r==4,"failed: r=%d\n",r);
637 /* a long hex number, upper case */
638 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!4X!", 0,
639 0, out, sizeof(out)/sizeof(CHAR), 0x1ab);
640 ok(!strcmp(" 1AB", out),"failed out=[%s]\n",out);
641 ok(r==4,"failed: r=%d\n",r);
644 r = doit(FORMAT_MESSAGE_FROM_STRING, " %%%% ", 0,
645 0, out, sizeof(out)/sizeof(CHAR));
646 ok(!strcmp(" %% ", out),"failed out=[%s]\n",out);
647 ok(r==4,"failed: r=%d\n",r);
649 /* periods are special cases */
650 r = doit(FORMAT_MESSAGE_FROM_STRING, " %.%. %1!d!", 0,
651 0, out, sizeof(out)/sizeof(CHAR), 0x1ab);
652 ok(!strcmp(" .. 427", out),"failed out=[%s]\n",out);
653 ok(r==7,"failed: r=%d\n",r);
655 /* %0 ends the line */
656 r = doit(FORMAT_MESSAGE_FROM_STRING, "test%0test", 0,
657 0, out, sizeof(out)/sizeof(CHAR));
658 ok(!strcmp("test", out),"failed out=[%s]\n",out);
659 ok(r==4,"failed: r=%d\n",r);
661 /* %! prints an exclamation */
662 r = doit(FORMAT_MESSAGE_FROM_STRING, "yah%!%0 ", 0,
663 0, out, sizeof(out)/sizeof(CHAR));
664 ok(!strcmp("yah!", out),"failed out=[%s]\n",out);
665 ok(r==4,"failed: r=%d\n",r);
668 r = doit(FORMAT_MESSAGE_FROM_STRING, "% % ", 0,
669 0, out, sizeof(out)/sizeof(CHAR));
670 ok(!strcmp(" ", out),"failed out=[%s]\n",out);
671 ok(r==4,"failed: r=%d\n",r);
673 /* %n yields \r\n, %r yields \r, %t yields \t */
674 r = doit(FORMAT_MESSAGE_FROM_STRING, "%n%r%t", 0,
675 0, out, sizeof(out)/sizeof(CHAR));
676 ok(!strcmp("\r\n\r\t", out),"failed out=[%s]\n",out);
677 ok(r==4,"failed: r=%d\n",r);
680 r = doit(FORMAT_MESSAGE_FROM_STRING, "hi\n", 0,
681 0, out, sizeof(out)/sizeof(CHAR));
682 ok(!strcmp("hi\r\n", out),"failed out=[%s]\n",out);
683 ok(r==4,"failed: r=%d\n",r);
685 /* carriage return line feed */
686 r = doit(FORMAT_MESSAGE_FROM_STRING, "hi\r\n", 0,
687 0, out, sizeof(out)/sizeof(CHAR));
688 ok(!strcmp("hi\r\n", out),"failed out=[%s]\n",out);
689 ok(r==4,"failed: r=%d\n",r);
691 /* carriage return */
692 r = doit(FORMAT_MESSAGE_FROM_STRING, "\r", 0,
693 0, out, sizeof(out)/sizeof(CHAR));
694 ok(!strcmp("\r\n", out),"failed out=[%s]\n",out);
695 ok(r==2,"failed: r=%d\n",r);
697 /* double carriage return line feed */
698 r = doit(FORMAT_MESSAGE_FROM_STRING, "\r\r\n", 0,
699 0, out, sizeof(out)/sizeof(CHAR));
700 ok(!strcmp("\r\n\r\n", out),"failed out=[%s]\n",out);
701 ok(r==4,"failed: r=%d\n",r);
703 /* precision and width */
705 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!3s!",
706 0, 0, out, sizeof(out), "t" );
707 ok(!strcmp(" t", out),"failed out=[%s]\n",out);
708 ok(r==3, "failed: r=%d\n",r);
709 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!*s!",
710 0, 0, out, sizeof(out), 4, "t");
711 if (!strcmp("*s",out)) win_skip( "width/precision not supported\n" );
714 ok(!strcmp( " t", out),"failed out=[%s]\n",out);
715 ok(r==4,"failed: r=%d\n",r);
716 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!4.2u!",
717 0, 0, out, sizeof(out), 3 );
718 ok(!strcmp( " 03", out),"failed out=[%s]\n",out);
719 ok(r==4,"failed: r=%d\n",r);
720 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!*.*u!",
721 0, 0, out, sizeof(out), 5, 3, 1 );
722 ok(!strcmp( " 001", out),"failed out=[%s]\n",out);
723 ok(r==5,"failed: r=%d\n",r);
724 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!*.*u!,%1!*.*u!",
725 0, 0, out, sizeof(out), 5, 3, 1, 4, 2 );
726 ok(!strcmp( " 001, 0002", out),"failed out=[%s]\n",out);
727 ok(r==11,"failed: r=%d\n",r);
728 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!*.*u!,%3!*.*u!",
729 0, 0, out, sizeof(out), 5, 3, 1, 6, 4, 2 );
730 /* older Win versions marked as broken even though this is arguably the correct behavior */
731 /* but the new (brain-damaged) behavior is specified on MSDN */
732 ok(!strcmp( " 001, 0002", out) ||
733 broken(!strcmp(" 001,000004", out)), /* NT4/Win2k */
734 "failed out=[%s]\n",out);
735 ok(r==12,"failed: r=%d\n",r);
736 /* args are not counted the same way with an argument array */
738 ULONG_PTR args[] = { 6, 4, 2, 5, 3, 1 };
739 r = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
740 "%1!*.*u!,%1!*.*u!", 0, 0, out, sizeof(out), (__ms_va_list *)args );
741 ok(!strcmp(" 0002, 00003", out),"failed out=[%s]\n",out);
742 ok(r==13,"failed: r=%d\n",r);
743 r = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
744 "%1!*.*u!,%4!*.*u!", 0, 0, out, sizeof(out), (__ms_va_list *)args );
745 ok(!strcmp(" 0002, 001", out),"failed out=[%s]\n",out);
746 ok(r==12,"failed: r=%d\n",r);
750 /* change of pace... test the low byte of dwflags */
753 r = doit(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_MAX_WIDTH_MASK, "hi\n", 0,
754 0, out, sizeof(out)/sizeof(CHAR));
755 ok(!strcmp("hi ", out), "failed out=[%s]\n",out);
756 ok(r==3, "failed: r=%d\n",r);
758 /* carriage return line feed */
759 r = doit(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_MAX_WIDTH_MASK, "hi\r\n", 0,
760 0, out, sizeof(out)/sizeof(CHAR));
761 ok(!strcmp("hi ", out),"failed out=[%s]\n",out);
762 ok(r==3,"failed: r=%d\n",r);
764 /* carriage return */
765 r = doit(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_MAX_WIDTH_MASK, "\r", 0,
766 0, out, sizeof(out)/sizeof(CHAR));
767 ok(!strcmp(" ", out),"failed out=[%s]\n",out);
768 ok(r==1,"failed: r=%d\n",r);
770 /* double carriage return line feed */
771 r = doit(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_MAX_WIDTH_MASK, "\r\r\n", 0,
772 0, out, sizeof(out)/sizeof(CHAR));
773 ok(!strcmp(" ", out),"failed out=[%s]\n",out);
774 ok(r==2,"failed: r=%d\n",r);
777 static void test_message_ignore_inserts(void)
779 static const char init_buf[] = {'x', 'x', 'x', 'x', 'x'};
784 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, "test", 0, 0, out,
785 sizeof(out)/sizeof(CHAR), NULL);
786 ok(ret == 4, "Expected FormatMessageA to return 4, got %d\n", ret);
787 ok(!strcmp("test", out), "Expected output string \"test\", got %s\n", out);
789 /* The %0 escape sequence is handled. */
790 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, "test%0", 0, 0, out,
791 sizeof(out)/sizeof(CHAR), NULL);
792 ok(ret == 4, "Expected FormatMessageA to return 4, got %d\n", ret);
793 ok(!strcmp("test", out), "Expected output string \"test\", got %s\n", out);
795 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, "test%0test", 0, 0, out,
796 sizeof(out)/sizeof(CHAR), NULL);
797 ok(ret == 4, "Expected FormatMessageA to return 4, got %d\n", ret);
798 ok(!strcmp("test", out), "Expected output string \"test\", got %s\n", out);
800 /* While FormatMessageA returns 0 in this case, no last error code is set. */
801 SetLastError(0xdeadbeef);
802 memcpy(out, init_buf, sizeof(init_buf));
803 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, "%0test", 0, 0, out,
804 sizeof(out)/sizeof(CHAR), NULL);
805 ok(ret == 0, "Expected FormatMessageA to return 0, got %d\n", ret);
806 ok(!memcmp(out, init_buf, sizeof(init_buf)), "Expected the output buffer to be untouched\n");
807 ok(GetLastError() == 0xdeadbeef, "Expected GetLastError() to return 0xdeadbeef, got %u\n", GetLastError());
809 /* Insert sequences are ignored. */
810 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, "test%1%2!*.*s!%99", 0, 0, out,
811 sizeof(out)/sizeof(CHAR), NULL);
812 ok(ret == 17, "Expected FormatMessageA to return 17, got %d\n", ret);
813 ok(!strcmp("test%1%2!*.*s!%99", out), "Expected output string \"test%%1%%2!*.*s!%%99\", got %s\n", out);
815 /* Only the "%n", "%r", and "%t" escape sequences are processed. */
816 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, "%%% %.%!", 0, 0, out,
817 sizeof(out)/sizeof(CHAR), NULL);
818 ok(ret == 8, "Expected FormatMessageA to return 8, got %d\n", ret);
819 ok(!strcmp("%%% %.%!", out), "Expected output string \"%%%%%% %%.%%!\", got %s\n", out);
821 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, "%n%r%t", 0, 0, out,
822 sizeof(out)/sizeof(CHAR), NULL);
823 ok(ret == 4, "Expected FormatMessageA to return 4, got %d\n", ret);
824 ok(!strcmp("\r\n\r\t", out), "Expected output string \"\\r\\n\\r\\t\", got %s\n", out);
826 /* CRLF characters are processed normally. */
827 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, "hi\n", 0, 0, out,
828 sizeof(out)/sizeof(CHAR), NULL);
829 ok(ret == 4, "Expected FormatMessageA to return 4, got %d\n", ret);
830 ok(!strcmp("hi\r\n", out), "Expected output string \"hi\\r\\n\", got %s\n", out);
832 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, "hi\r\n", 0, 0, out,
833 sizeof(out)/sizeof(CHAR), NULL);
834 ok(ret == 4, "Expected FormatMessageA to return 4, got %d\n", ret);
835 ok(!strcmp("hi\r\n", out), "Expected output string \"hi\\r\\n\", got %s\n", out);
837 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, "\r", 0, 0, out,
838 sizeof(out)/sizeof(CHAR), NULL);
839 ok(ret == 2, "Expected FormatMessageA to return 2, got %d\n", ret);
840 ok(!strcmp("\r\n", out), "Expected output string \"\\r\\n\", got %s\n", out);
842 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, "\r\r\n", 0, 0, out,
843 sizeof(out)/sizeof(CHAR), NULL);
844 ok(ret == 4, "Expected FormatMessageA to return 4, got %d\n", ret);
845 ok(!strcmp("\r\n\r\n", out), "Expected output string \"\\r\\n\\r\\n\", got %s\n", out);
847 /* The width parameter is handled the same also. */
848 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS |
849 FORMAT_MESSAGE_MAX_WIDTH_MASK, "hi\n", 0, 0, out,
850 sizeof(out)/sizeof(CHAR), NULL);
851 ok(!strcmp("hi ", out), "Expected output string \"hi \", got %s\n", out);
852 ok(ret == 3, "Expected FormatMessageA to return 3, got %d\n", ret);
854 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS |
855 FORMAT_MESSAGE_MAX_WIDTH_MASK, "hi\r\n", 0, 0, out,
856 sizeof(out)/sizeof(CHAR), NULL);
857 ok(ret == 3, "Expected FormatMessageA to return 3, got %d\n", ret);
858 ok(!strcmp("hi ", out), "Expected output string \"hi \", got %s\n", out);
860 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS |
861 FORMAT_MESSAGE_MAX_WIDTH_MASK, "\r", 0, 0, out,
862 sizeof(out)/sizeof(CHAR), NULL);
863 ok(ret == 1, "Expected FormatMessageA to return 1, got %d\n", ret);
864 ok(!strcmp(" ", out), "Expected output string \" \", got %s\n", out);
866 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS |
867 FORMAT_MESSAGE_MAX_WIDTH_MASK, "\r\r\n", 0, 0, out,
868 sizeof(out)/sizeof(CHAR), NULL);
869 ok(ret == 2, "Expected FormatMessageA to return 2, got %d\n", ret);
870 ok(!strcmp(" ", out), "Expected output string \" \", got %s\n", out);
873 static void test_message_ignore_inserts_wide(void)
875 static const WCHAR test[] = {'t','e','s','t',0};
876 static const WCHAR empty[] = {0};
877 static const WCHAR fmt_t0[] = {'t','e','s','t','%','0',0};
878 static const WCHAR fmt_t0t[] = {'t','e','s','t','%','0','t','e','s','t',0};
879 static const WCHAR fmt_0t[] = {'%','0','t','e','s','t',0};
880 static const WCHAR fmt_t12oos99[] = {'t','e','s','t','%','1','%','2','!','*','.','*','s','!','%','9','9',0};
881 static const WCHAR fmt_pctspacedot[] = {'%','%','%',' ','%','.','%','!',0};
882 static const WCHAR fmt_nrt[] = {'%','n','%','r','%','t',0};
883 static const WCHAR fmt_hi_lf[] = {'h','i','\n',0};
884 static const WCHAR fmt_hi_crlf[] = {'h','i','\r','\n',0};
885 static const WCHAR fmt_cr[] = {'\r',0};
886 static const WCHAR fmt_crcrlf[] = {'\r','\r','\n',0};
888 static const WCHAR s_nrt[] = {'\r','\n','\r','\t',0};
889 static const WCHAR s_hi_crlf[] = {'h','i','\r','\n',0};
890 static const WCHAR s_crlf[] = {'\r','\n',0};
891 static const WCHAR s_crlfcrlf[] = {'\r','\n','\r','\n',0};
892 static const WCHAR s_hi_sp[] = {'h','i',' ',0};
893 static const WCHAR s_sp[] = {' ',0};
894 static const WCHAR s_2sp[] = {' ',' ',0};
899 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, test, 0, 0, out,
900 sizeof(out)/sizeof(WCHAR), NULL);
901 ok(ret == 4, "Expected FormatMessageW to return 4, got %d\n", ret);
902 ok(!lstrcmpW(test, out), "Expected output string \"test\", got %s\n", wine_dbgstr_w(out));
904 /* The %0 escape sequence is handled. */
905 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, fmt_t0, 0, 0, out,
906 sizeof(out)/sizeof(WCHAR), NULL);
907 ok(ret == 4, "Expected FormatMessageW to return 4, got %d\n", ret);
908 ok(!lstrcmpW(test, out), "Expected output string \"test\", got %s\n", wine_dbgstr_w(out));
910 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, fmt_t0t, 0, 0, out,
911 sizeof(out)/sizeof(WCHAR), NULL);
912 ok(ret == 4, "Expected FormatMessageW to return 4, got %d\n", ret);
913 ok(!lstrcmpW(test, out), "Expected output string \"test\", got %s\n", wine_dbgstr_w(out));
915 /* While FormatMessageA returns 0 in this case, no last error code is set. */
916 SetLastError(0xdeadbeef);
917 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, fmt_0t, 0, 0, out,
918 sizeof(out)/sizeof(WCHAR), NULL);
919 ok(ret == 0, "Expected FormatMessageW to return 0, got %d\n", ret);
920 ok(!lstrcmpW(empty, out), "Expected the output buffer to be the empty string, got %s\n", wine_dbgstr_w(out));
921 ok(GetLastError() == 0xdeadbeef, "Expected GetLastError() to return 0xdeadbeef, got %u\n", GetLastError());
923 /* Insert sequences are ignored. */
924 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, fmt_t12oos99, 0, 0, out,
925 sizeof(out)/sizeof(WCHAR), NULL);
926 ok(ret == 17, "Expected FormatMessageW to return 17, got %d\n", ret);
927 ok(!lstrcmpW(fmt_t12oos99, out), "Expected output string \"test%%1%%2!*.*s!%%99\", got %s\n", wine_dbgstr_w(out));
929 /* Only the "%n", "%r", and "%t" escape sequences are processed. */
930 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, fmt_pctspacedot, 0, 0, out,
931 sizeof(out)/sizeof(WCHAR), NULL);
932 ok(ret == 8, "Expected FormatMessageW to return 8, got %d\n", ret);
933 ok(!lstrcmpW(fmt_pctspacedot, out), "Expected output string \"%%%%%% %%.%%!\", got %s\n", wine_dbgstr_w(out));
935 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, fmt_nrt, 0, 0, out,
936 sizeof(out)/sizeof(WCHAR), NULL);
937 ok(ret == 4, "Expected FormatMessageW to return 4, got %d\n", ret);
938 ok(!lstrcmpW(s_nrt, out), "Expected output string \"\\r\\n\\r\\t\", got %s\n", wine_dbgstr_w(out));
940 /* CRLF characters are processed normally. */
941 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, fmt_hi_lf, 0, 0, out,
942 sizeof(out)/sizeof(WCHAR), NULL);
943 ok(ret == 4, "Expected FormatMessageW to return 4, got %d\n", ret);
944 ok(!lstrcmpW(s_hi_crlf, out), "Expected output string \"hi\\r\\n\", got %s\n", wine_dbgstr_w(out));
946 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, fmt_hi_crlf, 0, 0, out,
947 sizeof(out)/sizeof(WCHAR), NULL);
948 ok(ret == 4, "Expected FormatMessageW to return 4, got %d\n", ret);
949 ok(!lstrcmpW(s_hi_crlf, out), "Expected output string \"hi\\r\\n\", got %s\n", wine_dbgstr_w(out));
951 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, fmt_cr, 0, 0, out,
952 sizeof(out)/sizeof(WCHAR), NULL);
953 ok(ret == 2, "Expected FormatMessageW to return 2, got %d\n", ret);
954 ok(!lstrcmpW(s_crlf, out), "Expected output string \"\\r\\n\", got %s\n", wine_dbgstr_w(out));
956 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, fmt_crcrlf, 0, 0, out,
957 sizeof(out)/sizeof(WCHAR), NULL);
958 ok(ret == 4, "Expected FormatMessageW to return 4, got %d\n", ret);
959 ok(!lstrcmpW(s_crlfcrlf, out), "Expected output string \"\\r\\n\\r\\n\", got %s\n", wine_dbgstr_w(out));
961 /* The width parameter is handled the same also. */
962 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS |
963 FORMAT_MESSAGE_MAX_WIDTH_MASK, fmt_hi_lf, 0, 0, out,
964 sizeof(out)/sizeof(WCHAR), NULL);
965 ok(ret == 3, "Expected FormatMessageW to return 3, got %d\n", ret);
966 ok(!lstrcmpW(s_hi_sp, out), "Expected output string \"hi \", got %s\n", wine_dbgstr_w(out));
968 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS |
969 FORMAT_MESSAGE_MAX_WIDTH_MASK, fmt_hi_crlf, 0, 0, out,
970 sizeof(out)/sizeof(WCHAR), NULL);
971 ok(ret == 3, "Expected FormatMessageW to return 3, got %d\n", ret);
972 ok(!lstrcmpW(s_hi_sp, out), "Expected output string \"hi \", got %s\n", wine_dbgstr_w(out));
974 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS |
975 FORMAT_MESSAGE_MAX_WIDTH_MASK, fmt_cr, 0, 0, out,
976 sizeof(out)/sizeof(WCHAR), NULL);
977 ok(ret == 1, "Expected FormatMessageW to return 1, got %d\n", ret);
978 ok(!lstrcmpW(s_sp, out), "Expected output string \" \", got %s\n", wine_dbgstr_w(out));
980 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS |
981 FORMAT_MESSAGE_MAX_WIDTH_MASK, fmt_crcrlf, 0, 0, out,
982 sizeof(out)/sizeof(WCHAR), NULL);
983 ok(ret == 2, "Expected FormatMessageW to return 2, got %d\n", ret);
984 ok(!lstrcmpW(s_2sp, out), "Expected output string \" \", got %s\n", wine_dbgstr_w(out));
987 static void test_message_insufficient_buffer(void)
989 static const char init_buf[] = {'x', 'x', 'x', 'x', 'x'};
990 static const char expected_buf[] = {'x', 'x', 'x', 'x', 'x'};
994 SetLastError(0xdeadbeef);
995 memcpy(out, init_buf, sizeof(init_buf));
996 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING, "test", 0, 0, out, 0, NULL);
997 ok(ret == 0, "Expected FormatMessageA to return 0, got %u\n", ret);
998 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
999 "Expected GetLastError() to return ERROR_INSUFFICIENT_BUFFER, got %u\n",
1001 ok(!memcmp(expected_buf, out, sizeof(expected_buf)),
1002 "Expected the buffer to be untouched\n");
1004 SetLastError(0xdeadbeef);
1005 memcpy(out, init_buf, sizeof(init_buf));
1006 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING, "test", 0, 0, out, 1, NULL);
1007 ok(ret == 0, "Expected FormatMessageA to return 0, got %u\n", ret);
1008 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
1009 "Expected GetLastError() to return ERROR_INSUFFICIENT_BUFFER, got %u\n",
1011 ok(!memcmp(expected_buf, out, sizeof(expected_buf)),
1012 "Expected the buffer to be untouched\n");
1014 SetLastError(0xdeadbeef);
1015 memcpy(out, init_buf, sizeof(init_buf));
1016 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING, "test", 0, 0, out, sizeof(out)/sizeof(out[0]) - 1, NULL);
1017 ok(ret == 0, "Expected FormatMessageA to return 0, got %u\n", ret);
1018 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
1019 "Expected GetLastError() to return ERROR_INSUFFICIENT_BUFFER, got %u\n",
1021 ok(!memcmp(expected_buf, out, sizeof(expected_buf)),
1022 "Expected the buffer to be untouched\n");
1025 static void test_message_insufficient_buffer_wide(void)
1027 static const WCHAR test[] = {'t','e','s','t',0};
1028 static const WCHAR init_buf[] = {'x', 'x', 'x', 'x', 'x'};
1029 static const WCHAR expected_buf[] = {'x', 'x', 'x', 'x', 'x'};
1030 static const WCHAR broken_buf[] = {0, 'x', 'x', 'x', 'x'};
1031 static const WCHAR broken2_buf[] = {'t','e','s',0,'x'};
1036 SetLastError(0xdeadbeef);
1037 memcpy(out, init_buf, sizeof(init_buf));
1038 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING, test, 0, 0, out, 0, NULL);
1039 ok(ret == 0, "Expected FormatMessageA to return 0, got %u\n", ret);
1040 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
1041 "Expected GetLastError() to return ERROR_INSUFFICIENT_BUFFER, got %u\n",
1043 ok(!memcmp(expected_buf, out, sizeof(expected_buf)),
1044 "Expected the buffer to be untouched\n");
1046 /* Windows Server 2003 and newer report failure but copy a
1047 * truncated string to the buffer for non-zero buffer sizes. */
1048 SetLastError(0xdeadbeef);
1049 memcpy(out, init_buf, sizeof(init_buf));
1050 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING, test, 0, 0, out, 1, NULL);
1051 ok(ret == 0, "Expected FormatMessageA to return 0, got %u\n", ret);
1052 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
1053 "Expected GetLastError() to return ERROR_INSUFFICIENT_BUFFER, got %u\n",
1055 ok(!memcmp(expected_buf, out, sizeof(expected_buf)) ||
1056 broken(!memcmp(broken_buf, out, sizeof(broken_buf))), /* W2K3+ */
1057 "Expected the buffer to be untouched\n");
1059 SetLastError(0xdeadbeef);
1060 memcpy(out, init_buf, sizeof(init_buf));
1061 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING, test, 0, 0, out, sizeof(out)/sizeof(out[0]) - 1, NULL);
1062 ok(ret == 0, "Expected FormatMessageA to return 0, got %u\n", ret);
1063 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
1064 "Expected GetLastError() to return ERROR_INSUFFICIENT_BUFFER, got %u\n",
1066 ok(!memcmp(expected_buf, out, sizeof(expected_buf)) ||
1067 broken(!memcmp(broken2_buf, out, sizeof(broken2_buf))), /* W2K3+ */
1068 "Expected the buffer to be untouched\n");
1071 static void test_message_null_buffer(void)
1075 /* Without FORMAT_MESSAGE_ALLOCATE_BUFFER, only the specified buffer size is checked. */
1076 SetLastError(0xdeadbeef);
1077 ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, 0, 0, NULL, 0, NULL);
1078 error = GetLastError();
1079 ok(!ret, "FormatMessageA returned %u\n", ret);
1080 ok(error == ERROR_INSUFFICIENT_BUFFER, "last error %u\n", error);
1082 SetLastError(0xdeadbeef);
1083 ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, 0, 0, NULL, 1, NULL);
1084 error = GetLastError();
1085 ok(!ret, "FormatMessageA returned %u\n", ret);
1086 ok(error == ERROR_INSUFFICIENT_BUFFER, "last error %u\n", error);
1088 if (0) /* crashes on Windows */
1090 SetLastError(0xdeadbeef);
1091 FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, 0, 0, NULL, 256, NULL);
1094 SetLastError(0xdeadbeef);
1095 ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, 0, 0, NULL, 0, NULL);
1096 error = GetLastError();
1097 ok(!ret, "FormatMessageA returned %u\n", ret);
1098 ok(error == ERROR_NOT_ENOUGH_MEMORY, "last error %u\n", error);
1100 SetLastError(0xdeadbeef);
1101 ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, 0, 0, NULL, 1, NULL);
1102 error = GetLastError();
1103 ok(!ret, "FormatMessageA returned %u\n", ret);
1104 ok(error == ERROR_NOT_ENOUGH_MEMORY, "last error %u\n", error);
1106 SetLastError(0xdeadbeef);
1107 ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, 0, 0, NULL, 256, NULL);
1108 error = GetLastError();
1109 ok(!ret, "FormatMessageA returned %u\n", ret);
1110 ok(error == ERROR_NOT_ENOUGH_MEMORY, "last error %u\n", error);
1113 static void test_message_null_buffer_wide(void)
1117 SetLastError(0xdeadbeef);
1118 ret = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, NULL, 0, 0, NULL, 0, NULL);
1119 error = GetLastError();
1120 ok(!ret, "FormatMessageW returned %u\n", ret);
1121 ok(error == ERROR_INVALID_PARAMETER, "last error %u\n", error);
1123 SetLastError(0xdeadbeef);
1124 ret = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, NULL, 0, 0, NULL, 1, NULL);
1125 error = GetLastError();
1126 ok(!ret, "FormatMessageW returned %u\n", ret);
1127 ok(error == ERROR_INVALID_PARAMETER, "last error %u\n", error);
1129 SetLastError(0xdeadbeef);
1130 ret = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, NULL, 0, 0, NULL, 256, NULL);
1131 error = GetLastError();
1132 ok(!ret, "FormatMessageW returned %u\n", ret);
1133 ok(error == ERROR_INVALID_PARAMETER, "last error %u\n", error);
1135 SetLastError(0xdeadbeef);
1136 ret = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, 0, 0, NULL, 0, NULL);
1137 error = GetLastError();
1138 ok(!ret, "FormatMessageW returned %u\n", ret);
1139 ok(error == ERROR_INVALID_PARAMETER, "last error %u\n", error);
1141 SetLastError(0xdeadbeef);
1142 ret = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, 0, 0, NULL, 1, NULL);
1143 error = GetLastError();
1144 ok(!ret, "FormatMessageW returned %u\n", ret);
1145 ok(error == ERROR_INVALID_PARAMETER, "last error %u\n", error);
1147 SetLastError(0xdeadbeef);
1148 ret = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, 0, 0, NULL, 256, NULL);
1149 error = GetLastError();
1150 ok(!ret, "FormatMessageW returned %u\n", ret);
1151 ok(error == ERROR_INVALID_PARAMETER, "last error %u\n", error);
1154 static void test_message_allocate_buffer(void)
1159 /* While MSDN suggests that FormatMessageA allocates a buffer whose size is
1160 * the larger of the output string and the requested buffer size, the tests
1161 * will not try to determine the actual size of the buffer allocated, as
1162 * the return value of LocalSize cannot be trusted for the purpose, and it should
1163 * in any case be safe for FormatMessageA to allocate in the manner that
1166 SetLastError(0xdeadbeef);
1167 buf = (char *)0xdeadbeef;
1168 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
1169 "", 0, 0, (char *)&buf, 0, NULL);
1170 ok(ret == 0, "Expected FormatMessageA to return 0, got %u\n", ret);
1171 ok(buf == NULL, "Expected output buffer pointer to be NULL\n");
1172 ok(GetLastError() == 0xdeadbeef,
1173 "Expected last error to be untouched, got %u\n", GetLastError());
1175 buf = (char *)0xdeadbeef;
1176 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
1177 "test", 0, 0, (char *)&buf, 0, NULL);
1178 ok(ret == 4, "Expected FormatMessageA to return 4, got %u\n", ret);
1179 ok(buf != NULL && buf != (char *)0xdeadbeef,
1180 "Expected output buffer pointer to be valid\n");
1181 if (buf != NULL && buf != (char *)0xdeadbeef)
1183 ok(!strcmp("test", buf),
1184 "Expected buffer to contain \"test\", got %s\n", buf);
1188 buf = (char *)0xdeadbeef;
1189 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
1190 "test", 0, 0, (char *)&buf, strlen("test"), NULL);
1191 ok(ret == 4, "Expected FormatMessageA to return 4, got %u\n", ret);
1192 ok(buf != NULL && buf != (char *)0xdeadbeef,
1193 "Expected output buffer pointer to be valid\n");
1194 if (buf != NULL && buf != (char *)0xdeadbeef)
1196 ok(!strcmp("test", buf),
1197 "Expected buffer to contain \"test\", got %s\n", buf);
1201 buf = (char *)0xdeadbeef;
1202 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
1203 "test", 0, 0, (char *)&buf, strlen("test") + 1, NULL);
1204 ok(ret == 4, "Expected FormatMessageA to return 4, got %u\n", ret);
1205 ok(buf != NULL && buf != (char *)0xdeadbeef,
1206 "Expected output buffer pointer to be valid\n");
1207 if (buf != NULL && buf != (char *)0xdeadbeef)
1209 ok(!strcmp("test", buf),
1210 "Expected buffer to contain \"test\", got %s\n", buf);
1214 buf = (char *)0xdeadbeef;
1215 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
1216 "test", 0, 0, (char *)&buf, strlen("test") + 2, NULL);
1217 ok(ret == 4, "Expected FormatMessageA to return 4, got %u\n", ret);
1218 ok(buf != NULL && buf != (char *)0xdeadbeef,
1219 "Expected output buffer pointer to be valid\n");
1220 if (buf != NULL && buf != (char *)0xdeadbeef)
1222 ok(!strcmp("test", buf),
1223 "Expected buffer to contain \"test\", got %s\n", buf);
1227 buf = (char *)0xdeadbeef;
1228 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
1229 "test", 0, 0, (char *)&buf, 1024, NULL);
1230 ok(ret == 4, "Expected FormatMessageA to return 4, got %u\n", ret);
1231 ok(buf != NULL && buf != (char *)0xdeadbeef,
1232 "Expected output buffer pointer to be valid\n");
1233 if (buf != NULL && buf != (char *)0xdeadbeef)
1235 ok(!strcmp("test", buf),
1236 "Expected buffer to contain \"test\", got %s\n", buf);
1241 static void test_message_allocate_buffer_wide(void)
1243 static const WCHAR empty[] = {0};
1244 static const WCHAR test[] = {'t','e','s','t',0};
1249 /* While MSDN suggests that FormatMessageW allocates a buffer whose size is
1250 * the larger of the output string and the requested buffer size, the tests
1251 * will not try to determine the actual size of the buffer allocated, as
1252 * the return value of LocalSize cannot be trusted for the purpose, and it should
1253 * in any case be safe for FormatMessageW to allocate in the manner that
1256 if (0) /* crashes on Windows */
1258 buf = (WCHAR *)0xdeadbeef;
1259 FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
1260 NULL, 0, 0, (WCHAR *)&buf, 0, NULL);
1263 SetLastError(0xdeadbeef);
1264 buf = (WCHAR *)0xdeadbeef;
1265 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
1266 empty, 0, 0, (WCHAR *)&buf, 0, NULL);
1267 ok(ret == 0, "Expected FormatMessageW to return 0, got %u\n", ret);
1268 ok(buf == NULL, "Expected output buffer pointer to be NULL\n");
1269 ok(GetLastError() == 0xdeadbeef,
1270 "Expected last error to be untouched, got %u\n", GetLastError());
1272 buf = (WCHAR *)0xdeadbeef;
1273 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
1274 test, 0, 0, (WCHAR *)&buf, 0, NULL);
1275 ok(ret == 4, "Expected FormatMessageA to return 4, got %u\n", ret);
1276 ok(buf != NULL && buf != (WCHAR *)0xdeadbeef,
1277 "Expected output buffer pointer to be valid\n");
1278 if (buf != NULL && buf != (WCHAR *)0xdeadbeef)
1280 ok(!lstrcmpW(test, buf),
1281 "Expected buffer to contain \"test\", got %s\n", wine_dbgstr_w(buf));
1285 buf = (WCHAR *)0xdeadbeef;
1286 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
1287 test, 0, 0, (WCHAR *)&buf, sizeof(test)/sizeof(WCHAR) - 1, NULL);
1288 ok(ret == 4, "Expected FormatMessageA to return 4, got %u\n", ret);
1289 ok(buf != NULL && buf != (WCHAR *)0xdeadbeef,
1290 "Expected output buffer pointer to be valid\n");
1291 if (buf != NULL && buf != (WCHAR *)0xdeadbeef)
1293 ok(!lstrcmpW(test, buf),
1294 "Expected buffer to contain \"test\", got %s\n", wine_dbgstr_w(buf));
1298 buf = (WCHAR *)0xdeadbeef;
1299 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
1300 test, 0, 0, (WCHAR *)&buf, sizeof(test)/sizeof(WCHAR), NULL);
1301 ok(ret == 4, "Expected FormatMessageA to return 4, got %u\n", ret);
1302 ok(buf != NULL && buf != (WCHAR *)0xdeadbeef,
1303 "Expected output buffer pointer to be valid\n");
1304 if (buf != NULL && buf != (WCHAR *)0xdeadbeef)
1306 ok(!lstrcmpW(test, buf),
1307 "Expected buffer to contain \"test\", got %s\n", wine_dbgstr_w(buf));
1311 buf = (WCHAR *)0xdeadbeef;
1312 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
1313 test, 0, 0, (WCHAR *)&buf, sizeof(test)/sizeof(WCHAR) + 1, NULL);
1314 ok(ret == 4, "Expected FormatMessageA to return 4, got %u\n", ret);
1315 ok(buf != NULL && buf != (WCHAR *)0xdeadbeef,
1316 "Expected output buffer pointer to be valid\n");
1317 if (buf != NULL && buf != (WCHAR *)0xdeadbeef)
1319 ok(!lstrcmpW(test, buf),
1320 "Expected buffer to contain \"test\", got %s\n", wine_dbgstr_w(buf));
1324 buf = (WCHAR *)0xdeadbeef;
1325 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER,
1326 test, 0, 0, (WCHAR *)&buf, 1024, NULL);
1327 ok(ret == 4, "Expected FormatMessageA to return 4, got %u\n", ret);
1328 ok(buf != NULL && buf != (WCHAR *)0xdeadbeef,
1329 "Expected output buffer pointer to be valid\n");
1330 if (buf != NULL && buf != (WCHAR *)0xdeadbeef)
1332 ok(!lstrcmpW(test, buf),
1333 "Expected buffer to contain \"test\", got %s\n", wine_dbgstr_w(buf));
1338 static void test_message_from_hmodule(void)
1342 CHAR out[0x100] = {0};
1344 h = GetModuleHandle("kernel32.dll");
1345 ok(h != 0, "GetModuleHandle failed\n");
1347 /*Test existing messageID; as the message strings from wine's kernel32 differ from windows' kernel32 we don't compare
1348 the strings but only test that FormatMessage doesn't return 0*/
1349 ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE, h, 7/*=ERROR_ARENA_TRASHED*/,
1350 MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), out, sizeof(out)/sizeof(CHAR), NULL);
1351 ok(ret != 0, "FormatMessageA returned 0\n");
1353 /* Test a message string with an insertion without passing any variadic arguments. */
1354 ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE, h, 193 /* ERROR_BAD_EXE_FORMAT */,
1355 MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), out, sizeof(out)/sizeof(CHAR), NULL);
1356 ok(ret == 0, "FormatMessageA returned non-zero\n");
1358 ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE |
1359 FORMAT_MESSAGE_ARGUMENT_ARRAY, h, 193 /* ERROR_BAD_EXE_FORMAT */,
1360 MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), out, sizeof(out)/sizeof(CHAR), NULL);
1361 ok(ret == 0, "FormatMessageA returned non-zero\n");
1363 /*Test nonexistent messageID with varying language IDs Note: FormatMessageW behaves the same*/
1364 SetLastError(0xdeadbeef);
1365 ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE, h, 3044,
1366 MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), out, sizeof(out)/sizeof(CHAR), NULL);
1367 error = GetLastError();
1368 ok(ret == 0, "FormatMessageA returned %u instead of 0\n", ret);
1369 ok(error == ERROR_MR_MID_NOT_FOUND || error == ERROR_MUI_FILE_NOT_FOUND, "last error %u\n", error);
1371 SetLastError(0xdeadbeef);
1372 ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE, h, 3044,
1373 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), out, sizeof(out)/sizeof(CHAR), NULL);
1374 error = GetLastError();
1375 ok(ret == 0, "FormatMessageA returned %u instead of 0\n", ret);
1376 ok(error == ERROR_MR_MID_NOT_FOUND || error == ERROR_MUI_FILE_NOT_LOADED, "last error %u\n", error);
1378 SetLastError(0xdeadbeef);
1379 ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE, h, 3044,
1380 MAKELANGID(LANG_NEUTRAL, SUBLANG_SYS_DEFAULT), out, sizeof(out)/sizeof(CHAR), NULL);
1381 error = GetLastError();
1382 ok(ret == 0, "FormatMessageA returned %u instead of 0\n", ret);
1383 ok(error == ERROR_MR_MID_NOT_FOUND || error == ERROR_MUI_FILE_NOT_LOADED, "last error %u\n", error);
1385 SetLastError(0xdeadbeef);
1386 ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE, h, 3044,
1387 MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), out, sizeof(out)/sizeof(CHAR), NULL);
1388 error = GetLastError();
1389 ok(ret == 0, "FormatMessageA returned %u instead of 0\n", ret);
1390 ok(error == ERROR_RESOURCE_LANG_NOT_FOUND ||
1391 error == ERROR_MR_MID_NOT_FOUND ||
1392 error == ERROR_MUI_FILE_NOT_FOUND ||
1393 error == ERROR_MUI_FILE_NOT_LOADED,
1394 "last error %u\n", error);
1396 SetLastError(0xdeadbeef);
1397 ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE, h, 3044,
1398 MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_UK), out, sizeof(out)/sizeof(CHAR), NULL);
1399 error = GetLastError();
1400 ok(ret == 0, "FormatMessageA returned %u instead of 0\n", ret);
1401 ok(error == ERROR_RESOURCE_LANG_NOT_FOUND ||
1402 error == ERROR_MR_MID_NOT_FOUND ||
1403 error == ERROR_MUI_FILE_NOT_FOUND ||
1404 error == ERROR_MUI_FILE_NOT_LOADED,
1405 "last error %u\n", error);
1408 static void test_message_invalid_flags(void)
1410 static const char init_buf[] = {'x', 'x', 'x', 'x', 'x'};
1416 SetLastError(0xdeadbeef);
1417 memcpy(out, init_buf, sizeof(init_buf));
1418 ret = FormatMessageA(0, "test", 0, 0, out, sizeof(out)/sizeof(CHAR), NULL);
1419 ok(ret == 0, "Expected FormatMessageA to return 0, got %u\n", ret);
1420 ok(!memcmp(out, init_buf, sizeof(init_buf)),
1421 "Expected the output buffer to be untouched\n");
1422 ok(GetLastError() == ERROR_INVALID_PARAMETER,
1423 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
1426 SetLastError(0xdeadbeef);
1427 ptr = (char *)0xdeadbeef;
1428 ret = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER, "test", 0, 0, (char *)&ptr, 0, NULL);
1429 ok(ret == 0, "Expected FormatMessageA to return 0, got %u\n", ret);
1430 ok(ptr == NULL, "Expected output pointer to be initialized to NULL, got %p\n", ptr);
1431 ok(GetLastError() == ERROR_INVALID_PARAMETER,
1432 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
1435 SetLastError(0xdeadbeef);
1436 memcpy(out, init_buf, sizeof(init_buf));
1437 ret = FormatMessageA(FORMAT_MESSAGE_IGNORE_INSERTS, "test", 0, 0, out, sizeof(out)/sizeof(CHAR), NULL);
1438 ok(ret == 0, "Expected FormatMessageA to return 0, got %u\n", ret);
1439 ok(!memcmp(out, init_buf, sizeof(init_buf)),
1440 "Expected the output buffer to be untouched\n");
1441 ok(GetLastError() == ERROR_INVALID_PARAMETER,
1442 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
1445 SetLastError(0xdeadbeef);
1446 memcpy(out, init_buf, sizeof(init_buf));
1447 ret = FormatMessageA(FORMAT_MESSAGE_ARGUMENT_ARRAY, "test", 0, 0, out, sizeof(out)/sizeof(CHAR), NULL);
1448 ok(ret == 0, "Expected FormatMessageA to return 0, got %u\n", ret);
1449 ok(!memcmp(out, init_buf, sizeof(init_buf)),
1450 "Expected the output buffer to be untouched\n");
1451 ok(GetLastError() == ERROR_INVALID_PARAMETER,
1452 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
1455 SetLastError(0xdeadbeef);
1456 memcpy(out, init_buf, sizeof(init_buf));
1457 ret = FormatMessageA(FORMAT_MESSAGE_MAX_WIDTH_MASK, "test", 0, 0, out, sizeof(out)/sizeof(CHAR), NULL);
1458 ok(ret == 0, "Expected FormatMessageA to return 0, got %u\n", ret);
1459 ok(!memcmp(out, init_buf, sizeof(init_buf)),
1460 "Expected the output buffer to be untouched\n");
1461 ok(GetLastError() == ERROR_INVALID_PARAMETER,
1462 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
1465 /* Simultaneously setting FORMAT_MESSAGE_FROM_STRING with other source
1466 * flags is apparently permissible, and FORMAT_MESSAGE_FROM_STRING takes
1467 * precedence in this case. */
1469 memcpy(out, init_buf, sizeof(init_buf));
1470 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_FROM_SYSTEM,
1471 "test", 0, 0, out, sizeof(out)/sizeof(CHAR), NULL);
1472 ok(ret == 4, "Expected FormatMessageA to return 4, got %u\n", ret);
1473 ok(!strcmp("test", out),
1474 "Expected the output buffer to be untouched\n");
1476 memcpy(out, init_buf, sizeof(init_buf));
1477 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_FROM_HMODULE,
1478 "test", 0, 0, out, sizeof(out)/sizeof(CHAR), NULL);
1479 ok(ret == 4, "Expected FormatMessageA to return 4, got %u\n", ret);
1480 ok(!strcmp("test", out),
1481 "Expected the output buffer to be untouched\n");
1483 memcpy(out, init_buf, sizeof(init_buf));
1484 ret = FormatMessageA(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_FROM_HMODULE |
1485 FORMAT_MESSAGE_FROM_SYSTEM, "test", 0, 0, out,
1486 sizeof(out)/sizeof(CHAR), NULL);
1487 ok(ret == 4, "Expected FormatMessageA to return 4, got %u\n", ret);
1488 ok(!strcmp("test", out),
1489 "Expected the output buffer to be untouched\n");
1492 static void test_message_invalid_flags_wide(void)
1494 static const WCHAR init_buf[] = {'x', 'x', 'x', 'x', 'x'};
1495 static const WCHAR test[] = {'t','e','s','t',0};
1501 SetLastError(0xdeadbeef);
1502 memcpy(out, init_buf, sizeof(init_buf));
1503 ret = FormatMessageW(0, test, 0, 0, out, sizeof(out)/sizeof(WCHAR), NULL);
1504 ok(ret == 0, "Expected FormatMessageW to return 0, got %u\n", ret);
1505 ok(!memcmp(out, init_buf, sizeof(init_buf)),
1506 "Expected the output buffer to be untouched\n");
1507 ok(GetLastError() == ERROR_INVALID_PARAMETER,
1508 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
1511 SetLastError(0xdeadbeef);
1512 ptr = (WCHAR *)0xdeadbeef;
1513 ret = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER, test, 0, 0, (WCHAR *)&ptr, 0, NULL);
1514 ok(ret == 0, "Expected FormatMessageW to return 0, got %u\n", ret);
1515 ok(ptr == NULL, "Expected output pointer to be initialized to NULL, got %p\n", ptr);
1516 ok(GetLastError() == ERROR_INVALID_PARAMETER,
1517 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
1520 SetLastError(0xdeadbeef);
1521 memcpy(out, init_buf, sizeof(init_buf));
1522 ret = FormatMessageW(FORMAT_MESSAGE_IGNORE_INSERTS, test, 0, 0, out, sizeof(out)/sizeof(WCHAR), NULL);
1523 ok(ret == 0, "Expected FormatMessageW to return 0, got %u\n", ret);
1524 ok(!memcmp(out, init_buf, sizeof(init_buf)),
1525 "Expected the output buffer to be untouched\n");
1526 ok(GetLastError() == ERROR_INVALID_PARAMETER,
1527 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
1530 SetLastError(0xdeadbeef);
1531 memcpy(out, init_buf, sizeof(init_buf));
1532 ret = FormatMessageW(FORMAT_MESSAGE_ARGUMENT_ARRAY, test, 0, 0, out, sizeof(out)/sizeof(WCHAR), NULL);
1533 ok(ret == 0, "Expected FormatMessageW to return 0, got %u\n", ret);
1534 ok(!memcmp(out, init_buf, sizeof(init_buf)),
1535 "Expected the output buffer to be untouched\n");
1536 ok(GetLastError() == ERROR_INVALID_PARAMETER,
1537 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
1540 SetLastError(0xdeadbeef);
1541 memcpy(out, init_buf, sizeof(init_buf));
1542 ret = FormatMessageW(FORMAT_MESSAGE_MAX_WIDTH_MASK, test, 0, 0, out, sizeof(out)/sizeof(WCHAR), NULL);
1543 ok(ret == 0, "Expected FormatMessageW to return 0, got %u\n", ret);
1544 ok(!memcmp(out, init_buf, sizeof(init_buf)),
1545 "Expected the output buffer to be untouched\n");
1546 ok(GetLastError() == ERROR_INVALID_PARAMETER,
1547 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
1550 /* Simultaneously setting FORMAT_MESSAGE_FROM_STRING with other source
1551 * flags is apparently permissible, and FORMAT_MESSAGE_FROM_STRING takes
1552 * precedence in this case. */
1554 memcpy(out, init_buf, sizeof(init_buf));
1555 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_FROM_SYSTEM,
1556 test, 0, 0, out, sizeof(out)/sizeof(WCHAR), NULL);
1557 ok(ret == 4, "Expected FormatMessageW to return 4, got %u\n", ret);
1558 ok(!lstrcmpW(test, out),
1559 "Expected the output buffer to be untouched\n");
1561 memcpy(out, init_buf, sizeof(init_buf));
1562 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_FROM_HMODULE,
1563 test, 0, 0, out, sizeof(out)/sizeof(WCHAR), NULL);
1564 ok(ret == 4, "Expected FormatMessageW to return 4, got %u\n", ret);
1565 ok(!lstrcmpW(test, out),
1566 "Expected the output buffer to be untouched\n");
1568 memcpy(out, init_buf, sizeof(init_buf));
1569 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_FROM_HMODULE |
1570 FORMAT_MESSAGE_FROM_SYSTEM, test, 0, 0, out,
1571 sizeof(out)/sizeof(WCHAR), NULL);
1572 ok(ret == 4, "Expected FormatMessageW to return 4, got %u\n", ret);
1573 ok(!lstrcmpW(test, out),
1574 "Expected the output buffer to be untouched\n");
1577 START_TEST(format_msg)
1581 test_message_from_string();
1582 test_message_ignore_inserts();
1583 test_message_insufficient_buffer();
1584 test_message_null_buffer();
1585 test_message_allocate_buffer();
1586 test_message_from_hmodule();
1587 test_message_invalid_flags();
1589 SetLastError(0xdeadbeef);
1590 ret = FormatMessageW(FORMAT_MESSAGE_FROM_STRING, NULL, 0, 0, NULL, 0, NULL);
1591 if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
1593 win_skip("FormatMessageW is not implemented\n");
1597 test_message_from_string_wide();
1598 test_message_ignore_inserts_wide();
1599 test_message_insufficient_buffer_wide();
1600 test_message_null_buffer_wide();
1601 test_message_allocate_buffer_wide();
1602 test_message_invalid_flags_wide();