From: Adam Dickmeiss Date: Thu, 13 Oct 2005 12:28:55 +0000 (+0000) Subject: Added test_package1 X-Git-Tag: YP2.0.0.2~219 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=c3c716e784b76e911dcb43cff74fa11af6d8853b;p=metaproxy-moved-to-github.git Added test_package1 --- diff --git a/src/Makefile.am b/src/Makefile.am index 0f2d0c7..229a720 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,20 +1,23 @@ -## $Id: Makefile.am,v 1.15 2005-10-12 23:30:43 adam Exp $ - -MAINTAINERCLEANFILES = Makefile.in config.in config.hpp +## $Id: Makefile.am,v 1.16 2005-10-13 12:28:55 adam Exp $ +MAINTAINERCLEANFILES = Makefile.in config.in config.hpp AM_CXXFLAGS = $(YAZPPINC) $(XSLT_CFLAGS) YP2_INCHPP = session.hpp package.hpp filter.hpp router.hpp bin_PROGRAMS = -check_PROGRAMS = test_filter1 test_filter2 \ - test_session1 test_session2 \ - test_thread_pool_observer test_boost_threads test_boost_time +check_PROGRAMS = \ + test_package1 \ + test_filter1 test_filter2 \ + test_session1 test_session2 \ + test_thread_pool_observer \ + test_boost_threads test_boost_time noinst_PROGRAMS = p2 TESTS=$(check_PROGRAMS) +test_package1_SOURCES=test_package1.cpp $(YP2_INCHPP) test_filter1_SOURCES=test_filter1.cpp $(YP2_INCHPP) test_filter2_SOURCES=test_filter2.cpp $(YP2_INCHPP) test_session1_SOURCES=test_session1.cpp $(YP2_INCHPP) @@ -33,14 +36,16 @@ p2_SOURCES=p2_frontend.cpp p2_msg.cpp p2.cpp p2_frontend.h \ LDADD= $(YAZPPLALIB) $(XSLT_LIBS) - -test_filter1_LDADD = $(LDADD) -lboost_unit_test_framework -test_filter2_LDADD = $(LDADD) -lboost_unit_test_framework -test_session1_LDADD = $(LDADD) -lboost_unit_test_framework -test_session2_LDADD = $(LDADD) -lboost_unit_test_framework -test_boost_threads_LDADD = $(LDADD) -lboost_unit_test_framework -test_boost_time_LDADD = $(LDADD) -lboost_unit_test_framework -test_thread_pool_observer_LDADD = $(LDADD) -lboost_unit_test_framework +TLDADD = $(LDADD) -lboost_unit_test_framework + +test_filter1_LDADD = $(TLDADD) +test_filter2_LDADD = $(TLDADD) +test_session1_LDADD = $(TLDADD) +test_session2_LDADD = $(TLDADD) +test_boost_threads_LDADD = $(TLDADD) +test_boost_time_LDADD = $(TLDADD) +test_thread_pool_observer_LDADD = $(TLDADD) +test_package1_LDADD = $(TLDADD) # doxygen target dox: diff --git a/src/package.hpp b/src/package.hpp index eaa370d..719aaf5 100644 --- a/src/package.hpp +++ b/src/package.hpp @@ -5,6 +5,8 @@ #include #include +#include "router.hpp" +#include "filter.hpp" #include "session.hpp" namespace yp2 { @@ -17,97 +19,81 @@ namespace yp2 { } type; std::string address; // UNIX+TCPIP int port; // TCPIP only + public: + Origin() : type(API) {}; }; class Package { public: - - - Package(yp2::Session &session, yp2::Origin &origin) - : m_session(session), m_origin(origin), - m_filter(0), m_router(0), m_data(0) {} - - /// send Package to it's next Filter defined in Router - Package & move() { - m_filter = m_router->move(m_filter, this); - if (m_filter) - return m_filter->process(*this); - else - return *this; - } - - - /// access session - left val in assignment - yp2::Session & session() { - return m_session; - } - - /// get function - right val in assignment - unsigned int data() const { - return m_data; - } - - /// set function - left val in assignment - unsigned int & data() { - return m_data; - } - - /// set function - can be chained - Package & data(const unsigned int & data){ - m_data = data; - return *this; - } - - - /// get function - right val in assignment - Origin origin() const { - return m_origin; - } - - /// set function - left val in assignment - Origin & origin() { - return m_origin; - } - - /// set function - can be chained - Package & origin(const Origin & origin){ - m_origin = origin; - return *this; - } - - - //Router router() const { - // return m_router; - //} - - //Router & router() { - // return m_router; - //} - - /// set function - can be chained - Package & router(const Router &router){ - m_filter = 0; - m_router = &router; - return *this; - } - - - private: - Session m_session; -// unsigned long int m_session_id; -// bool m_session_close; - Origin m_origin; - - const Filter *m_filter; - const Router *m_router; - unsigned int m_data; - - yazpp_1::GDU m_request_gdu; - yazpp_1::GDU m_response_gdu; - }; - - - + + Package(yp2::Session &session, yp2::Origin &origin) + : m_session(session), m_origin(origin), + m_filter(0), m_router(0), m_data(0) {} + + /// send Package to it's next Filter defined in Router + Package & move() { + m_filter = m_router->move(m_filter, this); + if (m_filter) + return m_filter->process(*this); + else + return *this; + } + + /// access session - left val in assignment + yp2::Session & session() { + return m_session; + } + + /// get function - right val in assignment + unsigned int data() const { + return m_data; + } + + /// set function - left val in assignment + unsigned int & data() { + return m_data; + } + + /// set function - can be chained + Package & data(const unsigned int & data){ + m_data = data; + return *this; + } + + + /// get function - right val in assignment + Origin origin() const { + return m_origin; + } + + /// set function - left val in assignment + Origin & origin() { + return m_origin; + } + + /// set function - can be chained + Package & origin(const Origin & origin){ + m_origin = origin; + return *this; + } + + Package & router(const Router &router){ + m_filter = 0; + m_router = &router; + return *this; + } + + private: + Session m_session; + Origin m_origin; + + const Filter *m_filter; + const Router *m_router; + unsigned int m_data; + + yazpp_1::GDU m_request_gdu; + yazpp_1::GDU m_response_gdu; + }; } #endif diff --git a/src/session.hpp b/src/session.hpp index 08301a7..9667a17 100644 --- a/src/session.hpp +++ b/src/session.hpp @@ -7,24 +7,31 @@ #include namespace yp2 { - + class Session { //typedef unsigned long type; public: - - /// create new session with new unique id - Session() { + + /// create new session with new unique id + Session() { boost::mutex::scoped_lock scoped_lock(m_mutex); ++m_global_id; m_id = m_global_id; m_close = false; }; - - /// copy session including old id - Session(const Session &s) : m_id(s.m_id), m_close(s.m_close) {}; - - //Session& operator=(const Session &); + + /// copy session including old id + Session(const Session &s) : m_id(s.m_id), m_close(s.m_close) {}; + + Session& operator=(const Session &s) { + if (this != &s) + { + m_id = s.m_id; + m_close = s.m_close; + } + return *this; + } unsigned long id() const { return m_id; @@ -33,17 +40,17 @@ namespace yp2 { bool is_closed() const { return m_close; }; - + /// mark session closed, can not be unset void close() { m_close = true; }; - - private: - + + private: + unsigned long int m_id; bool m_close; - + /// static mutex to lock static m_id static boost::mutex m_mutex; diff --git a/src/test_package1.cpp b/src/test_package1.cpp new file mode 100644 index 0000000..ba652ea --- /dev/null +++ b/src/test_package1.cpp @@ -0,0 +1,35 @@ + +#include "config.hpp" +#include +#include + +#include "package.hpp" + +#define BOOST_AUTO_TEST_MAIN +#include + +using namespace boost::unit_test; + +BOOST_AUTO_TEST_CASE( test_package1_1 ) +{ + try { + yp2::Origin origin; + yp2::Session session; + yp2::Package package1(session, origin); + + yp2::Package package2(package1.session(), origin); + + BOOST_CHECK_EQUAL(package1.session().id(), package2.session().id()); + } + catch ( ... ) { + BOOST_CHECK (false); + } +} + +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */