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);
29 static BOOL init_function_pointers()
31 HMODULE hAdvPack = LoadLibraryA("advpack.dll");
35 pRunSetupCommand = (void *)GetProcAddress(hAdvPack, "RunSetupCommand");
37 if (!pRunSetupCommand)
43 static BOOL is_spapi_err(DWORD err)
45 const DWORD SPAPI_PREFIX = 0x800F0000L;
46 const DWORD SPAPI_MASK = 0xFFFF0000L;
48 return (((err & SPAPI_MASK) ^ SPAPI_PREFIX) == 0);
51 static void test_RunSetupCommand()
56 /* try an invalid cmd name */
57 hr = pRunSetupCommand(NULL, NULL, "Install", "Dir", "Title", NULL, 0, NULL);
58 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr);
60 /* try an invalid directory */
61 hr = pRunSetupCommand(NULL, "winver.exe", "Install", NULL, "Title", NULL, 0, NULL);
62 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr);
64 /* try to run a nonexistent exe */
65 hexe = (HANDLE)0xdeadbeef;
66 hr = pRunSetupCommand(NULL, "idontexist.exe", "Install", "c:\\windows\\system32", "Title", &hexe, 0, NULL);
67 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
68 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %ld\n", hr);
69 ok(hexe == NULL, "Expcted hexe to be NULL\n");
70 ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n");
72 /* try a bad directory */
73 hexe = (HANDLE)0xdeadbeef;
74 hr = pRunSetupCommand(NULL, "winver.exe", "Install", "non\\existent\\directory", "Title", &hexe, 0, NULL);
75 ok(hr == HRESULT_FROM_WIN32(ERROR_DIRECTORY),
76 "Expected HRESULT_FROM_WIN32(ERROR_DIRECTORY), got %ld\n", hr);
77 ok(hexe == NULL, "Expcted hexe to be NULL\n");
78 ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n");
80 /* try to run an exe with the RSC_FLAG_INF flag */
81 hexe = (HANDLE)0xdeadbeef;
82 hr = pRunSetupCommand(NULL, "winver.exe", "Install", "c:\\windows\\system32", "Title", &hexe, RSC_FLAG_INF, NULL);
83 ok(is_spapi_err(hr), "Expected a setupapi error, got %ld\n", hr);
84 ok(hexe == (HANDLE)0xdeadbeef, "Expected hexe to be 0xdeadbeef\n");
85 ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n");
88 hexe = (HANDLE)0xdeadbeef;
89 hr = pRunSetupCommand(NULL, "winver.exe", "Install", "c:\\windows\\system32", "Title", &hexe, 0, NULL);
90 ok(hr == S_ASYNCHRONOUS, "Expected S_ASYNCHRONOUS, got %ld\n", hr);
91 ok(hexe != NULL, "Expected hexe to be non-NULL\n");
92 ok(TerminateProcess(hexe, 0), "Expected TerminateProcess to succeed\n");
97 if (!init_function_pointers())
100 test_RunSetupCommand();