Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51971 Signed-off-by: Robert Wilhelm robert.wilhelm@gmx.net --- dlls/scrrun/filesystem.c | 16 ++++++- dlls/scrrun/tests/filesystem.c | 79 ++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 2 deletions(-)
diff --git a/dlls/scrrun/filesystem.c b/dlls/scrrun/filesystem.c index e55615eb4da..c42a3155c4f 100644 --- a/dlls/scrrun/filesystem.c +++ b/dlls/scrrun/filesystem.c @@ -2522,9 +2522,21 @@ static HRESULT WINAPI folder_get_Files(IFolder *iface, IFileCollection **files) static HRESULT WINAPI folder_CreateTextFile(IFolder *iface, BSTR filename, VARIANT_BOOL overwrite, VARIANT_BOOL unicode, ITextStream **stream) { + DWORD disposition; + BSTR path; + HRESULT hres; + struct folder *This = impl_from_IFolder(iface); - FIXME("(%p)->(%s %x %x %p): stub\n", This, debugstr_w(filename), overwrite, unicode, stream); - return E_NOTIMPL; + + TRACE("%p %s %d %d %p\n", iface, debugstr_w(filename), overwrite, unicode, stream); + + hres = build_path(This->path, filename, &path); + if (FAILED(hres)) return hres; + + disposition = overwrite == VARIANT_TRUE ? CREATE_ALWAYS : CREATE_NEW; + hres = create_textstream(path, disposition, ForWriting, unicode ? TristateTrue : TristateFalse, stream); + SysFreeString(path); + return hres; }
static const IFolderVtbl foldervtbl = { diff --git a/dlls/scrrun/tests/filesystem.c b/dlls/scrrun/tests/filesystem.c index 5c55965ce88..352e986944a 100644 --- a/dlls/scrrun/tests/filesystem.c +++ b/dlls/scrrun/tests/filesystem.c @@ -1535,6 +1535,84 @@ static void test_CreateTextFile(void) SysFreeString(nameW); }
+/* shameless copy of test_CreateTextFile(void) */ +static void test_FolderCreateTextFile(void) +{ + WCHAR pathW[MAX_PATH], dirW[MAX_PATH], buffW[10]; + ITextStream *stream; + BSTR nameW, str; + HANDLE file; + IFolder *folder; + HRESULT hr; + BOOL ret; + + get_temp_filepath(testfileW, pathW, dirW); + nameW = SysAllocString(L"foo.txt"); + lstrcpyW(pathW, dirW); + lstrcatW(pathW, nameW); + + ret = CreateDirectoryW(dirW, NULL); + ok(ret, "got %d, %d\n", ret, GetLastError()); + + hr = IFileSystem3_GetFolder(fs3, dirW, &folder); + ok(ret, "got %d, %d\n", ret, GetLastError()); + + hr = IFolder_CreateTextFile(folder, nameW, VARIANT_FALSE, VARIANT_FALSE, &stream); + ok(hr == S_OK, "got 0x%08x\n", hr); + + test_provideclassinfo(stream, &CLSID_TextStream); + + hr = ITextStream_Read(stream, 1, &str); + ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr); + + hr = ITextStream_Close(stream); + ok(hr == S_OK, "got 0x%08x\n", hr); + + hr = ITextStream_Read(stream, 1, &str); + ok(hr == CTL_E_BADFILEMODE || hr == E_VAR_NOT_SET, "got 0x%08x\n", hr); + + hr = ITextStream_Close(stream); + ok(hr == S_FALSE || hr == E_VAR_NOT_SET, "got 0x%08x\n", hr); + + ITextStream_Release(stream); + + /* check it's created */ + file = CreateFileW(pathW, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + ok(file != INVALID_HANDLE_VALUE, "got %p\n", file); + CloseHandle(file); + + /* try to create again with no-overwrite mode */ + hr = IFolder_CreateTextFile(folder, nameW, VARIANT_FALSE, VARIANT_FALSE, &stream); + ok(hr == CTL_E_FILEALREADYEXISTS, "got 0x%08x\n", hr); + + /* now overwrite */ + hr = IFolder_CreateTextFile(folder, nameW, VARIANT_TRUE, VARIANT_FALSE, &stream); + ok(hr == S_OK, "got 0x%08x\n", hr); + ITextStream_Release(stream); + + /* overwrite in Unicode mode, check for BOM */ + hr = IFolder_CreateTextFile(folder, nameW, VARIANT_TRUE, VARIANT_TRUE, &stream); + ok(hr == S_OK, "got 0x%08x\n", hr); + ITextStream_Release(stream); + + /* File was created in Unicode mode, it contains 0xfffe BOM. Opening it in non-Unicode mode + treats BOM like a valuable data with appropriate CP_ACP -> WCHAR conversion. */ + buffW[0] = 0; + MultiByteToWideChar(CP_ACP, 0, utf16bom, -1, buffW, ARRAY_SIZE(buffW)); + + hr = IFileSystem3_OpenTextFile(fs3, pathW, ForReading, VARIANT_FALSE, TristateFalse, &stream); + ok(hr == S_OK, "got 0x%08x\n", hr); + hr = ITextStream_ReadAll(stream, &str); + ok(hr == S_FALSE || broken(hr == S_OK) /* win2k */, "got 0x%08x\n", hr); + ok(!lstrcmpW(str, buffW), "got %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(buffW)); + SysFreeString(str); + ITextStream_Release(stream); + + DeleteFileW(pathW); + RemoveDirectoryW(dirW); + SysFreeString(nameW); +} + static void test_WriteLine(void) { WCHAR pathW[MAX_PATH], dirW[MAX_PATH]; @@ -2516,6 +2594,7 @@ START_TEST(filesystem) test_FileCollection(); test_DriveCollection(); test_CreateTextFile(); + test_FolderCreateTextFile(); test_WriteLine(); test_ReadAll(); test_Read(); -- 2.31.1
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=102582
Your paranoid android.
=== w7u_2qxl (32 bit report) ===
scrrun: 06f0:filesystem: unhandled exception c0000005 at 0041169A
=== w7u_adm (32 bit report) ===
scrrun: 0878:filesystem: unhandled exception c0000005 at 0041169A
=== w7u_el (32 bit report) ===
scrrun: 0850:filesystem: unhandled exception c0000005 at 0041169A
=== w8 (32 bit report) ===
scrrun: 0b80:filesystem: unhandled exception c0000005 at 0041169A
=== w8adm (32 bit report) ===
scrrun: 0cbc:filesystem: unhandled exception c0000005 at 0041169A
=== w864 (32 bit report) ===
scrrun: 0a8c:filesystem: unhandled exception c0000005 at 0041169A
=== w1064v1507 (32 bit report) ===
scrrun: 08e8:filesystem: unhandled exception c0000005 at 0041169A
=== w1064v1809 (32 bit report) ===
scrrun: 19d4:filesystem: unhandled exception c0000005 at 0041169A
=== w1064 (32 bit report) ===
scrrun: 1980:filesystem: unhandled exception c0000005 at 0041169A
=== w1064_tsign (32 bit report) ===
scrrun: 1100:filesystem: unhandled exception c0000005 at 0041169A
=== w10pro64 (32 bit report) ===
scrrun: 1ef4:filesystem: unhandled exception c0000005 at 0041169A
=== w864 (64 bit report) ===
scrrun: 0a8c:filesystem: unhandled exception c0000005 at 000000000040F449
=== w1064v1507 (64 bit report) ===
scrrun: 0e2c:filesystem: unhandled exception c0000005 at 000000000040F449
=== w1064v1809 (64 bit report) ===
scrrun: 1a34:filesystem: unhandled exception c0000005 at 000000000040F449
=== w1064 (64 bit report) ===
scrrun: 1adc:filesystem: unhandled exception c0000005 at 000000000040F449
=== w1064_2qxl (64 bit report) ===
scrrun: 19b4:filesystem: unhandled exception c0000005 at 000000000040F449
=== w1064_tsign (64 bit report) ===
scrrun: 0dd8:filesystem: unhandled exception c0000005 at 000000000040F449
=== w10pro64 (64 bit report) ===
scrrun: 1eb4:filesystem: unhandled exception c0000005 at 000000000040F449
=== w10pro64_ar (64 bit report) ===
scrrun: 1e7c:filesystem: unhandled exception c0000005 at 000000000040F449
=== w10pro64_he (64 bit report) ===
scrrun: 1f10:filesystem: unhandled exception c0000005 at 000000000040F449
=== w10pro64_ja (64 bit report) ===
scrrun: 1ef4:filesystem: unhandled exception c0000005 at 000000000040F449
=== w10pro64_zh_CN (64 bit report) ===
scrrun: 209c:filesystem: unhandled exception c0000005 at 000000000040F449
=== debiant2 (32 bit Chinese:China report) ===
scrrun: filesystem.c:1607: Test failed: got L"\f8f5", expected L"\f8f5?"