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