dnsapi: Cast-qual warnings fix.
[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     ok (GetLastError() == ERROR_INVALID_PARAMETER /* XP/W2K3 */ ||
74         GetLastError() == 0xdeadbeef              /* Win98/NT4/W2K */,
75         "Expected ERROR_INVALID_PARAMETER(W2K3) or 0xdeadbeef(Win98/NT4/W2K), got %ld.\n", GetLastError());
76
77     /* NULL functions */
78     SetLastError(0xdeadbeef);
79     ret = pWintrustAddActionID(&ActionID, 0, NULL);
80     ok (!ret, "Expected WintrustAddActionID to fail.\n");
81     ok (GetLastError() == ERROR_INVALID_PARAMETER /* XP/W2K3 */ ||
82         GetLastError() == 0xdeadbeef              /* Win98/NT4/W2K */,
83         "Expected ERROR_INVALID_PARAMETER(W2K3) or 0xdeadbeef(Win98/NT4/W2K), got %ld.\n", GetLastError());
84
85     /* All OK (although no functions defined), except cbStruct is not set in ActionIDFunctions */
86     SetLastError(0xdeadbeef);
87     memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
88     ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
89     ok (!ret, "Expected WintrustAddActionID to fail.\n");
90     ok (GetLastError() == ERROR_INVALID_PARAMETER /* XP/W2K3 */ ||
91         GetLastError() == 0xdeadbeef              /* Win98/NT4/W2K */,
92         "Expected ERROR_INVALID_PARAMETER(W2K3) or 0xdeadbeef(Win98/NT4/W2K), got %ld.\n", GetLastError());
93
94     /* All OK (although no functions defined) and cbStruct is set now */
95     SetLastError(0xdeadbeef);
96     memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
97     ActionIDFunctions.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
98     ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
99     ok (ret, "Expected WintrustAddActionID to succeed.\n");
100     ok (GetLastError() == ERROR_INVALID_PARAMETER,
101         "Expected ERROR_INVALID_PARAMETER, got %ld.\n", GetLastError());
102
103     /* All OK and all (but 1) functions are correctly defined. The DLL and entrypoints
104      * are not present.
105      */
106     memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
107     ActionIDFunctions.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
108     ActionIDFunctions.sInitProvider = DummyProvider;
109     ActionIDFunctions.sObjectProvider = DummyProvider;
110     ActionIDFunctions.sSignatureProvider = EmptyProvider;
111     ActionIDFunctions.sCertificateProvider = DummyProvider;
112     ActionIDFunctions.sCertificatePolicyProvider = DummyProvider;
113     ActionIDFunctions.sFinalPolicyProvider = DummyProvider;
114     ActionIDFunctions.sTestPolicyProvider = DummyProvider;
115     ActionIDFunctions.sCleanupProvider = DummyProvider;
116     SetLastError(0xdeadbeef);
117     ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
118     ok (ret, "Expected WintrustAddActionID to succeed.\n");
119     ok (GetLastError() == ERROR_INVALID_PARAMETER,
120         "Expected ERROR_INVALID_PARAMETER, got %ld.\n", GetLastError());
121
122     /* All OK and all functions are correctly defined. The DLL and entrypoints
123      * are not present.
124      */
125     memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
126     ActionIDFunctions.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
127     ActionIDFunctions.sInitProvider = DummyProvider;
128     ActionIDFunctions.sObjectProvider = DummyProvider;
129     ActionIDFunctions.sSignatureProvider = DummyProvider;
130     ActionIDFunctions.sCertificateProvider = DummyProvider;
131     ActionIDFunctions.sCertificatePolicyProvider = DummyProvider;
132     ActionIDFunctions.sFinalPolicyProvider = DummyProvider;
133     ActionIDFunctions.sTestPolicyProvider = DummyProvider;
134     ActionIDFunctions.sCleanupProvider = DummyProvider;
135     SetLastError(0xdeadbeef);
136     ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
137     ok (ret, "Expected WintrustAddActionID to succeed.\n");
138     ok (GetLastError() == 0xdeadbeef,
139         "Expected 0xdeadbeef, got %ld.\n", GetLastError());
140
141     SetLastError(0xdeadbeef);
142     ret = pWintrustRemoveActionID(&ActionID);
143     ok ( ret, "WintrustRemoveActionID failed : 0x%08lx\n", GetLastError());
144     ok ( GetLastError() == 0xdeadbeef, "Last error should not have been changed: 0x%08lx\n", GetLastError());
145
146     /* NULL input */
147     SetLastError(0xdeadbeef);
148     ret = pWintrustRemoveActionID(NULL);
149     ok (ret, "Expected WintrustRemoveActionID to succeed.\n");
150     ok (GetLastError() == ERROR_INVALID_PARAMETER,
151         "Expected ERROR_INVALID_PARAMETER, got %ld.\n", GetLastError());
152
153     /* The passed GUID is removed by a previous call, so it's basically a test with a nonexistent Trust provider */ 
154     SetLastError(0xdeadbeef);
155     ret = pWintrustRemoveActionID(&ActionID);
156     ok (ret, "Expected WintrustRemoveActionID to succeed.\n");
157     ok (GetLastError() == 0xdeadbeef,
158         "Expected 0xdeadbeef, got %ld.\n", GetLastError());
159 }
160
161 START_TEST(register)
162 {
163     if(!InitFunctionPtrs())
164         return;
165
166     test_AddRem_ActionID();
167
168     FreeLibrary(hWintrust);
169 }