Module: wine Branch: master Commit: 3ec84397c95ada14d2ee2300d55b0ea227d51a43 URL: http://source.winehq.org/git/wine.git/?a=commit;h=3ec84397c95ada14d2ee2300d5...
Author: Vincent Povirk vincent@codeweavers.com Date: Thu Aug 13 15:12:25 2015 -0500
comdlg32: Add test for IFileDialogEvents::OnOverwrite.
---
dlls/comdlg32/tests/itemdlg.c | 162 ++++++++++++++++++++++++++++++++++++++++++ include/shobjidl.idl | 2 +- 2 files changed, 163 insertions(+), 1 deletion(-)
diff --git a/dlls/comdlg32/tests/itemdlg.c b/dlls/comdlg32/tests/itemdlg.c index ddf21f6..b7238bb 100644 --- a/dlls/comdlg32/tests/itemdlg.c +++ b/dlls/comdlg32/tests/itemdlg.c @@ -288,6 +288,9 @@ static HRESULT WINAPI IFileDialogEvents_fnOnOverwrite(IFileDialogEvents *iface, { IFileDialogEventsImpl *This = impl_from_IFileDialogEvents(iface); This->OnOverwrite++; + ok(*pResponse == FDEOR_DEFAULT, "overwrite response %u\n", *pResponse); + *pResponse = FDEOR_ACCEPT; + ok(!This->OnFileOk, "OnFileOk already called %u times\n", This->OnFileOk); return S_OK; }
@@ -2261,6 +2264,164 @@ if (0) IFileDialog_Release(fd); }
+static void test_overwrite(void) +{ + static const WCHAR filename_winetest[] = {'w','i','n','e','t','e','s','t','.','o','v','w',0}; + IFileDialogEventsImpl *pfdeimpl; + IFileDialogEvents *pfde; + IFileDialog *fd; + DWORD cookie; + LPWSTR filename; + IShellItem *psi_current; + WCHAR buf[MAX_PATH]; + HRESULT hr; + + GetCurrentDirectoryW(MAX_PATH, buf); + ok(!!pSHCreateItemFromParsingName, "SHCreateItemFromParsingName is missing.\n"); + hr = pSHCreateItemFromParsingName(buf, NULL, &IID_IShellItem, (void**)&psi_current); + ok(hr == S_OK, "Got 0x%08x\n", hr); + + touch_file(filename_winetest); + + /* FOS_OVERWRITEPROMPT has no effect on open dialog */ + hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, + &IID_IFileDialog, (void**)&fd); + ok(hr == S_OK, "got 0x%08x.\n", hr); + + hr = IFileDialog_SetOptions(fd, FOS_OVERWRITEPROMPT | FOS_NOCHANGEDIR); + ok(hr == S_OK, "got 0x%08x.\n", hr); + + hr = IFileDialog_SetFolder(fd, psi_current); + ok(hr == S_OK, "got 0x%08x.\n", hr); + + pfde = IFileDialogEvents_Constructor(); + pfdeimpl = impl_from_IFileDialogEvents(pfde); + pfdeimpl->set_filename = filename_winetest; + hr = IFileDialog_Advise(fd, pfde, &cookie); + ok(hr == S_OK, "Advise failed: Got 0x%08x\n", hr); + + hr = IFileDialog_Show(fd, NULL); + ok(hr == S_OK, "Show failed: Got 0x%08x\n", hr); + + ok(!pfdeimpl->OnOverwrite, "got %u overwrite events\n", pfdeimpl->OnOverwrite); + ok(pfdeimpl->OnFileOk == 1, "got %u ok events\n", pfdeimpl->OnFileOk); + + hr = IFileDialog_GetFileName(fd, &filename); + ok(hr == S_OK, "GetFileName failed: Got 0x%08x\n", hr); + ok(!lstrcmpW(filename, filename_winetest), "Got %s\n", wine_dbgstr_w(filename)); + CoTaskMemFree(filename); + + hr = IFileDialog_Unadvise(fd, cookie); + ok(hr == S_OK, "got 0x%08x.\n", hr); + + IFileDialog_Release(fd); + + IFileDialogEvents_Release(pfde); + + /* Save dialog doesn't check for overwrite without FOS_OVERWRITEPROMPT set */ + hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER, + &IID_IFileDialog, (void**)&fd); + ok(hr == S_OK, "got 0x%08x.\n", hr); + + hr = IFileDialog_SetOptions(fd, FOS_NOREADONLYRETURN | FOS_PATHMUSTEXIST | FOS_NOCHANGEDIR); + ok(hr == S_OK, "got 0x%08x.\n", hr); + + hr = IFileDialog_SetFolder(fd, psi_current); + ok(hr == S_OK, "got 0x%08x.\n", hr); + + pfde = IFileDialogEvents_Constructor(); + pfdeimpl = impl_from_IFileDialogEvents(pfde); + pfdeimpl->set_filename = filename_winetest; + hr = IFileDialog_Advise(fd, pfde, &cookie); + ok(hr == S_OK, "Advise failed: Got 0x%08x\n", hr); + + hr = IFileDialog_Show(fd, NULL); + ok(hr == S_OK, "Show failed: Got 0x%08x\n", hr); + + ok(!pfdeimpl->OnOverwrite, "got %u overwrite events\n", pfdeimpl->OnOverwrite); + ok(pfdeimpl->OnFileOk == 1, "got %u ok events\n", pfdeimpl->OnFileOk); + + hr = IFileDialog_GetFileName(fd, &filename); + ok(hr == S_OK, "GetFileName failed: Got 0x%08x\n", hr); + ok(!lstrcmpW(filename, filename_winetest), "Got %s\n", wine_dbgstr_w(filename)); + CoTaskMemFree(filename); + + hr = IFileDialog_Unadvise(fd, cookie); + ok(hr == S_OK, "got 0x%08x.\n", hr); + + IFileDialog_Release(fd); + + IFileDialogEvents_Release(pfde); + + /* Save dialog with FOS_OVERWRITEPROMPT set */ + hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER, + &IID_IFileDialog, (void**)&fd); + ok(hr == S_OK, "got 0x%08x.\n", hr); + + hr = IFileDialog_SetFolder(fd, psi_current); + ok(hr == S_OK, "got 0x%08x.\n", hr); + + pfde = IFileDialogEvents_Constructor(); + pfdeimpl = impl_from_IFileDialogEvents(pfde); + pfdeimpl->set_filename = filename_winetest; + hr = IFileDialog_Advise(fd, pfde, &cookie); + ok(hr == S_OK, "Advise failed: Got 0x%08x\n", hr); + + hr = IFileDialog_Show(fd, NULL); + ok(hr == S_OK, "Show failed: Got 0x%08x\n", hr); + + todo_wine ok(pfdeimpl->OnOverwrite == 1, "got %u overwrite events\n", pfdeimpl->OnOverwrite); + ok(pfdeimpl->OnFileOk == 1, "got %u ok events\n", pfdeimpl->OnFileOk); + + hr = IFileDialog_GetFileName(fd, &filename); + ok(hr == S_OK, "GetFileName failed: Got 0x%08x\n", hr); + ok(!lstrcmpW(filename, filename_winetest), "Got %s\n", wine_dbgstr_w(filename)); + CoTaskMemFree(filename); + + hr = IFileDialog_Unadvise(fd, cookie); + ok(hr == S_OK, "got 0x%08x.\n", hr); + + IFileDialog_Release(fd); + + IFileDialogEvents_Release(pfde); + + DeleteFileW(filename_winetest); + + /* Save dialog with FOS_OVERWRITEPROMPT set but without existing file */ + hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER, + &IID_IFileDialog, (void**)&fd); + ok(hr == S_OK, "got 0x%08x.\n", hr); + + hr = IFileDialog_SetFolder(fd, psi_current); + ok(hr == S_OK, "got 0x%08x.\n", hr); + + pfde = IFileDialogEvents_Constructor(); + pfdeimpl = impl_from_IFileDialogEvents(pfde); + pfdeimpl->set_filename = filename_winetest; + hr = IFileDialog_Advise(fd, pfde, &cookie); + ok(hr == S_OK, "Advise failed: Got 0x%08x\n", hr); + + hr = IFileDialog_Show(fd, NULL); + ok(hr == S_OK, "Show failed: Got 0x%08x\n", hr); + + ok(!pfdeimpl->OnOverwrite, "got %u overwrite events\n", pfdeimpl->OnOverwrite); + ok(pfdeimpl->OnFileOk == 1, "got %u ok events\n", pfdeimpl->OnFileOk); + + hr = IFileDialog_GetFileName(fd, &filename); + ok(hr == S_OK, "GetFileName failed: Got 0x%08x\n", hr); + ok(!lstrcmpW(filename, filename_winetest), "Got %s\n", wine_dbgstr_w(filename)); + CoTaskMemFree(filename); + + hr = IFileDialog_Unadvise(fd, cookie); + ok(hr == S_OK, "got 0x%08x.\n", hr); + + IFileDialog_Release(fd); + + IFileDialogEvents_Release(pfde); + + IShellItem_Release(psi_current); +} + START_TEST(itemdlg) { OleInitialize(NULL); @@ -2274,6 +2435,7 @@ START_TEST(itemdlg) test_filename(); test_customize(); test_persistent_state(); + test_overwrite(); } else skip("Skipping all Item Dialog tests.\n"); diff --git a/include/shobjidl.idl b/include/shobjidl.idl index b021178..1cc6132 100644 --- a/include/shobjidl.idl +++ b/include/shobjidl.idl @@ -2716,7 +2716,7 @@ interface IFileDialog; typedef [v1_enum] enum FDE_OVERWRITE_RESPONSE { FDEOR_DEFAULT = 0, - FDEOR_ACCCEP = 1, + FDEOR_ACCEPT = 1, FDEOR_REFUSE = 2 } FDE_OVERWRITE_RESPONSE;