d3d10core/tests: Avoid POINT sampling exactly halfway between two mip levels.
[wine.git] / dlls / advpack / tests / install.c
blobbdf02c5a3970ff5c9a69275947189fa6b9d146a3
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 static HMODULE hAdvPack;
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);
32 static char CURR_DIR[MAX_PATH];
34 static BOOL init_function_pointers(void)
36 hAdvPack = LoadLibraryA("advpack.dll");
37 if (!hAdvPack)
38 return FALSE;
40 pRunSetupCommand = (void *)GetProcAddress(hAdvPack, "RunSetupCommand");
41 pLaunchINFSection = (void *)GetProcAddress(hAdvPack, "LaunchINFSection");
42 pLaunchINFSectionEx = (void *)GetProcAddress(hAdvPack, "LaunchINFSectionEx");
44 if (!pRunSetupCommand || !pLaunchINFSection || !pLaunchINFSectionEx)
45 return FALSE;
47 return TRUE;
50 static BOOL is_spapi_err(DWORD err)
52 const DWORD SPAPI_PREFIX = 0x800F0000L;
53 const DWORD SPAPI_MASK = 0xFFFF0000L;
55 return (((err & SPAPI_MASK) ^ SPAPI_PREFIX) == 0);
58 static void create_inf_file(LPCSTR filename)
60 DWORD dwNumberOfBytesWritten;
61 HANDLE hf = CreateFileA(filename, GENERIC_WRITE, 0, NULL,
62 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
64 static const char data[] =
65 "[Version]\n"
66 "Signature=\"$Chicago$\"\n"
67 "AdvancedINF=2.5\n"
68 "[DefaultInstall]\n"
69 "CheckAdminRights=1\n";
71 WriteFile(hf, data, sizeof(data) - 1, &dwNumberOfBytesWritten, NULL);
72 CloseHandle(hf);
75 static void test_RunSetupCommand(void)
77 HRESULT hr;
78 HANDLE hexe;
79 char path[MAX_PATH];
80 char dir[MAX_PATH];
81 char systemdir[MAX_PATH];
83 GetSystemDirectoryA(systemdir, sizeof(systemdir));
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 %ld\n", hr);
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 %ld\n", hr);
93 /* try to run a nonexistent exe */
94 hexe = (HANDLE)0xdeadbeef;
95 hr = pRunSetupCommand(NULL, "idontexist.exe", "Install", systemdir, "Title", &hexe, 0, NULL);
96 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
97 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %ld\n", hr);
98 ok(hexe == NULL, "Expected hexe to be NULL\n");
99 ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n");
101 /* try a bad directory */
102 hexe = (HANDLE)0xdeadbeef;
103 hr = pRunSetupCommand(NULL, "winver.exe", "Install", "non\\existent\\directory", "Title", &hexe, 0, NULL);
104 ok(hr == HRESULT_FROM_WIN32(ERROR_DIRECTORY),
105 "Expected HRESULT_FROM_WIN32(ERROR_DIRECTORY), got %ld\n", hr);
106 ok(hexe == NULL, "Expected hexe to be NULL\n");
107 ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n");
109 /* try to run an exe with the RSC_FLAG_INF flag */
110 hexe = (HANDLE)0xdeadbeef;
111 hr = pRunSetupCommand(NULL, "winver.exe", "Install", systemdir, "Title", &hexe, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
112 ok(is_spapi_err(hr), "Expected a setupapi error, got %ld\n", hr);
113 ok(hexe == (HANDLE)0xdeadbeef, "Expected hexe to be 0xdeadbeef\n");
114 ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n");
116 /* run winver.exe */
117 hexe = (HANDLE)0xdeadbeef;
118 hr = pRunSetupCommand(NULL, "winver.exe", "Install", systemdir, "Title", &hexe, 0, NULL);
119 ok(hr == S_ASYNCHRONOUS, "Expected S_ASYNCHRONOUS, got %ld\n", hr);
120 ok(hexe != NULL, "Expected hexe to be non-NULL\n");
121 ok(TerminateProcess(hexe, 0), "Expected TerminateProcess to succeed\n");
123 CreateDirectoryA("one", NULL);
124 create_inf_file("one\\test.inf");
126 /* try a full path to the INF, with working dir provided */
127 lstrcpyA(path, CURR_DIR);
128 lstrcatA(path, "\\one\\test.inf");
129 lstrcpyA(dir, CURR_DIR);
130 lstrcatA(dir, "\\one");
131 hr = pRunSetupCommand(NULL, path, "DefaultInstall", dir, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
132 ok(hr == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", hr);
134 /* try a full path to the INF, NULL working dir */
135 hr = pRunSetupCommand(NULL, path, "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
136 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
137 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %ld\n", hr);
139 /* try a full path to the INF, empty working dir */
140 hr = pRunSetupCommand(NULL, path, "DefaultInstall", "", "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
141 ok(hr == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", hr);
143 /* try a relative path to the INF, with working dir provided */
144 hr = pRunSetupCommand(NULL, "one\\test.inf", "DefaultInstall", dir, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
145 ok(hr == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", hr);
147 /* try a relative path to the INF, NULL working dir */
148 hr = pRunSetupCommand(NULL, "one\\test.inf", "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
149 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
150 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %ld\n", hr);
152 /* try a relative path to the INF, empty working dir */
153 hr = pRunSetupCommand(NULL, "one\\test.inf", "DefaultInstall", "", "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
154 ok(hr == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %ld\n", hr);
156 /* try only the INF filename, with working dir provided */
157 hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", dir, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
158 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %ld\n", hr);
160 /* try only the INF filename, NULL working dir */
161 hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
162 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
163 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %ld\n", hr);
165 /* try only the INF filename, empty working dir */
166 hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", "", "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
167 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %ld\n", hr);
169 DeleteFileA("one\\test.inf");
170 RemoveDirectoryA("one");
172 create_inf_file("test.inf");
174 /* try INF file in the current directory, working directory provided */
175 hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", CURR_DIR, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
176 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %ld\n", hr);
178 /* try INF file in the current directory, NULL working directory */
179 hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
180 ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
181 "Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %ld\n", hr);
183 /* try INF file in the current directory, empty working directory */
184 hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", CURR_DIR, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
185 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %ld\n", hr);
188 static void test_LaunchINFSection(void)
190 HRESULT hr;
191 char cmdline[MAX_PATH];
192 static char file[] = "test.inf,DefaultInstall,4,0";
193 static char file2[] = "test.inf,,1,0";
195 /* The 'No UI' flag seems to have no effect whatsoever on Windows.
196 * So only do this test in interactive mode.
198 if (winetest_interactive)
200 /* try an invalid cmdline */
201 hr = pLaunchINFSection(NULL, NULL, NULL, 0);
202 ok(hr == 1, "Expected 1, got %ld\n", hr);
205 CreateDirectoryA("one", NULL);
206 create_inf_file("one\\test.inf");
208 /* try a full path to the INF */
209 lstrcpyA(cmdline, CURR_DIR);
210 lstrcatA(cmdline, "\\");
211 lstrcatA(cmdline, "one\\test.inf,DefaultInstall,,4");
212 hr = pLaunchINFSection(NULL, NULL, cmdline, 0);
213 ok(hr == 0, "Expected 0, got %ld\n", hr);
215 DeleteFileA("one\\test.inf");
216 RemoveDirectoryA("one");
218 create_inf_file("test.inf");
220 /* try just the INF filename */
221 hr = pLaunchINFSection(NULL, NULL, file, 0);
222 ok(hr == 0, "Expected 0, got %ld\n", hr);
224 hr = pLaunchINFSection(NULL, NULL, file2, 0);
225 ok(hr == 0, "Expected 0, got %ld\n", hr);
227 DeleteFileA("test.inf");
230 static void test_LaunchINFSectionEx(void)
232 HRESULT hr;
233 char cmdline[MAX_PATH];
235 create_inf_file("test.inf");
237 /* try an invalid CAB filename with an absolute INF name */
238 lstrcpyA(cmdline, CURR_DIR);
239 lstrcatA(cmdline, "\\");
240 lstrcatA(cmdline, "test.inf,DefaultInstall,c:imacab.cab,4");
241 hr = pLaunchINFSectionEx(NULL, NULL, cmdline, 0);
242 ok(hr == 0, "Expected 0, got %ld\n", hr);
244 /* try quoting the parameters */
245 lstrcpyA(cmdline, "\"");
246 lstrcatA(cmdline, CURR_DIR);
247 lstrcatA(cmdline, "\\test.inf\",\"DefaultInstall\",\"c:,imacab.cab\",\"4\"");
248 hr = pLaunchINFSectionEx(NULL, NULL, cmdline, 0);
249 ok(hr == 0, "Expected 0, got %ld\n", hr);
251 /* The 'No UI' flag seems to have no effect whatsoever on Windows.
252 * So only do this test in interactive mode.
254 if (winetest_interactive)
256 /* try an invalid CAB filename with a relative INF name */
257 lstrcpyA(cmdline, "test.inf,DefaultInstall,c:imacab.cab,4");
258 hr = pLaunchINFSectionEx(NULL, NULL, cmdline, 0);
259 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr);
262 DeleteFileA("test.inf");
265 START_TEST(install)
267 DWORD len;
268 char temp_path[MAX_PATH], prev_path[MAX_PATH];
270 if (!init_function_pointers())
271 return;
273 if (!IsNTAdmin(0, NULL))
275 skip("Most tests need admin rights\n");
276 return;
279 GetCurrentDirectoryA(MAX_PATH, prev_path);
280 GetTempPathA(MAX_PATH, temp_path);
281 SetCurrentDirectoryA(temp_path);
283 lstrcpyA(CURR_DIR, temp_path);
284 len = lstrlenA(CURR_DIR);
286 if(len && (CURR_DIR[len - 1] == '\\'))
287 CURR_DIR[len - 1] = 0;
289 test_RunSetupCommand();
290 test_LaunchINFSection();
291 test_LaunchINFSectionEx();
293 FreeLibrary(hAdvPack);
294 SetCurrentDirectoryA(prev_path);