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