modified: ../../../java/bytecode/InheritTest.java
modified: ../../bytecode/javFiles/Inherit.jav
This commit is contained in:
parent
eb27003515
commit
907ab2fcec
@ -5,6 +5,7 @@ import static org.junit.Assert.*;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
@ -30,14 +31,16 @@ public class InheritTest {
|
||||
private static JavaTXCompiler compiler;
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static Class<?> classToTest1, classToTest2, classToTest3, classToTest4;
|
||||
private static Class<?> classToTestAA, classToTestBB, classToTestCC, classToTestDD;
|
||||
private static String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/";;
|
||||
//private static String pathToClassFile1 = System.getProperty("user.dir") + "/src/test/resources/testBytecode/generatedBC/";
|
||||
private static Object instanceOfClass;
|
||||
private static Object instanceOfClass1, instanceOfClass2, instanceOfClass3, instanceOfClass4;
|
||||
private static Object instanceOfClassAA, instanceOfClassBB, instanceOfClassCC, instanceOfClassDD;
|
||||
private static HashMap<ArrayList<String>, Method> hm = new HashMap<>();
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/AA.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
@ -45,9 +48,10 @@ public class InheritTest {
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest1 = loader.loadClass("AA");
|
||||
instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance();
|
||||
classToTestAA = loader.loadClass("AA");
|
||||
instanceOfClassAA = classToTestAA.getDeclaredConstructor().newInstance();
|
||||
|
||||
/*
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/BB.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
@ -55,8 +59,8 @@ public class InheritTest {
|
||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest2 = loader.loadClass("BB");
|
||||
instanceOfClass2 = classToTest1.getDeclaredConstructor().newInstance();
|
||||
classToTestBB = loader.loadClass("BB");
|
||||
instanceOfClassBB = classToTestBB.getDeclaredConstructor().newInstance();
|
||||
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/CC.jav";
|
||||
fileToTest = new File(path);
|
||||
@ -65,8 +69,8 @@ public class InheritTest {
|
||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest3 = loader.loadClass("CC");
|
||||
instanceOfClass3 = classToTest1.getDeclaredConstructor().newInstance();
|
||||
classToTestCC = loader.loadClass("CC");
|
||||
instanceOfClassCC = classToTestCC.getDeclaredConstructor().newInstance();
|
||||
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/DD.jav";
|
||||
fileToTest = new File(path);
|
||||
@ -75,15 +79,18 @@ public class InheritTest {
|
||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest4 = loader.loadClass("DD");
|
||||
instanceOfClass4 = classToTest1.getDeclaredConstructor().newInstance();
|
||||
classToTestDD = loader.loadClass("DD");
|
||||
instanceOfClassDD = classToTestDD.getDeclaredConstructor().newInstance();
|
||||
*/
|
||||
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Inherit.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
/*
|
||||
compiler = new JavaTXCompiler(
|
||||
Lists.newArrayList(fileToTest),
|
||||
Lists.newArrayList(new File(pathToClassFile)));
|
||||
//compiler = new JavaTXCompiler(fileToTest);
|
||||
Lists.newArrayList(new File(pathToClassFile1)));
|
||||
*/
|
||||
typeinferenceResult = compiler.typeInference();
|
||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||
@ -91,6 +98,7 @@ public class InheritTest {
|
||||
classToTest = loader.loadClass("Inherit");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
||||
/*
|
||||
for (Method m: classToTest.getMethods()) {
|
||||
ArrayList<String> param = Arrays.stream(m.getParameterTypes()).map(x -> x.getName()).collect(Collectors.toCollection(ArrayList::new));
|
||||
ArrayList<String> nameParam = new ArrayList<>();
|
||||
@ -98,6 +106,7 @@ public class InheritTest {
|
||||
nameParam.addAll(param);
|
||||
hm.put(nameParam, m);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -105,33 +114,37 @@ public class InheritTest {
|
||||
assertEquals("Inherit", classToTest.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAAName() {
|
||||
assertEquals("AA", classToTest1.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAAName() {
|
||||
assertEquals("AA", classToTestAA.getName());
|
||||
}
|
||||
|
||||
/*
|
||||
@Test
|
||||
public void testBBName() {
|
||||
assertEquals("BB", classToTest2.getName());
|
||||
assertEquals("BB", classToTestBB.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCCName() {
|
||||
assertEquals("CC", classToTest3.getName());
|
||||
assertEquals("CC", classToTestCC.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDDName() {
|
||||
assertEquals("DD", classToTest4.getName());
|
||||
assertEquals("DD", classToTestDD.getName());
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testmainAA() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
|
||||
String[] x = {"main", "AA", "java.lang.Integer"};
|
||||
ArrayList<String> nameParam = new ArrayList<>(Arrays.asList(x));
|
||||
Method m = hm.get(nameParam);
|
||||
assertEquals(m.invoke(classToTest1.getConstructor().newInstance(), 5), "AA");
|
||||
public void testmainAA() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, MalformedURLException, ClassNotFoundException {
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("Inherit");
|
||||
Method m = classToTestAA.getDeclaredMethod("m", Integer.class);
|
||||
assertEquals(m.invoke(instanceOfClassAA, 5), "AA");
|
||||
Method main = classToTest.getDeclaredMethod("main", classToTestAA, Integer.class);
|
||||
assertEquals(main.invoke(instanceOfClass, instanceOfClassAA, 5), "AA");
|
||||
}
|
||||
/*
|
||||
Vector<Integer> v_invoke = new Vector<>();
|
||||
|
@ -6,6 +6,8 @@ import java.lang.String;
|
||||
|
||||
public class Inherit {
|
||||
|
||||
//m(Integer i) { return "AA"; }
|
||||
|
||||
main(d, i) {
|
||||
return d.m(i);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user