OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 // Dart test program for testing properties of ports. | |
6 | |
7 class PortTest { | |
8 | |
9 static void testMain() { | |
10 testHashCode(); | |
11 testEquals(); | |
12 testMap(); | |
13 } | |
14 | |
15 static void testHashCode() { | |
16 ReceivePort rp0 = new ReceivePort(); | |
17 ReceivePort rp1 = new ReceivePort(); | |
18 Expect.equals(rp0.toSendPort().hashCode(), rp0.toSendPort().hashCode()); | |
19 Expect.equals(rp1.toSendPort().hashCode(), rp1.toSendPort().hashCode()); | |
20 rp0.close(); | |
21 rp1.close(); | |
22 } | |
23 | |
24 static void testEquals() { | |
25 ReceivePort rp0 = new ReceivePort(); | |
26 ReceivePort rp1 = new ReceivePort(); | |
27 Expect.equals(rp0.toSendPort(), rp0.toSendPort()); | |
28 Expect.equals(rp1.toSendPort(), rp1.toSendPort()); | |
29 Expect.equals(false, (rp0.toSendPort() == rp1.toSendPort())); | |
30 rp0.close(); | |
31 rp1.close(); | |
32 } | |
33 | |
34 static void testMap() { | |
35 ReceivePort rp0 = new ReceivePort(); | |
36 ReceivePort rp1 = new ReceivePort(); | |
37 final map = new Map<SendPort, int>(); | |
38 map[rp0.toSendPort()] = 42; | |
39 map[rp1.toSendPort()] = 87; | |
40 Expect.equals(42, map[rp0.toSendPort()]); | |
41 Expect.equals(87, map[rp1.toSendPort()]); | |
42 | |
43 map[rp0.toSendPort()] = 99; | |
44 Expect.equals(99, map[rp0.toSendPort()]); | |
45 Expect.equals(87, map[rp1.toSendPort()]); | |
46 | |
47 map.remove(rp0.toSendPort()); | |
48 Expect.equals(false, map.containsKey(rp0.toSendPort())); | |
49 Expect.equals(87, map[rp1.toSendPort()]); | |
50 | |
51 map.remove(rp1.toSendPort()); | |
52 Expect.equals(false, map.containsKey(rp0.toSendPort())); | |
53 Expect.equals(false, map.containsKey(rp1.toSendPort())); | |
54 | |
55 rp0.close(); | |
56 rp1.close(); | |
57 } | |
58 | |
59 } | |
60 | |
61 main() { | |
62 PortTest.testMain(); | |
63 } | |
OLD | NEW |