secur32: Update ntlm_auth version detection to detect new samba4 version numbers.
[wine] / dlls / user / tests / text.c
1 /*
2  * DrawText tests
3  *
4  * Copyright (c) 2004 Zach Gorman
5  *
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.
10  *
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.
15  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307
19  * USA
20  */
21
22 #include <assert.h>
23
24 #include "wine/test.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "winerror.h"
29
30
31 static void test_DrawTextCalcRect(void)
32 {
33     HWND hwnd;
34     HDC hdc;
35     HFONT hFont, hOldFont;
36     LOGFONTA lf;
37     const char text[] = "Example text for testing DrawText in "
38       "MM_HIENGLISH mode";
39     const WCHAR textW[] = {'W','i','d','e',' ','c','h','a','r',' ',
40         's','t','r','i','n','g','\0'};
41     const WCHAR emptystringW[] = { 0 };
42     INT textlen,textheight;
43     RECT rect = { 0, 0, 100, 0 };
44     BOOL ret;
45
46     /* Initialization */
47     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
48                            0, 0, 200, 200, 0, 0, 0, NULL);
49     ok(hwnd != 0, "CreateWindowExA error %lu\n", GetLastError());
50     hdc = GetDC(hwnd);
51     ok(hdc != 0, "GetDC error %lu\n", GetLastError());
52     trace("hdc %p\n", hdc);
53     textlen = lstrlenA(text);
54
55     /* LOGFONT initialization */
56     memset(&lf, 0, sizeof(lf));
57     lf.lfCharSet = ANSI_CHARSET;
58     lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
59     lf.lfWeight = FW_DONTCARE;
60     lf.lfHeight = 0; /* mapping mode dependent */
61     lf.lfQuality = DEFAULT_QUALITY;
62     lstrcpyA(lf.lfFaceName, "Arial");
63
64     /* DrawText in MM_HIENGLISH with DT_CALCRECT */
65     SetMapMode(hdc, MM_HIENGLISH);
66     lf.lfHeight = 100 * 9 / 72; /* 9 point */
67     hFont = CreateFontIndirectA(&lf);
68     ok(hFont != 0, "CreateFontIndirectA error %lu\n",
69        GetLastError());
70     hOldFont = SelectObject(hdc, hFont);
71
72     textheight = DrawTextA(hdc, text, textlen, &rect, DT_CALCRECT |
73        DT_EXTERNALLEADING | DT_WORDBREAK | DT_NOCLIP | DT_LEFT |
74        DT_NOPREFIX);
75     ok( textheight, "DrawTextA error %lu\n", GetLastError());
76
77     trace("MM_HIENGLISH rect.bottom %ld\n", rect.bottom);
78     todo_wine ok(rect.bottom < 0, "In MM_HIENGLISH, DrawText with "
79        "DT_CALCRECT should return a negative rectangle bottom. "
80        "(bot=%ld)\n", rect.bottom);
81
82     SelectObject(hdc, hOldFont);
83     ret = DeleteObject(hFont);
84     ok( ret, "DeleteObject error %lu\n", GetLastError());
85
86
87     /* DrawText in MM_TEXT with DT_CALCRECT */
88     SetMapMode(hdc, MM_TEXT);
89     lf.lfHeight = -MulDiv(9, GetDeviceCaps(hdc,
90        LOGPIXELSY), 72); /* 9 point */
91     hFont = CreateFontIndirectA(&lf);
92     ok(hFont != 0, "CreateFontIndirectA error %lu\n",
93        GetLastError());
94     hOldFont = SelectObject(hdc, hFont);
95
96     textheight = DrawTextA(hdc, text, textlen, &rect, DT_CALCRECT |
97        DT_EXTERNALLEADING | DT_WORDBREAK | DT_NOCLIP | DT_LEFT |
98        DT_NOPREFIX);
99     ok( textheight, "DrawTextA error %lu\n", GetLastError());
100
101     trace("MM_TEXT rect.bottom %ld\n", rect.bottom);
102     ok(rect.bottom > 0, "In MM_TEXT, DrawText with DT_CALCRECT "
103        "should return a positive rectangle bottom. (bot=%ld)\n",
104        rect.bottom);
105
106     /* empty or null text should in some cases calc an empty rectangle */
107     /* note: testing the function's return value is useless, it differs
108      * ( 0 or 1) on every Windows version I tried */
109     SetRect( &rect, 10,10, 100, 100);
110     textheight = DrawTextExA(hdc, (char *) text, 0, &rect, DT_CALCRECT, NULL );
111     ok( !(rect.left == rect.right && rect.bottom == rect.top),
112             "rectangle should NOT be empty.\n");
113     SetRect( &rect, 10,10, 100, 100);
114     SetLastError( 0);
115     textheight = DrawTextExA(hdc, "", -1, &rect, DT_CALCRECT, NULL );
116     ok( (rect.left == rect.right && rect.bottom == rect.top),
117             "rectangle should be empty.\n");
118     SetRect( &rect, 10,10, 100, 100);
119     SetLastError( 0);
120     textheight = DrawTextExA(hdc, NULL, -1, &rect, DT_CALCRECT, NULL );
121     ok( (rect.left == rect.right && rect.bottom == rect.top),
122             "rectangle should be empty.\n");
123     SetRect( &rect, 10,10, 100, 100);
124     textheight = DrawTextExA(hdc, NULL, 0, &rect, DT_CALCRECT, NULL );
125     ok( !(rect.left == rect.right && rect.bottom == rect.top),
126             "rectangle should NOT be empty.\n");
127
128     /* Wide char versions */
129     SetRect( &rect, 10,10, 100, 100);
130     SetLastError( 0);
131     textheight = DrawTextExW(hdc, (WCHAR *) textW, 0, &rect, DT_CALCRECT, NULL );
132     if( GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) {
133         ok( !(rect.left == rect.right && rect.bottom == rect.top),
134                 "rectangle should NOT be empty.\n");
135         SetRect( &rect, 10,10, 100, 100);
136         textheight = DrawTextExW(hdc, (WCHAR *) emptystringW, -1, &rect, DT_CALCRECT, NULL );
137         ok( (rect.left == rect.right && rect.bottom == rect.top),
138                 "rectangle should be empty.\n");
139         SetRect( &rect, 10,10, 100, 100);
140         textheight = DrawTextExW(hdc, NULL, -1, &rect, DT_CALCRECT, NULL );
141         ok( !(rect.left == rect.right && rect.bottom == rect.top),
142                 "rectangle should NOT be empty.\n");
143         SetRect( &rect, 10,10, 100, 100);
144         textheight = DrawTextExW(hdc, NULL, 0, &rect, DT_CALCRECT, NULL );
145         ok( !(rect.left == rect.right && rect.bottom == rect.top),
146                 "rectangle should NOT be empty.\n");
147     }
148    
149     SelectObject(hdc, hOldFont);
150     ret = DeleteObject(hFont);
151     ok( ret, "DeleteObject error %lu\n", GetLastError());
152
153     /* Clean up */
154     ret = ReleaseDC(hwnd, hdc);
155     ok( ret, "ReleaseDC error %lu\n", GetLastError());
156     ret = DestroyWindow(hwnd);
157     ok( ret, "DestroyWindow error %lu\n", GetLastError());
158 }
159
160 /* replace tabs by \t */
161 static void strfmt( char *str, char *strout)
162 {
163     unsigned int i,j ;
164     for(i=0,j=0;i<=strlen(str);i++,j++)
165         if((strout[j]=str[i])=='\t') {
166             strout[j++]='\\';
167             strout[j]='t';
168         }
169 }
170   
171
172 #define TABTEST( tabval, tabcount, string, _exp) \
173 { int i,x_act, x_exp; char strdisp[64];\
174     for(i=0;i<8;i++) tabs[i]=(i+1)*(tabval); \
175     extent = GetTabbedTextExtentA( hdc, string, strlen( string), (tabcount), tabs); \
176     strfmt( string, strdisp); \
177  /*   trace( "Extent is %08lx\n", extent); */\
178     x_act = LOWORD( extent); \
179     x_exp = (_exp); \
180     ok( x_act == x_exp, "Test case \"%s\". Text extent is %d, expected %d tab %d tabcount %d\n", \
181         strdisp, x_act, x_exp, tabval, tabcount); \
182 } \
183
184
185 static void test_TabbedText(void)
186 {
187     HWND hwnd;
188     HDC hdc;
189     BOOL ret;
190     TEXTMETRICA tm;
191     DWORD extent;
192     INT tabs[8], cx, cy, tab, tabcount,t,align;
193
194     /* Initialization */
195     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
196                            0, 0, 200, 200, 0, 0, 0, NULL);
197     ok(hwnd != 0, "CreateWindowExA error %lu\n", GetLastError());
198     hdc = GetDC(hwnd);
199     ok(hdc != 0, "GetDC error %lu\n", GetLastError());
200
201     ret = GetTextMetricsA( hdc, &tm);
202     ok( ret, "GetTextMetrics error %lu\n", GetLastError());
203
204     extent = GetTabbedTextExtentA( hdc, "x", 1, 1, tabs);
205     cx = LOWORD( extent);
206     cy = HIWORD( extent);
207     trace( "cx is %d cy is %d\n", cx, cy);
208
209     align=1;
210     for( t=-1; t<=1; t++) { /* slightly adjust the 4 char tabstop, to 
211                                catch the one off errors */
212         tab =  (cx *4 + t);
213         /* test the special case tabcount =1 and the general array (80 of tabs */
214         for( tabcount = 1; tabcount <= 8; tabcount +=7) { 
215             TABTEST( align * tab, tabcount, "\t", tab)
216             TABTEST( align * tab, tabcount, "xxx\t", tab)
217             TABTEST( align * tab, tabcount, "\tx", tab+cx)
218             TABTEST( align * tab, tabcount, "\t\t", tab*2)
219             TABTEST( align * tab, tabcount, "\tx\t", tab*2)
220             TABTEST( align * tab, tabcount, "x\tx", tab+cx)
221             TABTEST( align * tab, tabcount, "xx\tx", tab+cx)
222             TABTEST( align * tab, tabcount, "xxx\tx", tab+cx)
223             TABTEST( align * tab, tabcount, "xxxx\tx", t>0 ? tab + cx : 2*tab+cx)
224             TABTEST( align * tab, tabcount, "xxxxx\tx", 2*tab+cx)
225         }
226     }
227     align=-1;
228     for( t=-1; t<=1; t++) { /* slightly adjust the 4 char tabstop, to 
229                                catch the one off errors */
230         tab =  (cx *4 + t);
231         /* test the special case tabcount =1 and the general array (8) of tabs */
232         for( tabcount = 1; tabcount <= 8; tabcount +=7) { 
233             TABTEST( align * tab, tabcount, "\t", tab)
234             TABTEST( align * tab, tabcount, "xxx\t", tab)
235             TABTEST( align * tab, tabcount, "\tx", tab)
236             TABTEST( align * tab, tabcount, "\t\t", tab*2)
237             TABTEST( align * tab, tabcount, "\tx\t", tab*2)
238             TABTEST( align * tab, tabcount, "x\tx", tab)
239             TABTEST( align * tab, tabcount, "xx\tx", tab)
240             TABTEST( align * tab, tabcount, "xxx\tx", 4 * cx >= tab ? 2*tab :tab)
241             TABTEST( align * tab, tabcount, "xxxx\tx", 2*tab)
242             TABTEST( align * tab, tabcount, "xxxxx\tx", 2*tab)
243         }
244     }
245
246
247 }
248
249 START_TEST(text)
250 {
251     test_TabbedText();
252     test_DrawTextCalcRect();
253 }