1 /* Unit test suite for list boxes.
3 * Copyright 2003 Ferenc Wagner
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.
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.
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
23 #include "wine/test.h"
26 #define WAIT Sleep (1000)
27 #define REDRAW RedrawWindow (handle, NULL, 0, RDW_UPDATENOW)
34 create_listbox (DWORD add_style)
36 HWND handle=CreateWindow ("LISTBOX", "TestList",
37 (LBS_STANDARD & ~LBS_SORT) | add_style,
42 SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) "First added");
43 SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) "Second added");
44 SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) "Third added");
47 ShowWindow (handle, SW_SHOW);
59 int selected, anchor, caret, selcount;
63 struct listbox_prop prop;
64 struct listbox_stat init, init_todo;
65 struct listbox_stat click, click_todo;
66 struct listbox_stat step, step_todo;
70 listbox_query (HWND handle, struct listbox_stat *results)
72 results->selected = SendMessage (handle, LB_GETCURSEL, 0, 0);
73 results->anchor = SendMessage (handle, LB_GETANCHORINDEX, 0, 0);
74 results->caret = SendMessage (handle, LB_GETCARETINDEX, 0, 0);
75 results->selcount = SendMessage (handle, LB_GETSELCOUNT, 0, 0);
79 buttonpress (HWND handle, WORD x, WORD y)
84 SendMessage (handle, WM_LBUTTONDOWN, (WPARAM) MK_LBUTTON, lp);
85 SendMessage (handle, WM_LBUTTONUP , (WPARAM) 0 , lp);
90 keypress (HWND handle, WPARAM keycode, BYTE scancode, BOOL extended)
92 LPARAM lp=1+(scancode<<16)+(extended?KEYEVENTF_EXTENDEDKEY:0);
95 SendMessage (handle, WM_KEYDOWN, keycode, lp);
96 SendMessage (handle, WM_KEYUP , keycode, lp | 0xc000000);
100 #define listbox_field_ok(t, s, f, got) \
101 ok (t.s.f==got.f, "style %#x, step " #s ", field " #f \
102 ": expected %d, got %d\n", (unsigned int)t.prop.add_style, \
105 #define listbox_todo_field_ok(t, s, f, got) \
106 if (t.s##_todo.f) todo_wine { listbox_field_ok(t, s, f, got); } \
107 else listbox_field_ok(t, s, f, got)
109 #define listbox_ok(t, s, got) \
110 listbox_todo_field_ok(t, s, selected, got); \
111 listbox_todo_field_ok(t, s, anchor, got); \
112 listbox_todo_field_ok(t, s, caret, got); \
113 listbox_todo_field_ok(t, s, selcount, got)
116 check (const struct listbox_test test)
118 struct listbox_stat answer;
119 HWND hLB=create_listbox (test.prop.add_style);
122 listbox_query (hLB, &answer);
123 listbox_ok (test, init, answer);
125 SendMessage (hLB, LB_GETITEMRECT, (WPARAM) 1, (LPARAM) &second_item);
126 buttonpress(hLB, (WORD)second_item.left, (WORD)second_item.top);
128 listbox_query (hLB, &answer);
129 listbox_ok (test, click, answer);
131 keypress (hLB, VK_DOWN, 0x50, TRUE);
133 listbox_query (hLB, &answer);
134 listbox_ok (test, step, answer);
140 void check_item_height()
148 hLB = create_listbox (0);
149 ok ((hdc = GetDCEx( hLB, 0, DCX_CACHE )) != 0, "Can't get hdc\n");
150 ok ((font = GetCurrentObject(hdc, OBJ_FONT)) != 0, "Can't get the current font\n");
151 ok (GetTextMetricsW( hdc, &tm ), "Can't read font metrics\n");
152 ReleaseDC( hLB, hdc);
154 ok (SendMessageW(hLB, WM_SETFONT, (WPARAM)font, 0) == 0, "Can't set font\n");
156 itemHeight = SendMessageW(hLB, LB_GETITEMHEIGHT, 0, 0);
157 ok (itemHeight == tm.tmHeight, "Item height wrong, got %d, expecting %ld\n", itemHeight, tm.tmHeight);
162 const struct listbox_test SS =
165 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
166 { 1, 1, 1, LB_ERR}, {0,0,0,0},
167 { 2, 2, 2, LB_ERR}, {0,0,0,0}};
168 /* {selected, anchor, caret, selcount}{TODO fields} */
169 const struct listbox_test SS_NS =
171 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
172 { 1, 1, 1, LB_ERR}, {0,0,0,0},
173 { 2, 2, 2, LB_ERR}, {0,0,0,0}};
174 const struct listbox_test MS =
176 { 0, LB_ERR, 0, 0}, {0,0,0,0},
177 { 1, 1, 1, 1}, {0,0,0,0},
178 { 2, 1, 2, 1}, {0,0,0,0}};
179 const struct listbox_test MS_NS =
180 {{LBS_MULTIPLESEL | LBS_NOSEL},
181 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
182 { 1, 1, 1, LB_ERR}, {0,0,0,0},
183 { 2, 2, 2, LB_ERR}, {0,0,0,0}};
184 const struct listbox_test ES =
186 { 0, LB_ERR, 0, 0}, {0,0,0,0},
187 { 1, 1, 1, 1}, {0,0,0,0},
188 { 2, 2, 2, 1}, {0,0,0,0}};
189 const struct listbox_test ES_NS =
190 {{LBS_EXTENDEDSEL | LBS_NOSEL},
191 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
192 { 1, 1, 1, LB_ERR}, {0,0,0,0},
193 { 2, 2, 2, LB_ERR}, {0,0,0,0}};
194 const struct listbox_test EMS =
195 {{LBS_EXTENDEDSEL | LBS_MULTIPLESEL},
196 { 0, LB_ERR, 0, 0}, {0,0,0,0},
197 { 1, 1, 1, 1}, {0,0,0,0},
198 { 2, 2, 2, 1}, {0,0,0,0}};
199 const struct listbox_test EMS_NS =
200 {{LBS_EXTENDEDSEL | LBS_MULTIPLESEL | LBS_NOSEL},
201 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
202 { 1, 1, 1, LB_ERR}, {0,0,0,0},
203 { 2, 2, 2, LB_ERR}, {0,0,0,0}};
205 trace (" Testing single selection...\n");
207 trace (" ... with NOSEL\n");
209 trace (" Testing multiple selection...\n");
211 trace (" ... with NOSEL\n");
213 trace (" Testing extended selection...\n");
215 trace (" ... with NOSEL\n");
217 trace (" Testing extended and multiple selection...\n");
219 trace (" ... with NOSEL\n");