Mercurial > hg > truffle
comparison graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/TestMetaAccessProvider.java @ 21663:381ab4105afe
moved com.oracle.graal.java.test to com.oracle.jvmci.runtime.test
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 02 Jun 2015 15:15:58 +0200 |
parents | graal/com.oracle.graal.java.test/src/com/oracle/graal/java/test/TestMetaAccessProvider.java@48c1ebd24120 |
children |
comparison
equal
deleted
inserted
replaced
21662:b45e0f791465 | 21663:381ab4105afe |
---|---|
1 /* | |
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 package com.oracle.jvmci.runtime.test; | |
24 | |
25 import static com.oracle.jvmci.meta.MetaUtil.*; | |
26 import static org.junit.Assert.*; | |
27 | |
28 import java.lang.reflect.*; | |
29 | |
30 import org.junit.*; | |
31 | |
32 import com.oracle.jvmci.meta.*; | |
33 | |
34 /** | |
35 * Tests for {@link MetaAccessProvider}. | |
36 */ | |
37 public class TestMetaAccessProvider extends TypeUniverse { | |
38 | |
39 @Test | |
40 public void lookupJavaTypeTest() { | |
41 for (Class<?> c : classes) { | |
42 ResolvedJavaType type = metaAccess.lookupJavaType(c); | |
43 assertNotNull(type); | |
44 assertEquals(c.getModifiers(), type.getModifiers()); | |
45 if (!type.isArray()) { | |
46 assertEquals(type.getName(), toInternalName(c.getName())); | |
47 assertEquals(type.toJavaName(), c.getName()); | |
48 } | |
49 } | |
50 } | |
51 | |
52 @Test | |
53 public void lookupJavaMethodTest() { | |
54 for (Class<?> c : classes) { | |
55 for (Method reflect : c.getDeclaredMethods()) { | |
56 ResolvedJavaMethod method = metaAccess.lookupJavaMethod(reflect); | |
57 assertNotNull(method); | |
58 int expected = reflect.getModifiers() & Modifier.methodModifiers(); | |
59 int actual = method.getModifiers(); | |
60 assertEquals(String.format("%s: 0x%x != 0x%x", reflect, expected, actual), expected, actual); | |
61 assertTrue(method.getDeclaringClass().equals(metaAccess.lookupJavaType(reflect.getDeclaringClass()))); | |
62 } | |
63 } | |
64 } | |
65 | |
66 @Test | |
67 public void lookupJavaFieldTest() { | |
68 for (Class<?> c : classes) { | |
69 for (Field reflect : c.getDeclaredFields()) { | |
70 ResolvedJavaField field = metaAccess.lookupJavaField(reflect); | |
71 assertNotNull(field); | |
72 int expected = reflect.getModifiers(); | |
73 int actual = field.getModifiers(); | |
74 assertEquals(String.format("%s: 0x%x != 0x%x", reflect, expected, actual), expected, actual); | |
75 assertTrue(field.getDeclaringClass().equals(metaAccess.lookupJavaType(reflect.getDeclaringClass()))); | |
76 } | |
77 } | |
78 } | |
79 | |
80 @Test | |
81 public void lookupJavaTypeConstantTest() { | |
82 for (ConstantValue cv : constants()) { | |
83 JavaConstant c = cv.value; | |
84 if (c.getKind() == Kind.Object && !c.isNull()) { | |
85 Object o = cv.boxed; | |
86 ResolvedJavaType type = metaAccess.lookupJavaType(c); | |
87 assertNotNull(type); | |
88 assertTrue(type.equals(metaAccess.lookupJavaType(o.getClass()))); | |
89 } else { | |
90 assertEquals(metaAccess.lookupJavaType(c), null); | |
91 } | |
92 } | |
93 } | |
94 } |