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