[APPHELP][APPHELP_APITEST] Update SdbTagToString tests to check all known tags CORE...
[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
36 #include "wine/test.h"
37
38
39 static DWORD g_Version;
40
41 #define VERSION_ANY 0
42 #define VERSION_WINXP 0x0501
43 #define VERSION_2003 0x0502
44 #define VERSION_VISTA 0x0600
45 #define VERSION_WIN7 0x0601
46 #define VERSION_WIN8 0x0602
47 #define VERSION_WIN10 0x1000
48
49
50 typedef WORD TAG;
51
52 #define TAG_TYPE_MASK 0xF000
53
54 #define TAG_TYPE_NULL 0x1000
55 #define TAG_TYPE_BYTE 0x2000
56 #define TAG_TYPE_WORD 0x3000
57 #define TAG_TYPE_DWORD 0x4000
58 #define TAG_TYPE_QWORD 0x5000
59 #define TAG_TYPE_STRINGREF 0x6000
60 #define TAG_TYPE_LIST 0x7000
61 #define TAG_TYPE_STRING 0x8000
62 #define TAG_TYPE_BINARY 0x9000
63
64
65 static HMODULE hdll;
66 static LPCWSTR (WINAPI *pSdbTagToString)(TAG);
67
68 static void test_SdbTagToString(void)
69 {
70 static const TAG invalid_values[] = {
71 1, TAG_TYPE_WORD, TAG_TYPE_MASK,
72 TAG_TYPE_DWORD | 0xFF,
73 TAG_TYPE_DWORD | (0x800 + 0xEE),
74 0x900, 0xFFFF, 0xDEAD, 0xBEEF
75 };
76 static const WCHAR invalid[] = {'I','n','v','a','l','i','d','T','a','g',0};
77 LPCWSTR ret;
78 WORD i;
79
80 for (i = 0; i < 9; ++i)
81 {
82 ret = pSdbTagToString(invalid_values[i]);
83 ok(lstrcmpW(ret, invalid) == 0, "unexpected string %s, should be %s\n",
84 wine_dbgstr_w(ret), wine_dbgstr_w(invalid));
85 }
86 }
87
88 static int strcmp_wa(LPCWSTR strw, const char *stra)
89 {
90 CHAR buf[512];
91 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), 0, 0);
92 return lstrcmpA(buf, stra);
93 }
94
95 void test_tag(TAG base, const char* names[], size_t upperlimit, int line)
96 {
97 TAG n;
98 for (n = 0; names[n]; ++n)
99 {
100 LPCWSTR tagstr = pSdbTagToString(base | n);
101 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);
102 }
103 for (; n < upperlimit; ++n)
104 {
105 LPCWSTR tagstr = pSdbTagToString(base | n);
106 ok_(__FILE__, line + 2)(!strcmp_wa(tagstr, "InvalidTag"), "Got %s instead of 'InvalidTag' for %x\n", wine_dbgstr_w(tagstr), base | n);
107 }
108 }
109
110 static struct
111 {
112 TAG base;
113 DWORD upper_limit;
114 DWORD line;
115 DWORD min_ver;
116 DWORD max_ver;
117 const char* tags[7*8];
118 } data[] = {
119 {
120 TAG_TYPE_NULL, 0x1000, __LINE__, VERSION_ANY, VERSION_2003,
121 {
122 "InvalidTag", "INCLUDE", "GENERAL", "MATCH_LOGIC_NOT", "APPLY_ALL_SHIMS", "USE_SERVICE_PACK_FILES", NULL
123 }
124 },
125 {
126 TAG_TYPE_NULL, 0x1000, __LINE__, VERSION_VISTA, VERSION_VISTA,
127 {
128 "InvalidTag", "INCLUDE", "GENERAL", "MATCH_LOGIC_NOT", "APPLY_ALL_SHIMS", "USE_SERVICE_PACK_FILES", "MITIGATION_OS", "BLOCK_UPGRADE",
129 "INCLUDEEXCLUDEDLL", NULL
130 }
131 },
132 {
133 TAG_TYPE_NULL, 0x1000, __LINE__, VERSION_WIN7, VERSION_ANY,
134 {
135 "InvalidTag", "INCLUDE", "GENERAL", "MATCH_LOGIC_NOT", "APPLY_ALL_SHIMS", "USE_SERVICE_PACK_FILES", "MITIGATION_OS", "BLOCK_UPGRADE",
136 "INCLUDEEXCLUDEDLL", "RAC_EVENT_OFF", "TELEMETRY_OFF", "SHIM_ENGINE_OFF", "LAYER_PROPAGATION_OFF", "REINSTALL_UPGRADE", NULL
137 }
138 },
139
140 {
141 TAG_TYPE_BYTE, 0x1000, __LINE__, VERSION_ANY, VERSION_ANY,
142 {
143 "InvalidTag", NULL
144 }
145 },
146
147 {
148 TAG_TYPE_WORD, 0x800, __LINE__, VERSION_ANY, VERSION_WIN7,
149 {
150 "InvalidTag", "MATCH_MODE", NULL
151 }
152 },
153 {
154 TAG_TYPE_WORD, 0x800, __LINE__, VERSION_WIN8, VERSION_ANY,
155 {
156 "InvalidTag", "MATCH_MODE", "QUIRK_COMPONENT_CODE_ID", "QUIRK_CODE_ID", NULL
157 }
158 },
159 {
160 TAG_TYPE_WORD | 0x800, 0x800, __LINE__, VERSION_ANY, VERSION_ANY,
161 {
162 "InvalidTag", "TAG", "INDEX_TAG", "INDEX_KEY", NULL
163 }
164 },
165
166 {
167 TAG_TYPE_DWORD, 0x800, __LINE__, VERSION_ANY, VERSION_WINXP,
168 {
169 "InvalidTag", "SIZE", "OFFSET", "CHECKSUM", "SHIM_TAGID", "PATCH_TAGID", "MODULE_TYPE", "VERFILEDATEHI",
170 "VERFILEDATELO", "VERFILEOS", "VERFILETYPE", "PE_CHECKSUM", "PREVOSMAJORVERSION", "PREVOSMINORVERSION", "PREVOSPLATFORMID", "PREVOSBUILDNO",
171 "PROBLEM_SEVERITY", "APPHELP_LANGID", "VER_LANGUAGE", "InvalidTag", "ENGINE", "HTMLHELPID", "INDEXFLAGS", "FLAGS",
172 "VALUETYPE", "DATA_DWORD", "LAYER_TAGID", "MSI_TRANSFORM_TAGID", "LINKER_VERSION", "LINK_DATE", "UPTO_LINK_DATE", "OS_SERVICE_PACK",
173 "FLAG_TAGID", "RUNTIME_PLATFORM", "OS_SKU", NULL
174 }
175 },
176 {
177 TAG_TYPE_DWORD, 0x800, __LINE__, VERSION_2003, VERSION_2003,
178 {
179 "InvalidTag", "SIZE", "OFFSET", "CHECKSUM", "SHIM_TAGID", "PATCH_TAGID", "MODULE_TYPE", "VERFILEDATEHI",
180 "VERFILEDATELO", "VERFILEOS", "VERFILETYPE", "PE_CHECKSUM", "PREVOSMAJORVERSION", "PREVOSMINORVERSION", "PREVOSPLATFORMID", "PREVOSBUILDNO",
181 "PROBLEM_SEVERITY", "APPHELP_LANGID", "VER_LANGUAGE", "InvalidTag", "ENGINE", "HTMLHELPID", "INDEXFLAGS", "FLAGS",
182 "VALUETYPE", "DATA_DWORD", "LAYER_TAGID", "MSI_TRANSFORM_TAGID", "LINKER_VERSION", "LINK_DATE", "UPTO_LINK_DATE", "OS_SERVICE_PACK",
183 "FLAG_TAGID", "RUNTIME_PLATFORM", "OS_SKU", "OS_PLATFORM", NULL
184 }
185 },
186 {
187 TAG_TYPE_DWORD, 0x800, __LINE__, VERSION_VISTA, VERSION_VISTA,
188 {
189 "InvalidTag", "SIZE", "OFFSET", "CHECKSUM", "SHIM_TAGID", "PATCH_TAGID", "MODULE_TYPE", "VERDATEHI",
190 "VERDATELO", "VERFILEOS", "VERFILETYPE", "PE_CHECKSUM", "PREVOSMAJORVER", "PREVOSMINORVER", "PREVOSPLATFORMID", "PREVOSBUILDNO",
191 "PROBLEMSEVERITY", "LANGID", "VER_LANGUAGE", "InvalidTag", "ENGINE", "HTMLHELPID", "INDEX_FLAGS", "FLAGS",
192 "DATA_VALUETYPE", "DATA_DWORD", "LAYER_TAGID", "MSI_TRANSFORM_TAGID", "LINKER_VERSION", "LINK_DATE", "UPTO_LINK_DATE", "OS_SERVICE_PACK",
193 "FLAG_TAGID", "RUNTIME_PLATFORM", "OS_SKU", "OS_PLATFORM", "APP_NAME_RC_ID", "VENDOR_NAME_RC_ID", "SUMMARY_MSG_RC_ID", "VISTA_SKU",
194 NULL
195 }
196 },
197 {
198 TAG_TYPE_DWORD, 0x800, __LINE__, VERSION_WIN7, VERSION_ANY,
199 {
200 "InvalidTag", "SIZE", "OFFSET", "CHECKSUM", "SHIM_TAGID", "PATCH_TAGID", "MODULE_TYPE", "VERDATEHI",
201 "VERDATELO", "VERFILEOS", "VERFILETYPE", "PE_CHECKSUM", "PREVOSMAJORVER", "PREVOSMINORVER", "PREVOSPLATFORMID", "PREVOSBUILDNO",
202 "PROBLEMSEVERITY", "LANGID", "VER_LANGUAGE", "InvalidTag", "ENGINE", "HTMLHELPID", "INDEX_FLAGS", "FLAGS",
203 "DATA_VALUETYPE", "DATA_DWORD", "LAYER_TAGID", "MSI_TRANSFORM_TAGID", "LINKER_VERSION", "LINK_DATE", "UPTO_LINK_DATE", "OS_SERVICE_PACK",
204 "FLAG_TAGID", "RUNTIME_PLATFORM", "OS_SKU", "OS_PLATFORM", "APP_NAME_RC_ID", "VENDOR_NAME_RC_ID", "SUMMARY_MSG_RC_ID", "VISTA_SKU",
205 "DESCRIPTION_RC_ID", "PARAMETER1_RC_ID", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag",
206 "CONTEXT_TAGID", "EXE_WRAPPER", "URL_ID", NULL
207 }
208 },
209 {
210 TAG_TYPE_DWORD | 0x800, 0x800, __LINE__, VERSION_ANY, VERSION_ANY,
211 {
212 "InvalidTag", "TAGID", NULL
213 }
214 },
215
216 {
217 TAG_TYPE_QWORD, 0x1000, __LINE__, VERSION_ANY, VERSION_WINXP,
218 {
219 "InvalidTag", "TIME", "BIN_FILE_VERSION", "BIN_PRODUCT_VERSION", "MODTIME", "FLAG_MASK_KERNEL", "UPTO_BIN_PRODUCT_VERSION", "DATA_QWORD",
220 "FLAG_MASK_USER", "FLAGS_NTVDM1", "FLAGS_NTVDM2", "FLAGS_NTVDM3", "FLAG_MASK_SHELL", "UPTO_BIN_FILE_VERSION", NULL
221 }
222 },
223 {
224 TAG_TYPE_QWORD, 0x1000, __LINE__, VERSION_2003, VERSION_2003,
225 {
226 "InvalidTag", "TIME", "BIN_FILE_VERSION", "BIN_PRODUCT_VERSION", "MODTIME", "FLAG_MASK_KERNEL", "UPTO_BIN_PRODUCT_VERSION", "DATA_QWORD",
227 "FLAG_MASK_USER", "FLAGS_NTVDM1", "FLAGS_NTVDM2", "FLAGS_NTVDM3", "FLAG_MASK_SHELL", "UPTO_BIN_FILE_VERSION", "FLAG_MASK_FUSION", "FLAGS_PROCESSPARAM",
228 NULL
229 }
230 },
231 {
232 TAG_TYPE_QWORD, 0x1000, __LINE__, VERSION_VISTA, VERSION_ANY,
233 {
234 "InvalidTag", "TIME", "BIN_FILE_VERSION", "BIN_PRODUCT_VERSION", "MODTIME", "FLAG_MASK_KERNEL", "UPTO_BIN_PRODUCT_VERSION", "DATA_QWORD",
235 "FLAG_MASK_USER", "FLAGS_NTVDM1", "FLAGS_NTVDM2", "FLAGS_NTVDM3", "FLAG_MASK_SHELL", "UPTO_BIN_FILE_VERSION", "FLAG_MASK_FUSION", "FLAG_PROCESSPARAM",
236 "FLAG_LUA", "FLAG_INSTALL", NULL
237 }
238 },
239
240 {
241 TAG_TYPE_STRINGREF, 0x1000, __LINE__, VERSION_ANY, VERSION_2003,
242 {
243 "InvalidTag", "NAME", "DESCRIPTION", "MODULE", "API", "VENDOR", "APP_NAME", "InvalidTag",
244 "COMMAND_LINE", "COMPANY_NAME", "DLLFILE", "WILDCARD_NAME", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag",
245 "PRODUCT_NAME", "PRODUCT_VERSION", "FILE_DESCRIPTION", "FILE_VERSION", "ORIGINAL_FILENAME", "INTERNAL_NAME", "LEGAL_COPYRIGHT", "S16BIT_DESCRIPTION",
246 "PROBLEM_DETAILS", "LINK_URL", "LINK_TEXT", "APPHELP_TITLE", "APPHELP_CONTACT", "SXS_MANIFEST", "DATA_STRING", "MSI_TRANSFORM_FILE",
247 "S16BIT_MODULE_NAME", "LAYER_DISPLAYNAME", "COMPILER_VERSION", "ACTION_TYPE", NULL
248 }
249 },
250 {
251 TAG_TYPE_STRINGREF, 0x1000, __LINE__, VERSION_VISTA, VERSION_VISTA,
252 {
253 "InvalidTag", "NAME", "DESCRIPTION", "MODULE", "API", "VENDOR", "APP_NAME", "InvalidTag",
254 "COMMAND_LINE", "COMPANY_NAME", "DLLFILE", "WILDCARD_NAME", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag",
255 "PRODUCT_NAME", "PRODUCT_VERSION", "FILE_DESCRIPTION", "FILE_VERSION", "ORIGINAL_FILENAME", "INTERNAL_NAME", "LEGAL_COPYRIGHT", "16BIT_DESCRIPTION",
256 "APPHELP_DETAILS", "LINK_URL", "LINK_TEXT", "APPHELP_TITLE", "APPHELP_CONTACT", "SXS_MANIFEST", "DATA_STRING", "MSI_TRANSFORM_FILE",
257 "16BIT_MODULE_NAME", "LAYER_DISPLAYNAME", "COMPILER_VERSION", "ACTION_TYPE", "EXPORT_NAME", NULL
258 }
259 },
260 {
261 TAG_TYPE_STRINGREF, 0x1000, __LINE__, VERSION_WIN7, VERSION_ANY,
262 {
263 "InvalidTag", "NAME", "DESCRIPTION", "MODULE", "API", "VENDOR", "APP_NAME", "InvalidTag",
264 "COMMAND_LINE", "COMPANY_NAME", "DLLFILE", "WILDCARD_NAME", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag",
265 "PRODUCT_NAME", "PRODUCT_VERSION", "FILE_DESCRIPTION", "FILE_VERSION", "ORIGINAL_FILENAME", "INTERNAL_NAME", "LEGAL_COPYRIGHT", "16BIT_DESCRIPTION",
266 "APPHELP_DETAILS", "LINK_URL", "LINK_TEXT", "APPHELP_TITLE", "APPHELP_CONTACT", "SXS_MANIFEST", "DATA_STRING", "MSI_TRANSFORM_FILE",
267 "16BIT_MODULE_NAME", "LAYER_DISPLAYNAME", "COMPILER_VERSION", "ACTION_TYPE", "EXPORT_NAME", "URL", NULL
268 }
269 },
270
271 {
272 TAG_TYPE_LIST, 0x800, __LINE__, VERSION_ANY, VERSION_2003,
273 {
274 "InvalidTag", "DATABASE", "LIBRARY", "INEXCLUDE", "SHIM", "PATCH", "APP", "EXE",
275 "MATCHING_FILE", "SHIM_REF", "PATCH_REF", "LAYER", "FILE", "APPHELP", "LINK", "DATA",
276 "MSI TRANSFORM", "MSI TRANSFORM REF", "MSI PACKAGE", "FLAG", "MSI CUSTOM ACTION", "FLAG_REF", "ACTION", NULL
277 }
278 },
279 {
280 TAG_TYPE_LIST, 0x800, __LINE__, VERSION_VISTA, VERSION_VISTA,
281 {
282 "InvalidTag", "DATABASE", "LIBRARY", "INEXCLUDE", "SHIM", "PATCH", "APP", "EXE",
283 "MATCHING_FILE", "SHIM_REF", "PATCH_REF", "LAYER", "FILE", "APPHELP", "LINK", "DATA",
284 "MSI_TRANSFORM", "MSI_TRANSFORM_REF", "MSI_PACKAGE", "FLAG", "MSI_CUSTOM_ACTION", "FLAG_REF", "ACTION", "LOOKUP",
285 NULL
286 }
287 },
288 {
289 TAG_TYPE_LIST, 0x800, __LINE__, VERSION_WIN7, VERSION_ANY,
290 {
291 "InvalidTag", "DATABASE", "LIBRARY", "INEXCLUDE", "SHIM", "PATCH", "APP", "EXE",
292 "MATCHING_FILE", "SHIM_REF", "PATCH_REF", "LAYER", "FILE", "APPHELP", "LINK", "DATA",
293 "MSI_TRANSFORM", "MSI_TRANSFORM_REF", "MSI_PACKAGE", "FLAG", "MSI_CUSTOM_ACTION", "FLAG_REF", "ACTION", "LOOKUP",
294 "CONTEXT", "CONTEXT_REF", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag",
295 "SPC", NULL
296 }
297 },
298 {
299 TAG_TYPE_LIST | 0x800, 0x800, __LINE__, VERSION_ANY, VERSION_ANY,
300 {
301 "InvalidTag", "STRINGTABLE", "INDEXES", "INDEX", NULL
302 }
303 },
304
305 {
306 TAG_TYPE_STRING, 0x800, __LINE__, VERSION_ANY, VERSION_ANY,
307 {
308 "InvalidTag", NULL
309 }
310 },
311 {
312 TAG_TYPE_STRING | 0x800, 0x800, __LINE__, VERSION_ANY, VERSION_2003,
313 {
314 "InvalidTag", "STRTAB_ITEM", NULL
315 }
316 },
317 {
318 TAG_TYPE_STRING | 0x800, 0x800, __LINE__, VERSION_VISTA, VERSION_ANY,
319 {
320 "InvalidTag", "STRINGTABLE_ITEM", NULL
321 }
322 },
323
324
325 {
326 TAG_TYPE_BINARY, 0x800, __LINE__, VERSION_ANY, VERSION_2003,
327 {
328 "InvalidTag", "InvalidTag", "PATCH_BITS", "FILE_BITS", "EXE_ID(GUID)", "DATA_BITS", "MSI_PACKAGE_ID(GUID)", "DATABASE_ID(GUID)",
329 NULL
330 }
331 },
332 {
333 TAG_TYPE_BINARY, 0x800, __LINE__, VERSION_VISTA, VERSION_VISTA,
334 {
335 "InvalidTag", "InvalidTag", "PATCH_BITS", "FILE_BITS", "EXE_ID", "DATA_BITS", "MSI_PACKAGE_ID", "DATABASE_ID",
336 NULL
337 }
338 },
339 {
340 TAG_TYPE_BINARY, 0x800, __LINE__, VERSION_WIN7, VERSION_ANY,
341 {
342 "InvalidTag", "InvalidTag", "PATCH_BITS", "FILE_BITS", "EXE_ID", "DATA_BITS", "MSI_PACKAGE_ID", "DATABASE_ID",
343 "CONTEXT_PLATFORM_ID", "CONTEXT_BRANCH_ID", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag",
344 "FIX_ID", "APP_ID", NULL
345 }
346 },
347 {
348 TAG_TYPE_BINARY | 0x800, 0x800, __LINE__, VERSION_ANY, VERSION_ANY,
349 {
350 "InvalidTag", "INDEX_BITS", NULL
351 }
352 },
353
354 { 0, 0, 0, 0, 0, { NULL } }
355 };
356
357
358 static void test_SdbTagToStringAllTags(void)
359 {
360 int n;
361 for (n = 0; data[n].base; ++n)
362 {
363 if ((data[n].min_ver == VERSION_ANY || g_Version >= data[n].min_ver) &&
364 (data[n].max_ver == VERSION_ANY || g_Version <= data[n].max_ver))
365 {
366 test_tag(data[n].base, data[n].tags, data[n].upper_limit, data[n].line);
367 }
368 }
369 }
370
371 START_TEST(apphelp)
372 {
373 RTL_OSVERSIONINFOEXW rtlinfo;
374 rtlinfo.dwOSVersionInfoSize = sizeof(rtlinfo);
375 #ifdef __REACTOS__
376 RtlGetVersion((PRTL_OSVERSIONINFOW)&rtlinfo);
377 #else
378 RtlGetVersion(&rtlinfo);
379 #endif
380 g_Version = (rtlinfo.dwMajorVersion << 8) | rtlinfo.dwMinorVersion;
381 trace("Detected version: 0x%x\n", g_Version);
382 //SetEnvironmentVariable("SHIM_DEBUG_LEVEL", "4");
383 //SetEnvironmentVariable("DEBUGCHANNEL", "+apphelp");
384 hdll = LoadLibraryA("apphelp.dll");
385 pSdbTagToString = (void *) GetProcAddress(hdll, "SdbTagToString");
386 test_SdbTagToString();
387 #ifdef __REACTOS__
388 if (g_Version < VERSION_WIN7)
389 {
390 g_Version = VERSION_WIN7;
391 trace("Using version 0x%x for SdbTagToString tests\n", g_Version);
392 }
393 #endif
394 test_SdbTagToStringAllTags();
395 }