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