Skip to content

Commit 0d64fd3

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

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

tests/test_slot.cc

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
namespace
1616
{
17+
18+
TestUtilities* util = nullptr;
1719
std::ostringstream result_stream;
1820

1921
class foo
@@ -36,15 +38,8 @@ class foo
3638
}
3739
};
3840

39-
} // end anonymous namespace
40-
41-
int main(int argc, char* argv[])
41+
void test_simple()
4242
{
43-
auto util = TestUtilities::get_instance();
44-
45-
if (!util->check_command_args(argc, argv))
46-
return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
47-
4843
// simple test
4944
sigc::slot<void,int> s1 = foo();
5045
s1(1);
@@ -53,32 +48,62 @@ int main(int argc, char* argv[])
5348
s1 = foo();
5449
s1(2);
5550
util->check_result(result_stream, "foo(int 2)");
51+
}
5652

53+
void test_implicit_conversion()
54+
{
5755
// test implicit conversion
5856
sigc::slot<void,char> s2 = foo();
5957
s2(3);
6058
util->check_result(result_stream, "foo(int 3)");
59+
}
6160

61+
void test_reference()
62+
{
6263
// test reference
6364
sigc::slot<void,std::string&> sl1 = foo();
6465
std::string str("guest book");
6566
sl1(str);
6667
result_stream << str;
6768
util->check_result(result_stream, "foo(string 'guest book') foo was here");
69+
}
6870

71+
void test_operator_equals()
72+
{
6973
// test operator=
70-
str = "guest book";
74+
std::string str = "guest book";
75+
sigc::slot<void,std::string&> sl1 = foo();
7176
sigc::slot<void,std::string&> sl2;
7277
sl2 = sl1;
7378
sl1 = sl2;
7479
sl1(str);
7580
result_stream << str;
7681
util->check_result(result_stream, "foo(string 'guest book') foo was here");
82+
}
7783

84+
void test_copy_ctor()
85+
{
7886
// test copy ctor
87+
sigc::slot<void,int> s1 = foo();
7988
sigc::slot<void,int> s1_clone(s1);
8089
s1_clone(4);
8190
util->check_result(result_stream, "foo(int 4)");
91+
}
92+
93+
} // end anonymous namespace
94+
95+
int main(int argc, char* argv[])
96+
{
97+
util = TestUtilities::get_instance();
98+
99+
if (!util->check_command_args(argc, argv))
100+
return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
101+
102+
test_simple();
103+
test_implicit_conversion();
104+
test_reference();
105+
test_operator_equals();
106+
test_copy_ctor();
82107

83108
return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
84109
}

0 commit comments

Comments
 (0)