ReactOS 0.4.15-dev-5667-ged97270
copy.c
Go to the documentation of this file.
1/*
2 * Copyright 2021 Hugh McMaster
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 "reg_test.h"
20
21#define COPY_SRC KEY_WINE "\\reg_copy"
22
23static void test_command_syntax(void)
24{
25 DWORD r;
26
27 run_reg_exe("reg copy", &r);
28 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
29
30 run_reg_exe("reg copy /?", &r);
31 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
32
33 run_reg_exe("reg copy /h", &r);
34 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
35
36 run_reg_exe("reg copy -H", &r);
37 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
38
39 run_reg_exe("reg copy /? /f", &r);
40 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
41
42 run_reg_exe("reg copy /h /f", &r);
43 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
44
45 run_reg_exe("reg copy /? /s", &r);
46 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
47
48 run_reg_exe("reg copy /h /s", &r);
49 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
50
51 run_reg_exe("reg copy /f", &r);
52 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
53
54 run_reg_exe("reg copy /s", &r);
55 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
56
57 run_reg_exe("reg copy /s /f", &r);
58 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
59
60 run_reg_exe("reg copy /f /s", &r);
61 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
62
63 run_reg_exe("reg copy HKCU\\" COPY_SRC " /f", &r);
64 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
65
66 run_reg_exe("reg copy HKCU\\" COPY_SRC " foo /f", &r);
67 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
68
69 run_reg_exe("reg copy /f HKCU\\" COPY_SRC " HKCU\\" KEY_BASE, &r);
70 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
71
72 run_reg_exe("reg copy HKCU\\" COPY_SRC " /f HKCU\\" KEY_BASE, &r);
73 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
74
75 run_reg_exe("reg copy HKCU\\" COPY_SRC " /s HKCU\\" KEY_BASE, &r);
76 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
77
78 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /a", &r);
79 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
80
81 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f /a", &r);
82 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
83
84 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\", &r);
85 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
86
87 /* Source and destination keys are the same */
88 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" COPY_SRC, &r);
89 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
90
91 run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" COPY_SRC, &r);
92 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
93
94 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" COPY_SRC "\\", &r);
95 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
96
97 run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" COPY_SRC "\\", &r);
98 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
99
100 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" COPY_SRC " /f", &r);
101 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
102
103 run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" COPY_SRC " /f", &r);
104 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
105
106 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" COPY_SRC "\\ /f", &r);
107 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
108
109 run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" COPY_SRC "\\ /f", &r);
110 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
111
112 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" COPY_SRC " /s /f", &r);
113 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
114
115 run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" COPY_SRC " /s /f", &r);
116 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
117
118 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" COPY_SRC "\\ /s /f", &r);
119 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
120
121 run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" COPY_SRC "\\ /s /f", &r);
122 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
123}
124
125static void test_copy_empty_key(void)
126{
127 DWORD r;
128
131
133
134
135 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
136 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
138
139 run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg", &r);
140 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
141 ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n");
142
144
145
146 run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" KEY_BASE " /f", &r);
147 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
149
150 run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg", &r);
151 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
152 ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n");
153
155
156
157 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE "\\ /f", &r);
158 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
160
161 run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg", &r);
162 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
163 ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n");
164
166
167
168 run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" KEY_BASE "\\ /f", &r);
169 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
171
172 run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg", &r);
173 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
174 ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n");
175
176
177 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /s /f", &r);
178 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
180
181 run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg", &r);
182 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
183 ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n");
184}
185
186static void test_copy_simple_data(void)
187{
188 HKEY hkey;
189 DWORD r, dword;
190
193
195
196 dword = 0x100;
197 add_value(hkey, "DWORD", REG_DWORD, &dword, sizeof(dword));
198 add_value(hkey, "String", REG_SZ, "Your text here...", 18);
199 close_key(hkey);
200
201
202 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
203 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
205
206 run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
207 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
208 ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n");
209
211
212
213 run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" KEY_BASE " /f", &r);
214 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
216
217 run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
218 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
219 ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n");
220
222
223
224 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE "\\ /f", &r);
225 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
227
228 run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
229 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
230 ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n");
231
233
234
235 run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" KEY_BASE "\\ /f", &r);
236 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
238
239 run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
240 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
241 ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n");
242
243
244 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /s /f", &r);
245 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
247
248 run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
249 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
250 ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n");
251}
252
253static void test_copy_complex_data(void)
254{
255 HKEY hkey, subkey;
256 DWORD r, dword;
257
260
262
263 dword = 0x100;
264 add_value(hkey, "DWORD", REG_DWORD, &dword, sizeof(dword));
265 add_value(hkey, "String", REG_SZ, "Your text here...", 18);
266
267 add_key(hkey, "Subkey1", 0, &subkey);
268 add_value(subkey, "Binary", REG_BINARY, "\x11\x22\x33\x44", 4);
269 add_value(subkey, "Undefined hex", 0x100, "%PATH%", 7);
270 close_key(subkey);
271
272 add_key(hkey, "Subkey2a", 0, &subkey);
273 add_value(subkey, "double\"quote", REG_SZ, "\"Hello, World!\"", 16);
274 dword = 0x8;
275 add_value(subkey, "single'quote", REG_DWORD, &dword, sizeof(dword));
276 close_key(subkey);
277
278 add_key(hkey, "Subkey2a\\Subkey2b", 0, &subkey);
279 add_value(subkey, NULL, REG_SZ, "Default value name", 19);
280 add_value(subkey, "Multiple strings", REG_MULTI_SZ, "Line1\0Line2\0Line3\0", 19);
281 close_key(subkey);
282
283 add_key(hkey, "Subkey3a", 0, &subkey);
284 add_value(subkey, "Backslash", REG_SZ, "Use \\\\ to escape a backslash", 29);
285 close_key(subkey);
286
287 add_key(hkey, "Subkey3a\\Subkey3b\\Subkey3c", 0, &subkey);
288 add_value(subkey, "String expansion", REG_EXPAND_SZ, "%HOME%\\%PATH%", 14);
289 add_value(subkey, "Zero data type", REG_NONE, "Value", 6);
290 close_key(subkey);
291
292 add_key(hkey, "Subkey4", 0, &subkey);
293 dword = 0x12345678;
294 add_value(subkey, NULL, REG_DWORD, &dword, sizeof(dword));
295 add_value(subkey, "43981", 0xabcd, "Value", 6);
296 close_key(subkey);
297
298 close_key(hkey);
299
300 /* Copy values only */
301 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
302 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
304
305 run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r);
306 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
307 ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n");
308
309 /* Copy subkeys and values */
310 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /s /f", &r);
311 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
313
314 run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r);
315 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
316 ok(compare_export("file.reg", complex_data_test, 0), "compare_export() failed\n");
317}
318
319static void test_copy_key_order(void)
320{
321 HKEY hkey;
322 DWORD r;
323
326
328 add_key(hkey, "Subkey2", 0, NULL);
329 add_key(hkey, "Subkey1", 0, NULL);
330 close_key(hkey);
331
332 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /s /f", &r);
333 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
335
336 run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
337 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
338 ok(compare_export("file.reg", key_order_test, 0), "compare_export() failed\n");
339}
340
341static void test_copy_value_order(void)
342{
343 HKEY hkey;
344 DWORD r;
345
348
350 add_value(hkey, "Value 2", REG_SZ, "I was added first!", 19);
351 add_value(hkey, "Value 1", REG_SZ, "I was added second!", 20);
352 close_key(hkey);
353
354 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
355 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
357
358 run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
359 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
360 ok(compare_export("file.reg", value_order_test, TODO_REG_COMPARE), "compare_export() failed\n");
361}
362
363static void test_copy_hex_data(void)
364{
365 HKEY hkey;
366 DWORD r;
367
370
371 /* Try copying empty hex values */
373 add_value(hkey, "Wine1a", REG_NONE, NULL, 0);
374 add_value(hkey, "Wine1b", REG_SZ, NULL, 0);
375 add_value(hkey, "Wine1c", REG_EXPAND_SZ, NULL, 0);
376 add_value(hkey, "Wine1d", REG_BINARY, NULL, 0);
377 add_value(hkey, "Wine1e", REG_DWORD, NULL, 0);
378 add_value(hkey, "Wine1f", REG_MULTI_SZ, NULL, 0);
379 add_value(hkey, "Wine1g", 0x100, NULL, 0);
380 add_value(hkey, "Wine1h", 0xabcd, NULL, 0);
381 close_key(hkey);
382
383 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
384 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
386
387 run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
388 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
389 ok(compare_export("file.reg", empty_hex_test, 0), "compare_export() failed\n");
390
393
394 /* Try copying after importing alternative registry data types */
395 test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
396 "[HKEY_CURRENT_USER\\" COPY_SRC "]\n"
397 "\"Wine2a\"=hex(1):\n"
398 "\"Wine2b\"=hex(3):\n"
399 "\"Wine2c\"=hex(4):\n\n", &r);
400 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
401
402 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
403 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
405
406 run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
407 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
408 ok(compare_export("file.reg", empty_hex_test2, 0), "compare_export() failed\n");
409
412
413 /* Try copying more complex hex data */
414 test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
415 "[HKEY_CURRENT_USER\\" COPY_SRC "]\n"
416 "\"Wine3a\"=hex(1):56,00,61,00,6c,00,75,00,65,00,00,00\n"
417 "\"Wine3b\"=hex(3):12,34,56,78\n"
418 "\"Wine3c\"=hex(4):40,30,20,10\n\n", &r);
419 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
420
421 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
422 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
424
425 run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r);
426 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
427 ok(compare_export("file.reg", hex_types_test, 0), "compare_export() failed\n");
428}
429
431{
432 DWORD r;
433
436
437 test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
438 "[HKEY_CURRENT_USER\\" COPY_SRC "]\n"
439 "\"Wine4a\"=dword:00000005\n"
440 "\"Wine4b\"=hex(1):00,00,00,00,00,00,00,00\n"
441 "\"Wine4c\"=\"Value\"\n"
442 "\"Wine4d\"=hex(1):00,00,61,00,62,00,63,00\n"
443 "\"Wine4e\"=dword:00000100\n"
444 "\"Wine4f\"=hex(1):00,00,56,00,61,00,6c,00,75,00,65,00,00,00\n"
445 "\"Wine4g\"=\"Value2\"\n"
446 "\"Wine4h\"=hex(1):61,00,62,00,63,00,00,00, \\\n"
447 " 64,00,65,00,66,00,00,00\n\n", &r);
448 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
449
450 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
451 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
453
454 run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r);
455 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
456 ok(compare_export("file.reg", embedded_null_test, 0), "compare_export() failed\n");
457}
458
459static void test_copy_slashes(void)
460{
461 HKEY hkey;
462 DWORD r;
463
466
468 add_key(hkey, "https://winehq.org", 0, NULL);
469 add_value(hkey, "count/up", REG_SZ, "one/two/three", 14);
470 add_value(hkey, "\\foo\\bar", REG_SZ, "", 1);
471 close_key(hkey);
472
473 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /s /f", &r);
474 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
476
477 run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
478 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
479 ok(compare_export("file.reg", slashes_test, TODO_REG_COMPARE), "compare_export() failed\n");
480}
481
483{
484 HKEY hkey;
485 DWORD r;
486
489
491 add_value(hkey, "Wine5a", REG_SZ, "\\0", 3);
492 add_value(hkey, "Wine5b", REG_SZ, "\\0\\0", 5);
493 add_value(hkey, "Wine5c", REG_SZ, "Value1\\0", 9);
494 add_value(hkey, "Wine5d", REG_SZ, "Value2\\0\\0\\0\\0", 15);
495 add_value(hkey, "Wine5e", REG_SZ, "Value3\\0Value4", 15);
496 add_value(hkey, "Wine5f", REG_SZ, "\\0Value5", 9);
497 close_key(hkey);
498
499 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
500 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
502
503 run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
504 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
505 ok(compare_export("file.reg", escaped_null_test, 0), "compare_export() failed\n");
506
509}
510
511static void test_copy_key_class(void)
512{
513 HKEY hkey;
514 LONG rc;
515 char class[] = "class";
516 char buf[16];
517 DWORD buf_size, r;
518
520 KEY_READ|KEY_WRITE, NULL, &hkey, NULL);
521 ok(rc == ERROR_SUCCESS, "RegCreateKeyExA failed: got %d, expected 0\n", rc);
522
523 add_value(hkey, "String", REG_SZ, "Data", 5);
524
525 buf_size = sizeof(buf);
526
527 rc = RegQueryInfoKeyA(hkey, buf, &buf_size, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
528 ok(rc == ERROR_SUCCESS, "RegQueryInfoKeyA failed: got %d, expected 0\n", rc);
529 ok(!strcmp(buf, "class"), "Incorrect key class set; got '%s', expected '%s'\n", buf, class);
530
531 RegCloseKey(hkey);
532
533 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
534 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
536
538 verify_reg(hkey, "String", REG_SZ, "Data", 5, 0);
539
540 memset(buf, 0, sizeof(buf));
541 buf_size = sizeof(buf);
542
543 rc = RegQueryInfoKeyA(hkey, buf, &buf_size, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
544 ok(rc == ERROR_SUCCESS, "RegQueryInfoKeyA failed: got %d, expected 0\n", rc);
545 ok(strlen(buf) == 0, "Key class should not exist\n");
546
547 RegCloseKey(hkey);
548
551}
552
553static void test_copy_overwrite(void)
554{
555 HKEY hkey;
556 DWORD r, dword;
557
559 add_value(hkey, "Wine1", REG_SZ, "def", 4);
560 dword = 0x5;
561 add_value(hkey, "Wine2", REG_DWORD, &dword, sizeof(dword));
562 add_value(hkey, "Wine3", REG_BINARY, "\x11\x22\x33\x44", 4);
563 add_value(hkey, "Wine4", REG_MULTI_SZ, "Line1\0Line2\0Line3\0", 19);
564 close_key(hkey);
565
567 add_value(hkey, "Wine1", REG_SZ, "abc", 4);
568 verify_reg_nonexist(hkey, "Wine2");
569 add_value(hkey, "Wine3", REG_EXPAND_SZ, "%HOME%\\%PATH%", 14);
570 dword = 0x1;
571 add_value(hkey, "Wine4", REG_DWORD, &dword, sizeof(dword));
572 add_value(hkey, NULL, REG_SZ, "Constant value", 15);
573 close_key(hkey);
574
575 run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
576 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
577
579 verify_reg(hkey, "Wine1", REG_SZ, "def", 4, 0);
580 dword = 0x5;
581 verify_reg(hkey, "Wine2", REG_DWORD, &dword, sizeof(dword), 0);
582 verify_reg(hkey, "Wine3", REG_BINARY, "\x11\x22\x33\x44", 4, 0);
583 verify_reg(hkey, "Wine4", REG_MULTI_SZ, "Line1\0Line2\0Line3\0", 19, 0);
584 verify_reg(hkey, NULL, REG_SZ, "Constant value", 15, 0);
585 close_key(hkey);
586
589}
590
591#if 0
592static void create_test_key(REGSAM sam)
593{
594 HKEY hkey, subkey;
595 DWORD dword = 0x100;
596
598 add_value(hkey, "DWORD", REG_DWORD, &dword, sizeof(dword));
599 add_value(hkey, "String", REG_SZ, "Your text here...", 18);
600
601 add_key(hkey, "Subkey1", sam, &subkey);
602 add_value(subkey, "Binary", REG_BINARY, "\x11\x22\x33\x44", 4);
603 add_value(subkey, "Undefined hex", 0x100, "%PATH%", 7);
604 close_key(subkey);
605
606 close_key(hkey);
607}
608
609static void test_registry_view_win32(void)
610{
611 DWORD r;
612 BOOL is_wow64, is_win32;
613
615 is_win32 = !is_wow64 && (sizeof(void *) == sizeof(int));
616
617 if (!is_win32) return;
618
621
622 /* Try copying registry data in the 32-bit registry view (32-bit Windows) */
623 create_test_key(KEY_WOW64_32KEY);
624
625 run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:32", &r);
626 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
627
628 run_reg_exe("reg export HKLM\\" KEY_BASE " file.reg /y /reg:32", &r);
629 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
630 ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n");
631
634
635 /* Try copying registry data in the 64-bit registry view, which doesn't exist on 32-bit Windows */
636 create_test_key(KEY_WOW64_64KEY);
637
638 run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:64", &r);
639 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
640
641 run_reg_exe("reg export HKLM\\" KEY_BASE " file.reg /y /reg:64", &r);
642 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
643 ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n");
644
647}
648
649static void test_registry_view_win64(void)
650{
651 DWORD r;
653
655 is_win64 = !is_wow64 && (sizeof(void *) > sizeof(int));
656
657 if (!is_win64) return;
658
663
664 /* Try copying registry data in the 32-bit registry view (64-bit Windows) */
665 create_test_key(KEY_WOW64_32KEY);
668
669 run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:32", &r);
670 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
671
672 run_reg_exe("reg export HKLM\\" KEY_BASE " file.reg /y /reg:32", &r);
673 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
674 ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n");
675
676 run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:64", &r);
677 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
678
681
682 /* Try copying registry data in the 64-bit registry view (64-bit Windows) */
683 create_test_key(KEY_WOW64_64KEY);
686
687 run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:64", &r);
688 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
689
690 run_reg_exe("reg export HKLM\\" KEY_BASE " file.reg /y /reg:64", &r);
691 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
692 ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n");
693
694 run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:32", &r);
695 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
696
699}
700
701static void test_registry_view_wow64(void)
702{
703 DWORD r;
705
707
708 if (!is_wow64) return;
709
714
715 /* Try copying registry data in the 32-bit registry view (WOW64) */
716 create_test_key(KEY_WOW64_32KEY);
719
720 run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:32", &r);
721 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
722
723 run_reg_exe("reg export HKLM\\" KEY_BASE " file.reg /y /reg:32", &r);
724 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
725 ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n");
726
727 run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:64", &r);
728 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
729
732
733 /* Try copying registry data in the 64-bit registry view (WOW64) */
734 create_test_key(KEY_WOW64_64KEY);
737
738 run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:64", &r);
739 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
740
741 run_reg_exe("reg export HKLM\\" KEY_BASE " file.reg /y /reg:64", &r);
742 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
743 ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n");
744
745 run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:32", &r);
746 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
747
750}
751#endif
752
754{
755 DWORD r;
756
757 if (!run_reg_exe("reg.exe /?", &r)) {
758 win_skip("reg.exe not available, skipping 'copy' tests\n");
759 return;
760 }
761
774
775 /* Check if reg.exe is running with elevated privileges */
776 if (!is_elevated_process())
777 {
778 win_skip("reg.exe is not running with elevated privileges; "
779 "skipping registry view tests\n");
780 return;
781 }
782
783#if 0
784 test_registry_view_win32();
785 test_registry_view_win64();
786 test_registry_view_wow64();
787#endif
788
789}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
static REGSAM sam
Definition: query.c:143
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
Definition: copy.c:51
#define RegCloseKey(hKey)
Definition: registry.h:47
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
LONG WINAPI RegQueryInfoKeyA(HKEY hKey, LPSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)
Definition: reg.c:3611
LONG WINAPI RegCreateKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD Reserved, _In_ LPSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_ LPDWORD lpdwDisposition)
Definition: reg.c:1029
#define GetCurrentProcess()
Definition: compat.h:759
#define IsWow64Process
Definition: compat.h:760
BOOL is_wow64
Definition: msi.c:54
static const BOOL is_win64
Definition: shellpath.c:59
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define REG_SZ
Definition: layer.c:22
static void test_copy_escaped_null_values(void)
Definition: copy.c:482
static void test_copy_key_class(void)
Definition: copy.c:511
static void test_copy_slashes(void)
Definition: copy.c:459
static void test_copy_hex_data(void)
Definition: copy.c:363
static void test_copy_complex_data(void)
Definition: copy.c:253
static void test_copy_simple_data(void)
Definition: copy.c:186
static void test_copy_key_order(void)
Definition: copy.c:319
static void test_copy_value_order(void)
Definition: copy.c:341
#define COPY_SRC
Definition: copy.c:21
static void test_copy_overwrite(void)
Definition: copy.c:553
static void test_copy_empty_key(void)
Definition: copy.c:125
static void test_command_syntax(void)
Definition: copy.c:23
static void test_copy_embedded_null_values(void)
Definition: copy.c:430
const char * empty_hex_test2
Definition: export.c:125
const char * hex_types_test
Definition: export.c:132
const char * complex_data_test
Definition: export.c:75
const char * escaped_null_test
Definition: export.c:158
const char * key_order_test
Definition: export.c:101
const char * slashes_test
Definition: export.c:151
const char * embedded_null_test
Definition: export.c:139
const char * simple_data_test
Definition: export.c:69
const char * registry_view_test
Definition: export.c:168
const char * value_order_test
Definition: export.c:107
const char * empty_hex_test
Definition: export.c:113
const char * empty_key_test
Definition: export.c:65
BOOL is_elevated_process(void)
Definition: import.c:21
#define REG_BINARY
Definition: nt_native.h:1496
#define KEY_READ
Definition: nt_native.h:1023
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define REG_MULTI_SZ
Definition: nt_native.h:1501
#define KEY_WRITE
Definition: nt_native.h:1031
#define REG_NONE
Definition: nt_native.h:1492
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
long LONG
Definition: pedump.c:60
#define add_value(k, n, t, d, s)
Definition: reg_test.h:70
#define REG_EXIT_FAILURE
Definition: reg_test.h:31
#define compare_export(f, e, todo)
Definition: reg_test.h:78
#define test_import_wstr(c, r)
Definition: reg_test.h:101
#define add_key(r, p, s, k)
Definition: reg_test.h:61
#define verify_reg(k, v, t, d, s, todo)
Definition: reg_test.h:42
#define delete_tree(r, p, s)
Definition: reg_test.h:67
#define open_key(r, p, s, k)
Definition: reg_test.h:49
#define verify_key(r, p, s)
Definition: reg_test.h:55
#define TODO_REG_COMPARE
Definition: reg_test.h:36
#define verify_key_nonexist(r, p, s)
Definition: reg_test.h:58
#define close_key(k)
Definition: reg_test.h:52
#define REG_EXIT_SUCCESS
Definition: reg_test.h:30
#define KEY_BASE
Definition: reg_test.h:29
#define run_reg_exe(c, r)
Definition: reg_test.h:39
#define delete_key(r, p, s)
Definition: reg_test.h:64
#define verify_reg_nonexist(k, v)
Definition: reg_test.h:46
#define REG_DWORD
Definition: sdbapi.c:596
#define win_skip
Definition: test.h:160
#define memset(x, y, z)
Definition: compat.h:39
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define HKEY_CURRENT_USER
Definition: winreg.h:11
ACCESS_MASK REGSAM
Definition: winreg.h:69
#define KEY_WOW64_32KEY
Definition: cmtypes.h:45
#define KEY_WOW64_64KEY
Definition: cmtypes.h:46