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 /*
  25  * @test
  26  * @library ..
  27  * @modules jdk.jextract
  28  * @build RpathTest
  29  *
  30  * @run testng/othervm RpathTest
  31  */
  32 
  33 import org.testng.annotations.*;
  34 
  35 import java.foreign.annotations.NativeHeader;
  36 import java.nio.file.Path;
  37 
  38 import static org.testng.Assert.*;
  39 
  40 public class RpathTest extends JextractToolRunner {
  41 
  42     @Test
  43     public void testExplicit() throws ReflectiveOperationException {
  44         Path clzPath = getOutputFilePath("libTestRpath.jar");
  45         checkSuccess(null,"-o", clzPath.toString(),
  46                 "-l", "b", "-rpath", "foo/bar",
  47                 getInputFilePath("foo.h").toString());
  48         for (String name : new String[] { "foo", "bar"}) {
  49             Class<?> headerCls = loadClass(name, clzPath);
  50             NativeHeader nativeHeader = headerCls.getAnnotation(NativeHeader.class);
  51             assertNotNull(nativeHeader);
  52             assertTrue(nativeHeader.libraryPaths().length == 1);
  53             assertEquals(nativeHeader.libraryPaths()[0], "foo/bar");
  54         }
  55     }
  56 
  57     @Test
  58     public void testAuto() throws ReflectiveOperationException {
  59         Path clzPath = getOutputFilePath("libTestRpath.jar");
  60         checkSuccess(null,"-o", clzPath.toString(),
  61                 "-l", "b", "-L", "foo/bar", "-infer-rpath",
  62                 getInputFilePath("foo.h").toString());
  63         for (String name : new String[] { "foo", "bar"}) {
  64             Class<?> headerCls = loadClass(name, clzPath);
  65             NativeHeader nativeHeader = headerCls.getAnnotation(NativeHeader.class);
  66             assertNotNull(nativeHeader);
  67             assertTrue(nativeHeader.libraryPaths().length == 1);
  68             assertEquals(nativeHeader.libraryPaths()[0], "foo/bar");
  69         }
  70     }
  71 }
--- EOF ---