ReactOS 0.4.17-dev-243-g1369312
QuerySourceCreateFromKey.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Tests for QuerySourceCreateFromKey
5 * COPYRIGHT: Copyright 2026 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6 */
7
8#include <apitest.h>
9#include <shlobj.h>
10#include <shlwapi.h>
11#include <shlguid_undoc.h>
12#include <shlobj_undoc.h>
13#include <shlwapi_undoc.h>
14#include <versionhelpers.h>
15
18
19static const WCHAR k_Root[] = L"Software\\QuerySrcTest";
20static const WCHAR k_SubKeyA[] = L"SubKeyA";
21static const WCHAR k_SubKeyB[] = L"SubKeyB";
22
23static void SetupRegistry(void)
24{
25 HKEY hRoot;
27
28 static const WCHAR valA[] = L"hello";
29 RegSetValueExW(hRoot, L"ValueA", 0, REG_SZ, (const BYTE*)valA, (DWORD)sizeof(valA));
30
31 DWORD dwValue = 0xBEEFCAFE;
32 RegSetValueExW(hRoot, L"ValueB", 0, REG_DWORD, (const BYTE*)&dwValue, (DWORD)sizeof(dwValue));
33
34 HKEY hSub;
36 RegCloseKey(hSub);
38 RegCloseKey(hSub);
39
41}
42
43static void CleanupRegistry(void)
44{
46}
47
48static void Test_EnumValues(void)
49{
50 IQuerySourceOld *pSrc = NULL;
52 IID_IQuerySourceOld, (PVOID*)&pSrc);
53 ok_hr(hr, S_OK);
54 ok(pSrc != NULL, "pSrc was NULL\n");
55
56 IEnumString *pEnum = NULL;
57 hr = 0xDEADFACE;
58 if (pSrc)
59 hr = pSrc->EnumValues(&pEnum);
60 ok(pSrc && hr == S_OK, "EnumValues failed: 0x%08X\n", hr);
61
62 LPWSTR psz = NULL;
63 ULONG fetched = 0;
64 hr = 0xDEADFACE;
65
66 if (pEnum)
67 hr = pEnum->Next(1, &psz, &fetched);
68 ok_hr(hr, S_OK);
69 ok(lstrcmpiW(psz, L"ValueA") == 0, "psz was %s\n", wine_dbgstr_w(psz));
70 ok_int(fetched, 1);
71 CoTaskMemFree(psz);
72
73 psz = NULL;
74 fetched = 0;
75 hr = 0xDEADFACE;
76
77 if (pEnum)
78 hr = pEnum->Next(1, &psz, &fetched);
79 ok_hr(hr, S_OK);
80 ok(lstrcmpiW(psz, L"ValueB") == 0, "psz was %s\n", wine_dbgstr_w(psz));
81 ok_int(fetched, 1);
82 CoTaskMemFree(psz);
83
84 psz = NULL;
85 fetched = 0;
86 hr = 0xDEADFACE;
87
88 if (pEnum)
89 hr = pEnum->Next(1, &psz, &fetched);
91 ok(psz == NULL, "psz was %s\n", wine_dbgstr_w(psz));
92 ok_int(fetched, 0);
93 CoTaskMemFree(psz);
94
95 if (pEnum)
96 pEnum->Release();
97 if (pSrc)
98 pSrc->Release();
99}
100
101static void Test_EnumSources(void)
102{
103 IQuerySourceOld *pSrc = NULL;
105 IID_IQuerySourceOld, (PVOID*)&pSrc);
106 ok_hr(hr, S_OK);
107 ok(pSrc != NULL, "pSrc was NULL\n");
108
109 IEnumString *pEnum = NULL;
110 hr = pSrc->EnumSources(&pEnum);
111 ok_hr(hr, S_OK);
112 ok(pEnum != NULL, "pEnum was NULL\n");
113
114 LPWSTR psz = NULL;
115 ULONG fetched = 0;
116 hr = 0xDEADFACE;
117
118 if (pEnum)
119 hr = pEnum->Next(1, &psz, &fetched);
120 ok_hr(hr, S_OK);
121 ok(lstrcmpiW(psz, k_SubKeyA) == 0, "psz was %s\n", wine_dbgstr_w(psz));
122 ok_int(fetched, 1);
123 CoTaskMemFree(psz);
124
125 psz = NULL;
126 fetched = 0;
127 hr = 0xDEADFACE;
128
129 if (pEnum)
130 hr = pEnum->Next(1, &psz, &fetched);
131 ok_hr(hr, S_OK);
132 ok(lstrcmpiW(psz, k_SubKeyB) == 0, "psz was %s\n", wine_dbgstr_w(psz));
133 ok_int(fetched, 1);
134 CoTaskMemFree(psz);
135
136 psz = NULL;
137 fetched = 0;
138 hr = 0xDEADFACE;
139
140 if (pEnum)
141 hr = pEnum->Next(1, &psz, &fetched);
142 ok_hr(hr, S_FALSE);
143 ok(psz == NULL, "psz was %s\n", wine_dbgstr_w(psz));
144 ok_int(fetched, 0);
145 CoTaskMemFree(psz);
146
147 if (pSrc)
148 pSrc->Release();
149}
150
151static void Test_CheckValues(void)
152{
153 IQuerySourceOld *pSrc = NULL;
155 IID_IQuerySourceOld, (PVOID*)&pSrc);
156 ok_hr(hr, S_OK);
157 ok(pSrc != NULL, "pSrc was NULL\n");
158
160
161 // QueryValueString
162 hr = 0xDEADFACE;
163 pszValue = NULL;
164 if (pSrc)
165 hr = pSrc->QueryValueString(NULL, L"ValueA", &pszValue);
166 ok_hr(hr, S_OK);
167 ok(lstrcmpiW(pszValue, L"hello") == 0, "pszValue was %s\n", wine_dbgstr_w(pszValue));
168
169 hr = 0xDEADFACE;
170 pszValue = NULL;
171 if (pSrc)
172 hr = pSrc->QueryValueString(NULL, L"ValueB", &pszValue);
174 ok(pszValue == NULL, "pszValue was %s\n", wine_dbgstr_w(pszValue));
175
176 // QueryValueExists
177 hr = 0xDEADFACE;
178 if (pSrc)
179 hr = pSrc->QueryValueExists(NULL, L"ValueA");
180 ok_hr(hr, S_OK);
181 if (pSrc)
182 hr = pSrc->QueryValueExists(NULL, L"ValueB");
183 ok_hr(hr, S_OK);
184
185 DWORD dwValue;
186
187 // QueryValueDword
188 dwValue = 0xDEADFACE;
189 hr = 0xDEADFACE;
190 if (pSrc)
191 hr = pSrc->QueryValueDword(NULL, L"ValueA", &dwValue);
193 ok_long(dwValue, 0xDEADFACE);
194
195 dwValue = 0xDEADFACE;
196 hr = 0xDEADFACE;
197 if (pSrc)
198 hr = pSrc->QueryValueDword(NULL, L"ValueB", &dwValue);
199 ok_hr(hr, S_OK);
200 ok_long(dwValue, 0xBEEFCAFE);
201
202 FLAGGED_BYTE_BLOB *pBlob;
203
204 // QueryValueDirect
205 hr = 0xDEADFACE;
206 pBlob = NULL;
207 if (pSrc)
208 hr = pSrc->QueryValueDirect(NULL, L"ValueA", &pBlob);
209 ok_hr(hr, S_OK);
210 ok(pBlob != NULL, "pBlob was %p\n", pBlob);
211 ok(pBlob && pBlob->clSize == 12, "pBlob->clSize was %ld\n", pBlob->clSize);
212 ok(pBlob && !memcmp(pBlob->abData, L"hello", 12), "pBlob->abData mismatch\n");
213 CoTaskMemFree(pBlob);
214
215 hr = 0xDEADFACE;
216 pBlob = NULL;
217 if (pSrc)
218 hr = pSrc->QueryValueDirect(NULL, L"ValueB", &pBlob);
219 ok_hr(hr, S_OK);
220 ok(pBlob != NULL, "pBlob was %p\n", pBlob);
221 ok(pBlob && pBlob->clSize == 4, "pBlob->clSize was %ld\n", pBlob->clSize);
222 dwValue = 0xBEEFCAFE;
223 ok(pBlob && !memcmp(pBlob->abData, &dwValue, sizeof(dwValue)), "pBlob->abData mismatch\n");
224 CoTaskMemFree(pBlob);
225
226 if (pSrc)
227 pSrc->Release();
228}
229
231{
233 {
234 skip("Vista+ is not tested well\n");
235 return;
236 }
237
241 {
242 skip("QuerySourceCreateFromKey not found\n");
243 return;
244 }
245
246 HRESULT hrCoInit = CoInitialize(NULL);
247
249
253
255
256 if (SUCCEEDED(hrCoInit))
258}
#define ok_hr(status, expected)
Definition: ACListISF.cpp:31
HRESULT(WINAPI * FN_QuerySourceCreateFromKey)(HKEY, PCWSTR, BOOL, REFIID, PVOID *)
static void SetupRegistry(void)
static void CleanupRegistry(void)
static const WCHAR k_SubKeyB[]
static FN_QuerySourceCreateFromKey g_pQuerySourceCreateFromKey
static void Test_CheckValues(void)
static const WCHAR k_SubKeyA[]
static const WCHAR k_Root[]
static void Test_EnumValues(void)
static void Test_EnumSources(void)
#define ok_long(expression, result)
Definition: atltest.h:133
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define ok_int(expression, result)
Definition: atltest.h:134
#define RegCloseKey(hKey)
Definition: registry.h:49
HANDLE HKEY
Definition: registry.h:26
#define ERROR_MORE_DATA
Definition: dderror.h:13
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1096
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: combase.c:2842
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4171
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2802
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:531
DWORD WINAPI SHDeleteKeyW(HKEY hKey, LPCWSTR lpszSubKey)
Definition: reg.c:1588
#define L(x)
Definition: resources.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
HRESULT Next([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] LPOLESTR *rgelt, [out] ULONG *pceltFetched)
ULONG Release()
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define wine_dbgstr_w
Definition: kernel32.h:34
#define REG_SZ
Definition: layer.c:22
void WINAPI CoTaskMemFree(void *ptr)
Definition: malloc.c:389
static HTREEITEM hRoot
Definition: treeview.c:383
#define KEY_ALL_ACCESS
Definition: nt_native.h:1044
#define BOOL
Definition: nt_native.h:43
short WCHAR
Definition: pedump.c:58
#define REFIID
Definition: guiddef.h:118
_In_opt_ LPCSTR _In_opt_ LPCSTR pszValue
Definition: shlwapi.h:783
EXTERN_C HRESULT WINAPI QuerySourceCreateFromKey(_In_ HKEY hKey, _In_opt_ PCWSTR lpSubKey, _In_ BOOL bCreate, _In_ REFIID riid, _Outptr_ PVOID *ppv)
Definition: querysrc.cpp:494
#define REG_DWORD
Definition: sdbapi.c:615
#define E_DATATYPE_MISMATCH
uint16_t * PWSTR
Definition: typedefs.h:56
const uint16_t * PCWSTR
Definition: typedefs.h:57
uint16_t * LPWSTR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
VERSIONHELPERAPI IsWindowsVistaOrGreater()
#define HRESULT
Definition: msvc.h:7
#define WINAPI
Definition: msvc.h:6
#define S_FALSE
Definition: winerror.h:3451
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581
unsigned char BYTE
Definition: xxhash.c:193