reg/tests: Combine and rename the test_import_*str functions.

Signed-off-by: Hugh McMaster <hugh.mcmaster@outlook.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hugh McMaster 2017-09-18 08:27:40 +00:00 committed by Alexandre Julliard
parent 08a7836ef3
commit bfe5fed0b3
1 changed files with 22 additions and 32 deletions

View File

@ -750,13 +750,31 @@ static BOOL write_file(const void *str, DWORD size)
return ret; return ret;
} }
#define test_import_str(c,r) test_import_str_(__LINE__,c,r) #define test_import_str(c,r) import_reg(__LINE__,c,FALSE,r)
static BOOL test_import_str_(unsigned line, const char *file_contents, DWORD *rc) #define test_import_wstr(c,r) import_reg(__LINE__,c,TRUE,r)
static BOOL import_reg(unsigned line, const char *contents, BOOL unicode, DWORD *rc)
{ {
int lenA;
BOOL ret; BOOL ret;
if (!write_file(file_contents, strlen(file_contents))) lenA = strlen(contents);
return FALSE;
if (unicode)
{
int len = MultiByteToWideChar(CP_UTF8, 0, contents, lenA, NULL, 0);
int size = len * sizeof(WCHAR);
WCHAR *wstr = HeapAlloc(GetProcessHeap(), 0, size);
if (!wstr) return FALSE;
MultiByteToWideChar(CP_UTF8, 0, contents, lenA, wstr, len);
ret = write_file(wstr, size);
HeapFree(GetProcessHeap(), 0, wstr);
}
else
ret = write_file(contents, lenA);
if (!ret) return FALSE;
run_reg_exe("reg import test.reg", rc); run_reg_exe("reg import test.reg", rc);
@ -766,34 +784,6 @@ static BOOL test_import_str_(unsigned line, const char *file_contents, DWORD *rc
return ret; return ret;
} }
#define test_import_wstr(c,r) test_import_wstr_(__LINE__,c,r)
static BOOL test_import_wstr_(unsigned line, const char *file_contents, DWORD *rc)
{
int lenA, len, memsize;
WCHAR *wstr;
BOOL ret = FALSE;
lenA = strlen(file_contents);
len = MultiByteToWideChar(CP_UTF8, 0, file_contents, lenA, NULL, 0);
memsize = len * sizeof(WCHAR);
wstr = HeapAlloc(GetProcessHeap(), 0, memsize);
if (!wstr) return FALSE;
MultiByteToWideChar(CP_UTF8, 0, file_contents, lenA, wstr, len);
if (!write_file(wstr, memsize))
goto exit;
run_reg_exe("reg import test.reg", rc);
ret = DeleteFileA("test.reg");
lok(ret, "DeleteFile failed: %u\n", GetLastError());
exit:
HeapFree(GetProcessHeap(), 0, wstr);
return ret;
}
static void test_import(void) static void test_import(void)
{ {
DWORD r, dword = 0x123, type, size; DWORD r, dword = 0x123, type, size;