//  package Tests;

public class TicTacToeBoardTest
    extends GameBoardTest {

    public TicTacToeBoardTest(String logFile) {
	super(logFile); // report file
	
	className = "TicTacToeBoard";     // CUT
	fileName =  "TicTacToeBoard.java";   // CUT file name
	
    }

    //      public void functionalSuite() {}   
    //      public void structuralSuite(){}
    //      public void interactionSuite(){}
    //      public void baselineSuite(){}
    //      public void regressionSuite(){}
 
    // PostCondition:  classInvariant will print to the log if the 
    //                 test has failed
    public boolean classInvariant(){
	
	boolean result;
	
	try {
	    boolean invariant1 = super.classInvariant();
	    
	    boolean invariant2 = ( ((TicTacToeBoard)OUT).playerID == 0 || 
				   ((TicTacToeBoard)OUT).playerID == 1) ;
	    
	    result = (invariant1 && invariant2);
	    
	} catch (Exception e) {
	    e.printStackTrace();
	    result = false;
	}
	
	if ( !result ) {
	    logTestResult("TicTacToeBoard::classInvariant", result); 
	    System.out.println("------------------------------------------");
	    showFieldValues(OUT, "TicTacToeBoard");  
	}

	return result;
    }

    public boolean instantiateOUT(){
	OUT = new TicTacToeBoard(0);
	boolean result = testCase1();
	logTestResult("Script1",result);
	return result;
    }

    protected boolean testCase1(){
	boolean result;

	try {
	    ((TicTacToeBoard)OUT).showTicTacToe();
	    showFieldValues(OUT, "TicTacToeBoard");
	    result = ((TicTacToeBoard)OUT).isVisible();
	}
	catch(Exception e) {  
	    showFieldValues(OUT, "TicTacToeBoard"); 
	    e.printStackTrace();
	    result = false;
	}

	return result;
    }

    public boolean setYourTurn( boolean isYourTurn ) {
	boolean result;

	try {
	    ((TicTacToeBoard)OUT).setYourTurn(isYourTurn);
	     
	    // add confirmation dialog here - jlr
	    result = true;
	}
	catch ( Exception e) {
	    showFieldValues(OUT, "TicTacToeBoard");  
	    e.printStackTrace();
	    result = false;
	}

	return result;
    }

    protected void showTestMenu(){
	super.showTestMenu();
	System.out.println("2.1 set Your Turn");
	System.out.println("2.2 set waiting for Turn");
	System.out.println();
    }

    protected void testDispatch(int which[])
	throws Exception {

	if ( which.length != 2 || which[0] != 2 ) {
	    super.testDispatch(which);
	    return;
	}

	switch (which[1]) {
	case 1 :			// 1. set Your Turn
	    logTestResult( " 2.1 set Your Turn", 
			   setYourTurn(true) );
	    break;
	case 2 :			// 2. set waiting for Turn
	    logTestResult( "2.2 set waiting for Turn", 
			   setYourTurn(false) );
	    break;
	default :
	    super.testDispatch(which);
	    break;
	}
    }


}
