comdlg32/tests: Enable compilation with long types.
[wine.git] / dlls / comdlg32 / tests / itemdlg.c
blobbba869ad0912c656114f08b168b76bcc697d3eb6
1 /*
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
22 #define COBJMACROS
23 #define CONST_VTABLE
25 #include "shlobj.h"
26 #include "wine/test.h"
28 #define IDT_CHANGEFILETYPE 500
29 #define IDT_CLOSEDIALOG 501
31 typedef enum {
32 IFDEVENT_TEST_NONE = 0,
33 IFDEVENT_TEST1 = 0x1,
34 IFDEVENT_TEST2 = 0x2,
35 IFDEVENT_TEST3 = 0x3
36 } FileDialogEventsTest;
38 static HRESULT (WINAPI *pSHCreateShellItem)(LPCITEMIDLIST,IShellFolder*,LPCITEMIDLIST,IShellItem**);
39 static HRESULT (WINAPI *pSHGetIDListFromObject)(IUnknown*, PIDLIST_ABSOLUTE*);
40 static HRESULT (WINAPI *pSHCreateItemFromParsingName)(PCWSTR,IBindCtx*,REFIID,void**);
42 static void init_function_pointers(void)
44 HMODULE hmod = GetModuleHandleA("shell32.dll");
46 #define MAKEFUNC(f) (p##f = (void*)GetProcAddress(hmod, #f))
47 MAKEFUNC(SHCreateShellItem);
48 MAKEFUNC(SHGetIDListFromObject);
49 MAKEFUNC(SHCreateItemFromParsingName);
50 #undef MAKEFUNC
53 #include <initguid.h>
54 DEFINE_GUID(IID_IFileDialogCustomizeAlt, 0x8016B7B3, 0x3D49, 0x4504, 0xA0,0xAA, 0x2A,0x37,0x49,0x4E,0x60,0x6F);
56 struct fw_arg {
57 LPCWSTR class, text;
58 HWND hwnd_res;
61 static BOOL CALLBACK find_window_callback(HWND hwnd, LPARAM lparam)
63 struct fw_arg *arg = (struct fw_arg*)lparam;
64 WCHAR buf[1024];
66 if(arg->class)
68 GetClassNameW(hwnd, buf, 1024);
69 if(lstrcmpW(buf, arg->class))
70 return TRUE;
73 if(arg->text)
75 GetWindowTextW(hwnd, buf, 1024);
76 if(lstrcmpW(buf, arg->text))
77 return TRUE;
80 arg->hwnd_res = hwnd;
81 return FALSE;
84 static HWND find_window(HWND parent, LPCWSTR class, LPCWSTR text)
86 struct fw_arg arg = {class, text, NULL};
88 EnumChildWindows(parent, find_window_callback, (LPARAM)&arg);
89 return arg.hwnd_res;
92 static HWND get_hwnd_from_ifiledialog(IFileDialog *pfd)
94 IOleWindow *pow;
95 HWND dlg_hwnd;
96 HRESULT hr;
98 hr = IFileDialog_QueryInterface(pfd, &IID_IOleWindow, (void**)&pow);
99 ok(hr == S_OK, "Got 0x%08lx\n", hr);
101 hr = IOleWindow_GetWindow(pow, &dlg_hwnd);
102 ok(hr == S_OK, "Got 0x%08lx\n", hr);
104 IOleWindow_Release(pow);
106 return dlg_hwnd;
109 static void test_customize_onfolderchange(IFileDialog *pfd);
110 static void filedialog_change_filetype(IFileDialog *pfd, HWND dlg_hwnd);
112 /**************************************************************************
113 * IFileDialogEvents implementation
115 typedef struct {
116 IFileDialogEvents IFileDialogEvents_iface;
117 LONG ref;
118 LONG QueryInterface;
119 LONG OnFileOk, OnFolderChanging, OnFolderChange;
120 LONG OnSelectionChange, OnShareViolation, OnTypeChange;
121 LONG OnOverwrite;
122 LPCWSTR set_filename;
123 BOOL set_filename_tried;
124 FileDialogEventsTest events_test;
125 } IFileDialogEventsImpl;
127 static inline IFileDialogEventsImpl *impl_from_IFileDialogEvents(IFileDialogEvents *iface)
129 return CONTAINING_RECORD(iface, IFileDialogEventsImpl, IFileDialogEvents_iface);
132 static HRESULT WINAPI IFileDialogEvents_fnQueryInterface(IFileDialogEvents *iface, REFIID riid, void **ppv)
134 /* Not called. */
135 ok(0, "Unexpectedly called.\n");
136 return E_NOINTERFACE;
139 static ULONG WINAPI IFileDialogEvents_fnAddRef(IFileDialogEvents *iface)
141 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
142 return InterlockedIncrement(&This->ref);
145 static ULONG WINAPI IFileDialogEvents_fnRelease(IFileDialogEvents *iface)
147 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
148 LONG ref = InterlockedDecrement(&This->ref);
150 if(!ref)
151 HeapFree(GetProcessHeap(), 0, This);
153 return ref;
156 static HRESULT WINAPI IFileDialogEvents_fnOnFileOk(IFileDialogEvents *iface, IFileDialog *pfd)
158 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
159 This->OnFileOk++;
160 return S_OK;
163 static HRESULT WINAPI IFileDialogEvents_fnOnFolderChanging(IFileDialogEvents *iface,
164 IFileDialog *pfd,
165 IShellItem *psiFolder)
167 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
168 This->OnFolderChanging++;
169 return S_OK;
172 static LRESULT CALLBACK test_customize_dlgproc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
174 WNDPROC oldwndproc = GetPropA(hwnd, "WT_OLDWC");
175 IFileDialog *pfd = GetPropA(hwnd, "WT_PFD");
176 BOOL br;
178 switch(message)
180 case WM_USER+0x1234:
181 test_customize_onfolderchange(pfd);
182 break;
183 case WM_TIMER:
184 switch(wparam)
186 case IDT_CHANGEFILETYPE:
187 filedialog_change_filetype(pfd, hwnd);
188 KillTimer(hwnd, IDT_CHANGEFILETYPE);
189 SetTimer(hwnd, IDT_CLOSEDIALOG, 100, 0);
190 return TRUE;
191 case IDT_CLOSEDIALOG:
192 /* Calling IFileDialog_Close here does not work */
193 br = PostMessageW(hwnd, WM_COMMAND, IDCANCEL, 0);
194 ok(br, "Failed\n");
195 return TRUE;
199 return CallWindowProcW(oldwndproc, hwnd, message, wparam, lparam);
202 static HRESULT WINAPI IFileDialogEvents_fnOnFolderChange(IFileDialogEvents *iface, IFileDialog *pfd)
204 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
205 HWND dlg_hwnd;
206 HRESULT hr;
207 BOOL br;
208 This->OnFolderChange++;
210 if(This->set_filename)
212 dlg_hwnd = get_hwnd_from_ifiledialog(pfd);
213 ok(dlg_hwnd != NULL, "Got NULL.\n");
215 hr = IFileDialog_SetFileName(pfd, This->set_filename);
216 ok(hr == S_OK, "Got 0x%08lx\n", hr);
218 if(!This->set_filename_tried)
220 br = PostMessageW(dlg_hwnd, WM_COMMAND, IDOK, 0);
221 ok(br, "Failed\n");
222 This->set_filename_tried = TRUE;
226 if(This->events_test)
228 WNDPROC oldwndproc;
230 dlg_hwnd = get_hwnd_from_ifiledialog(pfd);
232 /* On Vista, the custom control area of the dialog is not
233 * fully set up when the first OnFolderChange event is
234 * issued. */
235 oldwndproc = (WNDPROC)GetWindowLongPtrW(dlg_hwnd, GWLP_WNDPROC);
236 SetPropA(dlg_hwnd, "WT_OLDWC", (HANDLE)oldwndproc);
237 SetPropA(dlg_hwnd, "WT_PFD", (HANDLE)pfd);
238 SetWindowLongPtrW(dlg_hwnd, GWLP_WNDPROC, (LPARAM)test_customize_dlgproc);
240 switch(This->events_test)
242 case IFDEVENT_TEST1:
243 br = PostMessageW(dlg_hwnd, WM_USER+0x1234, 0, 0);
244 ok(br, "Failed\n");
245 break;
246 case IFDEVENT_TEST2:
247 SetTimer(dlg_hwnd, IDT_CLOSEDIALOG, 100, 0);
248 break;
249 case IFDEVENT_TEST3:
250 SetTimer(dlg_hwnd, IDT_CHANGEFILETYPE, 100, 0);
251 break;
252 default:
253 ok(FALSE, "Should not happen (%d)\n", This->events_test);
257 return S_OK;
260 static HRESULT WINAPI IFileDialogEvents_fnOnSelectionChange(IFileDialogEvents *iface, IFileDialog *pfd)
262 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
263 This->OnSelectionChange++;
264 return S_OK;
267 static HRESULT WINAPI IFileDialogEvents_fnOnShareViolation(IFileDialogEvents *iface,
268 IFileDialog *pfd,
269 IShellItem *psi,
270 FDE_SHAREVIOLATION_RESPONSE *pResponse)
272 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
273 This->OnShareViolation++;
274 return S_OK;
277 static HRESULT WINAPI IFileDialogEvents_fnOnTypeChange(IFileDialogEvents *iface, IFileDialog *pfd)
279 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
280 This->OnTypeChange++;
281 return S_OK;
284 static HRESULT WINAPI IFileDialogEvents_fnOnOverwrite(IFileDialogEvents *iface,
285 IFileDialog *pfd,
286 IShellItem *psi,
287 FDE_OVERWRITE_RESPONSE *pResponse)
289 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
290 This->OnOverwrite++;
291 ok(*pResponse == FDEOR_DEFAULT, "overwrite response %u\n", *pResponse);
292 *pResponse = FDEOR_ACCEPT;
293 ok(!This->OnFileOk, "OnFileOk already called %lu times\n", This->OnFileOk);
294 return S_OK;
297 static const IFileDialogEventsVtbl vt_IFileDialogEvents = {
298 IFileDialogEvents_fnQueryInterface,
299 IFileDialogEvents_fnAddRef,
300 IFileDialogEvents_fnRelease,
301 IFileDialogEvents_fnOnFileOk,
302 IFileDialogEvents_fnOnFolderChanging,
303 IFileDialogEvents_fnOnFolderChange,
304 IFileDialogEvents_fnOnSelectionChange,
305 IFileDialogEvents_fnOnShareViolation,
306 IFileDialogEvents_fnOnTypeChange,
307 IFileDialogEvents_fnOnOverwrite
310 static IFileDialogEvents *IFileDialogEvents_Constructor(void)
312 IFileDialogEventsImpl *This;
314 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IFileDialogEventsImpl));
315 This->IFileDialogEvents_iface.lpVtbl = &vt_IFileDialogEvents;
316 This->ref = 1;
318 return &This->IFileDialogEvents_iface;
321 static BOOL test_instantiation(void)
323 IFileDialog *pfd;
324 IFileOpenDialog *pfod;
325 IFileSaveDialog *pfsd;
326 IServiceProvider *psp;
327 IOleWindow *pow;
328 IUnknown *punk, *unk2;
329 HRESULT hr;
330 LONG ref;
332 /* Instantiate FileOpenDialog */
333 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
334 &IID_IFileOpenDialog, (void**)&pfod);
335 if(FAILED(hr))
337 win_skip("Could not instantiate the FileOpenDialog.\n");
338 return FALSE;
340 ok(hr == S_OK, "got 0x%08lx.\n", hr);
342 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialog, (void**)&pfd);
343 ok(hr == S_OK, "got 0x%08lx.\n", hr);
344 if(SUCCEEDED(hr)) IFileDialog_Release(pfd);
346 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialogCustomize, (void**)&punk);
347 ok(hr == S_OK, "got 0x%08lx.\n", hr);
349 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialogCustomizeAlt, (void**)&unk2);
350 ok(hr == S_OK, "got 0x%08lx.\n", hr);
351 ok(punk == unk2, "got %p, %p\n", punk, unk2);
352 IUnknown_Release(punk);
353 IUnknown_Release(unk2);
355 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileSaveDialog, (void**)&pfsd);
356 ok(hr == E_NOINTERFACE, "got 0x%08lx.\n", hr);
357 if(SUCCEEDED(hr)) IFileSaveDialog_Release(pfsd);
359 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IServiceProvider, (void**)&psp);
360 ok(hr == S_OK, "got 0x%08lx.\n", hr);
361 if(SUCCEEDED(hr))
363 IExplorerBrowser *peb;
364 IShellBrowser *psb;
366 hr = IServiceProvider_QueryService(psp, &SID_SExplorerBrowserFrame, &IID_ICommDlgBrowser, (void**)&punk);
367 ok(hr == S_OK, "got 0x%08lx.\n", hr);
368 if(SUCCEEDED(hr)) IUnknown_Release(punk);
370 /* since win8, the result is E_NOTIMPL for all other services */
371 hr = IServiceProvider_QueryService(psp, &SID_STopLevelBrowser, &IID_IExplorerBrowser, (void**)&peb);
372 ok(hr == E_NOTIMPL || broken(hr == E_FAIL), "got 0x%08lx (expected E_NOTIMPL)\n", hr);
373 if(SUCCEEDED(hr)) IExplorerBrowser_Release(peb);
374 hr = IServiceProvider_QueryService(psp, &SID_STopLevelBrowser, &IID_IShellBrowser, (void**)&psb);
375 ok(hr == E_NOTIMPL || broken(hr == E_FAIL), "got 0x%08lx (expected E_NOTIMPL)\n", hr);
376 if(SUCCEEDED(hr)) IShellBrowser_Release(psb);
377 hr = IServiceProvider_QueryService(psp, &SID_STopLevelBrowser, &IID_ICommDlgBrowser, (void**)&punk);
378 ok(hr == E_NOTIMPL || broken(hr == E_FAIL), "got 0x%08lx (expected E_NOTIMPL)\n", hr);
379 if(SUCCEEDED(hr)) IUnknown_Release(punk);
381 hr = IServiceProvider_QueryService(psp, &SID_STopLevelBrowser, &IID_IUnknown, (void**)&punk);
382 ok(hr == E_NOTIMPL || broken(hr == E_FAIL), "got 0x%08lx (expected E_NOTIMPL)\n", hr);
383 if(SUCCEEDED(hr)) IUnknown_Release(punk);
384 hr = IServiceProvider_QueryService(psp, &IID_IUnknown, &IID_IUnknown, (void**)&punk);
385 ok(hr == E_NOTIMPL || broken(hr == E_FAIL), "got 0x%08lx (expected E_NOTIMPL)\n", hr);
386 if(SUCCEEDED(hr)) IUnknown_Release(punk);
388 IServiceProvider_Release(psp);
391 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialogEvents, (void**)&punk);
392 ok(hr == E_NOINTERFACE, "got 0x%08lx.\n", hr);
393 if(SUCCEEDED(hr)) IUnknown_Release(punk);
395 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IExplorerBrowser, (void**)&punk);
396 ok(hr == E_NOINTERFACE, "got 0x%08lx.\n", hr);
397 if(SUCCEEDED(hr)) IUnknown_Release(punk);
399 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IExplorerBrowserEvents, (void**)&punk);
400 ok(hr == S_OK, "got 0x%08lx.\n", hr);
401 if(SUCCEEDED(hr)) IUnknown_Release(punk);
403 hr = IFileOpenDialog_QueryInterface(pfod, &IID_ICommDlgBrowser3, (void**)&punk);
404 ok(hr == S_OK, "got 0x%08lx.\n", hr);
405 if(SUCCEEDED(hr)) IUnknown_Release(punk);
407 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IShellBrowser, (void**)&punk);
408 ok(hr == E_NOINTERFACE, "got 0x%08lx.\n", hr);
409 if(SUCCEEDED(hr)) IUnknown_Release(punk);
411 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IOleWindow, (void**)&pow);
412 ok(hr == S_OK, "got 0x%08lx.\n", hr);
413 if(SUCCEEDED(hr))
415 HWND hwnd;
417 hr = IOleWindow_ContextSensitiveHelp(pow, TRUE);
418 todo_wine ok(hr == S_OK, "Got 0x%08lx\n", hr);
420 hr = IOleWindow_ContextSensitiveHelp(pow, FALSE);
421 todo_wine ok(hr == S_OK, "Got 0x%08lx\n", hr);
423 if(0)
425 /* Crashes on win7 */
426 IOleWindow_GetWindow(pow, NULL);
429 hr = IOleWindow_GetWindow(pow, &hwnd);
430 ok(hr == S_OK, "Got 0x%08lx\n", hr);
431 ok(hwnd == NULL, "Got %p\n", hwnd);
433 IOleWindow_Release(pow);
436 ref = IFileOpenDialog_Release(pfod);
437 ok(!ref, "Got refcount %ld, should have been released.\n", ref);
439 /* Instantiate FileSaveDialog */
440 hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER,
441 &IID_IFileSaveDialog, (void**)&pfsd);
442 if(FAILED(hr))
444 win_skip("Could not instantiate the FileSaveDialog.\n");
445 return FALSE;
447 ok(hr == S_OK, "got 0x%08lx.\n", hr);
449 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialog, (void**)&pfd);
450 ok(hr == S_OK, "got 0x%08lx.\n", hr);
451 if(SUCCEEDED(hr)) IFileDialog_Release(pfd);
453 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialogCustomize, (void**)&punk);
454 ok(hr == S_OK, "got 0x%08lx.\n", hr);
456 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialogCustomizeAlt, (void**)&unk2);
457 ok(hr == S_OK, "got 0x%08lx.\n", hr);
458 ok(punk == unk2, "got %p, %p\n", punk, unk2);
459 IUnknown_Release(punk);
460 IUnknown_Release(unk2);
462 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileOpenDialog, (void**)&pfod);
463 ok(hr == E_NOINTERFACE, "got 0x%08lx.\n", hr);
464 if(SUCCEEDED(hr)) IFileOpenDialog_Release(pfod);
466 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialogEvents, (void**)&punk);
467 ok(hr == E_NOINTERFACE, "got 0x%08lx.\n", hr);
468 if(SUCCEEDED(hr)) IFileDialog_Release(pfd);
470 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IExplorerBrowser, (void**)&punk);
471 ok(hr == E_NOINTERFACE, "got 0x%08lx.\n", hr);
472 if(SUCCEEDED(hr)) IUnknown_Release(punk);
474 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IExplorerBrowserEvents, (void**)&punk);
475 ok(hr == S_OK, "got 0x%08lx.\n", hr);
476 if(SUCCEEDED(hr)) IUnknown_Release(punk);
478 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_ICommDlgBrowser3, (void**)&punk);
479 ok(hr == S_OK, "got 0x%08lx.\n", hr);
480 if(SUCCEEDED(hr)) IUnknown_Release(punk);
482 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IShellBrowser, (void**)&punk);
483 ok(hr == E_NOINTERFACE, "got 0x%08lx.\n", hr);
484 if(SUCCEEDED(hr)) IUnknown_Release(punk);
486 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IOleWindow, (void**)&pow);
487 ok(hr == S_OK, "got 0x%08lx.\n", hr);
488 if(SUCCEEDED(hr))
490 HWND hwnd;
492 hr = IOleWindow_ContextSensitiveHelp(pow, TRUE);
493 todo_wine ok(hr == S_OK, "Got 0x%08lx\n", hr);
495 hr = IOleWindow_ContextSensitiveHelp(pow, FALSE);
496 todo_wine ok(hr == S_OK, "Got 0x%08lx\n", hr);
498 if(0)
500 /* Crashes on win7 */
501 IOleWindow_GetWindow(pow, NULL);
504 hr = IOleWindow_GetWindow(pow, &hwnd);
505 ok(hr == S_OK, "Got 0x%08lx\n", hr);
506 ok(hwnd == NULL, "Got %p\n", hwnd);
508 IOleWindow_Release(pow);
512 ref = IFileSaveDialog_Release(pfsd);
513 ok(!ref, "Got refcount %ld, should have been released.\n", ref);
514 return TRUE;
517 static void test_basics(void)
519 IFileOpenDialog *pfod;
520 IFileSaveDialog *pfsd;
521 IFileDialog2 *pfd2;
522 FILEOPENDIALOGOPTIONS fdoptions;
523 IShellFolder *psfdesktop;
524 IShellItem *psi, *psidesktop, *psi_original;
525 IShellItemArray *psia;
526 IPropertyStore *pps;
527 LPITEMIDLIST pidl;
528 WCHAR *filename;
529 UINT filetype;
530 LONG ref;
531 HRESULT hr;
532 const WCHAR txt[] = {'t','x','t', 0};
533 const WCHAR null[] = {0};
534 const WCHAR fname1[] = {'f','n','a','m','e','1', 0};
535 const WCHAR fspec1[] = {'*','.','t','x','t',0};
536 const WCHAR fname2[] = {'f','n','a','m','e','2', 0};
537 const WCHAR fspec2[] = {'*','.','e','x','e',0};
538 COMDLG_FILTERSPEC filterspec[2] = {{fname1, fspec1}, {fname2, fspec2}};
539 const DWORD invalid_fos[] = {0x1, 0x10, 0x400, 0x80000, 0x400000, 0x800000, 0x1000000, 0x4000000, 0x8000000};
540 INT i;
542 /* This should work on every platform with IFileDialog */
543 SHGetDesktopFolder(&psfdesktop);
544 hr = pSHGetIDListFromObject((IUnknown*)psfdesktop, &pidl);
545 if(SUCCEEDED(hr))
547 hr = pSHCreateShellItem(NULL, NULL, pidl, &psidesktop);
548 ILFree(pidl);
550 IShellFolder_Release(psfdesktop);
551 if(FAILED(hr))
553 skip("Failed to get ShellItem from DesktopFolder, skipping tests.\n");
554 return;
558 /* Instantiate FileOpenDialog and FileSaveDialog */
559 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
560 &IID_IFileOpenDialog, (void**)&pfod);
561 ok(hr == S_OK, "got 0x%08lx.\n", hr);
562 hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER,
563 &IID_IFileSaveDialog, (void**)&pfsd);
564 ok(hr == S_OK, "got 0x%08lx.\n", hr);
566 /* ClearClientData */
567 todo_wine
569 hr = IFileOpenDialog_ClearClientData(pfod);
570 ok(hr == E_FAIL, "got 0x%08lx.\n", hr);
571 hr = IFileSaveDialog_ClearClientData(pfsd);
572 ok(hr == E_FAIL, "got 0x%08lx.\n", hr);
575 /* GetOptions */
576 hr = IFileOpenDialog_GetOptions(pfod, NULL);
577 ok(hr == E_INVALIDARG, "got 0x%08lx.\n", hr);
578 hr = IFileSaveDialog_GetOptions(pfsd, NULL);
579 ok(hr == E_INVALIDARG, "got 0x%08lx.\n", hr);
581 /* Check default options */
582 hr = IFileOpenDialog_GetOptions(pfod, &fdoptions);
583 ok(hr == S_OK, "got 0x%08lx.\n", hr);
584 ok(fdoptions == (FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST | FOS_NOCHANGEDIR),
585 "Unexpected default options: 0x%08lx\n", fdoptions);
586 hr = IFileSaveDialog_GetOptions(pfsd, &fdoptions);
587 ok(hr == S_OK, "got 0x%08lx.\n", hr);
588 ok(fdoptions == (FOS_OVERWRITEPROMPT | FOS_NOREADONLYRETURN | FOS_PATHMUSTEXIST | FOS_NOCHANGEDIR),
589 "Unexpected default options: 0x%08lx\n", fdoptions);
591 /* Check SetOptions invalid options handling */
592 for (i = 0; i < ARRAY_SIZE(invalid_fos); i++)
594 hr = IFileOpenDialog_SetOptions(pfod, invalid_fos[i]);
595 ok(hr == E_INVALIDARG, "got 0x%08lx.\n", hr);
596 hr = IFileOpenDialog_GetOptions(pfod, &fdoptions);
597 ok(hr == S_OK, "got 0x%08lx.\n", hr);
598 ok(fdoptions == (FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST | FOS_NOCHANGEDIR), "got %08lx\n", fdoptions);
600 hr = IFileSaveDialog_SetOptions(pfsd, invalid_fos[i]);
601 ok(hr == E_INVALIDARG, "got 0x%08lx.\n", hr);
602 hr = IFileSaveDialog_GetOptions(pfsd, &fdoptions);
603 ok(hr == S_OK, "got 0x%08lx.\n", hr);
604 ok(fdoptions == (FOS_OVERWRITEPROMPT | FOS_NOREADONLYRETURN | FOS_PATHMUSTEXIST | FOS_NOCHANGEDIR),
605 "got %08lx\n", fdoptions);
608 /* GetResult */
609 hr = IFileOpenDialog_GetResult(pfod, NULL);
610 ok(hr == E_INVALIDARG, "got 0x%08lx.\n", hr);
611 hr = IFileSaveDialog_GetResult(pfsd, NULL);
612 ok(hr == E_INVALIDARG, "got 0x%08lx.\n", hr);
614 psi = (void*)0xdeadbeef;
615 hr = IFileOpenDialog_GetResult(pfod, &psi);
616 ok(hr == E_UNEXPECTED, "got 0x%08lx.\n", hr);
617 ok(psi == (void*)0xdeadbeef, "got %p.\n", psi);
618 psi = (void*)0xdeadbeef;
619 hr = IFileSaveDialog_GetResult(pfsd, &psi);
620 ok(hr == E_UNEXPECTED, "got 0x%08lx.\n", hr);
621 ok(psi == (void*)0xdeadbeef, "got %p.\n", psi);
623 /* GetCurrentSelection */
624 if(0) {
625 /* Crashes on Vista/W2K8. Tests below passes on Windows 7 */
626 hr = IFileOpenDialog_GetCurrentSelection(pfod, NULL);
627 ok(hr == E_INVALIDARG, "got 0x%08lx.\n", hr);
628 hr = IFileSaveDialog_GetCurrentSelection(pfsd, NULL);
629 ok(hr == E_INVALIDARG, "got 0x%08lx.\n", hr);
630 hr = IFileOpenDialog_GetCurrentSelection(pfod, &psi);
631 ok(hr == E_FAIL, "got 0x%08lx.\n", hr);
632 hr = IFileSaveDialog_GetCurrentSelection(pfsd, &psi);
633 ok(hr == E_FAIL, "got 0x%08lx.\n", hr);
636 /* GetFileName */
637 hr = IFileOpenDialog_GetFileName(pfod, NULL);
638 ok(hr == E_INVALIDARG, "got 0x%08lx.\n", hr);
639 filename = (void*)0xdeadbeef;
640 hr = IFileOpenDialog_GetFileName(pfod, &filename);
641 ok(hr == E_FAIL, "got 0x%08lx.\n", hr);
642 ok(filename == NULL, "got %p\n", filename);
643 hr = IFileSaveDialog_GetFileName(pfsd, NULL);
644 ok(hr == E_INVALIDARG, "got 0x%08lx.\n", hr);
645 filename = (void*)0xdeadbeef;
646 hr = IFileSaveDialog_GetFileName(pfsd, &filename);
647 ok(hr == E_FAIL, "got 0x%08lx.\n", hr);
648 ok(filename == NULL, "got %p\n", filename);
650 /* GetFileTypeIndex */
651 hr = IFileOpenDialog_GetFileTypeIndex(pfod, NULL);
652 ok(hr == E_INVALIDARG, "got 0x%08lx.\n", hr);
653 filetype = 0x12345;
654 hr = IFileOpenDialog_GetFileTypeIndex(pfod, &filetype);
655 ok(hr == S_OK, "got 0x%08lx.\n", hr);
656 ok(filetype == 0, "got %d.\n", filetype);
657 hr = IFileSaveDialog_GetFileTypeIndex(pfsd, NULL);
658 ok(hr == E_INVALIDARG, "got 0x%08lx.\n", hr);
659 filetype = 0x12345;
660 hr = IFileSaveDialog_GetFileTypeIndex(pfsd, &filetype);
661 ok(hr == S_OK, "got 0x%08lx.\n", hr);
662 ok(filetype == 0, "got %d.\n", filetype);
664 /* SetFileTypes / SetFileTypeIndex */
665 hr = IFileOpenDialog_SetFileTypes(pfod, 0, NULL);
666 ok(hr == E_INVALIDARG, "got 0x%08lx.\n", hr);
667 hr = IFileOpenDialog_SetFileTypes(pfod, 0, filterspec);
668 ok(hr == S_OK, "got 0x%08lx.\n", hr);
670 hr = IFileOpenDialog_SetFileTypeIndex(pfod, 0);
671 ok(hr == E_FAIL, "got 0x%08lx.\n", hr);
672 hr = IFileOpenDialog_SetFileTypeIndex(pfod, 1);
673 ok(hr == E_FAIL, "got 0x%08lx.\n", hr);
674 hr = IFileOpenDialog_SetFileTypes(pfod, 1, filterspec);
675 ok(hr == S_OK, "got 0x%08lx.\n", hr);
676 hr = IFileOpenDialog_SetFileTypes(pfod, 0, filterspec);
677 ok(hr == E_UNEXPECTED, "got 0x%08lx.\n", hr);
678 hr = IFileOpenDialog_SetFileTypes(pfod, 0, NULL);
679 ok(hr == E_INVALIDARG, "got 0x%08lx.\n", hr);
680 hr = IFileOpenDialog_SetFileTypeIndex(pfod, 0);
681 ok(hr == S_OK, "got 0x%08lx.\n", hr);
682 hr = IFileOpenDialog_GetFileTypeIndex(pfod, &filetype);
683 ok(hr == S_OK, "got 0x%08lx.\n", hr);
684 ok(filetype == 1, "got %d\n", filetype);
685 hr = IFileOpenDialog_SetFileTypeIndex(pfod, 100);
686 ok(hr == S_OK, "got 0x%08lx.\n", hr);
687 hr = IFileOpenDialog_GetFileTypeIndex(pfod, &filetype);
688 ok(hr == S_OK, "got 0x%08lx.\n", hr);
689 ok(filetype == 1, "got %d\n", filetype);
690 hr = IFileOpenDialog_SetFileTypes(pfod, 1, filterspec);
691 ok(hr == E_UNEXPECTED, "got 0x%08lx.\n", hr);
692 hr = IFileOpenDialog_SetFileTypes(pfod, 1, &filterspec[1]);
693 ok(hr == E_UNEXPECTED, "got 0x%08lx.\n", hr);
695 hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 0);
696 ok(hr == E_FAIL, "got 0x%08lx.\n", hr);
697 hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 1);
698 ok(hr == E_FAIL, "got 0x%08lx.\n", hr);
699 hr = IFileSaveDialog_SetFileTypes(pfsd, 2, filterspec);
700 ok(hr == S_OK, "got 0x%08lx.\n", hr);
701 hr = IFileSaveDialog_GetFileTypeIndex(pfsd, &filetype);
702 ok(hr == S_OK, "got 0x%08lx.\n", hr);
703 /* I hope no one relies on this one */
704 todo_wine ok(filetype == 0, "got %d\n", filetype);
705 hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 0);
706 ok(hr == S_OK, "got 0x%08lx.\n", hr);
707 hr = IFileSaveDialog_GetFileTypeIndex(pfsd, &filetype);
708 ok(hr == S_OK, "got 0x%08lx.\n", hr);
709 ok(filetype == 1, "got %d\n", filetype);
710 hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 100);
711 ok(hr == S_OK, "got 0x%08lx.\n", hr);
712 hr = IFileSaveDialog_GetFileTypeIndex(pfsd, &filetype);
713 ok(hr == S_OK, "got 0x%08lx.\n", hr);
714 ok(filetype == 2, "got %d\n", filetype);
715 hr = IFileSaveDialog_SetFileTypes(pfsd, 1, filterspec);
716 ok(hr == E_UNEXPECTED, "got 0x%08lx.\n", hr);
717 hr = IFileSaveDialog_SetFileTypes(pfsd, 1, &filterspec[1]);
718 ok(hr == E_UNEXPECTED, "got 0x%08lx.\n", hr);
720 /* SetFilter */
721 todo_wine
723 hr = IFileOpenDialog_SetFilter(pfod, NULL);
724 ok(hr == S_OK, "got 0x%08lx.\n", hr);
725 hr = IFileSaveDialog_SetFilter(pfsd, NULL);
726 ok(hr == S_OK, "got 0x%08lx.\n", hr);
729 /* SetFolder */
730 hr = IFileOpenDialog_SetFolder(pfod, NULL);
731 ok(hr == S_OK, "got 0x%08lx.\n", hr);
732 hr = IFileSaveDialog_SetFolder(pfsd, NULL);
733 ok(hr == S_OK, "got 0x%08lx.\n", hr);
735 /* SetDefaultExtension */
736 hr = IFileOpenDialog_SetDefaultExtension(pfod, NULL);
737 ok(hr == S_OK, "got 0x%08lx.\n", hr);
738 hr = IFileOpenDialog_SetDefaultExtension(pfod, txt);
739 ok(hr == S_OK, "got 0x%08lx.\n", hr);
740 hr = IFileOpenDialog_SetDefaultExtension(pfod, null);
741 ok(hr == S_OK, "got 0x%08lx.\n", hr);
743 hr = IFileSaveDialog_SetDefaultExtension(pfsd, NULL);
744 ok(hr == S_OK, "got 0x%08lx.\n", hr);
745 hr = IFileSaveDialog_SetDefaultExtension(pfsd, txt);
746 ok(hr == S_OK, "got 0x%08lx.\n", hr);
747 hr = IFileSaveDialog_SetDefaultExtension(pfsd, null);
748 ok(hr == S_OK, "got 0x%08lx.\n", hr);
750 /* SetDefaultFolder */
751 hr = IFileOpenDialog_SetDefaultFolder(pfod, NULL);
752 ok(hr == S_OK, "got 0x%08lx\n", hr);
753 hr = IFileSaveDialog_SetDefaultFolder(pfsd, NULL);
754 ok(hr == S_OK, "got 0x%08lx\n", hr);
756 hr = IFileOpenDialog_SetDefaultFolder(pfod, psidesktop);
757 ok(hr == S_OK, "got 0x%08lx\n", hr);
758 hr = IFileSaveDialog_SetDefaultFolder(pfsd, psidesktop);
759 ok(hr == S_OK, "got 0x%08lx\n", hr);
761 if(0)
763 /* Crashes under Windows 7 */
764 IFileOpenDialog_SetDefaultFolder(pfod, (void*)0x1234);
765 IFileSaveDialog_SetDefaultFolder(pfsd, (void*)0x1234);
768 /* GetFolder / SetFolder */
769 hr = IFileOpenDialog_GetFolder(pfod, NULL);
770 ok(hr == E_INVALIDARG, "got 0x%08lx.\n", hr);
772 hr = IFileOpenDialog_GetFolder(pfod, &psi_original);
773 ok(hr == S_OK, "got 0x%08lx.\n", hr);
774 if(SUCCEEDED(hr))
776 hr = IFileOpenDialog_SetFolder(pfod, psidesktop);
777 ok(hr == S_OK, "got 0x%08lx.\n", hr);
778 hr = IFileOpenDialog_SetFolder(pfod, psi_original);
779 ok(hr == S_OK, "got 0x%08lx.\n", hr);
780 IShellItem_Release(psi_original);
783 hr = IFileSaveDialog_GetFolder(pfsd, &psi_original);
784 ok(hr == S_OK, "got 0x%08lx.\n", hr);
785 if(SUCCEEDED(hr))
787 hr = IFileSaveDialog_SetFolder(pfsd, psidesktop);
788 ok(hr == S_OK, "got 0x%08lx.\n", hr);
789 hr = IFileSaveDialog_SetFolder(pfsd, psi_original);
790 ok(hr == S_OK, "got 0x%08lx.\n", hr);
791 IShellItem_Release(psi_original);
794 /* AddPlace */
795 if(0)
797 /* Crashes under Windows 7 */
798 IFileOpenDialog_AddPlace(pfod, NULL, 0);
799 IFileSaveDialog_AddPlace(pfsd, NULL, 0);
802 hr = IFileOpenDialog_AddPlace(pfod, psidesktop, FDAP_TOP + 1);
803 todo_wine ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
804 hr = IFileOpenDialog_AddPlace(pfod, psidesktop, FDAP_BOTTOM);
805 ok(hr == S_OK, "got 0x%08lx\n", hr);
806 hr = IFileOpenDialog_AddPlace(pfod, psidesktop, FDAP_TOP);
807 ok(hr == S_OK, "got 0x%08lx\n", hr);
809 hr = IFileSaveDialog_AddPlace(pfsd, psidesktop, FDAP_TOP + 1);
810 todo_wine ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
811 hr = IFileSaveDialog_AddPlace(pfsd, psidesktop, FDAP_BOTTOM);
812 ok(hr == S_OK, "got 0x%08lx\n", hr);
813 hr = IFileSaveDialog_AddPlace(pfsd, psidesktop, FDAP_TOP);
814 ok(hr == S_OK, "got 0x%08lx\n", hr);
816 /* SetFileName */
817 hr = IFileOpenDialog_SetFileName(pfod, NULL);
818 ok(hr == S_OK, "got 0x%08lx\n", hr);
819 hr = IFileOpenDialog_SetFileName(pfod, null);
820 ok(hr == S_OK, "got 0x%08lx\n", hr);
822 filename = NULL;
823 hr = IFileOpenDialog_GetFileName(pfod, &filename);
824 ok(hr == S_OK, "Got 0x%08lx\n", hr);
825 ok(!lstrcmpW(filename, null), "Strings do not match.\n");
826 CoTaskMemFree(filename);
828 hr = IFileOpenDialog_SetFileName(pfod, NULL);
829 ok(hr == S_OK, "got 0x%08lx\n", hr);
831 filename = (void*)0xdeadbeef;
832 hr = IFileOpenDialog_GetFileName(pfod, &filename);
833 ok(hr == E_FAIL, "Got 0x%08lx\n", hr);
834 ok(filename == NULL, "got %p.\n", filename);
836 hr = IFileOpenDialog_SetFileName(pfod, txt);
837 ok(hr == S_OK, "got 0x%08lx\n", hr);
838 hr = IFileOpenDialog_GetFileName(pfod, &filename);
839 ok(hr == S_OK, "Got 0x%08lx\n", hr);
840 ok(!lstrcmpW(filename, txt), "Strings do not match.\n");
841 CoTaskMemFree(filename);
843 hr = IFileSaveDialog_SetFileName(pfsd, NULL);
844 ok(hr == S_OK, "got 0x%08lx\n", hr);
845 hr = IFileSaveDialog_SetFileName(pfsd, null);
846 ok(hr == S_OK, "got 0x%08lx\n", hr);
847 hr = IFileSaveDialog_SetFileName(pfsd, txt);
848 ok(hr == S_OK, "got 0x%08lx\n", hr);
849 hr = IFileSaveDialog_GetFileName(pfsd, &filename);
850 ok(hr == S_OK, "Got 0x%08lx\n", hr);
851 ok(!lstrcmpW(filename, txt), "Strings do not match.\n");
852 CoTaskMemFree(filename);
854 /* SetFileNameLabel */
855 hr = IFileOpenDialog_SetFileNameLabel(pfod, NULL);
856 ok(hr == S_OK, "got 0x%08lx\n", hr);
857 hr = IFileOpenDialog_SetFileNameLabel(pfod, null);
858 ok(hr == S_OK, "got 0x%08lx\n", hr);
859 hr = IFileOpenDialog_SetFileNameLabel(pfod, txt);
860 ok(hr == S_OK, "got 0x%08lx\n", hr);
862 hr = IFileSaveDialog_SetFileNameLabel(pfsd, NULL);
863 ok(hr == S_OK, "got 0x%08lx\n", hr);
864 hr = IFileSaveDialog_SetFileNameLabel(pfsd, null);
865 ok(hr == S_OK, "got 0x%08lx\n", hr);
866 hr = IFileSaveDialog_SetFileNameLabel(pfsd, txt);
867 ok(hr == S_OK, "got 0x%08lx\n", hr);
869 /* Close */
870 hr = IFileOpenDialog_Close(pfod, S_FALSE);
871 ok(hr == S_OK, "got 0x%08lx\n", hr);
872 hr = IFileSaveDialog_Close(pfsd, S_FALSE);
873 ok(hr == S_OK, "got 0x%08lx\n", hr);
875 /* SetOkButtonLabel */
876 hr = IFileOpenDialog_SetOkButtonLabel(pfod, NULL);
877 ok(hr == S_OK, "got 0x%08lx\n", hr);
878 hr = IFileOpenDialog_SetOkButtonLabel(pfod, null);
879 ok(hr == S_OK, "got 0x%08lx\n", hr);
880 hr = IFileOpenDialog_SetOkButtonLabel(pfod, txt);
881 ok(hr == S_OK, "got 0x%08lx\n", hr);
882 hr = IFileSaveDialog_SetOkButtonLabel(pfsd, NULL);
883 ok(hr == S_OK, "got 0x%08lx\n", hr);
884 hr = IFileSaveDialog_SetOkButtonLabel(pfsd, null);
885 ok(hr == S_OK, "got 0x%08lx\n", hr);
886 hr = IFileSaveDialog_SetOkButtonLabel(pfsd, txt);
887 ok(hr == S_OK, "got 0x%08lx\n", hr);
889 /* SetTitle */
890 hr = IFileOpenDialog_SetTitle(pfod, NULL);
891 ok(hr == S_OK, "got 0x%08lx\n", hr);
892 hr = IFileOpenDialog_SetTitle(pfod, null);
893 ok(hr == S_OK, "got 0x%08lx\n", hr);
894 hr = IFileOpenDialog_SetTitle(pfod, txt);
895 ok(hr == S_OK, "got 0x%08lx\n", hr);
896 hr = IFileSaveDialog_SetTitle(pfsd, NULL);
897 ok(hr == S_OK, "got 0x%08lx\n", hr);
898 hr = IFileSaveDialog_SetTitle(pfsd, null);
899 ok(hr == S_OK, "got 0x%08lx\n", hr);
900 hr = IFileSaveDialog_SetTitle(pfsd, txt);
901 ok(hr == S_OK, "got 0x%08lx\n", hr);
903 /** IFileOpenDialog specific **/
905 /* GetResults */
906 if(0)
908 /* Crashes under Windows 7 */
909 IFileOpenDialog_GetResults(pfod, NULL);
911 psia = (void*)0xdeadbeef;
912 hr = IFileOpenDialog_GetResults(pfod, &psia);
913 ok(hr == E_FAIL, "got 0x%08lx.\n", hr);
914 ok(psia == NULL, "got %p.\n", psia);
916 /* GetSelectedItems */
917 if(0)
919 /* Crashes under W2K8 */
920 hr = IFileOpenDialog_GetSelectedItems(pfod, NULL);
921 ok(hr == E_FAIL, "got 0x%08lx.\n", hr);
922 psia = (void*)0xdeadbeef;
923 hr = IFileOpenDialog_GetSelectedItems(pfod, &psia);
924 ok(hr == E_FAIL, "got 0x%08lx.\n", hr);
925 ok(psia == (void*)0xdeadbeef, "got %p.\n", psia);
928 /** IFileSaveDialog specific **/
930 /* ApplyProperties */
931 if(0)
933 /* Crashes under windows 7 */
934 IFileSaveDialog_ApplyProperties(pfsd, NULL, NULL, NULL, NULL);
935 IFileSaveDialog_ApplyProperties(pfsd, psidesktop, NULL, NULL, NULL);
938 /* GetProperties */
939 hr = IFileSaveDialog_GetProperties(pfsd, NULL);
940 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08lx\n", hr);
941 pps = (void*)0xdeadbeef;
942 hr = IFileSaveDialog_GetProperties(pfsd, &pps);
943 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08lx\n", hr);
944 ok(pps == (void*)0xdeadbeef, "got %p\n", pps);
946 /* SetProperties */
947 if(0)
949 /* Crashes under W2K8 */
950 hr = IFileSaveDialog_SetProperties(pfsd, NULL);
951 ok(hr == S_OK, "got 0x%08lx\n", hr);
954 /* SetCollectedProperties */
955 todo_wine
957 hr = IFileSaveDialog_SetCollectedProperties(pfsd, NULL, TRUE);
958 ok(hr == S_OK, "got 0x%08lx\n", hr);
959 hr = IFileSaveDialog_SetCollectedProperties(pfsd, NULL, FALSE);
960 ok(hr == S_OK, "got 0x%08lx\n", hr);
963 /* SetSaveAsItem */
964 todo_wine
966 hr = IFileSaveDialog_SetSaveAsItem(pfsd, NULL);
967 ok(hr == S_OK, "got 0x%08lx\n", hr);
968 hr = IFileSaveDialog_SetSaveAsItem(pfsd, psidesktop);
969 ok(hr == MK_E_NOOBJECT, "got 0x%08lx\n", hr);
972 /** IFileDialog2 **/
974 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialog2, (void**)&pfd2);
975 ok((hr == S_OK) || broken(hr == E_NOINTERFACE), "got 0x%08lx\n", hr);
976 if(SUCCEEDED(hr))
978 /* SetCancelButtonLabel */
979 hr = IFileDialog2_SetOkButtonLabel(pfd2, NULL);
980 ok(hr == S_OK, "got 0x%08lx\n", hr);
981 hr = IFileDialog2_SetOkButtonLabel(pfd2, null);
982 ok(hr == S_OK, "got 0x%08lx\n", hr);
983 hr = IFileDialog2_SetOkButtonLabel(pfd2, txt);
984 ok(hr == S_OK, "got 0x%08lx\n", hr);
986 /* SetNavigationRoot */
987 todo_wine
989 hr = IFileDialog2_SetNavigationRoot(pfd2, NULL);
990 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
991 hr = IFileDialog2_SetNavigationRoot(pfd2, psidesktop);
992 ok(hr == S_OK, "got 0x%08lx\n", hr);
995 IFileDialog2_Release(pfd2);
998 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialog2, (void**)&pfd2);
999 ok((hr == S_OK) || broken(hr == E_NOINTERFACE), "got 0x%08lx\n", hr);
1000 if(SUCCEEDED(hr))
1002 /* SetCancelButtonLabel */
1003 hr = IFileDialog2_SetOkButtonLabel(pfd2, NULL);
1004 ok(hr == S_OK, "got 0x%08lx\n", hr);
1005 hr = IFileDialog2_SetOkButtonLabel(pfd2, null);
1006 ok(hr == S_OK, "got 0x%08lx\n", hr);
1007 hr = IFileDialog2_SetOkButtonLabel(pfd2, txt);
1008 ok(hr == S_OK, "got 0x%08lx\n", hr);
1010 /* SetNavigationRoot */
1011 todo_wine
1013 hr = IFileDialog2_SetNavigationRoot(pfd2, NULL);
1014 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
1015 hr = IFileDialog2_SetNavigationRoot(pfd2, psidesktop);
1016 ok(hr == S_OK, "got 0x%08lx\n", hr);
1019 IFileDialog2_Release(pfd2);
1022 /* Cleanup */
1023 IShellItem_Release(psidesktop);
1024 ref = IFileOpenDialog_Release(pfod);
1025 ok(!ref, "Got refcount %ld, should have been released.\n", ref);
1026 ref = IFileSaveDialog_Release(pfsd);
1027 ok(!ref, "Got refcount %ld, should have been released.\n", ref);
1030 static void ensure_zero_events_(const char *file, int line, IFileDialogEventsImpl *impl)
1032 ok_(file, line)(!impl->OnFileOk, "OnFileOk: %ld\n", impl->OnFileOk);
1033 ok_(file, line)(!impl->OnFolderChanging, "OnFolderChanging: %ld\n", impl->OnFolderChanging);
1034 ok_(file, line)(!impl->OnFolderChange, "OnFolderChange: %ld\n", impl->OnFolderChange);
1035 ok_(file, line)(!impl->OnSelectionChange, "OnSelectionChange: %ld\n", impl->OnSelectionChange);
1036 ok_(file, line)(!impl->OnShareViolation, "OnShareViolation: %ld\n", impl->OnShareViolation);
1037 ok_(file, line)(!impl->OnTypeChange, "OnTypeChange: %ld\n", impl->OnTypeChange);
1038 ok_(file, line)(!impl->OnOverwrite, "OnOverwrite: %ld\n", impl->OnOverwrite);
1039 impl->OnFileOk = impl->OnFolderChanging = impl->OnFolderChange = 0;
1040 impl->OnSelectionChange = impl->OnShareViolation = impl->OnTypeChange = 0;
1041 impl->OnOverwrite = 0;
1043 #define ensure_zero_events(impl) ensure_zero_events_(__FILE__, __LINE__, impl)
1045 static void test_advise_helper(IFileDialog *pfd)
1047 IFileDialogEventsImpl *pfdeimpl;
1048 IFileDialogEvents *pfde;
1049 DWORD cookie[10];
1050 UINT i;
1051 HRESULT hr;
1053 pfde = IFileDialogEvents_Constructor();
1054 pfdeimpl = impl_from_IFileDialogEvents(pfde);
1056 /* Null pointer tests crash on Windows 10 16299 or newer */
1057 if (0)
1059 hr = IFileDialog_Advise(pfd, NULL, NULL);
1060 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
1061 hr = IFileDialog_Advise(pfd, pfde, NULL);
1062 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
1064 hr = IFileDialog_Advise(pfd, NULL, &cookie[0]);
1065 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
1066 ok(pfdeimpl->ref == 1, "got ref %ld\n", pfdeimpl->ref);
1067 ensure_zero_events(pfdeimpl);
1069 hr = IFileDialog_Unadvise(pfd, 0);
1070 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
1071 for(i = 0; i < 10; i++) {
1072 hr = IFileDialog_Advise(pfd, pfde, &cookie[i]);
1073 ok(hr == S_OK, "got 0x%08lx\n", hr);
1074 ok(cookie[i] == i+cookie[0], "Got cookie: %ld\n", cookie[i]);
1076 ok(pfdeimpl->ref == 10+1, "got ref %ld\n", pfdeimpl->ref);
1077 ensure_zero_events(pfdeimpl);
1079 for(i = 3; i < 7; i++) {
1080 hr = IFileDialog_Unadvise(pfd, cookie[i]);
1081 ok(hr == S_OK, "got 0x%08lx\n", hr);
1083 ok(pfdeimpl->ref == 6+1, "got ref %ld\n", pfdeimpl->ref);
1084 ensure_zero_events(pfdeimpl);
1086 for(i = 0; i < 3; i++) {
1087 hr = IFileDialog_Unadvise(pfd, cookie[i]);
1088 ok(hr == S_OK, "got 0x%08lx\n", hr);
1090 ok(pfdeimpl->ref == 3+1, "got ref %ld\n", pfdeimpl->ref);
1091 ensure_zero_events(pfdeimpl);
1093 for(i = 7; i < 10; i++) {
1094 hr = IFileDialog_Unadvise(pfd, cookie[i]);
1095 ok(hr == S_OK, "got 0x%08lx\n", hr);
1097 ok(pfdeimpl->ref == 1, "got ref %ld\n", pfdeimpl->ref);
1098 ensure_zero_events(pfdeimpl);
1100 hr = IFileDialog_Unadvise(pfd, cookie[9]+1);
1101 ok(hr == E_INVALIDARG, "got 0x%08lx\n", hr);
1102 ok(pfdeimpl->ref == 1, "got ref %ld\n", pfdeimpl->ref);
1103 ensure_zero_events(pfdeimpl);
1105 hr = IFileDialog_Advise(pfd, pfde, &cookie[0]);
1106 ok(hr == S_OK, "got 0x%08lx\n", hr);
1107 ok(cookie[0] >= 1, "got cookie: %ld\n", cookie[0]);
1108 ok(pfdeimpl->ref == 1+1, "got ref %ld\n", pfdeimpl->ref);
1109 ensure_zero_events(pfdeimpl);
1111 hr = IFileDialog_Unadvise(pfd, cookie[0]);
1113 if(0)
1115 /* Unadvising already unadvised cookies crashes on
1116 Windows 7. */
1117 IFileDialog_Unadvise(pfd, cookie[0]);
1121 IFileDialogEvents_Release(pfde);
1124 static void test_advise(void)
1126 IFileDialog *pfd;
1127 HRESULT hr;
1128 LONG ref;
1130 trace("Testing FileOpenDialog (advise)\n");
1131 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
1132 &IID_IFileDialog, (void**)&pfd);
1133 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1134 test_advise_helper(pfd);
1135 ref = IFileDialog_Release(pfd);
1136 ok(!ref, "Got refcount %ld, should have been released.\n", ref);
1138 trace("Testing FileSaveDialog (advise)\n");
1139 hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER,
1140 &IID_IFileDialog, (void**)&pfd);
1141 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1142 test_advise_helper(pfd);
1143 ref = IFileDialog_Release(pfd);
1144 ok(!ref, "Got refcount %ld, should have been released.\n", ref);
1147 static void filedialog_change_filetype(IFileDialog *pfd, HWND dlg_hwnd)
1149 HWND cb_filetype;
1150 const WCHAR filetype1[] = {'f','n','a','m','e','1',0};
1151 const WCHAR filetype1_broken[] = {'f','n','a','m','e','1',' ', '(','*','.','t','x','t',')',0};
1153 cb_filetype = find_window(dlg_hwnd, NULL, filetype1);
1154 ok(cb_filetype != NULL || broken(cb_filetype == NULL), "Could not find combobox on first attempt\n");
1156 if(!cb_filetype)
1158 /* Not sure when this happens. Some specific version?
1159 * Seen on 32-bit English Vista */
1160 trace("Didn't find combobox on first attempt, trying broken string..\n");
1161 cb_filetype = find_window(dlg_hwnd, NULL, filetype1_broken);
1162 ok(broken(cb_filetype != NULL), "Failed to find combobox on second attempt\n");
1163 if(!cb_filetype)
1164 return;
1167 /* Making the combobox send a CBN_SELCHANGE */
1168 SendMessageW( cb_filetype, CB_SHOWDROPDOWN, 1, 0 );
1169 SendMessageW( cb_filetype, CB_SETCURSEL, 1, 0 );
1170 SendMessageW( cb_filetype, WM_LBUTTONDOWN, 0, -1 );
1171 SendMessageW( cb_filetype, WM_LBUTTONUP, 0, -1 );
1174 static void test_events(void)
1176 IFileDialog *pfd;
1177 IFileDialogEventsImpl *pfdeimpl;
1178 IFileDialogEvents *pfde;
1179 DWORD cookie;
1180 ULONG ref;
1181 HRESULT hr;
1182 const WCHAR fname1[] = {'f','n','a','m','e','1', 0};
1183 const WCHAR fspec1[] = {'*','.','t','x','t',0};
1184 const WCHAR fname2[] = {'f','n','a','m','e','2', 0};
1185 const WCHAR fspec2[] = {'*','.','e','x','e',0};
1186 COMDLG_FILTERSPEC filterspec[3] = {{fname1, fspec1}, {fname2, fspec2}};
1190 * 1. Show the dialog with no filetypes added
1192 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
1193 &IID_IFileDialog, (void**)&pfd);
1194 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1196 pfde = IFileDialogEvents_Constructor();
1197 pfdeimpl = impl_from_IFileDialogEvents(pfde);
1198 pfdeimpl->events_test = IFDEVENT_TEST2;
1200 hr = IFileDialog_Advise(pfd, pfde, &cookie);
1201 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1203 hr = IFileDialog_Show(pfd, NULL);
1204 ok(hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "got 0x%08lx.\n", hr);
1206 ok(pfdeimpl->OnFolderChanging == 1, "Got %ld\n", pfdeimpl->OnFolderChanging);
1207 pfdeimpl->OnFolderChanging = 0;
1208 ok(pfdeimpl->OnFolderChange == 1, "Got %ld\n", pfdeimpl->OnFolderChange);
1209 pfdeimpl->OnFolderChange = 0;
1210 /* pfdeimpl->OnSelectionChange too unreliable to test. Can be 0, 1 or even 2. */
1211 pfdeimpl->OnSelectionChange = 0;
1212 ok(pfdeimpl->OnTypeChange == 0, "Got %ld\n", pfdeimpl->OnTypeChange);
1213 pfdeimpl->OnTypeChange = 0;
1215 ensure_zero_events(pfdeimpl);
1217 hr = IFileDialog_Unadvise(pfd, cookie);
1218 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1220 IFileDialogEvents_Release(pfde);
1221 ref = IFileDialog_Release(pfd);
1222 ok(!ref || broken(ref /* win2008_64 (intermittently) */), "Got %ld\n", ref);
1226 * 2. Show the dialog with filetypes added
1228 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
1229 &IID_IFileDialog, (void**)&pfd);
1230 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1232 pfde = IFileDialogEvents_Constructor();
1233 pfdeimpl = impl_from_IFileDialogEvents(pfde);
1234 pfdeimpl->events_test = IFDEVENT_TEST2;
1236 hr = IFileDialog_Advise(pfd, pfde, &cookie);
1237 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1239 hr = IFileDialog_SetFileTypes(pfd, 2, filterspec);
1240 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1242 ensure_zero_events(pfdeimpl);
1244 hr = IFileDialog_Show(pfd, NULL);
1245 ok(hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "got 0x%08lx.\n", hr);
1247 ok(pfdeimpl->OnFolderChanging == 1, "Got %ld\n", pfdeimpl->OnFolderChanging);
1248 pfdeimpl->OnFolderChanging = 0;
1249 ok(pfdeimpl->OnFolderChange == 1, "Got %ld\n", pfdeimpl->OnFolderChange);
1250 pfdeimpl->OnFolderChange = 0;
1251 /* pfdeimpl->OnSelectionChange too unreliable to test. Can be 0, 1 or even 2. */
1252 pfdeimpl->OnSelectionChange = 0;
1253 /* Called once just by showing the dialog */
1254 ok(pfdeimpl->OnTypeChange == 1, "Got %ld\n", pfdeimpl->OnTypeChange);
1255 pfdeimpl->OnTypeChange = 0;
1257 ensure_zero_events(pfdeimpl);
1259 hr = IFileDialog_Unadvise(pfd, cookie);
1260 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1262 IFileDialogEvents_Release(pfde);
1263 ref = IFileDialog_Release(pfd);
1264 ok(!ref || broken(ref /* win2008_64 (intermittently) */), "Got %ld\n", ref);
1268 * 3. Show the dialog with filetypes added and simulate manual change of filetype
1270 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
1271 &IID_IFileDialog, (void**)&pfd);
1272 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1274 pfde = IFileDialogEvents_Constructor();
1275 pfdeimpl = impl_from_IFileDialogEvents(pfde);
1276 pfdeimpl->events_test = IFDEVENT_TEST3;
1278 hr = IFileDialog_Advise(pfd, pfde, &cookie);
1279 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1281 hr = IFileDialog_SetFileTypes(pfd, 2, filterspec);
1282 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1284 ensure_zero_events(pfdeimpl);
1286 hr = IFileDialog_Show(pfd, NULL);
1287 ok(hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "got 0x%08lx.\n", hr);
1289 ok(pfdeimpl->OnFolderChanging == 1, "Got %ld\n", pfdeimpl->OnFolderChanging);
1290 pfdeimpl->OnFolderChanging = 0;
1291 ok(pfdeimpl->OnFolderChange == 1, "Got %ld\n", pfdeimpl->OnFolderChange);
1292 pfdeimpl->OnFolderChange = 0;
1293 /* pfdeimpl->OnSelectionChange too unreliable to test. Can be 0, 1 or even 2. */
1294 pfdeimpl->OnSelectionChange = 0;
1295 /* Called once by showing the dialog and once again when changing the filetype */
1296 todo_wine ok(pfdeimpl->OnTypeChange == 2, "Got %ld\n", pfdeimpl->OnTypeChange);
1297 pfdeimpl->OnTypeChange = 0;
1299 ensure_zero_events(pfdeimpl);
1301 hr = IFileDialog_Unadvise(pfd, cookie);
1302 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1304 IFileDialogEvents_Release(pfde);
1305 ref = IFileDialog_Release(pfd);
1306 ok(!ref || broken(ref /* win2008_64 (intermittently) */), "Got %ld\n", ref);
1309 static void touch_file(LPCWSTR filename)
1311 HANDLE file;
1312 file = CreateFileW(filename, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
1313 ok(file != INVALID_HANDLE_VALUE, "Failed to create file.\n");
1314 CloseHandle(file);
1317 static void test_filename_savedlg_(LPCWSTR set_filename, LPCWSTR defext,
1318 const COMDLG_FILTERSPEC *filterspec, UINT fs_count,
1319 LPCWSTR exp_filename, const char *file, int line)
1321 IFileSaveDialog *pfsd;
1322 IFileDialogEventsImpl *pfdeimpl;
1323 IFileDialogEvents *pfde;
1324 DWORD cookie;
1325 LPWSTR filename;
1326 IShellItem *psi;
1327 LONG ref;
1328 HRESULT hr;
1330 hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER,
1331 &IID_IFileSaveDialog, (void**)&pfsd);
1332 ok_(file,line)(hr == S_OK, "Got 0x%08lx\n", hr);
1334 if(fs_count)
1336 hr = IFileSaveDialog_SetFileTypes(pfsd, fs_count, filterspec);
1337 ok_(file,line)(hr == S_OK, "SetFileTypes failed: Got 0x%08lx\n", hr);
1340 if(defext)
1342 hr = IFileSaveDialog_SetDefaultExtension(pfsd, defext);
1343 ok_(file,line)(hr == S_OK, "SetDefaultExtensions failed: Got 0x%08lx\n", hr);
1346 pfde = IFileDialogEvents_Constructor();
1347 pfdeimpl = impl_from_IFileDialogEvents(pfde);
1348 pfdeimpl->set_filename = set_filename;
1349 hr = IFileSaveDialog_Advise(pfsd, pfde, &cookie);
1350 ok_(file,line)(hr == S_OK, "Advise failed: Got 0x%08lx\n", hr);
1352 hr = IFileSaveDialog_Show(pfsd, NULL);
1353 ok_(file,line)(hr == S_OK, "Show failed: Got 0x%08lx\n", hr);
1355 hr = IFileSaveDialog_GetFileName(pfsd, &filename);
1356 ok_(file,line)(hr == S_OK, "GetFileName failed: Got 0x%08lx\n", hr);
1357 ok_(file,line)(!lstrcmpW(filename, set_filename), "Got %s\n", wine_dbgstr_w(filename));
1358 CoTaskMemFree(filename);
1360 hr = IFileSaveDialog_GetResult(pfsd, &psi);
1361 ok_(file,line)(hr == S_OK, "GetResult failed: Got 0x%08lx\n", hr);
1363 hr = IShellItem_GetDisplayName(psi, SIGDN_PARENTRELATIVEPARSING, &filename);
1364 ok_(file,line)(hr == S_OK, "GetDisplayName failed: Got 0x%08lx\n", hr);
1365 ok_(file,line)(!lstrcmpW(filename, exp_filename), "(GetDisplayName) Got %s\n", wine_dbgstr_w(filename));
1366 CoTaskMemFree(filename);
1367 IShellItem_Release(psi);
1369 hr = IFileSaveDialog_Unadvise(pfsd, cookie);
1370 ok_(file,line)(hr == S_OK, "Unadvise failed: Got 0x%08lx\n", hr);
1372 ref = IFileSaveDialog_Release(pfsd);
1373 ok_(file,line)(!ref, "Got refcount %ld, should have been released.\n", ref);
1375 IFileDialogEvents_Release(pfde);
1377 #define test_filename_savedlg(set_filename, defext, filterspec, fs_count, exp_filename) \
1378 test_filename_savedlg_(set_filename, defext, filterspec, fs_count, exp_filename, __FILE__, __LINE__)
1380 static void test_filename_opendlg_(LPCWSTR set_filename, IShellItem *psi_current, LPCWSTR defext,
1381 const COMDLG_FILTERSPEC *filterspec, UINT fs_count,
1382 LPCWSTR exp_filename, const char *file, int line)
1384 IFileOpenDialog *pfod;
1385 IFileDialogEventsImpl *pfdeimpl;
1386 IFileDialogEvents *pfde;
1387 DWORD cookie;
1388 LPWSTR filename;
1389 IShellItemArray *psia;
1390 IShellItem *psi;
1391 LONG ref;
1392 HRESULT hr;
1394 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
1395 &IID_IFileOpenDialog, (void**)&pfod);
1396 ok_(file,line)(hr == S_OK, "CoCreateInstance failed: Got 0x%08lx\n", hr);
1398 if(defext)
1400 hr = IFileOpenDialog_SetDefaultExtension(pfod, defext);
1401 ok_(file,line)(hr == S_OK, "SetDefaultExtensions failed: Got 0x%08lx\n", hr);
1404 if(fs_count)
1406 hr = IFileOpenDialog_SetFileTypes(pfod, 2, filterspec);
1407 ok_(file,line)(hr == S_OK, "SetFileTypes failed: Got 0x%08lx\n", hr);
1410 hr = IFileOpenDialog_SetFolder(pfod, psi_current);
1411 ok_(file,line)(hr == S_OK, "SetFolder failed: Got 0x%08lx\n", hr);
1413 pfde = IFileDialogEvents_Constructor();
1414 pfdeimpl = impl_from_IFileDialogEvents(pfde);
1415 pfdeimpl->set_filename = set_filename;
1416 pfdeimpl->set_filename_tried = FALSE;
1417 hr = IFileOpenDialog_Advise(pfod, pfde, &cookie);
1418 ok_(file,line)(hr == S_OK, "Advise failed: Got 0x%08lx\n", hr);
1420 hr = IFileOpenDialog_Show(pfod, NULL);
1421 ok_(file,line)(hr == S_OK || (!exp_filename && hr == HRESULT_FROM_WIN32(ERROR_CANCELLED)),
1422 "Show failed: Got 0x%08lx\n", hr);
1423 if(hr == S_OK)
1425 hr = IFileOpenDialog_GetResult(pfod, &psi);
1426 ok_(file,line)(hr == S_OK, "GetResult failed: Got 0x%08lx\n", hr);
1428 hr = IShellItem_GetDisplayName(psi, SIGDN_PARENTRELATIVEPARSING, &filename);
1429 ok_(file,line)(hr == S_OK, "GetDisplayName(Result) failed: Got 0x%08lx\n", hr);
1430 ok_(file,line)(!lstrcmpW(filename, exp_filename), "(GetResult) Got %s\n", wine_dbgstr_w(filename));
1431 CoTaskMemFree(filename);
1432 IShellItem_Release(psi);
1434 hr = IFileOpenDialog_GetResults(pfod, &psia);
1435 ok_(file,line)(hr == S_OK, "GetResults failed: Got 0x%08lx\n", hr);
1436 hr = IShellItemArray_GetItemAt(psia, 0, &psi);
1437 ok_(file,line)(hr == S_OK, "GetItemAt failed: Got 0x%08lx\n", hr);
1439 hr = IShellItem_GetDisplayName(psi, SIGDN_PARENTRELATIVEPARSING, &filename);
1440 ok_(file,line)(hr == S_OK, "GetDisplayName(Results) failed: Got 0x%08lx\n", hr);
1441 ok_(file,line)(!lstrcmpW(filename, exp_filename), "(GetResults) Got %s\n", wine_dbgstr_w(filename));
1442 CoTaskMemFree(filename);
1444 IShellItem_Release(psi);
1445 IShellItemArray_Release(psia);
1447 else
1449 hr = IFileOpenDialog_GetResult(pfod, &psi);
1450 ok_(file,line)(hr == E_UNEXPECTED, "GetResult: Got 0x%08lx\n", hr);
1452 hr = IFileOpenDialog_GetResults(pfod, &psia);
1453 ok_(file,line)(hr == E_FAIL, "GetResults: Got 0x%08lx\n", hr);
1456 hr = IFileOpenDialog_GetFileName(pfod, &filename);
1457 ok_(file,line)(hr == S_OK, "GetFileName failed: Got 0x%08lx\n", hr);
1458 ok_(file,line)(!lstrcmpW(filename, set_filename), "(GetFileName) Got %s\n", wine_dbgstr_w(filename));
1459 CoTaskMemFree(filename);
1462 hr = IFileOpenDialog_Unadvise(pfod, cookie);
1463 ok_(file,line)(hr == S_OK, "Unadvise failed: Got 0x%08lx\n", hr);
1465 ref = IFileOpenDialog_Release(pfod);
1466 ok_(file,line)(!ref, "Got refcount %ld, should have been released.\n", ref);
1468 IFileDialogEvents_Release(pfde);
1470 #define test_filename_opendlg(set_filename, psi, defext, filterspec, fs_count, exp_filename) \
1471 test_filename_opendlg_(set_filename, psi, defext, filterspec, fs_count, exp_filename, __FILE__, __LINE__)
1473 static void test_filename(void)
1475 IShellItem *psi_current;
1476 HRESULT hr;
1477 WCHAR buf[MAX_PATH];
1479 static const WCHAR filename_noextW[] = {'w','i','n','e','t','e','s','t',0};
1480 static const WCHAR filename_dotextW[] = {'w','i','n','e','t','e','s','t','.',0};
1481 static const WCHAR filename_dotanddefW[] = {'w','i','n','e','t','e','s','t','.','.','w','t','e',0};
1482 static const WCHAR filename_defextW[] = {'w','i','n','e','t','e','s','t','.','w','t','e',0};
1483 static const WCHAR filename_ext1W[] = {'w','i','n','e','t','e','s','t','.','w','t','1',0};
1484 static const WCHAR filename_ext2W[] = {'w','i','n','e','t','e','s','t','.','w','t','2',0};
1485 static const WCHAR filename_ext1anddefW[] =
1486 {'w','i','n','e','t','e','s','t','.','w','t','1','.','w','t','e',0};
1487 static const WCHAR defextW[] = {'w','t','e',0};
1488 static const WCHAR desc1[] = {'d','e','s','c','r','i','p','t','i','o','n','1',0};
1489 static const WCHAR desc2[] = {'d','e','s','c','r','i','p','t','i','o','n','2',0};
1490 static const WCHAR descdef[] = {'d','e','f','a','u','l','t',' ','d','e','s','c',0};
1491 static const WCHAR ext1[] = {'*','.','w','t','1',0};
1492 static const WCHAR ext2[] = {'*','.','w','t','2',0};
1493 static const WCHAR extdef[] = {'*','.','w','t','e',0};
1494 static const WCHAR complexext[] = {'*','.','w','t','2',';','*','.','w','t','1',0};
1496 static const COMDLG_FILTERSPEC filterspec[] = {
1497 { desc1, ext1 }, { desc2, ext2 }, { descdef, extdef }
1499 static const COMDLG_FILTERSPEC filterspec2[] = {
1500 { desc1, complexext }
1503 /* No extension */
1504 test_filename_savedlg(filename_noextW, NULL, NULL, 0, filename_noextW);
1505 /* Default extension */
1506 test_filename_savedlg(filename_noextW, defextW, NULL, 0, filename_defextW);
1507 /* Default extension on filename ending with a . */
1508 test_filename_savedlg(filename_dotextW, defextW, NULL, 0, filename_dotanddefW);
1509 /* Default extension on filename with default extension */
1510 test_filename_savedlg(filename_defextW, defextW, NULL, 0, filename_defextW);
1511 /* Default extension on filename with another extension */
1512 test_filename_savedlg(filename_ext1W, defextW, NULL, 0, filename_ext1anddefW);
1513 /* Default extension, filterspec without default extension */
1514 test_filename_savedlg(filename_noextW, defextW, filterspec, 2, filename_ext1W);
1515 /* Default extension, filterspec with default extension */
1516 test_filename_savedlg(filename_noextW, defextW, filterspec, 3, filename_ext1W);
1517 /* Default extension, filterspec with "complex" extension */
1518 test_filename_savedlg(filename_noextW, defextW, filterspec2, 1, filename_ext2W);
1520 GetCurrentDirectoryW(MAX_PATH, buf);
1521 ok(!!pSHCreateItemFromParsingName, "SHCreateItemFromParsingName is missing.\n");
1522 hr = pSHCreateItemFromParsingName(buf, NULL, &IID_IShellItem, (void**)&psi_current);
1523 ok(hr == S_OK, "Got 0x%08lx\n", hr);
1525 touch_file(filename_noextW);
1526 touch_file(filename_defextW);
1527 touch_file(filename_ext2W);
1529 /* IFileOpenDialog, default extension */
1530 test_filename_opendlg(filename_noextW, psi_current, defextW, NULL, 0, filename_noextW);
1531 /* IFileOpenDialog, default extension and filterspec */
1532 test_filename_opendlg(filename_noextW, psi_current, defextW, filterspec, 2, filename_noextW);
1534 DeleteFileW(filename_noextW);
1535 /* IFileOpenDialog, default extension, noextW deleted */
1536 test_filename_opendlg(filename_noextW, psi_current, defextW, NULL, 0, filename_defextW);
1537 if(0) /* Interactive */
1539 /* IFileOpenDialog, filterspec, no default extension, noextW deleted */
1540 test_filename_opendlg(filename_noextW, psi_current, NULL, filterspec, 2, NULL);
1543 IShellItem_Release(psi_current);
1544 DeleteFileW(filename_defextW);
1545 DeleteFileW(filename_ext2W);
1548 static const WCHAR label[] = {'l','a','b','e','l',0};
1549 static const WCHAR label2[] = {'t','e','s','t',0};
1550 static const WCHAR menuW[] = {'m','e','n','u','_','i','t','e','m',0};
1551 static const WCHAR pushbutton1W[] = {'p','u','s','h','b','u','t','t','o','n','_','i','t','e','m',0};
1552 static const WCHAR pushbutton2W[] = {'p','u','s','h','b','u','t','t','o','n','2','_','i','t','e','m',0};
1553 static const WCHAR comboboxitem1W[] = {'c','o','m','b','o','b','o','x','1','_','i','t','e','m',0};
1554 static const WCHAR comboboxitem2W[] = {'c','o','m','b','o','b','o','x','2','_','i','t','e','m',0};
1555 static const WCHAR radiobutton1W[] = {'r','a','d','i','o','b','u','t','t','o','n','1','_','i','t','e','m',0};
1556 static const WCHAR radiobutton2W[] = {'r','a','d','i','o','b','u','t','t','o','n','2','_','i','t','e','m',0};
1557 static const WCHAR checkbutton1W[] = {'c','h','e','c','k','b','u','t','t','o','n','1','_','i','t','e','m',0};
1558 static const WCHAR checkbutton2W[] = {'c','h','e','c','k','b','u','t','t','o','n','2','_','i','t','e','m',0};
1559 static const WCHAR editbox1W[] = {'e','d','i','t','b','o','x','W','1','_','i','t','e','m',0};
1560 static const WCHAR editbox2W[] = {'e','d','i','t','b','o','x','W','2','_','i','t','e','m',0};
1561 static const WCHAR textW[] = {'t','e','x','t','_','i','t','e','m',0};
1562 static const WCHAR text2W[] = {'t','e','x','t','2','_','i','t','e','m',0};
1563 static const WCHAR separatorW[] = {'s','e','p','a','r','a','t','o','r','_','i','t','e','m',0};
1564 static const WCHAR visualgroup1W[] = {'v','i','s','u','a','l','g','r','o','u','p','1',0};
1565 static const WCHAR visualgroup2W[] = {'v','i','s','u','a','l','g','r','o','u','p','2',0};
1567 static const WCHAR floatnotifysinkW[] = {'F','l','o','a','t','N','o','t','i','f','y','S','i','n','k',0};
1568 static const WCHAR RadioButtonListW[] = {'R','a','d','i','o','B','u','t','t','o','n','L','i','s','t',0};
1570 static void test_customize_onfolderchange(IFileDialog *pfd)
1572 HWND dlg_hwnd, item, item_parent;
1573 BOOL br;
1574 WCHAR buf[1024];
1576 buf[0] = '\0';
1578 dlg_hwnd = get_hwnd_from_ifiledialog(pfd);
1579 ok(dlg_hwnd != NULL, "Got NULL.\n");
1581 item = find_window(dlg_hwnd, NULL, checkbutton2W);
1582 ok(item != NULL, "Failed to find item.\n");
1583 item_parent = GetParent(item);
1584 GetClassNameW(item_parent, buf, 1024);
1585 ok(!lstrcmpW(buf, floatnotifysinkW), "Got %s\n", wine_dbgstr_w(buf));
1586 item = find_window(dlg_hwnd, NULL, text2W);
1587 ok(item != NULL, "Failed to find item.\n");
1588 item_parent = GetParent(item);
1589 GetClassNameW(item_parent, buf, 1024);
1590 ok(!lstrcmpW(buf, floatnotifysinkW), "Got %s\n", wine_dbgstr_w(buf));
1591 item = find_window(dlg_hwnd, NULL, radiobutton1W);
1592 ok(item != NULL, "Failed to find item.\n");
1593 item_parent = GetParent(item);
1594 GetClassNameW(item_parent, buf, 1024);
1595 ok(!lstrcmpW(buf, RadioButtonListW), "Got %s\n", wine_dbgstr_w(buf));
1596 item_parent = GetParent(item_parent);
1597 GetClassNameW(item_parent, buf, 1024);
1598 ok(!lstrcmpW(buf, floatnotifysinkW), "Got %s\n", wine_dbgstr_w(buf));
1600 item = find_window(dlg_hwnd, NULL, pushbutton1W);
1601 ok(item == NULL, "Found item: %p\n", item);
1602 item = find_window(dlg_hwnd, NULL, pushbutton2W);
1603 ok(item == NULL, "Found item: %p\n", item);
1604 item = find_window(dlg_hwnd, NULL, comboboxitem1W);
1605 ok(item == NULL, "Found item: %p\n", item);
1606 item = find_window(dlg_hwnd, NULL, comboboxitem2W);
1607 ok(item == NULL, "Found item: %p\n", item);
1608 item = find_window(dlg_hwnd, NULL, radiobutton2W);
1609 ok(item == NULL, "Found item: %p\n", item);
1610 item = find_window(dlg_hwnd, NULL, checkbutton1W);
1611 ok(item == NULL, "Found item: %p\n", item);
1612 item = find_window(dlg_hwnd, NULL, editbox1W);
1613 ok(item == NULL, "Found item: %p\n", item);
1614 item = find_window(dlg_hwnd, NULL, editbox2W);
1615 ok(item == NULL, "Found item: %p\n", item);
1616 item = find_window(dlg_hwnd, NULL, textW);
1617 ok(item == NULL, "Found item: %p\n", item);
1618 item = find_window(dlg_hwnd, NULL, separatorW);
1619 ok(item == NULL, "Found item: %p\n", item);
1620 item = find_window(dlg_hwnd, NULL, visualgroup1W);
1621 ok(item == NULL, "Found item: %p\n", item);
1622 item = find_window(dlg_hwnd, NULL, visualgroup2W);
1623 todo_wine ok(item == NULL, "Found item: %p\n", item);
1625 br = PostMessageW(dlg_hwnd, WM_COMMAND, IDCANCEL, 0);
1626 ok(br, "Failed\n");
1629 static void test_customize(void)
1631 IFileDialog *pfod;
1632 IFileDialogCustomize *pfdc;
1633 IFileDialogEventsImpl *pfdeimpl;
1634 IFileDialogEvents *pfde;
1635 IOleWindow *pow;
1636 CDCONTROLSTATEF cdstate;
1637 DWORD cookie;
1638 LPWSTR tmpstr;
1639 UINT i;
1640 UINT id_vgroup1, id_text, id_editbox1;
1641 LONG ref;
1642 HWND dlg_hwnd;
1643 HRESULT hr;
1644 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
1645 &IID_IFileDialog, (void**)&pfod);
1646 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1648 hr = IFileDialog_QueryInterface(pfod, &IID_IFileDialogCustomize, (void**)&pfdc);
1649 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1650 if(FAILED(hr))
1652 skip("Skipping IFileDialogCustomize tests.\n");
1653 IFileDialog_Release(pfod);
1654 return;
1657 i = 0;
1658 hr = IFileDialogCustomize_AddPushButton(pfdc, i, pushbutton1W);
1659 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1660 hr = IFileDialogCustomize_AddPushButton(pfdc, i, pushbutton1W);
1661 ok(hr == E_UNEXPECTED, "got 0x%08lx.\n", hr);
1663 hr = IFileDialog_QueryInterface(pfod, &IID_IOleWindow, (void**)&pow);
1664 ok(hr == S_OK, "Got 0x%08lx\n", hr);
1665 hr = IOleWindow_GetWindow(pow, &dlg_hwnd);
1666 ok(hr == S_OK, "Got 0x%08lx\n", hr);
1667 ok(dlg_hwnd == NULL, "NULL\n");
1668 IOleWindow_Release(pow);
1670 cdstate = 0xdeadbeef;
1671 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1672 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1673 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1675 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1676 ok(hr == E_NOINTERFACE, "got 0x%08lx.\n", hr);
1678 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1679 ok(hr == S_OK, "got 0x%08lx (control: %d).\n", hr, i);
1681 hr = IFileDialogCustomize_EnableOpenDropDown(pfdc, i);
1682 ok(hr == E_UNEXPECTED, "got 0x%08lx.\n", hr);
1683 hr = IFileDialogCustomize_EnableOpenDropDown(pfdc, ++i);
1684 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1686 hr = IFileDialogCustomize_EnableOpenDropDown(pfdc, i);
1687 ok(hr == E_UNEXPECTED, "got 0x%08lx.\n", hr);
1688 hr = IFileDialogCustomize_EnableOpenDropDown(pfdc, i+1);
1689 ok(hr == E_UNEXPECTED, "got 0x%08lx.\n", hr);
1691 cdstate = 0xdeadbeef;
1692 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1693 ok(hr == E_NOTIMPL, "got 0x%08lx.\n", hr);
1694 ok(cdstate == 0xdeadbeef, "got 0x%08x.\n", cdstate);
1696 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1697 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1698 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1699 ok(hr == E_INVALIDARG, "got 0x%08lx.\n", hr);
1701 cdstate = 0xdeadbeef;
1702 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1703 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1704 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1705 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, 0);
1706 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1707 cdstate = 0xdeadbeef;
1708 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1709 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1710 ok(!cdstate, "got 0x%08x.\n", cdstate);
1711 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, CDCS_ENABLEDVISIBLE);
1712 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1713 cdstate = 0xdeadbeef;
1714 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1715 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1716 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1718 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1719 ok(hr == E_NOTIMPL, "got 0x%08lx (control: %d).\n", hr, i);
1721 hr = IFileDialogCustomize_AddMenu(pfdc, i, menuW);
1722 ok(hr == E_UNEXPECTED, "got 0x%08lx.\n", hr);
1723 hr = IFileDialogCustomize_AddMenu(pfdc, ++i, label);
1724 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1726 cdstate = 0xdeadbeef;
1727 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1728 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1729 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1731 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1732 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1733 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1734 ok(hr == E_INVALIDARG, "got 0x%08lx.\n", hr);
1736 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1737 ok(hr == S_OK, "got 0x%08lx (control: %d).\n", hr, i);
1739 hr = IFileDialogCustomize_AddPushButton(pfdc, i, pushbutton2W);
1740 ok(hr == E_UNEXPECTED, "got 0x%08lx.\n", hr);
1741 hr = IFileDialogCustomize_AddPushButton(pfdc, ++i, pushbutton2W);
1742 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1744 cdstate = 0xdeadbeef;
1745 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1746 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1747 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1749 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1750 ok(hr == E_NOINTERFACE, "got 0x%08lx.\n", hr);
1752 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1753 ok(hr == S_OK, "got 0x%08lx (control: %d).\n", hr, i);
1755 hr = IFileDialogCustomize_AddComboBox(pfdc, i);
1756 ok(hr == E_UNEXPECTED, "got 0x%08lx.\n", hr);
1757 hr = IFileDialogCustomize_AddComboBox(pfdc, ++i);
1758 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1760 cdstate = 0xdeadbeef;
1761 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1762 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1763 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1765 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1766 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1767 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1768 ok(hr == E_INVALIDARG, "got 0x%08lx.\n", hr);
1770 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1771 ok(hr == S_OK, "got 0x%08lx (control: %d).\n", hr, i);
1773 hr = IFileDialogCustomize_AddRadioButtonList(pfdc, i);
1774 ok(hr == E_UNEXPECTED, "got 0x%08lx.\n", hr);
1775 hr = IFileDialogCustomize_AddRadioButtonList(pfdc, ++i);
1776 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1778 cdstate = 0xdeadbeef;
1779 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1780 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1781 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1783 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, radiobutton1W);
1784 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1785 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, radiobutton1W);
1786 ok(hr == E_INVALIDARG, "got 0x%08lx.\n", hr);
1788 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, radiobutton2W);
1789 ok(hr == S_OK, "got 0x%08lx (control: %d).\n", hr, i);
1791 hr = IFileDialogCustomize_AddCheckButton(pfdc, i, label, TRUE);
1792 ok(hr == E_UNEXPECTED, "got 0x%08lx.\n", hr);
1793 hr = IFileDialogCustomize_AddCheckButton(pfdc, ++i, checkbutton1W, TRUE);
1794 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1796 cdstate = 0xdeadbeef;
1797 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1798 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1799 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1801 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1802 ok(hr == E_NOINTERFACE, "got 0x%08lx.\n", hr);
1804 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, checkbutton2W);
1805 ok(hr == S_OK, "got 0x%08lx (control: %d).\n", hr, i);
1807 if(SUCCEEDED(hr))
1809 BOOL checked;
1810 hr = IFileDialogCustomize_GetCheckButtonState(pfdc, i, &checked);
1811 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1812 ok(checked, "checkbox not checked.\n");
1814 hr = IFileDialogCustomize_SetCheckButtonState(pfdc, i, FALSE);
1815 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1817 hr = IFileDialogCustomize_GetCheckButtonState(pfdc, i, &checked);
1818 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1819 ok(!checked, "checkbox checked.\n");
1821 hr = IFileDialogCustomize_SetCheckButtonState(pfdc, i, TRUE);
1822 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1824 hr = IFileDialogCustomize_GetCheckButtonState(pfdc, i, &checked);
1825 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1826 ok(checked, "checkbox not checked.\n");
1829 hr = IFileDialogCustomize_AddEditBox(pfdc, i, label);
1830 ok(hr == E_UNEXPECTED, "got 0x%08lx.\n", hr);
1831 hr = IFileDialogCustomize_AddEditBox(pfdc, ++i, editbox1W);
1832 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1834 cdstate = 0xdeadbeef;
1835 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1836 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1837 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1839 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1840 ok(hr == E_NOINTERFACE, "got 0x%08lx.\n", hr);
1842 /* Does not affect the text in the editbox */
1843 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, editbox2W);
1844 ok(hr == S_OK, "got 0x%08lx (control: %d).\n", hr, i);
1846 hr = IFileDialogCustomize_GetEditBoxText(pfdc, i, &tmpstr);
1847 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1848 if(SUCCEEDED(hr))
1850 ok(!lstrcmpW(tmpstr, editbox1W), "got %s.\n", wine_dbgstr_w(tmpstr));
1851 CoTaskMemFree(tmpstr);
1854 hr = IFileDialogCustomize_SetEditBoxText(pfdc, i, label2);
1855 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1857 hr = IFileDialogCustomize_GetEditBoxText(pfdc, i, &tmpstr);
1858 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1859 if(SUCCEEDED(hr))
1861 ok(!lstrcmpW(tmpstr, label2), "got %s.\n", wine_dbgstr_w(tmpstr));
1862 CoTaskMemFree(tmpstr);
1865 hr = IFileDialogCustomize_AddSeparator(pfdc, i);
1866 ok(hr == E_UNEXPECTED, "got 0x%08lx.\n", hr);
1867 hr = IFileDialogCustomize_AddSeparator(pfdc, ++i);
1868 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1870 cdstate = 0xdeadbeef;
1871 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1872 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1873 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1875 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1876 ok(hr == E_NOINTERFACE, "got 0x%08lx.\n", hr);
1878 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, separatorW);
1879 ok(hr == S_OK, "got 0x%08lx (control: %d).\n", hr, i);
1881 hr = IFileDialogCustomize_AddText(pfdc, i, label);
1882 ok(hr == E_UNEXPECTED, "got 0x%08lx.\n", hr);
1883 hr = IFileDialogCustomize_AddText(pfdc, ++i, textW);
1884 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1886 cdstate = 0xdeadbeef;
1887 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1888 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1889 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1891 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1892 ok(hr == E_NOINTERFACE, "got 0x%08lx.\n", hr);
1894 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, text2W);
1895 ok(hr == S_OK, "got 0x%08lx (control: %d).\n", hr, i);
1897 hr = IFileDialogCustomize_StartVisualGroup(pfdc, i, label);
1898 ok(hr == E_UNEXPECTED, "got 0x%08lx.\n", hr);
1899 hr = IFileDialogCustomize_StartVisualGroup(pfdc, ++i, visualgroup1W);
1900 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1902 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1903 ok(hr == E_NOINTERFACE, "got 0x%08lx.\n", hr);
1905 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, visualgroup2W);
1906 ok(hr == S_OK, "got 0x%08lx (control: %d).\n", hr, i);
1908 cdstate = 0xdeadbeef;
1909 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1910 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1911 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1913 hr = IFileDialogCustomize_StartVisualGroup(pfdc, ++i, label);
1914 ok(hr == E_UNEXPECTED, "got 0x%08lx.\n", hr);
1915 hr = IFileDialogCustomize_EndVisualGroup(pfdc);
1916 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1918 i++; /* Nonexisting control */
1919 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1920 todo_wine ok(hr == E_INVALIDARG, "got 0x%08lx.\n", hr);
1921 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1922 ok(hr == E_INVALIDARG, "got 0x%08lx (control: %d).\n", hr, i);
1923 cdstate = 0xdeadbeef;
1924 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1925 todo_wine ok(hr == E_INVALIDARG, "got 0x%08lx.\n", hr);
1926 ok(cdstate == 0xdeadbeef, "got 0x%08x.\n", cdstate);
1928 pfde = IFileDialogEvents_Constructor();
1929 pfdeimpl = impl_from_IFileDialogEvents(pfde);
1930 pfdeimpl->events_test = IFDEVENT_TEST1;
1931 hr = IFileDialog_Advise(pfod, pfde, &cookie);
1932 ok(hr == S_OK, "Got 0x%08lx\n", hr);
1934 hr = IFileDialog_Show(pfod, NULL);
1935 ok(hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "Got 0x%08lx\n", hr);
1937 hr = IFileDialog_Unadvise(pfod, cookie);
1938 ok(hr == S_OK, "Got 0x%08lx\n", hr);
1940 IFileDialogEvents_Release(pfde);
1941 IFileDialogCustomize_Release(pfdc);
1942 ref = IFileDialog_Release(pfod);
1943 ok(!ref, "Refcount not zero (%ld).\n", ref);
1946 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
1947 &IID_IFileDialog, (void**)&pfod);
1948 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1950 hr = IFileDialog_QueryInterface(pfod, &IID_IFileDialogCustomize, (void**)&pfdc);
1951 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1953 i = 0;
1954 hr = IFileDialogCustomize_AddMenu(pfdc, ++i, label);
1955 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1956 if(SUCCEEDED(hr))
1958 DWORD selected;
1959 UINT j = 0;
1961 for(j = 0; j < 10; j++)
1963 hr = IFileDialogCustomize_AddControlItem(pfdc, i, j, label);
1964 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1967 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
1968 ok(hr == E_NOTIMPL, "got 0x%08lx.\n", hr);
1970 cdstate = 0xdeadbeef;
1971 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1972 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1973 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1974 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, 0);
1975 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1976 cdstate = 0xdeadbeef;
1977 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1978 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1979 ok(cdstate == 0, "got 0x%08x.\n", cdstate);
1980 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, CDCS_ENABLEDVISIBLE);
1981 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1982 cdstate = 0xdeadbeef;
1983 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1984 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1985 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1987 hr = IFileDialogCustomize_RemoveAllControlItems(pfdc, i);
1988 ok(hr == E_NOTIMPL, "got 0x%08lx.\n", hr);
1990 for(j = 0; j < 10; j++)
1992 hr = IFileDialogCustomize_RemoveControlItem(pfdc, i, j);
1993 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1996 hr = IFileDialogCustomize_AddPushButton(pfdc, ++i, label);
1997 ok(hr == S_OK, "got 0x%08lx.\n", hr);
1998 hr = IFileDialogCustomize_AddComboBox(pfdc, ++i);
1999 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2000 if(SUCCEEDED(hr))
2002 DWORD selected = -1;
2003 UINT j = 0;
2005 for(j = 0; j < 10; j++)
2007 hr = IFileDialogCustomize_AddControlItem(pfdc, i, j, label);
2008 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2011 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
2012 ok(hr == E_FAIL, "got 0x%08lx.\n", hr);
2013 ok(selected == -1, "got %ld.\n", selected);
2015 cdstate = 0xdeadbeef;
2016 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
2017 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2018 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2019 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, 0);
2020 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2021 cdstate = 0xdeadbeef;
2022 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
2023 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2024 ok(cdstate == 0, "got 0x%08x.\n", cdstate);
2025 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, CDCS_ENABLEDVISIBLE);
2026 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2027 cdstate = 0xdeadbeef;
2028 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
2029 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2030 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2032 for(j = 0; j < 10; j++)
2034 hr = IFileDialogCustomize_SetSelectedControlItem(pfdc, i, j);
2035 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2036 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
2037 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2038 ok(selected == j, "got %ld.\n", selected);
2040 j++;
2041 hr = IFileDialogCustomize_SetSelectedControlItem(pfdc, i, j);
2042 ok(hr == E_INVALIDARG, "got 0x%08lx.\n", hr);
2044 hr = IFileDialogCustomize_RemoveAllControlItems(pfdc, i);
2045 ok(hr == E_NOTIMPL, "got 0x%08lx.\n", hr);
2047 for(j = 0; j < 10; j++)
2049 hr = IFileDialogCustomize_RemoveControlItem(pfdc, i, j);
2050 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2054 hr = IFileDialogCustomize_AddRadioButtonList(pfdc, ++i);
2055 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2056 if(SUCCEEDED(hr))
2058 DWORD selected = -1;
2059 UINT j = 0;
2061 for(j = 0; j < 10; j++)
2063 hr = IFileDialogCustomize_AddControlItem(pfdc, i, j, label);
2064 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2067 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
2068 ok(hr == E_FAIL, "got 0x%08lx.\n", hr);
2069 ok(selected == -1, "got %ld.\n", selected);
2071 cdstate = 0xdeadbeef;
2072 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
2073 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2074 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2075 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, 0);
2076 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2077 cdstate = 0xdeadbeef;
2078 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
2079 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2080 ok(cdstate == 0, "got 0x%08x.\n", cdstate);
2081 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, CDCS_ENABLEDVISIBLE);
2082 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2083 cdstate = 0xdeadbeef;
2084 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
2085 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2086 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2088 for(j = 0; j < 10; j++)
2090 hr = IFileDialogCustomize_SetSelectedControlItem(pfdc, i, j);
2091 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2092 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
2093 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2094 ok(selected == j, "got %ld.\n", selected);
2096 j++;
2097 hr = IFileDialogCustomize_SetSelectedControlItem(pfdc, i, j);
2098 ok(hr == E_INVALIDARG, "got 0x%08lx.\n", hr);
2100 hr = IFileDialogCustomize_RemoveAllControlItems(pfdc, i);
2101 ok(hr == E_NOTIMPL, "got 0x%08lx.\n", hr);
2103 for(j = 0; j < 10; j++)
2105 hr = IFileDialogCustomize_RemoveControlItem(pfdc, i, j);
2106 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2109 hr = IFileDialogCustomize_EnableOpenDropDown(pfdc, ++i);
2110 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2111 if(SUCCEEDED(hr))
2113 DWORD selected = -1;
2114 UINT j = 0;
2116 for(j = 0; j < 10; j++)
2118 hr = IFileDialogCustomize_AddControlItem(pfdc, i, j, label);
2119 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2122 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
2123 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2124 ok(selected == 0, "got %ld.\n", selected);
2126 cdstate = 0xdeadbeef;
2127 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
2128 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2129 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2130 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, 0);
2131 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2132 cdstate = 0xdeadbeef;
2133 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
2134 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2135 ok(cdstate == 0, "got 0x%08x.\n", cdstate);
2136 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, CDCS_ENABLEDVISIBLE);
2137 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2138 cdstate = 0xdeadbeef;
2139 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
2140 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2141 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2142 hr = IFileDialogCustomize_SetSelectedControlItem(pfdc, i, 0);
2143 todo_wine ok(hr == E_NOTIMPL, "got 0x%08lx.\n", hr);
2145 hr = IFileDialogCustomize_RemoveAllControlItems(pfdc, i);
2146 ok(hr == E_NOTIMPL, "got 0x%08lx.\n", hr);
2148 for(j = 0; j < 10; j++)
2150 hr = IFileDialogCustomize_RemoveControlItem(pfdc, i, j);
2151 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2155 IFileDialogCustomize_Release(pfdc);
2156 ref = IFileDialog_Release(pfod);
2157 ok(!ref, "Refcount not zero (%ld).\n", ref);
2160 /* Some more tests for VisualGroup behavior */
2161 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
2162 &IID_IFileDialog, (void**)&pfod);
2163 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2165 hr = IFileDialog_QueryInterface(pfod, &IID_IFileDialogCustomize, (void**)&pfdc);
2166 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2168 i = -1;
2169 id_vgroup1 = ++i;
2170 hr = IFileDialogCustomize_StartVisualGroup(pfdc, id_vgroup1, visualgroup1W);
2171 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2173 cdstate = 0xdeadbeef;
2174 hr = IFileDialogCustomize_GetControlState(pfdc, id_vgroup1, &cdstate);
2175 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2176 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2178 id_text = ++i;
2179 hr = IFileDialogCustomize_AddText(pfdc, id_text, label);
2180 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2182 cdstate = 0xdeadbeef;
2183 hr = IFileDialogCustomize_GetControlState(pfdc, id_text, &cdstate);
2184 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2185 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2187 id_editbox1 = ++i;
2188 hr = IFileDialogCustomize_AddEditBox(pfdc, id_editbox1, editbox1W);
2189 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2191 cdstate = 0xdeadbeef;
2192 hr = IFileDialogCustomize_GetControlState(pfdc, id_editbox1, &cdstate);
2193 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2194 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2197 /* Set all Visible but not Enabled */
2198 hr = IFileDialogCustomize_SetControlState(pfdc, id_vgroup1, CDCS_VISIBLE);
2199 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2201 cdstate = 0xdeadbeef;
2202 hr = IFileDialogCustomize_GetControlState(pfdc, id_vgroup1, &cdstate);
2203 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2204 ok(cdstate == CDCS_VISIBLE, "got 0x%08x.\n", cdstate);
2205 cdstate = 0xdeadbeef;
2207 hr = IFileDialogCustomize_GetControlState(pfdc, id_text, &cdstate);
2208 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2209 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2211 cdstate = 0xdeadbeef;
2212 hr = IFileDialogCustomize_GetControlState(pfdc, id_editbox1, &cdstate);
2213 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2214 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2216 /* Set text to Visible but not Enabled */
2217 hr = IFileDialogCustomize_SetControlState(pfdc, id_text, CDCS_VISIBLE);
2218 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2220 cdstate = 0xdeadbeef;
2221 hr = IFileDialogCustomize_GetControlState(pfdc, id_vgroup1, &cdstate);
2222 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2223 ok(cdstate == CDCS_VISIBLE, "got 0x%08x.\n", cdstate);
2224 cdstate = 0xdeadbeef;
2226 hr = IFileDialogCustomize_GetControlState(pfdc, id_text, &cdstate);
2227 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2228 ok(cdstate == CDCS_VISIBLE, "got 0x%08x.\n", cdstate);
2230 cdstate = 0xdeadbeef;
2231 hr = IFileDialogCustomize_GetControlState(pfdc, id_editbox1, &cdstate);
2232 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2233 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2235 /* Set vgroup to inactive */
2236 hr = IFileDialogCustomize_SetControlState(pfdc, id_vgroup1, CDCS_INACTIVE);
2237 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2239 cdstate = 0xdeadbeef;
2240 hr = IFileDialogCustomize_GetControlState(pfdc, id_vgroup1, &cdstate);
2241 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2242 ok(cdstate == CDCS_INACTIVE, "got 0x%08x.\n", cdstate);
2244 cdstate = 0xdeadbeef;
2245 hr = IFileDialogCustomize_GetControlState(pfdc, id_text, &cdstate);
2246 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2247 ok(cdstate == CDCS_VISIBLE, "got 0x%08x.\n", cdstate);
2249 cdstate = 0xdeadbeef;
2250 hr = IFileDialogCustomize_GetControlState(pfdc, id_editbox1, &cdstate);
2251 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2252 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2254 /* Set vgroup to Enabled and Visible again */
2255 hr = IFileDialogCustomize_SetControlState(pfdc, id_vgroup1, CDCS_ENABLEDVISIBLE);
2256 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2258 cdstate = 0xdeadbeef;
2259 hr = IFileDialogCustomize_GetControlState(pfdc, id_vgroup1, &cdstate);
2260 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2261 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2263 cdstate = 0xdeadbeef;
2264 hr = IFileDialogCustomize_GetControlState(pfdc, id_text, &cdstate);
2265 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2266 ok(cdstate == CDCS_VISIBLE, "got 0x%08x.\n", cdstate);
2268 cdstate = 0xdeadbeef;
2269 hr = IFileDialogCustomize_GetControlState(pfdc, id_editbox1, &cdstate);
2270 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2271 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2273 hr = IFileDialogCustomize_MakeProminent(pfdc, id_vgroup1);
2274 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2276 IFileDialogCustomize_Release(pfdc);
2277 ref = IFileDialog_Release(pfod);
2278 ok(!ref, "Refcount not zero (%ld).\n", ref);
2281 static void test_persistent_state(void)
2283 IFileDialog *fd;
2284 HRESULT hr;
2286 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
2287 &IID_IFileDialog, (void**)&fd);
2288 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2290 if (0)
2292 /* crashes at least on Win8 */
2293 hr = IFileDialog_SetClientGuid(fd, NULL);
2296 hr = IFileDialog_SetClientGuid(fd, &IID_IUnknown);
2297 ok(hr == S_OK, "got 0x%08lx\n", hr);
2299 hr = IFileDialog_SetClientGuid(fd, &IID_NULL);
2300 ok(hr == S_OK, "got 0x%08lx\n", hr);
2302 IFileDialog_Release(fd);
2305 static void test_overwrite(void)
2307 static const WCHAR filename_winetest[] = {'w','i','n','e','t','e','s','t','.','o','v','w',0};
2308 IFileDialogEventsImpl *pfdeimpl;
2309 IFileDialogEvents *pfde;
2310 IFileDialog *fd;
2311 DWORD cookie;
2312 LPWSTR filename;
2313 IShellItem *psi_current;
2314 WCHAR buf[MAX_PATH];
2315 HRESULT hr;
2317 GetCurrentDirectoryW(MAX_PATH, buf);
2318 ok(!!pSHCreateItemFromParsingName, "SHCreateItemFromParsingName is missing.\n");
2319 hr = pSHCreateItemFromParsingName(buf, NULL, &IID_IShellItem, (void**)&psi_current);
2320 ok(hr == S_OK, "Got 0x%08lx\n", hr);
2322 touch_file(filename_winetest);
2324 /* FOS_OVERWRITEPROMPT has no effect on open dialog */
2325 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
2326 &IID_IFileDialog, (void**)&fd);
2327 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2329 hr = IFileDialog_SetOptions(fd, FOS_OVERWRITEPROMPT | FOS_NOCHANGEDIR);
2330 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2332 hr = IFileDialog_SetFolder(fd, psi_current);
2333 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2335 pfde = IFileDialogEvents_Constructor();
2336 pfdeimpl = impl_from_IFileDialogEvents(pfde);
2337 pfdeimpl->set_filename = filename_winetest;
2338 hr = IFileDialog_Advise(fd, pfde, &cookie);
2339 ok(hr == S_OK, "Advise failed: Got 0x%08lx\n", hr);
2341 hr = IFileDialog_Show(fd, NULL);
2342 ok(hr == S_OK, "Show failed: Got 0x%08lx\n", hr);
2344 ok(!pfdeimpl->OnOverwrite, "got %lu overwrite events\n", pfdeimpl->OnOverwrite);
2345 ok(pfdeimpl->OnFileOk == 1, "got %lu ok events\n", pfdeimpl->OnFileOk);
2347 hr = IFileDialog_GetFileName(fd, &filename);
2348 ok(hr == S_OK, "GetFileName failed: Got 0x%08lx\n", hr);
2349 ok(!lstrcmpW(filename, filename_winetest), "Got %s\n", wine_dbgstr_w(filename));
2350 CoTaskMemFree(filename);
2352 hr = IFileDialog_Unadvise(fd, cookie);
2353 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2355 IFileDialog_Release(fd);
2357 IFileDialogEvents_Release(pfde);
2359 /* Save dialog doesn't check for overwrite without FOS_OVERWRITEPROMPT set */
2360 hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER,
2361 &IID_IFileDialog, (void**)&fd);
2362 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2364 hr = IFileDialog_SetOptions(fd, FOS_NOREADONLYRETURN | FOS_PATHMUSTEXIST | FOS_NOCHANGEDIR);
2365 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2367 hr = IFileDialog_SetFolder(fd, psi_current);
2368 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2370 pfde = IFileDialogEvents_Constructor();
2371 pfdeimpl = impl_from_IFileDialogEvents(pfde);
2372 pfdeimpl->set_filename = filename_winetest;
2373 hr = IFileDialog_Advise(fd, pfde, &cookie);
2374 ok(hr == S_OK, "Advise failed: Got 0x%08lx\n", hr);
2376 hr = IFileDialog_Show(fd, NULL);
2377 ok(hr == S_OK, "Show failed: Got 0x%08lx\n", hr);
2379 ok(!pfdeimpl->OnOverwrite, "got %lu overwrite events\n", pfdeimpl->OnOverwrite);
2380 ok(pfdeimpl->OnFileOk == 1, "got %lu ok events\n", pfdeimpl->OnFileOk);
2382 hr = IFileDialog_GetFileName(fd, &filename);
2383 ok(hr == S_OK, "GetFileName failed: Got 0x%08lx\n", hr);
2384 ok(!lstrcmpW(filename, filename_winetest), "Got %s\n", wine_dbgstr_w(filename));
2385 CoTaskMemFree(filename);
2387 hr = IFileDialog_Unadvise(fd, cookie);
2388 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2390 IFileDialog_Release(fd);
2392 IFileDialogEvents_Release(pfde);
2394 /* Save dialog with FOS_OVERWRITEPROMPT set */
2395 hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER,
2396 &IID_IFileDialog, (void**)&fd);
2397 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2399 hr = IFileDialog_SetFolder(fd, psi_current);
2400 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2402 pfde = IFileDialogEvents_Constructor();
2403 pfdeimpl = impl_from_IFileDialogEvents(pfde);
2404 pfdeimpl->set_filename = filename_winetest;
2405 hr = IFileDialog_Advise(fd, pfde, &cookie);
2406 ok(hr == S_OK, "Advise failed: Got 0x%08lx\n", hr);
2408 hr = IFileDialog_Show(fd, NULL);
2409 ok(hr == S_OK, "Show failed: Got 0x%08lx\n", hr);
2411 ok(pfdeimpl->OnOverwrite == 1, "got %lu overwrite events\n", pfdeimpl->OnOverwrite);
2412 ok(pfdeimpl->OnFileOk == 1, "got %lu ok events\n", pfdeimpl->OnFileOk);
2414 hr = IFileDialog_GetFileName(fd, &filename);
2415 ok(hr == S_OK, "GetFileName failed: Got 0x%08lx\n", hr);
2416 ok(!lstrcmpW(filename, filename_winetest), "Got %s\n", wine_dbgstr_w(filename));
2417 CoTaskMemFree(filename);
2419 hr = IFileDialog_Unadvise(fd, cookie);
2420 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2422 IFileDialog_Release(fd);
2424 IFileDialogEvents_Release(pfde);
2426 DeleteFileW(filename_winetest);
2428 /* Save dialog with FOS_OVERWRITEPROMPT set but without existing file */
2429 hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER,
2430 &IID_IFileDialog, (void**)&fd);
2431 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2433 hr = IFileDialog_SetFolder(fd, psi_current);
2434 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2436 pfde = IFileDialogEvents_Constructor();
2437 pfdeimpl = impl_from_IFileDialogEvents(pfde);
2438 pfdeimpl->set_filename = filename_winetest;
2439 hr = IFileDialog_Advise(fd, pfde, &cookie);
2440 ok(hr == S_OK, "Advise failed: Got 0x%08lx\n", hr);
2442 hr = IFileDialog_Show(fd, NULL);
2443 ok(hr == S_OK, "Show failed: Got 0x%08lx\n", hr);
2445 ok(!pfdeimpl->OnOverwrite, "got %lu overwrite events\n", pfdeimpl->OnOverwrite);
2446 ok(pfdeimpl->OnFileOk == 1, "got %lu ok events\n", pfdeimpl->OnFileOk);
2448 hr = IFileDialog_GetFileName(fd, &filename);
2449 ok(hr == S_OK, "GetFileName failed: Got 0x%08lx\n", hr);
2450 ok(!lstrcmpW(filename, filename_winetest), "Got %s\n", wine_dbgstr_w(filename));
2451 CoTaskMemFree(filename);
2453 hr = IFileDialog_Unadvise(fd, cookie);
2454 ok(hr == S_OK, "got 0x%08lx.\n", hr);
2456 IFileDialog_Release(fd);
2458 IFileDialogEvents_Release(pfde);
2460 IShellItem_Release(psi_current);
2463 START_TEST(itemdlg)
2465 OleInitialize(NULL);
2466 init_function_pointers();
2468 if(test_instantiation())
2470 test_basics();
2471 test_advise();
2472 test_events();
2473 test_filename();
2474 test_customize();
2475 test_persistent_state();
2476 test_overwrite();
2478 else
2479 skip("Skipping all Item Dialog tests.\n");
2481 OleUninitialize();