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.
25 #include "exceptions.h"
27 gboolean failed = FALSE;
32 volatile unsigned int ex_thrown, finally_called;
34 /* check that the right catch, and the finally, are called, on exception */
35 ex_thrown = finally_called = 0;
42 CATCH(ReportedBoundsError) {
43 printf("01: Caught wrong exception: ReportedBoundsError\n");
47 printf("01: Caught wrong exception: %lu\n", exc->except_id.except_code);
56 printf("01: %u BoundsErrors (not 1) on caught exception\n", ex_thrown);
60 if (finally_called != 1) {
61 printf("01: FINALLY called %u times (not 1) on caught exception\n", finally_called);
66 /* check that no catch at all is called when there is no exn */
67 ex_thrown = finally_called = 0;
71 printf("02: Caught wrong exception: BoundsError\n");
74 CATCH(ReportedBoundsError) {
75 printf("02: Caught wrong exception: ReportedBoundsError\n");
79 printf("02: Caught wrong exception: %lu\n", exc->except_id.except_code);
87 if (finally_called != 1) {
88 printf("02: FINALLY called %u times (not 1) on no exception\n", finally_called);
93 /* check that finally is called on an uncaught exception */
94 ex_thrown = finally_called = 0;
109 if (finally_called != 1) {
110 printf("03: FINALLY called %u times (not 1) on uncaught exception\n", finally_called);
114 if (ex_thrown != 1) {
115 printf("03: %u BoundsErrors (not 1) on uncaught exception\n", ex_thrown);
120 /* check that finally is called on an rethrown exception */
121 ex_thrown = finally_called = 0;
131 finally_called += 10;
143 if (finally_called != 11) {
144 printf("04: finally_called = %u (not 11) on rethrown exception\n", finally_called);
148 if (ex_thrown != 11) {
149 printf("04: %u BoundsErrors (not 11) on rethrown exception\n", ex_thrown);
154 /* check that finally is called on an exception thrown from a CATCH block */
155 ex_thrown = finally_called = 0;
162 printf("05: Looping exception\n");
170 finally_called += 10;
182 if (finally_called != 11) {
183 printf("05: finally_called = %u (not 11) on exception thrown from CATCH\n", finally_called);
187 if (ex_thrown != 11) {
188 printf("05: %u BoundsErrors (not 11) on exception thrown from CATCH\n", ex_thrown);