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