diff --git a/src/test/java/insertGenerics/TestAny.java b/src/test/java/insertGenerics/TestAny.java index 6c6d2a95..e40c205e 100644 --- a/src/test/java/insertGenerics/TestAny.java +++ b/src/test/java/insertGenerics/TestAny.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,12 +14,16 @@ 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.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; @@ -40,6 +48,28 @@ public class TestAny { } List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + classConstraintsTest.add(new ClassConstraint("N", "O", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("N", "U", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("U", "O", Relation.EXTENDS)); + classConstraintsTest.add(new ClassConstraint("O", "java/lang/Object", Relation.EXTENDS)); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + List lmc; + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("R", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH RanyMethod()", lmc); + lmc = new ArrayList<>(); + methodConstraintsWithPositionTest.put("TPH UotherMethod(TPH U)", 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(rootDirectory+"xxx.class", results, simplifyResultsForAllSourceFiles); for(File f : compiler.sourceFiles.keySet()){ SourceFile sf = compiler.sourceFiles.get(f); diff --git a/src/test/java/insertGenerics/TestGGFinder.java b/src/test/java/insertGenerics/TestGGFinder.java index 3b9e378e..55e9a09a 100644 --- a/src/test/java/insertGenerics/TestGGFinder.java +++ b/src/test/java/insertGenerics/TestGGFinder.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,33 @@ public class TestGGFinder { JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + classConstraintsTest.add(new ClassConstraint("S", "java/lang/Object", Relation.EXTENDS)); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + List lmc; + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("P", "AC", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AC", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH ACid(TPH P)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("T", "S", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH SsetA(TPH T)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AC", "Y", Relation.EXTENDS)); + lmc.add(new MethodConstraint("Z", "P", Relation.EXTENDS)); + lmc.add(new MethodConstraint("P", "AC", Relation.EXTENDS)); + lmc.add(new MethodConstraint("Y", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("voidm(TPH YTPH Z)", 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/TestLocalVarLambda.java b/src/test/java/insertGenerics/TestLocalVarLambda.java index d83e6d21..ea8071d7 100644 --- a/src/test/java/insertGenerics/TestLocalVarLambda.java +++ b/src/test/java/insertGenerics/TestLocalVarLambda.java @@ -77,9 +77,9 @@ public class TestLocalVarLambda { Set computedClassCons = new HashSet<>(fogg.classConstraints); Set expectedClassCons = new HashSet<>(classConstraintsTest); - assertEquals(computedClassCons, expectedClassCons); + assertEquals(expectedClassCons, computedClassCons); - assertEquals(fogg.methodConstraintsWithPosition, methodConstraintsWithPositionTest); + assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); diff --git a/src/test/java/insertGenerics/TestTPHsAndGenerics.java b/src/test/java/insertGenerics/TestTPHsAndGenerics.java index 6aebd04f..3c243171 100644 --- a/src/test/java/insertGenerics/TestTPHsAndGenerics.java +++ b/src/test/java/insertGenerics/TestTPHsAndGenerics.java @@ -79,9 +79,9 @@ public class TestTPHsAndGenerics { Set computedClassCons = new HashSet<>(fogg.classConstraints); Set expectedClassCons = new HashSet<>(classConstraintsTest); - assertEquals(computedClassCons, expectedClassCons); + assertEquals(expectedClassCons, computedClassCons); - assertEquals(fogg.methodConstraintsWithPosition, methodConstraintsWithPositionTest); + assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); /* compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); diff --git a/src/test/java/insertGenerics/TestTwoArgs.java b/src/test/java/insertGenerics/TestTwoArgs.java index d106e5c7..e492c49f 100644 --- a/src/test/java/insertGenerics/TestTwoArgs.java +++ b/src/test/java/insertGenerics/TestTwoArgs.java @@ -84,9 +84,9 @@ public class TestTwoArgs { Set computedClassCons = new HashSet<>(fogg.classConstraints); Set expectedClassCons = new HashSet<>(classConstraintsTest); - assertEquals(computedClassCons, expectedClassCons); + assertEquals(expectedClassCons, computedClassCons); - assertEquals(fogg.methodConstraintsWithPosition, methodConstraintsWithPositionTest); + assertEquals(methodConstraintsWithPositionTest, fogg.methodConstraintsWithPosition); compiler.generateBytecode(new File(pathToClassFile), results, simplifyResultsForAllSourceFiles); loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); diff --git a/src/test/java/insertGenerics/TestTwoArgs2.java b/src/test/java/insertGenerics/TestTwoArgs2.java index 6522187a..42a5a833 100644 --- a/src/test/java/insertGenerics/TestTwoArgs2.java +++ b/src/test/java/insertGenerics/TestTwoArgs2.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,39 @@ public class TestTwoArgs2 { JavaTXCompiler compiler = new JavaTXCompiler(fileToTest); List results = compiler.typeInference(); List simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(results); + + List classConstraintsTest = new ArrayList<>(); + classConstraintsTest.add(new ClassConstraint("N", "java/lang/Object", Relation.EXTENDS)); + HashMap> methodConstraintsWithPositionTest = new HashMap<>(); + List lmc; + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AG", "AA", Relation.EXTENDS)); + lmc.add(new MethodConstraint("U", "P", Relation.EXTENDS)); + lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AA", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH AAm(TPH AATPH U)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("AB", "P", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AC", "U", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AB", "AA", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AA", "U", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AG", "AA", Relation.EXTENDS)); + lmc.add(new MethodConstraint("U", "AA", Relation.EXTENDS)); + lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH AAmain(TPH ABTPH AC)", lmc); + lmc = new ArrayList<>(); + lmc.add(new MethodConstraint("P", "AG", Relation.EXTENDS)); + lmc.add(new MethodConstraint("AG", "java/lang/Object", Relation.EXTENDS)); + methodConstraintsWithPositionTest.put("TPH AGid(TPH P)", 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);