shell32: Implement IExplorerBrowser::Initialize.
[wine.git] / dlls / shell32 / tests / ebrowser.c
blobe3f4e9c38adb5c1cef9244281abda3c0e6b1b331
1 /*
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
21 #include <stdio.h>
23 #define COBJMACROS
25 #include "shlobj.h"
27 #include "wine/test.h"
29 static HWND hwnd;
31 /*********************************************************************
32 * Some simple helpers
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;
43 IUnknown *punk;
44 HRESULT hr;
45 LONG lres;
47 hr = ebrowser_instantiate(&peb);
48 ok(hr == S_OK, "Got 0x%08x\n", hr);
50 #define test_qinterface(iid, exp) \
51 do { \
52 hr = IExplorerBrowser_QueryInterface(peb, &iid, (void**)&punk); \
53 ok(hr == exp, "(%s:)Expected (0x%08x), got (0x%08x)\n", \
54 #iid, exp, hr); \
55 if(SUCCEEDED(hr)) IUnknown_Release(punk); \
56 } while(0)
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;
85 IShellBrowser *psb;
86 HRESULT hr;
87 HWND retHwnd;
88 LONG lres;
90 ebrowser_instantiate(&peb);
91 hr = IExplorerBrowser_QueryInterface(peb, &IID_IShellBrowser, (void**)&psb);
92 ok(hr == S_OK, "Got 0x%08x\n", hr);
93 if(FAILED(hr))
95 skip("Failed to get IShellBrowser interface.\n");
96 return;
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");
117 /* ::InsertMenuSB */
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);
125 /* ::SetMenuSB */
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;
137 IShellBrowser *psb;
138 HRESULT hr;
139 ULONG lres;
140 RECT rc;
142 ebrowser_instantiate(&peb);
144 if(0)
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);
170 /* Destroy again */
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 */
177 peb = NULL;
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);
184 if(SUCCEEDED(hr))
186 HWND eb_hwnd;
187 RECT eb_rc;
188 char buf[1024];
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);
203 buf[0] = '\0';
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);
226 else
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;
271 HRESULT hr;
273 hr = ebrowser_instantiate(&peb);
274 ok(hr == S_OK || hr == REGDB_E_CLASSNOTREG, "Got (0x%08x)\n", hr);
275 if(FAILED(hr))
276 return FALSE;
278 IExplorerBrowser_Release(peb);
279 return TRUE;
282 static void setup_window(void)
284 WNDCLASSW wc;
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;
290 RegisterClassW(&wc);
291 hwnd = CreateWindowExW(0, ebtestW, NULL, 0,
292 0, 0, 500, 500,
293 NULL, 0, 0, NULL);
294 ok(hwnd != NULL, "Failed to create window for tests.\n");
297 START_TEST(ebrowser)
299 OleInitialize(NULL);
301 if(!test_instantiate_control())
303 win_skip("No ExplorerBrowser control..\n");
304 OleUninitialize();
305 return;
308 setup_window();
310 test_QueryInterface();
311 test_SB_misc();
312 test_initialization();
314 DestroyWindow(hwnd);
315 OleUninitialize();