This commit is contained in:
Michael Schimmel
2025-06-06 01:22:25 +02:00
parent 73d656cda5
commit c4d8607d17
13 changed files with 393 additions and 173 deletions
+16 -16
View File
@@ -137,7 +137,7 @@ end;
procedure TTestMyLazy.TestConstruct_InitialChanged_IsAlwaysTrue;
var
lazyIntf: IMycLazy<Integer>;
lazyIntf: TLazy<Integer>.ILazy;
lazyRec: TLazy<Integer>;
procExecuted: Boolean;
begin
@@ -161,7 +161,7 @@ end;
procedure TTestMyLazy.TestConstruct_FirstPop_SucceedsAndResetsChanged;
var
lazyIntf: IMycLazy<Integer>;
lazyIntf: TLazy<Integer>.ILazy;
lazyRec: TLazy<Integer>;
procExecuted: Boolean;
expectedValue: Integer;
@@ -185,7 +185,7 @@ end;
procedure TTestMyLazy.TestConstruct_StateInteraction_SignalTriggersChanged;
var
lazyIntf: IMycLazy<Integer>;
lazyIntf: TLazy<Integer>.ILazy;
lazyRec: TLazy<Integer>;
expectedValue: Integer;
begin
@@ -203,7 +203,7 @@ end;
procedure TTestMyLazy.TestConstruct_StateInteraction_PopResetsChangedAfterSignal;
var
lazyIntf: IMycLazy<Integer>;
lazyIntf: TLazy<Integer>.ILazy;
lazyRec: TLazy<Integer>;
val: Integer;
popResult: Boolean;
@@ -234,7 +234,7 @@ end;
procedure TTestMyLazy.TestConstruct_StateInteraction_NotifyOnAlreadySetSource_DoesNotRetrigger;
var
lazyIntf: IMycLazy<Integer>;
lazyIntf: TLazy<Integer>.ILazy;
lazyRec: TLazy<Integer>;
val: Integer;
popResult: Boolean;
@@ -280,7 +280,7 @@ end;
procedure TTestMyLazy.TestConstruct_Destruction_UnsubscribesAndNoCrashOnSourceNotify;
var
lazyIntf: IMycLazy<Integer>;
lazyIntf: TLazy<Integer>.ILazy;
localChangingSignal: TFlag.IFlag; // Use a local signal for this test to control its lifetime
begin
localChangingSignal := TFlag.CreateFlag;
@@ -293,7 +293,7 @@ begin
var lazyRec: TLazy<Integer> := lazyIntf; // Wrap for initial pop
ConsumeInitialPop(lazyRec, 1, 'TestConstruct_Destruction (Initial)');
lazyIntf := nil; // Release the IMycLazy interface. ARC should destroy the TMycFuncLazy object.
lazyIntf := nil; // Release the ILazy interface. ARC should destroy the TMycFuncLazy object.
// This should trigger its destructor, which should unsubscribe from localChangingSignal.
Assert.WillNotRaise(
@@ -308,11 +308,11 @@ begin
localChangingSignal := nil; // Clean up the local signal itself.
end;
// == Tests for TLazy<T>.Create with a pre-existing (non-nil) IMycLazy ==
// == Tests for TLazy<T>.Create with a pre-existing (non-nil) ILazy ==
procedure TTestMyLazy.TestCreateWithExistingLazy_DelegatesChangedCorrectly;
var
originalLazyIntf: IMycLazy<Integer>;
originalLazyIntf: TLazy<Integer>.ILazy;
wrappedLazyRec: TLazy<Integer>;
expectedValue: Integer;
begin
@@ -335,7 +335,7 @@ end;
procedure TTestMyLazy.TestCreateWithExistingLazy_DelegatesPopCorrectly;
var
originalLazyIntf: IMycLazy<Integer>;
originalLazyIntf: TLazy<Integer>.ILazy;
wrappedLazyRec: TLazy<Integer>;
val: Integer;
popResult: Boolean;
@@ -376,7 +376,7 @@ end;
procedure TTestMyLazy.TestImplicitOperator_FromInterfaceToRecord;
var
lazyIntf: IMycLazy<Integer>;
lazyIntf: TLazy<Integer>.ILazy;
lazyRec: TLazy<Integer>;
expectedValue: Integer;
begin
@@ -384,7 +384,7 @@ begin
lazyIntf := TLazy<Integer>.Construct(FChangingSignal.State, function: Integer begin Result := expectedValue; end);
Assert.IsNotNull(lazyIntf, 'Interface should be assigned');
lazyRec := lazyIntf; // Implicit conversion: IMycLazy<T> to TLazy<T>
lazyRec := lazyIntf; // Implicit conversion: ILazy<T> to TLazy<T>
// Verify by using the record
Assert.IsTrue(lazyRec.Changed.IsSet, 'Record (from intf): Initial Changed.IsSet should be true');
@@ -393,9 +393,9 @@ end;
procedure TTestMyLazy.TestImplicitOperator_FromRecordToInterface;
var
lazyIntfFromConstruct: IMycLazy<Integer>;
lazyIntfFromConstruct: TLazy<Integer>.ILazy;
lazyRec: TLazy<Integer>;
lazyIntfFromRecord: IMycLazy<Integer>;
lazyIntfFromRecord: TLazy<Integer>.ILazy;
val: Integer;
expectedValue: Integer;
begin
@@ -403,7 +403,7 @@ begin
lazyIntfFromConstruct := TLazy<Integer>.Construct(FChangingSignal.State, function: Integer begin Result := expectedValue; end);
lazyRec.Create(lazyIntfFromConstruct); // Explicitly create record
lazyIntfFromRecord := lazyRec; // Implicit conversion: TLazy<T> to IMycLazy<T>
lazyIntfFromRecord := lazyRec; // Implicit conversion: TLazy<T> to ILazy<T>
// Verify by using the converted interface
Assert.AreSame(lazyIntfFromConstruct, lazyIntfFromRecord, 'Converted interface should be the same as the original wrapped one');
@@ -417,7 +417,7 @@ end;
// == Tests for TLazy<T>.Pop specific behaviors (Res undefined) ==
procedure TTestMyLazy.TestPop_AfterInitialAndNoSignal_ReturnsFalseAndResUndefined;
var
lazyIntf: IMycLazy<Integer>;
lazyIntf: TLazy<Integer>.ILazy;
lazyRec: TLazy<Integer>;
val: Integer; // Value will not be checked as Pop returns false
popResult: Boolean;