c59f08f51a5dc7b693e9e91a454d88013cda11a1
[reactos.git] / rostests / winetests / reg / reg.c
1 /*
2 * Copyright 2014 Akihiro Sagawa
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #include <windows.h>
20 #include "wine/test.h"
21
22 #define lok ok_(__FILE__,line)
23 #define KEY_BASE "Software\\Wine\\reg_test"
24 #define REG_EXIT_SUCCESS 0
25 #define REG_EXIT_FAILURE 1
26 #define TODO_REG_TYPE (0x0001u)
27 #define TODO_REG_SIZE (0x0002u)
28 #define TODO_REG_DATA (0x0004u)
29
30 #define run_reg_exe(c,r) run_reg_exe_(__LINE__,c,r)
31 static BOOL run_reg_exe_(unsigned line, const char *cmd, DWORD *rc)
32 {
33 STARTUPINFOA si = {sizeof(STARTUPINFOA)};
34 PROCESS_INFORMATION pi;
35 BOOL bret;
36 DWORD ret;
37 char cmdline[256];
38
39 si.dwFlags = STARTF_USESTDHANDLES;
40 si.hStdInput = INVALID_HANDLE_VALUE;
41 si.hStdOutput = INVALID_HANDLE_VALUE;
42 si.hStdError = INVALID_HANDLE_VALUE;
43
44 strcpy(cmdline, cmd);
45 if (!CreateProcessA(NULL, cmdline, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi))
46 return FALSE;
47
48 ret = WaitForSingleObject(pi.hProcess, 10000);
49 if (ret == WAIT_TIMEOUT)
50 TerminateProcess(pi.hProcess, 1);
51
52 bret = GetExitCodeProcess(pi.hProcess, rc);
53 lok(bret, "GetExitCodeProcess failed: %d\n", GetLastError());
54
55 CloseHandle(pi.hThread);
56 CloseHandle(pi.hProcess);
57 return bret;
58 }
59
60 #define verify_reg(k,v,t,d,s,todo) verify_reg_(__LINE__,k,v,t,d,s,todo)
61 static void verify_reg_(unsigned line, HKEY hkey, const char* value,
62 DWORD exp_type, const void *exp_data, DWORD exp_size, DWORD todo)
63 {
64 DWORD type, size;
65 BYTE data[256];
66 LONG err;
67
68 size = sizeof(data);
69 memset(data, 0xdd, size);
70 err = RegQueryValueExA(hkey, value, NULL, &type, data, &size);
71 lok(err == ERROR_SUCCESS, "RegQueryValueEx failed: got %d\n", err);
72 if (err != ERROR_SUCCESS)
73 return;
74
75 todo_wine_if (todo & TODO_REG_TYPE)
76 lok(type == exp_type, "got wrong type %d, expected %d\n", type, exp_type);
77 todo_wine_if (todo & TODO_REG_SIZE)
78 lok(size == exp_size, "got wrong size %d, expected %d\n", size, exp_size);
79 todo_wine_if (todo & TODO_REG_DATA)
80 lok(memcmp(data, exp_data, size) == 0, "got wrong data\n");
81 }
82
83 static void test_add(void)
84 {
85 HKEY hkey, subkey;
86 LONG err;
87 DWORD r, dword, type, size;
88 char buffer[22];
89
90 run_reg_exe("reg add", &r);
91 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
92
93 run_reg_exe("reg add /?", &r);
94 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
95
96 err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
97 ok(err == ERROR_SUCCESS || err == ERROR_FILE_NOT_FOUND, "got %d\n", err);
98
99 err = RegOpenKeyExA(HKEY_CURRENT_USER, KEY_BASE, 0, KEY_READ, &hkey);
100 ok(err == ERROR_FILE_NOT_FOUND, "got %d\n", err);
101
102 run_reg_exe("reg add HKCU\\" KEY_BASE " /f", &r);
103 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
104
105 err = RegOpenKeyExA(HKEY_CURRENT_USER, KEY_BASE, 0, KEY_READ, &hkey);
106 ok(err == ERROR_SUCCESS, "key creation failed, got %d\n", err);
107
108 /* Test empty type */
109 run_reg_exe("reg add HKCU\\" KEY_BASE " /v emptyType /t \"\" /d WineTest /f", &r);
110 ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
111
112 /* Test input key formats */
113 run_reg_exe("reg add \\HKCU\\" KEY_BASE "\\keytest0 /f", &r);
114 ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
115 err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE "\\keytest0");
116 ok(err == ERROR_FILE_NOT_FOUND, "got exit code %d\n", r);
117
118 run_reg_exe("reg add \\\\HKCU\\" KEY_BASE "\\keytest1 /f", &r);
119 ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
120 err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE "\\keytest1");
121 ok(err == ERROR_FILE_NOT_FOUND, "got exit code %d\n", r);
122
123 run_reg_exe("reg add HKCU\\" KEY_BASE "\\keytest2\\\\ /f", &r);
124 ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */),
125 "got exit code %u\n", r);
126 err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE "\\keytest2");
127 ok(err == ERROR_FILE_NOT_FOUND || broken(err == ERROR_SUCCESS /* WinXP */),
128 "got exit code %d\n", r);
129
130 run_reg_exe("reg add HKCU\\" KEY_BASE "\\keytest3\\ /f", &r);
131 ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
132 err = RegOpenKeyExA(HKEY_CURRENT_USER, KEY_BASE "\\keytest3", 0, KEY_READ, &subkey);
133 ok(err == ERROR_SUCCESS, "key creation failed, got %d\n", err);
134 RegCloseKey(subkey);
135 err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE "\\keytest3");
136 ok(err == ERROR_SUCCESS, "got exit code %d\n", r);
137
138 run_reg_exe("reg add HKCU\\" KEY_BASE "\\keytest4 /f", &r);
139 ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
140 err = RegOpenKeyExA(HKEY_CURRENT_USER, KEY_BASE "\\keytest4", 0, KEY_READ, &subkey);
141 ok(err == ERROR_SUCCESS, "key creation failed, got %d\n", err);
142 RegCloseKey(subkey);
143 err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE "\\keytest4");
144 ok(err == ERROR_SUCCESS, "got exit code %d\n", r);
145
146 /* REG_NONE */
147 run_reg_exe("reg add HKCU\\" KEY_BASE " /v none0 /d deadbeef /t REG_NONE /f", &r);
148 ok(r == REG_EXIT_SUCCESS, "got exit code %d\n", r);
149 verify_reg(hkey, "none0", REG_NONE, "d\0e\0a\0d\0b\0e\0e\0f\0\0", 18, 0);
150
151 run_reg_exe("reg add HKCU\\" KEY_BASE " /v none1 /t REG_NONE /f", &r);
152 ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
153 verify_reg(hkey, "none1", REG_NONE, "\0", 2, 0);
154
155 run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_NONE /f", &r);
156 ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
157 verify_reg(hkey, NULL, REG_NONE, "\0", 2, 0);
158
159 /* REG_SZ */
160 run_reg_exe("reg add HKCU\\" KEY_BASE " /d WineTest /f", &r);
161 ok(r == REG_EXIT_SUCCESS || broken(r == REG_EXIT_FAILURE /* WinXP */),
162 "got exit code %d, expected 0\n", r);
163 if (r == REG_EXIT_SUCCESS)
164 verify_reg(hkey, "", REG_SZ, "WineTest", 9, 0);
165 else
166 win_skip("broken reg.exe detected\n");
167
168 run_reg_exe("reg add HKCU\\" KEY_BASE " /v test /d deadbeef /f", &r);
169 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
170 verify_reg(hkey, "test", REG_SZ, "deadbeef", 9, 0);
171
172 run_reg_exe("reg add HKCU\\" KEY_BASE " /v test /f", &r);
173 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
174 verify_reg(hkey, "test", REG_SZ, "", 1, 0);
175
176 run_reg_exe("reg add HKCU\\" KEY_BASE " /v test1 /t REG_SZ /f /d", &r);
177 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
178
179 run_reg_exe("reg add HKEY_CURRENT_USER\\" KEY_BASE " /ve /d WineTEST /f", &r);
180 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
181 verify_reg(hkey, "", REG_SZ, "WineTEST", 9, 0);
182
183 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_SZ /v test2 /f", &r);
184 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
185 verify_reg(hkey, "test2", REG_SZ, "", 1, 0);
186
187 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_SZ /v test3 /f /d \"\"", &r);
188 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
189 verify_reg(hkey, "test3", REG_SZ, "", 1, 0);
190
191 run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /f", &r);
192 ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
193 verify_reg(hkey, NULL, REG_SZ, "", 1, 0);
194
195 run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_SZ /f", &r);
196 ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
197 verify_reg(hkey, NULL, REG_SZ, "", 1, 0);
198
199 /* REG_EXPAND_SZ */
200 run_reg_exe("reg add HKCU\\" KEY_BASE " /v expand0 /t REG_EXpand_sz /d \"dead%PATH%beef\" /f", &r);
201 ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
202 verify_reg(hkey, "expand0", REG_EXPAND_SZ, "dead%PATH%beef", 15, 0);
203
204 run_reg_exe("reg add HKCU\\" KEY_BASE " /v expand1 /t REG_EXpand_sz /d \"dead^%PATH^%beef\" /f", &r);
205 ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
206 verify_reg(hkey, "expand1", REG_EXPAND_SZ, "dead^%PATH^%beef", 17, 0);
207
208 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_EXPAND_SZ /v expand2 /f", &r);
209 ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
210 verify_reg(hkey, "expand2", REG_EXPAND_SZ, "", 1, 0);
211
212 run_reg_exe("reg add HKEY_CURRENT_USER\\" KEY_BASE " /ve /t REG_EXPAND_SZ /d WineTEST /f", &r);
213 ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
214 verify_reg(hkey, "", REG_EXPAND_SZ, "WineTEST", 9, 0);
215
216 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_EXPAND_SZ /v expand3 /f /d \"\"", &r);
217 ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
218 verify_reg(hkey, "expand3", REG_EXPAND_SZ, "", 1, 0);
219
220 run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_EXPAND_SZ /f", &r);
221 ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
222 verify_reg(hkey, NULL, REG_EXPAND_SZ, "", 1, 0);
223
224 /* REG_BINARY */
225 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_BINARY /v bin0 /f", &r);
226 ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
227 verify_reg(hkey, "bin0", REG_BINARY, buffer, 0, 0);
228
229 run_reg_exe("reg add HKEY_CURRENT_USER\\" KEY_BASE " /ve /t REG_BINARY /d deadbeef /f", &r);
230 ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
231 dword = 0xefbeadde;
232 verify_reg(hkey, "", REG_BINARY, &dword, sizeof(DWORD), 0);
233
234 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_BINARY /v bin1 /f /d 0xDeAdBeEf", &r);
235 ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
236 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_BINARY /v bin2 /f /d x01", &r);
237 ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
238 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_BINARY /v bin3 /f /d 01x", &r);
239 ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
240
241 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_BINARY /v bin4 /f /d DeAdBeEf0DD", &r);
242 ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
243 /* Remaining nibble prefixed */
244 buffer[0] = 0x0d; buffer[1] = 0xea; buffer[2] = 0xdb;
245 buffer[3] = 0xee; buffer[4] = 0xf0; buffer[5] = 0xdd;
246 /* Remaining nibble suffixed on winXP */
247 buffer[6] = 0xde; buffer[7] = 0xad; buffer[8] = 0xbe;
248 buffer[9] = 0xef; buffer[10] = 0x0d; buffer[11] = 0xd0;
249 size = 6;
250 err = RegQueryValueExA(hkey, "bin4", NULL, &type, (void *) (buffer+12), &size);
251 ok(err == ERROR_SUCCESS, "RegQueryValueEx failed: got %d\n", err);
252 ok(type == REG_BINARY, "got wrong type %u\n", type);
253 ok(size == 6, "got wrong size %u\n", size);
254 ok(memcmp(buffer, buffer+12, 6) == 0 ||
255 broken(memcmp(buffer+6, buffer+12, 6) == 0 /* WinXP */), "got wrong data\n");
256
257 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_BINARY /v bin5 /d \"\" /f", &r);
258 ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
259 verify_reg(hkey, "bin5", REG_BINARY, buffer, 0, 0);
260
261 run_reg_exe("reg add HKCU\\" KEY_BASE " /v bin6 /t REG_BINARY /f /d", &r);
262 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
263
264 run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_BINARY /f", &r);
265 ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
266 verify_reg(hkey, NULL, REG_BINARY, buffer, 0, 0);
267
268 /* REG_DWORD */
269 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_DWORD /f /d 12345678", &r);
270 ok(r == REG_EXIT_SUCCESS || broken(r == REG_EXIT_FAILURE /* WinXP */),
271 "got exit code %d, expected 0\n", r);
272 dword = 12345678;
273 if (r == REG_EXIT_SUCCESS)
274 verify_reg(hkey, "", REG_DWORD, &dword, sizeof(dword), 0);
275 else
276 win_skip("broken reg.exe detected\n");
277
278 run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword0 /t REG_DWORD /f /d", &r);
279 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
280 run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword1 /t REG_DWORD /f", &r);
281 ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */),
282 "got exit code %d, expected 1\n", r);
283 run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword2 /t REG_DWORD /d zzz /f", &r);
284 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
285 run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword3 /t REG_DWORD /d deadbeef /f", &r);
286 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
287 run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword4 /t REG_DWORD /d 123xyz /f", &r);
288 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
289
290 run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword5 /t reg_dword /d 12345678 /f", &r);
291 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
292 dword = 12345678;
293 verify_reg(hkey, "dword5", REG_DWORD, &dword, sizeof(dword), 0);
294
295 run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword6 /t REG_DWORD /D 0123 /f", &r);
296 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
297 size = sizeof(dword);
298 err = RegQueryValueExA(hkey, "dword6", NULL, &type, (LPBYTE)&dword, &size);
299 ok(err == ERROR_SUCCESS, "RegQueryValueEx failed: got %d\n", err);
300 ok(type == REG_DWORD, "got wrong type %d, expected %d\n", type, REG_DWORD);
301 ok(size == sizeof(DWORD), "got wrong size %d, expected %d\n", size, (int)sizeof(DWORD));
302 ok(dword == 123 || broken(dword == 0123 /* WinXP */), "got wrong data %d, expected 123\n", dword);
303
304 run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword7 /t reg_dword /d 0xabcdefg /f", &r);
305 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
306
307 run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword8 /t REG_dword /d 0xdeadbeef /f", &r);
308 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
309 dword = 0xdeadbeef;
310 verify_reg(hkey, "dword8", REG_DWORD, &dword, sizeof(dword), 0);
311
312 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_DWORD /v dword9 /f /d -1", &r);
313 ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */), "got exit code %u\n", r);
314 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_DWORD /v dword10 /f /d -0x1", &r);
315 ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */), "got exit code %u\n", r);
316
317 run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword8 /t REG_dword /d 0x01ffffffff /f", &r);
318 ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */), "got exit code %d\n", r);
319
320 run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword12 /t REG_DWORD /d 0xffffffff /f", &r);
321 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
322 dword = ~0u;
323 verify_reg(hkey, "dword12", REG_DWORD, &dword, sizeof(dword), 0);
324
325 run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword13 /t REG_DWORD /d 00x123 /f", &r);
326 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
327
328 run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword14 /t REG_DWORD /d 0X123 /f", &r);
329 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
330 dword = 0x123;
331 verify_reg(hkey, "dword14", REG_DWORD, &dword, sizeof(dword), 0);
332
333 run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword15 /t REG_DWORD /d 4294967296 /f", &r);
334 ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */), "got exit code %u\n", r);
335
336 run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_DWORD /f", &r);
337 ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */), "got exit code %u\n", r);
338
339 /* REG_DWORD_LITTLE_ENDIAN */
340 run_reg_exe("reg add HKCU\\" KEY_BASE " /v DWORD_LE /t REG_DWORD_LITTLE_ENDIAN /d 456 /f", &r);
341 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
342 dword = 456;
343 verify_reg(hkey, "DWORD_LE", REG_DWORD_LITTLE_ENDIAN, &dword, sizeof(dword), 0);
344
345 /* REG_DWORD_BIG_ENDIAN */
346 run_reg_exe("reg add HKCU\\" KEY_BASE " /v DWORD_BE /t REG_DWORD_BIG_ENDIAN /d 456 /f", &r);
347 ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
348 dword = 456;
349 verify_reg(hkey, "DWORD_BE", REG_DWORD_BIG_ENDIAN, &dword, sizeof(dword), 0);
350 /* REG_DWORD_BIG_ENDIAN is broken in every version of windows. It behaves like
351 * an ordinary REG_DWORD - that is little endian. GG */
352
353 run_reg_exe("reg add HKCU\\" KEY_BASE " /v DWORD_BE2 /t REG_DWORD_BIG_ENDIAN /f /d", &r);
354 ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
355
356 run_reg_exe("reg add HKCU\\" KEY_BASE " /v DWORD_BE3 /t REG_DWORD_BIG_ENDIAN /f", &r);
357 ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */), "got exit code %u\n", r);
358
359 run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_DWORD_BIG_ENDIAN /f", &r);
360 ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */), "got exit code %u\n", r);
361
362 /* REG_MULTI_SZ */
363 run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi0 /t REG_MULTI_SZ /d \"three\\0little\\0strings\" /f", &r);
364 ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
365 memcpy(buffer, "three\0little\0strings\0", 22);
366 verify_reg(hkey, "multi0", REG_MULTI_SZ, buffer, 22, 0);
367
368 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi1 /s \"#\" /d \"three#little#strings\" /f", &r);
369 ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
370 verify_reg(hkey, "multi1", REG_MULTI_SZ, buffer, 22, 0);
371
372 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi2 /d \"\" /f", &r);
373 ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
374 verify_reg(hkey, "multi2", REG_MULTI_SZ, &buffer[21], 1, 0);
375
376 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi3 /f", &r);
377 ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
378 verify_reg(hkey, "multi3", REG_MULTI_SZ, &buffer[21], 1, 0);
379
380 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi4 /s \"#\" /d \"threelittlestrings\" /f", &r);
381 ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
382 verify_reg(hkey, "multi4", REG_MULTI_SZ, "threelittlestrings\0", 20, 0);
383
384 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi5 /s \"#randomgibberish\" /d \"three#little#strings\" /f", &r);
385 ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
386 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi6 /s \"\\0\" /d \"three\\0little\\0strings\" /f", &r);
387 ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
388 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi7 /s \"\" /d \"three#little#strings\" /f", &r);
389 ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
390 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi8 /s \"#\" /d \"##\" /f", &r);
391 ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
392 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi9 /s \"#\" /d \"two##strings\" /f", &r);
393 ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
394 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi10 /s \"#\" /d \"#a\" /f", &r);
395 ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
396
397 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi11 /s \"#\" /d \"a#\" /f", &r);
398 ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
399 buffer[0]='a'; buffer[1]=0; buffer[2]=0;
400 verify_reg(hkey, "multi11", REG_MULTI_SZ, buffer, 3, 0);
401
402 run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi12 /t REG_MULTI_SZ /f /d", &r);
403 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
404
405 run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi13 /t REG_MULTI_SZ /f /s", &r);
406 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
407
408 run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi14 /t REG_MULTI_SZ /d \"\\0a\" /f", &r);
409 ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
410
411 run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi15 /t REG_MULTI_SZ /d \"a\\0\" /f", &r);
412 ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
413 verify_reg(hkey, "multi15", REG_MULTI_SZ, buffer, 3, 0);
414
415 run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi16 /d \"two\\0\\0strings\" /f", &r);
416 ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
417
418 run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi17 /t REG_MULTI_SZ /s \"#\" /d \"#\" /f", &r);
419 ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
420 buffer[0] = 0; buffer[1] = 0;
421 verify_reg(hkey, "multi17", REG_MULTI_SZ, buffer, 2, 0);
422
423 run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi18 /t REG_MULTI_SZ /d \"\\0\" /f", &r);
424 ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
425 verify_reg(hkey, "multi18", REG_MULTI_SZ, buffer, 2, 0);
426
427 run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi19 /t REG_MULTI_SZ /s \"#\" /d \"two\\0#strings\" /f", &r);
428 ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
429 verify_reg(hkey, "multi19", REG_MULTI_SZ, "two\\0\0strings\0", 15, 0);
430
431 run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi20 /t REG_MULTI_SZ /s \"#\" /d \"two#\\0strings\" /f", &r);
432 ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
433 verify_reg(hkey, "multi20", REG_MULTI_SZ, "two\0\\0strings\0", 15, 0);
434
435 run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi21 /t REG_MULTI_SZ /s \"#\" /d \"two\\0\\0strings\" /f", &r);
436 ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
437 verify_reg(hkey, "multi21", REG_MULTI_SZ, "two\\0\\0strings\0", 16, 0);
438
439 run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_MULTI_SZ /f", &r);
440 ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
441 verify_reg(hkey, NULL, REG_MULTI_SZ, buffer, 1, 0);
442
443 RegCloseKey(hkey);
444
445 err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
446 ok(err == ERROR_SUCCESS, "got %d\n", err);
447 }
448
449 static void test_delete(void)
450 {
451 HKEY hkey, hsubkey;
452 LONG err;
453 DWORD r;
454 const DWORD deadbeef = 0xdeadbeef;
455
456 run_reg_exe("reg delete", &r);
457 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
458
459 run_reg_exe("reg delete /?", &r);
460 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
461
462 err = RegCreateKeyExA(HKEY_CURRENT_USER, KEY_BASE, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, NULL);
463 ok(err == ERROR_SUCCESS, "got %d\n", err);
464
465 err = RegSetValueExA(hkey, "foo", 0, REG_DWORD, (LPBYTE)&deadbeef, sizeof(deadbeef));
466 ok(err == ERROR_SUCCESS, "got %d\n" ,err);
467
468 err = RegSetValueExA(hkey, "bar", 0, REG_DWORD, (LPBYTE)&deadbeef, sizeof(deadbeef));
469 ok(err == ERROR_SUCCESS, "got %d\n" ,err);
470
471 err = RegSetValueExA(hkey, "", 0, REG_DWORD, (LPBYTE)&deadbeef, sizeof(deadbeef));
472 ok(err == ERROR_SUCCESS, "got %d\n" ,err);
473
474 err = RegCreateKeyExA(hkey, "subkey", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hsubkey, NULL);
475 ok(err == ERROR_SUCCESS, "got %d\n" ,err);
476 RegCloseKey(hsubkey);
477
478 run_reg_exe("reg delete HKCU\\" KEY_BASE " /v bar /f", &r);
479 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
480 err = RegQueryValueExA(hkey, "bar", NULL, NULL, NULL, NULL);
481 ok(err == ERROR_FILE_NOT_FOUND, "got %d\n", err);
482
483 run_reg_exe("reg delete HKCU\\" KEY_BASE " /ve /f", &r);
484 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
485 err = RegQueryValueExA(hkey, "", NULL, NULL, NULL, NULL);
486 ok(err == ERROR_FILE_NOT_FOUND, "got %d, expected 2\n", err);
487
488 run_reg_exe("reg delete HKCU\\" KEY_BASE " /va /f", &r);
489 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
490 err = RegQueryValueExA(hkey, "foo", NULL, NULL, NULL, NULL);
491 ok(err == ERROR_FILE_NOT_FOUND, "got %d\n", err);
492 err = RegOpenKeyExA(hkey, "subkey", 0, KEY_READ, &hsubkey);
493 ok(err == ERROR_SUCCESS, "got %d\n", err);
494 RegCloseKey(hsubkey);
495 RegCloseKey(hkey);
496
497 run_reg_exe("reg delete HKCU\\" KEY_BASE " /f", &r);
498 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
499 err = RegOpenKeyExA(HKEY_CURRENT_USER, KEY_BASE, 0, KEY_READ, &hkey);
500 ok(err == ERROR_FILE_NOT_FOUND, "got %d\n", err);
501
502 run_reg_exe("reg delete HKCU\\" KEY_BASE " /f", &r);
503 ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
504 }
505
506 static void test_query(void)
507 {
508 DWORD r;
509 HKEY key, subkey;
510 LONG err;
511 const char hello[] = "Hello";
512 const char world[] = "World";
513 const char empty1[] = "Empty1";
514 const char empty2[] = "Empty2";
515 const DWORD dword1 = 0x123;
516 const DWORD dword2 = 0xabc;
517
518 run_reg_exe("reg query", &r);
519 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
520
521 run_reg_exe("reg query /?", &r);
522 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
523
524 /* Create a test key */
525 err = RegCreateKeyExA(HKEY_CURRENT_USER, KEY_BASE, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL);
526 ok(err == ERROR_SUCCESS, "got %d, expected 0\n", err);
527
528 run_reg_exe("reg query HKCU\\" KEY_BASE " /ve", &r);
529 todo_wine ok(r == REG_EXIT_SUCCESS || broken(r == REG_EXIT_FAILURE /* WinXP */),
530 "got exit code %d, expected 0\n", r);
531
532 err = RegSetValueExA(key, "Test", 0, REG_SZ, (BYTE *)hello, sizeof(hello));
533 ok(err == ERROR_SUCCESS, "got %d, expected 0\n", err);
534
535 err = RegSetValueExA(key, "Wine", 0, REG_DWORD, (BYTE *)&dword1, sizeof(dword1));
536 ok(err == ERROR_SUCCESS, "got %d, expected 0\n", err);
537
538 err = RegSetValueExA(key, NULL, 0, REG_SZ, (BYTE *)empty1, sizeof(empty1));
539 ok(err == ERROR_SUCCESS, "got %d, expected 0\n", err);
540
541 run_reg_exe("reg query HKCU\\" KEY_BASE, &r);
542 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
543
544 run_reg_exe("reg query HKCU\\" KEY_BASE " /v", &r);
545 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
546
547 run_reg_exe("reg query HKCU\\" KEY_BASE " /v Missing", &r);
548 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
549
550 run_reg_exe("reg query HKCU\\" KEY_BASE " /v Test", &r);
551 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
552
553 run_reg_exe("reg query HKCU\\" KEY_BASE " /v Wine", &r);
554 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
555
556 run_reg_exe("reg query HKCU\\" KEY_BASE " /ve", &r);
557 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
558
559 /* Create a test subkey */
560 err = RegCreateKeyExA(key, "Subkey", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &subkey, NULL);
561 ok(err == ERROR_SUCCESS, "got %d\n", err);
562
563 err = RegSetValueExA(subkey, "Test", 0, REG_SZ, (BYTE *)world, sizeof(world));
564 ok(err == ERROR_SUCCESS, "got %d, expected 0\n", err);
565
566 err = RegSetValueExA(subkey, "Wine", 0, REG_DWORD, (BYTE *)&dword2, sizeof(dword2));
567 ok(err == ERROR_SUCCESS, "got %d, expected 0\n", err);
568
569 err = RegSetValueExA(subkey, NULL, 0, REG_SZ, (BYTE *)empty2, sizeof(empty2));
570 ok(err == ERROR_SUCCESS, "got %d, expected 0\n", err);
571
572 err = RegCloseKey(subkey);
573 ok(err == ERROR_SUCCESS, "got %d, expected 0\n", err);
574
575 run_reg_exe("reg query HKCU\\" KEY_BASE "\\subkey", &r);
576 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
577
578 run_reg_exe("reg query HKCU\\" KEY_BASE "\\subkey /v Test", &r);
579 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
580
581 run_reg_exe("reg query HKCU\\" KEY_BASE "\\subkey /v Wine", &r);
582 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
583
584 run_reg_exe("reg query HKCU\\" KEY_BASE "\\subkey /ve", &r);
585 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
586
587 /* Test recursion */
588 run_reg_exe("reg query HKCU\\" KEY_BASE " /s", &r);
589 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
590
591 run_reg_exe("reg query HKCU\\" KEY_BASE " /v Test /s", &r);
592 ok(r == REG_EXIT_SUCCESS || r == REG_EXIT_FAILURE /* WinXP */,
593 "got exit code %d, expected 0\n", r);
594
595 run_reg_exe("reg query HKCU\\" KEY_BASE " /v Wine /s", &r);
596 ok(r == REG_EXIT_SUCCESS || r == REG_EXIT_FAILURE /* WinXP */,
597 "got exit code %d, expected 0\n", r);
598
599 run_reg_exe("reg query HKCU\\" KEY_BASE " /ve /s", &r);
600 ok(r == REG_EXIT_SUCCESS || r == REG_EXIT_FAILURE /* WinXP */,
601 "got exit code %d, expected 0\n", r);
602
603 /* Clean-up, then query */
604 err = RegDeleteKeyA(key, "subkey");
605 ok(err == ERROR_SUCCESS, "got %d, expected 0\n", err);
606
607 err = RegCloseKey(key);
608 ok(err == ERROR_SUCCESS, "got %d, expected 0\n", err);
609
610 run_reg_exe("reg query HKCU\\" KEY_BASE "\\subkey", &r);
611 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
612
613 err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
614 ok(err == ERROR_SUCCESS, "got %d, expected 0\n", err);
615
616 run_reg_exe("reg query HKCU\\" KEY_BASE, &r);
617 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
618 }
619
620 static void test_v_flags(void)
621 {
622 DWORD r;
623
624 run_reg_exe("reg add HKCU\\" KEY_BASE " /v Wine /ve", &r);
625 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
626
627 run_reg_exe("reg delete HKCU\\" KEY_BASE " /v Wine /ve", &r);
628 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
629
630 run_reg_exe("reg delete HKCU\\" KEY_BASE " /v Wine /va", &r);
631 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
632
633 run_reg_exe("reg delete HKCU\\" KEY_BASE " /ve /va", &r);
634 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
635
636 /* No /v argument */
637 run_reg_exe("reg add HKCU\\" KEY_BASE " /v", &r);
638 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
639
640 run_reg_exe("reg add HKCU\\" KEY_BASE " /d Test /f /v", &r);
641 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
642
643 run_reg_exe("reg delete HKCU\\" KEY_BASE " /v", &r);
644 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
645
646 run_reg_exe("reg delete HKCU\\" KEY_BASE " /f /v", &r);
647 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
648
649 /* Multiple /v switches */
650 run_reg_exe("reg add HKCU\\" KEY_BASE " /v Wine /t REG_DWORD /d 0x1 /v Test /f", &r);
651 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
652
653 run_reg_exe("reg delete HKCU\\" KEY_BASE " /v Wine /v Test /f", &r);
654 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
655 }
656
657 START_TEST(reg)
658 {
659 DWORD r;
660 if (!run_reg_exe("reg.exe /?", &r)) {
661 win_skip("reg.exe not available, skipping reg.exe tests\n");
662 return;
663 }
664
665 test_add();
666 test_delete();
667 test_query();
668 test_v_flags();
669 }