[PATCH 3/3] kernel32/tests: Add tests for UTF-7 conversion.
Alex Henrie
alexhenrie24 at gmail.com
Sat Sep 1 14:15:15 CDT 2012
---
dlls/kernel32/tests/codepage.c | 135 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 135 insertions(+)
diff --git a/dlls/kernel32/tests/codepage.c b/dlls/kernel32/tests/codepage.c
index c980348..1196872 100644
--- a/dlls/kernel32/tests/codepage.c
+++ b/dlls/kernel32/tests/codepage.c
@@ -412,6 +412,139 @@ static void test_string_conversion(LPBOOL bUsedDefaultChar)
ok(GetLastError() == 0xdeadbeef, "GetLastError() is %u\n", GetLastError());
}
+static void test_utf7_string_conversion(void)
+{
+ /* tests which ASCII characters are base64-encoded and which are not */
+ WCHAR example_0_utf16[] = {'\t',' ','!','"','#','$','%','&','\'','(',')','*','+',',','-','.',
+ '/','0','1','2','3','4','5','6','7','8','9',':',';','<','=','>','?',
+ '@','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
+ 'Q','R','S','T','U','V','W','X','Y','Z','[','\\',']','^','_','`','a',
+ 'b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r',
+ 's','t','u','v','w','x','y','z','{','|','}','~',0};
+ int example_0_utf16_len = sizeof(example_0_utf16) / sizeof(WCHAR);
+ char example_0_utf7[] = "\t +ACEAIgAjACQAJQAm-'()+ACo-+-,-./0123456789:+ADsAPAA9AD4-?+AEA-ABCDEFGHIJKLMNOPQRSTUVWXYZ+AFsAXABdAF4AXwBg-abcdefghijklmnopqrstuvwxyz+AHsAfAB9AH4-";
+ int example_0_utf7_len = sizeof(example_0_utf7);
+
+ /* this string is the Unicode for "5 + (<ALPHA>+<BETA>+x) <NOT EQUAL TO> <ALPHA><BETA>"
+ it tests:
+ - a + before a non-base64 character
+ - a + between two non-directly-encodable characters
+ - a + before a base64 character */
+ WCHAR example_1_utf16[] = {'5',' ','+',' ','(',0x0391,'+',0x0392,'+','x',')',' ',0x2260,' ',0x0391,0x0392,0};
+ int example_1_utf16_len = sizeof(example_1_utf16) / sizeof(WCHAR);
+ char example_1_utf7[] = "5 +- (+A5E-+-+A5I-+-x) +ImA- +A5EDkg-";
+ int example_1_utf7_len = sizeof(example_1_utf7);
+
+ /* tests a null char before the end of the buffer */
+ WCHAR example_2_utf16[] = {'a',0,'b',0};
+ int example_2_utf16_len = sizeof(example_2_utf16) / sizeof(WCHAR);
+ char example_2_utf7[] = "a\0b";
+ int example_2_utf7_len = sizeof(example_2_utf7);
+
+ /* tests some invalid UTF-7 */
+ /* (number of bits in base64 sequence is not a multiple of 16 and the last bit is a 1) */
+ char example_3_utf7[] = "+T2B-hello";
+ WCHAR example_3_utf16[] = {0x4F60,'h','e','l','l','o',0};
+ int example_3_utf16_len = sizeof(example_3_utf16) / sizeof(WCHAR);
+
+ /* tests some more invalid UTF-7 */
+ /* (number of bits in base64 sequence is a multiple of 8 but not a multiple of 16) */
+ char example_4_utf7[] = "+T2BZ-hello";
+ WCHAR example_4_utf16[] = {0x4F60,'h','e','l','l','o',0};
+ int example_4_utf16_len = sizeof(example_3_utf16) / sizeof(WCHAR);
+
+ /* tests a buffer that is too small */
+ WCHAR example_5_utf16[] = {'h','e','l','l','o',0};
+ char example_5_utf7[] = "he";
+
+ /* tests another buffer that is too small */
+ char example_6_utf7[] = "hello";
+ WCHAR example_6_utf16[] = {'h','e',0};
+
+ /* tests a buffer that runs out in the middle of encoding a UTF-7 sequence */
+ WCHAR example_7_utf16[] = {0x4F60,0x597D,0};
+ char example_7_utf7[] = "+T";
+
+ /* tests a buffer that runs out in the middle of decoding a UTF-7 sequence */
+ char example_8_utf7[] = "+T2BZfQ-";
+ WCHAR example_8_utf16[] = {0x4F60, 0};
+
+ char c_buffer[256] = {0};
+ WCHAR w_buffer[256] = {0};
+ int len;
+
+
+ len = WideCharToMultiByte(CP_UTF7, 0, example_0_utf16, -1, c_buffer, 256, NULL, NULL);
+ ok(len == example_0_utf7_len && strcmp(c_buffer, example_0_utf7) == 0, "len=%i dst=\"%s\"\n", len, c_buffer);
+
+ len = MultiByteToWideChar(CP_UTF7, 0, example_0_utf7, -1, w_buffer, 256);
+ ok(len == example_0_utf16_len && winetest_strcmpW(w_buffer, example_0_utf16) == 0, "len=%i dst=%s\n", len, wine_dbgstr_w(w_buffer));
+
+ /* 4 more tests to just compute the required length */
+ len = WideCharToMultiByte(CP_UTF7, 0, example_0_utf16, -1, NULL, 0, NULL, NULL);
+ ok(len == example_0_utf7_len, "len=%i\n", len);
+
+ len = WideCharToMultiByte(CP_UTF7, 0, example_0_utf16, -1, c_buffer, 0, NULL, NULL);
+ ok(len == example_0_utf7_len, "len=%i\n", len);
+
+ len = MultiByteToWideChar(CP_UTF7, 0, example_0_utf7, -1, NULL, 0);
+ ok(len == example_0_utf16_len, "len=%i\n", len);
+
+ len = MultiByteToWideChar(CP_UTF7, 0, example_0_utf7, -1, w_buffer, 0);
+ ok(len == example_0_utf16_len, "len=%i\n", len);
+
+ /* 2 more tests to check what happens if srclen < -1 */
+ memset(c_buffer, 0, sizeof(c_buffer));
+ len = WideCharToMultiByte(CP_UTF7, 0, example_0_utf16, -2, c_buffer, 256, NULL, NULL);
+ ok(len == example_0_utf7_len && strcmp(c_buffer, example_0_utf7) == 0, "len=%i dst=\"%s\"\n", len, c_buffer);
+
+ memset(w_buffer, 0, sizeof(w_buffer));
+ len = MultiByteToWideChar(CP_UTF7, 0, example_0_utf7, -2, w_buffer, 256);
+ ok(len == example_0_utf16_len && winetest_strcmpW(w_buffer, example_0_utf16) == 0, "len=%i dst=%s\n", len, wine_dbgstr_w(w_buffer));
+
+
+ len = WideCharToMultiByte(CP_UTF7, 0, example_1_utf16, -1, c_buffer, 256, NULL, NULL);
+ ok(len == example_1_utf7_len && strcmp(c_buffer, example_1_utf7) == 0, "len=%i dst=\"%s\"\n", len, c_buffer);
+
+ len = MultiByteToWideChar(CP_UTF7, 0, example_1_utf7, -1, w_buffer, 256);
+ ok(len == example_1_utf16_len && winetest_strcmpW(w_buffer, example_1_utf16) == 0, "len=%i dst=%s\n", len, wine_dbgstr_w(w_buffer));
+
+
+ len = WideCharToMultiByte(CP_UTF7, 0, example_2_utf16, example_2_utf16_len, c_buffer, 256, NULL, NULL);
+ ok(len == example_2_utf7_len && c_buffer[0] == 'a' && c_buffer[1] == 0 && c_buffer[2] == 'b' && c_buffer[3] == 0, "len=%i dst=\"%s\"\n", len, c_buffer);
+
+ len = MultiByteToWideChar(CP_UTF7, 0, example_2_utf7, example_2_utf7_len, w_buffer, 256);
+ ok(len == example_2_utf16_len && w_buffer[0] == 'a' && w_buffer[1] == 0 && w_buffer[2] == 'b' && w_buffer[3] == 0, "len=%i dst=%s\n", len, wine_dbgstr_w(w_buffer));
+
+
+ len = MultiByteToWideChar(CP_UTF7, 0, example_3_utf7, -1, w_buffer, 256);
+ ok(len == example_3_utf16_len && winetest_strcmpW(w_buffer, example_3_utf16) == 0, "len=%i dst=%s\n", len, wine_dbgstr_w(w_buffer));
+
+
+ len = MultiByteToWideChar(CP_UTF7, 0, example_4_utf7, -1, w_buffer, 256);
+ ok(len == example_4_utf16_len && winetest_strcmpW(w_buffer, example_4_utf16) == 0, "len=%i dst=%s\n", len, wine_dbgstr_w(w_buffer));
+
+
+ memset(c_buffer, 0, sizeof(c_buffer));
+ len = WideCharToMultiByte(CP_UTF7, 0, example_5_utf16, -1, c_buffer, 2, NULL, NULL);
+ ok(len == 0 && strcmp(c_buffer, example_5_utf7) == 0, "len=%i dst=\"%s\"\n", len, c_buffer);
+
+
+ memset(w_buffer, 0, sizeof(w_buffer));
+ len = MultiByteToWideChar(CP_UTF7, 0, example_6_utf7, -1, w_buffer, 2);
+ ok(len == 0 && winetest_strcmpW(w_buffer, example_6_utf16) == 0, "len=%i dst=%s\n", len, wine_dbgstr_w(w_buffer));
+
+
+ memset(c_buffer, 0, sizeof(c_buffer));
+ len = WideCharToMultiByte(CP_UTF7, 0, example_7_utf16, -1, c_buffer, 2, NULL, NULL);
+ ok(len == 0 && strcmp(c_buffer, example_7_utf7) == 0, "len=%i dst=\"%s\"\n", len, c_buffer);
+
+
+ memset(w_buffer, 0, sizeof(w_buffer));
+ len = MultiByteToWideChar(CP_UTF7, 0, example_8_utf7, -1, w_buffer, 1);
+ ok(len == 0 && winetest_strcmpW(w_buffer, example_8_utf16) == 0, "len=%i dst=%s\n", len, wine_dbgstr_w(w_buffer));
+}
+
static void test_undefined_byte_char(void)
{
static const struct tag_testset {
@@ -477,5 +610,7 @@ START_TEST(codepage)
test_string_conversion(NULL);
test_string_conversion(&bUsedDefaultChar);
+ test_utf7_string_conversion();
+
test_undefined_byte_char();
}
--
1.7.10.4
More information about the wine-patches
mailing list