;
public var receivedEventType:String;
public function mouseGeneralHandler(e:GridEvent):void
{
gridEvent=e;
}
public function selectionChangeHandler(event:GridSelectionEvent):void
{
gridSelectEvt=event;
}
public function cancelSelectionChangeHandler(event:GridSelectionEvent):void
{
event.preventDefault();
}
public function caretChangeHandler(event:GridCaretEvent):void
{
gridCaretEvt=event;
}
public function collectionEventHandler(evt:mx.events.CollectionEvent):void
{
receivedEventType = String(evt.kind);
}
public function addCollEvtListener(dg:DataGrid, type:String,func:Function):void
{
dg.dataProvider.addEventListener(type,func);
}
public function addEvtListener(dg:DataGrid, type:String,func:Function):void
{
dg.addEventListener(type,func);
}
public function removeEvtListener(dg:DataGrid, type:String, func:Function):void
{
dg.removeEventListener(type,func);
}
public function createExpectedGridEvent(type:String, rowIndex:int, columnIndex:int, dg:DataGrid):GridEvent
{
if (rowIndex==-1)
return new GridEvent(type,true,true,NaN,NaN,null,false,false,false,false,0,rowIndex,columnIndex, GridColumn(dg.columns.getItemAt(columnIndex)),null);
if (columnIndex==-1)
return new GridEvent(type,true,true,NaN,NaN,null,false,false,false,false,0,rowIndex,columnIndex, null,dg.dataProvider.getItemAt(rowIndex));
return new GridEvent(type,true,true,NaN,NaN,null,false,false,false,false,0,rowIndex,columnIndex, GridColumn(dg.columns.getItemAt(columnIndex)),dg.dataProvider.getItemAt(rowIndex));
}
public function createExpectedGridCaretEvent(type:String, oldRowIndex:int, oldColumnIndex:int,newRowIndex:int,newColumnIndex:int):GridCaretEvent
{
return new GridCaretEvent(type,true,true,oldRowIndex,oldColumnIndex, newRowIndex,newColumnIndex);
}
public function createExpectedGridSelectionEvent(type:String,kind:String, rowIndex:int, columnIndex:int,rowCount:int,columnCount:int):GridSelectionEvent
{
return new GridSelectionEvent(type,true,true,kind,new CellRegion(rowIndex,columnIndex,rowCount,columnCount));
}
/**
* this method is to verify expected GridEvent, it uses expectEvent comparing with gridEvent set in mouseGeneralHandler().
* it returns a string, if comparision result is equal, returns empty string, otherwise returns a string contains failure info.
*/
public function verifyGridEvent(expectEvent:GridEvent):String
{
var errMsg:String="";
if (gridEvent==null)
errMsg+="actual GridEvent=null\n";
else
{
if (expectEvent.columnIndex==-1)
{
if (gridEvent.rowIndex!=expectEvent.rowIndex || gridEvent.item!=null )
errMsg+="rowIndex not expected:actual="+gridEvent.rowIndex+";expect="+expectEvent.rowIndex +"\n";
return errMsg;
}
if ( expectEvent.rowIndex==-1 )
{
if (gridEvent.columnIndex!=expectEvent.columnIndex || gridEvent.item!=null)
errMsg+="columnIndex not expected:actual="+gridEvent.columnIndex+";expect="+expectEvent.columnIndex +"\n";
return errMsg;
}
if (gridEvent.type==expectEvent.type && gridEvent.columnIndex==expectEvent.columnIndex &&
gridEvent.rowIndex==expectEvent.rowIndex )
{
if (gridEvent.item[expectEvent.columnIndex]!=expectEvent.item[expectEvent.columnIndex])
errMsg+="item value for index="+expectEvent.columnIndex+"\n";
}
else
errMsg+="value unexpected:type="+gridEvent.type+";rowIndex="+gridEvent.rowIndex+";columnIndex="+gridEvent.columnIndex+ ";expect:type="+expectEvent.type+";rowIndex="+expectEvent.rowIndex+";columnIndex="+expectEvent.columnIndex+"\n";
}
return errMsg;
}
/**
* this method is to verify expected GridCaretEvent, it uses expectEvent comparing with gridCaretEvent set in caretChangeHandler().
* it returns a string, if comparision result is equal, returns empty string, otherwise returns a string contains failure info.
*/
public function verifyGridCaretEvent(expectEvent:GridCaretEvent):String
{
var errMsg:String="";
if (gridCaretEvt==null)
errMsg+="actual gridCaretEvt=null\n";
else
{
if (!(gridCaretEvt.type==expectEvent.type && gridCaretEvt.oldColumnIndex==expectEvent.oldColumnIndex &&
gridCaretEvt.oldRowIndex==expectEvent.oldRowIndex && gridCaretEvt.newColumnIndex==expectEvent.newColumnIndex &&
gridCaretEvt.newRowIndex==expectEvent.newRowIndex ))
errMsg+="value unexpected:type="+gridCaretEvt.type+";oldRowIndex="+gridCaretEvt.oldRowIndex+";oldColumnIndex="+gridCaretEvt.oldColumnIndex+
";newRowIndex="+gridCaretEvt.newRowIndex+";newColumnIndex="+gridCaretEvt.newColumnIndex+
";expect:type="+expectEvent.type+";oldRowIndex="+expectEvent.oldRowIndex+";oldColumnIndex="+expectEvent.oldColumnIndex+
";newRowIndex="+expectEvent.newRowIndex+";newColumnIndex="+expectEvent.newColumnIndex+"\n";
}
return errMsg;
}
/**
* this method is to verify expected GridSelectiontEvent, it uses expectEvent comparing with gridSelectionEvent set in selectionChangeHandler().
* it returns a string, if comparision result is equal, returns empty string, otherwise returns a string contains failure info.
*/
public function verifyGridSelectionEvent(expectEvent:GridSelectionEvent):String
{
var errMsg:String="";
if (gridSelectEvt==null)
errMsg+="actual gridSelectEvt=null\n";
else
{
if (!(gridSelectEvt.kind==expectEvent.kind && gridSelectEvt.selectionChange.columnIndex==expectEvent.selectionChange.columnIndex &&
gridSelectEvt.selectionChange.rowIndex==expectEvent.selectionChange.rowIndex && gridSelectEvt.selectionChange.rowCount==expectEvent.selectionChange.rowCount &&
gridSelectEvt.selectionChange.columnCount==expectEvent.selectionChange.columnCount))
errMsg+="value unexpected:kind="+gridSelectEvt.kind+";rowIndex="+gridSelectEvt.selectionChange.rowIndex+";columnIndex="+gridSelectEvt.selectionChange.columnIndex+
";rowCount="+gridSelectEvt.selectionChange.rowCount+";columnCount="+gridSelectEvt.selectionChange.columnCount+
";expect:kind="+expectEvent.kind+";rowIndex="+expectEvent.selectionChange.rowIndex+";columnIndex="+expectEvent.selectionChange.columnIndex+
";rowCount="+expectEvent.selectionChange.rowCount+";columnCount="+expectEvent.selectionChange.columnCount+"\n";
}
return errMsg;
}
public function createExpectedIndicesVector(start:int, end:int):Vector.
{
trace("end:+"+end);
var len:int=(start==0?(end-start+1):(end-start));
var v:Vector.=new Vector.;
for(var i:int=0;i