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 * @library .. 27 * @modules jdk.jextract 28 * @build IncompleteArrayTest 29 * 30 * @run testng/othervm IncompleteArrayTest 31 */ 32 33 import org.testng.annotations.Test; 34 import static org.testng.Assert.*; 35 36 import java.nio.file.Path; 37 38 public class IncompleteArrayTest extends JextractToolRunner { 39 40 static final boolean IS_WINDOWS = System.getProperty("os.name").startsWith("Windows"); 41 42 @Test 43 public void testIncompleteArraySimple() { 44 Path jar = getOutputFilePath("incompleteArray1.jar"); 45 Path input = getInputFilePath("incompleteArray1.h"); 46 run("-o", jar.toString(), 47 input.toString()) 48 .checkSuccess() 49 .checkMatchesOutput(".*WARNING: can not compute layout for type .+" + 50 " with flexible array member\\. Emitting undefined layout reference\\..*"); 51 try (Loader loader = classLoader(jar)) { 52 // check if we can still load the class without NoClassDefFound 53 assertNotNull(loader.loadClass(headerInterfaceName("incompleteArray1.h"))); 54 } finally { 55 deleteFile(jar); 56 } 57 } 58 59 @Test 60 public void testIncompleteArrayNested() { 61 Path jar = getOutputFilePath("incompleteArray2.jar"); 62 Path input = getInputFilePath("incompleteArray2.h"); 63 run("-o", jar.toString(), 64 input.toString()) 65 .checkSuccess() 66 .checkMatchesOutput(".*WARNING: can not compute layout for type .+" + 67 " with flexible array member\\. Emitting undefined layout reference\\..*"); 68 try (Loader loader = classLoader(jar)) { 69 assertNotNull(loader.loadClass(headerInterfaceName("incompleteArray2.h"))); 70 } finally { 71 deleteFile(jar); 72 } 73 } 74 75 @Test 76 public void testIncompleteArrayUnion() { 77 if (IS_WINDOWS) { // MSVC extension 78 Path jar = getOutputFilePath("incompleteArray3.jar"); 79 Path input = getInputFilePath("incompleteArray3.h"); 80 run("-o", jar.toString(), 81 input.toString()) 82 .checkSuccess() 83 .checkMatchesOutput(".*WARNING: can not compute layout for type .+" + 84 " with flexible array member\\. Emitting undefined layout reference\\..*"); 85 try (Loader loader = classLoader(jar)) { 86 assertNotNull(loader.loadClass(headerInterfaceName("incompleteArray3.h"))); 87 } finally { 88 deleteFile(jar); 89 } 90 } 91 } 92 93 }