Skip to content

Commit

Permalink
Add a self-blocking connection test
Browse files Browse the repository at this point in the history
In addition to single-shot connections, add a test for reflective
blocking connections.
  • Loading branch information
LeonMatthesKDAB committed Jun 12, 2024
1 parent 22837e0 commit 93d1e7f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/signal/tst_signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,29 @@ TEST_CASE("Signal connections")
REQUIRE(val == 10); // 'val' was incremented once to 10 by the first emit and should remain at 10
}

SUBCASE("Self-blocking connection")
{
Signal<int> mySignal;
int val = 5;

auto handle = mySignal.connectReflective([&val](ConnectionHandle &self, int value) {
val += value;
self.block(true);
});

REQUIRE_FALSE(handle.isBlocked());
mySignal.emit(5);
REQUIRE(val == 10);
REQUIRE(handle.isBlocked());

mySignal.emit(5);
REQUIRE(val == 10);

handle.block(false);
mySignal.emit(5);
REQUIRE(val == 15);
}

SUBCASE("A signal with arguments can be connected to a lambda and invoked with l-value args")
{
Signal<std::string, int> signal;
Expand Down

0 comments on commit 93d1e7f

Please sign in to comment.