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 when | 5 // Dart test program for checking implemention of MirrorSystem when |
6 // inspecting the current isolate. | 6 // inspecting the current isolate. |
7 | 7 |
8 #library('isolate_mirror_local_test'); | 8 #library('isolate_mirror_local_test'); |
9 | 9 |
10 #import('dart:isolate'); | 10 #import('dart:isolate'); |
11 #import('dart:mirrors'); | 11 #import('dart:mirrors'); |
12 | 12 |
13 ReceivePort exit_port; | 13 ReceivePort exit_port; |
14 Set expectedTests; | 14 Set expectedTests; |
15 | 15 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 'main, ' | 125 'main, ' |
126 'methodWithError, ' | 126 'methodWithError, ' |
127 'methodWithException, ' | 127 'methodWithException, ' |
128 'myVar, ' | 128 'myVar, ' |
129 'myVar=, ' | 129 'myVar=, ' |
130 'sort, ' | 130 'sort, ' |
131 'testBoolInstanceMirror, ' | 131 'testBoolInstanceMirror, ' |
132 'testCustomInstanceMirror, ' | 132 'testCustomInstanceMirror, ' |
133 'testDone, ' | 133 'testDone, ' |
134 'testIntegerInstanceMirror, ' | 134 'testIntegerInstanceMirror, ' |
135 'testIsolateMirror, ' | |
136 'testLibrariesMap, ' | 135 'testLibrariesMap, ' |
137 'testMirrorErrors, ' | 136 'testMirrorErrors, ' |
| 137 'testMirrorSystem, ' |
138 'testNullInstanceMirror, ' | 138 'testNullInstanceMirror, ' |
139 'testRootLibraryMirror, ' | 139 'testRootLibraryMirror, ' |
140 'testStringInstanceMirror]', | 140 'testStringInstanceMirror]', |
141 '$keys'); | 141 '$keys'); |
142 | 142 |
143 // Check that the classes map is complete. | 143 // Check that the classes map is complete. |
144 keys = lib_mirror.classes().getKeys(); | 144 keys = lib_mirror.classes().getKeys(); |
145 sort(keys); | 145 sort(keys); |
146 Expect.equals('[' | 146 Expect.equals('[' |
147 'MyClass, ' | 147 'MyClass, ' |
(...skipping 13 matching lines...) Expand all Loading... |
161 'main, ' | 161 'main, ' |
162 'methodWithError, ' | 162 'methodWithError, ' |
163 'methodWithException, ' | 163 'methodWithException, ' |
164 'myVar, ' | 164 'myVar, ' |
165 'myVar=, ' | 165 'myVar=, ' |
166 'sort, ' | 166 'sort, ' |
167 'testBoolInstanceMirror, ' | 167 'testBoolInstanceMirror, ' |
168 'testCustomInstanceMirror, ' | 168 'testCustomInstanceMirror, ' |
169 'testDone, ' | 169 'testDone, ' |
170 'testIntegerInstanceMirror, ' | 170 'testIntegerInstanceMirror, ' |
171 'testIsolateMirror, ' | |
172 'testLibrariesMap, ' | 171 'testLibrariesMap, ' |
173 'testMirrorErrors, ' | 172 'testMirrorErrors, ' |
| 173 'testMirrorSystem, ' |
174 'testNullInstanceMirror, ' | 174 'testNullInstanceMirror, ' |
175 'testRootLibraryMirror, ' | 175 'testRootLibraryMirror, ' |
176 'testStringInstanceMirror]', | 176 'testStringInstanceMirror]', |
177 '$keys'); | 177 '$keys'); |
178 | 178 |
179 // Check that the variables map is complete. | 179 // Check that the variables map is complete. |
180 keys = lib_mirror.variables().getKeys(); | 180 keys = lib_mirror.variables().getKeys(); |
181 sort(keys); | 181 sort(keys); |
182 Expect.equals('[' | 182 Expect.equals('[' |
183 'exit_port, ' | 183 'exit_port, ' |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 Expect.equals('Object', oom_cls.superclass().simpleName); | 250 Expect.equals('Object', oom_cls.superclass().simpleName); |
251 Expect.isTrue(oom_cls.defaultFactory() === null); | 251 Expect.isTrue(oom_cls.defaultFactory() === null); |
252 Expect.equals('dart:core', oom_cls.library.simpleName); | 252 Expect.equals('dart:core', oom_cls.library.simpleName); |
253 Expect.isTrue(oom_cls.isClass); | 253 Expect.isTrue(oom_cls.isClass); |
254 Expect.equals('Exception', oom_cls.superinterfaces()[0].simpleName); | 254 Expect.equals('Exception', oom_cls.superinterfaces()[0].simpleName); |
255 Expect.equals("InterfaceMirror on 'OutOfMemoryException'", | 255 Expect.equals("InterfaceMirror on 'OutOfMemoryException'", |
256 oom_cls.toString()); | 256 oom_cls.toString()); |
257 testDone('testLibrariesMap'); | 257 testDone('testLibrariesMap'); |
258 } | 258 } |
259 | 259 |
260 void testIsolateMirror(IsolateMirror mirror) { | 260 void testMirrorSystem(MirrorSystem mirrors) { |
261 Expect.isTrue(mirror.debugName.contains('main')); | 261 Expect.isTrue(mirrors.isolate.debugName.contains('main')); |
262 testRootLibraryMirror(mirror.rootLibrary); | 262 testRootLibraryMirror(mirrors.rootLibrary); |
263 testLibrariesMap(mirror.libraries()); | 263 testLibrariesMap(mirrors.libraries()); |
264 testDone('testIsolateMirror'); | 264 testDone('testMirrorSystem'); |
265 } | 265 } |
266 | 266 |
267 void testIntegerInstanceMirror(InstanceMirror mirror) { | 267 void testIntegerInstanceMirror(InstanceMirror mirror) { |
268 // TODO(turnidge): The mirrors api exposes internal vm | 268 // TODO(turnidge): The mirrors api exposes internal vm |
269 // implementation class names. Is this okay? | 269 // implementation class names. Is this okay? |
270 Expect.equals('Smi', mirror.getClass().simpleName); | 270 Expect.equals('Smi', mirror.getClass().simpleName); |
271 Expect.isTrue(mirror.hasSimpleValue); | 271 Expect.isTrue(mirror.hasSimpleValue); |
272 Expect.equals(1001, mirror.simpleValue); | 272 Expect.equals(1001, mirror.simpleValue); |
273 Expect.equals("InstanceMirror on <1001>", mirror.toString()); | 273 Expect.equals("InstanceMirror on <1001>", mirror.toString()); |
274 | 274 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 | 375 |
376 void methodWithException() { | 376 void methodWithException() { |
377 throw new MyException("from methodWithException"); | 377 throw new MyException("from methodWithException"); |
378 } | 378 } |
379 | 379 |
380 void methodWithError() { | 380 void methodWithError() { |
381 // We get a parse error when we try to run this function. | 381 // We get a parse error when we try to run this function. |
382 +++; | 382 +++; |
383 } | 383 } |
384 | 384 |
385 void testMirrorErrors(IsolateMirror mirror) { | 385 void testMirrorErrors(MirrorSystem mirrors) { |
386 LibraryMirror lib_mirror = mirror.rootLibrary; | 386 LibraryMirror lib_mirror = mirrors.rootLibrary; |
387 | 387 |
388 Future<InstanceMirror> future = | 388 Future<InstanceMirror> future = |
389 lib_mirror.invoke('methodWithException', []); | 389 lib_mirror.invoke('methodWithException', []); |
390 future.handleException( | 390 future.handleException( |
391 (MirroredError exc) { | 391 (MirroredError exc) { |
392 Expect.isTrue(exc is MirroredUncaughtExceptionError); | 392 Expect.isTrue(exc is MirroredUncaughtExceptionError); |
393 Expect.equals('MyException', | 393 Expect.equals('MyException', |
394 exc.exception_mirror.getClass().simpleName); | 394 exc.exception_mirror.getClass().simpleName); |
395 Expect.equals('MyException: from methodWithException', | 395 Expect.equals('MyException: from methodWithException', |
396 exc.exception_string); | 396 exc.exception_string); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 Expect.isTrue(false); | 439 Expect.isTrue(false); |
440 }); | 440 }); |
441 } | 441 } |
442 | 442 |
443 void main() { | 443 void main() { |
444 // When all of the expected tests complete, the exit_port is closed, | 444 // When all of the expected tests complete, the exit_port is closed, |
445 // allowing the program to terminate. | 445 // allowing the program to terminate. |
446 exit_port = new ReceivePort(); | 446 exit_port = new ReceivePort(); |
447 expectedTests = new Set<String>.from(['testRootLibraryMirror', | 447 expectedTests = new Set<String>.from(['testRootLibraryMirror', |
448 'testLibrariesMap', | 448 'testLibrariesMap', |
449 'testIsolateMirror', | 449 'testMirrorSystem', |
450 'testIntegerInstanceMirror', | 450 'testIntegerInstanceMirror', |
451 'testStringInstanceMirror', | 451 'testStringInstanceMirror', |
452 'testBoolInstanceMirror', | 452 'testBoolInstanceMirror', |
453 'testNullInstanceMirror', | 453 'testNullInstanceMirror', |
454 'testCustomInstanceMirror', | 454 'testCustomInstanceMirror', |
455 'testMirrorErrors1', | 455 'testMirrorErrors1', |
456 'testMirrorErrors2', | 456 'testMirrorErrors2', |
457 'testMirrorErrors3']); | 457 'testMirrorErrors3']); |
458 | 458 |
459 // Test that an isolate can reflect on itself. | 459 // Test that an isolate can reflect on itself. |
460 isolateMirrorOf(exit_port.toSendPort()).then(testIsolateMirror); | 460 mirrorSystemOf(exit_port.toSendPort()).then(testMirrorSystem); |
461 | 461 |
462 testIntegerInstanceMirror(mirrorOf(1001)); | 462 MirrorSystem mirrors = currentMirrorSystem(); |
463 testStringInstanceMirror(mirrorOf('This\nis\na\nString')); | 463 testIntegerInstanceMirror(mirrors.mirrorOf(1001)); |
464 testBoolInstanceMirror(mirrorOf(true)); | 464 testStringInstanceMirror(mirrors.mirrorOf('This\nis\na\nString')); |
465 testNullInstanceMirror(mirrorOf(null)); | 465 testBoolInstanceMirror(mirrors.mirrorOf(true)); |
466 testCustomInstanceMirror(mirrorOf(new MyClass(17))); | 466 testNullInstanceMirror(mirrors.mirrorOf(null)); |
467 testMirrorErrors(currentIsolateMirror()); | 467 testCustomInstanceMirror(mirrors.mirrorOf(new MyClass(17))); |
| 468 testMirrorErrors(currentMirrorSystem()); |
468 } | 469 } |
OLD | NEW |