Path: blob/master/test/jdk/java/foreign/TestCondy.java
41145 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @requires ((os.arch == "amd64" | os.arch == "x86_64") & sun.arch.data.model == "64") | os.arch == "aarch64"26* @run testng TestCondy27*/2829import jdk.incubator.foreign.FunctionDescriptor;30import jdk.incubator.foreign.MemoryLayout;31import org.testng.annotations.DataProvider;32import org.testng.annotations.Test;3334import java.lang.constant.Constable;35import java.lang.constant.ConstantDesc;36import java.lang.invoke.MethodHandles;37import java.util.ArrayList;38import java.util.Arrays;39import java.util.List;4041import static jdk.incubator.foreign.CLinker.*;42import static org.testng.Assert.assertEquals;4344public class TestCondy {4546@Test(dataProvider = "constables")47public void testPublicResolve(Constable constable) throws ReflectiveOperationException {48ConstantDesc desc = constable.describeConstable().orElseThrow();49Object result = desc.resolveConstantDesc(MethodHandles.publicLookup());50assertEquals(result, constable);51}525354private static final MemoryLayout[] constants = {55C_CHAR,56C_SHORT,57C_INT,58C_LONG,59C_LONG_LONG,60C_FLOAT,61C_DOUBLE,62C_POINTER63};6465@DataProvider66public static Object[][] constables() {67List<Constable> testValues = new ArrayList<>();6869testValues.addAll(Arrays.asList(constants));7071testValues.add(MemoryLayout.structLayout(constants));72testValues.add(MemoryLayout.unionLayout(constants));7374for (MemoryLayout ml : constants) {75testValues.add(MemoryLayout.sequenceLayout(ml));76testValues.add(MemoryLayout.sequenceLayout(10, ml));77}7879testValues.add(FunctionDescriptor.ofVoid(constants));80testValues.add(FunctionDescriptor.of(C_CHAR, constants));8182return testValues.stream().map(e -> new Object[] { e }).toArray(Object[][]::new);83}84}858687