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 import 'dart:isolate'; | 8 import 'dart:isolate'; |
9 import 'dart:async'; | 9 import 'package:unittest/unittest.dart'; |
10 import '../../pkg/unittest/lib/unittest.dart'; | 10 import 'remote_unittest_helper.dart'; |
11 | 11 |
12 | 12 |
13 void remote(SendPort port) { port.send("reply"); } | 13 void remote(SendPort port) { |
| 14 port.send("reply"); |
| 15 } |
| 16 |
14 void remote2(SendPort port) { | 17 void remote2(SendPort port) { |
15 port.send("reply 1"); | 18 port.send("reply 1"); |
16 port.send("reply 2"); | 19 port.send("reply 2"); |
17 } | 20 } |
18 | 21 |
19 main() { | 22 main([args, port]) { |
| 23 if (testRemote(main, port)) return; |
| 24 |
20 test("raw receive", () { | 25 test("raw receive", () { |
21 RawReceivePort port = new RawReceivePort(); | 26 RawReceivePort port = new RawReceivePort(); |
22 Isolate.spawn(remote, port.sendPort); | 27 Isolate.spawn(remote, port.sendPort); |
23 port.handler = expectAsync1((v) { | 28 port.handler = expectAsync1((v) { |
24 expect(v, "reply"); | 29 expect(v, "reply"); |
25 port.close(); | 30 port.close(); |
26 }); | 31 }); |
27 }); | 32 }); |
| 33 |
28 test("raw receive twice - change handler", () { | 34 test("raw receive twice - change handler", () { |
29 RawReceivePort port = new RawReceivePort(); | 35 RawReceivePort port = new RawReceivePort(); |
30 Isolate.spawn(remote2, port.sendPort); | 36 Isolate.spawn(remote2, port.sendPort); |
31 port.handler = expectAsync1((v) { | 37 port.handler = expectAsync1((v) { |
32 expect(v, "reply 1"); | 38 expect(v, "reply 1"); |
33 port.handler = expectAsync1((v) { | 39 port.handler = expectAsync1((v) { |
34 expect(v, "reply 2"); | 40 expect(v, "reply 2"); |
35 port.close(); | 41 port.close(); |
36 }); | 42 }); |
37 }); | 43 }); |
38 }); | 44 }); |
| 45 |
39 test("from-raw-port", () { | 46 test("from-raw-port", () { |
40 RawReceivePort rawPort = new RawReceivePort(); | 47 RawReceivePort rawPort = new RawReceivePort(); |
41 Isolate.spawn(remote, rawPort.sendPort); | 48 Isolate.spawn(remote, rawPort.sendPort); |
42 rawPort.handler = expectAsync1((v) { | 49 rawPort.handler = expectAsync1((v) { |
43 expect(v, "reply"); | 50 expect(v, "reply"); |
44 ReceivePort port = new ReceivePort.fromRawReceivePort(rawPort); | 51 ReceivePort port = new ReceivePort.fromRawReceivePort(rawPort); |
45 Isolate.spawn(remote, rawPort.sendPort); | 52 Isolate.spawn(remote, rawPort.sendPort); |
46 Isolate.spawn(remote, port.sendPort); | 53 Isolate.spawn(remote, port.sendPort); |
47 int ctr = 2; | 54 int ctr = 2; |
48 port.listen(expectAsync1((v) { | 55 port.listen(expectAsync1((v) { |
49 expect(v, "reply"); | 56 expect(v, "reply"); |
50 ctr--; | 57 ctr--; |
51 if (ctr == 0) port.close(); | 58 if (ctr == 0) port.close(); |
52 }, count: 2), | 59 }, count: 2), |
53 onDone: expectAsync0((){})); | 60 onDone: expectAsync0((){})); |
54 }); | 61 }); |
55 }); | 62 }); |
56 | |
57 } | 63 } |
OLD | NEW |