1c2c66affSColin Finck /*
2c2c66affSColin Finck * DrawText tests
3c2c66affSColin Finck *
4c2c66affSColin Finck * Copyright (c) 2004 Zach Gorman
5c2c66affSColin Finck * Copyright 2007,2016 Dmitry Timoshkov
6c2c66affSColin Finck *
7c2c66affSColin Finck * This library is free software; you can redistribute it and/or
8c2c66affSColin Finck * modify it under the terms of the GNU Lesser General Public
9c2c66affSColin Finck * License as published by the Free Software Foundation; either
10c2c66affSColin Finck * version 2.1 of the License, or (at your option) any later version.
11c2c66affSColin Finck *
12c2c66affSColin Finck * This library is distributed in the hope that it will be useful,
13c2c66affSColin Finck * but WITHOUT ANY WARRANTY; without even the implied warranty of
14c2c66affSColin Finck * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15c2c66affSColin Finck * Lesser General Public License for more details.
16c2c66affSColin Finck *
17c2c66affSColin Finck * You should have received a copy of the GNU Lesser General Public
18c2c66affSColin Finck * License along with this library; if not, write to the Free Software
19c2c66affSColin Finck * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20c2c66affSColin Finck */
21c2c66affSColin Finck
22d558fc75SAmine Khaldi #include <assert.h>
23d558fc75SAmine Khaldi
24d558fc75SAmine Khaldi #include "wine/test.h"
25d558fc75SAmine Khaldi #include "winbase.h"
26d558fc75SAmine Khaldi #include "wingdi.h"
27d558fc75SAmine Khaldi #include "winuser.h"
28d558fc75SAmine Khaldi #include "winerror.h"
29d558fc75SAmine Khaldi #include "winnls.h"
30c2c66affSColin Finck
31c2c66affSColin Finck #define MODIFIED(rect) (rect.left == 10 && rect.right != 100 && rect.top == 10 && rect.bottom != 100)
32c2c66affSColin Finck #define EMPTY(rect) (rect.left == rect.right && rect.bottom == rect.top)
33c2c66affSColin Finck
test_DrawTextCalcRect(void)34c2c66affSColin Finck static void test_DrawTextCalcRect(void)
35c2c66affSColin Finck {
36c2c66affSColin Finck HWND hwnd;
37c2c66affSColin Finck HDC hdc;
38c2c66affSColin Finck HFONT hFont, hOldFont;
39c2c66affSColin Finck LOGFONTA lf;
40c2c66affSColin Finck static CHAR text[] = "Example text for testing DrawText in "
41c2c66affSColin Finck "MM_HIENGLISH mode";
42c2c66affSColin Finck static WCHAR textW[] = {'W','i','d','e',' ','c','h','a','r',' ',
43c2c66affSColin Finck 's','t','r','i','n','g','\0'};
44c2c66affSColin Finck static CHAR emptystring[] = "";
45c2c66affSColin Finck static WCHAR emptystringW[] = { 0 };
46c2c66affSColin Finck static CHAR wordbreak_text[] = "line1 line2";
47c2c66affSColin Finck static WCHAR wordbreak_textW[] = {'l','i','n','e','1',' ','l','i','n','e','2',0};
48c2c66affSColin Finck static char tabstring[] = "one\ttwo";
49c2c66affSColin Finck INT textlen, textheight, heightcheck;
50c2c66affSColin Finck RECT rect = { 0, 0, 100, 0 }, rect2;
51c2c66affSColin Finck BOOL ret;
52c2c66affSColin Finck DRAWTEXTPARAMS dtp;
53c2c66affSColin Finck BOOL conform_xp = TRUE;
54c2c66affSColin Finck
55c2c66affSColin Finck /* Initialization */
56c2c66affSColin Finck hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
57c2c66affSColin Finck 0, 0, 200, 200, 0, 0, 0, NULL);
58c2c66affSColin Finck ok(hwnd != 0, "CreateWindowExA error %u\n", GetLastError());
59c2c66affSColin Finck hdc = GetDC(hwnd);
60c2c66affSColin Finck ok(hdc != 0, "GetDC error %u\n", GetLastError());
61c2c66affSColin Finck trace("hdc %p\n", hdc);
62c2c66affSColin Finck textlen = lstrlenA(text);
63c2c66affSColin Finck
64c2c66affSColin Finck /* LOGFONT initialization */
65c2c66affSColin Finck memset(&lf, 0, sizeof(lf));
66c2c66affSColin Finck lf.lfCharSet = ANSI_CHARSET;
67c2c66affSColin Finck lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
68c2c66affSColin Finck lf.lfWeight = FW_DONTCARE;
69c2c66affSColin Finck lf.lfHeight = 0; /* mapping mode dependent */
70c2c66affSColin Finck lf.lfQuality = DEFAULT_QUALITY;
71c2c66affSColin Finck lstrcpyA(lf.lfFaceName, "Arial");
72c2c66affSColin Finck
73c2c66affSColin Finck /* DrawText in MM_HIENGLISH with DT_CALCRECT */
74c2c66affSColin Finck SetMapMode(hdc, MM_HIENGLISH);
75c2c66affSColin Finck lf.lfHeight = 100 * 9 / 72; /* 9 point */
76c2c66affSColin Finck hFont = CreateFontIndirectA(&lf);
77c2c66affSColin Finck ok(hFont != 0, "CreateFontIndirectA error %u\n",
78c2c66affSColin Finck GetLastError());
79c2c66affSColin Finck hOldFont = SelectObject(hdc, hFont);
80c2c66affSColin Finck
81c2c66affSColin Finck textheight = DrawTextA(hdc, text, textlen, &rect, DT_CALCRECT |
82c2c66affSColin Finck DT_EXTERNALLEADING | DT_WORDBREAK | DT_NOCLIP | DT_LEFT |
83c2c66affSColin Finck DT_NOPREFIX);
84c2c66affSColin Finck ok( textheight, "DrawTextA error %u\n", GetLastError());
85c2c66affSColin Finck
86c2c66affSColin Finck trace("MM_HIENGLISH rect.bottom %d\n", rect.bottom);
87c2c66affSColin Finck ok(rect.bottom < 0, "In MM_HIENGLISH, DrawText with "
88c2c66affSColin Finck "DT_CALCRECT should return a negative rectangle bottom. "
89c2c66affSColin Finck "(bot=%d)\n", rect.bottom);
90c2c66affSColin Finck
91c2c66affSColin Finck SelectObject(hdc, hOldFont);
92c2c66affSColin Finck ret = DeleteObject(hFont);
93c2c66affSColin Finck ok( ret, "DeleteObject error %u\n", GetLastError());
94c2c66affSColin Finck
95c2c66affSColin Finck
96c2c66affSColin Finck /* DrawText in MM_TEXT with DT_CALCRECT */
97c2c66affSColin Finck SetMapMode(hdc, MM_TEXT);
98c2c66affSColin Finck lf.lfHeight = -MulDiv(9, GetDeviceCaps(hdc,
99c2c66affSColin Finck LOGPIXELSY), 72); /* 9 point */
100c2c66affSColin Finck hFont = CreateFontIndirectA(&lf);
101c2c66affSColin Finck ok(hFont != 0, "CreateFontIndirectA error %u\n",
102c2c66affSColin Finck GetLastError());
103c2c66affSColin Finck hOldFont = SelectObject(hdc, hFont);
104c2c66affSColin Finck
105c2c66affSColin Finck textheight = DrawTextA(hdc, text, textlen, &rect, DT_CALCRECT |
106c2c66affSColin Finck DT_EXTERNALLEADING | DT_WORDBREAK | DT_NOCLIP | DT_LEFT |
107c2c66affSColin Finck DT_NOPREFIX);
108c2c66affSColin Finck ok( textheight, "DrawTextA error %u\n", GetLastError());
109c2c66affSColin Finck
110c2c66affSColin Finck trace("MM_TEXT rect.bottom %d\n", rect.bottom);
111c2c66affSColin Finck ok(rect.bottom > 0, "In MM_TEXT, DrawText with DT_CALCRECT "
112c2c66affSColin Finck "should return a positive rectangle bottom. (bot=%d)\n",
113c2c66affSColin Finck rect.bottom);
114c2c66affSColin Finck
115c2c66affSColin Finck /* empty or null text should in some cases calc an empty rectangle */
116c2c66affSColin Finck
117c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
118c2c66affSColin Finck heightcheck = textheight = DrawTextExA(hdc, text, 0, &rect, DT_CALCRECT, NULL );
119c2c66affSColin Finck ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
120c2c66affSColin Finck "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
121c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextExA\n");
122c2c66affSColin Finck
123c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
124c2c66affSColin Finck textheight = DrawTextA(hdc, text, 0, &rect, DT_CALCRECT);
125c2c66affSColin Finck ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
126c2c66affSColin Finck "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
127c2c66affSColin Finck if (conform_xp)
128c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextA\n");
129c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
130c2c66affSColin Finck
131c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
132c2c66affSColin Finck SetLastError( 0);
133c2c66affSColin Finck heightcheck = textheight = DrawTextExA(hdc, emptystring, -1, &rect, DT_CALCRECT, NULL );
134c2c66affSColin Finck ok(EMPTY(rect), "rectangle should be empty got %s\n", wine_dbgstr_rect(&rect));
135c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextExA\n");
136c2c66affSColin Finck
137c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
138c2c66affSColin Finck textheight = DrawTextA(hdc, emptystring, -1, &rect, DT_CALCRECT);
139c2c66affSColin Finck ok(EMPTY(rect), "rectangle should be empty got %s\n", wine_dbgstr_rect(&rect));
140c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
141c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
142c2c66affSColin Finck
143c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
144c2c66affSColin Finck SetLastError( 0);
145c2c66affSColin Finck heightcheck = textheight = DrawTextExA(hdc, NULL, -1, &rect, DT_CALCRECT, NULL );
146c2c66affSColin Finck ok(EMPTY(rect), "rectangle should be empty got %s\n", wine_dbgstr_rect(&rect));
147c2c66affSColin Finck if (!textheight) /* Windows NT 4 */
148c2c66affSColin Finck {
149c2c66affSColin Finck if (conform_xp)
150c2c66affSColin Finck win_skip("XP conformity failed, skipping XP tests. Probably winNT\n");
151c2c66affSColin Finck conform_xp = FALSE;
152c2c66affSColin Finck }
153c2c66affSColin Finck else
154c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextExA\n");
155c2c66affSColin Finck
156c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
157c2c66affSColin Finck textheight = DrawTextA(hdc, NULL, -1, &rect, DT_CALCRECT);
158c2c66affSColin Finck ok(EMPTY(rect), "rectangle should be empty got %s\n", wine_dbgstr_rect(&rect));
159c2c66affSColin Finck if (conform_xp)
160c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
161c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
162c2c66affSColin Finck
163c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
164c2c66affSColin Finck heightcheck = textheight = DrawTextExA(hdc, NULL, 0, &rect, DT_CALCRECT, NULL );
165c2c66affSColin Finck ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
166c2c66affSColin Finck "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
167c2c66affSColin Finck if (conform_xp)
168c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextExA\n");
169c2c66affSColin Finck
170c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
171c2c66affSColin Finck textheight = DrawTextA(hdc, NULL, 0, &rect, DT_CALCRECT);
172c2c66affSColin Finck ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
173c2c66affSColin Finck "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
174c2c66affSColin Finck if (conform_xp)
175c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextA\n");
176c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
177c2c66affSColin Finck
178c2c66affSColin Finck /* DT_SINGLELINE tests */
179c2c66affSColin Finck
180c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
181c2c66affSColin Finck heightcheck = textheight = DrawTextExA(hdc, text, 0, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
182c2c66affSColin Finck ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
183c2c66affSColin Finck "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
184c2c66affSColin Finck if (conform_xp)
185c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextExA\n");
186c2c66affSColin Finck
187c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
188c2c66affSColin Finck textheight = DrawTextA(hdc, text, 0, &rect, DT_CALCRECT|DT_SINGLELINE);
189c2c66affSColin Finck ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
190c2c66affSColin Finck "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
191c2c66affSColin Finck if (conform_xp)
192c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextA\n");
193c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
194c2c66affSColin Finck
195c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
196c2c66affSColin Finck SetLastError( 0);
197c2c66affSColin Finck heightcheck = textheight = DrawTextExA(hdc, emptystring, -1, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
198c2c66affSColin Finck ok(!EMPTY(rect) && MODIFIED(rect), "rectangle should be modified got %s\n",
199c2c66affSColin Finck wine_dbgstr_rect(&rect));
200c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextExA\n");
201c2c66affSColin Finck
202c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
203c2c66affSColin Finck textheight = DrawTextA(hdc, emptystring, -1, &rect, DT_CALCRECT|DT_SINGLELINE);
204c2c66affSColin Finck ok(!EMPTY(rect) && MODIFIED (rect), "rectangle should be modified got %s\n",
205c2c66affSColin Finck wine_dbgstr_rect(&rect));
206c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
207c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
208c2c66affSColin Finck
209c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
210c2c66affSColin Finck SetLastError( 0);
211c2c66affSColin Finck heightcheck = textheight = DrawTextExA(hdc, NULL, -1, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
212c2c66affSColin Finck ok(!EMPTY(rect) && MODIFIED(rect), "rectangle should be modified got %s\n",
213c2c66affSColin Finck wine_dbgstr_rect(&rect));
214c2c66affSColin Finck if (conform_xp)
215c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextExA\n");
216c2c66affSColin Finck
217c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
218c2c66affSColin Finck textheight = DrawTextA(hdc, NULL, -1, &rect, DT_CALCRECT|DT_SINGLELINE);
219c2c66affSColin Finck ok(!EMPTY(rect) && MODIFIED(rect), "rectangle should be modified got %s\n",
220c2c66affSColin Finck wine_dbgstr_rect(&rect));
221c2c66affSColin Finck if (conform_xp)
222c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
223c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
224c2c66affSColin Finck
225c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
226c2c66affSColin Finck heightcheck = textheight = DrawTextExA(hdc, NULL, 0, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
227c2c66affSColin Finck ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
228c2c66affSColin Finck "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
229c2c66affSColin Finck if (conform_xp)
230c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextExA\n");
231c2c66affSColin Finck
232c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
233c2c66affSColin Finck textheight = DrawTextA(hdc, NULL, 0, &rect, DT_CALCRECT|DT_SINGLELINE);
234c2c66affSColin Finck ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
235c2c66affSColin Finck "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
236c2c66affSColin Finck if (conform_xp)
237c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextA\n");
238c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
239c2c66affSColin Finck
240c2c66affSColin Finck /* further tests with 0 count, NULL and empty strings */
241c2c66affSColin Finck heightcheck = textheight = DrawTextA(hdc, text, 0, &rect, 0);
242c2c66affSColin Finck if (conform_xp)
243c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextA\n");
244c2c66affSColin Finck textheight = DrawTextExA(hdc, text, 0, &rect, 0, NULL );
245c2c66affSColin Finck if (conform_xp)
246c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextExA\n");
247c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
248c2c66affSColin Finck heightcheck = textheight = DrawTextA(hdc, emptystring, 0, &rect, 0);
249c2c66affSColin Finck if (conform_xp)
250c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextA\n");
251c2c66affSColin Finck textheight = DrawTextExA(hdc, emptystring, 0, &rect, 0, NULL );
252c2c66affSColin Finck if (conform_xp)
253c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextExA\n");
254c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
255c2c66affSColin Finck heightcheck = textheight = DrawTextA(hdc, NULL, 0, &rect, 0);
256c2c66affSColin Finck if (conform_xp)
257c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextA\n");
258c2c66affSColin Finck textheight = DrawTextExA(hdc, NULL, 0, &rect, 0, NULL );
259c2c66affSColin Finck if (conform_xp)
260c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextExA\n");
261c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
262c2c66affSColin Finck heightcheck = textheight = DrawTextA(hdc, emptystring, -1, &rect, 0);
263c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
264c2c66affSColin Finck textheight = DrawTextExA(hdc, emptystring, -1, &rect, 0, NULL );
265c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextExA\n");
266c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
267c2c66affSColin Finck heightcheck = textheight = DrawTextA(hdc, NULL, -1, &rect, 0);
268c2c66affSColin Finck if (conform_xp)
269c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextA\n");
270c2c66affSColin Finck textheight = DrawTextExA(hdc, NULL, -1, &rect, 0, NULL );
271c2c66affSColin Finck if (conform_xp)
272c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextExA\n");
273c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
274c2c66affSColin Finck heightcheck = textheight = DrawTextA(hdc, NULL, 10, &rect, 0);
275c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextA\n");
276c2c66affSColin Finck textheight = DrawTextExA(hdc, NULL, 10, &rect, 0, NULL );
277c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextA\n");
278c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
279c2c66affSColin Finck
280*7a62c32bSAmine Khaldi /* When offset to top is zero, return 1 */
281*7a62c32bSAmine Khaldi SetRectEmpty(&rect);
282*7a62c32bSAmine Khaldi textheight = DrawTextExW(hdc, textW, -1, &rect, DT_SINGLELINE | DT_CALCRECT | DT_BOTTOM, NULL);
283*7a62c32bSAmine Khaldi ok(textheight == 1, "Expect returned height:1 got:%d\n", textheight);
284*7a62c32bSAmine Khaldi
285*7a62c32bSAmine Khaldi SetRect(&rect, 0, 100, 0, 100);
286*7a62c32bSAmine Khaldi textheight = DrawTextExW(hdc, textW, -1, &rect, DT_SINGLELINE | DT_CALCRECT | DT_BOTTOM, NULL);
287*7a62c32bSAmine Khaldi ok(textheight == 1, "Expect returned height:1 got:%d\n", textheight);
288*7a62c32bSAmine Khaldi
289*7a62c32bSAmine Khaldi SetRectEmpty(&rect);
290*7a62c32bSAmine Khaldi textheight = DrawTextExW(hdc, textW, -1, &rect, DT_SINGLELINE | DT_CALCRECT | DT_TOP, NULL);
291*7a62c32bSAmine Khaldi /* Set top to text height and bottom zero, so bottom of drawn text to top is zero when DT_VCENTER is used */
292*7a62c32bSAmine Khaldi SetRect(&rect, 0, textheight, 0, 0);
293*7a62c32bSAmine Khaldi textheight = DrawTextExW(hdc, textW, -1, &rect, DT_SINGLELINE | DT_CALCRECT | DT_VCENTER, NULL);
294*7a62c32bSAmine Khaldi ok(textheight == 1, "Expect returned height:1 got:%d\n", textheight);
295c2c66affSColin Finck
296c2c66affSColin Finck /* invalid dtp size test */
297c2c66affSColin Finck dtp.cbSize = -1; /* Invalid */
298c2c66affSColin Finck dtp.uiLengthDrawn = 1337;
299c2c66affSColin Finck textheight = DrawTextExA(hdc, text, 0, &rect, 0, &dtp);
300c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextExA\n");
301c2c66affSColin Finck ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
302c2c66affSColin Finck dtp.uiLengthDrawn = 1337;
303c2c66affSColin Finck textheight = DrawTextExA(hdc, emptystring, 0, &rect, 0, &dtp);
304c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextExA\n");
305c2c66affSColin Finck ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
306c2c66affSColin Finck dtp.uiLengthDrawn = 1337;
307c2c66affSColin Finck textheight = DrawTextExA(hdc, NULL, 0, &rect, 0, &dtp);
308c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextExA\n");
309c2c66affSColin Finck ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
310c2c66affSColin Finck dtp.uiLengthDrawn = 1337;
311c2c66affSColin Finck textheight = DrawTextExA(hdc, emptystring, -1, &rect, 0, &dtp);
312c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextExA\n");
313c2c66affSColin Finck ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
314c2c66affSColin Finck dtp.uiLengthDrawn = 1337;
315c2c66affSColin Finck textheight = DrawTextExA(hdc, NULL, -1, &rect, 0, &dtp);
316c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextExA\n");
317c2c66affSColin Finck ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
318c2c66affSColin Finck
319c2c66affSColin Finck /* Margin calculations */
320c2c66affSColin Finck dtp.cbSize = sizeof(dtp);
321c2c66affSColin Finck dtp.iLeftMargin = 0;
322c2c66affSColin Finck dtp.iRightMargin = 0;
323c2c66affSColin Finck SetRectEmpty(&rect);
324c2c66affSColin Finck DrawTextExA(hdc, text, -1, &rect, DT_CALCRECT, &dtp);
325c2c66affSColin Finck textlen = rect.right; /* Width without margin */
326c2c66affSColin Finck dtp.iLeftMargin = 8;
327c2c66affSColin Finck SetRectEmpty(&rect);
328c2c66affSColin Finck DrawTextExA(hdc, text, -1, &rect, DT_CALCRECT, &dtp);
329c2c66affSColin Finck ok(rect.right==dtp.iLeftMargin+textlen ,"Incorrect left margin calculated rc(%d,%d)\n", rect.left, rect.right);
330c2c66affSColin Finck dtp.iLeftMargin = 0;
331c2c66affSColin Finck dtp.iRightMargin = 8;
332c2c66affSColin Finck SetRectEmpty(&rect);
333c2c66affSColin Finck DrawTextExA(hdc, text, -1, &rect, DT_CALCRECT, &dtp);
334c2c66affSColin Finck ok(rect.right==dtp.iRightMargin+textlen ,"Incorrect right margin calculated rc(%d,%d)\n", rect.left, rect.right);
335c2c66affSColin Finck
336c2c66affSColin Finck /* Wide char versions */
337c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
338c2c66affSColin Finck SetLastError( 0);
339c2c66affSColin Finck heightcheck = textheight = DrawTextExW(hdc, textW, 0, &rect, DT_CALCRECT, NULL );
340c2c66affSColin Finck if( GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) {
341c2c66affSColin Finck ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
342c2c66affSColin Finck "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
343c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
344c2c66affSColin Finck
345c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
346c2c66affSColin Finck textheight = DrawTextW(hdc, textW, 0, &rect, DT_CALCRECT);
347c2c66affSColin Finck ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
348c2c66affSColin Finck "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
349c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
350c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
351c2c66affSColin Finck
352c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
353c2c66affSColin Finck heightcheck = textheight = DrawTextExW(hdc, emptystringW, -1, &rect, DT_CALCRECT, NULL );
354c2c66affSColin Finck ok(EMPTY(rect), "rectangle should be empty got %s\n", wine_dbgstr_rect(&rect));
355c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
356c2c66affSColin Finck
357c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
358c2c66affSColin Finck textheight = DrawTextW(hdc, emptystringW, -1, &rect, DT_CALCRECT);
359c2c66affSColin Finck ok(EMPTY(rect), "rectangle should be empty got %s\n", wine_dbgstr_rect(&rect));
360c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
361c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
362c2c66affSColin Finck
363c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
364c2c66affSColin Finck heightcheck = textheight = DrawTextExW(hdc, NULL, 0, &rect, DT_CALCRECT, NULL );
365c2c66affSColin Finck ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
366c2c66affSColin Finck "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
367c2c66affSColin Finck if (textheight) /* windows 2000 */
368c2c66affSColin Finck {
369c2c66affSColin Finck if (conform_xp)
370c2c66affSColin Finck win_skip("XP conformity failed, skipping XP tests. Probably win 2000\n");
371c2c66affSColin Finck conform_xp = FALSE;
372c2c66affSColin Finck }
373c2c66affSColin Finck else
374c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextExW\n");
375c2c66affSColin Finck
376c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
377c2c66affSColin Finck textheight = DrawTextW(hdc, NULL, 0, &rect, DT_CALCRECT);
378c2c66affSColin Finck ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
379c2c66affSColin Finck "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
380c2c66affSColin Finck if (conform_xp)
381c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextW\n");
382c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
383c2c66affSColin Finck
384c2c66affSColin Finck if (conform_xp) {
385c2c66affSColin Finck /* Crashes on NT4 */
386c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
387c2c66affSColin Finck heightcheck = textheight = DrawTextExW(hdc, NULL, -1, &rect, DT_CALCRECT, NULL );
388c2c66affSColin Finck ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
389c2c66affSColin Finck "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
390c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextExW\n");
391c2c66affSColin Finck
392c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
393c2c66affSColin Finck textheight = DrawTextW(hdc, NULL, -1, &rect, DT_CALCRECT);
394c2c66affSColin Finck ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
395c2c66affSColin Finck "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
396c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextW\n");
397c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
398c2c66affSColin Finck }
399c2c66affSColin Finck
400c2c66affSColin Finck
401c2c66affSColin Finck /* DT_SINGLELINE tests */
402c2c66affSColin Finck
403c2c66affSColin Finck heightcheck = textheight = DrawTextExW(hdc, textW, 0, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
404c2c66affSColin Finck ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
405c2c66affSColin Finck "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
406c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
407c2c66affSColin Finck
408c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
409c2c66affSColin Finck textheight = DrawTextW(hdc, textW, 0, &rect, DT_CALCRECT|DT_SINGLELINE);
410c2c66affSColin Finck ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
411c2c66affSColin Finck "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
412c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
413c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
414c2c66affSColin Finck
415c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
416c2c66affSColin Finck heightcheck = textheight = DrawTextExW(hdc, emptystringW, -1, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
417c2c66affSColin Finck ok(!EMPTY(rect) && MODIFIED(rect), "rectangle should be modified got %s\n",
418c2c66affSColin Finck wine_dbgstr_rect(&rect));
419c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
420c2c66affSColin Finck
421c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
422c2c66affSColin Finck textheight = DrawTextW(hdc, emptystringW, -1, &rect, DT_CALCRECT|DT_SINGLELINE);
423c2c66affSColin Finck ok(!EMPTY(rect) && MODIFIED(rect), "rectangle should be modified got %s\n",
424c2c66affSColin Finck wine_dbgstr_rect(&rect));
425c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
426c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
427c2c66affSColin Finck
428c2c66affSColin Finck if (conform_xp) {
429c2c66affSColin Finck /* Crashes on NT4 */
430c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
431c2c66affSColin Finck heightcheck = textheight = DrawTextExW(hdc, NULL, -1, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
432c2c66affSColin Finck ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
433c2c66affSColin Finck "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
434c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextExW\n");
435c2c66affSColin Finck
436c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
437c2c66affSColin Finck textheight = DrawTextW(hdc, NULL, -1, &rect, DT_CALCRECT|DT_SINGLELINE);
438c2c66affSColin Finck ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
439c2c66affSColin Finck "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
440c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextW\n");
441c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
442c2c66affSColin Finck }
443c2c66affSColin Finck
444c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
445c2c66affSColin Finck heightcheck = textheight = DrawTextExW(hdc, NULL, 0, &rect, DT_CALCRECT|DT_SINGLELINE, NULL );
446c2c66affSColin Finck ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
447c2c66affSColin Finck "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
448c2c66affSColin Finck if (conform_xp)
449c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextExW\n");
450c2c66affSColin Finck
451c2c66affSColin Finck SetRect( &rect, 10,10, 100, 100);
452c2c66affSColin Finck textheight = DrawTextW(hdc, NULL, 0, &rect, DT_CALCRECT|DT_SINGLELINE);
453c2c66affSColin Finck ok(!IsRectEmpty(&rect) && !MODIFIED(rect),
454c2c66affSColin Finck "rectangle should NOT be empty and NOT modified got %s\n", wine_dbgstr_rect(&rect));
455c2c66affSColin Finck if (conform_xp)
456c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextW\n");
457c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
458c2c66affSColin Finck
459c2c66affSColin Finck /* further tests with NULL and empty strings */
460c2c66affSColin Finck heightcheck = textheight = DrawTextW(hdc, textW, 0, &rect, 0);
461c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
462c2c66affSColin Finck textheight = DrawTextExW(hdc, textW, 0, &rect, 0, NULL );
463c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
464c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
465c2c66affSColin Finck heightcheck = textheight = DrawTextW(hdc, emptystringW, 0, &rect, 0);
466c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
467c2c66affSColin Finck textheight = DrawTextExW(hdc, emptystringW, 0, &rect, 0, NULL );
468c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
469c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
470c2c66affSColin Finck heightcheck = textheight = DrawTextW(hdc, NULL, 0, &rect, 0);
471c2c66affSColin Finck if (conform_xp)
472c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextW\n");
473c2c66affSColin Finck textheight = DrawTextExW(hdc, NULL, 0, &rect, 0, NULL );
474c2c66affSColin Finck if (conform_xp)
475c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextExW\n");
476c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
477c2c66affSColin Finck heightcheck = textheight = DrawTextW(hdc, emptystringW, -1, &rect, 0);
478c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextW\n");
479c2c66affSColin Finck textheight = DrawTextExW(hdc, emptystringW, -1, &rect, 0, NULL );
480c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
481c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
482c2c66affSColin Finck if (conform_xp) {
483c2c66affSColin Finck /* Crashes on NT4 */
484c2c66affSColin Finck heightcheck = textheight = DrawTextW(hdc, NULL, -1, &rect, 0);
485c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextW\n");
486c2c66affSColin Finck textheight = DrawTextExW(hdc, NULL, -1, &rect, 0, NULL );
487c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextExW\n");
488c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
489c2c66affSColin Finck heightcheck = textheight = DrawTextW(hdc, NULL, 10, &rect, 0);
490c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextW\n");
491c2c66affSColin Finck textheight = DrawTextExW(hdc, NULL, 10, &rect, 0, NULL );
492c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextW\n");
493c2c66affSColin Finck ok(textheight == heightcheck,"DrawTextEx and DrawText differ in return\n");
494c2c66affSColin Finck }
495c2c66affSColin Finck
496c2c66affSColin Finck dtp.cbSize = -1; /* Invalid */
497c2c66affSColin Finck dtp.uiLengthDrawn = 1337;
498c2c66affSColin Finck textheight = DrawTextExW(hdc, textW, 0, &rect, 0, &dtp);
499c2c66affSColin Finck ok(textheight!=0,"Failed to get textheight from DrawTextExW\n");
500c2c66affSColin Finck ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
501c2c66affSColin Finck dtp.uiLengthDrawn = 1337;
502c2c66affSColin Finck textheight = DrawTextExW(hdc, emptystringW, 0, &rect, 0, &dtp);
503c2c66affSColin Finck if (conform_xp)
504c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextExW\n");
505c2c66affSColin Finck ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
506c2c66affSColin Finck dtp.uiLengthDrawn = 1337;
507c2c66affSColin Finck textheight = DrawTextExW(hdc, NULL, 0, &rect, 0, &dtp);
508c2c66affSColin Finck if (conform_xp)
509c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextExW\n");
510c2c66affSColin Finck ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
511c2c66affSColin Finck dtp.uiLengthDrawn = 1337;
512c2c66affSColin Finck textheight = DrawTextExW(hdc, emptystringW, -1, &rect, 0, &dtp);
513c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextExW\n");
514c2c66affSColin Finck ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
515c2c66affSColin Finck if (conform_xp) {
516c2c66affSColin Finck /* Crashes on NT4 */
517c2c66affSColin Finck dtp.uiLengthDrawn = 1337;
518c2c66affSColin Finck textheight = DrawTextExW(hdc, NULL, -1, &rect, 0, &dtp);
519c2c66affSColin Finck ok(textheight==0,"Got textheight from DrawTextExW\n");
520c2c66affSColin Finck ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
521c2c66affSColin Finck }
522c2c66affSColin Finck }
523c2c66affSColin Finck
524c2c66affSColin Finck /* More test cases from bug 12226 */
525c2c66affSColin Finck SetRectEmpty(&rect);
526c2c66affSColin Finck textheight = DrawTextA(hdc, emptystring, -1, &rect, DT_CALCRECT | DT_LEFT | DT_SINGLELINE);
527c2c66affSColin Finck ok(textheight, "DrawTextA error %u\n", GetLastError());
528c2c66affSColin Finck ok(0 == rect.left, "expected 0, got %d\n", rect.left);
529c2c66affSColin Finck ok(0 == rect.right, "expected 0, got %d\n", rect.right);
530c2c66affSColin Finck ok(0 == rect.top, "expected 0, got %d\n", rect.top);
531c2c66affSColin Finck ok(rect.bottom, "rect.bottom should not be 0\n");
532c2c66affSColin Finck
533c2c66affSColin Finck SetRectEmpty(&rect);
534c2c66affSColin Finck textheight = DrawTextW(hdc, emptystringW, -1, &rect, DT_CALCRECT | DT_LEFT | DT_SINGLELINE);
535c2c66affSColin Finck if (!textheight && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
536c2c66affSColin Finck {
537c2c66affSColin Finck win_skip( "DrawTextW not implemented\n" );
538c2c66affSColin Finck }
539c2c66affSColin Finck else
540c2c66affSColin Finck {
541c2c66affSColin Finck ok(textheight, "DrawTextW error %u\n", GetLastError());
542c2c66affSColin Finck ok(0 == rect.left, "expected 0, got %d\n", rect.left);
543c2c66affSColin Finck ok(0 == rect.right, "expected 0, got %d\n", rect.right);
544c2c66affSColin Finck ok(0 == rect.top, "expected 0, got %d\n", rect.top);
545c2c66affSColin Finck ok(rect.bottom, "rect.bottom should not be 0\n");
546c2c66affSColin Finck }
547c2c66affSColin Finck
548c2c66affSColin Finck SetRect(&rect, 0, 0, 1, 1);
549c2c66affSColin Finck heightcheck = DrawTextA(hdc, wordbreak_text, -1, &rect, DT_CALCRECT);
550c2c66affSColin Finck SetRect(&rect, 0, 0, 1, 1);
551c2c66affSColin Finck textheight = DrawTextA(hdc, wordbreak_text, -1, &rect, DT_CALCRECT | DT_WORDBREAK);
552c2c66affSColin Finck ok(textheight == heightcheck * 2, "Got unexpected textheight %d, expected %d.\n",
553c2c66affSColin Finck textheight, heightcheck * 2);
554c2c66affSColin Finck SetRect(&rect, 0, 0, 1, 1);
555c2c66affSColin Finck textheight = DrawTextA(hdc, wordbreak_text, -1, &rect, DT_CALCRECT | DT_WORDBREAK | DT_EDITCONTROL);
556c2c66affSColin Finck ok(textheight >= heightcheck * 6, "Got unexpected textheight %d, expected at least %d.\n",
557c2c66affSColin Finck textheight, heightcheck * 6);
558c2c66affSColin Finck
559c2c66affSColin Finck SetRect(&rect, 0, 0, 1, 1);
560c2c66affSColin Finck heightcheck = DrawTextW(hdc, wordbreak_textW, -1, &rect, DT_CALCRECT);
561c2c66affSColin Finck SetRect(&rect, 0, 0, 1, 1);
562c2c66affSColin Finck textheight = DrawTextW(hdc, wordbreak_textW, -1, &rect, DT_CALCRECT | DT_WORDBREAK);
563c2c66affSColin Finck ok(textheight == heightcheck * 2, "Got unexpected textheight %d, expected %d.\n",
564c2c66affSColin Finck textheight, heightcheck * 2);
565c2c66affSColin Finck SetRect(&rect, 0, 0, 1, 1);
566c2c66affSColin Finck textheight = DrawTextW(hdc, wordbreak_textW, -1, &rect, DT_CALCRECT | DT_WORDBREAK | DT_EDITCONTROL);
567c2c66affSColin Finck ok(textheight >= heightcheck * 6, "Got unexpected textheight %d, expected at least %d.\n",
568c2c66affSColin Finck textheight, heightcheck * 6);
569c2c66affSColin Finck
570c2c66affSColin Finck /* DT_TABSTOP | DT_EXPANDTABS tests */
571c2c66affSColin Finck SetRect( &rect, 0,0, 10, 10);
572c2c66affSColin Finck textheight = DrawTextA(hdc, tabstring, -1, &rect, DT_TABSTOP | DT_EXPANDTABS );
573c2c66affSColin Finck ok(textheight >= heightcheck, "Got unexpected textheight %d\n", textheight);
574c2c66affSColin Finck
575c2c66affSColin Finck SetRect( &rect, 0,0, 10, 10);
576c2c66affSColin Finck memset(&dtp, 0, sizeof(dtp));
577c2c66affSColin Finck dtp.cbSize = sizeof(dtp);
578c2c66affSColin Finck textheight = DrawTextExA(hdc, tabstring, -1, &rect, DT_CALCRECT, &dtp);
579c2c66affSColin Finck ok(textheight >= heightcheck, "Got unexpected textheight %d\n", textheight);
580c2c66affSColin Finck ok(dtp.iTabLength == 0, "invalid dtp.iTabLength = %i\n",dtp.iTabLength);
581c2c66affSColin Finck
582c2c66affSColin Finck SetRect( &rect2, 0,0, 10, 10);
583c2c66affSColin Finck memset(&dtp, 0, sizeof(dtp));
584c2c66affSColin Finck dtp.cbSize = sizeof(dtp);
585c2c66affSColin Finck textheight = DrawTextExA(hdc, tabstring, -1, &rect2, DT_CALCRECT | DT_TABSTOP | DT_EXPANDTABS, &dtp);
586c2c66affSColin Finck ok(textheight >= heightcheck, "Got unexpected textheight %d\n", textheight);
587c2c66affSColin Finck ok(dtp.iTabLength == 0, "invalid dtp.iTabLength = %i\n",dtp.iTabLength);
588c2c66affSColin Finck ok(rect.left == rect2.left && rect.right != rect2.right && rect.top == rect2.top && rect.bottom == rect2.bottom,
589c2c66affSColin Finck "incorrect rect %s rect2 %s\n", wine_dbgstr_rect(&rect), wine_dbgstr_rect(&rect2));
590c2c66affSColin Finck
591c2c66affSColin Finck SetRect( &rect, 0,0, 10, 10);
592c2c66affSColin Finck memset(&dtp, 0, sizeof(dtp));
593c2c66affSColin Finck dtp.cbSize = sizeof(dtp);
594c2c66affSColin Finck dtp.iTabLength = 8;
595c2c66affSColin Finck textheight = DrawTextExA(hdc, tabstring, -1, &rect, DT_CALCRECT | DT_TABSTOP | DT_EXPANDTABS, &dtp);
596c2c66affSColin Finck ok(textheight >= heightcheck, "Got unexpected textheight %d\n", textheight);
597c2c66affSColin Finck ok(dtp.iTabLength == 8, "invalid dtp.iTabLength = %i\n",dtp.iTabLength);
598c2c66affSColin Finck ok(rect.left == rect2.left, "unexpected value %d, got %d\n", rect.left, rect2.left);
599c2c66affSColin Finck /* XP, 2003 appear to not give the same values. */
600c2c66affSColin Finck ok(rect.right == rect2.right || broken(rect.right > rect2.right), "unexpected value %d, got %d\n",rect.right, rect2.right);
601c2c66affSColin Finck ok(rect.top == rect2.top, "unexpected value %d, got %d\n", rect.top, rect2.top);
602c2c66affSColin Finck ok(rect.bottom == rect2.bottom , "unexpected value %d, got %d\n", rect.bottom, rect2.bottom);
603c2c66affSColin Finck
604c2c66affSColin Finck
605c2c66affSColin Finck SelectObject(hdc, hOldFont);
606c2c66affSColin Finck ret = DeleteObject(hFont);
607c2c66affSColin Finck ok( ret, "DeleteObject error %u\n", GetLastError());
608c2c66affSColin Finck
609c2c66affSColin Finck /* Clean up */
610c2c66affSColin Finck ret = ReleaseDC(hwnd, hdc);
611c2c66affSColin Finck ok( ret, "ReleaseDC error %u\n", GetLastError());
612c2c66affSColin Finck ret = DestroyWindow(hwnd);
613c2c66affSColin Finck ok( ret, "DestroyWindow error %u\n", GetLastError());
614c2c66affSColin Finck }
615c2c66affSColin Finck
616c2c66affSColin Finck /* replace tabs by \t */
strfmt(const char * str,char * strout)617c2c66affSColin Finck static void strfmt( const char *str, char *strout)
618c2c66affSColin Finck {
619c2c66affSColin Finck unsigned int i,j ;
620c2c66affSColin Finck for(i=0,j=0;i<=strlen(str);i++,j++)
621c2c66affSColin Finck if((strout[j]=str[i])=='\t') {
622c2c66affSColin Finck strout[j++]='\\';
623c2c66affSColin Finck strout[j]='t';
624c2c66affSColin Finck }
625c2c66affSColin Finck }
626c2c66affSColin Finck
627c2c66affSColin Finck
628c2c66affSColin Finck #define TABTEST( tabval, tabcount, string, _exp) \
629c2c66affSColin Finck { int i; char strdisp[64];\
630c2c66affSColin Finck for(i=0;i<8;i++) tabs[i]=(i+1)*(tabval); \
631c2c66affSColin Finck extent = GetTabbedTextExtentA( hdc, string, strlen( string), (tabcount), tabs); \
632c2c66affSColin Finck strfmt( string, strdisp); \
633c2c66affSColin Finck /* trace( "Extent is %08lx\n", extent); */\
634c2c66affSColin Finck ok( extent == _exp, "Test case \"%s\". Text extent is 0x%x, expected 0x%x tab %d tabcount %d\n", \
635c2c66affSColin Finck strdisp, extent, _exp, tabval, tabcount); \
636c2c66affSColin Finck } \
637c2c66affSColin Finck
638c2c66affSColin Finck
test_TabbedText(void)639c2c66affSColin Finck static void test_TabbedText(void)
640c2c66affSColin Finck {
641c2c66affSColin Finck HWND hwnd;
642c2c66affSColin Finck HDC hdc;
643c2c66affSColin Finck BOOL ret;
644c2c66affSColin Finck TEXTMETRICA tm;
645c2c66affSColin Finck DWORD extent;
646c2c66affSColin Finck INT tabs[8], cx, cy, tab, tabcount,t,align;
647c2c66affSColin Finck
648c2c66affSColin Finck /* Initialization */
649c2c66affSColin Finck hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
650c2c66affSColin Finck 0, 0, 200, 200, 0, 0, 0, NULL);
651c2c66affSColin Finck ok(hwnd != 0, "CreateWindowExA error %u\n", GetLastError());
652c2c66affSColin Finck hdc = GetDC(hwnd);
653c2c66affSColin Finck ok(hdc != 0, "GetDC error %u\n", GetLastError());
654c2c66affSColin Finck
655c2c66affSColin Finck ret = GetTextMetricsA( hdc, &tm);
656c2c66affSColin Finck ok( ret, "GetTextMetrics error %u\n", GetLastError());
657c2c66affSColin Finck
658c2c66affSColin Finck extent = GetTabbedTextExtentA( hdc, "x", 0, 1, tabs);
659c2c66affSColin Finck ok( extent == 0, "GetTabbedTextExtentA returned non-zero on nCount == 0\n");
660c2c66affSColin Finck
661c2c66affSColin Finck extent = GetTabbedTextExtentA( hdc, "x", 1, 1, tabs);
662c2c66affSColin Finck cx = LOWORD( extent);
663c2c66affSColin Finck cy = HIWORD( extent);
664c2c66affSColin Finck trace( "cx is %d cy is %d\n", cx, cy);
665c2c66affSColin Finck
666c2c66affSColin Finck align=1;
667c2c66affSColin Finck for( t=-1; t<=1; t++) { /* slightly adjust the 4 char tabstop, to
668c2c66affSColin Finck catch the one off errors */
669c2c66affSColin Finck tab = (cx *4 + t);
670c2c66affSColin Finck /* test the special case tabcount =1 and the general array (80 of tabs */
671c2c66affSColin Finck for( tabcount = 1; tabcount <= 8; tabcount +=7) {
672c2c66affSColin Finck TABTEST( align * tab, tabcount, "\t", MAKELONG(tab, cy))
673c2c66affSColin Finck TABTEST( align * tab, tabcount, "xxx\t", MAKELONG(tab, cy))
674c2c66affSColin Finck TABTEST( align * tab, tabcount, "\tx", MAKELONG(tab+cx, cy))
675c2c66affSColin Finck TABTEST( align * tab, tabcount, "\t\t", MAKELONG(tab*2, cy))
676c2c66affSColin Finck TABTEST( align * tab, tabcount, "\tx\t", MAKELONG(tab*2, cy))
677c2c66affSColin Finck TABTEST( align * tab, tabcount, "x\tx", MAKELONG(tab+cx, cy))
678c2c66affSColin Finck TABTEST( align * tab, tabcount, "xx\tx", MAKELONG(tab+cx, cy))
679c2c66affSColin Finck TABTEST( align * tab, tabcount, "xxx\tx", MAKELONG(tab+cx, cy))
680c2c66affSColin Finck TABTEST( align * tab, tabcount, "xxxx\tx", MAKELONG(t>0 ? tab + cx : 2*tab+cx, cy))
681c2c66affSColin Finck TABTEST( align * tab, tabcount, "xxxxx\tx", MAKELONG(2*tab+cx, cy))
682c2c66affSColin Finck }
683c2c66affSColin Finck }
684c2c66affSColin Finck align=-1;
685c2c66affSColin Finck for( t=-1; t<=1; t++) { /* slightly adjust the 4 char tabstop, to
686c2c66affSColin Finck catch the one off errors */
687c2c66affSColin Finck tab = (cx *4 + t);
688c2c66affSColin Finck /* test the special case tabcount =1 and the general array (8) of tabs */
689c2c66affSColin Finck for( tabcount = 1; tabcount <= 8; tabcount +=7) {
690c2c66affSColin Finck TABTEST( align * tab, tabcount, "\t", MAKELONG(tab, cy))
691c2c66affSColin Finck TABTEST( align * tab, tabcount, "xxx\t", MAKELONG(tab, cy))
692c2c66affSColin Finck TABTEST( align * tab, tabcount, "\tx", MAKELONG(tab, cy))
693c2c66affSColin Finck TABTEST( align * tab, tabcount, "\t\t", MAKELONG(tab*2, cy))
694c2c66affSColin Finck TABTEST( align * tab, tabcount, "\tx\t", MAKELONG(tab*2, cy))
695c2c66affSColin Finck TABTEST( align * tab, tabcount, "x\tx", MAKELONG(tab, cy))
696c2c66affSColin Finck TABTEST( align * tab, tabcount, "xx\tx", MAKELONG(tab, cy))
697c2c66affSColin Finck TABTEST( align * tab, tabcount, "xxx\tx", MAKELONG(4 * cx >= tab ? 2*tab :tab, cy))
698c2c66affSColin Finck TABTEST( align * tab, tabcount, "xxxx\tx", MAKELONG(2*tab, cy))
699c2c66affSColin Finck TABTEST( align * tab, tabcount, "xxxxx\tx", MAKELONG(2*tab, cy))
700c2c66affSColin Finck }
701c2c66affSColin Finck }
702c2c66affSColin Finck
703c2c66affSColin Finck ReleaseDC( hwnd, hdc );
704c2c66affSColin Finck DestroyWindow( hwnd );
705c2c66affSColin Finck }
706c2c66affSColin Finck
test_DrawState(void)707c2c66affSColin Finck static void test_DrawState(void)
708c2c66affSColin Finck {
709c2c66affSColin Finck static const char text[] = "Sample text string";
710c2c66affSColin Finck HWND hwnd;
711c2c66affSColin Finck HDC hdc;
712c2c66affSColin Finck BOOL ret;
713c2c66affSColin Finck
714c2c66affSColin Finck hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
715c2c66affSColin Finck 0, 0, 200, 200, 0, 0, 0, NULL);
716c2c66affSColin Finck assert(hwnd);
717c2c66affSColin Finck
718c2c66affSColin Finck hdc = GetDC(hwnd);
719c2c66affSColin Finck assert(hdc);
720c2c66affSColin Finck
721c2c66affSColin Finck SetLastError(0xdeadbeef);
722c2c66affSColin Finck ret = DrawStateA(hdc, GetStockObject(DKGRAY_BRUSH), NULL, (LPARAM)text, strlen(text),
723c2c66affSColin Finck 0, 0, 10, 10, DST_TEXT);
724c2c66affSColin Finck ok(ret, "DrawState error %u\n", GetLastError());
725c2c66affSColin Finck
726c2c66affSColin Finck SetLastError(0xdeadbeef);
727c2c66affSColin Finck ret = DrawStateA(hdc, GetStockObject(DKGRAY_BRUSH), NULL, (LPARAM)text, 0,
728c2c66affSColin Finck 0, 0, 10, 10, DST_TEXT);
729c2c66affSColin Finck ok(ret, "DrawState error %u\n", GetLastError());
730c2c66affSColin Finck
731c2c66affSColin Finck SetLastError(0xdeadbeef);
732c2c66affSColin Finck ret = DrawStateA(hdc, GetStockObject(DKGRAY_BRUSH), NULL, 0, strlen(text),
733c2c66affSColin Finck 0, 0, 10, 10, DST_TEXT);
734c2c66affSColin Finck ok(!ret || broken(ret) /* win98 */, "DrawState succeeded\n");
735c2c66affSColin Finck ok(GetLastError() == 0xdeadbeef, "not expected error %u\n", GetLastError());
736c2c66affSColin Finck
737c2c66affSColin Finck SetLastError(0xdeadbeef);
738c2c66affSColin Finck ret = DrawStateA(hdc, GetStockObject(DKGRAY_BRUSH), NULL, 0, 0,
739c2c66affSColin Finck 0, 0, 10, 10, DST_TEXT);
740c2c66affSColin Finck ok(!ret || broken(ret) /* win98 */, "DrawState succeeded\n");
741c2c66affSColin Finck ok(GetLastError() == 0xdeadbeef, "not expected error %u\n", GetLastError());
742c2c66affSColin Finck
743c2c66affSColin Finck ReleaseDC(hwnd, hdc);
744c2c66affSColin Finck DestroyWindow(hwnd);
745c2c66affSColin Finck }
746c2c66affSColin Finck
test_CharToOem_OemToChar(void)747c2c66affSColin Finck static void test_CharToOem_OemToChar(void)
748c2c66affSColin Finck {
749c2c66affSColin Finck static const WCHAR helloWorldW[] = {'H','e','l','l','o',' ','W','o','r','l','d',0};
750c2c66affSColin Finck static const WCHAR emptyW[] = {0};
751c2c66affSColin Finck static const char helloWorld[] = "Hello World";
752c2c66affSColin Finck static const struct
753c2c66affSColin Finck {
754c2c66affSColin Finck BOOL src, dst, ret;
755c2c66affSColin Finck }
756c2c66affSColin Finck tests[] =
757c2c66affSColin Finck {
758c2c66affSColin Finck { FALSE, FALSE, FALSE },
759c2c66affSColin Finck { TRUE, FALSE, FALSE },
760c2c66affSColin Finck { FALSE, TRUE, FALSE },
761c2c66affSColin Finck { TRUE, TRUE, TRUE },
762c2c66affSColin Finck };
763c2c66affSColin Finck BOOL ret;
764c2c66affSColin Finck int i;
765c2c66affSColin Finck char oem;
766c2c66affSColin Finck WCHAR uni, expect;
767c2c66affSColin Finck
768*7a62c32bSAmine Khaldi for (i = 0; i < ARRAY_SIZE(tests); i++)
769c2c66affSColin Finck {
770c2c66affSColin Finck const char *expected = tests[i].ret ? helloWorld : "";
771c2c66affSColin Finck const char *src = tests[i].src ? helloWorld : NULL;
772c2c66affSColin Finck char buf[64], *dst = tests[i].dst ? buf : NULL;
773c2c66affSColin Finck
774c2c66affSColin Finck memset(buf, 0, sizeof(buf));
775c2c66affSColin Finck ret = CharToOemA(src, dst);
776c2c66affSColin Finck ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
777c2c66affSColin Finck ok(!strcmp(buf, expected), "test %d: got '%s'\n", i, buf);
778c2c66affSColin Finck
779c2c66affSColin Finck memset(buf, 0, sizeof(buf));
780c2c66affSColin Finck ret = CharToOemBuffA(src, dst, sizeof(helloWorld));
781c2c66affSColin Finck ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
782c2c66affSColin Finck ok(!strcmp(buf, expected), "test %d: got '%s'\n", i, buf);
783c2c66affSColin Finck
784c2c66affSColin Finck memset(buf, 0, sizeof(buf));
785c2c66affSColin Finck ret = OemToCharA(src, dst);
786c2c66affSColin Finck ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
787c2c66affSColin Finck ok(!strcmp(buf, expected), "test %d: got '%s'\n", i, buf);
788c2c66affSColin Finck
789c2c66affSColin Finck memset(buf, 0, sizeof(buf));
790c2c66affSColin Finck ret = OemToCharBuffA(src, dst, sizeof(helloWorld));
791c2c66affSColin Finck ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
792c2c66affSColin Finck ok(!strcmp(buf, expected), "test %d: got '%s'\n", i, buf);
793c2c66affSColin Finck }
794c2c66affSColin Finck
795*7a62c32bSAmine Khaldi for (i = 0; i < ARRAY_SIZE(tests); i++)
796c2c66affSColin Finck {
797c2c66affSColin Finck const char *expected = tests[i].ret ? helloWorld : "";
798c2c66affSColin Finck const WCHAR *src = tests[i].src ? helloWorldW : NULL;
799c2c66affSColin Finck char buf[64], *dst = tests[i].dst ? buf : NULL;
800c2c66affSColin Finck
801c2c66affSColin Finck memset(buf, 0, sizeof(buf));
802c2c66affSColin Finck ret = CharToOemW(src, dst);
803c2c66affSColin Finck ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
804c2c66affSColin Finck ok(!strcmp(buf, expected), "test %d: got '%s'\n", i, buf);
805c2c66affSColin Finck
806c2c66affSColin Finck memset(buf, 0, sizeof(buf));
807*7a62c32bSAmine Khaldi ret = CharToOemBuffW(src, dst, ARRAY_SIZE(helloWorldW));
808c2c66affSColin Finck ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
809c2c66affSColin Finck ok(!strcmp(buf, expected), "test %d: got '%s'\n", i, buf);
810c2c66affSColin Finck }
811c2c66affSColin Finck
812*7a62c32bSAmine Khaldi for (i = 0; i < ARRAY_SIZE(tests); i++)
813c2c66affSColin Finck {
814c2c66affSColin Finck const WCHAR *expected = tests[i].ret ? helloWorldW : emptyW;
815c2c66affSColin Finck const char *src = tests[i].src ? helloWorld : NULL;
816c2c66affSColin Finck WCHAR buf[64], *dst = tests[i].dst ? buf : NULL;
817c2c66affSColin Finck
818c2c66affSColin Finck memset(buf, 0, sizeof(buf));
819c2c66affSColin Finck ret = OemToCharW(src, dst);
820c2c66affSColin Finck ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
821c2c66affSColin Finck ok(!lstrcmpW(buf, expected), "test %d: got '%s'\n", i, wine_dbgstr_w(buf));
822c2c66affSColin Finck
823c2c66affSColin Finck memset(buf, 0, sizeof(buf));
824c2c66affSColin Finck ret = OemToCharBuffW(src, dst, sizeof(helloWorld));
825c2c66affSColin Finck ok(ret == tests[i].ret, "test %d: expected %d, got %d\n", i, tests[i].ret, ret);
826c2c66affSColin Finck ok(!lstrcmpW(buf, expected), "test %d: got '%s'\n", i, wine_dbgstr_w(buf));
827c2c66affSColin Finck }
828c2c66affSColin Finck
829c2c66affSColin Finck for (i = 0; i < 0x100; i++)
830c2c66affSColin Finck {
831c2c66affSColin Finck oem = i;
832c2c66affSColin Finck ret = OemToCharBuffW( &oem, &uni, 1 );
833c2c66affSColin Finck ok( ret, "%02x: returns FALSE\n", i );
834c2c66affSColin Finck MultiByteToWideChar( CP_OEMCP, MB_PRECOMPOSED | MB_USEGLYPHCHARS, &oem, 1, &expect, 1 );
835c2c66affSColin Finck ok( uni == expect, "%02x: got %04x expected %04x\n", i, uni, expect );
836c2c66affSColin Finck }
837c2c66affSColin Finck }
838c2c66affSColin Finck
START_TEST(text)839c2c66affSColin Finck START_TEST(text)
840c2c66affSColin Finck {
841c2c66affSColin Finck test_TabbedText();
842c2c66affSColin Finck test_DrawTextCalcRect();
843c2c66affSColin Finck test_DrawState();
844c2c66affSColin Finck test_CharToOem_OemToChar();
845c2c66affSColin Finck }
846