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 "SocketHandle.test.hh"
26 //#include "SocketHandle.test.ih"
29 #include "SocketHandle.hh"
30 #include "SocketProtocol.test.hh"
31 #include "AddressingPolicy.hh"
33 #include "../Utils/auto_unit_test.hh"
34 #include <boost/test/test_tools.hpp>
37 ///////////////////////////////cc.p////////////////////////////////////////
42 : public senf::SocketHandle<senf::test::SomeSocketProtocol::Policy>
46 : senf::SocketHandle<senf::test::SomeSocketProtocol::Policy>(
47 std::auto_ptr<senf::SocketBody>(
48 new senf::ProtocolSocketBody<senf::test::SomeSocketProtocol>(false, 0)))
53 : public senf::FileHandle
56 FDHandle() : senf::FileHandle(std::auto_ptr<senf::FileBody>(new senf::FileBody())) {}
61 BOOST_AUTO_UNIT_TEST(socketHandle)
63 typedef senf::MakeSocketPolicy<
64 senf::test::SomeCommunicationPolicy,
65 senf::test::SomeReadPolicy
66 >::policy OtherSocketPolicy;
67 typedef senf::SocketHandle<OtherSocketPolicy> OtherSocketHandle;
69 typedef senf::MakeSocketPolicy<
70 senf::test::SomeCommunicationPolicy,
71 senf::test::SomeAddressingPolicy
72 >::policy AnotherSocketPolicy;
73 typedef senf::SocketHandle<AnotherSocketPolicy> AnotherSocketHandle;
77 OtherSocketHandle osh (myh);
80 typedef senf::SocketHandle<senf::test::SomeSocketProtocol::Policy> SomeSocketHandle;
81 SomeSocketHandle ssh = senf::static_socket_cast<SomeSocketHandle>(osh);
83 BOOST_CHECK_NO_THROW( senf::dynamic_socket_cast<SomeSocketHandle>(osh) );
84 BOOST_CHECK_NO_THROW( senf::dynamic_socket_cast<AnotherSocketHandle>(osh) );
86 typedef senf::SocketHandle< senf::MakeSocketPolicy<
88 senf::NoAddressingPolicy
89 >::policy> SomeOtherSocketHandle;
91 BOOST_CHECK_THROW( senf::dynamic_socket_cast<SomeOtherSocketHandle>(osh),
93 BOOST_CHECK_THROW( senf::dynamic_socket_cast<SomeSocketHandle>(
94 senf::FileHandle(FDHandle())),
97 BOOST_CHECK_EQUAL( myh.dumpState(),
100 "handle: senf::SocketHandle<senf::SocketPolicy<senf::test::SomeAddressingPolicy, senf::test::SomeFramingPolicy, senf::test::SomeCommunicationPolicy, senf::test::SomeReadPolicy, senf::test::SomeWritePolicy> >\n"
101 "socket.protocol: senf::test::SomeSocketProtocol\n"
102 "socket.protocol.policy: senf::SocketPolicy<senf::test::SomeAddressingPolicy, senf::test::SomeFramingPolicy, senf::test::SomeCommunicationPolicy, senf::test::SomeReadPolicy, senf::test::SomeWritePolicy>\n"
103 "socket.server: false\n" );
105 BOOST_CHECK_NO_THROW( myh.facet<senf::test::SomeSocketProtocol>() );
108 // Ensure, the destructor is called and calls the correct close() implementation
109 BOOST_CHECK_EQUAL( senf::test::SomeSocketProtocol::closeCount(), 1u );
112 ///////////////////////////////cc.e////////////////////////////////////////
119 // c-file-style: "senf"
120 // indent-tabs-mode: nil
121 // ispell-local-dictionary: "american"
122 // compile-command: "scons -u test"
123 // comment-column: 40