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 SocketHandle unit tests */
31 //#include "SocketHandle.test.hh"
32 //#include "SocketHandle.test.ih"
35 #include "SocketHandle.hh"
36 #include "SocketProtocol.test.hh"
37 #include "AddressingPolicy.hh"
39 #include <senf/Utils/auto_unit_test.hh>
40 #include <boost/test/test_tools.hpp>
43 //-/////////////////////////////////////////////////////////////////////////////////////////////////
48 : public senf::SocketHandle<senf::test::SomeSocketProtocol::Policy>
52 : senf::SocketHandle<senf::test::SomeSocketProtocol::Policy>(
53 std::auto_ptr<senf::SocketBody>(
54 new senf::ProtocolSocketBody<senf::test::SomeSocketProtocol>(false, 0)))
59 : public senf::FileHandle
62 FDHandle() : senf::FileHandle(std::auto_ptr<senf::FileBody>(new senf::FileBody())) {}
67 SENF_AUTO_UNIT_TEST(socketHandle)
69 typedef senf::MakeSocketPolicy<
70 senf::test::SomeCommunicationPolicy,
71 senf::test::SomeReadPolicy
72 >::policy OtherSocketPolicy;
73 typedef senf::SocketHandle<OtherSocketPolicy> OtherSocketHandle;
75 typedef senf::MakeSocketPolicy<
76 senf::test::SomeCommunicationPolicy,
77 senf::test::SomeAddressingPolicy
78 >::policy AnotherSocketPolicy;
79 typedef senf::SocketHandle<AnotherSocketPolicy> AnotherSocketHandle;
83 OtherSocketHandle osh (myh);
86 typedef senf::SocketHandle<senf::test::SomeSocketProtocol::Policy> SomeSocketHandle;
87 SomeSocketHandle ssh = senf::static_socket_cast<SomeSocketHandle>(osh);
89 SENF_CHECK_NO_THROW( senf::dynamic_socket_cast<SomeSocketHandle>(osh) );
90 SENF_CHECK_NO_THROW( senf::dynamic_socket_cast<AnotherSocketHandle>(osh) );
92 typedef senf::SocketHandle< senf::MakeSocketPolicy<
94 senf::NoAddressingPolicy
95 >::policy> SomeOtherSocketHandle;
97 BOOST_CHECK_THROW( senf::dynamic_socket_cast<SomeOtherSocketHandle>(osh),
99 BOOST_CHECK_THROW( senf::dynamic_socket_cast<SomeSocketHandle>(
100 senf::FileHandle(FDHandle())),
103 BOOST_CHECK_EQUAL( myh.dumpState(),
106 "handle: senf::SocketHandle<senf::SocketPolicy<senf::test::SomeAddressingPolicy, senf::test::SomeFramingPolicy, senf::test::SomeCommunicationPolicy, senf::test::SomeReadPolicy, senf::test::SomeWritePolicy> >\n"
107 "socket.protocol: senf::test::SomeSocketProtocol\n"
108 "socket.protocol.policy: senf::SocketPolicy<senf::test::SomeAddressingPolicy, senf::test::SomeFramingPolicy, senf::test::SomeCommunicationPolicy, senf::test::SomeReadPolicy, senf::test::SomeWritePolicy>\n"
109 "socket.server: false\n"
112 SENF_CHECK_NO_THROW( myh.facet<senf::test::SomeSocketProtocol>() );
115 // Ensure, the destructor is called and calls the correct close() implementation
116 BOOST_CHECK( senf::test::SomeSocketProtocol::closeCount() >= 1u );
119 //-/////////////////////////////////////////////////////////////////////////////////////////////////
126 // c-file-style: "senf"
127 // indent-tabs-mode: nil
128 // ispell-local-dictionary: "american"
129 // compile-command: "scons -u test"
130 // comment-column: 40