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

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

Issue 10825431: More mirrors changes to bring vm mirrors more in line with the (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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 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 #library('isolate_mirror_local_test'); 8 #library('isolate_mirror_local_test');
9 9
10 #import('dart:isolate'); 10 #import('dart:isolate');
(...skipping 24 matching lines...) Expand all
35 int function(int x) { 35 int function(int x) {
36 global_var = x; 36 global_var = x;
37 return x + 1; 37 return x + 1;
38 } 38 }
39 39
40 _stringCompare(String a, String b) => a.compareTo(b); 40 _stringCompare(String a, String b) => a.compareTo(b);
41 sort(list) => list.sort(_stringCompare); 41 sort(list) => list.sort(_stringCompare);
42 42
43 String buildMethodString(MethodMirror func) { 43 String buildMethodString(MethodMirror func) {
44 var result = '${func.simpleName}'; 44 var result = '${func.simpleName}';
45 if (func.isPrivate) {
46 result = '$result private';
47 }
45 if (func.isTopLevel) { 48 if (func.isTopLevel) {
46 result = '$result toplevel'; 49 result = '$result toplevel';
47 } 50 }
48 if (func.isStatic) { 51 if (func.isStatic) {
49 result = '$result static'; 52 result = '$result static';
50 } 53 }
51 if (func.isMethod) { 54 if (func.isAbstract) {
55 result = '$result abstract';
56 }
57 if (func.isRegularMethod) {
52 result = '$result method'; 58 result = '$result method';
53 } 59 }
54 if (func.isGetter) { 60 if (func.isGetter) {
55 result = '$result getter'; 61 result = '$result getter';
56 } 62 }
57 if (func.isSetter) { 63 if (func.isSetter) {
58 result = '$result setter'; 64 result = '$result setter';
59 } 65 }
60 if (func.isConstructor) { 66 if (func.isConstructor) {
61 result = '$result constructor'; 67 result = '$result constructor';
62 } 68 }
63 if (func.isConstConstructor) { 69 if (func.isConstConstructor) {
64 result = '$result const'; 70 result = '$result const';
65 } 71 }
66 if (func.isGenerativeConstructor) { 72 if (func.isGenerativeConstructor) {
67 result = '$result generative'; 73 result = '$result generative';
68 } 74 }
69 if (func.isRedirectingConstructor) { 75 if (func.isRedirectingConstructor) {
70 result = '$result redirecting'; 76 result = '$result redirecting';
71 } 77 }
72 if (func.isFactoryConstructor) { 78 if (func.isFactoryConstructor) {
73 result = '$result factory'; 79 result = '$result factory';
74 } 80 }
75 return result; 81 return result;
76 } 82 }
77 83
78 String buildVariableString(VariableMirror variable) { 84 String buildVariableString(VariableMirror variable) {
79 var result = '${variable.simpleName}'; 85 var result = '${variable.simpleName}';
86 if (variable.isPrivate) {
87 result = '$result private';
88 }
80 if (variable.isTopLevel) { 89 if (variable.isTopLevel) {
81 result = '$result toplevel'; 90 result = '$result toplevel';
82 } 91 }
83 if (variable.isStatic) { 92 if (variable.isStatic) {
84 result = '$result static'; 93 result = '$result static';
85 } 94 }
86 if (variable.isFinal) { 95 if (variable.isFinal) {
87 result = '$result final'; 96 result = '$result final';
88 } 97 }
89 return result; 98 return result;
90 } 99 }
91 100
92 void testRootLibraryMirror(LibraryMirror lib_mirror) { 101 void testRootLibraryMirror(LibraryMirror lib_mirror) {
93 Expect.equals('isolate_mirror_local_test', lib_mirror.simpleName); 102 Expect.equals('isolate_mirror_local_test', lib_mirror.simpleName);
103 Expect.equals('isolate_mirror_local_test', lib_mirror.qualifiedName);
104 Expect.equals(null, lib_mirror.owner);
105 Expect.isFalse(lib_mirror.isPrivate);
94 Expect.isTrue(lib_mirror.url.contains('isolate_mirror_local_test.dart')); 106 Expect.isTrue(lib_mirror.url.contains('isolate_mirror_local_test.dart'));
95 Expect.equals("LibraryMirror on 'isolate_mirror_local_test'", 107 Expect.equals("LibraryMirror on 'isolate_mirror_local_test'",
96 lib_mirror.toString()); 108 lib_mirror.toString());
97 109
98 // Test library invocation by calling function(123). 110 // Test library invocation by calling function(123).
99 Expect.equals(0, global_var); 111 Expect.equals(0, global_var);
100 lib_mirror.invoke('function', [ 123 ]).then( 112 lib_mirror.invoke('function', [ 123 ]).then(
101 (InstanceMirror retval) { 113 (InstanceMirror retval) {
102 Expect.equals(123, global_var); 114 Expect.equals(123, global_var);
103 Expect.equals('int', retval.type.simpleName); 115 Expect.equals('int', retval.type.simpleName);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 'testDone, ' 181 'testDone, '
170 'testIntegerInstanceMirror, ' 182 'testIntegerInstanceMirror, '
171 'testLibrariesMap, ' 183 'testLibrariesMap, '
172 'testMirrorErrors, ' 184 'testMirrorErrors, '
173 'testMirrorSystem, ' 185 'testMirrorSystem, '
174 'testNullInstanceMirror, ' 186 'testNullInstanceMirror, '
175 'testRootLibraryMirror, ' 187 'testRootLibraryMirror, '
176 'testStringInstanceMirror]', 188 'testStringInstanceMirror]',
177 '$keys'); 189 '$keys');
178 190
191 // Check that the getters map is complete.
192 keys = lib_mirror.getters.getKeys();
193 sort(keys);
194 Expect.equals('[myVar]', '$keys');
195
196 // Check that the setters map is complete.
197 keys = lib_mirror.setters.getKeys();
198 sort(keys);
199 Expect.equals('[myVar=]', '$keys');
200
179 // Check that the variables map is complete. 201 // Check that the variables map is complete.
180 keys = lib_mirror.variables.getKeys(); 202 keys = lib_mirror.variables.getKeys();
181 sort(keys); 203 sort(keys);
182 Expect.equals('[' 204 Expect.equals('['
183 'exit_port, ' 205 'exit_port, '
184 'expectedTests, ' 206 'expectedTests, '
185 'final_global_var, ' 207 'final_global_var, '
186 'global_var]', 208 'global_var]',
187 '$keys'); 209 '$keys');
188 210
(...skipping 13 matching lines...) Expand all
202 Expect.equals('myVar= toplevel static setter', buildMethodString(func)); 224 Expect.equals('myVar= toplevel static setter', buildMethodString(func));
203 225
204 func = cls_mirror.members['method']; 226 func = cls_mirror.members['method'];
205 Expect.isTrue(func is MethodMirror); 227 Expect.isTrue(func is MethodMirror);
206 Expect.equals('method method', buildMethodString(func)); 228 Expect.equals('method method', buildMethodString(func));
207 229
208 func = cls_mirror.members['MyClass']; 230 func = cls_mirror.members['MyClass'];
209 Expect.isTrue(func is MethodMirror); 231 Expect.isTrue(func is MethodMirror);
210 Expect.equals('MyClass constructor', buildMethodString(func)); 232 Expect.equals('MyClass constructor', buildMethodString(func));
211 233
234 func = cls_mirror.members['MyClass.named'];
235 Expect.isTrue(func is MethodMirror);
236 Expect.equals('MyClass.named constructor', buildMethodString(func));
237
212 // Test variable mirrors. 238 // Test variable mirrors.
213 VariableMirror variable = lib_mirror.members['global_var']; 239 VariableMirror variable = lib_mirror.members['global_var'];
214 Expect.isTrue(variable is VariableMirror); 240 Expect.isTrue(variable is VariableMirror);
215 Expect.equals('global_var toplevel static', buildVariableString(variable)); 241 Expect.equals('global_var toplevel static', buildVariableString(variable));
216 242
217 variable = lib_mirror.members['final_global_var']; 243 variable = lib_mirror.members['final_global_var'];
218 Expect.isTrue(variable is VariableMirror); 244 Expect.isTrue(variable is VariableMirror);
219 Expect.equals('final_global_var toplevel static final', 245 Expect.equals('final_global_var toplevel static final',
220 buildVariableString(variable)); 246 buildVariableString(variable));
221 247
222 variable = cls_mirror.members['value']; 248 variable = cls_mirror.members['value'];
223 Expect.isTrue(variable is VariableMirror); 249 Expect.isTrue(variable is VariableMirror);
224 Expect.equals('value final', buildVariableString(variable)); 250 Expect.equals('value final', buildVariableString(variable));
225 } 251 }
226 252
227 void testLibrariesMap(Map libraries) { 253 void testLibrariesMap(Map libraries) {
228 // Just look for a couple of well-known libs. 254 // Just look for a couple of well-known libs.
229 LibraryMirror core_lib = libraries['dart:core']; 255 LibraryMirror core_lib = libraries['dart:core'];
230 Expect.isTrue(core_lib is LibraryMirror); 256 Expect.isTrue(core_lib is LibraryMirror);
231 257
232 LibraryMirror mirror_lib = libraries['dart:mirrors']; 258 LibraryMirror mirror_lib = libraries['dart:mirrors'];
233 Expect.isTrue(mirror_lib is LibraryMirror); 259 Expect.isTrue(mirror_lib is LibraryMirror);
234 260
235 // Lookup an interface from a library and make sure it is sane. 261 // Lookup an interface from a library and make sure it is sane.
236 ClassMirror list_intf = core_lib.members['List']; 262 ClassMirror list_intf = core_lib.members['List'];
237 Expect.isTrue(list_intf is ClassMirror); 263 Expect.isTrue(list_intf is ClassMirror);
238 Expect.equals('List', list_intf.simpleName); 264 Expect.equals('List', list_intf.simpleName);
265 Expect.equals('dart:core.List', list_intf.qualifiedName);
266 Expect.isFalse(list_intf.isPrivate);
239 Expect.equals('Object', list_intf.superclass.simpleName); 267 Expect.equals('Object', list_intf.superclass.simpleName);
240 Expect.equals('ListFactory', list_intf.defaultFactory.simpleName); 268 Expect.equals('ListFactory', list_intf.defaultFactory.simpleName);
241 Expect.equals('dart:core', list_intf.library.simpleName); 269 Expect.equals('dart:core', list_intf.owner.simpleName);
242 Expect.isFalse(list_intf.isClass); 270 Expect.isFalse(list_intf.isClass);
243 Expect.equals('Collection', list_intf.superinterfaces[0].simpleName); 271 Expect.equals('Collection', list_intf.superinterfaces[0].simpleName);
244 Expect.equals("ClassMirror on 'List'", list_intf.toString()); 272 Expect.equals("ClassMirror on 'List'", list_intf.toString());
245 273
246 // Lookup a class from a library and make sure it is sane. 274 // Lookup a class from a library and make sure it is sane.
247 ClassMirror oom_cls = core_lib.members['OutOfMemoryException']; 275 ClassMirror oom_cls = core_lib.members['OutOfMemoryException'];
248 Expect.isTrue(oom_cls is ClassMirror); 276 Expect.isTrue(oom_cls is ClassMirror);
249 Expect.equals('OutOfMemoryException', oom_cls.simpleName); 277 Expect.equals('OutOfMemoryException', oom_cls.simpleName);
278 Expect.equals('dart:core.OutOfMemoryException', oom_cls.qualifiedName);
279 Expect.isFalse(oom_cls.isPrivate);
250 Expect.equals('Object', oom_cls.superclass.simpleName); 280 Expect.equals('Object', oom_cls.superclass.simpleName);
251 Expect.isTrue(oom_cls.defaultFactory === null); 281 Expect.isTrue(oom_cls.defaultFactory === null);
252 Expect.equals('dart:core', oom_cls.library.simpleName); 282 Expect.equals('dart:core', oom_cls.owner.simpleName);
253 Expect.isTrue(oom_cls.isClass); 283 Expect.isTrue(oom_cls.isClass);
254 Expect.equals('Exception', oom_cls.superinterfaces[0].simpleName); 284 Expect.equals('Exception', oom_cls.superinterfaces[0].simpleName);
255 Expect.equals("ClassMirror on 'OutOfMemoryException'", 285 Expect.equals("ClassMirror on 'OutOfMemoryException'",
256 oom_cls.toString()); 286 oom_cls.toString());
257 testDone('testLibrariesMap'); 287 testDone('testLibrariesMap');
258 } 288 }
259 289
260 void testMirrorSystem(MirrorSystem mirrors) { 290 void testMirrorSystem(MirrorSystem mirrors) {
261 Expect.isTrue(mirrors.isolate.debugName.contains('main')); 291 Expect.isTrue(mirrors.isolate.debugName.contains('main'));
262 testRootLibraryMirror(mirrors.isolate.rootLibrary); 292 testRootLibraryMirror(mirrors.isolate.rootLibrary);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 } 347 }
318 348
319 class MySuperClass { 349 class MySuperClass {
320 } 350 }
321 351
322 class MyInterface { 352 class MyInterface {
323 } 353 }
324 354
325 class MyClass extends MySuperClass implements MyInterface { 355 class MyClass extends MySuperClass implements MyInterface {
326 MyClass(this.value) {} 356 MyClass(this.value) {}
357 MyClass.named() {}
327 358
328 final value; 359 final value;
329 360
330 int method(int arg) { 361 int method(int arg) {
331 return arg + value; 362 return arg + value;
332 } 363 }
333 } 364 }
334 365
335 void testCustomInstanceMirror(InstanceMirror mirror) { 366 void testCustomInstanceMirror(InstanceMirror mirror) {
336 Expect.isTrue(mirror.hasReflectee); 367 Expect.isTrue(mirror.hasReflectee);
337 bool saw_exception = false; 368 bool saw_exception = false;
338 try { 369 try {
339 mirror.reflectee; 370 mirror.reflectee;
340 } catch (MirrorException me) { 371 } catch (MirrorException me) {
341 saw_exception = true; 372 saw_exception = true;
342 } 373 }
343 Expect.isFalse(saw_exception); 374 Expect.isFalse(saw_exception);
344 Expect.equals("InstanceMirror on instance of 'MyClass'", mirror.toString()); 375 Expect.equals("InstanceMirror on instance of 'MyClass'", mirror.toString());
345 376
346 ClassMirror cls = mirror.type; 377 ClassMirror cls = mirror.type;
347 Expect.isTrue(cls is ClassMirror); 378 Expect.isTrue(cls is ClassMirror);
348 Expect.equals('MyClass', cls.simpleName); 379 Expect.equals('MyClass', cls.simpleName);
349 Expect.equals('MySuperClass', cls.superclass.simpleName); 380 Expect.equals('MySuperClass', cls.superclass.simpleName);
350 Expect.isTrue(cls.defaultFactory === null); 381 Expect.isTrue(cls.defaultFactory === null);
351 Expect.equals('isolate_mirror_local_test', cls.library.simpleName); 382 Expect.equals('isolate_mirror_local_test', cls.owner.simpleName);
352 Expect.isTrue(cls.isClass); 383 Expect.isTrue(cls.isClass);
353 Expect.equals('MyInterface', cls.superinterfaces[0].simpleName); 384 Expect.equals('MyInterface', cls.superinterfaces[0].simpleName);
354 Expect.equals("ClassMirror on 'MyClass'", 385 Expect.equals("ClassMirror on 'MyClass'",
355 cls.toString()); 386 cls.toString());
356 387
357 // Invoke mirror.method(1000). 388 // Invoke mirror.method(1000).
358 mirror.invoke('method', [ 1000 ]).then( 389 mirror.invoke('method', [ 1000 ]).then(
359 (InstanceMirror retval) { 390 (InstanceMirror retval) {
360 Expect.equals('int', retval.type.simpleName); 391 Expect.equals('int', retval.type.simpleName);
361 Expect.isTrue(retval.hasReflectee); 392 Expect.isTrue(retval.hasReflectee);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 // Test that an isolate can reflect on itself. 488 // Test that an isolate can reflect on itself.
458 mirrorSystemOf(exit_port.toSendPort()).then(testMirrorSystem); 489 mirrorSystemOf(exit_port.toSendPort()).then(testMirrorSystem);
459 490
460 testIntegerInstanceMirror(reflect(1001)); 491 testIntegerInstanceMirror(reflect(1001));
461 testStringInstanceMirror(reflect('This\nis\na\nString')); 492 testStringInstanceMirror(reflect('This\nis\na\nString'));
462 testBoolInstanceMirror(reflect(true)); 493 testBoolInstanceMirror(reflect(true));
463 testNullInstanceMirror(reflect(null)); 494 testNullInstanceMirror(reflect(null));
464 testCustomInstanceMirror(reflect(new MyClass(17))); 495 testCustomInstanceMirror(reflect(new MyClass(17)));
465 testMirrorErrors(currentMirrorSystem()); 496 testMirrorErrors(currentMirrorSystem());
466 } 497 }
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