2 * Unit tests for the Explorer Browser control
4 * Copyright 2010 David Hedberg
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
27 #include "wine/test.h"
31 /*********************************************************************
34 static HRESULT
ebrowser_instantiate(IExplorerBrowser
**peb
)
36 return CoCreateInstance(&CLSID_ExplorerBrowser
, NULL
, CLSCTX_INPROC_SERVER
,
37 &IID_IExplorerBrowser
, (void**)peb
);
40 static void test_QueryInterface(void)
42 IExplorerBrowser
*peb
;
47 hr
= ebrowser_instantiate(&peb
);
48 ok(hr
== S_OK
, "Got 0x%08x\n", hr
);
50 #define test_qinterface(iid, exp) \
52 hr = IExplorerBrowser_QueryInterface(peb, &iid, (void**)&punk); \
53 ok(hr == exp, "(%s:)Expected (0x%08x), got (0x%08x)\n", \
55 if(SUCCEEDED(hr)) IUnknown_Release(punk); \
58 test_qinterface(IID_IUnknown
, S_OK
);
59 test_qinterface(IID_IExplorerBrowser
, S_OK
);
60 test_qinterface(IID_IShellBrowser
, S_OK
);
61 todo_wine
test_qinterface(IID_IOleWindow
, S_OK
);
62 todo_wine
test_qinterface(IID_ICommDlgBrowser
, S_OK
);
63 todo_wine
test_qinterface(IID_ICommDlgBrowser2
, S_OK
);
64 todo_wine
test_qinterface(IID_ICommDlgBrowser3
, S_OK
);
65 todo_wine
test_qinterface(IID_IServiceProvider
, S_OK
);
66 todo_wine
test_qinterface(IID_IObjectWithSite
, S_OK
);
67 todo_wine
test_qinterface(IID_IConnectionPointContainer
, S_OK
);
68 test_qinterface(IID_IOleObject
, E_NOINTERFACE
);
69 test_qinterface(IID_IViewObject
, E_NOINTERFACE
);
70 test_qinterface(IID_IViewObject2
, E_NOINTERFACE
);
71 test_qinterface(IID_IViewObjectEx
, E_NOINTERFACE
);
72 test_qinterface(IID_IConnectionPoint
, E_NOINTERFACE
);
73 test_qinterface(IID_IShellView
, E_NOINTERFACE
);
74 test_qinterface(IID_INameSpaceTreeControlEvents
, E_NOINTERFACE
);
76 #undef test_qinterface
78 lres
= IExplorerBrowser_Release(peb
);
79 ok(lres
== 0, "Got %d\n", lres
);
82 static void test_SB_misc(void)
84 IExplorerBrowser
*peb
;
90 ebrowser_instantiate(&peb
);
91 hr
= IExplorerBrowser_QueryInterface(peb
, &IID_IShellBrowser
, (void**)&psb
);
92 ok(hr
== S_OK
, "Got 0x%08x\n", hr
);
95 skip("Failed to get IShellBrowser interface.\n");
99 /* Some unimplemented methods */
100 retHwnd
= (HWND
)0xDEADBEEF;
101 hr
= IShellBrowser_GetControlWindow(psb
, FCW_TOOLBAR
, &retHwnd
);
102 ok(hr
== E_NOTIMPL
, "got (0x%08x)\n", hr
);
103 ok(retHwnd
== (HWND
)0xDEADBEEF, "HWND overwritten\n");
105 hr
= IShellBrowser_GetControlWindow(psb
, FCW_STATUS
, &retHwnd
);
106 ok(hr
== E_NOTIMPL
, "got (0x%08x)\n", hr
);
107 ok(retHwnd
== (HWND
)0xDEADBEEF, "HWND overwritten\n");
109 hr
= IShellBrowser_GetControlWindow(psb
, FCW_TREE
, &retHwnd
);
110 ok(hr
== E_NOTIMPL
, "got (0x%08x)\n", hr
);
111 ok(retHwnd
== (HWND
)0xDEADBEEF, "HWND overwritten\n");
113 hr
= IShellBrowser_GetControlWindow(psb
, FCW_PROGRESS
, &retHwnd
);
114 ok(hr
== E_NOTIMPL
, "got (0x%08x)\n", hr
);
115 ok(retHwnd
== (HWND
)0xDEADBEEF, "HWND overwritten\n");
118 hr
= IShellBrowser_InsertMenusSB(psb
, NULL
, NULL
);
119 ok(hr
== E_NOTIMPL
, "got (0x%08x)\n", hr
);
121 /* ::RemoveMenusSB */
122 hr
= IShellBrowser_RemoveMenusSB(psb
, NULL
);
123 ok(hr
== E_NOTIMPL
, "got (0x%08x)\n", hr
);
126 hr
= IShellBrowser_SetMenuSB(psb
, NULL
, NULL
, NULL
);
127 ok(hr
== E_NOTIMPL
, "got (0x%08x)\n", hr
);
129 IShellBrowser_Release(psb
);
130 lres
= IExplorerBrowser_Release(peb
);
131 ok(lres
== 0, "Got %d\n", lres
);
134 static void test_initialization(void)
136 IExplorerBrowser
*peb
;
142 ebrowser_instantiate(&peb
);
146 /* Crashes on Windows 7 */
147 hr
= IExplorerBrowser_Initialize(peb
, NULL
, NULL
, NULL
);
148 hr
= IExplorerBrowser_Initialize(peb
, hwnd
, NULL
, NULL
);
151 ZeroMemory(&rc
, sizeof(RECT
));
153 hr
= IExplorerBrowser_Initialize(peb
, NULL
, &rc
, NULL
);
154 ok(hr
== E_INVALIDARG
, "got (0x%08x)\n", hr
);
156 hr
= IExplorerBrowser_Initialize(peb
, hwnd
, &rc
, NULL
);
157 ok(hr
== S_OK
, "got (0x%08x)\n", hr
);
159 /* Initialize twice */
160 hr
= IExplorerBrowser_Initialize(peb
, hwnd
, &rc
, NULL
);
161 ok(hr
== E_UNEXPECTED
, "got (0x%08x)\n", hr
);
163 hr
= IExplorerBrowser_Destroy(peb
);
164 ok(hr
== S_OK
, "got (0x%08x)\n", hr
);
166 /* Initialize again */
167 hr
= IExplorerBrowser_Initialize(peb
, hwnd
, &rc
, NULL
);
168 ok(hr
== E_UNEXPECTED
, "got (0x%08x)\n", hr
);
171 hr
= IExplorerBrowser_Destroy(peb
);
172 ok(hr
== S_OK
, "got (0x%08x)\n", hr
);
173 lres
= IExplorerBrowser_Release(peb
);
174 ok(lres
== 0, "Got %d\n", lres
);
176 /* Initialize with a few different rectangles */
178 ebrowser_instantiate(&peb
);
179 rc
.left
= 50; rc
.top
= 20; rc
.right
= 100; rc
.bottom
= 80;
180 hr
= IExplorerBrowser_Initialize(peb
, hwnd
, &rc
, NULL
);
181 ok(hr
== S_OK
, "got (0x%08x)\n", hr
);
182 hr
= IExplorerBrowser_QueryInterface(peb
, &IID_IShellBrowser
, (void**)&psb
);
183 ok(hr
== S_OK
, "Got 0x%08x\n", hr
);
189 LONG style
, expected_style
;
190 static const RECT exp_rc
= {0, 0, 48, 58};
192 hr
= IShellBrowser_GetWindow(psb
, &eb_hwnd
);
193 ok(hr
== S_OK
, "Got 0x%08x\n", hr
);
195 GetClientRect(eb_hwnd
, &eb_rc
);
196 ok(EqualRect(&eb_rc
, &exp_rc
), "Got client rect (%d, %d)-(%d, %d)\n",
197 eb_rc
.left
, eb_rc
.top
, eb_rc
.right
, eb_rc
.bottom
);
199 GetWindowRect(eb_hwnd
, &eb_rc
);
200 ok(eb_rc
.right
- eb_rc
.left
== 50, "Got window width %d\n", eb_rc
.right
- eb_rc
.left
);
201 ok(eb_rc
.bottom
- eb_rc
.top
== 60, "Got window height %d\n", eb_rc
.bottom
- eb_rc
.top
);
204 GetClassNameA(eb_hwnd
, buf
, 1024);
205 ok(!lstrcmpA(buf
, "ExplorerBrowserControl"), "Unexpected classname %s\n", buf
);
207 expected_style
= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
| WS_BORDER
;
208 style
= GetWindowLongPtrW(eb_hwnd
, GWL_STYLE
);
209 todo_wine
ok(style
== expected_style
, "Got style 0x%08x, expected 0x%08x\n", style
, expected_style
);
211 expected_style
= WS_EX_CONTROLPARENT
;
212 style
= GetWindowLongPtrW(eb_hwnd
, GWL_EXSTYLE
);
213 ok(style
== expected_style
, "Got exstyle 0x%08x, expected 0x%08x\n", style
, expected_style
);
215 ok(GetParent(eb_hwnd
) == hwnd
, "GetParent returns %p\n", GetParent(eb_hwnd
));
217 /* ::Destroy() destroys the window. */
218 ok(IsWindow(eb_hwnd
), "eb_hwnd invalid.\n");
219 IExplorerBrowser_Destroy(peb
);
220 ok(!IsWindow(eb_hwnd
), "eb_hwnd valid.\n");
222 IShellBrowser_Release(psb
);
223 lres
= IExplorerBrowser_Release(peb
);
224 ok(lres
== 0, "Got refcount %d\n", lres
);
228 skip("Skipping some tests.\n");
230 IExplorerBrowser_Destroy(peb
);
231 lres
= IExplorerBrowser_Release(peb
);
232 ok(lres
== 0, "Got refcount %d\n", lres
);
235 ebrowser_instantiate(&peb
);
236 rc
.left
= 0; rc
.top
= 0; rc
.right
= 0; rc
.bottom
= 0;
237 hr
= IExplorerBrowser_Initialize(peb
, hwnd
, &rc
, NULL
);
238 ok(hr
== S_OK
, "got (0x%08x)\n", hr
);
239 IExplorerBrowser_Destroy(peb
);
240 lres
= IExplorerBrowser_Release(peb
);
241 ok(lres
== 0, "Got refcount %d\n", lres
);
243 ebrowser_instantiate(&peb
);
244 rc
.left
= -1; rc
.top
= -1; rc
.right
= 1; rc
.bottom
= 1;
245 hr
= IExplorerBrowser_Initialize(peb
, hwnd
, &rc
, NULL
);
246 ok(hr
== S_OK
, "got (0x%08x)\n", hr
);
247 IExplorerBrowser_Destroy(peb
);
248 lres
= IExplorerBrowser_Release(peb
);
249 ok(lres
== 0, "Got refcount %d\n", lres
);
251 ebrowser_instantiate(&peb
);
252 rc
.left
= 10; rc
.top
= 10; rc
.right
= 5; rc
.bottom
= 5;
253 hr
= IExplorerBrowser_Initialize(peb
, hwnd
, &rc
, NULL
);
254 ok(hr
== S_OK
, "got (0x%08x)\n", hr
);
255 IExplorerBrowser_Destroy(peb
);
256 lres
= IExplorerBrowser_Release(peb
);
257 ok(lres
== 0, "Got refcount %d\n", lres
);
259 ebrowser_instantiate(&peb
);
260 rc
.left
= 10; rc
.top
= 10; rc
.right
= 5; rc
.bottom
= 5;
261 hr
= IExplorerBrowser_Initialize(peb
, hwnd
, &rc
, NULL
);
262 ok(hr
== S_OK
, "got (0x%08x)\n", hr
);
263 IExplorerBrowser_Destroy(peb
);
264 lres
= IExplorerBrowser_Release(peb
);
265 ok(lres
== 0, "Got refcount %d\n", lres
);
268 static BOOL
test_instantiate_control(void)
270 IExplorerBrowser
*peb
;
273 hr
= ebrowser_instantiate(&peb
);
274 ok(hr
== S_OK
|| hr
== REGDB_E_CLASSNOTREG
, "Got (0x%08x)\n", hr
);
278 IExplorerBrowser_Release(peb
);
282 static void setup_window(void)
285 static const WCHAR ebtestW
[] = {'e','b','t','e','s','t',0};
287 ZeroMemory(&wc
, sizeof(WNDCLASSW
));
288 wc
.lpfnWndProc
= DefWindowProcW
;
289 wc
.lpszClassName
= ebtestW
;
291 hwnd
= CreateWindowExW(0, ebtestW
, NULL
, 0,
294 ok(hwnd
!= NULL
, "Failed to create window for tests.\n");
301 if(!test_instantiate_control())
303 win_skip("No ExplorerBrowser control..\n");
310 test_QueryInterface();
312 test_initialization();