1c2c66affSColin Finck /*
2c2c66affSColin Finck  * Unit tests for advpack.dll
3c2c66affSColin Finck  *
4c2c66affSColin Finck  * Copyright (C) 2005 Robert Reif
5c2c66affSColin Finck  * Copyright (C) 2005 Sami Aario
6c2c66affSColin Finck  *
7c2c66affSColin Finck  * This library is free software; you can redistribute it and/or
8c2c66affSColin Finck  * modify it under the terms of the GNU Lesser General Public
9c2c66affSColin Finck  * License as published by the Free Software Foundation; either
10c2c66affSColin Finck  * version 2.1 of the License, or (at your option) any later version.
11c2c66affSColin Finck  *
12c2c66affSColin Finck  * This library is distributed in the hope that it will be useful,
13c2c66affSColin Finck  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15c2c66affSColin Finck  * Lesser General Public License for more details.
16c2c66affSColin Finck  *
17c2c66affSColin Finck  * You should have received a copy of the GNU Lesser General Public
18c2c66affSColin Finck  * License along with this library; if not, write to the Free Software
19c2c66affSColin Finck  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20c2c66affSColin Finck  */
21c2c66affSColin Finck 
22c2c66affSColin Finck #include <stdio.h>
2359eab41aSAmine Khaldi #include <stdarg.h>
2459eab41aSAmine Khaldi #include <windows.h>
25c2c66affSColin Finck #include <advpub.h>
26c2c66affSColin Finck #include <assert.h>
2759eab41aSAmine Khaldi #include "wine/test.h"
28c2c66affSColin Finck 
29c2c66affSColin Finck /* defines for the TranslateInfString/Ex tests */
30c2c66affSColin Finck #define TEST_STRING1 "\\Application Name"
31c2c66affSColin Finck #define TEST_STRING2 "%49001%\\Application Name"
32c2c66affSColin Finck 
33c2c66affSColin Finck /* defines for the SetPerUserSecValues tests */
34c2c66affSColin Finck #define GUID_KEY    "SOFTWARE\\Microsoft\\Active Setup\\Installed Components\\guid"
35c2c66affSColin Finck #define REG_VAL_EXISTS(key, value)   !RegQueryValueExA(key, value, NULL, NULL, NULL, NULL)
36c2c66affSColin Finck #define OPEN_GUID_KEY() !RegOpenKeyA(HKEY_LOCAL_MACHINE, GUID_KEY, &guid)
37c2c66affSColin Finck 
38c2c66affSColin Finck static HMODULE hAdvPack;
39c2c66affSColin Finck static HRESULT (WINAPI *pCloseINFEngine)(HINF);
40c2c66affSColin Finck static HRESULT (WINAPI *pDelNode)(LPCSTR,DWORD);
41c2c66affSColin Finck static HRESULT (WINAPI *pGetVersionFromFile)(LPCSTR,LPDWORD,LPDWORD,BOOL);
42c2c66affSColin Finck static HRESULT (WINAPI *pOpenINFEngine)(PCSTR,PCSTR,DWORD,HINF*,PVOID);
43c2c66affSColin Finck static HRESULT (WINAPI *pSetPerUserSecValues)(PPERUSERSECTIONA pPerUser);
44c2c66affSColin Finck static HRESULT (WINAPI *pTranslateInfString)(LPCSTR,LPCSTR,LPCSTR,LPCSTR,LPSTR,DWORD,LPDWORD,LPVOID);
45c2c66affSColin Finck static HRESULT (WINAPI *pTranslateInfStringEx)(HINF,PCSTR,PCSTR,PCSTR,PSTR,DWORD,PDWORD,PVOID);
46c2c66affSColin Finck 
47c2c66affSColin Finck static CHAR inf_file[MAX_PATH];
48c2c66affSColin Finck static CHAR PROG_FILES_ROOT[MAX_PATH];
49c2c66affSColin Finck static CHAR PROG_FILES[MAX_PATH];
50c2c66affSColin Finck static CHAR APP_PATH[MAX_PATH];
51c2c66affSColin Finck static DWORD APP_PATH_LEN;
52c2c66affSColin Finck 
get_progfiles_dir(void)53c2c66affSColin Finck static void get_progfiles_dir(void)
54c2c66affSColin Finck {
55c2c66affSColin Finck     HKEY hkey;
56c2c66affSColin Finck     DWORD size = MAX_PATH;
57c2c66affSColin Finck 
58c2c66affSColin Finck     RegOpenKeyA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", &hkey);
59c2c66affSColin Finck     RegQueryValueExA(hkey, "ProgramFilesDir", NULL, NULL, (LPBYTE)PROG_FILES_ROOT, &size);
60c2c66affSColin Finck     RegCloseKey(hkey);
61c2c66affSColin Finck 
62c2c66affSColin Finck     lstrcpyA(PROG_FILES, PROG_FILES_ROOT + 3); /* skip C:\ */
63c2c66affSColin Finck     lstrcpyA(APP_PATH, PROG_FILES_ROOT);
64c2c66affSColin Finck     lstrcatA(APP_PATH, TEST_STRING1);
65c2c66affSColin Finck     APP_PATH_LEN = lstrlenA(APP_PATH) + 1;
66c2c66affSColin Finck }
67c2c66affSColin Finck 
init_function_pointers(void)68c2c66affSColin Finck static BOOL init_function_pointers(void)
69c2c66affSColin Finck {
70c2c66affSColin Finck     hAdvPack = LoadLibraryA("advpack.dll");
71c2c66affSColin Finck 
72c2c66affSColin Finck     if (!hAdvPack)
73c2c66affSColin Finck         return FALSE;
74c2c66affSColin Finck 
75c2c66affSColin Finck     pCloseINFEngine = (void*)GetProcAddress(hAdvPack, "CloseINFEngine");
76c2c66affSColin Finck     pDelNode = (void *)GetProcAddress(hAdvPack, "DelNode");
77c2c66affSColin Finck     pGetVersionFromFile = (void *)GetProcAddress(hAdvPack, "GetVersionFromFile");
78c2c66affSColin Finck     pOpenINFEngine = (void*)GetProcAddress(hAdvPack, "OpenINFEngine");
79c2c66affSColin Finck     pSetPerUserSecValues = (void*)GetProcAddress(hAdvPack, "SetPerUserSecValues");
80c2c66affSColin Finck     pTranslateInfString = (void *)GetProcAddress(hAdvPack, "TranslateInfString");
81c2c66affSColin Finck     pTranslateInfStringEx = (void*)GetProcAddress(hAdvPack, "TranslateInfStringEx");
82c2c66affSColin Finck 
83c2c66affSColin Finck     if (!pCloseINFEngine || !pDelNode || !pGetVersionFromFile ||
84c2c66affSColin Finck         !pOpenINFEngine || !pSetPerUserSecValues || !pTranslateInfString)
85c2c66affSColin Finck     {
86c2c66affSColin Finck         win_skip("Needed functions are not available\n");
87c2c66affSColin Finck         FreeLibrary(hAdvPack);
88c2c66affSColin Finck         return FALSE;
89c2c66affSColin Finck     }
90c2c66affSColin Finck 
91c2c66affSColin Finck     return TRUE;
92c2c66affSColin Finck }
93c2c66affSColin Finck 
version_test(void)94c2c66affSColin Finck static void version_test(void)
95c2c66affSColin Finck {
96c2c66affSColin Finck     HRESULT hr;
97c2c66affSColin Finck     DWORD major, minor;
98c2c66affSColin Finck 
99c2c66affSColin Finck     major = minor = 0;
100c2c66affSColin Finck     hr = pGetVersionFromFile("kernel32.dll", &major, &minor, FALSE);
101c2c66affSColin Finck     ok (hr == S_OK, "GetVersionFromFileEx(kernel32.dll) failed, returned "
102c2c66affSColin Finck         "0x%08x\n", hr);
103c2c66affSColin Finck     trace("kernel32.dll Language ID: 0x%08x, Codepage ID: 0x%08x\n",
104c2c66affSColin Finck            major, minor);
105c2c66affSColin Finck 
106c2c66affSColin Finck     major = minor = 0;
107c2c66affSColin Finck     hr = pGetVersionFromFile("kernel32.dll", &major, &minor, TRUE);
108c2c66affSColin Finck     ok (hr == S_OK, "GetVersionFromFileEx(kernel32.dll) failed, returned "
109c2c66affSColin Finck         "0x%08x\n", hr);
110c2c66affSColin Finck     trace("kernel32.dll version: %d.%d.%d.%d\n", HIWORD(major), LOWORD(major),
111c2c66affSColin Finck           HIWORD(minor), LOWORD(minor));
112c2c66affSColin Finck 
113c2c66affSColin Finck     major = minor = 0;
114c2c66affSColin Finck     hr = pGetVersionFromFile("advpack.dll", &major, &minor, FALSE);
115c2c66affSColin Finck     ok (hr == S_OK, "GetVersionFromFileEx(advpack.dll) failed, returned "
116c2c66affSColin Finck         "0x%08x\n", hr);
117c2c66affSColin Finck     trace("advpack.dll Language ID: 0x%08x, Codepage ID: 0x%08x\n",
118c2c66affSColin Finck            major, minor);
119c2c66affSColin Finck 
120c2c66affSColin Finck     major = minor = 0;
121c2c66affSColin Finck     hr = pGetVersionFromFile("advpack.dll", &major, &minor, TRUE);
122c2c66affSColin Finck     ok (hr == S_OK, "GetVersionFromFileEx(advpack.dll) failed, returned "
123c2c66affSColin Finck         "0x%08x\n", hr);
124c2c66affSColin Finck     trace("advpack.dll version: %d.%d.%d.%d\n", HIWORD(major), LOWORD(major),
125c2c66affSColin Finck           HIWORD(minor), LOWORD(minor));
126c2c66affSColin Finck }
127c2c66affSColin Finck 
delnode_test(void)128c2c66affSColin Finck static void delnode_test(void)
129c2c66affSColin Finck {
130c2c66affSColin Finck     HRESULT hr;
131c2c66affSColin Finck     HANDLE hn;
132c2c66affSColin Finck     CHAR currDir[MAX_PATH];
133c2c66affSColin Finck     UINT currDirLen;
134c2c66affSColin Finck 
135c2c66affSColin Finck     /* Native DelNode apparently does not support relative paths, so we use
136c2c66affSColin Finck        absolute paths for testing */
137d1060f20SAmine Khaldi     currDirLen = GetCurrentDirectoryA(ARRAY_SIZE(currDir), currDir);
138d1060f20SAmine Khaldi     assert(currDirLen > 0 && currDirLen < ARRAY_SIZE(currDir));
139c2c66affSColin Finck 
140c2c66affSColin Finck     if(currDir[currDirLen - 1] == '\\')
141c2c66affSColin Finck         currDir[--currDirLen] = 0;
142c2c66affSColin Finck 
143c2c66affSColin Finck     /* Simple tests; these should fail. */
144c2c66affSColin Finck     hr = pDelNode(NULL, 0);
145c2c66affSColin Finck     ok (hr == E_FAIL, "DelNode called with NULL pathname should return E_FAIL\n");
146c2c66affSColin Finck     hr = pDelNode("", 0);
147c2c66affSColin Finck     ok (hr == E_FAIL, "DelNode called with empty pathname should return E_FAIL\n");
148c2c66affSColin Finck 
149c2c66affSColin Finck     /* Test deletion of a file. */
150c2c66affSColin Finck     hn = CreateFileA("DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
151c2c66affSColin Finck         CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
152c2c66affSColin Finck     assert(hn != INVALID_HANDLE_VALUE);
153c2c66affSColin Finck     CloseHandle(hn);
154c2c66affSColin Finck     hr = pDelNode(lstrcatA(currDir, "\\DelNodeTestFile1"), 0);
155c2c66affSColin Finck     ok (hr == S_OK, "DelNode failed deleting a single file\n");
156c2c66affSColin Finck     currDir[currDirLen] = '\0';
157c2c66affSColin Finck 
158c2c66affSColin Finck     /* Test deletion of an empty directory. */
159c2c66affSColin Finck     CreateDirectoryA("DelNodeTestDir", NULL);
160c2c66affSColin Finck     hr = pDelNode(lstrcatA(currDir, "\\DelNodeTestDir"), 0);
161c2c66affSColin Finck     ok (hr == S_OK, "DelNode failed deleting an empty directory\n");
162c2c66affSColin Finck     currDir[currDirLen] = '\0';
163c2c66affSColin Finck 
164c2c66affSColin Finck     /* Test deletion of a directory containing one file. */
165c2c66affSColin Finck     CreateDirectoryA("DelNodeTestDir", NULL);
166c2c66affSColin Finck     hn = CreateFileA("DelNodeTestDir\\DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
167c2c66affSColin Finck         CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
168c2c66affSColin Finck     assert(hn != INVALID_HANDLE_VALUE);
169c2c66affSColin Finck     CloseHandle(hn);
170c2c66affSColin Finck     hr = pDelNode(lstrcatA(currDir, "\\DelNodeTestDir"), 0);
171c2c66affSColin Finck     ok (hr == S_OK, "DelNode failed deleting a directory containing one file\n");
172c2c66affSColin Finck     currDir[currDirLen] = '\0';
173c2c66affSColin Finck 
174c2c66affSColin Finck     /* Test deletion of a directory containing multiple files. */
175c2c66affSColin Finck     CreateDirectoryA("DelNodeTestDir", NULL);
176c2c66affSColin Finck     hn = CreateFileA("DelNodeTestDir\\DelNodeTestFile1", GENERIC_WRITE, 0, NULL,
177c2c66affSColin Finck         CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
178c2c66affSColin Finck     assert(hn != INVALID_HANDLE_VALUE);
179c2c66affSColin Finck     CloseHandle(hn);
180c2c66affSColin Finck     hn = CreateFileA("DelNodeTestDir\\DelNodeTestFile2", GENERIC_WRITE, 0, NULL,
181c2c66affSColin Finck         CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
182c2c66affSColin Finck     assert(hn != INVALID_HANDLE_VALUE);
183c2c66affSColin Finck     CloseHandle(hn);
184c2c66affSColin Finck     hn = CreateFileA("DelNodeTestDir\\DelNodeTestFile3", GENERIC_WRITE, 0, NULL,
185c2c66affSColin Finck         CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
186c2c66affSColin Finck     assert(hn != INVALID_HANDLE_VALUE);
187c2c66affSColin Finck     CloseHandle(hn);
188c2c66affSColin Finck     hr = pDelNode(lstrcatA(currDir, "\\DelNodeTestDir"), 0);
189c2c66affSColin Finck     ok (hr == S_OK, "DelNode failed deleting a directory containing multiple files\n");
190c2c66affSColin Finck }
191c2c66affSColin Finck 
append_str(char ** str,const char * data,...)192*14d97256SAmine Khaldi static void WINAPIV append_str(char **str, const char *data, ...)
193c2c66affSColin Finck {
194*14d97256SAmine Khaldi     __ms_va_list valist;
195c2c66affSColin Finck 
196*14d97256SAmine Khaldi     __ms_va_start(valist, data);
197c2c66affSColin Finck     vsprintf(*str, data, valist);
198c2c66affSColin Finck     *str += strlen(*str);
199*14d97256SAmine Khaldi     __ms_va_end(valist);
200c2c66affSColin Finck }
201c2c66affSColin Finck 
create_inf_file(void)202c2c66affSColin Finck static void create_inf_file(void)
203c2c66affSColin Finck {
204c2c66affSColin Finck     char data[1024];
205c2c66affSColin Finck     char *ptr = data;
206c2c66affSColin Finck     DWORD dwNumberOfBytesWritten;
207c2c66affSColin Finck     HANDLE hf = CreateFileA(inf_file, GENERIC_WRITE, 0, NULL,
208c2c66affSColin Finck                             CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
209c2c66affSColin Finck 
210c2c66affSColin Finck     append_str(&ptr, "[Version]\n");
211c2c66affSColin Finck     append_str(&ptr, "Signature=\"$Chicago$\"\n");
212c2c66affSColin Finck     append_str(&ptr, "[CustInstDestSection]\n");
213c2c66affSColin Finck     append_str(&ptr, "49001=ProgramFilesDir\n");
214c2c66affSColin Finck     append_str(&ptr, "49010=DestA,1\n");
215c2c66affSColin Finck     append_str(&ptr, "49020=DestB\n");
216c2c66affSColin Finck     append_str(&ptr, "49030=DestC\n");
217c2c66affSColin Finck     append_str(&ptr, "[ProgramFilesDir]\n");
218c2c66affSColin Finck     append_str(&ptr, "HKLM,\"Software\\Microsoft\\Windows\\CurrentVersion\",");
219c2c66affSColin Finck     append_str(&ptr, "\"ProgramFilesDir\",,\"%%24%%\\%%LProgramF%%\"\n");
220c2c66affSColin Finck     append_str(&ptr, "[section]\n");
221c2c66affSColin Finck     append_str(&ptr, "NotACustomDestination=Version\n");
222c2c66affSColin Finck     append_str(&ptr, "CustomDestination=CustInstDestSection\n");
223c2c66affSColin Finck     append_str(&ptr, "[Options.NTx86]\n");
224c2c66affSColin Finck     append_str(&ptr, "49001=ProgramFilesDir\n");
225c2c66affSColin Finck     append_str(&ptr, "InstallDir=%%49001%%\\%%DefaultAppPath%%\n");
226c2c66affSColin Finck     append_str(&ptr, "Result1=%%49010%%\n");
227c2c66affSColin Finck     append_str(&ptr, "Result2=%%49020%%\n");
228c2c66affSColin Finck     append_str(&ptr, "Result3=%%49030%%\n");
229c2c66affSColin Finck     append_str(&ptr, "CustomHDestination=CustInstDestSection\n");
230c2c66affSColin Finck     append_str(&ptr, "[Strings]\n");
231c2c66affSColin Finck     append_str(&ptr, "DefaultAppPath=\"Application Name\"\n");
232c2c66affSColin Finck     append_str(&ptr, "LProgramF=\"%s\"\n", PROG_FILES);
233c2c66affSColin Finck     append_str(&ptr, "[DestA]\n");
234c2c66affSColin Finck     append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%\\%%LProgramF%%'\n");
235c2c66affSColin Finck     append_str(&ptr, "[DestB]\n");
236c2c66affSColin Finck     append_str(&ptr, "'HKLM','Software\\Microsoft\\Windows\\CurrentVersion',");
237c2c66affSColin Finck     append_str(&ptr, "'ProgramFilesDir',,\"%%24%%\"\n");
238c2c66affSColin Finck     append_str(&ptr, "[DestC]\n");
239c2c66affSColin Finck     append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n");
240c2c66affSColin Finck 
241c2c66affSColin Finck     WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
242c2c66affSColin Finck     CloseHandle(hf);
243c2c66affSColin Finck }
244c2c66affSColin Finck 
translateinfstring_test(void)245c2c66affSColin Finck static void translateinfstring_test(void)
246c2c66affSColin Finck {
247c2c66affSColin Finck     HRESULT hr;
248c2c66affSColin Finck     char buffer[MAX_PATH];
249c2c66affSColin Finck     DWORD dwSize;
250c2c66affSColin Finck 
251c2c66affSColin Finck     create_inf_file();
252c2c66affSColin Finck 
253c2c66affSColin Finck     /* pass in a couple invalid parameters */
254c2c66affSColin Finck     hr = pTranslateInfString(NULL, NULL, NULL, NULL, buffer, MAX_PATH, &dwSize, NULL);
255c2c66affSColin Finck     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", (UINT)hr);
256c2c66affSColin Finck 
257c2c66affSColin Finck     /* try to open an inf file that doesn't exist */
258c2c66affSColin Finck     hr = pTranslateInfString("c:\\a.inf", "Options.NTx86", "Options.NTx86",
259c2c66affSColin Finck                              "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
260c2c66affSColin Finck     ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) || hr == E_INVALIDARG ||
261c2c66affSColin Finck        hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND),
262c2c66affSColin Finck        "Expected E_INVALIDARG, 0x80070002 or 0x8007007e, got 0x%08x\n", (UINT)hr);
263c2c66affSColin Finck 
264c2c66affSColin Finck     if(hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND))
265c2c66affSColin Finck     {
266c2c66affSColin Finck         win_skip("WinNT 3.51 detected. Skipping tests for TranslateInfString()\n");
267c2c66affSColin Finck         return;
268c2c66affSColin Finck     }
269c2c66affSColin Finck 
270c2c66affSColin Finck     /* try a nonexistent section */
271c2c66affSColin Finck     buffer[0] = 0;
272c2c66affSColin Finck     hr = pTranslateInfString(inf_file, "idontexist", "Options.NTx86",
273c2c66affSColin Finck                              "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
274c2c66affSColin Finck     if (hr == E_ACCESSDENIED)
275c2c66affSColin Finck     {
276c2c66affSColin Finck         skip("TranslateInfString is broken\n");
277c2c66affSColin Finck         return;
278c2c66affSColin Finck     }
279c2c66affSColin Finck     ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr);
280c2c66affSColin Finck     ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
281c2c66affSColin Finck     ok(dwSize == 25, "Expected size 25, got %d\n", dwSize);
282c2c66affSColin Finck 
283c2c66affSColin Finck     buffer[0] = 0;
284c2c66affSColin Finck     /* try other nonexistent section */
285c2c66affSColin Finck     hr = pTranslateInfString(inf_file, "Options.NTx86", "idontexist",
286c2c66affSColin Finck                              "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
287c2c66affSColin Finck     ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG,
288c2c66affSColin Finck        "Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr);
289c2c66affSColin Finck 
290c2c66affSColin Finck     buffer[0] = 0;
291c2c66affSColin Finck     /* try nonexistent key */
292c2c66affSColin Finck     hr = pTranslateInfString(inf_file, "Options.NTx86", "Options.NTx86",
293c2c66affSColin Finck                              "notvalid", buffer, MAX_PATH, &dwSize, NULL);
294c2c66affSColin Finck     ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG,
295c2c66affSColin Finck        "Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr);
296c2c66affSColin Finck 
297c2c66affSColin Finck     buffer[0] = 0;
298c2c66affSColin Finck     /* test the behavior of pszInstallSection */
299c2c66affSColin Finck     hr = pTranslateInfString(inf_file, "section", "Options.NTx86",
300c2c66affSColin Finck                              "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
301c2c66affSColin Finck     ok(hr == ERROR_SUCCESS || hr == E_FAIL,
302c2c66affSColin Finck        "Expected ERROR_SUCCESS or E_FAIL, got 0x%08x\n", (UINT)hr);
303c2c66affSColin Finck 
304c2c66affSColin Finck     if(hr == ERROR_SUCCESS)
305c2c66affSColin Finck     {
306c2c66affSColin Finck         ok(!strcmp(buffer, APP_PATH), "Expected '%s', got '%s'\n", APP_PATH, buffer);
307c2c66affSColin Finck         ok(dwSize == APP_PATH_LEN, "Expected size %d, got %d\n", APP_PATH_LEN, dwSize);
308c2c66affSColin Finck     }
309c2c66affSColin Finck 
310c2c66affSColin Finck     buffer[0] = 0;
311c2c66affSColin Finck     /* try without a pszInstallSection */
312c2c66affSColin Finck     hr = pTranslateInfString(inf_file, NULL, "Options.NTx86",
313c2c66affSColin Finck                              "InstallDir", buffer, MAX_PATH, &dwSize, NULL);
314c2c66affSColin Finck     ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr);
315c2c66affSColin Finck     todo_wine
316c2c66affSColin Finck     {
317c2c66affSColin Finck         ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
318c2c66affSColin Finck         ok(dwSize == 25, "Expected size 25, got %d\n", dwSize);
319c2c66affSColin Finck     }
320c2c66affSColin Finck 
321c2c66affSColin Finck     DeleteFileA("c:\\a.inf");
322c2c66affSColin Finck     DeleteFileA(inf_file);
323c2c66affSColin Finck }
324c2c66affSColin Finck 
translateinfstringex_test(void)325c2c66affSColin Finck static void translateinfstringex_test(void)
326c2c66affSColin Finck {
327c2c66affSColin Finck     HINF hinf;
328c2c66affSColin Finck     HRESULT hr;
329c2c66affSColin Finck     char buffer[MAX_PATH];
330c2c66affSColin Finck     DWORD size = MAX_PATH;
331c2c66affSColin Finck 
332c2c66affSColin Finck     hr = pOpenINFEngine(inf_file, NULL, 0, &hinf, NULL);
333c2c66affSColin Finck     if (hr == E_UNEXPECTED)
334c2c66affSColin Finck     {
335c2c66affSColin Finck         win_skip("Skipping tests on win9x because of brokenness\n");
336c2c66affSColin Finck         return;
337c2c66affSColin Finck     }
338c2c66affSColin Finck 
339c2c66affSColin Finck     create_inf_file();
340c2c66affSColin Finck 
341c2c66affSColin Finck     /* need to see if there are any flags */
342c2c66affSColin Finck 
343c2c66affSColin Finck     /* try a NULL filename */
344c2c66affSColin Finck     hr = pOpenINFEngine(NULL, "Options.NTx86", 0, &hinf, NULL);
345c2c66affSColin Finck     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
346c2c66affSColin Finck 
347c2c66affSColin Finck     /* try an empty filename */
348c2c66affSColin Finck     hr = pOpenINFEngine("", "Options.NTx86", 0, &hinf, NULL);
349c2c66affSColin Finck     ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) /* NT+ */ ||
350c2c66affSColin Finck        hr == HRESULT_FROM_WIN32(E_UNEXPECTED) /* 9x */,
351c2c66affSColin Finck         "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND or E_UNEXPECTED), got %08x\n", hr);
352c2c66affSColin Finck 
353c2c66affSColin Finck     /* try a NULL hinf */
354c2c66affSColin Finck     hr = pOpenINFEngine(inf_file, "Options.NTx86", 0, NULL, NULL);
355c2c66affSColin Finck     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
356c2c66affSColin Finck 
357c2c66affSColin Finck     /* open the INF without the Install section specified */
358c2c66affSColin Finck     hr = pOpenINFEngine(inf_file, NULL, 0, &hinf, NULL);
359c2c66affSColin Finck     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
360c2c66affSColin Finck 
361c2c66affSColin Finck     /* try a NULL hinf */
362c2c66affSColin Finck     hr = pTranslateInfStringEx(NULL, inf_file, "Options.NTx86", "InstallDir",
363c2c66affSColin Finck                               buffer, size, &size, NULL);
364c2c66affSColin Finck     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
365c2c66affSColin Finck 
366c2c66affSColin Finck     /* try a NULL filename */
367c2c66affSColin Finck     hr = pTranslateInfStringEx(hinf, NULL, "Options.NTx86", "InstallDir",
368c2c66affSColin Finck                               buffer, size, &size, NULL);
369c2c66affSColin Finck     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
370c2c66affSColin Finck 
371c2c66affSColin Finck     /* try an empty filename */
372c2c66affSColin Finck     memset(buffer, 'a', 25);
373c2c66affSColin Finck     buffer[24] = '\0';
374c2c66affSColin Finck     size = MAX_PATH;
375c2c66affSColin Finck     hr = pTranslateInfStringEx(hinf, "", "Options.NTx86", "InstallDir",
376c2c66affSColin Finck                               buffer, size, &size, NULL);
377c2c66affSColin Finck     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
378c2c66affSColin Finck     todo_wine
379c2c66affSColin Finck     {
380c2c66affSColin Finck         ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
381c2c66affSColin Finck         ok(size == 25, "Expected size 25, got %d\n", size);
382c2c66affSColin Finck     }
383c2c66affSColin Finck 
384c2c66affSColin Finck     /* try a NULL translate section */
385c2c66affSColin Finck     hr = pTranslateInfStringEx(hinf, inf_file, NULL, "InstallDir",
386c2c66affSColin Finck                               buffer, size, &size, NULL);
387c2c66affSColin Finck     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
388c2c66affSColin Finck 
389c2c66affSColin Finck     /* try an empty translate section */
390c2c66affSColin Finck     hr = pTranslateInfStringEx(hinf, inf_file, "", "InstallDir",
391c2c66affSColin Finck                               buffer, size, &size, NULL);
392c2c66affSColin Finck     ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %08x\n", hr);
393c2c66affSColin Finck 
394c2c66affSColin Finck     /* try a NULL translate key */
395c2c66affSColin Finck     hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", NULL,
396c2c66affSColin Finck                               buffer, size, &size, NULL);
397c2c66affSColin Finck     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
398c2c66affSColin Finck 
399c2c66affSColin Finck     /* try an empty translate key */
400c2c66affSColin Finck     hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "",
401c2c66affSColin Finck                               buffer, size, &size, NULL);
402c2c66affSColin Finck     ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %08x\n", hr);
403c2c66affSColin Finck 
404c2c66affSColin Finck     /* successfully translate the string */
405c2c66affSColin Finck     memset(buffer, 'a', 25);
406c2c66affSColin Finck     buffer[24] = '\0';
407c2c66affSColin Finck     size = MAX_PATH;
408c2c66affSColin Finck     hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "InstallDir",
409c2c66affSColin Finck                               buffer, size, &size, NULL);
410c2c66affSColin Finck     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
411c2c66affSColin Finck     todo_wine
412c2c66affSColin Finck     {
413c2c66affSColin Finck         ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer);
414c2c66affSColin Finck         ok(size == 25, "Expected size 25, got %d\n", size);
415c2c66affSColin Finck     }
416c2c66affSColin Finck 
417c2c66affSColin Finck     /* try a NULL hinf */
418c2c66affSColin Finck     hr = pCloseINFEngine(NULL);
419c2c66affSColin Finck     ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
420c2c66affSColin Finck 
421c2c66affSColin Finck     /* successfully close the hinf */
422c2c66affSColin Finck     hr = pCloseINFEngine(hinf);
423c2c66affSColin Finck     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
424c2c66affSColin Finck 
425c2c66affSColin Finck     /* open the inf with the install section */
426c2c66affSColin Finck     hr = pOpenINFEngine(inf_file, "section", 0, &hinf, NULL);
427c2c66affSColin Finck     if (hr == E_FAIL)
428c2c66affSColin Finck     {
429c2c66affSColin Finck         skip("can't open engine with install section (needs admin rights)\n");
430c2c66affSColin Finck         DeleteFileA(inf_file);
431c2c66affSColin Finck         return;
432c2c66affSColin Finck     }
433c2c66affSColin Finck     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
434c2c66affSColin Finck 
435c2c66affSColin Finck     /* translate the string with the install section specified */
436c2c66affSColin Finck     memset(buffer, 'a', APP_PATH_LEN);
437c2c66affSColin Finck     buffer[APP_PATH_LEN - 1] = '\0';
438c2c66affSColin Finck     size = MAX_PATH;
439c2c66affSColin Finck     hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "InstallDir",
440c2c66affSColin Finck                               buffer, size, &size, NULL);
441c2c66affSColin Finck     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
442c2c66affSColin Finck     ok(!strcmp(buffer, APP_PATH), "Expected %s, got %s\n", APP_PATH, buffer);
443c2c66affSColin Finck     ok(size == APP_PATH_LEN, "Expected size %d, got %d\n", APP_PATH_LEN, size);
444c2c66affSColin Finck 
445c2c66affSColin Finck     /* Single quote test (Note size includes null on return from call) */
446c2c66affSColin Finck     memset(buffer, 'a', APP_PATH_LEN);
447c2c66affSColin Finck     buffer[APP_PATH_LEN - 1] = '\0';
448c2c66affSColin Finck     size = MAX_PATH;
449c2c66affSColin Finck     hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result1",
450c2c66affSColin Finck                               buffer, size, &size, NULL);
451c2c66affSColin Finck     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
452c2c66affSColin Finck     ok(!lstrcmpiA(buffer, PROG_FILES_ROOT),
453c2c66affSColin Finck            "Expected %s, got %s\n", PROG_FILES_ROOT, buffer);
454c2c66affSColin Finck     ok(size == strlen(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n",
455c2c66affSColin Finck            lstrlenA(PROG_FILES_ROOT)+1, size);
456c2c66affSColin Finck 
457c2c66affSColin Finck     memset(buffer, 'a', APP_PATH_LEN);
458c2c66affSColin Finck     buffer[APP_PATH_LEN - 1] = '\0';
459c2c66affSColin Finck     size = MAX_PATH;
460c2c66affSColin Finck     hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result2",
461c2c66affSColin Finck                               buffer, size, &size, NULL);
462c2c66affSColin Finck     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
463c2c66affSColin Finck     ok(!lstrcmpiA(buffer, PROG_FILES_ROOT),
464c2c66affSColin Finck            "Expected %s, got %s\n", PROG_FILES_ROOT, buffer);
465c2c66affSColin Finck     ok(size == strlen(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n",
466c2c66affSColin Finck            lstrlenA(PROG_FILES_ROOT)+1, size);
467c2c66affSColin Finck 
468c2c66affSColin Finck     {
469c2c66affSColin Finck         char drive[MAX_PATH];
470c2c66affSColin Finck         lstrcpyA(drive, PROG_FILES_ROOT);
471c2c66affSColin Finck         drive[3] = 0x00; /* Just keep the system drive plus '\' */
472c2c66affSColin Finck 
473c2c66affSColin Finck         memset(buffer, 'a', APP_PATH_LEN);
474c2c66affSColin Finck         buffer[APP_PATH_LEN - 1] = '\0';
475c2c66affSColin Finck         size = MAX_PATH;
476c2c66affSColin Finck         hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result3",
477c2c66affSColin Finck                                   buffer, size, &size, NULL);
478c2c66affSColin Finck         ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
479c2c66affSColin Finck         ok(!lstrcmpiA(buffer, drive),
480c2c66affSColin Finck                "Expected %s, got %s\n", drive, buffer);
481c2c66affSColin Finck         ok(size == strlen(drive)+1, "Expected size %d, got %d\n",
482c2c66affSColin Finck                lstrlenA(drive)+1, size);
483c2c66affSColin Finck     }
484c2c66affSColin Finck 
485c2c66affSColin Finck     /* close the INF again */
486c2c66affSColin Finck     hr = pCloseINFEngine(hinf);
487c2c66affSColin Finck     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
488c2c66affSColin Finck 
489c2c66affSColin Finck     DeleteFileA(inf_file);
490c2c66affSColin Finck 
491c2c66affSColin Finck     /* Create another .inf file which is just here to trigger a wine bug */
492c2c66affSColin Finck     {
493c2c66affSColin Finck         char data[1024];
494c2c66affSColin Finck         char *ptr = data;
495c2c66affSColin Finck         DWORD dwNumberOfBytesWritten;
496c2c66affSColin Finck         HANDLE hf = CreateFileA(inf_file, GENERIC_WRITE, 0, NULL,
497c2c66affSColin Finck                            CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
498c2c66affSColin Finck 
499c2c66affSColin Finck         append_str(&ptr, "[Version]\n");
500c2c66affSColin Finck         append_str(&ptr, "Signature=\"$Chicago$\"\n");
501c2c66affSColin Finck         append_str(&ptr, "[section]\n");
502c2c66affSColin Finck         append_str(&ptr, "NotACustomDestination=Version\n");
503c2c66affSColin Finck         append_str(&ptr, "CustomDestination=CustInstDestSection\n");
504c2c66affSColin Finck         append_str(&ptr, "[CustInstDestSection]\n");
505c2c66affSColin Finck         append_str(&ptr, "49010=DestA,1\n");
506c2c66affSColin Finck         append_str(&ptr, "49020=DestB\n");
507c2c66affSColin Finck         append_str(&ptr, "49030=DestC\n");
508c2c66affSColin Finck         append_str(&ptr, "49040=DestD\n");
509c2c66affSColin Finck         append_str(&ptr, "[Options.NTx86]\n");
510c2c66affSColin Finck         append_str(&ptr, "Result2=%%49030%%\n");
511c2c66affSColin Finck         append_str(&ptr, "[DestA]\n");
512c2c66affSColin Finck         append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n");
513c2c66affSColin Finck         /* The point of this test is to have HKCU just before the quoted HKLM */
514c2c66affSColin Finck         append_str(&ptr, "[DestB]\n");
515c2c66affSColin Finck         append_str(&ptr, "HKCU,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n");
516c2c66affSColin Finck         append_str(&ptr, "[DestC]\n");
517c2c66affSColin Finck         append_str(&ptr, "'HKLM','Software\\Microsoft\\Windows\\CurrentVersion',");
518c2c66affSColin Finck         append_str(&ptr, "'ProgramFilesDir',,\"%%24%%\"\n");
519c2c66affSColin Finck         append_str(&ptr, "[DestD]\n");
520c2c66affSColin Finck         append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n");
521c2c66affSColin Finck 
522c2c66affSColin Finck         WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
523c2c66affSColin Finck         CloseHandle(hf);
524c2c66affSColin Finck     }
525c2c66affSColin Finck 
526c2c66affSColin Finck     /* open the inf with the install section */
527c2c66affSColin Finck     hr = pOpenINFEngine(inf_file, "section", 0, &hinf, NULL);
528c2c66affSColin Finck     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
529c2c66affSColin Finck 
530c2c66affSColin Finck     /* Single quote test (Note size includes null on return from call) */
531c2c66affSColin Finck     memset(buffer, 'a', APP_PATH_LEN);
532c2c66affSColin Finck     buffer[APP_PATH_LEN - 1] = '\0';
533c2c66affSColin Finck     size = MAX_PATH;
534c2c66affSColin Finck     hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result2",
535c2c66affSColin Finck                               buffer, size, &size, NULL);
536c2c66affSColin Finck     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
537c2c66affSColin Finck     ok(!lstrcmpiA(buffer, PROG_FILES_ROOT),
538c2c66affSColin Finck            "Expected %s, got %s\n", PROG_FILES_ROOT, buffer);
539c2c66affSColin Finck     ok(size == strlen(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n",
540c2c66affSColin Finck            lstrlenA(PROG_FILES_ROOT)+1, size);
541c2c66affSColin Finck 
542c2c66affSColin Finck     /* close the INF again */
543c2c66affSColin Finck     hr = pCloseINFEngine(hinf);
544c2c66affSColin Finck     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
545c2c66affSColin Finck 
546c2c66affSColin Finck     DeleteFileA(inf_file);
547c2c66affSColin Finck }
548c2c66affSColin Finck 
check_reg_str(HKEY hkey,LPCSTR name,LPCSTR value)549c2c66affSColin Finck static BOOL check_reg_str(HKEY hkey, LPCSTR name, LPCSTR value)
550c2c66affSColin Finck {
551c2c66affSColin Finck     DWORD size = MAX_PATH;
552c2c66affSColin Finck     char check[MAX_PATH];
553c2c66affSColin Finck 
554c2c66affSColin Finck     if (RegQueryValueExA(hkey, name, NULL, NULL, (LPBYTE)check, &size))
555c2c66affSColin Finck         return FALSE;
556c2c66affSColin Finck 
557c2c66affSColin Finck     return !lstrcmpA(check, value);
558c2c66affSColin Finck }
559c2c66affSColin Finck 
check_reg_dword(HKEY hkey,LPCSTR name,DWORD value)560c2c66affSColin Finck static BOOL check_reg_dword(HKEY hkey, LPCSTR name, DWORD value)
561c2c66affSColin Finck {
562c2c66affSColin Finck     DWORD size = sizeof(DWORD);
563c2c66affSColin Finck     DWORD check;
564c2c66affSColin Finck 
565c2c66affSColin Finck     if (RegQueryValueExA(hkey, name, NULL, NULL, (LPBYTE)&check, &size))
566c2c66affSColin Finck         return FALSE;
567c2c66affSColin Finck 
568c2c66affSColin Finck     return (check == value);
569c2c66affSColin Finck }
570c2c66affSColin Finck 
setperusersecvalues_test(void)571c2c66affSColin Finck static void setperusersecvalues_test(void)
572c2c66affSColin Finck {
573c2c66affSColin Finck     PERUSERSECTIONA peruser;
574c2c66affSColin Finck     HRESULT hr;
575c2c66affSColin Finck     HKEY guid;
576c2c66affSColin Finck 
577c2c66affSColin Finck     lstrcpyA(peruser.szDispName, "displayname");
578c2c66affSColin Finck     lstrcpyA(peruser.szLocale, "locale");
579c2c66affSColin Finck     lstrcpyA(peruser.szStub, "stub");
580c2c66affSColin Finck     lstrcpyA(peruser.szVersion, "1,1,1,1");
581c2c66affSColin Finck     lstrcpyA(peruser.szCompID, "compid");
582c2c66affSColin Finck     peruser.dwIsInstalled = 1;
583c2c66affSColin Finck     peruser.bRollback = FALSE;
584c2c66affSColin Finck 
585c2c66affSColin Finck     /* try a NULL pPerUser */
586c2c66affSColin Finck     if (0)
587c2c66affSColin Finck     {
588c2c66affSColin Finck         /* This crashes on systems with IE7 */
589c2c66affSColin Finck         hr = pSetPerUserSecValues(NULL);
590c2c66affSColin Finck         todo_wine
591c2c66affSColin Finck         ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
592c2c66affSColin Finck         ok(!OPEN_GUID_KEY(), "Expected guid key to not exist\n");
593c2c66affSColin Finck     }
594c2c66affSColin Finck 
595c2c66affSColin Finck     /* at the very least, szGUID must be valid */
596c2c66affSColin Finck     peruser.szGUID[0] = '\0';
597c2c66affSColin Finck     hr = pSetPerUserSecValues(&peruser);
598c2c66affSColin Finck     ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
599c2c66affSColin Finck     ok(!OPEN_GUID_KEY(), "Expected guid key to not exist\n");
600c2c66affSColin Finck 
601c2c66affSColin Finck     /* set initial values */
602c2c66affSColin Finck     lstrcpyA(peruser.szGUID, "guid");
603c2c66affSColin Finck     hr = pSetPerUserSecValues(&peruser);
604c2c66affSColin Finck     if (hr == E_FAIL)
605c2c66affSColin Finck     {
606c2c66affSColin Finck         skip("SetPerUserSecValues is broken\n");
607c2c66affSColin Finck         return;
608c2c66affSColin Finck     }
609c2c66affSColin Finck     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
610c2c66affSColin Finck     ok(OPEN_GUID_KEY(), "Expected guid key to exist\n");
611c2c66affSColin Finck     ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
612c2c66affSColin Finck     ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
613c2c66affSColin Finck     ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
614c2c66affSColin Finck     ok(check_reg_str(guid, "StubPath", "stub"), "Expected stub\n");
615c2c66affSColin Finck     ok(check_reg_str(guid, "Version", "1,1,1,1"), "Expected 1,1,1,1\n");
616c2c66affSColin Finck     ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
617c2c66affSColin Finck     ok(!REG_VAL_EXISTS(guid, "OldDisplayName"), "Expected OldDisplayName to not exist\n");
618c2c66affSColin Finck     ok(!REG_VAL_EXISTS(guid, "OldLocale"), "Expected OldLocale to not exist\n");
619c2c66affSColin Finck     ok(!REG_VAL_EXISTS(guid, "OldStubPath"), "Expected OldStubPath to not exist\n");
620c2c66affSColin Finck     ok(!REG_VAL_EXISTS(guid, "OldVersion"), "Expected OldVersion to not exist\n");
621c2c66affSColin Finck     ok(!REG_VAL_EXISTS(guid, "RealStubPath"), "Expected RealStubPath to not exist\n");
622c2c66affSColin Finck 
623c2c66affSColin Finck     /* raise the version, but bRollback is FALSE, so vals not saved */
624c2c66affSColin Finck     lstrcpyA(peruser.szVersion, "2,1,1,1");
625c2c66affSColin Finck     hr = pSetPerUserSecValues(&peruser);
626c2c66affSColin Finck     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
627c2c66affSColin Finck     ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
628c2c66affSColin Finck     ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
629c2c66affSColin Finck     ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
630c2c66affSColin Finck     ok(check_reg_str(guid, "StubPath", "stub"), "Expected stub\n");
631c2c66affSColin Finck     ok(check_reg_str(guid, "Version", "2,1,1,1"), "Expected 2,1,1,1\n");
632c2c66affSColin Finck     ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
633c2c66affSColin Finck     ok(!REG_VAL_EXISTS(guid, "OldDisplayName"), "Expected OldDisplayName to not exist\n");
634c2c66affSColin Finck     ok(!REG_VAL_EXISTS(guid, "OldLocale"), "Expected OldLocale to not exist\n");
635c2c66affSColin Finck     ok(!REG_VAL_EXISTS(guid, "OldStubPath"), "Expected OldStubPath to not exist\n");
636c2c66affSColin Finck     ok(!REG_VAL_EXISTS(guid, "OldVersion"), "Expected OldVersion to not exist\n");
637c2c66affSColin Finck     ok(!REG_VAL_EXISTS(guid, "RealStubPath"), "Expected RealStubPath to not exist\n");
638c2c66affSColin Finck 
639c2c66affSColin Finck     /* raise the version again, bRollback is TRUE so vals are saved */
640c2c66affSColin Finck     peruser.bRollback = TRUE;
641c2c66affSColin Finck     lstrcpyA(peruser.szVersion, "3,1,1,1");
642c2c66affSColin Finck     hr = pSetPerUserSecValues(&peruser);
643c2c66affSColin Finck     ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
644c2c66affSColin Finck     ok(check_reg_str(guid, NULL, "displayname"), "Expected displayname\n");
645c2c66affSColin Finck     ok(check_reg_str(guid, "ComponentID", "compid"), "Expected compid\n");
646c2c66affSColin Finck     ok(check_reg_str(guid, "Locale", "locale"), "Expected locale\n");
647c2c66affSColin Finck     ok(check_reg_dword(guid, "IsInstalled", 1), "Expected 1\n");
648c2c66affSColin Finck     ok(check_reg_str(guid, "Version", "3,1,1,1"), "Expected 3,1,1,1\n");
649c2c66affSColin Finck     todo_wine
650c2c66affSColin Finck     {
651c2c66affSColin Finck         ok(check_reg_str(guid, "OldDisplayName", "displayname"), "Expected displayname\n");
652c2c66affSColin Finck         ok(check_reg_str(guid, "OldLocale", "locale"), "Expected locale\n");
653c2c66affSColin Finck         ok(check_reg_str(guid, "RealStubPath", "stub"), "Expected stub\n");
654c2c66affSColin Finck         ok(check_reg_str(guid, "OldStubPath", "stub"), "Expected stub\n");
655c2c66affSColin Finck         ok(check_reg_str(guid, "OldVersion", "2,1,1,1"), "Expected 2,1,1,1\n");
656c2c66affSColin Finck         ok(check_reg_str(guid, "StubPath",
657c2c66affSColin Finck            "rundll32.exe advpack.dll,UserInstStubWrapper guid"),
658c2c66affSColin Finck            "Expected real stub\n");
659c2c66affSColin Finck     }
660c2c66affSColin Finck 
661c2c66affSColin Finck     RegDeleteKeyA(HKEY_LOCAL_MACHINE, GUID_KEY);
662c2c66affSColin Finck }
663c2c66affSColin Finck 
START_TEST(advpack)664c2c66affSColin Finck START_TEST(advpack)
665c2c66affSColin Finck {
666c2c66affSColin Finck     if (!init_function_pointers())
667c2c66affSColin Finck         return;
668c2c66affSColin Finck 
669c2c66affSColin Finck     /* Make sure we create the temporary file in a directory
670c2c66affSColin Finck      * where we have adequate rights
671c2c66affSColin Finck      */
672c2c66affSColin Finck     GetTempPathA(MAX_PATH, inf_file);
673c2c66affSColin Finck     lstrcatA(inf_file,"test.inf");
674c2c66affSColin Finck 
675c2c66affSColin Finck     get_progfiles_dir();
676c2c66affSColin Finck 
677c2c66affSColin Finck     version_test();
678c2c66affSColin Finck     delnode_test();
679c2c66affSColin Finck     setperusersecvalues_test();
680c2c66affSColin Finck     translateinfstring_test();
681c2c66affSColin Finck     translateinfstringex_test();
682c2c66affSColin Finck 
683c2c66affSColin Finck     FreeLibrary(hAdvPack);
684c2c66affSColin Finck }
685