OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 import "dart:platform" as platform; | 5 import "dart:platform" as platform; |
6 | 6 |
7 import "dart:isolate"; | 7 import "dart:isolate"; |
8 import "package:unittest/unittest.dart"; | 8 import "package:unittest/unittest.dart"; |
9 | 9 |
10 main() { | 10 sendReceive(SendPort port, msg) { |
11 var sendPort = spawnFunction(f); | 11 var response = new ReceivePort(); |
12 expect(sendPort.call("platform.executable"), completion(platform.executable)); | 12 port.send([msg, response.sendPort]); |
13 if (platform.script != null) { | 13 return response.first; |
14 expect(sendPort.call("platform.script").then((s) => s.path), | |
15 completion(endsWith('tests/lib/platform/isolate_test.dart'))); | |
16 } | |
17 expect(sendPort.call("platform.packageRoot"), | |
18 completion(platform.packageRoot)); | |
19 expect(sendPort.call("platform.executableArguments"), | |
20 completion(platform.executableArguments)); | |
21 } | 14 } |
22 | 15 |
23 void f() { | 16 main() { |
| 17 test("platform in isolate", () { |
| 18 var response = new ReceivePort(); |
| 19 Isolate.spawn(f, response.sendPort); |
| 20 response.first.then(expectAsync1((sendPort) { |
| 21 expect(sendReceive(sendPort, "platform.executable"), |
| 22 completion(platform.executable)); |
| 23 if (platform.script != null) { |
| 24 expect(sendReceive(sendPort, "platform.script").then((s) => s.path), |
| 25 completion(endsWith('tests/lib/platform/isolate_test.dart'))); |
| 26 } |
| 27 expect(sendReceive(sendPort, "platform.packageRoot"), |
| 28 completion(platform.packageRoot)); |
| 29 expect(sendReceive(sendPort, "platform.executableArguments"), |
| 30 completion(platform.executableArguments)); |
| 31 })); |
| 32 }); |
| 33 } |
| 34 |
| 35 void f(initialReplyTo) { |
| 36 var port = new ReceivePort(); |
| 37 initialReplyTo.send(port.sendPort); |
24 int count = 0; | 38 int count = 0; |
25 port.receive((msg, reply) { | 39 port.listen((msg) { |
26 if (msg == "platform.executable") { | 40 var data = msg[0]; |
27 reply.send(platform.executable); | 41 var replyTo = msg[1]; |
| 42 if (data == "platform.executable") { |
| 43 replyTo.send(platform.executable); |
28 } | 44 } |
29 if (msg == "platform.script") { | 45 if (data == "platform.script") { |
30 reply.send(platform.script); | 46 replyTo.send(platform.script); |
31 } | 47 } |
32 if (msg == "platform.packageRoot") { | 48 if (data == "platform.packageRoot") { |
33 reply.send(platform.packageRoot); | 49 replyTo.send(platform.packageRoot); |
34 } | 50 } |
35 if (msg == "platform.executableArguments") { | 51 if (data == "platform.executableArguments") { |
36 reply.send(platform.executableArguments); | 52 replyTo.send(platform.executableArguments); |
37 } | 53 } |
38 count++; | 54 count++; |
39 if (count == 4) { | 55 if (count == 4) { |
40 port.close(); | 56 port.close(); |
41 } | 57 } |
42 }); | 58 }); |
43 } | 59 } |
OLD | NEW |