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

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

Issue 10702186: Replaced simpleValue with more general reflectee. hasSimpleValue is retained internally for the sak… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 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
« no previous file with comments | « runtime/lib/mirrors_impl.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 IsolateMirror when 5 // Dart test program for checking implemention of IsolateMirror 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');
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 Expect.isTrue(lib_mirror.url.contains('isolate_mirror_local_test.dart')); 94 Expect.isTrue(lib_mirror.url.contains('isolate_mirror_local_test.dart'));
95 Expect.equals("LibraryMirror on 'isolate_mirror_local_test'", 95 Expect.equals("LibraryMirror on 'isolate_mirror_local_test'",
96 lib_mirror.toString()); 96 lib_mirror.toString());
97 97
98 // Test library invocation by calling function(123). 98 // Test library invocation by calling function(123).
99 Expect.equals(0, global_var); 99 Expect.equals(0, global_var);
100 lib_mirror.invoke('function', [ 123 ]).then( 100 lib_mirror.invoke('function', [ 123 ]).then(
101 (InstanceMirror retval) { 101 (InstanceMirror retval) {
102 Expect.equals(123, global_var); 102 Expect.equals(123, global_var);
103 Expect.equals('Smi', retval.getClass().simpleName); 103 Expect.equals('Smi', retval.getClass().simpleName);
104 Expect.isTrue(retval.hasSimpleValue); 104 Expect.isTrue(retval.hasReflectee);
105 Expect.equals(124, retval.simpleValue); 105 Expect.equals(124, retval.reflectee);
106 testDone('testRootLibraryMirror'); 106 testDone('testRootLibraryMirror');
107 }); 107 });
108 108
109 // Check that the members map is complete. 109 // Check that the members map is complete.
110 List keys = lib_mirror.members().getKeys(); 110 List keys = lib_mirror.members().getKeys();
111 sort(keys); 111 sort(keys);
112 Expect.equals('[' 112 Expect.equals('['
113 'MyClass, ' 113 'MyClass, '
114 'MyException, ' 114 'MyException, '
115 'MyInterface, ' 115 'MyInterface, '
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 Expect.isTrue(mirror.debugName.contains('main')); 261 Expect.isTrue(mirror.debugName.contains('main'));
262 testRootLibraryMirror(mirror.rootLibrary); 262 testRootLibraryMirror(mirror.rootLibrary);
263 testLibrariesMap(mirror.libraries()); 263 testLibrariesMap(mirror.libraries());
264 testDone('testIsolateMirror'); 264 testDone('testIsolateMirror');
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.hasReflectee);
272 Expect.equals(1001, mirror.simpleValue); 272 Expect.equals(1001, mirror.reflectee);
273 Expect.equals("InstanceMirror on <1001>", mirror.toString()); 273 Expect.equals("InstanceMirror on <1001>", mirror.toString());
274 274
275 // Invoke (mirror + mirror). 275 // Invoke (mirror + mirror).
276 mirror.invoke('+', [ mirror ]).then( 276 mirror.invoke('+', [ mirror ]).then(
277 (InstanceMirror retval) { 277 (InstanceMirror retval) {
278 Expect.equals('Smi', retval.getClass().simpleName); 278 Expect.equals('Smi', retval.getClass().simpleName);
279 Expect.isTrue(retval.hasSimpleValue); 279 Expect.isTrue(retval.hasReflectee);
280 Expect.equals(2002, retval.simpleValue); 280 Expect.equals(2002, retval.reflectee);
281 testDone('testIntegerInstanceMirror'); 281 testDone('testIntegerInstanceMirror');
282 }); 282 });
283 } 283 }
284 284
285 void testStringInstanceMirror(InstanceMirror mirror) { 285 void testStringInstanceMirror(InstanceMirror mirror) {
286 // TODO(turnidge): The mirrors api exposes internal vm 286 // TODO(turnidge): The mirrors api exposes internal vm
287 // implementation class names. Is this okay? 287 // implementation class names. Is this okay?
288 Expect.equals('OneByteString', mirror.getClass().simpleName); 288 Expect.equals('OneByteString', mirror.getClass().simpleName);
289 Expect.isTrue(mirror.hasSimpleValue); 289 Expect.isTrue(mirror.hasReflectee);
290 Expect.equals('This\nis\na\nString', mirror.simpleValue); 290 Expect.equals('This\nis\na\nString', mirror.reflectee);
291 Expect.equals("InstanceMirror on <'This\\nis\\na\\nString'>", 291 Expect.equals("InstanceMirror on <'This\\nis\\na\\nString'>",
292 mirror.toString()); 292 mirror.toString());
293 293
294 // Invoke mirror[0]. 294 // Invoke mirror[0].
295 mirror.invoke('[]', [ 0 ]).then( 295 mirror.invoke('[]', [ 0 ]).then(
296 (InstanceMirror retval) { 296 (InstanceMirror retval) {
297 Expect.equals('OneByteString', retval.getClass().simpleName); 297 Expect.equals('OneByteString', retval.getClass().simpleName);
298 Expect.isTrue(retval.hasSimpleValue); 298 Expect.isTrue(retval.hasReflectee);
299 Expect.equals('T', retval.simpleValue); 299 Expect.equals('T', retval.reflectee);
300 testDone('testStringInstanceMirror'); 300 testDone('testStringInstanceMirror');
301 }); 301 });
302 } 302 }
303 303
304 void testBoolInstanceMirror(InstanceMirror mirror) { 304 void testBoolInstanceMirror(InstanceMirror mirror) {
305 Expect.equals('Bool', mirror.getClass().simpleName); 305 Expect.equals('Bool', mirror.getClass().simpleName);
306 Expect.isTrue(mirror.hasSimpleValue); 306 Expect.isTrue(mirror.hasReflectee);
307 Expect.equals(true, mirror.simpleValue); 307 Expect.equals(true, mirror.reflectee);
308 Expect.equals("InstanceMirror on <true>", mirror.toString()); 308 Expect.equals("InstanceMirror on <true>", mirror.toString());
309 testDone('testBoolInstanceMirror'); 309 testDone('testBoolInstanceMirror');
310 } 310 }
311 311
312 void testNullInstanceMirror(InstanceMirror mirror) { 312 void testNullInstanceMirror(InstanceMirror mirror) {
313 // TODO(turnidge): This is returning the wrong class. Fix it. 313 // TODO(turnidge): This is returning the wrong class. Fix it.
314 Expect.equals('Object', mirror.getClass().simpleName); 314 Expect.equals('Object', mirror.getClass().simpleName);
315 Expect.isTrue(mirror.hasSimpleValue); 315 Expect.isTrue(mirror.hasReflectee);
316 Expect.equals(null, mirror.simpleValue); 316 Expect.equals(null, mirror.reflectee);
317 Expect.equals("InstanceMirror on <null>", mirror.toString()); 317 Expect.equals("InstanceMirror on <null>", mirror.toString());
318 testDone('testNullInstanceMirror'); 318 testDone('testNullInstanceMirror');
319 } 319 }
320 320
321 class MySuperClass { 321 class MySuperClass {
322 } 322 }
323 323
324 class MyInterface { 324 class MyInterface {
325 } 325 }
326 326
327 class MyClass extends MySuperClass implements MyInterface { 327 class MyClass extends MySuperClass implements MyInterface {
328 MyClass(this.value) {} 328 MyClass(this.value) {}
329 329
330 final value; 330 final value;
331 331
332 int method(int arg) { 332 int method(int arg) {
333 return arg + value; 333 return arg + value;
334 } 334 }
335 } 335 }
336 336
337 void testCustomInstanceMirror(InstanceMirror mirror) { 337 void testCustomInstanceMirror(InstanceMirror mirror) {
338 Expect.isFalse(mirror.hasSimpleValue); 338 Expect.isTrue(mirror.hasReflectee);
339 bool saw_exception = false; 339 bool saw_exception = false;
340 try { 340 try {
341 // mirror.simpleValue; 341 mirror.reflectee;
342 } catch (MirrorException me) { 342 } catch (MirrorException me) {
343 saw_exception = true; 343 saw_exception = true;
344 } 344 }
345 //Expect.isTrue(saw_exception); 345 Expect.isFalse(saw_exception);
346 Expect.equals("InstanceMirror on instance of 'MyClass'", mirror.toString()); 346 Expect.equals("InstanceMirror on instance of 'MyClass'", mirror.toString());
347 347
348 InterfaceMirror cls = mirror.getClass(); 348 InterfaceMirror cls = mirror.getClass();
349 Expect.isTrue(cls is InterfaceMirror); 349 Expect.isTrue(cls is InterfaceMirror);
350 Expect.equals('MyClass', cls.simpleName); 350 Expect.equals('MyClass', cls.simpleName);
351 Expect.equals('MySuperClass', cls.superclass().simpleName); 351 Expect.equals('MySuperClass', cls.superclass().simpleName);
352 Expect.isTrue(cls.defaultFactory() === null); 352 Expect.isTrue(cls.defaultFactory() === null);
353 Expect.equals('isolate_mirror_local_test', cls.library.simpleName); 353 Expect.equals('isolate_mirror_local_test', cls.library.simpleName);
354 Expect.isTrue(cls.isClass); 354 Expect.isTrue(cls.isClass);
355 Expect.equals('MyInterface', cls.superinterfaces()[0].simpleName); 355 Expect.equals('MyInterface', cls.superinterfaces()[0].simpleName);
356 Expect.equals("InterfaceMirror on 'MyClass'", 356 Expect.equals("InterfaceMirror on 'MyClass'",
357 cls.toString()); 357 cls.toString());
358 358
359 // Invoke mirror.method(1000). 359 // Invoke mirror.method(1000).
360 mirror.invoke('method', [ 1000 ]).then( 360 mirror.invoke('method', [ 1000 ]).then(
361 (InstanceMirror retval) { 361 (InstanceMirror retval) {
362 Expect.equals('Smi', retval.getClass().simpleName); 362 Expect.equals('Smi', retval.getClass().simpleName);
363 Expect.isTrue(retval.hasSimpleValue); 363 Expect.isTrue(retval.hasReflectee);
364 Expect.equals(1017, retval.simpleValue); 364 Expect.equals(1017, retval.reflectee);
365 testDone('testCustomInstanceMirror'); 365 testDone('testCustomInstanceMirror');
366 }); 366 });
367 367
368 } 368 }
369 369
370 class MyException implements Exception { 370 class MyException implements Exception {
371 MyException(this._message); 371 MyException(this._message);
372 final String _message; 372 final String _message;
373 String toString() { return 'MyException: $_message'; } 373 String toString() { return 'MyException: $_message'; }
374 } 374 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 isolateMirrorOf(exit_port.toSendPort()).then(testIsolateMirror);
461 461
462 testIntegerInstanceMirror(mirrorOf(1001)); 462 testIntegerInstanceMirror(mirrorOf(1001));
463 testStringInstanceMirror(mirrorOf('This\nis\na\nString')); 463 testStringInstanceMirror(mirrorOf('This\nis\na\nString'));
464 testBoolInstanceMirror(mirrorOf(true)); 464 testBoolInstanceMirror(mirrorOf(true));
465 testNullInstanceMirror(mirrorOf(null)); 465 testNullInstanceMirror(mirrorOf(null));
466 testCustomInstanceMirror(mirrorOf(new MyClass(17))); 466 testCustomInstanceMirror(mirrorOf(new MyClass(17)));
467 testMirrorErrors(currentIsolateMirror()); 467 testMirrorErrors(currentIsolateMirror());
468 } 468 }
OLDNEW
« no previous file with comments | « runtime/lib/mirrors_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698