1 /* 2 * Copyright (c) 2018, 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 import org.testng.annotations.Test; 25 26 import java.nio.file.Path; 27 import static org.testng.Assert.assertEquals; 28 import static org.testng.Assert.assertNotNull; 29 import static org.testng.Assert.assertTrue; 30 31 /* 32 * @test 33 * @bug 8210911 34 * @summary jextract does not handle redundant forward, backward declarations of struct, union, enum properly 35 * @modules jdk.jextract 36 * @build JextractToolRunner 37 * @run testng RedundantDeclsTest 38 */ 39 public class RedundantDeclsTest extends JextractToolRunner { 40 @Test 41 public void redundantDecls() { 42 Path clzPath = getOutputFilePath("RedundentDecls.jar"); 43 checkSuccess(null,"-o", clzPath.toString(), 44 getInputFilePath("redundantDecls.h").toString()); 45 Class<?> headerCls = loadClass("redundantDecls", clzPath); 46 Class<?>[] inners = headerCls.getDeclaredClasses(); 47 assertEquals(inners.length, 4); 48 49 Class<?> pointStruct = findClass(inners, "Point"); 50 assertNotNull(findStructFieldGet(pointStruct, "i")); 51 assertNotNull(findStructFieldGet(pointStruct, "j")); 52 53 Class<?> point3DStruct = findClass(inners, "Point3D"); 54 assertNotNull(findStructFieldGet(point3DStruct, "i")); 55 assertNotNull(findStructFieldGet(point3DStruct, "j")); 56 assertNotNull(findStructFieldGet(point3DStruct, "k")); 57 58 checkIntField(headerCls, "R", 0); 59 checkIntField(headerCls, "G", 1); 60 checkIntField(headerCls, "B", 2); 61 62 checkIntField(headerCls, "C", 0); 63 checkIntField(headerCls, "M", 1); 64 checkIntField(headerCls, "Y", 2); 65 66 Class<?> rgbColor = findClass(inners, "RGBColor"); 67 assertNotNull(rgbColor); 68 assertTrue(rgbColor.isAnnotation()); 69 70 Class<?> cmyColor = findClass(inners, "CMYColor"); 71 assertNotNull(cmyColor); 72 assertTrue(cmyColor.isAnnotation()); 73 74 deleteFile(clzPath); 75 } 76 }