modified: test/bytecode/MatrixTest.java

Test einfeguegt nicht getestet
	modified:   test/bytecode/OLTest.java
Test eingefuegt
	modified:   test/bytecode/javFiles/OL.jav
- Main in OLMain umbenannt
- Klassen publich gemacht
This commit is contained in:
Martin Plümicke 2018-07-18 15:34:49 +02:00
parent 2d5f03a3e0
commit 16b7db9218
3 changed files with 107 additions and 14 deletions

View File

@ -22,10 +22,11 @@ public class MatrixTest {
private static ClassLoader loader;
private static Class<?> classToTest;
private static String pathToClassFile;
private static Object instanceOfClass;
private static Object instanceOfClass_m1;
private static Object instanceOfClass_m2;
// @BeforeClass
// public static void setUpBeforeClass() throws Exception {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
// path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Matrix.jav";
// fileToTest = new File(path);
// compiler = new JavaTXCompiler(fileToTest);
@ -34,10 +35,19 @@ public class MatrixTest {
// loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
// classToTest = loader.loadClass("Matrix");
// instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
// }
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Matrix.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("Matrix");
}
@Test
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IOException {
public void test() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IOException, InstantiationException {
// Vector<Vector<Integer>> m1 = new Vector<>();
// Vector<Integer> r1 = new Vector<>();
// r1.addElement(1);
@ -58,11 +68,40 @@ public class MatrixTest {
// mr2.addElement(4);
// m2.add(mr2);
path = System.getProperty("user.dir")+"/test/bytecode/javFiles/Matrix.jav";
fileToTest = new File(path);
compiler = new JavaTXCompiler(fileToTest);
pathToClassFile = System.getProperty("user.dir")+"/testBytecode/generatedBC/";
compiler.generateBytecode(pathToClassFile);
Vector<Vector<Integer>> vv = new Vector<Vector<Integer>>();
Vector<Integer> v1 = new Vector<Integer> ();
v1.addElement(2);
v1.addElement(2);
Vector<Integer> v2 = new Vector<Integer> ();
v2.addElement(3);
v2.addElement(3);
//Matrix m1 = new Matrix();
//m1.addElement(v1);
//m1.addElement(v2);
vv.addElement(v1);
vv.addElement(v2);
instanceOfClass_m1 = classToTest.getDeclaredConstructor().newInstance(vv); //Matrix m1 = new Matrix(vv);
Vector<Vector<Integer>> vv1 = new Vector<Vector<Integer>>();
Vector<Integer> v3 = new Vector<Integer> ();
v3.addElement(2);
v3.addElement(2);
Vector<Integer> v4 = new Vector<Integer> ();
v4.addElement(3);
v4.addElement(3);
//Matrix m2 = new Matrix();
//m2.addElement(v3);
//m2.addElement(v4);
vv1.addElement(v3);
vv1.addElement(v4);
instanceOfClass_m2 = classToTest.getDeclaredConstructor().newInstance(vv1);//Matrix m2 = new Matrix(vv1);
//Matrix m3 = m1.mul(vv1);
Method m = classToTest.getDeclaredMethod("mul", Double.class);
Object result = m.invoke(instanceOfClass_m1, instanceOfClass_m2);
System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m1.toString() + " = " + result.toString());
}

View File

@ -3,6 +3,8 @@ 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;
@ -17,8 +19,10 @@ public class OLTest {
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 {
@ -30,10 +34,59 @@ public class OLTest {
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
classToTest = loader.loadClass("OL");
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
classToTest1 = loader.loadClass("OLMain");
instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance();
}
@Test
public void test() {
fail("Not yet implemented");
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(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(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(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(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);
}
}

View File

@ -1,3 +1,4 @@
import java.lang.String;
import java.lang.Integer;
import java.lang.Double;
@ -12,7 +13,7 @@ public class OL {
}
class Main {
public class OLMain {
main(x) {
var ol;