[PATCH 10/18] comctl32: TaskDialog - Changed the way tests work, allow them to send messages

Fabian Maurer dark.shadow4 at web.de
Sat Feb 25 10:01:38 CST 2017


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

diff --git a/dlls/comctl32/tests/taskdialog.c b/dlls/comctl32/tests/taskdialog.c
index f18afeb440..99501ab56d 100644
--- a/dlls/comctl32/tests/taskdialog.c
+++ b/dlls/comctl32/tests/taskdialog.c
@@ -36,13 +36,22 @@ static HRESULT (WINAPI *pTaskDialogIndirect)(const TASKDIALOGCONFIG *, int *, in
 
 typedef struct
 {
-   UINT   msg;
-   WPARAM wparam;
-   LPARAM lparam;
+   UINT    msg;
+   WPARAM  wparam;
+   LPARAM  lparam;
+   HRESULT ret;
 
    struct list entry;
 }message_data;
 
+typedef struct
+{
+    UINT        message;
+    WPARAM      wparam;
+    LPARAM      lparam;
+    const CHAR *title_target; /* control text, 0 means it's send to the dialog form instead */
+}message_send_data;
+
 static struct list messages = LIST_INIT(messages);
 
 /* Message lists to test against */
@@ -55,6 +64,39 @@ static const message_data mes_simple_show[] = {
     { TDN_NO_MORE_MESSAGES }
 };
 
+/* Message lists to send */
+
+static const message_send_data mes_send_return[] = {
+    { WM_KEYDOWN, VK_RETURN, 0 },
+    { 0 }
+};
+
+/* Our only way to get a button handle, since GetDlgItem and FindWindowEx don't work for the official taskdialog */
+
+static HWND taskdialog_child;
+BOOL CALLBACK enum_taskdialog_children_proc(HWND hwnd, LPARAM lParam)
+{
+    CHAR text[100];
+    const CHAR *title = (const CHAR *)lParam;
+
+    GetWindowTextA(hwnd, text, sizeof(text));
+
+    if(lstrcmpA(text, title) == 0)
+    {
+        taskdialog_child = hwnd;
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+static HWND get_child_from_title(HWND hwnd_parent, const CHAR *title)
+{
+    taskdialog_child = NULL;
+    EnumChildWindows(hwnd_parent, enum_taskdialog_children_proc, (LPARAM)title);
+    return taskdialog_child;
+}
+
 /* Functions handling message processing */
 
 static void message_add(UINT msg, WPARAM wparam, LPARAM lparam)
@@ -125,19 +167,42 @@ static void ok_sequence_(const message_data *expected_list, const char *file, in
 }
 
 static LONG_PTR backup_ref_data; /* Copy of dwRefData to test against */
+static const message_data *message_list;
+static const message_send_data *message_send_list;
 
 static HRESULT CALLBACK TaskDialogCallbackProc(HWND hwnd, UINT uNotification, WPARAM wParam,
                                                LPARAM lParam, LONG_PTR dwRefData)
 {
+    int max_messages = 0;
+    int message_number = list_count(&messages);
+
     message_add(uNotification, wParam, lParam);
 
     ok(backup_ref_data == dwRefData, "dwRefData is wrong, expected %lu, got %lu\n", backup_ref_data, dwRefData);
 
-    if(uNotification == TDN_CREATED)
+    if(uNotification == TDN_CREATED) /* Send test messages */
     {
-        PostMessageW(hwnd, WM_KEYDOWN, VK_RETURN, 0);
+        const message_send_data *message = message_send_list;
+        while(message->message) /* Iterate over all messages */
+        {
+            if(message->title_target)
+            {
+                HWND hwndChild = get_child_from_title(hwnd, message->title_target);
+                ok(hwndChild != NULL, "Can't find child window.\n");
+                PostMessageW(hwndChild, message->message, message->wparam, message->lparam);
+            }
+            else
+                PostMessageW(hwnd, message->message, message->wparam, message->lparam);
+
+            message++;
+        }
     }
-    return S_OK;
+
+    /* Return the value we specified for that message */
+    while(message_list[max_messages].msg != TDN_NO_MORE_MESSAGES) max_messages++;
+    if(message_number < max_messages)
+        return message_list[message_number].ret;
+    return S_OK; /* Fallback in case we got a message mismatch */
 }
 
 static void test_TaskDialogIndirect(void)
@@ -155,9 +220,11 @@ static void test_TaskDialogIndirect(void)
     info.pfCallback = TaskDialogCallbackProc;
     info.lpCallbackData = backup_ref_data = 0x12345678; /* Set data for callback tests */
 
+    message_list = mes_simple_show;
+    message_send_list = mes_send_return;
     ret = pTaskDialogIndirect(&info, NULL, NULL, NULL);
     ok(ret == S_OK, "Expected S_OK, got %x\n", ret);
-    ok_sequence(mes_simple_show);
+    ok_sequence(message_list);
 
 }
 
-- 
2.12.0




More information about the wine-patches mailing list