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