[PATCH v3] comctl32/tests: Add test for v6 combobox dropdown size

Fabian Maurer dark.shadow4 at web.de
Sun Feb 4 10:04:37 CST 2018


v2: Shorten test and fix style issues
v3: More accurate way to calculate expected list size, style issues

Signed-off-by: Fabian Maurer <dark.shadow4 at web.de>
---
 dlls/comctl32/tests/combo.c | 114 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 114 insertions(+)

diff --git a/dlls/comctl32/tests/combo.c b/dlls/comctl32/tests/combo.c
index 895d9429b4..ee1a100719 100644
--- a/dlls/comctl32/tests/combo.c
+++ b/dlls/comctl32/tests/combo.c
@@ -1151,6 +1151,118 @@ static void test_combo_WS_VSCROLL(void)
     DestroyWindow(hCombo);
 }
 
+
+static void test_combo_dropdown_size(DWORD style)
+{
+    HWND hCombo, hList;
+    COMBOBOXINFO cbInfo;
+    int i, test;
+    const char wine_test[] = "Wine Test";
+    LRESULT ret;
+
+    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(WC_COMBOBOXA, "Combo", CBS_DROPDOWN | 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, "Unexpected number of items: got %d, expected  30\n", min_visible_expected);
+
+        cbInfo.cbSize = sizeof(COMBOBOXINFO);
+        SetLastError(0xdeadbeef);
+        ret = SendMessageA(hCombo, CB_GETCOMBOBOXINFO, 0, (LPARAM)&cbInfo);
+        ok(ret, "Failed to get COMBOBOXINFO structure; LastError: %x\n", GetLastError());
+
+        hList = cbInfo.hwndList;
+        for (i = 0; i < info_test->num_items; i++)
+        {
+            ret = SendMessageA(hCombo, CB_ADDSTRING, 0, (LPARAM) wine_test);
+            ok(ret >= 0, "Failed to add string %d, returned %x\n", i, (int)ret);
+        }
+
+        if (info_test->limit != -1)
+        {
+            int min_visible_actual;
+            min_visible_expected = info_test->limit;
+
+            SetLastError(0xdeadbeef);
+            ret = SendMessageA(hCombo, CB_SETMINVISIBLE, min_visible_expected, 0);
+            todo_wine
+            ok(ret, "SendMessageA failed for CB_SETMINVISIBLE\n");
+            min_visible_actual = SendMessageA(hCombo, CB_GETMINVISIBLE, 0, 0);
+            todo_wine
+            ok(min_visible_expected == min_visible_actual, "Unexpected number of items: got %d, expected %d\n",
+                    min_visible_actual, min_visible_expected);
+        }
+
+        ret = SendMessageA(hCombo, CB_SHOWDROPDOWN, TRUE,0);
+        ok(ret, "SendMessage for CB_SHOWDROPDOWN failed\n");
+        ret = SendMessageA(hCombo, CB_GETDROPPEDSTATE, 0, 0);
+        ok(ret, "The dropdown list should have appeared.\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;
+            int edit_padding_size = cbInfo.rcItem.top; /* edit client rect top is the padding it has to its parent
+                                                          We assume it's the same on the bottom */
+
+            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      /* Take height we created combobox with */
+                    - (cbInfo.rcItem.bottom - cbInfo.rcItem.top)  /* Subtract size of edit control */
+                    - list_height_nonclient                       /* Subtract list nonclient area */
+                    - edit_padding_size * 2;                      /* subtract space around the edit control */
+
+            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 +1304,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(0);
+    test_combo_dropdown_size(CBS_NOINTEGRALHEIGHT);
 
     cleanup();
     unload_v6_module(ctx_cookie, hCtx);
-- 
2.16.1




More information about the wine-devel mailing list