Commit ad1d2157 authored by Hugh McMaster's avatar Hugh McMaster Committed by Alexandre Julliard

user32/tests: Add tests for EM_SETSEL and getting/losing focus in combo boxes.

parent 75d95f68
......@@ -17,6 +17,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <limits.h>
#include <stdarg.h>
#include <stdio.h>
......@@ -537,6 +538,107 @@ static void test_editselection(void)
DestroyWindow(hCombo);
}
static WNDPROC edit_window_proc;
static long setsel_start = 1, setsel_end = 1;
static HWND hCBN_SetFocus, hCBN_KillFocus;
static LRESULT CALLBACK combobox_subclass_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if (msg == EM_SETSEL)
{
setsel_start = wParam;
setsel_end = lParam;
}
return CallWindowProcA(edit_window_proc, hwnd, msg, wParam, lParam);
}
static LRESULT CALLBACK test_window_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_COMMAND:
switch (HIWORD(wParam))
{
case CBN_SETFOCUS:
hCBN_SetFocus = (HWND)lParam;
break;
case CBN_KILLFOCUS:
hCBN_KillFocus = (HWND)lParam;
break;
}
break;
case WM_NEXTDLGCTL:
SetFocus((HWND)wParam);
break;
}
return CallWindowProcA(old_parent_proc, hwnd, msg, wParam, lParam);
}
static void test_editselection_focus(DWORD style)
{
BOOL (WINAPI *pGetComboBoxInfo)(HWND, PCOMBOBOXINFO);
HWND hCombo, hEdit, hButton;
COMBOBOXINFO cbInfo;
BOOL ret;
const char wine_test[] = "Wine Test";
char buffer[16] = {0};
DWORD len;
pGetComboBoxInfo = (void *)GetProcAddress(GetModuleHandleA("user32.dll"), "GetComboBoxInfo");
if (!pGetComboBoxInfo)
{
win_skip("GetComboBoxInfo is not available\n");
return;
}
hCombo = build_combo(style);
cbInfo.cbSize = sizeof(COMBOBOXINFO);
SetLastError(0xdeadbeef);
ret = pGetComboBoxInfo(hCombo, &cbInfo);
ok(ret, "Failed to get COMBOBOXINFO structure; LastError: %u\n", GetLastError());
hEdit = cbInfo.hwndItem;
hButton = CreateWindowA("Button", "OK", WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON,
5, 50, 100, 20, hMainWnd, NULL,
(HINSTANCE)GetWindowLongPtrA(hMainWnd, GWLP_HINSTANCE), NULL);
old_parent_proc = (WNDPROC)SetWindowLongPtrA(hMainWnd, GWLP_WNDPROC, (ULONG_PTR)test_window_proc);
edit_window_proc = (WNDPROC)SetWindowLongPtrA(hEdit, GWLP_WNDPROC, (ULONG_PTR)combobox_subclass_proc);
SendMessageA(hCombo, WM_SETFOCUS, 0, (LPARAM)hEdit);
ok(setsel_start == 0, "Unexpected EM_SETSEL start value; got %ld\n", setsel_start);
todo_wine ok(setsel_end == INT_MAX, "Unexpected EM_SETSEL end value; got %ld\n", setsel_end);
ok(hCBN_SetFocus == hCombo, "Wrong handle set by CBN_SETFOCUS; got %p\n", hCBN_SetFocus);
ok(GetFocus() == hEdit, "hEdit should have keyboard focus\n");
SendMessageA(hMainWnd, WM_NEXTDLGCTL, (WPARAM)hButton, TRUE);
ok(setsel_start == 0, "Unexpected EM_SETSEL start value; got %ld\n", setsel_start);
todo_wine ok(setsel_end == 0, "Unexpected EM_SETSEL end value; got %ld\n", setsel_end);
ok(hCBN_KillFocus == hCombo, "Wrong handle set by CBN_KILLFOCUS; got %p\n", hCBN_KillFocus);
ok(GetFocus() == hButton, "hButton should have keyboard focus\n");
SendMessageA(hCombo, WM_SETTEXT, 0, (LPARAM)wine_test);
SendMessageA(hMainWnd, WM_NEXTDLGCTL, (WPARAM)hCombo, TRUE);
ok(setsel_start == 0, "Unexpected EM_SETSEL start value; got %ld\n", setsel_start);
todo_wine ok(setsel_end == INT_MAX, "Unexpected EM_SETSEL end value; got %ld\n", setsel_end);
ok(hCBN_SetFocus == hCombo, "Wrong handle set by CBN_SETFOCUS; got %p\n", hCBN_SetFocus);
ok(GetFocus() == hEdit, "hEdit should have keyboard focus\n");
SendMessageA(hCombo, WM_GETTEXT, sizeof(buffer), (LPARAM)buffer);
ok(!strcmp(buffer, wine_test), "Unexpected text in edit control; got '%s'\n", buffer);
SendMessageA(hMainWnd, WM_NEXTDLGCTL, (WPARAM)hButton, TRUE);
ok(setsel_start == 0, "Unexpected EM_SETSEL start value; got %ld\n", setsel_start);
todo_wine ok(setsel_end == 0, "Unexpected EM_SETSEL end value; got %ld\n", setsel_end);
ok(hCBN_KillFocus == hCombo, "Wrong handle set by CBN_KILLFOCUS; got %p\n", hCBN_KillFocus);
ok(GetFocus() == hButton, "hButton should have keyboard focus\n");
len = SendMessageA(hCombo, CB_GETEDITSEL, 0, 0);
ok(len == 0, "Unexpected text selection; start: %u, end: %u\n", LOWORD(len), HIWORD(len));
SetWindowLongPtrA(hMainWnd, GWLP_WNDPROC, (ULONG_PTR)old_parent_proc);
DestroyWindow(hButton);
DestroyWindow(hCombo);
}
static void test_listbox_styles(DWORD cb_style)
{
BOOL (WINAPI *pGetComboBoxInfo)(HWND, PCOMBOBOXINFO);
......@@ -606,6 +708,8 @@ START_TEST(combo)
test_changesize(CBS_DROPDOWN);
test_changesize(CBS_DROPDOWNLIST);
test_editselection();
test_editselection_focus(CBS_SIMPLE);
test_editselection_focus(CBS_DROPDOWN);
test_listbox_styles(CBS_SIMPLE);
test_listbox_styles(CBS_DROPDOWN);
test_listbox_styles(CBS_DROPDOWNLIST);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment