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;
33 volatile unsigned int ex_thrown, finally_called;
35 /* check that the right catch, and the finally, are called, on exception */
36 ex_thrown = finally_called = 0;
43 CATCH(FragmentBoundsError) {
44 printf("01: Caught wrong exception: FragmentBoundsError\n");
47 CATCH(ReportedBoundsError) {
48 printf("01: Caught wrong exception: ReportedBoundsError\n");
52 printf("01: Caught wrong exception: %lu\n", exc->except_id.except_code);
61 printf("01: %u BoundsErrors (not 1) on caught exception\n", ex_thrown);
65 if (finally_called != 1) {
66 printf("01: FINALLY called %u times (not 1) on caught exception\n", finally_called);
71 /* check that no catch at all is called when there is no exn */
72 ex_thrown = finally_called = 0;
76 printf("02: Caught wrong exception: BoundsError\n");
79 CATCH(FragmentBoundsError) {
80 printf("02: Caught wrong exception: FragmentBoundsError\n");
83 CATCH(ReportedBoundsError) {
84 printf("02: Caught wrong exception: ReportedBoundsError\n");
88 printf("02: Caught wrong exception: %lu\n", exc->except_id.except_code);
96 if (finally_called != 1) {
97 printf("02: FINALLY called %u times (not 1) on no exception\n", finally_called);
101 /* check that finally is called on an uncaught exception */
102 ex_thrown = finally_called = 0;
117 if (finally_called != 1) {
118 printf("03: FINALLY called %u times (not 1) on uncaught exception\n", finally_called);
122 if (ex_thrown != 1) {
123 printf("03: %u BoundsErrors (not 1) on uncaught exception\n", ex_thrown);
128 /* check that finally is called on an rethrown exception */
129 ex_thrown = finally_called = 0;
139 finally_called += 10;
151 if (finally_called != 11) {
152 printf("04: finally_called = %u (not 11) on rethrown exception\n", finally_called);
156 if (ex_thrown != 11) {
157 printf("04: %u BoundsErrors (not 11) on rethrown exception\n", ex_thrown);
162 /* check that finally is called on an exception thrown from a CATCH block */
163 ex_thrown = finally_called = 0;
170 printf("05: Looping exception\n");
178 finally_called += 10;
190 if (finally_called != 11) {
191 printf("05: finally_called = %u (not 11) on exception thrown from CATCH\n", finally_called);
195 if (ex_thrown != 11) {
196 printf("05: %u BoundsErrors (not 11) on exception thrown from CATCH\n", ex_thrown);
214 * Editor modelines - http://www.wireshark.org/tools/modelines.html
219 * indent-tabs-mode: nil
222 * vi: set shiftwidth=4 tabstop=8 expandtab:
223 * :indentSize=4:tabSize=8:noTabs=true: