Update test files

This commit is contained in:
Gabriel Tofvesson 2021-02-05 14:59:04 +01:00
parent 98b3b7cb3b
commit baf2739bf5
3 changed files with 38 additions and 7 deletions

View File

@ -45,8 +45,8 @@ public class MergeInject extends MergeTest implements Runnable {
@Inject(AFTER)
public int stackTest(int arg) {
Runnable r = () -> {
System.out.println(arg / 15);
System.out.println("Heyo");
System.out.println(arg / 15);
System.out.println("Heyo");
};
r.run();
return 69;
@ -54,10 +54,20 @@ public class MergeInject extends MergeTest implements Runnable {
@Inject(AFTER)
public String test(String retVal){
public String test(String retVal) throws Exception {
System.out.println(retVal + "Cringe");
try {
if (ThreadLocalRandom.current().nextBoolean())
throw new Exception("Hello from exception");
}catch (Exception e) {
System.out.println("Hello from catch");
e.printStackTrace();
} finally {
System.out.println("Hello from finally");
}
return "Modified";
}
@ -70,4 +80,4 @@ public class MergeInject extends MergeTest implements Runnable {
System.out.println(test()+'\n');
}
}
}
}

View File

@ -14,7 +14,7 @@ public class MergeTest {
}
public String test(){
Class<?> c = Combine.class;
final Class<?> c = Combine.class;
Runnable r = () -> {
System.out.println("Sick");
System.out.println(c.getName());
@ -57,4 +57,4 @@ public class MergeTest {
if (bool)
System.out.println(k + a + b * getNumber() + i);
}
}
}

View File

@ -1,10 +1,14 @@
import dev.w1zzrd.asm.Combine;
import dev.w1zzrd.asm.Injector;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class Test {
public static void main(String... args) throws IOException {
// Load target class, inject all annotated classes and load compiled bytecode into JVM
Injector.injectAll("MergeTest").compile();
dumpFile(Injector.injectAll("MergeTest"), "MergeTest").compile();
// Run simple injection tests
new MergeTest().test();
@ -17,4 +21,21 @@ public class Test {
r.run();
}
public static Combine dumpFile(Combine comb, String name) {
File f = new File(name + ".class");
try {
if ((f.isFile() && !f.delete()) || !f.createNewFile())
System.err.printf("Could not dump file %s.class%n", name);
else {
FileOutputStream fos = new FileOutputStream(f);
fos.write(comb.toByteArray());
fos.close(); // Implicit flush if underlying stream is buffered
}
} catch (IOException e) {
e.printStackTrace();
}
return comb;
}
}