added some e2e tests

This commit is contained in:
JonathanFleischmann 2024-06-28 23:18:15 +02:00
parent d11197173e
commit 4974a218b4
5 changed files with 131 additions and 17 deletions

View File

@ -172,7 +172,7 @@ public class ScannerParserTests {
@Test
public void testMultipleClasses() {
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/MultipleClasses.java"));
Program resultAst = Compiler.generateASTFromFiles(List.of("src/test/testFiles/JavaTestfilesFeatures/MultipleClasses1.java"));
assertEquals(AST_MultipleClasses.get(), resultAst);
}

View File

@ -2,9 +2,120 @@ package testResources.CodeGen.Features;
import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import testResources.CodeGen.BytecodeTestUtil;
import java.util.List;
public class ByteCode_MultipleClasses {
// TODO: implement with multiple Files
private BytecodeTestUtil util;
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/CodeGenFeatures/MultipleClasses1.java",
"src/test/testFiles/CodeGenFeatures/MultipleClasses2.java"), "MultipleClasses1");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
}
@Test
public void testConstructor() {
Assertions.assertEquals("MultipleClasses1", util.getConstructorNames().get(0));
Assertions.assertEquals(0, util.getConstructorParameterCount(0));
try {
Assertions.assertEquals("MultipleClasses1", util.invokeConstructor(new Class<?>[]{}, null).getClass().getName());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Test
public void testMethodCount() {
Assertions.assertEquals(1, util.getMethodCount());
}
@Test
public void testMethodNames() {
Assertions.assertEquals("getIFromAnotherClass", util.getMethodNames().get(0));
}
@Test
public void testMethodReturnType() {
try {
Assertions.assertEquals("int", util.getMethodReturnType("getIFromAnotherClass",
new Class[]{}));
} catch (Exception e) {
Assertions.fail();
}
}
@Test
public void testMethodParameters() {
try {
Assertions.assertEquals(0,
util.getMethodParameterCount("getIFromAnotherClass", new Class<?>[]{}));
} catch (Exception e) {
Assertions.fail();
}
}
@Test
public void testFieldCount() {
Assertions.assertEquals(1, util.getFieldCount());
}
@Test
public void testFieldNames() {
Assertions.assertTrue(util.getFieldNames().contains("anotherClass"));
}
@Test
public void testFieldType() {
try {
Assertions.assertEquals("MultipleClasses2", util.getFieldTypes().get(0));
} catch (Exception e) {
Assertions.fail();
}
}
@Test
public void testFieldValues() {
try {
Assertions.assertEquals("MultipleClasses2", util.getFieldValue("anotherClass").getClass().getName());
} catch (Exception e) {
Assertions.fail();
}
}
@Test
public void testInvokeConstructor() {
try {
Object instance = util.invokeConstructor(new Class<?>[]{}, null);
Assertions.assertEquals("MultipleClasses1", instance.getClass().getName());
Assertions.assertEquals("MultipleClasses2",
util.getFieldValueOfObject(instance, "anotherClass").getClass().getName());
} catch (Exception e) {
Assertions.fail();
}
}
@Test
public void testInvokeGetIFromAnotherClass() {
try {
Assertions.assertEquals(4,
util.invokeMethod("getIFromAnotherClass", new Class<?>[]{}, null));
} catch (Exception e) {
Assertions.fail();
}
}
}

View File

@ -1,15 +0,0 @@
public class MultipleClasses {
AnotherClass anotherClass;
public MultipleClasses() {
this.anotherClass = new AnotherClass();
}
}
public class AnotherClass {
MultipleClasses multipleClasses;
public AnotherClass() {
this.multipleClasses = new MultipleClasses();
}
}

View File

@ -0,0 +1,11 @@
public class MultipleClasses1 {
MultipleClasses2 anotherClass;
public MultipleClasses1() {
this.anotherClass = new MultipleClasses2();
}
public int getIFromAnotherClass() {
return this.anotherClass.i;
}
}

View File

@ -0,0 +1,7 @@
public class MultipleClasses2 {
int i;
public MultipleClasses2() {
this.i = 4;
}
}