Tests zu Bytecodegenerierung anfügen

This commit is contained in:
JanUlrich 2015-10-29 15:16:19 +01:00
parent 040a1f4088
commit bdbe20552e
5 changed files with 98 additions and 2 deletions

10
test/bytecode/Binary.jav Normal file
View File

@ -0,0 +1,10 @@
class Binary{
void method() {
a;
a = 20;
b;
b=59 + a;
}
}

16
test/bytecode/Binary2.jav Normal file
View File

@ -0,0 +1,16 @@
class OL {
Integer m(Integer x) { return x + x; }
Boolean m(Boolean x) {return x || x; }
}
class Binary2 {
main(x) {
ol;
ol = new OL();
return ol.m(x);
}
}

View File

@ -0,0 +1,34 @@
package bytecode;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import org.junit.Test;
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;
public class BinaryTest {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "Binary.jav";
public final static String outputFile = "Binary.class";
@Test
public void test() {
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile);
}
}

View File

@ -0,0 +1,34 @@
package bytecode;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import org.junit.Test;
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;
public class BinaryTest2 {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "Binary2.jav";
public final static String outputFile = "Binary2.class";
@Test
public void test() {
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile);
}
}

View File

@ -14,6 +14,7 @@ import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.logger.SectionLogger; import de.dhbwstuttgart.logger.SectionLogger;
import de.dhbwstuttgart.logger.Timewatch; import de.dhbwstuttgart.logger.Timewatch;
import de.dhbwstuttgart.parser.JavaParser.yyException; import de.dhbwstuttgart.parser.JavaParser.yyException;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet; import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
@ -78,8 +79,9 @@ public class MultipleTypesInsertTester extends TypeInsertTester{
String inferedSource = ""; String inferedSource = "";
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig); MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
try { try {
compiler.parse(new File(rootDirectory + sourceFileToInfere)); Menge<SourceFile> parsedSource = new Menge<>();
Menge<TypeinferenceResultSet> results = compiler.typeReconstruction(); parsedSource.add(compiler.parse(new File(rootDirectory + sourceFileToInfere)));
Menge<TypeinferenceResultSet> results = compiler.typeReconstruction(parsedSource);
//TestCase.assertTrue("Es darf nicht mehr als eine Lösungsmöglichkeit geben und nicht "+results.size(), results.size()==1); //TestCase.assertTrue("Es darf nicht mehr als eine Lösungsmöglichkeit geben und nicht "+results.size(), results.size()==1);
for(TypeinferenceResultSet result : results){ for(TypeinferenceResultSet result : results){
TypeInsertSet point = result.getTypeInsertionPoints(); TypeInsertSet point = result.getTypeInsertionPoints();