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