3 * Test program for using `finally.h'
5 * (c) 2023 Mark Wooding
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the `Finally' package.
12 * Finally is free software: you can redistribute it and/or modify it
13 * under the terms of the GNU Library General Public License as published
14 * by the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * Finally is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
20 * License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with Finally. If not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
30 * This file is also compiled as C++, so we must be careful to keep it in the
31 * common subset of C and C++. Anything language-specific needs to be split
32 * off into its own separate source file.
35 /*----- Header files ------------------------------------------------------*/
40 #include "finally-test.h"
42 /*----- Main code ---------------------------------------------------------*/
44 static int test_softball(void)
46 FINALLY({ STEP(1); });
52 static int test_ordering(void)
54 FINALLY({ STEP(2); });
55 FINALLY({ STEP(1); });
62 static int test_capture(void)
64 int n
= -1; FINALLY({ STEP(n
); });
70 static int test_internal_block(void)
73 FINALLY({ STEP(10); });
75 for (i
= 0; i
< 5; i
++) {
76 FINALLY({ STEP(2*i
+ 1); });
82 static int test_local_xfer(void)
88 { FINALLY({ STEP(2); }); STEP(1); }
91 FINALLY({ STEP(4); });
93 if (secretly_true
) break;
97 for (i
= 0; i
< 5; i
++) {
100 else STEP(12*i
+ 16);
103 for (j
= 0; j
< 5; j
++) {
104 FINALLY({ STEP(12*i
+ 2*j
+ 7); });
105 if (i
== 3 && j
== 1) { STEP(44); goto escape
; }
106 else if (j
!= 3) STEP(12*i
+ 2*j
+ 6);
107 else { FINALLY({ STEP(12*i
+ 2*j
+ 6); }); continue; }
116 #if defined(HAVE_FEXCEPTIONS)
117 void try_catch_filling(unsigned f
)
119 int outstep
= f
&TCF_THROW ?
12 : 5; FINALLY({ STEP(outstep
); });
121 if (f
&TCF_THROW
) STEP(10);
128 static int test_try_catch(void)
133 try_catch_outer(TCF_THROW
);
142 #define RUNTEST(name) \
143 do { begin_test(#name); STEP(test_##name()); end_test(); } while (0)
144 #define SKIPTEST(name, excuse) skip_test(#name, excuse)
150 RUNTEST(internal_block
);
151 #if defined(HAVE_FEXCEPTIONS)
154 SKIPTEST(try_catch
, "no C++ compiler or no exception-handling support");
160 return (test_report());
163 /*----- That's all, folks -------------------------------------------------*/