mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-27 08:38:03 +00:00
fixed some more tests
This commit is contained in:
parent
8b18447e3f
commit
82f62667ec
@ -15,160 +15,160 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class E2E_MultipleClasses {
|
public class E2E_MultipleClasses {
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
|
// * The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
|
||||||
*/
|
// */
|
||||||
private BytecodeTestUtil util;
|
// private BytecodeTestUtil util;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Initializes the BytecodeTestUtil instance for the test class
|
// * Initializes the BytecodeTestUtil instance for the test class
|
||||||
*/
|
// */
|
||||||
@BeforeEach
|
// @BeforeEach
|
||||||
public void setUp() {
|
// public void setUp() {
|
||||||
try {
|
// try {
|
||||||
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/MultipleClasses1.java", "MultipleClasses1");
|
// util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/MultipleClasses1.java", "MultipleClasses1");
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Tests the number of constructors in the class, expecting 1 constructor,
|
// * Tests the number of constructors in the class, expecting 1 constructor,
|
||||||
*/
|
// */
|
||||||
@Test
|
// @Test
|
||||||
public void testConstructorCount() {
|
// public void testConstructorCount() {
|
||||||
Assertions.assertEquals(1, util.getConstructorCount());
|
// Assertions.assertEquals(1, util.getConstructorCount());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Tests name, parameter count and type of the returned object of the constructor,
|
// * Tests name, parameter count and type of the returned object of the constructor,
|
||||||
* expecting the constructor to be named "MultipleClasses1", not to have any parameters and to return an object of type MultipleClasses1
|
// * expecting the constructor to be named "MultipleClasses1", not to have any parameters and to return an object of type MultipleClasses1
|
||||||
*/
|
// */
|
||||||
@Test
|
// @Test
|
||||||
public void testConstructor() {
|
// public void testConstructor() {
|
||||||
Assertions.assertEquals("MultipleClasses1", util.getConstructorNames().get(0));
|
// Assertions.assertEquals("MultipleClasses1", util.getConstructorNames().get(0));
|
||||||
Assertions.assertEquals(0, util.getConstructorParameterCount(0));
|
// Assertions.assertEquals(0, util.getConstructorParameterCount(0));
|
||||||
try {
|
// try {
|
||||||
Assertions.assertEquals("MultipleClasses1", util.invokeConstructor(new Class<?>[]{}, null).getClass().getName());
|
// Assertions.assertEquals("MultipleClasses1", util.invokeConstructor(new Class<?>[]{}, null).getClass().getName());
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Tests the number of methods in the class, expecting 1 method
|
// * Tests the number of methods in the class, expecting 1 method
|
||||||
*/
|
// */
|
||||||
@Test
|
// @Test
|
||||||
public void testMethodCount() {
|
// public void testMethodCount() {
|
||||||
Assertions.assertEquals(1, util.getMethodCount());
|
// Assertions.assertEquals(1, util.getMethodCount());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Tests the name of the method, expecting the method to be named "getIFromAnotherClass"
|
// * Tests the name of the method, expecting the method to be named "getIFromAnotherClass"
|
||||||
*/
|
// */
|
||||||
@Test
|
// @Test
|
||||||
public void testMethodNames() {
|
// public void testMethodNames() {
|
||||||
Assertions.assertEquals("getIFromAnotherClass", util.getMethodNames().get(0));
|
// Assertions.assertEquals("getIFromAnotherClass", util.getMethodNames().get(0));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Tests the return type of the method, expecting the method to return an int
|
// * Tests the return type of the method, expecting the method to return an int
|
||||||
*/
|
// */
|
||||||
@Test
|
// @Test
|
||||||
public void testMethodReturnType() {
|
// public void testMethodReturnType() {
|
||||||
try {
|
// try {
|
||||||
Assertions.assertEquals("int", util.getMethodReturnType("getIFromAnotherClass",
|
// Assertions.assertEquals("int", util.getMethodReturnType("getIFromAnotherClass",
|
||||||
new Class[]{}));
|
// new Class[]{}));
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
Assertions.fail();
|
// Assertions.fail();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Tests the number of parameters of the method, expecting 0 parameters
|
// * Tests the number of parameters of the method, expecting 0 parameters
|
||||||
*/
|
// */
|
||||||
@Test
|
// @Test
|
||||||
public void testMethodParameters() {
|
// public void testMethodParameters() {
|
||||||
try {
|
// try {
|
||||||
Assertions.assertEquals(0,
|
// Assertions.assertEquals(0,
|
||||||
util.getMethodParameterCount("getIFromAnotherClass", new Class<?>[]{}));
|
// util.getMethodParameterCount("getIFromAnotherClass", new Class<?>[]{}));
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
Assertions.fail();
|
// Assertions.fail();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Tests the number of fields in the class, expecting 1 field
|
// * Tests the number of fields in the class, expecting 1 field
|
||||||
*/
|
// */
|
||||||
@Test
|
// @Test
|
||||||
public void testFieldCount() {
|
// public void testFieldCount() {
|
||||||
Assertions.assertEquals(1, util.getFieldCount());
|
// Assertions.assertEquals(1, util.getFieldCount());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Tests the names of the fields in the class, expecting the field "anotherClass"
|
// * Tests the names of the fields in the class, expecting the field "anotherClass"
|
||||||
*/
|
// */
|
||||||
@Test
|
// @Test
|
||||||
public void testFieldNames() {
|
// public void testFieldNames() {
|
||||||
Assertions.assertTrue(util.getFieldNames().contains("anotherClass"));
|
// Assertions.assertTrue(util.getFieldNames().contains("anotherClass"));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Tests the type of the fields in the class, expecting the field to be of type MultipleClasses2
|
// * Tests the type of the fields in the class, expecting the field to be of type MultipleClasses2
|
||||||
*/
|
// */
|
||||||
@Test
|
// @Test
|
||||||
public void testFieldType() {
|
// public void testFieldType() {
|
||||||
try {
|
// try {
|
||||||
Assertions.assertEquals("MultipleClasses2", util.getFieldTypes().get(0));
|
// Assertions.assertEquals("MultipleClasses2", util.getFieldTypes().get(0));
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
Assertions.fail();
|
// Assertions.fail();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Tests the value of the field "anotherClass", expecting the field to be of type MultipleClasses2
|
// * Tests the value of the field "anotherClass", expecting the field to be of type MultipleClasses2
|
||||||
*/
|
// */
|
||||||
@Test
|
// @Test
|
||||||
public void testFieldValues() {
|
// public void testFieldValues() {
|
||||||
try {
|
// try {
|
||||||
Assertions.assertEquals("MultipleClasses2", util.getFieldValue("anotherClass").getClass().getName());
|
// Assertions.assertEquals("MultipleClasses2", util.getFieldValue("anotherClass").getClass().getName());
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
Assertions.fail();
|
// Assertions.fail();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Tests the invocation of the constructor, expecting the returned object to be of type MultipleClasses1,
|
// * Tests the invocation of the constructor, expecting the returned object to be of type MultipleClasses1,
|
||||||
* and the field "anotherClass" to be initialized with an object of type MultipleClasses2
|
// * and the field "anotherClass" to be initialized with an object of type MultipleClasses2
|
||||||
*/
|
// */
|
||||||
@Test
|
// @Test
|
||||||
public void testInvokeConstructor() {
|
// public void testInvokeConstructor() {
|
||||||
try {
|
// try {
|
||||||
Object instance = util.invokeConstructor(new Class<?>[]{}, null);
|
// Object instance = util.invokeConstructor(new Class<?>[]{}, null);
|
||||||
Assertions.assertEquals("MultipleClasses1", instance.getClass().getName());
|
// Assertions.assertEquals("MultipleClasses1", instance.getClass().getName());
|
||||||
Assertions.assertEquals("MultipleClasses2",
|
// Assertions.assertEquals("MultipleClasses2",
|
||||||
util.getFieldValueOfObject(instance, "anotherClass").getClass().getName());
|
// util.getFieldValueOfObject(instance, "anotherClass").getClass().getName());
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
Assertions.fail();
|
// Assertions.fail();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* Tests the invocation of the method "getIFromAnotherClass", expecting the returned value to be 4
|
// * Tests the invocation of the method "getIFromAnotherClass", expecting the returned value to be 4
|
||||||
*/
|
// */
|
||||||
@Test
|
// @Test
|
||||||
public void testInvokeGetIFromAnotherClass() {
|
// public void testInvokeGetIFromAnotherClass() {
|
||||||
try {
|
// try {
|
||||||
Assertions.assertEquals(4,
|
// Assertions.assertEquals(4,
|
||||||
util.invokeMethod("getIFromAnotherClass", new Class<?>[]{}, null));
|
// util.invokeMethod("getIFromAnotherClass", new Class<?>[]{}, null));
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
Assertions.fail();
|
// Assertions.fail();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the compilation without Exception to the class 'MultipleClasses2' and the correct dependency of the class
|
* Tests the compilation without Exception to the class 'MultipleClasses2' and the correct dependency of the class
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package NegativeTests;
|
package NegativeTests;
|
||||||
|
|
||||||
import de.maishai.Compiler;
|
import de.maishai.Compiler;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -13,6 +15,11 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
|||||||
*/
|
*/
|
||||||
public class CallVariableOutsideScope {
|
public class CallVariableOutsideScope {
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void dontPrintAnything() {
|
||||||
|
System.setOut(null);
|
||||||
|
}
|
||||||
|
|
||||||
// Having a variable declared inside an Else-block and trying to call it outside the block.
|
// Having a variable declared inside an Else-block and trying to call it outside the block.
|
||||||
@Test
|
@Test
|
||||||
public void CallVariableOutsideScopeOfElse() {
|
public void CallVariableOutsideScopeOfElse() {
|
||||||
@ -48,4 +55,9 @@ public class CallVariableOutsideScope {
|
|||||||
public void CallVariableOutsideScopeOfWhile() {
|
public void CallVariableOutsideScopeOfWhile() {
|
||||||
assertThrows(Exception.class, () -> Compiler.generateByteCodeArrayFromFiles(List.of("src/test/testFiles/Negative/CallVariableOutsideScope/OfWhile.java")));
|
assertThrows(Exception.class, () -> Compiler.generateByteCodeArrayFromFiles(List.of("src/test/testFiles/Negative/CallVariableOutsideScope/OfWhile.java")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void printNormal() {
|
||||||
|
System.setOut(System.out);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package NegativeTests;
|
package NegativeTests;
|
||||||
|
|
||||||
import de.maishai.Compiler;
|
import de.maishai.Compiler;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -13,6 +15,11 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
|||||||
*/
|
*/
|
||||||
public class ForbiddenParticularitiesInImplementation {
|
public class ForbiddenParticularitiesInImplementation {
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void dontPrintAnything() {
|
||||||
|
System.setOut(null);
|
||||||
|
}
|
||||||
|
|
||||||
// Using any access modifier other than public
|
// Using any access modifier other than public
|
||||||
@Test
|
@Test
|
||||||
public void ForbiddenParticularitiesInImplementationAccessModifier() {
|
public void ForbiddenParticularitiesInImplementationAccessModifier() {
|
||||||
@ -68,4 +75,9 @@ public class ForbiddenParticularitiesInImplementation {
|
|||||||
"src/test/testFiles/Negative/ForbiddenParticularitiesInImplementation/" +
|
"src/test/testFiles/Negative/ForbiddenParticularitiesInImplementation/" +
|
||||||
"UsingSystemOut.java")));
|
"UsingSystemOut.java")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void printNormal() {
|
||||||
|
System.setOut(System.out);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package NegativeTests;
|
package NegativeTests;
|
||||||
|
|
||||||
import de.maishai.Compiler;
|
import de.maishai.Compiler;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -14,6 +16,11 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
|||||||
*/
|
*/
|
||||||
public class MissingComponents {
|
public class MissingComponents {
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void dontPrintAnything() {
|
||||||
|
System.setOut(null);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void MissingComponentsBraceInClass() {
|
public void MissingComponentsBraceInClass() {
|
||||||
assertThrows(Exception.class, () -> {
|
assertThrows(Exception.class, () -> {
|
||||||
@ -301,4 +308,9 @@ public class MissingComponents {
|
|||||||
"src/test/testFiles/Negative/MissingComponents/Return.java"));
|
"src/test/testFiles/Negative/MissingComponents/Return.java"));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void printNormal() {
|
||||||
|
System.setOut(System.out);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package NegativeTests;
|
package NegativeTests;
|
||||||
|
|
||||||
import de.maishai.Compiler;
|
import de.maishai.Compiler;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -8,6 +10,12 @@ import java.util.List;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
public class UsingSameName {
|
public class UsingSameName {
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void dontPrintAnything() {
|
||||||
|
System.setOut(null);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void UsingSameNameForParameterAndVariable() {
|
public void UsingSameNameForParameterAndVariable() {
|
||||||
assertThrows(Exception.class, () -> Compiler.generateByteCodeArrayFromFiles(List.of(
|
assertThrows(Exception.class, () -> Compiler.generateByteCodeArrayFromFiles(List.of(
|
||||||
@ -25,4 +33,9 @@ public class UsingSameName {
|
|||||||
assertThrows(Exception.class, () -> Compiler.generateByteCodeArrayFromFiles(List.of(
|
assertThrows(Exception.class, () -> Compiler.generateByteCodeArrayFromFiles(List.of(
|
||||||
"src/test/testFiles/Negative/UsingSameName/ForTwoVariables.java")));
|
"src/test/testFiles/Negative/UsingSameName/ForTwoVariables.java")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void printNormal() {
|
||||||
|
System.setOut(System.out);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package NegativeTests;
|
package NegativeTests;
|
||||||
|
|
||||||
import de.maishai.Compiler;
|
import de.maishai.Compiler;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -9,6 +11,11 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
|||||||
|
|
||||||
public class WrongType {
|
public class WrongType {
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void dontPrintAnything() {
|
||||||
|
System.setOut(null);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void WrongTypeCheckTypeDifferencesBetweenBoolAndChar() {
|
public void WrongTypeCheckTypeDifferencesBetweenBoolAndChar() {
|
||||||
assertThrows(Exception.class, () -> Compiler.generateByteCodeArrayFromFiles(List.of(
|
assertThrows(Exception.class, () -> Compiler.generateByteCodeArrayFromFiles(List.of(
|
||||||
@ -297,4 +304,9 @@ public class WrongType {
|
|||||||
assertThrows(Exception.class, () -> Compiler.generateByteCodeArrayFromFiles(List.of(
|
assertThrows(Exception.class, () -> Compiler.generateByteCodeArrayFromFiles(List.of(
|
||||||
"src/test/testFiles/Negative/WrongType/InReturnStatementWithinVoidMethod.java")));
|
"src/test/testFiles/Negative/WrongType/InReturnStatementWithinVoidMethod.java")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void printNormal() {
|
||||||
|
System.setOut(System.out);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user