#include "wine/test.h" #include "windows.h" #include "assert.h" #include "unistd.h" HWND create_listbox (DWORD add_style, BOOL visible) { HWND handle=CreateWindow ("LISTBOX", "TestList", (LBS_STANDARD & ~LBS_SORT) | add_style, 0, 0, 100, 100, NULL, NULL, NULL, 0); assert (handle); assert (0==SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) "First added")); assert (1==SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) "Second added")); assert (2==SendMessage (handle, LB_ADDSTRING, 0, (LPARAM) (LPCTSTR) "Third added")); if (visible) { assert (!ShowWindow (handle, SW_SHOW)); assert (RedrawWindow (handle, NULL, 0, RDW_UPDATENOW)); } return handle; } struct listbox_prop { int selected; int anchor; int caret; }; void listbox_query (HWND handle, struct listbox_prop *results) { results->selected = SendMessage (handle, LB_GETCURSEL, 0, 0); results->anchor = SendMessage (handle, LB_GETANCHORINDEX, 0, 0); results->caret = SendMessage (handle, LB_GETCARETINDEX, 0, 0); } #define listbox_ok(style, ex, got) \ ok (ex.selected==got.selected && \ ex.anchor==got.anchor && \ ex.caret==got.caret, \ "style %#x: expected {s=%d,a=%d,c=%d}, got {s=%d,a=%d,c=%d}", \ (unsigned int)style, \ ex.selected, ex.anchor, ex.caret, \ got.selected, got.anchor, got.caret) void buttonpress (HWND handle, WORD x, WORD y, BOOL visible) { LPARAM lp=x+(y<<16); if (visible) sleep (1); assert (!SendMessage (handle, WM_LBUTTONDOWN, (WPARAM) MK_LBUTTON, lp)); assert (!SendMessage (handle, WM_LBUTTONUP , (WPARAM) 0 , lp)); if (visible) assert (RedrawWindow (handle, NULL, 0, RDW_UPDATENOW)); } void keypress (HWND handle, WPARAM keycode, BYTE scancode, BOOL extended, BOOL visible) { LPARAM lp=1+(scancode<<16)+(extended?KEYEVENTF_EXTENDEDKEY:0); if (visible) sleep (1); assert (!SendMessage (handle, WM_KEYDOWN, keycode, lp)); assert (!SendMessage (handle, WM_KEYUP , keycode, lp | 0xc000000)); if (visible) assert (RedrawWindow (handle, NULL, 0, RDW_UPDATENOW)); } void check (DWORD add_style, BOOL visible) { struct listbox_prop answer; const struct listbox_prop init = {LB_ERR,LB_ERR,0}, click = {1,1,1}, down = {2,2,2}; HWND hLB=create_listbox (add_style, visible); RECT second_item; listbox_query (hLB, &answer); listbox_ok (add_style, init, answer); assert (SendMessage (hLB, LB_GETITEMRECT, (WPARAM) 1, (LPARAM) &second_item)); buttonpress(hLB, second_item.left, second_item.top, visible); listbox_query (hLB, &answer); listbox_ok (add_style, click, answer); keypress (hLB, VK_DOWN, 0x50, TRUE, visible); listbox_query (hLB, &answer); listbox_ok (add_style, down, answer); if (visible) sleep (1); assert (DestroyWindow (hLB)); } START_TEST(listbox) { check (0, FALSE); check (LBS_NOSEL, FALSE); }