7d51364d4ea19228d0ae47268a8d3780c41feb36
[senf.git] / Socket / ProtocolServerSocketHandle.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 /** \file
24     \brief ProtocolServerSocketHandle unit tests */
25
26 //#include "ProtocolServerSocketHandle.test.hh"
27 //#include "ProtocolServerSocketHandle.test.ih"
28
29 // Custom includes
30 #include "ProtocolServerSocketHandle.hh"
31 #include "SocketProtocol.test.hh"
32
33 #include "../Utils/auto_unit_test.hh"
34 #include <boost/test/test_tools.hpp>
35
36 #define prefix_
37 ///////////////////////////////cc.p////////////////////////////////////////
38
39 namespace {
40
41     struct MySocketProtocol : public senf::test::SomeSocketProtocol
42     {
43         using senf::test::SomeSocketProtocol::init_server;
44         void init_server(char const *,unsigned) const {}
45     };
46 }
47
48 BOOST_AUTO_UNIT_TEST(protocolServerSocketHandle)
49 {
50     typedef senf::ProtocolServerSocketHandle<MySocketProtocol> MySocketHandle;
51
52     {
53         typedef senf::MakeSocketPolicy<
54             senf::test::SomeFramingPolicy,
55             senf::test::SomeReadPolicy,
56             senf::test::SomeWritePolicy
57             >::policy OtherSocketPolicy;
58         typedef senf::SocketHandle<OtherSocketPolicy> OtherSocketHandle;
59
60         MySocketHandle h;
61         h.protocol();
62
63         OtherSocketHandle osh (h);
64         h = senf::static_socket_cast<MySocketHandle>(osh);
65
66         MySocketHandle::ClientHandle client = h.accept();
67         BOOST_CHECK_EQUAL( client.fd(), -1 );
68
69         BOOST_CHECK_EQUAL( h.dumpState(),
70                 "handle: senf::ProtocolServerSocketHandle<(anonymous namespace)::MySocketProtocol>\n"
71                 "valid: false\n" );
72     }
73
74     {
75         MySocketHandle h("foo.bar.c",1234);
76     }
77 }
78
79 ///////////////////////////////cc.e////////////////////////////////////////
80 #undef prefix_
81
82 \f
83 // Local Variables:
84 // mode: c++
85 // fill-column: 100
86 // c-file-style: "senf"
87 // indent-tabs-mode: nil
88 // ispell-local-dictionary: "american"
89 // compile-command: "scons -u test"
90 // comment-column: 40
91 // End: