2 * Tests for autocomplete
4 * Copyright 2008 Jan de Mooij
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include <wine/test.h>
32 static HWND hMainWnd
, hEdit
;
33 static HINSTANCE hinst
;
34 static int killfocus_count
;
36 static void test_invalid_init(void)
43 /* AutoComplete instance */
44 hr
= CoCreateInstance(&CLSID_AutoComplete
, NULL
, CLSCTX_INPROC_SERVER
,
45 &IID_IAutoComplete
, (void **)&ac
);
46 if (hr
== REGDB_E_CLASSNOTREG
)
48 win_skip("CLSID_AutoComplete is not registered\n");
51 ok(hr
== S_OK
, "no IID_IAutoComplete (0x%08x)\n", hr
);
53 /* AutoComplete source */
54 hr
= CoCreateInstance(&CLSID_ACLMulti
, NULL
, CLSCTX_INPROC_SERVER
,
55 &IID_IACList
, (void **)&acSource
);
56 if (hr
== REGDB_E_CLASSNOTREG
)
58 win_skip("CLSID_ACLMulti is not registered\n");
59 IAutoComplete_Release(ac
);
62 ok(hr
== S_OK
, "no IID_IACList (0x%08x)\n", hr
);
64 edit_control
= CreateWindowExA(0, "EDIT", "Some text", 0, 10, 10, 300, 300,
65 hMainWnd
, NULL
, hinst
, NULL
);
66 ok(edit_control
!= NULL
, "Can't create edit control\n");
68 /* The refcount of acSource would be incremented on older Windows. */
69 hr
= IAutoComplete_Init(ac
, NULL
, acSource
, NULL
, NULL
);
70 ok(hr
== E_INVALIDARG
||
71 broken(hr
== S_OK
), /* Win2k/XP/Win2k3 */
72 "Init returned 0x%08x\n", hr
);
73 if (hr
== E_INVALIDARG
)
77 IUnknown_AddRef(acSource
);
78 ref
= IUnknown_Release(acSource
);
79 ok(ref
== 1, "Expected AutoComplete source refcount to be 1, got %d\n", ref
);
84 /* Older Windows versions never check the window handle, while newer
85 * versions only check for NULL. Subsequent attempts to initialize the
86 * object after this call succeeds would fail, because initialization
87 * state is determined by whether a non-NULL window handle is stored. */
88 hr
= IAutoComplete_Init(ac
, (HWND
)0xdeadbeef, acSource
, NULL
, NULL
);
89 ok(hr
== S_OK
, "Init returned 0x%08x\n", hr
);
91 /* Tests crash on older Windows. */
92 hr
= IAutoComplete_Init(ac
, NULL
, NULL
, NULL
, NULL
);
93 ok(hr
== E_INVALIDARG
, "Init returned 0x%08x\n", hr
);
95 hr
= IAutoComplete_Init(ac
, edit_control
, NULL
, NULL
, NULL
);
96 ok(hr
== E_INVALIDARG
, "Init returned 0x%08x\n", hr
);
99 /* bind to edit control */
100 hr
= IAutoComplete_Init(ac
, edit_control
, acSource
, NULL
, NULL
);
101 ok(hr
== S_OK
, "Init returned 0x%08x\n", hr
);
103 /* try invalid parameters after successful initialization .*/
104 hr
= IAutoComplete_Init(ac
, NULL
, NULL
, NULL
, NULL
);
105 ok(hr
== E_INVALIDARG
||
106 hr
== E_FAIL
, /* Win2k/XP/Win2k3 */
107 "Init returned 0x%08x\n", hr
);
109 hr
= IAutoComplete_Init(ac
, NULL
, acSource
, NULL
, NULL
);
110 ok(hr
== E_INVALIDARG
||
111 hr
== E_FAIL
, /* Win2k/XP/Win2k3 */
112 "Init returned 0x%08x\n", hr
);
114 hr
= IAutoComplete_Init(ac
, edit_control
, NULL
, NULL
, NULL
);
115 ok(hr
== E_INVALIDARG
||
116 hr
== E_FAIL
, /* Win2k/XP/Win2k3 */
117 "Init returned 0x%08x\n", hr
);
119 /* try initializing twice on the same control */
120 hr
= IAutoComplete_Init(ac
, edit_control
, acSource
, NULL
, NULL
);
121 ok(hr
== E_FAIL
, "Init returned 0x%08x\n", hr
);
123 /* try initializing with a different control */
124 hr
= IAutoComplete_Init(ac
, hEdit
, acSource
, NULL
, NULL
);
125 ok(hr
== E_FAIL
, "Init returned 0x%08x\n", hr
);
127 DestroyWindow(edit_control
);
129 /* try initializing with a different control after
130 * destroying the original initialization control */
131 hr
= IAutoComplete_Init(ac
, hEdit
, acSource
, NULL
, NULL
);
132 ok(hr
== E_UNEXPECTED
||
133 hr
== E_FAIL
, /* Win2k/XP/Win2k3 */
134 "Init returned 0x%08x\n", hr
);
136 IUnknown_Release(acSource
);
137 IAutoComplete_Release(ac
);
139 static IAutoComplete
*test_init(void)
146 /* AutoComplete instance */
147 r
= CoCreateInstance(&CLSID_AutoComplete
, NULL
, CLSCTX_INPROC_SERVER
,
148 &IID_IAutoComplete
, (LPVOID
*)&ac
);
149 if (r
== REGDB_E_CLASSNOTREG
)
151 win_skip("CLSID_AutoComplete is not registered\n");
154 ok(r
== S_OK
, "no IID_IAutoComplete (0x%08x)\n", r
);
156 /* AutoComplete source */
157 r
= CoCreateInstance(&CLSID_ACLMulti
, NULL
, CLSCTX_INPROC_SERVER
,
158 &IID_IACList
, (LPVOID
*)&acSource
);
159 if (r
== REGDB_E_CLASSNOTREG
)
161 win_skip("CLSID_ACLMulti is not registered\n");
162 IAutoComplete_Release(ac
);
165 ok(r
== S_OK
, "no IID_IACList (0x%08x)\n", r
);
167 user_data
= GetWindowLongPtrA(hEdit
, GWLP_USERDATA
);
168 ok(user_data
== 0, "Expected the edit control user data to be zero\n");
170 /* bind to edit control */
171 r
= IAutoComplete_Init(ac
, hEdit
, acSource
, NULL
, NULL
);
172 ok(r
== S_OK
, "Init returned 0x%08x\n", r
);
174 user_data
= GetWindowLongPtrA(hEdit
, GWLP_USERDATA
);
175 ok(user_data
== 0, "Expected the edit control user data to be zero\n");
177 IUnknown_Release(acSource
);
182 static void test_killfocus(void)
184 /* Test if WM_KILLFOCUS messages are handled properly by checking if
185 * the parent receives an EN_KILLFOCUS message. */
189 ok(killfocus_count
== 1, "Expected one EN_KILLFOCUS message, got: %d\n", killfocus_count
);
192 static LRESULT CALLBACK
MyWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
196 /* create edit control */
197 hEdit
= CreateWindowEx(0, "EDIT", "Some text", 0, 10, 10, 300, 300,
198 hWnd
, NULL
, hinst
, NULL
);
199 ok(hEdit
!= NULL
, "Can't create edit control\n");
202 if(HIWORD(wParam
) == EN_KILLFOCUS
)
206 return DefWindowProcA(hWnd
, msg
, wParam
, lParam
);
209 static void createMainWnd(void)
212 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
215 wc
.hInstance
= GetModuleHandleA(NULL
);
217 wc
.hCursor
= LoadCursorA(NULL
, IDC_IBEAM
);
218 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
219 wc
.lpszMenuName
= NULL
;
220 wc
.lpszClassName
= "MyTestWnd";
221 wc
.lpfnWndProc
= MyWndProc
;
224 hMainWnd
= CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW
,
225 CW_USEDEFAULT
, CW_USEDEFAULT
, 130, 105, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
228 START_TEST(autocomplete
)
234 r
= CoInitialize(NULL
);
235 ok(r
== S_OK
, "CoInitialize failed (0x%08x). Tests aborted.\n", r
);
240 ok(hMainWnd
!= NULL
, "Failed to create parent window. Tests aborted.\n");
241 if (!hMainWnd
) return;
250 while(GetMessageA(&msg
,0,0,0)) {
251 TranslateMessage(&msg
);
252 DispatchMessageA(&msg
);
255 IAutoComplete_Release(ac
);
258 DestroyWindow(hEdit
);
259 DestroyWindow(hMainWnd
);