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 RawReceivePort. | 5 // Test RawReceivePort. |
6 | 6 |
7 library raw_port_test; | 7 library raw_port_test; |
| 8 |
8 import 'dart:isolate'; | 9 import 'dart:isolate'; |
9 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
10 import 'remote_unittest_helper.dart'; | 11 import 'remote_unittest_helper.dart'; |
11 | 12 |
12 | |
13 void remote(SendPort port) { | 13 void remote(SendPort port) { |
14 port.send("reply"); | 14 port.send("reply"); |
15 } | 15 } |
16 | 16 |
17 void remote2(SendPort port) { | 17 void remote2(SendPort port) { |
18 port.send("reply 1"); | 18 port.send("reply 1"); |
19 port.send("reply 2"); | 19 port.send("reply 2"); |
20 } | 20 } |
21 | 21 |
22 main([args, port]) { | 22 main([args, port]) { |
(...skipping 28 matching lines...) Expand all Loading... |
51 | 51 |
52 test("from-raw-port", () { | 52 test("from-raw-port", () { |
53 RawReceivePort rawPort = new RawReceivePort(); | 53 RawReceivePort rawPort = new RawReceivePort(); |
54 Isolate.spawn(remote, rawPort.sendPort); | 54 Isolate.spawn(remote, rawPort.sendPort); |
55 rawPort.handler = expectAsync((v) { | 55 rawPort.handler = expectAsync((v) { |
56 expect(v, "reply"); | 56 expect(v, "reply"); |
57 ReceivePort port = new ReceivePort.fromRawReceivePort(rawPort); | 57 ReceivePort port = new ReceivePort.fromRawReceivePort(rawPort); |
58 Isolate.spawn(remote, rawPort.sendPort); | 58 Isolate.spawn(remote, rawPort.sendPort); |
59 Isolate.spawn(remote, port.sendPort); | 59 Isolate.spawn(remote, port.sendPort); |
60 int ctr = 2; | 60 int ctr = 2; |
61 port.listen(expectAsync((v) { | 61 port.listen( |
62 expect(v, "reply"); | 62 expectAsync((v) { |
63 ctr--; | 63 expect(v, "reply"); |
64 if (ctr == 0) port.close(); | 64 ctr--; |
65 }, count: 2), | 65 if (ctr == 0) port.close(); |
66 onDone: expectAsync((){})); | 66 }, count: 2), |
| 67 onDone: expectAsync(() {})); |
67 }); | 68 }); |
68 }); | 69 }); |
69 } | 70 } |
OLD | NEW |