Selaa lähdekoodia

* improved tests for streaming components with owned subcomponents

git-svn-id: branches/cleanroom@10400 -
Vincent Snijders 17 vuotta sitten
vanhempi
commit
0f5ec39c49
2 muutettua tiedostoa jossa 26 lisäystä ja 0 poistoa
  1. 6 0
      rtl/tests/tccompstreaming.pp
  2. 20 0
      rtl/tests/tcstreaming.pp

+ 6 - 0
rtl/tests/tccompstreaming.pp

@@ -6,6 +6,9 @@ Uses
   SysUtils,Classes,tcstreaming,fpcunit, testregistry;
 
 Type 
+
+{ TTestComponentStream }
+
 TTestComponentStream = Class(TTestStreaming)
   Published
     Procedure TestTEmptyComponent;
@@ -1126,6 +1129,8 @@ begin
     ExpectEndOfList;
     ExpectEndOfList;
     ExpectEndOfList;
+    ExpectEndOfList;
+    ExpectEndOfStream;
   Finally
     C.Free;
     end;
@@ -1160,6 +1165,7 @@ begin
     ExpectEndOfList;
     ExpectEndOfList;
     ExpectEndOfList;
+    ExpectEndOfStream;
   Finally
     C.Free;
     end;

+ 20 - 0
rtl/tests/tcstreaming.pp

@@ -8,6 +8,9 @@ Uses
   SysUtils,Classes, fpcunit, testutils, testregistry;
 
 Type
+
+  { TTestStreaming }
+
   TTestStreaming = Class(TTestCase)
   Private
     FStream : TMemoryStream;
@@ -39,6 +42,7 @@ Type
     Procedure ExpectWideString(AValue : WideString);
     Procedure ExpectEndofList;
     Procedure ExpectSignature;
+    Procedure ExpectEndOfStream;
   end;
 
 implementation
@@ -359,11 +363,20 @@ begin
 end;
 
 procedure TTestStreaming.SaveToStream(C: TComponent);
+var
+  s: TStream;
 begin
   C.Name:='Test'+C.ClassName;
   FStream.Clear;
   FStream.WriteComponent(C);
   FStream.Position:=0;
+  // for debugging purposes, you can write a component to file too
+  // set the class name of the component you want to write to disk in the next line
+  if (C.ClassName='TStreamedOwnedComponentsX') then begin
+    s := TFileStream.Create(C.ClassName+'.txt', fmCreate, fmShareDenyNone );
+    s.WriteComponent(C);
+    s.Free;
+  end;
 end;
 
 procedure TTestStreaming.TearDown;
@@ -412,4 +425,11 @@ begin
     Fail('Expected bare string %s, got :%s',[AValue,S]);
 end;
 
+procedure TTestStreaming.ExpectEndOfStream;
+begin
+  If (FStream.Position<>FStream.Size) then
+    Fail('Expected at end of stream, current position=%d, size=%d',
+          [FStream.Position,FStream.Size]);
+end;
+
 end.