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 static HWND hMainWnd
, hEdit
;
24 static HINSTANCE hinst
;
25 static int killfocus_count
;
27 static void test_invalid_init(void)
34 /* AutoComplete instance */
35 hr
= CoCreateInstance(&CLSID_AutoComplete
, NULL
, CLSCTX_INPROC_SERVER
,
36 &IID_IAutoComplete
, (void **)&ac
);
37 if (hr
== REGDB_E_CLASSNOTREG
)
39 win_skip("CLSID_AutoComplete is not registered\n");
42 ok(hr
== S_OK
, "no IID_IAutoComplete (0x%08x)\n", hr
);
44 /* AutoComplete source */
45 hr
= CoCreateInstance(&CLSID_ACLMulti
, NULL
, CLSCTX_INPROC_SERVER
,
46 &IID_IACList
, (void **)&acSource
);
47 if (hr
== REGDB_E_CLASSNOTREG
)
49 win_skip("CLSID_ACLMulti is not registered\n");
50 IAutoComplete_Release(ac
);
53 ok(hr
== S_OK
, "no IID_IACList (0x%08x)\n", hr
);
55 edit_control
= CreateWindowExA(0, "EDIT", "Some text", 0, 10, 10, 300, 300,
56 hMainWnd
, NULL
, hinst
, NULL
);
57 ok(edit_control
!= NULL
, "Can't create edit control\n");
59 /* The refcount of acSource would be incremented on older Windows. */
60 hr
= IAutoComplete_Init(ac
, NULL
, acSource
, NULL
, NULL
);
61 ok(hr
== E_INVALIDARG
||
62 broken(hr
== S_OK
), /* Win2k/XP/Win2k3 */
63 "Init returned 0x%08x\n", hr
);
64 if (hr
== E_INVALIDARG
)
68 IUnknown_AddRef(acSource
);
69 ref
= IUnknown_Release(acSource
);
70 ok(ref
== 1, "Expected AutoComplete source refcount to be 1, got %d\n", ref
);
75 /* Older Windows versions never check the window handle, while newer
76 * versions only check for NULL. Subsequent attempts to initialize the
77 * object after this call succeeds would fail, because initialization
78 * state is determined by whether a non-NULL window handle is stored. */
79 hr
= IAutoComplete_Init(ac
, (HWND
)0xdeadbeef, acSource
, NULL
, NULL
);
80 ok(hr
== S_OK
, "Init returned 0x%08x\n", hr
);
82 /* Tests crash on older Windows. */
83 hr
= IAutoComplete_Init(ac
, NULL
, NULL
, NULL
, NULL
);
84 ok(hr
== E_INVALIDARG
, "Init returned 0x%08x\n", hr
);
86 hr
= IAutoComplete_Init(ac
, edit_control
, NULL
, NULL
, NULL
);
87 ok(hr
== E_INVALIDARG
, "Init returned 0x%08x\n", hr
);
90 /* bind to edit control */
91 hr
= IAutoComplete_Init(ac
, edit_control
, acSource
, NULL
, NULL
);
92 ok(hr
== S_OK
, "Init returned 0x%08x\n", hr
);
94 /* try invalid parameters after successful initialization .*/
95 hr
= IAutoComplete_Init(ac
, NULL
, NULL
, NULL
, NULL
);
96 ok(hr
== E_INVALIDARG
||
97 hr
== E_FAIL
, /* Win2k/XP/Win2k3 */
98 "Init returned 0x%08x\n", hr
);
100 hr
= IAutoComplete_Init(ac
, NULL
, acSource
, NULL
, NULL
);
101 ok(hr
== E_INVALIDARG
||
102 hr
== E_FAIL
, /* Win2k/XP/Win2k3 */
103 "Init returned 0x%08x\n", hr
);
105 hr
= IAutoComplete_Init(ac
, edit_control
, NULL
, NULL
, NULL
);
106 ok(hr
== E_INVALIDARG
||
107 hr
== E_FAIL
, /* Win2k/XP/Win2k3 */
108 "Init returned 0x%08x\n", hr
);
110 /* try initializing twice on the same control */
111 hr
= IAutoComplete_Init(ac
, edit_control
, acSource
, NULL
, NULL
);
112 ok(hr
== E_FAIL
, "Init returned 0x%08x\n", hr
);
114 /* try initializing with a different control */
115 hr
= IAutoComplete_Init(ac
, hEdit
, acSource
, NULL
, NULL
);
116 ok(hr
== E_FAIL
, "Init returned 0x%08x\n", hr
);
118 DestroyWindow(edit_control
);
120 /* try initializing with a different control after
121 * destroying the original initialization control */
122 hr
= IAutoComplete_Init(ac
, hEdit
, acSource
, NULL
, NULL
);
123 ok(hr
== E_UNEXPECTED
||
124 hr
== E_FAIL
, /* Win2k/XP/Win2k3 */
125 "Init returned 0x%08x\n", hr
);
127 IUnknown_Release(acSource
);
128 IAutoComplete_Release(ac
);
130 static IAutoComplete
*test_init(void)
137 /* AutoComplete instance */
138 r
= CoCreateInstance(&CLSID_AutoComplete
, NULL
, CLSCTX_INPROC_SERVER
,
139 &IID_IAutoComplete
, (LPVOID
*)&ac
);
140 if (r
== REGDB_E_CLASSNOTREG
)
142 win_skip("CLSID_AutoComplete is not registered\n");
145 ok(r
== S_OK
, "no IID_IAutoComplete (0x%08x)\n", r
);
147 /* AutoComplete source */
148 r
= CoCreateInstance(&CLSID_ACLMulti
, NULL
, CLSCTX_INPROC_SERVER
,
149 &IID_IACList
, (LPVOID
*)&acSource
);
150 if (r
== REGDB_E_CLASSNOTREG
)
152 win_skip("CLSID_ACLMulti is not registered\n");
153 IAutoComplete_Release(ac
);
156 ok(r
== S_OK
, "no IID_IACList (0x%08x)\n", r
);
158 user_data
= GetWindowLongPtrA(hEdit
, GWLP_USERDATA
);
159 ok(user_data
== 0, "Expected the edit control user data to be zero\n");
161 /* bind to edit control */
162 r
= IAutoComplete_Init(ac
, hEdit
, acSource
, NULL
, NULL
);
163 ok(r
== S_OK
, "Init returned 0x%08x\n", r
);
165 user_data
= GetWindowLongPtrA(hEdit
, GWLP_USERDATA
);
166 ok(user_data
== 0, "Expected the edit control user data to be zero\n");
168 IUnknown_Release(acSource
);
173 static void test_killfocus(void)
175 /* Test if WM_KILLFOCUS messages are handled properly by checking if
176 * the parent receives an EN_KILLFOCUS message. */
180 ok(killfocus_count
== 1, "Expected one EN_KILLFOCUS message, got: %d\n", killfocus_count
);
183 static LRESULT CALLBACK
MyWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
187 /* create edit control */
188 hEdit
= CreateWindowExA(0, "EDIT", "Some text", 0, 10, 10, 300, 300,
189 hWnd
, NULL
, hinst
, NULL
);
190 ok(hEdit
!= NULL
, "Can't create edit control\n");
193 if(HIWORD(wParam
) == EN_KILLFOCUS
)
197 return DefWindowProcA(hWnd
, msg
, wParam
, lParam
);
200 static void createMainWnd(void)
203 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
206 wc
.hInstance
= GetModuleHandleA(NULL
);
208 wc
.hCursor
= LoadCursorA(NULL
, (LPSTR
)IDC_IBEAM
);
209 wc
.hbrBackground
= GetSysColorBrush(COLOR_WINDOW
);
210 wc
.lpszMenuName
= NULL
;
211 wc
.lpszClassName
= "MyTestWnd";
212 wc
.lpfnWndProc
= MyWndProc
;
215 hMainWnd
= CreateWindowExA(0, "MyTestWnd", "Blah", WS_OVERLAPPEDWINDOW
,
216 CW_USEDEFAULT
, CW_USEDEFAULT
, 130, 105, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
219 START_TEST(autocomplete
)
225 r
= CoInitialize(NULL
);
226 ok(r
== S_OK
, "CoInitialize failed (0x%08x). Tests aborted.\n", r
);
231 ok(hMainWnd
!= NULL
, "Failed to create parent window. Tests aborted.\n");
232 if (!hMainWnd
) return;
241 while(GetMessageA(&msg
,0,0,0)) {
242 TranslateMessage(&msg
);
243 DispatchMessageA(&msg
);
246 IAutoComplete_Release(ac
);
249 DestroyWindow(hEdit
);
250 DestroyWindow(hMainWnd
);