2 * Unit tests for advpack.dll install functions
4 * Copyright (C) 2006 James Hawkins
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/test.h"
26 static HMODULE hAdvPack;
27 /* function pointers */
28 static HRESULT (WINAPI *pRunSetupCommand)(HWND, LPCSTR, LPCSTR, LPCSTR, LPCSTR, HANDLE*, DWORD, LPVOID);
29 static HRESULT (WINAPI *pLaunchINFSection)(HWND, HINSTANCE, LPSTR, INT);
30 static HRESULT (WINAPI *pLaunchINFSectionEx)(HWND, HINSTANCE, LPSTR, INT);
32 static char CURR_DIR[MAX_PATH];
34 static BOOL init_function_pointers(void)
36 hAdvPack = LoadLibraryA("advpack.dll");
40 pRunSetupCommand = (void *)GetProcAddress(hAdvPack, "RunSetupCommand");
41 pLaunchINFSection = (void *)GetProcAddress(hAdvPack, "LaunchINFSection");
42 pLaunchINFSectionEx = (void *)GetProcAddress(hAdvPack, "LaunchINFSectionEx");
44 if (!pRunSetupCommand || !pLaunchINFSection || !pLaunchINFSectionEx)
50 static BOOL is_spapi_err(DWORD err)
52 const DWORD SPAPI_PREFIX = 0x800F0000L;
53 const DWORD SPAPI_MASK = 0xFFFF0000L;
55 return (((err & SPAPI_MASK) ^ SPAPI_PREFIX) == 0);
58 static void append_str(char **str, const char *data)
64 static void create_inf_file(LPCSTR filename)
68 DWORD dwNumberOfBytesWritten;
69 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
70 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
72 append_str(&ptr, "[Version]\n");
73 append_str(&ptr, "Signature=\"$Chicago$\"\n");
74 append_str(&ptr, "AdvancedINF=2.5\n");
75 append_str(&ptr, "[DefaultInstall]\n");
76 append_str(&ptr, "CheckAdminRights=1\n");
78 WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
82 static void test_RunSetupCommand(void)
88 char systemdir[MAX_PATH];
90 GetSystemDirectoryA(systemdir, sizeof(systemdir));
92 /* try an invalid cmd name */
93 hr = pRunSetupCommand(NULL, NULL, "Install", "Dir", "Title", NULL, 0, NULL);
94 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
96 /* try an invalid directory */
97 hr = pRunSetupCommand(NULL, "winver.exe", "Install", NULL, "Title", NULL, 0, NULL);
98 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
100 /* try to run a nonexistent exe */
101 hexe = (HANDLE)0xdeadbeef;
102 hr = pRunSetupCommand(NULL, "idontexist.exe", "Install", systemdir, "Title", &hexe, 0, NULL);
103 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
104 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr);
105 ok(hexe == NULL, "Expcted hexe to be NULL\n");
106 ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n");
108 /* try a bad directory */
109 hexe = (HANDLE)0xdeadbeef;
110 hr = pRunSetupCommand(NULL, "winver.exe", "Install", "non\\existent\\directory", "Title", &hexe, 0, NULL);
111 ok(hr == HRESULT_FROM_WIN32(ERROR_DIRECTORY),
112 "Expected HRESULT_FROM_WIN32(ERROR_DIRECTORY), got %d\n", hr);
113 ok(hexe == NULL, "Expcted hexe to be NULL\n");
114 ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n");
116 /* try to run an exe with the RSC_FLAG_INF flag */
117 hexe = (HANDLE)0xdeadbeef;
118 hr = pRunSetupCommand(NULL, "winver.exe", "Install", systemdir, "Title", &hexe, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
119 ok(is_spapi_err(hr) ||
120 hr == E_FAIL, /* win9x */
121 "Expected a setupapi error or E_FAIL, got %d\n", hr);
122 ok(hexe == (HANDLE)0xdeadbeef, "Expected hexe to be 0xdeadbeef\n");
123 ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n");
126 hexe = (HANDLE)0xdeadbeef;
127 hr = pRunSetupCommand(NULL, "winver.exe", "Install", systemdir, "Title", &hexe, 0, NULL);
128 ok(hr == S_ASYNCHRONOUS, "Expected S_ASYNCHRONOUS, got %d\n", hr);
129 ok(hexe != NULL, "Expected hexe to be non-NULL\n");
130 ok(TerminateProcess(hexe, 0), "Expected TerminateProcess to succeed\n");
132 CreateDirectoryA("one", NULL);
133 create_inf_file("one\\test.inf");
135 /* try a full path to the INF, with working dir provided */
136 lstrcpy(path, CURR_DIR);
137 lstrcat(path, "\\one\\test.inf");
138 lstrcpy(dir, CURR_DIR);
139 lstrcat(dir, "\\one");
140 hr = pRunSetupCommand(NULL, path, "DefaultInstall", dir, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
141 ok(hr == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", hr);
143 /* try a full path to the INF, NULL working dir */
144 hr = pRunSetupCommand(NULL, path, "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
145 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
146 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr);
148 /* try a full path to the INF, empty working dir */
149 hr = pRunSetupCommand(NULL, path, "DefaultInstall", "", "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
150 ok(hr == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", hr);
152 /* try a relative path to the INF, with working dir provided */
153 hr = pRunSetupCommand(NULL, "one\\test.inf", "DefaultInstall", dir, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
154 ok(hr == ERROR_SUCCESS ||
155 hr == E_FAIL, /* win9x */
156 "Expected ERROR_SUCCESS, got %d\n", hr);
158 /* try a relative path to the INF, NULL working dir */
159 hr = pRunSetupCommand(NULL, "one\\test.inf", "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
160 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
161 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr);
163 /* try a relative path to the INF, empty working dir */
164 hr = pRunSetupCommand(NULL, "one\\test.inf", "DefaultInstall", "", "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
165 ok(hr == ERROR_SUCCESS ||
166 hr == E_FAIL, /* win9x */
167 "Expected ERROR_SUCCESS or E_FAIL, got %d\n", hr);
169 /* try only the INF filename, with working dir provided */
170 hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", dir, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
171 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
172 hr == E_FAIL, /* win9x */
173 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) or E_FAIL, got %d\n", hr);
175 /* try only the INF filename, NULL working dir */
176 hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
177 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
178 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr);
180 /* try only the INF filename, empty working dir */
181 hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", "", "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
182 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
183 hr == E_FAIL, /* win9x */
184 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) or E_FAIL, got %d\n", hr);
186 DeleteFileA("one\\test.inf");
187 RemoveDirectoryA("one");
189 create_inf_file("test.inf");
191 /* try INF file in the current directory, working directory provided */
192 hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", CURR_DIR, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
193 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
194 hr == E_FAIL, /* win9x */
195 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) or E_FAIL, got %d\n", hr);
197 /* try INF file in the current directory, NULL working directory */
198 hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
199 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
200 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr);
202 /* try INF file in the current directory, empty working directory */
203 hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", CURR_DIR, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
204 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
205 hr == E_FAIL, /* win9x */
206 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) or E_FAIL, got %d\n", hr);
209 static void test_LaunchINFSection(void)
212 char cmdline[MAX_PATH];
213 static char file[] = "test.inf,DefaultInstall,4,0";
215 /* The 'No UI' flag seems to have no effect whatsoever on Windows.
216 * So only do this test in interactive mode.
218 if (winetest_interactive)
220 /* try an invalid cmdline */
221 hr = pLaunchINFSection(NULL, NULL, NULL, 0);
222 ok(hr == 1, "Expected 1, got %d\n", hr);
225 CreateDirectoryA("one", NULL);
226 create_inf_file("one\\test.inf");
228 /* try a full path to the INF */
229 lstrcpy(cmdline, CURR_DIR);
230 lstrcat(cmdline, "\\");
231 lstrcat(cmdline, "one\\test.inf,DefaultInstall,,4");
232 hr = pLaunchINFSection(NULL, NULL, cmdline, 0);
233 ok(hr == 0, "Expected 0, got %d\n", hr);
235 DeleteFileA("one\\test.inf");
236 RemoveDirectoryA("one");
238 create_inf_file("test.inf");
240 /* try just the INF filename */
241 hr = pLaunchINFSection(NULL, NULL, file, 0);
242 ok(hr == 0, "Expected 0, got %d\n", hr);
244 DeleteFileA("test.inf");
247 static void test_LaunchINFSectionEx(void)
250 char cmdline[MAX_PATH];
252 create_inf_file("test.inf");
254 /* try an invalid CAB filename with an absolute INF name */
255 lstrcpy(cmdline, CURR_DIR);
256 lstrcat(cmdline, "\\");
257 lstrcat(cmdline, "test.inf,DefaultInstall,c:imacab.cab,4");
258 hr = pLaunchINFSectionEx(NULL, NULL, cmdline, 0);
259 ok(hr == 0, "Expected 0, got %d\n", hr);
261 /* The 'No UI' flag seems to have no effect whatsoever on Windows.
262 * So only do this test in interactive mode.
264 if (winetest_interactive)
266 /* try an invalid CAB filename with a relative INF name */
267 lstrcpy(cmdline, "test.inf,DefaultInstall,c:imacab.cab,4");
268 hr = pLaunchINFSectionEx(NULL, NULL, cmdline, 0);
269 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
272 DeleteFileA("test.inf");
278 char temp_path[MAX_PATH], prev_path[MAX_PATH];
280 if (!init_function_pointers())
283 GetCurrentDirectoryA(MAX_PATH, prev_path);
284 GetTempPath(MAX_PATH, temp_path);
285 SetCurrentDirectoryA(temp_path);
287 lstrcpyA(CURR_DIR, temp_path);
288 len = lstrlenA(CURR_DIR);
290 if(len && (CURR_DIR[len - 1] == '\\'))
291 CURR_DIR[len - 1] = 0;
293 test_RunSetupCommand();
294 test_LaunchINFSection();
295 test_LaunchINFSectionEx();
297 FreeLibrary(hAdvPack);
298 SetCurrentDirectoryA(prev_path);