advapi32: Implement LsaSetSecret stub.
[wine/wine-kai.git] / dlls / advpack / tests / advpack.c
blob8615850ab38720d40bf2e2dff66f19c81d9391bd
1 /*
2 * Unit tests for advpack.dll
4 * Copyright (C) 2005 Robert Reif
5 * Copyright (C) 2005 Sami Aario
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.
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.
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
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"
29 /* defines for the TranslateInfString/Ex tests */
30 #define TEST_STRING1 "\\Application Name"
31 #define TEST_STRING2 "%49001%\\Application Name"
33 /* defines for the SetPerUserSecValues tests */
34 #define GUID_KEY "SOFTWARE\\Microsoft\\Active Setup\\Installed Components\\guid"
35 #define REG_VAL_EXISTS(key, value) !RegQueryValueEx(key, value, NULL, NULL, NULL, NULL)
36 #define OPEN_GUID_KEY() !RegOpenKey(HKEY_LOCAL_MACHINE, GUID_KEY, &guid)
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)(PPERUSERSECTION 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);
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;
53 static void get_progfiles_dir(void)
55 HKEY hkey;
56 DWORD size = MAX_PATH;
58 RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", &hkey);
59 RegQueryValueExA(hkey, "ProgramFilesDir", NULL, NULL, (LPBYTE)PROG_FILES_ROOT, &size);
60 RegCloseKey(hkey);
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;
68 static BOOL init_function_pointers(void)
70 hAdvPack = LoadLibraryA("advpack.dll");
72 if (!hAdvPack)
73 return FALSE;
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");
83 if (!pCloseINFEngine || !pDelNode || !pGetVersionFromFile ||
84 !pOpenINFEngine || !pSetPerUserSecValues || !pTranslateInfString)
86 skip("Needed functions are not available\n");
87 FreeLibrary(hAdvPack);
88 return FALSE;
91 return TRUE;
94 static void version_test(void)
96 HRESULT hr;
97 DWORD major, minor;
99 major = minor = 0;
100 hr = pGetVersionFromFile("kernel32.dll", &major, &minor, FALSE);
101 ok (hr == S_OK, "GetVersionFromFileEx(kernel32.dll) failed, returned "
102 "0x%08x\n", hr);
103 trace("kernel32.dll Language ID: 0x%08x, Codepage ID: 0x%08x\n",
104 major, minor);
106 major = minor = 0;
107 hr = pGetVersionFromFile("kernel32.dll", &major, &minor, TRUE);
108 ok (hr == S_OK, "GetVersionFromFileEx(kernel32.dll) failed, returned "
109 "0x%08x\n", hr);
110 trace("kernel32.dll version: %d.%d.%d.%d\n", HIWORD(major), LOWORD(major),
111 HIWORD(minor), LOWORD(minor));
113 major = minor = 0;
114 hr = pGetVersionFromFile("advpack.dll", &major, &minor, FALSE);
115 ok (hr == S_OK, "GetVersionFromFileEx(advpack.dll) failed, returned "
116 "0x%08x\n", hr);
117 trace("advpack.dll Language ID: 0x%08x, Codepage ID: 0x%08x\n",
118 major, minor);
120 major = minor = 0;
121 hr = pGetVersionFromFile("advpack.dll", &major, &minor, TRUE);
122 ok (hr == S_OK, "GetVersionFromFileEx(advpack.dll) failed, returned "
123 "0x%08x\n", hr);
124 trace("advpack.dll version: %d.%d.%d.%d\n", HIWORD(major), LOWORD(major),
125 HIWORD(minor), LOWORD(minor));
128 static void delnode_test(void)
130 HRESULT hr;
131 HANDLE hn;
132 CHAR currDir[MAX_PATH];
133 int currDirLen;
135 /* Native DelNode apparently does not support relative paths, so we use
136 absolute paths for testing */
137 currDirLen = GetCurrentDirectoryA(sizeof(currDir) / sizeof(CHAR), currDir);
138 assert(currDirLen > 0 && currDirLen < sizeof(currDir) / sizeof(CHAR));
140 if(currDir[currDirLen - 1] == '\\')
141 currDir[--currDirLen] = 0;
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");
149 /* Test deletion of a file. */
150 hn = CreateFile("DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
151 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
152 assert(hn != INVALID_HANDLE_VALUE);
153 CloseHandle(hn);
154 hr = pDelNode(lstrcat(currDir, "\\DelNodeTestFile1"), 0);
155 ok (hr == S_OK, "DelNode failed deleting a single file\n");
156 currDir[currDirLen] = '\0';
158 /* Test deletion of an empty directory. */
159 CreateDirectoryA("DelNodeTestDir", NULL);
160 hr = pDelNode(lstrcat(currDir, "\\DelNodeTestDir"), 0);
161 ok (hr == S_OK, "DelNode failed deleting an empty directory\n");
162 currDir[currDirLen] = '\0';
164 /* Test deletion of a directory containing one file. */
165 CreateDirectoryA("DelNodeTestDir", NULL);
166 hn = CreateFile("DelNodeTestDir\\DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
167 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
168 assert(hn != INVALID_HANDLE_VALUE);
169 CloseHandle(hn);
170 hr = pDelNode(lstrcat(currDir, "\\DelNodeTestDir"), 0);
171 ok (hr == S_OK, "DelNode failed deleting a directory containing one file\n");
172 currDir[currDirLen] = '\0';
174 /* Test deletion of a directory containing multiple files. */
175 CreateDirectoryA("DelNodeTestDir", NULL);
176 hn = CreateFile("DelNodeTestDir\\DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
177 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
178 assert(hn != INVALID_HANDLE_VALUE);
179 CloseHandle(hn);
180 hn = CreateFile("DelNodeTestDir\\DelNodeTestFile2", GENERIC_WRITE, 0, NULL,
181 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
182 assert(hn != INVALID_HANDLE_VALUE);
183 CloseHandle(hn);
184 hn = CreateFile("DelNodeTestDir\\DelNodeTestFile3", GENERIC_WRITE, 0, NULL,
185 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
186 assert(hn != INVALID_HANDLE_VALUE);
187 CloseHandle(hn);
188 hr = pDelNode(lstrcat(currDir, "\\DelNodeTestDir"), 0);
189 ok (hr == S_OK, "DelNode failed deleting a directory containing multiple files\n");
190 currDir[currDirLen] = '\0';
193 static void append_str(char **str, const char *data, ...)
195 va_list valist;
197 va_start(valist, data);
198 vsprintf(*str, data, valist);
199 *str += strlen(*str);
200 va_end(valist);
203 static void create_inf_file(void)
205 char data[1024];
206 char *ptr = data;
207 DWORD dwNumberOfBytesWritten;
208 HANDLE hf = CreateFile(inf_file, GENERIC_WRITE, 0, NULL,
209 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
211 append_str(&ptr, "[Version]\n");
212 append_str(&ptr, "Signature=\"$Chicago$\"\n");
213 append_str(&ptr, "[CustInstDestSection]\n");
214 append_str(&ptr, "49001=ProgramFilesDir\n");
215 append_str(&ptr, "49010=DestA,1\n");
216 append_str(&ptr, "49020=DestB\n");
217 append_str(&ptr, "49030=DestC\n");
218 append_str(&ptr, "[ProgramFilesDir]\n");
219 append_str(&ptr, "HKLM,\"Software\\Microsoft\\Windows\\CurrentVersion\",");
220 append_str(&ptr, "\"ProgramFilesDir\",,\"%%24%%\\%%LProgramF%%\"\n");
221 append_str(&ptr, "[section]\n");
222 append_str(&ptr, "NotACustomDestination=Version\n");
223 append_str(&ptr, "CustomDestination=CustInstDestSection\n");
224 append_str(&ptr, "[Options.NTx86]\n");
225 append_str(&ptr, "49001=ProgramFilesDir\n");
226 append_str(&ptr, "InstallDir=%%49001%%\\%%DefaultAppPath%%\n");
227 append_str(&ptr, "Result1=%%49010%%\n");
228 append_str(&ptr, "Result2=%%49020%%\n");
229 append_str(&ptr, "Result3=%%49030%%\n");
230 append_str(&ptr, "CustomHDestination=CustInstDestSection\n");
231 append_str(&ptr, "[Strings]\n");
232 append_str(&ptr, "DefaultAppPath=\"Application Name\"\n");
233 append_str(&ptr, "LProgramF=\"%s\"\n", PROG_FILES);
234 append_str(&ptr, "[DestA]\n");
235 append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%\\%%LProgramF%%'\n");
236 append_str(&ptr, "[DestB]\n");
237 append_str(&ptr, "'HKLM','Software\\Microsoft\\Windows\\CurrentVersion',");
238 append_str(&ptr, "'ProgramFilesDir',,\"%%24%%\"\n");
239 append_str(&ptr, "[DestC]\n");
240 append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n");
242 WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
243 CloseHandle(hf);
246 static void translateinfstring_test(void)
248 HRESULT hr;
249 char buffer[MAX_PATH];
250 DWORD dwSize;
252 create_inf_file();
254 /* pass in a couple invalid parameters */
255 hr = pTranslateInfString(NULL, NULL, NULL, NULL, buffer, MAX_PATH, &dwSize, NULL);
256 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", (UINT)hr);
258 /* try to open an inf file that doesn't exist */
259 hr = pTranslateInfString("c:\\a.inf", "Options.NTx86", "Options.NTx86",
260 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
261 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) || hr == E_INVALIDARG ||
262 hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND),
263 "Expected E_INVALIDARG, 0x80070002 or 0x8007007e, got 0x%08x\n", (UINT)hr);
265 if(hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND))
267 win_skip("WinNT 3.51 detected. Skipping tests for TranslateInfString()\n");
268 return;
271 /* try a nonexistent section */
272 buffer[0] = 0;
273 hr = pTranslateInfString(inf_file, "idontexist", "Options.NTx86",
274 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
275 ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr);
276 ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
277 ok(dwSize == 25, "Expected size 25, got %d\n", dwSize);
279 buffer[0] = 0;
280 /* try other nonexistent section */
281 hr = pTranslateInfString(inf_file, "Options.NTx86", "idontexist",
282 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
283 ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG,
284 "Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr);
286 buffer[0] = 0;
287 /* try nonexistent key */
288 hr = pTranslateInfString(inf_file, "Options.NTx86", "Options.NTx86",
289 "notvalid", buffer, MAX_PATH, &dwSize, NULL);
290 ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG,
291 "Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr);
293 buffer[0] = 0;
294 /* test the behavior of pszInstallSection */
295 hr = pTranslateInfString(inf_file, "section", "Options.NTx86",
296 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
297 ok(hr == ERROR_SUCCESS || hr == E_FAIL,
298 "Expected ERROR_SUCCESS or E_FAIL, got 0x%08x\n", (UINT)hr);
300 if(hr == ERROR_SUCCESS)
302 ok(!strcmp(buffer, APP_PATH), "Expected '%s', got '%s'\n", APP_PATH, buffer);
303 ok(dwSize == APP_PATH_LEN, "Expected size %d, got %d\n", APP_PATH_LEN, dwSize);
306 buffer[0] = 0;
307 /* try without a pszInstallSection */
308 hr = pTranslateInfString(inf_file, NULL, "Options.NTx86",
309 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
310 ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr);
311 todo_wine
313 ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
314 ok(dwSize == 25, "Expected size 25, got %d\n", dwSize);
317 DeleteFile("c:\\a.inf");
318 DeleteFile(inf_file);
321 static void translateinfstringex_test(void)
323 HINF hinf;
324 HRESULT hr;
325 char buffer[MAX_PATH];
326 DWORD size = MAX_PATH;
328 hr = pOpenINFEngine(inf_file, NULL, 0, &hinf, NULL);
329 if (hr == E_UNEXPECTED)
331 skip("Skipping tests on win9x because of brokenness\n");
332 return;
335 create_inf_file();
337 /* need to see if there are any flags */
339 /* try a NULL filename */
340 hr = pOpenINFEngine(NULL, "Options.NTx86", 0, &hinf, NULL);
341 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
343 /* try an empty filename */
344 hr = pOpenINFEngine("", "Options.NTx86", 0, &hinf, NULL);
345 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) /* NT+ */ ||
346 hr == HRESULT_FROM_WIN32(E_UNEXPECTED) /* 9x */,
347 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND or E_UNEXPECTED), got %08x\n", hr);
349 /* try a NULL hinf */
350 hr = pOpenINFEngine(inf_file, "Options.NTx86", 0, NULL, NULL);
351 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
353 /* open the INF without the Install section specified */
354 hr = pOpenINFEngine(inf_file, NULL, 0, &hinf, NULL);
355 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
357 /* try a NULL hinf */
358 hr = pTranslateInfStringEx(NULL, inf_file, "Options.NTx86", "InstallDir",
359 buffer, size, &size, NULL);
360 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
362 /* try a NULL filename */
363 hr = pTranslateInfStringEx(hinf, NULL, "Options.NTx86", "InstallDir",
364 buffer, size, &size, NULL);
365 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
367 /* try an empty filename */
368 memset(buffer, 'a', 25);
369 buffer[24] = '\0';
370 size = MAX_PATH;
371 hr = pTranslateInfStringEx(hinf, "", "Options.NTx86", "InstallDir",
372 buffer, size, &size, NULL);
373 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
374 todo_wine
376 ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
377 ok(size == 25, "Expected size 25, got %d\n", size);
380 /* try a NULL translate section */
381 hr = pTranslateInfStringEx(hinf, inf_file, NULL, "InstallDir",
382 buffer, size, &size, NULL);
383 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
385 /* try an empty translate section */
386 hr = pTranslateInfStringEx(hinf, inf_file, "", "InstallDir",
387 buffer, size, &size, NULL);
388 ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %08x\n", hr);
390 /* try a NULL translate key */
391 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", NULL,
392 buffer, size, &size, NULL);
393 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
395 /* try an empty translate key */
396 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "",
397 buffer, size, &size, NULL);
398 ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %08x\n", hr);
400 /* successfully translate the string */
401 memset(buffer, 'a', 25);
402 buffer[24] = '\0';
403 size = MAX_PATH;
404 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "InstallDir",
405 buffer, size, &size, NULL);
406 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
407 todo_wine
409 ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
410 ok(size == 25, "Expected size 25, got %d\n", size);
413 /* try a NULL hinf */
414 hr = pCloseINFEngine(NULL);
415 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
417 /* successfully close the hinf */
418 hr = pCloseINFEngine(hinf);
419 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
421 /* open the inf with the install section */
422 hr = pOpenINFEngine(inf_file, "section", 0, &hinf, NULL);
423 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
425 /* translate the string with the install section specified */
426 memset(buffer, 'a', APP_PATH_LEN);
427 buffer[APP_PATH_LEN - 1] = '\0';
428 size = MAX_PATH;
429 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "InstallDir",
430 buffer, size, &size, NULL);
431 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
432 ok(!strcmp(buffer, APP_PATH), "Expected %s, got %s\n", APP_PATH, buffer);
433 ok(size == APP_PATH_LEN, "Expected size %d, got %d\n", APP_PATH_LEN, size);
435 /* Single quote test (Note size includes null on return from call) */
436 memset(buffer, 'a', APP_PATH_LEN);
437 buffer[APP_PATH_LEN - 1] = '\0';
438 size = MAX_PATH;
439 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result1",
440 buffer, size, &size, NULL);
441 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
442 ok(!lstrcmpi(buffer, PROG_FILES_ROOT),
443 "Expected %s, got %s\n", PROG_FILES_ROOT, buffer);
444 ok(size == lstrlenA(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n",
445 lstrlenA(PROG_FILES_ROOT)+1, size);
447 memset(buffer, 'a', APP_PATH_LEN);
448 buffer[APP_PATH_LEN - 1] = '\0';
449 size = MAX_PATH;
450 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result2",
451 buffer, size, &size, NULL);
452 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
453 ok(!lstrcmpi(buffer, PROG_FILES_ROOT),
454 "Expected %s, got %s\n", PROG_FILES_ROOT, buffer);
455 ok(size == lstrlenA(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n",
456 lstrlenA(PROG_FILES_ROOT)+1, size);
459 char drive[MAX_PATH];
460 lstrcpy(drive, PROG_FILES_ROOT);
461 drive[3] = 0x00; /* Just keep the system drive plus '\' */
463 memset(buffer, 'a', APP_PATH_LEN);
464 buffer[APP_PATH_LEN - 1] = '\0';
465 size = MAX_PATH;
466 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result3",
467 buffer, size, &size, NULL);
468 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
469 ok(!lstrcmpi(buffer, drive),
470 "Expected %s, got %s\n", drive, buffer);
471 ok(size == lstrlenA(drive)+1, "Expected size %d, got %d\n",
472 lstrlenA(drive)+1, size);
475 /* close the INF again */
476 hr = pCloseINFEngine(hinf);
477 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
479 DeleteFileA(inf_file);
481 /* Create another .inf file which is just here to trigger a wine bug */
483 char data[1024];
484 char *ptr = data;
485 DWORD dwNumberOfBytesWritten;
486 HANDLE hf = CreateFile(inf_file, GENERIC_WRITE, 0, NULL,
487 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
489 append_str(&ptr, "[Version]\n");
490 append_str(&ptr, "Signature=\"$Chicago$\"\n");
491 append_str(&ptr, "[section]\n");
492 append_str(&ptr, "NotACustomDestination=Version\n");
493 append_str(&ptr, "CustomDestination=CustInstDestSection\n");
494 append_str(&ptr, "[CustInstDestSection]\n");
495 append_str(&ptr, "49010=DestA,1\n");
496 append_str(&ptr, "49020=DestB\n");
497 append_str(&ptr, "49030=DestC\n");
498 append_str(&ptr, "49040=DestD\n");
499 append_str(&ptr, "[Options.NTx86]\n");
500 append_str(&ptr, "Result2=%%49030%%\n");
501 append_str(&ptr, "[DestA]\n");
502 append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n");
503 /* The point of this test is to have HKCU just before the quoted HKLM */
504 append_str(&ptr, "[DestB]\n");
505 append_str(&ptr, "HKCU,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n");
506 append_str(&ptr, "[DestC]\n");
507 append_str(&ptr, "'HKLM','Software\\Microsoft\\Windows\\CurrentVersion',");
508 append_str(&ptr, "'ProgramFilesDir',,\"%%24%%\"\n");
509 append_str(&ptr, "[DestD]\n");
510 append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n");
512 WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
513 CloseHandle(hf);
516 /* open the inf with the install section */
517 hr = pOpenINFEngine(inf_file, "section", 0, &hinf, NULL);
518 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
520 /* Single quote test (Note size includes null on return from call) */
521 memset(buffer, 'a', APP_PATH_LEN);
522 buffer[APP_PATH_LEN - 1] = '\0';
523 size = MAX_PATH;
524 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result2",
525 buffer, size, &size, NULL);
526 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
527 ok(!lstrcmpi(buffer, PROG_FILES_ROOT),
528 "Expected %s, got %s\n", PROG_FILES_ROOT, buffer);
529 ok(size == lstrlenA(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n",
530 lstrlenA(PROG_FILES_ROOT)+1, size);
532 /* close the INF again */
533 hr = pCloseINFEngine(hinf);
534 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
536 DeleteFileA(inf_file);
539 static BOOL check_reg_str(HKEY hkey, LPCSTR name, LPCSTR value)
541 DWORD size = MAX_PATH;
542 char check[MAX_PATH];
544 if (RegQueryValueEx(hkey, name, NULL, NULL, (LPBYTE)check, &size))
545 return FALSE;
547 return !lstrcmp(check, value);
550 static BOOL check_reg_dword(HKEY hkey, LPCSTR name, DWORD value)
552 DWORD size = sizeof(DWORD);
553 DWORD check;
555 if (RegQueryValueEx(hkey, name, NULL, NULL, (LPBYTE)&check, &size))
556 return FALSE;
558 return (check == value);
561 static void setperusersecvalues_test(void)
563 PERUSERSECTION peruser;
564 HRESULT hr;
565 HKEY guid;
567 lstrcpy(peruser.szDispName, "displayname");
568 lstrcpy(peruser.szLocale, "locale");
569 lstrcpy(peruser.szStub, "stub");
570 lstrcpy(peruser.szVersion, "1,1,1,1");
571 lstrcpy(peruser.szCompID, "compid");
572 peruser.dwIsInstalled = 1;
573 peruser.bRollback = FALSE;
575 /* try a NULL pPerUser */
576 if (0)
578 /* This crashes on systems with IE7 */
579 hr = pSetPerUserSecValues(NULL);
580 todo_wine
581 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
582 ok(!OPEN_GUID_KEY(), "Expected guid key to not exist\n");
585 /* at the very least, szGUID must be valid */
586 peruser.szGUID[0] = '\0';
587 hr = pSetPerUserSecValues(&peruser);
588 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
589 ok(!OPEN_GUID_KEY(), "Expected guid key to not exist\n");
591 /* set initial values */
592 lstrcpy(peruser.szGUID, "guid");
593 hr = pSetPerUserSecValues(&peruser);
594 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
595 ok(OPEN_GUID_KEY(), "Expected guid key to exist\n");
596 ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
597 ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
598 ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
599 ok(check_reg_str(guid, "StubPath", "stub"), "Expected stub\n");
600 ok(check_reg_str(guid, "Version", "1,1,1,1"), "Expected 1,1,1,1\n");
601 ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
602 ok(!REG_VAL_EXISTS(guid, "OldDisplayName"), "Expected OldDisplayName to not exist\n");
603 ok(!REG_VAL_EXISTS(guid, "OldLocale"), "Expected OldLocale to not exist\n");
604 ok(!REG_VAL_EXISTS(guid, "OldStubPath"), "Expected OldStubPath to not exist\n");
605 ok(!REG_VAL_EXISTS(guid, "OldVersion"), "Expected OldVersion to not exist\n");
606 ok(!REG_VAL_EXISTS(guid, "RealStubPath"), "Expected RealStubPath to not exist\n");
608 /* raise the version, but bRollback is FALSE, so vals not saved */
609 lstrcpy(peruser.szVersion, "2,1,1,1");
610 hr = pSetPerUserSecValues(&peruser);
611 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
612 ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
613 ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
614 ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
615 ok(check_reg_str(guid, "StubPath", "stub"), "Expected stub\n");
616 ok(check_reg_str(guid, "Version", "2,1,1,1"), "Expected 2,1,1,1\n");
617 ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
618 ok(!REG_VAL_EXISTS(guid, "OldDisplayName"), "Expected OldDisplayName to not exist\n");
619 ok(!REG_VAL_EXISTS(guid, "OldLocale"), "Expected OldLocale to not exist\n");
620 ok(!REG_VAL_EXISTS(guid, "OldStubPath"), "Expected OldStubPath to not exist\n");
621 ok(!REG_VAL_EXISTS(guid, "OldVersion"), "Expected OldVersion to not exist\n");
622 ok(!REG_VAL_EXISTS(guid, "RealStubPath"), "Expected RealStubPath to not exist\n");
624 /* raise the version again, bRollback is TRUE so vals are saved */
625 peruser.bRollback = TRUE;
626 lstrcpy(peruser.szVersion, "3,1,1,1");
627 hr = pSetPerUserSecValues(&peruser);
628 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
629 ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
630 ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
631 ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
632 ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
633 ok(check_reg_str(guid, "Version", "3,1,1,1"), "Expected 3,1,1,1\n");
634 todo_wine
636 ok(check_reg_str(guid, "OldDisplayName", "displayname"), "Expected displayname\n");
637 ok(check_reg_str(guid, "OldLocale", "locale"), "Expected locale\n");
638 ok(check_reg_str(guid, "RealStubPath", "stub"), "Expected stub\n");
639 ok(check_reg_str(guid, "OldStubPath", "stub"), "Expected stub\n");
640 ok(check_reg_str(guid, "OldVersion", "2,1,1,1"), "Expected 2,1,1,1\n");
641 ok(check_reg_str(guid, "StubPath",
642 "rundll32.exe advpack.dll,UserInstStubWrapper guid"),
643 "Expected real stub\n");
646 RegDeleteKey(HKEY_LOCAL_MACHINE, GUID_KEY);
649 START_TEST(advpack)
651 if (!init_function_pointers())
652 return;
654 /* Make sure we create the temporary file in a directory
655 * were we have enough rights
657 GetTempPath(MAX_PATH, inf_file);
658 lstrcat(inf_file,"test.inf");
660 get_progfiles_dir();
662 version_test();
663 delnode_test();
664 setperusersecvalues_test();
665 translateinfstring_test();
666 translateinfstringex_test();
668 FreeLibrary(hAdvPack);