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 setting/getting of fields when | 4 // Dart test program for testing setting/getting of fields when |
5 // only getter/setter methods are specified. | 5 // only getter/setter methods are specified. |
6 | 6 |
7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
8 | 8 |
9 class First { | 9 class First { |
10 First(int val) : a_ = val { } | 10 First(int val) : a_ = val {} |
11 int a_; | 11 int a_; |
12 } | 12 } |
13 | 13 |
14 class Second extends First { | 14 class Second extends First { |
15 static int c; | 15 static int c; |
16 | 16 |
17 Second(int val) : super(val) { } | 17 Second(int val) : super(val) {} |
18 | 18 |
19 static void testStaticMethod() { | 19 static void testStaticMethod() { |
20 int i; | 20 int i; |
21 Second.static_a = 20; | 21 Second.static_a = 20; |
22 i = Second.c; | 22 i = Second.c; |
23 } | 23 } |
24 | 24 |
25 void set instance_a(int value) { | 25 void set instance_a(int value) { |
26 a_ = a_ + value; | 26 a_ = a_ + value; |
27 } | 27 } |
| 28 |
28 int get instance_a { | 29 int get instance_a { |
29 return a_; | 30 return a_; |
30 } | 31 } |
31 | 32 |
32 static void set static_a(int value) { | 33 static void set static_a(int value) { |
33 Second.c = value; | 34 Second.c = value; |
34 } | 35 } |
35 | 36 |
36 static int get static_d { | 37 static int get static_d { |
37 return Second.c; | 38 return Second.c; |
38 } | 39 } |
39 } | 40 } |
40 | 41 |
41 class Setter0Test { | 42 class Setter0Test { |
42 static testMain() { | 43 static testMain() { |
43 Second obj = new Second(10); | 44 Second obj = new Second(10); |
44 Expect.equals(10, obj.instance_a); | 45 Expect.equals(10, obj.instance_a); |
45 obj.instance_a = 20; | 46 obj.instance_a = 20; |
46 Expect.equals(30, obj.instance_a); | 47 Expect.equals(30, obj.instance_a); |
47 | 48 |
48 Second.testStaticMethod(); | 49 Second.testStaticMethod(); |
49 Expect.equals(20, Second.c); | 50 Expect.equals(20, Second.c); |
50 Expect.equals(20, Second.static_d); | 51 Expect.equals(20, Second.static_d); |
51 } | 52 } |
52 } | 53 } |
53 | 54 |
54 | |
55 main() { | 55 main() { |
56 Setter0Test.testMain(); | 56 Setter0Test.testMain(); |
57 } | 57 } |
OLD | NEW |