1 /* Standalone program to test functionality of exceptions.
3 * Copyright (c) 2004 MX Telecom Ltd. <richardv@mxtelecom.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program 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
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "exceptions.h"
27 gboolean failed = FALSE;
30 finally_called_uncaught_exception(volatile unsigned int* called)
42 finally_called_rethrown_exception(volatile unsigned int* thrown, volatile unsigned int* called)
58 finally_called_exception_from_catch(volatile unsigned int* thrown, volatile unsigned int* called)
65 printf("05: Looping exception\n");
81 volatile unsigned int ex_thrown, finally_called;
83 /* check that the right catch, and the finally, are called, on exception */
84 ex_thrown = finally_called = 0;
91 CATCH(FragmentBoundsError) {
92 printf("01: Caught wrong exception: FragmentBoundsError\n");
95 CATCH(ReportedBoundsError) {
96 printf("01: Caught wrong exception: ReportedBoundsError\n");
100 printf("01: Caught wrong exception: %lu\n", exc->except_id.except_code);
108 if (ex_thrown != 1) {
109 printf("01: %u BoundsErrors (not 1) on caught exception\n", ex_thrown);
113 if (finally_called != 1) {
114 printf("01: FINALLY called %u times (not 1) on caught exception\n", finally_called);
119 /* check that no catch at all is called when there is no exn */
120 ex_thrown = finally_called = 0;
124 printf("02: Caught wrong exception: BoundsError\n");
127 CATCH(FragmentBoundsError) {
128 printf("02: Caught wrong exception: FragmentBoundsError\n");
131 CATCH(ReportedBoundsError) {
132 printf("02: Caught wrong exception: ReportedBoundsError\n");
136 printf("02: Caught wrong exception: %lu\n", exc->except_id.except_code);
144 if (finally_called != 1) {
145 printf("02: FINALLY called %u times (not 1) on no exception\n", finally_called);
149 /* check that finally is called on an uncaught exception */
150 ex_thrown = finally_called = 0;
152 finally_called_uncaught_exception(&finally_called);
159 if (finally_called != 1) {
160 printf("03: FINALLY called %u times (not 1) on uncaught exception\n", finally_called);
164 if (ex_thrown != 1) {
165 printf("03: %u BoundsErrors (not 1) on uncaught exception\n", ex_thrown);
170 /* check that finally is called on an rethrown exception */
171 ex_thrown = finally_called = 0;
173 finally_called_rethrown_exception(&ex_thrown, &finally_called);
183 if (finally_called != 11) {
184 printf("04: finally_called = %u (not 11) on rethrown exception\n", finally_called);
188 if (ex_thrown != 11) {
189 printf("04: %u BoundsErrors (not 11) on rethrown exception\n", ex_thrown);
194 /* check that finally is called on an exception thrown from a CATCH block */
195 ex_thrown = finally_called = 0;
197 finally_called_exception_from_catch(&ex_thrown, &finally_called);
207 if (finally_called != 11) {
208 printf("05: finally_called = %u (not 11) on exception thrown from CATCH\n", finally_called);
212 if (ex_thrown != 11) {
213 printf("05: %u BoundsErrors (not 11) on exception thrown from CATCH\n", ex_thrown);
230 * Editor modelines - http://www.wireshark.org/tools/modelines.html
235 * indent-tabs-mode: nil
238 * vi: set shiftwidth=4 tabstop=8 expandtab:
239 * :indentSize=4:tabSize=8:noTabs=true: