Signed-off-by: Alex Henrie alexhenrie24@gmail.com --- dlls/scrrun/tests/filesystem.c | 80 ++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 28 deletions(-)
diff --git a/dlls/scrrun/tests/filesystem.c b/dlls/scrrun/tests/filesystem.c index 29ee73f243..d84828ec75 100644 --- a/dlls/scrrun/tests/filesystem.c +++ b/dlls/scrrun/tests/filesystem.c @@ -1469,6 +1469,7 @@ static void test_CreateTextFile(void) HANDLE file; HRESULT hr; BOOL ret; + INT len;
get_temp_filepath(testfileW, pathW, dirW);
@@ -1519,17 +1520,24 @@ static void test_CreateTextFile(void) 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, 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); + treats BOM like valuable data with appropriate CP_ACP -> WCHAR conversion. */ + len = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, utf16bom, -1, buffW, ARRAY_SIZE(buffW)); + if (len) + { + 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) /* win2003 */, "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); + } + else + { + /* ITextStream lets invalid characters through, but MultiByteToWideChar doesn't. + * This happens in Chinese, Japanese, and Korean locales. */ + skip("Can't determine how byte order mark should be (mis)interpreted in this locale\n"); + }
DeleteFileW(nameW); RemoveDirectoryW(dirW); @@ -1615,6 +1623,7 @@ static void test_ReadAll(void) HRESULT hr; BOOL ret; BSTR str; + INT len;
get_temp_filepath(testfileW, pathW, dirW);
@@ -1651,13 +1660,21 @@ static void test_ReadAll(void) ok(hr == E_POINTER, "got 0x%08x\n", hr);
/* Buffer content is not interpreted - BOM is kept, all data is converted to WCHARs */ - str = NULL; - hr = ITextStream_ReadAll(stream, &str); - ok(hr == S_FALSE || broken(hr == S_OK) /* win2k */, "got 0x%08x\n", hr); - buffW[0] = 0; - MultiByteToWideChar(CP_ACP, 0, utf16bom, -1, buffW, ARRAY_SIZE(buffW)); - ok(str[0] == buffW[0] && str[1] == buffW[1], "got %s, %d\n", wine_dbgstr_w(str), SysStringLen(str)); - SysFreeString(str); + len = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, utf16bom, -1, buffW, ARRAY_SIZE(buffW)); + if (len) + { + str = NULL; + hr = ITextStream_ReadAll(stream, &str); + ok(hr == S_FALSE || broken(hr == S_OK) /* win2003 */, "got 0x%08x\n", hr); + ok(str[0] == buffW[0] && str[1] == buffW[1], "got %s, %d\n", wine_dbgstr_w(str), SysStringLen(str)); + SysFreeString(str); + } + else + { + /* ITextStream lets invalid characters through, but MultiByteToWideChar doesn't. + * This happens in Chinese, Japanese, and Korean locales. */ + skip("Can't determine how byte order mark should be (mis)interpreted in this locale\n"); + } ITextStream_Release(stream);
/* Unicode file -> read with unicode stream */ @@ -1744,6 +1761,7 @@ static void test_Read(void) HRESULT hr; BOOL ret; BSTR str; + INT len;
get_temp_filepath(testfileW, pathW, dirW);
@@ -1796,16 +1814,22 @@ static void test_Read(void) ok(str == NULL, "got %p\n", str);
/* Buffer content is not interpreted - BOM is kept, all data is converted to WCHARs */ - str = NULL; - hr = ITextStream_Read(stream, 2, &str); - ok(hr == S_OK, "got 0x%08x\n", hr); - - buffW[0] = 0; - MultiByteToWideChar(CP_ACP, 0, utf16bom, -1, buffW, ARRAY_SIZE(buffW)); - - ok(!lstrcmpW(str, buffW), "got %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(buffW)); - ok(SysStringLen(str) == 2, "got %d\n", SysStringLen(str)); - SysFreeString(str); + len = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, utf16bom, -1, buffW, ARRAY_SIZE(buffW)); + if (len) + { + str = NULL; + hr = ITextStream_Read(stream, 2, &str); + ok(hr == S_OK, "got 0x%08x\n", hr); + ok(!lstrcmpW(str, buffW), "got %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(buffW)); + ok(SysStringLen(str) == 2, "got %d\n", SysStringLen(str)); + SysFreeString(str); + } + else + { + /* ITextStream lets invalid characters through, but MultiByteToWideChar doesn't. + * This happens in Chinese, Japanese, and Korean locales. */ + skip("Can't determine how byte order mark should be (mis)interpreted in this locale\n"); + } ITextStream_Release(stream);
/* Unicode file -> read with unicode stream */
This will suppress failures, but what we need is to understand how it works and adjust implementation.
On Tue, Dec 18, 2018 at 11:11 PM Nikolay Sivov nsivov@codeweavers.com wrote:
This will suppress failures, but what we need is to understand how it works and adjust implementation.
The invalid codepoint produced in the Chinese locale is U+FA0F. ITextStream_Read lets it through unmodified, and ITextStream_ReadAll drops it. Do you know how to make MultiByteToWideChar do either of those things? If not, changing the test failure to a test skipped warning is still a step in the right direction, and I included comments so that the next person who wants to look into this has a good place to start.
-Alex
On Tue, Dec 18, 2018 at 11:33 PM Alex Henrie alexhenrie24@gmail.com wrote:
On Tue, Dec 18, 2018 at 11:11 PM Nikolay Sivov nsivov@codeweavers.com wrote:
This will suppress failures, but what we need is to understand how it works and adjust implementation.
The invalid codepoint produced in the Chinese locale is U+FA0F. ITextStream_Read lets it through unmodified, and ITextStream_ReadAll drops it. Do you know how to make MultiByteToWideChar do either of those things? If not, changing the test failure to a test skipped warning is still a step in the right direction, and I included comments so that the next person who wants to look into this has a good place to start.
Actually never mind, I don't know what's different about the first of the three failing tests that causes the codepoint to be dropped instead of being let through like the other two tests. The first two tests use ITextStream_ReadAll and the last one uses ITextStream_Read.
-Alex