| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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 #library("RequestReplyTest"); | 5 #library("RequestReplyTest"); |
| 6 | |
| 7 #import("dart:isolate"); | 6 #import("dart:isolate"); |
| 8 #import('../../../lib/unittest/unittest.dart'); | 7 #import("TestFramework.dart"); |
| 9 | 8 |
| 10 class TestIsolate extends Isolate { | 9 class TestIsolate extends Isolate { |
| 11 | 10 |
| 12 TestIsolate() : super(); | 11 TestIsolate() : super(); |
| 13 | 12 |
| 14 void main() { | 13 void main() { |
| 15 this.port.receive((message, SendPort replyTo) { | 14 this.port.receive((message, SendPort replyTo) { |
| 16 replyTo.send(message + 87); | 15 replyTo.send(message + 87); |
| 17 this.port.close(); | 16 this.port.close(); |
| 18 }); | 17 }); |
| 19 } | 18 } |
| 20 | 19 |
| 21 } | 20 } |
| 22 | 21 |
| 23 void main() { | 22 void testCall(TestExpectation expect) { |
| 24 test("call", () { | 23 expect.completes(new TestIsolate().spawn()).then((SendPort port) { |
| 25 new TestIsolate().spawn().then(expectAsync1((SendPort port) { | 24 port.call(42).then(expect.runs1((message) { |
| 26 port.call(42).then(expectAsync1((message) { | 25 Expect.equals(42 + 87, message); |
| 27 Expect.equals(42 + 87, message); | 26 expect.succeeded(); |
| 28 })); | |
| 29 })); | |
| 30 }); | |
| 31 | |
| 32 test("send", () { | |
| 33 new TestIsolate().spawn().then(expectAsync1((SendPort port) { | |
| 34 ReceivePort reply = new ReceivePort(); | |
| 35 port.send(99, reply.toSendPort()); | |
| 36 reply.receive(expectAsync2((message, replyTo) { | |
| 37 Expect.equals(99 + 87, message); | |
| 38 reply.close(); | |
| 39 })); | |
| 40 })); | 27 })); |
| 41 }); | 28 }); |
| 42 } | 29 } |
| 30 |
| 31 void testSend(TestExpectation expect) { |
| 32 expect.completes(new TestIsolate().spawn()).then((SendPort port) { |
| 33 ReceivePort reply = new ReceivePort(); |
| 34 port.send(99, reply.toSendPort()); |
| 35 reply.receive(expect.runs2((message, replyTo) { |
| 36 Expect.equals(99 + 87, message); |
| 37 reply.close(); |
| 38 expect.succeeded(); |
| 39 })); |
| 40 }); |
| 41 } |
| 42 |
| 43 void main() { |
| 44 runTests([testCall, testSend]); |
| 45 } |
| OLD | NEW |