4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief SocketPolicy unit tests */
31 #include "SocketPolicy.test.hh"
32 //#include "SocketPolicy.test.ih"
35 #include <boost/mpl/assert.hpp>
36 #include <boost/concept_check.hpp>
37 #include <boost/utility.hpp> // enable_if
39 #include "SocketPolicy.hh"
41 #include <senf/Utils/auto_unit_test.hh>
42 #include <boost/test/test_tools.hpp>
45 //-/////////////////////////////////////////////////////////////////////////////////////////////////
50 struct INetAddressingPolicy : public AddressingPolicyBase {};
51 struct UnixAddressingPolicy : public AddressingPolicyBase {};
53 struct StreamFramingPolicy : public FramingPolicyBase {};
54 struct DgramFramingPolicy : public FramingPolicyBase {};
56 struct ConnectedCommunicationPolicy : public CommunicationPolicyBase {};
57 struct UnconnectedCommunicationPolicy : public CommunicationPolicyBase {};
59 struct ReadablePolicy : public ReadPolicyBase {};
60 struct UnreadablePolicy : public ReadPolicyBase {};
62 struct WritablePolicy : public WritePolicyBase {};
63 struct UnwritablePolicy : public WritePolicyBase {};
65 template <class SPolicy>
66 struct ConvertibleValue
69 ConvertibleValue(ConvertibleValue const & other) {}
71 template <class OtherPolicy>
72 ConvertibleValue(ConvertibleValue<OtherPolicy> const & other,
73 typename boost::enable_if< SocketPolicyIsBaseOf<SPolicy,OtherPolicy> >::type * = 0)
76 ConvertibleValue const & operator=(ConvertibleValue const & other)
79 template <class OtherPolicy>
80 typename boost::enable_if< SocketPolicyIsBaseOf<SPolicy,OtherPolicy>,
81 ConvertibleValue >::type const &
82 operator=(ConvertibleValue<OtherPolicy> const & other)
88 SENF_AUTO_UNIT_TEST(socketPolicy)
90 // Most of these checks are really compile-time checks ...
92 typedef MakeSocketPolicy<
94 ConnectedCommunicationPolicy,
95 ReadablePolicy>::policy Policy1;
99 UnspecifiedFramingPolicy,
100 ConnectedCommunicationPolicy,
102 UnspecifiedWritePolicy> Policy2;
104 BOOST_MPL_ASSERT(( boost::is_same<Policy1,Policy2> ));
106 typedef MakeSocketPolicy<
108 UnspecifiedCommunicationPolicy>::policy Policy3;
110 typedef SocketPolicy<
111 UnixAddressingPolicy,
112 UnspecifiedFramingPolicy,
113 UnspecifiedCommunicationPolicy,
115 UnspecifiedWritePolicy> Policy4;
117 BOOST_MPL_ASSERT(( boost::is_same<Policy3,Policy4> ));
118 BOOST_MPL_ASSERT_NOT(( boost::is_same<Policy1, Policy3> ));
120 BOOST_MPL_ASSERT(( SocketPolicyIsBaseOf<Policy3,Policy1> ));
121 BOOST_MPL_ASSERT_NOT(( SocketPolicyIsBaseOf<Policy1,Policy3> ));
122 BOOST_MPL_ASSERT_NOT(( SocketPolicyIsBaseOf<Policy1,int> ));
124 // The following should fail at compile time
125 // BOOST_MPL_ASSERT(( SocketPolicyIsBaseOf<Policy1,Policy3> ));
128 ConvertibleValue<Policy1> p1;
129 ConvertibleValue<Policy3> p3(p1);
132 // The following should fail at compile time
140 BOOST_CHECK_THROW( Policy1::checkBaseOf(p3), std::bad_cast );
141 SENF_CHECK_NO_THROW( Policy3::checkBaseOf(p1) );
145 //-/////////////////////////////////////////////////////////////////////////////////////////////////
152 // c-file-style: "senf"
153 // indent-tabs-mode: nil
154 // ispell-local-dictionary: "american"
155 // compile-command: "scons -u test"
156 // comment-column: 40