Quellcode durchsuchen

+ added another test for writing collections (shows how it should be written and thus read
+ added a test for a writing an enum with default value

git-svn-id: branches/cleanroom@10379 -

Vincent Snijders vor 17 Jahren
Ursprung
Commit
ed75718273
4 geänderte Dateien mit 178 neuen und 287 gelöschten Zeilen
  1. 60 4
      rtl/tests/tccompstreaming.pp
  2. 1 0
      rtl/tests/tcpersistent.pp
  3. 28 254
      rtl/tests/testclasses.lpi
  4. 89 29
      rtl/tests/testcomps.pp

+ 60 - 4
rtl/tests/tccompstreaming.pp

@@ -6,7 +6,7 @@ Uses
   SysUtils,Classes,tcstreaming,fpcunit, testregistry;
 
 Type 
-  TTestComponentStream = Class(TTestStreaming)
+TTestComponentStream = Class(TTestStreaming)
   Published
     Procedure TestTEmptyComponent;
     Procedure TestTIntegerComponent;
@@ -36,6 +36,7 @@ Type
     Procedure TestTEnumComponent2;
     Procedure TestTEnumComponent3;
     Procedure TestTEnumComponent4;
+    Procedure TestTEnumComponent5;
     Procedure TestTSetComponent;
     Procedure TestTSetComponent2;
     Procedure TestTSetComponent3;
@@ -46,6 +47,7 @@ Type
     Procedure TestTCollectionComponent2;
     Procedure TestTCollectionComponent3;
     Procedure TestTCollectionComponent4;
+    Procedure TestTCollectionComponent5;
     Procedure TestTOwnedComponent;
     Procedure TestTStreamedOwnedComponent;
     Procedure TestTMethodComponent;
@@ -95,7 +97,7 @@ Type
   TTestCollectionStream = Class(TTestCase)
 
   private
-    procedure CompareColl(CA, CB: TMyCOll);
+    procedure CompareColl(CA, CB: TMyColl);
     function CreateColl(Anr: Integer): TCollComp;
     function EmptyComp: TCollComp;
     procedure TestNr(ACount: Integer);
@@ -745,6 +747,26 @@ begin
     end;
 end;
 
+Procedure TTestComponentStream.TestTEnumComponent5;
+
+Var
+  C : TComponent;
+
+begin
+  C:=TEnumComponent5.Create(Nil);
+  Try
+    SaveToStream(C);
+    ExpectSignature;
+    ExpectFlags([],0);
+    ExpectBareString('TEnumComponent5');
+    ExpectBareString('TestTEnumComponent5');
+    ExpectEndOfList;
+    ExpectEndOfList;
+  Finally
+    C.Free;
+    end;
+end;
+
 
 Procedure TTestComponentStream.TestTSetComponent;
 
@@ -1023,6 +1045,40 @@ begin
     end;
 end;
 
+Procedure TTestComponentStream.TestTCollectionComponent5;
+
+Var
+  C : TComponent;
+
+begin
+  C:=TCollectionComponent5.Create(Nil);
+  Try
+    SaveToStream(C);
+    ExpectSignature;
+    ExpectFlags([],0);
+    ExpectBareString('TCollectionComponent5');
+    ExpectBareString('TestTCollectionComponent5');
+    ExpectBareString('Coll');
+    ExpectValue(vaCollection);
+    ExpectValue(vaList);
+    ExpectBareString('StrProp1');
+    ExpectString('Something');
+    ExpectBareString('StrProp2');
+    ExpectString('Otherthing');
+    ExpectEndOfList;
+    ExpectValue(vaList);
+    ExpectBareString('StrProp1');
+    ExpectString('Something 2');
+    ExpectBareString('StrProp2');
+    ExpectString('Otherthing 2');
+    ExpectEndOfList;
+    ExpectEndOfList;
+    ExpectEndOfList;
+  Finally
+    C.Free;
+    end;
+end;
+
 
 Procedure TTestComponentStream.TestTOwnedComponent;
 
@@ -1187,7 +1243,7 @@ begin
     inherited Assign(Source);
 end;
 
-Procedure TTestCollectionStream.CompareColl(CA,CB : TMyCOll);
+Procedure TTestCollectionStream.CompareColl(CA,CB : TMyColl);
 
 Var
   I : Integer;
@@ -1219,7 +1275,7 @@ begin
   For I:=0 to ANr-1 do
     begin
     T:=Result.MyColl.Add as TMyItem;
-    T.Nr:=0;
+    T.Nr:=I; // not I+1, so the default value gets tested too
     T.Str:=IntToStr(I+1);
     end;
 end;

+ 1 - 0
rtl/tests/tcpersistent.pp

@@ -106,6 +106,7 @@ begin
   P:=Nil;
   ACount:=GetPropList(Instance,P);
   AssertEquals('Property count of TPersistence is zero',1,ACount);
+  Freemem(p);
 end;
 
 procedure TTestPersistentDescendent.TestNamePath;

+ 28 - 254
rtl/tests/testclasses.lpi

@@ -1,20 +1,21 @@
 <?xml version="1.0"?>
 <CONFIG>
   <ProjectOptions>
-    <PathDelim Value="/"/>
+    <PathDelim Value="\"/>
     <Version Value="6"/>
     <General>
+      <SessionStorage Value="InIDEConfig"/>
       <MainUnit Value="0"/>
-      <IconPath Value="./"/>
+      <IconPath Value=".\"/>
       <TargetFileExt Value=""/>
       <Title Value="Test classes"/>
-      <ActiveEditorIndexAtStart Value="6"/>
     </General>
     <VersionInfo>
       <ProjectVersion Value=""/>
     </VersionInfo>
     <PublishOptions>
       <Version Value="2"/>
+      <DestinationDirectory Value="$(TestDir)\publishedproject\"/>
       <IgnoreBinaries Value="False"/>
       <IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
       <ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
@@ -22,328 +23,101 @@
     <RunParams>
       <local>
         <FormatVersion Value="1"/>
-        <CommandLineParams Value="--format=plain --suite=TTestResolveReference"/>
-        <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
+        <CommandLineParams Value="--format=plain --suite=TTestCollectionStream"/>
+        <LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/>
       </local>
     </RunParams>
     <RequiredPackages Count="2">
       <Item1>
-        <PackageName Value="FCL"/>
+        <PackageName Value="FPCUnitConsoleRunner"/>
       </Item1>
       <Item2>
-        <PackageName Value="FPCUnitConsoleRunner"/>
+        <PackageName Value="FCL"/>
       </Item2>
     </RequiredPackages>
-    <Units Count="22">
+    <Units Count="14">
       <Unit0>
         <Filename Value="testclasses.lpr"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="testclasses"/>
-        <UsageCount Value="221"/>
       </Unit0>
       <Unit1>
         <Filename Value="tcfindnested.pp"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="tcfindnested"/>
-        <CursorPos X="13" Y="116"/>
-        <TopLine Value="66"/>
-        <EditorIndex Value="0"/>
-        <UsageCount Value="221"/>
-        <Loaded Value="True"/>
       </Unit1>
       <Unit2>
         <Filename Value="tcstringlist.pp"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="tcstringlist"/>
-        <UsageCount Value="221"/>
-        <SyntaxHighlighter Value="Text"/>
       </Unit2>
       <Unit3>
         <Filename Value="tccollection.pp"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="tccollection"/>
-        <CursorPos X="1" Y="1"/>
-        <TopLine Value="1"/>
-        <EditorIndex Value="3"/>
-        <UsageCount Value="221"/>
-        <Loaded Value="True"/>
       </Unit3>
       <Unit4>
         <Filename Value="tclist.pp"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="tclist"/>
-        <CursorPos X="1" Y="1"/>
-        <TopLine Value="1"/>
-        <EditorIndex Value="4"/>
-        <UsageCount Value="221"/>
-        <Loaded Value="True"/>
       </Unit4>
       <Unit5>
         <Filename Value="tcpersistent.pp"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="tcpersistent"/>
-        <UsageCount Value="221"/>
-        <SyntaxHighlighter Value="Text"/>
       </Unit5>
       <Unit6>
         <Filename Value="tclinkedlist.pp"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="tclinkedlist"/>
-        <CursorPos X="1" Y="237"/>
-        <TopLine Value="187"/>
-        <EditorIndex Value="2"/>
-        <UsageCount Value="221"/>
-        <Loaded Value="True"/>
       </Unit6>
       <Unit7>
-        <Filename Value="../../../../fpc/rtl/objpas/classes/classesh.inc"/>
-        <CursorPos X="15" Y="195"/>
-        <TopLine Value="154"/>
-        <UsageCount Value="80"/>
-      </Unit7>
-      <Unit8>
-        <Filename Value="../../../../fpc/rtl/objpas/classes/collect.inc"/>
-        <CursorPos X="51" Y="319"/>
-        <TopLine Value="293"/>
-        <UsageCount Value="110"/>
-      </Unit8>
-      <Unit9>
         <Filename Value="tccomponent.pp"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="tccomponent"/>
-        <CursorPos X="1" Y="260"/>
-        <TopLine Value="236"/>
-        <UsageCount Value="221"/>
-      </Unit9>
-      <Unit10>
+      </Unit7>
+      <Unit8>
         <Filename Value="tcstreaming.pp"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="tcstreaming"/>
-        <CursorPos X="3" Y="11"/>
-        <TopLine Value="1"/>
-        <EditorIndex Value="6"/>
-        <UsageCount Value="220"/>
-        <Loaded Value="True"/>
-      </Unit10>
-      <Unit11>
-        <Filename Value="tccompstreaming.pas"/>
-        <UnitName Value="tctestcompstreaming"/>
-        <CursorPos X="51" Y="4"/>
-        <TopLine Value="1"/>
-        <UsageCount Value="10"/>
-      </Unit11>
-      <Unit12>
+      </Unit8>
+      <Unit9>
         <Filename Value="testcomps.inc"/>
         <IsPartOfProject Value="True"/>
-        <UsageCount Value="220"/>
-        <SyntaxHighlighter Value="Text"/>
-      </Unit12>
-      <Unit13>
+      </Unit9>
+      <Unit10>
         <Filename Value="tccompstreaming.pp"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="tccompstreaming"/>
-        <CursorPos X="89" Y="1221"/>
-        <TopLine Value="1194"/>
-        <EditorIndex Value="5"/>
-        <UsageCount Value="220"/>
-        <Loaded Value="True"/>
-      </Unit13>
-      <Unit14>
+      </Unit10>
+      <Unit11>
         <Filename Value="tcresref.pp"/>
         <IsPartOfProject Value="True"/>
         <UnitName Value="tcresref"/>
-        <CursorPos X="1" Y="1"/>
-        <TopLine Value="1"/>
-        <EditorIndex Value="1"/>
-        <UsageCount Value="220"/>
-        <Loaded Value="True"/>
-      </Unit14>
-      <Unit15>
+      </Unit11>
+      <Unit12>
         <Filename Value="sllist.inc"/>
         <IsPartOfProject Value="True"/>
-        <UsageCount Value="220"/>
-        <SyntaxHighlighter Value="Text"/>
-      </Unit15>
-      <Unit16>
+      </Unit12>
+      <Unit13>
         <Filename Value="resref.inc"/>
         <IsPartOfProject Value="True"/>
-        <CursorPos X="11" Y="28"/>
-        <TopLine Value="1"/>
-        <UsageCount Value="220"/>
-      </Unit16>
-      <Unit17>
-        <Filename Value="../../../../fpc/rtl/objpas/classes/classes.inc"/>
-        <CursorPos X="3" Y="933"/>
-        <TopLine Value="930"/>
-        <UsageCount Value="80"/>
-      </Unit17>
-      <Unit18>
-        <Filename Value="../objpas/classes/reader.inc"/>
-        <CursorPos X="16" Y="1108"/>
-        <TopLine Value="1093"/>
-        <UsageCount Value="80"/>
-      </Unit18>
-      <Unit19>
-        <Filename Value="../../../../fpc/rtl/objpas/classes/lists.inc"/>
-        <CursorPos X="3" Y="1"/>
-        <TopLine Value="1"/>
-        <UsageCount Value="10"/>
-      </Unit19>
-      <Unit20>
-        <Filename Value="../../../../tclist.pas"/>
-        <UnitName Value="tclist"/>
-        <CursorPos X="1" Y="40"/>
-        <TopLine Value="18"/>
-        <UsageCount Value="10"/>
-      </Unit20>
-      <Unit21>
-        <Filename Value="../../../../testcoll.pp"/>
-        <UnitName Value="testcoll"/>
-        <CursorPos X="1" Y="118"/>
-        <TopLine Value="68"/>
-        <UsageCount Value="10"/>
-      </Unit21>
+      </Unit13>
     </Units>
-    <JumpHistory Count="30" HistoryIndex="29">
-      <Position1>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="1283" Column="1" TopLine="1234"/>
-      </Position1>
-      <Position2>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="93" Column="3" TopLine="51"/>
-      </Position2>
-      <Position3>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="1177" Column="1" TopLine="1154"/>
-      </Position3>
-      <Position4>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="121" Column="7" TopLine="72"/>
-      </Position4>
-      <Position5>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="1275" Column="5" TopLine="1236"/>
-      </Position5>
-      <Position6>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="9" Column="38" TopLine="1"/>
-      </Position6>
-      <Position7>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="101" Column="42" TopLine="51"/>
-      </Position7>
-      <Position8>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="95" Column="3" TopLine="93"/>
-      </Position8>
-      <Position9>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="99" Column="50" TopLine="98"/>
-      </Position9>
-      <Position10>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="1206" Column="24" TopLine="1186"/>
-      </Position10>
-      <Position11>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="101" Column="25" TopLine="100"/>
-      </Position11>
-      <Position12>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="102" Column="39" TopLine="101"/>
-      </Position12>
-      <Position13>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="101" Column="25" TopLine="100"/>
-      </Position13>
-      <Position14>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="1288" Column="1" TopLine="1245"/>
-      </Position14>
-      <Position15>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="101" Column="21" TopLine="100"/>
-      </Position15>
-      <Position16>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="1295" Column="1" TopLine="1256"/>
-      </Position16>
-      <Position17>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="1304" Column="38" TopLine="1260"/>
-      </Position17>
-      <Position18>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="96" Column="25" TopLine="70"/>
-      </Position18>
-      <Position19>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="6" Column="39" TopLine="1"/>
-      </Position19>
-      <Position20>
-        <Filename Value="tclinkedlist.pp"/>
-        <Caret Line="209" Column="22" TopLine="176"/>
-      </Position20>
-      <Position21>
-        <Filename Value="tccollection.pp"/>
-        <Caret Line="66" Column="24" TopLine="52"/>
-      </Position21>
-      <Position22>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="1305" Column="12" TopLine="1260"/>
-      </Position22>
-      <Position23>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="51" Column="42" TopLine="1"/>
-      </Position23>
-      <Position24>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="1311" Column="17" TopLine="1261"/>
-      </Position24>
-      <Position25>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="51" Column="3" TopLine="1"/>
-      </Position25>
-      <Position26>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="1209" Column="1" TopLine="1159"/>
-      </Position26>
-      <Position27>
-        <Filename Value="tccollection.pp"/>
-        <Caret Line="499" Column="1" TopLine="449"/>
-      </Position27>
-      <Position28>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="1308" Column="16" TopLine="1259"/>
-      </Position28>
-      <Position29>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="6" Column="53" TopLine="1"/>
-      </Position29>
-      <Position30>
-        <Filename Value="tccompstreaming.pp"/>
-        <Caret Line="1197" Column="22" TopLine="1172"/>
-      </Position30>
-    </JumpHistory>
   </ProjectOptions>
   <CompilerOptions>
     <Version Value="5"/>
+    <PathDelim Value="\"/>
     <CodeGeneration>
       <Generate Value="Faster"/>
     </CodeGeneration>
+    <Linking>
+      <Debugging>
+        <UseHeaptrc Value="True"/>
+      </Debugging>
+    </Linking>
     <Other>
       <CompilerPath Value="$(CompPath)"/>
     </Other>
   </CompilerOptions>
-  <Debugging>
-    <Exceptions Count="2">
-      <Item1>
-        <Name Value="ECodetoolError"/>
-      </Item1>
-      <Item2>
-        <Name Value="EFOpenError"/>
-      </Item2>
-    </Exceptions>
-  </Debugging>
 </CONFIG>

+ 89 - 29
rtl/tests/testcomps.pp

@@ -274,6 +274,14 @@ Type
     Property Dice : TDice Read F Write F default two;
   end;
 
+  // Enum property with default, no need to set
+  TEnumComponent5 = Class(TComponent)
+  private
+    F: TDice;
+  Published
+    Property Dice : TDice Read F Write F default one;
+  end;
+
   Throws = Set of TDice;
 
   // Set property, no default.
@@ -363,6 +371,20 @@ Type
     Property StrProp : String Read F Write F;
   end;
 
+  // For use in collection streaming: items with two properties
+
+  { TTest2Item }
+
+  TTest2Item = Class(TCollectionItem)
+  Private
+    F1, F2 : String;
+  public
+  Published
+    Property StrProp1 : String Read F1 Write F1;
+    Property StrProp2 : String Read F2 Write F2;
+  end;
+
+
   TTestCollection = Class(TCollection)
   Public
     Constructor Create;
@@ -400,7 +422,18 @@ Type
     Constructor Create(AOwner : TComponent); override;
     Destructor Destroy; override;
   Published
-    Property Coll : TTestCollection Read FColl Write SetCOll;
+    Property Coll : TTestCollection Read FColl Write SetColl;
+  end;
+
+  // collection two elements, items with two properties
+  TCollectionComponent5 = Class(TComponent)
+    FColl : TCollection;
+    Procedure SetColl(AColl : TCollection);
+  Public
+    Constructor Create(AOwner : TComponent); override;
+    Destructor Destroy; override;
+  Published
+    Property Coll : TCollection Read FColl Write SetColl;
   end;
 
   // Component as published property
@@ -774,6 +807,61 @@ begin
   (FColl.Add as TTestItem).StrProp:='Third';
 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
+  FColl.Assign(AColl);
+end;
+
+{ TCollectionComponent5 }
+
+procedure TCollectionComponent5.SetColl(AColl: TCollection);
+begin
+  FColl.Assign(AColl);
+end;
+
+constructor TCollectionComponent5.Create(AOwner: TComponent);
+var
+  Item : TTest2Item;
+begin
+  inherited Create(AOwner);
+  FColl:=TCollection.Create(TTest2Item);
+  Item := FColl.Add as TTest2Item;
+  Item.StrProp1 := 'Something';
+  Item.StrProp2 := 'Otherthing';
+  Item := FColl.Add as TTest2Item;
+  Item.StrProp1 := 'Something 2';
+  Item.StrProp2 := 'Otherthing 2';
+end;
+
+destructor TCollectionComponent5.Destroy;
+begin
+  FreeAndNil(FColl);
+  inherited Destroy;
+end;
+
+{ TTestCollection }
+
+Constructor TTestCollection.Create;
+begin
+  Inherited Create(TTestitem);
+  PropName:='MyCollProp';
+end;
+
 { TStreamedOwnedComponent }
 
 Constructor TStreamedOwnedComponent.Create(AOwner : TComponent);
@@ -841,32 +929,4 @@ begin
 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.