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"
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
|
|
static BOOL init_function_pointers()
|
|
|
|
{
|
|
|
|
HMODULE hAdvPack = LoadLibraryA("advpack.dll");
|
|
|
|
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-08 03:30:46 +02:00
|
|
|
static void append_str(char **str, const char *data)
|
|
|
|
{
|
|
|
|
sprintf(*str, data);
|
|
|
|
*str += strlen(*str);
|
|
|
|
}
|
|
|
|
|
2006-07-29 15:29:25 +02:00
|
|
|
static void create_inf_file(LPCSTR filename)
|
2006-07-08 03:30:46 +02:00
|
|
|
{
|
|
|
|
char data[1024];
|
|
|
|
char *ptr = data;
|
|
|
|
DWORD dwNumberOfBytesWritten;
|
|
|
|
HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
|
|
|
|
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
|
|
|
|
append_str(&ptr, "[Version]\n");
|
|
|
|
append_str(&ptr, "Signature=\"$Chicago$\"\n");
|
|
|
|
append_str(&ptr, "AdvancedINF=2.5\n");
|
|
|
|
append_str(&ptr, "[DefaultInstall]\n");
|
|
|
|
append_str(&ptr, "RegisterOCXs=RegisterOCXsSection\n");
|
|
|
|
append_str(&ptr, "[RegisterOCXsSection]\n");
|
|
|
|
append_str(&ptr, "%%11%%\\ole32.dll\n");
|
|
|
|
|
|
|
|
WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
|
|
|
|
CloseHandle(hf);
|
|
|
|
}
|
|
|
|
|
2006-03-24 06:12:20 +01:00
|
|
|
static void test_RunSetupCommand()
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
HANDLE hexe;
|
2006-07-08 03:30:46 +02:00
|
|
|
char path[MAX_PATH];
|
|
|
|
char dir[MAX_PATH];
|
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;
|
2006-03-24 06:12:20 +01:00
|
|
|
hr = pRunSetupCommand(NULL, "idontexist.exe", "Install", "c:\\windows\\system32", "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);
|
2006-03-24 06:12:20 +01:00
|
|
|
ok(hexe == NULL, "Expcted hexe to be NULL\n");
|
|
|
|
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);
|
2006-03-24 06:12:20 +01:00
|
|
|
ok(hexe == NULL, "Expcted hexe to be NULL\n");
|
|
|
|
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;
|
2006-08-21 11:31:17 +02:00
|
|
|
hr = pRunSetupCommand(NULL, "winver.exe", "Install", "c:\\windows\\system32", "Title", &hexe, RSC_FLAG_INF | RSC_FLAG_QUIET, NULL);
|
2006-10-12 02:12:46 +02: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;
|
2006-03-24 06:12:20 +01:00
|
|
|
hr = pRunSetupCommand(NULL, "winver.exe", "Install", "c:\\windows\\system32", "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);
|
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, 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);
|
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 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);
|
2006-07-08 03:30:46 +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);
|
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);
|
2006-08-30 00:12:22 +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);
|
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);
|
2006-07-08 03:30:46 +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);
|
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);
|
2006-07-08 03:30:46 +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);
|
2006-07-08 03:30:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_LaunchINFSection()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
/* try an invalid cmdline */
|
|
|
|
hr = pLaunchINFSection(NULL, NULL, NULL, 0);
|
2006-10-12 02:12:46 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2006-10-24 03:44:59 +02:00
|
|
|
static void test_LaunchINFSectionEx()
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
2006-10-31 18:36:50 +01:00
|
|
|
/* 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);
|
2006-11-01 20:52:58 +01:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (!init_function_pointers())
|
|
|
|
return;
|
|
|
|
|
2006-07-08 03:30:46 +02:00
|
|
|
GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
|
|
|
|
|
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();
|
2006-03-24 06:12:20 +01:00
|
|
|
}
|