From 79d7cd76f9bcfb8885d0dd4a3760afa767380ffa Mon Sep 17 00:00:00 2001 From: Akihiro Sagawa Date: Mon, 4 Apr 2011 19:00:58 +0900 Subject: [PATCH] kernel32/tests: Add a test for undefined byte character conversion. --- dlls/kernel32/tests/codepage.c | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/dlls/kernel32/tests/codepage.c b/dlls/kernel32/tests/codepage.c index 402e4bfdd35..96dd45dc53b 100644 --- a/dlls/kernel32/tests/codepage.c +++ b/dlls/kernel32/tests/codepage.c @@ -354,6 +354,57 @@ static void test_string_conversion(LPBOOL bUsedDefaultChar) ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError()); } +static void test_undefined_byte_char(void) +{ + struct tag_testset { + INT codepage; + LPCSTR str; + BOOL is_error; + } testset[] = { + { 874, "\xdd", TRUE }, + { 932, "\xfe", TRUE }, + { 932, "\x80", FALSE }, + { 936, "\xff", TRUE }, + { 949, "\xff", TRUE }, + { 950, "\xff", TRUE }, + { 1252, "\x90", FALSE }, + { 1253, "\xaa", TRUE }, + { 1255, "\xff", TRUE }, + { 1257, "\xa5", TRUE }, + }; + INT i, ret; + + for (i = 0; i < (sizeof(testset) / sizeof(testset[0])); i++) { + if (! IsValidCodePage(testset[i].codepage)) + { + skip("Codepage %d not available\n", testset[i].codepage); + continue; + } + + SetLastError(0xdeadbeef); + ret = MultiByteToWideChar(testset[i].codepage, MB_ERR_INVALID_CHARS, + testset[i].str, -1, NULL, 0); + if (testset[i].is_error) { + todo_wine + ok(ret == 0 && GetLastError() == ERROR_NO_UNICODE_TRANSLATION, + "ret is %d, GetLastError is %u (cp %d)\n", + ret, GetLastError(), testset[i].codepage); + } + else { + ok(ret == strlen(testset[i].str)+1 && GetLastError() == 0xdeadbeef, + "ret is %d, GetLastError is %u (cp %d)\n", + ret, GetLastError(), testset[i].codepage); + } + + SetLastError(0xdeadbeef); + ret = MultiByteToWideChar(testset[i].codepage, 0, + testset[i].str, -1, NULL, 0); + ok(ret == strlen(testset[i].str)+1 && GetLastError() == 0xdeadbeef, + "ret is %d, GetLastError is %u (cp %d)\n", + ret, GetLastError(), testset[i].codepage); + } +} + START_TEST(codepage) { BOOL bUsedDefaultChar; @@ -367,4 +418,6 @@ START_TEST(codepage) /* WideCharToMultiByte has two code paths, test both here */ test_string_conversion(NULL); test_string_conversion(&bUsedDefaultChar); + + test_undefined_byte_char(); } -- 2.11.4.GIT