setupapi: Remove duplicate backslashes on dirids.
[wine.git] / dlls / advpack / tests / advpack.c
blob4c49e3f4c1386ae9514859930389941ce1155cfc
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 <windows.h>
24 #include <advpub.h>
25 #include <assert.h>
26 #include "wine/test.h"
28 /* defines for the TranslateInfString/Ex tests */
29 #define TEST_STRING1 "\\Application Name"
30 #define TEST_STRING2 "%49001%\\Application Name"
32 /* defines for the SetPerUserSecValues tests */
33 #define GUID_KEY "SOFTWARE\\Microsoft\\Active Setup\\Installed Components\\guid"
34 #define REG_VAL_EXISTS(key, value) !RegQueryValueEx(key, value, NULL, NULL, NULL, NULL)
35 #define OPEN_GUID_KEY() !RegOpenKey(HKEY_LOCAL_MACHINE, GUID_KEY, &guid)
37 static HRESULT (WINAPI *pCloseINFEngine)(HINF);
38 static HRESULT (WINAPI *pDelNode)(LPCSTR,DWORD);
39 static HRESULT (WINAPI *pGetVersionFromFile)(LPCSTR,LPDWORD,LPDWORD,BOOL);
40 static HRESULT (WINAPI *pOpenINFEngine)(PCSTR,PCSTR,DWORD,HINF*,PVOID);
41 static HRESULT (WINAPI *pSetPerUserSecValues)(PPERUSERSECTION pPerUser);
42 static HRESULT (WINAPI *pTranslateInfString)(LPCSTR,LPCSTR,LPCSTR,LPCSTR,LPSTR,DWORD,LPDWORD,LPVOID);
43 static HRESULT (WINAPI *pTranslateInfStringEx)(HINF,PCSTR,PCSTR,PCSTR,PSTR,DWORD,PDWORD,PVOID);
45 static CHAR inf_file[MAX_PATH];
46 static CHAR PROG_FILES_ROOT[MAX_PATH];
47 static CHAR PROG_FILES[MAX_PATH];
48 static DWORD PROG_FILES_LEN;
50 static void get_progfiles_dir(void)
52 HKEY hkey;
53 DWORD size = MAX_PATH;
55 RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", &hkey);
56 RegQueryValueExA(hkey, "ProgramFilesDir", NULL, NULL, (LPBYTE)PROG_FILES_ROOT, &size);
57 RegCloseKey(hkey);
59 lstrcpyA(PROG_FILES, PROG_FILES_ROOT);
60 lstrcatA(PROG_FILES, TEST_STRING1);
61 PROG_FILES_LEN = lstrlenA(PROG_FILES) + 1;
64 static BOOL init_function_pointers(void)
66 HMODULE hAdvPack = LoadLibraryA("advpack.dll");
68 if (!hAdvPack)
69 return FALSE;
71 pCloseINFEngine = (void*)GetProcAddress(hAdvPack, "CloseINFEngine");
72 pDelNode = (void *)GetProcAddress(hAdvPack, "DelNode");
73 pGetVersionFromFile = (void *)GetProcAddress(hAdvPack, "GetVersionFromFile");
74 pOpenINFEngine = (void*)GetProcAddress(hAdvPack, "OpenINFEngine");
75 pSetPerUserSecValues = (void*)GetProcAddress(hAdvPack, "SetPerUserSecValues");
76 pTranslateInfString = (void *)GetProcAddress(hAdvPack, "TranslateInfString");
77 pTranslateInfStringEx = (void*)GetProcAddress(hAdvPack, "TranslateInfStringEx");
79 if (!pCloseINFEngine || !pDelNode || !pGetVersionFromFile ||
80 !pOpenINFEngine || !pSetPerUserSecValues || !pTranslateInfString)
81 return FALSE;
83 return TRUE;
86 static void version_test(void)
88 HRESULT hr;
89 DWORD major, minor;
91 major = minor = 0;
92 hr = pGetVersionFromFile("kernel32.dll", &major, &minor, FALSE);
93 ok (hr == S_OK, "GetVersionFromFileEx(kernel32.dll) failed, returned "
94 "0x%08x\n", hr);
95 trace("kernel32.dll Language ID: 0x%08x, Codepage ID: 0x%08x\n",
96 major, minor);
98 major = minor = 0;
99 hr = pGetVersionFromFile("kernel32.dll", &major, &minor, TRUE);
100 ok (hr == S_OK, "GetVersionFromFileEx(kernel32.dll) failed, returned "
101 "0x%08x\n", hr);
102 trace("kernel32.dll version: %d.%d.%d.%d\n", HIWORD(major), LOWORD(major),
103 HIWORD(minor), LOWORD(minor));
105 major = minor = 0;
106 hr = pGetVersionFromFile("advpack.dll", &major, &minor, FALSE);
107 ok (hr == S_OK, "GetVersionFromFileEx(advpack.dll) failed, returned "
108 "0x%08x\n", hr);
109 trace("advpack.dll Language ID: 0x%08x, Codepage ID: 0x%08x\n",
110 major, minor);
112 major = minor = 0;
113 hr = pGetVersionFromFile("advpack.dll", &major, &minor, TRUE);
114 ok (hr == S_OK, "GetVersionFromFileEx(advpack.dll) failed, returned "
115 "0x%08x\n", hr);
116 trace("advpack.dll version: %d.%d.%d.%d\n", HIWORD(major), LOWORD(major),
117 HIWORD(minor), LOWORD(minor));
120 static void delnode_test(void)
122 HRESULT hr;
123 HANDLE hn;
124 CHAR currDir[MAX_PATH];
125 int currDirLen;
127 /* Native DelNode apparently does not support relative paths, so we use
128 absolute paths for testing */
129 currDirLen = GetCurrentDirectoryA(sizeof(currDir) / sizeof(CHAR), currDir);
130 assert(currDirLen > 0 && currDirLen < sizeof(currDir) / sizeof(CHAR));
132 if(currDir[currDirLen - 1] == '\\')
133 currDir[--currDirLen] = 0;
135 /* Simple tests; these should fail. */
136 hr = pDelNode(NULL, 0);
137 ok (hr == E_FAIL, "DelNode called with NULL pathname should return E_FAIL\n");
138 hr = pDelNode("", 0);
139 ok (hr == E_FAIL, "DelNode called with empty pathname should return E_FAIL\n");
141 /* Test deletion of a file. */
142 hn = CreateFile("DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
143 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
144 assert(hn != INVALID_HANDLE_VALUE);
145 CloseHandle(hn);
146 hr = pDelNode(lstrcat(currDir, "\\DelNodeTestFile1"), 0);
147 ok (hr == S_OK, "DelNode failed deleting a single file\n");
148 currDir[currDirLen] = '\0';
150 /* Test deletion of an empty directory. */
151 CreateDirectoryA("DelNodeTestDir", NULL);
152 hr = pDelNode(lstrcat(currDir, "\\DelNodeTestDir"), 0);
153 ok (hr == S_OK, "DelNode failed deleting an empty directory\n");
154 currDir[currDirLen] = '\0';
156 /* Test deletion of a directory containing one file. */
157 CreateDirectoryA("DelNodeTestDir", NULL);
158 hn = CreateFile("DelNodeTestDir\\DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
159 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
160 assert(hn != INVALID_HANDLE_VALUE);
161 CloseHandle(hn);
162 hr = pDelNode(lstrcat(currDir, "\\DelNodeTestDir"), 0);
163 ok (hr == S_OK, "DelNode failed deleting a directory containing one file\n");
164 currDir[currDirLen] = '\0';
166 /* Test deletion of a directory containing multiple files. */
167 CreateDirectoryA("DelNodeTestDir", NULL);
168 hn = CreateFile("DelNodeTestDir\\DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
169 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
170 assert(hn != INVALID_HANDLE_VALUE);
171 CloseHandle(hn);
172 hn = CreateFile("DelNodeTestDir\\DelNodeTestFile2", GENERIC_WRITE, 0, NULL,
173 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
174 assert(hn != INVALID_HANDLE_VALUE);
175 CloseHandle(hn);
176 hn = CreateFile("DelNodeTestDir\\DelNodeTestFile3", GENERIC_WRITE, 0, NULL,
177 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
178 assert(hn != INVALID_HANDLE_VALUE);
179 CloseHandle(hn);
180 hr = pDelNode(lstrcat(currDir, "\\DelNodeTestDir"), 0);
181 ok (hr == S_OK, "DelNode failed deleting a directory containing multiple files\n");
182 currDir[currDirLen] = '\0';
185 static void append_str(char **str, const char *data)
187 sprintf(*str, data);
188 *str += strlen(*str);
191 static void create_inf_file(void)
193 char data[1024];
194 char *ptr = data;
195 DWORD dwNumberOfBytesWritten;
196 HANDLE hf = CreateFile(inf_file, GENERIC_WRITE, 0, NULL,
197 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
199 append_str(&ptr, "[Version]\n");
200 append_str(&ptr, "Signature=\"$Chicago$\"\n");
201 append_str(&ptr, "[CustInstDestSection]\n");
202 append_str(&ptr, "49001=ProgramFilesDir\n");
203 append_str(&ptr, "49010=DestA,1\n");
204 append_str(&ptr, "49020=DestB\n");
205 append_str(&ptr, "49030=DestC\n");
206 append_str(&ptr, "[ProgramFilesDir]\n");
207 append_str(&ptr, "HKLM,\"Software\\Microsoft\\Windows\\CurrentVersion\",");
208 append_str(&ptr, "\"ProgramFilesDir\",,\"%%24%%\\%%LProgramF%%\"\n");
209 append_str(&ptr, "[section]\n");
210 append_str(&ptr, "NotACustomDestination=Version\n");
211 append_str(&ptr, "CustomDestination=CustInstDestSection\n");
212 append_str(&ptr, "[Options.NTx86]\n");
213 append_str(&ptr, "49001=ProgramFilesDir\n");
214 append_str(&ptr, "InstallDir=%%49001%%\\%%DefaultAppPath%%\n");
215 append_str(&ptr, "Result1=%%49010%%\n");
216 append_str(&ptr, "Result2=%%49020%%\n");
217 append_str(&ptr, "Result3=%%49030%%\n");
218 append_str(&ptr, "CustomHDestination=CustInstDestSection\n");
219 append_str(&ptr, "[Strings]\n");
220 append_str(&ptr, "DefaultAppPath=\"Application Name\"\n");
221 append_str(&ptr, "LProgramF=\"Program Files\"\n");
222 append_str(&ptr, "[DestA]\n");
223 append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%\\%%LProgramF%%'\n");
224 append_str(&ptr, "[DestB]\n");
225 append_str(&ptr, "'HKLM','Software\\Microsoft\\Windows\\CurrentVersion',");
226 append_str(&ptr, "'ProgramFilesDir',,\"%%24%%\"\n");
227 append_str(&ptr, "[DestC]\n");
228 append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n");
230 WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
231 CloseHandle(hf);
234 static void translateinfstring_test(void)
236 HRESULT hr;
237 char buffer[MAX_PATH];
238 DWORD dwSize;
240 create_inf_file();
242 /* pass in a couple invalid parameters */
243 hr = pTranslateInfString(NULL, NULL, NULL, NULL, buffer, MAX_PATH, &dwSize, NULL);
244 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", (UINT)hr);
246 /* try to open an inf file that doesn't exist */
247 hr = pTranslateInfString("c:\\a.inf", "Options.NTx86", "Options.NTx86",
248 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
249 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) || hr == E_INVALIDARG ||
250 hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND),
251 "Expected E_INVALIDARG, 0x80070002 or 0x8007007e, got 0x%08x\n", (UINT)hr);
253 if(hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND))
255 trace("WinNT 3.51 detected. Skipping tests for TranslateInfString()\n");
256 return;
259 /* try a nonexistent section */
260 buffer[0] = 0;
261 hr = pTranslateInfString(inf_file, "idontexist", "Options.NTx86",
262 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
263 ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr);
264 ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
265 ok(dwSize == 25, "Expected size 25, got %d\n", dwSize);
267 buffer[0] = 0;
268 /* try other nonexistent section */
269 hr = pTranslateInfString(inf_file, "Options.NTx86", "idontexist",
270 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
271 ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG,
272 "Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr);
274 buffer[0] = 0;
275 /* try nonexistent key */
276 hr = pTranslateInfString(inf_file, "Options.NTx86", "Options.NTx86",
277 "notvalid", buffer, MAX_PATH, &dwSize, NULL);
278 ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG,
279 "Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr);
281 buffer[0] = 0;
282 /* test the behavior of pszInstallSection */
283 hr = pTranslateInfString(inf_file, "section", "Options.NTx86",
284 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
285 ok(hr == ERROR_SUCCESS || hr == E_FAIL,
286 "Expected ERROR_SUCCESS or E_FAIL, got 0x%08x\n", (UINT)hr);
288 if(hr == ERROR_SUCCESS)
290 ok(!strcmp(buffer, PROG_FILES), "Expected '%s', got '%s'\n", PROG_FILES, buffer);
291 ok(dwSize == PROG_FILES_LEN, "Expected size %d, got %d\n", PROG_FILES_LEN, dwSize);
294 buffer[0] = 0;
295 /* try without a pszInstallSection */
296 hr = pTranslateInfString(inf_file, NULL, "Options.NTx86",
297 "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
298 ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr);
299 todo_wine
301 ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
302 ok(dwSize == 25, "Expected size 25, got %d\n", dwSize);
305 DeleteFile("c:\\a.inf");
306 DeleteFile(inf_file);
309 static void translateinfstringex_test(void)
311 HINF hinf;
312 HRESULT hr;
313 char buffer[MAX_PATH];
314 DWORD size = MAX_PATH;
316 create_inf_file();
318 /* need to see if there are any flags */
320 /* try a NULL filename */
321 hr = pOpenINFEngine(NULL, "Options.NTx86", 0, &hinf, NULL);
322 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
324 /* try an empty filename */
325 hr = pOpenINFEngine("", "Options.NTx86", 0, &hinf, NULL);
326 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
327 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %08x\n", hr);
329 /* try a NULL hinf */
330 hr = pOpenINFEngine(inf_file, "Options.NTx86", 0, NULL, NULL);
331 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
333 /* open the INF without the Install section specified */
334 hr = pOpenINFEngine(inf_file, NULL, 0, &hinf, NULL);
335 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
337 /* try a NULL hinf */
338 hr = pTranslateInfStringEx(NULL, inf_file, "Options.NTx86", "InstallDir",
339 buffer, size, &size, NULL);
340 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
342 /* try a NULL filename */
343 hr = pTranslateInfStringEx(hinf, NULL, "Options.NTx86", "InstallDir",
344 buffer, size, &size, NULL);
345 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
347 /* try an empty filename */
348 memset(buffer, 'a', 25);
349 buffer[24] = '\0';
350 size = MAX_PATH;
351 hr = pTranslateInfStringEx(hinf, "", "Options.NTx86", "InstallDir",
352 buffer, size, &size, NULL);
353 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
354 todo_wine
356 ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
357 ok(size == 25, "Expected size 25, got %d\n", size);
360 /* try a NULL translate section */
361 hr = pTranslateInfStringEx(hinf, inf_file, NULL, "InstallDir",
362 buffer, size, &size, NULL);
363 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
365 /* try an empty translate section */
366 hr = pTranslateInfStringEx(hinf, inf_file, "", "InstallDir",
367 buffer, size, &size, NULL);
368 ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %08x\n", hr);
370 /* try a NULL translate key */
371 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", NULL,
372 buffer, size, &size, NULL);
373 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
375 /* try an empty translate key */
376 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "",
377 buffer, size, &size, NULL);
378 ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %08x\n", hr);
380 /* successfully translate the string */
381 memset(buffer, 'a', 25);
382 buffer[24] = '\0';
383 size = MAX_PATH;
384 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "InstallDir",
385 buffer, size, &size, NULL);
386 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
387 todo_wine
389 ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
390 ok(size == 25, "Expected size 25, got %d\n", size);
393 /* try a NULL hinf */
394 hr = pCloseINFEngine(NULL);
395 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
397 /* successfully close the hinf */
398 hr = pCloseINFEngine(hinf);
399 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
401 /* open the inf with the install section */
402 hr = pOpenINFEngine(inf_file, "section", 0, &hinf, NULL);
403 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
405 /* translate the string with the install section specified */
406 memset(buffer, 'a', PROG_FILES_LEN);
407 buffer[PROG_FILES_LEN - 1] = '\0';
408 size = MAX_PATH;
409 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "InstallDir",
410 buffer, size, &size, NULL);
411 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
412 ok(!strcmp(buffer, PROG_FILES), "Expected %s, got %s\n", PROG_FILES, buffer);
413 ok(size == PROG_FILES_LEN, "Expected size %d, got %d\n", PROG_FILES_LEN, size);
415 /* Single quote test (Note size includes null on return from call) */
416 memset(buffer, 'a', PROG_FILES_LEN);
417 buffer[PROG_FILES_LEN - 1] = '\0';
418 size = MAX_PATH;
419 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result1",
420 buffer, size, &size, NULL);
421 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
422 ok(!lstrcmpi(buffer, PROG_FILES_ROOT),
423 "Expected %s, got %s\n", PROG_FILES_ROOT, buffer);
424 ok(size == lstrlenA(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n",
425 lstrlenA(PROG_FILES_ROOT)+1, size);
427 memset(buffer, 'a', PROG_FILES_LEN);
428 buffer[PROG_FILES_LEN - 1] = '\0';
429 size = MAX_PATH;
430 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result2",
431 buffer, size, &size, NULL);
432 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
433 ok(!lstrcmpi(buffer, PROG_FILES_ROOT),
434 "Expected %s, got %s\n", PROG_FILES_ROOT, buffer);
435 ok(size == lstrlenA(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n",
436 lstrlenA(PROG_FILES_ROOT)+1, size);
439 char drive[MAX_PATH];
440 lstrcpy(drive, PROG_FILES_ROOT);
441 drive[3] = 0x00; /* Just keep the system drive plus '\' */
443 memset(buffer, 'a', PROG_FILES_LEN);
444 buffer[PROG_FILES_LEN - 1] = '\0';
445 size = MAX_PATH;
446 hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result3",
447 buffer, size, &size, NULL);
448 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
449 ok(!lstrcmpi(buffer, drive),
450 "Expected %s, got %s\n", drive, buffer);
451 ok(size == lstrlenA(drive)+1, "Expected size %d, got %d\n",
452 lstrlenA(drive)+1, size);
455 /* close the INF again */
456 hr = pCloseINFEngine(hinf);
457 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
459 DeleteFileA(inf_file);
462 static BOOL check_reg_str(HKEY hkey, LPCSTR name, LPCSTR value)
464 DWORD size = MAX_PATH;
465 char check[MAX_PATH];
467 if (RegQueryValueEx(hkey, name, NULL, NULL, (LPBYTE)check, &size))
468 return FALSE;
470 return !lstrcmp(check, value);
473 static BOOL check_reg_dword(HKEY hkey, LPCSTR name, DWORD value)
475 DWORD size = sizeof(DWORD);
476 DWORD check;
478 if (RegQueryValueEx(hkey, name, NULL, NULL, (LPBYTE)&check, &size))
479 return FALSE;
481 return (check == value);
484 static void setperusersecvalues_test(void)
486 PERUSERSECTION peruser;
487 HRESULT hr;
488 HKEY guid;
490 lstrcpy(peruser.szDispName, "displayname");
491 lstrcpy(peruser.szLocale, "locale");
492 lstrcpy(peruser.szStub, "stub");
493 lstrcpy(peruser.szVersion, "1,1,1,1");
494 lstrcpy(peruser.szCompID, "compid");
495 peruser.dwIsInstalled = 1;
496 peruser.bRollback = FALSE;
498 /* try a NULL pPerUser */
499 if (0)
501 /* This crashes on systems with IE7 */
502 hr = pSetPerUserSecValues(NULL);
503 todo_wine
504 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
505 ok(!OPEN_GUID_KEY(), "Expected guid key to not exist\n");
508 /* at the very least, szGUID must be valid */
509 peruser.szGUID[0] = '\0';
510 hr = pSetPerUserSecValues(&peruser);
511 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
512 ok(!OPEN_GUID_KEY(), "Expected guid key to not exist\n");
514 /* set initial values */
515 lstrcpy(peruser.szGUID, "guid");
516 hr = pSetPerUserSecValues(&peruser);
517 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
518 ok(OPEN_GUID_KEY(), "Expected guid key to exist\n");
519 ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
520 ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
521 ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
522 ok(check_reg_str(guid, "StubPath", "stub"), "Expected stub\n");
523 ok(check_reg_str(guid, "Version", "1,1,1,1"), "Expected 1,1,1,1\n");
524 ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
525 ok(!REG_VAL_EXISTS(guid, "OldDisplayName"), "Expected OldDisplayName to not exist\n");
526 ok(!REG_VAL_EXISTS(guid, "OldLocale"), "Expected OldLocale to not exist\n");
527 ok(!REG_VAL_EXISTS(guid, "OldStubPath"), "Expected OldStubPath to not exist\n");
528 ok(!REG_VAL_EXISTS(guid, "OldVersion"), "Expected OldVersion to not exist\n");
529 ok(!REG_VAL_EXISTS(guid, "RealStubPath"), "Expected RealStubPath to not exist\n");
531 /* raise the version, but bRollback is FALSE, so vals not saved */
532 lstrcpy(peruser.szVersion, "2,1,1,1");
533 hr = pSetPerUserSecValues(&peruser);
534 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
535 ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
536 ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
537 ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
538 ok(check_reg_str(guid, "StubPath", "stub"), "Expected stub\n");
539 ok(check_reg_str(guid, "Version", "2,1,1,1"), "Expected 2,1,1,1\n");
540 ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
541 ok(!REG_VAL_EXISTS(guid, "OldDisplayName"), "Expected OldDisplayName to not exist\n");
542 ok(!REG_VAL_EXISTS(guid, "OldLocale"), "Expected OldLocale to not exist\n");
543 ok(!REG_VAL_EXISTS(guid, "OldStubPath"), "Expected OldStubPath to not exist\n");
544 ok(!REG_VAL_EXISTS(guid, "OldVersion"), "Expected OldVersion to not exist\n");
545 ok(!REG_VAL_EXISTS(guid, "RealStubPath"), "Expected RealStubPath to not exist\n");
547 /* raise the version again, bRollback is TRUE so vals are saved */
548 peruser.bRollback = TRUE;
549 lstrcpy(peruser.szVersion, "3,1,1,1");
550 hr = pSetPerUserSecValues(&peruser);
551 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
552 ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
553 ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
554 ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
555 ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
556 ok(check_reg_str(guid, "Version", "3,1,1,1"), "Expected 3,1,1,1\n");
557 todo_wine
559 ok(check_reg_str(guid, "OldDisplayName", "displayname"), "Expected displayname\n");
560 ok(check_reg_str(guid, "OldLocale", "locale"), "Expected locale\n");
561 ok(check_reg_str(guid, "RealStubPath", "stub"), "Expected stub\n");
562 ok(check_reg_str(guid, "OldStubPath", "stub"), "Expected stub\n");
563 ok(check_reg_str(guid, "OldVersion", "2,1,1,1"), "Expected 2,1,1,1\n");
564 ok(check_reg_str(guid, "StubPath",
565 "rundll32.exe advpack.dll,UserInstStubWrapper guid"),
566 "Expected real stub\n");
569 RegDeleteKey(HKEY_LOCAL_MACHINE, GUID_KEY);
572 START_TEST(advpack)
574 if (!init_function_pointers())
575 return;
577 /* Make sure we create the temporary file in a directory
578 * were we have enough rights
580 GetTempPath(MAX_PATH, inf_file);
581 lstrcat(inf_file,"test.inf");
583 get_progfiles_dir();
585 version_test();
586 delnode_test();
587 setperusersecvalues_test();
588 translateinfstring_test();
589 translateinfstringex_test();