Skip to content

Commit 52e162d

Browse files
author
Oliver Daniell
committed
Added test for moved from signals
1 parent df7cbc0 commit 52e162d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/tests/move_tests.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,31 @@ TEST_CASE( "signals can be move assigned", "[move_tests]" ) {
6666
REQUIRE( ss.str() == "" );
6767
}
6868
}
69+
70+
TEST_CASE("Move assigning signals to with state", "[move_tests") {
71+
using output_signal = nod::signal<void(std::ostream&)>;
72+
output_signal signal_1;
73+
auto connection_1 = signal_1.connect(
74+
[](std::ostream& out){
75+
out << "1";
76+
});
77+
output_signal signal_2;
78+
auto connection_2 = signal_2.connect(
79+
[](std::ostream& out){
80+
out << "2";
81+
});
82+
83+
signal_1 = std::move(signal_2);
84+
85+
SECTION( "The moved-to instance has disconnected it's original connection" ) {
86+
REQUIRE(connection_1.connected() == false);
87+
}
88+
SECTION( "The moved-from instance has moved not disconnected its original connection, it is now owned by the moved-to instance" ) {
89+
REQUIRE(connection_2.connected() == true);
90+
}
91+
SECTION( "Triggering the moved-to signal has expected output" ) {
92+
std::stringstream ss;
93+
signal_1(ss);
94+
REQUIRE(ss.str() == "2");
95+
}
96+
}

0 commit comments

Comments
 (0)