OLD | NEW |
1 // Copyright (c) 2012, 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 | 4 |
5 // Test properties of ports. | 5 // Test properties of ports. |
6 // Note: unittest.dart depends on ports, in particular on the behaviour tested | 6 // Note: unittest.dart depends on ports, in particular on the behaviour tested |
7 // here. To keep things simple, we don't use the unittest library here. | 7 // here. To keep things simple, we don't use the unittest library here. |
8 | 8 |
9 library PortTest; | 9 library PortTest; |
10 import "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
11 import 'dart:isolate'; | 11 import 'dart:isolate'; |
12 import '../../pkg/unittest/lib/matcher.dart'; | 12 import '../../pkg/unittest/lib/matcher.dart'; |
13 | 13 |
14 main() { | 14 main() { |
15 testHashCode(); | 15 testHashCode(); |
16 testEquals(); | 16 testEquals(); |
17 testMap(); | 17 testMap(); |
18 } | 18 } |
19 | 19 |
20 void testHashCode() { | 20 void testHashCode() { |
21 ReceivePort rp0 = new ReceivePort(); | 21 ReceivePort rp0 = new ReceivePort(); |
22 ReceivePort rp1 = new ReceivePort(); | 22 ReceivePort rp1 = new ReceivePort(); |
23 Expect.equals(rp0.toSendPort().hashCode, rp0.toSendPort().hashCode); | 23 Expect.equals(rp0.sendPort.hashCode, rp0.sendPort.hashCode); |
24 Expect.equals(rp1.toSendPort().hashCode, rp1.toSendPort().hashCode); | 24 Expect.equals(rp1.sendPort.hashCode, rp1.sendPort.hashCode); |
25 rp0.close(); | 25 rp0.close(); |
26 rp1.close(); | 26 rp1.close(); |
27 } | 27 } |
28 | 28 |
29 void testEquals() { | 29 void testEquals() { |
30 ReceivePort rp0 = new ReceivePort(); | 30 ReceivePort rp0 = new ReceivePort(); |
31 ReceivePort rp1 = new ReceivePort(); | 31 ReceivePort rp1 = new ReceivePort(); |
32 Expect.equals(rp0.toSendPort(), rp0.toSendPort()); | 32 Expect.equals(rp0.sendPort, rp0.sendPort); |
33 Expect.equals(rp1.toSendPort(), rp1.toSendPort()); | 33 Expect.equals(rp1.sendPort, rp1.sendPort); |
34 Expect.isFalse(rp0.toSendPort() == rp1.toSendPort()); | 34 Expect.isFalse(rp0.sendPort == rp1.sendPort); |
35 rp0.close(); | 35 rp0.close(); |
36 rp1.close(); | 36 rp1.close(); |
37 } | 37 } |
38 | 38 |
39 void testMap() { | 39 void testMap() { |
40 ReceivePort rp0 = new ReceivePort(); | 40 ReceivePort rp0 = new ReceivePort(); |
41 ReceivePort rp1 = new ReceivePort(); | 41 ReceivePort rp1 = new ReceivePort(); |
42 final map = new Map<SendPort, int>(); | 42 final map = new Map<SendPort, int>(); |
43 map[rp0.toSendPort()] = 42; | 43 map[rp0.sendPort] = 42; |
44 map[rp1.toSendPort()] = 87; | 44 map[rp1.sendPort] = 87; |
45 Expect.equals(map[rp0.toSendPort()], 42); | 45 Expect.equals(map[rp0.sendPort], 42); |
46 Expect.equals(map[rp1.toSendPort()], 87); | 46 Expect.equals(map[rp1.sendPort], 87); |
47 | 47 |
48 map[rp0.toSendPort()] = 99; | 48 map[rp0.sendPort] = 99; |
49 Expect.equals(map[rp0.toSendPort()], 99); | 49 Expect.equals(map[rp0.sendPort], 99); |
50 Expect.equals(map[rp1.toSendPort()], 87); | 50 Expect.equals(map[rp1.sendPort], 87); |
51 | 51 |
52 map.remove(rp0.toSendPort()); | 52 map.remove(rp0.sendPort); |
53 Expect.isFalse(map.containsKey(rp0.toSendPort())); | 53 Expect.isFalse(map.containsKey(rp0.sendPort)); |
54 Expect.equals(map[rp1.toSendPort()], 87); | 54 Expect.equals(map[rp1.sendPort], 87); |
55 | 55 |
56 map.remove(rp1.toSendPort()); | 56 map.remove(rp1.sendPort); |
57 Expect.isFalse(map.containsKey(rp0.toSendPort())); | 57 Expect.isFalse(map.containsKey(rp0.sendPort)); |
58 Expect.isFalse(map.containsKey(rp1.toSendPort())); | 58 Expect.isFalse(map.containsKey(rp1.sendPort)); |
59 | 59 |
60 rp0.close(); | 60 rp0.close(); |
61 rp1.close(); | 61 rp1.close(); |
62 } | 62 } |
OLD | NEW |