1 /*
2  * Copyright 2017-2018, 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 compare_export(f,e,todo) compare_export_(__FILE__,__LINE__,f,e,todo)
22 static BOOL compare_export_(const char *file, unsigned line, const char *filename,
23                             const char *expected, DWORD todo)
24 {
25     FILE *fp;
26     long file_size;
27     WCHAR *fbuf = NULL, *wstr = NULL;
28     size_t len;
29     BOOL ret = FALSE;
30 
31     fp = fopen(filename, "rb");
32     if (!fp) return FALSE;
33 
34     if (fseek(fp, 0, SEEK_END)) goto error;
35     file_size = ftell(fp);
36     if (file_size == -1) goto error;
37     rewind(fp);
38 
39     fbuf = HeapAlloc(GetProcessHeap(), 0, file_size + sizeof(WCHAR));
40     if (!fbuf) goto error;
41 
42     fread(fbuf, file_size, 1, fp);
43     fbuf[file_size/sizeof(WCHAR)] = 0;
44     fclose(fp);
45 
46     len = MultiByteToWideChar(CP_UTF8, 0, expected, -1, NULL, 0);
47     wstr = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
48     if (!wstr) goto exit;
49     MultiByteToWideChar(CP_UTF8, 0, expected, -1, wstr, len);
50 
51     todo_wine_if (todo & TODO_REG_COMPARE)
52         lok(!lstrcmpW(fbuf, wstr), "export data does not match expected data\n");
53 
54     ret = DeleteFileA(filename);
55     lok(ret, "DeleteFile failed: %u\n", GetLastError());
56 
57 exit:
58     HeapFree(GetProcessHeap(), 0, fbuf);
59     HeapFree(GetProcessHeap(), 0, wstr);
60     return ret;
61 
62 error:
63     fclose(fp);
64     return FALSE;
65 }
66 
67 /* Unit tests */
68 
69 static void test_export(void)
70 {
71     LONG err;
72     DWORD r, dword, type, size;
73     HKEY hkey, subkey;
74     BYTE hex[4], buffer[8];
75 
76     const char *empty_key_test =
77         "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
78         "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n\r\n";
79 
80     const char *simple_test =
81         "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
82         "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
83         "\"DWORD\"=dword:00000100\r\n"
84         "\"String\"=\"Your text here...\"\r\n\r\n";
85 
86     const char *complex_test =
87         "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
88         "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
89         "\"DWORD\"=dword:00000100\r\n"
90         "\"String\"=\"Your text here...\"\r\n\r\n"
91         "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1]\r\n"
92         "\"Binary\"=hex:11,22,33,44\r\n"
93         "\"Undefined hex\"=hex(100):25,50,41,54,48,25,00\r\n\r\n"
94         "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a]\r\n"
95         "\"double\\\"quote\"=\"\\\"Hello, World!\\\"\"\r\n"
96         "\"single'quote\"=dword:00000008\r\n\r\n"
97         "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a\\Subkey2b]\r\n"
98         "@=\"Default value name\"\r\n"
99         "\"Multiple strings\"=hex(7):4c,00,69,00,6e,00,65,00,31,00,00,00,4c,00,69,00,6e,\\\r\n"
100         "  00,65,00,32,00,00,00,4c,00,69,00,6e,00,65,00,33,00,00,00,00,00\r\n\r\n"
101         "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey3a]\r\n"
102         "\"Backslash\"=\"Use \\\\\\\\ to escape a backslash\"\r\n\r\n"
103         "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey3a\\Subkey3b]\r\n\r\n"
104         "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey3a\\Subkey3b\\Subkey3c]\r\n"
105         "\"String expansion\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00,25,00,50,\\\r\n"
106         "  00,41,00,54,00,48,00,25,00,00,00\r\n"
107         "\"Zero data type\"=hex(0):56,61,6c,75,65,00\r\n\r\n"
108         "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey4]\r\n"
109         "@=dword:12345678\r\n"
110         "\"43981\"=hex(abcd):56,61,6c,75,65,00\r\n\r\n";
111 
112     const char *key_order_test =
113         "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
114         "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n\r\n"
115         "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1]\r\n\r\n"
116         "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2]\r\n\r\n";
117 
118     const char *value_order_test =
119         "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
120         "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
121         "\"Value 2\"=\"I was added first!\"\r\n"
122         "\"Value 1\"=\"I was added second!\"\r\n\r\n";
123 
124     const char *empty_hex_test =
125         "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
126         "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
127         "\"Wine1a\"=hex(0):\r\n"
128         "\"Wine1b\"=\"\"\r\n"
129         "\"Wine1c\"=hex(2):\r\n"
130         "\"Wine1d\"=hex:\r\n"
131         "\"Wine1e\"=hex(4):\r\n"
132         "\"Wine1f\"=hex(7):\r\n"
133         "\"Wine1g\"=hex(100):\r\n"
134         "\"Wine1h\"=hex(abcd):\r\n\r\n";
135 
136     const char *empty_hex_test2 =
137         "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
138         "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
139         "\"Wine2a\"=\"\"\r\n"
140         "\"Wine2b\"=hex:\r\n"
141         "\"Wine2c\"=hex(4):\r\n\r\n";
142 
143     const char *hex_types_test =
144         "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
145         "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
146         "\"Wine3a\"=\"Value\"\r\n"
147         "\"Wine3b\"=hex:12,34,56,78\r\n"
148         "\"Wine3c\"=dword:10203040\r\n\r\n";
149 
150     const char *embedded_null_test =
151         "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
152         "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
153         "\"Wine4a\"=dword:00000005\r\n"
154         "\"Wine4b\"=\"\"\r\n"
155         "\"Wine4c\"=\"Value\"\r\n"
156         "\"Wine4d\"=\"\"\r\n"
157         "\"Wine4e\"=dword:00000100\r\n"
158         "\"Wine4f\"=\"\"\r\n"
159         "\"Wine4g\"=\"Value2\"\r\n"
160         "\"Wine4h\"=\"abc\"\r\n\r\n";
161 
162     const char *slashes_test =
163         "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
164         "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
165         "\"count/up\"=\"one/two/three\"\r\n"
166         "\"\\\\foo\\\\bar\"=\"\"\r\n\r\n"
167         "[HKEY_CURRENT_USER\\" KEY_BASE "\\https://winehq.org]\r\n\r\n";
168 
169     const char *escaped_null_test =
170         "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
171         "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
172         "\"Wine5a\"=\"\\\\0\"\r\n"
173         "\"Wine5b\"=\"\\\\0\\\\0\"\r\n"
174         "\"Wine5c\"=\"Value1\\\\0\"\r\n"
175         "\"Wine5d\"=\"Value2\\\\0\\\\0\\\\0\\\\0\"\r\n"
176         "\"Wine5e\"=\"Value3\\\\0Value4\"\r\n"
177         "\"Wine5f\"=\"\\\\0Value5\"\r\n\r\n";
178 
179     delete_tree(HKEY_CURRENT_USER, KEY_BASE);
180     verify_key_nonexist(HKEY_CURRENT_USER, KEY_BASE);
181 
182     run_reg_exe("reg export", &r);
183     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
184 
185     run_reg_exe("reg export /?", &r);
186     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
187 
188     run_reg_exe("reg export /h", &r);
189     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
190 
191     run_reg_exe("reg export -H", &r);
192     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
193 
194     run_reg_exe("reg export \\\\remote-pc\\HKLM\\Wine file.reg", &r);
195     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
196 
197     run_reg_exe("reg export HKEY_DYN_DATA file.reg", &r);
198     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
199 
200     run_reg_exe("reg export HKDD file.reg", &r);
201     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
202 
203     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE, &r);
204     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
205 
206     run_reg_exe("reg export file.reg", &r);
207     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
208 
209     run_reg_exe("reg export file.reg HKEY_CURRENT_USER\\" KEY_BASE, &r);
210     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
211 
212     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE, &r);
213     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
214 
215     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg", &r);
216     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
217 
218     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg file2.reg", &r);
219     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
220 
221     /* Test registry export with an empty key */
222     add_key(HKEY_CURRENT_USER, KEY_BASE, &hkey);
223 
224     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg", &r);
225     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
226     ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n");
227 
228     run_reg_exe("reg export /y HKEY_CURRENT_USER\\" KEY_BASE " file.reg", &r);
229     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
230 
231     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " /y file.reg", &r);
232     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
233 
234     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r);
235     ok(r == REG_EXIT_SUCCESS || broken(r == REG_EXIT_FAILURE), /* winxp */
236        "got exit code %d, expected 0\n", r);
237     ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n");
238 
239     /* Test registry export with a simple data structure */
240     dword = 0x100;
241     add_value(hkey, "DWORD", REG_DWORD, &dword, sizeof(dword));
242     add_value(hkey, "String", REG_SZ, "Your text here...", 18);
243 
244     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r);
245     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
246     ok(compare_export("file.reg", simple_test, 0), "compare_export() failed\n");
247 
248     /* Test whether a .reg file extension is required when exporting */
249     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " foo /y", &r);
250     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
251     ok(compare_export("foo", simple_test, 0), "compare_export() failed\n");
252 
253     /* Test registry export with a complex data structure */
254     add_key(hkey, "Subkey1", &subkey);
255     add_value(subkey, "Binary", REG_BINARY, "\x11\x22\x33\x44", 4);
256     add_value(subkey, "Undefined hex", 0x100, "%PATH%", 7);
257     close_key(subkey);
258 
259     add_key(hkey, "Subkey2a", &subkey);
260     add_value(subkey, "double\"quote", REG_SZ, "\"Hello, World!\"", 16);
261     dword = 0x8;
262     add_value(subkey, "single'quote", REG_DWORD, &dword, sizeof(dword));
263     close_key(subkey);
264 
265     add_key(hkey, "Subkey2a\\Subkey2b", &subkey);
266     add_value(subkey, NULL, REG_SZ, "Default value name", 19);
267     add_value(subkey, "Multiple strings", REG_MULTI_SZ, "Line1\0Line2\0Line3\0", 19);
268     close_key(subkey);
269 
270     add_key(hkey, "Subkey3a", &subkey);
271     add_value(subkey, "Backslash", REG_SZ, "Use \\\\ to escape a backslash", 29);
272     close_key(subkey);
273 
274     add_key(hkey, "Subkey3a\\Subkey3b\\Subkey3c", &subkey);
275     add_value(subkey, "String expansion", REG_EXPAND_SZ, "%HOME%\\%PATH%", 14);
276     add_value(subkey, "Zero data type", REG_NONE, "Value", 6);
277     close_key(subkey);
278 
279     add_key(hkey, "Subkey4", &subkey);
280     dword = 0x12345678;
281     add_value(subkey, NULL, REG_DWORD, &dword, sizeof(dword));
282     add_value(subkey, "43981", 0xabcd, "Value", 6);
283     close_key(subkey);
284 
285     close_key(hkey);
286 
287     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r);
288     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
289     ok(compare_export("file.reg", complex_test, 0), "compare_export() failed\n");
290     delete_tree(HKEY_CURRENT_USER, KEY_BASE);
291 
292     /* Test the export order of registry keys */
293     add_key(HKEY_CURRENT_USER, KEY_BASE, &hkey);
294     add_key(hkey, "Subkey2", NULL);
295     add_key(hkey, "Subkey1", NULL);
296 
297     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r);
298     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
299     ok(compare_export("file.reg", key_order_test, 0), "compare_export() failed\n");
300     delete_key(hkey, "Subkey1");
301     delete_key(hkey, "Subkey2");
302 
303     /* Test the export order of registry values. Windows exports registry values
304      * in order of creation; Wine uses alphabetical order.
305      */
306     add_value(hkey, "Value 2", REG_SZ, "I was added first!", 19);
307     add_value(hkey, "Value 1", REG_SZ, "I was added second!", 20);
308     close_key(hkey);
309 
310     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r);
311     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
312     ok(compare_export("file.reg", value_order_test, TODO_REG_COMPARE), "compare_export() failed\n");
313     delete_key(HKEY_CURRENT_USER, KEY_BASE);
314 
315     /* Test registry export with empty hex data */
316     add_key(HKEY_CURRENT_USER, KEY_BASE, &hkey);
317     add_value(hkey, "Wine1a", REG_NONE, NULL, 0);
318     add_value(hkey, "Wine1b", REG_SZ, NULL, 0);
319     add_value(hkey, "Wine1c", REG_EXPAND_SZ, NULL, 0);
320     add_value(hkey, "Wine1d", REG_BINARY, NULL, 0);
321     add_value(hkey, "Wine1e", REG_DWORD, NULL, 0);
322     add_value(hkey, "Wine1f", REG_MULTI_SZ, NULL, 0);
323     add_value(hkey, "Wine1g", 0x100, NULL, 0);
324     add_value(hkey, "Wine1h", 0xabcd, NULL, 0);
325     close_key(hkey);
326 
327     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r);
328     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
329     ok(compare_export("file.reg", empty_hex_test, 0), "compare_export() failed\n");
330     delete_key(HKEY_CURRENT_USER, KEY_BASE);
331 
332     /* Test registry export after importing alternative registry data types */
333     test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
334                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
335                      "\"Wine2a\"=hex(1):\n"
336                      "\"Wine2b\"=hex(3):\n"
337                      "\"Wine2c\"=hex(4):\n\n", &r);
338     open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
339     verify_reg(hkey, "Wine2a", REG_SZ, NULL, 0, 0);
340     verify_reg(hkey, "Wine2b", REG_BINARY, NULL, 0, 0);
341     verify_reg(hkey, "Wine2c", REG_DWORD, NULL, 0, 0);
342     close_key(hkey);
343 
344     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r);
345     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
346     ok(compare_export("file.reg", empty_hex_test2, 0), "compare_export() failed\n");
347     delete_key(HKEY_CURRENT_USER, KEY_BASE);
348 
349     test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
350                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
351                      "\"Wine3a\"=hex(1):56,00,61,00,6c,00,75,00,65,00,00,00\n"
352                      "\"Wine3b\"=hex(3):12,34,56,78\n"
353                      "\"Wine3c\"=hex(4):40,30,20,10\n\n", &r);
354     open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
355     verify_reg(hkey, "Wine3a", REG_SZ, "Value", 6, 0);
356     memcpy(hex, "\x12\x34\x56\x78", 4);
357     verify_reg(hkey, "Wine3b", REG_BINARY, hex, 4, 0);
358     dword = 0x10203040;
359     verify_reg(hkey, "Wine3c", REG_DWORD, &dword, sizeof(dword), 0);
360     close_key(hkey);
361 
362     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r);
363     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
364     ok(compare_export("file.reg", hex_types_test, 0), "compare_export() failed\n");
365     delete_key(HKEY_CURRENT_USER, KEY_BASE);
366 
367     /* Test registry export with embedded null characters */
368     test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
369                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
370                      "\"Wine4a\"=dword:00000005\n"
371                      "\"Wine4b\"=hex(1):00,00,00,00,00,00,00,00\n"
372                      "\"Wine4c\"=\"Value\"\n"
373                      "\"Wine4d\"=hex(1):00,00,61,00,62,00,63,00\n"
374                      "\"Wine4e\"=dword:00000100\n"
375                      "\"Wine4f\"=hex(1):00,00,56,00,61,00,6c,00,75,00,65,00,00,00\n"
376                      "\"Wine4g\"=\"Value2\"\n"
377                      "\"Wine4h\"=hex(1):61,00,62,00,63,00,00,00, \\\n"
378                      "  64,00,65,00,66,00,00,00\n\n", &r);
379     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
380     open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
381     dword = 0x5;
382     verify_reg(hkey, "Wine4a", REG_DWORD, &dword, sizeof(dword), 0);
383     verify_reg(hkey, "Wine4b", REG_SZ, "\0\0\0\0\0\0\0", 4, 0);
384     verify_reg(hkey, "Wine4c", REG_SZ, "Value", 6, 0);
385     /* Wine4d */
386     size = sizeof(buffer);
387     err = RegQueryValueExA(hkey, "Wine4d", NULL, &type, (BYTE *)&buffer, &size);
388     ok(err == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", err);
389     ok(type == REG_SZ, "got wrong type %u, expected %u\n", type, REG_SZ);
390     ok(size == 5 || broken(size == 4) /* WinXP */, "got wrong size %u, expected 5\n", size);
391     ok(memcmp(buffer, "\0abc", size) == 0, "got wrong data\n");
392     dword = 0x100;
393     verify_reg(hkey, "Wine4e", REG_DWORD, &dword, sizeof(dword), 0);
394     verify_reg(hkey, "Wine4f", REG_SZ, "\0Value", 7, 0);
395     verify_reg(hkey, "Wine4g", REG_SZ, "Value2", 7, 0);
396     verify_reg(hkey, "Wine4h", REG_SZ, "abc\0def", 8, 0);
397     close_key(hkey);
398 
399     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r);
400     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
401     ok(compare_export("file.reg", embedded_null_test, 0), "compare_export() failed\n");
402     delete_key(HKEY_CURRENT_USER, KEY_BASE);
403 
404     /* Test registry export with forward and back slashes */
405     add_key(HKEY_CURRENT_USER, KEY_BASE, &hkey);
406     add_key(hkey, "https://winehq.org", NULL);
407     add_value(hkey, "count/up", REG_SZ, "one/two/three", 14);
408     add_value(hkey, "\\foo\\bar", REG_SZ, "", 1);
409     close_key(hkey);
410 
411     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r);
412     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
413     ok(compare_export("file.reg", slashes_test, TODO_REG_COMPARE), "compare_export() failed\n");
414     delete_tree(HKEY_CURRENT_USER, KEY_BASE);
415 
416     /* Test escaped null characters */
417     add_key(HKEY_CURRENT_USER, KEY_BASE, &hkey);
418     add_value(hkey, "Wine5a", REG_SZ, "\\0", 3);
419     add_value(hkey, "Wine5b", REG_SZ, "\\0\\0", 5);
420     add_value(hkey, "Wine5c", REG_SZ, "Value1\\0", 9);
421     add_value(hkey, "Wine5d", REG_SZ, "Value2\\0\\0\\0\\0", 15);
422     add_value(hkey, "Wine5e", REG_SZ, "Value3\\0Value4", 15);
423     add_value(hkey, "Wine5f", REG_SZ, "\\0Value5", 9);
424     close_key(hkey);
425 
426     run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r);
427     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
428     ok(compare_export("file.reg", escaped_null_test, 0), "compare_export() failed\n");
429     delete_tree(HKEY_CURRENT_USER, KEY_BASE);
430 }
431 
432 START_TEST(export)
433 {
434     DWORD r;
435 
436     if (!run_reg_exe("reg.exe /?", &r)) {
437         win_skip("reg.exe not available, skipping 'export' tests\n");
438         return;
439     }
440 
441     test_export();
442 }
443