stabilize build system: depends, installer, boost/bdb fixes, cross targets groundwork
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
//!@file
|
||||
//!@brief common dataset macros
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_DATA_CONFIG_HPP_112611GER
|
||||
#define BOOST_TEST_DATA_CONFIG_HPP_112611GER
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/detail/config.hpp>
|
||||
#include <boost/test/detail/throw_exception.hpp>
|
||||
|
||||
// STL
|
||||
#include <stdexcept> // for std::logic_error
|
||||
|
||||
// availability on features: preprocessed by doxygen
|
||||
|
||||
#if defined(BOOST_NO_CXX11_HDR_RANDOM) || defined(BOOST_TEST_DOXYGEN_DOC__)
|
||||
//! Defined when the random dataset feature is not available
|
||||
#define BOOST_TEST_NO_RANDOM_DATASET_AVAILABLE
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_NO_CXX11_HDR_TUPLE) || defined(BOOST_TEST_DOXYGEN_DOC__)
|
||||
|
||||
//! Defined when grid composition of datasets is not available
|
||||
#define BOOST_TEST_NO_GRID_COMPOSITION_AVAILABLE
|
||||
|
||||
//! Defined when zip composition of datasets is not available
|
||||
#define BOOST_TEST_NO_ZIP_COMPOSITION_AVAILABLE
|
||||
|
||||
#endif
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
#define BOOST_TEST_DS_ERROR( msg ) BOOST_TEST_I_THROW( std::logic_error( msg ) )
|
||||
#define BOOST_TEST_DS_ASSERT( cond, msg ) BOOST_TEST_I_ASSRT( cond, std::logic_error( msg ) )
|
||||
|
||||
#endif // BOOST_TEST_DATA_CONFIG_HPP_112611GER
|
||||
@@ -0,0 +1,19 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
//!@file
|
||||
//!@brief dataset interfaces
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_DATA_DATASET_HPP_102211GER
|
||||
#define BOOST_TEST_DATA_DATASET_HPP_102211GER
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/data/monomorphic.hpp>
|
||||
|
||||
#endif // BOOST_TEST_DATA_DATASET_HPP_102211GER
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
/// @file
|
||||
/// Defines for_each_sample algorithm
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_DATA_FOR_EACH_SAMPLE_HPP_102211GER
|
||||
#define BOOST_TEST_DATA_FOR_EACH_SAMPLE_HPP_102211GER
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/data/config.hpp>
|
||||
#include <boost/test/data/size.hpp>
|
||||
#include <boost/test/data/index_sequence.hpp>
|
||||
#include <boost/test/data/monomorphic/sample_merge.hpp>
|
||||
#include <boost/test/data/monomorphic/fwd.hpp>
|
||||
|
||||
// STL
|
||||
#include <tuple>
|
||||
|
||||
#include <boost/test/detail/suppress_warnings.hpp>
|
||||
|
||||
// needed for std::min
|
||||
#include <algorithm>
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace boost {
|
||||
namespace unit_test {
|
||||
namespace data {
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** data::invoke_action ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
template<typename Action, typename T>
|
||||
inline void
|
||||
invoke_action( Action const& action, T && arg, std::false_type /* is_tuple */ )
|
||||
{
|
||||
action( std::forward<T>(arg) );
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
template<typename Action, typename T, std::size_t ...I>
|
||||
inline void
|
||||
invoke_action_impl( Action const& action,
|
||||
T && args,
|
||||
index_sequence<I...> const& )
|
||||
{
|
||||
action( std::get<I>(std::forward<T>(args))... );
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
template<typename Action, typename T>
|
||||
inline void
|
||||
invoke_action( Action const& action, T&& args, std::true_type /* is_tuple */ )
|
||||
{
|
||||
invoke_action_impl( action,
|
||||
std::forward<T>(args),
|
||||
typename make_index_sequence< 0,
|
||||
std::tuple_size<typename std::decay<T>::type>::value
|
||||
>::type{} );
|
||||
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** for_each_sample ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
template<typename DataSet, typename Action>
|
||||
inline typename std::enable_if<monomorphic::is_dataset<DataSet>::value,void>::type
|
||||
for_each_sample( DataSet && samples,
|
||||
Action const& act,
|
||||
data::size_t number_of_samples = BOOST_TEST_DS_INFINITE_SIZE )
|
||||
{
|
||||
data::size_t size = (std::min)( samples.size(), number_of_samples );
|
||||
BOOST_TEST_DS_ASSERT( !size.is_inf(), "Dataset has infinite size. Please specify the number of samples" );
|
||||
|
||||
auto it = samples.begin();
|
||||
|
||||
while( size-- > 0 ) {
|
||||
invoke_action( act,
|
||||
*it,
|
||||
typename monomorphic::ds_detail::is_tuple<decltype(*it)>::type());
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
template<typename DataSet, typename Action>
|
||||
inline typename std::enable_if<!monomorphic::is_dataset<DataSet>::value,void>::type
|
||||
for_each_sample( DataSet && samples,
|
||||
Action const& act,
|
||||
data::size_t number_of_samples = BOOST_TEST_DS_INFINITE_SIZE )
|
||||
{
|
||||
data::for_each_sample( data::make( std::forward<DataSet>(samples) ),
|
||||
act,
|
||||
number_of_samples );
|
||||
}
|
||||
|
||||
} // namespace data
|
||||
} // namespace unit_test
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/test/detail/enable_warnings.hpp>
|
||||
|
||||
#endif // BOOST_TEST_DATA_FOR_EACH_SAMPLE_HPP_102211GER
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
//!@file
|
||||
//!@brief specific generators
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_DATA_MONOMORPHIC_GENERATORS_HPP_112011GER
|
||||
#define BOOST_TEST_DATA_MONOMORPHIC_GENERATORS_HPP_112011GER
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/data/monomorphic/generators/xrange.hpp>
|
||||
|
||||
#endif // BOOST_TEST_DATA_MONOMORPHIC_GENERATORS_HPP_112011GER
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
/// @file
|
||||
/// Defines c++14 index_sequence implementation
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_DATA_INDEX_SEQUENCE_HPP
|
||||
#define BOOST_TEST_DATA_INDEX_SEQUENCE_HPP
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/data/config.hpp>
|
||||
|
||||
#include <boost/test/detail/suppress_warnings.hpp>
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace boost {
|
||||
namespace unit_test {
|
||||
namespace data {
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** data::index_sequence ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
template <std::size_t... Ns>
|
||||
struct index_sequence {};
|
||||
|
||||
template<typename IS1, typename IS2>
|
||||
struct merge_index_sequence;
|
||||
|
||||
template <std::size_t... Ns1, std::size_t... Ns2>
|
||||
struct merge_index_sequence<index_sequence<Ns1...>, index_sequence<Ns2...>> {
|
||||
typedef index_sequence<Ns1..., Ns2...> type;
|
||||
};
|
||||
|
||||
template <std::size_t B, std::size_t E, typename Enabler = void>
|
||||
struct make_index_sequence {
|
||||
typedef typename merge_index_sequence<typename make_index_sequence<B,(B+E)/2>::type,
|
||||
typename make_index_sequence<(B+E)/2,E>::type>::type type;
|
||||
};
|
||||
|
||||
template <std::size_t B, std::size_t E>
|
||||
struct make_index_sequence<B,E,typename std::enable_if<E==B+1,void>::type> {
|
||||
typedef index_sequence<B> type;
|
||||
};
|
||||
|
||||
template <typename... T>
|
||||
using index_sequence_for = typename make_index_sequence<0, sizeof...(T)>::type;
|
||||
|
||||
} // namespace data
|
||||
} // namespace unit_test
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/test/detail/enable_warnings.hpp>
|
||||
|
||||
#endif // BOOST_TEST_DATA_INDEX_SEQUENCE_HPP
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
//!@file
|
||||
//!@brief Monomorphic dataset interfaces
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_DATA_MONOMORPHIC_HPP_102211GER
|
||||
#define BOOST_TEST_DATA_MONOMORPHIC_HPP_102211GER
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/data/monomorphic/array.hpp>
|
||||
#include <boost/test/data/monomorphic/collection.hpp>
|
||||
#include <boost/test/data/monomorphic/initializer_list.hpp>
|
||||
#include <boost/test/data/monomorphic/generate.hpp>
|
||||
#include <boost/test/data/monomorphic/generators.hpp>
|
||||
#include <boost/test/data/monomorphic/grid.hpp>
|
||||
#include <boost/test/data/monomorphic/join.hpp>
|
||||
#include <boost/test/data/monomorphic/singleton.hpp>
|
||||
#include <boost/test/data/monomorphic/zip.hpp>
|
||||
|
||||
#endif // BOOST_TEST_DATA_MONOMORPHIC_HPP_102211GER
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
///@file
|
||||
///Defines monomorphic dataset based on C type arrays
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_DATA_MONOMORPHIC_ARRAY_HPP_121411GER
|
||||
#define BOOST_TEST_DATA_MONOMORPHIC_ARRAY_HPP_121411GER
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/data/config.hpp>
|
||||
#include <boost/test/data/monomorphic/fwd.hpp>
|
||||
|
||||
#include <boost/test/detail/suppress_warnings.hpp>
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace boost {
|
||||
namespace unit_test {
|
||||
namespace data {
|
||||
namespace monomorphic {
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** array ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
/// Dataset view of a C array
|
||||
template<typename T>
|
||||
class array {
|
||||
public:
|
||||
typedef T sample;
|
||||
|
||||
enum { arity = 1 };
|
||||
|
||||
typedef T const* iterator;
|
||||
|
||||
// Constructor
|
||||
array( T const* arr_, std::size_t size_ )
|
||||
: m_arr( arr_ )
|
||||
, m_size( size_ )
|
||||
{}
|
||||
|
||||
// dataset interface
|
||||
data::size_t size() const { return m_size; }
|
||||
iterator begin() const { return m_arr; }
|
||||
|
||||
private:
|
||||
// Data members
|
||||
T const* m_arr;
|
||||
std::size_t m_size;
|
||||
};
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
//! An array dataset is a dataset
|
||||
template<typename T>
|
||||
struct is_dataset<array<T>> : mpl::true_ {};
|
||||
|
||||
} // namespace monomorphic
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
//! @overload boost::unit_test::data::make()
|
||||
template<typename T, std::size_t size>
|
||||
inline monomorphic::array<typename boost::remove_const<T>::type>
|
||||
make( T (&a)[size] )
|
||||
{
|
||||
return monomorphic::array<typename boost::remove_const<T>::type>( a, size );
|
||||
}
|
||||
|
||||
} // namespace data
|
||||
} // namespace unit_test
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/test/detail/enable_warnings.hpp>
|
||||
|
||||
#endif // BOOST_TEST_DATA_MONOMORPHIC_ARRAY_HPP_121411GER
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
///@file
|
||||
///Defines monomorphic dataset based on forward iterable sequence
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_DATA_MONOMORPHIC_COLLECTION_HPP_102211GER
|
||||
#define BOOST_TEST_DATA_MONOMORPHIC_COLLECTION_HPP_102211GER
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/data/config.hpp>
|
||||
#include <boost/test/data/monomorphic/fwd.hpp>
|
||||
|
||||
#include <boost/test/detail/suppress_warnings.hpp>
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace boost {
|
||||
namespace unit_test {
|
||||
namespace data {
|
||||
namespace monomorphic {
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** collection ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
|
||||
//!@brief Dataset from a forward iterable container (collection)
|
||||
//!
|
||||
//! This dataset is applicable to any container implementing a forward iterator. Note that
|
||||
//! container with one element will be considered as singletons.
|
||||
//! This dataset is constructible with the @ref boost::unit_test::data::make function.
|
||||
template<typename C>
|
||||
class collection {
|
||||
typedef typename boost::decay<C>::type col_type;
|
||||
public:
|
||||
typedef typename col_type::value_type sample;
|
||||
|
||||
enum { arity = 1 };
|
||||
|
||||
typedef typename col_type::const_iterator iterator;
|
||||
|
||||
//! Constructor consumed a temporary collection or stores a reference
|
||||
explicit collection( C&& col ) : m_col( std::forward<C>(col) ) {}
|
||||
|
||||
//! Move constructor
|
||||
collection( collection&& c ) : m_col( std::forward<C>( c.m_col ) ) {}
|
||||
|
||||
//! Returns the underlying collection
|
||||
C const& col() const { return m_col; }
|
||||
|
||||
//! dataset interface
|
||||
data::size_t size() const { return m_col.size(); }
|
||||
iterator begin() const { return m_col.begin(); }
|
||||
|
||||
private:
|
||||
// Data members
|
||||
C m_col;
|
||||
};
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
//! A collection from a forward iterable container is a dataset.
|
||||
template<typename C>
|
||||
struct is_dataset<collection<C>> : mpl::true_ {};
|
||||
|
||||
} // namespace monomorphic
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
//! @overload boost::unit_test::data::make()
|
||||
template<typename C>
|
||||
inline typename std::enable_if<is_forward_iterable<C>::value,monomorphic::collection<C>>::type
|
||||
make( C&& c )
|
||||
{
|
||||
return monomorphic::collection<C>( std::forward<C>(c) );
|
||||
}
|
||||
|
||||
} // namespace data
|
||||
} // namespace unit_test
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/test/detail/enable_warnings.hpp>
|
||||
|
||||
#endif // BOOST_TEST_DATA_MONOMORPHIC_COLLECTION_HPP_102211GER
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
/// @file
|
||||
/// Forward declares monomorphic datasets interfaces
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_DATA_MONOMORPHIC_FWD_HPP_102212GER
|
||||
#define BOOST_TEST_DATA_MONOMORPHIC_FWD_HPP_102212GER
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/data/config.hpp>
|
||||
#include <boost/test/data/size.hpp>
|
||||
|
||||
#include <boost/test/utils/is_forward_iterable.hpp>
|
||||
|
||||
// Boost
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
#include <boost/type_traits/is_array.hpp>
|
||||
#include <boost/mpl/bool.hpp>
|
||||
|
||||
// STL
|
||||
#include <tuple>
|
||||
|
||||
#include <boost/test/detail/suppress_warnings.hpp>
|
||||
|
||||
// STL
|
||||
#include <initializer_list>
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace boost {
|
||||
namespace unit_test {
|
||||
namespace data {
|
||||
|
||||
namespace monomorphic {
|
||||
|
||||
|
||||
#if !defined(BOOST_TEST_DOXYGEN_DOC__)
|
||||
|
||||
template<typename T, typename Specific>
|
||||
class dataset;
|
||||
|
||||
template<typename T>
|
||||
class singleton;
|
||||
|
||||
template<typename C>
|
||||
class collection;
|
||||
|
||||
template<typename T>
|
||||
class array;
|
||||
|
||||
template<typename T>
|
||||
class init_list;
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** monomorphic::is_dataset ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
//! Helper metafunction indicating if the specified type is a dataset.
|
||||
template<typename DataSet>
|
||||
struct is_dataset : mpl::false_ {};
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
//! A reference to a dataset is a dataset
|
||||
template<typename DataSet>
|
||||
struct is_dataset<DataSet&> : is_dataset<DataSet> {};
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
//! A const dataset is a dataset
|
||||
template<typename DataSet>
|
||||
struct is_dataset<DataSet const> : is_dataset<DataSet> {};
|
||||
|
||||
} // namespace monomorphic
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** data::make ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
//! @brief Creates a dataset from a value, a collection or an array
|
||||
//!
|
||||
//! This function has several overloads:
|
||||
//! @code
|
||||
//! // returns ds if ds is already a dataset
|
||||
//! template <typename DataSet> DataSet make(DataSet&& ds);
|
||||
//!
|
||||
//! // creates a singleton dataset, for non forward iterable and non dataset type T
|
||||
//! // (a C string is not considered as a sequence).
|
||||
//! template <typename T> monomorphic::singleton<T> make(T&& v);
|
||||
//! monomorphic::singleton<char*> make( char* str );
|
||||
//! monomorphic::singleton<char const*> make( char const* str );
|
||||
//!
|
||||
//! // creates a collection dataset, for forward iterable and non dataset type C
|
||||
//! template <typename C> monomorphic::collection<C> make(C && c);
|
||||
//!
|
||||
//! // creates an array dataset
|
||||
//! template<typename T, std::size_t size> monomorphic::array<T> make( T (&a)[size] );
|
||||
//! @endcode
|
||||
template<typename DataSet>
|
||||
inline typename std::enable_if<monomorphic::is_dataset<DataSet>::value,DataSet>::type
|
||||
make(DataSet&& ds)
|
||||
{
|
||||
return std::forward<DataSet>( ds );
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
// warning: doxygen is apparently unable to handle @overload from different files, so if the overloads
|
||||
// below are not declared with @overload in THIS file, they do not appear in the documentation.
|
||||
|
||||
//! @overload boost::unit_test::data::make()
|
||||
template<typename T>
|
||||
inline typename std::enable_if<!is_forward_iterable<T>::value &&
|
||||
!monomorphic::is_dataset<T>::value &&
|
||||
!is_array<typename remove_reference<T>::type>::value,
|
||||
monomorphic::singleton<T>>::type
|
||||
make( T&& v );
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
//! @overload boost::unit_test::data::make()
|
||||
template<typename C>
|
||||
inline typename std::enable_if<is_forward_iterable<C>::value,monomorphic::collection<C>>::type
|
||||
make( C&& c );
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
//! @overload boost::unit_test::data::make()
|
||||
template<typename T, std::size_t size>
|
||||
inline monomorphic::array< typename boost::remove_const<T>::type >
|
||||
make( T (&a)[size] );
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
//! @overload boost::unit_test::data::make()
|
||||
inline monomorphic::singleton<char*>
|
||||
make( char* str );
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
//! @overload boost::unit_test::data::make()
|
||||
inline monomorphic::singleton<char const*>
|
||||
make( char const* str );
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
//! @overload boost::unit_test::data::make()
|
||||
template<typename T>
|
||||
inline monomorphic::init_list<T>
|
||||
make( std::initializer_list<T>&& );
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace result_of {
|
||||
|
||||
//! Result of the make call.
|
||||
template<typename DataSet>
|
||||
struct make {
|
||||
typedef decltype( data::make( declval<DataSet>() ) ) type;
|
||||
};
|
||||
|
||||
} // namespace result_of
|
||||
|
||||
} // namespace data
|
||||
} // namespace unit_test
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/test/detail/enable_warnings.hpp>
|
||||
|
||||
#endif // BOOST_TEST_DATA_MONOMORPHIC_FWD_HPP_102212GER
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
/// @file
|
||||
/// Defines generic interface for monomorphic dataset based on generator
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_DATA_MONOMORPHIC_GENERATE_HPP_112011GER
|
||||
#define BOOST_TEST_DATA_MONOMORPHIC_GENERATE_HPP_112011GER
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/data/config.hpp>
|
||||
#include <boost/test/data/monomorphic/fwd.hpp>
|
||||
|
||||
#include <boost/test/detail/suppress_warnings.hpp>
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace boost {
|
||||
namespace unit_test {
|
||||
namespace data {
|
||||
namespace monomorphic {
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** generated_by ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
/*!@brief Generators interface
|
||||
*
|
||||
* This class implements the dataset concept over a generator. Examples of generators are:
|
||||
* - xrange_t
|
||||
* - random_t
|
||||
*
|
||||
* The generator concept is the following:
|
||||
* - the type of the generated samples is given by field @c sample
|
||||
* - the member function @c capacity should return the size of the collection being generated (potentially infinite)
|
||||
* - the member function @c next should change the state of the generator to the next generated value
|
||||
* - the member function @c reset should put the state of the object in the same state as right after its instanciation
|
||||
*/
|
||||
template<typename Generator>
|
||||
class generated_by {
|
||||
public:
|
||||
typedef typename Generator::sample sample;
|
||||
|
||||
enum { arity = 1 };
|
||||
|
||||
struct iterator {
|
||||
// Constructor
|
||||
explicit iterator( Generator& gen )
|
||||
: m_gen( &gen )
|
||||
{
|
||||
if(m_gen->capacity() > 0) {
|
||||
m_gen->reset();
|
||||
++*this;
|
||||
}
|
||||
}
|
||||
|
||||
// forward iterator interface
|
||||
sample const& operator*() const { return m_curr_sample; }
|
||||
void operator++() { m_curr_sample = m_gen->next(); }
|
||||
|
||||
private:
|
||||
// Data members
|
||||
Generator* m_gen;
|
||||
sample m_curr_sample;
|
||||
};
|
||||
|
||||
typedef Generator generator_type;
|
||||
|
||||
// Constructor
|
||||
explicit generated_by( Generator&& G )
|
||||
: m_generator( std::forward<Generator>(G) )
|
||||
{}
|
||||
|
||||
// Move constructor
|
||||
generated_by( generated_by&& rhs )
|
||||
: m_generator( std::forward<Generator>(rhs.m_generator) )
|
||||
{}
|
||||
|
||||
//! Size of the underlying dataset
|
||||
data::size_t size() const { return m_generator.capacity(); }
|
||||
|
||||
//! Iterator on the beginning of the dataset
|
||||
iterator begin() const { return iterator( boost::ref(const_cast<Generator&>(m_generator)) ); }
|
||||
|
||||
private:
|
||||
// Data members
|
||||
Generator m_generator;
|
||||
};
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
//! A generated dataset is a dataset.
|
||||
template<typename Generator>
|
||||
struct is_dataset<generated_by<Generator>> : mpl::true_ {};
|
||||
|
||||
} // namespace monomorphic
|
||||
} // namespace data
|
||||
} // namespace unit_test
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/test/detail/enable_warnings.hpp>
|
||||
|
||||
#endif // BOOST_TEST_DATA_MONOMORPHIC_GENERATE_HPP_112011GER
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
///@file
|
||||
///Defines specific generators
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_DATA_MONOMORPHIC_GENERATORS_HPP_112011GER
|
||||
#define BOOST_TEST_DATA_MONOMORPHIC_GENERATORS_HPP_112011GER
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/data/monomorphic/generators/xrange.hpp>
|
||||
#include <boost/test/data/monomorphic/generators/random.hpp>
|
||||
|
||||
#endif // BOOST_TEST_DATA_MONOMORPHIC_GENERATORS_HPP_112011GER
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
///@file
|
||||
/// Keywords used in generator interfaces
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_DATA_MONOMORPHIC_GENERATORS_KEYWORDS_HPP_101512GER
|
||||
#define BOOST_TEST_DATA_MONOMORPHIC_GENERATORS_KEYWORDS_HPP_101512GER
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/data/config.hpp>
|
||||
#include <boost/test/utils/named_params.hpp>
|
||||
|
||||
#include <boost/test/detail/suppress_warnings.hpp>
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace boost {
|
||||
namespace unit_test {
|
||||
namespace data {
|
||||
|
||||
namespace {
|
||||
nfp::keyword<struct begin_t> begin;
|
||||
nfp::keyword<struct end_t> end;
|
||||
nfp::keyword<struct step_t> step;
|
||||
} // local namespace
|
||||
|
||||
} // namespace data
|
||||
} // namespace unit_test
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/test/detail/enable_warnings.hpp>
|
||||
|
||||
#endif // BOOST_TEST_DATA_MONOMORPHIC_GENERATORS_KEYWORDS_HPP_101512GER
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
//!@file
|
||||
//!@brief Random generator
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_DATA_MONOMORPHIC_GENERATORS_RANDOM_HPP_101512GER
|
||||
#define BOOST_TEST_DATA_MONOMORPHIC_GENERATORS_RANDOM_HPP_101512GER
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/data/config.hpp>
|
||||
|
||||
|
||||
|
||||
|
||||
#if !defined(BOOST_TEST_NO_RANDOM_DATASET_AVAILABLE) || defined(BOOST_TEST_DOXYGEN_DOC__)
|
||||
|
||||
#include <boost/test/data/monomorphic/generate.hpp>
|
||||
#include <boost/test/data/monomorphic/generators/keywords.hpp>
|
||||
|
||||
// STL
|
||||
#include <random>
|
||||
|
||||
#include <boost/test/detail/suppress_warnings.hpp>
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace boost {
|
||||
namespace unit_test {
|
||||
namespace data {
|
||||
|
||||
namespace {
|
||||
nfp::keyword<struct seed_t> seed;
|
||||
nfp::keyword<struct distribution_t> distribution;
|
||||
nfp::keyword<struct engine_t> engine;
|
||||
} // local namespace
|
||||
|
||||
namespace monomorphic {
|
||||
|
||||
namespace ds_detail {
|
||||
template<typename SampleType>
|
||||
struct default_distribution {
|
||||
typedef typename mpl::if_<std::is_integral<SampleType>,
|
||||
std::uniform_int_distribution<SampleType>,
|
||||
std::uniform_real_distribution<SampleType>>::type type;
|
||||
};
|
||||
|
||||
} // namespace ds_detail
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** random_t ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
/*!@brief Generator for the random sequences
|
||||
*
|
||||
* This class implements the generator concept (see @ref boost::unit_test::data::monomorphic::generated_by) for implementing
|
||||
* a random number generator.
|
||||
*/
|
||||
template<typename SampleType = double,
|
||||
typename DistributionType = typename ds_detail::default_distribution<SampleType>::type,
|
||||
typename EngineType = std::default_random_engine>
|
||||
class random_t {
|
||||
public:
|
||||
typedef SampleType sample;
|
||||
typedef DistributionType distr_type;
|
||||
typedef EngineType engine_type;
|
||||
|
||||
random_t()
|
||||
: m_distribution()
|
||||
, m_engine( std::random_device()() )
|
||||
{}
|
||||
explicit random_t( distr_type&& d )
|
||||
: m_distribution( std::forward<distr_type>(d) )
|
||||
, m_engine( std::random_device()() ){}
|
||||
random_t( engine_type&& e, distr_type&& d )
|
||||
: m_distribution( std::forward<distr_type>(d) )
|
||||
, m_engine( std::forward<engine_type>(e) ){}
|
||||
|
||||
// Generator interface
|
||||
data::size_t capacity() const { return BOOST_TEST_DS_INFINITE_SIZE; }
|
||||
SampleType next()
|
||||
{
|
||||
return m_distribution( m_engine );
|
||||
}
|
||||
void reset() {}
|
||||
|
||||
//! Sets the seed of the pseudo-random number engine.
|
||||
template<typename SeedType>
|
||||
void seed( SeedType&& seed ) { m_engine.seed( std::forward<SeedType>( seed ) ); }
|
||||
|
||||
private:
|
||||
// Data members
|
||||
DistributionType m_distribution;
|
||||
EngineType m_engine;
|
||||
};
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
} // namespace monomorphic
|
||||
|
||||
|
||||
//! @brief Returns an infinite sequence of random numbers.
|
||||
//!
|
||||
//! The following overloads are available:
|
||||
//! @code
|
||||
//! auto d = random();
|
||||
//! auto d = random(begin, end);
|
||||
//! auto d = random(params);
|
||||
//! @endcode
|
||||
//!
|
||||
//!
|
||||
//! - The first overload uses the default distribution, which is uniform and which elements
|
||||
//! are @c double type (the values are in [0, 1) ).
|
||||
//! - The second overload generates numbers in the given interval. The distribution is uniform (in [begin, end)
|
||||
//! for real numbers, and in [begin, end] for integers). The type of the distribution is deduced from the type
|
||||
//! of the @c begin and @c end parameters.
|
||||
//! - The third overload generates numbers using the named parameter inside @c params , which are:
|
||||
//! - @c distribution: the distribution used. In this overload, since the type of the samples cannot be deduced,
|
||||
//! the samples are of type @c double and the distribution is uniform real in [0, 1).
|
||||
//! - @c seed: the seed for generating the values
|
||||
//! - @c engine: the random number generator engine
|
||||
//!
|
||||
//! The function returns an object that implements the dataset API.
|
||||
//! @note This function is available only for C++11 capable compilers.
|
||||
inline monomorphic::generated_by< monomorphic::random_t<>> random()
|
||||
{
|
||||
return monomorphic::generated_by<monomorphic::random_t<>>( monomorphic::random_t<>() );
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
/// @overload boost::unit_test::data::random()
|
||||
template<typename SampleType>
|
||||
inline monomorphic::generated_by< monomorphic::random_t<SampleType>>
|
||||
random( SampleType begin, SampleType end )
|
||||
{
|
||||
typedef monomorphic::random_t<SampleType> Gen;
|
||||
typedef typename Gen::distr_type distr_type;
|
||||
return monomorphic::generated_by<Gen>( Gen( distr_type(begin,end) ) );
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace ds_detail {
|
||||
template<typename Params>
|
||||
struct random_gen_type {
|
||||
typedef typename nfp::param_type<Params,decltype(distribution),std::uniform_real_distribution<>>::type distr_type;
|
||||
typedef typename nfp::param_type<Params,decltype(engine),std::default_random_engine>::type engine_type;
|
||||
typedef typename distr_type::result_type sample_type;
|
||||
|
||||
typedef monomorphic::random_t<sample_type,distr_type,engine_type> type;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// @overload boost::unit_test::data::random()
|
||||
template<typename Params>
|
||||
inline monomorphic::generated_by<typename ds_detail::random_gen_type<Params>::type>
|
||||
random( Params const& params )
|
||||
{
|
||||
typedef typename ds_detail::random_gen_type<Params>::type Gen;
|
||||
typedef typename Gen::distr_type distr_type;
|
||||
typedef typename Gen::engine_type engine_type;
|
||||
|
||||
std::random_device rd;
|
||||
engine_type E;
|
||||
// engine_type E( rd );
|
||||
if( params.has(engine) )
|
||||
E = params[engine];
|
||||
|
||||
distr_type D;
|
||||
if( params.has(distribution) )
|
||||
D = params[distribution];
|
||||
|
||||
Gen G( std::move(E), std::move(D) );
|
||||
|
||||
if( params.has(seed) )
|
||||
G.seed( params[seed] );
|
||||
|
||||
return monomorphic::generated_by<Gen>( std::move(G) );
|
||||
}
|
||||
|
||||
} // namespace data
|
||||
} // namespace unit_test
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/test/detail/enable_warnings.hpp>
|
||||
|
||||
#endif // BOOST_TEST_NO_RANDOM_DATASET_AVAILABLE
|
||||
|
||||
|
||||
#endif // BOOST_TEST_DATA_MONOMORPHIC_GENERATORS_RANDOM_HPP_101512GER
|
||||
+224
@@ -0,0 +1,224 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
///@file
|
||||
///Defines range generator
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_DATA_MONOMORPHIC_GENERATORS_XRANGE_HPP_112011GER
|
||||
#define BOOST_TEST_DATA_MONOMORPHIC_GENERATORS_XRANGE_HPP_112011GER
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/data/config.hpp>
|
||||
|
||||
#include <boost/test/data/monomorphic/generators/keywords.hpp>
|
||||
#include <boost/test/data/monomorphic/generate.hpp>
|
||||
|
||||
// Boost
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits/is_unsigned.hpp>
|
||||
|
||||
// STL
|
||||
#include <limits>
|
||||
#include <cmath>
|
||||
|
||||
#include <boost/test/detail/suppress_warnings.hpp>
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace boost {
|
||||
namespace unit_test {
|
||||
namespace data {
|
||||
namespace monomorphic {
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** monomorphic::xrange_t ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
|
||||
/*!@brief Generator for the range sequences
|
||||
*
|
||||
* This class implements the generator concept (see @ref boost::unit_test::data::monomorphic::generated_by) for implementing
|
||||
* a range like sequence of numbers.
|
||||
*/
|
||||
template<typename SampleType, typename StepType=SampleType>
|
||||
class xrange_t {
|
||||
public:
|
||||
typedef SampleType sample;
|
||||
|
||||
xrange_t( SampleType const& begin_, StepType const& step_, data::size_t size_ )
|
||||
: m_begin( begin_ )
|
||||
, m_curr( begin_ )
|
||||
, m_step( step_ )
|
||||
, m_index( 0 )
|
||||
, m_size( size_ )
|
||||
{}
|
||||
|
||||
// Generator interface
|
||||
data::size_t capacity() const { return m_size; }
|
||||
SampleType next()
|
||||
{
|
||||
if( m_index == m_size )
|
||||
return m_curr;
|
||||
|
||||
SampleType res = m_curr;
|
||||
|
||||
m_curr += m_step;
|
||||
++m_index;
|
||||
|
||||
return res;
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
m_curr = m_begin;
|
||||
m_index = 0;
|
||||
}
|
||||
|
||||
private:
|
||||
// Data members
|
||||
SampleType m_begin;
|
||||
SampleType m_curr;
|
||||
StepType m_step;
|
||||
data::size_t m_index;
|
||||
data::size_t m_size;
|
||||
};
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace ds_detail {
|
||||
|
||||
template<typename SampleType, typename StepType=SampleType>
|
||||
struct make_xrange {
|
||||
static StepType abs( StepType s, boost::true_type* ) { return s; }
|
||||
static StepType abs( StepType s, boost::false_type* ) { return std::abs(s); }
|
||||
|
||||
typedef xrange_t<SampleType, StepType> range_gen;
|
||||
|
||||
template<typename Params>
|
||||
static generated_by<range_gen>
|
||||
_( Params const& params )
|
||||
{
|
||||
SampleType begin_val = params.has( data::begin ) ? params[data::begin] : SampleType();
|
||||
optional<SampleType> end_val = params.has( data::end ) ? params[data::end] : optional<SampleType>();
|
||||
StepType step_val = params.has( data::step ) ? params[data::step] : 1;
|
||||
|
||||
BOOST_TEST_DS_ASSERT( step_val != 0, "Range step can't be zero" );
|
||||
|
||||
data::size_t size;
|
||||
if( !end_val.is_initialized() )
|
||||
size = BOOST_TEST_DS_INFINITE_SIZE;
|
||||
else {
|
||||
BOOST_TEST_DS_ASSERT( (step_val < 0) ^ (begin_val < *end_val), "Invalid step direction" );
|
||||
|
||||
SampleType abs_distance = step_val < 0 ? begin_val - *end_val : *end_val-begin_val;
|
||||
StepType abs_step = make_xrange::abs(step_val, (typename boost::is_unsigned<StepType>::type*)0 );
|
||||
std::size_t s = static_cast<std::size_t>(abs_distance/abs_step);
|
||||
|
||||
if( static_cast<SampleType>(s*abs_step) < abs_distance )
|
||||
s++;
|
||||
|
||||
size = s;
|
||||
}
|
||||
|
||||
return generated_by<range_gen>( range_gen( begin_val, step_val, size ) );
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ds_detail
|
||||
} // namespace monomorphic
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
//! Creates a range (sequence) dataset.
|
||||
//!
|
||||
//! The following overloads are available:
|
||||
//! @code
|
||||
//! auto d = xrange();
|
||||
//! auto d = xrange(end_val);
|
||||
//! auto d = xrange(end_val, param);
|
||||
//! auto d = xrange(begin_val, end_val);
|
||||
//! auto d = xrange(begin_val, end_val, step_val);
|
||||
//! auto d = xrange(param);
|
||||
//! @endcode
|
||||
//!
|
||||
//! - @c begin_val indicates the start of the sequence (default to 0).
|
||||
//! - @c end_val is the end of the sequence. If ommited, the dataset has infinite size.\n
|
||||
//! - @c step_val is the step between two consecutive elements of the sequence, and defaults to 1.\n
|
||||
//! - @c param is the named parameters that describe the sequence. The following parameters are accepted:
|
||||
//! - @c begin: same meaning @c begin_val
|
||||
//! - @c end: same meaning as @c end_val
|
||||
//! - @c step: same meaning as @c step_val
|
||||
//!
|
||||
//!
|
||||
//! The returned value is an object that implements the dataset API.
|
||||
//!
|
||||
//! @note the step size cannot be null, and it should be positive if @c begin_val < @c end_val, negative otherwise.
|
||||
template<typename SampleType, typename Params>
|
||||
inline monomorphic::generated_by<monomorphic::xrange_t<SampleType>>
|
||||
xrange( Params const& params )
|
||||
{
|
||||
return monomorphic::ds_detail::make_xrange<SampleType>::_( params );
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
/// @overload boost::unit_test::data::xrange()
|
||||
template<typename SampleType>
|
||||
inline monomorphic::generated_by<monomorphic::xrange_t<SampleType>>
|
||||
xrange( SampleType const& end_val )
|
||||
{
|
||||
return monomorphic::ds_detail::make_xrange<SampleType>::_( data::end=end_val );
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
/// @overload boost::unit_test::data::xrange()
|
||||
template<typename SampleType, typename Params>
|
||||
inline typename enable_if_c<nfp::is_named_param_pack<Params>::value,
|
||||
monomorphic::generated_by<monomorphic::xrange_t<SampleType>>>::type
|
||||
xrange( SampleType const& end_val, Params const& params )
|
||||
{
|
||||
return monomorphic::ds_detail::make_xrange<SampleType>::_(( params, data::end=end_val ));
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
/// @overload boost::unit_test::data::xrange()
|
||||
template<typename SampleType>
|
||||
inline monomorphic::generated_by<monomorphic::xrange_t<SampleType>>
|
||||
xrange( SampleType const& begin_val, SampleType const& end_val )
|
||||
{
|
||||
return monomorphic::ds_detail::make_xrange<SampleType>::_((
|
||||
data::begin=begin_val,
|
||||
data::end=end_val ));
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
|
||||
|
||||
/// @overload boost::unit_test::data::xrange()
|
||||
template<typename SampleType,typename StepType>
|
||||
inline monomorphic::generated_by<monomorphic::xrange_t<SampleType>>
|
||||
xrange( SampleType const& begin_val, SampleType const& end_val, StepType const& step_val )
|
||||
{
|
||||
return monomorphic::ds_detail::make_xrange<SampleType,StepType>::_((
|
||||
data::begin=begin_val,
|
||||
data::end=end_val,
|
||||
data::step=step_val ));
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
} // namespace data
|
||||
} // namespace unit_test
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/test/detail/enable_warnings.hpp>
|
||||
|
||||
#endif // BOOST_TEST_DATA_MONOMORPHIC_GENERATORS_XRANGE_HPP_112011GER
|
||||
@@ -0,0 +1,181 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
///@file
|
||||
/// Defines monomorphic dataset n+m dimentional *. Samples in this
|
||||
/// dataset is grid of elements in DataSet1 and DataSet2. There will be total
|
||||
/// |DataSet1| * |DataSet2| samples
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_DATA_MONOMORPHIC_GRID_HPP_101512GER
|
||||
#define BOOST_TEST_DATA_MONOMORPHIC_GRID_HPP_101512GER
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/data/config.hpp>
|
||||
|
||||
#if !defined(BOOST_TEST_NO_GRID_COMPOSITION_AVAILABLE) || defined(BOOST_TEST_DOXYGEN_DOC__)
|
||||
|
||||
#include <boost/test/data/monomorphic/fwd.hpp>
|
||||
#include <boost/test/data/monomorphic/sample_merge.hpp>
|
||||
|
||||
#include <boost/test/detail/suppress_warnings.hpp>
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace boost {
|
||||
namespace unit_test {
|
||||
namespace data {
|
||||
namespace monomorphic {
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** grid ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
|
||||
//! Implements the dataset resulting from a cartesian product/grid operation on datasets.
|
||||
//!
|
||||
//! The arity of the resulting dataset is the sum of the arity of its operands.
|
||||
template<typename DataSet1, typename DataSet2>
|
||||
class grid {
|
||||
typedef typename boost::decay<DataSet1>::type dataset1_decay;
|
||||
typedef typename boost::decay<DataSet2>::type dataset2_decay;
|
||||
|
||||
typedef typename dataset1_decay::iterator dataset1_iter;
|
||||
typedef typename dataset2_decay::iterator dataset2_iter;
|
||||
|
||||
public:
|
||||
|
||||
struct iterator {
|
||||
// Constructor
|
||||
explicit iterator( dataset1_iter iter1, DataSet2 const& ds2 )
|
||||
: m_iter1( std::move( iter1 ) )
|
||||
, m_iter2( std::move( ds2.begin() ) )
|
||||
, m_ds2( &ds2 )
|
||||
, m_ds2_pos( 0 )
|
||||
{}
|
||||
|
||||
using iterator_sample = decltype(
|
||||
sample_merge( *std::declval<dataset1_iter>(),
|
||||
*std::declval<dataset2_iter>()) );
|
||||
|
||||
// forward iterator interface
|
||||
auto operator*() const -> iterator_sample {
|
||||
return sample_merge( *m_iter1, *m_iter2 );
|
||||
}
|
||||
void operator++()
|
||||
{
|
||||
++m_ds2_pos;
|
||||
if( m_ds2_pos != m_ds2->size() )
|
||||
++m_iter2;
|
||||
else {
|
||||
m_ds2_pos = 0;
|
||||
++m_iter1;
|
||||
m_iter2 = std::move( m_ds2->begin() );
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// Data members
|
||||
dataset1_iter m_iter1;
|
||||
dataset2_iter m_iter2;
|
||||
dataset2_decay const* m_ds2;
|
||||
data::size_t m_ds2_pos;
|
||||
};
|
||||
|
||||
public:
|
||||
enum { arity = boost::decay<DataSet1>::type::arity + boost::decay<DataSet2>::type::arity };
|
||||
|
||||
//! Constructor
|
||||
grid( DataSet1&& ds1, DataSet2&& ds2 )
|
||||
: m_ds1( std::forward<DataSet1>( ds1 ) )
|
||||
, m_ds2( std::forward<DataSet2>( ds2 ) )
|
||||
{}
|
||||
|
||||
//! Move constructor
|
||||
grid( grid&& j )
|
||||
: m_ds1( std::forward<DataSet1>( j.m_ds1 ) )
|
||||
, m_ds2( std::forward<DataSet2>( j.m_ds2 ) )
|
||||
{}
|
||||
|
||||
// dataset interface
|
||||
data::size_t size() const { return m_ds1.size() * m_ds2.size(); }
|
||||
iterator begin() const { return iterator( m_ds1.begin(), m_ds2 ); }
|
||||
|
||||
private:
|
||||
// Data members
|
||||
DataSet1 m_ds1;
|
||||
DataSet2 m_ds2;
|
||||
};
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
// A grid dataset is a dataset
|
||||
template<typename DataSet1, typename DataSet2>
|
||||
struct is_dataset<grid<DataSet1,DataSet2>> : mpl::true_ {};
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace result_of {
|
||||
|
||||
/// Result type of the grid operation on dataset.
|
||||
template<typename DS1Gen, typename DS2Gen>
|
||||
struct grid {
|
||||
typedef monomorphic::grid<typename DS1Gen::type,typename DS2Gen::type> type;
|
||||
};
|
||||
|
||||
} // namespace result_of
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
//! Grid operation
|
||||
template<typename DataSet1, typename DataSet2>
|
||||
inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && is_dataset<DataSet2>::value,
|
||||
result_of::grid<mpl::identity<DataSet1>,mpl::identity<DataSet2>>
|
||||
>::type
|
||||
operator*( DataSet1&& ds1, DataSet2&& ds2 )
|
||||
{
|
||||
BOOST_TEST_DS_ASSERT( !ds1.size().is_inf() && !ds2.size().is_inf(), "Grid axes can't have infinite size" );
|
||||
|
||||
return grid<DataSet1,DataSet2>( std::forward<DataSet1>( ds1 ), std::forward<DataSet2>( ds2 ) );
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
//! @overload boost::unit_test::data::operator*
|
||||
template<typename DataSet1, typename DataSet2>
|
||||
inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && !is_dataset<DataSet2>::value,
|
||||
result_of::grid<mpl::identity<DataSet1>,data::result_of::make<DataSet2>>
|
||||
>::type
|
||||
operator*( DataSet1&& ds1, DataSet2&& ds2 )
|
||||
{
|
||||
return std::forward<DataSet1>(ds1) * data::make(std::forward<DataSet2>(ds2));
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
//! @overload boost::unit_test::data::operator*
|
||||
template<typename DataSet1, typename DataSet2>
|
||||
inline typename boost::lazy_enable_if_c<!is_dataset<DataSet1>::value && is_dataset<DataSet2>::value,
|
||||
result_of::grid<data::result_of::make<DataSet1>,mpl::identity<DataSet2>>
|
||||
>::type
|
||||
operator*( DataSet1&& ds1, DataSet2&& ds2 )
|
||||
{
|
||||
return data::make(std::forward<DataSet1>(ds1)) * std::forward<DataSet2>(ds2);
|
||||
}
|
||||
|
||||
} // namespace monomorphic
|
||||
|
||||
} // namespace data
|
||||
} // namespace unit_test
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/test/detail/enable_warnings.hpp>
|
||||
|
||||
#endif // BOOST_TEST_NO_GRID_COMPOSITION_AVAILABLE
|
||||
|
||||
#endif // BOOST_TEST_DATA_MONOMORPHIC_GRID_HPP_101512GER
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
///@file
|
||||
///Defines monomorphic dataset based on C++11 initializer_list template
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_DATA_MONOMORPHIC_INITIALIZATION_LIST_HPP_091515GER
|
||||
#define BOOST_TEST_DATA_MONOMORPHIC_INITIALIZATION_LIST_HPP_091515GER
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/data/config.hpp>
|
||||
#include <boost/test/data/monomorphic/fwd.hpp>
|
||||
|
||||
#include <boost/test/detail/suppress_warnings.hpp>
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace boost {
|
||||
namespace unit_test {
|
||||
namespace data {
|
||||
namespace monomorphic {
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** array ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
/// Dataset view of a C array
|
||||
template<typename T>
|
||||
class init_list {
|
||||
public:
|
||||
typedef T sample;
|
||||
|
||||
enum { arity = 1 };
|
||||
|
||||
typedef T const* iterator;
|
||||
|
||||
//! Constructor swallows initializer_list
|
||||
init_list( std::initializer_list<T>&& il )
|
||||
: m_data( std::forward<std::initializer_list<T>>( il ) )
|
||||
{}
|
||||
|
||||
//! dataset interface
|
||||
data::size_t size() const { return m_data.size(); }
|
||||
iterator begin() const { return m_data.begin(); }
|
||||
|
||||
private:
|
||||
// Data members
|
||||
std::initializer_list<T> m_data;
|
||||
};
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
//! An array dataset is a dataset
|
||||
template<typename T>
|
||||
struct is_dataset<init_list<T>> : mpl::true_ {};
|
||||
|
||||
} // namespace monomorphic
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
//! @overload boost::unit_test::data::make()
|
||||
template<typename T>
|
||||
inline monomorphic::init_list<T>
|
||||
make( std::initializer_list<T>&& il )
|
||||
{
|
||||
return monomorphic::init_list<T>( std::forward<std::initializer_list<T>>( il ) );
|
||||
}
|
||||
|
||||
} // namespace data
|
||||
} // namespace unit_test
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/test/detail/enable_warnings.hpp>
|
||||
|
||||
#endif // BOOST_TEST_DATA_MONOMORPHIC_INITIALIZATION_LIST_HPP_091515GER
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
//! @file
|
||||
//! Defines dataset join operation
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_DATA_MONOMORPHIC_JOIN_HPP_112711GER
|
||||
#define BOOST_TEST_DATA_MONOMORPHIC_JOIN_HPP_112711GER
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/data/config.hpp>
|
||||
#include <boost/test/data/monomorphic/fwd.hpp>
|
||||
|
||||
#include <boost/test/detail/suppress_warnings.hpp>
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace boost {
|
||||
namespace unit_test {
|
||||
namespace data {
|
||||
namespace monomorphic {
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** join ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
//! Defines a new dataset from the concatenation of two datasets
|
||||
//!
|
||||
//! The size of the resulting dataset is the sum of the two underlying datasets. The arity of the datasets
|
||||
//! should match.
|
||||
template<typename DataSet1, typename DataSet2>
|
||||
class join {
|
||||
typedef typename boost::decay<DataSet1>::type dataset1_decay;
|
||||
typedef typename boost::decay<DataSet2>::type dataset2_decay;
|
||||
|
||||
typedef typename dataset1_decay::iterator dataset1_iter;
|
||||
typedef typename dataset2_decay::iterator dataset2_iter;
|
||||
public:
|
||||
typedef typename dataset1_decay::sample sample;
|
||||
|
||||
enum { arity = dataset1_decay::arity };
|
||||
|
||||
struct iterator {
|
||||
// Constructor
|
||||
explicit iterator( dataset1_iter it1, dataset2_iter it2, data::size_t first_size )
|
||||
: m_it1( std::move( it1 ) )
|
||||
, m_it2( std::move( it2 ) )
|
||||
, m_first_size( first_size )
|
||||
{}
|
||||
|
||||
// forward iterator interface
|
||||
sample const& operator*() const { return m_first_size > 0 ? *m_it1 : *m_it2; }
|
||||
void operator++() { if( m_first_size > 0 ) { --m_first_size; ++m_it1; } else ++m_it2; }
|
||||
|
||||
private:
|
||||
// Data members
|
||||
dataset1_iter m_it1;
|
||||
dataset2_iter m_it2;
|
||||
data::size_t m_first_size;
|
||||
};
|
||||
|
||||
//! Constructor
|
||||
join( DataSet1&& ds1, DataSet2&& ds2 )
|
||||
: m_ds1( std::forward<DataSet1>( ds1 ) )
|
||||
, m_ds2( std::forward<DataSet2>( ds2 ) )
|
||||
{}
|
||||
|
||||
//! Move constructor
|
||||
join( join&& j )
|
||||
: m_ds1( std::forward<DataSet1>( j.m_ds1 ) )
|
||||
, m_ds2( std::forward<DataSet2>( j.m_ds2 ) )
|
||||
{}
|
||||
|
||||
//! dataset interface
|
||||
data::size_t size() const { return m_ds1.size() + m_ds2.size(); }
|
||||
iterator begin() const { return iterator( m_ds1.begin(), m_ds2.begin(), m_ds1.size() ); }
|
||||
|
||||
private:
|
||||
// Data members
|
||||
DataSet1 m_ds1;
|
||||
DataSet2 m_ds2;
|
||||
};
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
// A joined dataset is a dataset.
|
||||
template<typename DataSet1, typename DataSet2>
|
||||
struct is_dataset<join<DataSet1,DataSet2>> : mpl::true_ {};
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace result_of {
|
||||
|
||||
//! Result type of the join operation on datasets.
|
||||
template<typename DataSet1Gen, typename DataSet2Gen>
|
||||
struct join {
|
||||
typedef monomorphic::join<typename DataSet1Gen::type,typename DataSet2Gen::type> type;
|
||||
};
|
||||
|
||||
} // namespace result_of
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
template<typename DataSet1, typename DataSet2>
|
||||
inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && is_dataset<DataSet2>::value,
|
||||
result_of::join<mpl::identity<DataSet1>,mpl::identity<DataSet2>>
|
||||
>::type
|
||||
operator+( DataSet1&& ds1, DataSet2&& ds2 )
|
||||
{
|
||||
return join<DataSet1,DataSet2>( std::forward<DataSet1>( ds1 ), std::forward<DataSet2>( ds2 ) );
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
template<typename DataSet1, typename DataSet2>
|
||||
inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && !is_dataset<DataSet2>::value,
|
||||
result_of::join<mpl::identity<DataSet1>,data::result_of::make<DataSet2>>
|
||||
>::type
|
||||
operator+( DataSet1&& ds1, DataSet2&& ds2 )
|
||||
{
|
||||
return std::forward<DataSet1>( ds1 ) + data::make( std::forward<DataSet2>( ds2 ) );
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
template<typename DataSet1, typename DataSet2>
|
||||
inline typename boost::lazy_enable_if_c<!is_dataset<DataSet1>::value && is_dataset<DataSet2>::value,
|
||||
result_of::join<data::result_of::make<DataSet1>,mpl::identity<DataSet2>>
|
||||
>::type
|
||||
operator+( DataSet1&& ds1, DataSet2&& ds2 )
|
||||
{
|
||||
return data::make( std::forward<DataSet1>(ds1) ) + std::forward<DataSet2>( ds2 );
|
||||
}
|
||||
|
||||
} // namespace monomorphic
|
||||
} // namespace data
|
||||
} // namespace unit_test
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/test/detail/enable_warnings.hpp>
|
||||
|
||||
#endif // BOOST_TEST_DATA_MONOMORPHIC_JOIN_HPP_112711GER
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
/// @file
|
||||
/// Defines helper routines and types for merging monomorphic samples
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_DATA_MONOMORPHIC_SAMPLE_MERGE_HPP
|
||||
#define BOOST_TEST_DATA_MONOMORPHIC_SAMPLE_MERGE_HPP
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/data/config.hpp>
|
||||
#include <boost/test/data/index_sequence.hpp>
|
||||
|
||||
#include <boost/test/data/monomorphic/fwd.hpp>
|
||||
|
||||
#include <boost/test/detail/suppress_warnings.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace unit_test {
|
||||
namespace data {
|
||||
namespace monomorphic {
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace ds_detail {
|
||||
|
||||
template <class T>
|
||||
struct is_tuple : std::false_type {};
|
||||
|
||||
template <class ...T>
|
||||
struct is_tuple<std::tuple<T...>> : std::true_type {};
|
||||
|
||||
template <class T>
|
||||
struct is_tuple<T&&> : is_tuple<typename std::decay<T>::type> {};
|
||||
|
||||
template <class T>
|
||||
struct is_tuple<T&> : is_tuple<typename std::decay<T>::type> {};
|
||||
|
||||
template<typename T>
|
||||
inline auto as_tuple_impl_xvalues( T const & arg, std::false_type /* is_rvalue_ref */ )
|
||||
-> decltype(std::tuple<T const&>(arg)) {
|
||||
//return std::tuple<T const&>(arg);
|
||||
return std::forward_as_tuple(arg);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline auto as_tuple_impl_xvalues( T && arg, std::true_type /* is_rvalue_ref */ )
|
||||
-> decltype(std::make_tuple(std::forward<T>(arg))) {
|
||||
return std::make_tuple(std::forward<T>(arg));
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline auto as_tuple_impl( T && arg, std::false_type /* is_tuple = nullptr */ )
|
||||
-> decltype(as_tuple_impl_xvalues(std::forward<T>(arg),
|
||||
typename std::is_rvalue_reference<T&&>::type())) {
|
||||
return as_tuple_impl_xvalues(std::forward<T>(arg),
|
||||
typename std::is_rvalue_reference<T&&>::type());
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
template<typename T>
|
||||
inline T &&
|
||||
as_tuple_impl(T && arg, std::true_type /* is_tuple */ ) {
|
||||
return std::forward<T>(arg);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline auto as_tuple( T && arg )
|
||||
-> decltype( as_tuple_impl(std::forward<T>(arg),
|
||||
typename ds_detail::is_tuple<T>::type()) ) {
|
||||
return as_tuple_impl(std::forward<T>(arg),
|
||||
typename ds_detail::is_tuple<T>::type());
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
} // namespace ds_detail
|
||||
|
||||
template<typename T1, typename T2>
|
||||
inline auto
|
||||
sample_merge( T1 && a1, T2 && a2 )
|
||||
-> decltype( std::tuple_cat(ds_detail::as_tuple(std::forward<T1>(a1)),
|
||||
ds_detail::as_tuple(std::forward<T2>(a2)) ) ) {
|
||||
return std::tuple_cat(ds_detail::as_tuple(std::forward<T1>(a1)),
|
||||
ds_detail::as_tuple(std::forward<T2>(a2)));
|
||||
}
|
||||
|
||||
} // namespace monomorphic
|
||||
} // namespace data
|
||||
} // namespace unit_test
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/test/detail/enable_warnings.hpp>
|
||||
|
||||
#endif // BOOST_TEST_DATA_MONOMORPHIC_SAMPLE_MERGE_HPP
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
/// @file
|
||||
/// Defines single element monomorphic dataset
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_DATA_MONOMORPHIC_SINGLETON_HPP_102211GER
|
||||
#define BOOST_TEST_DATA_MONOMORPHIC_SINGLETON_HPP_102211GER
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/data/config.hpp>
|
||||
#include <boost/test/data/monomorphic/fwd.hpp>
|
||||
|
||||
#include <boost/test/detail/suppress_warnings.hpp>
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace boost {
|
||||
namespace unit_test {
|
||||
namespace data {
|
||||
namespace monomorphic {
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** singleton ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
/// Models a single element data set
|
||||
template<typename T>
|
||||
class singleton {
|
||||
public:
|
||||
typedef typename boost::decay<T>::type sample;
|
||||
|
||||
enum { arity = 1 };
|
||||
|
||||
struct iterator {
|
||||
// Constructor
|
||||
explicit iterator( singleton<T> const* owner )
|
||||
: m_owner( owner )
|
||||
{}
|
||||
|
||||
// forward iterator interface
|
||||
sample const& operator*() const { return m_owner->value(); }
|
||||
void operator++() {}
|
||||
|
||||
private:
|
||||
singleton<T> const* m_owner;
|
||||
};
|
||||
|
||||
//! Constructor
|
||||
explicit singleton( T&& value ) : m_value( std::forward<T>( value ) ) {}
|
||||
|
||||
//! Move constructor
|
||||
singleton( singleton&& s ) : m_value( std::forward<T>( s.m_value ) ) {}
|
||||
|
||||
//! Value access method
|
||||
T const& value() const { return m_value; }
|
||||
|
||||
//! dataset interface
|
||||
data::size_t size() const { return 1; }
|
||||
iterator begin() const { return iterator( this ); }
|
||||
|
||||
private:
|
||||
// Data members
|
||||
T m_value;
|
||||
};
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
// a singleton is a dataset
|
||||
template<typename T>
|
||||
struct is_dataset<singleton<T>> : mpl::true_ {};
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
} // namespace monomorphic
|
||||
|
||||
/// @overload boost::unit_test::data::make()
|
||||
template<typename T>
|
||||
inline typename std::enable_if<!is_forward_iterable<T>::value &&
|
||||
!monomorphic::is_dataset<T>::value &&
|
||||
!boost::is_array<typename boost::remove_reference<T>::type>::value,
|
||||
monomorphic::singleton<T>
|
||||
>::type
|
||||
make( T&& v )
|
||||
{
|
||||
return monomorphic::singleton<T>( std::forward<T>( v ) );
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
/// @overload boost::unit_test::data::make
|
||||
inline monomorphic::singleton<char*>
|
||||
make( char* str )
|
||||
{
|
||||
return monomorphic::singleton<char*>( std::move(str) );
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
/// @overload boost::unit_test::data::make
|
||||
inline monomorphic::singleton<char const*>
|
||||
make( char const* str )
|
||||
{
|
||||
return monomorphic::singleton<char const*>( std::move(str) );
|
||||
}
|
||||
|
||||
} // namespace data
|
||||
} // namespace unit_test
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/test/detail/enable_warnings.hpp>
|
||||
|
||||
#endif // BOOST_TEST_DATA_MONOMORPHIC_SINGLETON_HPP_102211GER
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
/// @file
|
||||
/// Defines monomorphic dataset based on zipping of 2 other monomorphic datasets
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_DATA_MONOMORPHIC_ZIP_HPP_102211GER
|
||||
#define BOOST_TEST_DATA_MONOMORPHIC_ZIP_HPP_102211GER
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/data/config.hpp>
|
||||
|
||||
#if !defined(BOOST_TEST_NO_ZIP_COMPOSITION_AVAILABLE) || defined(BOOST_TEST_DOXYGEN_DOC__)
|
||||
|
||||
#include <boost/test/data/monomorphic/fwd.hpp>
|
||||
#include <boost/test/data/monomorphic/sample_merge.hpp>
|
||||
|
||||
#include <boost/test/detail/suppress_warnings.hpp>
|
||||
|
||||
|
||||
namespace boost {
|
||||
namespace unit_test {
|
||||
namespace data {
|
||||
namespace monomorphic {
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** zip ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
//! Zip datasets
|
||||
//!
|
||||
//! A zip of two datasets is a dataset whose arity is the sum of the operand datasets arity. The size is given by
|
||||
//! the function creating the instance (see @c operator^ on datasets).
|
||||
template<typename DataSet1, typename DataSet2>
|
||||
class zip {
|
||||
typedef typename boost::decay<DataSet1>::type dataset1_decay;
|
||||
typedef typename boost::decay<DataSet2>::type dataset2_decay;
|
||||
|
||||
typedef typename dataset1_decay::iterator dataset1_iter;
|
||||
typedef typename dataset2_decay::iterator dataset2_iter;
|
||||
|
||||
public:
|
||||
enum { arity = dataset1_decay::arity + dataset2_decay::arity };
|
||||
|
||||
struct iterator {
|
||||
// Constructor
|
||||
explicit iterator( dataset1_iter iter1, dataset2_iter iter2 )
|
||||
: m_iter1( std::move( iter1 ) )
|
||||
, m_iter2( std::move( iter2 ) )
|
||||
{}
|
||||
|
||||
using iterator_sample = decltype(
|
||||
sample_merge( *std::declval<dataset1_iter>(),
|
||||
*std::declval<dataset2_iter>()) );
|
||||
|
||||
// forward iterator interface
|
||||
auto operator*() const -> iterator_sample {
|
||||
return sample_merge( *m_iter1, *m_iter2 );
|
||||
}
|
||||
void operator++() { ++m_iter1; ++m_iter2; }
|
||||
|
||||
private:
|
||||
// Data members
|
||||
dataset1_iter m_iter1;
|
||||
dataset2_iter m_iter2;
|
||||
};
|
||||
|
||||
typedef typename iterator::iterator_sample sample;
|
||||
|
||||
//! Constructor
|
||||
//!
|
||||
//! The datasets are moved and not copied.
|
||||
zip( DataSet1&& ds1, DataSet2&& ds2, data::size_t size )
|
||||
: m_ds1( std::forward<DataSet1>( ds1 ) )
|
||||
, m_ds2( std::forward<DataSet2>( ds2 ) )
|
||||
, m_size( size )
|
||||
{}
|
||||
|
||||
//! Move constructor
|
||||
zip( zip&& j )
|
||||
: m_ds1( std::forward<DataSet1>( j.m_ds1 ) )
|
||||
, m_ds2( std::forward<DataSet2>( j.m_ds2 ) )
|
||||
, m_size( j.m_size )
|
||||
{}
|
||||
|
||||
// dataset interface
|
||||
data::size_t size() const { return m_size; }
|
||||
iterator begin() const { return iterator( m_ds1.begin(), m_ds2.begin() ); }
|
||||
|
||||
private:
|
||||
// Data members
|
||||
DataSet1 m_ds1;
|
||||
DataSet2 m_ds2;
|
||||
data::size_t m_size;
|
||||
};
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
//! Zipped datasets results in a dataset.
|
||||
template<typename DataSet1, typename DataSet2>
|
||||
struct is_dataset<zip<DataSet1,DataSet2>> : mpl::true_ {};
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace ds_detail {
|
||||
|
||||
//! Handles the sise of the resulting zipped dataset.
|
||||
template<typename DataSet1, typename DataSet2>
|
||||
inline data::size_t
|
||||
zip_size( DataSet1&& ds1, DataSet2&& ds2 )
|
||||
{
|
||||
data::size_t ds1_size = ds1.size();
|
||||
data::size_t ds2_size = ds2.size();
|
||||
|
||||
if( ds1_size == ds2_size )
|
||||
return ds1_size;
|
||||
|
||||
if( ds1_size == 1 || ds1_size.is_inf() )
|
||||
return ds2_size;
|
||||
|
||||
if( ds2_size == 1 || ds2_size.is_inf() )
|
||||
return ds1_size;
|
||||
|
||||
BOOST_TEST_DS_ERROR( "Can't zip datasets of different sizes" );
|
||||
}
|
||||
|
||||
} // namespace ds_detail
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace result_of {
|
||||
|
||||
//! Result type of the zip operator.
|
||||
template<typename DS1Gen, typename DS2Gen>
|
||||
struct zip {
|
||||
typedef monomorphic::zip<typename DS1Gen::type,typename DS2Gen::type> type;
|
||||
};
|
||||
|
||||
} // namespace result_of
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
//! Overload operator for zip support
|
||||
template<typename DataSet1, typename DataSet2>
|
||||
inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && is_dataset<DataSet2>::value,
|
||||
result_of::zip<mpl::identity<DataSet1>,mpl::identity<DataSet2>>
|
||||
>::type
|
||||
operator^( DataSet1&& ds1, DataSet2&& ds2 )
|
||||
{
|
||||
return zip<DataSet1,DataSet2>( std::forward<DataSet1>( ds1 ),
|
||||
std::forward<DataSet2>( ds2 ),
|
||||
ds_detail::zip_size( ds1, ds2 ) );
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
//! @overload boost::unit_test::data::monomorphic::operator^()
|
||||
template<typename DataSet1, typename DataSet2>
|
||||
inline typename boost::lazy_enable_if_c<is_dataset<DataSet1>::value && !is_dataset<DataSet2>::value,
|
||||
result_of::zip<mpl::identity<DataSet1>,data::result_of::make<DataSet2>>
|
||||
>::type
|
||||
operator^( DataSet1&& ds1, DataSet2&& ds2 )
|
||||
{
|
||||
return std::forward<DataSet1>( ds1 ) ^ data::make( std::forward<DataSet2>( ds2 ) );
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
//! @overload boost::unit_test::data::monomorphic::operator^()
|
||||
template<typename DataSet1, typename DataSet2>
|
||||
inline typename boost::lazy_enable_if_c<!is_dataset<DataSet1>::value && is_dataset<DataSet2>::value,
|
||||
result_of::zip<data::result_of::make<DataSet1>,mpl::identity<DataSet2>>
|
||||
>::type
|
||||
operator^( DataSet1&& ds1, DataSet2&& ds2 )
|
||||
{
|
||||
return data::make( std::forward<DataSet1>( ds1 ) ) ^ std::forward<DataSet2>( ds2 );
|
||||
}
|
||||
|
||||
} // namespace monomorphic
|
||||
} // namespace data
|
||||
} // namespace unit_test
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/test/detail/enable_warnings.hpp>
|
||||
|
||||
#endif // BOOST_TEST_NO_ZIP_COMPOSITION_AVAILABLE
|
||||
|
||||
#endif // BOOST_TEST_DATA_MONOMORPHIC_ZIP_HPP_102211GER
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
//!@file
|
||||
//!@brief simple dataset size abstraction (can be infinite)
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_DATA_SIZE_HPP_102211GER
|
||||
#define BOOST_TEST_DATA_SIZE_HPP_102211GER
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/data/config.hpp>
|
||||
|
||||
// STL
|
||||
#include <iosfwd>
|
||||
|
||||
#include <boost/test/detail/suppress_warnings.hpp>
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace boost {
|
||||
namespace unit_test {
|
||||
namespace data {
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** size_t ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
//! Utility for handling the size of a datasets
|
||||
class size_t {
|
||||
struct dummy { void nonnull() {} };
|
||||
typedef void (dummy::*safe_bool)();
|
||||
public:
|
||||
// Constructors
|
||||
size_t( std::size_t s = 0 ) : m_value( s ), m_infinity( false ) {}
|
||||
explicit size_t( bool ) : m_value( 0 ), m_infinity( true ) {}
|
||||
template<typename T>
|
||||
size_t( T v ) : m_value( static_cast<std::size_t>(v) ), m_infinity( false ) {}
|
||||
|
||||
// Access methods
|
||||
std::size_t value() const { return m_value; }
|
||||
bool is_inf() const { return m_infinity; }
|
||||
operator safe_bool() const { return is_inf() || m_value != 0 ? &dummy::nonnull : 0; }
|
||||
|
||||
// Unary operators
|
||||
data::size_t operator--() { if( !is_inf() ) m_value--; return *this; }
|
||||
data::size_t operator--(int) { data::size_t res(*this); if( !is_inf() ) m_value--; return res; }
|
||||
data::size_t operator++() { if( !is_inf() ) m_value++; return *this; }
|
||||
data::size_t operator++(int) { data::size_t res(*this); if( !is_inf() ) m_value++; return res; }
|
||||
|
||||
// Binary operators
|
||||
data::size_t& operator+=( std::size_t rhs ) { if( !is_inf() ) m_value += rhs; return *this; }
|
||||
data::size_t& operator+=( data::size_t rhs )
|
||||
{
|
||||
if( !is_inf() ) {
|
||||
if( rhs.is_inf() )
|
||||
*this = rhs;
|
||||
else
|
||||
m_value += rhs.value();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
data::size_t& operator-=( std::size_t rhs ) { if( !is_inf() ) m_value -= rhs; return *this; }
|
||||
data::size_t& operator-=( data::size_t rhs )
|
||||
{
|
||||
if( !is_inf() ) {
|
||||
if( value() < rhs.value() )
|
||||
m_value = 0;
|
||||
else
|
||||
m_value -= rhs.value();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
// Data members
|
||||
std::size_t m_value;
|
||||
bool m_infinity;
|
||||
};
|
||||
|
||||
namespace { const data::size_t BOOST_TEST_DS_INFINITE_SIZE( true ); }
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
// Binary operators
|
||||
inline bool operator>(data::size_t lhs, std::size_t rhs) { return lhs.is_inf() || (lhs.value() > rhs); }
|
||||
inline bool operator>(std::size_t lhs, data::size_t rhs) { return !rhs.is_inf() && (lhs > rhs.value()); }
|
||||
inline bool operator>(data::size_t lhs, data::size_t rhs) { return lhs.is_inf() ^ rhs.is_inf() ? lhs.is_inf() : lhs.value() > rhs.value(); }
|
||||
|
||||
inline bool operator>=(data::size_t lhs, std::size_t rhs ) { return lhs.is_inf() || (lhs.value() >= rhs); }
|
||||
inline bool operator>=(std::size_t lhs, data::size_t rhs) { return !rhs.is_inf() && (lhs >= rhs.value()); }
|
||||
inline bool operator>=(data::size_t lhs, data::size_t rhs) { return lhs.is_inf() ^ rhs.is_inf() ? lhs.is_inf() : lhs.value() >= rhs.value(); }
|
||||
|
||||
inline bool operator<(data::size_t lhs, std::size_t rhs) { return !lhs.is_inf() && (lhs.value() < rhs); }
|
||||
inline bool operator<(std::size_t lhs, data::size_t rhs) { return rhs.is_inf() || (lhs < rhs.value()); }
|
||||
inline bool operator<(data::size_t lhs, data::size_t rhs) { return lhs.is_inf() ^ rhs.is_inf() ? rhs.is_inf() : lhs.value() < rhs.value(); }
|
||||
|
||||
inline bool operator<=(data::size_t lhs, std::size_t rhs) { return !lhs.is_inf() && (lhs.value() <= rhs); }
|
||||
inline bool operator<=(std::size_t lhs, data::size_t rhs) { return rhs.is_inf() || (lhs <= rhs.value()); }
|
||||
inline bool operator<=(data::size_t lhs, data::size_t rhs) { return lhs.is_inf() ^ rhs.is_inf() ? rhs.is_inf() : lhs.value() <= rhs.value(); }
|
||||
|
||||
inline bool operator==(data::size_t lhs, std::size_t rhs) { return !lhs.is_inf() && (lhs.value() == rhs); }
|
||||
inline bool operator==(std::size_t lhs, data::size_t rhs) { return !rhs.is_inf() && (lhs == rhs.value()); }
|
||||
inline bool operator==(data::size_t lhs, data::size_t rhs) { return !(lhs.is_inf() ^ rhs.is_inf()) && lhs.value() == rhs.value(); }
|
||||
|
||||
inline bool operator!=(data::size_t lhs, std::size_t rhs) { return lhs.is_inf() || (lhs.value() != rhs); }
|
||||
inline bool operator!=(std::size_t lhs, data::size_t rhs) { return rhs.is_inf() || (lhs != rhs.value()); }
|
||||
inline bool operator!=(data::size_t lhs, data::size_t rhs) { return lhs.is_inf() ^ rhs.is_inf() || lhs.value() != rhs.value(); }
|
||||
|
||||
inline data::size_t operator+(data::size_t lhs, std::size_t rhs) { return lhs.is_inf() ? lhs : data::size_t( lhs.value()+rhs ); }
|
||||
inline data::size_t operator+(std::size_t lhs, data::size_t rhs) { return rhs.is_inf() ? rhs : data::size_t( lhs+rhs.value() ); }
|
||||
inline data::size_t operator+(data::size_t lhs, data::size_t rhs) { return lhs.is_inf() || rhs.is_inf() ? data::size_t(true) : data::size_t( lhs.value()+rhs.value() ); }
|
||||
|
||||
inline data::size_t operator*(data::size_t lhs, std::size_t rhs) { return lhs.is_inf() ? lhs : data::size_t( lhs.value()*rhs ); }
|
||||
inline data::size_t operator*(std::size_t lhs, data::size_t rhs) { return rhs.is_inf() ? rhs : data::size_t( lhs*rhs.value() ); }
|
||||
inline data::size_t operator*(data::size_t lhs, data::size_t rhs) { return lhs.is_inf() || rhs.is_inf() ? data::size_t(true) : data::size_t( lhs.value()*rhs.value() ); }
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
template<typename CharT1, typename Tr>
|
||||
inline std::basic_ostream<CharT1,Tr>&
|
||||
operator<<( std::basic_ostream<CharT1,Tr>& os, data::size_t const& s )
|
||||
{
|
||||
if( s.is_inf() )
|
||||
os << "infinity";
|
||||
else
|
||||
os << s.value();
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
} // namespace data
|
||||
} // namespace unit_test
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/test/detail/enable_warnings.hpp>
|
||||
|
||||
#endif // BOOST_TEST_DATA_SIZE_HPP_102211GER
|
||||
|
||||
@@ -0,0 +1,320 @@
|
||||
// (C) Copyright Gennadiy Rozental 2001.
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
//!@file
|
||||
//!@brief test case family based on data generator
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_DATA_TEST_CASE_HPP_102211GER
|
||||
#define BOOST_TEST_DATA_TEST_CASE_HPP_102211GER
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/data/config.hpp>
|
||||
#include <boost/test/data/dataset.hpp>
|
||||
#include <boost/test/data/for_each_sample.hpp>
|
||||
|
||||
// Boost
|
||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
|
||||
|
||||
#include <boost/preprocessor/variadic/to_seq.hpp>
|
||||
#include <boost/preprocessor/variadic/size.hpp>
|
||||
#include <boost/preprocessor/cat.hpp>
|
||||
#include <boost/preprocessor/seq/for_each_i.hpp>
|
||||
#include <boost/preprocessor/seq/for_each.hpp>
|
||||
#include <boost/preprocessor/seq/enum.hpp>
|
||||
#include <boost/preprocessor/control/iif.hpp>
|
||||
#include <boost/preprocessor/comparison/equal.hpp>
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include <boost/type_traits/is_copy_constructible.hpp>
|
||||
|
||||
#include <boost/test/detail/suppress_warnings.hpp>
|
||||
#include <boost/test/tools/detail/print_helper.hpp>
|
||||
#include <boost/test/utils/string_cast.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) \
|
||||
&& !defined(BOOST_TEST_DATASET_MAX_ARITY)
|
||||
# define BOOST_TEST_DATASET_MAX_ARITY 10
|
||||
#endif
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace boost {
|
||||
namespace unit_test {
|
||||
namespace data {
|
||||
|
||||
namespace ds_detail {
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** seed ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
struct seed {
|
||||
template<typename DataSet>
|
||||
typename data::result_of::make<DataSet>::type
|
||||
operator->*( DataSet&& ds ) const
|
||||
{
|
||||
return data::make( std::forward<DataSet>( ds ) );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
|
||||
!defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
|
||||
!defined(BOOST_NO_CXX11_DECLTYPE) && \
|
||||
!defined(BOOST_NO_CXX11_TRAILING_RESULT_TYPES) && \
|
||||
!defined(BOOST_NO_CXX11_SMART_PTR)
|
||||
|
||||
#define BOOST_TEST_DATASET_VARIADIC
|
||||
template <class T>
|
||||
struct parameter_holder {
|
||||
std::shared_ptr<T> value;
|
||||
|
||||
parameter_holder(T && value_)
|
||||
: value(std::make_shared<T>(std::move(value_)))
|
||||
{}
|
||||
|
||||
operator T const&() const {
|
||||
return *value;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
parameter_holder<typename std::remove_reference<T>::type>
|
||||
boost_bind_rvalue_holder_helper_impl(T&& value, boost::false_type /* is copy constructible */) {
|
||||
return parameter_holder<typename std::remove_reference<T>::type>(std::forward<T>(value));
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T&& boost_bind_rvalue_holder_helper_impl(T&& value, boost::true_type /* is copy constructible */) {
|
||||
return std::forward<T>(value);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
auto boost_bind_rvalue_holder_helper(T&& value)
|
||||
-> decltype(boost_bind_rvalue_holder_helper_impl(
|
||||
std::forward<T>(value),
|
||||
typename boost::is_copy_constructible<typename std::remove_reference<T>::type>::type()))
|
||||
{
|
||||
// need to use boost::is_copy_constructible because std::is_copy_constructible is broken on MSVC12
|
||||
return boost_bind_rvalue_holder_helper_impl(
|
||||
std::forward<T>(value),
|
||||
typename boost::is_copy_constructible<typename std::remove_reference<T>::type>::type());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** test_case_gen ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
template<typename TestCase,typename DataSet>
|
||||
class test_case_gen : public test_unit_generator {
|
||||
public:
|
||||
// Constructor
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
test_case_gen( const_string tc_name, const_string tc_file, std::size_t tc_line, DataSet&& ds )
|
||||
: m_tc_name( ut_detail::normalize_test_case_name( tc_name ) )
|
||||
, m_tc_file( tc_file )
|
||||
, m_tc_line( tc_line )
|
||||
, m_tc_index( 0 )
|
||||
{
|
||||
data::for_each_sample( std::forward<DataSet>( ds ), *this );
|
||||
}
|
||||
test_case_gen( test_case_gen&& gen )
|
||||
: m_tc_name( gen.m_tc_name )
|
||||
, m_tc_file( gen.m_tc_file )
|
||||
, m_tc_line( gen.m_tc_line )
|
||||
, m_tc_index( gen.m_tc_index )
|
||||
, m_test_cases( std::move(gen.m_test_cases) )
|
||||
{}
|
||||
#else
|
||||
test_case_gen( const_string tc_name, const_string tc_file, std::size_t tc_line, DataSet const& ds )
|
||||
: m_tc_name( ut_detail::normalize_test_case_name( tc_name ) )
|
||||
, m_tc_file( tc_file )
|
||||
, m_tc_line( tc_line )
|
||||
, m_tc_index( 0 )
|
||||
{
|
||||
data::for_each_sample( ds, *this );
|
||||
}
|
||||
#endif
|
||||
|
||||
virtual test_unit* next() const
|
||||
{
|
||||
if( m_test_cases.empty() )
|
||||
return 0;
|
||||
|
||||
test_unit* res = m_test_cases.front();
|
||||
m_test_cases.pop_front();
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
#if !defined(BOOST_TEST_DATASET_VARIADIC)
|
||||
// see BOOST_TEST_DATASET_MAX_ARITY to increase the default supported arity
|
||||
#define TC_MAKE(z,arity,_) \
|
||||
template<BOOST_PP_ENUM_PARAMS(arity, typename Arg)> \
|
||||
void operator()( BOOST_PP_ENUM_BINARY_PARAMS(arity, Arg, const& arg) ) const \
|
||||
{ \
|
||||
m_test_cases.push_back( new test_case( genTestCaseName(), m_tc_file, m_tc_line, \
|
||||
boost::bind( &TestCase::template test_method<BOOST_PP_ENUM_PARAMS(arity,Arg)>,\
|
||||
BOOST_PP_ENUM_PARAMS(arity, arg) ) ) ); \
|
||||
} \
|
||||
|
||||
BOOST_PP_REPEAT_FROM_TO(1, BOOST_TEST_DATASET_MAX_ARITY, TC_MAKE, _)
|
||||
#else
|
||||
template<typename ...Arg>
|
||||
void operator()(Arg&& ... arg) const
|
||||
{
|
||||
m_test_cases.push_back(
|
||||
new test_case( genTestCaseName(),
|
||||
m_tc_file,
|
||||
m_tc_line,
|
||||
boost::bind( &TestCase::template test_method<Arg...>,
|
||||
boost_bind_rvalue_holder_helper(std::forward<Arg>(arg))...)));
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
std::string genTestCaseName() const
|
||||
{
|
||||
return "_" + utils::string_cast(m_tc_index++);
|
||||
}
|
||||
|
||||
// Data members
|
||||
std::string m_tc_name;
|
||||
const_string m_tc_file;
|
||||
std::size_t m_tc_line;
|
||||
mutable std::size_t m_tc_index;
|
||||
mutable std::list<test_unit*> m_test_cases;
|
||||
};
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
template<typename TestCase,typename DataSet>
|
||||
test_case_gen<TestCase,DataSet>
|
||||
make_test_case_gen( const_string tc_name, const_string tc_file, std::size_t tc_line, DataSet&& ds )
|
||||
{
|
||||
return test_case_gen<TestCase,DataSet>( tc_name, tc_file, tc_line, std::forward<DataSet>(ds) );
|
||||
}
|
||||
#else
|
||||
template<typename TestCase,typename DataSet>
|
||||
test_case_gen<TestCase,DataSet>
|
||||
make_test_case_gen( const_string tc_name, const_string tc_file, std::size_t tc_line, DataSet const& ds )
|
||||
{
|
||||
return test_case_gen<TestCase,DataSet>( tc_name, tc_file, tc_line, ds );
|
||||
}
|
||||
#endif
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
} // namespace ds_detail
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** BOOST_DATA_TEST_CASE ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
#define BOOST_DATA_TEST_CASE_PARAM(r, _, i, param) (BOOST_PP_CAT(Arg, i) const& param)
|
||||
#define BOOST_DATA_TEST_CONTEXT(r, _, param) << BOOST_STRINGIZE(param) << " = " << boost::test_tools::tt_detail::print_helper(param) << "; "
|
||||
|
||||
#define BOOST_DATA_TEST_CASE_PARAMS( params ) \
|
||||
BOOST_PP_SEQ_ENUM( \
|
||||
BOOST_PP_SEQ_FOR_EACH_I(BOOST_DATA_TEST_CASE_PARAM, _, params)) \
|
||||
/**/
|
||||
|
||||
#define BOOST_DATA_TEST_CASE_IMPL(arity, F, test_name, dataset, params) \
|
||||
struct BOOST_PP_CAT(test_name, case) : public F { \
|
||||
template<BOOST_PP_ENUM_PARAMS(arity, typename Arg)> \
|
||||
static void test_method( BOOST_DATA_TEST_CASE_PARAMS( params ) ) \
|
||||
{ \
|
||||
BOOST_TEST_CHECKPOINT('"' << #test_name << "\" fixture entry.");\
|
||||
BOOST_PP_CAT(test_name, case) t; \
|
||||
BOOST_TEST_CHECKPOINT('"' << #test_name << "\" entry."); \
|
||||
BOOST_TEST_CONTEXT( "" \
|
||||
BOOST_PP_SEQ_FOR_EACH(BOOST_DATA_TEST_CONTEXT, _, params)) \
|
||||
t._impl(BOOST_PP_SEQ_ENUM(params)); \
|
||||
BOOST_TEST_CHECKPOINT('"' << #test_name << "\" exit."); \
|
||||
} \
|
||||
private: \
|
||||
template<BOOST_PP_ENUM_PARAMS(arity, typename Arg)> \
|
||||
void _impl(BOOST_DATA_TEST_CASE_PARAMS( params )); \
|
||||
}; \
|
||||
\
|
||||
BOOST_AUTO_TEST_SUITE( test_name ) \
|
||||
\
|
||||
BOOST_AUTO_TU_REGISTRAR( BOOST_PP_CAT(test_name, case) )( \
|
||||
boost::unit_test::data::ds_detail::make_test_case_gen< \
|
||||
BOOST_PP_CAT(test_name, case)>( \
|
||||
BOOST_STRINGIZE( test_name ), \
|
||||
__FILE__, __LINE__, \
|
||||
boost::unit_test::data::ds_detail::seed{} ->* dataset ), \
|
||||
boost::unit_test::decorator::collector::instance() ); \
|
||||
\
|
||||
BOOST_AUTO_TEST_SUITE_END() \
|
||||
\
|
||||
template<BOOST_PP_ENUM_PARAMS(arity, typename Arg)> \
|
||||
void BOOST_PP_CAT(test_name, case)::_impl( \
|
||||
BOOST_DATA_TEST_CASE_PARAMS( params ) ) \
|
||||
/**/
|
||||
|
||||
#define BOOST_DATA_TEST_CASE_WITH_PARAMS( F, test_name, dataset, ... ) \
|
||||
BOOST_DATA_TEST_CASE_IMPL( BOOST_PP_VARIADIC_SIZE(__VA_ARGS__), \
|
||||
F, test_name, dataset, \
|
||||
BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__) ) \
|
||||
/**/
|
||||
#define BOOST_DATA_TEST_CASE_NO_PARAMS( F, test_name, dataset ) \
|
||||
BOOST_DATA_TEST_CASE_WITH_PARAMS( F, test_name, dataset, sample ) \
|
||||
/**/
|
||||
|
||||
#if BOOST_PP_VARIADICS_MSVC
|
||||
|
||||
#define BOOST_DATA_TEST_CASE( ... ) \
|
||||
BOOST_PP_CAT( \
|
||||
BOOST_PP_IIF(BOOST_PP_EQUAL(BOOST_PP_VARIADIC_SIZE(__VA_ARGS__),2), \
|
||||
BOOST_DATA_TEST_CASE_NO_PARAMS, \
|
||||
BOOST_DATA_TEST_CASE_WITH_PARAMS) ( \
|
||||
BOOST_AUTO_TEST_CASE_FIXTURE, __VA_ARGS__), ) \
|
||||
/**/
|
||||
|
||||
#define BOOST_DATA_TEST_CASE_F( F, ... ) \
|
||||
BOOST_PP_CAT( \
|
||||
BOOST_PP_IIF(BOOST_PP_EQUAL(BOOST_PP_VARIADIC_SIZE(__VA_ARGS__),2), \
|
||||
BOOST_DATA_TEST_CASE_NO_PARAMS, \
|
||||
BOOST_DATA_TEST_CASE_WITH_PARAMS) ( \
|
||||
F, __VA_ARGS__), ) \
|
||||
/**/
|
||||
|
||||
#else
|
||||
|
||||
#define BOOST_DATA_TEST_CASE( ... ) \
|
||||
BOOST_PP_IIF(BOOST_PP_EQUAL(BOOST_PP_VARIADIC_SIZE(__VA_ARGS__),2), \
|
||||
BOOST_DATA_TEST_CASE_NO_PARAMS, \
|
||||
BOOST_DATA_TEST_CASE_WITH_PARAMS) ( \
|
||||
BOOST_AUTO_TEST_CASE_FIXTURE, __VA_ARGS__) \
|
||||
/**/
|
||||
|
||||
#define BOOST_DATA_TEST_CASE_F( F, ... ) \
|
||||
BOOST_PP_IIF(BOOST_PP_EQUAL(BOOST_PP_VARIADIC_SIZE(__VA_ARGS__),2), \
|
||||
BOOST_DATA_TEST_CASE_NO_PARAMS, \
|
||||
BOOST_DATA_TEST_CASE_WITH_PARAMS) ( \
|
||||
F, __VA_ARGS__) \
|
||||
/**/
|
||||
#endif
|
||||
|
||||
} // namespace data
|
||||
} // namespace unit_test
|
||||
} // namespace boost
|
||||
|
||||
#include <boost/test/detail/enable_warnings.hpp>
|
||||
|
||||
#endif // BOOST_TEST_DATA_TEST_CASE_HPP_102211GER
|
||||
|
||||
Reference in New Issue
Block a user