| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405 |
- Unit tccompstreaming;
- interface
- Uses
- SysUtils,Classes,tcstreaming,fpcunit, testregistry;
- Type
- { TTestComponentStream }
- TTestComponentStream = Class(TTestStreaming)
- Published
- Procedure TestTEmptyComponent;
- Procedure TestTIntegerComponent;
- Procedure TestTIntegerComponent2;
- Procedure TestTIntegerComponent3;
- Procedure TestTIntegerComponent4;
- Procedure TestTIntegerComponent5;
- Procedure TestTInt64Component;
- Procedure TestTInt64Component2;
- Procedure TestTInt64Component3;
- Procedure TestTInt64Component4;
- Procedure TestTInt64Component5;
- Procedure TestTInt64Component6;
- Procedure TestTStringComponent;
- Procedure TestTStringComponent2;
- Procedure TestTWideStringComponent;
- Procedure TestTWideStringComponent2;
- Procedure TestTSingleComponent;
- Procedure TestTDoubleComponent;
- Procedure TestTExtendedComponent;
- Procedure TestTCompComponent;
- Procedure TestTCurrencyComponent;
- Procedure TestTDateTimeComponent;
- Procedure TestTDateTimeComponent2;
- Procedure TestTDateTimeComponent3;
- Procedure TestTEnumComponent;
- Procedure TestTEnumComponent2;
- Procedure TestTEnumComponent3;
- Procedure TestTEnumComponent4;
- Procedure TestTEnumComponent5;
- Procedure TestTSetComponent;
- Procedure TestTSetComponent2;
- Procedure TestTSetComponent3;
- Procedure TestTSetComponent4;
- Procedure TestTMultipleComponent;
- Procedure TestTPersistentComponent;
- Procedure TestTCollectionComponent;
- Procedure TestTCollectionComponent2;
- Procedure TestTCollectionComponent3;
- Procedure TestTCollectionComponent4;
- Procedure TestTCollectionComponent5;
- Procedure TestTOwnedComponent;
- Procedure TestTStreamedOwnedComponent;
- Procedure TestTStreamedOwnedComponents;
- Procedure TestTMethodComponent;
- Procedure TestTMethodComponent2;
- end;
- { TMyItem }
- TMyItem = Class(TCollectionItem)
- private
- FNR: Integer;
- FStr: String;
- Public
- Procedure Assign(Source : TPersistent); override;
- Published
- Property Nr : Integer Read FNR Write FNR;
- Property Str: String Read FStr Write FStr;
- end;
- { TMyColl }
- TMyColl = Class(TCollection)
- private
- function GetIt(index : Integer): TMyItem;
- procedure SetIt(index : Integer; const AValue: TMyItem);
- Public
- Property It[index : Integer] : TMyItem Read GetIt Write SetIt; default;
- end;
- { TCollComp }
- TCollComp = Class(TComponent)
- private
- FMyColl: TMyColl;
- procedure SetMyColl(const AValue: TMyColl);
- Public
- Constructor Create(AOwner : TComponent); override;
- Destructor Destroy; override;
- Function ToStream : TStream;
- Procedure FromStream(AStream : TStream);
- Published
- Property MyColl : TMyColl Read FMyColl Write SetMyColl;
- end;
- { TTestCollectionStream }
- TTestCollectionStream = Class(TTestCase)
- private
- procedure CompareColl(CA, CB: TMyColl);
- function CreateColl(Anr: Integer): TCollComp;
- function EmptyComp: TCollComp;
- procedure TestNr(ACount: Integer);
- Published
- procedure Test1;
- procedure Test2;
- procedure Test3;
- procedure TestClear;
- procedure TestEmpty;
- end;
- Implementation
- uses testcomps;
- Procedure TTestComponentStream.TestTEmptyComponent;
- Var
- C : TComponent;
- begin
- C:=TEmptyComponent.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TEmptyComponent');
- ExpectBareString('TestTEmptyComponent');
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTIntegerComponent;
- Var
- C : TComponent;
- begin
- C:=TIntegerComponent.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TIntegerComponent');
- ExpectBareString('TestTIntegerComponent');
- ExpectBareString('IntProp');
- ExpectInteger(3);
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTIntegerComponent2;
- Var
- C : TComponent;
- begin
- C:=TIntegerComponent2.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TIntegerComponent2');
- ExpectBareString('TestTIntegerComponent2');
- ExpectBareString('IntProp');
- ExpectInteger(1024);
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTIntegerComponent3;
- Var
- C : TComponent;
- begin
- C:=TIntegerComponent3.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TIntegerComponent3');
- ExpectBareString('TestTIntegerComponent3');
- ExpectBareString('IntProp');
- ExpectInteger(262144);
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTIntegerComponent4;
- Var
- C : TComponent;
- begin
- C:=TIntegerComponent4.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TIntegerComponent4');
- ExpectBareString('TestTIntegerComponent4');
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTIntegerComponent5;
- Var
- C : TComponent;
- begin
- C:=TIntegerComponent5.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TIntegerComponent5');
- ExpectBareString('TestTIntegerComponent5');
- ExpectBareString('IntProp');
- ExpectInteger(5);
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTInt64Component;
- Var
- C : TComponent;
- begin
- C:=TInt64Component.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TInt64Component');
- ExpectBareString('TestTInt64Component');
- ExpectBareString('Int64Prop');
- ExpectInteger(4);
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTInt64Component2;
- Var
- C : TComponent;
- begin
- C:=TInt64Component2.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TInt64Component2');
- ExpectBareString('TestTInt64Component2');
- ExpectBareString('Int64Prop');
- ExpectInteger(1024);
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTInt64Component3;
- Var
- C : TComponent;
- begin
- C:=TInt64Component3.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TInt64Component3');
- ExpectBareString('TestTInt64Component3');
- ExpectBareString('Int64Prop');
- ExpectInteger(262144);
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTInt64Component4;
- Var
- C : TComponent;
- begin
- C:=TInt64Component4.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TInt64Component4');
- ExpectBareString('TestTInt64Component4');
- ExpectBareString('Int64Prop');
- ExpectInt64(2147745791);
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTInt64Component5;
- Var
- C : TComponent;
- begin
- C:=TInt64Component5.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TInt64Component5');
- ExpectBareString('TestTInt64Component5');
- ExpectBareString('Int64Prop');
- ExpectInteger(7);
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTInt64Component6;
- Var
- C : TComponent;
- begin
- C:=TInt64Component6.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TInt64Component6');
- ExpectBareString('TestTInt64Component6');
- ExpectBareString('Int64Prop');
- ExpectInteger(8);
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTStringComponent;
- Var
- C : TComponent;
- begin
- C:=TStringComponent.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TStringComponent');
- ExpectBareString('TestTStringComponent');
- ExpectBareString('StringProp');
- ExpectString('A string');
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTStringComponent2;
- Var
- C : TComponent;
- begin
- C:=TStringComponent2.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TStringComponent2');
- ExpectBareString('TestTStringComponent2');
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTWideStringComponent;
- Var
- C : TComponent;
- begin
- C:=TWideStringComponent.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TWideStringComponent');
- ExpectBareString('TestTWideStringComponent');
- ExpectBareString('WideStringProp');
- ExpectString('Some WideString');
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTWideStringComponent2;
- Var
- C : TComponent;
- begin
- C:=TWideStringComponent2.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TWideStringComponent2');
- ExpectBareString('TestTWideStringComponent2');
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTSingleComponent;
- Var
- C : TComponent;
- begin
- C:=TSingleComponent.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TSingleComponent');
- ExpectBareString('TestTSingleComponent');
- ExpectBareString('SingleProp');
- ExpectExtended(1.23);
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTDoubleComponent;
- Var
- C : TComponent;
- begin
- C:=TDoubleComponent.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TDoubleComponent');
- ExpectBareString('TestTDoubleComponent');
- ExpectBareString('DoubleProp');
- ExpectExtended(2.34);
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTExtendedComponent;
- Var
- C : TComponent;
- begin
- C:=TExtendedComponent.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TExtendedComponent');
- ExpectBareString('TestTExtendedComponent');
- ExpectBareString('ExtendedProp');
- ExpectExtended(3.45);
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTCompComponent;
- Var
- C : TComponent;
- begin
- C:=TCompComponent.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TCompComponent');
- ExpectBareString('TestTCompComponent');
- ExpectBareString('ExtendedProp');
- ExpectExtended(5.00);
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTCurrencyComponent;
- Var
- C : TComponent;
- begin
- C:=TCurrencyComponent.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TCurrencyComponent');
- ExpectBareString('TestTCurrencyComponent');
- ExpectBareString('CurrencyProp');
- ExpectExtended(5.67);
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTDateTimeComponent;
- Var
- C : TComponent;
- begin
- C:=TDateTimeComponent.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TDateTimeComponent');
- ExpectBareString('TestTDateTimeComponent');
- ExpectBareString('DateTimeProp');
- ExpectExtended(35278.00);
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTDateTimeComponent2;
- Var
- C : TComponent;
- begin
- C:=TDateTimeComponent2.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TDateTimeComponent2');
- ExpectBareString('TestTDateTimeComponent2');
- ExpectBareString('DateTimeProp');
- ExpectExtended(0.97);
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTDateTimeComponent3;
- Var
- C : TComponent;
- begin
- C:=TDateTimeComponent3.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TDateTimeComponent3');
- ExpectBareString('TestTDateTimeComponent3');
- ExpectBareString('DateTimeProp');
- ExpectExtended(35278.97);
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTEnumComponent;
- Var
- C : TComponent;
- begin
- C:=TEnumComponent.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TEnumComponent');
- ExpectBareString('TestTEnumComponent');
- ExpectBareString('Dice');
- ExpectIdent('four');
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTEnumComponent2;
- Var
- C : TComponent;
- begin
- C:=TEnumComponent2.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TEnumComponent2');
- ExpectBareString('TestTEnumComponent2');
- ExpectBareString('Dice');
- ExpectIdent('one');
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTEnumComponent3;
- Var
- C : TComponent;
- begin
- C:=TEnumComponent3.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TEnumComponent3');
- ExpectBareString('TestTEnumComponent3');
- ExpectBareString('Dice');
- ExpectIdent('three');
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTEnumComponent4;
- Var
- C : TComponent;
- begin
- C:=TEnumComponent4.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TEnumComponent4');
- ExpectBareString('TestTEnumComponent4');
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- 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;
- Var
- C : TComponent;
- begin
- C:=TSetComponent.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TSetComponent');
- ExpectBareString('TestTSetComponent');
- ExpectBareString('Throw');
- ExpectValue(vaSet);
- ExpectBareString('two');
- ExpectBareString('five');
- ExpectBareString('');
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTSetComponent2;
- Var
- C : TComponent;
- begin
- C:=TSetComponent2.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TSetComponent2');
- ExpectBareString('TestTSetComponent2');
- ExpectBareString('Throw');
- ExpectValue(vaSet);
- ExpectBareString('');
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTSetComponent3;
- Var
- C : TComponent;
- begin
- C:=TSetComponent3.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TSetComponent3');
- ExpectBareString('TestTSetComponent3');
- ExpectBareString('Throw');
- ExpectValue(vaSet);
- ExpectBareString('one');
- ExpectBareString('four');
- ExpectBareString('');
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTSetComponent4;
- Var
- C : TComponent;
- begin
- C:=TSetComponent4.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TSetComponent4');
- ExpectBareString('TestTSetComponent4');
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTMultipleComponent;
- Var
- C : TComponent;
- begin
- C:=TMultipleComponent.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TMultipleComponent');
- ExpectBareString('TestTMultipleComponent');
- ExpectBareString('IntProp');
- ExpectInteger(1);
- ExpectBareString('StringProp');
- ExpectString('A String');
- ExpectBareString('CurrencyProp');
- ExpectExtended(2.30);
- ExpectBareString('Dice');
- ExpectIdent('two');
- ExpectBareString('Throw');
- ExpectValue(vaSet);
- ExpectBareString('three');
- ExpectBareString('four');
- ExpectBareString('');
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTPersistentComponent;
- Var
- C : TComponent;
- begin
- C:=TPersistentComponent.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TPersistentComponent');
- ExpectBareString('TestTPersistentComponent');
- ExpectBareString('Persist.AInteger');
- ExpectInteger(3);
- ExpectBareString('Persist.AString');
- ExpectString('A persistent string');
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- 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.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;
- Var
- C : TComponent;
- begin
- C:=TOwnedComponent.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TOwnedComponent');
- ExpectBareString('TestTOwnedComponent');
- ExpectBareString('CompProp');
- ExpectIdent('SubComponent');
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTStreamedOwnedComponent;
- Var
- C : TComponent;
- begin
- C:=TStreamedOwnedComponent.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TStreamedOwnedComponent');
- ExpectBareString('TestTStreamedOwnedComponent');
- ExpectEndOfList;
- ExpectFlags([],0);
- ExpectBareString('TIntegerComponent');
- ExpectBareString('Sub');
- ExpectBareString('IntProp');
- ExpectInteger(3);
- ExpectEndOfList;
- ExpectEndOfList;
- ExpectEndOfList;
- ExpectEndOfStream;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTStreamedOwnedComponents;
- Var
- C : TComponent;
- begin
- C:=TStreamedOwnedComponents.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TStreamedOwnedComponents');
- ExpectBareString('TestTStreamedOwnedComponents');
- ExpectEndOfList;
- ExpectFlags([],0);
- ExpectBareString('TIntegerComponent');
- ExpectBareString('SubA');
- ExpectBareString('IntProp');
- ExpectInteger(3);
- ExpectEndOfList;
- ExpectEndOfList;
- ExpectFlags([],0);
- ExpectBareString('TStringComponent');
- ExpectBareString('SubB');
- ExpectBareString('StringProp');
- ExpectString('A string');
- ExpectEndOfList;
- ExpectEndOfList;
- ExpectEndOfList;
- ExpectEndOfStream;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTMethodComponent;
- Var
- C : TComponent;
- begin
- C:=TMethodComponent.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TMethodComponent');
- ExpectBareString('TestTMethodComponent');
- ExpectBareString('MethodProp');
- ExpectIdent('MyMethod');
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- Procedure TTestComponentStream.TestTMethodComponent2;
- Var
- C : TComponent;
- begin
- C:=TMethodComponent2.Create(Nil);
- Try
- SaveToStream(C);
- ExpectSignature;
- ExpectFlags([],0);
- ExpectBareString('TMethodComponent2');
- ExpectBareString('TestTMethodComponent2');
- ExpectEndOfList;
- ExpectFlags([],0);
- ExpectBareString('TMethodComponent');
- ExpectBareString('AComponent');
- ExpectBareString('MethodProp');
- ExpectIdent('MyMethod2');
- ExpectEndOfList;
- ExpectEndOfList;
- ExpectEndOfList;
- Finally
- C.Free;
- end;
- end;
- { TMyColl }
- function TMyColl.GetIt(index : Integer): TMyItem;
- begin
- Result:=Items[Index] as TMyItem;
- end;
- procedure TMyColl.SetIt(index : Integer; const AValue: TMyItem);
- begin
- Items[Index]:=AValue;
- end;
- { TCollComp }
- procedure TCollComp.SetMyColl(const AValue: TMyColl);
- begin
- if (FMyColl=AValue) then
- exit;
- FMyColl.Assign(AValue);
- end;
- constructor TCollComp.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- FMyColl:=TMyCOll.Create(TMyItem);
- end;
- destructor TCollComp.Destroy;
- begin
- FreeAndNil(FMyColl);
- inherited Destroy;
- end;
- function TCollComp.ToStream: TStream;
- begin
- Result:=TMemoryStream.Create;
- Result.WriteComponent(Self);
- Result.Position:=0;
- end;
- procedure TCollComp.FromStream(AStream: TStream);
- begin
- AStream.ReadComponent(Self);
- Astream.Free;
- end;
- procedure TMyItem.Assign(Source: TPersistent);
- Var
- I : TMyItem;
- begin
- If (Source is TMyItem) then
- begin
- I:=Source as TMyItem;
- FNR:=I.NR;
- FStr:=I.Str;
- end
- else
- inherited Assign(Source);
- end;
- Procedure TTestCollectionStream.CompareColl(CA,CB : TMyColl);
- Var
- I : Integer;
- begin
- AssertEquals('Counts differ: %d %d',CA.Count,CB.Count);
- For I:=0 to CA.Count-1 do
- begin
- AssertEquals(Format('Nr property of element %d equals',[I]),CA[i].Nr,CB[i].Nr);
- AssertEquals(Format('Str property of element %d equals',[I]),CA[i].Str,CB[i].Str);
- end;
- end;
- Function TTestCollectionStream.EmptyComp : TCollComp;
- begin
- Result:=TCollComp.Create(Nil);
- end;
- Function TTestCollectionStream.CreateColl(Anr : Integer) : TCollComp;
- Var
- I : Integer;
- T : TMyItem;
- begin
- Result:=EmptyComp;
- Result.Name:='C'+IntToStr(Anr);
- For I:=0 to ANr-1 do
- begin
- T:=Result.MyColl.Add as TMyItem;
- T.Nr:=I; // not I+1, so the default value gets tested too
- T.Str:=IntToStr(I+1);
- end;
- end;
- Procedure TTestCollectionStream.TestEmpty;
- Var
- CA,CB : TCollComp;
- begin
- CA:=CreateColl(0);
- try
- CB:=EmptyComp;
- Try
- CB.FromStream(CA.ToStream);
- CompareColl(CA.MyColl,CB.MyColl);
- Finally
- CB.Free;
- end;
- Finally
- CA.Free;
- end;
- end;
- Procedure TTestCollectionStream.TestNr(ACount : Integer);
- Var
- CA,CB : TCollComp;
- begin
- CA:=CreateColl(ACount);
- try
- CB:=EmptyComp;
- Try
- CB.FromStream(CA.ToStream);
- CompareColl(CA.MyColl,CB.MyColl);
- Finally
- CB.Free;
- end;
- Finally
- CA.Free;
- end;
- end;
- Procedure TTestCollectionStream.TestClear;
- Var
- CA,CB : TCollComp;
- begin
- CA:=CreateColl(3);
- try
- CB:=CreateColl(1);
- CB.Name:='';
- Try
- // CB collection should be cleared before loading.
- CB.FromStream(CA.ToStream);
- CompareColl(CA.MyColl,CB.MyColl);
- Finally
- CB.Free;
- end;
- Finally
- CA.Free;
- end;
- end;
- Procedure TTestCollectionStream.Test1;
- begin
- TestNr(1);
- end;
- Procedure TTestCollectionStream.Test2;
- begin
- TestNr(2);
- end;
- Procedure TTestCollectionStream.Test3;
- begin
- TestNr(3);
- end;
- begin
- RegisterTests([TTestComponentStream,TTestCollectionStream]);
- end.
|