OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // Dart test program for testing execution of finally blocks on | 4 // Dart test program for testing execution of finally blocks on |
5 // control flow breaks because of 'return', 'continue' etc. | 5 // control flow breaks because of 'return', 'continue' etc. |
6 | 6 |
7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
8 | 8 |
9 | |
10 class Helper { | 9 class Helper { |
11 Helper() : i = 0 { } | 10 Helper() : i = 0 {} |
12 | 11 |
13 int f1(int param) { | 12 int f1(int param) { |
14 if (param == 0) { | 13 if (param == 0) { |
15 try { | 14 try { |
16 int j; | 15 int j; |
17 j = func(); | 16 j = func(); |
18 try { | 17 try { |
19 i = 1; | 18 i = 1; |
20 return i; // Value of i is 1 on return. | 19 return i; // Value of i is 1 on return. |
21 } finally { | 20 } finally { |
22 i = i + 400; // Should get executed when we return. | 21 i = i + 400; // Should get executed when we return. |
23 } | 22 } |
24 i = 2; // Should not get executed. | 23 i = 2; // Should not get executed. |
25 return i; | 24 return i; |
26 } finally { | 25 } finally { |
27 i = i + 800; // Should get executed when we return. | 26 i = i + 800; // Should get executed when we return. |
28 } | 27 } |
29 return i + 200; // Should not get executed. | 28 return i + 200; // Should not get executed. |
30 } | 29 } |
31 try { | 30 try { |
32 int j; | 31 int j; |
33 j = func(); | 32 j = func(); |
34 try { | 33 try { |
35 i = 4; | 34 i = 4; |
36 return i; // Value of i is 1 on return. | 35 return i; // Value of i is 1 on return. |
37 } finally { | 36 } finally { |
38 i = i + 100; // Should get executed when we return. | 37 i = i + 100; // Should get executed when we return. |
39 } | 38 } |
40 i = 2; // Should not get executed. | 39 i = 2; // Should not get executed. |
41 return i; | 40 return i; |
42 } finally { | 41 } finally { |
43 i = i + 200; // Should get executed when we return. | 42 i = i + 200; // Should get executed when we return. |
44 } | 43 } |
45 return i + 200; // Should not get executed. | 44 return i + 200; // Should not get executed. |
46 } | 45 } |
47 | 46 |
48 static int func() { | 47 static int func() { |
49 int i = 0; | 48 int i = 0; |
50 while (i < 10) { | 49 while (i < 10) { |
51 i++; | 50 i++; |
52 } | 51 } |
53 return i; | 52 return i; |
54 } | 53 } |
55 | 54 |
56 int i; | 55 int i; |
57 } | 56 } |
58 | 57 |
59 class ExecuteFinally5Test { | 58 class ExecuteFinally5Test { |
60 static testMain() { | 59 static testMain() { |
61 Helper obj = new Helper(); | 60 Helper obj = new Helper(); |
62 Expect.equals(1, obj.f1(0)); | 61 Expect.equals(1, obj.f1(0)); |
63 Expect.equals(1201, obj.i); | 62 Expect.equals(1201, obj.i); |
64 Expect.equals(4, obj.f1(1)); | 63 Expect.equals(4, obj.f1(1)); |
65 Expect.equals(304, obj.i); | 64 Expect.equals(304, obj.i); |
66 } | 65 } |
67 } | 66 } |
68 | 67 |
69 main() { | 68 main() { |
70 ExecuteFinally5Test.testMain(); | 69 ExecuteFinally5Test.testMain(); |
71 } | 70 } |
OLD | NEW |