142 lines
6.1 KiB
Java
142 lines
6.1 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 LessThanTest {
|
|
|
|
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/LessThan.jav";
|
|
fileToTest = new File(path);
|
|
compiler = new JavaTXCompiler(fileToTest);
|
|
compiler.generateBytecode();
|
|
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
|
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
|
classToTest = loader.loadClass("LessThan");
|
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
|
}
|
|
|
|
@Test
|
|
public void testClassName() {
|
|
assertEquals("LessThan", classToTest.getName());
|
|
}
|
|
|
|
@Test
|
|
public void testLessThanInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessThan = classToTest.getDeclaredMethod("lessThan", Integer.class,Integer.class);
|
|
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 5, 7);
|
|
assertTrue(result);
|
|
}
|
|
|
|
@Test
|
|
public void testLessThanInt2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessThan = classToTest.getDeclaredMethod("lessThan", Integer.class, Integer.class);
|
|
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7, 5);
|
|
assertFalse(result);
|
|
}
|
|
|
|
@Test
|
|
public void testLessThanInt3() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessThan = classToTest.getDeclaredMethod("lessThan", Integer.class, Integer.class);
|
|
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 5, 5);
|
|
assertFalse(result);
|
|
}
|
|
|
|
@Test
|
|
public void testLessThanLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessThan = classToTest.getDeclaredMethod("lessThan", Long.class,Long.class);
|
|
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 5L, 7L);
|
|
assertTrue(result);
|
|
}
|
|
|
|
@Test
|
|
public void testLessThanLong2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessThan = classToTest.getDeclaredMethod("lessThan", Long.class, Long.class);
|
|
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7L, 5L);
|
|
assertFalse(result);
|
|
}
|
|
|
|
@Test
|
|
public void testLessThanLong3() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessThan = classToTest.getDeclaredMethod("lessThan", Long.class, Long.class);
|
|
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 5L, 5L);
|
|
assertFalse(result);
|
|
}
|
|
|
|
@Test
|
|
public void testLessThanFloat() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessThan = classToTest.getDeclaredMethod("lessThan", Float.class, Float.class);
|
|
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7F, 5F);
|
|
assertFalse(result);
|
|
}
|
|
|
|
@Test
|
|
public void testLessThanDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessThan = classToTest.getDeclaredMethod("lessThan", Double.class, Double.class);
|
|
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7.0, 5.0);
|
|
assertFalse(result);
|
|
}
|
|
|
|
@Test
|
|
public void testLessThanLongInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessThan = classToTest.getDeclaredMethod("lessThan", Long.class, Integer.class);
|
|
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7L, 5);
|
|
assertFalse(result);
|
|
}
|
|
|
|
@Test
|
|
public void testLessThanFloatInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessThan = classToTest.getDeclaredMethod("lessThan", Float.class, Integer.class);
|
|
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7F, 5);
|
|
assertFalse(result);
|
|
}
|
|
|
|
@Test
|
|
public void testLessThanDoubleInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessThan = classToTest.getDeclaredMethod("lessThan", Double.class, Integer.class);
|
|
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7.0, 5);
|
|
assertFalse(result);
|
|
}
|
|
|
|
@Test
|
|
public void testLessThanFloatLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessThan = classToTest.getDeclaredMethod("lessThan", Float.class, Long.class);
|
|
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7F, 5L);
|
|
assertFalse(result);
|
|
}
|
|
|
|
@Test
|
|
public void testLessThanDoubleLong() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessThan = classToTest.getDeclaredMethod("lessThan", Double.class, Long.class);
|
|
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7.0, 5L);
|
|
assertFalse(result);
|
|
}
|
|
|
|
@Test
|
|
public void testLessThanDoubleFloat() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
|
Method lessThan = classToTest.getDeclaredMethod("lessThan", Double.class, Float.class);
|
|
Boolean result = (Boolean) lessThan.invoke(instanceOfClass, 7.0, 5F);
|
|
assertFalse(result);
|
|
}
|
|
|
|
}
|