reg/tests: Test registry export with a complex data structure.
Signed-off-by: Hugh McMaster <hugh.mcmaster@outlook.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
ae313198a0
commit
7d93b9d099
|
@ -128,6 +128,48 @@ static void add_key_(unsigned line, const HKEY hkey, const char *path, HKEY *sub
|
|||
lok(err == ERROR_SUCCESS, "RegCreateKeyExA failed: %d\n", err);
|
||||
}
|
||||
|
||||
static LONG delete_tree(const HKEY key, const char *subkey)
|
||||
{
|
||||
HKEY hkey;
|
||||
LONG ret;
|
||||
char *subkey_name = NULL;
|
||||
DWORD max_subkey_len, subkey_len;
|
||||
static const char empty[1];
|
||||
|
||||
ret = RegOpenKeyExA(key, subkey, 0, KEY_READ, &hkey);
|
||||
if (ret) return ret;
|
||||
|
||||
ret = RegQueryInfoKeyA(hkey, NULL, NULL, NULL, NULL, &max_subkey_len,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
if (ret) goto cleanup;
|
||||
|
||||
max_subkey_len++;
|
||||
|
||||
subkey_name = HeapAlloc(GetProcessHeap(), 0, max_subkey_len);
|
||||
if (!subkey_name)
|
||||
{
|
||||
ret = ERROR_NOT_ENOUGH_MEMORY;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
subkey_len = max_subkey_len;
|
||||
ret = RegEnumKeyExA(hkey, 0, subkey_name, &subkey_len, NULL, NULL, NULL, NULL);
|
||||
if (ret == ERROR_NO_MORE_ITEMS) break;
|
||||
if (ret) goto cleanup;
|
||||
ret = delete_tree(hkey, subkey_name);
|
||||
if (ret) goto cleanup;
|
||||
}
|
||||
|
||||
ret = RegDeleteKeyA(hkey, empty);
|
||||
|
||||
cleanup:
|
||||
HeapFree(GetProcessHeap(), 0, subkey_name);
|
||||
RegCloseKey(hkey);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define add_value(k,n,t,d,s) add_value_(__LINE__,k,n,t,d,s)
|
||||
static void add_value_(unsigned line, HKEY hkey, const char *name, DWORD type,
|
||||
const void *data, size_t size)
|
||||
|
@ -4256,7 +4298,7 @@ static void test_export(void)
|
|||
{
|
||||
LONG err;
|
||||
DWORD r, os_version, major_version, minor_version, dword;
|
||||
HKEY hkey;
|
||||
HKEY hkey, subkey;
|
||||
|
||||
const char *empty_key_test =
|
||||
"\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
|
||||
|
@ -4268,6 +4310,32 @@ static void test_export(void)
|
|||
"\"DWORD\"=dword:00000100\r\n"
|
||||
"\"String\"=\"Your text here...\"\r\n\r\n";
|
||||
|
||||
const char *complex_test =
|
||||
"\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
|
||||
"[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
|
||||
"\"DWORD\"=dword:00000100\r\n"
|
||||
"\"String\"=\"Your text here...\"\r\n\r\n"
|
||||
"[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1]\r\n"
|
||||
"\"Binary\"=hex:11,22,33,44\r\n"
|
||||
"\"Undefined hex\"=hex(100):25,50,41,54,48,25,00\r\n\r\n"
|
||||
"[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a]\r\n"
|
||||
"\"double\\\"quote\"=\"\\\"Hello, World!\\\"\"\r\n"
|
||||
"\"single'quote\"=dword:00000008\r\n\r\n"
|
||||
"[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a\\Subkey2b]\r\n"
|
||||
"@=\"Default value name\"\r\n"
|
||||
"\"Multiple strings\"=hex(7):4c,00,69,00,6e,00,65,00,31,00,00,00,4c,00,69,00,6e,\\\r\n"
|
||||
" 00,65,00,32,00,00,00,4c,00,69,00,6e,00,65,00,33,00,00,00,00,00\r\n\r\n"
|
||||
"[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey3a]\r\n"
|
||||
"\"Backslash\"=\"Use \\\\\\\\ to escape a backslash\"\r\n\r\n"
|
||||
"[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey3a\\Subkey3b]\r\n\r\n"
|
||||
"[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey3a\\Subkey3b\\Subkey3c]\r\n"
|
||||
"\"String expansion\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00,25,00,50,\\\r\n"
|
||||
" 00,41,00,54,00,48,00,25,00,00,00\r\n"
|
||||
"\"Zero data type\"=hex(0):56,61,6c,75,65,00\r\n\r\n"
|
||||
"[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey4]\r\n"
|
||||
"@=dword:12345678\r\n"
|
||||
"\"43981\"=hex(abcd):56,61,6c,75,65,00\r\n\r\n";
|
||||
|
||||
err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
|
||||
ok(err == ERROR_SUCCESS || err == ERROR_FILE_NOT_FOUND, "got %d\n", err);
|
||||
|
||||
|
@ -4345,10 +4413,49 @@ static void test_export(void)
|
|||
err = DeleteFileA("file.reg");
|
||||
todo_wine ok(err, "DeleteFile failed: %u\n", GetLastError());
|
||||
|
||||
/* Test registry export with a complex data structure */
|
||||
add_key(hkey, "Subkey1", &subkey);
|
||||
add_value(subkey, "Binary", REG_BINARY, "\x11\x22\x33\x44", 4);
|
||||
add_value(subkey, "Undefined hex", 0x100, "%PATH%", 7);
|
||||
RegCloseKey(subkey);
|
||||
|
||||
add_key(hkey, "Subkey2a", &subkey);
|
||||
add_value(subkey, "double\"quote", REG_SZ, "\"Hello, World!\"", 16);
|
||||
dword = 0x8;
|
||||
add_value(subkey, "single'quote", REG_DWORD, &dword, sizeof(dword));
|
||||
RegCloseKey(subkey);
|
||||
|
||||
add_key(hkey, "Subkey2a\\Subkey2b", &subkey);
|
||||
add_value(subkey, NULL, REG_SZ, "Default value name", 19);
|
||||
add_value(subkey, "Multiple strings", REG_MULTI_SZ, "Line1\0Line2\0Line3\0", 19);
|
||||
RegCloseKey(subkey);
|
||||
|
||||
add_key(hkey, "Subkey3a", &subkey);
|
||||
add_value(subkey, "Backslash", REG_SZ, "Use \\\\ to escape a backslash", 29);
|
||||
RegCloseKey(subkey);
|
||||
|
||||
add_key(hkey, "Subkey3a\\Subkey3b\\Subkey3c", &subkey);
|
||||
add_value(subkey, "String expansion", REG_EXPAND_SZ, "%HOME%\\%PATH%", 14);
|
||||
add_value(subkey, "Zero data type", REG_NONE, "Value", 6);
|
||||
RegCloseKey(subkey);
|
||||
|
||||
add_key(hkey, "Subkey4", &subkey);
|
||||
dword = 0x12345678;
|
||||
add_value(subkey, NULL, REG_DWORD, &dword, sizeof(dword));
|
||||
add_value(subkey, "43981", 0xabcd, "Value", 6);
|
||||
RegCloseKey(subkey);
|
||||
|
||||
RegCloseKey(hkey);
|
||||
|
||||
err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
|
||||
ok(err == ERROR_SUCCESS, "RegDeleteKeyA failed: %d\n", err);
|
||||
run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg", &r);
|
||||
todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
|
||||
todo_wine ok(compare_export("file.reg", complex_test), "compare_export() failed\n");
|
||||
|
||||
err = DeleteFileA("file.reg");
|
||||
todo_wine ok(err, "DeleteFile failed: %u\n", GetLastError());
|
||||
|
||||
err = delete_tree(HKEY_CURRENT_USER, KEY_BASE);
|
||||
ok(err == ERROR_SUCCESS, "delete_tree() failed: %d\n", err);
|
||||
}
|
||||
|
||||
START_TEST(reg)
|
||||
|
|
Loading…
Reference in New Issue