[APPHELP_APITEST] Add tests for ApphelpCheckRunApp[Ex], SdbGetMatchingExe, Sdb[Un...
[reactos.git] / rostests / apitests / apphelp / apphelp.c
1 /*
2 * Copyright 2012 Detlef Riekenberg
3 * Copyright 2013 Mislav Blažević
4 * Copyright 2015,2016 Mark Jansen
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21
22 #include <ntstatus.h>
23 #define WIN32_NO_STATUS
24 #include <windows.h>
25 #include <shlwapi.h>
26 #include <winnt.h>
27 #ifdef __REACTOS__
28 #include <ntndk.h>
29 #else
30 #include <winternl.h>
31 #endif
32
33 #include <winerror.h>
34 #include <stdio.h>
35 #include <initguid.h>
36 #include <shlguid.h>
37 #include <shobjidl.h>
38
39 #include "wine/test.h"
40
41 #include "apphelp_apitest.h"
42
43
44 #define TAG_TYPE_MASK 0xF000
45
46 #define TAG_TYPE_NULL 0x1000
47 #define TAG_TYPE_BYTE 0x2000
48 #define TAG_TYPE_WORD 0x3000
49 #define TAG_TYPE_DWORD 0x4000
50 #define TAG_TYPE_QWORD 0x5000
51 #define TAG_TYPE_STRINGREF 0x6000
52 #define TAG_TYPE_LIST 0x7000
53 #define TAG_TYPE_STRING 0x8000
54 #define TAG_TYPE_BINARY 0x9000
55 #define TAG_NULL 0x0
56 #define TAG_SIZE (0x1 | TAG_TYPE_DWORD)
57 #define TAG_CHECKSUM (0x3 | TAG_TYPE_DWORD)
58 #define TAG_MODULE_TYPE (0x6 | TAG_TYPE_DWORD)
59 #define TAG_VERDATEHI (0x7 | TAG_TYPE_DWORD)
60 #define TAG_VERDATELO (0x8 | TAG_TYPE_DWORD)
61 #define TAG_VERFILEOS (0x9 | TAG_TYPE_DWORD)
62 #define TAG_VERFILETYPE (0xA | TAG_TYPE_DWORD)
63 #define TAG_PE_CHECKSUM (0xB | TAG_TYPE_DWORD)
64 #define TAG_VER_LANGUAGE (0x12 | TAG_TYPE_DWORD)
65 #define TAG_LINKER_VERSION (0x1C | TAG_TYPE_DWORD)
66 #define TAG_LINK_DATE (0x1D | TAG_TYPE_DWORD)
67 #define TAG_UPTO_LINK_DATE (0x1E | TAG_TYPE_DWORD)
68 #define TAG_EXE_WRAPPER (0x31 | TAG_TYPE_DWORD)
69 #define TAG_BIN_FILE_VERSION (0x2 | TAG_TYPE_QWORD)
70 #define TAG_BIN_PRODUCT_VERSION (0x3 | TAG_TYPE_QWORD)
71 #define TAG_UPTO_BIN_PRODUCT_VERSION (0x6 | TAG_TYPE_QWORD)
72 #define TAG_UPTO_BIN_FILE_VERSION (0xD | TAG_TYPE_QWORD)
73 #define TAG_NAME (0x1 | TAG_TYPE_STRINGREF)
74 #define TAG_COMPANY_NAME (0x9 | TAG_TYPE_STRINGREF)
75 #define TAG_PRODUCT_NAME (0x10 | TAG_TYPE_STRINGREF)
76 #define TAG_PRODUCT_VERSION (0x11 | TAG_TYPE_STRINGREF)
77 #define TAG_FILE_DESCRIPTION (0x12 | TAG_TYPE_STRINGREF)
78 #define TAG_FILE_VERSION (0x13 | TAG_TYPE_STRINGREF)
79 #define TAG_ORIGINAL_FILENAME (0x14 | TAG_TYPE_STRINGREF)
80 #define TAG_INTERNAL_NAME (0x15 | TAG_TYPE_STRINGREF)
81 #define TAG_LEGAL_COPYRIGHT (0x16 | TAG_TYPE_STRINGREF)
82 #define TAG_16BIT_DESCRIPTION (0x17 | TAG_TYPE_STRINGREF)
83 #define TAG_16BIT_MODULE_NAME (0x20 | TAG_TYPE_STRINGREF)
84 #define TAG_EXPORT_NAME (0x24 | TAG_TYPE_STRINGREF)
85
86
87 #define ATTRIBUTE_AVAILABLE 0x1
88 #define ATTRIBUTE_FAILED 0x2
89
90 typedef struct tagATTRINFO {
91 TAG type;
92 DWORD flags; /* ATTRIBUTE_AVAILABLE, ATTRIBUTE_FAILED */
93 union {
94 QWORD qwattr;
95 DWORD dwattr;
96 WCHAR *lpattr;
97 };
98 } ATTRINFO, *PATTRINFO;
99
100 static HMODULE hdll;
101 static BOOL (WINAPI *pApphelpCheckShellObject)(REFCLSID, BOOL, ULONGLONG *);
102 static LPCWSTR (WINAPI *pSdbTagToString)(TAG);
103 static BOOL (WINAPI *pSdbGUIDToString)(CONST GUID *, PCWSTR, SIZE_T);
104 static BOOL (WINAPI *pSdbIsNullGUID)(CONST GUID *);
105 static BOOL (WINAPI *pSdbGetStandardDatabaseGUID)(DWORD, GUID*);
106 static BOOL (WINAPI *pSdbGetFileAttributes)(LPCWSTR, PATTRINFO *, LPDWORD);
107 static BOOL (WINAPI *pSdbFreeFileAttributes)(PATTRINFO);
108
109 /* 'Known' database guids */
110 DEFINE_GUID(GUID_DATABASE_MSI,0xd8ff6d16,0x6a3a,0x468a,0x8b,0x44,0x01,0x71,0x4d,0xdc,0x49,0xea);
111 DEFINE_GUID(GUID_DATABASE_SHIM,0x11111111,0x1111,0x1111,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11);
112 DEFINE_GUID(GUID_DATABASE_DRIVERS,0xf9ab2228,0x3312,0x4a73,0xb6,0xf9,0x93,0x6d,0x70,0xe1,0x12,0xef);
113
114 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
115
116 DEFINE_GUID(test_Microsoft_Browser_Architecture, 0xa5e46e3a, 0x8849, 0x11d1, 0x9d, 0x8c, 0x00, 0xc0, 0x4f, 0xc9, 0x9d, 0x61);
117 DEFINE_GUID(test_UserAssist, 0xdd313e04, 0xfeff, 0x11d1, 0x8e, 0xcd, 0x00, 0x00, 0xf8, 0x7a, 0x47, 0x0c);
118 DEFINE_GUID(CLSID_InternetSecurityManager, 0x7b8a2d94, 0x0ac9, 0x11d1, 0x89, 0x6c, 0x00, 0xc0, 0x4f, 0xB6, 0xbf, 0xc4);
119
120 static const CLSID * objects[] = {
121 &GUID_NULL,
122 /* used by IE */
123 &test_Microsoft_Browser_Architecture,
124 &CLSID_MenuBand,
125 &CLSID_ShellLink,
126 &CLSID_ShellWindows,
127 &CLSID_InternetSecurityManager,
128 &test_UserAssist,
129 (const CLSID *)NULL
130 };
131
132 static void test_ApphelpCheckShellObject(void)
133 {
134 ULONGLONG flags;
135 BOOL res;
136 int i;
137
138 if (!pApphelpCheckShellObject)
139 {
140 win_skip("ApphelpCheckShellObject not available\n");
141 return;
142 }
143
144 for (i = 0; objects[i]; i++)
145 {
146 flags = 0xdeadbeef;
147 SetLastError(0xdeadbeef);
148 res = pApphelpCheckShellObject(objects[i], FALSE, &flags);
149 ok(res && (flags == 0), "%s 0: got %d and 0x%x%08x with 0x%x (expected TRUE and 0)\n",
150 wine_dbgstr_guid(objects[i]), res, (ULONG)(flags >> 32), (ULONG)flags, GetLastError());
151
152 flags = 0xdeadbeef;
153 SetLastError(0xdeadbeef);
154 res = pApphelpCheckShellObject(objects[i], TRUE, &flags);
155 ok(res && (flags == 0), "%s 1: got %d and 0x%x%08x with 0x%x (expected TRUE and 0)\n",
156 wine_dbgstr_guid(objects[i]), res, (ULONG)(flags >> 32), (ULONG)flags, GetLastError());
157
158 }
159
160 /* NULL as pointer to flags is checked */
161 SetLastError(0xdeadbeef);
162 res = pApphelpCheckShellObject(&GUID_NULL, FALSE, NULL);
163 ok(res, "%s 0: got %d with 0x%x (expected != FALSE)\n", wine_dbgstr_guid(&GUID_NULL), res, GetLastError());
164
165 /* NULL as CLSID* crash on Windows */
166 if (0)
167 {
168 flags = 0xdeadbeef;
169 SetLastError(0xdeadbeef);
170 res = pApphelpCheckShellObject(NULL, FALSE, &flags);
171 trace("NULL as CLSID*: got %d and 0x%x%08x with 0x%x\n", res, (ULONG)(flags >> 32), (ULONG)flags, GetLastError());
172 }
173 }
174
175 static void test_SdbTagToString(void)
176 {
177 static const TAG invalid_values[] = {
178 1, TAG_TYPE_WORD, TAG_TYPE_MASK,
179 TAG_TYPE_DWORD | 0xFF,
180 TAG_TYPE_DWORD | (0x800 + 0xEE),
181 0x900, 0xFFFF, 0xDEAD, 0xBEEF
182 };
183 static const WCHAR invalid[] = {'I','n','v','a','l','i','d','T','a','g',0};
184 LPCWSTR ret;
185 WORD i;
186
187 for (i = 0; i < 9; ++i)
188 {
189 ret = pSdbTagToString(invalid_values[i]);
190 ok(lstrcmpW(ret, invalid) == 0, "unexpected string %s, should be %s\n",
191 wine_dbgstr_w(ret), wine_dbgstr_w(invalid));
192 }
193 }
194
195 static int strcmp_wa(LPCWSTR strw, const char *stra)
196 {
197 CHAR buf[512];
198 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), 0, 0);
199 return lstrcmpA(buf, stra);
200 }
201
202 void test_tag(TAG base, const char* names[], size_t upperlimit, int line)
203 {
204 TAG n;
205 for (n = 0; names[n]; ++n)
206 {
207 LPCWSTR tagstr = pSdbTagToString(base | n);
208 ok_(__FILE__, line + 2)(!strcmp_wa(tagstr, names[n]), "Got %s instead of '%s' for %x\n", wine_dbgstr_w(tagstr), names[n], base | n);
209 }
210 for (; n < upperlimit; ++n)
211 {
212 LPCWSTR tagstr = pSdbTagToString(base | n);
213 ok_(__FILE__, line + 2)(!strcmp_wa(tagstr, "InvalidTag"), "Got %s instead of 'InvalidTag' for %x\n", wine_dbgstr_w(tagstr), base | n);
214 }
215 }
216
217 static struct
218 {
219 TAG base;
220 DWORD upper_limit;
221 DWORD line;
222 DWORD min_ver;
223 DWORD max_ver;
224 const char* tags[7*8];
225 } data[] = {
226 {
227 TAG_TYPE_NULL, 0x1000, __LINE__, WINVER_ANY, WINVER_2003,
228 {
229 "InvalidTag", "INCLUDE", "GENERAL", "MATCH_LOGIC_NOT", "APPLY_ALL_SHIMS", "USE_SERVICE_PACK_FILES", NULL
230 }
231 },
232 {
233 TAG_TYPE_NULL, 0x1000, __LINE__, WINVER_VISTA, WINVER_VISTA,
234 {
235 "InvalidTag", "INCLUDE", "GENERAL", "MATCH_LOGIC_NOT", "APPLY_ALL_SHIMS", "USE_SERVICE_PACK_FILES", "MITIGATION_OS", "BLOCK_UPGRADE",
236 "INCLUDEEXCLUDEDLL", NULL
237 }
238 },
239 {
240 TAG_TYPE_NULL, 0x1000, __LINE__, WINVER_WIN7, WINVER_ANY,
241 {
242 "InvalidTag", "INCLUDE", "GENERAL", "MATCH_LOGIC_NOT", "APPLY_ALL_SHIMS", "USE_SERVICE_PACK_FILES", "MITIGATION_OS", "BLOCK_UPGRADE",
243 "INCLUDEEXCLUDEDLL", "RAC_EVENT_OFF", "TELEMETRY_OFF", "SHIM_ENGINE_OFF", "LAYER_PROPAGATION_OFF", "REINSTALL_UPGRADE", NULL
244 }
245 },
246
247 {
248 TAG_TYPE_BYTE, 0x1000, __LINE__, WINVER_ANY, WINVER_ANY,
249 {
250 "InvalidTag", NULL
251 }
252 },
253
254 {
255 TAG_TYPE_WORD, 0x800, __LINE__, WINVER_ANY, WINVER_WIN7,
256 {
257 "InvalidTag", "MATCH_MODE", NULL
258 }
259 },
260 {
261 TAG_TYPE_WORD, 0x800, __LINE__, WINVER_WIN8, WINVER_ANY,
262 {
263 "InvalidTag", "MATCH_MODE", "QUIRK_COMPONENT_CODE_ID", "QUIRK_CODE_ID", NULL
264 }
265 },
266 {
267 TAG_TYPE_WORD | 0x800, 0x800, __LINE__, WINVER_ANY, WINVER_ANY,
268 {
269 "InvalidTag", "TAG", "INDEX_TAG", "INDEX_KEY", NULL
270 }
271 },
272
273 {
274 TAG_TYPE_DWORD, 0x800, __LINE__, WINVER_ANY, WINVER_WINXP,
275 {
276 "InvalidTag", "SIZE", "OFFSET", "CHECKSUM", "SHIM_TAGID", "PATCH_TAGID", "MODULE_TYPE", "VERFILEDATEHI",
277 "VERFILEDATELO", "VERFILEOS", "VERFILETYPE", "PE_CHECKSUM", "PREVOSMAJORVERSION", "PREVOSMINORVERSION", "PREVOSPLATFORMID", "PREVOSBUILDNO",
278 "PROBLEM_SEVERITY", "APPHELP_LANGID", "VER_LANGUAGE", "InvalidTag", "ENGINE", "HTMLHELPID", "INDEXFLAGS", "FLAGS",
279 "VALUETYPE", "DATA_DWORD", "LAYER_TAGID", "MSI_TRANSFORM_TAGID", "LINKER_VERSION", "LINK_DATE", "UPTO_LINK_DATE", "OS_SERVICE_PACK",
280 "FLAG_TAGID", "RUNTIME_PLATFORM", "OS_SKU", NULL
281 }
282 },
283 {
284 TAG_TYPE_DWORD, 0x800, __LINE__, WINVER_2003, WINVER_2003,
285 {
286 "InvalidTag", "SIZE", "OFFSET", "CHECKSUM", "SHIM_TAGID", "PATCH_TAGID", "MODULE_TYPE", "VERFILEDATEHI",
287 "VERFILEDATELO", "VERFILEOS", "VERFILETYPE", "PE_CHECKSUM", "PREVOSMAJORVERSION", "PREVOSMINORVERSION", "PREVOSPLATFORMID", "PREVOSBUILDNO",
288 "PROBLEM_SEVERITY", "APPHELP_LANGID", "VER_LANGUAGE", "InvalidTag", "ENGINE", "HTMLHELPID", "INDEXFLAGS", "FLAGS",
289 "VALUETYPE", "DATA_DWORD", "LAYER_TAGID", "MSI_TRANSFORM_TAGID", "LINKER_VERSION", "LINK_DATE", "UPTO_LINK_DATE", "OS_SERVICE_PACK",
290 "FLAG_TAGID", "RUNTIME_PLATFORM", "OS_SKU", "OS_PLATFORM", NULL
291 }
292 },
293 {
294 TAG_TYPE_DWORD, 0x800, __LINE__, WINVER_VISTA, WINVER_VISTA,
295 {
296 "InvalidTag", "SIZE", "OFFSET", "CHECKSUM", "SHIM_TAGID", "PATCH_TAGID", "MODULE_TYPE", "VERDATEHI",
297 "VERDATELO", "VERFILEOS", "VERFILETYPE", "PE_CHECKSUM", "PREVOSMAJORVER", "PREVOSMINORVER", "PREVOSPLATFORMID", "PREVOSBUILDNO",
298 "PROBLEMSEVERITY", "LANGID", "VER_LANGUAGE", "InvalidTag", "ENGINE", "HTMLHELPID", "INDEX_FLAGS", "FLAGS",
299 "DATA_VALUETYPE", "DATA_DWORD", "LAYER_TAGID", "MSI_TRANSFORM_TAGID", "LINKER_VERSION", "LINK_DATE", "UPTO_LINK_DATE", "OS_SERVICE_PACK",
300 "FLAG_TAGID", "RUNTIME_PLATFORM", "OS_SKU", "OS_PLATFORM", "APP_NAME_RC_ID", "VENDOR_NAME_RC_ID", "SUMMARY_MSG_RC_ID", "VISTA_SKU",
301 NULL
302 }
303 },
304 {
305 TAG_TYPE_DWORD, 0x800, __LINE__, WINVER_WIN7, WINVER_ANY,
306 {
307 "InvalidTag", "SIZE", "OFFSET", "CHECKSUM", "SHIM_TAGID", "PATCH_TAGID", "MODULE_TYPE", "VERDATEHI",
308 "VERDATELO", "VERFILEOS", "VERFILETYPE", "PE_CHECKSUM", "PREVOSMAJORVER", "PREVOSMINORVER", "PREVOSPLATFORMID", "PREVOSBUILDNO",
309 "PROBLEMSEVERITY", "LANGID", "VER_LANGUAGE", "InvalidTag", "ENGINE", "HTMLHELPID", "INDEX_FLAGS", "FLAGS",
310 "DATA_VALUETYPE", "DATA_DWORD", "LAYER_TAGID", "MSI_TRANSFORM_TAGID", "LINKER_VERSION", "LINK_DATE", "UPTO_LINK_DATE", "OS_SERVICE_PACK",
311 "FLAG_TAGID", "RUNTIME_PLATFORM", "OS_SKU", "OS_PLATFORM", "APP_NAME_RC_ID", "VENDOR_NAME_RC_ID", "SUMMARY_MSG_RC_ID", "VISTA_SKU",
312 "DESCRIPTION_RC_ID", "PARAMETER1_RC_ID", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag",
313 "CONTEXT_TAGID", "EXE_WRAPPER", "URL_ID", NULL
314 }
315 },
316 {
317 TAG_TYPE_DWORD | 0x800, 0x800, __LINE__, WINVER_ANY, WINVER_ANY,
318 {
319 "InvalidTag", "TAGID", NULL
320 }
321 },
322
323 {
324 TAG_TYPE_QWORD, 0x1000, __LINE__, WINVER_ANY, WINVER_WINXP,
325 {
326 "InvalidTag", "TIME", "BIN_FILE_VERSION", "BIN_PRODUCT_VERSION", "MODTIME", "FLAG_MASK_KERNEL", "UPTO_BIN_PRODUCT_VERSION", "DATA_QWORD",
327 "FLAG_MASK_USER", "FLAGS_NTVDM1", "FLAGS_NTVDM2", "FLAGS_NTVDM3", "FLAG_MASK_SHELL", "UPTO_BIN_FILE_VERSION", NULL
328 }
329 },
330 {
331 TAG_TYPE_QWORD, 0x1000, __LINE__, WINVER_2003, WINVER_2003,
332 {
333 "InvalidTag", "TIME", "BIN_FILE_VERSION", "BIN_PRODUCT_VERSION", "MODTIME", "FLAG_MASK_KERNEL", "UPTO_BIN_PRODUCT_VERSION", "DATA_QWORD",
334 "FLAG_MASK_USER", "FLAGS_NTVDM1", "FLAGS_NTVDM2", "FLAGS_NTVDM3", "FLAG_MASK_SHELL", "UPTO_BIN_FILE_VERSION", "FLAG_MASK_FUSION", "FLAGS_PROCESSPARAM",
335 NULL
336 }
337 },
338 {
339 TAG_TYPE_QWORD, 0x1000, __LINE__, WINVER_VISTA, WINVER_ANY,
340 {
341 "InvalidTag", "TIME", "BIN_FILE_VERSION", "BIN_PRODUCT_VERSION", "MODTIME", "FLAG_MASK_KERNEL", "UPTO_BIN_PRODUCT_VERSION", "DATA_QWORD",
342 "FLAG_MASK_USER", "FLAGS_NTVDM1", "FLAGS_NTVDM2", "FLAGS_NTVDM3", "FLAG_MASK_SHELL", "UPTO_BIN_FILE_VERSION", "FLAG_MASK_FUSION", "FLAG_PROCESSPARAM",
343 "FLAG_LUA", "FLAG_INSTALL", NULL
344 }
345 },
346
347 {
348 TAG_TYPE_STRINGREF, 0x1000, __LINE__, WINVER_ANY, WINVER_2003,
349 {
350 "InvalidTag", "NAME", "DESCRIPTION", "MODULE", "API", "VENDOR", "APP_NAME", "InvalidTag",
351 "COMMAND_LINE", "COMPANY_NAME", "DLLFILE", "WILDCARD_NAME", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag",
352 "PRODUCT_NAME", "PRODUCT_VERSION", "FILE_DESCRIPTION", "FILE_VERSION", "ORIGINAL_FILENAME", "INTERNAL_NAME", "LEGAL_COPYRIGHT", "S16BIT_DESCRIPTION",
353 "PROBLEM_DETAILS", "LINK_URL", "LINK_TEXT", "APPHELP_TITLE", "APPHELP_CONTACT", "SXS_MANIFEST", "DATA_STRING", "MSI_TRANSFORM_FILE",
354 "S16BIT_MODULE_NAME", "LAYER_DISPLAYNAME", "COMPILER_VERSION", "ACTION_TYPE", NULL
355 }
356 },
357 {
358 TAG_TYPE_STRINGREF, 0x1000, __LINE__, WINVER_VISTA, WINVER_VISTA,
359 {
360 "InvalidTag", "NAME", "DESCRIPTION", "MODULE", "API", "VENDOR", "APP_NAME", "InvalidTag",
361 "COMMAND_LINE", "COMPANY_NAME", "DLLFILE", "WILDCARD_NAME", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag",
362 "PRODUCT_NAME", "PRODUCT_VERSION", "FILE_DESCRIPTION", "FILE_VERSION", "ORIGINAL_FILENAME", "INTERNAL_NAME", "LEGAL_COPYRIGHT", "16BIT_DESCRIPTION",
363 "APPHELP_DETAILS", "LINK_URL", "LINK_TEXT", "APPHELP_TITLE", "APPHELP_CONTACT", "SXS_MANIFEST", "DATA_STRING", "MSI_TRANSFORM_FILE",
364 "16BIT_MODULE_NAME", "LAYER_DISPLAYNAME", "COMPILER_VERSION", "ACTION_TYPE", "EXPORT_NAME", NULL
365 }
366 },
367 {
368 TAG_TYPE_STRINGREF, 0x1000, __LINE__, WINVER_WIN7, WINVER_ANY,
369 {
370 "InvalidTag", "NAME", "DESCRIPTION", "MODULE", "API", "VENDOR", "APP_NAME", "InvalidTag",
371 "COMMAND_LINE", "COMPANY_NAME", "DLLFILE", "WILDCARD_NAME", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag",
372 "PRODUCT_NAME", "PRODUCT_VERSION", "FILE_DESCRIPTION", "FILE_VERSION", "ORIGINAL_FILENAME", "INTERNAL_NAME", "LEGAL_COPYRIGHT", "16BIT_DESCRIPTION",
373 "APPHELP_DETAILS", "LINK_URL", "LINK_TEXT", "APPHELP_TITLE", "APPHELP_CONTACT", "SXS_MANIFEST", "DATA_STRING", "MSI_TRANSFORM_FILE",
374 "16BIT_MODULE_NAME", "LAYER_DISPLAYNAME", "COMPILER_VERSION", "ACTION_TYPE", "EXPORT_NAME", "URL", NULL
375 }
376 },
377
378 {
379 TAG_TYPE_LIST, 0x800, __LINE__, WINVER_ANY, WINVER_2003,
380 {
381 "InvalidTag", "DATABASE", "LIBRARY", "INEXCLUDE", "SHIM", "PATCH", "APP", "EXE",
382 "MATCHING_FILE", "SHIM_REF", "PATCH_REF", "LAYER", "FILE", "APPHELP", "LINK", "DATA",
383 "MSI TRANSFORM", "MSI TRANSFORM REF", "MSI PACKAGE", "FLAG", "MSI CUSTOM ACTION", "FLAG_REF", "ACTION", NULL
384 }
385 },
386 {
387 TAG_TYPE_LIST, 0x800, __LINE__, WINVER_VISTA, WINVER_VISTA,
388 {
389 "InvalidTag", "DATABASE", "LIBRARY", "INEXCLUDE", "SHIM", "PATCH", "APP", "EXE",
390 "MATCHING_FILE", "SHIM_REF", "PATCH_REF", "LAYER", "FILE", "APPHELP", "LINK", "DATA",
391 "MSI_TRANSFORM", "MSI_TRANSFORM_REF", "MSI_PACKAGE", "FLAG", "MSI_CUSTOM_ACTION", "FLAG_REF", "ACTION", "LOOKUP",
392 NULL
393 }
394 },
395 {
396 TAG_TYPE_LIST, 0x800, __LINE__, WINVER_WIN7, WINVER_ANY,
397 {
398 "InvalidTag", "DATABASE", "LIBRARY", "INEXCLUDE", "SHIM", "PATCH", "APP", "EXE",
399 "MATCHING_FILE", "SHIM_REF", "PATCH_REF", "LAYER", "FILE", "APPHELP", "LINK", "DATA",
400 "MSI_TRANSFORM", "MSI_TRANSFORM_REF", "MSI_PACKAGE", "FLAG", "MSI_CUSTOM_ACTION", "FLAG_REF", "ACTION", "LOOKUP",
401 "CONTEXT", "CONTEXT_REF", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag",
402 "SPC", NULL
403 }
404 },
405 {
406 TAG_TYPE_LIST | 0x800, 0x800, __LINE__, WINVER_ANY, WINVER_ANY,
407 {
408 "InvalidTag", "STRINGTABLE", "INDEXES", "INDEX", NULL
409 }
410 },
411
412 {
413 TAG_TYPE_STRING, 0x800, __LINE__, WINVER_ANY, WINVER_ANY,
414 {
415 "InvalidTag", NULL
416 }
417 },
418 {
419 TAG_TYPE_STRING | 0x800, 0x800, __LINE__, WINVER_ANY, WINVER_2003,
420 {
421 "InvalidTag", "STRTAB_ITEM", NULL
422 }
423 },
424 {
425 TAG_TYPE_STRING | 0x800, 0x800, __LINE__, WINVER_VISTA, WINVER_ANY,
426 {
427 "InvalidTag", "STRINGTABLE_ITEM", NULL
428 }
429 },
430
431
432 {
433 TAG_TYPE_BINARY, 0x800, __LINE__, WINVER_ANY, WINVER_2003,
434 {
435 "InvalidTag", "InvalidTag", "PATCH_BITS", "FILE_BITS", "EXE_ID(GUID)", "DATA_BITS", "MSI_PACKAGE_ID(GUID)", "DATABASE_ID(GUID)",
436 NULL
437 }
438 },
439 {
440 TAG_TYPE_BINARY, 0x800, __LINE__, WINVER_VISTA, WINVER_VISTA,
441 {
442 "InvalidTag", "InvalidTag", "PATCH_BITS", "FILE_BITS", "EXE_ID", "DATA_BITS", "MSI_PACKAGE_ID", "DATABASE_ID",
443 NULL
444 }
445 },
446 {
447 TAG_TYPE_BINARY, 0x800, __LINE__, WINVER_WIN7, WINVER_ANY,
448 {
449 "InvalidTag", "InvalidTag", "PATCH_BITS", "FILE_BITS", "EXE_ID", "DATA_BITS", "MSI_PACKAGE_ID", "DATABASE_ID",
450 "CONTEXT_PLATFORM_ID", "CONTEXT_BRANCH_ID", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag",
451 "FIX_ID", "APP_ID", NULL
452 }
453 },
454 {
455 TAG_TYPE_BINARY | 0x800, 0x800, __LINE__, WINVER_ANY, WINVER_ANY,
456 {
457 "InvalidTag", "INDEX_BITS", NULL
458 }
459 },
460
461 { 0, 0, 0, 0, 0, { NULL } }
462 };
463
464
465 static void test_SdbTagToStringAllTags(void)
466 {
467 int n;
468 for (n = 0; data[n].base; ++n)
469 {
470 if ((data[n].min_ver == WINVER_ANY || g_WinVersion >= data[n].min_ver) &&
471 (data[n].max_ver == WINVER_ANY || g_WinVersion <= data[n].max_ver))
472 {
473 test_tag(data[n].base, data[n].tags, data[n].upper_limit, data[n].line);
474 }
475 }
476 }
477
478 static void test_GuidFunctions(void)
479 {
480 GUID guid;
481 ok(pSdbIsNullGUID(&GUID_NULL), "expected GUID_NULL to be recognized as NULL GUID\n");
482 ok(pSdbIsNullGUID(NULL), "expected NULL to be recognized as NULL GUID\n");
483 ok(pSdbIsNullGUID(&test_UserAssist) == 0, "expected a set GUID not to be recognized as NULL GUID\n");
484
485 memset(&guid, 0, sizeof(guid));
486 ok(pSdbGetStandardDatabaseGUID(0, &guid) == 0,"Expected SdbGetStandardDatabaseGUID to fail\n");
487 ok(IsEqualGUID(&GUID_NULL, &guid), "Expected guid not to be changed\n");
488
489 ok(pSdbGetStandardDatabaseGUID(0x80020000, NULL),"Expected SdbGetStandardDatabaseGUID to succeed\n");
490
491 memset(&guid, 0, sizeof(guid));
492 ok(pSdbGetStandardDatabaseGUID(0x80020000, &guid),"Expected SdbGetStandardDatabaseGUID to succeed\n");
493 ok(IsEqualGUID(&GUID_DATABASE_MSI, &guid), "Expected guid to equal GUID_DATABASE_MSI, was: %s\n", wine_dbgstr_guid(&guid));
494
495 memset(&guid, 0, sizeof(guid));
496 ok(pSdbGetStandardDatabaseGUID(0x80030000, &guid),"Expected SdbGetStandardDatabaseGUID to succeed\n");
497 ok(IsEqualGUID(&GUID_DATABASE_SHIM, &guid), "Expected guid to equal GUID_DATABASE_SHIM, was: %s\n", wine_dbgstr_guid(&guid));
498
499 memset(&guid, 0, sizeof(guid));
500 ok(pSdbGetStandardDatabaseGUID(0x80040000, &guid),"Expected SdbGetStandardDatabaseGUID to succeed\n");
501 ok(IsEqualGUID(&GUID_DATABASE_DRIVERS, &guid), "Expected guid to equal GUID_DATABASE_DRIVERS, was: %s\n", wine_dbgstr_guid(&guid));
502 }
503
504 static void expect_tag_skip_imp(PATTRINFO pattr, DWORD num)
505 {
506 PATTRINFO p = &pattr[num];
507 winetest_ok(p->type == TAG_NULL, "expected entry #%d to be TAG_NULL, was %x\n", num, p->type);
508 winetest_ok(p->flags == ATTRIBUTE_FAILED, "expected entry #%d to be failed, was %d\n", num, p->flags);
509 winetest_ok(p->qwattr == 0, "expected entry #%d to be 0, was 0x%I64x\n", num, p->qwattr);
510 }
511 static void expect_tag_empty_imp(PATTRINFO pattr, DWORD num)
512 {
513 PATTRINFO p = &pattr[num];
514 winetest_ok(p->type == TAG_NULL, "expected entry #%d to be TAG_NULL, was %x\n", num, p->type);
515 winetest_ok(p->flags == 0, "expected entry #%d to be 0, was %d\n", num, p->flags);
516 winetest_ok(p->qwattr == 0, "expected entry #%d to be 0, was 0x%I64x\n", num, p->qwattr);
517 }
518
519 static void expect_tag_dword_imp(PATTRINFO pattr, DWORD num, TAG tag, DWORD value)
520 {
521 PATTRINFO p = &pattr[num];
522 winetest_ok(p->type == tag, "expected entry #%d to be %x, was %x\n", num, tag, p->type);
523 winetest_ok(p->flags == ATTRIBUTE_AVAILABLE, "expected entry #%d to be available, was %d\n", num, p->flags);
524 winetest_ok(p->dwattr == value, "expected entry #%d to be 0x%x, was 0x%x\n", num, value, p->dwattr);
525 }
526
527 static void expect_tag_qword_imp(PATTRINFO pattr, DWORD num, TAG tag, QWORD value)
528 {
529 PATTRINFO p = &pattr[num];
530 winetest_ok(p->type == tag, "expected entry #%d to be %x, was %x\n", num, tag, p->type);
531 winetest_ok(p->flags == ATTRIBUTE_AVAILABLE, "expected entry #%d to be available, was %d\n", num, p->flags);
532 winetest_ok(p->qwattr == value, "expected entry #%d to be 0x%I64x, was 0x%I64x\n", num, value, p->qwattr);
533 }
534
535 static void expect_tag_str_imp(PATTRINFO pattr, DWORD num, TAG tag, const WCHAR* value)
536 {
537 PATTRINFO p = &pattr[num];
538 winetest_ok(p->type == tag, "expected entry #%d to be %x, was %x\n", num, tag, p->type);
539 winetest_ok(p->flags == ATTRIBUTE_AVAILABLE, "expected entry #%d to be available, was %d\n", num, p->flags);
540 winetest_ok(p->lpattr && wcscmp(p->lpattr, value) == 0, "expected entry #%d to be %s, was %s\n", num, wine_dbgstr_w(value), wine_dbgstr_w(p->lpattr));
541 }
542
543 #define expect_tag_skip (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : expect_tag_skip_imp
544 #define expect_tag_empty (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : expect_tag_empty_imp
545 #define expect_tag_dword (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : expect_tag_dword_imp
546 #define expect_tag_qword (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : expect_tag_qword_imp
547 #define expect_tag_str (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : expect_tag_str_imp
548 #define expect_tag_skip_range(ptr, from, to) \
549 do { \
550 int n = (from), n_end = (to); \
551 winetest_set_location(__FILE__, __LINE__); \
552 for ( ; n < n_end; ++n) \
553 expect_tag_skip_imp((ptr), n); \
554 } while (0)
555 #define test_crc (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : test_crc_imp
556 #define test_crc2 (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : test_crc2_imp
557
558 void test_onefile(WCHAR* filename)
559 {
560 PATTRINFO pattrinfo;
561 DWORD num;
562
563 if (!pSdbFreeFileAttributes)
564 {
565 hdll = LoadLibraryA("apphelp.dll");
566 pSdbTagToString = (void *)GetProcAddress(hdll, "SdbTagToString");
567 pSdbGetFileAttributes = (void *)GetProcAddress(hdll, "SdbGetFileAttributes");
568 pSdbFreeFileAttributes = (void *)GetProcAddress(hdll, "SdbFreeFileAttributes");
569 }
570
571 if (pSdbGetFileAttributes(filename, &pattrinfo, &num))
572 {
573 if (pattrinfo[16].flags == ATTRIBUTE_AVAILABLE)
574 {
575 if (pattrinfo[16].type != TAG_MODULE_TYPE)//SdbpSetAttrFail(&attr_info[16]); /* TAG_MODULE_TYPE (1: WIN16?) (3: WIN32?) (WIN64?), Win32VersionValue? */)
576 printf("FAIL TAG_MODULE_TYPE (%S)\n", filename);
577 if (pattrinfo[16].dwattr != 3 && pattrinfo[16].dwattr != 2)
578 printf("TAG_MODULE_TYPE(%S): %d\n", filename, pattrinfo[16].dwattr); // C:\Program Files (x86)\Windows Kits\8.1\Lib\win7\stub512.com
579 if (pattrinfo[16].dwattr == 2)
580 {
581 printf("TAG_MODULE_TYPE(%S): %d, %d\n", filename, pattrinfo[16].dwattr, pattrinfo[0].dwattr);
582 }
583 }
584
585 if (pattrinfo[27].flags == ATTRIBUTE_AVAILABLE)
586 {
587 if (pattrinfo[27].type != TAG_EXE_WRAPPER)
588 printf("FAIL TAG_EXE_WRAPPER (%S)\n", filename);
589 if (pattrinfo[27].dwattr != 0)
590 printf("TAG_EXE_WRAPPER(%S): %d\n", filename, pattrinfo[27].dwattr);
591 }
592
593 pSdbFreeFileAttributes(pattrinfo);
594 }
595 }
596
597 static void test_crc_imp(size_t len, DWORD expected)
598 {
599 static const WCHAR path[] = {'t','e','s','t','x','x','.','e','x','e',0};
600 static char crc_test[] = {4, 4, 4, 4, 1, 1, 1, 1, 4, 4, 4, 4, 2, 2, 2, 2};
601
602 PATTRINFO pattrinfo = (PATTRINFO)0xdead;
603 DWORD num = 333;
604 BOOL ret;
605
606 test_create_file_imp("testxx.exe", crc_test, len);
607 ret = pSdbGetFileAttributes(path, &pattrinfo, &num);
608 winetest_ok(ret != FALSE, "expected SdbGetFileAttributes to succeed.\n");
609 winetest_ok(pattrinfo != (PATTRINFO)0xdead, "expected a valid pointer.\n");
610 winetest_ok(num == 28, "expected 28 items, got %d.\n", num);
611
612 if (num == 28 && ret)
613 {
614 expect_tag_dword_imp(pattrinfo, 1, TAG_CHECKSUM, expected);
615 }
616 if (ret)
617 pSdbFreeFileAttributes(pattrinfo);
618 }
619
620 static void test_crc2_imp(size_t len, int fill, DWORD expected)
621 {
622 static const WCHAR path[] = {'t','e','s','t','x','x','.','e','x','e',0};
623
624 PATTRINFO pattrinfo = (PATTRINFO)0xdead;
625 DWORD num = 333;
626 BOOL ret;
627 size_t n;
628 char* crc_test = malloc(len);
629 for (n = 0; n < len; ++n)
630 crc_test[n] = (char)(fill ? fill : n);
631
632 test_create_file_imp("testxx.exe", crc_test, len);
633 free(crc_test);
634 ret = pSdbGetFileAttributes(path, &pattrinfo, &num);
635 winetest_ok(ret != FALSE, "expected SdbGetFileAttributes to succeed.\n");
636 winetest_ok(pattrinfo != (PATTRINFO)0xdead, "expected a valid pointer.\n");
637 winetest_ok(num == 28, "expected 28 items, got %d.\n", num);
638
639 if (num == 28 && ret)
640 {
641 expect_tag_dword_imp(pattrinfo, 0, TAG_SIZE, len);
642 expect_tag_dword_imp(pattrinfo, 1, TAG_CHECKSUM, expected);
643 }
644 if (ret)
645 pSdbFreeFileAttributes(pattrinfo);
646 }
647
648
649
650 static void test_ApplicationAttributes(void)
651 {
652 static const WCHAR path[] = {'t','e','s','t','x','x','.','e','x','e',0};
653 static const WCHAR PRODUCT_VERSION[] = {'1','.','0','.','0','.','1',0};
654 static const WCHAR FILE_DESCRIPTION[] = {'F','i','l','e','D','e','s','c','r','i','p','t','i','o','n',0};
655 static const WCHAR COMPANY_NAME[] = {'C','o','m','p','a','n','y','N','a','m','e',0};
656 static const WCHAR PRODUCT_NAME[] = {'P','r','o','d','u','c','t','N','a','m','e',0};
657 static const WCHAR FILE_VERSION[] = {'1','.','0','.','0','.','0',0};
658 static const WCHAR ORIGINAL_FILENAME[] = {'O','r','i','g','i','n','a','l','F','i','l','e','n','a','m','e',0};
659 static const WCHAR INTERNAL_NAME[] = {'I','n','t','e','r','n','a','l','N','a','m','e',0};
660 static const WCHAR LEGAL_COPYRIGHT[] = {'L','e','g','a','l','C','o','p','y','r','i','g','h','t',0};
661 static const WCHAR EXPORT_NAME[] = {'T','e','S','t','2','.','e','x','e',0};
662 static const WCHAR OS2_DESCRIPTION[] = {'M','O','D',' ','D','E','S','C','R','I','P','T','I','O','N',' ','H','E','R','E',0};
663 static const WCHAR OS2_EXPORT_NAME[] = {'T','E','S','T','M','O','D','.','h','X','x',0};
664 static const WCHAR OS2_DESCRIPTION_broken[] = {'Z',0};
665 static const WCHAR OS2_EXPORT_NAME_broken[] = {'E',0};
666
667 PATTRINFO pattrinfo = (PATTRINFO)0xdead;
668 DWORD num = 333;
669 BOOL ret;
670
671 /* ensure the file is not there. */
672 DeleteFileA("testxx.exe");
673 ret = pSdbGetFileAttributes(path, &pattrinfo, &num);
674 ok(ret == FALSE, "expected SdbGetFileAttributes to fail.\n");
675 ok(pattrinfo == (PATTRINFO)0xdead, "expected the pointer not to change.\n");
676 ok(num == 333, "expected the number of items not to change.\n");
677 if (ret)
678 pSdbFreeFileAttributes(pattrinfo);
679
680 /* Test a file with as much features as possible */
681 test_create_exe("testxx.exe", 0);
682
683 ret = pSdbGetFileAttributes(path, &pattrinfo, &num);
684 ok(ret != FALSE, "expected SdbGetFileAttributes to succeed.\n");
685 ok(pattrinfo != (PATTRINFO)0xdead, "expected a valid pointer.\n");
686 ok(num == 28, "expected 28 items, got %d.\n", num);
687
688 if (num == 28 && ret)
689 {
690 expect_tag_dword(pattrinfo, 0, TAG_SIZE, 0x800);
691 expect_tag_dword(pattrinfo, 1, TAG_CHECKSUM, 0x178bd629);
692 expect_tag_qword(pattrinfo, 2, TAG_BIN_FILE_VERSION, 0x1000000000000ull);
693 expect_tag_qword(pattrinfo, 3, TAG_BIN_PRODUCT_VERSION, 0x1000000000001ull);
694 expect_tag_str(pattrinfo, 4, TAG_PRODUCT_VERSION, PRODUCT_VERSION);
695 expect_tag_str(pattrinfo, 5, TAG_FILE_DESCRIPTION, FILE_DESCRIPTION);
696 expect_tag_str(pattrinfo, 6, TAG_COMPANY_NAME, COMPANY_NAME);
697 expect_tag_str(pattrinfo, 7, TAG_PRODUCT_NAME, PRODUCT_NAME);
698 expect_tag_str(pattrinfo, 8, TAG_FILE_VERSION, FILE_VERSION);
699 expect_tag_str(pattrinfo, 9, TAG_ORIGINAL_FILENAME, ORIGINAL_FILENAME);
700 expect_tag_str(pattrinfo, 10, TAG_INTERNAL_NAME, INTERNAL_NAME);
701 expect_tag_str(pattrinfo, 11, TAG_LEGAL_COPYRIGHT, LEGAL_COPYRIGHT);
702 expect_tag_dword(pattrinfo, 12, TAG_VERDATEHI, 0x1d1a019);
703 expect_tag_dword(pattrinfo, 13, TAG_VERDATELO, 0xac754c50);
704 expect_tag_dword(pattrinfo, 14, TAG_VERFILEOS, VOS__WINDOWS32);
705 expect_tag_dword(pattrinfo, 15, TAG_VERFILETYPE, VFT_APP);
706 expect_tag_dword(pattrinfo, 16, TAG_MODULE_TYPE, 0x3); /* Win32 */
707 expect_tag_dword(pattrinfo, 17, TAG_PE_CHECKSUM, 0xBAAD);
708 expect_tag_dword(pattrinfo, 18, TAG_LINKER_VERSION, 0x40002);
709 expect_tag_skip(pattrinfo, 19); /* TAG_16BIT_DESCRIPTION */
710 expect_tag_skip(pattrinfo, 20); /* TAG_16BIT_MODULE_NAME */
711 expect_tag_qword(pattrinfo, 21, TAG_UPTO_BIN_FILE_VERSION, 0x1000000000000ull);
712 expect_tag_qword(pattrinfo, 22, TAG_UPTO_BIN_PRODUCT_VERSION, 0x1000000000001ull);
713 expect_tag_dword(pattrinfo, 23, TAG_LINK_DATE, 0x12345);
714 expect_tag_dword(pattrinfo, 24, TAG_UPTO_LINK_DATE, 0x12345);
715 expect_tag_str(pattrinfo, 25, TAG_EXPORT_NAME, EXPORT_NAME);
716 expect_tag_dword(pattrinfo, 26, TAG_VER_LANGUAGE, 0xffff);
717 expect_tag_dword(pattrinfo, 27, TAG_EXE_WRAPPER, 0x0);
718 }
719 if (ret)
720 pSdbFreeFileAttributes(pattrinfo);
721
722
723 /* Disable resource and exports */
724 test_create_exe("testxx.exe", 1);
725
726 ret = pSdbGetFileAttributes(path, &pattrinfo, &num);
727 ok(ret != FALSE, "expected SdbGetFileAttributes to succeed.\n");
728 ok(pattrinfo != (PATTRINFO)0xdead, "expected a valid pointer.\n");
729 ok(num == 28, "expected 28 items, got %d.\n", num);
730
731 if (num == 28 && ret)
732 {
733 expect_tag_dword(pattrinfo, 0, TAG_SIZE, 0x800);
734 expect_tag_dword(pattrinfo, 1, TAG_CHECKSUM, 0xea7caffd);
735 expect_tag_skip_range(pattrinfo, 2, 16);
736 expect_tag_dword(pattrinfo, 16, TAG_MODULE_TYPE, 0x3); /* Win32 */
737 expect_tag_dword(pattrinfo, 17, TAG_PE_CHECKSUM, 0xBAAD);
738 expect_tag_dword(pattrinfo, 18, TAG_LINKER_VERSION, 0x40002);
739 expect_tag_skip_range(pattrinfo, 19, 23);
740 expect_tag_dword(pattrinfo, 23, TAG_LINK_DATE, 0x12345);
741 expect_tag_dword(pattrinfo, 24, TAG_UPTO_LINK_DATE, 0x12345);
742 expect_tag_skip(pattrinfo, 25); /* TAG_EXPORT_NAME */
743 expect_tag_empty(pattrinfo, 26); /* TAG_VER_LANGUAGE */
744 expect_tag_dword(pattrinfo, 27, TAG_EXE_WRAPPER, 0x0);
745 }
746 if (ret)
747 pSdbFreeFileAttributes(pattrinfo);
748
749 /* A file with just 'MZ' */
750 test_create_file("testxx.exe", "MZ", 2);
751
752 ret = pSdbGetFileAttributes(path, &pattrinfo, &num);
753 ok(ret != FALSE, "expected SdbGetFileAttributes to succeed.\n");
754 ok(pattrinfo != (PATTRINFO)0xdead, "expected a valid pointer.\n");
755 ok(num == 28, "expected 28 items, got %d.\n", num);
756
757 if (num == 28 && ret)
758 {
759 expect_tag_dword(pattrinfo, 0, TAG_SIZE, 0x2);
760 expect_tag_dword(pattrinfo, 1, TAG_CHECKSUM, 0);
761 expect_tag_skip_range(pattrinfo, 2, 16);
762 expect_tag_dword(pattrinfo, 16, TAG_MODULE_TYPE, 0x1);
763 expect_tag_skip_range(pattrinfo, 17, 26);
764 expect_tag_empty(pattrinfo, 26); /* TAG_VER_LANGUAGE */
765 expect_tag_skip(pattrinfo, 27); /* TAG_EXE_WRAPPER */
766 }
767 if (ret)
768 pSdbFreeFileAttributes(pattrinfo);
769
770 /* Empty file */
771 test_create_file("testxx.exe", NULL, 0);
772
773 ret = pSdbGetFileAttributes(path, &pattrinfo, &num);
774 ok(ret != FALSE, "expected SdbGetFileAttributes to succeed.\n");
775 ok(pattrinfo != (PATTRINFO)0xdead, "expected a valid pointer.\n");
776 ok(num == 28, "expected 28 items, got %d.\n", num);
777
778 if (num == 28 && ret)
779 {
780 expect_tag_dword(pattrinfo, 0, TAG_SIZE, 0);
781 expect_tag_skip_range(pattrinfo, 1, 26);
782 expect_tag_empty(pattrinfo, 26); /* TAG_VER_LANGUAGE */
783 expect_tag_skip(pattrinfo, 27); /* TAG_EXE_WRAPPER */
784 }
785 if (ret)
786 pSdbFreeFileAttributes(pattrinfo);
787
788 /* minimal NE executable */
789 test_create_ne("testxx.exe", 0);
790
791 ret = pSdbGetFileAttributes(path, &pattrinfo, &num);
792 ok(ret != FALSE, "expected SdbGetFileAttributes to succeed.\n");
793 ok(pattrinfo != (PATTRINFO)0xdead, "expected a valid pointer.\n");
794 ok(num == 28, "expected 28 items, got %d.\n", num);
795
796 if (num == 28 && ret)
797 {
798 expect_tag_dword(pattrinfo, 0, TAG_SIZE, 0xa8);
799 expect_tag_dword(pattrinfo, 1, TAG_CHECKSUM, 0xf2abe4e9);
800 expect_tag_skip_range(pattrinfo, 2, 16);
801 expect_tag_dword(pattrinfo, 16, TAG_MODULE_TYPE, 0x2);
802 expect_tag_skip(pattrinfo, 17); /* TAG_PE_CHECKSUM */
803 expect_tag_skip(pattrinfo, 18); /* TAG_LINKER_VERSION */
804 expect_tag_str(pattrinfo, 19, TAG_16BIT_DESCRIPTION, OS2_DESCRIPTION);
805 expect_tag_str(pattrinfo, 20, TAG_16BIT_MODULE_NAME, OS2_EXPORT_NAME);
806 expect_tag_skip_range(pattrinfo, 21, 26);
807 expect_tag_empty(pattrinfo, 26); /* TAG_VER_LANGUAGE */
808 expect_tag_skip(pattrinfo, 27); /* TAG_EXE_WRAPPER */
809 }
810 if (ret)
811 pSdbFreeFileAttributes(pattrinfo);
812
813 /* NE executable with description / module name pointers zero, to show they are always used */
814 test_create_ne("testxx.exe", 1);
815
816 ret = pSdbGetFileAttributes(path, &pattrinfo, &num);
817 ok(ret != FALSE, "expected SdbGetFileAttributes to succeed.\n");
818 ok(pattrinfo != (PATTRINFO)0xdead, "expected a valid pointer.\n");
819 ok(num == 28, "expected 28 items, got %d.\n", num);
820
821 if (num == 28 && ret)
822 {
823 expect_tag_dword(pattrinfo, 0, TAG_SIZE, 0xa8);
824 expect_tag_dword(pattrinfo, 1, TAG_CHECKSUM, 0xddcbe4c9);
825 expect_tag_skip_range(pattrinfo, 2, 16);
826 expect_tag_dword(pattrinfo, 16, TAG_MODULE_TYPE, 0x2);
827 expect_tag_skip(pattrinfo, 17); /* TAG_PE_CHECKSUM */
828 expect_tag_skip(pattrinfo, 18); /* TAG_LINKER_VERSION */
829 expect_tag_str(pattrinfo, 19, TAG_16BIT_DESCRIPTION, OS2_DESCRIPTION_broken); /* the 'Z' from 'MZ' */
830 expect_tag_str(pattrinfo, 20, TAG_16BIT_MODULE_NAME, OS2_EXPORT_NAME_broken); /* the 'E' from 'NE' */
831 expect_tag_skip_range(pattrinfo, 21, 26);
832 expect_tag_empty(pattrinfo, 26); /* TAG_VER_LANGUAGE */
833 expect_tag_skip(pattrinfo, 27); /* TAG_EXE_WRAPPER */
834 }
835 if (ret)
836 pSdbFreeFileAttributes(pattrinfo);
837
838 test_crc(1, 0);
839 test_crc(2, 0);
840 test_crc(3, 0);
841 test_crc(4, 0x2020202);
842 test_crc(5, 0x2020202);
843 test_crc(6, 0x2020202);
844 test_crc(7, 0x2020202);
845 test_crc(8, 0x81818181);
846 test_crc(9, 0x81818181);
847 test_crc(10, 0x81818181);
848 test_crc(11, 0x81818181);
849 test_crc(12, 0xc2c2c2c2);
850 test_crc(16, 0x62626262);
851
852 /* This seems to be the cutoff point */
853 test_crc2(0xffc, 4, 0xfbfbfcfc);
854 test_crc2(0xffc, 8, 0x7070717);
855 test_crc2(0xffc, 0xcc, 0xc8eba002);
856 test_crc2(0xffc, 0, 0x4622028d);
857
858 test_crc2(0x1000, 4, 0x80);
859 test_crc2(0x1000, 8, 0x8787878f);
860 test_crc2(0x1000, 0xcc, 0x4adc3667);
861 test_crc2(0x1000, 0, 0xa3108044);
862
863 /* Here is another cutoff point */
864 test_crc2(0x11fc, 4, 0x80);
865 test_crc2(0x11fc, 8, 0x8787878f);
866 test_crc2(0x11fc, 0xcc, 0x4adc3667);
867 test_crc2(0x11fc, 0, 0xf03e0800);
868
869 test_crc2(0x1200, 4, 0x80);
870 test_crc2(0x1200, 8, 0x8787878f);
871 test_crc2(0x1200, 0xcc, 0x4adc3667);
872 test_crc2(0x1200, 0, 0xa3108044);
873
874 /* After that, it stays the same for all sizes */
875 test_crc2(0xf000, 4, 0x80);
876 test_crc2(0xf000, 8, 0x8787878f);
877 test_crc2(0xf000, 0xcc, 0x4adc3667);
878 test_crc2(0xf000, 0, 0xa3108044);
879
880
881 DeleteFileA("testxx.exe");
882 }
883
884 START_TEST(apphelp)
885 {
886 g_WinVersion = get_host_winver();
887 trace("Detected version: 0x%x\n", g_WinVersion);
888 silence_debug_output();
889
890 //SetEnvironmentVariable("SHIM_DEBUG_LEVEL", "4");
891 //SetEnvironmentVariable("DEBUGCHANNEL", "+apphelp");
892 hdll = LoadLibraryA("apphelp.dll");
893
894 pApphelpCheckShellObject = (void *) GetProcAddress(hdll, "ApphelpCheckShellObject");
895 pSdbTagToString = (void *) GetProcAddress(hdll, "SdbTagToString");
896 pSdbGUIDToString = (void *) GetProcAddress(hdll, "SdbGUIDToString");
897 pSdbIsNullGUID = (void *) GetProcAddress(hdll, "SdbIsNullGUID");
898 pSdbGetStandardDatabaseGUID = (void *) GetProcAddress(hdll, "SdbGetStandardDatabaseGUID");
899 pSdbGetFileAttributes = (void *) GetProcAddress(hdll, "SdbGetFileAttributes");
900 pSdbFreeFileAttributes = (void *) GetProcAddress(hdll, "SdbFreeFileAttributes");
901
902 test_ApphelpCheckShellObject();
903 test_GuidFunctions();
904 test_ApplicationAttributes();
905 test_SdbTagToString();
906 #ifdef __REACTOS__
907 if (g_WinVersion < WINVER_WIN7)
908 {
909 g_WinVersion = WINVER_WIN7;
910 trace("Using version 0x%x for SdbTagToString tests\n", g_WinVersion);
911 }
912 #endif
913 test_SdbTagToStringAllTags();
914 }