diff --git a/test/bytecode/MatrixTest.java b/test/bytecode/MatrixTest.java index 3ec35e4b..530517b4 100644 --- a/test/bytecode/MatrixTest.java +++ b/test/bytecode/MatrixTest.java @@ -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> m1 = new Vector<>(); // Vector 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> vv = new Vector>(); + Vector v1 = new Vector (); + v1.addElement(2); + v1.addElement(2); + Vector v2 = new Vector (); + 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> vv1 = new Vector>(); + Vector v3 = new Vector (); + v3.addElement(2); + v3.addElement(2); + Vector v4 = new Vector (); + 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()); + } diff --git a/test/bytecode/OLTest.java b/test/bytecode/OLTest.java index 288e580f..d6ab4dd1 100644 --- a/test/bytecode/OLTest.java +++ b/test/bytecode/OLTest.java @@ -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); } - } diff --git a/test/bytecode/javFiles/OL.jav b/test/bytecode/javFiles/OL.jav index ea73c2d1..263cf1ec 100644 --- a/test/bytecode/javFiles/OL.jav +++ b/test/bytecode/javFiles/OL.jav @@ -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;