Hugh McMaster : reg/tests: Combine and rename the test_import_*str functions.
Alexandre Julliard
julliard at winehq.org
Mon Sep 18 14:43:48 CDT 2017
Module: wine
Branch: master
Commit: bfe5fed0b3e628a859eb53d906a104c28a3ce6a4
URL: http://source.winehq.org/git/wine.git/?a=commit;h=bfe5fed0b3e628a859eb53d906a104c28a3ce6a4
Author: Hugh McMaster <hugh.mcmaster at outlook.com>
Date: Mon Sep 18 08:27:40 2017 +0000
reg/tests: Combine and rename the test_import_*str functions.
Signed-off-by: Hugh McMaster <hugh.mcmaster at outlook.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
programs/reg/tests/reg.c | 50 +++++++++++++++++++-----------------------------
1 file changed, 20 insertions(+), 30 deletions(-)
diff --git a/programs/reg/tests/reg.c b/programs/reg/tests/reg.c
index 1857545..c41d284 100644
--- a/programs/reg/tests/reg.c
+++ b/programs/reg/tests/reg.c
@@ -750,47 +750,37 @@ static BOOL write_file(const void *str, DWORD size)
return ret;
}
-#define test_import_str(c,r) test_import_str_(__LINE__,c,r)
-static BOOL test_import_str_(unsigned line, const char *file_contents, DWORD *rc)
-{
- BOOL ret;
-
- if (!write_file(file_contents, strlen(file_contents)))
- return FALSE;
-
- run_reg_exe("reg import test.reg", rc);
-
- ret = DeleteFileA("test.reg");
- lok(ret, "DeleteFile failed: %u\n", GetLastError());
-
- return ret;
-}
+#define test_import_str(c,r) import_reg(__LINE__,c,FALSE,r)
+#define test_import_wstr(c,r) import_reg(__LINE__,c,TRUE,r)
-#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)
+static BOOL import_reg(unsigned line, const char *contents, BOOL unicode, DWORD *rc)
{
- int lenA, len, memsize;
- WCHAR *wstr;
- BOOL ret = FALSE;
+ int lenA;
+ BOOL ret;
- lenA = strlen(file_contents);
+ lenA = strlen(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 (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 (!write_file(wstr, memsize))
- goto exit;
+ if (!ret) return FALSE;
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;
}
More information about the wine-cvs
mailing list