2014-03-21 15:34:16 +00:00
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 ;
2014-09-02 08:33:54 +00:00
import de.dhbwstuttgart.core.MyCompiler ;
import de.dhbwstuttgart.core.MyCompilerAPI ;
2014-09-05 09:49:31 +00:00
import de.dhbwstuttgart.parser.JavaParser.yyException ;
2014-09-04 14:35:44 +00:00
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode ;
2014-09-02 08:33:54 +00:00
import de.dhbwstuttgart.syntaxtree.type.RefType ;
import de.dhbwstuttgart.syntaxtree.type.Type ;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder ;
2014-09-08 13:12:47 +00:00
import de.dhbwstuttgart.typeinference.Pair ;
2014-09-02 08:33:54 +00:00
import de.dhbwstuttgart.typeinference.ResultSet ;
import de.dhbwstuttgart.typeinference.TypeInsertable ;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet ;
2014-09-08 13:12:47 +00:00
import de.dhbwstuttgart.typeinference.Pair.PairOperator ;
2014-09-02 08:33:54 +00:00
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint ;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet ;
2014-03-21 15:34:16 +00:00
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<6E> gen eines Type muss das Set 1 Element enthalten " , replaceSet . size ( ) = = 1 ) ;
addTestNode ( " Typ2 " ) ;
2014-03-25 03:41:07 +00:00
assertTrue ( " Nach dem Anf<6E> gen eines weiteren Typs muss das Set 2 Elemente enthalten und nicht " + replaceSet . size ( ) , replaceSet . size ( ) = = 2 ) ;
2014-03-21 15:34:16 +00:00
addTestNode ( " Typ1 " ) ;
assertTrue ( " Nach dem Anf<6E> gen des selben Typs wie zuvor muss das Set immer noch 2 Element enthalten. Und nicht " + replaceSet . size ( ) , replaceSet . size ( ) = = 2 ) ;
}
2014-06-20 09:18:45 +00:00
2014-03-21 15:34:16 +00:00
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 ) ;
2014-04-23 10:05:57 +00:00
Vector < TypeInsertPoint > tphs = tph . getTypeInsertPoints ( resultSet ) ;
2014-06-19 17:40:13 +00:00
TypeInsertSet toAdd = new TypeInsertSet ( resultSet ) ;
2014-04-23 12:36:26 +00:00
for ( TypeInsertPoint tip : tphs ) {
toAdd . add ( tip ) ;
}
2014-03-21 15:34:16 +00:00
System . out . println ( " F<EFBFBD> ge hinzu: " + toAdd ) ;
if ( ! replaceSet . contains ( toAdd ) ) replaceSet . add ( toAdd ) ;
}
}
2014-08-05 10:34:09 +00:00
class TestNode extends SyntaxTreeNode implements TypeInsertable {
2014-03-21 15:34:16 +00:00
@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 ;
}
2014-03-25 03:41:07 +00:00
@Override
public TypeInsertPoint createTypeInsertPoint ( TypePlaceholder tph ,
ResultSet resultSet ) {
2014-08-05 10:34:09 +00:00
return new TypeInsertPoint ( this , this , resultSet . getTypeEqualTo ( tph ) , resultSet ) ;
2014-03-25 03:41:07 +00:00
}
2014-04-15 12:56:20 +00:00
@Override
public int getVariableLength ( ) {
// TODO Auto-generated method stub
return 0 ;
}
2014-08-05 10:34:09 +00:00
@Override
public Vector < SyntaxTreeNode > getChildren ( ) {
// TODO Auto-generated method stub
return new Vector < > ( ) ;
}
2014-03-21 15:34:16 +00:00
}