kernel: Check for an exe which is always present in a system dir.
[wine.git] / dlls / user / tests / text.c
bloba25b3bfab9cdab6c4f30352b0d6367f822c799cb
1 /*
2 * DrawText tests
4 * Copyright (c) 2004 Zach Gorman
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <assert.h>
23 #include "wine/test.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "winuser.h"
27 #include "winerror.h"
30 static void test_DrawTextCalcRect(void)
32 HWND hwnd;
33 HDC hdc;
34 HFONT hFont, hOldFont;
35 LOGFONTA lf;
36 const char text[] = "Example text for testing DrawText in "
37 "MM_HIENGLISH mode";
38 const WCHAR textW[] = {'W','i','d','e',' ','c','h','a','r',' ',
39 's','t','r','i','n','g','\0'};
40 const WCHAR emptystringW[] = { 0 };
41 INT textlen,textheight;
42 RECT rect = { 0, 0, 100, 0 };
43 BOOL ret;
45 /* Initialization */
46 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
47 0, 0, 200, 200, 0, 0, 0, NULL);
48 ok(hwnd != 0, "CreateWindowExA error %lu\n", GetLastError());
49 hdc = GetDC(hwnd);
50 ok(hdc != 0, "GetDC error %lu\n", GetLastError());
51 trace("hdc %p\n", hdc);
52 textlen = lstrlenA(text);
54 /* LOGFONT initialization */
55 memset(&lf, 0, sizeof(lf));
56 lf.lfCharSet = ANSI_CHARSET;
57 lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
58 lf.lfWeight = FW_DONTCARE;
59 lf.lfHeight = 0; /* mapping mode dependent */
60 lf.lfQuality = DEFAULT_QUALITY;
61 lstrcpyA(lf.lfFaceName, "Arial");
63 /* DrawText in MM_HIENGLISH with DT_CALCRECT */
64 SetMapMode(hdc, MM_HIENGLISH);
65 lf.lfHeight = 100 * 9 / 72; /* 9 point */
66 hFont = CreateFontIndirectA(&lf);
67 ok(hFont != 0, "CreateFontIndirectA error %lu\n",
68 GetLastError());
69 hOldFont = SelectObject(hdc, hFont);
71 textheight = DrawTextA(hdc, text, textlen, &rect, DT_CALCRECT |
72 DT_EXTERNALLEADING | DT_WORDBREAK | DT_NOCLIP | DT_LEFT |
73 DT_NOPREFIX);
74 ok( textheight, "DrawTextA error %lu\n", GetLastError());
76 trace("MM_HIENGLISH rect.bottom %ld\n", rect.bottom);
77 todo_wine ok(rect.bottom < 0, "In MM_HIENGLISH, DrawText with "
78 "DT_CALCRECT should return a negative rectangle bottom. "
79 "(bot=%ld)\n", rect.bottom);
81 SelectObject(hdc, hOldFont);
82 ret = DeleteObject(hFont);
83 ok( ret, "DeleteObject error %lu\n", GetLastError());
86 /* DrawText in MM_TEXT with DT_CALCRECT */
87 SetMapMode(hdc, MM_TEXT);
88 lf.lfHeight = -MulDiv(9, GetDeviceCaps(hdc,
89 LOGPIXELSY), 72); /* 9 point */
90 hFont = CreateFontIndirectA(&lf);
91 ok(hFont != 0, "CreateFontIndirectA error %lu\n",
92 GetLastError());
93 hOldFont = SelectObject(hdc, hFont);
95 textheight = DrawTextA(hdc, text, textlen, &rect, DT_CALCRECT |
96 DT_EXTERNALLEADING | DT_WORDBREAK | DT_NOCLIP | DT_LEFT |
97 DT_NOPREFIX);
98 ok( textheight, "DrawTextA error %lu\n", GetLastError());
100 trace("MM_TEXT rect.bottom %ld\n", rect.bottom);
101 ok(rect.bottom > 0, "In MM_TEXT, DrawText with DT_CALCRECT "
102 "should return a positive rectangle bottom. (bot=%ld)\n",
103 rect.bottom);
105 /* empty or null text should in some cases calc an empty rectangle */
106 /* note: testing the function's return value is useless, it differs
107 * ( 0 or 1) on every Windows version I tried */
108 SetRect( &rect, 10,10, 100, 100);
109 textheight = DrawTextExA(hdc, (char *) text, 0, &rect, DT_CALCRECT, NULL );
110 ok( !(rect.left == rect.right && rect.bottom == rect.top),
111 "rectangle should NOT be empty.\n");
112 SetRect( &rect, 10,10, 100, 100);
113 SetLastError( 0);
114 textheight = DrawTextExA(hdc, "", -1, &rect, DT_CALCRECT, NULL );
115 ok( (rect.left == rect.right && rect.bottom == rect.top),
116 "rectangle should be empty.\n");
117 SetRect( &rect, 10,10, 100, 100);
118 SetLastError( 0);
119 textheight = DrawTextExA(hdc, NULL, -1, &rect, DT_CALCRECT, NULL );
120 ok( (rect.left == rect.right && rect.bottom == rect.top),
121 "rectangle should be empty.\n");
122 SetRect( &rect, 10,10, 100, 100);
123 textheight = DrawTextExA(hdc, NULL, 0, &rect, DT_CALCRECT, NULL );
124 ok( !(rect.left == rect.right && rect.bottom == rect.top),
125 "rectangle should NOT be empty.\n");
127 /* Wide char versions */
128 SetRect( &rect, 10,10, 100, 100);
129 SetLastError( 0);
130 textheight = DrawTextExW(hdc, (WCHAR *) textW, 0, &rect, DT_CALCRECT, NULL );
131 if( GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) {
132 ok( !(rect.left == rect.right && rect.bottom == rect.top),
133 "rectangle should NOT be empty.\n");
134 SetRect( &rect, 10,10, 100, 100);
135 textheight = DrawTextExW(hdc, (WCHAR *) emptystringW, -1, &rect, DT_CALCRECT, NULL );
136 ok( (rect.left == rect.right && rect.bottom == rect.top),
137 "rectangle should be empty.\n");
138 SetRect( &rect, 10,10, 100, 100);
139 textheight = DrawTextExW(hdc, NULL, -1, &rect, DT_CALCRECT, NULL );
140 ok( !(rect.left == rect.right && rect.bottom == rect.top),
141 "rectangle should NOT be empty.\n");
142 SetRect( &rect, 10,10, 100, 100);
143 textheight = DrawTextExW(hdc, NULL, 0, &rect, DT_CALCRECT, NULL );
144 ok( !(rect.left == rect.right && rect.bottom == rect.top),
145 "rectangle should NOT be empty.\n");
148 SelectObject(hdc, hOldFont);
149 ret = DeleteObject(hFont);
150 ok( ret, "DeleteObject error %lu\n", GetLastError());
152 /* Clean up */
153 ret = ReleaseDC(hwnd, hdc);
154 ok( ret, "ReleaseDC error %lu\n", GetLastError());
155 ret = DestroyWindow(hwnd);
156 ok( ret, "DestroyWindow error %lu\n", GetLastError());
159 /* replace tabs by \t */
160 static void strfmt( char *str, char *strout)
162 unsigned int i,j ;
163 for(i=0,j=0;i<=strlen(str);i++,j++)
164 if((strout[j]=str[i])=='\t') {
165 strout[j++]='\\';
166 strout[j]='t';
171 #define TABTEST( tabval, tabcount, string, _exp) \
172 { int i,x_act, x_exp; char strdisp[64];\
173 for(i=0;i<8;i++) tabs[i]=(i+1)*(tabval); \
174 extent = GetTabbedTextExtentA( hdc, string, strlen( string), (tabcount), tabs); \
175 strfmt( string, strdisp); \
176 /* trace( "Extent is %08lx\n", extent); */\
177 x_act = LOWORD( extent); \
178 x_exp = (_exp); \
179 ok( x_act == x_exp, "Test case \"%s\". Text extent is %d, expected %d tab %d tabcount %d\n", \
180 strdisp, x_act, x_exp, tabval, tabcount); \
184 static void test_TabbedText(void)
186 HWND hwnd;
187 HDC hdc;
188 BOOL ret;
189 TEXTMETRICA tm;
190 DWORD extent;
191 INT tabs[8], cx, cy, tab, tabcount,t,align;
193 /* Initialization */
194 hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
195 0, 0, 200, 200, 0, 0, 0, NULL);
196 ok(hwnd != 0, "CreateWindowExA error %lu\n", GetLastError());
197 hdc = GetDC(hwnd);
198 ok(hdc != 0, "GetDC error %lu\n", GetLastError());
200 ret = GetTextMetricsA( hdc, &tm);
201 ok( ret, "GetTextMetrics error %lu\n", GetLastError());
203 extent = GetTabbedTextExtentA( hdc, "x", 1, 1, tabs);
204 cx = LOWORD( extent);
205 cy = HIWORD( extent);
206 trace( "cx is %d cy is %d\n", cx, cy);
208 align=1;
209 for( t=-1; t<=1; t++) { /* slightly adjust the 4 char tabstop, to
210 catch the one off errors */
211 tab = (cx *4 + t);
212 /* test the special case tabcount =1 and the general array (80 of tabs */
213 for( tabcount = 1; tabcount <= 8; tabcount +=7) {
214 TABTEST( align * tab, tabcount, "\t", tab)
215 TABTEST( align * tab, tabcount, "xxx\t", tab)
216 TABTEST( align * tab, tabcount, "\tx", tab+cx)
217 TABTEST( align * tab, tabcount, "\t\t", tab*2)
218 TABTEST( align * tab, tabcount, "\tx\t", tab*2)
219 TABTEST( align * tab, tabcount, "x\tx", tab+cx)
220 TABTEST( align * tab, tabcount, "xx\tx", tab+cx)
221 TABTEST( align * tab, tabcount, "xxx\tx", tab+cx)
222 TABTEST( align * tab, tabcount, "xxxx\tx", t>0 ? tab + cx : 2*tab+cx)
223 TABTEST( align * tab, tabcount, "xxxxx\tx", 2*tab+cx)
226 align=-1;
227 for( t=-1; t<=1; t++) { /* slightly adjust the 4 char tabstop, to
228 catch the one off errors */
229 tab = (cx *4 + t);
230 /* test the special case tabcount =1 and the general array (8) of tabs */
231 for( tabcount = 1; tabcount <= 8; tabcount +=7) {
232 TABTEST( align * tab, tabcount, "\t", tab)
233 TABTEST( align * tab, tabcount, "xxx\t", tab)
234 TABTEST( align * tab, tabcount, "\tx", tab)
235 TABTEST( align * tab, tabcount, "\t\t", tab*2)
236 TABTEST( align * tab, tabcount, "\tx\t", tab*2)
237 TABTEST( align * tab, tabcount, "x\tx", tab)
238 TABTEST( align * tab, tabcount, "xx\tx", tab)
239 TABTEST( align * tab, tabcount, "xxx\tx", 4 * cx >= tab ? 2*tab :tab)
240 TABTEST( align * tab, tabcount, "xxxx\tx", 2*tab)
241 TABTEST( align * tab, tabcount, "xxxxx\tx", 2*tab)
248 START_TEST(text)
250 test_TabbedText();
251 test_DrawTextCalcRect();