Add LICENSE file and Refer to it from the source. Include license material
[metaproxy-moved-to-github.git] / src / test_pipe.cpp
1 /* $Id: test_pipe.cpp,v 1.7 2006-06-10 14:29:13 adam Exp $
2    Copyright (c) 2005-2006, Index Data.
3
4    See the LICENSE file for details
5  */
6
7 #include "config.hpp"
8
9 #include <yazpp/socket-manager.h>
10
11 #include <iostream>
12 #include <stdexcept>
13
14 #include "util.hpp"
15 #include "pipe.hpp"
16
17 #define BOOST_AUTO_TEST_MAIN
18 #include <boost/test/auto_unit_test.hpp>
19
20 using namespace boost::unit_test;
21 namespace mp = metaproxy_1;
22
23 class Timer : public yazpp_1::ISocketObserver {
24 private:
25     yazpp_1::ISocketObservable *m_obs;
26     mp::Pipe m_pipe;
27     bool m_timeout;
28 public:
29     Timer(yazpp_1::ISocketObservable *obs, int duration);
30     void socketNotify(int event);
31     bool timeout() { return m_timeout; };
32 };
33
34
35 Timer::Timer(yazpp_1::ISocketObservable *obs,
36                                  int duration) : 
37     m_obs(obs), m_pipe(9122), m_timeout(false)
38 {
39     obs->addObserver(m_pipe.read_fd(), this);
40     obs->maskObserver(this, yazpp_1::SOCKET_OBSERVE_READ);
41     obs->timeoutObserver(this, duration);
42 }
43
44 void Timer::socketNotify(int event)
45 {
46     m_timeout = true;
47     m_obs->deleteObserver(this);
48 }
49
50 BOOST_AUTO_UNIT_TEST( test_pipe_1 )
51 {
52     yazpp_1::SocketManager mySocketManager;
53     
54     Timer t(&mySocketManager, 0);
55
56     while (mySocketManager.processEvent() > 0)
57         if (t.timeout())
58             break;
59     BOOST_CHECK(t.timeout());
60 }
61
62 /*
63  * Local variables:
64  * c-basic-offset: 4
65  * indent-tabs-mode: nil
66  * c-file-style: "stroustrup"
67  * End:
68  * vim: shiftwidth=4 tabstop=8 expandtab
69  */