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 #import("dart:isolate"); | 6 #import("dart:isolate"); |
7 #import("TestFramework.dart"); | 7 #import("TestFramework.dart"); |
8 | 8 |
9 class TestIsolate extends Isolate { | 9 class TestIsolate extends Isolate { |
10 | 10 |
11 TestIsolate() : super(); | 11 TestIsolate() : super(); |
12 | 12 |
13 void main() { | 13 void main() { |
14 this.port.receive((message, SendPort replyTo) { | 14 this.port.receive((message, SendPort replyTo) { |
15 replyTo.send(message + 87); | 15 replyTo.send(message + 87); |
16 this.port.close(); | 16 this.port.close(); |
17 }); | 17 }); |
18 } | 18 } |
19 | 19 |
20 } | 20 } |
21 | 21 |
22 void testCall(TestExpectation expect) { | 22 void testCall(TestExpectation expect) { |
23 expect.completes(new TestIsolate().spawn()).then((SendPort port) { | 23 expect.completes(new TestIsolate().spawn()).then((SendPort port) { |
24 port.call(42).receive(expect.runs2((message, replyTo) { | 24 port.call(42).then(expect.runs1((message) { |
25 Expect.equals(42 + 87, message); | 25 Expect.equals(42 + 87, message); |
26 expect.succeeded(); | 26 expect.succeeded(); |
27 })); | 27 })); |
28 }); | 28 }); |
29 } | 29 } |
30 | 30 |
31 void testSend(TestExpectation expect) { | 31 void testSend(TestExpectation expect) { |
32 expect.completes(new TestIsolate().spawn()).then((SendPort port) { | 32 expect.completes(new TestIsolate().spawn()).then((SendPort port) { |
33 ReceivePort reply = new ReceivePort(); | 33 ReceivePort reply = new ReceivePort(); |
34 port.send(99, reply.toSendPort()); | 34 port.send(99, reply.toSendPort()); |
35 reply.receive(expect.runs2((message, replyTo) { | 35 reply.receive(expect.runs2((message, replyTo) { |
36 Expect.equals(99 + 87, message); | 36 Expect.equals(99 + 87, message); |
37 reply.close(); | 37 reply.close(); |
38 expect.succeeded(); | 38 expect.succeeded(); |
39 })); | 39 })); |
40 }); | 40 }); |
41 } | 41 } |
42 | 42 |
43 void testSendSingleShot(TestExpectation expect) { | |
44 expect.completes(new TestIsolate().spawn()).then((SendPort port) { | |
45 ReceivePort reply = new ReceivePort.singleShot(); | |
46 port.send(99, replyTo: reply.toSendPort()); | |
47 reply.receive(expect.runs2((message, replyTo) { | |
48 Expect.equals(99 + 87, message); | |
49 expect.succeeded(); | |
50 })); | |
51 }); | |
52 } | |
53 | |
54 void main() { | 43 void main() { |
55 runTests([testCall, testSend, testSendSingleShot]); | 44 runTests([testCall, testSend]); |
56 } | 45 } |
OLD | NEW |