regedit.c 36.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
/*
 * Copyright 2010 Andrew Eikum for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include <windows.h>

#include "wine/test.h"

static BOOL supports_wchar;

#define lok ok_(__FILE__,line)

#define exec_import_str(c) r_exec_import_str(__LINE__, c)
static BOOL r_exec_import_str(unsigned line, const char *file_contents)
{
    STARTUPINFOA si = {sizeof(STARTUPINFOA)};
    PROCESS_INFORMATION pi;
    HANDLE regfile;
    DWORD written, dr;
    BOOL br;
    char cmd[] = "regedit /s test.reg";

    regfile = CreateFileA("test.reg", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
            FILE_ATTRIBUTE_NORMAL, NULL);
    lok(regfile != INVALID_HANDLE_VALUE, "Failed to create test.reg file\n");
    if(regfile == INVALID_HANDLE_VALUE)
        return FALSE;

    br = WriteFile(regfile, file_contents, strlen(file_contents), &written,
            NULL);
    lok(br == TRUE, "WriteFile failed: %d\n", GetLastError());

    CloseHandle(regfile);

    if(!CreateProcessA(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
        return FALSE;

    dr = WaitForSingleObject(pi.hProcess, 10000);
    if(dr == WAIT_TIMEOUT)
        TerminateProcess(pi.hProcess, 1);
    CloseHandle(pi.hThread);
    CloseHandle(pi.hProcess);

    br = DeleteFileA("test.reg");
    lok(br == TRUE, "DeleteFileA failed: %d\n", GetLastError());

    return (dr != WAIT_TIMEOUT);
}

#define exec_import_wstr(c) r_exec_import_wstr(__LINE__, c)
static BOOL r_exec_import_wstr(unsigned line, const WCHAR *file_contents)
{
    STARTUPINFOA si = {sizeof(STARTUPINFOA)};
    PROCESS_INFORMATION pi;
    HANDLE regfile;
    DWORD written, dr;
    BOOL br;
    char cmd[] = "regedit /s test.reg";

    regfile = CreateFileA("test.reg", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
            FILE_ATTRIBUTE_NORMAL, NULL);
    lok(regfile != INVALID_HANDLE_VALUE, "Failed to create test.reg file\n");
    if(regfile == INVALID_HANDLE_VALUE)
        return FALSE;

    br = WriteFile(regfile, file_contents,
            lstrlenW(file_contents) * sizeof(WCHAR), &written, NULL);
    lok(br == TRUE, "WriteFile failed: %d\n", GetLastError());

    CloseHandle(regfile);

    if(!CreateProcessA(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
        return FALSE;

    dr = WaitForSingleObject(pi.hProcess, 10000);
    if(dr == WAIT_TIMEOUT)
        TerminateProcess(pi.hProcess, 1);
    CloseHandle(pi.hThread);
    CloseHandle(pi.hProcess);

    br = DeleteFileA("test.reg");
    lok(br == TRUE, "DeleteFileA failed: %d\n", GetLastError());

    return (dr != WAIT_TIMEOUT);
}

101 102 103 104 105 106 107 108
#define TODO_REG_TYPE    (0x0001u)
#define TODO_REG_SIZE    (0x0002u)
#define TODO_REG_DATA    (0x0004u)

/* verify_reg() adapted from programs/reg/tests/reg.c */
#define verify_reg(k,v,t,d,s,todo) verify_reg_(__LINE__,k,v,t,d,s,todo)
static void verify_reg_(unsigned line, HKEY hkey, const char *value,
                        DWORD exp_type, const void *exp_data, DWORD exp_size, DWORD todo)
109
{
110 111 112 113 114 115 116 117 118
    DWORD type, size;
    BYTE data[256];
    LONG err;

    size = sizeof(data);
    memset(data, 0xdd, size);
    err = RegQueryValueExA(hkey, value, NULL, &type, data, &size);
    lok(err == ERROR_SUCCESS, "RegQueryValueEx failed: got %d\n", err);
    if (err != ERROR_SUCCESS)
119 120
        return;

121 122 123 124 125 126
    todo_wine_if (todo & TODO_REG_TYPE)
        lok(type == exp_type, "got wrong type %d, expected %d\n", type, exp_type);
    todo_wine_if (todo & TODO_REG_SIZE)
        lok(size == exp_size, "got wrong size %d, expected %d\n", size, exp_size);
    todo_wine_if (todo & TODO_REG_DATA)
        lok(memcmp(data, exp_data, size) == 0, "got wrong data\n");
127 128
}

129 130
#define verify_reg_wsz(k,n,e) r_verify_reg_wsz(__LINE__,k,n,e)
static void r_verify_reg_wsz(unsigned line, HKEY key, const char *value_name, const WCHAR *exp_value)
131 132 133 134 135 136
{
    LONG lr;
    DWORD fnd_type, fnd_len;
    WCHAR fnd_value[1024], value_nameW[1024];

    MultiByteToWideChar(CP_ACP, 0, value_name, -1, value_nameW,
137
            sizeof(value_nameW)/sizeof(value_nameW[0]));
138 139

    fnd_len = sizeof(fnd_value);
140
    lr = RegQueryValueExW(key, value_nameW, NULL, &fnd_type, (BYTE*)fnd_value, &fnd_len);
141 142 143 144 145 146 147 148 149 150 151 152
    lok(lr == ERROR_SUCCESS, "RegQueryValueExW failed: %d\n", lr);
    if(lr != ERROR_SUCCESS)
        return;

    lok(fnd_type == REG_SZ, "Got wrong type: %d\n", fnd_type);
    if(fnd_type != REG_SZ)
        return;
    lok(!lstrcmpW(exp_value, fnd_value),
            "Strings differ: expected %s, got %s\n",
            wine_dbgstr_w(exp_value), wine_dbgstr_w(fnd_value));
}

153 154
#define verify_reg_nonexist(k,n) r_verify_reg_nonexist(__LINE__,k,n)
static void r_verify_reg_nonexist(unsigned line, HKEY key, const char *value_name)
155 156 157 158 159 160
{
    LONG lr;
    DWORD fnd_type, fnd_len;
    char fnd_value[32];

    fnd_len = sizeof(fnd_value);
161
    lr = RegQueryValueExA(key, value_name, NULL, &fnd_type, (BYTE*)fnd_value, &fnd_len);
162 163 164 165
    lok(lr == ERROR_FILE_NOT_FOUND, "Reg value shouldn't exist: %s\n",
            value_name);
}

166 167
#define KEY_BASE "Software\\Wine\\regedit_test"

168 169
static void test_basic_import(void)
{
170
    HKEY hkey, subkey;
171
    DWORD dword = 0x17;
172 173 174 175 176 177 178 179 180
    char exp_binary[] = {0xAA,0xBB,0xCC,0x11};
    WCHAR wide_test[] = {0xFEFF,'W','i','n','d','o','w','s',' ','R','e','g',
        'i','s','t','r','y',' ','E','d','i','t','o','r',' ','V','e','r','s',
        'i','o','n',' ','5','.','0','0','\n','\n',
        '[','H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E',
        'R','\\','S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
        'r','e','g','e','d','i','t','_','t','e','s','t',']','\n',
        '"','T','e','s','t','V','a','l','u','e','3','"','=','"',0x3041,'V','a',
        'l','u','e','"','\n',0};
181 182 183 184 185 186 187 188
    WCHAR wide_test_r[] = {0xFEFF,'W','i','n','d','o','w','s',' ','R','e','g',
        'i','s','t','r','y',' ','E','d','i','t','o','r',' ','V','e','r','s',
        'i','o','n',' ','5','.','0','0','\r','\r',
        '[','H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E',
        'R','\\','S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
        'r','e','g','e','d','i','t','_','t','e','s','t',']','\r',
        '"','T','e','s','t','V','a','l','u','e','5','"','=','"',0x3041,'V','a',
        'l','u','e','"','\r',0};
189 190 191
    WCHAR wide_exp[] = {0x3041,'V','a','l','u','e',0};
    LONG lr;

192
    lr = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
193 194 195 196
    ok(lr == ERROR_SUCCESS || lr == ERROR_FILE_NOT_FOUND,
            "RegDeleteKeyA failed: %d\n", lr);

    exec_import_str("REGEDIT4\n\n"
197
                "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
198
                "\"TestValue\"=\"AValue\"\n");
199 200
    lr = RegOpenKeyExA(HKEY_CURRENT_USER, KEY_BASE, 0, KEY_READ, &hkey);
    ok(lr == ERROR_SUCCESS, "RegOpenKeyExA failed: %d\n", lr);
201
    verify_reg(hkey, "TestValue", REG_SZ, "AValue", 7, 0);
202 203

    exec_import_str("REGEDIT4\r\n\r\n"
204
                "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
205
                "\"TestValue2\"=\"BValue\"\r\n");
206
    verify_reg(hkey, "TestValue2", REG_SZ, "BValue", 7, 0);
207

208 209
    if (supports_wchar)
    {
210
        exec_import_wstr(wide_test);
211
        verify_reg_wsz(hkey, "TestValue3", wide_exp);
212 213

        exec_import_wstr(wide_test_r);
214 215 216
        verify_reg_wsz(hkey, "TestValue5", wide_exp);
    }
    else
217 218
        win_skip("Some WCHAR tests skipped\n");

219
    exec_import_str("REGEDIT4\r\r"
220
                "[HKEY_CURRENT_USER\\" KEY_BASE "]\r"
221
                "\"TestValue4\"=\"DValue\"\r");
222
    verify_reg(hkey, "TestValue4", REG_SZ, "DValue", 7, 0);
223

224
    exec_import_str("REGEDIT4\n\n"
225
                "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
226
                "\"TestDword\"=dword:00000017\n");
227
    verify_reg(hkey, "TestDword", REG_DWORD, &dword, sizeof(dword), 0);
228 229

    exec_import_str("REGEDIT4\n\n"
230
                "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
231
                "\"TestBinary\"=hex:aa,bb,cc,11\n");
232
    verify_reg(hkey, "TestBinary", REG_BINARY, exp_binary, sizeof(exp_binary), 0);
233

234
    exec_import_str("REGEDIT4\n\n"
235
                "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
236
                "\"With=Equals\"=\"asdf\"\n");
237
    verify_reg(hkey, "With=Equals", REG_SZ, "asdf", 5, 0);
238

239 240 241 242 243
    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Empty string\"=\"\"\n\n");
    verify_reg(hkey, "Empty string", REG_SZ, "", 1, 0);

244 245 246 247 248 249 250
    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Line1\"=\"Value1\"\n\n"
                    "\"Line2\"=\"Value2\"\n\n\n"
                    "\"Line3\"=\"Value3\"\n\n\n\n"
                    "\"Line4\"=\"Value4\"\n\n");
    verify_reg(hkey, "Line1", REG_SZ, "Value1", 7, 0);
251 252 253
    verify_reg(hkey, "Line2", REG_SZ, "Value2", 7, 0);
    verify_reg(hkey, "Line3", REG_SZ, "Value3", 7, 0);
    verify_reg(hkey, "Line4", REG_SZ, "Value4", 7, 0);
254 255 256 257 258

    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine1\"=dword:00000782\n\n"
                    "\"Wine2\"=\"Test Value\"\n"
259 260
                    "\"Wine3\"=hex(7):4c,69,6e,65,20,\\\n"
                    "  63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n"
261 262 263 264 265 266
                    "#comment\n"
                    "@=\"Test\"\n"
                    ";comment\n\n"
                    "\"Wine4\"=dword:12345678\n\n");
    dword = 0x782;
    verify_reg(hkey, "Wine1", REG_DWORD, &dword, sizeof(dword), 0);
267 268 269
    verify_reg(hkey, "Wine2", REG_SZ, "Test Value", 11, 0);
    verify_reg(hkey, "Wine3", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
    verify_reg(hkey, "", REG_SZ, "Test", 5, 0);
270
    dword = 0x12345678;
271
    verify_reg(hkey, "Wine4", REG_DWORD, &dword, sizeof(dword), 0);
272

273 274 275
    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine5\"=\"No newline\"");
276
    verify_reg(hkey, "Wine5", REG_SZ, "No newline", 11, 0);
277 278 279 280 281 282 283

    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine6\"=dword:00000050\n\n"
                    "\"Wine7\"=\"No newline\"");
    dword = 0x50;
    verify_reg(hkey, "Wine6", REG_DWORD, &dword, sizeof(dword), 0);
284
    verify_reg(hkey, "Wine7", REG_SZ, "No newline", 11, 0);
285

286 287 288 289 290 291 292 293 294
    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine8a\"=dword:1\n"
                    "\"Wine8b\"=dword:4444\n\n");
    dword = 0x1;
    verify_reg(hkey, "Wine8a", REG_DWORD, &dword, sizeof(dword), 0);
    dword = 0x4444;
    verify_reg(hkey, "Wine8b", REG_DWORD, &dword, sizeof(dword), 0);

295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine9a\"=hex(2):4c,69,6e,65,00\n"
                    "\"Wine9b\"=\"Value 1\"\n"
                    "\"Wine9c\"=hex(2):4c,69,6e,65\\\n"
                    "\"Wine9d\"=\"Value 2\"\n"
                    "\"Wine9e\"=hex(2):4c,69,6e,65,\\\n"
                    "\"Wine9f\"=\"Value 3\"\n"
                    "\"Wine9g\"=\"Value 4\"\n\n");
    verify_reg(hkey, "Wine9a", REG_EXPAND_SZ, "Line", 5, 0);
    verify_reg(hkey, "Wine9b", REG_SZ, "Value 1", 8, 0);
    verify_reg_nonexist(hkey, "Wine9c");
    todo_wine verify_reg(hkey, "Wine9d", REG_SZ, "Value 2", 8, 0);
    verify_reg_nonexist(hkey, "Wine9e");
    verify_reg_nonexist(hkey, "Wine9f");
    verify_reg(hkey, "Wine9g", REG_SZ, "Value 4", 8, 0);

312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"double\\\"quote\"=\"valid \\\"or\\\" not\"\n"
                    "\"single'quote\"=dword:00000008\n\n");
    verify_reg(hkey, "double\"quote", REG_SZ, "valid \"or\" not", 15, 0);
    dword = 0x00000008;
    verify_reg(hkey, "single'quote", REG_DWORD, &dword, sizeof(dword), 0);

    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey\"1]\n"
                    "\"Wine\\\\31\"=\"Test value\"\n\n");
    lr = RegOpenKeyExA(hkey, "Subkey\"1", 0, KEY_READ, &subkey);
    ok(lr == ERROR_SUCCESS, "got %d, expected 0\n", lr);
    verify_reg(subkey, "Wine\\31", REG_SZ, "Test value", 11, 0);
    lr = RegCloseKey(subkey);
    ok(lr == ERROR_SUCCESS, "got %d, expected 0\n", lr);
    lr = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE "\\Subkey\"1");
    ok(lr == ERROR_SUCCESS, "got %d, expected 0\n", lr);

    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey/2]\n"
                    "\"123/\\\"4;'5\"=\"Random value name\"\n\n");
    lr = RegOpenKeyExA(hkey, "Subkey/2", 0, KEY_READ, &subkey);
    ok(lr == ERROR_SUCCESS, "got %d, expected 0\n", lr);
    verify_reg(subkey, "123/\"4;'5", REG_SZ, "Random value name", 18, 0);
    lr = RegCloseKey(subkey);
    ok(lr == ERROR_SUCCESS, "got %d, expected 0\n", lr);
    lr = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE "\\Subkey/2");
    ok(lr == ERROR_SUCCESS, "got %d, expected 0\n", lr);

342
    RegCloseKey(hkey);
343

344
    lr = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
345 346 347
    ok(lr == ERROR_SUCCESS, "RegDeleteKeyA failed: %d\n", lr);
}

348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
static void test_basic_import_31(void)
{
    HKEY hkey;
    LONG lr;

    lr = RegDeleteKeyA(HKEY_CLASSES_ROOT, KEY_BASE);
    ok(lr == ERROR_SUCCESS || lr == ERROR_FILE_NOT_FOUND,
            "RegDeleteKeyA failed: %d\n", lr);

    /* Test simple value */
    exec_import_str("REGEDIT\r\n"
		    "HKEY_CLASSES_ROOT\\" KEY_BASE " = Value0\r\n");
    lr = RegOpenKeyExA(HKEY_CLASSES_ROOT, KEY_BASE, 0, KEY_READ, &hkey);
    ok(lr == ERROR_SUCCESS, "RegOpenKeyExA failed: %d\n", lr);
    verify_reg(hkey, "", REG_SZ, "Value0", 7, 0);

    /* Test proper handling of spaces and equals signs */
    exec_import_str("REGEDIT\r\n"
                    "HKEY_CLASSES_ROOT\\" KEY_BASE " =Value1\r\n");
    verify_reg(hkey, "", REG_SZ, "Value1", 7, 0);

    exec_import_str("REGEDIT\r\n"
                    "HKEY_CLASSES_ROOT\\" KEY_BASE " =  Value2\r\n");
    verify_reg(hkey, "", REG_SZ, " Value2", 8, 0);

    exec_import_str("REGEDIT\r\n"
                    "HKEY_CLASSES_ROOT\\" KEY_BASE " = Value3 \r\n");
    verify_reg(hkey, "", REG_SZ, "Value3 ", 8, 0);

    exec_import_str("REGEDIT\r\n"
                    "HKEY_CLASSES_ROOT\\" KEY_BASE " Value4\r\n");
    verify_reg(hkey, "", REG_SZ, "Value4", 7, 0);

    exec_import_str("REGEDIT\r\n"
                    "HKEY_CLASSES_ROOT\\" KEY_BASE "  Value5\r\n");
    verify_reg(hkey, "", REG_SZ, "Value5", 7, 0);

    exec_import_str("REGEDIT\r\n"
                    "HKEY_CLASSES_ROOT\\" KEY_BASE "\r\n");
    verify_reg(hkey, "", REG_SZ, "", 1, 0);

    exec_import_str("REGEDIT\r\n"
                    "HKEY_CLASSES_ROOT\\" KEY_BASE "  \r\n");
    verify_reg(hkey, "", REG_SZ, "", 1, 0);

    exec_import_str("REGEDIT\r\n"
                    "HKEY_CLASSES_ROOT\\" KEY_BASE " = No newline");
395
    verify_reg(hkey, "", REG_SZ, "No newline", 11, 0);
396 397 398 399 400 401 402

    RegCloseKey(hkey);

    lr = RegDeleteKeyA(HKEY_CLASSES_ROOT, KEY_BASE);
    ok(lr == ERROR_SUCCESS, "RegDeleteKeyA failed: %d\n", lr);
}

403 404 405
static void test_invalid_import(void)
{
    LONG lr;
406
    HKEY hkey;
407

408 409
    lr = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
    ok(lr == ERROR_SUCCESS || lr == ERROR_FILE_NOT_FOUND, "RegDeleteKeyA failed: %d\n", lr);
410 411

    exec_import_str("REGEDIT4\n\n"
412
                "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
413
                "\"TestNoEndQuote\"=\"Asdffdsa\n");
414 415 416
    lr = RegOpenKeyExA(HKEY_CURRENT_USER, KEY_BASE, 0, KEY_READ, &hkey);
    ok(lr == ERROR_SUCCESS, "RegOpenKeyExA failed: %d\n", lr);
    verify_reg_nonexist(hkey, "TestNoEndQuote");
417 418

    exec_import_str("REGEDIT4\n\n"
419
                "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
420
                "\"TestNoBeginQuote\"=Asdffdsa\"\n");
421
    verify_reg_nonexist(hkey, "TestNoBeginQuote");
422 423

    exec_import_str("REGEDIT4\n\n"
424
                "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
425
                "\"TestNoQuotes\"=Asdffdsa\n");
426
    verify_reg_nonexist(hkey, "TestNoQuotes");
427 428

    exec_import_str("REGEDIT4\n\n"
429
                "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
430
                "\"NameNoEndQuote=\"Asdffdsa\"\n");
431
    verify_reg_nonexist(hkey, "NameNoEndQuote");
432 433

    exec_import_str("REGEDIT4\n\n"
434
                "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
435
                "NameNoBeginQuote\"=\"Asdffdsa\"\n");
436
    verify_reg_nonexist(hkey, "NameNoBeginQuote");
437 438

    exec_import_str("REGEDIT4\n\n"
439
                "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
440
                "NameNoQuotes=\"Asdffdsa\"\n");
441
    verify_reg_nonexist(hkey, "NameNoQuotes");
442 443

    exec_import_str("REGEDIT4\n\n"
444
                "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
445
                "\"MixedQuotes=Asdffdsa\"\n");
446 447 448
    verify_reg_nonexist(hkey, "MixedQuotes");
    verify_reg_nonexist(hkey, "MixedQuotes=Asdffdsa");

449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
    /* Test import with non-standard registry file headers */
    exec_import_str("REGEDIT3\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test1\"=\"Value\"\n");
    verify_reg_nonexist(hkey, "Test1");

    exec_import_str("regedit4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test2\"=\"Value\"\n");
    verify_reg_nonexist(hkey, "Test2");

    exec_import_str("Regedit4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test3\"=\"Value\"\n");
    verify_reg_nonexist(hkey, "Test3");

    exec_import_str("REGEDIT 4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test4\"=\"Value\"\n");
    verify_reg_nonexist(hkey, "Test4");

    exec_import_str("REGEDIT4FOO\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test5\"=\"Value\"\n");
    verify_reg_nonexist(hkey, "Test5");

    exec_import_str("REGEDIT4 FOO\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test6\"=\"Value\"\n");
    verify_reg_nonexist(hkey, "Test6");

    exec_import_str("REGEDIT5\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test7\"=\"Value\"\n");
    verify_reg_nonexist(hkey, "Test7");

    exec_import_str("Windows Registry Editor Version 4.00\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test8\"=\"Value\"\n");
    verify_reg_nonexist(hkey, "Test8");

    exec_import_str("Windows Registry Editor Version 5\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test9\"=\"Value\"\n");
    verify_reg_nonexist(hkey, "Test9");

    exec_import_str("WINDOWS REGISTRY EDITOR VERSION 5.00\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test10\"=\"Value\"\n");
    verify_reg_nonexist(hkey, "Test10");

    exec_import_str("Windows Registry Editor version 5.00\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test11\"=\"Value\"\n");
    verify_reg_nonexist(hkey, "Test11");

505 506 507 508 509 510 511 512 513 514 515
    /* Test multi-line import with incorrect comma placement */
    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Multi-Line1\"=hex(7):4c,69,6e,65,20\\\n"
                    ",63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n\n");
    todo_wine verify_reg_nonexist(hkey, "Multi-Line1");

    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Multi-Line2\"=hex(7):4c,69,6e,65,20\\\n"
                    "  ,63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n\n");
516
    todo_wine verify_reg_nonexist(hkey, "Multi-Line2");
517 518 519 520 521 522 523 524 525 526 527

    exec_import_str("Windows Registry Editor Version 5.00\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Multi-Line3\"=hex(7):4c,69,6e,65,20\\\n"
                    ",63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n\n");
    todo_wine verify_reg_nonexist(hkey, "Multi-Line3");

    exec_import_str("Windows Registry Editor Version 5.00\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Multi-Line4\"=hex(7):4c,69,6e,65,20\\\n"
                    "  ,63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n\n");
528
    todo_wine verify_reg_nonexist(hkey, "Multi-Line4");
529

530 531 532 533 534
    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test12a\"=dword:\n"
                    "\"Test12b\"=dword:hello\n"
                    "\"Test12c\"=dword:123456789\n"
535 536
                    "\"Test12d\"=dword:012345678\n"
                    "\"Test12e\"=dword:000000001\n\n");
537 538 539 540
    verify_reg_nonexist(hkey, "Test12a");
    verify_reg_nonexist(hkey, "Test12b");
    verify_reg_nonexist(hkey, "Test12c");
    verify_reg_nonexist(hkey, "Test12d");
541
    verify_reg_nonexist(hkey, "Test12e");
542 543 544 545 546 547 548 549 550 551 552 553 554

    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test13a\"=dword:12345678abc\n"
                    "\"Test13b\"=dword:12345678 abc\n\n");
    verify_reg_nonexist(hkey, "Test13a");
    verify_reg_nonexist(hkey, "Test13b");

    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test14a\"=dword:0x123\n"
                    "\"Test14b\"=dword:123 456\n"
                    "\"Test14c\"=dword:1234 5678\n\n");
555
    verify_reg_nonexist(hkey, "Test14a");
556 557 558
    verify_reg_nonexist(hkey, "Test14b");
    verify_reg_nonexist(hkey, "Test14c");

559 560 561 562 563 564 565
    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test15a\"=\"foo\"bar\"\n"
                    "\"Test15b\"=\"foo\"\"bar\"\n\n");
    todo_wine verify_reg_nonexist(hkey, "Test15a");
    todo_wine verify_reg_nonexist(hkey, "Test15b");

566 567 568 569 570 571 572 573 574 575 576
    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test16a\"=\n"
                    "\"Test16b\"=\\\"\n"
                    "\"Test16c\"=\\\"Value\\\"\n"
                    "\"Test16d\"=\\\"Value\"\n\n");
    verify_reg_nonexist(hkey, "Test16a");
    verify_reg_nonexist(hkey, "Test16b");
    verify_reg_nonexist(hkey, "Test16c");
    verify_reg_nonexist(hkey, "Test16d");

577
    RegCloseKey(hkey);
578

579
    lr = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
580 581 582
    ok(lr == ERROR_SUCCESS, "RegDeleteKeyA failed: %d\n", lr);
}

583 584 585 586
static void test_comments(void)
{
    LONG lr;
    HKEY hkey;
587
    DWORD dword;
588 589 590 591 592 593 594 595 596 597 598

    lr = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
    ok(lr == ERROR_SUCCESS || lr == ERROR_FILE_NOT_FOUND, "RegDeleteKeyA failed: %d\n", lr);

    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "#comment\\\n"
                    "\"Wine1\"=\"Line 1\"\n"
                    ";comment\\\n"
                    "\"Wine2\"=\"Line 2\"\n\n");
    lr = RegOpenKeyExA(HKEY_CURRENT_USER, KEY_BASE, 0, KEY_READ, &hkey);
599
    ok(lr == ERROR_SUCCESS, "RegOpenKeyExA failed: %d\n", lr);
600 601
    todo_wine verify_reg(hkey, "Wine1", REG_SZ, "Line 1", 7, 0);
    todo_wine verify_reg(hkey, "Wine2", REG_SZ, "Line 2", 7, 0);
602

603 604 605 606 607 608 609 610 611 612
    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine3\"=\"Value 1\"#comment\n"
                    "\"Wine4\"=\"Value 2\";comment\n"
                    "\"Wine5\"=dword:01020304 #comment\n"
                    "\"Wine6\"=dword:02040608 ;comment\n\n");
    verify_reg_nonexist(hkey, "Wine3");
    todo_wine verify_reg(hkey, "Wine4", REG_SZ, "Value 2", 8, 0);
    verify_reg_nonexist(hkey, "Wine5");
    dword = 0x2040608;
613
    verify_reg(hkey, "Wine6", REG_DWORD, &dword, sizeof(dword), 0);
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672

    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine7\"=hex(7):4c,69,6e,65,20,\\\n"
                    "  #comment\n"
                    "  63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n"
                    "\"Wine8\"=\"A valid line\"\n"
                    "\"Wine9\"=hex(7):4c,69,6e,65,20,\\\n"
                    "  ;comment\n"
                    "  63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n"
                    "\"Wine10\"=\"Another valid line\"\n\n");
    verify_reg_nonexist(hkey, "Wine7");
    verify_reg(hkey, "Wine8", REG_SZ, "A valid line", 13, 0);
    todo_wine verify_reg(hkey, "Wine9", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
    verify_reg(hkey, "Wine10", REG_SZ, "Another valid line", 19, 0);

    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "#\"Comment1\"=\"Value 1\"\n"
                    ";\"Comment2\"=\"Value 2\"\n"
                    "    #\"Comment3\"=\"Value 3\"\n"
                    "    ;\"Comment4\"=\"Value 4\"\n"
                    "\"Wine11\"=\"Value 6\"#\"Comment5\"=\"Value 5\"\n"
                    "\"Wine12\"=\"Value 7\";\"Comment6\"=\"Value 6\"\n\n");
    verify_reg_nonexist(hkey, "Comment1");
    verify_reg_nonexist(hkey, "Comment2");
    verify_reg_nonexist(hkey, "Comment3");
    verify_reg_nonexist(hkey, "Comment4");
    todo_wine verify_reg_nonexist(hkey, "Wine11");
    verify_reg_nonexist(hkey, "Comment5");
    verify_reg(hkey, "Wine12", REG_SZ, "Value 7", 8, TODO_REG_SIZE|TODO_REG_DATA);
    verify_reg_nonexist(hkey, "Comment6");

    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine13\"=#\"Value 8\"\n"
                    "\"Wine14\"=;\"Value 9\"\n"
                    "\"Wine15\"=\"#comment1\"\n"
                    "\"Wine16\"=\";comment2\"\n"
                    "\"Wine17\"=\"Value#comment3\"\n"
                    "\"Wine18\"=\"Value;comment4\"\n"
                    "\"Wine19\"=\"Value #comment5\"\n"
                    "\"Wine20\"=\"Value ;comment6\"\n"
                    "\"Wine21\"=#dword:00000001\n"
                    "\"Wine22\"=;dword:00000002\n"
                    "\"Wine23\"=dword:00000003#comment\n"
                    "\"Wine24\"=dword:00000004;comment\n\n");
    verify_reg_nonexist(hkey, "Wine13");
    verify_reg_nonexist(hkey, "Wine14");
    verify_reg(hkey, "Wine15", REG_SZ, "#comment1", 10, 0);
    verify_reg(hkey, "Wine16", REG_SZ, ";comment2", 10, 0);
    verify_reg(hkey, "Wine17", REG_SZ, "Value#comment3", 15, 0);
    verify_reg(hkey, "Wine18", REG_SZ, "Value;comment4", 15, 0);
    verify_reg(hkey, "Wine19", REG_SZ, "Value #comment5", 16, 0);
    verify_reg(hkey, "Wine20", REG_SZ, "Value ;comment6", 16, 0);
    verify_reg_nonexist(hkey, "Wine21");
    verify_reg_nonexist(hkey, "Wine22");
    verify_reg_nonexist(hkey, "Wine23");
    dword = 0x00000004;
673
    verify_reg(hkey, "Wine24", REG_DWORD, &dword, sizeof(dword), 0);
674

675 676 677 678 679 680 681
    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine25a\"=dword:1234;5678\n"
                    "\"Wine25b\"=dword:1234 ;5678\n"
                    "\"Wine25c\"=dword:1234#5678\n"
                    "\"Wine25d\"=dword:1234 #5678\n\n");
    dword = 0x1234;
682 683
    verify_reg(hkey, "Wine25a", REG_DWORD, &dword, sizeof(dword), 0);
    verify_reg(hkey, "Wine25b", REG_DWORD, &dword, sizeof(dword), 0);
684 685 686
    verify_reg_nonexist(hkey, "Wine25c");
    verify_reg_nonexist(hkey, "Wine25d");

687 688 689 690 691 692 693 694 695 696 697
    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine26a\"=\"Value1\"  ;comment\n"
                    "\"Wine26b\"=\"Value2\"\t\t;comment\n"
                    "\"Wine26c\"=\"Value3\"  #comment\n"
                    "\"Wine26d\"=\"Value4\"\t\t#comment\n\n");
    todo_wine verify_reg(hkey, "Wine26a", REG_SZ, "Value1", 7, 0);
    todo_wine verify_reg(hkey, "Wine26b", REG_SZ, "Value2", 7, 0);
    verify_reg_nonexist(hkey, "Wine26c");
    verify_reg_nonexist(hkey, "Wine26d");

698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713
    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Multi-Line1\"=hex(7):4c,69,6e,65,20,\\\n"
                    "  63,6f,6e,\\;comment\n"
                    "  63,61,74,\\;comment\n"
                    "  65,6e,61,74,69,6f,6e,00,00\n\n");
    todo_wine verify_reg(hkey, "Multi-Line1", REG_MULTI_SZ, "Line concatenation\0", 20, 0);

    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Multi-Line2\"=hex(7):4c,69,6e,65,20,\\\n"
                    "  63,6f,6e,\\;comment\n"
                    "  63,61,74,;comment\n"
                    "  65,6e,61,74,69,6f,6e,00,00\n\n");
    todo_wine verify_reg(hkey, "Multi-Line2", REG_MULTI_SZ, "Line concat", 12, 0);

714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740
    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Multi-Line3\"=hex(7):4c,69,6e,\\;comment\n"
                    "  65,20,\\;comment\n"
                    "  63,6f,6e,\\;comment\n"
                    "  63,61,74,\\;comment\n"
                    "  65,6e,61,74,69,6f,6e,00,00\n\n");
    todo_wine verify_reg(hkey, "Multi-Line3", REG_MULTI_SZ, "Line concatenation\0", 20, 0);

    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Multi-Line4\"=hex(7):4c,69,6e,\\;#comment\n"
                    "  65,20,\\;#comment\n"
                    "  63,6f,6e,\\;#comment\n"
                    "  63,61,74,\\;#comment\n"
                    "  65,6e,61,74,69,6f,6e,00,00\n\n");
    todo_wine verify_reg(hkey, "Multi-Line4", REG_MULTI_SZ, "Line concatenation\0", 20, 0);

    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Multi-Line5\"=hex(7):4c,69,6e,\\;comment\n"
                    "  65,20,\\;comment\n"
                    "  63,6f,6e,\\;comment\n"
                    "  63,61,74,\\#comment\n"
                    "  65,6e,61,74,69,6f,6e,00,00\n\n");
    verify_reg_nonexist(hkey, "Multi-Line5");

741 742 743 744 745 746
    RegCloseKey(hkey);

    lr = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
    ok(lr == ERROR_SUCCESS, "RegDeleteKeyA failed: %d\n", lr);
}

747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
static void test_import_with_whitespace(void)
{
    HKEY hkey;
    LONG lr;
    DWORD dword;

    exec_import_str("  REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n\n");

    lr = RegOpenKeyExA(HKEY_CURRENT_USER, KEY_BASE, 0, KEY_READ, &hkey);
    ok(lr == ERROR_SUCCESS, "RegOpenKeyExA failed: got %d, expected 0\n", lr);

    exec_import_str("  REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine1a\"=\"Value\"\n\n");
    verify_reg(hkey, "Wine1a", REG_SZ, "Value", 6, 0);

    exec_import_str("\tREGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine1b\"=\"Value\"\n\n");
    verify_reg(hkey, "Wine1b", REG_SZ, "Value", 6, 0);

    exec_import_str(" \t REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine1c\"=\"Value\"\n\n");
    verify_reg(hkey, "Wine1c", REG_SZ, "Value", 6, 0);

    exec_import_str("REGEDIT4\n\n"
                    "  [HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine2a\"=\"Value\"\n\n");
777
    verify_reg(hkey, "Wine2a", REG_SZ, "Value", 6, 0);
778 779 780 781

    exec_import_str("REGEDIT4\n\n"
                    "\t[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine2b\"=\"Value\"\n\n");
782
    verify_reg(hkey, "Wine2b", REG_SZ, "Value", 6, 0);
783 784 785 786

    exec_import_str("REGEDIT4\n\n"
                    " \t [HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine2c\"=\"Value\"\n\n");
787
    verify_reg(hkey, "Wine2c", REG_SZ, "Value", 6, 0);
788 789 790 791

    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "  \"Wine3a\"=\"Two leading spaces\"\n\n");
792
    verify_reg(hkey, "Wine3a", REG_SZ, "Two leading spaces", 19, 0);
793 794 795 796

    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\t\"Wine3b\"=\"One leading tab\"\n\n");
797
    verify_reg(hkey, "Wine3b", REG_SZ, "One leading tab", 16, 0);
798 799 800 801

    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    " \t \"Wine3c\"=\"Space, tab, space\"\n\n");
802
    verify_reg(hkey, "Wine3c", REG_SZ, "Space, tab, space", 18, 0);
803 804 805 806 807 808 809 810 811

    exec_import_str("                    REGEDIT4\n\n"
                    "\t\t\t[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\t    \"Wine4a\"=\"Tab and four spaces\"\n"
                    "    \"Wine4b\"=dword:00112233\n"
                    "\t  \t  \t  \t  \t  \t  \"Wine4c\"=hex(7):4c,69,6e,65,20,\\\n"
                    "        63,6f,6e,\\;comment\n"
                    "\t\t\t\t63,61,74,\\;comment\n"
                    "  \t65,6e,61,74,69,6f,6e,00,00\n\n");
812
    verify_reg(hkey, "Wine4a", REG_SZ, "Tab and four spaces", 20, 0);
813
    dword = 0x112233;
814
    verify_reg(hkey, "Wine4b", REG_DWORD, &dword, sizeof(dword), 0);
815 816 817 818 819 820 821 822
    todo_wine verify_reg(hkey, "Wine4c", REG_MULTI_SZ, "Line concatenation\0", 20, 0);

    exec_import_str("    REGEDIT4\n\n"
                    "\t[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "  \"Wine5a\"=\"Leading spaces\"\n"
                    "\t\t\"Wine5b\"\t\t=\"Leading tabs\"\n"
                    "\t  \"Wine5c\"=\t  \"Tabs and spaces\"\n"
                    "    \"Wine5d\"    \t    =    \t    \"More whitespace\"\n\n");
823 824 825 826
    verify_reg(hkey, "Wine5a", REG_SZ, "Leading spaces", 15, 0);
    verify_reg(hkey, "Wine5b", REG_SZ, "Leading tabs", 13, 0);
    verify_reg(hkey, "Wine5c", REG_SZ, "Tabs and spaces", 16, 0);
    verify_reg(hkey, "Wine5d", REG_SZ, "More whitespace", 16, 0);
827 828 829 830 831 832 833 834

    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"  Wine6a\"=\"Leading spaces\"\n"
                    "\"\t\tWine6b\"=\"Leading tabs\"\n"
                    "  \"  Wine6c  \"  =  \"  Spaces everywhere  \"  \n\n");
    verify_reg(hkey, "  Wine6a", REG_SZ, "Leading spaces", 15, 0);
    verify_reg(hkey, "\t\tWine6b", REG_SZ, "Leading tabs", 13, 0);
835
    verify_reg(hkey, "  Wine6c  ", REG_SZ, "  Spaces everywhere  ", 22, 0);
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850

    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine7a\"=\"    Four spaces in the data\"\n"
                    "\"Wine7b\"=\"\t\tTwo tabs in the data\"\n\n");
    verify_reg(hkey, "Wine7a", REG_SZ, "    Four spaces in the data", 28, 0);
    verify_reg(hkey, "Wine7b", REG_SZ, "\t\tTwo tabs in the data", 23, 0);

    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine8a\"=\"Trailing spaces\"    \n"
                    "\"Wine8b\"=\"Trailing tabs and spaces\"\t  \t\n\n");
    verify_reg(hkey, "Wine8a", REG_SZ, "Trailing spaces", 16, 0);
    verify_reg(hkey, "Wine8b", REG_SZ, "Trailing tabs and spaces", 25, 0);

851 852 853 854 855
    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine9a\"=dword:  00000008\n"
                    "\"Wine9b\"=dword:\t\t00000008\n\n");
    dword = 0x00000008;
856 857
    verify_reg(hkey, "Wine9a", REG_DWORD, &dword, sizeof(dword), 0);
    verify_reg(hkey, "Wine9b", REG_DWORD, &dword, sizeof(dword), 0);
858

859 860 861 862 863 864 865 866 867 868
    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "@  =  \"Test Value\"\n\n");
    todo_wine verify_reg(hkey, "", REG_SZ, "Test Value", 11, 0);

    exec_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\t@\t=\tdword:\t00000008\t\n\n");
    todo_wine verify_reg(hkey, "", REG_DWORD, &dword, sizeof(DWORD), 0);

869 870 871 872 873 874 875
    lr = RegCloseKey(hkey);
    ok(lr == ERROR_SUCCESS, "RegCloseKey failed: got %d, expected 0\n", lr);

    lr = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
    ok(lr == ERROR_SUCCESS, "RegDeleteKeyA failed: got %d, expected 0\n", lr);
}

876 877 878 879 880 881 882 883 884 885 886 887 888 889
START_TEST(regedit)
{
    WCHAR wchar_test[] = {0xFEFF,'W','i','n','d','o','w','s',' ','R','e','g',
        'i','s','t','r','y',' ','E','d','i','t','o','r',' ','V','e','r','s',
        'i','o','n',' ','5','.','0','0','\n','\n',0};

    if(!exec_import_str("REGEDIT4\r\n\r\n")){
        win_skip("regedit not available, skipping regedit tests\n");
        return;
    }

    supports_wchar = exec_import_wstr(wchar_test);

    test_basic_import();
890
    test_basic_import_31();
891
    test_invalid_import();
892
    test_comments();
893
    test_import_with_whitespace();
894
}