1 // (C) Copyright Gennadiy Rozental 2011-2015.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/test for the library home page.
10 // Version : $Revision$
12 // Description : datasets test helpers
13 // ***************************************************************************
15 #ifndef BOOST_TEST_TEST_DATASETS_HPP
16 #define BOOST_TEST_TEST_DATASETS_HPP
19 #include <boost/type_traits/is_same.hpp>
20 #include <boost/type_traits/is_convertible.hpp>
26 //____________________________________________________________________________//
31 copy_count( copy_count const& ) {
34 copy_count( copy_count&& ) BOOST_NOEXCEPT_OR_NOTHROW {} // noexcept is important indeed
35 copy_count( copy_count const&& ) {}
36 // ~copy_count() { std::cout << "~copy_count" << std::endl; }
38 static int& value() { static int s_value; return s_value; };
40 static copy_count make() { return copy_count(); }
41 static copy_count const make_const() { return copy_count(); }
44 //____________________________________________________________________________//
47 struct check_arg_type {
49 void operator()( S const& ) const
51 BOOST_CHECK_MESSAGE( (boost::is_same<S,T>::value), "Sample type does not match expected" );
55 //____________________________________________________________________________//
57 template<typename T1, typename T2>
58 struct check_arg_type<std::tuple<T1,T2>> {
59 template<typename S1, typename S2>
60 void operator()( S1 const&, S2 const& ) const
62 BOOST_CHECK_MESSAGE( (boost::is_same<S1,T1>::value), "S1 type does not match expected" );
63 BOOST_CHECK_MESSAGE( (boost::is_same<S2,T2>::value), "S2 type does not match expected" );
67 //____________________________________________________________________________//
69 template<typename T1, typename T2, typename T3>
70 struct check_arg_type<std::tuple<T1,T2,T3>> {
71 template<typename S1, typename S2, typename S3>
72 void operator()( S1 const&, S2 const&, S3 const& ) const
74 BOOST_CHECK_MESSAGE( (boost::is_same<S1,T1>::value), "S1 type does not match expected" );
75 BOOST_CHECK_MESSAGE( (boost::is_same<S2,T2>::value), "S2 type does not match expected" );
76 BOOST_CHECK_MESSAGE( (boost::is_same<S3,T3>::value), "S3 type does not match expected" );
80 //____________________________________________________________________________//
83 struct check_arg_type_like {
85 void operator()( S const& ) const
87 BOOST_CHECK_MESSAGE( (boost::is_convertible<S,T>::value), "Sample type does not match expected" );
91 //____________________________________________________________________________//
93 template<typename T1, typename T2>
94 struct check_arg_type_like<std::tuple<T1,T2>> {
95 template<typename S1, typename S2>
96 void operator()( S1 const&, S2 const& ) const
98 BOOST_CHECK_MESSAGE( (boost::is_convertible<S1,T1>::value), "S1 type does not match expected" );
99 BOOST_CHECK_MESSAGE( (boost::is_convertible<S2,T2>::value), "S2 type does not match expected" );
103 //____________________________________________________________________________//
105 template<typename T1, typename T2, typename T3>
106 struct check_arg_type_like<std::tuple<T1,T2,T3>> {
107 template<typename S1, typename S2, typename S3>
108 void operator()( S1 const&, S2 const&, S3 const& ) const
110 BOOST_CHECK_MESSAGE( (boost::is_convertible<S1,T1>::value), "S1 type does not match expected" );
111 BOOST_CHECK_MESSAGE( (boost::is_convertible<S2,T2>::value), "S2 type does not match expected" );
112 BOOST_CHECK_MESSAGE( (boost::is_convertible<S3,T3>::value), "S3 type does not match expected" );
116 //____________________________________________________________________________//
118 struct invocation_count {
119 invocation_count() : m_value( 0 ) {}
122 void operator()( S const& ) const
126 template<typename S1,typename S2>
127 void operator()( S1 const&, S2 const& ) const
131 template<typename S1,typename S2,typename S3>
132 void operator()( S1 const&, S2 const&, S3 const& ) const
140 invocation_count(invocation_count const&);
143 //____________________________________________________________________________//
145 struct expected_call_count {
146 explicit expected_call_count( int exp_count )
148 , m_exp_count( exp_count )
150 expected_call_count(expected_call_count const&) = delete;
151 void operator=(expected_call_count const&) = delete;
153 ~expected_call_count()
155 BOOST_TEST( m_exp_count == m_call_count );
159 void operator()( S const& ) const
163 template<typename S1,typename S2>
164 void operator()( S1 const&, S2 const& ) const
168 template<typename S1,typename S2,typename S3>
169 void operator()( S1 const&, S2 const&, S3 const& ) const
174 mutable int m_call_count;
179 //____________________________________________________________________________//
181 struct print_sample {
183 void operator()( T const& sample ) const
185 std::cout << "S has type: " << typeid(T).name() << " and value " << sample << std::endl;
189 //____________________________________________________________________________//
191 inline std::vector<copy_count>
192 make_copy_count_collection()
194 return std::vector<copy_count>( 3 );
197 //____________________________________________________________________________//
199 inline std::list<copy_count> const
200 make_copy_count_const_collection()
202 return std::list<copy_count>( 3 );
205 //____________________________________________________________________________//
207 #endif // BOOST_TEST_TEST_DATASETS_HPP