reg/tests: Always specify the expected exit code in error messages.
[wine.git] / programs / reg / tests / delete.c
blobfff3c5348b88315f34bcdadfb07b543b40dc5ea4
1 /*
2 * Copyright 2014 Akihiro Sagawa
3 * Copyright 2016-2018, 2021 Hugh McMaster
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "reg_test.h"
22 static void test_delete(void)
24 HKEY hkey, hsubkey;
25 DWORD r;
26 const DWORD deadbeef = 0xdeadbeef;
28 delete_tree(HKEY_CURRENT_USER, KEY_BASE);
29 verify_key_nonexist(HKEY_CURRENT_USER, KEY_BASE);
31 run_reg_exe("reg delete", &r);
32 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
34 run_reg_exe("reg delete /?", &r);
35 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
37 run_reg_exe("reg delete /h", &r);
38 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
40 run_reg_exe("reg delete -H", &r);
41 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
43 /* Multiple /v* switches */
44 run_reg_exe("reg delete HKCU\\" KEY_BASE " /v Wine /ve", &r);
45 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
47 run_reg_exe("reg delete HKCU\\" KEY_BASE " /v Wine /va", &r);
48 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
50 run_reg_exe("reg delete HKCU\\" KEY_BASE " /ve /va", &r);
51 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
53 run_reg_exe("reg delete HKCU\\" KEY_BASE " /v Wine /v Test /f", &r);
54 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
56 /* No /v argument */
57 run_reg_exe("reg delete HKCU\\" KEY_BASE " /v", &r);
58 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
60 run_reg_exe("reg delete HKCU\\" KEY_BASE " /f /v", &r);
61 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
63 /* Create a test key */
64 add_key(HKEY_CURRENT_USER, KEY_BASE, &hkey);
65 add_value(hkey, "foo", REG_DWORD, &deadbeef, sizeof(deadbeef));
66 add_value(hkey, "bar", REG_DWORD, &deadbeef, sizeof(deadbeef));
67 add_value(hkey, NULL, REG_DWORD, &deadbeef, sizeof(deadbeef));
69 add_key(hkey, "subkey", &hsubkey);
70 close_key(hsubkey);
72 run_reg_exe("reg delete HKCU\\" KEY_BASE " /v bar /f", &r);
73 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
74 verify_reg_nonexist(hkey, "bar");
76 run_reg_exe("reg delete HKCU\\" KEY_BASE " /ve /f", &r);
77 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
78 verify_reg_nonexist(hkey, "");
80 run_reg_exe("reg delete HKCU\\" KEY_BASE " /va /f", &r);
81 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
82 verify_reg_nonexist(hkey, "foo");
83 verify_key(hkey, "subkey");
85 /* Test forward and back slashes */
86 add_key(hkey, "https://winehq.org", &hsubkey);
87 close_key(hsubkey);
88 add_value(hkey, "count/up", REG_SZ, "one/two/three", 14);
89 add_value(hkey, "\\foo\\bar", REG_SZ, "", 1);
91 run_reg_exe("reg delete HKCU\\" KEY_BASE "\\https://winehq.org /f", &r);
92 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
93 verify_key_nonexist(hkey, "https://winehq.org");
95 run_reg_exe("reg delete HKCU\\" KEY_BASE " /v count/up /f", &r);
96 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
97 verify_reg_nonexist(hkey, "count/up");
99 run_reg_exe("reg delete HKCU\\" KEY_BASE " /v \\foo\\bar /f", &r);
100 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
101 verify_reg_nonexist(hkey, "\\foo\\bar");
103 close_key(hkey);
105 run_reg_exe("reg delete HKCU\\" KEY_BASE " /f", &r);
106 ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
107 verify_key_nonexist(HKEY_CURRENT_USER, KEY_BASE);
109 run_reg_exe("reg delete HKCU\\" KEY_BASE " /f", &r);
110 ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
113 START_TEST(delete)
115 DWORD r;
117 if (!run_reg_exe("reg.exe /?", &r)) {
118 win_skip("reg.exe not available, skipping 'delete' tests\n");
119 return;
122 test_delete();