92b8c7a696a9b801287c6e8ba92046aff9c55586
[reactos.git] / rostests / apitests / apphelp / db.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
37 #include "wine/test.h"
38
39 /* data.c */
40 void test_create_db(const char* name);
41
42 typedef WORD TAG;
43 typedef DWORD TAGID;
44 typedef DWORD TAGREF;
45 typedef UINT64 QWORD;
46 typedef VOID* PDB;
47 typedef INT PATH_TYPE;
48 #define DOS_PATH 0
49
50 #define TAGID_NULL 0x0
51 #define TAGID_ROOT 0x0
52 #define _TAGID_ROOT 12
53
54
55 #define TAG_TYPE_MASK 0xF000
56
57 #define TAG_TYPE_NULL 0x1000
58 #define TAG_TYPE_BYTE 0x2000
59 #define TAG_TYPE_WORD 0x3000
60 #define TAG_TYPE_DWORD 0x4000
61 #define TAG_TYPE_QWORD 0x5000
62 #define TAG_TYPE_STRINGREF 0x6000
63 #define TAG_TYPE_LIST 0x7000
64 #define TAG_TYPE_STRING 0x8000
65 #define TAG_TYPE_BINARY 0x9000
66 #define TAG_NULL 0x0
67
68 #define TAG_INCLUDE (0x1 | TAG_TYPE_NULL)
69
70 #define TAG_MATCH_MODE (0x1 | TAG_TYPE_WORD)
71
72 #define TAG_SIZE (0x1 | TAG_TYPE_DWORD)
73 #define TAG_CHECKSUM (0x3 | TAG_TYPE_DWORD)
74 #define TAG_MODULE_TYPE (0x6 | TAG_TYPE_DWORD)
75 #define TAG_VERFILEOS (0x9 | TAG_TYPE_DWORD)
76 #define TAG_VERFILETYPE (0xA | TAG_TYPE_DWORD)
77 #define TAG_PE_CHECKSUM (0xB | TAG_TYPE_DWORD)
78 #define TAG_PROBLEMSEVERITY (0x10 | TAG_TYPE_DWORD)
79 #define TAG_HTMLHELPID (0x15 | TAG_TYPE_DWORD)
80 #define TAG_FLAGS (0x17 | TAG_TYPE_DWORD)
81 #define TAG_LAYER_TAGID (0x1A | TAG_TYPE_DWORD)
82 #define TAG_LINKER_VERSION (0x1C | TAG_TYPE_DWORD)
83 #define TAG_LINK_DATE (0x1D | TAG_TYPE_DWORD)
84 #define TAG_UPTO_LINK_DATE (0x1E | TAG_TYPE_DWORD)
85 #define TAG_APP_NAME_RC_ID (0x24 | TAG_TYPE_DWORD)
86 #define TAG_VENDOR_NAME_RC_ID (0x25 | TAG_TYPE_DWORD)
87 #define TAG_SUMMARY_MSG_RC_ID (0x26 | TAG_TYPE_DWORD)
88 #define TAG_OS_PLATFORM (0x23 | TAG_TYPE_DWORD)
89
90 #define TAG_TIME (0x1 | TAG_TYPE_QWORD)
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_FLAG_LUA (0x10 | TAG_TYPE_QWORD)
96
97 #define TAG_DATABASE (0x1 | TAG_TYPE_LIST)
98 #define TAG_INEXCLUD (0x3 | TAG_TYPE_LIST)
99 #define TAG_EXE (0x7 | TAG_TYPE_LIST)
100 #define TAG_MATCHING_FILE (0x8 | TAG_TYPE_LIST)
101 #define TAG_SHIM_REF (0x9| TAG_TYPE_LIST)
102 #define TAG_LAYER (0xB | TAG_TYPE_LIST)
103 #define TAG_APPHELP (0xD | TAG_TYPE_LIST)
104 #define TAG_LINK (0xE | TAG_TYPE_LIST)
105 #define TAG_STRINGTABLE (0x801 | TAG_TYPE_LIST)
106
107 #define TAG_STRINGTABLE_ITEM (0x801 | TAG_TYPE_STRING)
108
109 #define TAG_NAME (0x1 | TAG_TYPE_STRINGREF)
110 #define TAG_MODULE (0x3 | TAG_TYPE_STRINGREF)
111 #define TAG_VENDOR (0x5 | TAG_TYPE_STRINGREF)
112 #define TAG_APP_NAME (0x6 | TAG_TYPE_STRINGREF)
113 #define TAG_COMMAND_LINE (0x8 | TAG_TYPE_STRINGREF)
114 #define TAG_COMPANY_NAME (0x9 | TAG_TYPE_STRINGREF)
115 #define TAG_PRODUCT_NAME (0x10 | TAG_TYPE_STRINGREF)
116 #define TAG_PRODUCT_VERSION (0x11 | TAG_TYPE_STRINGREF)
117 #define TAG_FILE_DESCRIPTION (0x12 | TAG_TYPE_STRINGREF)
118 #define TAG_FILE_VERSION (0x13 | TAG_TYPE_STRINGREF)
119 #define TAG_ORIGINAL_FILENAME (0x14 | TAG_TYPE_STRINGREF)
120 #define TAG_INTERNAL_NAME (0x15 | TAG_TYPE_STRINGREF)
121 #define TAG_LEGAL_COPYRIGHT (0x16 | TAG_TYPE_STRINGREF)
122 #define TAG_APPHELP_DETAILS (0x18 | TAG_TYPE_STRINGREF)
123 #define TAG_LINK_URL (0x19 | TAG_TYPE_STRINGREF)
124 #define TAG_APPHELP_TITLE (0x1B | TAG_TYPE_STRINGREF)
125
126 #define TAG_COMPILER_VERSION (0x22 | TAG_TYPE_STRINGREF)
127
128 #define TAG_GENERAL (0x2 | TAG_TYPE_NULL)
129
130 #define TAG_EXE_ID (0x4 | TAG_TYPE_BINARY)
131 #define TAG_DATA_BITS (0x5 | TAG_TYPE_BINARY)
132 #define TAG_DATABASE_ID (0x7 | TAG_TYPE_BINARY)
133
134
135
136 static HMODULE hdll;
137 static LPCWSTR (WINAPI *pSdbTagToString)(TAG);
138 static PDB (WINAPI *pSdbOpenDatabase)(LPCWSTR, PATH_TYPE);
139 static PDB (WINAPI *pSdbCreateDatabase)(LPCWSTR, PATH_TYPE);
140 static BOOL (WINAPI *pSdbGetDatabaseVersion)(LPCWSTR, PDWORD, PDWORD);
141 static void (WINAPI *pSdbCloseDatabase)(PDB);
142 static void (WINAPI *pSdbCloseDatabaseWrite)(PDB);
143 static TAG (WINAPI *pSdbGetTagFromTagID)(PDB, TAGID);
144 static BOOL (WINAPI *pSdbWriteNULLTag)(PDB, TAG);
145 static BOOL (WINAPI *pSdbWriteWORDTag)(PDB, TAG, WORD);
146 static BOOL (WINAPI *pSdbWriteDWORDTag)(PDB, TAG, DWORD);
147 static BOOL (WINAPI *pSdbWriteQWORDTag)(PDB, TAG, QWORD);
148 static BOOL (WINAPI *pSdbWriteBinaryTagFromFile)(PDB, TAG, LPCWSTR);
149 static BOOL (WINAPI *pSdbWriteStringTag)(PDB, TAG, LPCWSTR);
150 static BOOL (WINAPI *pSdbWriteStringRefTag)(PDB, TAG, TAGID);
151 static TAGID (WINAPI *pSdbBeginWriteListTag)(PDB, TAG);
152 static BOOL (WINAPI *pSdbEndWriteListTag)(PDB, TAGID);
153 static TAGID (WINAPI *pSdbFindFirstTag)(PDB, TAGID, TAG);
154 static TAGID (WINAPI *pSdbFindNextTag)(PDB, TAGID, TAGID);
155 static WORD (WINAPI *pSdbReadWORDTag)(PDB, TAGID, WORD);
156 static DWORD (WINAPI *pSdbReadDWORDTag)(PDB, TAGID, DWORD);
157 static QWORD (WINAPI *pSdbReadQWORDTag)(PDB, TAGID, QWORD);
158 static BOOL (WINAPI *pSdbReadBinaryTag)(PDB, TAGID, PBYTE, DWORD);
159 static BOOL (WINAPI *pSdbReadStringTag)(PDB, TAGID, LPWSTR, DWORD);
160 static DWORD (WINAPI *pSdbGetTagDataSize)(PDB, TAGID);
161 static PVOID (WINAPI *pSdbGetBinaryTagData)(PDB, TAGID);
162 static LPWSTR (WINAPI *pSdbGetStringTagPtr)(PDB, TAGID);
163 static TAGID (WINAPI *pSdbGetFirstChild)(PDB, TAGID);
164 static TAGID (WINAPI *pSdbGetNextChild)(PDB, TAGID, TAGID);
165 static BOOL (WINAPI *pSdbGetDatabaseID)(PDB, GUID*);
166 static BOOL (WINAPI *pSdbGUIDToString)(CONST GUID *, PCWSTR, SIZE_T);
167
168 static void Write(HANDLE file, LPCVOID buffer, DWORD size)
169 {
170 DWORD dwWritten = 0;
171 WriteFile(file, buffer, size, &dwWritten, NULL);
172 }
173
174 static void test_Sdb(void)
175 {
176 static const WCHAR temp[] = {'t','e','m','p',0};
177 static const WCHAR path1[] = {'t','e','m','p','.','s','d','b',0};
178 static const WCHAR path2[] = {'t','e','m','p','2','.','b','i','n',0};
179 static const WCHAR tag_size_string[] = {'S','I','Z','E',0};
180 static const WCHAR tag_flag_lua_string[] = {'F','L','A','G','_','L','U','A',0};
181 static const TAG tags[5] = {
182 TAG_SIZE, TAG_FLAG_LUA, TAG_NAME,
183 TAG_STRINGTABLE, TAG_STRINGTABLE_ITEM
184 };
185 WCHAR buffer[6] = {0};
186 PDB pdb;
187 QWORD qword;
188 DWORD dword;
189 WORD word;
190 BOOL ret;
191 HANDLE file; /* temp file created for testing purpose */
192 TAG tag;
193 TAGID tagid, ptagid, stringref = 6;
194 LPCWSTR string;
195 PBYTE binary;
196
197 pdb = pSdbCreateDatabase(path1, DOS_PATH);
198 ok (pdb != NULL, "failed to create database\n");
199 if(pdb != NULL)
200 {
201 ret = pSdbWriteDWORDTag(pdb, tags[0], 0xDEADBEEF);
202 ok (ret, "failed to write DWORD tag\n");
203 ret = pSdbWriteQWORDTag(pdb, tags[1], 0xDEADBEEFBABE);
204 ok (ret, "failed to write QWORD tag\n");
205 ret = pSdbWriteStringRefTag(pdb, tags[2], stringref);
206 ok (ret, "failed to write stringref tag\n");
207 tagid = pSdbBeginWriteListTag(pdb, tags[3]);
208 ok (tagid != TAGID_NULL, "unexpected NULL tagid\n");
209 ret = pSdbWriteStringTag(pdb, tags[4], temp);
210 ok (ret, "failed to write string tag\n");
211 ret = pSdbWriteNULLTag(pdb, TAG_GENERAL);
212 ok (ret, "failed to write NULL tag\n");
213 ret = pSdbWriteWORDTag(pdb, TAG_MATCH_MODE, 0xACE);
214 ok (ret, "failed to write WORD tag\n");
215 ret = pSdbEndWriteListTag(pdb, tagid);
216 ok (ret, "failed to update list size\n");
217 /* [Err ][SdbCloseDatabase ] Failed to close the file. */
218 pSdbCloseDatabaseWrite(pdb);
219 }
220
221 /* [Err ][SdbGetDatabaseID ] Failed to get root tag */
222 pdb = pSdbOpenDatabase(path1, DOS_PATH);
223 ok(pdb != NULL, "unexpected NULL handle\n");
224
225 if(pdb)
226 {
227 tagid = pSdbGetFirstChild(pdb, TAGID_ROOT);
228 ok(tagid == _TAGID_ROOT, "unexpected tagid %u, expected %u\n", tagid, _TAGID_ROOT);
229
230 tag = pSdbGetTagFromTagID(pdb, tagid);
231 ok(tag == TAG_SIZE, "unexpected tag 0x%x, expected 0x%x\n", tag, TAG_SIZE);
232
233 string = pSdbTagToString(tag);
234 ok(lstrcmpW(string, tag_size_string) == 0, "unexpected string %s, expected %s\n",
235 wine_dbgstr_w(string), wine_dbgstr_w(tag_size_string));
236
237 dword = pSdbReadDWORDTag(pdb, tagid, 0);
238 ok(dword == 0xDEADBEEF, "unexpected value %u, expected 0xDEADBEEF\n", dword);
239
240 tagid = pSdbGetNextChild(pdb, TAGID_ROOT, tagid);
241 ok(tagid == _TAGID_ROOT + sizeof(TAG) + sizeof(DWORD), "unexpected tagid %u, expected %u\n",
242 tagid, _TAGID_ROOT + sizeof(TAG) + sizeof(DWORD));
243
244 tag = pSdbGetTagFromTagID(pdb, tagid);
245 ok (tag == TAG_FLAG_LUA, "unexpected tag 0x%x, expected 0x%x\n", tag, TAG_FLAG_LUA);
246
247 string = pSdbTagToString(tag);
248 ok(lstrcmpW(string, tag_flag_lua_string) == 0, "unexpected string %s, expected %s\n",
249 wine_dbgstr_w(string), wine_dbgstr_w(tag_flag_lua_string));
250
251 qword = pSdbReadQWORDTag(pdb, tagid, 0);
252 ok(qword == 0xDEADBEEFBABE, "unexpected value 0x%I64x, expected 0xDEADBEEFBABE\n", qword);
253
254 tagid = pSdbGetNextChild(pdb, TAGID_ROOT, tagid);
255 string = pSdbGetStringTagPtr(pdb, tagid);
256 ok (string && (lstrcmpW(string, temp) == 0), "unexpected string %s, expected %s\n",
257 wine_dbgstr_w(string), wine_dbgstr_w(temp));
258
259 ptagid = pSdbGetNextChild(pdb, TAGID_ROOT, tagid);
260 tagid = pSdbGetFirstChild(pdb, ptagid);
261
262 string = pSdbGetStringTagPtr(pdb, tagid);
263 ok (string && (lstrcmpW(string, temp) == 0), "unexpected string %s, expected %s\n",
264 wine_dbgstr_w(string), wine_dbgstr_w(temp));
265
266 ok (pSdbReadStringTag(pdb, tagid, buffer, 6), "failed to write string to buffer\n");
267 /* [Err ][SdbpReadTagData ] Buffer too small. Avail: 6, Need: 10. */
268 ok (!pSdbReadStringTag(pdb, tagid, buffer, 3), "string was written to buffer, but failure was expected");
269 ok (pSdbGetTagDataSize(pdb, tagid) == 5 * sizeof(WCHAR), "string has unexpected size\n");
270
271 tagid = pSdbGetNextChild(pdb, ptagid, tagid);
272 tag = pSdbGetTagFromTagID(pdb, tagid);
273 ok (tag == TAG_GENERAL, "unexpected tag 0x%x, expected 0x%x\n", tag, TAG_GENERAL);
274 ok (pSdbGetTagDataSize(pdb, tagid) == 0, "null tag with size > 0\n");
275
276 tagid = pSdbGetNextChild(pdb, ptagid, tagid);
277 word = pSdbReadWORDTag(pdb, tagid, 0);
278 ok (word == 0xACE, "unexpected value 0x%x, expected 0x%x\n", word, 0xACE);
279
280 pSdbCloseDatabase(pdb);
281 }
282 DeleteFileW(path1);
283
284 file = CreateFileW(path2, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
285 ok (file != INVALID_HANDLE_VALUE, "failed to open file\n");
286 Write(file, &qword, 8);
287 CloseHandle(file);
288
289 pdb = pSdbCreateDatabase(path1, DOS_PATH);
290 ok(pdb != NULL, "unexpected NULL handle\n");
291
292 if(pdb)
293 {
294 ret = pSdbWriteBinaryTagFromFile(pdb, TAG_DATA_BITS, path2);
295 ok(ret, "failed to write tag from binary file\n");
296 pSdbCloseDatabaseWrite(pdb); /* [Err ][SdbCloseDatabase ] Failed to close the file. */
297 DeleteFileW(path2);
298
299 pdb = pSdbOpenDatabase(path1, DOS_PATH);
300 ok(pdb != NULL, "unexpected NULL handle\n");
301 binary = pSdbGetBinaryTagData(pdb, _TAGID_ROOT);
302 ok(memcmp(binary, &qword, 8) == 0, "binary data is corrupt\n");
303 ret = pSdbReadBinaryTag(pdb, _TAGID_ROOT, (PBYTE)buffer, 12);
304 ok(ret, "failed to read binary tag\n");
305 ok(memcmp(buffer, &qword, 8) == 0, "binary data is corrupt\n");
306 pSdbCloseDatabase(pdb);
307 }
308 DeleteFileW(path1);
309 }
310
311 static void match_str_attr_imp(PDB pdb, TAGID parent, TAG find, const char* compare)
312 {
313 TAGID attr = pSdbFindFirstTag(pdb, parent, find);
314 winetest_ok(attr != TAG_NULL, "Could not find: %x\n", find);
315 if (attr != TAG_NULL)
316 {
317 LPWSTR name = pSdbGetStringTagPtr(pdb, attr);
318 winetest_ok(name != NULL, "Could not convert attr to str.\n");
319 if (name)
320 {
321 char name_a[100];
322 WideCharToMultiByte(CP_ACP, 0, name, -1, name_a, sizeof(name_a), NULL, NULL);
323 winetest_ok(strcmp(name_a, compare) == 0, "Expected tagid %x to be %s, was %s\n", attr, compare, name_a);
324 }
325 }
326 }
327
328 static void match_dw_attr_imp(PDB pdb, TAGID parent, TAG find, DWORD compare)
329 {
330 TAGID attr = pSdbFindFirstTag(pdb, parent, find);
331 winetest_ok(attr != TAG_NULL, "Could not find: %x\n", find);
332 if (attr != TAG_NULL)
333 {
334 DWORD val = pSdbReadDWORDTag(pdb, attr, 0x1234567);
335 winetest_ok(val == compare, "Expected tagid %x to be 0x%x, was 0x%x\n", attr, compare, val);
336 }
337 }
338
339 static void match_qw_attr_imp(PDB pdb, TAGID parent, TAG find, QWORD compare)
340 {
341 TAGID attr = pSdbFindFirstTag(pdb, parent, find);
342 winetest_ok(attr != TAG_NULL, "Could not find: %x\n", find);
343 if (attr != TAG_NULL)
344 {
345 QWORD val = pSdbReadQWORDTag(pdb, attr, 0x123456789abcdef);
346 winetest_ok(val == compare, "Expected tagid %x to be 0x%I64x, was 0x%I64x\n", attr, compare, val);
347 }
348 }
349
350 static void match_guid_attr_imp(PDB pdb, TAGID parent, TAG find, const GUID* compare)
351 {
352 TAGID attr = pSdbFindFirstTag(pdb, parent, find);
353 winetest_ok(attr != TAG_NULL, "Could not find: %x\n", find);
354 if (attr != TAG_NULL)
355 {
356 GUID guid = {0};
357 BOOL result = pSdbReadBinaryTag(pdb, attr, (PBYTE)&guid, sizeof(guid));
358 winetest_ok(result, "expected pSdbReadBinaryTag not to fail.\n");
359 winetest_ok(IsEqualGUID(&guid, compare), "expected guids to be equal(%s:%s)\n", wine_dbgstr_guid(&guid), wine_dbgstr_guid(compare));
360 }
361 }
362
363 #define match_str_attr (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : match_str_attr_imp
364 #define match_dw_attr (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : match_dw_attr_imp
365 #define match_qw_attr (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : match_qw_attr_imp
366 #define match_guid_attr (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : match_guid_attr_imp
367
368
369 //The application name cannot contain any of the following characters:
370 // \ / < > : * ? | "
371
372 static void check_db_properties(PDB pdb, TAGID root)
373 {
374 TAGID iter = pSdbFindFirstTag(pdb, root, TAG_DATABASE_ID);
375 ok(iter != TAGID_NULL, "expected a result, got TAGID_NULL\n");
376 if(iter != TAGID_NULL)
377 {
378 GUID guid = {0}, guid2 = {0};
379 BOOL result = pSdbReadBinaryTag(pdb, iter, (PBYTE)&guid, sizeof(guid));
380 ok(result, "expected SdbReadBinaryTag not to fail.\n");
381 if(result)
382 {
383 WCHAR guid_wstr[50];
384 result = pSdbGUIDToString(&guid, guid_wstr, 50);
385 ok(result, "expected SdbGUIDToString not to fail.\n");
386 if(result)
387 {
388 char guid_str[50];
389 WideCharToMultiByte( CP_ACP, 0, guid_wstr, -1, guid_str, sizeof(guid_str), NULL, NULL );
390 ok_str(guid_str, "{6e989ab7-864d-4575-8734-90364ac64fbd}");
391 }
392 ok(pSdbGetDatabaseID(pdb, &guid2),"expected SdbGetDatabaseID not to fail.\n");
393 ok(IsEqualGUID(&guid, &guid2), "expected guids to be equal(%s:%s)\n", wine_dbgstr_guid(&guid), wine_dbgstr_guid(&guid2));
394 }
395 }
396 match_qw_attr(pdb, root, TAG_TIME, 0x1d0f3e6003f963e);
397 match_str_attr(pdb, root, TAG_COMPILER_VERSION, "2.1.0.3");
398 match_str_attr(pdb, root, TAG_NAME, "apphelp_test1");
399 match_dw_attr(pdb, root, TAG_OS_PLATFORM, 1);
400 }
401
402 static void check_db_layer(PDB pdb, TAGID layer)
403 {
404 TAGID shimref, inexclude, is_include;
405 ok(layer != TAGID_NULL, "Expected a valid layer, got NULL\n");
406 if(!layer)
407 return;
408
409 match_str_attr(pdb, layer, TAG_NAME, "TestNewMode");
410 shimref = pSdbFindFirstTag(pdb, layer, TAG_SHIM_REF);
411 ok(shimref != TAGID_NULL, "Expected a valid shim ref, got NULL\n");
412 if(!shimref)
413 return;
414
415 match_str_attr(pdb, shimref, TAG_NAME, "VirtualRegistry");
416 match_str_attr(pdb, shimref, TAG_COMMAND_LINE, "ThemeActive");
417 inexclude = pSdbFindFirstTag(pdb, shimref, TAG_INEXCLUD);
418 ok(inexclude != TAGID_NULL, "Expected a valid in/exclude ref, got NULL\n");
419 if(!inexclude)
420 return;
421
422 is_include = pSdbFindFirstTag(pdb, inexclude, TAG_INCLUDE);
423 ok(is_include != TAGID_NULL, "Expected a valid include ref, got NULL\n");
424 match_str_attr(pdb, inexclude, TAG_MODULE, "include.dll");
425
426 inexclude = pSdbFindNextTag(pdb, shimref, inexclude);
427 ok(inexclude != TAGID_NULL, "Expected a valid in/exclude ref, got NULL\n");
428 if(!inexclude)
429 return;
430
431 is_include = pSdbFindFirstTag(pdb, inexclude, TAG_INCLUDE);
432 ok(is_include == TAGID_NULL, "Expected a NULL include ref, but got one anyway.\n");
433 match_str_attr(pdb, inexclude, TAG_MODULE, "exclude.dll");
434 }
435
436 static void check_matching_file(PDB pdb, TAGID exe, TAGID matching_file, int num)
437 {
438 ok(matching_file != TAGID_NULL, "Expected to find atleast 1 matching file.\n");
439 if(matching_file == TAGID_NULL)
440 return;
441
442 ok(num < 4, "Too many matches, expected only 4!\n");
443 if (num >= 4)
444 return;
445
446
447 match_str_attr(pdb, matching_file, TAG_NAME, "*");
448 match_str_attr(pdb, matching_file, TAG_COMPANY_NAME, "CompanyName");
449 match_str_attr(pdb, matching_file, TAG_PRODUCT_NAME, "ProductName");
450 match_str_attr(pdb, matching_file, TAG_PRODUCT_VERSION, "1.0.0.1");
451 match_str_attr(pdb, matching_file, TAG_FILE_VERSION, "1.0.0.0");
452
453 if( num == 0 || num == 3)
454 {
455 match_qw_attr(pdb, matching_file, TAG_UPTO_BIN_PRODUCT_VERSION, 0x1000000000001);
456 match_qw_attr(pdb, matching_file, TAG_UPTO_BIN_FILE_VERSION, 0x1000000000000);
457 }
458 if(num == 1 || num == 3)
459 {
460 match_dw_attr(pdb, matching_file, TAG_PE_CHECKSUM, 0x1848);
461 }
462 if(num != 0)
463 {
464 match_qw_attr(pdb, matching_file, TAG_BIN_PRODUCT_VERSION, 0x1000000000001);
465 match_qw_attr(pdb, matching_file, TAG_BIN_FILE_VERSION, 0x1000000000000);
466 }
467 if(num == 3)
468 {
469 match_dw_attr(pdb, matching_file, TAG_SIZE, 0x800);
470 match_dw_attr(pdb, matching_file, TAG_CHECKSUM, 0x550826fe);
471 match_str_attr(pdb, matching_file, TAG_FILE_DESCRIPTION, "FileDescription");
472 match_dw_attr(pdb, matching_file, TAG_MODULE_TYPE, 3);
473 match_dw_attr(pdb, matching_file, TAG_VERFILEOS, 4);
474 match_dw_attr(pdb, matching_file, TAG_VERFILETYPE, 1);
475 match_dw_attr(pdb, matching_file, TAG_LINKER_VERSION, 0);
476 match_str_attr(pdb, matching_file, TAG_ORIGINAL_FILENAME, "OriginalFilename");
477 match_str_attr(pdb, matching_file, TAG_INTERNAL_NAME, "InternalName");
478 match_str_attr(pdb, matching_file, TAG_LEGAL_COPYRIGHT, "LegalCopyright");
479 match_dw_attr(pdb, matching_file, TAG_LINK_DATE, 0);
480 match_dw_attr(pdb, matching_file, TAG_UPTO_LINK_DATE, 0);
481 }
482 if(num > 3)
483 {
484 ok(0, "unknown case: %d\n", num);
485 }
486 matching_file = pSdbFindNextTag(pdb, exe, matching_file);
487 if(num == 2)
488 {
489 ok(matching_file != TAGID_NULL, "Did expect a secondary match on %d\n", num);
490 match_str_attr(pdb, matching_file, TAG_NAME, "test_checkfile.txt");
491 match_dw_attr(pdb, matching_file, TAG_SIZE, 0x4);
492 match_dw_attr(pdb, matching_file, TAG_CHECKSUM, 0xb0b0b0b0);
493 }
494 else
495 {
496 ok(matching_file == TAGID_NULL, "Did not expect a secondary match on %d\n", num);
497 }
498 }
499
500 static void check_matching_apphelp(PDB pdb, TAGID apphelp, int num)
501 {
502 if(num == 0)
503 {
504 /*
505 [Window Title]
506 Program Compatibility Assistant
507
508 [Main Instruction]
509 This program has known compatibility issues
510
511 [Expanded Information]
512 Allow it!
513
514 [^] Hide details [ ] Don't show this message again [Check for solutions online] [Run program] [Cancel]
515 */
516 match_dw_attr(pdb, apphelp, TAG_FLAGS, 1);
517 match_dw_attr(pdb, apphelp, TAG_PROBLEMSEVERITY, 1);
518 match_dw_attr(pdb, apphelp, TAG_HTMLHELPID, 4);
519 match_dw_attr(pdb, apphelp, TAG_APP_NAME_RC_ID, 0x300078);
520 match_dw_attr(pdb, apphelp, TAG_VENDOR_NAME_RC_ID, 0x200022);
521 match_dw_attr(pdb, apphelp, TAG_SUMMARY_MSG_RC_ID, 0);
522 }
523 else
524 {
525 /*
526 [Window Title]
527 Program Compatibility Assistant
528
529 [Main Instruction]
530 This program is blocked due to compatibility issues
531
532 [Expanded Information]
533 Not allowed!
534
535 [^] Hide details [Check for solutions online] [Cancel]
536 */
537 match_dw_attr(pdb, apphelp, TAG_FLAGS, 1);
538 match_dw_attr(pdb, apphelp, TAG_PROBLEMSEVERITY, 2);
539 match_dw_attr(pdb, apphelp, TAG_HTMLHELPID, 3);
540 match_dw_attr(pdb, apphelp, TAG_APP_NAME_RC_ID, 0x200065);
541 match_dw_attr(pdb, apphelp, TAG_VENDOR_NAME_RC_ID, 0);
542 match_dw_attr(pdb, apphelp, TAG_SUMMARY_MSG_RC_ID, 0);
543 }
544 apphelp = pSdbFindNextTag(pdb, apphelp, apphelp);
545 ok(apphelp == TAGID_NULL, "Did not expect a secondary match on %d\n", num);
546 }
547
548 static void check_matching_layer(PDB pdb, TAGID layer, int num)
549 {
550 if(num == 2)
551 {
552 match_dw_attr(pdb, layer, TAG_LAYER_TAGID, 0x18e);
553 match_str_attr(pdb, layer, TAG_NAME, "TestNewMode");
554 }
555 else
556 {
557 TAGID layer_tagid = pSdbFindFirstTag(pdb, layer, TAG_LAYER_TAGID);
558 ok(layer_tagid == TAGID_NULL, "expected not to find a layer tagid, got %x\n", layer_tagid);
559 match_str_attr(pdb, layer, TAG_NAME, "WinSrv03");
560 }
561 }
562
563 static struct
564 {
565 const char* name;
566 const char* app_name;
567 const char* vendor;
568 GUID exe_id;
569 const char* extra_file;
570 DWORD dwLayerCount;
571 TAGREF atrExes_0;
572 TAGREF atrLayers_0;
573 } test_exedata[4] = {
574 {
575 "test_allow.exe",
576 "apphelp_name_allow",
577 "apphelp_vendor_allow",
578 {0x1a263552,0xe904,0x41b2,{0x98,0x95,0x1a,0x40,0xd9,0x15,0x2b,0x58}},
579 NULL,
580 0,
581 0x1c6,
582 0,
583 },
584 {
585 "test_disallow.exe",
586 "apphelp_name_disallow",
587 "apphelp_vendor_disallow",
588 {0xae94e02d,0x6300,0x4ee3,{0x92,0xc7,0x6f,0x51,0x09,0xd3,0xae,0xc0}},
589 NULL,
590 0,
591 0x256,
592 0,
593 },
594 {
595 "test_new.exe",
596 "fixnew_name",
597 "fixnew_vendor",
598 {0x5b6958c0,0x6084,0x4f7b,{0xb2,0x9e,0xd2,0xe2,0xa4,0x11,0x98,0x68}},
599 "test_checkfile.txt",
600 1,
601 0x2ec,
602 0x18e,
603 },
604 {
605 "test_w2k3.exe",
606 "fix_name",
607 "fix_vendor",
608 {0x8a3e9b36,0xafd0,0x42d0,{0x83,0x8d,0xe3,0x1c,0x19,0xc4,0x15,0x46}},
609 NULL,
610 0,
611 0x37c,
612 0,
613 },
614 };
615
616 static void check_db_exes(PDB pdb, TAGID root)
617 {
618 int num = 0;
619 TAGID exe = pSdbFindFirstTag(pdb, root, TAG_EXE);
620 while (exe != TAGID_NULL)
621 {
622 TAGID apphelp, layer;
623 ok(num < 4, "Too many matches, expected only 4!\n");
624 if(num >= 4)
625 break;
626 match_str_attr(pdb, exe, TAG_NAME, test_exedata[num].name);
627 match_str_attr(pdb, exe, TAG_APP_NAME, test_exedata[num].app_name);
628 match_str_attr(pdb, exe, TAG_VENDOR, test_exedata[num].vendor);
629 match_guid_attr(pdb, exe, TAG_EXE_ID, &test_exedata[num].exe_id);
630 check_matching_file(pdb, exe, pSdbFindFirstTag(pdb, exe, TAG_MATCHING_FILE), num);
631 apphelp = pSdbFindFirstTag(pdb, exe, TAG_APPHELP);
632 if(num == 0 || num == 1)
633 {
634 ok(apphelp != TAGID_NULL, "Expected to find a valid apphelp match on %d.\n", num);
635 if(apphelp)
636 check_matching_apphelp(pdb, apphelp, num);
637 }
638 else
639 {
640 ok(apphelp == TAGID_NULL, "Did not expect an apphelp match on %d\n", num);
641 }
642 layer = pSdbFindFirstTag(pdb, exe, TAG_LAYER);
643 if(num == 2 || num == 3)
644 {
645 ok(layer != TAGID_NULL, "Expected to find a valid layer match on %d.\n", num);
646 if(layer)
647 check_matching_layer(pdb, layer, num);
648 }
649 else
650 {
651 ok(layer == TAGID_NULL, "Did not expect a layer match on %d\n", num);
652 }
653 ++num;
654 exe = pSdbFindNextTag(pdb, root, exe);
655 }
656 ok(num == 4, "Expected to find 4 exe tags, found: %d\n", num);
657 }
658
659 static struct
660 {
661 DWORD htmlhelpid;
662 const char* link;
663 const char* apphelp_title;
664 const char* apphelp_details;
665 } test_layerdata[2] = {
666 {
667 4,
668 "http://reactos.org/allow",
669 "apphelp_name_allow",
670 "Allow it!",
671 },
672 {
673 3,
674 "http://reactos.org/disallow",
675 "apphelp_name_disallow",
676 "Not allowed!",
677 },
678 };
679
680 static void check_db_apphelp(PDB pdb, TAGID root)
681 {
682 int num = 0;
683 TAGID apphelp = pSdbFindFirstTag(pdb, root, TAG_APPHELP);
684 while (apphelp != TAGID_NULL)
685 {
686 TAGID link;
687 ok(num < 2, "Too many matches, expected only 4!\n");
688 if(num >= 2)
689 break;
690 match_dw_attr(pdb, apphelp, TAG_HTMLHELPID, test_layerdata[num].htmlhelpid);
691 link = pSdbFindFirstTag(pdb, apphelp, TAG_LINK);
692 ok(link != TAGID_NULL, "expected to find a link tag\n");
693 if (link != TAGID_NULL)
694 {
695 match_str_attr(pdb, link, TAG_LINK_URL, test_layerdata[num].link);
696 }
697 match_str_attr(pdb, apphelp, TAG_APPHELP_TITLE, test_layerdata[num].apphelp_title);
698 match_str_attr(pdb, apphelp, TAG_APPHELP_DETAILS, test_layerdata[num].apphelp_details);
699 apphelp = pSdbFindNextTag(pdb, root, apphelp);
700 num++;
701 }
702 ok(num == 2, "Expected to find 2 layer tags, found: %d\n", num);
703 }
704
705 static void test_CheckDatabaseManually(void)
706 {
707 static const WCHAR path[] = {'t','e','s','t','_','d','b','.','s','d','b',0};
708 TAGID root;
709 PDB pdb;
710 BOOL ret;
711 DWORD ver_hi, ver_lo;
712
713 test_create_db("test_db.sdb");
714
715 /* both ver_hi and ver_lo cannot be null, it'll crash. */
716 ver_hi = ver_lo = 0x12345678;
717 ret = pSdbGetDatabaseVersion(path, &ver_hi, &ver_lo);
718 ok(ret,"Expected SdbGetDatabaseVersion to succeed\n");
719 ok(ver_hi == 2,"Expected ver_hi to be 2, was: %d\n", ver_hi);
720 ok(ver_lo == 1,"Expected ver_lo to be 1, was: %d\n", ver_lo);
721
722 ver_hi = ver_lo = 0x12345678;
723 ret = pSdbGetDatabaseVersion(NULL, &ver_hi, &ver_lo);
724 ok(ret,"Expected SdbGetDatabaseVersion to succeed\n");
725 ok(ver_hi == 0x12345678,"Expected ver_hi to be 0x12345678, was: 0x%x\n", ver_hi);
726 ok(ver_lo == 0x12345678,"Expected ver_lo to be 0x12345678, was: 0x%x\n", ver_lo);
727
728 ver_hi = ver_lo = 0x12345678;
729 ret = pSdbGetDatabaseVersion(path + 1, &ver_hi, &ver_lo);
730 ok(ret,"Expected SdbGetDatabaseVersion to succeed\n");
731 ok(ver_hi == 0x12345678,"Expected ver_hi to be 0x12345678, was: 0x%x\n", ver_hi);
732 ok(ver_lo == 0x12345678,"Expected ver_lo to be 0x12345678, was: 0x%x\n", ver_lo);
733
734 pdb = pSdbOpenDatabase(path, DOS_PATH);
735 ok(pdb != NULL, "unexpected NULL handle\n");
736
737 root = pSdbFindFirstTag(pdb, TAGID_ROOT, TAG_DATABASE);
738 ok(root != TAGID_NULL, "expected to find a root tag\n");
739 if (root != TAGID_NULL)
740 {
741 check_db_properties(pdb, root);
742 check_db_layer(pdb, pSdbFindFirstTag(pdb, root, TAG_LAYER));
743 check_db_exes(pdb, root);
744 check_db_apphelp(pdb, root);
745 }
746
747 pSdbCloseDatabase(pdb);
748 DeleteFileA("test_db.sdb");
749 }
750
751 START_TEST(db)
752 {
753 //SetEnvironmentVariable("SHIM_DEBUG_LEVEL", "4");
754 //SetEnvironmentVariable("DEBUGCHANNEL", "+apphelp");
755 hdll = LoadLibraryA("apphelp.dll");
756 pSdbTagToString = (void *) GetProcAddress(hdll, "SdbTagToString");
757 pSdbOpenDatabase = (void *) GetProcAddress(hdll, "SdbOpenDatabase");
758 pSdbCreateDatabase = (void *) GetProcAddress(hdll, "SdbCreateDatabase");
759 pSdbGetDatabaseVersion = (void *) GetProcAddress(hdll, "SdbGetDatabaseVersion");
760 pSdbCloseDatabase = (void *) GetProcAddress(hdll, "SdbCloseDatabase");
761 pSdbCloseDatabaseWrite = (void *) GetProcAddress(hdll, "SdbCloseDatabaseWrite");
762 pSdbGetTagFromTagID = (void *) GetProcAddress(hdll, "SdbGetTagFromTagID");
763 pSdbWriteNULLTag = (void *) GetProcAddress(hdll, "SdbWriteNULLTag");
764 pSdbWriteWORDTag = (void *) GetProcAddress(hdll, "SdbWriteWORDTag");
765 pSdbWriteDWORDTag = (void *) GetProcAddress(hdll, "SdbWriteDWORDTag");
766 pSdbWriteQWORDTag = (void *) GetProcAddress(hdll, "SdbWriteQWORDTag");
767 pSdbWriteBinaryTagFromFile = (void *) GetProcAddress(hdll, "SdbWriteBinaryTagFromFile");
768 pSdbWriteStringTag = (void *) GetProcAddress(hdll, "SdbWriteStringTag");
769 pSdbWriteStringRefTag = (void *) GetProcAddress(hdll, "SdbWriteStringRefTag");
770 pSdbBeginWriteListTag = (void *)GetProcAddress(hdll, "SdbBeginWriteListTag");
771 pSdbEndWriteListTag = (void *) GetProcAddress(hdll, "SdbEndWriteListTag");
772 pSdbFindFirstTag = (void *) GetProcAddress(hdll, "SdbFindFirstTag");
773 pSdbFindNextTag = (void *) GetProcAddress(hdll, "SdbFindNextTag");
774 pSdbReadWORDTag = (void *) GetProcAddress(hdll, "SdbReadWORDTag");
775 pSdbReadDWORDTag = (void *) GetProcAddress(hdll, "SdbReadDWORDTag");
776 pSdbReadQWORDTag = (void *) GetProcAddress(hdll, "SdbReadQWORDTag");
777 pSdbReadBinaryTag = (void *) GetProcAddress(hdll, "SdbReadBinaryTag");
778 pSdbReadStringTag = (void *) GetProcAddress(hdll, "SdbReadStringTag");
779 pSdbGetTagDataSize = (void *) GetProcAddress(hdll, "SdbGetTagDataSize");
780 pSdbGetBinaryTagData = (void *) GetProcAddress(hdll, "SdbGetBinaryTagData");
781 pSdbGetStringTagPtr = (void *) GetProcAddress(hdll, "SdbGetStringTagPtr");
782 pSdbGetFirstChild = (void *) GetProcAddress(hdll, "SdbGetFirstChild");
783 pSdbGetNextChild = (void *) GetProcAddress(hdll, "SdbGetNextChild");
784 pSdbGetDatabaseID = (void *) GetProcAddress(hdll, "SdbGetDatabaseID");
785 pSdbGUIDToString = (void *) GetProcAddress(hdll, "SdbGUIDToString");
786
787 test_Sdb();
788 test_CheckDatabaseManually();
789 }