ReactOS 0.4.17-dev-243-g1369312
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

static void SetupRegistry (void)
 
static void CleanupRegistry (void)
 
static void Test_EnumValues (void)
 
static void Test_EnumSources (void)
 
static void Test_CheckValues (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 43 of file QuerySourceCreateFromKey.cpp.

44{
46}
static const WCHAR k_Root[]
DWORD WINAPI SHDeleteKeyW(HKEY hKey, LPCWSTR lpszSubKey)
Definition: reg.c:1588
#define HKEY_CURRENT_USER
Definition: winreg.h:11

Referenced by START_TEST().

◆ SetupRegistry()

static void SetupRegistry ( void  )
static

Definition at line 23 of file QuerySourceCreateFromKey.cpp.

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}
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().

◆ START_TEST()

START_TEST ( QuerySourceCreateFromKey  )

Definition at line 230 of file QuerySourceCreateFromKey.cpp.

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}
HRESULT(WINAPI * FN_QuerySourceCreateFromKey)(HKEY, PCWSTR, BOOL, REFIID, PVOID *)
static void SetupRegistry(void)
static void CleanupRegistry(void)
static FN_QuerySourceCreateFromKey g_pQuerySourceCreateFromKey
static void Test_CheckValues(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
VERSIONHELPERAPI IsWindowsVistaOrGreater()
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581

◆ Test_CheckValues()

static void Test_CheckValues ( void  )
static

Definition at line 151 of file QuerySourceCreateFromKey.cpp.

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}
#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
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
#define S_OK
Definition: intsafe.h:52
#define wine_dbgstr_w
Definition: kernel32.h:34
void WINAPI CoTaskMemFree(void *ptr)
Definition: malloc.c:389
_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 101 of file QuerySourceCreateFromKey.cpp.

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}
#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 48 of file QuerySourceCreateFromKey.cpp.

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

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 20 of file QuerySourceCreateFromKey.cpp.

Referenced by SetupRegistry(), and Test_EnumSources().

◆ k_SubKeyB

const WCHAR k_SubKeyB[] = L"SubKeyB"
static

Definition at line 21 of file QuerySourceCreateFromKey.cpp.

Referenced by SetupRegistry(), and Test_EnumSources().