ReactOS  0.4.13-dev-482-ge57f103
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 */
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);
31 
32 static 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 
75 static 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 
208 static 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 
250 static 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 
290  if (!init_function_pointers())
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 
304  len = lstrlenA(CURR_DIR);
305 
306  if(len && (CURR_DIR[len - 1] == '\\'))
307  CURR_DIR[len - 1] = 0;
308 
312 
314  SetCurrentDirectoryA(prev_path);
315 }
static HANDLE DWORD
Definition: install.c:28
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
static BOOL is_spapi_err(DWORD err)
Definition: install.c:50
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
static LPSTR
Definition: install.c:29
static INT
Definition: install.c:29
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
#define ERROR_SUCCESS
Definition: deptool.c:10
HRESULT hr
Definition: shlfolder.c:183
static HMODULE hAdvPack
Definition: install.c:26
static void test_LaunchINFSection(void)
Definition: install.c:208
int install
Definition: msacm.c:1353
#define SPAPI_PREFIX
Definition: install.c:40
BOOL WINAPI IsNTAdmin(DWORD reserved, LPDWORD pReserved)
Definition: advpack.c:222
static char CURR_DIR[MAX_PATH]
Definition: install.c:32
UINT WINAPI GetSystemDirectoryA(OUT LPSTR lpBuffer, IN UINT uSize)
Definition: path.c:2282
HANDLE HWND
Definition: compat.h:13
TCHAR * cmdline
Definition: stretchblt.cpp:32
int winetest_interactive
static HRESULT(WINAPI *pRunSetupCommand)(HWND
const char * filename
Definition: ioapi.h:135
#define ERROR_DIRECTORY
Definition: winerror.h:295
#define RSC_FLAG_INF
Definition: advpub.h:130
uint32_t ULONG_PTR
Definition: typedefs.h:63
static void test_LaunchINFSectionEx(void)
Definition: install.c:250
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GENERIC_WRITE
Definition: nt_native.h:90
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
#define ok(value,...)
#define E_INVALIDARG
Definition: ddrawi.h:101
BOOL WINAPI CreateDirectoryA(IN LPCSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:37
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
unsigned int dir
Definition: maze.c:112
const char * LPCSTR
Definition: xmlstorage.h:183
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
static HINSTANCE
Definition: install.c:29
static void create_inf_file(LPCSTR filename)
Definition: install.c:58
LPSTR WINAPI lstrcatA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:123
#define FreeLibrary(x)
Definition: compat.h:405
static LPCSTR
Definition: install.c:28
LONG HRESULT
Definition: typedefs.h:77
#define S_ASYNCHRONOUS
Definition: advpub.h:29
static void test_RunSetupCommand(void)
Definition: install.c:75
#define MAX_PATH
Definition: compat.h:26
static BOOL init_function_pointers(void)
Definition: install.c:34
#define WINAPI
Definition: msvc.h:8
PVOID HANDLE
Definition: typedefs.h:71
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SPAPI_MASK
Definition: install.c:41
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
LPSTR WINAPI lstrcpyA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:100
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
static const WCHAR L[]
Definition: oid.c:1250
BOOL WINAPI SetCurrentDirectoryA(IN LPCSTR lpPathName)
Definition: path.c:2205
GLenum GLsizei len
Definition: glext.h:6722
#define err(...)
#define CREATE_ALWAYS
Definition: disk.h:72
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2053
BOOL WINAPI TerminateProcess(IN HANDLE hProcess, IN UINT uExitCode)
Definition: proc.c:1562
DWORD WINAPI GetCurrentDirectoryA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2145
Definition: services.c:325
BOOL WINAPI RemoveDirectoryA(IN LPCSTR lpPathName)
Definition: dir.c:714
#define skip(...)
static HANDLE LPVOID
Definition: install.c:28
#define GetProcAddress(x, y)
Definition: compat.h:410
#define RSC_FLAG_QUIET
Definition: advpub.h:132
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399
START_TEST(install)
Definition: install.c:285
Definition: fci.c:126
char temp_path[MAX_PATH]
Definition: mspatcha.c:123