OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
ngeoffray
2013/11/19 07:43:41
2012 -> 2013
| |
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 RawReceivePort. | |
6 | |
7 library raw_port_test; | |
floitsch
2013/11/18 10:48:31
Test doesn't work in Dartium (because of spawn). M
Lasse Reichstein Nielsen
2013/11/18 15:45:36
Done.
| |
8 import 'dart:isolate'; | |
9 import 'dart:async'; | |
10 import '../../pkg/unittest/lib/unittest.dart'; | |
11 | |
12 | |
13 void remote(SendPort port) { port.send("reply"); } | |
14 void remote2(SendPort port) { | |
15 port.send("reply 1"); | |
16 port.send("reply 2"); | |
17 } | |
18 | |
19 main() { | |
20 test("raw receive", () { | |
21 RawReceivePort port = new RawReceivePort(); | |
22 Isolate.spawn(remote, port.sendPort); | |
23 port.handler = expectAsync1((v) { | |
24 expect(v, "reply"); | |
25 port.close(); | |
26 }); | |
27 }); | |
28 test("raw receive twice - change handler", () { | |
29 RawReceivePort port = new RawReceivePort(); | |
30 Isolate.spawn(remote2, port.sendPort); | |
31 port.handler = expectAsync1((v) { | |
32 expect(v, "reply 1"); | |
33 port.handler = expectAsync1((v) { | |
34 expect(v, "reply 2"); | |
35 port.close(); | |
36 }); | |
37 }); | |
38 }); | |
39 test("from-raw-port", () { | |
40 RawReceivePort rawPort = new RawReceivePort(); | |
41 Isolate.spawn(remote, rawPort.sendPort); | |
42 rawPort.handler = expectAsync1((v) { | |
43 expect(v, "reply"); | |
44 ReceivePort port = new ReceivePort.fromRawReceivePort(rawPort); | |
45 Isolate.spawn(remote, rawPort.sendPort); | |
46 Isolate.spawn(remote, port.sendPort); | |
47 int ctr = 2; | |
48 port.listen(expectAsync1((v) { | |
49 expect(v, "reply"); | |
50 ctr--; | |
51 if (ctr == 0) port.close(); | |
52 }, count: 2), | |
53 onDone: expectAsync0((){})); | |
54 }); | |
55 }); | |
56 | |
57 } | |
OLD | NEW |