FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
test/TestTypes.c
1
20#include <winpr/crt.h>
21#include <winpr/error.h>
22
23static BOOL test_co_errors(void)
24{
25 const LONG should[] = {
26 (LONG)0x80004006l, (LONG)0x80004007l, (LONG)0x80004008l, (LONG)0x80004009l,
27 (LONG)0x8000400Al, (LONG)0x8000400Bl, (LONG)0x8000400Cl, (LONG)0x8000400Dl,
28 (LONG)0x8000400El, (LONG)0x8000400Fl, (LONG)0x80004010l, (LONG)0x80004011l,
29 (LONG)0x80004012l, (LONG)0x80004013l, (LONG)0x80004014l, (LONG)0x80004015l,
30 (LONG)0x80004016l, (LONG)0x80004017l, (LONG)0x80004018l, (LONG)0x80004019l,
31 (LONG)0x8000401Al, (LONG)0x8000401Bl, (LONG)0x8000401Cl, (LONG)0x8000401Dl,
32 (LONG)0x8000401El, (LONG)0x8000401Fl, (LONG)0x80004020l, (LONG)0x80004021l,
33 (LONG)0x80004022l, (LONG)0x80004023l, (LONG)0x80004024l, (LONG)0x80004025l,
34 (LONG)0x80004026l, (LONG)0x80004027l, (LONG)0x80004028l, (LONG)0x80004029l,
35 (LONG)0x8000402Al, (LONG)0x8000402Bl, (LONG)0x80004030l, (LONG)0x80004031l,
36 (LONG)0x80004032l, (LONG)0x80004033l, (LONG)0x8000FFFFL, (LONG)0x80070005L,
37 (LONG)0x80070006L, (LONG)0x8007000EL, (LONG)0x80070057L, (LONG)0x80004001L,
38 (LONG)0x80004002L, (LONG)0x80004003L, (LONG)0x80004004L, (LONG)0x80004005L
39 };
40 const LONG are[] = { CO_E_INIT_TLS,
41 CO_E_INIT_SHARED_ALLOCATOR,
42 CO_E_INIT_MEMORY_ALLOCATOR,
43 CO_E_INIT_CLASS_CACHE,
44 CO_E_INIT_RPC_CHANNEL,
45 CO_E_INIT_TLS_SET_CHANNEL_CONTROL,
46 CO_E_INIT_TLS_CHANNEL_CONTROL,
47 CO_E_INIT_UNACCEPTED_USER_ALLOCATOR,
48 CO_E_INIT_SCM_MUTEX_EXISTS,
49 CO_E_INIT_SCM_FILE_MAPPING_EXISTS,
50 CO_E_INIT_SCM_MAP_VIEW_OF_FILE,
51 CO_E_INIT_SCM_EXEC_FAILURE,
52 CO_E_INIT_ONLY_SINGLE_THREADED,
53 CO_E_CANT_REMOTE,
54 CO_E_BAD_SERVER_NAME,
55 CO_E_WRONG_SERVER_IDENTITY,
56 CO_E_OLE1DDE_DISABLED,
57 CO_E_RUNAS_SYNTAX,
58 CO_E_CREATEPROCESS_FAILURE,
59 CO_E_RUNAS_CREATEPROCESS_FAILURE,
60 CO_E_RUNAS_LOGON_FAILURE,
61 CO_E_LAUNCH_PERMSSION_DENIED,
62 CO_E_START_SERVICE_FAILURE,
63 CO_E_REMOTE_COMMUNICATION_FAILURE,
64 CO_E_SERVER_START_TIMEOUT,
65 CO_E_CLSREG_INCONSISTENT,
66 CO_E_IIDREG_INCONSISTENT,
67 CO_E_NOT_SUPPORTED,
68 CO_E_RELOAD_DLL,
69 CO_E_MSI_ERROR,
70 CO_E_ATTEMPT_TO_CREATE_OUTSIDE_CLIENT_CONTEXT,
71 CO_E_SERVER_PAUSED,
72 CO_E_SERVER_NOT_PAUSED,
73 CO_E_CLASS_DISABLED,
74 CO_E_CLRNOTAVAILABLE,
75 CO_E_ASYNC_WORK_REJECTED,
76 CO_E_SERVER_INIT_TIMEOUT,
77 CO_E_NO_SECCTX_IN_ACTIVATE,
78 CO_E_TRACKER_CONFIG,
79 CO_E_THREADPOOL_CONFIG,
80 CO_E_SXS_CONFIG,
81 CO_E_MALFORMED_SPN,
82 E_UNEXPECTED,
83 E_ACCESSDENIED,
84 E_HANDLE,
85 E_OUTOFMEMORY,
86 E_INVALIDARG,
87 E_NOTIMPL,
88 E_NOINTERFACE,
89 E_POINTER,
90 E_ABORT,
91 E_FAIL };
92
93 if (ARRAYSIZE(should) != ARRAYSIZE(are))
94 {
95 const size_t a = ARRAYSIZE(should);
96 const size_t b = ARRAYSIZE(are);
97 printf("mismatch: %" PRIuz " vs %" PRIuz "\n", a, b);
98 return FALSE;
99 }
100 for (size_t x = 0; x < ARRAYSIZE(are); x++)
101 {
102 const LONG a = are[x];
103 const LONG b = should[x];
104 if (a != b)
105 {
106 printf("mismatch[%" PRIuz "]: %08" PRIx32 " vs %08" PRIx32 "\n", x, a, b);
107 return FALSE;
108 }
109 }
110 return TRUE;
111}
112
113static BOOL TestSucceededFailedMacros(HRESULT hr, char* sym, BOOL isSuccess)
114{
115 BOOL rv = TRUE;
116
117 if (SUCCEEDED(hr) && !isSuccess)
118 {
119 printf("Error: SUCCEEDED with \"%s\" must be false\n", sym);
120 rv = FALSE;
121 }
122 if (!SUCCEEDED(hr) && isSuccess)
123 {
124 printf("Error: SUCCEEDED with \"%s\" must be true\n", sym);
125 rv = FALSE;
126 }
127 if (!FAILED(hr) && !isSuccess)
128 {
129 printf("Error: FAILED with \"%s\" must be true\n", sym);
130 rv = FALSE;
131 }
132 if (FAILED(hr) && isSuccess)
133 {
134 printf("Error: FAILED with \"%s\" must be false\n", sym);
135 rv = FALSE;
136 }
137
138 return rv;
139}
140
141int TestTypes(int argc, char* argv[])
142{
143 BOOL ok = TRUE;
144 HRESULT hr = 0;
145
146 WINPR_UNUSED(argc);
147 WINPR_UNUSED(argv);
148
149 if (!test_co_errors())
150 goto err;
151
152 if (S_OK != 0L)
153 {
154 printf("Error: S_OK should be 0\n");
155 goto err;
156 }
157 if (S_FALSE != 1L)
158 {
159 printf("Error: S_FALSE should be 1\n");
160 goto err;
161 }
162
163 /* Test HRESULT success codes */
164 ok &= TestSucceededFailedMacros(S_OK, "S_OK", TRUE);
165 ok &= TestSucceededFailedMacros(S_FALSE, "S_FALSE", TRUE);
166
167 /* Test some HRESULT error codes */
168 ok &= TestSucceededFailedMacros(E_NOTIMPL, "E_NOTIMPL", FALSE);
169 ok &= TestSucceededFailedMacros(E_OUTOFMEMORY, "E_OUTOFMEMORY", FALSE);
170 ok &= TestSucceededFailedMacros(E_INVALIDARG, "E_INVALIDARG", FALSE);
171 ok &= TestSucceededFailedMacros(E_FAIL, "E_FAIL", FALSE);
172 ok &= TestSucceededFailedMacros(E_ABORT, "E_ABORT", FALSE);
173
174 /* Test some WIN32 error codes converted to HRESULT*/
175 hr = HRESULT_FROM_WIN32(ERROR_SUCCESS);
176 ok &= TestSucceededFailedMacros(hr, "HRESULT_FROM_WIN32(ERROR_SUCCESS)", TRUE);
177
178 hr = HRESULT_FROM_WIN32(ERROR_INVALID_FUNCTION);
179 ok &= TestSucceededFailedMacros(hr, "HRESULT_FROM_WIN32(ERROR_INVALID_FUNCTION)", FALSE);
180
181 hr = HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);
182 ok &= TestSucceededFailedMacros(hr, "HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED)", FALSE);
183
184 hr = HRESULT_FROM_WIN32(ERROR_NOACCESS);
185 ok &= TestSucceededFailedMacros(hr, "HRESULT_FROM_WIN32(ERROR_NOACCESS)", FALSE);
186
187 hr = HRESULT_FROM_WIN32(ERROR_NOT_FOUND);
188 ok &= TestSucceededFailedMacros(hr, "HRESULT_FROM_WIN32(ERROR_NOT_FOUND)", FALSE);
189
190 hr = HRESULT_FROM_WIN32(ERROR_TIMEOUT);
191 ok &= TestSucceededFailedMacros(hr, "HRESULT_FROM_WIN32(ERROR_TIMEOUT)", FALSE);
192
193 hr = HRESULT_FROM_WIN32(RPC_S_ZERO_DIVIDE);
194 ok &= TestSucceededFailedMacros(hr, "HRESULT_FROM_WIN32(RPC_S_ZERO_DIVIDE)", FALSE);
195
196 hr = HRESULT_FROM_WIN32(ERROR_STATIC_INIT);
197 ok &= TestSucceededFailedMacros(hr, "HRESULT_FROM_WIN32(ERROR_STATIC_INIT)", FALSE);
198
199 hr = HRESULT_FROM_WIN32(ERROR_ENCRYPTION_FAILED);
200 ok &= TestSucceededFailedMacros(hr, "HRESULT_FROM_WIN32(ERROR_ENCRYPTION_FAILED)", FALSE);
201
202 hr = HRESULT_FROM_WIN32(WSAECANCELLED);
203 ok &= TestSucceededFailedMacros(hr, "HRESULT_FROM_WIN32(WSAECANCELLED)", FALSE);
204
205 if (ok)
206 {
207 printf("Test completed successfully\n");
208 return 0;
209 }
210
211err:
212 printf("Error: Test failed\n");
213 return -1;
214}