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: test.c (exception_handling\raiseexception\test3)
8**
9** Purpose: Tests that the correct ExceptionCode is passed
10** to the filter by RaiseException
11**
12**
13**============================================================*/
14
15
16#include <palsuite.h>
17
18BOOL bFilter = FALSE;
19BOOL bTry = FALSE;
20BOOL bExcept = FALSE;
21
22/**
23**
24** Filter function that checks for the parameters
25**
26**/
27LONG Filter_test1(EXCEPTION_POINTERS* ep, VOID* unused)
28{
29 /* let the main know we've hit the filter function */
30 bFilter = TRUE;
31
32 if (!bTry)
33 {
34 Fail("PAL_EXCEPT_FILTER_EX: ERROR -> Something weird is going on."
35 " The filter was hit without PAL_TRY being hit.\n");
36 }
37
38
39 /* was the correct exception code passed? */
40 if (ep->ExceptionRecord->ExceptionCode != EXCEPTION_ARRAY_BOUNDS_EXCEEDED)
41 {
42 Fail("RaiseException: ERROR -> ep->ExceptionRecord->ExceptionCode"
43 " was %x when it was expected to be %x\n",
44 ep->ExceptionRecord->ExceptionCode,
45 EXCEPTION_ARRAY_BOUNDS_EXCEEDED);
46
47 }
48
49 return EXCEPTION_EXECUTE_HANDLER;
50}
51
52int __cdecl main(int argc, char *argv[])
53{
54 bExcept = FALSE;
55
56 if (0 != PAL_Initialize(argc, argv))
57 {
58 return FAIL;
59 }
60
61 /********************************************************
62 * Test that the correct arguments are passed
63 * to the filter by RaiseException
64 */
65 PAL_TRY(VOID*, unused, NULL)
66 {
67 bTry = TRUE; /* indicate we hit the PAL_TRY block */
68
69 RaiseException(EXCEPTION_ARRAY_BOUNDS_EXCEEDED,
70 0,
71 0,NULL);
72
73 Fail("RaiseException: ERROR -> code was executed after the "
74 "exception was raised.\n");
75 }
76 PAL_EXCEPT_FILTER(Filter_test1)
77 {
78 if (!bTry)
79 {
80 Fail("RaiseException: ERROR -> Something weird is going on."
81 " PAL_EXCEPT_FILTER was hit without PAL_TRY being hit.\n");
82 }
83 bExcept = TRUE; /* indicate we hit the PAL_EXCEPT_FILTER_EX block */
84 }
85 PAL_ENDTRY;
86
87 if (!bTry)
88 {
89 Trace("RaiseException: ERROR -> It appears the code in the "
90 "PAL_TRY block was not executed.\n");
91 }
92
93 if (!bExcept)
94 {
95 Trace("RaiseException: ERROR -> It appears the code in the "
96 "PAL_EXCEPT_FILTER_EX block was not executed.\n");
97 }
98
99 if (!bFilter)
100 {
101 Trace("RaiseException: ERROR -> It appears the code in the"
102 " filter function was not executed.\n");
103 }
104
105 /* did we hit all the code blocks? */
106 if(!bTry || !bExcept || !bFilter)
107 {
108 Fail("");
109 }
110
111
112 PAL_Terminate();
113 return PASS;
114
115}
116