new file: ../../../../../../../../java/packages/OLTest.java
new file: ../../../OL.jav new file: ../../../OLMain.jav
This commit is contained in:
parent
0c9c8ef321
commit
bd0b2e6058
102
src/test/java/packages/OLTest.java
Normal file
102
src/test/java/packages/OLTest.java
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
package packages;
|
||||||
|
|
||||||
|
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 java.util.List;
|
||||||
|
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||||
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
|
public class OLTest {
|
||||||
|
private static String path;
|
||||||
|
private static File fileToTest;
|
||||||
|
private static JavaTXCompiler compiler;
|
||||||
|
private static ClassLoader loader;
|
||||||
|
private static Class<?> classToTest;
|
||||||
|
private static Class<?> classToTest1;
|
||||||
|
private static String pathToClassFile;
|
||||||
|
private static Object instanceOfClass;
|
||||||
|
private static Object instanceOfClass1;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setUpBeforeClass() throws Exception {
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/de/test/OL.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/de/test/";
|
||||||
|
compiler.generateBytecode(pathToClassFile);
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTest = loader.loadClass("OL");
|
||||||
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
|
path = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/de/test/OLMain.jav";
|
||||||
|
fileToTest = new File(path);
|
||||||
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/de/test/";
|
||||||
|
compiler.generateBytecode(pathToClassFile);
|
||||||
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
|
classToTest1 = loader.loadClass("OLMain");
|
||||||
|
instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOLClassName() {
|
||||||
|
assertEquals("OL", classToTest.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method m = classToTest.getDeclaredMethod("m", Integer.class);
|
||||||
|
Integer result = (Integer) m.invoke(instanceOfClass, 5);
|
||||||
|
assertEquals(new Integer(10), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method m = classToTest.getDeclaredMethod("m", Double.class);
|
||||||
|
Double result = (Double) m.invoke(instanceOfClass, 5.0);
|
||||||
|
assertEquals(new Double(10.0), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method m = classToTest.getDeclaredMethod("m", String.class);
|
||||||
|
String result = (String) m.invoke(instanceOfClass, "xxx");
|
||||||
|
assertEquals("xxxxxx", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOLMainClassName() {
|
||||||
|
assertEquals("OLMain", classToTest1.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method main = classToTest1.getDeclaredMethod("main", Integer.class);
|
||||||
|
Integer result = (Integer) main.invoke(instanceOfClass1, 5);
|
||||||
|
assertEquals(new Integer(10), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method main = classToTest1.getDeclaredMethod("main", Double.class);
|
||||||
|
Double result = (Double) main.invoke(instanceOfClass1, 5.0);
|
||||||
|
assertEquals(new Double(10.0), result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testmainString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||||
|
Method main = classToTest1.getDeclaredMethod("main", String.class);
|
||||||
|
String result = (String) main.invoke(instanceOfClass1, "xxx");
|
||||||
|
assertEquals("xxxxxx", result);
|
||||||
|
}
|
||||||
|
}
|
12
src/test/resources/javFiles/packageTest/de/test/OL.jav
Normal file
12
src/test/resources/javFiles/packageTest/de/test/OL.jav
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import java.lang.String;
|
||||||
|
import java.lang.Integer;
|
||||||
|
import java.lang.Double;
|
||||||
|
import java.lang.Boolean;
|
||||||
|
//import java.util.Vector;
|
||||||
|
|
||||||
|
|
||||||
|
public class OL {
|
||||||
|
|
||||||
|
m(x) { return x + x; }
|
||||||
|
|
||||||
|
}
|
10
src/test/resources/javFiles/packageTest/de/test/OLMain.jav
Normal file
10
src/test/resources/javFiles/packageTest/de/test/OLMain.jav
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import OL;
|
||||||
|
|
||||||
|
public class OLMain {
|
||||||
|
|
||||||
|
main(x) {
|
||||||
|
var ol;
|
||||||
|
ol = new OL();
|
||||||
|
return ol.m(x);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user