1 /* 2 * Copyright (c) 2020, 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 * @build JextractApiTestBase 27 * @run testng/othervm --enable-native-access=jdk.incubator.jextract Test8239490 28 */ 29 30 import jdk.incubator.jextract.Declaration; 31 import jdk.incubator.jextract.Type; 32 import org.testng.annotations.Test; 33 34 import static org.testng.Assert.*; 35 36 public class Test8239490 extends JextractApiTestBase { 37 @Test 38 public void test8239490() { 39 Declaration.Scoped d = parse("Test8239490.h"); 40 // check Foo 41 String[] fooBitfieldNames = { "a", "b", "c" }; 42 int[] fooBitfieldSizes = { 1, 1, 30 }; 43 Declaration.Scoped structFoo = checkStruct(d, "Foo", ""); 44 Declaration.Scoped bitfieldsFoo = checkBitfields(structFoo, "", "a", "b", "c"); 45 Type intType = ((Declaration.Variable)bitfieldsFoo.members().get(0)).type(); 46 for (int i = 0 ; i < fooBitfieldNames.length ; i++) { 47 checkBitField(bitfieldsFoo, fooBitfieldNames[i], intType, fooBitfieldSizes[i]); 48 } 49 // check Bar 50 String[] barBitfieldNames = { "x", "y" }; 51 int[] barBitfieldSizes = { 1, 31 }; 52 Declaration.Scoped structBar = checkStruct(d, "Bar", "", "z"); 53 Declaration.Scoped bitfieldsBar = checkBitfields(structBar, "", "x", "y"); 54 for (int i = 0 ; i < barBitfieldNames.length ; i++) { 55 checkBitField(bitfieldsBar, barBitfieldNames[i], intType, barBitfieldSizes[i]); 56 } 57 checkField(structBar, "z", Type.array(1, Type.declared(structFoo))); 58 59 // check Baz 60 String[] bazBitfieldNames = { "x", "y" }; 61 int[] bazBitfieldSizes = { 1, 63 }; 62 Declaration.Scoped structBaz = checkStruct(d, "Baz", "", "z"); 63 Declaration.Scoped bitfieldsBaz = checkBitfields(structBaz, "", "x", "y"); 64 Type longType = ((Declaration.Variable)bitfieldsBaz.members().get(0)).type(); 65 for (int i = 0 ; i < bazBitfieldNames.length ; i++) { 66 checkBitField(bitfieldsBaz, bazBitfieldNames[i], longType, bazBitfieldSizes[i]); 67 } 68 checkField(structBaz, "z", Type.array(1, Type.declared(structBar))); 69 } 70 }