ReactOS 0.4.15-dev-7953-g1f49173
install.c
Go to the documentation of this file.
1/*
2 * Unit tests for advpack.dll install functions
3 *
4 * Copyright (C) 2006 James Hawkins
5 *
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.
10 *
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.
15 *
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
19 */
20
21#include <stdio.h>
22#include <windows.h>
23#include <advpub.h>
24#include "wine/test.h"
25
27/* function pointers */
28static HRESULT (WINAPI *pRunSetupCommand)(HWND, LPCSTR, LPCSTR, LPCSTR, LPCSTR, HANDLE*, DWORD, LPVOID);
29static HRESULT (WINAPI *pLaunchINFSection)(HWND, HINSTANCE, LPSTR, INT);
30static HRESULT (WINAPI *pLaunchINFSectionEx)(HWND, HINSTANCE, LPSTR, INT);
31
32static char CURR_DIR[MAX_PATH];
33
35{
36 hAdvPack = LoadLibraryA("advpack.dll");
37 if (!hAdvPack)
38 return FALSE;
39
40 pRunSetupCommand = (void *)GetProcAddress(hAdvPack, "RunSetupCommand");
41 pLaunchINFSection = (void *)GetProcAddress(hAdvPack, "LaunchINFSection");
42 pLaunchINFSectionEx = (void *)GetProcAddress(hAdvPack, "LaunchINFSectionEx");
43
44 if (!pRunSetupCommand || !pLaunchINFSection || !pLaunchINFSectionEx)
45 return FALSE;
46
47 return TRUE;
48}
49
51{
52 const DWORD SPAPI_PREFIX = 0x800F0000L;
53 const DWORD SPAPI_MASK = 0xFFFF0000L;
54
55 return (((err & SPAPI_MASK) ^ SPAPI_PREFIX) == 0);
56}
57
59{
60 DWORD dwNumberOfBytesWritten;
63
64 static const char data[] =
65 "[Version]\n"
66 "Signature=\"$Chicago$\"\n"
67 "AdvancedINF=2.5\n"
68 "[DefaultInstall]\n"
69 "CheckAdminRights=1\n";
70
71 WriteFile(hf, data, sizeof(data) - 1, &dwNumberOfBytesWritten, NULL);
72 CloseHandle(hf);
73}
74
75static void test_RunSetupCommand(void)
76{
77 HRESULT hr;
78 HANDLE hexe;
79 char path[MAX_PATH];
80 char dir[MAX_PATH];
81 char systemdir[MAX_PATH];
82
83 GetSystemDirectoryA(systemdir, sizeof(systemdir));
84
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);
88
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);
92
93 /* try to run a nonexistent exe */
94#ifdef __REACTOS__
95 hexe = (HANDLE)(ULONG_PTR)0xdeadbeefdeadbeefull;
96#else
97 hexe = (HANDLE)0xdeadbeef;
98#endif
99 hr = pRunSetupCommand(NULL, "idontexist.exe", "Install", systemdir, "Title", &hexe, 0, NULL);
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");
104
105 /* try a bad directory */
106#ifdef __REACTOS__
107 hexe = (HANDLE)(ULONG_PTR)0xdeadbeefdeadbeefull;
108#else
109 hexe = (HANDLE)0xdeadbeef;
110#endif
111 hr = pRunSetupCommand(NULL, "winver.exe", "Install", "non\\existent\\directory", "Title", &hexe, 0, NULL);
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");
116
117 /* try to run an exe with the RSC_FLAG_INF flag */
118#ifdef __REACTOS__
119 hexe = (HANDLE)(ULONG_PTR)0xdeadbeefdeadbeefull;
120#else
121 hexe = (HANDLE)0xdeadbeef;
122#endif
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);
125#ifdef __REACTOS__
126 ok(hexe == (HANDLE)(ULONG_PTR)0xdeadbeefdeadbeefull, "Expected hexe to be 0xdeadbeef\n");
127#else
128 ok(hexe == (HANDLE)0xdeadbeef, "Expected hexe to be 0xdeadbeef\n");
129#endif
130 ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n");
131
132 /* run winver.exe */
133#ifdef __REACTOS__
134 hexe = (HANDLE)(ULONG_PTR)0xdeadbeefdeadbeefull;
135#else
136 hexe = (HANDLE)0xdeadbeef;
137#endif
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");
142
143 CreateDirectoryA("one", NULL);
144 create_inf_file("one\\test.inf");
145
146 /* try a full path to the INF, with working dir provided */
148 lstrcatA(path, "\\one\\test.inf");
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);
153
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);
157 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr);
158
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);
162
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);
166
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);
170 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr);
171
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);
175
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);
179
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);
183 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr);
184
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);
188
189 DeleteFileA("one\\test.inf");
190 RemoveDirectoryA("one");
191
192 create_inf_file("test.inf");
193
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);
197
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);
201 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr);
202
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);
206}
207
208static void test_LaunchINFSection(void)
209{
210 HRESULT hr;
211 char cmdline[MAX_PATH];
212 static char file[] = "test.inf,DefaultInstall,4,0";
213 static char file2[] = "test.inf,,1,0";
214
215 /* The 'No UI' flag seems to have no effect whatsoever on Windows.
216 * So only do this test in interactive mode.
217 */
219 {
220 /* try an invalid cmdline */
221 hr = pLaunchINFSection(NULL, NULL, NULL, 0);
222 ok(hr == 1, "Expected 1, got %d\n", hr);
223 }
224
225 CreateDirectoryA("one", NULL);
226 create_inf_file("one\\test.inf");
227
228 /* try a full path to the INF */
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);
234
235 DeleteFileA("one\\test.inf");
236 RemoveDirectoryA("one");
237
238 create_inf_file("test.inf");
239
240 /* try just the INF filename */
241 hr = pLaunchINFSection(NULL, NULL, file, 0);
242 ok(hr == 0, "Expected 0, got %d\n", hr);
243
244 hr = pLaunchINFSection(NULL, NULL, file2, 0);
245 ok(hr == 0, "Expected 0, got %d\n", hr);
246
247 DeleteFileA("test.inf");
248}
249
250static void test_LaunchINFSectionEx(void)
251{
252 HRESULT hr;
253 char cmdline[MAX_PATH];
254
255 create_inf_file("test.inf");
256
257 /* try an invalid CAB filename with an absolute INF name */
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);
263
264 /* try quoting the parameters */
265 lstrcpyA(cmdline, "\"");
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);
270
271 /* The 'No UI' flag seems to have no effect whatsoever on Windows.
272 * So only do this test in interactive mode.
273 */
275 {
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);
280 }
281
282 DeleteFileA("test.inf");
283}
284
286{
287 DWORD len;
288 char temp_path[MAX_PATH], prev_path[MAX_PATH];
289
291 return;
292
293 if (!IsNTAdmin(0, NULL))
294 {
295 skip("Most tests need admin rights\n");
296 return;
297 }
298
299 GetCurrentDirectoryA(MAX_PATH, prev_path);
302
305
306 if(len && (CURR_DIR[len - 1] == '\\'))
307 CURR_DIR[len - 1] = 0;
308
312
314 SetCurrentDirectoryA(prev_path);
315}
#define RSC_FLAG_INF
Definition: advpub.h:130
#define RSC_FLAG_QUIET
Definition: advpub.h:132
#define S_ASYNCHRONOUS
Definition: urlmon.idl:2120
unsigned int dir
Definition: maze.c:112
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define E_INVALIDARG
Definition: ddrawi.h:101
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI IsNTAdmin(DWORD reserved, LPDWORD pReserved)
Definition: advpack.c:222
#define SPAPI_MASK
Definition: install.c:40
#define SPAPI_PREFIX
Definition: install.c:39
#define CloseHandle
Definition: compat.h:739
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
HANDLE HWND
Definition: compat.h:19
#define GetProcAddress(x, y)
Definition: compat.h:753
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define FreeLibrary(x)
Definition: compat.h:748
#define MAX_PATH
Definition: compat.h:34
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
BOOL WINAPI RemoveDirectoryA(IN LPCSTR lpPathName)
Definition: dir.c:714
BOOL WINAPI CreateDirectoryA(IN LPCSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:37
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
DWORD WINAPI GetCurrentDirectoryA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2146
BOOL WINAPI SetCurrentDirectoryA(IN LPCSTR lpPathName)
Definition: path.c:2206
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2054
UINT WINAPI GetSystemDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2283
BOOL WINAPI TerminateProcess(IN HANDLE hProcess, IN UINT uExitCode)
Definition: proc.c:1532
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLenum GLsizei len
Definition: glext.h:6722
const char * filename
Definition: ioapi.h:137
LPSTR WINAPI lstrcpyA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:100
LPSTR WINAPI lstrcatA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:123
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
#define CREATE_ALWAYS
Definition: disk.h:72
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
static void create_inf_file(void)
Definition: advpack.c:202
static HANDLE LPVOID
Definition: install.c:28
static LPSTR
Definition: install.c:29
static BOOL init_function_pointers(void)
Definition: install.c:34
static INT
Definition: install.c:29
static BOOL is_spapi_err(DWORD err)
Definition: install.c:50
static char CURR_DIR[MAX_PATH]
Definition: install.c:32
static void test_LaunchINFSectionEx(void)
Definition: install.c:250
static LPCSTR
Definition: install.c:28
static void test_RunSetupCommand(void)
Definition: install.c:75
static HMODULE hAdvPack
Definition: install.c:26
static void test_LaunchINFSection(void)
Definition: install.c:208
static HINSTANCE
Definition: install.c:29
int install
Definition: msacm.c:1365
char temp_path[MAX_PATH]
Definition: mspatcha.c:123
#define DWORD
Definition: nt_native.h:44
#define GENERIC_WRITE
Definition: nt_native.h:90
#define err(...)
int winetest_interactive
HRESULT hr
Definition: shlfolder.c:183
TCHAR * cmdline
Definition: stretchblt.cpp:32
Definition: fci.c:127
PVOID HANDLE
Definition: typedefs.h:73
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define HRESULT
Definition: msvc.h:7
#define WINAPI
Definition: msvc.h:6
#define ERROR_DIRECTORY
Definition: winerror.h:295
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
const char * LPCSTR
Definition: xmlstorage.h:183