From bf80361c1f1fe37ecbb284341e19ac3bfff1f00e Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Tue, 21 Jan 2020 14:12:48 +0100 Subject: [PATCH] new file: ../../../java/packages/OLOneFileTest.java new file: OLOneFile.jav --- src/test/java/packages/OLOneFileTest.java | 133 ++++++++++++++++++ .../javFiles/packageTest/OLOneFile.jav | 22 +++ 2 files changed, 155 insertions(+) create mode 100644 src/test/java/packages/OLOneFileTest.java create mode 100644 src/test/resources/javFiles/packageTest/OLOneFile.jav diff --git a/src/test/java/packages/OLOneFileTest.java b/src/test/java/packages/OLOneFileTest.java new file mode 100644 index 00000000..05ebbc5a --- /dev/null +++ b/src/test/java/packages/OLOneFileTest.java @@ -0,0 +1,133 @@ +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 com.google.common.collect.Lists; + +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.core.JavaTXCompiler; +import de.dhbwstuttgart.typeinference.result.ResultSet; + +public class OLOneFileTest { + 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 Class classToTest2; + private static String pathToClassFile; + private static Object instanceOfClass; + private static Object instanceOfClass1; + private static Object instanceOfClass2; + + public static final String rootDirectory = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest"; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + path = rootDirectory +"/OLOneFile.jav"; + fileToTest = new File(path); + compiler = new JavaTXCompiler( + Lists.newArrayList(fileToTest), + Lists.newArrayList(new File(rootDirectory+"/de/test/output/"))); + pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/javFiles/packageTest/"; + List typeinferenceResult = compiler.typeInference(); + List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult); + compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles); + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest = loader.loadClass("OLOneFile"); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); + classToTest1 = loader.loadClass("OLextendsOneFile"); + instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance(); + classToTest2 = loader.loadClass("OLMainOneFile"); + instanceOfClass2 = classToTest2.getDeclaredConstructor().newInstance(); + } + + @Test + public void testOLClassName() { + assertEquals("OLOneFile", classToTest.getName()); + } + + @Test + public void testmInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + Method m = classToTest.getDeclaredMethod("m2", 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("m2", 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("m2", String.class); + String result = (String) m.invoke(instanceOfClass, "xxx"); + assertEquals("xxxxxx", result); + } + + @Test + public void testOLextendsClassName() { + assertEquals("OLextendsOneFile", classToTest1.getName()); + } + + @Test + public void testextendsInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + Method main = classToTest1.getMethod("m2", Integer.class); + Integer result = (Integer) main.invoke(instanceOfClass1, 5); + assertEquals(new Integer(10), result); + } + + @Test + public void testextendsDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + Method main = classToTest1.getMethod("m2", Double.class); + Double result = (Double) main.invoke(instanceOfClass1, 5.0); + assertEquals(new Double(10.0), result); + } + + @Test + public void testextendsString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + Method main = classToTest1.getMethod("m2", String.class); + String result = (String) main.invoke(instanceOfClass1, "xxx"); + assertEquals("xxxxxx", result); + } + + @Test + public void testOLMainClassName() { + assertEquals("OLMainOneFile", classToTest2.getName()); + } + + @Test + public void testmainInt() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + Method main = classToTest2.getDeclaredMethod("main", Integer.class); + Integer result = (Integer) main.invoke(instanceOfClass2, 5); + assertEquals(new Integer(10), result); + } + + @Test + public void testmainDouble() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + Method main = classToTest2.getDeclaredMethod("main", Double.class); + Double result = (Double) main.invoke(instanceOfClass2, 5.0); + assertEquals(new Double(10.0), result); + } + + @Test + public void testmainString() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { + Method main = classToTest2.getDeclaredMethod("main", String.class); + String result = (String) main.invoke(instanceOfClass2, "xxx"); + assertEquals("xxxxxx", result); + } +} diff --git a/src/test/resources/javFiles/packageTest/OLOneFile.jav b/src/test/resources/javFiles/packageTest/OLOneFile.jav new file mode 100644 index 00000000..eb865d61 --- /dev/null +++ b/src/test/resources/javFiles/packageTest/OLOneFile.jav @@ -0,0 +1,22 @@ +import java.lang.String; +import java.lang.Integer; +import java.lang.Double; +import java.lang.Boolean; + + +public class OLOneFile { + + m2(x) { return x + x; } + +} + +public class OLextendsOneFile extends OLOneFile { } + +public class OLMainOneFile { + + main(x) { + var ol; + ol = new OLextendsOneFile(); + return ol.m2(x); + } +}