Anpassung der Tests für OLFun bzw. aktiv Nahme dieser.
This commit is contained in:
parent
ac6980b5e0
commit
65448c3bf3
@ -28,6 +28,7 @@ public class ByteCodeForFunNGenerator {
|
|||||||
*/
|
*/
|
||||||
private static HashSet<Integer> alreadyGeneratedFunN = new HashSet<>();
|
private static HashSet<Integer> alreadyGeneratedFunN = new HashSet<>();
|
||||||
|
|
||||||
|
//ToDo Etienne: wird in Test OLFun nicht verwendet!
|
||||||
public static void generateBCForFunN(LambdaExpression lambdaExpression, String methDesc, File path) {
|
public static void generateBCForFunN(LambdaExpression lambdaExpression, String methDesc, File path) {
|
||||||
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||||
|
|
||||||
@ -57,6 +58,7 @@ public class ByteCodeForFunNGenerator {
|
|||||||
public static void generateBCForFunN(ArgumentList argumentList, String methDesc, File path) {
|
public static void generateBCForFunN(ArgumentList argumentList, String methDesc, File path) {
|
||||||
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||||
List<Expression> arguments = argumentList.getArguments();
|
List<Expression> arguments = argumentList.getArguments();
|
||||||
|
|
||||||
/* //ToDo neu machen
|
/* //ToDo neu machen
|
||||||
int numberOfParams = arguments.size();
|
int numberOfParams = arguments.size();
|
||||||
//ToDo Classname anpassen
|
//ToDo Classname anpassen
|
||||||
@ -68,7 +70,6 @@ public class ByteCodeForFunNGenerator {
|
|||||||
writeClassFile(className, classWriter.toByteArray(), path);
|
writeClassFile(className, classWriter.toByteArray(), path);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
SignatureWriter signatureWriter = new SignatureWriter();
|
SignatureWriter signatureWriter = new SignatureWriter();
|
||||||
int numberOfParams = 0;
|
int numberOfParams = 0;
|
||||||
SignatureVisitor paramVisitor = signatureWriter.visitParameterType();
|
SignatureVisitor paramVisitor = signatureWriter.visitParameterType();
|
||||||
|
@ -1,52 +1,69 @@
|
|||||||
package bytecode;
|
package bytecode;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.invoke.*;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
import org.junit.Test;
|
import general.TestCleanUp;
|
||||||
|
import org.junit.*;
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test which only checks if the class {@code OLFun} was correctly compiled.
|
||||||
|
* This is achived by verifying the existence of the three implementations of {@code m}.
|
||||||
|
*
|
||||||
|
* @since Studienarbeit Type Erasure
|
||||||
|
* @author Etienne Zink
|
||||||
|
*/
|
||||||
public class OLFunTest {
|
public class OLFunTest {
|
||||||
private static String path;
|
private static String path;
|
||||||
private static File fileToTest;
|
private static File fileToTest;
|
||||||
private static JavaTXCompiler compiler;
|
private static JavaTXCompiler compiler;
|
||||||
private static ClassLoader loader;
|
private static ClassLoader loader;
|
||||||
private static Class<?> classToTest;
|
private static Class<?> classToTest;
|
||||||
private static String pathToClassFile;
|
private static Class<?> classFun1;
|
||||||
private static Object instanceOfClass;
|
private static Object instanceOfClass;
|
||||||
|
|
||||||
|
private static String generatedByteCodeDirectory = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/";
|
||||||
|
|
||||||
@Test
|
@BeforeClass
|
||||||
public void generateBC() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/OLFun.jav";
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/OLFun.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
compiler.generateBytecode(generatedByteCodeDirectory);
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
loader = new URLClassLoader(new URL[] {new URL("file://"+generatedByteCodeDirectory)});
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
|
||||||
classToTest = loader.loadClass("OLFun");
|
classToTest = loader.loadClass("OLFun");
|
||||||
/*
|
classFun1 = loader.loadClass("Fun1$$");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
Method m = classToTest.getDeclaredMethod("m");
|
|
||||||
Class<?> lambda = m.invoke(instanceOfClass).getClass();
|
|
||||||
Method apply = lambda.getMethod("apply", Object.class);
|
|
||||||
|
|
||||||
// Damit man auf die Methode zugreifen kann
|
|
||||||
apply.setAccessible(true);
|
|
||||||
|
|
||||||
Integer i = 77;
|
|
||||||
|
|
||||||
Integer result = (Integer) apply.invoke(m.invoke(instanceOfClass), i);
|
|
||||||
|
|
||||||
assertEquals(77, result);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mExistsWithInteger() throws Exception{
|
||||||
|
Method m = classToTest.getDeclaredMethod("m", classFun1 ,Integer.class);
|
||||||
|
assertNotNull(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mExistsWithString() throws Exception{
|
||||||
|
Method m = classToTest.getDeclaredMethod("m", classFun1 ,String.class);
|
||||||
|
assertNotNull(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mExistsWithDouble() throws Exception{
|
||||||
|
Method m = classToTest.getDeclaredMethod("m", classFun1 ,Double.class);
|
||||||
|
assertNotNull(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void cleanUp(){
|
||||||
|
TestCleanUp.cleanUpDirectory(new File(generatedByteCodeDirectory), f -> f.getName().contains(".class"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer apply(Integer x) {return x;}
|
||||||
}
|
}
|
||||||
|
14
src/test/java/general/TestCleanUp.java
Normal file
14
src/test/java/general/TestCleanUp.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package general;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileFilter;
|
||||||
|
|
||||||
|
public class TestCleanUp {
|
||||||
|
|
||||||
|
public static void cleanUpDirectory(File directory, FileFilter fileFilter){
|
||||||
|
if(!directory.isDirectory()) throw new RuntimeException("Directory for bytecode generation is wrong!");
|
||||||
|
for (File file: directory.listFiles(fileFilter)) {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -10,8 +10,8 @@ import java.lang.Boolean;
|
|||||||
public class OLFun {
|
public class OLFun {
|
||||||
|
|
||||||
//f = x -> {return x + x;};
|
//f = x -> {return x + x;};
|
||||||
|
y;
|
||||||
m(f, x) {
|
m(f, x) {
|
||||||
x = f.apply(x+x);
|
y = f.apply(x+x);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user