Moved test resources to src/test and refactored tests

This commit is contained in:
luca9913 2023-06-05 09:28:55 +02:00
parent e3edd0410a
commit 63c5cb8390
213 changed files with 583 additions and 861 deletions

View File

@ -1 +0,0 @@

View File

@ -1,5 +1,4 @@
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.io.File; import java.io.File;
@ -25,7 +24,6 @@ public class AllgemeinTest {
private static String pathToClassFile; private static String pathToClassFile;
private static Object instanceOfClass; private static Object instanceOfClass;
@Test @Test
public void test() throws Exception { public void test() throws Exception {
// String className = "GenTest"; // String className = "GenTest";
@ -52,17 +50,15 @@ public class AllgemeinTest {
String className = "VectorNotObject"; String className = "VectorNotObject";
// String className = "WildcardCaptureConversionTest"; // String className = "WildcardCaptureConversionTest";
// PL 2019-10-24: genutzt fuer unterschiedliche Tests // 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/" + className + ".jav";
//path = System.getProperty("user.dir")+"/src/test/resources/AllgemeinTest/Overloading_Generics.jav"; // path = System.getProperty("user.dir")+"/src/test/src/test/resources/AllgemeinTest/Overloading_Generics.jav";
//path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/mathStrucInteger.jav"; // path = System.getProperty("user.dir")+"/src/test/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(System.getProperty("user.dir")+"/src/test/src/test/resources/AllgemeinTest/Overloading_Generics.jav")));
/// * /// *
compiler = new JavaTXCompiler( compiler = new JavaTXCompiler(Lists.newArrayList(new File(path)), Lists.newArrayList(new File(System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/")));
Lists.newArrayList(new File(path)),
Lists.newArrayList(new File(System.getProperty("user.dir")+"/resources/testBytecode/generatedBC/")));
// */ // */
compiler.generateBytecode(System.getProperty("user.dir")+"/resources/testBytecode/generatedBC/"); compiler.generateBytecode(System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/");
pathToClassFile = System.getProperty("user.dir")+"/resources/testBytecode/generatedBC/"; pathToClassFile = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/";
loader = new URLClassLoader(new URL[] { new URL("file://" + pathToClassFile) }); loader = new URLClassLoader(new URL[] { new URL("file://" + pathToClassFile) });
classToTest = loader.loadClass(className); classToTest = loader.loadClass(className);
// classToTest = loader.loadClass("Overloading_Generics"); // classToTest = loader.loadClass("Overloading_Generics");

View File

@ -12,7 +12,8 @@ import java.net.URLClassLoader;
public class Bytecode extends TestCase { public class Bytecode extends TestCase {
public static final String rootDirectory = System.getProperty("user.dir")+"/resources/javFiles/packageTest/"; public static final String rootDirectory = System.getProperty("user.dir") + "/src/test/resources/javFiles/packageTest/";
@Test @Test
public void testSetPackageNameInBytecode() throws Exception { public void testSetPackageNameInBytecode() throws Exception {
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory + "de/test/TestClass.jav")); JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory + "de/test/TestClass.jav"));
@ -25,7 +26,6 @@ public class Bytecode extends TestCase {
f = new File(rootDirectory + "de/test/TestClass.class"); f = new File(rootDirectory + "de/test/TestClass.class");
assertTrue(f.exists()); assertTrue(f.exists());
URLClassLoader loader = new URLClassLoader(new URL[] { new URL("file://" + rootDirectory) }); URLClassLoader loader = new URLClassLoader(new URL[] { new URL("file://" + rootDirectory) });
Class<?> classToTest = loader.loadClass("de.test.TestClass"); Class<?> classToTest = loader.loadClass("de.test.TestClass");
Object instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); Object instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
@ -48,5 +48,4 @@ public class Bytecode extends TestCase {
Object instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); Object instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
} }
} }

View File

@ -12,7 +12,7 @@ import java.util.Arrays;
public class CheckPackageFolder extends TestCase { public class CheckPackageFolder extends TestCase {
public static final String rootDirectory = System.getProperty("user.dir")+"/resources/javFiles/packageTest/de/test/"; public static final String rootDirectory = System.getProperty("user.dir") + "/src/test/resources/javFiles/packageTest/de/test/";
@Test @Test
public void testCorrectFolder1FileWithWrongPackageName() throws IOException, ClassNotFoundException { public void testCorrectFolder1FileWithWrongPackageName() throws IOException, ClassNotFoundException {
@ -55,26 +55,8 @@ public class CheckPackageFolder extends TestCase {
/* /*
* Dieser Test wird übersprungen, da der Bytecode-Generator nicht mit zwei Eingabedateien gleichzeitig umgehen kann * Dieser Test wird übersprungen, da der Bytecode-Generator nicht mit zwei Eingabedateien gleichzeitig umgehen kann
@Test *
public void testCorrectFolder2Files() throws IOException, ClassNotFoundException { * @Test public void testCorrectFolder2Files() throws IOException, ClassNotFoundException { JavaTXCompiler compiler = new JavaTXCompiler(Arrays.asList( new File(rootDirectory+"subpackage1/Test1.jav"), new File(rootDirectory+"subpackage2/Test2.jav") )); compiler.typeInference(); File f = new File(rootDirectory + "subpackage1/Test1.class"); if(f.exists() && !f.isDirectory()) { f.delete(); } File f2 = new File(rootDirectory + "subpackage2/Test2.class"); if(f.exists() && !f.isDirectory()) {
JavaTXCompiler compiler = new JavaTXCompiler(Arrays.asList( * f.delete(); } compiler.generateBytecode(); f = new File(rootDirectory + "subpackage1/Test1.class"); f2 = new File(rootDirectory + "subpackage2/Test2.class"); assertTrue(f.exists()); assertTrue(f2.exists()); }
new File(rootDirectory+"subpackage1/Test1.jav"),
new File(rootDirectory+"subpackage2/Test2.jav")
));
compiler.typeInference();
File f = new File(rootDirectory + "subpackage1/Test1.class");
if(f.exists() && !f.isDirectory()) {
f.delete();
}
File f2 = new File(rootDirectory + "subpackage2/Test2.class");
if(f.exists() && !f.isDirectory()) {
f.delete();
}
compiler.generateBytecode();
f = new File(rootDirectory + "subpackage1/Test1.class");
f2 = new File(rootDirectory + "subpackage2/Test2.class");
assertTrue(f.exists());
assertTrue(f2.exists());
}
*/ */
} }

View File

@ -11,7 +11,7 @@ import java.net.URLClassLoader;
public class ConsoleInterfaceTest extends TestCase { public class ConsoleInterfaceTest extends TestCase {
public static final String rootDirectory = System.getProperty("user.dir")+"/resources/javFiles/packageTest/"; public static final String rootDirectory = System.getProperty("user.dir") + "/src/test/resources/javFiles/packageTest/";
@Test @Test
public void testCompileSingleJavFile() throws Exception { public void testCompileSingleJavFile() throws Exception {
@ -103,8 +103,7 @@ public class ConsoleInterfaceTest extends TestCase {
f.delete(); f.delete();
} }
ConsoleInterface.main(new String[]{"-cp", rootDirectory + "de/test/output/:"+rootDirectory+"de", ConsoleInterface.main(new String[] { "-cp", rootDirectory + "de/test/output/:" + rootDirectory + "de", rootDirectory + "de/test/ImportTest.jav" });
rootDirectory + "de/test/ImportTest.jav"});
f = new File(rootDirectory + "de/test/ImportTest.class"); f = new File(rootDirectory + "de/test/ImportTest.class");
assertTrue(f.exists()); assertTrue(f.exists());
@ -123,8 +122,7 @@ public class ConsoleInterfaceTest extends TestCase {
f.delete(); f.delete();
} }
ConsoleInterface.main(new String[]{"-cp", rootDirectory + "de/test/output/", ConsoleInterface.main(new String[] { "-cp", rootDirectory + "de/test/output/", "-d" + rootDirectory + "de/test/output/", rootDirectory + "de/test/ImportTest.jav" });
"-d"+rootDirectory + "de/test/output/" ,rootDirectory + "de/test/ImportTest.jav"});
f = new File(rootDirectory + "de/test/output/de/test/ImportTest.class"); f = new File(rootDirectory + "de/test/output/de/test/ImportTest.class");
assertTrue(f.exists()); assertTrue(f.exists());

View File

@ -12,12 +12,11 @@ import java.net.URL;
public class ImportTest extends TestCase { public class ImportTest extends TestCase {
public static final String rootDirectory = System.getProperty("user.dir")+"/resources/javFiles/packageTest/de/test/"; public static final String rootDirectory = System.getProperty("user.dir") + "/src/test/resources/javFiles/packageTest/de/test/";
public ImportTest() throws ClassNotFoundException, IOException { public ImportTest() throws ClassNotFoundException, IOException {
/* /*
Generate ToImport class in rootDirectory and in output-Directory * Generate ToImport class in rootDirectory and in output-Directory
*/ */
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory + "ToImport.jav")); JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory + "ToImport.jav"));
compiler.typeInference(); compiler.typeInference();
@ -46,9 +45,7 @@ public class ImportTest extends TestCase {
@Test @Test
public void testSetPackageNameInBytecodeAndOutputFolder() throws IOException, ClassNotFoundException { public void testSetPackageNameInBytecodeAndOutputFolder() throws IOException, ClassNotFoundException {
JavaTXCompiler compiler = new JavaTXCompiler( JavaTXCompiler compiler = new JavaTXCompiler(Lists.newArrayList(new File(rootDirectory + "ImportTest.jav")), Lists.newArrayList(new File(rootDirectory + "output/")));
Lists.newArrayList(new File(rootDirectory+"ImportTest.jav")),
Lists.newArrayList(new File(rootDirectory+"output/")));
compiler.typeInference(); compiler.typeInference();
File f = new File(rootDirectory + "output/de/test/ImportTest.class"); File f = new File(rootDirectory + "output/de/test/ImportTest.class");
if (f.exists() && !f.isDirectory()) { if (f.exists() && !f.isDirectory()) {
@ -61,9 +58,7 @@ public class ImportTest extends TestCase {
@Test @Test
public void testSetPackageNameInBytecodeAndStandardOutputFolder() throws IOException, ClassNotFoundException { public void testSetPackageNameInBytecodeAndStandardOutputFolder() throws IOException, ClassNotFoundException {
JavaTXCompiler compiler = new JavaTXCompiler( JavaTXCompiler compiler = new JavaTXCompiler(Lists.newArrayList(new File(rootDirectory + "ImportTest.jav")), Lists.newArrayList(new File(rootDirectory + "output/")));
Lists.newArrayList(new File(rootDirectory+"ImportTest.jav")),
Lists.newArrayList(new File(rootDirectory+"output/")));
compiler.typeInference(); compiler.typeInference();
File f = new File(rootDirectory + "ImportTest.class"); File f = new File(rootDirectory + "ImportTest.class");
if (f.exists() && !f.isDirectory()) { if (f.exists() && !f.isDirectory()) {
@ -74,12 +69,9 @@ public class ImportTest extends TestCase {
assertTrue(f.exists()); assertTrue(f.exists());
} }
@Test @Test
public void testImportTwoClasses() throws IOException, ClassNotFoundException { public void testImportTwoClasses() throws IOException, ClassNotFoundException {
JavaTXCompiler compiler = new JavaTXCompiler( JavaTXCompiler compiler = new JavaTXCompiler(Lists.newArrayList(new File(rootDirectory + "ImportTest2.jav")), Lists.newArrayList(new File(rootDirectory + "output/")));
Lists.newArrayList(new File(rootDirectory+"ImportTest2.jav")),
Lists.newArrayList(new File(rootDirectory+"output/")));
compiler.typeInference(); compiler.typeInference();
File f = new File(rootDirectory + "ImportTest2.class"); File f = new File(rootDirectory + "ImportTest2.class");
if (f.exists() && !f.isDirectory()) { if (f.exists() && !f.isDirectory()) {
@ -92,8 +84,7 @@ public class ImportTest extends TestCase {
@Test @Test
public void testImportDefaultPackage() throws IOException, ClassNotFoundException { public void testImportDefaultPackage() throws IOException, ClassNotFoundException {
JavaTXCompiler compiler = new JavaTXCompiler( JavaTXCompiler compiler = new JavaTXCompiler(Lists.newArrayList(new File(rootDirectory + "ImportTestDefault.jav")));
Lists.newArrayList(new File(rootDirectory+"ImportTestDefault.jav")));
compiler.typeInference(); compiler.typeInference();
File f = new File(rootDirectory + "ImportTestDefault.class"); File f = new File(rootDirectory + "ImportTestDefault.class");
if (f.exists() && !f.isDirectory()) { if (f.exists() && !f.isDirectory()) {
@ -104,5 +95,4 @@ public class ImportTest extends TestCase {
assertTrue(f.exists()); assertTrue(f.exists());
} }
} }

View File

@ -13,7 +13,7 @@ import java.net.URLClassLoader;
public class LoadDefaultPackageClassesTest extends TestCase { public class LoadDefaultPackageClassesTest extends TestCase {
public static final String rootDirectory = System.getProperty("user.dir") + "/resources/javFiles/packageTest/"; public static final String rootDirectory = System.getProperty("user.dir") + "/src/test/resources/javFiles/packageTest/";
public LoadDefaultPackageClassesTest() throws ClassNotFoundException, IOException { public LoadDefaultPackageClassesTest() throws ClassNotFoundException, IOException {
/* /*
@ -35,14 +35,8 @@ public class LoadDefaultPackageClassesTest extends TestCase {
cl.loadClass("Gen"); cl.loadClass("Gen");
} }
/* /*
* public void testE2E() throws IOException, ClassNotFoundException { * public void testE2E() throws IOException, ClassNotFoundException { JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"OL.jav")); compiler.typeInference(); compiler.generateBytecode(); File f = new File(rootDirectory + "OL.class"); assertTrue(f.exists());
* JavaTXCompiler compiler = new JavaTXCompiler(new
* File(rootDirectory+"OL.jav")); compiler.typeInference();
* compiler.generateBytecode(); File f = new File(rootDirectory + "OL.class");
* assertTrue(f.exists());
* *
* compiler = new JavaTXCompiler(new File(rootDirectory+"OLMain.jav")); * compiler = new JavaTXCompiler(new File(rootDirectory+"OLMain.jav")); compiler.typeInference(); compiler.generateBytecode(); f = new File(rootDirectory + "OLMain.class"); assertTrue(f.exists()); }
* compiler.typeInference(); compiler.generateBytecode(); f = new
* File(rootDirectory + "OLMain.class"); assertTrue(f.exists()); }
*/ */
} }

View File

@ -31,16 +31,14 @@ public class OLOneFileTest {
private static Object instanceOfClass1; private static Object instanceOfClass1;
private static Object instanceOfClass2; private static Object instanceOfClass2;
public static final String rootDirectory = System.getProperty("user.dir")+"/resources/javFiles/packageTest/"; public static final String rootDirectory = System.getProperty("user.dir") + "/src/test/resources/javFiles/packageTest/";
@BeforeClass @BeforeClass
public static void setUpBeforeClass() throws Exception { public static void setUpBeforeClass() throws Exception {
path = rootDirectory + "OLOneFile.jav"; path = rootDirectory + "OLOneFile.jav";
fileToTest = new File(path); fileToTest = new File(path);
compiler = new JavaTXCompiler( compiler = new JavaTXCompiler(Lists.newArrayList(fileToTest), Lists.newArrayList(new File(rootDirectory + "de/test/output/")));
Lists.newArrayList(fileToTest), pathToClassFile = System.getProperty("user.dir") + "/src/test/resources/javFiles/packageTest/";
Lists.newArrayList(new File(rootDirectory+"de/test/output/")));
pathToClassFile = System.getProperty("user.dir")+"/resources/javFiles/packageTest/";
List<ResultSet> typeinferenceResult = compiler.typeInference(); List<ResultSet> typeinferenceResult = compiler.typeInference();
// List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult); // List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
// compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles); // compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);

View File

@ -31,7 +31,7 @@ public class OLTest {
private static Object instanceOfClass1; private static Object instanceOfClass1;
private static Object instanceOfClass2; private static Object instanceOfClass2;
public static final String rootDirectory = System.getProperty("user.dir")+"/resources/javFiles/packageTest"; public static final String rootDirectory = System.getProperty("user.dir") + "/src/test/resources/javFiles/packageTest";
@BeforeClass @BeforeClass
public static void setUpBeforeClass() throws Exception { public static void setUpBeforeClass() throws Exception {
@ -42,25 +42,21 @@ public class OLTest {
classToTest = loader.loadClass("de.test.OL"); classToTest = loader.loadClass("de.test.OL");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
path = System.getProperty("user.dir")+"/resources/javFiles/packageTest/OLextends.jav"; path = System.getProperty("user.dir") + "/src/test/resources/javFiles/packageTest/OLextends.jav";
fileToTest = new File(path); fileToTest = new File(path);
compiler = new JavaTXCompiler( compiler = new JavaTXCompiler(Lists.newArrayList(new File(rootDirectory + "/OLextends.jav")), Lists.newArrayList(new File(rootDirectory + "/de/test/output/")));
Lists.newArrayList(new File(rootDirectory+"/OLextends.jav")),
Lists.newArrayList(new File(rootDirectory+"/de/test/output/")));
// compiler = new JavaTXCompiler(fileToTest); // compiler = new JavaTXCompiler(fileToTest);
pathToClassFile = System.getProperty("user.dir")+"/resources/javFiles/packageTest/"; pathToClassFile = System.getProperty("user.dir") + "/src/test/resources/javFiles/packageTest/";
compiler.generateBytecode(pathToClassFile); compiler.generateBytecode(pathToClassFile);
loader = new URLClassLoader(new URL[] { new URL("file://" + pathToClassFile), new URL("file://" + rootDirectory + "/de/test/output/") }); loader = new URLClassLoader(new URL[] { new URL("file://" + pathToClassFile), new URL("file://" + rootDirectory + "/de/test/output/") });
classToTest1 = loader.loadClass("OLextends"); classToTest1 = loader.loadClass("OLextends");
instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance(); instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance();
path = System.getProperty("user.dir")+"/resources/javFiles/packageTest/OLMain.jav"; path = System.getProperty("user.dir") + "/src/test/resources/javFiles/packageTest/OLMain.jav";
fileToTest = new File(path); fileToTest = new File(path);
compiler = new JavaTXCompiler( compiler = new JavaTXCompiler(Lists.newArrayList(new File(rootDirectory + "/OLMain.jav")), Lists.newArrayList(new File(rootDirectory + "/de/test/output/")));
Lists.newArrayList(new File(rootDirectory+"/OLMain.jav")),
Lists.newArrayList(new File(rootDirectory+"/de/test/output/")));
// compiler = new JavaTXCompiler(fileToTest); // compiler = new JavaTXCompiler(fileToTest);
pathToClassFile = System.getProperty("user.dir")+"/resources/javFiles/packageTest/"; pathToClassFile = System.getProperty("user.dir") + "/src/test/resources/javFiles/packageTest/";
compiler.generateBytecode(pathToClassFile); compiler.generateBytecode(pathToClassFile);
loader = new URLClassLoader(new URL[] { new URL("file://" + pathToClassFile), new URL("file://" + rootDirectory + "/de/test/output/") }); loader = new URLClassLoader(new URL[] { new URL("file://" + pathToClassFile), new URL("file://" + rootDirectory + "/de/test/output/") });
classToTest2 = loader.loadClass("OLMain"); classToTest2 = loader.loadClass("OLMain");

View File

@ -9,7 +9,8 @@ import java.io.IOException;
public class ParsePackageName { public class ParsePackageName {
public static final String rootDirectory = System.getProperty("user.dir")+"/resources/javFiles/packageTest/de/test/"; public static final String rootDirectory = System.getProperty("user.dir") + "/src/test/resources/javFiles/packageTest/de/test/";
@Test @Test
public void parsePackage() throws IOException, ClassNotFoundException { public void parsePackage() throws IOException, ClassNotFoundException {
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory + "TestClass.jav")); JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory + "TestClass.jav"));

View File

@ -12,7 +12,7 @@ import java.net.URL;
public class mathStrucMatrixOPTest extends TestCase { public class mathStrucMatrixOPTest extends TestCase {
public static final String rootDirectory = System.getProperty("user.dir")+"/resources/javFiles/packageTest/de/test/"; public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/de/test/";
public mathStrucMatrixOPTest() throws ClassNotFoundException, IOException { public mathStrucMatrixOPTest() throws ClassNotFoundException, IOException {

View File

@ -12,20 +12,15 @@ import java.net.URL;
public class mathStrucVectorTest extends TestCase { public class mathStrucVectorTest extends TestCase {
public static final String rootDirectory = System.getProperty("user.dir")+"/resources/javFiles/packageTest/de/test/"; public static final String rootDirectory = System.getProperty("user.dir") + "/src/test/resources/javFiles/packageTest/de/test/";
public mathStrucVectorTest() throws ClassNotFoundException, IOException { public mathStrucVectorTest() throws ClassNotFoundException, IOException {
/* /*
Generate ToImport class in rootDirectory and in output-Directory * Generate ToImport class in rootDirectory and in output-Directory
*/ */
/* PL 2020-01-07 kann z.Zt. nicht erzeugt werden (siehe Bug 170, http://bugzilla.ba-horb.de/show_bug.cgi?id=170) /*
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"mathStruc.jav")); * PL 2020-01-07 kann z.Zt. nicht erzeugt werden (siehe Bug 170, http://bugzilla.ba-horb.de/show_bug.cgi?id=170) JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+"mathStruc.jav")); compiler.typeInference(); compiler.generateBytecode(rootDirectory + "output/"); File f = new File(rootDirectory + "output/de/test/mathStruc.class"); assertTrue(f.exists());
compiler.typeInference();
compiler.generateBytecode(rootDirectory + "output/");
File f = new File(rootDirectory + "output/de/test/mathStruc.class");
assertTrue(f.exists());
*/ */
JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory + "vectorAdd.jav")); JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory + "vectorAdd.jav"));
compiler.typeInference(); compiler.typeInference();
@ -37,9 +32,7 @@ public class mathStrucVectorTest extends TestCase {
@Test @Test
public void testSetPackageNameInBytecodeAndOutputFolder() throws IOException, ClassNotFoundException { public void testSetPackageNameInBytecodeAndOutputFolder() throws IOException, ClassNotFoundException {
JavaTXCompiler compiler = new JavaTXCompiler( JavaTXCompiler compiler = new JavaTXCompiler(Lists.newArrayList(new File(rootDirectory + "mathStrucVector.jav")), Lists.newArrayList(new File(rootDirectory + "output/")));
Lists.newArrayList(new File(rootDirectory+"mathStrucVector.jav")),
Lists.newArrayList(new File(rootDirectory+"output/")));
compiler.typeInference(); compiler.typeInference();
File f = new File(rootDirectory + "output/de/test/mathStrucVector.class"); File f = new File(rootDirectory + "output/de/test/mathStrucVector.class");
if (f.exists() && !f.isDirectory()) { if (f.exists() && !f.isDirectory()) {
@ -50,5 +43,4 @@ public class mathStrucVectorTest extends TestCase {
assertTrue(f.exists()); assertTrue(f.exists());
} }
} }

View File

@ -25,8 +25,7 @@ public class ASTToTypedTargetAST {
@Test @Test
public void emptyClass() { public void emptyClass() {
ClassOrInterface emptyClass = new ClassOrInterface(0, new JavaClassName("EmptyClass"), new ArrayList<>(), java.util.Optional.empty(), new ArrayList<>(), new ArrayList<>(), new GenericDeclarationList(new ArrayList<>(), new NullToken()), ClassOrInterface emptyClass = new ClassOrInterface(0, new JavaClassName("EmptyClass"), new ArrayList<>(), java.util.Optional.empty(), new ArrayList<>(), new ArrayList<>(), new GenericDeclarationList(new ArrayList<>(), new NullToken()), new RefType(new JavaClassName("Object"), new NullToken()), false, new ArrayList<>(), new NullToken());
new RefType(new JavaClassName("Object"), new NullToken()), false, new ArrayList<>(), new NullToken());
ResultSet emptyResultSet = new ResultSet(new HashSet<>()); ResultSet emptyResultSet = new ResultSet(new HashSet<>());
TargetClass emptyTargetClass = new ASTToTargetAST(List.of(emptyResultSet)).convert(emptyClass); TargetClass emptyTargetClass = new ASTToTargetAST(List.of(emptyResultSet)).convert(emptyClass);
assert emptyTargetClass.getName().equals("EmptyClass"); assert emptyTargetClass.getName().equals("EmptyClass");
@ -36,7 +35,7 @@ public class ASTToTypedTargetAST {
@Test @Test
public void overloading() throws Exception { public void overloading() throws Exception {
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Overloading.jav").toFile(); var file = Path.of(System.getProperty("user.dir"), "/src/test/resources/bytecode/javFiles/Overloading.jav").toFile();
var compiler = new JavaTXCompiler(file); var compiler = new JavaTXCompiler(file);
var resultSet = compiler.typeInference(); var resultSet = compiler.typeInference();
var converter = new ASTToTargetAST(resultSet); var converter = new ASTToTargetAST(resultSet);
@ -58,7 +57,7 @@ public class ASTToTypedTargetAST {
@Test @Test
public void tphsAndGenerics() throws Exception { public void tphsAndGenerics() throws Exception {
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Tph2.jav").toFile(); var file = Path.of(System.getProperty("user.dir"), "/src/test/resources/bytecode/javFiles/Tph2.jav").toFile();
var compiler = new JavaTXCompiler(file); var compiler = new JavaTXCompiler(file);
var resultSet = compiler.typeInference(); var resultSet = compiler.typeInference();
var converter = new ASTToTargetAST(resultSet); var converter = new ASTToTargetAST(resultSet);
@ -69,7 +68,7 @@ public class ASTToTypedTargetAST {
@Test @Test
public void cycles() throws Exception { public void cycles() throws Exception {
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Cycle.jav").toFile(); var file = Path.of(System.getProperty("user.dir"), "/src/test/resources/bytecode/javFiles/Cycle.jav").toFile();
var compiler = new JavaTXCompiler(file); var compiler = new JavaTXCompiler(file);
var resultSet = compiler.typeInference(); var resultSet = compiler.typeInference();
var converter = new ASTToTargetAST(resultSet); var converter = new ASTToTargetAST(resultSet);
@ -80,7 +79,7 @@ public class ASTToTypedTargetAST {
@Test @Test
public void infimum() throws Exception { public void infimum() throws Exception {
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Infimum.jav").toFile(); var file = Path.of(System.getProperty("user.dir"), "/src/test/resources/bytecode/javFiles/Infimum.jav").toFile();
var compiler = new JavaTXCompiler(file); var compiler = new JavaTXCompiler(file);
var resultSet = compiler.typeInference(); var resultSet = compiler.typeInference();
var converter = new ASTToTargetAST(resultSet); var converter = new ASTToTargetAST(resultSet);
@ -91,7 +90,7 @@ public class ASTToTypedTargetAST {
@Test @Test
public void gen() throws Exception { public void gen() throws Exception {
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Gen.jav").toFile(); var file = Path.of(System.getProperty("user.dir"), "/src/test/resources/bytecode/javFiles/Gen.jav").toFile();
var compiler = new JavaTXCompiler(file); var compiler = new JavaTXCompiler(file);
var resultSet = compiler.typeInference(); var resultSet = compiler.typeInference();
var converter = new ASTToTargetAST(resultSet); var converter = new ASTToTargetAST(resultSet);
@ -101,12 +100,13 @@ public class ASTToTypedTargetAST {
var m = generics.getDeclaredMethod("m", Vector.class); var m = generics.getDeclaredMethod("m", Vector.class);
var mReturnType = m.getGenericReturnType(); var mReturnType = m.getGenericReturnType();
assertEquals(mReturnType, m.getParameters()[0].getParameterizedType()); assertEquals(mReturnType, m.getParameters()[0].getParameterizedType());
assertEquals(mReturnType, new TypeToken<Vector<Integer>>(){}.getType()); assertEquals(mReturnType, new TypeToken<Vector<Integer>>() {
}.getType());
} }
@Test @Test
public void definedGenerics() throws Exception { public void definedGenerics() throws Exception {
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Generics.jav").toFile(); var file = Path.of(System.getProperty("user.dir"), "/src/test/resources/bytecode/javFiles/Generics.jav").toFile();
var compiler = new JavaTXCompiler(file); var compiler = new JavaTXCompiler(file);
var resultSet = compiler.typeInference(); var resultSet = compiler.typeInference();
var converter = new ASTToTargetAST(resultSet); var converter = new ASTToTargetAST(resultSet);
@ -124,7 +124,7 @@ public class ASTToTypedTargetAST {
@Test @Test
public void definedGenerics2() throws Exception { public void definedGenerics2() throws Exception {
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Generics2.jav").toFile(); var file = Path.of(System.getProperty("user.dir"), "/src/test/resources/bytecode/javFiles/Generics2.jav").toFile();
var compiler = new JavaTXCompiler(file); var compiler = new JavaTXCompiler(file);
var resultSet = compiler.typeInference(); var resultSet = compiler.typeInference();
var converter = new ASTToTargetAST(resultSet); var converter = new ASTToTargetAST(resultSet);
@ -140,7 +140,7 @@ public class ASTToTypedTargetAST {
@Test @Test
@Ignore("Not implemented") @Ignore("Not implemented")
public void definedGenerics3() throws Exception { public void definedGenerics3() throws Exception {
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Generics3.jav").toFile(); var file = Path.of(System.getProperty("user.dir"), "/src/test/resources/bytecode/javFiles/Generics3.jav").toFile();
var compiler = new JavaTXCompiler(file); var compiler = new JavaTXCompiler(file);
var resultSet = compiler.typeInference(); var resultSet = compiler.typeInference();
var converter = new ASTToTargetAST(resultSet); var converter = new ASTToTargetAST(resultSet);
@ -151,7 +151,7 @@ public class ASTToTypedTargetAST {
@Test @Test
public void definedGenerics4() throws Exception { public void definedGenerics4() throws Exception {
var file = Path.of(System.getProperty("user.dir"), "/resources/bytecode/javFiles/Generics4.jav").toFile(); var file = Path.of(System.getProperty("user.dir"), "/src/test/resources/bytecode/javFiles/Generics4.jav").toFile();
var compiler = new JavaTXCompiler(file); var compiler = new JavaTXCompiler(file);
var resultSet = compiler.typeInference(); var resultSet = compiler.typeInference();
var converter = new ASTToTargetAST(resultSet); var converter = new ASTToTargetAST(resultSet);

View File

@ -25,7 +25,6 @@ import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class TestCodegen { public class TestCodegen {
private static void writeClassFile(String name, byte[] code) throws IOException { private static void writeClassFile(String name, byte[] code) throws IOException {
@ -42,7 +41,7 @@ public class TestCodegen {
} }
public static Map<String, ? extends Class<?>> generateClassFiles(String filename, IByteArrayClassLoader classLoader) throws IOException, ClassNotFoundException { 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 file = Path.of(System.getProperty("user.dir"), "/src/test/resources/bytecode/javFiles/", filename).toFile();
var compiler = new JavaTXCompiler(List.of(file), List.of(file.getParentFile())); var compiler = new JavaTXCompiler(List.of(file), List.of(file.getParentFile()));
var resultSet = compiler.typeInference(); var resultSet = compiler.typeInference();
@ -76,42 +75,11 @@ public class TestCodegen {
public void testArithmetic() throws Exception { public void testArithmetic() throws Exception {
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, "Arithmetic"); var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, "Arithmetic");
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "add", 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"))))));
List.of(new MethodParameter(TargetType.Integer, "a"), new MethodParameter(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"))))));
TargetType.Integer, 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"))))));
new TargetBlock(List.of(new TargetReturn( 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"))))));
new TargetBinaryOp.Add(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"))))));
))
);
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()); var clazz = generateClass(targetClass, new ByteArrayClassLoader());
assertEquals(clazz.getDeclaredMethod("add", Integer.class, Integer.class).invoke(null, 10, 10), 20); assertEquals(clazz.getDeclaredMethod("add", Integer.class, Integer.class).invoke(null, 10, 10), 20);
@ -125,27 +93,9 @@ public class TestCodegen {
public void testUnary() throws Exception { public void testUnary() throws Exception {
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, "Unary"); var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, "Unary");
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "not", 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"))))));
List.of(new MethodParameter(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"))))));
TargetType.Integer, 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"))))));
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()); var clazz = generateClass(targetClass, new ByteArrayClassLoader());
assertEquals(clazz.getDeclaredMethod("not", Integer.class).invoke(null, 10), -11); assertEquals(clazz.getDeclaredMethod("not", Integer.class).invoke(null, 10), -11);
@ -158,20 +108,8 @@ public class TestCodegen {
public void testConditional() throws Exception { public void testConditional() throws Exception {
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, "Conditional"); var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, "Conditional");
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "and", 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"))))));
List.of(new MethodParameter(TargetType.Boolean, "a"), new MethodParameter(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"))))));
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 clazz = generateClass(targetClass, new ByteArrayClassLoader());
var and = clazz.getDeclaredMethod("and", Boolean.class, Boolean.class); var and = clazz.getDeclaredMethod("and", Boolean.class, Boolean.class);
@ -186,11 +124,7 @@ public class TestCodegen {
@Test @Test
public void testArithmeticConvert() throws Exception { public void testArithmeticConvert() throws Exception {
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, "ArithmeticConvert"); var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, "ArithmeticConvert");
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "add", List.of(), TargetType.Long, 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))))));
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()); var clazz = generateClass(targetClass, new ByteArrayClassLoader());
assertEquals(clazz.getDeclaredMethod("add").invoke(null), (long) 30); assertEquals(clazz.getDeclaredMethod("add").invoke(null), (long) 30);
} }
@ -198,21 +132,7 @@ public class TestCodegen {
@Test @Test
public void testMethodCall() throws Exception { public void testMethodCall() throws Exception {
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, "HelloWorld"); var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, "HelloWorld");
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "helloWorld", List.of(), null, 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))));
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
)))
);
var clazz = generateClass(targetClass, new ByteArrayClassLoader()); var clazz = generateClass(targetClass, new ByteArrayClassLoader());
clazz.getDeclaredMethod("helloWorld").invoke(null); clazz.getDeclaredMethod("helloWorld").invoke(null);
@ -221,19 +141,7 @@ public class TestCodegen {
@Test @Test
public void testIfStatement() throws Exception { public void testIfStatement() throws Exception {
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, "IfStmt"); var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, "IfStmt");
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "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)))))));
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 clazz = generateClass(targetClass, new ByteArrayClassLoader());
var ifStmt = clazz.getDeclaredMethod("ifStmt", Integer.class); var ifStmt = clazz.getDeclaredMethod("ifStmt", Integer.class);
assertEquals(ifStmt.invoke(null, 10), 1); assertEquals(ifStmt.invoke(null, 10), 1);
@ -244,25 +152,7 @@ public class TestCodegen {
@Test @Test
public void testFor() throws Exception { public void testFor() throws Exception {
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, "For"); var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, "For");
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "forLoop", List.of(), TargetType.Integer, 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(new TargetVarDecl(TargetType.Integer, "i", new TargetLiteral.IntLiteral(0)), new TargetBinaryOp.Less(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "i"), new TargetLiteral.IntLiteral(10)), 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")))));
new TargetBlock(List.of(
new TargetVarDecl(TargetType.Integer, "sum", new TargetLiteral.IntLiteral(0)),
new TargetFor(
new TargetVarDecl(TargetType.Integer, "i", new TargetLiteral.IntLiteral(0)),
new TargetBinaryOp.Less(TargetType.Integer, new TargetLocalVar(TargetType.Integer, "i"), new TargetLiteral.IntLiteral(10)),
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()); var clazz = generateClass(targetClass, new ByteArrayClassLoader());
assertEquals(clazz.getDeclaredMethod("forLoop").invoke(null), 45); assertEquals(clazz.getDeclaredMethod("forLoop").invoke(null), 45);
} }
@ -270,21 +160,7 @@ public class TestCodegen {
@Test @Test
public void testWhile() throws Exception { public void testWhile() throws Exception {
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, "While"); var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, "While");
targetClass.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "whileLoop", List.of(), TargetType.Integer, 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")))));
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()); var clazz = generateClass(targetClass, new ByteArrayClassLoader());
assertEquals(clazz.getDeclaredMethod("whileLoop").invoke(null), 10); assertEquals(clazz.getDeclaredMethod("whileLoop").invoke(null), 10);
} }
@ -295,31 +171,10 @@ public class TestCodegen {
var pointTarget = new TargetClass(Opcodes.ACC_PUBLIC, "Point"); var pointTarget = new TargetClass(Opcodes.ACC_PUBLIC, "Point");
pointTarget.addField(Opcodes.ACC_PUBLIC, TargetType.Integer, "x"); pointTarget.addField(Opcodes.ACC_PUBLIC, TargetType.Integer, "x");
pointTarget.addField(Opcodes.ACC_PUBLIC, TargetType.Integer, "y"); pointTarget.addField(Opcodes.ACC_PUBLIC, TargetType.Integer, "y");
pointTarget.addConstructor(Opcodes.ACC_PUBLIC, pointTarget.addConstructor(Opcodes.ACC_PUBLIC, List.of(new MethodParameter(TargetType.Integer, "x"), new MethodParameter(TargetType.Integer, "y")), new TargetBlock(List.of(new TargetMethodCall(null, new TargetSuper(TargetType.Object), List.of(), TargetType.Object, "<init>", false, false), new TargetAssign(TargetType.Integer, new TargetFieldVar(TargetType.Integer, pointType, false, new TargetThis(pointType), "x"), new TargetLocalVar(TargetType.Integer, "x")), new TargetAssign(TargetType.Integer, new TargetFieldVar(TargetType.Integer, pointType, false, new TargetThis(pointType), "y"), new TargetLocalVar(TargetType.Integer, "y")))));
List.of(new MethodParameter(TargetType.Integer, "x"), new MethodParameter(TargetType.Integer, "y")),
new TargetBlock(List.of(
new TargetMethodCall(null, new TargetSuper(TargetType.Object), List.of(), TargetType.Object, "<init>", false, false),
new TargetAssign(TargetType.Integer,
new TargetFieldVar(TargetType.Integer, pointType, false, new TargetThis(pointType), "x"),
new TargetLocalVar(TargetType.Integer, "x")
),
new TargetAssign(TargetType.Integer,
new TargetFieldVar(TargetType.Integer, pointType, false, new TargetThis(pointType), "y"),
new TargetLocalVar(TargetType.Integer, "y")
)
))
);
var mainTarget = new TargetClass(Opcodes.ACC_PUBLIC, "New"); var mainTarget = new TargetClass(Opcodes.ACC_PUBLIC, "New");
mainTarget.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "makePoint", mainTarget.addMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "makePoint", List.of(new MethodParameter(TargetType.Integer, "x"), new MethodParameter(TargetType.Integer, "y")), pointType, new TargetBlock(List.of(new TargetReturn(new TargetNew(pointType, List.of(new TargetLocalVar(TargetType.Integer, "x"), new TargetLocalVar(TargetType.Integer, "y")))))));
List.of(new MethodParameter(TargetType.Integer, "x"), new MethodParameter(TargetType.Integer, "y")), pointType,
new TargetBlock(List.of(
new TargetReturn(new TargetNew(pointType, List.of(
new TargetLocalVar(TargetType.Integer, "x"),
new TargetLocalVar(TargetType.Integer, "y")
)))
))
);
var classLoader = new ByteArrayClassLoader(); var classLoader = new ByteArrayClassLoader();
var pointClass = generateClass(pointTarget, classLoader); var pointClass = generateClass(pointTarget, classLoader);
@ -338,26 +193,8 @@ public class TestCodegen {
var interfaceType = new TargetFunNType(1, List.of(TargetType.Integer)); var interfaceType = new TargetFunNType(1, List.of(TargetType.Integer));
var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, "CGLambda"); var targetClass = new TargetClass(Opcodes.ACC_PUBLIC, "CGLambda");
targetClass.addConstructor(Opcodes.ACC_PUBLIC, List.of(), new TargetBlock(List.of( 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))));
new TargetMethodCall(null, new TargetSuper(TargetType.Object), List.of(), TargetType.Object, "<init>", false, false) targetClass.addMethod(Opcodes.ACC_PUBLIC, "lambda", List.of(), TargetType.Integer, new TargetBlock(List.of(new TargetVarDecl(interfaceType, "by2", new TargetLambdaExpression(interfaceType, List.of(), List.of(new MethodParameter(TargetType.Integer, "num")), TargetType.Integer, 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))))));
)));
targetClass.addMethod(Opcodes.ACC_PUBLIC, "lambda", List.of(), TargetType.Integer,
new TargetBlock(List.of(
new TargetVarDecl(interfaceType, "by2",
new TargetLambdaExpression(interfaceType, List.of(), List.of(new MethodParameter(TargetType.Integer, "num")), TargetType.Integer,
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)))
))
);
var clazz = generateClass(targetClass, classLoader); var clazz = generateClass(targetClass, classLoader);
var instance = clazz.getConstructor().newInstance(); var instance = clazz.getConstructor().newInstance();
assertEquals(clazz.getDeclaredMethod("lambda").invoke(instance), 20); assertEquals(clazz.getDeclaredMethod("lambda").invoke(instance), 20);

View File

@ -20,10 +20,9 @@ import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class TestGenerics { public class TestGenerics {
private static final String rootDirectory = System.getProperty("user.dir") + "/resources/insertGenericsJav/"; private static final String rootDirectory = System.getProperty("user.dir") + "/src/test/resources/insertGenericsJav/";
private static final String bytecodeDirectory = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/"; private static final String bytecodeDirectory = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/";
private record Result(List<GenericsResult> genericsResults, ClassOrInterface clazz) { private record Result(List<GenericsResult> genericsResults, ClassOrInterface clazz) {
@ -266,12 +265,7 @@ public class TestGenerics {
var generics = result.genericsResults.get(0); var generics = result.genericsResults.get(0);
var AO = generics.getBounds(a.getType(), result.clazz); var AO = generics.getBounds(a.getType(), result.clazz);
var AOBound = new BoundsList( var AOBound = new BoundsList(new Bound(false, TypePlaceholder.of("Y")), new Bound(false, TypePlaceholder.of("AK")), new Bound(false, TypePlaceholder.of("AE")), new Bound(false, ASTToTargetAST.OBJECT));
new Bound(false, TypePlaceholder.of("Y")),
new Bound(false, TypePlaceholder.of("AK")),
new Bound(false, TypePlaceholder.of("AE")),
new Bound(false, ASTToTargetAST.OBJECT)
);
assertEquals(AO, AOBound); assertEquals(AO, AOBound);
var S = generics.getBounds(setA.getParameterList().getParameterAt(0).getType(), result.clazz, setA); var S = generics.getBounds(setA.getParameterList().getParameterAt(0).getType(), result.clazz, setA);
@ -288,12 +282,9 @@ public class TestGenerics {
assertEquals(AE, new BoundsList(new Bound(false, ASTToTargetAST.OBJECT))); assertEquals(AE, new BoundsList(new Bound(false, ASTToTargetAST.OBJECT)));
// TODO main seems to change between runs // 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 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(new Bound(true, TypePlaceholder.of("AK")), new Bound(true, TypePlaceholder.of("AE")), new Bound(false, ASTToTargetAST.OBJECT)))); assertEquals(AG, SChain));
var AG = generics.getBounds(main.getParameterList().getParameterAt(1).getType(), result.clazz, main); */
assertEquals(AE, AE2));
assertEquals(AF, new BoundsList(new Bound(true, TypePlaceholder.of("AK")), new Bound(true, TypePlaceholder.of("AE")), new Bound(false, ASTToTargetAST.OBJECT))));
assertEquals(AG, SChain));*/
} }
@Test @Test

View File

@ -23,96 +23,119 @@ import java.util.Set;
public class JavaTXCompilerTest { public class JavaTXCompilerTest {
public static final String rootDirectory = System.getProperty("user.dir")+"/resources/javFiles/"; public static final String rootDirectory = System.getProperty("user.dir") + "/src/test/resources/javFiles/";
@Test @Test
public void finiteClosure() throws IOException, ClassNotFoundException { public void finiteClosure() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "fc.jav")); execute(new File(rootDirectory + "fc.jav"));
} }
@Test @Test
public void importTest() throws IOException, ClassNotFoundException { public void importTest() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "Import.jav")); execute(new File(rootDirectory + "Import.jav"));
} }
@Test @Test
public void fieldTest() throws IOException, ClassNotFoundException { public void fieldTest() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "FieldAccess.jav")); execute(new File(rootDirectory + "FieldAccess.jav"));
} }
@Test @Test
public void lambda() throws IOException, ClassNotFoundException { public void lambda() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "Lambda.jav")); execute(new File(rootDirectory + "Lambda.jav"));
} }
@Test @Test
public void lambda2() throws IOException, ClassNotFoundException { public void lambda2() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "Lambda2.jav")); execute(new File(rootDirectory + "Lambda2.jav"));
} }
@Test @Test
public void lambda3() throws IOException, ClassNotFoundException { public void lambda3() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "Lambda3.jav")); execute(new File(rootDirectory + "Lambda3.jav"));
} }
@Test @Test
public void lambdaField() throws IOException, ClassNotFoundException { public void lambdaField() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "LambdaField.jav")); execute(new File(rootDirectory + "LambdaField.jav"));
} }
@Test @Test
public void mathStruc() throws IOException, ClassNotFoundException { public void mathStruc() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "mathStruc.jav")); execute(new File(rootDirectory + "mathStruc.jav"));
} }
@Test @Test
public void generics() throws IOException, ClassNotFoundException { public void generics() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "Generics.jav")); execute(new File(rootDirectory + "Generics.jav"));
} }
@Test @Test
public void genericsMethodCall() throws IOException, ClassNotFoundException { public void genericsMethodCall() throws IOException, ClassNotFoundException {
TestResultSet result = execute(new File(rootDirectory + "MethodCallGenerics.jav")); TestResultSet result = execute(new File(rootDirectory + "MethodCallGenerics.jav"));
// TODO: Hier sollte der Rückgabetyp der Methode String sein // TODO: Hier sollte der Rückgabetyp der Methode String sein
} }
@Test @Test
public void faculty() throws IOException, ClassNotFoundException { public void faculty() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "Faculty.jav")); execute(new File(rootDirectory + "Faculty.jav"));
} }
@Test @Test
public void facultyIf() throws IOException, ClassNotFoundException { public void facultyIf() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "FacultyIf.jav")); execute(new File(rootDirectory + "FacultyIf.jav"));
} }
@Test @Test
public void facultyTyped() throws IOException, ClassNotFoundException { public void facultyTyped() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "FacultyTyped.jav")); execute(new File(rootDirectory + "FacultyTyped.jav"));
} }
@Test @Test
public void matrix() throws IOException, ClassNotFoundException { public void matrix() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "Matrix.jav")); execute(new File(rootDirectory + "Matrix.jav"));
} }
@Test @Test
public void packageTests() throws IOException, ClassNotFoundException { public void packageTests() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "Package.jav")); execute(new File(rootDirectory + "Package.jav"));
} }
@Test @Test
public void vector() throws IOException, ClassNotFoundException { public void vector() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "Vector.jav")); execute(new File(rootDirectory + "Vector.jav"));
} }
@Test @Test
public void lambdaRunnable() throws IOException, ClassNotFoundException { public void lambdaRunnable() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "LambdaRunnable.jav")); execute(new File(rootDirectory + "LambdaRunnable.jav"));
} }
@Test @Test
public void expressions() throws IOException, ClassNotFoundException { public void expressions() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "Expressions.jav")); execute(new File(rootDirectory + "Expressions.jav"));
} }
@Test @Test
public void addLong() throws IOException, ClassNotFoundException { public void addLong() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "AddLong.jav")); execute(new File(rootDirectory + "AddLong.jav"));
} }
@Test @Test
public void fields() throws IOException, ClassNotFoundException { public void fields() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "Fields.jav")); execute(new File(rootDirectory + "Fields.jav"));
} }
@Test @Test
public void ifStatement() throws IOException, ClassNotFoundException { public void ifStatement() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "IfTest.jav")); execute(new File(rootDirectory + "IfTest.jav"));
} }
@Test @Test
public void multipleSolutions() throws IOException, ClassNotFoundException { public void multipleSolutions() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "Sorting.jav")); execute(new File(rootDirectory + "Sorting.jav"));
} }
@Test @Test
public void listenerTest() throws IOException, ClassNotFoundException { public void listenerTest() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "ListenerOverload.jav")); execute(new File(rootDirectory + "ListenerOverload.jav"));
@ -166,12 +189,9 @@ public class JavaTXCompilerTest {
return new TestResultSet(); return new TestResultSet();
} }
static String readFile(String path, Charset encoding) static String readFile(String path, Charset encoding) throws IOException {
throws IOException
{
byte[] encoded = Files.readAllBytes(Paths.get(path)); byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding); return new String(encoded, encoding);
} }
} }

View File

@ -23,64 +23,38 @@ import java.util.Set;
public class Meth_GenTest { public class Meth_GenTest {
public static final String rootDirectory = System.getProperty("user.dir")+"/resources/javFiles/"; public static final String rootDirectory = System.getProperty("user.dir") + "/src/test/resources/javFiles/";
/* /*
@Test * @Test public void finiteClosure() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"fc.jav")); }
public void finiteClosure() throws IOException, ClassNotFoundException { *
execute(new File(rootDirectory+"fc.jav")); * @Test public void lambda() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Lambda.jav")); }
} *
@Test * @Test public void lambda2() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Lambda2.jav")); }
public void lambda() throws IOException, ClassNotFoundException { *
execute(new File(rootDirectory+"Lambda.jav")); * @Test public void lambda3() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Lambda3.jav")); }
} *
@Test * @Test public void mathStruc() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"mathStruc.jav")); }
public void lambda2() throws IOException, ClassNotFoundException { *
execute(new File(rootDirectory+"Lambda2.jav")); * @Test public void generics() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Generics.jav")); }
} *
@Test * @Test public void faculty() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Faculty.jav")); }
public void lambda3() throws IOException, ClassNotFoundException { *
execute(new File(rootDirectory+"Lambda3.jav")); * @Test public void facultyTyped() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"FacultyTyped.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 faculty() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"Faculty.jav"));
}
@Test
public void facultyTyped() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"FacultyTyped.jav"));
}
*/ */
@Test @Test
public void matrix() throws IOException, ClassNotFoundException { public void matrix() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory + "Meth_Gen.jav")); execute(new File(rootDirectory + "Meth_Gen.jav"));
} }
/* /*
@Test * @Test public void vector() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Vector.jav")); }
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 * @Test public void expressions() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Expressions.jav")); }
public void lambdaRunnable() throws IOException, ClassNotFoundException { *
execute(new File(rootDirectory+"LambdaRunnable.jav")); * @Test public void matrixFC() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"FC_Matrix.jav")); }
}
@Test
public void expressions() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"Expressions.jav"));
}
@Test
public void matrixFC() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"FC_Matrix.jav"));
}
*/ */
private static class TestResultSet { private static class TestResultSet {
@ -130,12 +104,9 @@ public class Meth_GenTest {
return new TestResultSet(); return new TestResultSet();
} }
static String readFile(String path, Charset encoding) static String readFile(String path, Charset encoding) throws IOException {
throws IOException
{
byte[] encoded = Files.readAllBytes(Paths.get(path)); byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding); return new String(encoded, encoding);
} }
} }

View File

@ -23,63 +23,34 @@ import java.util.Set;
public class UnifyTest { public class UnifyTest {
public static final String rootDirectory = System.getProperty("user.dir")+"/resources/javFiles/"; public static final String rootDirectory = System.getProperty("user.dir") + "/src/test/resources/javFiles/";
/* /*
@Test * @Test public void finiteClosure() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"fc.jav")); }
public void finiteClosure() throws IOException, ClassNotFoundException { *
execute(new File(rootDirectory+"fc.jav")); * @Test public void lambda() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Lambda.jav")); }
} *
@Test
public void lambda() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"Lambda.jav"));
}
*/ */
/* /*
@Test * @Test public void vector() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Vector.jav")); }
public void vector() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"Vector.jav"));
}
*/ */
/* /*
@Test * @Test public void lambda2() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Lambda2.jav")); }
public void lambda2() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"Lambda2.jav"));
}
*/ */
/* /*
@Test * @Test public void lambda3() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Lambda3.jav")); }
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 lambdafield() throws IOException, ClassNotFoundException { * @Test public void generics() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Generics.jav")); }
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 * @Test public void faculty() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Faculty.jav")); }
public void faculty() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"Faculty.jav"));
}
*/ */
/* /*
@Test * @Test public void facultyTyped() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"FacultyTyped.jav")); }
public void facultyTyped() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"FacultyTyped.jav"));
}
*/ */
@Test @Test
@ -89,24 +60,14 @@ public class UnifyTest {
// compiler.generateBytecode(); // compiler.generateBytecode();
} }
/* /*
@Test * @Test public void vector() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Vector.jav")); }
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 * @Test public void expressions() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"Expressions.jav")); }
public void lambdaRunnable() throws IOException, ClassNotFoundException { *
execute(new File(rootDirectory+"LambdaRunnable.jav")); * @Test public void matrixFC() throws IOException, ClassNotFoundException { execute(new File(rootDirectory+"FC_Matrix.jav")); }
}
@Test
public void expressions() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"Expressions.jav"));
}
@Test
public void matrixFC() throws IOException, ClassNotFoundException {
execute(new File(rootDirectory+"FC_Matrix.jav"));
}
*/ */
private static class TestResultSet { private static class TestResultSet {
@ -156,12 +117,9 @@ public class UnifyTest {
return new TestResultSet(); return new TestResultSet();
} }
static String readFile(String path, Charset encoding) static String readFile(String path, Charset encoding) throws IOException {
throws IOException
{
byte[] encoded = Files.readAllBytes(Paths.get(path)); byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding); return new String(encoded, encoding);
} }
} }

Some files were not shown because too many files have changed in this diff Show More