Fixed a ConvertToUnicode issue and added a unit test
This commit is contained in:
parent
b05fea134e
commit
e15684cb14
@ -411,6 +411,31 @@ static BOOL test_ConvertToUnicode_wrapper(void)
|
||||
int ii;
|
||||
size_t i;
|
||||
|
||||
/* Test static string buffers of differing sizes */
|
||||
{
|
||||
char name[] = "someteststring";
|
||||
const WCHAR cmp[] = { L's', L'o', L'm', L'e', L't', L'e', L's', L't',
|
||||
L's', L't', L'r', L'i', L'n', L'g', 0 };
|
||||
WCHAR xname[128] = { 0 };
|
||||
LPWSTR aname = NULL;
|
||||
LPWSTR wname = &xname[0];
|
||||
const size_t len = strnlen(name, ARRAYSIZE(name) - 1);
|
||||
ii = ConvertToUnicode(CP_UTF8, 0, name, len, &wname, ARRAYSIZE(xname));
|
||||
if (ii != len)
|
||||
goto fail;
|
||||
|
||||
if (memcmp(wname, cmp, sizeof(cmp)) != 0)
|
||||
goto fail;
|
||||
|
||||
ii = ConvertToUnicode(CP_UTF8, 0, name, len, &aname, 0);
|
||||
if (ii != len)
|
||||
goto fail;
|
||||
ii = memcmp(aname, cmp, sizeof(cmp));
|
||||
free(aname);
|
||||
if (ii != 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Test unterminated unicode string:
|
||||
* ConvertToUnicode must always null-terminate, even if the src string isn't
|
||||
*/
|
||||
|
@ -429,9 +429,8 @@ int ConvertToUnicode(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, int cb
|
||||
{
|
||||
free(*lpWideCharStr);
|
||||
*lpWideCharStr = NULL;
|
||||
status = 0;
|
||||
}
|
||||
|
||||
status = 0;
|
||||
}
|
||||
|
||||
return status;
|
||||
|
Loading…
x
Reference in New Issue
Block a user