51 lines
1.6 KiB
Java
Raw Normal View History

2018-05-02 20:54:07 +02:00
package bytecode;
import static org.junit.Assert.assertEquals;
2018-05-02 20:54:07 +02:00
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
2018-05-02 20:54:07 +02:00
import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
public class LambdaTest {
private static String path;
private static File fileToTest;
private static JavaTXCompiler compiler;
private static ClassLoader loader;
private static Class<?> classToTest;
private static String pathToClassFile;
private static Object instanceOfClass;
2018-05-02 20:54:07 +02:00
@Test
public void generateBC() throws Exception {
modified: src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java In Zeile 833 catch Exception durch catch Throwable ersetzt, da der UnsupportedClassVersionError geworfen wurde modified: src/test/java/bytecode/FacTest.java modified: src/test/java/bytecode/FacultyTest.java modified: src/test/java/bytecode/FieldTest.java modified: src/test/java/bytecode/FieldTph.java modified: src/test/java/bytecode/FieldTph2Test.java modified: src/test/java/bytecode/FunOLTest.java modified: src/test/java/bytecode/GenTest.java modified: src/test/java/bytecode/GreaterEqualTest.java modified: src/test/java/bytecode/GreaterThanTest.java modified: src/test/java/bytecode/LambdaCapturetest.java modified: src/test/java/bytecode/LambdaTest.java modified: src/test/java/bytecode/LambdaVoidTest.java modified: src/test/java/bytecode/LessEqualTest.java modified: src/test/java/bytecode/LessThanTest.java modified: src/test/java/bytecode/MatrixOpTest.java modified: src/test/java/bytecode/MergeTest.java modified: src/test/java/bytecode/OLTest.java modified: src/test/java/bytecode/OpTest.java modified: src/test/java/bytecode/OverloadingSortingTest.java modified: src/test/java/bytecode/OverloadingTest.java modified: src/test/java/bytecode/PlusTest.java modified: src/test/java/bytecode/PostIncTest.java modified: src/test/java/bytecode/PreIncTest.java modified: src/test/java/bytecode/RelOpsTest.java modified: src/test/java/bytecode/SortingTest.java modified: src/test/java/bytecode/SubMatTest.java modified: src/test/java/bytecode/Tph2Test.java modified: src/test/java/bytecode/Tph3Test.java modified: src/test/java/bytecode/Tph5Test.java modified: src/test/java/bytecode/TphTest.java modified: src/test/java/bytecode/WhileTest.java modified: src/test/java/bytecode/YTest.java Pfade angepasst
2018-12-28 23:39:59 +01:00
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Lambda.jav";
2018-05-02 20:54:07 +02:00
fileToTest = new File(path);
compiler = new JavaTXCompiler(fileToTest);
modified: src/main/java/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java In Zeile 833 catch Exception durch catch Throwable ersetzt, da der UnsupportedClassVersionError geworfen wurde modified: src/test/java/bytecode/FacTest.java modified: src/test/java/bytecode/FacultyTest.java modified: src/test/java/bytecode/FieldTest.java modified: src/test/java/bytecode/FieldTph.java modified: src/test/java/bytecode/FieldTph2Test.java modified: src/test/java/bytecode/FunOLTest.java modified: src/test/java/bytecode/GenTest.java modified: src/test/java/bytecode/GreaterEqualTest.java modified: src/test/java/bytecode/GreaterThanTest.java modified: src/test/java/bytecode/LambdaCapturetest.java modified: src/test/java/bytecode/LambdaTest.java modified: src/test/java/bytecode/LambdaVoidTest.java modified: src/test/java/bytecode/LessEqualTest.java modified: src/test/java/bytecode/LessThanTest.java modified: src/test/java/bytecode/MatrixOpTest.java modified: src/test/java/bytecode/MergeTest.java modified: src/test/java/bytecode/OLTest.java modified: src/test/java/bytecode/OpTest.java modified: src/test/java/bytecode/OverloadingSortingTest.java modified: src/test/java/bytecode/OverloadingTest.java modified: src/test/java/bytecode/PlusTest.java modified: src/test/java/bytecode/PostIncTest.java modified: src/test/java/bytecode/PreIncTest.java modified: src/test/java/bytecode/RelOpsTest.java modified: src/test/java/bytecode/SortingTest.java modified: src/test/java/bytecode/SubMatTest.java modified: src/test/java/bytecode/Tph2Test.java modified: src/test/java/bytecode/Tph3Test.java modified: src/test/java/bytecode/Tph5Test.java modified: src/test/java/bytecode/TphTest.java modified: src/test/java/bytecode/WhileTest.java modified: src/test/java/bytecode/YTest.java Pfade angepasst
2018-12-28 23:39:59 +01:00
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("Lambda");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
2018-07-18 22:49:21 +02:00
Method m = classToTest.getDeclaredMethod("m");
Class<?> lambda = m.invoke(instanceOfClass).getClass();
Method apply = lambda.getMethod("apply", Object.class);
2018-07-25 11:01:03 +02:00
// Damit man auf die Methode zugreifen kann
2018-07-18 22:49:21 +02:00
apply.setAccessible(true);
Integer i = 77;
System.out.println(m.invoke(instanceOfClass).toString());
Integer result = (Integer) apply.invoke(m.invoke(instanceOfClass), i);
2019-07-25 22:24:06 +02:00
assertEquals(i, result);
2018-05-02 20:54:07 +02:00
}
}