diff options
author | Jiyoung Yun <jy910.yun@samsung.com> | 2016-11-23 19:09:09 +0900 |
---|---|---|
committer | Jiyoung Yun <jy910.yun@samsung.com> | 2016-11-23 19:09:09 +0900 |
commit | 4b4aad7217d3292650e77eec2cf4c198ea9c3b4b (patch) | |
tree | 98110734c91668dfdbb126fcc0e15ddbd93738ca /src/pal/tests/palsuite/locale_info/MultiByteToWideChar | |
parent | fa45f57ed55137c75ac870356a1b8f76c84b229c (diff) | |
download | coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.gz coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.tar.bz2 coreclr-4b4aad7217d3292650e77eec2cf4c198ea9c3b4b.zip |
Imported Upstream version 1.1.0upstream/1.1.0
Diffstat (limited to 'src/pal/tests/palsuite/locale_info/MultiByteToWideChar')
13 files changed, 589 insertions, 0 deletions
diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/CMakeLists.txt new file mode 100644 index 0000000000..0b8ae6062e --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +add_subdirectory(test1) +add_subdirectory(test2) +add_subdirectory(test3) +add_subdirectory(test4) diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test1/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test1/CMakeLists.txt new file mode 100644 index 0000000000..044c47712b --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test1/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test1.c +) + +add_executable(paltest_multibytetowidechar_test1 + ${SOURCES} +) + +add_dependencies(paltest_multibytetowidechar_test1 coreclrpal) + +target_link_libraries(paltest_multibytetowidechar_test1 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test1/test1.c b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test1/test1.c new file mode 100644 index 0000000000..81f58a532c --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test1/test1.c @@ -0,0 +1,81 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================================ +** +** Source: test1.c +** +** Purpose: Tests MultiByteToWideChar with all the ASCII characters (0-127). +** Also tests that WideCharToMultiByte handles different buffer +** lengths correctly (0, -1, and a valid length) +** +** +**==========================================================================*/ + +#include <palsuite.h> + +/* + * For now, it is assumed that MultiByteToWideChar will only be used in the PAL + * with CP_ACP, and that dwFlags will be 0. + */ + +int __cdecl main(int argc, char *argv[]) +{ + char mbStr[128]; + WCHAR wideStr[128]; + int ret; + int i; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + for (i=0; i<128; i++) + { + mbStr[i] = 127 - i; + wideStr[i] = 0; + } + + + ret = MultiByteToWideChar(CP_ACP, 0, mbStr, -1, wideStr, 0); + if (ret != 128) + { + Fail("MultiByteToWideChar did not return correct string length!\n" + "Got %d, expected %d\n", ret, 128); + } + + /* Make sure the ASCII set (0-127) gets translated correctly */ + ret = MultiByteToWideChar(CP_ACP, 0, mbStr, -1, wideStr, 128); + if (ret != 128) + { + Fail("MultiByteToWideChar did not return correct string length!\n" + "Got %d, expected %d\n", ret, 128); + } + + for (i=0; i<128; i++) + { + if (wideStr[i] != (WCHAR)(127 - i)) + { + Fail("MultiByteToWideChar failed to translate correctly!\n" + "Expected character %d to be %c (%x), got %c (%x)\n", + i, 127 - i, 127 - i,wideStr[i], wideStr[i]); + } + } + + + /* try a 0 length string */ + mbStr[0] = 0; + ret = MultiByteToWideChar(CP_ACP, 0, mbStr, -1, wideStr, 0); + if (ret != 1) + { + Fail("MultiByteToWideChar did not return correct string length!\n" + "Got %d, expected %d\n", ret, 1); + } + + PAL_Terminate(); + + return PASS; +} + diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test1/testinfo.dat b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test1/testinfo.dat new file mode 100644 index 0000000000..0e4591d247 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test1/testinfo.dat @@ -0,0 +1,14 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = Locale Information +Function = MultiByteToWideChar +Name = Test #1 for MultiByteToWideChar +TYPE = DEFAULT +EXE1 = test1 +Description +=Tests MultiByteToWideChar with all the ASCII characters (0-127). +=Also tests that WideCharToMultiByte handles different buffer +=lengths correctly (0, -1, and a valid length) diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test2/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test2/CMakeLists.txt new file mode 100644 index 0000000000..0367d53938 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test2/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test2.c +) + +add_executable(paltest_multibytetowidechar_test2 + ${SOURCES} +) + +add_dependencies(paltest_multibytetowidechar_test2 coreclrpal) + +target_link_libraries(paltest_multibytetowidechar_test2 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test2/test2.c b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test2/test2.c new file mode 100644 index 0000000000..1370dba894 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test2/test2.c @@ -0,0 +1,68 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================================ +** +** Source: test2.c +** +** Purpose: Tests that MultiByteToWideChar respects the length of the wide +** character string. + +** +**==========================================================================*/ + +#include <palsuite.h> + +/* + * For now, it is assumed that MultiByteToWideChar will only be used in the PAL + * with CP_ACP, and that dwFlags will be 0. + */ + +int __cdecl main(int argc, char *argv[]) +{ + char mbStr[128]; + WCHAR wideStr[128]; + int ret; + int i; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + for (i=0; i<128; i++) + { + mbStr[i] = 'a'; + wideStr[i] = 0; + } + + mbStr[127] = 0; + + + ret = MultiByteToWideChar(CP_ACP, 0, mbStr, 10, wideStr, 0); + if (ret != 10) + { + Fail("MultiByteToWideChar did not return correct string length!\n" + "Got %d, expected %d\n", ret, 10); + } + + wideStr[10] = (WCHAR) 'b'; + + ret = MultiByteToWideChar(CP_ACP, 0, mbStr, 10, wideStr, 128); + if (ret != 10) + { + Fail("MultiByteToWideChar did not return correct string length!\n" + "Got %d, expected %d\n", ret, 10); + } + + if (wideStr[10] != 'b') + { + Fail("WideCharToMultiByte overflowed the destination buffer!\n"); + } + + PAL_Terminate(); + + return PASS; +} + diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test2/testinfo.dat b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test2/testinfo.dat new file mode 100644 index 0000000000..5211db1256 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test2/testinfo.dat @@ -0,0 +1,13 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = Locale Information +Function = MultiByteToWideChar +Name = Test #2 for MultiByteToWideChar +TYPE = DEFAULT +EXE1 = test2 +Description +=Tests that MultiByteToWideChar respects the length of the wide +=character string. diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test3/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test3/CMakeLists.txt new file mode 100644 index 0000000000..57e3d66faf --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test3/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test3.c +) + +add_executable(paltest_multibytetowidechar_test3 + ${SOURCES} +) + +add_dependencies(paltest_multibytetowidechar_test3 coreclrpal) + +target_link_libraries(paltest_multibytetowidechar_test3 + pthread + m + coreclrpal +) diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test3/test3.c b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test3/test3.c new file mode 100644 index 0000000000..1b3a4bd4f5 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test3/test3.c @@ -0,0 +1,73 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================================ +** +** Source: test3.c +** +** Purpose: Tests that MultiByteToWideChar correctly handles the following +** error conditions: insufficient buffer space, invalid code pages, +** and invalid flags. +** +** +**==========================================================================*/ + +#include <palsuite.h> + + +int __cdecl main(int argc, char *argv[]) +{ + char mbStr[128]; + WCHAR wideStr[128]; + int ret; + int i; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + for (i=0; i<128; i++) + { + mbStr[i] = 'a'; + wideStr[i] = 0; + } + + mbStr[127] = 0; + + /* try with insufficient buffer space */ + ret = MultiByteToWideChar(CP_ACP, 0, mbStr, -1, wideStr, 10); + if (ret != 0) + { + Fail("MultiByteToWideChar did not return an error!\n" + "Expected return of 0, got %d", ret); + } + + ret = GetLastError(); + if (ret != ERROR_INSUFFICIENT_BUFFER) + { + Fail("MultiByteToWideChar did not set the last error to " + "ERROR_INSUFFICIENT_BUFFER!\n"); + } + + /* try with a wacky code page */ + ret = MultiByteToWideChar(-1, 0, mbStr, -1, wideStr, 128); + if (ret != 0) + { + Fail("MultiByteToWideChar did not return an error!\n" + "Expected return of 0, got %d", ret); + } + + ret = GetLastError(); + if (ret != ERROR_INVALID_PARAMETER) + { + Fail("MultiByteToWideChar did not set the last error to " + "ERROR_INVALID_PARAMETER!\n"); + } + + PAL_Terminate(); + + return PASS; +} + diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test3/testinfo.dat b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test3/testinfo.dat new file mode 100644 index 0000000000..c59f285dca --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test3/testinfo.dat @@ -0,0 +1,15 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. +# See the LICENSE file in the project root for more information. + +Version = 1.0 +Section = Locale Information +Function = MultiByteToWideChar +Name = Test #3 for MultiByteToWideChar +TYPE = DEFAULT +EXE1 = test3 +Description +=Tests that MultiByteToWideChar correctly handles the following +=error conditions: insufficient buffer space, invalid code pages, +=and invalid flags. + diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test4/CMakeLists.txt b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test4/CMakeLists.txt new file mode 100644 index 0000000000..3d167dff7c --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test4/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8.12.2) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(SOURCES + test4.c +) + +add_executable(paltest_multibytetowidechar_test4 + ${SOURCES} +) + +add_dependencies(paltest_multibytetowidechar_test4 coreclrpal) + +target_link_libraries(paltest_multibytetowidechar_test4 + pthread + m + coreclrpal +)
\ No newline at end of file diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test4/test4.c b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test4/test4.c new file mode 100644 index 0000000000..2ba606cf35 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test4/test4.c @@ -0,0 +1,230 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +/*============================================================================ +** +** Source: test4.c +** +** Purpose: Tests MultiByteToWideChar with a UTF-8 encoding +** +** +**==========================================================================*/ + +#include <palsuite.h> + +int __cdecl main(int argc, char *argv[]) +{ + int ret; + int ret2; + + if (PAL_Initialize(argc, argv)) + { + return FAIL; + } + + const char * const utf8Strings[] = + { + // Correct strings + + // Empty string + "", + // 1 byte encoded 1 character long string + "A", + // 2 byte encoded 1 character long string + "\xC2\x80", + // 3 byte encoded 1 character long string + "\xE0\xA0\x80", + // 1 byte encoded characters only + "ABCDEFGHIJKLMNOPQRSTUVWXYZ", + // valid 2 byte encoded characters only + "\xC2\x80\xC3\xBF\xC7\x81\xDF\xBF", + // valid 3 byte encoded characters only + "\xE0\xA0\x80\xE1\xB6\x88\xE1\x80\x80\xEF\xBF\xBF", + // 1 byte and 2 byte encoded characters interleaved 1:1 starting and ending with 1 byte char + "\x41\xC2\x80\x42\xC3\xBF\x43\xC7\x81\x44\xDF\xBF\x45", + // 1 byte and 2 byte encoded characters interleaved 1:1 starting with 1 byte char, ending with 2 byte one + "\x41\xC2\x80\x42\xC3\xBF\x43\xC7\x81\x44\xDF\xBF", + // 1 byte and 2 byte encoded characters interleaved 1:1 starting with 2 byte char, ending with 1 byte one + "\xC2\x80\x42\xC3\xBF\x43\xC7\x81\x44\xDF\xBF\x45", + // 1 byte and 2 byte encoded characters interleaved 1:1 starting and ending with 2 byte char + "\xC2\x80\x42\xC3\xBF\x43\xC7\x81\x44\xDF\xBF", + // 1 byte and 2 byte encoded characters interleaved 2:2 starting and ending with 1 byte char + "\x41\x42\xC2\x80\xC3\xBF\x43\x44\xC7\x81\xDF\xBF\x45\x46", + // 1 byte and 2 byte encoded characters interleaved 2:2 starting with 1 byte char, ending with 2 byte one + "\x41\x42\xC2\x80\xC3\xBF\x43\x44\xC7\x81\xDF\xBF", + // 1 byte and 2 byte encoded characters interleaved 2:2 starting with 2 byte char, ending with 1 byte one + "\xC2\x80\xC3\xBF\x43\x44\xC7\x81\xDF\xBF\x45\x46", + // 1 byte and 2 byte encoded characters interleaved 2:2 starting and ending with 2 byte char + "\xC2\x80\xC3\xBF\x43\x44\xC7\x81\xDF\xBF", + // surrogates + "\xF0\x90\x80\x80\xF0\x90\x89\x80\xF3\x80\x8E\xB0\xF4\x8F\xBF\xBF", + + // Strings with errors + // Incomplete 2 byte encoded character 1 byte missing standalone + "\xC2", + // Incomplete 3 byte encoded character 1 byte missing standalone + "\xE0\xA0", + // Incomplete 3 byte encoded character 2 bytes missing standalone + "\xE0", + // Incomplete surrogate character 1 byte missing standalone + "\xF0\x90\x80", + // Incomplete surrogate character 2 bytes missing standalone + "\xF0\x90", + // Incomplete surrogate character 3 bytes missing standalone + "\xF0", + // Trailing byte with no lead byte standalone + "\x80", + // Incomplete 2 byte encoded character 1 byte missing between 1 byte chars + "\x41\xC2\x42", + // Incomplete 3 byte encoded character 1 byte missing between 1 byte chars + "\x41\xE0\xA0\x42", + // Incomplete 3 byte encoded character 2 bytes missing between 1 byte chars + "\x41\xE0\x42", + // Trailing byte with no lead byte between 1 byte chars + "\x41\x80\x42", + // Incomplete 2 byte encoded character 1 byte missing before 1 byte char + "\xC2\x42", + // Incomplete 3 byte encoded character 1 byte missing before 1 byte char + "\xE0\xA0\x42", + // Incomplete 3 byte encoded character 2 bytes missing before 1 byte char + "\xE0\x42", + // Trailing byte with no lead byte before 1 byte char + "\x80\x42", + // Incomplete 2 byte encoded character 1 byte missing after 1 byte char + "\x41\xC2", + // Incomplete 3 byte encoded character 1 byte missing after 1 byte char + "\x41\xE0\xA0", + // Incomplete 3 byte encoded character 2 bytes missing after 1 byte char + "\x41\xE0", + // Trailing byte with no lead byte after 1 byte char + "\x41\x80", + // Incomplete 2 byte encoded character 1 byte missing between 2 byte chars + "\xC2\x80\xC2\xC3\xBF", + // Incomplete 3 byte encoded character 1 byte missing between 2 byte chars + "\xC2\x80\xE0\xA0\xC3\xBF", + // Incomplete 3 byte encoded character 2 bytes missing between 2 byte chars + "\xC2\x80\xE0\xC3\xBF", + // Trailing byte with no lead byte between 2 byte chars + "\xC2\x80\x80\xC3\xBF", + // 2 byte encoded character in non-shortest form encodings (these are not allowed) + "\xC0\x80", + // 3 byte encoded character in non-shortest form encodings (these are not allowed) + "\xE0\x80\x80", + // 4 byte encoded character in non-shortest form encodings (these are not allowed) + "\xF0\x80\x80\x80", + }; + + const WCHAR * const unicodeStrings[] = + { + // Empty string + W(""), + // 1 byte encoded 1 character long string + W("A"), + // 2 byte encoded 1 character long string + W("\x0080"), + // 3 byte encoded 1 character long string + W("\x0800"), + // 1 byte encoded characters only + W("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), + // 2 byte encoded characters only + W("\x0080\x00FF\x01C1\x07FF"), + // valid 3 byte encoded characters only + W("\x0800\x1D88\x1000\xFFFF"), + // 1 byte and 2 byte encoded characters interleaved 1:1 starting and ending with 1 byte char + W("\x0041\x0080\x0042\x00FF\x0043\x01C1\x0044\x07FF\x0045"), + // 1 byte and 2 byte encoded characters interleaved 1:1 starting with 1 byte char, ending with 2 byte one + W("\x0041\x0080\x0042\x00FF\x0043\x01C1\x0044\x07FF"), + // 1 byte and 2 byte encoded characters interleaved 1:1 starting with 2 byte char, ending with 1 byte one + W("\x0080\x0042\x00FF\x0043\x01C1\x0044\x07FF\x0045"), + // 1 byte and 2 byte encoded characters interleaved 1:1 starting and ending with 2 byte char + W("\x0080\x0042\x00FF\x0043\x01C1\x0044\x07FF"), + // 1 byte and 2 byte encoded characters interleaved 2:2 starting and ending with 1 byte char + W("\x0041\x0042\x0080\x00FF\x0043\x0044\x01C1\x07FF\x0045\x0046"), + // 1 byte and 2 byte encoded characters interleaved 2:2 starting with 1 byte char, ending with 2 byte one + W("\x0041\x0042\x0080\x00FF\x0043\x0044\x01C1\x07FF"), + // 1 byte and 2 byte encoded characters interleaved 2:2 starting with 2 byte char, ending with 1 byte one + W("\x0080\x00FF\x0043\x0044\x01C1\x07FF\x0045\x0046"), + // 1 byte and 2 byte encoded characters interleaved 2:2 starting and ending with 2 byte char + W("\x0080\x00FF\x0043\x0044\x01C1\x07FF"), + // surrogates + W("\xD800\xDC00\xD800\xDE40\xDAC0\xDFB0\xDBFF\xDFFF"), + + // Strings with errors + // Incomplete 2 byte encoded character standalone + W(""), + // Incomplete 3 byte encoded character 1 byte missing standalone + W(""), + // Incomplete 3 byte encoded character 2 bytes missing standalone + W(""), + // Incomplete surrogate character 1 byte missing standalone + W(""), + // Incomplete surrogate character 2 bytes missing standalone + W(""), + // Incomplete surrogate character 3 bytes missing standalone + W(""), + // Trailing byte with no lead byte standalone + W(""), + // Incomplete 2 byte encoded character 1 byte missing between 1 byte chars + W("\x0041\x0042"), + // Incomplete 3 byte encoded character 1 byte missing between 1 byte chars + W("\x0041\x0042"), + // Incomplete 3 byte encoded character 2 bytes missing between 1 byte chars + W("\x0041\x0042"), + // Trailing byte with no lead byte between 1 byte chars + W("\x0041\x0042"), + // Incomplete 2 byte encoded character 1 byte missing before 1 byte char + W("\x0042"), + // Incomplete 3 byte encoded character 1 byte missing before 1 byte char + W("\x0042"), + // Incomplete 3 byte encoded character 2 bytes missing before 1 byte char + W("\x0042"), + // Trailing byte with no lead byte before 1 byte char + W("\x0042"), + // Incomplete 2 byte encoded character 1 byte missing after 1 byte char + W("\x0041"), + // Incomplete 3 byte encoded character 1 byte missing after 1 byte char + W("\x0041"), + // Incomplete 3 byte encoded character 2 bytes missing after 1 byte char + W("\x0041"), + // Trailing byte with no lead byte after 1 byte char + W("\x0041"), + // Incomplete 2 byte encoded character 1 byte missing between 2 byte chars + W("\x0080\x00FF"), + // Incomplete 3 byte encoded character 1 byte missing between 2 byte chars + W("\x0080\x00FF"), + // Incomplete 3 byte encoded character 2 bytes missing between 2 byte chars + W("\x0080\x00FF"), + // Trailing byte with no lead byte between 2 byte chars + W("\x0080\x00FF"), + // 2 byte encoded character in non-shortest form encodings (these are not allowed) + W(""), + // 3 byte encoded character in non-shortest form encodings (these are not allowed) + W(""), + // 4 byte encoded character in non-shortest form encodings (these are not allowed) + W(""), + }; + + for (int i = 0; i < (sizeof(utf8Strings) / sizeof(utf8Strings[0])); i++) + { + ret = MultiByteToWideChar(CP_UTF8, 0, utf8Strings[i], -1, NULL, 0); + WCHAR* wideBuffer = malloc(ret * sizeof(WCHAR)); + ret2 = MultiByteToWideChar(CP_UTF8, 0, utf8Strings[i], -1, wideBuffer, ret); + if (ret != ret2) + { + Fail("MultiByteToWideChar string %d: returned different string length for empty and real dest buffers!\n" + "Got %d for the empty one, %d for real one.\n", i, ret2, ret); + } + + if (wcscmp(wideBuffer, unicodeStrings[i]) != 0) + { + Fail("MultiByteToWideChar string %d: the resulting string doesn't match the expected one!\n", i); + } + + free(wideBuffer); + } + + PAL_Terminate(); + + return PASS; +}
\ No newline at end of file diff --git a/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test4/testinfo.dat b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test4/testinfo.dat new file mode 100644 index 0000000000..e95f413904 --- /dev/null +++ b/src/pal/tests/palsuite/locale_info/MultiByteToWideChar/test4/testinfo.dat @@ -0,0 +1,13 @@ +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# + +Version = 1.0 +Section = Locale Information +Function = MultiByteToWideChar +Name = Test #4 for MultiByteToWideChar +TYPE = DEFAULT +EXE1 = test4 +Description +=Tests MultiByteToWideChar with UTF-8 encoded strings +=containing various corner cases
\ No newline at end of file |