Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: runtime/tests/vm/dart/isolate_mirror_local_test.dart

Issue 23460050: Mirror removals: async invoke, mirrorSystemOf(port), Mirror.mirrors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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(
125 (InstanceMirror retval) { 125 (InstanceMirror retval) {
126 Expect.equals(123, global_var); 126 Expect.equals(123, global_var);
127 Expect.equals(const Symbol('int'), retval.type.simpleName); 127 Expect.equals(const Symbol('int'), retval.type.simpleName);
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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 Expect.isTrue(mirror_lib is LibraryMirror); 306 Expect.isTrue(mirror_lib is LibraryMirror);
307 307
308 // Lookup an interface from a library and make sure it is sane. 308 // Lookup an interface from a library and make sure it is sane.
309 ClassMirror list_intf = core_lib.members[const Symbol('List')]; 309 ClassMirror list_intf = core_lib.members[const Symbol('List')];
310 Expect.isTrue(list_intf is ClassMirror); 310 Expect.isTrue(list_intf is ClassMirror);
311 Expect.equals(const Symbol('List'), list_intf.simpleName); 311 Expect.equals(const Symbol('List'), list_intf.simpleName);
312 Expect.equals(const Symbol('dart.core.List'), list_intf.qualifiedName); 312 Expect.equals(const Symbol('dart.core.List'), list_intf.qualifiedName);
313 Expect.isFalse(list_intf.isPrivate); 313 Expect.isFalse(list_intf.isPrivate);
314 Expect.equals(const Symbol('Object'), list_intf.superclass.simpleName); 314 Expect.equals(const Symbol('Object'), list_intf.superclass.simpleName);
315 Expect.equals(const Symbol('dart.core'), list_intf.owner.simpleName); 315 Expect.equals(const Symbol('dart.core'), list_intf.owner.simpleName);
316 Expect.isTrue(list_intf.isClass);
317 Expect.equals(const Symbol('Iterable'), 316 Expect.equals(const Symbol('Iterable'),
318 list_intf.superinterfaces[0].simpleName); 317 list_intf.superinterfaces[0].simpleName);
319 Expect.equals("ClassMirror on 'List'", list_intf.toString()); 318 Expect.equals("ClassMirror on 'List'", list_intf.toString());
320 319
321 // Lookup a class from a library and make sure it is sane. 320 // Lookup a class from a library and make sure it is sane.
322 ClassMirror oom_cls = core_lib.members[const Symbol('OutOfMemoryError')]; 321 ClassMirror oom_cls = core_lib.members[const Symbol('OutOfMemoryError')];
323 Expect.isTrue(oom_cls is ClassMirror); 322 Expect.isTrue(oom_cls is ClassMirror);
324 Expect.equals(const Symbol('OutOfMemoryError'), oom_cls.simpleName); 323 Expect.equals(const Symbol('OutOfMemoryError'), oom_cls.simpleName);
325 Expect.equals(const Symbol('dart.core.OutOfMemoryError'), 324 Expect.equals(const Symbol('dart.core.OutOfMemoryError'),
326 oom_cls.qualifiedName); 325 oom_cls.qualifiedName);
327 Expect.isFalse(oom_cls.isPrivate); 326 Expect.isFalse(oom_cls.isPrivate);
328 Expect.equals(const Symbol('Object'), oom_cls.superclass.simpleName); 327 Expect.equals(const Symbol('Object'), oom_cls.superclass.simpleName);
329 Expect.isTrue(oom_cls.defaultFactory == null);
330 Expect.equals(const Symbol('dart.core'), oom_cls.owner.simpleName); 328 Expect.equals(const Symbol('dart.core'), oom_cls.owner.simpleName);
331 Expect.isTrue(oom_cls.isClass);
332 Expect.equals(const Symbol('Error'), oom_cls.superinterfaces[0].simpleName); 329 Expect.equals(const Symbol('Error'), oom_cls.superinterfaces[0].simpleName);
333 Expect.equals("ClassMirror on 'OutOfMemoryError'", 330 Expect.equals("ClassMirror on 'OutOfMemoryError'",
334 oom_cls.toString()); 331 oom_cls.toString());
335 testDone('testLibrariesMap'); 332 testDone('testLibrariesMap');
336 } 333 }
337 334
338 void testMirrorSystem(MirrorSystem mirrors) { 335 void testMirrorSystem(MirrorSystem mirrors) {
339 Expect.isTrue(mirrors.isolate.debugName.contains('main')); 336 Expect.isTrue(mirrors.isolate.debugName.contains('main'));
340 testRootLibraryMirror(mirrors.isolate.rootLibrary); 337 testRootLibraryMirror(mirrors.isolate.rootLibrary);
341 testLibrariesMap(mirrors.libraries); 338 testLibrariesMap(mirrors.libraries);
342 Expect.equals(const Symbol('void'), mirrors.voidType.simpleName); 339 Expect.equals(const Symbol('void'), mirrors.voidType.simpleName);
343 Expect.equals(const Symbol('dynamic'), mirrors.dynamicType.simpleName); 340 Expect.equals(const Symbol('dynamic'), mirrors.dynamicType.simpleName);
344 Expect.isTrue(mirrors.voidType is TypeMirror); 341 Expect.isTrue(mirrors.voidType is TypeMirror);
345 Expect.isTrue(mirrors.dynamicType is TypeMirror); 342 Expect.isTrue(mirrors.dynamicType is TypeMirror);
346 Expect.isFalse(mirrors.voidType is ClassMirror); 343 Expect.isFalse(mirrors.voidType is ClassMirror);
347 Expect.isFalse(mirrors.dynamicType is ClassMirror); 344 Expect.isFalse(mirrors.dynamicType is ClassMirror);
348 testDone('testMirrorSystem'); 345 testDone('testMirrorSystem');
349 } 346 }
350 347
351 void testIntegerInstanceMirror(InstanceMirror mirror) { 348 void testIntegerInstanceMirror(InstanceMirror mirror) {
352 Expect.equals(const Symbol('int'), mirror.type.simpleName); 349 Expect.equals(const Symbol('int'), mirror.type.simpleName);
353 Expect.isTrue(mirror.hasReflectee); 350 Expect.isTrue(mirror.hasReflectee);
354 Expect.equals(1001, mirror.reflectee); 351 Expect.equals(1001, mirror.reflectee);
355 Expect.equals("InstanceMirror on 1001", mirror.toString()); 352 Expect.equals("InstanceMirror on 1001", mirror.toString());
356 353
357 // Invoke (mirror + mirror). 354 // Invoke (mirror + mirror).
358 mirror.invokeAsync(const Symbol('+'), [ mirror ]).then( 355 new Future(()=>mirror.invoke(const Symbol('+'), [ mirror.reflectee ])).then(
359 (InstanceMirror retval) { 356 (InstanceMirror retval) {
360 Expect.equals(const Symbol('int'), retval.type.simpleName); 357 Expect.equals(const Symbol('int'), retval.type.simpleName);
361 Expect.isTrue(retval.hasReflectee); 358 Expect.isTrue(retval.hasReflectee);
362 Expect.equals(2002, retval.reflectee); 359 Expect.equals(2002, retval.reflectee);
363 testDone('testIntegerInstanceMirror'); 360 testDone('testIntegerInstanceMirror');
364 }); 361 });
365 } 362 }
366 363
367 void testStringInstanceMirror(InstanceMirror mirror) { 364 void testStringInstanceMirror(InstanceMirror mirror) {
368 Expect.equals(const Symbol('String'), mirror.type.simpleName); 365 Expect.equals(const Symbol('String'), mirror.type.simpleName);
369 Expect.isTrue(mirror.hasReflectee); 366 Expect.isTrue(mirror.hasReflectee);
370 Expect.equals('This\nis\na\nString', mirror.reflectee); 367 Expect.equals('This\nis\na\nString', mirror.reflectee);
371 Expect.equals('InstanceMirror on "This\\nis\\na\\nString"', 368 Expect.equals('InstanceMirror on "This\\nis\\na\\nString"',
372 mirror.toString()); 369 mirror.toString());
373 370
374 // Invoke mirror[0]. 371 // Invoke mirror[0].
375 mirror.invokeAsync(const Symbol('[]'), [ 0 ]).then( 372 new Future(()=>mirror.invoke(const Symbol('[]'), [ 0 ])).then(
376 (InstanceMirror retval) { 373 (InstanceMirror retval) {
377 Expect.equals(const Symbol('String'), retval.type.simpleName); 374 Expect.equals(const Symbol('String'), retval.type.simpleName);
378 Expect.isTrue(retval.hasReflectee); 375 Expect.isTrue(retval.hasReflectee);
379 Expect.equals('T', retval.reflectee); 376 Expect.equals('T', retval.reflectee);
380 testDone('testStringInstanceMirror'); 377 testDone('testStringInstanceMirror');
381 }); 378 });
382 } 379 }
383 380
384 void testBoolInstanceMirror(InstanceMirror mirror) { 381 void testBoolInstanceMirror(InstanceMirror mirror) {
385 Expect.equals(const Symbol('bool'), mirror.type.simpleName); 382 Expect.equals(const Symbol('bool'), mirror.type.simpleName);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 saw_exception = true; 427 saw_exception = true;
431 } 428 }
432 Expect.isFalse(saw_exception); 429 Expect.isFalse(saw_exception);
433 Expect.equals("InstanceMirror on Instance of 'MyClass'", 430 Expect.equals("InstanceMirror on Instance of 'MyClass'",
434 mirror.toString()); 431 mirror.toString());
435 432
436 ClassMirror cls = mirror.type; 433 ClassMirror cls = mirror.type;
437 Expect.isTrue(cls is ClassMirror); 434 Expect.isTrue(cls is ClassMirror);
438 Expect.equals(const Symbol('MyClass'), cls.simpleName); 435 Expect.equals(const Symbol('MyClass'), cls.simpleName);
439 Expect.equals(const Symbol('MySuperClass'), cls.superclass.simpleName); 436 Expect.equals(const Symbol('MySuperClass'), cls.superclass.simpleName);
440 Expect.isTrue(cls.defaultFactory == null);
441 Expect.equals(const Symbol('isolate_mirror_local_test'), 437 Expect.equals(const Symbol('isolate_mirror_local_test'),
442 cls.owner.simpleName); 438 cls.owner.simpleName);
443 Expect.isTrue(cls.isClass);
444 Expect.equals(const Symbol('MyInterface'), cls.superinterfaces[0].simpleName); 439 Expect.equals(const Symbol('MyInterface'), cls.superinterfaces[0].simpleName);
445 Expect.throws(() => cls.metadata, 440 Expect.throws(() => cls.metadata,
446 (e) => e is MirroredCompilationError, 441 (e) => e is MirroredCompilationError,
447 'Bad metadata'); 442 'Bad metadata');
448 Expect.equals("ClassMirror on 'MyClass'", cls.toString()); 443 Expect.equals("ClassMirror on 'MyClass'", cls.toString());
449 444
450 // Invoke mirror.method(1000). 445 // Invoke mirror.method(1000).
451 mirror.invokeAsync(const Symbol('method'), [ 1000 ]).then( 446 new Future(()=>mirror.invoke(const Symbol('method'), [ 1000 ])).then(
452 (InstanceMirror retval) { 447 (InstanceMirror retval) {
453 Expect.equals(const Symbol('int'), retval.type.simpleName); 448 Expect.equals(const Symbol('int'), retval.type.simpleName);
454 Expect.isTrue(retval.hasReflectee); 449 Expect.isTrue(retval.hasReflectee);
455 Expect.equals(1017, retval.reflectee); 450 Expect.equals(1017, retval.reflectee);
456 testDone('testCustomInstanceMirror'); 451 testDone('testCustomInstanceMirror');
457 }); 452 });
458 453
459 } 454 }
460 455
461 class MyException implements Exception { 456 class MyException implements Exception {
462 MyException(this._message); 457 MyException(this._message);
463 final String _message; 458 final String _message;
464 String toString() { return 'MyException: $_message'; } 459 String toString() { return 'MyException: $_message'; }
465 } 460 }
466 461
467 void methodWithException() { 462 void methodWithException() {
468 throw new MyException("from methodWithException"); 463 throw new MyException("from methodWithException");
469 } 464 }
470 465
471 void methodWithError() { 466 void methodWithError() {
472 // We get a parse error when we try to run this function. 467 // We get a parse error when we try to run this function.
473 +++; 468 +++;
474 } 469 }
475 470
476 void testMirrorErrors(MirrorSystem mirrors) { 471 void testMirrorErrors(MirrorSystem mirrors) {
477 LibraryMirror lib_mirror = mirrors.isolate.rootLibrary; 472 LibraryMirror lib_mirror = mirrors.isolate.rootLibrary;
478 473
479 lib_mirror.invokeAsync(const Symbol('methodWithException'), []) 474 new Future(()=>lib_mirror.invoke(const Symbol('methodWithException'), []))
480 .then((InstanceMirror retval) { 475 .then((InstanceMirror retval) {
481 // Should not reach here. 476 // Should not reach here.
482 Expect.isTrue(false); 477 Expect.isTrue(false);
483 }) 478 })
484 .catchError((error) { 479 .catchError((error) {
485 Expect.isTrue(error is MyException); 480 Expect.isTrue(error is MyException);
486 Expect.equals('MyException: from methodWithException', 481 Expect.equals('MyException: from methodWithException',
487 error.toString()); 482 error.toString());
488 testDone('testMirrorErrors1'); 483 testDone('testMirrorErrors1');
489 }); 484 });
490 485
491 lib_mirror.invokeAsync(const Symbol('methodWithError'), []) 486 new Future(()=>lib_mirror.invoke(const Symbol('methodWithError'), []))
492 .then((InstanceMirror retval) { 487 .then((InstanceMirror retval) {
493 // Should not reach here. 488 // Should not reach here.
494 Expect.isTrue(false); 489 Expect.isTrue(false);
495 }) 490 })
496 .catchError((error) { 491 .catchError((error) {
497 Expect.isTrue(error is MirroredCompilationError); 492 Expect.isTrue(error is MirroredCompilationError);
498 Expect.isTrue(error.message.contains('unexpected token')); 493 Expect.isTrue(error.message.contains('unexpected token'));
499 testDone('testMirrorErrors2'); 494 testDone('testMirrorErrors2');
500 }); 495 });
501 496
502 // TODO(turnidge): When we call a method that doesn't exist, we 497 // TODO(turnidge): When we call a method that doesn't exist, we
503 // should probably call noSuchMethod(). I'm adding this test to 498 // should probably call noSuchMethod(). I'm adding this test to
504 // document the current behavior in the meantime. 499 // document the current behavior in the meantime.
505 lib_mirror.invokeAsync(const Symbol('methodNotFound'), []) 500 new Future(()=>lib_mirror.invoke(const Symbol('methodNotFound'), []))
506 .then((InstanceMirror retval) { 501 .then((InstanceMirror retval) {
507 // Should not reach here. 502 // Should not reach here.
508 Expect.isTrue(false); 503 Expect.isTrue(false);
509 }) 504 })
510 .catchError((error) { 505 .catchError((error) {
511 Expect.isTrue(error is NoSuchMethodError); 506 Expect.isTrue(error is NoSuchMethodError);
512 Expect.isTrue(error.toString().contains( 507 Expect.isTrue(error.toString().contains(
513 "No top-level method 'methodNotFound'")); 508 "No top-level method 'methodNotFound'"));
514 testDone('testMirrorErrors3'); 509 testDone('testMirrorErrors3');
515 }); 510 });
516 } 511 }
517 512
518 void main() { 513 void main() {
519 // When all of the expected tests complete, the exit_port is closed, 514 // When all of the expected tests complete, the exit_port is closed,
520 // allowing the program to terminate. 515 // allowing the program to terminate.
521 exit_port = new ReceivePort(); 516 exit_port = new ReceivePort();
522 expectedTests = new Set<String>.from(['testRootLibraryMirror', 517 expectedTests = new Set<String>.from(['testRootLibraryMirror',
523 'testLibrariesMap', 518 'testLibrariesMap',
524 'testMirrorSystem', 519 'testMirrorSystem',
525 'testIntegerInstanceMirror', 520 'testIntegerInstanceMirror',
526 'testStringInstanceMirror', 521 'testStringInstanceMirror',
527 'testBoolInstanceMirror', 522 'testBoolInstanceMirror',
528 'testNullInstanceMirror', 523 'testNullInstanceMirror',
529 'testCustomInstanceMirror', 524 'testCustomInstanceMirror',
530 'testMirrorErrors1', 525 'testMirrorErrors1',
531 'testMirrorErrors2', 526 'testMirrorErrors2',
532 'testMirrorErrors3']); 527 'testMirrorErrors3']);
533 528
534 // Test that an isolate can reflect on itself. 529 testMirrorSystem(currentMirrorSystem());
535 mirrorSystemOf(exit_port.toSendPort()).then(testMirrorSystem);
536 530
537 testIntegerInstanceMirror(reflect(1001)); 531 testIntegerInstanceMirror(reflect(1001));
538 testStringInstanceMirror(reflect('This\nis\na\nString')); 532 testStringInstanceMirror(reflect('This\nis\na\nString'));
539 testBoolInstanceMirror(reflect(true)); 533 testBoolInstanceMirror(reflect(true));
540 testNullInstanceMirror(reflect(null)); 534 testNullInstanceMirror(reflect(null));
541 testCustomInstanceMirror(reflect(new MyClass(17))); 535 testCustomInstanceMirror(reflect(new MyClass(17)));
542 testMirrorErrors(currentMirrorSystem()); 536 testMirrorErrors(currentMirrorSystem());
543 } 537 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698