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 /* #define ok(cond,failstr) if(!(cond)) {printf("line %d : %s\n",__LINE__,failstr);exit(1);} */
29 static DWORD
doit(DWORD flags
, LPCVOID src
, DWORD msg_id
, DWORD lang_id
,
30 LPSTR out
, DWORD outsize
, ... )
35 va_start(list
, outsize
);
36 r
= FormatMessageA(flags
, src
, msg_id
,
37 lang_id
, out
, outsize
, &list
);
42 static DWORD
doitW(DWORD flags
, LPCVOID src
, DWORD msg_id
, DWORD lang_id
,
43 LPWSTR out
, DWORD outsize
, ... )
48 va_start(list
, outsize
);
49 r
= FormatMessageW(flags
, src
, msg_id
,
50 lang_id
, out
, outsize
, &list
);
55 static void test_message_from_string_wide(void)
57 static const WCHAR test
[] = {'t','e','s','t',0};
58 static const WCHAR te
[] = {'t','e',0};
59 static const WCHAR st
[] = {'s','t',0};
60 static const WCHAR t
[] = {'t',0};
61 static const WCHAR e
[] = {'e',0};
62 static const WCHAR s
[] = {'s',0};
63 static const WCHAR fmt_1
[] = {'%','1',0};
64 static const WCHAR fmt_12
[] = {'%','1','%','2',0};
65 static const WCHAR fmt_123
[] = {'%','1','%','3','%','2','%','1',0};
66 static const WCHAR fmt_123c
[] = {'%','1','!','c','!','%','2','!','c','!','%','3','!','c','!','%','1','!','c','!',0};
67 static const WCHAR fmt_123lc
[] = {'%','1','!','l','c','!','%','2','!','l','c','!','%','3','!','l','c','!','%','1','!','l','c','!',0};
68 static const WCHAR fmt_123wc
[] = {'%','1','!','w','c','!','%','2','!','w','c','!','%','3','!','w','c','!','%','1','!','w','c','!',0};
69 static const WCHAR fmt_123C
[] = {'%','1','!','C','!','%','2','!','C','!','%','3','!','C','!','%','1','!','C','!',0};
70 static const WCHAR fmt_123d
[] = {'%','1','!','d','!','%','2','!','d','!','%','3','!','d','!',0};
71 static const WCHAR fmt_1s
[] = {'%','1','!','s','!',0};
72 static const WCHAR fmt_s
[] = {'%','!','s','!',0};
73 static const WCHAR fmt_ls
[] = {'%','!','l','s','!',0};
74 static const WCHAR fmt_ws
[] = {'%','!','w','s','!',0};
75 static const WCHAR fmt_S
[] = {'%','!','S','!',0};
76 static const WCHAR fmt_14d
[] = {'%','1','!','4','d','!',0};
77 static const WCHAR fmt_14x
[] = {'%','1','!','4','x','!',0};
78 static const WCHAR fmt_14X
[] = {'%','1','!','4','X','!',0};
79 static const WCHAR fmt_1_4X
[] = {'%','1','!','-','4','X','!',0};
80 static const WCHAR fmt_1_4d
[] = {'%','1','!','-','4','d','!',0};
81 static const WCHAR fmt_2pct
[] = {' ','%','%','%','%',' ',0};
82 static const WCHAR fmt_2dot1d
[] = {' ', '%','.','%','.',' ',' ','%','1','!','d','!',0};
83 static const WCHAR fmt_t0t
[] = {'t','e','s','t','%','0','t','e','s','t',0};
84 static const WCHAR fmt_yah
[] = {'y','a','h','%','!','%','0',' ',' ',' ',0};
85 static const WCHAR fmt_space
[] = {'%',' ','%',' ',' ',' ',0};
86 static const WCHAR fmt_hi_lf
[] = {'h','i','\n',0};
87 static const WCHAR fmt_hi_crlf
[] = {'h','i','\r','\n',0};
88 static const WCHAR fmt_cr
[] = {'\r',0};
89 static const WCHAR fmt_crcrlf
[] = {'\r','\r','\n',0};
90 static const WCHAR s_123d
[] = {'1','2','3',0};
91 static const WCHAR s_14d
[] = {' ',' ',' ','1',0};
92 static const WCHAR s_14x
[] = {' ',' ',' ','b',0};
93 static const WCHAR s_14X
[] = {' ',' ',' ','B',0};
94 static const WCHAR s_1_4X
[] = {'B',' ',' ',' ',0};
95 static const WCHAR s_14d2
[] = {' ',' ','1','1',0};
96 static const WCHAR s_1_4d
[] = {'1',' ',' ',' ',0};
97 static const WCHAR s_1AB
[] = {' ','1','A','B',0};
98 static const WCHAR s_2pct
[] = {' ','%','%',' ',0};
99 static const WCHAR s_2dot147
[] = {' ','.','.',' ',' ','4','2','7',0};
100 static const WCHAR s_yah
[] = {'y','a','h','!',0};
101 static const WCHAR s_space
[] = {' ',' ',' ',' ',0};
102 static const WCHAR s_hi_crlf
[] = {'h','i','\r','\n',0};
103 static const WCHAR s_crlf
[] = {'\r','\n',0};
104 static const WCHAR s_crlfcrlf
[] = {'\r','\n','\r','\n',0};
105 static const WCHAR s_hi_sp
[] = {'h','i',' ',0};
106 static const WCHAR s_sp
[] = {' ',0};
107 static const WCHAR s_2sp
[] = {' ',' ',0};
108 WCHAR out
[0x100] = {0};
111 SetLastError(0xdeadbeef);
112 r
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
, NULL
, 0, 0, NULL
, 0, NULL
);
113 error
= GetLastError();
114 if (!r
&& error
== ERROR_CALL_NOT_IMPLEMENTED
)
116 win_skip("FormatMessageW is not implemented\n");
121 r
= FormatMessageW(FORMAT_MESSAGE_FROM_STRING
, test
, 0,
122 0, out
, sizeof(out
)/sizeof(WCHAR
), NULL
);
123 ok(!lstrcmpW(test
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
124 ok(r
==4, "failed: r=%d\n", r
);
126 /* using the format feature */
127 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_1s
, 0,
128 0, out
, sizeof(out
)/sizeof(WCHAR
), test
);
129 ok(!lstrcmpW(test
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
130 ok(r
==4,"failed: r=%d\n", r
);
133 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_1
, 0,
134 0, out
, sizeof(out
)/sizeof(WCHAR
), test
);
135 ok(!lstrcmpW(test
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
136 ok(r
==4,"failed: r=%d\n", r
);
139 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_12
, 0,
140 0, out
, sizeof(out
)/sizeof(WCHAR
), te
, st
);
141 ok(!lstrcmpW(test
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
142 ok(r
==4,"failed: r=%d\n", r
);
145 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_123
, 0,
146 0, out
, sizeof(out
)/sizeof(WCHAR
), t
, s
, e
);
147 ok(!lstrcmpW(test
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
148 ok(r
==4,"failed: r=%d\n", r
);
150 /* s doesn't seem to work in format strings */
151 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_s
, 0,
152 0, out
, sizeof(out
)/sizeof(WCHAR
), test
);
153 ok(!lstrcmpW(&fmt_s
[1], out
), "failed out=%s\n", wine_dbgstr_w(out
));
154 ok(r
==3, "failed: r=%d\n", r
);
157 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_ls
, 0,
158 0, out
, sizeof(out
)/sizeof(WCHAR
), test
);
159 ok(!lstrcmpW(&fmt_ls
[1], out
), "failed out=%s\n", wine_dbgstr_w(out
));
160 ok(r
==4, "failed: r=%d\n", r
);
163 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_S
, 0,
164 0, out
, sizeof(out
)/sizeof(WCHAR
), test
);
165 ok(!lstrcmpW(&fmt_S
[1], out
), "failed out=%s\n", wine_dbgstr_w(out
));
166 ok(r
==3, "failed: r=%d\n", r
);
169 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_ws
, 0,
170 0, out
, sizeof(out
)/sizeof(WCHAR
), test
);
171 ok(!lstrcmpW(&fmt_ws
[1], out
), "failed out=%s\n", wine_dbgstr_w(out
));
172 ok(r
==4, "failed: r=%d\n", r
);
175 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_123c
, 0,
176 0, out
, sizeof(out
)/sizeof(WCHAR
), 't', 'e', 's');
177 ok(!lstrcmpW(test
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
178 ok(r
==4,"failed: r=%d\n", r
);
181 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_123lc
, 0,
182 0, out
, sizeof(out
)/sizeof(WCHAR
), 't', 'e', 's');
183 ok(!lstrcmpW(test
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
184 ok(r
==4,"failed: r=%d\n", r
);
187 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_123wc
, 0,
188 0, out
, sizeof(out
)/sizeof(WCHAR
), 't', 'e', 's');
189 ok(!lstrcmpW(test
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
190 ok(r
==4,"failed: r=%d\n", r
);
193 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_123C
, 0,
194 0, out
, sizeof(out
)/sizeof(WCHAR
), 't', 'e', 's');
195 ok(!lstrcmpW(test
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
196 ok(r
==4,"failed: r=%d\n", r
);
199 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_123d
, 0,
200 0, out
, sizeof(out
)/sizeof(WCHAR
), 1, 2, 3);
201 ok(!lstrcmpW(s_123d
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
202 ok(r
==3,"failed: r=%d\n", r
);
204 /* a single digit with some spacing */
205 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_14d
, 0,
206 0, out
, sizeof(out
)/sizeof(WCHAR
), 1);
207 ok(!lstrcmpW(s_14d
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
209 /* a single digit, left justified */
210 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_1_4d
, 0,
211 0, out
, sizeof(out
)/sizeof(CHAR
), 1);
212 ok(!lstrcmpW(s_1_4d
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
213 ok(r
==4,"failed: r=%d\n", r
);
215 /* two digit decimal number */
216 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_14d
, 0,
217 0, out
, sizeof(out
)/sizeof(WCHAR
), 11);
218 ok(!lstrcmpW(s_14d2
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
219 ok(r
==4,"failed: r=%d\n", r
);
222 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_14x
, 0,
223 0, out
, sizeof(out
)/sizeof(WCHAR
), 11);
224 ok(!lstrcmpW(s_14x
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
225 ok(r
==4,"failed: r=%d\n", r
);
227 /* a hex number, upper case */
228 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_14X
, 0,
229 0, out
, sizeof(out
)/sizeof(WCHAR
), 11);
230 ok(!lstrcmpW(s_14X
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
231 ok(r
==4,"failed: r=%d\n", r
);
233 /* a hex number, upper case, left justified */
234 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_1_4X
, 0,
235 0, out
, sizeof(out
)/sizeof(WCHAR
), 11);
236 ok(!lstrcmpW(s_1_4X
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
237 ok(r
==4,"failed: r=%d\n", r
);
239 /* a long hex number, upper case */
240 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_14X
, 0,
241 0, out
, sizeof(out
)/sizeof(WCHAR
), 0x1ab);
242 ok(!lstrcmpW(s_1AB
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
243 ok(r
==4,"failed: r=%d\n", r
);
246 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_2pct
, 0,
247 0, out
, sizeof(out
)/sizeof(WCHAR
));
248 ok(!lstrcmpW(s_2pct
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
249 ok(r
==4,"failed: r=%d\n", r
);
251 /* periods are special cases */
252 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_2dot1d
, 0,
253 0, out
, sizeof(out
)/sizeof(WCHAR
), 0x1ab);
254 ok(!lstrcmpW(s_2dot147
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
255 ok(r
==8,"failed: r=%d\n", r
);
257 /* %0 ends the line */
258 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_t0t
, 0,
259 0, out
, sizeof(out
)/sizeof(WCHAR
));
260 ok(!lstrcmpW(test
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
261 ok(r
==4,"failed: r=%d\n", r
);
263 /* %! prints an exclamation */
264 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_yah
, 0,
265 0, out
, sizeof(out
)/sizeof(WCHAR
));
266 ok(!lstrcmpW(s_yah
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
267 ok(r
==4,"failed: r=%d\n", r
);
270 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_space
, 0,
271 0, out
, sizeof(out
)/sizeof(WCHAR
));
272 ok(!lstrcmpW(s_space
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
273 ok(r
==4,"failed: r=%d\n", r
);
276 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_hi_lf
, 0,
277 0, out
, sizeof(out
)/sizeof(WCHAR
));
278 ok(!lstrcmpW(s_hi_crlf
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
279 ok(r
==4,"failed: r=%d\n", r
);
281 /* carriage return line feed */
282 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_hi_crlf
, 0,
283 0, out
, sizeof(out
)/sizeof(WCHAR
));
284 ok(!lstrcmpW(s_hi_crlf
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
285 ok(r
==4,"failed: r=%d\n", r
);
287 /* carriage return */
288 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_cr
, 0,
289 0, out
, sizeof(out
)/sizeof(WCHAR
));
290 ok(!lstrcmpW(s_crlf
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
291 ok(r
==2,"failed: r=%d\n", r
);
293 /* double carriage return line feed */
294 r
= doitW(FORMAT_MESSAGE_FROM_STRING
, fmt_crcrlf
, 0,
295 0, out
, sizeof(out
)/sizeof(WCHAR
));
296 ok(!lstrcmpW(s_crlfcrlf
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
297 ok(r
==4,"failed: r=%d\n", r
);
299 /* change of pace... test the low byte of dwflags */
302 r
= doitW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_MAX_WIDTH_MASK
, fmt_hi_lf
, 0,
303 0, out
, sizeof(out
)/sizeof(WCHAR
));
304 ok(!lstrcmpW(s_hi_sp
, out
) || !lstrcmpW(s_hi_crlf
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
305 ok(r
==3 || r
==4,"failed: r=%d\n", r
);
307 /* carriage return line feed */
308 r
= doitW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_MAX_WIDTH_MASK
, fmt_hi_crlf
, 0,
309 0, out
, sizeof(out
)/sizeof(WCHAR
));
310 ok(!lstrcmpW(s_hi_sp
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
311 ok(r
==3,"failed: r=%d\n", r
);
313 /* carriage return */
314 r
= doitW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_MAX_WIDTH_MASK
, fmt_cr
, 0,
315 0, out
, sizeof(out
)/sizeof(WCHAR
));
316 ok(!lstrcmpW(s_sp
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
317 ok(r
==1,"failed: r=%d\n", r
);
319 /* double carriage return line feed */
320 r
= doitW(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_MAX_WIDTH_MASK
, fmt_crcrlf
, 0,
321 0, out
, sizeof(out
)/sizeof(WCHAR
));
322 ok(!lstrcmpW(s_2sp
, out
), "failed out=%s\n", wine_dbgstr_w(out
));
323 ok(r
==2,"failed: r=%d\n", r
);
326 static void test_message_from_string(void)
328 CHAR out
[0x100] = {0};
330 static const WCHAR szwTest
[] = { 't','e','s','t',0};
333 r
= FormatMessageA(FORMAT_MESSAGE_FROM_STRING
, "test", 0,
334 0, out
, sizeof(out
)/sizeof(CHAR
),NULL
);
335 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
336 ok(r
==4,"failed: r=%d\n",r
);
338 /* using the format feature */
339 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!s!", 0,
340 0, out
, sizeof(out
)/sizeof(CHAR
), "test");
341 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
342 ok(r
==4,"failed: r=%d\n",r
);
345 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1", 0,
346 0, out
, sizeof(out
)/sizeof(CHAR
), "test");
347 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
348 ok(r
==4,"failed: r=%d\n",r
);
351 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1%2", 0,
352 0, out
, sizeof(out
)/sizeof(CHAR
), "te","st");
353 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
354 ok(r
==4,"failed: r=%d\n",r
);
357 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1%3%2%1", 0,
358 0, out
, sizeof(out
)/sizeof(CHAR
), "t","s","e");
359 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
360 ok(r
==4,"failed: r=%d\n",r
);
362 /* s doesn't seem to work in format strings */
363 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%!s!", 0,
364 0, out
, sizeof(out
)/sizeof(CHAR
), "test");
365 ok(!strcmp("!s!", out
),"failed out=[%s]\n",out
);
366 ok(r
==3,"failed: r=%d\n",r
);
369 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!ls!", 0,
370 0, out
, sizeof(out
)/sizeof(CHAR
), szwTest
);
371 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
372 ok(r
==4,"failed: r=%d\n",r
);
375 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!S!", 0,
376 0, out
, sizeof(out
)/sizeof(CHAR
), szwTest
);
377 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
378 ok(r
==4,"failed: r=%d\n",r
);
381 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!ws!", 0,
382 0, out
, sizeof(out
)/sizeof(CHAR
), szwTest
);
383 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
384 ok(r
==4,"failed: r=%d\n",r
);
387 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!c!%2!c!%3!c!%1!c!", 0,
388 0, out
, sizeof(out
)/sizeof(CHAR
), 't','e','s');
389 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
390 ok(r
==4,"failed: r=%d\n",r
);
393 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!lc!%2!lc!%3!lc!%1!lc!", 0,
394 0, out
, sizeof(out
)/sizeof(CHAR
), 't','e','s');
395 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
396 ok(r
==4,"failed: r=%d\n",r
);
399 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!wc!%2!wc!%3!wc!%1!wc!", 0,
400 0, out
, sizeof(out
)/sizeof(CHAR
), 't','e','s');
401 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
402 ok(r
==4,"failed: r=%d\n",r
);
405 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!C!%2!C!%3!C!%1!C!", 0,
406 0, out
, sizeof(out
)/sizeof(CHAR
), 't','e','s');
407 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
408 ok(r
==4,"failed: r=%d\n",r
);
411 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!d!%2!d!%3!d!", 0,
412 0, out
, sizeof(out
)/sizeof(CHAR
), 1,2,3);
413 ok(!strcmp("123", out
),"failed out=[%s]\n",out
);
414 ok(r
==3,"failed: r=%d\n",r
);
416 /* a single digit with some spacing */
417 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!4d!", 0,
418 0, out
, sizeof(out
)/sizeof(CHAR
), 1);
419 ok(!strcmp(" 1", out
),"failed out=[%s]\n",out
);
420 ok(r
==4,"failed: r=%d\n",r
);
422 /* a single digit, left justified */
423 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!-4d!", 0,
424 0, out
, sizeof(out
)/sizeof(CHAR
), 1);
425 ok(!strcmp("1 ", out
),"failed out=[%s]\n",out
);
426 ok(r
==4,"failed: r=%d\n",r
);
428 /* two digit decimal number */
429 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!4d!", 0,
430 0, out
, sizeof(out
)/sizeof(CHAR
), 11);
431 ok(!strcmp(" 11", out
),"failed out=[%s]\n",out
);
432 ok(r
==4,"failed: r=%d\n",r
);
435 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!4x!", 0,
436 0, out
, sizeof(out
)/sizeof(CHAR
), 11);
437 ok(!strcmp(" b", out
),"failed out=[%s]\n",out
);
438 ok(r
==4,"failed: r=%d\n",r
);
440 /* a hex number, upper case */
441 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!4X!", 0,
442 0, out
, sizeof(out
)/sizeof(CHAR
), 11);
443 ok(!strcmp(" B", out
),"failed out=[%s]\n",out
);
444 ok(r
==4,"failed: r=%d\n",r
);
446 /* a hex number, upper case, left justified */
447 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!-4X!", 0,
448 0, out
, sizeof(out
)/sizeof(CHAR
), 11);
449 ok(!strcmp("B ", out
),"failed out=[%s]\n",out
);
450 ok(r
==4,"failed: r=%d\n",r
);
452 /* a long hex number, upper case */
453 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "%1!4X!", 0,
454 0, out
, sizeof(out
)/sizeof(CHAR
), 0x1ab);
455 ok(!strcmp(" 1AB", out
),"failed out=[%s]\n",out
);
456 ok(r
==4,"failed: r=%d\n",r
);
459 r
= doit(FORMAT_MESSAGE_FROM_STRING
, " %%%% ", 0,
460 0, out
, sizeof(out
)/sizeof(CHAR
));
461 ok(!strcmp(" %% ", out
),"failed out=[%s]\n",out
);
462 ok(r
==4,"failed: r=%d\n",r
);
464 /* periods are special cases */
465 r
= doit(FORMAT_MESSAGE_FROM_STRING
, " %.%. %1!d!", 0,
466 0, out
, sizeof(out
)/sizeof(CHAR
), 0x1ab);
467 ok(!strcmp(" .. 427", out
),"failed out=[%s]\n",out
);
468 ok(r
==7,"failed: r=%d\n",r
);
470 /* %0 ends the line */
471 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "test%0test", 0,
472 0, out
, sizeof(out
)/sizeof(CHAR
));
473 ok(!strcmp("test", out
),"failed out=[%s]\n",out
);
474 ok(r
==4,"failed: r=%d\n",r
);
476 /* %! prints an exclamation */
477 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "yah%!%0 ", 0,
478 0, out
, sizeof(out
)/sizeof(CHAR
));
479 ok(!strcmp("yah!", out
),"failed out=[%s]\n",out
);
480 ok(r
==4,"failed: r=%d\n",r
);
483 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "% % ", 0,
484 0, out
, sizeof(out
)/sizeof(CHAR
));
485 ok(!strcmp(" ", out
),"failed out=[%s]\n",out
);
486 ok(r
==4,"failed: r=%d\n",r
);
489 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "hi\n", 0,
490 0, out
, sizeof(out
)/sizeof(CHAR
));
491 ok(!strcmp("hi\r\n", out
),"failed out=[%s]\n",out
);
492 ok(r
==4,"failed: r=%d\n",r
);
494 /* carriage return line feed */
495 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "hi\r\n", 0,
496 0, out
, sizeof(out
)/sizeof(CHAR
));
497 ok(!strcmp("hi\r\n", out
),"failed out=[%s]\n",out
);
498 ok(r
==4,"failed: r=%d\n",r
);
500 /* carriage return */
501 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "\r", 0,
502 0, out
, sizeof(out
)/sizeof(CHAR
));
503 ok(!strcmp("\r\n", out
),"failed out=[%s]\n",out
);
504 ok(r
==2,"failed: r=%d\n",r
);
506 /* double carriage return line feed */
507 r
= doit(FORMAT_MESSAGE_FROM_STRING
, "\r\r\n", 0,
508 0, out
, sizeof(out
)/sizeof(CHAR
));
509 ok(!strcmp("\r\n\r\n", out
),"failed out=[%s]\n",out
);
510 ok(r
==4,"failed: r=%d\n",r
);
512 /* change of pace... test the low byte of dwflags */
515 r
= doit(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_MAX_WIDTH_MASK
, "hi\n", 0,
516 0, out
, sizeof(out
)/sizeof(CHAR
));
517 ok(!strcmp("hi ", out
) || !strcmp("hi\r\n", out
),"failed out=[%s]\n",out
);
518 ok(r
==3 || r
==4,"failed: r=%d\n",r
);
520 /* carriage return line feed */
521 r
= doit(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_MAX_WIDTH_MASK
, "hi\r\n", 0,
522 0, out
, sizeof(out
)/sizeof(CHAR
));
523 ok(!strcmp("hi ", out
),"failed out=[%s]\n",out
);
524 ok(r
==3,"failed: r=%d\n",r
);
526 /* carriage return */
527 r
= doit(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_MAX_WIDTH_MASK
, "\r", 0,
528 0, out
, sizeof(out
)/sizeof(CHAR
));
529 ok(!strcmp(" ", out
),"failed out=[%s]\n",out
);
530 ok(r
==1,"failed: r=%d\n",r
);
532 /* double carriage return line feed */
533 r
= doit(FORMAT_MESSAGE_FROM_STRING
| FORMAT_MESSAGE_MAX_WIDTH_MASK
, "\r\r\n", 0,
534 0, out
, sizeof(out
)/sizeof(CHAR
));
535 ok(!strcmp(" ", out
),"failed out=[%s]\n",out
);
536 ok(r
==2,"failed: r=%d\n",r
);
539 static void test_message_null_buffer(void)
543 SetLastError(0xdeadbeef);
544 ret
= FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_ALLOCATE_BUFFER
, NULL
, 0, 0, NULL
, 0, NULL
);
545 error
= GetLastError();
546 ok(!ret
, "FormatMessageA returned %u\n", ret
);
547 ok(error
== ERROR_NOT_ENOUGH_MEMORY
||
548 error
== ERROR_INVALID_PARAMETER
, /* win9x */
549 "last error %u\n", error
);
551 SetLastError(0xdeadbeef);
552 ret
= FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_ALLOCATE_BUFFER
, NULL
, 0, 0, NULL
, 0, NULL
);
553 error
= GetLastError();
554 if (!ret
&& error
== ERROR_CALL_NOT_IMPLEMENTED
)
556 win_skip("FormatMessageW is not implemented\n");
560 ok(!ret
, "FormatMessageW returned %u\n", ret
);
561 ok(error
== ERROR_INVALID_PARAMETER
, "last error %u\n", error
);
564 START_TEST(format_msg
)
566 test_message_from_string();
567 test_message_from_string_wide();
568 test_message_null_buffer();