Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/dlls/advpack/tests/advpack.c
4393 views
1
/*
2
* Unit tests for advpack.dll
3
*
4
* Copyright (C) 2005 Robert Reif
5
* Copyright (C) 2005 Sami Aario
6
*
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version.
11
*
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
16
*
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20
*/
21
22
#include <stdio.h>
23
#include <stdarg.h>
24
#include <windows.h>
25
#include <advpub.h>
26
#include <assert.h>
27
#include "wine/test.h"
28
29
/* defines for the TranslateInfString/Ex tests */
30
#define TEST_STRING1 "\\Application Name"
31
#define TEST_STRING2 "%49001%\\Application Name"
32
33
/* defines for the SetPerUserSecValues tests */
34
#define GUID_KEY "SOFTWARE\\Microsoft\\Active Setup\\Installed Components\\guid"
35
#define REG_VAL_EXISTS(key, value) !RegQueryValueExA(key, value, NULL, NULL, NULL, NULL)
36
#define OPEN_GUID_KEY() !RegOpenKeyA(HKEY_LOCAL_MACHINE, GUID_KEY, &guid)
37
38
static HMODULE hAdvPack;
39
static HRESULT (WINAPI *pCloseINFEngine)(HINF);
40
static HRESULT (WINAPI *pDelNode)(LPCSTR,DWORD);
41
static HRESULT (WINAPI *pGetVersionFromFile)(LPCSTR,LPDWORD,LPDWORD,BOOL);
42
static HRESULT (WINAPI *pOpenINFEngine)(PCSTR,PCSTR,DWORD,HINF*,PVOID);
43
static HRESULT (WINAPI *pSetPerUserSecValues)(PPERUSERSECTIONA pPerUser);
44
static HRESULT (WINAPI *pTranslateInfString)(LPCSTR,LPCSTR,LPCSTR,LPCSTR,LPSTR,DWORD,LPDWORD,LPVOID);
45
static HRESULT (WINAPI *pTranslateInfStringEx)(HINF,PCSTR,PCSTR,PCSTR,PSTR,DWORD,PDWORD,PVOID);
46
47
static CHAR inf_file[MAX_PATH];
48
static CHAR PROG_FILES_ROOT[MAX_PATH];
49
static CHAR PROG_FILES[MAX_PATH];
50
static CHAR APP_PATH[MAX_PATH];
51
static DWORD APP_PATH_LEN;
52
53
static void get_progfiles_dir(void)
54
{
55
HKEY hkey;
56
DWORD size = MAX_PATH;
57
58
RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", &hkey);
59
RegQueryValueExA(hkey, "ProgramFilesDir", NULL, NULL, (LPBYTE)PROG_FILES_ROOT, &size);
60
RegCloseKey(hkey);
61
62
lstrcpyA(PROG_FILES, PROG_FILES_ROOT + 3); /* skip C:\ */
63
lstrcpyA(APP_PATH, PROG_FILES_ROOT);
64
lstrcatA(APP_PATH, TEST_STRING1);
65
APP_PATH_LEN = lstrlenA(APP_PATH) + 1;
66
}
67
68
static BOOL init_function_pointers(void)
69
{
70
hAdvPack = LoadLibraryA("advpack.dll");
71
72
if (!hAdvPack)
73
return FALSE;
74
75
pCloseINFEngine = (void*)GetProcAddress(hAdvPack, "CloseINFEngine");
76
pDelNode = (void *)GetProcAddress(hAdvPack, "DelNode");
77
pGetVersionFromFile = (void *)GetProcAddress(hAdvPack, "GetVersionFromFile");
78
pOpenINFEngine = (void*)GetProcAddress(hAdvPack, "OpenINFEngine");
79
pSetPerUserSecValues = (void*)GetProcAddress(hAdvPack, "SetPerUserSecValues");
80
pTranslateInfString = (void *)GetProcAddress(hAdvPack, "TranslateInfString");
81
pTranslateInfStringEx = (void*)GetProcAddress(hAdvPack, "TranslateInfStringEx");
82
83
if (!pCloseINFEngine || !pDelNode || !pGetVersionFromFile ||
84
!pOpenINFEngine || !pSetPerUserSecValues || !pTranslateInfString)
85
{
86
win_skip("Needed functions are not available\n");
87
FreeLibrary(hAdvPack);
88
return FALSE;
89
}
90
91
return TRUE;
92
}
93
94
static void version_test(void)
95
{
96
HRESULT hr;
97
DWORD major, minor;
98
99
major = minor = 0;
100
hr = pGetVersionFromFile("kernel32.dll", &major, &minor, FALSE);
101
ok (hr == S_OK, "GetVersionFromFileEx(kernel32.dll) failed, returned "
102
"0x%08lx\n", hr);
103
trace("kernel32.dll Language ID: 0x%08lx, Codepage ID: 0x%08lx\n",
104
major, minor);
105
106
major = minor = 0;
107
hr = pGetVersionFromFile("kernel32.dll", &major, &minor, TRUE);
108
ok (hr == S_OK, "GetVersionFromFileEx(kernel32.dll) failed, returned "
109
"0x%08lx\n", hr);
110
trace("kernel32.dll version: %d.%d.%d.%d\n", HIWORD(major), LOWORD(major),
111
HIWORD(minor), LOWORD(minor));
112
113
major = minor = 0;
114
hr = pGetVersionFromFile("advpack.dll", &major, &minor, FALSE);
115
ok (hr == S_OK, "GetVersionFromFileEx(advpack.dll) failed, returned "
116
"0x%08lx\n", hr);
117
trace("advpack.dll Language ID: 0x%08lx, Codepage ID: 0x%08lx\n",
118
major, minor);
119
120
major = minor = 0;
121
hr = pGetVersionFromFile("advpack.dll", &major, &minor, TRUE);
122
ok (hr == S_OK, "GetVersionFromFileEx(advpack.dll) failed, returned "
123
"0x%08lx\n", hr);
124
trace("advpack.dll version: %d.%d.%d.%d\n", HIWORD(major), LOWORD(major),
125
HIWORD(minor), LOWORD(minor));
126
}
127
128
static void delnode_test(void)
129
{
130
HRESULT hr;
131
HANDLE hn;
132
CHAR currDir[MAX_PATH];
133
UINT currDirLen;
134
135
/* Native DelNode apparently does not support relative paths, so we use
136
absolute paths for testing */
137
currDirLen = GetCurrentDirectoryA(ARRAY_SIZE(currDir), currDir);
138
assert(currDirLen > 0 && currDirLen < ARRAY_SIZE(currDir));
139
140
if(currDir[currDirLen - 1] == '\\')
141
currDir[--currDirLen] = 0;
142
143
/* Simple tests; these should fail. */
144
hr = pDelNode(NULL, 0);
145
ok (hr == E_FAIL, "DelNode called with NULL pathname should return E_FAIL\n");
146
hr = pDelNode("", 0);
147
ok (hr == E_FAIL, "DelNode called with empty pathname should return E_FAIL\n");
148
149
/* Test deletion of a file. */
150
hn = CreateFileA("DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
151
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
152
assert(hn != INVALID_HANDLE_VALUE);
153
CloseHandle(hn);
154
hr = pDelNode(lstrcatA(currDir, "\\DelNodeTestFile1"), 0);
155
ok (hr == S_OK, "DelNode failed deleting a single file\n");
156
currDir[currDirLen] = '\0';
157
158
/* Test deletion of an empty directory. */
159
CreateDirectoryA("DelNodeTestDir", NULL);
160
hr = pDelNode(lstrcatA(currDir, "\\DelNodeTestDir"), 0);
161
ok (hr == S_OK, "DelNode failed deleting an empty directory\n");
162
currDir[currDirLen] = '\0';
163
CreateDirectoryA("DelNodeTestDir", NULL);
164
hr = pDelNode(lstrcatA(currDir, "\\DelNodeTestDir"), ADN_DEL_IF_EMPTY);
165
ok (hr == S_OK, "DelNode ADN_DEL_IF_EMPTY failed deleting an empty directory\n");
166
currDir[currDirLen] = '\0';
167
168
/* Test deletion of a directory containing one file. */
169
CreateDirectoryA("DelNodeTestDir", NULL);
170
hn = CreateFileA("DelNodeTestDir\\DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
171
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
172
assert(hn != INVALID_HANDLE_VALUE);
173
CloseHandle(hn);
174
lstrcatA(currDir, "\\DelNodeTestDir");
175
hr = pDelNode(currDir, ADN_DEL_IF_EMPTY);
176
ok (hr == E_FAIL, "DelNode ADN_DEL_IF_EMPTY should not delete non-empty\n");
177
hr = pDelNode(currDir, 0);
178
ok (hr == S_OK, "DelNode failed deleting a directory containing one file\n");
179
currDir[currDirLen] = '\0';
180
181
/* Test deletion of a directory containing multiple files. */
182
CreateDirectoryA("DelNodeTestDir", NULL);
183
hn = CreateFileA("DelNodeTestDir\\DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
184
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
185
assert(hn != INVALID_HANDLE_VALUE);
186
CloseHandle(hn);
187
hn = CreateFileA("DelNodeTestDir\\DelNodeTestFile2", GENERIC_WRITE, 0, NULL,
188
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
189
assert(hn != INVALID_HANDLE_VALUE);
190
CloseHandle(hn);
191
hn = CreateFileA("DelNodeTestDir\\DelNodeTestFile3", GENERIC_WRITE, 0, NULL,
192
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
193
assert(hn != INVALID_HANDLE_VALUE);
194
CloseHandle(hn);
195
hr = pDelNode(lstrcatA(currDir, "\\DelNodeTestDir"), 0);
196
ok (hr == S_OK, "DelNode failed deleting a directory containing multiple files\n");
197
}
198
199
static void WINAPIV append_str(char **str, const char *data, ...)
200
{
201
va_list valist;
202
203
va_start(valist, data);
204
vsprintf(*str, data, valist);
205
*str += strlen(*str);
206
va_end(valist);
207
}
208
209
static void create_inf_file(void)
210
{
211
char data[1024];
212
char *ptr = data;
213
DWORD dwNumberOfBytesWritten;
214
HANDLE hf = CreateFileA(inf_file, GENERIC_WRITE, 0, NULL,
215
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
216
217
append_str(&ptr, "[Version]\n");
218
append_str(&ptr, "Signature=\"$Chicago$\"\n");
219
append_str(&ptr, "[CustInstDestSection]\n");
220
append_str(&ptr, "49001=ProgramFilesDir\n");
221
append_str(&ptr, "49010=DestA,1\n");
222
append_str(&ptr, "49020=DestB\n");
223
append_str(&ptr, "49030=DestC\n");
224
append_str(&ptr, "[ProgramFilesDir]\n");
225
append_str(&ptr, "HKLM,\"Software\\Microsoft\\Windows\\CurrentVersion\",");
226
append_str(&ptr, "\"ProgramFilesDir\",,\"%%24%%\\%%LProgramF%%\"\n");
227
append_str(&ptr, "[section]\n");
228
append_str(&ptr, "NotACustomDestination=Version\n");
229
append_str(&ptr, "CustomDestination=CustInstDestSection\n");
230
append_str(&ptr, "[Options.NTx86]\n");
231
append_str(&ptr, "49001=ProgramFilesDir\n");
232
append_str(&ptr, "InstallDir=%%49001%%\\%%DefaultAppPath%%\n");
233
append_str(&ptr, "Result1=%%49010%%\n");
234
append_str(&ptr, "Result2=%%49020%%\n");
235
append_str(&ptr, "Result3=%%49030%%\n");
236
append_str(&ptr, "CustomHDestination=CustInstDestSection\n");
237
append_str(&ptr, "[Strings]\n");
238
append_str(&ptr, "DefaultAppPath=\"Application Name\"\n");
239
append_str(&ptr, "LProgramF=\"%s\"\n", PROG_FILES);
240
append_str(&ptr, "[DestA]\n");
241
append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%\\%%LProgramF%%'\n");
242
append_str(&ptr, "[DestB]\n");
243
append_str(&ptr, "'HKLM','Software\\Microsoft\\Windows\\CurrentVersion',");
244
append_str(&ptr, "'ProgramFilesDir',,\"%%24%%\"\n");
245
append_str(&ptr, "[DestC]\n");
246
append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n");
247
248
WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
249
CloseHandle(hf);
250
}
251
252
static void translateinfstring_test(void)
253
{
254
HRESULT hr;
255
char buffer[MAX_PATH];
256
DWORD dwSize;
257
258
create_inf_file();
259
260
/* pass in a couple invalid parameters */
261
hr = pTranslateInfString(NULL, NULL, NULL, NULL, buffer, MAX_PATH, &dwSize, NULL);
262
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", (UINT)hr);
263
264
/* try to open an inf file that doesn't exist */
265
hr = pTranslateInfString("c:\\a.inf", "Options.NTx86", "Options.NTx86",
266
"InstallDir", buffer, MAX_PATH, &dwSize, NULL);
267
ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) || hr == E_INVALIDARG ||
268
hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND),
269
"Expected E_INVALIDARG, 0x80070002 or 0x8007007e, got 0x%08x\n", (UINT)hr);
270
271
if(hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND))
272
{
273
win_skip("WinNT 3.51 detected. Skipping tests for TranslateInfString()\n");
274
return;
275
}
276
277
/* try a nonexistent section */
278
buffer[0] = 0;
279
hr = pTranslateInfString(inf_file, "idontexist", "Options.NTx86",
280
"InstallDir", buffer, MAX_PATH, &dwSize, NULL);
281
if (hr == E_ACCESSDENIED)
282
{
283
skip("TranslateInfString is broken\n");
284
return;
285
}
286
ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr);
287
ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
288
ok(dwSize == 25, "Expected size 25, got %ld\n", dwSize);
289
290
buffer[0] = 0;
291
/* try other nonexistent section */
292
hr = pTranslateInfString(inf_file, "Options.NTx86", "idontexist",
293
"InstallDir", buffer, MAX_PATH, &dwSize, NULL);
294
ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG,
295
"Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr);
296
297
buffer[0] = 0;
298
/* try nonexistent key */
299
hr = pTranslateInfString(inf_file, "Options.NTx86", "Options.NTx86",
300
"notvalid", buffer, MAX_PATH, &dwSize, NULL);
301
ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG,
302
"Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr);
303
304
buffer[0] = 0;
305
/* test the behavior of pszInstallSection */
306
hr = pTranslateInfString(inf_file, "section", "Options.NTx86",
307
"InstallDir", buffer, MAX_PATH, &dwSize, NULL);
308
ok(hr == ERROR_SUCCESS || hr == E_FAIL,
309
"Expected ERROR_SUCCESS or E_FAIL, got 0x%08x\n", (UINT)hr);
310
311
if(hr == ERROR_SUCCESS)
312
{
313
ok(!strcmp(buffer, APP_PATH), "Expected '%s', got '%s'\n", APP_PATH, buffer);
314
ok(dwSize == APP_PATH_LEN, "Expected size %ld, got %ld\n", APP_PATH_LEN, dwSize);
315
}
316
317
buffer[0] = 0;
318
/* try without a pszInstallSection */
319
hr = pTranslateInfString(inf_file, NULL, "Options.NTx86",
320
"InstallDir", buffer, MAX_PATH, &dwSize, NULL);
321
ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr);
322
todo_wine
323
{
324
ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
325
ok(dwSize == 25, "Expected size 25, got %ld\n", dwSize);
326
}
327
328
DeleteFileA("c:\\a.inf");
329
DeleteFileA(inf_file);
330
}
331
332
static void translateinfstringex_test(void)
333
{
334
HINF hinf;
335
HRESULT hr;
336
char buffer[MAX_PATH];
337
DWORD size = MAX_PATH;
338
339
hr = pOpenINFEngine(inf_file, NULL, 0, &hinf, NULL);
340
if (hr == E_UNEXPECTED)
341
{
342
win_skip("Skipping tests on win9x because of brokenness\n");
343
return;
344
}
345
346
create_inf_file();
347
348
/* need to see if there are any flags */
349
350
/* try a NULL filename */
351
hr = pOpenINFEngine(NULL, "Options.NTx86", 0, &hinf, NULL);
352
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08lx\n", hr);
353
354
/* try an empty filename */
355
hr = pOpenINFEngine("", "Options.NTx86", 0, &hinf, NULL);
356
ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) /* NT+ */ ||
357
hr == HRESULT_FROM_WIN32(E_UNEXPECTED) /* 9x */,
358
"Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND or E_UNEXPECTED), got %08lx\n", hr);
359
360
/* try a NULL hinf */
361
hr = pOpenINFEngine(inf_file, "Options.NTx86", 0, NULL, NULL);
362
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08lx\n", hr);
363
364
/* open the INF without the Install section specified */
365
hr = pOpenINFEngine(inf_file, NULL, 0, &hinf, NULL);
366
ok(hr == S_OK, "Expected S_OK, got %08lx\n", hr);
367
368
/* try a NULL hinf */
369
hr = pTranslateInfStringEx(NULL, inf_file, "Options.NTx86", "InstallDir",
370
buffer, size, &size, NULL);
371
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08lx\n", hr);
372
373
/* try a NULL filename */
374
hr = pTranslateInfStringEx(hinf, NULL, "Options.NTx86", "InstallDir",
375
buffer, size, &size, NULL);
376
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08lx\n", hr);
377
378
/* try an empty filename */
379
memset(buffer, 'a', 25);
380
buffer[24] = '\0';
381
size = MAX_PATH;
382
hr = pTranslateInfStringEx(hinf, "", "Options.NTx86", "InstallDir",
383
buffer, size, &size, NULL);
384
ok(hr == S_OK, "Expected S_OK, got %08lx\n", hr);
385
todo_wine
386
{
387
ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
388
ok(size == 25, "Expected size 25, got %ld\n", size);
389
}
390
391
/* try a NULL translate section */
392
hr = pTranslateInfStringEx(hinf, inf_file, NULL, "InstallDir",
393
buffer, size, &size, NULL);
394
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08lx\n", hr);
395
396
/* try an empty translate section */
397
hr = pTranslateInfStringEx(hinf, inf_file, "", "InstallDir",
398
buffer, size, &size, NULL);
399
ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %08lx\n", hr);
400
401
/* try a NULL translate key */
402
hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", NULL,
403
buffer, size, &size, NULL);
404
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08lx\n", hr);
405
406
/* try an empty translate key */
407
hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "",
408
buffer, size, &size, NULL);
409
ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %08lx\n", hr);
410
411
/* successfully translate the string */
412
memset(buffer, 'a', 25);
413
buffer[24] = '\0';
414
size = MAX_PATH;
415
hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "InstallDir",
416
buffer, size, &size, NULL);
417
ok(hr == S_OK, "Expected S_OK, got %08lx\n", hr);
418
todo_wine
419
{
420
ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
421
ok(size == 25, "Expected size 25, got %ld\n", size);
422
}
423
424
/* try a NULL hinf */
425
hr = pCloseINFEngine(NULL);
426
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08lx\n", hr);
427
428
/* successfully close the hinf */
429
hr = pCloseINFEngine(hinf);
430
ok(hr == S_OK, "Expected S_OK, got %08lx\n", hr);
431
432
/* open the inf with the install section */
433
hr = pOpenINFEngine(inf_file, "section", 0, &hinf, NULL);
434
if (hr == E_FAIL)
435
{
436
skip("can't open engine with install section (needs admin rights)\n");
437
DeleteFileA(inf_file);
438
return;
439
}
440
ok(hr == S_OK, "Expected S_OK, got %08lx\n", hr);
441
442
/* translate the string with the install section specified */
443
memset(buffer, 'a', APP_PATH_LEN);
444
buffer[APP_PATH_LEN - 1] = '\0';
445
size = MAX_PATH;
446
hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "InstallDir",
447
buffer, size, &size, NULL);
448
ok(hr == S_OK, "Expected S_OK, got %08lx\n", hr);
449
ok(!strcmp(buffer, APP_PATH), "Expected %s, got %s\n", APP_PATH, buffer);
450
ok(size == APP_PATH_LEN, "Expected size %ld, got %ld\n", APP_PATH_LEN, size);
451
452
/* Single quote test (Note size includes null on return from call) */
453
memset(buffer, 'a', APP_PATH_LEN);
454
buffer[APP_PATH_LEN - 1] = '\0';
455
size = MAX_PATH;
456
hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result1",
457
buffer, size, &size, NULL);
458
ok(hr == S_OK, "Expected S_OK, got %08lx\n", hr);
459
ok(!lstrcmpiA(buffer, PROG_FILES_ROOT),
460
"Expected %s, got %s\n", PROG_FILES_ROOT, buffer);
461
ok(size == strlen(PROG_FILES_ROOT)+1, "Expected size %d, got %ld\n",
462
lstrlenA(PROG_FILES_ROOT)+1, size);
463
464
memset(buffer, 'a', APP_PATH_LEN);
465
buffer[APP_PATH_LEN - 1] = '\0';
466
size = MAX_PATH;
467
hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result2",
468
buffer, size, &size, NULL);
469
ok(hr == S_OK, "Expected S_OK, got %08lx\n", hr);
470
ok(!lstrcmpiA(buffer, PROG_FILES_ROOT),
471
"Expected %s, got %s\n", PROG_FILES_ROOT, buffer);
472
ok(size == strlen(PROG_FILES_ROOT)+1, "Expected size %d, got %ld\n",
473
lstrlenA(PROG_FILES_ROOT)+1, size);
474
475
{
476
char drive[MAX_PATH];
477
lstrcpyA(drive, PROG_FILES_ROOT);
478
drive[3] = 0x00; /* Just keep the system drive plus '\' */
479
480
memset(buffer, 'a', APP_PATH_LEN);
481
buffer[APP_PATH_LEN - 1] = '\0';
482
size = MAX_PATH;
483
hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result3",
484
buffer, size, &size, NULL);
485
ok(hr == S_OK, "Expected S_OK, got %08lx\n", hr);
486
ok(!lstrcmpiA(buffer, drive),
487
"Expected %s, got %s\n", drive, buffer);
488
ok(size == strlen(drive)+1, "Expected size %d, got %ld\n",
489
lstrlenA(drive)+1, size);
490
}
491
492
/* close the INF again */
493
hr = pCloseINFEngine(hinf);
494
ok(hr == S_OK, "Expected S_OK, got %08lx\n", hr);
495
496
DeleteFileA(inf_file);
497
498
/* Create another .inf file which is just here to trigger a wine bug */
499
{
500
char data[1024];
501
char *ptr = data;
502
DWORD dwNumberOfBytesWritten;
503
HANDLE hf = CreateFileA(inf_file, GENERIC_WRITE, 0, NULL,
504
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
505
506
append_str(&ptr, "[Version]\n");
507
append_str(&ptr, "Signature=\"$Chicago$\"\n");
508
append_str(&ptr, "[section]\n");
509
append_str(&ptr, "NotACustomDestination=Version\n");
510
append_str(&ptr, "CustomDestination=CustInstDestSection\n");
511
append_str(&ptr, "[CustInstDestSection]\n");
512
append_str(&ptr, "49010=DestA,1\n");
513
append_str(&ptr, "49020=DestB\n");
514
append_str(&ptr, "49030=DestC\n");
515
append_str(&ptr, "49040=DestD\n");
516
append_str(&ptr, "[Options.NTx86]\n");
517
append_str(&ptr, "Result2=%%49030%%\n");
518
append_str(&ptr, "[DestA]\n");
519
append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n");
520
/* The point of this test is to have HKCU just before the quoted HKLM */
521
append_str(&ptr, "[DestB]\n");
522
append_str(&ptr, "HKCU,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n");
523
append_str(&ptr, "[DestC]\n");
524
append_str(&ptr, "'HKLM','Software\\Microsoft\\Windows\\CurrentVersion',");
525
append_str(&ptr, "'ProgramFilesDir',,\"%%24%%\"\n");
526
append_str(&ptr, "[DestD]\n");
527
append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n");
528
529
WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
530
CloseHandle(hf);
531
}
532
533
/* open the inf with the install section */
534
hr = pOpenINFEngine(inf_file, "section", 0, &hinf, NULL);
535
ok(hr == S_OK, "Expected S_OK, got %08lx\n", hr);
536
537
/* Single quote test (Note size includes null on return from call) */
538
memset(buffer, 'a', APP_PATH_LEN);
539
buffer[APP_PATH_LEN - 1] = '\0';
540
size = MAX_PATH;
541
hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result2",
542
buffer, size, &size, NULL);
543
ok(hr == S_OK, "Expected S_OK, got %08lx\n", hr);
544
ok(!lstrcmpiA(buffer, PROG_FILES_ROOT),
545
"Expected %s, got %s\n", PROG_FILES_ROOT, buffer);
546
ok(size == strlen(PROG_FILES_ROOT)+1, "Expected size %d, got %ld\n",
547
lstrlenA(PROG_FILES_ROOT)+1, size);
548
549
/* close the INF again */
550
hr = pCloseINFEngine(hinf);
551
ok(hr == S_OK, "Expected S_OK, got %08lx\n", hr);
552
553
DeleteFileA(inf_file);
554
}
555
556
static BOOL check_reg_str(HKEY hkey, LPCSTR name, LPCSTR value)
557
{
558
DWORD size = MAX_PATH;
559
char check[MAX_PATH];
560
561
if (RegQueryValueExA(hkey, name, NULL, NULL, (LPBYTE)check, &size))
562
return FALSE;
563
564
return !lstrcmpA(check, value);
565
}
566
567
static BOOL check_reg_dword(HKEY hkey, LPCSTR name, DWORD value)
568
{
569
DWORD size = sizeof(DWORD);
570
DWORD check;
571
572
if (RegQueryValueExA(hkey, name, NULL, NULL, (LPBYTE)&check, &size))
573
return FALSE;
574
575
return (check == value);
576
}
577
578
static void setperusersecvalues_test(void)
579
{
580
PERUSERSECTIONA peruser;
581
HRESULT hr;
582
HKEY guid;
583
584
lstrcpyA(peruser.szDispName, "displayname");
585
lstrcpyA(peruser.szLocale, "locale");
586
lstrcpyA(peruser.szStub, "stub");
587
lstrcpyA(peruser.szVersion, "1,1,1,1");
588
lstrcpyA(peruser.szCompID, "compid");
589
peruser.dwIsInstalled = 1;
590
peruser.bRollback = FALSE;
591
592
/* try a NULL pPerUser */
593
if (0)
594
{
595
/* This crashes on systems with IE7 */
596
hr = pSetPerUserSecValues(NULL);
597
todo_wine
598
ok(hr == S_OK, "Expected S_OK, got %ld\n", hr);
599
ok(!OPEN_GUID_KEY(), "Expected guid key to not exist\n");
600
}
601
602
/* at the very least, szGUID must be valid */
603
peruser.szGUID[0] = '\0';
604
hr = pSetPerUserSecValues(&peruser);
605
ok(hr == S_OK, "Expected S_OK, got %ld\n", hr);
606
ok(!OPEN_GUID_KEY(), "Expected guid key to not exist\n");
607
608
/* set initial values */
609
lstrcpyA(peruser.szGUID, "guid");
610
hr = pSetPerUserSecValues(&peruser);
611
if (hr == E_FAIL)
612
{
613
skip("SetPerUserSecValues is broken\n");
614
return;
615
}
616
ok(hr == S_OK, "Expected S_OK, got %08lx\n", hr);
617
ok(OPEN_GUID_KEY(), "Expected guid key to exist\n");
618
ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
619
ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
620
ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
621
ok(check_reg_str(guid, "StubPath", "stub"), "Expected stub\n");
622
ok(check_reg_str(guid, "Version", "1,1,1,1"), "Expected 1,1,1,1\n");
623
ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
624
ok(!REG_VAL_EXISTS(guid, "OldDisplayName"), "Expected OldDisplayName to not exist\n");
625
ok(!REG_VAL_EXISTS(guid, "OldLocale"), "Expected OldLocale to not exist\n");
626
ok(!REG_VAL_EXISTS(guid, "OldStubPath"), "Expected OldStubPath to not exist\n");
627
ok(!REG_VAL_EXISTS(guid, "OldVersion"), "Expected OldVersion to not exist\n");
628
ok(!REG_VAL_EXISTS(guid, "RealStubPath"), "Expected RealStubPath to not exist\n");
629
630
/* raise the version, but bRollback is FALSE, so vals not saved */
631
lstrcpyA(peruser.szVersion, "2,1,1,1");
632
hr = pSetPerUserSecValues(&peruser);
633
ok(hr == S_OK, "Expected S_OK, got %08lx\n", hr);
634
ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
635
ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
636
ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
637
ok(check_reg_str(guid, "StubPath", "stub"), "Expected stub\n");
638
ok(check_reg_str(guid, "Version", "2,1,1,1"), "Expected 2,1,1,1\n");
639
ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
640
ok(!REG_VAL_EXISTS(guid, "OldDisplayName"), "Expected OldDisplayName to not exist\n");
641
ok(!REG_VAL_EXISTS(guid, "OldLocale"), "Expected OldLocale to not exist\n");
642
ok(!REG_VAL_EXISTS(guid, "OldStubPath"), "Expected OldStubPath to not exist\n");
643
ok(!REG_VAL_EXISTS(guid, "OldVersion"), "Expected OldVersion to not exist\n");
644
ok(!REG_VAL_EXISTS(guid, "RealStubPath"), "Expected RealStubPath to not exist\n");
645
646
/* raise the version again, bRollback is TRUE so vals are saved */
647
peruser.bRollback = TRUE;
648
lstrcpyA(peruser.szVersion, "3,1,1,1");
649
hr = pSetPerUserSecValues(&peruser);
650
ok(hr == S_OK, "Expected S_OK, got %08lx\n", hr);
651
ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
652
ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
653
ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
654
ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
655
ok(check_reg_str(guid, "Version", "3,1,1,1"), "Expected 3,1,1,1\n");
656
todo_wine
657
{
658
ok(check_reg_str(guid, "OldDisplayName", "displayname"), "Expected displayname\n");
659
ok(check_reg_str(guid, "OldLocale", "locale"), "Expected locale\n");
660
ok(check_reg_str(guid, "RealStubPath", "stub"), "Expected stub\n");
661
ok(check_reg_str(guid, "OldStubPath", "stub"), "Expected stub\n");
662
ok(check_reg_str(guid, "OldVersion", "2,1,1,1"), "Expected 2,1,1,1\n");
663
ok(check_reg_str(guid, "StubPath",
664
"rundll32.exe advpack.dll,UserInstStubWrapper guid"),
665
"Expected real stub\n");
666
}
667
668
RegDeleteKeyA(HKEY_LOCAL_MACHINE, GUID_KEY);
669
}
670
671
START_TEST(advpack)
672
{
673
if (!init_function_pointers())
674
return;
675
676
/* Make sure we create the temporary file in a directory
677
* where we have adequate rights
678
*/
679
GetTempPathA(MAX_PATH, inf_file);
680
lstrcatA(inf_file,"test.inf");
681
682
get_progfiles_dir();
683
684
version_test();
685
delnode_test();
686
setperusersecvalues_test();
687
translateinfstring_test();
688
translateinfstringex_test();
689
690
FreeLibrary(hAdvPack);
691
}
692
693