ReactOS 0.4.16-dev-197-g92996da
VerQueryValue.c File Reference
#include "precomp.h"
Include dependency graph for VerQueryValue.c:

Go to the source code of this file.

Classes

struct  TEST_VERSIONINFO
 
struct  TEST_VERSIONINFO::_StringFileInfo
 
struct  TEST_VERSIONINFO::_StringFileInfo::_StringTable
 
struct  TEST_VERSIONINFO::_StringFileInfo::_StringTable::_String_CompanyName
 
struct  TEST_VERSIONINFO::_StringFileInfo::_StringTable::_String_Comments
 
struct  TEST_VERSIONINFO::_StringFileInfo::_StringTable::_String_Comments2
 
struct  TEST_VERSIONINFO::_StringFileInfo::_StringTable::_String_FooBar
 

Functions

void Test_VerQueryValueA (void)
 
void Test_VerQueryValueW (void)
 
void Test_StaticVersionInfo (void)
 
 START_TEST (VerQueryValue)
 

Variables

static const TEST_VERSIONINFO g_VersionInfo
 

Function Documentation

◆ START_TEST()

START_TEST ( VerQueryValue  )

Definition at line 297 of file VerQueryValue.c.

298{
302}
void Test_VerQueryValueA(void)
void Test_StaticVersionInfo(void)
void Test_VerQueryValueW(void)

◆ Test_StaticVersionInfo()

void Test_StaticVersionInfo ( void  )

Definition at line 238 of file VerQueryValue.c.

239{
240 PVOID pVersionInfo;
241 PVOID pvData = NULL;
242 SIZE_T ExpectedOffset;
243 UINT cbLen;
244 BOOL result;
245
246 /* Make a copy of the version info. Windows actually writes to it!
247 We make the buffer twice as big to account for the ANSI copy,
248 even if we don't use it. */
249 pVersionInfo = malloc(2 * sizeof(g_VersionInfo));
250 memset(pVersionInfo, 0, 2 * sizeof(g_VersionInfo));
251 memcpy(pVersionInfo, &g_VersionInfo, sizeof(g_VersionInfo));
252
253 /* Test a special static version */
254 result = VerQueryValueW(pVersionInfo,
255 L"\\StringFileInfo\\000004B0\\CompanyName",
256 &pvData,
257 &cbLen);
258 ok(result, "VerQueryValueW failed\n");
259 ok_eq_int(cbLen, 16);
260 ok_eq_wstr((WCHAR*)pvData, L"ReactOS Project");
261 ExpectedOffset = FIELD_OFFSET(TEST_VERSIONINFO, StringFileInfo.StringTable.CompanyName.Value);
262 ok(pvData == (PVOID)((ULONG_PTR)pVersionInfo + ExpectedOffset), "Unexpected offset\n");
263
264 result = VerQueryValueW(pVersionInfo,
265 L"\\StringFileInfo\\000004B0\\Comments",
266 &pvData,
267 &cbLen);
268 ok(result, "VerQueryValueW failed\n");
269 ok_eq_int(cbLen, 0);
270 ok_eq_wstr((WCHAR*)pvData, L"");
271 ExpectedOffset = FIELD_OFFSET(TEST_VERSIONINFO, StringFileInfo.StringTable.Comments.szKey[8]);
272 ok(pvData == (PVOID)((ULONG_PTR)pVersionInfo + ExpectedOffset), "Unexpected offset\n");
273
274 result = VerQueryValueW(pVersionInfo,
275 L"\\StringFileInfo\\000004B0\\Comments2",
276 &pvData,
277 &cbLen);
278 ok(result, "VerQueryValueW failed\n");
279 ok_eq_int(cbLen, 0);
280 ok_eq_wstr((WCHAR*)pvData, L"");
281 ExpectedOffset = FIELD_OFFSET(TEST_VERSIONINFO, StringFileInfo.StringTable.Comments2.szKey[9]);
282 ok(pvData == (PVOID)((ULONG_PTR)pVersionInfo + ExpectedOffset), "Unexpected offset\n");
283
284 result = VerQueryValueW(pVersionInfo,
285 L"\\StringFileInfo\\000004B0\\FooBar",
286 &pvData,
287 &cbLen);
288 ok(result, "VerQueryValueW failed\n");
289 ok_eq_int(cbLen, 4);
290 ok(wcscmp((WCHAR*)pvData, L"Bar") == 0, "Bar\n");
291 ExpectedOffset = FIELD_OFFSET(TEST_VERSIONINFO, StringFileInfo.StringTable.FooBar.Value);
292 ok(pvData == (PVOID)((ULONG_PTR)pVersionInfo + ExpectedOffset), "Unexpected offset\n");
293
294 free(pVersionInfo);
295}
static const TEST_VERSIONINFO g_VersionInfo
Definition: VerQueryValue.c:73
#define ok_eq_wstr(value, expected)
Definition: apitest.h:84
#define ok_eq_int(value, expected)
Definition: apitest.h:60
#define ok(value,...)
Definition: atltest.h:57
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
BOOL WINAPI VerQueryValueW(LPCVOID pBlock, LPCWSTR lpSubBlock, LPVOID *lplpBuffer, PUINT puLen)
Definition: version.c:1057
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint64EXT * result
Definition: glext.h:11304
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define memset(x, y, z)
Definition: compat.h:39
VS_FIXEDFILEINFO Value
Definition: VerQueryValue.c:17
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_ ULONG _In_opt_ PVOID pvData
Definition: winddi.h:3749
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ Test_VerQueryValueA()

void Test_VerQueryValueA ( void  )

Definition at line 146 of file VerQueryValue.c.

147{
148 DWORD dwVersionInfoSizeW, dwVersionInfoSizeA;
149 PVOID pvVersionInfoA, pvData = NULL;
150 CHAR szSubBlock[256];
151 USHORT uLanguage, uCodePage;
152 UINT cbLen;
153 BOOL result;
154
155 /* Get the size for the unicode version info */
156 dwVersionInfoSizeW = GetFileVersionInfoSizeW(L"kernel32.dll", NULL);
157 ok(dwVersionInfoSizeW > 0, "GetFileVersionInfoSizeW failed\n");
158
159 /* Get the size for the ANSI version info */
160 dwVersionInfoSizeA = GetFileVersionInfoSizeA("kernel32.dll", NULL);
161 ok(dwVersionInfoSizeA > 0, "GetFileVersionInfoSizeA failed\n");
162 ok(dwVersionInfoSizeA == dwVersionInfoSizeW, "Unexpected size\n");
163
164 /* Get the ANSI version info from kernel32 */
165 pvVersionInfoA = malloc(dwVersionInfoSizeA);
166 memset(pvVersionInfoA, 0xCC, dwVersionInfoSizeA);
167 result = GetFileVersionInfoA("kernel32.dll", 0, dwVersionInfoSizeA, pvVersionInfoA);
168 ok(result, "GetFileVersionInfoA failed\n");
169
170 /* Query available translations */
171 result = VerQueryValueA(pvVersionInfoA,
172 "\\VarFileInfo\\Translation",
173 &pvData,
174 &cbLen);
175 ok(result, "VerQueryValueA failed\n");
176 ok(cbLen >= 4, "Unexpected value\n");
177 ok((cbLen & 0x3) == 0, "Unexpected value\n");
178 uLanguage = ((USHORT*)pvData)[0];
179 uCodePage = ((USHORT*)pvData)[1];
180
181 /* Query sublock */
182 sprintf(szSubBlock, "\\StringFileInfo\\%04X%04X\\CompanyName", uLanguage, uCodePage);
183 result = VerQueryValueA(pvVersionInfoA,
184 szSubBlock,
185 &pvData,
186 &cbLen);
187 ok(result, "VerQueryValueA failed\n");
188 ok(cbLen >= 2, "Unexpected value\n");
189 ok((cbLen & 0x1) == 0, "Unexpected value\n");
190
191 free(pvVersionInfoA);
192}
DWORD WINAPI GetFileVersionInfoSizeA(LPCSTR filename, LPDWORD handle)
Definition: version.c:619
BOOL WINAPI VerQueryValueA(LPCVOID pBlock, LPCSTR lpSubBlock, LPVOID *lplpBuffer, PUINT puLen)
Definition: version.c:1001
BOOL WINAPI GetFileVersionInfoA(LPCSTR filename, DWORD handle, DWORD datasize, LPVOID data)
Definition: version.c:853
DWORD WINAPI GetFileVersionInfoSizeW(LPCWSTR filename, LPDWORD handle)
Definition: version.c:611
unsigned long DWORD
Definition: ntddk_ex.h:95
#define sprintf(buf, format,...)
Definition: sprintf.c:55
unsigned short USHORT
Definition: pedump.c:61
char CHAR
Definition: xmlstorage.h:175

Referenced by START_TEST().

◆ Test_VerQueryValueW()

void Test_VerQueryValueW ( void  )

Definition at line 195 of file VerQueryValue.c.

196{
197 DWORD dwVersionInfoSizeW;
198 PVOID pvVersionInfoW, pvData = NULL;
199 WCHAR szSubBlock[256];
200 USHORT uLanguage, uCodePage;
201 UINT cbLen;
202 BOOL result;
203
204 /* Get the size for the unicode version info */
205 dwVersionInfoSizeW = GetFileVersionInfoSizeW(L"kernel32.dll", NULL);
206 ok(dwVersionInfoSizeW > 0, "GetFileVersionInfoSizeW failed\n");
207
208 /* Get the unicode version info from kernel32 */
209 pvVersionInfoW = malloc(dwVersionInfoSizeW);
210 result = GetFileVersionInfoW(L"kernel32.dll", 0, dwVersionInfoSizeW, pvVersionInfoW);
211 ok(result, "GetFileVersionInfoW failed\n");
212
213 /* Query available translations */
214 result = VerQueryValueW(pvVersionInfoW,
215 L"\\VarFileInfo\\Translation",
216 &pvData,
217 &cbLen);
218 ok(result, "VerQueryValueA failed\n");
219 ok(cbLen >= 4, "Unexpected value\n");
220 ok((cbLen & 0x3) == 0, "Unexpected value\n");
221 uLanguage = ((USHORT*)pvData)[0];
222 uCodePage = ((USHORT*)pvData)[1];
223
224 /* Query sublock */
225 _swprintf(szSubBlock, L"\\StringFileInfo\\%04X%04X\\CompanyName", uLanguage, uCodePage);
226 result = VerQueryValueW(pvVersionInfoW,
227 szSubBlock,
228 &pvData,
229 &cbLen);
230 ok(result, "VerQueryValueA failed\n");
231 ok(cbLen >= 2, "Unexpected value\n");
232 ok((cbLen & 0x1) == 0, "Unexpected value\n");
233
234 free(pvVersionInfoW);
235}
BOOL WINAPI GetFileVersionInfoW(LPCWSTR filename, DWORD handle, DWORD datasize, LPVOID data)
Definition: version.c:845
int _swprintf(wchar_t *buffer, const wchar_t *format,...)

Referenced by START_TEST().

Variable Documentation

◆ g_VersionInfo

const TEST_VERSIONINFO g_VersionInfo
static

Definition at line 73 of file VerQueryValue.c.

Referenced by Test_StaticVersionInfo().