Chromium Code Reviews| 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 MirrorSystem when | 5 // Dart test program for checking implemention of MirrorSystem when |
| 6 // inspecting the current isolate. | 6 // inspecting the current isolate. |
| 7 // | 7 // |
| 8 // VMOptions=--enable_type_checks | 8 // VMOptions=--enable_type_checks |
| 9 | 9 |
| 10 library isolate_mirror_local_test; | 10 library isolate_mirror_local_test; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 Expect.equals(const Symbol('isolate_mirror_local_test'), | 114 Expect.equals(const Symbol('isolate_mirror_local_test'), |
| 115 lib_mirror.qualifiedName); | 115 lib_mirror.qualifiedName); |
| 116 Expect.equals(null, lib_mirror.owner); | 116 Expect.equals(null, lib_mirror.owner); |
| 117 Expect.isFalse(lib_mirror.isPrivate); | 117 Expect.isFalse(lib_mirror.isPrivate); |
| 118 Expect.isTrue(lib_mirror.uri.path.contains('isolate_mirror_local_test.dart')); | 118 Expect.isTrue(lib_mirror.uri.path.contains('isolate_mirror_local_test.dart')); |
| 119 Expect.equals("LibraryMirror on 'isolate_mirror_local_test'", | 119 Expect.equals("LibraryMirror on 'isolate_mirror_local_test'", |
| 120 lib_mirror.toString()); | 120 lib_mirror.toString()); |
| 121 | 121 |
| 122 // Test library invocation by calling function(123). | 122 // Test library invocation by calling function(123). |
| 123 Expect.equals(0, global_var); | 123 Expect.equals(0, global_var); |
| 124 lib_mirror.invokeAsync(const Symbol('function'), [123]).then( | 124 new Future(()=>lib_mirror.invoke(const Symbol('function'), [123])).then( |
|
ahe
2013/10/29 10:18:22
Don't use future?
rmacnak
2013/10/30 17:25:30
Actually I will just delete this test. This test h
| |
| 125 (InstanceMirror retval) { | 125 (InstanceMirror retval) { |
| 126 Expect.equals(123, global_var); | 126 Expect.equals(123, global_var); |
| 127 testImplements(retval.type, #int); | 127 testImplements(retval.type, #int); |
| 128 Expect.isTrue(retval.hasReflectee); | 128 Expect.isTrue(retval.hasReflectee); |
| 129 Expect.equals(124, retval.reflectee); | 129 Expect.equals(124, retval.reflectee); |
| 130 testDone('testRootLibraryMirror'); | 130 testDone('testRootLibraryMirror'); |
| 131 }); | 131 }); |
| 132 | 132 |
| 133 // Check that the members map is complete. | 133 // Check that the members map is complete. |
| 134 List keys = lib_mirror.members.keys.map(MirrorSystem.getName).toList(); | 134 List keys = lib_mirror.members.keys.map(MirrorSystem.getName).toList(); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 Expect.isTrue(mirror_lib is LibraryMirror); | 316 Expect.isTrue(mirror_lib is LibraryMirror); |
| 317 | 317 |
| 318 // Lookup an interface from a library and make sure it is sane. | 318 // Lookup an interface from a library and make sure it is sane. |
| 319 ClassMirror list_intf = core_lib.members[const Symbol('List')]; | 319 ClassMirror list_intf = core_lib.members[const Symbol('List')]; |
| 320 Expect.isTrue(list_intf is ClassMirror); | 320 Expect.isTrue(list_intf is ClassMirror); |
| 321 Expect.equals(const Symbol('List'), list_intf.simpleName); | 321 Expect.equals(const Symbol('List'), list_intf.simpleName); |
| 322 Expect.equals(const Symbol('dart.core.List'), list_intf.qualifiedName); | 322 Expect.equals(const Symbol('dart.core.List'), list_intf.qualifiedName); |
| 323 Expect.isFalse(list_intf.isPrivate); | 323 Expect.isFalse(list_intf.isPrivate); |
| 324 Expect.equals(const Symbol('Object'), list_intf.superclass.simpleName); | 324 Expect.equals(const Symbol('Object'), list_intf.superclass.simpleName); |
| 325 Expect.equals(const Symbol('dart.core'), list_intf.owner.simpleName); | 325 Expect.equals(const Symbol('dart.core'), list_intf.owner.simpleName); |
| 326 Expect.isTrue(list_intf.isClass); | |
| 327 Expect.equals(const Symbol('Iterable'), | 326 Expect.equals(const Symbol('Iterable'), |
| 328 list_intf.superinterfaces[0].simpleName); | 327 list_intf.superinterfaces[0].simpleName); |
| 329 Expect.equals("ClassMirror on 'List'", list_intf.toString()); | 328 Expect.equals("ClassMirror on 'List'", list_intf.toString()); |
| 330 | 329 |
| 331 // Lookup a class from a library and make sure it is sane. | 330 // Lookup a class from a library and make sure it is sane. |
| 332 ClassMirror oom_cls = core_lib.members[const Symbol('OutOfMemoryError')]; | 331 ClassMirror oom_cls = core_lib.members[const Symbol('OutOfMemoryError')]; |
| 333 Expect.isTrue(oom_cls is ClassMirror); | 332 Expect.isTrue(oom_cls is ClassMirror); |
| 334 Expect.equals(const Symbol('OutOfMemoryError'), oom_cls.simpleName); | 333 Expect.equals(const Symbol('OutOfMemoryError'), oom_cls.simpleName); |
| 335 Expect.equals(const Symbol('dart.core.OutOfMemoryError'), | 334 Expect.equals(const Symbol('dart.core.OutOfMemoryError'), |
| 336 oom_cls.qualifiedName); | 335 oom_cls.qualifiedName); |
| 337 Expect.isFalse(oom_cls.isPrivate); | 336 Expect.isFalse(oom_cls.isPrivate); |
| 338 Expect.equals(const Symbol('Object'), oom_cls.superclass.simpleName); | 337 Expect.equals(const Symbol('Object'), oom_cls.superclass.simpleName); |
| 339 Expect.isTrue(oom_cls.defaultFactory == null); | |
| 340 Expect.equals(const Symbol('dart.core'), oom_cls.owner.simpleName); | 338 Expect.equals(const Symbol('dart.core'), oom_cls.owner.simpleName); |
| 341 Expect.isTrue(oom_cls.isClass); | |
| 342 Expect.equals(const Symbol('Error'), oom_cls.superinterfaces[0].simpleName); | 339 Expect.equals(const Symbol('Error'), oom_cls.superinterfaces[0].simpleName); |
| 343 Expect.equals("ClassMirror on 'OutOfMemoryError'", | 340 Expect.equals("ClassMirror on 'OutOfMemoryError'", |
| 344 oom_cls.toString()); | 341 oom_cls.toString()); |
| 345 testDone('testLibrariesMap'); | 342 testDone('testLibrariesMap'); |
| 346 } | 343 } |
| 347 | 344 |
| 348 void testMirrorSystem(MirrorSystem mirrors) { | 345 void testMirrorSystem(MirrorSystem mirrors) { |
| 349 Expect.isTrue(mirrors.isolate.debugName.contains('main')); | 346 Expect.isTrue(mirrors.isolate.debugName.contains('main')); |
| 350 testRootLibraryMirror(mirrors.isolate.rootLibrary); | 347 testRootLibraryMirror(mirrors.isolate.rootLibrary); |
| 351 testLibrariesMap(mirrors.libraries); | 348 testLibrariesMap(mirrors.libraries); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 369 Expect.isTrue(foundInterface, '$klass should implement $intfName'); | 366 Expect.isTrue(foundInterface, '$klass should implement $intfName'); |
| 370 } | 367 } |
| 371 | 368 |
| 372 void testIntegerInstanceMirror(InstanceMirror mirror) { | 369 void testIntegerInstanceMirror(InstanceMirror mirror) { |
| 373 testImplements(mirror.type, #int); | 370 testImplements(mirror.type, #int); |
| 374 Expect.isTrue(mirror.hasReflectee); | 371 Expect.isTrue(mirror.hasReflectee); |
| 375 Expect.equals(1001, mirror.reflectee); | 372 Expect.equals(1001, mirror.reflectee); |
| 376 Expect.equals("InstanceMirror on 1001", mirror.toString()); | 373 Expect.equals("InstanceMirror on 1001", mirror.toString()); |
| 377 | 374 |
| 378 // Invoke (mirror + mirror). | 375 // Invoke (mirror + mirror). |
| 379 mirror.invokeAsync(const Symbol('+'), [ mirror ]).then( | 376 new Future(()=>mirror.invoke(const Symbol('+'), [ mirror.reflectee ])).then( |
|
ahe
2013/10/29 10:18:22
Don't use future?
| |
| 380 (InstanceMirror retval) { | 377 (InstanceMirror retval) { |
| 381 testImplements(retval.type, #int); | 378 testImplements(retval.type, #int); |
| 382 Expect.isTrue(retval.hasReflectee); | 379 Expect.isTrue(retval.hasReflectee); |
| 383 Expect.equals(2002, retval.reflectee); | 380 Expect.equals(2002, retval.reflectee); |
| 384 testDone('testIntegerInstanceMirror'); | 381 testDone('testIntegerInstanceMirror'); |
| 385 }); | 382 }); |
| 386 } | 383 } |
| 387 | 384 |
| 388 void testStringInstanceMirror(InstanceMirror mirror) { | 385 void testStringInstanceMirror(InstanceMirror mirror) { |
| 389 testImplements(mirror.type, #String); | 386 testImplements(mirror.type, #String); |
| 390 Expect.isTrue(mirror.hasReflectee); | 387 Expect.isTrue(mirror.hasReflectee); |
| 391 Expect.equals('This\nis\na\nString', mirror.reflectee); | 388 Expect.equals('This\nis\na\nString', mirror.reflectee); |
| 392 Expect.equals('InstanceMirror on "This\\nis\\na\\nString"', | 389 Expect.equals('InstanceMirror on "This\\nis\\na\\nString"', |
| 393 mirror.toString()); | 390 mirror.toString()); |
| 394 | 391 |
| 395 // Invoke mirror[0]. | 392 // Invoke mirror[0]. |
| 396 mirror.invokeAsync(const Symbol('[]'), [ 0 ]).then( | 393 new Future(()=>mirror.invoke(const Symbol('[]'), [ 0 ])).then( |
|
ahe
2013/10/29 10:18:22
Ditto.
| |
| 397 (InstanceMirror retval) { | 394 (InstanceMirror retval) { |
| 398 testImplements(retval.type, #String); | 395 testImplements(retval.type, #String); |
| 399 Expect.isTrue(retval.hasReflectee); | 396 Expect.isTrue(retval.hasReflectee); |
| 400 Expect.equals('T', retval.reflectee); | 397 Expect.equals('T', retval.reflectee); |
| 401 testDone('testStringInstanceMirror'); | 398 testDone('testStringInstanceMirror'); |
| 402 }); | 399 }); |
| 403 } | 400 } |
| 404 | 401 |
| 405 void testBoolInstanceMirror(InstanceMirror mirror) { | 402 void testBoolInstanceMirror(InstanceMirror mirror) { |
| 406 testImplements(mirror.type, #bool); | 403 testImplements(mirror.type, #bool); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 450 saw_exception = true; | 447 saw_exception = true; |
| 451 } | 448 } |
| 452 Expect.isFalse(saw_exception); | 449 Expect.isFalse(saw_exception); |
| 453 Expect.equals("InstanceMirror on Instance of 'MyClass'", | 450 Expect.equals("InstanceMirror on Instance of 'MyClass'", |
| 454 mirror.toString()); | 451 mirror.toString()); |
| 455 | 452 |
| 456 ClassMirror cls = mirror.type; | 453 ClassMirror cls = mirror.type; |
| 457 Expect.isTrue(cls is ClassMirror); | 454 Expect.isTrue(cls is ClassMirror); |
| 458 Expect.equals(const Symbol('MyClass'), cls.simpleName); | 455 Expect.equals(const Symbol('MyClass'), cls.simpleName); |
| 459 Expect.equals(const Symbol('MySuperClass'), cls.superclass.simpleName); | 456 Expect.equals(const Symbol('MySuperClass'), cls.superclass.simpleName); |
| 460 Expect.isTrue(cls.defaultFactory == null); | |
| 461 Expect.equals(const Symbol('isolate_mirror_local_test'), | 457 Expect.equals(const Symbol('isolate_mirror_local_test'), |
| 462 cls.owner.simpleName); | 458 cls.owner.simpleName); |
| 463 Expect.isTrue(cls.isClass); | |
| 464 Expect.equals(const Symbol('MyInterface'), cls.superinterfaces[0].simpleName); | 459 Expect.equals(const Symbol('MyInterface'), cls.superinterfaces[0].simpleName); |
| 465 Expect.equals("ClassMirror on 'MyClass'", cls.toString()); | 460 Expect.equals("ClassMirror on 'MyClass'", cls.toString()); |
| 466 | 461 |
| 467 // Invoke mirror.method(1000). | 462 // Invoke mirror.method(1000). |
| 468 mirror.invokeAsync(const Symbol('method'), [ 1000 ]).then( | 463 new Future(()=>mirror.invoke(const Symbol('method'), [ 1000 ])).then( |
|
ahe
2013/10/29 10:18:22
Ditto.
| |
| 469 (InstanceMirror retval) { | 464 (InstanceMirror retval) { |
| 470 testImplements(retval.type, #int); | 465 testImplements(retval.type, #int); |
| 471 Expect.isTrue(retval.hasReflectee); | 466 Expect.isTrue(retval.hasReflectee); |
| 472 Expect.equals(1017, retval.reflectee); | 467 Expect.equals(1017, retval.reflectee); |
| 473 testDone('testCustomInstanceMirror'); | 468 testDone('testCustomInstanceMirror'); |
| 474 }); | 469 }); |
| 475 | 470 |
| 476 } | 471 } |
| 477 | 472 |
| 478 class MyException implements Exception { | 473 class MyException implements Exception { |
| 479 MyException(this._message); | 474 MyException(this._message); |
| 480 final String _message; | 475 final String _message; |
| 481 String toString() { return 'MyException: $_message'; } | 476 String toString() { return 'MyException: $_message'; } |
| 482 } | 477 } |
| 483 | 478 |
| 484 void main() { | 479 void main() { |
| 485 // When all of the expected tests complete, the exit_port is closed, | 480 // When all of the expected tests complete, the exit_port is closed, |
| 486 // allowing the program to terminate. | 481 // allowing the program to terminate. |
| 487 exit_port = new ReceivePort(); | 482 exit_port = new ReceivePort(); |
| 488 expectedTests = new Set<String>.from(['testRootLibraryMirror', | 483 expectedTests = new Set<String>.from(['testRootLibraryMirror', |
| 489 'testLibrariesMap', | 484 'testLibrariesMap', |
| 490 'testMirrorSystem', | 485 'testMirrorSystem', |
| 491 'testIntegerInstanceMirror', | 486 'testIntegerInstanceMirror', |
| 492 'testStringInstanceMirror', | 487 'testStringInstanceMirror', |
| 493 'testBoolInstanceMirror', | 488 'testBoolInstanceMirror', |
| 494 'testNullInstanceMirror', | 489 'testNullInstanceMirror', |
| 495 'testCustomInstanceMirror']); | 490 'testCustomInstanceMirror']); |
| 496 | 491 |
| 497 // Test that an isolate can reflect on itself. | 492 testMirrorSystem(currentMirrorSystem()); |
| 498 mirrorSystemOf(exit_port.toSendPort()).then(testMirrorSystem); | |
| 499 | 493 |
| 500 testIntegerInstanceMirror(reflect(1001)); | 494 testIntegerInstanceMirror(reflect(1001)); |
| 501 testStringInstanceMirror(reflect('This\nis\na\nString')); | 495 testStringInstanceMirror(reflect('This\nis\na\nString')); |
| 502 testBoolInstanceMirror(reflect(true)); | 496 testBoolInstanceMirror(reflect(true)); |
| 503 testNullInstanceMirror(reflect(null)); | 497 testNullInstanceMirror(reflect(null)); |
| 504 testCustomInstanceMirror(reflect(new MyClass(17))); | 498 testCustomInstanceMirror(reflect(new MyClass(17))); |
| 505 } | 499 } |
| OLD | NEW |