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.
24 \brief ClientSocketHandle unit tests */
26 //#include "ClientSocketHandle.test.hh"
27 //#include "ClientSocketHandle.test.ih"
30 #include "SocketPolicy.test.hh"
31 #include "SocketProtocol.test.hh"
32 #include "ClientSocketHandle.hh"
33 #include "AddressingPolicy.hh"
35 #include <senf/Utils/auto_unit_test.hh>
36 #include <boost/test/test_tools.hpp>
39 ///////////////////////////////cc.p////////////////////////////////////////
44 : public senf::ClientSocketHandle<senf::test::SomeSocketProtocol::Policy>
48 : senf::ClientSocketHandle<senf::test::SomeSocketProtocol::Policy>(
49 std::auto_ptr<senf::SocketBody>(
50 new senf::ProtocolSocketBody<senf::test::SomeSocketProtocol>(false)))
56 SENF_AUTO_UNIT_TEST(clientSocketHandle)
58 BOOST_CHECKPOINT("Constructing socket handle");
61 // conversion to other socket handles
63 typedef senf::MakeSocketPolicy<
64 senf::test::SomeFramingPolicy,
65 senf::test::SomeReadPolicy,
66 senf::test::SomeWritePolicy
67 >::policy OtherSocketPolicy;
68 typedef senf::SocketHandle<OtherSocketPolicy> OtherSocketHandle;
70 BOOST_CHECKPOINT("Copy-constructing socket handle");
71 OtherSocketHandle osh (myh);
72 BOOST_CHECKPOINT("Assigning socket handle");
74 typedef senf::ClientSocketHandle<senf::test::SomeSocketProtocol::Policy> SomeSocketHandle;
75 BOOST_CHECKPOINT("static_casting socket handle");
76 SomeSocketHandle ssh =
77 senf::static_socket_cast<SomeSocketHandle>(osh);
78 SENF_CHECK_NO_THROW( senf::dynamic_socket_cast<SomeSocketHandle>(osh) );
79 typedef senf::ClientSocketHandle<senf::MakeSocketPolicy<
81 senf::NoAddressingPolicy
82 >::policy> SomeOtherSocketHandle;
83 BOOST_CHECK_THROW( senf::dynamic_socket_cast<SomeOtherSocketHandle>(osh),
87 // reading and writing
88 SENF_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.read(), "TEST-READ" ) );
90 std::string buf("FOO-BAR");
91 SENF_CHECK_NO_THROW( myh.read(buf,0) );
92 BOOST_CHECK_EQUAL( buf, "TEST-READ" );
96 ::strcpy(buf,"0123456789");
97 SENF_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.read(buf,buf+10), buf+9 ) );
98 BOOST_CHECK_EQUAL( buf, "TEST-READ9" );
101 SENF_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.readfrom().first, "TEST-READ" ) );
103 std::string buf("FOO-BAR");
105 SENF_CHECK_NO_THROW( myh.readfrom(buf,addr,0) );
106 BOOST_CHECK_EQUAL( buf, "TEST-READ" );
111 ::strcpy(buf,"0123456789");
112 SENF_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.readfrom(buf,buf+10,addr), buf+9 ) );
113 BOOST_CHECK_EQUAL( buf, "TEST-READ9" );
117 std::string s ("TEST-WRITE");
118 SENF_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.write(s)-s.begin(), 10 ) );
120 // This simulates a closed file in this test policy. However, we
121 // have changed the semantics so this will not work anymore.
122 // BOOST_CHECK_THROW( myh.write(s),senf::SystemException );
123 char const * const s1 = "TEST-WRITE9";
124 SENF_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.write(s1,s1+10), s1+10u ) );
126 SENF_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.writeto(0,s)-s.begin(), 10 ) );
127 SENF_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.writeto(0,s1,s1+10), s1+10 ) );
130 SENF_CHECK_NO_THROW( myh.connect(0) );
131 SENF_CHECK_NO_THROW( myh.bind(0) );
132 SENF_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.peer(), 1u ) );
133 SENF_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.local(), 2u ) );
136 ///////////////////////////////cc.e////////////////////////////////////////
143 // c-file-style: "senf"
144 // indent-tabs-mode: nil
145 // ispell-local-dictionary: "american"
146 // compile-command: "scons -u test"
147 // comment-column: 40