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.
25 //#include "SocketPolicy.test.hh"
26 //#include "SocketPolicy.test.ih"
29 #include "SocketPolicy.hh"
30 #include "SocketPolicy.test.hh"
32 #include "../Utils/auto_unit_test.hh"
33 #include <boost/test/test_tools.hpp>
34 #include <boost/mpl/assert.hpp>
35 #include <boost/concept_check.hpp>
36 #include <boost/utility.hpp> // enable_if
39 ///////////////////////////////cc.p////////////////////////////////////////
44 struct INetAddressingPolicy : public AddressingPolicyBase {};
45 struct UnixAddressingPolicy : public AddressingPolicyBase {};
47 struct StreamFramingPolicy : public FramingPolicyBase {};
48 struct DgramFramingPolicy : public FramingPolicyBase {};
50 struct ConnectedCommunicationPolicy : public CommunicationPolicyBase {};
51 struct UnconnectedCommunicationPolicy : public CommunicationPolicyBase {};
53 struct ReadablePolicy : public ReadPolicyBase {};
54 struct UnreadablePolicy : public ReadPolicyBase {};
56 struct WritablePolicy : public WritePolicyBase {};
57 struct UnwritablePolicy : public WritePolicyBase {};
59 struct SocketBufferingPolicy : public BufferingPolicyBase {};
61 template <class Policy>
62 struct ConvertibleValue
65 ConvertibleValue(ConvertibleValue const & other) {}
67 template <class OtherPolicy>
68 ConvertibleValue(ConvertibleValue<OtherPolicy> const & other,
69 typename boost::enable_if< SocketPolicyIsBaseOf<Policy,OtherPolicy> >::type * = 0)
72 ConvertibleValue const & operator=(ConvertibleValue const & other)
75 template <class OtherPolicy>
76 typename boost::enable_if< SocketPolicyIsBaseOf<Policy,OtherPolicy>,
77 ConvertibleValue >::type const &
78 operator=(ConvertibleValue<OtherPolicy> const & other)
84 BOOST_AUTO_UNIT_TEST(socketPolicy)
86 // Most of these checks are really compile-time checks ...
88 typedef MakeSocketPolicy<
90 ConnectedCommunicationPolicy,
91 ReadablePolicy>::policy Policy1;
95 UnspecifiedFramingPolicy,
96 ConnectedCommunicationPolicy,
98 UnspecifiedWritePolicy,
99 UnspecifiedBufferingPolicy> Policy2;
101 BOOST_MPL_ASSERT(( boost::is_same<Policy1,Policy2> ));
103 typedef MakeSocketPolicy<
105 UnspecifiedCommunicationPolicy>::policy Policy3;
107 typedef SocketPolicy<
108 UnixAddressingPolicy,
109 UnspecifiedFramingPolicy,
110 UnspecifiedCommunicationPolicy,
112 UnspecifiedWritePolicy,
113 UnspecifiedBufferingPolicy> Policy4;
115 BOOST_MPL_ASSERT(( boost::is_same<Policy3,Policy4> ));
116 BOOST_MPL_ASSERT_NOT(( boost::is_same<Policy1, Policy3> ));
118 BOOST_MPL_ASSERT(( SocketPolicyIsBaseOf<Policy3,Policy1> ));
119 BOOST_MPL_ASSERT_NOT(( SocketPolicyIsBaseOf<Policy1,Policy3> ));
120 BOOST_MPL_ASSERT_NOT(( SocketPolicyIsBaseOf<Policy1,int> ));
122 // The following should fail at compile time
123 // BOOST_MPL_ASSERT(( SocketPolicyIsBaseOf<Policy1,Policy3> ));
126 ConvertibleValue<Policy1> p1;
127 ConvertibleValue<Policy3> p3(p1);
130 // The following should fail at compile time
138 BOOST_CHECK_THROW( Policy1::checkBaseOf(p3), std::bad_cast );
139 BOOST_CHECK_NO_THROW( Policy3::checkBaseOf(p1) );
143 ///////////////////////////////cc.e////////////////////////////////////////
150 // c-file-style: "senf"
151 // indent-tabs-mode: nil
152 // ispell-local-dictionary: "american"
153 // compile-command: "scons -u test"
154 // comment-column: 40