2006-03-24 06:12:20 +01:00
|
|
|
/*
|
|
|
|
* Unit tests for advpack.dll install functions
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 James Hawkins
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2006-03-24 06:12:20 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <advpub.h>
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2008-03-09 12:15:05 +01:00
|
|
|
static HMODULE hAdvPack;
|
2006-03-24 06:12:20 +01:00
|
|
|
/* function pointers */
|
|
|
|
static HRESULT (WINAPI *pRunSetupCommand)(HWND, LPCSTR, LPCSTR, LPCSTR, LPCSTR, HANDLE*, DWORD, LPVOID);
|
2006-07-08 03:30:46 +02:00
|
|
|
static HRESULT (WINAPI *pLaunchINFSection)(HWND, HINSTANCE, LPSTR, INT);
|
|
|
|
static HRESULT (WINAPI *pLaunchINFSectionEx)(HWND, HINSTANCE, LPSTR, INT);
|
|
|
|
|
|
|
|
static char CURR_DIR[MAX_PATH];
|
2006-03-24 06:12:20 +01:00
|
|
|
|
2007-03-10 22:00:47 +01:00
|
|
|
static BOOL init_function_pointers(void)
|
2006-03-24 06:12:20 +01:00
|
|
|
{
|
2008-03-09 12:15:05 +01:00
|
|
|
hAdvPack = LoadLibraryA("advpack.dll");
|
2006-03-24 06:12:20 +01:00
|
|
|
if (!hAdvPack)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
pRunSetupCommand = (void *)GetProcAddress(hAdvPack, "RunSetupCommand");
|
2006-07-08 03:30:46 +02:00
|
|
|
pLaunchINFSection = (void *)GetProcAddress(hAdvPack, "LaunchINFSection");
|
|
|
|
pLaunchINFSectionEx = (void *)GetProcAddress(hAdvPack, "LaunchINFSectionEx");
|
2006-03-24 06:12:20 +01:00
|
|
|
|
2006-07-08 03:30:46 +02:00
|
|
|
if (!pRunSetupCommand || !pLaunchINFSection || !pLaunchINFSectionEx)
|
2006-03-24 06:12:20 +01:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-03-29 19:36:04 +02:00
|
|
|
static BOOL is_spapi_err(DWORD err)
|
|
|
|
{
|
|
|
|
const DWORD SPAPI_PREFIX = 0x800F0000L;
|
|
|
|
const DWORD SPAPI_MASK = 0xFFFF0000L;
|
|
|
|
|
|
|
|
return (((err & SPAPI_MASK) ^ SPAPI_PREFIX) == 0);
|
|
|
|
}
|
|
|
|
|
2006-07-29 15:29:25 +02:00
|
|
|
static void create_inf_file(LPCSTR filename)
|
2006-07-08 03:30:46 +02:00
|
|
|
{
|
|
|
|
DWORD dwNumberOfBytesWritten;
|
|
|
|
HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
|
|
|
|
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
|
2008-12-05 04:26:48 +01:00
|
|
|
static const char data[] =
|
|
|
|
"[Version]\n"
|
|
|
|
"Signature=\"$Chicago$\"\n"
|
|
|
|
"AdvancedINF=2.5\n"
|
|
|
|
"[DefaultInstall]\n"
|
|
|
|
"CheckAdminRights=1\n";
|
2006-07-08 03:30:46 +02:00
|
|
|
|
2008-12-05 04:26:48 +01:00
|
|
|
WriteFile(hf, data, sizeof(data) - 1, &dwNumberOfBytesWritten, NULL);
|
2006-07-08 03:30:46 +02:00
|
|
|
CloseHandle(hf);
|
|
|
|
}
|
|
|
|
|
2007-03-10 22:00:47 +01:00
|
|
|
static void test_RunSetupCommand(void)
|
2006-03-24 06:12:20 +01:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
HANDLE hexe;
|
2006-07-08 03:30:46 +02:00
|
|
|
char path[MAX_PATH];
|
|
|
|
char dir[MAX_PATH];
|
2007-05-19 22:34:43 +02:00
|
|
|
char systemdir[MAX_PATH];
|
|
|
|
|
|
|
|
GetSystemDirectoryA(systemdir, sizeof(systemdir));
|
2006-03-24 06:12:20 +01:00
|
|
|
|
|
|
|
/* try an invalid cmd name */
|
|
|
|
hr = pRunSetupCommand(NULL, NULL, "Install", "Dir", "Title", NULL, 0, NULL);
|
2006-10-12 02:12:46 +02:00
|
|
|
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
|
2006-03-24 06:12:20 +01:00
|
|
|
|
|
|
|
/* try an invalid directory */
|
|
|
|
hr = pRunSetupCommand(NULL, "winver.exe", "Install", NULL, "Title", NULL, 0, NULL);
|
2006-10-12 02:12:46 +02:00
|
|
|
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
|
2006-03-24 06:12:20 +01:00
|
|
|
|
2006-05-12 00:06:31 +02:00
|
|
|
/* try to run a nonexistent exe */
|
2006-03-27 05:38:40 +02:00
|
|
|
hexe = (HANDLE)0xdeadbeef;
|
2007-05-19 22:34:43 +02:00
|
|
|
hr = pRunSetupCommand(NULL, "idontexist.exe", "Install", systemdir, "Title", &hexe, 0, NULL);
|
2006-03-27 06:05:58 +02:00
|
|
|
ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
|
2006-10-12 02:12:46 +02:00
|
|
|
"Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr);
|
2011-08-03 23:50:18 +02:00
|
|
|
ok(hexe == NULL, "Expected hexe to be NULL\n");
|
2006-03-24 06:12:20 +01:00
|
|
|
ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n");
|
|
|
|
|
|
|
|
/* try a bad directory */
|
2006-03-27 05:38:40 +02:00
|
|
|
hexe = (HANDLE)0xdeadbeef;
|
2006-03-27 06:05:58 +02:00
|
|
|
hr = pRunSetupCommand(NULL, "winver.exe", "Install", "non\\existent\\directory", "Title", &hexe, 0, NULL);
|
|
|
|
ok(hr == HRESULT_FROM_WIN32(ERROR_DIRECTORY),
|
2006-10-12 02:12:46 +02:00
|
|
|
"Expected HRESULT_FROM_WIN32(ERROR_DIRECTORY), got %d\n", hr);
|
2011-08-03 23:50:18 +02:00
|
|
|
ok(hexe == NULL, "Expected hexe to be NULL\n");
|
2006-03-24 06:12:20 +01:00
|
|
|
ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n");
|
|
|
|
|
|
|
|
/* try to run an exe with the RSC_FLAG_INF flag */
|
2006-03-27 05:38:40 +02:00
|
|
|
hexe = (HANDLE)0xdeadbeef;
|
2007-05-19 22:34:43 +02:00
|
|
|
hr = pRunSetupCommand(NULL, "winver.exe", "Install", systemdir, "Title", &hexe, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
|
2011-02-25 23:28:33 +01:00
|
|
|
ok(is_spapi_err(hr), "Expected a setupapi error, got %d\n", hr);
|
2006-03-27 05:38:40 +02:00
|
|
|
ok(hexe == (HANDLE)0xdeadbeef, "Expected hexe to be 0xdeadbeef\n");
|
2006-03-24 06:12:20 +01:00
|
|
|
ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n");
|
|
|
|
|
|
|
|
/* run winver.exe */
|
2006-03-27 05:38:40 +02:00
|
|
|
hexe = (HANDLE)0xdeadbeef;
|
2007-05-19 22:34:43 +02:00
|
|
|
hr = pRunSetupCommand(NULL, "winver.exe", "Install", systemdir, "Title", &hexe, 0, NULL);
|
2006-10-12 02:12:46 +02:00
|
|
|
ok(hr == S_ASYNCHRONOUS, "Expected S_ASYNCHRONOUS, got %d\n", hr);
|
2006-03-27 05:40:26 +02:00
|
|
|
ok(hexe != NULL, "Expected hexe to be non-NULL\n");
|
|
|
|
ok(TerminateProcess(hexe, 0), "Expected TerminateProcess to succeed\n");
|
2006-07-08 03:30:46 +02:00
|
|
|
|
|
|
|
CreateDirectoryA("one", NULL);
|
|
|
|
create_inf_file("one\\test.inf");
|
|
|
|
|
|
|
|
/* try a full path to the INF, with working dir provided */
|
|
|
|
lstrcpy(path, CURR_DIR);
|
|
|
|
lstrcat(path, "\\one\\test.inf");
|
|
|
|
lstrcpy(dir, CURR_DIR);
|
|
|
|
lstrcat(dir, "\\one");
|
2006-08-21 11:31:17 +02:00
|
|
|
hr = pRunSetupCommand(NULL, path, "DefaultInstall", dir, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
|
2006-10-12 02:12:46 +02:00
|
|
|
ok(hr == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", hr);
|
2006-07-08 03:30:46 +02:00
|
|
|
|
|
|
|
/* try a full path to the INF, NULL working dir */
|
2006-08-21 11:31:17 +02:00
|
|
|
hr = pRunSetupCommand(NULL, path, "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
|
2006-07-08 03:30:46 +02:00
|
|
|
ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
|
2006-10-12 02:12:46 +02:00
|
|
|
"Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr);
|
2006-07-08 03:30:46 +02:00
|
|
|
|
|
|
|
/* try a full path to the INF, empty working dir */
|
2006-08-21 11:31:17 +02:00
|
|
|
hr = pRunSetupCommand(NULL, path, "DefaultInstall", "", "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
|
2006-10-12 02:12:46 +02:00
|
|
|
ok(hr == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", hr);
|
2006-07-08 03:30:46 +02:00
|
|
|
|
|
|
|
/* try a relative path to the INF, with working dir provided */
|
2006-08-21 11:31:17 +02:00
|
|
|
hr = pRunSetupCommand(NULL, "one\\test.inf", "DefaultInstall", dir, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
|
2011-02-25 23:28:33 +01:00
|
|
|
ok(hr == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", hr);
|
2006-07-08 03:30:46 +02:00
|
|
|
|
|
|
|
/* try a relative path to the INF, NULL working dir */
|
2006-08-21 11:31:17 +02:00
|
|
|
hr = pRunSetupCommand(NULL, "one\\test.inf", "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
|
2006-07-08 03:30:46 +02:00
|
|
|
ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
|
2006-10-12 02:12:46 +02:00
|
|
|
"Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr);
|
2006-07-08 03:30:46 +02:00
|
|
|
|
|
|
|
/* try a relative path to the INF, empty working dir */
|
2006-08-21 11:31:17 +02:00
|
|
|
hr = pRunSetupCommand(NULL, "one\\test.inf", "DefaultInstall", "", "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
|
2011-02-25 23:28:33 +01:00
|
|
|
ok(hr == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", hr);
|
2006-07-08 03:30:46 +02:00
|
|
|
|
|
|
|
/* try only the INF filename, with working dir provided */
|
2006-08-21 11:31:17 +02:00
|
|
|
hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", dir, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
|
2011-02-25 23:28:33 +01:00
|
|
|
ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr);
|
2006-07-08 03:30:46 +02:00
|
|
|
|
|
|
|
/* try only the INF filename, NULL working dir */
|
2006-08-21 11:31:17 +02:00
|
|
|
hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
|
2006-07-08 03:30:46 +02:00
|
|
|
ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
|
2006-10-12 02:12:46 +02:00
|
|
|
"Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr);
|
2006-07-08 03:30:46 +02:00
|
|
|
|
|
|
|
/* try only the INF filename, empty working dir */
|
2006-08-21 11:31:17 +02:00
|
|
|
hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", "", "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
|
2011-02-25 23:28:33 +01:00
|
|
|
ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr);
|
2006-07-08 03:30:46 +02:00
|
|
|
|
|
|
|
DeleteFileA("one\\test.inf");
|
|
|
|
RemoveDirectoryA("one");
|
|
|
|
|
|
|
|
create_inf_file("test.inf");
|
|
|
|
|
|
|
|
/* try INF file in the current directory, working directory provided */
|
2006-08-21 11:31:17 +02:00
|
|
|
hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", CURR_DIR, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
|
2011-02-25 23:28:33 +01:00
|
|
|
ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr);
|
2006-07-08 03:30:46 +02:00
|
|
|
|
|
|
|
/* try INF file in the current directory, NULL working directory */
|
2006-08-21 11:31:17 +02:00
|
|
|
hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", NULL, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
|
2006-07-08 03:30:46 +02:00
|
|
|
ok(hr == HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER),
|
2006-10-12 02:12:46 +02:00
|
|
|
"Expected HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER), got %d\n", hr);
|
2006-07-08 03:30:46 +02:00
|
|
|
|
|
|
|
/* try INF file in the current directory, empty working directory */
|
2006-08-21 11:31:17 +02:00
|
|
|
hr = pRunSetupCommand(NULL, "test.inf", "DefaultInstall", CURR_DIR, "Title", NULL, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
|
2011-02-25 23:28:33 +01:00
|
|
|
ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %d\n", hr);
|
2006-07-08 03:30:46 +02:00
|
|
|
}
|
|
|
|
|
2007-03-10 22:00:47 +01:00
|
|
|
static void test_LaunchINFSection(void)
|
2006-07-08 03:30:46 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
char cmdline[MAX_PATH];
|
2006-07-29 15:29:25 +02:00
|
|
|
static char file[] = "test.inf,DefaultInstall,4,0";
|
2006-07-08 03:30:46 +02:00
|
|
|
|
2007-11-13 20:50:14 +01:00
|
|
|
/* The 'No UI' flag seems to have no effect whatsoever on Windows.
|
|
|
|
* So only do this test in interactive mode.
|
|
|
|
*/
|
|
|
|
if (winetest_interactive)
|
|
|
|
{
|
|
|
|
/* try an invalid cmdline */
|
|
|
|
hr = pLaunchINFSection(NULL, NULL, NULL, 0);
|
|
|
|
ok(hr == 1, "Expected 1, got %d\n", hr);
|
|
|
|
}
|
2006-07-08 03:30:46 +02:00
|
|
|
|
|
|
|
CreateDirectoryA("one", NULL);
|
|
|
|
create_inf_file("one\\test.inf");
|
|
|
|
|
|
|
|
/* try a full path to the INF */
|
|
|
|
lstrcpy(cmdline, CURR_DIR);
|
|
|
|
lstrcat(cmdline, "\\");
|
|
|
|
lstrcat(cmdline, "one\\test.inf,DefaultInstall,,4");
|
|
|
|
hr = pLaunchINFSection(NULL, NULL, cmdline, 0);
|
2006-10-12 02:12:46 +02:00
|
|
|
ok(hr == 0, "Expected 0, got %d\n", hr);
|
2006-07-08 03:30:46 +02:00
|
|
|
|
|
|
|
DeleteFileA("one\\test.inf");
|
|
|
|
RemoveDirectoryA("one");
|
|
|
|
|
|
|
|
create_inf_file("test.inf");
|
|
|
|
|
|
|
|
/* try just the INF filename */
|
2006-07-29 15:29:25 +02:00
|
|
|
hr = pLaunchINFSection(NULL, NULL, file, 0);
|
2006-10-12 02:12:46 +02:00
|
|
|
ok(hr == 0, "Expected 0, got %d\n", hr);
|
2006-07-08 03:30:46 +02:00
|
|
|
|
|
|
|
DeleteFileA("test.inf");
|
2006-03-24 06:12:20 +01:00
|
|
|
}
|
|
|
|
|
2007-03-10 22:00:47 +01:00
|
|
|
static void test_LaunchINFSectionEx(void)
|
2006-10-24 03:44:59 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
char cmdline[MAX_PATH];
|
|
|
|
|
|
|
|
create_inf_file("test.inf");
|
|
|
|
|
2006-10-31 18:36:50 +01:00
|
|
|
/* try an invalid CAB filename with an absolute INF name */
|
2006-10-24 03:44:59 +02:00
|
|
|
lstrcpy(cmdline, CURR_DIR);
|
2006-10-31 15:17:31 +01:00
|
|
|
lstrcat(cmdline, "\\");
|
|
|
|
lstrcat(cmdline, "test.inf,DefaultInstall,c:imacab.cab,4");
|
2006-10-24 03:44:59 +02:00
|
|
|
hr = pLaunchINFSectionEx(NULL, NULL, cmdline, 0);
|
|
|
|
ok(hr == 0, "Expected 0, got %d\n", hr);
|
|
|
|
|
2007-11-13 20:50:14 +01:00
|
|
|
/* The 'No UI' flag seems to have no effect whatsoever on Windows.
|
|
|
|
* So only do this test in interactive mode.
|
|
|
|
*/
|
|
|
|
if (winetest_interactive)
|
|
|
|
{
|
|
|
|
/* try an invalid CAB filename with a relative INF name */
|
|
|
|
lstrcpy(cmdline, "test.inf,DefaultInstall,c:imacab.cab,4");
|
|
|
|
hr = pLaunchINFSectionEx(NULL, NULL, cmdline, 0);
|
|
|
|
ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
|
|
|
|
}
|
2006-10-31 18:36:50 +01:00
|
|
|
|
2006-10-24 03:44:59 +02:00
|
|
|
DeleteFileA("test.inf");
|
|
|
|
}
|
|
|
|
|
2006-03-24 06:12:20 +01:00
|
|
|
START_TEST(install)
|
|
|
|
{
|
2008-06-30 01:17:44 +02:00
|
|
|
DWORD len;
|
|
|
|
char temp_path[MAX_PATH], prev_path[MAX_PATH];
|
|
|
|
|
2006-03-24 06:12:20 +01:00
|
|
|
if (!init_function_pointers())
|
|
|
|
return;
|
|
|
|
|
2008-06-30 01:17:44 +02:00
|
|
|
GetCurrentDirectoryA(MAX_PATH, prev_path);
|
|
|
|
GetTempPath(MAX_PATH, temp_path);
|
|
|
|
SetCurrentDirectoryA(temp_path);
|
|
|
|
|
|
|
|
lstrcpyA(CURR_DIR, temp_path);
|
|
|
|
len = lstrlenA(CURR_DIR);
|
|
|
|
|
|
|
|
if(len && (CURR_DIR[len - 1] == '\\'))
|
|
|
|
CURR_DIR[len - 1] = 0;
|
2006-07-08 03:30:46 +02:00
|
|
|
|
2006-03-24 06:12:20 +01:00
|
|
|
test_RunSetupCommand();
|
2006-07-08 03:30:46 +02:00
|
|
|
test_LaunchINFSection();
|
2006-10-24 03:44:59 +02:00
|
|
|
test_LaunchINFSectionEx();
|
2008-03-09 12:15:05 +01:00
|
|
|
|
|
|
|
FreeLibrary(hAdvPack);
|
2008-06-30 01:17:44 +02:00
|
|
|
SetCurrentDirectoryA(prev_path);
|
2006-03-24 06:12:20 +01:00
|
|
|
}
|