~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/kernel32/tests/format_msg.c

Version: ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~ [ wine-1.0-rc5 ] ~ [ wine-1.0-rc4 ] ~ [ wine-1.0-rc3 ] ~ [ wine-1.0-rc2 ] ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  1 /* Unit test suite for FormatMessageA
  2  *
  3  * Copyright 2002 Mike McCormack for CodeWeavers
  4  *
  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.
  9  *
 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.
 14  *
 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
 18  */
 19 
 20 #include <stdarg.h>
 21 
 22 #include "wine/test.h"
 23 #include "windef.h"
 24 #include "winbase.h"
 25 
 26 /* #define ok(cond,failstr) if(!(cond)) {printf("line %d : %s\n",__LINE__,failstr);exit(1);} */
 27 
 28 static DWORD doit(DWORD flags, LPCVOID src, DWORD msg_id, DWORD lang_id,
 29            LPSTR out, DWORD outsize, ... )
 30 {
 31     va_list list;
 32     DWORD r;
 33 
 34     va_start(list, outsize);
 35     r = FormatMessageA(flags, src, msg_id,
 36         lang_id, out, outsize, &list);
 37     va_end(list);
 38     return r;
 39 }
 40 
 41 static void test_message_from_string(void)
 42 {
 43     CHAR out[0x100] = {0};
 44     DWORD r;
 45     static const WCHAR szwTest[] = { 't','e','s','t',0};
 46 
 47     /* the basics */
 48     r = FormatMessageA(FORMAT_MESSAGE_FROM_STRING, "test", 0,
 49         0, out, sizeof(out)/sizeof(CHAR),NULL);
 50     ok(!strcmp("test", out),"failed out=[%s]\n",out);
 51     ok(r==4,"failed: r=%d\n",r);
 52 
 53     /* using the format feature */
 54     r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!s!", 0,
 55         0, out, sizeof(out)/sizeof(CHAR), "test");
 56     ok(!strcmp("test", out),"failed out=[%s]\n",out);
 57     ok(r==4,"failed: r=%d\n",r);
 58 
 59     /* no format */
 60     r = doit(FORMAT_MESSAGE_FROM_STRING, "%1", 0,
 61         0, out, sizeof(out)/sizeof(CHAR), "test");
 62     ok(!strcmp("test", out),"failed out=[%s]\n",out);
 63     ok(r==4,"failed: r=%d\n",r);
 64 
 65     /* two pieces */
 66     r = doit(FORMAT_MESSAGE_FROM_STRING, "%1%2", 0,
 67         0, out, sizeof(out)/sizeof(CHAR), "te","st");
 68     ok(!strcmp("test", out),"failed out=[%s]\n",out);
 69     ok(r==4,"failed: r=%d\n",r);
 70 
 71     /* three pieces */
 72     r = doit(FORMAT_MESSAGE_FROM_STRING, "%1%3%2%1", 0,
 73         0, out, sizeof(out)/sizeof(CHAR), "t","s","e");
 74     ok(!strcmp("test", out),"failed out=[%s]\n",out);
 75     ok(r==4,"failed: r=%d\n",r);
 76 
 77     /* s doesn't seem to work in format strings */
 78     r = doit(FORMAT_MESSAGE_FROM_STRING, "%!s!", 0,
 79         0, out, sizeof(out)/sizeof(CHAR), "test");
 80     ok(!strcmp("!s!", out),"failed out=[%s]\n",out);
 81     ok(r==3,"failed: r=%d\n",r);
 82 
 83     /* S is unicode */
 84     r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!S!", 0,
 85         0, out, sizeof(out)/sizeof(CHAR), szwTest);
 86     ok(!strcmp("test", out),"failed out=[%s]\n",out);
 87     ok(r==4,"failed: r=%d\n",r);
 88 
 89     /* as characters */
 90     r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!c!%2!c!%3!c!%1!c!", 0,
 91         0, out, sizeof(out)/sizeof(CHAR), 't','e','s');
 92     ok(!strcmp("test", out),"failed out=[%s]\n",out);
 93     ok(r==4,"failed: r=%d\n",r);
 94 
 95     /* some numbers */
 96     r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!d!%2!d!%3!d!", 0,
 97         0, out, sizeof(out)/sizeof(CHAR), 1,2,3);
 98     ok(!strcmp("123", out),"failed out=[%s]\n",out);
 99     ok(r==3,"failed: r=%d\n",r);
100 
101     /* a single digit with some spacing */
102     r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!4d!", 0,
103         0, out, sizeof(out)/sizeof(CHAR), 1);
104     ok(!strcmp("   1", out),"failed out=[%s]\n",out);
105     ok(r==4,"failed: r=%d\n",r);
106 
107     /* a single digit, left justified */
108     r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!-4d!", 0,
109         0, out, sizeof(out)/sizeof(CHAR), 1);
110     ok(!strcmp("1   ", out),"failed out=[%s]\n",out);
111     ok(r==4,"failed: r=%d\n",r);
112 
113     /* two digit decimal number */
114     r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!4d!", 0,
115         0, out, sizeof(out)/sizeof(CHAR), 11);
116     ok(!strcmp("  11", out),"failed out=[%s]\n",out);
117     ok(r==4,"failed: r=%d\n",r);
118 
119     /* a hex number */
120     r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!4x!", 0,
121         0, out, sizeof(out)/sizeof(CHAR), 11);
122     ok(!strcmp("   b", out),"failed out=[%s]\n",out);
123     ok(r==4,"failed: r=%d\n",r);
124 
125     /* a hex number, upper case */
126     r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!4X!", 0,
127         0, out, sizeof(out)/sizeof(CHAR), 11);
128     ok(!strcmp("   B", out),"failed out=[%s]\n",out);
129     ok(r==4,"failed: r=%d\n",r);
130 
131     /* a hex number, upper case, left justified */
132     r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!-4X!", 0,
133         0, out, sizeof(out)/sizeof(CHAR), 11);
134     ok(!strcmp("B   ", out),"failed out=[%s]\n",out);
135     ok(r==4,"failed: r=%d\n",r);
136 
137     /* a long hex number, upper case */
138     r = doit(FORMAT_MESSAGE_FROM_STRING, "%1!4X!", 0,
139         0, out, sizeof(out)/sizeof(CHAR), 0x1ab);
140     ok(!strcmp(" 1AB", out),"failed out=[%s]\n",out);
141     ok(r==4,"failed: r=%d\n",r);
142 
143     /* two percent... */
144     r = doit(FORMAT_MESSAGE_FROM_STRING, " %%%% ", 0,
145         0, out, sizeof(out)/sizeof(CHAR));
146     ok(!strcmp(" %% ", out),"failed out=[%s]\n",out);
147     ok(r==4,"failed: r=%d\n",r);
148 
149     /* periods are special cases */
150     r = doit(FORMAT_MESSAGE_FROM_STRING, " %.%. %1!d!", 0,
151         0, out, sizeof(out)/sizeof(CHAR), 0x1ab);
152     ok(!strcmp(" .. 427", out),"failed out=[%s]\n",out);
153     ok(r==7,"failed: r=%d\n",r);
154 
155     /* %0 ends the line */
156     r = doit(FORMAT_MESSAGE_FROM_STRING, "test%0test", 0,
157         0, out, sizeof(out)/sizeof(CHAR));
158     ok(!strcmp("test", out),"failed out=[%s]\n",out);
159     ok(r==4,"failed: r=%d\n",r);
160 
161     /* %! prints an exclamation */
162     r = doit(FORMAT_MESSAGE_FROM_STRING, "yah%!%0   ", 0,
163         0, out, sizeof(out)/sizeof(CHAR));
164     ok(!strcmp("yah!", out),"failed out=[%s]\n",out);
165     ok(r==4,"failed: r=%d\n",r);
166 
167     /* %space */
168     r = doit(FORMAT_MESSAGE_FROM_STRING, "% %   ", 0,
169         0, out, sizeof(out)/sizeof(CHAR));
170     ok(!strcmp("    ", out),"failed out=[%s]\n",out);
171     ok(r==4,"failed: r=%d\n",r);
172 
173     /* line feed */
174     r = doit(FORMAT_MESSAGE_FROM_STRING, "hi\n", 0,
175         0, out, sizeof(out)/sizeof(CHAR));
176     ok(!strcmp("hi\r\n", out),"failed out=[%s]\n",out);
177     ok(r==4,"failed: r=%d\n",r);
178 
179     /* carriage return line feed */
180     r = doit(FORMAT_MESSAGE_FROM_STRING, "hi\r\n", 0,
181         0, out, sizeof(out)/sizeof(CHAR));
182     ok(!strcmp("hi\r\n", out),"failed out=[%s]\n",out);
183     ok(r==4,"failed: r=%d\n",r);
184 
185     /* carriage return line feed */
186     r = doit(FORMAT_MESSAGE_FROM_STRING, "\r", 0,
187         0, out, sizeof(out)/sizeof(CHAR));
188     ok(!strcmp("\r\n", out),"failed out=[%s]\n",out);
189     ok(r==2,"failed: r=%d\n",r);
190 
191     /* carriage return line feed */
192     r = doit(FORMAT_MESSAGE_FROM_STRING, "\r\r\n", 0,
193         0, out, sizeof(out)/sizeof(CHAR));
194     ok(!strcmp("\r\n\r\n", out),"failed out=[%s]\n",out);
195     ok(r==4,"failed: r=%d\n",r);
196 
197     /* change of pace... test the low byte of dwflags */
198     /* line feed */
199     r = doit(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_MAX_WIDTH_MASK, "hi\n", 0,
200         0, out, sizeof(out)/sizeof(CHAR));
201     ok(!strcmp("hi ", out) || !strcmp("hi\r\n", out),"failed out=[%s]\n",out);
202     ok(r==3 || r==4,"failed: r=%d\n",r);
203 
204     /* carriage return line feed */
205     r = doit(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_MAX_WIDTH_MASK, "hi\r\n", 0,
206         0, out, sizeof(out)/sizeof(CHAR));
207     ok(!strcmp("hi ", out),"failed out=[%s]\n",out);
208     ok(r==3,"failed: r=%d\n",r);
209 
210     /* carriage return line feed */
211     r = doit(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_MAX_WIDTH_MASK, "\r", 0,
212         0, out, sizeof(out)/sizeof(CHAR));
213     ok(!strcmp(" ", out),"failed out=[%s]\n",out);
214     ok(r==1,"failed: r=%d\n",r);
215 
216     /* carriage return line feed */
217     r = doit(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_MAX_WIDTH_MASK, "\r\r\n", 0,
218         0, out, sizeof(out)/sizeof(CHAR));
219     ok(!strcmp("  ", out),"failed out=[%s]\n",out);
220     ok(r==2,"failed: r=%d\n",r);
221 }
222 
223 static void test_message_null_buffer(void)
224 {
225     DWORD ret, error;
226 
227     SetLastError(0xdeadbeef);
228     ret = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, 0, 0, NULL, 0, NULL);
229     error = GetLastError();
230     ok(!ret, "FormatMessageA returned %u\n", ret);
231     ok(error == ERROR_NOT_ENOUGH_MEMORY ||
232        error == ERROR_INVALID_PARAMETER, /* win9x */
233        "last error %u\n", error);
234 
235     SetLastError(0xdeadbeef);
236     ret = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, 0, 0, NULL, 0, NULL);
237     error = GetLastError();
238     if (!ret && error == ERROR_CALL_NOT_IMPLEMENTED)
239     {
240         skip("FormatMessageW is not implemented\n");
241         return;
242     }
243 
244     ok(!ret, "FormatMessageW returned %u\n", ret);
245     ok(error == ERROR_INVALID_PARAMETER, "last error %u\n", error);
246 }
247 
248 START_TEST(format_msg)
249 {
250     test_message_from_string();
251     test_message_null_buffer();
252 }
253 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.