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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 lib_mirror.invokeAsync(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 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(); |
135 sort(keys); | 135 sort(keys); |
136 Expect.equals('[' | 136 Expect.equals('[' |
137 'FuncType, ' | 137 'FuncType, ' |
(...skipping 13 matching lines...) Expand all Loading... |
151 'main, ' | 151 'main, ' |
152 'methodWithError, ' | 152 'methodWithError, ' |
153 'methodWithException, ' | 153 'methodWithException, ' |
154 'myFunc, ' | 154 'myFunc, ' |
155 'myVar, ' | 155 'myVar, ' |
156 'myVar=, ' | 156 'myVar=, ' |
157 'sort, ' | 157 'sort, ' |
158 'testBoolInstanceMirror, ' | 158 'testBoolInstanceMirror, ' |
159 'testCustomInstanceMirror, ' | 159 'testCustomInstanceMirror, ' |
160 'testDone, ' | 160 'testDone, ' |
| 161 'testImplements, ' |
161 'testIntegerInstanceMirror, ' | 162 'testIntegerInstanceMirror, ' |
162 'testLibrariesMap, ' | 163 'testLibrariesMap, ' |
163 'testMirrorErrors, ' | 164 'testMirrorErrors, ' |
164 'testMirrorSystem, ' | 165 'testMirrorSystem, ' |
165 'testNullInstanceMirror, ' | 166 'testNullInstanceMirror, ' |
166 'testRootLibraryMirror, ' | 167 'testRootLibraryMirror, ' |
167 'testStringInstanceMirror]', | 168 'testStringInstanceMirror]', |
168 '$keys'); | 169 '$keys'); |
169 | 170 |
170 // Check that the classes map is complete. | 171 // Check that the classes map is complete. |
(...skipping 18 matching lines...) Expand all Loading... |
189 'function, ' | 190 'function, ' |
190 'main, ' | 191 'main, ' |
191 'methodWithError, ' | 192 'methodWithError, ' |
192 'methodWithException, ' | 193 'methodWithException, ' |
193 'myVar, ' | 194 'myVar, ' |
194 'myVar=, ' | 195 'myVar=, ' |
195 'sort, ' | 196 'sort, ' |
196 'testBoolInstanceMirror, ' | 197 'testBoolInstanceMirror, ' |
197 'testCustomInstanceMirror, ' | 198 'testCustomInstanceMirror, ' |
198 'testDone, ' | 199 'testDone, ' |
| 200 'testImplements, ' |
199 'testIntegerInstanceMirror, ' | 201 'testIntegerInstanceMirror, ' |
200 'testLibrariesMap, ' | 202 'testLibrariesMap, ' |
201 'testMirrorErrors, ' | 203 'testMirrorErrors, ' |
202 'testMirrorSystem, ' | 204 'testMirrorSystem, ' |
203 'testNullInstanceMirror, ' | 205 'testNullInstanceMirror, ' |
204 'testRootLibraryMirror, ' | 206 'testRootLibraryMirror, ' |
205 'testStringInstanceMirror]', | 207 'testStringInstanceMirror]', |
206 '$keys'); | 208 '$keys'); |
207 | 209 |
208 // Check that the getters map is complete. | 210 // Check that the getters map is complete. |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 testLibrariesMap(mirrors.libraries); | 344 testLibrariesMap(mirrors.libraries); |
343 Expect.equals(const Symbol('void'), mirrors.voidType.simpleName); | 345 Expect.equals(const Symbol('void'), mirrors.voidType.simpleName); |
344 Expect.equals(const Symbol('dynamic'), mirrors.dynamicType.simpleName); | 346 Expect.equals(const Symbol('dynamic'), mirrors.dynamicType.simpleName); |
345 Expect.isTrue(mirrors.voidType is TypeMirror); | 347 Expect.isTrue(mirrors.voidType is TypeMirror); |
346 Expect.isTrue(mirrors.dynamicType is TypeMirror); | 348 Expect.isTrue(mirrors.dynamicType is TypeMirror); |
347 Expect.isFalse(mirrors.voidType is ClassMirror); | 349 Expect.isFalse(mirrors.voidType is ClassMirror); |
348 Expect.isFalse(mirrors.dynamicType is ClassMirror); | 350 Expect.isFalse(mirrors.dynamicType is ClassMirror); |
349 testDone('testMirrorSystem'); | 351 testDone('testMirrorSystem'); |
350 } | 352 } |
351 | 353 |
| 354 void testImplements(klass, intfName) { |
| 355 bool foundInterface = false; |
| 356 for (ClassMirror cm = klass; cm != null; cm = cm.superclass) { |
| 357 if (cm.simpleName == intfName) foundInterface = true; |
| 358 cm.superinterfaces.forEach((intf) { |
| 359 if (intf.simpleName == intfName) foundInterface = true; |
| 360 }); |
| 361 } |
| 362 Expect.isTrue(foundInterface, '$klass should implement $intfName'); |
| 363 } |
| 364 |
352 void testIntegerInstanceMirror(InstanceMirror mirror) { | 365 void testIntegerInstanceMirror(InstanceMirror mirror) { |
353 Expect.equals(const Symbol('int'), mirror.type.simpleName); | 366 testImplements(mirror.type, #int); |
354 Expect.isTrue(mirror.hasReflectee); | 367 Expect.isTrue(mirror.hasReflectee); |
355 Expect.equals(1001, mirror.reflectee); | 368 Expect.equals(1001, mirror.reflectee); |
356 Expect.equals("InstanceMirror on 1001", mirror.toString()); | 369 Expect.equals("InstanceMirror on 1001", mirror.toString()); |
357 | 370 |
358 // Invoke (mirror + mirror). | 371 // Invoke (mirror + mirror). |
359 mirror.invokeAsync(const Symbol('+'), [ mirror ]).then( | 372 mirror.invokeAsync(const Symbol('+'), [ mirror ]).then( |
360 (InstanceMirror retval) { | 373 (InstanceMirror retval) { |
361 Expect.equals(const Symbol('int'), retval.type.simpleName); | 374 testImplements(retval.type, #int); |
362 Expect.isTrue(retval.hasReflectee); | 375 Expect.isTrue(retval.hasReflectee); |
363 Expect.equals(2002, retval.reflectee); | 376 Expect.equals(2002, retval.reflectee); |
364 testDone('testIntegerInstanceMirror'); | 377 testDone('testIntegerInstanceMirror'); |
365 }); | 378 }); |
366 } | 379 } |
367 | 380 |
368 void testStringInstanceMirror(InstanceMirror mirror) { | 381 void testStringInstanceMirror(InstanceMirror mirror) { |
369 Expect.equals(const Symbol('String'), mirror.type.simpleName); | 382 testImplements(mirror.type, #String); |
370 Expect.isTrue(mirror.hasReflectee); | 383 Expect.isTrue(mirror.hasReflectee); |
371 Expect.equals('This\nis\na\nString', mirror.reflectee); | 384 Expect.equals('This\nis\na\nString', mirror.reflectee); |
372 Expect.equals('InstanceMirror on "This\\nis\\na\\nString"', | 385 Expect.equals('InstanceMirror on "This\\nis\\na\\nString"', |
373 mirror.toString()); | 386 mirror.toString()); |
374 | 387 |
375 // Invoke mirror[0]. | 388 // Invoke mirror[0]. |
376 mirror.invokeAsync(const Symbol('[]'), [ 0 ]).then( | 389 mirror.invokeAsync(const Symbol('[]'), [ 0 ]).then( |
377 (InstanceMirror retval) { | 390 (InstanceMirror retval) { |
378 Expect.equals(const Symbol('String'), retval.type.simpleName); | 391 testImplements(retval.type, #String); |
379 Expect.isTrue(retval.hasReflectee); | 392 Expect.isTrue(retval.hasReflectee); |
380 Expect.equals('T', retval.reflectee); | 393 Expect.equals('T', retval.reflectee); |
381 testDone('testStringInstanceMirror'); | 394 testDone('testStringInstanceMirror'); |
382 }); | 395 }); |
383 } | 396 } |
384 | 397 |
385 void testBoolInstanceMirror(InstanceMirror mirror) { | 398 void testBoolInstanceMirror(InstanceMirror mirror) { |
386 Expect.equals(const Symbol('bool'), mirror.type.simpleName); | 399 testImplements(mirror.type, #bool); |
387 Expect.isTrue(mirror.hasReflectee); | 400 Expect.isTrue(mirror.hasReflectee); |
388 Expect.equals(true, mirror.reflectee); | 401 Expect.equals(true, mirror.reflectee); |
389 Expect.equals("InstanceMirror on true", mirror.toString()); | 402 Expect.equals("InstanceMirror on true", mirror.toString()); |
390 testDone('testBoolInstanceMirror'); | 403 testDone('testBoolInstanceMirror'); |
391 } | 404 } |
392 | 405 |
393 void testNullInstanceMirror(InstanceMirror mirror) { | 406 void testNullInstanceMirror(InstanceMirror mirror) { |
394 Expect.equals(const Symbol('Null'), mirror.type.simpleName); | 407 testImplements(mirror.type, #Null); |
395 Expect.isTrue(mirror.hasReflectee); | 408 Expect.isTrue(mirror.hasReflectee); |
396 Expect.equals(null, mirror.reflectee); | 409 Expect.equals(null, mirror.reflectee); |
397 Expect.equals("InstanceMirror on null", mirror.toString()); | 410 Expect.equals("InstanceMirror on null", mirror.toString()); |
398 testDone('testNullInstanceMirror'); | 411 testDone('testNullInstanceMirror'); |
399 } | 412 } |
400 | 413 |
401 class MySuperClass { | 414 class MySuperClass { |
402 } | 415 } |
403 | 416 |
404 class MyInterface { | 417 class MyInterface { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 Expect.isTrue(cls.isClass); | 457 Expect.isTrue(cls.isClass); |
445 Expect.equals(const Symbol('MyInterface'), cls.superinterfaces[0].simpleName); | 458 Expect.equals(const Symbol('MyInterface'), cls.superinterfaces[0].simpleName); |
446 Expect.throws(() => cls.metadata, | 459 Expect.throws(() => cls.metadata, |
447 (e) => e is MirroredCompilationError, | 460 (e) => e is MirroredCompilationError, |
448 'Bad metadata'); | 461 'Bad metadata'); |
449 Expect.equals("ClassMirror on 'MyClass'", cls.toString()); | 462 Expect.equals("ClassMirror on 'MyClass'", cls.toString()); |
450 | 463 |
451 // Invoke mirror.method(1000). | 464 // Invoke mirror.method(1000). |
452 mirror.invokeAsync(const Symbol('method'), [ 1000 ]).then( | 465 mirror.invokeAsync(const Symbol('method'), [ 1000 ]).then( |
453 (InstanceMirror retval) { | 466 (InstanceMirror retval) { |
454 Expect.equals(const Symbol('int'), retval.type.simpleName); | 467 testImplements(retval.type, #int); |
455 Expect.isTrue(retval.hasReflectee); | 468 Expect.isTrue(retval.hasReflectee); |
456 Expect.equals(1017, retval.reflectee); | 469 Expect.equals(1017, retval.reflectee); |
457 testDone('testCustomInstanceMirror'); | 470 testDone('testCustomInstanceMirror'); |
458 }); | 471 }); |
459 | 472 |
460 } | 473 } |
461 | 474 |
462 class MyException implements Exception { | 475 class MyException implements Exception { |
463 MyException(this._message); | 476 MyException(this._message); |
464 final String _message; | 477 final String _message; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 // Test that an isolate can reflect on itself. | 548 // Test that an isolate can reflect on itself. |
536 mirrorSystemOf(exit_port.toSendPort()).then(testMirrorSystem); | 549 mirrorSystemOf(exit_port.toSendPort()).then(testMirrorSystem); |
537 | 550 |
538 testIntegerInstanceMirror(reflect(1001)); | 551 testIntegerInstanceMirror(reflect(1001)); |
539 testStringInstanceMirror(reflect('This\nis\na\nString')); | 552 testStringInstanceMirror(reflect('This\nis\na\nString')); |
540 testBoolInstanceMirror(reflect(true)); | 553 testBoolInstanceMirror(reflect(true)); |
541 testNullInstanceMirror(reflect(null)); | 554 testNullInstanceMirror(reflect(null)); |
542 testCustomInstanceMirror(reflect(new MyClass(17))); | 555 testCustomInstanceMirror(reflect(new MyClass(17))); |
543 testMirrorErrors(currentMirrorSystem()); | 556 testMirrorErrors(currentMirrorSystem()); |
544 } | 557 } |
OLD | NEW |