1 // (C) Copyright Raffi Enficiaud 2016.
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.
9 /// Tests the variadic sample element support and the respect of move semantics
10 /// for the datasets definitions
11 // ***************************************************************************
14 #define BOOST_TEST_MODULE test movable return type on datasets test
15 #include <boost/test/unit_test.hpp>
16 #include <boost/test/data/test_case.hpp>
18 #include <boost/test/data/monomorphic/singleton.hpp>
19 #include <boost/test/data/monomorphic/collection.hpp>
20 #include <boost/test/data/for_each_sample.hpp>
23 namespace utf
=boost::unit_test
;
24 namespace bdata
=utf::data
;
30 class non_copyable_type
33 static int nb_rvalue_construct
;
34 static int nb_rvalue_assignment
;
35 static int nb_destructs
;
37 non_copyable_type(const non_copyable_type
&) = delete;
38 non_copyable_type
& operator=(const non_copyable_type
&) = delete;
40 ~non_copyable_type() {
44 non_copyable_type(non_copyable_type
&& rhs
)
48 nb_rvalue_construct
++;
50 non_copyable_type
& operator=(non_copyable_type
&& rhs
) {
53 nb_rvalue_assignment
++;
57 explicit non_copyable_type(const int value
)
62 friend std::ostream
& operator<<(std::ostream
& ost
, const non_copyable_type
& rhs
)
64 ost
<< "non_copyable_type: " << rhs
.value_
<< std::endl
;
76 int non_copyable_type::nb_rvalue_construct
= 0;
77 int non_copyable_type::nb_rvalue_assignment
= 0;
78 int non_copyable_type::nb_destructs
= 0;
80 // Dataset generating a Fibonacci sequence
81 // The return type is either a regular int or a non-movable type
82 template <class return_t
= int>
83 class fibonacci_dataset
{
89 iterator() : a(1), b(1) {}
91 return_t
operator*() const { return return_t(b
); }
99 int b
; // b is the output
102 fibonacci_dataset() {}
105 bdata::size_t size() const { return bdata::BOOST_TEST_DS_INFINITE_SIZE
; }
108 iterator
begin() const { return iterator(); }
111 namespace boost
{ namespace unit_test
{ namespace data
{ namespace monomorphic
{
112 // registering fibonacci_dataset as a proper dataset
114 struct is_dataset
< fibonacci_dataset
<int> > : boost::mpl::true_
{};
117 struct is_dataset
< fibonacci_dataset
<non_copyable_type
> > : boost::mpl::true_
{};
120 // Creating a test-driven dataset
121 BOOST_DATA_TEST_CASE(
123 fibonacci_dataset
<int>() ^ bdata::make( { 1, 2, 3, 5, 8, 13, 21, 34, 55 } ),
126 BOOST_TEST(fib_sample
== exp
);
129 BOOST_DATA_TEST_CASE(
131 fibonacci_dataset
<non_copyable_type
>() ^ bdata::make( { 1, 2, 3, 5, 8, 13, 21, 34, 55 } ),
134 BOOST_TEST(fib_sample
.get() == exp
);
137 //____________________________________________________________________________//