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