//  package Tests;

import java.awt.event.*; // for mouseEvent and InputEvent
import java.beans.*;
import RemoteInterface.*; // for Move

public class HumanPlayerTest 
    extends PlayerTest {
    
	String ORBArgs[] = new String[1];
    
    public HumanPlayerTest(String logFile) {
	super(logFile); // report file
	 
	className = "HumanPlayer";        // CUT
	fileName =  "HumanPlayer.java";   // CUT file name
	ORBArgs[0] = "ORBInitialPort 1050";
    }

    // Preconditions: called by AbstractTest::testProcess via inheritance
    // Symantics: showTestMenu is to be used together with testDispatch
    // Postconditions: Displays super.showTestMenu and then displays
    //                 tests available in this class
    protected void showTestMenu(){
	super.showTestMenu();
	System.out.println("8. Create HumanPlayer");
	System.out.println("9. Check Class Invariants");
	System.out.println("10. Check ORB registration");
	System.out.println("11. Check contents of boardState");
    }
    
    // Preconditions: called by AbstractTest::testProcess via inheritance
    //                called after a user has input "which" test to run
    //                the tests are numbered in showTestMenu.
    // Symantics: testDispatch is to be used with showTestMenu
    // Postconditions: Executes the user selected test
    protected void testDispatch(int which[])
	throws Exception {
	
	switch (which[0]) {
	case 8 :		
	    functionalSuite();
	    break;
	case 9 :			
	    logTestResult( "Class Invariants", 
			   classInvariant() );
		break;
	case 10 :		
	    logTestResult( "Script2 - check ORB registration", 
			   testScript2() );

	    break;
	case 11 :		
	    logTestResult( "Script3 - check boardStatus", 
			   testScript3() );

	    break;

	default :
	    super.testDispatch(which);
	    break;  
	}
	
    }
 
    //--------------------------------------------------------------
    // The following are test scripts to be used with HumanPlayer.java
    // tests Scripts return boolean and do not take parameters.
  
    public boolean functionalSuite(){
        return testScript1() && testScript2() && testScript3();	
    }

    public boolean structuralSuite(){return true;}
    public boolean interactionSuite(){return true;}
    public boolean baselineSuite(){return testScript3() && testScript4() && testScript5();}
    public boolean regressionSuite(){return functionalSuite() && baselineSuite();}
    
	public boolean instantiateOUT(){
		OUT = new HumanPlayer("0");
		return classInvariant();
	}


	//Reflective accessors for locally defined state

	protected int getBoardStatePosition(int which){
		try{
			int[] array = (int[])getPrivateField((HumanPlayer)OUT, "HumanPlayer", "boardState");
			return array[which];
		}catch(Exception e){
			e.printStackTrace();
			return -32767;
		}
	}



    public boolean classInvariant(){
	
	//It is the same as the abstract Player class's invariant
	return super.classInvariant();
    }

	

    protected boolean testScript1(){
	OUT = new HumanPlayer("1");
	boolean result = super.testCase1();
	logTestResult("Script1",result);
	return result && classInvariant();
    }

	protected boolean testScript2(){
	if(askTester("Is the ORB Naming Server running?")){

	OUT = new HumanPlayer("1");
	boolean result = testCase2(ORBArgs);
	logTestResult("Script2 ",result);
	return result && classInvariant();
	}
	else{
		System.out.println("Test requires the Naming server");
		return false;
	}
    }

    protected boolean testScript3(){
	OUT = new HumanPlayer("1");
	boolean result = this.testCase3();
	logTestResult("Script3 ",result);
	return result && classInvariant();
    }

	protected boolean testScript4(){
	OUT = new HumanPlayer("1");
	boolean result = this.testCase4();
	logTestResult("Script4 ",result);
	return result && classInvariant();
    }

	protected boolean testScript5(){
	OUT = new HumanPlayer("1");
	boolean result = this.testCase5();
	logTestResult("Script5 ",result);
	return result && classInvariant();
    }
    
    protected boolean testCase5(){
	boolean result=false;
	
	if (this.getBoardStatePosition(2)==2){
		result = true;	
	}
	return result;
    }

    // -------------------------------------------------------------
    // The following are individual tests.  Most of these take 
    // a paramater and can be used in a test Script.
    // the individual tests attempt to follow a nameing scheme
    // which is the name of primary method they exercise followed
    // by the postfix - test.
    
    public boolean setGameStatusTest(int status){
 
	//legal status values are
	// -1=playing, 0=lost, 1=won, 2=draw
	boolean result;

	try {
	    ((HumanPlayer)OUT).setGameStatus(status);
	    int gameStatus 
		= ((Integer)(getPrivateField(OUT, "HumanPlayer","gameStatus"))).intValue();
	    result = (gameStatus == status) &&  classInvariant() ;
	} catch (Exception e) {
	    e.printStackTrace();
	    result = false;
	}

	return result;
	
    }

    
    

}
