advapi32/tests: Add trailing slashes tests for RegOpen/CreateKey.
[wine.git] / dlls / comdlg32 / tests / itemdlg.c
blob9a3f8510b5edaed1a11ced17f953ea3c77f698d2
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%08x\n", hr);
101 hr = IOleWindow_GetWindow(pow, &dlg_hwnd);
102 ok(hr == S_OK, "Got 0x%08x\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%08x\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 return S_OK;
294 static const IFileDialogEventsVtbl vt_IFileDialogEvents = {
295 IFileDialogEvents_fnQueryInterface,
296 IFileDialogEvents_fnAddRef,
297 IFileDialogEvents_fnRelease,
298 IFileDialogEvents_fnOnFileOk,
299 IFileDialogEvents_fnOnFolderChanging,
300 IFileDialogEvents_fnOnFolderChange,
301 IFileDialogEvents_fnOnSelectionChange,
302 IFileDialogEvents_fnOnShareViolation,
303 IFileDialogEvents_fnOnTypeChange,
304 IFileDialogEvents_fnOnOverwrite
307 static IFileDialogEvents *IFileDialogEvents_Constructor(void)
309 IFileDialogEventsImpl *This;
311 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IFileDialogEventsImpl));
312 This->IFileDialogEvents_iface.lpVtbl = &vt_IFileDialogEvents;
313 This->ref = 1;
315 return &This->IFileDialogEvents_iface;
318 static BOOL test_instantiation(void)
320 IFileDialog *pfd;
321 IFileOpenDialog *pfod;
322 IFileSaveDialog *pfsd;
323 IServiceProvider *psp;
324 IOleWindow *pow;
325 IUnknown *punk;
326 HRESULT hr;
327 LONG ref;
329 /* Instantiate FileOpenDialog */
330 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
331 &IID_IFileOpenDialog, (void**)&pfod);
332 if(FAILED(hr))
334 skip("Could not instantiate the FileOpenDialog.\n");
335 return FALSE;
337 ok(hr == S_OK, "got 0x%08x.\n", hr);
339 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialog, (void**)&pfd);
340 ok(hr == S_OK, "got 0x%08x.\n", hr);
341 if(SUCCEEDED(hr)) IFileDialog_Release(pfd);
343 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialogCustomize, (void**)&punk);
344 ok(hr == S_OK, "got 0x%08x.\n", hr);
345 if(SUCCEEDED(hr)) IUnknown_Release(punk);
347 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialogCustomizeAlt, (void**)&punk);
348 ok(hr == S_OK, "got 0x%08x.\n", hr);
349 if(SUCCEEDED(hr)) IUnknown_Release(punk);
351 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileSaveDialog, (void**)&pfsd);
352 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
353 if(SUCCEEDED(hr)) IFileSaveDialog_Release(pfsd);
355 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IServiceProvider, (void**)&psp);
356 ok(hr == S_OK, "got 0x%08x.\n", hr);
357 if(SUCCEEDED(hr))
359 IExplorerBrowser *peb;
360 IShellBrowser *psb;
362 hr = IServiceProvider_QueryService(psp, &SID_SExplorerBrowserFrame, &IID_ICommDlgBrowser, (void**)&punk);
363 ok(hr == S_OK, "got 0x%08x.\n", hr);
364 if(SUCCEEDED(hr)) IUnknown_Release(punk);
366 /* since win8, the result is E_NOTIMPL for all other services */
367 hr = IServiceProvider_QueryService(psp, &SID_STopLevelBrowser, &IID_IExplorerBrowser, (void**)&peb);
368 ok(hr == E_NOTIMPL || broken(hr == E_FAIL), "got 0x%08x (expected E_NOTIMPL)\n", hr);
369 if(SUCCEEDED(hr)) IExplorerBrowser_Release(peb);
370 hr = IServiceProvider_QueryService(psp, &SID_STopLevelBrowser, &IID_IShellBrowser, (void**)&psb);
371 ok(hr == E_NOTIMPL || broken(hr == E_FAIL), "got 0x%08x (expected E_NOTIMPL)\n", hr);
372 if(SUCCEEDED(hr)) IShellBrowser_Release(psb);
373 hr = IServiceProvider_QueryService(psp, &SID_STopLevelBrowser, &IID_ICommDlgBrowser, (void**)&punk);
374 ok(hr == E_NOTIMPL || broken(hr == E_FAIL), "got 0x%08x (expected E_NOTIMPL)\n", hr);
375 if(SUCCEEDED(hr)) IUnknown_Release(punk);
377 hr = IServiceProvider_QueryService(psp, &SID_STopLevelBrowser, &IID_IUnknown, (void**)&punk);
378 ok(hr == E_NOTIMPL || broken(hr == E_FAIL), "got 0x%08x (expected E_NOTIMPL)\n", hr);
379 if(SUCCEEDED(hr)) IUnknown_Release(punk);
380 hr = IServiceProvider_QueryService(psp, &IID_IUnknown, &IID_IUnknown, (void**)&punk);
381 ok(hr == E_NOTIMPL || broken(hr == E_FAIL), "got 0x%08x (expected E_NOTIMPL)\n", hr);
382 if(SUCCEEDED(hr)) IUnknown_Release(punk);
384 IServiceProvider_Release(psp);
387 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialogEvents, (void**)&punk);
388 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
389 if(SUCCEEDED(hr)) IUnknown_Release(punk);
391 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IExplorerBrowser, (void**)&punk);
392 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
393 if(SUCCEEDED(hr)) IUnknown_Release(punk);
395 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IExplorerBrowserEvents, (void**)&punk);
396 ok(hr == S_OK, "got 0x%08x.\n", hr);
397 if(SUCCEEDED(hr)) IUnknown_Release(punk);
399 hr = IFileOpenDialog_QueryInterface(pfod, &IID_ICommDlgBrowser3, (void**)&punk);
400 ok(hr == S_OK, "got 0x%08x.\n", hr);
401 if(SUCCEEDED(hr)) IUnknown_Release(punk);
403 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IShellBrowser, (void**)&punk);
404 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
405 if(SUCCEEDED(hr)) IUnknown_Release(punk);
407 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IOleWindow, (void**)&pow);
408 ok(hr == S_OK, "got 0x%08x.\n", hr);
409 if(SUCCEEDED(hr))
411 HWND hwnd;
413 hr = IOleWindow_ContextSensitiveHelp(pow, TRUE);
414 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
416 hr = IOleWindow_ContextSensitiveHelp(pow, FALSE);
417 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
419 if(0)
421 /* Crashes on win7 */
422 IOleWindow_GetWindow(pow, NULL);
425 hr = IOleWindow_GetWindow(pow, &hwnd);
426 ok(hr == S_OK, "Got 0x%08x\n", hr);
427 ok(hwnd == NULL, "Got %p\n", hwnd);
429 IOleWindow_Release(pow);
432 ref = IFileOpenDialog_Release(pfod);
433 ok(!ref, "Got refcount %d, should have been released.\n", ref);
435 /* Instantiate FileSaveDialog */
436 hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER,
437 &IID_IFileSaveDialog, (void**)&pfsd);
438 if(FAILED(hr))
440 skip("Could not instantiate the FileSaveDialog.\n");
441 return FALSE;
443 ok(hr == S_OK, "got 0x%08x.\n", hr);
445 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialog, (void**)&pfd);
446 ok(hr == S_OK, "got 0x%08x.\n", hr);
447 if(SUCCEEDED(hr)) IFileDialog_Release(pfd);
449 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialogCustomize, (void**)&punk);
450 ok(hr == S_OK, "got 0x%08x.\n", hr);
451 if(SUCCEEDED(hr)) IUnknown_Release(punk);
453 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialogCustomizeAlt, (void**)&punk);
454 ok(hr == S_OK, "got 0x%08x.\n", hr);
455 if(SUCCEEDED(hr)) IUnknown_Release(punk);
457 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileOpenDialog, (void**)&pfod);
458 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
459 if(SUCCEEDED(hr)) IFileOpenDialog_Release(pfod);
461 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialogEvents, (void**)&punk);
462 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
463 if(SUCCEEDED(hr)) IFileDialog_Release(pfd);
465 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IExplorerBrowser, (void**)&punk);
466 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
467 if(SUCCEEDED(hr)) IUnknown_Release(punk);
469 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IExplorerBrowserEvents, (void**)&punk);
470 ok(hr == S_OK, "got 0x%08x.\n", hr);
471 if(SUCCEEDED(hr)) IUnknown_Release(punk);
473 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_ICommDlgBrowser3, (void**)&punk);
474 ok(hr == S_OK, "got 0x%08x.\n", hr);
475 if(SUCCEEDED(hr)) IUnknown_Release(punk);
477 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IShellBrowser, (void**)&punk);
478 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
479 if(SUCCEEDED(hr)) IUnknown_Release(punk);
481 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IOleWindow, (void**)&pow);
482 ok(hr == S_OK, "got 0x%08x.\n", hr);
483 if(SUCCEEDED(hr))
485 HWND hwnd;
487 hr = IOleWindow_ContextSensitiveHelp(pow, TRUE);
488 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
490 hr = IOleWindow_ContextSensitiveHelp(pow, FALSE);
491 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
493 if(0)
495 /* Crashes on win7 */
496 IOleWindow_GetWindow(pow, NULL);
499 hr = IOleWindow_GetWindow(pow, &hwnd);
500 ok(hr == S_OK, "Got 0x%08x\n", hr);
501 ok(hwnd == NULL, "Got %p\n", hwnd);
503 IOleWindow_Release(pow);
507 ref = IFileSaveDialog_Release(pfsd);
508 ok(!ref, "Got refcount %d, should have been released.\n", ref);
509 return TRUE;
512 static void test_basics(void)
514 IFileOpenDialog *pfod;
515 IFileSaveDialog *pfsd;
516 IFileDialog2 *pfd2;
517 FILEOPENDIALOGOPTIONS fdoptions;
518 IShellFolder *psfdesktop;
519 IShellItem *psi, *psidesktop, *psi_original;
520 IShellItemArray *psia;
521 IPropertyStore *pps;
522 LPITEMIDLIST pidl;
523 WCHAR *filename;
524 UINT filetype;
525 LONG ref;
526 HRESULT hr;
527 const WCHAR txt[] = {'t','x','t', 0};
528 const WCHAR null[] = {0};
529 const WCHAR fname1[] = {'f','n','a','m','e','1', 0};
530 const WCHAR fspec1[] = {'*','.','t','x','t',0};
531 const WCHAR fname2[] = {'f','n','a','m','e','2', 0};
532 const WCHAR fspec2[] = {'*','.','e','x','e',0};
533 COMDLG_FILTERSPEC filterspec[2] = {{fname1, fspec1}, {fname2, fspec2}};
535 /* This should work on every platform with IFileDialog */
536 SHGetDesktopFolder(&psfdesktop);
537 hr = pSHGetIDListFromObject((IUnknown*)psfdesktop, &pidl);
538 if(SUCCEEDED(hr))
540 hr = pSHCreateShellItem(NULL, NULL, pidl, &psidesktop);
541 ILFree(pidl);
543 IShellFolder_Release(psfdesktop);
544 if(FAILED(hr))
546 skip("Failed to get ShellItem from DesktopFolder, skipping tests.\n");
547 return;
551 /* Instantiate FileOpenDialog and FileSaveDialog */
552 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
553 &IID_IFileOpenDialog, (void**)&pfod);
554 ok(hr == S_OK, "got 0x%08x.\n", hr);
555 hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER,
556 &IID_IFileSaveDialog, (void**)&pfsd);
557 ok(hr == S_OK, "got 0x%08x.\n", hr);
559 /* ClearClientData */
560 todo_wine
562 hr = IFileOpenDialog_ClearClientData(pfod);
563 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
564 hr = IFileSaveDialog_ClearClientData(pfsd);
565 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
568 /* GetOptions */
569 hr = IFileOpenDialog_GetOptions(pfod, NULL);
570 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
571 hr = IFileSaveDialog_GetOptions(pfsd, NULL);
572 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
574 /* Check default options */
575 hr = IFileOpenDialog_GetOptions(pfod, &fdoptions);
576 ok(hr == S_OK, "got 0x%08x.\n", hr);
577 ok(fdoptions == (FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST | FOS_NOCHANGEDIR),
578 "Unexpected default options: 0x%08x\n", fdoptions);
579 hr = IFileSaveDialog_GetOptions(pfsd, &fdoptions);
580 ok(hr == S_OK, "got 0x%08x.\n", hr);
581 ok(fdoptions == (FOS_OVERWRITEPROMPT | FOS_NOREADONLYRETURN | FOS_PATHMUSTEXIST | FOS_NOCHANGEDIR),
582 "Unexpected default options: 0x%08x\n", fdoptions);
584 /* GetResult */
585 hr = IFileOpenDialog_GetResult(pfod, NULL);
586 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
587 hr = IFileSaveDialog_GetResult(pfsd, NULL);
588 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
590 psi = (void*)0xdeadbeef;
591 hr = IFileOpenDialog_GetResult(pfod, &psi);
592 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
593 ok(psi == (void*)0xdeadbeef, "got %p.\n", psi);
594 psi = (void*)0xdeadbeef;
595 hr = IFileSaveDialog_GetResult(pfsd, &psi);
596 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
597 ok(psi == (void*)0xdeadbeef, "got %p.\n", psi);
599 /* GetCurrentSelection */
600 if(0) {
601 /* Crashes on Vista/W2K8. Tests below passes on Windows 7 */
602 hr = IFileOpenDialog_GetCurrentSelection(pfod, NULL);
603 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
604 hr = IFileSaveDialog_GetCurrentSelection(pfsd, NULL);
605 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
606 hr = IFileOpenDialog_GetCurrentSelection(pfod, &psi);
607 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
608 hr = IFileSaveDialog_GetCurrentSelection(pfsd, &psi);
609 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
612 /* GetFileName */
613 hr = IFileOpenDialog_GetFileName(pfod, NULL);
614 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
615 filename = (void*)0xdeadbeef;
616 hr = IFileOpenDialog_GetFileName(pfod, &filename);
617 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
618 ok(filename == NULL, "got %p\n", filename);
619 hr = IFileSaveDialog_GetFileName(pfsd, NULL);
620 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
621 filename = (void*)0xdeadbeef;
622 hr = IFileSaveDialog_GetFileName(pfsd, &filename);
623 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
624 ok(filename == NULL, "got %p\n", filename);
626 /* GetFileTypeIndex */
627 hr = IFileOpenDialog_GetFileTypeIndex(pfod, NULL);
628 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
629 filetype = 0x12345;
630 hr = IFileOpenDialog_GetFileTypeIndex(pfod, &filetype);
631 ok(hr == S_OK, "got 0x%08x.\n", hr);
632 ok(filetype == 0, "got %d.\n", filetype);
633 hr = IFileSaveDialog_GetFileTypeIndex(pfsd, NULL);
634 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
635 filetype = 0x12345;
636 hr = IFileSaveDialog_GetFileTypeIndex(pfsd, &filetype);
637 ok(hr == S_OK, "got 0x%08x.\n", hr);
638 ok(filetype == 0, "got %d.\n", filetype);
640 /* SetFileTypes / SetFileTypeIndex */
641 hr = IFileOpenDialog_SetFileTypes(pfod, 0, NULL);
642 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
643 hr = IFileOpenDialog_SetFileTypes(pfod, 0, filterspec);
644 ok(hr == S_OK, "got 0x%08x.\n", hr);
646 hr = IFileOpenDialog_SetFileTypeIndex(pfod, 0);
647 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
648 hr = IFileOpenDialog_SetFileTypeIndex(pfod, 1);
649 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
650 hr = IFileOpenDialog_SetFileTypes(pfod, 1, filterspec);
651 ok(hr == S_OK, "got 0x%08x.\n", hr);
652 hr = IFileOpenDialog_SetFileTypes(pfod, 0, filterspec);
653 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
654 hr = IFileOpenDialog_SetFileTypeIndex(pfod, 0);
655 ok(hr == S_OK, "got 0x%08x.\n", hr);
656 hr = IFileOpenDialog_GetFileTypeIndex(pfod, &filetype);
657 ok(hr == S_OK, "got 0x%08x.\n", hr);
658 ok(filetype == 1, "got %d\n", filetype);
659 hr = IFileOpenDialog_SetFileTypeIndex(pfod, 100);
660 ok(hr == S_OK, "got 0x%08x.\n", hr);
661 hr = IFileOpenDialog_GetFileTypeIndex(pfod, &filetype);
662 ok(hr == S_OK, "got 0x%08x.\n", hr);
663 ok(filetype == 1, "got %d\n", filetype);
664 hr = IFileOpenDialog_SetFileTypes(pfod, 1, filterspec);
665 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
666 hr = IFileOpenDialog_SetFileTypes(pfod, 1, &filterspec[1]);
667 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
669 hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 0);
670 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
671 hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 1);
672 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
673 hr = IFileSaveDialog_SetFileTypes(pfsd, 2, filterspec);
674 ok(hr == S_OK, "got 0x%08x.\n", hr);
675 hr = IFileSaveDialog_GetFileTypeIndex(pfsd, &filetype);
676 ok(hr == S_OK, "got 0x%08x.\n", hr);
677 /* I hope no one relies on this one */
678 todo_wine ok(filetype == 0, "got %d\n", filetype);
679 hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 0);
680 ok(hr == S_OK, "got 0x%08x.\n", hr);
681 hr = IFileSaveDialog_GetFileTypeIndex(pfsd, &filetype);
682 ok(hr == S_OK, "got 0x%08x.\n", hr);
683 ok(filetype == 1, "got %d\n", filetype);
684 hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 100);
685 ok(hr == S_OK, "got 0x%08x.\n", hr);
686 hr = IFileSaveDialog_GetFileTypeIndex(pfsd, &filetype);
687 ok(hr == S_OK, "got 0x%08x.\n", hr);
688 ok(filetype == 2, "got %d\n", filetype);
689 hr = IFileSaveDialog_SetFileTypes(pfsd, 1, filterspec);
690 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
691 hr = IFileSaveDialog_SetFileTypes(pfsd, 1, &filterspec[1]);
692 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
694 /* SetFilter */
695 todo_wine
697 hr = IFileOpenDialog_SetFilter(pfod, NULL);
698 ok(hr == S_OK, "got 0x%08x.\n", hr);
699 hr = IFileSaveDialog_SetFilter(pfsd, NULL);
700 ok(hr == S_OK, "got 0x%08x.\n", hr);
703 /* SetFolder */
704 hr = IFileOpenDialog_SetFolder(pfod, NULL);
705 ok(hr == S_OK, "got 0x%08x.\n", hr);
706 hr = IFileSaveDialog_SetFolder(pfsd, NULL);
707 ok(hr == S_OK, "got 0x%08x.\n", hr);
709 /* SetDefaultExtension */
710 hr = IFileOpenDialog_SetDefaultExtension(pfod, NULL);
711 ok(hr == S_OK, "got 0x%08x.\n", hr);
712 hr = IFileOpenDialog_SetDefaultExtension(pfod, txt);
713 ok(hr == S_OK, "got 0x%08x.\n", hr);
714 hr = IFileOpenDialog_SetDefaultExtension(pfod, null);
715 ok(hr == S_OK, "got 0x%08x.\n", hr);
717 hr = IFileSaveDialog_SetDefaultExtension(pfsd, NULL);
718 ok(hr == S_OK, "got 0x%08x.\n", hr);
719 hr = IFileSaveDialog_SetDefaultExtension(pfsd, txt);
720 ok(hr == S_OK, "got 0x%08x.\n", hr);
721 hr = IFileSaveDialog_SetDefaultExtension(pfsd, null);
722 ok(hr == S_OK, "got 0x%08x.\n", hr);
724 /* SetDefaultFolder */
725 hr = IFileOpenDialog_SetDefaultFolder(pfod, NULL);
726 ok(hr == S_OK, "got 0x%08x\n", hr);
727 hr = IFileSaveDialog_SetDefaultFolder(pfsd, NULL);
728 ok(hr == S_OK, "got 0x%08x\n", hr);
730 hr = IFileOpenDialog_SetDefaultFolder(pfod, psidesktop);
731 ok(hr == S_OK, "got 0x%08x\n", hr);
732 hr = IFileSaveDialog_SetDefaultFolder(pfsd, psidesktop);
733 ok(hr == S_OK, "got 0x%08x\n", hr);
735 if(0)
737 /* Crashes under Windows 7 */
738 IFileOpenDialog_SetDefaultFolder(pfod, (void*)0x1234);
739 IFileSaveDialog_SetDefaultFolder(pfsd, (void*)0x1234);
742 /* GetFolder / SetFolder */
743 hr = IFileOpenDialog_GetFolder(pfod, NULL);
744 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
746 hr = IFileOpenDialog_GetFolder(pfod, &psi_original);
747 ok(hr == S_OK, "got 0x%08x.\n", hr);
748 if(SUCCEEDED(hr))
750 hr = IFileOpenDialog_SetFolder(pfod, psidesktop);
751 ok(hr == S_OK, "got 0x%08x.\n", hr);
752 hr = IFileOpenDialog_SetFolder(pfod, psi_original);
753 ok(hr == S_OK, "got 0x%08x.\n", hr);
754 IShellItem_Release(psi_original);
757 hr = IFileSaveDialog_GetFolder(pfsd, &psi_original);
758 ok(hr == S_OK, "got 0x%08x.\n", hr);
759 if(SUCCEEDED(hr))
761 hr = IFileSaveDialog_SetFolder(pfsd, psidesktop);
762 ok(hr == S_OK, "got 0x%08x.\n", hr);
763 hr = IFileSaveDialog_SetFolder(pfsd, psi_original);
764 ok(hr == S_OK, "got 0x%08x.\n", hr);
765 IShellItem_Release(psi_original);
768 /* AddPlace */
769 if(0)
771 /* Crashes under Windows 7 */
772 IFileOpenDialog_AddPlace(pfod, NULL, 0);
773 IFileSaveDialog_AddPlace(pfsd, NULL, 0);
776 todo_wine
778 hr = IFileOpenDialog_AddPlace(pfod, psidesktop, FDAP_TOP + 1);
779 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
780 hr = IFileOpenDialog_AddPlace(pfod, psidesktop, FDAP_BOTTOM);
781 ok(hr == S_OK, "got 0x%08x\n", hr);
782 hr = IFileOpenDialog_AddPlace(pfod, psidesktop, FDAP_TOP);
783 ok(hr == S_OK, "got 0x%08x\n", hr);
785 hr = IFileSaveDialog_AddPlace(pfsd, psidesktop, FDAP_TOP + 1);
786 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
787 hr = IFileSaveDialog_AddPlace(pfsd, psidesktop, FDAP_BOTTOM);
788 ok(hr == S_OK, "got 0x%08x\n", hr);
789 hr = IFileSaveDialog_AddPlace(pfsd, psidesktop, FDAP_TOP);
790 ok(hr == S_OK, "got 0x%08x\n", hr);
793 /* SetFileName */
794 hr = IFileOpenDialog_SetFileName(pfod, NULL);
795 ok(hr == S_OK, "got 0x%08x\n", hr);
796 hr = IFileOpenDialog_SetFileName(pfod, null);
797 ok(hr == S_OK, "got 0x%08x\n", hr);
798 hr = IFileOpenDialog_SetFileName(pfod, txt);
799 ok(hr == S_OK, "got 0x%08x\n", hr);
800 hr = IFileOpenDialog_GetFileName(pfod, &filename);
801 ok(hr == S_OK, "Got 0x%08x\n", hr);
802 ok(!lstrcmpW(filename, txt), "Strings do not match.\n");
803 CoTaskMemFree(filename);
805 hr = IFileSaveDialog_SetFileName(pfsd, NULL);
806 ok(hr == S_OK, "got 0x%08x\n", hr);
807 hr = IFileSaveDialog_SetFileName(pfsd, null);
808 ok(hr == S_OK, "got 0x%08x\n", hr);
809 hr = IFileSaveDialog_SetFileName(pfsd, txt);
810 ok(hr == S_OK, "got 0x%08x\n", hr);
811 hr = IFileSaveDialog_GetFileName(pfsd, &filename);
812 ok(hr == S_OK, "Got 0x%08x\n", hr);
813 ok(!lstrcmpW(filename, txt), "Strings do not match.\n");
814 CoTaskMemFree(filename);
816 /* SetFileNameLabel */
817 hr = IFileOpenDialog_SetFileNameLabel(pfod, NULL);
818 ok(hr == S_OK, "got 0x%08x\n", hr);
819 hr = IFileOpenDialog_SetFileNameLabel(pfod, null);
820 ok(hr == S_OK, "got 0x%08x\n", hr);
821 hr = IFileOpenDialog_SetFileNameLabel(pfod, txt);
822 ok(hr == S_OK, "got 0x%08x\n", hr);
824 hr = IFileSaveDialog_SetFileNameLabel(pfsd, NULL);
825 ok(hr == S_OK, "got 0x%08x\n", hr);
826 hr = IFileSaveDialog_SetFileNameLabel(pfsd, null);
827 ok(hr == S_OK, "got 0x%08x\n", hr);
828 hr = IFileSaveDialog_SetFileNameLabel(pfsd, txt);
829 ok(hr == S_OK, "got 0x%08x\n", hr);
831 /* Close */
832 hr = IFileOpenDialog_Close(pfod, S_FALSE);
833 ok(hr == S_OK, "got 0x%08x\n", hr);
834 hr = IFileSaveDialog_Close(pfsd, S_FALSE);
835 ok(hr == S_OK, "got 0x%08x\n", hr);
837 /* SetOkButtonLabel */
838 hr = IFileOpenDialog_SetOkButtonLabel(pfod, NULL);
839 ok(hr == S_OK, "got 0x%08x\n", hr);
840 hr = IFileOpenDialog_SetOkButtonLabel(pfod, null);
841 ok(hr == S_OK, "got 0x%08x\n", hr);
842 hr = IFileOpenDialog_SetOkButtonLabel(pfod, txt);
843 ok(hr == S_OK, "got 0x%08x\n", hr);
844 hr = IFileSaveDialog_SetOkButtonLabel(pfsd, NULL);
845 ok(hr == S_OK, "got 0x%08x\n", hr);
846 hr = IFileSaveDialog_SetOkButtonLabel(pfsd, null);
847 ok(hr == S_OK, "got 0x%08x\n", hr);
848 hr = IFileSaveDialog_SetOkButtonLabel(pfsd, txt);
849 ok(hr == S_OK, "got 0x%08x\n", hr);
851 /* SetTitle */
852 hr = IFileOpenDialog_SetTitle(pfod, NULL);
853 ok(hr == S_OK, "got 0x%08x\n", hr);
854 hr = IFileOpenDialog_SetTitle(pfod, null);
855 ok(hr == S_OK, "got 0x%08x\n", hr);
856 hr = IFileOpenDialog_SetTitle(pfod, txt);
857 ok(hr == S_OK, "got 0x%08x\n", hr);
858 hr = IFileSaveDialog_SetTitle(pfsd, NULL);
859 ok(hr == S_OK, "got 0x%08x\n", hr);
860 hr = IFileSaveDialog_SetTitle(pfsd, null);
861 ok(hr == S_OK, "got 0x%08x\n", hr);
862 hr = IFileSaveDialog_SetTitle(pfsd, txt);
863 ok(hr == S_OK, "got 0x%08x\n", hr);
865 /** IFileOpenDialog specific **/
867 /* GetResults */
868 if(0)
870 /* Crashes under Windows 7 */
871 IFileOpenDialog_GetResults(pfod, NULL);
873 psia = (void*)0xdeadbeef;
874 hr = IFileOpenDialog_GetResults(pfod, &psia);
875 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
876 ok(psia == NULL, "got %p.\n", psia);
878 /* GetSelectedItems */
879 if(0)
881 /* Crashes under W2K8 */
882 hr = IFileOpenDialog_GetSelectedItems(pfod, NULL);
883 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
884 psia = (void*)0xdeadbeef;
885 hr = IFileOpenDialog_GetSelectedItems(pfod, &psia);
886 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
887 ok(psia == (void*)0xdeadbeef, "got %p.\n", psia);
890 /** IFileSaveDialog specific **/
892 /* ApplyProperties */
893 if(0)
895 /* Crashes under windows 7 */
896 IFileSaveDialog_ApplyProperties(pfsd, NULL, NULL, NULL, NULL);
897 IFileSaveDialog_ApplyProperties(pfsd, psidesktop, NULL, NULL, NULL);
900 /* GetProperties */
901 hr = IFileSaveDialog_GetProperties(pfsd, NULL);
902 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
903 pps = (void*)0xdeadbeef;
904 hr = IFileSaveDialog_GetProperties(pfsd, &pps);
905 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
906 ok(pps == (void*)0xdeadbeef, "got %p\n", pps);
908 /* SetProperties */
909 if(0)
911 /* Crashes under W2K8 */
912 hr = IFileSaveDialog_SetProperties(pfsd, NULL);
913 ok(hr == S_OK, "got 0x%08x\n", hr);
916 /* SetCollectedProperties */
917 todo_wine
919 hr = IFileSaveDialog_SetCollectedProperties(pfsd, NULL, TRUE);
920 ok(hr == S_OK, "got 0x%08x\n", hr);
921 hr = IFileSaveDialog_SetCollectedProperties(pfsd, NULL, FALSE);
922 ok(hr == S_OK, "got 0x%08x\n", hr);
925 /* SetSaveAsItem */
926 todo_wine
928 hr = IFileSaveDialog_SetSaveAsItem(pfsd, NULL);
929 ok(hr == S_OK, "got 0x%08x\n", hr);
930 hr = IFileSaveDialog_SetSaveAsItem(pfsd, psidesktop);
931 ok(hr == MK_E_NOOBJECT, "got 0x%08x\n", hr);
934 /** IFileDialog2 **/
936 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialog2, (void**)&pfd2);
937 ok((hr == S_OK) || broken(hr == E_NOINTERFACE), "got 0x%08x\n", hr);
938 if(SUCCEEDED(hr))
940 /* SetCancelButtonLabel */
941 hr = IFileDialog2_SetOkButtonLabel(pfd2, NULL);
942 ok(hr == S_OK, "got 0x%08x\n", hr);
943 hr = IFileDialog2_SetOkButtonLabel(pfd2, null);
944 ok(hr == S_OK, "got 0x%08x\n", hr);
945 hr = IFileDialog2_SetOkButtonLabel(pfd2, txt);
946 ok(hr == S_OK, "got 0x%08x\n", hr);
948 /* SetNavigationRoot */
949 todo_wine
951 hr = IFileDialog2_SetNavigationRoot(pfd2, NULL);
952 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
953 hr = IFileDialog2_SetNavigationRoot(pfd2, psidesktop);
954 ok(hr == S_OK, "got 0x%08x\n", hr);
957 IFileDialog2_Release(pfd2);
960 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialog2, (void**)&pfd2);
961 ok((hr == S_OK) || broken(hr == E_NOINTERFACE), "got 0x%08x\n", hr);
962 if(SUCCEEDED(hr))
964 /* SetCancelButtonLabel */
965 hr = IFileDialog2_SetOkButtonLabel(pfd2, NULL);
966 ok(hr == S_OK, "got 0x%08x\n", hr);
967 hr = IFileDialog2_SetOkButtonLabel(pfd2, null);
968 ok(hr == S_OK, "got 0x%08x\n", hr);
969 hr = IFileDialog2_SetOkButtonLabel(pfd2, txt);
970 ok(hr == S_OK, "got 0x%08x\n", hr);
972 /* SetNavigationRoot */
973 todo_wine
975 hr = IFileDialog2_SetNavigationRoot(pfd2, NULL);
976 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
977 hr = IFileDialog2_SetNavigationRoot(pfd2, psidesktop);
978 ok(hr == S_OK, "got 0x%08x\n", hr);
981 IFileDialog2_Release(pfd2);
984 /* Cleanup */
985 IShellItem_Release(psidesktop);
986 ref = IFileOpenDialog_Release(pfod);
987 ok(!ref, "Got refcount %d, should have been released.\n", ref);
988 ref = IFileSaveDialog_Release(pfsd);
989 ok(!ref, "Got refcount %d, should have been released.\n", ref);
992 static void ensure_zero_events_(const char *file, int line, IFileDialogEventsImpl *impl)
994 ok_(file, line)(!impl->OnFileOk, "OnFileOk: %d\n", impl->OnFileOk);
995 ok_(file, line)(!impl->OnFolderChanging, "OnFolderChanging: %d\n", impl->OnFolderChanging);
996 ok_(file, line)(!impl->OnFolderChange, "OnFolderChange: %d\n", impl->OnFolderChange);
997 ok_(file, line)(!impl->OnSelectionChange, "OnSelectionChange: %d\n", impl->OnSelectionChange);
998 ok_(file, line)(!impl->OnShareViolation, "OnShareViolation: %d\n", impl->OnShareViolation);
999 ok_(file, line)(!impl->OnTypeChange, "OnTypeChange: %d\n", impl->OnTypeChange);
1000 ok_(file, line)(!impl->OnOverwrite, "OnOverwrite: %d\n", impl->OnOverwrite);
1001 impl->OnFileOk = impl->OnFolderChanging = impl->OnFolderChange = 0;
1002 impl->OnSelectionChange = impl->OnShareViolation = impl->OnTypeChange = 0;
1003 impl->OnOverwrite = 0;
1005 #define ensure_zero_events(impl) ensure_zero_events_(__FILE__, __LINE__, impl)
1007 static void test_advise_helper(IFileDialog *pfd)
1009 IFileDialogEventsImpl *pfdeimpl;
1010 IFileDialogEvents *pfde;
1011 DWORD cookie[10];
1012 UINT i;
1013 HRESULT hr;
1015 pfde = IFileDialogEvents_Constructor();
1016 pfdeimpl = impl_from_IFileDialogEvents(pfde);
1018 hr = IFileDialog_Advise(pfd, NULL, NULL);
1019 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
1020 hr = IFileDialog_Advise(pfd, pfde, NULL);
1021 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
1022 hr = IFileDialog_Advise(pfd, NULL, &cookie[0]);
1023 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
1024 ok(pfdeimpl->ref == 1, "got ref %d\n", pfdeimpl->ref);
1025 ensure_zero_events(pfdeimpl);
1027 hr = IFileDialog_Unadvise(pfd, 0);
1028 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
1029 for(i = 0; i < 10; i++) {
1030 hr = IFileDialog_Advise(pfd, pfde, &cookie[i]);
1031 ok(hr == S_OK, "got 0x%08x\n", hr);
1032 ok(cookie[i] == i+1, "Got cookie: %d\n", cookie[i]);
1034 ok(pfdeimpl->ref == 10+1, "got ref %d\n", pfdeimpl->ref);
1035 ensure_zero_events(pfdeimpl);
1037 for(i = 3; i < 7; i++) {
1038 hr = IFileDialog_Unadvise(pfd, cookie[i]);
1039 ok(hr == S_OK, "got 0x%08x\n", hr);
1041 ok(pfdeimpl->ref == 6+1, "got ref %d\n", pfdeimpl->ref);
1042 ensure_zero_events(pfdeimpl);
1044 for(i = 0; i < 3; i++) {
1045 hr = IFileDialog_Unadvise(pfd, cookie[i]);
1046 ok(hr == S_OK, "got 0x%08x\n", hr);
1048 ok(pfdeimpl->ref == 3+1, "got ref %d\n", pfdeimpl->ref);
1049 ensure_zero_events(pfdeimpl);
1051 for(i = 7; i < 10; i++) {
1052 hr = IFileDialog_Unadvise(pfd, cookie[i]);
1053 ok(hr == S_OK, "got 0x%08x\n", hr);
1055 ok(pfdeimpl->ref == 1, "got ref %d\n", pfdeimpl->ref);
1056 ensure_zero_events(pfdeimpl);
1058 hr = IFileDialog_Unadvise(pfd, cookie[9]+1);
1059 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
1060 ok(pfdeimpl->ref == 1, "got ref %d\n", pfdeimpl->ref);
1061 ensure_zero_events(pfdeimpl);
1063 hr = IFileDialog_Advise(pfd, pfde, &cookie[0]);
1064 ok(hr == S_OK, "got 0x%08x\n", hr);
1065 todo_wine ok(cookie[0] == 1, "got cookie: %d\n", cookie[0]);
1066 ok(pfdeimpl->ref == 1+1, "got ref %d\n", pfdeimpl->ref);
1067 ensure_zero_events(pfdeimpl);
1069 hr = IFileDialog_Unadvise(pfd, cookie[0]);
1071 if(0)
1073 /* Unadvising already unadvised cookies crashes on
1074 Windows 7. */
1075 IFileDialog_Unadvise(pfd, cookie[0]);
1079 IFileDialogEvents_Release(pfde);
1082 static void test_advise(void)
1084 IFileDialog *pfd;
1085 HRESULT hr;
1086 LONG ref;
1088 trace("Testing FileOpenDialog (advise)\n");
1089 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
1090 &IID_IFileDialog, (void**)&pfd);
1091 ok(hr == S_OK, "got 0x%08x.\n", hr);
1092 test_advise_helper(pfd);
1093 ref = IFileDialog_Release(pfd);
1094 ok(!ref, "Got refcount %d, should have been released.\n", ref);
1096 trace("Testing FileSaveDialog (advise)\n");
1097 hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER,
1098 &IID_IFileDialog, (void**)&pfd);
1099 ok(hr == S_OK, "got 0x%08x.\n", hr);
1100 test_advise_helper(pfd);
1101 ref = IFileDialog_Release(pfd);
1102 ok(!ref, "Got refcount %d, should have been released.\n", ref);
1105 static void filedialog_change_filetype(IFileDialog *pfd, HWND dlg_hwnd)
1107 HWND cb_filetype;
1108 const WCHAR filetype1[] = {'f','n','a','m','e','1',0};
1109 const WCHAR filetype1_broken[] = {'f','n','a','m','e','1',' ', '(','*','.','t','x','t',')',0};
1111 cb_filetype = find_window(dlg_hwnd, NULL, filetype1);
1112 ok(cb_filetype != NULL || broken(cb_filetype == NULL), "Could not find combobox on first attempt\n");
1114 if(!cb_filetype)
1116 /* Not sure when this happens. Some specific version?
1117 * Seen on 32-bit English Vista */
1118 trace("Didn't find combobox on first attempt, trying broken string..\n");
1119 cb_filetype = find_window(dlg_hwnd, NULL, filetype1_broken);
1120 ok(broken(cb_filetype != NULL), "Failed to find combobox on second attempt\n");
1121 if(!cb_filetype)
1122 return;
1125 /* Making the combobox send a CBN_SELCHANGE */
1126 SendMessageW( cb_filetype, CB_SHOWDROPDOWN, 1, 0 );
1127 SendMessageW( cb_filetype, CB_SETCURSEL, 1, 0 );
1128 SendMessageW( cb_filetype, WM_LBUTTONDOWN, 0, -1 );
1129 SendMessageW( cb_filetype, WM_LBUTTONUP, 0, -1 );
1132 static void test_events(void)
1134 IFileDialog *pfd;
1135 IFileDialogEventsImpl *pfdeimpl;
1136 IFileDialogEvents *pfde;
1137 DWORD cookie;
1138 ULONG ref;
1139 HRESULT hr;
1140 const WCHAR fname1[] = {'f','n','a','m','e','1', 0};
1141 const WCHAR fspec1[] = {'*','.','t','x','t',0};
1142 const WCHAR fname2[] = {'f','n','a','m','e','2', 0};
1143 const WCHAR fspec2[] = {'*','.','e','x','e',0};
1144 COMDLG_FILTERSPEC filterspec[3] = {{fname1, fspec1}, {fname2, fspec2}};
1148 * 1. Show the dialog with no filetypes added
1150 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
1151 &IID_IFileDialog, (void**)&pfd);
1152 ok(hr == S_OK, "got 0x%08x.\n", hr);
1154 pfde = IFileDialogEvents_Constructor();
1155 pfdeimpl = impl_from_IFileDialogEvents(pfde);
1156 pfdeimpl->events_test = IFDEVENT_TEST2;
1158 hr = IFileDialog_Advise(pfd, pfde, &cookie);
1159 ok(hr == S_OK, "got 0x%08x.\n", hr);
1161 hr = IFileDialog_Show(pfd, NULL);
1162 ok(hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "got 0x%08x.\n", hr);
1164 ok(pfdeimpl->OnFolderChanging == 1, "Got %d\n", pfdeimpl->OnFolderChanging);
1165 pfdeimpl->OnFolderChanging = 0;
1166 ok(pfdeimpl->OnFolderChange == 1, "Got %d\n", pfdeimpl->OnFolderChange);
1167 pfdeimpl->OnFolderChange = 0;
1168 /* pfdeimpl->OnSelectionChange too unreliable to test. Can be 0, 1 or even 2. */
1169 pfdeimpl->OnSelectionChange = 0;
1170 ok(pfdeimpl->OnTypeChange == 0, "Got %d\n", pfdeimpl->OnTypeChange);
1171 pfdeimpl->OnTypeChange = 0;
1173 ensure_zero_events(pfdeimpl);
1175 hr = IFileDialog_Unadvise(pfd, cookie);
1176 ok(hr == S_OK, "got 0x%08x.\n", hr);
1178 IFileDialogEvents_Release(pfde);
1179 ref = IFileDialog_Release(pfd);
1180 ok(!ref || broken(ref /* win2008_64 (intermittently) */), "Got %d\n", ref);
1184 * 2. Show the dialog with filetypes added
1186 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
1187 &IID_IFileDialog, (void**)&pfd);
1188 ok(hr == S_OK, "got 0x%08x.\n", hr);
1190 pfde = IFileDialogEvents_Constructor();
1191 pfdeimpl = impl_from_IFileDialogEvents(pfde);
1192 pfdeimpl->events_test = IFDEVENT_TEST2;
1194 hr = IFileDialog_Advise(pfd, pfde, &cookie);
1195 ok(hr == S_OK, "got 0x%08x.\n", hr);
1197 hr = IFileDialog_SetFileTypes(pfd, 2, filterspec);
1198 ok(hr == S_OK, "got 0x%08x.\n", hr);
1200 ensure_zero_events(pfdeimpl);
1202 hr = IFileDialog_Show(pfd, NULL);
1203 ok(hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "got 0x%08x.\n", hr);
1205 ok(pfdeimpl->OnFolderChanging == 1, "Got %d\n", pfdeimpl->OnFolderChanging);
1206 pfdeimpl->OnFolderChanging = 0;
1207 ok(pfdeimpl->OnFolderChange == 1, "Got %d\n", pfdeimpl->OnFolderChange);
1208 pfdeimpl->OnFolderChange = 0;
1209 /* pfdeimpl->OnSelectionChange too unreliable to test. Can be 0, 1 or even 2. */
1210 pfdeimpl->OnSelectionChange = 0;
1211 /* Called once just by showing the dialog */
1212 ok(pfdeimpl->OnTypeChange == 1, "Got %d\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%08x.\n", hr);
1220 IFileDialogEvents_Release(pfde);
1221 ref = IFileDialog_Release(pfd);
1222 ok(!ref || broken(ref /* win2008_64 (intermittently) */), "Got %d\n", ref);
1226 * 3. Show the dialog with filetypes added and simulate manual change of filetype
1228 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
1229 &IID_IFileDialog, (void**)&pfd);
1230 ok(hr == S_OK, "got 0x%08x.\n", hr);
1232 pfde = IFileDialogEvents_Constructor();
1233 pfdeimpl = impl_from_IFileDialogEvents(pfde);
1234 pfdeimpl->events_test = IFDEVENT_TEST3;
1236 hr = IFileDialog_Advise(pfd, pfde, &cookie);
1237 ok(hr == S_OK, "got 0x%08x.\n", hr);
1239 hr = IFileDialog_SetFileTypes(pfd, 2, filterspec);
1240 ok(hr == S_OK, "got 0x%08x.\n", hr);
1242 ensure_zero_events(pfdeimpl);
1244 hr = IFileDialog_Show(pfd, NULL);
1245 ok(hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "got 0x%08x.\n", hr);
1247 ok(pfdeimpl->OnFolderChanging == 1, "Got %d\n", pfdeimpl->OnFolderChanging);
1248 pfdeimpl->OnFolderChanging = 0;
1249 ok(pfdeimpl->OnFolderChange == 1, "Got %d\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 by showing the dialog and once again when changing the filetype */
1254 todo_wine ok(pfdeimpl->OnTypeChange == 2, "Got %d\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%08x.\n", hr);
1262 IFileDialogEvents_Release(pfde);
1263 ref = IFileDialog_Release(pfd);
1264 ok(!ref || broken(ref /* win2008_64 (intermittently) */), "Got %d\n", ref);
1267 static void touch_file(LPCWSTR filename)
1269 HANDLE file;
1270 file = CreateFileW(filename, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
1271 ok(file != INVALID_HANDLE_VALUE, "Failed to create file.\n");
1272 CloseHandle(file);
1275 static void test_filename_savedlg_(LPCWSTR set_filename, LPCWSTR defext,
1276 const COMDLG_FILTERSPEC *filterspec, UINT fs_count,
1277 LPCWSTR exp_filename, const char *file, int line)
1279 IFileSaveDialog *pfsd;
1280 IFileDialogEventsImpl *pfdeimpl;
1281 IFileDialogEvents *pfde;
1282 DWORD cookie;
1283 LPWSTR filename;
1284 IShellItem *psi;
1285 LONG ref;
1286 HRESULT hr;
1288 hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER,
1289 &IID_IFileSaveDialog, (void**)&pfsd);
1290 ok_(file,line)(hr == S_OK, "Got 0x%08x\n", hr);
1292 if(fs_count)
1294 hr = IFileSaveDialog_SetFileTypes(pfsd, fs_count, filterspec);
1295 ok_(file,line)(hr == S_OK, "SetFileTypes failed: Got 0x%08x\n", hr);
1298 if(defext)
1300 hr = IFileSaveDialog_SetDefaultExtension(pfsd, defext);
1301 ok_(file,line)(hr == S_OK, "SetDefaultExtensions failed: Got 0x%08x\n", hr);
1304 pfde = IFileDialogEvents_Constructor();
1305 pfdeimpl = impl_from_IFileDialogEvents(pfde);
1306 pfdeimpl->set_filename = set_filename;
1307 hr = IFileSaveDialog_Advise(pfsd, pfde, &cookie);
1308 ok_(file,line)(hr == S_OK, "Advise failed: Got 0x%08x\n", hr);
1310 hr = IFileSaveDialog_Show(pfsd, NULL);
1311 ok_(file,line)(hr == S_OK, "Show failed: Got 0x%08x\n", hr);
1313 hr = IFileSaveDialog_GetFileName(pfsd, &filename);
1314 ok_(file,line)(hr == S_OK, "GetFileName failed: Got 0x%08x\n", hr);
1315 ok_(file,line)(!lstrcmpW(filename, set_filename), "Got %s\n", wine_dbgstr_w(filename));
1316 CoTaskMemFree(filename);
1318 hr = IFileSaveDialog_GetResult(pfsd, &psi);
1319 ok_(file,line)(hr == S_OK, "GetResult failed: Got 0x%08x\n", hr);
1321 hr = IShellItem_GetDisplayName(psi, SIGDN_PARENTRELATIVEPARSING, &filename);
1322 ok_(file,line)(hr == S_OK, "GetDisplayName failed: Got 0x%08x\n", hr);
1323 ok_(file,line)(!lstrcmpW(filename, exp_filename), "(GetDisplayName) Got %s\n", wine_dbgstr_w(filename));
1324 CoTaskMemFree(filename);
1325 IShellItem_Release(psi);
1327 hr = IFileSaveDialog_Unadvise(pfsd, cookie);
1328 ok_(file,line)(hr == S_OK, "Unadvise failed: Got 0x%08x\n", hr);
1330 ref = IFileSaveDialog_Release(pfsd);
1331 ok_(file,line)(!ref, "Got refcount %d, should have been released.\n", ref);
1333 IFileDialogEvents_Release(pfde);
1335 #define test_filename_savedlg(set_filename, defext, filterspec, fs_count, exp_filename) \
1336 test_filename_savedlg_(set_filename, defext, filterspec, fs_count, exp_filename, __FILE__, __LINE__)
1338 static void test_filename_opendlg_(LPCWSTR set_filename, IShellItem *psi_current, LPCWSTR defext,
1339 const COMDLG_FILTERSPEC *filterspec, UINT fs_count,
1340 LPCWSTR exp_filename, const char *file, int line)
1342 IFileOpenDialog *pfod;
1343 IFileDialogEventsImpl *pfdeimpl;
1344 IFileDialogEvents *pfde;
1345 DWORD cookie;
1346 LPWSTR filename;
1347 IShellItemArray *psia;
1348 IShellItem *psi;
1349 LONG ref;
1350 HRESULT hr;
1352 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
1353 &IID_IFileOpenDialog, (void**)&pfod);
1354 ok_(file,line)(hr == S_OK, "CoCreateInstance failed: Got 0x%08x\n", hr);
1356 if(defext)
1358 hr = IFileOpenDialog_SetDefaultExtension(pfod, defext);
1359 ok_(file,line)(hr == S_OK, "SetDefaultExtensions failed: Got 0x%08x\n", hr);
1362 if(fs_count)
1364 hr = IFileOpenDialog_SetFileTypes(pfod, 2, filterspec);
1365 ok_(file,line)(hr == S_OK, "SetFileTypes failed: Got 0x%08x\n", hr);
1368 hr = IFileOpenDialog_SetFolder(pfod, psi_current);
1369 ok_(file,line)(hr == S_OK, "SetFolder failed: Got 0x%08x\n", hr);
1371 pfde = IFileDialogEvents_Constructor();
1372 pfdeimpl = impl_from_IFileDialogEvents(pfde);
1373 pfdeimpl->set_filename = set_filename;
1374 pfdeimpl->set_filename_tried = FALSE;
1375 hr = IFileOpenDialog_Advise(pfod, pfde, &cookie);
1376 ok_(file,line)(hr == S_OK, "Advise failed: Got 0x%08x\n", hr);
1378 hr = IFileOpenDialog_Show(pfod, NULL);
1379 ok_(file,line)(hr == S_OK || (!exp_filename && hr == HRESULT_FROM_WIN32(ERROR_CANCELLED)),
1380 "Show failed: Got 0x%08x\n", hr);
1381 if(hr == S_OK)
1383 hr = IFileOpenDialog_GetResult(pfod, &psi);
1384 ok_(file,line)(hr == S_OK, "GetResult failed: Got 0x%08x\n", hr);
1386 hr = IShellItem_GetDisplayName(psi, SIGDN_PARENTRELATIVEPARSING, &filename);
1387 ok_(file,line)(hr == S_OK, "GetDisplayName(Result) failed: Got 0x%08x\n", hr);
1388 ok_(file,line)(!lstrcmpW(filename, exp_filename), "(GetResult) Got %s\n", wine_dbgstr_w(filename));
1389 CoTaskMemFree(filename);
1390 IShellItem_Release(psi);
1392 hr = IFileOpenDialog_GetResults(pfod, &psia);
1393 ok_(file,line)(hr == S_OK, "GetResults failed: Got 0x%08x\n", hr);
1394 hr = IShellItemArray_GetItemAt(psia, 0, &psi);
1395 ok_(file,line)(hr == S_OK, "GetItemAt failed: Got 0x%08x\n", hr);
1397 hr = IShellItem_GetDisplayName(psi, SIGDN_PARENTRELATIVEPARSING, &filename);
1398 ok_(file,line)(hr == S_OK, "GetDisplayName(Results) failed: Got 0x%08x\n", hr);
1399 ok_(file,line)(!lstrcmpW(filename, exp_filename), "(GetResults) Got %s\n", wine_dbgstr_w(filename));
1400 CoTaskMemFree(filename);
1402 IShellItem_Release(psi);
1403 IShellItemArray_Release(psia);
1405 else
1407 hr = IFileOpenDialog_GetResult(pfod, &psi);
1408 ok_(file,line)(hr == E_UNEXPECTED, "GetResult: Got 0x%08x\n", hr);
1410 hr = IFileOpenDialog_GetResults(pfod, &psia);
1411 ok_(file,line)(hr == E_FAIL, "GetResults: Got 0x%08x\n", hr);
1414 hr = IFileOpenDialog_GetFileName(pfod, &filename);
1415 ok_(file,line)(hr == S_OK, "GetFileName failed: Got 0x%08x\n", hr);
1416 ok_(file,line)(!lstrcmpW(filename, set_filename), "(GetFileName) Got %s\n", wine_dbgstr_w(filename));
1417 CoTaskMemFree(filename);
1420 hr = IFileOpenDialog_Unadvise(pfod, cookie);
1421 ok_(file,line)(hr == S_OK, "Unadvise failed: Got 0x%08x\n", hr);
1423 ref = IFileOpenDialog_Release(pfod);
1424 ok_(file,line)(!ref, "Got refcount %d, should have been released.\n", ref);
1426 IFileDialogEvents_Release(pfde);
1428 #define test_filename_opendlg(set_filename, psi, defext, filterspec, fs_count, exp_filename) \
1429 test_filename_opendlg_(set_filename, psi, defext, filterspec, fs_count, exp_filename, __FILE__, __LINE__)
1431 static void test_filename(void)
1433 IShellItem *psi_current;
1434 HRESULT hr;
1435 WCHAR buf[MAX_PATH];
1437 static const WCHAR filename_noextW[] = {'w','i','n','e','t','e','s','t',0};
1438 static const WCHAR filename_dotextW[] = {'w','i','n','e','t','e','s','t','.',0};
1439 static const WCHAR filename_dotanddefW[] = {'w','i','n','e','t','e','s','t','.','.','w','t','e',0};
1440 static const WCHAR filename_defextW[] = {'w','i','n','e','t','e','s','t','.','w','t','e',0};
1441 static const WCHAR filename_ext1W[] = {'w','i','n','e','t','e','s','t','.','w','t','1',0};
1442 static const WCHAR filename_ext2W[] = {'w','i','n','e','t','e','s','t','.','w','t','2',0};
1443 static const WCHAR filename_ext1anddefW[] =
1444 {'w','i','n','e','t','e','s','t','.','w','t','1','.','w','t','e',0};
1445 static const WCHAR defextW[] = {'w','t','e',0};
1446 static const WCHAR desc1[] = {'d','e','s','c','r','i','p','t','i','o','n','1',0};
1447 static const WCHAR desc2[] = {'d','e','s','c','r','i','p','t','i','o','n','2',0};
1448 static const WCHAR descdef[] = {'d','e','f','a','u','l','t',' ','d','e','s','c',0};
1449 static const WCHAR ext1[] = {'*','.','w','t','1',0};
1450 static const WCHAR ext2[] = {'*','.','w','t','2',0};
1451 static const WCHAR extdef[] = {'*','.','w','t','e',0};
1452 static const WCHAR complexext[] = {'*','.','w','t','2',';','*','.','w','t','1',0};
1454 static const COMDLG_FILTERSPEC filterspec[] = {
1455 { desc1, ext1 }, { desc2, ext2 }, { descdef, extdef }
1457 static const COMDLG_FILTERSPEC filterspec2[] = {
1458 { desc1, complexext }
1461 /* No extension */
1462 test_filename_savedlg(filename_noextW, NULL, NULL, 0, filename_noextW);
1463 /* Default extension */
1464 test_filename_savedlg(filename_noextW, defextW, NULL, 0, filename_defextW);
1465 /* Default extension on filename ending with a . */
1466 test_filename_savedlg(filename_dotextW, defextW, NULL, 0, filename_dotanddefW);
1467 /* Default extension on filename with default extension */
1468 test_filename_savedlg(filename_defextW, defextW, NULL, 0, filename_defextW);
1469 /* Default extension on filename with another extension */
1470 test_filename_savedlg(filename_ext1W, defextW, NULL, 0, filename_ext1anddefW);
1471 /* Default extension, filterspec without default extension */
1472 test_filename_savedlg(filename_noextW, defextW, filterspec, 2, filename_ext1W);
1473 /* Default extension, filterspec with default extension */
1474 test_filename_savedlg(filename_noextW, defextW, filterspec, 3, filename_ext1W);
1475 /* Default extension, filterspec with "complex" extension */
1476 test_filename_savedlg(filename_noextW, defextW, filterspec2, 1, filename_ext2W);
1478 GetCurrentDirectoryW(MAX_PATH, buf);
1479 ok(!!pSHCreateItemFromParsingName, "SHCreateItemFromParsingName is missing.\n");
1480 hr = pSHCreateItemFromParsingName(buf, NULL, &IID_IShellItem, (void**)&psi_current);
1481 ok(hr == S_OK, "Got 0x%08x\n", hr);
1483 touch_file(filename_noextW);
1484 touch_file(filename_defextW);
1485 touch_file(filename_ext2W);
1487 /* IFileOpenDialog, default extension */
1488 test_filename_opendlg(filename_noextW, psi_current, defextW, NULL, 0, filename_noextW);
1489 /* IFileOpenDialog, default extension and filterspec */
1490 test_filename_opendlg(filename_noextW, psi_current, defextW, filterspec, 2, filename_noextW);
1492 DeleteFileW(filename_noextW);
1493 /* IFileOpenDialog, default extension, noextW deleted */
1494 test_filename_opendlg(filename_noextW, psi_current, defextW, NULL, 0, filename_defextW);
1495 if(0) /* Interactive */
1497 /* IFileOpenDialog, filterspec, no default extension, noextW deleted */
1498 test_filename_opendlg(filename_noextW, psi_current, NULL, filterspec, 2, NULL);
1501 IShellItem_Release(psi_current);
1502 DeleteFileW(filename_defextW);
1503 DeleteFileW(filename_ext2W);
1506 static const WCHAR label[] = {'l','a','b','e','l',0};
1507 static const WCHAR label2[] = {'t','e','s','t',0};
1508 static const WCHAR menuW[] = {'m','e','n','u','_','i','t','e','m',0};
1509 static const WCHAR pushbutton1W[] = {'p','u','s','h','b','u','t','t','o','n','_','i','t','e','m',0};
1510 static const WCHAR pushbutton2W[] = {'p','u','s','h','b','u','t','t','o','n','2','_','i','t','e','m',0};
1511 static const WCHAR comboboxitem1W[] = {'c','o','m','b','o','b','o','x','1','_','i','t','e','m',0};
1512 static const WCHAR comboboxitem2W[] = {'c','o','m','b','o','b','o','x','2','_','i','t','e','m',0};
1513 static const WCHAR radiobutton1W[] = {'r','a','d','i','o','b','u','t','t','o','n','1','_','i','t','e','m',0};
1514 static const WCHAR radiobutton2W[] = {'r','a','d','i','o','b','u','t','t','o','n','2','_','i','t','e','m',0};
1515 static const WCHAR checkbutton1W[] = {'c','h','e','c','k','b','u','t','t','o','n','1','_','i','t','e','m',0};
1516 static const WCHAR checkbutton2W[] = {'c','h','e','c','k','b','u','t','t','o','n','2','_','i','t','e','m',0};
1517 static const WCHAR editbox1W[] = {'e','d','i','t','b','o','x','W','1','_','i','t','e','m',0};
1518 static const WCHAR editbox2W[] = {'e','d','i','t','b','o','x','W','2','_','i','t','e','m',0};
1519 static const WCHAR textW[] = {'t','e','x','t','_','i','t','e','m',0};
1520 static const WCHAR text2W[] = {'t','e','x','t','2','_','i','t','e','m',0};
1521 static const WCHAR separatorW[] = {'s','e','p','a','r','a','t','o','r','_','i','t','e','m',0};
1522 static const WCHAR visualgroup1W[] = {'v','i','s','u','a','l','g','r','o','u','p','1',0};
1523 static const WCHAR visualgroup2W[] = {'v','i','s','u','a','l','g','r','o','u','p','2',0};
1525 static const WCHAR floatnotifysinkW[] = {'F','l','o','a','t','N','o','t','i','f','y','S','i','n','k',0};
1526 static const WCHAR RadioButtonListW[] = {'R','a','d','i','o','B','u','t','t','o','n','L','i','s','t',0};
1528 static void test_customize_onfolderchange(IFileDialog *pfd)
1530 HWND dlg_hwnd, item, item_parent;
1531 BOOL br;
1532 WCHAR buf[1024];
1534 buf[0] = '\0';
1536 dlg_hwnd = get_hwnd_from_ifiledialog(pfd);
1537 ok(dlg_hwnd != NULL, "Got NULL.\n");
1539 item = find_window(dlg_hwnd, NULL, checkbutton2W);
1540 ok(item != NULL, "Failed to find item.\n");
1541 item_parent = GetParent(item);
1542 GetClassNameW(item_parent, buf, 1024);
1543 ok(!lstrcmpW(buf, floatnotifysinkW), "Got %s\n", wine_dbgstr_w(buf));
1544 item = find_window(dlg_hwnd, NULL, text2W);
1545 ok(item != NULL, "Failed to find item.\n");
1546 item_parent = GetParent(item);
1547 GetClassNameW(item_parent, buf, 1024);
1548 ok(!lstrcmpW(buf, floatnotifysinkW), "Got %s\n", wine_dbgstr_w(buf));
1549 item = find_window(dlg_hwnd, NULL, radiobutton1W);
1550 todo_wine ok(item != NULL, "Failed to find item.\n");
1551 item_parent = GetParent(item);
1552 GetClassNameW(item_parent, buf, 1024);
1553 todo_wine ok(!lstrcmpW(buf, RadioButtonListW), "Got %s\n", wine_dbgstr_w(buf));
1554 item_parent = GetParent(item_parent);
1555 GetClassNameW(item_parent, buf, 1024);
1556 ok(!lstrcmpW(buf, floatnotifysinkW), "Got %s\n", wine_dbgstr_w(buf));
1558 item = find_window(dlg_hwnd, NULL, pushbutton1W);
1559 ok(item == NULL, "Found item: %p\n", item);
1560 item = find_window(dlg_hwnd, NULL, pushbutton2W);
1561 ok(item == NULL, "Found item: %p\n", item);
1562 item = find_window(dlg_hwnd, NULL, comboboxitem1W);
1563 ok(item == NULL, "Found item: %p\n", item);
1564 item = find_window(dlg_hwnd, NULL, comboboxitem2W);
1565 ok(item == NULL, "Found item: %p\n", item);
1566 item = find_window(dlg_hwnd, NULL, radiobutton2W);
1567 ok(item == NULL, "Found item: %p\n", item);
1568 item = find_window(dlg_hwnd, NULL, checkbutton1W);
1569 ok(item == NULL, "Found item: %p\n", item);
1570 item = find_window(dlg_hwnd, NULL, editbox1W);
1571 ok(item == NULL, "Found item: %p\n", item);
1572 item = find_window(dlg_hwnd, NULL, editbox2W);
1573 ok(item == NULL, "Found item: %p\n", item);
1574 item = find_window(dlg_hwnd, NULL, textW);
1575 ok(item == NULL, "Found item: %p\n", item);
1576 item = find_window(dlg_hwnd, NULL, separatorW);
1577 ok(item == NULL, "Found item: %p\n", item);
1578 item = find_window(dlg_hwnd, NULL, visualgroup1W);
1579 ok(item == NULL, "Found item: %p\n", item);
1580 item = find_window(dlg_hwnd, NULL, visualgroup2W);
1581 todo_wine ok(item == NULL, "Found item: %p\n", item);
1583 br = PostMessageW(dlg_hwnd, WM_COMMAND, IDCANCEL, 0);
1584 ok(br, "Failed\n");
1587 static void test_customize(void)
1589 IFileDialog *pfod;
1590 IFileDialogCustomize *pfdc;
1591 IFileDialogEventsImpl *pfdeimpl;
1592 IFileDialogEvents *pfde;
1593 IOleWindow *pow;
1594 CDCONTROLSTATEF cdstate;
1595 DWORD cookie;
1596 LPWSTR tmpstr;
1597 UINT i;
1598 UINT id_vgroup1, id_text, id_editbox1;
1599 LONG ref;
1600 HWND dlg_hwnd;
1601 HRESULT hr;
1602 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
1603 &IID_IFileDialog, (void**)&pfod);
1604 ok(hr == S_OK, "got 0x%08x.\n", hr);
1606 hr = IFileDialog_QueryInterface(pfod, &IID_IFileDialogCustomize, (void**)&pfdc);
1607 ok(hr == S_OK, "got 0x%08x.\n", hr);
1608 if(FAILED(hr))
1610 skip("Skipping IFileDialogCustomize tests.\n");
1611 IFileDialog_Release(pfod);
1612 return;
1615 i = 0;
1616 hr = IFileDialogCustomize_AddPushButton(pfdc, i, pushbutton1W);
1617 ok(hr == S_OK, "got 0x%08x.\n", hr);
1618 hr = IFileDialogCustomize_AddPushButton(pfdc, i, pushbutton1W);
1619 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1621 hr = IFileDialog_QueryInterface(pfod, &IID_IOleWindow, (void**)&pow);
1622 ok(hr == S_OK, "Got 0x%08x\n", hr);
1623 hr = IOleWindow_GetWindow(pow, &dlg_hwnd);
1624 ok(hr == S_OK, "Got 0x%08x\n", hr);
1625 ok(dlg_hwnd == NULL, "NULL\n");
1626 IOleWindow_Release(pow);
1628 cdstate = 0xdeadbeef;
1629 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1630 ok(hr == S_OK, "got 0x%08x.\n", hr);
1631 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1633 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1634 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
1636 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1637 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1639 hr = IFileDialogCustomize_EnableOpenDropDown(pfdc, i);
1640 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1641 hr = IFileDialogCustomize_EnableOpenDropDown(pfdc, ++i);
1642 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1644 cdstate = 0xdeadbeef;
1645 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1646 ok(hr == E_NOTIMPL, "got 0x%08x.\n", hr);
1647 ok(cdstate == 0xdeadbeef, "got 0x%08x.\n", cdstate);
1649 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1650 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1651 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1652 todo_wine ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
1654 cdstate = 0xdeadbeef;
1655 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1656 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1657 todo_wine ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1658 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, 0);
1659 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1660 cdstate = 0xdeadbeef;
1661 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1662 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1663 todo_wine ok(!cdstate, "got 0x%08x.\n", cdstate);
1664 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, CDCS_ENABLEDVISIBLE);
1665 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1666 cdstate = 0xdeadbeef;
1667 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1668 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1669 todo_wine ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1671 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1672 todo_wine ok(hr == E_NOTIMPL, "got 0x%08x (control: %d).\n", hr, i);
1674 hr = IFileDialogCustomize_AddMenu(pfdc, i, menuW);
1675 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1676 hr = IFileDialogCustomize_AddMenu(pfdc, ++i, label);
1677 ok(hr == S_OK, "got 0x%08x.\n", hr);
1679 cdstate = 0xdeadbeef;
1680 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1681 ok(hr == S_OK, "got 0x%08x.\n", hr);
1682 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1684 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1685 ok(hr == S_OK, "got 0x%08x.\n", hr);
1686 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1687 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
1689 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1690 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1692 hr = IFileDialogCustomize_AddPushButton(pfdc, i, pushbutton2W);
1693 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1694 hr = IFileDialogCustomize_AddPushButton(pfdc, ++i, pushbutton2W);
1695 ok(hr == S_OK, "got 0x%08x.\n", hr);
1697 cdstate = 0xdeadbeef;
1698 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1699 ok(hr == S_OK, "got 0x%08x.\n", hr);
1700 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1702 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1703 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
1705 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1706 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1708 hr = IFileDialogCustomize_AddComboBox(pfdc, i);
1709 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1710 hr = IFileDialogCustomize_AddComboBox(pfdc, ++i);
1711 ok(hr == S_OK, "got 0x%08x.\n", hr);
1713 cdstate = 0xdeadbeef;
1714 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1715 ok(hr == S_OK, "got 0x%08x.\n", hr);
1716 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1718 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1719 ok(hr == S_OK, "got 0x%08x.\n", hr);
1720 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1721 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
1723 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1724 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1726 hr = IFileDialogCustomize_AddRadioButtonList(pfdc, i);
1727 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1728 hr = IFileDialogCustomize_AddRadioButtonList(pfdc, ++i);
1729 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1731 cdstate = 0xdeadbeef;
1732 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1733 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1734 todo_wine ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1736 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, radiobutton1W);
1737 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1738 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, radiobutton1W);
1739 todo_wine ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
1741 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, radiobutton2W);
1742 todo_wine ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1744 hr = IFileDialogCustomize_AddCheckButton(pfdc, i, label, TRUE);
1745 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1746 hr = IFileDialogCustomize_AddCheckButton(pfdc, ++i, checkbutton1W, TRUE);
1747 ok(hr == S_OK, "got 0x%08x.\n", hr);
1749 cdstate = 0xdeadbeef;
1750 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1751 ok(hr == S_OK, "got 0x%08x.\n", hr);
1752 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1754 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1755 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
1757 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, checkbutton2W);
1758 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1760 if(SUCCEEDED(hr))
1762 BOOL checked;
1763 hr = IFileDialogCustomize_GetCheckButtonState(pfdc, i, &checked);
1764 ok(hr == S_OK, "got 0x%08x.\n", hr);
1765 ok(checked, "checkbox not checked.\n");
1767 hr = IFileDialogCustomize_SetCheckButtonState(pfdc, i, FALSE);
1768 ok(hr == S_OK, "got 0x%08x.\n", hr);
1770 hr = IFileDialogCustomize_GetCheckButtonState(pfdc, i, &checked);
1771 ok(hr == S_OK, "got 0x%08x.\n", hr);
1772 ok(!checked, "checkbox checked.\n");
1774 hr = IFileDialogCustomize_SetCheckButtonState(pfdc, i, TRUE);
1775 ok(hr == S_OK, "got 0x%08x.\n", hr);
1777 hr = IFileDialogCustomize_GetCheckButtonState(pfdc, i, &checked);
1778 ok(hr == S_OK, "got 0x%08x.\n", hr);
1779 ok(checked, "checkbox not checked.\n");
1782 hr = IFileDialogCustomize_AddEditBox(pfdc, i, label);
1783 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1784 hr = IFileDialogCustomize_AddEditBox(pfdc, ++i, editbox1W);
1785 ok(hr == S_OK, "got 0x%08x.\n", hr);
1787 cdstate = 0xdeadbeef;
1788 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1789 ok(hr == S_OK, "got 0x%08x.\n", hr);
1790 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1792 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1793 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
1795 /* Does not affect the text in the editbox */
1796 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, editbox2W);
1797 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1799 hr = IFileDialogCustomize_GetEditBoxText(pfdc, i, &tmpstr);
1800 ok(hr == S_OK, "got 0x%08x.\n", hr);
1801 if(SUCCEEDED(hr))
1803 ok(!lstrcmpW(tmpstr, editbox1W), "got %s.\n", wine_dbgstr_w(tmpstr));
1804 CoTaskMemFree(tmpstr);
1807 hr = IFileDialogCustomize_SetEditBoxText(pfdc, i, label2);
1808 ok(hr == S_OK, "got 0x%08x.\n", hr);
1810 hr = IFileDialogCustomize_GetEditBoxText(pfdc, i, &tmpstr);
1811 ok(hr == S_OK, "got 0x%08x.\n", hr);
1812 if(SUCCEEDED(hr))
1814 ok(!lstrcmpW(tmpstr, label2), "got %s.\n", wine_dbgstr_w(tmpstr));
1815 CoTaskMemFree(tmpstr);
1818 hr = IFileDialogCustomize_AddSeparator(pfdc, i);
1819 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1820 hr = IFileDialogCustomize_AddSeparator(pfdc, ++i);
1821 ok(hr == S_OK, "got 0x%08x.\n", hr);
1823 cdstate = 0xdeadbeef;
1824 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1825 ok(hr == S_OK, "got 0x%08x.\n", hr);
1826 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1828 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1829 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
1831 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, separatorW);
1832 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1834 hr = IFileDialogCustomize_AddText(pfdc, i, label);
1835 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1836 hr = IFileDialogCustomize_AddText(pfdc, ++i, textW);
1837 ok(hr == S_OK, "got 0x%08x.\n", hr);
1839 cdstate = 0xdeadbeef;
1840 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1841 ok(hr == S_OK, "got 0x%08x.\n", hr);
1842 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1844 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1845 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
1847 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, text2W);
1848 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1850 hr = IFileDialogCustomize_StartVisualGroup(pfdc, i, label);
1851 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1852 hr = IFileDialogCustomize_StartVisualGroup(pfdc, ++i, visualgroup1W);
1853 ok(hr == S_OK, "got 0x%08x.\n", hr);
1855 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1856 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
1858 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, visualgroup2W);
1859 ok(hr == S_OK, "got 0x%08x (control: %d).\n", hr, i);
1861 cdstate = 0xdeadbeef;
1862 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1863 ok(hr == S_OK, "got 0x%08x.\n", hr);
1864 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1866 hr = IFileDialogCustomize_StartVisualGroup(pfdc, ++i, label);
1867 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
1868 hr = IFileDialogCustomize_EndVisualGroup(pfdc);
1869 ok(hr == S_OK, "got 0x%08x.\n", hr);
1871 i++; /* Nonexisting control */
1872 hr = IFileDialogCustomize_AddControlItem(pfdc, i, 0, label);
1873 todo_wine ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
1874 hr = IFileDialogCustomize_SetControlLabel(pfdc, i, label2);
1875 ok(hr == E_INVALIDARG, "got 0x%08x (control: %d).\n", hr, i);
1876 cdstate = 0xdeadbeef;
1877 hr = IFileDialogCustomize_GetControlState(pfdc, i, &cdstate);
1878 todo_wine ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
1879 ok(cdstate == 0xdeadbeef, "got 0x%08x.\n", cdstate);
1881 pfde = IFileDialogEvents_Constructor();
1882 pfdeimpl = impl_from_IFileDialogEvents(pfde);
1883 pfdeimpl->events_test = IFDEVENT_TEST1;
1884 hr = IFileDialog_Advise(pfod, pfde, &cookie);
1885 ok(hr == S_OK, "Got 0x%08x\n", hr);
1887 hr = IFileDialog_Show(pfod, NULL);
1888 ok(hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "Got 0x%08x\n", hr);
1890 hr = IFileDialog_Unadvise(pfod, cookie);
1891 ok(hr == S_OK, "Got 0x%08x\n", hr);
1893 IFileDialogEvents_Release(pfde);
1894 IFileDialogCustomize_Release(pfdc);
1895 ref = IFileDialog_Release(pfod);
1896 ok(!ref, "Refcount not zero (%d).\n", ref);
1899 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
1900 &IID_IFileDialog, (void**)&pfod);
1901 ok(hr == S_OK, "got 0x%08x.\n", hr);
1903 hr = IFileDialog_QueryInterface(pfod, &IID_IFileDialogCustomize, (void**)&pfdc);
1904 ok(hr == S_OK, "got 0x%08x.\n", hr);
1906 i = 0;
1907 hr = IFileDialogCustomize_AddMenu(pfdc, ++i, label);
1908 ok(hr == S_OK, "got 0x%08x.\n", hr);
1909 if(SUCCEEDED(hr))
1911 DWORD selected;
1912 UINT j = 0;
1914 for(j = 0; j < 10; j++)
1916 hr = IFileDialogCustomize_AddControlItem(pfdc, i, j, label);
1917 ok(hr == S_OK, "got 0x%08x.\n", hr);
1920 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
1921 ok(hr == E_NOTIMPL, "got 0x%08x.\n", hr);
1923 cdstate = 0xdeadbeef;
1924 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1925 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1926 todo_wine ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1927 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, 0);
1928 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1929 cdstate = 0xdeadbeef;
1930 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1931 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1932 todo_wine ok(cdstate == 0, "got 0x%08x.\n", cdstate);
1933 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, CDCS_ENABLEDVISIBLE);
1934 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1935 cdstate = 0xdeadbeef;
1936 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1937 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
1938 todo_wine ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1940 hr = IFileDialogCustomize_RemoveAllControlItems(pfdc, i);
1941 ok(hr == E_NOTIMPL, "got 0x%08x.\n", hr);
1943 for(j = 0; j < 10; j++)
1945 hr = IFileDialogCustomize_RemoveControlItem(pfdc, i, j);
1946 ok(hr == S_OK, "got 0x%08x.\n", hr);
1949 hr = IFileDialogCustomize_AddPushButton(pfdc, ++i, label);
1950 ok(hr == S_OK, "got 0x%08x.\n", hr);
1951 hr = IFileDialogCustomize_AddComboBox(pfdc, ++i);
1952 ok(hr == S_OK, "got 0x%08x.\n", hr);
1953 if(SUCCEEDED(hr))
1955 DWORD selected = -1;
1956 UINT j = 0;
1958 for(j = 0; j < 10; j++)
1960 hr = IFileDialogCustomize_AddControlItem(pfdc, i, j, label);
1961 ok(hr == S_OK, "got 0x%08x.\n", hr);
1964 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
1965 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
1966 ok(selected == -1, "got %d.\n", selected);
1968 todo_wine {
1969 cdstate = 0xdeadbeef;
1970 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1971 ok(hr == S_OK, "got 0x%08x.\n", hr);
1972 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1973 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, 0);
1974 ok(hr == S_OK, "got 0x%08x.\n", hr);
1975 cdstate = 0xdeadbeef;
1976 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1977 ok(hr == S_OK, "got 0x%08x.\n", hr);
1978 ok(cdstate == 0, "got 0x%08x.\n", cdstate);
1979 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, CDCS_ENABLEDVISIBLE);
1980 ok(hr == S_OK, "got 0x%08x.\n", hr);
1981 cdstate = 0xdeadbeef;
1982 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
1983 ok(hr == S_OK, "got 0x%08x.\n", hr);
1984 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
1987 for(j = 0; j < 10; j++)
1989 hr = IFileDialogCustomize_SetSelectedControlItem(pfdc, i, j);
1990 ok(hr == S_OK, "got 0x%08x.\n", hr);
1991 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
1992 ok(hr == S_OK, "got 0x%08x.\n", hr);
1993 ok(selected == j, "got %d.\n", selected);
1995 j++;
1996 hr = IFileDialogCustomize_SetSelectedControlItem(pfdc, i, j);
1997 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
1999 hr = IFileDialogCustomize_RemoveAllControlItems(pfdc, i);
2000 ok(hr == E_NOTIMPL, "got 0x%08x.\n", hr);
2002 for(j = 0; j < 10; j++)
2004 hr = IFileDialogCustomize_RemoveControlItem(pfdc, i, j);
2005 ok(hr == S_OK, "got 0x%08x.\n", hr);
2009 hr = IFileDialogCustomize_AddRadioButtonList(pfdc, ++i);
2010 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
2011 if(SUCCEEDED(hr))
2013 DWORD selected = -1;
2014 UINT j = 0;
2016 for(j = 0; j < 10; j++)
2018 hr = IFileDialogCustomize_AddControlItem(pfdc, i, j, label);
2019 ok(hr == S_OK, "got 0x%08x.\n", hr);
2022 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
2023 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
2024 ok(selected == -1, "got %d.\n", selected);
2026 todo_wine {
2027 cdstate = 0xdeadbeef;
2028 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
2029 ok(hr == S_OK, "got 0x%08x.\n", hr);
2030 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2031 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, 0);
2032 ok(hr == S_OK, "got 0x%08x.\n", hr);
2033 cdstate = 0xdeadbeef;
2034 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
2035 ok(hr == S_OK, "got 0x%08x.\n", hr);
2036 ok(cdstate == 0, "got 0x%08x.\n", cdstate);
2037 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, CDCS_ENABLEDVISIBLE);
2038 ok(hr == S_OK, "got 0x%08x.\n", hr);
2039 cdstate = 0xdeadbeef;
2040 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
2041 ok(hr == S_OK, "got 0x%08x.\n", hr);
2042 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2045 for(j = 0; j < 10; j++)
2047 hr = IFileDialogCustomize_SetSelectedControlItem(pfdc, i, j);
2048 ok(hr == S_OK, "got 0x%08x.\n", hr);
2049 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
2050 ok(hr == S_OK, "got 0x%08x.\n", hr);
2051 ok(selected == j, "got %d.\n", selected);
2053 j++;
2054 hr = IFileDialogCustomize_SetSelectedControlItem(pfdc, i, j);
2055 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
2057 hr = IFileDialogCustomize_RemoveAllControlItems(pfdc, i);
2058 ok(hr == E_NOTIMPL, "got 0x%08x.\n", hr);
2060 for(j = 0; j < 10; j++)
2062 hr = IFileDialogCustomize_RemoveControlItem(pfdc, i, j);
2063 ok(hr == S_OK, "got 0x%08x.\n", hr);
2066 hr = IFileDialogCustomize_EnableOpenDropDown(pfdc, ++i);
2067 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
2068 if(SUCCEEDED(hr))
2070 DWORD selected = -1;
2071 UINT j = 0;
2073 for(j = 0; j < 10; j++)
2075 hr = IFileDialogCustomize_AddControlItem(pfdc, i, j, label);
2076 ok(hr == S_OK, "got 0x%08x.\n", hr);
2079 hr = IFileDialogCustomize_GetSelectedControlItem(pfdc, i, &selected);
2080 ok(hr == S_OK, "got 0x%08x.\n", hr);
2081 ok(selected == 0, "got %d.\n", selected);
2083 cdstate = 0xdeadbeef;
2084 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
2085 ok(hr == S_OK, "got 0x%08x.\n", hr);
2086 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2087 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, 0);
2088 ok(hr == S_OK, "got 0x%08x.\n", hr);
2089 cdstate = 0xdeadbeef;
2090 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
2091 ok(hr == S_OK, "got 0x%08x.\n", hr);
2092 ok(cdstate == 0, "got 0x%08x.\n", cdstate);
2093 hr = IFileDialogCustomize_SetControlItemState(pfdc, i, 0, CDCS_ENABLEDVISIBLE);
2094 ok(hr == S_OK, "got 0x%08x.\n", hr);
2095 cdstate = 0xdeadbeef;
2096 hr = IFileDialogCustomize_GetControlItemState(pfdc, i, 0, &cdstate);
2097 ok(hr == S_OK, "got 0x%08x.\n", hr);
2098 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2099 hr = IFileDialogCustomize_SetSelectedControlItem(pfdc, i, 0);
2100 ok(hr == E_NOTIMPL, "got 0x%08x.\n", hr);
2102 hr = IFileDialogCustomize_RemoveAllControlItems(pfdc, i);
2103 ok(hr == E_NOTIMPL, "got 0x%08x.\n", hr);
2105 for(j = 0; j < 10; j++)
2107 hr = IFileDialogCustomize_RemoveControlItem(pfdc, i, j);
2108 ok(hr == S_OK, "got 0x%08x.\n", hr);
2112 IFileDialogCustomize_Release(pfdc);
2113 ref = IFileDialog_Release(pfod);
2114 ok(!ref, "Refcount not zero (%d).\n", ref);
2117 /* Some more tests for VisualGroup behavior */
2118 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
2119 &IID_IFileDialog, (void**)&pfod);
2120 ok(hr == S_OK, "got 0x%08x.\n", hr);
2122 hr = IFileDialog_QueryInterface(pfod, &IID_IFileDialogCustomize, (void**)&pfdc);
2123 ok(hr == S_OK, "got 0x%08x.\n", hr);
2125 i = -1;
2126 id_vgroup1 = ++i;
2127 hr = IFileDialogCustomize_StartVisualGroup(pfdc, id_vgroup1, visualgroup1W);
2128 ok(hr == S_OK, "got 0x%08x.\n", hr);
2130 cdstate = 0xdeadbeef;
2131 hr = IFileDialogCustomize_GetControlState(pfdc, id_vgroup1, &cdstate);
2132 ok(hr == S_OK, "got 0x%08x.\n", hr);
2133 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2135 id_text = ++i;
2136 hr = IFileDialogCustomize_AddText(pfdc, id_text, label);
2137 ok(hr == S_OK, "got 0x%08x.\n", hr);
2139 cdstate = 0xdeadbeef;
2140 hr = IFileDialogCustomize_GetControlState(pfdc, id_text, &cdstate);
2141 ok(hr == S_OK, "got 0x%08x.\n", hr);
2142 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2144 id_editbox1 = ++i;
2145 hr = IFileDialogCustomize_AddEditBox(pfdc, id_editbox1, editbox1W);
2146 ok(hr == S_OK, "got 0x%08x.\n", hr);
2148 cdstate = 0xdeadbeef;
2149 hr = IFileDialogCustomize_GetControlState(pfdc, id_editbox1, &cdstate);
2150 ok(hr == S_OK, "got 0x%08x.\n", hr);
2151 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2154 /* Set all Visible but not Enabled */
2155 hr = IFileDialogCustomize_SetControlState(pfdc, id_vgroup1, CDCS_VISIBLE);
2156 ok(hr == S_OK, "got 0x%08x.\n", hr);
2158 cdstate = 0xdeadbeef;
2159 hr = IFileDialogCustomize_GetControlState(pfdc, id_vgroup1, &cdstate);
2160 ok(hr == S_OK, "got 0x%08x.\n", hr);
2161 ok(cdstate == CDCS_VISIBLE, "got 0x%08x.\n", cdstate);
2162 cdstate = 0xdeadbeef;
2164 hr = IFileDialogCustomize_GetControlState(pfdc, id_text, &cdstate);
2165 ok(hr == S_OK, "got 0x%08x.\n", hr);
2166 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2168 cdstate = 0xdeadbeef;
2169 hr = IFileDialogCustomize_GetControlState(pfdc, id_editbox1, &cdstate);
2170 ok(hr == S_OK, "got 0x%08x.\n", hr);
2171 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2173 /* Set text to Visible but not Enabled */
2174 hr = IFileDialogCustomize_SetControlState(pfdc, id_text, CDCS_VISIBLE);
2175 ok(hr == S_OK, "got 0x%08x.\n", hr);
2177 cdstate = 0xdeadbeef;
2178 hr = IFileDialogCustomize_GetControlState(pfdc, id_vgroup1, &cdstate);
2179 ok(hr == S_OK, "got 0x%08x.\n", hr);
2180 ok(cdstate == CDCS_VISIBLE, "got 0x%08x.\n", cdstate);
2181 cdstate = 0xdeadbeef;
2183 hr = IFileDialogCustomize_GetControlState(pfdc, id_text, &cdstate);
2184 ok(hr == S_OK, "got 0x%08x.\n", hr);
2185 ok(cdstate == CDCS_VISIBLE, "got 0x%08x.\n", cdstate);
2187 cdstate = 0xdeadbeef;
2188 hr = IFileDialogCustomize_GetControlState(pfdc, id_editbox1, &cdstate);
2189 ok(hr == S_OK, "got 0x%08x.\n", hr);
2190 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2192 /* Set vgroup to inactive */
2193 hr = IFileDialogCustomize_SetControlState(pfdc, id_vgroup1, CDCS_INACTIVE);
2194 ok(hr == S_OK, "got 0x%08x.\n", hr);
2196 cdstate = 0xdeadbeef;
2197 hr = IFileDialogCustomize_GetControlState(pfdc, id_vgroup1, &cdstate);
2198 ok(hr == S_OK, "got 0x%08x.\n", hr);
2199 ok(cdstate == CDCS_INACTIVE, "got 0x%08x.\n", cdstate);
2201 cdstate = 0xdeadbeef;
2202 hr = IFileDialogCustomize_GetControlState(pfdc, id_text, &cdstate);
2203 ok(hr == S_OK, "got 0x%08x.\n", hr);
2204 ok(cdstate == CDCS_VISIBLE, "got 0x%08x.\n", cdstate);
2206 cdstate = 0xdeadbeef;
2207 hr = IFileDialogCustomize_GetControlState(pfdc, id_editbox1, &cdstate);
2208 ok(hr == S_OK, "got 0x%08x.\n", hr);
2209 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2211 /* Set vgroup to Enabled and Visible again */
2212 hr = IFileDialogCustomize_SetControlState(pfdc, id_vgroup1, CDCS_ENABLEDVISIBLE);
2213 ok(hr == S_OK, "got 0x%08x.\n", hr);
2215 cdstate = 0xdeadbeef;
2216 hr = IFileDialogCustomize_GetControlState(pfdc, id_vgroup1, &cdstate);
2217 ok(hr == S_OK, "got 0x%08x.\n", hr);
2218 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2220 cdstate = 0xdeadbeef;
2221 hr = IFileDialogCustomize_GetControlState(pfdc, id_text, &cdstate);
2222 ok(hr == S_OK, "got 0x%08x.\n", hr);
2223 ok(cdstate == CDCS_VISIBLE, "got 0x%08x.\n", cdstate);
2225 cdstate = 0xdeadbeef;
2226 hr = IFileDialogCustomize_GetControlState(pfdc, id_editbox1, &cdstate);
2227 ok(hr == S_OK, "got 0x%08x.\n", hr);
2228 ok(cdstate == CDCS_ENABLEDVISIBLE, "got 0x%08x.\n", cdstate);
2230 hr = IFileDialogCustomize_MakeProminent(pfdc, id_vgroup1);
2231 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
2233 IFileDialogCustomize_Release(pfdc);
2234 ref = IFileDialog_Release(pfod);
2235 ok(!ref, "Refcount not zero (%d).\n", ref);
2238 static void test_persistent_state(void)
2240 IFileDialog *fd;
2241 HRESULT hr;
2243 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
2244 &IID_IFileDialog, (void**)&fd);
2245 ok(hr == S_OK, "got 0x%08x.\n", hr);
2247 if (0)
2249 /* crashes at least on Win8 */
2250 hr = IFileDialog_SetClientGuid(fd, NULL);
2253 hr = IFileDialog_SetClientGuid(fd, &IID_IUnknown);
2254 ok(hr == S_OK, "got 0x%08x\n", hr);
2256 hr = IFileDialog_SetClientGuid(fd, &IID_NULL);
2257 ok(hr == S_OK, "got 0x%08x\n", hr);
2259 IFileDialog_Release(fd);
2262 START_TEST(itemdlg)
2264 OleInitialize(NULL);
2265 init_function_pointers();
2267 if(test_instantiation())
2269 test_basics();
2270 test_advise();
2271 test_events();
2272 test_filename();
2273 test_customize();
2274 test_persistent_state();
2276 else
2277 skip("Skipping all Item Dialog tests.\n");
2279 OleUninitialize();