1 | |
---|
2 | #include <stdlib.h> |
---|
3 | #include <stdio.h> |
---|
4 | #include <assert.h> |
---|
5 | |
---|
6 | #include <drmaa_utils/common.h> |
---|
7 | |
---|
8 | |
---|
9 | void |
---|
10 | raise_ex( int err_code ) |
---|
11 | { |
---|
12 | fsd_exc_raise_code( err_code ); |
---|
13 | printf( "after raise\n" ); |
---|
14 | assert(0); |
---|
15 | } |
---|
16 | |
---|
17 | |
---|
18 | void |
---|
19 | runner( void (*function)(void) ) |
---|
20 | { |
---|
21 | int volatile in_except_default_block = 0; |
---|
22 | TRY |
---|
23 | { |
---|
24 | printf( "runner: before\n" ); |
---|
25 | function(); |
---|
26 | printf( "runner: after\n" ); |
---|
27 | assert(0); |
---|
28 | } |
---|
29 | EXCEPT_DEFAULT |
---|
30 | { |
---|
31 | printf( "runner: except: %s\n", fsd_exc_get()->_message ); |
---|
32 | in_except_default_block = 1; |
---|
33 | } |
---|
34 | END_TRY |
---|
35 | |
---|
36 | assert(in_except_default_block); |
---|
37 | } |
---|
38 | |
---|
39 | |
---|
40 | void test_0(void) |
---|
41 | { |
---|
42 | TRY |
---|
43 | { printf( "try\n" ); } |
---|
44 | EXCEPT( FSD_ERRNO_INVALID_VALUE ) |
---|
45 | { |
---|
46 | printf( "except\n" ); |
---|
47 | assert(0); |
---|
48 | } |
---|
49 | END_TRY |
---|
50 | printf( "after try\n" ); |
---|
51 | printf( "test finished.\n" ); |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | void test_1(void) |
---|
56 | { |
---|
57 | |
---|
58 | int volatile in_else = 0; |
---|
59 | int volatile in_finally = 0; |
---|
60 | TRY |
---|
61 | { printf( "try\n" ); } |
---|
62 | EXCEPT_DEFAULT |
---|
63 | { printf( "except\n" ); assert(0); } |
---|
64 | ELSE |
---|
65 | { printf( "else\n" ); in_else = 1; } |
---|
66 | FINALLY |
---|
67 | { printf( "finally\n" ); in_finally = 1; } |
---|
68 | END_TRY |
---|
69 | |
---|
70 | assert(in_else); |
---|
71 | assert(in_finally); |
---|
72 | printf( "test finished.\n" ); |
---|
73 | } |
---|
74 | |
---|
75 | |
---|
76 | void test_2(void) |
---|
77 | { |
---|
78 | int volatile in_except = 0; |
---|
79 | int volatile in_finally = 0; |
---|
80 | TRY |
---|
81 | { |
---|
82 | printf( "try\n" ); |
---|
83 | raise_ex( FSD_ERRNO_INVALID_VALUE ); |
---|
84 | assert(0); |
---|
85 | } |
---|
86 | EXCEPT_DEFAULT |
---|
87 | { |
---|
88 | printf( "except: %s\n", fsd_exc_get()->_message ); |
---|
89 | in_except = 1; |
---|
90 | } |
---|
91 | FINALLY |
---|
92 | { |
---|
93 | printf( "finally\n" ); |
---|
94 | in_finally = 1; |
---|
95 | } |
---|
96 | END_TRY |
---|
97 | |
---|
98 | assert(in_except); |
---|
99 | assert(in_finally); |
---|
100 | printf("test finished\n"); |
---|
101 | } |
---|
102 | |
---|
103 | |
---|
104 | void test_3(void) |
---|
105 | { |
---|
106 | int volatile blocks_counter = 0; |
---|
107 | TRY |
---|
108 | { |
---|
109 | TRY |
---|
110 | { |
---|
111 | blocks_counter++; |
---|
112 | printf( "inner try\n" ); |
---|
113 | raise_ex( FSD_ERRNO_INVALID_VALUE ); |
---|
114 | assert(0); |
---|
115 | } |
---|
116 | FINALLY |
---|
117 | { |
---|
118 | blocks_counter++; |
---|
119 | printf( "inner finally\n" ); |
---|
120 | } |
---|
121 | END_TRY |
---|
122 | printf( "after\n" ); |
---|
123 | assert(0); |
---|
124 | } |
---|
125 | EXCEPT_DEFAULT |
---|
126 | { |
---|
127 | blocks_counter++; |
---|
128 | printf( "except: %s\n", fsd_exc_get()->_message ); |
---|
129 | fsd_exc_reraise(); |
---|
130 | } |
---|
131 | ELSE |
---|
132 | { printf( "else\n" ); assert(0); } |
---|
133 | FINALLY |
---|
134 | { |
---|
135 | printf( "finally\n" ); |
---|
136 | blocks_counter++; |
---|
137 | assert(blocks_counter == 4); |
---|
138 | } |
---|
139 | END_TRY |
---|
140 | |
---|
141 | assert(0); |
---|
142 | } |
---|
143 | |
---|
144 | |
---|
145 | void test_4(void) |
---|
146 | { |
---|
147 | TRY |
---|
148 | { |
---|
149 | raise_ex( FSD_ERRNO_INVALID_VALUE ); |
---|
150 | assert(0); |
---|
151 | } |
---|
152 | EXCEPT( FSD_ERRNO_INVALID_VALUE ) |
---|
153 | { printf( "except: %s\n", fsd_exc_get()->_message ); } |
---|
154 | EXCEPT_DEFAULT |
---|
155 | { printf( "except_default: %s\n", fsd_exc_get()->_message ); assert(0); } |
---|
156 | FINALLY |
---|
157 | { |
---|
158 | printf( "finally\n" ); |
---|
159 | raise_ex( FSD_ERRNO_INTERNAL_ERROR ); |
---|
160 | } |
---|
161 | END_TRY |
---|
162 | |
---|
163 | assert(0); |
---|
164 | } |
---|
165 | |
---|
166 | |
---|
167 | int |
---|
168 | main( int argc, char *argv[] ) |
---|
169 | { |
---|
170 | printf("Running Test 0\n"); |
---|
171 | test_0(); |
---|
172 | printf("Running Test 1\n"); |
---|
173 | test_1(); |
---|
174 | printf("Running Test 2\n"); |
---|
175 | test_2(); |
---|
176 | printf("Running Test 3\n"); |
---|
177 | runner( test_3 ); |
---|
178 | printf("Running Test 4\n"); |
---|
179 | runner( test_4 ); |
---|
180 | printf("All tests done.\n"); |
---|
181 | |
---|
182 | return 0; |
---|
183 | } |
---|
184 | |
---|