From: Damjan Jovanovic damjan.jov@gmail.com
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=57810 --- dlls/scrrun/filesystem.c | 12 +++++- dlls/scrrun/tests/filesystem.c | 76 ++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 2 deletions(-)
diff --git a/dlls/scrrun/filesystem.c b/dlls/scrrun/filesystem.c index e53355267db..d174125ea91 100644 --- a/dlls/scrrun/filesystem.c +++ b/dlls/scrrun/filesystem.c @@ -682,9 +682,17 @@ static HRESULT WINAPI textstream_WriteLine(ITextStream *iface, BSTR text)
static HRESULT WINAPI textstream_WriteBlankLines(ITextStream *iface, LONG lines) { - FIXME("%p, %ld stub\n", iface, lines); + struct textstream *stream = impl_from_ITextStream(iface); + HRESULT hr = S_OK;
- return E_NOTIMPL; + TRACE("%p, %ld.\n", iface, lines); + + if (lines < 0) + return E_INVALIDARG; + for (; lines > 0 && SUCCEEDED(hr); lines--) { + hr = textstream_writecrlf(stream); + } + return hr; }
static HRESULT WINAPI textstream_Skip(ITextStream *iface, LONG count) diff --git a/dlls/scrrun/tests/filesystem.c b/dlls/scrrun/tests/filesystem.c index e53bd092ce9..2efda2e762e 100644 --- a/dlls/scrrun/tests/filesystem.c +++ b/dlls/scrrun/tests/filesystem.c @@ -1738,6 +1738,81 @@ static void test_WriteLine(void) SysFreeString(nameW); }
+static HRESULT write_blank_lines(WCHAR *nameW, VARIANT_BOOL is_unicode, LONG lines) +{ + HRESULT hr; + ITextStream *stream; + + hr = IFileSystem3_CreateTextFile(fs3, nameW, VARIANT_FALSE, is_unicode, &stream); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + hr = ITextStream_WriteBlankLines(stream, lines); + ITextStream_Release(stream); + return hr; +} + +static void test_WriteBlankLines(void) +{ + WCHAR pathW[MAX_PATH], dirW[MAX_PATH]; + WCHAR ExpectedW[MAX_PATH]; + BSTR nameW; + HRESULT hr; + BOOL ret; + + get_temp_filepath(testfileW, pathW, dirW); + + ret = CreateDirectoryW(dirW, NULL); + ok(ret, "Unexpected retval %d, error %ld.\n", ret, GetLastError()); + + nameW = SysAllocString(pathW); + + hr = write_blank_lines(nameW, VARIANT_FALSE, -1); + ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr); + test_file_contents(pathW,0,NULL); + DeleteFileW(nameW); + + hr = write_blank_lines(nameW, VARIANT_FALSE, 0); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + test_file_contents(pathW,0,NULL); + DeleteFileW(nameW); + + hr = write_blank_lines(nameW, VARIANT_FALSE, 1); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + test_file_contents(pathW,2,"\r\n"); + DeleteFileW(nameW); + + hr = write_blank_lines(nameW, VARIANT_FALSE, 2); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + test_file_contents(pathW,4,"\r\n\r\n"); + DeleteFileW(nameW); + + hr = write_blank_lines(nameW, VARIANT_TRUE, -1); + ok(hr == E_INVALIDARG, "Unexpected hr %#lx.\n", hr); + lstrcpyW(ExpectedW, L"\ufeff"); + test_file_contents(pathW,lstrlenW(ExpectedW)*sizeof(WCHAR),ExpectedW); + DeleteFileW(nameW); + + hr = write_blank_lines(nameW, VARIANT_TRUE, 0); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + lstrcpyW(ExpectedW, L"\ufeff"); + test_file_contents(pathW,lstrlenW(ExpectedW)*sizeof(WCHAR),ExpectedW); + DeleteFileW(nameW); + + hr = write_blank_lines(nameW, VARIANT_TRUE, 1); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + lstrcpyW(ExpectedW, L"\ufeff\r\n"); + test_file_contents(pathW,lstrlenW(ExpectedW)*sizeof(WCHAR),ExpectedW); + DeleteFileW(nameW); + + hr = write_blank_lines(nameW, VARIANT_TRUE, 2); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + lstrcpyW(ExpectedW, L"\ufeff\r\n\r\n"); + test_file_contents(pathW,lstrlenW(ExpectedW)*sizeof(WCHAR),ExpectedW); + DeleteFileW(nameW); + + RemoveDirectoryW(dirW); + SysFreeString(nameW); +} + static void test_ReadAll(void) { static const WCHAR firstlineW[] = L"first"; @@ -2762,6 +2837,7 @@ START_TEST(filesystem) test_CreateTextFile(); test_FolderCreateTextFile(); test_WriteLine(); + test_WriteBlankLines(); test_ReadAll(); test_Read(); test_ReadLine();