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 library illegal_msg_function_test; | 5 library illegal_msg_function_test; |
6 | 6 |
7 import "package:expect/expect.dart"; | |
8 import "dart:isolate"; | 7 import "dart:isolate"; |
9 import "dart:async" show Future; | 8 import "dart:async" show Future; |
10 import "package:async_helper/async_helper.dart"; | 9 import "package:unittest/unittest.dart"; |
| 10 import "remote_unittest_helper.dart"; |
11 | 11 |
12 funcFoo(x) => x + 2; | 12 funcFoo(x) => x + 2; |
13 | 13 |
14 echo(sendPort) { | 14 echo(sendPort) { |
15 var port = new ReceivePort(); | 15 var port = new ReceivePort(); |
16 sendPort.send(port.sendPort); | 16 sendPort.send(port.sendPort); |
17 port.listen((msg) { | 17 port.listen((msg) { |
18 sendPort.send("echoing ${msg(1)}}"); | 18 sendPort.send("echoing ${msg(1)}}"); |
19 }); | 19 }); |
20 } | 20 } |
21 | 21 |
22 main() { | 22 void main([args, port]) { |
23 var function = funcFoo; | 23 if (testRemote(main, port)) return; |
| 24 test("msg_function", () { |
| 25 var function = funcFoo; |
| 26 ReceivePort port = new ReceivePort(); |
| 27 Future spawn = Isolate.spawn(echo, port.sendPort); |
| 28 var caught_exception = false; |
| 29 var stream = port.asBroadcastStream(); |
| 30 stream.first.then(expectAsync1((snd) { |
| 31 try { |
| 32 snd.send(function); |
| 33 } catch (e) { |
| 34 caught_exception = true; |
| 35 } |
24 | 36 |
25 ReceivePort port = new ReceivePort(); | 37 if (caught_exception) { |
26 Future spawn = Isolate.spawn(echo, port.sendPort); | 38 port.close(); |
27 var caught_exception = false; | 39 } else { |
28 var stream = port.asBroadcastStream(); | 40 stream.first.then(expectAsync1((msg) { |
29 asyncStart(); | 41 print("from worker ${msg}"); |
30 stream.first.then((snd) { | 42 })); |
31 try { | 43 } |
32 snd.send(function); | 44 expect(caught_exception, isTrue); |
33 } catch (e) { | 45 })); |
34 caught_exception = true; | |
35 } | |
36 | |
37 if (caught_exception) { | |
38 port.close(); | |
39 } else { | |
40 asyncStart(); | |
41 stream.first.then((msg) { | |
42 print("from worker ${msg}"); | |
43 asyncEnd(); | |
44 }); | |
45 } | |
46 Expect.isTrue(caught_exception); | |
47 asyncEnd(); | |
48 }); | 46 }); |
49 } | 47 } |
OLD | NEW |