From bc378f2fe956fda4a3970fafff0812c0667ffd1b Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Thu, 25 Mar 2021 00:41:03 +0100 Subject: [PATCH] modified: src/test/java/insertGenerics/AllTests.java modified: src/test/java/insertGenerics/TestTwoCalls.java modified: src/test/java/insertGenerics/TestVector.java --- src/test/java/insertGenerics/AllTests.java | 44 ++++++++++++++++++- .../java/insertGenerics/TestTwoCalls.java | 29 ++++++++++++ src/test/java/insertGenerics/TestVector.java | 27 ++++++++++++ 3 files changed, 99 insertions(+), 1 deletion(-) diff --git a/src/test/java/insertGenerics/AllTests.java b/src/test/java/insertGenerics/AllTests.java index 42fa736f..f4f09992 100644 --- a/src/test/java/insertGenerics/AllTests.java +++ b/src/test/java/insertGenerics/AllTests.java @@ -1,6 +1,10 @@ package insertGenerics; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; @@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; import org.junit.Test; +import static org.junit.Assert.assertEquals; + import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -19,6 +25,8 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -35,7 +43,41 @@ public class AllTests { @Test public void TestMutualRecursion() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException { className = "TestMutualRecursion"; - execute(new File(rootDirectory+className+".jav")); + JavaTXCompiler compiler = new JavaTXCompiler(new File(rootDirectory+className+".jav")); + List results = compiler.typeInference(); + List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + + List classConstraintsTest = new ArrayList<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + List lmc; + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("P", "Q", Relation.EXTENDS)); + lmc.add(new MethodConstraint("Q", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH ALid(TPH P)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("Z", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH ALm(TPH ALTPH Z)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AG", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AH", "java/lang/Object", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AL", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH ALmain(TPH AGTPH AH)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + assertEquals(expectedClassCons, computedClassCons); + + assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); + + compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); + loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); + classToTest = loader.loadClass(className); + instanceOfClass = classToTest.getDeclaredConstructor().newInstance(); } @Test diff --git a/src/test/java/insertGenerics/TestTwoCalls.java b/src/test/java/insertGenerics/TestTwoCalls.java index 6d107b16..a6157ecc 100644 --- a/src/test/java/insertGenerics/TestTwoCalls.java +++ b/src/test/java/insertGenerics/TestTwoCalls.java @@ -1,6 +1,10 @@ package insertGenerics; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; @@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; import org.junit.Test; +import static org.junit.Assert.assertEquals; + import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -19,6 +25,8 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -45,6 +53,27 @@ public class TestTwoCalls { JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + List lmc; + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("O", "R", Relation.EXTENDS)); + lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH Rid(TPH O)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("T", "O", Relation.EXTENDS)); + lmc.add(new MethodConstraint("O", "R", Relation.EXTENDS)); + lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH Rmain(TPH STPH T)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + assertEquals(expectedClassCons, computedClassCons); + + assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass(className); diff --git a/src/test/java/insertGenerics/TestVector.java b/src/test/java/insertGenerics/TestVector.java index a585abe5..a020b279 100644 --- a/src/test/java/insertGenerics/TestVector.java +++ b/src/test/java/insertGenerics/TestVector.java @@ -1,6 +1,10 @@ package insertGenerics; +import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation; import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; +import de.dhbwstuttgart.bytecode.insertGenerics.ClassConstraint; +import de.dhbwstuttgart.bytecode.insertGenerics.FamilyOfGeneratedGenerics; +import de.dhbwstuttgart.bytecode.insertGenerics.MethodConstraint; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.syntaxtree.SourceFile; import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter; @@ -10,6 +14,8 @@ import de.dhbwstuttgart.typedeployment.TypeInsertFactory; import de.dhbwstuttgart.typeinference.result.ResultSet; import org.junit.Test; +import static org.junit.Assert.assertEquals; + import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -19,6 +25,8 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -45,6 +53,25 @@ public class TestVector { JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + List lmc; + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("T", "W", Relation.EXTENDS)); + lmc.add(new MethodConstraint("W", "ZU", Relation.EXTENDS)); + lmc.add(new MethodConstraint("ZU", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("voidm(java/util/Vectorjava/util/Vector)", lmc); + lmc = new ArrayList<>(); + methodConstraintsWithPositionTest.put("TPH Wid(TPH W)", lmc); + + FamilyOfGeneratedGenerics fogg = compiler.fogg; + Set computedClassCons = new HashSet<>(fogg.classConstraints); + Set expectedClassCons = new HashSet<>(classConstraintsTest); + + assertEquals(expectedClassCons, computedClassCons); + + assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass(className);