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.
24 \brief SocketPolicy unit tests */
26 #include "SocketPolicy.test.hh"
27 //#include "SocketPolicy.test.ih"
30 #include <boost/mpl/assert.hpp>
31 #include <boost/concept_check.hpp>
32 #include <boost/utility.hpp> // enable_if
34 #include "SocketPolicy.hh"
36 #include <senf/Utils/auto_unit_test.hh>
37 #include <boost/test/test_tools.hpp>
40 ///////////////////////////////cc.p////////////////////////////////////////
45 struct INetAddressingPolicy : public AddressingPolicyBase {};
46 struct UnixAddressingPolicy : public AddressingPolicyBase {};
48 struct StreamFramingPolicy : public FramingPolicyBase {};
49 struct DgramFramingPolicy : public FramingPolicyBase {};
51 struct ConnectedCommunicationPolicy : public CommunicationPolicyBase {};
52 struct UnconnectedCommunicationPolicy : public CommunicationPolicyBase {};
54 struct ReadablePolicy : public ReadPolicyBase {};
55 struct UnreadablePolicy : public ReadPolicyBase {};
57 struct WritablePolicy : public WritePolicyBase {};
58 struct UnwritablePolicy : public WritePolicyBase {};
60 template <class SPolicy>
61 struct ConvertibleValue
64 ConvertibleValue(ConvertibleValue const & other) {}
66 template <class OtherPolicy>
67 ConvertibleValue(ConvertibleValue<OtherPolicy> const & other,
68 typename boost::enable_if< SocketPolicyIsBaseOf<SPolicy,OtherPolicy> >::type * = 0)
71 ConvertibleValue const & operator=(ConvertibleValue const & other)
74 template <class OtherPolicy>
75 typename boost::enable_if< SocketPolicyIsBaseOf<SPolicy,OtherPolicy>,
76 ConvertibleValue >::type const &
77 operator=(ConvertibleValue<OtherPolicy> const & other)
83 BOOST_AUTO_UNIT_TEST(socketPolicy)
85 // Most of these checks are really compile-time checks ...
87 typedef MakeSocketPolicy<
89 ConnectedCommunicationPolicy,
90 ReadablePolicy>::policy Policy1;
94 UnspecifiedFramingPolicy,
95 ConnectedCommunicationPolicy,
97 UnspecifiedWritePolicy> Policy2;
99 BOOST_MPL_ASSERT(( boost::is_same<Policy1,Policy2> ));
101 typedef MakeSocketPolicy<
103 UnspecifiedCommunicationPolicy>::policy Policy3;
105 typedef SocketPolicy<
106 UnixAddressingPolicy,
107 UnspecifiedFramingPolicy,
108 UnspecifiedCommunicationPolicy,
110 UnspecifiedWritePolicy> Policy4;
112 BOOST_MPL_ASSERT(( boost::is_same<Policy3,Policy4> ));
113 BOOST_MPL_ASSERT_NOT(( boost::is_same<Policy1, Policy3> ));
115 BOOST_MPL_ASSERT(( SocketPolicyIsBaseOf<Policy3,Policy1> ));
116 BOOST_MPL_ASSERT_NOT(( SocketPolicyIsBaseOf<Policy1,Policy3> ));
117 BOOST_MPL_ASSERT_NOT(( SocketPolicyIsBaseOf<Policy1,int> ));
119 // The following should fail at compile time
120 // BOOST_MPL_ASSERT(( SocketPolicyIsBaseOf<Policy1,Policy3> ));
123 ConvertibleValue<Policy1> p1;
124 ConvertibleValue<Policy3> p3(p1);
127 // The following should fail at compile time
135 BOOST_CHECK_THROW( Policy1::checkBaseOf(p3), std::bad_cast );
136 SENF_CHECK_NO_THROW( Policy3::checkBaseOf(p1) );
140 ///////////////////////////////cc.e////////////////////////////////////////
147 // c-file-style: "senf"
148 // indent-tabs-mode: nil
149 // ispell-local-dictionary: "american"
150 // compile-command: "scons -u test"
151 // comment-column: 40