package de.uni_hildesheim.sse.trans.in.rsf;

import java.io.File;
import java.io.IOException;
import java.util.List;

import org.junit.Assert;
import org.junit.Test;

import de.uni_hildesheim.sse.model.varModel.AbstractVariable;
import de.uni_hildesheim.sse.model.varModel.Project;
import de.uni_hildesheim.sse.model.varModel.datatypes.BooleanType;
import de.uni_hildesheim.sse.model.varModel.filter.ConstraintFinder;
import de.uni_hildesheim.sse.model.varModel.filter.DeclarationFinder;
import de.uni_hildesheim.sse.model.varModel.filter.DeclarationFinder.VisibilityType;
import de.uni_hildesheim.sse.model.varModel.filter.FilterType;
import de.uni_hildesheim.sse.trans.AllTests;
import de.uni_hildesheim.sse.trans.in.ParserException;

/**
 * Tests for {@link RSFReader}.
 * 
 * @author Adam Krafczyk
 */
public class RSFReaderTest {

    /**
     * Tests the read method of the {@link RSFReader}.
     * @throws IOException when the {@link RSFReader} throws an {@link IOException}.
     * @throws ParserException  when the {@link RSFReader} throws an {@link ParserException}.
     */
    @Test
    public void testRead() throws IOException, ParserException {
        File modelFile = new File(AllTests.INPUT_FOLDER, "testModel.rsf");
        RSFReader reader = new RSFReader(modelFile, true);
        
        Project project = reader.read();
        
        ConstraintFinder cFinder = new ConstraintFinder(project);
        // 8 conditions + 2 _MODULE conditions + 1 Tristate-Depends-on-Tristate condition
        Assert.assertEquals(11, cFinder.getConstraints().size());
        
//        for (Constraint c : cFinder.getConstraints()) {
//            c.getConsSyntax().accept(new DebugConstraintTreeVisitor());
//        }
        
        DeclarationFinder varFinder = new DeclarationFinder(project, FilterType.ALL, null);
        // 4 boolean variables + 2 tristate variables (with another _MODULE version each) + 1 constant
        //  + 1 string variable + 1 string comparison
        List<AbstractVariable> variables = varFinder.getVariableDeclarations(VisibilityType.ALL);
        Assert.assertEquals(11, variables.size());
        
        for (AbstractVariable var : variables) {
            Assert.assertFalse(var.getName().contains("'"));
            Assert.assertEquals(BooleanType.TYPE, var.getType());
        }
    }
    
}
