advpack: Skip some tests if not in interactive mode because they pop up dialogs.
[wine/gsoc_dplay.git] / dlls / advpack / tests / install.c
blob607596347f5f05b52fdd1599b777c03a2f1af306
1 /*
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
21 #include <stdio.h>
22 #include <windows.h>
23 #include <advpub.h>
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(void)
35 HMODULE hAdvPack = LoadLibraryA("advpack.dll");
36 if (!hAdvPack)
37 return FALSE;
39 pRunSetupCommand = (void *)GetProcAddress(hAdvPack, "RunSetupCommand");
40 pLaunchINFSection = (void *)GetProcAddress(hAdvPack, "LaunchINFSection");
41 pLaunchINFSectionEx = (void *)GetProcAddress(hAdvPack, "LaunchINFSectionEx");
43 if (!pRunSetupCommand || !pLaunchINFSection || !pLaunchINFSectionEx)
44 return FALSE;
46 return TRUE;
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)
59 sprintf(*str, data);
60 *str += strlen(*str);
63 static void create_inf_file(LPCSTR filename)
65 char data[1024];
66 char *ptr = data;
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);
80 CloseHandle(hf);
83 static void test_RunSetupCommand(void)
85 HRESULT hr;
86 HANDLE hexe;
87 char path[MAX_PATH];
88 char dir[MAX_PATH];
89 char systemdir[MAX_PATH];
91 GetSystemDirectoryA(systemdir, sizeof(systemdir));
93 /* try an invalid cmd name */
94 hr = pRunSetupCommand(NULL, NULL, "Install", "Dir", "Title", NULL, 0, NULL);
95 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
97 /* try an invalid directory */
98 hr = pRunSetupCommand(NULL, "winver.exe", "Install", NULL, "Title", NULL, 0, NULL);
99 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
101 /* try to run a nonexistent exe */
102 hexe = (HANDLE)0xdeadbeef;
103 hr = pRunSetupCommand(NULL, "idontexist.exe", "Install", systemdir, "Title", &hexe, 0, NULL);
104 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
105 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr);
106 ok(hexe == NULL, "Expcted hexe to be NULL\n");
107 ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n");
109 /* try a bad directory */
110 hexe = (HANDLE)0xdeadbeef;
111 hr = pRunSetupCommand(NULL, "winver.exe", "Install", "non\\existent\\directory", "Title", &hexe, 0, NULL);
112 ok(hr == HRESULT_FROM_WIN32(ERROR_DIRECTORY),
113 "Expected HRESULT_FROM_WIN32(ERROR_DIRECTORY), got %d\n", hr);
114 ok(hexe == NULL, "Expcted hexe to be NULL\n");
115 ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n");
117 /* try to run an exe with the RSC_FLAG_INF flag */
118 hexe = (HANDLE)0xdeadbeef;
119 hr = pRunSetupCommand(NULL, "winver.exe", "Install", systemdir, "Title", &hexe, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
120 ok(is_spapi_err(hr), "Expected a setupapi error, got %d\n", hr);
121 ok(hexe == (HANDLE)0xdeadbeef, "Expected hexe to be 0xdeadbeef\n");
122 ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n");
124 /* run winver.exe */
125 hexe = (HANDLE)0xdeadbeef;
126 hr = pRunSetupCommand(NULL, "winver.exe", "Install", systemdir, "Title", &hexe, 0, NULL);
127 ok(hr == S_ASYNCHRONOUS, "Expected S_ASYNCHRONOUS, got %d\n", hr);
128 ok(hexe != NULL, "Expected hexe to be non-NULL\n");
129 ok(TerminateProcess(hexe, 0), "Expected TerminateProcess to succeed\n");
131 CreateDirectoryA("one", NULL);
132 create_inf_file("one\\test.inf");
134 /* try a full path to the INF, with working dir provided */
135 lstrcpy(path, CURR_DIR);
136 lstrcat(path, "\\one\\test.inf");
137 lstrcpy(dir, CURR_DIR);
138 lstrcat(dir, "\\one");
139 hr = pRunSetupCommand(NULL, path, "DefaultInstall", dir, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
140 ok(hr == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", hr);
142 /* try a full path to the INF, NULL working dir */
143 hr = pRunSetupCommand(NULL, path, "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
144 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
145 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr);
147 /* try a full path to the INF, empty working dir */
148 hr = pRunSetupCommand(NULL, path, "DefaultInstall", "", "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
149 ok(hr == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", hr);
151 /* try a relative path to the INF, with working dir provided */
152 hr = pRunSetupCommand(NULL, "one\\test.inf", "DefaultInstall", dir, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
153 ok(hr == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", hr);
155 /* try a relative path to the INF, NULL working dir */
156 hr = pRunSetupCommand(NULL, "one\\test.inf", "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
157 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
158 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr);
160 /* try a relative path to the INF, empty working dir */
161 hr = pRunSetupCommand(NULL, "one\\test.inf", "DefaultInstall", "", "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
162 ok(hr == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", hr);
164 /* try only the INF filename, with working dir provided */
165 hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", dir, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
166 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
167 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr);
169 /* try only the INF filename, NULL working dir */
170 hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
171 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
172 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr);
174 /* try only the INF filename, empty working dir */
175 hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", "", "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
176 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
177 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr);
179 DeleteFileA("one\\test.inf");
180 RemoveDirectoryA("one");
182 create_inf_file("test.inf");
184 /* try INF file in the current directory, working directory provided */
185 hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", CURR_DIR, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
186 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
187 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr);
189 /* try INF file in the current directory, NULL working directory */
190 hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
191 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
192 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr);
194 /* try INF file in the current directory, empty working directory */
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),
197 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr);
200 static void test_LaunchINFSection(void)
202 HRESULT hr;
203 char cmdline[MAX_PATH];
204 static char file[] = "test.inf,DefaultInstall,4,0";
206 /* The 'No UI' flag seems to have no effect whatsoever on Windows.
207 * So only do this test in interactive mode.
209 if (winetest_interactive)
211 /* try an invalid cmdline */
212 hr = pLaunchINFSection(NULL, NULL, NULL, 0);
213 ok(hr == 1, "Expected 1, got %d\n", hr);
216 CreateDirectoryA("one", NULL);
217 create_inf_file("one\\test.inf");
219 /* try a full path to the INF */
220 lstrcpy(cmdline, CURR_DIR);
221 lstrcat(cmdline, "\\");
222 lstrcat(cmdline, "one\\test.inf,DefaultInstall,,4");
223 hr = pLaunchINFSection(NULL, NULL, cmdline, 0);
224 ok(hr == 0, "Expected 0, got %d\n", hr);
226 DeleteFileA("one\\test.inf");
227 RemoveDirectoryA("one");
229 create_inf_file("test.inf");
231 /* try just the INF filename */
232 hr = pLaunchINFSection(NULL, NULL, file, 0);
233 ok(hr == 0, "Expected 0, got %d\n", hr);
235 DeleteFileA("test.inf");
238 static void test_LaunchINFSectionEx(void)
240 HRESULT hr;
241 char cmdline[MAX_PATH];
243 create_inf_file("test.inf");
245 /* try an invalid CAB filename with an absolute INF name */
246 lstrcpy(cmdline, CURR_DIR);
247 lstrcat(cmdline, "\\");
248 lstrcat(cmdline, "test.inf,DefaultInstall,c:imacab.cab,4");
249 hr = pLaunchINFSectionEx(NULL, NULL, cmdline, 0);
250 ok(hr == 0, "Expected 0, got %d\n", hr);
252 /* The 'No UI' flag seems to have no effect whatsoever on Windows.
253 * So only do this test in interactive mode.
255 if (winetest_interactive)
257 /* try an invalid CAB filename with a relative INF name */
258 lstrcpy(cmdline, "test.inf,DefaultInstall,c:imacab.cab,4");
259 hr = pLaunchINFSectionEx(NULL, NULL, cmdline, 0);
260 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
263 DeleteFileA("test.inf");
266 START_TEST(install)
268 if (!init_function_pointers())
269 return;
271 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
273 test_RunSetupCommand();
274 test_LaunchINFSection();
275 test_LaunchINFSectionEx();