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
, "RegisterOCXs=RegisterOCXsSection\n");
77 append_str(&ptr
, "[RegisterOCXsSection]\n");
78 append_str(&ptr
, "%%11%%\\ole32.dll\n");
80 WriteFile(hf
, data
, ptr
- data
, &dwNumberOfBytesWritten
, NULL
);
84 static void test_RunSetupCommand(void)
90 char systemdir
[MAX_PATH
];
92 GetSystemDirectoryA(systemdir
, sizeof(systemdir
));
94 /* try an invalid cmd name */
95 hr
= pRunSetupCommand(NULL
, NULL
, "Install", "Dir", "Title", NULL
, 0, NULL
);
96 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %d\n", hr
);
98 /* try an invalid directory */
99 hr
= pRunSetupCommand(NULL
, "winver.exe", "Install", NULL
, "Title", NULL
, 0, NULL
);
100 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %d\n", hr
);
102 /* try to run a nonexistent exe */
103 hexe
= (HANDLE
)0xdeadbeef;
104 hr
= pRunSetupCommand(NULL
, "idontexist.exe", "Install", systemdir
, "Title", &hexe
, 0, NULL
);
105 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
106 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr
);
107 ok(hexe
== NULL
, "Expcted hexe to be NULL\n");
108 ok(!TerminateProcess(hexe
, 0), "Expected TerminateProcess to fail\n");
110 /* try a bad directory */
111 hexe
= (HANDLE
)0xdeadbeef;
112 hr
= pRunSetupCommand(NULL
, "winver.exe", "Install", "non\\existent\\directory", "Title", &hexe
, 0, NULL
);
113 ok(hr
== HRESULT_FROM_WIN32(ERROR_DIRECTORY
),
114 "Expected HRESULT_FROM_WIN32(ERROR_DIRECTORY), got %d\n", hr
);
115 ok(hexe
== NULL
, "Expcted hexe to be NULL\n");
116 ok(!TerminateProcess(hexe
, 0), "Expected TerminateProcess to fail\n");
118 /* try to run an exe with the RSC_FLAG_INF flag */
119 hexe
= (HANDLE
)0xdeadbeef;
120 hr
= pRunSetupCommand(NULL
, "winver.exe", "Install", systemdir
, "Title", &hexe
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
121 ok(is_spapi_err(hr
), "Expected a setupapi error, 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
, "Expected ERROR_SUCCESS, got %d\n", hr
);
156 /* try a relative path to the INF, NULL working dir */
157 hr
= pRunSetupCommand(NULL
, "one\\test.inf", "DefaultInstall", NULL
, "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
158 ok(hr
== HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER
),
159 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr
);
161 /* try a relative path to the INF, empty working dir */
162 hr
= pRunSetupCommand(NULL
, "one\\test.inf", "DefaultInstall", "", "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
163 ok(hr
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", hr
);
165 /* try only the INF filename, with working dir provided */
166 hr
= pRunSetupCommand(NULL
, "test.inf", "DefaultInstall", dir
, "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
167 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
168 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr
);
170 /* try only the INF filename, NULL working dir */
171 hr
= pRunSetupCommand(NULL
, "test.inf", "DefaultInstall", NULL
, "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
172 ok(hr
== HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER
),
173 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr
);
175 /* try only the INF filename, empty working dir */
176 hr
= pRunSetupCommand(NULL
, "test.inf", "DefaultInstall", "", "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
177 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
178 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr
);
180 DeleteFileA("one\\test.inf");
181 RemoveDirectoryA("one");
183 create_inf_file("test.inf");
185 /* try INF file in the current directory, working directory provided */
186 hr
= pRunSetupCommand(NULL
, "test.inf", "DefaultInstall", CURR_DIR
, "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
187 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
188 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), 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 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr
);
201 static void test_LaunchINFSection(void)
204 char cmdline
[MAX_PATH
];
205 static char file
[] = "test.inf,DefaultInstall,4,0";
207 /* The 'No UI' flag seems to have no effect whatsoever on Windows.
208 * So only do this test in interactive mode.
210 if (winetest_interactive
)
212 /* try an invalid cmdline */
213 hr
= pLaunchINFSection(NULL
, NULL
, NULL
, 0);
214 ok(hr
== 1, "Expected 1, got %d\n", hr
);
217 CreateDirectoryA("one", NULL
);
218 create_inf_file("one\\test.inf");
220 /* try a full path to the INF */
221 lstrcpy(cmdline
, CURR_DIR
);
222 lstrcat(cmdline
, "\\");
223 lstrcat(cmdline
, "one\\test.inf,DefaultInstall,,4");
224 hr
= pLaunchINFSection(NULL
, NULL
, cmdline
, 0);
225 ok(hr
== 0, "Expected 0, got %d\n", hr
);
227 DeleteFileA("one\\test.inf");
228 RemoveDirectoryA("one");
230 create_inf_file("test.inf");
232 /* try just the INF filename */
233 hr
= pLaunchINFSection(NULL
, NULL
, file
, 0);
234 ok(hr
== 0, "Expected 0, got %d\n", hr
);
236 DeleteFileA("test.inf");
239 static void test_LaunchINFSectionEx(void)
242 char cmdline
[MAX_PATH
];
244 create_inf_file("test.inf");
246 /* try an invalid CAB filename with an absolute INF name */
247 lstrcpy(cmdline
, CURR_DIR
);
248 lstrcat(cmdline
, "\\");
249 lstrcat(cmdline
, "test.inf,DefaultInstall,c:imacab.cab,4");
250 hr
= pLaunchINFSectionEx(NULL
, NULL
, cmdline
, 0);
251 ok(hr
== 0, "Expected 0, got %d\n", hr
);
253 /* The 'No UI' flag seems to have no effect whatsoever on Windows.
254 * So only do this test in interactive mode.
256 if (winetest_interactive
)
258 /* try an invalid CAB filename with a relative INF name */
259 lstrcpy(cmdline
, "test.inf,DefaultInstall,c:imacab.cab,4");
260 hr
= pLaunchINFSectionEx(NULL
, NULL
, cmdline
, 0);
261 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %d\n", hr
);
264 DeleteFileA("test.inf");
269 if (!init_function_pointers())
272 GetCurrentDirectoryA(MAX_PATH
, CURR_DIR
);
274 test_RunSetupCommand();
275 test_LaunchINFSection();
276 test_LaunchINFSectionEx();
278 FreeLibrary(hAdvPack
);