| 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 |
| 6 #import("dart:isolate"); | 7 #import("dart:isolate"); |
| 7 #import("TestFramework.dart"); | 8 #import('../../../lib/unittest/unittest.dart'); |
| 8 | 9 |
| 9 class TestIsolate extends Isolate { | 10 class TestIsolate extends Isolate { |
| 10 | 11 |
| 11 TestIsolate() : super(); | 12 TestIsolate() : super(); |
| 12 | 13 |
| 13 void main() { | 14 void main() { |
| 14 this.port.receive((message, SendPort replyTo) { | 15 this.port.receive((message, SendPort replyTo) { |
| 15 replyTo.send(message + 87); | 16 replyTo.send(message + 87); |
| 16 this.port.close(); | 17 this.port.close(); |
| 17 }); | 18 }); |
| 18 } | 19 } |
| 19 | 20 |
| 20 } | 21 } |
| 21 | 22 |
| 22 void testCall(TestExpectation expect) { | 23 void main() { |
| 23 expect.completes(new TestIsolate().spawn()).then((SendPort port) { | 24 test("call", () { |
| 24 port.call(42).then(expect.runs1((message) { | 25 new TestIsolate().spawn().then(expectAsync1((SendPort port) { |
| 25 Expect.equals(42 + 87, message); | 26 port.call(42).then(expectAsync1((message) { |
| 26 expect.succeeded(); | 27 Expect.equals(42 + 87, message); |
| 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 })); |
| 27 })); | 40 })); |
| 28 }); | 41 }); |
| 29 } | 42 } |
| 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 |