Add a lot of new tests for the actual WideCharToMultiByte =

Colin Finck mail at colinfinck.de
Sun Jul 27 21:16:59 CDT 2008


string conversion as well.=0A=
=0A=
---=0A=
 dlls/kernel32/tests/codepage.c |  134 =
++++++++++++++++++++++++++++++++++++++++=0A=
 1 files changed, 134 insertions(+), 0 deletions(-)=0A=
=0A=
diff --git a/dlls/kernel32/tests/codepage.c =
b/dlls/kernel32/tests/codepage.c=0A=
index e8908f7..a20a306 100644=0A=
--- a/dlls/kernel32/tests/codepage.c=0A=
+++ b/dlls/kernel32/tests/codepage.c=0A=
@@ -2,6 +2,7 @@=0A=
  * Unit tests for code page to/from unicode translations=0A=
  *=0A=
  * Copyright (c) 2002 Dmitry Timoshkov=0A=
+ * Copyright (c) 2008 Colin Finck=0A=
  *=0A=
  * This library is free software; you can redistribute it and/or=0A=
  * modify it under the terms of the GNU Lesser General Public=0A=
@@ -203,17 +204,150 @@ static void test_overlapped_buffers(void)=0A=
     char buf[256];=0A=
     int ret;=0A=
 =0A=
+    SetLastError(0xdeadbeef);=0A=
     memcpy((WCHAR *)(buf + 1), strW, sizeof(strW));=0A=
     ret =3D WideCharToMultiByte(CP_ACP, 0, (WCHAR *)(buf + 1), -1, buf, =
sizeof(buf), NULL, NULL);=0A=
     ok(ret =3D=3D sizeof(strA), "unexpected ret %d\n", ret);=0A=
     ok(!memcmp(buf, strA, sizeof(strA)), "conversion failed: %s\n", =
buf);=0A=
+    ok(GetLastError() =3D=3D 0xdeadbeef, "GetLastError() is %u\n", =
GetLastError());=0A=
+}=0A=
+=0A=
+static void test_string_conversion(LPBOOL bUsedDefaultChar)=0A=
+{=0A=
+    char mbc;=0A=
+    char mbs[5];=0A=
+    int ret;=0A=
+    WCHAR wc1 =3D 228;                           /* Western =
Windows-1252 character */=0A=
+    WCHAR wc2 =3D 1088;                          /* Russian =
Windows-1251 character not displayable for Windows-1252 */=0A=
+    WCHAR wcs[5] =3D {'T', 'h', 1088, 'i', 0};   /* String with ASCII =
characters and a Russian character */=0A=
+    WCHAR dbwcs[3] =3D {28953, 25152, 0};        /* String with Chinese =
(codepage 950) characters */=0A=
+=0A=
+    SetLastError(0xdeadbeef);=0A=
+    ret =3D WideCharToMultiByte(1252, 0, &wc1, 1, &mbc, 1, NULL, =
bUsedDefaultChar);=0A=
+    ok(ret =3D=3D 1, "ret is %d\n", ret);=0A=
+    ok(mbc =3D=3D -28, "mbc is %d\n", mbc);=0A=
+    if(bUsedDefaultChar) ok(*bUsedDefaultChar =3D=3D FALSE, =
"bUsedDefaultChar is %d\n", *bUsedDefaultChar);=0A=
+    ok(GetLastError() =3D=3D 0xdeadbeef, "GetLastError() is %u\n", =
GetLastError());=0A=
+=0A=
+    SetLastError(0xdeadbeef);=0A=
+    ret =3D WideCharToMultiByte(1252, 0, &wc2, 1, &mbc, 1, NULL, =
bUsedDefaultChar);=0A=
+    ok(ret =3D=3D 1, "ret is %d\n", ret);=0A=
+    ok(mbc =3D=3D 63, "mbc is %d\n", mbc);=0A=
+    if(bUsedDefaultChar) ok(*bUsedDefaultChar =3D=3D TRUE, =
"bUsedDefaultChar is %d\n", *bUsedDefaultChar);=0A=
+    ok(GetLastError() =3D=3D 0xdeadbeef, "GetLastError() is %u\n", =
GetLastError());=0A=
+=0A=
+    SetLastError(0xdeadbeef);=0A=
+    ret =3D WideCharToMultiByte(1251, 0, &wc2, 1, &mbc, 1, NULL, =
bUsedDefaultChar);=0A=
+    ok(ret =3D=3D 1, "ret is %d\n", ret);=0A=
+    ok(mbc =3D=3D -16, "mbc is %d\n", mbc);=0A=
+    if(bUsedDefaultChar) ok(*bUsedDefaultChar =3D=3D FALSE, =
"bUsedDefaultChar is %d\n", *bUsedDefaultChar);=0A=
+    ok(GetLastError() =3D=3D 0xdeadbeef, "GetLastError() is %u\n", =
GetLastError());=0A=
+=0A=
+    SetLastError(0xdeadbeef);=0A=
+    ret =3D WideCharToMultiByte(1251, 0, &wc1, 1, &mbc, 1, NULL, =
bUsedDefaultChar);=0A=
+    ok(ret =3D=3D 1, "ret is %d\n", ret);=0A=
+    ok(mbc =3D=3D 97, "mbc is %d\n", mbc);=0A=
+    if(bUsedDefaultChar) ok(*bUsedDefaultChar =3D=3D FALSE, =
"bUsedDefaultChar is %d\n", *bUsedDefaultChar);=0A=
+    ok(GetLastError() =3D=3D 0xdeadbeef, "GetLastError() is %u\n", =
GetLastError());=0A=
+=0A=
+    /* This call triggers the last Win32 error */=0A=
+    SetLastError(0xdeadbeef);=0A=
+    ret =3D WideCharToMultiByte(1252, 0, wcs, -1, &mbc, 1, NULL, =
bUsedDefaultChar);=0A=
+    ok(ret =3D=3D 0, "ret is %d\n", ret);=0A=
+    ok(mbc =3D=3D 84, "mbc is %d\n", mbc);=0A=
+    if(bUsedDefaultChar) ok(*bUsedDefaultChar =3D=3D FALSE, =
"bUsedDefaultChar is %d\n", *bUsedDefaultChar);=0A=
+    ok(GetLastError() =3D=3D ERROR_INSUFFICIENT_BUFFER, "GetLastError() =
is %u\n", GetLastError());=0A=
+=0A=
+    SetLastError(0xdeadbeef);=0A=
+    ret =3D WideCharToMultiByte(1252, 0, wcs, -1, mbs, sizeof(mbs), =
NULL, bUsedDefaultChar);=0A=
+    ok(ret =3D=3D 5, "ret is %d\n", ret);=0A=
+    ok(!strcmp(mbs, "Th?i"), "mbs is %s\n", mbs);=0A=
+    if(bUsedDefaultChar) ok(*bUsedDefaultChar =3D=3D TRUE, =
"bUsedDefaultChar is %d\n", *bUsedDefaultChar);=0A=
+    ok(GetLastError() =3D=3D 0xdeadbeef, "GetLastError() is %u\n", =
GetLastError());=0A=
+    mbs[0] =3D 0;=0A=
+=0A=
+    /* WideCharToMultiByte mustn't add any null character automatically.=0A=
+       So in this case, we should get the same string again, even if we =
only copied the first three bytes. */=0A=
+    SetLastError(0xdeadbeef);=0A=
+    ret =3D WideCharToMultiByte(1252, 0, wcs, 3, mbs, sizeof(mbs), =
NULL, bUsedDefaultChar);=0A=
+    ok(ret =3D=3D 3, "ret is %d\n", ret);=0A=
+    ok(!strcmp(mbs, "Th?i"), "mbs is %s\n", mbs);=0A=
+    if(bUsedDefaultChar) ok(*bUsedDefaultChar =3D=3D TRUE, =
"bUsedDefaultChar is %d\n", *bUsedDefaultChar);=0A=
+    ok(GetLastError() =3D=3D 0xdeadbeef, "GetLastError() is %u\n", =
GetLastError());=0A=
+    ZeroMemory(mbs, 5);=0A=
+=0A=
+    /* Now this shouldn't be the case like above as we zeroed the =
complete string buffer. */=0A=
+    SetLastError(0xdeadbeef);=0A=
+    ret =3D WideCharToMultiByte(1252, 0, wcs, 3, mbs, sizeof(mbs), =
NULL, bUsedDefaultChar);=0A=
+    ok(ret =3D=3D 3, "ret is %d\n", ret);=0A=
+    ok(!strcmp(mbs, "Th?"), "mbs is %s\n", mbs);=0A=
+    if(bUsedDefaultChar) ok(*bUsedDefaultChar =3D=3D TRUE, =
"bUsedDefaultChar is %d\n", *bUsedDefaultChar);=0A=
+    ok(GetLastError() =3D=3D 0xdeadbeef, "GetLastError() is %u\n", =
GetLastError());=0A=
+=0A=
+    /* Double-byte tests */=0A=
+    ret =3D WideCharToMultiByte(1252, 0, dbwcs, 5, mbs, sizeof(mbs), =
NULL, bUsedDefaultChar);=0A=
+    ok(ret =3D=3D 5, "ret is %d\n", ret);=0A=
+    ok(!strcmp(mbs, "??"), "mbs is %s\n", mbs);=0A=
+    if(bUsedDefaultChar) ok(*bUsedDefaultChar =3D=3D TRUE, =
"bUsedDefaultChar is %d\n", *bUsedDefaultChar);=0A=
+=0A=
+    SetLastError(0xdeadbeef);=0A=
+    ret =3D WideCharToMultiByte(950, 0, dbwcs, -1, mbs, sizeof(mbs), =
NULL, bUsedDefaultChar);=0A=
+    ok(ret =3D=3D 5, "ret is %d\n", ret);=0A=
+    ok(!strcmp(mbs, "=B5H=A9=D2"), "mbs is %s\n", mbs);=0A=
+    if(bUsedDefaultChar) ok(*bUsedDefaultChar =3D=3D FALSE, =
"bUsedDefaultChar is %d\n", *bUsedDefaultChar);=0A=
+    ok(GetLastError() =3D=3D 0xdeadbeef, "GetLastError() is %u\n", =
GetLastError());=0A=
+=0A=
+    SetLastError(0xdeadbeef);=0A=
+    ret =3D WideCharToMultiByte(950, 0, dbwcs, 1, &mbc, 1, NULL, =
bUsedDefaultChar);=0A=
+    ok(ret =3D=3D 0, "ret is %d\n", ret);=0A=
+    if(bUsedDefaultChar) ok(*bUsedDefaultChar =3D=3D FALSE, =
"bUsedDefaultChar is %d\n", *bUsedDefaultChar);=0A=
+    ok(GetLastError() =3D=3D ERROR_INSUFFICIENT_BUFFER, "GetLastError() =
is %u\n", GetLastError());=0A=
+    ZeroMemory(mbs, 5);=0A=
+=0A=
+    SetLastError(0xdeadbeef);=0A=
+    ret =3D WideCharToMultiByte(950, 0, dbwcs, 1, mbs, sizeof(mbs), =
NULL, bUsedDefaultChar);=0A=
+    ok(ret =3D=3D 2, "ret is %d\n", ret);=0A=
+    ok(!strcmp(mbs, "=B5H"), "mbs is %s\n", mbs);=0A=
+    if(bUsedDefaultChar) ok(*bUsedDefaultChar =3D=3D FALSE, =
"bUsedDefaultChar is %d\n", *bUsedDefaultChar);=0A=
+    ok(GetLastError() =3D=3D 0xdeadbeef, "GetLastError() is %u\n", =
GetLastError());=0A=
+=0A=
+    /* Length-only tests */=0A=
+    SetLastError(0xdeadbeef);=0A=
+    ret =3D WideCharToMultiByte(1252, 0, &wc2, 1, NULL, 0, NULL, =
bUsedDefaultChar);=0A=
+    ok(ret =3D=3D 1, "ret is %d\n", ret);=0A=
+    if(bUsedDefaultChar) ok(*bUsedDefaultChar =3D=3D TRUE, =
"bUsedDefaultChar is %d\n", *bUsedDefaultChar);=0A=
+    ok(GetLastError() =3D=3D 0xdeadbeef, "GetLastError() is %u\n", =
GetLastError());=0A=
+=0A=
+    SetLastError(0xdeadbeef);=0A=
+    ret =3D WideCharToMultiByte(1252, 0, wcs, -1, NULL, 0, NULL, =
bUsedDefaultChar);=0A=
+    ok(ret =3D=3D 5, "ret is %d\n", ret);=0A=
+    if(bUsedDefaultChar) ok(*bUsedDefaultChar =3D=3D TRUE, =
"bUsedDefaultChar is %d\n", *bUsedDefaultChar);=0A=
+    ok(GetLastError() =3D=3D 0xdeadbeef, "GetLastError() is %u\n", =
GetLastError());=0A=
+=0A=
+    SetLastError(0xdeadbeef);=0A=
+    ret =3D WideCharToMultiByte(950, 0, dbwcs, 1, NULL, 0, NULL, =
bUsedDefaultChar);=0A=
+    ok(ret =3D=3D 2, "ret is %d\n", ret);=0A=
+    if(bUsedDefaultChar) ok(*bUsedDefaultChar =3D=3D FALSE, =
"bUsedDefaultChar is %d\n", *bUsedDefaultChar);=0A=
+    ok(GetLastError() =3D=3D 0xdeadbeef, "GetLastError() is %u\n", =
GetLastError());=0A=
+=0A=
+    SetLastError(0xdeadbeef);=0A=
+    ret =3D WideCharToMultiByte(950, 0, dbwcs, -1, NULL, 0, NULL, =
bUsedDefaultChar);=0A=
+    ok(ret =3D=3D 5, "ret is %d\n", ret);=0A=
+    if(bUsedDefaultChar) ok(*bUsedDefaultChar =3D=3D FALSE, =
"bUsedDefaultChar is %d\n", *bUsedDefaultChar);=0A=
+    ok(GetLastError() =3D=3D 0xdeadbeef, "GetLastError() is %u\n", =
GetLastError());=0A=
 }=0A=
 =0A=
 START_TEST(codepage)=0A=
 {=0A=
+    BOOL bUsedDefaultChar;=0A=
+=0A=
     test_destination_buffer();=0A=
     test_null_source();=0A=
     test_negative_source_length();=0A=
     test_negative_dest_length();=0A=
     test_overlapped_buffers();=0A=
+=0A=
+    /* WideCharToMultiByte has two code pathes, test both here */=0A=
+    test_string_conversion(NULL);=0A=
+    test_string_conversion(&bUsedDefaultChar);=0A=
 }=0A=
-- =0A=
1.5.6.1.1071.g76fb=0A=
=0A=

------=_NextPart_000_003A_01C8F30A.D653AE50--




More information about the wine-patches mailing list