ReactOS 0.4.17-dev-684-ga6524ef
QuerySourceCreateFromKey.cpp File Reference
#include <apitest.h>
#include <shlobj.h>
#include <shlwapi.h>
#include <shlguid_undoc.h>
#include <shlobj_undoc.h>
#include <shlwapi_undoc.h>
#include <versionhelpers.h>
Include dependency graph for QuerySourceCreateFromKey.cpp:

Go to the source code of this file.

Typedefs

typedef HRESULT(WINAPIFN_QuerySourceCreateFromKey) (HKEY, PCWSTR, BOOL, REFIID, PVOID *)
 

Functions

template<class T >
static LONG SafeRelease (T *p)
 
static HRESULT QSCFK (HKEY hKey, PCWSTR pszKey, BOOL Create, REFIID riid, PVOID *ppv)
 
static HRESULT ShimverQSCFK (HKEY hKey, PCWSTR pszKey, BOOL Create, PVOID *ppv)
 
static void SetupRegistry (void)
 
static void CleanupRegistry (void)
 
static void Test_EnumValues (void)
 
static void Test_EnumSources (void)
 
static void Test_CheckValues (void)
 
void Test_Version (void)
 
 START_TEST (QuerySourceCreateFromKey)
 

Variables

static FN_QuerySourceCreateFromKey g_pQuerySourceCreateFromKey = NULL
 
static const WCHAR k_Root [] = L"Software\\QuerySrcTest"
 
static const WCHAR k_SubKeyA [] = L"SubKeyA"
 
static const WCHAR k_SubKeyB [] = L"SubKeyB"
 

Typedef Documentation

◆ FN_QuerySourceCreateFromKey

typedef HRESULT(WINAPI * FN_QuerySourceCreateFromKey) (HKEY, PCWSTR, BOOL, REFIID, PVOID *)

Definition at line 16 of file QuerySourceCreateFromKey.cpp.

Function Documentation

◆ CleanupRegistry()

static void CleanupRegistry ( void  )
static

Definition at line 58 of file QuerySourceCreateFromKey.cpp.

59{
61}
static const WCHAR k_Root[]
DWORD WINAPI SHDeleteKeyW(HKEY hkey, const WCHAR *subkey)
Definition: main.c:1886
#define HKEY_CURRENT_USER
Definition: winreg.h:11

Referenced by START_TEST().

◆ QSCFK()

static HRESULT QSCFK ( HKEY  hKey,
PCWSTR  pszKey,
BOOL  Create,
REFIID  riid,
PVOID ppv 
)
static

Definition at line 24 of file QuerySourceCreateFromKey.cpp.

25{
27}
static FN_QuerySourceCreateFromKey g_pQuerySourceCreateFromKey
@ Create
Definition: registry.c:563
#define E_NOTIMPL
Definition: ddrawi.h:99
FxAutoRegKey hKey
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39

Referenced by ShimverQSCFK(), and Test_Version().

◆ SafeRelease()

template<class T >
static LONG SafeRelease ( T p)
static

Definition at line 19 of file QuerySourceCreateFromKey.cpp.

20{
21 return p ? p->Release() : 0;
22}
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by Test_Version().

◆ SetupRegistry()

static void SetupRegistry ( void  )
static

Definition at line 38 of file QuerySourceCreateFromKey.cpp.

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}
static const WCHAR k_SubKeyB[]
static const WCHAR k_SubKeyA[]
#define RegCloseKey(hKey)
Definition: registry.h:49
#define NULL
Definition: types.h:112
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
#define L(x)
Definition: resources.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
#define REG_SZ
Definition: layer.c:22
static HTREEITEM hRoot
Definition: treeview.c:383
#define KEY_ALL_ACCESS
Definition: nt_native.h:1044
short WCHAR
Definition: pedump.c:58
#define REG_DWORD
Definition: sdbapi.c:615
unsigned char BYTE
Definition: xxhash.c:193

Referenced by START_TEST().

◆ ShimverQSCFK()

static HRESULT ShimverQSCFK ( HKEY  hKey,
PCWSTR  pszKey,
BOOL  Create,
PVOID ppv 
)
static

Definition at line 29 of file QuerySourceCreateFromKey.cpp.

30{
31 return QSCFK(hKey, pszKey, Create, IsWindowsVistaOrGreater() ? IID_IQuerySource : IID_IQuerySourceOld, ppv);
32}
static HRESULT QSCFK(HKEY hKey, PCWSTR pszKey, BOOL Create, REFIID riid, PVOID *ppv)
VERSIONHELPERAPI IsWindowsVistaOrGreater()

Referenced by Test_Version().

◆ START_TEST()

START_TEST ( QuerySourceCreateFromKey  )

Definition at line 261 of file QuerySourceCreateFromKey.cpp.

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}
HRESULT(WINAPI * FN_QuerySourceCreateFromKey)(HKEY, PCWSTR, BOOL, REFIID, PVOID *)
static void SetupRegistry(void)
static void CleanupRegistry(void)
static void Test_CheckValues(void)
void Test_Version(void)
static void Test_EnumValues(void)
static void Test_EnumSources(void)
#define skip(...)
Definition: atltest.h:64
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
HRESULT WINAPI CoInitialize(LPVOID lpReserved)
Definition: compobj.c:531
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581

◆ Test_CheckValues()

static void Test_CheckValues ( void  )
static

Definition at line 166 of file QuerySourceCreateFromKey.cpp.

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}
#define ok_hr(status, expected)
Definition: ACListISF.cpp:31
#define ok_long(expression, result)
Definition: atltest.h:133
#define ok(value,...)
Definition: atltest.h:57
#define ERROR_MORE_DATA
Definition: dderror.h:13
HRESULT hr
Definition: delayimp.cpp:582
#define FALSE
Definition: types.h:117
void WINAPI CoTaskMemFree(void *ptr)
Definition: malloc.c:389
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
#define S_OK
Definition: intsafe.h:52
#define wine_dbgstr_w
Definition: kernel32.h:34
_In_opt_ LPCSTR _In_opt_ LPCSTR pszValue
Definition: shlwapi.h:783
#define E_DATATYPE_MISMATCH
uint16_t * PWSTR
Definition: typedefs.h:56
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210

Referenced by START_TEST().

◆ Test_EnumSources()

static void Test_EnumSources ( void  )
static

Definition at line 116 of file QuerySourceCreateFromKey.cpp.

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}
#define ok_int(expression, result)
Definition: atltest.h:134
HRESULT Next([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] LPOLESTR *rgelt, [out] ULONG *pceltFetched)
uint16_t * LPWSTR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
#define S_FALSE
Definition: winerror.h:3451

Referenced by START_TEST().

◆ Test_EnumValues()

static void Test_EnumValues ( void  )
static

Definition at line 63 of file QuerySourceCreateFromKey.cpp.

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}
ULONG Release()

Referenced by START_TEST().

◆ Test_Version()

void Test_Version ( void  )

Definition at line 245 of file QuerySourceCreateFromKey.cpp.

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}
static HRESULT ShimverQSCFK(HKEY hKey, PCWSTR pszKey, BOOL Create, PVOID *ppv)
static LONG SafeRelease(T *p)
const GUID IID_IUnknown
#define E_FAIL
Definition: ddrawi.h:102
static void *static void *static LPDIRECTPLAY IUnknown * pUnk
Definition: dplayx.c:30
nsresult QueryInterface(nsIIDRef riid, void **result)
#define REFIID
Definition: guiddef.h:118

Referenced by START_TEST().

Variable Documentation

◆ g_pQuerySourceCreateFromKey

FN_QuerySourceCreateFromKey g_pQuerySourceCreateFromKey = NULL
static

◆ k_Root

const WCHAR k_Root[] = L"Software\\QuerySrcTest"
static

◆ k_SubKeyA

const WCHAR k_SubKeyA[] = L"SubKeyA"
static

Definition at line 35 of file QuerySourceCreateFromKey.cpp.

Referenced by SetupRegistry(), and Test_EnumSources().

◆ k_SubKeyB

const WCHAR k_SubKeyB[] = L"SubKeyB"
static

Definition at line 36 of file QuerySourceCreateFromKey.cpp.

Referenced by SetupRegistry(), and Test_EnumSources().