Added parser template and made AVISplitter use it.
[wine] / dlls / user / tests / edit.c
1 /* Unit test suite for edit control.
2  *
3  * Copyright 2004 Vitaliy Margolen
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  */
19
20 #include <assert.h>
21 #include <windows.h>
22 #include <commctrl.h>
23
24 #include "wine/test.h"
25
26 HWND create_editcontrol (DWORD style, DWORD exstyle)
27 {
28     HWND handle;
29
30     handle = CreateWindowEx(exstyle,
31                           "EDIT",
32                           NULL,
33                           ES_AUTOHSCROLL | ES_AUTOVSCROLL | style,
34                           10, 10, 300, 300,
35                           NULL, NULL, NULL, NULL);
36     assert (handle);
37     if (winetest_interactive)
38         ShowWindow (handle, SW_SHOW);
39     return handle;
40 }
41
42 static LONG get_edit_style (HWND hwnd)
43 {
44     return GetWindowLongA( hwnd, GWL_STYLE ) & (
45         ES_LEFT |
46 /* FIXME: not implemented
47         ES_CENTER |
48         ES_RIGHT |
49         ES_OEMCONVERT |
50 */
51         ES_MULTILINE |
52         ES_UPPERCASE |
53         ES_LOWERCASE |
54         ES_PASSWORD |
55         ES_AUTOVSCROLL |
56         ES_AUTOHSCROLL |
57         ES_NOHIDESEL |
58         ES_COMBO |
59         ES_READONLY |
60         ES_WANTRETURN |
61         ES_NUMBER
62         );
63 }
64
65 static void set_client_height(HWND Wnd, unsigned Height)
66 {
67     RECT ClientRect, WindowRect;
68
69     GetWindowRect(Wnd, &WindowRect);
70     GetClientRect(Wnd, &ClientRect);
71     SetWindowPos(Wnd, NULL, WindowRect.left, WindowRect.top,
72                  WindowRect.right - WindowRect.left,
73                  Height + (WindowRect.bottom - WindowRect.top) - (ClientRect.bottom - ClientRect.top),
74                  SWP_NOMOVE | SWP_NOZORDER);
75 }
76
77 static void test_edit_control(void)
78 {
79     HWND hwEdit;
80     MSG msMessage;
81     int i;
82     LONG r;
83     HFONT Font, OldFont;
84     HDC Dc;
85     TEXTMETRIC Metrics;
86     RECT FormatRect;
87
88     msMessage.message = WM_KEYDOWN;
89
90     trace("EDIT: Single line\n");
91     hwEdit = create_editcontrol(0, 0);
92     r = get_edit_style(hwEdit);
93     ok(r == (ES_AUTOVSCROLL | ES_AUTOHSCROLL), "Wrong style expected 0xc0 got: 0x%lx\n", r); 
94     for (i=0;i<65535;i++)
95     {
96         msMessage.wParam = i;
97         r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
98         ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS),
99             "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS got %lx\n", r);
100     }
101     DestroyWindow (hwEdit);
102
103     trace("EDIT: Single line want returns\n");
104     hwEdit = create_editcontrol(ES_WANTRETURN, 0);
105     r = get_edit_style(hwEdit);
106     ok(r == (ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN), "Wrong style expected 0x10c0 got: 0x%lx\n", r); 
107     for (i=0;i<65535;i++)
108     {
109         msMessage.wParam = i;
110         r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
111         ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS),
112             "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS got %lx\n", r);
113     }
114     DestroyWindow (hwEdit);
115
116     trace("EDIT: Multiline line\n");
117     hwEdit = create_editcontrol(ES_MULTILINE | WS_VSCROLL | ES_AUTOVSCROLL, 0);
118     r = get_edit_style(hwEdit);
119     ok(r == (ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE), "Wrong style expected 0xc4 got: 0x%lx\n", r); 
120     for (i=0;i<65535;i++)
121     {
122         msMessage.wParam = i;
123         r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
124         ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS),
125             "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS got %lx\n", r);
126     }
127     DestroyWindow (hwEdit);
128
129     trace("EDIT: Multi line want returns\n");
130     hwEdit = create_editcontrol(ES_MULTILINE | WS_VSCROLL | ES_AUTOVSCROLL | ES_WANTRETURN, 0);
131     r = get_edit_style(hwEdit);
132     ok(r == (ES_WANTRETURN | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE), "Wrong style expected 0x10c4 got: 0x%lx\n", r); 
133     for (i=0;i<65535;i++)
134     {
135         msMessage.wParam = i;
136         r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
137         ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS),
138             "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS got %lx\n", r);
139     }
140     DestroyWindow (hwEdit);
141
142     /* Get a stock font for which we can determine the metrics */
143     Font = GetStockObject(SYSTEM_FONT);
144     assert(NULL != Font);
145     Dc = GetDC(NULL);
146     assert(NULL != Dc);
147     OldFont = SelectObject(Dc, Font);
148     assert(NULL != OldFont);
149     if (! GetTextMetrics(Dc, &Metrics))
150     {
151         assert(FALSE);
152     }
153     SelectObject(Dc, OldFont);
154     ReleaseDC(NULL, Dc);
155
156     trace("EDIT: vertical text position\n");
157     hwEdit = create_editcontrol(WS_POPUP, 0);
158     SendMessage(hwEdit, WM_SETFONT, (WPARAM) Font, (LPARAM) FALSE);
159     set_client_height(hwEdit, Metrics.tmHeight - 1);
160     SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
161     ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
162     ok(Metrics.tmHeight - 1 == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight - 1, FormatRect.bottom - FormatRect.top);
163     set_client_height(hwEdit, Metrics.tmHeight);
164     SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
165     ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
166     ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
167     set_client_height(hwEdit, Metrics.tmHeight + 1);
168     SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
169     ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
170     ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
171     set_client_height(hwEdit, Metrics.tmHeight + 2);
172     SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
173     ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
174     ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
175     set_client_height(hwEdit, Metrics.tmHeight + 10);
176     SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
177     ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
178     ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
179     DestroyWindow(hwEdit);
180
181     hwEdit = create_editcontrol(WS_POPUP | WS_BORDER, 0);
182     SendMessage(hwEdit, WM_SETFONT, (WPARAM) Font, (LPARAM) FALSE);
183     set_client_height(hwEdit, Metrics.tmHeight - 1);
184     SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
185     ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
186     ok(Metrics.tmHeight - 1 == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight - 1, FormatRect.bottom - FormatRect.top);
187     set_client_height(hwEdit, Metrics.tmHeight);
188     SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
189     ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
190     ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
191     set_client_height(hwEdit, Metrics.tmHeight + 2);
192     SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
193     ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
194     ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
195     set_client_height(hwEdit, Metrics.tmHeight + 3);
196     SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
197     ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
198     ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
199     set_client_height(hwEdit, Metrics.tmHeight + 4);
200     SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
201     ok(2 == FormatRect.top, "wrong vertical position expected 2 got %ld\n", FormatRect.top);
202     ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
203     set_client_height(hwEdit, Metrics.tmHeight + 10);
204     SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
205     ok(2 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
206     ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
207     DestroyWindow(hwEdit);
208
209     hwEdit = create_editcontrol(WS_POPUP, WS_EX_CLIENTEDGE);
210     SendMessage(hwEdit, WM_SETFONT, (WPARAM) Font, (LPARAM) FALSE);
211     set_client_height(hwEdit, Metrics.tmHeight - 1);
212     SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
213     ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
214     ok(Metrics.tmHeight - 1 == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight - 1, FormatRect.bottom - FormatRect.top);
215     set_client_height(hwEdit, Metrics.tmHeight);
216     SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
217     ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
218     ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
219     set_client_height(hwEdit, Metrics.tmHeight + 1);
220     SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
221     ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
222     ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
223     set_client_height(hwEdit, Metrics.tmHeight + 2);
224     SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
225     ok(1 == FormatRect.top, "wrong vertical position expected 1 got %ld\n", FormatRect.top);
226     ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
227     set_client_height(hwEdit, Metrics.tmHeight + 4);
228     SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
229     ok(1 == FormatRect.top, "wrong vertical position expected 1 got %ld\n", FormatRect.top);
230     ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
231     set_client_height(hwEdit, Metrics.tmHeight + 10);
232     SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
233     ok(1 == FormatRect.top, "wrong vertical position expected 1 got %ld\n", FormatRect.top);
234     ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
235     DestroyWindow(hwEdit);
236
237     hwEdit = create_editcontrol(WS_POPUP | WS_BORDER, WS_EX_CLIENTEDGE);
238     SendMessage(hwEdit, WM_SETFONT, (WPARAM) Font, (LPARAM) FALSE);
239     set_client_height(hwEdit, Metrics.tmHeight - 1);
240     SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
241     ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
242     ok(Metrics.tmHeight - 1 == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight - 1, FormatRect.bottom - FormatRect.top);
243     set_client_height(hwEdit, Metrics.tmHeight);
244     SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
245     ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
246     ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
247     set_client_height(hwEdit, Metrics.tmHeight + 1);
248     SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
249     ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
250     ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
251     set_client_height(hwEdit, Metrics.tmHeight + 2);
252     SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
253     ok(1 == FormatRect.top, "wrong vertical position expected 1 got %ld\n", FormatRect.top);
254     ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
255     set_client_height(hwEdit, Metrics.tmHeight + 4);
256     SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
257     ok(1 == FormatRect.top, "wrong vertical position expected 1 got %ld\n", FormatRect.top);
258     ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
259     set_client_height(hwEdit, Metrics.tmHeight + 10);
260     SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
261     ok(1 == FormatRect.top, "wrong vertical position expected 1 got %ld\n", FormatRect.top);
262     ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
263     DestroyWindow(hwEdit);
264 }
265
266 START_TEST(edit)
267 {
268     test_edit_control();
269 }