user32: Fix for failing tests of LB_GETTEXT on listbox on Win98.
[wine/gsoc_dplay.git] / dlls / user32 / tests / listbox.c
blob8009d38f1b524a2de521aedb5ad057d8426a9c6b
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <assert.h>
21 #include <stdarg.h>
22 #include <stdio.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "winnls.h"
30 #include "wine/test.h"
32 #ifdef VISIBLE
33 #define WAIT Sleep (1000)
34 #define REDRAW RedrawWindow (handle, NULL, 0, RDW_UPDATENOW)
35 #else
36 #define WAIT
37 #define REDRAW
38 #endif
40 static const char * const strings[4] = {
41 "First added",
42 "Second added",
43 "Third added",
44 "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."
47 static HWND
48 create_listbox (DWORD add_style, HWND parent)
50 HWND handle;
51 int ctl_id=0;
52 if (parent)
53 ctl_id=1;
54 handle=CreateWindow ("LISTBOX", "TestList",
55 (LBS_STANDARD & ~LBS_SORT) | add_style,
56 0, 0, 100, 100,
57 parent, (HMENU)ctl_id, NULL, 0);
59 assert (handle);
60 SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) strings[0]);
61 SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) strings[1]);
62 SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) strings[2]);
63 SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) strings[3]);
65 #ifdef VISIBLE
66 ShowWindow (handle, SW_SHOW);
67 #endif
68 REDRAW;
70 return handle;
73 struct listbox_prop {
74 DWORD add_style;
77 struct listbox_stat {
78 int selected, anchor, caret, selcount;
81 struct listbox_test {
82 struct listbox_prop prop;
83 struct listbox_stat init, init_todo;
84 struct listbox_stat click, click_todo;
85 struct listbox_stat step, step_todo;
86 struct listbox_stat sel, sel_todo;
89 static void
90 listbox_query (HWND handle, struct listbox_stat *results)
92 results->selected = SendMessage (handle, LB_GETCURSEL, 0, 0);
93 results->anchor = SendMessage (handle, LB_GETANCHORINDEX, 0, 0);
94 results->caret = SendMessage (handle, LB_GETCARETINDEX, 0, 0);
95 results->selcount = SendMessage (handle, LB_GETSELCOUNT, 0, 0);
98 static void
99 buttonpress (HWND handle, WORD x, WORD y)
101 LPARAM lp=x+(y<<16);
103 WAIT;
104 SendMessage (handle, WM_LBUTTONDOWN, (WPARAM) MK_LBUTTON, lp);
105 SendMessage (handle, WM_LBUTTONUP , (WPARAM) 0 , lp);
106 REDRAW;
109 static void
110 keypress (HWND handle, WPARAM keycode, BYTE scancode, BOOL extended)
112 LPARAM lp=1+(scancode<<16)+(extended?KEYEVENTF_EXTENDEDKEY:0);
114 WAIT;
115 SendMessage (handle, WM_KEYDOWN, keycode, lp);
116 SendMessage (handle, WM_KEYUP , keycode, lp | 0xc000000);
117 REDRAW;
120 #define listbox_field_ok(t, s, f, got) \
121 ok (t.s.f==got.f, "style %#x, step " #s ", field " #f \
122 ": expected %d, got %d\n", (unsigned int)t.prop.add_style, \
123 t.s.f, got.f)
125 #define listbox_todo_field_ok(t, s, f, got) \
126 if (t.s##_todo.f) todo_wine { listbox_field_ok(t, s, f, got); } \
127 else listbox_field_ok(t, s, f, got)
129 #define listbox_ok(t, s, got) \
130 listbox_todo_field_ok(t, s, selected, got); \
131 listbox_todo_field_ok(t, s, anchor, got); \
132 listbox_todo_field_ok(t, s, caret, got); \
133 listbox_todo_field_ok(t, s, selcount, got)
135 static void
136 check (const struct listbox_test test)
138 struct listbox_stat answer;
139 HWND hLB=create_listbox (test.prop.add_style, 0);
140 RECT second_item;
141 int i;
142 int res;
144 listbox_query (hLB, &answer);
145 listbox_ok (test, init, answer);
147 SendMessage (hLB, LB_GETITEMRECT, (WPARAM) 1, (LPARAM) &second_item);
148 buttonpress(hLB, (WORD)second_item.left, (WORD)second_item.top);
150 listbox_query (hLB, &answer);
151 listbox_ok (test, click, answer);
153 keypress (hLB, VK_DOWN, 0x50, TRUE);
155 listbox_query (hLB, &answer);
156 listbox_ok (test, step, answer);
158 DestroyWindow (hLB);
159 hLB=create_listbox (test.prop.add_style, 0);
161 SendMessage (hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(1, 2));
162 listbox_query (hLB, &answer);
163 listbox_ok (test, sel, answer);
165 for (i=0;i<4;i++) {
166 DWORD size = SendMessage (hLB, LB_GETTEXTLEN, i, 0);
167 CHAR *txt;
168 WCHAR *txtw;
169 int resA, resW;
171 txt = HeapAlloc (GetProcessHeap(), 0, size+1);
172 memset(txt, 0, size+1);
173 resA=SendMessageA(hLB, LB_GETTEXT, i, (LPARAM)txt);
174 ok(!strcmp (txt, strings[i]), "returned string for item %d does not match %s vs %s\n", i, txt, strings[i]);
176 txtw = HeapAlloc (GetProcessHeap(), 0, 2*size+2);
177 memset(txtw, 0, 2*size+2);
178 resW=SendMessageW(hLB, LB_GETTEXT, i, (LPARAM)txtw);
179 if (resA != resW) {
180 trace("SendMessageW(LB_GETTEXT) not supported on this platform (resA=%d resW=%d), skipping...\n",
181 resA, resW);
182 } else {
183 WideCharToMultiByte( CP_ACP, 0, txtw, -1, txt, size, NULL, NULL );
184 ok(!strcmp (txt, strings[i]), "returned string for item %d does not match %s vs %s\n", i, txt, strings[i]);
187 HeapFree (GetProcessHeap(), 0, txtw);
188 HeapFree (GetProcessHeap(), 0, txt);
191 /* Confirm the count of items, and that an invalid delete does not remove anything */
192 res = SendMessage (hLB, LB_GETCOUNT, 0, 0);
193 ok((res==4), "Expected 4 items, got %d\n", res);
194 res = SendMessage (hLB, LB_DELETESTRING, -1, 0);
195 ok((res==LB_ERR), "Expected LB_ERR items, got %d\n", res);
196 res = SendMessage (hLB, LB_DELETESTRING, 4, 0);
197 ok((res==LB_ERR), "Expected LB_ERR items, got %d\n", res);
198 res = SendMessage (hLB, LB_GETCOUNT, 0, 0);
199 ok((res==4), "Expected 4 items, got %d\n", res);
201 WAIT;
202 DestroyWindow (hLB);
205 static void check_item_height(void)
207 HWND hLB;
208 HDC hdc;
209 HFONT font;
210 TEXTMETRIC tm;
211 INT itemHeight;
213 hLB = create_listbox (0, 0);
214 ok ((hdc = GetDCEx( hLB, 0, DCX_CACHE )) != 0, "Can't get hdc\n");
215 ok ((font = GetCurrentObject(hdc, OBJ_FONT)) != 0, "Can't get the current font\n");
216 ok (GetTextMetrics( hdc, &tm ), "Can't read font metrics\n");
217 ReleaseDC( hLB, hdc);
219 ok (SendMessage(hLB, WM_SETFONT, (WPARAM)font, 0) == 0, "Can't set font\n");
221 itemHeight = SendMessage(hLB, LB_GETITEMHEIGHT, 0, 0);
222 ok (itemHeight == tm.tmHeight, "Item height wrong, got %d, expecting %d\n", itemHeight, tm.tmHeight);
224 DestroyWindow (hLB);
226 hLB = CreateWindow ("LISTBOX", "TestList", LBS_OWNERDRAWVARIABLE,
227 0, 0, 100, 100, NULL, NULL, NULL, 0);
228 itemHeight = SendMessage(hLB, LB_GETITEMHEIGHT, 0, 0);
229 ok(itemHeight == tm.tmHeight, "itemHeight %d\n", itemHeight);
230 itemHeight = SendMessage(hLB, LB_GETITEMHEIGHT, 5, 0);
231 ok(itemHeight == tm.tmHeight, "itemHeight %d\n", itemHeight);
232 itemHeight = SendMessage(hLB, LB_GETITEMHEIGHT, -5, 0);
233 ok(itemHeight == tm.tmHeight, "itemHeight %d\n", itemHeight);
234 DestroyWindow (hLB);
237 static LRESULT WINAPI main_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
239 switch (msg)
241 case WM_DRAWITEM:
243 RECT rc_item, rc_client, rc_clip;
244 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lparam;
246 trace("%p WM_DRAWITEM %08lx %08lx\n", hwnd, wparam, lparam);
248 ok(wparam == dis->CtlID, "got wParam=%08lx instead of %08x\n",
249 wparam, dis->CtlID);
250 ok(dis->CtlType == ODT_LISTBOX, "wrong CtlType %04x\n", dis->CtlType);
252 GetClientRect(dis->hwndItem, &rc_client);
253 trace("hwndItem %p client rect (%d,%d-%d,%d)\n", dis->hwndItem,
254 rc_client.left, rc_client.top, rc_client.right, rc_client.bottom);
255 GetClipBox(dis->hDC, &rc_clip);
256 trace("clip rect (%d,%d-%d,%d)\n", rc_clip.left, rc_clip.top, rc_clip.right, rc_clip.bottom);
257 ok(EqualRect(&rc_client, &rc_clip), "client rect of the listbox should be equal to the clip box\n");
259 trace("rcItem (%d,%d-%d,%d)\n", dis->rcItem.left, dis->rcItem.top,
260 dis->rcItem.right, dis->rcItem.bottom);
261 SendMessage(dis->hwndItem, LB_GETITEMRECT, dis->itemID, (LPARAM)&rc_item);
262 trace("item rect (%d,%d-%d,%d)\n", rc_item.left, rc_item.top, rc_item.right, rc_item.bottom);
263 ok(EqualRect(&dis->rcItem, &rc_item), "item rects are not equal\n");
265 break;
268 default:
269 break;
272 return DefWindowProc(hwnd, msg, wparam, lparam);
275 static void test_ownerdraw(void)
277 WNDCLASS cls;
278 HWND parent, hLB;
279 INT ret;
280 RECT rc;
282 cls.style = 0;
283 cls.lpfnWndProc = main_window_proc;
284 cls.cbClsExtra = 0;
285 cls.cbWndExtra = 0;
286 cls.hInstance = GetModuleHandle(0);
287 cls.hIcon = 0;
288 cls.hCursor = LoadCursor(0, (LPSTR)IDC_ARROW);
289 cls.hbrBackground = GetStockObject(WHITE_BRUSH);
290 cls.lpszMenuName = NULL;
291 cls.lpszClassName = "main_window_class";
292 assert(RegisterClass(&cls));
294 parent = CreateWindowEx(0, "main_window_class", NULL,
295 WS_POPUP | WS_VISIBLE,
296 100, 100, 400, 400,
297 GetDesktopWindow(), 0,
298 GetModuleHandle(0), NULL);
299 assert(parent);
301 hLB = create_listbox(LBS_OWNERDRAWFIXED | WS_CHILD | WS_VISIBLE, parent);
302 assert(hLB);
304 UpdateWindow(hLB);
306 /* make height short enough */
307 SendMessage(hLB, LB_GETITEMRECT, 0, (LPARAM)&rc);
308 SetWindowPos(hLB, 0, 0, 0, 100, rc.bottom - rc.top + 1,
309 SWP_NOZORDER | SWP_NOMOVE);
311 /* make 0 item invisible */
312 SendMessage(hLB, LB_SETTOPINDEX, 1, 0);
313 ret = SendMessage(hLB, LB_GETTOPINDEX, 0, 0);
314 ok(ret == 1, "wrong top index %d\n", ret);
316 SendMessage(hLB, LB_GETITEMRECT, 0, (LPARAM)&rc);
317 trace("item 0 rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
318 ok(!IsRectEmpty(&rc), "empty item rect\n");
319 ok(rc.top < 0, "rc.top is not negative (%d)\n", rc.top);
321 DestroyWindow(hLB);
322 DestroyWindow(parent);
325 #define listbox_test_query(exp, got) \
326 ok(exp.selected == got.selected, "expected selected %d, got %d\n", exp.selected, got.selected); \
327 ok(exp.anchor == got.anchor, "expected anchor %d, got %d\n", exp.anchor, got.anchor); \
328 ok(exp.caret == got.caret, "expected caret %d, got %d\n", exp.caret, got.caret); \
329 ok(exp.selcount == got.selcount, "expected selcount %d, got %d\n", exp.selcount, got.selcount);
331 static void test_selection(void)
333 static const struct listbox_stat test_nosel = { 0, LB_ERR, 0, 0 };
334 static const struct listbox_stat test_1 = { 0, LB_ERR, 0, 2 };
335 static const struct listbox_stat test_2 = { 0, LB_ERR, 0, 3 };
336 static const struct listbox_stat test_3 = { 0, LB_ERR, 0, 4 };
337 HWND hLB;
338 struct listbox_stat answer;
339 INT ret;
341 trace("testing LB_SELITEMRANGE\n");
343 hLB = create_listbox(LBS_EXTENDEDSEL, 0);
344 assert(hLB);
346 listbox_query(hLB, &answer);
347 listbox_test_query(test_nosel, answer);
349 ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(1, 2));
350 ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
351 listbox_query(hLB, &answer);
352 listbox_test_query(test_1, answer);
354 SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
355 listbox_query(hLB, &answer);
356 listbox_test_query(test_nosel, answer);
358 ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(0, 4));
359 ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
360 listbox_query(hLB, &answer);
361 listbox_test_query(test_3, answer);
363 SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
364 listbox_query(hLB, &answer);
365 listbox_test_query(test_nosel, answer);
367 ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(-5, 5));
368 ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
369 listbox_query(hLB, &answer);
370 listbox_test_query(test_nosel, answer);
372 SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
373 listbox_query(hLB, &answer);
374 listbox_test_query(test_nosel, answer);
376 ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(2, 10));
377 ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
378 listbox_query(hLB, &answer);
379 listbox_test_query(test_1, answer);
381 SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
382 listbox_query(hLB, &answer);
383 listbox_test_query(test_nosel, answer);
385 ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(4, 10));
386 ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
387 listbox_query(hLB, &answer);
388 listbox_test_query(test_nosel, answer);
390 SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
391 listbox_query(hLB, &answer);
392 listbox_test_query(test_nosel, answer);
394 ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(10, 1));
395 ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
396 listbox_query(hLB, &answer);
397 listbox_test_query(test_2, answer);
399 SendMessage(hLB, LB_SETSEL, FALSE, (LPARAM)-1);
400 listbox_query(hLB, &answer);
401 listbox_test_query(test_nosel, answer);
403 ret = SendMessage(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(1, -1));
404 ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
405 listbox_query(hLB, &answer);
406 listbox_test_query(test_2, answer);
408 DestroyWindow(hLB);
411 static void test_listbox_height(void)
413 HWND hList;
414 int r, id;
416 hList = CreateWindow( "ListBox", "list test", 0,
417 1, 1, 600, 100, NULL, NULL, NULL, NULL );
418 ok( hList != NULL, "failed to create listbox\n");
420 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi");
421 ok( id == 0, "item id wrong\n");
423 r = SendMessage( hList, LB_SETITEMHEIGHT, 0, MAKELPARAM( 20, 0 ));
424 ok( r == 0, "send message failed\n");
426 r = SendMessage(hList, LB_GETITEMHEIGHT, 0, 0 );
427 ok( r == 20, "height wrong\n");
429 r = SendMessage( hList, LB_SETITEMHEIGHT, 0, MAKELPARAM( 0, 30 ));
430 ok( r == -1, "send message failed\n");
432 r = SendMessage(hList, LB_GETITEMHEIGHT, 0, 0 );
433 ok( r == 20, "height wrong\n");
435 r = SendMessage( hList, LB_SETITEMHEIGHT, 0, MAKELPARAM( 0x100, 0 ));
436 ok( r == -1, "send message failed\n");
438 r = SendMessage(hList, LB_GETITEMHEIGHT, 0, 0 );
439 ok( r == 20, "height wrong\n");
441 r = SendMessage( hList, LB_SETITEMHEIGHT, 0, MAKELPARAM( 0xff, 0 ));
442 ok( r == 0, "send message failed\n");
444 r = SendMessage(hList, LB_GETITEMHEIGHT, 0, 0 );
445 ok( r == 0xff, "height wrong\n");
447 DestroyWindow( hList );
450 static void test_itemfrompoint(void)
452 /* WS_POPUP is required in order to have a more accurate size calculation (
453 without caption). LBS_NOINTEGRALHEIGHT is required in order to test
454 behavior of partially-displayed item.
456 HWND hList = CreateWindow( "ListBox", "list test",
457 WS_VISIBLE|WS_POPUP|LBS_NOINTEGRALHEIGHT,
458 1, 1, 600, 100, NULL, NULL, NULL, NULL );
459 LONG r, id;
460 RECT rc;
462 /* For an empty listbox win2k returns 0x1ffff, win98 returns 0x10000 */
463 r = SendMessage(hList, LB_ITEMFROMPOINT, 0, MAKELPARAM( /* x */ 30, /* y */ 30 ));
464 ok( r == 0x1ffff || r == 0x10000, "ret %x\n", r );
466 r = SendMessage(hList, LB_ITEMFROMPOINT, 0, MAKELPARAM( 700, 30 ));
467 ok( r == 0x1ffff || r == 0x10000, "ret %x\n", r );
469 r = SendMessage(hList, LB_ITEMFROMPOINT, 0, MAKELPARAM( 30, 300 ));
470 ok( r == 0x1ffff || r == 0x10000, "ret %x\n", r );
472 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi");
473 ok( id == 0, "item id wrong\n");
474 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi1");
475 ok( id == 1, "item id wrong\n");
477 r = SendMessage(hList, LB_ITEMFROMPOINT, 0, MAKELPARAM( /* x */ 30, /* y */ 30 ));
478 ok( r == 0x1, "ret %x\n", r );
480 r = SendMessage(hList, LB_ITEMFROMPOINT, 0, MAKELPARAM( /* x */ 30, /* y */ 601 ));
481 ok( r == 0x10001, "ret %x\n", r );
483 /* Resize control so that below assertions about sizes are valid */
484 r = SendMessage( hList, LB_GETITEMRECT, 0, (LPARAM)&rc);
485 ok( r == 1, "ret %x\n", r);
486 r = MoveWindow(hList, 1, 1, 600, (rc.bottom - rc.top + 1) * 9 / 2, TRUE);
487 ok( r != 0, "ret %x\n", r);
489 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi2");
490 ok( id == 2, "item id wrong\n");
491 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi3");
492 ok( id == 3, "item id wrong\n");
493 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi4");
494 ok( id == 4, "item id wrong\n");
495 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi5");
496 ok( id == 5, "item id wrong\n");
497 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi6");
498 ok( id == 6, "item id wrong\n");
499 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi7");
500 ok( id == 7, "item id wrong\n");
502 /* Set the listbox up so that id 1 is at the top, this leaves 5
503 partially visible at the bottom and 6, 7 are invisible */
505 SendMessage( hList, LB_SETTOPINDEX, 1, 0);
506 r = SendMessage( hList, LB_GETTOPINDEX, 0, 0);
507 ok( r == 1, "top %d\n", r);
509 r = SendMessage( hList, LB_GETITEMRECT, 5, (LPARAM)&rc);
510 ok( r == 1, "ret %x\n", r);
511 r = SendMessage( hList, LB_GETITEMRECT, 6, (LPARAM)&rc);
512 ok( r == 0, "ret %x\n", r);
514 r = SendMessage( hList, LB_ITEMFROMPOINT, 0, MAKELPARAM(/* x */ 10, /* y */ 10) );
515 ok( r == 1, "ret %x\n", r);
517 r = SendMessage( hList, LB_ITEMFROMPOINT, 0, MAKELPARAM(1000, 10) );
518 ok( r == 0x10001, "ret %x\n", r );
520 r = SendMessage( hList, LB_ITEMFROMPOINT, 0, MAKELPARAM(10, -10) );
521 ok( r == 0x10001, "ret %x\n", r );
523 r = SendMessage( hList, LB_ITEMFROMPOINT, 0, MAKELPARAM(10, 100) );
524 ok( r == 0x10005, "item %x\n", r );
526 r = SendMessage( hList, LB_ITEMFROMPOINT, 0, MAKELPARAM(10, 200) );
527 ok( r == 0x10005, "item %x\n", r );
529 DestroyWindow( hList );
532 static void test_listbox_item_data(void)
534 HWND hList;
535 int r, id;
537 hList = CreateWindow( "ListBox", "list test", 0,
538 1, 1, 600, 100, NULL, NULL, NULL, NULL );
539 ok( hList != NULL, "failed to create listbox\n");
541 id = SendMessage( hList, LB_ADDSTRING, 0, (LPARAM) "hi");
542 ok( id == 0, "item id wrong\n");
544 r = SendMessage( hList, LB_SETITEMDATA, 0, MAKELPARAM( 20, 0 ));
545 ok(r == TRUE, "LB_SETITEMDATA returned %d instead of TRUE\n", r);
547 r = SendMessage( hList, LB_GETITEMDATA, 0, 0);
548 ok( r == 20, "get item data failed\n");
550 DestroyWindow( hList );
553 START_TEST(listbox)
555 const struct listbox_test SS =
556 /* {add_style} */
557 {{0},
558 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
559 { 1, 1, 1, LB_ERR}, {0,0,0,0},
560 { 2, 2, 2, LB_ERR}, {0,0,0,0},
561 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0}};
562 /* {selected, anchor, caret, selcount}{TODO fields} */
563 const struct listbox_test SS_NS =
564 {{LBS_NOSEL},
565 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
566 { 1, 1, 1, LB_ERR}, {0,0,0,0},
567 { 2, 2, 2, LB_ERR}, {0,0,0,0},
568 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0}};
569 const struct listbox_test MS =
570 {{LBS_MULTIPLESEL},
571 { 0, LB_ERR, 0, 0}, {0,0,0,0},
572 { 1, 1, 1, 1}, {0,0,0,0},
573 { 2, 1, 2, 1}, {0,0,0,0},
574 { 0, LB_ERR, 0, 2}, {0,0,0,0}};
575 const struct listbox_test MS_NS =
576 {{LBS_MULTIPLESEL | LBS_NOSEL},
577 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
578 { 1, 1, 1, LB_ERR}, {0,0,0,0},
579 { 2, 2, 2, LB_ERR}, {0,0,0,0},
580 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0}};
581 const struct listbox_test ES =
582 {{LBS_EXTENDEDSEL},
583 { 0, LB_ERR, 0, 0}, {0,0,0,0},
584 { 1, 1, 1, 1}, {0,0,0,0},
585 { 2, 2, 2, 1}, {0,0,0,0},
586 { 0, LB_ERR, 0, 2}, {0,0,0,0}};
587 const struct listbox_test ES_NS =
588 {{LBS_EXTENDEDSEL | LBS_NOSEL},
589 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
590 { 1, 1, 1, LB_ERR}, {0,0,0,0},
591 { 2, 2, 2, LB_ERR}, {0,0,0,0},
592 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0}};
593 const struct listbox_test EMS =
594 {{LBS_EXTENDEDSEL | LBS_MULTIPLESEL},
595 { 0, LB_ERR, 0, 0}, {0,0,0,0},
596 { 1, 1, 1, 1}, {0,0,0,0},
597 { 2, 2, 2, 1}, {0,0,0,0},
598 { 0, LB_ERR, 0, 2}, {0,0,0,0}};
599 const struct listbox_test EMS_NS =
600 {{LBS_EXTENDEDSEL | LBS_MULTIPLESEL | LBS_NOSEL},
601 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0},
602 { 1, 1, 1, LB_ERR}, {0,0,0,0},
603 { 2, 2, 2, LB_ERR}, {0,0,0,0},
604 {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0}};
606 trace (" Testing single selection...\n");
607 check (SS);
608 trace (" ... with NOSEL\n");
609 check (SS_NS);
610 trace (" Testing multiple selection...\n");
611 check (MS);
612 trace (" ... with NOSEL\n");
613 check (MS_NS);
614 trace (" Testing extended selection...\n");
615 check (ES);
616 trace (" ... with NOSEL\n");
617 check (ES_NS);
618 trace (" Testing extended and multiple selection...\n");
619 check (EMS);
620 trace (" ... with NOSEL\n");
621 check (EMS_NS);
623 check_item_height();
624 test_ownerdraw();
625 test_selection();
626 test_listbox_height();
627 test_itemfrompoint();
628 test_listbox_item_data();