Skip to content

Commit 109409f

Browse files
committed
test_signal(): Restructure this.
To make it clearer and to keep the small tests more self-contained and separate.
1 parent 0d64fd3 commit 109409f

File tree

1 file changed

+40
-14
lines changed

1 file changed

+40
-14
lines changed

tests/test_signal.cc

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
namespace
1515
{
16+
17+
TestUtilities* util = nullptr;
1618
std::ostringstream result_stream;
1719

1820
int foo(int i)
@@ -21,12 +23,6 @@ int foo(int i)
2123
return 1;
2224
}
2325

24-
int bar(float i)
25-
{
26-
result_stream << "bar(float " << i << ") ";
27-
return 1;
28-
}
29-
3026
struct A : public sigc::trackable
3127
{
3228
int foo(int i)
@@ -42,21 +38,26 @@ struct A : public sigc::trackable
4238
}
4339
};
4440

45-
} // end anonymous namespace
46-
47-
int main(int argc, char* argv[])
41+
void test_empty_signal()
4842
{
49-
auto util = TestUtilities::get_instance();
50-
51-
if (!util->check_command_args(argc, argv))
52-
return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
53-
5443
// signal
5544
sigc::signal<int,int> sig;
5645

5746
// emit empty signal
5847
sig(0);
5948
util->check_result(result_stream, "");
49+
}
50+
51+
int bar(float i)
52+
{
53+
result_stream << "bar(float " << i << ") ";
54+
return 1;
55+
}
56+
57+
void test_auto_disconnection()
58+
{
59+
// signal
60+
sigc::signal<int,int> sig;
6061

6162
// connect some slots before emitting & test auto-disconnection
6263
{
@@ -73,7 +74,10 @@ int main(int argc, char* argv[])
7374
sig(2);
7475
result_stream << sig.size();
7576
util->check_result(result_stream, "foo(int 2) bar(float 2) 2");
77+
}
7678

79+
void test_reference()
80+
{
7781
// test reference
7882
A a;
7983
std::string str("guest book");
@@ -82,13 +86,35 @@ int main(int argc, char* argv[])
8286
sigstr(str);
8387
result_stream << str;
8488
util->check_result(result_stream, "A::foo(string 'guest book') foo was here");
89+
}
8590

91+
void test_make_slot()
92+
{
8693
// test make_slot()
94+
sigc::signal<int,int> sig;
8795
sig.connect(sigc::ptr_fun1(&foo));
96+
sig.connect(sigc::ptr_fun(&bar));
97+
sig.connect(sigc::ptr_fun(&foo));
98+
8899
sigc::signal<int,int> sig2;
89100
sig2.connect(sig.make_slot());
90101
sig2(3);
91102
util->check_result(result_stream, "foo(int 3) bar(float 3) foo(int 3) ");
103+
}
104+
105+
} // end anonymous namespace
106+
107+
int main(int argc, char* argv[])
108+
{
109+
util = TestUtilities::get_instance();
110+
111+
if (!util->check_command_args(argc, argv))
112+
return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
113+
114+
test_empty_signal();
115+
test_auto_disconnection();
116+
test_reference();
117+
test_make_slot();
92118

93119
return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
94120
}

0 commit comments

Comments
 (0)