1 /* 2 * Copyright (c) 2019, 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 24 /* 25 * @test 26 * @run testng TestLayoutConstants 27 */ 28 29 import jdk.incubator.foreign.MemoryLayouts; 30 import jdk.incubator.foreign.MemoryLayout; 31 32 import java.lang.invoke.MethodHandles; 33 34 import org.testng.annotations.*; 35 import static org.testng.Assert.*; 36 37 public class TestLayoutConstants { 38 39 @Test(dataProvider = "layouts") 40 public void testDescribeResolve(MemoryLayout expected) { 41 try { 42 MemoryLayout actual = expected.describeConstable().get() 43 .resolveConstantDesc(MethodHandles.lookup()); 44 assertEquals(actual, expected); 45 } catch (ReflectiveOperationException ex) { 46 throw new AssertionError(ex); 47 } 48 } 49 50 @DataProvider(name = "layouts") 51 public Object[][] createLayouts() { 52 return new Object[][] { 53 //padding 54 { MemoryLayouts.PAD_32 }, 55 { MemoryLayout.ofSequence(MemoryLayouts.PAD_32) }, 56 { MemoryLayout.ofSequence(5, MemoryLayouts.PAD_32) }, 57 { MemoryLayout.ofStruct(MemoryLayouts.PAD_32, MemoryLayouts.PAD_32) }, 58 { MemoryLayout.ofUnion(MemoryLayouts.PAD_32, MemoryLayouts.PAD_32) }, 59 //values, big endian 60 { MemoryLayouts.BITS_32_BE }, 61 { MemoryLayout.ofStruct( 62 MemoryLayouts.BITS_32_BE, 63 MemoryLayouts.BITS_32_BE) }, 64 { MemoryLayout.ofUnion( 65 MemoryLayouts.BITS_32_BE, 66 MemoryLayouts.BITS_32_BE) }, 67 //values, little endian 68 { MemoryLayouts.BITS_32_LE }, 69 { MemoryLayout.ofStruct( 70 MemoryLayouts.BITS_32_LE, 71 MemoryLayouts.BITS_32_LE) }, 72 { MemoryLayout.ofUnion( 73 MemoryLayouts.BITS_32_LE, 74 MemoryLayouts.BITS_32_LE) }, 75 //deeply nested 76 { MemoryLayout.ofStruct( 77 MemoryLayouts.PAD_16, 78 MemoryLayout.ofStruct( 79 MemoryLayouts.PAD_8, 80 MemoryLayouts.BITS_32_BE)) }, 81 { MemoryLayout.ofUnion( 82 MemoryLayouts.PAD_16, 83 MemoryLayout.ofStruct( 84 MemoryLayouts.PAD_8, 85 MemoryLayouts.BITS_32_BE)) }, 86 { MemoryLayout.ofSequence( 87 MemoryLayout.ofStruct( 88 MemoryLayouts.PAD_8, 89 MemoryLayouts.BITS_32_BE)) }, 90 { MemoryLayout.ofSequence(5, 91 MemoryLayout.ofStruct( 92 MemoryLayouts.PAD_8, 93 MemoryLayouts.BITS_32_BE)) }, 94 }; 95 } 96 }