JavaCompilerCore/test/plugindevelopment/TRMEqualTest.java
2014-09-08 15:12:47 +02:00

133 lines
3.5 KiB
Java

package plugindevelopment;
import static org.junit.Assert.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Vector;
import org.junit.Test;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.core.MyCompilerAPI;
import de.dhbwstuttgart.parser.JavaParser.yyException;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeInsertable;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.Pair.PairOperator;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
import junit.framework.TestCase;
import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent;
public class TRMEqualTest {
Vector<TypeInsertSet> replaceSet = new Vector<TypeInsertSet>();
TestNode node;
TypePlaceholder tph;
public void initTRMEqualTest(){
node = new TestNode();
tph = TypePlaceholder.fresh(node);
node.setType(tph);
}
@Test
public void test(){
initTRMEqualTest();
assertTrue("Zu Beginn ist das Set leer",replaceSet.size()==0);
addTestNode("Typ1");
assertTrue("Nach dem Anfügen eines Type muss das Set 1 Element enthalten",replaceSet.size()==1);
addTestNode("Typ2");
assertTrue("Nach dem Anfügen eines weiteren Typs muss das Set 2 Elemente enthalten und nicht "+replaceSet.size(),replaceSet.size()==2);
addTestNode("Typ1");
assertTrue("Nach dem Anfügen des selben Typs wie zuvor muss das Set immer noch 2 Element enthalten. Und nicht "+replaceSet.size(),replaceSet.size()==2);
}
private void addTestNode(String type){
Vector<Pair> resultContent = new Vector<Pair>();
Pair pair = new Pair(tph,new RefType(type,0));
pair.SetOperator(PairOperator.Equal);
resultContent.add(pair);
ResultSet resultSet = new ResultSet(resultContent);
Vector<TypeInsertPoint> tphs = tph.getTypeInsertPoints(resultSet);
TypeInsertSet toAdd = new TypeInsertSet(resultSet);
for(TypeInsertPoint tip : tphs){
toAdd.add(tip);
}
System.out.println("Füge hinzu: "+toAdd);
if(!replaceSet.contains(toAdd))replaceSet.add(toAdd);
}
}
class TestNode extends SyntaxTreeNode implements TypeInsertable{
@Override
public void replaceType(CReplaceTypeEvent e) {
// TODO Auto-generated method stub
}
@Override
public int getTypeLineNumber() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void setType(Type typ) {
// TODO Auto-generated method stub
}
@Override
public Type getType() {
// TODO Auto-generated method stub
return null;
}
@Override
public int getOffset() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void setOffset(int offset) {
// TODO Auto-generated method stub
}
@Override
public String getIdentifier() {
// TODO Auto-generated method stub
return null;
}
@Override
public TypeInsertPoint createTypeInsertPoint(TypePlaceholder tph,
ResultSet resultSet) {
return new TypeInsertPoint( this, this, resultSet.getTypeEqualTo(tph), resultSet);
}
@Override
public int getVariableLength() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Vector<SyntaxTreeNode> getChildren() {
// TODO Auto-generated method stub
return new Vector<>();
}
}