unit Unit1;
interface
implementation
TStatus = (Ready, Executing, Done, Skipped);
procedure ITestNode.SetStatus( Value: TStatus; Stamp: TDateTime);
begin
if FStatus = Value then exit;
FStatus := Value;
if (FStatus in [Executing, Done]) and (Stamp = 0.0) then
Stamp := Now;
case FStatus of
Executing: FExecutionBegin := Stamp;
Done: FExecutionFinal := Stamp;
end;
if assigned( FTestNodeObserver) and (FStatus in [Executing, Done]) then
FTestNodeObserver.Changed( self, [Times]);
if assigned( FTestNodeObserver) then
FTestNodeObserver.Changed( self, [Status]);
if assigned( FUpwardPropagator) and Enabled then
FUpwardPropagator.DownwardStatusChange( FStatus, self, Stamp);
end;
procedure IUpwardPropagator.DownwardStatusChange( Value: TStatus; const Child: ITestNode; Stamp: TDateTime);
begin
if (not Enabled) or FdoingSkipDisabledDeep then exit;
for j := 0 to Children.Count - 1 do
if Supports( Children[j], ITestNode, Child) and Child.Enabled then
case Child.GetStatus of
erReady : Inc( ReadyCount);
erExecuting: Inc( ExecCount);
erDone : Inc( DoneCount);
end;
if (ReadyCount > 0) and (ExecCount = 0) and (DoneCount = 0) then
SetStatus( Ready, Stamp)
else if (ReadyCount = 0) and (ExecCount = 0) and (DoneCount > 0) then
SetStatus( Done, Stamp)
else if ExecCount = 0 then
SetStatus( Skipped, Stamp)
else if
SetStatus( Executing, Stamp)
end;
procedure ITestNode.SetLoadCount( Value: integer);
begin
if not Enabled then
Value := 0;
Delta := Value - FLoadCount;
if Delta = 0 then exit;
FLoadCount := Value;
if assigned( FTestNodeObserver) then
FTestNodeObserver.Changed( self, [LoadCount]);
if assigned( FUpwardPropagator) then
FUpwardPropagator.DownwardLoadCountChange( Delta, self)
end;
function ITestNode.ComputedLoadCount: integer;
var
Child: ITestNode;
begin
if FEnabled then
begin
result := IntrinsicLoadCount;
for j := 0 to Children.Count - 1 do
if Supports( Children[j], ITestNode, Child) then
Inc( result, Child.LoadCount)
end
else
result := 0
end;
procedure ITestNode.SetEnabled( Value: boolean);
begin
if FEnabled = Value then exit;
FEnabled := Value;
if assigned( FTestNodeObserver) then
FTestNodeObserver.Changed( self, [Enabled]);
SetLoadCount( ComputedLoadCount)
end;
procedure IUpwardPropagator.DownwardLoadCountChange( Delta: integer; const Child: ITestNode);
begin
if not FdoingSetEnabledDeep then
SetLoadCount( FLoadCount + Delta)
end;
TExecutionResult = (erPass, erFail, erNull);
procedure IInternalTestNode.SetTestResult_Overall( Value: TExecutionResult);
begin
if FTestResult_Overall = Value then exit;
FTestResult_Overall := Value;
if assigned( FTestNodeObserver) then
FTestNodeObserver.Changed( self, [TestResult]);
if (FValue in [erPass, erFail]) and assigned( FUpwardPropagator) then
FUpwardPropagator.DownwardExecutionResultChange( FTestResult_Overall, self);
end;
procedure IUpwardPropagator.DownwardExecutionResultChange( ChildResult: TExecutionResult; const Child: ITestNode);
var
PassCount, FailCount, NullCount: integer;
begin
case ChildResult of
erPass:
begin
PassCount := 0;
FailCount := 0;
NullCount := 0;
for j := 0 to Children.Count - 1 do
if Supports( Children[j], ITestNode, Child) then
case Child.GetTestResult_Overall of
erPass: Inc( PassCount);
erFail: Inc( FailCount);
erNull: if Child.Enabled then
Inc( NullCount);
end;
if (PassCount > 0) and (FailCount = 0) and (NullCount = 0) then
SetTestResult_Overall( erPass)
end;
erFail:
SetTestResult_Overall( erFail);
end
end;
procedure ITestNode.Clear;
var
Changes: ChangeSet;
begin
Changes := [];
if FLoadCount <> 0 then
Include( Changes, LoadCount);
FLoadCount := 0;
if FTestResult_Overall <> erNull then
Include( Changes, TestResult);
FTestResult_Overall := erNull;
if FStatus <> Ready then
Include( Changes, Status);
FStatus := Ready;
if (FExecutionBegin <> 0.0) or (FExecutionFinal <> 0.0) then
Include( Changes, Times);
FExecutionBegin := 0.0;
FExecutionFinal := 0.0;
if assigned( FTestNodeObserver) then
FTestNodeObserver.Changed( self, Changes);
for j := 0 to Children.Count - 1 do
if Supports( Children[j], ITestNode, Child) then
Child.Clear
end;
procedure ITestNode.SkipDisabledDeep;
begin
FdoingSkipDisabledDeep := True;
if not Enabled then
SetStatus( Skipped);
for j := 0 to Children.Count - 1 do
if Supports( Children[j], ITestNode, Child) then
SkipDisabledDeep;
FdoingSkipDisabledDeep := False
end;
procedure ITestNode.SetEnabledDeep( Value: boolean);
begin
FdoingSetEnabledDeep := True;
FEnabled := Value;
for j := 0 to Children.Count - 1 do
if Supports( Children[j], ITestNode, Child) then
Child.SetEnabledDeep( Value);
SetLoadCount( ComputedLoadCount);
FdoingSetEnabledDeep := False;
end;
end.