xref: /reactos/modules/rostests/winetests/reg/query.c (revision 7fcb8aca)
1*7fcb8acaSwinesync /*
2*7fcb8acaSwinesync  * Copyright 2014 Akihiro Sagawa
3*7fcb8acaSwinesync  * Copyright 2016-2018, 2021 Hugh McMaster
4*7fcb8acaSwinesync  *
5*7fcb8acaSwinesync  * This library is free software; you can redistribute it and/or
6*7fcb8acaSwinesync  * modify it under the terms of the GNU Lesser General Public
7*7fcb8acaSwinesync  * License as published by the Free Software Foundation; either
8*7fcb8acaSwinesync  * version 2.1 of the License, or (at your option) any later version.
9*7fcb8acaSwinesync  *
10*7fcb8acaSwinesync  * This library is distributed in the hope that it will be useful,
11*7fcb8acaSwinesync  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*7fcb8acaSwinesync  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13*7fcb8acaSwinesync  * Lesser General Public License for more details.
14*7fcb8acaSwinesync  *
15*7fcb8acaSwinesync  * You should have received a copy of the GNU Lesser General Public
16*7fcb8acaSwinesync  * License along with this library; if not, write to the Free Software
17*7fcb8acaSwinesync  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18*7fcb8acaSwinesync  */
19*7fcb8acaSwinesync 
20*7fcb8acaSwinesync #include "reg_test.h"
21*7fcb8acaSwinesync 
22*7fcb8acaSwinesync static void test_query(void)
23*7fcb8acaSwinesync {
24*7fcb8acaSwinesync     DWORD r;
25*7fcb8acaSwinesync     HKEY key, subkey;
26*7fcb8acaSwinesync     const char hello[] = "Hello";
27*7fcb8acaSwinesync     const char world[] = "World";
28*7fcb8acaSwinesync     const char empty1[] = "Empty1";
29*7fcb8acaSwinesync     const char empty2[] = "Empty2";
30*7fcb8acaSwinesync     const DWORD dword1 = 0x123;
31*7fcb8acaSwinesync     const DWORD dword2 = 0xabc;
32*7fcb8acaSwinesync 
33*7fcb8acaSwinesync     delete_tree(HKEY_CURRENT_USER, KEY_BASE);
34*7fcb8acaSwinesync     verify_key_nonexist(HKEY_CURRENT_USER, KEY_BASE);
35*7fcb8acaSwinesync 
36*7fcb8acaSwinesync     run_reg_exe("reg query", &r);
37*7fcb8acaSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
38*7fcb8acaSwinesync 
39*7fcb8acaSwinesync     run_reg_exe("reg query /?", &r);
40*7fcb8acaSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
41*7fcb8acaSwinesync 
42*7fcb8acaSwinesync     run_reg_exe("reg query /h", &r);
43*7fcb8acaSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
44*7fcb8acaSwinesync 
45*7fcb8acaSwinesync     run_reg_exe("reg query -H", &r);
46*7fcb8acaSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
47*7fcb8acaSwinesync 
48*7fcb8acaSwinesync     /* Create a test key */
49*7fcb8acaSwinesync     add_key(HKEY_CURRENT_USER, KEY_BASE, &key);
50*7fcb8acaSwinesync 
51*7fcb8acaSwinesync     run_reg_exe("reg query HKCU\\" KEY_BASE " /ve", &r);
52*7fcb8acaSwinesync     ok(r == REG_EXIT_SUCCESS || broken(r == REG_EXIT_FAILURE /* WinXP */),
53*7fcb8acaSwinesync        "got exit code %d, expected 0\n", r);
54*7fcb8acaSwinesync 
55*7fcb8acaSwinesync     add_value(key, "Test", REG_SZ, hello, sizeof(hello));
56*7fcb8acaSwinesync     add_value(key, "Wine", REG_DWORD, &dword1, sizeof(dword1));
57*7fcb8acaSwinesync     add_value(key, NULL, REG_SZ, empty1, sizeof(empty1));
58*7fcb8acaSwinesync 
59*7fcb8acaSwinesync     run_reg_exe("reg query HKCU\\" KEY_BASE, &r);
60*7fcb8acaSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
61*7fcb8acaSwinesync 
62*7fcb8acaSwinesync     run_reg_exe("reg query HKCU\\" KEY_BASE " /v", &r);
63*7fcb8acaSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
64*7fcb8acaSwinesync 
65*7fcb8acaSwinesync     run_reg_exe("reg query HKCU\\" KEY_BASE " /v Missing", &r);
66*7fcb8acaSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
67*7fcb8acaSwinesync 
68*7fcb8acaSwinesync     run_reg_exe("reg query HKCU\\" KEY_BASE " /v Test", &r);
69*7fcb8acaSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
70*7fcb8acaSwinesync 
71*7fcb8acaSwinesync     run_reg_exe("reg query HKCU\\" KEY_BASE " /v Wine", &r);
72*7fcb8acaSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
73*7fcb8acaSwinesync 
74*7fcb8acaSwinesync     run_reg_exe("reg query HKCU\\" KEY_BASE " /ve", &r);
75*7fcb8acaSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
76*7fcb8acaSwinesync 
77*7fcb8acaSwinesync     /* Create a test subkey */
78*7fcb8acaSwinesync     add_key(key, "Subkey", &subkey);
79*7fcb8acaSwinesync     add_value(subkey, "Test", REG_SZ, world, sizeof(world));
80*7fcb8acaSwinesync     add_value(subkey, "Wine", REG_DWORD, &dword2, sizeof(dword2));
81*7fcb8acaSwinesync     add_value(subkey, NULL, REG_SZ, empty2, sizeof(empty2));
82*7fcb8acaSwinesync 
83*7fcb8acaSwinesync     close_key(subkey);
84*7fcb8acaSwinesync 
85*7fcb8acaSwinesync     run_reg_exe("reg query HKCU\\" KEY_BASE "\\subkey", &r);
86*7fcb8acaSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
87*7fcb8acaSwinesync 
88*7fcb8acaSwinesync     run_reg_exe("reg query HKCU\\" KEY_BASE "\\subkey /v Test", &r);
89*7fcb8acaSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
90*7fcb8acaSwinesync 
91*7fcb8acaSwinesync     run_reg_exe("reg query HKCU\\" KEY_BASE "\\subkey /v Wine", &r);
92*7fcb8acaSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
93*7fcb8acaSwinesync 
94*7fcb8acaSwinesync     run_reg_exe("reg query HKCU\\" KEY_BASE "\\subkey /ve", &r);
95*7fcb8acaSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
96*7fcb8acaSwinesync 
97*7fcb8acaSwinesync     /* Test recursion */
98*7fcb8acaSwinesync     run_reg_exe("reg query HKCU\\" KEY_BASE " /s", &r);
99*7fcb8acaSwinesync     ok(r == REG_EXIT_SUCCESS, "got exit code %d, expected 0\n", r);
100*7fcb8acaSwinesync 
101*7fcb8acaSwinesync     run_reg_exe("reg query HKCU\\" KEY_BASE " /v Test /s", &r);
102*7fcb8acaSwinesync     ok(r == REG_EXIT_SUCCESS || r == REG_EXIT_FAILURE /* WinXP */,
103*7fcb8acaSwinesync        "got exit code %d, expected 0\n", r);
104*7fcb8acaSwinesync 
105*7fcb8acaSwinesync     run_reg_exe("reg query HKCU\\" KEY_BASE " /v Wine /s", &r);
106*7fcb8acaSwinesync     ok(r == REG_EXIT_SUCCESS || r == REG_EXIT_FAILURE /* WinXP */,
107*7fcb8acaSwinesync        "got exit code %d, expected 0\n", r);
108*7fcb8acaSwinesync 
109*7fcb8acaSwinesync     run_reg_exe("reg query HKCU\\" KEY_BASE " /ve /s", &r);
110*7fcb8acaSwinesync     ok(r == REG_EXIT_SUCCESS || r == REG_EXIT_FAILURE /* WinXP */,
111*7fcb8acaSwinesync        "got exit code %d, expected 0\n", r);
112*7fcb8acaSwinesync 
113*7fcb8acaSwinesync     /* Clean-up, then query */
114*7fcb8acaSwinesync     delete_key(key, "subkey");
115*7fcb8acaSwinesync     close_key(key);
116*7fcb8acaSwinesync 
117*7fcb8acaSwinesync     run_reg_exe("reg query HKCU\\" KEY_BASE "\\subkey", &r);
118*7fcb8acaSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
119*7fcb8acaSwinesync 
120*7fcb8acaSwinesync     delete_key(HKEY_CURRENT_USER, KEY_BASE);
121*7fcb8acaSwinesync 
122*7fcb8acaSwinesync     run_reg_exe("reg query HKCU\\" KEY_BASE, &r);
123*7fcb8acaSwinesync     ok(r == REG_EXIT_FAILURE, "got exit code %d, expected 1\n", r);
124*7fcb8acaSwinesync }
125*7fcb8acaSwinesync 
126*7fcb8acaSwinesync START_TEST(query)
127*7fcb8acaSwinesync {
128*7fcb8acaSwinesync     DWORD r;
129*7fcb8acaSwinesync 
130*7fcb8acaSwinesync     if (!run_reg_exe("reg.exe /?", &r)) {
131*7fcb8acaSwinesync         win_skip("reg.exe not available, skipping 'query' tests\n");
132*7fcb8acaSwinesync         return;
133*7fcb8acaSwinesync     }
134*7fcb8acaSwinesync 
135*7fcb8acaSwinesync     test_query();
136*7fcb8acaSwinesync }
137