1 /*
2  * Copyright 2010 Andrew Eikum for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18 
19 #include <windows.h>
20 #include <stdio.h>
21 #include "wine/test.h"
22 
23 #define lok ok_(__FILE__,line)
24 
25 #define run_regedit_exe(c) run_regedit_exe_(__LINE__,c)
26 static BOOL run_regedit_exe_(unsigned line, const char *cmd)
27 {
28     STARTUPINFOA si = {sizeof(STARTUPINFOA)};
29     PROCESS_INFORMATION pi;
30     DWORD ret;
31     char cmdline[256];
32 
33     si.dwFlags = STARTF_USESTDHANDLES;
34     si.hStdInput  = INVALID_HANDLE_VALUE;
35     si.hStdOutput = INVALID_HANDLE_VALUE;
36     si.hStdError  = INVALID_HANDLE_VALUE;
37 
38     strcpy(cmdline, cmd);
39     if (!CreateProcessA(NULL, cmdline, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi))
40         return FALSE;
41 
42     ret = WaitForSingleObject(pi.hProcess, 10000);
43     if (ret == WAIT_TIMEOUT)
44         TerminateProcess(pi.hProcess, 1);
45 
46     CloseHandle(pi.hThread);
47     CloseHandle(pi.hProcess);
48     return (ret != WAIT_TIMEOUT);
49 }
50 
51 static BOOL write_file(const void *str, DWORD size)
52 {
53     HANDLE file;
54     BOOL ret;
55     DWORD written;
56 
57     file = CreateFileA("test.reg", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
58                        FILE_ATTRIBUTE_NORMAL, NULL);
59     ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
60     if (file == INVALID_HANDLE_VALUE)
61         return FALSE;
62 
63     ret = WriteFile(file, str, size, &written, NULL);
64     ok(ret, "WriteFile failed: %u\n", GetLastError());
65     CloseHandle(file);
66 
67     return ret;
68 }
69 
70 #define exec_import_str(c)  import_reg(__LINE__,c,FALSE)
71 #define exec_import_wstr(c) import_reg(__LINE__,c,TRUE)
72 
73 static BOOL import_reg(unsigned line, const char *contents, BOOL unicode)
74 {
75     int lenA;
76     BOOL ret;
77 
78     lenA = strlen(contents);
79 
80     if (unicode)
81     {
82         int len = MultiByteToWideChar(CP_UTF8, 0, contents, lenA, NULL, 0);
83         int size = len * sizeof(WCHAR);
84         WCHAR *wstr = HeapAlloc(GetProcessHeap(), 0, size);
85         if (!wstr) return FALSE;
86         MultiByteToWideChar(CP_UTF8, 0, contents, lenA, wstr, len);
87 
88         ret = write_file(wstr, size);
89         HeapFree(GetProcessHeap(), 0, wstr);
90     }
91     else
92         ret = write_file(contents, lenA);
93 
94     if (!ret) return FALSE;
95 
96     run_regedit_exe("regedit.exe /s test.reg");
97 
98     ret = DeleteFileA("test.reg");
99     lok(ret, "DeleteFile failed: %u\n", GetLastError());
100 
101     return ret;
102 }
103 
104 #define TODO_REG_TYPE    (0x0001u)
105 #define TODO_REG_SIZE    (0x0002u)
106 #define TODO_REG_DATA    (0x0004u)
107 #define TODO_REG_COMPARE (0x0008u)
108 
109 /* verify_reg() adapted from programs/reg/tests/reg.c */
110 #define verify_reg(k,v,t,d,s,todo) verify_reg_(__LINE__,k,v,t,d,s,todo)
111 static void verify_reg_(unsigned line, HKEY hkey, const char *value,
112                         DWORD exp_type, const void *exp_data, DWORD exp_size, DWORD todo)
113 {
114     DWORD type, size;
115     BYTE data[256];
116     LONG err;
117 
118     size = sizeof(data);
119     memset(data, 0xdd, size);
120     err = RegQueryValueExA(hkey, value, NULL, &type, data, &size);
121     lok(err == ERROR_SUCCESS, "RegQueryValueEx failed: got %d\n", err);
122     if (err != ERROR_SUCCESS)
123         return;
124 
125     todo_wine_if (todo & TODO_REG_TYPE)
126         lok(type == exp_type, "got wrong type %d, expected %d\n", type, exp_type);
127     todo_wine_if (todo & TODO_REG_SIZE)
128         lok(size == exp_size, "got wrong size %d, expected %d\n", size, exp_size);
129     if (exp_data)
130     {
131         todo_wine_if (todo & TODO_REG_DATA)
132             lok(memcmp(data, exp_data, size) == 0, "got wrong data\n");
133     }
134 }
135 
136 #define verify_reg_nonexist(k,n) r_verify_reg_nonexist(__LINE__,k,n)
137 static void r_verify_reg_nonexist(unsigned line, HKEY key, const char *value_name)
138 {
139     LONG lr;
140 
141     lr = RegQueryValueExA(key, value_name, NULL, NULL, NULL, NULL);
142     lok(lr == ERROR_FILE_NOT_FOUND, "registry value '%s' shouldn't exist; got %d, expected 2\n",
143        (value_name && *value_name) ? value_name : "(Default)", lr);
144 }
145 
146 #define open_key(b,p,s,k) open_key_(__LINE__,b,p,s,k)
147 static void open_key_(unsigned line, const HKEY base, const char *path, const DWORD sam, HKEY *hkey)
148 {
149     LONG lr;
150 
151     lr = RegOpenKeyExA(base, path, 0, KEY_READ|sam, hkey);
152     lok(lr == ERROR_SUCCESS, "RegOpenKeyExA failed: %d\n", lr);
153 }
154 
155 #define close_key(k) close_key_(__LINE__,k)
156 static void close_key_(unsigned line, HKEY hkey)
157 {
158     LONG lr;
159 
160     lr = RegCloseKey(hkey);
161     lok(lr == ERROR_SUCCESS, "RegCloseKey failed: %d\n", lr);
162 }
163 
164 #define verify_key(k,s) verify_key_(__LINE__,k,s)
165 static void verify_key_(unsigned line, HKEY key_base, const char *subkey)
166 {
167     HKEY hkey;
168     LONG lr;
169 
170     lr = RegOpenKeyExA(key_base, subkey, 0, KEY_READ, &hkey);
171     lok(lr == ERROR_SUCCESS, "RegOpenKeyExA failed: got %d\n", lr);
172 
173     if (hkey)
174         RegCloseKey(hkey);
175 }
176 
177 #define verify_key_nonexist(k,s) verify_key_nonexist_(__LINE__,k,s)
178 static void verify_key_nonexist_(unsigned line, HKEY key_base, const char *subkey)
179 {
180     HKEY hkey;
181     LONG lr;
182 
183     lr = RegOpenKeyExA(key_base, subkey, 0, KEY_READ, &hkey);
184     lok(lr == ERROR_FILE_NOT_FOUND, "registry key '%s' shouldn't exist; got %d, expected 2\n",
185         subkey, lr);
186 
187     if (hkey)
188         RegCloseKey(hkey);
189 }
190 
191 #define add_key(k,p,s) add_key_(__LINE__,k,p,s)
192 static void add_key_(unsigned line, const HKEY hkey, const char *path, HKEY *subkey)
193 {
194     LONG lr;
195 
196     lr = RegCreateKeyExA(hkey, path, 0, NULL, REG_OPTION_NON_VOLATILE,
197                          KEY_READ|KEY_WRITE, NULL, subkey, NULL);
198     lok(lr == ERROR_SUCCESS, "RegCreateKeyExA failed: %d\n", lr);
199 }
200 
201 #define delete_key(k,p) delete_key_(__LINE__,k,p)
202 static void delete_key_(unsigned line, const HKEY hkey, const char *path)
203 {
204     if (path && *path)
205     {
206         LONG lr;
207 
208         lr = RegDeleteKeyA(hkey, path);
209         lok(lr == ERROR_SUCCESS, "RegDeleteKeyA failed: %d\n", lr);
210     }
211 }
212 
213 static LONG delete_tree(const HKEY key, const char *subkey)
214 {
215     HKEY hkey;
216     LONG ret;
217     char *subkey_name = NULL;
218     DWORD max_subkey_len, subkey_len;
219     static const char empty[1];
220 
221     ret = RegOpenKeyExA(key, subkey, 0, KEY_READ, &hkey);
222     if (ret) return ret;
223 
224     ret = RegQueryInfoKeyA(hkey, NULL, NULL, NULL, NULL, &max_subkey_len,
225                            NULL, NULL, NULL, NULL, NULL, NULL);
226     if (ret) goto cleanup;
227 
228     max_subkey_len++;
229 
230     subkey_name = HeapAlloc(GetProcessHeap(), 0, max_subkey_len);
231     if (!subkey_name)
232     {
233         ret = ERROR_NOT_ENOUGH_MEMORY;
234         goto cleanup;
235     }
236 
237     for (;;)
238     {
239         subkey_len = max_subkey_len;
240         ret = RegEnumKeyExA(hkey, 0, subkey_name, &subkey_len, NULL, NULL, NULL, NULL);
241         if (ret == ERROR_NO_MORE_ITEMS) break;
242         if (ret) goto cleanup;
243         ret = delete_tree(hkey, subkey_name);
244         if (ret) goto cleanup;
245     }
246 
247     ret = RegDeleteKeyA(hkey, empty);
248 
249 cleanup:
250     HeapFree(GetProcessHeap(), 0, subkey_name);
251     RegCloseKey(hkey);
252     return ret;
253 }
254 
255 #define add_value(k,n,t,d,s) add_value_(__LINE__,k,n,t,d,s)
256 static void add_value_(unsigned line, HKEY hkey, const char *name, DWORD type,
257                        const void *data, size_t size)
258 {
259     LONG lr;
260 
261     lr = RegSetValueExA(hkey, name, 0, type, (const BYTE *)data, size);
262     lok(lr == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", lr);
263 }
264 
265 #define delete_value(k,n) delete_value_(__LINE__,k,n)
266 static void delete_value_(unsigned line, const HKEY hkey, const char *name)
267 {
268     LONG lr;
269 
270     lr = RegDeleteValueA(hkey, name);
271     lok(lr == ERROR_SUCCESS, "RegDeleteValueA failed: %d\n", lr);
272 }
273 
274 #define KEY_BASE "Software\\Wine\\regedit_test"
275 
276 static void test_basic_import(void)
277 {
278     HKEY hkey, subkey;
279     DWORD dword = 0x17, type, size;
280     char exp_binary[] = {0xAA,0xBB,0xCC,0x11};
281     LONG lr;
282     char buffer[256];
283     BYTE hex[8];
284 
285     delete_tree(HKEY_CURRENT_USER, KEY_BASE);
286     verify_key_nonexist(HKEY_CURRENT_USER, KEY_BASE);
287 
288     exec_import_str("REGEDIT4\n\n"
289                 "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
290                 "\"TestValue\"=\"AValue\"\n");
291     open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
292     verify_reg(hkey, "TestValue", REG_SZ, "AValue", 7, 0);
293 
294     exec_import_str("REGEDIT4\r\n\r\n"
295                 "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
296                 "\"TestValue2\"=\"BValue\"\r\n");
297     verify_reg(hkey, "TestValue2", REG_SZ, "BValue", 7, 0);
298 
299     exec_import_str("Windows Registry Editor Version 5.00\n\n"
300                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
301                     "\"TestValue3\"=\"Value\"\n");
302     verify_reg(hkey, "TestValue3", REG_SZ, "Value", 6, 0);
303 
304     exec_import_str("REGEDIT4\r\r"
305                 "[HKEY_CURRENT_USER\\" KEY_BASE "]\r"
306                 "\"TestValue4\"=\"DValue\"\r");
307     verify_reg(hkey, "TestValue4", REG_SZ, "DValue", 7, 0);
308 
309     exec_import_str("Windows Registry Editor Version 5.00\r\r"
310                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\r"
311                     "\"TestValue5\"=\"Value\"\r");
312     verify_reg(hkey, "TestValue5", REG_SZ, "Value", 6, 0);
313 
314     exec_import_str("REGEDIT4\n\n"
315                 "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
316                 "\"TestDword\"=dword:00000017\n");
317     verify_reg(hkey, "TestDword", REG_DWORD, &dword, sizeof(dword), 0);
318 
319     exec_import_str("REGEDIT4\n\n"
320                 "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
321                 "\"TestBinary\"=hex:aa,bb,cc,11\n");
322     verify_reg(hkey, "TestBinary", REG_BINARY, exp_binary, sizeof(exp_binary), 0);
323 
324     exec_import_str("REGEDIT4\n\n"
325                 "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
326                 "\"With=Equals\"=\"asdf\"\n");
327     verify_reg(hkey, "With=Equals", REG_SZ, "asdf", 5, 0);
328 
329     exec_import_str("REGEDIT4\n\n"
330                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
331                     "\"Empty string\"=\"\"\n"
332                     "\"\"=\"Default registry value\"\n\n");
333     verify_reg(hkey, "Empty string", REG_SZ, "", 1, 0);
334     verify_reg(hkey, NULL, REG_SZ, "Default registry value", 23, 0);
335 
336     exec_import_str("REGEDIT4\n\n"
337                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
338                     "\"Line1\"=\"Value1\"\n\n"
339                     "\"Line2\"=\"Value2\"\n\n\n"
340                     "\"Line3\"=\"Value3\"\n\n\n\n"
341                     "\"Line4\"=\"Value4\"\n\n");
342     verify_reg(hkey, "Line1", REG_SZ, "Value1", 7, 0);
343     verify_reg(hkey, "Line2", REG_SZ, "Value2", 7, 0);
344     verify_reg(hkey, "Line3", REG_SZ, "Value3", 7, 0);
345     verify_reg(hkey, "Line4", REG_SZ, "Value4", 7, 0);
346 
347     exec_import_str("REGEDIT4\n\n"
348                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
349                     "\"Wine1\"=dword:00000782\n\n"
350                     "\"Wine2\"=\"Test Value\"\n"
351                     "\"Wine3\"=hex(7):4c,69,6e,65,20,\\\n"
352                     "  63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n"
353                     "#comment\n"
354                     "@=\"Test\"\n"
355                     ";comment\n\n"
356                     "\"Wine4\"=dword:12345678\n\n");
357     dword = 0x782;
358     verify_reg(hkey, "Wine1", REG_DWORD, &dword, sizeof(dword), 0);
359     verify_reg(hkey, "Wine2", REG_SZ, "Test Value", 11, 0);
360     verify_reg(hkey, "Wine3", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
361     verify_reg(hkey, "", REG_SZ, "Test", 5, 0);
362     dword = 0x12345678;
363     verify_reg(hkey, "Wine4", REG_DWORD, &dword, sizeof(dword), 0);
364 
365     exec_import_str("REGEDIT4\n\n"
366                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
367                     "\"Wine5\"=\"No newline\"");
368     verify_reg(hkey, "Wine5", REG_SZ, "No newline", 11, 0);
369 
370     exec_import_str("REGEDIT4\n\n"
371                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
372                     "\"Wine6\"=dword:00000050\n\n"
373                     "\"Wine7\"=\"No newline\"");
374     dword = 0x50;
375     verify_reg(hkey, "Wine6", REG_DWORD, &dword, sizeof(dword), 0);
376     verify_reg(hkey, "Wine7", REG_SZ, "No newline", 11, 0);
377 
378     exec_import_str("REGEDIT4\n\n"
379                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
380                     "\"Wine8a\"=dword:1\n"
381                     "\"Wine8b\"=dword:4444\n\n");
382     dword = 0x1;
383     verify_reg(hkey, "Wine8a", REG_DWORD, &dword, sizeof(dword), 0);
384     dword = 0x4444;
385     verify_reg(hkey, "Wine8b", REG_DWORD, &dword, sizeof(dword), 0);
386 
387     exec_import_str("REGEDIT4\n\n"
388                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
389                     "\"Wine9a\"=hex(2):4c,69,6e,65,00\n"
390                     "\"Wine9b\"=\"Value 1\"\n"
391                     "\"Wine9c\"=hex(2):4c,69,6e,65\\\n"
392                     "\"Wine9d\"=\"Value 2\"\n"
393                     "\"Wine9e\"=hex(2):4c,69,6e,65,\\\n"
394                     "\"Wine9f\"=\"Value 3\"\n"
395                     "\"Wine9g\"=\"Value 4\"\n\n");
396     verify_reg(hkey, "Wine9a", REG_EXPAND_SZ, "Line", 5, 0);
397     verify_reg(hkey, "Wine9b", REG_SZ, "Value 1", 8, 0);
398     verify_reg_nonexist(hkey, "Wine9c");
399     verify_reg(hkey, "Wine9d", REG_SZ, "Value 2", 8, 0);
400     verify_reg_nonexist(hkey, "Wine9e");
401     verify_reg_nonexist(hkey, "Wine9f");
402     verify_reg(hkey, "Wine9g", REG_SZ, "Value 4", 8, 0);
403 
404     exec_import_str("REGEDIT4\n\n"
405                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
406                     "\"double\\\"quote\"=\"valid \\\"or\\\" not\"\n"
407                     "\"single'quote\"=dword:00000008\n\n");
408     verify_reg(hkey, "double\"quote", REG_SZ, "valid \"or\" not", 15, 0);
409     dword = 0x00000008;
410     verify_reg(hkey, "single'quote", REG_DWORD, &dword, sizeof(dword), 0);
411 
412     /* Test hex data concatenation for REG_NONE, REG_EXPAND_SZ and REG_BINARY */
413     exec_import_str("REGEDIT4\n\n"
414                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
415                     "\"Wine10a\"=hex(0):56,00,61,00,6c,00,75,00,65,00,00,00\n"
416                     "\"Wine10b\"=hex(0):56,00,61,00,6c,00,\\\n"
417                     "  75,00,65,00,00,00\n"
418                     "\"Wine10c\"=hex(0):56,00,61,00,\\;comment\n"
419                     "  6c,00,75,00,\\\n"
420                     "  65,00,00,00\n"
421                     "\"Wine10d\"=hex(0):56,00,61,00,\\;comment\n"
422                     "  6c,00,75,00,\n"
423                     "  65,00,00,00\n"
424                     "\"Wine10e\"=hex(0):56,00,61,00,\\;comment\n"
425                     "  6c,00,75,00,;comment\n"
426                     "  65,00,00,00\n");
427     verify_reg(hkey, "Wine10a", REG_NONE, "V\0a\0l\0u\0e\0\0", 12, 0);
428     verify_reg(hkey, "Wine10b", REG_NONE, "V\0a\0l\0u\0e\0\0", 12, 0);
429     verify_reg(hkey, "Wine10c", REG_NONE, "V\0a\0l\0u\0e\0\0", 12, 0);
430     verify_reg(hkey, "Wine10d", REG_NONE, "V\0a\0l\0u", 8, 0);
431     verify_reg(hkey, "Wine10e", REG_NONE, "V\0a\0l\0u", 8, 0);
432 
433     exec_import_str("REGEDIT4\n\n"
434                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
435                     "\"Wine11a\"=hex(2):25,50,41,54,48,25,00\n"
436                     "\"Wine11b\"=hex(2):25,50,41,\\\n"
437                     "  54,48,25,00\n"
438                     "\"Wine11c\"=hex(2):25,50,41,\\;comment\n"
439                     "  54,48,\\\n"
440                     "  25,00\n"
441                     "\"Wine11d\"=hex(2):25,50,41,\\;comment\n"
442                     "  54,48,\n"
443                     "  25,00\n"
444                     "\"Wine11e\"=hex(2):25,50,41,\\;comment\n"
445                     "  54,48,;comment\n"
446                     "  25,00\n");
447     verify_reg(hkey, "Wine11a", REG_EXPAND_SZ, "%PATH%", 7, 0);
448     verify_reg(hkey, "Wine11b", REG_EXPAND_SZ, "%PATH%", 7, 0);
449     verify_reg(hkey, "Wine11c", REG_EXPAND_SZ, "%PATH%", 7, 0);
450     /* Wine11d */
451     size = sizeof(buffer);
452     lr = RegQueryValueExA(hkey, "Wine11d", NULL, &type, (BYTE *)&buffer, &size);
453     ok(lr == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", lr);
454     ok(type == REG_EXPAND_SZ, "got wrong type %u, expected %u\n", type, REG_EXPAND_SZ);
455     ok(size == 6 || broken(size == 5) /* Win2k */, "got wrong size %u, expected 6\n", size);
456     ok(memcmp(buffer, "%PATH", size) == 0, "got wrong data\n");
457     /* Wine11e */
458     size = sizeof(buffer);
459     memset(buffer, '-', size);
460     lr = RegQueryValueExA(hkey, "Wine11e", NULL, &type, (BYTE *)&buffer, &size);
461     ok(lr == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", lr);
462     ok(type == REG_EXPAND_SZ, "got wrong type %u, expected %u\n", type, REG_EXPAND_SZ);
463     ok(size == 6 || broken(size == 5) /* Win2k */, "got wrong size %u, expected 6\n", size);
464     ok(memcmp(buffer, "%PATH", size) == 0, "got wrong data\n");
465 
466     exec_import_str("REGEDIT4\n\n"
467                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
468                     "\"Wine12a\"=hex:11,22,33,44,55,66,77,88\n"
469                     "\"Wine12b\"=hex:11,22,33,44,\\\n"
470                     "  55,66,77,88\n"
471                     "\"Wine12c\"=hex:11,22,33,44,\\;comment\n"
472                     "  55,66,\\\n"
473                     "  77,88\n"
474                     "\"Wine12d\"=hex:11,22,33,44,\\;comment\n"
475                     "  55,66,\n"
476                     "  77,88\n"
477                     "\"Wine12e\"=hex:11,22,33,44,\\;comment\n"
478                     "  55,66,;comment\n"
479                     "  77,88\n");
480     hex[0] = 0x11; hex[1] = 0x22; hex[2] = 0x33; hex[3] = 0x44;
481     hex[4] = 0x55; hex[5] = 0x66; hex[6] = 0x77; hex[7] = 0x88;
482     verify_reg(hkey, "Wine12a", REG_BINARY, hex, sizeof(hex), 0);
483     verify_reg(hkey, "Wine12b", REG_BINARY, hex, sizeof(hex), 0);
484     verify_reg(hkey, "Wine12c", REG_BINARY, hex, sizeof(hex), 0);
485     verify_reg(hkey, "Wine12d", REG_BINARY, hex, 6, 0);
486     verify_reg(hkey, "Wine12e", REG_BINARY, hex, 6, 0);
487 
488     /* Test import with subkeys */
489     exec_import_str("REGEDIT4\n\n"
490                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey\"1]\n"
491                     "\"Wine\\\\31\"=\"Test value\"\n\n");
492     open_key(hkey, "Subkey\"1", 0, &subkey);
493     verify_reg(subkey, "Wine\\31", REG_SZ, "Test value", 11, 0);
494     close_key(subkey);
495     delete_key(hkey, "Subkey\"1");
496 
497     exec_import_str("REGEDIT4\n\n"
498                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey/2]\n"
499                     "\"123/\\\"4;'5\"=\"Random value name\"\n\n");
500     open_key(hkey, "Subkey/2", 0, &subkey);
501     verify_reg(subkey, "123/\"4;'5", REG_SZ, "Random value name", 18, 0);
502     close_key(subkey);
503     delete_key(hkey, "Subkey/2");
504 
505     /* Test the accepted range of the hex-based data types */
506     exec_import_str("REGEDIT4\n\n"
507                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
508                     "\"Wine13a\"=hex(0):56,61,6c,75,65,00\n"
509                     "\"Wine13b\"=hex(10):56,61,6c,75,65,00\n"
510                     "\"Wine13c\"=hex(100):56,61,6c,75,65,00\n"
511                     "\"Wine13d\"=hex(1000):56,61,6c,75,65,00\n"
512                     "\"Wine13e\"=hex(7fff):56,61,6c,75,65,00\n"
513                     "\"Wine13f\"=hex(ffff):56,61,6c,75,65,00\n"
514                     "\"Wine13g\"=hex(7fffffff):56,61,6c,75,65,00\n"
515                     "\"Wine13h\"=hex(ffffffff):56,61,6c,75,65,00\n"
516                     "\"Wine13i\"=hex(100000000):56,61,6c,75,65,00\n"
517                     "\"Wine13j\"=hex(0x2):56,61,6c,75,65,00\n"
518                     "\"Wine13k\"=hex(0X2):56,61,6c,75,65,00\n"
519                     "\"Wine13l\"=hex(x2):56,61,6c,75,65,00\n\n");
520     verify_reg(hkey, "Wine13a", REG_NONE, "Value", 6, 0);
521     verify_reg(hkey, "Wine13b", 0x10, "Value", 6, 0);
522     verify_reg(hkey, "Wine13c", 0x100, "Value", 6, 0);
523     verify_reg(hkey, "Wine13d", 0x1000, "Value", 6, 0);
524     verify_reg(hkey, "Wine13e", 0x7fff, "Value", 6, 0);
525     verify_reg(hkey, "Wine13f", 0xffff, "Value", 6, 0);
526     verify_reg(hkey, "Wine13g", 0x7fffffff, "Value", 6, 0);
527     verify_reg(hkey, "Wine13h", 0xffffffff, "Value", 6, 0);
528     verify_reg_nonexist(hkey, "Wine13i");
529     verify_reg_nonexist(hkey, "Wine13j");
530     verify_reg_nonexist(hkey, "Wine13k");
531     verify_reg_nonexist(hkey, "Wine13l");
532 
533     exec_import_str("REGEDIT4\n\n"
534                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
535                     "\"Wine14a\"=hex(7):4c,69,6e,65,20,  \\\n"
536                     "  63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n"
537                     "\"Wine14b\"=hex(7):4c,69,6e,65,20,\t\\\n"
538                     "  63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n\n");
539     verify_reg(hkey, "Wine14a", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
540     verify_reg(hkey, "Wine14b", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
541 
542     exec_import_str("REGEDIT4\n\n"
543                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
544                     "\"Wine15\"=hex(2):25,50,41,54,48,25,00,\n\n");
545     verify_reg(hkey, "Wine15", REG_EXPAND_SZ, "%PATH%", 7, 0);
546 
547     exec_import_str("REGEDIT4\n\n"
548                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
549                     "\"Wine16\"=hex(2):\\\n"
550                     "  25,48,4f,4d,45,25,00\n\n");
551     verify_reg(hkey, "Wine16", REG_EXPAND_SZ, "%HOME%", 7, 0);
552 
553     exec_import_str("REGEDIT4\n\n"
554                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
555                     "\"Wine17a\"=hex(0):56,61,6c,75,65,\\");
556     verify_reg(hkey, "Wine17a", REG_NONE, "Value", 5, 0);
557 
558     exec_import_str("REGEDIT4\n\n"
559                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
560                     "\"Wine17b\"=hex(2):25,50,41,54,48,25,\\");
561     verify_reg(hkey, "Wine17b", REG_EXPAND_SZ, "%PATH%", 7, 0);
562 
563     exec_import_str("REGEDIT4\n\n"
564                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
565                     "\"Wine17c\"=hex:11,22,33,44,55,\\");
566     verify_reg(hkey, "Wine17c", REG_BINARY, hex, 5, 0);
567 
568     exec_import_str("REGEDIT4\n\n"
569                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
570                     "\"Wine17d\"=hex(7):4c,69,6e,65,\\");
571     verify_reg(hkey, "Wine17d", REG_MULTI_SZ, "Line", 5, 0);
572 
573     exec_import_str("REGEDIT4\n\n"
574                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
575                     "\"Wine17e\"=hex(100):56,61,6c,75,65,\\");
576     verify_reg(hkey, "Wine17e", 0x100, "Value", 5, 0);
577 
578     exec_import_str("REGEDIT4\n\n"
579                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
580                     "\"Wine18a\"=hex(7):4c,69,6e,65,00,00\n"
581                     "\"Wine18b\"=hex(7):4c,69,6e,65,20,\\\n"
582                     "  63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n"
583                     "\"Wine18c\"=hex(7):4c,69,6e,65,20,\\;comment\n"
584                     "  63,6f,6e,63,61,74,\\\n"
585                     "  65,6e,61,74,69,6f,6e,00,00\n"
586                     "\"Wine18d\"=hex(7):4c,69,6e,65,20,\\;comment\n"
587                     "  63,6f,6e,63,61,74,\n"
588                     "  65,6e,61,74,69,6f,6e,00,00\n"
589                     "\"Wine18e\"=hex(7):4c,69,6e,65,20,\\\n"
590                     "  63,6f,6e,63,61,74,;comment\n"
591                     "  65,6e,61,74,69,6f,6e,00,00\n\n");
592     verify_reg(hkey, "Wine18a", REG_MULTI_SZ, "Line\0", 6, 0);
593     verify_reg(hkey, "Wine18b", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
594     verify_reg(hkey, "Wine18c", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
595     /* Wine18d */
596     size = sizeof(buffer);
597     memset(buffer, '-', size);
598     lr = RegQueryValueExA(hkey, "Wine18d", NULL, &type, (BYTE *)&buffer, &size);
599     ok(lr == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", lr);
600     ok(type == REG_MULTI_SZ, "got wrong type %u, expected %u\n", type, REG_MULTI_SZ);
601     ok(size == 12 || broken(size == 11) /* Win2k */, "got wrong size %u, expected 12\n", size);
602     ok(memcmp(buffer, "Line concat", size) == 0, "got wrong data\n");
603     /* Wine18e */
604     size = sizeof(buffer);
605     memset(buffer, '-', size);
606     lr = RegQueryValueExA(hkey, "Wine18e", NULL, &type, (BYTE *)&buffer, &size);
607     ok(lr == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", lr);
608     ok(type == REG_MULTI_SZ, "got wrong type %u, expected %u\n", type, REG_MULTI_SZ);
609     ok(size == 12 || broken(size == 11) /* Win2k */, "got wrong size %u, expected 12\n", size);
610     ok(memcmp(buffer, "Line concat", size) == 0, "got wrong data\n");
611 
612     exec_import_str("REGEDIT4\n\n"
613                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
614                     "\"Wine19a\"=hex(100):25,50,41,54,48,25,00\n"
615                     "\"Wine19b\"=hex(100):25,50,41,\\\n"
616                     "  54,48,25,00\n"
617                     "\"Wine19c\"=hex(100):25,50,41,\\;comment\n"
618                     "  54,48,\\\n"
619                     "  25,00\n"
620                     "\"Wine19d\"=hex(100):25,50,41,\\;comment\n"
621                     "  54,48,\n"
622                     "  25,00\n"
623                     "\"Wine19e\"=hex(100):25,50,41,\\;comment\n"
624                     "  54,48,;comment\n"
625                     "  25,00\n");
626     verify_reg(hkey, "Wine19a", 0x100, "%PATH%", 7, 0);
627     verify_reg(hkey, "Wine19b", 0x100, "%PATH%", 7, 0);
628     verify_reg(hkey, "Wine19c", 0x100, "%PATH%", 7, 0);
629     verify_reg(hkey, "Wine19d", 0x100, "%PATH", 5, 0);
630     verify_reg(hkey, "Wine19e", 0x100, "%PATH", 5, 0);
631 
632     /* Test null-termination of REG_EXPAND_SZ and REG_MULTI_SZ data*/
633     exec_import_str("REGEDIT4\n\n"
634                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
635                     "\"Wine20a\"=hex(7):4c,69,6e,65\n"
636                     "\"Wine20b\"=hex(7):4c,69,6e,65,\n"
637                     "\"Wine20c\"=hex(7):4c,69,6e,65,00\n"
638                     "\"Wine20d\"=hex(7):4c,69,6e,65,00,\n"
639                     "\"Wine20e\"=hex(7):4c,69,6e,65,00,00\n"
640                     "\"Wine20f\"=hex(7):4c,69,6e,65,00,00,\n\n");
641     verify_reg(hkey, "Wine20a", REG_MULTI_SZ, "Line", 5, 0);
642     verify_reg(hkey, "Wine20b", REG_MULTI_SZ, "Line", 5, 0);
643     verify_reg(hkey, "Wine20c", REG_MULTI_SZ, "Line", 5, 0);
644     verify_reg(hkey, "Wine20d", REG_MULTI_SZ, "Line", 5, 0);
645     verify_reg(hkey, "Wine20e", REG_MULTI_SZ, "Line\0", 6, 0);
646     verify_reg(hkey, "Wine20f", REG_MULTI_SZ, "Line\0", 6, 0);
647 
648     exec_import_str("REGEDIT4\n\n"
649                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
650                     "\"Wine21a\"=hex(2):25,50,41,54,48,25\n"
651                     "\"Wine21b\"=hex(2):25,50,41,54,48,25,\n"
652                     "\"Wine21c\"=hex(2):25,50,41,54,48,25,00\n"
653                     "\"Wine21d\"=hex(2):25,50,41,54,48,25,00,\n\n");
654     verify_reg(hkey, "Wine21a", REG_EXPAND_SZ, "%PATH%", 7, 0);
655     verify_reg(hkey, "Wine21b", REG_EXPAND_SZ, "%PATH%", 7, 0);
656     verify_reg(hkey, "Wine21c", REG_EXPAND_SZ, "%PATH%", 7, 0);
657     verify_reg(hkey, "Wine21d", REG_EXPAND_SZ, "%PATH%", 7, 0);
658 
659     exec_import_str("REGEDIT4\n\n"
660                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
661                     "\"Wine22a\"=hex(1):\n"
662                     "\"Wine22b\"=hex(2):\n"
663                     "\"Wine22c\"=hex(3):\n"
664                     "\"Wine22d\"=hex(4):\n"
665                     "\"Wine22e\"=hex(7):\n"
666                     "\"Wine22f\"=hex(100):\n"
667                     "\"Wine22g\"=hex(abcd):\n"
668                     "\"Wine22h\"=hex:\n"
669                     "\"Wine22i\"=hex(0):\n\n");
670     verify_reg(hkey, "Wine22a", REG_SZ, NULL, 0, 0);
671     verify_reg(hkey, "Wine22b", REG_EXPAND_SZ, NULL, 0, 0);
672     verify_reg(hkey, "Wine22c", REG_BINARY, NULL, 0, 0);
673     verify_reg(hkey, "Wine22d", REG_DWORD, NULL, 0, 0);
674     verify_reg(hkey, "Wine22e", REG_MULTI_SZ, NULL, 0, 0);
675     verify_reg(hkey, "Wine22f", 0x100, NULL, 0, 0);
676     verify_reg(hkey, "Wine22g", 0xabcd, NULL, 0, 0);
677     verify_reg(hkey, "Wine22h", REG_BINARY, NULL, 0, 0);
678     verify_reg(hkey, "Wine22i", REG_NONE, NULL, 0, 0);
679 
680     /* Test with escaped null characters */
681     exec_import_str("REGEDIT4\n\n"
682                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
683                     "\"Wine23a\"=\"\\\\0\"\n"
684                     "\"Wine23b\"=\"\\\\0\\\\0\"\n"
685                     "\"Wine23c\"=\"Value1\\\\0\"\n"
686                     "\"Wine23d\"=\"Value2\\\\0\\\\0\\\\0\\\\0\"\n"
687                     "\"Wine23e\"=\"Value3\\\\0Value4\"\n"
688                     "\"Wine23f\"=\"\\\\0Value5\"\n\n");
689     verify_reg(hkey, "Wine23a", REG_SZ, "\\0", 3, 0);
690     verify_reg(hkey, "Wine23b", REG_SZ, "\\0\\0", 5, 0);
691     verify_reg(hkey, "Wine23c", REG_SZ, "Value1\\0", 9, 0);
692     verify_reg(hkey, "Wine23d", REG_SZ, "Value2\\0\\0\\0\\0", 15, 0);
693     verify_reg(hkey, "Wine23e", REG_SZ, "Value3\\0Value4", 15, 0);
694     verify_reg(hkey, "Wine23f", REG_SZ, "\\0Value5", 9, 0);
695 
696     /* Test forward and back slashes */
697     exec_import_str("REGEDIT4\n\n"
698                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
699                     "\"count/up\"=\"one/two/three\"\n"
700                     "\"\\\\foo\\\\bar\"=\"\"\n\n"
701                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\https://winehq.org]\n\n");
702     verify_reg(hkey, "count/up", REG_SZ, "one/two/three", 14, 0);
703     verify_reg(hkey, "\\foo\\bar", REG_SZ, "", 1, 0);
704     verify_key(hkey, "https://winehq.org");
705 
706     close_key(hkey);
707 
708     delete_tree(HKEY_CURRENT_USER, KEY_BASE);
709 }
710 
711 static void test_basic_import_unicode(void)
712 {
713     HKEY hkey, subkey;
714     DWORD dword = 0x17, type, size;
715     char exp_binary[] = {0xAA,0xBB,0xCC,0x11};
716     LONG lr;
717     char buffer[256];
718     BYTE hex[8];
719 
720     delete_tree(HKEY_CURRENT_USER, KEY_BASE);
721     verify_key_nonexist(HKEY_CURRENT_USER, KEY_BASE);
722 
723     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
724                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
725                      "\"TestValue\"=\"AValue\"\n");
726     open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
727     verify_reg(hkey, "TestValue", REG_SZ, "AValue", 7, 0);
728 
729     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
730                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
731                      "\"TestValue2\"=\"BValue\"\r\n");
732     verify_reg(hkey, "TestValue2", REG_SZ, "BValue", 7, 0);
733 
734     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
735                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
736                      "\"TestValue3\"=\"Value\"\n");
737     verify_reg(hkey, "TestValue3", REG_SZ, "Value", 6, 0);
738 
739     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\r\r"
740                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\r"
741                      "\"TestValue4\"=\"DValue\"\r");
742     verify_reg(hkey, "TestValue4", REG_SZ, "DValue", 7, 0);
743 
744     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\r\r"
745                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\r"
746                      "\"TestValue5\"=\"Value\"\r");
747     verify_reg(hkey, "TestValue5", REG_SZ, "Value", 6, 0);
748 
749     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
750                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
751                      "\"TestDword\"=dword:00000017\n");
752     verify_reg(hkey, "TestDword", REG_DWORD, &dword, sizeof(dword), 0);
753 
754     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
755                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
756                     "\"TestBinary\"=hex:aa,bb,cc,11\n");
757     verify_reg(hkey, "TestBinary", REG_BINARY, exp_binary, sizeof(exp_binary), 0);
758 
759     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
760                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
761                     "\"With=Equals\"=\"asdf\"\n");
762     verify_reg(hkey, "With=Equals", REG_SZ, "asdf", 5, 0);
763 
764     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
765                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
766                      "\"Empty string\"=\"\"\n"
767                      "\"\"=\"Default registry value\"\n\n");
768     verify_reg(hkey, "Empty string", REG_SZ, "", 1, 0);
769     verify_reg(hkey, NULL, REG_SZ, "Default registry value", 23, 0);
770 
771     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
772                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
773                      "\"Line1\"=\"Value1\"\n\n"
774                      "\"Line2\"=\"Value2\"\n\n\n"
775                      "\"Line3\"=\"Value3\"\n\n\n\n"
776                      "\"Line4\"=\"Value4\"\n\n");
777     verify_reg(hkey, "Line1", REG_SZ, "Value1", 7, 0);
778     verify_reg(hkey, "Line2", REG_SZ, "Value2", 7, 0);
779     verify_reg(hkey, "Line3", REG_SZ, "Value3", 7, 0);
780     verify_reg(hkey, "Line4", REG_SZ, "Value4", 7, 0);
781 
782     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
783                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
784                      "\"Wine1\"=dword:00000782\n\n"
785                      "\"Wine2\"=\"Test Value\"\n"
786                      "\"Wine3\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
787                      "  63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
788                      "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n"
789                      "#comment\n"
790                      "@=\"Test\"\n"
791                      ";comment\n\n"
792                      "\"Wine4\"=dword:12345678\n\n");
793     dword = 0x782;
794     verify_reg(hkey, "Wine1", REG_DWORD, &dword, sizeof(dword), 0);
795     verify_reg(hkey, "Wine2", REG_SZ, "Test Value", 11, 0);
796     verify_reg(hkey, "Wine3", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
797     verify_reg(hkey, "", REG_SZ, "Test", 5, 0);
798     dword = 0x12345678;
799     verify_reg(hkey, "Wine4", REG_DWORD, &dword, sizeof(dword), 0);
800 
801     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
802                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
803                      "\"Wine5\"=\"No newline\"");
804     verify_reg(hkey, "Wine5", REG_SZ, "No newline", 11, 0);
805 
806     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
807                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
808                      "\"Wine6\"=dword:00000050\n\n"
809                      "\"Wine7\"=\"No newline\"");
810     dword = 0x50;
811     verify_reg(hkey, "Wine6", REG_DWORD, &dword, sizeof(dword), 0);
812     verify_reg(hkey, "Wine7", REG_SZ, "No newline", 11, 0);
813 
814     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
815                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
816                      "\"Wine8a\"=dword:1\n"
817                      "\"Wine8b\"=dword:4444\n\n");
818     dword = 0x1;
819     verify_reg(hkey, "Wine8a", REG_DWORD, &dword, sizeof(dword), 0);
820     dword = 0x4444;
821     verify_reg(hkey, "Wine8b", REG_DWORD, &dword, sizeof(dword), 0);
822 
823     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
824                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
825                      "\"Wine9a\"=hex(2):4c,00,69,00,6e,00,65,00,00,00\n"
826                      "\"Wine9b\"=\"Value 1\"\n"
827                      "\"Wine9c\"=hex(2):4c,00,69,00,6e,00,65,00\\\n"
828                      "\"Wine9d\"=\"Value 2\"\n"
829                      "\"Wine9e\"=hex(2):4c,00,69,00,6e,00,65,00,\\\n"
830                      "\"Wine9f\"=\"Value 3\"\n"
831                      "\"Wine9g\"=\"Value 4\"\n\n");
832     verify_reg(hkey, "Wine9a", REG_EXPAND_SZ, "Line", 5, 0);
833     verify_reg(hkey, "Wine9b", REG_SZ, "Value 1", 8, 0);
834     verify_reg_nonexist(hkey, "Wine9c");
835     verify_reg(hkey, "Wine9d", REG_SZ, "Value 2", 8, 0);
836     verify_reg_nonexist(hkey, "Wine9e");
837     verify_reg_nonexist(hkey, "Wine9f");
838     verify_reg(hkey, "Wine9g", REG_SZ, "Value 4", 8, 0);
839 
840     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
841                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
842                      "\"double\\\"quote\"=\"valid \\\"or\\\" not\"\n"
843                      "\"single'quote\"=dword:00000008\n\n");
844     verify_reg(hkey, "double\"quote", REG_SZ, "valid \"or\" not", 15, 0);
845     dword = 0x00000008;
846     verify_reg(hkey, "single'quote", REG_DWORD, &dword, sizeof(dword), 0);
847 
848     /* Test hex data concatenation for REG_NONE, REG_EXPAND_SZ and REG_BINARY */
849     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
850                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
851                      "\"Wine10a\"=hex(0):56,00,61,00,6c,00,75,00,65,00,00,00\n"
852                      "\"Wine10b\"=hex(0):56,00,61,00,6c,00,\\\n"
853                      "  75,00,65,00,00,00\n"
854                      "\"Wine10c\"=hex(0):56,00,61,00,\\;comment\n"
855                      "  6c,00,75,00,\\\n"
856                      "  65,00,00,00\n"
857                      "\"Wine10d\"=hex(0):56,00,61,00,\\;comment\n"
858                      "  6c,00,75,00,\n"
859                      "  65,00,00,00\n"
860                      "\"Wine10e\"=hex(0):56,00,61,00,\\;comment\n"
861                      "  6c,00,75,00,;comment\n"
862                      "  65,00,00,00\n");
863     verify_reg(hkey, "Wine10a", REG_NONE, "V\0a\0l\0u\0e\0\0", 12, 0);
864     verify_reg(hkey, "Wine10b", REG_NONE, "V\0a\0l\0u\0e\0\0", 12, 0);
865     verify_reg(hkey, "Wine10c", REG_NONE, "V\0a\0l\0u\0e\0\0", 12, 0);
866     verify_reg(hkey, "Wine10d", REG_NONE, "V\0a\0l\0u", 8, 0);
867     verify_reg(hkey, "Wine10e", REG_NONE, "V\0a\0l\0u", 8, 0);
868 
869     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
870                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
871                      "\"Wine11a\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"
872                      "\"Wine11b\"=hex(2):25,00,50,00,41,00,\\\n"
873                      "  54,00,48,00,25,00,00,00\n"
874                      "\"Wine11c\"=hex(2):25,00,50,00,41,00,\\;comment\n"
875                      "  54,00,48,00,\\\n"
876                      "  25,00,00,00\n"
877                      "\"Wine11d\"=hex(2):25,00,50,00,41,00,\\;comment\n"
878                      "  54,00,48,00,\n"
879                      "  25,00,00,00\n"
880                      "\"Wine11e\"=hex(2):25,00,50,00,41,00,\\;comment\n"
881                      "  54,00,48,00,;comment\n"
882                      "  25,00,00,00\n");
883     verify_reg(hkey, "Wine11a", REG_EXPAND_SZ, "%PATH%", 7, 0);
884     verify_reg(hkey, "Wine11b", REG_EXPAND_SZ, "%PATH%", 7, 0);
885     verify_reg(hkey, "Wine11c", REG_EXPAND_SZ, "%PATH%", 7, 0);
886     /* Wine11d */
887     size = sizeof(buffer);
888     lr = RegQueryValueExA(hkey, "Wine11d", NULL, &type, (BYTE *)&buffer, &size);
889     ok(lr == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", lr);
890     ok(type == REG_EXPAND_SZ, "got wrong type %u, expected %u\n", type, REG_EXPAND_SZ);
891     ok(size == 6 || broken(size == 5) /* Win2k */, "got wrong size %u, expected 6\n", size);
892     ok(memcmp(buffer, "%PATH", size) == 0, "got wrong data\n");
893     /* Wine11e */
894     size = sizeof(buffer);
895     memset(buffer, '-', size);
896     lr = RegQueryValueExA(hkey, "Wine11e", NULL, &type, (BYTE *)&buffer, &size);
897     ok(lr == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", lr);
898     ok(type == REG_EXPAND_SZ, "got wrong type %u, expected %u\n", type, REG_EXPAND_SZ);
899     ok(size == 6 || broken(size == 5) /* Win2k */, "got wrong size %u, expected 6\n", size);
900     ok(memcmp(buffer, "%PATH", size) == 0, "got wrong data\n");
901 
902     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
903                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
904                      "\"Wine12a\"=hex:11,22,33,44,55,66,77,88\n"
905                      "\"Wine12b\"=hex:11,22,33,44,\\\n"
906                      "  55,66,77,88\n"
907                      "\"Wine12c\"=hex:11,22,33,44,\\;comment\n"
908                      "  55,66,\\\n"
909                      "  77,88\n"
910                      "\"Wine12d\"=hex:11,22,33,44,\\;comment\n"
911                      "  55,66,\n"
912                      "  77,88\n"
913                      "\"Wine12e\"=hex:11,22,33,44,\\;comment\n"
914                      "  55,66,;comment\n"
915                      "  77,88\n");
916     hex[0] = 0x11; hex[1] = 0x22; hex[2] = 0x33; hex[3] = 0x44;
917     hex[4] = 0x55; hex[5] = 0x66; hex[6] = 0x77; hex[7] = 0x88;
918     verify_reg(hkey, "Wine12a", REG_BINARY, hex, sizeof(hex), 0);
919     verify_reg(hkey, "Wine12b", REG_BINARY, hex, sizeof(hex), 0);
920     verify_reg(hkey, "Wine12c", REG_BINARY, hex, sizeof(hex), 0);
921     verify_reg(hkey, "Wine12d", REG_BINARY, hex, 6, 0);
922     verify_reg(hkey, "Wine12e", REG_BINARY, hex, 6, 0);
923 
924     /* Test import with subkeys */
925     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
926                      "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey\"1]\n"
927                      "\"Wine\\\\31\"=\"Test value\"\n\n");
928     open_key(hkey, "Subkey\"1", 0, &subkey);
929     verify_reg(subkey, "Wine\\31", REG_SZ, "Test value", 11, 0);
930     close_key(subkey);
931     delete_key(hkey, "Subkey\"1");
932 
933     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
934                      "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey/2]\n"
935                      "\"123/\\\"4;'5\"=\"Random value name\"\n\n");
936     open_key(hkey, "Subkey/2", 0, &subkey);
937     verify_reg(subkey, "123/\"4;'5", REG_SZ, "Random value name", 18, 0);
938     close_key(subkey);
939     delete_key(hkey, "Subkey/2");
940 
941     /* Test the accepted range of the hex-based data types */
942     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
943                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
944                      "\"Wine13a\"=hex(0):56,61,6c,75,65,00\n"
945                      "\"Wine13b\"=hex(10):56,61,6c,75,65,00\n"
946                      "\"Wine13c\"=hex(100):56,61,6c,75,65,00\n"
947                      "\"Wine13d\"=hex(1000):56,61,6c,75,65,00\n"
948                      "\"Wine13e\"=hex(7fff):56,61,6c,75,65,00\n"
949                      "\"Wine13f\"=hex(ffff):56,61,6c,75,65,00\n"
950                      "\"Wine13g\"=hex(7fffffff):56,61,6c,75,65,00\n"
951                      "\"Wine13h\"=hex(ffffffff):56,61,6c,75,65,00\n"
952                      "\"Wine13i\"=hex(100000000):56,61,6c,75,65,00\n"
953                      "\"Wine13j\"=hex(0x2):56,61,6c,75,65,00\n"
954                      "\"Wine13k\"=hex(0X2):56,61,6c,75,65,00\n"
955                      "\"Wine13l\"=hex(x2):56,61,6c,75,65,00\n\n");
956     verify_reg(hkey, "Wine13a", REG_NONE, "Value", 6, 0);
957     verify_reg(hkey, "Wine13b", 0x10, "Value", 6, 0);
958     verify_reg(hkey, "Wine13c", 0x100, "Value", 6, 0);
959     verify_reg(hkey, "Wine13d", 0x1000, "Value", 6, 0);
960     verify_reg(hkey, "Wine13e", 0x7fff, "Value", 6, 0);
961     verify_reg(hkey, "Wine13f", 0xffff, "Value", 6, 0);
962     verify_reg(hkey, "Wine13g", 0x7fffffff, "Value", 6, 0);
963     verify_reg(hkey, "Wine13h", 0xffffffff, "Value", 6, 0);
964     verify_reg_nonexist(hkey, "Wine13i");
965     verify_reg_nonexist(hkey, "Wine13j");
966     verify_reg_nonexist(hkey, "Wine13k");
967     verify_reg_nonexist(hkey, "Wine13l");
968 
969     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
970                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
971                      "\"Wine14a\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,  \\\n"
972                      "  63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
973                      "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n"
974                      "\"Wine14b\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\t\\\n"
975                      "  63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
976                      "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n");
977     verify_reg(hkey, "Wine14a", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
978     verify_reg(hkey, "Wine14b", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
979 
980     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
981                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
982                      "\"Wine15\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00,\n\n");
983     verify_reg(hkey, "Wine15", REG_EXPAND_SZ, "%PATH%", 7, 0);
984 
985     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
986                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
987                      "\"Wine16\"=hex(2):\\\n"
988                      "  25,00,48,00,4f,00,4d,00,45,00,25,00,00,00\n\n");
989     verify_reg(hkey, "Wine16", REG_EXPAND_SZ, "%HOME%", 7, 0);
990 
991     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
992                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
993                      "\"Wine17a\"=hex(0):56,61,6c,75,65,\\");
994     verify_reg(hkey, "Wine17a", REG_NONE, "Value", 5, 0);
995 
996     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
997                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
998                      "\"Wine17b\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,\\");
999     verify_reg(hkey, "Wine17b", REG_EXPAND_SZ, "%PATH%", 7, 0);
1000 
1001     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1002                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1003                      "\"Wine17c\"=hex:11,22,33,44,55,\\");
1004     verify_reg(hkey, "Wine17c", REG_BINARY, hex, 5, 0);
1005 
1006     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1007                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1008                      "\"Wine17d\"=hex(7):4c,00,69,00,6e,00,65,00,\\");
1009     verify_reg(hkey, "Wine17d", REG_MULTI_SZ, "Line", 5, 0);
1010 
1011     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1012                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1013                      "\"Wine17e\"=hex(100):56,61,6c,75,65,\\");
1014     verify_reg(hkey, "Wine17e", 0x100, "Value", 5, 0);
1015 
1016     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1017                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1018                      "\"Wine18a\"=hex(7):4c,00,69,00,6e,00,65,00,00,00,00,00\n"
1019                      "\"Wine18b\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
1020                      "  63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
1021                      "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n"
1022                      "\"Wine18c\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\;comment\n"
1023                      "  63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
1024                      "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n"
1025                      "\"Wine18d\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\;comment\n"
1026                      "  63,00,6f,00,6e,00,63,00,61,00,74,00,\n"
1027                      "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n"
1028                      "\"Wine18e\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
1029                      "  63,00,6f,00,6e,00,63,00,61,00,74,00,;comment\n"
1030                      "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n");
1031     verify_reg(hkey, "Wine18a", REG_MULTI_SZ, "Line\0", 6, 0);
1032     verify_reg(hkey, "Wine18b", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
1033     verify_reg(hkey, "Wine18c", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
1034     /* Wine18d */
1035     size = sizeof(buffer);
1036     memset(buffer, '-', size);
1037     lr = RegQueryValueExA(hkey, "Wine18d", NULL, &type, (BYTE *)&buffer, &size);
1038     ok(lr == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", lr);
1039     ok(type == REG_MULTI_SZ, "got wrong type %u, expected %u\n", type, REG_MULTI_SZ);
1040     ok(size == 12 || broken(size == 11) /* Win2k */, "got wrong size %u, expected 12\n", size);
1041     ok(memcmp(buffer, "Line concat", size) == 0, "got wrong data\n");
1042     /* Wine18e */
1043     size = sizeof(buffer);
1044     memset(buffer, '-', size);
1045     lr = RegQueryValueExA(hkey, "Wine18e", NULL, &type, (BYTE *)&buffer, &size);
1046     ok(lr == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", lr);
1047     ok(type == REG_MULTI_SZ, "got wrong type %u, expected %u\n", type, REG_MULTI_SZ);
1048     ok(size == 12 || broken(size == 11) /* Win2k */, "got wrong size %u, expected 12\n", size);
1049     ok(memcmp(buffer, "Line concat", size) == 0, "got wrong data\n");
1050 
1051     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1052                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1053                      "\"Wine19a\"=hex(100):25,50,41,54,48,25,00\n"
1054                      "\"Wine19b\"=hex(100):25,50,41,\\\n"
1055                      "  54,48,25,00\n"
1056                      "\"Wine19c\"=hex(100):25,50,41,\\;comment\n"
1057                      "  54,48,\\\n"
1058                      "  25,00\n"
1059                      "\"Wine19d\"=hex(100):25,50,41,\\;comment\n"
1060                      "  54,48,\n"
1061                      "  25,00\n"
1062                      "\"Wine19e\"=hex(100):25,50,41,\\;comment\n"
1063                      "  54,48,;comment\n"
1064                      "  25,00\n");
1065     verify_reg(hkey, "Wine19a", 0x100, "%PATH%", 7, 0);
1066     verify_reg(hkey, "Wine19b", 0x100, "%PATH%", 7, 0);
1067     verify_reg(hkey, "Wine19c", 0x100, "%PATH%", 7, 0);
1068     verify_reg(hkey, "Wine19d", 0x100, "%PATH", 5, 0);
1069     verify_reg(hkey, "Wine19e", 0x100, "%PATH", 5, 0);
1070 
1071     /* Test null-termination of REG_EXPAND_SZ and REG_MULTI_SZ data*/
1072     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1073                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1074                      "\"Wine20a\"=hex(7):4c,00,69,00,6e,00,65,00\n"
1075                      "\"Wine20b\"=hex(7):4c,00,69,00,6e,00,65,00,\n"
1076                      "\"Wine20c\"=hex(7):4c,00,69,00,6e,00,65,00,00,00\n"
1077                      "\"Wine20d\"=hex(7):4c,00,69,00,6e,00,65,00,00,00,\n"
1078                      "\"Wine20e\"=hex(7):4c,00,69,00,6e,00,65,00,00,00,00,00\n"
1079                      "\"Wine20f\"=hex(7):4c,00,69,00,6e,00,65,00,00,00,00,00,\n\n");
1080     verify_reg(hkey, "Wine20a", REG_MULTI_SZ, "Line", 5, 0);
1081     verify_reg(hkey, "Wine20b", REG_MULTI_SZ, "Line", 5, 0);
1082     verify_reg(hkey, "Wine20c", REG_MULTI_SZ, "Line", 5, 0);
1083     verify_reg(hkey, "Wine20d", REG_MULTI_SZ, "Line", 5, 0);
1084     verify_reg(hkey, "Wine20e", REG_MULTI_SZ, "Line\0", 6, 0);
1085     verify_reg(hkey, "Wine20f", REG_MULTI_SZ, "Line\0", 6, 0);
1086 
1087     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1088                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1089                      "\"Wine21a\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00\n"
1090                      "\"Wine21b\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,\n"
1091                      "\"Wine21c\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"
1092                      "\"Wine21d\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00,\n\n");
1093     verify_reg(hkey, "Wine21a", REG_EXPAND_SZ, "%PATH%", 7, 0);
1094     verify_reg(hkey, "Wine21b", REG_EXPAND_SZ, "%PATH%", 7, 0);
1095     verify_reg(hkey, "Wine21c", REG_EXPAND_SZ, "%PATH%", 7, 0);
1096     verify_reg(hkey, "Wine21d", REG_EXPAND_SZ, "%PATH%", 7, 0);
1097 
1098     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1099                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1100                      "\"Wine22a\"=hex(1):\n"
1101                      "\"Wine22b\"=hex(2):\n"
1102                      "\"Wine22c\"=hex(3):\n"
1103                      "\"Wine22d\"=hex(4):\n"
1104                      "\"Wine22e\"=hex(7):\n"
1105                      "\"Wine22f\"=hex(100):\n"
1106                      "\"Wine22g\"=hex(abcd):\n"
1107                      "\"Wine22h\"=hex:\n"
1108                      "\"Wine22i\"=hex(0):\n\n");
1109     verify_reg(hkey, "Wine22a", REG_SZ, NULL, 0, 0);
1110     verify_reg(hkey, "Wine22b", REG_EXPAND_SZ, NULL, 0, 0);
1111     verify_reg(hkey, "Wine22c", REG_BINARY, NULL, 0, 0);
1112     verify_reg(hkey, "Wine22d", REG_DWORD, NULL, 0, 0);
1113     verify_reg(hkey, "Wine22e", REG_MULTI_SZ, NULL, 0, 0);
1114     verify_reg(hkey, "Wine22f", 0x100, NULL, 0, 0);
1115     verify_reg(hkey, "Wine22g", 0xabcd, NULL, 0, 0);
1116     verify_reg(hkey, "Wine22h", REG_BINARY, NULL, 0, 0);
1117     verify_reg(hkey, "Wine22i", REG_NONE, NULL, 0, 0);
1118 
1119     /* Test with escaped null characters */
1120     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1121                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1122                      "\"Wine23a\"=\"\\\\0\"\n"
1123                      "\"Wine23b\"=\"\\\\0\\\\0\"\n"
1124                      "\"Wine23c\"=\"Value1\\\\0\"\n"
1125                      "\"Wine23d\"=\"Value2\\\\0\\\\0\\\\0\\\\0\"\n"
1126                      "\"Wine23e\"=\"Value3\\\\0Value4\"\n"
1127                      "\"Wine23f\"=\"\\\\0Value5\"\n\n");
1128     verify_reg(hkey, "Wine23a", REG_SZ, "\\0", 3, 0);
1129     verify_reg(hkey, "Wine23b", REG_SZ, "\\0\\0", 5, 0);
1130     verify_reg(hkey, "Wine23c", REG_SZ, "Value1\\0", 9, 0);
1131     verify_reg(hkey, "Wine23d", REG_SZ, "Value2\\0\\0\\0\\0", 15, 0);
1132     verify_reg(hkey, "Wine23e", REG_SZ, "Value3\\0Value4", 15, 0);
1133     verify_reg(hkey, "Wine23f", REG_SZ, "\\0Value5", 9, 0);
1134 
1135     /* Test forward and back slashes */
1136     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1137                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1138                     "\"count/up\"=\"one/two/three\"\n"
1139                     "\"\\\\foo\\\\bar\"=\"\"\n\n"
1140                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\https://winehq.org]\n\n");
1141     verify_reg(hkey, "count/up", REG_SZ, "one/two/three", 14, 0);
1142     verify_reg(hkey, "\\foo\\bar", REG_SZ, "", 1, 0);
1143     verify_key(hkey, "https://winehq.org");
1144 
1145     close_key(hkey);
1146 
1147     delete_tree(HKEY_CURRENT_USER, KEY_BASE);
1148 }
1149 
1150 static void test_basic_import_31(void)
1151 {
1152     HKEY hkey;
1153     DWORD dispos;
1154 
1155     RegCreateKeyExA(HKEY_CLASSES_ROOT, KEY_BASE, 0, NULL, REG_OPTION_NON_VOLATILE,
1156                     KEY_READ|KEY_SET_VALUE, NULL, &hkey, &dispos);
1157 
1158     if (dispos == REG_OPENED_EXISTING_KEY)
1159         delete_value(hkey, NULL);
1160 
1161     /* Test simple value */
1162     exec_import_str("REGEDIT\r\n"
1163 		    "HKEY_CLASSES_ROOT\\" KEY_BASE " = Value0\r\n");
1164     verify_reg(hkey, "", REG_SZ, "Value0", 7, 0);
1165 
1166     /* Test proper handling of spaces and equals signs */
1167     exec_import_str("REGEDIT\r\n"
1168                     "HKEY_CLASSES_ROOT\\" KEY_BASE " =Value1\r\n");
1169     verify_reg(hkey, "", REG_SZ, "Value1", 7, 0);
1170 
1171     exec_import_str("REGEDIT\r\n"
1172                     "HKEY_CLASSES_ROOT\\" KEY_BASE " =  Value2\r\n");
1173     verify_reg(hkey, "", REG_SZ, " Value2", 8, 0);
1174 
1175     exec_import_str("REGEDIT\r\n"
1176                     "HKEY_CLASSES_ROOT\\" KEY_BASE " = Value3 \r\n");
1177     verify_reg(hkey, "", REG_SZ, "Value3 ", 8, 0);
1178 
1179     exec_import_str("REGEDIT\r\n"
1180                     "HKEY_CLASSES_ROOT\\" KEY_BASE " Value4\r\n");
1181     verify_reg(hkey, "", REG_SZ, "Value4", 7, 0);
1182 
1183     exec_import_str("REGEDIT\r\n"
1184                     "HKEY_CLASSES_ROOT\\" KEY_BASE "  Value5\r\n");
1185     verify_reg(hkey, "", REG_SZ, "Value5", 7, 0);
1186 
1187     exec_import_str("REGEDIT\r\n"
1188                     "HKEY_CLASSES_ROOT\\" KEY_BASE "\r\n");
1189     verify_reg(hkey, "", REG_SZ, "", 1, 0);
1190 
1191     exec_import_str("REGEDIT\r\n"
1192                     "HKEY_CLASSES_ROOT\\" KEY_BASE "  \r\n");
1193     verify_reg(hkey, "", REG_SZ, "", 1, 0);
1194 
1195     exec_import_str("REGEDIT\r\n"
1196                     "HKEY_CLASSES_ROOT\\" KEY_BASE " = No newline");
1197     verify_reg(hkey, "", REG_SZ, "No newline", 11, 0);
1198 
1199     close_key(hkey);
1200 
1201     delete_key(HKEY_CLASSES_ROOT, KEY_BASE);
1202 }
1203 
1204 static void test_invalid_import(void)
1205 {
1206     HKEY hkey;
1207     DWORD dword = 0x8;
1208 
1209     delete_tree(HKEY_CURRENT_USER, KEY_BASE);
1210     verify_key_nonexist(HKEY_CURRENT_USER, KEY_BASE);
1211 
1212     exec_import_str("REGEDIT4\n\n"
1213                 "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1214                 "\"TestNoEndQuote\"=\"Asdffdsa\n");
1215     open_key(HKEY_CURRENT_USER, KEY_BASE, KEY_SET_VALUE, &hkey);
1216     verify_reg_nonexist(hkey, "TestNoEndQuote");
1217 
1218     exec_import_str("REGEDIT4\n\n"
1219                 "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1220                 "\"TestNoBeginQuote\"=Asdffdsa\"\n");
1221     verify_reg_nonexist(hkey, "TestNoBeginQuote");
1222 
1223     exec_import_str("REGEDIT4\n\n"
1224                 "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1225                 "\"TestNoQuotes\"=Asdffdsa\n");
1226     verify_reg_nonexist(hkey, "TestNoQuotes");
1227 
1228     exec_import_str("REGEDIT4\n\n"
1229                 "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1230                 "\"NameNoEndQuote=\"Asdffdsa\"\n");
1231     verify_reg_nonexist(hkey, "NameNoEndQuote");
1232 
1233     exec_import_str("REGEDIT4\n\n"
1234                 "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1235                 "NameNoBeginQuote\"=\"Asdffdsa\"\n");
1236     verify_reg_nonexist(hkey, "NameNoBeginQuote");
1237 
1238     exec_import_str("REGEDIT4\n\n"
1239                 "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1240                 "NameNoQuotes=\"Asdffdsa\"\n");
1241     verify_reg_nonexist(hkey, "NameNoQuotes");
1242 
1243     exec_import_str("REGEDIT4\n\n"
1244                 "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1245                 "\"MixedQuotes=Asdffdsa\"\n");
1246     verify_reg_nonexist(hkey, "MixedQuotes");
1247     verify_reg_nonexist(hkey, "MixedQuotes=Asdffdsa");
1248 
1249     /* Test import with non-standard registry file headers */
1250     exec_import_str("REGEDIT3\n\n"
1251                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1252                     "\"Test1\"=\"Value\"\n");
1253     verify_reg_nonexist(hkey, "Test1");
1254 
1255     exec_import_str("regedit4\n\n"
1256                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1257                     "\"Test2\"=\"Value\"\n");
1258     verify_reg_nonexist(hkey, "Test2");
1259 
1260     exec_import_str("Regedit4\n\n"
1261                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1262                     "\"Test3\"=\"Value\"\n");
1263     verify_reg_nonexist(hkey, "Test3");
1264 
1265     exec_import_str("REGEDIT 4\n\n"
1266                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1267                     "\"Test4\"=\"Value\"\n");
1268     verify_reg_nonexist(hkey, "Test4");
1269 
1270     exec_import_str("REGEDIT4FOO\n\n"
1271                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1272                     "\"Test5\"=\"Value\"\n");
1273     verify_reg_nonexist(hkey, "Test5");
1274 
1275     exec_import_str("REGEDIT4 FOO\n\n"
1276                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1277                     "\"Test6\"=\"Value\"\n");
1278     verify_reg_nonexist(hkey, "Test6");
1279 
1280     exec_import_str("REGEDIT5\n\n"
1281                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1282                     "\"Test7\"=\"Value\"\n");
1283     verify_reg_nonexist(hkey, "Test7");
1284 
1285     exec_import_str("Windows Registry Editor Version 4.00\n\n"
1286                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1287                     "\"Test8\"=\"Value\"\n");
1288     verify_reg_nonexist(hkey, "Test8");
1289 
1290     exec_import_str("Windows Registry Editor Version 5\n\n"
1291                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1292                     "\"Test9\"=\"Value\"\n");
1293     verify_reg_nonexist(hkey, "Test9");
1294 
1295     exec_import_str("WINDOWS REGISTRY EDITOR VERSION 5.00\n\n"
1296                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1297                     "\"Test10\"=\"Value\"\n");
1298     verify_reg_nonexist(hkey, "Test10");
1299 
1300     exec_import_str("Windows Registry Editor version 5.00\n\n"
1301                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1302                     "\"Test11\"=\"Value\"\n");
1303     verify_reg_nonexist(hkey, "Test11");
1304 
1305     /* Test multi-line import with incorrect comma placement */
1306     exec_import_str("REGEDIT4\n\n"
1307                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1308                     "\"Multi-Line1\"=hex(7):4c,69,6e,65,20\\\n"
1309                     ",63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n\n");
1310     verify_reg_nonexist(hkey, "Multi-Line1");
1311 
1312     exec_import_str("REGEDIT4\n\n"
1313                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1314                     "\"Multi-Line2\"=hex(7):4c,69,6e,65,20\\\n"
1315                     "  ,63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n\n");
1316     verify_reg_nonexist(hkey, "Multi-Line2");
1317 
1318     exec_import_str("Windows Registry Editor Version 5.00\n\n"
1319                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1320                     "\"Multi-Line3\"=hex(7):4c,69,6e,65,20\\\n"
1321                     ",63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n\n");
1322     verify_reg_nonexist(hkey, "Multi-Line3");
1323 
1324     exec_import_str("Windows Registry Editor Version 5.00\n\n"
1325                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1326                     "\"Multi-Line4\"=hex(7):4c,69,6e,65,20\\\n"
1327                     "  ,63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n\n");
1328     verify_reg_nonexist(hkey, "Multi-Line4");
1329 
1330     exec_import_str("REGEDIT4\n\n"
1331                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1332                     "\"Test12a\"=dword:\n"
1333                     "\"Test12b\"=dword:hello\n"
1334                     "\"Test12c\"=dword:123456789\n"
1335                     "\"Test12d\"=dword:012345678\n"
1336                     "\"Test12e\"=dword:000000001\n\n");
1337     verify_reg_nonexist(hkey, "Test12a");
1338     verify_reg_nonexist(hkey, "Test12b");
1339     verify_reg_nonexist(hkey, "Test12c");
1340     verify_reg_nonexist(hkey, "Test12d");
1341     verify_reg_nonexist(hkey, "Test12e");
1342 
1343     exec_import_str("REGEDIT4\n\n"
1344                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1345                     "\"Test13a\"=dword:12345678abc\n"
1346                     "\"Test13b\"=dword:12345678 abc\n\n");
1347     verify_reg_nonexist(hkey, "Test13a");
1348     verify_reg_nonexist(hkey, "Test13b");
1349 
1350     exec_import_str("REGEDIT4\n\n"
1351                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1352                     "\"Test14a\"=dword:0x123\n"
1353                     "\"Test14b\"=dword:123 456\n"
1354                     "\"Test14c\"=dword:1234 5678\n\n");
1355     verify_reg_nonexist(hkey, "Test14a");
1356     verify_reg_nonexist(hkey, "Test14b");
1357     verify_reg_nonexist(hkey, "Test14c");
1358 
1359     exec_import_str("REGEDIT4\n\n"
1360                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1361                     "\"Test15a\"=\"foo\"bar\"\n"
1362                     "\"Test15b\"=\"foo\"\"bar\"\n\n");
1363     verify_reg_nonexist(hkey, "Test15a");
1364     verify_reg_nonexist(hkey, "Test15b");
1365 
1366     exec_import_str("REGEDIT4\n\n"
1367                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1368                     "\"Test16a\"=\n"
1369                     "\"Test16b\"=\\\"\n"
1370                     "\"Test16c\"=\\\"Value\\\"\n"
1371                     "\"Test16d\"=\\\"Value\"\n\n");
1372     verify_reg_nonexist(hkey, "Test16a");
1373     verify_reg_nonexist(hkey, "Test16b");
1374     verify_reg_nonexist(hkey, "Test16c");
1375     verify_reg_nonexist(hkey, "Test16d");
1376 
1377     /* Test key name and value name concatenation */
1378     exec_import_str("REGEDIT4\n\n"
1379                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\\n"
1380                     "Subkey1]\n");
1381     verify_key_nonexist(hkey, "Subkey1");
1382 
1383     exec_import_str("REGEDIT4\n\n"
1384                     "[HKEY_CURRENT_USER\\" KEY_BASE "\n"
1385                     "\\Subkey2]\n");
1386     verify_key_nonexist(hkey, "Subkey2");
1387 
1388     exec_import_str("REGEDIT4\n\n"
1389                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1390                     "\"Test\\\n"
1391                     "17a\"=\"Value 1\"\n"
1392                     "\"Test17b\"=\"Value 2\"\n"
1393                     "\"Test\n"
1394                     "\\17c\"=\"Value 3\"\n\n");
1395     verify_reg_nonexist(hkey, "Test17a");
1396     verify_reg(hkey, "Test17b", REG_SZ, "Value 2", 8, 0);
1397     verify_reg_nonexist(hkey, "Test17c");
1398 
1399     exec_import_str("REGEDIT4\n\n"
1400                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1401                     "\"Test18a\"=dword:1234\\\n"
1402                     "5678\n"
1403                     "\"Test18b\"=\"Test \\\n"
1404                     "Value\"\n\n");
1405     verify_reg_nonexist(hkey, "Test18a");
1406     verify_reg_nonexist(hkey, "Test18b");
1407 
1408     /* Test hex data concatenation for REG_NONE, REG_EXPAND_SZ and REG_BINARY */
1409     exec_import_str("REGEDIT4\n\n"
1410                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1411                     "\"Test19a\"=hex(0):56,00,61,00,6c,00\\\n"
1412                     ",75,00,65,00,00,00\n"
1413                     "\"Test19b\"=hex(0):56,00,61,00,6c,00\\\n"
1414                     "  ,75,00,65,00,00,00\n"
1415                     "\"Test19c\"=hex(0):56,00,61,00,6c,00\\\n"
1416                     "  75,00,65,00,00,00\n"
1417                     "\"Test19d\"=hex(0):56,00,61,00,6c,00,7\\\n"
1418                     "5,00,65,00,00,00\n"
1419                     "\"Test19e\"=hex(0):56,00,61,00,6c,00,7\\\n"
1420                     "  5,00,65,00,00,00\n"
1421                     "\"Test19f\"=hex(0):56,00,61,00,\\;comment\n"
1422                     "  6c,00,75,00,\\#comment\n"
1423                     "  65,00,00,00\n\n");
1424     verify_reg_nonexist(hkey, "Test19a");
1425     verify_reg_nonexist(hkey, "Test19b");
1426     verify_reg_nonexist(hkey, "Test19c");
1427     verify_reg_nonexist(hkey, "Test19d");
1428     verify_reg_nonexist(hkey, "Test19e");
1429     verify_reg_nonexist(hkey, "Test19f");
1430 
1431     exec_import_str("REGEDIT4\n\n"
1432                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1433                     "\"Test20a\"=hex(2):25,50,41\\\n"
1434                     ",54,48,25,00\n"
1435                     "\"Test20b\"=hex(2):25,50,41\\\n"
1436                     "  ,54,48,25,00\n"
1437                     "\"Test20c\"=hex(2):25,50,41\\\n"
1438                     "  54,48,25,00\n"
1439                     "\"Test20d\"=hex(2):25,50,4\\\n"
1440                     "1,54,48,25,00\n"
1441                     "\"Test20e\"=hex(2):25,50,4\\\n"
1442                     "  1,54,48,25,00\n"
1443                     "\"Test20f\"=hex(2):25,50,41,\\;comment\n"
1444                     "  54,48,\\#comment\n"
1445                     "  25,00\n\n");
1446     verify_reg_nonexist(hkey, "Test20a");
1447     verify_reg_nonexist(hkey, "Test20b");
1448     verify_reg_nonexist(hkey, "Test20c");
1449     verify_reg_nonexist(hkey, "Test20d");
1450     verify_reg_nonexist(hkey, "Test20e");
1451     verify_reg_nonexist(hkey, "Test20f");
1452 
1453     exec_import_str("REGEDIT4\n\n"
1454                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1455                     "\"Test21a\"=hex:11,22,33,44\\\n"
1456                     ",55,66,77,88\n"
1457                     "\"Test21b\"=hex:11,22,33,44\\\n"
1458                     "  ,55,66,77,88\n"
1459                     "\"Test21c\"=hex:11,22,33,44\\\n"
1460                     "  55,66,77,88\n"
1461                     "\"Test21d\"=hex:11,22,33,4\\\n"
1462                     "4,55,66,77,88\n"
1463                     "\"Test21e\"=hex:11,22,33,4\\\n"
1464                     "  4,55,66,77,88\n"
1465                     "\"Test21f\"=hex:11,22,33,\\;comment\n"
1466                     "  44,55,66,\\#comment\n"
1467                     "  77,88\n\n");
1468     verify_reg_nonexist(hkey, "Test21a");
1469     verify_reg_nonexist(hkey, "Test21b");
1470     verify_reg_nonexist(hkey, "Test21c");
1471     verify_reg_nonexist(hkey, "Test21d");
1472     verify_reg_nonexist(hkey, "Test21e");
1473     verify_reg_nonexist(hkey, "Test21f");
1474 
1475     /* Test support for characters greater than 0xff */
1476     exec_import_str("REGEDIT4\n\n"
1477                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1478                     "\"Wine22a\"=hex(0):25,50,100,54,48,25,00\n"
1479                     "\"Wine22b\"=hex(0):25,1a4,100,164,124,25,00\n\n");
1480     verify_reg_nonexist(hkey, "Wine22a");
1481     verify_reg_nonexist(hkey, "Wine22b");
1482 
1483     /* Test the effect of backslashes in hex data */
1484     exec_import_str("REGEDIT4\n\n"
1485                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1486                     "\"Wine23a\"=hex(2):25,48\\,4f,4d,45,25,00\n"
1487                     "\"Wine23b\"=hex(2):25,48,\\4f,4d,45,25,00\n"
1488                     "\"Wine23c\"=hex(2):25,48\\ ,4f,4d,45,25,00\n"
1489                     "\"Wine23d\"=hex(2):25,48,\\ 4f,4d,45,25,00\n"
1490                     "\"Wine23e\"=hex(2):\\25,48,4f,4d,45,25,00\n"
1491                     "\"Wine23f\"=hex(2):\\ 25,48,4f,4d,45,25,00\n"
1492                     "\"Wine23g\"=hex(2):25,48,4\\f,4d,45,25,00\n"
1493                     "\"Wine23h\"=hex(2):25,48,4\\\n"
1494                     "  f,4d,45,25,00\n"
1495                     "\"Wine23i\"=hex(2):25,50,\\,41,54,48,25,00\n"
1496                     "\"Wine23j\"=hex(2):25,48,4f,4d,45,25,5c,\\\\\n"
1497                     "  25,50,41,54,48,25,00\n"
1498                     "\"Wine23k\"=hex(2):,\\\n"
1499                     "  25,48,4f,4d,45,25,00\n\n");
1500     verify_reg_nonexist(hkey, "Wine23a");
1501     verify_reg_nonexist(hkey, "Wine23b");
1502     verify_reg_nonexist(hkey, "Wine23c");
1503     verify_reg_nonexist(hkey, "Wine23d");
1504     verify_reg_nonexist(hkey, "Wine23e");
1505     verify_reg_nonexist(hkey, "Wine23f");
1506     verify_reg_nonexist(hkey, "Wine23g");
1507     verify_reg_nonexist(hkey, "Wine23h");
1508     verify_reg_nonexist(hkey, "Wine23i");
1509     verify_reg_nonexist(hkey, "Wine23j");
1510     verify_reg_nonexist(hkey, "Wine23k");
1511 
1512     exec_import_str("REGEDIT4\n\n"
1513                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1514                     "\"Wine24a\"=hex(2):4c,69,6e,65,20,\\\n"
1515                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1]\n");
1516     verify_reg_nonexist(hkey, "Wine24a");
1517     verify_key_nonexist(hkey, "Subkey1");
1518 
1519     exec_import_str("REGEDIT4\n\n"
1520                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1521                     "\"Wine24b\"=hex(2):4c,69,6e,65,20\\\n"
1522                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2]\n");
1523     verify_reg_nonexist(hkey, "Wine24b");
1524     verify_key(hkey, "Subkey2");
1525 
1526     delete_key(hkey, "Subkey2");
1527 
1528     exec_import_str("REGEDIT4\n\n"
1529                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1530                     "\"Wine25a\"=hex(2):4c,69,6e,65,20,\\\n"
1531                     "\"Wine25b\"=\"Test value\"\n"
1532 
1533                     "\"Wine25c\"=hex(2):4c,69,6e,65,20,\\\n"
1534                     ";comment\n"
1535                     "\"Wine25d\"=\"Test value\"\n"
1536 
1537                     "\"Wine25e\"=hex(2):4c,69,6e,65,20,\\\n"
1538                     "#comment\n"
1539                     "\"Wine25f\"=\"Test value\"\n"
1540 
1541                     "\"Wine25g\"=hex(2):4c,69,6e,65,20,\\\n\n"
1542                     "\"Wine25h\"=\"Test value\"\n"
1543 
1544                     "\"Wine25i\"=hex(2):4c,69,6e,65,20\\\n"
1545                     "\"Wine25j\"=\"Test value\"\n\n");
1546     verify_reg_nonexist(hkey, "Wine25a");
1547     verify_reg_nonexist(hkey, "Wine25b");
1548     verify_reg_nonexist(hkey, "Wine25c");
1549     verify_reg_nonexist(hkey, "Wine25d");
1550     verify_reg_nonexist(hkey, "Wine25e");
1551     verify_reg(hkey, "Wine25f", REG_SZ, "Test value", 11, 0);
1552     verify_reg_nonexist(hkey, "Wine25g");
1553     verify_reg_nonexist(hkey, "Wine25h");
1554     verify_reg_nonexist(hkey, "Wine25i");
1555     verify_reg(hkey, "Wine25j", REG_SZ, "Test value", 11, 0);
1556 
1557     exec_import_str("REGEDIT4\n\n"
1558                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1559                     "\"Wine26a\"=hex(2):4c,69,6e,65,20,\\\n"
1560                     "\"Wine26b\"=dword:00000008\n"
1561 
1562                     "\"Wine26c\"=hex(2):4c,69,6e,65,20,\\\n"
1563                     ";comment\n"
1564                     "\"Wine26d\"=dword:00000008\n"
1565 
1566                     "\"Wine26e\"=hex(2):4c,69,6e,65,20,\\\n"
1567                     "#comment\n"
1568                     "\"Wine26f\"=dword:00000008\n"
1569 
1570                     "\"Wine26g\"=hex(2):4c,69,6e,65,20,\\\n\n"
1571                     "\"Wine26h\"=dword:00000008\n"
1572 
1573                     "\"Wine26i\"=hex(2):4c,69,6e,65,20\\\n"
1574                     "\"Wine26j\"=dword:00000008\n\n");
1575     verify_reg_nonexist(hkey, "Wine26a");
1576     verify_reg_nonexist(hkey, "Wine26b");
1577     verify_reg_nonexist(hkey, "Wine26c");
1578     verify_reg_nonexist(hkey, "Wine26d");
1579     verify_reg_nonexist(hkey, "Wine26e");
1580     verify_reg(hkey, "Wine26f", REG_DWORD, &dword, sizeof(dword), 0);
1581     verify_reg_nonexist(hkey, "Wine26g");
1582     verify_reg_nonexist(hkey, "Wine26h");
1583     verify_reg_nonexist(hkey, "Wine26i");
1584     verify_reg(hkey, "Wine26j", REG_DWORD, &dword, sizeof(dword), 0);
1585 
1586     exec_import_str("REGEDIT4\n\n"
1587                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1588                     "\"Wine27a\"=hex(2):25,48,4f,4d,45,25,5c,\\\n"
1589                     "\"Wine27b\"=hex(2):25,50,41,54,48,25,00\n"
1590 
1591                     "\"Wine27c\"=hex(2):25,48,4f,4d,45,25,5c,\\\n"
1592                     ";comment\n"
1593                     "\"Wine27d\"=hex(2):25,50,41,54,48,25,00\n"
1594 
1595                     "\"Wine27e\"=hex(2):25,48,4f,4d,45,25,5c,\\\n"
1596                     "#comment\n"
1597                     "\"Wine27f\"=hex(2):25,50,41,54,48,25,00\n"
1598 
1599                     "\"Wine27g\"=hex(2):25,48,4f,4d,45,25,5c,\\\n\n"
1600                     "\"Wine27h\"=hex(2):25,50,41,54,48,25,00\n"
1601 
1602                     "\"Wine27i\"=hex(2):25,48,4f,4d,45,25,5c\\\n"
1603                     "\"Wine27j\"=hex(2):25,50,41,54,48,25,00\n\n");
1604     verify_reg_nonexist(hkey, "Wine27a");
1605     verify_reg_nonexist(hkey, "Wine27b");
1606     verify_reg_nonexist(hkey, "Wine27c");
1607     verify_reg_nonexist(hkey, "Wine27d");
1608     verify_reg_nonexist(hkey, "Wine27e");
1609     verify_reg(hkey, "Wine27f", REG_EXPAND_SZ, "%PATH%", 7, 0);
1610     verify_reg_nonexist(hkey, "Wine27g");
1611     verify_reg_nonexist(hkey, "Wine27h");
1612     verify_reg_nonexist(hkey, "Wine27i");
1613     verify_reg(hkey, "Wine27j", REG_EXPAND_SZ, "%PATH%", 7, 0);
1614 
1615     exec_import_str("REGEDIT4\n\n"
1616                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1617                     "\"Wine28a\"=hex(2):4c,69,6e,65,20,\\\n"
1618                     "@=\"Default value 1\"\n\n");
1619     verify_reg_nonexist(hkey, "Wine28a");
1620     verify_reg_nonexist(hkey, NULL);
1621 
1622     exec_import_str("REGEDIT4\n\n"
1623                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1624                     "\"Wine28b\"=hex(2):4c,69,6e,65,20,\\\n"
1625                     ";comment\n"
1626                     "@=\"Default value 2\"\n\n");
1627     verify_reg_nonexist(hkey, "Wine28b");
1628     verify_reg_nonexist(hkey, NULL);
1629 
1630     exec_import_str("REGEDIT4\n\n"
1631                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1632                     "\"Wine28c\"=hex(2):4c,69,6e,65,20,\\\n"
1633                     "#comment\n"
1634                     "@=\"Default value 3\"\n\n");
1635     verify_reg_nonexist(hkey, "Wine28c");
1636     verify_reg(hkey, NULL, REG_SZ, "Default value 3", 16, 0);
1637 
1638     delete_value(hkey, NULL);
1639 
1640     exec_import_str("REGEDIT4\n\n"
1641                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1642                     "\"Wine28d\"=hex(2):4c,69,6e,65,20,\\\n\n"
1643                     "@=\"Default value 4\"\n\n");
1644     verify_reg_nonexist(hkey, "Wine28d");
1645     verify_reg_nonexist(hkey, NULL);
1646 
1647     exec_import_str("REGEDIT4\n\n"
1648                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1649                     "\"Wine28e\"=hex(2):4c,69,6e,65,20\\\n"
1650                     "@=\"Default value 5\"\n\n");
1651     verify_reg_nonexist(hkey, "Wine28e");
1652     verify_reg(hkey, NULL, REG_SZ, "Default value 5", 16, 0);
1653 
1654     exec_import_str("REGEDIT4\n\n"
1655                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1656                     "\"Wine29a\"=hex:11,22,33,\\\n"
1657                     "\\\n"
1658                     "  44,55,66\n"
1659                     "\"Wine29b\"=hex:11,22,33,\\\n"
1660                     "  \\\n"
1661                     "  44,55,66\n\n");
1662     verify_reg_nonexist(hkey, "Wine29a");
1663     verify_reg_nonexist(hkey, "Wine29b");
1664 
1665     exec_import_str("REGEDIT4\n\n"
1666                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1667                     "\"Wine30a\"=hex(0):25,48,4f,4d,45,25,5c,/\n"
1668                     "  25,50,41,54,48,25,00\n"
1669                     "\"Wine30b\"=hex(0):25,48,4f,4d,45,25,5c/\n"
1670                     "  25,50,41,54,48,25,00\n\n");
1671     verify_reg_nonexist(hkey, "Wine30a");
1672     verify_reg_nonexist(hkey, "Wine30b");
1673 
1674     exec_import_str("REGEDIT4\n\n"
1675                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1676                     "\"Wine31\"=hex(7):4c,69,6e,65,20\\");
1677     verify_reg_nonexist(hkey, "Wine31");
1678 
1679     exec_import_str("REGEDIT4\n\n"
1680                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1681                     "\"Wine32a\"=hex(7):4c,69,6e,65,20,\\\n"
1682                     "  ,63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n"
1683                     "\"Wine32b\"=hex(7):4c,69,6e,65,20,\\\n"
1684                     "  63,,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n\n");
1685     verify_reg_nonexist(hkey, "Wine32a");
1686     verify_reg_nonexist(hkey, "Wine32b");
1687 
1688     /* Test with embedded null characters */
1689     exec_import_str("REGEDIT4\n\n"
1690                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1691                     "\"Wine33a\"=\"\\0\"\n"
1692                     "\"Wine33b\"=\"\\0\\0\"\n"
1693                     "\"Wine33c\"=\"Value1\\0\"\n"
1694                     "\"Wine33d\"=\"Value2\\0\\0\\0\\0\"\n"
1695                     "\"Wine33e\"=\"Value3\\0Value4\"\n"
1696                     "\"Wine33f\"=\"\\0Value5\"\n\n");
1697     verify_reg_nonexist(hkey, "Wine33a");
1698     verify_reg_nonexist(hkey, "Wine33b");
1699     verify_reg_nonexist(hkey, "Wine33c");
1700     verify_reg_nonexist(hkey, "Wine33d");
1701     verify_reg_nonexist(hkey, "Wine33e");
1702     verify_reg_nonexist(hkey, "Wine33f");
1703 
1704     close_key(hkey);
1705 
1706     delete_key(HKEY_CURRENT_USER, KEY_BASE);
1707 }
1708 
1709 static void test_invalid_import_unicode(void)
1710 {
1711     HKEY hkey;
1712     DWORD dword = 0x8;
1713 
1714     delete_tree(HKEY_CURRENT_USER, KEY_BASE);
1715     verify_key_nonexist(HKEY_CURRENT_USER, KEY_BASE);
1716 
1717     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1718                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1719                      "\"TestNoEndQuote\"=\"Asdffdsa\n");
1720     open_key(HKEY_CURRENT_USER, KEY_BASE, KEY_SET_VALUE, &hkey);
1721     verify_reg_nonexist(hkey, "TestNoEndQuote");
1722 
1723     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1724                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1725                      "\"TestNoBeginQuote\"=Asdffdsa\"\n");
1726     verify_reg_nonexist(hkey, "TestNoBeginQuote");
1727 
1728     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1729                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1730                     "\"TestNoQuotes\"=Asdffdsa\n");
1731     verify_reg_nonexist(hkey, "TestNoQuotes");
1732 
1733     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1734                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1735                      "\"NameNoEndQuote=\"Asdffdsa\"\n");
1736     verify_reg_nonexist(hkey, "NameNoEndQuote");
1737 
1738     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1739                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1740                      "NameNoBeginQuote\"=\"Asdffdsa\"\n");
1741     verify_reg_nonexist(hkey, "NameNoBeginQuote");
1742 
1743     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1744                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1745                      "NameNoQuotes=\"Asdffdsa\"\n");
1746     verify_reg_nonexist(hkey, "NameNoQuotes");
1747 
1748     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1749                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1750                      "\"MixedQuotes=Asdffdsa\"\n");
1751     verify_reg_nonexist(hkey, "MixedQuotes");
1752     verify_reg_nonexist(hkey, "MixedQuotes=Asdffdsa");
1753 
1754     /* Test import with non-standard registry file headers */
1755     exec_import_wstr("\xef\xbb\xbfREGEDIT3\n\n"
1756                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1757                      "\"Test1\"=\"Value\"\n");
1758     verify_reg_nonexist(hkey, "Test1");
1759 
1760     exec_import_wstr("\xef\xbb\xbfregedit4\n\n"
1761                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1762                      "\"Test2\"=\"Value\"\n");
1763     verify_reg_nonexist(hkey, "Test2");
1764 
1765     exec_import_wstr("\xef\xbb\xbfRegedit4\n\n"
1766                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1767                      "\"Test3\"=\"Value\"\n");
1768     verify_reg_nonexist(hkey, "Test3");
1769 
1770     exec_import_wstr("\xef\xbb\xbfREGEDIT 4\n\n"
1771                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1772                      "\"Test4\"=\"Value\"\n");
1773     verify_reg_nonexist(hkey, "Test4");
1774 
1775     exec_import_wstr("\xef\xbb\xbfREGEDIT4FOO\n\n"
1776                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1777                      "\"Test5\"=\"Value\"\n");
1778     verify_reg_nonexist(hkey, "Test5");
1779 
1780     exec_import_wstr("\xef\xbb\xbfREGEDIT4 FOO\n\n"
1781                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1782                      "\"Test6\"=\"Value\"\n");
1783     verify_reg_nonexist(hkey, "Test6");
1784 
1785     exec_import_wstr("\xef\xbb\xbfREGEDIT5\n\n"
1786                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1787                      "\"Test7\"=\"Value\"\n");
1788     verify_reg_nonexist(hkey, "Test7");
1789 
1790     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 4.00\n\n"
1791                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1792                      "\"Test8\"=\"Value\"\n");
1793     verify_reg_nonexist(hkey, "Test8");
1794 
1795     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5\n\n"
1796                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1797                      "\"Test9\"=\"Value\"\n");
1798     verify_reg_nonexist(hkey, "Test9");
1799 
1800     exec_import_wstr("\xef\xbb\xbfWINDOWS REGISTRY EDITOR VERSION 5.00\n\n"
1801                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1802                      "\"Test10\"=\"Value\"\n");
1803     verify_reg_nonexist(hkey, "Test10");
1804 
1805     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor version 5.00\n\n"
1806                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1807                      "\"Test11\"=\"Value\"\n");
1808     verify_reg_nonexist(hkey, "Test11");
1809 
1810     /* Test multi-line import with incorrect comma placement */
1811     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1812                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1813                      "\"Multi-Line1\"=hex(7):4c,00,69,00,6e,00,65,00,20,00\\\n"
1814                      ",63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
1815                      "65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n");
1816     verify_reg_nonexist(hkey, "Multi-Line1");
1817 
1818     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1819                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1820                      "\"Multi-Line2\"=hex(7):4c,00,69,00,6e,00,65,00,20,00\\\n"
1821                      "  ,63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
1822                      "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n");
1823     verify_reg_nonexist(hkey, "Multi-Line2");
1824 
1825     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1826                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1827                      "\"Multi-Line3\"=hex(7):4c,00,69,00,6e,00,65,00,20,00\\\n"
1828                      ",63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
1829                      "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n");
1830     verify_reg_nonexist(hkey, "Multi-Line3");
1831 
1832     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1833                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1834                      "\"Multi-Line4\"=hex(7):4c,00,69,00,6e,00,65,00,20,00\\\n"
1835                      ",  63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
1836                      "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n");
1837     verify_reg_nonexist(hkey, "Multi-Line4");
1838 
1839     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1840                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1841                      "\"Test12a\"=dword:\n"
1842                      "\"Test12b\"=dword:hello\n"
1843                      "\"Test12c\"=dword:123456789\n"
1844                      "\"Test12d\"=dword:012345678\n"
1845                      "\"Test12e\"=dword:000000001\n\n");
1846     verify_reg_nonexist(hkey, "Test12a");
1847     verify_reg_nonexist(hkey, "Test12b");
1848     verify_reg_nonexist(hkey, "Test12c");
1849     verify_reg_nonexist(hkey, "Test12d");
1850     verify_reg_nonexist(hkey, "Test12e");
1851 
1852     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1853                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1854                      "\"Test13a\"=dword:12345678abc\n"
1855                      "\"Test13b\"=dword:12345678 abc\n\n");
1856     verify_reg_nonexist(hkey, "Test13a");
1857     verify_reg_nonexist(hkey, "Test13b");
1858 
1859     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1860                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1861                      "\"Test14a\"=dword:0x123\n"
1862                      "\"Test14b\"=dword:123 456\n"
1863                      "\"Test14c\"=dword:1234 5678\n\n");
1864     verify_reg_nonexist(hkey, "Test14a");
1865     verify_reg_nonexist(hkey, "Test14b");
1866     verify_reg_nonexist(hkey, "Test14c");
1867 
1868     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1869                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1870                      "\"Test15a\"=\"foo\"bar\"\n"
1871                      "\"Test15b\"=\"foo\"\"bar\"\n\n");
1872     verify_reg_nonexist(hkey, "Test15a");
1873     verify_reg_nonexist(hkey, "Test15b");
1874 
1875     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1876                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1877                      "\"Test16a\"=\n"
1878                      "\"Test16b\"=\\\"\n"
1879                      "\"Test16c\"=\\\"Value\\\"\n"
1880                      "\"Test16d\"=\\\"Value\"\n\n");
1881     verify_reg_nonexist(hkey, "Test16a");
1882     verify_reg_nonexist(hkey, "Test16b");
1883     verify_reg_nonexist(hkey, "Test16c");
1884     verify_reg_nonexist(hkey, "Test16d");
1885 
1886     /* Test key name and value name concatenation */
1887     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1888                      "[HKEY_CURRENT_USER\\" KEY_BASE "\\\n"
1889                      "Subkey1]\n");
1890     verify_key_nonexist(hkey, "Subkey1");
1891 
1892     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1893                      "[HKEY_CURRENT_USER\\" KEY_BASE "\n"
1894                      "\\Subkey2]\n");
1895     verify_key_nonexist(hkey, "Subkey2");
1896 
1897     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1898                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1899                      "\"Test\\\n"
1900                      "17a\"=\"Value 1\"\n"
1901                      "\"Test17b\"=\"Value 2\"\n"
1902                      "\"Test\n"
1903                      "\\17c\"=\"Value 3\"\n\n");
1904     verify_reg_nonexist(hkey, "Test17a");
1905     verify_reg(hkey, "Test17b", REG_SZ, "Value 2", 8, 0);
1906     verify_reg_nonexist(hkey, "Test17c");
1907 
1908     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1909                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1910                      "\"Test18a\"=dword:1234\\\n"
1911                      "5678\n"
1912                      "\"Test18b\"=\"Test \\\n"
1913                      "Value\"\n\n");
1914     verify_reg_nonexist(hkey, "Test18a");
1915     verify_reg_nonexist(hkey, "Test18b");
1916 
1917     /* Test hex data concatenation for REG_NONE, REG_EXPAND_SZ and REG_BINARY */
1918     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1919                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1920                      "\"Test19a\"=hex(0):56,00,61,00,6c,00\\\n"
1921                      ",75,00,65,00,00,00\n"
1922                      "\"Test19b\"=hex(0):56,00,61,00,6c,00\\\n"
1923                      "  ,75,00,65,00,00,00\n"
1924                      "\"Test19c\"=hex(0):56,00,61,00,6c,00\\\n"
1925                      "  75,00,65,00,00,00\n"
1926                      "\"Test19d\"=hex(0):56,00,61,00,6c,00,7\\\n"
1927                      "5,00,65,00,00,00\n"
1928                      "\"Test19e\"=hex(0):56,00,61,00,6c,00,7\\\n"
1929                      "  5,00,65,00,00,00\n"
1930                      "\"Test19f\"=hex(0):56,00,61,00,\\;comment\n"
1931                      "  6c,00,75,00,\\#comment\n"
1932                      "  65,00,00,00\n\n");
1933     verify_reg_nonexist(hkey, "Test19a");
1934     verify_reg_nonexist(hkey, "Test19b");
1935     verify_reg_nonexist(hkey, "Test19c");
1936     verify_reg_nonexist(hkey, "Test19d");
1937     verify_reg_nonexist(hkey, "Test19e");
1938     verify_reg_nonexist(hkey, "Test19f");
1939 
1940     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1941                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1942                      "\"Test20a\"=hex(2):25,00,50,00,41,00\\\n"
1943                      ",54,00,48,00,25,00,00,00\n"
1944                      "\"Test20b\"=hex(2):25,00,50,00,41,00\\\n"
1945                      "  ,54,00,48,00,25,00,00,00\n"
1946                      "\"Test20c\"=hex(2):25,00,50,00,41,00\\\n"
1947                      "  54,00,48,00,25,00,00,00\n"
1948                      "\"Test20d\"=hex(2):25,00,50,00,4\\\n"
1949                      "1,00,54,00,48,00,25,00,00,00\n"
1950                      "\"Test20e\"=hex(2):25,00,50,00,4\\\n"
1951                      "  1,00,54,00,48,00,25,00,00\n"
1952                      "\"Test20f\"=hex(2):25,00,50,00,41,00,\\;comment\n"
1953                      "  54,00,48,00,\\#comment\n"
1954                      "  25,00,00,00\n\n");
1955     verify_reg_nonexist(hkey, "Test20a");
1956     verify_reg_nonexist(hkey, "Test20b");
1957     verify_reg_nonexist(hkey, "Test20c");
1958     verify_reg_nonexist(hkey, "Test20d");
1959     verify_reg_nonexist(hkey, "Test20e");
1960     verify_reg_nonexist(hkey, "Test20f");
1961 
1962     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1963                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1964                      "\"Test21a\"=hex:11,22,33,44\\\n"
1965                      ",55,66,77,88\n"
1966                      "\"Test21b\"=hex:11,22,33,44\\\n"
1967                      "  ,55,66,77,88\n"
1968                      "\"Test21c\"=hex:11,22,33,44\\\n"
1969                      "  55,66,77,88\n"
1970                      "\"Test21d\"=hex:11,22,33,4\\\n"
1971                      "4,55,66,77,88\n"
1972                      "\"Test21e\"=hex:11,22,33,4\\\n"
1973                      "  4,55,66,77,88\n"
1974                      "\"Test21f\"=hex:11,22,33,\\;comment\n"
1975                      "  44,55,66,\\#comment\n"
1976                      "  77,88\n\n");
1977     verify_reg_nonexist(hkey, "Test21a");
1978     verify_reg_nonexist(hkey, "Test21b");
1979     verify_reg_nonexist(hkey, "Test21c");
1980     verify_reg_nonexist(hkey, "Test21d");
1981     verify_reg_nonexist(hkey, "Test21e");
1982     verify_reg_nonexist(hkey, "Test21f");
1983 
1984     /* Test support for characters greater than 0xff */
1985     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1986                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1987                      "\"Wine22a\"=hex(0):25,50,100,54,48,25,00\n"
1988                      "\"Wine22b\"=hex(0):25,1a4,100,164,124,25,00\n\n");
1989     verify_reg_nonexist(hkey, "Wine22a");
1990     verify_reg_nonexist(hkey, "Wine22b");
1991 
1992     /* Test the effect of backslashes in hex data */
1993     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
1994                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1995                      "\"Wine23a\"=hex(2):25,00,48\\,00,4f,00,4d,00,45,00,25,00,00,00\n"
1996                      "\"Wine23b\"=hex(2):25,00,48,00,\\4f,00,4d,00,45,00,25,00,00,00\n"
1997                      "\"Wine23c\"=hex(2):25,00,48\\ ,00,4f,00,4d,00,45,00,25,00,00,00\n"
1998                      "\"Wine23d\"=hex(2):25,00,48,00,\\ 4f,00,4d,00,45,00,25,00,00,00\n"
1999                      "\"Wine23e\"=hex(2):\\25,00,48,00,4f,00,4d,00,45,00,25,00,00,00\n"
2000                      "\"Wine23f\"=hex(2):\\ 25,00,48,00,4f,00,4d,00,45,00,25,00,00,00\n"
2001                      "\"Wine23g\"=hex(2):25,00,48,00,4\\f,00,4d,00,45,00,25,00,00,00\n"
2002                      "\"Wine23h\"=hex(2):25,00,48,00,4\\\n"
2003                      "  f,00,4d,00,45,00,25,00,00,00\n"
2004                      "\"Wine23i\"=hex(2):25,00,50,00,\\,41,00,54,00,48,00,25,00,00,00\n"
2005                      "\"Wine23j\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00,\\\\\n"
2006                      "  25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"
2007                      "\"Wine23k\"=hex(2):,\\\n"
2008                      "  25,00,48,00,4f,00,4d,00,45,00,25,00,00,00\n\n");
2009     verify_reg_nonexist(hkey, "Wine23a");
2010     verify_reg_nonexist(hkey, "Wine23b");
2011     verify_reg_nonexist(hkey, "Wine23c");
2012     verify_reg_nonexist(hkey, "Wine23d");
2013     verify_reg_nonexist(hkey, "Wine23e");
2014     verify_reg_nonexist(hkey, "Wine23f");
2015     verify_reg_nonexist(hkey, "Wine23g");
2016     verify_reg_nonexist(hkey, "Wine23h");
2017     verify_reg_nonexist(hkey, "Wine23i");
2018     verify_reg_nonexist(hkey, "Wine23j");
2019     verify_reg_nonexist(hkey, "Wine23k");
2020 
2021     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2022                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2023                      "\"Wine24a\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n"
2024                      "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1]\n");
2025     verify_reg_nonexist(hkey, "Wine24a");
2026     verify_key_nonexist(hkey, "Subkey1");
2027 
2028     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2029                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2030                      "\"Wine24b\"=hex(2):4c,00,69,00,6e,00,65,00,20,00\\\n"
2031                      "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2]\n");
2032     verify_reg_nonexist(hkey, "Wine24b");
2033     verify_key(hkey, "Subkey2");
2034 
2035     delete_key(hkey, "Subkey2");
2036 
2037     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2038                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2039                      "\"Wine25a\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n"
2040                      "\"Wine25b\"=\"Test value\"\n"
2041 
2042                      "\"Wine25c\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n"
2043                      ";comment\n"
2044                      "\"Wine25d\"=\"Test value\"\n"
2045 
2046                      "\"Wine25e\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n"
2047                      "#comment\n"
2048                      "\"Wine25f\"=\"Test value\"\n"
2049 
2050                      "\"Wine25g\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n\n"
2051                      "\"Wine25h\"=\"Test value\"\n"
2052 
2053                      "\"Wine25i\"=hex(2):4c,00,69,00,6e,00,65,00,20,00\\\n"
2054                      "\"Wine25j\"=\"Test value\"\n\n");
2055     verify_reg_nonexist(hkey, "Wine25a");
2056     verify_reg_nonexist(hkey, "Wine25b");
2057     verify_reg_nonexist(hkey, "Wine25c");
2058     verify_reg_nonexist(hkey, "Wine25d");
2059     verify_reg_nonexist(hkey, "Wine25e");
2060     verify_reg(hkey, "Wine25f", REG_SZ, "Test value", 11, 0);
2061     verify_reg_nonexist(hkey, "Wine25g");
2062     verify_reg_nonexist(hkey, "Wine25h");
2063     verify_reg_nonexist(hkey, "Wine25i");
2064     verify_reg(hkey, "Wine25j", REG_SZ, "Test value", 11, 0);
2065 
2066     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2067                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2068                      "\"Wine26a\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n"
2069                      "\"Wine26b\"=dword:00000008\n"
2070 
2071                      "\"Wine26c\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n"
2072                      ";comment\n"
2073                      "\"Wine26d\"=dword:00000008\n"
2074 
2075                      "\"Wine26e\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n"
2076                      "#comment\n"
2077                      "\"Wine26f\"=dword:00000008\n"
2078 
2079                      "\"Wine26g\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n\n"
2080                      "\"Wine26h\"=dword:00000008\n"
2081 
2082                      "\"Wine26i\"=hex(2):4c,00,69,00,6e,00,65,00,20,00\\\n"
2083                      "\"Wine26j\"=dword:00000008\n\n");
2084     verify_reg_nonexist(hkey, "Wine26a");
2085     verify_reg_nonexist(hkey, "Wine26b");
2086     verify_reg_nonexist(hkey, "Wine26c");
2087     verify_reg_nonexist(hkey, "Wine26d");
2088     verify_reg_nonexist(hkey, "Wine26e");
2089     verify_reg(hkey, "Wine26f", REG_DWORD, &dword, sizeof(dword), 0);
2090     verify_reg_nonexist(hkey, "Wine26g");
2091     verify_reg_nonexist(hkey, "Wine26h");
2092     verify_reg_nonexist(hkey, "Wine26i");
2093     verify_reg(hkey, "Wine26j", REG_DWORD, &dword, sizeof(dword), 0);
2094 
2095     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2096                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2097                      "\"Wine27a\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00,\\\n"
2098                      "\"Wine27b\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"
2099 
2100                      "\"Wine27c\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00,\\\n"
2101                      ";comment\n"
2102                      "\"Wine27d\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"
2103 
2104                      "\"Wine27e\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00,\\\n"
2105                      "#comment\n"
2106                      "\"Wine27f\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"
2107 
2108                      "\"Wine27g\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00,\\\n\n"
2109                      "\"Wine27h\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"
2110 
2111                      "\"Wine27i\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00\\\n"
2112                      "\"Wine27j\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00\n\n");
2113     verify_reg_nonexist(hkey, "Wine27a");
2114     verify_reg_nonexist(hkey, "Wine27b");
2115     verify_reg_nonexist(hkey, "Wine27c");
2116     verify_reg_nonexist(hkey, "Wine27d");
2117     verify_reg_nonexist(hkey, "Wine27e");
2118     verify_reg(hkey, "Wine27f", REG_EXPAND_SZ, "%PATH%", 7, 0);
2119     verify_reg_nonexist(hkey, "Wine27g");
2120     verify_reg_nonexist(hkey, "Wine27h");
2121     verify_reg_nonexist(hkey, "Wine27i");
2122     verify_reg(hkey, "Wine27j", REG_EXPAND_SZ, "%PATH%", 7, 0);
2123 
2124     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2125                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2126                      "\"Wine28a\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n"
2127                      "@=\"Default value 1\"\n\n");
2128     verify_reg_nonexist(hkey, "Wine28a");
2129     verify_reg_nonexist(hkey, NULL);
2130 
2131     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2132                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2133                      "\"Wine28b\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n"
2134                      ";comment\n"
2135                      "@=\"Default value 2\"\n\n");
2136     verify_reg_nonexist(hkey, "Wine28b");
2137     verify_reg_nonexist(hkey, NULL);
2138 
2139     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2140                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2141                      "\"Wine28c\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n"
2142                      "#comment\n"
2143                      "@=\"Default value 3\"\n\n");
2144     verify_reg_nonexist(hkey, "Wine28c");
2145     verify_reg(hkey, NULL, REG_SZ, "Default value 3", 16, 0);
2146 
2147     delete_value(hkey, NULL);
2148 
2149     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2150                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2151                      "\"Wine28d\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n\n"
2152                      "@=\"Default value 4\"\n\n");
2153     verify_reg_nonexist(hkey, "Wine28d");
2154     verify_reg_nonexist(hkey, NULL);
2155 
2156     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2157                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2158                      "\"Wine28e\"=hex(2):4c,00,69,00,6e,00,65,00,20,00\\\n"
2159                      "@=\"Default value 5\"\n\n");
2160     verify_reg_nonexist(hkey, "Wine28e");
2161     verify_reg(hkey, NULL, REG_SZ, "Default value 5", 16, 0);
2162 
2163     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2164                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2165                      "\"Wine29a\"=hex:11,22,33,\\\n"
2166                      "\\\n"
2167                      "  44,55,66\n"
2168                      "\"Wine29b\"=hex:11,22,33,\\\n"
2169                      "  \\\n"
2170                      "  44,55,66\n\n");
2171     verify_reg_nonexist(hkey, "Wine29a");
2172     verify_reg_nonexist(hkey, "Wine29b");
2173 
2174     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2175                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2176                      "\"Wine30a\"=hex(0):25,48,4f,4d,45,25,5c,/\n"
2177                      "  25,50,41,54,48,25,00\n"
2178                      "\"Wine30b\"=hex(0):25,48,4f,4d,45,25,5c/\n"
2179                      "  25,50,41,54,48,25,00\n\n");
2180     verify_reg_nonexist(hkey, "Wine30a");
2181     verify_reg_nonexist(hkey, "Wine30b");
2182 
2183     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2184                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2185                      "\"Wine31\"=hex(7):4c,00,69,00,6e,00,65,00,20,00\\");
2186     verify_reg_nonexist(hkey, "Wine31");
2187 
2188     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2189                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2190                      "\"Wine32a\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
2191                      "  ,63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
2192                      "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n"
2193                      "\"Wine32b\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
2194                      "  63,00,,6f,00,6e,00,63,00,61,00,74,00,\\\n"
2195                      "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n");
2196     verify_reg_nonexist(hkey, "Wine32a");
2197     verify_reg_nonexist(hkey, "Wine32b");
2198 
2199     /* Test with embedded null characters */
2200     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2201                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2202                      "\"Wine33a\"=\"\\0\"\n"
2203                      "\"Wine33b\"=\"\\0\\0\"\n"
2204                      "\"Wine33c\"=\"Value1\\0\"\n"
2205                      "\"Wine33d\"=\"Value2\\0\\0\\0\\0\"\n"
2206                      "\"Wine33e\"=\"Value3\\0Value4\"\n"
2207                      "\"Wine33f\"=\"\\0Value5\"\n\n");
2208     verify_reg_nonexist(hkey, "Wine33a");
2209     verify_reg_nonexist(hkey, "Wine33b");
2210     verify_reg_nonexist(hkey, "Wine33c");
2211     verify_reg_nonexist(hkey, "Wine33d");
2212     verify_reg_nonexist(hkey, "Wine33e");
2213     verify_reg_nonexist(hkey, "Wine33f");
2214 
2215     close_key(hkey);
2216 
2217     delete_key(HKEY_CURRENT_USER, KEY_BASE);
2218 }
2219 
2220 static void test_invalid_import_31(void)
2221 {
2222     HKEY hkey;
2223     DWORD dispos;
2224 
2225     RegCreateKeyExA(HKEY_CLASSES_ROOT, KEY_BASE, 0, NULL, REG_OPTION_NON_VOLATILE,
2226                      KEY_READ|KEY_SET_VALUE, NULL, &hkey, &dispos);
2227 
2228     if (dispos == REG_OPENED_EXISTING_KEY)
2229         delete_value(hkey, NULL);
2230 
2231     /* Test character validity at the start of the line */
2232     exec_import_str("REGEDIT\r\n"
2233                     " HKEY_CLASSES_ROOT\\" KEY_BASE " = Value1a\r\n");
2234     verify_reg_nonexist(hkey, "");
2235 
2236     exec_import_str("REGEDIT\r\n"
2237                     "  HKEY_CLASSES_ROOT\\" KEY_BASE " = Value1b\r\n");
2238     verify_reg_nonexist(hkey, "");
2239 
2240     exec_import_str("REGEDIT\r\n"
2241                     "\tHKEY_CLASSES_ROOT\\" KEY_BASE " = Value1c\r\n");
2242     verify_reg_nonexist(hkey, "");
2243 
2244     exec_import_str("REGEDIT\r\n"
2245                     ";HKEY_CLASSES_ROOT\\" KEY_BASE " = Value2a\r\n");
2246     verify_reg_nonexist(hkey, "");
2247 
2248     exec_import_str("REGEDIT\r\n"
2249                     "#HKEY_CLASSES_ROOT\\" KEY_BASE " = Value2b\r\n");
2250     verify_reg_nonexist(hkey, "");
2251 
2252     /* Test case sensitivity */
2253     exec_import_str("REGEDIT\r\n"
2254                     "hkey_classes_root\\" KEY_BASE " = Value3a\r\n");
2255     verify_reg_nonexist(hkey, "");
2256 
2257     exec_import_str("REGEDIT\r\n"
2258                     "hKEY_CLASSES_ROOT\\" KEY_BASE " = Value3b\r\n");
2259     verify_reg_nonexist(hkey, "");
2260 
2261     exec_import_str("REGEDIT\r\n"
2262                     "Hkey_Classes_Root\\" KEY_BASE " = Value3c\r\n");
2263     verify_reg_nonexist(hkey, "");
2264 
2265     close_key(hkey);
2266 
2267     delete_key(HKEY_CLASSES_ROOT, KEY_BASE);
2268 }
2269 
2270 static void test_comments(void)
2271 {
2272     HKEY hkey;
2273     DWORD dword;
2274 
2275     delete_tree(HKEY_CURRENT_USER, KEY_BASE);
2276     verify_key_nonexist(HKEY_CURRENT_USER, KEY_BASE);
2277 
2278     exec_import_str("REGEDIT4\n\n"
2279                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2280                     "#comment\\\n"
2281                     "\"Wine1\"=\"Line 1\"\n"
2282                     ";comment\\\n"
2283                     "\"Wine2\"=\"Line 2\"\n\n");
2284     open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
2285     verify_reg(hkey, "Wine1", REG_SZ, "Line 1", 7, 0);
2286     verify_reg(hkey, "Wine2", REG_SZ, "Line 2", 7, 0);
2287 
2288     exec_import_str("REGEDIT4\n\n"
2289                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2290                     "\"Wine3\"=\"Value 1\"#comment\n"
2291                     "\"Wine4\"=\"Value 2\";comment\n"
2292                     "\"Wine5\"=dword:01020304 #comment\n"
2293                     "\"Wine6\"=dword:02040608 ;comment\n\n");
2294     verify_reg_nonexist(hkey, "Wine3");
2295     verify_reg(hkey, "Wine4", REG_SZ, "Value 2", 8, 0);
2296     verify_reg_nonexist(hkey, "Wine5");
2297     dword = 0x2040608;
2298     verify_reg(hkey, "Wine6", REG_DWORD, &dword, sizeof(dword), 0);
2299 
2300     exec_import_str("REGEDIT4\n\n"
2301                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2302                     "\"Wine7\"=hex(7):4c,69,6e,65,20,\\\n"
2303                     "  #comment\n"
2304                     "  63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n"
2305                     "\"Wine8\"=\"A valid line\"\n"
2306                     "\"Wine9\"=hex(7):4c,69,6e,65,20,\\\n"
2307                     "  ;comment\n"
2308                     "  63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n"
2309                     "\"Wine10\"=\"Another valid line\"\n\n");
2310     verify_reg_nonexist(hkey, "Wine7");
2311     verify_reg(hkey, "Wine8", REG_SZ, "A valid line", 13, 0);
2312     verify_reg(hkey, "Wine9", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2313     verify_reg(hkey, "Wine10", REG_SZ, "Another valid line", 19, 0);
2314 
2315     exec_import_str("REGEDIT4\n\n"
2316                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2317                     "#\"Comment1\"=\"Value 1\"\n"
2318                     ";\"Comment2\"=\"Value 2\"\n"
2319                     "    #\"Comment3\"=\"Value 3\"\n"
2320                     "    ;\"Comment4\"=\"Value 4\"\n"
2321                     "\"Wine11\"=\"Value 6\"#\"Comment5\"=\"Value 5\"\n"
2322                     "\"Wine12\"=\"Value 7\";\"Comment6\"=\"Value 6\"\n\n");
2323     verify_reg_nonexist(hkey, "Comment1");
2324     verify_reg_nonexist(hkey, "Comment2");
2325     verify_reg_nonexist(hkey, "Comment3");
2326     verify_reg_nonexist(hkey, "Comment4");
2327     verify_reg_nonexist(hkey, "Wine11");
2328     verify_reg_nonexist(hkey, "Comment5");
2329     verify_reg(hkey, "Wine12", REG_SZ, "Value 7", 8, 0);
2330     verify_reg_nonexist(hkey, "Comment6");
2331 
2332     exec_import_str("REGEDIT4\n\n"
2333                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2334                     "\"Wine13\"=#\"Value 8\"\n"
2335                     "\"Wine14\"=;\"Value 9\"\n"
2336                     "\"Wine15\"=\"#comment1\"\n"
2337                     "\"Wine16\"=\";comment2\"\n"
2338                     "\"Wine17\"=\"Value#comment3\"\n"
2339                     "\"Wine18\"=\"Value;comment4\"\n"
2340                     "\"Wine19\"=\"Value #comment5\"\n"
2341                     "\"Wine20\"=\"Value ;comment6\"\n"
2342                     "\"Wine21\"=#dword:00000001\n"
2343                     "\"Wine22\"=;dword:00000002\n"
2344                     "\"Wine23\"=dword:00000003#comment\n"
2345                     "\"Wine24\"=dword:00000004;comment\n\n");
2346     verify_reg_nonexist(hkey, "Wine13");
2347     verify_reg_nonexist(hkey, "Wine14");
2348     verify_reg(hkey, "Wine15", REG_SZ, "#comment1", 10, 0);
2349     verify_reg(hkey, "Wine16", REG_SZ, ";comment2", 10, 0);
2350     verify_reg(hkey, "Wine17", REG_SZ, "Value#comment3", 15, 0);
2351     verify_reg(hkey, "Wine18", REG_SZ, "Value;comment4", 15, 0);
2352     verify_reg(hkey, "Wine19", REG_SZ, "Value #comment5", 16, 0);
2353     verify_reg(hkey, "Wine20", REG_SZ, "Value ;comment6", 16, 0);
2354     verify_reg_nonexist(hkey, "Wine21");
2355     verify_reg_nonexist(hkey, "Wine22");
2356     verify_reg_nonexist(hkey, "Wine23");
2357     dword = 0x00000004;
2358     verify_reg(hkey, "Wine24", REG_DWORD, &dword, sizeof(dword), 0);
2359 
2360     exec_import_str("REGEDIT4\n\n"
2361                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2362                     "\"Wine25a\"=dword:1234;5678\n"
2363                     "\"Wine25b\"=dword:1234 ;5678\n"
2364                     "\"Wine25c\"=dword:1234#5678\n"
2365                     "\"Wine25d\"=dword:1234 #5678\n\n");
2366     dword = 0x1234;
2367     verify_reg(hkey, "Wine25a", REG_DWORD, &dword, sizeof(dword), 0);
2368     verify_reg(hkey, "Wine25b", REG_DWORD, &dword, sizeof(dword), 0);
2369     verify_reg_nonexist(hkey, "Wine25c");
2370     verify_reg_nonexist(hkey, "Wine25d");
2371 
2372     exec_import_str("REGEDIT4\n\n"
2373                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2374                     "\"Wine26a\"=\"Value1\"  ;comment\n"
2375                     "\"Wine26b\"=\"Value2\"\t\t;comment\n"
2376                     "\"Wine26c\"=\"Value3\"  #comment\n"
2377                     "\"Wine26d\"=\"Value4\"\t\t#comment\n\n");
2378     verify_reg(hkey, "Wine26a", REG_SZ, "Value1", 7, 0);
2379     verify_reg(hkey, "Wine26b", REG_SZ, "Value2", 7, 0);
2380     verify_reg_nonexist(hkey, "Wine26c");
2381     verify_reg_nonexist(hkey, "Wine26d");
2382 
2383     exec_import_str("REGEDIT4\n\n"
2384                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2385                     "\"Multi-Line1\"=hex(7):4c,69,6e,65,20,\\\n"
2386                     "  63,6f,6e,\\;comment\n"
2387                     "  63,61,74,\\;comment\n"
2388                     "  65,6e,61,74,69,6f,6e,00,00\n\n");
2389     verify_reg(hkey, "Multi-Line1", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2390 
2391     exec_import_str("REGEDIT4\n\n"
2392                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2393                     "\"Multi-Line2\"=hex(7):4c,69,6e,65,20,\\\n"
2394                     "  63,6f,6e,\\;comment\n"
2395                     "  63,61,74,;comment\n"
2396                     "  65,6e,61,74,69,6f,6e,00,00\n\n");
2397     verify_reg(hkey, "Multi-Line2", REG_MULTI_SZ, "Line concat", 12, 0);
2398 
2399     exec_import_str("REGEDIT4\n\n"
2400                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2401                     "\"Multi-Line3\"=hex(7):4c,69,6e,\\;comment\n"
2402                     "  65,20,\\;comment\n"
2403                     "  63,6f,6e,\\;comment\n"
2404                     "  63,61,74,\\;comment\n"
2405                     "  65,6e,61,74,69,6f,6e,00,00\n\n");
2406     verify_reg(hkey, "Multi-Line3", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2407 
2408     exec_import_str("REGEDIT4\n\n"
2409                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2410                     "\"Multi-Line4\"=hex(7):4c,69,6e,\\;#comment\n"
2411                     "  65,20,\\;#comment\n"
2412                     "  63,6f,6e,\\;#comment\n"
2413                     "  63,61,74,\\;#comment\n"
2414                     "  65,6e,61,74,69,6f,6e,00,00\n\n");
2415     verify_reg(hkey, "Multi-Line4", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2416 
2417     exec_import_str("REGEDIT4\n\n"
2418                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2419                     "\"Multi-Line5\"=hex(7):4c,69,6e,\\;comment\n"
2420                     "  65,20,\\;comment\n"
2421                     "  63,6f,6e,\\;comment\n"
2422                     "  63,61,74,\\#comment\n"
2423                     "  65,6e,61,74,69,6f,6e,00,00\n\n");
2424     verify_reg_nonexist(hkey, "Multi-Line5");
2425 
2426     exec_import_str("REGEDIT4\n\n"
2427                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2428                     "\"Multi-Line6\"=hex(7):4c,69,6e,65,20,\\\n"
2429                     "  63,6f,6e,\\;comment\n"
2430                     "  63,61,74,\\\n\n"
2431                     "  65,6e,\\;comment\n\n"
2432                     "  61,74,69,6f,6e,00,00\n\n");
2433     verify_reg(hkey, "Multi-Line6", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2434 
2435     exec_import_str("REGEDIT4\n\n"
2436                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2437                     "\"Wine27a\"=hex(2):25,50,41,54,48,25,00  ;comment\n"
2438                     "\"Wine27b\"=hex(2):25,50,41,54,48,25,00\t;comment\n"
2439                     "\"Wine27c\"=hex(2):25,50,41,54,48,25,00  #comment\n"
2440                     "\"Wine27d\"=hex(2):25,50,41,54,48,25,00\t#comment\n\n");
2441     verify_reg(hkey, "Wine27a", REG_EXPAND_SZ, "%PATH%", 7, 0);
2442     verify_reg(hkey, "Wine27b", REG_EXPAND_SZ, "%PATH%", 7, 0);
2443     verify_reg_nonexist(hkey, "Wine27c");
2444     verify_reg_nonexist(hkey, "Wine27d");
2445 
2446     exec_import_str("REGEDIT4\n\n"
2447                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2448                     "\"Wine28a\"=hex(2):25,48,4f,4d,45,25,5c,\\\n"
2449                     "  25,50,41,54,48,25,00\n"
2450                     "\"Wine28b\"=hex(2):25,48,4f,4d,45,25,5c\\\n"
2451                     "  25,50,41,54,48,25,00\n"
2452                     "\"Wine28c\"=hex(2):25,48,4f,4d,45,25,5c,  \\  ;comment\n"
2453                     "  25,50,41,54,48,25,00\n"
2454                     "\"Wine28d\"=hex(2):25,48,4f,4d,45,25,5c  \\  ;comment\n"
2455                     "  25,50,41,54,48,25,00\n"
2456                     "\"Wine28e\"=hex(2):25,48,4f,4d,45,25,5c,\\\t  ;comment\n"
2457                     "  25,50,41,54,48,25,00\n"
2458                     "\"Wine28f\"=hex(2):25,48,4f,4d,45,25,5c\\\t  ;comment\n"
2459                     "  25,50,41,54,48,25,00\n\n");
2460     verify_reg(hkey, "Wine28a", REG_EXPAND_SZ, "%HOME%\\%PATH%", 14, 0);
2461     verify_reg_nonexist(hkey, "Wine28b");
2462     verify_reg(hkey, "Wine28c", REG_EXPAND_SZ, "%HOME%\\%PATH%", 14, 0);
2463     verify_reg_nonexist(hkey, "Wine28d");
2464     verify_reg(hkey, "Wine28e", REG_EXPAND_SZ, "%HOME%\\%PATH%", 14, 0);
2465     verify_reg_nonexist(hkey, "Wine28f");
2466 
2467     exec_import_str("REGEDIT4\n\n"
2468                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2469                     "\"Wine29a\"=hex(7):4c,69,6e,65,20,\\\n"
2470                     "  63,6f,6e,63,61,74,\\\n"
2471                     ";comment\n"
2472                     "  65,6e,\\;comment\n"
2473                     "  61,74,69,6f,6e,00,00\n\n");
2474     verify_reg(hkey, "Wine29a", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2475 
2476     exec_import_str("REGEDIT4\n\n"
2477                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2478                     "\"Wine29b\"=hex(7):4c,69,6e,65,20,\\\n"
2479                     "  63,6f,6e,63,61,74,\\\n"
2480                     "  ;comment\n"
2481                     "  65,6e,\\;comment\n"
2482                     "  61,74,69,6f,6e,00,00\n\n");
2483     verify_reg(hkey, "Wine29b", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2484 
2485     exec_import_str("REGEDIT4\n\n"
2486                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2487                     "\"Wine29c\"=hex(7):4c,69,6e,65,20,\\\n"
2488                     "  63,6f,6e,63,61,74,\\\n"
2489                     "#comment\n"
2490                     "  65,6e,\\;comment\n"
2491                     "  61,74,69,6f,6e,00,00\n\n");
2492     verify_reg_nonexist(hkey, "Wine29c");
2493 
2494     exec_import_str("REGEDIT4\n\n"
2495                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2496                     "\"Wine29d\"=hex(7):4c,69,6e,65,20,\\\n"
2497                     "  63,6f,6e,63,61,74,\\\n"
2498                     "  #comment\n"
2499                     "  65,6e,\\;comment\n"
2500                     "  61,74,69,6f,6e,00,00\n\n");
2501     verify_reg_nonexist(hkey, "Wine29d");
2502 
2503     close_key(hkey);
2504 
2505     delete_key(HKEY_CURRENT_USER, KEY_BASE);
2506 }
2507 
2508 static void test_comments_unicode(void)
2509 {
2510     HKEY hkey;
2511     DWORD dword;
2512 
2513     delete_tree(HKEY_CURRENT_USER, KEY_BASE);
2514     verify_key_nonexist(HKEY_CURRENT_USER, KEY_BASE);
2515 
2516     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2517                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2518                      "#comment\\\n"
2519                      "\"Wine1\"=\"Line 1\"\n"
2520                      ";comment\\\n"
2521                      "\"Wine2\"=\"Line 2\"\n\n");
2522     open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
2523     verify_reg(hkey, "Wine1", REG_SZ, "Line 1", 7, 0);
2524     verify_reg(hkey, "Wine2", REG_SZ, "Line 2", 7, 0);
2525 
2526     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2527                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2528                      "\"Wine3\"=\"Value 1\"#comment\n"
2529                      "\"Wine4\"=\"Value 2\";comment\n"
2530                      "\"Wine5\"=dword:01020304 #comment\n"
2531                      "\"Wine6\"=dword:02040608 ;comment\n\n");
2532     verify_reg_nonexist(hkey, "Wine3");
2533     verify_reg(hkey, "Wine4", REG_SZ, "Value 2", 8, 0);
2534     verify_reg_nonexist(hkey, "Wine5");
2535     dword = 0x2040608;
2536     verify_reg(hkey, "Wine6", REG_DWORD, &dword, sizeof(dword), 0);
2537 
2538     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2539                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2540                      "\"Wine7\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
2541                      "  #comment\n"
2542                      "  63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
2543                      "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n"
2544                      "\"Wine8\"=\"A valid line\"\n"
2545                      "\"Wine9\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
2546                      "  ;comment\n"
2547                      "  63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
2548                      "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n"
2549                      "\"Wine10\"=\"Another valid line\"\n\n");
2550     verify_reg_nonexist(hkey, "Wine7");
2551     verify_reg(hkey, "Wine8", REG_SZ, "A valid line", 13, 0);
2552     verify_reg(hkey, "Wine9", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2553     verify_reg(hkey, "Wine10", REG_SZ, "Another valid line", 19, 0);
2554 
2555     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2556                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2557                      "#\"Comment1\"=\"Value 1\"\n"
2558                      ";\"Comment2\"=\"Value 2\"\n"
2559                      "    #\"Comment3\"=\"Value 3\"\n"
2560                      "    ;\"Comment4\"=\"Value 4\"\n"
2561                      "\"Wine11\"=\"Value 6\"#\"Comment5\"=\"Value 5\"\n"
2562                      "\"Wine12\"=\"Value 7\";\"Comment6\"=\"Value 6\"\n\n");
2563     verify_reg_nonexist(hkey, "Comment1");
2564     verify_reg_nonexist(hkey, "Comment2");
2565     verify_reg_nonexist(hkey, "Comment3");
2566     verify_reg_nonexist(hkey, "Comment4");
2567     verify_reg_nonexist(hkey, "Wine11");
2568     verify_reg_nonexist(hkey, "Comment5");
2569     verify_reg(hkey, "Wine12", REG_SZ, "Value 7", 8, 0);
2570     verify_reg_nonexist(hkey, "Comment6");
2571 
2572     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2573                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2574                      "\"Wine13\"=#\"Value 8\"\n"
2575                      "\"Wine14\"=;\"Value 9\"\n"
2576                      "\"Wine15\"=\"#comment1\"\n"
2577                      "\"Wine16\"=\";comment2\"\n"
2578                      "\"Wine17\"=\"Value#comment3\"\n"
2579                      "\"Wine18\"=\"Value;comment4\"\n"
2580                      "\"Wine19\"=\"Value #comment5\"\n"
2581                      "\"Wine20\"=\"Value ;comment6\"\n"
2582                      "\"Wine21\"=#dword:00000001\n"
2583                      "\"Wine22\"=;dword:00000002\n"
2584                      "\"Wine23\"=dword:00000003#comment\n"
2585                      "\"Wine24\"=dword:00000004;comment\n\n");
2586     verify_reg_nonexist(hkey, "Wine13");
2587     verify_reg_nonexist(hkey, "Wine14");
2588     verify_reg(hkey, "Wine15", REG_SZ, "#comment1", 10, 0);
2589     verify_reg(hkey, "Wine16", REG_SZ, ";comment2", 10, 0);
2590     verify_reg(hkey, "Wine17", REG_SZ, "Value#comment3", 15, 0);
2591     verify_reg(hkey, "Wine18", REG_SZ, "Value;comment4", 15, 0);
2592     verify_reg(hkey, "Wine19", REG_SZ, "Value #comment5", 16, 0);
2593     verify_reg(hkey, "Wine20", REG_SZ, "Value ;comment6", 16, 0);
2594     verify_reg_nonexist(hkey, "Wine21");
2595     verify_reg_nonexist(hkey, "Wine22");
2596     verify_reg_nonexist(hkey, "Wine23");
2597     dword = 0x00000004;
2598     verify_reg(hkey, "Wine24", REG_DWORD, &dword, sizeof(dword), 0);
2599 
2600     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2601                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2602                      "\"Wine25a\"=dword:1234;5678\n"
2603                      "\"Wine25b\"=dword:1234 ;5678\n"
2604                      "\"Wine25c\"=dword:1234#5678\n"
2605                      "\"Wine25d\"=dword:1234 #5678\n\n");
2606     dword = 0x1234;
2607     verify_reg(hkey, "Wine25a", REG_DWORD, &dword, sizeof(dword), 0);
2608     verify_reg(hkey, "Wine25b", REG_DWORD, &dword, sizeof(dword), 0);
2609     verify_reg_nonexist(hkey, "Wine25c");
2610     verify_reg_nonexist(hkey, "Wine25d");
2611 
2612     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2613                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2614                      "\"Wine26a\"=\"Value1\"  ;comment\n"
2615                      "\"Wine26b\"=\"Value2\"\t\t;comment\n"
2616                      "\"Wine26c\"=\"Value3\"  #comment\n"
2617                      "\"Wine26d\"=\"Value4\"\t\t#comment\n\n");
2618     verify_reg(hkey, "Wine26a", REG_SZ, "Value1", 7, 0);
2619     verify_reg(hkey, "Wine26b", REG_SZ, "Value2", 7, 0);
2620     verify_reg_nonexist(hkey, "Wine26c");
2621     verify_reg_nonexist(hkey, "Wine26d");
2622 
2623     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2624                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2625                      "\"Multi-Line1\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
2626                      "  63,00,6f,00,6e,00,\\;comment\n"
2627                      "  63,00,61,00,74,00,\\;comment\n"
2628                      "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n");
2629     verify_reg(hkey, "Multi-Line1", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2630 
2631     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2632                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2633                      "\"Multi-Line2\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
2634                      "  63,00,6f,00,6e,00,\\;comment\n"
2635                      "  63,00,61,00,74,00,;comment\n"
2636                      "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n");
2637     verify_reg(hkey, "Multi-Line2", REG_MULTI_SZ, "Line concat", 12, 0);
2638 
2639     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2640                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2641                      "\"Multi-Line3\"=hex(7):4c,00,69,00,6e,00,\\;comment\n"
2642                      "  65,00,20,00,\\;comment\n"
2643                      "  63,00,6f,00,6e,00,\\;comment\n"
2644                      "  63,00,61,00,74,00,\\;comment\n"
2645                      "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n");
2646     verify_reg(hkey, "Multi-Line3", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2647 
2648     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2649                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2650                      "\"Multi-Line4\"=hex(7):4c,00,69,00,6e,00,\\;#comment\n"
2651                      "  65,00,20,00,\\;#comment\n"
2652                      "  63,00,6f,00,6e,00,\\;#comment\n"
2653                      "  63,00,61,00,74,00,\\;#comment\n"
2654                      "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n");
2655     verify_reg(hkey, "Multi-Line4", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2656 
2657     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2658                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2659                      "\"Multi-Line5\"=hex(7):4c,00,69,00,6e,00,\\;comment\n"
2660                      "  65,00,20,00,\\;comment\n"
2661                      "  63,00,6f,00,6e,00,\\;comment\n"
2662                      "  63,00,61,00,74,00,\\#comment\n"
2663                      "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n");
2664     verify_reg_nonexist(hkey, "Multi-Line5");
2665 
2666     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2667                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2668                      "\"Multi-Line6\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
2669                      "  63,00,6f,00,6e,00,\\;comment\n"
2670                      "  63,00,61,00,74,00,\\\n\n"
2671                      "  65,00,6e,00,\\;comment\n\n"
2672                      "  61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n");
2673     verify_reg(hkey, "Multi-Line6", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2674 
2675     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2676                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2677                      "\"Wine27a\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00  ;comment\n"
2678                      "\"Wine27b\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00\t;comment\n"
2679                      "\"Wine27c\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00  #comment\n"
2680                      "\"Wine27d\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00\t#comment\n\n");
2681     verify_reg(hkey, "Wine27a", REG_EXPAND_SZ, "%PATH%", 7, 0);
2682     verify_reg(hkey, "Wine27b", REG_EXPAND_SZ, "%PATH%", 7, 0);
2683     verify_reg_nonexist(hkey, "Wine27c");
2684     verify_reg_nonexist(hkey, "Wine27d");
2685 
2686     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2687                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2688                      "\"Wine28a\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00,\\\n"
2689                      "  25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"
2690                      "\"Wine28b\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00\\\n"
2691                      "  25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"
2692                      "\"Wine28c\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00,  \\  ;comment\n"
2693                      "  25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"
2694                      "\"Wine28d\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00  \\  ;comment\n"
2695                      "  25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"
2696                      "\"Wine28e\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00,\\\t  ;comment\n"
2697                      "  25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"
2698                      "\"Wine28f\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00\\\t  ;comment\n"
2699                      "  25,00,50,00,41,00,54,00,48,00,25,00,00,00\n\n");
2700     verify_reg(hkey, "Wine28a", REG_EXPAND_SZ, "%HOME%\\%PATH%", 14, 0);
2701     verify_reg_nonexist(hkey, "Wine28b");
2702     verify_reg(hkey, "Wine28c", REG_EXPAND_SZ, "%HOME%\\%PATH%", 14, 0);
2703     verify_reg_nonexist(hkey, "Wine28d");
2704     verify_reg(hkey, "Wine28e", REG_EXPAND_SZ, "%HOME%\\%PATH%", 14, 0);
2705     verify_reg_nonexist(hkey, "Wine28f");
2706 
2707     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2708                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2709                      "\"Wine29a\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
2710                      "  63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
2711                      ";comment\n"
2712                      "  65,00,6e,00,\\;comment\n"
2713                      "  61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n");
2714     verify_reg(hkey, "Wine29a", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2715 
2716     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2717                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2718                      "\"Wine29b\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
2719                      "  63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
2720                      "  ;comment\n"
2721                      "  65,00,6e,00,\\;comment\n"
2722                      "  61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n");
2723     verify_reg(hkey, "Wine29b", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2724 
2725     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2726                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2727                      "\"Wine29c\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
2728                      "  63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
2729                      "#comment\n"
2730                      "  65,00,6e,00,\\;comment\n"
2731                      "  61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n");
2732     verify_reg_nonexist(hkey, "Wine29c");
2733 
2734     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2735                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2736                      "\"Wine29d\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
2737                      "  63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
2738                      "  #comment\n"
2739                      "  65,00,6e,00,\\;comment\n"
2740                      "  61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n");
2741     verify_reg_nonexist(hkey, "Wine29d");
2742 
2743     close_key(hkey);
2744 
2745     delete_key(HKEY_CURRENT_USER, KEY_BASE);
2746 }
2747 
2748 static void test_import_with_whitespace(void)
2749 {
2750     HKEY hkey;
2751     DWORD dword;
2752 
2753     delete_tree(HKEY_CURRENT_USER, KEY_BASE);
2754     verify_key_nonexist(HKEY_CURRENT_USER, KEY_BASE);
2755 
2756     exec_import_str("  REGEDIT4\n\n"
2757                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n\n");
2758 
2759     open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
2760 
2761     exec_import_str("  REGEDIT4\n\n"
2762                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2763                     "\"Wine1a\"=\"Value\"\n\n");
2764     verify_reg(hkey, "Wine1a", REG_SZ, "Value", 6, 0);
2765 
2766     exec_import_str("\tREGEDIT4\n\n"
2767                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2768                     "\"Wine1b\"=\"Value\"\n\n");
2769     verify_reg(hkey, "Wine1b", REG_SZ, "Value", 6, 0);
2770 
2771     exec_import_str(" \t REGEDIT4\n\n"
2772                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2773                     "\"Wine1c\"=\"Value\"\n\n");
2774     verify_reg(hkey, "Wine1c", REG_SZ, "Value", 6, 0);
2775 
2776     exec_import_str("REGEDIT4\n\n"
2777                     "  [HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2778                     "\"Wine2a\"=\"Value\"\n\n");
2779     verify_reg(hkey, "Wine2a", REG_SZ, "Value", 6, 0);
2780 
2781     exec_import_str("REGEDIT4\n\n"
2782                     "\t[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2783                     "\"Wine2b\"=\"Value\"\n\n");
2784     verify_reg(hkey, "Wine2b", REG_SZ, "Value", 6, 0);
2785 
2786     exec_import_str("REGEDIT4\n\n"
2787                     " \t [HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2788                     "\"Wine2c\"=\"Value\"\n\n");
2789     verify_reg(hkey, "Wine2c", REG_SZ, "Value", 6, 0);
2790 
2791     exec_import_str("REGEDIT4\n\n"
2792                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2793                     "  \"Wine3a\"=\"Two leading spaces\"\n\n");
2794     verify_reg(hkey, "Wine3a", REG_SZ, "Two leading spaces", 19, 0);
2795 
2796     exec_import_str("REGEDIT4\n\n"
2797                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2798                     "\t\"Wine3b\"=\"One leading tab\"\n\n");
2799     verify_reg(hkey, "Wine3b", REG_SZ, "One leading tab", 16, 0);
2800 
2801     exec_import_str("REGEDIT4\n\n"
2802                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2803                     " \t \"Wine3c\"=\"Space, tab, space\"\n\n");
2804     verify_reg(hkey, "Wine3c", REG_SZ, "Space, tab, space", 18, 0);
2805 
2806     exec_import_str("                    REGEDIT4\n\n"
2807                     "\t\t\t[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2808                     "\t    \"Wine4a\"=\"Tab and four spaces\"\n"
2809                     "    \"Wine4b\"=dword:00112233\n"
2810                     "\t  \t  \t  \t  \t  \t  \"Wine4c\"=hex(7):4c,69,6e,65,20,\\\n"
2811                     "        63,6f,6e,\\;comment\n"
2812                     "\t\t\t\t63,61,74,\\;comment\n"
2813                     "  \t65,6e,61,74,69,6f,6e,00,00\n\n");
2814     verify_reg(hkey, "Wine4a", REG_SZ, "Tab and four spaces", 20, 0);
2815     dword = 0x112233;
2816     verify_reg(hkey, "Wine4b", REG_DWORD, &dword, sizeof(dword), 0);
2817     verify_reg(hkey, "Wine4c", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2818 
2819     exec_import_str("    REGEDIT4\n\n"
2820                     "\t[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2821                     "  \"Wine5a\"=\"Leading spaces\"\n"
2822                     "\t\t\"Wine5b\"\t\t=\"Leading tabs\"\n"
2823                     "\t  \"Wine5c\"=\t  \"Tabs and spaces\"\n"
2824                     "    \"Wine5d\"    \t    =    \t    \"More whitespace\"\n\n");
2825     verify_reg(hkey, "Wine5a", REG_SZ, "Leading spaces", 15, 0);
2826     verify_reg(hkey, "Wine5b", REG_SZ, "Leading tabs", 13, 0);
2827     verify_reg(hkey, "Wine5c", REG_SZ, "Tabs and spaces", 16, 0);
2828     verify_reg(hkey, "Wine5d", REG_SZ, "More whitespace", 16, 0);
2829 
2830     exec_import_str("REGEDIT4\n\n"
2831                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2832                     "\"  Wine6a\"=\"Leading spaces\"\n"
2833                     "\"\t\tWine6b\"=\"Leading tabs\"\n"
2834                     "  \"  Wine6c  \"  =  \"  Spaces everywhere  \"  \n\n");
2835     verify_reg(hkey, "  Wine6a", REG_SZ, "Leading spaces", 15, 0);
2836     verify_reg(hkey, "\t\tWine6b", REG_SZ, "Leading tabs", 13, 0);
2837     verify_reg(hkey, "  Wine6c  ", REG_SZ, "  Spaces everywhere  ", 22, 0);
2838 
2839     exec_import_str("REGEDIT4\n\n"
2840                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2841                     "\"Wine7a\"=\"    Four spaces in the data\"\n"
2842                     "\"Wine7b\"=\"\t\tTwo tabs in the data\"\n\n");
2843     verify_reg(hkey, "Wine7a", REG_SZ, "    Four spaces in the data", 28, 0);
2844     verify_reg(hkey, "Wine7b", REG_SZ, "\t\tTwo tabs in the data", 23, 0);
2845 
2846     exec_import_str("REGEDIT4\n\n"
2847                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2848                     "\"Wine8a\"=\"Trailing spaces\"    \n"
2849                     "\"Wine8b\"=\"Trailing tabs and spaces\"\t  \t\n\n");
2850     verify_reg(hkey, "Wine8a", REG_SZ, "Trailing spaces", 16, 0);
2851     verify_reg(hkey, "Wine8b", REG_SZ, "Trailing tabs and spaces", 25, 0);
2852 
2853     exec_import_str("REGEDIT4\n\n"
2854                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2855                     "\"Wine9a\"=dword:  00000008\n"
2856                     "\"Wine9b\"=dword:\t\t00000008\n\n");
2857     dword = 0x00000008;
2858     verify_reg(hkey, "Wine9a", REG_DWORD, &dword, sizeof(dword), 0);
2859     verify_reg(hkey, "Wine9b", REG_DWORD, &dword, sizeof(dword), 0);
2860 
2861     exec_import_str("REGEDIT4\n\n"
2862                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2863                     "@  =  \"Test Value\"\n\n");
2864     verify_reg(hkey, "", REG_SZ, "Test Value", 11, 0);
2865 
2866     exec_import_str("REGEDIT4\n\n"
2867                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2868                     "\t@\t=\tdword:\t00000008\t\n\n");
2869     verify_reg(hkey, "", REG_DWORD, &dword, sizeof(DWORD), 0);
2870 
2871     exec_import_str("REGEDIT4\n\n"
2872                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2873                     "\"Wine10a\"=hex(7):4c,69,6e,65,20,\\\n"
2874                     "  63,6f,6e,\\\n\n"
2875                     "  63,61,74,\\\n\n\n"
2876                     "  65,6e,\\\n\n\n\n"
2877                     "  61,74,69,6f,6e,00,00\n\n");
2878     verify_reg(hkey, "Wine10a", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2879 
2880     exec_import_str("REGEDIT4\n\n"
2881                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2882                     "\"Wine10b\"=hex(7):4c,69,6e,65,20,\\\n"
2883                     "  63,6f,6e,\\\n \n"
2884                     "  63,61,74,\\\n\t\n\t\n"
2885                     "  65,6e,\\\n\t \t\n\t \t\n\t \t\n"
2886                     "  61,74,69,6f,6e,00,00\n\n");
2887     verify_reg(hkey, "Wine10b", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2888 
2889     close_key(hkey);
2890 
2891     delete_key(HKEY_CURRENT_USER, KEY_BASE);
2892 }
2893 
2894 static void test_import_with_whitespace_unicode(void)
2895 {
2896     HKEY hkey;
2897     DWORD dword;
2898 
2899     delete_tree(HKEY_CURRENT_USER, KEY_BASE);
2900     verify_key_nonexist(HKEY_CURRENT_USER, KEY_BASE);
2901 
2902     exec_import_wstr("\xef\xbb\xbf  Windows Registry Editor Version 5.00\n\n"
2903                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n\n");
2904 
2905     open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
2906 
2907     exec_import_wstr("\xef\xbb\xbf  Windows Registry Editor Version 5.00\n\n"
2908                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2909                      "\"Wine1a\"=\"Value\"\n\n");
2910     verify_reg(hkey, "Wine1a", REG_SZ, "Value", 6, 0);
2911 
2912     exec_import_wstr("\xef\xbb\xbf\tWindows Registry Editor Version 5.00\n\n"
2913                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2914                      "\"Wine1b\"=\"Value\"\n\n");
2915     verify_reg(hkey, "Wine1b", REG_SZ, "Value", 6, 0);
2916 
2917     exec_import_wstr("\xef\xbb\xbf \t Windows Registry Editor Version 5.00\n\n"
2918                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2919                      "\"Wine1c\"=\"Value\"\n\n");
2920     verify_reg(hkey, "Wine1c", REG_SZ, "Value", 6, 0);
2921 
2922     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2923                      "  [HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2924                      "\"Wine2a\"=\"Value\"\n\n");
2925     verify_reg(hkey, "Wine2a", REG_SZ, "Value", 6, 0);
2926 
2927     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2928                      "\t[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2929                      "\"Wine2b\"=\"Value\"\n\n");
2930     verify_reg(hkey, "Wine2b", REG_SZ, "Value", 6, 0);
2931 
2932     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2933                      " \t [HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2934                      "\"Wine2c\"=\"Value\"\n\n");
2935     verify_reg(hkey, "Wine2c", REG_SZ, "Value", 6, 0);
2936 
2937     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2938                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2939                      "  \"Wine3a\"=\"Two leading spaces\"\n\n");
2940     verify_reg(hkey, "Wine3a", REG_SZ, "Two leading spaces", 19, 0);
2941 
2942     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2943                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2944                      "\t\"Wine3b\"=\"One leading tab\"\n\n");
2945     verify_reg(hkey, "Wine3b", REG_SZ, "One leading tab", 16, 0);
2946 
2947     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2948                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2949                      " \t \"Wine3c\"=\"Space, tab, space\"\n\n");
2950     verify_reg(hkey, "Wine3c", REG_SZ, "Space, tab, space", 18, 0);
2951 
2952     exec_import_wstr("\xef\xbb\xbf                    Windows Registry Editor Version 5.00\n\n"
2953                      "\t\t\t[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2954                      "\t    \"Wine4a\"=\"Tab and four spaces\"\n"
2955                      "    \"Wine4b\"=dword:00112233\n"
2956                      "\t  \t  \t  \t  \t  \t  \"Wine4c\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
2957                      "        63,00,6f,00,6e,00,\\;comment\n"
2958                      "\t\t\t\t63,00,61,00,74,00,\\;comment\n"
2959                      "  \t65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n");
2960     verify_reg(hkey, "Wine4a", REG_SZ, "Tab and four spaces", 20, 0);
2961     dword = 0x112233;
2962     verify_reg(hkey, "Wine4b", REG_DWORD, &dword, sizeof(dword), 0);
2963     verify_reg(hkey, "Wine4c", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2964 
2965     exec_import_wstr("\xef\xbb\xbf    Windows Registry Editor Version 5.00\n\n"
2966                      "\t[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2967                      "  \"Wine5a\"=\"Leading spaces\"\n"
2968                      "\t\t\"Wine5b\"\t\t=\"Leading tabs\"\n"
2969                      "\t  \"Wine5c\"=\t  \"Tabs and spaces\"\n"
2970                      "    \"Wine5d\"    \t    =    \t    \"More whitespace\"\n\n");
2971     verify_reg(hkey, "Wine5a", REG_SZ, "Leading spaces", 15, 0);
2972     verify_reg(hkey, "Wine5b", REG_SZ, "Leading tabs", 13, 0);
2973     verify_reg(hkey, "Wine5c", REG_SZ, "Tabs and spaces", 16, 0);
2974     verify_reg(hkey, "Wine5d", REG_SZ, "More whitespace", 16, 0);
2975 
2976     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2977                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2978                      "\"  Wine6a\"=\"Leading spaces\"\n"
2979                      "\"\t\tWine6b\"=\"Leading tabs\"\n"
2980                      "  \"  Wine6c  \"  =  \"  Spaces everywhere  \"  \n\n");
2981     verify_reg(hkey, "  Wine6a", REG_SZ, "Leading spaces", 15, 0);
2982     verify_reg(hkey, "\t\tWine6b", REG_SZ, "Leading tabs", 13, 0);
2983     verify_reg(hkey, "  Wine6c  ", REG_SZ, "  Spaces everywhere  ", 22, 0);
2984 
2985     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2986                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2987                      "\"Wine7a\"=\"    Four spaces in the data\"\n"
2988                      "\"Wine7b\"=\"\t\tTwo tabs in the data\"\n\n");
2989     verify_reg(hkey, "Wine7a", REG_SZ, "    Four spaces in the data", 28, 0);
2990     verify_reg(hkey, "Wine7b", REG_SZ, "\t\tTwo tabs in the data", 23, 0);
2991 
2992     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
2993                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2994                      "\"Wine8a\"=\"Trailing spaces\"    \n"
2995                      "\"Wine8b\"=\"Trailing tabs and spaces\"\t  \t\n\n");
2996     verify_reg(hkey, "Wine8a", REG_SZ, "Trailing spaces", 16, 0);
2997     verify_reg(hkey, "Wine8b", REG_SZ, "Trailing tabs and spaces", 25, 0);
2998 
2999     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3000                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
3001                      "\"Wine9a\"=dword:  00000008\n"
3002                      "\"Wine9b\"=dword:\t\t00000008\n\n");
3003     dword = 0x00000008;
3004     verify_reg(hkey, "Wine9a", REG_DWORD, &dword, sizeof(dword), 0);
3005     verify_reg(hkey, "Wine9b", REG_DWORD, &dword, sizeof(dword), 0);
3006 
3007     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3008                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
3009                      "@  =  \"Test Value\"\n\n");
3010     verify_reg(hkey, "", REG_SZ, "Test Value", 11, 0);
3011 
3012     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3013                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
3014                      "\t@\t=\tdword:\t00000008\t\n\n");
3015     verify_reg(hkey, "", REG_DWORD, &dword, sizeof(DWORD), 0);
3016 
3017     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3018                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
3019                      "\"Wine10a\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
3020                      "  63,00,6f,00,6e,00,\\\n\n"
3021                      "  63,00,61,00,74,00,\\\n\n\n"
3022                      "  65,00,6e,00,\\\n\n\n\n"
3023                      "  61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n");
3024     verify_reg(hkey, "Wine10a", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
3025 
3026     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3027                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
3028                      "\"Wine10b\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
3029                      "  63,00,6f,00,6e,00,\\\n \n"
3030                      "  63,00,61,00,74,00,\\\n\t\n\t\n"
3031                      "  65,00,6e,00,\\\n\t \t\n\t \t\n\t \t\n"
3032                      "  61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n");
3033     verify_reg(hkey, "Wine10b", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
3034 
3035     close_key(hkey);
3036 
3037     delete_key(HKEY_CURRENT_USER, KEY_BASE);
3038 }
3039 
3040 static void test_key_creation_and_deletion(void)
3041 {
3042     HKEY hkey, subkey;
3043 
3044     delete_tree(HKEY_CURRENT_USER, KEY_BASE);
3045     verify_key_nonexist(HKEY_CURRENT_USER, KEY_BASE);
3046 
3047     exec_import_str("REGEDIT4\n\n"
3048                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n\n");
3049 
3050     open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
3051 
3052     /* Test key creation */
3053     exec_import_str("REGEDIT4\n\n"
3054                     "HKEY_CURRENT_USER\\" KEY_BASE "\\No_Opening_Bracket]\n");
3055     verify_key_nonexist(hkey, "No_Opening_Bracket");
3056 
3057     exec_import_str("REGEDIT4\n\n"
3058                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\No_Closing_Bracket\n");
3059     verify_key_nonexist(hkey, "No_Closing_Bracket");
3060 
3061     exec_import_str("REGEDIT4\n\n"
3062                     "[ HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1a]\n");
3063     verify_key_nonexist(hkey, "Subkey1a");
3064 
3065     exec_import_str("REGEDIT4\n\n"
3066                     "[\tHKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1b]\n");
3067     verify_key_nonexist(hkey, "Subkey1b");
3068 
3069     exec_import_str("REGEDIT4\n\n"
3070                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1c ]\n");
3071     verify_key(hkey, "Subkey1c ");
3072     delete_key(hkey, "Subkey1c ");
3073 
3074     exec_import_str("REGEDIT4\n\n"
3075                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1d\t]\n");
3076     verify_key(hkey, "Subkey1d\t");
3077     delete_key(hkey, "Subkey1d\t");
3078 
3079     exec_import_str("REGEDIT4\n\n"
3080                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1e\\]\n"
3081                     "\"Wine\"=\"Test value\"\n\n");
3082     verify_key(hkey, "Subkey1e\\");
3083     verify_key(hkey, "Subkey1e");
3084     open_key(hkey, "Subkey1e", 0, &subkey);
3085     verify_reg(subkey, "Wine", REG_SZ, "Test value", 11, 0);
3086     close_key(subkey);
3087     delete_key(hkey, "Subkey1e");
3088 
3089     exec_import_str("REGEDIT4\n\n"
3090                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1f\\\\]\n"
3091                     "\"Wine\"=\"Test value\"\n\n");
3092     verify_key(hkey, "Subkey1f\\\\");
3093     verify_key(hkey, "Subkey1f\\");
3094     verify_key(hkey, "Subkey1f");
3095     open_key(hkey, "Subkey1f\\\\", 0, &subkey);
3096     verify_reg(subkey, "Wine", REG_SZ, "Test value", 11, 0);
3097     close_key(subkey);
3098     delete_key(hkey, "Subkey1f\\\\");
3099 
3100     exec_import_str("REGEDIT4\n\n"
3101                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1g\\\\\\\\]\n"
3102                     "\"Wine\"=\"Test value\"\n\n");
3103     verify_key(hkey, "Subkey1g\\\\\\\\");
3104     verify_key(hkey, "Subkey1g\\\\");
3105     verify_key(hkey, "Subkey1g\\");
3106     verify_key(hkey, "Subkey1g");
3107     open_key(hkey, "Subkey1g\\\\", 0, &subkey);
3108     verify_reg(subkey, "Wine", REG_SZ, "Test value", 11, 0);
3109     close_key(subkey);
3110     delete_key(hkey, "Subkey1g\\\\");
3111 
3112     /* Test key deletion. We start by creating some registry keys. */
3113     exec_import_str("REGEDIT4\n\n"
3114                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a]\n\n"
3115                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2b]\n\n");
3116     verify_key(hkey, "Subkey2a");
3117     verify_key(hkey, "Subkey2b");
3118 
3119     exec_import_str("REGEDIT4\n\n"
3120                     "[ -HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a]\n");
3121     verify_key(hkey, "Subkey2a");
3122 
3123     exec_import_str("REGEDIT4\n\n"
3124                     "[\t-HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2b]\n");
3125     verify_key(hkey, "Subkey2b");
3126 
3127     exec_import_str("REGEDIT4\n\n"
3128                     "[- HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a]\n");
3129     verify_key(hkey, "Subkey2a");
3130 
3131     exec_import_str("REGEDIT4\n\n"
3132                     "[-\tHKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2b]\n");
3133     verify_key(hkey, "Subkey2b");
3134 
3135     exec_import_str("REGEDIT4\n\n"
3136                     "[-HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a]\n\n"
3137                     "[-HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2b]\n\n");
3138     verify_key_nonexist(hkey, "Subkey2a");
3139     verify_key_nonexist(hkey, "Subkey2b");
3140 
3141     /* Test case sensitivity when creating and deleting registry keys. */
3142     exec_import_str("REGEDIT4\n\n"
3143                     "[hkey_CURRENT_user\\" KEY_BASE "\\Subkey3a]\n\n"
3144                     "[HkEy_CuRrEnT_uSeR\\" KEY_BASE "\\SuBkEy3b]\n\n");
3145     verify_key(hkey, "Subkey3a");
3146     verify_key(hkey, "Subkey3b");
3147 
3148     exec_import_str("REGEDIT4\n\n"
3149                     "[-HKEY_current_USER\\" KEY_BASE "\\sUBKEY3A]\n\n"
3150                     "[-hKeY_cUrReNt_UsEr\\" KEY_BASE "\\sUbKeY3B]\n\n");
3151     verify_key_nonexist(hkey, "Subkey3a");
3152     verify_key_nonexist(hkey, "Subkey3b");
3153 
3154     /* Test mixed key creation and deletion. We start by creating a subkey. */
3155     exec_import_str("REGEDIT4\n\n"
3156                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey4a]\n\n");
3157     verify_key(hkey, "Subkey4a");
3158 
3159     exec_import_str("REGEDIT4\n\n"
3160                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n\n"
3161                     "[-HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey4a]\n"
3162                     "\"Wine1a\"=dword:12345678\n\n");
3163     verify_key_nonexist(hkey, "Subkey4a");
3164     verify_reg_nonexist(hkey, "Wine1a");
3165 
3166     exec_import_str("REGEDIT4\n\n"
3167                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n\n"
3168                     "[HKEY_CURRENT_USERS\\" KEY_BASE "\\Subkey4b]\n"
3169                     "\"Wine1b\"=dword:12345678\n\n");
3170     verify_key_nonexist(hkey, "Subkey4b");
3171     verify_reg_nonexist(hkey, "Wine1b");
3172 
3173     close_key(hkey);
3174 
3175     delete_key(HKEY_CURRENT_USER, KEY_BASE);
3176 }
3177 
3178 static void test_key_creation_and_deletion_unicode(void)
3179 {
3180     HKEY hkey, subkey;
3181 
3182     delete_tree(HKEY_CURRENT_USER, KEY_BASE);
3183     verify_key_nonexist(HKEY_CURRENT_USER, KEY_BASE);
3184 
3185     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3186                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n\n");
3187 
3188     open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
3189 
3190     /* Test key creation */
3191     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3192                      "HKEY_CURRENT_USER\\" KEY_BASE "\\No_Opening_Bracket]\n");
3193     verify_key_nonexist(hkey, "No_Opening_Bracket");
3194 
3195     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3196                      "[HKEY_CURRENT_USER\\" KEY_BASE "\\No_Closing_Bracket\n");
3197     verify_key_nonexist(hkey, "No_Closing_Bracket");
3198 
3199     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3200                      "[ HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1a]\n");
3201     verify_key_nonexist(hkey, "Subkey1a");
3202 
3203     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3204                      "[\tHKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1b]\n");
3205     verify_key_nonexist(hkey, "Subkey1b");
3206 
3207     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3208                      "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1c ]\n");
3209     verify_key(hkey, "Subkey1c ");
3210     delete_key(hkey, "Subkey1c ");
3211 
3212     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3213                      "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1d\t]\n");
3214     verify_key(hkey, "Subkey1d\t");
3215     delete_key(hkey, "Subkey1d\t");
3216 
3217     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3218                      "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1e\\]\n"
3219                      "\"Wine\"=\"Test value\"\n\n");
3220     verify_key(hkey, "Subkey1e\\");
3221     verify_key(hkey, "Subkey1e");
3222     open_key(hkey, "Subkey1e", 0, &subkey);
3223     verify_reg(subkey, "Wine", REG_SZ, "Test value", 11, 0);
3224     close_key(subkey);
3225     delete_key(hkey, "Subkey1e");
3226 
3227     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3228                      "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1f\\\\]\n"
3229                      "\"Wine\"=\"Test value\"\n\n");
3230     verify_key(hkey, "Subkey1f\\\\");
3231     verify_key(hkey, "Subkey1f\\");
3232     verify_key(hkey, "Subkey1f");
3233     open_key(hkey, "Subkey1f\\\\", 0, &subkey);
3234     verify_reg(subkey, "Wine", REG_SZ, "Test value", 11, 0);
3235     close_key(subkey);
3236     delete_key(hkey, "Subkey1f\\\\");
3237 
3238     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3239                      "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1g\\\\\\\\]\n"
3240                      "\"Wine\"=\"Test value\"\n\n");
3241     verify_key(hkey, "Subkey1g\\\\\\\\");
3242     verify_key(hkey, "Subkey1g\\\\");
3243     verify_key(hkey, "Subkey1g\\");
3244     verify_key(hkey, "Subkey1g");
3245     open_key(hkey, "Subkey1g\\\\", 0, &subkey);
3246     verify_reg(subkey, "Wine", REG_SZ, "Test value", 11, 0);
3247     close_key(subkey);
3248     delete_key(hkey, "Subkey1g\\\\");
3249 
3250     /* Test key deletion. We start by creating some registry keys. */
3251     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3252                      "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a]\n\n"
3253                      "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2b]\n\n");
3254     verify_key(hkey, "Subkey2a");
3255     verify_key(hkey, "Subkey2b");
3256 
3257     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3258                      "[ -HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a]\n");
3259     verify_key(hkey, "Subkey2a");
3260 
3261     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3262                      "[\t-HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2b]\n");
3263     verify_key(hkey, "Subkey2b");
3264 
3265     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3266                      "[- HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a]\n");
3267     verify_key(hkey, "Subkey2a");
3268 
3269     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3270                      "[-\tHKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2b]\n");
3271     verify_key(hkey, "Subkey2b");
3272 
3273     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3274                      "[-HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a]\n\n"
3275                      "[-HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2b]\n\n");
3276     verify_key_nonexist(hkey, "Subkey2a");
3277     verify_key_nonexist(hkey, "Subkey2b");
3278 
3279     /* Test case sensitivity when creating and deleting registry keys. */
3280     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3281                      "[hkey_CURRENT_user\\" KEY_BASE "\\Subkey3a]\n\n"
3282                      "[HkEy_CuRrEnT_uSeR\\" KEY_BASE "\\SuBkEy3b]\n\n");
3283     verify_key(hkey, "Subkey3a");
3284     verify_key(hkey, "Subkey3b");
3285 
3286     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3287                      "[-HKEY_current_USER\\" KEY_BASE "\\sUBKEY3A]\n\n"
3288                      "[-hKeY_cUrReNt_UsEr\\" KEY_BASE "\\sUbKeY3B]\n\n");
3289     verify_key_nonexist(hkey, "Subkey3a");
3290     verify_key_nonexist(hkey, "Subkey3b");
3291 
3292     /* Test mixed key creation and deletion. We start by creating a subkey. */
3293     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3294                      "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey4a]\n\n");
3295     verify_key(hkey, "Subkey4a");
3296 
3297     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3298                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n\n"
3299                      "[-HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey4a]\n"
3300                      "\"Wine1a\"=dword:12345678\n\n");
3301     verify_key_nonexist(hkey, "Subkey4a");
3302     verify_reg_nonexist(hkey, "Wine1a");
3303 
3304     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3305                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n\n"
3306                      "[HKEY_CURRENT_USERS\\" KEY_BASE "\\Subkey4b]\n"
3307                      "\"Wine1b\"=dword:12345678\n\n");
3308     verify_key_nonexist(hkey, "Subkey4b");
3309     verify_reg_nonexist(hkey, "Wine1b");
3310 
3311     close_key(hkey);
3312 
3313     delete_key(HKEY_CURRENT_USER, KEY_BASE);
3314 }
3315 
3316 static void test_value_deletion(void)
3317 {
3318     HKEY hkey;
3319     DWORD dword = 0x8;
3320     BYTE hex[4] = {0x11, 0x22, 0x33, 0x44};
3321 
3322     delete_tree(HKEY_CURRENT_USER, KEY_BASE);
3323     verify_key_nonexist(HKEY_CURRENT_USER, KEY_BASE);
3324 
3325     exec_import_str("REGEDIT4\n\n"
3326                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n\n");
3327 
3328     open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
3329 
3330     /* Test value deletion. We start by creating some registry values. */
3331     exec_import_str("REGEDIT4\n\n"
3332                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
3333                     "\"Wine46a\"=\"Test Value\"\n"
3334                     "\"Wine46b\"=dword:00000008\n"
3335                     "\"Wine46c\"=hex:11,22,33,44\n"
3336                     "\"Wine46d\"=hex(7):4c,69,6e,65,20,\\\n"
3337                     "  63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n"
3338                     "\"Wine46e\"=hex(2):25,50,41,54,48,25,00\n"
3339                     "\"Wine46f\"=hex(0):56,00,61,00,6c,00,75,00,65,00,00,00\n\n");
3340     verify_reg(hkey, "Wine46a", REG_SZ, "Test Value", 11, 0);
3341     verify_reg(hkey, "Wine46b", REG_DWORD, &dword, sizeof(dword), 0);
3342     verify_reg(hkey, "Wine46c", REG_BINARY, hex, 4, 0);
3343     verify_reg(hkey, "Wine46d", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
3344     verify_reg(hkey, "Wine46e", REG_EXPAND_SZ, "%PATH%", 7, 0);
3345     verify_reg(hkey, "Wine46f", REG_NONE, "V\0a\0l\0u\0e\0\0", 12, 0);
3346 
3347     exec_import_str("REGEDIT4\n\n"
3348                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
3349                     "\"Wine46a\"=-\n"
3350                     "\"Wine46b\"=  -\n"
3351                     "\"Wine46c\"=  \t-\t  \n"
3352                     "\"Wine46d\"=-\"Test\"\n"
3353                     "\"Wine46e\"=- ;comment\n"
3354                     "\"Wine46f\"=- #comment\n\n");
3355     verify_reg_nonexist(hkey, "Wine46a");
3356     verify_reg_nonexist(hkey, "Wine46b");
3357     verify_reg_nonexist(hkey, "Wine46c");
3358     verify_reg(hkey, "Wine46d", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
3359     verify_reg_nonexist(hkey, "Wine46e");
3360     verify_reg(hkey, "Wine46f", REG_NONE, "V\0a\0l\0u\0e\0\0", 12, 0);
3361 
3362     close_key(hkey);
3363 
3364     delete_key(HKEY_CURRENT_USER, KEY_BASE);
3365 }
3366 
3367 
3368 static void test_value_deletion_unicode(void)
3369 {
3370     HKEY hkey;
3371     DWORD dword = 0x8;
3372     BYTE hex[4] = {0x11, 0x22, 0x33, 0x44};
3373 
3374     delete_tree(HKEY_CURRENT_USER, KEY_BASE);
3375     verify_key_nonexist(HKEY_CURRENT_USER, KEY_BASE);
3376 
3377     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3378                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n\n");
3379 
3380     open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
3381 
3382     /* Test value deletion. We start by creating some registry values. */
3383     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3384                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
3385                      "\"Wine46a\"=\"Test Value\"\n"
3386                      "\"Wine46b\"=dword:00000008\n"
3387                      "\"Wine46c\"=hex:11,22,33,44\n"
3388                      "\"Wine46d\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
3389                      "  63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
3390                      "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n"
3391                      "\"Wine46e\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"
3392                      "\"Wine46f\"=hex(0):56,00,61,00,6c,00,75,00,65,00,00,00\n\n");
3393     verify_reg(hkey, "Wine46a", REG_SZ, "Test Value", 11, 0);
3394     verify_reg(hkey, "Wine46b", REG_DWORD, &dword, sizeof(dword), 0);
3395     verify_reg(hkey, "Wine46c", REG_BINARY, hex, 4, 0);
3396     verify_reg(hkey, "Wine46d", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
3397     verify_reg(hkey, "Wine46e", REG_EXPAND_SZ, "%PATH%", 7, 0);
3398     verify_reg(hkey, "Wine46f", REG_NONE, "V\0a\0l\0u\0e\0\0", 12, 0);
3399 
3400     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3401                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
3402                      "\"Wine46a\"=-\n"
3403                      "\"Wine46b\"=  -\n"
3404                      "\"Wine46c\"=  \t-\t  \n"
3405                      "\"Wine46d\"=-\"Test\"\n"
3406                      "\"Wine46e\"=- ;comment\n"
3407                      "\"Wine46f\"=- #comment\n\n");
3408     verify_reg_nonexist(hkey, "Wine46a");
3409     verify_reg_nonexist(hkey, "Wine46b");
3410     verify_reg_nonexist(hkey, "Wine46c");
3411     verify_reg(hkey, "Wine46d", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
3412     verify_reg_nonexist(hkey, "Wine46e");
3413     verify_reg(hkey, "Wine46f", REG_NONE, "V\0a\0l\0u\0e\0\0", 12, 0);
3414 
3415     close_key(hkey);
3416 
3417     delete_key(HKEY_CURRENT_USER, KEY_BASE);
3418 }
3419 
3420 #define compare_export(f,e,todo) compare_export_(__LINE__,f,e,todo)
3421 static BOOL compare_export_(unsigned line, const char *filename, const char *expected, DWORD todo)
3422 {
3423     FILE *fp;
3424     long file_size;
3425     WCHAR *fbuf = NULL, *wstr = NULL;
3426     size_t len;
3427     BOOL ret = FALSE;
3428 
3429     fp = fopen(filename, "rb");
3430     if (!fp) return FALSE;
3431 
3432     if (fseek(fp, 0, SEEK_END)) goto error;
3433     file_size = ftell(fp);
3434     if (file_size == -1) goto error;
3435     rewind(fp);
3436 
3437     fbuf = HeapAlloc(GetProcessHeap(), 0, file_size + sizeof(WCHAR));
3438     if (!fbuf) goto error;
3439 
3440     fread(fbuf, file_size, 1, fp);
3441     fbuf[file_size/sizeof(WCHAR)] = 0;
3442     fclose(fp);
3443 
3444     len = MultiByteToWideChar(CP_UTF8, 0, expected, -1, NULL, 0);
3445     wstr = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
3446     if (!wstr) goto exit;
3447     MultiByteToWideChar(CP_UTF8, 0, expected, -1, wstr, len);
3448 
3449     todo_wine_if (todo & TODO_REG_COMPARE)
3450         lok(!lstrcmpW(fbuf, wstr), "export data does not match expected data\n");
3451 
3452     ret = DeleteFileA(filename);
3453     lok(ret, "DeleteFile failed: %u\n", GetLastError());
3454 
3455 exit:
3456     HeapFree(GetProcessHeap(), 0, fbuf);
3457     HeapFree(GetProcessHeap(), 0, wstr);
3458     return ret;
3459 
3460 error:
3461     fclose(fp);
3462     return FALSE;
3463 }
3464 
3465 static void test_export(void)
3466 {
3467     HKEY hkey, subkey;
3468     DWORD dword;
3469     BYTE hex[4];
3470 
3471     const char *empty_key_test =
3472         "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
3473         "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n\r\n";
3474 
3475     const char *simple_test =
3476         "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
3477         "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
3478         "\"DWORD\"=dword:00000100\r\n"
3479         "\"String\"=\"Your text here...\"\r\n\r\n";
3480 
3481     const char *complex_test =
3482         "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
3483         "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
3484         "\"DWORD\"=dword:00000100\r\n"
3485         "\"String\"=\"Your text here...\"\r\n\r\n"
3486         "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1]\r\n"
3487         "\"Binary\"=hex:11,22,33,44\r\n"
3488         "\"Undefined hex\"=hex(100):25,50,41,54,48,25,00\r\n\r\n"
3489         "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a]\r\n"
3490         "\"double\\\"quote\"=\"\\\"Hello, World!\\\"\"\r\n"
3491         "\"single'quote\"=dword:00000008\r\n\r\n"
3492         "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a\\Subkey2b]\r\n"
3493         "@=\"Default value name\"\r\n"
3494         "\"Multiple strings\"=hex(7):4c,00,69,00,6e,00,65,00,31,00,00,00,4c,00,69,00,6e,\\\r\n"
3495         "  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"
3496         "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey3a]\r\n"
3497         "\"Backslash\"=\"Use \\\\\\\\ to escape a backslash\"\r\n\r\n"
3498         "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey3a\\Subkey3b]\r\n\r\n"
3499         "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey3a\\Subkey3b\\Subkey3c]\r\n"
3500         "\"String expansion\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00,25,00,50,\\\r\n"
3501         "  00,41,00,54,00,48,00,25,00,00,00\r\n"
3502         "\"Zero data type\"=hex(0):56,61,6c,75,65,00\r\n\r\n"
3503         "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey4]\r\n"
3504         "@=dword:12345678\r\n"
3505         "\"43981\"=hex(abcd):56,61,6c,75,65,00\r\n\r\n";
3506 
3507     const char *key_order_test =
3508         "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
3509         "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n\r\n"
3510         "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1]\r\n\r\n"
3511         "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2]\r\n\r\n";
3512 
3513     const char *value_order_test =
3514         "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
3515         "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
3516         "\"Value 2\"=\"I was added first!\"\r\n"
3517         "\"Value 1\"=\"I was added second!\"\r\n\r\n";
3518 
3519     const char *empty_hex_test =
3520         "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
3521         "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
3522         "\"Wine1a\"=hex(0):\r\n"
3523         "\"Wine1b\"=\"\"\r\n"
3524         "\"Wine1c\"=hex(2):\r\n"
3525         "\"Wine1d\"=hex:\r\n"
3526         "\"Wine1e\"=hex(4):\r\n"
3527         "\"Wine1f\"=hex(7):\r\n"
3528         "\"Wine1g\"=hex(100):\r\n"
3529         "\"Wine1h\"=hex(abcd):\r\n\r\n";
3530 
3531     const char *empty_hex_test2 =
3532         "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
3533         "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
3534         "\"Wine2a\"=\"\"\r\n"
3535         "\"Wine2b\"=hex:\r\n"
3536         "\"Wine2c\"=hex(4):\r\n\r\n";
3537 
3538     const char *hex_types_test =
3539         "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
3540         "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
3541         "\"Wine3a\"=\"Value\"\r\n"
3542         "\"Wine3b\"=hex:12,34,56,78\r\n"
3543         "\"Wine3c\"=dword:10203040\r\n\r\n";
3544 
3545     const char *embedded_null_test =
3546         "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
3547         "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
3548         "\"Wine4a\"=dword:00000005\r\n"
3549         "\"Wine4b\"=\"\"\r\n"
3550         "\"Wine4c\"=\"Value\"\r\n"
3551         "\"Wine4d\"=\"\"\r\n"
3552         "\"Wine4e\"=dword:00000100\r\n"
3553         "\"Wine4f\"=\"\"\r\n"
3554         "\"Wine4g\"=\"Value2\"\r\n"
3555         "\"Wine4h\"=\"abc\"\r\n\r\n";
3556 
3557     const char *slashes_test =
3558         "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
3559         "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
3560         "\"count/up\"=\"one/two/three\"\r\n"
3561         "\"\\\\foo\\\\bar\"=\"\"\r\n\r\n"
3562         "[HKEY_CURRENT_USER\\" KEY_BASE "\\https://winehq.org]\r\n\r\n";
3563 
3564     const char *escaped_null_test =
3565         "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
3566         "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
3567         "\"Wine5a\"=\"\\\\0\"\r\n"
3568         "\"Wine5b\"=\"\\\\0\\\\0\"\r\n"
3569         "\"Wine5c\"=\"Value1\\\\0\"\r\n"
3570         "\"Wine5d\"=\"Value2\\\\0\\\\0\\\\0\\\\0\"\r\n"
3571         "\"Wine5e\"=\"Value3\\\\0Value4\"\r\n"
3572         "\"Wine5f\"=\"\\\\0Value5\"\r\n\r\n";
3573 
3574     delete_tree(HKEY_CURRENT_USER, KEY_BASE);
3575     verify_key_nonexist(HKEY_CURRENT_USER, KEY_BASE);
3576 
3577     /* Test registry export with an empty key */
3578     add_key(HKEY_CURRENT_USER, KEY_BASE, &hkey);
3579 
3580     run_regedit_exe("regedit.exe /e file.reg HKEY_CURRENT_USER\\" KEY_BASE);
3581     ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n");
3582 
3583     /* Test registry export with a simple data structure */
3584     dword = 0x100;
3585     add_value(hkey, "DWORD", REG_DWORD, &dword, sizeof(dword));
3586     add_value(hkey, "String", REG_SZ, "Your text here...", 18);
3587 
3588     run_regedit_exe("regedit.exe /e file.reg HKEY_CURRENT_USER\\" KEY_BASE);
3589     ok(compare_export("file.reg", simple_test, 0), "compare_export() failed\n");
3590 
3591     /* Test registry export with a complex data structure */
3592     add_key(hkey, "Subkey1", &subkey);
3593     add_value(subkey, "Binary", REG_BINARY, "\x11\x22\x33\x44", 4);
3594     add_value(subkey, "Undefined hex", 0x100, "%PATH%", 7);
3595     close_key(subkey);
3596 
3597     add_key(hkey, "Subkey2a", &subkey);
3598     add_value(subkey, "double\"quote", REG_SZ, "\"Hello, World!\"", 16);
3599     dword = 0x8;
3600     add_value(subkey, "single'quote", REG_DWORD, &dword, sizeof(dword));
3601     close_key(subkey);
3602 
3603     add_key(hkey, "Subkey2a\\Subkey2b", &subkey);
3604     add_value(subkey, NULL, REG_SZ, "Default value name", 19);
3605     add_value(subkey, "Multiple strings", REG_MULTI_SZ, "Line1\0Line2\0Line3\0", 19);
3606     close_key(subkey);
3607 
3608     add_key(hkey, "Subkey3a", &subkey);
3609     add_value(subkey, "Backslash", REG_SZ, "Use \\\\ to escape a backslash", 29);
3610     close_key(subkey);
3611 
3612     add_key(hkey, "Subkey3a\\Subkey3b\\Subkey3c", &subkey);
3613     add_value(subkey, "String expansion", REG_EXPAND_SZ, "%HOME%\\%PATH%", 14);
3614     add_value(subkey, "Zero data type", REG_NONE, "Value", 6);
3615     close_key(subkey);
3616 
3617     add_key(hkey, "Subkey4", &subkey);
3618     dword = 0x12345678;
3619     add_value(subkey, NULL, REG_DWORD, &dword, sizeof(dword));
3620     add_value(subkey, "43981", 0xabcd, "Value", 6);
3621     close_key(subkey);
3622     close_key(hkey);
3623 
3624     run_regedit_exe("regedit.exe /e file.reg HKEY_CURRENT_USER\\" KEY_BASE);
3625     ok(compare_export("file.reg", complex_test, 0), "compare_export() failed\n");
3626     delete_tree(HKEY_CURRENT_USER, KEY_BASE);
3627 
3628     /* Test the export order of registry keys */
3629     add_key(HKEY_CURRENT_USER, KEY_BASE, &hkey);
3630     add_key(hkey, "Subkey2", &subkey);
3631     close_key(subkey);
3632     add_key(hkey, "Subkey1", &subkey);
3633     close_key(subkey);
3634 
3635     run_regedit_exe("regedit.exe /e file.reg HKEY_CURRENT_USER\\" KEY_BASE);
3636     ok(compare_export("file.reg", key_order_test, 0), "compare_export() failed\n");
3637     delete_key(hkey, "Subkey1");
3638     delete_key(hkey, "Subkey2");
3639 
3640     /* Test the export order of registry values. Windows exports registry values
3641      * in order of creation; Wine uses alphabetical order.
3642      */
3643     add_value(hkey, "Value 2", REG_SZ, "I was added first!", 19);
3644     add_value(hkey, "Value 1", REG_SZ, "I was added second!", 20);
3645     close_key(hkey);
3646 
3647     run_regedit_exe("regedit.exe /e file.reg HKEY_CURRENT_USER\\" KEY_BASE);
3648     ok(compare_export("file.reg", value_order_test, TODO_REG_COMPARE), "compare_export() failed\n");
3649     delete_key(HKEY_CURRENT_USER, KEY_BASE);
3650 
3651     /* Test registry export with empty hex data */
3652     add_key(HKEY_CURRENT_USER, KEY_BASE, &hkey);
3653     add_value(hkey, "Wine1a", REG_NONE, NULL, 0);
3654     add_value(hkey, "Wine1b", REG_SZ, NULL, 0);
3655     add_value(hkey, "Wine1c", REG_EXPAND_SZ, NULL, 0);
3656     add_value(hkey, "Wine1d", REG_BINARY, NULL, 0);
3657     add_value(hkey, "Wine1e", REG_DWORD, NULL, 0);
3658     add_value(hkey, "Wine1f", REG_MULTI_SZ, NULL, 0);
3659     add_value(hkey, "Wine1g", 0x100, NULL, 0);
3660     add_value(hkey, "Wine1h", 0xabcd, NULL, 0);
3661     close_key(hkey);
3662 
3663     run_regedit_exe("regedit.exe /e file.reg HKEY_CURRENT_USER\\" KEY_BASE);
3664     ok(compare_export("file.reg", empty_hex_test, 0), "compare_export() failed\n");
3665     delete_key(HKEY_CURRENT_USER, KEY_BASE);
3666 
3667     /* Test registry export after importing alternative registry data types */
3668     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3669                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
3670                      "\"Wine2a\"=hex(1):\n"
3671                      "\"Wine2b\"=hex(3):\n"
3672                      "\"Wine2c\"=hex(4):\n\n");
3673     open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
3674     verify_reg(hkey, "Wine2a", REG_SZ, NULL, 0, 0);
3675     verify_reg(hkey, "Wine2b", REG_BINARY, NULL, 0, 0);
3676     verify_reg(hkey, "Wine2c", REG_DWORD, NULL, 0, 0);
3677     close_key(hkey);
3678 
3679     run_regedit_exe("regedit.exe /e file.reg HKEY_CURRENT_USER\\" KEY_BASE);
3680     ok(compare_export("file.reg", empty_hex_test2, 0), "compare_export() failed\n");
3681     delete_key(HKEY_CURRENT_USER, KEY_BASE);
3682 
3683     /* Test registry export with embedded null characters */
3684     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3685                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
3686                      "\"Wine3a\"=hex(1):56,00,61,00,6c,00,75,00,65,00,00,00\n"
3687                      "\"Wine3b\"=hex(3):12,34,56,78\n"
3688                      "\"Wine3c\"=hex(4):40,30,20,10\n\n");
3689     open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
3690     verify_reg(hkey, "Wine3a", REG_SZ, "Value", 6, 0);
3691     memcpy(hex, "\x12\x34\x56\x78", 4);
3692     verify_reg(hkey, "Wine3b", REG_BINARY, hex, 4, 0);
3693     dword = 0x10203040;
3694     verify_reg(hkey, "Wine3c", REG_DWORD, &dword, sizeof(dword), 0);
3695     close_key(hkey);
3696 
3697     run_regedit_exe("regedit.exe /e file.reg HKEY_CURRENT_USER\\" KEY_BASE);
3698     ok(compare_export("file.reg", hex_types_test, 0), "compare_export() failed\n");
3699     delete_key(HKEY_CURRENT_USER, KEY_BASE);
3700 
3701     exec_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3702                      "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
3703                      "\"Wine4a\"=dword:00000005\n"
3704                      "\"Wine4b\"=hex(1):00,00,00,00,00,00,00,00\n"
3705                      "\"Wine4c\"=\"Value\"\n"
3706                      "\"Wine4d\"=hex(1):00,00,61,00,62,00,63,00\n"
3707                      "\"Wine4e\"=dword:00000100\n"
3708                      "\"Wine4f\"=hex(1):00,00,56,00,61,00,6c,00,75,00,65,00,00,00\n"
3709                      "\"Wine4g\"=\"Value2\"\n"
3710                      "\"Wine4h\"=hex(1):61,00,62,00,63,00,00,00, \\\n"
3711                      "  64,00,65,00,66,00,00,00\n\n");
3712     open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
3713     dword = 0x5;
3714     verify_reg(hkey, "Wine4a", REG_DWORD, &dword, sizeof(dword), 0);
3715     verify_reg(hkey, "Wine4b", REG_SZ, "\0\0\0\0\0\0\0", 4, 0);
3716     verify_reg(hkey, "Wine4c", REG_SZ, "Value", 6, 0);
3717     verify_reg(hkey, "Wine4d", REG_SZ, "\0abc", 5, 0);
3718     dword = 0x100;
3719     verify_reg(hkey, "Wine4e", REG_DWORD, &dword, sizeof(dword), 0);
3720     verify_reg(hkey, "Wine4f", REG_SZ, "\0Value", 7, 0);
3721     verify_reg(hkey, "Wine4g", REG_SZ, "Value2", 7, 0);
3722     verify_reg(hkey, "Wine4h", REG_SZ, "abc\0def", 8, 0);
3723     close_key(hkey);
3724 
3725     run_regedit_exe("regedit.exe /e file.reg HKEY_CURRENT_USER\\" KEY_BASE);
3726     ok(compare_export("file.reg", embedded_null_test, 0), "compare_export() failed\n");
3727     delete_key(HKEY_CURRENT_USER, KEY_BASE);
3728 
3729     /* Test registry export with forward and back slashes */
3730     add_key(HKEY_CURRENT_USER, KEY_BASE, &hkey);
3731     add_key(hkey, "https://winehq.org", &subkey);
3732     close_key(subkey);
3733     add_value(hkey, "count/up", REG_SZ, "one/two/three", 14);
3734     add_value(hkey, "\\foo\\bar", REG_SZ, "", 1);
3735     close_key(hkey);
3736 
3737     run_regedit_exe("regedit.exe /e file.reg HKEY_CURRENT_USER\\" KEY_BASE);
3738     ok(compare_export("file.reg", slashes_test, TODO_REG_COMPARE), "compare_export() failed\n");
3739     delete_tree(HKEY_CURRENT_USER, KEY_BASE);
3740 
3741     /* Test registry export with escaped null characters */
3742     add_key(HKEY_CURRENT_USER, KEY_BASE, &hkey);
3743     add_value(hkey, "Wine5a", REG_SZ, "\\0", 3);
3744     add_value(hkey, "Wine5b", REG_SZ, "\\0\\0", 5);
3745     add_value(hkey, "Wine5c", REG_SZ, "Value1\\0", 9);
3746     add_value(hkey, "Wine5d", REG_SZ, "Value2\\0\\0\\0\\0", 15);
3747     add_value(hkey, "Wine5e", REG_SZ, "Value3\\0Value4", 15);
3748     add_value(hkey, "Wine5f", REG_SZ, "\\0Value5", 9);
3749     close_key(hkey);
3750 
3751     run_regedit_exe("regedit.exe /e file.reg HKEY_CURRENT_USER\\" KEY_BASE);
3752     ok(compare_export("file.reg", escaped_null_test, 0), "compare_export() failed\n");
3753     delete_key(HKEY_CURRENT_USER, KEY_BASE);
3754 }
3755 
3756 START_TEST(regedit)
3757 {
3758     HKEY hkey;
3759     LONG err;
3760 
3761     /* Check if regedit.exe is running with elevated privileges */
3762     err = RegDeleteKeyA(HKEY_CLASSES_ROOT, KEY_BASE);
3763     if (err == ERROR_ACCESS_DENIED)
3764     {
3765         win_skip("User is a non-elevated admin; skipping regedit tests.\n");
3766         return;
3767     }
3768     if (err == ERROR_FILE_NOT_FOUND)
3769     {
3770         if (RegCreateKeyExA(HKEY_CLASSES_ROOT, KEY_BASE, 0, NULL, REG_OPTION_NON_VOLATILE,
3771                             KEY_READ, NULL, &hkey, NULL))
3772         {
3773             win_skip("User is a non-elevated admin; skipping regedit tests.\n");
3774             return;
3775         }
3776         RegCloseKey(hkey);
3777         RegDeleteKeyA(HKEY_CLASSES_ROOT, KEY_BASE);
3778     }
3779 
3780     test_basic_import();
3781     test_basic_import_unicode();
3782     test_basic_import_31();
3783     test_invalid_import();
3784     test_invalid_import_unicode();
3785     test_invalid_import_31();
3786     test_comments();
3787     test_comments_unicode();
3788     test_import_with_whitespace();
3789     test_import_with_whitespace_unicode();
3790     test_key_creation_and_deletion();
3791     test_key_creation_and_deletion_unicode();
3792     test_value_deletion();
3793     test_value_deletion_unicode();
3794     test_export();
3795 }
3796