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 ------------------------------------------------------*/
39 #define FINALLY_TOLERATE_BUG_CAPTURE_COPIES 1
41 #include "finally-test.h"
43 /*----- Main code ---------------------------------------------------------*/
45 static int test_softball(void)
47 FINALLY({ STEP(1); });
53 static int test_ordering(void)
55 FINALLY({ STEP(2); });
56 FINALLY({ STEP(1); });
63 #ifndef FINALLY_BUG_CAPTURE_COPIES
64 static int test_capture(void)
66 int n
= -1; FINALLY({ STEP(n
); });
73 static int test_internal_block(void)
76 FINALLY({ STEP(10); });
78 for (i
= 0; i
< 5; i
++) {
79 FINALLY({ STEP(2*i
+ 1); });
85 static int test_local_xfer(void)
91 { FINALLY({ STEP(2); }); STEP(1); }
94 FINALLY({ STEP(4); });
96 if (secretly_true
) break;
100 for (i
= 0; i
< 5; i
++) {
102 if (i
== 3) STEP(46);
103 else STEP(12*i
+ 16);
106 for (j
= 0; j
< 5; j
++) {
107 FINALLY({ STEP(12*i
+ 2*j
+ 7); });
108 if (i
== 3 && j
== 1) { STEP(44); goto escape
; }
109 else if (j
!= 3) STEP(12*i
+ 2*j
+ 6);
110 else { FINALLY({ STEP(12*i
+ 2*j
+ 6); }); continue; }
119 #if defined(HAVE_FEXCEPTIONS)
120 void try_catch_filling(unsigned f
)
122 int outstep
= f
&TCF_THROW ?
12 : 5; FINALLY({ STEP(outstep
); });
124 if (f
&TCF_THROW
) STEP(10);
131 static int test_try_catch(void)
136 try_catch_outer(TCF_THROW
);
145 #define RUNTEST(name) \
146 do { begin_test(#name); STEP(test_##name()); end_test(); } while (0)
147 #define SKIPTEST(name, excuse) skip_test(#name, excuse)
152 #ifndef FINALLY_BUG_CAPTURE_COPIES
155 SKIPTEST(capture
, "selected flavour captures copies");
157 RUNTEST(internal_block
);
158 #if defined(HAVE_FEXCEPTIONS)
161 SKIPTEST(try_catch
, "no C++ compiler or no exception-handling support");
167 return (test_report());
170 /*----- That's all, folks -------------------------------------------------*/