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