comdlg32/tests: Fix some copypaste errors.
[wine.git] / dlls / comdlg32 / tests / itemdlg.c
blobc57e166696e09fa2e9d554b6269821c20ab81588
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 static HRESULT (WINAPI *pSHCreateShellItem)(LPCITEMIDLIST,IShellFolder*,LPCITEMIDLIST,IShellItem**);
29 static HRESULT (WINAPI *pSHGetIDListFromObject)(IUnknown*, PIDLIST_ABSOLUTE*);
30 static HRESULT (WINAPI *pSHCreateItemFromParsingName)(PCWSTR,IBindCtx*,REFIID,void**);
32 static void init_function_pointers(void)
34 HMODULE hmod = GetModuleHandleA("shell32.dll");
36 #define MAKEFUNC(f) (p##f = (void*)GetProcAddress(hmod, #f))
37 MAKEFUNC(SHCreateShellItem);
38 MAKEFUNC(SHGetIDListFromObject);
39 MAKEFUNC(SHCreateItemFromParsingName);
40 #undef MAKEFUNC
43 /**************************************************************************
44 * IFileDialogEvents implementation
46 typedef struct {
47 IFileDialogEvents IFileDialogEvents_iface;
48 LONG ref;
49 LONG QueryInterface;
50 LONG OnFileOk, OnFolderChanging, OnFolderChange;
51 LONG OnSelectionChange, OnShareViolation, OnTypeChange;
52 LONG OnOverwrite;
53 LPCWSTR set_filename;
54 BOOL set_filename_tried;
55 } IFileDialogEventsImpl;
57 static inline IFileDialogEventsImpl *impl_from_IFileDialogEvents(IFileDialogEvents *iface)
59 return CONTAINING_RECORD(iface, IFileDialogEventsImpl, IFileDialogEvents_iface);
62 static HRESULT WINAPI IFileDialogEvents_fnQueryInterface(IFileDialogEvents *iface, REFIID riid, void **ppv)
64 /* Not called. */
65 ok(0, "Unexpectedly called.\n");
66 return E_NOINTERFACE;
69 static ULONG WINAPI IFileDialogEvents_fnAddRef(IFileDialogEvents *iface)
71 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
72 return InterlockedIncrement(&This->ref);
75 static ULONG WINAPI IFileDialogEvents_fnRelease(IFileDialogEvents *iface)
77 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
78 LONG ref = InterlockedDecrement(&This->ref);
80 if(!ref)
81 HeapFree(GetProcessHeap(), 0, This);
83 return ref;
86 static HRESULT WINAPI IFileDialogEvents_fnOnFileOk(IFileDialogEvents *iface, IFileDialog *pfd)
88 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
89 This->OnFileOk++;
90 return S_OK;
93 static HRESULT WINAPI IFileDialogEvents_fnOnFolderChanging(IFileDialogEvents *iface,
94 IFileDialog *pfd,
95 IShellItem *psiFolder)
97 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
98 This->OnFolderChanging++;
99 return S_OK;
102 static HRESULT WINAPI IFileDialogEvents_fnOnFolderChange(IFileDialogEvents *iface, IFileDialog *pfd)
104 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
105 This->OnFolderChange++;
107 if(This->set_filename)
109 IOleWindow *pow;
110 HWND dlg_hwnd;
111 HRESULT hr;
112 BOOL br;
114 hr = IFileDialog_QueryInterface(pfd, &IID_IOleWindow, (void**)&pow);
115 ok(hr == S_OK, "Got 0x%08x\n", hr);
117 hr = IOleWindow_GetWindow(pow, &dlg_hwnd);
118 ok(hr == S_OK, "Got 0x%08x\n", hr);
119 ok(dlg_hwnd != NULL, "Got NULL.\n");
121 IOleWindow_Release(pow);
123 hr = IFileDialog_SetFileName(pfd, This->set_filename);
124 ok(hr == S_OK, "Got 0x%08x\n", hr);
126 if(!This->set_filename_tried)
128 br = PostMessageW(dlg_hwnd, WM_COMMAND, IDOK, 0);
129 ok(br, "Failed\n");
130 This->set_filename_tried = TRUE;
134 return S_OK;
137 static HRESULT WINAPI IFileDialogEvents_fnOnSelectionChange(IFileDialogEvents *iface, IFileDialog *pfd)
139 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
140 This->OnSelectionChange++;
141 return S_OK;
144 static HRESULT WINAPI IFileDialogEvents_fnOnShareViolation(IFileDialogEvents *iface,
145 IFileDialog *pfd,
146 IShellItem *psi,
147 FDE_SHAREVIOLATION_RESPONSE *pResponse)
149 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
150 This->OnShareViolation++;
151 return S_OK;
154 static HRESULT WINAPI IFileDialogEvents_fnOnTypeChange(IFileDialogEvents *iface, IFileDialog *pfd)
156 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
157 This->OnTypeChange++;
158 return S_OK;
161 static HRESULT WINAPI IFileDialogEvents_fnOnOverwrite(IFileDialogEvents *iface,
162 IFileDialog *pfd,
163 IShellItem *psi,
164 FDE_OVERWRITE_RESPONSE *pResponse)
166 IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface);
167 This->OnOverwrite++;
168 return S_OK;
171 static const IFileDialogEventsVtbl vt_IFileDialogEvents = {
172 IFileDialogEvents_fnQueryInterface,
173 IFileDialogEvents_fnAddRef,
174 IFileDialogEvents_fnRelease,
175 IFileDialogEvents_fnOnFileOk,
176 IFileDialogEvents_fnOnFolderChanging,
177 IFileDialogEvents_fnOnFolderChange,
178 IFileDialogEvents_fnOnSelectionChange,
179 IFileDialogEvents_fnOnShareViolation,
180 IFileDialogEvents_fnOnTypeChange,
181 IFileDialogEvents_fnOnOverwrite
184 static IFileDialogEvents *IFileDialogEvents_Constructor(void)
186 IFileDialogEventsImpl *This;
188 This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IFileDialogEventsImpl));
189 This->IFileDialogEvents_iface.lpVtbl = &vt_IFileDialogEvents;
190 This->ref = 1;
192 return &This->IFileDialogEvents_iface;
195 static BOOL test_instantiation(void)
197 IFileDialog *pfd;
198 IFileOpenDialog *pfod;
199 IFileSaveDialog *pfsd;
200 IServiceProvider *psp;
201 IOleWindow *pow;
202 IUnknown *punk;
203 HRESULT hr;
204 LONG ref;
206 /* Instantiate FileOpenDialog */
207 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
208 &IID_IFileOpenDialog, (void**)&pfod);
209 if(FAILED(hr))
211 skip("Could not instantiate the FileOpenDialog.\n");
212 return FALSE;
214 ok(hr == S_OK, "got 0x%08x.\n", hr);
216 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialog, (void**)&pfd);
217 ok(hr == S_OK, "got 0x%08x.\n", hr);
218 if(SUCCEEDED(hr)) IFileDialog_Release(pfd);
220 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialogCustomize, (void**)&punk);
221 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
222 if(SUCCEEDED(hr)) IUnknown_Release(punk);
224 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileSaveDialog, (void**)&pfsd);
225 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
226 if(SUCCEEDED(hr)) IFileSaveDialog_Release(pfsd);
228 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IServiceProvider, (void**)&psp);
229 ok(hr == S_OK, "got 0x%08x.\n", hr);
230 if(SUCCEEDED(hr))
232 IExplorerBrowser *peb;
233 IShellBrowser *psb;
235 hr = IServiceProvider_QueryService(psp, &SID_STopLevelBrowser, &IID_IExplorerBrowser, (void**)&peb);
236 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
237 if(SUCCEEDED(hr)) IExplorerBrowser_Release(peb);
238 hr = IServiceProvider_QueryService(psp, &SID_STopLevelBrowser, &IID_IShellBrowser, (void**)&psb);
239 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
240 if(SUCCEEDED(hr)) IShellBrowser_Release(psb);
241 hr = IServiceProvider_QueryService(psp, &SID_STopLevelBrowser, &IID_ICommDlgBrowser, (void**)&punk);
242 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
243 if(SUCCEEDED(hr)) IUnknown_Release(punk);
244 hr = IServiceProvider_QueryService(psp, &SID_SExplorerBrowserFrame, &IID_ICommDlgBrowser, (void**)&punk);
245 ok(hr == S_OK, "got 0x%08x.\n", hr);
246 if(SUCCEEDED(hr)) IUnknown_Release(punk);
248 IServiceProvider_Release(psp);
251 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialogEvents, (void**)&punk);
252 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
253 if(SUCCEEDED(hr)) IUnknown_Release(punk);
255 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IExplorerBrowser, (void**)&punk);
256 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
257 if(SUCCEEDED(hr)) IUnknown_Release(punk);
259 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IExplorerBrowserEvents, (void**)&punk);
260 ok(hr == S_OK, "got 0x%08x.\n", hr);
261 if(SUCCEEDED(hr)) IUnknown_Release(punk);
263 hr = IFileOpenDialog_QueryInterface(pfod, &IID_ICommDlgBrowser3, (void**)&punk);
264 ok(hr == S_OK, "got 0x%08x.\n", hr);
265 if(SUCCEEDED(hr)) IUnknown_Release(punk);
267 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IShellBrowser, (void**)&punk);
268 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
269 if(SUCCEEDED(hr)) IUnknown_Release(punk);
271 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IOleWindow, (void**)&pow);
272 ok(hr == S_OK, "got 0x%08x.\n", hr);
273 if(SUCCEEDED(hr))
275 HWND hwnd;
277 hr = IOleWindow_ContextSensitiveHelp(pow, TRUE);
278 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
280 hr = IOleWindow_ContextSensitiveHelp(pow, FALSE);
281 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
283 if(0)
285 /* Crashes on win7 */
286 IOleWindow_GetWindow(pow, NULL);
289 hr = IOleWindow_GetWindow(pow, &hwnd);
290 ok(hr == S_OK, "Got 0x%08x\n", hr);
291 ok(hwnd == NULL, "Got %p\n", hwnd);
293 IOleWindow_Release(pow);
296 ref = IFileOpenDialog_Release(pfod);
297 ok(!ref, "Got refcount %d, should have been released.\n", ref);
299 /* Instantiate FileSaveDialog */
300 hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER,
301 &IID_IFileSaveDialog, (void**)&pfsd);
302 if(FAILED(hr))
304 skip("Could not instantiate the FileSaveDialog.\n");
305 return FALSE;
307 ok(hr == S_OK, "got 0x%08x.\n", hr);
309 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialog, (void**)&pfd);
310 ok(hr == S_OK, "got 0x%08x.\n", hr);
311 if(SUCCEEDED(hr)) IFileDialog_Release(pfd);
313 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialogCustomize, (void**)&punk);
314 todo_wine ok(hr == S_OK, "got 0x%08x.\n", hr);
315 if(SUCCEEDED(hr)) IUnknown_Release(punk);
317 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileOpenDialog, (void**)&pfod);
318 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
319 if(SUCCEEDED(hr)) IFileOpenDialog_Release(pfod);
321 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialogEvents, (void**)&punk);
322 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
323 if(SUCCEEDED(hr)) IUnknown_Release(pfd);
325 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IExplorerBrowser, (void**)&punk);
326 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
327 if(SUCCEEDED(hr)) IUnknown_Release(punk);
329 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IExplorerBrowserEvents, (void**)&punk);
330 ok(hr == S_OK, "got 0x%08x.\n", hr);
331 if(SUCCEEDED(hr)) IUnknown_Release(punk);
333 hr = IFileOpenDialog_QueryInterface(pfsd, &IID_ICommDlgBrowser3, (void**)&punk);
334 ok(hr == S_OK, "got 0x%08x.\n", hr);
335 if(SUCCEEDED(hr)) IUnknown_Release(punk);
337 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IShellBrowser, (void**)&punk);
338 ok(hr == E_NOINTERFACE, "got 0x%08x.\n", hr);
339 if(SUCCEEDED(hr)) IUnknown_Release(punk);
341 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IOleWindow, (void**)&pow);
342 ok(hr == S_OK, "got 0x%08x.\n", hr);
343 if(SUCCEEDED(hr))
345 HWND hwnd;
347 hr = IOleWindow_ContextSensitiveHelp(pow, TRUE);
348 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
350 hr = IOleWindow_ContextSensitiveHelp(pow, FALSE);
351 todo_wine ok(hr == S_OK, "Got 0x%08x\n", hr);
353 if(0)
355 /* Crashes on win7 */
356 IOleWindow_GetWindow(pow, NULL);
359 hr = IOleWindow_GetWindow(pow, &hwnd);
360 ok(hr == S_OK, "Got 0x%08x\n", hr);
361 ok(hwnd == NULL, "Got %p\n", hwnd);
363 IOleWindow_Release(pow);
367 ref = IFileSaveDialog_Release(pfsd);
368 ok(!ref, "Got refcount %d, should have been released.\n", ref);
369 return TRUE;
372 static void test_basics(void)
374 IFileOpenDialog *pfod;
375 IFileSaveDialog *pfsd;
376 IFileDialog2 *pfd2;
377 FILEOPENDIALOGOPTIONS fdoptions;
378 IShellFolder *psfdesktop;
379 IShellItem *psi, *psidesktop, *psi_original;
380 IShellItemArray *psia;
381 IPropertyStore *pps;
382 LPITEMIDLIST pidl;
383 WCHAR *filename;
384 UINT filetype;
385 LONG ref;
386 HRESULT hr;
387 const WCHAR txt[] = {'t','x','t', 0};
388 const WCHAR null[] = {0};
389 const WCHAR fname1[] = {'f','n','a','m','e','1', 0};
390 const WCHAR fspec1[] = {'*','.','t','x','t',0};
391 const WCHAR fname2[] = {'f','n','a','m','e','2', 0};
392 const WCHAR fspec2[] = {'*','.','e','x','e',0};
393 COMDLG_FILTERSPEC filterspec[2] = {{fname1, fspec1}, {fname2, fspec2}};
395 /* This should work on every platform with IFileDialog */
396 SHGetDesktopFolder(&psfdesktop);
397 hr = pSHGetIDListFromObject((IUnknown*)psfdesktop, &pidl);
398 if(SUCCEEDED(hr))
400 hr = pSHCreateShellItem(NULL, NULL, pidl, &psidesktop);
401 ILFree(pidl);
403 IShellFolder_Release(psfdesktop);
404 if(FAILED(hr))
406 skip("Failed to get ShellItem from DesktopFolder, skipping tests.\n");
407 return;
411 /* Instantiate FileOpenDialog and FileSaveDialog */
412 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
413 &IID_IFileOpenDialog, (void**)&pfod);
414 ok(hr == S_OK, "got 0x%08x.\n", hr);
415 hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER,
416 &IID_IFileSaveDialog, (void**)&pfsd);
417 ok(hr == S_OK, "got 0x%08x.\n", hr);
419 /* ClearClientData */
420 todo_wine
422 hr = IFileOpenDialog_ClearClientData(pfod);
423 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
424 hr = IFileSaveDialog_ClearClientData(pfsd);
425 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
428 /* GetOptions */
429 hr = IFileOpenDialog_GetOptions(pfod, NULL);
430 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
431 hr = IFileSaveDialog_GetOptions(pfsd, NULL);
432 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
434 /* Check default options */
435 hr = IFileOpenDialog_GetOptions(pfod, &fdoptions);
436 ok(hr == S_OK, "got 0x%08x.\n", hr);
437 ok(fdoptions == (FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST | FOS_NOCHANGEDIR),
438 "Unexpected default options: 0x%08x\n", fdoptions);
439 hr = IFileSaveDialog_GetOptions(pfsd, &fdoptions);
440 ok(hr == S_OK, "got 0x%08x.\n", hr);
441 ok(fdoptions == (FOS_OVERWRITEPROMPT | FOS_NOREADONLYRETURN | FOS_PATHMUSTEXIST | FOS_NOCHANGEDIR),
442 "Unexpected default options: 0x%08x\n", fdoptions);
444 /* GetResult */
445 hr = IFileOpenDialog_GetResult(pfod, NULL);
446 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
447 hr = IFileSaveDialog_GetResult(pfsd, NULL);
448 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
450 psi = (void*)0xdeadbeef;
451 hr = IFileOpenDialog_GetResult(pfod, &psi);
452 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
453 ok(psi == (void*)0xdeadbeef, "got %p.\n", psi);
454 psi = (void*)0xdeadbeef;
455 hr = IFileSaveDialog_GetResult(pfsd, &psi);
456 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
457 ok(psi == (void*)0xdeadbeef, "got %p.\n", psi);
459 /* GetCurrentSelection */
460 if(0) {
461 /* Crashes on Vista/W2K8. Tests below passes on Windows 7 */
462 hr = IFileOpenDialog_GetCurrentSelection(pfod, NULL);
463 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
464 hr = IFileSaveDialog_GetCurrentSelection(pfsd, NULL);
465 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
466 hr = IFileOpenDialog_GetCurrentSelection(pfod, &psi);
467 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
468 hr = IFileSaveDialog_GetCurrentSelection(pfsd, &psi);
469 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
472 /* GetFileName */
473 hr = IFileOpenDialog_GetFileName(pfod, NULL);
474 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
475 filename = (void*)0xdeadbeef;
476 hr = IFileOpenDialog_GetFileName(pfod, &filename);
477 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
478 ok(filename == NULL, "got %p\n", filename);
479 hr = IFileSaveDialog_GetFileName(pfsd, NULL);
480 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
481 filename = (void*)0xdeadbeef;
482 hr = IFileSaveDialog_GetFileName(pfsd, &filename);
483 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
484 ok(filename == NULL, "got %p\n", filename);
486 /* GetFileTypeIndex */
487 hr = IFileOpenDialog_GetFileTypeIndex(pfod, NULL);
488 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
489 filetype = 0x12345;
490 hr = IFileOpenDialog_GetFileTypeIndex(pfod, &filetype);
491 ok(hr == S_OK, "got 0x%08x.\n", hr);
492 ok(filetype == 0, "got %d.\n", filetype);
493 hr = IFileSaveDialog_GetFileTypeIndex(pfsd, NULL);
494 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
495 filetype = 0x12345;
496 hr = IFileSaveDialog_GetFileTypeIndex(pfsd, &filetype);
497 ok(hr == S_OK, "got 0x%08x.\n", hr);
498 ok(filetype == 0, "got %d.\n", filetype);
500 /* SetFileTypes / SetFileTypeIndex */
501 hr = IFileOpenDialog_SetFileTypes(pfod, 0, NULL);
502 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
503 hr = IFileOpenDialog_SetFileTypes(pfod, 0, filterspec);
504 ok(hr == S_OK, "got 0x%08x.\n", hr);
506 hr = IFileOpenDialog_SetFileTypeIndex(pfod, -1);
507 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
508 hr = IFileOpenDialog_SetFileTypeIndex(pfod, 0);
509 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
510 hr = IFileOpenDialog_SetFileTypeIndex(pfod, 1);
511 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
512 hr = IFileOpenDialog_SetFileTypes(pfod, 1, filterspec);
513 ok(hr == S_OK, "got 0x%08x.\n", hr);
514 hr = IFileOpenDialog_SetFileTypes(pfod, 0, filterspec);
515 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
516 hr = IFileOpenDialog_SetFileTypeIndex(pfod, 0);
517 ok(hr == S_OK, "got 0x%08x.\n", hr);
518 hr = IFileOpenDialog_SetFileTypeIndex(pfod, 100);
519 ok(hr == S_OK, "got 0x%08x.\n", hr);
520 hr = IFileOpenDialog_SetFileTypes(pfod, 1, filterspec);
521 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
522 hr = IFileOpenDialog_SetFileTypes(pfod, 1, &filterspec[1]);
523 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
525 hr = IFileSaveDialog_SetFileTypeIndex(pfsd, -1);
526 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
527 hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 0);
528 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
529 hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 1);
530 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
531 hr = IFileSaveDialog_SetFileTypes(pfsd, 1, filterspec);
532 ok(hr == S_OK, "got 0x%08x.\n", hr);
533 hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 0);
534 ok(hr == S_OK, "got 0x%08x.\n", hr);
535 hr = IFileSaveDialog_SetFileTypeIndex(pfsd, 100);
536 ok(hr == S_OK, "got 0x%08x.\n", hr);
537 hr = IFileSaveDialog_SetFileTypes(pfsd, 1, filterspec);
538 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
539 hr = IFileSaveDialog_SetFileTypes(pfsd, 1, &filterspec[1]);
540 ok(hr == E_UNEXPECTED, "got 0x%08x.\n", hr);
542 /* SetFilter */
543 todo_wine
545 hr = IFileOpenDialog_SetFilter(pfod, NULL);
546 ok(hr == S_OK, "got 0x%08x.\n", hr);
547 hr = IFileSaveDialog_SetFilter(pfsd, NULL);
548 ok(hr == S_OK, "got 0x%08x.\n", hr);
551 /* SetFolder */
552 hr = IFileOpenDialog_SetFolder(pfod, NULL);
553 ok(hr == S_OK, "got 0x%08x.\n", hr);
554 hr = IFileSaveDialog_SetFolder(pfsd, NULL);
555 ok(hr == S_OK, "got 0x%08x.\n", hr);
557 /* SetDefaultExtension */
558 hr = IFileOpenDialog_SetDefaultExtension(pfod, NULL);
559 ok(hr == S_OK, "got 0x%08x.\n", hr);
560 hr = IFileOpenDialog_SetDefaultExtension(pfod, txt);
561 ok(hr == S_OK, "got 0x%08x.\n", hr);
562 hr = IFileOpenDialog_SetDefaultExtension(pfod, null);
563 ok(hr == S_OK, "got 0x%08x.\n", hr);
565 hr = IFileSaveDialog_SetDefaultExtension(pfsd, NULL);
566 ok(hr == S_OK, "got 0x%08x.\n", hr);
567 hr = IFileSaveDialog_SetDefaultExtension(pfsd, txt);
568 ok(hr == S_OK, "got 0x%08x.\n", hr);
569 hr = IFileSaveDialog_SetDefaultExtension(pfsd, null);
570 ok(hr == S_OK, "got 0x%08x.\n", hr);
572 /* SetDefaultFolder */
573 hr = IFileOpenDialog_SetDefaultFolder(pfod, NULL);
574 ok(hr == S_OK, "got 0x%08x\n", hr);
575 hr = IFileSaveDialog_SetDefaultFolder(pfsd, NULL);
576 ok(hr == S_OK, "got 0x%08x\n", hr);
578 hr = IFileOpenDialog_SetDefaultFolder(pfod, psidesktop);
579 ok(hr == S_OK, "got 0x%08x\n", hr);
580 hr = IFileSaveDialog_SetDefaultFolder(pfsd, psidesktop);
581 ok(hr == S_OK, "got 0x%08x\n", hr);
583 if(0)
585 /* Crashes under Windows 7 */
586 IFileOpenDialog_SetDefaultFolder(pfod, (void*)0x1234);
587 IFileSaveDialog_SetDefaultFolder(pfsd, (void*)0x1234);
590 /* GetFolder / SetFolder */
591 hr = IFileOpenDialog_GetFolder(pfod, NULL);
592 ok(hr == E_INVALIDARG, "got 0x%08x.\n", hr);
594 hr = IFileOpenDialog_GetFolder(pfod, &psi_original);
595 ok(hr == S_OK, "got 0x%08x.\n", hr);
596 if(SUCCEEDED(hr))
598 hr = IFileOpenDialog_SetFolder(pfod, psidesktop);
599 ok(hr == S_OK, "got 0x%08x.\n", hr);
600 hr = IFileOpenDialog_SetFolder(pfod, psi_original);
601 ok(hr == S_OK, "got 0x%08x.\n", hr);
602 IShellItem_Release(psi_original);
605 hr = IFileSaveDialog_GetFolder(pfsd, &psi_original);
606 ok(hr == S_OK, "got 0x%08x.\n", hr);
607 if(SUCCEEDED(hr))
609 hr = IFileSaveDialog_SetFolder(pfsd, psidesktop);
610 ok(hr == S_OK, "got 0x%08x.\n", hr);
611 hr = IFileSaveDialog_SetFolder(pfsd, psi_original);
612 ok(hr == S_OK, "got 0x%08x.\n", hr);
613 IShellItem_Release(psi_original);
616 /* AddPlace */
617 if(0)
619 /* Crashes under Windows 7 */
620 IFileOpenDialog_AddPlace(pfod, NULL, 0);
621 IFileSaveDialog_AddPlace(pfsd, NULL, 0);
624 todo_wine
626 hr = IFileOpenDialog_AddPlace(pfod, psidesktop, FDAP_TOP + 1);
627 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
628 hr = IFileOpenDialog_AddPlace(pfod, psidesktop, FDAP_BOTTOM);
629 ok(hr == S_OK, "got 0x%08x\n", hr);
630 hr = IFileOpenDialog_AddPlace(pfod, psidesktop, FDAP_TOP);
631 ok(hr == S_OK, "got 0x%08x\n", hr);
633 hr = IFileSaveDialog_AddPlace(pfsd, psidesktop, FDAP_TOP + 1);
634 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
635 hr = IFileSaveDialog_AddPlace(pfsd, psidesktop, FDAP_BOTTOM);
636 ok(hr == S_OK, "got 0x%08x\n", hr);
637 hr = IFileSaveDialog_AddPlace(pfsd, psidesktop, FDAP_TOP);
638 ok(hr == S_OK, "got 0x%08x\n", hr);
641 /* SetFileName */
642 hr = IFileOpenDialog_SetFileName(pfod, NULL);
643 ok(hr == S_OK, "got 0x%08x\n", hr);
644 hr = IFileOpenDialog_SetFileName(pfod, null);
645 ok(hr == S_OK, "got 0x%08x\n", hr);
646 hr = IFileOpenDialog_SetFileName(pfod, txt);
647 ok(hr == S_OK, "got 0x%08x\n", hr);
648 hr = IFileOpenDialog_GetFileName(pfod, &filename);
649 ok(hr == S_OK, "Got 0x%08x\n", hr);
650 ok(!lstrcmpW(filename, txt), "Strings do not match.\n");
651 CoTaskMemFree(filename);
653 hr = IFileSaveDialog_SetFileName(pfsd, NULL);
654 ok(hr == S_OK, "got 0x%08x\n", hr);
655 hr = IFileSaveDialog_SetFileName(pfsd, null);
656 ok(hr == S_OK, "got 0x%08x\n", hr);
657 hr = IFileSaveDialog_SetFileName(pfsd, txt);
658 ok(hr == S_OK, "got 0x%08x\n", hr);
659 hr = IFileSaveDialog_GetFileName(pfsd, &filename);
660 ok(hr == S_OK, "Got 0x%08x\n", hr);
661 ok(!lstrcmpW(filename, txt), "Strings do not match.\n");
662 CoTaskMemFree(filename);
664 /* SetFileNameLabel */
665 hr = IFileOpenDialog_SetFileNameLabel(pfod, NULL);
666 ok(hr == S_OK, "got 0x%08x\n", hr);
667 hr = IFileOpenDialog_SetFileNameLabel(pfod, null);
668 ok(hr == S_OK, "got 0x%08x\n", hr);
669 hr = IFileOpenDialog_SetFileNameLabel(pfod, txt);
670 ok(hr == S_OK, "got 0x%08x\n", hr);
672 hr = IFileSaveDialog_SetFileNameLabel(pfsd, NULL);
673 ok(hr == S_OK, "got 0x%08x\n", hr);
674 hr = IFileSaveDialog_SetFileNameLabel(pfsd, null);
675 ok(hr == S_OK, "got 0x%08x\n", hr);
676 hr = IFileSaveDialog_SetFileNameLabel(pfsd, txt);
677 ok(hr == S_OK, "got 0x%08x\n", hr);
679 /* Close */
680 hr = IFileOpenDialog_Close(pfod, S_FALSE);
681 ok(hr == S_OK, "got 0x%08x\n", hr);
682 hr = IFileSaveDialog_Close(pfsd, S_FALSE);
683 ok(hr == S_OK, "got 0x%08x\n", hr);
685 /* SetOkButtonLabel */
686 hr = IFileOpenDialog_SetOkButtonLabel(pfod, NULL);
687 ok(hr == S_OK, "got 0x%08x\n", hr);
688 hr = IFileOpenDialog_SetOkButtonLabel(pfod, null);
689 ok(hr == S_OK, "got 0x%08x\n", hr);
690 hr = IFileOpenDialog_SetOkButtonLabel(pfod, txt);
691 ok(hr == S_OK, "got 0x%08x\n", hr);
692 hr = IFileSaveDialog_SetOkButtonLabel(pfsd, NULL);
693 ok(hr == S_OK, "got 0x%08x\n", hr);
694 hr = IFileSaveDialog_SetOkButtonLabel(pfsd, null);
695 ok(hr == S_OK, "got 0x%08x\n", hr);
696 hr = IFileSaveDialog_SetOkButtonLabel(pfsd, txt);
697 ok(hr == S_OK, "got 0x%08x\n", hr);
699 /* SetTitle */
700 hr = IFileOpenDialog_SetTitle(pfod, NULL);
701 ok(hr == S_OK, "got 0x%08x\n", hr);
702 hr = IFileOpenDialog_SetTitle(pfod, null);
703 ok(hr == S_OK, "got 0x%08x\n", hr);
704 hr = IFileOpenDialog_SetTitle(pfod, txt);
705 ok(hr == S_OK, "got 0x%08x\n", hr);
706 hr = IFileSaveDialog_SetTitle(pfsd, NULL);
707 ok(hr == S_OK, "got 0x%08x\n", hr);
708 hr = IFileSaveDialog_SetTitle(pfsd, null);
709 ok(hr == S_OK, "got 0x%08x\n", hr);
710 hr = IFileSaveDialog_SetTitle(pfsd, txt);
711 ok(hr == S_OK, "got 0x%08x\n", hr);
713 /** IFileOpenDialog specific **/
715 /* GetResults */
716 if(0)
718 /* Crashes under Windows 7 */
719 IFileOpenDialog_GetResults(pfod, NULL);
721 psia = (void*)0xdeadbeef;
722 hr = IFileOpenDialog_GetResults(pfod, &psia);
723 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
724 ok(psia == NULL, "got %p.\n", psia);
726 /* GetSelectedItems */
727 if(0)
729 /* Crashes under W2K8 */
730 hr = IFileOpenDialog_GetSelectedItems(pfod, NULL);
731 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
732 psia = (void*)0xdeadbeef;
733 hr = IFileOpenDialog_GetSelectedItems(pfod, &psia);
734 ok(hr == E_FAIL, "got 0x%08x.\n", hr);
735 ok(psia == (void*)0xdeadbeef, "got %p.\n", psia);
738 /** IFileSaveDialog specific **/
740 /* ApplyProperties */
741 if(0)
743 /* Crashes under windows 7 */
744 IFileSaveDialog_ApplyProperties(pfsd, NULL, NULL, NULL, NULL);
745 IFileSaveDialog_ApplyProperties(pfsd, psidesktop, NULL, NULL, NULL);
748 /* GetProperties */
749 hr = IFileSaveDialog_GetProperties(pfsd, NULL);
750 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
751 pps = (void*)0xdeadbeef;
752 hr = IFileSaveDialog_GetProperties(pfsd, &pps);
753 todo_wine ok(hr == E_UNEXPECTED, "got 0x%08x\n", hr);
754 ok(pps == (void*)0xdeadbeef, "got %p\n", pps);
756 /* SetProperties */
757 if(0)
759 /* Crashes under W2K8 */
760 hr = IFileSaveDialog_SetProperties(pfsd, NULL);
761 ok(hr == S_OK, "got 0x%08x\n", hr);
764 /* SetCollectedProperties */
765 todo_wine
767 hr = IFileSaveDialog_SetCollectedProperties(pfsd, NULL, TRUE);
768 ok(hr == S_OK, "got 0x%08x\n", hr);
769 hr = IFileSaveDialog_SetCollectedProperties(pfsd, NULL, FALSE);
770 ok(hr == S_OK, "got 0x%08x\n", hr);
773 /* SetSaveAsItem */
774 todo_wine
776 hr = IFileSaveDialog_SetSaveAsItem(pfsd, NULL);
777 ok(hr == S_OK, "got 0x%08x\n", hr);
778 hr = IFileSaveDialog_SetSaveAsItem(pfsd, psidesktop);
779 ok(hr == MK_E_NOOBJECT, "got 0x%08x\n", hr);
782 /** IFileDialog2 **/
784 hr = IFileOpenDialog_QueryInterface(pfod, &IID_IFileDialog2, (void**)&pfd2);
785 ok((hr == S_OK) || broken(hr == E_NOINTERFACE), "got 0x%08x\n", hr);
786 if(SUCCEEDED(hr))
788 /* SetCancelButtonLabel */
789 hr = IFileDialog2_SetOkButtonLabel(pfd2, NULL);
790 ok(hr == S_OK, "got 0x%08x\n", hr);
791 hr = IFileDialog2_SetOkButtonLabel(pfd2, null);
792 ok(hr == S_OK, "got 0x%08x\n", hr);
793 hr = IFileDialog2_SetOkButtonLabel(pfd2, txt);
794 ok(hr == S_OK, "got 0x%08x\n", hr);
796 /* SetNavigationRoot */
797 todo_wine
799 hr = IFileDialog2_SetNavigationRoot(pfd2, NULL);
800 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
801 hr = IFileDialog2_SetNavigationRoot(pfd2, psidesktop);
802 ok(hr == S_OK, "got 0x%08x\n", hr);
805 IFileDialog2_Release(pfd2);
808 hr = IFileSaveDialog_QueryInterface(pfsd, &IID_IFileDialog2, (void**)&pfd2);
809 ok((hr == S_OK) || broken(hr == E_NOINTERFACE), "got 0x%08x\n", hr);
810 if(SUCCEEDED(hr))
812 /* SetCancelButtonLabel */
813 hr = IFileDialog2_SetOkButtonLabel(pfd2, NULL);
814 ok(hr == S_OK, "got 0x%08x\n", hr);
815 hr = IFileDialog2_SetOkButtonLabel(pfd2, null);
816 ok(hr == S_OK, "got 0x%08x\n", hr);
817 hr = IFileDialog2_SetOkButtonLabel(pfd2, txt);
818 ok(hr == S_OK, "got 0x%08x\n", hr);
820 /* SetNavigationRoot */
821 todo_wine
823 hr = IFileDialog2_SetNavigationRoot(pfd2, NULL);
824 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
825 hr = IFileDialog2_SetNavigationRoot(pfd2, psidesktop);
826 ok(hr == S_OK, "got 0x%08x\n", hr);
829 IFileDialog2_Release(pfd2);
832 /* Cleanup */
833 IShellItem_Release(psidesktop);
834 ref = IFileOpenDialog_Release(pfod);
835 ok(!ref, "Got refcount %d, should have been released.\n", ref);
836 ref = IFileSaveDialog_Release(pfsd);
837 ok(!ref, "Got refcount %d, should have been released.\n", ref);
840 void ensure_zero_events_(const char *file, int line, IFileDialogEventsImpl *impl)
842 ok_(file, line)(!impl->OnFileOk, "OnFileOk: %d\n", impl->OnFileOk);
843 ok_(file, line)(!impl->OnFolderChanging, "OnFolderChanging: %d\n", impl->OnFolderChanging);
844 ok_(file, line)(!impl->OnFolderChange, "OnFolderChange: %d\n", impl->OnFolderChange);
845 ok_(file, line)(!impl->OnSelectionChange, "OnSelectionChange: %d\n", impl->OnSelectionChange);
846 ok_(file, line)(!impl->OnShareViolation, "OnShareViolation: %d\n", impl->OnShareViolation);
847 ok_(file, line)(!impl->OnTypeChange, "OnTypeChange: %d\n", impl->OnTypeChange);
848 ok_(file, line)(!impl->OnOverwrite, "OnOverwrite: %d\n", impl->OnOverwrite);
849 impl->OnFileOk = impl->OnFolderChanging = impl->OnFolderChange = 0;
850 impl->OnSelectionChange = impl->OnShareViolation = impl->OnTypeChange = 0;
851 impl->OnOverwrite = 0;
853 #define ensure_zero_events(impl) ensure_zero_events_(__FILE__, __LINE__, impl)
855 static void test_advise_helper(IFileDialog *pfd)
857 IFileDialogEventsImpl *pfdeimpl;
858 IFileDialogEvents *pfde;
859 DWORD cookie[10];
860 UINT i;
861 HRESULT hr;
863 pfde = IFileDialogEvents_Constructor();
864 pfdeimpl = impl_from_IFileDialogEvents(pfde);
866 hr = IFileDialog_Advise(pfd, NULL, NULL);
867 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
868 hr = IFileDialog_Advise(pfd, pfde, NULL);
869 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
870 hr = IFileDialog_Advise(pfd, NULL, &cookie[0]);
871 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
872 ok(pfdeimpl->ref == 1, "got ref %d\n", pfdeimpl->ref);
873 ensure_zero_events(pfdeimpl);
875 hr = IFileDialog_Unadvise(pfd, 0);
876 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
877 for(i = 0; i < 10; i++) {
878 hr = IFileDialog_Advise(pfd, pfde, &cookie[i]);
879 ok(hr == S_OK, "got 0x%08x\n", hr);
880 ok(cookie[i] == i+1, "Got cookie: %d\n", cookie[i]);
882 ok(pfdeimpl->ref == 10+1, "got ref %d\n", pfdeimpl->ref);
883 ensure_zero_events(pfdeimpl);
885 for(i = 3; i < 7; i++) {
886 hr = IFileDialog_Unadvise(pfd, cookie[i]);
887 ok(hr == S_OK, "got 0x%08x\n", hr);
889 ok(pfdeimpl->ref == 6+1, "got ref %d\n", pfdeimpl->ref);
890 ensure_zero_events(pfdeimpl);
892 for(i = 0; i < 3; i++) {
893 hr = IFileDialog_Unadvise(pfd, cookie[i]);
894 ok(hr == S_OK, "got 0x%08x\n", hr);
896 ok(pfdeimpl->ref == 3+1, "got ref %d\n", pfdeimpl->ref);
897 ensure_zero_events(pfdeimpl);
899 for(i = 7; i < 10; i++) {
900 hr = IFileDialog_Unadvise(pfd, cookie[i]);
901 ok(hr == S_OK, "got 0x%08x\n", hr);
903 ok(pfdeimpl->ref == 1, "got ref %d\n", pfdeimpl->ref);
904 ensure_zero_events(pfdeimpl);
906 hr = IFileDialog_Unadvise(pfd, cookie[9]+1);
907 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
908 ok(pfdeimpl->ref == 1, "got ref %d\n", pfdeimpl->ref);
909 ensure_zero_events(pfdeimpl);
911 hr = IFileDialog_Advise(pfd, pfde, &cookie[0]);
912 ok(hr == S_OK, "got 0x%08x\n", hr);
913 todo_wine ok(cookie[0] == 1, "got cookie: %d\n", cookie[0]);
914 ok(pfdeimpl->ref == 1+1, "got ref %d\n", pfdeimpl->ref);
915 ensure_zero_events(pfdeimpl);
917 hr = IFileDialog_Unadvise(pfd, cookie[0]);
919 if(0)
921 /* Unadvising already unadvised cookies crashes on
922 Windows 7. */
923 IFileDialog_Unadvise(pfd, cookie[0]);
927 IFileDialogEvents_Release(pfde);
930 static void test_advise(void)
932 IFileDialog *pfd;
933 HRESULT hr;
934 LONG ref;
936 trace("Testing FileOpenDialog (advise)\n");
937 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
938 &IID_IFileDialog, (void**)&pfd);
939 ok(hr == S_OK, "got 0x%08x.\n", hr);
940 test_advise_helper(pfd);
941 ref = IFileDialog_Release(pfd);
942 ok(!ref, "Got refcount %d, should have been released.\n", ref);
944 trace("Testing FileSaveDialog (advise)\n");
945 hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER,
946 &IID_IFileDialog, (void**)&pfd);
947 ok(hr == S_OK, "got 0x%08x.\n", hr);
948 test_advise_helper(pfd);
949 ref = IFileDialog_Release(pfd);
950 ok(!ref, "Got refcount %d, should have been released.\n", ref);
953 static void touch_file(LPCWSTR filename)
955 HANDLE file;
956 file = CreateFileW(filename, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
957 ok(file != INVALID_HANDLE_VALUE, "Failed to create file.\n");
958 CloseHandle(file);
961 static void test_filename_savedlg_(LPCWSTR set_filename, LPCWSTR defext,
962 const COMDLG_FILTERSPEC *filterspec, UINT fs_count,
963 LPCWSTR exp_filename, const char *file, int line)
965 IFileSaveDialog *pfsd;
966 IFileDialogEventsImpl *pfdeimpl;
967 IFileDialogEvents *pfde;
968 DWORD cookie;
969 LPWSTR filename;
970 IShellItem *psi;
971 LONG ref;
972 HRESULT hr;
974 hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER,
975 &IID_IFileSaveDialog, (void**)&pfsd);
976 ok_(file,line)(hr == S_OK, "Got 0x%08x\n", hr);
978 if(fs_count)
980 hr = IFileSaveDialog_SetFileTypes(pfsd, fs_count, filterspec);
981 ok_(file,line)(hr == S_OK, "SetFileTypes failed: Got 0x%08x\n", hr);
984 if(defext)
986 hr = IFileSaveDialog_SetDefaultExtension(pfsd, defext);
987 ok_(file,line)(hr == S_OK, "SetDefaultExtensions failed: Got 0x%08x\n", hr);
990 pfde = IFileDialogEvents_Constructor();
991 pfdeimpl = impl_from_IFileDialogEvents(pfde);
992 pfdeimpl->set_filename = set_filename;
993 hr = IFileSaveDialog_Advise(pfsd, pfde, &cookie);
994 ok_(file,line)(hr == S_OK, "Advise failed: Got 0x%08x\n", hr);
996 hr = IFileSaveDialog_Show(pfsd, NULL);
997 ok_(file,line)(hr == S_OK, "Show failed: Got 0x%08x\n", hr);
999 hr = IFileSaveDialog_GetFileName(pfsd, &filename);
1000 ok_(file,line)(hr == S_OK, "GetFileName failed: Got 0x%08x\n", hr);
1001 ok_(file,line)(!lstrcmpW(filename, set_filename), "Got %s\n", wine_dbgstr_w(filename));
1002 CoTaskMemFree(filename);
1004 hr = IFileSaveDialog_GetResult(pfsd, &psi);
1005 ok_(file,line)(hr == S_OK, "GetResult failed: Got 0x%08x\n", hr);
1007 hr = IShellItem_GetDisplayName(psi, SIGDN_PARENTRELATIVEPARSING, &filename);
1008 ok_(file,line)(hr == S_OK, "GetDisplayName failed: Got 0x%08x\n", hr);
1009 ok_(file,line)(!lstrcmpW(filename, exp_filename), "(GetDisplayName) Got %s\n", wine_dbgstr_w(filename));
1010 CoTaskMemFree(filename);
1011 IShellItem_Release(psi);
1013 hr = IFileSaveDialog_Unadvise(pfsd, cookie);
1014 ok_(file,line)(hr == S_OK, "Unadvise failed: Got 0x%08x\n", hr);
1016 ref = IFileSaveDialog_Release(pfsd);
1017 ok_(file,line)(!ref, "Got refcount %d, should have been released.\n", ref);
1019 IFileDialogEvents_Release(pfde);
1021 #define test_filename_savedlg(set_filename, defext, filterspec, fs_count, exp_filename) \
1022 test_filename_savedlg_(set_filename, defext, filterspec, fs_count, exp_filename, __FILE__, __LINE__)
1024 static void test_filename_opendlg_(LPCWSTR set_filename, IShellItem *psi_current, LPCWSTR defext,
1025 const COMDLG_FILTERSPEC *filterspec, UINT fs_count,
1026 LPCWSTR exp_filename, const char *file, int line)
1028 IFileOpenDialog *pfod;
1029 IFileDialogEventsImpl *pfdeimpl;
1030 IFileDialogEvents *pfde;
1031 DWORD cookie;
1032 LPWSTR filename;
1033 IShellItemArray *psia;
1034 IShellItem *psi;
1035 LONG ref;
1036 HRESULT hr;
1038 hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
1039 &IID_IFileOpenDialog, (void**)&pfod);
1040 ok_(file,line)(hr == S_OK, "CoCreateInstance failed: Got 0x%08x\n", hr);
1042 if(defext)
1044 hr = IFileOpenDialog_SetDefaultExtension(pfod, defext);
1045 ok_(file,line)(hr == S_OK, "SetDefaultExtensions failed: Got 0x%08x\n", hr);
1048 if(fs_count)
1050 hr = IFileOpenDialog_SetFileTypes(pfod, 2, filterspec);
1051 ok_(file,line)(hr == S_OK, "SetFileTypes failed: Got 0x%08x\n", hr);
1054 hr = IFileOpenDialog_SetFolder(pfod, psi_current);
1055 ok_(file,line)(hr == S_OK, "SetFolder failed: Got 0x%08x\n", hr);
1057 pfde = IFileDialogEvents_Constructor();
1058 pfdeimpl = impl_from_IFileDialogEvents(pfde);
1059 pfdeimpl->set_filename = set_filename;
1060 pfdeimpl->set_filename_tried = FALSE;
1061 hr = IFileOpenDialog_Advise(pfod, pfde, &cookie);
1062 ok_(file,line)(hr == S_OK, "Advise failed: Got 0x%08x\n", hr);
1064 hr = IFileOpenDialog_Show(pfod, NULL);
1065 ok_(file,line)(hr == S_OK || (!exp_filename && hr == HRESULT_FROM_WIN32(ERROR_CANCELLED)),
1066 "Show failed: Got 0x%08x\n", hr);
1067 if(hr == S_OK)
1069 hr = IFileOpenDialog_GetResult(pfod, &psi);
1070 ok_(file,line)(hr == S_OK, "GetResult failed: Got 0x%08x\n", hr);
1072 hr = IShellItem_GetDisplayName(psi, SIGDN_PARENTRELATIVEPARSING, &filename);
1073 ok_(file,line)(hr == S_OK, "GetDisplayName(Result) failed: Got 0x%08x\n", hr);
1074 ok_(file,line)(!lstrcmpW(filename, exp_filename), "(GetResult) Got %s\n", wine_dbgstr_w(filename));
1075 CoTaskMemFree(filename);
1076 IShellItem_Release(psi);
1078 hr = IFileOpenDialog_GetResults(pfod, &psia);
1079 ok_(file,line)(hr == S_OK, "GetResults failed: Got 0x%08x\n", hr);
1080 hr = IShellItemArray_GetItemAt(psia, 0, &psi);
1081 ok_(file,line)(hr == S_OK, "GetItemAt failed: Got 0x%08x\n", hr);
1083 hr = IShellItem_GetDisplayName(psi, SIGDN_PARENTRELATIVEPARSING, &filename);
1084 ok_(file,line)(hr == S_OK, "GetDisplayName(Results) failed: Got 0x%08x\n", hr);
1085 ok_(file,line)(!lstrcmpW(filename, exp_filename), "(GetResults) Got %s\n", wine_dbgstr_w(filename));
1086 CoTaskMemFree(filename);
1088 IShellItem_Release(psi);
1089 IShellItemArray_Release(psia);
1091 else
1093 hr = IFileOpenDialog_GetResult(pfod, &psi);
1094 ok_(file,line)(hr == E_UNEXPECTED, "GetResult: Got 0x%08x\n", hr);
1096 hr = IFileOpenDialog_GetResults(pfod, &psia);
1097 ok_(file,line)(hr == E_FAIL, "GetResults: Got 0x%08x\n", hr);
1100 hr = IFileOpenDialog_GetFileName(pfod, &filename);
1101 ok_(file,line)(hr == S_OK, "GetFileName failed: Got 0x%08x\n", hr);
1102 ok_(file,line)(!lstrcmpW(filename, set_filename), "(GetFileName) Got %s\n", wine_dbgstr_w(filename));
1103 CoTaskMemFree(filename);
1106 hr = IFileOpenDialog_Unadvise(pfod, cookie);
1107 ok_(file,line)(hr == S_OK, "Unadvise failed: Got 0x%08x\n", hr);
1109 ref = IFileOpenDialog_Release(pfod);
1110 ok_(file,line)(!ref, "Got refcount %d, should have been released.\n", ref);
1112 IFileDialogEvents_Release(pfde);
1114 #define test_filename_opendlg(set_filename, psi, defext, filterspec, fs_count, exp_filename) \
1115 test_filename_opendlg_(set_filename, psi, defext, filterspec, fs_count, exp_filename, __FILE__, __LINE__)
1117 static void test_filename(void)
1119 IShellItem *psi_current;
1120 HRESULT hr;
1121 WCHAR buf[MAX_PATH];
1123 static const WCHAR filename_noextW[] = {'w','i','n','e','t','e','s','t',0};
1124 static const WCHAR filename_dotextW[] = {'w','i','n','e','t','e','s','t','.',0};
1125 static const WCHAR filename_dotanddefW[] = {'w','i','n','e','t','e','s','t','.','.','w','t','e',0};
1126 static const WCHAR filename_defextW[] = {'w','i','n','e','t','e','s','t','.','w','t','e',0};
1127 static const WCHAR filename_ext1W[] = {'w','i','n','e','t','e','s','t','.','w','t','1',0};
1128 static const WCHAR filename_ext2W[] = {'w','i','n','e','t','e','s','t','.','w','t','2',0};
1129 static const WCHAR filename_ext1anddefW[] =
1130 {'w','i','n','e','t','e','s','t','.','w','t','1','.','w','t','e',0};
1131 static const WCHAR defextW[] = {'w','t','e',0};
1132 static const WCHAR desc1[] = {'d','e','s','c','r','i','p','t','i','o','n','1',0};
1133 static const WCHAR desc2[] = {'d','e','s','c','r','i','p','t','i','o','n','2',0};
1134 static const WCHAR descdef[] = {'d','e','f','a','u','l','t',' ','d','e','s','c',0};
1135 static const WCHAR ext1[] = {'*','.','w','t','1',0};
1136 static const WCHAR ext2[] = {'*','.','w','t','2',0};
1137 static const WCHAR extdef[] = {'*','.','w','t','e',0};
1138 static const WCHAR complexext[] = {'*','.','w','t','2',';','*','.','w','t','1',0};
1140 static const COMDLG_FILTERSPEC filterspec[] = {
1141 { desc1, ext1 }, { desc2, ext2 }, { descdef, extdef }
1143 static const COMDLG_FILTERSPEC filterspec2[] = {
1144 { desc1, complexext }
1147 /* No extension */
1148 test_filename_savedlg(filename_noextW, NULL, NULL, 0, filename_noextW);
1149 /* Default extension */
1150 test_filename_savedlg(filename_noextW, defextW, NULL, 0, filename_defextW);
1151 /* Default extension on filename ending with a . */
1152 test_filename_savedlg(filename_dotextW, defextW, NULL, 0, filename_dotanddefW);
1153 /* Default extension on filename with default extension */
1154 test_filename_savedlg(filename_defextW, defextW, NULL, 0, filename_defextW);
1155 /* Default extension on filename with another extension */
1156 test_filename_savedlg(filename_ext1W, defextW, NULL, 0, filename_ext1anddefW);
1157 /* Default extension, filterspec without default extension */
1158 test_filename_savedlg(filename_noextW, defextW, filterspec, 2, filename_ext1W);
1159 /* Default extension, filterspec with default extension */
1160 test_filename_savedlg(filename_noextW, defextW, filterspec, 3, filename_ext1W);
1161 /* Default extension, filterspec with "complex" extension */
1162 test_filename_savedlg(filename_noextW, defextW, filterspec2, 1, filename_ext2W);
1164 GetCurrentDirectoryW(MAX_PATH, buf);
1165 ok(!!pSHCreateItemFromParsingName, "SHCreateItemFromParsingName is missing.\n");
1166 hr = pSHCreateItemFromParsingName(buf, NULL, &IID_IShellItem, (void**)&psi_current);
1167 ok(hr == S_OK, "Got 0x%08x\n", hr);
1169 touch_file(filename_noextW);
1170 touch_file(filename_defextW);
1171 touch_file(filename_ext2W);
1173 /* IFileOpenDialog, default extension */
1174 test_filename_opendlg(filename_noextW, psi_current, defextW, NULL, 0, filename_noextW);
1175 /* IFileOpenDialog, default extension and filterspec */
1176 test_filename_opendlg(filename_noextW, psi_current, defextW, filterspec, 2, filename_noextW);
1178 DeleteFileW(filename_noextW);
1179 /* IFileOpenDialog, default extension, noextW deleted */
1180 test_filename_opendlg(filename_noextW, psi_current, defextW, NULL, 0, filename_defextW);
1181 if(0) /* Interactive */
1183 /* IFileOpenDialog, filterspec, no default extension, noextW deleted */
1184 test_filename_opendlg(filename_noextW, psi_current, NULL, filterspec, 2, NULL);
1187 IShellItem_Release(psi_current);
1188 DeleteFileW(filename_defextW);
1189 DeleteFileW(filename_ext2W);
1192 START_TEST(itemdlg)
1194 OleInitialize(NULL);
1195 init_function_pointers();
1197 if(test_instantiation())
1199 test_basics();
1200 test_advise();
1201 test_filename();
1203 else
1204 skip("Skipping all Item Dialog tests.\n");
1206 OleUninitialize();