From bd0b2e605891d8fdbf3aa3651adb87036ba9a7ff Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Mon, 30 Dec 2019 10:45:32 +0100 Subject: [PATCH] new file: ../../../../../../../../java/packages/OLTest.java new file: ../../../OL.jav new file: ../../../OLMain.jav --- src/test/java/packages/OLTest.java | 102 ++++++++++++++++++ .../javFiles/packageTest/de/test/OL.jav | 12 +++ .../javFiles/packageTest/de/test/OLMain.jav | 10 ++ 3 files changed, 124 insertions(+) create mode 100644 src/test/java/packages/OLTest.java create mode 100644 src/test/resources/javFiles/packageTest/de/test/OL.jav create mode 100644 src/test/resources/javFiles/packageTest/de/test/OLMain.jav diff --git a/src/test/java/packages/OLTest.java b/src/test/java/packages/OLTest.java new file mode 100644 index 000000000..dc1646b7f --- /dev/null +++ b/src/test/java/packages/OLTest.java @@ -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); + } +} diff --git a/src/test/resources/javFiles/packageTest/de/test/OL.jav b/src/test/resources/javFiles/packageTest/de/test/OL.jav new file mode 100644 index 000000000..91d0f4ab8 --- /dev/null +++ b/src/test/resources/javFiles/packageTest/de/test/OL.jav @@ -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; } + +} diff --git a/src/test/resources/javFiles/packageTest/de/test/OLMain.jav b/src/test/resources/javFiles/packageTest/de/test/OLMain.jav new file mode 100644 index 000000000..4f08635b0 --- /dev/null +++ b/src/test/resources/javFiles/packageTest/de/test/OLMain.jav @@ -0,0 +1,10 @@ +import OL; + +public class OLMain { + + main(x) { + var ol; + ol = new OL(); + return ol.m(x); + } +}