Skip to content

Commit 334079b

Browse files
committed
test_signal: Test calls to signal_base::clear()
Call it both during signal emission and otherwise. Bug 784550
1 parent abadda4 commit 334079b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/test_signal.cc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,33 @@ void test_std_function_style_syntax()
120120
util->check_result(result_stream, "foo(int 1) ");
121121
}
122122

123+
void test_clear_called_in_signal_handler()
124+
{
125+
sigc::signal<void()> sig;
126+
sig.connect([]() { result_stream << ", slot 1, "; });
127+
sig.connect([&sig]() { sig.clear(); result_stream << "slot 2, "; });
128+
sig.connect([]() { result_stream << "slot 3, "; });
129+
result_stream << sig.size();
130+
sig.emit();
131+
result_stream << sig.size();
132+
sig.emit();
133+
util->check_result(result_stream, "3, slot 1, slot 2, 0");
134+
}
135+
136+
void test_clear_called_outside_signal_handler()
137+
{
138+
sigc::signal<void()> sig;
139+
sig.connect([]() { result_stream << ", slot 1, "; });
140+
sig.connect([]() { result_stream << "slot 2, "; });
141+
sig.connect([]() { result_stream << "slot 3, "; });
142+
result_stream << sig.size();
143+
sig.emit();
144+
sig.clear();
145+
result_stream << sig.size();
146+
sig.emit();
147+
util->check_result(result_stream, "3, slot 1, slot 2, slot 3, 0");
148+
}
149+
123150
} // end anonymous namespace
124151

125152
int main(int argc, char* argv[])
@@ -135,6 +162,8 @@ int main(int argc, char* argv[])
135162
test_reference();
136163
test_make_slot();
137164
test_std_function_style_syntax();
165+
test_clear_called_in_signal_handler();
166+
test_clear_called_outside_signal_handler();
138167

139168
return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
140169
}

0 commit comments

Comments
 (0)