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 /* function pointers */
27 static HRESULT (WINAPI
*pRunSetupCommand
)(HWND
, LPCSTR
, LPCSTR
, LPCSTR
, LPCSTR
, HANDLE
*, DWORD
, LPVOID
);
28 static HRESULT (WINAPI
*pLaunchINFSection
)(HWND
, HINSTANCE
, LPSTR
, INT
);
29 static HRESULT (WINAPI
*pLaunchINFSectionEx
)(HWND
, HINSTANCE
, LPSTR
, INT
);
31 static char CURR_DIR
[MAX_PATH
];
33 static BOOL
init_function_pointers()
35 HMODULE hAdvPack
= LoadLibraryA("advpack.dll");
39 pRunSetupCommand
= (void *)GetProcAddress(hAdvPack
, "RunSetupCommand");
40 pLaunchINFSection
= (void *)GetProcAddress(hAdvPack
, "LaunchINFSection");
41 pLaunchINFSectionEx
= (void *)GetProcAddress(hAdvPack
, "LaunchINFSectionEx");
43 if (!pRunSetupCommand
|| !pLaunchINFSection
|| !pLaunchINFSectionEx
)
49 static BOOL
is_spapi_err(DWORD err
)
51 const DWORD SPAPI_PREFIX
= 0x800F0000L
;
52 const DWORD SPAPI_MASK
= 0xFFFF0000L
;
54 return (((err
& SPAPI_MASK
) ^ SPAPI_PREFIX
) == 0);
57 static void append_str(char **str
, const char *data
)
63 static void create_inf_file(LPCSTR filename
)
67 DWORD dwNumberOfBytesWritten
;
68 HANDLE hf
= CreateFile(filename
, GENERIC_WRITE
, 0, NULL
,
69 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
71 append_str(&ptr
, "[Version]\n");
72 append_str(&ptr
, "Signature=\"$Chicago$\"\n");
73 append_str(&ptr
, "AdvancedINF=2.5\n");
74 append_str(&ptr
, "[DefaultInstall]\n");
75 append_str(&ptr
, "RegisterOCXs=RegisterOCXsSection\n");
76 append_str(&ptr
, "[RegisterOCXsSection]\n");
77 append_str(&ptr
, "%%11%%\\ole32.dll\n");
79 WriteFile(hf
, data
, ptr
- data
, &dwNumberOfBytesWritten
, NULL
);
83 static void test_RunSetupCommand()
90 /* try an invalid cmd name */
91 hr
= pRunSetupCommand(NULL
, NULL
, "Install", "Dir", "Title", NULL
, 0, NULL
);
92 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %ld\n", hr
);
94 /* try an invalid directory */
95 hr
= pRunSetupCommand(NULL
, "winver.exe", "Install", NULL
, "Title", NULL
, 0, NULL
);
96 ok(hr
== E_INVALIDARG
, "Expected E_INVALIDARG, got %ld\n", hr
);
98 /* try to run a nonexistent exe */
99 hexe
= (HANDLE
)0xdeadbeef;
100 hr
= pRunSetupCommand(NULL
, "idontexist.exe", "Install", "c:\\windows\\system32", "Title", &hexe
, 0, NULL
);
101 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
102 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %ld\n", hr
);
103 ok(hexe
== NULL
, "Expcted hexe to be NULL\n");
104 ok(!TerminateProcess(hexe
, 0), "Expected TerminateProcess to fail\n");
106 /* try a bad directory */
107 hexe
= (HANDLE
)0xdeadbeef;
108 hr
= pRunSetupCommand(NULL
, "winver.exe", "Install", "non\\existent\\directory", "Title", &hexe
, 0, NULL
);
109 ok(hr
== HRESULT_FROM_WIN32(ERROR_DIRECTORY
),
110 "Expected HRESULT_FROM_WIN32(ERROR_DIRECTORY), got %ld\n", hr
);
111 ok(hexe
== NULL
, "Expcted hexe to be NULL\n");
112 ok(!TerminateProcess(hexe
, 0), "Expected TerminateProcess to fail\n");
114 /* try to run an exe with the RSC_FLAG_INF flag */
115 hexe
= (HANDLE
)0xdeadbeef;
116 hr
= pRunSetupCommand(NULL
, "winver.exe", "Install", "c:\\windows\\system32", "Title", &hexe
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
117 ok(is_spapi_err(hr
), "Expected a setupapi error, got %ld\n", hr
);
118 ok(hexe
== (HANDLE
)0xdeadbeef, "Expected hexe to be 0xdeadbeef\n");
119 ok(!TerminateProcess(hexe
, 0), "Expected TerminateProcess to fail\n");
122 hexe
= (HANDLE
)0xdeadbeef;
123 hr
= pRunSetupCommand(NULL
, "winver.exe", "Install", "c:\\windows\\system32", "Title", &hexe
, 0, NULL
);
124 ok(hr
== S_ASYNCHRONOUS
, "Expected S_ASYNCHRONOUS, got %ld\n", hr
);
125 ok(hexe
!= NULL
, "Expected hexe to be non-NULL\n");
126 ok(TerminateProcess(hexe
, 0), "Expected TerminateProcess to succeed\n");
128 CreateDirectoryA("one", NULL
);
129 create_inf_file("one\\test.inf");
131 /* try a full path to the INF, with working dir provided */
132 lstrcpy(path
, CURR_DIR
);
133 lstrcat(path
, "\\one\\test.inf");
134 lstrcpy(dir
, CURR_DIR
);
135 lstrcat(dir
, "\\one");
136 hr
= pRunSetupCommand(NULL
, path
, "DefaultInstall", dir
, "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
137 ok(hr
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %ld\n", hr
);
139 /* try a full path to the INF, NULL working dir */
140 hr
= pRunSetupCommand(NULL
, path
, "DefaultInstall", NULL
, "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
141 ok(hr
== HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER
),
142 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %ld\n", hr
);
144 /* try a full path to the INF, empty working dir */
145 hr
= pRunSetupCommand(NULL
, path
, "DefaultInstall", "", "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
146 ok(hr
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %ld\n", hr
);
148 /* try a relative path to the INF, with working dir provided */
149 hr
= pRunSetupCommand(NULL
, "one\\test.inf", "DefaultInstall", dir
, "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
150 ok(hr
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %ld\n", hr
);
152 /* try a relative path to the INF, NULL working dir */
153 hr
= pRunSetupCommand(NULL
, "one\\test.inf", "DefaultInstall", NULL
, "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
154 ok(hr
== HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER
),
155 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %ld\n", hr
);
157 /* try a relative path to the INF, empty working dir */
158 hr
= pRunSetupCommand(NULL
, "one\\test.inf", "DefaultInstall", "", "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
159 ok(hr
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %ld\n", hr
);
161 /* try only the INF filename, with working dir provided */
162 hr
= pRunSetupCommand(NULL
, "test.inf", "DefaultInstall", dir
, "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
163 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
164 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %ld\n", hr
);
166 /* try only the INF filename, NULL working dir */
167 hr
= pRunSetupCommand(NULL
, "test.inf", "DefaultInstall", NULL
, "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
168 ok(hr
== HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER
),
169 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %ld\n", hr
);
171 /* try only the INF filename, empty working dir */
172 hr
= pRunSetupCommand(NULL
, "test.inf", "DefaultInstall", "", "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
173 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
174 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %ld\n", hr
);
176 DeleteFileA("one\\test.inf");
177 RemoveDirectoryA("one");
179 create_inf_file("test.inf");
181 /* try INF file in the current directory, working directory provided */
182 hr
= pRunSetupCommand(NULL
, "test.inf", "DefaultInstall", CURR_DIR
, "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
183 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
184 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %ld\n", hr
);
186 /* try INF file in the current directory, NULL working directory */
187 hr
= pRunSetupCommand(NULL
, "test.inf", "DefaultInstall", NULL
, "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
188 ok(hr
== HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER
),
189 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %ld\n", hr
);
191 /* try INF file in the current directory, empty working directory */
192 hr
= pRunSetupCommand(NULL
, "test.inf", "DefaultInstall", CURR_DIR
, "Title", NULL
, RSC_FLAG_INF
| RSC_FLAG_QUIET
, NULL
);
193 ok(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
194 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %ld\n", hr
);
197 static void test_LaunchINFSection()
200 char cmdline
[MAX_PATH
];
201 static char file
[] = "test.inf,DefaultInstall,4,0";
203 /* try an invalid cmdline */
204 hr
= pLaunchINFSection(NULL
, NULL
, NULL
, 0);
205 ok(hr
== 1, "Expected 1, got %ld\n", hr
);
207 CreateDirectoryA("one", NULL
);
208 create_inf_file("one\\test.inf");
210 /* try a full path to the INF */
211 lstrcpy(cmdline
, CURR_DIR
);
212 lstrcat(cmdline
, "\\");
213 lstrcat(cmdline
, "one\\test.inf,DefaultInstall,,4");
214 hr
= pLaunchINFSection(NULL
, NULL
, cmdline
, 0);
215 ok(hr
== 0, "Expected 0, got %ld\n", hr
);
217 DeleteFileA("one\\test.inf");
218 RemoveDirectoryA("one");
220 create_inf_file("test.inf");
222 /* try just the INF filename */
223 hr
= pLaunchINFSection(NULL
, NULL
, file
, 0);
224 ok(hr
== 0, "Expected 0, got %ld\n", hr
);
226 DeleteFileA("test.inf");
231 if (!init_function_pointers())
234 GetCurrentDirectoryA(MAX_PATH
, CURR_DIR
);
236 test_RunSetupCommand();
237 test_LaunchINFSection();