From ecad9e138ca8bcda6f3ccce3bcf560b6bf99bb11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Schr=C3=B6dter?= Date: Tue, 10 Nov 2015 18:26:29 +0100 Subject: [PATCH] =?UTF-8?q?BytecodeTest=20in=20SourceFileBytecodeTest=20?= =?UTF-8?q?=20umbenannt=20ExtendsObjectTest=20von=20SourceFileBytecodeTest?= =?UTF-8?q?=20zu=20ASTBytecodeTest=20=C3=BCberf=C3=BChrt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/bytecode/ASTBytecodeTest.java | 13 +- test/bytecode/NewClassTest.java | 2 +- ...eTest.java => SourceFileBytecodeTest.java} | 4 +- test/bytecode/types/AutoOverloadingTest.java | 4 +- test/bytecode/types/ExtendsObjectTest.java | 10 +- ...{ExtendsType.java => ExtendsTypeTest.java} | 4 +- test/bytecode/types/ExtendsVector.jav | 5 - .../types/ExtendsVectorStringTest.java | 4 +- test/bytecode/types/ExtendsVectorTest.java | 51 ++++---- .../types/LocalVariableStringVectorTest.java | 4 +- .../types/LocalVariableVectorTest.java | 4 +- .../types/MethodWithTypedVectorTest.java | 4 +- .../types/MethodWithUntypedVectorTest.java | 4 +- .../types/OverloadingAdditionTest.java | 4 +- test/bytecode/types/OverloadingTest.java | 4 +- test/bytecode/types/ReflectionTest.java | 120 ------------------ test/bytecode/types/SuperType.java | 4 +- 17 files changed, 57 insertions(+), 188 deletions(-) rename test/bytecode/{BytecodeTest.java => SourceFileBytecodeTest.java} (92%) rename test/bytecode/types/{ExtendsType.java => ExtendsTypeTest.java} (85%) delete mode 100644 test/bytecode/types/ExtendsVector.jav delete mode 100644 test/bytecode/types/ReflectionTest.java diff --git a/test/bytecode/ASTBytecodeTest.java b/test/bytecode/ASTBytecodeTest.java index 382459c7..1558fa77 100644 --- a/test/bytecode/ASTBytecodeTest.java +++ b/test/bytecode/ASTBytecodeTest.java @@ -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 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(); } diff --git a/test/bytecode/NewClassTest.java b/test/bytecode/NewClassTest.java index 7cb425ea..5757d32d 100644 --- a/test/bytecode/NewClassTest.java +++ b/test/bytecode/NewClassTest.java @@ -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"; diff --git a/test/bytecode/BytecodeTest.java b/test/bytecode/SourceFileBytecodeTest.java similarity index 92% rename from test/bytecode/BytecodeTest.java rename to test/bytecode/SourceFileBytecodeTest.java index 0c86ae55..8e1245ba 100644 --- a/test/bytecode/BytecodeTest.java +++ b/test/bytecode/SourceFileBytecodeTest.java @@ -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){ diff --git a/test/bytecode/types/AutoOverloadingTest.java b/test/bytecode/types/AutoOverloadingTest.java index a25df619..41c0bfc7 100644 --- a/test/bytecode/types/AutoOverloadingTest.java +++ b/test/bytecode/types/AutoOverloadingTest.java @@ -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"; diff --git a/test/bytecode/types/ExtendsObjectTest.java b/test/bytecode/types/ExtendsObjectTest.java index 5c8ed76a..c5614bff 100644 --- a/test/bytecode/types/ExtendsObjectTest.java +++ b/test/bytecode/types/ExtendsObjectTest.java @@ -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); } diff --git a/test/bytecode/types/ExtendsType.java b/test/bytecode/types/ExtendsTypeTest.java similarity index 85% rename from test/bytecode/types/ExtendsType.java rename to test/bytecode/types/ExtendsTypeTest.java index 8821bdf1..32f24c9c 100644 --- a/test/bytecode/types/ExtendsType.java +++ b/test/bytecode/types/ExtendsTypeTest.java @@ -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"; diff --git a/test/bytecode/types/ExtendsVector.jav b/test/bytecode/types/ExtendsVector.jav deleted file mode 100644 index f029967d..00000000 --- a/test/bytecode/types/ExtendsVector.jav +++ /dev/null @@ -1,5 +0,0 @@ -import java.util.Vector; - -class ExtendsVector extends Vector{ - -} \ No newline at end of file diff --git a/test/bytecode/types/ExtendsVectorStringTest.java b/test/bytecode/types/ExtendsVectorStringTest.java index efcbc095..5e4e35aa 100644 --- a/test/bytecode/types/ExtendsVectorStringTest.java +++ b/test/bytecode/types/ExtendsVectorStringTest.java @@ -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"; diff --git a/test/bytecode/types/ExtendsVectorTest.java b/test/bytecode/types/ExtendsVectorTest.java index 5253507e..0a0725de 100644 --- a/test/bytecode/types/ExtendsVectorTest.java +++ b/test/bytecode/types/ExtendsVectorTest.java @@ -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{ + + } + */ + 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(); diff --git a/test/bytecode/types/LocalVariableStringVectorTest.java b/test/bytecode/types/LocalVariableStringVectorTest.java index a3761210..9c16a4b4 100644 --- a/test/bytecode/types/LocalVariableStringVectorTest.java +++ b/test/bytecode/types/LocalVariableStringVectorTest.java @@ -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"; diff --git a/test/bytecode/types/LocalVariableVectorTest.java b/test/bytecode/types/LocalVariableVectorTest.java index 52869f43..b6278a65 100644 --- a/test/bytecode/types/LocalVariableVectorTest.java +++ b/test/bytecode/types/LocalVariableVectorTest.java @@ -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"; diff --git a/test/bytecode/types/MethodWithTypedVectorTest.java b/test/bytecode/types/MethodWithTypedVectorTest.java index 6933c248..f8ae8fe3 100644 --- a/test/bytecode/types/MethodWithTypedVectorTest.java +++ b/test/bytecode/types/MethodWithTypedVectorTest.java @@ -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"; diff --git a/test/bytecode/types/MethodWithUntypedVectorTest.java b/test/bytecode/types/MethodWithUntypedVectorTest.java index 1be45ff0..bb0a7577 100644 --- a/test/bytecode/types/MethodWithUntypedVectorTest.java +++ b/test/bytecode/types/MethodWithUntypedVectorTest.java @@ -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"; diff --git a/test/bytecode/types/OverloadingAdditionTest.java b/test/bytecode/types/OverloadingAdditionTest.java index 0830a656..bb5211f5 100644 --- a/test/bytecode/types/OverloadingAdditionTest.java +++ b/test/bytecode/types/OverloadingAdditionTest.java @@ -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"; diff --git a/test/bytecode/types/OverloadingTest.java b/test/bytecode/types/OverloadingTest.java index 15469089..bdbc1092 100644 --- a/test/bytecode/types/OverloadingTest.java +++ b/test/bytecode/types/OverloadingTest.java @@ -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"; diff --git a/test/bytecode/types/ReflectionTest.java b/test/bytecode/types/ReflectionTest.java deleted file mode 100644 index db5a25e2..00000000 --- a/test/bytecode/types/ReflectionTest.java +++ /dev/null @@ -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 vector = new Vector(); - - 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 vector = new Vector(); - - 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); - } - } -} diff --git a/test/bytecode/types/SuperType.java b/test/bytecode/types/SuperType.java index 425ba200..26b5b790 100644 --- a/test/bytecode/types/SuperType.java +++ b/test/bytecode/types/SuperType.java @@ -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";