ReactOS 0.4.17-dev-684-ga6524ef
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
19template<class T> static LONG SafeRelease(T *p)
20{
21 return p ? p->Release() : 0;
22}
23
25{
27}
28
30{
31 return QSCFK(hKey, pszKey, Create, IsWindowsVistaOrGreater() ? IID_IQuerySource : IID_IQuerySourceOld, ppv);
32}
33
34static const WCHAR k_Root[] = L"Software\\QuerySrcTest";
35static const WCHAR k_SubKeyA[] = L"SubKeyA";
36static const WCHAR k_SubKeyB[] = L"SubKeyB";
37
38static void SetupRegistry(void)
39{
40 HKEY hRoot;
42
43 static const WCHAR valA[] = L"hello";
44 RegSetValueExW(hRoot, L"ValueA", 0, REG_SZ, (const BYTE*)valA, (DWORD)sizeof(valA));
45
46 DWORD dwValue = 0xBEEFCAFE;
47 RegSetValueExW(hRoot, L"ValueB", 0, REG_DWORD, (const BYTE*)&dwValue, (DWORD)sizeof(dwValue));
48
49 HKEY hSub;
51 RegCloseKey(hSub);
53 RegCloseKey(hSub);
54
56}
57
58static void CleanupRegistry(void)
59{
61}
62
63static void Test_EnumValues(void)
64{
65 IQuerySourceOld *pSrc = NULL;
67 IID_IQuerySourceOld, (PVOID*)&pSrc);
68 ok_hr(hr, S_OK);
69 ok(pSrc != NULL, "pSrc was NULL\n");
70
71 IEnumString *pEnum = NULL;
72 hr = 0xDEADFACE;
73 if (pSrc)
74 hr = pSrc->EnumValues(&pEnum);
75 ok(pSrc && hr == S_OK, "EnumValues failed: 0x%08X\n", hr);
76
77 LPWSTR psz = NULL;
78 ULONG fetched = 0;
79 hr = 0xDEADFACE;
80
81 if (pEnum)
82 hr = pEnum->Next(1, &psz, &fetched);
83 ok_hr(hr, S_OK);
84 ok(lstrcmpiW(psz, L"ValueA") == 0, "psz was %s\n", wine_dbgstr_w(psz));
85 ok_int(fetched, 1);
86 CoTaskMemFree(psz);
87
88 psz = NULL;
89 fetched = 0;
90 hr = 0xDEADFACE;
91
92 if (pEnum)
93 hr = pEnum->Next(1, &psz, &fetched);
94 ok_hr(hr, S_OK);
95 ok(lstrcmpiW(psz, L"ValueB") == 0, "psz was %s\n", wine_dbgstr_w(psz));
96 ok_int(fetched, 1);
97 CoTaskMemFree(psz);
98
99 psz = NULL;
100 fetched = 0;
101 hr = 0xDEADFACE;
102
103 if (pEnum)
104 hr = pEnum->Next(1, &psz, &fetched);
105 ok_hr(hr, S_FALSE);
106 ok(psz == NULL, "psz was %s\n", wine_dbgstr_w(psz));
107 ok_int(fetched, 0);
108 CoTaskMemFree(psz);
109
110 if (pEnum)
111 pEnum->Release();
112 if (pSrc)
113 pSrc->Release();
114}
115
116static void Test_EnumSources(void)
117{
118 IQuerySourceOld *pSrc = NULL;
120 IID_IQuerySourceOld, (PVOID*)&pSrc);
121 ok_hr(hr, S_OK);
122 ok(pSrc != NULL, "pSrc was NULL\n");
123
124 IEnumString *pEnum = NULL;
125 hr = pSrc->EnumSources(&pEnum);
126 ok_hr(hr, S_OK);
127 ok(pEnum != NULL, "pEnum was NULL\n");
128
129 LPWSTR psz = NULL;
130 ULONG fetched = 0;
131 hr = 0xDEADFACE;
132
133 if (pEnum)
134 hr = pEnum->Next(1, &psz, &fetched);
135 ok_hr(hr, S_OK);
136 ok(lstrcmpiW(psz, k_SubKeyA) == 0, "psz was %s\n", wine_dbgstr_w(psz));
137 ok_int(fetched, 1);
138 CoTaskMemFree(psz);
139
140 psz = NULL;
141 fetched = 0;
142 hr = 0xDEADFACE;
143
144 if (pEnum)
145 hr = pEnum->Next(1, &psz, &fetched);
146 ok_hr(hr, S_OK);
147 ok(lstrcmpiW(psz, k_SubKeyB) == 0, "psz was %s\n", wine_dbgstr_w(psz));
148 ok_int(fetched, 1);
149 CoTaskMemFree(psz);
150
151 psz = NULL;
152 fetched = 0;
153 hr = 0xDEADFACE;
154
155 if (pEnum)
156 hr = pEnum->Next(1, &psz, &fetched);
157 ok_hr(hr, S_FALSE);
158 ok(psz == NULL, "psz was %s\n", wine_dbgstr_w(psz));
159 ok_int(fetched, 0);
160 CoTaskMemFree(psz);
161
162 if (pSrc)
163 pSrc->Release();
164}
165
166static void Test_CheckValues(void)
167{
168 IQuerySourceOld *pSrc = NULL;
170 IID_IQuerySourceOld, (PVOID*)&pSrc);
171 ok_hr(hr, S_OK);
172 ok(pSrc != NULL, "pSrc was NULL\n");
173
175
176 // QueryValueString
177 hr = 0xDEADFACE;
178 pszValue = NULL;
179 if (pSrc)
180 hr = pSrc->QueryValueString(NULL, L"ValueA", &pszValue);
181 ok_hr(hr, S_OK);
182 ok(lstrcmpiW(pszValue, L"hello") == 0, "pszValue was %s\n", wine_dbgstr_w(pszValue));
183
184 hr = 0xDEADFACE;
185 pszValue = NULL;
186 if (pSrc)
187 hr = pSrc->QueryValueString(NULL, L"ValueB", &pszValue);
189 ok(pszValue == NULL, "pszValue was %s\n", wine_dbgstr_w(pszValue));
190
191 // QueryValueExists
192 hr = 0xDEADFACE;
193 if (pSrc)
194 hr = pSrc->QueryValueExists(NULL, L"ValueA");
195 ok_hr(hr, S_OK);
196 if (pSrc)
197 hr = pSrc->QueryValueExists(NULL, L"ValueB");
198 ok_hr(hr, S_OK);
199
200 DWORD dwValue;
201
202 // QueryValueDword
203 dwValue = 0xDEADFACE;
204 hr = 0xDEADFACE;
205 if (pSrc)
206 hr = pSrc->QueryValueDword(NULL, L"ValueA", &dwValue);
208 ok_long(dwValue, 0xDEADFACE);
209
210 dwValue = 0xDEADFACE;
211 hr = 0xDEADFACE;
212 if (pSrc)
213 hr = pSrc->QueryValueDword(NULL, L"ValueB", &dwValue);
214 ok_hr(hr, S_OK);
215 ok_long(dwValue, 0xBEEFCAFE);
216
217 FLAGGED_BYTE_BLOB *pBlob;
218
219 // QueryValueDirect
220 hr = 0xDEADFACE;
221 pBlob = NULL;
222 if (pSrc)
223 hr = pSrc->QueryValueDirect(NULL, L"ValueA", &pBlob);
224 ok_hr(hr, S_OK);
225 ok(pBlob != NULL, "pBlob was %p\n", pBlob);
226 ok(pBlob && pBlob->clSize == 12, "pBlob->clSize was %ld\n", pBlob->clSize);
227 ok(pBlob && !memcmp(pBlob->abData, L"hello", 12), "pBlob->abData mismatch\n");
228 CoTaskMemFree(pBlob);
229
230 hr = 0xDEADFACE;
231 pBlob = NULL;
232 if (pSrc)
233 hr = pSrc->QueryValueDirect(NULL, L"ValueB", &pBlob);
234 ok_hr(hr, S_OK);
235 ok(pBlob != NULL, "pBlob was %p\n", pBlob);
236 ok(pBlob && pBlob->clSize == 4, "pBlob->clSize was %ld\n", pBlob->clSize);
237 dwValue = 0xBEEFCAFE;
238 ok(pBlob && !memcmp(pBlob->abData, &dwValue, sizeof(dwValue)), "pBlob->abData mismatch\n");
239 CoTaskMemFree(pBlob);
240
241 if (pSrc)
242 pSrc->Release();
243}
244
245void Test_Version(void)
246{
247 IUnknown *pUnk, *pUnk2;
248 REFIID riidQS = IsWindowsVistaOrGreater() ? IID_IQuerySource : IID_IQuerySourceOld;
249 HRESULT hr;
251 ok_hr(hr, S_OK);
253
255 hr = pUnk ? pUnk->QueryInterface(riidQS, (void**)&pUnk2) : E_FAIL;
256 ok_hr(hr, S_OK);
257 SafeRelease(pUnk2);
259}
260
262{
264 {
265 skip("Vista+ is not tested well\n");
266 return;
267 }
268
272 {
273 skip("QuerySourceCreateFromKey not found\n");
274 return;
275 }
276
277 HRESULT hrCoInit = CoInitialize(NULL);
278
280
284 Test_Version();
285
287
288 if (SUCCEEDED(hrCoInit))
290}
#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 HRESULT QSCFK(HKEY hKey, PCWSTR pszKey, BOOL Create, REFIID riid, PVOID *ppv)
static const WCHAR k_SubKeyB[]
static FN_QuerySourceCreateFromKey g_pQuerySourceCreateFromKey
static void Test_CheckValues(void)
void Test_Version(void)
static const WCHAR k_SubKeyA[]
static const WCHAR k_Root[]
static void Test_EnumValues(void)
static void Test_EnumSources(void)
static HRESULT ShimverQSCFK(HKEY hKey, PCWSTR pszKey, BOOL Create, PVOID *ppv)
static LONG SafeRelease(T *p)
#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
@ Create
Definition: registry.c:563
const GUID IID_IUnknown
#define RegCloseKey(hKey)
Definition: registry.h:49
HANDLE HKEY
Definition: registry.h:26
#define ERROR_MORE_DATA
Definition: dderror.h:13
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
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
void WINAPI CoTaskMemFree(void *ptr)
Definition: malloc.c:389
#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:2807
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:531
DWORD WINAPI SHDeleteKeyW(HKEY hkey, const WCHAR *subkey)
Definition: main.c:1886
static void *static void *static LPDIRECTPLAY IUnknown * pUnk
Definition: dplayx.c:30
#define L(x)
Definition: resources.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
GLfloat GLfloat p
Definition: glext.h:8902
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
HRESULT Next([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] LPOLESTR *rgelt, [out] ULONG *pceltFetched)
ULONG Release()
nsresult QueryInterface(nsIIDRef riid, void **result)
#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
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
long LONG
Definition: pedump.c:60
#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:577
#define T(num)
Definition: thunks.c:311
#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