diff options
Diffstat (limited to 'src/tests/testSignals.cc')
-rw-r--r-- | src/tests/testSignals.cc | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/tests/testSignals.cc b/src/tests/testSignals.cc index 86096bf..6d68d3a 100644 --- a/src/tests/testSignals.cc +++ b/src/tests/testSignals.cc | |||
@@ -21,7 +21,8 @@ struct OneArgument { | |||
21 | }; | 21 | }; |
22 | 22 | ||
23 | struct TwoArguments { | 23 | struct TwoArguments { |
24 | void operator ()( int value, const string& message ) { | 24 | template <typename T1, typename T2> |
25 | void operator ()( const T1& value, const T2& message ) { | ||
25 | cout << "Two arguments, (1) = " << value << ", (2) = " << message << endl; | 26 | cout << "Two arguments, (1) = " << value << ", (2) = " << message << endl; |
26 | } | 27 | } |
27 | }; | 28 | }; |
@@ -51,6 +52,9 @@ struct FunctionClass { | |||
51 | void showMessage( int value, const string& message ) { | 52 | void showMessage( int value, const string& message ) { |
52 | cout << "(" << value << "): " << message << endl; | 53 | cout << "(" << value << "): " << message << endl; |
53 | } | 54 | } |
55 | void showMessage2( const string& message1, const string& message2) { | ||
56 | cout << "(" << message1 << ", " << message2 << ")" << endl; | ||
57 | } | ||
54 | void threeArgs( int value, const string& str, double pi ) { | 58 | void threeArgs( int value, const string& str, double pi ) { |
55 | cout << "(" << value << "): " << str << ", pi = " << pi << endl; | 59 | cout << "(" << value << "): " << str << ", pi = " << pi << endl; |
56 | } | 60 | } |
@@ -118,4 +122,21 @@ int main() { | |||
118 | three_args.clear(); | 122 | three_args.clear(); |
119 | three_args.connect(MemFun(obj, &FunctionClass::threeArgs)); | 123 | three_args.connect(MemFun(obj, &FunctionClass::threeArgs)); |
120 | three_args.emit(9, "nine", 3.141592); | 124 | three_args.emit(9, "nine", 3.141592); |
125 | |||
126 | // Test ignore signals | ||
127 | { | ||
128 | cout << "----------- Testing ignoring arguments for signal." << endl; | ||
129 | using FbTk::MemFunIgnoreArgs; | ||
130 | // Create a signal that emits with three arguments, and connect | ||
131 | // sinks that takes less than three arguments. | ||
132 | Signal<void, string, string, float> more_args; | ||
133 | more_args.connect(MemFunIgnoreArgs(obj, &FunctionClass::print)); | ||
134 | more_args.connect(MemFunIgnoreArgs(obj, &FunctionClass::takeIt)); | ||
135 | more_args.connect(MemFunIgnoreArgs(obj, &FunctionClass::showMessage2)); | ||
136 | more_args.emit("This should be visible for takeIt(string)", | ||
137 | "Visible to the two args function.", | ||
138 | 2.9); | ||
139 | |||
140 | } | ||
141 | |||
121 | } | 142 | } |