~ubuntu-branches/ubuntu/trusty/fluxbox/trusty-proposed

« back to all changes in this revision

Viewing changes to src/tests/testSignals.cc

  • Committer: Package Import Robot
  • Author(s): Paul Tagliamonte
  • Date: 2010-08-12 21:16:02 UTC
  • mfrom: (0.1.1) (1.1.10)
  • Revision ID: package-import@ubuntu.com-20100812211602-3tsmzl9in5nmwz7z
Tags: 1.1.1+git20100807.0cc08f9-1
* debian/ dir has been cleaned out, complete repackage
  of most files.
* pulled new archive from git.fluxbox.org HEAD, saved as
  tar.gz.
* Added in fluxbox.* files from the old dfsg tree.
* Added in system.fluxbox-menu file from the old dfsg tree
* Added the source/format file to bump package source
  version from 1.0 to 3.0 (quilt). 
* Changed rules file to match the old dfsg setup so that
  fluxbox behaves nicely.
* Removed entries from copyright that no longer apply.
* Added theme based on Denis Brand ( naran )'s old theme.
* Added a background I whipped up.
* Changed compile flags to point to debian theme by default
* Adding a patch to have fluxbox use x-terminal-emulator
  over xterm. Closes: #591694 (LP: #580485)
* Adding a patch to allow titlebar-window dragging.
* Changed the flags in rules to pull from a script. This script
  lets us un-hardcode what theme is default. Be sure there
  is a theme pack!
* Added comments to my patches.
* Removing debian/docs, empty file.
* Fixing fluxbox.desktop to remove all the warnings from
  desktop-file-validate
* Fixing libtool issue by running an update before
  configure in the rules script.
* Added a compile flag script to auto-detect what platform
  we are running on, and apply the correct theme. This
  should solve Ubuntnu issues later on.
* adding in a get-orig-source rule
* fixing the upstream version number to pinpoint
  the commit ( thanks, lfaraone ).
* adding a rule for get-orig-source. ( thanks again,
  lfaraone ).
* Updated rules to actually allow us to do a build from it
* Removed Denis from the uploaders ( as per an email
  conversation )
* Removing madduck from the uploaders ( thanks for asking,
  lfaraone. ). Thanks for your hard work, madduck.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <iostream>
 
2
using namespace std;
 
3
 
 
4
#include "../FbTk/Signal.hh"
 
5
#include "../FbTk/MemFun.hh"
 
6
#include "../FbTk/RelaySignal.hh"
 
7
#include "../FbTk/Observer.hh"
 
8
#include "../FbTk/Subject.hh"
 
9
 
 
10
#include <string>
 
11
 
 
12
 
 
13
 
 
14
struct NoArgument {
 
15
    void operator() () const {
 
16
        cout << "No Argument." << endl;
 
17
    }
 
18
};
 
19
 
 
20
struct OneArgument {
 
21
    void operator ()( int value ) {
 
22
        cout << "One argument = " << value << endl;
 
23
    }
 
24
};
 
25
 
 
26
struct TwoArguments {
 
27
    template <typename T1, typename T2>
 
28
    void operator ()( const T1& value, const T2& message ) {
 
29
        cout << "Two arguments, (1) = " << value << ", (2) = " << message << endl;
 
30
    }
 
31
};
 
32
 
 
33
struct ThreeArguments {
 
34
    void operator ()( int value, const string& message, double value2 ) {
 
35
        cout << "Two arguments, (1) = " << value << ", (2) = " << message
 
36
             << ", (3) = " << value2 << endl;
 
37
    }
 
38
};
 
39
 
 
40
struct FunctionClass {
 
41
    FunctionClass() {
 
42
        cout << "FunctionClass created." << endl;
 
43
    }
 
44
    ~FunctionClass() {
 
45
        cout << "FunctionClass deleted." << endl;
 
46
    }
 
47
    void print() {
 
48
        cout << "Printing." << endl;
 
49
    }
 
50
 
 
51
    void takeIt( string& str ) {
 
52
        cout << "FunctionClass::takeIt( " << str << " )" << endl;
 
53
    }
 
54
 
 
55
    void showMessage( int value, const string& message ) {
 
56
        cout << "(" << value << "): " << message << endl;
 
57
    }
 
58
    void showMessage2( const string& message1, const string& message2) {
 
59
        cout << "(" << message1 << ", " << message2 << ")" << endl;
 
60
    }
 
61
    void threeArgs( int value, const string& str, double pi ) {
 
62
        cout << "(" << value << "): " << str << ", pi = " << pi << endl;
 
63
    }
 
64
 
 
65
};
 
66
 
 
67
struct Printer {
 
68
    void printInt(int value) {
 
69
        cout << "Int:" << value << endl;
 
70
    }
 
71
    void printString(string value) {
 
72
        cout << "string:" << value << endl;
 
73
    }
 
74
    void printFloat(float value) {
 
75
        cout << "Float:" << value << endl;
 
76
    }
 
77
}; 
 
78
 
 
79
int main() {
 
80
    using FbTk::Signal;
 
81
    using FbTk::SignalTracker;
 
82
 
 
83
    Signal<void> no_arg;
 
84
    no_arg.connect( NoArgument() );
 
85
 
 
86
    Signal<void, int> one_arg;
 
87
    one_arg.connect( OneArgument() );
 
88
 
 
89
    Signal<void, int, const string&> two_args;
 
90
    two_args.connect( TwoArguments() );
 
91
    
 
92
    Signal<void, int, const string&, double> three_args;
 
93
    three_args.connect( ThreeArguments() );
 
94
 
 
95
    // emit test
 
96
    no_arg.emit();
 
97
    one_arg.emit( 10 );
 
98
    two_args.emit( 10, "Message" );
 
99
    three_args.emit( 10, "Three", 3.141592 );
 
100
 
 
101
    // test signal tracker
 
102
    {
 
103
        cout << "---- tracker ----" << endl;
 
104
        SignalTracker tracker;
 
105
        // setup two new slots and track them
 
106
        SignalTracker::TrackID id_no_arg = tracker.join( no_arg, NoArgument() );
 
107
        SignalTracker::TrackID id_one_arg = tracker.join( one_arg, OneArgument() );
 
108
 
 
109
        // two outputs each from these two signals
 
110
        no_arg.emit();
 
111
        one_arg.emit( 31 );
 
112
 
 
113
        // stop tracking id_one_arg, which should keep the slot after this scope,
 
114
        // the id_no_arg connection should be destroyed after this.
 
115
        tracker.leave( id_one_arg );
 
116
        cout << "---- tracker end ----" << endl;
 
117
    }
 
118
 
 
119
    // now we should have one output from no_arg and two outputs from one_arg
 
120
    no_arg.emit();
 
121
    one_arg.emit( 2 );
 
122
 
 
123
    using FbTk::MemFun;
 
124
    FunctionClass obj;
 
125
    no_arg.clear();
 
126
    no_arg.connect(MemFun(obj, &FunctionClass::print));
 
127
    no_arg.emit();
 
128
 
 
129
    string takeThis("Take this");
 
130
    Signal<void, string&> ref_arg;
 
131
    ref_arg.connect(MemFun(obj, &FunctionClass::takeIt));
 
132
    ref_arg.emit( takeThis );
 
133
 
 
134
    two_args.clear();
 
135
    two_args.connect(MemFun(obj, &FunctionClass::showMessage));
 
136
    two_args.emit(10, "This is a message");
 
137
    
 
138
    three_args.clear();
 
139
    three_args.connect(MemFun(obj, &FunctionClass::threeArgs));
 
140
    three_args.emit(9, "nine", 3.141592);
 
141
 
 
142
    // Test ignore signals
 
143
    {
 
144
        cout << "----------- Testing ignoring arguments for signal." << endl;
 
145
        using FbTk::MemFunIgnoreArgs;
 
146
        // Create a signal that emits with three arguments, and connect
 
147
        // sinks that takes less than three arguments.
 
148
        Signal<void, string, string, float> more_args;
 
149
        more_args.connect(MemFunIgnoreArgs(obj, &FunctionClass::print));
 
150
        more_args.connect(MemFunIgnoreArgs(obj, &FunctionClass::takeIt));
 
151
        more_args.connect(MemFunIgnoreArgs(obj, &FunctionClass::showMessage2));
 
152
        more_args.emit("This should be visible for takeIt(string)",
 
153
                       "Visible to the two args function.",
 
154
                       2.9);
 
155
 
 
156
    }
 
157
    // Test relay new signals to old
 
158
    {
 
159
        cout << "---------- Testing relay of signals" << endl;
 
160
        struct Observer: public FbTk::Observer {
 
161
            void update(FbTk::Subject* subj) {
 
162
                cout << "Observer called." << endl;
 
163
            }
 
164
        };
 
165
        // setup old subject->observer listening
 
166
        FbTk::Subject destination;
 
167
        Observer obs;
 
168
        destination.attach(&obs);
 
169
        // create a new signal and relay it to the
 
170
        // old subject
 
171
        FbTk::Signal<void, string> source;
 
172
        FbTk::relaySignal(source, destination);
 
173
        // the new signal should now make the old
 
174
        // subject notify its observers
 
175
        source.emit("hello world");
 
176
    }
 
177
 
 
178
    // Test argument selector
 
179
    {
 
180
        using namespace FbTk;
 
181
        Signal<void, int, string, float> source;
 
182
 
 
183
        Printer printer;
 
184
        source.connect(MemFunSelectArg0(printer, &Printer::printInt));
 
185
        source.connect(MemFunSelectArg1(printer, &Printer::printString));
 
186
        source.connect(MemFunSelectArg2(printer, &Printer::printFloat));
 
187
 
 
188
        source.emit(10, "hello", 3.141592);
 
189
 
 
190
        Signal<void, string, int> source2;
 
191
        source2.connect(MemFunSelectArg0(printer, &Printer::printString));
 
192
        source2.connect(MemFunSelectArg1(printer, &Printer::printInt));
 
193
        source2.emit("world", 37);
 
194
    }
 
195
}