wined3d: Implement more GLSL instructions and a little cleanup.
[wine] / dlls / advpack / tests / install.c
1 /*
2  * Unit tests for advpack.dll install functions
3  *
4  * Copyright (C) 2006 James Hawkins
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdio.h>
22 #include <windows.h>
23 #include <advpub.h>
24 #include "wine/test.h"
25
26 /* function pointers */
27 static HRESULT (WINAPI *pRunSetupCommand)(HWND, LPCSTR, LPCSTR, LPCSTR, LPCSTR, HANDLE*, DWORD, LPVOID);
28
29 static BOOL init_function_pointers()
30 {
31     HMODULE hAdvPack = LoadLibraryA("advpack.dll");
32     if (!hAdvPack)
33         return FALSE;
34
35     pRunSetupCommand = (void *)GetProcAddress(hAdvPack, "RunSetupCommand");
36
37     if (!pRunSetupCommand)
38         return FALSE;
39
40     return TRUE;
41 }
42
43 static BOOL is_spapi_err(DWORD err)
44 {
45     const DWORD SPAPI_PREFIX = 0x800F0000L;
46     const DWORD SPAPI_MASK = 0xFFFF0000L;
47
48     return (((err & SPAPI_MASK) ^ SPAPI_PREFIX) == 0);
49 }
50
51 static void test_RunSetupCommand()
52 {
53     HRESULT hr;
54     HANDLE hexe;
55
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);
59
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);
63
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");
71
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");
79
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");
86
87     /* run winver.exe */
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");
93 }
94
95 START_TEST(install)
96 {
97     if (!init_function_pointers())
98         return;
99
100     test_RunSetupCommand();
101 }