Art work commit:
[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 #include "apphelp_apitest.h"
40
41
42
43 typedef WORD TAG;
44 typedef DWORD TAGID;
45 typedef DWORD TAGREF;
46 typedef UINT64 QWORD;
47 typedef VOID* PDB;
48 typedef VOID* HSDB;
49 typedef INT PATH_TYPE;
50
51 #define DOS_PATH 0
52 #define HID_DATABASE_FULLPATH 2
53
54 #define SDB_DATABASE_MAIN_SHIM 0x80030000
55
56
57 #define TAGID_NULL 0x0
58 #define TAGID_ROOT 0x0
59 #define _TAGID_ROOT 12
60
61
62 #define TAG_TYPE_MASK 0xF000
63
64 #define TAG_TYPE_NULL 0x1000
65 #define TAG_TYPE_BYTE 0x2000
66 #define TAG_TYPE_WORD 0x3000
67 #define TAG_TYPE_DWORD 0x4000
68 #define TAG_TYPE_QWORD 0x5000
69 #define TAG_TYPE_STRINGREF 0x6000
70 #define TAG_TYPE_LIST 0x7000
71 #define TAG_TYPE_STRING 0x8000
72 #define TAG_TYPE_BINARY 0x9000
73 #define TAG_NULL 0x0
74
75 #define TAG_INCLUDE (0x1 | TAG_TYPE_NULL)
76
77 #define TAG_MATCH_MODE (0x1 | TAG_TYPE_WORD)
78
79 #define TAG_SIZE (0x1 | TAG_TYPE_DWORD)
80 #define TAG_CHECKSUM (0x3 | TAG_TYPE_DWORD)
81 #define TAG_MODULE_TYPE (0x6 | TAG_TYPE_DWORD)
82 #define TAG_VERFILEOS (0x9 | TAG_TYPE_DWORD)
83 #define TAG_VERFILETYPE (0xA | TAG_TYPE_DWORD)
84 #define TAG_PE_CHECKSUM (0xB | TAG_TYPE_DWORD)
85 #define TAG_PROBLEMSEVERITY (0x10 | TAG_TYPE_DWORD)
86 #define TAG_HTMLHELPID (0x15 | TAG_TYPE_DWORD)
87 #define TAG_FLAGS (0x17 | TAG_TYPE_DWORD)
88 #define TAG_LAYER_TAGID (0x1A | TAG_TYPE_DWORD)
89 #define TAG_LINKER_VERSION (0x1C | TAG_TYPE_DWORD)
90 #define TAG_LINK_DATE (0x1D | TAG_TYPE_DWORD)
91 #define TAG_UPTO_LINK_DATE (0x1E | TAG_TYPE_DWORD)
92 #define TAG_APP_NAME_RC_ID (0x24 | TAG_TYPE_DWORD)
93 #define TAG_VENDOR_NAME_RC_ID (0x25 | TAG_TYPE_DWORD)
94 #define TAG_SUMMARY_MSG_RC_ID (0x26 | TAG_TYPE_DWORD)
95 #define TAG_OS_PLATFORM (0x23 | TAG_TYPE_DWORD)
96
97 #define TAG_TIME (0x1 | TAG_TYPE_QWORD)
98 #define TAG_BIN_FILE_VERSION (0x2 | TAG_TYPE_QWORD)
99 #define TAG_BIN_PRODUCT_VERSION (0x3 | TAG_TYPE_QWORD)
100 #define TAG_UPTO_BIN_PRODUCT_VERSION (0x6 | TAG_TYPE_QWORD)
101 #define TAG_UPTO_BIN_FILE_VERSION (0xD | TAG_TYPE_QWORD)
102 #define TAG_FLAG_LUA (0x10 | TAG_TYPE_QWORD)
103
104 #define TAG_DATABASE (0x1 | TAG_TYPE_LIST)
105 #define TAG_INEXCLUD (0x3 | TAG_TYPE_LIST)
106 #define TAG_EXE (0x7 | TAG_TYPE_LIST)
107 #define TAG_MATCHING_FILE (0x8 | TAG_TYPE_LIST)
108 #define TAG_SHIM_REF (0x9| TAG_TYPE_LIST)
109 #define TAG_LAYER (0xB | TAG_TYPE_LIST)
110 #define TAG_APPHELP (0xD | TAG_TYPE_LIST)
111 #define TAG_LINK (0xE | TAG_TYPE_LIST)
112 #define TAG_STRINGTABLE (0x801 | TAG_TYPE_LIST)
113
114 #define TAG_STRINGTABLE_ITEM (0x801 | TAG_TYPE_STRING)
115
116 #define TAG_NAME (0x1 | TAG_TYPE_STRINGREF)
117 #define TAG_MODULE (0x3 | TAG_TYPE_STRINGREF)
118 #define TAG_VENDOR (0x5 | TAG_TYPE_STRINGREF)
119 #define TAG_APP_NAME (0x6 | TAG_TYPE_STRINGREF)
120 #define TAG_COMMAND_LINE (0x8 | TAG_TYPE_STRINGREF)
121 #define TAG_COMPANY_NAME (0x9 | TAG_TYPE_STRINGREF)
122 #define TAG_PRODUCT_NAME (0x10 | TAG_TYPE_STRINGREF)
123 #define TAG_PRODUCT_VERSION (0x11 | TAG_TYPE_STRINGREF)
124 #define TAG_FILE_DESCRIPTION (0x12 | TAG_TYPE_STRINGREF)
125 #define TAG_FILE_VERSION (0x13 | TAG_TYPE_STRINGREF)
126 #define TAG_ORIGINAL_FILENAME (0x14 | TAG_TYPE_STRINGREF)
127 #define TAG_INTERNAL_NAME (0x15 | TAG_TYPE_STRINGREF)
128 #define TAG_LEGAL_COPYRIGHT (0x16 | TAG_TYPE_STRINGREF)
129 #define TAG_APPHELP_DETAILS (0x18 | TAG_TYPE_STRINGREF)
130 #define TAG_LINK_URL (0x19 | TAG_TYPE_STRINGREF)
131 #define TAG_APPHELP_TITLE (0x1B | TAG_TYPE_STRINGREF)
132
133 #define TAG_COMPILER_VERSION (0x22 | TAG_TYPE_STRINGREF)
134
135 #define TAG_GENERAL (0x2 | TAG_TYPE_NULL)
136
137 #define TAG_EXE_ID (0x4 | TAG_TYPE_BINARY)
138 #define TAG_DATA_BITS (0x5 | TAG_TYPE_BINARY)
139 #define TAG_DATABASE_ID (0x7 | TAG_TYPE_BINARY)
140
141
142 #define SDB_MAX_SDBS 16
143 #define SDB_MAX_EXES 16
144 #define SDB_MAX_LAYERS 8
145
146 #define SDBQUERYRESULT_EXPECTED_SIZE 456
147
148 typedef struct tagSDBQUERYRESULT {
149 TAGREF atrExes[SDB_MAX_EXES];
150 DWORD adwExeFlags[SDB_MAX_EXES];
151 TAGREF atrLayers[SDB_MAX_LAYERS];
152 DWORD dwLayerFlags;
153 TAGREF trApphelp;
154 DWORD dwExeCount;
155 DWORD dwLayerCount;
156 GUID guidID;
157 DWORD dwFlags;
158 DWORD dwCustomSDBMap;
159 GUID rgGuidDB[SDB_MAX_SDBS];
160 } SDBQUERYRESULT, *PSDBQUERYRESULT;
161
162
163 static HMODULE hdll;
164 static LPCWSTR (WINAPI *pSdbTagToString)(TAG);
165 static PDB (WINAPI *pSdbOpenDatabase)(LPCWSTR, PATH_TYPE);
166 static PDB (WINAPI *pSdbCreateDatabase)(LPCWSTR, PATH_TYPE);
167 static BOOL (WINAPI *pSdbGetDatabaseVersion)(LPCWSTR, PDWORD, PDWORD);
168 static void (WINAPI *pSdbCloseDatabase)(PDB);
169 static void (WINAPI *pSdbCloseDatabaseWrite)(PDB);
170 static TAG (WINAPI *pSdbGetTagFromTagID)(PDB, TAGID);
171 static BOOL (WINAPI *pSdbWriteNULLTag)(PDB, TAG);
172 static BOOL (WINAPI *pSdbWriteWORDTag)(PDB, TAG, WORD);
173 static BOOL (WINAPI *pSdbWriteDWORDTag)(PDB, TAG, DWORD);
174 static BOOL (WINAPI *pSdbWriteQWORDTag)(PDB, TAG, QWORD);
175 static BOOL (WINAPI *pSdbWriteBinaryTagFromFile)(PDB, TAG, LPCWSTR);
176 static BOOL (WINAPI *pSdbWriteStringTag)(PDB, TAG, LPCWSTR);
177 static BOOL (WINAPI *pSdbWriteStringRefTag)(PDB, TAG, TAGID);
178 static TAGID (WINAPI *pSdbBeginWriteListTag)(PDB, TAG);
179 static BOOL (WINAPI *pSdbEndWriteListTag)(PDB, TAGID);
180 static TAGID (WINAPI *pSdbFindFirstTag)(PDB, TAGID, TAG);
181 static TAGID (WINAPI *pSdbFindNextTag)(PDB, TAGID, TAGID);
182 static WORD (WINAPI *pSdbReadWORDTag)(PDB, TAGID, WORD);
183 static DWORD (WINAPI *pSdbReadDWORDTag)(PDB, TAGID, DWORD);
184 static QWORD (WINAPI *pSdbReadQWORDTag)(PDB, TAGID, QWORD);
185 static BOOL (WINAPI *pSdbReadBinaryTag)(PDB, TAGID, PBYTE, DWORD);
186 static BOOL (WINAPI *pSdbReadStringTag)(PDB, TAGID, LPWSTR, DWORD);
187 static DWORD (WINAPI *pSdbGetTagDataSize)(PDB, TAGID);
188 static PVOID (WINAPI *pSdbGetBinaryTagData)(PDB, TAGID);
189 static LPWSTR (WINAPI *pSdbGetStringTagPtr)(PDB, TAGID);
190 static TAGID (WINAPI *pSdbGetFirstChild)(PDB, TAGID);
191 static TAGID (WINAPI *pSdbGetNextChild)(PDB, TAGID, TAGID);
192 static BOOL (WINAPI *pSdbGetDatabaseID)(PDB, GUID*);
193 static BOOL (WINAPI *pSdbGUIDToString)(CONST GUID *, PCWSTR, SIZE_T);
194 static HSDB (WINAPI *pSdbInitDatabase)(DWORD, LPCWSTR);
195 static void (WINAPI *pSdbReleaseDatabase)(HSDB);
196 static BOOL(WINAPI *pSdbGetMatchingExe)(HSDB hsdb, LPCWSTR path, LPCWSTR module_name, LPCWSTR env, DWORD flags, PSDBQUERYRESULT result);
197 static BOOL (WINAPI *pSdbTagRefToTagID)(HSDB hSDB, TAGREF trWhich, PDB *ppdb, TAGID *ptiWhich);
198 static LONGLONG(WINAPI* pSdbMakeIndexKeyFromString)(LPCWSTR);
199
200
201 DEFINE_GUID(GUID_DATABASE_TEST,0xe39b0eb0,0x55db,0x450b,0x9b,0xd4,0xd2,0x0c,0x94,0x84,0x26,0x0f);
202
203
204 static void Write(HANDLE file, LPCVOID buffer, DWORD size)
205 {
206 DWORD dwWritten = 0;
207 WriteFile(file, buffer, size, &dwWritten, NULL);
208 }
209
210 static void test_Sdb(void)
211 {
212 static const WCHAR temp[] = {'t','e','m','p',0};
213 static const WCHAR path1[] = {'t','e','m','p','.','s','d','b',0};
214 static const WCHAR path2[] = {'t','e','m','p','2','.','b','i','n',0};
215 static const WCHAR tag_size_string[] = {'S','I','Z','E',0};
216 static const WCHAR tag_flag_lua_string[] = {'F','L','A','G','_','L','U','A',0};
217 static const TAG tags[5] = {
218 TAG_SIZE, TAG_FLAG_LUA, TAG_NAME,
219 TAG_STRINGTABLE, TAG_STRINGTABLE_ITEM
220 };
221 WCHAR buffer[6] = {0};
222 PDB pdb;
223 QWORD qword;
224 DWORD dword;
225 WORD word;
226 BOOL ret;
227 HANDLE file; /* temp file created for testing purpose */
228 TAG tag;
229 TAGID tagid, ptagid, stringref = 6;
230 LPCWSTR string;
231 PBYTE binary;
232
233 pdb = pSdbCreateDatabase(path1, DOS_PATH);
234 ok (pdb != NULL, "failed to create database\n");
235 if(pdb != NULL)
236 {
237 ret = pSdbWriteDWORDTag(pdb, tags[0], 0xDEADBEEF);
238 ok (ret, "failed to write DWORD tag\n");
239 ret = pSdbWriteQWORDTag(pdb, tags[1], 0xDEADBEEFBABE);
240 ok (ret, "failed to write QWORD tag\n");
241 ret = pSdbWriteStringRefTag(pdb, tags[2], stringref);
242 ok (ret, "failed to write stringref tag\n");
243 tagid = pSdbBeginWriteListTag(pdb, tags[3]);
244 ok (tagid != TAGID_NULL, "unexpected NULL tagid\n");
245 ret = pSdbWriteStringTag(pdb, tags[4], temp);
246 ok (ret, "failed to write string tag\n");
247 ret = pSdbWriteNULLTag(pdb, TAG_GENERAL);
248 ok (ret, "failed to write NULL tag\n");
249 ret = pSdbWriteWORDTag(pdb, TAG_MATCH_MODE, 0xACE);
250 ok (ret, "failed to write WORD tag\n");
251 ret = pSdbEndWriteListTag(pdb, tagid);
252 ok (ret, "failed to update list size\n");
253 /* [Err ][SdbCloseDatabase ] Failed to close the file. */
254 pSdbCloseDatabaseWrite(pdb);
255 }
256
257 /* [Err ][SdbGetDatabaseID ] Failed to get root tag */
258 pdb = pSdbOpenDatabase(path1, DOS_PATH);
259 ok(pdb != NULL, "unexpected NULL handle\n");
260
261 if(pdb)
262 {
263 tagid = pSdbGetFirstChild(pdb, TAGID_ROOT);
264 ok(tagid == _TAGID_ROOT, "unexpected tagid %u, expected %u\n", tagid, _TAGID_ROOT);
265
266 tag = pSdbGetTagFromTagID(pdb, tagid);
267 ok(tag == TAG_SIZE, "unexpected tag 0x%x, expected 0x%x\n", tag, TAG_SIZE);
268
269 string = pSdbTagToString(tag);
270 ok(lstrcmpW(string, tag_size_string) == 0, "unexpected string %s, expected %s\n",
271 wine_dbgstr_w(string), wine_dbgstr_w(tag_size_string));
272
273 dword = pSdbReadDWORDTag(pdb, tagid, 0);
274 ok(dword == 0xDEADBEEF, "unexpected value %u, expected 0xDEADBEEF\n", dword);
275
276 tagid = pSdbGetNextChild(pdb, TAGID_ROOT, tagid);
277 ok(tagid == _TAGID_ROOT + sizeof(TAG) + sizeof(DWORD), "unexpected tagid %u, expected %u\n",
278 tagid, _TAGID_ROOT + sizeof(TAG) + sizeof(DWORD));
279
280 tag = pSdbGetTagFromTagID(pdb, tagid);
281 ok (tag == TAG_FLAG_LUA, "unexpected tag 0x%x, expected 0x%x\n", tag, TAG_FLAG_LUA);
282
283 string = pSdbTagToString(tag);
284 ok(lstrcmpW(string, tag_flag_lua_string) == 0, "unexpected string %s, expected %s\n",
285 wine_dbgstr_w(string), wine_dbgstr_w(tag_flag_lua_string));
286
287 qword = pSdbReadQWORDTag(pdb, tagid, 0);
288 ok(qword == 0xDEADBEEFBABE, "unexpected value 0x%I64x, expected 0xDEADBEEFBABE\n", qword);
289
290 tagid = pSdbGetNextChild(pdb, TAGID_ROOT, tagid);
291 string = pSdbGetStringTagPtr(pdb, tagid);
292 ok (string && (lstrcmpW(string, temp) == 0), "unexpected string %s, expected %s\n",
293 wine_dbgstr_w(string), wine_dbgstr_w(temp));
294
295 ptagid = pSdbGetNextChild(pdb, TAGID_ROOT, tagid);
296 tagid = pSdbGetFirstChild(pdb, ptagid);
297
298 string = pSdbGetStringTagPtr(pdb, tagid);
299 ok (string && (lstrcmpW(string, temp) == 0), "unexpected string %s, expected %s\n",
300 wine_dbgstr_w(string), wine_dbgstr_w(temp));
301
302 ok (pSdbReadStringTag(pdb, tagid, buffer, 6), "failed to write string to buffer\n");
303 /* [Err ][SdbpReadTagData ] Buffer too small. Avail: 6, Need: 10. */
304 ok (!pSdbReadStringTag(pdb, tagid, buffer, 3), "string was written to buffer, but failure was expected");
305 ok (pSdbGetTagDataSize(pdb, tagid) == 5 * sizeof(WCHAR), "string has unexpected size\n");
306
307 tagid = pSdbGetNextChild(pdb, ptagid, tagid);
308 tag = pSdbGetTagFromTagID(pdb, tagid);
309 ok (tag == TAG_GENERAL, "unexpected tag 0x%x, expected 0x%x\n", tag, TAG_GENERAL);
310 ok (pSdbGetTagDataSize(pdb, tagid) == 0, "null tag with size > 0\n");
311
312 tagid = pSdbGetNextChild(pdb, ptagid, tagid);
313 word = pSdbReadWORDTag(pdb, tagid, 0);
314 ok (word == 0xACE, "unexpected value 0x%x, expected 0x%x\n", word, 0xACE);
315
316 pSdbCloseDatabase(pdb);
317 }
318 DeleteFileW(path1);
319
320 file = CreateFileW(path2, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
321 ok (file != INVALID_HANDLE_VALUE, "failed to open file\n");
322 Write(file, &qword, 8);
323 CloseHandle(file);
324
325 pdb = pSdbCreateDatabase(path1, DOS_PATH);
326 ok(pdb != NULL, "unexpected NULL handle\n");
327
328 if(pdb)
329 {
330 ret = pSdbWriteBinaryTagFromFile(pdb, TAG_DATA_BITS, path2);
331 ok(ret, "failed to write tag from binary file\n");
332 pSdbCloseDatabaseWrite(pdb); /* [Err ][SdbCloseDatabase ] Failed to close the file. */
333 DeleteFileW(path2);
334
335 pdb = pSdbOpenDatabase(path1, DOS_PATH);
336 ok(pdb != NULL, "unexpected NULL handle\n");
337 binary = pSdbGetBinaryTagData(pdb, _TAGID_ROOT);
338 ok(memcmp(binary, &qword, 8) == 0, "binary data is corrupt\n");
339 ret = pSdbReadBinaryTag(pdb, _TAGID_ROOT, (PBYTE)buffer, 12);
340 ok(ret, "failed to read binary tag\n");
341 ok(memcmp(buffer, &qword, 8) == 0, "binary data is corrupt\n");
342 pSdbCloseDatabase(pdb);
343 }
344 DeleteFileW(path1);
345 }
346
347 /*
348 - Show that a stringtable is automatically generated,
349 - Show that entries in the stringtable are re-used,
350 - validate multiple lists (for the length)
351 */
352 static void test_write_ex(void)
353 {
354 WCHAR path1[] = {'t','e','s','t','.','s','d','b',0};
355 WCHAR test1[] = {'T','E','S','T',0};
356 WCHAR test2[] = {'t','e','s','t',0};
357 PDB pdb;
358 TAGID tagdb, tagstr;
359 TAG tag;
360 DWORD size;
361 BOOL ret;
362 LPWSTR ptr;
363
364 /* Write a small database */
365 pdb = pSdbCreateDatabase(path1, DOS_PATH);
366 ok(pdb != NULL, "Expected a valid database\n");
367 if (!pdb)
368 return;
369 tagdb = pSdbBeginWriteListTag(pdb, TAG_DATABASE);
370 ok(tagdb == 12, "Expected tag to be 12, was %u\n", tagdb);
371 ret = pSdbWriteStringTag(pdb, TAG_NAME, test1);
372 ret = pSdbWriteStringTag(pdb, TAG_NAME, test2);
373 ok(ret, "Expected SdbWriteStringTag to succeed\n");
374 ret = pSdbEndWriteListTag(pdb, tagdb);
375 ok(ret, "Expected SdbEndWriteListTag to succeed\n");
376
377 tagdb = pSdbBeginWriteListTag(pdb, TAG_DATABASE);
378 ok(tagdb == 30, "Expected tag to be 24, was %u\n", tagdb);
379 ret = pSdbWriteStringTag(pdb, TAG_NAME, test1);
380 ret = pSdbWriteStringTag(pdb, TAG_NAME, test2);
381 ok(ret, "Expected SdbWriteStringTag to succeed\n");
382 ret = pSdbEndWriteListTag(pdb, tagdb);
383 ok(ret, "Expected SdbEndWriteListTag to succeed\n");
384
385 pSdbCloseDatabaseWrite(pdb);
386
387 /* Now validate it's contents */
388 pdb = pSdbOpenDatabase(path1, DOS_PATH);
389 ok(pdb != NULL, "Expected a valid database\n");
390 if (!pdb)
391 return;
392
393 tagdb = pSdbFindFirstTag(pdb, TAGID_ROOT, TAG_DATABASE);
394 ok(tagdb == 12, "Expected tag to be 12, was %u\n", tagdb);
395 size = pSdbGetTagDataSize(pdb, tagdb);
396 ok(size == 12, "Expected size to be 12, was %u\n", size);
397
398 tagstr = pSdbFindFirstTag(pdb, tagdb, TAG_NAME);
399 ok(tagstr == 18, "Expected string tag to be 18, was %u\n", tagstr);
400 tag = pSdbGetTagFromTagID(pdb, tagstr);
401 ok(tag == TAG_NAME, "Expected tag to be TAG_NAME, was 0x%x\n", (DWORD)tag);
402 size = pSdbGetTagDataSize(pdb, tagstr);
403 ok(size == 4, "Expected size to be 4, was 0x%x\n", size);
404
405 tagstr = pSdbFindNextTag(pdb, tagdb, tagstr);
406 ok(tagstr == 24, "Expected string tag to be 24, was %u\n", tagstr);
407 tag = pSdbGetTagFromTagID(pdb, tagstr);
408 ok(tag == TAG_NAME, "Expected tag to be TAG_NAME, was 0x%x\n", (DWORD)tag);
409 size = pSdbGetTagDataSize(pdb, tagstr);
410 ok(size == 4, "Expected size to be 4, was 0x%x\n", size);
411
412 tagdb = pSdbFindNextTag(pdb, TAGID_ROOT, tagdb);
413 ok(tagdb == 30, "Expected tag to be 30, was %u\n", tagdb);
414 size = pSdbGetTagDataSize(pdb, tagdb);
415 ok(size == 12, "Expected size to be 12, was %u\n", size);
416
417 tagstr = pSdbFindFirstTag(pdb, tagdb, TAG_NAME);
418 ok(tagstr == 36, "Expected string tag to be 36, was %u\n", tagstr);
419 tag = pSdbGetTagFromTagID(pdb, tagstr);
420 ok(tag == TAG_NAME, "Expected tag to be TAG_NAME, was 0x%x\n", (DWORD)tag);
421 size = pSdbGetTagDataSize(pdb, tagstr);
422 ok(size == 4, "Expected size to be 4, was %u\n", size);
423
424 tagstr = pSdbFindNextTag(pdb, tagdb, tagstr);
425 ok(tagstr == 42, "Expected string tag to be 42, was %u\n", tagstr);
426 tag = pSdbGetTagFromTagID(pdb, tagstr);
427 ok(tag == TAG_NAME, "Expected tag to be TAG_NAME, was 0x%x\n", (DWORD)tag);
428 size = pSdbGetTagDataSize(pdb, tagstr);
429 ok(size == 4, "Expected size to be 4, was 0x%x\n", size);
430
431 tagdb = pSdbFindFirstTag(pdb, TAGID_ROOT, TAG_STRINGTABLE);
432 ok(tagdb == 48, "Expected tag to be 48, was %u\n", tagdb);
433 size = pSdbGetTagDataSize(pdb, tagdb);
434 ok(size == 32, "Expected size to be 32, was %u\n", size);
435
436 tagstr = pSdbGetFirstChild(pdb, tagdb);
437 ok(tagstr == 54, "Expected string tag to be 54, was %u\n", tagstr);
438 tag = pSdbGetTagFromTagID(pdb, tagstr);
439 ok(tag == TAG_STRINGTABLE_ITEM, "Expected tag to be TAG_STRINGTABLE_ITEM, was 0x%x\n", (DWORD)tag);
440 size = pSdbGetTagDataSize(pdb, tagstr);
441 ok(size == 10, "Expected size to be 10, was %u\n", size);
442 ptr = pSdbGetStringTagPtr(pdb, tagstr);
443 ok(ptr != NULL, "Expected a valid pointer\n");
444 if (ptr)
445 ok(!wcscmp(ptr, test1), "Expected ptr to be %s, was %s\n", wine_dbgstr_w(test1), wine_dbgstr_w(ptr));
446
447 tagstr = pSdbGetNextChild(pdb, tagdb, tagstr);
448 ok(tagstr == 70, "Expected string tag to be 70, was %u\n", tagstr);
449 tag = pSdbGetTagFromTagID(pdb, tagstr);
450 ok(tag == TAG_STRINGTABLE_ITEM, "Expected tag to be TAG_STRINGTABLE_ITEM, was 0x%x\n", (DWORD)tag);
451 size = pSdbGetTagDataSize(pdb, tagstr);
452 ok(size == 10, "Expected size to be 10, was %u\n", size);
453 ptr = pSdbGetStringTagPtr(pdb, tagstr);
454 ok(ptr != NULL, "Expected a valid pointer\n");
455 if (ptr)
456 ok(!wcscmp(ptr, test2), "Expected ptr to be %s, was %s\n", wine_dbgstr_w(test2), wine_dbgstr_w(ptr));
457
458 pSdbCloseDatabase(pdb);
459 }
460
461
462 static void write_db_strings(const WCHAR* name, const WCHAR* data[], size_t count)
463 {
464 PDB pdb;
465 size_t n;
466 BOOL ret;
467
468 pdb = pSdbCreateDatabase(name, DOS_PATH);
469 ok(pdb != NULL, "Failed to create db for case %u\n", count);
470 for (n = 0; n < count; ++n)
471 {
472 ret = pSdbWriteStringTag(pdb, TAG_NAME, data[n]);
473 ok(ret, "Failed to write string %u/%u\n", n, count);
474 }
475 pSdbCloseDatabaseWrite(pdb);
476 }
477
478 static void test_stringtable()
479 {
480 static const WCHAR path1[] = {'t','e','s','t','.','s','d','b',0};
481 static const WCHAR test1[] = {'t','e','s','t','1',0};
482 static const WCHAR test2[] = {'T','e','s','t','1',0};
483 static const WCHAR test3[] = {'T','E','s','t','1',0};
484 static const WCHAR test4[] = {'T','E','S','T','1',0};
485 static const WCHAR test5[] = {'T','E','S','T','2',0};
486 static const WCHAR lipsum[] = {'L','o','r','e','m',' ','i','p','s','u','m',' ','d','o','l','o','r',' ','s','i','t',' ','a','m','e','t',',',' ','c','o','n','s','e','c','t','e','t','u','r',' ','a','d','i','p','i','s','c','i','n','g',' ','e','l','i','t','.',' ','N','u','l','l','a',' ','a','n','t','e',' ','r','i','s','u','s',',',' ','m','a','l','e','s','u','a','d','a',' ','s','e','d',' ','i','a','c','u','l','i','s',' ','l','u','c','t','u','s',',',' ','o','r','n','a','r','e',' ','p','u','l','v','i','n','a','r',' ','v','e','l','i','t','.',' ','L','o','r','e','m',' ','i','p','s','u','m',' ','d','o','l','o','r',' ','s','i','t',' ','a','m','e','t',',',' ','c','o','n','s','e','c','t','e','t','u','r',' ','a','d','i','p','i','s','c','i','n','g',' ','e','l','i','t','.',' ','I','n','t','e','g','e','r',' ','q','u','i','s',' ','f','e','l','i','s',' ','u','t',' ','l','e','o',' ','e','l','e','i','f','e','n','d',' ','u','l','t','r','i','c','e','s',' ','f','i','n','i','b','u','s',' ','e','u',' ','d','o','l','o','r','.',' ','I','n',' ','b','i','b','e','n','d','u','m',',',' ','e','r','o','s',' ','e','u',' ','f','a','u','c','i','b','u','s',' ','c','o','n','s','e','q','u','a','t',',',' ','n','i','s','i',' ','m','a','g','n','a',' ','v','e','n','e','n','a','t','i','s',' ','j','u','s','t','o',',',' ','a','t',' ','t','r','i','s','t','i','q','u','e',' ','m','e','t','u','s',' ','d','o','l','o','r',' ','u','t',' ','r','i','s','u','s','.',' ','N','u','n','c',' ','e','u',' ','o','d','i','o',' ','d','i','g','n','i','s','s','i','m',',',' ','o','r','n','a','r','e',' ','a','n','t','e',' ','g','r','a','v','i','d','a',',',' ','l','o','b','o','r','t','i','s',' ','e','r','o','s','.',' ','C','r','a','s',' ','s','e','m',' ','e','x',',',' ','c','o','n','s','e','c','t','e','t','u','r',' ','p','u','l','v','i','n','a','r',' ','t','i','n','c','i','d','u','n','t',' ','e','u',',',' ','c','o','n','g','u','e',' ','a',' ','e','r','o','s','.',' ','C','u','r','a','b','i','t','u','r',' ','e','r','o','s',' ','e','r','a','t',',',' ','p','e','l','l','e','n','t','e','s','q','u','e',' ','e','t',' ','n','i','b','h',' ','q','u','i','s',',',' ','i','n','t','e','r','d','u','m',' ','t','e','m','p','o','r',' ','o','d','i','o','.',' ','E','t','i','a','m',' ','s','a','p','i','e','n',' ','s','a','p','i','e','n',',',' ','a','l','i','q','u','a','m',' ','u','t',' ','a','l','i','q','u','a','m',' ','a','t',',',' ','s','a','g','i','t','t','i','s',' ','e','u',' ','m','a','g','n','a','.',' ','M','a','e','c','e','n','a','s',' ','m','a','g','n','a',' ','m','a','g','n','a',',',' ','s','u','s','c','i','p','i','t',' ','u','t',' ','l','o','r','e','m',' ','u','t',',',' ','v','a','r','i','u','s',' ','p','r','e','t','i','u','m',' ','f','e','l','i','s','.',' ','I','n','t','e','g','e','r',' ','t','i','n','c','i','d','u','n','t',',',' ','m','e','t','u','s',' ','v','e','l',' ','s','o','l','l','i','c','i','t','u','d','i','n',' ','f','i','n','i','b','u','s',',',' ','f','e','l','i','s',' ','e','r','a','t',' ','m','o','l','e','s','t','i','e',' ','u','r','n','a',',',' ','a',' ','c','o','n','d','i','m','e','n','t','u','m',' ','a','u','g','u','e',' ','a','r','c','u',' ','v','i','t','a','e',' ','r','i','s','u','s','.',' ','E','t','i','a','m',' ','i','d',' ','s','a','g','i','t','t','i','s',' ','q','u','a','m','.',' ','M','o','r','b','i',' ','a',' ','u','l','t','r','i','c','i','e','s',' ','n','u','n','c','.',' ','P','h','a','s','e','l','l','u','s',' ','e','r','o','s',' ','r','i','s','u','s',',',' ','c','u','r','s','u','s',' ','u','l','l','a','m','c','o','r','p','e','r',' ','m','a','s','s','a',' ','s','e','d',',',' ','d','i','g','n','i','s','s','i','m',' ','c','o','n','s','e','q','u','a','t',' ','l','i','g','u','l','a','.',' ','A','l','i','q','u','a','m',' ','t','u','r','p','i','s',' ','a','r','c','u',',',' ','a','c','c','u','m','s','a','n',' ','q','u','i','s',' ','s','a','p','i','e','n',' ','v','i','t','a','e',',',' ','l','a','c','i','n','i','a',' ','e','u','i','s','m','o','d',' ','n','i','s','l','.',' ','M','a','u','r','i','s',' ','i','d',' ','f','e','l','i','s',' ','s','e','m','.',0};
487 /* Last char changed from '.' to '!' */
488 static const WCHAR lipsum2[] = {'L','o','r','e','m',' ','i','p','s','u','m',' ','d','o','l','o','r',' ','s','i','t',' ','a','m','e','t',',',' ','c','o','n','s','e','c','t','e','t','u','r',' ','a','d','i','p','i','s','c','i','n','g',' ','e','l','i','t','.',' ','N','u','l','l','a',' ','a','n','t','e',' ','r','i','s','u','s',',',' ','m','a','l','e','s','u','a','d','a',' ','s','e','d',' ','i','a','c','u','l','i','s',' ','l','u','c','t','u','s',',',' ','o','r','n','a','r','e',' ','p','u','l','v','i','n','a','r',' ','v','e','l','i','t','.',' ','L','o','r','e','m',' ','i','p','s','u','m',' ','d','o','l','o','r',' ','s','i','t',' ','a','m','e','t',',',' ','c','o','n','s','e','c','t','e','t','u','r',' ','a','d','i','p','i','s','c','i','n','g',' ','e','l','i','t','.',' ','I','n','t','e','g','e','r',' ','q','u','i','s',' ','f','e','l','i','s',' ','u','t',' ','l','e','o',' ','e','l','e','i','f','e','n','d',' ','u','l','t','r','i','c','e','s',' ','f','i','n','i','b','u','s',' ','e','u',' ','d','o','l','o','r','.',' ','I','n',' ','b','i','b','e','n','d','u','m',',',' ','e','r','o','s',' ','e','u',' ','f','a','u','c','i','b','u','s',' ','c','o','n','s','e','q','u','a','t',',',' ','n','i','s','i',' ','m','a','g','n','a',' ','v','e','n','e','n','a','t','i','s',' ','j','u','s','t','o',',',' ','a','t',' ','t','r','i','s','t','i','q','u','e',' ','m','e','t','u','s',' ','d','o','l','o','r',' ','u','t',' ','r','i','s','u','s','.',' ','N','u','n','c',' ','e','u',' ','o','d','i','o',' ','d','i','g','n','i','s','s','i','m',',',' ','o','r','n','a','r','e',' ','a','n','t','e',' ','g','r','a','v','i','d','a',',',' ','l','o','b','o','r','t','i','s',' ','e','r','o','s','.',' ','C','r','a','s',' ','s','e','m',' ','e','x',',',' ','c','o','n','s','e','c','t','e','t','u','r',' ','p','u','l','v','i','n','a','r',' ','t','i','n','c','i','d','u','n','t',' ','e','u',',',' ','c','o','n','g','u','e',' ','a',' ','e','r','o','s','.',' ','C','u','r','a','b','i','t','u','r',' ','e','r','o','s',' ','e','r','a','t',',',' ','p','e','l','l','e','n','t','e','s','q','u','e',' ','e','t',' ','n','i','b','h',' ','q','u','i','s',',',' ','i','n','t','e','r','d','u','m',' ','t','e','m','p','o','r',' ','o','d','i','o','.',' ','E','t','i','a','m',' ','s','a','p','i','e','n',' ','s','a','p','i','e','n',',',' ','a','l','i','q','u','a','m',' ','u','t',' ','a','l','i','q','u','a','m',' ','a','t',',',' ','s','a','g','i','t','t','i','s',' ','e','u',' ','m','a','g','n','a','.',' ','M','a','e','c','e','n','a','s',' ','m','a','g','n','a',' ','m','a','g','n','a',',',' ','s','u','s','c','i','p','i','t',' ','u','t',' ','l','o','r','e','m',' ','u','t',',',' ','v','a','r','i','u','s',' ','p','r','e','t','i','u','m',' ','f','e','l','i','s','.',' ','I','n','t','e','g','e','r',' ','t','i','n','c','i','d','u','n','t',',',' ','m','e','t','u','s',' ','v','e','l',' ','s','o','l','l','i','c','i','t','u','d','i','n',' ','f','i','n','i','b','u','s',',',' ','f','e','l','i','s',' ','e','r','a','t',' ','m','o','l','e','s','t','i','e',' ','u','r','n','a',',',' ','a',' ','c','o','n','d','i','m','e','n','t','u','m',' ','a','u','g','u','e',' ','a','r','c','u',' ','v','i','t','a','e',' ','r','i','s','u','s','.',' ','E','t','i','a','m',' ','i','d',' ','s','a','g','i','t','t','i','s',' ','q','u','a','m','.',' ','M','o','r','b','i',' ','a',' ','u','l','t','r','i','c','i','e','s',' ','n','u','n','c','.',' ','P','h','a','s','e','l','l','u','s',' ','e','r','o','s',' ','r','i','s','u','s',',',' ','c','u','r','s','u','s',' ','u','l','l','a','m','c','o','r','p','e','r',' ','m','a','s','s','a',' ','s','e','d',',',' ','d','i','g','n','i','s','s','i','m',' ','c','o','n','s','e','q','u','a','t',' ','l','i','g','u','l','a','.',' ','A','l','i','q','u','a','m',' ','t','u','r','p','i','s',' ','a','r','c','u',',',' ','a','c','c','u','m','s','a','n',' ','q','u','i','s',' ','s','a','p','i','e','n',' ','v','i','t','a','e',',',' ','l','a','c','i','n','i','a',' ','e','u','i','s','m','o','d',' ','n','i','s','l','.',' ','M','a','u','r','i','s',' ','i','d',' ','f','e','l','i','s',' ','s','e','m','!',0};
489 static const WCHAR empty[] = {0};
490 static const WCHAR* all[] = { test1, test2, test3, test4, test5, lipsum, lipsum2, empty };
491 static const TAGID expected_str[] = { 0xc, 0x12, 0x18, 0x1e, 0x24, 0x2a, 0x30, 0x36 };
492 static const TAGID expected_tab[] = { 6, 0x18, 0x2a, 0x3c, 0x4e, 0x60, 0x846, 0x102c };
493 size_t n, j;
494
495 for (n = 0; n < (sizeof(all) / sizeof(all[0])); ++n)
496 {
497 PDB pdb;
498 TAGID tagstr, table, expected_table;
499
500 write_db_strings(path1, all, n+1);
501
502 pdb = pSdbOpenDatabase(path1, DOS_PATH);
503 ok(pdb != NULL, "Expected a valid database\n");
504 if (!pdb)
505 {
506 DeleteFileW(path1);
507 continue;
508 }
509 tagstr = pSdbFindFirstTag(pdb, TAGID_ROOT, TAG_NAME);
510 for (j = 0; j <= n; ++j)
511 {
512 ok(tagstr == expected_str[j], "Expected tagstr to be 0x%x, was 0x%x for %u/%u\n", expected_str[j], tagstr, j, n);
513 if (tagstr)
514 {
515 LPWSTR data;
516 DWORD size;
517 TAG tag = pSdbGetTagFromTagID(pdb, tagstr);
518 ok(tag == TAG_NAME, "Expected tag to be TAG_NAME, was 0x%x for %u/%u\n", tag, j, n);
519 size = pSdbGetTagDataSize(pdb, tagstr);
520 ok(size == 4, "Expected datasize to be 4, was %u for %u/%u\n", size, j, n);
521 data = pSdbGetStringTagPtr(pdb, tagstr);
522 ok(data && !wcsicmp(data, all[j]), "Expected data to be %s was %s for %u/%u\n", wine_dbgstr_w(all[j]), wine_dbgstr_w(data), j, n);
523 }
524 tagstr = pSdbFindNextTag(pdb, TAGID_ROOT, tagstr);
525 }
526 ok(tagstr == TAGID_NULL, "Expected to be at the end for %u\n", n);
527
528
529 table = pSdbFindFirstTag(pdb, TAGID_ROOT, TAG_STRINGTABLE);
530 expected_table = 0xc + (n+1)*6;
531 ok(table == expected_table, "Expected to find a stringtable at 0x%x instead of 0x%x for %u\n", expected_table, table, n);
532 if (table)
533 {
534 tagstr = pSdbFindFirstTag(pdb, table, TAG_STRINGTABLE_ITEM);
535 for (j = 0; j <= n; ++j)
536 {
537 ok(tagstr == (expected_tab[j] + expected_table), "Expected tagstr to be 0x%x, was 0x%x for %u/%u\n", (expected_tab[j] + expected_table), tagstr, j, n);
538 if (tagstr)
539 {
540 LPWSTR data;
541 DWORD size, expected_size;
542 TAG tag = pSdbGetTagFromTagID(pdb, tagstr);
543 ok(tag == TAG_STRINGTABLE_ITEM, "Expected tag to be TAG_NAME, was 0x%x for %u/%u\n", tag, j, n);
544 size = pSdbGetTagDataSize(pdb, tagstr);
545 expected_size = (lstrlenW(all[j])+1) * 2;
546 ok(size == expected_size, "Expected datasize to be %u, was %u for %u/%u\n", expected_size, size, j, n);
547 data = pSdbGetStringTagPtr(pdb, tagstr);
548 ok(data && !wcsicmp(data, all[j]), "Expected data to be %s was %s for %u/%u\n", wine_dbgstr_w(all[j]), wine_dbgstr_w(data), j, n);
549 }
550 tagstr = pSdbFindNextTag(pdb, TAGID_ROOT, tagstr);
551 }
552 ok(tagstr == TAGID_NULL, "Expected to be at the end for %u\n", n);
553 }
554
555 pSdbCloseDatabase(pdb);
556 DeleteFileW(path1);
557 }
558 }
559
560 static void match_str_attr_imp(PDB pdb, TAGID parent, TAG find, const char* compare)
561 {
562 TAGID attr = pSdbFindFirstTag(pdb, parent, find);
563 winetest_ok(attr != TAG_NULL, "Could not find: %x\n", find);
564 if (attr != TAG_NULL)
565 {
566 LPWSTR name = pSdbGetStringTagPtr(pdb, attr);
567 winetest_ok(name != NULL, "Could not convert attr to str.\n");
568 if (name)
569 {
570 char name_a[100];
571 WideCharToMultiByte(CP_ACP, 0, name, -1, name_a, sizeof(name_a), NULL, NULL);
572 winetest_ok(strcmp(name_a, compare) == 0, "Expected tagid %x to be %s, was %s\n", attr, compare, name_a);
573 }
574 }
575 }
576
577 static void match_dw_attr_imp(PDB pdb, TAGID parent, TAG find, DWORD compare)
578 {
579 TAGID attr = pSdbFindFirstTag(pdb, parent, find);
580 winetest_ok(attr != TAG_NULL, "Could not find: %x\n", find);
581 if (attr != TAG_NULL)
582 {
583 DWORD val = pSdbReadDWORDTag(pdb, attr, 0x1234567);
584 winetest_ok(val == compare, "Expected tagid %x to be 0x%x, was 0x%x\n", attr, compare, val);
585 }
586 }
587
588 static void match_qw_attr_imp(PDB pdb, TAGID parent, TAG find, QWORD compare)
589 {
590 TAGID attr = pSdbFindFirstTag(pdb, parent, find);
591 winetest_ok(attr != TAG_NULL, "Could not find: %x\n", find);
592 if (attr != TAG_NULL)
593 {
594 QWORD val = pSdbReadQWORDTag(pdb, attr, 0x123456789abcdef);
595 winetest_ok(val == compare, "Expected tagid %x to be 0x%I64x, was 0x%I64x\n", attr, compare, val);
596 }
597 }
598
599 static void match_guid_attr_imp(PDB pdb, TAGID parent, TAG find, const GUID* compare)
600 {
601 TAGID attr = pSdbFindFirstTag(pdb, parent, find);
602 winetest_ok(attr != TAG_NULL, "Could not find: %x\n", find);
603 if (attr != TAG_NULL)
604 {
605 GUID guid = {0};
606 BOOL result = pSdbReadBinaryTag(pdb, attr, (PBYTE)&guid, sizeof(guid));
607 winetest_ok(result, "expected pSdbReadBinaryTag not to fail.\n");
608 winetest_ok(IsEqualGUID(&guid, compare), "expected guids to be equal(%s:%s)\n", wine_dbgstr_guid(&guid), wine_dbgstr_guid(compare));
609 }
610 }
611
612 #define match_str_attr (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : match_str_attr_imp
613 #define match_dw_attr (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : match_dw_attr_imp
614 #define match_qw_attr (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : match_qw_attr_imp
615 #define match_guid_attr (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : match_guid_attr_imp
616
617
618 //The application name cannot contain any of the following characters:
619 // \ / < > : * ? | "
620
621 static void check_db_properties(PDB pdb, TAGID root)
622 {
623 TAGID iter = pSdbFindFirstTag(pdb, root, TAG_DATABASE_ID);
624 ok(iter != TAGID_NULL, "expected a result, got TAGID_NULL\n");
625 if(iter != TAGID_NULL)
626 {
627 GUID guid = {0}, guid2 = {0};
628 BOOL result = pSdbReadBinaryTag(pdb, iter, (PBYTE)&guid, sizeof(guid));
629 ok(result, "expected SdbReadBinaryTag not to fail.\n");
630 if(result)
631 {
632 WCHAR guid_wstr[50];
633 result = pSdbGUIDToString(&guid, guid_wstr, 50);
634 ok(result, "expected SdbGUIDToString not to fail.\n");
635 if(result)
636 {
637 char guid_str[50];
638 WideCharToMultiByte( CP_ACP, 0, guid_wstr, -1, guid_str, sizeof(guid_str), NULL, NULL );
639 ok_str(guid_str, "{e39b0eb0-55db-450b-9bd4-d20c9484260f}");
640 }
641 ok(pSdbGetDatabaseID(pdb, &guid2),"expected SdbGetDatabaseID not to fail.\n");
642 ok(IsEqualGUID(&guid, &guid2), "expected guids to be equal(%s:%s)\n", wine_dbgstr_guid(&guid), wine_dbgstr_guid(&guid2));
643 }
644 }
645 match_qw_attr(pdb, root, TAG_TIME, 0x1d1b91a02c0d63e);
646 match_str_attr(pdb, root, TAG_COMPILER_VERSION, "2.1.0.3");
647 match_str_attr(pdb, root, TAG_NAME, "apphelp_test1");
648 match_dw_attr(pdb, root, TAG_OS_PLATFORM, 1);
649 }
650
651 static void check_db_layer(PDB pdb, TAGID layer)
652 {
653 TAGID shimref, inexclude, is_include;
654 ok(layer != TAGID_NULL, "Expected a valid layer, got NULL\n");
655 if(!layer)
656 return;
657
658 match_str_attr(pdb, layer, TAG_NAME, "TestNewMode");
659 shimref = pSdbFindFirstTag(pdb, layer, TAG_SHIM_REF);
660 ok(shimref != TAGID_NULL, "Expected a valid shim ref, got NULL\n");
661 if(!shimref)
662 return;
663
664 match_str_attr(pdb, shimref, TAG_NAME, "VirtualRegistry");
665 match_str_attr(pdb, shimref, TAG_COMMAND_LINE, "ThemeActive");
666 inexclude = pSdbFindFirstTag(pdb, shimref, TAG_INEXCLUD);
667 ok(inexclude != TAGID_NULL, "Expected a valid in/exclude ref, got NULL\n");
668 if(!inexclude)
669 return;
670
671 is_include = pSdbFindFirstTag(pdb, inexclude, TAG_INCLUDE);
672 ok(is_include == TAGID_NULL, "Expected a NULL include ref, but got one anyway.\n");
673 match_str_attr(pdb, inexclude, TAG_MODULE, "exclude.dll");
674
675 inexclude = pSdbFindNextTag(pdb, shimref, inexclude);
676 ok(inexclude != TAGID_NULL, "Expected a valid in/exclude ref, got NULL\n");
677 if(!inexclude)
678 return;
679
680 is_include = pSdbFindFirstTag(pdb, inexclude, TAG_INCLUDE);
681 ok(is_include != TAGID_NULL, "Expected a valid include ref, got NULL\n");
682 match_str_attr(pdb, inexclude, TAG_MODULE, "include.dll");
683 }
684
685 static void check_matching_file(PDB pdb, TAGID exe, TAGID matching_file, int num)
686 {
687 ok(matching_file != TAGID_NULL, "Expected to find atleast 1 matching file.\n");
688 if(matching_file == TAGID_NULL)
689 return;
690
691 ok(num < 4, "Too many matches, expected only 4!\n");
692 if (num >= 4)
693 return;
694
695
696 match_str_attr(pdb, matching_file, TAG_NAME, "*");
697 match_str_attr(pdb, matching_file, TAG_COMPANY_NAME, "CompanyName");
698 match_str_attr(pdb, matching_file, TAG_PRODUCT_NAME, "ProductName");
699 match_str_attr(pdb, matching_file, TAG_PRODUCT_VERSION, "1.0.0.1");
700 match_str_attr(pdb, matching_file, TAG_FILE_VERSION, "1.0.0.0");
701
702 if( num == 0 || num == 3)
703 {
704 match_qw_attr(pdb, matching_file, TAG_UPTO_BIN_PRODUCT_VERSION, 0x1000000000001);
705 match_qw_attr(pdb, matching_file, TAG_UPTO_BIN_FILE_VERSION, 0x1000000000000);
706 }
707 if(num == 1 || num == 3)
708 {
709 match_dw_attr(pdb, matching_file, TAG_PE_CHECKSUM, 0xbaad);
710 }
711 if(num != 0)
712 {
713 match_qw_attr(pdb, matching_file, TAG_BIN_PRODUCT_VERSION, 0x1000000000001);
714 match_qw_attr(pdb, matching_file, TAG_BIN_FILE_VERSION, 0x1000000000000);
715 }
716 if(num == 3)
717 {
718 match_dw_attr(pdb, matching_file, TAG_SIZE, 0x800);
719 match_dw_attr(pdb, matching_file, TAG_CHECKSUM, 0x178bd629);
720 match_str_attr(pdb, matching_file, TAG_FILE_DESCRIPTION, "FileDescription");
721 match_dw_attr(pdb, matching_file, TAG_MODULE_TYPE, 3);
722 match_dw_attr(pdb, matching_file, TAG_VERFILEOS, 4);
723 match_dw_attr(pdb, matching_file, TAG_VERFILETYPE, 1);
724 match_dw_attr(pdb, matching_file, TAG_LINKER_VERSION, 0x40002);
725 match_str_attr(pdb, matching_file, TAG_ORIGINAL_FILENAME, "OriginalFilename");
726 match_str_attr(pdb, matching_file, TAG_INTERNAL_NAME, "InternalName");
727 match_str_attr(pdb, matching_file, TAG_LEGAL_COPYRIGHT, "LegalCopyright");
728 match_dw_attr(pdb, matching_file, TAG_LINK_DATE, 0x12345);
729 match_dw_attr(pdb, matching_file, TAG_UPTO_LINK_DATE, 0x12345);
730 }
731 if(num > 3)
732 {
733 ok(0, "unknown case: %d\n", num);
734 }
735 matching_file = pSdbFindNextTag(pdb, exe, matching_file);
736 if(num == 2)
737 {
738 ok(matching_file != TAGID_NULL, "Did expect a secondary match on %d\n", num);
739 match_str_attr(pdb, matching_file, TAG_NAME, "test_checkfile.txt");
740 match_dw_attr(pdb, matching_file, TAG_SIZE, 0x4);
741 match_dw_attr(pdb, matching_file, TAG_CHECKSUM, 0xb0b0b0b0);
742 }
743 else
744 {
745 ok(matching_file == TAGID_NULL, "Did not expect a secondary match on %d\n", num);
746 }
747 }
748
749 // "C:\WINDOWS\system32\pcaui.exe" /g {bf39e0e6-c61c-4a22-8802-3ea8ad00b655} /x {4e50c93f-b863-4dfa-bae2-d80ef4ce5c89} /a "apphelp_name_allow" /v "apphelp_vendor_allow" /s "Allow it!" /b 1 /f 0 /k 0 /e "C:\Users\Mark\AppData\Local\Temp\apphelp_test\test_allow.exe" /u "http://reactos.org/allow" /c
750 // "C:\WINDOWS\system32\pcaui.exe" /g {fa150915-1244-4169-a4ba-fc098c442840} /x {156720e1-ef98-4d04-965a-d85de05e6d9f} /a "apphelp_name_disallow" /v "apphelp_vendor_disallow" /s "Not allowed!" /b 2 /f 0 /k 0 /e "C:\Users\Mark\AppData\Local\Temp\apphelp_test\test_disallow.exe" /u "http://reactos.org/disallow" /c
751
752 static void check_matching_apphelp(PDB pdb, TAGID apphelp, int num)
753 {
754 if(num == 0)
755 {
756 /*
757 [Window Title]
758 Program Compatibility Assistant
759
760 [Main Instruction]
761 This program has known compatibility issues
762
763 [Expanded Information]
764 Allow it!
765
766 [^] Hide details [ ] Don't show this message again [Check for solutions online] [Run program] [Cancel]
767 */
768 match_dw_attr(pdb, apphelp, TAG_FLAGS, 1);
769 match_dw_attr(pdb, apphelp, TAG_PROBLEMSEVERITY, 1);
770 match_dw_attr(pdb, apphelp, TAG_HTMLHELPID, 1);
771 match_dw_attr(pdb, apphelp, TAG_APP_NAME_RC_ID, 0x6f0072);
772 match_dw_attr(pdb, apphelp, TAG_VENDOR_NAME_RC_ID, 0x720067);
773 match_dw_attr(pdb, apphelp, TAG_SUMMARY_MSG_RC_ID, 0);
774 }
775 else
776 {
777 /*
778 [Window Title]
779 Program Compatibility Assistant
780
781 [Main Instruction]
782 This program is blocked due to compatibility issues
783
784 [Expanded Information]
785 Not allowed!
786
787 [^] Hide details [Check for solutions online] [Cancel]
788 */
789 match_dw_attr(pdb, apphelp, TAG_FLAGS, 1);
790 match_dw_attr(pdb, apphelp, TAG_PROBLEMSEVERITY, 2);
791 match_dw_attr(pdb, apphelp, TAG_HTMLHELPID, 2);
792 match_dw_attr(pdb, apphelp, TAG_APP_NAME_RC_ID, 0x320020);
793 match_dw_attr(pdb, apphelp, TAG_VENDOR_NAME_RC_ID, 0x38002e);
794 match_dw_attr(pdb, apphelp, TAG_SUMMARY_MSG_RC_ID, 0);
795 }
796 apphelp = pSdbFindNextTag(pdb, apphelp, apphelp);
797 ok(apphelp == TAGID_NULL, "Did not expect a secondary match on %d\n", num);
798 }
799
800 static void check_matching_layer(PDB pdb, TAGID layer, int num)
801 {
802 if(num == 2)
803 {
804 match_dw_attr(pdb, layer, TAG_LAYER_TAGID, 0x18e);
805 match_str_attr(pdb, layer, TAG_NAME, "TestNewMode");
806 }
807 else
808 {
809 TAGID layer_tagid = pSdbFindFirstTag(pdb, layer, TAG_LAYER_TAGID);
810 ok(layer_tagid == TAGID_NULL, "expected not to find a layer tagid, got %x\n", layer_tagid);
811 match_str_attr(pdb, layer, TAG_NAME, "WinSrv03");
812 }
813 }
814
815 static struct
816 {
817 const char* name;
818 const char* app_name;
819 const char* vendor;
820 GUID exe_id;
821 const char* extra_file;
822 DWORD dwLayerCount;
823 TAGREF atrExes_0;
824 DWORD adwExeFlags_0;
825 TAGREF atrLayers_0;
826 TAGREF trApphelp;
827 const char* env_var;
828 } test_exedata[5] = {
829 {
830 "test_allow.exe",
831 "apphelp_name_allow",
832 "apphelp_vendor_allow",
833 {0x4e50c93f,0xb863,0x4dfa,{0xba,0xe2,0xd8,0x0e,0xf4,0xce,0x5c,0x89}},
834 NULL,
835 0,
836 0x1c6,
837 0x1000,
838 0,
839 0x1c6,
840 NULL,
841 },
842 {
843 "test_disallow.exe",
844 "apphelp_name_disallow",
845 "apphelp_vendor_disallow",
846 {0x156720e1,0xef98,0x4d04,{0x96,0x5a,0xd8,0x5d,0xe0,0x5e,0x6d,0x9f}},
847 NULL,
848 0,
849 0x256,
850 0x3000,
851 0,
852 0x256,
853 NULL,
854 },
855 {
856 "test_new.exe",
857 "fixnew_name",
858 "fixnew_vendor",
859 {0xce70ef69,0xa21d,0x408b,{0x84,0x5b,0xf9,0x9e,0xac,0x06,0x09,0xe7}},
860 "test_checkfile.txt",
861 1,
862 0x2ec,
863 0,
864 0x18e,
865 0,
866 NULL,
867 },
868 {
869 "test_w2k3.exe",
870 "fix_name",
871 "fix_vendor",
872 {0xb4ead144,0xf640,0x4e4b,{0x94,0xc4,0x0c,0x7f,0xa8,0x66,0x23,0xb0}},
873 NULL,
874 0,
875 0x37c,
876 0,
877 0,
878 0,
879 NULL,
880 },
881 {
882 "test_unknown_file.exe",
883 "apphelp_name_allow",
884 "apphelp_vendor_allow",
885 {0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
886 NULL,
887 1,
888 0,
889 0,
890 0x18e,
891 0,
892 "TestNewMode",
893 },
894 };
895
896 static void check_db_exes(PDB pdb, TAGID root)
897 {
898 int num = 0;
899 TAGID exe = pSdbFindFirstTag(pdb, root, TAG_EXE);
900 while (exe != TAGID_NULL)
901 {
902 TAGID apphelp, layer;
903 ok(num < 4, "Too many matches, expected only 4!\n");
904 if(num >= 4)
905 break;
906 match_str_attr(pdb, exe, TAG_NAME, test_exedata[num].name);
907 match_str_attr(pdb, exe, TAG_APP_NAME, test_exedata[num].app_name);
908 match_str_attr(pdb, exe, TAG_VENDOR, test_exedata[num].vendor);
909 match_guid_attr(pdb, exe, TAG_EXE_ID, &test_exedata[num].exe_id);
910 check_matching_file(pdb, exe, pSdbFindFirstTag(pdb, exe, TAG_MATCHING_FILE), num);
911 apphelp = pSdbFindFirstTag(pdb, exe, TAG_APPHELP);
912 if(num == 0 || num == 1)
913 {
914 ok(apphelp != TAGID_NULL, "Expected to find a valid apphelp match on %d.\n", num);
915 if(apphelp)
916 check_matching_apphelp(pdb, apphelp, num);
917 }
918 else
919 {
920 ok(apphelp == TAGID_NULL, "Did not expect an apphelp match on %d\n", num);
921 }
922 layer = pSdbFindFirstTag(pdb, exe, TAG_LAYER);
923 if(num == 2 || num == 3)
924 {
925 ok(layer != TAGID_NULL, "Expected to find a valid layer match on %d.\n", num);
926 if(layer)
927 check_matching_layer(pdb, layer, num);
928 }
929 else
930 {
931 ok(layer == TAGID_NULL, "Did not expect a layer match on %d\n", num);
932 }
933 ++num;
934 exe = pSdbFindNextTag(pdb, root, exe);
935 }
936 ok(num == 4, "Expected to find 4 exe tags, found: %d\n", num);
937 }
938
939 static struct
940 {
941 DWORD htmlhelpid;
942 const char* link;
943 const char* apphelp_title;
944 const char* apphelp_details;
945 } test_layerdata[2] = {
946 {
947 2,
948 "http://reactos.org/disallow",
949 "apphelp_name_disallow",
950 "Not allowed!",
951 },
952 {
953 1,
954 "http://reactos.org/allow",
955 "apphelp_name_allow",
956 "Allow it!",
957 },
958 };
959
960 static void check_db_apphelp(PDB pdb, TAGID root)
961 {
962 int num = 0;
963 TAGID apphelp = pSdbFindFirstTag(pdb, root, TAG_APPHELP);
964 while (apphelp != TAGID_NULL)
965 {
966 TAGID link;
967 ok(num < 2, "Too many matches, expected only 4!\n");
968 if(num >= 2)
969 break;
970 match_dw_attr(pdb, apphelp, TAG_HTMLHELPID, test_layerdata[num].htmlhelpid);
971 link = pSdbFindFirstTag(pdb, apphelp, TAG_LINK);
972 ok(link != TAGID_NULL, "expected to find a link tag\n");
973 if (link != TAGID_NULL)
974 {
975 match_str_attr(pdb, link, TAG_LINK_URL, test_layerdata[num].link);
976 }
977 match_str_attr(pdb, apphelp, TAG_APPHELP_TITLE, test_layerdata[num].apphelp_title);
978 match_str_attr(pdb, apphelp, TAG_APPHELP_DETAILS, test_layerdata[num].apphelp_details);
979 apphelp = pSdbFindNextTag(pdb, root, apphelp);
980 num++;
981 }
982 ok(num == 2, "Expected to find 2 layer tags, found: %d\n", num);
983 }
984
985 static void test_CheckDatabaseManually(void)
986 {
987 static const WCHAR path[] = {'t','e','s','t','_','d','b','.','s','d','b',0};
988 TAGID root;
989 PDB pdb;
990 BOOL ret;
991 DWORD ver_hi, ver_lo;
992
993 test_create_db("test_db.sdb");
994
995 /* both ver_hi and ver_lo cannot be null, it'll crash. */
996 ver_hi = ver_lo = 0x12345678;
997 ret = pSdbGetDatabaseVersion(path, &ver_hi, &ver_lo);
998 ok(ret,"Expected SdbGetDatabaseVersion to succeed\n");
999 ok(ver_hi == 2,"Expected ver_hi to be 2, was: %d\n", ver_hi);
1000 ok(ver_lo == 1,"Expected ver_lo to be 1, was: %d\n", ver_lo);
1001
1002 ver_hi = ver_lo = 0x12345678;
1003 ret = pSdbGetDatabaseVersion(NULL, &ver_hi, &ver_lo);
1004 ok(ret,"Expected SdbGetDatabaseVersion to succeed\n");
1005 ok(ver_hi == 0x12345678,"Expected ver_hi to be 0x12345678, was: 0x%x\n", ver_hi);
1006 ok(ver_lo == 0x12345678,"Expected ver_lo to be 0x12345678, was: 0x%x\n", ver_lo);
1007
1008 ver_hi = ver_lo = 0x12345678;
1009 ret = pSdbGetDatabaseVersion(path + 1, &ver_hi, &ver_lo);
1010 ok(ret,"Expected SdbGetDatabaseVersion to succeed\n");
1011 ok(ver_hi == 0x12345678,"Expected ver_hi to be 0x12345678, was: 0x%x\n", ver_hi);
1012 ok(ver_lo == 0x12345678,"Expected ver_lo to be 0x12345678, was: 0x%x\n", ver_lo);
1013
1014 pdb = pSdbOpenDatabase(path, DOS_PATH);
1015 ok(pdb != NULL, "unexpected NULL handle\n");
1016
1017 root = pSdbFindFirstTag(pdb, TAGID_ROOT, TAG_DATABASE);
1018 ok(root != TAGID_NULL, "expected to find a root tag\n");
1019 if (root != TAGID_NULL)
1020 {
1021 check_db_properties(pdb, root);
1022 check_db_layer(pdb, pSdbFindFirstTag(pdb, root, TAG_LAYER));
1023 check_db_exes(pdb, root);
1024 check_db_apphelp(pdb, root);
1025 }
1026
1027 pSdbCloseDatabase(pdb);
1028 DeleteFileA("test_db.sdb");
1029 }
1030
1031 static void test_is_testdb(PDB pdb)
1032 {
1033 if(pdb)
1034 {
1035 GUID guid;
1036 memset(&guid, 0, sizeof(guid));
1037 ok(pSdbGetDatabaseID(pdb, &guid),"expected SdbGetDatabaseID not to fail.\n");
1038 ok(IsEqualGUID(&guid, &GUID_DATABASE_TEST), "Expected SdbGetDatabaseID to return the test db GUID, was: %s\n", wine_dbgstr_guid(&guid));
1039 }
1040 else
1041 {
1042 skip("Not checking DB GUID, received a null pdb\n");
1043 }
1044 }
1045
1046
1047 static void test_mode_generic(const char* workdir, HSDB hsdb, int cur)
1048 {
1049 char exename[MAX_PATH], testfile[MAX_PATH];
1050 WCHAR exenameW[MAX_PATH];
1051 BOOL ret;
1052 SDBQUERYRESULT query;
1053 PDB pdb;
1054 TAGID tagid;
1055 TAGREF trApphelp;
1056 DWORD expect_flags = 0, adwExeFlags_0, exe_count;
1057 int n;
1058
1059 memset(&query, 0xab, sizeof(query));
1060
1061 sprintf(exename, "%s\\%s", workdir, test_exedata[cur].name);
1062 if (test_exedata[cur].extra_file)
1063 sprintf(testfile, "%s\\%s", workdir, test_exedata[cur].extra_file);
1064 test_create_exe(exename, 0);
1065 MultiByteToWideChar(CP_ACP, 0, exename, -1, exenameW, MAX_PATH);
1066
1067 if (test_exedata[cur].extra_file)
1068 {
1069 /* First we try without the file at all. */
1070 DeleteFileA(testfile);
1071 ret = pSdbGetMatchingExe(hsdb, exenameW, NULL, NULL, 0, &query);
1072 ok(ret == 0, "SdbGetMatchingExe should have failed for %d.\n", cur);
1073 /* Now re-try with the correct file */
1074 test_create_file(testfile, "aaaa", 4);
1075 }
1076
1077 #if 0
1078 // Results seem to be cached based on filename, until we can invalidate this, do not test the same filename twice!
1079 DeleteFileA(exename);
1080 // skip exports
1081 test_create_exe(exename, 1);
1082 ret = pSdbGetMatchingExe(hsdb, exenameW, NULL, NULL, 0, &query);
1083 ok(ret == 0, "SdbGetMatchingExe should have failed for %d.\n", cur);
1084
1085 DeleteFileA(exename);
1086 test_create_exe(exename, 0);
1087 #endif
1088
1089 if (test_exedata[cur].env_var)
1090 {
1091 SetEnvironmentVariableA("__COMPAT_LAYER", test_exedata[cur].env_var);
1092 }
1093
1094 ret = pSdbGetMatchingExe(hsdb, exenameW, NULL, NULL, 0, &query);
1095 ok(ret, "SdbGetMatchingExe should not fail for %d.\n", cur);
1096
1097 exe_count = (test_exedata[cur].env_var == NULL) ? 1 : 0;
1098
1099 ok(query.dwExeCount == exe_count, "Expected dwExeCount to be %d, was %d for %d\n", exe_count, query.dwExeCount, cur);
1100 ok(query.dwLayerCount == test_exedata[cur].dwLayerCount, "Expected dwLayerCount to be %d, was %d for %d\n", test_exedata[cur].dwLayerCount, query.dwLayerCount, cur);
1101 ok(query.dwCustomSDBMap == 1, "Expected dwCustomSDBMap to be 1, was %d for %d\n", query.dwCustomSDBMap, cur);
1102 ok(query.dwLayerFlags == 0, "Expected dwLayerFlags to be 0, was 0x%x for %d\n", query.dwLayerFlags, cur);
1103 trApphelp = (g_WinVersion < WINVER_WIN10) ? 0 : test_exedata[cur].trApphelp;
1104 ok(query.trApphelp == trApphelp, "Expected trApphelp to be 0x%x, was 0x%x for %d\n", trApphelp, query.trApphelp, cur);
1105
1106 if (g_WinVersion < WINVER_WIN7)
1107 expect_flags = 0;
1108 else if (g_WinVersion < WINVER_WIN8)
1109 expect_flags = 1;
1110 else if (g_WinVersion < WINVER_WIN10)
1111 expect_flags = 0x101;
1112 else
1113 expect_flags = 0x121;
1114
1115 if (test_exedata[cur].env_var)
1116 expect_flags &= ~0x100;
1117
1118 ok(query.dwFlags == expect_flags, "Expected dwFlags to be 0x%x, was 0x%x for %d\n", expect_flags, query.dwFlags, cur);
1119
1120 ok(query.atrExes[0] == test_exedata[cur].atrExes_0, "Expected atrExes[0] to be 0x%x, was: 0x%x for %d\n", test_exedata[cur].atrExes_0, query.atrExes[0], cur);
1121 for (n = 1; n < SDB_MAX_EXES; ++n)
1122 ok(query.atrExes[n] == 0, "Expected atrExes[%d] to be 0, was: %x for %d\n", n, query.atrExes[n], cur);
1123
1124 adwExeFlags_0 = (g_WinVersion < WINVER_WIN10) ? 0 : test_exedata[cur].adwExeFlags_0;
1125 ok(query.adwExeFlags[0] == adwExeFlags_0, "Expected adwExeFlags[0] to be 0x%x, was: 0x%x for %d\n", adwExeFlags_0, query.adwExeFlags[0], cur);
1126 for (n = 1; n < SDB_MAX_EXES; ++n)
1127 ok(query.adwExeFlags[n] == 0, "Expected adwExeFlags[%d] to be 0, was: %x for %d\n", n, query.adwExeFlags[0], cur);
1128
1129 ok(query.atrLayers[0] == test_exedata[cur].atrLayers_0, "Expected atrLayers[0] to be 0x%x, was: %x for %d\n", test_exedata[cur].atrLayers_0, query.atrLayers[0], cur);
1130 for (n = 1; n < SDB_MAX_LAYERS; ++n)
1131 ok(query.atrLayers[n] == 0, "Expected atrLayers[%d] to be 0, was: %x for %d\n", n, query.atrLayers[0], cur);
1132
1133 ok(IsEqualGUID(&query.rgGuidDB[0], &GUID_DATABASE_TEST), "Expected rgGuidDB[0] to be the test db GUID, was: %s for %d\n", wine_dbgstr_guid(&query.rgGuidDB[0]), cur);
1134 for (n = 1; n < SDB_MAX_SDBS; ++n)
1135 ok(IsEqualGUID(&query.rgGuidDB[n], &GUID_NULL), "Expected rgGuidDB[%d] to be GUID_NULL, was: %s for %d\n", n, wine_dbgstr_guid(&query.rgGuidDB[n]), cur);
1136
1137 if (query.atrExes[0])
1138 {
1139 pdb = (PDB)0x12345678;
1140 tagid = 0x76543210;
1141 ret = pSdbTagRefToTagID(hsdb, query.atrExes[0], &pdb, &tagid);
1142 ok(ret, "SdbTagRefToTagID failed for %d.\n", cur);
1143 ok(pdb != NULL && pdb != (PDB)0x12345678, "SdbTagRefToTagID failed to return a pdb for %d.\n", cur);
1144 ok(tagid != 0 && tagid != 0x76543210, "SdbTagRefToTagID failed to return a tagid for %d.\n", cur);
1145
1146 if (pdb && pdb != (PDB)0x12345678)
1147 {
1148 TAG tag = pSdbGetTagFromTagID(pdb, tagid);
1149 test_is_testdb(pdb);
1150 ok(tag == TAG_EXE, "Expected tag to be TAG_EXE, was 0x%x for %d.\n", tag, cur);
1151 match_str_attr(pdb, tagid, TAG_NAME, test_exedata[cur].name);
1152 }
1153 else
1154 {
1155 skip("Skipping a bunch of tests because of an invalid pointer\n");
1156 }
1157 }
1158
1159 if (test_exedata[cur].atrLayers_0)
1160 {
1161 pdb = (PDB)0x12345678;
1162 tagid = 0x76543210;
1163 ret = pSdbTagRefToTagID(hsdb, query.atrLayers[0], &pdb, &tagid);
1164 ok(ret, "SdbTagRefToTagID failed for %d.\n", cur);
1165 ok(pdb != NULL && pdb != (PDB)0x12345678, "SdbTagRefToTagID failed to return a pdb for %d.\n", cur);
1166 ok(tagid != 0 && tagid != 0x76543210, "SdbTagRefToTagID failed to return a tagid for %d.\n", cur);
1167
1168 if (pdb && pdb != (PDB)0x12345678)
1169 {
1170 TAG tag = pSdbGetTagFromTagID(pdb, tagid);
1171 test_is_testdb(pdb);
1172 ok(tag == TAG_LAYER, "Expected tag to be TAG_LAYER, was 0x%x for %d.\n", tag, cur);
1173 match_str_attr(pdb, tagid, TAG_NAME, "TestNewMode");
1174 }
1175 else
1176 {
1177 skip("Skipping a bunch of tests because of an invalid pointer\n");
1178 }
1179 }
1180
1181 pdb = (PDB)0x12345678;
1182 tagid = 0x76543210;
1183 ret = pSdbTagRefToTagID(hsdb, 0, &pdb, &tagid);
1184 ok(pdb != NULL && pdb != (PDB)0x12345678, "Expected pdb to be set to a valid pdb, was: %p\n", pdb);
1185 ok(tagid == 0, "Expected tagid to be set to 0, was: 0x%x\n", tagid);
1186
1187 if (test_exedata[cur].extra_file)
1188 DeleteFileA(testfile);
1189 DeleteFileA(exename);
1190
1191 if (test_exedata[cur].env_var)
1192 {
1193 SetEnvironmentVariableA("__COMPAT_LAYER", NULL);
1194 }
1195 }
1196
1197
1198 static void test_MatchApplications(void)
1199 {
1200 char workdir[MAX_PATH], dbpath[MAX_PATH];
1201 WCHAR dbpathW[MAX_PATH];
1202 BOOL ret;
1203 HSDB hsdb;
1204
1205 ret = GetTempPathA(MAX_PATH, workdir);
1206 ok(ret, "GetTempPathA error: %d\n", GetLastError());
1207 lstrcatA(workdir, "apphelp_test");
1208
1209 ret = CreateDirectoryA(workdir, NULL);
1210 ok(ret, "CreateDirectoryA error: %d\n", GetLastError());
1211
1212 /* SdbInitDatabase needs an nt-path */
1213 sprintf(dbpath, "\\??\\%s\\test.sdb", workdir);
1214
1215 test_create_db(dbpath + 4);
1216
1217 MultiByteToWideChar(CP_ACP, 0, dbpath, -1, dbpathW, MAX_PATH);
1218 hsdb = pSdbInitDatabase(HID_DATABASE_FULLPATH, dbpathW);
1219
1220 ok(hsdb != NULL, "Expected a valid database handle\n");
1221
1222 if (!hsdb)
1223 {
1224 skip("SdbInitDatabase not implemented?\n");
1225 }
1226 else
1227 {
1228 /* now that our enviroment is setup, let's go ahead and run the actual tests.. */
1229 int n;
1230 for (n = 0; n < _countof(test_exedata); ++n)
1231 test_mode_generic(workdir, hsdb, n);
1232 pSdbReleaseDatabase(hsdb);
1233 }
1234
1235 DeleteFileA(dbpath + 4);
1236
1237 ret = RemoveDirectoryA(workdir);
1238 ok(ret, "RemoveDirectoryA error: %d\n", GetLastError());
1239 }
1240
1241 static void test_TagRef(void)
1242 {
1243 char tmpdir[MAX_PATH], dbpath[MAX_PATH];
1244 WCHAR dbpathW[MAX_PATH];
1245 BOOL ret;
1246 HSDB hsdb;
1247 PDB pdb;
1248 TAGID db;
1249 DWORD size;
1250
1251 ret = GetTempPathA(MAX_PATH, tmpdir);
1252 ok(ret, "GetTempPathA error: %d\n", GetLastError());
1253
1254 /* SdbInitDatabase needs an nt-path */
1255 sprintf(dbpath, "\\??\\%stest.sdb", tmpdir);
1256
1257 test_create_db(dbpath + 4);
1258
1259 MultiByteToWideChar(CP_ACP, 0, dbpath, -1, dbpathW, MAX_PATH);
1260 hsdb = pSdbInitDatabase(HID_DATABASE_FULLPATH, dbpathW);
1261
1262 /* HSDB is the only arg that can't be null */
1263 ret = pSdbTagRefToTagID(hsdb, 0, NULL, NULL);
1264 ok(ret == TRUE, "Expected ret to be TRUE, was: %d\n", ret);
1265
1266 size = test_get_db_size();
1267
1268 pdb = (PDB)&db;
1269 db = 12345;
1270 ret = pSdbTagRefToTagID(hsdb, size - 1, &pdb, &db);
1271 ok(ret == TRUE, "Expected ret to be TRUE, was: %d\n", ret);
1272 ok(pdb != NULL, "Expected a result, got: %p\n", pdb);
1273 ok(db == (size - 1), "Expected %u, got: %u\n", size - 1, db);
1274
1275 pdb = (PDB)&db;
1276 db = 12345;
1277 ret = pSdbTagRefToTagID(hsdb, size, &pdb, &db);
1278 ok(ret == TRUE, "Expected ret to be TRUE, was: %d\n", ret);
1279 ok(pdb != NULL, "Expected a result, got: %p\n", pdb);
1280 ok(db == (size), "Expected %u, got: %u\n", size, db);
1281
1282 pdb = (PDB)&db;
1283 db = 12345;
1284 ret = pSdbTagRefToTagID(hsdb, size + 1, &pdb, &db);
1285 ok(ret == TRUE, "Expected ret to be TRUE, was: %d\n", ret);
1286 ok(pdb != NULL, "Expected a result, got: %p\n", pdb);
1287 ok(db == (size + 1), "Expected %u, got: %u\n", size + 1, db);
1288
1289 pdb = (PDB)&db;
1290 db = 12345;
1291 ret = pSdbTagRefToTagID(hsdb, 0x0fffffff, &pdb, &db);
1292 ok(ret == TRUE, "Expected ret to be TRUE, was: %d\n", ret);
1293 ok(pdb != NULL, "Expected a result, got: %p\n", pdb);
1294 ok(db == 0x0fffffff, "Expected %u, got: %u\n", 0x0fffffff, db);
1295
1296 pdb = (PDB)&db;
1297 db = 12345;
1298 ret = pSdbTagRefToTagID(hsdb, 0x10000000, &pdb, &db);
1299 ok(ret == FALSE, "Expected ret to be FALSE, was: %d\n", ret);
1300 ok(pdb == NULL, "Expected no result, got: %p\n", pdb);
1301 ok(db == 0, "Expected no result, got: 0x%x\n", db);
1302
1303 pdb = NULL;
1304 db = TAGID_NULL;
1305 ret = pSdbTagRefToTagID(hsdb, TAGID_ROOT, &pdb, NULL);
1306 ok(ret != FALSE, "Expected ret to be TRUE, was: %d\n", ret);
1307 ok(pdb != NULL, "Expected pdb to be valid\n");
1308
1309 if(pdb == NULL)
1310 {
1311 skip("Cannot run tests without pdb\n");
1312 }
1313 else
1314 {
1315 db = pSdbFindFirstTag(pdb, TAGID_ROOT, TAG_DATABASE);
1316 if(db != TAGID_NULL)
1317 {
1318 TAGID child;
1319 child = pSdbGetFirstChild(pdb, db);
1320 while(child != TAGID_NULL)
1321 {
1322 PDB pdb_res;
1323 TAGID tagid_res;
1324 ret = pSdbTagRefToTagID(hsdb, child, &pdb_res, &tagid_res);
1325 ok(ret, "Expected SdbTagRefToTagID to succeed\n");
1326 child = pSdbGetNextChild(pdb, db, child);
1327 }
1328 }
1329 else
1330 {
1331 skip("Cannot run tests without valid db tag\n");
1332 }
1333 }
1334
1335 DeleteFileA(dbpath + 4);
1336 }
1337
1338
1339
1340 static void expect_indexA_imp(const char* text, LONGLONG expected)
1341 {
1342 static WCHAR wide_string[100] = { 0 };
1343 LONGLONG result;
1344 MultiByteToWideChar(CP_ACP, 0, text, -1, wide_string, 100);
1345
1346 result = pSdbMakeIndexKeyFromString(wide_string);
1347 winetest_ok(result == expected, "Expected %s to result in %s, was: %s\n", text, wine_dbgstr_longlong(expected), wine_dbgstr_longlong(result));
1348 }
1349
1350 #define expect_indexA (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : expect_indexA_imp
1351
1352 static void test_IndexKeyFromString(void)
1353 {
1354 static WCHAR tmp [] = { 0xabba, 0xbcde, 0x2020, 0x20, 0x4444, 0};
1355 static WCHAR tmp2 [] = { 0xabba, 0xbcde, 0x20, 0x4444, 0};
1356 static WCHAR tmp3 [] = { 0x20, 0xbcde, 0x4041, 0x4444, 0};
1357 static WCHAR tmp4 [] = { 0x20, 0xbcde, 0x4041, 0x4444, 0x4444, 0};
1358 static WCHAR tmp5 [] = { 0x2020, 0xbcde, 0x4041, 0x4444, 0x4444, 0};
1359 static WCHAR tmp6 [] = { 0x20, 0xbcde, 0x4041, 0x4444, 0x4444, 0x4444, 0};
1360 static WCHAR tmp7 [] = { 0xbcde, 0x4041, 0x4444, 0x4444, 0x4444, 0x4444, 0x4444, 0x4444, 0x4444, 0};
1361 static WCHAR tmp8 [] = { 0xbc00, 0x4041, 0x4444, 0x4444, 0x4444, 0x4444, 0x4444, 0x4444, 0x4444, 0};
1362 LONGLONG result;
1363
1364 #if 0
1365 /* This crashes. */
1366 pSdbMakeIndexKeyFromString(NULL);
1367 #endif
1368
1369 expect_indexA("", 0x0000000000000000);
1370 expect_indexA("a", 0x4100000000000000);
1371 expect_indexA("aa", 0x4141000000000000);
1372 expect_indexA("aaa", 0x4141410000000000);
1373 expect_indexA("aaaa", 0x4141414100000000);
1374 expect_indexA("aaaaa", 0x4141414141000000);
1375 expect_indexA("aaaaaa", 0x4141414141410000);
1376 expect_indexA("aaaaaaa", 0x4141414141414100);
1377 expect_indexA("aaaaaaaa", 0x4141414141414141);
1378 expect_indexA("aaa aaaaa", 0x4141412041414141);
1379 /* Does not change */
1380 expect_indexA("aaaaaaaaa", 0x4141414141414141);
1381 expect_indexA("aaaaaaaab", 0x4141414141414141);
1382 expect_indexA("aaaaaaaac", 0x4141414141414141);
1383 expect_indexA("aaaaaaaaF", 0x4141414141414141);
1384 /* Upcase */
1385 expect_indexA("AAAAAAAA", 0x4141414141414141);
1386 expect_indexA("ABABABAB", 0x4142414241424142);
1387 expect_indexA("ABABABABZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ", 0x4142414241424142);
1388
1389 result = pSdbMakeIndexKeyFromString(tmp);
1390 ok(result == 0xbaabdebc20200000, "Expected %s to result in %s, was: %s\n", wine_dbgstr_w(tmp),
1391 wine_dbgstr_longlong(0xbaabdebc20200000), wine_dbgstr_longlong(result));
1392
1393 result = pSdbMakeIndexKeyFromString(tmp2);
1394 ok(result == 0xbaabdebc00000000, "Expected %s to result in %s, was: %s\n", wine_dbgstr_w(tmp2),
1395 wine_dbgstr_longlong(0xbaabdebc00000000), wine_dbgstr_longlong(result));
1396
1397 result = pSdbMakeIndexKeyFromString(tmp3);
1398 ok(result == 0x20debc4140000000, "Expected %s to result in %s, was: %s\n", wine_dbgstr_w(tmp3),
1399 wine_dbgstr_longlong(0x20debc4140000000), wine_dbgstr_longlong(result));
1400
1401 result = pSdbMakeIndexKeyFromString(tmp4);
1402 ok(result == 0x20debc4140000000, "Expected %s to result in %s, was: %s\n", wine_dbgstr_w(tmp4),
1403 wine_dbgstr_longlong(0x20debc4140000000), wine_dbgstr_longlong(result));
1404
1405 result = pSdbMakeIndexKeyFromString(tmp5);
1406 ok(result == 0x2020debc41400000, "Expected %s to result in %s, was: %s\n", wine_dbgstr_w(tmp5),
1407 wine_dbgstr_longlong(0x2020debc41400000), wine_dbgstr_longlong(result));
1408
1409 result = pSdbMakeIndexKeyFromString(tmp6);
1410 ok(result == 0x20debc4140444400, "Expected %s to result in %s, was: %s\n", wine_dbgstr_w(tmp6),
1411 wine_dbgstr_longlong(0x20debc4140444400), wine_dbgstr_longlong(result));
1412
1413 result = pSdbMakeIndexKeyFromString(tmp7);
1414 ok(result == 0xdebc414044444444, "Expected %s to result in %s, was: %s\n", wine_dbgstr_w(tmp7),
1415 wine_dbgstr_longlong(0xdebc414044444444), wine_dbgstr_longlong(result));
1416
1417 result = pSdbMakeIndexKeyFromString(tmp8);
1418 ok(result == 0xbc414044444444, "Expected %s to result in %s, was: %s\n", wine_dbgstr_w(tmp8),
1419 wine_dbgstr_longlong(0xbc414044444444), wine_dbgstr_longlong(result));
1420 }
1421
1422 static int validate_SDBQUERYRESULT_size()
1423 {
1424 unsigned char buffer[SDBQUERYRESULT_EXPECTED_SIZE * 2];
1425 WCHAR path[MAX_PATH];
1426 HSDB hsdb;
1427
1428 memset(buffer, 0xab, sizeof(buffer));
1429 hsdb = pSdbInitDatabase(SDB_DATABASE_MAIN_SHIM, NULL);
1430 if (hsdb)
1431 {
1432 GetModuleFileNameW(NULL, path, MAX_PATH);
1433 pSdbGetMatchingExe(hsdb, path, NULL, NULL, 0, (SDBQUERYRESULT*)buffer);
1434 pSdbReleaseDatabase(hsdb);
1435 if (buffer[0] == buffer[1] && buffer[1] == 0xab)
1436 {
1437 trace("SdbGetMatchingExe didnt do anything, cannot determine SDBQUERYRESULT size\n");
1438 return 1;
1439 }
1440 return buffer[SDBQUERYRESULT_EXPECTED_SIZE] == 0xab && buffer[SDBQUERYRESULT_EXPECTED_SIZE-1] != 0xab;
1441 }
1442
1443 return 1;
1444 }
1445
1446
1447 START_TEST(db)
1448 {
1449 g_WinVersion = get_host_winver();
1450 trace("Detected version: 0x%x\n", g_WinVersion);
1451 silence_debug_output();
1452
1453 //SetEnvironmentVariable("SHIM_DEBUG_LEVEL", "4");
1454 //SetEnvironmentVariable("SHIMENG_DEBUG_LEVEL", "4");
1455 //SetEnvironmentVariable("DEBUGCHANNEL", "+apphelp");
1456 hdll = LoadLibraryA("apphelp.dll");
1457 pSdbTagToString = (void *) GetProcAddress(hdll, "SdbTagToString");
1458 pSdbOpenDatabase = (void *) GetProcAddress(hdll, "SdbOpenDatabase");
1459 pSdbCreateDatabase = (void *) GetProcAddress(hdll, "SdbCreateDatabase");
1460 pSdbGetDatabaseVersion = (void *) GetProcAddress(hdll, "SdbGetDatabaseVersion");
1461 pSdbCloseDatabase = (void *) GetProcAddress(hdll, "SdbCloseDatabase");
1462 pSdbCloseDatabaseWrite = (void *) GetProcAddress(hdll, "SdbCloseDatabaseWrite");
1463 pSdbGetTagFromTagID = (void *) GetProcAddress(hdll, "SdbGetTagFromTagID");
1464 pSdbWriteNULLTag = (void *) GetProcAddress(hdll, "SdbWriteNULLTag");
1465 pSdbWriteWORDTag = (void *) GetProcAddress(hdll, "SdbWriteWORDTag");
1466 pSdbWriteDWORDTag = (void *) GetProcAddress(hdll, "SdbWriteDWORDTag");
1467 pSdbWriteQWORDTag = (void *) GetProcAddress(hdll, "SdbWriteQWORDTag");
1468 pSdbWriteBinaryTagFromFile = (void *) GetProcAddress(hdll, "SdbWriteBinaryTagFromFile");
1469 pSdbWriteStringTag = (void *) GetProcAddress(hdll, "SdbWriteStringTag");
1470 pSdbWriteStringRefTag = (void *) GetProcAddress(hdll, "SdbWriteStringRefTag");
1471 pSdbBeginWriteListTag = (void *)GetProcAddress(hdll, "SdbBeginWriteListTag");
1472 pSdbEndWriteListTag = (void *) GetProcAddress(hdll, "SdbEndWriteListTag");
1473 pSdbFindFirstTag = (void *) GetProcAddress(hdll, "SdbFindFirstTag");
1474 pSdbFindNextTag = (void *) GetProcAddress(hdll, "SdbFindNextTag");
1475 pSdbReadWORDTag = (void *) GetProcAddress(hdll, "SdbReadWORDTag");
1476 pSdbReadDWORDTag = (void *) GetProcAddress(hdll, "SdbReadDWORDTag");
1477 pSdbReadQWORDTag = (void *) GetProcAddress(hdll, "SdbReadQWORDTag");
1478 pSdbReadBinaryTag = (void *) GetProcAddress(hdll, "SdbReadBinaryTag");
1479 pSdbReadStringTag = (void *) GetProcAddress(hdll, "SdbReadStringTag");
1480 pSdbGetTagDataSize = (void *) GetProcAddress(hdll, "SdbGetTagDataSize");
1481 pSdbGetBinaryTagData = (void *) GetProcAddress(hdll, "SdbGetBinaryTagData");
1482 pSdbGetStringTagPtr = (void *) GetProcAddress(hdll, "SdbGetStringTagPtr");
1483 pSdbGetFirstChild = (void *) GetProcAddress(hdll, "SdbGetFirstChild");
1484 pSdbGetNextChild = (void *) GetProcAddress(hdll, "SdbGetNextChild");
1485 pSdbGetDatabaseID = (void *) GetProcAddress(hdll, "SdbGetDatabaseID");
1486 pSdbGUIDToString = (void *) GetProcAddress(hdll, "SdbGUIDToString");
1487 pSdbInitDatabase = (void *) GetProcAddress(hdll, "SdbInitDatabase");
1488 pSdbReleaseDatabase = (void *) GetProcAddress(hdll, "SdbReleaseDatabase");
1489 pSdbGetMatchingExe = (void *) GetProcAddress(hdll, "SdbGetMatchingExe");
1490 pSdbTagRefToTagID = (void *) GetProcAddress(hdll, "SdbTagRefToTagID");
1491 pSdbMakeIndexKeyFromString = (void *) GetProcAddress(hdll, "SdbMakeIndexKeyFromString");
1492
1493 test_Sdb();
1494 test_write_ex();
1495 test_stringtable();
1496 test_CheckDatabaseManually();
1497 if (validate_SDBQUERYRESULT_size())
1498 test_MatchApplications();
1499 else
1500 skip("Skipping tests with SDBQUERYRESULT due to a wrong size reported\n");
1501 test_TagRef();
1502 skip("test_SecondaryDB()\n");
1503 test_IndexKeyFromString();
1504 }