4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief ClientSocketHandle unit tests */
31 //#include "ClientSocketHandle.test.hh"
32 //#include "ClientSocketHandle.test.ih"
35 #include "SocketPolicy.test.hh"
36 #include "SocketProtocol.test.hh"
37 #include "ClientSocketHandle.hh"
38 #include "AddressingPolicy.hh"
40 #include <senf/Utils/auto_unit_test.hh>
41 #include <boost/test/test_tools.hpp>
44 //-/////////////////////////////////////////////////////////////////////////////////////////////////
49 : public senf::ClientSocketHandle<senf::test::SomeSocketProtocol::Policy>
53 : senf::ClientSocketHandle<senf::test::SomeSocketProtocol::Policy>(
54 std::auto_ptr<senf::SocketBody>(
55 new senf::ProtocolSocketBody<senf::test::SomeSocketProtocol>(false)))
61 SENF_AUTO_UNIT_TEST(clientSocketHandle)
63 BOOST_CHECKPOINT("Constructing socket handle");
66 // conversion to other socket handles
68 typedef senf::MakeSocketPolicy<
69 senf::test::SomeFramingPolicy,
70 senf::test::SomeReadPolicy,
71 senf::test::SomeWritePolicy
72 >::policy OtherSocketPolicy;
73 typedef senf::SocketHandle<OtherSocketPolicy> OtherSocketHandle;
75 BOOST_CHECKPOINT("Copy-constructing socket handle");
76 OtherSocketHandle osh (myh);
77 BOOST_CHECKPOINT("Assigning socket handle");
79 typedef senf::ClientSocketHandle<senf::test::SomeSocketProtocol::Policy> SomeSocketHandle;
80 BOOST_CHECKPOINT("static_casting socket handle");
81 SomeSocketHandle ssh =
82 senf::static_socket_cast<SomeSocketHandle>(osh);
83 SENF_CHECK_NO_THROW( senf::dynamic_socket_cast<SomeSocketHandle>(osh) );
84 typedef senf::ClientSocketHandle<senf::MakeSocketPolicy<
86 senf::NoAddressingPolicy
87 >::policy> SomeOtherSocketHandle;
88 BOOST_CHECK_THROW( senf::dynamic_socket_cast<SomeOtherSocketHandle>(osh),
92 // reading and writing
93 SENF_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.read(), "TEST-READ" ) );
95 std::string buf("FOO-BAR");
96 SENF_CHECK_NO_THROW( myh.read(buf,0) );
97 BOOST_CHECK_EQUAL( buf, "TEST-READ" );
101 ::strcpy(buf,"0123456789");
102 SENF_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.read(buf,buf+10), buf+9 ) );
103 BOOST_CHECK_EQUAL( buf, "TEST-READ9" );
106 SENF_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.readfrom().first, "TEST-READ" ) );
108 std::string buf("FOO-BAR");
110 SENF_CHECK_NO_THROW( myh.readfrom(buf,addr,0) );
111 BOOST_CHECK_EQUAL( buf, "TEST-READ" );
116 ::strcpy(buf,"0123456789");
117 SENF_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.readfrom(buf,buf+10,addr), buf+9 ) );
118 BOOST_CHECK_EQUAL( buf, "TEST-READ9" );
122 std::string s ("TEST-WRITE");
123 SENF_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.write(s)-s.begin(), 10 ) );
125 // This simulates a closed file in this test policy. However, we
126 // have changed the semantics so this will not work anymore.
127 // BOOST_CHECK_THROW( myh.write(s),senf::SystemException );
128 char const * const s1 = "TEST-WRITE9";
129 SENF_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.write(s1,s1+10), s1+10u ) );
131 SENF_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.writeto(0,s)-s.begin(), 10 ) );
132 SENF_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.writeto(0,s1,s1+10), s1+10 ) );
135 SENF_CHECK_NO_THROW( myh.connect(0) );
136 SENF_CHECK_NO_THROW( myh.bind(0) );
137 SENF_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.peer(), 1u ) );
138 SENF_CHECK_NO_THROW( BOOST_CHECK_EQUAL( myh.local(), 2u ) );
141 //-/////////////////////////////////////////////////////////////////////////////////////////////////
148 // c-file-style: "senf"
149 // indent-tabs-mode: nil
150 // ispell-local-dictionary: "american"
151 // compile-command: "scons -u test"
152 // comment-column: 40