~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to src/tests/testEventLoop.cc

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2010-05-04 11:15:49 UTC
  • mfrom: (1.3.1 upstream)
  • mto: (20.3.1 squeeze) (21.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20100504111549-1apjh2g5sndki4te
Tags: upstream-3.1.3
ImportĀ upstreamĀ versionĀ 3.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include "config.h"
 
2
 
2
3
#include <cppunit/TestAssert.h>
3
4
 
4
 
#include "AsyncEngine.h"
5
 
#include "CompletionDispatcher.h"
6
 
#include "Mem.h"
7
5
#include "testEventLoop.h"
8
6
#include "EventLoop.h"
 
7
#include "Mem.h"
 
8
 
 
9
#if 0
 
10
#include "AsyncEngine.h"
 
11
#include "base/AsyncCallQueue.h"
9
12
#include "event.h"
10
 
 
 
13
#endif
11
14
 
12
15
CPPUNIT_TEST_SUITE_REGISTRATION( testEventLoop );
13
16
 
40
43
    EventLoop();
41
44
}
42
45
 
 
46
#if POLISHED_MAIN_LOOP
43
47
 
44
48
/*
45
 
 * Running the loop once is useful for integration with other loops, such as 
 
49
 * Running the loop once is useful for integration with other loops, such as
46
50
 * migrating to it in incrementally.
47
51
 *
48
52
 * This test works by having a custom dispatcher and engine which record how
54
58
 
55
59
public:
56
60
    int calls;
57
 
    RecordDispatcher(): calls(0)
58
 
    {}
 
61
    RecordDispatcher(): calls(0) {}
59
62
 
60
 
    bool dispatch()
61
 
    {
 
63
    bool dispatch() {
62
64
        ++calls;
63
65
        /* claim we dispatched calls to be useful for the testStopOnIdle test.
64
66
         */
66
68
    }
67
69
};
68
70
 
 
71
#endif /* POLISHED_MAIN_LOOP */
 
72
 
69
73
class RecordingEngine : public AsyncEngine
70
74
{
71
75
 
74
78
    int lasttimeout;
75
79
    int return_timeout;
76
80
    RecordingEngine(int return_timeout=0): calls(0), lasttimeout(0),
77
 
            return_timeout(return_timeout)
78
 
          {}
79
 
 
80
 
          virtual int checkEvents(int timeout)
81
 
          {
82
 
              ++calls;
83
 
              lasttimeout = timeout;
84
 
              return return_timeout;
85
 
          }
86
 
      };
 
81
            return_timeout(return_timeout) {}
 
82
 
 
83
    virtual int checkEvents(int timeout) {
 
84
        ++calls;
 
85
        lasttimeout = timeout;
 
86
        return return_timeout;
 
87
    }
 
88
};
 
89
 
 
90
#if POLISHED_MAIN_LOOP
87
91
 
88
92
void
89
93
testEventLoop::testRunOnce()
115
119
public:
116
120
    EventLoop &theLoop;
117
121
    int calls;
118
 
    ShutdownDispatcher(EventLoop & theLoop):theLoop(theLoop), calls(0)
119
 
    {}
 
122
    ShutdownDispatcher(EventLoop & theLoop):theLoop(theLoop), calls(0) {}
120
123
 
121
 
    bool dispatch()
122
 
    {
 
124
    bool dispatch() {
123
125
        if (++calls == 2)
124
126
            theLoop.stop();
125
127
 
224
226
    CPPUNIT_ASSERT_EQUAL(false, theLoop.runOnce());
225
227
}
226
228
 
 
229
#endif /* POLISHED_MAIN_LOOP */
 
230
 
227
231
/* An event loop has a time service which is like an async engine but never
228
232
 * generates events and there can only be one such service.
229
233
 */
235
239
    StubTime() : calls(0) {}
236
240
 
237
241
    int calls;
238
 
    void tick()
239
 
    {
 
242
    void tick() {
240
243
        ++calls;
241
244
    }
242
245
};
270
273
    /* one engine - gets a timeout */
271
274
    theLoop.registerEngine(&first_engine);
272
275
    theLoop.runOnce();
273
 
    CPPUNIT_ASSERT_EQUAL(10, first_engine.lasttimeout);
 
276
    CPPUNIT_ASSERT_EQUAL(EVENT_LOOP_TIMEOUT, first_engine.lasttimeout);
274
277
    /* two engines - the second gets the timeout */
275
278
    theLoop.registerEngine(&second_engine);
276
279
    theLoop.runOnce();
281
284
    theLoop.runOnce();
282
285
    CPPUNIT_ASSERT_EQUAL(10, first_engine.lasttimeout);
283
286
    CPPUNIT_ASSERT_EQUAL(0, second_engine.lasttimeout);
284
 
 
285
287
}