OnSimulate Event (AProgram, ADriver, ASystem) |
Version 9 |
Occurs when a simulated procedure or IOTable is called in simulation mode.
vReturn=Object.OnSimulate(obModule, procCallee, penSimulateStatus )
The OnSimulate event syntax has the following parts:
|
Name |
Type |
Description |
|
Object |
AProgram, ADriver, ASystem |
Module object |
|
obModule |
Val Object |
The simulated procedure module, could be one of the following types: AProgram, ADriver, ASystem |
|
procCallee |
Val Procedure |
The simulated procedure |
|
penSimulateStatus |
Return status indicating how to proceed with the simulation handling, By default it is set to aSimulateCallNext. |
|
|
vReturn |
Variant |
Simulated procedure return value |
The OnSimulate event occurs before ATEasy calls a simulated procedure (or IO Table). To set a procedure as simulated you must call the SetSimulateProcedures function.
Use this event to implement simulation, it can be used to:
● Call the simulated procedure using the procCallee parameter.
● Change the simulated procedure return value and Var/Val parameters to test the application logic and flow control.
● Track procedures calls and parameters.
● Trace and analyze procedures performance and call count.
The OnSimulate events apply to the Program, System and Driver modules, ATEasy will call first the Program, then the System drivers (in the order they show) and last the System. Only defined events are called. You can stop the event calling for the simulated procedure by setting the penSimulateStatus to aSimulateDone or aSimulateCallSimulated. Setting penSimulateStatus to aSimulateCallNext will continue calling OnSimulate events for other modules if defined.
For more information about Simulation see the Simulation topic in the ATEasy User's Guide.
The following example shows implementation of simulation as taken from the example project Simulation.prj (see ATEasy Examples folder). The code handle simulation for two modules "DMM" (driver) and "Language" (program):
Procedure OnSimulate(obModule, procCallee, penSimulateStatus): Variant Public
obModule: Val Object
procCallee: Val Procedure
penSimulateStatus: Var Internal.enumASimulateStatus
j: Long
i: Long
iCols: Long
iRows: Long
dMultiplier: Double
vr: Variant
lIndex: Long
sModule: String
p: Any
vrReturn: Variant
sProc: String
{
sModule=obModule.name
select sModule
case "DMM"
sProc=procCallee
select sProc
case "DMM.Measure"
p=GetSimulateParameter("pdResult")
p=6.0
case "DMM.GetSystemIdentification"
p=GetSimulateParameter("psID")
p="34401A"
endselect
trace sProc ! trace all DMM calls
penSimulateStatus=aSimulateDone
case "Language"
sProc=procCallee
select sProc
case "Language.User32.GetSystemMetrics"
! language test 7.1
if Test.Id="User32"
p=GetSimulateParameter("smIndex")
lIndex=p
if lIndex=0 or lIndex=1
vrReturn=1024
else
vrReturn=0
TestStatus=FAIL
endif
endif
trace sProc ! trace specific calls
penSimulateStatus=aSimulateDone
case "Language.MultipleMatrix"
! see language test 3.3
p=GetSimulateParameter("aadMatrix")
vr=p ! p is Var double[,]
dMultiplier=GetSimulateParameter("dMultiplier")
iRows=VarDimSize(vr, 0)
iCols=VarDimSize(vr, 1)
for i=0 to iRows-1
for j=0 to iCols-1
vr[i, j]=vr[i, j]*dMultiplier
next
next
p=vr
penSimulateStatus=aSimulateDone
case "Language.FillTestResultInfo"
! see language test 3.4
p=GetSimulateParameter("stTestResInfo")
! p is a structure when assigning a struct to variant, the variant is an array and each element is a field
vr=p
vr[0]=Task.Index ! .nTask
vr[1]=Test.Index ! .nTest
vr[2]=TestResult ! .vResult
vr[3]=TestStatus ! .enTestStatus
p=vr ! assign to the var parameter
penSimulateStatus=aSimulateDone
case else
! call the original function, some of the user32 api will get here
penSimulateStatus=aSimulateCallSimulated
endselect
trace sProc
case else
penSimulateStatus=aSimulateCallSimulated
trace sModule
TestStatus=FAIL ! should not get here
endselect
return vrReturn
}
Simulation, App.Simulate, SetSimulateProcedures, GetSimulateParameter, GetCallerName, Program Variable, Task Variable, Test Variable, enumASimulateStatus, About Module Events,