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: test1.c |
8 | ** |
9 | ** Purpose: Tests that RaiseException throws a catchable exception |
10 | ** and Tests the behaviour of RaiseException with |
11 | ** PAL_FINALLY |
12 | ** |
13 | ** |
14 | **============================================================*/ |
15 | |
16 | |
17 | #include <palsuite.h> |
18 | |
19 | BOOL bExcept = FALSE; |
20 | BOOL bTry = FALSE; |
21 | BOOL bFinally = FALSE; |
22 | |
23 | int __cdecl main(int argc, char *argv[]) |
24 | { |
25 | |
26 | if(0 != (PAL_Initialize(argc, argv))) |
27 | { |
28 | return FAIL; |
29 | } |
30 | |
31 | /********************************************************* |
32 | * Tests that RaiseException throws a catchable exception |
33 | */ |
34 | PAL_TRY(VOID*, unused, NULL) |
35 | { |
36 | bTry = TRUE; |
37 | RaiseException(0,0,0,0); |
38 | |
39 | Fail("RaiseException: ERROR -> code was executed after the " |
40 | "exception was raised.\n" ); |
41 | } |
42 | PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) |
43 | { |
44 | bExcept = TRUE; |
45 | } |
46 | PAL_ENDTRY; |
47 | |
48 | if (!bTry) |
49 | { |
50 | Trace("RaiseException: ERROR -> It appears the code in the " |
51 | "PAL_TRY block was not executed.\n" ); |
52 | } |
53 | |
54 | if (!bExcept) |
55 | { |
56 | Trace("RaiseException: ERROR -> It appears the code in the " |
57 | "PAL_EXCEPT_FILTER_EX block was not executed.\n" ); |
58 | } |
59 | |
60 | /* did we hit all the code blocks? */ |
61 | if(!bTry || !bExcept) |
62 | { |
63 | Fail("" ); |
64 | } |
65 | |
66 | /* Reinit flags */ |
67 | bTry = bExcept = FALSE; |
68 | |
69 | |
70 | /********************************************************* |
71 | * Tests the behaviour of RaiseException with |
72 | * PAL_FINALLY |
73 | * (bFinally should be set before bExcept) |
74 | */ |
75 | PAL_TRY(VOID*, unused, NULL) |
76 | { |
77 | PAL_TRY(VOID*, unused, NULL) |
78 | { |
79 | bTry = TRUE; |
80 | RaiseException(0,0,0,0); |
81 | |
82 | Fail("RaiseException: ERROR -> code was executed after the " |
83 | "exception was raised.\n" ); |
84 | } |
85 | PAL_FINALLY |
86 | { |
87 | bFinally = TRUE; |
88 | } |
89 | PAL_ENDTRY; |
90 | } |
91 | PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) |
92 | { |
93 | if( bFinally == FALSE ) |
94 | { |
95 | Fail("RaiseException: ERROR -> It appears the code in the " |
96 | "PAL_EXCEPT executed before the code in PAL_FINALLY.\n" ); |
97 | } |
98 | |
99 | bExcept = TRUE; |
100 | } |
101 | |
102 | PAL_ENDTRY; |
103 | |
104 | if (!bTry) |
105 | { |
106 | Trace("RaiseException: ERROR -> It appears the code in the " |
107 | "PAL_TRY block was not executed.\n" ); |
108 | } |
109 | |
110 | if (!bExcept) |
111 | { |
112 | Trace("RaiseException: ERROR -> It appears the code in the " |
113 | "PAL_EXCEPT block was not executed.\n" ); |
114 | } |
115 | |
116 | if (!bFinally) |
117 | { |
118 | Trace("RaiseException: ERROR -> It appears the code in the " |
119 | "PAL_FINALLY block was not executed.\n" ); |
120 | } |
121 | |
122 | /* did we hit all the code blocks? */ |
123 | if(!bTry || !bExcept || !bFinally) |
124 | { |
125 | Fail("" ); |
126 | } |
127 | |
128 | PAL_Terminate(); |
129 | return PASS; |
130 | } |
131 | |