push 73336d9f381967eae40f391d78198b916ed9848d
[wine/hacks.git] / dlls / advpack / tests / advpack.c
blobb90df2d4b65e78bdde293521bf127d2582d7cd1e
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)
85 return FALSE;
87 return TRUE;
90 static void version_test(void)
92 HRESULT hr;
93 DWORD major, minor;
95 major = minor = 0;
96 hr = pGetVersionFromFile("kernel32.dll", &major, &minor, FALSE);
97 ok (hr == S_OK, "GetVersionFromFileEx(kernel32.dll) failed, returned "
98 "0x%08x\n", hr);
99 trace("kernel32.dll Language ID: 0x%08x, Codepage ID: 0x%08x\n",
100 major, minor);
102 major = minor = 0;
103 hr = pGetVersionFromFile("kernel32.dll", &major, &minor, TRUE);
104 ok (hr == S_OK, "GetVersionFromFileEx(kernel32.dll) failed, returned "
105 "0x%08x\n", hr);
106 trace("kernel32.dll version: %d.%d.%d.%d\n", HIWORD(major), LOWORD(major),
107 HIWORD(minor), LOWORD(minor));
109 major = minor = 0;
110 hr = pGetVersionFromFile("advpack.dll", &major, &minor, FALSE);
111 ok (hr == S_OK, "GetVersionFromFileEx(advpack.dll) failed, returned "
112 "0x%08x\n", hr);
113 trace("advpack.dll Language ID: 0x%08x, Codepage ID: 0x%08x\n",
114 major, minor);
116 major = minor = 0;
117 hr = pGetVersionFromFile("advpack.dll", &major, &minor, TRUE);
118 ok (hr == S_OK, "GetVersionFromFileEx(advpack.dll) failed, returned "
119 "0x%08x\n", hr);
120 trace("advpack.dll version: %d.%d.%d.%d\n", HIWORD(major), LOWORD(major),
121 HIWORD(minor), LOWORD(minor));
124 static void delnode_test(void)
126 HRESULT hr;
127 HANDLE hn;
128 CHAR currDir[MAX_PATH];
129 int currDirLen;
131 /* Native DelNode apparently does not support relative paths, so we use
132 absolute paths for testing */
133 currDirLen = GetCurrentDirectoryA(sizeof(currDir) / sizeof(CHAR), currDir);
134 assert(currDirLen > 0 && currDirLen < sizeof(currDir) / sizeof(CHAR));
136 if(currDir[currDirLen - 1] == '\\')
137 currDir[--currDirLen] = 0;
139 /* Simple tests; these should fail. */
140 hr = pDelNode(NULL, 0);
141 ok (hr == E_FAIL, "DelNode called with NULL pathname should return E_FAIL\n");
142 hr = pDelNode("", 0);
143 ok (hr == E_FAIL, "DelNode called with empty pathname should return E_FAIL\n");
145 /* Test deletion of a file. */
146 hn = CreateFile("DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
147 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
148 assert(hn != INVALID_HANDLE_VALUE);
149 CloseHandle(hn);
150 hr = pDelNode(lstrcat(currDir, "\\DelNodeTestFile1"), 0);
151 ok (hr == S_OK, "DelNode failed deleting a single file\n");
152 currDir[currDirLen] = '\0';
154 /* Test deletion of an empty directory. */
155 CreateDirectoryA("DelNodeTestDir", NULL);
156 hr = pDelNode(lstrcat(currDir, "\\DelNodeTestDir"), 0);
157 ok (hr == S_OK, "DelNode failed deleting an empty directory\n");
158 currDir[currDirLen] = '\0';
160 /* Test deletion of a directory containing one file. */
161 CreateDirectoryA("DelNodeTestDir", NULL);
162 hn = CreateFile("DelNodeTestDir\\DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
163 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
164 assert(hn != INVALID_HANDLE_VALUE);
165 CloseHandle(hn);
166 hr = pDelNode(lstrcat(currDir, "\\DelNodeTestDir"), 0);
167 ok (hr == S_OK, "DelNode failed deleting a directory containing one file\n");
168 currDir[currDirLen] = '\0';
170 /* Test deletion of a directory containing multiple files. */
171 CreateDirectoryA("DelNodeTestDir", NULL);
172 hn = CreateFile("DelNodeTestDir\\DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
173 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
174 assert(hn != INVALID_HANDLE_VALUE);
175 CloseHandle(hn);
176 hn = CreateFile("DelNodeTestDir\\DelNodeTestFile2", GENERIC_WRITE, 0, NULL,
177 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
178 assert(hn != INVALID_HANDLE_VALUE);
179 CloseHandle(hn);
180 hn = CreateFile("DelNodeTestDir\\DelNodeTestFile3", GENERIC_WRITE, 0, NULL,
181 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
182 assert(hn != INVALID_HANDLE_VALUE);
183 CloseHandle(hn);
184 hr = pDelNode(lstrcat(currDir, "\\DelNodeTestDir"), 0);
185 ok (hr == S_OK, "DelNode failed deleting a directory containing multiple files\n");
186 currDir[currDirLen] = '\0';
189 static void append_str(char **str, const char *data, ...)
191 va_list valist;
193 va_start(valist, data);
194 vsprintf(*str, data, valist);
195 *str += strlen(*str);
196 va_end(valist);
199 static void create_inf_file(void)
201 char data[1024];
202 char *ptr = data;
203 DWORD dwNumberOfBytesWritten;
204 HANDLE hf = CreateFile(inf_file, GENERIC_WRITE, 0, NULL,
205 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
207 append_str(&ptr, "[Version]\n");
208 append_str(&ptr, "Signature=\"$Chicago$\"\n");
209 append_str(&ptr, "[CustInstDestSection]\n");
210 append_str(&ptr, "49001=ProgramFilesDir\n");
211 append_str(&ptr, "49010=DestA,1\n");
212 append_str(&ptr, "49020=DestB\n");
213 append_str(&ptr, "49030=DestC\n");
214 append_str(&ptr, "[ProgramFilesDir]\n");
215 append_str(&ptr, "HKLM,\"Software\\Microsoft\\Windows\\CurrentVersion\",");
216 append_str(&ptr, "\"ProgramFilesDir\",,\"%%24%%\\%%LProgramF%%\"\n");
217 append_str(&ptr, "[section]\n");
218 append_str(&ptr, "NotACustomDestination=Version\n");
219 append_str(&ptr, "CustomDestination=CustInstDestSection\n");
220 append_str(&ptr, "[Options.NTx86]\n");
221 append_str(&ptr, "49001=ProgramFilesDir\n");
222 append_str(&ptr, "InstallDir=%%49001%%\\%%DefaultAppPath%%\n");
223 append_str(&ptr, "Result1=%%49010%%\n");
224 append_str(&ptr, "Result2=%%49020%%\n");
225 append_str(&ptr, "Result3=%%49030%%\n");
226 append_str(&ptr, "CustomHDestination=CustInstDestSection\n");
227 append_str(&ptr, "[Strings]\n");
228 append_str(&ptr, "DefaultAppPath=\"Application Name\"\n");
229 append_str(&ptr, "LProgramF=\"%s\"\n", PROG_FILES);
230 append_str(&ptr, "[DestA]\n");
231 append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%\\%%LProgramF%%'\n");
232 append_str(&ptr, "[DestB]\n");
233 append_str(&ptr, "'HKLM','Software\\Microsoft\\Windows\\CurrentVersion',");
234 append_str(&ptr, "'ProgramFilesDir',,\"%%24%%\"\n");
235 append_str(&ptr, "[DestC]\n");
236 append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n");
238 WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
239 CloseHandle(hf);
242 static void translateinfstring_test(void)
244 HRESULT hr;
245 char buffer[MAX_PATH];
246 DWORD dwSize;
248 create_inf_file();
250 /* pass in a couple invalid parameters */
251 hr = pTranslateInfString(NULL, NULL, NULL, NULL, buffer, MAX_PATH, &dwSize, NULL);
252 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", (UINT)hr);
254 /* try to open an inf file that doesn't exist */
255 hr = pTranslateInfString("c:\\a.inf", "Options.NTx86", "Options.NTx86",
256 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
257 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) || hr == E_INVALIDARG ||
258 hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND),
259 "Expected E_INVALIDARG, 0x80070002 or 0x8007007e, got 0x%08x\n", (UINT)hr);
261 if(hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND))
263 trace("WinNT 3.51 detected. Skipping tests for TranslateInfString()\n");
264 return;
267 /* try a nonexistent section */
268 buffer[0] = 0;
269 hr = pTranslateInfString(inf_file, "idontexist", "Options.NTx86",
270 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
271 ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr);
272 ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
273 ok(dwSize == 25, "Expected size 25, got %d\n", dwSize);
275 buffer[0] = 0;
276 /* try other nonexistent section */
277 hr = pTranslateInfString(inf_file, "Options.NTx86", "idontexist",
278 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
279 ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG,
280 "Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr);
282 buffer[0] = 0;
283 /* try nonexistent key */
284 hr = pTranslateInfString(inf_file, "Options.NTx86", "Options.NTx86",
285 "notvalid", buffer, MAX_PATH, &dwSize, NULL);
286 ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG,
287 "Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr);
289 buffer[0] = 0;
290 /* test the behavior of pszInstallSection */
291 hr = pTranslateInfString(inf_file, "section", "Options.NTx86",
292 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
293 ok(hr == ERROR_SUCCESS || hr == E_FAIL,
294 "Expected ERROR_SUCCESS or E_FAIL, got 0x%08x\n", (UINT)hr);
296 if(hr == ERROR_SUCCESS)
298 ok(!strcmp(buffer, APP_PATH), "Expected '%s', got '%s'\n", APP_PATH, buffer);
299 ok(dwSize == APP_PATH_LEN, "Expected size %d, got %d\n", APP_PATH_LEN, dwSize);
302 buffer[0] = 0;
303 /* try without a pszInstallSection */
304 hr = pTranslateInfString(inf_file, NULL, "Options.NTx86",
305 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
306 ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr);
307 todo_wine
309 ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
310 ok(dwSize == 25, "Expected size 25, got %d\n", dwSize);
313 DeleteFile("c:\\a.inf");
314 DeleteFile(inf_file);
317 static void translateinfstringex_test(void)
319 HINF hinf;
320 HRESULT hr;
321 char buffer[MAX_PATH];
322 DWORD size = MAX_PATH;
324 create_inf_file();
326 /* need to see if there are any flags */
328 /* try a NULL filename */
329 hr = pOpenINFEngine(NULL, "Options.NTx86", 0, &hinf, NULL);
330 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
332 /* try an empty filename */
333 hr = pOpenINFEngine("", "Options.NTx86", 0, &hinf, NULL);
334 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
335 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %08x\n", hr);
337 /* try a NULL hinf */
338 hr = pOpenINFEngine(inf_file, "Options.NTx86", 0, NULL, NULL);
339 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
341 /* open the INF without the Install section specified */
342 hr = pOpenINFEngine(inf_file, NULL, 0, &hinf, NULL);
343 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
345 /* try a NULL hinf */
346 hr = pTranslateInfStringEx(NULL, inf_file, "Options.NTx86", "InstallDir",
347 buffer, size, &size, NULL);
348 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
350 /* try a NULL filename */
351 hr = pTranslateInfStringEx(hinf, NULL, "Options.NTx86", "InstallDir",
352 buffer, size, &size, NULL);
353 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
355 /* try an empty filename */
356 memset(buffer, 'a', 25);
357 buffer[24] = '\0';
358 size = MAX_PATH;
359 hr = pTranslateInfStringEx(hinf, "", "Options.NTx86", "InstallDir",
360 buffer, size, &size, NULL);
361 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
362 todo_wine
364 ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
365 ok(size == 25, "Expected size 25, got %d\n", size);
368 /* try a NULL translate section */
369 hr = pTranslateInfStringEx(hinf, inf_file, NULL, "InstallDir",
370 buffer, size, &size, NULL);
371 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
373 /* try an empty translate section */
374 hr = pTranslateInfStringEx(hinf, inf_file, "", "InstallDir",
375 buffer, size, &size, NULL);
376 ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %08x\n", hr);
378 /* try a NULL translate key */
379 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", NULL,
380 buffer, size, &size, NULL);
381 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
383 /* try an empty translate key */
384 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "",
385 buffer, size, &size, NULL);
386 ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %08x\n", hr);
388 /* successfully translate the string */
389 memset(buffer, 'a', 25);
390 buffer[24] = '\0';
391 size = MAX_PATH;
392 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "InstallDir",
393 buffer, size, &size, NULL);
394 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
395 todo_wine
397 ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
398 ok(size == 25, "Expected size 25, got %d\n", size);
401 /* try a NULL hinf */
402 hr = pCloseINFEngine(NULL);
403 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
405 /* successfully close the hinf */
406 hr = pCloseINFEngine(hinf);
407 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
409 /* open the inf with the install section */
410 hr = pOpenINFEngine(inf_file, "section", 0, &hinf, NULL);
411 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
413 /* translate the string with the install section specified */
414 memset(buffer, 'a', APP_PATH_LEN);
415 buffer[APP_PATH_LEN - 1] = '\0';
416 size = MAX_PATH;
417 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "InstallDir",
418 buffer, size, &size, NULL);
419 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
420 ok(!strcmp(buffer, APP_PATH), "Expected %s, got %s\n", APP_PATH, buffer);
421 ok(size == APP_PATH_LEN, "Expected size %d, got %d\n", APP_PATH_LEN, size);
423 /* Single quote test (Note size includes null on return from call) */
424 memset(buffer, 'a', APP_PATH_LEN);
425 buffer[APP_PATH_LEN - 1] = '\0';
426 size = MAX_PATH;
427 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result1",
428 buffer, size, &size, NULL);
429 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
430 ok(!lstrcmpi(buffer, PROG_FILES_ROOT),
431 "Expected %s, got %s\n", PROG_FILES_ROOT, buffer);
432 ok(size == lstrlenA(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n",
433 lstrlenA(PROG_FILES_ROOT)+1, size);
435 memset(buffer, 'a', APP_PATH_LEN);
436 buffer[APP_PATH_LEN - 1] = '\0';
437 size = MAX_PATH;
438 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result2",
439 buffer, size, &size, NULL);
440 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
441 ok(!lstrcmpi(buffer, PROG_FILES_ROOT),
442 "Expected %s, got %s\n", PROG_FILES_ROOT, buffer);
443 ok(size == lstrlenA(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n",
444 lstrlenA(PROG_FILES_ROOT)+1, size);
447 char drive[MAX_PATH];
448 lstrcpy(drive, PROG_FILES_ROOT);
449 drive[3] = 0x00; /* Just keep the system drive plus '\' */
451 memset(buffer, 'a', APP_PATH_LEN);
452 buffer[APP_PATH_LEN - 1] = '\0';
453 size = MAX_PATH;
454 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result3",
455 buffer, size, &size, NULL);
456 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
457 ok(!lstrcmpi(buffer, drive),
458 "Expected %s, got %s\n", drive, buffer);
459 ok(size == lstrlenA(drive)+1, "Expected size %d, got %d\n",
460 lstrlenA(drive)+1, size);
463 /* close the INF again */
464 hr = pCloseINFEngine(hinf);
465 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
467 DeleteFileA(inf_file);
470 static BOOL check_reg_str(HKEY hkey, LPCSTR name, LPCSTR value)
472 DWORD size = MAX_PATH;
473 char check[MAX_PATH];
475 if (RegQueryValueEx(hkey, name, NULL, NULL, (LPBYTE)check, &size))
476 return FALSE;
478 return !lstrcmp(check, value);
481 static BOOL check_reg_dword(HKEY hkey, LPCSTR name, DWORD value)
483 DWORD size = sizeof(DWORD);
484 DWORD check;
486 if (RegQueryValueEx(hkey, name, NULL, NULL, (LPBYTE)&check, &size))
487 return FALSE;
489 return (check == value);
492 static void setperusersecvalues_test(void)
494 PERUSERSECTION peruser;
495 HRESULT hr;
496 HKEY guid;
498 lstrcpy(peruser.szDispName, "displayname");
499 lstrcpy(peruser.szLocale, "locale");
500 lstrcpy(peruser.szStub, "stub");
501 lstrcpy(peruser.szVersion, "1,1,1,1");
502 lstrcpy(peruser.szCompID, "compid");
503 peruser.dwIsInstalled = 1;
504 peruser.bRollback = FALSE;
506 /* try a NULL pPerUser */
507 if (0)
509 /* This crashes on systems with IE7 */
510 hr = pSetPerUserSecValues(NULL);
511 todo_wine
512 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
513 ok(!OPEN_GUID_KEY(), "Expected guid key to not exist\n");
516 /* at the very least, szGUID must be valid */
517 peruser.szGUID[0] = '\0';
518 hr = pSetPerUserSecValues(&peruser);
519 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
520 ok(!OPEN_GUID_KEY(), "Expected guid key to not exist\n");
522 /* set initial values */
523 lstrcpy(peruser.szGUID, "guid");
524 hr = pSetPerUserSecValues(&peruser);
525 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
526 ok(OPEN_GUID_KEY(), "Expected guid key to exist\n");
527 ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
528 ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
529 ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
530 ok(check_reg_str(guid, "StubPath", "stub"), "Expected stub\n");
531 ok(check_reg_str(guid, "Version", "1,1,1,1"), "Expected 1,1,1,1\n");
532 ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
533 ok(!REG_VAL_EXISTS(guid, "OldDisplayName"), "Expected OldDisplayName to not exist\n");
534 ok(!REG_VAL_EXISTS(guid, "OldLocale"), "Expected OldLocale to not exist\n");
535 ok(!REG_VAL_EXISTS(guid, "OldStubPath"), "Expected OldStubPath to not exist\n");
536 ok(!REG_VAL_EXISTS(guid, "OldVersion"), "Expected OldVersion to not exist\n");
537 ok(!REG_VAL_EXISTS(guid, "RealStubPath"), "Expected RealStubPath to not exist\n");
539 /* raise the version, but bRollback is FALSE, so vals not saved */
540 lstrcpy(peruser.szVersion, "2,1,1,1");
541 hr = pSetPerUserSecValues(&peruser);
542 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
543 ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
544 ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
545 ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
546 ok(check_reg_str(guid, "StubPath", "stub"), "Expected stub\n");
547 ok(check_reg_str(guid, "Version", "2,1,1,1"), "Expected 2,1,1,1\n");
548 ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
549 ok(!REG_VAL_EXISTS(guid, "OldDisplayName"), "Expected OldDisplayName to not exist\n");
550 ok(!REG_VAL_EXISTS(guid, "OldLocale"), "Expected OldLocale to not exist\n");
551 ok(!REG_VAL_EXISTS(guid, "OldStubPath"), "Expected OldStubPath to not exist\n");
552 ok(!REG_VAL_EXISTS(guid, "OldVersion"), "Expected OldVersion to not exist\n");
553 ok(!REG_VAL_EXISTS(guid, "RealStubPath"), "Expected RealStubPath to not exist\n");
555 /* raise the version again, bRollback is TRUE so vals are saved */
556 peruser.bRollback = TRUE;
557 lstrcpy(peruser.szVersion, "3,1,1,1");
558 hr = pSetPerUserSecValues(&peruser);
559 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
560 ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
561 ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
562 ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
563 ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
564 ok(check_reg_str(guid, "Version", "3,1,1,1"), "Expected 3,1,1,1\n");
565 todo_wine
567 ok(check_reg_str(guid, "OldDisplayName", "displayname"), "Expected displayname\n");
568 ok(check_reg_str(guid, "OldLocale", "locale"), "Expected locale\n");
569 ok(check_reg_str(guid, "RealStubPath", "stub"), "Expected stub\n");
570 ok(check_reg_str(guid, "OldStubPath", "stub"), "Expected stub\n");
571 ok(check_reg_str(guid, "OldVersion", "2,1,1,1"), "Expected 2,1,1,1\n");
572 ok(check_reg_str(guid, "StubPath",
573 "rundll32.exe advpack.dll,UserInstStubWrapper guid"),
574 "Expected real stub\n");
577 RegDeleteKey(HKEY_LOCAL_MACHINE, GUID_KEY);
580 START_TEST(advpack)
582 if (!init_function_pointers())
583 return;
585 /* Make sure we create the temporary file in a directory
586 * were we have enough rights
588 GetTempPath(MAX_PATH, inf_file);
589 lstrcat(inf_file,"test.inf");
591 get_progfiles_dir();
593 version_test();
594 delnode_test();
595 setperusersecvalues_test();
596 translateinfstring_test();
597 translateinfstringex_test();
599 FreeLibrary(hAdvPack);