xref: /reactos/modules/rostests/winetests/reg/add.c (revision 1a6f523e)
1a09c8c41Swinesync /*
2a09c8c41Swinesync  * Copyright 2014 Akihiro Sagawa
3a09c8c41Swinesync  *
4a09c8c41Swinesync  * This library is free software; you can redistribute it and/or
5a09c8c41Swinesync  * modify it under the terms of the GNU Lesser General Public
6a09c8c41Swinesync  * License as published by the Free Software Foundation; either
7a09c8c41Swinesync  * version 2.1 of the License, or (at your option) any later version.
8a09c8c41Swinesync  *
9a09c8c41Swinesync  * This library is distributed in the hope that it will be useful,
10a09c8c41Swinesync  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11a09c8c41Swinesync  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12a09c8c41Swinesync  * Lesser General Public License for more details.
13a09c8c41Swinesync  *
14a09c8c41Swinesync  * You should have received a copy of the GNU Lesser General Public
15a09c8c41Swinesync  * License along with this library; if not, write to the Free Software
16a09c8c41Swinesync  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17a09c8c41Swinesync  */
18a09c8c41Swinesync 
19a09c8c41Swinesync #include "reg_test.h"
20a09c8c41Swinesync 
run_reg_exe_(const char * file,unsigned line,const char * cmd,DWORD * rc)2107907552Swinesync BOOL run_reg_exe_(const char *file, unsigned line, const char *cmd, DWORD *rc)
22a09c8c41Swinesync {
23a09c8c41Swinesync     STARTUPINFOA si = {sizeof(STARTUPINFOA)};
24a09c8c41Swinesync     PROCESS_INFORMATION pi;
25a09c8c41Swinesync     BOOL bret;
26a09c8c41Swinesync     DWORD ret;
27a09c8c41Swinesync     char cmdline[256];
28a09c8c41Swinesync 
29a09c8c41Swinesync     si.dwFlags = STARTF_USESTDHANDLES;
30a09c8c41Swinesync     si.hStdInput  = INVALID_HANDLE_VALUE;
31a09c8c41Swinesync     si.hStdOutput = INVALID_HANDLE_VALUE;
32a09c8c41Swinesync     si.hStdError  = INVALID_HANDLE_VALUE;
33a09c8c41Swinesync 
34a09c8c41Swinesync     strcpy(cmdline, cmd);
35a09c8c41Swinesync     if (!CreateProcessA(NULL, cmdline, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi))
36a09c8c41Swinesync         return FALSE;
37a09c8c41Swinesync 
38a09c8c41Swinesync     ret = WaitForSingleObject(pi.hProcess, 10000);
39a09c8c41Swinesync     if (ret == WAIT_TIMEOUT)
40a09c8c41Swinesync         TerminateProcess(pi.hProcess, 1);
41a09c8c41Swinesync 
42a09c8c41Swinesync     bret = GetExitCodeProcess(pi.hProcess, rc);
43a09c8c41Swinesync     lok(bret, "GetExitCodeProcess failed: %d\n", GetLastError());
44a09c8c41Swinesync 
45a09c8c41Swinesync     CloseHandle(pi.hThread);
46a09c8c41Swinesync     CloseHandle(pi.hProcess);
47a09c8c41Swinesync     return bret;
48a09c8c41Swinesync }
49a09c8c41Swinesync 
verify_reg_(const char * file,unsigned line,HKEY hkey,const char * value,DWORD exp_type,const void * exp_data,DWORD exp_size,DWORD todo)5007907552Swinesync void verify_reg_(const char *file, unsigned line, HKEY hkey, const char *value,
5107907552Swinesync                  DWORD exp_type, const void *exp_data, DWORD exp_size, DWORD todo)
52a09c8c41Swinesync {
53a09c8c41Swinesync     DWORD type, size;
54a09c8c41Swinesync     BYTE data[256];
55a09c8c41Swinesync     LONG err;
56a09c8c41Swinesync 
57a09c8c41Swinesync     size = sizeof(data);
58a09c8c41Swinesync     memset(data, 0xdd, size);
59a09c8c41Swinesync     err = RegQueryValueExA(hkey, value, NULL, &type, data, &size);
6051327111Swinesync     lok(err == ERROR_SUCCESS, "RegQueryValueEx failed: got error %d\n", err);
61a09c8c41Swinesync     if (err != ERROR_SUCCESS)
62a09c8c41Swinesync         return;
63a09c8c41Swinesync 
64a09c8c41Swinesync     todo_wine_if (todo & TODO_REG_TYPE)
6551327111Swinesync         lok(type == exp_type, "got registry type %d, expected %d\n", type, exp_type);
66a09c8c41Swinesync     todo_wine_if (todo & TODO_REG_SIZE)
6751327111Swinesync         lok(size == exp_size, "got data size %d, expected %d\n", size, exp_size);
68a09c8c41Swinesync     if (exp_data)
69a09c8c41Swinesync     {
70a09c8c41Swinesync         todo_wine_if (todo & TODO_REG_DATA)
7151327111Swinesync             lok(memcmp(data, exp_data, size) == 0, "registry data does not match\n");
72a09c8c41Swinesync     }
73a09c8c41Swinesync }
74a09c8c41Swinesync 
verify_reg_nonexist_(const char * file,unsigned line,HKEY hkey,const char * value)7507907552Swinesync void verify_reg_nonexist_(const char *file, unsigned line, HKEY hkey, const char *value)
76a09c8c41Swinesync {
77a09c8c41Swinesync     LONG err;
78a09c8c41Swinesync 
79a09c8c41Swinesync     err = RegQueryValueExA(hkey, value, NULL, NULL, NULL, NULL);
80a09c8c41Swinesync     lok(err == ERROR_FILE_NOT_FOUND, "registry value '%s' shouldn't exist; got %d, expected 2\n",
81a09c8c41Swinesync         (value && *value) ? value : "(Default)", err);
82a09c8c41Swinesync }
83a09c8c41Swinesync 
open_key_(const char * file,unsigned line,HKEY root,const char * path,REGSAM sam,HKEY * hkey)84ea4fae51Swinesync void open_key_(const char *file, unsigned line, HKEY root, const char *path, REGSAM sam, HKEY *hkey)
85a09c8c41Swinesync {
86a09c8c41Swinesync     LONG err;
87a09c8c41Swinesync 
88ea4fae51Swinesync     err = RegOpenKeyExA(root, path, 0, KEY_READ|sam, hkey);
8951327111Swinesync     lok(err == ERROR_SUCCESS, "RegOpenKeyExA failed: got error %d\n", err);
90a09c8c41Swinesync }
91a09c8c41Swinesync 
close_key_(const char * file,unsigned line,HKEY hkey)9207907552Swinesync void close_key_(const char *file, unsigned line, HKEY hkey)
93a09c8c41Swinesync {
94a09c8c41Swinesync     LONG err;
95a09c8c41Swinesync 
96a09c8c41Swinesync     err = RegCloseKey(hkey);
9751327111Swinesync     lok(err == ERROR_SUCCESS, "RegCloseKey failed: got error %d\n", err);
98a09c8c41Swinesync }
99a09c8c41Swinesync 
verify_key_(const char * file,unsigned line,HKEY root,const char * path,REGSAM sam)100cd3b6fe7Swinesync void verify_key_(const char *file, unsigned line, HKEY root, const char *path, REGSAM sam)
101a09c8c41Swinesync {
102a09c8c41Swinesync     HKEY hkey;
103a09c8c41Swinesync     LONG err;
104a09c8c41Swinesync 
105cd3b6fe7Swinesync     err = RegOpenKeyExA(root, path, 0, KEY_READ|sam, &hkey);
10651327111Swinesync     lok(err == ERROR_SUCCESS, "RegOpenKeyExA failed: got error %d\n", err);
107a09c8c41Swinesync 
108a09c8c41Swinesync     if (hkey)
109a09c8c41Swinesync         RegCloseKey(hkey);
110a09c8c41Swinesync }
111a09c8c41Swinesync 
verify_key_nonexist_(const char * file,unsigned line,HKEY root,const char * path,REGSAM sam)112df92c046Swinesync void verify_key_nonexist_(const char *file, unsigned line, HKEY root, const char *path, REGSAM sam)
113a09c8c41Swinesync {
114a09c8c41Swinesync     HKEY hkey;
115a09c8c41Swinesync     LONG err;
116a09c8c41Swinesync 
117df92c046Swinesync     err = RegOpenKeyExA(root, path, 0, KEY_READ|sam, &hkey);
118df92c046Swinesync     lok(err == ERROR_FILE_NOT_FOUND, "registry key '%s' shouldn't exist; got %d, expected 2\n", path, err);
119a09c8c41Swinesync 
120a09c8c41Swinesync     if (hkey)
121a09c8c41Swinesync         RegCloseKey(hkey);
122a09c8c41Swinesync }
123a09c8c41Swinesync 
add_key_(const char * file,unsigned line,const HKEY root,const char * path,REGSAM sam,HKEY * hkey)12477b2d21eSwinesync void add_key_(const char *file, unsigned line, const HKEY root, const char *path, REGSAM sam, HKEY *hkey)
125a09c8c41Swinesync {
126a09c8c41Swinesync     LONG err;
127ba10b11fSwinesync     HKEY new_key;
128a09c8c41Swinesync 
12977b2d21eSwinesync     err = RegCreateKeyExA(root, path, 0, NULL, REG_OPTION_NON_VOLATILE,
13077b2d21eSwinesync                           KEY_READ|KEY_WRITE|sam, NULL, &new_key, NULL);
13151327111Swinesync     lok(err == ERROR_SUCCESS, "RegCreateKeyExA failed: got error %d\n", err);
132ba10b11fSwinesync 
13377b2d21eSwinesync     if (hkey)
13477b2d21eSwinesync         *hkey = new_key;
135ba10b11fSwinesync     else
136ba10b11fSwinesync         RegCloseKey(new_key);
137a09c8c41Swinesync }
138a09c8c41Swinesync 
delete_key_(const char * file,unsigned line,HKEY root,const char * path,REGSAM sam)1390ea0084cSwinesync void delete_key_(const char *file, unsigned line, HKEY root, const char *path, REGSAM sam)
140a09c8c41Swinesync {
141a09c8c41Swinesync     LONG err;
142a09c8c41Swinesync 
1430ea0084cSwinesync     if (!path) return;
1440ea0084cSwinesync 
1450ea0084cSwinesync     if (!sam)
1460ea0084cSwinesync     {
1470ea0084cSwinesync         err = RegDeleteKeyA(root, path);
14851327111Swinesync         lok(err == ERROR_SUCCESS, "RegDeleteKeyA failed: got error %d\n", err);
149a09c8c41Swinesync     }
1500ea0084cSwinesync     else
1510ea0084cSwinesync     {
1520ea0084cSwinesync         err = RegDeleteKeyExA(root, path, sam, 0);
1530ea0084cSwinesync         lok(err == ERROR_SUCCESS, "RegDeleteKeyExA failed: got error %d\n", err);
1540ea0084cSwinesync     }
155a09c8c41Swinesync }
156a09c8c41Swinesync 
delete_tree_(const char * file,unsigned line,HKEY root,const char * path,REGSAM sam)1572d9dfc03Swinesync LONG delete_tree_(const char *file, unsigned line, HKEY root, const char *path, REGSAM sam)
158a09c8c41Swinesync {
159a09c8c41Swinesync     HKEY hkey;
160a09c8c41Swinesync     LONG ret;
161a09c8c41Swinesync     char *subkey_name = NULL;
162a09c8c41Swinesync     DWORD max_subkey_len, subkey_len;
163a09c8c41Swinesync     static const char empty[1];
164a09c8c41Swinesync 
16544c2f0d9Swinesync     ret = RegOpenKeyExA(root, path, 0, KEY_READ|sam, &hkey);
1662d9dfc03Swinesync     lok(!ret || ret == ERROR_FILE_NOT_FOUND, "RegOpenKeyExA failed, got error %d\n", ret);
167a09c8c41Swinesync     if (ret) return ret;
168a09c8c41Swinesync 
169a09c8c41Swinesync     ret = RegQueryInfoKeyA(hkey, NULL, NULL, NULL, NULL, &max_subkey_len,
170a09c8c41Swinesync                            NULL, NULL, NULL, NULL, NULL, NULL);
171a09c8c41Swinesync     if (ret) goto cleanup;
172a09c8c41Swinesync 
173a09c8c41Swinesync     max_subkey_len++;
174a09c8c41Swinesync 
175a09c8c41Swinesync     subkey_name = HeapAlloc(GetProcessHeap(), 0, max_subkey_len);
176a09c8c41Swinesync     if (!subkey_name)
177a09c8c41Swinesync     {
178a09c8c41Swinesync         ret = ERROR_NOT_ENOUGH_MEMORY;
179a09c8c41Swinesync         goto cleanup;
180a09c8c41Swinesync     }
181a09c8c41Swinesync 
182a09c8c41Swinesync     for (;;)
183a09c8c41Swinesync     {
184a09c8c41Swinesync         subkey_len = max_subkey_len;
185a09c8c41Swinesync         ret = RegEnumKeyExA(hkey, 0, subkey_name, &subkey_len, NULL, NULL, NULL, NULL);
186a09c8c41Swinesync         if (ret == ERROR_NO_MORE_ITEMS) break;
187a09c8c41Swinesync         if (ret) goto cleanup;
1882d9dfc03Swinesync         ret = delete_tree_(file, line, hkey, subkey_name, sam);
189a09c8c41Swinesync         if (ret) goto cleanup;
190a09c8c41Swinesync     }
191a09c8c41Swinesync 
19244c2f0d9Swinesync     if (!sam)
193a09c8c41Swinesync         ret = RegDeleteKeyA(hkey, empty);
19444c2f0d9Swinesync     else
19544c2f0d9Swinesync         ret = RegDeleteKeyExA(hkey, empty, sam, 0);
196a09c8c41Swinesync 
197a09c8c41Swinesync cleanup:
1985caeeb03Swinesync     lok(!ret, "Failed to delete registry key, got error %d\n", ret);
199a09c8c41Swinesync     HeapFree(GetProcessHeap(), 0, subkey_name);
200a09c8c41Swinesync     RegCloseKey(hkey);
201a09c8c41Swinesync     return ret;
202a09c8c41Swinesync }
203a09c8c41Swinesync 
add_value_(const char * file,unsigned line,HKEY hkey,const char * name,DWORD type,const void * data,size_t size)20407907552Swinesync void add_value_(const char *file, unsigned line, HKEY hkey, const char *name,
20507907552Swinesync                 DWORD type, const void *data, size_t size)
206a09c8c41Swinesync {
207a09c8c41Swinesync     LONG err;
208a09c8c41Swinesync 
209a09c8c41Swinesync     err = RegSetValueExA(hkey, name, 0, type, (const BYTE *)data, size);
21051327111Swinesync     lok(err == ERROR_SUCCESS, "RegSetValueExA failed: got error %d\n", err);
211a09c8c41Swinesync }
212a09c8c41Swinesync 
delete_value_(const char * file,unsigned line,HKEY hkey,const char * name)21364c84526Swinesync void delete_value_(const char *file, unsigned line, HKEY hkey, const char *name)
214a09c8c41Swinesync {
215a09c8c41Swinesync     LONG err;
216a09c8c41Swinesync 
217a09c8c41Swinesync     err = RegDeleteValueA(hkey, name);
21851327111Swinesync     lok(err == ERROR_SUCCESS, "RegDeleteValueA failed: got error %d\n", err);
219a09c8c41Swinesync }
220a09c8c41Swinesync 
221a09c8c41Swinesync /* Unit tests */
222a09c8c41Swinesync 
test_command_syntax(void)2233969dcc3Swinesync static void test_command_syntax(void)
224a09c8c41Swinesync {
2253969dcc3Swinesync     DWORD r;
226a09c8c41Swinesync 
22744c2f0d9Swinesync     delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0);
228a09c8c41Swinesync 
229a09c8c41Swinesync     run_reg_exe("reg add", &r);
230a09c8c41Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
231a09c8c41Swinesync 
232a09c8c41Swinesync     run_reg_exe("reg add /?", &r);
233a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
234a09c8c41Swinesync 
235a09c8c41Swinesync     run_reg_exe("reg add /h", &r);
236a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
237a09c8c41Swinesync 
238a09c8c41Swinesync     run_reg_exe("reg add -H", &r);
239a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
240a09c8c41Swinesync 
2413969dcc3Swinesync     /* Duplicate switches */
2423969dcc3Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v Wine /t REG_DWORD /d 0x1 /v Test /f", &r);
2433969dcc3Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
2443969dcc3Swinesync 
2453969dcc3Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v dup1 /t REG_DWORD /d 123 /f /t REG_SZ", &r);
2463969dcc3Swinesync     ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */),
2473969dcc3Swinesync        "got exit code %d, expected 1\n", r);
2483969dcc3Swinesync 
2493969dcc3Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v dup2 /t REG_DWORD /d 123 /f /d 456", &r);
2503969dcc3Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
251a09c8c41Swinesync 
25226226dc5Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /f /f", &r);
253cb66fe28Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
25426226dc5Swinesync 
2553969dcc3Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v Wine /ve", &r);
2563969dcc3Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
2573969dcc3Swinesync 
2583969dcc3Swinesync     /* No /v argument */
2593969dcc3Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v", &r);
2603969dcc3Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
2613969dcc3Swinesync 
2623969dcc3Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /d Test /f /v", &r);
2633969dcc3Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
2643969dcc3Swinesync 
2653969dcc3Swinesync     /* Test invalid switches */
2663969dcc3Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v invalid1 /a", &r);
2673969dcc3Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
2683969dcc3Swinesync 
2693969dcc3Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v invalid2 /ae", &r);
2703969dcc3Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
2713969dcc3Swinesync 
2723969dcc3Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v invalid3 /", &r);
2733969dcc3Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
2743969dcc3Swinesync 
2753969dcc3Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v invalid4 -", &r);
2763969dcc3Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
277a09c8c41Swinesync 
278a09c8c41Swinesync     /* Test empty type */
279a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v emptyType /t \"\" /d WineTest /f", &r);
2803969dcc3Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
281334c2e27Swinesync 
282334c2e27Swinesync     /* Test registry view */
283334c2e27Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v abc /d 123 /f /reg:32 /reg:32", &r);
284ad80ceabSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
285334c2e27Swinesync 
286334c2e27Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v abc /d 123 /f /reg:32 /reg:64", &r);
287ad80ceabSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
288334c2e27Swinesync 
289334c2e27Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v abc /d 123 /f /reg:64 /reg:64", &r);
290ad80ceabSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
2913969dcc3Swinesync }
292a09c8c41Swinesync 
test_key_formats(void)2933969dcc3Swinesync static void test_key_formats(void)
2943969dcc3Swinesync {
2953969dcc3Swinesync     HKEY hkey;
2963969dcc3Swinesync     DWORD r;
2973969dcc3Swinesync     LONG err;
2983969dcc3Swinesync 
29977b2d21eSwinesync     add_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
3003969dcc3Swinesync 
301a09c8c41Swinesync     run_reg_exe("reg add \\HKCU\\" KEY_BASE "\\keytest0 /f", &r);
3022d45084dSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
303df92c046Swinesync     verify_key_nonexist(hkey, "keytest0", 0);
304a09c8c41Swinesync 
305a09c8c41Swinesync     run_reg_exe("reg add \\\\HKCU\\" KEY_BASE "\\keytest1 /f", &r);
3062d45084dSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
307df92c046Swinesync     verify_key_nonexist(hkey, "keytest1", 0);
308a09c8c41Swinesync 
309a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE "\\keytest2\\\\ /f", &r);
310a09c8c41Swinesync     ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */),
3112d45084dSwinesync         "got exit code %u, expected 1\n", r);
312a09c8c41Swinesync     err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE "\\keytest2");
313a09c8c41Swinesync     ok(err == ERROR_FILE_NOT_FOUND || broken(err == ERROR_SUCCESS /* WinXP */),
3142d45084dSwinesync         "got exit code %d, expected 2\n", err);
315a09c8c41Swinesync 
316a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE "\\keytest3\\ /f", &r);
3172d45084dSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
318cd3b6fe7Swinesync     verify_key(hkey, "keytest3", 0);
319a09c8c41Swinesync 
320a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE "\\keytest4 /f", &r);
3212d45084dSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
322cd3b6fe7Swinesync     verify_key(hkey, "keytest4", 0);
323a09c8c41Swinesync 
3243969dcc3Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE "\\https://winehq.org /f", &r);
3253969dcc3Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
326cd3b6fe7Swinesync     verify_key(hkey, "https://winehq.org", 0);
3273969dcc3Swinesync 
3283969dcc3Swinesync     close_key(hkey);
32944c2f0d9Swinesync     delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0);
3303969dcc3Swinesync 
3313969dcc3Swinesync     /* Test validity of trailing backslash after system key */
332a1330deaSwinesync     run_reg_exe("reg add HKCU\\ /v Value1 /t REG_SZ /d foo /f", &r);
333f42b63fdSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
334f42b63fdSwinesync     verify_reg_nonexist(HKEY_CURRENT_USER, "Value1");
335a1330deaSwinesync 
336a1330deaSwinesync     run_reg_exe("reg add HKEY_CURRENT_USER\\ /v Value2 /t REG_SZ /d bar /f", &r);
337f42b63fdSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
338f42b63fdSwinesync     verify_reg_nonexist(HKEY_CURRENT_USER, "Value2");
3393969dcc3Swinesync }
340a1330deaSwinesync 
test_add(void)3413969dcc3Swinesync static void test_add(void)
3423969dcc3Swinesync {
343ba10b11fSwinesync     HKEY hkey;
3443969dcc3Swinesync     DWORD r, dword;
3453969dcc3Swinesync 
3463969dcc3Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /f", &r);
3473969dcc3Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3483969dcc3Swinesync 
3493969dcc3Swinesync     open_key(HKEY_CURRENT_USER, KEY_BASE, KEY_WRITE, &hkey);
3503969dcc3Swinesync 
35100ef8711Swinesync     /* The Default value is initialized if no parameters are specified */
35239593a1eSwinesync     verify_reg(hkey, NULL, REG_SZ, "", 1, 0);
35339593a1eSwinesync     delete_value(hkey, NULL);
35400ef8711Swinesync 
35500ef8711Swinesync     /* This also occurs when specifying a registry type and passing data */
35600ef8711Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_DWORD /d 0x5 /f", &r);
35700ef8711Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
35800ef8711Swinesync     dword = 0x5;
35900ef8711Swinesync     verify_reg(hkey, NULL, REG_DWORD, &dword, sizeof(dword), 0);
36000ef8711Swinesync 
36100ef8711Swinesync     /* The Default value can also be overwritten as an empty string */
36200ef8711Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /f", &r);
36300ef8711Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
36439593a1eSwinesync     verify_reg(hkey, NULL, REG_SZ, "", 1, 0);
36500ef8711Swinesync 
36600ef8711Swinesync     close_key(hkey);
3670ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, KEY_BASE, 0);
36800ef8711Swinesync 
36900ef8711Swinesync     /* Specifying a value name doesn't initialize the Default value in a new key */
37000ef8711Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v Test /t REG_SZ /d \"Just me here\" /f", &r);
37100ef8711Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
37200ef8711Swinesync 
37300ef8711Swinesync     open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
37400ef8711Swinesync 
37500ef8711Swinesync     verify_reg(hkey, "Test", REG_SZ, "Just me here", 13, 0);
37600ef8711Swinesync     verify_reg_nonexist(hkey, NULL);
37700ef8711Swinesync 
37800ef8711Swinesync     close_key(hkey);
3790ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, KEY_BASE, 0);
38000ef8711Swinesync 
38100ef8711Swinesync     /* Adding a registry key via WinAPI doesn't initialize the Default value... */
38277b2d21eSwinesync     add_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
38300ef8711Swinesync     verify_reg_nonexist(hkey, NULL);
38400ef8711Swinesync 
38500ef8711Swinesync     /* ... but we can add it without passing [/f] to reg.exe */
38600ef8711Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE, &r);
38700ef8711Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
38839593a1eSwinesync     verify_reg(hkey, NULL, REG_SZ, "", 1, 0);
38939593a1eSwinesync     delete_value(hkey, NULL);
39000ef8711Swinesync 
3913969dcc3Swinesync     /* Test whether overwriting a registry key modifies existing keys and values */
39277b2d21eSwinesync     add_key(hkey, "Subkey", 0, NULL);
3933969dcc3Swinesync     add_value(hkey, "Test1", REG_SZ, "Value1", 7);
3943969dcc3Swinesync     dword = 0x123;
3953969dcc3Swinesync     add_value(hkey, "Test2", REG_DWORD, &dword, sizeof(dword));
3963969dcc3Swinesync 
3973969dcc3Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /f", &r);
3983969dcc3Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3993969dcc3Swinesync 
400cd3b6fe7Swinesync     verify_key(HKEY_CURRENT_USER, KEY_BASE, 0);
401cd3b6fe7Swinesync     verify_key(hkey, "Subkey", 0);
4023969dcc3Swinesync     verify_reg(hkey, "Test1", REG_SZ, "Value1", 7, 0);
4033969dcc3Swinesync     verify_reg(hkey, "Test2", REG_DWORD, &dword, sizeof(dword), 0);
40439593a1eSwinesync     verify_reg(hkey, NULL, REG_SZ, "", 1, 0);
4053969dcc3Swinesync 
40640d62f3cSwinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_NONE /d Test /f", &r);
40740d62f3cSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
40840d62f3cSwinesync 
409cd3b6fe7Swinesync     verify_key(HKEY_CURRENT_USER, KEY_BASE, 0);
410cd3b6fe7Swinesync     verify_key(hkey, "Subkey", 0);
41140d62f3cSwinesync     verify_reg(hkey, "Test1", REG_SZ, "Value1", 7, 0);
41240d62f3cSwinesync     verify_reg(hkey, "Test2", REG_DWORD, &dword, sizeof(dword), 0);
41340d62f3cSwinesync     verify_reg(hkey, NULL, REG_NONE, "T\0e\0s\0t\0\0", 10, 0);
41440d62f3cSwinesync 
4153969dcc3Swinesync     close_key(hkey);
41644c2f0d9Swinesync     delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0);
4173969dcc3Swinesync }
4183969dcc3Swinesync 
test_reg_none(void)4193969dcc3Swinesync static void test_reg_none(void)
4203969dcc3Swinesync {
4213969dcc3Swinesync     HKEY hkey;
4223969dcc3Swinesync     DWORD r;
4233969dcc3Swinesync 
42477b2d21eSwinesync     add_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
4253969dcc3Swinesync 
4265e7302ebSwinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_NONE /f", &r);
4275e7302ebSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
42839593a1eSwinesync     verify_reg(hkey, NULL, REG_NONE, "\0", 2, 0);
4295e7302ebSwinesync 
43039593a1eSwinesync     delete_value(hkey, NULL);
4315e7302ebSwinesync 
4325e7302ebSwinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_NONE /f", &r);
4335e7302ebSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
4345e7302ebSwinesync     verify_reg(hkey, NULL, REG_NONE, "\0", 2, 0);
4355e7302ebSwinesync 
436a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v none0 /d deadbeef /t REG_NONE /f", &r);
4372d45084dSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
438a09c8c41Swinesync     verify_reg(hkey, "none0", REG_NONE, "d\0e\0a\0d\0b\0e\0e\0f\0\0", 18, 0);
439a09c8c41Swinesync 
440a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v none1 /t REG_NONE /f", &r);
441a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
442a09c8c41Swinesync     verify_reg(hkey, "none1", REG_NONE, "\0", 2, 0);
443a09c8c41Swinesync 
4443969dcc3Swinesync     close_key(hkey);
4450ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, KEY_BASE, 0);
4463969dcc3Swinesync }
4473969dcc3Swinesync 
test_reg_sz(void)4483969dcc3Swinesync static void test_reg_sz(void)
4493969dcc3Swinesync {
4503969dcc3Swinesync     HKEY hkey;
4513969dcc3Swinesync     DWORD r;
4523969dcc3Swinesync 
45377b2d21eSwinesync     add_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
4543969dcc3Swinesync 
4555e7302ebSwinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_SZ /f", &r);
4565e7302ebSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
45739593a1eSwinesync     verify_reg(hkey, NULL, REG_SZ, "", 1, 0);
4585e7302ebSwinesync 
459a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /d WineTest /f", &r);
460a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS || broken(r == REG_EXIT_FAILURE /* WinXP */),
461a09c8c41Swinesync        "got exit code %d, expected 0\n", r);
462a09c8c41Swinesync     if (r == REG_EXIT_SUCCESS)
463a09c8c41Swinesync         verify_reg(hkey, "", REG_SZ, "WineTest", 9, 0);
464a09c8c41Swinesync     else
465a09c8c41Swinesync         win_skip("broken reg.exe detected\n");
466a09c8c41Swinesync 
4678789d866Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /f", &r);
4688789d866Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
4698789d866Swinesync     verify_reg(hkey, NULL, REG_SZ, "", 1, 0);
4708789d866Swinesync 
47126226dc5Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /f /ve", &r);
472cb66fe28Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
47326226dc5Swinesync 
4748789d866Swinesync     run_reg_exe("reg add HKEY_CURRENT_USER\\" KEY_BASE " /ve /d WineTEST /f", &r);
4758789d866Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4768789d866Swinesync     verify_reg(hkey, "", REG_SZ, "WineTEST", 9, 0);
4778789d866Swinesync 
4788789d866Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_SZ /f", &r);
4798789d866Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
4808789d866Swinesync     verify_reg(hkey, NULL, REG_SZ, "", 1, 0);
4818789d866Swinesync 
482bfe2251bSwinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v test0 /d deadbeef /f", &r);
483a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
484bfe2251bSwinesync     verify_reg(hkey, "test0", REG_SZ, "deadbeef", 9, 0);
485a09c8c41Swinesync 
486bfe2251bSwinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v test0 /f", &r);
487a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
488bfe2251bSwinesync     verify_reg(hkey, "test0", REG_SZ, "", 1, 0);
489a09c8c41Swinesync 
490a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v test1 /t REG_SZ /f /d", &r);
491a09c8c41Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
492a09c8c41Swinesync 
493a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_SZ /v test2 /f", &r);
494a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
495a09c8c41Swinesync     verify_reg(hkey, "test2", REG_SZ, "", 1, 0);
496a09c8c41Swinesync 
497a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_SZ /v test3 /f /d \"\"", &r);
498a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
499a09c8c41Swinesync     verify_reg(hkey, "test3", REG_SZ, "", 1, 0);
500a09c8c41Swinesync 
5011e0e137fSwinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v string\\04 /t REG_SZ /d \"Value\" /f", &r);
5021e0e137fSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
5031e0e137fSwinesync     verify_reg(hkey, "string\\04", REG_SZ, "Value", 6, 0);
5041e0e137fSwinesync 
5051e0e137fSwinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v string5 /t REG_SZ /d \"foo\\0bar\" /f", &r);
5061e0e137fSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
5071e0e137fSwinesync     verify_reg(hkey, "string5", REG_SZ, "foo\\0bar", 9, 0);
5081e0e137fSwinesync 
5091e0e137fSwinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v \\0 /t REG_SZ /d \"Value\" /f", &r);
5101e0e137fSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
5111e0e137fSwinesync     verify_reg(hkey, "\\0", REG_SZ, "Value", 6, 0);
5121e0e137fSwinesync 
5133969dcc3Swinesync     /* Test support for forward and back slashes in value names */
5143969dcc3Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v count/up /d one/two/three /f", &r);
5153969dcc3Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
5163969dcc3Swinesync     verify_reg(hkey, "count/up", REG_SZ, "one/two/three", 14, 0);
5173969dcc3Swinesync 
5183969dcc3Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v \\foo\\bar /f", &r);
5193969dcc3Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
5203969dcc3Swinesync     verify_reg(hkey, "\\foo\\bar", REG_SZ, "", 1, 0);
5213969dcc3Swinesync 
5223969dcc3Swinesync     close_key(hkey);
5230ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, KEY_BASE, 0);
5243969dcc3Swinesync }
5253969dcc3Swinesync 
test_reg_expand_sz(void)5263969dcc3Swinesync static void test_reg_expand_sz(void)
5273969dcc3Swinesync {
5283969dcc3Swinesync     HKEY hkey;
5293969dcc3Swinesync     DWORD r;
5303969dcc3Swinesync 
53177b2d21eSwinesync     add_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
5323969dcc3Swinesync 
5335e7302ebSwinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_EXPAND_SZ /f", &r);
5345e7302ebSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
53539593a1eSwinesync     verify_reg(hkey, NULL, REG_EXPAND_SZ, "", 1, 0);
5365e7302ebSwinesync 
53739593a1eSwinesync     delete_value(hkey, NULL);
5385e7302ebSwinesync 
5395e7302ebSwinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_EXPAND_SZ /f", &r);
5405e7302ebSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
5415e7302ebSwinesync     verify_reg(hkey, NULL, REG_EXPAND_SZ, "", 1, 0);
5425e7302ebSwinesync 
543a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v expand0 /t REG_EXpand_sz /d \"dead%PATH%beef\" /f", &r);
5442d45084dSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
545a09c8c41Swinesync     verify_reg(hkey, "expand0", REG_EXPAND_SZ, "dead%PATH%beef", 15, 0);
546a09c8c41Swinesync 
547a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v expand1 /t REG_EXpand_sz /d \"dead^%PATH^%beef\" /f", &r);
5482d45084dSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
549a09c8c41Swinesync     verify_reg(hkey, "expand1", REG_EXPAND_SZ, "dead^%PATH^%beef", 17, 0);
550a09c8c41Swinesync 
551a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_EXPAND_SZ /v expand2 /f", &r);
5522d45084dSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
553a09c8c41Swinesync     verify_reg(hkey, "expand2", REG_EXPAND_SZ, "", 1, 0);
554a09c8c41Swinesync 
555a09c8c41Swinesync     run_reg_exe("reg add HKEY_CURRENT_USER\\" KEY_BASE " /ve /t REG_EXPAND_SZ /d WineTEST /f", &r);
5562d45084dSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
557a09c8c41Swinesync     verify_reg(hkey, "", REG_EXPAND_SZ, "WineTEST", 9, 0);
558a09c8c41Swinesync 
559a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_EXPAND_SZ /v expand3 /f /d \"\"", &r);
5602d45084dSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
561a09c8c41Swinesync     verify_reg(hkey, "expand3", REG_EXPAND_SZ, "", 1, 0);
562a09c8c41Swinesync 
5633969dcc3Swinesync     close_key(hkey);
5640ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, KEY_BASE, 0);
5653969dcc3Swinesync }
5663969dcc3Swinesync 
test_reg_binary(void)5673969dcc3Swinesync static void test_reg_binary(void)
5683969dcc3Swinesync {
5693969dcc3Swinesync     HKEY hkey;
5703969dcc3Swinesync     DWORD r, dword, type, size;
5713969dcc3Swinesync     char buffer[22];
5723969dcc3Swinesync     LONG err;
5733969dcc3Swinesync 
57477b2d21eSwinesync     add_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
5753969dcc3Swinesync 
5765e7302ebSwinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_BINARY /f", &r);
5772d45084dSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
57839593a1eSwinesync     verify_reg(hkey, NULL, REG_BINARY, buffer, 0, 0);
5795e7302ebSwinesync 
58039593a1eSwinesync     delete_value(hkey, NULL);
5815e7302ebSwinesync 
5825e7302ebSwinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_BINARY /f", &r);
5835e7302ebSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
5845e7302ebSwinesync     verify_reg(hkey, NULL, REG_BINARY, buffer, 0, 0);
585a09c8c41Swinesync 
586a09c8c41Swinesync     run_reg_exe("reg add HKEY_CURRENT_USER\\" KEY_BASE " /ve /t REG_BINARY /d deadbeef /f", &r);
5872d45084dSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
588a09c8c41Swinesync     dword = 0xefbeadde;
589a09c8c41Swinesync     verify_reg(hkey, "", REG_BINARY, &dword, sizeof(DWORD), 0);
590a09c8c41Swinesync 
5915e7302ebSwinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_BINARY /v bin0 /f", &r);
5925e7302ebSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
5935e7302ebSwinesync     verify_reg(hkey, "bin0", REG_BINARY, buffer, 0, 0);
5945e7302ebSwinesync 
595a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_BINARY /v bin1 /f /d 0xDeAdBeEf", &r);
5962d45084dSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
597a09c8c41Swinesync 
598a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_BINARY /v bin2 /f /d x01", &r);
5992d45084dSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
600a09c8c41Swinesync 
601a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_BINARY /v bin3 /f /d 01x", &r);
6022d45084dSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
603a09c8c41Swinesync 
604a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_BINARY /v bin4 /f /d DeAdBeEf0DD", &r);
6052d45084dSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
606a09c8c41Swinesync     /* Remaining nibble prefixed */
607a09c8c41Swinesync     buffer[0] = 0x0d; buffer[1] = 0xea; buffer[2] = 0xdb;
608a09c8c41Swinesync     buffer[3] = 0xee; buffer[4] = 0xf0; buffer[5] = 0xdd;
6093969dcc3Swinesync     /* Remaining nibble suffixed on WinXP */
610a09c8c41Swinesync     buffer[6] = 0xde; buffer[7] = 0xad; buffer[8] = 0xbe;
611a09c8c41Swinesync     buffer[9] = 0xef; buffer[10] = 0x0d; buffer[11] = 0xd0;
612a09c8c41Swinesync     size = 6;
613a09c8c41Swinesync     err = RegQueryValueExA(hkey, "bin4", NULL, &type, (void *) (buffer+12), &size);
614a09c8c41Swinesync     ok(err == ERROR_SUCCESS, "RegQueryValueEx failed: got %d\n", err);
615a09c8c41Swinesync     ok(type == REG_BINARY, "got wrong type %u\n", type);
616a09c8c41Swinesync     ok(size == 6, "got wrong size %u\n", size);
617a09c8c41Swinesync     ok(memcmp(buffer, buffer+12, 6) == 0 ||
618a09c8c41Swinesync         broken(memcmp(buffer+6, buffer+12, 6) == 0 /* WinXP */), "got wrong data\n");
619a09c8c41Swinesync 
620a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_BINARY /v bin5 /d \"\" /f", &r);
6212d45084dSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
622a09c8c41Swinesync     verify_reg(hkey, "bin5", REG_BINARY, buffer, 0, 0);
623a09c8c41Swinesync 
624a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v bin6 /t REG_BINARY /f /d", &r);
625a09c8c41Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
626a09c8c41Swinesync 
6273969dcc3Swinesync     close_key(hkey);
6280ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, KEY_BASE, 0);
6293969dcc3Swinesync }
6303969dcc3Swinesync 
test_reg_dword(void)6313969dcc3Swinesync static void test_reg_dword(void)
6323969dcc3Swinesync {
6333969dcc3Swinesync     HKEY hkey;
6343969dcc3Swinesync     DWORD r, dword, type, size;
6353969dcc3Swinesync     LONG err;
6363969dcc3Swinesync 
63777b2d21eSwinesync     add_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
6383969dcc3Swinesync 
639a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_DWORD /f /d 12345678", &r);
640a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS || broken(r == REG_EXIT_FAILURE /* WinXP */),
641a09c8c41Swinesync        "got exit code %d, expected 0\n", r);
642a09c8c41Swinesync     dword = 12345678;
643a09c8c41Swinesync     if (r == REG_EXIT_SUCCESS)
644a09c8c41Swinesync         verify_reg(hkey, "", REG_DWORD, &dword, sizeof(dword), 0);
645a09c8c41Swinesync     else
646a09c8c41Swinesync         win_skip("broken reg.exe detected\n");
647a09c8c41Swinesync 
6485e7302ebSwinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_DWORD /f", &r);
6495e7302ebSwinesync     ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */), "got exit code %u, expected 1\n", r);
6505e7302ebSwinesync 
651a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword0 /t REG_DWORD /f /d", &r);
652a09c8c41Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
653a09c8c41Swinesync 
654a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword1 /t REG_DWORD /f", &r);
655a09c8c41Swinesync     ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */),
656a09c8c41Swinesync        "got exit code %d, expected 1\n", r);
657a09c8c41Swinesync 
658a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword2 /t REG_DWORD /d zzz /f", &r);
659a09c8c41Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
660a09c8c41Swinesync 
661a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword3 /t REG_DWORD /d deadbeef /f", &r);
662a09c8c41Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
663a09c8c41Swinesync 
664a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword4 /t REG_DWORD /d 123xyz /f", &r);
665a09c8c41Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
666a09c8c41Swinesync 
667a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword5 /t reg_dword /d 12345678 /f", &r);
668a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
669a09c8c41Swinesync     dword = 12345678;
670a09c8c41Swinesync     verify_reg(hkey, "dword5", REG_DWORD, &dword, sizeof(dword), 0);
671a09c8c41Swinesync 
672a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword6 /t REG_DWORD /D 0123 /f", &r);
673a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
674a09c8c41Swinesync     size = sizeof(dword);
675a09c8c41Swinesync     err = RegQueryValueExA(hkey, "dword6", NULL, &type, (LPBYTE)&dword, &size);
676a09c8c41Swinesync     ok(err == ERROR_SUCCESS, "RegQueryValueEx failed: got %d\n", err);
677a09c8c41Swinesync     ok(type == REG_DWORD, "got wrong type %d, expected %d\n", type, REG_DWORD);
678a09c8c41Swinesync     ok(size == sizeof(DWORD), "got wrong size %d, expected %d\n", size, (int)sizeof(DWORD));
679a09c8c41Swinesync     ok(dword == 123 || broken(dword == 0123 /* WinXP */), "got wrong data %d, expected 123\n", dword);
680a09c8c41Swinesync 
681a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword7 /t reg_dword /d 0xabcdefg /f", &r);
682a09c8c41Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
683a09c8c41Swinesync 
684a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword8 /t REG_dword /d 0xdeadbeef /f", &r);
685a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
686a09c8c41Swinesync     dword = 0xdeadbeef;
687a09c8c41Swinesync     verify_reg(hkey, "dword8", REG_DWORD, &dword, sizeof(dword), 0);
688a09c8c41Swinesync 
689a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_DWORD /v dword9 /f /d -1", &r);
6902d45084dSwinesync     ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */), "got exit code %u, expected 1\n", r);
691a09c8c41Swinesync 
692a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_DWORD /v dword10 /f /d -0x1", &r);
6932d45084dSwinesync     ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */), "got exit code %u, expected 1\n", r);
694a09c8c41Swinesync 
695a260ccceSwinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword11 /t REG_dword /d 0x01ffffffff /f", &r);
6962d45084dSwinesync     ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */), "got exit code %d, expected 1\n", r);
697a09c8c41Swinesync 
698a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword12 /t REG_DWORD /d 0xffffffff /f", &r);
699a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
700a09c8c41Swinesync     dword = ~0u;
701a09c8c41Swinesync     verify_reg(hkey, "dword12", REG_DWORD, &dword, sizeof(dword), 0);
702a09c8c41Swinesync 
703a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword13 /t REG_DWORD /d 00x123 /f", &r);
704a09c8c41Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
705a09c8c41Swinesync 
706a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword14 /t REG_DWORD /d 0X123 /f", &r);
707a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
708a09c8c41Swinesync     dword = 0x123;
709a09c8c41Swinesync     verify_reg(hkey, "dword14", REG_DWORD, &dword, sizeof(dword), 0);
710a09c8c41Swinesync 
711a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword15 /t REG_DWORD /d 4294967296 /f", &r);
7122d45084dSwinesync     ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */), "got exit code %u, expected 1\n", r);
713a09c8c41Swinesync 
71444774b38Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword16 /t REG_DWORD /d 456 /f", &r);
71544774b38Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
71644774b38Swinesync     dword = 456;
71744774b38Swinesync     verify_reg(hkey, "dword16", REG_DWORD, &dword, sizeof(dword), 0);
71844774b38Swinesync 
71944774b38Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword17 /t REG_DWORD /d 0x456 /f", &r);
72044774b38Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
72144774b38Swinesync     dword = 0x456;
72244774b38Swinesync     verify_reg(hkey, "dword17", REG_DWORD, &dword, sizeof(dword), 0);
72344774b38Swinesync 
724a09c8c41Swinesync     /* REG_DWORD_LITTLE_ENDIAN */
725a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v DWORD_LE /t REG_DWORD_LITTLE_ENDIAN /d 456 /f", &r);
726a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
727a09c8c41Swinesync     dword = 456;
728a09c8c41Swinesync     verify_reg(hkey, "DWORD_LE", REG_DWORD_LITTLE_ENDIAN, &dword, sizeof(dword), 0);
729a09c8c41Swinesync 
730fe627c0eSwinesync     close_key(hkey);
7310ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, KEY_BASE, 0);
732fe627c0eSwinesync }
733a09c8c41Swinesync 
734fe627c0eSwinesync /* REG_DWORD_BIG_ENDIAN is broken in every version of Windows. It behaves
735fe627c0eSwinesync  * like an ordinary REG_DWORD, which is little endian.
736fe627c0eSwinesync  */
test_reg_dword_big_endian(void)737fe627c0eSwinesync static void test_reg_dword_big_endian(void)
738fe627c0eSwinesync {
739fe627c0eSwinesync     HKEY hkey;
740fe627c0eSwinesync     DWORD r, dword;
741a09c8c41Swinesync 
742a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_DWORD_BIG_ENDIAN /f", &r);
743fe627c0eSwinesync     ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */), "got exit code %d, expected 1\n", r);
744fe627c0eSwinesync 
745fe627c0eSwinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v Test1 /t REG_DWORD_BIG_ENDIAN /f /d", &r);
746fe627c0eSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
747fe627c0eSwinesync 
748fe627c0eSwinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v Test2 /t REG_DWORD_BIG_ENDIAN /f", &r);
749fe627c0eSwinesync     ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */), "got exit code %d, expected 1\n", r);
750fe627c0eSwinesync 
75177b2d21eSwinesync     add_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
752fe627c0eSwinesync 
753fe627c0eSwinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v Test3 /t REG_DWORD_BIG_ENDIAN /d 456 /f", &r);
754fe627c0eSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
755fe627c0eSwinesync     dword = 456;
756fe627c0eSwinesync     verify_reg(hkey, "Test3", REG_DWORD_BIG_ENDIAN, &dword, sizeof(dword), 0);
757fe627c0eSwinesync 
758fe627c0eSwinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v Test4 /t REG_DWORD_BIG_ENDIAN /d 0x456 /f", &r);
759fe627c0eSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
760fe627c0eSwinesync     dword = 0x456;
761fe627c0eSwinesync     verify_reg(hkey, "Test4", REG_DWORD_BIG_ENDIAN, &dword, sizeof(dword), 0);
762a09c8c41Swinesync 
7633969dcc3Swinesync     close_key(hkey);
7640ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, KEY_BASE, 0);
7653969dcc3Swinesync }
7663969dcc3Swinesync 
test_reg_multi_sz(void)7673969dcc3Swinesync static void test_reg_multi_sz(void)
7683969dcc3Swinesync {
7693969dcc3Swinesync     HKEY hkey;
7703969dcc3Swinesync     DWORD r;
7713969dcc3Swinesync 
77277b2d21eSwinesync     add_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
7733969dcc3Swinesync 
7745e7302ebSwinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /f", &r);
7755e7302ebSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
77639593a1eSwinesync     verify_reg(hkey, NULL, REG_MULTI_SZ, "", 1, 0);
7775e7302ebSwinesync 
77839593a1eSwinesync     delete_value(hkey, NULL);
7795e7302ebSwinesync 
7805e7302ebSwinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_MULTI_SZ /f", &r);
7815e7302ebSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
7826802956eSwinesync     verify_reg(hkey, NULL, REG_MULTI_SZ, "", 1, 0);
7835e7302ebSwinesync 
784a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi0 /t REG_MULTI_SZ /d \"three\\0little\\0strings\" /f", &r);
785a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
7866802956eSwinesync     verify_reg(hkey, "multi0", REG_MULTI_SZ, "three\0little\0strings\0", 22, 0);
787a09c8c41Swinesync 
788a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi1 /s \"#\" /d \"three#little#strings\" /f", &r);
789a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
7906802956eSwinesync     verify_reg(hkey, "multi1", REG_MULTI_SZ, "three\0little\0strings\0", 22, 0);
791a09c8c41Swinesync 
792a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi2 /d \"\" /f", &r);
793a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
7946802956eSwinesync     verify_reg(hkey, "multi2", REG_MULTI_SZ, "", 1, 0);
795a09c8c41Swinesync 
796a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi3 /f", &r);
7972d45084dSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
7986802956eSwinesync     verify_reg(hkey, "multi3", REG_MULTI_SZ, "", 1, 0);
799a09c8c41Swinesync 
800a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi4 /s \"#\" /d \"threelittlestrings\" /f", &r);
801a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
802a09c8c41Swinesync     verify_reg(hkey, "multi4", REG_MULTI_SZ, "threelittlestrings\0", 20, 0);
803a09c8c41Swinesync 
804a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi5 /s \"#randomgibberish\" /d \"three#little#strings\" /f", &r);
8052d45084dSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
806a09c8c41Swinesync 
807a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi6 /s \"\\0\" /d \"three\\0little\\0strings\" /f", &r);
8082d45084dSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
809a09c8c41Swinesync 
810a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi7 /s \"\" /d \"three#little#strings\" /f", &r);
8112d45084dSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
812a09c8c41Swinesync 
813a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi8 /s \"#\" /d \"##\" /f", &r);
8142d45084dSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
815a09c8c41Swinesync 
816a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi9 /s \"#\" /d \"two##strings\" /f", &r);
8172d45084dSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
818a09c8c41Swinesync 
819a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi10 /s \"#\" /d \"#a\" /f", &r);
8202d45084dSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
821a09c8c41Swinesync 
822a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi11 /s \"#\" /d \"a#\" /f", &r);
823a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
8246802956eSwinesync     verify_reg(hkey, "multi11", REG_MULTI_SZ, "a\0", 3, 0);
825a09c8c41Swinesync 
826a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi12 /t REG_MULTI_SZ /f /d", &r);
827a09c8c41Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
828a09c8c41Swinesync 
829a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi13 /t REG_MULTI_SZ /f /s", &r);
830a09c8c41Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
831a09c8c41Swinesync 
832a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi14 /t REG_MULTI_SZ /d \"\\0a\" /f", &r);
833a09c8c41Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
834a09c8c41Swinesync 
835a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi15 /t REG_MULTI_SZ /d \"a\\0\" /f", &r);
836a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
8376802956eSwinesync     verify_reg(hkey, "multi15", REG_MULTI_SZ, "a\0", 3, 0);
838a09c8c41Swinesync 
839a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi16 /d \"two\\0\\0strings\" /f", &r);
840a09c8c41Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
841a09c8c41Swinesync 
842a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi17 /t REG_MULTI_SZ /s \"#\" /d \"#\" /f", &r);
843a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
8446802956eSwinesync     verify_reg(hkey, "multi17", REG_MULTI_SZ, "\0", 2, 0);
845a09c8c41Swinesync 
846a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi18 /t REG_MULTI_SZ /d \"\\0\" /f", &r);
847a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
8486802956eSwinesync     verify_reg(hkey, "multi18", REG_MULTI_SZ, "\0", 2, 0);
849a09c8c41Swinesync 
850a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi19 /t REG_MULTI_SZ /s \"#\" /d \"two\\0#strings\" /f", &r);
851a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
852a09c8c41Swinesync     verify_reg(hkey, "multi19", REG_MULTI_SZ, "two\\0\0strings\0", 15, 0);
853a09c8c41Swinesync 
854a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi20 /t REG_MULTI_SZ /s \"#\" /d \"two#\\0strings\" /f", &r);
855a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
856a09c8c41Swinesync     verify_reg(hkey, "multi20", REG_MULTI_SZ, "two\0\\0strings\0", 15, 0);
857a09c8c41Swinesync 
858a09c8c41Swinesync     run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi21 /t REG_MULTI_SZ /s \"#\" /d \"two\\0\\0strings\" /f", &r);
859a09c8c41Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
860a09c8c41Swinesync     verify_reg(hkey, "multi21", REG_MULTI_SZ, "two\\0\\0strings\0", 16, 0);
861a09c8c41Swinesync 
862a09c8c41Swinesync     close_key(hkey);
8630ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, KEY_BASE, 0);
864a09c8c41Swinesync }
865a09c8c41Swinesync 
866*1a6f523eSThomas Csovcsity #if 0
867334c2e27Swinesync static void test_registry_view_win32(void)
868334c2e27Swinesync {
869334c2e27Swinesync     HKEY hkey;
870334c2e27Swinesync     DWORD r;
871334c2e27Swinesync     BOOL is_wow64, is_win32;
872334c2e27Swinesync 
873334c2e27Swinesync     IsWow64Process(GetCurrentProcess(), &is_wow64);
874334c2e27Swinesync     is_win32 = !is_wow64 && (sizeof(void *) == sizeof(int));
875334c2e27Swinesync 
876334c2e27Swinesync     if (!is_win32) return;
877334c2e27Swinesync 
878334c2e27Swinesync     /* Try adding to the 32-bit registry view (32-bit Windows) */
879334c2e27Swinesync     run_reg_exe("reg add HKLM\\" KEY_BASE " /v Wine32 /d Test /f /reg:32", &r);
880334c2e27Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
881334c2e27Swinesync 
882334c2e27Swinesync     open_key(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY, &hkey);
883334c2e27Swinesync     verify_reg(hkey, "Wine32", REG_SZ, "Test", 5, 0);
884334c2e27Swinesync     close_key(hkey);
885334c2e27Swinesync 
886334c2e27Swinesync     open_key(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY, &hkey);
887334c2e27Swinesync     verify_reg(hkey, "Wine32", REG_SZ, "Test", 5, 0);
888334c2e27Swinesync     close_key(hkey);
889334c2e27Swinesync 
890334c2e27Swinesync     delete_key(HKEY_LOCAL_MACHINE, KEY_BASE, 0);
891334c2e27Swinesync 
892334c2e27Swinesync     /* Try adding to the 64-bit registry view, which doesn't exist on 32-bit Windows */
893334c2e27Swinesync     run_reg_exe("reg add HKLM\\" KEY_BASE " /v Wine64 /d Test /f /reg:64", &r);
894334c2e27Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
895334c2e27Swinesync 
896334c2e27Swinesync     open_key(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY, &hkey);
897334c2e27Swinesync     verify_reg(hkey, "Wine64", REG_SZ, "Test", 5, 0);
898334c2e27Swinesync     close_key(hkey);
899334c2e27Swinesync 
900334c2e27Swinesync     open_key(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY, &hkey);
901334c2e27Swinesync     verify_reg(hkey, "Wine64", REG_SZ, "Test", 5, 0);
902334c2e27Swinesync     close_key(hkey);
903334c2e27Swinesync 
904334c2e27Swinesync     delete_key(HKEY_LOCAL_MACHINE, KEY_BASE, 0);
905334c2e27Swinesync }
906334c2e27Swinesync 
907334c2e27Swinesync static void test_registry_view_win64(void)
908334c2e27Swinesync {
909334c2e27Swinesync     HKEY hkey;
910334c2e27Swinesync     DWORD r;
911334c2e27Swinesync     BOOL is_wow64, is_win64;
912334c2e27Swinesync 
913334c2e27Swinesync     IsWow64Process(GetCurrentProcess(), &is_wow64);
914334c2e27Swinesync     is_win64 = !is_wow64 && (sizeof(void *) > sizeof(int));
915334c2e27Swinesync 
916334c2e27Swinesync     if (!is_win64) return;
917334c2e27Swinesync 
918334c2e27Swinesync     /* Try adding to the 32-bit registry view (64-bit Windows) */
919334c2e27Swinesync     run_reg_exe("reg add HKLM\\" KEY_BASE " /v Wine32 /d Test /f /reg:32", &r);
920334c2e27Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
921334c2e27Swinesync 
922ad80ceabSwinesync     open_key(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY, &hkey);
923ad80ceabSwinesync     verify_reg(hkey, "Wine32", REG_SZ, "Test", 5, 0);
924ad80ceabSwinesync     close_key(hkey);
925ad80ceabSwinesync     delete_key(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY);
926334c2e27Swinesync 
927ad80ceabSwinesync     verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY);
928334c2e27Swinesync 
929334c2e27Swinesync     /* Try adding to the 64-bit registry view (64-bit Windows) */
930334c2e27Swinesync     run_reg_exe("reg add HKLM\\" KEY_BASE " /v Wine64 /d Test /f /reg:64", &r);
931334c2e27Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
932334c2e27Swinesync 
933334c2e27Swinesync     open_key(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY, &hkey);
934334c2e27Swinesync     verify_reg(hkey, "Wine64", REG_SZ, "Test", 5, 0);
935334c2e27Swinesync     close_key(hkey);
936334c2e27Swinesync     delete_key(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY);
937334c2e27Swinesync 
938334c2e27Swinesync     verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY);
939334c2e27Swinesync }
940334c2e27Swinesync 
941334c2e27Swinesync static void test_registry_view_wow64(void)
942334c2e27Swinesync {
943334c2e27Swinesync     HKEY hkey;
944334c2e27Swinesync     DWORD r;
945334c2e27Swinesync     BOOL is_wow64;
946334c2e27Swinesync 
947334c2e27Swinesync     IsWow64Process(GetCurrentProcess(), &is_wow64);
948334c2e27Swinesync 
949334c2e27Swinesync     if (!is_wow64) return;
950334c2e27Swinesync 
951334c2e27Swinesync     /* Try adding to the 32-bit registry view (WOW64) */
952334c2e27Swinesync     run_reg_exe("reg add HKLM\\" KEY_BASE " /v Wine32 /d Test /f /reg:32", &r);
953334c2e27Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
954334c2e27Swinesync 
955334c2e27Swinesync     open_key(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY, &hkey);
956334c2e27Swinesync     verify_reg(hkey, "Wine32", REG_SZ, "Test", 5, 0);
957334c2e27Swinesync     close_key(hkey);
958334c2e27Swinesync     delete_key(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY);
959334c2e27Swinesync 
960334c2e27Swinesync     verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY);
961334c2e27Swinesync 
962334c2e27Swinesync     /* Try adding to the 64-bit registry view (WOW64) */
963334c2e27Swinesync     run_reg_exe("reg add HKLM\\" KEY_BASE " /v Wine64 /d Test /f /reg:64", &r);
964334c2e27Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
965334c2e27Swinesync 
966ad80ceabSwinesync     open_key(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY, &hkey);
967ad80ceabSwinesync     verify_reg(hkey, "Wine64", REG_SZ, "Test", 5, 0);
968ad80ceabSwinesync     close_key(hkey);
969ad80ceabSwinesync     delete_key(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY);
970334c2e27Swinesync 
971ad80ceabSwinesync     verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY);
972334c2e27Swinesync }
973*1a6f523eSThomas Csovcsity #endif
974334c2e27Swinesync 
START_TEST(add)975a09c8c41Swinesync START_TEST(add)
976a09c8c41Swinesync {
977a09c8c41Swinesync     DWORD r;
978a09c8c41Swinesync 
979a09c8c41Swinesync     if (!run_reg_exe("reg.exe /?", &r)) {
9802161165dSwinesync         win_skip("reg.exe not available, skipping 'add' tests\n");
981a09c8c41Swinesync         return;
982a09c8c41Swinesync     }
983a09c8c41Swinesync 
9843969dcc3Swinesync     test_command_syntax();
9853969dcc3Swinesync     test_key_formats();
986a09c8c41Swinesync     test_add();
9873969dcc3Swinesync     test_reg_none();
9883969dcc3Swinesync     test_reg_sz();
9893969dcc3Swinesync     test_reg_expand_sz();
9903969dcc3Swinesync     test_reg_binary();
9913969dcc3Swinesync     test_reg_dword();
992fe627c0eSwinesync     test_reg_dword_big_endian();
9933969dcc3Swinesync     test_reg_multi_sz();
994334c2e27Swinesync 
995334c2e27Swinesync     /* Check if reg.exe is running with elevated privileges */
996334c2e27Swinesync     if (!is_elevated_process())
997334c2e27Swinesync     {
998334c2e27Swinesync         win_skip("reg.exe is not running with elevated privileges; "
999334c2e27Swinesync                  "skipping registry view tests\n");
1000334c2e27Swinesync         return;
1001334c2e27Swinesync     }
1002334c2e27Swinesync 
1003*1a6f523eSThomas Csovcsity #if 0
1004334c2e27Swinesync     test_registry_view_win32();
1005334c2e27Swinesync     test_registry_view_win64();
1006334c2e27Swinesync     test_registry_view_wow64();
1007*1a6f523eSThomas Csovcsity #endif
1008*1a6f523eSThomas Csovcsity 
1009a09c8c41Swinesync }
1010