
import java.beans.*;

public class TestObserver extends AbstractTest{


public TestObserver(String filename){
	super(filename);
	className = "HumanPlayer";        // CUT
	fileName =  "HumanPlayer.java";   // CUT file name
}

public boolean structuralSuite(){return false;}
public boolean functionalSuite(){return testScript1();}
public boolean interactionSuite(){return false;}
public boolean baselineSuite(){return false;}
public boolean regressionSuite(){return false;}
public boolean classInvariant(){return true;}
public boolean instantiateOUT(){return false;}

protected boolean testCase1(){
	hp = new HumanPlayer("1");
	Class parameterTypes[] =   { Boolean.TYPE };	
	Object parameters[] = { new Boolean(true) };

	result = false;
	try{
		//set turn to true for hp
		invokePrivateMethod(hp,"HumanPlayer","setYourTurn",parameterTypes,parameters);
		//get TicTacToeBoard reference from the HumanPlayer
		tttb = (TicTacToeBoard)getPrivateField(hp,"HumanPlayer","ticTacToeBoard");
		//add a listener for the PACT class
		tttb.addVetoableChangeListener( new VetoableChangeListener(){
		public void vetoableChange(PropertyChangeEvent evt) throws PropertyVetoException {
				result = checkState(1);
			}
		}
		);
		tttb.addPropertyChangeListener( new PropertyChangeListener(){
		public void propertyChange(PropertyChangeEvent evt) {
				result = checkState(2);
			}
		}
		);
		//askTester("Click the left mouse button in the upper left corner of the game board",false);
		java.lang.Object sync = new java.lang.Object();
	    	synchronized (sync) {
			sync.wait(10000);
	    	}

	}catch (Exception e){
		e.printStackTrace();
	}
	return result;
}

protected boolean checkState(int select){
	try{
		if(select == 1){
			System.out.println("Checking at the vetoable side\n");
		}else{
			System.out.println("Checking at the prperty change side\n");
		}
		int[] position = (int[])getPrivateField(hp,"HumanPlayer","boardState");
		GameBoardPosition[] boardPosition = (GameBoardPosition[] )getPrivateField(tttb,"GameBoard","position");
		System.out.println("checkState " + position[0] + " " + boardPosition[0].getPositionState()+"\n");
		return position[0] == boardPosition[0].getPositionState();
	}catch(Exception e){e.printStackTrace(); return false;}
}

protected boolean testScript1(){
      boolean result = testCase1();
      logTestResult("Script1",result && classInvariant());
      return result;
  }

protected void testDispatch(int[] which)throws Exception{
	
      super.testDispatch(which);
	
}


public static void main(String[] args){

	TestObserver tester = new TestObserver("TestObserver.rpt");
	tester.testProcess();

}//main


TicTacToeBoard tttb;
HumanPlayer hp;
boolean result;
}