Path: blob/master/test/jdk/java/foreign/TestLayoutEquality.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*22*/2324/*25* @test26* @modules jdk.incubator.foreign/jdk.internal.foreign27*28* @run testng TestLayoutEquality29*/3031import jdk.incubator.foreign.MemoryLayout;32import jdk.incubator.foreign.ValueLayout;33import jdk.internal.foreign.PlatformLayouts;34import org.testng.annotations.DataProvider;35import org.testng.annotations.Test;3637import java.lang.reflect.Field;38import java.util.ArrayList;39import java.util.List;4041import static org.testng.Assert.*;4243public class TestLayoutEquality {4445@Test(dataProvider = "layoutConstants")46public void testReconstructedEquality(ValueLayout layout) {47ValueLayout newLayout = MemoryLayout.valueLayout(layout.bitSize(), layout.order());4849// properties should be equal50assertEquals(newLayout.bitSize(), layout.bitSize());51assertEquals(newLayout.bitAlignment(), layout.bitAlignment());52assertEquals(newLayout.name(), layout.name());53assertEquals(newLayout.attributes().toArray().length, 0);54assertEquals(layout.attributes().toArray().length, 1);5556// but equals should return false, because one is a ValueLayout with a CLinker kind57assertNotEquals(newLayout, layout);58}5960@DataProvider61public static Object[][] layoutConstants() throws ReflectiveOperationException {62List<ValueLayout> testValues = new ArrayList<>();6364addLayoutConstants(testValues, PlatformLayouts.SysV.class);65addLayoutConstants(testValues, PlatformLayouts.Win64.class);66addLayoutConstants(testValues, PlatformLayouts.AArch64.class);6768return testValues.stream().map(e -> new Object[]{ e }).toArray(Object[][]::new);69}7071private static void addLayoutConstants(List<ValueLayout> testValues, Class<?> cls) throws ReflectiveOperationException {72for (Field f : cls.getFields()) {73if (f.getName().startsWith("C_"))74testValues.add((ValueLayout) f.get(null));75}76}7778}798081