ole32: Make the virtual table functions static where possible.
[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)(LPSTR,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)(LPSTR,LPSTR,LPSTR,LPSTR,LPSTR,DWORD,LPDWORD,LPVOID);
43 static HRESULT (WINAPI *pTranslateInfStringEx)(HINF,PCSTR,PCSTR,PCSTR,PSTR,DWORD,PDWORD,PVOID);
44
45 static CHAR PROG_FILES[MAX_PATH];
46 static DWORD PROG_FILES_LEN;
47
48 static void get_progfiles_dir(void)
49 {
50     HKEY hkey;
51     DWORD size = MAX_PATH;
52
53     RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", &hkey);
54     RegQueryValueExA(hkey, "ProgramFilesDir", NULL, NULL, (LPBYTE)PROG_FILES, &size);
55     RegCloseKey(hkey);
56
57     lstrcatA(PROG_FILES, TEST_STRING1);
58     PROG_FILES_LEN = lstrlenA(PROG_FILES) + 1;
59 }
60
61 static BOOL init_function_pointers(void)
62 {
63     HMODULE hAdvPack = LoadLibraryA("advpack.dll");
64
65     if (!hAdvPack)
66         return FALSE;
67
68     pCloseINFEngine = (void*)GetProcAddress(hAdvPack, "CloseINFEngine");
69     pDelNode = (void *)GetProcAddress(hAdvPack, "DelNode");
70     pGetVersionFromFile = (void *)GetProcAddress(hAdvPack, "GetVersionFromFile");
71     pOpenINFEngine = (void*)GetProcAddress(hAdvPack, "OpenINFEngine");
72     pSetPerUserSecValues = (void*)GetProcAddress(hAdvPack, "SetPerUserSecValues");
73     pTranslateInfString = (void *)GetProcAddress(hAdvPack, "TranslateInfString");
74     pTranslateInfStringEx = (void*)GetProcAddress(hAdvPack, "TranslateInfStringEx");
75
76     if (!pCloseINFEngine || !pDelNode || !pGetVersionFromFile ||
77         !pOpenINFEngine || !pSetPerUserSecValues || !pTranslateInfString)
78         return FALSE;
79
80     return TRUE;
81 }
82
83 static void version_test(void)
84 {
85     HRESULT hr;
86     DWORD major, minor;
87
88     major = minor = 0;
89     hr = pGetVersionFromFile("kernel32.dll", &major, &minor, FALSE);
90     ok (hr == S_OK, "GetVersionFromFileEx(kernel32.dll) failed, returned "
91         "0x%08lx\n", hr);
92     trace("kernel32.dll Language ID: 0x%08lx, Codepage ID: 0x%08lx\n",
93            major, minor);
94
95     major = minor = 0;
96     hr = pGetVersionFromFile("kernel32.dll", &major, &minor, TRUE);
97     ok (hr == S_OK, "GetVersionFromFileEx(kernel32.dll) failed, returned "
98         "0x%08lx\n", hr);
99     trace("kernel32.dll version: %d.%d.%d.%d\n", HIWORD(major), LOWORD(major),
100           HIWORD(minor), LOWORD(minor));
101
102     major = minor = 0;
103     hr = pGetVersionFromFile("advpack.dll", &major, &minor, FALSE);
104     ok (hr == S_OK, "GetVersionFromFileEx(advpack.dll) failed, returned "
105         "0x%08lx\n", hr);
106     trace("advpack.dll Language ID: 0x%08lx, Codepage ID: 0x%08lx\n",
107            major, minor);
108
109     major = minor = 0;
110     hr = pGetVersionFromFile("advpack.dll", &major, &minor, TRUE);
111     ok (hr == S_OK, "GetVersionFromFileEx(advpack.dll) failed, returned "
112         "0x%08lx\n", hr);
113     trace("advpack.dll version: %d.%d.%d.%d\n", HIWORD(major), LOWORD(major),
114           HIWORD(minor), LOWORD(minor));
115 }
116
117 static void delnode_test(void)
118 {
119     HRESULT hr;
120     HANDLE hn;
121     CHAR currDir[MAX_PATH];
122     int currDirLen;
123
124     /* Native DelNode apparently does not support relative paths, so we use
125        absolute paths for testing */
126     currDirLen = GetCurrentDirectoryA(sizeof(currDir) / sizeof(CHAR), currDir);
127     assert(currDirLen > 0 && currDirLen < sizeof(currDir) / sizeof(CHAR));
128
129     if(currDir[currDirLen - 1] == '\\')
130         currDir[--currDirLen] = 0;
131
132     /* Simple tests; these should fail. */
133     hr = pDelNode(NULL, 0);
134     ok (hr == E_FAIL, "DelNode called with NULL pathname should return E_FAIL\n");
135     hr = pDelNode("", 0);
136     ok (hr == E_FAIL, "DelNode called with empty pathname should return E_FAIL\n");
137
138     /* Test deletion of a file. */
139     hn = CreateFile("DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
140         CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
141     assert(hn != INVALID_HANDLE_VALUE);
142     CloseHandle(hn);
143     hr = pDelNode(lstrcat(currDir, "\\DelNodeTestFile1"), 0);
144     ok (hr == S_OK, "DelNode failed deleting a single file\n");
145     currDir[currDirLen] = '\0';
146
147     /* Test deletion of an empty directory. */
148     CreateDirectoryA("DelNodeTestDir", NULL);
149     hr = pDelNode(lstrcat(currDir, "\\DelNodeTestDir"), 0);
150     ok (hr == S_OK, "DelNode failed deleting an empty directory\n");
151     currDir[currDirLen] = '\0';
152
153     /* Test deletion of a directory containing one file. */
154     CreateDirectoryA("DelNodeTestDir", NULL);
155     hn = CreateFile("DelNodeTestDir\\DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
156         CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
157     assert(hn != INVALID_HANDLE_VALUE);
158     CloseHandle(hn);
159     hr = pDelNode(lstrcat(currDir, "\\DelNodeTestDir"), 0);
160     ok (hr == S_OK, "DelNode failed deleting a directory containing one file\n");
161     currDir[currDirLen] = '\0';
162
163     /* Test deletion of a directory containing multiple files. */
164     CreateDirectoryA("DelNodeTestDir", NULL);
165     hn = CreateFile("DelNodeTestDir\\DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
166         CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
167     assert(hn != INVALID_HANDLE_VALUE);
168     CloseHandle(hn);
169     hn = CreateFile("DelNodeTestDir\\DelNodeTestFile2", GENERIC_WRITE, 0, NULL,
170         CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
171     assert(hn != INVALID_HANDLE_VALUE);
172     CloseHandle(hn);
173     hn = CreateFile("DelNodeTestDir\\DelNodeTestFile3", GENERIC_WRITE, 0, NULL,
174         CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
175     assert(hn != INVALID_HANDLE_VALUE);
176     CloseHandle(hn);
177     hr = pDelNode(lstrcat(currDir, "\\DelNodeTestDir"), 0);
178     ok (hr == S_OK, "DelNode failed deleting a directory containing multiple files\n");
179     currDir[currDirLen] = '\0';
180 }
181
182 static void append_str(char **str, const char *data)
183 {
184     sprintf(*str, data);
185     *str += strlen(*str);
186 }
187
188 static void create_inf_file()
189 {
190     char data[1024];
191     char *ptr = data;
192     DWORD dwNumberOfBytesWritten;
193     HANDLE hf = CreateFile("c:\\test.inf", GENERIC_WRITE, 0, NULL,
194                            CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
195
196     append_str(&ptr, "[Version]\n");
197     append_str(&ptr, "Signature=\"$Chicago$\"\n");
198     append_str(&ptr, "[CustInstDestSection]\n");
199     append_str(&ptr, "49001=ProgramFilesDir\n");
200     append_str(&ptr, "[ProgramFilesDir]\n");
201     append_str(&ptr, "HKLM,\"Software\\Microsoft\\Windows\\CurrentVersion\",");
202     append_str(&ptr, "\"ProgramFilesDir\",,\"%%24%%\\%%LProgramF%%\"\n");
203     append_str(&ptr, "[section]\n");
204     append_str(&ptr, "NotACustomDestination=Version\n");
205     append_str(&ptr, "CustomDestination=CustInstDestSection\n");
206     append_str(&ptr, "[Options.NTx86]\n");
207     append_str(&ptr, "49001=ProgramFilesDir\n");
208     append_str(&ptr, "InstallDir=%%49001%%\\%%DefaultAppPath%%\n");
209     append_str(&ptr, "CustomHDestination=CustInstDestSection\n");
210     append_str(&ptr, "[Strings]\n");
211     append_str(&ptr, "DefaultAppPath=\"Application Name\"\n");
212     append_str(&ptr, "LProgramF=\"Program Files\"\n");
213
214     WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
215     CloseHandle(hf);
216 }
217
218 static void translateinfstring_test()
219 {
220     HRESULT hr;
221     char buffer[MAX_PATH];
222     DWORD dwSize;
223
224     create_inf_file();
225
226     /* pass in a couple invalid parameters */
227     hr = pTranslateInfString(NULL, NULL, NULL, NULL, buffer, MAX_PATH, &dwSize, NULL);
228     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", (UINT)hr);
229
230     /* try to open an inf file that doesn't exist */
231     hr = pTranslateInfString("c:\\a.inf", "Options.NTx86", "Options.NTx86",
232                              "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
233     ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) || hr == E_INVALIDARG || 
234        hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND), 
235        "Expected E_INVALIDARG, 0x80070002 or 0x8007007e, got 0x%08x\n", (UINT)hr);
236
237     if(hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND))
238     {
239         trace("WinNT 3.51 detected. Skipping tests for TranslateInfString()\n");
240         return;
241     }
242
243     /* try a nonexistent section */
244     buffer[0] = 0;
245     hr = pTranslateInfString("c:\\test.inf", "idontexist", "Options.NTx86",
246                              "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
247     ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr);
248     ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
249     ok(dwSize == 25, "Expected size 25, got %ld\n", dwSize);
250
251     buffer[0] = 0;
252     /* try other nonexistent section */
253     hr = pTranslateInfString("c:\\test.inf", "Options.NTx86", "idontexist",
254                              "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
255     ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG, 
256        "Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr);
257
258     buffer[0] = 0;
259     /* try nonexistent key */
260     hr = pTranslateInfString("c:\\test.inf", "Options.NTx86", "Options.NTx86",
261                              "notvalid", buffer, MAX_PATH, &dwSize, NULL);
262     ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG, 
263        "Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr);
264
265     buffer[0] = 0;
266     /* test the behavior of pszInstallSection */
267     hr = pTranslateInfString("c:\\test.inf", "section", "Options.NTx86",
268                              "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
269     ok(hr == ERROR_SUCCESS || hr == E_FAIL, 
270        "Expected ERROR_SUCCESS or E_FAIL, got 0x%08x\n", (UINT)hr);
271
272     if(hr == ERROR_SUCCESS)
273     {
274         ok(!strcmp(buffer, PROG_FILES), "Expected '%s', got '%s'\n", PROG_FILES, buffer);
275         ok(dwSize == PROG_FILES_LEN, "Expected size %ld, got %ld\n", PROG_FILES_LEN, dwSize);
276     }
277
278     buffer[0] = 0;
279     /* try without a pszInstallSection */
280     hr = pTranslateInfString("c:\\test.inf", NULL, "Options.NTx86",
281                              "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
282     ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr);
283     todo_wine
284     {
285         ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
286         ok(dwSize == 25, "Expected size 25, got %ld\n", dwSize);
287     }
288
289     DeleteFile("c:\\a.inf");
290     DeleteFile("c:\\test.inf");
291 }
292
293 static void translateinfstringex_test(void)
294 {
295     HINF hinf;
296     HRESULT hr;
297     char buffer[MAX_PATH];
298     DWORD size = MAX_PATH;
299
300     create_inf_file();
301     
302     /* need to see if there are any flags */
303
304     /* try a NULL filename */
305     hr = pOpenINFEngine(NULL, "Options.NTx86", 0, &hinf, NULL);
306     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr);
307
308     /* try an empty filename */
309     hr = pOpenINFEngine("", "Options.NTx86", 0, &hinf, NULL);
310     ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
311         "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %ld\n", hr);
312
313     /* try a NULL hinf */
314     hr = pOpenINFEngine("c:\\test.inf", "Options.NTx86", 0, NULL, NULL);
315     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr);
316
317     /* open the INF without the Install section specified */
318     hr = pOpenINFEngine("c:\\test.inf", NULL, 0, &hinf, NULL);
319     ok(hr == S_OK, "Expected S_OK, got %ld\n", hr);
320
321     /* try a NULL hinf */
322     hr = pTranslateInfStringEx(NULL, "c:\\test.inf", "Options.NTx86", "InstallDir",
323                               buffer, size, &size, NULL);
324     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr);
325
326     /* try a NULL filename */
327     hr = pTranslateInfStringEx(hinf, NULL, "Options.NTx86", "InstallDir",
328                               buffer, size, &size, NULL);
329     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr);
330
331     /* try an empty filename */
332     size = MAX_PATH;
333     hr = pTranslateInfStringEx(hinf, "", "Options.NTx86", "InstallDir",
334                               buffer, size, &size, NULL);
335     ok(hr == S_OK, "Expected S_OK, got %08x\n", (UINT)hr);
336     todo_wine
337     {
338         ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
339         ok(size == 25, "Expected size 25, got %ld\n", size);
340     }
341
342     /* try a NULL translate section */
343     hr = pTranslateInfStringEx(hinf, "c:\\test.inf", NULL, "InstallDir",
344                               buffer, size, &size, NULL);
345     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr);
346
347     /* try an empty translate section */
348     hr = pTranslateInfStringEx(hinf, "c:\\test.inf", "", "InstallDir",
349                               buffer, size, &size, NULL);
350     ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %ld\n", hr);
351
352     /* try a NULL translate key */
353     hr = pTranslateInfStringEx(hinf, "c:\\test.inf", "Options.NTx86", NULL,
354                               buffer, size, &size, NULL);
355     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr);
356
357     /* try an empty translate key */
358     hr = pTranslateInfStringEx(hinf, "c:\\test.inf", "Options.NTx86", "",
359                               buffer, size, &size, NULL);
360     ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %ld\n", hr);
361
362     /* successfully translate the string */
363     size = MAX_PATH;
364     hr = pTranslateInfStringEx(hinf, "c:\\test.inf", "Options.NTx86", "InstallDir",
365                               buffer, size, &size, NULL);
366     ok(hr == S_OK, "Expected S_OK, got %ld\n", hr);
367     todo_wine
368     {
369         ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
370         ok(size == 25, "Expected size 25, got %ld\n", size);
371     }
372
373     /* try a NULL hinf */
374     hr = pCloseINFEngine(NULL);
375     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr);
376
377     /* successfully close the hinf */
378     hr = pCloseINFEngine(hinf);
379     ok(hr == S_OK, "Expected S_OK, got %ld\n", hr);
380
381     /* open the inf with the install section */
382     hr = pOpenINFEngine("c:\\test.inf", "section", 0, &hinf, NULL);
383     ok(hr == S_OK, "Expected S_OK, got %ld\n", hr);
384
385     /* translate the string with the install section specified */
386     size = MAX_PATH;
387     hr = pTranslateInfStringEx(hinf, "c:\\test.inf", "Options.NTx86", "InstallDir",
388                               buffer, size, &size, NULL);
389     ok(hr == S_OK, "Expected S_OK, got %ld\n", hr);
390     ok(!strcmp(buffer, PROG_FILES), "Expected %s, got %s\n", PROG_FILES, buffer);
391     ok(size == PROG_FILES_LEN, "Expected size %ld, got %ld\n", PROG_FILES_LEN, size);
392
393     /* close the INF again */
394     hr = pCloseINFEngine(hinf);
395     ok(hr == S_OK, "Expected S_OK, got %ld\n", hr);
396
397     DeleteFileA("c:\\test.inf");
398 }
399
400 static BOOL check_reg_str(HKEY hkey, LPSTR name, LPSTR value)
401 {
402     DWORD size = MAX_PATH;
403     char check[MAX_PATH];
404
405     if (RegQueryValueEx(hkey, name, NULL, NULL, (LPBYTE)check, &size))
406         return FALSE;
407
408     return !lstrcmp(check, value);
409 }
410
411 static BOOL check_reg_dword(HKEY hkey, LPSTR name, DWORD value)
412 {
413     DWORD size = sizeof(DWORD);
414     DWORD check;
415
416     if (RegQueryValueEx(hkey, name, NULL, NULL, (LPBYTE)&check, &size))
417         return FALSE;
418
419     return (check == value);
420 }
421
422 static void setperusersecvalues_test()
423 {
424     PERUSERSECTION peruser;
425     HRESULT hr;
426     HKEY guid;
427
428     lstrcpy(peruser.szDispName, "displayname");
429     lstrcpy(peruser.szLocale, "locale");
430     lstrcpy(peruser.szStub, "stub");
431     lstrcpy(peruser.szVersion, "1,1,1,1");
432     lstrcpy(peruser.szCompID, "compid");
433     peruser.dwIsInstalled = 1;
434     peruser.bRollback = FALSE;
435
436     /* try a NULL pPerUser */
437     hr = pSetPerUserSecValues(NULL);
438     todo_wine
439     ok(hr == S_OK, "Expected S_OK, got %ld\n", hr);
440     ok(!OPEN_GUID_KEY(), "Expected guid key to not exist\n");
441
442     /* at the very least, szGUID must be valid */
443     peruser.szGUID[0] = '\0';
444     hr = pSetPerUserSecValues(&peruser);
445     ok(hr == S_OK, "Expected S_OK, got %ld\n", hr);
446     ok(!OPEN_GUID_KEY(), "Expected guid key to not exist\n");
447
448     /* set initial values */
449     lstrcpy(peruser.szGUID, "guid");
450     hr = pSetPerUserSecValues(&peruser);
451     ok(hr == S_OK, "Expected S_OK, got %ld\n", hr);
452     ok(OPEN_GUID_KEY(), "Expected guid key to exist\n");
453     ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
454     ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
455     ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
456     ok(check_reg_str(guid, "StubPath", "stub"), "Expected stub\n");
457     ok(check_reg_str(guid, "Version", "1,1,1,1"), "Expected 1,1,1,1\n");
458     ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
459     ok(!REG_VAL_EXISTS(guid, "OldDisplayName"), "Expected OldDisplayName to not exist\n");
460     ok(!REG_VAL_EXISTS(guid, "OldLocale"), "Expected OldLocale to not exist\n");
461     ok(!REG_VAL_EXISTS(guid, "OldStubPath"), "Expected OldStubPath to not exist\n");
462     ok(!REG_VAL_EXISTS(guid, "OldVersion"), "Expected OldVersion to not exist\n");
463     ok(!REG_VAL_EXISTS(guid, "RealStubPath"), "Expected RealStubPath to not exist\n");
464
465     /* raise the version, but bRollback is FALSE, so vals not saved */
466     lstrcpy(peruser.szVersion, "2,1,1,1");
467     hr = pSetPerUserSecValues(&peruser);
468     ok(hr == S_OK, "Expected S_OK, got %ld\n", hr);
469     ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
470     ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
471     ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
472     ok(check_reg_str(guid, "StubPath", "stub"), "Expected stub\n");
473     ok(check_reg_str(guid, "Version", "2,1,1,1"), "Expected 2,1,1,1\n");
474     ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
475     ok(!REG_VAL_EXISTS(guid, "OldDisplayName"), "Expected OldDisplayName to not exist\n");
476     ok(!REG_VAL_EXISTS(guid, "OldLocale"), "Expected OldLocale to not exist\n");
477     ok(!REG_VAL_EXISTS(guid, "OldStubPath"), "Expected OldStubPath to not exist\n");
478     ok(!REG_VAL_EXISTS(guid, "OldVersion"), "Expected OldVersion to not exist\n");
479     ok(!REG_VAL_EXISTS(guid, "RealStubPath"), "Expected RealStubPath to not exist\n");
480
481     /* raise the version again, bRollback is TRUE so vals are saved */
482     peruser.bRollback = TRUE;
483     lstrcpy(peruser.szVersion, "3,1,1,1");
484     hr = pSetPerUserSecValues(&peruser);
485     ok(hr == S_OK, "Expected S_OK, got %ld\n", hr);
486     ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
487     ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
488     ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
489     ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
490     ok(check_reg_str(guid, "Version", "3,1,1,1"), "Expected 3,1,1,1\n");
491     todo_wine
492     {
493         ok(check_reg_str(guid, "OldDisplayName", "displayname"), "Expected displayname\n");
494         ok(check_reg_str(guid, "OldLocale", "locale"), "Expected locale\n");
495         ok(check_reg_str(guid, "RealStubPath", "stub"), "Expected stub\n");
496         ok(check_reg_str(guid, "OldStubPath", "stub"), "Expected stub\n");
497         ok(check_reg_str(guid, "OldVersion", "2,1,1,1"), "Expected 2,1,1,1\n");
498         ok(check_reg_str(guid, "StubPath",
499            "rundll32.exe advpack.dll,UserInstStubWrapper guid"),
500            "Expected real stub\n");
501     }
502
503     RegDeleteKey(HKEY_LOCAL_MACHINE, GUID_KEY);
504 }
505
506 START_TEST(advpack)
507 {
508     if (!init_function_pointers())
509         return;
510
511     get_progfiles_dir();
512
513     version_test();
514     delnode_test();
515     setperusersecvalues_test();
516     translateinfstring_test();
517     translateinfstringex_test();
518 }