1 /* Standalone program to test functionality of exceptions.
5 * Copyright (c) 2004 MX Telecom Ltd. <richardv@mxtelecom.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #include "exceptions.h"
28 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(ReportedBoundsError) {
44 printf("01: Caught wrong exception: ReportedBoundsError\n");
48 printf("01: Caught wrong exception: %lu\n", exc->except_id.except_code);
57 printf("01: %u BoundsErrors (not 1) on caught exception\n", ex_thrown);
61 if (finally_called != 1) {
62 printf("01: FINALLY called %u times (not 1) on caught exception\n", finally_called);
67 /* check that no catch at all is called when there is no exn */
68 ex_thrown = finally_called = 0;
72 printf("02: Caught wrong exception: BoundsError\n");
75 CATCH(ReportedBoundsError) {
76 printf("02: Caught wrong exception: ReportedBoundsError\n");
80 printf("02: Caught wrong exception: %lu\n", exc->except_id.except_code);
88 if (finally_called != 1) {
89 printf("02: FINALLY called %u times (not 1) on no exception\n", finally_called);
94 /* check that finally is called on an uncaught exception */
95 ex_thrown = finally_called = 0;
110 if (finally_called != 1) {
111 printf("03: FINALLY called %u times (not 1) on uncaught exception\n", finally_called);
115 if (ex_thrown != 1) {
116 printf("03: %u BoundsErrors (not 1) on uncaught exception\n", ex_thrown);
121 /* check that finally is called on an rethrown exception */
122 ex_thrown = finally_called = 0;
132 finally_called += 10;
144 if (finally_called != 11) {
145 printf("04: finally_called = %u (not 11) on rethrown exception\n", finally_called);
149 if (ex_thrown != 11) {
150 printf("04: %u BoundsErrors (not 11) on rethrown exception\n", ex_thrown);
155 /* check that finally is called on an exception thrown from a CATCH block */
156 ex_thrown = finally_called = 0;
163 printf("05: Looping exception\n");
171 finally_called += 10;
183 if (finally_called != 11) {
184 printf("05: finally_called = %u (not 11) on exception thrown from CATCH\n", finally_called);
188 if (ex_thrown != 11) {
189 printf("05: %u BoundsErrors (not 11) on exception thrown from CATCH\n", ex_thrown);