1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5/*=============================================================
6**
7** Source: test2.c (exception_handling\raiseexception\test2)
8**
9** Purpose: Tests that the correct arguments are passed
10** to the filter by RaiseException and tests that
11** the number of arguments never exceeds
12** EXCEPTION_MAXIMUM_PARAMETERS, even though we
13** pass a greater number of arguments
14**
15**
16**============================================================*/
17
18
19#include <palsuite.h>
20
21BOOL bFilter;
22BOOL bTry;
23BOOL bExcept;
24
25ULONG_PTR lpArguments_test1[EXCEPTION_MAXIMUM_PARAMETERS];
26DWORD nArguments_test1 = EXCEPTION_MAXIMUM_PARAMETERS;
27
28ULONG_PTR lpArguments_test2[EXCEPTION_MAXIMUM_PARAMETERS+1];
29DWORD nArguments_test2 = EXCEPTION_MAXIMUM_PARAMETERS+1;
30
31
32/**
33**
34** Filter function that checks for the parameters
35**
36**/
37LONG Filter_test1(EXCEPTION_POINTERS* ep, VOID *unused)
38{
39 int i;
40
41 /* let the main know we've hit the filter function */
42 bFilter = TRUE;
43
44 if (!bTry)
45 {
46 Fail("PAL_EXCEPT_FILTER_EX: ERROR -> Something weird is going on."
47 " The filter was hit without PAL_TRY being hit.\n");
48 }
49
50
51 /* was the correct number of arguments passed */
52 if (ep->ExceptionRecord->NumberParameters != (DWORD) nArguments_test1)
53 {
54 Fail("RaiseException: ERROR -> Number of arguments passed to filter"
55 " was %d when it should have been %d",
56 ep->ExceptionRecord->NumberParameters,
57 nArguments_test1);
58
59 }
60
61 /* were the correct arguments passed */
62 for( i=0; ((DWORD)i)<nArguments_test1; i++ )
63 {
64 if( ep->ExceptionRecord->ExceptionInformation[i]
65 != lpArguments_test1[i])
66 {
67 Fail("RaiseException: ERROR -> Argument %d passed to filter"
68 " was %d when it should have been %d",
69 i,
70 ep->ExceptionRecord->ExceptionInformation[i],
71 lpArguments_test1[i]);
72 }
73 }
74
75 return EXCEPTION_EXECUTE_HANDLER;
76}
77
78/**
79**
80** Filter function that checks for the maximum parameters
81**
82**/
83LONG Filter_test2(EXCEPTION_POINTERS* ep, VOID* unused)
84{
85 /* let the main know we've hit the filter function */
86 bFilter = TRUE;
87
88 if (ep->ExceptionRecord->NumberParameters > EXCEPTION_MAXIMUM_PARAMETERS)
89 {
90 Fail("RaiseException: ERROR -> Number of arguments passed to filter"
91 " was %d which is greater than the maximum allowed of %d\n",
92 ep->ExceptionRecord->NumberParameters,
93 EXCEPTION_MAXIMUM_PARAMETERS);
94 }
95
96 return EXCEPTION_EXECUTE_HANDLER;
97}
98
99int __cdecl main(int argc, char *argv[])
100{
101 bExcept = FALSE;
102
103 if (0 != PAL_Initialize(argc, argv))
104 {
105 return FAIL;
106 }
107
108 /********************************************************
109 * Test that the correct arguments are passed
110 * to the filter by RaiseException
111 */
112 PAL_TRY(VOID*, unused, NULL)
113 {
114 bTry = TRUE; /* indicate we hit the PAL_TRY block */
115
116 /* Initialize arguments to pass to filter */
117 for(int i = 0; ((DWORD)i) < nArguments_test1; i++ )
118 {
119 lpArguments_test1[i] = i;
120 }
121
122 RaiseException(0,0,nArguments_test1,lpArguments_test1);
123
124 Fail("RaiseException: ERROR -> code was executed after the "
125 "exception was raised.\n");
126 }
127 PAL_EXCEPT_FILTER(Filter_test1)
128 {
129 if (!bTry)
130 {
131 Fail("RaiseException: ERROR -> Something weird is going on."
132 " PAL_EXCEPT_FILTER was hit without PAL_TRY being hit.\n");
133 }
134 bExcept = TRUE; /* indicate we hit the PAL_EXCEPT_FILTER_EX block */
135 }
136 PAL_ENDTRY;
137
138 if (!bTry)
139 {
140 Trace("RaiseException: ERROR -> It appears the code in the "
141 "PAL_TRY block was not executed.\n");
142 }
143
144 if (!bExcept)
145 {
146 Trace("RaiseException: ERROR -> It appears the code in the "
147 "PAL_EXCEPT_FILTER_EX block was not executed.\n");
148 }
149
150 if (!bFilter)
151 {
152 Trace("RaiseException: ERROR -> It appears the code in the"
153 " filter function was not executed.\n");
154 }
155
156 /* did we hit all the code blocks? */
157 if(!bTry || !bExcept || !bFilter)
158 {
159 Fail("");
160 }
161
162
163 /* Reinit flags */
164 bTry = bExcept = bFilter = FALSE;
165
166 /********************************************************
167 * Test that the number of arguments never
168 * exceeds EXCEPTION_MAXIMUM_PARAMETERS, even though we
169 * pass a greater number of arguments
170 */
171 PAL_TRY(VOID*, unused, NULL)
172 {
173 bTry = TRUE; /* indicate we hit the PAL_TRY block */
174
175 /* Initialize arguments to pass to filter */
176 for(int i = 0; ((DWORD)i) < nArguments_test2; i++ )
177 {
178 lpArguments_test2[i] = i;
179 }
180
181 RaiseException(0,0,nArguments_test2,lpArguments_test2);
182
183 Fail("RaiseException: ERROR -> code was executed after the "
184 "exception was raised.\n");
185 }
186 PAL_EXCEPT_FILTER(Filter_test2)
187 {
188 if (!bTry)
189 {
190 Fail("RaiseException: ERROR -> Something weird is going on."
191 " PAL_EXCEPT_FILTER was hit without PAL_TRY being hit.\n");
192 }
193 bExcept = TRUE; /* indicate we hit the PAL_EXCEPT_FILTER_EX block */
194 }
195 PAL_ENDTRY;
196
197 if (!bTry)
198 {
199 Trace("RaiseException: ERROR -> It appears the code in the "
200 "PAL_TRY block was not executed.\n");
201 }
202
203 if (!bExcept)
204 {
205 Trace("RaiseException: ERROR -> It appears the code in the "
206 "PAL_EXCEPT_FILTER_EX block was not executed.\n");
207 }
208
209 if (!bFilter)
210 {
211 Trace("RaiseException: ERROR -> It appears the code in the"
212 " filter function was not executed.\n");
213 }
214
215 /* did we hit all the code blocks? */
216 if(!bTry || !bExcept || !bFilter)
217 {
218 Fail("");
219 }
220
221 PAL_Terminate();
222 return PASS;
223
224}
225