forked from JavaTX/JavaCompilerCore
134 lines
5.7 KiB
Java
134 lines
5.7 KiB
Java
package bytecode;
|
|
|
|
import static org.junit.Assert.*;
|
|
|
|
import java.io.File;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.Method;
|
|
import java.net.URL;
|
|
import java.net.URLClassLoader;
|
|
|
|
import org.junit.BeforeClass;
|
|
import org.junit.Test;
|
|
|
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
|
|
|
public class LessEqualTest {
|
|
|
|
private static String path;
|
|
private static File fileToTest;
|
|
private static JavaTXCompiler compiler;
|
|
private static ClassLoader loader;
|
|
private static Class<?> classToTest;
|
|
private static String pathToClassFile;
|
|
private static Object instanceOfClass;
|
|
|
|
@BeforeClass
|
|
public static void setUpBeforeClass() throws Exception {
|
|
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/LessEqual.jav";
|
|
fileToTest = new File(path);
|
|
compiler = new JavaTXCompiler(fileToTest);
|
|
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
|
compiler.generateBytecode(pathToClassFile);
|
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
|
classToTest = loader.loadClass("LessEqual");
|
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
|
}
|
|
|
|
@Test
|
|
public void testName() {
|
|
assertEquals("LessEqual", classToTest.getName());
|
|
}
|
|
|
|
@Test
|
|
public void testIntegers() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Integer.class, Integer.class);
|
|
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5,7);
|
|
assertTrue(result);
|
|
}
|
|
|
|
@Test
|
|
public void testEqualIntegers() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Integer.class, Integer.class);
|
|
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5,5);
|
|
assertTrue(result);
|
|
}
|
|
|
|
@Test
|
|
public void testLongs() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Long.class, Long.class);
|
|
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5L,7L);
|
|
assertTrue(result);
|
|
}@Test
|
|
|
|
public void testFloats() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Float.class, Float.class);
|
|
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5F,7F);
|
|
assertTrue(result);
|
|
}
|
|
|
|
@Test
|
|
public void testDoubles() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Double.class);
|
|
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5.0,7.0);
|
|
assertTrue(result);
|
|
}
|
|
|
|
@Test
|
|
public void testLongInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Long.class, Integer.class);
|
|
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5L,7);
|
|
assertTrue(result);
|
|
}
|
|
|
|
@Test
|
|
public void testFloatInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Float.class, Integer.class);
|
|
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5F,7);
|
|
assertTrue(result);
|
|
}
|
|
|
|
@Test
|
|
public void testDoubleInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Integer.class);
|
|
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5.0,7);
|
|
assertTrue(result);
|
|
}
|
|
|
|
@Test
|
|
public void testFloatLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Float.class, Long.class);
|
|
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5F,7L);
|
|
assertTrue(result);
|
|
}
|
|
|
|
@Test
|
|
public void testDoubleLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Long.class);
|
|
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5.0,7L);
|
|
assertTrue(result);
|
|
}
|
|
|
|
@Test
|
|
public void testEqDoubleFloat() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Float.class);
|
|
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 7.0,7F);
|
|
assertTrue(result);
|
|
}
|
|
|
|
@Test
|
|
public void testDoubleFloat() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Float.class);
|
|
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 5.0,7F);
|
|
assertTrue(result);
|
|
}
|
|
|
|
@Test
|
|
public void testDoubleFloat3() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessEqual = classToTest.getDeclaredMethod("lessEqual", Double.class, Float.class);
|
|
Boolean result = (Boolean) lessEqual.invoke(instanceOfClass, 9.0,7F);
|
|
assertFalse(result);
|
|
}
|
|
|
|
}
|