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 template <class SPolicy>
60 struct ConvertibleValue
63 ConvertibleValue(ConvertibleValue const & other) {}
65 template <class OtherPolicy>
66 ConvertibleValue(ConvertibleValue<OtherPolicy> const & other,
67 typename boost::enable_if< SocketPolicyIsBaseOf<SPolicy,OtherPolicy> >::type * = 0)
70 ConvertibleValue const & operator=(ConvertibleValue const & other)
73 template <class OtherPolicy>
74 typename boost::enable_if< SocketPolicyIsBaseOf<SPolicy,OtherPolicy>,
75 ConvertibleValue >::type const &
76 operator=(ConvertibleValue<OtherPolicy> const & other)
82 BOOST_AUTO_UNIT_TEST(socketPolicy)
84 // Most of these checks are really compile-time checks ...
86 typedef MakeSocketPolicy<
88 ConnectedCommunicationPolicy,
89 ReadablePolicy>::policy Policy1;
93 UnspecifiedFramingPolicy,
94 ConnectedCommunicationPolicy,
96 UnspecifiedWritePolicy> Policy2;
98 BOOST_MPL_ASSERT(( boost::is_same<Policy1,Policy2> ));
100 typedef MakeSocketPolicy<
102 UnspecifiedCommunicationPolicy>::policy Policy3;
104 typedef SocketPolicy<
105 UnixAddressingPolicy,
106 UnspecifiedFramingPolicy,
107 UnspecifiedCommunicationPolicy,
109 UnspecifiedWritePolicy> Policy4;
111 BOOST_MPL_ASSERT(( boost::is_same<Policy3,Policy4> ));
112 BOOST_MPL_ASSERT_NOT(( boost::is_same<Policy1, Policy3> ));
114 BOOST_MPL_ASSERT(( SocketPolicyIsBaseOf<Policy3,Policy1> ));
115 BOOST_MPL_ASSERT_NOT(( SocketPolicyIsBaseOf<Policy1,Policy3> ));
116 BOOST_MPL_ASSERT_NOT(( SocketPolicyIsBaseOf<Policy1,int> ));
118 // The following should fail at compile time
119 // BOOST_MPL_ASSERT(( SocketPolicyIsBaseOf<Policy1,Policy3> ));
122 ConvertibleValue<Policy1> p1;
123 ConvertibleValue<Policy3> p3(p1);
126 // The following should fail at compile time
134 BOOST_CHECK_THROW( Policy1::checkBaseOf(p3), std::bad_cast );
135 BOOST_CHECK_NO_THROW( Policy3::checkBaseOf(p1) );
139 ///////////////////////////////cc.e////////////////////////////////////////
146 // c-file-style: "senf"
147 // indent-tabs-mode: nil
148 // ispell-local-dictionary: "american"
149 // compile-command: "scons -u test"
150 // comment-column: 40