]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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) | |
5 | ||
6 | // See http://www.boost.org/libs/test for the library home page. | |
7 | // | |
8 | // File : $RCSfile$ | |
9 | // | |
10 | // Version : $Revision$ | |
11 | // | |
12 | // Description : datasets test helpers | |
13 | // *************************************************************************** | |
14 | ||
15 | #ifndef BOOST_TEST_TEST_DATASETS_HPP | |
16 | #define BOOST_TEST_TEST_DATASETS_HPP | |
17 | ||
18 | // Boost | |
19 | #include <boost/type_traits/is_same.hpp> | |
20 | #include <boost/type_traits/is_convertible.hpp> | |
21 | ||
22 | #include <iostream> | |
23 | #include <vector> | |
24 | #include <list> | |
25 | ||
26 | //____________________________________________________________________________// | |
27 | ||
28 | class copy_count { | |
29 | public: | |
30 | copy_count() {} | |
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; } | |
35 | ||
36 | static int& value() { static int s_value; return s_value; }; | |
37 | ||
38 | static copy_count make() { return copy_count(); } | |
39 | static copy_count const make_const() { return copy_count(); } | |
40 | }; | |
41 | ||
42 | //____________________________________________________________________________// | |
43 | ||
44 | template<typename T> | |
45 | struct check_arg_type { | |
46 | template<typename S> | |
47 | void operator()( S const& ) const | |
48 | { | |
49 | BOOST_CHECK_MESSAGE( (boost::is_same<S,T>::value), "Sample type does not match expected" ); | |
50 | } | |
51 | }; | |
52 | ||
53 | //____________________________________________________________________________// | |
54 | ||
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 | |
59 | { | |
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" ); | |
62 | } | |
63 | }; | |
64 | ||
65 | //____________________________________________________________________________// | |
66 | ||
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 | |
71 | { | |
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" ); | |
75 | } | |
76 | }; | |
77 | ||
78 | //____________________________________________________________________________// | |
79 | ||
80 | template<typename T> | |
81 | struct check_arg_type_like { | |
82 | template<typename S> | |
83 | void operator()( S const& ) const | |
84 | { | |
85 | BOOST_CHECK_MESSAGE( (boost::is_convertible<S,T>::value), "Sample type does not match expected" ); | |
86 | } | |
87 | }; | |
88 | ||
89 | //____________________________________________________________________________// | |
90 | ||
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 | |
95 | { | |
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" ); | |
98 | } | |
99 | }; | |
100 | ||
101 | //____________________________________________________________________________// | |
102 | ||
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 | |
107 | { | |
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" ); | |
111 | } | |
112 | }; | |
113 | ||
114 | //____________________________________________________________________________// | |
115 | ||
116 | struct invocation_count { | |
117 | invocation_count() : m_value( 0 ) {} | |
118 | ||
119 | template<typename S> | |
120 | void operator()( S const& ) const | |
121 | { | |
122 | m_value++; | |
123 | } | |
124 | template<typename S1,typename S2> | |
125 | void operator()( S1 const&, S2 const& ) const | |
126 | { | |
127 | m_value++; | |
128 | } | |
129 | template<typename S1,typename S2,typename S3> | |
130 | void operator()( S1 const&, S2 const&, S3 const& ) const | |
131 | { | |
132 | m_value++; | |
133 | } | |
134 | ||
135 | mutable int m_value; | |
136 | ||
137 | private: | |
138 | invocation_count(invocation_count const&); | |
139 | }; | |
140 | ||
141 | //____________________________________________________________________________// | |
142 | ||
143 | struct expected_call_count { | |
144 | explicit expected_call_count( int exp_count ) | |
145 | : m_call_count( 0 ) | |
146 | , m_exp_count( exp_count ) | |
147 | {} | |
148 | expected_call_count(expected_call_count const&) = delete; | |
149 | void operator=(expected_call_count const&) = delete; | |
150 | ||
151 | ~expected_call_count() | |
152 | { | |
153 | BOOST_TEST( m_exp_count == m_call_count ); | |
154 | } | |
155 | ||
156 | template<typename S> | |
157 | void operator()( S const& ) const | |
158 | { | |
159 | m_call_count++; | |
160 | } | |
161 | template<typename S1,typename S2> | |
162 | void operator()( S1 const&, S2 const& ) const | |
163 | { | |
164 | m_call_count++; | |
165 | } | |
166 | template<typename S1,typename S2,typename S3> | |
167 | void operator()( S1 const&, S2 const&, S3 const& ) const | |
168 | { | |
169 | m_call_count++; | |
170 | } | |
171 | ||
172 | mutable int m_call_count; | |
173 | int m_exp_count; | |
174 | ||
175 | }; | |
176 | ||
177 | //____________________________________________________________________________// | |
178 | ||
179 | struct print_sample { | |
180 | template<typename T> | |
181 | void operator()( T const& sample ) const | |
182 | { | |
183 | std::cout << "S has type: " << typeid(T).name() << " and value " << sample << std::endl; | |
184 | } | |
185 | }; | |
186 | ||
187 | //____________________________________________________________________________// | |
188 | ||
189 | inline std::vector<copy_count> | |
190 | make_copy_count_collection() | |
191 | { | |
192 | return std::vector<copy_count>( 3 ); | |
193 | } | |
194 | ||
195 | //____________________________________________________________________________// | |
196 | ||
197 | inline std::list<copy_count> const | |
198 | make_copy_count_const_collection() | |
199 | { | |
200 | return std::list<copy_count>( 3 ); | |
201 | } | |
202 | ||
203 | //____________________________________________________________________________// | |
204 | ||
205 | #endif // BOOST_TEST_TEST_DATASETS_HPP |