[PATCH v2] comctl32/tests: Add test for v6 combobox dropdown size
v2: Shorten test and fix style issues Signed-off-by: Fabian Maurer <dark.shadow4(a)web.de> --- dlls/comctl32/tests/combo.c | 111 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/dlls/comctl32/tests/combo.c b/dlls/comctl32/tests/combo.c index 895d9429b4..47cbdd1059 100644 --- a/dlls/comctl32/tests/combo.c +++ b/dlls/comctl32/tests/combo.c @@ -1151,6 +1151,115 @@ static void test_combo_WS_VSCROLL(void) DestroyWindow(hCombo); } + +static void test_combo_dropdown_size(DWORD style) +{ + HWND hCombo, hList; + COMBOBOXINFO cbInfo; + UINT x, y; + BOOL ret; + int i, test; + const char wine_test[] = "Wine Test"; + const int combo_bordersize = 2; + + static const struct list_size_info + { + int num_items; + int height_combo; + int limit; + } info_height[] = { + {33, 50, -1}, + {35, 50, 40}, + {15, 50, 3}, + }; + + for (test = 0; test < sizeof(info_height) / sizeof(info_height[0]); test++) + { + const struct list_size_info *info_test = &info_height[test]; + int height_item; /* Height of a list item */ + int height_list; /* Height of the list we got */ + int expected_height_list; + RECT rect_list_client; + int min_visible_expected; + + hCombo = CreateWindowA("ComboBox", WC_COMBOBOXA, WS_VISIBLE | WS_CHILD | style, 5, 5, 100, + info_test->height_combo, hMainWnd, (HMENU)COMBO_ID, NULL, 0); + + min_visible_expected = SendMessageA(hCombo, CB_GETMINVISIBLE, 0, 0); + todo_wine + ok(min_visible_expected == 30, "Expected maximum of visible items to be 30, got %d\n", min_visible_expected); + + cbInfo.cbSize = sizeof(COMBOBOXINFO); + SetLastError(0xdeadbeef); + ret = GetComboBoxInfo(hCombo, &cbInfo); + ok(ret, "Failed to get COMBOBOXINFO structure; LastError: %u\n", GetLastError()); + + hList = cbInfo.hwndList; + for (i = 0; i < info_test->num_items; i++) + SendMessageA(hCombo, CB_ADDSTRING, 0, (LPARAM) wine_test); + + if (info_test->limit != -1) + { + int min_visible_actual; + min_visible_expected = info_test->limit; + + SendMessageA(hCombo, CB_SETMINVISIBLE, min_visible_expected, 0); + min_visible_actual = SendMessageA(hCombo, CB_GETMINVISIBLE, 0, 0); + todo_wine + ok(min_visible_expected == min_visible_actual, "Expected maximum of visible items to be %d, got %d\n", + min_visible_expected, min_visible_actual); + } + + /* Click on the button to drop down the list */ + x = cbInfo.rcButton.left + (cbInfo.rcButton.right-cbInfo.rcButton.left)/2; + y = cbInfo.rcButton.top + (cbInfo.rcButton.bottom-cbInfo.rcButton.top)/2; + ret = SendMessageA(hCombo, WM_LBUTTONDOWN, 0, MAKELPARAM(x, y)); + ok(ret, "WM_LBUTTONDOWN was not processed. LastError=%d\n", GetLastError()); + ok(SendMessageA(hCombo, CB_GETDROPPEDSTATE, 0, 0), + "The dropdown list should have appeared after clicking the button.\n"); + + GetClientRect(hList, &rect_list_client); + height_list = rect_list_client.bottom - rect_list_client.top; + height_item = (int)SendMessageA(hList, LB_GETITEMHEIGHT, 0, 0); + + if (style & CBS_NOINTEGRALHEIGHT) + { + RECT rect_list_complete; + int list_height_nonclient; + int list_height_calculated; + + GetWindowRect(hList, &rect_list_complete); + + list_height_nonclient = (rect_list_complete.bottom - rect_list_complete.top) + - (rect_list_client.bottom - rect_list_client.top); + + /* Calculate the expected client size of the listbox popup from the size of the combobox. */ + list_height_calculated = info_test->height_combo + - (cbInfo.rcItem.bottom + combo_bordersize) + - list_height_nonclient + - 1; + + expected_height_list = min(list_height_calculated, height_item * info_test->num_items); + if (expected_height_list < 0) + expected_height_list = 0; + + todo_wine + ok(expected_height_list == height_list, + "Test %d, expected list height to be %d, got %d\n", test, expected_height_list, height_list); + } + else + { + expected_height_list = min(info_test->num_items, min_visible_expected) * height_item; + + todo_wine + ok(expected_height_list == height_list, + "Test %d, expected list height to be %d, got %d\n", test, expected_height_list, height_list); + } + + DestroyWindow(hCombo); + } +} + START_TEST(combo) { ULONG_PTR ctx_cookie; @@ -1192,6 +1301,8 @@ START_TEST(combo) test_combo_listbox_styles(CBS_SIMPLE); test_combo_listbox_styles(CBS_DROPDOWN); test_combo_listbox_styles(CBS_DROPDOWNLIST); + test_combo_dropdown_size(CBS_DROPDOWN); + test_combo_dropdown_size(CBS_DROPDOWN | CBS_NOINTEGRALHEIGHT); cleanup(); unload_v6_module(ctx_cookie, hCtx); -- 2.16.1
On 2/2/2018 12:56 AM, Fabian Maurer wrote:
v2: Shorten test and fix style issues
Signed-off-by: Fabian Maurer <dark.shadow4(a)web.de> --- dlls/comctl32/tests/combo.c | 111 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+)
diff --git a/dlls/comctl32/tests/combo.c b/dlls/comctl32/tests/combo.c index 895d9429b4..47cbdd1059 100644 --- a/dlls/comctl32/tests/combo.c +++ b/dlls/comctl32/tests/combo.c @@ -1151,6 +1151,115 @@ static void test_combo_WS_VSCROLL(void) DestroyWindow(hCombo); }
+ +static void test_combo_dropdown_size(DWORD style) +{ + HWND hCombo, hList; + COMBOBOXINFO cbInfo; + UINT x, y; + BOOL ret; + int i, test; + const char wine_test[] = "Wine Test"; + const int combo_bordersize = 2; + + static const struct list_size_info + { + int num_items; + int height_combo; + int limit; + } info_height[] = { + {33, 50, -1}, + {35, 50, 40}, + {15, 50, 3}, + }; + + for (test = 0; test < sizeof(info_height) / sizeof(info_height[0]); test++) + { + const struct list_size_info *info_test = &info_height[test]; + int height_item; /* Height of a list item */ + int height_list; /* Height of the list we got */ + int expected_height_list; + RECT rect_list_client; + int min_visible_expected; + + hCombo = CreateWindowA("ComboBox", WC_COMBOBOXA, WS_VISIBLE | WS_CHILD | style, 5, 5, 100, + info_test->height_combo, hMainWnd, (HMENU)COMBO_ID, NULL, 0);
First argument is a window class.
+ ok(min_visible_expected == 30, "Expected maximum of visible items to be 30, got %d\n", min_visible_expected);
Shouldn't it say minimum? But I think shorter is better, you can call it unexpected number of items, without specifying expected number at all.
+ cbInfo.cbSize = sizeof(COMBOBOXINFO); + SetLastError(0xdeadbeef); + ret = GetComboBoxInfo(hCombo, &cbInfo); + ok(ret, "Failed to get COMBOBOXINFO structure; LastError: %u\n", GetLastError());
I think CB_GETCOMBOBOXINFO is preferable.
+ for (i = 0; i < info_test->num_items; i++) + SendMessageA(hCombo, CB_ADDSTRING, 0, (LPARAM) wine_test);
...
+ + SendMessageA(hCombo, CB_SETMINVISIBLE, min_visible_expected, 0);
Please check return values for sent messages.
+ + /* Click on the button to drop down the list */ + x = cbInfo.rcButton.left + (cbInfo.rcButton.right-cbInfo.rcButton.left)/2; + y = cbInfo.rcButton.top + (cbInfo.rcButton.bottom-cbInfo.rcButton.top)/2; + ret = SendMessageA(hCombo, WM_LBUTTONDOWN, 0, MAKELPARAM(x, y)); + ok(ret, "WM_LBUTTONDOWN was not processed. LastError=%d\n", GetLastError());
I haven't tested what cbInfo returns exactly, but does this work in RTL case? CB_SHOWDROPDOWN should work better here.
+ ok(SendMessageA(hCombo, CB_GETDROPPEDSTATE, 0, 0), + "The dropdown list should have appeared after clicking the button.\n");
If only for consistency please place call on a separate line.
+ + /* Calculate the expected client size of the listbox popup from the size of the combobox. */ + list_height_calculated = info_test->height_combo + - (cbInfo.rcItem.bottom + combo_bordersize) + - list_height_nonclient + - 1;
It's hard to tell what those constant are about. I.e. should bordersize be 3 actually, or if it's affected by resolution.
+ test_combo_dropdown_size(CBS_DROPDOWN); + test_combo_dropdown_size(CBS_DROPDOWN | CBS_NOINTEGRALHEIGHT);
My understanding is this only applies to CBS_DROPDOWN controls, right? You can use this style unconditionally in CreateWindow().
participants (2)
-
Fabian Maurer -
Nikolay Sivov