2
0
Эх сурвалжийг харах

* Added additional tests for collection streaming. Restructured

git-svn-id: branches/cleanroom@9401 -
michael 18 жил өмнө
parent
commit
2fedebf078

+ 1 - 1
.gitattributes

@@ -5539,7 +5539,7 @@ rtl/tests/tcstrutils.pp svneol=native#text/plain
 rtl/tests/tctparser.pp svneol=native#text/plain
 rtl/tests/testclasses.lpi svneol=native#text/plain
 rtl/tests/testclasses.lpr svneol=native#text/plain
-rtl/tests/testcomps.inc svneol=native#text/plain
+rtl/tests/testcomps.pp svneol=native#text/plain
 rtl/tests/tstrutils.lpi svneol=native#text/plain
 rtl/tests/tstrutils.lpr svneol=native#text/plain
 rtl/ucmaps/8859-1.txt svneol=native#text/plain

+ 12 - 9
rtl/tests/gencomptest.dpr

@@ -5,7 +5,9 @@ program gencomptest;
 uses
   SysUtils,
   classes,
-  typinfo;
+  typinfo,
+  tcstreaming in 'tcstreaming.pas',
+  testcomps in 'testcomps.pas';
 
 Var
   Indent : String;
@@ -183,6 +185,7 @@ var
               ConvertValue;
               end;
             Reader.CheckValue(vaList);
+            AddExpectValue(vaList);
             Inc(NestingLevel);
             while not Reader.EndOfList do
               ConvertProperty;
@@ -292,8 +295,6 @@ begin
   Addln('end;');
 end;
 
-{$i testcomps.inc}
-
 Procedure GenTests;
 
 begin
@@ -331,6 +332,10 @@ begin
   TestComponent(TSetComponent4,Nil);
   TestComponent(TMultipleComponent,Nil);
   TestComponent(TPersistentComponent,Nil);
+  TestComponent(TCollectionComponent,Nil);
+  TestComponent(TCollectionComponent2,Nil);
+  TestComponent(TCollectionComponent3,Nil);
+  TestComponent(TCollectionComponent4,Nil);
   TestComponent(TOwnedComponent,Nil);
   TestComponent(TStreamedOwnedComponent,Nil);
   TestComponent(TMethodComponent,Nil);
@@ -345,15 +350,15 @@ Var
   F : Text;
 
 begin
-  Assign(f,'tccompstreaming.pp');
+  Assign(f,'tctestcompstreaming.pas');
   Rewrite(F);
   try
-  Writeln(F,'Unit tccompstreaming;');
+  Writeln(F,'Unit tctestcompstreaming;');
   Writeln(F);
   Writeln(F,'interface');
   Writeln(F);
   Writeln(F,'Uses');
-  Writeln(F,'  SysUtils,Classes,tcstreaming, testregistry;');
+  Writeln(F,'  SysUtils,Classes,tcstreaming;');
   Writeln(F);
   Writeln(F,'Type ');
   Writeln(F,'  TTestComponentStream = Class(TTestStreaming)');
@@ -364,12 +369,10 @@ begin
   Writeln(F);
   Writeln(F,'Implementation');
   Writeln(F);
-  Writeln(F,'{$i testcomps.inc}');
+  Writeln(F,'uses testcomps;');
   For I:=0 to Src.Count-1 do
     Writeln(F,Src[i]);
   Writeln(F);
-  Writeln(F,'begin');
-  Writeln(F,'  RegisterTest(TTestComponentStream);');
   Writeln(F,'end.');
   Finally
     Close(f);

+ 128 - 4
rtl/tests/tccompstreaming.pp

@@ -3,7 +3,7 @@ Unit tccompstreaming;
 interface
 
 Uses
-  SysUtils, Classes, tcstreaming, testregistry;
+  SysUtils,Classes,tcstreaming;
 
 Type 
   TTestComponentStream = Class(TTestStreaming)
@@ -42,6 +42,10 @@ Type
     Procedure TestTSetComponent4;
     Procedure TestTMultipleComponent;
     Procedure TestTPersistentComponent;
+    Procedure TestTCollectionComponent;
+    Procedure TestTCollectionComponent2;
+    Procedure TestTCollectionComponent3;
+    Procedure TestTCollectionComponent4;
     Procedure TestTOwnedComponent;
     Procedure TestTStreamedOwnedComponent;
     Procedure TestTMethodComponent;
@@ -50,7 +54,7 @@ Type
 
 Implementation
 
-{$i testcomps.inc}
+uses testcomps;
 
 
 Procedure TTestComponentStream.TestTEmptyComponent;
@@ -843,6 +847,128 @@ begin
 end;
 
 
+Procedure TTestComponentStream.TestTCollectionComponent;
+
+Var
+  C : TComponent;
+
+begin
+  C:=TCollectionComponent.Create(Nil);
+  Try
+    SaveToStream(C);
+    ExpectSignature;
+    ExpectFlags([],0);
+    ExpectBareString('TCollectionComponent');
+    ExpectBareString('TestTCollectionComponent');
+    ExpectBareString('Coll');
+    ExpectValue(vaCollection);
+    ExpectEndOfList;
+    ExpectEndOfList;
+    ExpectEndOfList;
+  Finally
+    C.Free;
+    end;
+end;
+
+
+Procedure TTestComponentStream.TestTCollectionComponent2;
+
+Var
+  C : TComponent;
+
+begin
+  C:=TCollectionComponent2.Create(Nil);
+  Try
+    SaveToStream(C);
+    ExpectSignature;
+    ExpectFlags([],0);
+    ExpectBareString('TCollectionComponent2');
+    ExpectBareString('TestTCollectionComponent2');
+    ExpectBareString('Coll');
+    ExpectValue(vaCollection);
+    ExpectValue(vaList);
+    ExpectBareString('StrProp');
+    ExpectString('First');
+    ExpectEndOfList;
+    ExpectValue(vaList);
+    ExpectBareString('StrProp');
+    ExpectString('Second');
+    ExpectEndOfList;
+    ExpectValue(vaList);
+    ExpectBareString('StrProp');
+    ExpectString('Third');
+    ExpectEndOfList;
+    ExpectEndOfList;
+    ExpectEndOfList;
+    ExpectEndOfList;
+  Finally
+    C.Free;
+    end;
+end;
+
+
+Procedure TTestComponentStream.TestTCollectionComponent3;
+
+Var
+  C : TComponent;
+
+begin
+  C:=TCollectionComponent3.Create(Nil);
+  Try
+    SaveToStream(C);
+    ExpectSignature;
+    ExpectFlags([],0);
+    ExpectBareString('TCollectionComponent3');
+    ExpectBareString('TestTCollectionComponent3');
+    ExpectBareString('Coll');
+    ExpectValue(vaCollection);
+    ExpectValue(vaList);
+    ExpectBareString('StrProp');
+    ExpectString('First');
+    ExpectEndOfList;
+    ExpectValue(vaList);
+    ExpectEndOfList;
+    ExpectValue(vaList);
+    ExpectBareString('StrProp');
+    ExpectString('Third');
+    ExpectEndOfList;
+    ExpectEndOfList;
+    ExpectEndOfList;
+    ExpectEndOfList;
+  Finally
+    C.Free;
+    end;
+end;
+
+
+Procedure TTestComponentStream.TestTCollectionComponent4;
+
+Var
+  C : TComponent;
+
+begin
+  C:=TCollectionComponent4.Create(Nil);
+  Try
+    SaveToStream(C);
+    ExpectSignature;
+    ExpectFlags([],0);
+    ExpectBareString('TCollectionComponent4');
+    ExpectBareString('TestTCollectionComponent4');
+    ExpectBareString('Coll');
+    ExpectValue(vaCollection);
+    ExpectValue(vaList);
+    ExpectBareString('StrProp');
+    ExpectString('Something');
+    ExpectEndOfList;
+    ExpectEndOfList;
+    ExpectEndOfList;
+    ExpectEndOfList;
+  Finally
+    C.Free;
+    end;
+end;
+
+
 Procedure TTestComponentStream.TestTOwnedComponent;
 
 Var
@@ -944,6 +1070,4 @@ begin
     end;
 end;
 
-begin
-  RegisterTest(TTestComponentStream);
 end.

+ 2 - 2
rtl/tests/testclasses.lpr

@@ -3,8 +3,8 @@ program testclasses;
 {$mode objfpc}{$H+}
 
 uses
-  Classes, consoletestrunner, tcfindnested, tcstringlist, tccollection, tclist,
-  tcpersistent, tclinkedlist, tccomponent, tcstreaming, tccompstreaming;
+  Classes, tcfindnested, tcstringlist, tccollection, tclist,
+  tcpersistent, tclinkedlist, tccomponent, tcstreaming, tccompstreaming,consoletestrunner;
 
 type
 

+ 146 - 0
rtl/tests/testcomps.inc → rtl/tests/testcomps.pp

@@ -1,3 +1,9 @@
+unit testcomps;
+
+interface
+
+uses classes, sysutils;
+
 Type
   TEmptyComponent = Class(TComponent)
   end;
@@ -344,10 +350,60 @@ Type
     procedure SetPers(const Value: TTestPersistent1);
   Public
     Constructor Create(AOwner : TComponent);  override;
+    Destructor Destroy; override;
   Published
     Property Persist : TTestPersistent1 Read FPers Write SetPers;
   end;
 
+  // For use in collection streaming
+  TTestItem = Class(TCollectionItem)
+  Private
+    F : String;
+  Published
+    Property StrProp : String Read F Write F;
+  end;
+
+  TTestCollection = Class(TCollection)
+  Public
+    Constructor Create;
+  end;
+
+  // Empty collection
+  TCollectionComponent = Class(TComponent)
+  Private
+    FColl : TCollection;
+    Procedure SetColl(AColl : TCollection);
+  Public
+    Constructor Create(AOwner : TComponent); override;
+    Destructor Destroy; override;
+  Published
+    Property Coll : TCollection Read FColl Write SetCOll;
+  end;
+
+  // collection with elements.
+  TCollectionComponent2 = Class(TCollectionComponent)
+  Public
+    Constructor Create(AOwner : TComponent); override;
+  end;
+
+  // collection with elements, one has no props
+  TCollectionComponent3 = Class(TCollectionComponent)
+  Public
+    Constructor Create(AOwner : TComponent); override;
+  end;
+
+  // collection with changed propname, one element
+  TCollectionComponent4 = Class(TComponent)
+    FColl : TTestCollection;
+    Procedure SetColl(AColl : TTestCollection);
+  Public
+    Constructor Create(AOwner : TComponent); override;
+    Destructor Destroy; override;
+  Published
+    Property Coll : TTestCollection Read FColl Write SetCOll;
+  end;
+
+  // Component as published property
   TOwnedComponent = Class(TComponent)
     F : TComponent;
   Public
@@ -362,6 +418,7 @@ Type
     procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
   end;
 
+  // Stream sub component.
   TStreamedOwnedComponent = Class(TChildrenComponent)
   Public
     Constructor Create(AOwner : TComponent);  override;
@@ -369,8 +426,11 @@ Type
     Sub : TIntegerComponent;
   end;
 
+  // Method tests.
+
   THandler = Procedure of Object;
 
+  // Method property that points to own method.
   TMethodComponent = Class(TComponent)
   Private
     F : THandler;
@@ -381,6 +441,7 @@ Type
     Property MethodProp : THandler Read F Write F;
   end;
 
+  // Method property of owned component that points to own method.
   TMethodComponent2 = Class(TChildrenComponent)
   Public
     Constructor Create(AOwner : TComponent);  override;
@@ -388,6 +449,8 @@ Type
     Procedure MyMethod2;
   end;
 
+Implementation
+
 procedure TChildrenComponent.GetChildren(Proc: TGetChildProc; Root: TComponent);
 
 Var
@@ -655,11 +718,64 @@ begin
   FPers.AString:='A persistent string';
 end;
 
+Destructor TPersistentComponent.Destroy;
+
+begin
+  FreeAndNil(FPers);
+  Inherited;
+end;
+
 procedure TPersistentComponent.SetPers(const Value: TTestPersistent1);
 begin
   FPers.Assign(Value);
 end;
 
+{ TCollectionComponent }
+
+Procedure TCollectionComponent.SetColl(AColl : TCollection);
+
+begin
+  FColl.Assign(AColl);
+end;
+
+Constructor TCollectionComponent.Create(AOwner : TComponent);
+
+begin
+  Inherited;
+  FColl:=TCollection.Create(TTestItem);
+end;
+
+Destructor TCollectionComponent.Destroy;
+
+begin
+  FreeAndNil(FColl);
+  Inherited;
+end;
+
+{ TCollectionComponent2 }
+
+Constructor TCollectionComponent2.Create(AOwner : TComponent);
+
+begin
+  Inherited;
+  (FColl.Add as TTestItem).StrProp:='First';
+  (FColl.Add as TTestItem).StrProp:='Second';
+  (FColl.Add as TTestItem).StrProp:='Third';
+end;
+
+{ TCollectionComponen3 }
+
+Constructor TCollectionComponent3.Create(AOwner : TComponent);
+
+begin
+  Inherited;
+  (FColl.Add as TTestItem).StrProp:='First';
+  (FColl.Add as TTestItem).StrProp:='';
+  (FColl.Add as TTestItem).StrProp:='Third';
+end;
+
+{ TStreamedOwnedComponent }
+
 Constructor TStreamedOwnedComponent.Create(AOwner : TComponent);
 
 begin
@@ -724,3 +840,33 @@ begin
  // Do nothng
 end;
 
+
+{ TCollectionComponent4 }
+
+constructor TCollectionComponent4.Create(AOwner: TComponent);
+begin
+  inherited;
+  FColl:=TTestCollection.Create;
+  (FColl.Add as TTestItem).StrProp:='Something'
+end;
+
+destructor TCollectionComponent4.Destroy;
+begin
+  FreeAndNil(FColl);
+  inherited;
+end;
+
+procedure TCollectionComponent4.SetColl(AColl: TTestCollection);
+begin
+
+end;
+
+{ TTestCollection }
+
+Constructor TTestCollection.Create;
+begin
+  Inherited Create(TTestitem);
+  PropName:='MyCollProp';
+end;
+
+end.