4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 //#include "ClientSocketHandle.test.hh"
26 //#include "ClientSocketHandle.test.ih"
29 #include "SocketPolicy.test.hh"
30 #include "SocketProtocol.test.hh"
31 #include "ClientSocketHandle.hh"
32 #include "AddressingPolicy.hh"
34 #include "../Utils/auto_unit_test.hh"
35 #include <boost/test/test_tools.hpp>
38 ///////////////////////////////cc.p////////////////////////////////////////
43 : public senf::ClientSocketHandle<senf::test::SomeProtocol::Policy>
47 : senf::ClientSocketHandle<senf::test::SomeProtocol::Policy>(
48 std::auto_ptr<senf::SocketBody>(
49 new senf::ProtocolSocketBody<senf::test::SomeProtocol>(false)))
55 BOOST_AUTO_UNIT_TEST(clientSocketHandle)
57 BOOST_CHECKPOINT("Constructing socket handle");
60 // conversion to other socket handles
62 typedef senf::MakeSocketPolicy<
63 senf::test::SomeFramingPolicy,
64 senf::test::SomeReadPolicy,
65 senf::test::SomeWritePolicy
66 >::policy OtherSocketPolicy;
67 typedef senf::SocketHandle<OtherSocketPolicy> OtherSocketHandle;
69 BOOST_CHECKPOINT("Copy-constructing socket handle");
70 OtherSocketHandle osh (myh);
71 BOOST_CHECKPOINT("Assigning socket handle");
73 typedef senf::ClientSocketHandle<senf::test::SomeProtocol::Policy> SomeSocketHandle;
74 BOOST_CHECKPOINT("static_casting socket handle");
75 SomeSocketHandle ssh =
76 senf::static_socket_cast<SomeSocketHandle>(osh);
77 BOOST_CHECK_NO_THROW( senf::dynamic_socket_cast<SomeSocketHandle>(osh) );
78 typedef senf::ClientSocketHandle<senf::MakeSocketPolicy<
80 senf::NoAddressingPolicy
81 >::policy> SomeOtherSocketHandle;
82 BOOST_CHECK_THROW( senf::dynamic_socket_cast<SomeOtherSocketHandle>(osh),
86 // reading and writing
87 BOOST_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.read(), "TEST-READ" ) );
89 std::string buf("FOO-BAR");
90 BOOST_CHECK_NO_THROW( myh.read(buf,0) );
91 BOOST_CHECK_EQUAL( buf, "TEST-READ" );
95 ::strcpy(buf,"0123456789");
96 BOOST_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.read(buf,buf+10), buf+9 ) );
97 BOOST_CHECK_EQUAL( buf, "TEST-READ9" );
100 BOOST_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.readfrom().first, "TEST-READ" ) );
102 std::string buf("FOO-BAR");
104 BOOST_CHECK_NO_THROW( myh.readfrom(buf,addr,0) );
105 BOOST_CHECK_EQUAL( buf, "TEST-READ" );
110 ::strcpy(buf,"0123456789");
111 BOOST_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.readfrom(buf,buf+10,addr), buf+9 ) );
112 BOOST_CHECK_EQUAL( buf, "TEST-READ9" );
116 std::string s ("TEST-WRITE");
117 BOOST_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.write(s)-s.begin(), 10 ) );
119 // This simulates a closed file in this test policy. However, we
120 // have changed the semantics so this will not work anymore.
121 // BOOST_CHECK_THROW( myh.write(s),senf::SystemException );
122 char const * const s1 = "TEST-WRITE9";
123 BOOST_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.write(s1,s1+10), s1+10u ) );
125 BOOST_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.writeto(0,s)-s.begin(), 10 ) );
126 BOOST_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.writeto(0,s1,s1+10), s1+10 ) );
129 BOOST_CHECK_NO_THROW( myh.connect(0) );
130 BOOST_CHECK_NO_THROW( myh.bind(0) );
131 BOOST_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.peer(), 1u ) );
132 BOOST_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.local(), 2u ) );
135 ///////////////////////////////cc.e////////////////////////////////////////
142 // c-file-style: "senf"
143 // indent-tabs-mode: nil
144 // ispell-local-dictionary: "american"
145 // compile-command: "scons -u test"
146 // comment-column: 40