[REACTOS]
[reactos.git] / rostests / winetests / comdlg32 / itemdlg.c
1 /*
2 * Unit tests for the Common Item Dialog
3 *
4 * Copyright 2010,2011 David Hedberg
5 *
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.
10 *
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.
15 *
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
19 *
20 */
21
22 #define WIN32_NO_STATUS
23 #define _INC_WINDOWS
24 #define COM_NO_WINDOWS_H
25
26 #include <wine/test.h>
27
28 #define COBJMACROS
29 #define CONST_VTABLE
30
31 #include <shlobj.h>
32
33 static HRESULT (WINAPI *pSHCreateShellItem)(LPCITEMIDLIST,IShellFolder*,LPCITEMIDLIST,IShellItem**);
34 static HRESULT (WINAPI *pSHGetIDListFromObject)(IUnknown*, PIDLIST_ABSOLUTE*);
35 static HRESULT (WINAPI *pSHCreateItemFromParsingName)(PCWSTR,IBindCtx*,REFIID,void**);
36
37 static void init_function_pointers(void)
38 {
39 HMODULE hmod = GetModuleHandleA("shell32.dll");
40
41 #define MAKEFUNC(f) (p##f = (void*)GetProcAddress(hmod, #f))
42 MAKEFUNC(SHCreateShellItem);
43 MAKEFUNC(SHGetIDListFromObject);
44 MAKEFUNC(SHCreateItemFromParsingName);
45 #undef MAKEFUNC
46 }
47
48 #include <initguid.h>
49 DEFINE_GUID(IID_IFileDialogCustomizeAlt, 0x8016B7B3, 0x3D49, 0x4504, 0xA0,0xAA, 0x2A,0x37,0x49,0x4E,0x60,0x6F);
50
51 /**************************************************************************
52 * IFileDialogEvents implementation
53 */
54 typedef struct {
55 IFileDialogEvents IFileDialogEvents_iface;
56 LONG ref;
57 LONG QueryInterface;
58 LONG OnFileOk, OnFolderChanging, OnFolderChange;
59 LONG OnSelectionChange, OnShareViolation, OnTypeChange;
60 LONG OnOverwrite;
61 LPCWSTR set_filename;
62 BOOL set_filename_tried;
63 BOOL cfd_test1;
64 } IFileDialogEventsImpl;
65
66 static inline IFileDialogEventsImpl *impl_from_IFileDialogEvents(IFileDialogEvents *iface)
67 {
68 return CONTAINING_RECORD(iface, IFileDialogEventsImpl, IFileDialogEvents_iface);
69 }
70
71 static HRESULT WINAPI IFileDialogEvents_fnQueryInterface(IFileDialogEvents *iface, REFIID riid, void **ppv)
72 {
73 /* Not called. */
74 ok(0, "Unexpectedly called.\n");
75 return E_NOINTERFACE;
76 }
77
78 static ULONG WINAPI IFileDialogEvents_fnAddRef(IFileDialogEvents *iface)
79 {
80 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
81 return InterlockedIncrement(&This->ref);
82 }
83
84 static ULONG WINAPI IFileDialogEvents_fnRelease(IFileDialogEvents *iface)
85 {
86 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
87 LONG ref = InterlockedDecrement(&This->ref);
88
89 if(!ref)
90 HeapFree(GetProcessHeap(), 0, This);
91
92 return ref;
93 }
94
95 static HRESULT WINAPI IFileDialogEvents_fnOnFileOk(IFileDialogEvents *iface, IFileDialog *pfd)
96 {
97 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
98 This->OnFileOk++;
99 return S_OK;
100 }
101
102 static HRESULT WINAPI IFileDialogEvents_fnOnFolderChanging(IFileDialogEvents *iface,
103 IFileDialog *pfd,
104 IShellItem *psiFolder)
105 {
106 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
107 This->OnFolderChanging++;
108 return S_OK;
109 }
110
111 static void test_customize_onfolderchange(IFileDialog *pfd);
112
113 static LRESULT CALLBACK test_customize_dlgproc(HWND hwnd, UINT message, LPARAM lparam, WPARAM wparam)
114 {
115 WNDPROC oldwndproc = GetPropA(hwnd, "WT_OLDWC");
116
117 if(message == WM_USER+0x1234)
118 {
119 IFileDialog *pfd = (IFileDialog*)lparam;
120 test_customize_onfolderchange(pfd);
121 }
122
123 return CallWindowProcW(oldwndproc, hwnd, message, lparam, wparam);
124 }
125
126 static HRESULT WINAPI IFileDialogEvents_fnOnFolderChange(IFileDialogEvents *iface, IFileDialog *pfd)
127 {
128 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
129 IOleWindow *pow;
130 HWND dlg_hwnd;
131 HRESULT hr;
132 BOOL br;
133 This->OnFolderChange++;
134
135 if(This->set_filename)
136 {
137 hr = IFileDialog_QueryInterface(pfd, &IID_IOleWindow, (void**)&pow);
138 ok(hr == S_OK, "Got 0x%08x\n", hr);
139
140 hr = IOleWindow_GetWindow(pow, &dlg_hwnd);
141 ok(hr == S_OK, "Got 0x%08x\n", hr);
142 ok(dlg_hwnd != NULL, "Got NULL.\n");
143
144 IOleWindow_Release(pow);
145
146 hr = IFileDialog_SetFileName(pfd, This->set_filename);
147 ok(hr == S_OK, "Got 0x%08x\n", hr);
148
149 if(!This->set_filename_tried)
150 {
151 br = PostMessageW(dlg_hwnd, WM_COMMAND, IDOK, 0);
152 ok(br, "Failed\n");
153 This->set_filename_tried = TRUE;
154 }
155 }
156
157 if(This->cfd_test1)
158 {
159 WNDPROC oldwndproc;
160 hr = IFileDialog_QueryInterface(pfd, &IID_IOleWindow, (void**)&pow);
161 ok(hr == S_OK, "Got 0x%08x\n", hr);
162
163 hr = IOleWindow_GetWindow(pow, &dlg_hwnd);
164 ok(hr == S_OK, "Got 0x%08x\n", hr);
165 ok(dlg_hwnd != NULL, "Got NULL.\n");
166
167 IOleWindow_Release(pow);
168
169 /* On Vista, the custom control area of the dialog is not
170 * fully set up when the first OnFolderChange event is
171 * issued. */
172 oldwndproc = (WNDPROC)GetWindowLongPtrW(dlg_hwnd, GWLP_WNDPROC);
173 SetPropA(dlg_hwnd, "WT_OLDWC", (HANDLE)oldwndproc);
174 SetWindowLongPtrW(dlg_hwnd, GWLP_WNDPROC, (LPARAM)test_customize_dlgproc);
175
176 br = PostMessageW(dlg_hwnd, WM_USER+0x1234, (LPARAM)pfd, 0);
177 ok(br, "Failed\n");
178 }
179
180 return S_OK;
181 }
182
183 static HRESULT WINAPI IFileDialogEvents_fnOnSelectionChange(IFileDialogEvents *iface, IFileDialog *pfd)
184 {
185 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
186 This->OnSelectionChange++;
187 return S_OK;
188 }
189
190 static HRESULT WINAPI IFileDialogEvents_fnOnShareViolation(IFileDialogEvents *iface,
191 IFileDialog *pfd,
192 IShellItem *psi,
193 FDE_SHAREVIOLATION_RESPONSE *pResponse)
194 {
195 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
196 This->OnShareViolation++;
197 return S_OK;
198 }
199
200 static HRESULT WINAPI IFileDialogEvents_fnOnTypeChange(IFileDialogEvents *iface, IFileDialog *pfd)
201 {
202 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
203 This->OnTypeChange++;
204 return S_OK;
205 }
206
207 static HRESULT WINAPI IFileDialogEvents_fnOnOverwrite(IFileDialogEvents *iface,
208 IFileDialog *pfd,
209 IShellItem *psi,
210 FDE_OVERWRITE_RESPONSE *pResponse)
211 {
212 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
213 This->OnOverwrite++;
214 return S_OK;
215 }
216
217 static const IFileDialogEventsVtbl vt_IFileDialogEvents = {
218 IFileDialogEvents_fnQueryInterface,
219 IFileDialogEvents_fnAddRef,
220 IFileDialogEvents_fnRelease,
221 IFileDialogEvents_fnOnFileOk,
222 IFileDialogEvents_fnOnFolderChanging,
223 IFileDialogEvents_fnOnFolderChange,
224 IFileDialogEvents_fnOnSelectionChange,
225 IFileDialogEvents_fnOnShareViolation,
226 IFileDialogEvents_fnOnTypeChange,
227 IFileDialogEvents_fnOnOverwrite
228 };
229
230 static IFileDialogEvents *IFileDialogEvents_Constructor(void)
231 {
232 IFileDialogEventsImpl *This;
233
234 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IFileDialogEventsImpl));
235 This->IFileDialogEvents_iface.lpVtbl = &vt_IFileDialogEvents;
236 This->ref = 1;
237
238 return &This->IFileDialogEvents_iface;
239 }
240
241 static BOOL test_instantiation(void)
242 {
243 IFileDialog *pfd;
244 IFileOpenDialog *pfod;
245 IFileSaveDialog *pfsd;
246 IServiceProvider *psp;
247 IOleWindow *pow;
248 IUnknown *punk;
249 HRESULT hr;
250 LONG ref;
251
252 /* Instantiate FileOpenDialog */
253 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
254 &IID_IFileOpenDialog, (void**)&pfod);
255 if(FAILED(hr))
256 {
257 skip("Could not instantiate the FileOpenDialog.\n");
258 return FALSE;
259 }
260 ok(hr == S_OK, "got 0x%08x.\n", hr);
261
262 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialog, (void**)&pfd);
263 ok(hr == S_OK, "got 0x%08x.\n", hr);
264 if(SUCCEEDED(hr)) IFileDialog_Release(pfd);
265
266 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialogCustomize, (void**)&punk);
267 ok(hr == S_OK, "got 0x%08x.\n", hr);
268 if(SUCCEEDED(hr)) IUnknown_Release(punk);
269
270 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialogCustomizeAlt, (void**)&punk);
271 ok(hr == S_OK, "got 0x%08x.\n", hr);
272 if(SUCCEEDED(hr)) IUnknown_Release(punk);
273
274 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileSaveDialog, (void**)&pfsd);
275 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
276 if(SUCCEEDED(hr)) IFileSaveDialog_Release(pfsd);
277
278 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IServiceProvider, (void**)&psp);
279 ok(hr == S_OK, "got 0x%08x.\n", hr);
280 if(SUCCEEDED(hr))
281 {
282 IExplorerBrowser *peb;
283 IShellBrowser *psb;
284
285 hr = IServiceProvider_QueryService(psp, &SID_SExplorerBrowserFrame, &IID_ICommDlgBrowser, (void**)&punk);
286 ok(hr == S_OK, "got 0x%08x.\n", hr);
287 if(SUCCEEDED(hr)) IUnknown_Release(punk);
288
289 /* since win8, the result is E_NOTIMPL for all other services */
290 hr = IServiceProvider_QueryService(psp, &SID_STopLevelBrowser, &IID_IExplorerBrowser, (void**)&peb);
291 ok(hr == E_NOTIMPL || broken(hr == E_FAIL), "got 0x%08x (expected E_NOTIMPL)\n", hr);
292 if(SUCCEEDED(hr)) IExplorerBrowser_Release(peb);
293 hr = IServiceProvider_QueryService(psp, &SID_STopLevelBrowser, &IID_IShellBrowser, (void**)&psb);
294 ok(hr == E_NOTIMPL || broken(hr == E_FAIL), "got 0x%08x (expected E_NOTIMPL)\n", hr);
295 if(SUCCEEDED(hr)) IShellBrowser_Release(psb);
296 hr = IServiceProvider_QueryService(psp, &SID_STopLevelBrowser, &IID_ICommDlgBrowser, (void**)&punk);
297 ok(hr == E_NOTIMPL || broken(hr == E_FAIL), "got 0x%08x (expected E_NOTIMPL)\n", hr);
298 if(SUCCEEDED(hr)) IUnknown_Release(punk);
299
300 hr = IServiceProvider_QueryService(psp, &SID_STopLevelBrowser, &IID_IUnknown, (void**)&punk);
301 ok(hr == E_NOTIMPL || broken(hr == E_FAIL), "got 0x%08x (expected E_NOTIMPL)\n", hr);
302 if(SUCCEEDED(hr)) IUnknown_Release(punk);
303 hr = IServiceProvider_QueryService(psp, &IID_IUnknown, &IID_IUnknown, (void**)&punk);
304 ok(hr == E_NOTIMPL || broken(hr == E_FAIL), "got 0x%08x (expected E_NOTIMPL)\n", hr);
305 if(SUCCEEDED(hr)) IUnknown_Release(punk);
306
307 IServiceProvider_Release(psp);
308 }
309
310 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialogEvents, (void**)&punk);
311 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
312 if(SUCCEEDED(hr)) IUnknown_Release(punk);
313
314 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IExplorerBrowser, (void**)&punk);
315 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
316 if(SUCCEEDED(hr)) IUnknown_Release(punk);
317
318 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IExplorerBrowserEvents, (void**)&punk);
319 ok(hr == S_OK, "got 0x%08x.\n", hr);
320 if(SUCCEEDED(hr)) IUnknown_Release(punk);
321
322 hr = IFileOpenDialog_QueryInterface(pfod, &IID_ICommDlgBrowser3, (void**)&punk);
323 ok(hr == S_OK, "got 0x%08x.\n", hr);
324 if(SUCCEEDED(hr)) IUnknown_Release(punk);
325
326 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IShellBrowser, (void**)&punk);
327 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
328 if(SUCCEEDED(hr)) IUnknown_Release(punk);
329
330 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IOleWindow, (void**)&pow);
331 ok(hr == S_OK, "got 0x%08x.\n", hr);
332 if(SUCCEEDED(hr))
333 {
334 HWND hwnd;
335
336 hr = IOleWindow_ContextSensitiveHelp(pow, TRUE);
337 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
338
339 hr = IOleWindow_ContextSensitiveHelp(pow, FALSE);
340 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
341
342 if(0)
343 {
344 /* Crashes on win7 */
345 IOleWindow_GetWindow(pow, NULL);
346 }
347
348 hr = IOleWindow_GetWindow(pow, &hwnd);
349 ok(hr == S_OK, "Got 0x%08x\n", hr);
350 ok(hwnd == NULL, "Got %p\n", hwnd);
351
352 IOleWindow_Release(pow);
353 }
354
355 ref = IFileOpenDialog_Release(pfod);
356 ok(!ref, "Got refcount %d, should have been released.\n", ref);
357
358 /* Instantiate FileSaveDialog */
359 hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER,
360 &IID_IFileSaveDialog, (void**)&pfsd);
361 if(FAILED(hr))
362 {
363 skip("Could not instantiate the FileSaveDialog.\n");
364 return FALSE;
365 }
366 ok(hr == S_OK, "got 0x%08x.\n", hr);
367
368 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialog, (void**)&pfd);
369 ok(hr == S_OK, "got 0x%08x.\n", hr);
370 if(SUCCEEDED(hr)) IFileDialog_Release(pfd);
371
372 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialogCustomize, (void**)&punk);
373 ok(hr == S_OK, "got 0x%08x.\n", hr);
374 if(SUCCEEDED(hr)) IUnknown_Release(punk);
375
376 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialogCustomizeAlt, (void**)&punk);
377 ok(hr == S_OK, "got 0x%08x.\n", hr);
378 if(SUCCEEDED(hr)) IUnknown_Release(punk);
379
380 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileOpenDialog, (void**)&pfod);
381 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
382 if(SUCCEEDED(hr)) IFileOpenDialog_Release(pfod);
383
384 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialogEvents, (void**)&punk);
385 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
386 if(SUCCEEDED(hr)) IFileDialog_Release(pfd);
387
388 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IExplorerBrowser, (void**)&punk);
389 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
390 if(SUCCEEDED(hr)) IUnknown_Release(punk);
391
392 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IExplorerBrowserEvents, (void**)&punk);
393 ok(hr == S_OK, "got 0x%08x.\n", hr);
394 if(SUCCEEDED(hr)) IUnknown_Release(punk);
395
396 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_ICommDlgBrowser3, (void**)&punk);
397 ok(hr == S_OK, "got 0x%08x.\n", hr);
398 if(SUCCEEDED(hr)) IUnknown_Release(punk);
399
400 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IShellBrowser, (void**)&punk);
401 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
402 if(SUCCEEDED(hr)) IUnknown_Release(punk);
403
404 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IOleWindow, (void**)&pow);
405 ok(hr == S_OK, "got 0x%08x.\n", hr);
406 if(SUCCEEDED(hr))
407 {
408 HWND hwnd;
409
410 hr = IOleWindow_ContextSensitiveHelp(pow, TRUE);
411 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
412
413 hr = IOleWindow_ContextSensitiveHelp(pow, FALSE);
414 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
415
416 if(0)
417 {
418 /* Crashes on win7 */
419 IOleWindow_GetWindow(pow, NULL);
420 }
421
422 hr = IOleWindow_GetWindow(pow, &hwnd);
423 ok(hr == S_OK, "Got 0x%08x\n", hr);
424 ok(hwnd == NULL, "Got %p\n", hwnd);
425
426 IOleWindow_Release(pow);
427 }
428
429
430 ref = IFileSaveDialog_Release(pfsd);
431 ok(!ref, "Got refcount %d, should have been released.\n", ref);
432 return TRUE;
433 }
434
435 static void test_basics(void)
436 {
437 IFileOpenDialog *pfod;
438 IFileSaveDialog *pfsd;
439 IFileDialog2 *pfd2;
440 FILEOPENDIALOGOPTIONS fdoptions;
441 IShellFolder *psfdesktop;
442 IShellItem *psi, *psidesktop, *psi_original;
443 IShellItemArray *psia;
444 IPropertyStore *pps;
445 LPITEMIDLIST pidl;
446 WCHAR *filename;
447 UINT filetype;
448 LONG ref;
449 HRESULT hr;
450 const WCHAR txt[] = {'t','x','t', 0};
451 const WCHAR null[] = {0};
452 const WCHAR fname1[] = {'f','n','a','m','e','1', 0};
453 const WCHAR fspec1[] = {'*','.','t','x','t',0};
454 const WCHAR fname2[] = {'f','n','a','m','e','2', 0};
455 const WCHAR fspec2[] = {'*','.','e','x','e',0};
456 COMDLG_FILTERSPEC filterspec[2] = {{fname1, fspec1}, {fname2, fspec2}};
457
458 /* This should work on every platform with IFileDialog */
459 SHGetDesktopFolder(&psfdesktop);
460 hr = pSHGetIDListFromObject((IUnknown*)psfdesktop, &pidl);
461 if(SUCCEEDED(hr))
462 {
463 hr = pSHCreateShellItem(NULL, NULL, pidl, &psidesktop);
464 ILFree(pidl);
465 }
466 IShellFolder_Release(psfdesktop);
467 if(FAILED(hr))
468 {
469 skip("Failed to get ShellItem from DesktopFolder, skipping tests.\n");
470 return;
471 }
472
473
474 /* Instantiate FileOpenDialog and FileSaveDialog */
475 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
476 &IID_IFileOpenDialog, (void**)&pfod);
477 ok(hr == S_OK, "got 0x%08x.\n", hr);
478 hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER,
479 &IID_IFileSaveDialog, (void**)&pfsd);
480 ok(hr == S_OK, "got 0x%08x.\n", hr);
481
482 /* ClearClientData */
483 todo_wine
484 {
485 hr = IFileOpenDialog_ClearClientData(pfod);
486 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
487 hr = IFileSaveDialog_ClearClientData(pfsd);
488 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
489 }
490
491 /* GetOptions */
492 hr = IFileOpenDialog_GetOptions(pfod, NULL);
493 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
494 hr = IFileSaveDialog_GetOptions(pfsd, NULL);
495 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
496
497 /* Check default options */
498 hr = IFileOpenDialog_GetOptions(pfod, &fdoptions);
499 ok(hr == S_OK, "got 0x%08x.\n", hr);
500 ok(fdoptions == (FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST | FOS_NOCHANGEDIR),
501 "Unexpected default options: 0x%08x\n", fdoptions);
502 hr = IFileSaveDialog_GetOptions(pfsd, &fdoptions);
503 ok(hr == S_OK, "got 0x%08x.\n", hr);
504 ok(fdoptions == (FOS_OVERWRITEPROMPT | FOS_NOREADONLYRETURN | FOS_PATHMUSTEXIST | FOS_NOCHANGEDIR),
505 "Unexpected default options: 0x%08x\n", fdoptions);
506
507 /* GetResult */
508 hr = IFileOpenDialog_GetResult(pfod, NULL);
509 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
510 hr = IFileSaveDialog_GetResult(pfsd, NULL);
511 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
512
513 psi = (void*)0xdeadbeef;
514 hr = IFileOpenDialog_GetResult(pfod, &psi);
515 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
516 ok(psi == (void*)0xdeadbeef, "got %p.\n", psi);
517 psi = (void*)0xdeadbeef;
518 hr = IFileSaveDialog_GetResult(pfsd, &psi);
519 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
520 ok(psi == (void*)0xdeadbeef, "got %p.\n", psi);
521
522 /* GetCurrentSelection */
523 if(0) {
524 /* Crashes on Vista/W2K8. Tests below passes on Windows 7 */
525 hr = IFileOpenDialog_GetCurrentSelection(pfod, NULL);
526 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
527 hr = IFileSaveDialog_GetCurrentSelection(pfsd, NULL);
528 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
529 hr = IFileOpenDialog_GetCurrentSelection(pfod, &psi);
530 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
531 hr = IFileSaveDialog_GetCurrentSelection(pfsd, &psi);
532 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
533 }
534
535 /* GetFileName */
536 hr = IFileOpenDialog_GetFileName(pfod, NULL);
537 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
538 filename = (void*)0xdeadbeef;
539 hr = IFileOpenDialog_GetFileName(pfod, &filename);
540 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
541 ok(filename == NULL, "got %p\n", filename);
542 hr = IFileSaveDialog_GetFileName(pfsd, NULL);
543 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
544 filename = (void*)0xdeadbeef;
545 hr = IFileSaveDialog_GetFileName(pfsd, &filename);
546 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
547 ok(filename == NULL, "got %p\n", filename);
548
549 /* GetFileTypeIndex */
550 hr = IFileOpenDialog_GetFileTypeIndex(pfod, NULL);
551 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
552 filetype = 0x12345;
553 hr = IFileOpenDialog_GetFileTypeIndex(pfod, &filetype);
554 ok(hr == S_OK, "got 0x%08x.\n", hr);
555 ok(filetype == 0, "got %d.\n", filetype);
556 hr = IFileSaveDialog_GetFileTypeIndex(pfsd, NULL);
557 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
558 filetype = 0x12345;
559 hr = IFileSaveDialog_GetFileTypeIndex(pfsd, &filetype);
560 ok(hr == S_OK, "got 0x%08x.\n", hr);
561 ok(filetype == 0, "got %d.\n", filetype);
562
563 /* SetFileTypes / SetFileTypeIndex */
564 hr = IFileOpenDialog_SetFileTypes(pfod, 0, NULL);
565 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
566 hr = IFileOpenDialog_SetFileTypes(pfod, 0, filterspec);
567 ok(hr == S_OK, "got 0x%08x.\n", hr);
568
569 hr = IFileOpenDialog_SetFileTypeIndex(pfod, -1);
570 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
571 hr = IFileOpenDialog_SetFileTypeIndex(pfod, 0);
572 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
573 hr = IFileOpenDialog_SetFileTypeIndex(pfod, 1);
574 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
575 hr = IFileOpenDialog_SetFileTypes(pfod, 1, filterspec);
576 ok(hr == S_OK, "got 0x%08x.\n", hr);
577 hr = IFileOpenDialog_SetFileTypes(pfod, 0, filterspec);
578 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
579 hr = IFileOpenDialog_SetFileTypeIndex(pfod, 0);
580 ok(hr == S_OK, "got 0x%08x.\n", hr);
581 hr = IFileOpenDialog_SetFileTypeIndex(pfod, 100);
582 ok(hr == S_OK, "got 0x%08x.\n", hr);
583 hr = IFileOpenDialog_SetFileTypes(pfod, 1, filterspec);
584 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
585 hr = IFileOpenDialog_SetFileTypes(pfod, 1, &filterspec[1]);
586 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
587
588 hr = IFileSaveDialog_SetFileTypeIndex(pfsd, -1);
589 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
590 hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 0);
591 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
592 hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 1);
593 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
594 hr = IFileSaveDialog_SetFileTypes(pfsd, 1, filterspec);
595 ok(hr == S_OK, "got 0x%08x.\n", hr);
596 hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 0);
597 ok(hr == S_OK, "got 0x%08x.\n", hr);
598 hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 100);
599 ok(hr == S_OK, "got 0x%08x.\n", hr);
600 hr = IFileSaveDialog_SetFileTypes(pfsd, 1, filterspec);
601 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
602 hr = IFileSaveDialog_SetFileTypes(pfsd, 1, &filterspec[1]);
603 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
604
605 /* SetFilter */
606 todo_wine
607 {
608 hr = IFileOpenDialog_SetFilter(pfod, NULL);
609 ok(hr == S_OK, "got 0x%08x.\n", hr);
610 hr = IFileSaveDialog_SetFilter(pfsd, NULL);
611 ok(hr == S_OK, "got 0x%08x.\n", hr);
612 }
613
614 /* SetFolder */
615 hr = IFileOpenDialog_SetFolder(pfod, NULL);
616 ok(hr == S_OK, "got 0x%08x.\n", hr);
617 hr = IFileSaveDialog_SetFolder(pfsd, NULL);
618 ok(hr == S_OK, "got 0x%08x.\n", hr);
619
620 /* SetDefaultExtension */
621 hr = IFileOpenDialog_SetDefaultExtension(pfod, NULL);
622 ok(hr == S_OK, "got 0x%08x.\n", hr);
623 hr = IFileOpenDialog_SetDefaultExtension(pfod, txt);
624 ok(hr == S_OK, "got 0x%08x.\n", hr);
625 hr = IFileOpenDialog_SetDefaultExtension(pfod, null);
626 ok(hr == S_OK, "got 0x%08x.\n", hr);
627
628 hr = IFileSaveDialog_SetDefaultExtension(pfsd, NULL);
629 ok(hr == S_OK, "got 0x%08x.\n", hr);
630 hr = IFileSaveDialog_SetDefaultExtension(pfsd, txt);
631 ok(hr == S_OK, "got 0x%08x.\n", hr);
632 hr = IFileSaveDialog_SetDefaultExtension(pfsd, null);
633 ok(hr == S_OK, "got 0x%08x.\n", hr);
634
635 /* SetDefaultFolder */
636 hr = IFileOpenDialog_SetDefaultFolder(pfod, NULL);
637 ok(hr == S_OK, "got 0x%08x\n", hr);
638 hr = IFileSaveDialog_SetDefaultFolder(pfsd, NULL);
639 ok(hr == S_OK, "got 0x%08x\n", hr);
640
641 hr = IFileOpenDialog_SetDefaultFolder(pfod, psidesktop);
642 ok(hr == S_OK, "got 0x%08x\n", hr);
643 hr = IFileSaveDialog_SetDefaultFolder(pfsd, psidesktop);
644 ok(hr == S_OK, "got 0x%08x\n", hr);
645
646 if(0)
647 {
648 /* Crashes under Windows 7 */
649 IFileOpenDialog_SetDefaultFolder(pfod, (void*)0x1234);
650 IFileSaveDialog_SetDefaultFolder(pfsd, (void*)0x1234);
651 }
652
653 /* GetFolder / SetFolder */
654 hr = IFileOpenDialog_GetFolder(pfod, NULL);
655 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
656
657 hr = IFileOpenDialog_GetFolder(pfod, &psi_original);
658 ok(hr == S_OK, "got 0x%08x.\n", hr);
659 if(SUCCEEDED(hr))
660 {
661 hr = IFileOpenDialog_SetFolder(pfod, psidesktop);
662 ok(hr == S_OK, "got 0x%08x.\n", hr);
663 hr = IFileOpenDialog_SetFolder(pfod, psi_original);
664 ok(hr == S_OK, "got 0x%08x.\n", hr);
665 IShellItem_Release(psi_original);
666 }
667
668 hr = IFileSaveDialog_GetFolder(pfsd, &psi_original);
669 ok(hr == S_OK, "got 0x%08x.\n", hr);
670 if(SUCCEEDED(hr))
671 {
672 hr = IFileSaveDialog_SetFolder(pfsd, psidesktop);
673 ok(hr == S_OK, "got 0x%08x.\n", hr);
674 hr = IFileSaveDialog_SetFolder(pfsd, psi_original);
675 ok(hr == S_OK, "got 0x%08x.\n", hr);
676 IShellItem_Release(psi_original);
677 }
678
679 /* AddPlace */
680 if(0)
681 {
682 /* Crashes under Windows 7 */
683 IFileOpenDialog_AddPlace(pfod, NULL, 0);
684 IFileSaveDialog_AddPlace(pfsd, NULL, 0);
685 }
686
687 todo_wine
688 {
689 hr = IFileOpenDialog_AddPlace(pfod, psidesktop, FDAP_TOP + 1);
690 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
691 hr = IFileOpenDialog_AddPlace(pfod, psidesktop, FDAP_BOTTOM);
692 ok(hr == S_OK, "got 0x%08x\n", hr);
693 hr = IFileOpenDialog_AddPlace(pfod, psidesktop, FDAP_TOP);
694 ok(hr == S_OK, "got 0x%08x\n", hr);
695
696 hr = IFileSaveDialog_AddPlace(pfsd, psidesktop, FDAP_TOP + 1);
697 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
698 hr = IFileSaveDialog_AddPlace(pfsd, psidesktop, FDAP_BOTTOM);
699 ok(hr == S_OK, "got 0x%08x\n", hr);
700 hr = IFileSaveDialog_AddPlace(pfsd, psidesktop, FDAP_TOP);
701 ok(hr == S_OK, "got 0x%08x\n", hr);
702 }
703
704 /* SetFileName */
705 hr = IFileOpenDialog_SetFileName(pfod, NULL);
706 ok(hr == S_OK, "got 0x%08x\n", hr);
707 hr = IFileOpenDialog_SetFileName(pfod, null);
708 ok(hr == S_OK, "got 0x%08x\n", hr);
709 hr = IFileOpenDialog_SetFileName(pfod, txt);
710 ok(hr == S_OK, "got 0x%08x\n", hr);
711 hr = IFileOpenDialog_GetFileName(pfod, &filename);
712 ok(hr == S_OK, "Got 0x%08x\n", hr);
713 ok(!lstrcmpW(filename, txt), "Strings do not match.\n");
714 CoTaskMemFree(filename);
715
716 hr = IFileSaveDialog_SetFileName(pfsd, NULL);
717 ok(hr == S_OK, "got 0x%08x\n", hr);
718 hr = IFileSaveDialog_SetFileName(pfsd, null);
719 ok(hr == S_OK, "got 0x%08x\n", hr);
720 hr = IFileSaveDialog_SetFileName(pfsd, txt);
721 ok(hr == S_OK, "got 0x%08x\n", hr);
722 hr = IFileSaveDialog_GetFileName(pfsd, &filename);
723 ok(hr == S_OK, "Got 0x%08x\n", hr);
724 ok(!lstrcmpW(filename, txt), "Strings do not match.\n");
725 CoTaskMemFree(filename);
726
727 /* SetFileNameLabel */
728 hr = IFileOpenDialog_SetFileNameLabel(pfod, NULL);
729 ok(hr == S_OK, "got 0x%08x\n", hr);
730 hr = IFileOpenDialog_SetFileNameLabel(pfod, null);
731 ok(hr == S_OK, "got 0x%08x\n", hr);
732 hr = IFileOpenDialog_SetFileNameLabel(pfod, txt);
733 ok(hr == S_OK, "got 0x%08x\n", hr);
734
735 hr = IFileSaveDialog_SetFileNameLabel(pfsd, NULL);
736 ok(hr == S_OK, "got 0x%08x\n", hr);
737 hr = IFileSaveDialog_SetFileNameLabel(pfsd, null);
738 ok(hr == S_OK, "got 0x%08x\n", hr);
739 hr = IFileSaveDialog_SetFileNameLabel(pfsd, txt);
740 ok(hr == S_OK, "got 0x%08x\n", hr);
741
742 /* Close */
743 hr = IFileOpenDialog_Close(pfod, S_FALSE);
744 ok(hr == S_OK, "got 0x%08x\n", hr);
745 hr = IFileSaveDialog_Close(pfsd, S_FALSE);
746 ok(hr == S_OK, "got 0x%08x\n", hr);
747
748 /* SetOkButtonLabel */
749 hr = IFileOpenDialog_SetOkButtonLabel(pfod, NULL);
750 ok(hr == S_OK, "got 0x%08x\n", hr);
751 hr = IFileOpenDialog_SetOkButtonLabel(pfod, null);
752 ok(hr == S_OK, "got 0x%08x\n", hr);
753 hr = IFileOpenDialog_SetOkButtonLabel(pfod, txt);
754 ok(hr == S_OK, "got 0x%08x\n", hr);
755 hr = IFileSaveDialog_SetOkButtonLabel(pfsd, NULL);
756 ok(hr == S_OK, "got 0x%08x\n", hr);
757 hr = IFileSaveDialog_SetOkButtonLabel(pfsd, null);
758 ok(hr == S_OK, "got 0x%08x\n", hr);
759 hr = IFileSaveDialog_SetOkButtonLabel(pfsd, txt);
760 ok(hr == S_OK, "got 0x%08x\n", hr);
761
762 /* SetTitle */
763 hr = IFileOpenDialog_SetTitle(pfod, NULL);
764 ok(hr == S_OK, "got 0x%08x\n", hr);
765 hr = IFileOpenDialog_SetTitle(pfod, null);
766 ok(hr == S_OK, "got 0x%08x\n", hr);
767 hr = IFileOpenDialog_SetTitle(pfod, txt);
768 ok(hr == S_OK, "got 0x%08x\n", hr);
769 hr = IFileSaveDialog_SetTitle(pfsd, NULL);
770 ok(hr == S_OK, "got 0x%08x\n", hr);
771 hr = IFileSaveDialog_SetTitle(pfsd, null);
772 ok(hr == S_OK, "got 0x%08x\n", hr);
773 hr = IFileSaveDialog_SetTitle(pfsd, txt);
774 ok(hr == S_OK, "got 0x%08x\n", hr);
775
776 /** IFileOpenDialog specific **/
777
778 /* GetResults */
779 if(0)
780 {
781 /* Crashes under Windows 7 */
782 IFileOpenDialog_GetResults(pfod, NULL);
783 }
784 psia = (void*)0xdeadbeef;
785 hr = IFileOpenDialog_GetResults(pfod, &psia);
786 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
787 ok(psia == NULL, "got %p.\n", psia);
788
789 /* GetSelectedItems */
790 if(0)
791 {
792 /* Crashes under W2K8 */
793 hr = IFileOpenDialog_GetSelectedItems(pfod, NULL);
794 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
795 psia = (void*)0xdeadbeef;
796 hr = IFileOpenDialog_GetSelectedItems(pfod, &psia);
797 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
798 ok(psia == (void*)0xdeadbeef, "got %p.\n", psia);
799 }
800
801 /** IFileSaveDialog specific **/
802
803 /* ApplyProperties */
804 if(0)
805 {
806 /* Crashes under windows 7 */
807 IFileSaveDialog_ApplyProperties(pfsd, NULL, NULL, NULL, NULL);
808 IFileSaveDialog_ApplyProperties(pfsd, psidesktop, NULL, NULL, NULL);
809 }
810
811 /* GetProperties */
812 hr = IFileSaveDialog_GetProperties(pfsd, NULL);
813 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
814 pps = (void*)0xdeadbeef;
815 hr = IFileSaveDialog_GetProperties(pfsd, &pps);
816 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
817 ok(pps == (void*)0xdeadbeef, "got %p\n", pps);
818
819 /* SetProperties */
820 if(0)
821 {
822 /* Crashes under W2K8 */
823 hr = IFileSaveDialog_SetProperties(pfsd, NULL);
824 ok(hr == S_OK, "got 0x%08x\n", hr);
825 }
826
827 /* SetCollectedProperties */
828 todo_wine
829 {
830 hr = IFileSaveDialog_SetCollectedProperties(pfsd, NULL, TRUE);
831 ok(hr == S_OK, "got 0x%08x\n", hr);
832 hr = IFileSaveDialog_SetCollectedProperties(pfsd, NULL, FALSE);
833 ok(hr == S_OK, "got 0x%08x\n", hr);
834 }
835
836 /* SetSaveAsItem */
837 todo_wine
838 {
839 hr = IFileSaveDialog_SetSaveAsItem(pfsd, NULL);
840 ok(hr == S_OK, "got 0x%08x\n", hr);
841 hr = IFileSaveDialog_SetSaveAsItem(pfsd, psidesktop);
842 ok(hr == MK_E_NOOBJECT, "got 0x%08x\n", hr);
843 }
844
845 /** IFileDialog2 **/
846
847 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialog2, (void**)&pfd2);
848 ok((hr == S_OK) || broken(hr == E_NOINTERFACE), "got 0x%08x\n", hr);
849 if(SUCCEEDED(hr))
850 {
851 /* SetCancelButtonLabel */
852 hr = IFileDialog2_SetOkButtonLabel(pfd2, NULL);
853 ok(hr == S_OK, "got 0x%08x\n", hr);
854 hr = IFileDialog2_SetOkButtonLabel(pfd2, null);
855 ok(hr == S_OK, "got 0x%08x\n", hr);
856 hr = IFileDialog2_SetOkButtonLabel(pfd2, txt);
857 ok(hr == S_OK, "got 0x%08x\n", hr);
858
859 /* SetNavigationRoot */
860 todo_wine
861 {
862 hr = IFileDialog2_SetNavigationRoot(pfd2, NULL);
863 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
864 hr = IFileDialog2_SetNavigationRoot(pfd2, psidesktop);
865 ok(hr == S_OK, "got 0x%08x\n", hr);
866 }
867
868 IFileDialog2_Release(pfd2);
869 }
870
871 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialog2, (void**)&pfd2);
872 ok((hr == S_OK) || broken(hr == E_NOINTERFACE), "got 0x%08x\n", hr);
873 if(SUCCEEDED(hr))
874 {
875 /* SetCancelButtonLabel */
876 hr = IFileDialog2_SetOkButtonLabel(pfd2, NULL);
877 ok(hr == S_OK, "got 0x%08x\n", hr);
878 hr = IFileDialog2_SetOkButtonLabel(pfd2, null);
879 ok(hr == S_OK, "got 0x%08x\n", hr);
880 hr = IFileDialog2_SetOkButtonLabel(pfd2, txt);
881 ok(hr == S_OK, "got 0x%08x\n", hr);
882
883 /* SetNavigationRoot */
884 todo_wine
885 {
886 hr = IFileDialog2_SetNavigationRoot(pfd2, NULL);
887 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
888 hr = IFileDialog2_SetNavigationRoot(pfd2, psidesktop);
889 ok(hr == S_OK, "got 0x%08x\n", hr);
890 }
891
892 IFileDialog2_Release(pfd2);
893 }
894
895 /* Cleanup */
896 IShellItem_Release(psidesktop);
897 ref = IFileOpenDialog_Release(pfod);
898 ok(!ref, "Got refcount %d, should have been released.\n", ref);
899 ref = IFileSaveDialog_Release(pfsd);
900 ok(!ref, "Got refcount %d, should have been released.\n", ref);
901 }
902
903 static void ensure_zero_events_(const char *file, int line, IFileDialogEventsImpl *impl)
904 {
905 ok_(file, line)(!impl->OnFileOk, "OnFileOk: %d\n", impl->OnFileOk);
906 ok_(file, line)(!impl->OnFolderChanging, "OnFolderChanging: %d\n", impl->OnFolderChanging);
907 ok_(file, line)(!impl->OnFolderChange, "OnFolderChange: %d\n", impl->OnFolderChange);
908 ok_(file, line)(!impl->OnSelectionChange, "OnSelectionChange: %d\n", impl->OnSelectionChange);
909 ok_(file, line)(!impl->OnShareViolation, "OnShareViolation: %d\n", impl->OnShareViolation);
910 ok_(file, line)(!impl->OnTypeChange, "OnTypeChange: %d\n", impl->OnTypeChange);
911 ok_(file, line)(!impl->OnOverwrite, "OnOverwrite: %d\n", impl->OnOverwrite);
912 impl->OnFileOk = impl->OnFolderChanging = impl->OnFolderChange = 0;
913 impl->OnSelectionChange = impl->OnShareViolation = impl->OnTypeChange = 0;
914 impl->OnOverwrite = 0;
915 }
916 #define ensure_zero_events(impl) ensure_zero_events_(__FILE__, __LINE__, impl)
917
918 static void test_advise_helper(IFileDialog *pfd)
919 {
920 IFileDialogEventsImpl *pfdeimpl;
921 IFileDialogEvents *pfde;
922 DWORD cookie[10];
923 UINT i;
924 HRESULT hr;
925
926 pfde = IFileDialogEvents_Constructor();
927 pfdeimpl = impl_from_IFileDialogEvents(pfde);
928
929 hr = IFileDialog_Advise(pfd, NULL, NULL);
930 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
931 hr = IFileDialog_Advise(pfd, pfde, NULL);
932 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
933 hr = IFileDialog_Advise(pfd, NULL, &cookie[0]);
934 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
935 ok(pfdeimpl->ref == 1, "got ref %d\n", pfdeimpl->ref);
936 ensure_zero_events(pfdeimpl);
937
938 hr = IFileDialog_Unadvise(pfd, 0);
939 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
940 for(i = 0; i < 10; i++) {
941 hr = IFileDialog_Advise(pfd, pfde, &cookie[i]);
942 ok(hr == S_OK, "got 0x%08x\n", hr);
943 ok(cookie[i] == i+1, "Got cookie: %d\n", cookie[i]);
944 }
945 ok(pfdeimpl->ref == 10+1, "got ref %d\n", pfdeimpl->ref);
946 ensure_zero_events(pfdeimpl);
947
948 for(i = 3; i < 7; i++) {
949 hr = IFileDialog_Unadvise(pfd, cookie[i]);
950 ok(hr == S_OK, "got 0x%08x\n", hr);
951 }
952 ok(pfdeimpl->ref == 6+1, "got ref %d\n", pfdeimpl->ref);
953 ensure_zero_events(pfdeimpl);
954
955 for(i = 0; i < 3; i++) {
956 hr = IFileDialog_Unadvise(pfd, cookie[i]);
957 ok(hr == S_OK, "got 0x%08x\n", hr);
958 }
959 ok(pfdeimpl->ref == 3+1, "got ref %d\n", pfdeimpl->ref);
960 ensure_zero_events(pfdeimpl);
961
962 for(i = 7; i < 10; i++) {
963 hr = IFileDialog_Unadvise(pfd, cookie[i]);
964 ok(hr == S_OK, "got 0x%08x\n", hr);
965 }
966 ok(pfdeimpl->ref == 1, "got ref %d\n", pfdeimpl->ref);
967 ensure_zero_events(pfdeimpl);
968
969 hr = IFileDialog_Unadvise(pfd, cookie[9]+1);
970 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
971 ok(pfdeimpl->ref == 1, "got ref %d\n", pfdeimpl->ref);
972 ensure_zero_events(pfdeimpl);
973
974 hr = IFileDialog_Advise(pfd, pfde, &cookie[0]);
975 ok(hr == S_OK, "got 0x%08x\n", hr);
976 todo_wine ok(cookie[0] == 1, "got cookie: %d\n", cookie[0]);
977 ok(pfdeimpl->ref == 1+1, "got ref %d\n", pfdeimpl->ref);
978 ensure_zero_events(pfdeimpl);
979
980 hr = IFileDialog_Unadvise(pfd, cookie[0]);
981
982 if(0)
983 {
984 /* Unadvising already unadvised cookies crashes on
985 Windows 7. */
986 IFileDialog_Unadvise(pfd, cookie[0]);
987 }
988
989
990 IFileDialogEvents_Release(pfde);
991 }
992
993 static void test_advise(void)
994 {
995 IFileDialog *pfd;
996 HRESULT hr;
997 LONG ref;
998
999 trace("Testing FileOpenDialog (advise)\n");
1000 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
1001 &IID_IFileDialog, (void**)&pfd);
1002 ok(hr == S_OK, "got 0x%08x.\n", hr);
1003 test_advise_helper(pfd);
1004 ref = IFileDialog_Release(pfd);
1005 ok(!ref, "Got refcount %d, should have been released.\n", ref);
1006
1007 trace("Testing FileSaveDialog (advise)\n");
1008 hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER,
1009 &IID_IFileDialog, (void**)&pfd);
1010 ok(hr == S_OK, "got 0x%08x.\n", hr);
1011 test_advise_helper(pfd);
1012 ref = IFileDialog_Release(pfd);
1013 ok(!ref, "Got refcount %d, should have been released.\n", ref);
1014 }
1015
1016 static void touch_file(LPCWSTR filename)
1017 {
1018 HANDLE file;
1019 file = CreateFileW(filename, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
1020 ok(file != INVALID_HANDLE_VALUE, "Failed to create file.\n");
1021 CloseHandle(file);
1022 }
1023
1024 static void test_filename_savedlg_(LPCWSTR set_filename, LPCWSTR defext,
1025 const COMDLG_FILTERSPEC *filterspec, UINT fs_count,
1026 LPCWSTR exp_filename, const char *file, int line)
1027 {
1028 IFileSaveDialog *pfsd;
1029 IFileDialogEventsImpl *pfdeimpl;
1030 IFileDialogEvents *pfde;
1031 DWORD cookie;
1032 LPWSTR filename;
1033 IShellItem *psi;
1034 LONG ref;
1035 HRESULT hr;
1036
1037 hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER,
1038 &IID_IFileSaveDialog, (void**)&pfsd);
1039 ok_(file,line)(hr == S_OK, "Got 0x%08x\n", hr);
1040
1041 if(fs_count)
1042 {
1043 hr = IFileSaveDialog_SetFileTypes(pfsd, fs_count, filterspec);
1044 ok_(file,line)(hr == S_OK, "SetFileTypes failed: Got 0x%08x\n", hr);
1045 }
1046
1047 if(defext)
1048 {
1049 hr = IFileSaveDialog_SetDefaultExtension(pfsd, defext);
1050 ok_(file,line)(hr == S_OK, "SetDefaultExtensions failed: Got 0x%08x\n", hr);
1051 }
1052
1053 pfde = IFileDialogEvents_Constructor();
1054 pfdeimpl = impl_from_IFileDialogEvents(pfde);
1055 pfdeimpl->set_filename = set_filename;
1056 hr = IFileSaveDialog_Advise(pfsd, pfde, &cookie);
1057 ok_(file,line)(hr == S_OK, "Advise failed: Got 0x%08x\n", hr);
1058
1059 hr = IFileSaveDialog_Show(pfsd, NULL);
1060 ok_(file,line)(hr == S_OK, "Show failed: Got 0x%08x\n", hr);
1061
1062 hr = IFileSaveDialog_GetFileName(pfsd, &filename);
1063 ok_(file,line)(hr == S_OK, "GetFileName failed: Got 0x%08x\n", hr);
1064 ok_(file,line)(!lstrcmpW(filename, set_filename), "Got %s\n", wine_dbgstr_w(filename));
1065 CoTaskMemFree(filename);
1066
1067 hr = IFileSaveDialog_GetResult(pfsd, &psi);
1068 ok_(file,line)(hr == S_OK, "GetResult failed: Got 0x%08x\n", hr);
1069
1070 hr = IShellItem_GetDisplayName(psi, SIGDN_PARENTRELATIVEPARSING, &filename);
1071 ok_(file,line)(hr == S_OK, "GetDisplayName failed: Got 0x%08x\n", hr);
1072 ok_(file,line)(!lstrcmpW(filename, exp_filename), "(GetDisplayName) Got %s\n", wine_dbgstr_w(filename));
1073 CoTaskMemFree(filename);
1074 IShellItem_Release(psi);
1075
1076 hr = IFileSaveDialog_Unadvise(pfsd, cookie);
1077 ok_(file,line)(hr == S_OK, "Unadvise failed: Got 0x%08x\n", hr);
1078
1079 ref = IFileSaveDialog_Release(pfsd);
1080 ok_(file,line)(!ref, "Got refcount %d, should have been released.\n", ref);
1081
1082 IFileDialogEvents_Release(pfde);
1083 }
1084 #define test_filename_savedlg(set_filename, defext, filterspec, fs_count, exp_filename) \
1085 test_filename_savedlg_(set_filename, defext, filterspec, fs_count, exp_filename, __FILE__, __LINE__)
1086
1087 static void test_filename_opendlg_(LPCWSTR set_filename, IShellItem *psi_current, LPCWSTR defext,
1088 const COMDLG_FILTERSPEC *filterspec, UINT fs_count,
1089 LPCWSTR exp_filename, const char *file, int line)
1090 {
1091 IFileOpenDialog *pfod;
1092 IFileDialogEventsImpl *pfdeimpl;
1093 IFileDialogEvents *pfde;
1094 DWORD cookie;
1095 LPWSTR filename;
1096 IShellItemArray *psia;
1097 IShellItem *psi;
1098 LONG ref;
1099 HRESULT hr;
1100
1101 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
1102 &IID_IFileOpenDialog, (void**)&pfod);
1103 ok_(file,line)(hr == S_OK, "CoCreateInstance failed: Got 0x%08x\n", hr);
1104
1105 if(defext)
1106 {
1107 hr = IFileOpenDialog_SetDefaultExtension(pfod, defext);
1108 ok_(file,line)(hr == S_OK, "SetDefaultExtensions failed: Got 0x%08x\n", hr);
1109 }
1110
1111 if(fs_count)
1112 {
1113 hr = IFileOpenDialog_SetFileTypes(pfod, 2, filterspec);
1114 ok_(file,line)(hr == S_OK, "SetFileTypes failed: Got 0x%08x\n", hr);
1115 }
1116
1117 hr = IFileOpenDialog_SetFolder(pfod, psi_current);
1118 ok_(file,line)(hr == S_OK, "SetFolder failed: Got 0x%08x\n", hr);
1119
1120 pfde = IFileDialogEvents_Constructor();
1121 pfdeimpl = impl_from_IFileDialogEvents(pfde);
1122 pfdeimpl->set_filename = set_filename;
1123 pfdeimpl->set_filename_tried = FALSE;
1124 hr = IFileOpenDialog_Advise(pfod, pfde, &cookie);
1125 ok_(file,line)(hr == S_OK, "Advise failed: Got 0x%08x\n", hr);
1126
1127 hr = IFileOpenDialog_Show(pfod, NULL);
1128 ok_(file,line)(hr == S_OK || (!exp_filename && hr == HRESULT_FROM_WIN32(ERROR_CANCELLED)),
1129 "Show failed: Got 0x%08x\n", hr);
1130 if(hr == S_OK)
1131 {
1132 hr = IFileOpenDialog_GetResult(pfod, &psi);
1133 ok_(file,line)(hr == S_OK, "GetResult failed: Got 0x%08x\n", hr);
1134
1135 hr = IShellItem_GetDisplayName(psi, SIGDN_PARENTRELATIVEPARSING, &filename);
1136 ok_(file,line)(hr == S_OK, "GetDisplayName(Result) failed: Got 0x%08x\n", hr);
1137 ok_(file,line)(!lstrcmpW(filename, exp_filename), "(GetResult) Got %s\n", wine_dbgstr_w(filename));
1138 CoTaskMemFree(filename);
1139 IShellItem_Release(psi);
1140
1141 hr = IFileOpenDialog_GetResults(pfod, &psia);
1142 ok_(file,line)(hr == S_OK, "GetResults failed: Got 0x%08x\n", hr);
1143 hr = IShellItemArray_GetItemAt(psia, 0, &psi);
1144 ok_(file,line)(hr == S_OK, "GetItemAt failed: Got 0x%08x\n", hr);
1145
1146 hr = IShellItem_GetDisplayName(psi, SIGDN_PARENTRELATIVEPARSING, &filename);
1147 ok_(file,line)(hr == S_OK, "GetDisplayName(Results) failed: Got 0x%08x\n", hr);
1148 ok_(file,line)(!lstrcmpW(filename, exp_filename), "(GetResults) Got %s\n", wine_dbgstr_w(filename));
1149 CoTaskMemFree(filename);
1150
1151 IShellItem_Release(psi);
1152 IShellItemArray_Release(psia);
1153 }
1154 else
1155 {
1156 hr = IFileOpenDialog_GetResult(pfod, &psi);
1157 ok_(file,line)(hr == E_UNEXPECTED, "GetResult: Got 0x%08x\n", hr);
1158
1159 hr = IFileOpenDialog_GetResults(pfod, &psia);
1160 ok_(file,line)(hr == E_FAIL, "GetResults: Got 0x%08x\n", hr);
1161 }
1162
1163 hr = IFileOpenDialog_GetFileName(pfod, &filename);
1164 ok_(file,line)(hr == S_OK, "GetFileName failed: Got 0x%08x\n", hr);
1165 ok_(file,line)(!lstrcmpW(filename, set_filename), "(GetFileName) Got %s\n", wine_dbgstr_w(filename));
1166 CoTaskMemFree(filename);
1167
1168
1169 hr = IFileOpenDialog_Unadvise(pfod, cookie);
1170 ok_(file,line)(hr == S_OK, "Unadvise failed: Got 0x%08x\n", hr);
1171
1172 ref = IFileOpenDialog_Release(pfod);
1173 ok_(file,line)(!ref, "Got refcount %d, should have been released.\n", ref);
1174
1175 IFileDialogEvents_Release(pfde);
1176 }
1177 #define test_filename_opendlg(set_filename, psi, defext, filterspec, fs_count, exp_filename) \
1178 test_filename_opendlg_(set_filename, psi, defext, filterspec, fs_count, exp_filename, __FILE__, __LINE__)
1179
1180 static void test_filename(void)
1181 {
1182 IShellItem *psi_current;
1183 HRESULT hr;
1184 WCHAR buf[MAX_PATH];
1185
1186 static const WCHAR filename_noextW[] = {'w','i','n','e','t','e','s','t',0};
1187 static const WCHAR filename_dotextW[] = {'w','i','n','e','t','e','s','t','.',0};
1188 static const WCHAR filename_dotanddefW[] = {'w','i','n','e','t','e','s','t','.','.','w','t','e',0};
1189 static const WCHAR filename_defextW[] = {'w','i','n','e','t','e','s','t','.','w','t','e',0};
1190 static const WCHAR filename_ext1W[] = {'w','i','n','e','t','e','s','t','.','w','t','1',0};
1191 static const WCHAR filename_ext2W[] = {'w','i','n','e','t','e','s','t','.','w','t','2',0};
1192 static const WCHAR filename_ext1anddefW[] =
1193 {'w','i','n','e','t','e','s','t','.','w','t','1','.','w','t','e',0};
1194 static const WCHAR defextW[] = {'w','t','e',0};
1195 static const WCHAR desc1[] = {'d','e','s','c','r','i','p','t','i','o','n','1',0};
1196 static const WCHAR desc2[] = {'d','e','s','c','r','i','p','t','i','o','n','2',0};
1197 static const WCHAR descdef[] = {'d','e','f','a','u','l','t',' ','d','e','s','c',0};
1198 static const WCHAR ext1[] = {'*','.','w','t','1',0};
1199 static const WCHAR ext2[] = {'*','.','w','t','2',0};
1200 static const WCHAR extdef[] = {'*','.','w','t','e',0};
1201 static const WCHAR complexext[] = {'*','.','w','t','2',';','*','.','w','t','1',0};
1202
1203 static const COMDLG_FILTERSPEC filterspec[] = {
1204 { desc1, ext1 }, { desc2, ext2 }, { descdef, extdef }
1205 };
1206 static const COMDLG_FILTERSPEC filterspec2[] = {
1207 { desc1, complexext }
1208 };
1209
1210 /* No extension */
1211 test_filename_savedlg(filename_noextW, NULL, NULL, 0, filename_noextW);
1212 /* Default extension */
1213 test_filename_savedlg(filename_noextW, defextW, NULL, 0, filename_defextW);
1214 /* Default extension on filename ending with a . */
1215 test_filename_savedlg(filename_dotextW, defextW, NULL, 0, filename_dotanddefW);
1216 /* Default extension on filename with default extension */
1217 test_filename_savedlg(filename_defextW, defextW, NULL, 0, filename_defextW);
1218 /* Default extension on filename with another extension */
1219 test_filename_savedlg(filename_ext1W, defextW, NULL, 0, filename_ext1anddefW);
1220 /* Default extension, filterspec without default extension */
1221 test_filename_savedlg(filename_noextW, defextW, filterspec, 2, filename_ext1W);
1222 /* Default extension, filterspec with default extension */
1223 test_filename_savedlg(filename_noextW, defextW, filterspec, 3, filename_ext1W);
1224 /* Default extension, filterspec with "complex" extension */
1225 test_filename_savedlg(filename_noextW, defextW, filterspec2, 1, filename_ext2W);
1226
1227 GetCurrentDirectoryW(MAX_PATH, buf);
1228 ok(!!pSHCreateItemFromParsingName, "SHCreateItemFromParsingName is missing.\n");
1229 hr = pSHCreateItemFromParsingName(buf, NULL, &IID_IShellItem, (void**)&psi_current);
1230 ok(hr == S_OK, "Got 0x%08x\n", hr);
1231
1232 touch_file(filename_noextW);
1233 touch_file(filename_defextW);
1234 touch_file(filename_ext2W);
1235
1236 /* IFileOpenDialog, default extension */
1237 test_filename_opendlg(filename_noextW, psi_current, defextW, NULL, 0, filename_noextW);
1238 /* IFileOpenDialog, default extension and filterspec */
1239 test_filename_opendlg(filename_noextW, psi_current, defextW, filterspec, 2, filename_noextW);
1240
1241 DeleteFileW(filename_noextW);
1242 /* IFileOpenDialog, default extension, noextW deleted */
1243 test_filename_opendlg(filename_noextW, psi_current, defextW, NULL, 0, filename_defextW);
1244 if(0) /* Interactive */
1245 {
1246 /* IFileOpenDialog, filterspec, no default extension, noextW deleted */
1247 test_filename_opendlg(filename_noextW, psi_current, NULL, filterspec, 2, NULL);
1248 }
1249
1250 IShellItem_Release(psi_current);
1251 DeleteFileW(filename_defextW);
1252 DeleteFileW(filename_ext2W);
1253 }
1254
1255 static const WCHAR label[] = {'l','a','b','e','l',0};
1256 static const WCHAR label2[] = {'t','e','s','t',0};
1257 static const WCHAR menuW[] = {'m','e','n','u','_','i','t','e','m',0};
1258 static const WCHAR pushbutton1W[] = {'p','u','s','h','b','u','t','t','o','n','_','i','t','e','m',0};
1259 static const WCHAR pushbutton2W[] = {'p','u','s','h','b','u','t','t','o','n','2','_','i','t','e','m',0};
1260 static const WCHAR comboboxitem1W[] = {'c','o','m','b','o','b','o','x','1','_','i','t','e','m',0};
1261 static const WCHAR comboboxitem2W[] = {'c','o','m','b','o','b','o','x','2','_','i','t','e','m',0};
1262 static const WCHAR radiobutton1W[] = {'r','a','d','i','o','b','u','t','t','o','n','1','_','i','t','e','m',0};
1263 static const WCHAR radiobutton2W[] = {'r','a','d','i','o','b','u','t','t','o','n','2','_','i','t','e','m',0};
1264 static const WCHAR checkbutton1W[] = {'c','h','e','c','k','b','u','t','t','o','n','1','_','i','t','e','m',0};
1265 static const WCHAR checkbutton2W[] = {'c','h','e','c','k','b','u','t','t','o','n','2','_','i','t','e','m',0};
1266 static const WCHAR editbox1W[] = {'e','d','i','t','b','o','x','W','1','_','i','t','e','m',0};
1267 static const WCHAR editbox2W[] = {'e','d','i','t','b','o','x','W','2','_','i','t','e','m',0};
1268 static const WCHAR textW[] = {'t','e','x','t','_','i','t','e','m',0};
1269 static const WCHAR text2W[] = {'t','e','x','t','2','_','i','t','e','m',0};
1270 static const WCHAR separatorW[] = {'s','e','p','a','r','a','t','o','r','_','i','t','e','m',0};
1271 static const WCHAR visualgroup1W[] = {'v','i','s','u','a','l','g','r','o','u','p','1',0};
1272 static const WCHAR visualgroup2W[] = {'v','i','s','u','a','l','g','r','o','u','p','2',0};
1273
1274 static const WCHAR floatnotifysinkW[] = {'F','l','o','a','t','N','o','t','i','f','y','S','i','n','k',0};
1275 static const WCHAR RadioButtonListW[] = {'R','a','d','i','o','B','u','t','t','o','n','L','i','s','t',0};
1276
1277 struct fw_arg {
1278 LPCWSTR class, text;
1279 HWND hwnd_res;
1280 };
1281 static BOOL CALLBACK find_window_callback(HWND hwnd, LPARAM lparam)
1282 {
1283 struct fw_arg *arg = (struct fw_arg*)lparam;
1284 WCHAR buf[1024];
1285
1286 if(arg->class)
1287 {
1288 GetClassNameW(hwnd, buf, 1024);
1289 if(lstrcmpW(buf, arg->class))
1290 return TRUE;
1291 }
1292
1293 if(arg->text)
1294 {
1295 GetWindowTextW(hwnd, buf, 1024);
1296 if(lstrcmpW(buf, arg->text))
1297 return TRUE;
1298 }
1299
1300 arg->hwnd_res = hwnd;
1301 return FALSE;
1302 }
1303
1304 static HWND find_window(HWND parent, LPCWSTR class, LPCWSTR text)
1305 {
1306 struct fw_arg arg = {class, text, NULL};
1307
1308 EnumChildWindows(parent, find_window_callback, (LPARAM)&arg);
1309 return arg.hwnd_res;
1310 }
1311
1312 static void test_customize_onfolderchange(IFileDialog *pfd)
1313 {
1314 IOleWindow *pow;
1315 HWND dlg_hwnd, item, item_parent;
1316 HRESULT hr;
1317 BOOL br;
1318 WCHAR buf[1024];
1319
1320 buf[0] = '\0';
1321
1322 hr = IFileDialog_QueryInterface(pfd, &IID_IOleWindow, (void**)&pow);
1323 ok(hr == S_OK, "Got 0x%08x\n", hr);
1324 hr = IOleWindow_GetWindow(pow, &dlg_hwnd);
1325 ok(hr == S_OK, "Got 0x%08x\n", hr);
1326 ok(dlg_hwnd != NULL, "Got NULL.\n");
1327 IOleWindow_Release(pow);
1328
1329 item = find_window(dlg_hwnd, NULL, checkbutton2W);
1330 ok(item != NULL, "Failed to find item.\n");
1331 item_parent = GetParent(item);
1332 GetClassNameW(item_parent, buf, 1024);
1333 ok(!lstrcmpW(buf, floatnotifysinkW), "Got %s\n", wine_dbgstr_w(buf));
1334 item = find_window(dlg_hwnd, NULL, text2W);
1335 ok(item != NULL, "Failed to find item.\n");
1336 item_parent = GetParent(item);
1337 GetClassNameW(item_parent, buf, 1024);
1338 ok(!lstrcmpW(buf, floatnotifysinkW), "Got %s\n", wine_dbgstr_w(buf));
1339 item = find_window(dlg_hwnd, NULL, radiobutton1W);
1340 todo_wine ok(item != NULL, "Failed to find item.\n");
1341 item_parent = GetParent(item);
1342 GetClassNameW(item_parent, buf, 1024);
1343 todo_wine ok(!lstrcmpW(buf, RadioButtonListW), "Got %s\n", wine_dbgstr_w(buf));
1344 item_parent = GetParent(item_parent);
1345 GetClassNameW(item_parent, buf, 1024);
1346 ok(!lstrcmpW(buf, floatnotifysinkW), "Got %s\n", wine_dbgstr_w(buf));
1347
1348 item = find_window(dlg_hwnd, NULL, pushbutton1W);
1349 ok(item == NULL, "Found item: %p\n", item);
1350 item = find_window(dlg_hwnd, NULL, pushbutton2W);
1351 ok(item == NULL, "Found item: %p\n", item);
1352 item = find_window(dlg_hwnd, NULL, comboboxitem1W);
1353 ok(item == NULL, "Found item: %p\n", item);
1354 item = find_window(dlg_hwnd, NULL, comboboxitem2W);
1355 ok(item == NULL, "Found item: %p\n", item);
1356 item = find_window(dlg_hwnd, NULL, radiobutton2W);
1357 ok(item == NULL, "Found item: %p\n", item);
1358 item = find_window(dlg_hwnd, NULL, checkbutton1W);
1359 ok(item == NULL, "Found item: %p\n", item);
1360 item = find_window(dlg_hwnd, NULL, editbox1W);
1361 ok(item == NULL, "Found item: %p\n", item);
1362 item = find_window(dlg_hwnd, NULL, editbox2W);
1363 ok(item == NULL, "Found item: %p\n", item);
1364 item = find_window(dlg_hwnd, NULL, textW);
1365 ok(item == NULL, "Found item: %p\n", item);
1366 item = find_window(dlg_hwnd, NULL, separatorW);
1367 ok(item == NULL, "Found item: %p\n", item);
1368 item = find_window(dlg_hwnd, NULL, visualgroup1W);
1369 ok(item == NULL, "Found item: %p\n", item);
1370 item = find_window(dlg_hwnd, NULL, visualgroup2W);
1371 ok(item == NULL, "Found item: %p\n", item);
1372
1373 br = PostMessageW(dlg_hwnd, WM_COMMAND, IDCANCEL, 0);
1374 ok(br, "Failed\n");
1375 }
1376
1377 static void test_customize(void)
1378 {
1379 IFileDialog *pfod;
1380 IFileDialogCustomize *pfdc;
1381 IFileDialogEventsImpl *pfdeimpl;
1382 IFileDialogEvents *pfde;
1383 IOleWindow *pow;
1384 CDCONTROLSTATEF cdstate;
1385 DWORD cookie;
1386 LPWSTR tmpstr;
1387 UINT i;
1388 LONG ref;
1389 HWND dlg_hwnd;
1390 HRESULT hr;
1391 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
1392 &IID_IFileDialog, (void**)&pfod);
1393 ok(hr == S_OK, "got 0x%08x.\n", hr);
1394
1395 hr = IFileDialog_QueryInterface(pfod, &IID_IFileDialogCustomize, (void**)&pfdc);
1396 ok(hr == S_OK, "got 0x%08x.\n", hr);
1397 if(FAILED(hr))
1398 {
1399 skip("Skipping IFileDialogCustomize tests.\n");
1400 IFileDialog_Release(pfod);
1401 return;
1402 }
1403
1404 i = 0;
1405 hr = IFileDialogCustomize_AddPushButton(pfdc, i, pushbutton1W);
1406 ok(hr == S_OK, "got 0x%08x.\n", hr);
1407 hr = IFileDialogCustomize_AddPushButton(pfdc, i, pushbutton1W);
1408 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1409
1410 hr = IFileDialog_QueryInterface(pfod, &IID_IOleWindow, (void**)&pow);
1411 ok(hr == S_OK, "Got 0x%08x\n", hr);
1412 hr = IOleWindow_GetWindow(pow, &dlg_hwnd);
1413 ok(hr == S_OK, "Got 0x%08x\n", hr);
1414 ok(dlg_hwnd == NULL, "NULL\n");
1415 IOleWindow_Release(pow);
1416
1417 cdstate = 0xdeadbeef;
1418 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1419 ok(hr == S_OK, "got 0x%08x.\n", hr);
1420 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1421
1422 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1423 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
1424
1425 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1426 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1427
1428 hr = IFileDialogCustomize_EnableOpenDropDown(pfdc, i);
1429 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1430 hr = IFileDialogCustomize_EnableOpenDropDown(pfdc, ++i);
1431 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1432
1433 cdstate = 0xdeadbeef;
1434 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1435 ok(hr == E_NOTIMPL, "got 0x%08x.\n", hr);
1436 ok(cdstate == 0xdeadbeef, "got 0x%08x.\n", cdstate);
1437
1438 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1439 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1440 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1441 todo_wine ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
1442
1443 cdstate = 0xdeadbeef;
1444 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1445 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1446 todo_wine ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1447 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, 0);
1448 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1449 cdstate = 0xdeadbeef;
1450 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1451 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1452 todo_wine ok(!cdstate, "got 0x%08x.\n", cdstate);
1453 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, CDCS_ENABLEDVISIBLE);
1454 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1455 cdstate = 0xdeadbeef;
1456 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1457 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1458 todo_wine ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1459
1460 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1461 todo_wine ok(hr == E_NOTIMPL, "got 0x%08x (control: %d).\n", hr, i);
1462
1463 hr = IFileDialogCustomize_AddMenu(pfdc, i, menuW);
1464 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1465 hr = IFileDialogCustomize_AddMenu(pfdc, ++i, label);
1466 ok(hr == S_OK, "got 0x%08x.\n", hr);
1467
1468 cdstate = 0xdeadbeef;
1469 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1470 ok(hr == S_OK, "got 0x%08x.\n", hr);
1471 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1472
1473 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1474 ok(hr == S_OK, "got 0x%08x.\n", hr);
1475 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1476 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
1477
1478 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1479 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1480
1481 hr = IFileDialogCustomize_AddPushButton(pfdc, i, pushbutton2W);
1482 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1483 hr = IFileDialogCustomize_AddPushButton(pfdc, ++i, pushbutton2W);
1484 ok(hr == S_OK, "got 0x%08x.\n", hr);
1485
1486 cdstate = 0xdeadbeef;
1487 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1488 ok(hr == S_OK, "got 0x%08x.\n", hr);
1489 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1490
1491 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1492 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
1493
1494 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1495 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1496
1497 hr = IFileDialogCustomize_AddComboBox(pfdc, i);
1498 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1499 hr = IFileDialogCustomize_AddComboBox(pfdc, ++i);
1500 ok(hr == S_OK, "got 0x%08x.\n", hr);
1501
1502 cdstate = 0xdeadbeef;
1503 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1504 ok(hr == S_OK, "got 0x%08x.\n", hr);
1505 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1506
1507 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1508 ok(hr == S_OK, "got 0x%08x.\n", hr);
1509 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1510 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
1511
1512 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1513 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1514
1515 hr = IFileDialogCustomize_AddRadioButtonList(pfdc, i);
1516 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1517 hr = IFileDialogCustomize_AddRadioButtonList(pfdc, ++i);
1518 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1519
1520 cdstate = 0xdeadbeef;
1521 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1522 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1523 todo_wine ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1524
1525 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, radiobutton1W);
1526 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1527 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, radiobutton1W);
1528 todo_wine ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
1529
1530 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, radiobutton2W);
1531 todo_wine ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1532
1533 hr = IFileDialogCustomize_AddCheckButton(pfdc, i, label, TRUE);
1534 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1535 hr = IFileDialogCustomize_AddCheckButton(pfdc, ++i, checkbutton1W, TRUE);
1536 ok(hr == S_OK, "got 0x%08x.\n", hr);
1537
1538 cdstate = 0xdeadbeef;
1539 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1540 ok(hr == S_OK, "got 0x%08x.\n", hr);
1541 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1542
1543 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1544 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
1545
1546 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, checkbutton2W);
1547 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1548
1549 if(SUCCEEDED(hr))
1550 {
1551 BOOL checked;
1552 hr = IFileDialogCustomize_GetCheckButtonState(pfdc, i, &checked);
1553 ok(hr == S_OK, "got 0x%08x.\n", hr);
1554 ok(checked, "checkbox not checked.\n");
1555
1556 hr = IFileDialogCustomize_SetCheckButtonState(pfdc, i, FALSE);
1557 ok(hr == S_OK, "got 0x%08x.\n", hr);
1558
1559 hr = IFileDialogCustomize_GetCheckButtonState(pfdc, i, &checked);
1560 ok(hr == S_OK, "got 0x%08x.\n", hr);
1561 ok(!checked, "checkbox checked.\n");
1562
1563 hr = IFileDialogCustomize_SetCheckButtonState(pfdc, i, TRUE);
1564 ok(hr == S_OK, "got 0x%08x.\n", hr);
1565
1566 hr = IFileDialogCustomize_GetCheckButtonState(pfdc, i, &checked);
1567 ok(hr == S_OK, "got 0x%08x.\n", hr);
1568 ok(checked, "checkbox not checked.\n");
1569 }
1570
1571 hr = IFileDialogCustomize_AddEditBox(pfdc, i, label);
1572 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1573 hr = IFileDialogCustomize_AddEditBox(pfdc, ++i, editbox1W);
1574 ok(hr == S_OK, "got 0x%08x.\n", hr);
1575
1576 cdstate = 0xdeadbeef;
1577 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1578 ok(hr == S_OK, "got 0x%08x.\n", hr);
1579 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1580
1581 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1582 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
1583
1584 /* Does not affect the text in the editbox */
1585 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, editbox2W);
1586 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1587
1588 hr = IFileDialogCustomize_GetEditBoxText(pfdc, i, &tmpstr);
1589 ok(hr == S_OK, "got 0x%08x.\n", hr);
1590 if(SUCCEEDED(hr))
1591 {
1592 ok(!lstrcmpW(tmpstr, editbox1W), "got %s.\n", wine_dbgstr_w(tmpstr));
1593 CoTaskMemFree(tmpstr);
1594 }
1595
1596 hr = IFileDialogCustomize_SetEditBoxText(pfdc, i, label2);
1597 ok(hr == S_OK, "got 0x%08x.\n", hr);
1598
1599 hr = IFileDialogCustomize_GetEditBoxText(pfdc, i, &tmpstr);
1600 ok(hr == S_OK, "got 0x%08x.\n", hr);
1601 if(SUCCEEDED(hr))
1602 {
1603 ok(!lstrcmpW(tmpstr, label2), "got %s.\n", wine_dbgstr_w(tmpstr));
1604 CoTaskMemFree(tmpstr);
1605 }
1606
1607 hr = IFileDialogCustomize_AddSeparator(pfdc, i);
1608 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1609 hr = IFileDialogCustomize_AddSeparator(pfdc, ++i);
1610 ok(hr == S_OK, "got 0x%08x.\n", hr);
1611
1612 cdstate = 0xdeadbeef;
1613 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1614 ok(hr == S_OK, "got 0x%08x.\n", hr);
1615 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1616
1617 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1618 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
1619
1620 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, separatorW);
1621 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1622
1623 hr = IFileDialogCustomize_AddText(pfdc, i, label);
1624 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1625 hr = IFileDialogCustomize_AddText(pfdc, ++i, textW);
1626 ok(hr == S_OK, "got 0x%08x.\n", hr);
1627
1628 cdstate = 0xdeadbeef;
1629 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1630 ok(hr == S_OK, "got 0x%08x.\n", hr);
1631 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1632
1633 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1634 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
1635
1636 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, text2W);
1637 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1638
1639 hr = IFileDialogCustomize_StartVisualGroup(pfdc, i, label);
1640 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1641 hr = IFileDialogCustomize_StartVisualGroup(pfdc, ++i, visualgroup1W);
1642 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1643
1644 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1645 todo_wine ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
1646
1647 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, visualgroup2W);
1648 todo_wine ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1649
1650 cdstate = 0xdeadbeef;
1651 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1652 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1653 todo_wine ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1654
1655 hr = IFileDialogCustomize_StartVisualGroup(pfdc, ++i, label);
1656 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1657 hr = IFileDialogCustomize_EndVisualGroup(pfdc);
1658 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1659
1660 i++; /* Nonexisting control */
1661 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1662 todo_wine ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
1663 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1664 ok(hr == E_INVALIDARG, "got 0x%08x (control: %d).\n", hr, i);
1665 cdstate = 0xdeadbeef;
1666 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1667 todo_wine ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
1668 ok(cdstate == 0xdeadbeef, "got 0x%08x.\n", cdstate);
1669
1670 pfde = IFileDialogEvents_Constructor();
1671 pfdeimpl = impl_from_IFileDialogEvents(pfde);
1672 pfdeimpl->cfd_test1 = TRUE;
1673 hr = IFileDialog_Advise(pfod, pfde, &cookie);
1674 ok(hr == S_OK, "Got 0x%08x\n", hr);
1675
1676 hr = IFileDialog_Show(pfod, NULL);
1677 ok(hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "Got 0x%08x\n", hr);
1678
1679 hr = IFileDialog_Unadvise(pfod, cookie);
1680 ok(hr == S_OK, "Got 0x%08x\n", hr);
1681
1682 IFileDialogEvents_Release(pfde);
1683 IFileDialogCustomize_Release(pfdc);
1684 ref = IFileDialog_Release(pfod);
1685 ok(!ref, "Refcount not zero (%d).\n", ref);
1686
1687
1688 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
1689 &IID_IFileDialog, (void**)&pfod);
1690 ok(hr == S_OK, "got 0x%08x.\n", hr);
1691
1692 hr = IFileDialog_QueryInterface(pfod, &IID_IFileDialogCustomize, (void**)&pfdc);
1693 ok(hr == S_OK, "got 0x%08x.\n", hr);
1694
1695 i = 0;
1696 hr = IFileDialogCustomize_AddMenu(pfdc, ++i, label);
1697 ok(hr == S_OK, "got 0x%08x.\n", hr);
1698 if(SUCCEEDED(hr))
1699 {
1700 DWORD selected;
1701 UINT j = 0;
1702
1703 for(j = 0; j < 10; j++)
1704 {
1705 hr = IFileDialogCustomize_AddControlItem(pfdc, i, j, label);
1706 ok(hr == S_OK, "got 0x%08x.\n", hr);
1707 }
1708
1709 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
1710 ok(hr == E_NOTIMPL, "got 0x%08x.\n", hr);
1711
1712 cdstate = 0xdeadbeef;
1713 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1714 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1715 todo_wine ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1716 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, 0);
1717 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1718 cdstate = 0xdeadbeef;
1719 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1720 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1721 todo_wine ok(cdstate == 0, "got 0x%08x.\n", cdstate);
1722 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, CDCS_ENABLEDVISIBLE);
1723 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1724 cdstate = 0xdeadbeef;
1725 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1726 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1727 todo_wine ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1728
1729 hr = IFileDialogCustomize_RemoveAllControlItems(pfdc, i);
1730 ok(hr == E_NOTIMPL, "got 0x%08x.\n", hr);
1731
1732 for(j = 0; j < 10; j++)
1733 {
1734 hr = IFileDialogCustomize_RemoveControlItem(pfdc, i, j);
1735 ok(hr == S_OK, "got 0x%08x.\n", hr);
1736 }
1737 }
1738 hr = IFileDialogCustomize_AddPushButton(pfdc, ++i, label);
1739 ok(hr == S_OK, "got 0x%08x.\n", hr);
1740 hr = IFileDialogCustomize_AddComboBox(pfdc, ++i);
1741 ok(hr == S_OK, "got 0x%08x.\n", hr);
1742 if(SUCCEEDED(hr))
1743 {
1744 DWORD selected = -1;
1745 UINT j = 0;
1746
1747 for(j = 0; j < 10; j++)
1748 {
1749 hr = IFileDialogCustomize_AddControlItem(pfdc, i, j, label);
1750 ok(hr == S_OK, "got 0x%08x.\n", hr);
1751 }
1752
1753 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
1754 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
1755 ok(selected == -1, "got %d.\n", selected);
1756
1757 todo_wine {
1758 cdstate = 0xdeadbeef;
1759 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1760 ok(hr == S_OK, "got 0x%08x.\n", hr);
1761 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1762 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, 0);
1763 ok(hr == S_OK, "got 0x%08x.\n", hr);
1764 cdstate = 0xdeadbeef;
1765 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1766 ok(hr == S_OK, "got 0x%08x.\n", hr);
1767 ok(cdstate == 0, "got 0x%08x.\n", cdstate);
1768 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, CDCS_ENABLEDVISIBLE);
1769 ok(hr == S_OK, "got 0x%08x.\n", hr);
1770 cdstate = 0xdeadbeef;
1771 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1772 ok(hr == S_OK, "got 0x%08x.\n", hr);
1773 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1774 }
1775
1776 for(j = 0; j < 10; j++)
1777 {
1778 hr = IFileDialogCustomize_SetSelectedControlItem(pfdc, i, j);
1779 ok(hr == S_OK, "got 0x%08x.\n", hr);
1780 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
1781 ok(hr == S_OK, "got 0x%08x.\n", hr);
1782 ok(selected == j, "got %d.\n", selected);
1783 }
1784 j++;
1785 hr = IFileDialogCustomize_SetSelectedControlItem(pfdc, i, j);
1786 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
1787
1788 hr = IFileDialogCustomize_RemoveAllControlItems(pfdc, i);
1789 ok(hr == E_NOTIMPL, "got 0x%08x.\n", hr);
1790
1791 for(j = 0; j < 10; j++)
1792 {
1793 hr = IFileDialogCustomize_RemoveControlItem(pfdc, i, j);
1794 ok(hr == S_OK, "got 0x%08x.\n", hr);
1795 }
1796 }
1797
1798 hr = IFileDialogCustomize_AddRadioButtonList(pfdc, ++i);
1799 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1800 if(SUCCEEDED(hr))
1801 {
1802 DWORD selected = -1;
1803 UINT j = 0;
1804
1805 for(j = 0; j < 10; j++)
1806 {
1807 hr = IFileDialogCustomize_AddControlItem(pfdc, i, j, label);
1808 ok(hr == S_OK, "got 0x%08x.\n", hr);
1809 }
1810
1811 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
1812 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
1813 ok(selected == -1, "got %d.\n", selected);
1814
1815 todo_wine {
1816 cdstate = 0xdeadbeef;
1817 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1818 ok(hr == S_OK, "got 0x%08x.\n", hr);
1819 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1820 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, 0);
1821 ok(hr == S_OK, "got 0x%08x.\n", hr);
1822 cdstate = 0xdeadbeef;
1823 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1824 ok(hr == S_OK, "got 0x%08x.\n", hr);
1825 ok(cdstate == 0, "got 0x%08x.\n", cdstate);
1826 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, CDCS_ENABLEDVISIBLE);
1827 ok(hr == S_OK, "got 0x%08x.\n", hr);
1828 cdstate = 0xdeadbeef;
1829 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1830 ok(hr == S_OK, "got 0x%08x.\n", hr);
1831 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1832 }
1833
1834 for(j = 0; j < 10; j++)
1835 {
1836 hr = IFileDialogCustomize_SetSelectedControlItem(pfdc, i, j);
1837 ok(hr == S_OK, "got 0x%08x.\n", hr);
1838 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
1839 ok(hr == S_OK, "got 0x%08x.\n", hr);
1840 ok(selected == j, "got %d.\n", selected);
1841 }
1842 j++;
1843 hr = IFileDialogCustomize_SetSelectedControlItem(pfdc, i, j);
1844 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
1845
1846 hr = IFileDialogCustomize_RemoveAllControlItems(pfdc, i);
1847 ok(hr == E_NOTIMPL, "got 0x%08x.\n", hr);
1848
1849 for(j = 0; j < 10; j++)
1850 {
1851 hr = IFileDialogCustomize_RemoveControlItem(pfdc, i, j);
1852 ok(hr == S_OK, "got 0x%08x.\n", hr);
1853 }
1854 }
1855 hr = IFileDialogCustomize_EnableOpenDropDown(pfdc, ++i);
1856 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1857 if(SUCCEEDED(hr))
1858 {
1859 DWORD selected = -1;
1860 UINT j = 0;
1861
1862 for(j = 0; j < 10; j++)
1863 {
1864 hr = IFileDialogCustomize_AddControlItem(pfdc, i, j, label);
1865 ok(hr == S_OK, "got 0x%08x.\n", hr);
1866 }
1867
1868 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
1869 ok(hr == S_OK, "got 0x%08x.\n", hr);
1870 ok(selected == 0, "got %d.\n", selected);
1871
1872 cdstate = 0xdeadbeef;
1873 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1874 ok(hr == S_OK, "got 0x%08x.\n", hr);
1875 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1876 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, 0);
1877 ok(hr == S_OK, "got 0x%08x.\n", hr);
1878 cdstate = 0xdeadbeef;
1879 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1880 ok(hr == S_OK, "got 0x%08x.\n", hr);
1881 ok(cdstate == 0, "got 0x%08x.\n", cdstate);
1882 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, CDCS_ENABLEDVISIBLE);
1883 ok(hr == S_OK, "got 0x%08x.\n", hr);
1884 cdstate = 0xdeadbeef;
1885 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1886 ok(hr == S_OK, "got 0x%08x.\n", hr);
1887 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1888 hr = IFileDialogCustomize_SetSelectedControlItem(pfdc, i, 0);
1889 ok(hr == E_NOTIMPL, "got 0x%08x.\n", hr);
1890
1891 hr = IFileDialogCustomize_RemoveAllControlItems(pfdc, i);
1892 ok(hr == E_NOTIMPL, "got 0x%08x.\n", hr);
1893
1894 for(j = 0; j < 10; j++)
1895 {
1896 hr = IFileDialogCustomize_RemoveControlItem(pfdc, i, j);
1897 ok(hr == S_OK, "got 0x%08x.\n", hr);
1898 }
1899 }
1900
1901 IFileDialogCustomize_Release(pfdc);
1902 ref = IFileDialog_Release(pfod);
1903 ok(!ref, "Refcount not zero (%d).\n", ref);
1904 }
1905
1906 static void test_persistent_state(void)
1907 {
1908 IFileDialog *fd;
1909 HRESULT hr;
1910
1911 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
1912 &IID_IFileDialog, (void**)&fd);
1913 ok(hr == S_OK, "got 0x%08x.\n", hr);
1914
1915 if (0)
1916 {
1917 /* crashes at least on Win8 */
1918 hr = IFileDialog_SetClientGuid(fd, NULL);
1919 }
1920
1921 hr = IFileDialog_SetClientGuid(fd, &IID_IUnknown);
1922 ok(hr == S_OK, "got 0x%08x\n", hr);
1923
1924 hr = IFileDialog_SetClientGuid(fd, &IID_NULL);
1925 ok(hr == S_OK, "got 0x%08x\n", hr);
1926
1927 IFileDialog_Release(fd);
1928 }
1929
1930 START_TEST(itemdlg)
1931 {
1932 OleInitialize(NULL);
1933 init_function_pointers();
1934
1935 if(test_instantiation())
1936 {
1937 test_basics();
1938 test_advise();
1939 test_filename();
1940 test_customize();
1941 test_persistent_state();
1942 }
1943 else
1944 skip("Skipping all Item Dialog tests.\n");
1945
1946 OleUninitialize();
1947 }