| 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 // Test properties of ports. | |
| 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. | |
| 8 | |
| 9 #library("PortTest"); | |
| 10 #import("dart:isolate"); | |
| 11 | |
| 12 | |
| 13 main() { | |
| 14 testHashCode(); | |
| 15 testEquals(); | |
| 16 testMap(); | |
| 17 } | |
| 18 | |
| 19 void testHashCode() { | |
| 20 ReceivePort rp0 = new ReceivePort(); | |
| 21 ReceivePort rp1 = new ReceivePort(); | |
| 22 Expect.equals(rp0.toSendPort().hashCode(), rp0.toSendPort().hashCode()); | |
| 23 Expect.equals(rp1.toSendPort().hashCode(), rp1.toSendPort().hashCode()); | |
| 24 rp0.close(); | |
| 25 rp1.close(); | |
| 26 } | |
| 27 | |
| 28 void testEquals() { | |
| 29 ReceivePort rp0 = new ReceivePort(); | |
| 30 ReceivePort rp1 = new ReceivePort(); | |
| 31 Expect.equals(rp0.toSendPort(), rp0.toSendPort()); | |
| 32 Expect.equals(rp1.toSendPort(), rp1.toSendPort()); | |
| 33 Expect.equals(false, (rp0.toSendPort() == rp1.toSendPort())); | |
| 34 rp0.close(); | |
| 35 rp1.close(); | |
| 36 } | |
| 37 | |
| 38 void testMap() { | |
| 39 ReceivePort rp0 = new ReceivePort(); | |
| 40 ReceivePort rp1 = new ReceivePort(); | |
| 41 final map = new Map<SendPort, int>(); | |
| 42 map[rp0.toSendPort()] = 42; | |
| 43 map[rp1.toSendPort()] = 87; | |
| 44 Expect.equals(42, map[rp0.toSendPort()]); | |
| 45 Expect.equals(87, map[rp1.toSendPort()]); | |
| 46 | |
| 47 map[rp0.toSendPort()] = 99; | |
| 48 Expect.equals(99, map[rp0.toSendPort()]); | |
| 49 Expect.equals(87, map[rp1.toSendPort()]); | |
| 50 | |
| 51 map.remove(rp0.toSendPort()); | |
| 52 Expect.equals(false, map.containsKey(rp0.toSendPort())); | |
| 53 Expect.equals(87, map[rp1.toSendPort()]); | |
| 54 | |
| 55 map.remove(rp1.toSendPort()); | |
| 56 Expect.equals(false, map.containsKey(rp0.toSendPort())); | |
| 57 Expect.equals(false, map.containsKey(rp1.toSendPort())); | |
| 58 | |
| 59 rp0.close(); | |
| 60 rp1.close(); | |
| 61 } | |
| OLD | NEW |