reg/tests: Add some tests for 'reg import'.

Signed-off-by: Hugh McMaster <hugh.mcmaster@outlook.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hugh McMaster 2016-07-25 07:54:21 +00:00 committed by Alexandre Julliard
parent cf69c12c54
commit 78fecb0397
1 changed files with 61 additions and 1 deletions

View File

@ -16,6 +16,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <stdio.h>
#include <windows.h>
#include "wine/test.h"
@ -675,9 +676,37 @@ static void test_v_flags(void)
ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
}
static BOOL write_reg_file(const char *value, char *tmp_name)
{
static const char regedit4[] = "REGEDIT4";
static const char key[] = "[HKEY_CURRENT_USER\\" KEY_BASE "]";
char file_data[MAX_PATH], tmp_path[MAX_PATH];
HANDLE hfile;
DWORD written;
BOOL ret;
sprintf(file_data, "%s\n\n%s\n%s\n", regedit4, key, value);
GetTempPathA(MAX_PATH, tmp_path);
GetTempFileNameA(tmp_path, "reg", 0, tmp_name);
hfile = CreateFileA(tmp_name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if (hfile == INVALID_HANDLE_VALUE)
return FALSE;
ret = WriteFile(hfile, file_data, strlen(file_data), &written, NULL);
CloseHandle(hfile);
return ret;
}
static void test_import(void)
{
DWORD r;
DWORD r, dword = 0x123;
char test1_reg[MAX_PATH], test2_reg[MAX_PATH];
char cmdline[MAX_PATH];
char test_string[] = "Test string";
HKEY hkey;
LONG err;
run_reg_exe("reg import", &r);
ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
@ -687,6 +716,37 @@ static void test_import(void)
run_reg_exe("reg import missing.reg", &r);
ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
/* Create test files */
ok(write_reg_file("\"Wine\"=dword:00000123", test1_reg), "Failed to write registry file\n");
ok(write_reg_file("@=\"Test string\"", test2_reg), "Failed to write registry file\n");
sprintf(cmdline, "reg import %s", test1_reg);
run_reg_exe(cmdline, &r);
todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
sprintf(cmdline, "reg import %s", test2_reg);
run_reg_exe(cmdline, &r);
todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
err = RegOpenKeyExA(HKEY_CURRENT_USER, KEY_BASE, 0, KEY_READ, &hkey);
todo_wine ok(err == ERROR_SUCCESS, "got %d, expected 0\n", err);
todo_wine verify_reg(hkey, "Wine", REG_DWORD, &dword, sizeof(dword), 0);
todo_wine verify_reg(hkey, "", REG_SZ, test_string, sizeof(test_string), 0);
err = RegCloseKey(hkey);
todo_wine ok(err == ERROR_SUCCESS, "got %d, expected 0\n", err);
err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
todo_wine ok(err == ERROR_SUCCESS, "got %d, expected 0\n", err);
sprintf(cmdline, "reg import %s %s", test1_reg, test2_reg);
run_reg_exe(cmdline, &r);
ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
DeleteFileA(test1_reg);
DeleteFileA(test2_reg);
}
START_TEST(reg)