Remove tests
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 44s
Some checks failed
Build and Test with Maven / Build-and-test-with-Maven (push) Failing after 44s
This commit is contained in:
parent
494ce63838
commit
d176dfb1e3
@ -1,91 +0,0 @@
|
||||
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static targetast.TestCodegen.generateClassFiles;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
||||
|
||||
public class AllgemeinTest {
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
//String className = "GenTest";
|
||||
//String className = "Overloading_Generics";
|
||||
//String className = "Generics";
|
||||
//String className = "OverloadingMain";
|
||||
//String className = "OverrideMain";
|
||||
//String className = "OverrideMainRet";
|
||||
//String className = "FCTest1";
|
||||
//String className = "FCTest2";
|
||||
//String className = "Pair";
|
||||
//String className = "FCTest3";
|
||||
//String className = "Var";
|
||||
//String className = "Put";
|
||||
//String className = "Twice";
|
||||
//String className = "Twice2";
|
||||
//String className = "TestSubTypless";
|
||||
//String className = "addList";
|
||||
//String className = "M";
|
||||
//String className = "Wildcard_Andi";
|
||||
//String className = "Box";
|
||||
//String className = "Box_Main";
|
||||
//String className = "wildcardPair";
|
||||
//String className = "VectorConstAdd";
|
||||
//String className = "VectorNotObject";
|
||||
//String className = "WildcardCaptureConversionTest";
|
||||
//String className = "CaptureConversion";
|
||||
//String className = "Pair";
|
||||
//String className = "UseWildcardPair";
|
||||
//String className = "Assign";
|
||||
//String className = "StreamTest";
|
||||
//String className = "Iteration";
|
||||
|
||||
//String className = "Cycle";
|
||||
//String className = "TripleTest";
|
||||
//String className = "WildcardList";
|
||||
//String className = "List";
|
||||
//String className = "Box";
|
||||
String className = "GenBox";
|
||||
//PL 2019-10-24: genutzt fuer unterschiedliche Tests
|
||||
path = System.getProperty("user.dir")+"/resources/AllgemeinTest/" + className + ".jav";
|
||||
//path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav";
|
||||
//path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/mathStrucInteger.jav";
|
||||
//compiler = new JavaTXCompiler(Lists.newArrayList(new File(System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav")));
|
||||
///*
|
||||
compiler = new JavaTXCompiler(
|
||||
Lists.newArrayList(new File(path)),
|
||||
Lists.newArrayList(new File(System.getProperty("user.dir")+"/resources/bytecode/classFiles/")),
|
||||
new File(System.getProperty("user.dir")+"/resources/bytecode/classFiles/"));
|
||||
//*/
|
||||
compiler.generateBytecode();
|
||||
pathToClassFile = System.getProperty("user.dir")+"/resources/bytecode/classFiles/";
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass(className);
|
||||
//classToTest = loader.loadClass("Overloading_Generics");
|
||||
//instanceOfClass = classToTest.getDeclaredConstructor().newInstance("A");
|
||||
//classToTest = loader.loadClass("Overloading_Generics1");
|
||||
//instanceOfClass = classToTest.getDeclaredConstructor(Object.class).newInstance("B");
|
||||
}
|
||||
|
||||
}
|
@ -1,105 +0,0 @@
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.GenericContext;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class GenericsParserTest {
|
||||
|
||||
@Test
|
||||
public void testMethodNoGenerics() {
|
||||
var signature = "()V";
|
||||
var generics = ASTFactory.createGenerics(signature);
|
||||
assertEquals(generics, new GenericDeclarationList(List.of(), new NullToken()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodSimpleGenerics() {
|
||||
var signature = "<T:Ljava/lang/Object;>()V";
|
||||
var generics = ASTFactory.createGenerics(signature);
|
||||
assertEquals(generics, new GenericDeclarationList(
|
||||
List.of(new GenericTypeVar("T", List.of(ASTToTargetAST.OBJECT), new NullToken(), new NullToken())), new NullToken())
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodExtends() {
|
||||
var signature = "<T:Ljava/lang/Class<TT;>;>()V";
|
||||
var generics = ASTFactory.createGenerics(signature);
|
||||
assertEquals(generics, new GenericDeclarationList(
|
||||
List.of(new GenericTypeVar("T", List.of(
|
||||
new RefType(new JavaClassName("java.lang.Class"), List.of(new GenericRefType("T", new NullToken())), new NullToken())),
|
||||
new NullToken(), new NullToken())), new NullToken()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodVariance() {
|
||||
var signature = "<T:Ljava/lang/Class<+TT;>;>()V";
|
||||
var generics = ASTFactory.createGenerics(signature);
|
||||
|
||||
assertEquals(generics, new GenericDeclarationList(
|
||||
List.of(new GenericTypeVar("T", List.of(
|
||||
new RefType(new JavaClassName("java.lang.Class"), List.of(
|
||||
new ExtendsWildcardType(new GenericRefType("T", new NullToken()), new NullToken())
|
||||
), new NullToken())),
|
||||
new NullToken(), new NullToken())),
|
||||
new NullToken())
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodTypeVars() {
|
||||
var signature = "<A:TB;B:LClassA;C:LClassB<TA;>;D:TB;>()V";
|
||||
var generics = ASTFactory.createGenerics(signature);
|
||||
assertEquals(generics, new GenericDeclarationList(
|
||||
List.of(
|
||||
new GenericTypeVar("A", List.of(new GenericRefType("B", new NullToken())), new NullToken(), new NullToken()),
|
||||
new GenericTypeVar("B", List.of(new RefType(new JavaClassName("ClassA"), new NullToken())), new NullToken(), new NullToken()),
|
||||
new GenericTypeVar("C", List.of(new RefType(new JavaClassName("ClassB"),
|
||||
List.of(new GenericRefType("A", new NullToken())),
|
||||
new NullToken())), new NullToken(), new NullToken()
|
||||
),
|
||||
new GenericTypeVar("D", List.of(new GenericRefType("B", new NullToken())), new NullToken(), new NullToken())
|
||||
),
|
||||
new NullToken()
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodComplex() {
|
||||
var signature = "<T:LClassA<+TT;LClassB<+LClassA;-LClassC<LClassA;>;>;>;U:LClassC<LClassC;>;>()V";
|
||||
var generics = ASTFactory.createGenerics(signature);
|
||||
|
||||
assertEquals(generics, new GenericDeclarationList(
|
||||
List.of(new GenericTypeVar("T", List.of(
|
||||
new RefType(new JavaClassName("ClassA"), List.of(
|
||||
new ExtendsWildcardType(new GenericRefType("T", new NullToken()), new NullToken()),
|
||||
new RefType(new JavaClassName("ClassB"), List.of(
|
||||
new ExtendsWildcardType(new RefType(new JavaClassName("ClassA"), new NullToken()), new NullToken()),
|
||||
new SuperWildcardType(
|
||||
new RefType(new JavaClassName("ClassC"), List.of(
|
||||
new RefType(new JavaClassName("ClassA"), new NullToken())
|
||||
), new NullToken()), new NullToken())
|
||||
), new NullToken())
|
||||
), new NullToken())
|
||||
), new NullToken(), new NullToken()),
|
||||
new GenericTypeVar("U", List.of(
|
||||
new RefType(new JavaClassName("ClassC"), List.of(
|
||||
new RefType(new JavaClassName("ClassC"), new NullToken())
|
||||
), new NullToken())
|
||||
), new NullToken(), new NullToken())),
|
||||
new NullToken()
|
||||
));
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,51 +0,0 @@
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class TestPackages {
|
||||
|
||||
private static final String bytecodeDirectory = System.getProperty("user.dir") + "/targetTest";
|
||||
|
||||
@Test
|
||||
public void testPackages() throws Exception {
|
||||
var cmp = new JavaTXCompiler(
|
||||
List.of(
|
||||
new File("resources/packageTest/pkg/sub/Test1.jav") // This should pull in Test2
|
||||
//new File("resources/packageTest/pkg/sub2/Test2.jav")
|
||||
),
|
||||
List.of(new File("resources/packageTest")),
|
||||
new File(bytecodeDirectory)
|
||||
);
|
||||
|
||||
cmp.generateBytecode();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("This doesn't work")
|
||||
public void testPackagesCircular() throws Exception {
|
||||
var cmp = new JavaTXCompiler(
|
||||
List.of(
|
||||
new File("resources/packageTest/pkg/sub/Cycle1.jav")
|
||||
//new File("resources/packageTest/pkg/sub2/Cycle2.jav")
|
||||
),
|
||||
List.of(new File("resources/packageTest")),
|
||||
new File(bytecodeDirectory)
|
||||
);
|
||||
|
||||
cmp.generateBytecode();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPackageInterface() throws Exception {
|
||||
var cmp = new JavaTXCompiler(
|
||||
List.of(new File("resources/packageTest/pkg/sub/Interface.jav")),
|
||||
List.of(new File("resources/packageTest")),
|
||||
new File(bytecodeDirectory)
|
||||
);
|
||||
|
||||
cmp.generateBytecode();
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestTypeDeployment {
|
||||
|
||||
@Test
|
||||
public void testTypeDeployment() throws Exception {
|
||||
var path = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Cycle.jav");
|
||||
var file = path.toFile();
|
||||
var compiler = new JavaTXCompiler(file, false);
|
||||
var parsedSource = compiler.sourceFiles.get(file);
|
||||
var tiResults = compiler.typeInference(file);
|
||||
Set<TypeInsert> tips = new HashSet<>();
|
||||
|
||||
for (var sf : compiler.sourceFiles.values()) {
|
||||
Map<JavaClassName, byte[]> bytecode = compiler.generateBytecode(sf, tiResults);
|
||||
}
|
||||
|
||||
System.out.println(compiler.getGeneratedGenerics());
|
||||
|
||||
for (int i = 0; i < tiResults.size(); i++) {
|
||||
ResultSet tiResult = tiResults.get(i);
|
||||
tips.addAll(TypeInsertFactory.createTypeInsertPoints(parsedSource, tiResult, compiler.getGeneratedGenerics().get(compiler.sourceFiles.get(file)).get(i)));
|
||||
for (TypeInsert p : tips) {
|
||||
System.out.println(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package astfactory;
|
||||
|
||||
//import javafx.collections.ObservableList;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ASTFactoryTest<A> extends HashMap<String, A>{
|
||||
@Test
|
||||
public void test(){
|
||||
System.out.println((this.getClass().getGenericSuperclass()));
|
||||
Type[] arguments = ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments();
|
||||
System.out.println(Arrays.toString(arguments));
|
||||
System.out.println(((TypeVariable)arguments[1]).getGenericDeclaration());
|
||||
}
|
||||
|
||||
public static class GenericFieldTest<G>{
|
||||
public G testField;
|
||||
}
|
||||
@Test
|
||||
public void genericFieldTest(){
|
||||
ClassOrInterface test = ASTFactory.createClass(GenericFieldTest.class);
|
||||
assertTrue(test.getFieldDecl().get(0).getType() instanceof GenericRefType);
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package finiteClosure;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
public class SuperInterfacesTest {
|
||||
@Test
|
||||
public void test() throws ClassNotFoundException {
|
||||
Collection<ClassOrInterface> classes = new ArrayList<>();
|
||||
classes.add(ASTFactory.createClass(TestClass.class));
|
||||
System.out.println(FCGenerator.toFC(classes, ClassLoader.getSystemClassLoader()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGeneric() throws ClassNotFoundException {
|
||||
Collection<ClassOrInterface> classes = new ArrayList<>();
|
||||
classes.add(ASTFactory.createClass(TestClassGeneric.class));
|
||||
System.out.println(FCGenerator.toFC(classes, ClassLoader.getSystemClassLoader()));
|
||||
}
|
||||
}
|
||||
|
||||
class TestClass implements Test2, Test3{
|
||||
|
||||
}
|
||||
|
||||
class TestClassGeneric<A,B> implements Test4<A>{
|
||||
|
||||
}
|
||||
|
||||
interface Test2 {
|
||||
|
||||
}
|
||||
|
||||
interface Test3{
|
||||
|
||||
}
|
||||
|
||||
interface Test4<A>{
|
||||
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
|
||||
|
||||
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
|
||||
|
||||
<appender name="CONSOLE" class="de.dhbwstuttgart.logger.ConsoleAppender">
|
||||
<param name="Target" value="System.out"/>
|
||||
|
||||
<layout class="de.dhbwstuttgart.logger.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-15C{1} %-5p [%-9c] %m%n"/>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<logger name="trtest">
|
||||
<level value="DEBUG"/>
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
|
||||
<logger name="funcTest">
|
||||
<level value="DEBUG"/>
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
|
||||
</log4j:configuration>
|
@ -1,870 +0,0 @@
|
||||
package syntaxtreegenerator;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
|
||||
/**
|
||||
* Unit-Tests für den 'SyntaxTreeGenerator' aus dem Package 'parser' nach Vorbild der Klasse 'TestComplete' aus dem Test-Package 'targetast'
|
||||
*/
|
||||
public class TestComplete {
|
||||
private static HashMap<String, File[]> javFiles = new HashMap<>();
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
final String testFileDirectory = "resources/bytecode/javFiles/";
|
||||
final String expectedASTDirectory = "resources/syntaxtreegenerator/";
|
||||
File dir = new File(testFileDirectory);
|
||||
for (File f : dir.listFiles(new JavFilter())) {
|
||||
String basefilename = f.getName().replace(".jav", "");
|
||||
javFiles.put(basefilename, new File[] { f, new File(expectedASTDirectory + basefilename + ".ast") });
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyLambdaTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("applyLambda")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("applyLambda")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for applyLambda.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for applyLambda.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void binaryInMethTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("BinaryInMeth")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("BinaryInMeth")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for BinaryInMeth.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for BinaryInMeth.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void classGenLamTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("ClassGenLam")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("ClassGenLam")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for ClassGenLam.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for ClassGenLam.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void facTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Fac")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Fac")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Fac.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Fac.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void facultyTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Faculty")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Faculty")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Faculty.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Faculty.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fieldTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Field")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Field")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Field.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Field.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fieldTph2Test() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("FieldTph2")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("FieldTph2")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for FieldTph2.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for FieldTph2.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fieldTphConsMethTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("FieldTphConsMeth")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("FieldTphConsMeth")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for FieldTphConsMeth.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for FieldTphConsMeth.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fieldTphMMethTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("FieldTphMMeth")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("FieldTphMMeth")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for FieldTphMMeth.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for FieldTphMMeth.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void genTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Gen")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Gen")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Gen.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Gen.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void idTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Id")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Id")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Id.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Id.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void infTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Inf")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Inf")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Inf.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Inf.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kompTphTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("KompTph")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("KompTph")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for KompTph.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for KompTph.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lambdaCaptureTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("LambdaCapture")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("LambdaCapture")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for LambdaCapture.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for LambdaCapture.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lambdaTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Lambda")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Lambda")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Lambda.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Lambda.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mathStrucIntegerTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("mathStrucInteger")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("mathStrucInteger")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for mathStrucInteger.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
assertTrue("An error occured while generating the AST for mathStrucInteger.jav", exc instanceof NotImplementedException);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mathStrucTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("mathStruc")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("mathStruc")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for mathStruc.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for mathStruc.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matrixOPTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("MatrixOP")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("MatrixOP")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for MatrixOP.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for MatrixOP.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matrixTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Matrix")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Matrix")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Matrix.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Matrix.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Merge")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Merge")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Merge.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Merge.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void overloadingSortingTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Sorting")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Sorting")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Sorting.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Sorting.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void overloadingTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Overloading")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Overloading")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Overloading.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Overloading.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void plusTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Plus")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Plus")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Plus.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Plus.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void relOpsTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("RelOps")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("RelOps")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for RelOps.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for RelOps.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleCycleTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("SimpleCycle")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("SimpleCycle")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for SimpleCycle.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for SimpleCycle.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subMatTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("SubMatrix")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("SubMatrix")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for SubMatrix.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for SubMatrix.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tphTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Tph")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Tph")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Tph.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Tph.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tph2Test() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Tph2")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Tph2")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Tph2.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Tph2.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tph3Test() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Tph3")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Tph3")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Tph3.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Tph3.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tph4Test() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Tph4")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Tph4")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Tph4.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Tph4.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tph5Test() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Tph5")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Tph5")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Tph5.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Tph5.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tph6Test() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Tph6")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Tph6")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Tph6.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Tph6.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tph7Test() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Tph7")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Tph7")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Tph7.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Tph7.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void typedIdTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("TypedID")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("TypedID")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for TypedID.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for TypedID.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vectorAddTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("VectorAdd")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("VectorAdd")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for VectorAdd.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for VectorAdd.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vectorSuperTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("VectorSuper")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("VectorSuper")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for VectorSuper.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for VectorSuper.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void yTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Y")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Y")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Y.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Y.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void boxTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Box")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Box")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Box.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Box.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cycleTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Cycle")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Cycle")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Cycle.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Cycle.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void olFunTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("OLFun")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("OLFun")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for OLFun.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for OLFun.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void olFun2Test() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("OLFun2")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("OLFun2")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for OLFun2.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for OLFun2.jav");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class JavFilter implements FileFilter {
|
||||
|
||||
@Override
|
||||
public boolean accept(File pathname) {
|
||||
if (pathname.getName().contains(".jav"))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -1,131 +0,0 @@
|
||||
package syntaxtreegenerator;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
|
||||
public class TestNewFeatures {
|
||||
private static HashMap<String, File[]> javFiles = new HashMap<>();
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
final String testFileDirectory = "resources/syntaxtreegenerator/javFiles/";
|
||||
final String expectedASTDirectory = "resources/syntaxtreegenerator/";
|
||||
File dir = new File(testFileDirectory);
|
||||
for (File f : dir.listFiles(new JavFilter())) {
|
||||
String basefilename = f.getName().replace(".jav", "");
|
||||
// javFiles.put(basefilename, new File[] { f, new File(expectedASTDirectory + basefilename + ".ast") });
|
||||
javFiles.put(basefilename, new File[] { f, new File(expectedASTDirectory + basefilename + ".ast") });
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void instanceOfTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Instanceof")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Instanceof")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Instanceof.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Instanceof.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void recordTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Record")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Record")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for RecordTest.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for RecordTest.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sealedTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Sealed")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Sealed")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Sealed.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Sealed.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void switchTest() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Switch")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Switch")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for Switch.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for Switch.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void patternMatching() {
|
||||
try {
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("PatternMatching")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("PatternMatching")[0];
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
|
||||
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
|
||||
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
System.out.println("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
assertEquals("Comparing expected and resulting AST for PatternMatching.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for PatternMatching.jav");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,163 +0,0 @@
|
||||
package targetast;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
|
||||
import de.dhbwstuttgart.target.tree.TargetStructure;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ASTToTypedTargetAST {
|
||||
|
||||
@Test
|
||||
public void emptyClass() {
|
||||
ClassOrInterface emptyClass = new ClassOrInterface(0, new JavaClassName("EmptyClass"), new ArrayList<>(), Optional.empty(), Optional.empty(), new ArrayList<>(), new ArrayList<>(), new GenericDeclarationList(new ArrayList<>(), new NullToken()), new RefType(new JavaClassName("Object"), new NullToken()), false, false, new ArrayList<>(), new ArrayList<>(), new NullToken(), null);
|
||||
ResultSet emptyResultSet = new ResultSet(new HashSet<>());
|
||||
TargetStructure emptyTargetClass = new ASTToTargetAST(List.of(emptyResultSet)).convert(emptyClass);
|
||||
assert emptyTargetClass.getName().equals("EmptyClass");
|
||||
assert emptyTargetClass.methods().size() == 0;
|
||||
assert emptyTargetClass.fields().size() == 0;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void overloading() throws Exception {
|
||||
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Overloading.jav").toFile();
|
||||
var compiler = new JavaTXCompiler(file);
|
||||
var resultSet = compiler.typeInference(file);
|
||||
var converter = new ASTToTargetAST(compiler, resultSet);
|
||||
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||
|
||||
var classLoader = new ByteArrayClassLoader();
|
||||
var overloading = TestCodegen.generateClass(converter.convert(classes.get(0)), classLoader);
|
||||
var overloading2 = TestCodegen.generateClass(converter.convert(classes.get(1)), classLoader);
|
||||
|
||||
var test1 = overloading.getDeclaredMethod("test", overloading);
|
||||
test1.setAccessible(true);
|
||||
var test2 = overloading.getDeclaredMethod("test", overloading2);
|
||||
test2.setAccessible(true);
|
||||
Object overloadingInstance = overloading.getDeclaredConstructor().newInstance();
|
||||
Object overloading2Instance = overloading2.getDeclaredConstructor().newInstance();
|
||||
assertEquals(test1.invoke(overloadingInstance, overloadingInstance), "Overloading");
|
||||
assertEquals(test2.invoke(overloadingInstance, overloading2Instance), "Overloading2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tphsAndGenerics() throws Exception {
|
||||
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Tph2.jav").toFile();
|
||||
var compiler = new JavaTXCompiler(file);
|
||||
var resultSet = compiler.typeInference(file);
|
||||
var converter = new ASTToTargetAST(compiler, resultSet);
|
||||
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||
|
||||
var tphAndGenerics = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cycles() throws Exception {
|
||||
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Cycle.jav").toFile();
|
||||
var compiler = new JavaTXCompiler(file);
|
||||
var resultSet = compiler.typeInference(file);
|
||||
var converter = new ASTToTargetAST(compiler, resultSet);
|
||||
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||
|
||||
var cycle = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void infimum() throws Exception {
|
||||
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Infimum.jav").toFile();
|
||||
var compiler = new JavaTXCompiler(file);
|
||||
var resultSet = compiler.typeInference(file);
|
||||
var converter = new ASTToTargetAST(compiler, resultSet);
|
||||
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||
|
||||
var infimum = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gen() throws Exception {
|
||||
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Gen.jav").toFile();
|
||||
var compiler = new JavaTXCompiler(file);
|
||||
var resultSet = compiler.typeInference(file);
|
||||
var converter = new ASTToTargetAST(compiler, resultSet);
|
||||
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||
|
||||
var generics = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
||||
var m = generics.getDeclaredMethod("m", Vector.class);
|
||||
var mReturnType = m.getGenericReturnType();
|
||||
assertEquals(mReturnType, m.getParameters()[0].getParameterizedType());
|
||||
assertEquals(mReturnType, new TypeToken<Vector<Integer>>() {
|
||||
}.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void definedGenerics() throws Exception {
|
||||
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Generics.jav").toFile();
|
||||
var compiler = new JavaTXCompiler(file);
|
||||
var resultSet = compiler.typeInference(file);
|
||||
var converter = new ASTToTargetAST(compiler, resultSet);
|
||||
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||
|
||||
var generics = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
||||
var B = generics.getTypeParameters()[0];
|
||||
var mt1 = generics.getDeclaredMethod("mt1", Object.class);
|
||||
var constructor = generics.getDeclaredConstructor(Object.class);
|
||||
|
||||
assertEquals(B, mt1.getGenericReturnType());
|
||||
assertEquals(B, mt1.getParameters()[0].getParameterizedType());
|
||||
assertEquals(B, constructor.getParameters()[0].getParameterizedType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void definedGenerics2() throws Exception {
|
||||
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Generics2.jav").toFile();
|
||||
var compiler = new JavaTXCompiler(file);
|
||||
var resultSet = compiler.typeInference(file);
|
||||
var converter = new ASTToTargetAST(compiler, resultSet);
|
||||
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||
|
||||
var generics2 = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
||||
assertEquals(generics2.getTypeParameters()[0].getBounds()[0], String.class);
|
||||
var m = generics2.getDeclaredMethod("m1", Object.class);
|
||||
assertEquals(m.getTypeParameters()[0].getBounds()[0], Integer.class);
|
||||
var param = m.getTypeParameters()[0];
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Not implemented")
|
||||
public void definedGenerics3() throws Exception {
|
||||
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Generics3.jav").toFile();
|
||||
var compiler = new JavaTXCompiler(file);
|
||||
var resultSet = compiler.typeInference(file);
|
||||
var converter = new ASTToTargetAST(compiler, resultSet);
|
||||
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||
|
||||
var generics3 = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void definedGenerics4() throws Exception {
|
||||
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Generics4.jav").toFile();
|
||||
var compiler = new JavaTXCompiler(file);
|
||||
var resultSet = compiler.typeInference(file);
|
||||
var converter = new ASTToTargetAST(compiler, resultSet);
|
||||
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||
|
||||
var generics4 = TestCodegen.generateClass(converter.convert(classes.get(0)), new ByteArrayClassLoader());
|
||||
|
||||
// var instance = generics4.getDeclaredConstructor().newInstance();
|
||||
// var method = generics4.getDeclaredMethod("m2", Object.class);
|
||||
// method.invoke(instance, new Object());
|
||||
}
|
||||
}
|
@ -1,135 +0,0 @@
|
||||
package targetast;
|
||||
|
||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class GreaterEqualTest {
|
||||
static Class<?> classToTest;
|
||||
static Object instance;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "GreaterEqual.jav");
|
||||
classToTest = classFiles.get("GreaterEqual");
|
||||
instance = classToTest.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntegers() throws Exception {
|
||||
Method gE = classToTest.getDeclaredMethod("gE", Integer.class, Integer.class);
|
||||
gE.setAccessible(true);
|
||||
Boolean result = (Boolean) gE.invoke(instance, 7, 5);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntegers2() throws Exception {
|
||||
Method gE = classToTest.getDeclaredMethod("gE", Integer.class, Integer.class);
|
||||
gE.setAccessible(true);
|
||||
Boolean result = (Boolean) gE.invoke(instance, 5, 7);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqIntegers() throws Exception {
|
||||
Method gE = classToTest.getDeclaredMethod("gE", Integer.class, Integer.class);
|
||||
gE.setAccessible(true);
|
||||
Boolean result = (Boolean) gE.invoke(instance, 5, 5);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongs() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method gE = classToTest.getDeclaredMethod("gE", Long.class, Long.class);
|
||||
gE.setAccessible(true);
|
||||
Boolean result = (Boolean) gE.invoke(instance, 10L, 7L);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFloats() throws Exception {
|
||||
Method gE = classToTest.getDeclaredMethod("gE", Float.class, Float.class);
|
||||
gE.setAccessible(true);
|
||||
Boolean result = (Boolean) gE.invoke(instance, 5F, 7F);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubles() throws Exception {
|
||||
Method gE = classToTest.getDeclaredMethod("gE", Double.class, Double.class);
|
||||
gE.setAccessible(true);
|
||||
Boolean result = (Boolean) gE.invoke(instance, 5.0, 7.0);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongInt() throws Exception {
|
||||
Method gE = classToTest.getDeclaredMethod("gE", Long.class, Integer.class);
|
||||
gE.setAccessible(true);
|
||||
Boolean result = (Boolean) gE.invoke(instance, 15L, 7);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFloatInt() throws Exception {
|
||||
Method gE = classToTest.getDeclaredMethod("gE", Float.class, Integer.class);
|
||||
gE.setAccessible(true);
|
||||
Boolean result = (Boolean) gE.invoke(instance, 5F, 7);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleInt() throws Exception {
|
||||
Method gE = classToTest.getDeclaredMethod("gE", Double.class, Integer.class);
|
||||
gE.setAccessible(true);
|
||||
Boolean result = (Boolean) gE.invoke(instance, 25.0, 17);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFloatLong() throws Exception {
|
||||
Method gE = classToTest.getDeclaredMethod("gE", Float.class, Long.class);
|
||||
gE.setAccessible(true);
|
||||
Boolean result = (Boolean) gE.invoke(instance, 75F, 70L);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleLong() throws Exception {
|
||||
Method gE = classToTest.getDeclaredMethod("gE", Double.class, Long.class);
|
||||
gE.setAccessible(true);
|
||||
Boolean result = (Boolean) gE.invoke(instance, 5.0, 7L);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqDoubleFloat() throws Exception {
|
||||
Method gE = classToTest.getDeclaredMethod("gE", Double.class, Float.class);
|
||||
gE.setAccessible(true);
|
||||
Boolean result = (Boolean) gE.invoke(instance, 7.0, 7F);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleFloat() throws Exception {
|
||||
Method gE = classToTest.getDeclaredMethod("gE", Double.class, Float.class);
|
||||
gE.setAccessible(true);
|
||||
Boolean result = (Boolean) gE.invoke(instance, 15.0, 7F);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleFloat3() throws Exception {
|
||||
Method gE = classToTest.getDeclaredMethod("gE", Double.class, Float.class);
|
||||
gE.setAccessible(true);
|
||||
Boolean result = (Boolean) gE.invoke(instance, 9.0, 17F);
|
||||
assertFalse(result);
|
||||
}
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
package targetast;
|
||||
|
||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class GreaterThanTest {
|
||||
static Class<?> classToTest;
|
||||
static Object instance;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "GreaterThan.jav");
|
||||
classToTest = classFiles.get("GreaterThan");
|
||||
instance = classToTest.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntegers() throws Exception {
|
||||
Method gT = classToTest.getDeclaredMethod("gT", Integer.class, Integer.class);
|
||||
gT.setAccessible(true);
|
||||
Boolean result = (Boolean) gT.invoke(instance, 7, 5);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntegers2() throws Exception {
|
||||
Method gT = classToTest.getDeclaredMethod("gT", Integer.class, Integer.class);
|
||||
gT.setAccessible(true);
|
||||
Boolean result = (Boolean) gT.invoke(instance, 5, 7);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqIntegers() throws Exception {
|
||||
Method gT = classToTest.getDeclaredMethod("gT", Integer.class, Integer.class);
|
||||
gT.setAccessible(true);
|
||||
Boolean result = (Boolean) gT.invoke(instance, 5, 5);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongs() throws Exception {
|
||||
Method gT = classToTest.getDeclaredMethod("gT", Long.class, Long.class);
|
||||
gT.setAccessible(true);
|
||||
Boolean result = (Boolean) gT.invoke(instance, 10L,7L);
|
||||
assertTrue(result);
|
||||
}@Test
|
||||
|
||||
public void testFloats() throws Exception {
|
||||
Method gT = classToTest.getDeclaredMethod("gT", Float.class, Float.class);
|
||||
gT.setAccessible(true);
|
||||
Boolean result = (Boolean) gT.invoke(instance, 5F,7F);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubles() throws Exception {
|
||||
Method gT = classToTest.getDeclaredMethod("gT", Double.class, Double.class);
|
||||
gT.setAccessible(true);
|
||||
Boolean result = (Boolean) gT.invoke(instance, 5.0,7.0);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongInt() throws Exception {
|
||||
Method gT = classToTest.getDeclaredMethod("gT", Long.class, Integer.class);
|
||||
gT.setAccessible(true);
|
||||
Boolean result = (Boolean) gT.invoke(instance, 15L,7);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFloatInt() throws Exception {
|
||||
Method gT = classToTest.getDeclaredMethod("gT", Float.class, Integer.class);
|
||||
gT.setAccessible(true);
|
||||
Boolean result = (Boolean) gT.invoke(instance, 5F,7);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleInt() throws Exception {
|
||||
Method gT = classToTest.getDeclaredMethod("gT", Double.class, Integer.class);
|
||||
gT.setAccessible(true);
|
||||
Boolean result = (Boolean) gT.invoke(instance, 25.0,17);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFloatLong() throws Exception {
|
||||
Method gT = classToTest.getDeclaredMethod("gT", Float.class, Long.class);
|
||||
gT.setAccessible(true);
|
||||
Boolean result = (Boolean) gT.invoke(instance, 75F,70L);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleLong() throws Exception {
|
||||
Method gT = classToTest.getDeclaredMethod("gT", Double.class, Long.class);
|
||||
gT.setAccessible(true);
|
||||
Boolean result = (Boolean) gT.invoke(instance, 5.0,7L);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqDoubleFloat() throws Exception {
|
||||
Method gT = classToTest.getDeclaredMethod("gT", Double.class, Float.class);
|
||||
gT.setAccessible(true);
|
||||
Boolean result = (Boolean) gT.invoke(instance, 7.0,7F);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleFloat() throws Exception {
|
||||
Method gT = classToTest.getDeclaredMethod("gT", Double.class, Float.class);
|
||||
gT.setAccessible(true);
|
||||
Boolean result = (Boolean) gT.invoke(instance, 15.0,7F);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleFloat3() throws Exception {
|
||||
Method gT = classToTest.getDeclaredMethod("gT", Double.class, Float.class);
|
||||
gT.setAccessible(true);
|
||||
Boolean result = (Boolean) gT.invoke(instance, 9.0,17F);
|
||||
assertFalse(result);
|
||||
}
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
package targetast;
|
||||
|
||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Vector;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class InheritTest {
|
||||
private static Class<?> classToTest, classToTestAA, classToTestBB, classToTestCC, classToTestDD;
|
||||
private static Object instanceOfClass, instanceOfClassAA, instanceOfClassBB, instanceOfClassCC, instanceOfClassDD;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
var classLoader = new ByteArrayClassLoader();
|
||||
|
||||
var classes = TestCodegen.generateClassFiles(classLoader, "Inherit.jav");
|
||||
classToTest = classes.get("Inherit");
|
||||
classToTestAA = classes.get("AA");
|
||||
classToTestBB = classes.get("BB");
|
||||
classToTestCC = classes.get("CC");
|
||||
classToTestDD = classes.get("DD");
|
||||
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
instanceOfClassAA = classToTestAA.getDeclaredConstructor().newInstance();
|
||||
instanceOfClassBB = classToTestBB.getDeclaredConstructor().newInstance();
|
||||
instanceOfClassCC = classToTestCC.getDeclaredConstructor().newInstance();
|
||||
instanceOfClassDD = classToTestDD.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainAA() throws Exception {
|
||||
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
||||
assertEquals(m.invoke(instanceOfClassAA, 5), "AA");
|
||||
Method main = classToTest.getDeclaredMethod("main", classToTestAA, Integer.class);
|
||||
assertEquals(main.invoke(instanceOfClass, instanceOfClassAA, 5), "AA");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainBB() throws Exception {
|
||||
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
||||
assertEquals(m.invoke(instanceOfClassBB, 5), "AA");
|
||||
Method main = classToTest.getDeclaredMethod("main", classToTestAA, Integer.class);
|
||||
assertEquals(main.invoke(instanceOfClass, instanceOfClassBB, 5), "AA");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainCC() throws Exception {
|
||||
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
||||
assertEquals(m.invoke(instanceOfClassCC, 5), "CC");
|
||||
Method main = classToTest.getDeclaredMethod("main", classToTestCC, Integer.class);
|
||||
assertEquals(main.invoke(instanceOfClass, instanceOfClassCC, 5), "CC");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainDD() throws Exception {
|
||||
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
||||
assertEquals(m.invoke(instanceOfClassDD, 5), "CC");
|
||||
Method main = classToTest.getDeclaredMethod("main", classToTestCC, Integer.class);
|
||||
assertEquals(main.invoke(instanceOfClass, instanceOfClassDD, 5), "CC");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainVectorAA() throws Exception {
|
||||
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
||||
assertEquals(m.invoke(instanceOfClassAA, 5), "AA");
|
||||
Vector v = new Vector<>();
|
||||
v.add(instanceOfClassAA);
|
||||
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
||||
assertEquals(main.invoke(instanceOfClass, v, 5), "AA");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainVectorBB() throws Exception {
|
||||
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
||||
assertEquals(m.invoke(instanceOfClassBB, 5), "AA");
|
||||
Vector v = new Vector<>();
|
||||
v.add(instanceOfClassBB);
|
||||
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
||||
assertEquals(main.invoke(instanceOfClass, v, 5), "AA");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainVectorCC() throws Exception {
|
||||
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
||||
assertEquals(m.invoke(instanceOfClassCC, 5), "CC");
|
||||
Vector v = new Vector<>();
|
||||
v.add(instanceOfClassCC);
|
||||
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
||||
assertEquals(main.invoke(instanceOfClass, v, 5), "CC");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainVectorDD() throws Exception {
|
||||
Method m = classToTestCC.getDeclaredMethod("m", Integer.class);
|
||||
assertEquals(m.invoke(instanceOfClassDD, 5), "CC");
|
||||
Vector v = new Vector<>();
|
||||
v.add(instanceOfClassDD);
|
||||
Method main = classToTest.getDeclaredMethod("main", Vector.class, Integer.class);
|
||||
assertEquals(main.invoke(instanceOfClass, v, 5), "CC");
|
||||
}
|
||||
}
|
@ -1,121 +0,0 @@
|
||||
package targetast;
|
||||
|
||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Vector;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@Ignore("FIXME")
|
||||
public class InheritTest2 {
|
||||
private static Class<?> classToTest, classToTestAA, classToTestBB, classToTestCC, classToTestDD;
|
||||
private static Object instanceOfClass, instanceOfClassAA, instanceOfClassBB, instanceOfClassCC, instanceOfClassDD;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
var classLoader = new ByteArrayClassLoader();
|
||||
classToTest = TestCodegen.generateClassFiles(classLoader, "Inherit2.jav").get("Inherit2");
|
||||
classToTestAA = TestCodegen.generateClassFiles(classLoader, "AA.jav").get("AA");
|
||||
classToTestBB = TestCodegen.generateClassFiles(classLoader, "BB.jav").get("BB");
|
||||
classToTestCC = TestCodegen.generateClassFiles(classLoader, "CC.jav").get("CC");
|
||||
classToTestDD = TestCodegen.generateClassFiles(classLoader,"DD.jav").get("DD");
|
||||
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
instanceOfClassAA = classToTestAA.getDeclaredConstructor().newInstance();
|
||||
instanceOfClassBB = classToTestBB.getDeclaredConstructor().newInstance();
|
||||
instanceOfClassCC = classToTestCC.getDeclaredConstructor().newInstance();
|
||||
instanceOfClassDD = classToTestDD.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainAA() throws Exception {
|
||||
Method m2 = classToTestAA.getDeclaredMethod("m2", classToTestAA);
|
||||
assertEquals(m2.invoke(instanceOfClassAA, instanceOfClassAA), "AA");
|
||||
Method main = classToTest.getDeclaredMethod("main", classToTestAA);
|
||||
assertEquals(main.invoke(instanceOfClass, instanceOfClassAA), "AA");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainBB() throws Exception {
|
||||
Method m2 = classToTestAA.getDeclaredMethod("m2", classToTestAA);
|
||||
assertEquals(m2.invoke(instanceOfClassAA, instanceOfClassAA), "AA");
|
||||
Method main = classToTest.getDeclaredMethod("main", classToTestAA);
|
||||
assertEquals(main.invoke(instanceOfClass, instanceOfClassBB), "AA");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainCC() throws Exception {
|
||||
Method m2 = classToTestCC.getDeclaredMethod("m2", classToTestCC);
|
||||
assertEquals(m2.invoke(instanceOfClassCC, instanceOfClassCC), "CC");
|
||||
Method main = classToTest.getDeclaredMethod("main", classToTestCC);
|
||||
assertEquals(main.invoke(instanceOfClass, instanceOfClassCC), "CC");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainDD() throws Exception {
|
||||
Method m2 = classToTestCC.getDeclaredMethod("m2", classToTestCC);
|
||||
assertEquals(m2.invoke(instanceOfClassCC, instanceOfClassCC), "CC");
|
||||
Method main = classToTest.getDeclaredMethod("main", classToTestCC);
|
||||
assertEquals(main.invoke(instanceOfClass, instanceOfClassDD), "CC");
|
||||
}
|
||||
|
||||
|
||||
//PL 2020-05-12: Die folgenden Test funktionieren erst, wenn Generics im Bytecode implementiert sind
|
||||
@Test
|
||||
public void testmainVectorAA() throws Exception {
|
||||
Method m2 = classToTestAA.getDeclaredMethod("m2", classToTestAA);
|
||||
assertEquals(m2.invoke(instanceOfClassAA, instanceOfClassAA), "AA");
|
||||
Vector v = new Vector<>();
|
||||
v.add(instanceOfClassAA);
|
||||
Method main = classToTest.getDeclaredMethod("main", Vector.class);
|
||||
try {
|
||||
assertEquals(main.invoke(instanceOfClass, v), "AA");
|
||||
}
|
||||
catch (java.lang.reflect.InvocationTargetException e) {
|
||||
testmainVectorCC();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainVectorBB() throws Exception {
|
||||
Method m2 = classToTestAA.getDeclaredMethod("m2", classToTestAA);
|
||||
assertEquals(m2.invoke(instanceOfClassAA, instanceOfClassAA), "AA");
|
||||
Vector v = new Vector<>();
|
||||
v.add(instanceOfClassBB);
|
||||
Method main = classToTest.getDeclaredMethod("main", Vector.class);
|
||||
try {
|
||||
assertEquals(main.invoke(instanceOfClass, v), "AA");
|
||||
}
|
||||
catch (java.lang.reflect.InvocationTargetException e) {
|
||||
testmainVectorCC();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainVectorCC() throws Exception {
|
||||
Method m2 = classToTestCC.getDeclaredMethod("m2", classToTestCC);
|
||||
assertEquals(m2.invoke(instanceOfClassCC, instanceOfClassCC), "CC");
|
||||
Vector v = new Vector<>();
|
||||
v.add(instanceOfClassCC);
|
||||
Method main = classToTest.getDeclaredMethod("main", Vector.class);
|
||||
String erg;
|
||||
assertEquals(erg= (String) main.invoke(instanceOfClass, v),
|
||||
erg.equals("CC")? "CC": "AA");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainVectorDD() throws Exception {
|
||||
Method m2 = classToTestCC.getDeclaredMethod("m2", classToTestCC);
|
||||
assertEquals(m2.invoke(instanceOfClassCC, instanceOfClassCC), "CC");
|
||||
Vector v = new Vector<>();
|
||||
v.add(instanceOfClassDD);
|
||||
Method main = classToTest.getDeclaredMethod("main", Vector.class);
|
||||
String erg;
|
||||
assertEquals(erg= (String) main.invoke(instanceOfClass, v),
|
||||
erg.equals("CC")? "CC": "AA");
|
||||
}
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
package targetast;
|
||||
|
||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class LessEqualTest {
|
||||
static Class<?> classToTest;
|
||||
static Object instance;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "LessEqual.jav");
|
||||
classToTest = classFiles.get("LessEqual");
|
||||
instance = classToTest.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntegers() throws Exception {
|
||||
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Integer.class, Integer.class);
|
||||
Boolean result = (Boolean) lessEqual.invoke(instance, 5,7);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualIntegers() throws Exception {
|
||||
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Integer.class, Integer.class);
|
||||
Boolean result = (Boolean) lessEqual.invoke(instance, 5,5);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongs() throws Exception {
|
||||
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Long.class, Long.class);
|
||||
Boolean result = (Boolean) lessEqual.invoke(instance, 5L,7L);
|
||||
assertTrue(result);
|
||||
}@Test
|
||||
|
||||
public void testFloats() throws Exception {
|
||||
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Float.class, Float.class);
|
||||
Boolean result = (Boolean) lessEqual.invoke(instance, 5F,7F);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubles() throws Exception {
|
||||
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Double.class);
|
||||
Boolean result = (Boolean) lessEqual.invoke(instance, 5.0,7.0);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongInt() throws Exception {
|
||||
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Long.class, Integer.class);
|
||||
Boolean result = (Boolean) lessEqual.invoke(instance, 5L,7);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFloatInt() throws Exception {
|
||||
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Float.class, Integer.class);
|
||||
Boolean result = (Boolean) lessEqual.invoke(instance, 5F,7);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleInt() throws Exception {
|
||||
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Integer.class);
|
||||
Boolean result = (Boolean) lessEqual.invoke(instance, 5.0,7);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFloatLong() throws Exception {
|
||||
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Float.class, Long.class);
|
||||
Boolean result = (Boolean) lessEqual.invoke(instance, 5F,7L);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleLong() throws Exception {
|
||||
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Long.class);
|
||||
Boolean result = (Boolean) lessEqual.invoke(instance, 5.0,7L);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqDoubleFloat() throws Exception {
|
||||
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Float.class);
|
||||
Boolean result = (Boolean) lessEqual.invoke(instance, 7.0,7F);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleFloat() throws Exception {
|
||||
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Float.class);
|
||||
Boolean result = (Boolean) lessEqual.invoke(instance, 5.0,7F);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleFloat3() throws Exception {
|
||||
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Float.class);
|
||||
Boolean result = (Boolean) lessEqual.invoke(instance, 9.0,7F);
|
||||
assertFalse(result);
|
||||
}
|
||||
}
|
@ -1,120 +0,0 @@
|
||||
package targetast;
|
||||
|
||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class LessThanTest {
|
||||
static Class<?> classToTest;
|
||||
static Object instance;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "LessThan.jav");
|
||||
classToTest = classFiles.get("LessThan");
|
||||
instance = classToTest.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLessThanInt() throws Exception {
|
||||
Method lessThan = classToTest.getDeclaredMethod("lessThan", Integer.class,Integer.class);
|
||||
Boolean result = (Boolean) lessThan.invoke(instance, 5, 7);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLessThanInt2() throws Exception {
|
||||
Method lessThan = classToTest.getDeclaredMethod("lessThan", Integer.class, Integer.class);
|
||||
Boolean result = (Boolean) lessThan.invoke(instance, 7, 5);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLessThanInt3() throws Exception {
|
||||
Method lessThan = classToTest.getDeclaredMethod("lessThan", Integer.class, Integer.class);
|
||||
Boolean result = (Boolean) lessThan.invoke(instance, 5, 5);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLessThanLong() throws Exception {
|
||||
Method lessThan = classToTest.getDeclaredMethod("lessThan", Long.class,Long.class);
|
||||
Boolean result = (Boolean) lessThan.invoke(instance, 5L, 7L);
|
||||
assertTrue(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLessThanLong2() throws Exception {
|
||||
Method lessThan = classToTest.getDeclaredMethod("lessThan", Long.class, Long.class);
|
||||
Boolean result = (Boolean) lessThan.invoke(instance, 7L, 5L);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLessThanLong3() throws Exception {
|
||||
Method lessThan = classToTest.getDeclaredMethod("lessThan", Long.class, Long.class);
|
||||
Boolean result = (Boolean) lessThan.invoke(instance, 5L, 5L);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLessThanFloat() throws Exception {
|
||||
Method lessThan = classToTest.getDeclaredMethod("lessThan", Float.class, Float.class);
|
||||
Boolean result = (Boolean) lessThan.invoke(instance, 7F, 5F);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLessThanDouble() throws Exception {
|
||||
Method lessThan = classToTest.getDeclaredMethod("lessThan", Double.class, Double.class);
|
||||
Boolean result = (Boolean) lessThan.invoke(instance, 7.0, 5.0);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLessThanLongInt() throws Exception {
|
||||
Method lessThan = classToTest.getDeclaredMethod("lessThan", Long.class, Integer.class);
|
||||
Boolean result = (Boolean) lessThan.invoke(instance, 7L, 5);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLessThanFloatInt() throws Exception {
|
||||
Method lessThan = classToTest.getDeclaredMethod("lessThan", Float.class, Integer.class);
|
||||
Boolean result = (Boolean) lessThan.invoke(instance, 7F, 5);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLessThanDoubleInt() throws Exception {
|
||||
Method lessThan = classToTest.getDeclaredMethod("lessThan", Double.class, Integer.class);
|
||||
Boolean result = (Boolean) lessThan.invoke(instance, 7.0, 5);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLessThanFloatLong() throws Exception {
|
||||
Method lessThan = classToTest.getDeclaredMethod("lessThan", Float.class, Long.class);
|
||||
Boolean result = (Boolean) lessThan.invoke(instance, 7F, 5L);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLessThanDoubleLong() throws Exception {
|
||||
Method lessThan = classToTest.getDeclaredMethod("lessThan", Double.class, Long.class);
|
||||
Boolean result = (Boolean) lessThan.invoke(instance, 7.0, 5L);
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLessThanDoubleFloat() throws Exception {
|
||||
Method lessThan = classToTest.getDeclaredMethod("lessThan", Double.class, Float.class);
|
||||
Boolean result = (Boolean) lessThan.invoke(instance, 7.0, 5F);
|
||||
assertFalse(result);
|
||||
}
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
package targetast;
|
||||
|
||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class OLTest {
|
||||
private static Class<?> classToTest;
|
||||
private static Class<?> classToTest1;
|
||||
private static Object instanceOfClass;
|
||||
private static Object instanceOfClass1;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "OL.jav");
|
||||
classToTest = classFiles.get("OL");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
classToTest1 = classFiles.get("OLMain");
|
||||
instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmInt() throws Exception {
|
||||
Method m = classToTest.getDeclaredMethod("m", Integer.class);
|
||||
Integer result = (Integer) m.invoke(instanceOfClass, 5);
|
||||
assertEquals(new Integer(10), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmDouble() throws Exception {
|
||||
Method m = classToTest.getDeclaredMethod("m", Double.class);
|
||||
Double result = (Double) m.invoke(instanceOfClass, 5.0);
|
||||
assertEquals(new Double(10.0), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmString() throws Exception {
|
||||
Method m = classToTest.getDeclaredMethod("m", String.class);
|
||||
String result = (String) m.invoke(instanceOfClass, "xxx");
|
||||
assertEquals("xxxxxx", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOLMainClassName() {
|
||||
assertEquals("OLMain", classToTest1.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainInt() throws Exception {
|
||||
Method main = classToTest1.getDeclaredMethod("main", Integer.class);
|
||||
Integer result = (Integer) main.invoke(instanceOfClass1, 5);
|
||||
assertEquals(Integer.valueOf(10), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainDouble() throws Exception {
|
||||
Method main = classToTest1.getDeclaredMethod("main", Double.class);
|
||||
Double result = (Double) main.invoke(instanceOfClass1, 5.0);
|
||||
assertEquals(Double.valueOf(10.0), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testmainString() throws Exception {
|
||||
Method main = classToTest1.getDeclaredMethod("main", String.class);
|
||||
String result = (String) main.invoke(instanceOfClass1, "xxx");
|
||||
assertEquals("xxxxxx", result);
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package targetast;
|
||||
|
||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class PostIncTest {
|
||||
private static Class<?> classToTest;
|
||||
private static Object instanceOfClass;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "PostIncDec.jav");
|
||||
classToTest = classFiles.get("PostIncDec");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testM1() throws Exception {
|
||||
Method m = classToTest.getDeclaredMethod("m");
|
||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||
assertEquals(Integer.valueOf(1), res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testM2() throws Exception {
|
||||
Method m = classToTest.getDeclaredMethod("m2");
|
||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||
assertEquals(Integer.valueOf(0), res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testD1() throws Exception {
|
||||
Method m = classToTest.getDeclaredMethod("d");
|
||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||
assertEquals(Integer.valueOf(-1), res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testD2() throws Exception {
|
||||
Method m = classToTest.getDeclaredMethod("d2");
|
||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||
assertEquals(Integer.valueOf(0), res);
|
||||
}
|
||||
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package targetast;
|
||||
|
||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class PreIncTest {
|
||||
private static Class<?> classToTest;
|
||||
private static Object instanceOfClass;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "PreInc.jav");
|
||||
classToTest = classFiles.get("PreInc");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testM() throws Exception {
|
||||
Method m = classToTest.getDeclaredMethod("m");
|
||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||
assertEquals(Integer.valueOf(1), res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testM2() throws Exception {
|
||||
Method m = classToTest.getDeclaredMethod("m2");
|
||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||
assertEquals(Integer.valueOf(1), res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testD() throws Exception {
|
||||
Method m = classToTest.getDeclaredMethod("d");
|
||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||
assertEquals(Integer.valueOf(-1), res);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testD2() throws Exception {
|
||||
Method m = classToTest.getDeclaredMethod("d2");
|
||||
Integer res = (Integer) m.invoke(instanceOfClass);
|
||||
assertEquals(Integer.valueOf(-1), res);
|
||||
}
|
||||
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package targetast;
|
||||
|
||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Stack;
|
||||
import java.util.Vector;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class PutTest {
|
||||
private static Class<?> classToTest;
|
||||
private static Object instanceOfClass;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "Put.jav");
|
||||
classToTest = classFiles.get("Put");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPutElementVector() throws Exception {
|
||||
Method m = classToTest.getDeclaredMethod("putElement", Object.class, Vector.class);
|
||||
Vector<Integer> v_invoke = new Vector<>();
|
||||
m.invoke(instanceOfClass, 5, v_invoke);
|
||||
Vector<Integer> v = new Vector<>();
|
||||
v.add(5);
|
||||
assertEquals(v, v_invoke);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPutElementStack() throws Exception {
|
||||
Method m = classToTest.getDeclaredMethod("putElement", Object.class, Stack.class);
|
||||
Stack<Integer> s_invoke = new Stack<>();
|
||||
m.invoke(instanceOfClass, 5, s_invoke);
|
||||
assertEquals(new Integer(5), s_invoke.pop());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMainVector() throws Exception {
|
||||
Method m = classToTest.getDeclaredMethod("main", Object.class, Vector.class);
|
||||
Vector<Integer> v_invoke = new Vector<>();
|
||||
m.invoke(instanceOfClass, 6, v_invoke);
|
||||
Vector<Integer> v = new Vector<>();
|
||||
v.add(6);
|
||||
assertEquals(v, v_invoke);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMainStack() throws Exception {
|
||||
Method m = classToTest.getDeclaredMethod("main", Object.class, Stack.class);
|
||||
Stack<Integer> s_invoke = new Stack<>();
|
||||
m.invoke(instanceOfClass, 6, s_invoke);
|
||||
assertEquals(new Integer(6), s_invoke.pop());
|
||||
}
|
||||
}
|
@ -1,290 +0,0 @@
|
||||
package targetast;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.bytecode.Codegen;
|
||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
||||
import de.dhbwstuttgart.environment.IByteArrayClassLoader;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
|
||||
import de.dhbwstuttgart.target.tree.MethodParameter;
|
||||
import de.dhbwstuttgart.target.tree.TargetClass;
|
||||
import de.dhbwstuttgart.target.tree.TargetMethod;
|
||||
import de.dhbwstuttgart.target.tree.TargetStructure;
|
||||
import de.dhbwstuttgart.target.tree.expression.*;
|
||||
import de.dhbwstuttgart.target.tree.type.TargetFunNType;
|
||||
import de.dhbwstuttgart.target.tree.type.TargetRefType;
|
||||
import de.dhbwstuttgart.target.tree.type.TargetType;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TestCodegen {
|
||||
static final Path outputPath = Path.of(System.getProperty("user.dir"), "/targetTest");
|
||||
|
||||
private static void writeClassFile(String name, byte[] code) throws IOException {
|
||||
Files.createDirectories(outputPath);
|
||||
Files.write(outputPath.resolve(name + ".class"), code);
|
||||
}
|
||||
|
||||
public static Path path = Path.of(System.getProperty("user.dir"), "resources/bytecode/javFiles/");
|
||||
|
||||
public static Map<String, ? extends Class<?>> generateClassFiles(IByteArrayClassLoader classLoader, String... files) throws IOException, ClassNotFoundException {
|
||||
Files.createDirectories(outputPath);
|
||||
var filenames = Arrays.stream(files).map(filename -> Path.of(path.toString(), filename).toFile()).toList();
|
||||
var compiler = new JavaTXCompiler(filenames, List.of(path.toFile(), outputPath.toFile()), outputPath.toFile());
|
||||
|
||||
var result = new HashMap<String, Class<?>>();
|
||||
for (var file : filenames) {
|
||||
var resultSet = compiler.typeInference(file);
|
||||
|
||||
var sourceFile = compiler.sourceFiles.get(file);
|
||||
var converter = new ASTToTargetAST(compiler, resultSet, sourceFile, classLoader);
|
||||
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||
|
||||
result.putAll(classes.stream().map(cli -> {
|
||||
try {
|
||||
return generateClass(converter.convert(cli), classLoader, converter);
|
||||
} catch (IOException exception) {
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
}).collect(Collectors.toMap(Class::getName, Function.identity())));
|
||||
|
||||
converter.generateFunNTypes();
|
||||
|
||||
for (var entry : converter.auxiliaries.entrySet()) {
|
||||
writeClassFile(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
for (var entry : compiler.loadedClasses.entrySet()) {
|
||||
var name = entry.getKey().toString();
|
||||
result.put(name, classLoader.loadClass(Path.of(entry.getValue().classFile().toURI())));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Class<?> generateClass(TargetStructure clazz, IByteArrayClassLoader classLoader) throws IOException, ClassNotFoundException {
|
||||
Codegen codegen = new Codegen(clazz, new JavaTXCompiler(List.of()), null);
|
||||
var code = codegen.generate();
|
||||
writeClassFile(clazz.qualifiedName().getClassName(), code);
|
||||
return classLoader.loadClass(code);
|
||||
}
|
||||
|
||||
public static Class<?> generateClass(TargetStructure clazz, IByteArrayClassLoader classLoader, ASTToTargetAST converter) throws IOException {
|
||||
Codegen codegen = new Codegen(clazz, converter.compiler, converter);
|
||||
var code = codegen.generate();
|
||||
writeClassFile(clazz.qualifiedName().getClassName(), code);
|
||||
return classLoader.loadClass(code);
|
||||
}
|
||||
|
||||
public static Map<String, ? extends Class<?>> generateClassFiles(String filename, IByteArrayClassLoader classLoader) throws IOException, ClassNotFoundException {
|
||||
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/", filename).toFile();
|
||||
var compiler = new JavaTXCompiler(List.of(file), List.of(file.getParentFile()), outputPath.toFile());
|
||||
var resultSet = compiler.typeInference(file);
|
||||
|
||||
var sourceFile = compiler.sourceFiles.get(file);
|
||||
var converter = new ASTToTargetAST(compiler, resultSet, sourceFile, classLoader);
|
||||
var classes = compiler.sourceFiles.get(file).getClasses();
|
||||
|
||||
var result = classes.stream().map(cli -> {
|
||||
try {
|
||||
return generateClass(converter.convert(cli), classLoader, converter);
|
||||
} catch (IOException exception) {
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
}).collect(Collectors.toMap(Class::getName, Function.identity()));
|
||||
|
||||
converter.generateFunNTypes();
|
||||
|
||||
for (var entry : converter.auxiliaries.entrySet()) {
|
||||
writeClassFile(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyClass() throws Exception {
|
||||
var clazz = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("Empty"));
|
||||
clazz.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "main", List.of(), null, new TargetBlock(List.of()));
|
||||
generateClass(clazz, new ByteArrayClassLoader()).getDeclaredMethod("main").invoke(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArithmetic() throws Exception {
|
||||
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("Arithmetic"));
|
||||
|
||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "add", List.of(new MethodParameter(TargetType.Integer, "a"), new MethodParameter(TargetType.Integer, "b")), TargetType.Integer, new TargetBlock(List.of(new TargetReturn(new TargetBinaryOp.Add(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "a"), new TargetLocalVar(TargetType.Integer, "b"))))));
|
||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "sub", List.of(new MethodParameter(TargetType.Integer, "a"), new MethodParameter(TargetType.Integer, "b")), TargetType.Integer, new TargetBlock(List.of(new TargetReturn(new TargetBinaryOp.Sub(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "a"), new TargetLocalVar(TargetType.Integer, "b"))))));
|
||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "div", List.of(new MethodParameter(TargetType.Integer, "a"), new MethodParameter(TargetType.Integer, "b")), TargetType.Integer, new TargetBlock(List.of(new TargetReturn(new TargetBinaryOp.Div(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "a"), new TargetLocalVar(TargetType.Integer, "b"))))));
|
||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "mul", List.of(new MethodParameter(TargetType.Integer, "a"), new MethodParameter(TargetType.Integer, "b")), TargetType.Integer, new TargetBlock(List.of(new TargetReturn(new TargetBinaryOp.Mul(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "a"), new TargetLocalVar(TargetType.Integer, "b"))))));
|
||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "rem", List.of(new MethodParameter(TargetType.Integer, "a"), new MethodParameter(TargetType.Integer, "b")), TargetType.Integer, new TargetBlock(List.of(new TargetReturn(new TargetBinaryOp.Rem(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "a"), new TargetLocalVar(TargetType.Integer, "b"))))));
|
||||
|
||||
var clazz = generateClass(targetClass, new ByteArrayClassLoader());
|
||||
assertEquals(clazz.getDeclaredMethod("add", Integer.class, Integer.class).invoke(null, 10, 10), 20);
|
||||
assertEquals(clazz.getDeclaredMethod("sub", Integer.class, Integer.class).invoke(null, 20, 10), 10);
|
||||
assertEquals(clazz.getDeclaredMethod("div", Integer.class, Integer.class).invoke(null, 20, 10), 2);
|
||||
assertEquals(clazz.getDeclaredMethod("mul", Integer.class, Integer.class).invoke(null, 20, 10), 200);
|
||||
assertEquals(clazz.getDeclaredMethod("rem", Integer.class, Integer.class).invoke(null, 10, 3), 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnary() throws Exception {
|
||||
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("Unary"));
|
||||
|
||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "not", List.of(new MethodParameter(TargetType.Integer, "a")), TargetType.Integer, new TargetBlock(List.of(new TargetReturn(new TargetUnaryOp.Not(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "a"))))));
|
||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "neg", List.of(new MethodParameter(TargetType.Integer, "a")), TargetType.Integer, new TargetBlock(List.of(new TargetReturn(new TargetUnaryOp.Negate(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "a"))))));
|
||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "add", List.of(new MethodParameter(TargetType.Integer, "a")), TargetType.Integer, new TargetBlock(List.of(new TargetReturn(new TargetUnaryOp.Add(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "a"))))));
|
||||
|
||||
var clazz = generateClass(targetClass, new ByteArrayClassLoader());
|
||||
assertEquals(clazz.getDeclaredMethod("not", Integer.class).invoke(null, 10), -11);
|
||||
assertEquals(clazz.getDeclaredMethod("neg", Integer.class).invoke(null, 10), -10);
|
||||
assertEquals(clazz.getDeclaredMethod("add", Integer.class).invoke(null, 10), 10);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConditional() throws Exception {
|
||||
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("Conditional"));
|
||||
|
||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "and", List.of(new MethodParameter(TargetType.Boolean, "a"), new MethodParameter(TargetType.Boolean, "b")), TargetType.Boolean, new TargetBlock(List.of(new TargetReturn(new TargetBinaryOp.And(TargetType.Boolean, new TargetLocalVar(TargetType.Boolean, "a"), new TargetLocalVar(TargetType.Boolean, "b"))))));
|
||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "or", List.of(new MethodParameter(TargetType.Boolean, "a"), new MethodParameter(TargetType.Boolean, "b")), TargetType.Boolean, new TargetBlock(List.of(new TargetReturn(new TargetBinaryOp.Or(TargetType.Boolean, new TargetLocalVar(TargetType.Boolean, "a"), new TargetLocalVar(TargetType.Boolean, "b"))))));
|
||||
|
||||
var clazz = generateClass(targetClass, new ByteArrayClassLoader());
|
||||
var and = clazz.getDeclaredMethod("and", Boolean.class, Boolean.class);
|
||||
var or = clazz.getDeclaredMethod("or", Boolean.class, Boolean.class);
|
||||
assertEquals(and.invoke(null, true, false), false);
|
||||
assertEquals(and.invoke(null, true, true), true);
|
||||
assertEquals(or.invoke(null, false, false), false);
|
||||
assertEquals(or.invoke(null, true, false), true);
|
||||
}
|
||||
|
||||
// When adding two numbers and the return type is Long it needs to convert both values to Long
|
||||
@Test
|
||||
public void testArithmeticConvert() throws Exception {
|
||||
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("ArithmeticConvert"));
|
||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "add", List.of(), TargetType.Long, new TargetBlock(List.of(new TargetReturn(new TargetBinaryOp.Add(TargetType.Long, new TargetLiteral.CharLiteral((char) 10), new TargetLiteral.LongLiteral((long) 20))))));
|
||||
var clazz = generateClass(targetClass, new ByteArrayClassLoader());
|
||||
assertEquals(clazz.getDeclaredMethod("add").invoke(null), (long) 30);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodCall() throws Exception {
|
||||
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("HelloWorld"));
|
||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "helloWorld", List.of(), null, new TargetBlock(List.of(new TargetMethodCall(null, new TargetFieldVar(new TargetRefType("java.io.PrintStream"), new TargetRefType("java.lang.System"), true, new TargetClassName(new TargetRefType("java.lang.System")), "out"), List.of(new TargetLiteral.StringLiteral("Hello World!")), new TargetRefType("java.io.PrintStream"), "println", false, false, false))));
|
||||
|
||||
var clazz = generateClass(targetClass, new ByteArrayClassLoader());
|
||||
clazz.getDeclaredMethod("helloWorld").invoke(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIfStatement() throws Exception {
|
||||
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("IfStmt"));
|
||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "ifStmt", List.of(new MethodParameter(TargetType.Integer, "val")), TargetType.Integer, new TargetBlock(List.of(new TargetIf(new TargetBinaryOp.Equal(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "val"), new TargetLiteral.IntLiteral(10)), new TargetReturn(new TargetLiteral.IntLiteral(1)), new TargetIf(new TargetBinaryOp.Less(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "val"), new TargetLiteral.IntLiteral(5)), new TargetReturn(new TargetLiteral.IntLiteral(2)), new TargetReturn(new TargetLiteral.IntLiteral(3)))))));
|
||||
var clazz = generateClass(targetClass, new ByteArrayClassLoader());
|
||||
var ifStmt = clazz.getDeclaredMethod("ifStmt", Integer.class);
|
||||
assertEquals(ifStmt.invoke(null, 10), 1);
|
||||
assertEquals(ifStmt.invoke(null, 3), 2);
|
||||
assertEquals(ifStmt.invoke(null, 20), 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFor() throws Exception {
|
||||
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("For"));
|
||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "forLoop", List.of(), TargetType.Integer, new TargetBlock(List.of(new TargetVarDecl(TargetType.Integer, "sum", new TargetLiteral.IntLiteral(0)), new TargetFor(List.of(new TargetVarDecl(TargetType.Integer, "i", new TargetLiteral.IntLiteral(0))), new TargetBinaryOp.Less(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "i"), new TargetLiteral.IntLiteral(10)), List.of(new TargetAssign(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "i"), new TargetBinaryOp.Add(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "i"), new TargetLiteral.IntLiteral(1)))), new TargetBlock(List.of(new TargetAssign(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "sum"), new TargetBinaryOp.Add(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "sum"), new TargetLocalVar(TargetType.Integer, "i")))))), new TargetReturn(new TargetLocalVar(TargetType.Integer, "sum")))));
|
||||
var clazz = generateClass(targetClass, new ByteArrayClassLoader());
|
||||
assertEquals(clazz.getDeclaredMethod("forLoop").invoke(null), 45);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhile() throws Exception {
|
||||
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("While"));
|
||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "whileLoop", List.of(), TargetType.Integer, new TargetBlock(List.of(new TargetVarDecl(TargetType.Integer, "i", new TargetLiteral.IntLiteral(0)), new TargetWhile(new TargetBinaryOp.Less(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "i"), new TargetLiteral.IntLiteral(10)), new TargetBlock(List.of(new TargetAssign(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "i"), new TargetBinaryOp.Add(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "i"), new TargetLiteral.IntLiteral(1)))))), new TargetReturn(new TargetLocalVar(TargetType.Integer, "i")))));
|
||||
var clazz = generateClass(targetClass, new ByteArrayClassLoader());
|
||||
assertEquals(clazz.getDeclaredMethod("whileLoop").invoke(null), 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassicSwitch() throws Exception {
|
||||
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC , new JavaClassName("SwitchClassic"));
|
||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "switchClassic", List.of(new MethodParameter(TargetType.Integer, "i")), TargetType.Integer, new TargetBlock(List.of(
|
||||
new TargetVarDecl(TargetType.Integer, "res", null),
|
||||
new TargetSwitch(new TargetLocalVar(TargetType.Integer, "i"), List.of(
|
||||
new TargetSwitch.Case(List.of(new TargetLiteral.IntLiteral(10)), new TargetBlock(
|
||||
List.of(new TargetAssign(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "res"), new TargetLiteral.IntLiteral(0)), new TargetBreak())
|
||||
)),
|
||||
new TargetSwitch.Case(List.of(new TargetLiteral.IntLiteral(15), new TargetLiteral.IntLiteral(20)), new TargetBlock(List.of())),
|
||||
new TargetSwitch.Case(List.of(new TargetLiteral.IntLiteral(30)), new TargetBlock(
|
||||
List.of(new TargetAssign(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "res"), new TargetLiteral.IntLiteral(1)), new TargetBreak())
|
||||
))
|
||||
), new TargetSwitch.Case(new TargetBlock(
|
||||
List.of(new TargetAssign(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "res"), new TargetLiteral.IntLiteral(2)), new TargetBreak())
|
||||
), false)),
|
||||
new TargetReturn(new TargetLocalVar(TargetType.Integer, "res"))
|
||||
)));
|
||||
|
||||
var clazz = generateClass(targetClass, new ByteArrayClassLoader());
|
||||
var m = clazz.getDeclaredMethod("switchClassic", Integer.class);
|
||||
assertEquals(m.invoke(null, 10), 0);
|
||||
assertEquals(m.invoke(null, 15), 1);
|
||||
assertEquals(m.invoke(null, 20), 1);
|
||||
assertEquals(m.invoke(null, 30), 1);
|
||||
assertEquals(m.invoke(null, 99), 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeSwitch() throws Exception {
|
||||
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("SwitchEnhanced"));
|
||||
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "switchType", List.of(new MethodParameter(TargetType.Object, "obj")), TargetType.Integer, new TargetBlock(List.of(
|
||||
new TargetReturn(new TargetSwitch(new TargetLocalVar(TargetType.Object, "obj"), List.of(
|
||||
new TargetSwitch.Case(List.of(new TargetTypePattern(TargetType.String, "aString")), new TargetBlock(
|
||||
List.of(new TargetYield(new TargetLiteral.IntLiteral(0)))
|
||||
), false),
|
||||
new TargetSwitch.Case(List.of(
|
||||
new TargetGuard(new TargetTypePattern(TargetType.Integer, "i"), new TargetBinaryOp.Less(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "i"), new TargetLiteral.IntLiteral(10)))
|
||||
), new TargetBlock(
|
||||
List.of(new TargetLiteral.IntLiteral(3))
|
||||
), true),
|
||||
new TargetSwitch.Case(List.of(new TargetTypePattern(TargetType.Integer, "anInteger")), new TargetBlock(
|
||||
List.of(new TargetLiteral.IntLiteral(1))
|
||||
), true)
|
||||
), new TargetSwitch.Case(new TargetBlock(
|
||||
List.of(new TargetLiteral.IntLiteral(2))
|
||||
), true), TargetType.Integer)
|
||||
))));
|
||||
var clazz = generateClass(targetClass, new ByteArrayClassLoader());
|
||||
var m = clazz.getDeclaredMethod("switchType", Object.class);
|
||||
assertEquals(m.invoke(null, "String"), 0);
|
||||
assertEquals(m.invoke(null, 10), 1);
|
||||
assertEquals(m.invoke(null, 'A'), 2);
|
||||
assertEquals(m.invoke(null, 5), 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("The lambda class is not generated because we don't call ASTToTargetAST")
|
||||
public void testLambda() throws Exception {
|
||||
var classLoader = new ByteArrayClassLoader();
|
||||
// var fun = classLoader.loadClass(Path.of(System.getProperty("user.dir"), "src/test/java/targetast/Fun1$$.class"));
|
||||
var interfaceType = TargetFunNType.fromParams(List.of(TargetType.Integer), 1);
|
||||
|
||||
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, new JavaClassName("CGLambda"));
|
||||
targetClass.addConstructor(Opcodes.ACC_PUBLIC, List.of(), new TargetBlock(List.of(new TargetMethodCall(null, new TargetSuper(TargetType.Object), List.of(), TargetType.Object, "<init>", false, false, false))));
|
||||
var signature = new TargetMethod.Signature(Set.of(), List.of(new MethodParameter(TargetType.Integer, "num")), TargetType.Integer);
|
||||
targetClass.addMethod(Opcodes.ACC_PUBLIC, "lambda", List.of(), TargetType.Integer, new TargetBlock(List.of(new TargetVarDecl(interfaceType, "by2", new TargetLambdaExpression(interfaceType, List.of(), signature, new TargetBlock(List.of(new TargetReturn(new TargetBinaryOp.Mul(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "num"), new TargetLiteral.IntLiteral(2))))))), new TargetReturn(new TargetCast(TargetType.Integer, new TargetMethodCall(TargetType.Object, TargetType.Object, List.of(TargetType.Object), new TargetLocalVar(interfaceType, "by2"), List.of(new TargetLiteral.IntLiteral(10)), interfaceType, "apply", false, true, false))))));
|
||||
var clazz = generateClass(targetClass, classLoader);
|
||||
var instance = clazz.getConstructor().newInstance();
|
||||
assertEquals(clazz.getDeclaredMethod("lambda").invoke(instance), 20);
|
||||
}
|
||||
}
|
@ -1,396 +0,0 @@
|
||||
package targetast;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.target.generate.ASTToTargetAST;
|
||||
import static de.dhbwstuttgart.target.generate.ASTToTargetAST.OBJECT;
|
||||
import de.dhbwstuttgart.target.generate.Bound;
|
||||
import static de.dhbwstuttgart.target.generate.Bound.*;
|
||||
import de.dhbwstuttgart.target.generate.BoundsList;
|
||||
import de.dhbwstuttgart.target.generate.GenericsResult;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Ignore("TODO: Rewrite with the new algorithm")
|
||||
public class TestGenerics {
|
||||
private static final String rootDirectory = System.getProperty("user.dir") + "/resources/insertGenerics/javFiles/";
|
||||
private static final String bytecodeDirectory = System.getProperty("user.dir") + "targetTest";
|
||||
|
||||
private record Result(List<GenericsResult> genericsResults, ClassOrInterface clazz) {
|
||||
Method findMethod(String name) {
|
||||
return clazz.getMethods().stream().filter(m -> m.getName().equals(name)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
Field findField(String name) {
|
||||
return clazz.getFieldDecl().stream().filter(field -> field.getName().equals(name)).findFirst().orElse(null);
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertStrictlyEquals(BoundsList a, BoundsList b) {
|
||||
assertEquals(a.base, b.base);
|
||||
assertEquals(a, b);
|
||||
}
|
||||
|
||||
private static void assertStrictlyNotEquals(BoundsList a, BoundsList b) {
|
||||
assertNotEquals(a.base, b.base);
|
||||
}
|
||||
|
||||
private static Result computeGenerics(String filename) throws IOException, ClassNotFoundException {
|
||||
var file = Path.of(rootDirectory + filename).toFile();
|
||||
var compiler = new JavaTXCompiler(List.of(file), List.of(file.getParentFile()), new File(bytecodeDirectory));
|
||||
var inference = compiler.typeInference(file);
|
||||
compiler.generateBytecode(new File(bytecodeDirectory), inference);
|
||||
var sf = compiler.sourceFiles.get(file);
|
||||
var clazz = sf.getClasses().get(0);
|
||||
return new Result(compiler.getGeneratedGenerics().get(sf), clazz);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAny() throws Exception {
|
||||
var result = computeGenerics("TestAny.jav");
|
||||
var anyMethod = result.findMethod("anyMethod");
|
||||
var otherMethod = result.findMethod("otherMethod");
|
||||
var a = result.findField("a");
|
||||
var b = result.findField("b");
|
||||
|
||||
var generics = result.genericsResults.get(0);
|
||||
assertEquals(1, generics.get(anyMethod).size());
|
||||
assertEquals(2, generics.get(result.clazz).size());
|
||||
|
||||
var ECK1 = generics.getBounds(otherMethod.getParameterList().getParameterAt(0).getType(), result.clazz, anyMethod);
|
||||
var ECK2 = generics.getBounds(otherMethod.getReturnType(), result.clazz, anyMethod);
|
||||
var ECKChain = new BoundsList(onClass(OBJECT));
|
||||
assertStrictlyEquals(ECK1, ECK2);
|
||||
assertEquals(ECK2, generics.getBounds(b.getType(), result.clazz));
|
||||
|
||||
var M = generics.getBounds(a.getType(), result.clazz);
|
||||
var MChain = new BoundsList(onClass("ECK"), onClass(OBJECT));
|
||||
assertEquals(M, MChain);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassField() throws Exception {
|
||||
var result = computeGenerics("TestClassField.jav");
|
||||
var fReturn = result.findMethod("fReturn");
|
||||
|
||||
var generics = result.genericsResults.get(0);
|
||||
assertEquals(1, generics.get(result.clazz).size());
|
||||
assertEquals(0, generics.get(fReturn).size());
|
||||
|
||||
var N = generics.getBounds(fReturn.getReturnType(), result.clazz);
|
||||
var NChain = new BoundsList(onClass(OBJECT));
|
||||
assertEquals(N, NChain);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContraVariant() throws Exception {
|
||||
var result = computeGenerics("TestContraVariant.jav");
|
||||
var m = result.findMethod("m");
|
||||
var main = result.findMethod("main");
|
||||
|
||||
var generics = result.genericsResults.get(0);
|
||||
assertEquals(0, generics.get(result.clazz).size());
|
||||
assertEquals(3, generics.get(m).size());
|
||||
assertEquals(3, generics.get(main).size());
|
||||
|
||||
{
|
||||
var AJ = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m);
|
||||
var AK = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
|
||||
var KWU = generics.getBounds(((RefType) generics.resolve(m.getReturnType())).getParaList().get(0), result.clazz, m);
|
||||
var AK2 = generics.getBounds(((RefType) generics.resolve(m.getReturnType())).getParaList().get(1), result.clazz, m);
|
||||
|
||||
assertStrictlyEquals(AK, AK2);
|
||||
assertStrictlyNotEquals(AJ, KWU);
|
||||
var NChain = new BoundsList(onMethod(OBJECT));
|
||||
assertEquals(AJ, NChain);
|
||||
assertEquals(AK, NChain);
|
||||
assertEquals(KWU, NChain);
|
||||
}
|
||||
|
||||
{
|
||||
var O = generics.getBounds(main.getParameterList().getParameterAt(0).getType(), result.clazz, main);
|
||||
var P = generics.getBounds(main.getParameterList().getParameterAt(1).getType(), result.clazz, main);
|
||||
var KWQ = generics.getBounds(((RefType) generics.resolve(main.getReturnType())).getParaList().get(1), result.clazz, main);
|
||||
var O2 = generics.getBounds(((RefType) generics.resolve(main.getReturnType())).getParaList().get(0), result.clazz, main);
|
||||
|
||||
assertStrictlyEquals(O, O2);
|
||||
assertStrictlyNotEquals(P, KWQ);
|
||||
var NChain = new BoundsList(onMethod(OBJECT));
|
||||
assertEquals(O, NChain);
|
||||
assertEquals(P, NChain);
|
||||
assertEquals(KWQ, NChain);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGGFinder() throws Exception {
|
||||
var result = computeGenerics("TestGGFinder.jav");
|
||||
var id = result.findMethod("id");
|
||||
var setA = result.findMethod("setA");
|
||||
var m = result.findMethod("m");
|
||||
var a = result.findField("a");
|
||||
|
||||
var generics = result.genericsResults.get(0);
|
||||
assertEquals(1, generics.get(result.clazz).size());
|
||||
assertEquals(2, generics.get(id).size());
|
||||
assertEquals(1, generics.get(setA).size());
|
||||
assertEquals(2, generics.get(m).size());
|
||||
|
||||
var R = generics.getBounds(a.getType(), result.clazz);
|
||||
var RChain = new BoundsList(onClass(OBJECT));
|
||||
assertEquals(R, RChain);
|
||||
|
||||
var O = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id);
|
||||
var AB = generics.getBounds(id.getReturnType(), result.clazz, id);
|
||||
assertEquals(O, AB);
|
||||
assertEquals(AB, new BoundsList(onMethod(OBJECT)));
|
||||
|
||||
var S = generics.getBounds(setA.getParameterList().getParameterAt(0).getType(), result.clazz, setA);
|
||||
assertEquals(S, RChain);
|
||||
assertEquals(generics.getBounds(setA.getReturnType(), result.clazz, setA), RChain);
|
||||
|
||||
var X = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m);
|
||||
var Y = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
|
||||
var XChain = new BoundsList(onMethod(OBJECT));
|
||||
assertEquals(X, XChain);
|
||||
assertEquals(Y, X);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocalVarLambda() throws Exception {
|
||||
var result = computeGenerics("TestLocalVarLambda.jav");
|
||||
// TODO Generics of lambdas
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMutualRecursion() throws Exception {
|
||||
var result = computeGenerics("TestMutualRecursion.jav");
|
||||
var id = result.findMethod("id");
|
||||
var m = result.findMethod("m");
|
||||
var main = result.findMethod("main");
|
||||
var a = result.findField("a");
|
||||
|
||||
var generics = result.genericsResults.get(0);
|
||||
assertEquals(1, generics.get(result.clazz).size());
|
||||
assertEquals(2, generics.get(id).size());
|
||||
assertEquals(2, generics.get(m).size());
|
||||
assertEquals(3, generics.get(main).size());
|
||||
|
||||
var N = generics.getBounds(a.getType(), result.clazz);
|
||||
assertEquals(N, new BoundsList(onClass(OBJECT)));
|
||||
|
||||
var P = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id);
|
||||
var O = generics.getBounds(id.getReturnType(), result.clazz, id);
|
||||
assertEquals(P, O);
|
||||
assertEquals(O, new BoundsList(onMethod(OBJECT)));
|
||||
|
||||
assertEquals(generics.resolve(m.getParameterList().getParameterAt(0).getType()), generics.resolve(m.getReturnType()));
|
||||
var Y = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m);
|
||||
var AA = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
|
||||
assertEquals(Y, AA);
|
||||
assertEquals(AA, new BoundsList(onMethod(OBJECT)));
|
||||
|
||||
var AI = generics.getBounds(m.getParameterList().getParameterAt(0).getType(), result.clazz, m);
|
||||
var AJ = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
|
||||
var AH = generics.getBounds(m.getReturnType(), result.clazz, m);
|
||||
assertEquals(AI, AJ);
|
||||
assertEquals(AJ, AH);
|
||||
assertEquals(AH, new BoundsList(onMethod(OBJECT)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReturnVar() throws Exception {
|
||||
var result = computeGenerics("TestReturnVar.jav");
|
||||
var anyMethod = result.findMethod("anyMethod");
|
||||
|
||||
var generics = result.genericsResults.get(0);
|
||||
assertEquals(1, generics.get(anyMethod).size());
|
||||
|
||||
var M = generics.getBounds(anyMethod.getReturnType(), result.clazz, anyMethod);
|
||||
assertEquals(M, new BoundsList(onMethod(OBJECT)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecondLineOfClassConstraints() throws Exception {
|
||||
var result = computeGenerics("TestSecondLineOfClassConstraints.jav");
|
||||
var a = result.findField("a");
|
||||
var b = result.findField("b");
|
||||
var anyMethod = result.findMethod("anyMethod");
|
||||
var otherMethod = result.findMethod("otherMethod");
|
||||
|
||||
var generics = result.genericsResults.get(0);
|
||||
var M = generics.getBounds(a.getType(), result.clazz);
|
||||
var DYX = generics.getBounds(b.getType(), result.clazz);
|
||||
var MChain = new BoundsList(onClass("DYX"), onClass(OBJECT));
|
||||
var DYXChain = new BoundsList(onClass(OBJECT));
|
||||
assertEquals(M, MChain);
|
||||
|
||||
var Q = generics.getBounds(anyMethod.getReturnType(), result.clazz, anyMethod);
|
||||
assertEquals(Q, new BoundsList(onMethod(OBJECT)));
|
||||
|
||||
System.out.println(otherMethod.getReturnType());
|
||||
var DYX2 = generics.getBounds(otherMethod.getReturnType(), result.clazz, otherMethod);
|
||||
assertEquals(DYX, DYX2);
|
||||
assertEquals(DYX, generics.getBounds(otherMethod.getReturnType(), result.clazz, otherMethod));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThreeArgs() throws Exception {
|
||||
var result = computeGenerics("TestThreeArgs.jav");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTPHsAndGenerics() throws Exception {
|
||||
var result = computeGenerics("TestTPHsAndGenerics.jav");
|
||||
var id2 = result.findMethod("id2");
|
||||
var m = result.findMethod("m");
|
||||
var m2 = result.findMethod("m2");
|
||||
|
||||
var generics = result.genericsResults.get(0);
|
||||
var U = generics.getBounds(id2.getParameterList().getParameterAt(0).getType(), result.clazz, id2);
|
||||
var FPT = generics.getBounds(id2.getReturnType(), result.clazz, id2);
|
||||
assertEquals(U, new BoundsList(onMethod("FPT"), onClass(OBJECT)));
|
||||
assertEquals(FPT, new BoundsList(onClass(OBJECT)));
|
||||
|
||||
var AA = generics.getBounds(m.getReturnType(), result.clazz, m);
|
||||
var AC = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
|
||||
assertEquals(AA, new BoundsList(onMethod(OBJECT)));
|
||||
assertEquals(AC, new BoundsList(onMethod(OBJECT)));
|
||||
|
||||
var AH = generics.getBounds(m2.getReturnType(), result.clazz, m2);
|
||||
var AL = generics.getBounds(m2.getParameterList().getParameterAt(0).getType(), result.clazz, m2);
|
||||
assertEquals(AH, new BoundsList(onMethod(OBJECT)));
|
||||
assertEquals(AH, AL);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTwoArgs() throws Exception {
|
||||
var result = computeGenerics("TestTwoArgs.jav");
|
||||
|
||||
var a = result.findField("a");
|
||||
var id = result.findMethod("id");
|
||||
var setA = result.findMethod("setA");
|
||||
var m = result.findMethod("m");
|
||||
var main = result.findMethod("main");
|
||||
|
||||
var generics = result.genericsResults.get(0);
|
||||
var AO = generics.getBounds(a.getType(), result.clazz);
|
||||
var AOBound = new BoundsList(
|
||||
onClass("Y"),
|
||||
onClass("AK"),
|
||||
onClass("AE"),
|
||||
onClass(OBJECT)
|
||||
);
|
||||
assertEquals(AO, AOBound);
|
||||
|
||||
var S = generics.getBounds(setA.getParameterList().getParameterAt(0).getType(), result.clazz, setA);
|
||||
var c = new ArrayList<Bound>();
|
||||
c.add(onMethod("AO"));
|
||||
c.addAll(AOBound);
|
||||
var SChain = new BoundsList(c);
|
||||
assertEquals(S, SChain);
|
||||
|
||||
var Y = generics.getBounds(m.getParameterList().getParameterAt(1).getType(), result.clazz, m);
|
||||
var YChain = new BoundsList(onMethod("AE"), onClass(OBJECT));
|
||||
var AE = generics.getBounds(m.getReturnType(), result.clazz, m);
|
||||
assertEquals(Y, YChain);
|
||||
assertEquals(AE, new BoundsList(onClass(OBJECT)));
|
||||
|
||||
// TODO main seems to change between runs
|
||||
/*var AE2 = generics.getBounds(main.getReturnType(), result.clazz, main);
|
||||
var AF = generics.getBounds(main.getParameterList().getParameterAt(0).getType(), result.clazz, main);
|
||||
var AG = generics.getBounds(main.getParameterList().getParameterAt(1).getType(), result.clazz, main);
|
||||
assertEquals(AE, AE2));
|
||||
assertEquals(AF, new BoundsList(onMethod("AK"), onMethod("AE"), onClass(OBJECT))));
|
||||
assertEquals(AG, SChain));*/
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTwoArgs2() throws Exception {
|
||||
var result = computeGenerics("TestTwoArgs2.jav");
|
||||
// TODO Test generics
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTwoCalls() throws Exception {
|
||||
var result = computeGenerics("TestTwoCalls.jav");
|
||||
var id = result.findMethod("id");
|
||||
var main = result.findMethod("main");
|
||||
|
||||
var generics = result.genericsResults.get(0);
|
||||
var O = generics.getBounds(id.getReturnType(), result.clazz, id);
|
||||
var O2 = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id);
|
||||
assertStrictlyEquals(O, O2);
|
||||
assertEquals(O2, new BoundsList(onMethod(OBJECT)));
|
||||
|
||||
// TODO Maybe test in other ways if the parameter generics equals the return generics
|
||||
var S = generics.getBounds(main.getReturnType(), result.clazz, main);
|
||||
var S2 = generics.getBounds(main.getParameterList().getParameterAt(1).getType(), result.clazz, main);
|
||||
var T = generics.getBounds(main.getParameterList().getParameterAt(0).getType(), result.clazz, main);
|
||||
assertStrictlyEquals(S, S2);
|
||||
assertEquals(S2, new BoundsList(onMethod(OBJECT)));
|
||||
assertEquals(T, new BoundsList(onMethod(OBJECT)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVector() throws Exception {
|
||||
var result = computeGenerics("TestVector.jav");
|
||||
var m = result.findMethod("m");
|
||||
var id = result.findMethod("id");
|
||||
|
||||
var generics = result.genericsResults.get(0);
|
||||
var par1 = generics.resolve(m.getParameterList().getParameterAt(0).getType());
|
||||
var par2 = generics.resolve(m.getParameterList().getParameterAt(1).getType());
|
||||
|
||||
var S = generics.getBounds(((RefType) par1).getParaList().get(0), result.clazz, m);
|
||||
var ACM = generics.getBounds(((RefType) par2).getParaList().get(0), result.clazz, m);
|
||||
assertEquals(S, new BoundsList(onMethod("V"), onMethod(OBJECT)));
|
||||
assertEquals(ACM, new BoundsList(onMethod(OBJECT)));
|
||||
|
||||
var Y = generics.getBounds(id.getParameterList().getParameterAt(0).getType(), result.clazz, id);
|
||||
assertEquals(Y, new BoundsList(onMethod(OBJECT)));
|
||||
assertEquals(Y, generics.getBounds(id.getReturnType(), result.clazz, id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVectorArg() throws Exception {
|
||||
var result = computeGenerics("TestVectorArg.jav");
|
||||
var add = result.findMethod("add");
|
||||
var main = result.findMethod("main");
|
||||
|
||||
var generics = result.genericsResults.get(0);
|
||||
var par1 = generics.resolve(add.getParameterList().getParameterAt(0).getType());
|
||||
var ACK = generics.getBounds(((RefType) par1).getParaList().get(0), result.clazz, add);
|
||||
var O = generics.getBounds(add.getParameterList().getParameterAt(1).getType(), result.clazz, add);
|
||||
assertEquals(ACK, new BoundsList(onMethod(OBJECT)));
|
||||
assertEquals(O, new BoundsList(onMethod("ACK"), onMethod(OBJECT)));
|
||||
|
||||
var par2 = generics.resolve(main.getParameterList().getParameterAt(0).getType());
|
||||
var ACK2 = generics.getBounds(((RefType) par2).getParaList().get(0), result.clazz, add);
|
||||
var V = generics.getBounds(add.getParameterList().getParameterAt(1).getType(), result.clazz, add);
|
||||
assertStrictlyEquals(ACK2, ACK);
|
||||
assertEquals(V, O);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVoidMeth() throws Exception {
|
||||
var result = computeGenerics("TestVoidMeth.jav");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssign() throws Exception {
|
||||
// TODO Check generics
|
||||
var result = computeGenerics("TestAssign.jav");
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
package targetast;
|
||||
|
||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TphTest {
|
||||
|
||||
private static Class<?> classToTest;
|
||||
private static Object instanceOfClass;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "Tph.jav");
|
||||
classToTest = classFiles.get("Tph");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test1() throws Exception {
|
||||
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
|
||||
Object result = m.invoke(instanceOfClass, 1,2);
|
||||
|
||||
assertEquals(1,result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2() throws Exception {
|
||||
Method m = classToTest.getDeclaredMethod("m", Object.class, Object.class);
|
||||
Object result = m.invoke(instanceOfClass, 1, "sss");
|
||||
|
||||
assertEquals(1,result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3() throws Exception {
|
||||
Method m = classToTest.getDeclaredMethod("m2", Object.class);
|
||||
Object result = m.invoke(instanceOfClass, 2);
|
||||
|
||||
assertEquals(2,result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test4() throws Exception {
|
||||
Method m = classToTest.getDeclaredMethod("m2", Object.class);
|
||||
Object result = m.invoke(instanceOfClass,"xxx");
|
||||
|
||||
assertEquals("xxx",result);
|
||||
}
|
||||
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
package targetast;
|
||||
|
||||
import de.dhbwstuttgart.environment.ByteArrayClassLoader;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class WhileTest {
|
||||
private static Class<?> classToTest;
|
||||
private static Object instanceOfClass;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
var classFiles = TestCodegen.generateClassFiles(new ByteArrayClassLoader(), "While.jav");
|
||||
classToTest = classFiles.get("While");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
Method m = classToTest.getDeclaredMethod("m", Integer.class);
|
||||
Integer result = (Integer) m.invoke(instanceOfClass, 0);
|
||||
assertEquals(Integer.valueOf(2), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDouble() throws Exception {
|
||||
Method m = classToTest.getDeclaredMethod("m", Double.class);
|
||||
Double result = (Double) m.invoke(instanceOfClass, 0.0);
|
||||
assertEquals(Double.valueOf(2.0), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLong() throws Exception {
|
||||
Method m = classToTest.getDeclaredMethod("m", Long.class);
|
||||
Long result = (Long) m.invoke(instanceOfClass, 0l);
|
||||
assertEquals(Long.valueOf(2l), result);
|
||||
}
|
||||
|
||||
}
|
@ -1,200 +0,0 @@
|
||||
package typeinference;
|
||||
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Ignore("To be renewed")
|
||||
public class JavaTXCompilerTest {
|
||||
|
||||
public static final String rootDirectory = System.getProperty("user.dir") + "/src/test/resources/javFiles/";
|
||||
|
||||
@Test
|
||||
public void finiteClosure() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory + "fc.jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void importTest() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory + "Import.jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fieldTest() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory + "FieldAccess.jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lambda() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory + "Lambda.jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lambda2() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory + "Lambda2.jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lambda3() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory + "Lambda3.jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lambdaField() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory + "LambdaField.jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mathStruc() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory + "mathStruc.jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generics() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory + "Generics.jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void genericsMethodCall() throws IOException, ClassNotFoundException {
|
||||
TestResultSet result = execute(new File(rootDirectory + "MethodCallGenerics.jav"));
|
||||
// TODO: Hier sollte der Rückgabetyp der Methode String sein
|
||||
}
|
||||
|
||||
@Test
|
||||
public void faculty() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory + "Faculty.jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void facultyIf() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory + "FacultyIf.jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void facultyTyped() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory + "FacultyTyped.jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matrix() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory + "Matrix.jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void packageTests() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory + "Package.jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vector() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory + "Vector.jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lambdaRunnable() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory + "LambdaRunnable.jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void expressions() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory + "Expressions.jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addLong() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory + "AddLong.jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fields() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory + "Fields.jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ifStatement() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory + "IfTest.jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleSolutions() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory + "Sorting.jav"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listenerTest() throws IOException, ClassNotFoundException {
|
||||
execute(new File(rootDirectory + "ListenerOverload.jav"));
|
||||
}
|
||||
|
||||
private static class TestResultSet {
|
||||
|
||||
}
|
||||
|
||||
public TestResultSet execute(File fileToTest) throws IOException, ClassNotFoundException {
|
||||
// filesToTest.add(new File(rootDirectory+"fc.jav"));
|
||||
// filesToTest.add(new File(rootDirectory+"Lambda.jav"));
|
||||
// filesToTest.add(new File(rootDirectory+"Lambda2.jav"));
|
||||
// filesToTest.add(new File(rootDirectory+"Lambda3.jav"));
|
||||
// filesToTest.add(new File(rootDirectory+"Vector.jav"));
|
||||
// filesToTest.add(new File(rootDirectory+"Generics.jav"));
|
||||
// filesToTest.add(new File(rootDirectory+"MethodsEasy.jav"));
|
||||
// filesToTest.add(new File(rootDirectory+"Matrix.jav"));
|
||||
// filesToTest.add(new File(rootDirectory+"Import.jav"));
|
||||
// filesToTest.add(new File(rootDirectory+"Faculty.jav"));
|
||||
// filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
|
||||
// filesToTest.add(new File(rootDirectory+"test.jav"));
|
||||
JavaTXCompiler compiler = new JavaTXCompiler(fileToTest);
|
||||
for (File f : compiler.sourceFiles.keySet()) {
|
||||
SourceFile sf = compiler.sourceFiles.get(f);
|
||||
System.out.println(ASTTypePrinter.print(sf));
|
||||
System.out.println(ASTPrinter.print(sf));
|
||||
}
|
||||
|
||||
// compiler.generateBytecode(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles);
|
||||
for (File f : compiler.sourceFiles.keySet()) {
|
||||
List<ResultSet> results = compiler.typeInference(f);
|
||||
SourceFile sf = compiler.sourceFiles.get(f);
|
||||
System.out.println(ASTTypePrinter.print(sf));
|
||||
System.out.println(ASTPrinter.print(sf));
|
||||
// List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
|
||||
assert results.size() > 0;
|
||||
Set<String> insertedTypes = new HashSet<>();
|
||||
for (var i = 0; i < results.size(); i++) {
|
||||
var resultSet = results.get(i);
|
||||
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet, compiler.getGeneratedGenerics().get(sf).get(i));
|
||||
assert result.size() > 0;
|
||||
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
|
||||
for (TypeInsert tip : result) {
|
||||
insertedTypes.add(tip.insert(content));
|
||||
}
|
||||
}
|
||||
for (String s : insertedTypes) {
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
||||
return new TestResultSet();
|
||||
}
|
||||
|
||||
static String readFile(String path, Charset encoding) throws IOException {
|
||||
byte[] encoded = Files.readAllBytes(Paths.get(path));
|
||||
return new String(encoded, encoding);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user