< prev index next >

test/jdk/com/sun/tools/jextract/ConstantsTest.java

Print this page




  34 import static org.testng.Assert.assertNotNull;
  35 import static org.testng.Assert.assertTrue;
  36 
  37 
  38 /*
  39  * @test
  40  * @modules jdk.jextract
  41  * @build ConstantsTest
  42  * @run testng ConstantsTest
  43  */
  44 public class ConstantsTest extends JextractToolRunner {
  45 
  46     Object[] constants;
  47     Path clzPath;
  48     Path dirPath;
  49 
  50     @BeforeTest
  51     public void setup() {
  52         clzPath = getOutputFilePath("ConstantsTest.c.jar");
  53         dirPath = getOutputFilePath("ConstantsTest.c.dir");
  54         checkSuccess(null,"-o", clzPath.toString(), "-d", dirPath.toString(),
  55                 getInputFilePath("constants.h").toString());
  56         Class<?>[] cls = {
  57                 loadClass("constants", clzPath),
  58                 loadClass("constants", dirPath)
  59         };
  60         constants = new Object[cls.length];
  61         for (int i = 0 ; i < cls.length ; i++) {
  62             Class<?> cl = cls[i];
  63             constants[i] = Proxy.newProxyInstance(cl.getClassLoader(),
  64                     new Class<?>[]{ cl },
  65                     (proxy, method, args) -> MethodHandles.privateLookupIn(cl, MethodHandles.lookup())
  66                                 .unreflectSpecial(method, cl)
  67                                 .bindTo(proxy)
  68                                 .invokeWithArguments(args));
  69         }
  70     }
  71 
  72     @AfterTest
  73     public void cleanup() {
  74         deleteFile(clzPath);
  75         deleteDir(dirPath);




  34 import static org.testng.Assert.assertNotNull;
  35 import static org.testng.Assert.assertTrue;
  36 
  37 
  38 /*
  39  * @test
  40  * @modules jdk.jextract
  41  * @build ConstantsTest
  42  * @run testng ConstantsTest
  43  */
  44 public class ConstantsTest extends JextractToolRunner {
  45 
  46     Object[] constants;
  47     Path clzPath;
  48     Path dirPath;
  49 
  50     @BeforeTest
  51     public void setup() {
  52         clzPath = getOutputFilePath("ConstantsTest.c.jar");
  53         dirPath = getOutputFilePath("ConstantsTest.c.dir");
  54         run("-o", clzPath.toString(), "-d", dirPath.toString(),
  55                 getInputFilePath("constants.h").toString()).checkSuccess();
  56         Class<?>[] cls = {
  57                 loadClass("constants", clzPath),
  58                 loadClass("constants", dirPath)
  59         };
  60         constants = new Object[cls.length];
  61         for (int i = 0 ; i < cls.length ; i++) {
  62             Class<?> cl = cls[i];
  63             constants[i] = Proxy.newProxyInstance(cl.getClassLoader(),
  64                     new Class<?>[]{ cl },
  65                     (proxy, method, args) -> MethodHandles.privateLookupIn(cl, MethodHandles.lookup())
  66                                 .unreflectSpecial(method, cl)
  67                                 .bindTo(proxy)
  68                                 .invokeWithArguments(args));
  69         }
  70     }
  71 
  72     @AfterTest
  73     public void cleanup() {
  74         deleteFile(clzPath);
  75         deleteDir(dirPath);


< prev index next >