#include "wine/test.h" #include "windows.h" #include "assert.h" HWND create_listbox (DWORD add_style) { 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")); 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(ex, got) ok (ex.selected==got.selected && \ ex.anchor==got.anchor && \ ex.caret==got.caret, \ "expected {s=%d,a=%d,c=%d}, got {s=%d,a=%d,c=%d}", \ ex.selected, ex.anchor, ex.caret, \ got.selected, got.anchor, got.caret) void buttonpress (HWND handle, WORD x, WORD y) { LPARAM lp=x+(y<<16); assert (0==SendMessage (handle, WM_LBUTTONDOWN, (WPARAM) MK_LBUTTON, lp)); assert (0==SendMessage (handle, WM_LBUTTONUP, (WPARAM) 0, lp)); } void keypress (HWND handle, WPARAM keycode, BYTE scancode, BOOL extended) { LPARAM lp=1+(scancode<<16)+(extended?KEYEVENTF_EXTENDEDKEY:0); assert (0==SendMessage (handle, WM_KEYDOWN, keycode, lp)); assert (0==SendMessage (handle, WM_KEYUP , keycode, lp | 0xc000000)); } void check_buttonpress () { 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 (0); listbox_query (hLB, &answer); listbox_ok (init, answer); buttonpress(hLB, 8, 16); listbox_query (hLB, &answer); listbox_ok (click, answer); keypress (hLB, VK_DOWN, 0x50, 1); listbox_query (hLB, &answer); listbox_ok (down, answer); assert (DestroyWindow (hLB)); } void check_buttonpress_NOSEL () { 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 (LBS_NOSEL); listbox_query (hLB, &answer); listbox_ok (init, answer); buttonpress(hLB, 8, 16); listbox_query (hLB, &answer); listbox_ok (click, answer); keypress (hLB, VK_DOWN, 0x50, 1); listbox_query (hLB, &answer); listbox_ok (down, answer); assert (DestroyWindow (hLB)); } START_TEST(listbox) { check_buttonpress (); check_buttonpress_NOSEL (); }