TestMetaAccessProvider.java revision 9111:a41fe5ffa839
131695Smsmith/*
231695Smsmith * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
331695Smsmith * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
431695Smsmith *
531695Smsmith * This code is free software; you can redistribute it and/or modify it
631695Smsmith * under the terms of the GNU General Public License version 2 only, as
731695Smsmith * published by the Free Software Foundation.
831695Smsmith *
931695Smsmith * This code is distributed in the hope that it will be useful, but WITHOUT
1031695Smsmith * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1131695Smsmith * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1231695Smsmith * version 2 for more details (a copy is included in the LICENSE file that
1331695Smsmith * accompanied this code).
1431695Smsmith *
1531695Smsmith * You should have received a copy of the GNU General Public License version
1631695Smsmith * 2 along with this work; if not, write to the Free Software Foundation,
1731695Smsmith * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1831695Smsmith *
1931695Smsmith * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2031695Smsmith * or visit www.oracle.com if you need additional information or have any
2131695Smsmith * questions.
2231695Smsmith */
2331695Smsmith
2431695Smsmith/**
2550477Speter * @test
2631695Smsmith * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9") & os.arch != "aarch64"
27235802Sdelphij * @compile TestMetaAccessProvider.java TypeUniverse.java TestMetaAccessProvider.java
2831695Smsmith * @run junit/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI jdk.vm.ci.runtime.test.TestMetaAccessProvider
2931695Smsmith */
3031695Smsmith
3131695Smsmithpackage jdk.vm.ci.runtime.test;
3231695Smsmith
3331695Smsmithimport static jdk.vm.ci.meta.MetaUtil.*;
3468963Sruimport static org.junit.Assert.*;
35104418Sjohan
3672432Sruimport java.lang.reflect.*;
3731695Smsmith
3895124Scharnierimport jdk.vm.ci.meta.*;
3995124Scharnier
4095124Scharnierimport org.junit.*;
4132272Scharnier
42131491Sru/**
43131491Sru * Tests for {@link MetaAccessProvider}.
4431695Smsmith */
4531695Smsmithpublic class TestMetaAccessProvider extends TypeUniverse {
4631695Smsmith
4731695Smsmith    @Test
4879755Sdd    public void lookupJavaTypeTest() {
4931695Smsmith        for (Class<?> c : classes) {
5031695Smsmith            ResolvedJavaType type = metaAccess.lookupJavaType(c);
51235802Sdelphij            assertNotNull(c.toString(), type);
5231695Smsmith            assertEquals(c.toString(), type.getName(), toInternalName(c.getName()));
5331695Smsmith            assertEquals(c.toString(), type.getName(), toInternalName(type.toJavaName()));
5431695Smsmith            assertEquals(c.toString(), c.getName(), type.toClassName());
5579755Sdd            if (!type.isArray()) {
56131491Sru                assertEquals(c.toString(), c.getName(), type.toJavaName());
57131491Sru            }
5831695Smsmith        }
59131491Sru    }
60131491Sru
6131695Smsmith    @Test
6231695Smsmith    public void lookupJavaMethodTest() {
6331695Smsmith        for (Class<?> c : classes) {
6431695Smsmith            for (Method reflect : c.getDeclaredMethods()) {
6531695Smsmith                ResolvedJavaMethod method = metaAccess.lookupJavaMethod(reflect);
6631695Smsmith                assertNotNull(method);
6731695Smsmith                assertTrue(method.getDeclaringClass().equals(metaAccess.lookupJavaType(reflect.getDeclaringClass())));
6879755Sdd            }
6931695Smsmith        }
70104418Sjohan    }
71104418Sjohan
72104418Sjohan    @Test
73107276Sru    public void lookupJavaFieldTest() {
74104418Sjohan        for (Class<?> c : classes) {
75104418Sjohan            for (Field reflect : c.getDeclaredFields()) {
76104418Sjohan                ResolvedJavaField field = metaAccess.lookupJavaField(reflect);
7732272Scharnier                assertNotNull(field);
7832272Scharnier                assertTrue(field.getDeclaringClass().equals(metaAccess.lookupJavaType(reflect.getDeclaringClass())));
7931695Smsmith            }
8095124Scharnier        }
8195124Scharnier    }
8295124Scharnier
8332272Scharnier    @Test
84    public void lookupJavaTypeConstantTest() {
85        for (ConstantValue cv : constants()) {
86            JavaConstant c = cv.value;
87            if (c.getJavaKind() == JavaKind.Object && !c.isNull()) {
88                Object o = cv.boxed;
89                ResolvedJavaType type = metaAccess.lookupJavaType(c);
90                assertNotNull(type);
91                assertTrue(type.equals(metaAccess.lookupJavaType(o.getClass())));
92            } else {
93                assertEquals(metaAccess.lookupJavaType(c), null);
94            }
95        }
96    }
97}
98