advpack: Set hexe to a non-NULL value to test that the handle is NULL on return.
[wine/dcerpc.git] / dlls / advpack / tests / install.c
blob6d0daaeebba0702653cd9c6246ad094f0b16bab5
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <stdio.h>
22 #include <windows.h>
23 #include <advpub.h>
24 #include <urlmon.h>
25 #include "wine/test.h"
27 /* function pointers */
28 static HRESULT (WINAPI *pRunSetupCommand)(HWND, LPCSTR, LPCSTR, LPCSTR, LPCSTR, HANDLE*, DWORD, LPVOID);
30 static BOOL init_function_pointers()
32 HMODULE hAdvPack = LoadLibraryA("advpack.dll");
33 if (!hAdvPack)
34 return FALSE;
36 pRunSetupCommand = (void *)GetProcAddress(hAdvPack, "RunSetupCommand");
38 if (!pRunSetupCommand)
39 return FALSE;
41 return TRUE;
44 static void test_RunSetupCommand()
46 HRESULT hr;
47 HANDLE hexe;
49 /* try an invalid cmd name */
50 hr = pRunSetupCommand(NULL, NULL, "Install", "Dir", "Title", NULL, 0, NULL);
51 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr);
53 /* try an invalid directory */
54 hr = pRunSetupCommand(NULL, "winver.exe", "Install", NULL, "Title", NULL, 0, NULL);
55 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %ld\n", hr);
57 /* try to run a non-existent exe */
58 hexe = (HANDLE)0xdeadbeef;
59 hr = pRunSetupCommand(NULL, "idontexist.exe", "Install", "c:\\windows\\system32", "Title", &hexe, 0, NULL);
60 todo_wine
62 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
63 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %ld\n", hr);
65 ok(hexe == NULL, "Expcted hexe to be NULL\n");
66 ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n");
68 /* try a bad directory */
69 hexe = (HANDLE)0xdeadbeef;
70 hr = pRunSetupCommand(NULL, "winver.exe", "Install", "windows\\system32", "Title", &hexe, 0, NULL);
71 todo_wine
73 ok(hr == HRESULT_FROM_WIN32(ERROR_DIRECTORY),
74 "Expected HRESULT_FROM_WIN32(ERROR_DIRECTORY), got %ld\n", hr);
76 ok(hexe == NULL, "Expcted hexe to be NULL\n");
77 ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n");
79 /* try to run an exe with the RSC_FLAG_INF flag */
80 hexe = (HANDLE)0xdeadbeef;
81 hr = pRunSetupCommand(NULL, "winver.exe", "Install", "c:\\windows\\system32", "Title", &hexe, RSC_FLAG_INF, NULL);
82 todo_wine
84 ok(hr == SPAPI_E_WRONG_INF_STYLE, "Expected SPAPI_E_WRONG_INF_STYLE, got %ld\n", hr);
86 ok(hexe == (HANDLE)0xdeadbeef, "Expected hexe to be 0xdeadbeef\n");
87 ok(!TerminateProcess(hexe, 0), "Expected TerminateProcess to fail\n");
89 /* run winver.exe */
90 hexe = (HANDLE)0xdeadbeef;
91 hr = pRunSetupCommand(NULL, "winver.exe", "Install", "c:\\windows\\system32", "Title", &hexe, 0, NULL);
92 todo_wine
94 ok(hr == S_ASYNCHRONOUS, "Expected S_ASYNCHRONOUS, got %ld\n", hr);
95 ok(hexe != NULL, "Expected hexe to be non-NULL\n");
96 ok(TerminateProcess(hexe, 0), "Expected TerminateProcess to succeed\n");
100 START_TEST(install)
102 if (!init_function_pointers())
103 return;
105 test_RunSetupCommand();