In tests use BOOST_AUTO_UNIT_TEST instead of BOOST_AUTO_TEST_CASE
[metaproxy-moved-to-github.git] / src / test_pipe.cpp
1 /* $Id: test_pipe.cpp,v 1.4 2005-12-02 12:21:07 adam Exp $
2    Copyright (c) 2005, Index Data.
3
4 %LICENSE%
5  */
6
7 #include "config.hpp"
8
9 #include <yaz++/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
22 class Timer : public yazpp_1::ISocketObserver {
23 private:
24     yazpp_1::ISocketObservable *m_obs;
25     yp2::Pipe m_pipe;
26     bool m_timeout;
27 public:
28     Timer(yazpp_1::ISocketObservable *obs, int duration);
29     void socketNotify(int event);
30     bool timeout() { return m_timeout; };
31 };
32
33
34 Timer::Timer(yazpp_1::ISocketObservable *obs,
35                                  int duration) : 
36     m_obs(obs), m_pipe(9122), m_timeout(false)
37 {
38     obs->addObserver(m_pipe.read_fd(), this);
39     obs->maskObserver(this, yazpp_1::SOCKET_OBSERVE_READ);
40     obs->timeoutObserver(this, duration);
41 }
42
43 void Timer::socketNotify(int event)
44 {
45     m_timeout = true;
46     m_obs->deleteObserver(this);
47 }
48
49 BOOST_AUTO_UNIT_TEST( test_pipe_1 )
50 {
51     yazpp_1::SocketManager mySocketManager;
52     
53     Timer t(&mySocketManager, 0);
54
55     while (mySocketManager.processEvent() > 0)
56         if (t.timeout())
57             break;
58     BOOST_CHECK(t.timeout());
59 }
60
61 /*
62  * Local variables:
63  * c-basic-offset: 4
64  * indent-tabs-mode: nil
65  * c-file-style: "stroustrup"
66  * End:
67  * vim: shiftwidth=4 tabstop=8 expandtab
68  */