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