Jason Edmeades : user32/tests: Combo should preselect all text on first WM_SETFOCUS.

Alexandre Julliard julliard at winehq.org
Mon Jan 25 11:21:17 CST 2010


Module: wine
Branch: master
Commit: 0641192b520fda444e62e0aa84ddc67937f405a0
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=0641192b520fda444e62e0aa84ddc67937f405a0

Author: Jason Edmeades <jason.edmeades at googlemail.com>
Date:   Sun Jan 24 12:37:59 2010 -0800

user32/tests: Combo should preselect all text on first WM_SETFOCUS.

---

 dlls/user32/tests/combo.c |  101 +++++++++++++++++++++++++++++++++++++++++++++
 dlls/user32/tests/edit.c  |    8 ++++
 2 files changed, 109 insertions(+), 0 deletions(-)

diff --git a/dlls/user32/tests/combo.c b/dlls/user32/tests/combo.c
index 8108dce..b0f7488 100644
--- a/dlls/user32/tests/combo.c
+++ b/dlls/user32/tests/combo.c
@@ -401,6 +401,106 @@ static void test_changesize( DWORD style)
     DestroyWindow(hCombo);
 }
 
+static void test_editselection(void)
+{
+    HWND hCombo;
+    INT start,end;
+    HWND hEdit;
+    COMBOBOXINFO cbInfo;
+    BOOL ret;
+    DWORD len;
+    BOOL (WINAPI *pGetComboBoxInfo)(HWND, PCOMBOBOXINFO);
+    char edit[20];
+
+    pGetComboBoxInfo = (void*)GetProcAddress(GetModuleHandleA("user32.dll"), "GetComboBoxInfo");
+    if (!pGetComboBoxInfo){
+        win_skip("GetComboBoxInfo is not available\n");
+        return;
+    }
+
+    /* Build a combo */
+    hCombo = build_combo(CBS_SIMPLE);
+    cbInfo.cbSize = sizeof(COMBOBOXINFO);
+    SetLastError(0xdeadbeef);
+    ret = pGetComboBoxInfo(hCombo, &cbInfo);
+    ok(ret, "Failed to get combobox info structure. LastError=%d\n",
+       GetLastError());
+    hEdit = cbInfo.hwndItem;
+
+    /* Initially combo selection is empty*/
+    len = SendMessage(hCombo, CB_GETEDITSEL, 0,0);
+    ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len));
+    ok(HIWORD(len)==0, "Unexpected end position for selection %d\n", HIWORD(len));
+
+    /* Set some text, and press a key to replace it */
+    edit[0] = 0x00;
+    SendMessage(hCombo, WM_SETTEXT, 0, (LPARAM)"Jason1");
+    SendMessage(hCombo, WM_GETTEXT, sizeof(edit), (LPARAM)edit);
+    ok(strcmp(edit, "Jason1")==0, "Unexpected text retrieved %s\n", edit);
+
+    /* Now what is the selection - still empty */
+    SendMessage(hCombo, CB_GETEDITSEL, (WPARAM)&start, (WPARAM)&end);
+    len = SendMessage(hCombo, CB_GETEDITSEL, 0,0);
+    ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len));
+    ok(HIWORD(len)==0, "Unexpected end position for selection %d\n", HIWORD(len));
+
+    /* Give it focus, and it gets selected */
+    SendMessage(hCombo, WM_SETFOCUS, 0, (LPARAM)hEdit);
+    SendMessage(hCombo, CB_GETEDITSEL, (WPARAM)&start, (WPARAM)&end);
+    len = SendMessage(hCombo, CB_GETEDITSEL, 0,0);
+    ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len));
+    todo_wine ok(HIWORD(len)==6, "Unexpected end position for selection %d\n", HIWORD(len));
+
+    /* Now emulate a key press */
+    edit[0] = 0x00;
+    SendMessage(hCombo, WM_CHAR, 'A', 0x1c0001);
+    SendMessage(hCombo, WM_GETTEXT, sizeof(edit), (LPARAM)edit);
+    todo_wine ok(strcmp(edit, "A")==0, "Unexpected text retrieved %s\n", edit);
+
+    len = SendMessage(hCombo, CB_GETEDITSEL, 0,0);
+    ok(LOWORD(len)==1, "Unexpected start position for selection %d\n", LOWORD(len));
+    ok(HIWORD(len)==1, "Unexpected end position for selection %d\n", HIWORD(len));
+
+    /* Now what happens when it gets more focus a second time - it doesnt reselect */
+    SendMessage(hCombo, WM_SETFOCUS, 0, (LPARAM)hEdit);
+    len = SendMessage(hCombo, CB_GETEDITSEL, 0,0);
+    ok(LOWORD(len)==1, "Unexpected start position for selection %d\n", LOWORD(len));
+    ok(HIWORD(len)==1, "Unexpected end position for selection %d\n", HIWORD(len));
+    DestroyWindow(hCombo);
+
+    /* Start again - Build a combo */
+    hCombo = build_combo(CBS_SIMPLE);
+    cbInfo.cbSize = sizeof(COMBOBOXINFO);
+    SetLastError(0xdeadbeef);
+    ret = pGetComboBoxInfo(hCombo, &cbInfo);
+    ok(ret, "Failed to get combobox info structure. LastError=%d\n",
+       GetLastError());
+    hEdit = cbInfo.hwndItem;
+
+    /* Set some text and give focus so it gets selected */
+    edit[0] = 0x00;
+    SendMessage(hCombo, WM_SETTEXT, 0, (LPARAM)"Jason2");
+    SendMessage(hCombo, WM_GETTEXT, sizeof(edit), (LPARAM)edit);
+    ok(strcmp(edit, "Jason2")==0, "Unexpected text retrieved %s\n", edit);
+
+    SendMessage(hCombo, WM_SETFOCUS, 0, (LPARAM)hEdit);
+
+    /* Now what is the selection */
+    SendMessage(hCombo, CB_GETEDITSEL, (WPARAM)&start, (WPARAM)&end);
+    len = SendMessage(hCombo, CB_GETEDITSEL, 0,0);
+    ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len));
+    todo_wine ok(HIWORD(len)==6, "Unexpected end position for selection %d\n", HIWORD(len));
+
+    /* Now change the selection to the apparently invalid start -1, end -1 and
+       show it means no selection (ie start -1) but cursor at end              */
+    SendMessage(hCombo, CB_SETEDITSEL, 0, -1);
+    edit[0] = 0x00;
+    SendMessage(hCombo, WM_CHAR, 'A', 0x1c0001);
+    SendMessage(hCombo, WM_GETTEXT, sizeof(edit), (LPARAM)edit);
+    todo_wine ok(strcmp(edit, "Jason2A")==0, "Unexpected text retrieved %s\n", edit);
+    DestroyWindow(hCombo);
+}
+
 START_TEST(combo)
 {
     hMainWnd = CreateWindow("static", "Test", WS_OVERLAPPEDWINDOW, 10, 10, 300, 300, NULL, NULL, NULL, 0);
@@ -414,6 +514,7 @@ START_TEST(combo)
     test_WM_LBUTTONDOWN();
     test_changesize(CBS_DROPDOWN);
     test_changesize(CBS_DROPDOWNLIST);
+    test_editselection();
 
     DestroyWindow(hMainWnd);
 }
diff --git a/dlls/user32/tests/edit.c b/dlls/user32/tests/edit.c
index 3b38d30..7ecee13 100644
--- a/dlls/user32/tests/edit.c
+++ b/dlls/user32/tests/edit.c
@@ -869,6 +869,14 @@ static void test_edit_control_3(void)
     ok(lstrlenA(str) == len, "text shouldn't have been truncated\n");
     test_notify(1, 0, 1);
 
+    len = SendMessageA(hWnd, EM_GETSEL, 0, 0);
+    ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len));
+    ok(HIWORD(len)==0, "Unexpected end position for selection %d\n", HIWORD(len));
+    SendMessage(hParent, WM_SETFOCUS, 0, (LPARAM)hWnd);
+    len = SendMessageA(hWnd, EM_GETSEL, 0, 0);
+    ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len));
+    ok(HIWORD(len)==0, "Unexpected end position for selection %d\n", HIWORD(len));
+
     SendMessageA(hWnd, EM_SETLIMITTEXT, 5, 0);
 
     SendMessageA(hWnd, WM_SETTEXT, 0, (LPARAM)"");




More information about the wine-cvs mailing list