< prev index next >

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

Print this page




 282                 System.err.println("Load class " + name);
 283                 // AsmCheckClass(name);
 284                 // AsmifyClass(name);
 285                 clz_data[i][0] = actualCL.loadClass(name);
 286                 clz_data[i][1] = expectedCL.loadClass(name);
 287             }
 288         }
 289         return clz_data;
 290     }
 291 
 292     @BeforeClass
 293     public void compile() throws IOException {
 294         System.out.println("Compiling...");
 295         mfm = compileJavaCode();
 296         writer = extract();
 297         actualClz = writer.results();
 298         expectedCL = mfm.getTheClassLoader();
 299         actualCL = new ClassLoader() {
 300             @Override
 301             protected Class<?> findClass(String name) throws ClassNotFoundException {
 302                 byte[] byteCode = actualClz.get(canonicalize(name));
 303                 if (byteCode == null) throw new ClassNotFoundException(name);
 304                 return defineClass(name, byteCode, 0, byteCode.length);
 305             }
 306         };
 307         System.out.println("Done compile, ready for test");
 308         assertEquals(actualClz.keySet().stream()
 309                         .map(Runner::normalize)
 310                         .collect(Collectors.toSet()),
 311                 mfm.listClasses());
 312         System.out.println("Compile result validated.");
 313     }
 314 
 315     private static String normalize(String classname) {
 316         return classname.replace('/', '.');
 317     }
 318 
 319     private static String canonicalize(String classname) {
 320         return classname.replace('.', '/');
 321     }
 322 
 323     private static Path[] paths(String testDir, String[] files, boolean platformDependent) {
 324         boolean isWindows = System.getProperty("os.name").startsWith("Windows");
 325         return Arrays.stream(files)
 326                 .map(f -> Paths.get(testDir, "compare", isWindows && platformDependent ? "windows" : "", f))
 327                 .toArray(Path[]::new);
 328     }
 329 
 330     @Factory(dataProvider = "cases")
 331     public static Object[] run(String nativeSrc, String pkgName, String[] javaSrcFiles, boolean platformDependent) {
 332         String testDir = System.getProperty("test.src", ".");
 333         System.out.println("Use test case files in " + testDir);
 334         return new Object[] {
 335             new Runner(Paths.get(testDir, nativeSrc), pkgName, paths(testDir, javaSrcFiles, platformDependent))
 336         };
 337     }
 338 
 339     @DataProvider(name = "cases")
 340     public static Object[][] cases() {
 341         return new Object[][] {
 342             { "simple.h", "com.acme", new String[] { "simple_h.java" }, true},


 282                 System.err.println("Load class " + name);
 283                 // AsmCheckClass(name);
 284                 // AsmifyClass(name);
 285                 clz_data[i][0] = actualCL.loadClass(name);
 286                 clz_data[i][1] = expectedCL.loadClass(name);
 287             }
 288         }
 289         return clz_data;
 290     }
 291 
 292     @BeforeClass
 293     public void compile() throws IOException {
 294         System.out.println("Compiling...");
 295         mfm = compileJavaCode();
 296         writer = extract();
 297         actualClz = writer.results();
 298         expectedCL = mfm.getTheClassLoader();
 299         actualCL = new ClassLoader() {
 300             @Override
 301             protected Class<?> findClass(String name) throws ClassNotFoundException {
 302                 byte[] byteCode = actualClz.get(name);
 303                 if (byteCode == null) throw new ClassNotFoundException(name);
 304                 return defineClass(name, byteCode, 0, byteCode.length);
 305             }
 306         };
 307         System.out.println("Done compile, ready for test");
 308         assertEquals(actualClz.keySet().stream()
 309                         .map(Runner::normalize)
 310                         .collect(Collectors.toSet()),
 311                 mfm.listClasses());
 312         System.out.println("Compile result validated.");
 313     }
 314 
 315     private static String normalize(String classname) {
 316         return classname.replace('/', '.');
 317     }
 318 




 319     private static Path[] paths(String testDir, String[] files, boolean platformDependent) {
 320         boolean isWindows = System.getProperty("os.name").startsWith("Windows");
 321         return Arrays.stream(files)
 322                 .map(f -> Paths.get(testDir, "compare", isWindows && platformDependent ? "windows" : "", f))
 323                 .toArray(Path[]::new);
 324     }
 325 
 326     @Factory(dataProvider = "cases")
 327     public static Object[] run(String nativeSrc, String pkgName, String[] javaSrcFiles, boolean platformDependent) {
 328         String testDir = System.getProperty("test.src", ".");
 329         System.out.println("Use test case files in " + testDir);
 330         return new Object[] {
 331             new Runner(Paths.get(testDir, nativeSrc), pkgName, paths(testDir, javaSrcFiles, platformDependent))
 332         };
 333     }
 334 
 335     @DataProvider(name = "cases")
 336     public static Object[][] cases() {
 337         return new Object[][] {
 338             { "simple.h", "com.acme", new String[] { "simple_h.java" }, true},
< prev index next >