removed some useless spaces; not very important, I know :)
[senf.git] / Socket / ServerSocketHandle.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 // Unit tests
24
25 //#include "ServerSocketHandle.test.hh"
26 //#include "ServerSocketHandle.test.ih"
27
28 // Custom includes
29 #include "ServerSocketHandle.hh"
30 #include "ClientSocketHandle.hh"
31 #include "SocketProtocol.test.hh"
32 #include "AddressingPolicy.hh"
33
34 #include "../Utils/auto_unit_test.hh"
35 #include <boost/test/test_tools.hpp>
36
37 #define prefix_
38 ///////////////////////////////cc.p////////////////////////////////////////
39
40 namespace {
41
42     class MySocketHandle
43         : public senf::ServerSocketHandle<senf::test::SomeProtocol::Policy>
44     {
45     public:
46         MySocketHandle()
47             : senf::ServerSocketHandle<senf::test::SomeProtocol::Policy>(
48                 std::auto_ptr<senf::SocketBody>(
49                     new senf::ProtocolSocketBody<senf::test::SomeProtocol>(true)))
50             {}
51     };
52
53 }
54
55 BOOST_AUTO_UNIT_TEST(serverSocketHandle)
56 {
57     typedef senf::MakeSocketPolicy<
58         senf::test::SomeFramingPolicy,
59         senf::test::SomeReadPolicy,
60         senf::test::SomeWritePolicy
61         >::policy OtherSocketPolicy;
62     typedef senf::SocketHandle<OtherSocketPolicy> OtherSocketHandle;
63
64     MySocketHandle myh;
65     OtherSocketHandle osh (myh);
66     osh = myh;
67
68     typedef senf::ServerSocketHandle<senf::test::SomeProtocol::Policy> SomeSocketHandle;
69     SomeSocketHandle ssh = senf::static_socket_cast<SomeSocketHandle>(osh);
70
71     typedef senf::ServerSocketHandle<senf::MakeSocketPolicy<
72         OtherSocketPolicy,
73         senf::NoAddressingPolicy
74         >::policy> SomeOtherSocketHandle;
75     typedef senf::ClientSocketHandle<OtherSocketPolicy> OtherClientHandle;
76
77     BOOST_CHECK_NO_THROW( senf::dynamic_socket_cast<SomeSocketHandle>(osh) );
78     BOOST_CHECK_THROW( senf::dynamic_socket_cast<SomeOtherSocketHandle>(osh),
79                        std::bad_cast );
80     BOOST_CHECK_THROW( senf::dynamic_socket_cast<OtherClientHandle>(osh),
81                        std::bad_cast );
82
83     BOOST_CHECK_NO_THROW( myh.bind(0) );
84     BOOST_CHECK_EQUAL( myh.local(), 2u );
85
86     {
87         MySocketHandle::ClientSocketHandle client = myh.accept();
88         BOOST_CHECK_EQUAL( client.fd(), -1 );
89     }
90
91 }
92
93
94 ///////////////////////////////cc.e////////////////////////////////////////
95 #undef prefix_
96
97 \f
98 // Local Variables:
99 // mode: c++
100 // fill-column: 100
101 // c-file-style: "senf"
102 // indent-tabs-mode: nil
103 // ispell-local-dictionary: "american"
104 // compile-command: "scons -u test"
105 // comment-column: 40
106 // End: