Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=57810
Closes #57810
-- v4: scrrun: implement ITextStream::WriteBlankLines().
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 | 71 ++++++++++++++++++++++++++++++++++ 2 files changed, 81 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..ea0d0925a42 100644 --- a/dlls/scrrun/tests/filesystem.c +++ b/dlls/scrrun/tests/filesystem.c @@ -1738,6 +1738,76 @@ 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]; + 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); + test_file_contents(pathW, 1*sizeof(WCHAR), L"\ufeff"); + DeleteFileW(nameW); + + hr = write_blank_lines(nameW, VARIANT_TRUE, 0); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + test_file_contents(pathW, 1*sizeof(WCHAR), L"\ufeff"); + DeleteFileW(nameW); + + hr = write_blank_lines(nameW, VARIANT_TRUE, 1); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + test_file_contents(pathW, 3*sizeof(WCHAR), L"\ufeff\r\n"); + DeleteFileW(nameW); + + hr = write_blank_lines(nameW, VARIANT_TRUE, 2); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + test_file_contents(pathW, 5*sizeof(WCHAR), L"\ufeff\r\n\r\n"); + DeleteFileW(nameW); + + RemoveDirectoryW(dirW); + SysFreeString(nameW); +} + static void test_ReadAll(void) { static const WCHAR firstlineW[] = L"first"; @@ -2762,6 +2832,7 @@ START_TEST(filesystem) test_CreateTextFile(); test_FolderCreateTextFile(); test_WriteLine(); + test_WriteBlankLines(); test_ReadAll(); test_Read(); test_ReadLine();
On Sat Feb 8 18:10:47 2025 +0000, Nikolay Sivov wrote:
Thanks. You can do the same with WCHAR ones, the helper takes void* for that reason. But it's not very important.
I've changed those too now, but used N*sizeof(WCHAR) as the length for clarity.