Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com ---
The last batch of tests that should prove the previous patches' behavior matches Windows.
dlls/comctl32/tests/listbox.c | 99 ++++++++++++++++++++++++++++++----- 1 file changed, 87 insertions(+), 12 deletions(-)
diff --git a/dlls/comctl32/tests/listbox.c b/dlls/comctl32/tests/listbox.c index e7777d1..a84adb2 100644 --- a/dlls/comctl32/tests/listbox.c +++ b/dlls/comctl32/tests/listbox.c @@ -167,10 +167,10 @@ static void keypress(HWND handle, WPARAM keycode, BYTE scancode, BOOL extended) listbox_todo_field_ok(t, s, caret, got); \ listbox_todo_field_ok(t, s, selcount, got)
-static void run_test(const struct listbox_test test) +static void run_test(const struct listbox_test test, DWORD extra_styles) { struct listbox_stat answer; - HWND hLB=create_listbox (test.prop.add_style, 0); + HWND hLB=create_listbox (test.prop.add_style | extra_styles, 0); RECT second_item; int i, res;
@@ -190,13 +190,13 @@ static void run_test(const struct listbox_test test)
DestroyWindow(hLB);
- hLB = create_listbox(test.prop.add_style, 0); + hLB = create_listbox(test.prop.add_style | extra_styles, 0);
SendMessageA(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(1, 2)); listbox_query(hLB, &answer); listbox_ok(test, sel, answer);
- for (i = 0; i < 4; i++) + if (!(extra_styles & LBS_NODATA)) for (i = 0; i < 4; i++) { DWORD size = SendMessageA(hLB, LB_GETTEXTLEN, i, 0); int resA, resW; @@ -1809,6 +1809,71 @@ static void test_nodata_invalid_styles( void ) DestroyWindow(parent); }
+static void test_nodata( void ) +{ + static const UINT invalid_idx[] = { -2, 2 }; + static const UINT valid_idx[] = { 0, 1 }; + HWND listbox; + DWORD_PTR data; + INT i, ret; + + listbox = CreateWindowA(WC_LISTBOXA, "TestList", LBS_NODATA | LBS_OWNERDRAWFIXED | WS_VISIBLE, + 0, 0, 100, 100, NULL, NULL, NULL, 0); + ok(listbox != NULL, "last error 0x%08x\n", GetLastError()); + if (!listbox) return; + + ret = SendMessageA(listbox, LB_INSERTSTRING, -1, 0); + ok(ret == 0, "expected 0, got %d\n", ret); + ret = SendMessageA(listbox, LB_INSERTSTRING, -1, 0); + ok(ret == 1, "expected 1, got %d\n", ret); + ret = SendMessageA(listbox, LB_GETCOUNT, 0, 0); + ok(ret == 2, "Expected 2 items, got %d\n", ret); + + /* try invalid indices */ + for (i = 0; i < ARRAY_SIZE(invalid_idx); i++) + { + ret = SendMessageA(listbox, LB_SETITEMDATA, invalid_idx[i], 42); + ok(ret == LB_ERR, "got %d\n", ret); + ret = SendMessageA(listbox, LB_GETTEXTLEN, invalid_idx[i], 0); + ok(ret == LB_ERR, "got %d\n", ret); + if (ret == LB_ERR) + { + ret = SendMessageA(listbox, LB_GETTEXT, invalid_idx[i], (LPARAM)&data); + ok(ret == LB_ERR, "got %d\n", ret); + } + ret = SendMessageA(listbox, LB_GETITEMDATA, invalid_idx[i], 0); + ok(ret == LB_ERR, "got %d\n", ret); + } + + /* valid indices should always retreive zeros */ + for (i = 0; i < ARRAY_SIZE(valid_idx); i++) + { + ret = SendMessageA(listbox, LB_SETITEMDATA, valid_idx[i], 42); + ok(ret == TRUE, "got %d\n", ret); + ret = SendMessageA(listbox, LB_GETTEXTLEN, valid_idx[i], 0); + ok(ret <= sizeof(data), "got %d\n", ret); + if (ret <= sizeof(data)) + { + data = 0xdeadbeef; + ret = SendMessageA(listbox, LB_GETTEXT, valid_idx[i], (LPARAM)&data); + ok(ret <= sizeof(data), "got %d\n", ret); + ok(data == 0, "LB_GETTEXT should retrieve 0 with LBS_NODATA, got 0x%lx\n", data); + } + ret = SendMessageA(listbox, LB_GETITEMDATA, valid_idx[i], 0); + ok(ret == 0, "LB_GETDATA should return 0 with LBS_NODATA, got %d\n", ret); + } + + /* test more invalid messages with LBS_NODATA */ + ret = SendMessageA(listbox, LB_FINDSTRING, 1, 42); + ok(ret == LB_ERR, "got %d\n", ret); + ret = SendMessageA(listbox, LB_FINDSTRINGEXACT, 1, 42); + ok(ret == LB_ERR, "got %d\n", ret); + ret = SendMessageA(listbox, LB_SELECTSTRING, 1, 42); + ok(ret == LB_ERR, "got %d\n", ret); + + DestroyWindow(listbox); +} + static int lb_getlistboxinfo;
static LRESULT WINAPI listbox_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) @@ -2104,14 +2169,23 @@ static void test_listbox(void) { 2, 2, 2, LB_ERR}, {0,0,0,0}, {LB_ERR, LB_ERR, 0, LB_ERR}, {0,0,0,0}};
- run_test(SS); - run_test(SS_NS); - run_test(MS); - run_test(MS_NS); - run_test(ES); - run_test(ES_NS); - run_test(EMS); - run_test(EMS_NS); + run_test(SS, 0); + run_test(SS_NS, 0); + run_test(MS, 0); + run_test(MS_NS, 0); + run_test(ES, 0); + run_test(ES_NS, 0); + run_test(EMS, 0); + run_test(EMS_NS, 0); + + run_test(SS, LBS_NODATA | LBS_OWNERDRAWFIXED); + run_test(SS_NS, LBS_NODATA | LBS_OWNERDRAWFIXED); + run_test(MS, LBS_NODATA | LBS_OWNERDRAWFIXED); + run_test(MS_NS, LBS_NODATA | LBS_OWNERDRAWFIXED); + run_test(ES, LBS_NODATA | LBS_OWNERDRAWFIXED); + run_test(ES_NS, LBS_NODATA | LBS_OWNERDRAWFIXED); + run_test(EMS, LBS_NODATA | LBS_OWNERDRAWFIXED); + run_test(EMS_NS, LBS_NODATA | LBS_OWNERDRAWFIXED); }
static const struct message lb_addstring_ownerdraw_parent_seq[] = @@ -2252,6 +2326,7 @@ START_TEST(listbox) test_listbox_dlgdir(); test_set_count(); test_nodata_invalid_styles(); + test_nodata(); test_GetListBoxInfo(); test_missing_lbuttonup(); test_extents();