[IPHLPAPI_APITEST]
[reactos.git] / rostests / apitests / advapi32 / RegQueryInfoKey.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: LGPLv2.1+ - See COPYING.Lib in the top level directory
4 * PURPOSE: Test for RegQueryInfoKey
5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org>
6 */
7
8 #include <apitest.h>
9
10 #define WIN32_NO_STATUS
11 #include <winreg.h>
12
13 #define TestKeyAccess(da, er, es) TestKeyAccess_(__FILE__, __LINE__, da, er, es)
14 static
15 VOID
16 TestKeyAccess_(
17 _In_ PCSTR File,
18 _In_ INT Line,
19 _In_ REGSAM DesiredAccess,
20 _In_ LONG ExpectedReturn,
21 _In_ BOOLEAN ExpectSd)
22 {
23 DWORD cbSd;
24 HKEY hKey;
25 LONG ret;
26
27 ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software", 0, DesiredAccess, &hKey);
28 ok_(File, Line)(ret == NO_ERROR, "RegOpenKeyEx returned %ld\n", ret);
29 if (ret == NO_ERROR)
30 {
31 cbSd = 0x55555555;
32 ret = RegQueryInfoKeyW(hKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &cbSd, NULL);
33 ok_(File, Line)(ret == ExpectedReturn, "RegQueryInfoKeyW returned %ld\n", ret);
34 if (ExpectSd)
35 ok_(File, Line)(cbSd != 0 && cbSd != 0x55555555, "RegQueryInfoKeyW - cbSd = %lu\n", cbSd);
36 else
37 ok_(File, Line)(cbSd == 0, "RegQueryInfoKeyW - cbSd = %lu\n", cbSd);
38
39 cbSd = 0x55555555;
40 ret = RegQueryInfoKeyA(hKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &cbSd, NULL);
41 ok_(File, Line)(ret == ExpectedReturn, "RegQueryInfoKeyA returned %ld\n", ret);
42 if (ExpectSd)
43 ok_(File, Line)(cbSd != 0 && cbSd != 0x55555555, "RegQueryInfoKeyA - cbSd = %lu\n", cbSd);
44 else
45 ok_(File, Line)(cbSd == 0, "RegQueryInfoKeyA - cbSd = %lu\n", cbSd);
46 ret = RegCloseKey(hKey);
47 ok_(File, Line)(ret == NO_ERROR, "RegCloseKey returned %ld\n", ret);
48 }
49 else
50 {
51 skip_(File, Line)("No key handle\n");
52 }
53 }
54
55 START_TEST(RegQueryInfoKey)
56 {
57 /* 0 access just fails the open */
58 if (0)
59 TestKeyAccess(0, ERROR_ACCESS_DENIED, FALSE);
60 /* Without KEY_QUERY_VALUE we can't query anything */
61 TestKeyAccess(READ_CONTROL, ERROR_ACCESS_DENIED, FALSE);
62 /* Without READ_CONTROL we'll get success but SD size will yield 0 */
63 TestKeyAccess(KEY_QUERY_VALUE, NO_ERROR, FALSE);
64 /* With the two combined we get everything */
65 TestKeyAccess(KEY_QUERY_VALUE | READ_CONTROL, NO_ERROR, TRUE);
66 /* Write rights return nothing on 2003 (but succeed and return SD size on Win7) */
67 TestKeyAccess(KEY_SET_VALUE, ERROR_ACCESS_DENIED, FALSE);
68 TestKeyAccess(KEY_CREATE_SUB_KEY, ERROR_ACCESS_DENIED, FALSE);
69 TestKeyAccess(KEY_CREATE_LINK, ERROR_ACCESS_DENIED, FALSE);
70 TestKeyAccess(DELETE, ERROR_ACCESS_DENIED, FALSE);
71 TestKeyAccess(WRITE_DAC, ERROR_ACCESS_DENIED, FALSE);
72 TestKeyAccess(WRITE_OWNER, ERROR_ACCESS_DENIED, FALSE);
73 /* But these return nothing */
74 TestKeyAccess(KEY_ENUMERATE_SUB_KEYS, ERROR_ACCESS_DENIED, FALSE);
75 TestKeyAccess(KEY_NOTIFY, ERROR_ACCESS_DENIED, FALSE);
76 }