* Fix memleak in case only a selection of tests is run

git-svn-id: trunk@35954 -
This commit is contained in:
michael 2017-04-26 13:24:42 +00:00
parent 5f66f5cebb
commit 3c53796044
2 changed files with 31 additions and 17 deletions

View File

@ -285,29 +285,16 @@ Type
TDecoratorTestSuite = Class(TTestSuite)
public
Procedure FreeDecorators(T : TTest);
Destructor Destroy; override;
end;
Procedure TDecoratorTestSuite.FreeDecorators(T : TTest);
Var
I : Integer;
begin
If (T is TTestSuite) then
for I:=0 to TTestSuite(t).ChildTestCount-1 do
FreeDecorators(TTest(TTestSuite(t).Test[i]));
if (T is TTestDecorator) and (TTestDecorator(T).Test is TDecoratorTestSuite) then
T.free;
end;
{ TDecoratorTestSuite }
destructor TDecoratorTestSuite.Destroy;
begin
FreeDecorators(Self);
// We need to find something for this.
Tests.Clear;
OwnsTests:=False;
inherited Destroy;
end;

View File

@ -244,11 +244,14 @@ type
TTestSuite = class(TTest)
private
FOwnsTests: Boolean;
FTests: TFPList;
FName: string;
FTestSuiteName: string;
FEnableIgnores: boolean;
procedure SetOwnsTests(AValue: Boolean);
protected
Procedure SetOwnTestOnTests(AValue: Boolean);
Function DoAddTest(ATest : TTest) : Integer;
function GetTestName: string; override;
function GetTestSuiteName: string; override;
@ -256,6 +259,7 @@ type
procedure SetTestSuiteName(const aName: string); override;
procedure SetTestName(const Value: string); virtual;
procedure SetEnableIgnores(Value: boolean); override;
property OwnsTests : Boolean Read FOwnsTests Write SetOwnsTests;
public
constructor Create(AClass: TClass; AName: string); reintroduce; overload; virtual;
constructor Create(AClass: TClass); reintroduce; overload; virtual;
@ -1252,6 +1256,7 @@ constructor TTestSuite.Create;
begin
inherited Create;
FTests := TFPList.Create;
FOwnsTests:=True;
FEnableIgnores := True;
end;
@ -1274,9 +1279,31 @@ begin
Result:=FTests.Count;
end;
function TTestSuite.DoAddTest(ATest: TTest): Integer;
procedure TTestSuite.SetOwnsTests(AValue: Boolean);
begin
Result:=FTests.Add(TTestItem.Create(ATest));
if FOwnsTests=AValue then Exit;
FOwnsTests:=AValue;
SetOwnTestOnTests(AValue);
end;
procedure TTestSuite.SetOwnTestOnTests(AValue: Boolean);
Var
I : Integer;
begin
For I:=0 to FTests.Count-1 do
TTestItem(FTests[i]).OwnsTest:=AValue;
end;
function TTestSuite.DoAddTest(ATest: TTest): Integer;
Var
I : TTestItem;
begin
I:=TTestItem.Create(ATest);
I.OwnsTest:=OwnsTests;
Result:=FTests.Add(I);
if ATest.TestSuiteName = '' then
ATest.TestSuiteName := Self.TestName;
ATest.EnableIgnores := Self.EnableIgnores;