reg.c 215 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * Copyright 2014 Akihiro Sagawa
 *
 * 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
 */

19
#include <stdio.h>
20 21 22 23 24 25 26 27 28 29
#include <windows.h>
#include "wine/test.h"

#define lok ok_(__FILE__,line)
#define KEY_BASE "Software\\Wine\\reg_test"
#define REG_EXIT_SUCCESS 0
#define REG_EXIT_FAILURE 1
#define TODO_REG_TYPE    (0x0001u)
#define TODO_REG_SIZE    (0x0002u)
#define TODO_REG_DATA    (0x0004u)
30
#define TODO_REG_COMPARE (0x0008u)
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

#define run_reg_exe(c,r) run_reg_exe_(__LINE__,c,r)
static BOOL run_reg_exe_(unsigned line, const char *cmd, DWORD *rc)
{
    STARTUPINFOA si = {sizeof(STARTUPINFOA)};
    PROCESS_INFORMATION pi;
    BOOL bret;
    DWORD ret;
    char cmdline[256];

    si.dwFlags = STARTF_USESTDHANDLES;
    si.hStdInput  = INVALID_HANDLE_VALUE;
    si.hStdOutput = INVALID_HANDLE_VALUE;
    si.hStdError  = INVALID_HANDLE_VALUE;

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

    ret = WaitForSingleObject(pi.hProcess, 10000);
    if (ret == WAIT_TIMEOUT)
        TerminateProcess(pi.hProcess, 1);

    bret = GetExitCodeProcess(pi.hProcess, rc);
    lok(bret, "GetExitCodeProcess failed: %d\n", GetLastError());

    CloseHandle(pi.hThread);
    CloseHandle(pi.hProcess);
    return bret;
}

#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)
{
    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)
        return;

77
    todo_wine_if (todo & TODO_REG_TYPE)
78
        lok(type == exp_type, "got wrong type %d, expected %d\n", type, exp_type);
79
    todo_wine_if (todo & TODO_REG_SIZE)
80
        lok(size == exp_size, "got wrong size %d, expected %d\n", size, exp_size);
81 82 83 84 85
    if (exp_data)
    {
        todo_wine_if (todo & TODO_REG_DATA)
            lok(memcmp(data, exp_data, size) == 0, "got wrong data\n");
    }
86 87
}

88 89 90 91 92 93 94
#define verify_reg_nonexist(k,v) verify_reg_nonexist_(__LINE__,k,v)
static void verify_reg_nonexist_(unsigned line, HKEY hkey, const char *value)
{
    LONG err;

    err = RegQueryValueExA(hkey, value, NULL, NULL, NULL, NULL);
    lok(err == ERROR_FILE_NOT_FOUND, "registry value '%s' shouldn't exist; got %d, expected 2\n",
95
        (value && *value) ? value : "(Default)", err);
96 97
}

98 99 100 101 102 103 104 105 106
#define open_key(b,p,s,k) open_key_(__LINE__,b,p,s,k)
static void open_key_(unsigned line, const HKEY base, const char *path, const DWORD sam, HKEY *hkey)
{
    LONG err;

    err = RegOpenKeyExA(base, path, 0, KEY_READ|sam, hkey);
    lok(err == ERROR_SUCCESS, "RegOpenKeyExA failed: %d\n", err);
}

107 108
#define verify_key(k,s) verify_key_(__LINE__,k,s)
static void verify_key_(unsigned line, HKEY key_base, const char *subkey)
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
{
    HKEY hkey;
    LONG err;

    err = RegOpenKeyExA(key_base, subkey, 0, KEY_READ, &hkey);
    lok(err == ERROR_SUCCESS, "RegOpenKeyExA failed: got %d\n", err);

    if (hkey)
        RegCloseKey(hkey);
}

#define verify_key_nonexist(k,s) verify_key_nonexist_(__LINE__,k,s)
static void verify_key_nonexist_(unsigned line, HKEY key_base, const char *subkey)
{
    HKEY hkey;
    LONG err;

    err = RegOpenKeyExA(key_base, subkey, 0, KEY_READ, &hkey);
    lok(err == ERROR_FILE_NOT_FOUND, "registry key '%s' shouldn't exist; got %d, expected 2\n",
        subkey, err);

    if (hkey)
        RegCloseKey(hkey);
}

134 135 136 137 138 139 140 141 142 143
#define add_key(k,p,s) add_key_(__LINE__,k,p,s)
static void add_key_(unsigned line, const HKEY hkey, const char *path, HKEY *subkey)
{
    LONG err;

    err = RegCreateKeyExA(hkey, path, 0, NULL, REG_OPTION_NON_VOLATILE,
                          KEY_READ|KEY_WRITE, NULL, subkey, NULL);
    lok(err == ERROR_SUCCESS, "RegCreateKeyExA failed: %d\n", err);
}

144 145 146 147 148 149 150 151 152 153 154 155
#define delete_key(k,p) delete_key_(__LINE__,k,p)
static void delete_key_(unsigned line, const HKEY hkey, const char *path)
{
    if (path && *path)
    {
        LONG err;

        err = RegDeleteKeyA(hkey, path);
        lok(err == ERROR_SUCCESS, "RegDeleteKeyA failed: %d\n", err);
    }
}

156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
static LONG delete_tree(const HKEY key, const char *subkey)
{
    HKEY hkey;
    LONG ret;
    char *subkey_name = NULL;
    DWORD max_subkey_len, subkey_len;
    static const char empty[1];

    ret = RegOpenKeyExA(key, subkey, 0, KEY_READ, &hkey);
    if (ret) return ret;

    ret = RegQueryInfoKeyA(hkey, NULL, NULL, NULL, NULL, &max_subkey_len,
                           NULL, NULL, NULL, NULL, NULL, NULL);
    if (ret) goto cleanup;

    max_subkey_len++;

    subkey_name = HeapAlloc(GetProcessHeap(), 0, max_subkey_len);
    if (!subkey_name)
    {
        ret = ERROR_NOT_ENOUGH_MEMORY;
        goto cleanup;
    }

    for (;;)
    {
        subkey_len = max_subkey_len;
        ret = RegEnumKeyExA(hkey, 0, subkey_name, &subkey_len, NULL, NULL, NULL, NULL);
        if (ret == ERROR_NO_MORE_ITEMS) break;
        if (ret) goto cleanup;
        ret = delete_tree(hkey, subkey_name);
        if (ret) goto cleanup;
    }

    ret = RegDeleteKeyA(hkey, empty);

cleanup:
    HeapFree(GetProcessHeap(), 0, subkey_name);
    RegCloseKey(hkey);
    return ret;
}

198 199 200 201 202 203 204 205 206 207
#define add_value(k,n,t,d,s) add_value_(__LINE__,k,n,t,d,s)
static void add_value_(unsigned line, HKEY hkey, const char *name, DWORD type,
                       const void *data, size_t size)
{
    LONG err;

    err = RegSetValueExA(hkey, name, 0, type, (const BYTE *)data, size);
    lok(err == ERROR_SUCCESS, "RegSetValueExA failed: %d\n", err);
}

208 209 210 211 212 213 214 215 216
#define delete_value(k,n) delete_value_(__LINE__,k,n)
static void delete_value_(unsigned line, const HKEY hkey, const char *name)
{
    LONG err;

    err = RegDeleteValueA(hkey, name);
    lok(err == ERROR_SUCCESS, "RegDeleteValueA failed: %d\n", err);
}

217 218
static void test_add(void)
{
219
    HKEY hkey;
220 221
    LONG err;
    DWORD r, dword, type, size;
222
    char buffer[22];
223 224 225 226

    run_reg_exe("reg add", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

227 228 229
    run_reg_exe("reg add /?", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);

230 231 232 233
    run_reg_exe("reg add /h", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);

    run_reg_exe("reg add -H", &r);
234
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
235

236 237 238
    err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
    ok(err == ERROR_SUCCESS || err == ERROR_FILE_NOT_FOUND, "got %d\n", err);

239
    verify_key_nonexist(HKEY_CURRENT_USER, KEY_BASE);
240

241 242 243
    run_reg_exe("reg add HKCU\\" KEY_BASE " /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);

244
    open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
245

246 247
    /* Test empty type */
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v emptyType /t \"\" /d WineTest /f", &r);
248
    ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
249

250
    /* Test input key formats */
251 252
    run_reg_exe("reg add \\HKCU\\" KEY_BASE "\\keytest0 /f", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
253
    err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE "\\keytest0");
254
    ok(err == ERROR_FILE_NOT_FOUND, "got exit code %d\n", err);
255

256 257
    run_reg_exe("reg add \\\\HKCU\\" KEY_BASE "\\keytest1 /f", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
258
    err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE "\\keytest1");
259
    ok(err == ERROR_FILE_NOT_FOUND, "got exit code %d\n", err);
260

261
    run_reg_exe("reg add HKCU\\" KEY_BASE "\\keytest2\\\\ /f", &r);
262
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */),
263
        "got exit code %u\n", r);
264
    err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE "\\keytest2");
265
    ok(err == ERROR_FILE_NOT_FOUND || broken(err == ERROR_SUCCESS /* WinXP */),
266
        "got exit code %d\n", err);
267 268 269

    run_reg_exe("reg add HKCU\\" KEY_BASE "\\keytest3\\ /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
270
    verify_key(hkey, "keytest3");
271
    delete_key(hkey, "keytest3");
272 273 274

    run_reg_exe("reg add HKCU\\" KEY_BASE "\\keytest4 /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
275
    verify_key(hkey, "keytest4");
276
    delete_key(hkey, "keytest4");
277

278 279 280
    /* REG_NONE */
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v none0 /d deadbeef /t REG_NONE /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d\n", r);
281
    verify_reg(hkey, "none0", REG_NONE, "d\0e\0a\0d\0b\0e\0e\0f\0\0", 18, 0);
282

283 284
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v none1 /t REG_NONE /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
285
    verify_reg(hkey, "none1", REG_NONE, "\0", 2, 0);
286

287 288
    run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_NONE /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
289
    verify_reg(hkey, NULL, REG_NONE, "\0", 2, 0);
290

291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
    /* REG_SZ */
    run_reg_exe("reg add HKCU\\" KEY_BASE " /d WineTest /f", &r);
    ok(r == REG_EXIT_SUCCESS || broken(r == REG_EXIT_FAILURE /* WinXP */),
       "got exit code %d, expected 0\n", r);
    if (r == REG_EXIT_SUCCESS)
        verify_reg(hkey, "", REG_SZ, "WineTest", 9, 0);
    else
        win_skip("broken reg.exe detected\n");

    run_reg_exe("reg add HKCU\\" KEY_BASE " /v test /d deadbeef /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_reg(hkey, "test", REG_SZ, "deadbeef", 9, 0);

    run_reg_exe("reg add HKCU\\" KEY_BASE " /v test /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
306
    verify_reg(hkey, "test", REG_SZ, "", 1, 0);
307

308
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v test1 /t REG_SZ /f /d", &r);
309
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
310

311 312 313 314 315 316
    run_reg_exe("reg add HKEY_CURRENT_USER\\" KEY_BASE " /ve /d WineTEST /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_reg(hkey, "", REG_SZ, "WineTEST", 9, 0);

    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_SZ /v test2 /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
317
    verify_reg(hkey, "test2", REG_SZ, "", 1, 0);
318 319 320 321 322

    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_SZ /v test3 /f /d \"\"", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_reg(hkey, "test3", REG_SZ, "", 1, 0);

323 324
    run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
325
    verify_reg(hkey, NULL, REG_SZ, "", 1, 0);
326 327 328

    run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_SZ /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
329
    verify_reg(hkey, NULL, REG_SZ, "", 1, 0);
330

331 332 333
    /* REG_EXPAND_SZ */
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v expand0 /t REG_EXpand_sz /d \"dead%PATH%beef\" /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
334
    verify_reg(hkey, "expand0", REG_EXPAND_SZ, "dead%PATH%beef", 15, 0);
335 336 337

    run_reg_exe("reg add HKCU\\" KEY_BASE " /v expand1 /t REG_EXpand_sz /d \"dead^%PATH^%beef\" /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
338
    verify_reg(hkey, "expand1", REG_EXPAND_SZ, "dead^%PATH^%beef", 17, 0);
339 340 341

    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_EXPAND_SZ /v expand2 /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
342
    verify_reg(hkey, "expand2", REG_EXPAND_SZ, "", 1, 0);
343 344 345

    run_reg_exe("reg add HKEY_CURRENT_USER\\" KEY_BASE " /ve /t REG_EXPAND_SZ /d WineTEST /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
346
    verify_reg(hkey, "", REG_EXPAND_SZ, "WineTEST", 9, 0);
347 348 349

    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_EXPAND_SZ /v expand3 /f /d \"\"", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
350
    verify_reg(hkey, "expand3", REG_EXPAND_SZ, "", 1, 0);
351

352 353
    run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_EXPAND_SZ /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
354
    verify_reg(hkey, NULL, REG_EXPAND_SZ, "", 1, 0);
355

356 357 358 359 360 361 362 363
    /* REG_BINARY */
    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_BINARY /v bin0 /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
    verify_reg(hkey, "bin0", REG_BINARY, buffer, 0, 0);

    run_reg_exe("reg add HKEY_CURRENT_USER\\" KEY_BASE " /ve /t REG_BINARY /d deadbeef /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
    dword = 0xefbeadde;
364
    verify_reg(hkey, "", REG_BINARY, &dword, sizeof(DWORD), 0);
365 366

    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_BINARY /v bin1 /f /d 0xDeAdBeEf", &r);
367
    ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
368
    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_BINARY /v bin2 /f /d x01", &r);
369
    ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
370
    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_BINARY /v bin3 /f /d 01x", &r);
371
    ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
372 373 374 375 376 377 378 379 380 381 382 383 384

    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_BINARY /v bin4 /f /d DeAdBeEf0DD", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
    /* Remaining nibble prefixed */
    buffer[0] = 0x0d; buffer[1] = 0xea; buffer[2] = 0xdb;
    buffer[3] = 0xee; buffer[4] = 0xf0; buffer[5] = 0xdd;
    /* Remaining nibble suffixed on winXP */
    buffer[6] = 0xde; buffer[7] = 0xad; buffer[8] = 0xbe;
    buffer[9] = 0xef; buffer[10] = 0x0d; buffer[11] = 0xd0;
    size = 6;
    err = RegQueryValueExA(hkey, "bin4", NULL, &type, (void *) (buffer+12), &size);
    ok(err == ERROR_SUCCESS, "RegQueryValueEx failed: got %d\n", err);
    ok(type == REG_BINARY, "got wrong type %u\n", type);
385 386
    ok(size == 6, "got wrong size %u\n", size);
    ok(memcmp(buffer, buffer+12, 6) == 0 ||
387 388
        broken(memcmp(buffer+6, buffer+12, 6) == 0 /* WinXP */), "got wrong data\n");

389 390 391 392
    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_BINARY /v bin5 /d \"\" /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
    verify_reg(hkey, "bin5", REG_BINARY, buffer, 0, 0);

393
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v bin6 /t REG_BINARY /f /d", &r);
394
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
395

396 397
    run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_BINARY /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
398
    verify_reg(hkey, NULL, REG_BINARY, buffer, 0, 0);
399

400 401 402 403 404 405 406 407 408 409
    /* REG_DWORD */
    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_DWORD /f /d 12345678", &r);
    ok(r == REG_EXIT_SUCCESS || broken(r == REG_EXIT_FAILURE /* WinXP */),
       "got exit code %d, expected 0\n", r);
    dword = 12345678;
    if (r == REG_EXIT_SUCCESS)
        verify_reg(hkey, "", REG_DWORD, &dword, sizeof(dword), 0);
    else
        win_skip("broken reg.exe detected\n");

410
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword0 /t REG_DWORD /f /d", &r);
411
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
412
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword1 /t REG_DWORD /f", &r);
413
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */),
414
       "got exit code %d, expected 1\n", r);
415
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword2 /t REG_DWORD /d zzz /f", &r);
416
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
417
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword3 /t REG_DWORD /d deadbeef /f", &r);
418
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
419
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword4 /t REG_DWORD /d 123xyz /f", &r);
420
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
421 422 423 424 425 426 427 428 429 430 431 432 433

    run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword5 /t reg_dword /d 12345678 /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    dword = 12345678;
    verify_reg(hkey, "dword5", REG_DWORD, &dword, sizeof(dword), 0);

    run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword6 /t REG_DWORD /D 0123 /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    size = sizeof(dword);
    err = RegQueryValueExA(hkey, "dword6", NULL, &type, (LPBYTE)&dword, &size);
    ok(err == ERROR_SUCCESS, "RegQueryValueEx failed: got %d\n", err);
    ok(type == REG_DWORD, "got wrong type %d, expected %d\n", type, REG_DWORD);
    ok(size == sizeof(DWORD), "got wrong size %d, expected %d\n", size, (int)sizeof(DWORD));
434
    ok(dword == 123 || broken(dword == 0123 /* WinXP */), "got wrong data %d, expected 123\n", dword);
435 436

    run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword7 /t reg_dword /d 0xabcdefg /f", &r);
437
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
438 439 440 441

    run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword8 /t REG_dword /d 0xdeadbeef /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    dword = 0xdeadbeef;
442
    verify_reg(hkey, "dword8", REG_DWORD, &dword, sizeof(dword), 0);
443

444
    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_DWORD /v dword9 /f /d -1", &r);
445
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */), "got exit code %u\n", r);
446
    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_DWORD /v dword10 /f /d -0x1", &r);
447
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */), "got exit code %u\n", r);
448

449
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword8 /t REG_dword /d 0x01ffffffff /f", &r);
450
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */), "got exit code %d\n", r);
451

452 453 454
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword12 /t REG_DWORD /d 0xffffffff /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    dword = ~0u;
455
    verify_reg(hkey, "dword12", REG_DWORD, &dword, sizeof(dword), 0);
456 457

    run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword13 /t REG_DWORD /d 00x123 /f", &r);
458
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
459

460 461 462 463 464
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword14 /t REG_DWORD /d 0X123 /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    dword = 0x123;
    verify_reg(hkey, "dword14", REG_DWORD, &dword, sizeof(dword), 0);

465 466 467
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v dword15 /t REG_DWORD /d 4294967296 /f", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */), "got exit code %u\n", r);

468
    run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_DWORD /f", &r);
469
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */), "got exit code %u\n", r);
470

471 472 473 474 475 476
    /* REG_DWORD_LITTLE_ENDIAN */
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v DWORD_LE /t REG_DWORD_LITTLE_ENDIAN /d 456 /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    dword = 456;
    verify_reg(hkey, "DWORD_LE", REG_DWORD_LITTLE_ENDIAN, &dword, sizeof(dword), 0);

477 478 479 480
    /* REG_DWORD_BIG_ENDIAN */
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v DWORD_BE /t REG_DWORD_BIG_ENDIAN /d 456 /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
    dword = 456;
481
    verify_reg(hkey, "DWORD_BE", REG_DWORD_BIG_ENDIAN, &dword, sizeof(dword), 0);
482 483 484
    /* REG_DWORD_BIG_ENDIAN is broken in every version of windows. It behaves like
     * an ordinary REG_DWORD - that is little endian. GG */

485 486 487 488
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v DWORD_BE2 /t REG_DWORD_BIG_ENDIAN /f /d", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);

    run_reg_exe("reg add HKCU\\" KEY_BASE " /v DWORD_BE3 /t REG_DWORD_BIG_ENDIAN /f", &r);
489
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */), "got exit code %u\n", r);
490 491

    run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_DWORD_BIG_ENDIAN /f", &r);
492
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */), "got exit code %u\n", r);
493

494 495
    /* REG_MULTI_SZ */
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi0 /t REG_MULTI_SZ /d \"three\\0little\\0strings\" /f", &r);
496
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
497
    memcpy(buffer, "three\0little\0strings\0", 22);
498
    verify_reg(hkey, "multi0", REG_MULTI_SZ, buffer, 22, 0);
499 500

    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi1 /s \"#\" /d \"three#little#strings\" /f", &r);
501 502
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
    verify_reg(hkey, "multi1", REG_MULTI_SZ, buffer, 22, 0);
503 504

    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi2 /d \"\" /f", &r);
505 506
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
    verify_reg(hkey, "multi2", REG_MULTI_SZ, &buffer[21], 1, 0);
507 508 509

    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi3 /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %u\n", r);
510
    verify_reg(hkey, "multi3", REG_MULTI_SZ, &buffer[21], 1, 0);
511 512

    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi4 /s \"#\" /d \"threelittlestrings\" /f", &r);
513 514
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
    verify_reg(hkey, "multi4", REG_MULTI_SZ, "threelittlestrings\0", 20, 0);
515 516

    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi5 /s \"#randomgibberish\" /d \"three#little#strings\" /f", &r);
517
    ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
518
    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi6 /s \"\\0\" /d \"three\\0little\\0strings\" /f", &r);
519
    ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
520
    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi7 /s \"\" /d \"three#little#strings\" /f", &r);
521
    ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
522
    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi8 /s \"#\" /d \"##\" /f", &r);
523
    ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
524
    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi9 /s \"#\" /d \"two##strings\" /f", &r);
525
    ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
526
    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi10 /s \"#\" /d \"#a\" /f", &r);
527
    ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
528 529

    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi11 /s \"#\" /d \"a#\" /f", &r);
530
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
531
    buffer[0]='a'; buffer[1]=0; buffer[2]=0;
532
    verify_reg(hkey, "multi11", REG_MULTI_SZ, buffer, 3, 0);
533

534
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi12 /t REG_MULTI_SZ /f /d", &r);
535
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
536

537 538 539
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi13 /t REG_MULTI_SZ /f /s", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

540
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi14 /t REG_MULTI_SZ /d \"\\0a\" /f", &r);
541
    ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
542 543

    run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi15 /t REG_MULTI_SZ /d \"a\\0\" /f", &r);
544 545
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
    verify_reg(hkey, "multi15", REG_MULTI_SZ, buffer, 3, 0);
546 547

    run_reg_exe("reg add HKCU\\" KEY_BASE " /t REG_MULTI_SZ /v multi16 /d \"two\\0\\0strings\" /f", &r);
548
    ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
549

550
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi17 /t REG_MULTI_SZ /s \"#\" /d \"#\" /f", &r);
551
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
552
    buffer[0] = 0; buffer[1] = 0;
553
    verify_reg(hkey, "multi17", REG_MULTI_SZ, buffer, 2, 0);
554 555

    run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi18 /t REG_MULTI_SZ /d \"\\0\" /f", &r);
556 557
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
    verify_reg(hkey, "multi18", REG_MULTI_SZ, buffer, 2, 0);
558

559 560
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi19 /t REG_MULTI_SZ /s \"#\" /d \"two\\0#strings\" /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
561
    verify_reg(hkey, "multi19", REG_MULTI_SZ, "two\\0\0strings\0", 15, 0);
562 563 564

    run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi20 /t REG_MULTI_SZ /s \"#\" /d \"two#\\0strings\" /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
565
    verify_reg(hkey, "multi20", REG_MULTI_SZ, "two\0\\0strings\0", 15, 0);
566 567 568

    run_reg_exe("reg add HKCU\\" KEY_BASE " /v multi21 /t REG_MULTI_SZ /s \"#\" /d \"two\\0\\0strings\" /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
569
    verify_reg(hkey, "multi21", REG_MULTI_SZ, "two\\0\\0strings\0", 16, 0);
570

571 572
    run_reg_exe("reg add HKCU\\" KEY_BASE " /ve /t REG_MULTI_SZ /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
573
    verify_reg(hkey, NULL, REG_MULTI_SZ, buffer, 1, 0);
574

575 576
    RegCloseKey(hkey);

577 578 579 580 581 582 583 584
    /* Test duplicate switches */
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v dup1 /t REG_DWORD /d 123 /f /t REG_SZ", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS /* WinXP */),
       "got exit code %u, expected 1\n", r);

    run_reg_exe("reg add HKCU\\" KEY_BASE " /v dup2 /t REG_DWORD /d 123 /f /d 456", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);

585 586
    /* Test invalid switches */
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v invalid1 /a", &r);
587
    ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
588 589

    run_reg_exe("reg add HKCU\\" KEY_BASE " /v invalid2 /ae", &r);
590
    ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
591 592

    run_reg_exe("reg add HKCU\\" KEY_BASE " /v invalid3 /", &r);
593
    ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
594 595

    run_reg_exe("reg add HKCU\\" KEY_BASE " /v invalid4 -", &r);
596
    ok(r == REG_EXIT_FAILURE, "got exit code %u, expected 1\n", r);
597

598
    delete_key(HKEY_CURRENT_USER, KEY_BASE);
599 600 601 602 603 604 605 606 607
}

static void test_delete(void)
{
    HKEY hkey, hsubkey;
    LONG err;
    DWORD r;
    const DWORD deadbeef = 0xdeadbeef;

608 609 610
    err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
    ok(err == ERROR_SUCCESS || err == ERROR_FILE_NOT_FOUND, "got %d\n", err);

611 612 613
    run_reg_exe("reg delete", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

614 615 616
    run_reg_exe("reg delete /?", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);

617 618 619 620
    run_reg_exe("reg delete /h", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);

    run_reg_exe("reg delete -H", &r);
621
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
622

623
    add_key(HKEY_CURRENT_USER, KEY_BASE, &hkey);
624 625 626
    add_value(hkey, "foo", REG_DWORD, &deadbeef, sizeof(deadbeef));
    add_value(hkey, "bar", REG_DWORD, &deadbeef, sizeof(deadbeef));
    add_value(hkey, NULL, REG_DWORD, &deadbeef, sizeof(deadbeef));
627

628
    add_key(hkey, "subkey", &hsubkey);
629 630 631 632
    RegCloseKey(hsubkey);

    run_reg_exe("reg delete HKCU\\" KEY_BASE " /v bar /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
633
    verify_reg_nonexist(hkey, "bar");
634 635 636

    run_reg_exe("reg delete HKCU\\" KEY_BASE " /ve /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
637
    verify_reg_nonexist(hkey, "");
638 639 640

    run_reg_exe("reg delete HKCU\\" KEY_BASE " /va /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
641
    verify_reg_nonexist(hkey, "foo");
642 643
    verify_key(hkey, "subkey");

644 645 646 647
    RegCloseKey(hkey);

    run_reg_exe("reg delete HKCU\\" KEY_BASE " /f", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
648
    verify_key_nonexist(HKEY_CURRENT_USER, KEY_BASE);
649 650 651

    run_reg_exe("reg delete HKCU\\" KEY_BASE " /f", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %u\n", r);
652 653 654 655 656
}

static void test_query(void)
{
    DWORD r;
657 658 659 660 661 662 663 664 665
    HKEY key, subkey;
    LONG err;
    const char hello[] = "Hello";
    const char world[] = "World";
    const char empty1[] = "Empty1";
    const char empty2[] = "Empty2";
    const DWORD dword1 = 0x123;
    const DWORD dword2 = 0xabc;

666 667 668
    err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
    ok(err == ERROR_SUCCESS || err == ERROR_FILE_NOT_FOUND, "got %d\n", err);

669 670 671
    run_reg_exe("reg query", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

672 673 674
    run_reg_exe("reg query /?", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);

675 676 677 678
    run_reg_exe("reg query /h", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);

    run_reg_exe("reg query -H", &r);
679
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
680

681
    /* Create a test key */
682
    add_key(HKEY_CURRENT_USER, KEY_BASE, &key);
683 684

    run_reg_exe("reg query HKCU\\" KEY_BASE " /ve", &r);
685
    ok(r == REG_EXIT_SUCCESS || broken(r == REG_EXIT_FAILURE /* WinXP */),
686 687
       "got exit code %d, expected 0\n", r);

688 689 690
    add_value(key, "Test", REG_SZ, hello, sizeof(hello));
    add_value(key, "Wine", REG_DWORD, &dword1, sizeof(dword1));
    add_value(key, NULL, REG_SZ, empty1, sizeof(empty1));
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710

    run_reg_exe("reg query HKCU\\" KEY_BASE, &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);

    run_reg_exe("reg query HKCU\\" KEY_BASE " /v", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

    run_reg_exe("reg query HKCU\\" KEY_BASE " /v Missing", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

    run_reg_exe("reg query HKCU\\" KEY_BASE " /v Test", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);

    run_reg_exe("reg query HKCU\\" KEY_BASE " /v Wine", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);

    run_reg_exe("reg query HKCU\\" KEY_BASE " /ve", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);

    /* Create a test subkey */
711
    add_key(key, "Subkey", &subkey);
712 713 714
    add_value(subkey, "Test", REG_SZ, world, sizeof(world));
    add_value(subkey, "Wine", REG_DWORD, &dword2, sizeof(dword2));
    add_value(subkey, NULL, REG_SZ, empty2, sizeof(empty2));
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 741 742 743 744 745 746 747

    err = RegCloseKey(subkey);
    ok(err == ERROR_SUCCESS, "got %d, expected 0\n", err);

    run_reg_exe("reg query HKCU\\" KEY_BASE "\\subkey", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);

    run_reg_exe("reg query HKCU\\" KEY_BASE "\\subkey /v Test", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);

    run_reg_exe("reg query HKCU\\" KEY_BASE "\\subkey /v Wine", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);

    run_reg_exe("reg query HKCU\\" KEY_BASE "\\subkey /ve", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);

    /* Test recursion */
    run_reg_exe("reg query HKCU\\" KEY_BASE " /s", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);

    run_reg_exe("reg query HKCU\\" KEY_BASE " /v Test /s", &r);
    ok(r == REG_EXIT_SUCCESS || r == REG_EXIT_FAILURE /* WinXP */,
       "got exit code %d, expected 0\n", r);

    run_reg_exe("reg query HKCU\\" KEY_BASE " /v Wine /s", &r);
    ok(r == REG_EXIT_SUCCESS || r == REG_EXIT_FAILURE /* WinXP */,
       "got exit code %d, expected 0\n", r);

    run_reg_exe("reg query HKCU\\" KEY_BASE " /ve /s", &r);
    ok(r == REG_EXIT_SUCCESS || r == REG_EXIT_FAILURE /* WinXP */,
       "got exit code %d, expected 0\n", r);

    /* Clean-up, then query */
748
    delete_key(key, "subkey");
749 750 751 752 753 754 755

    err = RegCloseKey(key);
    ok(err == ERROR_SUCCESS, "got %d, expected 0\n", err);

    run_reg_exe("reg query HKCU\\" KEY_BASE "\\subkey", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

756
    delete_key(HKEY_CURRENT_USER, KEY_BASE);
757 758

    run_reg_exe("reg query HKCU\\" KEY_BASE, &r);
759 760 761
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
}

762 763 764 765 766 767 768 769 770 771 772 773 774 775 776
static void test_v_flags(void)
{
    DWORD r;

    run_reg_exe("reg add HKCU\\" KEY_BASE " /v Wine /ve", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

    run_reg_exe("reg delete HKCU\\" KEY_BASE " /v Wine /ve", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

    run_reg_exe("reg delete HKCU\\" KEY_BASE " /v Wine /va", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

    run_reg_exe("reg delete HKCU\\" KEY_BASE " /ve /va", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
777 778 779 780 781 782 783 784 785 786 787 788 789

    /* No /v argument */
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

    run_reg_exe("reg add HKCU\\" KEY_BASE " /d Test /f /v", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

    run_reg_exe("reg delete HKCU\\" KEY_BASE " /v", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

    run_reg_exe("reg delete HKCU\\" KEY_BASE " /f /v", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
790 791 792 793 794 795 796

    /* Multiple /v switches */
    run_reg_exe("reg add HKCU\\" KEY_BASE " /v Wine /t REG_DWORD /d 0x1 /v Test /f", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

    run_reg_exe("reg delete HKCU\\" KEY_BASE " /v Wine /v Test /f", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
797 798
}

799 800 801 802 803 804 805 806
static BOOL write_file(const void *str, DWORD size)
{
    HANDLE file;
    BOOL ret;
    DWORD written;

    file = CreateFileA("test.reg", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
                       FILE_ATTRIBUTE_NORMAL, NULL);
807
    ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
808 809 810 811 812 813 814 815 816 817
    if (file == INVALID_HANDLE_VALUE)
        return FALSE;

    ret = WriteFile(file, str, size, &written, NULL);
    ok(ret, "WriteFile failed: %u\n", GetLastError());
    CloseHandle(file);

    return ret;
}

818 819 820 821
#define test_import_str(c,r) import_reg(__LINE__,c,FALSE,r)
#define test_import_wstr(c,r) import_reg(__LINE__,c,TRUE,r)

static BOOL import_reg(unsigned line, const char *contents, BOOL unicode, DWORD *rc)
822
{
823
    int lenA;
824 825
    BOOL ret;

826
    lenA = strlen(contents);
827

828 829 830 831 832 833 834
    if (unicode)
    {
        int len = MultiByteToWideChar(CP_UTF8, 0, contents, lenA, NULL, 0);
        int size = len * sizeof(WCHAR);
        WCHAR *wstr = HeapAlloc(GetProcessHeap(), 0, size);
        if (!wstr) return FALSE;
        MultiByteToWideChar(CP_UTF8, 0, contents, lenA, wstr, len);
835

836 837 838 839 840
        ret = write_file(wstr, size);
        HeapFree(GetProcessHeap(), 0, wstr);
    }
    else
        ret = write_file(contents, lenA);
841

842
    if (!ret) return FALSE;
843 844 845 846 847 848 849 850 851

    run_reg_exe("reg import test.reg", rc);

    ret = DeleteFileA("test.reg");
    lok(ret, "DeleteFile failed: %u\n", GetLastError());

    return ret;
}

852 853
static void test_import(void)
{
854
    DWORD r, dword = 0x123, type, size;
855
    char buffer[24];
856
    HKEY hkey, subkey = NULL;
857
    LONG err;
858
    BYTE hex[8];
859

860 861 862
    err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
    ok(err == ERROR_SUCCESS || err == ERROR_FILE_NOT_FOUND, "got %d\n", err);

863 864 865 866
    run_reg_exe("reg import", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

    run_reg_exe("reg import /?", &r);
867
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
868

869 870 871 872
    run_reg_exe("reg import /h", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);

    run_reg_exe("reg import -H", &r);
873
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
874

875 876
    run_reg_exe("reg import missing.reg", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
877

878
    run_reg_exe("reg import a.reg b.reg", &r);
879 880
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

881 882 883 884 885 886 887 888 889
    /* Test file contents */
    test_import_str("regedit\n", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);

    test_import_str("regedit4\n", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);

890
    test_import_str("REGEDIT", &r);
891
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
892

893
    test_import_str("REGEDIT\n", &r);
894
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
895 896

    test_import_str("REGEDIT4\n", &r);
897
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
898 899

    test_import_str(" REGEDIT4\n", &r);
900
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
901 902

    test_import_str("\tREGEDIT4\n", &r);
903
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
904 905 906 907 908 909 910 911 912 913 914 915 916 917

    test_import_str("\nREGEDIT4\n", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);

    test_import_str("AREGEDIT4\n", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);

    test_import_str("1REGEDIT4\n", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);

    test_import_str("REGEDIT3\n", &r);
918
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
919 920

    test_import_str("REGEDIT5\n", &r);
921
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
922 923

    test_import_str("REGEDIT9\n", &r);
924
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
925 926

    test_import_str("REGEDIT 4\n", &r);
927
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
928 929

    test_import_str("REGEDIT4 FOO\n", &r);
930
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
931

932 933
    test_import_str("REGEDIT4\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n", &r);
934
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
935

936
    open_key(HKEY_CURRENT_USER, KEY_BASE, KEY_SET_VALUE, &hkey);
937

938 939 940 941 942 943 944 945 946 947 948 949
    test_import_str("REGEDIT4\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine\"=dword:00000123\n\n", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_reg(hkey, "Wine", REG_DWORD, &dword, sizeof(dword), 0);

    test_import_str("REGEDIT4\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "@=\"Test string\"\n\n", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_reg(hkey, NULL, REG_SZ, "Test string", 12, 0);

950 951 952
    test_import_str("REGEDIT3\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test1\"=\"Value\"\n", &r);
953
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
954
    verify_reg_nonexist(hkey, "Test1");
955 956 957 958 959 960

    test_import_str("regedit4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test2\"=\"Value\"\n", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);
961
    verify_reg_nonexist(hkey, "Test2");
962 963 964 965 966 967

    test_import_str("Regedit4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test3\"=\"Value\"\n", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);
968
    verify_reg_nonexist(hkey, "Test3");
969 970 971 972

    test_import_str("REGEDIT 4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test4\"=\"Value\"\n", &r);
973
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
974
    verify_reg_nonexist(hkey, "Test4");
975 976 977 978

    test_import_str("REGEDIT4FOO\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test5\"=\"Value\"\n", &r);
979
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
980
    verify_reg_nonexist(hkey, "Test5");
981 982 983 984

    test_import_str("REGEDIT4 FOO\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test6\"=\"Value\"\n", &r);
985
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
986
    verify_reg_nonexist(hkey, "Test6");
987 988 989 990

    test_import_str("REGEDIT5\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test7\"=\"Value\"\n", &r);
991
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
992
    verify_reg_nonexist(hkey, "Test7");
993 994 995 996

    test_import_str("REGEDIT9\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test8\"=\"Value\"\n", &r);
997
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
998
    verify_reg_nonexist(hkey, "Test8");
999 1000 1001 1002 1003 1004

    test_import_str("Windows Registry Editor Version 4.00\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test9\"=\"Value\"\n", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);
1005
    verify_reg_nonexist(hkey, "Test9");
1006 1007 1008 1009 1010 1011

    test_import_str("Windows Registry Editor Version 5\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test10\"=\"Value\"\n", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);
1012
    verify_reg_nonexist(hkey, "Test10");
1013 1014 1015 1016 1017 1018

    test_import_str("WINDOWS REGISTRY EDITOR VERSION 5.00\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test11\"=\"Value\"\n", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);
1019
    verify_reg_nonexist(hkey, "Test11");
1020 1021 1022 1023 1024 1025

    test_import_str("Windows Registry Editor version 5.00\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test12\"=\"Value\"\n", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);
1026
    verify_reg_nonexist(hkey, "Test12");
1027

1028 1029 1030
    test_import_str("REGEDIT4\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test1\"=\"Value1\"\n", &r);
1031
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1032
    verify_reg(hkey, "Test1", REG_SZ, "Value1", 7, 0);
1033 1034 1035 1036

    test_import_str("REGEDIT4\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test2\"=\"Value2\"\n\n", &r);
1037
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1038
    verify_reg(hkey, "Test2", REG_SZ, "Value2", 7, 0);
1039 1040 1041 1042

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test3\"=\"Value3\"\n\n", &r);
1043
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1044
    verify_reg(hkey, "Test3", REG_SZ, "Value3", 7, 0);
1045

1046 1047 1048 1049 1050
    test_import_str("Windows Registry Editor Version 4.00\n", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);

    test_import_str("Windows Registry Editor Version 5.00\n", &r);
1051
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1052

1053 1054 1055
    test_import_str("Windows Registry Editor Version 5.00\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test4\"=\"Value4\"\n", &r);
1056
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1057
    verify_reg(hkey, "Test4", REG_SZ, "Value4", 7, 0);
1058 1059 1060 1061

    test_import_str("Windows Registry Editor Version 5.00\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test5\"=\"Value5\"\n\n", &r);
1062
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1063
    verify_reg(hkey, "Test5", REG_SZ, "Value5", 7, 0);
1064 1065 1066 1067

    test_import_str("Windows Registry Editor Version 5.00\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test6\"=\"Value6\"\n\n", &r);
1068
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1069
    verify_reg(hkey, "Test6", REG_SZ, "Value6", 7, 0);
1070

1071 1072 1073 1074 1075 1076
    test_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", &r);
1077
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1078 1079 1080 1081
    verify_reg(hkey, "Line1", REG_SZ, "Value1", 7, 0);
    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);
1082 1083 1084 1085 1086

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine1\"=dword:00000782\n\n"
                    "\"Wine2\"=\"Test Value\"\n"
1087 1088
                    "\"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"
1089 1090 1091 1092
                    "#comment\n"
                    "@=\"Test\"\n"
                    ";comment\n\n"
                    "\"Wine4\"=dword:12345678\n\n", &r);
1093
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1094
    dword = 0x782;
1095
    verify_reg(hkey, "Wine1", REG_DWORD, &dword, sizeof(dword), 0);
1096
    verify_reg(hkey, "Wine2", REG_SZ, "Test Value", 11, 0);
1097
    verify_reg(hkey, "Wine3", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
1098
    verify_reg(hkey, "", REG_SZ, "Test", 5, 0);
1099
    dword = 0x12345678;
1100
    verify_reg(hkey, "Wine4", REG_DWORD, &dword, sizeof(dword), 0);
1101

1102 1103 1104
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine5\"=\"No newline\"", &r);
1105
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1106
    err = RegQueryValueExA(hkey, "Wine5", NULL, NULL, NULL, NULL);
1107
    ok(err == ERROR_SUCCESS || broken(err == ERROR_FILE_NOT_FOUND /* WinXP */),
1108 1109 1110 1111 1112 1113 1114 1115
       "got %d, expected 0\n", err);
    if (err == ERROR_SUCCESS)
        verify_reg(hkey, "Wine5", REG_SZ, "No newline", 11, 0);

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine6\"=dword:00000050\n\n"
                    "\"Wine7\"=\"No newline\"", &r);
1116
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1117
    dword = 0x50;
1118
    verify_reg(hkey, "Wine6", REG_DWORD, &dword, sizeof(dword), 0);
1119
    err = RegQueryValueExA(hkey, "Wine7", NULL, NULL, NULL, NULL);
1120
    ok(err == ERROR_SUCCESS || broken(err == ERROR_FILE_NOT_FOUND /* WinXP */),
1121 1122 1123 1124
       "got %d, expected 0\n", err);
    if (err == ERROR_SUCCESS)
        verify_reg(hkey, "Wine7", REG_SZ, "No newline", 11, 0);

1125 1126 1127 1128 1129 1130
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "#comment\\\n"
                    "\"Wine8\"=\"Line 1\"\n"
                    ";comment\\\n"
                    "\"Wine9\"=\"Line 2\"\n\n", &r);
1131
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1132 1133
    verify_reg(hkey, "Wine8", REG_SZ, "Line 1", 7, 0);
    verify_reg(hkey, "Wine9", REG_SZ, "Line 2", 7, 0);
1134

1135 1136 1137 1138 1139 1140
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine10\"=\"Value 1\"#comment\n"
                    "\"Wine11\"=\"Value 2\";comment\n"
                    "\"Wine12\"=dword:01020304 #comment\n"
                    "\"Wine13\"=dword:02040608 ;comment\n\n", &r);
1141
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1142
    verify_reg_nonexist(hkey, "Wine10");
1143
    verify_reg(hkey, "Wine11", REG_SZ, "Value 2", 8, 0);
1144
    verify_reg_nonexist(hkey, "Wine12");
1145
    dword = 0x2040608;
1146
    verify_reg(hkey, "Wine13", REG_DWORD, &dword, sizeof(dword), 0);
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine14\"=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"
                    "\"Wine15\"=\"A valid line\"\n"
                    "\"Wine16\"=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"
                    "\"Wine17\"=\"Another valid line\"\n\n", &r);
1158
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1159
    verify_reg_nonexist(hkey, "Wine14");
1160
    verify_reg(hkey, "Wine15", REG_SZ, "A valid line", 13, 0);
1161
    verify_reg(hkey, "Wine16", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
1162
    verify_reg(hkey, "Wine17", REG_SZ, "Another valid line", 19, 0);
1163 1164 1165 1166 1167 1168 1169 1170 1171

    test_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"
                    "\"Wine18\"=\"Value 6\"#\"Comment5\"=\"Value 5\"\n"
                    "\"Wine19\"=\"Value 7\";\"Comment6\"=\"Value 6\"\n\n", &r);
1172
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1173 1174 1175 1176 1177 1178
    verify_reg_nonexist(hkey, "Comment1");
    verify_reg_nonexist(hkey, "Comment2");
    verify_reg_nonexist(hkey, "Comment3");
    verify_reg_nonexist(hkey, "Comment4");
    verify_reg_nonexist(hkey, "Wine18");
    verify_reg_nonexist(hkey, "Comment5");
1179
    verify_reg(hkey, "Wine19", REG_SZ, "Value 7", 8, 0);
1180
    verify_reg_nonexist(hkey, "Comment6");
1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine20\"=#\"Value 8\"\n"
                    "\"Wine21\"=;\"Value 9\"\n"
                    "\"Wine22\"=\"#comment1\"\n"
                    "\"Wine23\"=\";comment2\"\n"
                    "\"Wine24\"=\"Value#comment3\"\n"
                    "\"Wine25\"=\"Value;comment4\"\n"
                    "\"Wine26\"=\"Value #comment5\"\n"
                    "\"Wine27\"=\"Value ;comment6\"\n"
                    "\"Wine28\"=#dword:00000001\n"
                    "\"Wine29\"=;dword:00000002\n"
                    "\"Wine30\"=dword:00000003#comment\n"
                    "\"Wine31\"=dword:00000004;comment\n\n", &r);
1196
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1197 1198
    verify_reg_nonexist(hkey, "Wine20");
    verify_reg_nonexist(hkey, "Wine21");
1199 1200 1201 1202 1203 1204
    verify_reg(hkey, "Wine22", REG_SZ, "#comment1", 10, 0);
    verify_reg(hkey, "Wine23", REG_SZ, ";comment2", 10, 0);
    verify_reg(hkey, "Wine24", REG_SZ, "Value#comment3", 15, 0);
    verify_reg(hkey, "Wine25", REG_SZ, "Value;comment4", 15, 0);
    verify_reg(hkey, "Wine26", REG_SZ, "Value #comment5", 16, 0);
    verify_reg(hkey, "Wine27", REG_SZ, "Value ;comment6", 16, 0);
1205 1206 1207
    verify_reg_nonexist(hkey, "Wine28");
    verify_reg_nonexist(hkey, "Wine29");
    verify_reg_nonexist(hkey, "Wine30");
1208
    dword = 0x00000004;
1209
    verify_reg(hkey, "Wine31", REG_DWORD, &dword, sizeof(dword), 0);
1210

1211 1212 1213 1214 1215 1216
    test_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", &r);
1217
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1218
    verify_reg(hkey, "Multi-Line1", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
1219 1220 1221 1222 1223 1224 1225

    test_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", &r);
1226
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1227
    verify_reg(hkey, "Multi-Line2", REG_MULTI_SZ, "Line concat", 12, 0);
1228

1229 1230 1231 1232
    test_import_str("REGEDIT4\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", &r);
1233
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1234
    verify_reg_nonexist(hkey, "Multi-Line3");
1235 1236 1237 1238 1239

    test_import_str("REGEDIT4\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", &r);
1240
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1241
    verify_reg_nonexist(hkey, "Multi-Line4");
1242 1243 1244 1245 1246

    test_import_str("Windows Registry Editor Version 5.00\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Multi-Line5\"=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", &r);
1247
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1248
    verify_reg_nonexist(hkey, "Multi-Line5");
1249 1250 1251 1252 1253

    test_import_str("Windows Registry Editor Version 5.00\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Multi-Line6\"=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", &r);
1254
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1255
    verify_reg_nonexist(hkey, "Multi-Line6");
1256

1257 1258 1259 1260 1261 1262 1263
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Multi-Line7\"=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", &r);
1264
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1265
    verify_reg(hkey, "Multi-Line7", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
1266 1267 1268 1269 1270 1271 1272 1273

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Multi-Line8\"=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", &r);
1274
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1275
    verify_reg(hkey, "Multi-Line8", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
1276 1277 1278 1279 1280 1281 1282 1283

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Multi-Line9\"=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", &r);
1284
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1285
    verify_reg_nonexist(hkey, "Multi-Line9");
1286

1287 1288 1289 1290 1291 1292 1293
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Multi-Line10\"=hex(7):4c,69,6e,65,20,\\\n"
                    "  63,6f,6e,\\;comment\n"
                    "  63,61,74,\\\n\n"
                    "  65,6e,\\;comment\n\n"
                    "  61,74,69,6f,6e,00,00\n\n", &r);
1294
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1295
    verify_reg(hkey, "Multi-Line10", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
1296

1297 1298 1299 1300
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine32a\"=dword:1\n"
                    "\"Wine32b\"=dword:4444\n\n", &r);
1301
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1302
    dword = 0x1;
1303
    verify_reg(hkey, "Wine32a", REG_DWORD, &dword, sizeof(dword), 0);
1304
    dword = 0x4444;
1305
    verify_reg(hkey, "Wine32b", REG_DWORD, &dword, sizeof(dword), 0);
1306 1307 1308 1309 1310 1311

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine33a\"=dword:\n"
                    "\"Wine33b\"=dword:hello\n"
                    "\"Wine33c\"=dword:123456789\n"
1312 1313
                    "\"Wine33d\"=dword:012345678\n"
                    "\"Wine33e\"=dword:000000001\n\n", &r);
1314
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1315 1316 1317 1318 1319
    verify_reg_nonexist(hkey, "Wine33a");
    verify_reg_nonexist(hkey, "Wine33b");
    verify_reg_nonexist(hkey, "Wine33c");
    verify_reg_nonexist(hkey, "Wine33d");
    verify_reg_nonexist(hkey, "Wine33e");
1320 1321 1322 1323 1324

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine34a\"=dword:12345678abc\n"
                    "\"Wine34b\"=dword:12345678 abc\n\n", &r);
1325
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1326 1327
    verify_reg_nonexist(hkey, "Wine34a");
    verify_reg_nonexist(hkey, "Wine34b");
1328 1329 1330 1331 1332 1333

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine35a\"=dword:0x123\n"
                    "\"Wine35b\"=dword:123 456\n"
                    "\"Wine35c\"=dword:1234 5678\n\n", &r);
1334
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1335 1336 1337
    verify_reg_nonexist(hkey, "Wine35a");
    verify_reg_nonexist(hkey, "Wine35b");
    verify_reg_nonexist(hkey, "Wine35c");
1338 1339 1340 1341 1342 1343 1344

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine36a\"=dword:1234;5678\n"
                    "\"Wine36b\"=dword:1234 ;5678\n"
                    "\"Wine36c\"=dword:1234#5678\n"
                    "\"Wine36d\"=dword:1234 #5678\n\n", &r);
1345
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1346
    dword = 0x1234;
1347 1348
    verify_reg(hkey, "Wine36a", REG_DWORD, &dword, sizeof(dword), 0);
    verify_reg(hkey, "Wine36b", REG_DWORD, &dword, sizeof(dword), 0);
1349 1350
    verify_reg_nonexist(hkey, "Wine36c");
    verify_reg_nonexist(hkey, "Wine36d");
1351

1352 1353 1354 1355
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine37a\"=\"foo\"bar\"\n"
                    "\"Wine37b\"=\"foo\"\"bar\"\n\n", &r);
1356
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1357 1358
    verify_reg_nonexist(hkey, "Wine37a");
    verify_reg_nonexist(hkey, "Wine37b");
1359

1360 1361
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
1362 1363
                    "\"Empty string\"=\"\"\n"
                    "\"\"=\"Default Value Name\"\n\n", &r);
1364
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1365 1366
    verify_reg(hkey, "Empty string", REG_SZ, "", 1, 0);
    verify_reg(hkey, NULL, REG_SZ, "Default Value Name", 19, 0);
1367 1368 1369 1370 1371 1372 1373

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Test38a\"=\n"
                    "\"Test38b\"=\\\"\n"
                    "\"Test38c\"=\\\"Value\\\"\n"
                    "\"Test38d\"=\\\"Value\"\n\n", &r);
1374
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1375 1376 1377 1378
    verify_reg_nonexist(hkey, "Test38a");
    verify_reg_nonexist(hkey, "Test38b");
    verify_reg_nonexist(hkey, "Test38c");
    verify_reg_nonexist(hkey, "Test38d");
1379 1380 1381 1382 1383 1384 1385

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine39a\"=\"Value1\"  ;comment\n"
                    "\"Wine39b\"=\"Value2\"\t\t;comment\n"
                    "\"Wine39c\"=\"Value3\"  #comment\n"
                    "\"Wine39d\"=\"Value4\"\t\t#comment\n\n", &r);
1386
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1387 1388
    verify_reg(hkey, "Wine39a", REG_SZ, "Value1", 7, 0);
    verify_reg(hkey, "Wine39b", REG_SZ, "Value2", 7, 0);
1389 1390
    verify_reg_nonexist(hkey, "Wine39c");
    verify_reg_nonexist(hkey, "Wine39d");
1391

1392 1393 1394
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"TestNoBeginQuote\"=Asdffdsa\"\n", &r);
1395
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1396
    verify_reg_nonexist(hkey, "TestNoBeginQuote");
1397 1398 1399 1400

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"TestNoEndQuote\"=\"Asdffdsa\n", &r);
1401
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1402
    verify_reg_nonexist(hkey, "TestNoEndQuote");
1403 1404 1405 1406

    test_import_str("REGEDIT4\n\n"
                   "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                   "\"TestNoQuotes\"=Asdffdsa\n", &r);
1407
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1408
    verify_reg_nonexist(hkey, "TestNoQuotes");
1409 1410 1411 1412

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "NameNoBeginQuote\"=\"Asdffdsa\"\n", &r);
1413
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1414
    verify_reg_nonexist(hkey, "NameNoBeginQuote");
1415 1416 1417 1418

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"NameNoEndQuote=\"Asdffdsa\"\n", &r);
1419
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1420
    verify_reg_nonexist(hkey, "NameNoEndQuote");
1421 1422 1423 1424

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "NameNoQuotes=\"Asdffdsa\"\n", &r);
1425
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1426
    verify_reg_nonexist(hkey, "NameNoQuotes");
1427 1428 1429 1430

    test_import_str("REGEDIT4\n\n"
                "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                "\"MixedQuotes=Asdffdsa\"\n", &r);
1431
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1432 1433
    verify_reg_nonexist(hkey, "MixedQuotes");
    verify_reg_nonexist(hkey, "MixedQuotes=Asdffdsa");
1434

1435 1436 1437 1438 1439 1440 1441 1442 1443
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine40a\"=hex(2):4c,69,6e,65,00\n"
                    "\"Wine40b\"=\"Value 1\"\n"
                    "\"Wine40c\"=hex(2):4c,69,6e,65\\\n"
                    "\"Wine40d\"=\"Value 2\"\n"
                    "\"Wine40e\"=hex(2):4c,69,6e,65,\\\n"
                    "\"Wine40f\"=\"Value 3\"\n"
                    "\"Wine40g\"=\"Value 4\"\n\n", &r);
1444
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1445
    verify_reg(hkey, "Wine40a", REG_EXPAND_SZ, "Line", 5, 0);
1446
    verify_reg(hkey, "Wine40b", REG_SZ, "Value 1", 8, 0);
1447
    verify_reg_nonexist(hkey, "Wine40c");
1448
    verify_reg(hkey, "Wine40d", REG_SZ, "Value 2", 8, 0);
1449
    verify_reg_nonexist(hkey, "Wine40e");
1450
    verify_reg_nonexist(hkey, "Wine40f");
1451
    verify_reg(hkey, "Wine40g", REG_SZ, "Value 4", 8, 0);
1452

1453 1454 1455 1456 1457 1458
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine41a\"=dword:1234\\\n"
                    "5678\n"
                    "\"Wine41b\"=\"Test \\\n"
                    "Value\"\n\n", &r);
1459
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1460 1461
    verify_reg_nonexist(hkey, "Wine41a");
    verify_reg_nonexist(hkey, "Wine41b");
1462

1463 1464 1465 1466
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"double\\\"quote\"=\"valid \\\"or\\\" not\"\n"
                    "\"single'quote\"=dword:00000008\n\n", &r);
1467
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1468
    verify_reg(hkey, "double\"quote", REG_SZ, "valid \"or\" not", 15, 0);
1469
    dword = 0x00000008;
1470
    verify_reg(hkey, "single'quote", REG_DWORD, &dword, sizeof(dword), 0);
1471

1472 1473 1474 1475
    /* Test key name and value name concatenation */
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "\\\n"
                    "Subkey1]\n", &r);
1476
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1477
    verify_key_nonexist(hkey, "Subkey1");
1478 1479 1480 1481

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "\n"
                    "\\Subkey2]\n", &r);
1482
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1483
    verify_key_nonexist(hkey, "Subkey2");
1484 1485 1486 1487 1488 1489 1490 1491

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine\\\n"
                    "42a\"=\"Value 1\"\n"
                    "\"Wine42b\"=\"Value 2\"\n"
                    "\"Wine\n"
                    "\\42c\"=\"Value 3\"\n\n", &r);
1492
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1493
    verify_reg_nonexist(hkey, "Wine42a");
1494
    verify_reg(hkey, "Wine42b", REG_SZ, "Value 2", 8, 0);
1495
    verify_reg_nonexist(hkey, "Wine42c");
1496

1497
    /* Test hex data concatenation for REG_NONE, REG_EXPAND_SZ and REG_BINARY */
1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine43a\"=hex(0):56,00,61,00,6c,00,75,00,65,00,00,00\n"
                    "\"Wine43b\"=hex(0):56,00,61,00,6c,00,\\\n"
                    "  75,00,65,00,00,00\n"
                    "\"Wine43c\"=hex(0):56,00,61,00,6c,00\\\n"
                    ",75,00,65,00,00,00\n"
                    "\"Wine43d\"=hex(0):56,00,61,00,6c,00\\\n"
                    "  ,75,00,65,00,00,00\n"
                    "\"Wine43e\"=hex(0):56,00,61,00,6c,00\\\n"
                    "  75,00,65,00,00,00\n"
                    "\"Wine43f\"=hex(0):56,00,61,00,6c,00,7\\\n"
                    "5,00,65,00,00,00\n"
                    "\"Wine43g\"=hex(0):56,00,61,00,6c,00,7\\\n"
1512
                    "  5,00,65,00,00,00\n"
1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524
                    "\"Wine43h\"=hex(0):56,00,61,00,\\;comment\n"
                    "  6c,00,75,00,\\\n"
                    "  65,00,00,00\n"
                    "\"Wine43i\"=hex(0):56,00,61,00,\\;comment\n"
                    "  6c,00,75,00,\n"
                    "  65,00,00,00\n"
                    "\"Wine43j\"=hex(0):56,00,61,00,\\;comment\n"
                    "  6c,00,75,00,;comment\n"
                    "  65,00,00,00\n"
                    "\"Wine43k\"=hex(0):56,00,61,00,\\;comment\n"
                    "  6c,00,75,00,\\#comment\n"
                    "  65,00,00,00\n\n", &r);
1525
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1526 1527
    verify_reg(hkey, "Wine43a", REG_NONE, "V\0a\0l\0u\0e\0\0", 12, 0);
    verify_reg(hkey, "Wine43b", REG_NONE, "V\0a\0l\0u\0e\0\0", 12, 0);
1528 1529 1530 1531 1532
    verify_reg_nonexist(hkey, "Wine43c");
    verify_reg_nonexist(hkey, "Wine43d");
    verify_reg_nonexist(hkey, "Wine43e");
    verify_reg_nonexist(hkey, "Wine43f");
    verify_reg_nonexist(hkey, "Wine43g");
1533 1534 1535
    verify_reg(hkey, "Wine43h", REG_NONE, "V\0a\0l\0u\0e\0\0", 12, 0);
    verify_reg(hkey, "Wine43i", REG_NONE, "V\0a\0l\0u", 8, 0);
    verify_reg(hkey, "Wine43j", REG_NONE, "V\0a\0l\0u", 8, 0);
1536
    verify_reg_nonexist(hkey, "Wine43k");
1537

1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine44a\"=hex(2):25,50,41,54,48,25,00\n"
                    "\"Wine44b\"=hex(2):25,50,41,\\\n"
                    "  54,48,25,00\n"
                    "\"Wine44c\"=hex(2):25,50,41\\\n"
                    ",54,48,25,00\n"
                    "\"Wine44d\"=hex(2):25,50,41\\\n"
                    "  ,54,48,25,00\n"
                    "\"Wine44e\"=hex(2):25,50,41\\\n"
                    "  54,48,25,00\n"
                    "\"Wine44f\"=hex(2):25,50,4\\\n"
                    "1,54,48,25,00\n"
                    "\"Wine44g\"=hex(2):25,50,4\\\n"
                    "  1,54,48,25,00\n"
                    "\"Wine44h\"=hex(2):25,50,41,\\;comment\n"
                    "  54,48,\\\n"
                    "  25,00\n"
                    "\"Wine44i\"=hex(2):25,50,41,\\;comment\n"
                    "  54,48,\n"
                    "  25,00\n"
                    "\"Wine44j\"=hex(2):25,50,41,\\;comment\n"
                    "  54,48,;comment\n"
                    "  25,00\n"
                    "\"Wine44k\"=hex(2):25,50,41,\\;comment\n"
                    "  54,48,\\#comment\n"
                    "  25,00\n\n", &r);
1565
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1566 1567
    verify_reg(hkey, "Wine44a", REG_EXPAND_SZ, "%PATH%", 7, 0);
    verify_reg(hkey, "Wine44b", REG_EXPAND_SZ, "%PATH%", 7, 0);
1568 1569 1570 1571 1572
    verify_reg_nonexist(hkey, "Wine44c");
    verify_reg_nonexist(hkey, "Wine44d");
    verify_reg_nonexist(hkey, "Wine44e");
    verify_reg_nonexist(hkey, "Wine44f");
    verify_reg_nonexist(hkey, "Wine44g");
1573
    verify_reg(hkey, "Wine44h", REG_EXPAND_SZ, "%PATH%", 7, 0);
1574 1575 1576
    /* Wine44i */
    size = sizeof(buffer);
    err = RegQueryValueExA(hkey, "Wine44i", NULL, &type, (BYTE *)&buffer, &size);
1577 1578 1579 1580
    ok(err == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", err);
    ok(type == REG_EXPAND_SZ, "got wrong type %u, expected %u\n", type, REG_EXPAND_SZ);
    ok(size == 6 || broken(size == 5) /* WinXP */, "got wrong size %u, expected 6\n", size);
    ok(memcmp(buffer, "%PATH", size) == 0, "got wrong data\n");
1581 1582 1583 1584
    /* Wine44j */
    size = sizeof(buffer);
    memset(buffer, '-', size);
    err = RegQueryValueExA(hkey, "Wine44j", NULL, &type, (BYTE *)&buffer, &size);
1585 1586 1587 1588
    ok(err == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", err);
    ok(type == REG_EXPAND_SZ, "got wrong type %u, expected %u\n", type, REG_EXPAND_SZ);
    ok(size == 6 || broken(size == 5) /* WinXP */, "got wrong size %u, expected 6\n", size);
    ok(memcmp(buffer, "%PATH", size) == 0, "got wrong data\n");
1589
    /* Wine44k */
1590
    verify_reg_nonexist(hkey, "Wine44k");
1591

1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine45a\"=hex:11,22,33,44,55,66,77,88\n"
                    "\"Wine45b\"=hex:11,22,33,44,\\\n"
                    "  55,66,77,88\n"
                    "\"Wine45c\"=hex:11,22,33,44\\\n"
                    ",55,66,77,88\n"
                    "\"Wine45d\"=hex:11,22,33,44\\\n"
                    "  ,55,66,77,88\n"
                    "\"Wine45e\"=hex:11,22,33,44\\\n"
                    "  55,66,77,88\n"
                    "\"Wine45f\"=hex:11,22,33,4\\\n"
                    "4,55,66,77,88\n"
                    "\"Wine45g\"=hex:11,22,33,4\\\n"
                    "  4,55,66,77,88\n"
                    "\"Wine45h\"=hex:11,22,33,44,\\;comment\n"
                    "  55,66,\\\n"
                    "  77,88\n"
                    "\"Wine45i\"=hex:11,22,33,44,\\;comment\n"
                    "  55,66,\n"
                    "  77,88\n"
                    "\"Wine45j\"=hex:11,22,33,44,\\;comment\n"
                    "  55,66,;comment\n"
                    "  77,88\n"
                    "\"Wine45k\"=hex:11,22,33,\\;comment\n"
                    "  44,55,66,\\#comment\n"
                    "  77,88\n\n", &r);
1619
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1620 1621
    hex[0] = 0x11; hex[1] = 0x22; hex[2] = 0x33; hex[3] = 0x44;
    hex[4] = 0x55; hex[5] = 0x66; hex[6] = 0x77; hex[7] = 0x88;
1622 1623
    verify_reg(hkey, "Wine45a", REG_BINARY, hex, sizeof(hex), 0);
    verify_reg(hkey, "Wine45b", REG_BINARY, hex, sizeof(hex), 0);
1624 1625 1626 1627 1628
    verify_reg_nonexist(hkey, "Wine45c");
    verify_reg_nonexist(hkey, "Wine45d");
    verify_reg_nonexist(hkey, "Wine45e");
    verify_reg_nonexist(hkey, "Wine45f");
    verify_reg_nonexist(hkey, "Wine45g");
1629 1630 1631
    verify_reg(hkey, "Wine45h", REG_BINARY, hex, sizeof(hex), 0);
    verify_reg(hkey, "Wine45i", REG_BINARY, hex, 6, 0);
    verify_reg(hkey, "Wine45j", REG_BINARY, hex, 6, 0);
1632
    verify_reg_nonexist(hkey, "Wine45k");
1633

1634
    /* Test import with subkeys */
1635 1636 1637
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey\"1]\n"
                    "\"Wine\\\\31\"=\"Test value\"\n\n", &r);
1638
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1639
    open_key(hkey, "Subkey\"1", 0, &subkey);
1640
    verify_reg(subkey, "Wine\\31", REG_SZ, "Test value", 11, 0);
1641
    err = RegCloseKey(subkey);
1642
    ok(err == ERROR_SUCCESS, "got %d, expected 0\n", err);
1643
    delete_key(HKEY_CURRENT_USER, KEY_BASE "\\Subkey\"1");
1644 1645 1646 1647

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey/2]\n"
                    "\"123/\\\"4;'5\"=\"Random value name\"\n\n", &r);
1648
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1649
    open_key(hkey, "Subkey/2", 0, &subkey);
1650
    verify_reg(subkey, "123/\"4;'5", REG_SZ, "Random value name", 18, 0);
1651
    err = RegCloseKey(subkey);
1652
    ok(err == ERROR_SUCCESS, "got %d, expected 0\n", err);
1653
    delete_key(HKEY_CURRENT_USER, KEY_BASE "\\Subkey/2");
1654

1655 1656 1657
    /* Test key creation */
    test_import_str("REGEDIT4\n\n"
                    "HKEY_CURRENT_USER\\" KEY_BASE "\\No_Opening_Bracket]\n", &r);
1658
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1659
    verify_key_nonexist(hkey, "No_Opening_Bracket");
1660 1661 1662

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "\\No_Closing_Bracket\n", &r);
1663
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1664
    verify_key_nonexist(hkey, "No_Closing_Bracket");
1665 1666 1667

    test_import_str("REGEDIT4\n\n"
                    "[ HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1a]\n", &r);
1668
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1669
    verify_key_nonexist(hkey, "Subkey1a");
1670 1671 1672

    test_import_str("REGEDIT4\n\n"
                    "[\tHKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1b]\n", &r);
1673
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1674
    verify_key_nonexist(hkey, "Subkey1b");
1675 1676 1677

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1c ]\n", &r);
1678
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1679
    verify_key(hkey, "Subkey1c ");
1680
    delete_key(hkey, "Subkey1c ");
1681 1682 1683

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1d\t]\n", &r);
1684
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1685
    verify_key(hkey, "Subkey1d\t");
1686
    delete_key(hkey, "Subkey1d\t");
1687

1688 1689 1690
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1e\\]\n"
                    "\"Wine\"=\"Test value\"\n\n", &r);
1691
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1692 1693
    verify_key(hkey, "Subkey1e\\");
    verify_key(hkey, "Subkey1e");
1694
    open_key(hkey, "Subkey1e", 0, &subkey);
1695
    verify_reg(subkey, "Wine", REG_SZ, "Test value", 11, 0);
1696
    RegCloseKey(subkey);
1697
    delete_key(hkey, "Subkey1e");
1698 1699 1700 1701

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1f\\\\]\n"
                    "\"Wine\"=\"Test value\"\n\n", &r);
1702
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1703 1704 1705
    verify_key(hkey, "Subkey1f\\\\");
    verify_key(hkey, "Subkey1f\\");
    verify_key(hkey, "Subkey1f");
1706
    open_key(hkey, "Subkey1f\\\\", 0, &subkey);
1707
    verify_reg(subkey, "Wine", REG_SZ, "Test value", 11, 0);
1708
    RegCloseKey(subkey);
1709
    delete_key(hkey, "Subkey1f\\\\");
1710 1711 1712 1713

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1g\\\\\\\\]\n"
                    "\"Wine\"=\"Test value\"\n\n", &r);
1714
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1715 1716 1717 1718
    verify_key(hkey, "Subkey1g\\\\\\\\");
    verify_key(hkey, "Subkey1g\\\\");
    verify_key(hkey, "Subkey1g\\");
    verify_key(hkey, "Subkey1g");
1719
    open_key(hkey, "Subkey1g\\\\", 0, &subkey);
1720
    verify_reg(subkey, "Wine", REG_SZ, "Test value", 11, 0);
1721
    RegCloseKey(subkey);
1722
    delete_key(hkey, "Subkey1g\\\\");
1723

1724 1725 1726 1727
    /* Test key deletion. We start by creating some registry keys. */
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a]\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2b]\n\n", &r);
1728
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1729 1730
    verify_key(hkey, "Subkey2a");
    verify_key(hkey, "Subkey2b");
1731 1732 1733

    test_import_str("REGEDIT4\n\n"
                    "[ -HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a]\n", &r);
1734
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1735
    verify_key(hkey, "Subkey2a");
1736 1737 1738

    test_import_str("REGEDIT4\n\n"
                    "[\t-HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2b]\n", &r);
1739
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1740
    verify_key(hkey, "Subkey2b");
1741 1742 1743

    test_import_str("REGEDIT4\n\n"
                    "[- HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a]\n", &r);
1744
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1745
    verify_key(hkey, "Subkey2a");
1746 1747

    test_import_str("REGEDIT4\n\n"
1748
                    "[-\tHKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2b]\n", &r);
1749
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1750
    verify_key(hkey, "Subkey2b");
1751 1752 1753 1754

    test_import_str("REGEDIT4\n\n"
                    "[-HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a]\n\n"
                    "[-HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2b]\n\n", &r);
1755
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1756 1757
    verify_key_nonexist(hkey, "Subkey2a");
    verify_key_nonexist(hkey, "Subkey2b");
1758

1759 1760 1761 1762
    /* Test case sensitivity when creating and deleting registry keys. */
    test_import_str("REGEDIT4\n\n"
                    "[hkey_CURRENT_user\\" KEY_BASE "\\Subkey3a]\n\n"
                    "[HkEy_CuRrEnT_uSeR\\" KEY_BASE "\\SuBkEy3b]\n\n", &r);
1763
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1764 1765
    verify_key(hkey, "Subkey3a");
    verify_key(hkey, "Subkey3b");
1766 1767 1768 1769

    test_import_str("REGEDIT4\n\n"
                    "[-HKEY_current_USER\\" KEY_BASE "\\sUBKEY3A]\n\n"
                    "[-hKeY_cUrReNt_UsEr\\" KEY_BASE "\\sUbKeY3B]\n\n", &r);
1770
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1771 1772
    verify_key_nonexist(hkey, "Subkey3a");
    verify_key_nonexist(hkey, "Subkey3b");
1773

1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785
    /* Test mixed key creation and deletion. We start by creating a subkey. */
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey4a]\n\n", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_key(hkey, "Subkey4a");

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n\n"
                    "[-HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey4a]\n"
                    "\"Wine46a\"=dword:12345678\n\n", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_key_nonexist(hkey, "Subkey4a");
1786
    verify_reg_nonexist(hkey, "Wine46a");
1787 1788 1789 1790 1791 1792 1793 1794 1795

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n\n"
                    "[HKEY_CURRENT_USERS\\" KEY_BASE "\\Subkey4b]\n"
                    "\"Wine46b\"=dword:12345678\n\n", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_key_nonexist(hkey, "Subkey4b");
    verify_reg_nonexist(hkey, "Wine46b");

1796 1797 1798 1799 1800 1801 1802 1803 1804 1805
    /* Test value deletion. We start by creating some registry values. */
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine46a\"=\"Test Value\"\n"
                    "\"Wine46b\"=dword:00000008\n"
                    "\"Wine46c\"=hex:11,22,33,44\n"
                    "\"Wine46d\"=hex(7):4c,69,6e,65,20,\\\n"
                    "  63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n"
                    "\"Wine46e\"=hex(2):25,50,41,54,48,25,00\n"
                    "\"Wine46f\"=hex(0):56,00,61,00,6c,00,75,00,65,00,00,00\n\n", &r);
1806
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1807
    verify_reg(hkey, "Wine46a", REG_SZ, "Test Value", 11, 0);
1808
    verify_reg(hkey, "Wine46b", REG_DWORD, &dword, sizeof(dword), 0);
1809 1810 1811 1812
    verify_reg(hkey, "Wine46c", REG_BINARY, hex, 4, 0);
    verify_reg(hkey, "Wine46d", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
    verify_reg(hkey, "Wine46e", REG_EXPAND_SZ, "%PATH%", 7, 0);
    verify_reg(hkey, "Wine46f", REG_NONE, "V\0a\0l\0u\0e\0\0", 12, 0);
1813 1814 1815 1816 1817 1818 1819 1820 1821

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine46a\"=-\n"
                    "\"Wine46b\"=  -\n"
                    "\"Wine46c\"=  \t-\t  \n"
                    "\"Wine46d\"=-\"Test\"\n"
                    "\"Wine46e\"=- ;comment\n"
                    "\"Wine46f\"=- #comment\n\n", &r);
1822
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1823 1824 1825
    verify_reg_nonexist(hkey, "Wine46a");
    verify_reg_nonexist(hkey, "Wine46b");
    verify_reg_nonexist(hkey, "Wine46c");
1826
    verify_reg(hkey, "Wine46d", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
1827
    verify_reg_nonexist(hkey, "Wine46e");
1828
    verify_reg(hkey, "Wine46f", REG_NONE, "V\0a\0l\0u\0e\0\0", 12, 0);
1829

1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840
    /* Test the accepted range of the hex-based data types */
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine47a\"=hex(0):56,61,6c,75,65,00\n"
                    "\"Wine47b\"=hex(10):56,61,6c,75,65,00\n"
                    "\"Wine47c\"=hex(100):56,61,6c,75,65,00\n"
                    "\"Wine47d\"=hex(1000):56,61,6c,75,65,00\n"
                    "\"Wine47e\"=hex(7fff):56,61,6c,75,65,00\n"
                    "\"Wine47f\"=hex(ffff):56,61,6c,75,65,00\n"
                    "\"Wine47g\"=hex(7fffffff):56,61,6c,75,65,00\n"
                    "\"Wine47h\"=hex(ffffffff):56,61,6c,75,65,00\n"
1841 1842
                    "\"Wine47i\"=hex(100000000):56,61,6c,75,65,00\n"
                    "\"Wine47j\"=hex(0x2):56,61,6c,75,65,00\n"
1843 1844
                    "\"Wine47k\"=hex(0X2):56,61,6c,75,65,00\n"
                    "\"Wine47l\"=hex(x2):56,61,6c,75,65,00\n\n", &r);
1845
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1846 1847 1848 1849 1850 1851 1852 1853
    verify_reg(hkey, "Wine47a", REG_NONE, "Value", 6, 0);
    verify_reg(hkey, "Wine47b", 0x10, "Value", 6, 0);
    verify_reg(hkey, "Wine47c", 0x100, "Value", 6, 0);
    verify_reg(hkey, "Wine47d", 0x1000, "Value", 6, 0);
    verify_reg(hkey, "Wine47e", 0x7fff, "Value", 6, 0);
    verify_reg(hkey, "Wine47f", 0xffff, "Value", 6, 0);
    verify_reg(hkey, "Wine47g", 0x7fffffff, "Value", 6, 0);
    verify_reg(hkey, "Wine47h", 0xffffffff, "Value", 6, 0);
1854 1855 1856 1857
    verify_reg_nonexist(hkey, "Wine47i");
    verify_reg_nonexist(hkey, "Wine47j");
    verify_reg_nonexist(hkey, "Wine47k");
    verify_reg_nonexist(hkey, "Wine47l");
1858

1859 1860 1861 1862 1863 1864
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine48a\"=hex(7):4c,69,6e,65,20,  \\\n"
                    "  63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n"
                    "\"Wine48b\"=hex(7):4c,69,6e,65,20,\t\\\n"
                    "  63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n\n", &r);
1865
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1866 1867
    verify_reg(hkey, "Wine48a", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
    verify_reg(hkey, "Wine48b", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
1868 1869 1870 1871

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine49\"=hex(2):25,50,41,54,48,25,00,\n\n", &r);
1872
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1873
    verify_reg(hkey, "Wine49", REG_EXPAND_SZ, "%PATH%", 7, 0);
1874 1875 1876 1877 1878 1879 1880

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine50a\"=hex(2):25,50,41,54,48,25,00  ;comment\n"
                    "\"Wine50b\"=hex(2):25,50,41,54,48,25,00\t;comment\n"
                    "\"Wine50c\"=hex(2):25,50,41,54,48,25,00  #comment\n"
                    "\"Wine50d\"=hex(2):25,50,41,54,48,25,00\t#comment\n\n", &r);
1881
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1882 1883
    verify_reg(hkey, "Wine50a", REG_EXPAND_SZ, "%PATH%", 7, 0);
    verify_reg(hkey, "Wine50b", REG_EXPAND_SZ, "%PATH%", 7, 0);
1884 1885
    verify_reg_nonexist(hkey, "Wine50c");
    verify_reg_nonexist(hkey, "Wine50d");
1886 1887 1888 1889 1890 1891

    /* Test support for characters greater than 0xff */
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine51a\"=hex(0):25,50,100,54,48,25,00\n"
                    "\"Wine51b\"=hex(0):25,1a4,100,164,124,25,00\n\n", &r);
1892
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1893 1894
    verify_reg_nonexist(hkey, "Wine51a");
    verify_reg_nonexist(hkey, "Wine51b");
1895

1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914
    /* Test the effect of backslashes in hex data */
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine52a\"=hex(2):25,48\\,4f,4d,45,25,00\n"
                    "\"Wine52b\"=hex(2):25,48,\\4f,4d,45,25,00\n"
                    "\"Wine52c\"=hex(2):25,48\\ ,4f,4d,45,25,00\n"
                    "\"Wine52d\"=hex(2):25,48,\\ 4f,4d,45,25,00\n"
                    "\"Wine52e\"=hex(2):\\25,48,4f,4d,45,25,00\n"
                    "\"Wine52f\"=hex(2):\\ 25,48,4f,4d,45,25,00\n"
                    "\"Wine52g\"=hex(2):25,48,4\\f,4d,45,25,00\n"
                    "\"Wine52h\"=hex(2):25,48,4\\\n"
                    "  f,4d,45,25,00\n"
                    "\"Wine52i\"=hex(2):25,50,\\,41,54,48,25,00\n"
                    "\"Wine52j\"=hex(2):25,48,4f,4d,45,25,5c,\\\\\n"
                    "  25,50,41,54,48,25,00\n"
                    "\"Wine52k\"=hex(2):,\\\n"
                    "  25,48,4f,4d,45,25,00\n"
                    "\"Wine52l\"=hex(2):\\\n"
                    "  25,48,4f,4d,45,25,00\n\n", &r);
1915
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926
    verify_reg_nonexist(hkey, "Wine52a");
    verify_reg_nonexist(hkey, "Wine52b");
    verify_reg_nonexist(hkey, "Wine52c");
    verify_reg_nonexist(hkey, "Wine52d");
    verify_reg_nonexist(hkey, "Wine52e");
    verify_reg_nonexist(hkey, "Wine52f");
    verify_reg_nonexist(hkey, "Wine52g");
    verify_reg_nonexist(hkey, "Wine52h");
    verify_reg_nonexist(hkey, "Wine52i");
    verify_reg_nonexist(hkey, "Wine52j");
    verify_reg_nonexist(hkey, "Wine52k");
1927
    verify_reg(hkey, "Wine52l", REG_EXPAND_SZ, "%HOME%", 7, 0);
1928

1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine53a\"=hex(2):25,48,4f,4d,45,25,5c,\\\n"
                    "  25,50,41,54,48,25,00\n"
                    "\"Wine53b\"=hex(2):25,48,4f,4d,45,25,5c\\\n"
                    "  25,50,41,54,48,25,00\n"
                    "\"Wine53c\"=hex(2):25,48,4f,4d,45,25,5c,  \\  ;comment\n"
                    "  25,50,41,54,48,25,00\n"
                    "\"Wine53d\"=hex(2):25,48,4f,4d,45,25,5c  \\  ;comment\n"
                    "  25,50,41,54,48,25,00\n"
                    "\"Wine53e\"=hex(2):25,48,4f,4d,45,25,5c,\\\t  ;comment\n"
                    "  25,50,41,54,48,25,00\n"
                    "\"Wine53f\"=hex(2):25,48,4f,4d,45,25,5c\\\t  ;comment\n"
                    "  25,50,41,54,48,25,00\n\n", &r);
1943
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1944
    verify_reg(hkey, "Wine53a", REG_EXPAND_SZ, "%HOME%\\%PATH%", 14, 0);
1945
    verify_reg_nonexist(hkey, "Wine53b");
1946
    verify_reg(hkey, "Wine53c", REG_EXPAND_SZ, "%HOME%\\%PATH%", 14, 0);
1947
    verify_reg_nonexist(hkey, "Wine53d");
1948
    verify_reg(hkey, "Wine53e", REG_EXPAND_SZ, "%HOME%\\%PATH%", 14, 0);
1949
    verify_reg_nonexist(hkey, "Wine53f");
1950

1951 1952 1953 1954
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine54a\"=hex(2):4c,69,6e,65,20,\\\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1]\n", &r);
1955
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1956
    verify_reg_nonexist(hkey, "Wine54a");
1957
    verify_key_nonexist(hkey, "Subkey1");
1958 1959 1960 1961 1962

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine54b\"=hex(2):4c,69,6e,65,20\\\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2]\n", &r);
1963
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1964 1965
    verify_reg_nonexist(hkey, "Wine54b");
    verify_key(hkey, "Subkey2");
1966

1967
    delete_key(hkey, "Subkey2");
1968

1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine55a\"=hex(2):4c,69,6e,65,20,\\\n"
                    "\"Wine55b\"=\"Test value\"\n"

                    "\"Wine55c\"=hex(2):4c,69,6e,65,20,\\\n"
                    ";comment\n"
                    "\"Wine55d\"=\"Test value\"\n"

                    "\"Wine55e\"=hex(2):4c,69,6e,65,20,\\\n"
                    "#comment\n"
                    "\"Wine55f\"=\"Test value\"\n"

                    "\"Wine55g\"=hex(2):4c,69,6e,65,20,\\\n\n"
                    "\"Wine55h\"=\"Test value\"\n"

                    "\"Wine55i\"=hex(2):4c,69,6e,65,20\\\n"
                    "\"Wine55j\"=\"Test value\"\n\n", &r);
1987
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
1988
    verify_reg_nonexist(hkey, "Wine55a");
1989
    verify_reg_nonexist(hkey, "Wine55b");
1990
    verify_reg_nonexist(hkey, "Wine55c");
1991
    verify_reg_nonexist(hkey, "Wine55d");
1992
    verify_reg_nonexist(hkey, "Wine55e");
1993
    verify_reg(hkey, "Wine55f", REG_SZ, "Test value", 11, 0);
1994
    verify_reg_nonexist(hkey, "Wine55g");
1995
    verify_reg_nonexist(hkey, "Wine55h");
1996
    verify_reg_nonexist(hkey, "Wine55i");
1997
    verify_reg(hkey, "Wine55j", REG_SZ, "Test value", 11, 0);
1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine56a\"=hex(2):4c,69,6e,65,20,\\\n"
                    "\"Wine56b\"=dword:00000008\n"

                    "\"Wine56c\"=hex(2):4c,69,6e,65,20,\\\n"
                    ";comment\n"
                    "\"Wine56d\"=dword:00000008\n"

                    "\"Wine56e\"=hex(2):4c,69,6e,65,20,\\\n"
                    "#comment\n"
                    "\"Wine56f\"=dword:00000008\n"

                    "\"Wine56g\"=hex(2):4c,69,6e,65,20,\\\n\n"
                    "\"Wine56h\"=dword:00000008\n"

                    "\"Wine56i\"=hex(2):4c,69,6e,65,20\\\n"
                    "\"Wine56j\"=dword:00000008\n\n", &r);
2017
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2018
    verify_reg_nonexist(hkey, "Wine56a");
2019
    verify_reg_nonexist(hkey, "Wine56b");
2020
    verify_reg_nonexist(hkey, "Wine56c");
2021
    verify_reg_nonexist(hkey, "Wine56d");
2022
    verify_reg_nonexist(hkey, "Wine56e");
2023
    verify_reg(hkey, "Wine56f", REG_DWORD, &dword, sizeof(dword), 0);
2024
    verify_reg_nonexist(hkey, "Wine56g");
2025
    verify_reg_nonexist(hkey, "Wine56h");
2026
    verify_reg_nonexist(hkey, "Wine56i");
2027
    verify_reg(hkey, "Wine56j", REG_DWORD, &dword, sizeof(dword), 0);
2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine57a\"=hex(2):25,48,4f,4d,45,25,5c,\\\n"
                    "\"Wine57b\"=hex(2):25,50,41,54,48,25,00\n"

                    "\"Wine57c\"=hex(2):25,48,4f,4d,45,25,5c,\\\n"
                    ";comment\n"
                    "\"Wine57d\"=hex(2):25,50,41,54,48,25,00\n"

                    "\"Wine57e\"=hex(2):25,48,4f,4d,45,25,5c,\\\n"
                    "#comment\n"
                    "\"Wine57f\"=hex(2):25,50,41,54,48,25,00\n"

                    "\"Wine57g\"=hex(2):25,48,4f,4d,45,25,5c,\\\n\n"
                    "\"Wine57h\"=hex(2):25,50,41,54,48,25,00\n"

                    "\"Wine57i\"=hex(2):25,48,4f,4d,45,25,5c\\\n"
                    "\"Wine57j\"=hex(2):25,50,41,54,48,25,00\n\n", &r);
2047
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2048 2049 2050 2051 2052
    verify_reg_nonexist(hkey, "Wine57a");
    verify_reg_nonexist(hkey, "Wine57b");
    verify_reg_nonexist(hkey, "Wine57c");
    verify_reg_nonexist(hkey, "Wine57d");
    verify_reg_nonexist(hkey, "Wine57e");
2053
    verify_reg(hkey, "Wine57f", REG_EXPAND_SZ, "%PATH%", 7, 0);
2054 2055 2056
    verify_reg_nonexist(hkey, "Wine57g");
    verify_reg_nonexist(hkey, "Wine57h");
    verify_reg_nonexist(hkey, "Wine57i");
2057
    verify_reg(hkey, "Wine57j", REG_EXPAND_SZ, "%PATH%", 7, 0);
2058

2059
    delete_value(hkey, NULL);
2060 2061 2062 2063 2064

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine58a\"=hex(2):4c,69,6e,65,20,\\\n"
                    "@=\"Default value 1\"\n\n", &r);
2065
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2066
    verify_reg_nonexist(hkey, "Wine58a");
2067
    verify_reg_nonexist(hkey, NULL);
2068 2069 2070 2071 2072 2073

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine58b\"=hex(2):4c,69,6e,65,20,\\\n"
                    ";comment\n"
                    "@=\"Default value 2\"\n\n", &r);
2074
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2075
    verify_reg_nonexist(hkey, "Wine58b");
2076
    verify_reg_nonexist(hkey, NULL);
2077 2078 2079 2080 2081 2082

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine58c\"=hex(2):4c,69,6e,65,20,\\\n"
                    "#comment\n"
                    "@=\"Default value 3\"\n\n", &r);
2083
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2084
    verify_reg_nonexist(hkey, "Wine58c");
2085
    verify_reg(hkey, NULL, REG_SZ, "Default value 3", 16, 0);
2086

2087
    delete_value(hkey, NULL);
2088 2089 2090 2091 2092

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine58d\"=hex(2):4c,69,6e,65,20,\\\n\n"
                    "@=\"Default value 4\"\n\n", &r);
2093
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2094
    verify_reg_nonexist(hkey, "Wine58d");
2095
    verify_reg_nonexist(hkey, NULL);
2096 2097 2098 2099 2100

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine58e\"=hex(2):4c,69,6e,65,20\\\n"
                    "@=\"Default value 5\"\n\n", &r);
2101
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2102
    verify_reg_nonexist(hkey, "Wine58e");
2103
    verify_reg(hkey, NULL, REG_SZ, "Default value 5", 16, 0);
2104

2105 2106 2107 2108 2109 2110 2111 2112
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine59a\"=hex:11,22,33,\\\n"
                    "\\\n"
                    "  44,55,66\n"
                    "\"Wine59b\"=hex:11,22,33,\\\n"
                    "  \\\n"
                    "  44,55,66\n\n", &r);
2113
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2114 2115
    verify_reg_nonexist(hkey, "Wine59a");
    verify_reg_nonexist(hkey, "Wine59b");
2116

2117 2118 2119 2120 2121 2122 2123
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine60a\"=hex(7):4c,69,6e,65,20,\\\n"
                    "  63,6f,6e,63,61,74,\\\n"
                    ";comment\n"
                    "  65,6e,\\;comment\n"
                    "  61,74,69,6f,6e,00,00\n\n", &r);
2124
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2125
    verify_reg(hkey, "Wine60a", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2126 2127 2128 2129 2130 2131 2132 2133

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine60b\"=hex(7):4c,69,6e,65,20,\\\n"
                    "  63,6f,6e,63,61,74,\\\n"
                    "  ;comment\n"
                    "  65,6e,\\;comment\n"
                    "  61,74,69,6f,6e,00,00\n\n", &r);
2134
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2135
    verify_reg(hkey, "Wine60b", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2136 2137 2138 2139 2140 2141 2142 2143

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine60c\"=hex(7):4c,69,6e,65,20,\\\n"
                    "  63,6f,6e,63,61,74,\\\n"
                    "#comment\n"
                    "  65,6e,\\;comment\n"
                    "  61,74,69,6f,6e,00,00\n\n", &r);
2144
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2145
    verify_reg_nonexist(hkey, "Wine60c");
2146 2147 2148 2149 2150 2151 2152 2153

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine60d\"=hex(7):4c,69,6e,65,20,\\\n"
                    "  63,6f,6e,63,61,74,\\\n"
                    "  #comment\n"
                    "  65,6e,\\;comment\n"
                    "  61,74,69,6f,6e,00,00\n\n", &r);
2154
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2155
    verify_reg_nonexist(hkey, "Wine60d");
2156 2157 2158 2159 2160 2161 2162 2163

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine60e\"=hex(7):4c,69,6e,65,20,\\\n"
                    "  63,6f,6e,\\\n\n"
                    "  63,61,74,\\\n\n\n"
                    "  65,6e,\\\n\n\n\n"
                    "  61,74,69,6f,6e,00,00\n\n", &r);
2164
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2165
    verify_reg(hkey, "Wine60e", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2166

2167 2168 2169 2170 2171 2172 2173
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine60f\"=hex(7):4c,69,6e,65,20,\\\n"
                    "  63,6f,6e,\\\n \n"
                    "  63,61,74,\\\n\t\n\t\n"
                    "  65,6e,\\\n\t \t\n\t \t\n\t \t\n"
                    "  61,74,69,6f,6e,00,00\n\n", &r);
2174
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2175
    verify_reg(hkey, "Wine60f", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2176

2177 2178 2179 2180 2181 2182
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine61a\"=hex(0):25,48,4f,4d,45,25,5c,/\n"
                    "  25,50,41,54,48,25,00\n"
                    "\"Wine61b\"=hex(0):25,48,4f,4d,45,25,5c/\n"
                    "  25,50,41,54,48,25,00\n\n", &r);
2183
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2184 2185
    verify_reg_nonexist(hkey, "Wine61a");
    verify_reg_nonexist(hkey, "Wine61b");
2186

2187 2188
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2189
                    "\"Wine62a\"=hex(0):56,61,6c,75,65,\\", &r);
2190
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2191
    err = RegQueryValueExA(hkey, "Wine62a", NULL, NULL, NULL, NULL);
2192 2193
    ok(err == ERROR_SUCCESS || broken(err == ERROR_FILE_NOT_FOUND) /* WinXP */,
       "got %u, expected 0\n", err);
2194
    if (err == ERROR_SUCCESS)
2195
        verify_reg(hkey, "Wine62a", REG_NONE, "Value", 5, 0);
2196 2197 2198

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2199
                    "\"Wine62b\"=hex(2):25,50,41,54,48,25,\\", &r);
2200
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2201
    err = RegQueryValueExA(hkey, "Wine62b", NULL, NULL, NULL, NULL);
2202 2203
    ok(err == ERROR_SUCCESS || broken(err == ERROR_FILE_NOT_FOUND) /* WinXP */,
       "got %u, expected 0\n", err);
2204
    if (err == ERROR_SUCCESS)
2205
        verify_reg(hkey, "Wine62b", REG_EXPAND_SZ, "%PATH%", 7, 0);
2206 2207 2208 2209

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine62c\"=hex:11,22,33,44,55,\\", &r);
2210
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2211
    err = RegQueryValueExA(hkey, "Wine62c", NULL, NULL, NULL, NULL);
2212 2213
    ok(err == ERROR_SUCCESS || broken(err == ERROR_FILE_NOT_FOUND) /* WinXP */,
       "got %u, expected 0\n", err);
2214
    if (err == ERROR_SUCCESS)
2215
        verify_reg(hkey, "Wine62c", REG_BINARY, hex, 5, 0);
2216 2217 2218 2219

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine62d\"=hex(7):4c,69,6e,65,\\", &r);
2220
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2221
    err = RegQueryValueExA(hkey, "Wine62d", NULL, NULL, NULL, NULL);
2222 2223
    ok(err == ERROR_SUCCESS || broken(err == ERROR_FILE_NOT_FOUND) /* WinXP */,
       "got %u, expected 0\n", err);
2224
    if (err == ERROR_SUCCESS)
2225
        verify_reg(hkey, "Wine62d", REG_MULTI_SZ, "Line", 5, 0);
2226 2227 2228 2229

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine62e\"=hex(100):56,61,6c,75,65,\\", &r);
2230
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2231
    err = RegQueryValueExA(hkey, "Wine62e", NULL, NULL, NULL, NULL);
2232 2233
    ok(err == ERROR_SUCCESS || broken(err == ERROR_FILE_NOT_FOUND) /* WinXP */,
       "got %u, expected 0\n", err);
2234
    if (err == ERROR_SUCCESS)
2235
        verify_reg(hkey, "Wine62e", 0x100, "Value", 5, 0);
2236 2237 2238 2239

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine62f\"=hex(7):4c,69,6e,65,20\\", &r);
2240
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2241
    verify_reg_nonexist(hkey, "Wine62f");
2242

2243 2244 2245 2246 2247 2248
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine63a\"=hex(7):4c,69,6e,65,20,\\\n"
                    "  ,63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n"
                    "\"Wine63b\"=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", &r);
2249
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2250 2251
    verify_reg_nonexist(hkey, "Wine63a");
    verify_reg_nonexist(hkey, "Wine63b");
2252

2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine64a\"=hex(7):4c,69,6e,65,00,00\n"
                    "\"Wine64b\"=hex(7):4c,69,6e,65,20,\\\n"
                    "  63,6f,6e,63,61,74,65,6e,61,74,69,6f,6e,00,00\n"
                    "\"Wine64c\"=hex(7):4c,69,6e,65,20,\\;comment\n"
                    "  63,6f,6e,63,61,74,\\\n"
                    "  65,6e,61,74,69,6f,6e,00,00\n"
                    "\"Wine64d\"=hex(7):4c,69,6e,65,20,\\;comment\n"
                    "  63,6f,6e,63,61,74,\n"
                    "  65,6e,61,74,69,6f,6e,00,00\n"
                    "\"Wine64e\"=hex(7):4c,69,6e,65,20,\\\n"
                    "  63,6f,6e,63,61,74,;comment\n"
                    "  65,6e,61,74,69,6f,6e,00,00\n\n", &r);
2267
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2268 2269 2270
    verify_reg(hkey, "Wine64a", REG_MULTI_SZ, "Line\0", 6, 0);
    verify_reg(hkey, "Wine64b", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
    verify_reg(hkey, "Wine64c", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2271 2272 2273
    /* Wine64d */
    size = sizeof(buffer);
    err = RegQueryValueExA(hkey, "Wine64d", NULL, &type, (BYTE *)&buffer, &size);
2274 2275 2276 2277
    ok(err == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", err);
    ok(type == REG_MULTI_SZ, "got wrong type %u, expected %u\n", type, REG_MULTI_SZ);
    ok(size == 12 || broken(size == 11) /* WinXP */, "got wrong size %u, expected 12\n", size);
    ok(memcmp(buffer, "Line concat", size) == 0, "got wrong data\n");
2278 2279 2280
    /* Wine64e */
    size = sizeof(buffer);
    err = RegQueryValueExA(hkey, "Wine64e", NULL, &type, (BYTE *)&buffer, &size);
2281 2282 2283 2284
    ok(err == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", err);
    ok(type == REG_MULTI_SZ, "got wrong type %u, expected %u\n", type, REG_MULTI_SZ);
    ok(size == 12 || broken(size == 11) /* WinXP */, "got wrong size %u, expected 12\n", size);
    ok(memcmp(buffer, "Line concat", size) == 0, "got wrong data\n");
2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine65a\"=hex(100):25,50,41,54,48,25,00\n"
                    "\"Wine65b\"=hex(100):25,50,41,\\\n"
                    "  54,48,25,00\n"
                    "\"Wine65c\"=hex(100):25,50,41,\\;comment\n"
                    "  54,48,\\\n"
                    "  25,00\n"
                    "\"Wine65d\"=hex(100):25,50,41,\\;comment\n"
                    "  54,48,\n"
                    "  25,00\n"
                    "\"Wine65e\"=hex(100):25,50,41,\\;comment\n"
                    "  54,48,;comment\n"
                    "  25,00\n", &r);
2300
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2301 2302 2303 2304 2305
    verify_reg(hkey, "Wine65a", 0x100, "%PATH%", 7, 0);
    verify_reg(hkey, "Wine65b", 0x100, "%PATH%", 7, 0);
    verify_reg(hkey, "Wine65c", 0x100, "%PATH%", 7, 0);
    verify_reg(hkey, "Wine65d", 0x100, "%PATH", 5, 0);
    verify_reg(hkey, "Wine65e", 0x100, "%PATH", 5, 0);
2306 2307 2308 2309 2310 2311 2312 2313 2314 2315

    /* Test null-termination of REG_EXPAND_SZ and REG_MULTI_SZ data*/
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine66a\"=hex(7):4c,69,6e,65\n"
                    "\"Wine66b\"=hex(7):4c,69,6e,65,\n"
                    "\"Wine66c\"=hex(7):4c,69,6e,65,00\n"
                    "\"Wine66d\"=hex(7):4c,69,6e,65,00,\n"
                    "\"Wine66e\"=hex(7):4c,69,6e,65,00,00\n"
                    "\"Wine66f\"=hex(7):4c,69,6e,65,00,00,\n\n", &r);
2316
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2317 2318 2319 2320 2321 2322
    verify_reg(hkey, "Wine66a", REG_MULTI_SZ, "Line", 5, 0);
    verify_reg(hkey, "Wine66b", REG_MULTI_SZ, "Line", 5, 0);
    verify_reg(hkey, "Wine66c", REG_MULTI_SZ, "Line", 5, 0);
    verify_reg(hkey, "Wine66d", REG_MULTI_SZ, "Line", 5, 0);
    verify_reg(hkey, "Wine66e", REG_MULTI_SZ, "Line\0", 6, 0);
    verify_reg(hkey, "Wine66f", REG_MULTI_SZ, "Line\0", 6, 0);
2323 2324 2325 2326 2327 2328 2329

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine67a\"=hex(2):25,50,41,54,48,25\n"
                    "\"Wine67b\"=hex(2):25,50,41,54,48,25,\n"
                    "\"Wine67c\"=hex(2):25,50,41,54,48,25,00\n"
                    "\"Wine67d\"=hex(2):25,50,41,54,48,25,00,\n\n", &r);
2330
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2331 2332 2333 2334
    verify_reg(hkey, "Wine67a", REG_EXPAND_SZ, "%PATH%", 7, 0);
    verify_reg(hkey, "Wine67b", REG_EXPAND_SZ, "%PATH%", 7, 0);
    verify_reg(hkey, "Wine67c", REG_EXPAND_SZ, "%PATH%", 7, 0);
    verify_reg(hkey, "Wine67d", REG_EXPAND_SZ, "%PATH%", 7, 0);
2335

2336 2337 2338 2339 2340 2341 2342 2343
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine68a\"=hex(1):\n"
                    "\"Wine68b\"=hex(2):\n"
                    "\"Wine68c\"=hex(3):\n"
                    "\"Wine68d\"=hex(4):\n"
                    "\"Wine68e\"=hex(7):\n"
                    "\"Wine68f\"=hex(100):\n"
2344
                    "\"Wine68g\"=hex(abcd):\n"
2345 2346
                    "\"Wine68h\"=hex:\n"
                    "\"Wine68i\"=hex(0):\n\n", &r);
2347 2348
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_reg(hkey, "Wine68a", REG_SZ, NULL, 0, 0);
2349
    verify_reg(hkey, "Wine68b", REG_EXPAND_SZ, NULL, 0, 0);
2350 2351
    verify_reg(hkey, "Wine68c", REG_BINARY, NULL, 0, 0);
    verify_reg(hkey, "Wine68d", REG_DWORD, NULL, 0, 0);
2352
    verify_reg(hkey, "Wine68e", REG_MULTI_SZ, NULL, 0, 0);
2353 2354
    verify_reg(hkey, "Wine68f", 0x100, NULL, 0, 0);
    verify_reg(hkey, "Wine68g", 0xabcd, NULL, 0, 0);
2355
    verify_reg(hkey, "Wine68h", REG_BINARY, NULL, 0, 0);
2356
    verify_reg(hkey, "Wine68i", REG_NONE, NULL, 0, 0);
2357

2358
    err = RegCloseKey(hkey);
2359
    ok(err == ERROR_SUCCESS, "got %d, expected 0\n", err);
2360

2361
    delete_key(HKEY_CURRENT_USER, KEY_BASE);
2362 2363 2364 2365 2366 2367 2368
}

static void test_unicode_import(void)
{
    DWORD r, dword = 0x123, type, size;
    HKEY hkey, subkey;
    LONG err;
2369
    char buffer[24];
2370
    BYTE hex[8];
2371

2372 2373 2374
    err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
    ok(err == ERROR_SUCCESS || err == ERROR_FILE_NOT_FOUND, "got %d\n", err);

2375 2376 2377 2378 2379 2380 2381 2382
    test_import_wstr("REGEDIT\n", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);

    test_import_wstr("REGEDIT4\n", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);

2383
    test_import_wstr("\xef\xbb\xbfREGEDIT", &r);
2384
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2385

2386
    test_import_wstr("\xef\xbb\xbfREGEDIT\n", &r);
2387
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2388

2389
    test_import_wstr("\xef\xbb\xbfREGEDIT4", &r);
2390
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2391

2392
    test_import_wstr("\xef\xbb\xbfREGEDIT4\n", &r);
2393
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2394

2395
    test_import_wstr("\xef\xbb\xbf REGEDIT4\n", &r);
2396
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2397 2398

    test_import_wstr("\xef\xbb\xbf\tREGEDIT4\n", &r);
2399
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2400 2401 2402 2403 2404

    test_import_wstr("\xef\xbb\xbf\nREGEDIT4\n", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);

2405 2406
    test_import_wstr("\xef\xbb\xbfREGEDIT4\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n", &r);
2407
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2408

2409
    open_key(HKEY_CURRENT_USER, KEY_BASE, KEY_SET_VALUE, &hkey);
2410

2411 2412 2413
    test_import_wstr("\xef\xbb\xbfREGEDIT3\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Test1\"=\"Value\"\n", &r);
2414
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2415
    verify_reg_nonexist(hkey, "Test1");
2416 2417 2418 2419 2420 2421

    test_import_wstr("\xef\xbb\xbfregedit4\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Test2\"=\"Value\"\n", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);
2422
    verify_reg_nonexist(hkey, "Test2");
2423 2424 2425 2426 2427 2428

    test_import_wstr("\xef\xbb\xbfRegedit4\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Test3\"=\"Value\"\n", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);
2429
    verify_reg_nonexist(hkey, "Test3");
2430 2431 2432 2433

    test_import_wstr("\xef\xbb\xbfREGEDIT 4\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Test4\"=\"Value\"\n", &r);
2434
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2435
    verify_reg_nonexist(hkey, "Test4");
2436 2437 2438 2439

    test_import_wstr("\xef\xbb\xbfREGEDIT4FOO\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Test5\"=\"Value\"\n", &r);
2440
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2441
    verify_reg_nonexist(hkey, "Test5");
2442 2443 2444 2445

    test_import_wstr("\xef\xbb\xbfREGEDIT4 FOO\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Test6\"=\"Value\"\n", &r);
2446
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2447
    verify_reg_nonexist(hkey, "Test6");
2448 2449 2450 2451

    test_import_wstr("\xef\xbb\xbfREGEDIT5\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Test7\"=\"Value\"\n", &r);
2452
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2453
    verify_reg_nonexist(hkey, "Test7");
2454 2455 2456 2457

    test_import_wstr("\xef\xbb\xbfREGEDIT9\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Test8\"=\"Value\"\n", &r);
2458
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2459
    verify_reg_nonexist(hkey, "Test8");
2460

2461 2462 2463
    test_import_wstr("\xef\xbb\xbfREGEDIT4\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Unicode1\"=\"Value1\"\n", &r);
2464
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2465
    verify_reg(hkey, "Unicode1", REG_SZ, "Value1", 7, 0);
2466 2467 2468 2469

    test_import_wstr("\xef\xbb\xbfREGEDIT4\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Unicode2\"=\"Value2\"\n\n", &r);
2470
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2471
    verify_reg(hkey, "Unicode2", REG_SZ, "Value2", 7, 0);
2472 2473 2474 2475

    test_import_wstr("\xef\xbb\xbfREGEDIT4\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Unicode3\"=\"Value3\"\n\n", &r);
2476
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2477
    verify_reg(hkey, "Unicode3", REG_SZ, "Value3", 7, 0);
2478

2479 2480 2481 2482 2483 2484 2485 2486
    test_import_wstr("Windows Registry Editor Version 4.00\n", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);

    test_import_wstr("Windows Registry Editor Version 5.00\n", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);

2487
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5\n", &r);
2488 2489 2490
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);

2491
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00", &r);
2492
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2493

2494
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n", &r);
2495
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2496

2497
    test_import_wstr("\xef\xbb\xbfWINDOWS Registry Editor Version 5.00\n", &r);
2498 2499 2500
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);

2501
    test_import_wstr("\xef\xbb\xbf Windows Registry Editor Version 5.00\n", &r);
2502
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2503

2504
    test_import_wstr("\xef\xbb\xbf\tWindows Registry Editor Version 5.00\n", &r);
2505
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2506

2507
    test_import_wstr("\xef\xbb\xbf\nWindows Registry Editor Version 5.00\n", &r);
2508 2509
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);
2510

2511 2512 2513 2514 2515
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 4.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Test9\"=\"Value\"\n", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);
2516
    verify_reg_nonexist(hkey, "Test9");
2517 2518 2519 2520 2521 2522

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Test10\"=\"Value\"\n", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);
2523
    verify_reg_nonexist(hkey, "Test10");
2524 2525 2526 2527 2528 2529

    test_import_wstr("\xef\xbb\xbfWINDOWS REGISTRY EDITOR VERSION 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Test11\"=\"Value\"\n", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);
2530
    verify_reg_nonexist(hkey, "Test11");
2531 2532 2533 2534 2535 2536

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Test12\"=\"Value\"\n", &r);
    ok(r == REG_EXIT_FAILURE || broken(r == REG_EXIT_SUCCESS) /* WinXP */,
       "got exit code %d, expected 1\n", r);
2537
    verify_reg_nonexist(hkey, "Test12");
2538

2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine\"=dword:00000123\n\n", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_reg(hkey, "Wine", REG_DWORD, &dword, sizeof(dword), 0);

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "@=\"Test string\"\n\n", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_reg(hkey, NULL, REG_SZ, "Test string", 12, 0);

2551 2552 2553
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Unicode4\"=\"Value4\"\n", &r);
2554
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2555
    verify_reg(hkey, "Unicode4", REG_SZ, "Value4", 7, 0);
2556 2557 2558 2559

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Unicode5\"=\"Value5\"\n\n", &r);
2560
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2561
    verify_reg(hkey, "Unicode5", REG_SZ, "Value5", 7, 0);
2562 2563 2564 2565

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Unicode6\"=\"Value6\"\n\n", &r);
2566
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2567
    verify_reg(hkey, "Unicode6", REG_SZ, "Value6", 7, 0);
2568

2569 2570 2571 2572 2573 2574
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\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", &r);
2575
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2576 2577 2578 2579
    verify_reg(hkey, "Line1", REG_SZ, "Value1", 7, 0);
    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);
2580 2581 2582 2583 2584

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine1\"=dword:00000782\n\n"
                     "\"Wine2\"=\"Test Value\"\n"
2585 2586
                     "\"Wine3\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,63,00,6f,00,6e,00,63,00,\\\n"
                     "  61,00,74,00,65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n"
2587 2588 2589 2590
                     "#comment\n"
                     "@=\"Test\"\n"
                     ";comment\n\n"
                     "\"Wine4\"=dword:12345678\n\n", &r);
2591
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2592
    dword = 0x782;
2593
    verify_reg(hkey, "Wine1", REG_DWORD, &dword, sizeof(dword), 0);
2594
    verify_reg(hkey, "Wine2", REG_SZ, "Test Value", 11, 0);
2595
    verify_reg(hkey, "Wine3", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2596
    verify_reg(hkey, "", REG_SZ, "Test", 5, 0);
2597
    dword = 0x12345678;
2598
    verify_reg(hkey, "Wine4", REG_DWORD, &dword, sizeof(dword), 0);
2599 2600 2601 2602

    test_import_wstr("\xef\xbb\xbfREGEDIT4\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine5\"=\"No newline\"", &r);
2603
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2604
    err = RegQueryValueExA(hkey, "Wine5", NULL, NULL, NULL, NULL);
2605
    ok(err == ERROR_SUCCESS || broken(err == ERROR_FILE_NOT_FOUND /* WinXP */),
2606 2607 2608 2609 2610 2611 2612 2613
       "got %d, expected 0\n", err);
    if (err == ERROR_SUCCESS)
        verify_reg(hkey, "Wine5", REG_SZ, "No newline", 11, 0);

    test_import_wstr("\xef\xbb\xbfREGEDIT4\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine6\"=dword:00000050\n\n"
                     "\"Wine7\"=\"No newline\"", &r);
2614
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2615
    dword = 0x50;
2616
    verify_reg(hkey, "Wine6", REG_DWORD, &dword, sizeof(dword), 0);
2617
    err = RegQueryValueExA(hkey, "Wine7", NULL, NULL, NULL, NULL);
2618
    ok(err == ERROR_SUCCESS || broken(err == ERROR_FILE_NOT_FOUND /* WinXP */),
2619 2620 2621 2622
       "got %d, expected 0\n", err);
    if (err == ERROR_SUCCESS)
        verify_reg(hkey, "Wine7", REG_SZ, "No newline", 11, 0);

2623 2624 2625 2626 2627 2628
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "#comment\\\n"
                     "\"Wine8\"=\"Line 1\"\n"
                     ";comment\\\n"
                     "\"Wine9\"=\"Line 2\"\n\n", &r);
2629
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2630 2631
    verify_reg(hkey, "Wine8", REG_SZ, "Line 1", 7, 0);
    verify_reg(hkey, "Wine9", REG_SZ, "Line 2", 7, 0);
2632

2633 2634 2635 2636 2637 2638
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine10\"=\"Value 1\"#comment\n"
                     "\"Wine11\"=\"Value 2\";comment\n"
                     "\"Wine12\"=dword:01020304 #comment\n"
                     "\"Wine13\"=dword:02040608 ;comment\n\n", &r);
2639
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2640
    verify_reg_nonexist(hkey, "Wine10");
2641
    verify_reg(hkey, "Wine11", REG_SZ, "Value 2", 8, 0);
2642
    verify_reg_nonexist(hkey, "Wine12");
2643
    dword = 0x2040608;
2644
    verify_reg(hkey, "Wine13", REG_DWORD, &dword, sizeof(dword), 0);
2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine14\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,63,00,6f,00,6e,00,63,00,\\\n"
                     "  #comment\n"
                     "  61,00,74,00,65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n"
                     "\"Wine15\"=\"A valid line\"\n"
                     "\"Wine16\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,63,00,6f,00,6e,00,63,00,\\\n"
                     "  ;comment\n"
                     "  61,00,74,00,65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n"
                     "\"Wine17\"=\"Another valid line\"\n\n", &r);
2656
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2657
    verify_reg_nonexist(hkey, "Wine14");
2658
    verify_reg(hkey, "Wine15", REG_SZ, "A valid line", 13, 0);
2659
    verify_reg(hkey, "Wine16", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2660
    verify_reg(hkey, "Wine17", REG_SZ, "Another valid line", 19, 0);
2661 2662 2663 2664 2665 2666 2667 2668 2669

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "#\"Comment1\"=\"Value 1\"\n"
                     ";\"Comment2\"=\"Value 2\"\n"
                     "    #\"Comment3\"=\"Value 3\"\n"
                     "    ;\"Comment4\"=\"Value 4\"\n"
                     "\"Wine18\"=\"Value 6\"#\"Comment5\"=\"Value 5\"\n"
                     "\"Wine19\"=\"Value 7\";\"Comment6\"=\"Value 6\"\n\n", &r);
2670
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2671 2672 2673 2674 2675 2676
    verify_reg_nonexist(hkey, "Comment1");
    verify_reg_nonexist(hkey, "Comment2");
    verify_reg_nonexist(hkey, "Comment3");
    verify_reg_nonexist(hkey, "Comment4");
    verify_reg_nonexist(hkey, "Wine18");
    verify_reg_nonexist(hkey, "Comment5");
2677
    verify_reg(hkey, "Wine19", REG_SZ, "Value 7", 8, 0);
2678
    verify_reg_nonexist(hkey, "Comment6");
2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine20\"=#\"Value 8\"\n"
                     "\"Wine21\"=;\"Value 9\"\n"
                     "\"Wine22\"=\"#comment1\"\n"
                     "\"Wine23\"=\";comment2\"\n"
                     "\"Wine24\"=\"Value#comment3\"\n"
                     "\"Wine25\"=\"Value;comment4\"\n"
                     "\"Wine26\"=\"Value #comment5\"\n"
                     "\"Wine27\"=\"Value ;comment6\"\n"
                     "\"Wine28\"=#dword:00000001\n"
                     "\"Wine29\"=;dword:00000002\n"
                     "\"Wine30\"=dword:00000003#comment\n"
                     "\"Wine31\"=dword:00000004;comment\n\n", &r);
2694
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2695 2696
    verify_reg_nonexist(hkey, "Wine20");
    verify_reg_nonexist(hkey, "Wine21");
2697 2698 2699 2700 2701 2702
    verify_reg(hkey, "Wine22", REG_SZ, "#comment1", 10, 0);
    verify_reg(hkey, "Wine23", REG_SZ, ";comment2", 10, 0);
    verify_reg(hkey, "Wine24", REG_SZ, "Value#comment3", 15, 0);
    verify_reg(hkey, "Wine25", REG_SZ, "Value;comment4", 15, 0);
    verify_reg(hkey, "Wine26", REG_SZ, "Value #comment5", 16, 0);
    verify_reg(hkey, "Wine27", REG_SZ, "Value ;comment6", 16, 0);
2703 2704 2705
    verify_reg_nonexist(hkey, "Wine28");
    verify_reg_nonexist(hkey, "Wine29");
    verify_reg_nonexist(hkey, "Wine30");
2706
    dword = 0x00000004;
2707
    verify_reg(hkey, "Wine31", REG_DWORD, &dword, sizeof(dword), 0);
2708

2709 2710 2711 2712
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine32a\"=dword:1\n"
                     "\"Wine32b\"=dword:4444\n\n", &r);
2713
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2714
    dword = 0x1;
2715
    verify_reg(hkey, "Wine32a", REG_DWORD, &dword, sizeof(dword), 0);
2716
    dword = 0x4444;
2717
    verify_reg(hkey, "Wine32b", REG_DWORD, &dword, sizeof(dword), 0);
2718 2719 2720 2721 2722 2723

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine33a\"=dword:\n"
                     "\"Wine33b\"=dword:hello\n"
                     "\"Wine33c\"=dword:123456789\n"
2724 2725
                     "\"Wine33d\"=dword:012345678\n"
                     "\"Wine33e\"=dword:000000001\n\n", &r);
2726
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2727 2728 2729 2730 2731
    verify_reg_nonexist(hkey, "Wine33a");
    verify_reg_nonexist(hkey, "Wine33b");
    verify_reg_nonexist(hkey, "Wine33c");
    verify_reg_nonexist(hkey, "Wine33d");
    verify_reg_nonexist(hkey, "Wine33e");
2732 2733 2734 2735 2736

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine34a\"=dword:12345678abc\n"
                     "\"Wine34b\"=dword:12345678 abc\n\n", &r);
2737
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2738 2739
    verify_reg_nonexist(hkey, "Wine34a");
    verify_reg_nonexist(hkey, "Wine34b");
2740 2741 2742 2743 2744 2745

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine35a\"=dword:0x123\n"
                     "\"Wine35b\"=dword:123 456\n"
                     "\"Wine35c\"=dword:1234 5678\n\n", &r);
2746
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2747 2748 2749
    verify_reg_nonexist(hkey, "Wine35a");
    verify_reg_nonexist(hkey, "Wine35b");
    verify_reg_nonexist(hkey, "Wine35c");
2750 2751 2752 2753 2754 2755 2756

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine36a\"=dword:1234;5678\n"
                     "\"Wine36b\"=dword:1234 ;5678\n"
                     "\"Wine36c\"=dword:1234#5678\n"
                     "\"Wine36d\"=dword:1234 #5678\n\n", &r);
2757
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2758
    dword = 0x1234;
2759 2760
    verify_reg(hkey, "Wine36a", REG_DWORD, &dword, sizeof(dword), 0);
    verify_reg(hkey, "Wine36b", REG_DWORD, &dword, sizeof(dword), 0);
2761 2762
    verify_reg_nonexist(hkey, "Wine36c");
    verify_reg_nonexist(hkey, "Wine36d");
2763

2764 2765 2766 2767
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine37a\"=\"foo\"bar\"\n"
                     "\"Wine37b\"=\"foo\"\"bar\"\n\n", &r);
2768
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2769 2770
    verify_reg_nonexist(hkey, "Wine37a");
    verify_reg_nonexist(hkey, "Wine37b");
2771

2772 2773
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
2774 2775
                     "\"Empty string\"=\"\"\n"
                     "\"\"=\"Default registry value\"\n\n", &r);
2776
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2777 2778
    verify_reg(hkey, "Empty string", REG_SZ, "", 1, 0);
    verify_reg(hkey, NULL, REG_SZ, "Default registry value", 23, 0);
2779 2780 2781 2782 2783 2784 2785

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Test38a\"=\n"
                     "\"Test38b\"=\\\"\n"
                     "\"Test38c\"=\\\"Value\\\"\n"
                     "\"Test38d\"=\\\"Value\"\n\n", &r);
2786
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2787 2788 2789 2790
    verify_reg_nonexist(hkey, "Test38a");
    verify_reg_nonexist(hkey, "Test38b");
    verify_reg_nonexist(hkey, "Test38c");
    verify_reg_nonexist(hkey, "Test38d");
2791 2792 2793 2794 2795 2796 2797

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine39a\"=\"Value1\"  ;comment\n"
                     "\"Wine39b\"=\"Value2\"\t\t;comment\n"
                     "\"Wine39c\"=\"Value3\"  #comment\n"
                     "\"Wine39d\"=\"Value4\"\t\t#comment\n\n", &r);
2798
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2799 2800
    verify_reg(hkey, "Wine39a", REG_SZ, "Value1", 7, 0);
    verify_reg(hkey, "Wine39b", REG_SZ, "Value2", 7, 0);
2801 2802
    verify_reg_nonexist(hkey, "Wine39c");
    verify_reg_nonexist(hkey, "Wine39d");
2803

2804 2805 2806
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"TestNoBeginQuote\"=Asdffdsa\"\n", &r);
2807
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2808
    verify_reg_nonexist(hkey, "TestNoBeginQuote");
2809 2810 2811 2812

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"TestNoEndQuote\"=\"Asdffdsa\n", &r);
2813
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2814
    verify_reg_nonexist(hkey, "TestNoEndQuote");
2815 2816 2817 2818

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"TestNoQuotes\"=Asdffdsa\n", &r);
2819
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2820
    verify_reg_nonexist(hkey, "TestNoQuotes");
2821 2822 2823 2824

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "NameNoBeginQuote\"=\"Asdffdsa\"\n", &r);
2825
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2826
    verify_reg_nonexist(hkey, "NameNoBeginQuote");
2827 2828 2829 2830

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"NameNoEndQuote=\"Asdffdsa\"\n", &r);
2831
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2832
    verify_reg_nonexist(hkey, "NameNoEndQuote");
2833 2834 2835 2836

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "NameNoQuotes=\"Asdffdsa\"\n", &r);
2837
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2838
    verify_reg_nonexist(hkey, "NameNoQuotes");
2839 2840 2841 2842

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                 "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                 "\"MixedQuotes=Asdffdsa\"\n", &r);
2843
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2844 2845
    verify_reg_nonexist(hkey, "MixedQuotes");
    verify_reg_nonexist(hkey, "MixedQuotes=Asdffdsa");
2846

2847 2848 2849 2850 2851 2852 2853 2854 2855
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine40a\"=hex(2):4c,00,69,00,6e,00,65,00,00,00\n"
                     "\"Wine40b\"=\"Value 1\"\n"
                     "\"Wine40c\"=hex(2):4c,00,69,00,6e,00,65,00\\\n"
                     "\"Wine40d\"=\"Value 2\"\n"
                     "\"Wine40e\"=hex(2):4c,00,69,00,6e,00,65,00,\\\n"
                     "\"Wine40f\"=\"Value 3\"\n"
                     "\"Wine40g\"=\"Value 4\"\n\n", &r);
2856
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2857
    verify_reg(hkey, "Wine40a", REG_EXPAND_SZ, "Line", 5, 0);
2858
    verify_reg(hkey, "Wine40b", REG_SZ, "Value 1", 8, 0);
2859
    verify_reg_nonexist(hkey, "Wine40c");
2860
    verify_reg(hkey, "Wine40d", REG_SZ, "Value 2", 8, 0);
2861
    verify_reg_nonexist(hkey, "Wine40e");
2862
    verify_reg_nonexist(hkey, "Wine40f");
2863
    verify_reg(hkey, "Wine40g", REG_SZ, "Value 4", 8, 0);
2864

2865 2866 2867 2868 2869 2870
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Multi-Line1\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
                     "  63,00,6f,00,6e,00,\\;comment\n"
                     "  63,00,61,00,74,00,\\;comment\n"
                     "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n", &r);
2871
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2872
    verify_reg(hkey, "Multi-Line1", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2873 2874 2875 2876 2877 2878 2879

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Multi-Line2\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
                     "  63,00,6f,00,6e,00,\\;comment\n"
                     "  63,00,61,00,74,00,;comment\n"
                     "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n", &r);
2880
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2881
    verify_reg(hkey, "Multi-Line2", REG_MULTI_SZ, "Line concat", 12, 0);
2882

2883 2884 2885 2886
    test_import_wstr("\xef\xbb\xbfREGEDIT4\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", &r);
2887
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2888
    verify_reg_nonexist(hkey, "Multi-Line3");
2889 2890 2891 2892 2893

    test_import_wstr("\xef\xbb\xbfREGEDIT4\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", &r);
2894
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2895
    verify_reg_nonexist(hkey, "Multi-Line4");
2896 2897 2898 2899 2900

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Multi-Line5\"=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", &r);
2901
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2902
    verify_reg_nonexist(hkey, "Multi-Line5");
2903 2904 2905 2906 2907

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Multi-Line6\"=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", &r);
2908
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2909
    verify_reg_nonexist(hkey, "Multi-Line6");
2910

2911 2912 2913 2914 2915 2916 2917
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Multi-Line7\"=hex(7):4c,00,69,00,6e,00,\\;comment\n"
                     "  65,00,20,00,\\;comment\n"
                     "  63,00,6f,00,6e,00,\\;comment\n"
                     "  63,00,61,00,74,00,\\;comment\n"
                     "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n", &r);
2918
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2919
    verify_reg(hkey, "Multi-Line7", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2920 2921 2922 2923 2924 2925 2926 2927

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Multi-Line8\"=hex(7):4c,00,69,00,6e,00,\\;#comment\n"
                     "  65,00,20,00,\\;#comment\n"
                     "  63,00,6f,00,6e,00,\\;#comment\n"
                     "  63,00,61,00,74,00,\\;#comment\n"
                     "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n", &r);
2928
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2929
    verify_reg(hkey, "Multi-Line8", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2930 2931 2932 2933 2934 2935 2936 2937

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Multi-Line9\"=hex(7):4c,00,69,00,6e,00,\\;comment\n"
                     "  65,00,20,00,\\;comment\n"
                     "  63,00,6f,00,6e,00,\\;comment\n"
                     "  63,00,61,00,74,00,\\#comment\n"
                     "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n", &r);
2938
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2939
    verify_reg_nonexist(hkey, "Multi-Line9");
2940

2941 2942 2943 2944 2945 2946 2947
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Multi-Line10\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
                     "  63,00,6f,00,6e,00,\\;comment\n"
                     "  63,00,61,00,74,00,\\\n\n"
                     "  65,00,6e,00,\\;comment\n\n"
                     "  61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n", &r);
2948
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2949
    verify_reg(hkey, "Multi-Line10", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
2950

2951 2952 2953 2954 2955 2956
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine41a\"=dword:1234\\\n"
                     "5678\n"
                     "\"Wine41b\"=\"Test \\\n"
                     "Value\"\n\n", &r);
2957
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2958 2959
    verify_reg_nonexist(hkey, "Wine41a");
    verify_reg_nonexist(hkey, "Wine41b");
2960

2961 2962 2963 2964
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"double\\\"quote\"=\"valid \\\"or\\\" not\"\n"
                     "\"single'quote\"=dword:00000008\n\n", &r);
2965
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2966
    verify_reg(hkey, "double\"quote", REG_SZ, "valid \"or\" not", 15, 0);
2967
    dword = 0x00000008;
2968
    verify_reg(hkey, "single'quote", REG_DWORD, &dword, sizeof(dword), 0);
2969

2970 2971 2972 2973
    /* Test key name and value name concatenation */
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\\n"
                     "Subkey1]\n", &r);
2974
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2975
    verify_key_nonexist(hkey, "Subkey1");
2976 2977 2978 2979

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "\n"
                     "\\Subkey2]\n", &r);
2980
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2981
    verify_key_nonexist(hkey, "Subkey2");
2982 2983 2984 2985 2986 2987 2988 2989

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine\\\n"
                     "42a\"=\"Value 1\"\n"
                     "\"Wine42b\"=\"Value 2\"\n"
                     "\"Wine\n"
                     "\\42c\"=\"Value 3\"\n\n", &r);
2990
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
2991
    verify_reg_nonexist(hkey, "Wine42a");
2992
    verify_reg(hkey, "Wine42b", REG_SZ, "Value 2", 8, 0);
2993
    verify_reg_nonexist(hkey, "Wine42c");
2994

2995
    /* Test hex data concatenation for REG_NONE, REG_EXPAND_SZ and REG_BINARY */
2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine43a\"=hex(0):56,00,61,00,6c,00,75,00,65,00,00,00\n"
                     "\"Wine43b\"=hex(0):56,00,61,00,6c,00,\\\n"
                     "  75,00,65,00,00,00\n"
                     "\"Wine43c\"=hex(0):56,00,61,00,6c,00\\\n"
                     ",75,00,65,00,00,00\n"
                     "\"Wine43d\"=hex(0):56,00,61,00,6c,00\\\n"
                     "  ,75,00,65,00,00,00\n"
                     "\"Wine43e\"=hex(0):56,00,61,00,6c,00\\\n"
                     "  75,00,65,00,00,00\n"
                     "\"Wine43f\"=hex(0):56,00,61,00,6c,00,7\\\n"
                     "5,00,65,00,00,00\n"
                     "\"Wine43g\"=hex(0):56,00,61,00,6c,00,7\\\n"
3010
                     "  5,00,65,00,00,00\n"
3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022
                     "\"Wine43h\"=hex(0):56,00,61,00,\\;comment\n"
                     "  6c,00,75,00,\\\n"
                     "  65,00,00,00\n"
                     "\"Wine43i\"=hex(0):56,00,61,00,\\;comment\n"
                     "  6c,00,75,00,\n"
                     "  65,00,00,00\n"
                     "\"Wine43j\"=hex(0):56,00,61,00,\\;comment\n"
                     "  6c,00,75,00,;comment\n"
                     "  65,00,00,00\n"
                     "\"Wine43k\"=hex(0):56,00,61,00,\\;comment\n"
                     "  6c,00,75,00,\\#comment\n"
                     "  65,00,00,00\n\n", &r);
3023
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3024 3025
    verify_reg(hkey, "Wine43a", REG_NONE, "V\0a\0l\0u\0e\0\0", 12, 0);
    verify_reg(hkey, "Wine43b", REG_NONE, "V\0a\0l\0u\0e\0\0", 12, 0);
3026 3027 3028 3029 3030
    verify_reg_nonexist(hkey, "Wine43c");
    verify_reg_nonexist(hkey, "Wine43d");
    verify_reg_nonexist(hkey, "Wine43e");
    verify_reg_nonexist(hkey, "Wine43f");
    verify_reg_nonexist(hkey, "Wine43g");
3031 3032 3033
    verify_reg(hkey, "Wine43h", REG_NONE, "V\0a\0l\0u\0e\0\0", 12, 0);
    verify_reg(hkey, "Wine43i", REG_NONE, "V\0a\0l\0u", 8, 0);
    verify_reg(hkey, "Wine43j", REG_NONE, "V\0a\0l\0u", 8, 0);
3034
    verify_reg_nonexist(hkey, "Wine43k");
3035

3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine44a\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"
                     "\"Wine44b\"=hex(2):25,00,50,00,41,00,\\\n"
                     "  54,00,48,00,25,00,00,00\n"
                     "\"Wine44c\"=hex(2):25,00,50,00,41,00\\\n"
                     ",54,00,48,00,25,00,00,00\n"
                     "\"Wine44d\"=hex(2):25,00,50,00,41,00\\\n"
                     "  ,54,00,48,00,25,00,00,00\n"
                     "\"Wine44e\"=hex(2):25,00,50,00,41,00\\\n"
                     "  54,00,48,00,25,00,00,00\n"
                     "\"Wine44f\"=hex(2):25,00,50,00,4\\\n"
                     "1,00,54,00,48,00,25,00,00,00\n"
                     "\"Wine44g\"=hex(2):25,00,50,00,4\\\n"
                     "  1,00,54,00,48,00,25,00,00,00\n"
                     "\"Wine44h\"=hex(2):25,00,50,00,41,00,\\;comment\n"
                     "  54,00,48,00,\\\n"
                     "  25,00,00,00\n"
                     "\"Wine44i\"=hex(2):25,00,50,00,41,00,\\;comment\n"
                     "  54,00,48,00\n"
                     "  25,00,00,00\n"
                     "\"Wine44j\"=hex(2):25,00,50,00,41,00,\\;comment\n"
                     "  54,00,48,00;comment\n"
                     "  25,00,00,00\n"
                     "\"Wine44k\"=hex(2):25,00,50,00,41,00,\\;comment\n"
                     "  54,00,48,00,\\#comment\n"
                     "  25,00,00,00\n\n", &r);
3063
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3064 3065
    verify_reg(hkey, "Wine44a", REG_EXPAND_SZ, "%PATH%", 7, 0);
    verify_reg(hkey, "Wine44b", REG_EXPAND_SZ, "%PATH%", 7, 0);
3066 3067 3068 3069 3070
    verify_reg_nonexist(hkey, "Wine44c");
    verify_reg_nonexist(hkey, "Wine44d");
    verify_reg_nonexist(hkey, "Wine44e");
    verify_reg_nonexist(hkey, "Wine44f");
    verify_reg_nonexist(hkey, "Wine44g");
3071
    verify_reg(hkey, "Wine44h", REG_EXPAND_SZ, "%PATH%", 7, 0);
3072 3073 3074
    /* Wine44i */
    size = sizeof(buffer);
    err = RegQueryValueExA(hkey, "Wine44i", NULL, &type, (BYTE *)&buffer, &size);
3075 3076
    ok(err == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", err);
    ok(type == REG_EXPAND_SZ, "got wrong type %u, expected %u\n", type, REG_EXPAND_SZ);
3077
    ok(size == 6 || broken(size == 5) /* WinXP */, "got wrong size %u, expected 6\n", size);
3078
    ok(memcmp(buffer, "%PATH", size) == 0, "got wrong data\n");
3079 3080 3081 3082
    /* Wine44j */
    size = sizeof(buffer);
    memset(buffer, '-', size);
    err = RegQueryValueExA(hkey, "Wine44j", NULL, &type, (BYTE *)&buffer, &size);
3083 3084
    ok(err == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", err);
    ok(type == REG_EXPAND_SZ, "got wrong type %u, expected %u\n", type, REG_EXPAND_SZ);
3085
    ok(size == 6 || broken(size == 5) /* WinXP */, "got wrong size %u, expected 6\n", size);
3086
    ok(memcmp(buffer, "%PATH", size) == 0, "got wrong data\n");
3087
    /* Wine44k */
3088
    verify_reg_nonexist(hkey, "Wine44k");
3089

3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine45a\"=hex:11,22,33,44,55,66,77,88\n"
                     "\"Wine45b\"=hex:11,22,33,44,\\\n"
                     "  55,66,77,88\n"
                     "\"Wine45c\"=hex:11,22,33,44\\\n"
                     ",55,66,77,88\n"
                     "\"Wine45d\"=hex:11,22,33,44\\\n"
                     "  ,55,66,77,88\n"
                     "\"Wine45e\"=hex:11,22,33,44\\\n"
                     "  55,66,77,88\n"
                     "\"Wine45f\"=hex:11,22,33,4\\\n"
                     "4,55,66,77,88\n"
                     "\"Wine45g\"=hex:11,22,33,4\\\n"
                     "  4,55,66,77,88\n"
                     "\"Wine45h\"=hex:11,22,33,44,\\;comment\n"
                     "  55,66,\\\n"
                     "  77,88\n"
                     "\"Wine45i\"=hex:11,22,33,44,\\;comment\n"
                     "  55,66,\n"
                     "  77,88\n"
                     "\"Wine45j\"=hex:11,22,33,44,\\;comment\n"
                     "  55,66,;comment\n"
                     "  77,88\n"
                     "\"Wine45k\"=hex:11,22,33,\\;comment\n"
                     "  44,55,66,\\#comment\n"
                     "  77,88\n\n", &r);
3117
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3118 3119
    hex[0] = 0x11; hex[1] = 0x22; hex[2] = 0x33; hex[3] = 0x44;
    hex[4] = 0x55; hex[5] = 0x66; hex[6] = 0x77; hex[7] = 0x88;
3120 3121
    verify_reg(hkey, "Wine45a", REG_BINARY, hex, sizeof(hex), 0);
    verify_reg(hkey, "Wine45b", REG_BINARY, hex, sizeof(hex), 0);
3122 3123 3124 3125 3126
    verify_reg_nonexist(hkey, "Wine45c");
    verify_reg_nonexist(hkey, "Wine45d");
    verify_reg_nonexist(hkey, "Wine45e");
    verify_reg_nonexist(hkey, "Wine45f");
    verify_reg_nonexist(hkey, "Wine45g");
3127 3128 3129
    verify_reg(hkey, "Wine45h", REG_BINARY, hex, sizeof(hex), 0);
    verify_reg(hkey, "Wine45i", REG_BINARY, hex, 6, 0);
    verify_reg(hkey, "Wine45j", REG_BINARY, hex, 6, 0);
3130
    verify_reg_nonexist(hkey, "Wine45k");
3131

3132
    /* Test import with subkeys */
3133 3134 3135
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey\"1]\n"
                     "\"Wine\\\\31\"=\"Test value\"\n\n", &r);
3136
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3137
    open_key(hkey, "Subkey\"1", 0, &subkey);
3138
    verify_reg(subkey, "Wine\\31", REG_SZ, "Test value", 11, 0);
3139
    err = RegCloseKey(subkey);
3140
    ok(err == ERROR_SUCCESS, "got %d, expected 0\n", err);
3141
    delete_key(HKEY_CURRENT_USER, KEY_BASE "\\Subkey\"1");
3142 3143 3144 3145

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey/2]\n"
                     "\"123/\\\"4;'5\"=\"Random value name\"\n\n", &r);
3146
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3147
    open_key(hkey, "Subkey/2", 0, &subkey);
3148
    verify_reg(subkey, "123/\"4;'5", REG_SZ, "Random value name", 18, 0);
3149
    err = RegCloseKey(subkey);
3150
    ok(err == ERROR_SUCCESS, "got %d, expected 0\n", err);
3151
    delete_key(HKEY_CURRENT_USER, KEY_BASE "\\Subkey/2");
3152

3153 3154 3155
    /* Test key creation */
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "HKEY_CURRENT_USER\\" KEY_BASE "\\No_Opening_Bracket]\n", &r);
3156
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3157
    verify_key_nonexist(hkey, "No_Opening_Bracket");
3158 3159 3160

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\No_Closing_Bracket\n", &r);
3161
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3162
    verify_key_nonexist(hkey, "No_Closing_Bracket");
3163 3164 3165

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[ HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1a]\n", &r);
3166
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3167
    verify_key_nonexist(hkey, "Subkey1a");
3168 3169 3170

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[\tHKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1b]\n", &r);
3171
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3172
    verify_key_nonexist(hkey, "Subkey1b");
3173 3174 3175

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1c ]\n", &r);
3176
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3177
    verify_key(hkey, "Subkey1c ");
3178
    delete_key(hkey, "Subkey1c ");
3179 3180 3181

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1d\t]\n", &r);
3182
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3183
    verify_key(hkey, "Subkey1d\t");
3184
    delete_key(hkey, "Subkey1d\t");
3185

3186 3187 3188
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1e\\]\n"
                     "\"Wine\"=\"Test value\"\n\n", &r);
3189
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3190 3191
    verify_key(hkey, "Subkey1e\\");
    verify_key(hkey, "Subkey1e");
3192
    open_key(hkey, "Subkey1e", 0, &subkey);
3193
    verify_reg(subkey, "Wine", REG_SZ, "Test value", 11, 0);
3194
    RegCloseKey(subkey);
3195
    delete_key(hkey, "Subkey1e");
3196 3197 3198 3199

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1f\\\\]\n"
                     "\"Wine\"=\"Test value\"\n\n", &r);
3200
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3201 3202 3203
    verify_key(hkey, "Subkey1f\\\\");
    verify_key(hkey, "Subkey1f\\");
    verify_key(hkey, "Subkey1f");
3204
    open_key(hkey, "Subkey1f\\\\", 0, &subkey);
3205
    verify_reg(subkey, "Wine", REG_SZ, "Test value", 11, 0);
3206
    RegCloseKey(subkey);
3207
    delete_key(hkey, "Subkey1f\\\\");
3208 3209 3210 3211

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1g\\\\\\\\]\n"
                     "\"Wine\"=\"Test value\"\n\n", &r);
3212
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3213 3214 3215 3216
    verify_key(hkey, "Subkey1g\\\\\\\\");
    verify_key(hkey, "Subkey1g\\\\");
    verify_key(hkey, "Subkey1g\\");
    verify_key(hkey, "Subkey1g");
3217
    open_key(hkey, "Subkey1g\\\\", 0, &subkey);
3218
    verify_reg(subkey, "Wine", REG_SZ, "Test value", 11, 0);
3219
    RegCloseKey(subkey);
3220
    delete_key(hkey, "Subkey1g\\\\");
3221

3222 3223 3224 3225
    /* Test key deletion. We start by creating some registry keys. */
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a]\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2b]\n\n", &r);
3226
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3227 3228
    verify_key(hkey, "Subkey2a");
    verify_key(hkey, "Subkey2b");
3229 3230 3231

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[ -HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a]\n", &r);
3232
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3233
    verify_key(hkey, "Subkey2a");
3234 3235 3236

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[\t-HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2b]\n", &r);
3237
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3238
    verify_key(hkey, "Subkey2b");
3239 3240 3241

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[- HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a]\n", &r);
3242
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3243
    verify_key(hkey, "Subkey2a");
3244 3245

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3246
                     "[-\tHKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2b]\n", &r);
3247
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3248
    verify_key(hkey, "Subkey2b");
3249 3250 3251 3252

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[-HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a]\n\n"
                     "[-HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2b]\n\n", &r);
3253
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3254 3255
    verify_key_nonexist(hkey, "Subkey2a");
    verify_key_nonexist(hkey, "Subkey2b");
3256

3257 3258 3259 3260
    /* Test case sensitivity when creating and deleting registry keys. */
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[hkey_CURRENT_user\\" KEY_BASE "\\Subkey3a]\n\n"
                     "[HkEy_CuRrEnT_uSeR\\" KEY_BASE "\\SuBkEy3b]\n\n", &r);
3261
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3262 3263
    verify_key(hkey, "Subkey3a");
    verify_key(hkey, "Subkey3b");
3264 3265 3266 3267

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[-HKEY_current_USER\\" KEY_BASE "\\sUBKEY3A]\n\n"
                     "[-hKeY_cUrReNt_UsEr\\" KEY_BASE "\\sUbKeY3B]\n\n", &r);
3268
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3269 3270
    verify_key_nonexist(hkey, "Subkey3a");
    verify_key_nonexist(hkey, "Subkey3b");
3271

3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283
    /* Test mixed key creation and deletion. We start by creating a subkey. */
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey4a]\n\n", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_key(hkey, "Subkey4a");

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n\n"
                     "[-HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey4a]\n"
                     "\"Wine46a\"=dword:12345678\n\n", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_key_nonexist(hkey, "Subkey4a");
3284
    verify_reg_nonexist(hkey, "Wine46a");
3285 3286 3287 3288 3289 3290 3291 3292 3293

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n\n"
                     "[HKEY_CURRENT_USERS\\" KEY_BASE "\\Subkey4b]\n"
                     "\"Wine46b\"=dword:12345678\n\n", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_key_nonexist(hkey, "Subkey4b");
    verify_reg_nonexist(hkey, "Wine46b");

3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304
    /* Test value deletion. We start by creating some registry values. */
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine46a\"=\"Test Value\"\n"
                     "\"Wine46b\"=dword:00000008\n"
                     "\"Wine46c\"=hex:11,22,33,44\n"
                     "\"Wine46d\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
                     "  63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
                     "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n"
                     "\"Wine46e\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"
                     "\"Wine46f\"=hex(0):56,00,61,00,6c,00,75,00,65,00,00,00\n\n", &r);
3305
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3306
    verify_reg(hkey, "Wine46a", REG_SZ, "Test Value", 11, 0);
3307
    verify_reg(hkey, "Wine46b", REG_DWORD, &dword, sizeof(dword), 0);
3308 3309 3310 3311
    verify_reg(hkey, "Wine46c", REG_BINARY, hex, 4, 0);
    verify_reg(hkey, "Wine46d", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
    verify_reg(hkey, "Wine46e", REG_EXPAND_SZ, "%PATH%", 7, 0);
    verify_reg(hkey, "Wine46f", REG_NONE, "V\0a\0l\0u\0e\0\0", 12, 0);
3312 3313 3314 3315 3316 3317 3318 3319 3320

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine46a\"=-\n"
                     "\"Wine46b\"=  -\n"
                     "\"Wine46c\"=  \t-\t  \n"
                     "\"Wine46d\"=-\"Test\"\n"
                     "\"Wine46e\"=- ;comment\n"
                     "\"Wine46f\"=- #comment\n\n", &r);
3321
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3322 3323 3324
    verify_reg_nonexist(hkey, "Wine46a");
    verify_reg_nonexist(hkey, "Wine46b");
    verify_reg_nonexist(hkey, "Wine46c");
3325
    verify_reg(hkey, "Wine46d", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
3326
    verify_reg_nonexist(hkey, "Wine46e");
3327
    verify_reg(hkey, "Wine46f", REG_NONE, "V\0a\0l\0u\0e\0\0", 12, 0);
3328

3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339
    /* Test the accepted range of the hex-based data types */
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine47a\"=hex(0):56,61,6c,75,65,00\n"
                     "\"Wine47b\"=hex(10):56,61,6c,75,65,00\n"
                     "\"Wine47c\"=hex(100):56,61,6c,75,65,00\n"
                     "\"Wine47d\"=hex(1000):56,61,6c,75,65,00\n"
                     "\"Wine47e\"=hex(7fff):56,61,6c,75,65,00\n"
                     "\"Wine47f\"=hex(ffff):56,61,6c,75,65,00\n"
                     "\"Wine47g\"=hex(7fffffff):56,61,6c,75,65,00\n"
                     "\"Wine47h\"=hex(ffffffff):56,61,6c,75,65,00\n"
3340 3341
                     "\"Wine47i\"=hex(100000000):56,61,6c,75,65,00\n"
                     "\"Wine47j\"=hex(0x2):56,00,61,00,6c,00,75,00,65,00,00,00\n"
3342 3343
                     "\"Wine47k\"=hex(0X2):56,00,61,00,6c,00,75,00,65,00,00,00\n"
                     "\"Wine47l\"=hex(x2):56,00,61,00,6c,00,75,00,65,00,00,00\n\n", &r);
3344
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3345 3346 3347 3348 3349 3350 3351 3352
    verify_reg(hkey, "Wine47a", REG_NONE, "Value", 6, 0);
    verify_reg(hkey, "Wine47b", 0x10, "Value", 6, 0);
    verify_reg(hkey, "Wine47c", 0x100, "Value", 6, 0);
    verify_reg(hkey, "Wine47d", 0x1000, "Value", 6, 0);
    verify_reg(hkey, "Wine47e", 0x7fff, "Value", 6, 0);
    verify_reg(hkey, "Wine47f", 0xffff, "Value", 6, 0);
    verify_reg(hkey, "Wine47g", 0x7fffffff, "Value", 6, 0);
    verify_reg(hkey, "Wine47h", 0xffffffff, "Value", 6, 0);
3353 3354 3355 3356
    verify_reg_nonexist(hkey, "Wine47i");
    verify_reg_nonexist(hkey, "Wine47j");
    verify_reg_nonexist(hkey, "Wine47k");
    verify_reg_nonexist(hkey, "Wine47l");
3357

3358 3359 3360 3361 3362 3363 3364 3365
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine48a\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,  \\\n"
                     "  63,00,6f,00,6e,00,63,00,61,00,74,00,    \\\n"
                     "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n"
                     "\"Wine48b\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\t\\\n"
                     "  63,00,6f,00,6e,00,63,00,61,00,74,00,\t  \t  \\\n"
                     "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n", &r);
3366
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3367 3368
    verify_reg(hkey, "Wine48a", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
    verify_reg(hkey, "Wine48b", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
3369 3370 3371

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
3372
                     "\"Wine49\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00,\n\n", &r);
3373
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3374
    verify_reg(hkey, "Wine49", REG_EXPAND_SZ, "%PATH%", 7, 0);
3375 3376 3377 3378 3379 3380 3381

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine50a\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00  ;comment\n"
                     "\"Wine50b\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00\t;comment\n"
                     "\"Wine50c\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00  #comment\n"
                     "\"Wine50d\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00\t#comment\n\n", &r);
3382
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3383 3384
    verify_reg(hkey, "Wine50a", REG_EXPAND_SZ, "%PATH%", 7, 0);
    verify_reg(hkey, "Wine50b", REG_EXPAND_SZ, "%PATH%", 7, 0);
3385 3386
    verify_reg_nonexist(hkey, "Wine50c");
    verify_reg_nonexist(hkey, "Wine50d");
3387 3388 3389 3390 3391 3392

    /* Test support for characters greater than 0xff */
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine51a\"=hex(0):25,50,100,54,48,25,00\n"
                     "\"Wine51b\"=hex(0):25,1a4,100,164,124,25,00\n\n", &r);
3393
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3394 3395
    verify_reg_nonexist(hkey, "Wine51a");
    verify_reg_nonexist(hkey, "Wine51b");
3396

3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415
    /* Test the effect of backslashes in hex data */
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine52a\"=hex(2):25,00,48\\,00,4f,00,4d,00,45,00,25,00,00,00\n"
                     "\"Wine52b\"=hex(2):25,00,48,00,\\4f,00,4d,00,45,00,25,00,00,00\n"
                     "\"Wine52c\"=hex(2):25,00,48\\ ,00,4f,00,4d,00,45,00,25,00,00,00\n"
                     "\"Wine52d\"=hex(2):25,00,48,00,\\ 4f,00,4d,00,45,00,25,00,00,00\n"
                     "\"Wine52e\"=hex(2):\\25,00,48,00,4f,00,4d,00,45,00,25,00,00,00\n"
                     "\"Wine52f\"=hex(2):\\ 25,00,48,00,4f,00,4d,00,45,00,25,00,00,00\n"
                     "\"Wine52g\"=hex(2):25,00,48,00,4\\f,00,4d,00,45,00,25,00,00,00\n"
                     "\"Wine52h\"=hex(2):25,00,48,00,4\\\n"
                     "  f,00,4d,00,45,00,25,00,00,00\n"
                     "\"Wine52i\"=hex(2):25,00,50,00,\\,41,00,54,00,48,00,25,00,00,00\n"
                     "\"Wine52j\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00,\\\\\n"
                     "  25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"
                     "\"Wine52k\"=hex(2):,\\\n"
                     "  25,00,48,00,4f,00,4d,00,45,00,25,00,00,00\n"
                     "\"Wine52l\"=hex(2):\\\n"
                     "  25,00,48,00,4f,00,4d,00,45,00,25,00,00,00\n\n", &r);
3416
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427
    verify_reg_nonexist(hkey, "Wine52a");
    verify_reg_nonexist(hkey, "Wine52b");
    verify_reg_nonexist(hkey, "Wine52c");
    verify_reg_nonexist(hkey, "Wine52d");
    verify_reg_nonexist(hkey, "Wine52e");
    verify_reg_nonexist(hkey, "Wine52f");
    verify_reg_nonexist(hkey, "Wine52g");
    verify_reg_nonexist(hkey, "Wine52h");
    verify_reg_nonexist(hkey, "Wine52i");
    verify_reg_nonexist(hkey, "Wine52j");
    verify_reg_nonexist(hkey, "Wine52k");
3428
    verify_reg(hkey, "Wine52l", REG_EXPAND_SZ, "%HOME%", 7, 0);
3429

3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine53a\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00,\\\n"
                     "  25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"
                     "\"Wine53b\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00\\\n"
                     "  25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"
                     "\"Wine53c\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00,  \\  ;comment\n"
                     "  25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"
                     "\"Wine53d\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00  \\  ;comment\n"
                     "  25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"
                     "\"Wine53e\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00,\\\t  ;comment\n"
                     "  25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"
                     "\"Wine53f\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00\\\t  ;comment\n"
                     "  25,00,50,00,41,00,54,00,48,00,25,00,00,00\n\n", &r);
3444
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3445
    verify_reg(hkey, "Wine53a", REG_EXPAND_SZ, "%HOME%\\%PATH%", 14, 0);
3446
    verify_reg_nonexist(hkey, "Wine53b");
3447
    verify_reg(hkey, "Wine53c", REG_EXPAND_SZ, "%HOME%\\%PATH%", 14, 0);
3448
    verify_reg_nonexist(hkey, "Wine53d");
3449
    verify_reg(hkey, "Wine53e", REG_EXPAND_SZ, "%HOME%\\%PATH%", 14, 0);
3450
    verify_reg_nonexist(hkey, "Wine53f");
3451

3452 3453 3454 3455
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine54a\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1]\n", &r);
3456
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3457
    verify_reg_nonexist(hkey, "Wine54a");
3458
    verify_key_nonexist(hkey, "Subkey1");
3459 3460 3461 3462 3463

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine54b\"=hex(2):4c,00,69,00,6e,00,65,00,20,00\\\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2]\n", &r);
3464
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3465 3466
    verify_reg_nonexist(hkey, "Wine54b");
    verify_key(hkey, "Subkey2");
3467

3468
    delete_key(hkey, "Subkey2");
3469

3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine55a\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n"
                     "\"Wine55b\"=\"Test value\"\n"

                     "\"Wine55c\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n"
                     ";comment\n"
                     "\"Wine55d\"=\"Test value\"\n"

                     "\"Wine55e\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n"
                     "#comment\n"
                     "\"Wine55f\"=\"Test value\"\n"

                     "\"Wine55g\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n\n"
                     "\"Wine55h\"=\"Test value\"\n"

                     "\"Wine55i\"=hex(2):4c,00,69,00,6e,00,65,00,20,00\\\n"
                     "\"Wine55j\"=\"Test value\"\n\n", &r);
3488
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3489
    verify_reg_nonexist(hkey, "Wine55a");
3490
    verify_reg_nonexist(hkey, "Wine55b");
3491
    verify_reg_nonexist(hkey, "Wine55c");
3492
    verify_reg_nonexist(hkey, "Wine55d");
3493
    verify_reg_nonexist(hkey, "Wine55e");
3494
    verify_reg(hkey, "Wine55f", REG_SZ, "Test value", 11, 0);
3495
    verify_reg_nonexist(hkey, "Wine55g");
3496
    verify_reg_nonexist(hkey, "Wine55h");
3497
    verify_reg_nonexist(hkey, "Wine55i");
3498
    verify_reg(hkey, "Wine55j", REG_SZ, "Test value", 11, 0);
3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine56a\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n"
                     "\"Wine56b\"=dword:00000008\n"

                     "\"Wine56c\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n"
                     ";comment\n"
                     "\"Wine56d\"=dword:00000008\n"

                     "\"Wine56e\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n"
                     "#comment\n"
                     "\"Wine56f\"=dword:00000008\n"

                     "\"Wine56g\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n\n"
                     "\"Wine56h\"=dword:00000008\n"

                     "\"Wine56i\"=hex(2):4c,00,69,00,6e,00,65,00,20,00\\\n"
                     "\"Wine56j\"=dword:00000008\n\n", &r);
3518
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3519
    verify_reg_nonexist(hkey, "Wine56a");
3520
    verify_reg_nonexist(hkey, "Wine56b");
3521
    verify_reg_nonexist(hkey, "Wine56c");
3522
    verify_reg_nonexist(hkey, "Wine56d");
3523
    verify_reg_nonexist(hkey, "Wine56e");
3524
    verify_reg(hkey, "Wine56f", REG_DWORD, &dword, sizeof(dword), 0);
3525
    verify_reg_nonexist(hkey, "Wine56g");
3526
    verify_reg_nonexist(hkey, "Wine56h");
3527
    verify_reg_nonexist(hkey, "Wine56i");
3528
    verify_reg(hkey, "Wine56j", REG_DWORD, &dword, sizeof(dword), 0);
3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine57a\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00,\\\n"
                     "\"Wine57b\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"

                     "\"Wine57c\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00,\\\n"
                     ";comment\n"
                     "\"Wine57d\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"

                     "\"Wine57e\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00,\\\n"
                     "#comment\n"
                     "\"Wine57f\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"

                     "\"Wine57g\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00,\\\n\n"
                     "\"Wine57h\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"

                     "\"Wine57i\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00\\\n"
                     "\"Wine57j\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00\n\n", &r);
3548
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3549 3550 3551 3552 3553
    verify_reg_nonexist(hkey, "Wine57a");
    verify_reg_nonexist(hkey, "Wine57b");
    verify_reg_nonexist(hkey, "Wine57c");
    verify_reg_nonexist(hkey, "Wine57d");
    verify_reg_nonexist(hkey, "Wine57e");
3554
    verify_reg(hkey, "Wine57f", REG_EXPAND_SZ, "%PATH%", 7, 0);
3555 3556 3557
    verify_reg_nonexist(hkey, "Wine57g");
    verify_reg_nonexist(hkey, "Wine57h");
    verify_reg_nonexist(hkey, "Wine57i");
3558
    verify_reg(hkey, "Wine57j", REG_EXPAND_SZ, "%PATH%", 7, 0);
3559

3560
    delete_value(hkey, NULL);
3561 3562 3563 3564 3565

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine58a\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n"
                     "@=\"Default value 1\"\n\n", &r);
3566
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3567
    verify_reg_nonexist(hkey, "Wine58a");
3568
    verify_reg_nonexist(hkey, NULL);
3569 3570 3571 3572 3573 3574

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine58b\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n"
                     ";comment\n"
                     "@=\"Default value 2\"\n\n", &r);
3575
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3576
    verify_reg_nonexist(hkey, "Wine58b");
3577
    verify_reg_nonexist(hkey, NULL);
3578 3579 3580 3581 3582 3583

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine58c\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n"
                     "#comment\n"
                     "@=\"Default value 3\"\n\n", &r);
3584
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3585
    verify_reg_nonexist(hkey, "Wine58c");
3586
    verify_reg(hkey, NULL, REG_SZ, "Default value 3", 16, 0);
3587

3588
    delete_value(hkey, NULL);
3589 3590 3591 3592 3593

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine58d\"=hex(2):4c,00,69,00,6e,00,65,00,20,00,\\\n\n"
                     "@=\"Default value 4\"\n\n", &r);
3594
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3595
    verify_reg_nonexist(hkey, "Wine58d");
3596
    verify_reg_nonexist(hkey, NULL);
3597 3598 3599 3600 3601

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine58e\"=hex(2):4c,00,69,00,6e,00,65,00,20,00\\\n"
                     "@=\"Default value 5\"\n\n", &r);
3602
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3603
    verify_reg_nonexist(hkey, "Wine58e");
3604
    verify_reg(hkey, NULL, REG_SZ, "Default value 5", 16, 0);
3605

3606 3607 3608 3609 3610 3611 3612 3613
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine59a\"=hex:11,22,33,\\\n"
                     "\\\n"
                     "  44,55,66\n"
                     "\"Wine59b\"=hex:11,22,33,\\\n"
                     "  \\\n"
                     "  44,55,66\n\n", &r);
3614
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3615 3616
    verify_reg_nonexist(hkey, "Wine59a");
    verify_reg_nonexist(hkey, "Wine59b");
3617

3618 3619 3620 3621 3622 3623 3624
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine60a\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
                     "  63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
                     ";comment\n"
                     "  65,00,6e,00,\\;comment\n"
                     "  61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n", &r);
3625
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3626
    verify_reg(hkey, "Wine60a", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
3627 3628 3629 3630 3631 3632 3633 3634

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine60b\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
                     "  63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
                     "  ;comment\n"
                     "  65,00,6e,00,\\;comment\n"
                     "  61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n", &r);
3635
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3636
    verify_reg(hkey, "Wine60b", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
3637 3638 3639 3640 3641 3642 3643 3644

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine60c\"=hex(7):4c,69,6e,65,20,\\\n"
                     "  63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
                     "#comment\n"
                     "  65,00,6e,00,\\;comment\n"
                     "  61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n", &r);
3645
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3646
    verify_reg_nonexist(hkey, "Wine60c");
3647 3648 3649 3650 3651 3652 3653 3654

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine60d\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
                     "  63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
                     "  #comment\n"
                     "  65,00,6e,00,\\;comment\n"
                     "  61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n", &r);
3655
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3656
    verify_reg_nonexist(hkey, "Wine60d");
3657 3658 3659 3660 3661 3662 3663 3664

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine60e\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
                     "  63,00,6f,00,6e,00,\\\n\n"
                     "  63,00,61,00,74,00,\\\n\n\n"
                     "  65,00,6e,00,\\\n\n\n\n"
                     "  61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n", &r);
3665
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3666
    verify_reg(hkey, "Wine60e", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
3667

3668 3669 3670 3671 3672 3673 3674
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine60f\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
                     "  63,00,6f,00,6e,00,\\\n \n"
                     "  63,00,61,00,74,00,\\\n\t\n\t\n"
                     "  65,00,6e,00,\\\n\t \t\n\t \t\n\t \t\n"
                     "  61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n", &r);
3675
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3676
    verify_reg(hkey, "Wine60f", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
3677

3678 3679 3680 3681 3682 3683
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine61a\"=hex(0):25,48,4f,4d,45,25,5c,/\n"
                     "  25,50,41,54,48,25,00\n"
                     "\"Wine61b\"=hex(0):25,48,4f,4d,45,25,5c/\n"
                     "  25,50,41,54,48,25,00\n\n", &r);
3684
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3685 3686
    verify_reg_nonexist(hkey, "Wine61a");
    verify_reg_nonexist(hkey, "Wine61b");
3687

3688 3689
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
3690
                     "\"Wine62a\"=hex(0):56,61,6c,75,65,\\", &r);
3691
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3692
    err = RegQueryValueExA(hkey, "Wine62a", NULL, NULL, NULL, NULL);
3693 3694
    ok(err == ERROR_SUCCESS || broken(err == ERROR_FILE_NOT_FOUND) /* WinXP */,
       "got %u, expected 0\n", err);
3695
    if (err == ERROR_SUCCESS)
3696
        verify_reg(hkey, "Wine62a", REG_NONE, "Value", 5, 0);
3697 3698

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
3699 3700
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine62b\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,\\", &r);
3701
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3702
    err = RegQueryValueExA(hkey, "Wine62b", NULL, NULL, NULL, NULL);
3703 3704
    ok(err == ERROR_SUCCESS || broken(err == ERROR_FILE_NOT_FOUND) /* WinXP */,
       "got %u, expected 0\n", err);
3705
    if (err == ERROR_SUCCESS)
3706
        verify_reg(hkey, "Wine62b", REG_EXPAND_SZ, "%PATH%", 7, 0);
3707 3708 3709 3710

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine62c\"=hex:11,22,33,44,55,\\", &r);
3711
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3712
    err = RegQueryValueExA(hkey, "Wine62c", NULL, NULL, NULL, NULL);
3713 3714
    ok(err == ERROR_SUCCESS || broken(err == ERROR_FILE_NOT_FOUND) /* WinXP */,
       "got %u, expected 0\n", err);
3715
    if (err == ERROR_SUCCESS)
3716
        verify_reg(hkey, "Wine62c", REG_BINARY, hex, 5, 0);
3717 3718 3719 3720

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine62d\"=hex(7):4c,00,69,00,6e,00,65,00,\\", &r);
3721
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3722
    err = RegQueryValueExA(hkey, "Wine62d", NULL, NULL, NULL, NULL);
3723 3724
    ok(err == ERROR_SUCCESS || broken(err == ERROR_FILE_NOT_FOUND) /* WinXP */,
       "got %u, expected 0\n", err);
3725
    if (err == ERROR_SUCCESS)
3726
        verify_reg(hkey, "Wine62d", REG_MULTI_SZ, "Line", 5, 0);
3727 3728 3729 3730

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine62e\"=hex(100):56,61,6c,75,65,\\", &r);
3731
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3732
    err = RegQueryValueExA(hkey, "Wine62e", NULL, NULL, NULL, NULL);
3733 3734
    ok(err == ERROR_SUCCESS || broken(err == ERROR_FILE_NOT_FOUND) /* WinXP */,
       "got %u, expected 0\n", err);
3735
    if (err == ERROR_SUCCESS)
3736
        verify_reg(hkey, "Wine62e", 0x100, "Value", 5, 0);
3737 3738 3739 3740

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine62f\"=hex(7):4c,00,69,00,6e,00,65,00,20,00\\", &r);
3741
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3742
    verify_reg_nonexist(hkey, "Wine62f");
3743

3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine63a\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
                     "  ,63,00,6f,00,6e,00,\\\n"
                     "  63,00,61,00,74,00,\\\n"
                     "  65,00,6e,00,\\\n"
                     "  61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n"
                     "\"Wine63b\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
                     "  63,,00,6f,00,6e,00,\\\n"
                     "  63,00,61,00,74,00,\\\n"
                     "  65,00,6e,00,\\\n"
                     "  61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n", &r);
3756
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3757 3758
    verify_reg_nonexist(hkey, "Wine63a");
    verify_reg_nonexist(hkey, "Wine63b");
3759

3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine64a\"=hex(7):4c,00,69,00,6e,00,65,00,00,00,00,00\n"
                     "\"Wine64b\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
                     "  63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
                     "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n"
                     "\"Wine64c\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\;comment\n"
                     "  63,00,6f,00,6e,00,63,00,61,00,74,00,\\\n"
                     "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n"
                     "\"Wine64d\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\;comment\n"
                     "  63,00,6f,00,6e,00,63,00,61,00,74,00,\n"
                     "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n"
                     "\"Wine64e\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,\\\n"
                     "  63,00,6f,00,6e,00,63,00,61,00,74,00,;comment\n"
                     "  65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n", &r);
3775
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3776 3777 3778
    verify_reg(hkey, "Wine64a", REG_MULTI_SZ, "Line\0", 6, 0);
    verify_reg(hkey, "Wine64b", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
    verify_reg(hkey, "Wine64c", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
3779 3780 3781
    /* Wine64d */
    size = sizeof(buffer);
    err = RegQueryValueExA(hkey, "Wine64d", NULL, &type, (BYTE *)&buffer, &size);
3782 3783
    ok(err == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", err);
    ok(type == REG_MULTI_SZ, "got wrong type %u, expected %u\n", type, REG_MULTI_SZ);
3784
    ok(size == 12 || broken(size == 11) /* WinXP */, "got wrong size %u, expected 12\n", size);
3785
    ok(memcmp(buffer, "Line concat", size) == 0, "got wrong data\n");
3786 3787 3788
    /* Wine64e */
    size = sizeof(buffer);
    err = RegQueryValueExA(hkey, "Wine64e", NULL, &type, (BYTE *)&buffer, &size);
3789 3790
    ok(err == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", err);
    ok(type == REG_MULTI_SZ, "got wrong type %u, expected %u\n", type, REG_MULTI_SZ);
3791
    ok(size == 12 || broken(size == 11) /* WinXP */, "got wrong size %u, expected 12\n", size);
3792
    ok(memcmp(buffer, "Line concat", size) == 0, "got wrong data\n");
3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine65a\"=hex(100):25,50,41,54,48,25,00\n"
                     "\"Wine65b\"=hex(100):25,50,41,\\\n"
                     "  54,48,25,00\n"
                     "\"Wine65c\"=hex(100):25,50,41,\\;comment\n"
                     "  54,48,\\\n"
                     "  25,00\n"
                     "\"Wine65d\"=hex(100):25,50,41,\\;comment\n"
                     "  54,48,\n"
                     "  25,00\n"
                     "\"Wine65e\"=hex(100):25,50,41,\\;comment\n"
                     "  54,48,;comment\n"
                     "  25,00\n", &r);
3808
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3809 3810 3811 3812 3813
    verify_reg(hkey, "Wine65a", 0x100, "%PATH%", 7, 0);
    verify_reg(hkey, "Wine65b", 0x100, "%PATH%", 7, 0);
    verify_reg(hkey, "Wine65c", 0x100, "%PATH%", 7, 0);
    verify_reg(hkey, "Wine65d", 0x100, "%PATH", 5, 0);
    verify_reg(hkey, "Wine65e", 0x100, "%PATH", 5, 0);
3814 3815 3816 3817 3818 3819 3820 3821 3822 3823

    /* Test null-termination of REG_EXPAND_SZ and REG_MULTI_SZ data*/
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine66a\"=hex(7):4c,00,69,00,6e,00,65,00\n"
                     "\"Wine66b\"=hex(7):4c,00,69,00,6e,00,65,00,\n"
                     "\"Wine66c\"=hex(7):4c,00,69,00,6e,00,65,00,00,00\n"
                     "\"Wine66d\"=hex(7):4c,00,69,00,6e,00,65,00,00,00,\n"
                     "\"Wine66e\"=hex(7):4c,00,69,00,6e,00,65,00,00,00,00,00\n"
                     "\"Wine66f\"=hex(7):4c,00,69,00,6e,00,65,00,00,00,00,00,\n\n", &r);
3824
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3825 3826
    verify_reg(hkey, "Wine66a", REG_MULTI_SZ, "Line", 5, 0);
    verify_reg(hkey, "Wine66b", REG_MULTI_SZ, "Line", 5, 0);
3827 3828 3829 3830
    verify_reg(hkey, "Wine66c", REG_MULTI_SZ, "Line", 5, 0);
    verify_reg(hkey, "Wine66d", REG_MULTI_SZ, "Line", 5, 0);
    verify_reg(hkey, "Wine66e", REG_MULTI_SZ, "Line\0", 6, 0);
    verify_reg(hkey, "Wine66f", REG_MULTI_SZ, "Line\0", 6, 0);
3831 3832 3833 3834 3835 3836 3837

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine67a\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00\n"
                     "\"Wine67b\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,\n"
                     "\"Wine67c\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00\n"
                     "\"Wine67d\"=hex(2):25,00,50,00,41,00,54,00,48,00,25,00,00,00,\n\n", &r);
3838
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3839 3840
    verify_reg(hkey, "Wine67a", REG_EXPAND_SZ, "%PATH%", 7, 0);
    verify_reg(hkey, "Wine67b", REG_EXPAND_SZ, "%PATH%", 7, 0);
3841 3842
    verify_reg(hkey, "Wine67c", REG_EXPAND_SZ, "%PATH%", 7, 0);
    verify_reg(hkey, "Wine67d", REG_EXPAND_SZ, "%PATH%", 7, 0);
3843

3844 3845 3846 3847 3848 3849 3850 3851
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine68a\"=hex(1):\n"
                     "\"Wine68b\"=hex(2):\n"
                     "\"Wine68c\"=hex(3):\n"
                     "\"Wine68d\"=hex(4):\n"
                     "\"Wine68e\"=hex(7):\n"
                     "\"Wine68f\"=hex(100):\n"
3852
                     "\"Wine68g\"=hex(abcd):\n"
3853 3854
                     "\"Wine68h\"=hex:\n"
                     "\"Wine68i\"=hex(0):\n\n", &r);
3855 3856
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_reg(hkey, "Wine68a", REG_SZ, NULL, 0, 0);
3857
    verify_reg(hkey, "Wine68b", REG_EXPAND_SZ, NULL, 0, 0);
3858 3859
    verify_reg(hkey, "Wine68c", REG_BINARY, NULL, 0, 0);
    verify_reg(hkey, "Wine68d", REG_DWORD, NULL, 0, 0);
3860
    verify_reg(hkey, "Wine68e", REG_MULTI_SZ, NULL, 0, 0);
3861 3862
    verify_reg(hkey, "Wine68f", 0x100, NULL, 0, 0);
    verify_reg(hkey, "Wine68g", 0xabcd, NULL, 0, 0);
3863
    verify_reg(hkey, "Wine68h", REG_BINARY, NULL, 0, 0);
3864
    verify_reg(hkey, "Wine68i", REG_NONE, NULL, 0, 0);
3865

3866
    err = RegCloseKey(hkey);
3867
    ok(err == ERROR_SUCCESS, "got %d, expected 0\n", err);
3868

3869
    delete_key(HKEY_CURRENT_USER, KEY_BASE);
3870 3871
}

3872 3873 3874 3875 3876 3877
static void test_import_with_whitespace(void)
{
    HKEY hkey;
    DWORD r, dword;
    LONG err;

3878 3879 3880
    err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
    ok(err == ERROR_SUCCESS || err == ERROR_FILE_NOT_FOUND, "got %d\n", err);

3881 3882
    test_import_str("  REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n\n", &r);
3883
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
3884

3885
    open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
3886 3887 3888 3889

    test_import_str("  REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine1a\"=\"Value\"\n\n", &r);
3890
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
3891
    verify_reg(hkey, "Wine1a", REG_SZ, "Value", 6, 0);
3892 3893 3894 3895

    test_import_str("\tREGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine1b\"=\"Value\"\n\n", &r);
3896
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
3897
    verify_reg(hkey, "Wine1b", REG_SZ, "Value", 6, 0);
3898 3899 3900 3901

    test_import_str(" \t REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine1c\"=\"Value\"\n\n", &r);
3902
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
3903
    verify_reg(hkey, "Wine1c", REG_SZ, "Value", 6, 0);
3904 3905 3906 3907

    test_import_str("REGEDIT4\n\n"
                    "  [HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine2a\"=\"Value\"\n\n", &r);
3908
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
3909
    verify_reg(hkey, "Wine2a", REG_SZ, "Value", 6, 0);
3910 3911 3912 3913

    test_import_str("REGEDIT4\n\n"
                    "\t[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine2b\"=\"Value\"\n\n", &r);
3914
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
3915
    verify_reg(hkey, "Wine2b", REG_SZ, "Value", 6, 0);
3916 3917 3918 3919

    test_import_str("REGEDIT4\n\n"
                    " \t [HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine2c\"=\"Value\"\n\n", &r);
3920
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
3921
    verify_reg(hkey, "Wine2c", REG_SZ, "Value", 6, 0);
3922 3923 3924 3925

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "  \"Wine3a\"=\"Two leading spaces\"\n\n", &r);
3926
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
3927
    verify_reg(hkey, "Wine3a", REG_SZ, "Two leading spaces", 19, 0);
3928 3929 3930 3931

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\t\"Wine3b\"=\"One leading tab\"\n\n", &r);
3932
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
3933
    verify_reg(hkey, "Wine3b", REG_SZ, "One leading tab", 16, 0);
3934 3935 3936 3937

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    " \t \"Wine3c\"=\"Space, tab, space\"\n\n", &r);
3938
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
3939
    verify_reg(hkey, "Wine3c", REG_SZ, "Space, tab, space", 18, 0);
3940 3941 3942 3943 3944 3945 3946 3947 3948

    test_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", &r);
3949
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3950
    verify_reg(hkey, "Wine4a", REG_SZ, "Tab and four spaces", 20, 0);
3951
    dword = 0x112233;
3952
    verify_reg(hkey, "Wine4b", REG_DWORD, &dword, sizeof(dword), 0);
3953
    verify_reg(hkey, "Wine4c", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
3954 3955 3956 3957 3958 3959 3960

    test_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", &r);
3961
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3962 3963 3964 3965
    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);
3966 3967 3968 3969 3970 3971

    test_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", &r);
3972
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3973 3974 3975
    verify_reg(hkey, "  Wine6a", REG_SZ, "Leading spaces", 15, 0);
    verify_reg(hkey, "\t\tWine6b", REG_SZ, "Leading tabs", 13, 0);
    verify_reg(hkey, "  Wine6c  ", REG_SZ, "  Spaces everywhere  ", 22, 0);
3976 3977 3978 3979 3980

    test_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", &r);
3981
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3982 3983
    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);
3984 3985 3986 3987 3988

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine8a\"=\"Trailing spaces\"    \n"
                    "\"Wine8b\"=\"Trailing tabs and spaces\"\t  \t\n\n", &r);
3989
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3990 3991
    verify_reg(hkey, "Wine8a", REG_SZ, "Trailing spaces", 16, 0);
    verify_reg(hkey, "Wine8b", REG_SZ, "Trailing tabs and spaces", 25, 0);
3992

3993 3994 3995 3996
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine9a\"=dword:  00000008\n"
                    "\"Wine9b\"=dword:\t\t00000008\n\n", &r);
3997
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
3998
    dword = 0x00000008;
3999 4000
    verify_reg(hkey, "Wine9a", REG_DWORD, &dword, sizeof(dword), 0);
    verify_reg(hkey, "Wine9b", REG_DWORD, &dword, sizeof(dword), 0);
4001

4002 4003 4004
    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "@  =  \"Test Value\"\n\n", &r);
4005
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4006
    verify_reg(hkey, "", REG_SZ, "Test Value", 11, 0);
4007 4008 4009 4010

    test_import_str("REGEDIT4\n\n"
                    "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\t@\t=\tdword:\t00000008\t\n\n", &r);
4011
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4012
    verify_reg(hkey, "", REG_DWORD, &dword, sizeof(DWORD), 0);
4013

4014
    err = RegCloseKey(hkey);
4015
    ok(err == ERROR_SUCCESS, "RegCloseKey failed: got %d, expected 0\n", err);
4016

4017
    delete_key(HKEY_CURRENT_USER, KEY_BASE);
4018 4019 4020 4021 4022 4023 4024
}

static void test_unicode_import_with_whitespace(void)
{
    HKEY hkey;
    DWORD r, dword;
    LONG err;
4025

4026 4027 4028
    err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
    ok(err == ERROR_SUCCESS || err == ERROR_FILE_NOT_FOUND, "got %d\n", err);

4029 4030
    test_import_wstr("\xef\xbb\xbf  Windows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n\n", &r);
4031
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
4032

4033
    open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
4034 4035 4036 4037

    test_import_wstr("\xef\xbb\xbf  Windows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine1a\"=\"Value\"\n\n", &r);
4038
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
4039
    verify_reg(hkey, "Wine1a", REG_SZ, "Value", 6, 0);
4040 4041 4042 4043

    test_import_wstr("\xef\xbb\xbf\tWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine1b\"=\"Value\"\n\n", &r);
4044
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
4045
    verify_reg(hkey, "Wine1b", REG_SZ, "Value", 6, 0);
4046 4047 4048 4049

    test_import_wstr("\xef\xbb\xbf \t Windows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine1c\"=\"Value\"\n\n", &r);
4050
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
4051
    verify_reg(hkey, "Wine1c", REG_SZ, "Value", 6, 0);
4052 4053 4054 4055

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "  [HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine2a\"=\"Value\"\n\n", &r);
4056
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
4057
    verify_reg(hkey, "Wine2a", REG_SZ, "Value", 6, 0);
4058 4059 4060 4061

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "\t[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine2b\"=\"Value\"\n\n", &r);
4062
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
4063
    verify_reg(hkey, "Wine2b", REG_SZ, "Value", 6, 0);
4064 4065 4066 4067

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                    " \t [HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                    "\"Wine2c\"=\"Value\"\n\n", &r);
4068
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
4069
    verify_reg(hkey, "Wine2c", REG_SZ, "Value", 6, 0);
4070 4071 4072 4073

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "  \"Wine3a\"=\"Two leading spaces\"\n\n", &r);
4074
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
4075
    verify_reg(hkey, "Wine3a", REG_SZ, "Two leading spaces", 19, 0);
4076 4077 4078 4079

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\t\"Wine3b\"=\"One leading tab\"\n\n", &r);
4080
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
4081
    verify_reg(hkey, "Wine3b", REG_SZ, "One leading tab", 16, 0);
4082 4083 4084 4085

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     " \t \"Wine3c\"=\"Space, tab, space\"\n\n", &r);
4086
    ok(r == REG_EXIT_SUCCESS, "got exit code %u, expected 0\n", r);
4087
    verify_reg(hkey, "Wine3c", REG_SZ, "Space, tab, space", 18, 0);
4088 4089 4090 4091 4092 4093 4094 4095 4096

    test_import_wstr("\xef\xbb\xbf                    Windows Registry Editor Version 5.00\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,00,69,00,6e,00,65,00,20,00,\\\n"
                     "        63,00,6f,00,6e,00,\\;comment\n"
                     "\t\t\t\t63,00,61,00,74,00,\\;comment\n"
                     "  \t65,00,6e,00,61,00,74,00,69,00,6f,00,6e,00,00,00,00,00\n\n", &r);
4097
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4098
    verify_reg(hkey, "Wine4a", REG_SZ, "Tab and four spaces", 20, 0);
4099
    dword = 0x112233;
4100
    verify_reg(hkey, "Wine4b", REG_DWORD, &dword, sizeof(dword), 0);
4101
    verify_reg(hkey, "Wine4c", REG_MULTI_SZ, "Line concatenation\0", 20, 0);
4102 4103 4104 4105 4106 4107 4108

    test_import_wstr("\xef\xbb\xbf    Windows Registry Editor Version 5.00\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", &r);
4109
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4110 4111 4112 4113
    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);
4114 4115 4116 4117 4118 4119

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"  Wine6a\"=\"Leading spaces\"\n"
                     "\"\t\tWine6b\"=\"Leading tabs\"\n"
                     "  \"  Wine6c  \"  =  \"  Spaces everywhere  \"  \n\n", &r);
4120
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4121 4122 4123
    verify_reg(hkey, "  Wine6a", REG_SZ, "Leading spaces", 15, 0);
    verify_reg(hkey, "\t\tWine6b", REG_SZ, "Leading tabs", 13, 0);
    verify_reg(hkey, "  Wine6c  ", REG_SZ, "  Spaces everywhere  ", 22, 0);
4124 4125 4126 4127 4128

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine7a\"=\"    Four spaces in the data\"\n"
                     "\"Wine7b\"=\"\t\tTwo tabs in the data\"\n\n", &r);
4129
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4130 4131
    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);
4132 4133 4134 4135 4136

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine8a\"=\"Trailing spaces\"    \n"
                     "\"Wine8b\"=\"Trailing tabs and spaces\"\t  \t\n\n", &r);
4137
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4138 4139
    verify_reg(hkey, "Wine8a", REG_SZ, "Trailing spaces", 16, 0);
    verify_reg(hkey, "Wine8b", REG_SZ, "Trailing tabs and spaces", 25, 0);
4140

4141 4142 4143 4144
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine9a\"=dword:  00000008\n"
                     "\"Wine9b\"=dword:\t\t00000008\n\n", &r);
4145
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4146
    dword = 0x00000008;
4147 4148
    verify_reg(hkey, "Wine9a", REG_DWORD, &dword, sizeof(dword), 0);
    verify_reg(hkey, "Wine9b", REG_DWORD, &dword, sizeof(dword), 0);
4149

4150 4151 4152
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "@  =  \"Test Value\"\n\n", &r);
4153
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4154
    verify_reg(hkey, "", REG_SZ, "Test Value", 11, 0);
4155 4156 4157 4158

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\t@\t=\tdword:\t00000008\t\n\n", &r);
4159
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4160
    verify_reg(hkey, "", REG_DWORD, &dword, sizeof(DWORD), 0);
4161

4162
    err = RegCloseKey(hkey);
4163
    ok(err == ERROR_SUCCESS, "RegCloseKey failed: got %d, expected 0\n", err);
4164

4165
    delete_key(HKEY_CURRENT_USER, KEY_BASE);
4166 4167
}

4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188
static void test_import_31(void)
{
    LONG err;
    HKEY hkey;
    DWORD r;

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

    /* Check if reg.exe is running with elevated privileges */
    err = RegCreateKeyExA(HKEY_CLASSES_ROOT, KEY_BASE, 0, NULL, REG_OPTION_NON_VOLATILE,
                          KEY_READ|KEY_SET_VALUE, NULL, &hkey, NULL);
    if (err == ERROR_ACCESS_DENIED)
    {
        win_skip("reg.exe is not running with elevated privileges; "
                 "skipping Windows 3.1 import tests\n");
        return;
    }

    /* Test simple value */
    test_import_str("REGEDIT\r\n"
4189 4190 4191
                    "HKEY_CLASSES_ROOT\\" KEY_BASE " = Value0\r\n", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_reg(hkey, "", REG_SZ, "Value0", 7, 0);
4192 4193 4194 4195

    /* Test proper handling of spaces and equals signs */
    test_import_str("REGEDIT\r\n"
                    "HKEY_CLASSES_ROOT\\" KEY_BASE " =Value1\r\n", &r);
4196 4197
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_reg(hkey, "", REG_SZ, "Value1", 7, 0);
4198 4199 4200

    test_import_str("REGEDIT\r\n"
                    "HKEY_CLASSES_ROOT\\" KEY_BASE " =  Value2\r\n", &r);
4201 4202
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_reg(hkey, "", REG_SZ, " Value2", 8, 0);
4203 4204 4205

    test_import_str("REGEDIT\r\n"
                    "HKEY_CLASSES_ROOT\\" KEY_BASE " = Value3 \r\n", &r);
4206 4207
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_reg(hkey, "", REG_SZ, "Value3 ", 8, 0);
4208 4209 4210

    test_import_str("REGEDIT\r\n"
                    "HKEY_CLASSES_ROOT\\" KEY_BASE " Value4\r\n", &r);
4211 4212
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_reg(hkey, "", REG_SZ, "Value4", 7, 0);
4213 4214 4215

    test_import_str("REGEDIT\r\n"
                    "HKEY_CLASSES_ROOT\\" KEY_BASE "  Value5\r\n", &r);
4216 4217
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_reg(hkey, "", REG_SZ, "Value5", 7, 0);
4218 4219 4220

    test_import_str("REGEDIT\r\n"
                    "HKEY_CLASSES_ROOT\\" KEY_BASE "\r\n", &r);
4221 4222
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_reg(hkey, "", REG_SZ, "", 1, 0);
4223 4224 4225

    test_import_str("REGEDIT\r\n"
                    "HKEY_CLASSES_ROOT\\" KEY_BASE "  \r\n", &r);
4226 4227
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_reg(hkey, "", REG_SZ, "", 1, 0);
4228 4229 4230

    test_import_str("REGEDIT\r\n"
                    "HKEY_CLASSES_ROOT\\" KEY_BASE " = No newline", &r);
4231 4232
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
    verify_reg(hkey, "", REG_SZ, "No newline", 11, 0);
4233

4234
    delete_value(hkey, NULL);
4235 4236 4237 4238

    /* Test character validity at the start of the line */
    test_import_str("REGEDIT\r\n"
                    " HKEY_CLASSES_ROOT\\" KEY_BASE " = Value1a\r\n", &r);
4239
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4240 4241 4242 4243
    verify_reg_nonexist(hkey, "");

    test_import_str("REGEDIT\r\n"
                    "  HKEY_CLASSES_ROOT\\" KEY_BASE " = Value1b\r\n", &r);
4244
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4245 4246 4247 4248
    verify_reg_nonexist(hkey, "");

    test_import_str("REGEDIT\r\n"
                    "\tHKEY_CLASSES_ROOT\\" KEY_BASE " = Value1c\r\n", &r);
4249
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4250 4251 4252 4253
    verify_reg_nonexist(hkey, "");

    test_import_str("REGEDIT\r\n"
                    ";HKEY_CLASSES_ROOT\\" KEY_BASE " = Value2a\r\n", &r);
4254
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4255 4256 4257 4258
    verify_reg_nonexist(hkey, "");

    test_import_str("REGEDIT\r\n"
                    "#HKEY_CLASSES_ROOT\\" KEY_BASE " = Value2b\r\n", &r);
4259
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4260 4261 4262 4263 4264
    verify_reg_nonexist(hkey, "");

    /* Test case sensitivity */
    test_import_str("REGEDIT\r\n"
                    "hkey_classes_root\\" KEY_BASE " = Value3a\r\n", &r);
4265
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4266 4267 4268 4269
    verify_reg_nonexist(hkey, "");

    test_import_str("REGEDIT\r\n"
                    "hKEY_CLASSES_ROOT\\" KEY_BASE " = Value3b\r\n", &r);
4270
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4271 4272 4273 4274
    verify_reg_nonexist(hkey, "");

    test_import_str("REGEDIT\r\n"
                    "Hkey_Classes_Root\\" KEY_BASE " = Value3c\r\n", &r);
4275
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4276 4277 4278 4279
    verify_reg_nonexist(hkey, "");

    RegCloseKey(hkey);

4280
    delete_key(HKEY_CLASSES_ROOT, KEY_BASE);
4281 4282
}

4283 4284
#define compare_export(f,e,todo) compare_export_(__LINE__,f,e,todo)
static BOOL compare_export_(unsigned line, const char *filename, const char *expected, DWORD todo)
4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311
{
    FILE *fp;
    long file_size;
    WCHAR *fbuf = NULL, *wstr = NULL;
    size_t len;
    BOOL ret = FALSE;

    fp = fopen(filename, "rb");
    if (!fp) return FALSE;

    if (fseek(fp, 0, SEEK_END)) goto error;
    file_size = ftell(fp);
    if (file_size == -1) goto error;
    rewind(fp);

    fbuf = HeapAlloc(GetProcessHeap(), 0, file_size + sizeof(WCHAR));
    if (!fbuf) goto error;

    fread(fbuf, file_size, 1, fp);
    fbuf[file_size/sizeof(WCHAR)] = 0;
    fclose(fp);

    len = MultiByteToWideChar(CP_UTF8, 0, expected, -1, NULL, 0);
    wstr = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
    if (!wstr) goto exit;
    MultiByteToWideChar(CP_UTF8, 0, expected, -1, wstr, len);

4312 4313
    todo_wine_if (todo & TODO_REG_COMPARE)
        lok(!lstrcmpW(fbuf, wstr), "export data does not match expected data\n");
4314 4315

    ret = DeleteFileA(filename);
4316
    lok(ret, "DeleteFile failed: %u\n", GetLastError());
4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327

exit:
    HeapFree(GetProcessHeap(), 0, fbuf);
    HeapFree(GetProcessHeap(), 0, wstr);
    return ret;

error:
    fclose(fp);
    return FALSE;
}

4328 4329 4330
static void test_export(void)
{
    LONG err;
4331
    DWORD r, dword;
4332
    HKEY hkey, subkey;
4333
    BYTE hex[4];
4334 4335 4336 4337 4338 4339 4340 4341 4342 4343

    const char *empty_key_test =
        "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
        "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n\r\n";

    const char *simple_test =
        "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
        "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
        "\"DWORD\"=dword:00000100\r\n"
        "\"String\"=\"Your text here...\"\r\n\r\n";
4344

4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370
    const char *complex_test =
        "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
        "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
        "\"DWORD\"=dword:00000100\r\n"
        "\"String\"=\"Your text here...\"\r\n\r\n"
        "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1]\r\n"
        "\"Binary\"=hex:11,22,33,44\r\n"
        "\"Undefined hex\"=hex(100):25,50,41,54,48,25,00\r\n\r\n"
        "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a]\r\n"
        "\"double\\\"quote\"=\"\\\"Hello, World!\\\"\"\r\n"
        "\"single'quote\"=dword:00000008\r\n\r\n"
        "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2a\\Subkey2b]\r\n"
        "@=\"Default value name\"\r\n"
        "\"Multiple strings\"=hex(7):4c,00,69,00,6e,00,65,00,31,00,00,00,4c,00,69,00,6e,\\\r\n"
        "  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"
        "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey3a]\r\n"
        "\"Backslash\"=\"Use \\\\\\\\ to escape a backslash\"\r\n\r\n"
        "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey3a\\Subkey3b]\r\n\r\n"
        "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey3a\\Subkey3b\\Subkey3c]\r\n"
        "\"String expansion\"=hex(2):25,00,48,00,4f,00,4d,00,45,00,25,00,5c,00,25,00,50,\\\r\n"
        "  00,41,00,54,00,48,00,25,00,00,00\r\n"
        "\"Zero data type\"=hex(0):56,61,6c,75,65,00\r\n\r\n"
        "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey4]\r\n"
        "@=dword:12345678\r\n"
        "\"43981\"=hex(abcd):56,61,6c,75,65,00\r\n\r\n";

4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382
    const char *key_order_test =
        "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
        "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n\r\n"
        "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey1]\r\n\r\n"
        "[HKEY_CURRENT_USER\\" KEY_BASE "\\Subkey2]\r\n\r\n";

    const char *value_order_test =
        "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
        "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
        "\"Value 2\"=\"I was added first!\"\r\n"
        "\"Value 1\"=\"I was added second!\"\r\n\r\n";

4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408
    const char *empty_hex_test =
        "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
        "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
        "\"Wine1a\"=hex(0):\r\n"
        "\"Wine1b\"=\"\"\r\n"
        "\"Wine1c\"=hex(2):\r\n"
        "\"Wine1d\"=hex:\r\n"
        "\"Wine1e\"=hex(4):\r\n"
        "\"Wine1f\"=hex(7):\r\n"
        "\"Wine1g\"=hex(100):\r\n"
        "\"Wine1h\"=hex(abcd):\r\n\r\n";

    const char *empty_hex_test2 =
        "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
        "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
        "\"Wine2a\"=\"\"\r\n"
        "\"Wine2b\"=hex:\r\n"
        "\"Wine2c\"=hex(4):\r\n\r\n";

    const char *hex_types_test =
        "\xef\xbb\xbfWindows Registry Editor Version 5.00\r\n\r\n"
        "[HKEY_CURRENT_USER\\" KEY_BASE "]\r\n"
        "\"Wine3a\"=\"Value\"\r\n"
        "\"Wine3b\"=hex:12,34,56,78\r\n"
        "\"Wine3c\"=dword:10203040\r\n\r\n";

4409 4410 4411 4412 4413 4414 4415
    err = RegDeleteKeyA(HKEY_CURRENT_USER, KEY_BASE);
    ok(err == ERROR_SUCCESS || err == ERROR_FILE_NOT_FOUND, "got %d\n", err);

    run_reg_exe("reg export", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

    run_reg_exe("reg export /?", &r);
4416
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4417

4418 4419 4420 4421
    run_reg_exe("reg export /h", &r);
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);

    run_reg_exe("reg export -H", &r);
4422
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4423

4424
    run_reg_exe("reg export \\\\remote-pc\\HKLM\\Wine file.reg", &r);
4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

    run_reg_exe("reg export HKEY_DYN_DATA file.reg", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

    run_reg_exe("reg export HKDD file.reg", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

    run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE, &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

    run_reg_exe("reg export file.reg", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

    run_reg_exe("reg export file.reg HKEY_CURRENT_USER\\" KEY_BASE, &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

    run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE, &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

    run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);

    run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg file2.reg", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
4450 4451 4452 4453 4454

    /* Test registry export with an empty key */
    add_key(HKEY_CURRENT_USER, KEY_BASE, &hkey);

    run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg", &r);
4455
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4456

4457 4458
    run_reg_exe("reg export /y HKEY_CURRENT_USER\\" KEY_BASE " file.reg", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
4459

4460 4461
    run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " /y file.reg", &r);
    ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
4462

4463 4464 4465
    run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r);
    ok(r == REG_EXIT_SUCCESS || broken(r == REG_EXIT_FAILURE), /* winxp */
       "got exit code %d, expected 0\n", r);
4466

4467
    ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n");
4468

4469 4470 4471 4472 4473 4474
    /* Test registry export with a simple data structure */
    dword = 0x100;
    add_value(hkey, "DWORD", REG_DWORD, &dword, sizeof(dword));
    add_value(hkey, "String", REG_SZ, "Your text here...", 18);

    run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg", &r);
4475
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4476
    ok(compare_export("file.reg", simple_test, 0), "compare_export() failed\n");
4477

4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509
    /* Test registry export with a complex data structure */
    add_key(hkey, "Subkey1", &subkey);
    add_value(subkey, "Binary", REG_BINARY, "\x11\x22\x33\x44", 4);
    add_value(subkey, "Undefined hex", 0x100, "%PATH%", 7);
    RegCloseKey(subkey);

    add_key(hkey, "Subkey2a", &subkey);
    add_value(subkey, "double\"quote", REG_SZ, "\"Hello, World!\"", 16);
    dword = 0x8;
    add_value(subkey, "single'quote", REG_DWORD, &dword, sizeof(dword));
    RegCloseKey(subkey);

    add_key(hkey, "Subkey2a\\Subkey2b", &subkey);
    add_value(subkey, NULL, REG_SZ, "Default value name", 19);
    add_value(subkey, "Multiple strings", REG_MULTI_SZ, "Line1\0Line2\0Line3\0", 19);
    RegCloseKey(subkey);

    add_key(hkey, "Subkey3a", &subkey);
    add_value(subkey, "Backslash", REG_SZ, "Use \\\\ to escape a backslash", 29);
    RegCloseKey(subkey);

    add_key(hkey, "Subkey3a\\Subkey3b\\Subkey3c", &subkey);
    add_value(subkey, "String expansion", REG_EXPAND_SZ, "%HOME%\\%PATH%", 14);
    add_value(subkey, "Zero data type", REG_NONE, "Value", 6);
    RegCloseKey(subkey);

    add_key(hkey, "Subkey4", &subkey);
    dword = 0x12345678;
    add_value(subkey, NULL, REG_DWORD, &dword, sizeof(dword));
    add_value(subkey, "43981", 0xabcd, "Value", 6);
    RegCloseKey(subkey);

4510 4511
    RegCloseKey(hkey);

4512
    run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg", &r);
4513
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4514
    ok(compare_export("file.reg", complex_test, 0), "compare_export() failed\n");
4515 4516 4517

    err = delete_tree(HKEY_CURRENT_USER, KEY_BASE);
    ok(err == ERROR_SUCCESS, "delete_tree() failed: %d\n", err);
4518 4519 4520 4521 4522 4523 4524 4525 4526

    /* Test the export order of registry keys */
    add_key(HKEY_CURRENT_USER, KEY_BASE, &hkey);
    add_key(hkey, "Subkey2", &subkey);
    RegCloseKey(subkey);
    add_key(hkey, "Subkey1", &subkey);
    RegCloseKey(subkey);

    run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg", &r);
4527
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4528
    ok(compare_export("file.reg", key_order_test, 0), "compare_export() failed\n");
4529

4530 4531
    delete_key(hkey, "Subkey1");
    delete_key(hkey, "Subkey2");
4532 4533 4534 4535 4536 4537 4538 4539 4540 4541

    /* Test the export order of registry values. Windows exports registry values
     * in order of creation; Wine uses alphabetical order.
     */
    add_value(hkey, "Value 2", REG_SZ, "I was added first!", 19);
    add_value(hkey, "Value 1", REG_SZ, "I was added second!", 20);

    RegCloseKey(hkey);

    run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg", &r);
4542
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4543
    ok(compare_export("file.reg", value_order_test, TODO_REG_COMPARE), "compare_export() failed\n");
4544

4545
    delete_key(HKEY_CURRENT_USER, KEY_BASE);
4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559

    /* Test registry export with empty hex data */
    add_key(HKEY_CURRENT_USER, KEY_BASE, &hkey);
    add_value(hkey, "Wine1a", REG_NONE, NULL, 0);
    add_value(hkey, "Wine1b", REG_SZ, NULL, 0);
    add_value(hkey, "Wine1c", REG_EXPAND_SZ, NULL, 0);
    add_value(hkey, "Wine1d", REG_BINARY, NULL, 0);
    add_value(hkey, "Wine1e", REG_DWORD, NULL, 0);
    add_value(hkey, "Wine1f", REG_MULTI_SZ, NULL, 0);
    add_value(hkey, "Wine1g", 0x100, NULL, 0);
    add_value(hkey, "Wine1h", 0xabcd, NULL, 0);
    RegCloseKey(hkey);

    run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg", &r);
4560
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4561
    ok(compare_export("file.reg", empty_hex_test, 0), "compare_export() failed\n");
4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577

    delete_key(HKEY_CURRENT_USER, KEY_BASE);

    /* Test registry export after importing alternative registry data types */
    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine2a\"=hex(1):\n"
                     "\"Wine2b\"=hex(3):\n"
                     "\"Wine2c\"=hex(4):\n\n", &r);
    open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
    verify_reg(hkey, "Wine2a", REG_SZ, NULL, 0, 0);
    verify_reg(hkey, "Wine2b", REG_BINARY, NULL, 0, 0);
    verify_reg(hkey, "Wine2c", REG_DWORD, NULL, 0, 0);
    RegCloseKey(hkey);

    run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg", &r);
4578
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4579
    ok(compare_export("file.reg", empty_hex_test2, 0), "compare_export() failed\n");
4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596

    delete_key(HKEY_CURRENT_USER, KEY_BASE);

    test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n"
                     "[HKEY_CURRENT_USER\\" KEY_BASE "]\n"
                     "\"Wine3a\"=hex(1):56,00,61,00,6c,00,75,00,65,00,00,00\n"
                     "\"Wine3b\"=hex(3):12,34,56,78\n"
                     "\"Wine3c\"=hex(4):40,30,20,10\n\n", &r);
    open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey);
    verify_reg(hkey, "Wine3a", REG_SZ, "Value", 6, 0);
    memcpy(hex, "\x12\x34\x56\x78", 4);
    verify_reg(hkey, "Wine3b", REG_BINARY, hex, 4, 0);
    dword = 0x10203040;
    verify_reg(hkey, "Wine3c", REG_DWORD, &dword, sizeof(dword), 0);
    RegCloseKey(hkey);

    run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg", &r);
4597
    ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
4598
    ok(compare_export("file.reg", hex_types_test, 0), "compare_export() failed\n");
4599 4600

    delete_key(HKEY_CURRENT_USER, KEY_BASE);
4601 4602
}

4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613
START_TEST(reg)
{
    DWORD r;
    if (!run_reg_exe("reg.exe /?", &r)) {
        win_skip("reg.exe not available, skipping reg.exe tests\n");
        return;
    }

    test_add();
    test_delete();
    test_query();
4614
    test_v_flags();
4615
    test_import();
4616
    test_unicode_import();
4617
    test_import_with_whitespace();
4618
    test_unicode_import_with_whitespace();
4619
    test_import_31();
4620
    test_export();
4621
}