wintrust: Add a helper function to initialize chain creation parameters.
[wine] / dlls / advpack / tests / advpack.c
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 <windows.h>
24 #include <advpub.h>
25 #include <assert.h>
26 #include "wine/test.h"
27
28 /* defines for the TranslateInfString/Ex tests */
29 #define TEST_STRING1 "\\Application Name"
30 #define TEST_STRING2 "%49001%\\Application Name"
31
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)
36
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);
44
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;
49
50 static void get_progfiles_dir(void)
51 {
52     HKEY hkey;
53     DWORD size = MAX_PATH;
54
55     RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", &hkey);
56     RegQueryValueExA(hkey, "ProgramFilesDir", NULL, NULL, (LPBYTE)PROG_FILES_ROOT, &size);
57     RegCloseKey(hkey);
58
59     lstrcpyA(PROG_FILES, PROG_FILES_ROOT);
60     lstrcatA(PROG_FILES, TEST_STRING1);
61     PROG_FILES_LEN = lstrlenA(PROG_FILES) + 1;
62 }
63
64 static BOOL init_function_pointers(void)
65 {
66     HMODULE hAdvPack = LoadLibraryA("advpack.dll");
67
68     if (!hAdvPack)
69         return FALSE;
70
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");
78
79     if (!pCloseINFEngine || !pDelNode || !pGetVersionFromFile ||
80         !pOpenINFEngine || !pSetPerUserSecValues || !pTranslateInfString)
81         return FALSE;
82
83     return TRUE;
84 }
85
86 static void version_test(void)
87 {
88     HRESULT hr;
89     DWORD major, minor;
90
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);
97
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));
104
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);
111
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));
118 }
119
120 static void delnode_test(void)
121 {
122     HRESULT hr;
123     HANDLE hn;
124     CHAR currDir[MAX_PATH];
125     int currDirLen;
126
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));
131
132     if(currDir[currDirLen - 1] == '\\')
133         currDir[--currDirLen] = 0;
134
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");
140
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';
149
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';
155
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';
165
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';
183 }
184
185 static void append_str(char **str, const char *data)
186 {
187     sprintf(*str, data);
188     *str += strlen(*str);
189 }
190
191 static void create_inf_file(void)
192 {
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);
198
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%%\\%%16422%%\"\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, "[DestA]\n");
222     append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%16422%%'\n");
223     append_str(&ptr, "[DestB]\n");
224     append_str(&ptr, "'HKLM','Software\\Microsoft\\Windows\\CurrentVersion',");
225     append_str(&ptr, "'ProgramFilesDir',,\"%%24%%\"\n");
226     append_str(&ptr, "[DestC]\n");
227     append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n");
228
229     WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
230     CloseHandle(hf);
231 }
232
233 static void translateinfstring_test(void)
234 {
235     HRESULT hr;
236     char buffer[MAX_PATH];
237     DWORD dwSize;
238
239     create_inf_file();
240
241     /* pass in a couple invalid parameters */
242     hr = pTranslateInfString(NULL, NULL, NULL, NULL, buffer, MAX_PATH, &dwSize, NULL);
243     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", (UINT)hr);
244
245     /* try to open an inf file that doesn't exist */
246     hr = pTranslateInfString("c:\\a.inf", "Options.NTx86", "Options.NTx86",
247                              "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
248     ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) || hr == E_INVALIDARG || 
249        hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND), 
250        "Expected E_INVALIDARG, 0x80070002 or 0x8007007e, got 0x%08x\n", (UINT)hr);
251
252     if(hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND))
253     {
254         trace("WinNT 3.51 detected. Skipping tests for TranslateInfString()\n");
255         return;
256     }
257
258     /* try a nonexistent section */
259     buffer[0] = 0;
260     hr = pTranslateInfString(inf_file, "idontexist", "Options.NTx86",
261                              "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
262     ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr);
263     ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
264     ok(dwSize == 25, "Expected size 25, got %d\n", dwSize);
265
266     buffer[0] = 0;
267     /* try other nonexistent section */
268     hr = pTranslateInfString(inf_file, "Options.NTx86", "idontexist",
269                              "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
270     ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG, 
271        "Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr);
272
273     buffer[0] = 0;
274     /* try nonexistent key */
275     hr = pTranslateInfString(inf_file, "Options.NTx86", "Options.NTx86",
276                              "notvalid", buffer, MAX_PATH, &dwSize, NULL);
277     ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG, 
278        "Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr);
279
280     buffer[0] = 0;
281     /* test the behavior of pszInstallSection */
282     hr = pTranslateInfString(inf_file, "section", "Options.NTx86",
283                              "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
284     ok(hr == ERROR_SUCCESS || hr == E_FAIL, 
285        "Expected ERROR_SUCCESS or E_FAIL, got 0x%08x\n", (UINT)hr);
286
287     if(hr == ERROR_SUCCESS)
288     {
289         ok(!strcmp(buffer, PROG_FILES), "Expected '%s', got '%s'\n", PROG_FILES, buffer);
290         ok(dwSize == PROG_FILES_LEN, "Expected size %d, got %d\n", PROG_FILES_LEN, dwSize);
291     }
292
293     buffer[0] = 0;
294     /* try without a pszInstallSection */
295     hr = pTranslateInfString(inf_file, NULL, "Options.NTx86",
296                              "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
297     ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr);
298     todo_wine
299     {
300         ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
301         ok(dwSize == 25, "Expected size 25, got %d\n", dwSize);
302     }
303
304     DeleteFile("c:\\a.inf");
305     DeleteFile(inf_file);
306 }
307
308 static void translateinfstringex_test(void)
309 {
310     HINF hinf;
311     HRESULT hr;
312     char buffer[MAX_PATH];
313     DWORD size = MAX_PATH;
314
315     create_inf_file();
316     
317     /* need to see if there are any flags */
318
319     /* try a NULL filename */
320     hr = pOpenINFEngine(NULL, "Options.NTx86", 0, &hinf, NULL);
321     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
322
323     /* try an empty filename */
324     hr = pOpenINFEngine("", "Options.NTx86", 0, &hinf, NULL);
325     ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
326         "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %08x\n", hr);
327
328     /* try a NULL hinf */
329     hr = pOpenINFEngine(inf_file, "Options.NTx86", 0, NULL, NULL);
330     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
331
332     /* open the INF without the Install section specified */
333     hr = pOpenINFEngine(inf_file, NULL, 0, &hinf, NULL);
334     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
335
336     /* try a NULL hinf */
337     hr = pTranslateInfStringEx(NULL, inf_file, "Options.NTx86", "InstallDir",
338                               buffer, size, &size, NULL);
339     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
340
341     /* try a NULL filename */
342     hr = pTranslateInfStringEx(hinf, NULL, "Options.NTx86", "InstallDir",
343                               buffer, size, &size, NULL);
344     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
345
346     /* try an empty filename */
347     memset(buffer, 'a', 25);
348     buffer[24] = '\0';
349     size = MAX_PATH;
350     hr = pTranslateInfStringEx(hinf, "", "Options.NTx86", "InstallDir",
351                               buffer, size, &size, NULL);
352     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
353     todo_wine
354     {
355         ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
356         ok(size == 25, "Expected size 25, got %d\n", size);
357     }
358
359     /* try a NULL translate section */
360     hr = pTranslateInfStringEx(hinf, inf_file, NULL, "InstallDir",
361                               buffer, size, &size, NULL);
362     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
363
364     /* try an empty translate section */
365     hr = pTranslateInfStringEx(hinf, inf_file, "", "InstallDir",
366                               buffer, size, &size, NULL);
367     ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %08x\n", hr);
368
369     /* try a NULL translate key */
370     hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", NULL,
371                               buffer, size, &size, NULL);
372     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
373
374     /* try an empty translate key */
375     hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "",
376                               buffer, size, &size, NULL);
377     ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %08x\n", hr);
378
379     /* successfully translate the string */
380     memset(buffer, 'a', 25);
381     buffer[24] = '\0';
382     size = MAX_PATH;
383     hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "InstallDir",
384                               buffer, size, &size, NULL);
385     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
386     todo_wine
387     {
388         ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
389         ok(size == 25, "Expected size 25, got %d\n", size);
390     }
391
392     /* try a NULL hinf */
393     hr = pCloseINFEngine(NULL);
394     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
395
396     /* successfully close the hinf */
397     hr = pCloseINFEngine(hinf);
398     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
399
400     /* open the inf with the install section */
401     hr = pOpenINFEngine(inf_file, "section", 0, &hinf, NULL);
402     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
403
404     /* translate the string with the install section specified */
405     memset(buffer, 'a', PROG_FILES_LEN);
406     buffer[PROG_FILES_LEN - 1] = '\0';
407     size = MAX_PATH;
408     hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "InstallDir",
409                               buffer, size, &size, NULL);
410     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
411     ok(!strcmp(buffer, PROG_FILES), "Expected %s, got %s\n", PROG_FILES, buffer);
412     ok(size == PROG_FILES_LEN, "Expected size %d, got %d\n", PROG_FILES_LEN, size);
413
414     /* Single quote test (Note size includes null on return from call) */
415     memset(buffer, 'a', PROG_FILES_LEN);
416     buffer[PROG_FILES_LEN - 1] = '\0';
417     size = MAX_PATH;
418     hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result1",
419                               buffer, size, &size, NULL);
420     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
421     ok(!lstrcmpi(buffer, PROG_FILES_ROOT),
422            "Expected %s, got %s\n", PROG_FILES_ROOT, buffer);
423     ok(size == lstrlenA(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n",
424            lstrlenA(PROG_FILES_ROOT)+1, size);
425
426     memset(buffer, 'a', PROG_FILES_LEN);
427     buffer[PROG_FILES_LEN - 1] = '\0';
428     size = MAX_PATH;
429     hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result2",
430                               buffer, size, &size, NULL);
431     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
432     ok(!lstrcmpi(buffer, PROG_FILES_ROOT),
433            "Expected %s, got %s\n", PROG_FILES_ROOT, buffer);
434     ok(size == lstrlenA(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n",
435            lstrlenA(PROG_FILES_ROOT)+1, size);
436
437     {
438         char drive[MAX_PATH];
439         lstrcpy(drive, PROG_FILES_ROOT);
440         drive[3] = 0x00; /* Just keep the system drive plus '\' */
441
442         memset(buffer, 'a', PROG_FILES_LEN);
443         buffer[PROG_FILES_LEN - 1] = '\0';
444         size = MAX_PATH;
445         hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result3",
446                                   buffer, size, &size, NULL);
447         ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
448         ok(!lstrcmpi(buffer, drive),
449                "Expected %s, got %s\n", drive, buffer);
450         ok(size == lstrlenA(drive)+1, "Expected size %d, got %d\n",
451                lstrlenA(drive)+1, size);
452     }
453
454     /* close the INF again */
455     hr = pCloseINFEngine(hinf);
456     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
457
458     DeleteFileA(inf_file);
459 }
460
461 static BOOL check_reg_str(HKEY hkey, LPCSTR name, LPCSTR value)
462 {
463     DWORD size = MAX_PATH;
464     char check[MAX_PATH];
465
466     if (RegQueryValueEx(hkey, name, NULL, NULL, (LPBYTE)check, &size))
467         return FALSE;
468
469     return !lstrcmp(check, value);
470 }
471
472 static BOOL check_reg_dword(HKEY hkey, LPCSTR name, DWORD value)
473 {
474     DWORD size = sizeof(DWORD);
475     DWORD check;
476
477     if (RegQueryValueEx(hkey, name, NULL, NULL, (LPBYTE)&check, &size))
478         return FALSE;
479
480     return (check == value);
481 }
482
483 static void setperusersecvalues_test(void)
484 {
485     PERUSERSECTION peruser;
486     HRESULT hr;
487     HKEY guid;
488
489     lstrcpy(peruser.szDispName, "displayname");
490     lstrcpy(peruser.szLocale, "locale");
491     lstrcpy(peruser.szStub, "stub");
492     lstrcpy(peruser.szVersion, "1,1,1,1");
493     lstrcpy(peruser.szCompID, "compid");
494     peruser.dwIsInstalled = 1;
495     peruser.bRollback = FALSE;
496
497     /* try a NULL pPerUser */
498     if (0)
499     {
500         /* This crashes on systems with IE7 */
501         hr = pSetPerUserSecValues(NULL);
502         todo_wine
503         ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
504         ok(!OPEN_GUID_KEY(), "Expected guid key to not exist\n");
505     }
506
507     /* at the very least, szGUID must be valid */
508     peruser.szGUID[0] = '\0';
509     hr = pSetPerUserSecValues(&peruser);
510     ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
511     ok(!OPEN_GUID_KEY(), "Expected guid key to not exist\n");
512
513     /* set initial values */
514     lstrcpy(peruser.szGUID, "guid");
515     hr = pSetPerUserSecValues(&peruser);
516     ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
517     ok(OPEN_GUID_KEY(), "Expected guid key to exist\n");
518     ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
519     ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
520     ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
521     ok(check_reg_str(guid, "StubPath", "stub"), "Expected stub\n");
522     ok(check_reg_str(guid, "Version", "1,1,1,1"), "Expected 1,1,1,1\n");
523     ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
524     ok(!REG_VAL_EXISTS(guid, "OldDisplayName"), "Expected OldDisplayName to not exist\n");
525     ok(!REG_VAL_EXISTS(guid, "OldLocale"), "Expected OldLocale to not exist\n");
526     ok(!REG_VAL_EXISTS(guid, "OldStubPath"), "Expected OldStubPath to not exist\n");
527     ok(!REG_VAL_EXISTS(guid, "OldVersion"), "Expected OldVersion to not exist\n");
528     ok(!REG_VAL_EXISTS(guid, "RealStubPath"), "Expected RealStubPath to not exist\n");
529
530     /* raise the version, but bRollback is FALSE, so vals not saved */
531     lstrcpy(peruser.szVersion, "2,1,1,1");
532     hr = pSetPerUserSecValues(&peruser);
533     ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
534     ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
535     ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
536     ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
537     ok(check_reg_str(guid, "StubPath", "stub"), "Expected stub\n");
538     ok(check_reg_str(guid, "Version", "2,1,1,1"), "Expected 2,1,1,1\n");
539     ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
540     ok(!REG_VAL_EXISTS(guid, "OldDisplayName"), "Expected OldDisplayName to not exist\n");
541     ok(!REG_VAL_EXISTS(guid, "OldLocale"), "Expected OldLocale to not exist\n");
542     ok(!REG_VAL_EXISTS(guid, "OldStubPath"), "Expected OldStubPath to not exist\n");
543     ok(!REG_VAL_EXISTS(guid, "OldVersion"), "Expected OldVersion to not exist\n");
544     ok(!REG_VAL_EXISTS(guid, "RealStubPath"), "Expected RealStubPath to not exist\n");
545
546     /* raise the version again, bRollback is TRUE so vals are saved */
547     peruser.bRollback = TRUE;
548     lstrcpy(peruser.szVersion, "3,1,1,1");
549     hr = pSetPerUserSecValues(&peruser);
550     ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
551     ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
552     ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
553     ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
554     ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
555     ok(check_reg_str(guid, "Version", "3,1,1,1"), "Expected 3,1,1,1\n");
556     todo_wine
557     {
558         ok(check_reg_str(guid, "OldDisplayName", "displayname"), "Expected displayname\n");
559         ok(check_reg_str(guid, "OldLocale", "locale"), "Expected locale\n");
560         ok(check_reg_str(guid, "RealStubPath", "stub"), "Expected stub\n");
561         ok(check_reg_str(guid, "OldStubPath", "stub"), "Expected stub\n");
562         ok(check_reg_str(guid, "OldVersion", "2,1,1,1"), "Expected 2,1,1,1\n");
563         ok(check_reg_str(guid, "StubPath",
564            "rundll32.exe advpack.dll,UserInstStubWrapper guid"),
565            "Expected real stub\n");
566     }
567
568     RegDeleteKey(HKEY_LOCAL_MACHINE, GUID_KEY);
569 }
570
571 START_TEST(advpack)
572 {
573     if (!init_function_pointers())
574         return;
575
576     /* Make sure we create the temporary file in a directory
577      * were we have enough rights
578      */
579     GetTempPath(MAX_PATH, inf_file);
580     lstrcat(inf_file,"test.inf");
581
582     get_progfiles_dir();
583
584     version_test();
585     delnode_test();
586     setperusersecvalues_test();
587     translateinfstring_test();
588     translateinfstringex_test();
589 }