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.
24 #include "exceptions.h"
26 #include <wsutil/ws_diag_control.h>
28 gboolean failed = FALSE;
34 volatile unsigned int ex_thrown, finally_called;
36 /* check that the right catch, and the finally, are called, on exception */
37 ex_thrown = finally_called = 0;
44 CATCH(FragmentBoundsError) {
45 printf("01: Caught wrong exception: FragmentBoundsError\n");
48 CATCH(ReportedBoundsError) {
49 printf("01: Caught wrong exception: ReportedBoundsError\n");
53 printf("01: Caught wrong exception: %lu\n", exc->except_id.except_code);
62 printf("01: %u BoundsErrors (not 1) on caught exception\n", ex_thrown);
66 if (finally_called != 1) {
67 printf("01: FINALLY called %u times (not 1) on caught exception\n", finally_called);
72 /* check that no catch at all is called when there is no exn */
73 ex_thrown = finally_called = 0;
77 printf("02: Caught wrong exception: BoundsError\n");
80 CATCH(FragmentBoundsError) {
81 printf("02: Caught wrong exception: FragmentBoundsError\n");
84 CATCH(ReportedBoundsError) {
85 printf("02: Caught wrong exception: ReportedBoundsError\n");
89 printf("02: Caught wrong exception: %lu\n", exc->except_id.except_code);
97 if (finally_called != 1) {
98 printf("02: FINALLY called %u times (not 1) on no exception\n", finally_called);
102 /* check that finally is called on an uncaught exception */
103 ex_thrown = finally_called = 0;
118 if (finally_called != 1) {
119 printf("03: FINALLY called %u times (not 1) on uncaught exception\n", finally_called);
123 if (ex_thrown != 1) {
124 printf("03: %u BoundsErrors (not 1) on uncaught exception\n", ex_thrown);
129 /* check that finally is called on an rethrown exception */
130 ex_thrown = finally_called = 0;
140 finally_called += 10;
152 if (finally_called != 11) {
153 printf("04: finally_called = %u (not 11) on rethrown exception\n", finally_called);
157 if (ex_thrown != 11) {
158 printf("04: %u BoundsErrors (not 11) on rethrown exception\n", ex_thrown);
163 /* check that finally is called on an exception thrown from a CATCH block */
164 ex_thrown = finally_called = 0;
171 printf("05: Looping exception\n");
179 finally_called += 10;
191 if (finally_called != 11) {
192 printf("05: finally_called = %u (not 11) on exception thrown from CATCH\n", finally_called);
196 if (ex_thrown != 11) {
197 printf("05: %u BoundsErrors (not 11) on exception thrown from CATCH\n", ex_thrown);
215 * Editor modelines - http://www.wireshark.org/tools/modelines.html
220 * indent-tabs-mode: nil
223 * vi: set shiftwidth=4 tabstop=8 expandtab:
224 * :indentSize=4:tabSize=8:noTabs=true: