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