mirror of
https://github.com/reactos/wine.git
synced 2024-12-03 01:12:25 +00:00
kernel32/tests: Add tabular UTF-7 encoding tests.
This commit is contained in:
parent
9598a39bdb
commit
38027cda8f
@ -433,6 +433,114 @@ static void test_utf7_encoding(void)
|
||||
static const char base64_encoding_table[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
const struct
|
||||
{
|
||||
/* inputs */
|
||||
WCHAR src[16];
|
||||
int srclen;
|
||||
char *dst;
|
||||
int dstlen;
|
||||
/* expected outputs */
|
||||
char expected_dst[16];
|
||||
int chars_written;
|
||||
int len;
|
||||
}
|
||||
tests[] =
|
||||
{
|
||||
/* tests string conversion with srclen=-1 */
|
||||
{
|
||||
{0x4F60,0x597D,0x5417,0}, -1, output, sizeof(output) - 1,
|
||||
"+T2BZfVQX-", 11, 11
|
||||
},
|
||||
/* tests string conversion with srclen=-2 */
|
||||
{
|
||||
{0x4F60,0x597D,0x5417,0}, -2, output, sizeof(output) - 1,
|
||||
"+T2BZfVQX-", 11, 11
|
||||
},
|
||||
/* tests string conversion with dstlen=strlen(expected_dst) */
|
||||
{
|
||||
{0x4F60,0x597D,0x5417,0}, -1, output, 10,
|
||||
"+T2BZfVQX-", 10, 0
|
||||
},
|
||||
/* tests string conversion with dstlen=strlen(expected_dst)+1 */
|
||||
{
|
||||
{0x4F60,0x597D,0x5417,0}, -1, output, 11,
|
||||
"+T2BZfVQX-", 11, 11
|
||||
},
|
||||
/* tests string conversion with dstlen=strlen(expected_dst)+2 */
|
||||
{
|
||||
{0x4F60,0x597D,0x5417,0}, -1, output, 12,
|
||||
"+T2BZfVQX-", 11, 11
|
||||
},
|
||||
/* tests dry run with dst=NULL and dstlen=0 */
|
||||
{
|
||||
{0x4F60,0x597D,0x5417,0}, -1, NULL, 0,
|
||||
{}, 0, 11
|
||||
},
|
||||
/* tests dry run with dst!=NULL and dstlen=0 */
|
||||
{
|
||||
{0x4F60,0x597D,0x5417,0}, -1, output, 0,
|
||||
{}, 0, 11
|
||||
},
|
||||
/* tests srclen < strlenW(src) with directly encodable chars */
|
||||
{
|
||||
{'h','e','l','l','o',0}, 2, output, sizeof(output) - 1,
|
||||
"he", 2, 2
|
||||
},
|
||||
/* tests srclen < strlenW(src) with non-directly encodable chars */
|
||||
{
|
||||
{0x4F60,0x597D,0x5417,0}, 2, output, sizeof(output) - 1,
|
||||
"+T2BZfQ-", 8, 8
|
||||
},
|
||||
/* tests a single null char */
|
||||
{
|
||||
{0}, -1, output, sizeof(output) - 1,
|
||||
"", 1, 1
|
||||
},
|
||||
/* tests a buffer that runs out while not encoding a UTF-7 sequence */
|
||||
{
|
||||
{'h','e','l','l','o',0}, -1, output, 2,
|
||||
"he", 2, 0
|
||||
},
|
||||
/* tests a buffer that runs out after writing 1 base64 character */
|
||||
{
|
||||
{0x4F60,0x0001,0}, -1, output, 2,
|
||||
"+T", 2, 0
|
||||
},
|
||||
/* tests a buffer that runs out after writing 2 base64 characters */
|
||||
{
|
||||
{0x4F60,0x0001,0}, -1, output, 3,
|
||||
"+T2", 3, 0
|
||||
},
|
||||
/* tests a buffer that runs out after writing 3 base64 characters */
|
||||
{
|
||||
{0x4F60,0x0001,0}, -1, output, 4,
|
||||
"+T2A", 4, 0
|
||||
},
|
||||
/* tests a buffer that runs out just after writing the + sign */
|
||||
{
|
||||
{0x4F60,0}, -1, output, 1,
|
||||
"+", 1, 0
|
||||
},
|
||||
/* tests a buffer that runs out just before writing the - sign
|
||||
* the number of bits to encode here is evenly divisible by 6 */
|
||||
{
|
||||
{0x4F60,0x597D,0x5417,0}, -1, output, 9,
|
||||
"+T2BZfVQX", 9, 0
|
||||
},
|
||||
/* tests a buffer that runs out just before writing the - sign
|
||||
* the number of bits to encode here is NOT evenly divisible by 6 */
|
||||
{
|
||||
{0x4F60,0}, -1, output, 4,
|
||||
"+T2", 3, 0
|
||||
},
|
||||
/* tests a buffer that runs out in the middle of escaping a + sign */
|
||||
{
|
||||
{'+',0}, -1, output, 1,
|
||||
"+", 1, 0
|
||||
}
|
||||
};
|
||||
|
||||
if (WideCharToMultiByte(CP_UTF7, 0, foobarW, -1, NULL, 0, NULL, NULL) == 0 &&
|
||||
GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
||||
{
|
||||
@ -525,6 +633,34 @@ static void test_utf7_encoding(void)
|
||||
ok(output[expected_len] == '#', "i=0x%04x: expected output[%i]='#', got output[%i]=%i\n",
|
||||
i, expected_len, expected_len, output[expected_len]);
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++)
|
||||
{
|
||||
memset(output, '#', sizeof(output) - 1);
|
||||
output[sizeof(output) - 1] = 0;
|
||||
SetLastError(0xdeadbeef);
|
||||
|
||||
len = WideCharToMultiByte(CP_UTF7, 0, tests[i].src, tests[i].srclen,
|
||||
tests[i].dst, tests[i].dstlen, NULL, NULL);
|
||||
|
||||
if (!tests[i].len)
|
||||
{
|
||||
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
|
||||
"tests[%i]: expected error=0x%x, got error=0x%x\n",
|
||||
i, ERROR_INSUFFICIENT_BUFFER, GetLastError());
|
||||
}
|
||||
ok(len == tests[i].len, "tests[%i]: expected len=%i, got len=%i\n", i, tests[i].len, len);
|
||||
|
||||
if (tests[i].dst)
|
||||
{
|
||||
ok(memcmp(tests[i].dst, tests[i].expected_dst, tests[i].chars_written) == 0,
|
||||
"tests[%i]: expected dst='%s', got dst='%s'\n",
|
||||
i, tests[i].expected_dst, tests[i].dst);
|
||||
ok(tests[i].dst[tests[i].chars_written] == '#',
|
||||
"tests[%i]: expected dst[%i]='#', got dst[%i]=%i\n",
|
||||
i, tests[i].chars_written, tests[i].chars_written, tests[i].dst[tests[i].chars_written]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void test_utf7_decoding(void)
|
||||
|
Loading…
Reference in New Issue
Block a user