aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/Makefile.am2
-rw-r--r--src/tests/signaltest.cc86
-rw-r--r--src/tests/testSignals.cc172
3 files changed, 0 insertions, 260 deletions
diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
index 6b3809d..b6678ce 100644
--- a/src/tests/Makefile.am
+++ b/src/tests/Makefile.am
@@ -3,7 +3,6 @@ AM_CPPFLAGS= -I$(top_srcdir)/src
3noinst_PROGRAMS= \ 3noinst_PROGRAMS= \
4 testTexture \ 4 testTexture \
5 testFont \ 5 testFont \
6 testSignals \
7 testKeys \ 6 testKeys \
8 testDemandAttention \ 7 testDemandAttention \
9 testFullscreen \ 8 testFullscreen \
@@ -12,7 +11,6 @@ noinst_PROGRAMS= \
12 11
13testTexture_SOURCES = texturetest.cc 12testTexture_SOURCES = texturetest.cc
14testFont_SOURCES = testFont.cc 13testFont_SOURCES = testFont.cc
15testSignals_SOURCES = testSignals.cc
16testKeys_SOURCES = testKeys.cc 14testKeys_SOURCES = testKeys.cc
17testDemandAttention_SOURCES = testDemandAttention.cc 15testDemandAttention_SOURCES = testDemandAttention.cc
18#testResource_SOURCES = Resourcetest.cc 16#testResource_SOURCES = Resourcetest.cc
diff --git a/src/tests/signaltest.cc b/src/tests/signaltest.cc
deleted file mode 100644
index 09ebdac..0000000
--- a/src/tests/signaltest.cc
+++ /dev/null
@@ -1,86 +0,0 @@
1// signaltest.cc for testing signal handler in fluxbox
2// Copyright (c) 2002 - 2006 Henrik Kinnunen (fluxgen at fluxbox dot org)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22#include "../FbTk/SignalHandler.hh"
23
24#include <iostream>
25#ifdef HAVE_CASSERT
26 #include <cassert>
27#else
28 #include <assert.h>
29#endif
30
31using namespace std;
32using namespace FbTk;
33
34class IntSig:public SignalEventHandler {
35public:
36 void handleSignal(int signum) {
37 assert(signum == SIGINT);
38 cerr<<"Signal SIGINT!"<<endl;
39 exit(0);
40 }
41};
42
43class AllSig:public SignalEventHandler {
44public:
45 void handleSignal(int signum) {
46 switch (signum) {
47 case SIGSEGV:
48 cerr<<"SIGSEGV";
49 break;
50 case SIGTERM:
51 cerr<<"SIGTERM";
52 break;
53 case SIGUSR1:
54 cerr<<"SIGUSR1";
55 break;
56 case SIGUSR2:
57 cerr<<"SIGUSR2";
58 break;
59 default:
60 cerr<<"signum = "<<signum;
61 }
62 cerr<<endl;
63 if (signum == SIGTERM)
64 exit(1); // end program
65 }
66};
67
68int main(int argc, char **argv) {
69 SignalHandler &sigh = SignalHandler::instance();
70
71 IntSig handler;
72 AllSig allhand;
73
74 sigh.registerHandler(SIGINT, &handler);
75 sigh.registerHandler(SIGSEGV, &allhand);
76 sigh.registerHandler(SIGTERM, &allhand);
77 sigh.registerHandler(SIGUSR1, &allhand);
78 sigh.registerHandler(SIGUSR2, &allhand);
79
80 cerr<<"Send signals to me :)"<<endl;
81 while (1) {
82
83 }
84}
85
86
diff --git a/src/tests/testSignals.cc b/src/tests/testSignals.cc
deleted file mode 100644
index d316a62..0000000
--- a/src/tests/testSignals.cc
+++ /dev/null
@@ -1,172 +0,0 @@
1#include <iostream>
2using namespace std;
3
4#include "../FbTk/Signal.hh"
5#include "../FbTk/MemFun.hh"
6
7#include <string>
8
9
10
11struct NoArgument {
12 void operator() () const {
13 cout << "No Argument." << endl;
14 }
15};
16
17struct OneArgument {
18 void operator ()( int value ) {
19 cout << "One argument = " << value << endl;
20 }
21};
22
23struct TwoArguments {
24 template <typename T1, typename T2>
25 void operator ()( const T1& value, const T2& message ) {
26 cout << "Two arguments, (1) = " << value << ", (2) = " << message << endl;
27 }
28};
29
30struct ThreeArguments {
31 void operator ()( int value, const string& message, double value2 ) {
32 cout << "Two arguments, (1) = " << value << ", (2) = " << message
33 << ", (3) = " << value2 << endl;
34 }
35};
36
37struct FunctionClass {
38 FunctionClass() {
39 cout << "FunctionClass created." << endl;
40 }
41 ~FunctionClass() {
42 cout << "FunctionClass deleted." << endl;
43 }
44 void print() {
45 cout << "Printing." << endl;
46 }
47
48 void takeIt( string& str ) {
49 cout << "FunctionClass::takeIt( " << str << " )" << endl;
50 }
51
52 void showMessage( int value, const string& message ) {
53 cout << "(" << value << "): " << message << endl;
54 }
55 void showMessage2( const string& message1, const string& message2) {
56 cout << "(" << message1 << ", " << message2 << ")" << endl;
57 }
58 void threeArgs( int value, const string& str, double pi ) {
59 cout << "(" << value << "): " << str << ", pi = " << pi << endl;
60 }
61
62};
63
64struct Printer {
65 void printInt(int value) {
66 cout << "Int:" << value << endl;
67 }
68 void printString(string value) {
69 cout << "string:" << value << endl;
70 }
71 void printFloat(float value) {
72 cout << "Float:" << value << endl;
73 }
74};
75
76int main() {
77 using FbTk::Signal;
78 using FbTk::SignalTracker;
79
80 Signal<> no_arg;
81 no_arg.connect( NoArgument() );
82
83 Signal<int> one_arg;
84 one_arg.connect( OneArgument() );
85
86 Signal<int, const string&> two_args;
87 two_args.connect( TwoArguments() );
88
89 Signal<int, const string&, double> three_args;
90 three_args.connect( ThreeArguments() );
91
92 // emit test
93 no_arg.emit();
94 one_arg.emit( 10 );
95 two_args.emit( 10, "Message" );
96 three_args.emit( 10, "Three", 3.141592 );
97
98 // test signal tracker
99 {
100 cout << "---- tracker ----" << endl;
101 SignalTracker tracker;
102 // setup two new slots and track them
103 SignalTracker::TrackID id_no_arg = tracker.join( no_arg, NoArgument() );
104 SignalTracker::TrackID id_one_arg = tracker.join( one_arg, OneArgument() );
105
106 // two outputs each from these two signals
107 no_arg.emit();
108 one_arg.emit( 31 );
109
110 // stop tracking id_one_arg, which should keep the slot after this scope,
111 // the id_no_arg connection should be destroyed after this.
112 tracker.leave( id_one_arg );
113 cout << "---- tracker end ----" << endl;
114 }
115
116 // now we should have one output from no_arg and two outputs from one_arg
117 no_arg.emit();
118 one_arg.emit( 2 );
119
120 using FbTk::MemFun;
121 FunctionClass obj;
122 no_arg.clear();
123 no_arg.connect(MemFun(obj, &FunctionClass::print));
124 no_arg.emit();
125
126 string takeThis("Take this");
127 Signal<string&> ref_arg;
128 ref_arg.connect(MemFun(obj, &FunctionClass::takeIt));
129 ref_arg.emit( takeThis );
130
131 two_args.clear();
132 two_args.connect(MemFun(obj, &FunctionClass::showMessage));
133 two_args.emit(10, "This is a message");
134
135 three_args.clear();
136 three_args.connect(MemFun(obj, &FunctionClass::threeArgs));
137 three_args.emit(9, "nine", 3.141592);
138
139 // Test ignore signals
140 {
141 cout << "----------- Testing ignoring arguments for signal." << endl;
142 using FbTk::MemFunIgnoreArgs;
143 // Create a signal that emits with three arguments, and connect
144 // sinks that takes less than three arguments.
145 Signal<string, string, float> more_args;
146 more_args.connect(MemFunIgnoreArgs(obj, &FunctionClass::print));
147 more_args.connect(MemFunIgnoreArgs(obj, &FunctionClass::takeIt));
148 more_args.connect(MemFunIgnoreArgs(obj, &FunctionClass::showMessage2));
149 more_args.emit("This should be visible for takeIt(string)",
150 "Visible to the two args function.",
151 2.9);
152
153 }
154
155 // Test argument selector
156 {
157 using namespace FbTk;
158 Signal<int, string, float> source;
159
160 Printer printer;
161 source.connect(MemFunSelectArg0(printer, &Printer::printInt));
162 source.connect(MemFunSelectArg1(printer, &Printer::printString));
163 source.connect(MemFunSelectArg2(printer, &Printer::printFloat));
164
165 source.emit(10, "hello", 3.141592);
166
167 Signal<string, int> source2;
168 source2.connect(MemFunSelectArg0(printer, &Printer::printString));
169 source2.connect(MemFunSelectArg1(printer, &Printer::printInt));
170 source2.emit("world", 37);
171 }
172}