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
= CreateFileA(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 */
95 hexe
= (HANDLE
)(ULONG_PTR
)0xdeadbeefdeadbeefull
;
97 hexe
= (HANDLE
)0xdeadbeef;
99 hr
= pRunSetupCommand(NULL
, "idontexist.exe", "Install", systemdir
, "Title", &hexe
, 0, NULL
);
100 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
101 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr
);
102 ok(hexe
== NULL
, "Expected hexe to be NULL\n");
103 ok(!TerminateProcess(hexe
, 0), "Expected TerminateProcess to fail\n");
105 /* try a bad directory */
107 hexe
= (HANDLE
)(ULONG_PTR
)0xdeadbeefdeadbeefull
;
109 hexe
= (HANDLE
)0xdeadbeef;
111 hr
= pRunSetupCommand(NULL
, "winver.exe", "Install", "non\\existent\\directory", "Title", &hexe
, 0, NULL
);
112 ok(hr
== HRESULT_FROM_WIN32(ERROR_DIRECTORY
),
113 "Expected HRESULT_FROM_WIN32(ERROR_DIRECTORY), got %d\n", hr
);
114 ok(hexe
== NULL
, "Expected hexe to be NULL\n");
115 ok(!TerminateProcess(hexe
, 0), "Expected TerminateProcess to fail\n");
117 /* try to run an exe with the RSC_FLAG_INF flag */
119 hexe
= (HANDLE
)(ULONG_PTR
)0xdeadbeefdeadbeefull
;
121 hexe
= (HANDLE
)0xdeadbeef;
123 hr
= pRunSetupCommand(NULL
, "winver.exe", "Install", systemdir
, "Title", &hexe
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
124 ok(is_spapi_err(hr
), "Expected a setupapi error, got %d\n", hr
);
126 ok(hexe
== (HANDLE
)(ULONG_PTR
)0xdeadbeefdeadbeefull
, "Expected hexe to be 0xdeadbeef\n");
128 ok(hexe
== (HANDLE
)0xdeadbeef, "Expected hexe to be 0xdeadbeef\n");
130 ok(!TerminateProcess(hexe
, 0), "Expected TerminateProcess to fail\n");
134 hexe
= (HANDLE
)(ULONG_PTR
)0xdeadbeefdeadbeefull
;
136 hexe
= (HANDLE
)0xdeadbeef;
138 hr
= pRunSetupCommand(NULL
, "winver.exe", "Install", systemdir
, "Title", &hexe
, 0, NULL
);
139 ok(hr
== S_ASYNCHRONOUS
, "Expected S_ASYNCHRONOUS, got %d\n", hr
);
140 ok(hexe
!= NULL
, "Expected hexe to be non-NULL\n");
141 ok(TerminateProcess(hexe
, 0), "Expected TerminateProcess to succeed\n");
143 CreateDirectoryA("one", NULL
);
144 create_inf_file("one\\test.inf");
146 /* try a full path to the INF, with working dir provided */
147 lstrcpyA(path
, CURR_DIR
);
148 lstrcatA(path
, "\\one\\test.inf");
149 lstrcpyA(dir
, CURR_DIR
);
150 lstrcatA(dir
, "\\one");
151 hr
= pRunSetupCommand(NULL
, path
, "DefaultInstall", dir
, "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
152 ok(hr
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", hr
);
154 /* try a full path to the INF, NULL working dir */
155 hr
= pRunSetupCommand(NULL
, path
, "DefaultInstall", NULL
, "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
156 ok(hr
== HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER
),
157 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr
);
159 /* try a full path to the INF, empty working dir */
160 hr
= pRunSetupCommand(NULL
, path
, "DefaultInstall", "", "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
161 ok(hr
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", hr
);
163 /* try a relative path to the INF, with working dir provided */
164 hr
= pRunSetupCommand(NULL
, "one\\test.inf", "DefaultInstall", dir
, "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
165 ok(hr
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", hr
);
167 /* try a relative path to the INF, NULL working dir */
168 hr
= pRunSetupCommand(NULL
, "one\\test.inf", "DefaultInstall", NULL
, "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
169 ok(hr
== HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER
),
170 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr
);
172 /* try a relative path to the INF, empty working dir */
173 hr
= pRunSetupCommand(NULL
, "one\\test.inf", "DefaultInstall", "", "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
174 ok(hr
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", hr
);
176 /* try only the INF filename, with working dir provided */
177 hr
= pRunSetupCommand(NULL
, "test.inf", "DefaultInstall", dir
, "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
178 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
), "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr
);
180 /* try only the INF filename, NULL working dir */
181 hr
= pRunSetupCommand(NULL
, "test.inf", "DefaultInstall", NULL
, "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
182 ok(hr
== HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER
),
183 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr
);
185 /* try only the INF filename, empty working dir */
186 hr
= pRunSetupCommand(NULL
, "test.inf", "DefaultInstall", "", "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
187 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
), "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr
);
189 DeleteFileA("one\\test.inf");
190 RemoveDirectoryA("one");
192 create_inf_file("test.inf");
194 /* try INF file in the current directory, working directory provided */
195 hr
= pRunSetupCommand(NULL
, "test.inf", "DefaultInstall", CURR_DIR
, "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
196 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
), "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr
);
198 /* try INF file in the current directory, NULL working directory */
199 hr
= pRunSetupCommand(NULL
, "test.inf", "DefaultInstall", NULL
, "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
200 ok(hr
== HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER
),
201 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr
);
203 /* try INF file in the current directory, empty working directory */
204 hr
= pRunSetupCommand(NULL
, "test.inf", "DefaultInstall", CURR_DIR
, "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
205 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
), "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr
);
208 static void test_LaunchINFSection(void)
211 char cmdline
[MAX_PATH
];
212 static char file
[] = "test.inf,DefaultInstall,4,0";
213 static char file2
[] = "test.inf,,1,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 lstrcpyA(cmdline
, CURR_DIR
);
230 lstrcatA(cmdline
, "\\");
231 lstrcatA(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 hr
= pLaunchINFSection(NULL
, NULL
, file2
, 0);
245 ok(hr
== 0, "Expected 0, got %d\n", hr
);
247 DeleteFileA("test.inf");
250 static void test_LaunchINFSectionEx(void)
253 char cmdline
[MAX_PATH
];
255 create_inf_file("test.inf");
257 /* try an invalid CAB filename with an absolute INF name */
258 lstrcpyA(cmdline
, CURR_DIR
);
259 lstrcatA(cmdline
, "\\");
260 lstrcatA(cmdline
, "test.inf,DefaultInstall,c:imacab.cab,4");
261 hr
= pLaunchINFSectionEx(NULL
, NULL
, cmdline
, 0);
262 ok(hr
== 0, "Expected 0, got %d\n", hr
);
264 /* try quoting the parameters */
265 lstrcpyA(cmdline
, "\"");
266 lstrcatA(cmdline
, CURR_DIR
);
267 lstrcatA(cmdline
, "\\test.inf\",\"DefaultInstall\",\"c:,imacab.cab\",\"4\"");
268 hr
= pLaunchINFSectionEx(NULL
, NULL
, cmdline
, 0);
269 ok(hr
== 0, "Expected 0, got %d\n", hr
);
271 /* The 'No UI' flag seems to have no effect whatsoever on Windows.
272 * So only do this test in interactive mode.
274 if (winetest_interactive
)
276 /* try an invalid CAB filename with a relative INF name */
277 lstrcpyA(cmdline
, "test.inf,DefaultInstall,c:imacab.cab,4");
278 hr
= pLaunchINFSectionEx(NULL
, NULL
, cmdline
, 0);
279 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %d\n", hr
);
282 DeleteFileA("test.inf");
288 char temp_path
[MAX_PATH
], prev_path
[MAX_PATH
];
290 if (!init_function_pointers())
293 if (!IsNTAdmin(0, NULL
))
295 skip("Most tests need admin rights\n");
299 GetCurrentDirectoryA(MAX_PATH
, prev_path
);
300 GetTempPathA(MAX_PATH
, temp_path
);
301 SetCurrentDirectoryA(temp_path
);
303 lstrcpyA(CURR_DIR
, temp_path
);
304 len
= lstrlenA(CURR_DIR
);
306 if(len
&& (CURR_DIR
[len
- 1] == '\\'))
307 CURR_DIR
[len
- 1] = 0;
309 test_RunSetupCommand();
310 test_LaunchINFSection();
311 test_LaunchINFSectionEx();
313 FreeLibrary(hAdvPack
);
314 SetCurrentDirectoryA(prev_path
);