[PATCH 1/3] scrrun: check file contents using ReadFile in CreateTextFile test.
Robert Wilhelm
robert.wilhelm at gmx.net
Thu Dec 2 15:32:24 CST 2021
This is less fragile then former MultiByteToWideChar method because second byte of BOM (0xfe) is LeadByte in Asian locales.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=39244
Signed-off-by: Robert Wilhelm <robert.wilhelm at gmx.net>
---
dlls/scrrun/tests/filesystem.c | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/dlls/scrrun/tests/filesystem.c b/dlls/scrrun/tests/filesystem.c
index 91729bb047f..dba8c067d63 100644
--- a/dlls/scrrun/tests/filesystem.c
+++ b/dlls/scrrun/tests/filesystem.c
@@ -1462,12 +1462,13 @@ static void get_temp_filepath(const WCHAR *filename, WCHAR *path, WCHAR *dir)
static void test_CreateTextFile(void)
{
- WCHAR pathW[MAX_PATH], dirW[MAX_PATH], buffW[10];
+ WCHAR pathW[MAX_PATH], dirW[MAX_PATH], buffW[10], buff2W[10];
ITextStream *stream;
BSTR nameW, str;
HANDLE file;
HRESULT hr;
BOOL ret;
+ DWORD r;
get_temp_filepath(testfileW, pathW, dirW);
@@ -1517,18 +1518,18 @@ static void test_CreateTextFile(void)
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));
+ /* check contents */
+ file = CreateFileW(pathW, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ ok(file != INVALID_HANDLE_VALUE, "got %p\n", file);
+ r = 0;
+ ret = ReadFile(file, buffW, sizeof(buffW), &r, NULL);
+ ok(ret && r == 2, "read %d, got %d, %d\n", r, ret, GetLastError());
+ buffW[r/sizeof(WCHAR)] = 0;
- hr = IFileSystem3_OpenTextFile(fs3, nameW, 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);
+ buff2W[0] = 0xfeff;
+ buff2W[1] = 0;
+ ok(!lstrcmpW(buff2W, buffW), "got %s, expected %s\n", wine_dbgstr_w(buffW), wine_dbgstr_w(buff2W));
+ CloseHandle(file);
DeleteFileW(nameW);
RemoveDirectoryW(dirW);
--
2.31.1
More information about the wine-devel
mailing list