In preparation to fix https://bugs.winehq.org/show_bug.cgi?id=56104 and https://bugs.winehq.org/show_bug.cgi?id=42898
-- v3: comctl32/listbox: Add tests for keypresses showing search functionality comctl32/combo: Add tests for keypresses showing search functionality comctl32/listbox: Close a few leaked window handles
From: Fabian Maurer dark.shadow4@web.de
--- dlls/comctl32/tests/listbox.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/dlls/comctl32/tests/listbox.c b/dlls/comctl32/tests/listbox.c index aba91384d15..1e023d5f372 100644 --- a/dlls/comctl32/tests/listbox.c +++ b/dlls/comctl32/tests/listbox.c @@ -735,6 +735,7 @@ static void test_LB_SETCURSEL(void) ok(ret == -1, "Unexpected anchor index %d.\n", ret);
DestroyWindow(hLB); + DestroyWindow(parent); }
static void test_LB_SETSEL(void) @@ -2484,6 +2485,7 @@ static void test_WM_MEASUREITEM(void)
data = SendMessageA(listbox, LB_GETITEMDATA, 0, 0); ok(data == (LRESULT)strings[0], "data = %08Ix, expected %p\n", data, strings[0]); + DestroyWindow(listbox); DestroyWindow(parent);
parent = create_parent(); @@ -2491,6 +2493,8 @@ static void test_WM_MEASUREITEM(void)
data = SendMessageA(listbox, LB_GETITEMDATA, 0, 0); ok(!data, "data = %08Ix\n", data); + DestroyWindow(listbox); + DestroyWindow(parent);
/* LBS_HASSTRINGS */ parent = create_parent();
From: Fabian Maurer dark.shadow4@web.de
--- dlls/comctl32/tests/combo.c | 153 ++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+)
diff --git a/dlls/comctl32/tests/combo.c b/dlls/comctl32/tests/combo.c index 4a58b8763a4..743a6f8630d 100644 --- a/dlls/comctl32/tests/combo.c +++ b/dlls/comctl32/tests/combo.c @@ -1514,6 +1514,158 @@ static void test_comboex_CBEN_GETDISPINFO(void) DestroyWindow(combo); }
+static void get_selected_value(HWND combo, char* selected) +{ + int index; + selected[0] = 0; + index = SendMessageA(combo, CB_GETCURSEL, 0, 0); + SendMessageA(combo, CB_GETLBTEXT, index, (LPARAM)selected); +} + +static void wait_with_messageloop(DWORD ms) +{ + MSG msg; + DWORD start = GetTickCount(); + while (GetTickCount() - start < ms) + { + if (MsgWaitForMultipleObjects(0, NULL, FALSE, 10, QS_ALLINPUT) == WAIT_OBJECT_0) + { + while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) + { + TranslateMessage(&msg); + DispatchMessageA(&msg); + } + } + } +} + + +static void test_combo_keypresses(void) +{ + HWND combo; + BOOL dropped; + int i; + char selected[20]; + const char* strings_to_add[] = { + "b_eta", "a_lpha", "be_ta", "al_pha", "beta", "alpha", "gamma", "epsilon", "le" + }; + + /* Test with an unsorted combo box */ + + combo = create_combobox(CBS_DROPDOWNLIST); + + for (i = 0; i < ARRAY_SIZE(strings_to_add); i++) + { + SendMessageA(combo, CB_ADDSTRING, 0, (LPARAM)strings_to_add[i]); + } + + SendMessageA(combo, WM_CHAR, (WPARAM)'a', 0); + get_selected_value(combo, selected); + ok(!strcmp(selected, "a_lpha"), "Got %s\n", selected); + + SendMessageA(combo, WM_CHAR, (WPARAM)'l', 0); + get_selected_value(combo, selected); + ok(!strcmp(selected, "le"), "Got %s\n", selected); + + SendMessageA(combo, WM_CHAR, (WPARAM)'p', 0); + get_selected_value(combo, selected); + ok(!strcmp(selected, "le"), "Got %s\n", selected); + + SendMessageA(combo, CB_SHOWDROPDOWN, TRUE, 0); + dropped = SendMessageA(combo, CB_GETDROPPEDSTATE, 0, 0); + ok(dropped, "Expected combo box to be dropped\n"); + + SendMessageA(combo, WM_CHAR, (WPARAM)'b', 0); + get_selected_value(combo, selected); + ok(!strcmp(selected, "b_eta"), "Got %s\n", selected); + dropped = SendMessageA(combo, CB_GETDROPPEDSTATE, 0, 0); + todo_wine + ok(dropped, "Expected combo box to be dropped\n"); + + SendMessageA(combo, WM_CHAR, (WPARAM)'e', 0); + get_selected_value(combo, selected); + ok(!strcmp(selected, "epsilon"), "Got %s\n", selected); + dropped = SendMessageA(combo, CB_GETDROPPEDSTATE, 0, 0); + todo_wine + ok(dropped, "Expected combo box to be dropped\n"); + + SendMessageA(combo, WM_CHAR, (WPARAM)'t', 0); + get_selected_value(combo, selected); + ok(!strcmp(selected, "epsilon"), "Got %s\n", selected); + dropped = SendMessageA(combo, CB_GETDROPPEDSTATE, 0, 0); + todo_wine + ok(dropped, "Expected combo box to be dropped\n"); + + DestroyWindow(combo); + + /* Test with a sorted combo box */ + + combo = create_combobox(CBS_DROPDOWNLIST | CBS_SORT); + + for (i = 0; i < ARRAY_SIZE(strings_to_add); i++) + { + SendMessageA(combo, CB_ADDSTRING, 0, (LPARAM)strings_to_add[i]); + } + + SendMessageA(combo, WM_CHAR, (WPARAM)'a', 0); + get_selected_value(combo, selected); + todo_wine + ok(!strcmp(selected, "a_lpha"), "Got %s\n", selected); + + SendMessageA(combo, WM_CHAR, (WPARAM)'l', 0); + get_selected_value(combo, selected); + todo_wine + ok(!strcmp(selected, "al_pha"), "Got %s\n", selected); + + SendMessageA(combo, WM_CHAR, (WPARAM)'p', 0); + get_selected_value(combo, selected); + todo_wine + ok(!strcmp(selected, "alpha"), "Got %s\n", selected); + + SendMessageA(combo, CB_SHOWDROPDOWN, TRUE, 0); + dropped = SendMessageA(combo, CB_GETDROPPEDSTATE, 0, 0); + ok(dropped, "Expected combo box to be dropped\n"); + + SendMessageA(combo, WM_CHAR, (WPARAM)'b', 0); + get_selected_value(combo, selected); + ok(!strcmp(selected, "b_eta"), "Got %s\n", selected); + dropped = SendMessageA(combo, CB_GETDROPPEDSTATE, 0, 0); + todo_wine + ok(dropped, "Expected combo box to be dropped\n"); + + SendMessageA(combo, WM_CHAR, (WPARAM)'e', 0); + get_selected_value(combo, selected); + todo_wine + ok(!strcmp(selected, "be_ta"), "Got %s\n", selected); + dropped = SendMessageA(combo, CB_GETDROPPEDSTATE, 0, 0); + todo_wine + ok(dropped, "Expected combo box to be dropped\n"); + + SendMessageA(combo, WM_CHAR, (WPARAM)'t', 0); + get_selected_value(combo, selected); + todo_wine + ok(!strcmp(selected, "beta"), "Got %s\n", selected); + dropped = SendMessageA(combo, CB_GETDROPPEDSTATE, 0, 0); + todo_wine + ok(dropped, "Expected combo box to be dropped\n"); + + /* Windows needs a certain time to pass until it starts a new search */ + + SendMessageA(combo, WM_CHAR, (WPARAM)'a', 0); + get_selected_value(combo, selected); + todo_wine + ok(!strcmp(selected, "beta"), "Got %s\n", selected); + + wait_with_messageloop(2100); + + SendMessageA(combo, WM_CHAR, (WPARAM)'a', 0); + get_selected_value(combo, selected); + todo_wine + ok(!strcmp(selected, "a_lpha"), "Got %s\n", selected); + + DestroyWindow(combo); +} + START_TEST(combo) { ULONG_PTR ctx_cookie; @@ -1565,6 +1717,7 @@ START_TEST(combo) test_combo_dropdown_size(0); test_combo_dropdown_size(CBS_NOINTEGRALHEIGHT); test_combo_ctlcolor(); + test_combo_keypresses();
cleanup(); unload_v6_module(ctx_cookie, hCtx);
From: Fabian Maurer dark.shadow4@web.de
--- dlls/comctl32/tests/listbox.c | 112 ++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+)
diff --git a/dlls/comctl32/tests/listbox.c b/dlls/comctl32/tests/listbox.c index 1e023d5f372..c3d9103c63d 100644 --- a/dlls/comctl32/tests/listbox.c +++ b/dlls/comctl32/tests/listbox.c @@ -2756,6 +2756,117 @@ static void test_LB_FINDSTRING(void) DestroyWindow( listbox ); }
+static void get_selected_value(HWND list, char* selected) +{ + int index; + selected[0] = 0; + index = SendMessageA(list, LB_GETCURSEL, 0, 0); + SendMessageA(list, LB_GETTEXT, index, (LPARAM)selected); +} + +static void wait_with_messageloop(DWORD ms) +{ + MSG msg; + DWORD start = GetTickCount(); + while (GetTickCount() - start < ms) + { + if (MsgWaitForMultipleObjects(0, NULL, FALSE, 10, QS_ALLINPUT) == WAIT_OBJECT_0) + { + while (PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) + { + TranslateMessage(&msg); + DispatchMessageA(&msg); + } + } + } +} + +static void test_keypresses(void) +{ + HWND list; + int i; + char selected[20]; + const char* strings_to_add[] = { + "b_eta", "a_lpha", "be_ta", "al_pha", "beta", "alpha", "gamma", "epsilon", "le" + }; + + /* Test with an unsorted list */ + + list = CreateWindowA(WC_LISTBOXA, "TestList", (LBS_STANDARD & ~LBS_SORT), 0, 0, 100, 100, NULL, NULL, NULL, 0); + ok(list != NULL, "Failed to create listbox window.\n"); + + for (i = 0; i < ARRAY_SIZE(strings_to_add); i++) + { + SendMessageA(list, LB_ADDSTRING, 0, (LPARAM)strings_to_add[i]); + } + + SendMessageA(list, WM_CHAR, (WPARAM)'a', 0); + get_selected_value(list, selected); + ok(!strcmp(selected, "a_lpha"), "Got %s\n", selected); + + SendMessageA(list, WM_CHAR, (WPARAM)'l', 0); + get_selected_value(list, selected); + ok(!strcmp(selected, "le"), "Got %s\n", selected); + + SendMessageA(list, WM_CHAR, (WPARAM)'p', 0); + get_selected_value(list, selected); + ok(!strcmp(selected, "le"), "Got %s\n", selected); + + SendMessageA(list, WM_CHAR, (WPARAM)'b', 0); + get_selected_value(list, selected); + ok(!strcmp(selected, "b_eta"), "Got %s\n", selected); + + SendMessageA(list, WM_CHAR, (WPARAM)'e', 0); + get_selected_value(list, selected); + ok(!strcmp(selected, "epsilon"), "Got %s\n", selected); + + SendMessageA(list, WM_CHAR, (WPARAM)'t', 0); + get_selected_value(list, selected); + ok(!strcmp(selected, "epsilon"), "Got %s\n", selected); + + DestroyWindow(list); + + /* Test with a sorted list */ + + list = CreateWindowA(WC_LISTBOXA, "TestList", LBS_STANDARD, 0, 0, 100, 100, NULL, NULL, NULL, 0); + + for (i = 0; i < ARRAY_SIZE(strings_to_add); i++) + { + SendMessageA(list, LB_ADDSTRING, 0, (LPARAM)strings_to_add[i]); + } + + SendMessageA(list, WM_CHAR, (WPARAM)'a', 0); + get_selected_value(list, selected); + todo_wine + ok(!strcmp(selected, "a_lpha"), "Got %s\n", selected); + + SendMessageA(list, WM_CHAR, (WPARAM)'l', 0); + get_selected_value(list, selected); + todo_wine + ok(!strcmp(selected, "al_pha"), "Got %s\n", selected); + + SendMessageA(list, WM_CHAR, (WPARAM)'p', 0); + get_selected_value(list, selected); + todo_wine + ok(!strcmp(selected, "alpha"), "Got %s\n", selected); + + /* Windows needs a certain time to pass until it starts a new search */ + + SendMessageA(list, WM_CHAR, (WPARAM)'b', 0); + get_selected_value(list, selected); + todo_wine + ok(!strcmp(selected, "alpha"), "Got %s\n", selected); + + wait_with_messageloop(2100); + + SendMessageA(list, WM_CHAR, (WPARAM)'b', 0); + get_selected_value(list, selected); + todo_wine + ok(!strcmp(selected, "b_eta"), "Got %s\n", selected); + + DestroyWindow(list); +} + START_TEST(listbox) { ULONG_PTR ctx_cookie; @@ -2786,6 +2897,7 @@ START_TEST(listbox) test_LB_SETSEL(); test_LBS_NODATA(); test_LB_FINDSTRING(); + test_keypresses();
unload_v6_module(ctx_cookie, hCtx); }
On Fri Nov 15 15:40:59 2024 +0000, Zhiyi Zhang wrote:
The following tests seem unnecessary.
Thanks, removed
On Sat Nov 16 09:22:43 2024 +0000, Zhiyi Zhang wrote:
A couple hundred milliseconds should be enough and acceptable.
Added a test. It needs 2100 ms (2000 is not enough yet) so I only added one.
Zhiyi Zhang (@zhiyi) commented about dlls/comctl32/tests/listbox.c:
listbox_test_query(test_nosel, answer); ret = SendMessageA(hLB, LB_SELITEMRANGE, TRUE, MAKELPARAM(2, 10)); ok(ret == LB_OKAY, "LB_SELITEMRANGE returned %d instead of LB_OKAY\n", ret);
Add a dot at the end of the commit subject.
Zhiyi Zhang (@zhiyi) commented about dlls/comctl32/tests/combo.c:
DestroyWindow(combo);
}
+static void get_selected_value(HWND combo, char* selected) +{
- int index;
- selected[0] = 0;
- index = SendMessageA(combo, CB_GETCURSEL, 0, 0);
- SendMessageA(combo, CB_GETLBTEXT, index, (LPARAM)selected);
+}
+static void wait_with_messageloop(DWORD ms)
This works but I would rather copy flush_events() from other files and then do a Sleep(2000) and a flush_events(). This way, flush_events may be used for future tests while wait_with_messageloop() is for this test only.
Zhiyi Zhang (@zhiyi) commented about dlls/comctl32/tests/combo.c:
{
TranslateMessage(&msg);
DispatchMessageA(&msg);
}
}
- }
+}
+static void test_combo_keypresses(void) +{
- HWND combo;
- BOOL dropped;
- int i;
- char selected[20];
- const char* strings_to_add[] = {
Let's align the asterisk to the right.