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& ) { value()++; }
32 copy_count( copy_count&& ) {}
33 copy_count( copy_count const&& ) {}
34 // ~copy_count() { std::cout << "~copy_count" << std::endl; }
36 static int& value() { static int s_value; return s_value; };
38 static copy_count make() { return copy_count(); }
39 static copy_count const make_const() { return copy_count(); }
42 //____________________________________________________________________________//
45 struct check_arg_type {
47 void operator()( S const& ) const
49 BOOST_CHECK_MESSAGE( (boost::is_same<S,T>::value), "Sample type does not match expected" );
53 //____________________________________________________________________________//
55 template<typename T1, typename T2>
56 struct check_arg_type<std::tuple<T1,T2>> {
57 template<typename S1, typename S2>
58 void operator()( S1 const&, S2 const& ) const
60 BOOST_CHECK_MESSAGE( (boost::is_same<S1,T1>::value), "S1 type does not match expected" );
61 BOOST_CHECK_MESSAGE( (boost::is_same<S2,T2>::value), "S2 type does not match expected" );
65 //____________________________________________________________________________//
67 template<typename T1, typename T2, typename T3>
68 struct check_arg_type<std::tuple<T1,T2,T3>> {
69 template<typename S1, typename S2, typename S3>
70 void operator()( S1 const&, S2 const&, S3 const& ) const
72 BOOST_CHECK_MESSAGE( (boost::is_same<S1,T1>::value), "S1 type does not match expected" );
73 BOOST_CHECK_MESSAGE( (boost::is_same<S2,T2>::value), "S2 type does not match expected" );
74 BOOST_CHECK_MESSAGE( (boost::is_same<S3,T3>::value), "S3 type does not match expected" );
78 //____________________________________________________________________________//
81 struct check_arg_type_like {
83 void operator()( S const& ) const
85 BOOST_CHECK_MESSAGE( (boost::is_convertible<S,T>::value), "Sample type does not match expected" );
89 //____________________________________________________________________________//
91 template<typename T1, typename T2>
92 struct check_arg_type_like<std::tuple<T1,T2>> {
93 template<typename S1, typename S2>
94 void operator()( S1 const&, S2 const& ) const
96 BOOST_CHECK_MESSAGE( (boost::is_convertible<S1,T1>::value), "S1 type does not match expected" );
97 BOOST_CHECK_MESSAGE( (boost::is_convertible<S2,T2>::value), "S2 type does not match expected" );
101 //____________________________________________________________________________//
103 template<typename T1, typename T2, typename T3>
104 struct check_arg_type_like<std::tuple<T1,T2,T3>> {
105 template<typename S1, typename S2, typename S3>
106 void operator()( S1 const&, S2 const&, S3 const& ) const
108 BOOST_CHECK_MESSAGE( (boost::is_convertible<S1,T1>::value), "S1 type does not match expected" );
109 BOOST_CHECK_MESSAGE( (boost::is_convertible<S2,T2>::value), "S2 type does not match expected" );
110 BOOST_CHECK_MESSAGE( (boost::is_convertible<S3,T3>::value), "S3 type does not match expected" );
114 //____________________________________________________________________________//
116 struct invocation_count {
117 invocation_count() : m_value( 0 ) {}
120 void operator()( S const& ) const
124 template<typename S1,typename S2>
125 void operator()( S1 const&, S2 const& ) const
129 template<typename S1,typename S2,typename S3>
130 void operator()( S1 const&, S2 const&, S3 const& ) const
138 invocation_count(invocation_count const&);
141 //____________________________________________________________________________//
143 struct expected_call_count {
144 explicit expected_call_count( int exp_count )
146 , m_exp_count( exp_count )
148 expected_call_count(expected_call_count const&) = delete;
149 void operator=(expected_call_count const&) = delete;
151 ~expected_call_count()
153 BOOST_TEST( m_exp_count == m_call_count );
157 void operator()( S const& ) const
161 template<typename S1,typename S2>
162 void operator()( S1 const&, S2 const& ) const
166 template<typename S1,typename S2,typename S3>
167 void operator()( S1 const&, S2 const&, S3 const& ) const
172 mutable int m_call_count;
177 //____________________________________________________________________________//
179 struct print_sample {
181 void operator()( T const& sample ) const
183 std::cout << "S has type: " << typeid(T).name() << " and value " << sample << std::endl;
187 //____________________________________________________________________________//
189 inline std::vector<copy_count>
190 make_copy_count_collection()
192 return std::vector<copy_count>( 3 );
195 //____________________________________________________________________________//
197 inline std::list<copy_count> const
198 make_copy_count_const_collection()
200 return std::list<copy_count>( 3 );
203 //____________________________________________________________________________//
205 #endif // BOOST_TEST_TEST_DATASETS_HPP