ReactOS 0.4.15-dev-7918-g2a2556c
install.c File Reference
#include <stdio.h>
#include <windows.h>
#include <advpub.h>
#include "wine/test.h"
Include dependency graph for install.c:

Go to the source code of this file.

Functions

static HRESULT (WINAPI *pRunSetupCommand)(HWND
 
static BOOL init_function_pointers (void)
 
static BOOL is_spapi_err (DWORD err)
 
static void create_inf_file (LPCSTR filename)
 
static void test_RunSetupCommand (void)
 
static void test_LaunchINFSection (void)
 
static void test_LaunchINFSectionEx (void)
 
 START_TEST (install)
 

Variables

static HMODULE hAdvPack
 
static LPCSTR
 
static HANDLE DWORD
 
static HANDLE LPVOID
 
static HINSTANCE
 
static LPSTR
 
static INT
 
static char CURR_DIR [MAX_PATH]
 

Function Documentation

◆ create_inf_file()

static void create_inf_file ( LPCSTR  filename)
static

Definition at line 58 of file install.c.

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}
#define NULL
Definition: types.h:112
#define CloseHandle
Definition: compat.h:739
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
const char * filename
Definition: ioapi.h:137
#define CREATE_ALWAYS
Definition: disk.h:72
#define GENERIC_WRITE
Definition: nt_native.h:90

◆ HRESULT()

static HRESULT ( WINAPI pRunSetupCommand)
static

◆ init_function_pointers()

static BOOL init_function_pointers ( void  )
static

Definition at line 34 of file install.c.

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}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcAddress(x, y)
Definition: compat.h:753
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
static HMODULE hAdvPack
Definition: install.c:26

Referenced by START_TEST().

◆ is_spapi_err()

static BOOL is_spapi_err ( DWORD  err)
static

Definition at line 50 of file install.c.

51{
52 const DWORD SPAPI_PREFIX = 0x800F0000L;
53 const DWORD SPAPI_MASK = 0xFFFF0000L;
54
55 return (((err & SPAPI_MASK) ^ SPAPI_PREFIX) == 0);
56}
#define SPAPI_MASK
Definition: install.c:40
#define SPAPI_PREFIX
Definition: install.c:39
#define err(...)

Referenced by test_RunSetupCommand().

◆ START_TEST()

START_TEST ( install  )

Definition at line 285 of file install.c.

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 skip(...)
Definition: atltest.h:64
BOOL WINAPI IsNTAdmin(DWORD reserved, LPDWORD pReserved)
Definition: advpack.c:222
#define FreeLibrary(x)
Definition: compat.h:748
#define MAX_PATH
Definition: compat.h:34
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
GLenum GLsizei len
Definition: glext.h:6722
LPSTR WINAPI lstrcpyA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:100
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
static BOOL init_function_pointers(void)
Definition: install.c:34
static char CURR_DIR[MAX_PATH]
Definition: install.c:32
static void test_LaunchINFSectionEx(void)
Definition: install.c:250
static void test_RunSetupCommand(void)
Definition: install.c:75
static void test_LaunchINFSection(void)
Definition: install.c:208
char temp_path[MAX_PATH]
Definition: mspatcha.c:123

◆ test_LaunchINFSection()

static void test_LaunchINFSection ( void  )
static

Definition at line 208 of file install.c.

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}
#define ok(value,...)
Definition: atltest.h:57
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
LPSTR WINAPI lstrcatA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:123
static void create_inf_file(void)
Definition: advpack.c:202
int winetest_interactive
HRESULT hr
Definition: shlfolder.c:183
TCHAR * cmdline
Definition: stretchblt.cpp:32
Definition: fci.c:127

Referenced by START_TEST().

◆ test_LaunchINFSectionEx()

static void test_LaunchINFSectionEx ( void  )
static

Definition at line 250 of file install.c.

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}
#define E_INVALIDARG
Definition: ddrawi.h:101

Referenced by START_TEST().

◆ test_RunSetupCommand()

static void test_RunSetupCommand ( void  )
static

Definition at line 75 of file install.c.

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}
#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 ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
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
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
static BOOL is_spapi_err(DWORD err)
Definition: install.c:50
PVOID HANDLE
Definition: typedefs.h:73
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define ERROR_DIRECTORY
Definition: winerror.h:295
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92

Referenced by START_TEST().

Variable Documentation

◆ CURR_DIR

◆ DWORD

Definition at line 28 of file install.c.

◆ hAdvPack

HMODULE hAdvPack
static

Definition at line 26 of file install.c.

Referenced by init_function_pointers(), and START_TEST().

◆ HINSTANCE

Definition at line 29 of file install.c.

◆ INT

INT

Definition at line 29 of file install.c.

◆ LPCSTR

Definition at line 28 of file install.c.

◆ LPSTR

Definition at line 29 of file install.c.

◆ LPVOID

Definition at line 28 of file install.c.