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