2 * Unit tests for the Common Item Dialog
4 * Copyright 2010,2011 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
26 #include "wine/test.h"
28 static HRESULT (WINAPI *pSHCreateShellItem)(LPCITEMIDLIST,IShellFolder*,LPCITEMIDLIST,IShellItem**);
29 static HRESULT (WINAPI *pSHGetIDListFromObject)(IUnknown*, PIDLIST_ABSOLUTE*);
30 static HRESULT (WINAPI *pSHCreateItemFromParsingName)(PCWSTR,IBindCtx*,REFIID,void**);
32 static void init_function_pointers(void)
34 HMODULE hmod = GetModuleHandleA("shell32.dll");
36 #define MAKEFUNC(f) (p##f = (void*)GetProcAddress(hmod, #f))
37 MAKEFUNC(SHCreateShellItem);
38 MAKEFUNC(SHGetIDListFromObject);
39 MAKEFUNC(SHCreateItemFromParsingName);
44 DEFINE_GUID(IID_IFileDialogCustomizeAlt, 0x8016B7B3, 0x3D49, 0x4504, 0xA0,0xAA, 0x2A,0x37,0x49,0x4E,0x60,0x6F);
46 /**************************************************************************
47 * IFileDialogEvents implementation
50 IFileDialogEvents IFileDialogEvents_iface;
53 LONG OnFileOk, OnFolderChanging, OnFolderChange;
54 LONG OnSelectionChange, OnShareViolation, OnTypeChange;
57 BOOL set_filename_tried;
59 } IFileDialogEventsImpl;
61 static inline IFileDialogEventsImpl *impl_from_IFileDialogEvents(IFileDialogEvents *iface)
63 return CONTAINING_RECORD(iface, IFileDialogEventsImpl, IFileDialogEvents_iface);
66 static HRESULT WINAPI IFileDialogEvents_fnQueryInterface(IFileDialogEvents *iface, REFIID riid, void **ppv)
69 ok(0, "Unexpectedly called.\n");
73 static ULONG WINAPI IFileDialogEvents_fnAddRef(IFileDialogEvents *iface)
75 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
76 return InterlockedIncrement(&This->ref);
79 static ULONG WINAPI IFileDialogEvents_fnRelease(IFileDialogEvents *iface)
81 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
82 LONG ref = InterlockedDecrement(&This->ref);
85 HeapFree(GetProcessHeap(), 0, This);
90 static HRESULT WINAPI IFileDialogEvents_fnOnFileOk(IFileDialogEvents *iface, IFileDialog *pfd)
92 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
97 static HRESULT WINAPI IFileDialogEvents_fnOnFolderChanging(IFileDialogEvents *iface,
99 IShellItem *psiFolder)
101 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
102 This->OnFolderChanging++;
106 static void test_customize_onfolderchange(IFileDialog *pfd);
108 static LRESULT CALLBACK test_customize_dlgproc(HWND hwnd, UINT message, LPARAM lparam, WPARAM wparam)
110 WNDPROC oldwndproc = GetPropA(hwnd, "WT_OLDWC");
112 if(message == WM_USER+0x1234)
114 IFileDialog *pfd = (IFileDialog*)lparam;
115 test_customize_onfolderchange(pfd);
118 return CallWindowProcW(oldwndproc, hwnd, message, lparam, wparam);
121 static HRESULT WINAPI IFileDialogEvents_fnOnFolderChange(IFileDialogEvents *iface, IFileDialog *pfd)
123 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
128 This->OnFolderChange++;
130 if(This->set_filename)
132 hr = IFileDialog_QueryInterface(pfd, &IID_IOleWindow, (void**)&pow);
133 ok(hr == S_OK, "Got 0x%08x\n", hr);
135 hr = IOleWindow_GetWindow(pow, &dlg_hwnd);
136 ok(hr == S_OK, "Got 0x%08x\n", hr);
137 ok(dlg_hwnd != NULL, "Got NULL.\n");
139 IOleWindow_Release(pow);
141 hr = IFileDialog_SetFileName(pfd, This->set_filename);
142 ok(hr == S_OK, "Got 0x%08x\n", hr);
144 if(!This->set_filename_tried)
146 br = PostMessageW(dlg_hwnd, WM_COMMAND, IDOK, 0);
148 This->set_filename_tried = TRUE;
155 hr = IFileDialog_QueryInterface(pfd, &IID_IOleWindow, (void**)&pow);
156 ok(hr == S_OK, "Got 0x%08x\n", hr);
158 hr = IOleWindow_GetWindow(pow, &dlg_hwnd);
159 ok(hr == S_OK, "Got 0x%08x\n", hr);
160 ok(dlg_hwnd != NULL, "Got NULL.\n");
162 IOleWindow_Release(pow);
164 /* On Vista, the custom control area of the dialog is not
165 * fully set up when the first OnFolderChange event is
167 oldwndproc = (WNDPROC)GetWindowLongPtrW(dlg_hwnd, GWLP_WNDPROC);
168 SetPropA(dlg_hwnd, "WT_OLDWC", (HANDLE)oldwndproc);
169 SetWindowLongPtrW(dlg_hwnd, GWLP_WNDPROC, (LPARAM)test_customize_dlgproc);
171 br = PostMessageW(dlg_hwnd, WM_USER+0x1234, (LPARAM)pfd, 0);
178 static HRESULT WINAPI IFileDialogEvents_fnOnSelectionChange(IFileDialogEvents *iface, IFileDialog *pfd)
180 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
181 This->OnSelectionChange++;
185 static HRESULT WINAPI IFileDialogEvents_fnOnShareViolation(IFileDialogEvents *iface,
188 FDE_SHAREVIOLATION_RESPONSE *pResponse)
190 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
191 This->OnShareViolation++;
195 static HRESULT WINAPI IFileDialogEvents_fnOnTypeChange(IFileDialogEvents *iface, IFileDialog *pfd)
197 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
198 This->OnTypeChange++;
202 static HRESULT WINAPI IFileDialogEvents_fnOnOverwrite(IFileDialogEvents *iface,
205 FDE_OVERWRITE_RESPONSE *pResponse)
207 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
212 static const IFileDialogEventsVtbl vt_IFileDialogEvents = {
213 IFileDialogEvents_fnQueryInterface,
214 IFileDialogEvents_fnAddRef,
215 IFileDialogEvents_fnRelease,
216 IFileDialogEvents_fnOnFileOk,
217 IFileDialogEvents_fnOnFolderChanging,
218 IFileDialogEvents_fnOnFolderChange,
219 IFileDialogEvents_fnOnSelectionChange,
220 IFileDialogEvents_fnOnShareViolation,
221 IFileDialogEvents_fnOnTypeChange,
222 IFileDialogEvents_fnOnOverwrite
225 static IFileDialogEvents *IFileDialogEvents_Constructor(void)
227 IFileDialogEventsImpl *This;
229 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IFileDialogEventsImpl));
230 This->IFileDialogEvents_iface.lpVtbl = &vt_IFileDialogEvents;
233 return &This->IFileDialogEvents_iface;
236 static BOOL test_instantiation(void)
239 IFileOpenDialog *pfod;
240 IFileSaveDialog *pfsd;
241 IServiceProvider *psp;
247 /* Instantiate FileOpenDialog */
248 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
249 &IID_IFileOpenDialog, (void**)&pfod);
252 skip("Could not instantiate the FileOpenDialog.\n");
255 ok(hr == S_OK, "got 0x%08x.\n", hr);
257 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialog, (void**)&pfd);
258 ok(hr == S_OK, "got 0x%08x.\n", hr);
259 if(SUCCEEDED(hr)) IFileDialog_Release(pfd);
261 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialogCustomize, (void**)&punk);
262 ok(hr == S_OK, "got 0x%08x.\n", hr);
263 if(SUCCEEDED(hr)) IUnknown_Release(punk);
265 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialogCustomizeAlt, (void**)&punk);
266 ok(hr == S_OK, "got 0x%08x.\n", hr);
267 if(SUCCEEDED(hr)) IUnknown_Release(punk);
269 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileSaveDialog, (void**)&pfsd);
270 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
271 if(SUCCEEDED(hr)) IFileSaveDialog_Release(pfsd);
273 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IServiceProvider, (void**)&psp);
274 ok(hr == S_OK, "got 0x%08x.\n", hr);
277 IExplorerBrowser *peb;
280 hr = IServiceProvider_QueryService(psp, &SID_SExplorerBrowserFrame, &IID_ICommDlgBrowser, (void**)&punk);
281 ok(hr == S_OK, "got 0x%08x.\n", hr);
282 if(SUCCEEDED(hr)) IUnknown_Release(punk);
284 /* since win8, the result is E_NOTIMPL for all other services */
285 hr = IServiceProvider_QueryService(psp, &SID_STopLevelBrowser, &IID_IExplorerBrowser, (void**)&peb);
286 ok(hr == E_NOTIMPL || broken(hr == E_FAIL), "got 0x%08x (expected E_NOTIMPL)\n", hr);
287 if(SUCCEEDED(hr)) IExplorerBrowser_Release(peb);
288 hr = IServiceProvider_QueryService(psp, &SID_STopLevelBrowser, &IID_IShellBrowser, (void**)&psb);
289 ok(hr == E_NOTIMPL || broken(hr == E_FAIL), "got 0x%08x (expected E_NOTIMPL)\n", hr);
290 if(SUCCEEDED(hr)) IShellBrowser_Release(psb);
291 hr = IServiceProvider_QueryService(psp, &SID_STopLevelBrowser, &IID_ICommDlgBrowser, (void**)&punk);
292 ok(hr == E_NOTIMPL || broken(hr == E_FAIL), "got 0x%08x (expected E_NOTIMPL)\n", hr);
293 if(SUCCEEDED(hr)) IUnknown_Release(punk);
295 hr = IServiceProvider_QueryService(psp, &SID_STopLevelBrowser, &IID_IUnknown, (void**)&punk);
296 ok(hr == E_NOTIMPL || broken(hr == E_FAIL), "got 0x%08x (expected E_NOTIMPL)\n", hr);
297 if(SUCCEEDED(hr)) IUnknown_Release(punk);
298 hr = IServiceProvider_QueryService(psp, &IID_IUnknown, &IID_IUnknown, (void**)&punk);
299 ok(hr == E_NOTIMPL || broken(hr == E_FAIL), "got 0x%08x (expected E_NOTIMPL)\n", hr);
300 if(SUCCEEDED(hr)) IUnknown_Release(punk);
302 IServiceProvider_Release(psp);
305 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialogEvents, (void**)&punk);
306 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
307 if(SUCCEEDED(hr)) IUnknown_Release(punk);
309 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IExplorerBrowser, (void**)&punk);
310 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
311 if(SUCCEEDED(hr)) IUnknown_Release(punk);
313 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IExplorerBrowserEvents, (void**)&punk);
314 ok(hr == S_OK, "got 0x%08x.\n", hr);
315 if(SUCCEEDED(hr)) IUnknown_Release(punk);
317 hr = IFileOpenDialog_QueryInterface(pfod, &IID_ICommDlgBrowser3, (void**)&punk);
318 ok(hr == S_OK, "got 0x%08x.\n", hr);
319 if(SUCCEEDED(hr)) IUnknown_Release(punk);
321 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IShellBrowser, (void**)&punk);
322 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
323 if(SUCCEEDED(hr)) IUnknown_Release(punk);
325 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IOleWindow, (void**)&pow);
326 ok(hr == S_OK, "got 0x%08x.\n", hr);
331 hr = IOleWindow_ContextSensitiveHelp(pow, TRUE);
332 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
334 hr = IOleWindow_ContextSensitiveHelp(pow, FALSE);
335 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
339 /* Crashes on win7 */
340 IOleWindow_GetWindow(pow, NULL);
343 hr = IOleWindow_GetWindow(pow, &hwnd);
344 ok(hr == S_OK, "Got 0x%08x\n", hr);
345 ok(hwnd == NULL, "Got %p\n", hwnd);
347 IOleWindow_Release(pow);
350 ref = IFileOpenDialog_Release(pfod);
351 ok(!ref, "Got refcount %d, should have been released.\n", ref);
353 /* Instantiate FileSaveDialog */
354 hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER,
355 &IID_IFileSaveDialog, (void**)&pfsd);
358 skip("Could not instantiate the FileSaveDialog.\n");
361 ok(hr == S_OK, "got 0x%08x.\n", hr);
363 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialog, (void**)&pfd);
364 ok(hr == S_OK, "got 0x%08x.\n", hr);
365 if(SUCCEEDED(hr)) IFileDialog_Release(pfd);
367 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialogCustomize, (void**)&punk);
368 ok(hr == S_OK, "got 0x%08x.\n", hr);
369 if(SUCCEEDED(hr)) IUnknown_Release(punk);
371 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialogCustomizeAlt, (void**)&punk);
372 ok(hr == S_OK, "got 0x%08x.\n", hr);
373 if(SUCCEEDED(hr)) IUnknown_Release(punk);
375 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileOpenDialog, (void**)&pfod);
376 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
377 if(SUCCEEDED(hr)) IFileOpenDialog_Release(pfod);
379 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialogEvents, (void**)&punk);
380 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
381 if(SUCCEEDED(hr)) IFileDialog_Release(pfd);
383 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IExplorerBrowser, (void**)&punk);
384 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
385 if(SUCCEEDED(hr)) IUnknown_Release(punk);
387 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IExplorerBrowserEvents, (void**)&punk);
388 ok(hr == S_OK, "got 0x%08x.\n", hr);
389 if(SUCCEEDED(hr)) IUnknown_Release(punk);
391 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_ICommDlgBrowser3, (void**)&punk);
392 ok(hr == S_OK, "got 0x%08x.\n", hr);
393 if(SUCCEEDED(hr)) IUnknown_Release(punk);
395 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IShellBrowser, (void**)&punk);
396 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
397 if(SUCCEEDED(hr)) IUnknown_Release(punk);
399 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IOleWindow, (void**)&pow);
400 ok(hr == S_OK, "got 0x%08x.\n", hr);
405 hr = IOleWindow_ContextSensitiveHelp(pow, TRUE);
406 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
408 hr = IOleWindow_ContextSensitiveHelp(pow, FALSE);
409 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
413 /* Crashes on win7 */
414 IOleWindow_GetWindow(pow, NULL);
417 hr = IOleWindow_GetWindow(pow, &hwnd);
418 ok(hr == S_OK, "Got 0x%08x\n", hr);
419 ok(hwnd == NULL, "Got %p\n", hwnd);
421 IOleWindow_Release(pow);
425 ref = IFileSaveDialog_Release(pfsd);
426 ok(!ref, "Got refcount %d, should have been released.\n", ref);
430 static void test_basics(void)
432 IFileOpenDialog *pfod;
433 IFileSaveDialog *pfsd;
435 FILEOPENDIALOGOPTIONS fdoptions;
436 IShellFolder *psfdesktop;
437 IShellItem *psi, *psidesktop, *psi_original;
438 IShellItemArray *psia;
445 const WCHAR txt[] = {'t','x','t', 0};
446 const WCHAR null[] = {0};
447 const WCHAR fname1[] = {'f','n','a','m','e','1', 0};
448 const WCHAR fspec1[] = {'*','.','t','x','t',0};
449 const WCHAR fname2[] = {'f','n','a','m','e','2', 0};
450 const WCHAR fspec2[] = {'*','.','e','x','e',0};
451 COMDLG_FILTERSPEC filterspec[2] = {{fname1, fspec1}, {fname2, fspec2}};
453 /* This should work on every platform with IFileDialog */
454 SHGetDesktopFolder(&psfdesktop);
455 hr = pSHGetIDListFromObject((IUnknown*)psfdesktop, &pidl);
458 hr = pSHCreateShellItem(NULL, NULL, pidl, &psidesktop);
461 IShellFolder_Release(psfdesktop);
464 skip("Failed to get ShellItem from DesktopFolder, skipping tests.\n");
469 /* Instantiate FileOpenDialog and FileSaveDialog */
470 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
471 &IID_IFileOpenDialog, (void**)&pfod);
472 ok(hr == S_OK, "got 0x%08x.\n", hr);
473 hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER,
474 &IID_IFileSaveDialog, (void**)&pfsd);
475 ok(hr == S_OK, "got 0x%08x.\n", hr);
477 /* ClearClientData */
480 hr = IFileOpenDialog_ClearClientData(pfod);
481 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
482 hr = IFileSaveDialog_ClearClientData(pfsd);
483 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
487 hr = IFileOpenDialog_GetOptions(pfod, NULL);
488 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
489 hr = IFileSaveDialog_GetOptions(pfsd, NULL);
490 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
492 /* Check default options */
493 hr = IFileOpenDialog_GetOptions(pfod, &fdoptions);
494 ok(hr == S_OK, "got 0x%08x.\n", hr);
495 ok(fdoptions == (FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST | FOS_NOCHANGEDIR),
496 "Unexpected default options: 0x%08x\n", fdoptions);
497 hr = IFileSaveDialog_GetOptions(pfsd, &fdoptions);
498 ok(hr == S_OK, "got 0x%08x.\n", hr);
499 ok(fdoptions == (FOS_OVERWRITEPROMPT | FOS_NOREADONLYRETURN | FOS_PATHMUSTEXIST | FOS_NOCHANGEDIR),
500 "Unexpected default options: 0x%08x\n", fdoptions);
503 hr = IFileOpenDialog_GetResult(pfod, NULL);
504 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
505 hr = IFileSaveDialog_GetResult(pfsd, NULL);
506 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
508 psi = (void*)0xdeadbeef;
509 hr = IFileOpenDialog_GetResult(pfod, &psi);
510 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
511 ok(psi == (void*)0xdeadbeef, "got %p.\n", psi);
512 psi = (void*)0xdeadbeef;
513 hr = IFileSaveDialog_GetResult(pfsd, &psi);
514 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
515 ok(psi == (void*)0xdeadbeef, "got %p.\n", psi);
517 /* GetCurrentSelection */
519 /* Crashes on Vista/W2K8. Tests below passes on Windows 7 */
520 hr = IFileOpenDialog_GetCurrentSelection(pfod, NULL);
521 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
522 hr = IFileSaveDialog_GetCurrentSelection(pfsd, NULL);
523 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
524 hr = IFileOpenDialog_GetCurrentSelection(pfod, &psi);
525 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
526 hr = IFileSaveDialog_GetCurrentSelection(pfsd, &psi);
527 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
531 hr = IFileOpenDialog_GetFileName(pfod, NULL);
532 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
533 filename = (void*)0xdeadbeef;
534 hr = IFileOpenDialog_GetFileName(pfod, &filename);
535 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
536 ok(filename == NULL, "got %p\n", filename);
537 hr = IFileSaveDialog_GetFileName(pfsd, NULL);
538 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
539 filename = (void*)0xdeadbeef;
540 hr = IFileSaveDialog_GetFileName(pfsd, &filename);
541 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
542 ok(filename == NULL, "got %p\n", filename);
544 /* GetFileTypeIndex */
545 hr = IFileOpenDialog_GetFileTypeIndex(pfod, NULL);
546 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
548 hr = IFileOpenDialog_GetFileTypeIndex(pfod, &filetype);
549 ok(hr == S_OK, "got 0x%08x.\n", hr);
550 ok(filetype == 0, "got %d.\n", filetype);
551 hr = IFileSaveDialog_GetFileTypeIndex(pfsd, NULL);
552 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
554 hr = IFileSaveDialog_GetFileTypeIndex(pfsd, &filetype);
555 ok(hr == S_OK, "got 0x%08x.\n", hr);
556 ok(filetype == 0, "got %d.\n", filetype);
558 /* SetFileTypes / SetFileTypeIndex */
559 hr = IFileOpenDialog_SetFileTypes(pfod, 0, NULL);
560 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
561 hr = IFileOpenDialog_SetFileTypes(pfod, 0, filterspec);
562 ok(hr == S_OK, "got 0x%08x.\n", hr);
564 hr = IFileOpenDialog_SetFileTypeIndex(pfod, -1);
565 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
566 hr = IFileOpenDialog_SetFileTypeIndex(pfod, 0);
567 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
568 hr = IFileOpenDialog_SetFileTypeIndex(pfod, 1);
569 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
570 hr = IFileOpenDialog_SetFileTypes(pfod, 1, filterspec);
571 ok(hr == S_OK, "got 0x%08x.\n", hr);
572 hr = IFileOpenDialog_SetFileTypes(pfod, 0, filterspec);
573 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
574 hr = IFileOpenDialog_SetFileTypeIndex(pfod, 0);
575 ok(hr == S_OK, "got 0x%08x.\n", hr);
576 hr = IFileOpenDialog_SetFileTypeIndex(pfod, 100);
577 ok(hr == S_OK, "got 0x%08x.\n", hr);
578 hr = IFileOpenDialog_SetFileTypes(pfod, 1, filterspec);
579 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
580 hr = IFileOpenDialog_SetFileTypes(pfod, 1, &filterspec[1]);
581 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
583 hr = IFileSaveDialog_SetFileTypeIndex(pfsd, -1);
584 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
585 hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 0);
586 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
587 hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 1);
588 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
589 hr = IFileSaveDialog_SetFileTypes(pfsd, 1, filterspec);
590 ok(hr == S_OK, "got 0x%08x.\n", hr);
591 hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 0);
592 ok(hr == S_OK, "got 0x%08x.\n", hr);
593 hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 100);
594 ok(hr == S_OK, "got 0x%08x.\n", hr);
595 hr = IFileSaveDialog_SetFileTypes(pfsd, 1, filterspec);
596 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
597 hr = IFileSaveDialog_SetFileTypes(pfsd, 1, &filterspec[1]);
598 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
603 hr = IFileOpenDialog_SetFilter(pfod, NULL);
604 ok(hr == S_OK, "got 0x%08x.\n", hr);
605 hr = IFileSaveDialog_SetFilter(pfsd, NULL);
606 ok(hr == S_OK, "got 0x%08x.\n", hr);
610 hr = IFileOpenDialog_SetFolder(pfod, NULL);
611 ok(hr == S_OK, "got 0x%08x.\n", hr);
612 hr = IFileSaveDialog_SetFolder(pfsd, NULL);
613 ok(hr == S_OK, "got 0x%08x.\n", hr);
615 /* SetDefaultExtension */
616 hr = IFileOpenDialog_SetDefaultExtension(pfod, NULL);
617 ok(hr == S_OK, "got 0x%08x.\n", hr);
618 hr = IFileOpenDialog_SetDefaultExtension(pfod, txt);
619 ok(hr == S_OK, "got 0x%08x.\n", hr);
620 hr = IFileOpenDialog_SetDefaultExtension(pfod, null);
621 ok(hr == S_OK, "got 0x%08x.\n", hr);
623 hr = IFileSaveDialog_SetDefaultExtension(pfsd, NULL);
624 ok(hr == S_OK, "got 0x%08x.\n", hr);
625 hr = IFileSaveDialog_SetDefaultExtension(pfsd, txt);
626 ok(hr == S_OK, "got 0x%08x.\n", hr);
627 hr = IFileSaveDialog_SetDefaultExtension(pfsd, null);
628 ok(hr == S_OK, "got 0x%08x.\n", hr);
630 /* SetDefaultFolder */
631 hr = IFileOpenDialog_SetDefaultFolder(pfod, NULL);
632 ok(hr == S_OK, "got 0x%08x\n", hr);
633 hr = IFileSaveDialog_SetDefaultFolder(pfsd, NULL);
634 ok(hr == S_OK, "got 0x%08x\n", hr);
636 hr = IFileOpenDialog_SetDefaultFolder(pfod, psidesktop);
637 ok(hr == S_OK, "got 0x%08x\n", hr);
638 hr = IFileSaveDialog_SetDefaultFolder(pfsd, psidesktop);
639 ok(hr == S_OK, "got 0x%08x\n", hr);
643 /* Crashes under Windows 7 */
644 IFileOpenDialog_SetDefaultFolder(pfod, (void*)0x1234);
645 IFileSaveDialog_SetDefaultFolder(pfsd, (void*)0x1234);
648 /* GetFolder / SetFolder */
649 hr = IFileOpenDialog_GetFolder(pfod, NULL);
650 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
652 hr = IFileOpenDialog_GetFolder(pfod, &psi_original);
653 ok(hr == S_OK, "got 0x%08x.\n", hr);
656 hr = IFileOpenDialog_SetFolder(pfod, psidesktop);
657 ok(hr == S_OK, "got 0x%08x.\n", hr);
658 hr = IFileOpenDialog_SetFolder(pfod, psi_original);
659 ok(hr == S_OK, "got 0x%08x.\n", hr);
660 IShellItem_Release(psi_original);
663 hr = IFileSaveDialog_GetFolder(pfsd, &psi_original);
664 ok(hr == S_OK, "got 0x%08x.\n", hr);
667 hr = IFileSaveDialog_SetFolder(pfsd, psidesktop);
668 ok(hr == S_OK, "got 0x%08x.\n", hr);
669 hr = IFileSaveDialog_SetFolder(pfsd, psi_original);
670 ok(hr == S_OK, "got 0x%08x.\n", hr);
671 IShellItem_Release(psi_original);
677 /* Crashes under Windows 7 */
678 IFileOpenDialog_AddPlace(pfod, NULL, 0);
679 IFileSaveDialog_AddPlace(pfsd, NULL, 0);
684 hr = IFileOpenDialog_AddPlace(pfod, psidesktop, FDAP_TOP + 1);
685 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
686 hr = IFileOpenDialog_AddPlace(pfod, psidesktop, FDAP_BOTTOM);
687 ok(hr == S_OK, "got 0x%08x\n", hr);
688 hr = IFileOpenDialog_AddPlace(pfod, psidesktop, FDAP_TOP);
689 ok(hr == S_OK, "got 0x%08x\n", hr);
691 hr = IFileSaveDialog_AddPlace(pfsd, psidesktop, FDAP_TOP + 1);
692 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
693 hr = IFileSaveDialog_AddPlace(pfsd, psidesktop, FDAP_BOTTOM);
694 ok(hr == S_OK, "got 0x%08x\n", hr);
695 hr = IFileSaveDialog_AddPlace(pfsd, psidesktop, FDAP_TOP);
696 ok(hr == S_OK, "got 0x%08x\n", hr);
700 hr = IFileOpenDialog_SetFileName(pfod, NULL);
701 ok(hr == S_OK, "got 0x%08x\n", hr);
702 hr = IFileOpenDialog_SetFileName(pfod, null);
703 ok(hr == S_OK, "got 0x%08x\n", hr);
704 hr = IFileOpenDialog_SetFileName(pfod, txt);
705 ok(hr == S_OK, "got 0x%08x\n", hr);
706 hr = IFileOpenDialog_GetFileName(pfod, &filename);
707 ok(hr == S_OK, "Got 0x%08x\n", hr);
708 ok(!lstrcmpW(filename, txt), "Strings do not match.\n");
709 CoTaskMemFree(filename);
711 hr = IFileSaveDialog_SetFileName(pfsd, NULL);
712 ok(hr == S_OK, "got 0x%08x\n", hr);
713 hr = IFileSaveDialog_SetFileName(pfsd, null);
714 ok(hr == S_OK, "got 0x%08x\n", hr);
715 hr = IFileSaveDialog_SetFileName(pfsd, txt);
716 ok(hr == S_OK, "got 0x%08x\n", hr);
717 hr = IFileSaveDialog_GetFileName(pfsd, &filename);
718 ok(hr == S_OK, "Got 0x%08x\n", hr);
719 ok(!lstrcmpW(filename, txt), "Strings do not match.\n");
720 CoTaskMemFree(filename);
722 /* SetFileNameLabel */
723 hr = IFileOpenDialog_SetFileNameLabel(pfod, NULL);
724 ok(hr == S_OK, "got 0x%08x\n", hr);
725 hr = IFileOpenDialog_SetFileNameLabel(pfod, null);
726 ok(hr == S_OK, "got 0x%08x\n", hr);
727 hr = IFileOpenDialog_SetFileNameLabel(pfod, txt);
728 ok(hr == S_OK, "got 0x%08x\n", hr);
730 hr = IFileSaveDialog_SetFileNameLabel(pfsd, NULL);
731 ok(hr == S_OK, "got 0x%08x\n", hr);
732 hr = IFileSaveDialog_SetFileNameLabel(pfsd, null);
733 ok(hr == S_OK, "got 0x%08x\n", hr);
734 hr = IFileSaveDialog_SetFileNameLabel(pfsd, txt);
735 ok(hr == S_OK, "got 0x%08x\n", hr);
738 hr = IFileOpenDialog_Close(pfod, S_FALSE);
739 ok(hr == S_OK, "got 0x%08x\n", hr);
740 hr = IFileSaveDialog_Close(pfsd, S_FALSE);
741 ok(hr == S_OK, "got 0x%08x\n", hr);
743 /* SetOkButtonLabel */
744 hr = IFileOpenDialog_SetOkButtonLabel(pfod, NULL);
745 ok(hr == S_OK, "got 0x%08x\n", hr);
746 hr = IFileOpenDialog_SetOkButtonLabel(pfod, null);
747 ok(hr == S_OK, "got 0x%08x\n", hr);
748 hr = IFileOpenDialog_SetOkButtonLabel(pfod, txt);
749 ok(hr == S_OK, "got 0x%08x\n", hr);
750 hr = IFileSaveDialog_SetOkButtonLabel(pfsd, NULL);
751 ok(hr == S_OK, "got 0x%08x\n", hr);
752 hr = IFileSaveDialog_SetOkButtonLabel(pfsd, null);
753 ok(hr == S_OK, "got 0x%08x\n", hr);
754 hr = IFileSaveDialog_SetOkButtonLabel(pfsd, txt);
755 ok(hr == S_OK, "got 0x%08x\n", hr);
758 hr = IFileOpenDialog_SetTitle(pfod, NULL);
759 ok(hr == S_OK, "got 0x%08x\n", hr);
760 hr = IFileOpenDialog_SetTitle(pfod, null);
761 ok(hr == S_OK, "got 0x%08x\n", hr);
762 hr = IFileOpenDialog_SetTitle(pfod, txt);
763 ok(hr == S_OK, "got 0x%08x\n", hr);
764 hr = IFileSaveDialog_SetTitle(pfsd, NULL);
765 ok(hr == S_OK, "got 0x%08x\n", hr);
766 hr = IFileSaveDialog_SetTitle(pfsd, null);
767 ok(hr == S_OK, "got 0x%08x\n", hr);
768 hr = IFileSaveDialog_SetTitle(pfsd, txt);
769 ok(hr == S_OK, "got 0x%08x\n", hr);
771 /** IFileOpenDialog specific **/
776 /* Crashes under Windows 7 */
777 IFileOpenDialog_GetResults(pfod, NULL);
779 psia = (void*)0xdeadbeef;
780 hr = IFileOpenDialog_GetResults(pfod, &psia);
781 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
782 ok(psia == NULL, "got %p.\n", psia);
784 /* GetSelectedItems */
787 /* Crashes under W2K8 */
788 hr = IFileOpenDialog_GetSelectedItems(pfod, NULL);
789 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
790 psia = (void*)0xdeadbeef;
791 hr = IFileOpenDialog_GetSelectedItems(pfod, &psia);
792 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
793 ok(psia == (void*)0xdeadbeef, "got %p.\n", psia);
796 /** IFileSaveDialog specific **/
798 /* ApplyProperties */
801 /* Crashes under windows 7 */
802 IFileSaveDialog_ApplyProperties(pfsd, NULL, NULL, NULL, NULL);
803 IFileSaveDialog_ApplyProperties(pfsd, psidesktop, NULL, NULL, NULL);
807 hr = IFileSaveDialog_GetProperties(pfsd, NULL);
808 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
809 pps = (void*)0xdeadbeef;
810 hr = IFileSaveDialog_GetProperties(pfsd, &pps);
811 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
812 ok(pps == (void*)0xdeadbeef, "got %p\n", pps);
817 /* Crashes under W2K8 */
818 hr = IFileSaveDialog_SetProperties(pfsd, NULL);
819 ok(hr == S_OK, "got 0x%08x\n", hr);
822 /* SetCollectedProperties */
825 hr = IFileSaveDialog_SetCollectedProperties(pfsd, NULL, TRUE);
826 ok(hr == S_OK, "got 0x%08x\n", hr);
827 hr = IFileSaveDialog_SetCollectedProperties(pfsd, NULL, FALSE);
828 ok(hr == S_OK, "got 0x%08x\n", hr);
834 hr = IFileSaveDialog_SetSaveAsItem(pfsd, NULL);
835 ok(hr == S_OK, "got 0x%08x\n", hr);
836 hr = IFileSaveDialog_SetSaveAsItem(pfsd, psidesktop);
837 ok(hr == MK_E_NOOBJECT, "got 0x%08x\n", hr);
842 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialog2, (void**)&pfd2);
843 ok((hr == S_OK) || broken(hr == E_NOINTERFACE), "got 0x%08x\n", hr);
846 /* SetCancelButtonLabel */
847 hr = IFileDialog2_SetOkButtonLabel(pfd2, NULL);
848 ok(hr == S_OK, "got 0x%08x\n", hr);
849 hr = IFileDialog2_SetOkButtonLabel(pfd2, null);
850 ok(hr == S_OK, "got 0x%08x\n", hr);
851 hr = IFileDialog2_SetOkButtonLabel(pfd2, txt);
852 ok(hr == S_OK, "got 0x%08x\n", hr);
854 /* SetNavigationRoot */
857 hr = IFileDialog2_SetNavigationRoot(pfd2, NULL);
858 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
859 hr = IFileDialog2_SetNavigationRoot(pfd2, psidesktop);
860 ok(hr == S_OK, "got 0x%08x\n", hr);
863 IFileDialog2_Release(pfd2);
866 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialog2, (void**)&pfd2);
867 ok((hr == S_OK) || broken(hr == E_NOINTERFACE), "got 0x%08x\n", hr);
870 /* SetCancelButtonLabel */
871 hr = IFileDialog2_SetOkButtonLabel(pfd2, NULL);
872 ok(hr == S_OK, "got 0x%08x\n", hr);
873 hr = IFileDialog2_SetOkButtonLabel(pfd2, null);
874 ok(hr == S_OK, "got 0x%08x\n", hr);
875 hr = IFileDialog2_SetOkButtonLabel(pfd2, txt);
876 ok(hr == S_OK, "got 0x%08x\n", hr);
878 /* SetNavigationRoot */
881 hr = IFileDialog2_SetNavigationRoot(pfd2, NULL);
882 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
883 hr = IFileDialog2_SetNavigationRoot(pfd2, psidesktop);
884 ok(hr == S_OK, "got 0x%08x\n", hr);
887 IFileDialog2_Release(pfd2);
891 IShellItem_Release(psidesktop);
892 ref = IFileOpenDialog_Release(pfod);
893 ok(!ref, "Got refcount %d, should have been released.\n", ref);
894 ref = IFileSaveDialog_Release(pfsd);
895 ok(!ref, "Got refcount %d, should have been released.\n", ref);
898 static void ensure_zero_events_(const char *file, int line, IFileDialogEventsImpl *impl)
900 ok_(file, line)(!impl->OnFileOk, "OnFileOk: %d\n", impl->OnFileOk);
901 ok_(file, line)(!impl->OnFolderChanging, "OnFolderChanging: %d\n", impl->OnFolderChanging);
902 ok_(file, line)(!impl->OnFolderChange, "OnFolderChange: %d\n", impl->OnFolderChange);
903 ok_(file, line)(!impl->OnSelectionChange, "OnSelectionChange: %d\n", impl->OnSelectionChange);
904 ok_(file, line)(!impl->OnShareViolation, "OnShareViolation: %d\n", impl->OnShareViolation);
905 ok_(file, line)(!impl->OnTypeChange, "OnTypeChange: %d\n", impl->OnTypeChange);
906 ok_(file, line)(!impl->OnOverwrite, "OnOverwrite: %d\n", impl->OnOverwrite);
907 impl->OnFileOk = impl->OnFolderChanging = impl->OnFolderChange = 0;
908 impl->OnSelectionChange = impl->OnShareViolation = impl->OnTypeChange = 0;
909 impl->OnOverwrite = 0;
911 #define ensure_zero_events(impl) ensure_zero_events_(__FILE__, __LINE__, impl)
913 static void test_advise_helper(IFileDialog *pfd)
915 IFileDialogEventsImpl *pfdeimpl;
916 IFileDialogEvents *pfde;
921 pfde = IFileDialogEvents_Constructor();
922 pfdeimpl = impl_from_IFileDialogEvents(pfde);
924 hr = IFileDialog_Advise(pfd, NULL, NULL);
925 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
926 hr = IFileDialog_Advise(pfd, pfde, NULL);
927 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
928 hr = IFileDialog_Advise(pfd, NULL, &cookie[0]);
929 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
930 ok(pfdeimpl->ref == 1, "got ref %d\n", pfdeimpl->ref);
931 ensure_zero_events(pfdeimpl);
933 hr = IFileDialog_Unadvise(pfd, 0);
934 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
935 for(i = 0; i < 10; i++) {
936 hr = IFileDialog_Advise(pfd, pfde, &cookie[i]);
937 ok(hr == S_OK, "got 0x%08x\n", hr);
938 ok(cookie[i] == i+1, "Got cookie: %d\n", cookie[i]);
940 ok(pfdeimpl->ref == 10+1, "got ref %d\n", pfdeimpl->ref);
941 ensure_zero_events(pfdeimpl);
943 for(i = 3; i < 7; i++) {
944 hr = IFileDialog_Unadvise(pfd, cookie[i]);
945 ok(hr == S_OK, "got 0x%08x\n", hr);
947 ok(pfdeimpl->ref == 6+1, "got ref %d\n", pfdeimpl->ref);
948 ensure_zero_events(pfdeimpl);
950 for(i = 0; i < 3; i++) {
951 hr = IFileDialog_Unadvise(pfd, cookie[i]);
952 ok(hr == S_OK, "got 0x%08x\n", hr);
954 ok(pfdeimpl->ref == 3+1, "got ref %d\n", pfdeimpl->ref);
955 ensure_zero_events(pfdeimpl);
957 for(i = 7; i < 10; i++) {
958 hr = IFileDialog_Unadvise(pfd, cookie[i]);
959 ok(hr == S_OK, "got 0x%08x\n", hr);
961 ok(pfdeimpl->ref == 1, "got ref %d\n", pfdeimpl->ref);
962 ensure_zero_events(pfdeimpl);
964 hr = IFileDialog_Unadvise(pfd, cookie[9]+1);
965 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
966 ok(pfdeimpl->ref == 1, "got ref %d\n", pfdeimpl->ref);
967 ensure_zero_events(pfdeimpl);
969 hr = IFileDialog_Advise(pfd, pfde, &cookie[0]);
970 ok(hr == S_OK, "got 0x%08x\n", hr);
971 todo_wine ok(cookie[0] == 1, "got cookie: %d\n", cookie[0]);
972 ok(pfdeimpl->ref == 1+1, "got ref %d\n", pfdeimpl->ref);
973 ensure_zero_events(pfdeimpl);
975 hr = IFileDialog_Unadvise(pfd, cookie[0]);
979 /* Unadvising already unadvised cookies crashes on
981 IFileDialog_Unadvise(pfd, cookie[0]);
985 IFileDialogEvents_Release(pfde);
988 static void test_advise(void)
994 trace("Testing FileOpenDialog (advise)\n");
995 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
996 &IID_IFileDialog, (void**)&pfd);
997 ok(hr == S_OK, "got 0x%08x.\n", hr);
998 test_advise_helper(pfd);
999 ref = IFileDialog_Release(pfd);
1000 ok(!ref, "Got refcount %d, should have been released.\n", ref);
1002 trace("Testing FileSaveDialog (advise)\n");
1003 hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER,
1004 &IID_IFileDialog, (void**)&pfd);
1005 ok(hr == S_OK, "got 0x%08x.\n", hr);
1006 test_advise_helper(pfd);
1007 ref = IFileDialog_Release(pfd);
1008 ok(!ref, "Got refcount %d, should have been released.\n", ref);
1011 static void touch_file(LPCWSTR filename)
1014 file = CreateFileW(filename, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
1015 ok(file != INVALID_HANDLE_VALUE, "Failed to create file.\n");
1019 static void test_filename_savedlg_(LPCWSTR set_filename, LPCWSTR defext,
1020 const COMDLG_FILTERSPEC *filterspec, UINT fs_count,
1021 LPCWSTR exp_filename, const char *file, int line)
1023 IFileSaveDialog *pfsd;
1024 IFileDialogEventsImpl *pfdeimpl;
1025 IFileDialogEvents *pfde;
1032 hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER,
1033 &IID_IFileSaveDialog, (void**)&pfsd);
1034 ok_(file,line)(hr == S_OK, "Got 0x%08x\n", hr);
1038 hr = IFileSaveDialog_SetFileTypes(pfsd, fs_count, filterspec);
1039 ok_(file,line)(hr == S_OK, "SetFileTypes failed: Got 0x%08x\n", hr);
1044 hr = IFileSaveDialog_SetDefaultExtension(pfsd, defext);
1045 ok_(file,line)(hr == S_OK, "SetDefaultExtensions failed: Got 0x%08x\n", hr);
1048 pfde = IFileDialogEvents_Constructor();
1049 pfdeimpl = impl_from_IFileDialogEvents(pfde);
1050 pfdeimpl->set_filename = set_filename;
1051 hr = IFileSaveDialog_Advise(pfsd, pfde, &cookie);
1052 ok_(file,line)(hr == S_OK, "Advise failed: Got 0x%08x\n", hr);
1054 hr = IFileSaveDialog_Show(pfsd, NULL);
1055 ok_(file,line)(hr == S_OK, "Show failed: Got 0x%08x\n", hr);
1057 hr = IFileSaveDialog_GetFileName(pfsd, &filename);
1058 ok_(file,line)(hr == S_OK, "GetFileName failed: Got 0x%08x\n", hr);
1059 ok_(file,line)(!lstrcmpW(filename, set_filename), "Got %s\n", wine_dbgstr_w(filename));
1060 CoTaskMemFree(filename);
1062 hr = IFileSaveDialog_GetResult(pfsd, &psi);
1063 ok_(file,line)(hr == S_OK, "GetResult failed: Got 0x%08x\n", hr);
1065 hr = IShellItem_GetDisplayName(psi, SIGDN_PARENTRELATIVEPARSING, &filename);
1066 ok_(file,line)(hr == S_OK, "GetDisplayName failed: Got 0x%08x\n", hr);
1067 ok_(file,line)(!lstrcmpW(filename, exp_filename), "(GetDisplayName) Got %s\n", wine_dbgstr_w(filename));
1068 CoTaskMemFree(filename);
1069 IShellItem_Release(psi);
1071 hr = IFileSaveDialog_Unadvise(pfsd, cookie);
1072 ok_(file,line)(hr == S_OK, "Unadvise failed: Got 0x%08x\n", hr);
1074 ref = IFileSaveDialog_Release(pfsd);
1075 ok_(file,line)(!ref, "Got refcount %d, should have been released.\n", ref);
1077 IFileDialogEvents_Release(pfde);
1079 #define test_filename_savedlg(set_filename, defext, filterspec, fs_count, exp_filename) \
1080 test_filename_savedlg_(set_filename, defext, filterspec, fs_count, exp_filename, __FILE__, __LINE__)
1082 static void test_filename_opendlg_(LPCWSTR set_filename, IShellItem *psi_current, LPCWSTR defext,
1083 const COMDLG_FILTERSPEC *filterspec, UINT fs_count,
1084 LPCWSTR exp_filename, const char *file, int line)
1086 IFileOpenDialog *pfod;
1087 IFileDialogEventsImpl *pfdeimpl;
1088 IFileDialogEvents *pfde;
1091 IShellItemArray *psia;
1096 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
1097 &IID_IFileOpenDialog, (void**)&pfod);
1098 ok_(file,line)(hr == S_OK, "CoCreateInstance failed: Got 0x%08x\n", hr);
1102 hr = IFileOpenDialog_SetDefaultExtension(pfod, defext);
1103 ok_(file,line)(hr == S_OK, "SetDefaultExtensions failed: Got 0x%08x\n", hr);
1108 hr = IFileOpenDialog_SetFileTypes(pfod, 2, filterspec);
1109 ok_(file,line)(hr == S_OK, "SetFileTypes failed: Got 0x%08x\n", hr);
1112 hr = IFileOpenDialog_SetFolder(pfod, psi_current);
1113 ok_(file,line)(hr == S_OK, "SetFolder failed: Got 0x%08x\n", hr);
1115 pfde = IFileDialogEvents_Constructor();
1116 pfdeimpl = impl_from_IFileDialogEvents(pfde);
1117 pfdeimpl->set_filename = set_filename;
1118 pfdeimpl->set_filename_tried = FALSE;
1119 hr = IFileOpenDialog_Advise(pfod, pfde, &cookie);
1120 ok_(file,line)(hr == S_OK, "Advise failed: Got 0x%08x\n", hr);
1122 hr = IFileOpenDialog_Show(pfod, NULL);
1123 ok_(file,line)(hr == S_OK || (!exp_filename && hr == HRESULT_FROM_WIN32(ERROR_CANCELLED)),
1124 "Show failed: Got 0x%08x\n", hr);
1127 hr = IFileOpenDialog_GetResult(pfod, &psi);
1128 ok_(file,line)(hr == S_OK, "GetResult failed: Got 0x%08x\n", hr);
1130 hr = IShellItem_GetDisplayName(psi, SIGDN_PARENTRELATIVEPARSING, &filename);
1131 ok_(file,line)(hr == S_OK, "GetDisplayName(Result) failed: Got 0x%08x\n", hr);
1132 ok_(file,line)(!lstrcmpW(filename, exp_filename), "(GetResult) Got %s\n", wine_dbgstr_w(filename));
1133 CoTaskMemFree(filename);
1134 IShellItem_Release(psi);
1136 hr = IFileOpenDialog_GetResults(pfod, &psia);
1137 ok_(file,line)(hr == S_OK, "GetResults failed: Got 0x%08x\n", hr);
1138 hr = IShellItemArray_GetItemAt(psia, 0, &psi);
1139 ok_(file,line)(hr == S_OK, "GetItemAt failed: Got 0x%08x\n", hr);
1141 hr = IShellItem_GetDisplayName(psi, SIGDN_PARENTRELATIVEPARSING, &filename);
1142 ok_(file,line)(hr == S_OK, "GetDisplayName(Results) failed: Got 0x%08x\n", hr);
1143 ok_(file,line)(!lstrcmpW(filename, exp_filename), "(GetResults) Got %s\n", wine_dbgstr_w(filename));
1144 CoTaskMemFree(filename);
1146 IShellItem_Release(psi);
1147 IShellItemArray_Release(psia);
1151 hr = IFileOpenDialog_GetResult(pfod, &psi);
1152 ok_(file,line)(hr == E_UNEXPECTED, "GetResult: Got 0x%08x\n", hr);
1154 hr = IFileOpenDialog_GetResults(pfod, &psia);
1155 ok_(file,line)(hr == E_FAIL, "GetResults: Got 0x%08x\n", hr);
1158 hr = IFileOpenDialog_GetFileName(pfod, &filename);
1159 ok_(file,line)(hr == S_OK, "GetFileName failed: Got 0x%08x\n", hr);
1160 ok_(file,line)(!lstrcmpW(filename, set_filename), "(GetFileName) Got %s\n", wine_dbgstr_w(filename));
1161 CoTaskMemFree(filename);
1164 hr = IFileOpenDialog_Unadvise(pfod, cookie);
1165 ok_(file,line)(hr == S_OK, "Unadvise failed: Got 0x%08x\n", hr);
1167 ref = IFileOpenDialog_Release(pfod);
1168 ok_(file,line)(!ref, "Got refcount %d, should have been released.\n", ref);
1170 IFileDialogEvents_Release(pfde);
1172 #define test_filename_opendlg(set_filename, psi, defext, filterspec, fs_count, exp_filename) \
1173 test_filename_opendlg_(set_filename, psi, defext, filterspec, fs_count, exp_filename, __FILE__, __LINE__)
1175 static void test_filename(void)
1177 IShellItem *psi_current;
1179 WCHAR buf[MAX_PATH];
1181 static const WCHAR filename_noextW[] = {'w','i','n','e','t','e','s','t',0};
1182 static const WCHAR filename_dotextW[] = {'w','i','n','e','t','e','s','t','.',0};
1183 static const WCHAR filename_dotanddefW[] = {'w','i','n','e','t','e','s','t','.','.','w','t','e',0};
1184 static const WCHAR filename_defextW[] = {'w','i','n','e','t','e','s','t','.','w','t','e',0};
1185 static const WCHAR filename_ext1W[] = {'w','i','n','e','t','e','s','t','.','w','t','1',0};
1186 static const WCHAR filename_ext2W[] = {'w','i','n','e','t','e','s','t','.','w','t','2',0};
1187 static const WCHAR filename_ext1anddefW[] =
1188 {'w','i','n','e','t','e','s','t','.','w','t','1','.','w','t','e',0};
1189 static const WCHAR defextW[] = {'w','t','e',0};
1190 static const WCHAR desc1[] = {'d','e','s','c','r','i','p','t','i','o','n','1',0};
1191 static const WCHAR desc2[] = {'d','e','s','c','r','i','p','t','i','o','n','2',0};
1192 static const WCHAR descdef[] = {'d','e','f','a','u','l','t',' ','d','e','s','c',0};
1193 static const WCHAR ext1[] = {'*','.','w','t','1',0};
1194 static const WCHAR ext2[] = {'*','.','w','t','2',0};
1195 static const WCHAR extdef[] = {'*','.','w','t','e',0};
1196 static const WCHAR complexext[] = {'*','.','w','t','2',';','*','.','w','t','1',0};
1198 static const COMDLG_FILTERSPEC filterspec[] = {
1199 { desc1, ext1 }, { desc2, ext2 }, { descdef, extdef }
1201 static const COMDLG_FILTERSPEC filterspec2[] = {
1202 { desc1, complexext }
1206 test_filename_savedlg(filename_noextW, NULL, NULL, 0, filename_noextW);
1207 /* Default extension */
1208 test_filename_savedlg(filename_noextW, defextW, NULL, 0, filename_defextW);
1209 /* Default extension on filename ending with a . */
1210 test_filename_savedlg(filename_dotextW, defextW, NULL, 0, filename_dotanddefW);
1211 /* Default extension on filename with default extension */
1212 test_filename_savedlg(filename_defextW, defextW, NULL, 0, filename_defextW);
1213 /* Default extension on filename with another extension */
1214 test_filename_savedlg(filename_ext1W, defextW, NULL, 0, filename_ext1anddefW);
1215 /* Default extension, filterspec without default extension */
1216 test_filename_savedlg(filename_noextW, defextW, filterspec, 2, filename_ext1W);
1217 /* Default extension, filterspec with default extension */
1218 test_filename_savedlg(filename_noextW, defextW, filterspec, 3, filename_ext1W);
1219 /* Default extension, filterspec with "complex" extension */
1220 test_filename_savedlg(filename_noextW, defextW, filterspec2, 1, filename_ext2W);
1222 GetCurrentDirectoryW(MAX_PATH, buf);
1223 ok(!!pSHCreateItemFromParsingName, "SHCreateItemFromParsingName is missing.\n");
1224 hr = pSHCreateItemFromParsingName(buf, NULL, &IID_IShellItem, (void**)&psi_current);
1225 ok(hr == S_OK, "Got 0x%08x\n", hr);
1227 touch_file(filename_noextW);
1228 touch_file(filename_defextW);
1229 touch_file(filename_ext2W);
1231 /* IFileOpenDialog, default extension */
1232 test_filename_opendlg(filename_noextW, psi_current, defextW, NULL, 0, filename_noextW);
1233 /* IFileOpenDialog, default extension and filterspec */
1234 test_filename_opendlg(filename_noextW, psi_current, defextW, filterspec, 2, filename_noextW);
1236 DeleteFileW(filename_noextW);
1237 /* IFileOpenDialog, default extension, noextW deleted */
1238 test_filename_opendlg(filename_noextW, psi_current, defextW, NULL, 0, filename_defextW);
1239 if(0) /* Interactive */
1241 /* IFileOpenDialog, filterspec, no default extension, noextW deleted */
1242 test_filename_opendlg(filename_noextW, psi_current, NULL, filterspec, 2, NULL);
1245 IShellItem_Release(psi_current);
1246 DeleteFileW(filename_defextW);
1247 DeleteFileW(filename_ext2W);
1250 static const WCHAR label[] = {'l','a','b','e','l',0};
1251 static const WCHAR label2[] = {'t','e','s','t',0};
1252 static const WCHAR menuW[] = {'m','e','n','u','_','i','t','e','m',0};
1253 static const WCHAR pushbutton1W[] = {'p','u','s','h','b','u','t','t','o','n','_','i','t','e','m',0};
1254 static const WCHAR pushbutton2W[] = {'p','u','s','h','b','u','t','t','o','n','2','_','i','t','e','m',0};
1255 static const WCHAR comboboxitem1W[] = {'c','o','m','b','o','b','o','x','1','_','i','t','e','m',0};
1256 static const WCHAR comboboxitem2W[] = {'c','o','m','b','o','b','o','x','2','_','i','t','e','m',0};
1257 static const WCHAR radiobutton1W[] = {'r','a','d','i','o','b','u','t','t','o','n','1','_','i','t','e','m',0};
1258 static const WCHAR radiobutton2W[] = {'r','a','d','i','o','b','u','t','t','o','n','2','_','i','t','e','m',0};
1259 static const WCHAR checkbutton1W[] = {'c','h','e','c','k','b','u','t','t','o','n','1','_','i','t','e','m',0};
1260 static const WCHAR checkbutton2W[] = {'c','h','e','c','k','b','u','t','t','o','n','2','_','i','t','e','m',0};
1261 static const WCHAR editbox1W[] = {'e','d','i','t','b','o','x','W','1','_','i','t','e','m',0};
1262 static const WCHAR editbox2W[] = {'e','d','i','t','b','o','x','W','2','_','i','t','e','m',0};
1263 static const WCHAR textW[] = {'t','e','x','t','_','i','t','e','m',0};
1264 static const WCHAR text2W[] = {'t','e','x','t','2','_','i','t','e','m',0};
1265 static const WCHAR separatorW[] = {'s','e','p','a','r','a','t','o','r','_','i','t','e','m',0};
1266 static const WCHAR visualgroup1W[] = {'v','i','s','u','a','l','g','r','o','u','p','1',0};
1267 static const WCHAR visualgroup2W[] = {'v','i','s','u','a','l','g','r','o','u','p','2',0};
1269 static const WCHAR floatnotifysinkW[] = {'F','l','o','a','t','N','o','t','i','f','y','S','i','n','k',0};
1270 static const WCHAR RadioButtonListW[] = {'R','a','d','i','o','B','u','t','t','o','n','L','i','s','t',0};
1273 LPCWSTR class, text;
1276 static BOOL CALLBACK find_window_callback(HWND hwnd, LPARAM lparam)
1278 struct fw_arg *arg = (struct fw_arg*)lparam;
1283 GetClassNameW(hwnd, buf, 1024);
1284 if(lstrcmpW(buf, arg->class))
1290 GetWindowTextW(hwnd, buf, 1024);
1291 if(lstrcmpW(buf, arg->text))
1295 arg->hwnd_res = hwnd;
1299 static HWND find_window(HWND parent, LPCWSTR class, LPCWSTR text)
1301 struct fw_arg arg = {class, text, NULL};
1303 EnumChildWindows(parent, find_window_callback, (LPARAM)&arg);
1304 return arg.hwnd_res;
1307 static void test_customize_onfolderchange(IFileDialog *pfd)
1310 HWND dlg_hwnd, item, item_parent;
1317 hr = IFileDialog_QueryInterface(pfd, &IID_IOleWindow, (void**)&pow);
1318 ok(hr == S_OK, "Got 0x%08x\n", hr);
1319 hr = IOleWindow_GetWindow(pow, &dlg_hwnd);
1320 ok(hr == S_OK, "Got 0x%08x\n", hr);
1321 ok(dlg_hwnd != NULL, "Got NULL.\n");
1322 IOleWindow_Release(pow);
1324 item = find_window(dlg_hwnd, NULL, checkbutton2W);
1325 ok(item != NULL, "Failed to find item.\n");
1326 item_parent = GetParent(item);
1327 GetClassNameW(item_parent, buf, 1024);
1328 ok(!lstrcmpW(buf, floatnotifysinkW), "Got %s\n", wine_dbgstr_w(buf));
1329 item = find_window(dlg_hwnd, NULL, text2W);
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, radiobutton1W);
1335 todo_wine ok(item != NULL, "Failed to find item.\n");
1336 item_parent = GetParent(item);
1337 GetClassNameW(item_parent, buf, 1024);
1338 todo_wine ok(!lstrcmpW(buf, RadioButtonListW), "Got %s\n", wine_dbgstr_w(buf));
1339 item_parent = GetParent(item_parent);
1340 GetClassNameW(item_parent, buf, 1024);
1341 ok(!lstrcmpW(buf, floatnotifysinkW), "Got %s\n", wine_dbgstr_w(buf));
1343 item = find_window(dlg_hwnd, NULL, pushbutton1W);
1344 ok(item == NULL, "Found item: %p\n", item);
1345 item = find_window(dlg_hwnd, NULL, pushbutton2W);
1346 ok(item == NULL, "Found item: %p\n", item);
1347 item = find_window(dlg_hwnd, NULL, comboboxitem1W);
1348 ok(item == NULL, "Found item: %p\n", item);
1349 item = find_window(dlg_hwnd, NULL, comboboxitem2W);
1350 ok(item == NULL, "Found item: %p\n", item);
1351 item = find_window(dlg_hwnd, NULL, radiobutton2W);
1352 ok(item == NULL, "Found item: %p\n", item);
1353 item = find_window(dlg_hwnd, NULL, checkbutton1W);
1354 ok(item == NULL, "Found item: %p\n", item);
1355 item = find_window(dlg_hwnd, NULL, editbox1W);
1356 ok(item == NULL, "Found item: %p\n", item);
1357 item = find_window(dlg_hwnd, NULL, editbox2W);
1358 ok(item == NULL, "Found item: %p\n", item);
1359 item = find_window(dlg_hwnd, NULL, textW);
1360 ok(item == NULL, "Found item: %p\n", item);
1361 item = find_window(dlg_hwnd, NULL, separatorW);
1362 ok(item == NULL, "Found item: %p\n", item);
1363 item = find_window(dlg_hwnd, NULL, visualgroup1W);
1364 ok(item == NULL, "Found item: %p\n", item);
1365 item = find_window(dlg_hwnd, NULL, visualgroup2W);
1366 ok(item == NULL, "Found item: %p\n", item);
1368 br = PostMessageW(dlg_hwnd, WM_COMMAND, IDCANCEL, 0);
1372 static void test_customize(void)
1375 IFileDialogCustomize *pfdc;
1376 IFileDialogEventsImpl *pfdeimpl;
1377 IFileDialogEvents *pfde;
1379 CDCONTROLSTATEF cdstate;
1386 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
1387 &IID_IFileDialog, (void**)&pfod);
1388 ok(hr == S_OK, "got 0x%08x.\n", hr);
1390 hr = IFileDialog_QueryInterface(pfod, &IID_IFileDialogCustomize, (void**)&pfdc);
1391 ok(hr == S_OK, "got 0x%08x.\n", hr);
1394 skip("Skipping IFileDialogCustomize tests.\n");
1399 hr = IFileDialogCustomize_AddPushButton(pfdc, i, pushbutton1W);
1400 ok(hr == S_OK, "got 0x%08x.\n", hr);
1401 hr = IFileDialogCustomize_AddPushButton(pfdc, i, pushbutton1W);
1402 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1404 hr = IFileDialog_QueryInterface(pfod, &IID_IOleWindow, (void**)&pow);
1405 ok(hr == S_OK, "Got 0x%08x\n", hr);
1406 hr = IOleWindow_GetWindow(pow, &dlg_hwnd);
1407 ok(hr == S_OK, "Got 0x%08x\n", hr);
1408 ok(dlg_hwnd == NULL, "NULL\n");
1409 IOleWindow_Release(pow);
1411 cdstate = 0xdeadbeef;
1412 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1413 ok(hr == S_OK, "got 0x%08x.\n", hr);
1414 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1416 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1417 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
1419 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1420 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1422 hr = IFileDialogCustomize_EnableOpenDropDown(pfdc, i);
1423 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1424 hr = IFileDialogCustomize_EnableOpenDropDown(pfdc, ++i);
1425 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1427 cdstate = 0xdeadbeef;
1428 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1429 ok(hr == E_NOTIMPL, "got 0x%08x.\n", hr);
1430 ok(cdstate == 0xdeadbeef, "got 0x%08x.\n", cdstate);
1432 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1433 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1434 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1435 todo_wine ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
1437 cdstate = 0xdeadbeef;
1438 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1439 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1440 todo_wine ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1441 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, 0);
1442 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
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, "got 0x%08x.\n", cdstate);
1447 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, CDCS_ENABLEDVISIBLE);
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 == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1454 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1455 todo_wine ok(hr == E_NOTIMPL, "got 0x%08x (control: %d).\n", hr, i);
1457 hr = IFileDialogCustomize_AddMenu(pfdc, i, menuW);
1458 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1459 hr = IFileDialogCustomize_AddMenu(pfdc, ++i, label);
1460 ok(hr == S_OK, "got 0x%08x.\n", hr);
1462 cdstate = 0xdeadbeef;
1463 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1464 ok(hr == S_OK, "got 0x%08x.\n", hr);
1465 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1467 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1468 ok(hr == S_OK, "got 0x%08x.\n", hr);
1469 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1470 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
1472 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1473 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1475 hr = IFileDialogCustomize_AddPushButton(pfdc, i, pushbutton2W);
1476 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1477 hr = IFileDialogCustomize_AddPushButton(pfdc, ++i, pushbutton2W);
1478 ok(hr == S_OK, "got 0x%08x.\n", hr);
1480 cdstate = 0xdeadbeef;
1481 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1482 ok(hr == S_OK, "got 0x%08x.\n", hr);
1483 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1485 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1486 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
1488 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1489 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1491 hr = IFileDialogCustomize_AddComboBox(pfdc, i);
1492 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1493 hr = IFileDialogCustomize_AddComboBox(pfdc, ++i);
1494 ok(hr == S_OK, "got 0x%08x.\n", hr);
1496 cdstate = 0xdeadbeef;
1497 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1498 ok(hr == S_OK, "got 0x%08x.\n", hr);
1499 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1501 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1502 ok(hr == S_OK, "got 0x%08x.\n", hr);
1503 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1504 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
1506 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1507 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1509 hr = IFileDialogCustomize_AddRadioButtonList(pfdc, i);
1510 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1511 hr = IFileDialogCustomize_AddRadioButtonList(pfdc, ++i);
1512 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1514 cdstate = 0xdeadbeef;
1515 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1516 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1517 todo_wine ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1519 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, radiobutton1W);
1520 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1521 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, radiobutton1W);
1522 todo_wine ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
1524 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, radiobutton2W);
1525 todo_wine ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1527 hr = IFileDialogCustomize_AddCheckButton(pfdc, i, label, TRUE);
1528 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1529 hr = IFileDialogCustomize_AddCheckButton(pfdc, ++i, checkbutton1W, TRUE);
1530 ok(hr == S_OK, "got 0x%08x.\n", hr);
1532 cdstate = 0xdeadbeef;
1533 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1534 ok(hr == S_OK, "got 0x%08x.\n", hr);
1535 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1537 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1538 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
1540 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, checkbutton2W);
1541 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1546 hr = IFileDialogCustomize_GetCheckButtonState(pfdc, i, &checked);
1547 ok(hr == S_OK, "got 0x%08x.\n", hr);
1548 ok(checked, "checkbox not checked.\n");
1550 hr = IFileDialogCustomize_SetCheckButtonState(pfdc, i, FALSE);
1551 ok(hr == S_OK, "got 0x%08x.\n", hr);
1553 hr = IFileDialogCustomize_GetCheckButtonState(pfdc, i, &checked);
1554 ok(hr == S_OK, "got 0x%08x.\n", hr);
1555 ok(!checked, "checkbox checked.\n");
1557 hr = IFileDialogCustomize_SetCheckButtonState(pfdc, i, TRUE);
1558 ok(hr == S_OK, "got 0x%08x.\n", hr);
1560 hr = IFileDialogCustomize_GetCheckButtonState(pfdc, i, &checked);
1561 ok(hr == S_OK, "got 0x%08x.\n", hr);
1562 ok(checked, "checkbox not checked.\n");
1565 hr = IFileDialogCustomize_AddEditBox(pfdc, i, label);
1566 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1567 hr = IFileDialogCustomize_AddEditBox(pfdc, ++i, editbox1W);
1568 ok(hr == S_OK, "got 0x%08x.\n", hr);
1570 cdstate = 0xdeadbeef;
1571 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1572 ok(hr == S_OK, "got 0x%08x.\n", hr);
1573 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1575 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1576 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
1578 /* Does not affect the text in the editbox */
1579 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, editbox2W);
1580 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1582 hr = IFileDialogCustomize_GetEditBoxText(pfdc, i, &tmpstr);
1583 ok(hr == S_OK, "got 0x%08x.\n", hr);
1586 ok(!lstrcmpW(tmpstr, editbox1W), "got %s.\n", wine_dbgstr_w(tmpstr));
1587 CoTaskMemFree(tmpstr);
1590 hr = IFileDialogCustomize_SetEditBoxText(pfdc, i, label2);
1591 ok(hr == S_OK, "got 0x%08x.\n", hr);
1593 hr = IFileDialogCustomize_GetEditBoxText(pfdc, i, &tmpstr);
1594 ok(hr == S_OK, "got 0x%08x.\n", hr);
1597 ok(!lstrcmpW(tmpstr, label2), "got %s.\n", wine_dbgstr_w(tmpstr));
1598 CoTaskMemFree(tmpstr);
1601 hr = IFileDialogCustomize_AddSeparator(pfdc, i);
1602 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1603 hr = IFileDialogCustomize_AddSeparator(pfdc, ++i);
1604 ok(hr == S_OK, "got 0x%08x.\n", hr);
1606 cdstate = 0xdeadbeef;
1607 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1608 ok(hr == S_OK, "got 0x%08x.\n", hr);
1609 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1611 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1612 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
1614 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, separatorW);
1615 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1617 hr = IFileDialogCustomize_AddText(pfdc, i, label);
1618 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1619 hr = IFileDialogCustomize_AddText(pfdc, ++i, textW);
1620 ok(hr == S_OK, "got 0x%08x.\n", hr);
1622 cdstate = 0xdeadbeef;
1623 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1624 ok(hr == S_OK, "got 0x%08x.\n", hr);
1625 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1627 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1628 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
1630 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, text2W);
1631 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1633 hr = IFileDialogCustomize_StartVisualGroup(pfdc, i, label);
1634 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1635 hr = IFileDialogCustomize_StartVisualGroup(pfdc, ++i, visualgroup1W);
1636 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1638 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1639 todo_wine ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
1641 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, visualgroup2W);
1642 todo_wine ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1644 cdstate = 0xdeadbeef;
1645 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1646 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1647 todo_wine ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1649 hr = IFileDialogCustomize_StartVisualGroup(pfdc, ++i, label);
1650 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1651 hr = IFileDialogCustomize_EndVisualGroup(pfdc);
1652 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1654 i++; /* Nonexisting control */
1655 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1656 todo_wine ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
1657 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1658 ok(hr == E_INVALIDARG, "got 0x%08x (control: %d).\n", hr, i);
1659 cdstate = 0xdeadbeef;
1660 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1661 todo_wine ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
1662 ok(cdstate == 0xdeadbeef, "got 0x%08x.\n", cdstate);
1664 pfde = IFileDialogEvents_Constructor();
1665 pfdeimpl = impl_from_IFileDialogEvents(pfde);
1666 pfdeimpl->cfd_test1 = TRUE;
1667 hr = IFileDialog_Advise(pfod, pfde, &cookie);
1668 ok(hr == S_OK, "Got 0x%08x\n", hr);
1670 hr = IFileDialog_Show(pfod, NULL);
1671 ok(hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "Got 0x%08x\n", hr);
1673 hr = IFileDialog_Unadvise(pfod, cookie);
1674 ok(hr == S_OK, "Got 0x%08x\n", hr);
1676 IFileDialogEvents_Release(pfde);
1677 IFileDialogCustomize_Release(pfdc);
1678 ref = IFileDialog_Release(pfod);
1679 ok(!ref, "Refcount not zero (%d).\n", ref);
1682 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
1683 &IID_IFileDialog, (void**)&pfod);
1684 ok(hr == S_OK, "got 0x%08x.\n", hr);
1686 hr = IFileDialog_QueryInterface(pfod, &IID_IFileDialogCustomize, (void**)&pfdc);
1687 ok(hr == S_OK, "got 0x%08x.\n", hr);
1690 hr = IFileDialogCustomize_AddMenu(pfdc, ++i, label);
1691 ok(hr == S_OK, "got 0x%08x.\n", hr);
1697 for(j = 0; j < 10; j++)
1699 hr = IFileDialogCustomize_AddControlItem(pfdc, i, j, label);
1700 ok(hr == S_OK, "got 0x%08x.\n", hr);
1703 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
1704 ok(hr == E_NOTIMPL, "got 0x%08x.\n", hr);
1706 cdstate = 0xdeadbeef;
1707 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1708 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1709 todo_wine ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1710 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, 0);
1711 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
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 == 0, "got 0x%08x.\n", cdstate);
1716 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, CDCS_ENABLEDVISIBLE);
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 == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1723 hr = IFileDialogCustomize_RemoveAllControlItems(pfdc, i);
1724 ok(hr == E_NOTIMPL, "got 0x%08x.\n", hr);
1726 for(j = 0; j < 10; j++)
1728 hr = IFileDialogCustomize_RemoveControlItem(pfdc, i, j);
1729 ok(hr == S_OK, "got 0x%08x.\n", hr);
1732 hr = IFileDialogCustomize_AddPushButton(pfdc, ++i, label);
1733 ok(hr == S_OK, "got 0x%08x.\n", hr);
1734 hr = IFileDialogCustomize_AddComboBox(pfdc, ++i);
1735 ok(hr == S_OK, "got 0x%08x.\n", hr);
1738 DWORD selected = -1;
1741 for(j = 0; j < 10; j++)
1743 hr = IFileDialogCustomize_AddControlItem(pfdc, i, j, label);
1744 ok(hr == S_OK, "got 0x%08x.\n", hr);
1747 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
1748 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
1749 ok(selected == -1, "got %d.\n", selected);
1752 cdstate = 0xdeadbeef;
1753 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1754 ok(hr == S_OK, "got 0x%08x.\n", hr);
1755 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1756 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, 0);
1757 ok(hr == S_OK, "got 0x%08x.\n", hr);
1758 cdstate = 0xdeadbeef;
1759 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1760 ok(hr == S_OK, "got 0x%08x.\n", hr);
1761 ok(cdstate == 0, "got 0x%08x.\n", cdstate);
1762 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, CDCS_ENABLEDVISIBLE);
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 == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1770 for(j = 0; j < 10; j++)
1772 hr = IFileDialogCustomize_SetSelectedControlItem(pfdc, i, j);
1773 ok(hr == S_OK, "got 0x%08x.\n", hr);
1774 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
1775 ok(hr == S_OK, "got 0x%08x.\n", hr);
1776 ok(selected == j, "got %d.\n", selected);
1779 hr = IFileDialogCustomize_SetSelectedControlItem(pfdc, i, j);
1780 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
1782 hr = IFileDialogCustomize_RemoveAllControlItems(pfdc, i);
1783 ok(hr == E_NOTIMPL, "got 0x%08x.\n", hr);
1785 for(j = 0; j < 10; j++)
1787 hr = IFileDialogCustomize_RemoveControlItem(pfdc, i, j);
1788 ok(hr == S_OK, "got 0x%08x.\n", hr);
1792 hr = IFileDialogCustomize_AddRadioButtonList(pfdc, ++i);
1793 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1796 DWORD selected = -1;
1799 for(j = 0; j < 10; j++)
1801 hr = IFileDialogCustomize_AddControlItem(pfdc, i, j, label);
1802 ok(hr == S_OK, "got 0x%08x.\n", hr);
1805 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
1806 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
1807 ok(selected == -1, "got %d.\n", selected);
1810 cdstate = 0xdeadbeef;
1811 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1812 ok(hr == S_OK, "got 0x%08x.\n", hr);
1813 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1814 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, 0);
1815 ok(hr == S_OK, "got 0x%08x.\n", hr);
1816 cdstate = 0xdeadbeef;
1817 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1818 ok(hr == S_OK, "got 0x%08x.\n", hr);
1819 ok(cdstate == 0, "got 0x%08x.\n", cdstate);
1820 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, CDCS_ENABLEDVISIBLE);
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 == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1828 for(j = 0; j < 10; j++)
1830 hr = IFileDialogCustomize_SetSelectedControlItem(pfdc, i, j);
1831 ok(hr == S_OK, "got 0x%08x.\n", hr);
1832 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
1833 ok(hr == S_OK, "got 0x%08x.\n", hr);
1834 ok(selected == j, "got %d.\n", selected);
1837 hr = IFileDialogCustomize_SetSelectedControlItem(pfdc, i, j);
1838 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
1840 hr = IFileDialogCustomize_RemoveAllControlItems(pfdc, i);
1841 ok(hr == E_NOTIMPL, "got 0x%08x.\n", hr);
1843 for(j = 0; j < 10; j++)
1845 hr = IFileDialogCustomize_RemoveControlItem(pfdc, i, j);
1846 ok(hr == S_OK, "got 0x%08x.\n", hr);
1849 hr = IFileDialogCustomize_EnableOpenDropDown(pfdc, ++i);
1850 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1853 DWORD selected = -1;
1856 for(j = 0; j < 10; j++)
1858 hr = IFileDialogCustomize_AddControlItem(pfdc, i, j, label);
1859 ok(hr == S_OK, "got 0x%08x.\n", hr);
1862 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
1863 ok(hr == S_OK, "got 0x%08x.\n", hr);
1864 ok(selected == 0, "got %d.\n", selected);
1866 cdstate = 0xdeadbeef;
1867 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1868 ok(hr == S_OK, "got 0x%08x.\n", hr);
1869 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1870 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, 0);
1871 ok(hr == S_OK, "got 0x%08x.\n", hr);
1872 cdstate = 0xdeadbeef;
1873 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1874 ok(hr == S_OK, "got 0x%08x.\n", hr);
1875 ok(cdstate == 0, "got 0x%08x.\n", cdstate);
1876 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, CDCS_ENABLEDVISIBLE);
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 == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1882 hr = IFileDialogCustomize_SetSelectedControlItem(pfdc, i, 0);
1883 ok(hr == E_NOTIMPL, "got 0x%08x.\n", hr);
1885 hr = IFileDialogCustomize_RemoveAllControlItems(pfdc, i);
1886 ok(hr == E_NOTIMPL, "got 0x%08x.\n", hr);
1888 for(j = 0; j < 10; j++)
1890 hr = IFileDialogCustomize_RemoveControlItem(pfdc, i, j);
1891 ok(hr == S_OK, "got 0x%08x.\n", hr);
1895 IFileDialogCustomize_Release(pfdc);
1896 ref = IFileDialog_Release(pfod);
1897 ok(!ref, "Refcount not zero (%d).\n", ref);
1902 OleInitialize(NULL);
1903 init_function_pointers();
1905 if(test_instantiation())
1913 skip("Skipping all Item Dialog tests.\n");