1 /* $Id: test_thread_pool_observer.cpp,v 1.5 2005-10-14 10:27:18 adam Exp $
2 Copyright (c) 1998-2005, Index Data.
4 This file is part of the yaz-proxy.
6 YAZ proxy is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
11 YAZ proxy is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with YAZ proxy; see the file LICENSE. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 #include <yaz++/pdu-assoc.h>
27 #include <yaz++/socket-manager.h>
29 #include "thread_pool_observer.hpp"
31 #define BOOST_AUTO_TEST_MAIN
32 #include <boost/test/auto_unit_test.hpp>
34 using namespace boost::unit_test;
35 using namespace yazpp_1;
37 class My_Timer_Thread;
39 class My_Msg : public yp2::IThreadPoolMsg {
41 yp2::IThreadPoolMsg *handle();
44 My_Timer_Thread *m_timer;
47 class My_Timer_Thread : public ISocketObserver {
49 ISocketObservable *m_obs;
51 yp2::ThreadPoolSocketObserver *m_t;
56 My_Timer_Thread(ISocketObservable *obs, yp2::ThreadPoolSocketObserver *t);
57 void socketNotify(int event);
61 yp2::IThreadPoolMsg *My_Msg::handle()
63 My_Msg *res = new My_Msg;
69 res->m_timer = m_timer;
75 m_timer->m_sum += m_val;
76 m_timer->m_responses++;
79 My_Timer_Thread::My_Timer_Thread(ISocketObservable *obs,
80 yp2::ThreadPoolSocketObserver *t) : m_obs(obs)
87 obs->addObserver(m_fd[0], this);
88 obs->maskObserver(this, SOCKET_OBSERVE_READ);
89 obs->timeoutObserver(this, 0);
92 void My_Timer_Thread::socketNotify(int event)
94 My_Msg *m = new My_Msg;
95 m->m_val = m_requests++;
100 BOOST_AUTO_TEST_CASE( thread_pool_observer1 )
102 SocketManager mySocketManager;
104 yp2::ThreadPoolSocketObserver m(&mySocketManager, 3);
105 My_Timer_Thread t(&mySocketManager, &m) ;
106 while (t.m_responses < 30 && mySocketManager.processEvent() > 0)
108 BOOST_CHECK_EQUAL(t.m_responses, 30);
109 BOOST_CHECK(t.m_sum >= 435);
115 * indent-tabs-mode: nil
117 * vim: shiftwidth=4 tabstop=8 expandtab