Add automated tests on function-type FSCommand parameter passing.
[gnash.git] / testsuite / misc-mtasc.all / exception.as
blobb21847c4eb22fe0ac1756bd9076b38dc90360faf
1 // exception.as - MTASC testcase for try/catch
2 //
3 // Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software
4 // Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 // Original author: Asger Ottar Alstrup <asger@area9.dk>
24 #include "check.as"
26 // This movie tests exceptions
28 class Test
31 // constructor
32 function Test()
34 note("Test constructor called");
37 function addOneOnFinal(o)
39 try {
40 return 'try';
42 finally {
43 o.num += 1;
44 return 'finally';
48 function throwAndCatchAddingOne(o)
50 try {
51 throw 'catch';
52 return 'try';
54 catch (e) {
55 return e;
57 finally {
58 o.num += 1;
62 function throwFromCatchAddingOne(o)
64 try {
65 throw 'catch';
66 return 'try';
68 catch (e) {
69 o.num += 1;
70 note("Catch inside, throwing again (not expected to survive after finally)!");
71 throw e; // double throw not supported ?
72 return 'catch';
74 finally {
75 return 'finally';
79 function throwNested(o)
81 try {
82 throw 'throw';
83 } catch (e) {
84 note("Catch inside, throwing again!");
85 throw e;
89 function returnInTryAndCatch(o)
91 try {
92 return 'try';
93 note ("After return in try");
94 o.num += 1;
96 catch (e) {
97 note ("Catch after return in try");
98 o.num += 1;
99 return 'catch';
103 function returnInTryCatchAndFinally(o)
105 try {
106 return 'try';
107 note ("After return in try");
108 o.num += 1;
110 catch (e) {
111 note ("Catch after return in try");
112 o.num += 1;
113 return 'catch';
115 finally {
116 note ("Finally after returns in try and catch");
117 o.num += 1;
118 return 'finally';
122 function tryCatchAndFinally(o)
124 try {
125 o.sequence += "try";
126 o.num += 1;
128 catch (e) {
129 o.sequence += "catch";
130 o.num += 1;
132 finally {
133 o.sequence += "finally";
134 o.num += 1;
138 function returnInCatchAndFinally(o)
140 try {
141 throw 'try'
142 note ("After throw in try");
143 o.num += 1;
145 catch (e) {
146 note ("Catch after throw in try");
147 return 'catch';
148 o.num += 1;
150 finally {
151 note ("Finally after returns in catch");
152 o.num += 1;
153 return 'finally';
158 function test_all()
160 var res = 'string';
161 try {
162 throw(1);
163 res = 0;
164 } catch (e) {
165 res = e;
167 check_equals(typeof(res), 'number');
168 check_equals(res, 1);
170 res = 'string';
171 try {
172 throw('thrown');
173 res = 0;
174 } catch(e) {
175 res = e;
177 finally {
178 res += '_finally';
180 check_equals(typeof(res), 'string');
181 check_equals(res, 'thrown_finally');
183 res = 'string';
184 try {
185 res = 0;
186 } catch(e) {
187 res = e;
189 finally {
190 res = 3;
192 check_equals(typeof(res), 'number');
193 check_equals(res, 3);
195 var o = new Object();
196 o.num = 1;
197 var ret = addOneOnFinal(o);
198 check_equals(ret, 'finally');
199 check_equals(o.num, 2);
201 ret = throwAndCatchAddingOne(o);
202 check_equals(ret, 'catch');
203 check_equals(o.num, 3);
205 try {
206 ret = throwAndCatchAddingOne(o);
207 } catch (e) {
208 ret = 'catch_outside';
210 check_equals(ret, 'catch');
211 check_equals(o.num, 4);
213 try {
214 ret = throwFromCatchAddingOne(o);
215 } catch (e) {
216 note("Catch outside");
217 o.num += 1;
218 ret += e+'_outside';
220 check_equals(ret, 'finally');
221 check_equals(o.num, 5);
224 try {
225 ret = returnInTryAndCatch(o);
227 check_equals(ret, "try");
228 check_equals(o.num, 5);
230 ret = returnInTryCatchAndFinally(o);
231 check_equals(ret, "finally");
232 check_equals(o.num, 6);
234 o.sequence = "";
235 tryCatchAndFinally(o);
236 check_equals(o.sequence, "tryfinally");
237 check_equals(o.num, 8);
239 ret = returnInCatchAndFinally(o);
240 check_equals(o.num, 9);
241 check_equals(ret, "finally");
243 try {
244 throwNested();
245 } catch (e) {
246 note("Catch outside");
247 o.num = e;
249 check_equals(o.num, 'throw');
252 static function main(mc)
255 var myTest = new Test;
256 myTest.test_all();
258 check_totals(23);
259 Dejagnu.done();