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