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 import java.lang.reflect.Method;
25 import java.nio.file.Path;
26 import org.testng.annotations.Test;
27 import static org.testng.Assert.assertNull;
28 import static org.testng.Assert.assertNotNull;
29 import static org.testng.Assert.assertTrue;
30 
31 /*
32  * @test
33  * @modules jdk.incubator.jextract
34  * @library /test/lib
35  * @build JextractToolRunner
36  * @bug 8245767
37  * @summary jextract crashes with typedef on a opaque struct or union
38  * @run testng/othervm --enable-native-access=jdk.incubator.jextract Test8245767
39  */
40 public class Test8245767 extends JextractToolRunner {
41     @Test
42     public void testTypedefs() {
43         Path test8245767Output = getOutputFilePath("test8245767_gen");
44         Path test8245767H = getInputFilePath("test8245767.h");
45         run("-d", test8245767Output.toString(), test8245767H.toString()).checkSuccess();
46         try(Loader loader = classLoader(test8245767Output)) {
47             Class<?> cls = loader.loadClass("test8245767_h");
48             assertNotNull(cls);
49 
50             // class should be generated for typedef on opaque struct
51             Class<?> fooCls = loader.loadClass("Foo");
52             assertNotNull(fooCls);
53 
54             // check Point_t
55             Class<?> point_tCls = loader.loadClass("Point_t");
56             assertNotNull(point_tCls);
57 
58             // check Point
59             Class<?> pointCls = loader.loadClass("Point");
60             assertNotNull(pointCls);
61             assertTrue(pointCls.isAssignableFrom(point_tCls));
62         } finally {
63             deleteDir(test8245767Output);
64         }
65     }
66 }