forked from JavaTX/JavaCompilerCore
BytecodeTest in SourceFileBytecodeTest umbenannt
ExtendsObjectTest von SourceFileBytecodeTest zu ASTBytecodeTest überführt
This commit is contained in:
parent
0c63695f7b
commit
ecad9e138c
@ -19,10 +19,10 @@ import de.dhbwstuttgart.typeinference.TypeinferenceResults;
|
||||
public abstract class ASTBytecodeTest {
|
||||
public static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
|
||||
|
||||
protected String testName = "";
|
||||
protected static String testName = "No Testname defined!";
|
||||
|
||||
protected SourceFile sourceFile = new SourceFile();
|
||||
protected TypeinferenceResults results = new TypeinferenceResults();
|
||||
protected static SourceFile sourceFile = new SourceFile();
|
||||
protected static TypeinferenceResults results = new TypeinferenceResults();
|
||||
|
||||
protected Class getClassToTest(){
|
||||
Class classToTest = null;
|
||||
@ -48,12 +48,10 @@ public abstract class ASTBytecodeTest {
|
||||
}
|
||||
|
||||
public ASTBytecodeTest(){
|
||||
init();
|
||||
|
||||
System.out.println("ASTBytecodeTest");
|
||||
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
|
||||
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
|
||||
try {
|
||||
|
||||
Menge<SourceFile> sourceFiles = new Menge<>();
|
||||
sourceFiles.add(sourceFile);
|
||||
|
||||
@ -64,6 +62,7 @@ public abstract class ASTBytecodeTest {
|
||||
JavaClass javaClass = result.getByteCode().getJavaClass();
|
||||
javaClass.dump(new File(rootDirectory+javaClass.getClassName()+".class"));
|
||||
|
||||
|
||||
System.out.println(new File(rootDirectory+javaClass.getClassName()+".class").getAbsolutePath());
|
||||
|
||||
for(ClassGenerator cg: result.getByteCode().getExtraClasses().values()){
|
||||
@ -74,6 +73,4 @@ public abstract class ASTBytecodeTest {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void init();
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
|
||||
|
||||
public class NewClassTest extends BytecodeTest{
|
||||
public class NewClassTest extends SourceFileBytecodeTest{
|
||||
@Override
|
||||
protected void init() {
|
||||
testName = "NewClass";
|
||||
|
@ -13,14 +13,14 @@ import junit.framework.TestCase;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public abstract class BytecodeTest extends TestCase{
|
||||
public abstract class SourceFileBytecodeTest extends TestCase{
|
||||
public String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
|
||||
public String testFile;
|
||||
public String outputDirectory;
|
||||
|
||||
protected String testName;
|
||||
|
||||
public BytecodeTest(){
|
||||
public SourceFileBytecodeTest(){
|
||||
init();
|
||||
|
||||
if(testName != null){
|
@ -11,9 +11,9 @@ import java.util.Vector;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import bytecode.BytecodeTest;
|
||||
import bytecode.SourceFileBytecodeTest;
|
||||
|
||||
public class AutoOverloadingTest extends BytecodeTest{
|
||||
public class AutoOverloadingTest extends SourceFileBytecodeTest{
|
||||
@Override
|
||||
protected void init() {
|
||||
testName = "AutoOverloading";
|
||||
|
@ -3,6 +3,8 @@ package bytecode.types;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import bytecode.ASTBytecodeTest;
|
||||
@ -12,16 +14,16 @@ import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
public class ExtendsObjectTest extends ASTBytecodeTest{
|
||||
public static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/";
|
||||
|
||||
protected String testName = "ExtendsObjectTest2";
|
||||
protected static String testName = "ExtendsObjectTest";
|
||||
|
||||
protected void init(){
|
||||
@BeforeClass
|
||||
public static void init(){
|
||||
/*
|
||||
class ExtendsObject extends Object{
|
||||
|
||||
}
|
||||
*/
|
||||
de.dhbwstuttgart.syntaxtree.Class classToTest = ASTFactory.createClass("ExtendsObjectTest2", null, null, null, sourceFile);
|
||||
|
||||
de.dhbwstuttgart.syntaxtree.Class classToTest = ASTFactory.createClass(testName, null, null, null, sourceFile);
|
||||
sourceFile.addElement(classToTest);
|
||||
}
|
||||
|
||||
|
@ -10,9 +10,9 @@ import java.util.Vector;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import bytecode.BytecodeTest;
|
||||
import bytecode.SourceFileBytecodeTest;
|
||||
|
||||
public class ExtendsType extends BytecodeTest{
|
||||
public class ExtendsTypeTest extends SourceFileBytecodeTest{
|
||||
@Override
|
||||
protected void init() {
|
||||
testName = "SuperType";
|
@ -1,5 +0,0 @@
|
||||
import java.util.Vector;
|
||||
|
||||
class ExtendsVector extends Vector<Object>{
|
||||
|
||||
}
|
@ -12,7 +12,7 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import bytecode.BytecodeTest;
|
||||
import bytecode.SourceFileBytecodeTest;
|
||||
import plugindevelopment.TypeInsertTester;
|
||||
import de.dhbwstuttgart.core.MyCompiler;
|
||||
import de.dhbwstuttgart.core.MyCompilerAPI;
|
||||
@ -24,7 +24,7 @@ import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
|
||||
|
||||
public class ExtendsVectorStringTest extends BytecodeTest{
|
||||
public class ExtendsVectorStringTest extends SourceFileBytecodeTest{
|
||||
@Override
|
||||
protected void init() {
|
||||
testName = "ExtendsVectorString";
|
||||
|
@ -2,47 +2,42 @@ package bytecode.types;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Vector;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import bytecode.BytecodeTest;
|
||||
import plugindevelopment.TypeInsertTester;
|
||||
import de.dhbwstuttgart.core.MyCompiler;
|
||||
import de.dhbwstuttgart.core.MyCompilerAPI;
|
||||
import de.dhbwstuttgart.logger.LoggerConfiguration;
|
||||
import de.dhbwstuttgart.logger.Section;
|
||||
import de.dhbwstuttgart.parser.JavaParser.yyException;
|
||||
import de.dhbwstuttgart.typeinference.ByteCodeResult;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
|
||||
import bytecode.ASTBytecodeTest;
|
||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
|
||||
public class ExtendsVectorTest extends BytecodeTest{
|
||||
@Override
|
||||
protected void init() {
|
||||
testName = "ExtendsVector";
|
||||
rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/";
|
||||
|
||||
public class ExtendsVectorTest extends ASTBytecodeTest{
|
||||
public static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/";
|
||||
|
||||
protected static String testName = "ExtendsVectorTest2";
|
||||
|
||||
@BeforeClass
|
||||
public static void init(){
|
||||
/*
|
||||
import java.util.Vector;
|
||||
|
||||
class ExtendsVector extends Vector<Object>{
|
||||
|
||||
}
|
||||
*/
|
||||
de.dhbwstuttgart.syntaxtree.Class classToTest = ASTFactory.createClass(testName, new RefType("java.util.Vector", sourceFile, 0), null, null, sourceFile);
|
||||
sourceFile.addElement(classToTest);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstruct(){
|
||||
public void testSupertype(){
|
||||
try{
|
||||
ClassLoader classLoader = getClassLoader();
|
||||
|
||||
Class cls = classLoader.loadClass(testName);
|
||||
|
||||
Object obj = cls.newInstance();
|
||||
|
||||
Constructor method = cls.getConstructor(new Class[]{});
|
||||
method.newInstance();
|
||||
assertTrue(true);
|
||||
assertEquals("java.util.Vector", cls.getSuperclass().getName());
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
|
@ -10,9 +10,9 @@ import java.util.Vector;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import bytecode.BytecodeTest;
|
||||
import bytecode.SourceFileBytecodeTest;
|
||||
|
||||
public class LocalVariableStringVectorTest extends BytecodeTest{
|
||||
public class LocalVariableStringVectorTest extends SourceFileBytecodeTest{
|
||||
@Override
|
||||
protected void init() {
|
||||
testName = "LocalVariableStringVector";
|
||||
|
@ -10,9 +10,9 @@ import java.util.Vector;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import bytecode.BytecodeTest;
|
||||
import bytecode.SourceFileBytecodeTest;
|
||||
|
||||
public class LocalVariableVectorTest extends BytecodeTest{
|
||||
public class LocalVariableVectorTest extends SourceFileBytecodeTest{
|
||||
@Override
|
||||
protected void init() {
|
||||
testName = "LocalVariableVector";
|
||||
|
@ -11,11 +11,11 @@ import java.util.Vector;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import bytecode.BytecodeTest;
|
||||
import bytecode.SourceFileBytecodeTest;
|
||||
import de.dhbwstuttgart.logger.Logger;
|
||||
import de.dhbwstuttgart.logger.Section;
|
||||
|
||||
public class MethodWithTypedVectorTest extends BytecodeTest{
|
||||
public class MethodWithTypedVectorTest extends SourceFileBytecodeTest{
|
||||
@Override
|
||||
protected void init() {
|
||||
testName = "MethodWithTypedVector";
|
||||
|
@ -11,11 +11,11 @@ import java.util.Vector;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import bytecode.BytecodeTest;
|
||||
import bytecode.SourceFileBytecodeTest;
|
||||
import de.dhbwstuttgart.logger.Logger;
|
||||
import de.dhbwstuttgart.logger.Section;
|
||||
|
||||
public class MethodWithUntypedVectorTest extends BytecodeTest{
|
||||
public class MethodWithUntypedVectorTest extends SourceFileBytecodeTest{
|
||||
@Override
|
||||
protected void init() {
|
||||
testName = "MethodWithUntypedVector";
|
||||
|
@ -11,9 +11,9 @@ import java.util.Vector;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import bytecode.BytecodeTest;
|
||||
import bytecode.SourceFileBytecodeTest;
|
||||
|
||||
public class OverloadingAdditionTest extends BytecodeTest{
|
||||
public class OverloadingAdditionTest extends SourceFileBytecodeTest{
|
||||
@Override
|
||||
protected void init() {
|
||||
testName = "OverloadingAddition";
|
||||
|
@ -10,9 +10,9 @@ import java.util.Vector;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import bytecode.BytecodeTest;
|
||||
import bytecode.SourceFileBytecodeTest;
|
||||
|
||||
public class OverloadingTest extends BytecodeTest{
|
||||
public class OverloadingTest extends SourceFileBytecodeTest{
|
||||
@Override
|
||||
protected void init() {
|
||||
testName = "Overloading";
|
||||
|
@ -1,120 +0,0 @@
|
||||
package bytecode.types;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Stack;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import bytecode.BytecodeTest;
|
||||
import de.dhbwstuttgart.logger.Logger;
|
||||
import de.dhbwstuttgart.logger.Section;
|
||||
|
||||
public class ReflectionTest{
|
||||
@Test
|
||||
public void testUntypedVectorDeclaredMethods() {
|
||||
try{
|
||||
File file = new File(System.getProperty("user.dir")+"/test/bytecode/types/");
|
||||
URL url = file.toURL();
|
||||
URL[] urls = new URL[]{url};
|
||||
|
||||
ClassLoader classLoader = new URLClassLoader(urls);
|
||||
|
||||
Class untypedVectorTest = classLoader.loadClass("UntypedVector");
|
||||
|
||||
for(Method method: untypedVectorTest.getDeclaredMethods()){
|
||||
System.out.println(method.toGenericString());
|
||||
}
|
||||
}catch(Exception e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUntypedVectorDeclaredMethodsCallMethod() {
|
||||
try{
|
||||
File file = new File(System.getProperty("user.dir")+"/test/bytecode/types/");
|
||||
URL url = file.toURL();
|
||||
URL[] urls = new URL[]{url};
|
||||
|
||||
ClassLoader classLoader = new URLClassLoader(urls);
|
||||
|
||||
Class untypedVectorTest = classLoader.loadClass("UntypedVector");
|
||||
|
||||
Class stringVector = classLoader.loadClass("java%util%Vector%%java%lang%Object%");
|
||||
Object stringVectorObj = stringVector.newInstance();
|
||||
|
||||
for(Method method: untypedVectorTest.getDeclaredMethods()){
|
||||
method.invoke(untypedVectorTest.newInstance(), stringVectorObj);
|
||||
}
|
||||
}catch(Exception e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUntypedVectorMethod() {
|
||||
try{
|
||||
File file = new File(System.getProperty("user.dir")+"/test/bytecode/types/");
|
||||
URL url = file.toURL();
|
||||
URL[] urls = new URL[]{url};
|
||||
|
||||
ClassLoader classLoader = new URLClassLoader(urls);
|
||||
|
||||
Class untypedVectorTest = classLoader.loadClass("UntypedVector");
|
||||
|
||||
Class stringVector = classLoader.loadClass("java%util%Vector%%java%lang%Object%");
|
||||
|
||||
Class[] params = new Class[1];
|
||||
params[0] = stringVector;
|
||||
|
||||
Method method = untypedVectorTest.getDeclaredMethod("method", params);
|
||||
method.invoke(untypedVectorTest.newInstance(), stringVector.newInstance());
|
||||
}catch(Exception e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStdVectorAdd() {
|
||||
try{
|
||||
Vector<String> vector = new Vector<String>();
|
||||
|
||||
Class vectorClass = vector.getClass();
|
||||
|
||||
String helloWorld = new String("Hello World!");
|
||||
|
||||
Class[] params = new Class[1];
|
||||
params[0] = new Object().getClass();
|
||||
|
||||
Method method = vectorClass.getDeclaredMethod("add", params);
|
||||
method.invoke(vector, helloWorld);
|
||||
}catch(Exception e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStdVectorEnsureCapacity() {
|
||||
try{
|
||||
Vector<String> vector = new Vector<String>();
|
||||
|
||||
Class vectorClass = vector.getClass();
|
||||
|
||||
Integer integer = new Integer(1);
|
||||
|
||||
Class[] params = new Class[1];
|
||||
params[0] = int.class;
|
||||
|
||||
Method method = vectorClass.getDeclaredMethod("ensureCapacity", params);
|
||||
method.invoke(vector, integer);
|
||||
}catch(Exception e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -11,9 +11,9 @@ import java.util.Vector;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import bytecode.BytecodeTest;
|
||||
import bytecode.SourceFileBytecodeTest;
|
||||
|
||||
public class SuperType extends BytecodeTest{
|
||||
public class SuperType extends SourceFileBytecodeTest{
|
||||
@Override
|
||||
protected void init() {
|
||||
testName = "ExtendsType";
|
||||
|
Loading…
Reference in New Issue
Block a user