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 create_inf_file(LPCSTR filename)
60 DWORD dwNumberOfBytesWritten;
61 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
62 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
64 static const char data[] =
66 "Signature=\"$Chicago$\"\n"
69 "CheckAdminRights=1\n";
71 WriteFile(hf, data, sizeof(data) - 1, &dwNumberOfBytesWritten, NULL);
75 static void test_RunSetupCommand(void)
81 char systemdir[MAX_PATH];
83 GetSystemDirectoryA(systemdir, sizeof(systemdir));
85 /* try an invalid cmd name */
86 hr = pRunSetupCommand(NULL, NULL, "Install", "Dir", "Title", NULL, 0, NULL);
87 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
89 /* try an invalid directory */
90 hr = pRunSetupCommand(NULL, "winver.exe", "Install", NULL, "Title", NULL, 0, NULL);
91 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
93 /* try to run a nonexistent exe */
94 hexe = (HANDLE)0xdeadbeef;
95 hr = pRunSetupCommand(NULL, "idontexist.exe", "Install", systemdir, "Title", &hexe, 0, NULL);
96 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
97 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr);
98 ok(hexe == NULL, "Expcted hexe to be NULL\n");
99 ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n");
101 /* try a bad directory */
102 hexe = (HANDLE)0xdeadbeef;
103 hr = pRunSetupCommand(NULL, "winver.exe", "Install", "non\\existent\\directory", "Title", &hexe, 0, NULL);
104 ok(hr == HRESULT_FROM_WIN32(ERROR_DIRECTORY),
105 "Expected HRESULT_FROM_WIN32(ERROR_DIRECTORY), got %d\n", hr);
106 ok(hexe == NULL, "Expcted hexe to be NULL\n");
107 ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n");
109 /* try to run an exe with the RSC_FLAG_INF flag */
110 hexe = (HANDLE)0xdeadbeef;
111 hr = pRunSetupCommand(NULL, "winver.exe", "Install", systemdir, "Title", &hexe, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
112 ok(is_spapi_err(hr) ||
113 hr == E_FAIL, /* win9x */
114 "Expected a setupapi error or E_FAIL, got %d\n", hr);
115 ok(hexe == (HANDLE)0xdeadbeef, "Expected hexe to be 0xdeadbeef\n");
116 ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n");
119 hexe = (HANDLE)0xdeadbeef;
120 hr = pRunSetupCommand(NULL, "winver.exe", "Install", systemdir, "Title", &hexe, 0, NULL);
121 ok(hr == S_ASYNCHRONOUS, "Expected S_ASYNCHRONOUS, got %d\n", hr);
122 ok(hexe != NULL, "Expected hexe to be non-NULL\n");
123 ok(TerminateProcess(hexe, 0), "Expected TerminateProcess to succeed\n");
125 CreateDirectoryA("one", NULL);
126 create_inf_file("one\\test.inf");
128 /* try a full path to the INF, with working dir provided */
129 lstrcpy(path, CURR_DIR);
130 lstrcat(path, "\\one\\test.inf");
131 lstrcpy(dir, CURR_DIR);
132 lstrcat(dir, "\\one");
133 hr = pRunSetupCommand(NULL, path, "DefaultInstall", dir, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
134 ok(hr == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", hr);
136 /* try a full path to the INF, NULL working dir */
137 hr = pRunSetupCommand(NULL, path, "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
138 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
139 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr);
141 /* try a full path to the INF, empty working dir */
142 hr = pRunSetupCommand(NULL, path, "DefaultInstall", "", "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
143 ok(hr == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", hr);
145 /* try a relative path to the INF, with working dir provided */
146 hr = pRunSetupCommand(NULL, "one\\test.inf", "DefaultInstall", dir, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
147 ok(hr == ERROR_SUCCESS ||
148 hr == E_FAIL, /* win9x */
149 "Expected ERROR_SUCCESS, got %d\n", hr);
151 /* try a relative path to the INF, NULL working dir */
152 hr = pRunSetupCommand(NULL, "one\\test.inf", "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
153 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
154 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr);
156 /* try a relative path to the INF, empty working dir */
157 hr = pRunSetupCommand(NULL, "one\\test.inf", "DefaultInstall", "", "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
158 ok(hr == ERROR_SUCCESS ||
159 hr == E_FAIL, /* win9x */
160 "Expected ERROR_SUCCESS or E_FAIL, got %d\n", hr);
162 /* try only the INF filename, with working dir provided */
163 hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", dir, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
164 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
165 hr == E_FAIL, /* win9x */
166 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) or E_FAIL, got %d\n", hr);
168 /* try only the INF filename, NULL working dir */
169 hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
170 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
171 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr);
173 /* try only the INF filename, empty working dir */
174 hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", "", "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
175 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
176 hr == E_FAIL, /* win9x */
177 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) or E_FAIL, got %d\n", hr);
179 DeleteFileA("one\\test.inf");
180 RemoveDirectoryA("one");
182 create_inf_file("test.inf");
184 /* try INF file in the current directory, working directory provided */
185 hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", CURR_DIR, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
186 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
187 hr == E_FAIL, /* win9x */
188 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) or E_FAIL, got %d\n", hr);
190 /* try INF file in the current directory, NULL working directory */
191 hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
192 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
193 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr);
195 /* try INF file in the current directory, empty working directory */
196 hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", CURR_DIR, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
197 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) ||
198 hr == E_FAIL, /* win9x */
199 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) or E_FAIL, got %d\n", hr);
202 static void test_LaunchINFSection(void)
205 char cmdline[MAX_PATH];
206 static char file[] = "test.inf,DefaultInstall,4,0";
208 /* The 'No UI' flag seems to have no effect whatsoever on Windows.
209 * So only do this test in interactive mode.
211 if (winetest_interactive)
213 /* try an invalid cmdline */
214 hr = pLaunchINFSection(NULL, NULL, NULL, 0);
215 ok(hr == 1, "Expected 1, got %d\n", hr);
218 CreateDirectoryA("one", NULL);
219 create_inf_file("one\\test.inf");
221 /* try a full path to the INF */
222 lstrcpy(cmdline, CURR_DIR);
223 lstrcat(cmdline, "\\");
224 lstrcat(cmdline, "one\\test.inf,DefaultInstall,,4");
225 hr = pLaunchINFSection(NULL, NULL, cmdline, 0);
226 ok(hr == 0, "Expected 0, got %d\n", hr);
228 DeleteFileA("one\\test.inf");
229 RemoveDirectoryA("one");
231 create_inf_file("test.inf");
233 /* try just the INF filename */
234 hr = pLaunchINFSection(NULL, NULL, file, 0);
235 ok(hr == 0, "Expected 0, got %d\n", hr);
237 DeleteFileA("test.inf");
240 static void test_LaunchINFSectionEx(void)
243 char cmdline[MAX_PATH];
245 create_inf_file("test.inf");
247 /* try an invalid CAB filename with an absolute INF name */
248 lstrcpy(cmdline, CURR_DIR);
249 lstrcat(cmdline, "\\");
250 lstrcat(cmdline, "test.inf,DefaultInstall,c:imacab.cab,4");
251 hr = pLaunchINFSectionEx(NULL, NULL, cmdline, 0);
252 ok(hr == 0, "Expected 0, got %d\n", hr);
254 /* The 'No UI' flag seems to have no effect whatsoever on Windows.
255 * So only do this test in interactive mode.
257 if (winetest_interactive)
259 /* try an invalid CAB filename with a relative INF name */
260 lstrcpy(cmdline, "test.inf,DefaultInstall,c:imacab.cab,4");
261 hr = pLaunchINFSectionEx(NULL, NULL, cmdline, 0);
262 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
265 DeleteFileA("test.inf");
271 char temp_path[MAX_PATH], prev_path[MAX_PATH];
273 if (!init_function_pointers())
276 GetCurrentDirectoryA(MAX_PATH, prev_path);
277 GetTempPath(MAX_PATH, temp_path);
278 SetCurrentDirectoryA(temp_path);
280 lstrcpyA(CURR_DIR, temp_path);
281 len = lstrlenA(CURR_DIR);
283 if(len && (CURR_DIR[len - 1] == '\\'))
284 CURR_DIR[len - 1] = 0;
286 test_RunSetupCommand();
287 test_LaunchINFSection();
288 test_LaunchINFSectionEx();
290 FreeLibrary(hAdvPack);
291 SetCurrentDirectoryA(prev_path);