Moved signal interfaces inside records

This commit is contained in:
Michael Schimmel
2025-06-05 23:27:48 +02:00
parent 7ba42b0c7c
commit a57b2d50e4
15 changed files with 316 additions and 313 deletions
+33 -33
View File
@@ -120,7 +120,7 @@ end;
procedure TTestMycLatch.TestCreate_InitialState(InitialCount: Integer; ExpectedIsSet: Boolean);
var
latch: IMycLatch;
latch: TLatch.ILatch;
begin
// TMycLatch.CreateLatch returns TMycLatch.Null if InitialCount <= 0
latch := TLatch.CreateLatch(InitialCount);
@@ -133,11 +133,11 @@ procedure TTestMycLatch.TestNotify_ReturnValueAndState_AfterOneNotify(
ExpectedIsSet: Boolean
);
var
latch: IMycLatch;
latch: TLatch.ILatch;
returnedValueFromNotify: Boolean;
begin
latch := TLatch.CreateLatch(InitialCount);
returnedValueFromNotify := latch.Notify; // This is IMycLatch (as IMycSubscriber).Notify
returnedValueFromNotify := latch.Notify; // This is TLatch.ILatch (as IMycSubscriber).Notify
Assert.AreEqual(
ExpectedReturn,
@@ -153,7 +153,7 @@ end;
procedure TTestMycLatch.TestNotify_DecrementsCounter_StateChanges;
var
latch: IMycLatch;
latch: TLatch.ILatch;
begin
latch := TLatch.CreateLatch(1);
Assert.IsFalse(latch.State.IsSet, 'Latch should initially not be set (Count=1).');
@@ -163,7 +163,7 @@ end;
procedure TTestMycLatch.TestNotify_MultipleNotifies_CounterBecomesNegativeAndStaysSet;
var
latch: IMycLatch;
latch: TLatch.ILatch;
begin
latch := TLatch.CreateLatch(1);
latch.Notify; // Count becomes 0, IsSet = True
@@ -176,9 +176,9 @@ end;
procedure TTestMycLatch.TestSubscriber_Single_IsNotifiedWhenLatchSet;
var
latch: IMycLatch;
latch: TLatch.ILatch;
mockSub: TMockSubscriber;
subscription: TSubscription;
subscription: TSignal.TSubscription;
begin
latch := TLatch.CreateLatch(1);
mockSub := TMockSubscriber.Create;
@@ -195,9 +195,9 @@ end;
procedure TTestMycLatch.TestSubscriber_Multiple_AreNotifiedWhenLatchSet;
var
latch: IMycLatch;
latch: TLatch.ILatch;
mockSub1, mockSub2, mockSub3: TMockSubscriber;
sub1, sub2, sub3: TSubscription; // Keep subscriptions in scope
sub1, sub2, sub3: TSignal.TSubscription; // Keep subscriptions in scope
begin
latch := TLatch.CreateLatch(1);
mockSub1 := TMockSubscriber.Create;
@@ -217,9 +217,9 @@ end;
procedure TTestMycLatch.TestSubscriber_NotNotified_BeforeLatchSet;
var
latch: IMycLatch;
latch: TLatch.ILatch;
mockSub: TMockSubscriber;
subscription: TSubscription;
subscription: TSignal.TSubscription;
begin
latch := TLatch.CreateLatch(2); // Count = 2
mockSub := TMockSubscriber.Create;
@@ -232,9 +232,9 @@ end;
procedure TTestMycLatch.TestSubscriber_NotifiedOnlyOnce_AfterLatchSetAndUnadvised;
var
latch: IMycLatch;
latch: TLatch.ILatch;
mockSub: TMockSubscriber;
subscription: TSubscription;
subscription: TSignal.TSubscription;
begin
latch := TLatch.CreateLatch(1);
mockSub := TMockSubscriber.Create;
@@ -249,9 +249,9 @@ end;
procedure TTestMycLatch.TestSubscribe_ToAlreadySetLatch_NotifiesImmediately;
var
latch: IMycLatch;
latch: TLatch.ILatch;
mockSub1, mockSub2: TMockSubscriber;
subscription1, subscription2: TSubscription;
subscription1, subscription2: TSignal.TSubscription;
begin
latch := TLatch.CreateLatch(1); // Create with count 1
mockSub1 := TMockSubscriber.Create;
@@ -277,9 +277,9 @@ end;
procedure TTestMycLatch.TestChaining_A_Notifies_B;
var
latchA, latchB: IMycLatch;
latchA, latchB: TLatch.ILatch;
mockSubForB: TMockSubscriber;
subHandle_B_listens_A, subHandle_Mock_listens_B: TSubscription;
subHandle_B_listens_A, subHandle_Mock_listens_B: TSignal.TSubscription;
begin
latchA := TLatch.CreateLatch(1);
latchB := TLatch.CreateLatch(1); // latchB is an IMycSubscriber
@@ -302,9 +302,9 @@ end;
procedure TTestMycLatch.TestCascade_A_Notifies_B_Notifies_C;
var
latchA, latchB, latchC: IMycLatch;
latchA, latchB, latchC: TLatch.ILatch;
mockSubForC: TMockSubscriber;
sub_Mock_C, sub_C_B, sub_B_A: TSubscription;
sub_Mock_C, sub_C_B, sub_B_A: TSignal.TSubscription;
begin
latchA := TLatch.CreateLatch(1);
latchB := TLatch.CreateLatch(1);
@@ -325,9 +325,9 @@ end;
procedure TTestMycLatch.TestChaining_B_NeedsMultipleNotifiesFromA_WithSubscriberOnB;
var
latchA, latchB: IMycLatch;
latchA, latchB: TLatch.ILatch;
mockSubForB: TMockSubscriber;
sub_Mock_B, sub_B_A: TSubscription;
sub_Mock_B, sub_B_A: TSignal.TSubscription;
begin
// LatchA needs 2 notifies to become set. LatchB needs 1 notify to become set.
// LatchB subscribes to LatchA. So LatchB will be notified once LatchA becomes set.
@@ -354,9 +354,9 @@ end;
procedure TTestMycLatch.TestInitiallySetLatch_NotifiesNewSubscriberImmediately;
var
latch: IMycLatch; // Will be TMycLatch.Null
latch: TLatch.ILatch; // Will be TMycLatch.Null
mockSub: TMockSubscriber;
subscription: TSubscription;
subscription: TSignal.TSubscription;
begin
latch := TLatch.CreateLatch(0); // Returns TMycLatch.Null which is set.
mockSub := TMockSubscriber.Create;
@@ -369,9 +369,9 @@ end;
procedure TTestMycLatch.TestUnsubscribe_SubscriberNotNotified;
var
latch: IMycLatch;
latch: TLatch.ILatch;
mockSub: TMockSubscriber;
subscription: TSubscription;
subscription: TSignal.TSubscription;
begin
latch := TLatch.CreateLatch(1);
mockSub := TMockSubscriber.Create;
@@ -388,9 +388,9 @@ end;
procedure TTestMycLatch.TestMultipleTriggersNoSubscriber_StateCorrectForLaterSubscriber;
var
latch: IMycLatch;
latch: TLatch.ILatch;
mockSub: TMockSubscriber;
subscription: TSubscription;
subscription: TSignal.TSubscription;
begin
latch := TLatch.CreateLatch(3);
@@ -411,9 +411,9 @@ end;
procedure TTestMycLatch.TestLatchSet_ClearsSubscribers_NoFurtherNotification;
var
latch: IMycLatch;
latch: TLatch.ILatch;
mockSub1, mockSub2: TMockSubscriber;
subscription1, subscription2: TSubscription;
subscription1, subscription2: TSignal.TSubscription;
begin
latch := TLatch.CreateLatch(1);
mockSub1 := TMockSubscriber.Create;
@@ -439,7 +439,7 @@ end;
procedure TTestMycLatch.TestLatchSet_SubscriptionFinalize_IsSafePostUnadviseAll;
var
latch: IMycLatch;
latch: TLatch.ILatch;
mockSub: TMockSubscriber;
// 'subscription' will be declared in an inner scope to control its finalization
begin
@@ -449,7 +449,7 @@ begin
var noException: Boolean := True;
try
begin // Inner block to control lifetime of 'subscription'
var subscription: TSubscription; // Local to this block
var subscription: TSignal.TSubscription; // Local to this block
subscription := latch.State.Subscribe(mockSub);
latch.Notify; // Sets the latch, mockSub is notified, UnadviseAll is called internally.
@@ -475,9 +475,9 @@ end;
procedure TTestMycLatch.TestLatchSet_NewSubscriberToSetLatch_NotifiedImmediatelyButNotPersistedForLatchNotify;
var
latch: IMycLatch;
latch: TLatch.ILatch;
mockSubInitial, mockSubNew: TMockSubscriber;
subscriptionInitial, subscriptionNew: TSubscription;
subscriptionInitial, subscriptionNew: TSignal.TSubscription;
begin
latch := TLatch.CreateLatch(1);
mockSubInitial := TMockSubscriber.Create;