diff --git a/src/test/java/inferWildcards/TestInferWildcardsFields.java b/src/test/java/inferWildcards/TestInferWildcardsFields.java index 8bdaf148..ae2bd63c 100644 --- a/src/test/java/inferWildcards/TestInferWildcardsFields.java +++ b/src/test/java/inferWildcards/TestInferWildcardsFields.java @@ -4,6 +4,8 @@ import static org.junit.Assert.assertThat; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -12,35 +14,41 @@ import org.hamcrest.CoreMatchers; import org.junit.Before; import org.junit.Test; +import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile; import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.inferWildcards.ConstraintsGenerationUtils; import de.dhbwstuttgart.inferWildcards.JavaTXCompilerWildcards; import de.dhbwstuttgart.inferWildcards.TypePlaceholderReplaceUtils; +import de.dhbwstuttgart.parser.NullToken; +import de.dhbwstuttgart.parser.scope.JavaClassName; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.constraints.Pair; +import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType; +import de.dhbwstuttgart.typeinference.result.ResultPair; import de.dhbwstuttgart.typeinference.result.ResultSet; public class TestInferWildcardsFields { - private String resourcePath; + private String resourceFilePath; + private String resourceDirPath; @Before public void setup () { - resourcePath = System.getProperty("user.dir") - + "/src/test/resources/inferWildcards/TestClassWildcardsFields.java"; + resourceDirPath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards"; + resourceFilePath = resourceDirPath + "/TestClassWildcardsFields.java"; } private JavaTXCompiler getStandardCompiler () throws ClassNotFoundException, IOException { - File[] files1 = { new File(resourcePath) }; + File[] files1 = { new File(resourceFilePath) }; return new JavaTXCompiler(files1); } private JavaTXCompilerWildcards getWildcardsCompiler () throws ClassNotFoundException, IOException { - File[] files1 = { new File(resourcePath) }; + File[] files1 = { new File(resourceFilePath) }; return new JavaTXCompilerWildcards(files1); } @@ -50,6 +58,22 @@ public class TestInferWildcardsFields return TypePlaceholderReplaceUtils.generateTypePlaceholder(javaTXCompiler); } + private static List generateExpectedTypeInferResult (JavaTXCompilerWildcards compiler) { + Map tphMap = compiler.getTphMap(); + + ArrayList list = new ArrayList<>(); + + tphMap.forEach( (tph, t) -> { + ResultPair r = new PairTPHequalRefTypeOrWildcardType(tph, + new RefType(new JavaClassName("java.lan.String"), new NullToken())); + HashSet set = new HashSet<>(); + set.add(r); + list.add(new ResultSet(set)); + }); + + return list; + } + @Test public void testGenerateTph () throws ClassNotFoundException, IOException { System.out.println("\n--------- Test Generate TPH --------------\n"); @@ -96,5 +120,27 @@ public class TestInferWildcardsFields List typeInference = wildcardsCompiler.typeInference(); System.out.println(typeInference); + + List expectedTypeInferResult = generateExpectedTypeInferResult(wildcardsCompiler); + + assertThat("Type Inference Results containing the correct Wildcard results", typeInference, + CoreMatchers.hasItems(expectedTypeInferResult.toArray(new ResultSet[] {}))); + } + + @Test + public void testGenrationBytecode () throws ClassNotFoundException, IOException { + JavaTXCompilerWildcards wildcardsCompiler = getWildcardsCompiler(); + wildcardsCompiler.getTphMap(); + + List typeinferenceResult = generateExpectedTypeInferResult(wildcardsCompiler); + + List simplifyResultsForAllSourceFiles = wildcardsCompiler + .getGeneratedGenericResultsForAllSourceFiles( + typeinferenceResult); + + wildcardsCompiler.generateBytecode(new File(resourceDirPath + "/generatedBC"), typeinferenceResult, + simplifyResultsForAllSourceFiles); + + assertThat("Generation Succeeded", null, CoreMatchers.anything()); } }