wintrust: Implementation of WintrustRemoveActionID.
[wine] / dlls / wintrust / tests / register.c
1 /* Unit test suite for wintrust API functions
2  *
3  * Copyright 2006 Paul Vriens
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  *
19  */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #include "windows.h"
25 #include "softpub.h"
26 #include "wintrust.h"
27
28 #include "wine/test.h"
29
30 static BOOL (WINAPI * pWintrustAddActionID)(GUID*, DWORD, CRYPT_REGISTER_ACTIONID*);
31 static BOOL (WINAPI * pWintrustRemoveActionID)(GUID*);
32
33 static HMODULE hWintrust = 0;
34
35 #define WINTRUST_GET_PROC(func) \
36     p ## func = (void*)GetProcAddress(hWintrust, #func); \
37     if(!p ## func) { \
38       trace("GetProcAddress(%s) failed\n", #func); \
39       FreeLibrary(hWintrust); \
40       return FALSE; \
41     }
42
43 static BOOL InitFunctionPtrs(void)
44 {
45     hWintrust = LoadLibraryA("wintrust.dll");
46
47     if(!hWintrust)
48     {
49         trace("Could not load wintrust.dll\n");
50         return FALSE;
51     }
52
53     WINTRUST_GET_PROC(WintrustAddActionID)
54     WINTRUST_GET_PROC(WintrustRemoveActionID)
55
56     return TRUE;
57 }
58
59 static void test_AddRem_ActionID(void)
60 {
61     static WCHAR DummyDllW[]      = {'d','e','a','d','b','e','e','f','.','d','l','l',0 };
62     static WCHAR DummyFunctionW[] = {'d','u','m','m','y','f','u','n','c','t','i','o','n',0 };
63     GUID ActionID = { 0xdeadbe, 0xefde, 0xadbe, { 0xef,0xde,0xad,0xbe,0xef,0xde,0xad,0xbe }};
64     CRYPT_REGISTER_ACTIONID ActionIDFunctions;
65     CRYPT_TRUST_REG_ENTRY EmptyProvider = { 0, NULL, NULL };
66     CRYPT_TRUST_REG_ENTRY DummyProvider = { sizeof(CRYPT_TRUST_REG_ENTRY), DummyDllW, DummyFunctionW };
67     BOOL ret;
68
69     /* All NULL */
70     SetLastError(0xdeadbeef);
71     ret = pWintrustAddActionID(NULL, 0, NULL);
72     ok (!ret, "Expected WintrustAddActionID to fail.\n");
73     todo_wine
74     {
75         ok (GetLastError() == ERROR_INVALID_PARAMETER /* XP/W2K3 */ ||
76             GetLastError() == 0xdeadbeef              /* Win98/NT4/W2K */,
77             "Expected ERROR_INVALID_PARAMETER(W2K3) or 0xdeadbeef(Win98/NT4/W2K), got %ld.\n", GetLastError());
78     }
79
80     /* NULL functions */
81     SetLastError(0xdeadbeef);
82     ret = pWintrustAddActionID(&ActionID, 0, NULL);
83     ok (!ret, "Expected WintrustAddActionID to fail.\n");
84     todo_wine
85     {
86         ok (GetLastError() == ERROR_INVALID_PARAMETER /* XP/W2K3 */ ||
87             GetLastError() == 0xdeadbeef              /* Win98/NT4/W2K */,
88             "Expected ERROR_INVALID_PARAMETER(W2K3) or 0xdeadbeef(Win98/NT4/W2K), got %ld.\n", GetLastError());
89     }
90
91     /* All OK (although no functions defined), except cbStruct is not set in ActionIDFunctions */
92     SetLastError(0xdeadbeef);
93     memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
94     ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
95     ok (!ret, "Expected WintrustAddActionID to fail.\n");
96     todo_wine
97     {
98         ok (GetLastError() == ERROR_INVALID_PARAMETER /* XP/W2K3 */ ||
99             GetLastError() == 0xdeadbeef              /* Win98/NT4/W2K */,
100             "Expected ERROR_INVALID_PARAMETER(W2K3) or 0xdeadbeef(Win98/NT4/W2K), got %ld.\n", GetLastError());
101     }
102
103     /* All OK (although no functions defined) and cbStruct is set now */
104     SetLastError(0xdeadbeef);
105     memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
106     ActionIDFunctions.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
107     ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
108     todo_wine
109     {
110         ok (ret, "Expected WintrustAddActionID to succeed.\n");
111         ok (GetLastError() == ERROR_INVALID_PARAMETER /* W2K */,
112             "Expected ERROR_INVALID_PARAMETER, got %ld.\n", GetLastError());
113     }
114
115     /* All OK and all (but 1) functions are correctly defined. The DLL and entrypoints
116      * are not present.
117      */
118     memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
119     ActionIDFunctions.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
120     ActionIDFunctions.sInitProvider = DummyProvider;
121     ActionIDFunctions.sObjectProvider = DummyProvider;
122     ActionIDFunctions.sSignatureProvider = EmptyProvider;
123     ActionIDFunctions.sCertificateProvider = DummyProvider;
124     ActionIDFunctions.sCertificatePolicyProvider = DummyProvider;
125     ActionIDFunctions.sFinalPolicyProvider = DummyProvider;
126     ActionIDFunctions.sTestPolicyProvider = DummyProvider;
127     ActionIDFunctions.sCleanupProvider = DummyProvider;
128     SetLastError(0xdeadbeef);
129     ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
130     todo_wine
131     {
132         ok (ret, "Expected WintrustAddActionID to succeed.\n");
133         ok (GetLastError() == ERROR_INVALID_PARAMETER,
134             "Expected ERROR_INVALID_PARAMETER, got %ld.\n", GetLastError());
135     }
136
137     /* All OK and all functions are correctly defined. The DLL and entrypoints
138      * are not present.
139      */
140     memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
141     ActionIDFunctions.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
142     ActionIDFunctions.sInitProvider = DummyProvider;
143     ActionIDFunctions.sObjectProvider = DummyProvider;
144     ActionIDFunctions.sSignatureProvider = DummyProvider;
145     ActionIDFunctions.sCertificateProvider = DummyProvider;
146     ActionIDFunctions.sCertificatePolicyProvider = DummyProvider;
147     ActionIDFunctions.sFinalPolicyProvider = DummyProvider;
148     ActionIDFunctions.sTestPolicyProvider = DummyProvider;
149     ActionIDFunctions.sCleanupProvider = DummyProvider;
150     SetLastError(0xdeadbeef);
151     ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
152     todo_wine
153     {
154         ok (ret, "Expected WintrustAddActionID to succeed.\n");
155         ok (GetLastError() == 0xdeadbeef,
156             "Expected 0xdeadbeef, got %ld.\n", GetLastError());
157     }
158
159     SetLastError(0xdeadbeef);
160     ret = pWintrustRemoveActionID(&ActionID);
161     ok ( ret, "WintrustRemoveActionID failed : 0x%08lx\n", GetLastError());
162     ok ( GetLastError() == 0xdeadbeef, "Last error should not have been changed: 0x%08lx\n", GetLastError());
163
164     /* NULL input */
165     SetLastError(0xdeadbeef);
166     ret = pWintrustRemoveActionID(NULL);
167     ok (ret, "Expected WintrustRemoveActionID to succeed.\n");
168     ok (GetLastError() == ERROR_INVALID_PARAMETER,
169         "Expected ERROR_INVALID_PARAMETER, got %ld.\n", GetLastError());
170
171     /* The passed GUID is removed by a previous call, so it's basically a test with a non-existent Trust provider */ 
172     SetLastError(0xdeadbeef);
173     ret = pWintrustRemoveActionID(&ActionID);
174     ok (ret, "Expected WintrustRemoveActionID to succeed.\n");
175     ok (GetLastError() == 0xdeadbeef,
176         "Expected 0xdeadbeef, got %ld.\n", GetLastError());
177 }
178
179 START_TEST(register)
180 {
181     if(!InitFunctionPtrs())
182         return;
183
184     test_AddRem_ActionID();
185
186     FreeLibrary(hWintrust);
187 }