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