HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / exntest.c
blobf8b77da8f52cc006ae4c8217568696ec0eca8bce
1 /* Standalone program to test functionality of exceptions.
3 * $Id$
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include <stdio.h>
24 #include <glib.h>
25 #include <config.h>
26 #include "exceptions.h"
28 gboolean failed = FALSE;
30 void
31 run_tests(void)
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;
37 TRY {
38 THROW(BoundsError);
40 CATCH(BoundsError) {
41 ex_thrown++;
43 CATCH(FragmentBoundsError) {
44 printf("01: Caught wrong exception: FragmentBoundsError\n");
45 failed = TRUE;
47 CATCH(ReportedBoundsError) {
48 printf("01: Caught wrong exception: ReportedBoundsError\n");
49 failed = TRUE;
51 CATCH_ALL {
52 printf("01: Caught wrong exception: %lu\n", exc->except_id.except_code);
53 failed = TRUE;
55 FINALLY {
56 finally_called ++;
58 ENDTRY;
60 if (ex_thrown != 1) {
61 printf("01: %u BoundsErrors (not 1) on caught exception\n", ex_thrown);
62 failed = TRUE;
65 if (finally_called != 1) {
66 printf("01: FINALLY called %u times (not 1) on caught exception\n", finally_called);
67 failed = TRUE;
71 /* check that no catch at all is called when there is no exn */
72 ex_thrown = finally_called = 0;
73 TRY {
75 CATCH(BoundsError) {
76 printf("02: Caught wrong exception: BoundsError\n");
77 failed = TRUE;
79 CATCH(FragmentBoundsError) {
80 printf("02: Caught wrong exception: FragmentBoundsError\n");
81 failed = TRUE;
83 CATCH(ReportedBoundsError) {
84 printf("02: Caught wrong exception: ReportedBoundsError\n");
85 failed = TRUE;
87 CATCH_ALL {
88 printf("02: Caught wrong exception: %lu\n", exc->except_id.except_code);
89 failed = TRUE;
91 FINALLY {
92 finally_called ++;
94 ENDTRY;
96 if (finally_called != 1) {
97 printf("02: FINALLY called %u times (not 1) on no exception\n", finally_called);
98 failed = TRUE;
102 /* check that finally is called on an uncaught exception */
103 ex_thrown = finally_called = 0;
104 TRY {
105 TRY {
106 THROW(BoundsError);
108 FINALLY {
109 finally_called ++;
111 ENDTRY;
113 CATCH(BoundsError) {
114 ex_thrown++;
116 ENDTRY;
118 if (finally_called != 1) {
119 printf("03: FINALLY called %u times (not 1) on uncaught exception\n", finally_called);
120 failed = TRUE;
123 if (ex_thrown != 1) {
124 printf("03: %u BoundsErrors (not 1) on uncaught exception\n", ex_thrown);
125 failed = TRUE;
129 /* check that finally is called on an rethrown exception */
130 ex_thrown = finally_called = 0;
131 TRY {
132 TRY {
133 THROW(BoundsError);
135 CATCH_ALL {
136 ex_thrown += 10;
137 RETHROW;
139 FINALLY {
140 finally_called += 10;
142 ENDTRY;
144 CATCH(BoundsError) {
145 ex_thrown ++;
147 FINALLY {
148 finally_called ++;
150 ENDTRY;
152 if (finally_called != 11) {
153 printf("04: finally_called = %u (not 11) on rethrown exception\n", finally_called);
154 failed = TRUE;
157 if (ex_thrown != 11) {
158 printf("04: %u BoundsErrors (not 11) on rethrown exception\n", ex_thrown);
159 failed = TRUE;
163 /* check that finally is called on an exception thrown from a CATCH block */
164 ex_thrown = finally_called = 0;
165 TRY {
166 TRY {
167 THROW(BoundsError);
169 CATCH_ALL {
170 if(ex_thrown > 0) {
171 printf("05: Looping exception\n");
172 failed = TRUE;
173 } else {
174 ex_thrown += 10;
175 THROW(BoundsError);
178 FINALLY {
179 finally_called += 10;
181 ENDTRY;
183 CATCH(BoundsError) {
184 ex_thrown ++;
186 FINALLY {
187 finally_called ++;
189 ENDTRY;
191 if (finally_called != 11) {
192 printf("05: finally_called = %u (not 11) on exception thrown from CATCH\n", finally_called);
193 failed = TRUE;
196 if (ex_thrown != 11) {
197 printf("05: %u BoundsErrors (not 11) on exception thrown from CATCH\n", ex_thrown);
198 failed = TRUE;
201 if(failed == FALSE )
202 printf("success\n");
205 int main(void)
207 except_init();
208 run_tests();
209 except_deinit();
210 exit(failed?1:0);