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)
33 static const char *strings[4] = {
37 "Fourth added which is very long because at some time we only had a 256 byte character buffer and that was overflowing in one of those applications that had a common dialog file open box and tried to add a 300 characters long custom filter string which of course the code did not like and crashed. Just make sure this string is longer than 256 characters."
41 create_listbox (DWORD add_style)
43 HWND handle=CreateWindow ("LISTBOX", "TestList",
44 (LBS_STANDARD & ~LBS_SORT) | add_style,
49 SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) strings[0]);
50 SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) strings[1]);
51 SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) strings[2]);
52 SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) strings[3]);
55 ShowWindow (handle, SW_SHOW);
67 int selected, anchor, caret, selcount;
71 struct listbox_prop prop;
72 struct listbox_stat init, init_todo;
73 struct listbox_stat click, click_todo;
74 struct listbox_stat step, step_todo;
75 struct listbox_stat sel, sel_todo;
79 listbox_query (HWND handle, struct listbox_stat *results)
81 results->selected = SendMessage (handle, LB_GETCURSEL, 0, 0);
82 results->anchor = SendMessage (handle, LB_GETANCHORINDEX, 0, 0);
83 results->caret = SendMessage (handle, LB_GETCARETINDEX, 0, 0);
84 results->selcount = SendMessage (handle, LB_GETSELCOUNT, 0, 0);
88 buttonpress (HWND handle, WORD x, WORD y)
93 SendMessage (handle, WM_LBUTTONDOWN, (WPARAM) MK_LBUTTON, lp);
94 SendMessage (handle, WM_LBUTTONUP , (WPARAM) 0 , lp);
99 keypress (HWND handle, WPARAM keycode, BYTE scancode, BOOL extended)
101 LPARAM lp=1+(scancode<<16)+(extended?KEYEVENTF_EXTENDEDKEY:0);
104 SendMessage (handle, WM_KEYDOWN, keycode, lp);
105 SendMessage (handle, WM_KEYUP , keycode, lp | 0xc000000);
109 #define listbox_field_ok(t, s, f, got) \
110 ok (t.s.f==got.f, "style %#x, step " #s ", field " #f \
111 ": expected %d, got %d\n", (unsigned int)t.prop.add_style, \
114 #define listbox_todo_field_ok(t, s, f, got) \
115 if (t.s##_todo.f) todo_wine { listbox_field_ok(t, s, f, got); } \
116 else listbox_field_ok(t, s, f, got)
118 #define listbox_ok(t, s, got) \
119 listbox_todo_field_ok(t, s, selected, got); \
120 listbox_todo_field_ok(t, s, anchor, got); \
121 listbox_todo_field_ok(t, s, caret, got); \
122 listbox_todo_field_ok(t, s, selcount, got)
125 check (const struct listbox_test test)
127 struct listbox_stat answer;
128 HWND hLB=create_listbox (test.prop.add_style);
132 listbox_query (hLB, &answer);
133 listbox_ok (test, init, answer);
135 SendMessage (hLB, LB_GETITEMRECT, (WPARAM) 1, (LPARAM) &second_item);
136 buttonpress(hLB, (WORD)second_item.left, (WORD)second_item.top);
138 listbox_query (hLB, &answer);
139 listbox_ok (test, click, answer);
141 keypress (hLB, VK_DOWN, 0x50, TRUE);
143 listbox_query (hLB, &answer);
144 listbox_ok (test, step, answer);
147 hLB=create_listbox (test.prop.add_style);
149 SendMessage (hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(1, 2));
150 listbox_query (hLB, &answer);
151 listbox_ok (test, sel, answer);
154 DWORD size = SendMessage (hLB, LB_GETTEXTLEN, i, 0);
158 txt = HeapAlloc (GetProcessHeap(), 0, size+1);
159 SendMessageA(hLB, LB_GETTEXT, i, (LPARAM)txt);
160 ok(!strcmp (txt, strings[i]), "returned string for item %d does not match %s vs %s\n", i, txt, strings[i]);
162 txtw = HeapAlloc (GetProcessHeap(), 0, 2*size+2);
163 SendMessageW(hLB, LB_GETTEXT, i, (LPARAM)txtw);
164 WideCharToMultiByte( CP_ACP, 0, txtw, -1, txt, size, NULL, NULL );
165 ok(!strcmp (txt, strings[i]), "returned string for item %d does not match %s vs %s\n", i, txt, strings[i]);
167 HeapFree (GetProcessHeap(), 0, txtw);
168 HeapFree (GetProcessHeap(), 0, txt);
175 static void check_item_height(void)
183 hLB = create_listbox (0);
184 ok ((hdc = GetDCEx( hLB, 0, DCX_CACHE )) != 0, "Can't get hdc\n");
185 ok ((font = GetCurrentObject(hdc, OBJ_FONT)) != 0, "Can't get the current font\n");
186 ok (GetTextMetricsW( hdc, &tm ), "Can't read font metrics\n");
187 ReleaseDC( hLB, hdc);
189 ok (SendMessageW(hLB, WM_SETFONT, (WPARAM)font, 0) == 0, "Can't set font\n");
191 itemHeight = SendMessageW(hLB, LB_GETITEMHEIGHT, 0, 0);
192 ok (itemHeight == tm.tmHeight, "Item height wrong, got %d, expecting %ld\n", itemHeight, tm.tmHeight);
199 const struct listbox_test SS =
202 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
203 { 1, 1, 1, LB_ERR}, {0,0,0,0},
204 { 2, 2, 2, LB_ERR}, {0,0,0,0},
205 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0}};
206 /* {selected, anchor, caret, selcount}{TODO fields} */
207 const struct listbox_test SS_NS =
209 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
210 { 1, 1, 1, LB_ERR}, {0,0,0,0},
211 { 2, 2, 2, LB_ERR}, {0,0,0,0},
212 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0}};
213 const struct listbox_test MS =
215 { 0, LB_ERR, 0, 0}, {0,0,0,0},
216 { 1, 1, 1, 1}, {0,0,0,0},
217 { 2, 1, 2, 1}, {0,0,0,0},
218 { 0, LB_ERR, 0, 2}, {0,0,0,0}};
219 const struct listbox_test MS_NS =
220 {{LBS_MULTIPLESEL | LBS_NOSEL},
221 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
222 { 1, 1, 1, LB_ERR}, {0,0,0,0},
223 { 2, 2, 2, LB_ERR}, {0,0,0,0},
224 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0}};
225 const struct listbox_test ES =
227 { 0, LB_ERR, 0, 0}, {0,0,0,0},
228 { 1, 1, 1, 1}, {0,0,0,0},
229 { 2, 2, 2, 1}, {0,0,0,0},
230 { 0, LB_ERR, 0, 2}, {0,0,0,0}};
231 const struct listbox_test ES_NS =
232 {{LBS_EXTENDEDSEL | LBS_NOSEL},
233 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
234 { 1, 1, 1, LB_ERR}, {0,0,0,0},
235 { 2, 2, 2, LB_ERR}, {0,0,0,0},
236 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0}};
237 const struct listbox_test EMS =
238 {{LBS_EXTENDEDSEL | LBS_MULTIPLESEL},
239 { 0, LB_ERR, 0, 0}, {0,0,0,0},
240 { 1, 1, 1, 1}, {0,0,0,0},
241 { 2, 2, 2, 1}, {0,0,0,0},
242 { 0, LB_ERR, 0, 2}, {0,0,0,0}};
243 const struct listbox_test EMS_NS =
244 {{LBS_EXTENDEDSEL | LBS_MULTIPLESEL | LBS_NOSEL},
245 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
246 { 1, 1, 1, LB_ERR}, {0,0,0,0},
247 { 2, 2, 2, LB_ERR}, {0,0,0,0},
248 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0}};
250 trace (" Testing single selection...\n");
252 trace (" ... with NOSEL\n");
254 trace (" Testing multiple selection...\n");
256 trace (" ... with NOSEL\n");
258 trace (" Testing extended selection...\n");
260 trace (" ... with NOSEL\n");
262 trace (" Testing extended and multiple selection...\n");
264 trace (" ... with NOSEL\n");