1295a04dfSwinesync /* 2295a04dfSwinesync * Copyright 2021 Hugh McMaster 3295a04dfSwinesync * 4295a04dfSwinesync * This library is free software; you can redistribute it and/or 5295a04dfSwinesync * modify it under the terms of the GNU Lesser General Public 6295a04dfSwinesync * License as published by the Free Software Foundation; either 7295a04dfSwinesync * version 2.1 of the License, or (at your option) any later version. 8295a04dfSwinesync * 9295a04dfSwinesync * This library is distributed in the hope that it will be useful, 10295a04dfSwinesync * but WITHOUT ANY WARRANTY; without even the implied warranty of 11295a04dfSwinesync * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12295a04dfSwinesync * Lesser General Public License for more details. 13295a04dfSwinesync * 14295a04dfSwinesync * You should have received a copy of the GNU Lesser General Public 15295a04dfSwinesync * License along with this library; if not, write to the Free Software 16295a04dfSwinesync * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 17295a04dfSwinesync */ 18295a04dfSwinesync 19295a04dfSwinesync #include "reg_test.h" 20295a04dfSwinesync 211aea6bdfSwinesync #define COPY_SRC KEY_WINE "\\reg_copy" 22295a04dfSwinesync 231aea6bdfSwinesync static void test_command_syntax(void) 24295a04dfSwinesync { 25295a04dfSwinesync DWORD r; 26295a04dfSwinesync 27295a04dfSwinesync run_reg_exe("reg copy", &r); 28295a04dfSwinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 29295a04dfSwinesync 30295a04dfSwinesync run_reg_exe("reg copy /?", &r); 31181292dcSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 32295a04dfSwinesync 33295a04dfSwinesync run_reg_exe("reg copy /h", &r); 34181292dcSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 35295a04dfSwinesync 36295a04dfSwinesync run_reg_exe("reg copy -H", &r); 37181292dcSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 38295a04dfSwinesync 39295a04dfSwinesync run_reg_exe("reg copy /? /f", &r); 4067493a40Swinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 41295a04dfSwinesync 42295a04dfSwinesync run_reg_exe("reg copy /h /f", &r); 4367493a40Swinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 44295a04dfSwinesync 45295a04dfSwinesync run_reg_exe("reg copy /? /s", &r); 4667493a40Swinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 47295a04dfSwinesync 48295a04dfSwinesync run_reg_exe("reg copy /h /s", &r); 4967493a40Swinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 50295a04dfSwinesync 51295a04dfSwinesync run_reg_exe("reg copy /f", &r); 52295a04dfSwinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 53295a04dfSwinesync 54295a04dfSwinesync run_reg_exe("reg copy /s", &r); 55295a04dfSwinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 56295a04dfSwinesync 57295a04dfSwinesync run_reg_exe("reg copy /s /f", &r); 58295a04dfSwinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 59295a04dfSwinesync 60295a04dfSwinesync run_reg_exe("reg copy /f /s", &r); 61295a04dfSwinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 62295a04dfSwinesync 631aea6bdfSwinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " /f", &r); 64295a04dfSwinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 65295a04dfSwinesync 661aea6bdfSwinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " foo /f", &r); 67295a04dfSwinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 68295a04dfSwinesync 691aea6bdfSwinesync run_reg_exe("reg copy /f HKCU\\" COPY_SRC " HKCU\\" KEY_BASE, &r); 70295a04dfSwinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 71295a04dfSwinesync 721aea6bdfSwinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " /f HKCU\\" KEY_BASE, &r); 73295a04dfSwinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 74295a04dfSwinesync 751aea6bdfSwinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " /s HKCU\\" KEY_BASE, &r); 76295a04dfSwinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 77295a04dfSwinesync 781aea6bdfSwinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /a", &r); 79295a04dfSwinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 80295a04dfSwinesync 811aea6bdfSwinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f /a", &r); 82295a04dfSwinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 83295a04dfSwinesync 841aea6bdfSwinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\", &r); 85295a04dfSwinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 86295a04dfSwinesync 871aea6bdfSwinesync /* Source and destination keys are the same */ 881aea6bdfSwinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" COPY_SRC, &r); 89295a04dfSwinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 90295a04dfSwinesync 91f27a0866Swinesync run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" COPY_SRC, &r); 92f27a0866Swinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 93f27a0866Swinesync 94f27a0866Swinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" COPY_SRC "\\", &r); 95f27a0866Swinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 96f27a0866Swinesync 97f27a0866Swinesync run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" COPY_SRC "\\", &r); 98f27a0866Swinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 99f27a0866Swinesync 1001aea6bdfSwinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" COPY_SRC " /f", &r); 101295a04dfSwinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 102295a04dfSwinesync 103f27a0866Swinesync run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" COPY_SRC " /f", &r); 104f27a0866Swinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 105f27a0866Swinesync 106f27a0866Swinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" COPY_SRC "\\ /f", &r); 107f27a0866Swinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 108f27a0866Swinesync 109f27a0866Swinesync run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" COPY_SRC "\\ /f", &r); 110f27a0866Swinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 111f27a0866Swinesync 1121aea6bdfSwinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" COPY_SRC " /s /f", &r); 113295a04dfSwinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 114f27a0866Swinesync 115f27a0866Swinesync run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" COPY_SRC " /s /f", &r); 116f27a0866Swinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 117f27a0866Swinesync 118f27a0866Swinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" COPY_SRC "\\ /s /f", &r); 119f27a0866Swinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 120f27a0866Swinesync 121f27a0866Swinesync run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" COPY_SRC "\\ /s /f", &r); 122f27a0866Swinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 123295a04dfSwinesync } 124295a04dfSwinesync 125d40c4ec1Swinesync static void test_copy_empty_key(void) 126d40c4ec1Swinesync { 127d40c4ec1Swinesync DWORD r; 128d40c4ec1Swinesync 12944c2f0d9Swinesync delete_tree(HKEY_CURRENT_USER, COPY_SRC, 0); 13044c2f0d9Swinesync delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0); 131d40c4ec1Swinesync 13277b2d21eSwinesync add_key(HKEY_CURRENT_USER, COPY_SRC, 0, NULL); 133d40c4ec1Swinesync 134d40c4ec1Swinesync 135d40c4ec1Swinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r); 136da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 137cd3b6fe7Swinesync verify_key(HKEY_CURRENT_USER, KEY_BASE, 0); 138d40c4ec1Swinesync 139d40c4ec1Swinesync run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg", &r); 140da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 141da2d23fbSwinesync ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n"); 142d40c4ec1Swinesync 1430ea0084cSwinesync delete_key(HKEY_CURRENT_USER, KEY_BASE, 0); 144d40c4ec1Swinesync 145d40c4ec1Swinesync 146d40c4ec1Swinesync run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" KEY_BASE " /f", &r); 147da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 148cd3b6fe7Swinesync verify_key(HKEY_CURRENT_USER, KEY_BASE, 0); 149d40c4ec1Swinesync 150d40c4ec1Swinesync run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg", &r); 151da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 152da2d23fbSwinesync ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n"); 153d40c4ec1Swinesync 1540ea0084cSwinesync delete_key(HKEY_CURRENT_USER, KEY_BASE, 0); 155d40c4ec1Swinesync 156d40c4ec1Swinesync 157d40c4ec1Swinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE "\\ /f", &r); 158da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 159cd3b6fe7Swinesync verify_key(HKEY_CURRENT_USER, KEY_BASE, 0); 160d40c4ec1Swinesync 161d40c4ec1Swinesync run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg", &r); 162da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 163da2d23fbSwinesync ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n"); 164d40c4ec1Swinesync 1650ea0084cSwinesync delete_key(HKEY_CURRENT_USER, KEY_BASE, 0); 166d40c4ec1Swinesync 167d40c4ec1Swinesync 168d40c4ec1Swinesync run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" KEY_BASE "\\ /f", &r); 169da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 170cd3b6fe7Swinesync verify_key(HKEY_CURRENT_USER, KEY_BASE, 0); 171d40c4ec1Swinesync 172d40c4ec1Swinesync run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg", &r); 173da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 174da2d23fbSwinesync ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n"); 175d40c4ec1Swinesync 176d40c4ec1Swinesync 177d40c4ec1Swinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /s /f", &r); 178da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 179cd3b6fe7Swinesync verify_key(HKEY_CURRENT_USER, KEY_BASE, 0); 180d40c4ec1Swinesync 181d40c4ec1Swinesync run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg", &r); 182da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 183da2d23fbSwinesync ok(compare_export("file.reg", empty_key_test, 0), "compare_export() failed\n"); 184d40c4ec1Swinesync } 185d40c4ec1Swinesync 186d40c4ec1Swinesync static void test_copy_simple_data(void) 187d40c4ec1Swinesync { 188d40c4ec1Swinesync HKEY hkey; 189d40c4ec1Swinesync DWORD r, dword; 190d40c4ec1Swinesync 19144c2f0d9Swinesync delete_tree(HKEY_CURRENT_USER, COPY_SRC, 0); 19244c2f0d9Swinesync delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0); 193d40c4ec1Swinesync 19477b2d21eSwinesync add_key(HKEY_CURRENT_USER, COPY_SRC, 0, &hkey); 195d40c4ec1Swinesync 196d40c4ec1Swinesync dword = 0x100; 197d40c4ec1Swinesync add_value(hkey, "DWORD", REG_DWORD, &dword, sizeof(dword)); 198d40c4ec1Swinesync add_value(hkey, "String", REG_SZ, "Your text here...", 18); 199d40c4ec1Swinesync close_key(hkey); 200d40c4ec1Swinesync 201d40c4ec1Swinesync 202d40c4ec1Swinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r); 203da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 204cd3b6fe7Swinesync verify_key(HKEY_CURRENT_USER, KEY_BASE, 0); 205d40c4ec1Swinesync 206d40c4ec1Swinesync run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r); 207da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 208da2d23fbSwinesync ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n"); 209d40c4ec1Swinesync 2100ea0084cSwinesync delete_key(HKEY_CURRENT_USER, KEY_BASE, 0); 211d40c4ec1Swinesync 212d40c4ec1Swinesync 213d40c4ec1Swinesync run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" KEY_BASE " /f", &r); 214da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 215cd3b6fe7Swinesync verify_key(HKEY_CURRENT_USER, KEY_BASE, 0); 216d40c4ec1Swinesync 217d40c4ec1Swinesync run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r); 218da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 219da2d23fbSwinesync ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n"); 220d40c4ec1Swinesync 2210ea0084cSwinesync delete_key(HKEY_CURRENT_USER, KEY_BASE, 0); 222d40c4ec1Swinesync 223d40c4ec1Swinesync 224d40c4ec1Swinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE "\\ /f", &r); 225da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 226cd3b6fe7Swinesync verify_key(HKEY_CURRENT_USER, KEY_BASE, 0); 227d40c4ec1Swinesync 228d40c4ec1Swinesync run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r); 229da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 230da2d23fbSwinesync ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n"); 231d40c4ec1Swinesync 2320ea0084cSwinesync delete_key(HKEY_CURRENT_USER, KEY_BASE, 0); 233d40c4ec1Swinesync 234d40c4ec1Swinesync 235d40c4ec1Swinesync run_reg_exe("reg copy HKCU\\" COPY_SRC "\\ HKCU\\" KEY_BASE "\\ /f", &r); 236da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 237cd3b6fe7Swinesync verify_key(HKEY_CURRENT_USER, KEY_BASE, 0); 238d40c4ec1Swinesync 239d40c4ec1Swinesync run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r); 240da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 241da2d23fbSwinesync ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n"); 242d40c4ec1Swinesync 243d40c4ec1Swinesync 244d40c4ec1Swinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /s /f", &r); 245da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 246cd3b6fe7Swinesync verify_key(HKEY_CURRENT_USER, KEY_BASE, 0); 247d40c4ec1Swinesync 248d40c4ec1Swinesync run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r); 249da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 250da2d23fbSwinesync ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n"); 251d40c4ec1Swinesync } 252d40c4ec1Swinesync 2536ae4684dSwinesync static void test_copy_complex_data(void) 2546ae4684dSwinesync { 2556ae4684dSwinesync HKEY hkey, subkey; 2566ae4684dSwinesync DWORD r, dword; 2576ae4684dSwinesync 25844c2f0d9Swinesync delete_tree(HKEY_CURRENT_USER, COPY_SRC, 0); 25944c2f0d9Swinesync delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0); 2606ae4684dSwinesync 26177b2d21eSwinesync add_key(HKEY_CURRENT_USER, COPY_SRC, 0, &hkey); 2626ae4684dSwinesync 2636ae4684dSwinesync dword = 0x100; 2646ae4684dSwinesync add_value(hkey, "DWORD", REG_DWORD, &dword, sizeof(dword)); 2656ae4684dSwinesync add_value(hkey, "String", REG_SZ, "Your text here...", 18); 2666ae4684dSwinesync 26777b2d21eSwinesync add_key(hkey, "Subkey1", 0, &subkey); 2686ae4684dSwinesync add_value(subkey, "Binary", REG_BINARY, "\x11\x22\x33\x44", 4); 2696ae4684dSwinesync add_value(subkey, "Undefined hex", 0x100, "%PATH%", 7); 2706ae4684dSwinesync close_key(subkey); 2716ae4684dSwinesync 27277b2d21eSwinesync add_key(hkey, "Subkey2a", 0, &subkey); 2736ae4684dSwinesync add_value(subkey, "double\"quote", REG_SZ, "\"Hello, World!\"", 16); 2746ae4684dSwinesync dword = 0x8; 2756ae4684dSwinesync add_value(subkey, "single'quote", REG_DWORD, &dword, sizeof(dword)); 2766ae4684dSwinesync close_key(subkey); 2776ae4684dSwinesync 27877b2d21eSwinesync add_key(hkey, "Subkey2a\\Subkey2b", 0, &subkey); 2796ae4684dSwinesync add_value(subkey, NULL, REG_SZ, "Default value name", 19); 2806ae4684dSwinesync add_value(subkey, "Multiple strings", REG_MULTI_SZ, "Line1\0Line2\0Line3\0", 19); 2816ae4684dSwinesync close_key(subkey); 2826ae4684dSwinesync 28377b2d21eSwinesync add_key(hkey, "Subkey3a", 0, &subkey); 2846ae4684dSwinesync add_value(subkey, "Backslash", REG_SZ, "Use \\\\ to escape a backslash", 29); 2856ae4684dSwinesync close_key(subkey); 2866ae4684dSwinesync 28777b2d21eSwinesync add_key(hkey, "Subkey3a\\Subkey3b\\Subkey3c", 0, &subkey); 2886ae4684dSwinesync add_value(subkey, "String expansion", REG_EXPAND_SZ, "%HOME%\\%PATH%", 14); 2896ae4684dSwinesync add_value(subkey, "Zero data type", REG_NONE, "Value", 6); 2906ae4684dSwinesync close_key(subkey); 2916ae4684dSwinesync 29277b2d21eSwinesync add_key(hkey, "Subkey4", 0, &subkey); 2936ae4684dSwinesync dword = 0x12345678; 2946ae4684dSwinesync add_value(subkey, NULL, REG_DWORD, &dword, sizeof(dword)); 2956ae4684dSwinesync add_value(subkey, "43981", 0xabcd, "Value", 6); 2966ae4684dSwinesync close_key(subkey); 2976ae4684dSwinesync 2986ae4684dSwinesync close_key(hkey); 2996ae4684dSwinesync 3006ae4684dSwinesync /* Copy values only */ 3016ae4684dSwinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r); 302da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 303cd3b6fe7Swinesync verify_key(HKEY_CURRENT_USER, KEY_BASE, 0); 3046ae4684dSwinesync 3056ae4684dSwinesync run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r); 306da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 307da2d23fbSwinesync ok(compare_export("file.reg", simple_data_test, 0), "compare_export() failed\n"); 3086ae4684dSwinesync 3096ae4684dSwinesync /* Copy subkeys and values */ 3106ae4684dSwinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /s /f", &r); 311da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 312cd3b6fe7Swinesync verify_key(HKEY_CURRENT_USER, KEY_BASE, 0); 3136ae4684dSwinesync 3146ae4684dSwinesync run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r); 315da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 316ded0675dSwinesync ok(compare_export("file.reg", complex_data_test, 0), "compare_export() failed\n"); 3176ae4684dSwinesync } 3186ae4684dSwinesync 319552256c1Swinesync static void test_copy_key_order(void) 320552256c1Swinesync { 321552256c1Swinesync HKEY hkey; 322552256c1Swinesync DWORD r; 323552256c1Swinesync 32444c2f0d9Swinesync delete_tree(HKEY_CURRENT_USER, COPY_SRC, 0); 32544c2f0d9Swinesync delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0); 326552256c1Swinesync 32777b2d21eSwinesync add_key(HKEY_CURRENT_USER, COPY_SRC, 0, &hkey); 32877b2d21eSwinesync add_key(hkey, "Subkey2", 0, NULL); 32977b2d21eSwinesync add_key(hkey, "Subkey1", 0, NULL); 330552256c1Swinesync close_key(hkey); 331552256c1Swinesync 332552256c1Swinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /s /f", &r); 333da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 334cd3b6fe7Swinesync verify_key(HKEY_CURRENT_USER, KEY_BASE, 0); 335552256c1Swinesync 336552256c1Swinesync run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r); 337da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 338ded0675dSwinesync ok(compare_export("file.reg", key_order_test, 0), "compare_export() failed\n"); 339552256c1Swinesync } 340552256c1Swinesync 341552256c1Swinesync static void test_copy_value_order(void) 342552256c1Swinesync { 343552256c1Swinesync HKEY hkey; 344552256c1Swinesync DWORD r; 345552256c1Swinesync 34644c2f0d9Swinesync delete_tree(HKEY_CURRENT_USER, COPY_SRC, 0); 34744c2f0d9Swinesync delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0); 348552256c1Swinesync 34977b2d21eSwinesync add_key(HKEY_CURRENT_USER, COPY_SRC, 0, &hkey); 350552256c1Swinesync add_value(hkey, "Value 2", REG_SZ, "I was added first!", 19); 351552256c1Swinesync add_value(hkey, "Value 1", REG_SZ, "I was added second!", 20); 352552256c1Swinesync close_key(hkey); 353552256c1Swinesync 354552256c1Swinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r); 355da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 356cd3b6fe7Swinesync verify_key(HKEY_CURRENT_USER, KEY_BASE, 0); 357552256c1Swinesync 358552256c1Swinesync run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r); 359da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 360da2d23fbSwinesync ok(compare_export("file.reg", value_order_test, TODO_REG_COMPARE), "compare_export() failed\n"); 361552256c1Swinesync } 362552256c1Swinesync 3636ae4684dSwinesync static void test_copy_hex_data(void) 3646ae4684dSwinesync { 3656ae4684dSwinesync HKEY hkey; 3666ae4684dSwinesync DWORD r; 3676ae4684dSwinesync 36844c2f0d9Swinesync delete_tree(HKEY_CURRENT_USER, COPY_SRC, 0); 36944c2f0d9Swinesync delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0); 3706ae4684dSwinesync 3716ae4684dSwinesync /* Try copying empty hex values */ 37277b2d21eSwinesync add_key(HKEY_CURRENT_USER, COPY_SRC, 0, &hkey); 3736ae4684dSwinesync add_value(hkey, "Wine1a", REG_NONE, NULL, 0); 3746ae4684dSwinesync add_value(hkey, "Wine1b", REG_SZ, NULL, 0); 3756ae4684dSwinesync add_value(hkey, "Wine1c", REG_EXPAND_SZ, NULL, 0); 3766ae4684dSwinesync add_value(hkey, "Wine1d", REG_BINARY, NULL, 0); 3776ae4684dSwinesync add_value(hkey, "Wine1e", REG_DWORD, NULL, 0); 3786ae4684dSwinesync add_value(hkey, "Wine1f", REG_MULTI_SZ, NULL, 0); 3796ae4684dSwinesync add_value(hkey, "Wine1g", 0x100, NULL, 0); 3806ae4684dSwinesync add_value(hkey, "Wine1h", 0xabcd, NULL, 0); 3816ae4684dSwinesync close_key(hkey); 3826ae4684dSwinesync 3836ae4684dSwinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r); 384da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 385cd3b6fe7Swinesync verify_key(HKEY_CURRENT_USER, KEY_BASE, 0); 3866ae4684dSwinesync 3876ae4684dSwinesync run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r); 388da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 389da2d23fbSwinesync ok(compare_export("file.reg", empty_hex_test, 0), "compare_export() failed\n"); 3906ae4684dSwinesync 3910ea0084cSwinesync delete_key(HKEY_CURRENT_USER, COPY_SRC, 0); 3920ea0084cSwinesync delete_key(HKEY_CURRENT_USER, KEY_BASE, 0); 3936ae4684dSwinesync 3946ae4684dSwinesync /* Try copying after importing alternative registry data types */ 3956ae4684dSwinesync test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n" 3966ae4684dSwinesync "[HKEY_CURRENT_USER\\" COPY_SRC "]\n" 3976ae4684dSwinesync "\"Wine2a\"=hex(1):\n" 3986ae4684dSwinesync "\"Wine2b\"=hex(3):\n" 3996ae4684dSwinesync "\"Wine2c\"=hex(4):\n\n", &r); 4006ae4684dSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 4016ae4684dSwinesync 4026ae4684dSwinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r); 403da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 404cd3b6fe7Swinesync verify_key(HKEY_CURRENT_USER, KEY_BASE, 0); 4056ae4684dSwinesync 4066ae4684dSwinesync run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r); 407da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 408da2d23fbSwinesync ok(compare_export("file.reg", empty_hex_test2, 0), "compare_export() failed\n"); 4096ae4684dSwinesync 4100ea0084cSwinesync delete_key(HKEY_CURRENT_USER, COPY_SRC, 0); 4110ea0084cSwinesync delete_key(HKEY_CURRENT_USER, KEY_BASE, 0); 4126ae4684dSwinesync 4136ae4684dSwinesync /* Try copying more complex hex data */ 4146ae4684dSwinesync test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n" 4156ae4684dSwinesync "[HKEY_CURRENT_USER\\" COPY_SRC "]\n" 4166ae4684dSwinesync "\"Wine3a\"=hex(1):56,00,61,00,6c,00,75,00,65,00,00,00\n" 4176ae4684dSwinesync "\"Wine3b\"=hex(3):12,34,56,78\n" 4186ae4684dSwinesync "\"Wine3c\"=hex(4):40,30,20,10\n\n", &r); 4196ae4684dSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 4206ae4684dSwinesync 4216ae4684dSwinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r); 422da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 423cd3b6fe7Swinesync verify_key(HKEY_CURRENT_USER, KEY_BASE, 0); 4246ae4684dSwinesync 4256ae4684dSwinesync run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r); 426da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 427da2d23fbSwinesync ok(compare_export("file.reg", hex_types_test, 0), "compare_export() failed\n"); 4286ae4684dSwinesync } 4296ae4684dSwinesync 430927db6beSwinesync static void test_copy_embedded_null_values(void) 431927db6beSwinesync { 432927db6beSwinesync DWORD r; 433927db6beSwinesync 43444c2f0d9Swinesync delete_tree(HKEY_CURRENT_USER, COPY_SRC, 0); 43544c2f0d9Swinesync delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0); 436927db6beSwinesync 437927db6beSwinesync test_import_wstr("\xef\xbb\xbfWindows Registry Editor Version 5.00\n\n" 438927db6beSwinesync "[HKEY_CURRENT_USER\\" COPY_SRC "]\n" 439927db6beSwinesync "\"Wine4a\"=dword:00000005\n" 440927db6beSwinesync "\"Wine4b\"=hex(1):00,00,00,00,00,00,00,00\n" 441927db6beSwinesync "\"Wine4c\"=\"Value\"\n" 442927db6beSwinesync "\"Wine4d\"=hex(1):00,00,61,00,62,00,63,00\n" 443927db6beSwinesync "\"Wine4e\"=dword:00000100\n" 444927db6beSwinesync "\"Wine4f\"=hex(1):00,00,56,00,61,00,6c,00,75,00,65,00,00,00\n" 445927db6beSwinesync "\"Wine4g\"=\"Value2\"\n" 446927db6beSwinesync "\"Wine4h\"=hex(1):61,00,62,00,63,00,00,00, \\\n" 447927db6beSwinesync " 64,00,65,00,66,00,00,00\n\n", &r); 448927db6beSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 449927db6beSwinesync 450927db6beSwinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r); 451da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 452cd3b6fe7Swinesync verify_key(HKEY_CURRENT_USER, KEY_BASE, 0); 453927db6beSwinesync 454927db6beSwinesync run_reg_exe("reg export HKEY_CURRENT_USER\\" KEY_BASE " file.reg /y", &r); 455da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 456da2d23fbSwinesync ok(compare_export("file.reg", embedded_null_test, 0), "compare_export() failed\n"); 457927db6beSwinesync } 458927db6beSwinesync 459927db6beSwinesync static void test_copy_slashes(void) 460927db6beSwinesync { 461927db6beSwinesync HKEY hkey; 462927db6beSwinesync DWORD r; 463927db6beSwinesync 46444c2f0d9Swinesync delete_tree(HKEY_CURRENT_USER, COPY_SRC, 0); 46544c2f0d9Swinesync delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0); 466927db6beSwinesync 46777b2d21eSwinesync add_key(HKEY_CURRENT_USER, COPY_SRC, 0, &hkey); 46877b2d21eSwinesync add_key(hkey, "https://winehq.org", 0, NULL); 469927db6beSwinesync add_value(hkey, "count/up", REG_SZ, "one/two/three", 14); 470927db6beSwinesync add_value(hkey, "\\foo\\bar", REG_SZ, "", 1); 471927db6beSwinesync close_key(hkey); 472927db6beSwinesync 473927db6beSwinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /s /f", &r); 474da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 475cd3b6fe7Swinesync verify_key(HKEY_CURRENT_USER, KEY_BASE, 0); 476927db6beSwinesync 477927db6beSwinesync run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r); 478da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 479da2d23fbSwinesync ok(compare_export("file.reg", slashes_test, TODO_REG_COMPARE), "compare_export() failed\n"); 480927db6beSwinesync } 481927db6beSwinesync 482927db6beSwinesync static void test_copy_escaped_null_values(void) 483927db6beSwinesync { 484927db6beSwinesync HKEY hkey; 485927db6beSwinesync DWORD r; 486927db6beSwinesync 48744c2f0d9Swinesync delete_tree(HKEY_CURRENT_USER, COPY_SRC, 0); 48844c2f0d9Swinesync delete_tree(HKEY_CURRENT_USER, KEY_BASE, 0); 489927db6beSwinesync 49077b2d21eSwinesync add_key(HKEY_CURRENT_USER, COPY_SRC, 0, &hkey); 491927db6beSwinesync add_value(hkey, "Wine5a", REG_SZ, "\\0", 3); 492927db6beSwinesync add_value(hkey, "Wine5b", REG_SZ, "\\0\\0", 5); 493927db6beSwinesync add_value(hkey, "Wine5c", REG_SZ, "Value1\\0", 9); 494927db6beSwinesync add_value(hkey, "Wine5d", REG_SZ, "Value2\\0\\0\\0\\0", 15); 495927db6beSwinesync add_value(hkey, "Wine5e", REG_SZ, "Value3\\0Value4", 15); 496927db6beSwinesync add_value(hkey, "Wine5f", REG_SZ, "\\0Value5", 9); 497927db6beSwinesync close_key(hkey); 498927db6beSwinesync 499927db6beSwinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r); 500da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 501cd3b6fe7Swinesync verify_key(HKEY_CURRENT_USER, KEY_BASE, 0); 502927db6beSwinesync 503927db6beSwinesync run_reg_exe("reg export HKCU\\" KEY_BASE " file.reg /y", &r); 504da2d23fbSwinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 505da2d23fbSwinesync ok(compare_export("file.reg", escaped_null_test, 0), "compare_export() failed\n"); 506927db6beSwinesync 5070ea0084cSwinesync delete_key(HKEY_CURRENT_USER, COPY_SRC, 0); 5080ea0084cSwinesync delete_key(HKEY_CURRENT_USER, KEY_BASE, 0); 509927db6beSwinesync } 510927db6beSwinesync 51107427368Swinesync static void test_copy_key_class(void) 51207427368Swinesync { 51307427368Swinesync HKEY hkey; 51407427368Swinesync LONG rc; 51507427368Swinesync char class[] = "class"; 51607427368Swinesync char buf[16]; 51707427368Swinesync DWORD buf_size, r; 51807427368Swinesync 51907427368Swinesync rc = RegCreateKeyExA(HKEY_CURRENT_USER, COPY_SRC, 0, class, REG_OPTION_NON_VOLATILE, 52007427368Swinesync KEY_READ|KEY_WRITE, NULL, &hkey, NULL); 52107427368Swinesync ok(rc == ERROR_SUCCESS, "RegCreateKeyExA failed: got %d, expected 0\n", rc); 52207427368Swinesync 52307427368Swinesync add_value(hkey, "String", REG_SZ, "Data", 5); 52407427368Swinesync 52507427368Swinesync buf_size = sizeof(buf); 52607427368Swinesync 52707427368Swinesync rc = RegQueryInfoKeyA(hkey, buf, &buf_size, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); 52807427368Swinesync ok(rc == ERROR_SUCCESS, "RegQueryInfoKeyA failed: got %d, expected 0\n", rc); 52907427368Swinesync ok(!strcmp(buf, "class"), "Incorrect key class set; got '%s', expected '%s'\n", buf, class); 53007427368Swinesync 53107427368Swinesync RegCloseKey(hkey); 53207427368Swinesync 53307427368Swinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r); 53407427368Swinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 535cd3b6fe7Swinesync verify_key(HKEY_CURRENT_USER, KEY_BASE, 0); 53607427368Swinesync 53707427368Swinesync open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey); 53807427368Swinesync verify_reg(hkey, "String", REG_SZ, "Data", 5, 0); 53907427368Swinesync 54007427368Swinesync memset(buf, 0, sizeof(buf)); 54107427368Swinesync buf_size = sizeof(buf); 54207427368Swinesync 54307427368Swinesync rc = RegQueryInfoKeyA(hkey, buf, &buf_size, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); 54407427368Swinesync ok(rc == ERROR_SUCCESS, "RegQueryInfoKeyA failed: got %d, expected 0\n", rc); 54507427368Swinesync ok(strlen(buf) == 0, "Key class should not exist\n"); 54607427368Swinesync 54707427368Swinesync RegCloseKey(hkey); 54807427368Swinesync 5490ea0084cSwinesync delete_key(HKEY_CURRENT_USER, COPY_SRC, 0); 5500ea0084cSwinesync delete_key(HKEY_CURRENT_USER, KEY_BASE, 0); 55107427368Swinesync } 55207427368Swinesync 5539ad9ae45Swinesync static void test_copy_overwrite(void) 5549ad9ae45Swinesync { 5559ad9ae45Swinesync HKEY hkey; 5569ad9ae45Swinesync DWORD r, dword; 5579ad9ae45Swinesync 55877b2d21eSwinesync add_key(HKEY_CURRENT_USER, COPY_SRC, 0, &hkey); 5599ad9ae45Swinesync add_value(hkey, "Wine1", REG_SZ, "def", 4); 5609ad9ae45Swinesync dword = 0x5; 5619ad9ae45Swinesync add_value(hkey, "Wine2", REG_DWORD, &dword, sizeof(dword)); 5629ad9ae45Swinesync add_value(hkey, "Wine3", REG_BINARY, "\x11\x22\x33\x44", 4); 5639ad9ae45Swinesync add_value(hkey, "Wine4", REG_MULTI_SZ, "Line1\0Line2\0Line3\0", 19); 5649ad9ae45Swinesync close_key(hkey); 5659ad9ae45Swinesync 56677b2d21eSwinesync add_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey); 5679ad9ae45Swinesync add_value(hkey, "Wine1", REG_SZ, "abc", 4); 5689ad9ae45Swinesync verify_reg_nonexist(hkey, "Wine2"); 5699ad9ae45Swinesync add_value(hkey, "Wine3", REG_EXPAND_SZ, "%HOME%\\%PATH%", 14); 5709ad9ae45Swinesync dword = 0x1; 5719ad9ae45Swinesync add_value(hkey, "Wine4", REG_DWORD, &dword, sizeof(dword)); 5729ad9ae45Swinesync add_value(hkey, NULL, REG_SZ, "Constant value", 15); 5739ad9ae45Swinesync close_key(hkey); 5749ad9ae45Swinesync 5759ad9ae45Swinesync run_reg_exe("reg copy HKCU\\" COPY_SRC " HKCU\\" KEY_BASE " /f", &r); 5769ad9ae45Swinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 5779ad9ae45Swinesync 5789ad9ae45Swinesync open_key(HKEY_CURRENT_USER, KEY_BASE, 0, &hkey); 5799ad9ae45Swinesync verify_reg(hkey, "Wine1", REG_SZ, "def", 4, 0); 5809ad9ae45Swinesync dword = 0x5; 5819ad9ae45Swinesync verify_reg(hkey, "Wine2", REG_DWORD, &dword, sizeof(dword), 0); 5829ad9ae45Swinesync verify_reg(hkey, "Wine3", REG_BINARY, "\x11\x22\x33\x44", 4, 0); 5839ad9ae45Swinesync verify_reg(hkey, "Wine4", REG_MULTI_SZ, "Line1\0Line2\0Line3\0", 19, 0); 5849ad9ae45Swinesync verify_reg(hkey, NULL, REG_SZ, "Constant value", 15, 0); 5859ad9ae45Swinesync close_key(hkey); 5869ad9ae45Swinesync 5870ea0084cSwinesync delete_key(HKEY_CURRENT_USER, COPY_SRC, 0); 5880ea0084cSwinesync delete_key(HKEY_CURRENT_USER, KEY_BASE, 0); 5899ad9ae45Swinesync } 5909ad9ae45Swinesync 591*be726bd7Swinesync static void create_test_key(REGSAM sam) 592*be726bd7Swinesync { 593*be726bd7Swinesync HKEY hkey, subkey; 594*be726bd7Swinesync DWORD dword = 0x100; 595*be726bd7Swinesync 596*be726bd7Swinesync add_key(HKEY_LOCAL_MACHINE, COPY_SRC, sam, &hkey); 597*be726bd7Swinesync add_value(hkey, "DWORD", REG_DWORD, &dword, sizeof(dword)); 598*be726bd7Swinesync add_value(hkey, "String", REG_SZ, "Your text here...", 18); 599*be726bd7Swinesync 600*be726bd7Swinesync add_key(hkey, "Subkey1", sam, &subkey); 601*be726bd7Swinesync add_value(subkey, "Binary", REG_BINARY, "\x11\x22\x33\x44", 4); 602*be726bd7Swinesync add_value(subkey, "Undefined hex", 0x100, "%PATH%", 7); 603*be726bd7Swinesync close_key(subkey); 604*be726bd7Swinesync 605*be726bd7Swinesync close_key(hkey); 606*be726bd7Swinesync } 607*be726bd7Swinesync 608*be726bd7Swinesync static void test_registry_view_win32(void) 609*be726bd7Swinesync { 610*be726bd7Swinesync DWORD r; 611*be726bd7Swinesync BOOL is_wow64, is_win32; 612*be726bd7Swinesync 613*be726bd7Swinesync IsWow64Process(GetCurrentProcess(), &is_wow64); 614*be726bd7Swinesync is_win32 = !is_wow64 && (sizeof(void *) == sizeof(int)); 615*be726bd7Swinesync 616*be726bd7Swinesync if (!is_win32) return; 617*be726bd7Swinesync 618*be726bd7Swinesync delete_tree(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_32KEY); 619*be726bd7Swinesync delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY); 620*be726bd7Swinesync 621*be726bd7Swinesync /* Try copying registry data in the 32-bit registry view (32-bit Windows) */ 622*be726bd7Swinesync create_test_key(KEY_WOW64_32KEY); 623*be726bd7Swinesync 624*be726bd7Swinesync run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:32", &r); 625*be726bd7Swinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 626*be726bd7Swinesync 627*be726bd7Swinesync run_reg_exe("reg export HKLM\\" KEY_BASE " file.reg /y /reg:32", &r); 628*be726bd7Swinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 629*be726bd7Swinesync ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n"); 630*be726bd7Swinesync 631*be726bd7Swinesync delete_tree(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_32KEY); 632*be726bd7Swinesync delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY); 633*be726bd7Swinesync 634*be726bd7Swinesync /* Try copying registry data in the 64-bit registry view, which doesn't exist on 32-bit Windows */ 635*be726bd7Swinesync create_test_key(KEY_WOW64_64KEY); 636*be726bd7Swinesync 637*be726bd7Swinesync run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:64", &r); 638*be726bd7Swinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 639*be726bd7Swinesync 640*be726bd7Swinesync run_reg_exe("reg export HKLM\\" KEY_BASE " file.reg /y /reg:64", &r); 641*be726bd7Swinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 642*be726bd7Swinesync ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n"); 643*be726bd7Swinesync 644*be726bd7Swinesync delete_tree(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_64KEY); 645*be726bd7Swinesync delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY); 646*be726bd7Swinesync } 647*be726bd7Swinesync 648*be726bd7Swinesync static void test_registry_view_win64(void) 649*be726bd7Swinesync { 650*be726bd7Swinesync DWORD r; 651*be726bd7Swinesync BOOL is_wow64, is_win64; 652*be726bd7Swinesync 653*be726bd7Swinesync IsWow64Process(GetCurrentProcess(), &is_wow64); 654*be726bd7Swinesync is_win64 = !is_wow64 && (sizeof(void *) > sizeof(int)); 655*be726bd7Swinesync 656*be726bd7Swinesync if (!is_win64) return; 657*be726bd7Swinesync 658*be726bd7Swinesync delete_tree(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_32KEY); 659*be726bd7Swinesync delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY); 660*be726bd7Swinesync delete_tree(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_64KEY); 661*be726bd7Swinesync delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY); 662*be726bd7Swinesync 663*be726bd7Swinesync /* Try copying registry data in the 32-bit registry view (64-bit Windows) */ 664*be726bd7Swinesync create_test_key(KEY_WOW64_32KEY); 665*be726bd7Swinesync verify_key_nonexist(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_64KEY); 666*be726bd7Swinesync verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY); 667*be726bd7Swinesync 668*be726bd7Swinesync run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:32", &r); 669*be726bd7Swinesync todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 670*be726bd7Swinesync 671*be726bd7Swinesync run_reg_exe("reg export HKLM\\" KEY_BASE " file.reg /y /reg:32", &r); 672*be726bd7Swinesync todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 673*be726bd7Swinesync todo_wine ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n"); 674*be726bd7Swinesync 675*be726bd7Swinesync run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:64", &r); 676*be726bd7Swinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 677*be726bd7Swinesync 678*be726bd7Swinesync delete_tree(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_32KEY); 679*be726bd7Swinesync delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY); 680*be726bd7Swinesync 681*be726bd7Swinesync /* Try copying registry data in the 64-bit registry view (64-bit Windows) */ 682*be726bd7Swinesync create_test_key(KEY_WOW64_64KEY); 683*be726bd7Swinesync verify_key_nonexist(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_32KEY); 684*be726bd7Swinesync verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY); 685*be726bd7Swinesync 686*be726bd7Swinesync run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:64", &r); 687*be726bd7Swinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 688*be726bd7Swinesync 689*be726bd7Swinesync run_reg_exe("reg export HKLM\\" KEY_BASE " file.reg /y /reg:64", &r); 690*be726bd7Swinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 691*be726bd7Swinesync ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n"); 692*be726bd7Swinesync 693*be726bd7Swinesync run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:32", &r); 694*be726bd7Swinesync todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 695*be726bd7Swinesync 696*be726bd7Swinesync delete_tree(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_64KEY); 697*be726bd7Swinesync delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY); 698*be726bd7Swinesync } 699*be726bd7Swinesync 700*be726bd7Swinesync static void test_registry_view_wow64(void) 701*be726bd7Swinesync { 702*be726bd7Swinesync DWORD r; 703*be726bd7Swinesync BOOL is_wow64; 704*be726bd7Swinesync 705*be726bd7Swinesync IsWow64Process(GetCurrentProcess(), &is_wow64); 706*be726bd7Swinesync 707*be726bd7Swinesync if (!is_wow64) return; 708*be726bd7Swinesync 709*be726bd7Swinesync delete_tree(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_32KEY); 710*be726bd7Swinesync delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY); 711*be726bd7Swinesync delete_tree(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_64KEY); 712*be726bd7Swinesync delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY); 713*be726bd7Swinesync 714*be726bd7Swinesync /* Try copying registry data in the 32-bit registry view (WOW64) */ 715*be726bd7Swinesync create_test_key(KEY_WOW64_32KEY); 716*be726bd7Swinesync verify_key_nonexist(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_64KEY); 717*be726bd7Swinesync verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY); 718*be726bd7Swinesync 719*be726bd7Swinesync run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:32", &r); 720*be726bd7Swinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 721*be726bd7Swinesync 722*be726bd7Swinesync run_reg_exe("reg export HKLM\\" KEY_BASE " file.reg /y /reg:32", &r); 723*be726bd7Swinesync ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 724*be726bd7Swinesync ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n"); 725*be726bd7Swinesync 726*be726bd7Swinesync run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:64", &r); 727*be726bd7Swinesync todo_wine ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 728*be726bd7Swinesync 729*be726bd7Swinesync delete_tree(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_32KEY); 730*be726bd7Swinesync delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY); 731*be726bd7Swinesync 732*be726bd7Swinesync /* Try copying registry data in the 64-bit registry view (WOW64) */ 733*be726bd7Swinesync create_test_key(KEY_WOW64_64KEY); 734*be726bd7Swinesync verify_key_nonexist(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_32KEY); 735*be726bd7Swinesync verify_key_nonexist(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_32KEY); 736*be726bd7Swinesync 737*be726bd7Swinesync run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:64", &r); 738*be726bd7Swinesync todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 739*be726bd7Swinesync 740*be726bd7Swinesync run_reg_exe("reg export HKLM\\" KEY_BASE " file.reg /y /reg:64", &r); 741*be726bd7Swinesync todo_wine ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r); 742*be726bd7Swinesync todo_wine ok(compare_export("file.reg", registry_view_test, 0), "compare_export() failed\n"); 743*be726bd7Swinesync 744*be726bd7Swinesync run_reg_exe("reg copy HKLM\\" COPY_SRC " HKLM\\" KEY_BASE " /s /f /reg:32", &r); 745*be726bd7Swinesync ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r); 746*be726bd7Swinesync 747*be726bd7Swinesync delete_tree(HKEY_LOCAL_MACHINE, COPY_SRC, KEY_WOW64_64KEY); 748*be726bd7Swinesync delete_tree(HKEY_LOCAL_MACHINE, KEY_BASE, KEY_WOW64_64KEY); 749*be726bd7Swinesync } 750*be726bd7Swinesync 751295a04dfSwinesync START_TEST(copy) 752295a04dfSwinesync { 753295a04dfSwinesync DWORD r; 754295a04dfSwinesync 755295a04dfSwinesync if (!run_reg_exe("reg.exe /?", &r)) { 7562161165dSwinesync win_skip("reg.exe not available, skipping 'copy' tests\n"); 757295a04dfSwinesync return; 758295a04dfSwinesync } 759295a04dfSwinesync 7601aea6bdfSwinesync test_command_syntax(); 761d40c4ec1Swinesync test_copy_empty_key(); 762d40c4ec1Swinesync test_copy_simple_data(); 7636ae4684dSwinesync test_copy_complex_data(); 764552256c1Swinesync test_copy_key_order(); 765552256c1Swinesync test_copy_value_order(); 7666ae4684dSwinesync test_copy_hex_data(); 767927db6beSwinesync test_copy_embedded_null_values(); 768927db6beSwinesync test_copy_slashes(); 769927db6beSwinesync test_copy_escaped_null_values(); 77007427368Swinesync test_copy_key_class(); 7719ad9ae45Swinesync test_copy_overwrite(); 772*be726bd7Swinesync 773*be726bd7Swinesync /* Check if reg.exe is running with elevated privileges */ 774*be726bd7Swinesync if (!is_elevated_process()) 775*be726bd7Swinesync { 776*be726bd7Swinesync win_skip("reg.exe is not running with elevated privileges; " 777*be726bd7Swinesync "skipping registry view tests\n"); 778*be726bd7Swinesync return; 779*be726bd7Swinesync } 780*be726bd7Swinesync 781*be726bd7Swinesync test_registry_view_win32(); 782*be726bd7Swinesync test_registry_view_win64(); 783*be726bd7Swinesync test_registry_view_wow64(); 784295a04dfSwinesync } 785