Release 1.6-rc2.
[wine/testsucceed.git] / dlls / user32 / tests / text.c
blob1874b1572e074452466b4d2f4b3e98fa6c9be2e2
1 /*
2 * DrawText tests
4 * Copyright (c) 2004 Zach Gorman
5 * Copyright 2007 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <assert.h>
24 #include "wine/test.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "winerror.h"
30 #define MODIFIED(rect) (rect.left == 10 && rect.right != 100 && rect.top == 10 && rect.bottom != 100)
31 #define EMPTY(rect) (rect.left == rect.right && rect.bottom == rect.top)
33 static void test_DrawTextCalcRect(void)
35 HWND hwnd;
36 HDC hdc;
37 HFONT hFont, hOldFont;
38 LOGFONTA lf;
39 static CHAR text[] = "Example text for testing DrawText in "
40 "MM_HIENGLISH mode";
41 static WCHAR textW[] = {'W','i','d','e',' ','c','h','a','r',' ',
42 's','t','r','i','n','g','\0'};
43 static CHAR emptystring[] = "";
44 static WCHAR emptystringW[] = { 0 };
45 INT textlen, textheight, heightcheck;
46 RECT rect = { 0, 0, 100, 0 };
47 BOOL ret;
48 DRAWTEXTPARAMS dtp;
49 BOOL conform_xp = TRUE;
51 /* Initialization */
52 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
53 0, 0, 200, 200, 0, 0, 0, NULL);
54 ok(hwnd != 0, "CreateWindowExA error %u\n", GetLastError());
55 hdc = GetDC(hwnd);
56 ok(hdc != 0, "GetDC error %u\n", GetLastError());
57 trace("hdc %p\n", hdc);
58 textlen = lstrlenA(text);
60 /* LOGFONT initialization */
61 memset(&lf, 0, sizeof(lf));
62 lf.lfCharSet = ANSI_CHARSET;
63 lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
64 lf.lfWeight = FW_DONTCARE;
65 lf.lfHeight = 0; /* mapping mode dependent */
66 lf.lfQuality = DEFAULT_QUALITY;
67 lstrcpyA(lf.lfFaceName, "Arial");
69 /* DrawText in MM_HIENGLISH with DT_CALCRECT */
70 SetMapMode(hdc, MM_HIENGLISH);
71 lf.lfHeight = 100 * 9 / 72; /* 9 point */
72 hFont = CreateFontIndirectA(&lf);
73 ok(hFont != 0, "CreateFontIndirectA error %u\n",
74 GetLastError());
75 hOldFont = SelectObject(hdc, hFont);
77 textheight = DrawTextA(hdc, text, textlen, &rect, DT_CALCRECT |
78 DT_EXTERNALLEADING | DT_WORDBREAK | DT_NOCLIP | DT_LEFT |
79 DT_NOPREFIX);
80 ok( textheight, "DrawTextA error %u\n", GetLastError());
82 trace("MM_HIENGLISH rect.bottom %d\n", rect.bottom);
83 ok(rect.bottom < 0, "In MM_HIENGLISH, DrawText with "
84 "DT_CALCRECT should return a negative rectangle bottom. "
85 "(bot=%d)\n", rect.bottom);
87 SelectObject(hdc, hOldFont);
88 ret = DeleteObject(hFont);
89 ok( ret, "DeleteObject error %u\n", GetLastError());
92 /* DrawText in MM_TEXT with DT_CALCRECT */
93 SetMapMode(hdc, MM_TEXT);
94 lf.lfHeight = -MulDiv(9, GetDeviceCaps(hdc,
95 LOGPIXELSY), 72); /* 9 point */
96 hFont = CreateFontIndirectA(&lf);
97 ok(hFont != 0, "CreateFontIndirectA error %u\n",
98 GetLastError());
99 hOldFont = SelectObject(hdc, hFont);
101 textheight = DrawTextA(hdc, text, textlen, &rect, DT_CALCRECT |
102 DT_EXTERNALLEADING | DT_WORDBREAK | DT_NOCLIP | DT_LEFT |
103 DT_NOPREFIX);
104 ok( textheight, "DrawTextA error %u\n", GetLastError());
106 trace("MM_TEXT rect.bottom %d\n", rect.bottom);
107 ok(rect.bottom > 0, "In MM_TEXT, DrawText with DT_CALCRECT "
108 "should return a positive rectangle bottom. (bot=%d)\n",
109 rect.bottom);
111 /* empty or null text should in some cases calc an empty rectangle */
113 SetRect( &rect, 10,10, 100, 100);
114 heightcheck = textheight = DrawTextExA(hdc, text, 0, &rect, DT_CALCRECT, NULL );
115 ok( !EMPTY(rect) && !MODIFIED(rect),
116 "rectangle should NOT be empty got %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
117 ok(textheight==0,"Got textheight from DrawTextExA\n");
119 SetRect( &rect, 10,10, 100, 100);
120 textheight = DrawTextA(hdc, text, 0, &rect, DT_CALCRECT);
121 ok( !EMPTY(rect) && !MODIFIED(rect),
122 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
123 rect.left, rect.top, rect.right, rect.bottom );
124 if (conform_xp)
125 ok(textheight==0,"Got textheight from DrawTextA\n");
126 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
128 SetRect( &rect, 10,10, 100, 100);
129 SetLastError( 0);
130 heightcheck = textheight = DrawTextExA(hdc, emptystring, -1, &rect, DT_CALCRECT, NULL );
131 ok( EMPTY(rect),
132 "rectangle should be empty got %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
133 ok(textheight!=0,"Failed to get textheight from DrawTextExA\n");
135 SetRect( &rect, 10,10, 100, 100);
136 textheight = DrawTextA(hdc, emptystring, -1, &rect, DT_CALCRECT);
137 ok( EMPTY(rect),
138 "rectangle should be empty got %d,%d-%d,%d\n",
139 rect.left, rect.top, rect.right, rect.bottom );
140 ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
141 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
143 SetRect( &rect, 10,10, 100, 100);
144 SetLastError( 0);
145 heightcheck = textheight = DrawTextExA(hdc, NULL, -1, &rect, DT_CALCRECT, NULL );
146 ok( EMPTY(rect) || !MODIFIED(rect),
147 "rectangle should be empty or not modified got %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
148 if (!textheight) /* Windows NT 4 */
150 if (conform_xp)
151 win_skip("XP conformity failed, skipping XP tests. Probably winNT\n");
152 conform_xp = FALSE;
154 else
155 ok(textheight!=0,"Failed to get textheight from DrawTextExA\n");
157 SetRect( &rect, 10,10, 100, 100);
158 textheight = DrawTextA(hdc, NULL, -1, &rect, DT_CALCRECT);
159 ok( EMPTY(rect) || !MODIFIED(rect),
160 "rectangle should be empty or NOT modified got %d,%d-%d,%d\n",
161 rect.left, rect.top, rect.right, rect.bottom );
162 if (conform_xp)
163 ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
164 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
166 SetRect( &rect, 10,10, 100, 100);
167 heightcheck = textheight = DrawTextExA(hdc, NULL, 0, &rect, DT_CALCRECT, NULL );
168 ok( !EMPTY(rect) && !MODIFIED(rect),
169 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
170 if (conform_xp)
171 ok(textheight==0,"Got textheight from DrawTextExA\n");
173 SetRect( &rect, 10,10, 100, 100);
174 textheight = DrawTextA(hdc, NULL, 0, &rect, DT_CALCRECT);
175 ok( !EMPTY(rect) && !MODIFIED(rect),
176 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
177 rect.left, rect.top, rect.right, rect.bottom );
178 if (conform_xp)
179 ok(textheight==0,"Got textheight from DrawTextA\n");
180 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
182 /* DT_SINGLELINE tests */
184 SetRect( &rect, 10,10, 100, 100);
185 heightcheck = textheight = DrawTextExA(hdc, text, 0, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
186 ok( !EMPTY(rect) && !MODIFIED(rect),
187 "rectangle should NOT be empty got %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
188 if (conform_xp)
189 ok(textheight==0,"Got textheight from DrawTextExA\n");
191 SetRect( &rect, 10,10, 100, 100);
192 textheight = DrawTextA(hdc, text, 0, &rect, DT_CALCRECT|DT_SINGLELINE);
193 ok( !EMPTY(rect) && !MODIFIED(rect),
194 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
195 rect.left, rect.top, rect.right, rect.bottom );
196 if (conform_xp)
197 ok(textheight==0,"Got textheight from DrawTextA\n");
198 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
200 SetRect( &rect, 10,10, 100, 100);
201 SetLastError( 0);
202 heightcheck = textheight = DrawTextExA(hdc, emptystring, -1, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
203 ok( !EMPTY(rect) && MODIFIED(rect),
204 "rectangle should be modified got %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
205 ok(textheight!=0,"Failed to get textheight from DrawTextExA\n");
207 SetRect( &rect, 10,10, 100, 100);
208 textheight = DrawTextA(hdc, emptystring, -1, &rect, DT_CALCRECT|DT_SINGLELINE);
209 ok( !EMPTY(rect) && MODIFIED (rect),
210 "rectangle should be modified got %d,%d-%d,%d\n",
211 rect.left, rect.top, rect.right, rect.bottom );
212 ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
213 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
215 SetRect( &rect, 10,10, 100, 100);
216 SetLastError( 0);
217 heightcheck = textheight = DrawTextExA(hdc, NULL, -1, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
218 ok( (!EMPTY(rect) && MODIFIED(rect)) || !MODIFIED(rect),
219 "rectangle should be modified got %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
220 if (conform_xp)
221 ok(textheight!=0,"Failed to get textheight from DrawTextExA\n");
223 SetRect( &rect, 10,10, 100, 100);
224 textheight = DrawTextA(hdc, NULL, -1, &rect, DT_CALCRECT|DT_SINGLELINE);
225 ok( (!EMPTY(rect) && MODIFIED(rect)) || !MODIFIED(rect),
226 "rectangle should be modified got %d,%d-%d,%d\n",
227 rect.left, rect.top, rect.right, rect.bottom );
228 if (conform_xp)
229 ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
230 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
232 SetRect( &rect, 10,10, 100, 100);
233 heightcheck = textheight = DrawTextExA(hdc, NULL, 0, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
234 ok( !EMPTY(rect) && !MODIFIED(rect),
235 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
236 if (conform_xp)
237 ok(textheight==0,"Got textheight from DrawTextExA\n");
239 SetRect( &rect, 10,10, 100, 100);
240 textheight = DrawTextA(hdc, NULL, 0, &rect, DT_CALCRECT|DT_SINGLELINE);
241 ok( !EMPTY(rect) && !MODIFIED(rect),
242 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
243 rect.left, rect.top, rect.right, rect.bottom );
244 if (conform_xp)
245 ok(textheight==0,"Got textheight from DrawTextA\n");
246 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
248 /* further tests with 0 count, NULL and empty strings */
249 heightcheck = textheight = DrawTextA(hdc, text, 0, &rect, 0);
250 if (conform_xp)
251 ok(textheight==0,"Got textheight from DrawTextA\n");
252 textheight = DrawTextExA(hdc, text, 0, &rect, 0, NULL );
253 if (conform_xp)
254 ok(textheight==0,"Got textheight from DrawTextExA\n");
255 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
256 heightcheck = textheight = DrawTextA(hdc, emptystring, 0, &rect, 0);
257 if (conform_xp)
258 ok(textheight==0,"Got textheight from DrawTextA\n");
259 textheight = DrawTextExA(hdc, emptystring, 0, &rect, 0, NULL );
260 if (conform_xp)
261 ok(textheight==0,"Got textheight from DrawTextExA\n");
262 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
263 heightcheck = textheight = DrawTextA(hdc, NULL, 0, &rect, 0);
264 if (conform_xp)
265 ok(textheight==0,"Got textheight from DrawTextA\n");
266 textheight = DrawTextExA(hdc, NULL, 0, &rect, 0, NULL );
267 if (conform_xp)
268 ok(textheight==0,"Got textheight from DrawTextExA\n");
269 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
270 heightcheck = textheight = DrawTextA(hdc, emptystring, -1, &rect, 0);
271 ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
272 textheight = DrawTextExA(hdc, emptystring, -1, &rect, 0, NULL );
273 ok(textheight!=0,"Failed to get textheight from DrawTextExA\n");
274 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
275 heightcheck = textheight = DrawTextA(hdc, NULL, -1, &rect, 0);
276 if (conform_xp)
277 ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
278 textheight = DrawTextExA(hdc, NULL, -1, &rect, 0, NULL );
279 if (conform_xp)
280 ok(textheight!=0,"Failed to get textheight from DrawTextExA\n");
281 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
282 heightcheck = textheight = DrawTextA(hdc, NULL, 10, &rect, 0);
283 ok(textheight==0,"Got textheight from DrawTextA\n");
284 textheight = DrawTextExA(hdc, NULL, 10, &rect, 0, NULL );
285 ok(textheight==0,"Got textheight from DrawTextA\n");
286 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
289 /* invalid dtp size test */
290 dtp.cbSize = -1; /* Invalid */
291 dtp.uiLengthDrawn = 1337;
292 textheight = DrawTextExA(hdc, text, 0, &rect, 0, &dtp);
293 ok(textheight==0,"Got textheight from DrawTextExA\n");
294 ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
295 dtp.uiLengthDrawn = 1337;
296 textheight = DrawTextExA(hdc, emptystring, 0, &rect, 0, &dtp);
297 ok(textheight==0,"Got textheight from DrawTextExA\n");
298 ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
299 dtp.uiLengthDrawn = 1337;
300 textheight = DrawTextExA(hdc, NULL, 0, &rect, 0, &dtp);
301 ok(textheight==0,"Got textheight from DrawTextExA\n");
302 ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
303 dtp.uiLengthDrawn = 1337;
304 textheight = DrawTextExA(hdc, emptystring, -1, &rect, 0, &dtp);
305 ok(textheight==0,"Got textheight from DrawTextExA\n");
306 ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
307 dtp.uiLengthDrawn = 1337;
308 textheight = DrawTextExA(hdc, NULL, -1, &rect, 0, &dtp);
309 ok(textheight==0,"Got textheight from DrawTextExA\n");
310 ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
312 /* Margin calculations */
313 dtp.cbSize = sizeof(dtp);
314 dtp.iLeftMargin = 0;
315 dtp.iRightMargin = 0;
316 SetRect( &rect, 0, 0, 0, 0);
317 DrawTextExA(hdc, text, -1, &rect, DT_CALCRECT, &dtp);
318 textlen = rect.right; /* Width without margin */
319 dtp.iLeftMargin = 8;
320 SetRect( &rect, 0, 0, 0, 0);
321 DrawTextExA(hdc, text, -1, &rect, DT_CALCRECT, &dtp);
322 ok(rect.right==dtp.iLeftMargin+textlen ,"Incorrect left margin calculated rc(%d,%d)\n", rect.left, rect.right);
323 dtp.iLeftMargin = 0;
324 dtp.iRightMargin = 8;
325 SetRect( &rect, 0, 0, 0, 0);
326 DrawTextExA(hdc, text, -1, &rect, DT_CALCRECT, &dtp);
327 ok(rect.right==dtp.iRightMargin+textlen ,"Incorrect right margin calculated rc(%d,%d)\n", rect.left, rect.right);
329 /* Wide char versions */
330 SetRect( &rect, 10,10, 100, 100);
331 SetLastError( 0);
332 heightcheck = textheight = DrawTextExW(hdc, textW, 0, &rect, DT_CALCRECT, NULL );
333 if( GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) {
334 ok( !EMPTY(rect) && !MODIFIED(rect),
335 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
336 rect.left, rect.top, rect.right, rect.bottom );
337 ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
339 SetRect( &rect, 10,10, 100, 100);
340 textheight = DrawTextW(hdc, textW, 0, &rect, DT_CALCRECT);
341 ok( !EMPTY(rect) && !MODIFIED(rect),
342 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
343 rect.left, rect.top, rect.right, rect.bottom );
344 ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
345 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
347 SetRect( &rect, 10,10, 100, 100);
348 heightcheck = textheight = DrawTextExW(hdc, emptystringW, -1, &rect, DT_CALCRECT, NULL );
349 ok( EMPTY(rect),
350 "rectangle should be empty got %d,%d-%d,%d\n",
351 rect.left, rect.top, rect.right, rect.bottom );
352 ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
354 SetRect( &rect, 10,10, 100, 100);
355 textheight = DrawTextW(hdc, emptystringW, -1, &rect, DT_CALCRECT);
356 ok( EMPTY(rect),
357 "rectangle should be empty got %d,%d-%d,%d\n",
358 rect.left, rect.top, rect.right, rect.bottom );
359 ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
360 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
362 SetRect( &rect, 10,10, 100, 100);
363 heightcheck = textheight = DrawTextExW(hdc, NULL, 0, &rect, DT_CALCRECT, NULL );
364 ok( !EMPTY(rect) && !MODIFIED(rect),
365 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
366 rect.left, rect.top, rect.right, rect.bottom );
367 if (textheight) /* windows 2000 */
369 if (conform_xp)
370 win_skip("XP conformity failed, skipping XP tests. Probably win 2000\n");
371 conform_xp = FALSE;
373 else
374 ok(textheight==0,"Got textheight from DrawTextExW\n");
376 SetRect( &rect, 10,10, 100, 100);
377 textheight = DrawTextW(hdc, NULL, 0, &rect, DT_CALCRECT);
378 ok( !EMPTY(rect) && !MODIFIED(rect),
379 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
380 rect.left, rect.top, rect.right, rect.bottom );
381 if (conform_xp)
382 ok(textheight==0,"Got textheight from DrawTextW\n");
383 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
385 if (conform_xp) {
386 /* Crashes on NT4 */
387 SetRect( &rect, 10,10, 100, 100);
388 heightcheck = textheight = DrawTextExW(hdc, NULL, -1, &rect, DT_CALCRECT, NULL );
389 ok( !EMPTY(rect) && !MODIFIED(rect),
390 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
391 rect.left, rect.top, rect.right, rect.bottom );
392 ok(textheight==0,"Got textheight from DrawTextExW\n");
394 SetRect( &rect, 10,10, 100, 100);
395 textheight = DrawTextW(hdc, NULL, -1, &rect, DT_CALCRECT);
396 ok( !EMPTY(rect) && !MODIFIED(rect),
397 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
398 rect.left, rect.top, rect.right, rect.bottom );
399 ok(textheight==0,"Got textheight from DrawTextW\n");
400 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
404 /* DT_SINGLELINE tests */
406 heightcheck = textheight = DrawTextExW(hdc, textW, 0, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
407 ok( !EMPTY(rect) && !MODIFIED(rect),
408 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
409 rect.left, rect.top, rect.right, rect.bottom );
410 ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
412 SetRect( &rect, 10,10, 100, 100);
413 textheight = DrawTextW(hdc, textW, 0, &rect, DT_CALCRECT|DT_SINGLELINE);
414 ok( !EMPTY(rect) && !MODIFIED(rect),
415 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
416 rect.left, rect.top, rect.right, rect.bottom );
417 ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
418 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
420 SetRect( &rect, 10,10, 100, 100);
421 heightcheck = textheight = DrawTextExW(hdc, emptystringW, -1, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
422 ok( !EMPTY(rect) && MODIFIED(rect),
423 "rectangle should be modified got %d,%d-%d,%d\n",
424 rect.left, rect.top, rect.right, rect.bottom );
425 ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
427 SetRect( &rect, 10,10, 100, 100);
428 textheight = DrawTextW(hdc, emptystringW, -1, &rect, DT_CALCRECT|DT_SINGLELINE);
429 ok( !EMPTY(rect) && MODIFIED(rect),
430 "rectangle should be modified got %d,%d-%d,%d\n",
431 rect.left, rect.top, rect.right, rect.bottom );
432 ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
433 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
435 if (conform_xp) {
436 /* Crashes on NT4 */
437 SetRect( &rect, 10,10, 100, 100);
438 heightcheck = textheight = DrawTextExW(hdc, NULL, -1, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
439 ok( !EMPTY(rect) && !MODIFIED(rect),
440 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
441 rect.left, rect.top, rect.right, rect.bottom );
442 ok(textheight==0,"Got textheight from DrawTextExW\n");
444 SetRect( &rect, 10,10, 100, 100);
445 textheight = DrawTextW(hdc, NULL, -1, &rect, DT_CALCRECT|DT_SINGLELINE);
446 ok( !EMPTY(rect) && !MODIFIED(rect),
447 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
448 rect.left, rect.top, rect.right, rect.bottom );
449 ok(textheight==0,"Got textheight from DrawTextW\n");
450 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
453 SetRect( &rect, 10,10, 100, 100);
454 heightcheck = textheight = DrawTextExW(hdc, NULL, 0, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
455 ok( !EMPTY(rect) && !MODIFIED(rect),
456 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
457 rect.left, rect.top, rect.right, rect.bottom );
458 if (conform_xp)
459 ok(textheight==0,"Got textheight from DrawTextExW\n");
461 SetRect( &rect, 10,10, 100, 100);
462 textheight = DrawTextW(hdc, NULL, 0, &rect, DT_CALCRECT|DT_SINGLELINE);
463 ok( !EMPTY(rect) && !MODIFIED(rect),
464 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
465 rect.left, rect.top, rect.right, rect.bottom );
466 if (conform_xp)
467 ok(textheight==0,"Got textheight from DrawTextW\n");
468 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
470 /* further tests with NULL and empty strings */
471 heightcheck = textheight = DrawTextW(hdc, textW, 0, &rect, 0);
472 ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
473 textheight = DrawTextExW(hdc, textW, 0, &rect, 0, NULL );
474 ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
475 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
476 heightcheck = textheight = DrawTextW(hdc, emptystringW, 0, &rect, 0);
477 ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
478 textheight = DrawTextExW(hdc, emptystringW, 0, &rect, 0, NULL );
479 ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
480 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
481 heightcheck = textheight = DrawTextW(hdc, NULL, 0, &rect, 0);
482 if (conform_xp)
483 ok(textheight==0,"Got textheight from DrawTextW\n");
484 textheight = DrawTextExW(hdc, NULL, 0, &rect, 0, NULL );
485 if (conform_xp)
486 ok(textheight==0,"Got textheight from DrawTextExW\n");
487 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
488 heightcheck = textheight = DrawTextW(hdc, emptystringW, -1, &rect, 0);
489 ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
490 textheight = DrawTextExW(hdc, emptystringW, -1, &rect, 0, NULL );
491 ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
492 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
493 if (conform_xp) {
494 /* Crashes on NT4 */
495 heightcheck = textheight = DrawTextW(hdc, NULL, -1, &rect, 0);
496 ok(textheight==0,"Got textheight from DrawTextW\n");
497 textheight = DrawTextExW(hdc, NULL, -1, &rect, 0, NULL );
498 ok(textheight==0,"Got textheight from DrawTextExW\n");
499 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
500 heightcheck = textheight = DrawTextW(hdc, NULL, 10, &rect, 0);
501 ok(textheight==0,"Got textheight from DrawTextW\n");
502 textheight = DrawTextExW(hdc, NULL, 10, &rect, 0, NULL );
503 ok(textheight==0,"Got textheight from DrawTextW\n");
504 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
507 dtp.cbSize = -1; /* Invalid */
508 dtp.uiLengthDrawn = 1337;
509 textheight = DrawTextExW(hdc, textW, 0, &rect, 0, &dtp);
510 ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
511 ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
512 dtp.uiLengthDrawn = 1337;
513 textheight = DrawTextExW(hdc, emptystringW, 0, &rect, 0, &dtp);
514 if (conform_xp)
515 ok(textheight==0,"Got textheight from DrawTextExW\n");
516 ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
517 dtp.uiLengthDrawn = 1337;
518 textheight = DrawTextExW(hdc, NULL, 0, &rect, 0, &dtp);
519 if (conform_xp)
520 ok(textheight==0,"Got textheight from DrawTextExW\n");
521 ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
522 dtp.uiLengthDrawn = 1337;
523 textheight = DrawTextExW(hdc, emptystringW, -1, &rect, 0, &dtp);
524 ok(textheight==0,"Got textheight from DrawTextExW\n");
525 ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
526 if (conform_xp) {
527 /* Crashes on NT4 */
528 dtp.uiLengthDrawn = 1337;
529 textheight = DrawTextExW(hdc, NULL, -1, &rect, 0, &dtp);
530 ok(textheight==0,"Got textheight from DrawTextExW\n");
531 ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
535 /* More test cases from bug 12226 */
536 SetRect(&rect, 0, 0, 0, 0);
537 textheight = DrawTextA(hdc, emptystring, -1, &rect, DT_CALCRECT | DT_LEFT | DT_SINGLELINE);
538 ok(textheight, "DrawTextA error %u\n", GetLastError());
539 ok(0 == rect.left, "expected 0, got %d\n", rect.left);
540 ok(0 == rect.right, "expected 0, got %d\n", rect.right);
541 ok(0 == rect.top, "expected 0, got %d\n", rect.top);
542 ok(rect.bottom, "rect.bottom should not be 0\n");
544 SetRect(&rect, 0, 0, 0, 0);
545 textheight = DrawTextW(hdc, emptystringW, -1, &rect, DT_CALCRECT | DT_LEFT | DT_SINGLELINE);
546 if (!textheight && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
548 win_skip( "DrawTextW not implemented\n" );
550 else
552 ok(textheight, "DrawTextW error %u\n", GetLastError());
553 ok(0 == rect.left, "expected 0, got %d\n", rect.left);
554 ok(0 == rect.right, "expected 0, got %d\n", rect.right);
555 ok(0 == rect.top, "expected 0, got %d\n", rect.top);
556 ok(rect.bottom, "rect.bottom should not be 0\n");
559 SelectObject(hdc, hOldFont);
560 ret = DeleteObject(hFont);
561 ok( ret, "DeleteObject error %u\n", GetLastError());
563 /* Clean up */
564 ret = ReleaseDC(hwnd, hdc);
565 ok( ret, "ReleaseDC error %u\n", GetLastError());
566 ret = DestroyWindow(hwnd);
567 ok( ret, "DestroyWindow error %u\n", GetLastError());
570 /* replace tabs by \t */
571 static void strfmt( const char *str, char *strout)
573 unsigned int i,j ;
574 for(i=0,j=0;i<=strlen(str);i++,j++)
575 if((strout[j]=str[i])=='\t') {
576 strout[j++]='\\';
577 strout[j]='t';
582 #define TABTEST( tabval, tabcount, string, _exp) \
583 { int i,x_act, x_exp; char strdisp[64];\
584 for(i=0;i<8;i++) tabs[i]=(i+1)*(tabval); \
585 extent = GetTabbedTextExtentA( hdc, string, strlen( string), (tabcount), tabs); \
586 strfmt( string, strdisp); \
587 /* trace( "Extent is %08lx\n", extent); */\
588 x_act = LOWORD( extent); \
589 x_exp = (_exp); \
590 ok( x_act == x_exp, "Test case \"%s\". Text extent is %d, expected %d tab %d tabcount %d\n", \
591 strdisp, x_act, x_exp, tabval, tabcount); \
595 static void test_TabbedText(void)
597 HWND hwnd;
598 HDC hdc;
599 BOOL ret;
600 TEXTMETRICA tm;
601 DWORD extent;
602 INT tabs[8], cx, cy, tab, tabcount,t,align;
604 /* Initialization */
605 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
606 0, 0, 200, 200, 0, 0, 0, NULL);
607 ok(hwnd != 0, "CreateWindowExA error %u\n", GetLastError());
608 hdc = GetDC(hwnd);
609 ok(hdc != 0, "GetDC error %u\n", GetLastError());
611 ret = GetTextMetricsA( hdc, &tm);
612 ok( ret, "GetTextMetrics error %u\n", GetLastError());
614 extent = GetTabbedTextExtentA( hdc, "x", 0, 1, tabs);
615 ok( extent == 0, "GetTabbedTextExtentA returned non-zero on nCount == 0\n");
617 extent = GetTabbedTextExtentA( hdc, "x", 1, 1, tabs);
618 cx = LOWORD( extent);
619 cy = HIWORD( extent);
620 trace( "cx is %d cy is %d\n", cx, cy);
622 align=1;
623 for( t=-1; t<=1; t++) { /* slightly adjust the 4 char tabstop, to
624 catch the one off errors */
625 tab = (cx *4 + t);
626 /* test the special case tabcount =1 and the general array (80 of tabs */
627 for( tabcount = 1; tabcount <= 8; tabcount +=7) {
628 TABTEST( align * tab, tabcount, "\t", tab)
629 TABTEST( align * tab, tabcount, "xxx\t", tab)
630 TABTEST( align * tab, tabcount, "\tx", tab+cx)
631 TABTEST( align * tab, tabcount, "\t\t", tab*2)
632 TABTEST( align * tab, tabcount, "\tx\t", tab*2)
633 TABTEST( align * tab, tabcount, "x\tx", tab+cx)
634 TABTEST( align * tab, tabcount, "xx\tx", tab+cx)
635 TABTEST( align * tab, tabcount, "xxx\tx", tab+cx)
636 TABTEST( align * tab, tabcount, "xxxx\tx", t>0 ? tab + cx : 2*tab+cx)
637 TABTEST( align * tab, tabcount, "xxxxx\tx", 2*tab+cx)
640 align=-1;
641 for( t=-1; t<=1; t++) { /* slightly adjust the 4 char tabstop, to
642 catch the one off errors */
643 tab = (cx *4 + t);
644 /* test the special case tabcount =1 and the general array (8) of tabs */
645 for( tabcount = 1; tabcount <= 8; tabcount +=7) {
646 TABTEST( align * tab, tabcount, "\t", tab)
647 TABTEST( align * tab, tabcount, "xxx\t", tab)
648 TABTEST( align * tab, tabcount, "\tx", tab)
649 TABTEST( align * tab, tabcount, "\t\t", tab*2)
650 TABTEST( align * tab, tabcount, "\tx\t", tab*2)
651 TABTEST( align * tab, tabcount, "x\tx", tab)
652 TABTEST( align * tab, tabcount, "xx\tx", tab)
653 TABTEST( align * tab, tabcount, "xxx\tx", 4 * cx >= tab ? 2*tab :tab)
654 TABTEST( align * tab, tabcount, "xxxx\tx", 2*tab)
655 TABTEST( align * tab, tabcount, "xxxxx\tx", 2*tab)
659 ReleaseDC( hwnd, hdc );
660 DestroyWindow( hwnd );
663 static void test_DrawState(void)
665 static const char text[] = "Sample text string";
666 HWND hwnd;
667 HDC hdc;
668 BOOL ret;
670 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
671 0, 0, 200, 200, 0, 0, 0, NULL);
672 assert(hwnd);
674 hdc = GetDC(hwnd);
675 assert(hdc);
677 SetLastError(0xdeadbeef);
678 ret = DrawState(hdc, GetStockObject(DKGRAY_BRUSH), NULL, (LPARAM)text, strlen(text),
679 0, 0, 10, 10, DST_TEXT);
680 ok(ret, "DrawState error %u\n", GetLastError());
682 SetLastError(0xdeadbeef);
683 ret = DrawState(hdc, GetStockObject(DKGRAY_BRUSH), NULL, (LPARAM)text, 0,
684 0, 0, 10, 10, DST_TEXT);
685 ok(ret, "DrawState error %u\n", GetLastError());
687 SetLastError(0xdeadbeef);
688 ret = DrawState(hdc, GetStockObject(DKGRAY_BRUSH), NULL, 0, strlen(text),
689 0, 0, 10, 10, DST_TEXT);
690 ok(!ret || broken(ret) /* win98 */, "DrawState succeeded\n");
691 ok(GetLastError() == 0xdeadbeef, "not expected error %u\n", GetLastError());
693 SetLastError(0xdeadbeef);
694 ret = DrawState(hdc, GetStockObject(DKGRAY_BRUSH), NULL, 0, 0,
695 0, 0, 10, 10, DST_TEXT);
696 ok(!ret || broken(ret) /* win98 */, "DrawState succeeded\n");
697 ok(GetLastError() == 0xdeadbeef, "not expected error %u\n", GetLastError());
699 ReleaseDC(hwnd, hdc);
700 DestroyWindow(hwnd);
703 START_TEST(text)
705 test_TabbedText();
706 test_DrawTextCalcRect();
707 test_DrawState();