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 // Dart test program for checking implemention of IsolateMirror. | 5 // Dart test program for checking implemention of IsolateMirror when |
6 // inspecting the current isolate. | |
6 | 7 |
7 #library('isolate_mirror_self_test'); | 8 #library('isolate_mirror_local_test'); |
8 | 9 |
9 #import('dart:isolate'); | 10 #import('dart:isolate'); |
10 #import('dart:mirrors'); | 11 #import('dart:mirrors'); |
11 | 12 |
12 ReceivePort rp; | 13 ReceivePort rp; |
14 int global_var = 0; | |
13 | 15 |
14 void testIsolateMirror(port) { | 16 // This function will be invoked reflectively. |
15 isolateMirrorOf(port).then((IsolateMirror mirror) { | 17 int function(int x) { |
16 Expect.isTrue(mirror.debugName.contains("main")); | 18 global_var = x; |
17 rp.close(); | 19 return x + 1; |
18 }); | 20 } |
21 | |
22 void testRootLibraryMirror(LibraryMirror lib_mirror) { | |
23 Expect.equals('isolate_mirror_local_test', lib_mirror.simpleName); | |
24 Expect.isTrue(lib_mirror.url.contains('isolate_mirror_local_test.dart')); | |
25 | |
26 // Test library invocation. | |
27 Expect.equals(0, global_var); | |
28 lib_mirror.invoke('function', [ 123 ]).then( | |
29 (InstanceMirror retval) { | |
30 Expect.equals(123, global_var); | |
31 Expect.equals(124, retval.simpleValue); | |
32 }); | |
33 } | |
34 | |
35 void testLibrariesMap(Map libraries) { | |
36 // Just look for a couple of well-known libs. | |
37 LibraryMirror core_lib = libraries['dart:core']; | |
38 Expect.isTrue(core_lib is LibraryMirror); | |
39 | |
40 LibraryMirror mirror_lib = libraries['dart:mirrors']; | |
41 Expect.isTrue(mirror_lib is LibraryMirror); | |
42 } | |
43 | |
44 void testIsolateMirror(IsolateMirror mirror) { | |
45 Expect.isTrue(mirror.debugName.contains('main')); | |
46 testRootLibraryMirror(mirror.rootLibrary); | |
47 testLibrariesMap(mirror.libraries); | |
19 } | 48 } |
20 | 49 |
21 void main() { | 50 void main() { |
22 // Test that I can reflect on myself. | 51 // Test that an isolate can reflect on itself. |
23 rp = new ReceivePort(); | 52 rp = new ReceivePort(); |
24 testIsolateMirror(rp.toSendPort()); | 53 isolateMirrorOf(rp.toSendPort()).then(testIsolateMirror); |
54 rp.close(); | |
Ivan Posva
2012/05/29 22:13:45
Shouldn't you be closing rp inside the closure reg
turnidge
2012/05/29 23:13:47
Done-ish. I've moved the rp.close() into the last
| |
25 } | 55 } |
OLD | NEW |