1 /*
  2  * Copyright (c) 2021, 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 jdk.incubator.foreign.MemoryAddress;
 25 import jdk.incubator.foreign.MemorySegment;
 26 import org.testng.annotations.Test;
 27 import test.jextract.test8259473.*;
 28 import static org.testng.Assert.assertEquals;
 29 import static org.testng.Assert.assertTrue;
 30 import static test.jextract.test8259473.test8259473_h.*;
 31 
 32 /*
 33  * @test id=classes
 34  * @bug 8259473
 35  * @summary jextract generated code should throw exception for unfound native symbols from calls, variable access, set immediately
 36  * @library ..
 37  * @modules jdk.incubator.jextract
 38  * @run driver JtregJextract -t test.jextract.test8259473 -- test8259473.h
 39  * @run testng/othervm --enable-native-access=jdk.incubator.jextract,ALL-UNNAMED LibTest8259473Test
 40  */
 41 /*
 42  * @test id=sources
 43  * @bug 8259473
 44  * @summary jextract generated code should throw exception for unfound native symbols from calls, variable access, set immediately
 45  * @library ..
 46  * @modules jdk.incubator.jextract
 47  * @run driver JtregJextractSources -t test.jextract.test8259473 -- test8259473.h
 48  * @run testng/othervm --enable-native-access=jdk.incubator.jextract,ALL-UNNAMED LibTest8259473Test
 49  */
 50 public class LibTest8259473Test {
 51     @Test
 52     public void nullChecksTest() {
 53         try {
 54             func();
 55             throw new AssertionError("should not reach here");
 56         } catch (UnsatisfiedLinkError ule) {
 57             assertTrue(ule.getMessage().contains("unresolved symbol: func"));
 58         }
 59 
 60         try {
 61             func$MH();
 62             throw new AssertionError("should not reach here");
 63         } catch (UnsatisfiedLinkError ule) {
 64             assertTrue(ule.getMessage().contains("unresolved symbol: func"));
 65         }
 66 
 67         try {
 68             x$get();
 69             throw new AssertionError("should not reach here");
 70         } catch (UnsatisfiedLinkError ule) {
 71             assertTrue(ule.getMessage().contains("unresolved symbol: x"));
 72         }
 73 
 74         try {
 75             x$set(1);
 76             throw new AssertionError("should not reach here");
 77         } catch (UnsatisfiedLinkError ule) {
 78             assertTrue(ule.getMessage().contains("unresolved symbol: x"));
 79         }
 80 
 81         try {
 82             x$SEGMENT();
 83             throw new AssertionError("should not reach here");
 84         } catch (UnsatisfiedLinkError ule) {
 85             assertTrue(ule.getMessage().contains("unresolved symbol: x"));
 86         }
 87 
 88         try {
 89             y$SEGMENT();
 90             throw new AssertionError("should not reach here");
 91         } catch (UnsatisfiedLinkError ule) {
 92             assertTrue(ule.getMessage().contains("unresolved symbol: y"));
 93         }
 94 
 95         try {
 96             pt$SEGMENT();
 97             throw new AssertionError("should not reach here");
 98         } catch (UnsatisfiedLinkError ule) {
 99             assertTrue(ule.getMessage().contains("unresolved symbol: pt"));
100         }
101     }
102 }