Fixed whitespace in all files (no tabs)
[senf.git] / Socket / ServerSocketHandle.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2006
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.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 <boost/test/auto_unit_test.hpp>
35 #include <boost/test/test_tools.hpp>
36
37 #define prefix_
38 ///////////////////////////////cc.p////////////////////////////////////////
39
40 namespace {
41
42     namespace sl = senf;
43
44     class MySocketHandle
45         : public sl::ServerSocketHandle<sl::test::SomeProtocol::Policy>
46     {
47     public:
48         MySocketHandle()
49             : sl::ServerSocketHandle<sl::test::SomeProtocol::Policy>(
50                 std::auto_ptr<sl::SocketProtocol>(new sl::test::SomeProtocol()))
51             {}
52     };
53 }
54
55 BOOST_AUTO_UNIT_TEST(serverSocketHandle)
56 {
57     typedef sl::MakeSocketPolicy<
58         sl::test::SomeFramingPolicy,
59         sl::test::SomeReadPolicy,
60         sl::test::SomeWritePolicy
61         >::policy OtherSocketPolicy;
62     typedef sl::SocketHandle<OtherSocketPolicy> OtherSocketHandle;
63
64     MySocketHandle myh;
65     OtherSocketHandle osh (myh);
66     osh = myh;
67
68     typedef sl::ServerSocketHandle<sl::test::SomeProtocol::Policy> SomeSocketHandle;
69     SomeSocketHandle ssh = sl::static_socket_cast<SomeSocketHandle>(osh);
70
71     typedef sl::ServerSocketHandle<sl::MakeSocketPolicy<
72         OtherSocketPolicy,
73         senf::NoAddressingPolicy
74         >::policy> SomeOtherSocketHandle;
75     typedef sl::ClientSocketHandle<OtherSocketPolicy> OtherClientHandle;
76
77     BOOST_CHECK_NO_THROW( sl::dynamic_socket_cast<SomeSocketHandle>(osh) );
78     BOOST_CHECK_THROW( sl::dynamic_socket_cast<SomeOtherSocketHandle>(osh),
79                        std::bad_cast );
80     BOOST_CHECK_THROW( sl::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 // End: