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