1 /* Unit test suite for wintrust API functions
3 * Copyright 2006 Paul Vriens
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.
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.
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
28 #include "wine/test.h"
30 static BOOL (WINAPI * pWintrustAddActionID)(GUID*, DWORD, CRYPT_REGISTER_ACTIONID*);
31 static BOOL (WINAPI * pWintrustRemoveActionID)(GUID*);
33 static HMODULE hWintrust = 0;
35 #define WINTRUST_GET_PROC(func) \
36 p ## func = (void*)GetProcAddress(hWintrust, #func); \
38 trace("GetProcAddress(%s) failed\n", #func); \
39 FreeLibrary(hWintrust); \
43 static BOOL InitFunctionPtrs(void)
45 hWintrust = LoadLibraryA("wintrust.dll");
49 trace("Could not load wintrust.dll\n");
53 WINTRUST_GET_PROC(WintrustAddActionID)
54 WINTRUST_GET_PROC(WintrustRemoveActionID)
59 static void test_AddRem_ActionID(void)
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 };
70 SetLastError(0xdeadbeef);
71 ret = pWintrustAddActionID(NULL, 0, NULL);
72 ok (!ret, "Expected WintrustAddActionID to fail.\n");
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());
81 SetLastError(0xdeadbeef);
82 ret = pWintrustAddActionID(&ActionID, 0, NULL);
83 ok (!ret, "Expected WintrustAddActionID to fail.\n");
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());
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");
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());
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);
110 ok (ret, "Expected WintrustAddActionID to succeed.\n");
111 ok (GetLastError() == ERROR_INVALID_PARAMETER /* W2K */,
112 "Expected ERROR_INVALID_PARAMETER, got %ld.\n", GetLastError());
115 /* All OK and all (but 1) functions are correctly defined. The DLL and entrypoints
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);
132 ok (ret, "Expected WintrustAddActionID to succeed.\n");
133 ok (GetLastError() == ERROR_INVALID_PARAMETER,
134 "Expected ERROR_INVALID_PARAMETER, got %ld.\n", GetLastError());
137 /* All OK and all functions are correctly defined. The DLL and entrypoints
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);
154 ok (ret, "Expected WintrustAddActionID to succeed.\n");
155 ok (GetLastError() == 0xdeadbeef,
156 "Expected 0xdeadbeef, got %ld.\n", GetLastError());
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());
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());
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());
181 if(!InitFunctionPtrs())
184 test_AddRem_ActionID();
186 FreeLibrary(hWintrust);