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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 testLibrariesMap(mirrors.libraries); | 343 testLibrariesMap(mirrors.libraries); |
342 Expect.equals(const Symbol('void'), mirrors.voidType.simpleName); | 344 Expect.equals(const Symbol('void'), mirrors.voidType.simpleName); |
343 Expect.equals(const Symbol('dynamic'), mirrors.dynamicType.simpleName); | 345 Expect.equals(const Symbol('dynamic'), mirrors.dynamicType.simpleName); |
344 Expect.isTrue(mirrors.voidType is TypeMirror); | 346 Expect.isTrue(mirrors.voidType is TypeMirror); |
345 Expect.isTrue(mirrors.dynamicType is TypeMirror); | 347 Expect.isTrue(mirrors.dynamicType is TypeMirror); |
346 Expect.isFalse(mirrors.voidType is ClassMirror); | 348 Expect.isFalse(mirrors.voidType is ClassMirror); |
347 Expect.isFalse(mirrors.dynamicType is ClassMirror); | 349 Expect.isFalse(mirrors.dynamicType is ClassMirror); |
348 testDone('testMirrorSystem'); | 350 testDone('testMirrorSystem'); |
349 } | 351 } |
350 | 352 |
| 353 void testImplements(klass, intfName) { |
| 354 bool foundInterface = false; |
| 355 for (ClassMirror cm = klass; cm != null; cm = cm.superclass) { |
| 356 if (cm.simpleName == intfName) foundInterface = true; |
| 357 cm.superinterfaces.forEach((intf) { |
| 358 if (intf.simpleName == intfName) foundInterface = true; |
| 359 }); |
| 360 } |
| 361 Expect.isTrue(foundInterface, '$klass should implement $intfName'); |
| 362 } |
| 363 |
351 void testIntegerInstanceMirror(InstanceMirror mirror) { | 364 void testIntegerInstanceMirror(InstanceMirror mirror) { |
352 Expect.equals(const Symbol('int'), mirror.type.simpleName); | 365 testImplements(mirror.type, #int); |
353 Expect.isTrue(mirror.hasReflectee); | 366 Expect.isTrue(mirror.hasReflectee); |
354 Expect.equals(1001, mirror.reflectee); | 367 Expect.equals(1001, mirror.reflectee); |
355 Expect.equals("InstanceMirror on 1001", mirror.toString()); | 368 Expect.equals("InstanceMirror on 1001", mirror.toString()); |
356 | 369 |
357 // Invoke (mirror + mirror). | 370 // Invoke (mirror + mirror). |
358 mirror.invokeAsync(const Symbol('+'), [ mirror ]).then( | 371 mirror.invokeAsync(const Symbol('+'), [ mirror ]).then( |
359 (InstanceMirror retval) { | 372 (InstanceMirror retval) { |
360 Expect.equals(const Symbol('int'), retval.type.simpleName); | 373 testImplements(retval.type, #int); |
361 Expect.isTrue(retval.hasReflectee); | 374 Expect.isTrue(retval.hasReflectee); |
362 Expect.equals(2002, retval.reflectee); | 375 Expect.equals(2002, retval.reflectee); |
363 testDone('testIntegerInstanceMirror'); | 376 testDone('testIntegerInstanceMirror'); |
364 }); | 377 }); |
365 } | 378 } |
366 | 379 |
367 void testStringInstanceMirror(InstanceMirror mirror) { | 380 void testStringInstanceMirror(InstanceMirror mirror) { |
368 Expect.equals(const Symbol('String'), mirror.type.simpleName); | 381 testImplements(mirror.type, #String); |
369 Expect.isTrue(mirror.hasReflectee); | 382 Expect.isTrue(mirror.hasReflectee); |
370 Expect.equals('This\nis\na\nString', mirror.reflectee); | 383 Expect.equals('This\nis\na\nString', mirror.reflectee); |
371 Expect.equals('InstanceMirror on "This\\nis\\na\\nString"', | 384 Expect.equals('InstanceMirror on "This\\nis\\na\\nString"', |
372 mirror.toString()); | 385 mirror.toString()); |
373 | 386 |
374 // Invoke mirror[0]. | 387 // Invoke mirror[0]. |
375 mirror.invokeAsync(const Symbol('[]'), [ 0 ]).then( | 388 mirror.invokeAsync(const Symbol('[]'), [ 0 ]).then( |
376 (InstanceMirror retval) { | 389 (InstanceMirror retval) { |
377 Expect.equals(const Symbol('String'), retval.type.simpleName); | 390 testImplements(retval.type, #String); |
378 Expect.isTrue(retval.hasReflectee); | 391 Expect.isTrue(retval.hasReflectee); |
379 Expect.equals('T', retval.reflectee); | 392 Expect.equals('T', retval.reflectee); |
380 testDone('testStringInstanceMirror'); | 393 testDone('testStringInstanceMirror'); |
381 }); | 394 }); |
382 } | 395 } |
383 | 396 |
384 void testBoolInstanceMirror(InstanceMirror mirror) { | 397 void testBoolInstanceMirror(InstanceMirror mirror) { |
385 Expect.equals(const Symbol('bool'), mirror.type.simpleName); | 398 testImplements(mirror.type, #bool); |
386 Expect.isTrue(mirror.hasReflectee); | 399 Expect.isTrue(mirror.hasReflectee); |
387 Expect.equals(true, mirror.reflectee); | 400 Expect.equals(true, mirror.reflectee); |
388 Expect.equals("InstanceMirror on true", mirror.toString()); | 401 Expect.equals("InstanceMirror on true", mirror.toString()); |
389 testDone('testBoolInstanceMirror'); | 402 testDone('testBoolInstanceMirror'); |
390 } | 403 } |
391 | 404 |
392 void testNullInstanceMirror(InstanceMirror mirror) { | 405 void testNullInstanceMirror(InstanceMirror mirror) { |
393 Expect.equals(const Symbol('Null'), mirror.type.simpleName); | 406 testImplements(mirror.type, #Null); |
394 Expect.isTrue(mirror.hasReflectee); | 407 Expect.isTrue(mirror.hasReflectee); |
395 Expect.equals(null, mirror.reflectee); | 408 Expect.equals(null, mirror.reflectee); |
396 Expect.equals("InstanceMirror on null", mirror.toString()); | 409 Expect.equals("InstanceMirror on null", mirror.toString()); |
397 testDone('testNullInstanceMirror'); | 410 testDone('testNullInstanceMirror'); |
398 } | 411 } |
399 | 412 |
400 class MySuperClass { | 413 class MySuperClass { |
401 } | 414 } |
402 | 415 |
403 class MyInterface { | 416 class MyInterface { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 Expect.isTrue(cls.isClass); | 456 Expect.isTrue(cls.isClass); |
444 Expect.equals(const Symbol('MyInterface'), cls.superinterfaces[0].simpleName); | 457 Expect.equals(const Symbol('MyInterface'), cls.superinterfaces[0].simpleName); |
445 Expect.throws(() => cls.metadata, | 458 Expect.throws(() => cls.metadata, |
446 (e) => e is MirroredCompilationError, | 459 (e) => e is MirroredCompilationError, |
447 'Bad metadata'); | 460 'Bad metadata'); |
448 Expect.equals("ClassMirror on 'MyClass'", cls.toString()); | 461 Expect.equals("ClassMirror on 'MyClass'", cls.toString()); |
449 | 462 |
450 // Invoke mirror.method(1000). | 463 // Invoke mirror.method(1000). |
451 mirror.invokeAsync(const Symbol('method'), [ 1000 ]).then( | 464 mirror.invokeAsync(const Symbol('method'), [ 1000 ]).then( |
452 (InstanceMirror retval) { | 465 (InstanceMirror retval) { |
453 Expect.equals(const Symbol('int'), retval.type.simpleName); | 466 testImplements(retval.type, #int); |
454 Expect.isTrue(retval.hasReflectee); | 467 Expect.isTrue(retval.hasReflectee); |
455 Expect.equals(1017, retval.reflectee); | 468 Expect.equals(1017, retval.reflectee); |
456 testDone('testCustomInstanceMirror'); | 469 testDone('testCustomInstanceMirror'); |
457 }); | 470 }); |
458 | 471 |
459 } | 472 } |
460 | 473 |
461 class MyException implements Exception { | 474 class MyException implements Exception { |
462 MyException(this._message); | 475 MyException(this._message); |
463 final String _message; | 476 final String _message; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 // Test that an isolate can reflect on itself. | 547 // Test that an isolate can reflect on itself. |
535 mirrorSystemOf(exit_port.toSendPort()).then(testMirrorSystem); | 548 mirrorSystemOf(exit_port.toSendPort()).then(testMirrorSystem); |
536 | 549 |
537 testIntegerInstanceMirror(reflect(1001)); | 550 testIntegerInstanceMirror(reflect(1001)); |
538 testStringInstanceMirror(reflect('This\nis\na\nString')); | 551 testStringInstanceMirror(reflect('This\nis\na\nString')); |
539 testBoolInstanceMirror(reflect(true)); | 552 testBoolInstanceMirror(reflect(true)); |
540 testNullInstanceMirror(reflect(null)); | 553 testNullInstanceMirror(reflect(null)); |
541 testCustomInstanceMirror(reflect(new MyClass(17))); | 554 testCustomInstanceMirror(reflect(new MyClass(17))); |
542 testMirrorErrors(currentMirrorSystem()); | 555 testMirrorErrors(currentMirrorSystem()); |
543 } | 556 } |
OLD | NEW |