1 /* Unit test suite for FormatMessageA
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "wine/test.h"
23 /* #define ok(cond,failstr) if(!(cond)) {printf("line %d : %s\n",__LINE__,failstr);exit(1);} */
25 DWORD doit(DWORD flags, LPCVOID src, DWORD msg_id, DWORD lang_id,
26 LPSTR out, DWORD outsize, ... )
31 va_start(list, outsize);
32 r = FormatMessageA(flags, src, msg_id,
33 lang_id, out, outsize, &list);
38 void test_message_from_string(void)
40 CHAR out[0x100] = {0};
42 WCHAR szwTest[] = { 't','e','s','t',0};
45 r = FormatMessageA(FORMAT_MESSAGE_FROM_STRING, "test", 0,
46 0, out, sizeof out/sizeof (CHAR),NULL);
47 ok(!strcmp("test", out),"failed");
50 /* using the format feature */
51 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!s!", 0,
52 0, out, sizeof out/sizeof (CHAR), "test");
53 ok(!strcmp("test", out),"failed");
57 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1", 0,
58 0, out, sizeof out/sizeof (CHAR), "test");
59 ok(!strcmp("test", out),"failed");
63 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1%2", 0,
64 0, out, sizeof out/sizeof (CHAR), "te","st");
65 ok(!strcmp("test", out),"failed");
69 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1%3%2%1", 0,
70 0, out, sizeof out/sizeof (CHAR), "t","s","e");
71 ok(!strcmp("test", out),"failed");
74 /* s doesn't seem to work in format strings */
75 r = doit(FORMAT_MESSAGE_FROM_STRING, "%!s!", 0,
76 0, out, sizeof out/sizeof (CHAR), "test");
77 ok(!strcmp("!s!", out),"failed");
81 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!S!", 0,
82 0, out, sizeof out/sizeof (CHAR), szwTest);
83 ok(!strcmp("test", out),"failed");
87 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!c!%2!c!%3!c!%1!c!", 0,
88 0, out, sizeof out/sizeof (CHAR), 't','e','s');
89 ok(!strcmp("test", out),"failed");
93 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!d!%2!d!%3!d!", 0,
94 0, out, sizeof out/sizeof (CHAR), 1,2,3);
95 ok(!strcmp("123", out),"failed");
98 /* a single digit with some spacing */
99 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!4d!", 0,
100 0, out, sizeof out/sizeof (CHAR), 1);
101 ok(!strcmp(" 1", out),"failed");
104 /* a single digit, left justified */
105 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!-4d!", 0,
106 0, out, sizeof out/sizeof (CHAR), 1);
107 ok(!strcmp("1 ", out),"failed");
110 /* two digit decimal number */
111 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!4d!", 0,
112 0, out, sizeof out/sizeof (CHAR), 11);
113 ok(!strcmp(" 11", out),"failed");
117 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!4x!", 0,
118 0, out, sizeof out/sizeof (CHAR), 11);
119 ok(!strcmp(" b", out),"failed");
122 /* a hex number, upper case */
123 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!4X!", 0,
124 0, out, sizeof out/sizeof (CHAR), 11);
125 ok(!strcmp(" B", out),"failed");
128 /* a hex number, upper case, left justified */
129 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!-4X!", 0,
130 0, out, sizeof out/sizeof (CHAR), 11);
131 ok(!strcmp("B ", out),"failed");
134 /* a long hex number, upper case */
135 r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!4X!", 0,
136 0, out, sizeof out/sizeof (CHAR), 0x1ab);
137 ok(!strcmp(" 1AB", out),"failed");
141 r = doit(FORMAT_MESSAGE_FROM_STRING, " %%%% ", 0,
142 0, out, sizeof out/sizeof (CHAR));
143 ok(!strcmp(" %% ", out),"failed");
146 /* periods are special cases */
147 r = doit(FORMAT_MESSAGE_FROM_STRING, " %.%. %1!d!", 0,
148 0, out, sizeof out/sizeof (CHAR), 0x1ab);
149 ok(!strcmp(" .. 427", out),"failed");
152 /* %0 ends the line */
153 r = doit(FORMAT_MESSAGE_FROM_STRING, "test%0test", 0,
154 0, out, sizeof out/sizeof (CHAR));
155 ok(!strcmp("test", out),"failed");
158 /* %! prints an exclaimation */
159 r = doit(FORMAT_MESSAGE_FROM_STRING, "yah%!%0 ", 0,
160 0, out, sizeof out/sizeof (CHAR));
161 ok(!strcmp("yah!", out),"failed");
165 r = doit(FORMAT_MESSAGE_FROM_STRING, "% % ", 0,
166 0, out, sizeof out/sizeof (CHAR));
167 ok(!strcmp(" ", out),"failed");
171 r = doit(FORMAT_MESSAGE_FROM_STRING, "hi\n", 0,
172 0, out, sizeof out/sizeof (CHAR));
173 ok(!strcmp("hi\r\n", out),"failed");
176 /* carriage return line feed */
177 r = doit(FORMAT_MESSAGE_FROM_STRING, "hi\r\n", 0,
178 0, out, sizeof out/sizeof (CHAR));
179 ok(!strcmp("hi\r\n", out),"failed");
182 /* carriage return line feed */
183 r = doit(FORMAT_MESSAGE_FROM_STRING, "\r", 0,
184 0, out, sizeof out/sizeof (CHAR));
185 ok(!strcmp("\r\n", out),"failed");
188 /* carriage return line feed */
189 r = doit(FORMAT_MESSAGE_FROM_STRING, "\r\r\n", 0,
190 0, out, sizeof out/sizeof (CHAR));
191 ok(!strcmp("\r\n\r\n", out),"failed");
194 /* change of pace... test the low byte of dwflags */
196 r = doit(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_MAX_WIDTH_MASK, "hi\n", 0,
197 0, out, sizeof out/sizeof (CHAR));
198 ok(!strcmp("hi ", out),"failed");
201 /* carriage return line feed */
202 r = doit(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_MAX_WIDTH_MASK, "hi\r\n", 0,
203 0, out, sizeof out/sizeof (CHAR));
204 ok(!strcmp("hi ", out),"failed");
207 /* carriage return line feed */
208 r = doit(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_MAX_WIDTH_MASK, "\r", 0,
209 0, out, sizeof out/sizeof (CHAR));
210 ok(!strcmp(" ", out),"failed");
213 /* carriage return line feed */
214 r = doit(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_MAX_WIDTH_MASK, "\r\r\n", 0,
215 0, out, sizeof out/sizeof (CHAR));
216 ok(!strcmp(" ", out),"failed");
220 START_TEST(format_msg)
222 test_message_from_string();