1 // Eris Online RPG Protocol Library
2 // Copyright (C) 2011 Alistair Riddoch
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software Foundation,
16 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 
18 // $Id$
19 
20 #ifdef NDEBUG
21 #undef NDEBUG
22 #endif
23 #ifndef DEBUG
24 #define DEBUG
25 #endif
26 
27 #include <Eris/TimedEventService.h>
28 
29 #include <sigc++/functors/mem_fun.h>
30 
31 #include <cassert>
32 
33 class TestSignalTracker
34 {
35   protected:
36     bool m_called;
37   public:
TestSignalTracker()38     TestSignalTracker() : m_called(false) { }
39 
called() const40     bool called() const { return m_called; }
41 
call()42     void call() { m_called = true; }
43 };
44 
main()45 int main()
46 {
47     {
48         Eris::TimedEventService * ted = Eris::TimedEventService::instance();
49 
50         assert(ted != 0);
51 
52         Eris::TimedEventService::del();
53     }
54 
55     {
56         Eris::TimedEventService * ted = Eris::TimedEventService::instance();
57 
58         assert(ted != 0);
59         ted->Idle.emit();
60 
61         Eris::TimedEventService::del();
62     }
63 
64     {
65         TestSignalTracker tst;
66         assert(!tst.called());
67 
68         Eris::TimedEventService * ted = Eris::TimedEventService::instance();
69         assert(ted != 0);
70 
71         ted->Idle.emit();
72         assert(!tst.called());
73 
74         ted->Idle.connect(sigc::mem_fun(tst, &TestSignalTracker::call));
75         assert(!tst.called());
76 
77         ted->Idle.emit();
78         assert(tst.called());
79 
80         Eris::TimedEventService::del();
81     }
82 
83     {
84         TestSignalTracker tst;
85 
86         Eris::TimedEventService * ted = Eris::TimedEventService::instance();
87 
88         ted->Idle.connect(sigc::mem_fun(tst, &TestSignalTracker::call));
89 
90         ted->tick();
91         assert(!tst.called());
92 
93         Eris::TimedEventService::del();
94     }
95 
96     {
97         TestSignalTracker tst;
98 
99         Eris::TimedEventService * ted = Eris::TimedEventService::instance();
100 
101         ted->Idle.connect(sigc::mem_fun(tst, &TestSignalTracker::call));
102 
103         ted->tick(true);
104         assert(tst.called());
105 
106         Eris::TimedEventService::del();
107     }
108 
109     return 0;
110 }
111 
112 // stubs
113 
114 #include <Eris/Poll.h>
115 
116 bool Eris::Poll::new_timeout_ = false;
117