push 9bfdf186dc6a237cd7f58f0ee2ef677e81617b1d
[wine/hacks.git] / dlls / user32 / tests / text.c
blobfc554ae363265461ea5e46bef08e84cc93003b56
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 SAME(rect) (rect.left = 10 && rect.right == 100 && rect.top == 10 && rect.bottom == 100)
32 #define EMPTY(rect) (rect.left == rect.right && rect.bottom == rect.top)
34 static void test_DrawTextCalcRect(void)
36 HWND hwnd;
37 HDC hdc;
38 HFONT hFont, hOldFont;
39 LOGFONTA lf;
40 static CHAR text[] = "Example text for testing DrawText in "
41 "MM_HIENGLISH mode";
42 static WCHAR textW[] = {'W','i','d','e',' ','c','h','a','r',' ',
43 's','t','r','i','n','g','\0'};
44 static CHAR emptystring[] = "";
45 static WCHAR emptystringW[] = { 0 };
46 INT textlen, textheight, heightcheck;
47 RECT rect = { 0, 0, 100, 0 };
48 BOOL ret;
49 DRAWTEXTPARAMS dtp;
50 BOOL conform_xp = TRUE;
52 /* Initialization */
53 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
54 0, 0, 200, 200, 0, 0, 0, NULL);
55 ok(hwnd != 0, "CreateWindowExA error %u\n", GetLastError());
56 hdc = GetDC(hwnd);
57 ok(hdc != 0, "GetDC error %u\n", GetLastError());
58 trace("hdc %p\n", hdc);
59 textlen = lstrlenA(text);
61 /* LOGFONT initialization */
62 memset(&lf, 0, sizeof(lf));
63 lf.lfCharSet = ANSI_CHARSET;
64 lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
65 lf.lfWeight = FW_DONTCARE;
66 lf.lfHeight = 0; /* mapping mode dependent */
67 lf.lfQuality = DEFAULT_QUALITY;
68 lstrcpyA(lf.lfFaceName, "Arial");
70 /* DrawText in MM_HIENGLISH with DT_CALCRECT */
71 SetMapMode(hdc, MM_HIENGLISH);
72 lf.lfHeight = 100 * 9 / 72; /* 9 point */
73 hFont = CreateFontIndirectA(&lf);
74 ok(hFont != 0, "CreateFontIndirectA error %u\n",
75 GetLastError());
76 hOldFont = SelectObject(hdc, hFont);
78 textheight = DrawTextA(hdc, text, textlen, &rect, DT_CALCRECT |
79 DT_EXTERNALLEADING | DT_WORDBREAK | DT_NOCLIP | DT_LEFT |
80 DT_NOPREFIX);
81 ok( textheight, "DrawTextA error %u\n", GetLastError());
83 trace("MM_HIENGLISH rect.bottom %d\n", rect.bottom);
84 todo_wine ok(rect.bottom < 0, "In MM_HIENGLISH, DrawText with "
85 "DT_CALCRECT should return a negative rectangle bottom. "
86 "(bot=%d)\n", rect.bottom);
88 SelectObject(hdc, hOldFont);
89 ret = DeleteObject(hFont);
90 ok( ret, "DeleteObject error %u\n", GetLastError());
93 /* DrawText in MM_TEXT with DT_CALCRECT */
94 SetMapMode(hdc, MM_TEXT);
95 lf.lfHeight = -MulDiv(9, GetDeviceCaps(hdc,
96 LOGPIXELSY), 72); /* 9 point */
97 hFont = CreateFontIndirectA(&lf);
98 ok(hFont != 0, "CreateFontIndirectA error %u\n",
99 GetLastError());
100 hOldFont = SelectObject(hdc, hFont);
102 textheight = DrawTextA(hdc, text, textlen, &rect, DT_CALCRECT |
103 DT_EXTERNALLEADING | DT_WORDBREAK | DT_NOCLIP | DT_LEFT |
104 DT_NOPREFIX);
105 ok( textheight, "DrawTextA error %u\n", GetLastError());
107 trace("MM_TEXT rect.bottom %d\n", rect.bottom);
108 ok(rect.bottom > 0, "In MM_TEXT, DrawText with DT_CALCRECT "
109 "should return a positive rectangle bottom. (bot=%d)\n",
110 rect.bottom);
112 /* empty or null text should in some cases calc an empty rectangle */
114 SetRect( &rect, 10,10, 100, 100);
115 heightcheck = textheight = DrawTextExA(hdc, text, 0, &rect, DT_CALCRECT, NULL );
116 ok( !EMPTY(rect) && !MODIFIED(rect),
117 "rectangle should NOT be empty got %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
118 if (textheight != 0) /* Windows 98 */
120 win_skip("XP conformity failed, skipping XP tests. Probably win9x\n");
121 conform_xp = FALSE;
123 else
124 ok(textheight==0,"Got textheight from DrawTextExA\n");
126 SetRect( &rect, 10,10, 100, 100);
127 textheight = DrawTextA(hdc, text, 0, &rect, DT_CALCRECT);
128 ok( !EMPTY(rect) && !MODIFIED(rect),
129 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
130 rect.left, rect.top, rect.right, rect.bottom );
131 if (conform_xp)
132 ok(textheight==0,"Got textheight from DrawTextA\n");
133 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
135 SetRect( &rect, 10,10, 100, 100);
136 SetLastError( 0);
137 heightcheck = textheight = DrawTextExA(hdc, emptystring, -1, &rect, DT_CALCRECT, NULL );
138 ok( EMPTY(rect),
139 "rectangle should be empty got %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
140 ok(textheight!=0,"Failed to get textheight from DrawTextExA\n");
142 SetRect( &rect, 10,10, 100, 100);
143 textheight = DrawTextA(hdc, emptystring, -1, &rect, DT_CALCRECT);
144 ok( EMPTY(rect),
145 "rectangle should be empty got %d,%d-%d,%d\n",
146 rect.left, rect.top, rect.right, rect.bottom );
147 ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
148 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
150 SetRect( &rect, 10,10, 100, 100);
151 SetLastError( 0);
152 heightcheck = textheight = DrawTextExA(hdc, NULL, -1, &rect, DT_CALCRECT, NULL );
153 ok( EMPTY(rect) || !MODIFIED(rect),
154 "rectangle should be empty or not modified got %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
155 if (!textheight) /* Windows NT 4 */
157 if (conform_xp)
158 win_skip("XP conformity failed, skipping XP tests. Probably winNT\n");
159 conform_xp = FALSE;
161 else
162 ok(textheight!=0,"Failed to get textheight from DrawTextExA\n");
164 SetRect( &rect, 10,10, 100, 100);
165 textheight = DrawTextA(hdc, NULL, -1, &rect, DT_CALCRECT);
166 ok( EMPTY(rect) || !MODIFIED(rect),
167 "rectangle should be empty or NOT modified got %d,%d-%d,%d\n",
168 rect.left, rect.top, rect.right, rect.bottom );
169 if (conform_xp)
170 ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
171 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
173 SetRect( &rect, 10,10, 100, 100);
174 heightcheck = textheight = DrawTextExA(hdc, NULL, 0, &rect, DT_CALCRECT, NULL );
175 ok( !EMPTY(rect) && !MODIFIED(rect),
176 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
177 if (conform_xp)
178 ok(textheight==0,"Got textheight from DrawTextExA\n");
180 SetRect( &rect, 10,10, 100, 100);
181 textheight = DrawTextA(hdc, NULL, 0, &rect, DT_CALCRECT);
182 ok( !EMPTY(rect) && !MODIFIED(rect),
183 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
184 rect.left, rect.top, rect.right, rect.bottom );
185 if (conform_xp)
186 ok(textheight==0,"Got textheight from DrawTextA\n");
187 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
189 /* DT_SINGLELINE tests */
191 SetRect( &rect, 10,10, 100, 100);
192 heightcheck = textheight = DrawTextExA(hdc, text, 0, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
193 ok( !EMPTY(rect) && !MODIFIED(rect),
194 "rectangle should NOT be empty got %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
195 if (conform_xp)
196 ok(textheight==0,"Got textheight from DrawTextExA\n");
198 SetRect( &rect, 10,10, 100, 100);
199 textheight = DrawTextA(hdc, text, 0, &rect, DT_CALCRECT|DT_SINGLELINE);
200 ok( !EMPTY(rect) && !MODIFIED(rect),
201 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
202 rect.left, rect.top, rect.right, rect.bottom );
203 if (conform_xp)
204 ok(textheight==0,"Got textheight from DrawTextA\n");
205 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
207 SetRect( &rect, 10,10, 100, 100);
208 SetLastError( 0);
209 heightcheck = textheight = DrawTextExA(hdc, emptystring, -1, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
210 ok( !EMPTY(rect) && MODIFIED(rect),
211 "rectangle should be modified got %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
212 ok(textheight!=0,"Failed to get textheight from DrawTextExA\n");
214 SetRect( &rect, 10,10, 100, 100);
215 textheight = DrawTextA(hdc, emptystring, -1, &rect, DT_CALCRECT|DT_SINGLELINE);
216 ok( !EMPTY(rect) && MODIFIED (rect),
217 "rectangle should be modified got %d,%d-%d,%d\n",
218 rect.left, rect.top, rect.right, rect.bottom );
219 ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
220 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
222 SetRect( &rect, 10,10, 100, 100);
223 SetLastError( 0);
224 heightcheck = textheight = DrawTextExA(hdc, NULL, -1, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
225 ok( (!EMPTY(rect) && MODIFIED(rect)) || !MODIFIED(rect),
226 "rectangle should be modified got %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
227 if (conform_xp)
228 ok(textheight!=0,"Failed to get textheight from DrawTextExA\n");
230 SetRect( &rect, 10,10, 100, 100);
231 textheight = DrawTextA(hdc, NULL, -1, &rect, DT_CALCRECT|DT_SINGLELINE);
232 ok( (!EMPTY(rect) && MODIFIED(rect)) || !MODIFIED(rect),
233 "rectangle should be modified got %d,%d-%d,%d\n",
234 rect.left, rect.top, rect.right, rect.bottom );
235 if (conform_xp)
236 ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
237 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
239 SetRect( &rect, 10,10, 100, 100);
240 heightcheck = textheight = DrawTextExA(hdc, NULL, 0, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
241 ok( !EMPTY(rect) && !MODIFIED(rect),
242 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
243 if (conform_xp)
244 ok(textheight==0,"Got textheight from DrawTextExA\n");
246 SetRect( &rect, 10,10, 100, 100);
247 textheight = DrawTextA(hdc, NULL, 0, &rect, DT_CALCRECT|DT_SINGLELINE);
248 ok( !EMPTY(rect) && !MODIFIED(rect),
249 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
250 rect.left, rect.top, rect.right, rect.bottom );
251 if (conform_xp)
252 ok(textheight==0,"Got textheight from DrawTextA\n");
253 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
255 /* further tests with 0 count, NULL and empty strings */
256 heightcheck = textheight = DrawTextA(hdc, text, 0, &rect, 0);
257 if (conform_xp)
258 ok(textheight==0,"Got textheight from DrawTextA\n");
259 textheight = DrawTextExA(hdc, text, 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, emptystring, 0, &rect, 0);
264 if (conform_xp)
265 ok(textheight==0,"Got textheight from DrawTextA\n");
266 textheight = DrawTextExA(hdc, emptystring, 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, NULL, 0, &rect, 0);
271 if (conform_xp)
272 ok(textheight==0,"Got textheight from DrawTextA\n");
273 textheight = DrawTextExA(hdc, NULL, 0, &rect, 0, NULL );
274 if (conform_xp)
275 ok(textheight==0,"Got textheight from DrawTextExA\n");
276 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
277 heightcheck = textheight = DrawTextA(hdc, emptystring, -1, &rect, 0);
278 ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
279 textheight = DrawTextExA(hdc, emptystring, -1, &rect, 0, NULL );
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, -1, &rect, 0);
283 if (conform_xp)
284 ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
285 textheight = DrawTextExA(hdc, NULL, -1, &rect, 0, NULL );
286 if (conform_xp)
287 ok(textheight!=0,"Failed to get textheight from DrawTextExA\n");
288 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
289 heightcheck = textheight = DrawTextA(hdc, NULL, 10, &rect, 0);
290 ok(textheight==0,"Got textheight from DrawTextA\n");
291 textheight = DrawTextExA(hdc, NULL, 10, &rect, 0, NULL );
292 ok(textheight==0,"Got textheight from DrawTextA\n");
293 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
296 /* invalid dtp size test */
297 dtp.cbSize = -1; /* Invalid */
298 dtp.uiLengthDrawn = 1337;
299 textheight = DrawTextExA(hdc, text, 0, &rect, 0, &dtp);
300 ok(textheight==0,"Got textheight from DrawTextExA\n");
301 ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
302 dtp.uiLengthDrawn = 1337;
303 textheight = DrawTextExA(hdc, emptystring, 0, &rect, 0, &dtp);
304 ok(textheight==0,"Got textheight from DrawTextExA\n");
305 ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
306 dtp.uiLengthDrawn = 1337;
307 textheight = DrawTextExA(hdc, NULL, 0, &rect, 0, &dtp);
308 ok(textheight==0,"Got textheight from DrawTextExA\n");
309 ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
310 dtp.uiLengthDrawn = 1337;
311 textheight = DrawTextExA(hdc, emptystring, -1, &rect, 0, &dtp);
312 ok(textheight==0,"Got textheight from DrawTextExA\n");
313 ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
314 dtp.uiLengthDrawn = 1337;
315 textheight = DrawTextExA(hdc, NULL, -1, &rect, 0, &dtp);
316 ok(textheight==0,"Got textheight from DrawTextExA\n");
317 ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
319 /* Wide char versions */
320 SetRect( &rect, 10,10, 100, 100);
321 SetLastError( 0);
322 heightcheck = textheight = DrawTextExW(hdc, textW, 0, &rect, DT_CALCRECT, NULL );
323 if( GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) {
324 ok( !EMPTY(rect) && !MODIFIED(rect),
325 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
326 rect.left, rect.top, rect.right, rect.bottom );
327 ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
329 SetRect( &rect, 10,10, 100, 100);
330 textheight = DrawTextW(hdc, textW, 0, &rect, DT_CALCRECT);
331 ok( !EMPTY(rect) && !MODIFIED(rect),
332 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
333 rect.left, rect.top, rect.right, rect.bottom );
334 ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
335 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
337 SetRect( &rect, 10,10, 100, 100);
338 heightcheck = textheight = DrawTextExW(hdc, emptystringW, -1, &rect, DT_CALCRECT, NULL );
339 ok( EMPTY(rect),
340 "rectangle should be empty got %d,%d-%d,%d\n",
341 rect.left, rect.top, rect.right, rect.bottom );
342 ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
344 SetRect( &rect, 10,10, 100, 100);
345 textheight = DrawTextW(hdc, emptystringW, -1, &rect, DT_CALCRECT);
346 ok( EMPTY(rect),
347 "rectangle should be empty got %d,%d-%d,%d\n",
348 rect.left, rect.top, rect.right, rect.bottom );
349 ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
350 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
352 SetRect( &rect, 10,10, 100, 100);
353 heightcheck = textheight = DrawTextExW(hdc, NULL, 0, &rect, DT_CALCRECT, NULL );
354 ok( !EMPTY(rect) && !MODIFIED(rect),
355 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
356 rect.left, rect.top, rect.right, rect.bottom );
357 if (textheight) /* windows 2000 */
359 if (conform_xp)
360 win_skip("XP conformity failed, skipping XP tests. Probably win 2000\n");
361 conform_xp = FALSE;
363 else
364 ok(textheight==0,"Got textheight from DrawTextExW\n");
366 SetRect( &rect, 10,10, 100, 100);
367 textheight = DrawTextW(hdc, NULL, 0, &rect, DT_CALCRECT);
368 ok( !EMPTY(rect) && !MODIFIED(rect),
369 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
370 rect.left, rect.top, rect.right, rect.bottom );
371 if (conform_xp)
372 ok(textheight==0,"Got textheight from DrawTextW\n");
373 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
375 if (conform_xp) {
376 /* Crashes on NT4 */
377 SetRect( &rect, 10,10, 100, 100);
378 heightcheck = textheight = DrawTextExW(hdc, NULL, -1, &rect, DT_CALCRECT, NULL );
379 ok( !EMPTY(rect) && !MODIFIED(rect),
380 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
381 rect.left, rect.top, rect.right, rect.bottom );
382 ok(textheight==0,"Got textheight from DrawTextExW\n");
384 SetRect( &rect, 10,10, 100, 100);
385 textheight = DrawTextW(hdc, NULL, -1, &rect, DT_CALCRECT);
386 ok( !EMPTY(rect) && !MODIFIED(rect),
387 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
388 rect.left, rect.top, rect.right, rect.bottom );
389 ok(textheight==0,"Got textheight from DrawTextW\n");
390 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
394 /* DT_SINGLELINE tests */
396 heightcheck = textheight = DrawTextExW(hdc, textW, 0, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
397 ok( !EMPTY(rect) && !MODIFIED(rect),
398 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
399 rect.left, rect.top, rect.right, rect.bottom );
400 ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
402 SetRect( &rect, 10,10, 100, 100);
403 textheight = DrawTextW(hdc, textW, 0, &rect, DT_CALCRECT|DT_SINGLELINE);
404 ok( !EMPTY(rect) && !MODIFIED(rect),
405 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
406 rect.left, rect.top, rect.right, rect.bottom );
407 ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
408 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
410 SetRect( &rect, 10,10, 100, 100);
411 heightcheck = textheight = DrawTextExW(hdc, emptystringW, -1, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
412 ok( !EMPTY(rect) && MODIFIED(rect),
413 "rectangle should be modified got %d,%d-%d,%d\n",
414 rect.left, rect.top, rect.right, rect.bottom );
415 ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
417 SetRect( &rect, 10,10, 100, 100);
418 textheight = DrawTextW(hdc, emptystringW, -1, &rect, DT_CALCRECT|DT_SINGLELINE);
419 ok( !EMPTY(rect) && MODIFIED(rect),
420 "rectangle should be modified got %d,%d-%d,%d\n",
421 rect.left, rect.top, rect.right, rect.bottom );
422 ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
423 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
425 if (conform_xp) {
426 /* Crashes on NT4 */
427 SetRect( &rect, 10,10, 100, 100);
428 heightcheck = textheight = DrawTextExW(hdc, NULL, -1, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
429 ok( !EMPTY(rect) && !MODIFIED(rect),
430 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
431 rect.left, rect.top, rect.right, rect.bottom );
432 ok(textheight==0,"Got textheight from DrawTextExW\n");
434 SetRect( &rect, 10,10, 100, 100);
435 textheight = DrawTextW(hdc, NULL, -1, &rect, DT_CALCRECT|DT_SINGLELINE);
436 ok( !EMPTY(rect) && !MODIFIED(rect),
437 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
438 rect.left, rect.top, rect.right, rect.bottom );
439 ok(textheight==0,"Got textheight from DrawTextW\n");
440 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
443 SetRect( &rect, 10,10, 100, 100);
444 heightcheck = textheight = DrawTextExW(hdc, NULL, 0, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
445 ok( !EMPTY(rect) && !MODIFIED(rect),
446 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
447 rect.left, rect.top, rect.right, rect.bottom );
448 if (conform_xp)
449 ok(textheight==0,"Got textheight from DrawTextExW\n");
451 SetRect( &rect, 10,10, 100, 100);
452 textheight = DrawTextW(hdc, NULL, 0, &rect, DT_CALCRECT|DT_SINGLELINE);
453 ok( !EMPTY(rect) && !MODIFIED(rect),
454 "rectangle should NOT be empty and NOT modified got %d,%d-%d,%d\n",
455 rect.left, rect.top, rect.right, rect.bottom );
456 if (conform_xp)
457 ok(textheight==0,"Got textheight from DrawTextW\n");
458 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
460 /* further tests with NULL and empty strings */
461 heightcheck = textheight = DrawTextW(hdc, textW, 0, &rect, 0);
462 ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
463 textheight = DrawTextExW(hdc, textW, 0, &rect, 0, NULL );
464 ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
465 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
466 heightcheck = textheight = DrawTextW(hdc, emptystringW, 0, &rect, 0);
467 ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
468 textheight = DrawTextExW(hdc, emptystringW, 0, &rect, 0, NULL );
469 ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
470 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
471 heightcheck = textheight = DrawTextW(hdc, NULL, 0, &rect, 0);
472 if (conform_xp)
473 ok(textheight==0,"Got textheight from DrawTextW\n");
474 textheight = DrawTextExW(hdc, NULL, 0, &rect, 0, NULL );
475 if (conform_xp)
476 ok(textheight==0,"Got textheight from DrawTextExW\n");
477 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
478 heightcheck = textheight = DrawTextW(hdc, emptystringW, -1, &rect, 0);
479 ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
480 textheight = DrawTextExW(hdc, emptystringW, -1, &rect, 0, NULL );
481 ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
482 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
483 if (conform_xp) {
484 /* Crashes on NT4 */
485 heightcheck = textheight = DrawTextW(hdc, NULL, -1, &rect, 0);
486 ok(textheight==0,"Got textheight from DrawTextW\n");
487 textheight = DrawTextExW(hdc, NULL, -1, &rect, 0, NULL );
488 ok(textheight==0,"Got textheight from DrawTextExW\n");
489 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
490 heightcheck = textheight = DrawTextW(hdc, NULL, 10, &rect, 0);
491 ok(textheight==0,"Got textheight from DrawTextW\n");
492 textheight = DrawTextExW(hdc, NULL, 10, &rect, 0, NULL );
493 ok(textheight==0,"Got textheight from DrawTextW\n");
494 ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
497 dtp.cbSize = -1; /* Invalid */
498 dtp.uiLengthDrawn = 1337;
499 textheight = DrawTextExW(hdc, textW, 0, &rect, 0, &dtp);
500 ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
501 ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
502 dtp.uiLengthDrawn = 1337;
503 textheight = DrawTextExW(hdc, emptystringW, 0, &rect, 0, &dtp);
504 if (conform_xp)
505 ok(textheight==0,"Got textheight from DrawTextExW\n");
506 ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
507 dtp.uiLengthDrawn = 1337;
508 textheight = DrawTextExW(hdc, NULL, 0, &rect, 0, &dtp);
509 if (conform_xp)
510 ok(textheight==0,"Got 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, -1, &rect, 0, &dtp);
514 ok(textheight==0,"Got textheight from DrawTextExW\n");
515 ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
516 if (conform_xp) {
517 /* Crashes on NT4 */
518 dtp.uiLengthDrawn = 1337;
519 textheight = DrawTextExW(hdc, NULL, -1, &rect, 0, &dtp);
520 ok(textheight==0,"Got textheight from DrawTextExW\n");
521 ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
525 /* More test cases from bug 12226 */
526 SetRect(&rect, 0, 0, 0, 0);
527 textheight = DrawTextA(hdc, emptystring, -1, &rect, DT_CALCRECT | DT_LEFT | DT_SINGLELINE);
528 ok(textheight, "DrawTextA error %u\n", GetLastError());
529 ok(0 == rect.left, "expected 0, got %d\n", rect.left);
530 ok(0 == rect.right, "expected 0, got %d\n", rect.right);
531 ok(0 == rect.top, "expected 0, got %d\n", rect.top);
532 ok(rect.bottom, "rect.bottom should not be 0\n");
534 SetRect(&rect, 0, 0, 0, 0);
535 textheight = DrawTextW(hdc, emptystringW, -1, &rect, DT_CALCRECT | DT_LEFT | DT_SINGLELINE);
536 if (!textheight && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
538 win_skip( "DrawTextW not implemented\n" );
540 else
542 ok(textheight, "DrawTextW error %u\n", GetLastError());
543 ok(0 == rect.left, "expected 0, got %d\n", rect.left);
544 ok(0 == rect.right, "expected 0, got %d\n", rect.right);
545 ok(0 == rect.top, "expected 0, got %d\n", rect.top);
546 ok(rect.bottom, "rect.bottom should not be 0\n");
549 SelectObject(hdc, hOldFont);
550 ret = DeleteObject(hFont);
551 ok( ret, "DeleteObject error %u\n", GetLastError());
553 /* Clean up */
554 ret = ReleaseDC(hwnd, hdc);
555 ok( ret, "ReleaseDC error %u\n", GetLastError());
556 ret = DestroyWindow(hwnd);
557 ok( ret, "DestroyWindow error %u\n", GetLastError());
560 /* replace tabs by \t */
561 static void strfmt( const char *str, char *strout)
563 unsigned int i,j ;
564 for(i=0,j=0;i<=strlen(str);i++,j++)
565 if((strout[j]=str[i])=='\t') {
566 strout[j++]='\\';
567 strout[j]='t';
572 #define TABTEST( tabval, tabcount, string, _exp) \
573 { int i,x_act, x_exp; char strdisp[64];\
574 for(i=0;i<8;i++) tabs[i]=(i+1)*(tabval); \
575 extent = GetTabbedTextExtentA( hdc, string, strlen( string), (tabcount), tabs); \
576 strfmt( string, strdisp); \
577 /* trace( "Extent is %08lx\n", extent); */\
578 x_act = LOWORD( extent); \
579 x_exp = (_exp); \
580 ok( x_act == x_exp, "Test case \"%s\". Text extent is %d, expected %d tab %d tabcount %d\n", \
581 strdisp, x_act, x_exp, tabval, tabcount); \
585 static void test_TabbedText(void)
587 HWND hwnd;
588 HDC hdc;
589 BOOL ret;
590 TEXTMETRICA tm;
591 DWORD extent;
592 INT tabs[8], cx, cy, tab, tabcount,t,align;
594 /* Initialization */
595 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
596 0, 0, 200, 200, 0, 0, 0, NULL);
597 ok(hwnd != 0, "CreateWindowExA error %u\n", GetLastError());
598 hdc = GetDC(hwnd);
599 ok(hdc != 0, "GetDC error %u\n", GetLastError());
601 ret = GetTextMetricsA( hdc, &tm);
602 ok( ret, "GetTextMetrics error %u\n", GetLastError());
604 extent = GetTabbedTextExtentA( hdc, "x", 1, 1, tabs);
605 cx = LOWORD( extent);
606 cy = HIWORD( extent);
607 trace( "cx is %d cy is %d\n", cx, cy);
609 align=1;
610 for( t=-1; t<=1; t++) { /* slightly adjust the 4 char tabstop, to
611 catch the one off errors */
612 tab = (cx *4 + t);
613 /* test the special case tabcount =1 and the general array (80 of tabs */
614 for( tabcount = 1; tabcount <= 8; tabcount +=7) {
615 TABTEST( align * tab, tabcount, "\t", tab)
616 TABTEST( align * tab, tabcount, "xxx\t", tab)
617 TABTEST( align * tab, tabcount, "\tx", tab+cx)
618 TABTEST( align * tab, tabcount, "\t\t", tab*2)
619 TABTEST( align * tab, tabcount, "\tx\t", tab*2)
620 TABTEST( align * tab, tabcount, "x\tx", tab+cx)
621 TABTEST( align * tab, tabcount, "xx\tx", tab+cx)
622 TABTEST( align * tab, tabcount, "xxx\tx", tab+cx)
623 TABTEST( align * tab, tabcount, "xxxx\tx", t>0 ? tab + cx : 2*tab+cx)
624 TABTEST( align * tab, tabcount, "xxxxx\tx", 2*tab+cx)
627 align=-1;
628 for( t=-1; t<=1; t++) { /* slightly adjust the 4 char tabstop, to
629 catch the one off errors */
630 tab = (cx *4 + t);
631 /* test the special case tabcount =1 and the general array (8) of tabs */
632 for( tabcount = 1; tabcount <= 8; tabcount +=7) {
633 TABTEST( align * tab, tabcount, "\t", tab)
634 TABTEST( align * tab, tabcount, "xxx\t", tab)
635 TABTEST( align * tab, tabcount, "\tx", tab)
636 TABTEST( align * tab, tabcount, "\t\t", tab*2)
637 TABTEST( align * tab, tabcount, "\tx\t", tab*2)
638 TABTEST( align * tab, tabcount, "x\tx", tab)
639 TABTEST( align * tab, tabcount, "xx\tx", tab)
640 TABTEST( align * tab, tabcount, "xxx\tx", 4 * cx >= tab ? 2*tab :tab)
641 TABTEST( align * tab, tabcount, "xxxx\tx", 2*tab)
642 TABTEST( align * tab, tabcount, "xxxxx\tx", 2*tab)
646 ReleaseDC( hwnd, hdc );
647 DestroyWindow( hwnd );
650 static void test_DrawState(void)
652 static const char text[] = "Sample text string";
653 HWND hwnd;
654 HDC hdc;
655 BOOL ret;
657 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
658 0, 0, 200, 200, 0, 0, 0, NULL);
659 assert(hwnd);
661 hdc = GetDC(hwnd);
662 assert(hdc);
664 SetLastError(0xdeadbeef);
665 ret = DrawState(hdc, GetStockObject(DKGRAY_BRUSH), NULL, (LPARAM)text, strlen(text),
666 0, 0, 10, 10, DST_TEXT);
667 ok(ret, "DrawState error %u\n", GetLastError());
669 SetLastError(0xdeadbeef);
670 ret = DrawState(hdc, GetStockObject(DKGRAY_BRUSH), NULL, (LPARAM)text, 0,
671 0, 0, 10, 10, DST_TEXT);
672 ok(ret, "DrawState error %u\n", GetLastError());
674 SetLastError(0xdeadbeef);
675 ret = DrawState(hdc, GetStockObject(DKGRAY_BRUSH), NULL, 0, strlen(text),
676 0, 0, 10, 10, DST_TEXT);
677 ok(!ret || broken(ret) /* win98 */, "DrawState succeeded\n");
678 ok(GetLastError() == 0xdeadbeef, "not expected error %u\n", GetLastError());
680 SetLastError(0xdeadbeef);
681 ret = DrawState(hdc, GetStockObject(DKGRAY_BRUSH), NULL, 0, 0,
682 0, 0, 10, 10, DST_TEXT);
683 ok(!ret || broken(ret) /* win98 */, "DrawState succeeded\n");
684 ok(GetLastError() == 0xdeadbeef, "not expected error %u\n", GetLastError());
686 ReleaseDC(hwnd, hdc);
687 DestroyWindow(hwnd);
690 START_TEST(text)
692 test_TabbedText();
693 test_DrawTextCalcRect();
694 test_DrawState();