xref: /reactos/modules/rostests/winetests/reg/copy.c (revision 1a6f523e)
1295a04dfSwinesync /*
2295a04dfSwinesync  * Copyright 2021 Hugh McMaster
3295a04dfSwinesync  *
4295a04dfSwinesync  * This library is free software; you can redistribute it and/or
5295a04dfSwinesync  * modify it under the terms of the GNU Lesser General Public
6295a04dfSwinesync  * License as published by the Free Software Foundation; either
7295a04dfSwinesync  * version 2.1 of the License, or (at your option) any later version.
8295a04dfSwinesync  *
9295a04dfSwinesync  * This library is distributed in the hope that it will be useful,
10295a04dfSwinesync  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11295a04dfSwinesync  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12295a04dfSwinesync  * Lesser General Public License for more details.
13295a04dfSwinesync  *
14295a04dfSwinesync  * You should have received a copy of the GNU Lesser General Public
15295a04dfSwinesync  * License along with this library; if not, write to the Free Software
16295a04dfSwinesync  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17295a04dfSwinesync  */
18295a04dfSwinesync 
19295a04dfSwinesync #include "reg_test.h"
20295a04dfSwinesync 
211aea6bdfSwinesync #define COPY_SRC  KEY_WINE "\\reg_copy"
22295a04dfSwinesync 
test_command_syntax(void)231aea6bdfSwinesync static void test_command_syntax(void)
24295a04dfSwinesync {
25295a04dfSwinesync     DWORD r;
26295a04dfSwinesync 
27295a04dfSwinesync     run_reg_exe("reg copy", &r);
28295a04dfSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
29295a04dfSwinesync 
30295a04dfSwinesync     run_reg_exe("reg copy /?", &r);
31181292dcSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
32295a04dfSwinesync 
33295a04dfSwinesync     run_reg_exe("reg copy /h", &r);
34181292dcSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
35295a04dfSwinesync 
36295a04dfSwinesync     run_reg_exe("reg copy -H", &r);
37181292dcSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
38295a04dfSwinesync 
39295a04dfSwinesync     run_reg_exe("reg copy /? /f", &r);
4067493a40Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
41295a04dfSwinesync 
42295a04dfSwinesync     run_reg_exe("reg copy /h /f", &r);
4367493a40Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
44295a04dfSwinesync 
45295a04dfSwinesync     run_reg_exe("reg copy /? /s", &r);
4667493a40Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
47295a04dfSwinesync 
48295a04dfSwinesync     run_reg_exe("reg copy /h /s", &r);
4967493a40Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
50295a04dfSwinesync 
51295a04dfSwinesync     run_reg_exe("reg copy /f", &r);
52295a04dfSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
53295a04dfSwinesync 
54295a04dfSwinesync     run_reg_exe("reg copy /s", &r);
55295a04dfSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
56295a04dfSwinesync 
57295a04dfSwinesync     run_reg_exe("reg copy /s /f", &r);
58295a04dfSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
59295a04dfSwinesync 
60295a04dfSwinesync     run_reg_exe("reg copy /f /s", &r);
61295a04dfSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
62295a04dfSwinesync 
631aea6bdfSwinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " /f", &r);
64295a04dfSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
65295a04dfSwinesync 
661aea6bdfSwinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " foo /f", &r);
67295a04dfSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
68295a04dfSwinesync 
691aea6bdfSwinesync     run_reg_exe("reg copy /f HKCU\\" COPY_SRC " HKCU\\" KEY_BASE, &r);
70295a04dfSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
71295a04dfSwinesync 
721aea6bdfSwinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " /f HKCU\\" KEY_BASE, &r);
73295a04dfSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
74295a04dfSwinesync 
751aea6bdfSwinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " /s HKCU\\" KEY_BASE, &r);
76295a04dfSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
77295a04dfSwinesync 
781aea6bdfSwinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /a", &r);
79295a04dfSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
80295a04dfSwinesync 
811aea6bdfSwinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f /a", &r);
82295a04dfSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
83295a04dfSwinesync 
841aea6bdfSwinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\", &r);
85295a04dfSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
86295a04dfSwinesync 
871aea6bdfSwinesync     /* Source and destination keys are the same */
881aea6bdfSwinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" COPY_SRC, &r);
89295a04dfSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
90295a04dfSwinesync 
91f27a0866Swinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" COPY_SRC, &r);
92f27a0866Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
93f27a0866Swinesync 
94f27a0866Swinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" COPY_SRC "\\", &r);
95f27a0866Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
96f27a0866Swinesync 
97f27a0866Swinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" COPY_SRC "\\", &r);
98f27a0866Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
99f27a0866Swinesync 
1001aea6bdfSwinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" COPY_SRC " /f", &r);
101295a04dfSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
102295a04dfSwinesync 
103f27a0866Swinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" COPY_SRC " /f", &r);
104f27a0866Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
105f27a0866Swinesync 
106f27a0866Swinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" COPY_SRC "\\ /f", &r);
107f27a0866Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
108f27a0866Swinesync 
109f27a0866Swinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" COPY_SRC "\\ /f", &r);
110f27a0866Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
111f27a0866Swinesync 
1121aea6bdfSwinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" COPY_SRC " /s /f", &r);
113295a04dfSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
114f27a0866Swinesync 
115f27a0866Swinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" COPY_SRC " /s /f", &r);
116f27a0866Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
117f27a0866Swinesync 
118f27a0866Swinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" COPY_SRC "\\ /s /f", &r);
119f27a0866Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
120f27a0866Swinesync 
121f27a0866Swinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" COPY_SRC "\\ /s /f", &r);
122f27a0866Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
123295a04dfSwinesync }
124295a04dfSwinesync 
test_copy_empty_key(void)125d40c4ec1Swinesync static void test_copy_empty_key(void)
126d40c4ec1Swinesync {
127d40c4ec1Swinesync     DWORD r;
128d40c4ec1Swinesync 
12944c2f0d9Swinesync     delete_tree(HKEY_CURRENT_USER, COPY_SRC, 0);
13044c2f0d9Swinesync     delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0);
131d40c4ec1Swinesync 
13277b2d21eSwinesync     add_key(HKEY_CURRENT_USER, COPY_SRC, 0, NULL);
133d40c4ec1Swinesync 
134d40c4ec1Swinesync 
135d40c4ec1Swinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
136da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
137cd3b6fe7Swinesync     verify_key(HKEY_CURRENT_USER, KEY_BASE, 0);
138d40c4ec1Swinesync 
139d40c4ec1Swinesync     run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg", &r);
140da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
141da2d23fbSwinesync     ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n");
142d40c4ec1Swinesync 
1430ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, KEY_BASE, 0);
144d40c4ec1Swinesync 
145d40c4ec1Swinesync 
146d40c4ec1Swinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" KEY_BASE " /f", &r);
147da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
148cd3b6fe7Swinesync     verify_key(HKEY_CURRENT_USER, KEY_BASE, 0);
149d40c4ec1Swinesync 
150d40c4ec1Swinesync     run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg", &r);
151da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
152da2d23fbSwinesync     ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n");
153d40c4ec1Swinesync 
1540ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, KEY_BASE, 0);
155d40c4ec1Swinesync 
156d40c4ec1Swinesync 
157d40c4ec1Swinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE "\\ /f", &r);
158da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
159cd3b6fe7Swinesync     verify_key(HKEY_CURRENT_USER, KEY_BASE, 0);
160d40c4ec1Swinesync 
161d40c4ec1Swinesync     run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg", &r);
162da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
163da2d23fbSwinesync     ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n");
164d40c4ec1Swinesync 
1650ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, KEY_BASE, 0);
166d40c4ec1Swinesync 
167d40c4ec1Swinesync 
168d40c4ec1Swinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" KEY_BASE "\\ /f", &r);
169da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
170cd3b6fe7Swinesync     verify_key(HKEY_CURRENT_USER, KEY_BASE, 0);
171d40c4ec1Swinesync 
172d40c4ec1Swinesync     run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg", &r);
173da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
174da2d23fbSwinesync     ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n");
175d40c4ec1Swinesync 
176d40c4ec1Swinesync 
177d40c4ec1Swinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /s /f", &r);
178da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
179cd3b6fe7Swinesync     verify_key(HKEY_CURRENT_USER, KEY_BASE, 0);
180d40c4ec1Swinesync 
181d40c4ec1Swinesync     run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg", &r);
182da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
183da2d23fbSwinesync     ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n");
184d40c4ec1Swinesync }
185d40c4ec1Swinesync 
test_copy_simple_data(void)186d40c4ec1Swinesync static void test_copy_simple_data(void)
187d40c4ec1Swinesync {
188d40c4ec1Swinesync     HKEY hkey;
189d40c4ec1Swinesync     DWORD r, dword;
190d40c4ec1Swinesync 
19144c2f0d9Swinesync     delete_tree(HKEY_CURRENT_USER, COPY_SRC, 0);
19244c2f0d9Swinesync     delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0);
193d40c4ec1Swinesync 
19477b2d21eSwinesync     add_key(HKEY_CURRENT_USER, COPY_SRC, 0, &hkey);
195d40c4ec1Swinesync 
196d40c4ec1Swinesync     dword = 0x100;
197d40c4ec1Swinesync     add_value(hkey, "DWORD", REG_DWORD, &dword, sizeof(dword));
198d40c4ec1Swinesync     add_value(hkey, "String", REG_SZ, "Your text here...", 18);
199d40c4ec1Swinesync     close_key(hkey);
200d40c4ec1Swinesync 
201d40c4ec1Swinesync 
202d40c4ec1Swinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
203da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
204cd3b6fe7Swinesync     verify_key(HKEY_CURRENT_USER, KEY_BASE, 0);
205d40c4ec1Swinesync 
206d40c4ec1Swinesync     run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
207da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
208da2d23fbSwinesync     ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n");
209d40c4ec1Swinesync 
2100ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, KEY_BASE, 0);
211d40c4ec1Swinesync 
212d40c4ec1Swinesync 
213d40c4ec1Swinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" KEY_BASE " /f", &r);
214da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
215cd3b6fe7Swinesync     verify_key(HKEY_CURRENT_USER, KEY_BASE, 0);
216d40c4ec1Swinesync 
217d40c4ec1Swinesync     run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
218da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
219da2d23fbSwinesync     ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n");
220d40c4ec1Swinesync 
2210ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, KEY_BASE, 0);
222d40c4ec1Swinesync 
223d40c4ec1Swinesync 
224d40c4ec1Swinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE "\\ /f", &r);
225da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
226cd3b6fe7Swinesync     verify_key(HKEY_CURRENT_USER, KEY_BASE, 0);
227d40c4ec1Swinesync 
228d40c4ec1Swinesync     run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
229da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
230da2d23fbSwinesync     ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n");
231d40c4ec1Swinesync 
2320ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, KEY_BASE, 0);
233d40c4ec1Swinesync 
234d40c4ec1Swinesync 
235d40c4ec1Swinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" KEY_BASE "\\ /f", &r);
236da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
237cd3b6fe7Swinesync     verify_key(HKEY_CURRENT_USER, KEY_BASE, 0);
238d40c4ec1Swinesync 
239d40c4ec1Swinesync     run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
240da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
241da2d23fbSwinesync     ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n");
242d40c4ec1Swinesync 
243d40c4ec1Swinesync 
244d40c4ec1Swinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /s /f", &r);
245da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
246cd3b6fe7Swinesync     verify_key(HKEY_CURRENT_USER, KEY_BASE, 0);
247d40c4ec1Swinesync 
248d40c4ec1Swinesync     run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
249da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
250da2d23fbSwinesync     ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n");
251d40c4ec1Swinesync }
252d40c4ec1Swinesync 
test_copy_complex_data(void)2536ae4684dSwinesync static void test_copy_complex_data(void)
2546ae4684dSwinesync {
2556ae4684dSwinesync     HKEY hkey, subkey;
2566ae4684dSwinesync     DWORD r, dword;
2576ae4684dSwinesync 
25844c2f0d9Swinesync     delete_tree(HKEY_CURRENT_USER, COPY_SRC, 0);
25944c2f0d9Swinesync     delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0);
2606ae4684dSwinesync 
26177b2d21eSwinesync     add_key(HKEY_CURRENT_USER, COPY_SRC, 0, &hkey);
2626ae4684dSwinesync 
2636ae4684dSwinesync     dword = 0x100;
2646ae4684dSwinesync     add_value(hkey, "DWORD", REG_DWORD, &dword, sizeof(dword));
2656ae4684dSwinesync     add_value(hkey, "String", REG_SZ, "Your text here...", 18);
2666ae4684dSwinesync 
26777b2d21eSwinesync     add_key(hkey, "Subkey1", 0, &subkey);
2686ae4684dSwinesync     add_value(subkey, "Binary", REG_BINARY, "\x11\x22\x33\x44", 4);
2696ae4684dSwinesync     add_value(subkey, "Undefined hex", 0x100, "%PATH%", 7);
2706ae4684dSwinesync     close_key(subkey);
2716ae4684dSwinesync 
27277b2d21eSwinesync     add_key(hkey, "Subkey2a", 0, &subkey);
2736ae4684dSwinesync     add_value(subkey, "double\"quote", REG_SZ, "\"Hello, World!\"", 16);
2746ae4684dSwinesync     dword = 0x8;
2756ae4684dSwinesync     add_value(subkey, "single'quote", REG_DWORD, &dword, sizeof(dword));
2766ae4684dSwinesync     close_key(subkey);
2776ae4684dSwinesync 
27877b2d21eSwinesync     add_key(hkey, "Subkey2a\\Subkey2b", 0, &subkey);
2796ae4684dSwinesync     add_value(subkey, NULL, REG_SZ, "Default value name", 19);
2806ae4684dSwinesync     add_value(subkey, "Multiple strings", REG_MULTI_SZ, "Line1\0Line2\0Line3\0", 19);
2816ae4684dSwinesync     close_key(subkey);
2826ae4684dSwinesync 
28377b2d21eSwinesync     add_key(hkey, "Subkey3a", 0, &subkey);
2846ae4684dSwinesync     add_value(subkey, "Backslash", REG_SZ, "Use \\\\ to escape a backslash", 29);
2856ae4684dSwinesync     close_key(subkey);
2866ae4684dSwinesync 
28777b2d21eSwinesync     add_key(hkey, "Subkey3a\\Subkey3b\\Subkey3c", 0, &subkey);
2886ae4684dSwinesync     add_value(subkey, "String expansion", REG_EXPAND_SZ, "%HOME%\\%PATH%", 14);
2896ae4684dSwinesync     add_value(subkey, "Zero data type", REG_NONE, "Value", 6);
2906ae4684dSwinesync     close_key(subkey);
2916ae4684dSwinesync 
29277b2d21eSwinesync     add_key(hkey, "Subkey4", 0, &subkey);
2936ae4684dSwinesync     dword = 0x12345678;
2946ae4684dSwinesync     add_value(subkey, NULL, REG_DWORD, &dword, sizeof(dword));
2956ae4684dSwinesync     add_value(subkey, "43981", 0xabcd, "Value", 6);
2966ae4684dSwinesync     close_key(subkey);
2976ae4684dSwinesync 
2986ae4684dSwinesync     close_key(hkey);
2996ae4684dSwinesync 
3006ae4684dSwinesync     /* Copy values only */
3016ae4684dSwinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
302da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
303cd3b6fe7Swinesync     verify_key(HKEY_CURRENT_USER, KEY_BASE, 0);
3046ae4684dSwinesync 
3056ae4684dSwinesync     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r);
306da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
307da2d23fbSwinesync     ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n");
3086ae4684dSwinesync 
3096ae4684dSwinesync     /* Copy subkeys and values */
3106ae4684dSwinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /s /f", &r);
311da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
312cd3b6fe7Swinesync     verify_key(HKEY_CURRENT_USER, KEY_BASE, 0);
3136ae4684dSwinesync 
3146ae4684dSwinesync     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r);
315da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
316ded0675dSwinesync     ok(compare_export("file.reg", complex_data_test, 0), "compare_export() failed\n");
3176ae4684dSwinesync }
3186ae4684dSwinesync 
test_copy_key_order(void)319552256c1Swinesync static void test_copy_key_order(void)
320552256c1Swinesync {
321552256c1Swinesync     HKEY hkey;
322552256c1Swinesync     DWORD r;
323552256c1Swinesync 
32444c2f0d9Swinesync     delete_tree(HKEY_CURRENT_USER, COPY_SRC, 0);
32544c2f0d9Swinesync     delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0);
326552256c1Swinesync 
32777b2d21eSwinesync     add_key(HKEY_CURRENT_USER, COPY_SRC, 0, &hkey);
32877b2d21eSwinesync     add_key(hkey, "Subkey2", 0, NULL);
32977b2d21eSwinesync     add_key(hkey, "Subkey1", 0, NULL);
330552256c1Swinesync     close_key(hkey);
331552256c1Swinesync 
332552256c1Swinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /s /f", &r);
333da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
334cd3b6fe7Swinesync     verify_key(HKEY_CURRENT_USER, KEY_BASE, 0);
335552256c1Swinesync 
336552256c1Swinesync     run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
337da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
338ded0675dSwinesync     ok(compare_export("file.reg", key_order_test, 0), "compare_export() failed\n");
339552256c1Swinesync }
340552256c1Swinesync 
test_copy_value_order(void)341552256c1Swinesync static void test_copy_value_order(void)
342552256c1Swinesync {
343552256c1Swinesync     HKEY hkey;
344552256c1Swinesync     DWORD r;
345552256c1Swinesync 
34644c2f0d9Swinesync     delete_tree(HKEY_CURRENT_USER, COPY_SRC, 0);
34744c2f0d9Swinesync     delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0);
348552256c1Swinesync 
34977b2d21eSwinesync     add_key(HKEY_CURRENT_USER, COPY_SRC, 0, &hkey);
350552256c1Swinesync     add_value(hkey, "Value 2", REG_SZ, "I was added first!", 19);
351552256c1Swinesync     add_value(hkey, "Value 1", REG_SZ, "I was added second!", 20);
352552256c1Swinesync     close_key(hkey);
353552256c1Swinesync 
354552256c1Swinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
355da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
356cd3b6fe7Swinesync     verify_key(HKEY_CURRENT_USER, KEY_BASE, 0);
357552256c1Swinesync 
358552256c1Swinesync     run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
359da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
360da2d23fbSwinesync     ok(compare_export("file.reg", value_order_test, TODO_REG_COMPARE), "compare_export() failed\n");
361552256c1Swinesync }
362552256c1Swinesync 
test_copy_hex_data(void)3636ae4684dSwinesync static void test_copy_hex_data(void)
3646ae4684dSwinesync {
3656ae4684dSwinesync     HKEY hkey;
3666ae4684dSwinesync     DWORD r;
3676ae4684dSwinesync 
36844c2f0d9Swinesync     delete_tree(HKEY_CURRENT_USER, COPY_SRC, 0);
36944c2f0d9Swinesync     delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0);
3706ae4684dSwinesync 
3716ae4684dSwinesync     /* Try copying empty hex values */
37277b2d21eSwinesync     add_key(HKEY_CURRENT_USER, COPY_SRC, 0, &hkey);
3736ae4684dSwinesync     add_value(hkey, "Wine1a", REG_NONE, NULL, 0);
3746ae4684dSwinesync     add_value(hkey, "Wine1b", REG_SZ, NULL, 0);
3756ae4684dSwinesync     add_value(hkey, "Wine1c", REG_EXPAND_SZ, NULL, 0);
3766ae4684dSwinesync     add_value(hkey, "Wine1d", REG_BINARY, NULL, 0);
3776ae4684dSwinesync     add_value(hkey, "Wine1e", REG_DWORD, NULL, 0);
3786ae4684dSwinesync     add_value(hkey, "Wine1f", REG_MULTI_SZ, NULL, 0);
3796ae4684dSwinesync     add_value(hkey, "Wine1g", 0x100, NULL, 0);
3806ae4684dSwinesync     add_value(hkey, "Wine1h", 0xabcd, NULL, 0);
3816ae4684dSwinesync     close_key(hkey);
3826ae4684dSwinesync 
3836ae4684dSwinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
384da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
385cd3b6fe7Swinesync     verify_key(HKEY_CURRENT_USER, KEY_BASE, 0);
3866ae4684dSwinesync 
3876ae4684dSwinesync     run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
388da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
389da2d23fbSwinesync     ok(compare_export("file.reg", empty_hex_test, 0), "compare_export() failed\n");
3906ae4684dSwinesync 
3910ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, COPY_SRC, 0);
3920ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, KEY_BASE, 0);
3936ae4684dSwinesync 
3946ae4684dSwinesync     /* Try copying after importing alternative registry data types */
3956ae4684dSwinesync     test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3966ae4684dSwinesync                      "[HKEY_CURRENT_USER\\" COPY_SRC "]\n"
3976ae4684dSwinesync                      "\"Wine2a\"=hex(1):\n"
3986ae4684dSwinesync                      "\"Wine2b\"=hex(3):\n"
3996ae4684dSwinesync                      "\"Wine2c\"=hex(4):\n\n", &r);
4006ae4684dSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4016ae4684dSwinesync 
4026ae4684dSwinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
403da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
404cd3b6fe7Swinesync     verify_key(HKEY_CURRENT_USER, KEY_BASE, 0);
4056ae4684dSwinesync 
4066ae4684dSwinesync     run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
407da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
408da2d23fbSwinesync     ok(compare_export("file.reg", empty_hex_test2, 0), "compare_export() failed\n");
4096ae4684dSwinesync 
4100ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, COPY_SRC, 0);
4110ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, KEY_BASE, 0);
4126ae4684dSwinesync 
4136ae4684dSwinesync     /* Try copying more complex hex data */
4146ae4684dSwinesync     test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
4156ae4684dSwinesync                      "[HKEY_CURRENT_USER\\" COPY_SRC "]\n"
4166ae4684dSwinesync                      "\"Wine3a\"=hex(1):56,00,61,00,6c,00,75,00,65,00,00,00\n"
4176ae4684dSwinesync                      "\"Wine3b\"=hex(3):12,34,56,78\n"
4186ae4684dSwinesync                      "\"Wine3c\"=hex(4):40,30,20,10\n\n", &r);
4196ae4684dSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4206ae4684dSwinesync 
4216ae4684dSwinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
422da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
423cd3b6fe7Swinesync     verify_key(HKEY_CURRENT_USER, KEY_BASE, 0);
4246ae4684dSwinesync 
4256ae4684dSwinesync     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r);
426da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
427da2d23fbSwinesync     ok(compare_export("file.reg", hex_types_test, 0), "compare_export() failed\n");
4286ae4684dSwinesync }
4296ae4684dSwinesync 
test_copy_embedded_null_values(void)430927db6beSwinesync static void test_copy_embedded_null_values(void)
431927db6beSwinesync {
432927db6beSwinesync     DWORD r;
433927db6beSwinesync 
43444c2f0d9Swinesync     delete_tree(HKEY_CURRENT_USER, COPY_SRC, 0);
43544c2f0d9Swinesync     delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0);
436927db6beSwinesync 
437927db6beSwinesync     test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
438927db6beSwinesync                      "[HKEY_CURRENT_USER\\" COPY_SRC "]\n"
439927db6beSwinesync                      "\"Wine4a\"=dword:00000005\n"
440927db6beSwinesync                      "\"Wine4b\"=hex(1):00,00,00,00,00,00,00,00\n"
441927db6beSwinesync                      "\"Wine4c\"=\"Value\"\n"
442927db6beSwinesync                      "\"Wine4d\"=hex(1):00,00,61,00,62,00,63,00\n"
443927db6beSwinesync                      "\"Wine4e\"=dword:00000100\n"
444927db6beSwinesync                      "\"Wine4f\"=hex(1):00,00,56,00,61,00,6c,00,75,00,65,00,00,00\n"
445927db6beSwinesync                      "\"Wine4g\"=\"Value2\"\n"
446927db6beSwinesync                      "\"Wine4h\"=hex(1):61,00,62,00,63,00,00,00, \\\n"
447927db6beSwinesync                      "  64,00,65,00,66,00,00,00\n\n", &r);
448927db6beSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
449927db6beSwinesync 
450927db6beSwinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
451da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
452cd3b6fe7Swinesync     verify_key(HKEY_CURRENT_USER, KEY_BASE, 0);
453927db6beSwinesync 
454927db6beSwinesync     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r);
455da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
456da2d23fbSwinesync     ok(compare_export("file.reg", embedded_null_test, 0), "compare_export() failed\n");
457927db6beSwinesync }
458927db6beSwinesync 
test_copy_slashes(void)459927db6beSwinesync static void test_copy_slashes(void)
460927db6beSwinesync {
461927db6beSwinesync     HKEY hkey;
462927db6beSwinesync     DWORD r;
463927db6beSwinesync 
46444c2f0d9Swinesync     delete_tree(HKEY_CURRENT_USER, COPY_SRC, 0);
46544c2f0d9Swinesync     delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0);
466927db6beSwinesync 
46777b2d21eSwinesync     add_key(HKEY_CURRENT_USER, COPY_SRC, 0, &hkey);
46877b2d21eSwinesync     add_key(hkey, "https://winehq.org", 0, NULL);
469927db6beSwinesync     add_value(hkey, "count/up", REG_SZ, "one/two/three", 14);
470927db6beSwinesync     add_value(hkey, "\\foo\\bar", REG_SZ, "", 1);
471927db6beSwinesync     close_key(hkey);
472927db6beSwinesync 
473927db6beSwinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /s /f", &r);
474da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
475cd3b6fe7Swinesync     verify_key(HKEY_CURRENT_USER, KEY_BASE, 0);
476927db6beSwinesync 
477927db6beSwinesync     run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
478da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
479da2d23fbSwinesync     ok(compare_export("file.reg", slashes_test, TODO_REG_COMPARE), "compare_export() failed\n");
480927db6beSwinesync }
481927db6beSwinesync 
test_copy_escaped_null_values(void)482927db6beSwinesync static void test_copy_escaped_null_values(void)
483927db6beSwinesync {
484927db6beSwinesync     HKEY hkey;
485927db6beSwinesync     DWORD r;
486927db6beSwinesync 
48744c2f0d9Swinesync     delete_tree(HKEY_CURRENT_USER, COPY_SRC, 0);
48844c2f0d9Swinesync     delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0);
489927db6beSwinesync 
49077b2d21eSwinesync     add_key(HKEY_CURRENT_USER, COPY_SRC, 0, &hkey);
491927db6beSwinesync     add_value(hkey, "Wine5a", REG_SZ, "\\0", 3);
492927db6beSwinesync     add_value(hkey, "Wine5b", REG_SZ, "\\0\\0", 5);
493927db6beSwinesync     add_value(hkey, "Wine5c", REG_SZ, "Value1\\0", 9);
494927db6beSwinesync     add_value(hkey, "Wine5d", REG_SZ, "Value2\\0\\0\\0\\0", 15);
495927db6beSwinesync     add_value(hkey, "Wine5e", REG_SZ, "Value3\\0Value4", 15);
496927db6beSwinesync     add_value(hkey, "Wine5f", REG_SZ, "\\0Value5", 9);
497927db6beSwinesync     close_key(hkey);
498927db6beSwinesync 
499927db6beSwinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
500da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
501cd3b6fe7Swinesync     verify_key(HKEY_CURRENT_USER, KEY_BASE, 0);
502927db6beSwinesync 
503927db6beSwinesync     run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r);
504da2d23fbSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
505da2d23fbSwinesync     ok(compare_export("file.reg", escaped_null_test, 0), "compare_export() failed\n");
506927db6beSwinesync 
5070ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, COPY_SRC, 0);
5080ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, KEY_BASE, 0);
509927db6beSwinesync }
510927db6beSwinesync 
test_copy_key_class(void)51107427368Swinesync static void test_copy_key_class(void)
51207427368Swinesync {
51307427368Swinesync     HKEY hkey;
51407427368Swinesync     LONG rc;
51507427368Swinesync     char class[] = "class";
51607427368Swinesync     char buf[16];
51707427368Swinesync     DWORD buf_size, r;
51807427368Swinesync 
51907427368Swinesync     rc = RegCreateKeyExA(HKEY_CURRENT_USER, COPY_SRC, 0, class, REG_OPTION_NON_VOLATILE,
52007427368Swinesync                          KEY_READ|KEY_WRITE, NULL, &hkey, NULL);
52107427368Swinesync     ok(rc == ERROR_SUCCESS, "RegCreateKeyExA failed: got %d, expected 0\n", rc);
52207427368Swinesync 
52307427368Swinesync     add_value(hkey, "String", REG_SZ, "Data", 5);
52407427368Swinesync 
52507427368Swinesync     buf_size = sizeof(buf);
52607427368Swinesync 
52707427368Swinesync     rc = RegQueryInfoKeyA(hkey, buf, &buf_size, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
52807427368Swinesync     ok(rc == ERROR_SUCCESS, "RegQueryInfoKeyA failed: got %d, expected 0\n", rc);
52907427368Swinesync     ok(!strcmp(buf, "class"), "Incorrect key class set; got '%s', expected '%s'\n", buf, class);
53007427368Swinesync 
53107427368Swinesync     RegCloseKey(hkey);
53207427368Swinesync 
53307427368Swinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
53407427368Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
535cd3b6fe7Swinesync     verify_key(HKEY_CURRENT_USER, KEY_BASE, 0);
53607427368Swinesync 
53707427368Swinesync     open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
53807427368Swinesync     verify_reg(hkey, "String", REG_SZ, "Data", 5, 0);
53907427368Swinesync 
54007427368Swinesync     memset(buf, 0, sizeof(buf));
54107427368Swinesync     buf_size = sizeof(buf);
54207427368Swinesync 
54307427368Swinesync     rc = RegQueryInfoKeyA(hkey, buf, &buf_size, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
54407427368Swinesync     ok(rc == ERROR_SUCCESS, "RegQueryInfoKeyA failed: got %d, expected 0\n", rc);
54507427368Swinesync     ok(strlen(buf) == 0, "Key class should not exist\n");
54607427368Swinesync 
54707427368Swinesync     RegCloseKey(hkey);
54807427368Swinesync 
5490ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, COPY_SRC, 0);
5500ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, KEY_BASE, 0);
55107427368Swinesync }
55207427368Swinesync 
test_copy_overwrite(void)5539ad9ae45Swinesync static void test_copy_overwrite(void)
5549ad9ae45Swinesync {
5559ad9ae45Swinesync     HKEY hkey;
5569ad9ae45Swinesync     DWORD r, dword;
5579ad9ae45Swinesync 
55877b2d21eSwinesync     add_key(HKEY_CURRENT_USER, COPY_SRC, 0, &hkey);
5599ad9ae45Swinesync     add_value(hkey, "Wine1", REG_SZ, "def", 4);
5609ad9ae45Swinesync     dword = 0x5;
5619ad9ae45Swinesync     add_value(hkey, "Wine2", REG_DWORD, &dword, sizeof(dword));
5629ad9ae45Swinesync     add_value(hkey, "Wine3", REG_BINARY, "\x11\x22\x33\x44", 4);
5639ad9ae45Swinesync     add_value(hkey, "Wine4", REG_MULTI_SZ, "Line1\0Line2\0Line3\0", 19);
5649ad9ae45Swinesync     close_key(hkey);
5659ad9ae45Swinesync 
56677b2d21eSwinesync     add_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
5679ad9ae45Swinesync     add_value(hkey, "Wine1", REG_SZ, "abc", 4);
5689ad9ae45Swinesync     verify_reg_nonexist(hkey, "Wine2");
5699ad9ae45Swinesync     add_value(hkey, "Wine3", REG_EXPAND_SZ, "%HOME%\\%PATH%", 14);
5709ad9ae45Swinesync     dword = 0x1;
5719ad9ae45Swinesync     add_value(hkey, "Wine4", REG_DWORD, &dword, sizeof(dword));
5729ad9ae45Swinesync     add_value(hkey, NULL, REG_SZ, "Constant value", 15);
5739ad9ae45Swinesync     close_key(hkey);
5749ad9ae45Swinesync 
5759ad9ae45Swinesync     run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r);
5769ad9ae45Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
5779ad9ae45Swinesync 
5789ad9ae45Swinesync     open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
5799ad9ae45Swinesync     verify_reg(hkey, "Wine1", REG_SZ, "def", 4, 0);
5809ad9ae45Swinesync     dword = 0x5;
5819ad9ae45Swinesync     verify_reg(hkey, "Wine2", REG_DWORD, &dword, sizeof(dword), 0);
5829ad9ae45Swinesync     verify_reg(hkey, "Wine3", REG_BINARY, "\x11\x22\x33\x44", 4, 0);
5839ad9ae45Swinesync     verify_reg(hkey, "Wine4", REG_MULTI_SZ, "Line1\0Line2\0Line3\0", 19, 0);
5849ad9ae45Swinesync     verify_reg(hkey, NULL, REG_SZ, "Constant value", 15, 0);
5859ad9ae45Swinesync     close_key(hkey);
5869ad9ae45Swinesync 
5870ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, COPY_SRC, 0);
5880ea0084cSwinesync     delete_key(HKEY_CURRENT_USER, KEY_BASE, 0);
5899ad9ae45Swinesync }
5909ad9ae45Swinesync 
591*1a6f523eSThomas Csovcsity #if 0
592be726bd7Swinesync static void create_test_key(REGSAM sam)
593be726bd7Swinesync {
594be726bd7Swinesync     HKEY hkey, subkey;
595be726bd7Swinesync     DWORD dword = 0x100;
596be726bd7Swinesync 
597be726bd7Swinesync     add_key(HKEY_LOCAL_MACHINE, COPY_SRC, sam, &hkey);
598be726bd7Swinesync     add_value(hkey, "DWORD", REG_DWORD, &dword, sizeof(dword));
599be726bd7Swinesync     add_value(hkey, "String", REG_SZ, "Your text here...", 18);
600be726bd7Swinesync 
601be726bd7Swinesync     add_key(hkey, "Subkey1", sam, &subkey);
602be726bd7Swinesync     add_value(subkey, "Binary", REG_BINARY, "\x11\x22\x33\x44", 4);
603be726bd7Swinesync     add_value(subkey, "Undefined hex", 0x100, "%PATH%", 7);
604be726bd7Swinesync     close_key(subkey);
605be726bd7Swinesync 
606be726bd7Swinesync     close_key(hkey);
607be726bd7Swinesync }
608be726bd7Swinesync 
609be726bd7Swinesync static void test_registry_view_win32(void)
610be726bd7Swinesync {
611be726bd7Swinesync     DWORD r;
612be726bd7Swinesync     BOOL is_wow64, is_win32;
613be726bd7Swinesync 
614be726bd7Swinesync     IsWow64Process(GetCurrentProcess(), &is_wow64);
615be726bd7Swinesync     is_win32 = !is_wow64 && (sizeof(void *) == sizeof(int));
616be726bd7Swinesync 
617be726bd7Swinesync     if (!is_win32) return;
618be726bd7Swinesync 
619be726bd7Swinesync     delete_tree(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_32KEY);
620be726bd7Swinesync     delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY);
621be726bd7Swinesync 
622be726bd7Swinesync     /* Try copying registry data in the 32-bit registry view (32-bit Windows) */
623be726bd7Swinesync     create_test_key(KEY_WOW64_32KEY);
624be726bd7Swinesync 
625be726bd7Swinesync     run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:32", &r);
626be726bd7Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
627be726bd7Swinesync 
628be726bd7Swinesync     run_reg_exe("reg export HKLM\\" KEY_BASE " file.reg /y /reg:32", &r);
629be726bd7Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
630be726bd7Swinesync     ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n");
631be726bd7Swinesync 
632be726bd7Swinesync     delete_tree(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_32KEY);
633be726bd7Swinesync     delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY);
634be726bd7Swinesync 
635be726bd7Swinesync     /* Try copying registry data in the 64-bit registry view, which doesn't exist on 32-bit Windows */
636be726bd7Swinesync     create_test_key(KEY_WOW64_64KEY);
637be726bd7Swinesync 
638be726bd7Swinesync     run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:64", &r);
639be726bd7Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
640be726bd7Swinesync 
641be726bd7Swinesync     run_reg_exe("reg export HKLM\\" KEY_BASE " file.reg /y /reg:64", &r);
642be726bd7Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
643be726bd7Swinesync     ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n");
644be726bd7Swinesync 
645be726bd7Swinesync     delete_tree(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_64KEY);
646be726bd7Swinesync     delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY);
647be726bd7Swinesync }
648be726bd7Swinesync 
649be726bd7Swinesync static void test_registry_view_win64(void)
650be726bd7Swinesync {
651be726bd7Swinesync     DWORD r;
652be726bd7Swinesync     BOOL is_wow64, is_win64;
653be726bd7Swinesync 
654be726bd7Swinesync     IsWow64Process(GetCurrentProcess(), &is_wow64);
655be726bd7Swinesync     is_win64 = !is_wow64 && (sizeof(void *) > sizeof(int));
656be726bd7Swinesync 
657be726bd7Swinesync     if (!is_win64) return;
658be726bd7Swinesync 
659be726bd7Swinesync     delete_tree(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_32KEY);
660be726bd7Swinesync     delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY);
661be726bd7Swinesync     delete_tree(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_64KEY);
662be726bd7Swinesync     delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY);
663be726bd7Swinesync 
664be726bd7Swinesync     /* Try copying registry data in the 32-bit registry view (64-bit Windows) */
665be726bd7Swinesync     create_test_key(KEY_WOW64_32KEY);
666be726bd7Swinesync     verify_key_nonexist(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_64KEY);
667be726bd7Swinesync     verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY);
668be726bd7Swinesync 
669be726bd7Swinesync     run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:32", &r);
67029992c17Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
671be726bd7Swinesync 
672be726bd7Swinesync     run_reg_exe("reg export HKLM\\" KEY_BASE " file.reg /y /reg:32", &r);
67329992c17Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
67429992c17Swinesync     ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n");
675be726bd7Swinesync 
676be726bd7Swinesync     run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:64", &r);
677be726bd7Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
678be726bd7Swinesync 
679be726bd7Swinesync     delete_tree(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_32KEY);
680be726bd7Swinesync     delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY);
681be726bd7Swinesync 
682be726bd7Swinesync     /* Try copying registry data in the 64-bit registry view (64-bit Windows) */
683be726bd7Swinesync     create_test_key(KEY_WOW64_64KEY);
684be726bd7Swinesync     verify_key_nonexist(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_32KEY);
685be726bd7Swinesync     verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY);
686be726bd7Swinesync 
687be726bd7Swinesync     run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:64", &r);
688be726bd7Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
689be726bd7Swinesync 
690be726bd7Swinesync     run_reg_exe("reg export HKLM\\" KEY_BASE " file.reg /y /reg:64", &r);
691be726bd7Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
692be726bd7Swinesync     ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n");
693be726bd7Swinesync 
694be726bd7Swinesync     run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:32", &r);
69529992c17Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
696be726bd7Swinesync 
697be726bd7Swinesync     delete_tree(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_64KEY);
698be726bd7Swinesync     delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY);
699be726bd7Swinesync }
700be726bd7Swinesync 
701be726bd7Swinesync static void test_registry_view_wow64(void)
702be726bd7Swinesync {
703be726bd7Swinesync     DWORD r;
704be726bd7Swinesync     BOOL is_wow64;
705be726bd7Swinesync 
706be726bd7Swinesync     IsWow64Process(GetCurrentProcess(), &is_wow64);
707be726bd7Swinesync 
708be726bd7Swinesync     if (!is_wow64) return;
709be726bd7Swinesync 
710be726bd7Swinesync     delete_tree(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_32KEY);
711be726bd7Swinesync     delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY);
712be726bd7Swinesync     delete_tree(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_64KEY);
713be726bd7Swinesync     delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY);
714be726bd7Swinesync 
715be726bd7Swinesync     /* Try copying registry data in the 32-bit registry view (WOW64) */
716be726bd7Swinesync     create_test_key(KEY_WOW64_32KEY);
717be726bd7Swinesync     verify_key_nonexist(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_64KEY);
718be726bd7Swinesync     verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY);
719be726bd7Swinesync 
720be726bd7Swinesync     run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:32", &r);
721be726bd7Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
722be726bd7Swinesync 
723be726bd7Swinesync     run_reg_exe("reg export HKLM\\" KEY_BASE " file.reg /y /reg:32", &r);
724be726bd7Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
725be726bd7Swinesync     ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n");
726be726bd7Swinesync 
727be726bd7Swinesync     run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:64", &r);
72829992c17Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
729be726bd7Swinesync 
730be726bd7Swinesync     delete_tree(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_32KEY);
731be726bd7Swinesync     delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY);
732be726bd7Swinesync 
733be726bd7Swinesync     /* Try copying registry data in the 64-bit registry view (WOW64) */
734be726bd7Swinesync     create_test_key(KEY_WOW64_64KEY);
735be726bd7Swinesync     verify_key_nonexist(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_32KEY);
736be726bd7Swinesync     verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY);
737be726bd7Swinesync 
738be726bd7Swinesync     run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:64", &r);
73929992c17Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
740be726bd7Swinesync 
741be726bd7Swinesync     run_reg_exe("reg export HKLM\\" KEY_BASE " file.reg /y /reg:64", &r);
74229992c17Swinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
74329992c17Swinesync     ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n");
744be726bd7Swinesync 
745be726bd7Swinesync     run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:32", &r);
746be726bd7Swinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
747be726bd7Swinesync 
748be726bd7Swinesync     delete_tree(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_64KEY);
749be726bd7Swinesync     delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY);
750be726bd7Swinesync }
751*1a6f523eSThomas Csovcsity #endif
752be726bd7Swinesync 
START_TEST(copy)753295a04dfSwinesync START_TEST(copy)
754295a04dfSwinesync {
755295a04dfSwinesync     DWORD r;
756295a04dfSwinesync 
757295a04dfSwinesync     if (!run_reg_exe("reg.exe /?", &r)) {
7582161165dSwinesync         win_skip("reg.exe not available, skipping 'copy' tests\n");
759295a04dfSwinesync         return;
760295a04dfSwinesync     }
761295a04dfSwinesync 
7621aea6bdfSwinesync     test_command_syntax();
763d40c4ec1Swinesync     test_copy_empty_key();
764d40c4ec1Swinesync     test_copy_simple_data();
7656ae4684dSwinesync     test_copy_complex_data();
766552256c1Swinesync     test_copy_key_order();
767552256c1Swinesync     test_copy_value_order();
7686ae4684dSwinesync     test_copy_hex_data();
769927db6beSwinesync     test_copy_embedded_null_values();
770927db6beSwinesync     test_copy_slashes();
771927db6beSwinesync     test_copy_escaped_null_values();
77207427368Swinesync     test_copy_key_class();
7739ad9ae45Swinesync     test_copy_overwrite();
774be726bd7Swinesync 
775be726bd7Swinesync     /* Check if reg.exe is running with elevated privileges */
776be726bd7Swinesync     if (!is_elevated_process())
777be726bd7Swinesync     {
778be726bd7Swinesync         win_skip("reg.exe is not running with elevated privileges; "
779be726bd7Swinesync                  "skipping registry view tests\n");
780be726bd7Swinesync         return;
781be726bd7Swinesync     }
782be726bd7Swinesync 
783*1a6f523eSThomas Csovcsity #if 0
784be726bd7Swinesync     test_registry_view_win32();
785be726bd7Swinesync     test_registry_view_win64();
786be726bd7Swinesync     test_registry_view_wow64();
787*1a6f523eSThomas Csovcsity #endif
788*1a6f523eSThomas Csovcsity 
789295a04dfSwinesync }
790