OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 setting/getting/initializing static fields. | 4 // Dart test program for testing setting/getting/initializing static fields. |
5 | 5 |
6 class First { | 6 class First { |
7 First() {} | 7 First() {} |
8 static var a; | 8 static var a; |
9 static var b; | 9 static var b; |
10 static final int c = 1; | 10 static final int c = 1; |
11 static setValues() { | 11 static setValues() { |
12 a = 24; | 12 a = 24; |
13 b = 10; | 13 b = 10; |
14 return a + b + c; | 14 return a + b + c; |
15 } | 15 } |
16 } | 16 } |
17 | 17 |
18 class Second extends First { | |
19 static void testUnqualifiedStatic() { | |
20 setValues(); // static function in superclass. | |
21 Expect.equals(24, a); // static field in superclass. | |
22 Expect.equals(24, First.a); // same field as above. | |
23 } | |
24 } | |
25 | 18 |
26 class InitializerTest { | 19 class InitializerTest { |
27 static var one; | 20 static var one; |
28 static var two = 2; | 21 static var two = 2; |
29 static var three = 2; | 22 static var three = 2; |
30 | 23 |
31 static checkValueOfThree() { | 24 static checkValueOfThree() { |
32 // We need to keep this check separate to prevent three from | 25 // We need to keep this check separate to prevent three from |
33 // getting initialized before the += is executed. | 26 // getting initialized before the += is executed. |
34 Expect.equals(3, three); | 27 Expect.equals(3, three); |
(...skipping 23 matching lines...) Expand all Loading... |
58 Expect.equals(First.a, First.b); | 51 Expect.equals(First.a, First.b); |
59 First.b = (First.a = 10); | 52 First.b = (First.a = 10); |
60 Expect.equals(10, First.a); | 53 Expect.equals(10, First.a); |
61 Expect.equals(10, First.b); | 54 Expect.equals(10, First.b); |
62 First.b = First.a = 15; | 55 First.b = First.a = 15; |
63 Expect.equals(15, First.a); | 56 Expect.equals(15, First.a); |
64 Expect.equals(15, First.b); | 57 Expect.equals(15, First.b); |
65 Expect.equals(35, First.setValues()); | 58 Expect.equals(35, First.setValues()); |
66 Expect.equals(24, First.a); | 59 Expect.equals(24, First.a); |
67 Expect.equals(10, First.b); | 60 Expect.equals(10, First.b); |
68 Second.testUnqualifiedStatic(); | |
69 } | 61 } |
70 } | 62 } |
71 | 63 |
72 | 64 |
73 main() { | 65 main() { |
74 StaticFieldTest.testMain(); | 66 StaticFieldTest.testMain(); |
75 InitializerTest.testStaticFieldInitialization(); | 67 InitializerTest.testStaticFieldInitialization(); |
76 } | 68 } |
OLD | NEW |