diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-10-06 10:33:54 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-10-06 10:36:09 +0900 |
commit | d9ec475d945d3035377a0d89ed42e382d8988891 (patch) | |
tree | 34aff2cee4b209906243ab5499d61f3edee2982f /boost/test | |
parent | 71d216b90256936a9638f325af9bc69d720e75de (diff) | |
download | boost-d9ec475d945d3035377a0d89ed42e382d8988891.tar.gz boost-d9ec475d945d3035377a0d89ed42e382d8988891.tar.bz2 boost-d9ec475d945d3035377a0d89ed42e382d8988891.zip |
Imported Upstream version 1.60.0
Change-Id: Ie709530d6d5841088ceaba025cbe175a4ef43050
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'boost/test')
195 files changed, 3758 insertions, 7505 deletions
diff --git a/boost/test/auto_unit_test.hpp b/boost/test/auto_unit_test.hpp index df41743962..99acd162ab 100644 --- a/boost/test/auto_unit_test.hpp +++ b/boost/test/auto_unit_test.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) diff --git a/boost/test/data/config.hpp b/boost/test/data/config.hpp index bedfae5de0..7a9d03be98 100644 --- a/boost/test/data/config.hpp +++ b/boost/test/data/config.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) @@ -19,7 +19,6 @@ // 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__) @@ -28,7 +27,6 @@ #endif - #if defined(BOOST_NO_CXX11_HDR_TUPLE) || defined(BOOST_TEST_DOXYGEN_DOC__) //! Defined when grid composition of datasets is not available @@ -41,8 +39,7 @@ //____________________________________________________________________________// -#define BOOST_TEST_DS_ERROR( msg ) BOOST_TEST_IMPL_THROW( std::logic_error( msg ) ) -#define BOOST_TEST_DS_ASSERT( cond, msg ) if( cond ) {} else BOOST_TEST_DS_ERROR( msg ) +#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 - diff --git a/boost/test/data/dataset.hpp b/boost/test/data/dataset.hpp index 390cf5bf3f..3f576ab357 100644 --- a/boost/test/data/dataset.hpp +++ b/boost/test/data/dataset.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) diff --git a/boost/test/data/for_each_sample.hpp b/boost/test/data/for_each_sample.hpp new file mode 100644 index 0000000000..8bc1964311 --- /dev/null +++ b/boost/test/data/for_each_sample.hpp @@ -0,0 +1,71 @@ +// (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/traits.hpp> +#include <boost/test/data/size.hpp> +#include <boost/test/data/monomorphic/fwd.hpp> + +#include <boost/test/detail/suppress_warnings.hpp> + +// needed for std::min +#include <algorithm> + +//____________________________________________________________________________// + +namespace boost { +namespace unit_test { +namespace data { + +// ************************************************************************** // +// ************** for_each_sample ************** // +// ************************************************************************** // + +template<typename DataSet, typename Action> +inline typename std::enable_if<monomorphic::is_dataset<DataSet>::value,void>::type +for_each_sample( DataSet const& 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 ) { + data::traits<typename DataSet::sample>::invoke_action( *it, act ); + ++it; + } +} + +//____________________________________________________________________________// + +template<typename DataSet, typename Action> +inline typename std::enable_if<!monomorphic::is_dataset<DataSet>::value,void>::type +for_each_sample( DataSet const& samples, + Action const& act, + data::size_t number_of_samples = BOOST_TEST_DS_INFINITE_SIZE ) +{ + data::for_each_sample( data::make( 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 + diff --git a/boost/test/data/generators.hpp b/boost/test/data/generators.hpp index ff8ad07400..e9bd4c17b5 100644 --- a/boost/test/data/generators.hpp +++ b/boost/test/data/generators.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) diff --git a/boost/test/data/monomorphic.hpp b/boost/test/data/monomorphic.hpp index 487b2a9cce..31d7b01b32 100644 --- a/boost/test/data/monomorphic.hpp +++ b/boost/test/data/monomorphic.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) @@ -15,6 +15,7 @@ // 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> diff --git a/boost/test/data/monomorphic/array.hpp b/boost/test/data/monomorphic/array.hpp index 87c55e7653..6f7ed8eb3b 100644 --- a/boost/test/data/monomorphic/array.hpp +++ b/boost/test/data/monomorphic/array.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) @@ -14,7 +14,7 @@ // Boost.Test #include <boost/test/data/config.hpp> -#include <boost/test/data/monomorphic/dataset.hpp> +#include <boost/test/data/monomorphic/fwd.hpp> #include <boost/test/detail/suppress_warnings.hpp> @@ -29,41 +29,25 @@ namespace monomorphic { // ************** array ************** // // ************************************************************************** // -/// Dataset view of an C array +/// Dataset view of a C array template<typename T> -class array : public monomorphic::dataset<T> { - typedef monomorphic::dataset<T> base; - typedef typename base::iter_ptr iter_ptr; - - struct iterator : public base::iterator { - // Constructor - explicit iterator( T const* begin, data::size_t size ) - : m_it( begin ) - , m_singleton( size == 1 ) - {} - - // forward iterator interface - virtual T const& operator*() { return *m_it; } - virtual void operator++() { if( !m_singleton ) ++m_it; } - - private: - // Data members - T const* m_it; - bool m_singleton; - }; - +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 ) + array( T const* arr_, std::size_t size_ ) + : m_arr( arr_ ) + , m_size( size_ ) {} // dataset interface - virtual data::size_t size() const { return m_size; } - virtual iter_ptr begin() const { return boost::make_shared<iterator>( m_arr, m_size ); } + data::size_t size() const { return m_size; } + iterator begin() const { return m_arr; } private: // Data members @@ -75,34 +59,20 @@ private: //! An array dataset is a dataset template<typename T> -struct is_dataset<array<T> > : mpl::true_ {}; +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 ); -} - -//! @overload boost::unit_test::data::make() -template<typename T, std::size_t size> -inline monomorphic::array< typename boost::remove_const<T>::type > make( T const (&a)[size] ) -{ - return monomorphic::array<T>( a, size ); -} - -template<typename T, std::size_t size> -inline monomorphic::array< typename boost::remove_const<T>::type > make( T a[size] ) +inline monomorphic::array<typename boost::remove_const<T>::type> +make( T (&a)[size] ) { - return monomorphic::array<T>( a, size ); + return monomorphic::array<typename boost::remove_const<T>::type>( a, size ); } - -//____________________________________________________________________________// - } // namespace data } // namespace unit_test } // namespace boost diff --git a/boost/test/data/monomorphic/collection.hpp b/boost/test/data/monomorphic/collection.hpp index 5666a62f8d..49e81458bf 100644 --- a/boost/test/data/monomorphic/collection.hpp +++ b/boost/test/data/monomorphic/collection.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) @@ -14,7 +14,7 @@ // Boost.Test #include <boost/test/data/config.hpp> -#include <boost/test/data/monomorphic/dataset.hpp> +#include <boost/test/data/monomorphic/fwd.hpp> #include <boost/test/detail/suppress_warnings.hpp> @@ -35,54 +35,28 @@ namespace monomorphic { //! 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. -//! -//! For compilers supporting r-value references, the collection is moved instead of copied. template<typename C> -class collection : public monomorphic::dataset<typename boost::decay<C>::type::value_type> { +class collection { typedef typename boost::decay<C>::type col_type; - typedef typename col_type::value_type T; - typedef monomorphic::dataset<T> base; - typedef typename base::iter_ptr iter_ptr; - - struct iterator : public base::iterator { - // Constructor - explicit iterator( collection<C> const& owner ) - : m_iter( owner.col().begin() ) - , m_singleton( owner.col().size() == 1 ) - {} - - // forward iterator interface - virtual T const& operator*() { return *m_iter; } - virtual void operator++() { if( !m_singleton ) ++m_iter; } - - private: - // Data members - typename col_type::const_iterator m_iter; - bool m_singleton; - }; - public: + typedef typename col_type::value_type sample; + enum { arity = 1 }; -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES - //! Constructor - //! The collection is moved - explicit collection( C&& col ) : m_col( std::forward<C>(col) ) {} + 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 ) ) {} -#else - //! Constructor - //! The collection is copied - explicit collection( C const& col ) : m_col( col ) {} -#endif //! Returns the underlying collection - C const& col() const { return m_col; } + C const& col() const { return m_col; } - // dataset interface - virtual data::size_t size() const { return m_col.size(); } - virtual iter_ptr begin() const { return boost::make_shared<iterator>( *this ); } + //! dataset interface + data::size_t size() const { return m_col.size(); } + iterator begin() const { return m_col.begin(); } private: // Data members @@ -93,27 +67,19 @@ private: //! A collection from a forward iterable container is a dataset. template<typename C> -struct is_dataset<collection<C> > : mpl::true_ {}; +struct is_dataset<collection<C>> : mpl::true_ {}; } // namespace monomorphic +//____________________________________________________________________________// + //! @overload boost::unit_test::data::make() template<typename C> -inline typename BOOST_TEST_ENABLE_IF<is_forward_iterable<C>::value, - monomorphic::collection<C> >::type -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES +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) ); } -#else -make( C const& c ) -{ - return monomorphic::collection<C>( c ); -} -#endif - -//____________________________________________________________________________// } // namespace data } // namespace unit_test diff --git a/boost/test/data/monomorphic/dataset.hpp b/boost/test/data/monomorphic/dataset.hpp deleted file mode 100644 index 122dbea8c5..0000000000 --- a/boost/test/data/monomorphic/dataset.hpp +++ /dev/null @@ -1,174 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. -// 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 interface -// -// *************************************************************************** - -#ifndef BOOST_TEST_DATA_MONOMORPHIC_DATASET_HPP_102211GER -#define BOOST_TEST_DATA_MONOMORPHIC_DATASET_HPP_102211GER - -// Boost.Test -#include <boost/test/data/config.hpp> -#include <boost/test/data/monomorphic/fwd.hpp> - -// STL -#ifndef BOOST_NO_CXX11_HDR_TUPLE -#include <tuple> -#endif -//#include <stdexcept> - -#include <boost/test/detail/suppress_warnings.hpp> - -//____________________________________________________________________________// - -namespace boost { -namespace unit_test { -namespace data { -namespace monomorphic { - -// ************************************************************************** // -// ************** monomorphic::traits ************** // -// ************************************************************************** // - -template<typename T> -struct traits { - // type of the reference to sample returned by iterator - typedef T const& ref_type; - - template<typename Action> - static void - invoke_action( ref_type arg, Action const& action ) - { - action( arg ); - } -}; - -//____________________________________________________________________________// - -#ifndef BOOST_NO_CXX11_HDR_TUPLE -// !! ?? reimplement using variadics -template<typename T1, typename T2> -struct traits<std::tuple<T1,T2>> { - // type of the reference to sample returned by iterator - typedef std::tuple<T1 const&,T2 const&> ref_type; - - template<typename Action> - static void - invoke_action( ref_type arg, Action const& action ) - { - action( std::get<0>(arg), std::get<1>(arg) ); - } -}; - -//____________________________________________________________________________// - -template<typename T1, typename T2, typename T3> -struct traits<std::tuple<T1,T2,T3>> { - // type of the reference to sample returned by iterator - typedef std::tuple<T1 const&,T2 const&,T3 const&> ref_type; - - template<typename Action> - static void - invoke_action( ref_type arg, Action const& action ) - { - action( std::get<0>(arg), std::get<1>(arg), std::get<2>(arg) ); - } -}; - -//____________________________________________________________________________// - -#endif - -// ************************************************************************** // -// ************** monomorphic::dataset ************** // -// ************************************************************************** // - -//!@brief Dataset base class -//! -//! This class defines the dataset concept, which is an implementation of a sequence. -//! Each dataset should implement -//! - the @c size -//! - the @c begin function, which provides a forward iterator on the beginning of the sequence. The returned -//! iterator should be incrementable a number of times corresponding to the returned size. -//! -template<typename T> -class dataset { -public: - //! Type of the samples in this dataset - typedef T data_type; - - virtual ~dataset() - {} - - //! Interface of the dataset iterator - class iterator { - public: - typedef typename monomorphic::traits<T>::ref_type ref_type; - - virtual ~iterator() {} - - // forward iterator interface - virtual ref_type operator*() = 0; - virtual void operator++() = 0; - }; - - //! Type of the iterator - typedef boost::shared_ptr<iterator> iter_ptr; - - //! Dataset size - virtual data::size_t size() const = 0; - - //! Iterator to use to iterate over this dataset - virtual iter_ptr begin() const = 0; -}; - -} // namespace monomorphic - -// ************************************************************************** // -// ************** for_each_sample ************** // -// ************************************************************************** // - -template<typename SampleType, typename Action> -inline void -for_each_sample( monomorphic::dataset<SampleType> const& ds, - Action const& act, - data::size_t number_of_samples = BOOST_TEST_DS_INFINITE_SIZE ) -{ - data::size_t size = (std::min)( ds.size(), number_of_samples ); - BOOST_TEST_DS_ASSERT( !size.is_inf(), "Dataset has infinite size. Please specify the number of samples" ); - - typename monomorphic::dataset<SampleType>::iter_ptr it = ds.begin(); - - while( size-- > 0 ) { - monomorphic::traits<SampleType>::invoke_action( **it, act ); - ++(*it); - } -} - -//____________________________________________________________________________// - -template<typename SampleType, typename Action> -inline typename BOOST_TEST_ENABLE_IF<!monomorphic::is_dataset<SampleType>::value,void>::type -for_each_sample( SampleType const& samples, - Action const& act, - data::size_t number_of_samples = BOOST_TEST_DS_INFINITE_SIZE ) -{ - data::for_each_sample( data::make( samples ), act, number_of_samples ); -} - -//____________________________________________________________________________// - -} // namespace data -} // namespace unit_test -} // namespace boost - -#include <boost/test/detail/enable_warnings.hpp> - -#endif // BOOST_TEST_DATA_MONOMORPHIC_DATASET_HPP_102211GER - diff --git a/boost/test/data/monomorphic/fwd.hpp b/boost/test/data/monomorphic/fwd.hpp index 9ff4955432..26c36743df 100644 --- a/boost/test/data/monomorphic/fwd.hpp +++ b/boost/test/data/monomorphic/fwd.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2012-2014. +// (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) @@ -18,22 +18,17 @@ #include <boost/test/utils/is_forward_iterable.hpp> - // Boost -#ifdef BOOST_NO_CXX11_RVALUE_REFERENCES -#include <boost/utility/enable_if.hpp> -#include <boost/type_traits/add_const.hpp> -#else -#include <boost/utility/declval.hpp> -#endif #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> -#include <boost/smart_ptr/make_shared.hpp> -#include <boost/shared_ptr.hpp> -#include <boost/type_traits/decay.hpp> #include <boost/test/detail/suppress_warnings.hpp> +// STL +#include <initializer_list> + //____________________________________________________________________________// namespace boost { @@ -44,10 +39,8 @@ namespace monomorphic { #if !defined(BOOST_TEST_DOXYGEN_DOC__) -template<typename T> -struct traits; -template<typename T> +template<typename T, typename Specific> class dataset; template<typename T> @@ -58,12 +51,10 @@ class collection; template<typename T> class array; -#endif -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES -# define BOOST_TEST_ENABLE_IF std::enable_if -#else -# define BOOST_TEST_ENABLE_IF boost::enable_if_c +template<typename T> +class init_list; + #endif // ************************************************************************** // @@ -74,25 +65,24 @@ class array; 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 ************** // // ************************************************************************** // -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES - - //! @brief Creates a dataset from a value, a collection or an array //! //! This function has several overloads: @@ -113,201 +103,74 @@ struct is_dataset<DataSet const> : is_dataset<DataSet> {}; //! template<typename T, std::size_t size> monomorphic::array<T> make( T (&a)[size] ); //! @endcode template<typename DataSet> -inline typename BOOST_TEST_ENABLE_IF<monomorphic::is_dataset<DataSet>::value,DataSet>::type +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. -// fwrd declaration for singletons //! @overload boost::unit_test::data::make() template<typename T> -inline typename BOOST_TEST_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 +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 BOOST_TEST_ENABLE_IF<is_forward_iterable<C>::value, - monomorphic::collection<C> >::type +inline typename std::enable_if<is_forward_iterable<C>::value,monomorphic::collection<C>>::type make( C&& c ); - -#else // !BOOST_NO_CXX11_RVALUE_REFERENCES - -//! @overload boost::unit_test:data::make() -template<typename DataSet> -inline typename BOOST_TEST_ENABLE_IF<monomorphic::is_dataset<DataSet>::value,DataSet const&>::type -make(DataSet const& ds) -{ - return ds; -} - - -// fwrd declaration for singletons -#if !(defined(BOOST_MSVC) && (BOOST_MSVC < 1600)) -//! @overload boost::unit_test::data::make() -template<typename T> -inline typename BOOST_TEST_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 const& v ); -#endif - - -// fwrd declaration for collections -//! @overload boost::unit_test::data::make() -template<typename C> -inline typename BOOST_TEST_ENABLE_IF<is_forward_iterable<C>::value, - monomorphic::collection<C> >::type -make( C const& c ); - //____________________________________________________________________________// - - -#endif // !BOOST_NO_CXX11_RVALUE_REFERENCES - - - - -// fwrd declarations //! @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] ); -// apparently some compilers (eg clang-3.4 on linux) have trouble understanding -// the previous line for T being const -//! @overload boost::unit_test::data::make() -template<typename T, std::size_t size> -inline monomorphic::array< typename boost::remove_const<T>::type > -make( T const (&)[size] ); - -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 { -#ifndef BOOST_NO_CXX11_DECLTYPE //! Result of the make call. template<typename DataSet> -struct make -{ - typedef decltype(data::make(boost::declval<DataSet>())) type; -}; -#else - -// explicit specialisation, cumbersome - -template <typename DataSet, typename Enable = void> -struct make; - -template <typename DataSet> -struct make< - DataSet const&, - typename BOOST_TEST_ENABLE_IF<monomorphic::is_dataset<DataSet>::value>::type - > -{ - typedef DataSet const& type; -}; - -template <typename T> -struct make< - T, - typename BOOST_TEST_ENABLE_IF< (!is_forward_iterable<T>::value && - !monomorphic::is_dataset<T>::value && - !boost::is_array< typename boost::remove_reference<T>::type >::value) - >::type - > -{ - typedef monomorphic::singleton<T> type; -}; - -template <typename C> -struct make< - C, - typename BOOST_TEST_ENABLE_IF< is_forward_iterable<C>::value>::type - > -{ - typedef monomorphic::collection<C> type; -}; - -#if 1 -template <typename T, std::size_t size> -struct make<T [size]> -{ - typedef monomorphic::array<typename boost::remove_const<T>::type> type; +struct make { + typedef decltype( data::make( declval<DataSet>() ) ) type; }; -#endif - -template <typename T, std::size_t size> -struct make<T (&)[size]> -{ - typedef monomorphic::array<typename boost::remove_const<T>::type> type; -}; - -template <typename T, std::size_t size> -struct make<T const (&)[size]> -{ - typedef monomorphic::array<typename boost::remove_const<T>::type> type; -}; - -template <> -struct make<char*> -{ - typedef monomorphic::singleton<char*> type; -}; - -template <> -struct make<char const*> -{ - typedef monomorphic::singleton<char const*> type; -}; - -#endif // BOOST_NO_CXX11_DECLTYPE - } // 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 diff --git a/boost/test/data/monomorphic/generate.hpp b/boost/test/data/monomorphic/generate.hpp index c5ff1d699b..af3b5c0bb9 100644 --- a/boost/test/data/monomorphic/generate.hpp +++ b/boost/test/data/monomorphic/generate.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) @@ -14,7 +14,7 @@ // Boost.Test #include <boost/test/data/config.hpp> -#include <boost/test/data/monomorphic/dataset.hpp> +#include <boost/test/data/monomorphic/fwd.hpp> #include <boost/test/detail/suppress_warnings.hpp> @@ -36,44 +36,43 @@ namespace monomorphic { * - random_t * * The generator concept is the following: - * - the type of the generated samples is given by field @c data_type + * - 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 monomorphic::dataset<typename Generator::data_type> { - typedef typename Generator::data_type T; - typedef monomorphic::dataset<T> base; - typedef typename base::iter_ptr iter_ptr; +class generated_by { +public: + typedef typename Generator::sample sample; + + enum { arity = 1 }; - struct iterator : public base::iterator { + struct iterator { // Constructor explicit iterator( Generator& gen ) - : m_gen( gen ) + : m_gen( &gen ) { - if(m_gen.capacity() > 0) { - m_gen.reset(); + if(m_gen->capacity() > 0) { + m_gen->reset(); ++*this; } } // forward iterator interface - virtual T const& operator*() { return m_curr_sample; } - virtual void operator++() { m_curr_sample = m_gen.next(); } + sample const& operator*() const { return m_curr_sample; } + void operator++() { m_curr_sample = m_gen->next(); } private: // Data members - Generator& m_gen; - T m_curr_sample; + Generator* m_gen; + sample m_curr_sample; }; -public: - enum { arity = 1 }; + typedef Generator generator_type; -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES // Constructor - explicit generated_by( Generator&& G ) + explicit generated_by( Generator&& G ) : m_generator( std::forward<Generator>(G) ) {} @@ -81,29 +80,23 @@ public: generated_by( generated_by&& rhs ) : m_generator( std::forward<Generator>(rhs.m_generator) ) {} -#else - // Constructor - explicit generated_by( Generator const& G ) - : m_generator( G ) - {} -#endif //! Size of the underlying dataset - data::size_t size() const { return m_generator.capacity(); } + data::size_t size() const { return m_generator.capacity(); } //! Iterator on the beginning of the dataset - virtual iter_ptr begin() const { return boost::make_shared<iterator>( boost::ref(const_cast<Generator&>(m_generator)) ); } + iterator begin() const { return iterator( boost::ref(const_cast<Generator&>(m_generator)) ); } private: // Data members - Generator m_generator; + Generator m_generator; }; +//____________________________________________________________________________// //! A generated dataset is a dataset. template<typename Generator> -struct is_dataset<generated_by<Generator> > : mpl::true_ {}; - +struct is_dataset<generated_by<Generator>> : mpl::true_ {}; } // namespace monomorphic } // namespace data diff --git a/boost/test/data/monomorphic/generators.hpp b/boost/test/data/monomorphic/generators.hpp index aa74d7abb1..108d4ba58d 100644 --- a/boost/test/data/monomorphic/generators.hpp +++ b/boost/test/data/monomorphic/generators.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) diff --git a/boost/test/data/monomorphic/generators/keywords.hpp b/boost/test/data/monomorphic/generators/keywords.hpp index 4983678f95..de6a4e89e5 100644 --- a/boost/test/data/monomorphic/generators/keywords.hpp +++ b/boost/test/data/monomorphic/generators/keywords.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) diff --git a/boost/test/data/monomorphic/generators/random.hpp b/boost/test/data/monomorphic/generators/random.hpp index a82eef103d..24a1df3c64 100644 --- a/boost/test/data/monomorphic/generators/random.hpp +++ b/boost/test/data/monomorphic/generators/random.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) @@ -36,7 +36,7 @@ namespace data { namespace { nfp::keyword<struct seed_t> seed; -nfp::keyword<struct distrbution_t> distribution; +nfp::keyword<struct distribution_t> distribution; nfp::keyword<struct engine_t> engine; } // local namespace @@ -47,7 +47,7 @@ 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; + std::uniform_real_distribution<SampleType>>::type type; }; } // namespace ds_detail @@ -66,7 +66,7 @@ template<typename SampleType = double, typename EngineType = std::default_random_engine> class random_t { public: - typedef SampleType data_type; + typedef SampleType sample; typedef DistributionType distr_type; typedef EngineType engine_type; @@ -127,7 +127,7 @@ private: //! //! 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() +inline monomorphic::generated_by< monomorphic::random_t<>> random() { return monomorphic::generated_by<monomorphic::random_t<>>( monomorphic::random_t<>() ); } @@ -136,7 +136,7 @@ inline monomorphic::generated_by< monomorphic::random_t<> > random() /// @overload boost::unit_test::data::random() template<typename SampleType> -inline monomorphic::generated_by< monomorphic::random_t<SampleType> > +inline monomorphic::generated_by< monomorphic::random_t<SampleType>> random( SampleType begin, SampleType end ) { typedef monomorphic::random_t<SampleType> Gen; diff --git a/boost/test/data/monomorphic/generators/xrange.hpp b/boost/test/data/monomorphic/generators/xrange.hpp index 55a51110b4..02da352adf 100644 --- a/boost/test/data/monomorphic/generators/xrange.hpp +++ b/boost/test/data/monomorphic/generators/xrange.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) @@ -49,14 +49,14 @@ namespace monomorphic { template<typename SampleType, typename StepType=SampleType> class xrange_t { public: - typedef SampleType data_type; + typedef SampleType sample; - xrange_t( SampleType const& begin, StepType const& step, data::size_t size ) - : m_begin( begin ) - , m_curr( begin ) - , m_step( step ) + 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 ) + , m_size( size_ ) {} // Generator interface @@ -159,7 +159,7 @@ struct make_xrange { //! //! @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> > +inline monomorphic::generated_by<monomorphic::xrange_t<SampleType>> xrange( Params const& params ) { return monomorphic::ds_detail::make_xrange<SampleType>::_( params ); @@ -169,7 +169,7 @@ xrange( Params const& params ) /// @overload boost::unit_test::data::xrange() template<typename SampleType> -inline monomorphic::generated_by<monomorphic::xrange_t<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 ); @@ -179,22 +179,23 @@ xrange( SampleType const& end_val ) /// @overload boost::unit_test::data::xrange() template<typename SampleType, typename Params> -inline typename enable_if_c<nfp::is_named_params<Params>::value,monomorphic::generated_by<monomorphic::xrange_t<SampleType> > >::type +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 )); + 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> > +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 )); + return monomorphic::ds_detail::make_xrange<SampleType>::_(( + data::begin=begin_val, + data::end=end_val )); } //____________________________________________________________________________// @@ -203,11 +204,13 @@ xrange( SampleType const& begin_val, SampleType const& end_val ) /// @overload boost::unit_test::data::xrange() template<typename SampleType,typename StepType> -inline monomorphic::generated_by<monomorphic::xrange_t<SampleType> > +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 )); + return monomorphic::ds_detail::make_xrange<SampleType,StepType>::_(( + data::begin=begin_val, + data::end=end_val, + data::step=step_val )); } //____________________________________________________________________________// diff --git a/boost/test/data/monomorphic/grid.hpp b/boost/test/data/monomorphic/grid.hpp index 00aaa56cd1..6af906c62c 100644 --- a/boost/test/data/monomorphic/grid.hpp +++ b/boost/test/data/monomorphic/grid.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) @@ -7,8 +7,8 @@ // ///@file /// Defines monomorphic dataset n+m dimentional *. Samples in this -/// dataset is grid of elements in DS1 and DS2. There will be total -/// |DS1| * |DS2| samples +/// dataset is grid of elements in DataSet1 and DataSet2. There will be total +/// |DataSet1| * |DataSet2| samples // *************************************************************************** #ifndef BOOST_TEST_DATA_MONOMORPHIC_GRID_HPP_101512GER @@ -17,10 +17,11 @@ // 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/dataset.hpp> +#include <boost/test/data/traits.hpp> +#include <boost/test/data/monomorphic/fwd.hpp> + #include <boost/test/detail/suppress_warnings.hpp> //____________________________________________________________________________// @@ -36,7 +37,7 @@ namespace ds_detail { template<typename T1, typename T2> struct grid_traits { typedef std::tuple<T1,T2> type; - typedef typename monomorphic::traits<type>::ref_type ref_type; + typedef typename data::traits<type>::ref_type ref_type; static ref_type tuple_merge(T1 const& a1, T2 const& a2) @@ -50,7 +51,7 @@ struct grid_traits { template<typename T1, typename T2,typename T3> struct grid_traits<T1,std::tuple<T2,T3>> { typedef std::tuple<T1,T2,T3> type; - typedef typename monomorphic::traits<type>::ref_type ref_type; + typedef typename data::traits<type>::ref_type ref_type; static ref_type tuple_merge(T1 const& a1, std::tuple<T2 const&,T3 const&> const& a2) @@ -64,7 +65,7 @@ struct grid_traits<T1,std::tuple<T2,T3>> { template<typename T1, typename T2,typename T3> struct grid_traits<std::tuple<T1,T2>,T3> { typedef std::tuple<T1,T2,T3> type; - typedef typename monomorphic::traits<type>::ref_type ref_type; + typedef typename data::traits<type>::ref_type ref_type; static ref_type tuple_merge(std::tuple<T1 const&,T2 const&> const& a1, T3 const& a2) @@ -85,82 +86,83 @@ struct grid_traits<std::tuple<T1,T2>,T3> { //! 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 DS1, typename DS2> -class grid : public monomorphic::dataset<typename ds_detail::grid_traits<typename boost::decay<DS1>::type::data_type, - typename boost::decay<DS2>::type::data_type>::type> { - typedef typename boost::decay<DS1>::type::data_type T1; - typedef typename boost::decay<DS2>::type::data_type T2; +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; - typedef typename monomorphic::dataset<T1>::iter_ptr ds1_iter_ptr; - typedef typename monomorphic::dataset<T2>::iter_ptr ds2_iter_ptr; + typedef typename dataset1_decay::sample sample1; + typedef typename dataset2_decay::sample sample2; - typedef typename ds_detail::grid_traits<T1,T2>::type T; - typedef monomorphic::dataset<T> base; - typedef typename base::iter_ptr iter_ptr; +public: + typedef typename ds_detail::grid_traits<sample1,sample2>::type sample; - struct iterator : public base::iterator { - typedef typename monomorphic::traits<T>::ref_type ref_type; + struct iterator { + typedef typename data::traits<sample>::ref_type ref_type; // Constructor - explicit iterator( ds1_iter_ptr iter1, DS2 const& ds2 ) - : m_iter1( iter1 ) - , m_iter2( ds2.begin() ) - , m_ds2( ds2 ) + 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 ) {} // forward iterator interface - virtual ref_type operator*() { return ds_detail::grid_traits<T1,T2>::tuple_merge( **m_iter1, **m_iter2 ); } - virtual void operator++() + ref_type operator*() const { return ds_detail::grid_traits<sample1,sample2>::tuple_merge( *m_iter1, *m_iter2 ); } + void operator++() { ++m_ds2_pos; - if( m_ds2_pos != m_ds2.size() ) - ++(*m_iter2); + if( m_ds2_pos != m_ds2->size() ) + ++m_iter2; else { m_ds2_pos = 0; - ++(*m_iter1); - m_iter2 = m_ds2.begin(); + ++m_iter1; + m_iter2 = std::move( m_ds2->begin() ); } } private: // Data members - ds1_iter_ptr m_iter1; - ds2_iter_ptr m_iter2; - DS2 const& m_ds2; + dataset1_iter m_iter1; + dataset2_iter m_iter2; + dataset2_decay const* m_ds2; data::size_t m_ds2_pos; }; public: - enum { arity = boost::decay<DS1>::type::arity + boost::decay<DS2>::type::arity }; + enum { arity = boost::decay<DataSet1>::type::arity + boost::decay<DataSet2>::type::arity }; //! Constructor - grid( DS1&& ds1, DS2&& ds2 ) - : m_ds1( std::forward<DS1>( ds1 ) ) - , m_ds2( std::forward<DS2>( ds2 ) ) + 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<DS1>( j.m_ds1 ) ) - , m_ds2( std::forward<DS2>( j.m_ds2 ) ) + : m_ds1( std::forward<DataSet1>( j.m_ds1 ) ) + , m_ds2( std::forward<DataSet2>( j.m_ds2 ) ) {} // dataset interface - virtual data::size_t size() const { return m_ds1.size() * m_ds2.size(); } - virtual iter_ptr begin() const { return boost::make_shared<iterator>( m_ds1.begin(), m_ds2 ); } + 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 - DS1 m_ds1; - DS2 m_ds2; + DataSet1 m_ds1; + DataSet2 m_ds2; }; //____________________________________________________________________________// // A grid dataset is a dataset -template<typename DS1, typename DS2> -struct is_dataset<grid<DS1,DS2> > : mpl::true_ {}; +template<typename DataSet1, typename DataSet2> +struct is_dataset<grid<DataSet1,DataSet2>> : mpl::true_ {}; //____________________________________________________________________________// @@ -176,42 +178,42 @@ struct grid { //____________________________________________________________________________// - - //! Grid operation -template<typename DS1, typename DS2> -inline typename boost::lazy_enable_if_c<is_dataset<DS1>::value && is_dataset<DS2>::value, - result_of::grid<mpl::identity<DS1>,mpl::identity<DS2>> +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*( DS1&& ds1, DS2&& ds2 ) +operator*( DataSet1&& ds1, DataSet2&& ds2 ) { - BOOST_TEST_DS_ASSERT( !ds1.size().is_inf() && !ds2.size().is_inf(), "Grid dimension can't have infinite size" ); + BOOST_TEST_DS_ASSERT( !ds1.size().is_inf() && !ds2.size().is_inf(), "Grid axes can't have infinite size" ); - return grid<DS1,DS2>( std::forward<DS1>( ds1 ), std::forward<DS2>( ds2 ) ); + return grid<DataSet1,DataSet2>( std::forward<DataSet1>( ds1 ), std::forward<DataSet2>( ds2 ) ); } +//____________________________________________________________________________// + //! @overload boost::unit_test::data::operator* -template<typename DS1, typename DS2> -inline typename boost::lazy_enable_if_c<is_dataset<DS1>::value && !is_dataset<DS2>::value, - result_of::grid<mpl::identity<DS1>,data::result_of::make<DS2>> +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*( DS1&& ds1, DS2&& ds2 ) +operator*( DataSet1&& ds1, DataSet2&& ds2 ) { - return std::forward<DS1>(ds1) * data::make(std::forward<DS2>(ds2)); + return std::forward<DataSet1>(ds1) * data::make(std::forward<DataSet2>(ds2)); } +//____________________________________________________________________________// + //! @overload boost::unit_test::data::operator* -template<typename DS1, typename DS2> -inline typename boost::lazy_enable_if_c<!is_dataset<DS1>::value && is_dataset<DS2>::value, - result_of::grid<data::result_of::make<DS1>,mpl::identity<DS2>> +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*( DS1&& ds1, DS2&& ds2 ) +operator*( DataSet1&& ds1, DataSet2&& ds2 ) { - return data::make(std::forward<DS1>(ds1)) * std::forward<DS2>(ds2); + return data::make(std::forward<DataSet1>(ds1)) * std::forward<DataSet2>(ds2); } -//____________________________________________________________________________// - } // namespace monomorphic } // namespace data diff --git a/boost/test/data/monomorphic/initializer_list.hpp b/boost/test/data/monomorphic/initializer_list.hpp new file mode 100644 index 0000000000..3221597396 --- /dev/null +++ b/boost/test/data/monomorphic/initializer_list.hpp @@ -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 + diff --git a/boost/test/data/monomorphic/join.hpp b/boost/test/data/monomorphic/join.hpp index 94b25c78e2..f817994dd3 100644 --- a/boost/test/data/monomorphic/join.hpp +++ b/boost/test/data/monomorphic/join.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) @@ -14,7 +14,7 @@ // Boost.Test #include <boost/test/data/config.hpp> -#include <boost/test/data/monomorphic/dataset.hpp> +#include <boost/test/data/monomorphic/fwd.hpp> #include <boost/test/detail/suppress_warnings.hpp> @@ -33,157 +33,111 @@ namespace monomorphic { //! //! The size of the resulting dataset is the sum of the two underlying datasets. The arity of the datasets //! should match. -template<typename DS1, typename DS2> -class join : public monomorphic::dataset<typename boost::decay<DS1>::type::data_type> { - typedef typename boost::decay<DS1>::type::data_type T; - typedef monomorphic::dataset<T> base; - typedef typename base::iter_ptr iter_ptr; +template<typename DataSet1, typename DataSet2> +class join { + typedef typename boost::decay<DataSet1>::type dataset1_decay; + typedef typename boost::decay<DataSet2>::type dataset2_decay; - struct iterator : public base::iterator { + 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( iter_ptr it1, iter_ptr it2, data::size_t first_size ) -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES - : m_it1( std::move(it1) ) - , m_it2( std::move(it2) ) -#else - : m_it1( it1 ) - , m_it2( it2 ) -#endif + 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 - virtual T const& operator*() { return m_first_size > 0 ? **m_it1 : **m_it2; } - virtual void operator++() { m_first_size > 0 ? (--m_first_size,++(*m_it1)) : ++(*m_it2); } + 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 - iter_ptr m_it1; - iter_ptr m_it2; - data::size_t m_first_size; + dataset1_iter m_it1; + dataset2_iter m_it2; + data::size_t m_first_size; }; -public: - enum { arity = boost::decay<DS1>::type::arity }; - -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES - // Constructor - join( DS1&& ds1, DS2&& ds2 ) - : m_ds1( std::forward<DS1>( ds1 ) ) - , m_ds2( std::forward<DS2>( ds2 ) ) + //! Constructor + join( DataSet1&& ds1, DataSet2&& ds2 ) + : m_ds1( std::forward<DataSet1>( ds1 ) ) + , m_ds2( std::forward<DataSet2>( ds2 ) ) {} - // Move constructor + //! Move constructor join( join&& j ) - : m_ds1( std::forward<DS1>( j.m_ds1 ) ) - , m_ds2( std::forward<DS2>( j.m_ds2 ) ) + : m_ds1( std::forward<DataSet1>( j.m_ds1 ) ) + , m_ds2( std::forward<DataSet2>( j.m_ds2 ) ) {} -#else - // Constructor - join( DS1 const& ds1, DS2 const& ds2 ) - : m_ds1( ds1 ) - , m_ds2( ds2 ) - {} -#endif - // dataset interface - virtual data::size_t size() const { return m_ds1.size() + m_ds2.size(); } - virtual iter_ptr begin() const { return boost::make_shared<iterator>( m_ds1.begin(), - m_ds2.begin(), - m_ds1.size() ); } + //! 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 - DS1 m_ds1; - DS2 m_ds2; + DataSet1 m_ds1; + DataSet2 m_ds2; }; //____________________________________________________________________________// // A joined dataset is a dataset. -template<typename DS1, typename DS2> -struct is_dataset<join<DS1,DS2> > : mpl::true_ {}; +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 DS1Gen, typename DS2Gen> +template<typename DataSet1Gen, typename DataSet2Gen> struct join { - typedef monomorphic::join<typename DS1Gen::type,typename DS2Gen::type> type; + typedef monomorphic::join<typename DataSet1Gen::type,typename DataSet2Gen::type> type; }; } // namespace result_of //____________________________________________________________________________// -template<typename DS1, typename DS2> -inline typename boost::lazy_enable_if_c<is_dataset<DS1>::value && is_dataset<DS2>::value, - result_of::join<mpl::identity<DS1>,mpl::identity<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>,mpl::identity<DataSet2>> >::type -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES -operator+( DS1&& ds1, DS2&& ds2 ) -{ - return join<DS1,DS2>( std::forward<DS1>( ds1 ), std::forward<DS2>( ds2 ) ); -} -#else -operator+( DS1 const& ds1, DS2 const& ds2 ) +operator+( DataSet1&& ds1, DataSet2&& ds2 ) { - return join<DS1,DS2>( ds1, ds2 ); + return join<DataSet1,DataSet2>( std::forward<DataSet1>( ds1 ), std::forward<DataSet2>( ds2 ) ); } -#endif //____________________________________________________________________________// -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES - -template<typename DS1, typename DS2> -inline typename boost::lazy_enable_if_c<is_dataset<DS1>::value && !is_dataset<DS2>::value, - result_of::join<mpl::identity<DS1>,data::result_of::make<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+( DS1&& ds1, DS2&& ds2 ) +operator+( DataSet1&& ds1, DataSet2&& ds2 ) { - return std::forward<DS1>(ds1) + data::make(std::forward<DS2>(ds2)); + return std::forward<DataSet1>( ds1 ) + data::make( std::forward<DataSet2>( ds2 ) ); } -#else -template<typename DS1, typename DS2> -inline typename boost::lazy_enable_if_c<is_dataset<DS1>::value && !is_dataset<DS2>::value, - result_of::join<mpl::identity<DS1>,data::result_of::make<DS2> > ->::type -operator+( DS1 const& ds1, DS2 const& ds2 ) -{ - return ds1 + data::make(ds2); -} -#endif //____________________________________________________________________________// - -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES -template<typename DS1, typename DS2> -inline typename boost::lazy_enable_if_c<!is_dataset<DS1>::value && is_dataset<DS2>::value, - result_of::join<data::result_of::make<DS1>,mpl::identity<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+( DS1&& ds1, DS2&& ds2 ) +operator+( DataSet1&& ds1, DataSet2&& ds2 ) { - return data::make(std::forward<DS1>(ds1)) + std::forward<DS2>(ds2); + return data::make( std::forward<DataSet1>(ds1) ) + std::forward<DataSet2>( ds2 ); } -#else -template<typename DS1, typename DS2> -inline typename boost::lazy_enable_if_c<!is_dataset<DS1>::value && is_dataset<DS2>::value, - result_of::join<data::result_of::make<DS1>,mpl::identity<DS2> > ->::type -operator+( DS1 const& ds1, DS2 const& ds2 ) -{ - return data::make(ds1) + ds2; -} - -#endif - } // namespace monomorphic - } // namespace data } // namespace unit_test } // namespace boost diff --git a/boost/test/data/monomorphic/singleton.hpp b/boost/test/data/monomorphic/singleton.hpp index 4d305c2546..586487a6d7 100644 --- a/boost/test/data/monomorphic/singleton.hpp +++ b/boost/test/data/monomorphic/singleton.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) @@ -14,7 +14,7 @@ // Boost.Test #include <boost/test/data/config.hpp> -#include <boost/test/data/monomorphic/dataset.hpp> +#include <boost/test/data/monomorphic/fwd.hpp> #include <boost/test/detail/suppress_warnings.hpp> @@ -31,102 +31,84 @@ namespace monomorphic { /// Models a single element data set template<typename T> -class singleton : public monomorphic::dataset<typename boost::decay<T>::type> { - typedef monomorphic::dataset<typename boost::decay<T>::type> base; - typedef typename base::iter_ptr iter_ptr; +class singleton { +public: + typedef typename boost::decay<T>::type sample; + + enum { arity = 1 }; - struct iterator : public base::iterator { + struct iterator { // Constructor - explicit iterator( singleton<T> const& owner ) + explicit iterator( singleton<T> const* owner ) : m_owner( owner ) {} // forward iterator interface - virtual typename base::data_type const& - operator*() { return m_owner.value(); } - virtual void operator++() {} + sample const& operator*() const { return m_owner->value(); } + void operator++() {} private: - singleton<T> const& m_owner; + singleton<T> const* m_owner; }; -public: - enum { arity = 1 }; - -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES //! Constructor - explicit singleton( T&& value ) : m_value( std::forward<T>( value ) ) {} + explicit singleton( T&& value ) : m_value( std::forward<T>( value ) ) {} //! Move constructor singleton( singleton&& s ) : m_value( std::forward<T>( s.m_value ) ) {} -#else - // Constructor - explicit singleton( T const& value ) : m_value( value ) {} -#endif - // Access methods - T const& value() const { return m_value; } + //! Value access method + T const& value() const { return m_value; } - // dataset interface - virtual data::size_t size() const { return 1; } - virtual iter_ptr begin() const { return boost::make_shared<iterator>( *this ); } + //! 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 +struct is_dataset<singleton<T>> : mpl::true_ {}; +//____________________________________________________________________________// +} // namespace monomorphic /// @overload boost::unit_test::data::make() template<typename T> -inline typename BOOST_TEST_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> +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 -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES make( T&& v ) { return monomorphic::singleton<T>( std::forward<T>( v ) ); } -#else -make( T const& v ) -{ - return monomorphic::singleton<T>( v ); -} -#endif +//____________________________________________________________________________// /// @overload boost::unit_test::data::make -inline monomorphic::singleton<char*> make( char* str ) +inline monomorphic::singleton<char*> +make( char* str ) { -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES return monomorphic::singleton<char*>( std::move(str) ); -#else - return monomorphic::singleton<char*>( str ); -#endif } +//____________________________________________________________________________// /// @overload boost::unit_test::data::make -inline monomorphic::singleton<char const*> make( char const* str ) +inline monomorphic::singleton<char const*> +make( char const* str ) { -#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES return monomorphic::singleton<char const*>( std::move(str) ); -#else - return monomorphic::singleton<char const*>( str ); -#endif } - - } // namespace data } // namespace unit_test } // namespace boost diff --git a/boost/test/data/monomorphic/zip.hpp b/boost/test/data/monomorphic/zip.hpp index 3ee91817a9..1c7f46472c 100644 --- a/boost/test/data/monomorphic/zip.hpp +++ b/boost/test/data/monomorphic/zip.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) @@ -12,12 +12,14 @@ #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__) -// Boost.Test -#include <boost/test/data/monomorphic/dataset.hpp> +#include <boost/test/data/traits.hpp> +#include <boost/test/data/monomorphic/fwd.hpp> + #include <boost/test/detail/suppress_warnings.hpp> @@ -28,14 +30,11 @@ namespace monomorphic { namespace ds_detail { - -//____________________________________________________________________________// - // !! ?? variadic template implementation; use forward_as_tuple? template<typename T1, typename T2> struct zip_traits { typedef std::tuple<T1,T2> type; - typedef typename monomorphic::traits<type>::ref_type ref_type; + typedef typename data::traits<type>::ref_type ref_type; static ref_type tuple_merge(T1 const& a1, T2 const& a2) @@ -49,7 +48,7 @@ struct zip_traits { template<typename T1, typename T2,typename T3> struct zip_traits<T1,std::tuple<T2,T3>> { typedef std::tuple<T1,T2,T3> type; - typedef typename monomorphic::traits<type>::ref_type ref_type; + typedef typename data::traits<type>::ref_type ref_type; static ref_type tuple_merge(T1 const& a1, std::tuple<T2 const&,T3 const&> const& a2) @@ -63,7 +62,7 @@ struct zip_traits<T1,std::tuple<T2,T3>> { template<typename T1, typename T2,typename T3> struct zip_traits<std::tuple<T1,T2>,T3> { typedef std::tuple<T1,T2,T3> type; - typedef typename monomorphic::traits<type>::ref_type ref_type; + typedef typename data::traits<type>::ref_type ref_type; static ref_type tuple_merge(std::tuple<T1 const&,T2 const&> const& a1, T3 const& a2) @@ -72,8 +71,6 @@ struct zip_traits<std::tuple<T1,T2>,T3> { } }; -//____________________________________________________________________________// - } // namespace ds_detail // ************************************************************************** // @@ -84,82 +81,82 @@ struct zip_traits<std::tuple<T1,T2>,T3> { //! //! 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 DS1, typename DS2> -class zip : public monomorphic::dataset<typename ds_detail::zip_traits<typename boost::decay<DS1>::type::data_type, - typename boost::decay<DS2>::type::data_type>::type> { - typedef typename boost::decay<DS1>::type::data_type T1; - typedef typename boost::decay<DS2>::type::data_type T2; +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; - typedef typename monomorphic::dataset<T1>::iter_ptr ds1_iter_ptr; - typedef typename monomorphic::dataset<T2>::iter_ptr ds2_iter_ptr; + typedef typename dataset1_decay::sample sample1; + typedef typename dataset2_decay::sample sample2; + +public: + typedef typename ds_detail::zip_traits<sample1,sample2>::type sample; - typedef typename ds_detail::zip_traits<T1,T2>::type T; - typedef monomorphic::dataset<T> base; - typedef typename base::iter_ptr iter_ptr; + enum { arity = dataset1_decay::arity + dataset2_decay::arity }; - struct iterator : public base::iterator { - typedef typename monomorphic::traits<T>::ref_type ref_type; + struct iterator { + typedef typename data::traits<sample>::ref_type ref_type; // Constructor - explicit iterator( ds1_iter_ptr iter1, ds2_iter_ptr iter2 ) - : m_iter1( iter1 ) - , m_iter2( iter2 ) + explicit iterator( dataset1_iter iter1, dataset2_iter iter2 ) + : m_iter1( std::move( iter1 ) ) + , m_iter2( std::move( iter2 ) ) {} // forward iterator interface - virtual ref_type operator*() { return ds_detail::zip_traits<T1,T2>::tuple_merge( **m_iter1, **m_iter2 ); } - virtual void operator++() { ++(*m_iter1); ++(*m_iter2); } + ref_type operator*() const { return ds_detail::zip_traits<sample1,sample2>::tuple_merge( *m_iter1, *m_iter2 ); } + void operator++() { ++m_iter1; ++m_iter2; } private: // Data members - ds1_iter_ptr m_iter1; - ds2_iter_ptr m_iter2; + dataset1_iter m_iter1; + dataset2_iter m_iter2; }; -public: - enum { arity = boost::decay<DS1>::type::arity + boost::decay<DS2>::type::arity }; - //! Constructor //! //! The datasets are moved and not copied. - zip( DS1&& ds1, DS2&& ds2, data::size_t size ) - : m_ds1( std::forward<DS1>( ds1 ) ) - , m_ds2( std::forward<DS2>( ds2 ) ) + 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<DS1>( j.m_ds1 ) ) - , m_ds2( std::forward<DS2>( j.m_ds2 ) ) + : m_ds1( std::forward<DataSet1>( j.m_ds1 ) ) + , m_ds2( std::forward<DataSet2>( j.m_ds2 ) ) , m_size( j.m_size ) {} // dataset interface - virtual data::size_t size() const { return m_size; } - virtual iter_ptr begin() const { return boost::make_shared<iterator>( m_ds1.begin(), m_ds2.begin() ); } + data::size_t size() const { return m_size; } + iterator begin() const { return iterator( m_ds1.begin(), m_ds2.begin() ); } private: // Data members - DS1 m_ds1; - DS2 m_ds2; + DataSet1 m_ds1; + DataSet2 m_ds2; data::size_t m_size; }; //____________________________________________________________________________// //! Zipped datasets results in a dataset. -template<typename DS1, typename DS2> -struct is_dataset<zip<DS1,DS2> > : mpl::true_ {}; +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 DS1, typename DS2> +template<typename DataSet1, typename DataSet2> inline data::size_t -zip_size( DS1&& ds1, DS2&& ds2 ) +zip_size( DataSet1&& ds1, DataSet2&& ds2 ) { data::size_t ds1_size = ds1.size(); data::size_t ds2_size = ds2.size(); @@ -190,44 +187,45 @@ struct zip { } // namespace result_of - //____________________________________________________________________________// - //! Overload operator for zip support -template<typename DS1, typename DS2> -inline typename boost::lazy_enable_if_c<is_dataset<DS1>::value && is_dataset<DS2>::value, - result_of::zip<mpl::identity<DS1>,mpl::identity<DS2>> +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^( DS1&& ds1, DS2&& ds2 ) +operator^( DataSet1&& ds1, DataSet2&& ds2 ) { - return zip<DS1,DS2>( std::forward<DS1>( ds1 ), std::forward<DS2>( ds2 ), ds_detail::zip_size( ds1, 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 DS1, typename DS2> -inline typename boost::lazy_enable_if_c<is_dataset<DS1>::value && !is_dataset<DS2>::value, - result_of::zip<mpl::identity<DS1>,data::result_of::make<DS2>> +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^( DS1&& ds1, DS2&& ds2 ) +operator^( DataSet1&& ds1, DataSet2&& ds2 ) { - return std::forward<DS1>(ds1) ^ data::make(std::forward<DS2>(ds2)); + return std::forward<DataSet1>( ds1 ) ^ data::make( std::forward<DataSet2>( ds2 ) ); } +//____________________________________________________________________________// + //! @overload boost::unit_test::data::monomorphic::operator^() -template<typename DS1, typename DS2> -inline typename boost::lazy_enable_if_c<!is_dataset<DS1>::value && is_dataset<DS2>::value, - result_of::zip<data::result_of::make<DS1>,mpl::identity<DS2>> +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^( DS1&& ds1, DS2&& ds2 ) +operator^( DataSet1&& ds1, DataSet2&& ds2 ) { - return data::make(std::forward<DS1>(ds1)) ^ std::forward<DS2>(ds2); + return data::make( std::forward<DataSet1>( ds1 ) ) ^ std::forward<DataSet2>( ds2 ); } -//____________________________________________________________________________// - } // namespace monomorphic - } // namespace data } // namespace unit_test } // namespace boost diff --git a/boost/test/data/size.hpp b/boost/test/data/size.hpp index ddd725d26c..3e9ba96795 100644 --- a/boost/test/data/size.hpp +++ b/boost/test/data/size.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) diff --git a/boost/test/data/test_case.hpp b/boost/test/data/test_case.hpp index 31a61d92ec..112be06c54 100644 --- a/boost/test/data/test_case.hpp +++ b/boost/test/data/test_case.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) @@ -15,6 +15,7 @@ // 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> @@ -41,11 +42,24 @@ namespace boost { namespace unit_test { namespace data { +namespace ds_detail { + // ************************************************************************** // -// ************** test_case_template ************** // +// ************** seed ************** // // ************************************************************************** // -namespace ds_detail { +struct seed { + template<typename DataSet> + typename data::result_of::make<DataSet>::type + operator->*( DataSet&& ds ) const + { + return data::make( std::forward<DataSet>( ds ) ); + } +}; + +// ************************************************************************** // +// ************** test_case_gen ************** // +// ************************************************************************** // template<typename TestCase,typename DataSet> class test_case_gen : public test_unit_generator { @@ -152,7 +166,7 @@ BOOST_AUTO_TU_REGISTRAR( test_name )( \ boost::unit_test::data::ds_detail::make_test_case_gen<test_name>( \ BOOST_STRINGIZE( test_name ), \ __FILE__, __LINE__, \ - boost::unit_test::data::make(dataset) ), \ + boost::unit_test::data::ds_detail::seed{} ->* dataset ), \ boost::unit_test::decorator::collector::instance() ); \ \ template<BOOST_PP_ENUM_PARAMS(arity, typename Arg)> \ diff --git a/boost/test/data/traits.hpp b/boost/test/data/traits.hpp new file mode 100644 index 0000000000..eee52fdab5 --- /dev/null +++ b/boost/test/data/traits.hpp @@ -0,0 +1,87 @@ +// (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 traits +// *************************************************************************** + +#ifndef BOOST_TEST_DATA_TRAITS_HPP_102211GER +#define BOOST_TEST_DATA_TRAITS_HPP_102211GER + +// Boost.Test +#include <boost/test/data/config.hpp> +#include <boost/test/data/monomorphic/fwd.hpp> + +// STL +#include <tuple> + +#include <boost/test/detail/suppress_warnings.hpp> + +//____________________________________________________________________________// + +namespace boost { +namespace unit_test { +namespace data { + +// ************************************************************************** // +// ************** data::traits ************** // +// ************************************************************************** // + +template<typename T> +struct traits { + // type of the reference to sample returned by iterator + typedef T const& ref_type; + + template<typename Action> + static void + invoke_action( ref_type arg, Action const& action ) + { + action( arg ); + } +}; + +//____________________________________________________________________________// + +// !! ?? reimplement using variadics +template<typename T1, typename T2> +struct traits<std::tuple<T1,T2>> { + // type of the reference to sample returned by iterator + typedef std::tuple<T1 const&,T2 const&> ref_type; + + template<typename Action> + static void + invoke_action( ref_type arg, Action const& action ) + { + action( std::get<0>(arg), std::get<1>(arg) ); + } +}; + +//____________________________________________________________________________// + +template<typename T1, typename T2, typename T3> +struct traits<std::tuple<T1,T2,T3>> { + // type of the reference to sample returned by iterator + typedef std::tuple<T1 const&,T2 const&,T3 const&> ref_type; + + template<typename Action> + static void + invoke_action( ref_type arg, Action const& action ) + { + action( std::get<0>(arg), std::get<1>(arg), std::get<2>(arg) ); + } +}; + +//____________________________________________________________________________// + +} // namespace data +} // namespace unit_test +} // namespace boost + +#include <boost/test/detail/enable_warnings.hpp> + +#endif // BOOST_TEST_DATA_TRAITS_HPP_102211GER + diff --git a/boost/test/debug.hpp b/boost/test/debug.hpp index 2d367167ae..a8ccae0b97 100644 --- a/boost/test/debug.hpp +++ b/boost/test/debug.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2006-2014. +// (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) diff --git a/boost/test/debug_config.hpp b/boost/test/debug_config.hpp index 63ceed5f1a..894d78e65a 100644 --- a/boost/test/debug_config.hpp +++ b/boost/test/debug_config.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2006-2014. +// (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) diff --git a/boost/test/detail/config.hpp b/boost/test/detail/config.hpp index 0e0c1f2d45..db9b5d2b92 100644 --- a/boost/test/detail/config.hpp +++ b/boost/test/detail/config.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) @@ -106,10 +106,22 @@ class type_info; #define BOOST_TEST_MAIN BOOST_TEST_MODULE #endif + + +#ifndef BOOST_PP_VARIADICS /* we can change this only if not already defined) */ + #ifdef __PGI #define BOOST_PP_VARIADICS 1 #endif +#if BOOST_CLANG +#define BOOST_PP_VARIADICS 1 +#endif + +#if defined(BOOST_GCC) && (BOOST_GCC >= 4 * 10000 + 8 * 100) +#define BOOST_PP_VARIADICS 1 +#endif +#endif /* ifndef BOOST_PP_VARIADICS */ #endif // BOOST_TEST_CONFIG_HPP_071894GER diff --git a/boost/test/detail/enable_warnings.hpp b/boost/test/detail/enable_warnings.hpp index 13fd01f445..45afb31944 100644 --- a/boost/test/detail/enable_warnings.hpp +++ b/boost/test/detail/enable_warnings.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2004-2014. +// (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) @@ -26,6 +26,11 @@ # pragma warning(pop) #endif -#ifdef BOOST_CLANG +#if BOOST_CLANG #pragma clang diagnostic pop #endif + +#if defined(BOOST_GCC) && (BOOST_GCC >= 4 * 10000 + 6 * 100) +# pragma GCC diagnostic pop +#endif + diff --git a/boost/test/detail/fwd_decl.hpp b/boost/test/detail/fwd_decl.hpp index 5f4110b096..944d52267d 100644 --- a/boost/test/detail/fwd_decl.hpp +++ b/boost/test/detail/fwd_decl.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) diff --git a/boost/test/detail/global_typedef.hpp b/boost/test/detail/global_typedef.hpp index 0c71479a23..9b7653c078 100644 --- a/boost/test/detail/global_typedef.hpp +++ b/boost/test/detail/global_typedef.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) @@ -19,13 +19,6 @@ #define BOOST_TEST_STRINGIZE( s ) BOOST_TEST_L( BOOST_STRINGIZE( s ) ) #define BOOST_TEST_EMPTY_STRING BOOST_TEST_L( "" ) -#define BOOST_TEST_SCOPE_SETCOLOR( os, attr, color ) \ - scope_setcolor const& sc = runtime_config::color_output() \ - ? scope_setcolor( os, attr, color ) \ - : scope_setcolor(); \ - ut_detail::ignore_unused_variable_warning( sc ) \ -/**/ - #include <boost/test/detail/suppress_warnings.hpp> //____________________________________________________________________________// @@ -44,7 +37,7 @@ enum report_level { INV_REPORT_LEVEL, CONFIRMATION_REPORT, SHORT_REPORT, DETAIL enum output_format { OF_INVALID, OF_CLF, ///< compiler log format OF_XML, ///< XML format for report and log, - OF_DOT ///< dot format for output content + OF_DOT ///< dot format for output content }; //____________________________________________________________________________// @@ -77,6 +70,8 @@ test_id_2_unit_type( test_unit_id id ) //____________________________________________________________________________// +} // namespace ut_detail + // helper templates to prevent ODR violations template<class T> struct static_constant { @@ -88,8 +83,6 @@ T static_constant<T>::value; //____________________________________________________________________________// -} // namespace ut_detail - } // namespace unit_test } // namespace boost diff --git a/boost/test/detail/log_level.hpp b/boost/test/detail/log_level.hpp index 5975161773..abdecea7ec 100644 --- a/boost/test/detail/log_level.hpp +++ b/boost/test/detail/log_level.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) diff --git a/boost/test/detail/pp_variadic.hpp b/boost/test/detail/pp_variadic.hpp index 3d31cd1705..a443744daa 100644 --- a/boost/test/detail/pp_variadic.hpp +++ b/boost/test/detail/pp_variadic.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2015. +// (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) diff --git a/boost/test/detail/suppress_warnings.hpp b/boost/test/detail/suppress_warnings.hpp index f667d31242..4badf20758 100644 --- a/boost/test/detail/suppress_warnings.hpp +++ b/boost/test/detail/suppress_warnings.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2004-2014. +// (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) @@ -26,7 +26,13 @@ # pragma warning(disable: 4511) // 'class' : copy constructor could not be generated #endif -#ifdef BOOST_CLANG -#pragma clang diagnostic push -//#pragma clang diagnostic ignored "-Wlogical-op-parentheses" +#if BOOST_CLANG +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wvariadic-macros" #endif + +#if defined(BOOST_GCC) && (BOOST_GCC >= 4 * 10000 + 6 * 100) +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wvariadic-macros" +#endif + diff --git a/boost/test/detail/throw_exception.hpp b/boost/test/detail/throw_exception.hpp index b29b9c07dd..2fee10c2cb 100644 --- a/boost/test/detail/throw_exception.hpp +++ b/boost/test/detail/throw_exception.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2015. +// (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) @@ -29,34 +29,37 @@ namespace boost { namespace unit_test { namespace ut_detail { -#ifdef BOOST_NO_EXCEPTION +#ifdef BOOST_NO_EXCEPTIONS template<typename E> -inline int -throw_exception(E const& e) { abort(); return 0; } +BOOST_NORETURN inline void +throw_exception(E const& e) { abort(); } -#define BOOST_TEST_IMPL_TRY -#define BOOST_TEST_IMPL_CATCH( T, var ) for(T const& var = *(T*)0; false;) -#define BOOST_TEST_IMPL_CATCH0( T ) if(0) -#define BOOST_TEST_IMPL_CATCHALL() if(0) -#define BOOST_TEST_IMPL_RETHROW +#define BOOST_TEST_I_TRY +#define BOOST_TEST_I_CATCH( T, var ) for(T const& var = *(T*)0; false;) +#define BOOST_TEST_I_CATCH0( T ) if(0) +#define BOOST_TEST_I_CATCHALL() if(0) +#define BOOST_TEST_I_RETHROW #else template<typename E> -inline int -throw_exception(E const& e) { throw e; return 0; } - -#define BOOST_TEST_IMPL_TRY try -#define BOOST_TEST_IMPL_CATCH( T, var ) catch( T const& var ) -#define BOOST_TEST_IMPL_CATCH0( T ) catch( T const& ) -#define BOOST_TEST_IMPL_CATCHALL() catch(...) -#define BOOST_TEST_IMPL_RETHROW throw +BOOST_NORETURN inline void +throw_exception(E const& e) { throw e; } + +#define BOOST_TEST_I_TRY try +#define BOOST_TEST_I_CATCH( T, var ) catch( T const& var ) +#define BOOST_TEST_I_CATCH0( T ) catch( T const& ) +#define BOOST_TEST_I_CATCHALL() catch(...) +#define BOOST_TEST_I_RETHROW throw #endif //____________________________________________________________________________// -#define BOOST_TEST_IMPL_THROW( E ) unit_test::ut_detail::throw_exception( E ) +#define BOOST_TEST_I_THROW( E ) unit_test::ut_detail::throw_exception( E ) +#define BOOST_TEST_I_THROW( E ) unit_test::ut_detail::throw_exception( E ) +#define BOOST_TEST_I_ASSRT( cond, ex ) if( cond ) {} else BOOST_TEST_I_THROW( ex ) + } // namespace ut_detail } // namespace unit_test diff --git a/boost/test/detail/workaround.hpp b/boost/test/detail/workaround.hpp index 60a03eca61..4ba3a7e934 100644 --- a/boost/test/detail/workaround.hpp +++ b/boost/test/detail/workaround.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) diff --git a/boost/test/execution_monitor.hpp b/boost/test/execution_monitor.hpp index b01137da7b..c9036be5ba 100644 --- a/boost/test/execution_monitor.hpp +++ b/boost/test/execution_monitor.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (C) Copyright Gennadiy Rozental 2001. // (C) Copyright Beman Dawes 2001. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -415,10 +415,10 @@ public: // translator holder interface virtual int operator()( boost::function<int ()> const& F ) { - BOOST_TEST_IMPL_TRY { + BOOST_TEST_I_TRY { return m_next ? (*m_next)( F ) : F(); } - BOOST_TEST_IMPL_CATCH( ExceptionType, e ) { + BOOST_TEST_I_CATCH( ExceptionType, e ) { m_translator( e ); return boost::exit_exception_failure; } @@ -461,13 +461,11 @@ public: // Constructor explicit system_error( char const* exp ); - unit_test::readonly_property<long> p_errno; - unit_test::readonly_property<char const*> p_failed_exp; + long const p_errno; + char const* const p_failed_exp; }; -#define BOOST_TEST_SYS_ASSERT( exp ) \ - if( (exp) ) ; \ - else BOOST_TEST_IMPL_THROW( ::boost::system_error( BOOST_STRINGIZE( exp ) ) ) +#define BOOST_TEST_SYS_ASSERT( cond ) BOOST_TEST_I_ASSRT( cond, ::boost::system_error( BOOST_STRINGIZE( exp ) ) ) // ************************************************************************** // // **************Floating point exception management interface ************** // diff --git a/boost/test/floating_point_comparison.hpp b/boost/test/floating_point_comparison.hpp index 8475520f32..e889274477 100644 --- a/boost/test/floating_point_comparison.hpp +++ b/boost/test/floating_point_comparison.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) diff --git a/boost/test/framework.hpp b/boost/test/framework.hpp index 92716a0be0..1f5189d23c 100644 --- a/boost/test/framework.hpp +++ b/boost/test/framework.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) @@ -120,7 +120,7 @@ BOOST_TEST_DECL void deregister_test_unit( test_unit* tu ); // This function clears up the framework mono-state. -/// Afer this call the framework can be reinitialized to perform a second test run during the same program lifetime. +/// After this call the framework can be reinitialized to perform a second test run during the same program lifetime. BOOST_TEST_DECL void clear(); /// @} @@ -254,13 +254,15 @@ struct BOOST_TEST_DECL setup_error : public std::runtime_error { setup_error( const_string m ) : std::runtime_error( std::string( m.begin(), m.size() ) ) {} }; -#define BOOST_TEST_SETUP_ASSERT( cond, msg ) \ - if( cond ) {} \ - else BOOST_TEST_IMPL_THROW( unit_test::framework::setup_error( msg ) ) +#define BOOST_TEST_SETUP_ASSERT( cond, msg ) BOOST_TEST_I_ASSRT( cond, unit_test::framework::setup_error( msg ) ) //____________________________________________________________________________// -struct nothing_to_test {}; // not really an error +struct nothing_to_test { + explicit nothing_to_test( int rc ) : m_result_code( rc ) {} + + int m_result_code; +}; //____________________________________________________________________________// @@ -271,4 +273,3 @@ struct nothing_to_test {}; // not really an error #include <boost/test/detail/enable_warnings.hpp> #endif // BOOST_TEST_FRAMEWORK_HPP_020805GER - diff --git a/boost/test/impl/compiler_log_formatter.ipp b/boost/test/impl/compiler_log_formatter.ipp index c1ed944ab1..c5aa6afe93 100644 --- a/boost/test/impl/compiler_log_formatter.ipp +++ b/boost/test/impl/compiler_log_formatter.ipp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) @@ -16,14 +16,18 @@ #define BOOST_TEST_COMPILER_LOG_FORMATTER_IPP_020105GER // Boost.Test +#include <boost/test/output/compiler_log_formatter.hpp> + #include <boost/test/framework.hpp> #include <boost/test/execution_monitor.hpp> +#include <boost/test/unit_test_parameters.hpp> + #include <boost/test/tree/test_unit.hpp> + #include <boost/test/utils/basic_cstring/io.hpp> #include <boost/test/utils/lazy_ostream.hpp> #include <boost/test/utils/setcolor.hpp> -#include <boost/test/output/compiler_log_formatter.hpp> -#include <boost/test/unit_test_parameters.hpp> + // Boost #include <boost/version.hpp> @@ -58,6 +62,8 @@ test_phase_identifier() void compiler_log_formatter::log_start( std::ostream& output, counter_t test_cases_amount ) { + m_color_output = runtime_config::get<bool>( runtime_config::COLOR_OUTPUT ); + if( test_cases_amount > 0 ) output << "Running " << test_cases_amount << " test " << (test_cases_amount > 1 ? "cases" : "case") << "...\n"; @@ -89,7 +95,7 @@ compiler_log_formatter::log_build_info( std::ostream& output ) void compiler_log_formatter::test_unit_start( std::ostream& output, test_unit const& tu ) { - BOOST_TEST_SCOPE_SETCOLOR( output, term_attr::BRIGHT, term_color::BLUE ); + BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::BLUE ); print_prefix( output, tu.p_file_name, tu.p_line_num ); @@ -101,7 +107,7 @@ compiler_log_formatter::test_unit_start( std::ostream& output, test_unit const& void compiler_log_formatter::test_unit_finish( std::ostream& output, test_unit const& tu, unsigned long elapsed ) { - BOOST_TEST_SCOPE_SETCOLOR( output, term_attr::BRIGHT, term_color::BLUE ); + BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::BLUE ); print_prefix( output, tu.p_file_name, tu.p_line_num ); @@ -123,7 +129,7 @@ compiler_log_formatter::test_unit_finish( std::ostream& output, test_unit const& void compiler_log_formatter::test_unit_skipped( std::ostream& output, test_unit const& tu, const_string reason ) { - BOOST_TEST_SCOPE_SETCOLOR( output, term_attr::BRIGHT, term_color::YELLOW ); + BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::YELLOW ); print_prefix( output, tu.p_file_name, tu.p_line_num ); @@ -140,7 +146,7 @@ compiler_log_formatter::log_exception_start( std::ostream& output, log_checkpoin print_prefix( output, loc.m_file_name, loc.m_line_num ); { - BOOST_TEST_SCOPE_SETCOLOR( output, term_attr::BLINK, term_color::RED ); + BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BLINK, term_color::RED ); output << "fatal error: in \"" << (loc.m_function.is_empty() ? test_phase_identifier() : loc.m_function ) << "\": " << ex.what(); @@ -150,7 +156,7 @@ compiler_log_formatter::log_exception_start( std::ostream& output, log_checkpoin output << '\n'; print_prefix( output, checkpoint_data.m_file_name, checkpoint_data.m_line_num ); - BOOST_TEST_SCOPE_SETCOLOR( output, term_attr::BRIGHT, term_color::CYAN ); + BOOST_TEST_SCOPE_SETCOLOR( m_color_output, output, term_attr::BRIGHT, term_color::CYAN ); output << "last checkpoint"; if( !checkpoint_data.m_message.empty() ) @@ -171,32 +177,34 @@ compiler_log_formatter::log_exception_finish( std::ostream& output ) void compiler_log_formatter::log_entry_start( std::ostream& output, log_entry_data const& entry_data, log_entry_types let ) { + using namespace utils; + switch( let ) { case BOOST_UTL_ET_INFO: print_prefix( output, entry_data.m_file_name, entry_data.m_line_num ); - if( runtime_config::color_output() ) + if( m_color_output ) output << setcolor( term_attr::BRIGHT, term_color::GREEN ); output << "info: "; break; case BOOST_UTL_ET_MESSAGE: - if( runtime_config::color_output() ) + if( m_color_output ) output << setcolor( term_attr::BRIGHT, term_color::CYAN ); break; case BOOST_UTL_ET_WARNING: print_prefix( output, entry_data.m_file_name, entry_data.m_line_num ); - if( runtime_config::color_output() ) + if( m_color_output ) output << setcolor( term_attr::BRIGHT, term_color::YELLOW ); output << "warning: in \"" << test_phase_identifier() << "\": "; break; case BOOST_UTL_ET_ERROR: print_prefix( output, entry_data.m_file_name, entry_data.m_line_num ); - if( runtime_config::color_output() ) + if( m_color_output ) output << setcolor( term_attr::BRIGHT, term_color::RED ); output << "error: in \"" << test_phase_identifier() << "\": "; break; case BOOST_UTL_ET_FATAL_ERROR: print_prefix( output, entry_data.m_file_name, entry_data.m_line_num ); - if( runtime_config::color_output() ) + if( m_color_output ) output << setcolor( term_attr::BLINK, term_color::RED ); output << "fatal error: in \"" << test_phase_identifier() << "\": "; break; @@ -224,8 +232,8 @@ compiler_log_formatter::log_entry_value( std::ostream& output, lazy_ostream cons void compiler_log_formatter::log_entry_finish( std::ostream& output ) { - if( runtime_config::color_output() ) - output << setcolor(); + if( m_color_output ) + output << utils::setcolor(); output << std::endl; } @@ -236,8 +244,7 @@ compiler_log_formatter::log_entry_finish( std::ostream& output ) void compiler_log_formatter::print_prefix( std::ostream& output, const_string file_name, std::size_t line_num ) { - if( !file_name.empty() ) - { + if( !file_name.empty() ) { #ifdef __APPLE_CC__ // Xcode-compatible logging format, idea by Richard Dingwall at // <http://richarddingwall.name/2008/06/01/using-the-boost-unit-test-framework-with-xcode-3/>. diff --git a/boost/test/impl/cpp_main.ipp b/boost/test/impl/cpp_main.ipp index 5cab0f4274..aaa5cabfc5 100644 --- a/boost/test/impl/cpp_main.ipp +++ b/boost/test/impl/cpp_main.ipp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (C) Copyright Gennadiy Rozental 2001. // (C) Copyright Beman Dawes 1995-2001. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -68,7 +68,7 @@ prg_exec_monitor_main( int (*cpp_main)( int argc, char* argv[] ), int argc, char { int result = 0; - BOOST_TEST_IMPL_TRY { + BOOST_TEST_I_TRY { boost::unit_test::const_string p( std::getenv( "BOOST_TEST_CATCH_SYSTEM_ERRORS" ) ); ::boost::execution_monitor ex_mon; @@ -83,11 +83,11 @@ prg_exec_monitor_main( int (*cpp_main)( int argc, char* argv[] ), int argc, char result = ::boost::exit_failure; } } - BOOST_TEST_IMPL_CATCH( ::boost::execution_exception, exex ) { + BOOST_TEST_I_CATCH( ::boost::execution_exception, exex ) { std::cout << "\n**** exception(" << exex.code() << "): " << exex.what() << std::endl; result = ::boost::exit_exception_failure; } - BOOST_TEST_IMPL_CATCH( ::boost::system_error, ex ) { + BOOST_TEST_I_CATCH( ::boost::system_error, ex ) { std::cout << "\n**** failed to initialize execution monitor." << "\n**** expression at fault: " << ex.p_failed_exp << "\n**** error(" << ex.p_errno << "): " << std::strerror( ex.p_errno ) << std::endl; diff --git a/boost/test/impl/debug.ipp b/boost/test/impl/debug.ipp index 90e9d7ff2f..f4ee4971ce 100644 --- a/boost/test/impl/debug.ipp +++ b/boost/test/impl/debug.ipp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2006-2014. +// (C) Copyright Gennadiy Rozental 2001. // Use, modification, and distribution are subject to the // Boost Software License, Version 1.0. (See accompanying file // http://www.boost.org/LICENSE_1_0.txt) @@ -305,8 +305,8 @@ prepare_window_title( dbg_startup_info const& dsi ) str_t path_sep( "\\/" ); - str_t::iterator it = unit_test::find_last_of( dsi.binary_path.begin(), dsi.binary_path.end(), - path_sep.begin(), path_sep.end() ); + str_t::iterator it = unit_test::utils::find_last_of( dsi.binary_path.begin(), dsi.binary_path.end(), + path_sep.begin(), path_sep.end() ); if( it == dsi.binary_path.end() ) it = dsi.binary_path.begin(); diff --git a/boost/test/impl/decorator.ipp b/boost/test/impl/decorator.ipp index bf17907881..74d42b22a2 100644 --- a/boost/test/impl/decorator.ipp +++ b/boost/test/impl/decorator.ipp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) @@ -132,10 +132,10 @@ depends_on::apply( test_unit& tu ) #if !BOOST_TEST_SUPPORT_TOKEN_ITERATOR BOOST_TEST_SETUP_ASSERT( false, "depends_on decorator is not supported on this platform" ); #else - string_token_iterator tit( m_dependency, (dropped_delimeters = "/", kept_delimeters = dt_none) ); + utils::string_token_iterator tit( m_dependency, (utils::dropped_delimeters = "/", utils::kept_delimeters = utils::dt_none) ); test_unit* dep = &framework::master_test_suite(); - while( tit != string_token_iterator() ) { + while( tit != utils::string_token_iterator() ) { BOOST_TEST_SETUP_ASSERT( dep->p_type == TUT_SUITE, std::string( "incorrect dependency specification " ) + m_dependency ); test_unit_id next_id = static_cast<test_suite*>(dep)->get( *tit ); diff --git a/boost/test/impl/execution_monitor.ipp b/boost/test/impl/execution_monitor.ipp index 9929f74b53..b3e873efbe 100644 --- a/boost/test/impl/execution_monitor.ipp +++ b/boost/test/impl/execution_monitor.ipp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (C) Copyright Gennadiy Rozental 2001. // (C) Copyright Beman Dawes and Ullrich Koethe 1995-2001. // Use, modification, and distribution are subject to the // Boost Software License, Version 1.0. (See accompanying file @@ -243,9 +243,9 @@ report_error( execution_exception::error_code ec, boost::exception const* be, ch va_end( *args ); - throw execution_exception( ec, buf, execution_exception::location( extract<throw_file>( be ), - (size_t)extract<throw_line>( be ), - extract<throw_function>( be ) ) ); + BOOST_TEST_I_THROW(execution_exception( ec, buf, execution_exception::location( extract<throw_file>( be ), + (size_t)extract<throw_line>( be ), + extract<throw_function>( be ) ) )); } //____________________________________________________________________________// @@ -869,7 +869,7 @@ execution_monitor::catch_signals( boost::function<int ()> const& F ) if( !sigsetjmp( signal_handler::jump_buffer(), 1 ) ) return detail::do_invoke( m_custom_translators , F ); else - return BOOST_TEST_IMPL_THROW( local_signal_handler.sys_sig() ); + BOOST_TEST_I_THROW( local_signal_handler.sys_sig() ); } //____________________________________________________________________________// @@ -1200,14 +1200,14 @@ execution_monitor::execute( boost::function<int ()> const& F ) if( debug::under_debugger() ) p_catch_system_errors.value = false; - BOOST_TEST_IMPL_TRY { + BOOST_TEST_I_TRY { detail::fpe_except_guard G( p_detect_fp_exceptions ); unit_test::ut_detail::ignore_unused_variable_warning( G ); return catch_signals( F ); } -#ifndef BOOST_NO_EXCEPTION +#ifndef BOOST_NO_EXCEPTIONS // Catch-clause reference arguments are a bit different from function // arguments (ISO 15.3 paragraphs 18 & 19). Apparently const isn't @@ -1273,7 +1273,7 @@ execution_monitor::execute( boost::function<int ()> const& F ) // system errors catch( system_error const& ex ) { detail::report_error( execution_exception::cpp_exception_error, - "system_error produced by: %s: %s", ex.p_failed_exp.get(), std::strerror( ex.p_errno ) ); } + "system_error produced by: %s: %s", ex.p_failed_exp, std::strerror( ex.p_errno ) ); } catch( detail::system_signal_exception const& ex ) { ex.report(); } diff --git a/boost/test/impl/framework.ipp b/boost/test/impl/framework.ipp index a69d95cd2d..f710828051 100644 --- a/boost/test/impl/framework.ipp +++ b/boost/test/impl/framework.ipp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) @@ -170,8 +170,7 @@ static void invoke_init_func( init_unit_test_func init_func ) { #ifdef BOOST_TEST_ALTERNATIVE_INIT_API - if( !(*init_func)() ) - BOOST_TEST_IMPL_THROW( std::runtime_error( "test module initialization failed" ) ); + BOOST_TEST_I_ASSRT( (*init_func)(), std::runtime_error( "test module initialization failed" ) ); #else test_suite* manual_test_units = (*init_func)( framework::master_test_suite().argc, framework::master_test_suite().argv ); @@ -237,11 +236,14 @@ public: name_filter( test_unit_id_list& targ_list, const_string filter_expr ) : m_targ_list( targ_list ), m_depth( 0 ) { #ifdef BOOST_TEST_SUPPORT_TOKEN_ITERATOR - string_token_iterator tit( filter_expr, (dropped_delimeters = "/", kept_delimeters = dt_none) ); + utils::string_token_iterator tit( filter_expr, (utils::dropped_delimeters = "/", + utils::kept_delimeters = utils::dt_none) ); - while( tit != string_token_iterator() ) { - m_components.push_back( std::vector<component>( string_token_iterator( *tit, (dropped_delimeters = ",", kept_delimeters = dt_none) ), - string_token_iterator() ) ); + while( tit != utils::string_token_iterator() ) { + m_components.push_back( + std::vector<component>( utils::string_token_iterator( *tit, (utils::dropped_delimeters = ",", + utils::kept_delimeters = utils::dt_none) ), + utils::string_token_iterator() ) ); ++tit; } @@ -390,7 +392,9 @@ parse_filters( test_unit_id master_tu_id, test_unit_id_list& tu_to_enable, test_ // 10. collect tu to enable and disable based on filters bool had_selector_filter = false; - BOOST_TEST_FOREACH( const_string, filter, runtime_config::test_to_run() ) { + std::vector<std::string> const& filters = runtime_config::get<std::vector<std::string> >( runtime_config::RUN_FILTERS ); + + BOOST_TEST_FOREACH( const_string, filter, filters ) { BOOST_TEST_SETUP_ASSERT( !filter.is_empty(), "Invalid filter specification" ); enum { SELECTOR, ENABLER, DISABLER } filter_type = SELECTOR; @@ -433,6 +437,8 @@ public: , m_next_test_suite_id( MIN_TEST_SUITE_ID ) , m_test_in_progress( false ) , m_context_idx( 0 ) + , m_log_sink( std::cout ) + , m_report_sink( std::cerr ) { } @@ -531,12 +537,12 @@ public: test_unit_id_list tu_to_disable; // 10. If there are any filters supplied, figure out lists of test units to enable/disable - bool had_selector_filter = !runtime_config::test_to_run().empty() && + bool had_selector_filter = !runtime_config::get<std::vector<std::string> >( runtime_config::RUN_FILTERS ).empty() && parse_filters( master_tu_id, tu_to_enable, tu_to_disable ); // 20. Set the stage: either use default run status or disable all test units - set_run_status setter( had_selector_filter ? test_unit::RS_DISABLED : test_unit::RS_INVALID ); - traverse_test_tree( master_tu_id, setter, true ); + set_run_status initial_setter( had_selector_filter ? test_unit::RS_DISABLED : test_unit::RS_INVALID ); + traverse_test_tree( master_tu_id, initial_setter, true ); // 30. Apply all selectors and enablers. while( !tu_to_enable.empty() ) { @@ -549,8 +555,8 @@ public: continue; // set new status and add all dependencies into tu_to_enable - set_run_status setter( test_unit::RS_ENABLED, &tu_to_enable ); - traverse_test_tree( tu.p_id, setter, true ); + set_run_status enabler( test_unit::RS_ENABLED, &tu_to_enable ); + traverse_test_tree( tu.p_id, enabler, true ); } // 40. Apply all disablers @@ -563,8 +569,8 @@ public: if( !tu.is_enabled() ) continue; - set_run_status setter( test_unit::RS_DISABLED ); - traverse_test_tree( tu.p_id, setter, true ); + set_run_status disabler( test_unit::RS_DISABLED ); + traverse_test_tree( tu.p_id, disabler, true ); } // 50. Make sure parents of enabled test units are also enabled @@ -627,7 +633,7 @@ public: if( tu.p_type == TUT_SUITE ) { test_suite const& ts = static_cast<test_suite const&>( tu ); - if( runtime_config::random_seed() == 0 ) { + if( runtime_config::get<unsigned>( runtime_config::RANDOM_SEED ) == 0 ) { typedef std::pair<counter_t,test_unit_id> value_type; BOOST_TEST_FOREACH( value_type, chld, ts.m_ranked_children ) { @@ -768,6 +774,9 @@ public: int m_context_idx; boost::execution_monitor m_aux_em; + + runtime_config::stream_holder m_log_sink; + runtime_config::stream_holder m_report_sink; }; //____________________________________________________________________________// @@ -802,41 +811,48 @@ setup_for_execution( test_unit const& tu ) void init( init_unit_test_func init_func, int argc, char* argv[] ) { + using namespace impl; + // 10. Set up runtime parameters runtime_config::init( argc, argv ); - // 20. Set the desired log level and format - unit_test_log.set_threshold_level( runtime_config::log_level() ); - unit_test_log.set_format( runtime_config::log_format() ); + // 20. Set the desired log level, format and sink + unit_test_log.set_threshold_level( runtime_config::get<log_level>( runtime_config::LOG_LEVEL ) ); + unit_test_log.set_format( runtime_config::get<output_format>( runtime_config::LOG_FORMAT ) ); + s_frk_state().m_log_sink.setup( runtime_config::LOG_SINK ); + unit_test_log.set_stream( s_frk_state().m_log_sink.ref() ); - // 30. Set the desired report level and format - results_reporter::set_level( runtime_config::report_level() ); - results_reporter::set_format( runtime_config::report_format() ); + // 30. Set the desired report level, format and sink + results_reporter::set_level( runtime_config::get<report_level>( runtime_config::REPORT_LEVEL ) ); + results_reporter::set_format( runtime_config::get<output_format>( runtime_config::REPORT_FORMAT ) ); + s_frk_state().m_report_sink.setup( runtime_config::REPORT_SINK ); + results_reporter::set_stream( s_frk_state().m_report_sink.ref() ); // 40. Register default test observers register_observer( results_collector ); register_observer( unit_test_log ); - if( runtime_config::show_progress() ) + if( runtime_config::get<bool>( runtime_config::SHOW_PROGRESS ) ) { + progress_monitor.set_stream( s_frk_state().m_log_sink.ref() ); register_observer( progress_monitor ); + } // 50. Set up memory leak detection - if( runtime_config::detect_memory_leaks() > 0 ) { - debug::detect_memory_leaks( true, runtime_config::memory_leaks_report_file() ); - debug::break_memory_alloc( runtime_config::detect_memory_leaks() ); + unsigned long detect_mem_leak = runtime_config::get<unsigned long>( runtime_config::DETECT_MEM_LEAKS ); + if( detect_mem_leak > 0 ) { + debug::detect_memory_leaks( true, runtime_config::get<std::string>( runtime_config::REPORT_MEM_LEAKS ) ); + debug::break_memory_alloc( (long)detect_mem_leak ); } // 60. Initialize master unit test suite master_test_suite().argc = argc; master_test_suite().argv = argv; - using namespace impl; - // 70. Invoke test module initialization routine - BOOST_TEST_IMPL_TRY { + BOOST_TEST_I_TRY { s_frk_state().m_aux_em.vexecute( boost::bind( &impl::invoke_init_func, init_func ) ); } - BOOST_TEST_IMPL_CATCH( execution_exception, ex ) { + BOOST_TEST_I_CATCH( execution_exception, ex ) { BOOST_TEST_SETUP_ASSERT( false, ex.what() ); } } @@ -1157,8 +1173,7 @@ get( test_unit_id id, test_unit_type t ) { test_unit* res = impl::s_frk_state().m_test_units[id]; - if( (res->p_type & t) == 0 ) - BOOST_TEST_IMPL_THROW( internal_error( "Invalid test unit type" ) ); + BOOST_TEST_I_ASSRT( (res->p_type & t) != 0, internal_error( "Invalid test unit type" ) ); return *res; } @@ -1181,7 +1196,7 @@ run( test_unit_id id, bool continue_test ) test_case_counter tcc; traverse_test_tree( id, tcc ); - BOOST_TEST_SETUP_ASSERT( tcc.p_count != 0 , runtime_config::test_to_run().empty() + BOOST_TEST_SETUP_ASSERT( tcc.p_count != 0 , runtime_config::get<std::vector<std::string> >( runtime_config::RUN_FILTERS ).empty() ? BOOST_TEST_L( "test tree is empty" ) : BOOST_TEST_L( "no test cases matching filter or all test cases were disabled" ) ); @@ -1192,27 +1207,24 @@ run( test_unit_id id, bool continue_test ) if( call_start_finish ) { BOOST_TEST_FOREACH( test_observer*, to, impl::s_frk_state().m_observers ) { - BOOST_TEST_IMPL_TRY { + BOOST_TEST_I_TRY { impl::s_frk_state().m_aux_em.vexecute( boost::bind( &test_observer::test_start, to, tcc.p_count ) ); } - BOOST_TEST_IMPL_CATCH( execution_exception, ex ) { + BOOST_TEST_I_CATCH( execution_exception, ex ) { BOOST_TEST_SETUP_ASSERT( false, ex.what() ); } } } - switch( runtime_config::random_seed() ) { + unsigned seed = runtime_config::get<unsigned>( runtime_config::RANDOM_SEED ); + switch( seed ) { case 0: break; - case 1: { - unsigned seed = static_cast<unsigned>( std::time( 0 ) ); + case 1: + seed = static_cast<unsigned>( std::time( 0 ) ); + default: BOOST_TEST_MESSAGE( "Test cases order is shuffled using seed: " << seed ); std::srand( seed ); - break; - } - default: - BOOST_TEST_MESSAGE( "Test cases order is shuffled using seed: " << runtime_config::random_seed() ); - std::srand( runtime_config::random_seed() ); } impl::s_frk_state().execute_test_tree( id ); diff --git a/boost/test/impl/plain_report_formatter.ipp b/boost/test/impl/plain_report_formatter.ipp index f9e7db772a..262083eeaa 100644 --- a/boost/test/impl/plain_report_formatter.ipp +++ b/boost/test/impl/plain_report_formatter.ipp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) @@ -19,14 +19,13 @@ #include <boost/test/output/plain_report_formatter.hpp> #include <boost/test/utils/custom_manip.hpp> #include <boost/test/results_collector.hpp> +#include <boost/test/unit_test_parameters.hpp> #include <boost/test/tree/test_unit.hpp> #include <boost/test/utils/basic_cstring/io.hpp> #include <boost/test/utils/setcolor.hpp> -#include <boost/test/unit_test_parameters.hpp> - // STL #include <iomanip> #include <boost/config/no_tr1/cmath.hpp> @@ -46,11 +45,11 @@ namespace output { namespace { -typedef custom_manip<struct quote_t> quote; +typedef utils::custom_manip<struct quote_t> quote; template<typename T> inline std::ostream& -operator<<( custom_printer<quote> const& p, T const& value ) +operator<<( utils::custom_printer<quote> const& p, T const& value ) { *p << '"' << value << '"'; @@ -84,6 +83,7 @@ void plain_report_formatter::results_report_start( std::ostream& ostr ) { m_indent = 0; + m_color_output = runtime_config::get<bool>( runtime_config::COLOR_OUTPUT ); ostr << '\n'; } @@ -160,13 +160,13 @@ plain_report_formatter::do_confirmation_report( test_unit const& tu, std::ostrea test_results const& tr = results_collector.results( tu.p_id ); if( tr.passed() ) { - BOOST_TEST_SCOPE_SETCOLOR( ostr, term_attr::BRIGHT, term_color::GREEN ); + BOOST_TEST_SCOPE_SETCOLOR( m_color_output, ostr, term_attr::BRIGHT, term_color::GREEN ); ostr << "*** No errors detected\n"; return; } - BOOST_TEST_SCOPE_SETCOLOR( ostr, term_attr::BRIGHT, term_color::RED ); + BOOST_TEST_SCOPE_SETCOLOR( m_color_output, ostr, term_attr::BRIGHT, term_color::RED ); if( tr.p_skipped ) { ostr << "*** The test " << tu.p_type_name << ' ' << quote() << tu.full_name() << " was skipped" diff --git a/boost/test/impl/progress_monitor.ipp b/boost/test/impl/progress_monitor.ipp index ebdd7e9320..7fb3baf8f0 100644 --- a/boost/test/impl/progress_monitor.ipp +++ b/boost/test/impl/progress_monitor.ipp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) @@ -17,8 +17,8 @@ // Boost.Test #include <boost/test/progress_monitor.hpp> - #include <boost/test/unit_test_parameters.hpp> + #include <boost/test/utils/setcolor.hpp> #include <boost/test/tree/test_unit.hpp> @@ -102,15 +102,21 @@ namespace { struct progress_monitor_impl { // Constructor progress_monitor_impl() - : m_stream( runtime_config::log_sink() ) - {} + : m_stream( &std::cout ) + , m_color_output( false ) + { + } - std::ostream* m_stream; - scoped_ptr<progress_display> m_progress_display; + std::ostream* m_stream; + scoped_ptr<progress_display> m_progress_display; + bool m_color_output; }; progress_monitor_impl& s_pm_impl() { static progress_monitor_impl the_inst; return the_inst; } +#define PM_SCOPED_COLOR() \ + BOOST_TEST_SCOPE_SETCOLOR( s_pm_impl().m_color_output, *s_pm_impl().m_stream, term_attr::BRIGHT, term_color::MAGENTA ) + } // local namespace //____________________________________________________________________________// @@ -118,7 +124,9 @@ progress_monitor_impl& s_pm_impl() { static progress_monitor_impl the_inst; retu void progress_monitor_t::test_start( counter_t test_cases_amount ) { - BOOST_TEST_SCOPE_SETCOLOR( *s_pm_impl().m_stream, term_attr::BRIGHT, term_color::MAGENTA ); + s_pm_impl().m_color_output = runtime_config::get<bool>( runtime_config::COLOR_OUTPUT ); + + PM_SCOPED_COLOR(); s_pm_impl().m_progress_display.reset( new progress_display( test_cases_amount, *s_pm_impl().m_stream ) ); } @@ -128,7 +136,7 @@ progress_monitor_t::test_start( counter_t test_cases_amount ) void progress_monitor_t::test_aborted() { - BOOST_TEST_SCOPE_SETCOLOR( *s_pm_impl().m_stream, term_attr::BRIGHT, term_color::MAGENTA ); + PM_SCOPED_COLOR(); (*s_pm_impl().m_progress_display) += s_pm_impl().m_progress_display->count(); } @@ -138,7 +146,7 @@ progress_monitor_t::test_aborted() void progress_monitor_t::test_unit_finish( test_unit const& tu, unsigned long ) { - BOOST_TEST_SCOPE_SETCOLOR( *s_pm_impl().m_stream, term_attr::BRIGHT, term_color::MAGENTA ); + PM_SCOPED_COLOR(); if( tu.p_type == TUT_CASE ) ++(*s_pm_impl().m_progress_display); @@ -149,7 +157,7 @@ progress_monitor_t::test_unit_finish( test_unit const& tu, unsigned long ) void progress_monitor_t::test_unit_skipped( test_unit const& tu, const_string /*reason*/ ) { - BOOST_TEST_SCOPE_SETCOLOR( *s_pm_impl().m_stream, term_attr::BRIGHT, term_color::MAGENTA ); + PM_SCOPED_COLOR(); test_case_counter tcc; traverse_test_tree( tu, tcc ); @@ -167,6 +175,8 @@ progress_monitor_t::set_stream( std::ostream& ostr ) //____________________________________________________________________________// +#undef PM_SCOPED_COLOR + } // namespace unit_test } // namespace boost diff --git a/boost/test/impl/results_collector.ipp b/boost/test/impl/results_collector.ipp index d04d64fd6d..17a31955ea 100644 --- a/boost/test/impl/results_collector.ipp +++ b/boost/test/impl/results_collector.ipp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) diff --git a/boost/test/impl/results_reporter.ipp b/boost/test/impl/results_reporter.ipp index 885295c928..87c1172e12 100644 --- a/boost/test/impl/results_reporter.ipp +++ b/boost/test/impl/results_reporter.ipp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) @@ -19,6 +19,7 @@ #include <boost/test/results_reporter.hpp> #include <boost/test/results_collector.hpp> #include <boost/test/framework.hpp> + #include <boost/test/output/plain_report_formatter.hpp> #include <boost/test/output/xml_report_formatter.hpp> @@ -26,8 +27,6 @@ #include <boost/test/tree/test_unit.hpp> #include <boost/test/tree/traverse.hpp> -#include <boost/test/unit_test_parameters.hpp> - // Boost #include <boost/scoped_ptr.hpp> #include <boost/io/ios_state.hpp> @@ -53,8 +52,8 @@ namespace { struct results_reporter_impl : test_tree_visitor { // Constructor results_reporter_impl() - : m_output( runtime_config::report_sink() ) - , m_stream_state_saver( new io_saver_type( *m_output ) ) + : m_stream( &std::cerr ) + , m_stream_state_saver( new io_saver_type( std::cerr ) ) , m_report_level( CONFIRMATION_REPORT ) , m_formatter( new output::plain_report_formatter ) {} @@ -62,28 +61,28 @@ struct results_reporter_impl : test_tree_visitor { // test tree visitor interface implementation void visit( test_case const& tc ) { - m_formatter->test_unit_report_start( tc, *m_output ); - m_formatter->test_unit_report_finish( tc, *m_output ); + m_formatter->test_unit_report_start( tc, *m_stream ); + m_formatter->test_unit_report_finish( tc, *m_stream ); } bool test_suite_start( test_suite const& ts ) { - m_formatter->test_unit_report_start( ts, *m_output ); + m_formatter->test_unit_report_start( ts, *m_stream ); if( m_report_level == DETAILED_REPORT && !results_collector.results( ts.p_id ).p_skipped ) return true; - m_formatter->test_unit_report_finish( ts, *m_output ); + m_formatter->test_unit_report_finish( ts, *m_stream ); return false; } void test_suite_finish( test_suite const& ts ) { - m_formatter->test_unit_report_finish( ts, *m_output ); + m_formatter->test_unit_report_finish( ts, *m_stream ); } typedef scoped_ptr<io_saver_type> saver_ptr; // Data members - std::ostream* m_output; + std::ostream* m_stream; saver_ptr m_stream_state_saver; report_level m_report_level; scoped_ptr<format> m_formatter; @@ -109,7 +108,7 @@ set_level( report_level l ) void set_stream( std::ostream& ostr ) { - s_rr_impl().m_output = &ostr; + s_rr_impl().m_stream = &ostr; s_rr_impl().m_stream_state_saver.reset( new io_saver_type( ostr ) ); } @@ -118,7 +117,7 @@ set_stream( std::ostream& ostr ) std::ostream& get_stream() { - return *s_rr_impl().m_output; + return *s_rr_impl().m_stream; } //____________________________________________________________________________// @@ -169,11 +168,11 @@ make_report( report_level l, test_unit_id id ) report_level bkup = s_rr_impl().m_report_level; s_rr_impl().m_report_level = l; - s_rr_impl().m_formatter->results_report_start( *s_rr_impl().m_output ); + s_rr_impl().m_formatter->results_report_start( *s_rr_impl().m_stream ); switch( l ) { case CONFIRMATION_REPORT: - s_rr_impl().m_formatter->do_confirmation_report( framework::get<test_unit>( id ), *s_rr_impl().m_output ); + s_rr_impl().m_formatter->do_confirmation_report( framework::get<test_unit>( id ), *s_rr_impl().m_stream ); break; case SHORT_REPORT: case DETAILED_REPORT: @@ -183,7 +182,7 @@ make_report( report_level l, test_unit_id id ) break; } - s_rr_impl().m_formatter->results_report_finish( *s_rr_impl().m_output ); + s_rr_impl().m_formatter->results_report_finish( *s_rr_impl().m_stream ); s_rr_impl().m_report_level = bkup; } diff --git a/boost/test/impl/test_main.ipp b/boost/test/impl/test_main.ipp index c95c91e88b..6adc5bb9c2 100644 --- a/boost/test/impl/test_main.ipp +++ b/boost/test/impl/test_main.ipp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (C) Copyright Gennadiy Rozental 2001. // (C) Copyright Beman Dawes 1995-2001. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at diff --git a/boost/test/impl/test_tools.ipp b/boost/test/impl/test_tools.ipp index 03fea91605..ed94da3a5b 100644 --- a/boost/test/impl/test_tools.ipp +++ b/boost/test/impl/test_tools.ipp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) @@ -294,9 +294,8 @@ report_assertion( assertion_result const& ar, { using namespace unit_test; - if( framework::current_test_case_id() == INV_TEST_UNIT_ID ) - BOOST_TEST_IMPL_THROW( - std::runtime_error( "can't use testing tools outside of test case implementation" ) ); + BOOST_TEST_I_ASSRT( framework::current_test_case_id() != INV_TEST_UNIT_ID, + std::runtime_error( "Can't use testing tools outside of test case implementation." ) ); if( !!ar ) tl = PASS; @@ -357,7 +356,7 @@ report_assertion( assertion_result const& ar, framework::test_unit_aborted( framework::current_test_case() ); - BOOST_TEST_IMPL_THROW( execution_aborted() ); + BOOST_TEST_I_THROW( execution_aborted() ); } return true; diff --git a/boost/test/impl/test_tree.ipp b/boost/test/impl/test_tree.ipp index 712cb9ee42..d45f7b32b5 100644 --- a/boost/test/impl/test_tree.ipp +++ b/boost/test/impl/test_tree.ipp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) @@ -39,10 +39,6 @@ #include <boost/test/detail/suppress_warnings.hpp> -#if BOOST_WORKAROUND(__BORLANDC__, < 0x600) && BOOST_WORKAROUND(_STLPORT_VERSION, <= 0x450) - using std::rand; // rand is in std and random_shuffle is in _STL -#endif - //____________________________________________________________________________// namespace boost { @@ -141,8 +137,13 @@ test_unit::check_preconditions() const BOOST_TEST_FOREACH( precondition_t, precondition, p_preconditions.get() ) { test_tools::assertion_result res = precondition( p_id ); - if( !res ) - return res; + if( !res ) { + test_tools::assertion_result res_out(false); + res_out.message() << "precondition failed"; + if( !res.has_empty_message() ) + res_out.message() << ": " << res.message(); + return res_out; + } } return true; diff --git a/boost/test/impl/unit_test_log.ipp b/boost/test/impl/unit_test_log.ipp index f202f5027d..4c9ac40691 100644 --- a/boost/test/impl/unit_test_log.ipp +++ b/boost/test/impl/unit_test_log.ipp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) @@ -20,7 +20,6 @@ #include <boost/test/unit_test_log_formatter.hpp> #include <boost/test/execution_monitor.hpp> #include <boost/test/framework.hpp> - #include <boost/test/unit_test_parameters.hpp> #include <boost/test/utils/basic_cstring/compare.hpp> @@ -85,8 +84,8 @@ namespace { struct unit_test_log_impl { // Constructor unit_test_log_impl() - : m_stream( runtime_config::log_sink() ) - , m_stream_state_saver( new io_saver_type( *m_stream ) ) + : m_stream( &std::cout ) + , m_stream_state_saver( new io_saver_type( std::cout ) ) , m_threshold_level( log_all_errors ) , m_log_formatter( new output::compiler_log_formatter ) { @@ -110,11 +109,14 @@ struct unit_test_log_impl { log_checkpoint_data m_checkpoint_data; // helper functions - std::ostream& stream() { return *m_stream; } + std::ostream& stream() + { + return *m_stream; + } void set_checkpoint( const_string file, std::size_t line_num, const_string msg ) { assign_op( m_checkpoint_data.m_message, msg, 0 ); - m_checkpoint_data.m_file_name = file; + m_checkpoint_data.m_file_name = file; m_checkpoint_data.m_line_num = line_num; } }; @@ -133,7 +135,7 @@ unit_test_log_t::test_start( counter_t test_cases_amount ) s_log_impl().m_log_formatter->log_start( s_log_impl().stream(), test_cases_amount ); - if( runtime_config::show_build_info() ) + if( runtime_config::get<bool>( runtime_config::BUILD_INFO ) ) s_log_impl().m_log_formatter->log_build_info( s_log_impl().stream() ); s_log_impl().m_entry_in_progress = false; diff --git a/boost/test/impl/unit_test_main.ipp b/boost/test/impl/unit_test_main.ipp index 327e14de30..1f30c0213e 100644 --- a/boost/test/impl/unit_test_main.ipp +++ b/boost/test/impl/unit_test_main.ipp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) @@ -102,7 +102,7 @@ private: m_os << ",fontname=Helvetica"; - m_os << (tu.is_enabled() ? ",color=green" : ",color=yellow"); + m_os << (tu.p_default_status == test_unit::RS_ENABLED ? ",color=green" : ",color=yellow"); if( master_ts ) m_os << ",label=\"" << tu.p_name << "\"];\n"; @@ -185,10 +185,10 @@ unit_test_main( init_unit_test_func init_func, int argc, char* argv[] ) { int result_code = 0; - BOOST_TEST_IMPL_TRY { + BOOST_TEST_I_TRY { framework::init( init_func, argc, argv ); - if( runtime_config::wait_for_debugger() ) { + if( runtime_config::get<bool>( runtime_config::WAIT_FOR_DEBUGGER ) ) { results_reporter::get_stream() << "Press any key to continue..." << std::endl; std::getchar(); @@ -197,8 +197,9 @@ unit_test_main( init_unit_test_func init_func, int argc, char* argv[] ) framework::finalize_setup_phase(); - if( runtime_config::list_content() != unit_test::OF_INVALID ) { - if( runtime_config::list_content() == unit_test::OF_DOT ) { + output_format list_cont = runtime_config::get<output_format>( runtime_config::LIST_CONTENT ); + if( list_cont != unit_test::OF_INVALID ) { + if( list_cont == unit_test::OF_DOT ) { ut_detail::dot_content_reporter reporter( results_reporter::get_stream() ); traverse_test_tree( framework::master_test_suite().p_id, reporter, true ); @@ -212,7 +213,7 @@ unit_test_main( init_unit_test_func init_func, int argc, char* argv[] ) return boost::exit_success; } - if( runtime_config::list_labels() ) { + if( runtime_config::get<bool>( runtime_config::LIST_LABELS ) ) { ut_detail::labels_collector collector; traverse_test_tree( framework::master_test_suite().p_id, collector, true ); @@ -229,24 +230,24 @@ unit_test_main( init_unit_test_func init_func, int argc, char* argv[] ) results_reporter::make_report(); - result_code = runtime_config::no_result_code() + result_code = !runtime_config::get<bool>( runtime_config::RESULT_CODE ) ? boost::exit_success : results_collector.results( framework::master_test_suite().p_id ).result_code(); } - BOOST_TEST_IMPL_CATCH0( framework::nothing_to_test ) { - result_code = boost::exit_success; + BOOST_TEST_I_CATCH( framework::nothing_to_test, ex ) { + result_code = ex.m_result_code; } - BOOST_TEST_IMPL_CATCH( framework::internal_error, ex ) { + BOOST_TEST_I_CATCH( framework::internal_error, ex ) { results_reporter::get_stream() << "Boost.Test framework internal error: " << ex.what() << std::endl; result_code = boost::exit_exception_failure; } - BOOST_TEST_IMPL_CATCH( framework::setup_error, ex ) { + BOOST_TEST_I_CATCH( framework::setup_error, ex ) { results_reporter::get_stream() << "Test setup error: " << ex.what() << std::endl; result_code = boost::exit_exception_failure; } - BOOST_TEST_IMPL_CATCHALL() { + BOOST_TEST_I_CATCHALL() { results_reporter::get_stream() << "Boost.Test framework internal error: unknown reason" << std::endl; result_code = boost::exit_exception_failure; diff --git a/boost/test/impl/unit_test_monitor.ipp b/boost/test/impl/unit_test_monitor.ipp index 8c931f203f..304c8f1c04 100644 --- a/boost/test/impl/unit_test_monitor.ipp +++ b/boost/test/impl/unit_test_monitor.ipp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) @@ -36,16 +36,16 @@ namespace unit_test { unit_test_monitor_t::error_level unit_test_monitor_t::execute_and_translate( boost::function<void ()> const& func, unsigned timeout ) { - BOOST_TEST_IMPL_TRY { - p_catch_system_errors.value = runtime_config::catch_sys_errors(); + BOOST_TEST_I_TRY { + p_catch_system_errors.value = runtime_config::get<bool>( runtime_config::CATCH_SYS_ERRORS ); p_timeout.value = timeout; - p_auto_start_dbg.value = runtime_config::auto_start_dbg(); - p_use_alt_stack.value = runtime_config::use_alt_stack(); - p_detect_fp_exceptions.value = runtime_config::detect_fp_exceptions(); + p_auto_start_dbg.value = runtime_config::get<bool>( runtime_config::AUTO_START_DBG ); + p_use_alt_stack.value = runtime_config::get<bool>( runtime_config::USE_ALT_STACK ); + p_detect_fp_exceptions.value = runtime_config::get<bool>( runtime_config::DETECT_FP_EXCEPT ); vexecute( func ); } - BOOST_TEST_IMPL_CATCH( execution_exception, ex ) { + BOOST_TEST_I_CATCH( execution_exception, ex ) { framework::exception_caught( ex ); framework::test_unit_aborted( framework::current_test_case() ); diff --git a/boost/test/impl/unit_test_parameters.ipp b/boost/test/impl/unit_test_parameters.ipp index 2ffa495e67..3ca183e400 100644 --- a/boost/test/impl/unit_test_parameters.ipp +++ b/boost/test/impl/unit_test_parameters.ipp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) @@ -20,36 +20,32 @@ // Boost.Test #include <boost/test/unit_test_parameters.hpp> + #include <boost/test/utils/basic_cstring/basic_cstring.hpp> #include <boost/test/utils/basic_cstring/compare.hpp> #include <boost/test/utils/basic_cstring/io.hpp> -#include <boost/test/utils/fixed_mapping.hpp> + #include <boost/test/debug.hpp> #include <boost/test/framework.hpp> +#include <boost/test/detail/log_level.hpp> #include <boost/test/detail/throw_exception.hpp> // Boost.Runtime.Param -#include <boost/test/utils/runtime/cla/dual_name_parameter.hpp> +#include <boost/test/utils/runtime/parameter.hpp> +#include <boost/test/utils/runtime/argument.hpp> +#include <boost/test/utils/runtime/finalize.hpp> #include <boost/test/utils/runtime/cla/parser.hpp> - -namespace rt = boost::runtime; -namespace cla = rt::cla; - -#ifndef UNDER_CE -#include <boost/test/utils/runtime/env/variable.hpp> - -namespace env = rt::env; -#endif +#include <boost/test/utils/runtime/env/fetch.hpp> // Boost #include <boost/config.hpp> #include <boost/test/detail/suppress_warnings.hpp> -#include <boost/lexical_cast.hpp> #include <boost/test/detail/enable_warnings.hpp> +#include <boost/optional.hpp> +#include <boost/cstdlib.hpp> // STL -#include <map> #include <cstdlib> #include <iostream> #include <fstream> @@ -65,85 +61,7 @@ namespace std { using ::getenv; using ::strncmp; using ::strcmp; } namespace boost { namespace unit_test { -// ************************************************************************** // -// ************** input operations for unit_test's enums ************** // -// ************************************************************************** // - -std::istream& -operator>>( std::istream& in, unit_test::log_level& ll ) -{ - static fixed_mapping<const_string,unit_test::log_level,case_ins_less<char const> > log_level_name( - "all" , log_successful_tests, - "success" , log_successful_tests, - "test_suite" , log_test_units, - "unit_scope" , log_test_units, - "message" , log_messages, - "warning" , log_warnings, - "error" , log_all_errors, - "cpp_exception" , log_cpp_exception_errors, - "system_error" , log_system_errors, - "fatal_error" , log_fatal_errors, - "nothing" , log_nothing, - - invalid_log_level - ); - - std::string val; - in >> val; - - ll = log_level_name[val]; - BOOST_TEST_SETUP_ASSERT( ll != unit_test::invalid_log_level, "invalid log level " + val ); - - return in; -} - -//____________________________________________________________________________// - -std::istream& -operator>>( std::istream& in, unit_test::report_level& rl ) -{ - fixed_mapping<const_string,unit_test::report_level,case_ins_less<char const> > report_level_name ( - "confirm", CONFIRMATION_REPORT, - "short", SHORT_REPORT, - "detailed", DETAILED_REPORT, - "no", NO_REPORT, - - INV_REPORT_LEVEL - ); - - std::string val; - in >> val; - - rl = report_level_name[val]; - BOOST_TEST_SETUP_ASSERT( rl != INV_REPORT_LEVEL, "invalid report level " + val ); - - return in; -} - -//____________________________________________________________________________// - -std::istream& -operator>>( std::istream& in, unit_test::output_format& of ) -{ - fixed_mapping<const_string,unit_test::output_format,case_ins_less<char const> > output_format_name ( - "HRF", unit_test::OF_CLF, - "CLF", unit_test::OF_CLF, - "XML", unit_test::OF_XML, - "DOT", unit_test::OF_DOT, - - unit_test::OF_INVALID - ); - - std::string val; - in >> val; - - of = output_format_name[val]; - BOOST_TEST_SETUP_ASSERT( of != unit_test::OF_INVALID, "invalid output format " + val ); - - return in; -} - -//____________________________________________________________________________// +namespace rt = boost::runtime; // ************************************************************************** // // ************** runtime_config ************** // @@ -151,9 +69,7 @@ operator>>( std::istream& in, unit_test::output_format& of ) namespace runtime_config { -namespace { - -// framework parameters and corresponding command-line arguments +// UTF parameters std::string AUTO_START_DBG = "auto_start_dbg"; std::string BREAK_EXEC_PATH = "break_exec_path"; std::string BUILD_INFO = "build_info"; @@ -170,463 +86,636 @@ std::string OUTPUT_FORMAT = "output_format"; std::string RANDOM_SEED = "random"; std::string REPORT_FORMAT = "report_format"; std::string REPORT_LEVEL = "report_level"; +std::string REPORT_MEM_LEAKS = "report_memory_leaks_to"; std::string REPORT_SINK = "report_sink"; std::string RESULT_CODE = "result_code"; -std::string TESTS_TO_RUN = "run_test"; +std::string RUN_FILTERS = "run_test"; std::string SAVE_TEST_PATTERN = "save_pattern"; std::string SHOW_PROGRESS = "show_progress"; std::string USE_ALT_STACK = "use_alt_stack"; std::string WAIT_FOR_DEBUGGER = "wait_for_debugger"; -static const_string -parameter_2_env_var( const_string param_name ) -{ - typedef std::map<const_string,const_string> mtype; - static mtype s_mapping; - - if( s_mapping.empty() ) { - s_mapping[AUTO_START_DBG] = "BOOST_TEST_AUTO_START_DBG"; - s_mapping[BREAK_EXEC_PATH] = "BOOST_TEST_BREAK_EXEC_PATH"; - s_mapping[BUILD_INFO] = "BOOST_TEST_BUILD_INFO"; - s_mapping[CATCH_SYS_ERRORS] = "BOOST_TEST_CATCH_SYSTEM_ERRORS"; - s_mapping[COLOR_OUTPUT] = "BOOST_TEST_COLOR_OUTPUT"; - s_mapping[DETECT_FP_EXCEPT] = "BOOST_TEST_DETECT_FP_EXCEPTIONS"; - s_mapping[DETECT_MEM_LEAKS] = "BOOST_TEST_DETECT_MEMORY_LEAK"; - s_mapping[LIST_CONTENT] = "BOOST_TEST_LIST_CONTENT"; - s_mapping[LIST_CONTENT] = "BOOST_TEST_LIST_LABELS"; - s_mapping[LOG_FORMAT] = "BOOST_TEST_LOG_FORMAT"; - s_mapping[LOG_LEVEL] = "BOOST_TEST_LOG_LEVEL"; - s_mapping[LOG_SINK] = "BOOST_TEST_LOG_SINK"; - s_mapping[OUTPUT_FORMAT] = "BOOST_TEST_OUTPUT_FORMAT"; - s_mapping[RANDOM_SEED] = "BOOST_TEST_RANDOM"; - s_mapping[REPORT_FORMAT] = "BOOST_TEST_REPORT_FORMAT"; - s_mapping[REPORT_LEVEL] = "BOOST_TEST_REPORT_LEVEL"; - s_mapping[REPORT_SINK] = "BOOST_TEST_REPORT_SINK"; - s_mapping[RESULT_CODE] = "BOOST_TEST_RESULT_CODE"; - s_mapping[TESTS_TO_RUN] = "BOOST_TESTS_TO_RUN"; - s_mapping[SAVE_TEST_PATTERN] = "BOOST_TEST_SAVE_PATTERN"; - s_mapping[SHOW_PROGRESS] = "BOOST_TEST_SHOW_PROGRESS"; - s_mapping[USE_ALT_STACK] = "BOOST_TEST_USE_ALT_STACK"; - s_mapping[WAIT_FOR_DEBUGGER] = "BOOST_TEST_WAIT_FOR_DEBUGGER"; - } - - mtype::const_iterator it = s_mapping.find( param_name ); - - return it == s_mapping.end() ? const_string() : it->second; -} - -//____________________________________________________________________________// - -// storage for the CLAs -cla::parser s_cla_parser; -std::string s_empty; - -output_format s_report_format; -output_format s_log_format; - -std::list<std::string> s_test_to_run; +std::string HELP = "help"; +std::string USAGE = "usage"; //____________________________________________________________________________// -template<typename T> -T -retrieve_parameter( const_string parameter_name, cla::parser const& s_cla_parser, T const& default_value = T(), T const& optional_value = T() ) -{ - rt::const_argument_ptr arg = s_cla_parser[parameter_name]; - if( arg ) { - if( rtti::type_id<T>() == rtti::type_id<bool>() || - !static_cast<cla::parameter const&>( arg->p_formal_parameter.get() ).p_optional_value ) - return s_cla_parser.get<T>( parameter_name ); - - optional<T> val = s_cla_parser.get<optional<T> >( parameter_name ); - if( val ) - return *val; - else - return optional_value; - } - - boost::optional<T> v; - -#ifndef UNDER_CE - env::get( parameter_2_env_var(parameter_name), v ); -#endif - - if( v ) - return *v; - else - return default_value; -} - -//____________________________________________________________________________// - -void -disable_use( cla::parameter const&, std::string const& ) -{ - BOOST_TEST_SETUP_ASSERT( false, "parameter break_exec_path is disabled in this release" ); -} - -//____________________________________________________________________________// - -} // local namespace +namespace { void -init( int& argc, char** argv ) +register_parameters( rt::parameters_store& store ) { - using namespace cla; - - BOOST_TEST_IMPL_TRY { - if( s_cla_parser.num_params() != 0 ) - s_cla_parser.reset(); - else - s_cla_parser - cla::ignore_mismatch - << cla::dual_name_parameter<bool>( AUTO_START_DBG + "|d" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Automatically starts debugger if system level error (signal) occurs") - << cla::named_parameter<std::string>( BREAK_EXEC_PATH ) - - (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional, - cla::description = "For the exception safety testing allows to break at specific execution path", - cla::handler = &disable_use) - << cla::dual_name_parameter<bool>( BUILD_INFO + "|i" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Shows library build information" ) - << cla::dual_name_parameter<bool>( CATCH_SYS_ERRORS + "|s" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Allows to switch between catching and ignoring system errors (signals)") - << cla::dual_name_parameter<bool>( COLOR_OUTPUT + "|x" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Allows to switch between catching and ignoring system errors (signals)") - << cla::named_parameter<bool>( DETECT_FP_EXCEPT ) - - (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional, - cla::description = "Allows to switch between catching and ignoring floating point exceptions") - << cla::named_parameter<std::string>( DETECT_MEM_LEAKS ) - - (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional,cla::optional_value, - cla::description = "Allows to switch between catching and ignoring memory leaks") - << cla::dual_name_parameter<unit_test::output_format>( LOG_FORMAT + "|f" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Specifies log format") - << cla::dual_name_parameter<unit_test::log_level>( LOG_LEVEL + "|l" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Specifies log level") - << cla::dual_name_parameter<std::string>( LOG_SINK + "|k" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Specifies log sink:stdout(default),stderr or file name") - << cla::dual_name_parameter<unit_test::output_format>( OUTPUT_FORMAT + "|o" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Specifies output format (both log and report)") - << cla::dual_name_parameter<unsigned>( RANDOM_SEED + "|a" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,cla::optional_value, - cla::description = "Allows to switch between sequential and random order of test units execution.\n" - "Optionally allows to specify concrete seed for random number generator") - << cla::dual_name_parameter<unit_test::output_format>( REPORT_FORMAT + "|m" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Specifies report format") - << cla::dual_name_parameter<unit_test::report_level>(REPORT_LEVEL + "|r") - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Specifies report level") - << cla::dual_name_parameter<std::string>( REPORT_SINK + "|e" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Specifies report sink:stderr(default),stdout or file name") - << cla::dual_name_parameter<bool>( RESULT_CODE + "|c" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Allows to disable test modules's result code generation") - << cla::dual_name_parameter<std::string>( TESTS_TO_RUN + "|t" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,cla::multiplicable, - cla::description = "Allows to filter which test units to run") - << cla::named_parameter<bool>( SAVE_TEST_PATTERN ) - - (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional, - cla::description = "Allows to switch between saving and matching against test pattern file") - << cla::dual_name_parameter<bool>( SHOW_PROGRESS + "|p" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Turns on progress display") - << cla::dual_name_parameter<unit_test::output_format>( LIST_CONTENT + "|j" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,cla::optional_value, - cla::description = "Lists the content of test tree - names of all test suites and test cases") - << cla::named_parameter<bool>( LIST_LABELS ) - - (cla::prefix = "--",cla::separator = "= ",cla::guess_name,cla::optional, - cla::description = "Lists all available labels") - << cla::named_parameter<bool>( USE_ALT_STACK ) - - (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional, - cla::description = "Turns on/off usage of an alternative stack for signal handling") - << cla::dual_name_parameter<bool>( WAIT_FOR_DEBUGGER + "|w" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,cla::optional_value, - cla::description = "Forces test module to wait for button to be pressed before starting test run") - - << cla::dual_name_parameter<bool>( "help|?" ) - - (cla::prefix = "--|-",cla::separator = "=",cla::guess_name,cla::optional, - cla::description = "this help message") - ; - - s_cla_parser.parse( argc, argv ); - - if( s_cla_parser["help"] ) { - s_cla_parser.help( std::cout ); - BOOST_TEST_IMPL_THROW( framework::nothing_to_test() ); + rt::option auto_start_dbg( AUTO_START_DBG, ( + rt::description = "Automatically attaches debugger in case of system level failure (signal).", + rt::env_var = "BOOST_TEST_AUTO_START_DBG", + + rt::help = "Option " + AUTO_START_DBG + " specifies whether Boost.Test should attempt " + "to attach a debugger when fatal system error occurs. At the moment this feature " + "is only available on a few selected platforms: Win32 and *nix. There is a " + "default debugger configured for these platforms. You can manually configure " + "different debugger. For more details on how to configure the debugger see the " + "Boost.Test debug API, specifically the function boost::debug::set_debugger." + )); + + auto_start_dbg.add_cla_id( "--", AUTO_START_DBG, "=" ); + auto_start_dbg.add_cla_id( "-", "d", " " ); + store.add( auto_start_dbg ); + + /////////////////////////////////////////////// + + rt::parameter<std::string> break_exec_path( BREAK_EXEC_PATH, ( + rt::description = "For the exception safety testing allows to break at specific execution path.", + rt::env_var = "BOOST_TEST_BREAK_EXEC_PATH" +#ifndef BOOST_NO_CXX11_LAMBDAS + , + rt::callback = [](rt::cstring) { + BOOST_TEST_SETUP_ASSERT( false, "parameter break_exec_path is disabled in this release" ); } +#endif + )); - s_report_format = retrieve_parameter( REPORT_FORMAT, s_cla_parser, unit_test::OF_CLF ); - s_log_format = retrieve_parameter( LOG_FORMAT, s_cla_parser, unit_test::OF_CLF ); - - unit_test::output_format of = retrieve_parameter( OUTPUT_FORMAT, s_cla_parser, unit_test::OF_INVALID ); - - if( of != unit_test::OF_INVALID ) - s_report_format = s_log_format = of; - - s_test_to_run = retrieve_parameter<std::list<std::string> >( TESTS_TO_RUN, s_cla_parser ); - } - BOOST_TEST_IMPL_CATCH( rt::logic_error, ex ) { - std::ostringstream err; - - err << "Fail to process runtime parameters: " << ex.msg() << std::endl; - s_cla_parser.usage( err ); - - BOOST_TEST_SETUP_ASSERT( false, err.str() ); - } -} - -//____________________________________________________________________________// - -unit_test::log_level -log_level() -{ - return retrieve_parameter( LOG_LEVEL, s_cla_parser, unit_test::log_all_errors ); -} - -//____________________________________________________________________________// - -bool -no_result_code() -{ - return !retrieve_parameter( RESULT_CODE, s_cla_parser, true ); -} - -//____________________________________________________________________________// - -unit_test::report_level -report_level() -{ - return retrieve_parameter( REPORT_LEVEL, s_cla_parser, unit_test::CONFIRMATION_REPORT ); -} - -//____________________________________________________________________________// - -std::list<std::string> const& -test_to_run() -{ - return s_test_to_run; -} - -//____________________________________________________________________________// - -const_string -break_exec_path() -{ - static std::string s_break_exec_path = retrieve_parameter( BREAK_EXEC_PATH, s_cla_parser, s_empty ); - - return s_break_exec_path; -} - -//____________________________________________________________________________// - -bool -save_pattern() -{ - return retrieve_parameter( SAVE_TEST_PATTERN, s_cla_parser, false ); -} - -//____________________________________________________________________________// - -bool -show_progress() -{ - return retrieve_parameter( SHOW_PROGRESS, s_cla_parser, false ); -} - -//____________________________________________________________________________// - -bool -show_build_info() -{ - return retrieve_parameter( BUILD_INFO, s_cla_parser, false ); -} - -//____________________________________________________________________________// + break_exec_path.add_cla_id( "--", BREAK_EXEC_PATH, "=" ); + store.add( break_exec_path ); -output_format -list_content() -{ - return retrieve_parameter( LIST_CONTENT, s_cla_parser, unit_test::OF_INVALID, unit_test::OF_CLF ); -} + rt::option build_info( BUILD_INFO, ( + rt::description = "Displays library build information.", + rt::env_var = "BOOST_TEST_BUILD_INFO", + rt::help = "Option " + BUILD_INFO + " displays library build information, including: platform, " + "compiler, STL version and Boost version." + )); -//____________________________________________________________________________// + /////////////////////////////////////////////// -bool -list_labels() -{ - return retrieve_parameter( LIST_LABELS, s_cla_parser, false ); -} + build_info.add_cla_id( "--", BUILD_INFO, "=" ); + build_info.add_cla_id( "-", "i", " " ); + store.add( build_info ); -//____________________________________________________________________________// -bool -catch_sys_errors() -{ - return retrieve_parameter( CATCH_SYS_ERRORS, s_cla_parser, + rt::option catch_sys_errors( CATCH_SYS_ERRORS, ( + rt::description = "Allows to switch between catching and ignoring system errors (signals).", + rt::env_var = "BOOST_TEST_CATCH_SYSTEM_ERRORS", + rt::default_value = #ifdef BOOST_TEST_DEFAULTS_TO_CORE_DUMP - false + false, #else - true + true, #endif - ); -} - -//____________________________________________________________________________// - -bool -color_output() -{ - return retrieve_parameter( COLOR_OUTPUT, s_cla_parser, false ); -} - -//____________________________________________________________________________// - -bool -auto_start_dbg() -{ - // !! ?? set debugger as an option - return retrieve_parameter( AUTO_START_DBG, s_cla_parser, false ); -; -} - -//____________________________________________________________________________// - -bool -wait_for_debugger() -{ - return retrieve_parameter( WAIT_FOR_DEBUGGER, s_cla_parser, false ); -} - -//____________________________________________________________________________// - -bool -use_alt_stack() -{ - return retrieve_parameter( USE_ALT_STACK, s_cla_parser, true ); -} - -//____________________________________________________________________________// - -bool -detect_fp_exceptions() -{ - return retrieve_parameter( DETECT_FP_EXCEPT, s_cla_parser, false ); + rt::help = "If option " + CATCH_SYS_ERRORS + " has value no the frameworks does not attempt to catch " + "asynchronous system failure events (signals on *NIX platforms or structured exceptions on Windows). " + " Default value is " +#ifdef BOOST_TEST_DEFAULTS_TO_CORE_DUMP + "no." +#else + "true." +#endif + )); + + catch_sys_errors.add_cla_id( "--", CATCH_SYS_ERRORS, "=", true ); + catch_sys_errors.add_cla_id( "-", "s", " " ); + store.add( catch_sys_errors ); + + /////////////////////////////////////////////// + + rt::option color_output( COLOR_OUTPUT, ( + rt::description = "Enables color output of the framework log and report messages.", + rt::env_var = "BOOST_TEST_COLOR_OUTPUT", + rt::help = "The framework is able to produce color output on systems which supports it. " + "To enable this behavior set this option to yes. By default the framework " + "does not produces color output." + )); + + color_output.add_cla_id( "--", COLOR_OUTPUT, "=", true ); + color_output.add_cla_id( "-", "x", " " ); + store.add( color_output ); + + /////////////////////////////////////////////// + + rt::option detect_fp_except( DETECT_FP_EXCEPT, ( + rt::description = "Enables/disables floating point exceptions traps.", + rt::env_var = "BOOST_TEST_DETECT_FP_EXCEPTIONS", + rt::help = "Option " + DETECT_FP_EXCEPT + " enables/disables hardware traps for the floating " + "point exceptions (if supported on your platfrom)." + )); + + detect_fp_except.add_cla_id( "--", DETECT_FP_EXCEPT, "=", true ); + store.add( detect_fp_except ); + + /////////////////////////////////////////////// + + rt::parameter<unsigned long> detect_mem_leaks( DETECT_MEM_LEAKS, ( + rt::description = "Turns on/off memory leaks detection (optionally breaking on specified alloc order number).", + rt::env_var = "BOOST_TEST_DETECT_MEMORY_LEAK", + rt::default_value = 1L, + rt::optional_value = 1L, + rt::value_hint = "<alloc order number>", + rt::help = "Parameter " + DETECT_MEM_LEAKS + " enables/disables memory leaks detection. " + "This parameter has optional long integer value. The default value is 1, which " + "enables the memory leak detection. The value 0 disables memory leak detection. " + "Any value N greater than 1 is treated as leak allocation number and tells the " + "framework to setup runtime breakpoint at Nth heap allocation. If value is " + "omitted the default value is assumed." + )); + + detect_mem_leaks.add_cla_id( "--", DETECT_MEM_LEAKS, "=" ); + store.add( detect_mem_leaks ); + + /////////////////////////////////////////////// + + rt::enum_parameter<unit_test::output_format> list_content( LIST_CONTENT, ( + rt::description = "Lists the content of test tree - names of all test suites and test cases.", + rt::env_var = "BOOST_TEST_LIST_CONTENT", + rt::default_value = OF_INVALID, + rt::optional_value = OF_CLF, + rt::enum_values<unit_test::output_format>::value = +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) + { + { "HRF", OF_CLF }, + { "DOT", OF_DOT } + }, +#else + rt::enum_values_list<unit_test::output_format>() + ( "HRF", OF_CLF ) + ( "DOT", OF_DOT ) + , +#endif + rt::help = "Parameter " + LIST_CONTENT + " instructs the framework to list the content " + "of the test module instead of executing the test cases. Parameter accepts " + "optional string value indicating the format of the output. Currently the " + "framework supports two formats: human readable format (HRF) and dot graph " + "format (DOT). If value is omitted HRF value is assumed." + )); + list_content.add_cla_id( "--", LIST_CONTENT, "=" ); + store.add( list_content ); + + /////////////////////////////////////////////// + + rt::option list_labels( LIST_LABELS, ( + rt::description = "Lists all available labels.", + rt::env_var = "BOOST_TEST_LIST_LABELS", + rt::help = "Option " + LIST_LABELS + " instructs the framework to list all the the labels " + "defined in the test module instead of executing the test cases." + )); + + list_labels.add_cla_id( "--", LIST_LABELS, "=" ); + store.add( list_labels ); + + /////////////////////////////////////////////// + + rt::enum_parameter<unit_test::output_format> log_format( LOG_FORMAT, ( + rt::description = "Specifies log format.", + rt::env_var = "BOOST_TEST_LOG_FORMAT", + rt::default_value = OF_CLF, + rt::enum_values<unit_test::output_format>::value = +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) + { + { "HRF", OF_CLF }, + { "CLF", OF_CLF }, + { "XML", OF_XML } + }, +#else + rt::enum_values_list<unit_test::output_format>() + ( "HRF", OF_CLF ) + ( "CLF", OF_CLF ) + ( "XML", OF_XML ) + , +#endif + rt::help = "Parameter " + LOG_FORMAT + " allows to set the frameowrk's log format to one " + "of the formats supplied by the framework. The only acceptable values for this " + "parameter are the names of the output formats supplied by the framework. By " + "default the framework uses human readable format (HRF) for testing log. This " + "format is similar to compiler error format. Alternatively you can specify XML " + "as log format. This format is easier to process by testing automation tools." + )); + + log_format.add_cla_id( "--", LOG_FORMAT, "=" ); + log_format.add_cla_id( "-", "f", " " ); + store.add( log_format ); + + /////////////////////////////////////////////// + + rt::enum_parameter<unit_test::log_level> log_level( LOG_LEVEL, ( + rt::description = "Specifies log level.", + rt::env_var = "BOOST_TEST_LOG_LEVEL", + rt::default_value = log_all_errors, + rt::enum_values<unit_test::log_level>::value = +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) + { + { "all" , log_successful_tests }, + { "success" , log_successful_tests }, + { "test_suite" , log_test_units }, + { "unit_scope" , log_test_units }, + { "message" , log_messages }, + { "warning" , log_warnings }, + { "error" , log_all_errors }, + { "cpp_exception" , log_cpp_exception_errors }, + { "system_error" , log_system_errors }, + { "fatal_error" , log_fatal_errors }, + { "nothing" , log_nothing } + }, +#else + rt::enum_values_list<unit_test::log_level>() + ( "all" , log_successful_tests ) + ( "success" , log_successful_tests ) + ( "test_suite" , log_test_units ) + ( "unit_scope" , log_test_units ) + ( "message" , log_messages ) + ( "warning" , log_warnings ) + ( "error" , log_all_errors ) + ( "cpp_exception" , log_cpp_exception_errors ) + ( "system_error" , log_system_errors ) + ( "fatal_error" , log_fatal_errors ) + ( "nothing" , log_nothing ) + , +#endif + rt::help = "Parameter " + LOG_LEVEL + " allows to set the framework's log level. " + "Log level defines the verbosity of testing log produced by a testing " + "module. The verbosity ranges from a complete log, when all assertions " + "(both successful and failing) are reported, all notifications about " + "test units start and finish are included, to an empty log when nothing " + "is reported to a testing log stream." + )); + + log_level.add_cla_id( "--", LOG_LEVEL, "=" ); + log_level.add_cla_id( "-", "l", " " ); + store.add( log_level ); + + /////////////////////////////////////////////// + + rt::parameter<std::string> log_sink( LOG_SINK, ( + rt::description = "Specifies log sink: stdout(default), stderr or file name.", + rt::env_var = "BOOST_TEST_LOG_SINK", + rt::value_hint = "<stderr|stdout|file name>", + rt::help = "Parameter " + LOG_SINK + " allows to set the log sink - location " + "where we report the log to, thus it allows to easily redirect the " + "test logs to file or standard streams. By default testing log is " + "directed to standard output." + )); + + log_sink.add_cla_id( "--", LOG_SINK, "=" ); + log_sink.add_cla_id( "-", "k", " " ); + store.add( log_sink ); + + /////////////////////////////////////////////// + + rt::enum_parameter<unit_test::output_format> output_format( OUTPUT_FORMAT, ( + rt::description = "Specifies output format (both log and report).", + rt::env_var = "BOOST_TEST_OUTPUT_FORMAT", + rt::enum_values<unit_test::output_format>::value = +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) + { + { "HRF", OF_CLF }, + { "CLF", OF_CLF }, + { "XML", OF_XML } + }, +#else + rt::enum_values_list<unit_test::output_format>() + ( "HRF", OF_CLF ) + ( "CLF", OF_CLF ) + ( "XML", OF_XML ) + , +#endif + rt::help = "Parameter " + OUTPUT_FORMAT + " combines an effect of " + REPORT_FORMAT + + " and " + LOG_FORMAT + " parameters. This parameter has higher priority " + "than either one of them. In other words if this parameter is specified " + "it overrides the value of other two parameters. This parameter does not " + "have a default value. The only acceptable values are string names of " + "output formats: HRF - human readable format and XML - XML formats for " + "automation tools processing." + )); + + output_format.add_cla_id( "--", OUTPUT_FORMAT, "=" ); + output_format.add_cla_id( "-", "o", " " ); + store.add( output_format ); + + /////////////////////////////////////////////// + + rt::parameter<unsigned> random_seed( RANDOM_SEED, ( + rt::description = "Allows to switch between sequential and random order of test units execution." + " Optionally allows to specify concrete seed for random number generator.", + rt::env_var = "BOOST_TEST_RANDOM", + rt::default_value = 0U, + rt::optional_value = 1U, + rt::value_hint = "<seed>", + rt::help = "Parameter " + RANDOM_SEED + " instructs the framework to execute the " + "test cases in random order. This parameter accepts optional unsigned " + "integer argument. By default test cases are executed in some specific " + "order defined by order of test units in test files and dependency between " + "test units. If parameter is specified without the argument value testing " + "order is randomized based on current time. Alternatively you can specify " + "any positive value greater than 1 and it will be used as random seed for " + "the run." + )); + + random_seed.add_cla_id( "--", RANDOM_SEED, "=" ); + store.add( random_seed ); + + /////////////////////////////////////////////// + + rt::enum_parameter<unit_test::output_format> report_format( REPORT_FORMAT, ( + rt::description = "Specifies report format.", + rt::env_var = "BOOST_TEST_REPORT_FORMAT", + rt::default_value = OF_CLF, + rt::enum_values<unit_test::output_format>::value = +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) + { + { "HRF", OF_CLF }, + { "CLF", OF_CLF }, + { "XML", OF_XML } + }, +#else + rt::enum_values_list<unit_test::output_format>() + ( "HRF", OF_CLF ) + ( "CLF", OF_CLF ) + ( "XML", OF_XML ) + , +#endif + rt::help = "Parameter " + REPORT_FORMAT + " allows to set the framework's report format " + "to one of the formats supplied by the framework. The only acceptable values " + "for this parameter are the names of the output formats. By default the framework " + "uses human readable format (HRF) for results reporting. Alternatively you can " + "specify XML as report format. This format is easier to process by testing " + "automation tools." + )); + + report_format.add_cla_id( "--", REPORT_FORMAT, "=" ); + report_format.add_cla_id( "-", "m", " " ); + store.add( report_format ); + + /////////////////////////////////////////////// + + rt::enum_parameter<unit_test::report_level> report_level( REPORT_LEVEL, ( + rt::description = "Specifies report level.", + rt::env_var = "BOOST_TEST_REPORT_LEVEL", + rt::default_value = CONFIRMATION_REPORT, + rt::enum_values<unit_test::report_level>::value = +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) + { + { "confirm", CONFIRMATION_REPORT }, + { "short", SHORT_REPORT }, + { "detailed", DETAILED_REPORT }, + { "no", NO_REPORT } + }, +#else + rt::enum_values_list<unit_test::report_level>() + ( "confirm", CONFIRMATION_REPORT ) + ( "short", SHORT_REPORT ) + ( "detailed", DETAILED_REPORT ) + ( "no", NO_REPORT ) + , +#endif + rt::help = "Parameter " + REPORT_LEVEL + " allows to set the verbosity level of the " + "testing result report generated by the framework. Use value 'no' to " + "eliminate the results report completely." + )); + + report_level.add_cla_id( "--", REPORT_LEVEL, "=" ); + report_level.add_cla_id( "-", "r", " " ); + store.add( report_level ); + + /////////////////////////////////////////////// + + rt::parameter<std::string> report_mem_leaks( REPORT_MEM_LEAKS, ( + rt::description = "File where to report memory leaks to.", + rt::env_var = "BOOST_TEST_REPORT_MEMORY_LEAKS_TO", + rt::default_value = std::string(), + rt::value_hint = "<file name>", + rt::help = "Parameter " + REPORT_MEM_LEAKS + " allows to specify a file where to report " + "memory leaks to. The parameter does not have default value. If it is not specified, " + "memory leaks (if any) are reported to the standard error stream." + )); + + report_mem_leaks.add_cla_id( "--", REPORT_MEM_LEAKS, "=" ); + store.add( report_mem_leaks ); + + /////////////////////////////////////////////// + + rt::parameter<std::string> report_sink( REPORT_SINK, ( + rt::description = "Specifies report sink: stderr(default), stdout or file name.", + rt::env_var = "BOOST_TEST_REPORT_SINK", + rt::value_hint = "<stderr|stdout|file name>", + rt::help = "Parameter " + REPORT_SINK + " allows to set the result report sink - " + "the location where the framework writes the result report to, thus it " + "allows to easily redirect the result report to a file or a standard " + "stream. By default the testing result report is directed to the " + "standard error stream." + )); + + report_sink.add_cla_id( "--", REPORT_SINK, "=" ); + report_sink.add_cla_id( "-", "e", " " ); + store.add( report_sink ); + + /////////////////////////////////////////////// + + rt::option result_code( RESULT_CODE, ( + rt::description = "Disables test modules's result code generation.", + rt::env_var = "BOOST_TEST_RESULT_CODE", + rt::default_value = true, + rt::help = "The 'no' argument value for the parameter " + RESULT_CODE + " instructs the " + "framework to always return zero result code. This can be used for test programs " + "executed within IDE. By default this parameter has value 'yes'." + )); + + result_code.add_cla_id( "--", RESULT_CODE, "=", true ); + result_code.add_cla_id( "-", "c", " " ); + store.add( result_code ); + + /////////////////////////////////////////////// + + rt::parameter<std::string,rt::REPEATABLE_PARAM> tests_to_run( RUN_FILTERS, ( + rt::description = "Filters, which test units to include or exclude from test module execution.", + rt::env_var = "BOOST_TEST_RUN_FILTERS", + rt::value_hint = "<test unit filter>", + rt::help = "Parameter " + RUN_FILTERS + " allows to filter which test units to execute during " + "testing. The framework supports both 'selection filters', which allow to select " + "which test units to enable from the set of available test units, and 'disabler " + "filters', which allow to disable some test units. The __UTF__ also supports " + "enabling/disabling test units at compile time. These settings identify the default " + "set of test units to run. Parameter " + RUN_FILTERS + " is used to change this default. " + "This parameter is repeatable, so you can specify more than one filter if necessary." + )); + + tests_to_run.add_cla_id( "--", RUN_FILTERS, "=" ); + tests_to_run.add_cla_id( "-", "t", " " ); + store.add( tests_to_run ); + + /////////////////////////////////////////////// + + rt::option save_test_pattern( SAVE_TEST_PATTERN, ( + rt::description = "Allows to switch between saving or matching test pattern file.", + rt::env_var = "BOOST_TEST_SAVE_PATTERN", + rt::help = "Parameter " + SAVE_TEST_PATTERN + " facilitates switching mode of operation for " + "testing output streams.\n\nThis parameter serves no particular purpose within the " + "framework itself. It can be used by test modules relying on output_test_stream to " + "implement testing logic. Default mode is 'match' (false)." + )); + + save_test_pattern.add_cla_id( "--", SAVE_TEST_PATTERN, "=" ); + store.add( save_test_pattern ); + + /////////////////////////////////////////////// + + rt::option show_progress( SHOW_PROGRESS, ( + rt::description = "Turns on progress display.", + rt::env_var = "BOOST_TEST_SHOW_PROGRESS", + rt::help = "Parameter " + SHOW_PROGRESS + " instructs the framework to display test progress " + "information. By default the test progress is not shown." + )); + + show_progress.add_cla_id( "--", SHOW_PROGRESS, "=" ); + show_progress.add_cla_id( "-", "p", " " ); + store.add( show_progress ); + + /////////////////////////////////////////////// + + rt::option use_alt_stack( USE_ALT_STACK, ( + rt::description = "Turns on/off usage of an alternative stack for signal handling.", + rt::env_var = "BOOST_TEST_USE_ALT_STACK", + rt::default_value = true, + rt::help = "Parameter " + USE_ALT_STACK + " instructs the framework to use alternative " + "stack for signals processing, on platforms where they are supported. The feature " + "is enabled by default, but can be disabled using this parameter." + )); + + use_alt_stack.add_cla_id( "--", USE_ALT_STACK, "=", true ); + store.add( use_alt_stack ); + + /////////////////////////////////////////////// + + rt::option wait_for_debugger( WAIT_FOR_DEBUGGER, ( + rt::description = "Forces test module to wait for button to be pressed before starting test run.", + rt::env_var = "BOOST_TEST_WAIT_FOR_DEBUGGER", + rt::help = "Parameter " + WAIT_FOR_DEBUGGER + " instructs the framework to pause before starting " + "test units execution, so that you can attach a debugger to running test module. By " + "default this parameters turned off." + )); + + wait_for_debugger.add_cla_id( "--", WAIT_FOR_DEBUGGER, "=" ); + wait_for_debugger.add_cla_id( "-", "w", " " ); + store.add( wait_for_debugger ); + + /////////////////////////////////////////////// + + rt::parameter<std::string> help( HELP, ( + rt::description = "Help for framework parameters.", + rt::optional_value = std::string(), + rt::value_hint = "<parameter name>", + rt::help = "Parameter " + HELP + " displays help on the framework's parameters. " + "The parameter accepts an optional argument value. If present, an argument value is " + "interpreted as a parameter name (name guessing works as well, so for example " + "--help=rand displays help on the parameter random). If the parameter name is unknown " + "or ambiguous error is reported. If argument value is absent, a summary of all " + "framework's parameter is displayed." + )); + help.add_cla_id( "--", HELP, "=" ); + store.add( help ); + + /////////////////////////////////////////////// + + rt::option usage( USAGE, ( + rt::description = "Short message explaining usage of Boost.Test parameters." + )); + usage.add_cla_id( "-", "?", " " ); + store.add( usage ); } -//____________________________________________________________________________// - -output_format -report_format() -{ - return s_report_format; -} +static rt::arguments_store s_arguments_store; +static rt::parameters_store s_parameters_store; //____________________________________________________________________________// -output_format -log_format() -{ - return s_log_format; -} - -//____________________________________________________________________________// +} // local namespace -std::ostream* -report_sink() +void +init( int& argc, char** argv ) { - std::string sink_name = retrieve_parameter( REPORT_SINK, s_cla_parser, s_empty ); + shared_ptr<rt::cla::parser> parser; - if( sink_name.empty() || sink_name == "stderr" ) - return &std::cerr; + BOOST_TEST_I_TRY { + // Initialize parameters list + if( s_parameters_store.is_empty() ) + register_parameters( s_parameters_store ); - if( sink_name == "stdout" ) - return &std::cout; + // Clear up arguments store just in case (of multiple init invocations) + s_arguments_store.clear(); - static std::ofstream report_file( sink_name.c_str() ); - return &report_file; -} + // Parse CLA they take precedence over environment + parser.reset( new rt::cla::parser( s_parameters_store, (rt::end_of_params = "--", rt::negation_prefix = "no_") ) ); + argc = parser->parse( argc, argv, s_arguments_store ); -//____________________________________________________________________________// - -std::ostream* -log_sink() -{ - std::string sink_name = retrieve_parameter( LOG_SINK, s_cla_parser, s_empty ); + // Try to fetch missing arguments from environment + rt::env::fetch_absent( s_parameters_store, s_arguments_store ); - if( sink_name.empty() || sink_name == "stdout" ) - return &std::cout; + // Set arguments to default values if defined and perform all the validations + rt::finalize_arguments( s_parameters_store, s_arguments_store ); - if( sink_name == "stderr" ) - return &std::cerr; - - static std::ofstream log_file( sink_name.c_str() ); - return &log_file; -} + // Report help if requested + if( runtime_config::get<bool>( USAGE ) ) { + parser->usage( std::cerr ); + BOOST_TEST_I_THROW( framework::nothing_to_test( boost::exit_success ) ); + } + else if( s_arguments_store.has( HELP ) ) { + parser->help( std::cerr, s_parameters_store, runtime_config::get<std::string>( HELP ) ); + BOOST_TEST_I_THROW( framework::nothing_to_test( boost::exit_success ) ); + } -//____________________________________________________________________________// + // A bit of business logic: output_format takes precedence over log/report formats + if( s_arguments_store.has( OUTPUT_FORMAT ) ) { + unit_test::output_format of = s_arguments_store.get<unit_test::output_format>( OUTPUT_FORMAT ); + s_arguments_store.set( REPORT_FORMAT, of ); + s_arguments_store.set( LOG_FORMAT, of ); + } + } + BOOST_TEST_I_CATCH( rt::init_error, ex ) { + BOOST_TEST_SETUP_ASSERT( false, ex.msg ); + } + BOOST_TEST_I_CATCH( rt::ambiguous_param, ex ) { + std::cerr << ex.msg << "\n Did you mean one of these?\n"; -long -detect_memory_leaks() -{ - static long s_value = -1; + BOOST_TEST_FOREACH( rt::cstring, name, ex.m_amb_candidates ) + std::cerr << " " << name << "\n"; - if( s_value >= 0 ) - return s_value; + BOOST_TEST_I_THROW( framework::nothing_to_test( boost::exit_exception_failure ) ); + } + BOOST_TEST_I_CATCH( rt::unrecognized_param, ex ) { + std::cerr << ex.msg << "\n"; - std::string value = retrieve_parameter( DETECT_MEM_LEAKS, s_cla_parser, s_empty ); + if( !ex.m_typo_candidates.empty() ) { + std::cerr << " Did you mean one of these?\n"; - optional<bool> bool_val; - if( runtime::interpret_argument_value_impl<bool>::_( value, bool_val ) ) - s_value = *bool_val ? 1L : 0L; - else { - BOOST_TEST_IMPL_TRY { - // if representable as long - this is leak number - s_value = boost::lexical_cast<long>( value ); + BOOST_TEST_FOREACH( rt::cstring, name, ex.m_typo_candidates ) + std::cerr << " " << name << "\n"; } - BOOST_TEST_IMPL_CATCH0( boost::bad_lexical_cast ) { - // value is leak report file and detection is enabled - s_value = 1L; + else if( parser ) { + std::cerr << "\n"; + parser->usage( std::cerr ); } + + BOOST_TEST_I_THROW( framework::nothing_to_test( boost::exit_exception_failure ) ); } + BOOST_TEST_I_CATCH( rt::input_error, ex ) { + std::cerr << ex.msg << "\n\n"; - return s_value; + if( parser ) + parser->usage( std::cerr, ex.param_name ); + + BOOST_TEST_I_THROW( framework::nothing_to_test( boost::exit_exception_failure ) ); + } } //____________________________________________________________________________// -const_string -memory_leaks_report_file() +rt::arguments_store const& +argument_store() { - if( detect_memory_leaks() != 1 ) - return const_string(); - - static std::string s_value; - - if( s_value.empty() ) { - s_value = retrieve_parameter<std::string>( DETECT_MEM_LEAKS, s_cla_parser ); - - optional<bool> bool_val; - if( runtime::interpret_argument_value_impl<bool>::_( s_value, bool_val ) ) - s_value.clear(); - } - - return s_value; + return s_arguments_store; } //____________________________________________________________________________// -unsigned -random_seed() +bool +save_pattern() { - return retrieve_parameter( RANDOM_SEED, s_cla_parser, 0U, 1U ); + return runtime_config::get<bool>( SAVE_TEST_PATTERN ); } //____________________________________________________________________________// diff --git a/boost/test/impl/xml_log_formatter.ipp b/boost/test/impl/xml_log_formatter.ipp index 286cd60005..81284020dd 100644 --- a/boost/test/impl/xml_log_formatter.ipp +++ b/boost/test/impl/xml_log_formatter.ipp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) @@ -66,9 +66,9 @@ void xml_log_formatter::log_build_info( std::ostream& ostr ) { ostr << "<BuildInfo" - << " platform" << attr_value() << BOOST_PLATFORM - << " compiler" << attr_value() << BOOST_COMPILER - << " stl" << attr_value() << BOOST_STDLIB + << " platform" << utils::attr_value() << BOOST_PLATFORM + << " compiler" << utils::attr_value() << BOOST_COMPILER + << " stl" << utils::attr_value() << BOOST_STDLIB << " boost=\"" << BOOST_VERSION/100000 << "." << BOOST_VERSION/100 % 1000 << "." << BOOST_VERSION % 100 << '\"' @@ -80,11 +80,11 @@ xml_log_formatter::log_build_info( std::ostream& ostr ) void xml_log_formatter::test_unit_start( std::ostream& ostr, test_unit const& tu ) { - ostr << "<" << tu_type_name( tu ) << " name" << attr_value() << tu.p_name.get(); + ostr << "<" << tu_type_name( tu ) << " name" << utils::attr_value() << tu.p_name.get(); - if( !tu.p_file_name.get().empty() ) - ostr << BOOST_TEST_L( " file" ) << attr_value() << tu.p_file_name - << BOOST_TEST_L( " line" ) << attr_value() << tu.p_line_num; + if( !tu.p_file_name.empty() ) + ostr << BOOST_TEST_L( " file" ) << utils::attr_value() << tu.p_file_name + << BOOST_TEST_L( " line" ) << utils::attr_value() << tu.p_line_num; ostr << ">"; } @@ -106,9 +106,9 @@ void xml_log_formatter::test_unit_skipped( std::ostream& ostr, test_unit const& tu, const_string reason ) { ostr << "<" << tu_type_name( tu ) - << " name" << attr_value() << tu.p_name.get() - << " skipped" << attr_value() << "yes" - << " reason" << attr_value() << reason + << " name" << utils::attr_value() << tu.p_name + << " skipped" << utils::attr_value() << "yes" + << " reason" << utils::attr_value() << reason << "/>"; } @@ -119,19 +119,19 @@ xml_log_formatter::log_exception_start( std::ostream& ostr, log_checkpoint_data { execution_exception::location const& loc = ex.where(); - ostr << "<Exception file" << attr_value() << loc.m_file_name - << " line" << attr_value() << loc.m_line_num; + ostr << "<Exception file" << utils::attr_value() << loc.m_file_name + << " line" << utils::attr_value() << loc.m_line_num; if( !loc.m_function.is_empty() ) - ostr << " function" << attr_value() << loc.m_function; + ostr << " function" << utils::attr_value() << loc.m_function; - ostr << ">" << cdata() << ex.what(); + ostr << ">" << utils::cdata() << ex.what(); if( !checkpoint_data.m_file_name.is_empty() ) { - ostr << "<LastCheckpoint file" << attr_value() << checkpoint_data.m_file_name - << " line" << attr_value() << checkpoint_data.m_line_num + ostr << "<LastCheckpoint file" << utils::attr_value() << checkpoint_data.m_file_name + << " line" << utils::attr_value() << checkpoint_data.m_line_num << ">" - << cdata() << checkpoint_data.m_message + << utils::cdata() << checkpoint_data.m_message << "</LastCheckpoint>"; } } @@ -153,8 +153,8 @@ xml_log_formatter::log_entry_start( std::ostream& ostr, log_entry_data const& en m_curr_tag = xml_tags[let]; ostr << '<' << m_curr_tag - << BOOST_TEST_L( " file" ) << attr_value() << entry_data.m_file_name - << BOOST_TEST_L( " line" ) << attr_value() << entry_data.m_line_num + << BOOST_TEST_L( " file" ) << utils::attr_value() << entry_data.m_file_name + << BOOST_TEST_L( " line" ) << utils::attr_value() << entry_data.m_line_num << BOOST_TEST_L( "><![CDATA[" ); m_value_closed = false; @@ -165,7 +165,7 @@ xml_log_formatter::log_entry_start( std::ostream& ostr, log_entry_data const& en void xml_log_formatter::log_entry_value( std::ostream& ostr, const_string value ) { - print_escaped_cdata( ostr, value ); + utils::print_escaped_cdata( ostr, value ); } //____________________________________________________________________________// @@ -194,7 +194,6 @@ xml_log_formatter::entry_context_start( std::ostream& ostr, log_level ) } ostr << BOOST_TEST_L( "<Context>" ); - } //____________________________________________________________________________// @@ -210,7 +209,7 @@ xml_log_formatter::entry_context_finish( std::ostream& ostr ) void xml_log_formatter::log_entry_context( std::ostream& ostr, const_string context_descr ) { - ostr << BOOST_TEST_L( "<Frame>" ) << cdata() << context_descr << BOOST_TEST_L( "</Frame>" ); + ostr << BOOST_TEST_L( "<Frame>" ) << utils::cdata() << context_descr << BOOST_TEST_L( "</Frame>" ); } //____________________________________________________________________________// diff --git a/boost/test/impl/xml_report_formatter.ipp b/boost/test/impl/xml_report_formatter.ipp index 5606fdc0b1..08af9a3427 100644 --- a/boost/test/impl/xml_report_formatter.ipp +++ b/boost/test/impl/xml_report_formatter.ipp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) @@ -65,22 +65,21 @@ xml_report_formatter::test_unit_report_start( test_unit const& tu, std::ostream& descr = "failed"; ostr << '<' << ( tu.p_type == TUT_CASE ? "TestCase" : "TestSuite" ) - << " name" << attr_value() << tu.p_name.get() - << " result" << attr_value() << descr - << " assertions_passed" << attr_value() << tr.p_assertions_passed - << " assertions_failed" << attr_value() << tr.p_assertions_failed - << " warnings_failed" << attr_value() << tr.p_warnings_failed - << " expected_failures" << attr_value() << tr.p_expected_failures; + << " name" << utils::attr_value() << tu.p_name + << " result" << utils::attr_value() << descr + << " assertions_passed" << utils::attr_value() << tr.p_assertions_passed + << " assertions_failed" << utils::attr_value() << tr.p_assertions_failed + << " warnings_failed" << utils::attr_value() << tr.p_warnings_failed + << " expected_failures" << utils::attr_value() << tr.p_expected_failures; if( tu.p_type == TUT_SUITE ) { - ostr << " test_cases_passed" << attr_value() << tr.p_test_cases_passed - << " test_cases_passed_with_warnings" << attr_value() << tr.p_test_cases_warned - << " test_cases_failed" << attr_value() << tr.p_test_cases_failed - << " test_cases_skipped" << attr_value() << tr.p_test_cases_skipped - << " test_cases_aborted" << attr_value() << tr.p_test_cases_aborted; + ostr << " test_cases_passed" << utils::attr_value() << tr.p_test_cases_passed + << " test_cases_passed_with_warnings" << utils::attr_value() << tr.p_test_cases_warned + << " test_cases_failed" << utils::attr_value() << tr.p_test_cases_failed + << " test_cases_skipped" << utils::attr_value() << tr.p_test_cases_skipped + << " test_cases_aborted" << utils::attr_value() << tr.p_test_cases_aborted; } - ostr << '>'; } diff --git a/boost/test/included/execution_monitor.hpp b/boost/test/included/execution_monitor.hpp index d372084604..cff2adc9a0 100644 --- a/boost/test/included/execution_monitor.hpp +++ b/boost/test/included/execution_monitor.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2010-2014. +// (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) diff --git a/boost/test/included/prg_exec_monitor.hpp b/boost/test/included/prg_exec_monitor.hpp index e8d655be7d..ff48ce5594 100644 --- a/boost/test/included/prg_exec_monitor.hpp +++ b/boost/test/included/prg_exec_monitor.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) diff --git a/boost/test/included/test_exec_monitor.hpp b/boost/test/included/test_exec_monitor.hpp index 0d5e4b1bf4..cedbcb0ad8 100644 --- a/boost/test/included/test_exec_monitor.hpp +++ b/boost/test/included/test_exec_monitor.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) diff --git a/boost/test/included/unit_test.hpp b/boost/test/included/unit_test.hpp index 5bc17a38cb..03c0277d6d 100644 --- a/boost/test/included/unit_test.hpp +++ b/boost/test/included/unit_test.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) diff --git a/boost/test/included/unit_test_framework.hpp b/boost/test/included/unit_test_framework.hpp index 219cc6c283..5bf366ad80 100644 --- a/boost/test/included/unit_test_framework.hpp +++ b/boost/test/included/unit_test_framework.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2012. +// (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) diff --git a/boost/test/minimal.hpp b/boost/test/minimal.hpp index dfaa68c6e2..c52295309e 100644 --- a/boost/test/minimal.hpp +++ b/boost/test/minimal.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2002-2014. +// (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) diff --git a/boost/test/output/compiler_log_formatter.hpp b/boost/test/output/compiler_log_formatter.hpp index 0b3e881179..e3f98d7567 100644 --- a/boost/test/output/compiler_log_formatter.hpp +++ b/boost/test/output/compiler_log_formatter.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) @@ -33,6 +33,8 @@ namespace output { class BOOST_TEST_DECL compiler_log_formatter : public unit_test_log_formatter { public: + compiler_log_formatter() : m_color_output( false ) {} + // Formatter interface void log_start( std::ostream&, counter_t test_cases_amount ); void log_finish( std::ostream& ); @@ -56,6 +58,9 @@ public: protected: virtual void print_prefix( std::ostream&, const_string file, std::size_t line ); + + // Data members + bool m_color_output; }; } // namespace output diff --git a/boost/test/output/plain_report_formatter.hpp b/boost/test/output/plain_report_formatter.hpp index ff8924f623..8c50964597 100644 --- a/boost/test/output/plain_report_formatter.hpp +++ b/boost/test/output/plain_report_formatter.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) @@ -33,6 +33,8 @@ namespace output { class plain_report_formatter : public results_reporter::format { public: + plain_report_formatter() : m_indent( 0 ), m_color_output( false ) {} + // Formatter interface void results_report_start( std::ostream& ostr ); void results_report_finish( std::ostream& ostr ); @@ -45,6 +47,7 @@ public: private: // Data members counter_t m_indent; + bool m_color_output; }; } // namespace output diff --git a/boost/test/output/xml_log_formatter.hpp b/boost/test/output/xml_log_formatter.hpp index 7c05e482e7..4d848a0425 100644 --- a/boost/test/output/xml_log_formatter.hpp +++ b/boost/test/output/xml_log_formatter.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) diff --git a/boost/test/output/xml_report_formatter.hpp b/boost/test/output/xml_report_formatter.hpp index ab183d02ae..ca5e47182f 100644 --- a/boost/test/output/xml_report_formatter.hpp +++ b/boost/test/output/xml_report_formatter.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) diff --git a/boost/test/output_test_stream.hpp b/boost/test/output_test_stream.hpp index 83f9264635..26eaf320ac 100644 --- a/boost/test/output_test_stream.hpp +++ b/boost/test/output_test_stream.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) diff --git a/boost/test/parameterized_test.hpp b/boost/test/parameterized_test.hpp index 4e08567d31..b94e7ec8b3 100644 --- a/boost/test/parameterized_test.hpp +++ b/boost/test/parameterized_test.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) diff --git a/boost/test/predicate_result.hpp b/boost/test/predicate_result.hpp index fb924c7733..9b57363713 100644 --- a/boost/test/predicate_result.hpp +++ b/boost/test/predicate_result.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) diff --git a/boost/test/prg_exec_monitor.hpp b/boost/test/prg_exec_monitor.hpp index 7234833f72..f072e215db 100644 --- a/boost/test/prg_exec_monitor.hpp +++ b/boost/test/prg_exec_monitor.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) diff --git a/boost/test/progress_monitor.hpp b/boost/test/progress_monitor.hpp index 3d66152297..e480ac669d 100644 --- a/boost/test/progress_monitor.hpp +++ b/boost/test/progress_monitor.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) diff --git a/boost/test/results_collector.hpp b/boost/test/results_collector.hpp index f34bf38345..d12fefb39c 100644 --- a/boost/test/results_collector.hpp +++ b/boost/test/results_collector.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) diff --git a/boost/test/results_reporter.hpp b/boost/test/results_reporter.hpp index 4c8627e458..6f8d8f1105 100644 --- a/boost/test/results_reporter.hpp +++ b/boost/test/results_reporter.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) diff --git a/boost/test/test_case_template.hpp b/boost/test/test_case_template.hpp index 77adf6cc8c..c01bd0738a 100644 --- a/boost/test/test_case_template.hpp +++ b/boost/test/test_case_template.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2003-2014. +// (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) diff --git a/boost/test/test_exec_monitor.hpp b/boost/test/test_exec_monitor.hpp index af81aa0296..0450809335 100644 --- a/boost/test/test_exec_monitor.hpp +++ b/boost/test/test_exec_monitor.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) diff --git a/boost/test/test_tools.hpp b/boost/test/test_tools.hpp index dea2b20fa2..a542d5fcde 100644 --- a/boost/test/test_tools.hpp +++ b/boost/test/test_tools.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) @@ -15,16 +15,24 @@ #define BOOST_TEST_TOOLS_HPP_111812GER #include <boost/config.hpp> + +// brings some compiler configuration like BOOST_PP_VARIADICS +#include <boost/test/detail/config.hpp> + #include <boost/preprocessor/config/config.hpp> -#if !BOOST_PP_VARIADICS || ((__cplusplus >= 201103L) && defined(BOOST_NO_CXX11_VARIADIC_MACROS)) -#define BOOST_TEST_NO_VARIADIC +#if defined(BOOST_NO_CXX11_VARIADIC_MACROS) \ + || defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) \ + || defined(BOOST_NO_CXX11_DECLTYPE) +# define BOOST_TEST_MACRO_LIMITED_SUPPORT #endif // Boost.Test // #define BOOST_TEST_NO_OLD_TOOLS -#if defined(BOOST_TEST_NO_VARIADIC) +#if defined(BOOST_TEST_MACRO_LIMITED_SUPPORT) \ + && ( !BOOST_PP_VARIADICS \ + || !(__cplusplus >= 201103L) && defined(BOOST_NO_CXX11_VARIADIC_MACROS)) # define BOOST_TEST_NO_NEW_TOOLS #endif @@ -57,5 +65,4 @@ # include <boost/test/tools/detail/lexicographic_manip.hpp> #endif - #endif // BOOST_TEST_TOOLS_HPP_111812GER diff --git a/boost/test/tools/assertion.hpp b/boost/test/tools/assertion.hpp index b46b6760e7..cca2f52beb 100644 --- a/boost/test/tools/assertion.hpp +++ b/boost/test/tools/assertion.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) @@ -23,6 +23,7 @@ #include <boost/mpl/assert.hpp> #include <boost/utility/declval.hpp> #include <boost/type_traits/remove_reference.hpp> +#include <boost/type_traits/remove_const.hpp> // STL #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES @@ -180,15 +181,17 @@ class expression_base { public: #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES - + template<typename T> + struct RhsT : remove_const<typename remove_reference<T>::type> {}; + #define ADD_OP_SUPPORT( oper, name, _ ) \ template<typename T> \ binary_expr<ExprType,T, \ - op::name<ValType,typename remove_reference<T>::type> > \ + op::name<ValType,typename RhsT<T>::type> > \ operator oper( T&& rhs ) \ { \ return binary_expr<ExprType,T, \ - op::name<ValType,typename remove_reference<T>::type> > \ + op::name<ValType,typename RhsT<T>::type> > \ ( std::forward<ExprType>( \ *static_cast<ExprType*>(this) ), \ std::forward<T>(rhs) ); \ @@ -199,7 +202,7 @@ public: #define ADD_OP_SUPPORT( oper, name, _ ) \ template<typename T> \ binary_expr<ExprType,typename boost::decay<T const>::type, \ - op::name<ValType,typename boost::decay<T const>::type> > \ + op::name<ValType,typename boost::decay<T const>::type> >\ operator oper( T const& rhs ) const \ { \ typedef typename boost::decay<T const>::type Rhs; \ @@ -248,7 +251,7 @@ public: // simple value expression template<typename T> -class value_expr : public expression_base<value_expr<T>,typename remove_reference<T>::type> { +class value_expr : public expression_base<value_expr<T>,typename remove_const<typename remove_reference<T>::type>::type> { public: // Public types typedef T result_type; diff --git a/boost/test/tools/assertion_result.hpp b/boost/test/tools/assertion_result.hpp index 85cd18c0eb..85eea741f7 100644 --- a/boost/test/tools/assertion_result.hpp +++ b/boost/test/tools/assertion_result.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) diff --git a/boost/test/tools/collection_comparison_op.hpp b/boost/test/tools/collection_comparison_op.hpp index 81a7046725..e5c5ca3bb8 100644 --- a/boost/test/tools/collection_comparison_op.hpp +++ b/boost/test/tools/collection_comparison_op.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2014-2015. +// (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) @@ -50,7 +50,7 @@ struct specialized_compare<Col> : public mpl::true_ {}; \ namespace op { -template <typename OP, bool can_be_equal, bool prefer_shorter, +template <typename OP, bool can_be_equal, bool prefer_shorter, typename Lhs, typename Rhs> inline assertion_result lexicographic_compare( Lhs const& lhs, Rhs const& rhs ) @@ -69,13 +69,13 @@ lexicographic_compare( Lhs const& lhs, Rhs const& rhs ) return ar; // a < b assertion_result const& reverse_ar = OP::eval(*first2, *first1); - if( element_ar && !reverse_ar ) + if( element_ar && !reverse_ar ) return ar; // a<=b and !(b<=a) => a < b => return true - - if( element_ar || !reverse_ar ) - continue; // (a<=b and b<=a) or (!(a<b) and !(b<a)) => a == b => keep looking - // !(a<=b) and b<=a => b < a => return false + if( element_ar || !reverse_ar ) + continue; // (a<=b and b<=a) or (!(a<b) and !(b<a)) => a == b => keep looking + + // !(a<=b) and b<=a => b < a => return false ar = false; ar.message() << "\nFailure at position " << pos << ": " << tt_detail::print_helper(*first1) @@ -85,7 +85,7 @@ lexicographic_compare( Lhs const& lhs, Rhs const& rhs ) return ar; } - + if( first1 != last1 ) { if( prefer_shorter ) { ar = false; @@ -325,7 +325,7 @@ compare_collections( Lhs const& lhs, Rhs const& rhs, boost::type<op::GE<L, R> >* // ********* specialization of comparison operators for collections ********* // // ************************************************************************** // -#define DEFINE_COLLECTION_COMPARISON( oper, name, _ ) \ +#define DEFINE_COLLECTION_COMPARISON( oper, name, rev ) \ template<typename Lhs,typename Rhs> \ struct name<Lhs,Rhs,typename boost::enable_if_c< \ unit_test::is_forward_iterable<Lhs>::value && \ @@ -356,6 +356,10 @@ public: \ report( std::ostream&, \ PrevExprType const&, \ Rhs const& ) {} \ + \ + static char const* revert() \ + { return " " #rev " "; } \ + \ }; \ /**/ @@ -372,4 +376,3 @@ BOOST_TEST_FOR_EACH_COMP_OP( DEFINE_COLLECTION_COMPARISON ) #include <boost/test/detail/enable_warnings.hpp> #endif // BOOST_TEST_TOOLS_COLLECTION_COMPARISON_OP_HPP_050815GER - diff --git a/boost/test/tools/context.hpp b/boost/test/tools/context.hpp index 38018b84b8..71650065ef 100644 --- a/boost/test/tools/context.hpp +++ b/boost/test/tools/context.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) diff --git a/boost/test/tools/cstring_comparison_op.hpp b/boost/test/tools/cstring_comparison_op.hpp index 3b114e5977..0aaf997b5d 100644 --- a/boost/test/tools/cstring_comparison_op.hpp +++ b/boost/test/tools/cstring_comparison_op.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2014-2015. +// (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) diff --git a/boost/test/tools/detail/bitwise_manip.hpp b/boost/test/tools/detail/bitwise_manip.hpp index e0fd36acd4..f8c9685c10 100644 --- a/boost/test/tools/detail/bitwise_manip.hpp +++ b/boost/test/tools/detail/bitwise_manip.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) diff --git a/boost/test/tools/detail/expression_holder.hpp b/boost/test/tools/detail/expression_holder.hpp index 7d7efd04e6..694a2d5f4e 100644 --- a/boost/test/tools/detail/expression_holder.hpp +++ b/boost/test/tools/detail/expression_holder.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) diff --git a/boost/test/tools/detail/fwd.hpp b/boost/test/tools/detail/fwd.hpp index d5915a1656..339ab39eda 100644 --- a/boost/test/tools/detail/fwd.hpp +++ b/boost/test/tools/detail/fwd.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) diff --git a/boost/test/tools/detail/indirections.hpp b/boost/test/tools/detail/indirections.hpp index 429420f55a..836218d98d 100644 --- a/boost/test/tools/detail/indirections.hpp +++ b/boost/test/tools/detail/indirections.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) diff --git a/boost/test/tools/detail/it_pair.hpp b/boost/test/tools/detail/it_pair.hpp index 929bbae96d..4352fd464f 100644 --- a/boost/test/tools/detail/it_pair.hpp +++ b/boost/test/tools/detail/it_pair.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) diff --git a/boost/test/tools/detail/lexicographic_manip.hpp b/boost/test/tools/detail/lexicographic_manip.hpp index 01d63a9e91..f6ffff7a34 100644 --- a/boost/test/tools/detail/lexicographic_manip.hpp +++ b/boost/test/tools/detail/lexicographic_manip.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2015. +// (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) diff --git a/boost/test/tools/detail/per_element_manip.hpp b/boost/test/tools/detail/per_element_manip.hpp index efcd45e9b8..4a9aebbaaa 100644 --- a/boost/test/tools/detail/per_element_manip.hpp +++ b/boost/test/tools/detail/per_element_manip.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2015. +// (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) diff --git a/boost/test/tools/detail/print_helper.hpp b/boost/test/tools/detail/print_helper.hpp index ab15146aa2..77b936c44b 100644 --- a/boost/test/tools/detail/print_helper.hpp +++ b/boost/test/tools/detail/print_helper.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) diff --git a/boost/test/tools/detail/tolerance_manip.hpp b/boost/test/tools/detail/tolerance_manip.hpp index adb58f98d0..e07b043591 100644 --- a/boost/test/tools/detail/tolerance_manip.hpp +++ b/boost/test/tools/detail/tolerance_manip.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) @@ -50,7 +50,7 @@ inline tolerance_manip<FPT> operator%( FPT v, tolerance_manip_delay const& ) { BOOST_STATIC_ASSERT_MSG( (fpc::tolerance_based<FPT>::value), - "tolerance only for floating points" ); + "tolerance should be specified using a floating points type" ); return tolerance_manip<FPT>( FPT(v / 100) ); } diff --git a/boost/test/tools/floating_point_comparison.hpp b/boost/test/tools/floating_point_comparison.hpp index fac914c91d..d704a41092 100644 --- a/boost/test/tools/floating_point_comparison.hpp +++ b/boost/test/tools/floating_point_comparison.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) @@ -285,7 +285,7 @@ public: // Action method bool operator()( FPT fpv ) const { - return fpc::fpc_detail::fpt_abs( fpv ) < m_tolerance; + return fpc::fpc_detail::fpt_abs( fpv ) <= m_tolerance; } private: diff --git a/boost/test/tools/fpc_op.hpp b/boost/test/tools/fpc_op.hpp index a2513ccfa3..da143aa9f3 100644 --- a/boost/test/tools/fpc_op.hpp +++ b/boost/test/tools/fpc_op.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2014-2015. +// (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) @@ -169,27 +169,27 @@ public: \ typedef assertion_result result_type; \ \ static bool \ - eval_direct( Lhs const& lhs, Rhs const& rhs) \ + eval_direct( Lhs const& lhs, Rhs const& rhs ) \ { \ return lhs oper rhs; \ } \ \ static assertion_result \ - eval( Lhs const& lhs, Rhs const& rhs) \ + eval( Lhs const& lhs, Rhs const& rhs ) \ { \ if( lhs == 0 ) \ - return compare_fpv_near_zero(rhs, (OP*)0); \ + return compare_fpv_near_zero( rhs, (OP*)0 ); \ \ if( rhs == 0 ) \ - return compare_fpv_near_zero(lhs, (OP*)0); \ + return compare_fpv_near_zero( lhs, (OP*)0 ); \ \ bool direct_res = eval_direct( lhs, rhs ); \ \ - if((direct_res && fpctraits<OP>::cmp_direct) \ - || fpc_tolerance<FPT>() == FPT(0)) \ + if( (direct_res && fpctraits<OP>::cmp_direct) || \ + fpc_tolerance<FPT>() == FPT(0) ) \ return direct_res; \ \ - return compare_fpv<FPT>(lhs, rhs, (OP*)0); \ + return compare_fpv<FPT>( lhs, rhs, (OP*)0 ); \ } \ \ template<typename PrevExprType> \ diff --git a/boost/test/tools/fpc_tolerance.hpp b/boost/test/tools/fpc_tolerance.hpp index 013b571ded..c862a17e75 100644 --- a/boost/test/tools/fpc_tolerance.hpp +++ b/boost/test/tools/fpc_tolerance.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) diff --git a/boost/test/tools/interface.hpp b/boost/test/tools/interface.hpp index fe51021303..48d5affc4f 100644 --- a/boost/test/tools/interface.hpp +++ b/boost/test/tools/interface.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) diff --git a/boost/test/tools/old/impl.hpp b/boost/test/tools/old/impl.hpp index e5414f566e..b975f61b38 100644 --- a/boost/test/tools/old/impl.hpp +++ b/boost/test/tools/old/impl.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) diff --git a/boost/test/tools/old/interface.hpp b/boost/test/tools/old/interface.hpp index 0c35c82b87..2d6f8b78c0 100644 --- a/boost/test/tools/old/interface.hpp +++ b/boost/test/tools/old/interface.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) @@ -95,16 +95,17 @@ do { //____________________________________________________________________________// -#define BOOST_CHECK_THROW_IMPL( S, E, P, prefix, TL ) \ +#define BOOST_CHECK_THROW_IMPL( S, E, P, postfix, TL ) \ do { \ try { \ BOOST_TEST_PASSPOINT(); \ S; \ - BOOST_TEST_TOOL_IMPL( 2, false, "exception " BOOST_STRINGIZE(E) " is expected", \ + BOOST_TEST_TOOL_IMPL( 2, false, "exception " BOOST_STRINGIZE(E) " expected but not raised", \ TL, CHECK_MSG, _ ); \ } catch( E const& ex ) { \ ::boost::unit_test::ut_detail::ignore_unused_variable_warning( ex ); \ - BOOST_TEST_TOOL_IMPL( 2, P, prefix BOOST_STRINGIZE( E ) " is caught", \ + BOOST_TEST_TOOL_IMPL( 2, P, \ + "exception \"" BOOST_STRINGIZE( E )"\" raised as expected" postfix, \ TL, CHECK_MSG, _ ); \ } \ } while( ::boost::test_tools::tt_detail::dummy_cond() ) \ @@ -112,15 +113,18 @@ do { //____________________________________________________________________________// -#define BOOST_WARN_THROW( S, E ) BOOST_CHECK_THROW_IMPL( S, E, true, "exception ", WARN ) -#define BOOST_CHECK_THROW( S, E ) BOOST_CHECK_THROW_IMPL( S, E, true, "exception ", CHECK ) -#define BOOST_REQUIRE_THROW( S, E ) BOOST_CHECK_THROW_IMPL( S, E, true, "exception ", REQUIRE ) +#define BOOST_WARN_THROW( S, E ) BOOST_CHECK_THROW_IMPL( S, E, true, "", WARN ) +#define BOOST_CHECK_THROW( S, E ) BOOST_CHECK_THROW_IMPL( S, E, true, "", CHECK ) +#define BOOST_REQUIRE_THROW( S, E ) BOOST_CHECK_THROW_IMPL( S, E, true, "", REQUIRE ) //____________________________________________________________________________// -#define BOOST_WARN_EXCEPTION( S, E, P ) BOOST_CHECK_THROW_IMPL( S, E, P( ex ), "incorrect exception ", WARN ) -#define BOOST_CHECK_EXCEPTION( S, E, P ) BOOST_CHECK_THROW_IMPL( S, E, P( ex ), "incorrect exception ", CHECK ) -#define BOOST_REQUIRE_EXCEPTION( S, E, P ) BOOST_CHECK_THROW_IMPL( S, E, P( ex ), "incorrect exception ", REQUIRE ) +#define BOOST_WARN_EXCEPTION( S, E, P ) BOOST_CHECK_THROW_IMPL( S, E, P( ex ), \ + ": validation on the raised exception through predicate \"" BOOST_STRINGIZE(P) "\"", WARN ) +#define BOOST_CHECK_EXCEPTION( S, E, P ) BOOST_CHECK_THROW_IMPL( S, E, P( ex ), \ + ": validation on the raised exception through predicate \"" BOOST_STRINGIZE(P) "\"", CHECK ) +#define BOOST_REQUIRE_EXCEPTION( S, E, P ) BOOST_CHECK_THROW_IMPL( S, E, P( ex ), \ + ": validation on the raised exception through predicate \"" BOOST_STRINGIZE(P) "\"", REQUIRE ) //____________________________________________________________________________// @@ -131,7 +135,7 @@ do { BOOST_TEST_TOOL_IMPL( 2, true, "no exceptions thrown by " BOOST_STRINGIZE( S ), \ TL, CHECK_MSG, _ ); \ } catch( ... ) { \ - BOOST_TEST_TOOL_IMPL( 2, false, "exception thrown by " BOOST_STRINGIZE( S ), \ + BOOST_TEST_TOOL_IMPL( 2, false, "unexpected exception thrown by " BOOST_STRINGIZE( S ), \ TL, CHECK_MSG, _ ); \ } \ } while( ::boost::test_tools::tt_detail::dummy_cond() ) \ diff --git a/boost/test/tools/output_test_stream.hpp b/boost/test/tools/output_test_stream.hpp index 89c9ad1919..02d3715e9d 100644 --- a/boost/test/tools/output_test_stream.hpp +++ b/boost/test/tools/output_test_stream.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) diff --git a/boost/test/tree/auto_registration.hpp b/boost/test/tree/auto_registration.hpp index a32e6b8ad1..a3fe32fda7 100644 --- a/boost/test/tree/auto_registration.hpp +++ b/boost/test/tree/auto_registration.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) diff --git a/boost/test/tree/decorator.hpp b/boost/test/tree/decorator.hpp index c24a0210ad..27c46682a0 100644 --- a/boost/test/tree/decorator.hpp +++ b/boost/test/tree/decorator.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) diff --git a/boost/test/tree/fixture.hpp b/boost/test/tree/fixture.hpp index da6befbae7..7bca5a8de3 100644 --- a/boost/test/tree/fixture.hpp +++ b/boost/test/tree/fixture.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) diff --git a/boost/test/tree/global_fixture.hpp b/boost/test/tree/global_fixture.hpp index 9ba4462a5c..89ee61eb0c 100644 --- a/boost/test/tree/global_fixture.hpp +++ b/boost/test/tree/global_fixture.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) diff --git a/boost/test/tree/observer.hpp b/boost/test/tree/observer.hpp index 3ae96c488d..d878949f67 100644 --- a/boost/test/tree/observer.hpp +++ b/boost/test/tree/observer.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) @@ -38,7 +38,7 @@ public: virtual void test_unit_start( test_unit const& ) {} virtual void test_unit_finish( test_unit const&, unsigned long /* elapsed */ ) {} virtual void test_unit_skipped( test_unit const& tu, const_string ) { test_unit_skipped( tu ); } - virtual void test_unit_skipped( test_unit const& ) {} ///< backward compartibility + virtual void test_unit_skipped( test_unit const& ) {} ///< backward compatibility virtual void test_unit_aborted( test_unit const& ) {} virtual void assertion_result( unit_test::assertion_result ar ) diff --git a/boost/test/tree/test_case_counter.hpp b/boost/test/tree/test_case_counter.hpp index f9fa2d2bd2..6feaddcb0e 100644 --- a/boost/test/tree/test_case_counter.hpp +++ b/boost/test/tree/test_case_counter.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) diff --git a/boost/test/tree/test_case_template.hpp b/boost/test/tree/test_case_template.hpp index ef2881588a..56871b7b6b 100644 --- a/boost/test/tree/test_case_template.hpp +++ b/boost/test/tree/test_case_template.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) diff --git a/boost/test/tree/test_unit.hpp b/boost/test/tree/test_unit.hpp index 4791bd15ac..273fa14ff3 100644 --- a/boost/test/tree/test_unit.hpp +++ b/boost/test/tree/test_unit.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) @@ -82,10 +82,10 @@ public: std::string full_name() const; // Public r/o properties - readonly_property<test_unit_type> p_type; ///< type for this test unit - readonly_property<const_string> p_type_name; ///< "case"/"suite"/"module" - readonly_property<const_string> p_file_name; - readonly_property<std::size_t> p_line_num; + test_unit_type const p_type; ///< type for this test unit + const_string const p_type_name; ///< "case"/"suite"/"module" + const_string const p_file_name; + std::size_t const p_line_num; id_t p_id; ///< unique id for this test unit parent_id_t p_parent_id; ///< parent test suite id label_list_t p_labels; ///< list of labels associated with this test unit diff --git a/boost/test/tree/traverse.hpp b/boost/test/tree/traverse.hpp index 461ff89ba4..d27917cace 100644 --- a/boost/test/tree/traverse.hpp +++ b/boost/test/tree/traverse.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) diff --git a/boost/test/tree/visitor.hpp b/boost/test/tree/visitor.hpp index 0dd864063b..8f1bae5c92 100644 --- a/boost/test/tree/visitor.hpp +++ b/boost/test/tree/visitor.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2011-2014. +// (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) diff --git a/boost/test/unit_test.hpp b/boost/test/unit_test.hpp index 6181355316..e6a236a1b5 100644 --- a/boost/test/unit_test.hpp +++ b/boost/test/unit_test.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) diff --git a/boost/test/unit_test_log.hpp b/boost/test/unit_test_log.hpp index 76817ffcb8..4126953d02 100644 --- a/boost/test/unit_test_log.hpp +++ b/boost/test/unit_test_log.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) diff --git a/boost/test/unit_test_log_formatter.hpp b/boost/test/unit_test_log_formatter.hpp index f89b74bd17..1e3d64322f 100644 --- a/boost/test/unit_test_log_formatter.hpp +++ b/boost/test/unit_test_log_formatter.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2003-2014. +// (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) diff --git a/boost/test/unit_test_monitor.hpp b/boost/test/unit_test_monitor.hpp index b0358352e9..1f937fa674 100644 --- a/boost/test/unit_test_monitor.hpp +++ b/boost/test/unit_test_monitor.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) diff --git a/boost/test/unit_test_parameters.hpp b/boost/test/unit_test_parameters.hpp index 31f76d7b2f..ad69c1732e 100644 --- a/boost/test/unit_test_parameters.hpp +++ b/boost/test/unit_test_parameters.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) @@ -14,14 +14,15 @@ #ifndef BOOST_TEST_UNIT_TEST_PARAMETERS_HPP_071894GER #define BOOST_TEST_UNIT_TEST_PARAMETERS_HPP_071894GER +// Boost.Test #include <boost/test/detail/global_typedef.hpp> -#include <boost/test/detail/log_level.hpp> - -#include <boost/test/detail/suppress_warnings.hpp> +#include <boost/test/utils/runtime/argument.hpp> // STL -#include <iosfwd> -#include <list> +#include <iostream> +#include <fstream> + +#include <boost/test/detail/suppress_warnings.hpp> //____________________________________________________________________________// @@ -33,53 +34,88 @@ namespace runtime_config { // ************** runtime_config ************** // // ************************************************************************** // -BOOST_TEST_DECL void init( int& argc, char** argv ); - -/// Automatically attach debugger in a location of fatal error -BOOST_TEST_DECL bool auto_start_dbg(); -BOOST_TEST_DECL const_string break_exec_path(); -/// Should we catch system errors/sygnals? -BOOST_TEST_DECL bool catch_sys_errors(); -/// Should we try to produce color output? -BOOST_TEST_DECL bool color_output(); -/// Should we detect floating point exceptions? -BOOST_TEST_DECL bool detect_fp_exceptions(); -/// Should we detect memory leaks (>0)? And if yes, which specific memory allocation should we break. -BOOST_TEST_DECL long detect_memory_leaks(); -/// List content of test tree? -BOOST_TEST_DECL output_format list_content(); -/// List available labels? -BOOST_TEST_DECL bool list_labels(); -/// Which output format to use -BOOST_TEST_DECL output_format log_format(); -/// Which log level to set -BOOST_TEST_DECL unit_test::log_level log_level(); -/// Where to direct log stream into -BOOST_TEST_DECL std::ostream* log_sink(); -/// If memory leak detection, where to direct the report -BOOST_TEST_DECL const_string memory_leaks_report_file(); -/// Do not prodce result code -BOOST_TEST_DECL bool no_result_code(); -/// Random seed to use to randomize order of test units being run -BOOST_TEST_DECL unsigned random_seed(); -/// Which format to use to report results -BOOST_TEST_DECL output_format report_format(); -/// Wht lever of report format to set -BOOST_TEST_DECL unit_test::report_level report_level(); -/// Where to direct results report into -BOOST_TEST_DECL std::ostream* report_sink(); -/// Should we save pattern (true) or match against existing pattern (used by output validation tool) -BOOST_TEST_DECL bool save_pattern(); -/// Should Unit Test framework show the build information? -BOOST_TEST_DECL bool show_build_info(); -/// Tells Unit Test Framework to show test progress (forces specific log level) -BOOST_TEST_DECL bool show_progress(); -/// Specific test units to run/exclude -BOOST_TEST_DECL std::list<std::string> const& test_to_run(); -/// Should execution monitor use alternative stack for signal handling -BOOST_TEST_DECL bool use_alt_stack(); -/// Tells Unit Test Framework to wait for debugger to attach -BOOST_TEST_DECL bool wait_for_debugger(); +// UTF parameters +BOOST_TEST_DECL extern std::string AUTO_START_DBG; +BOOST_TEST_DECL extern std::string BREAK_EXEC_PATH; +BOOST_TEST_DECL extern std::string BUILD_INFO; +BOOST_TEST_DECL extern std::string CATCH_SYS_ERRORS; +BOOST_TEST_DECL extern std::string COLOR_OUTPUT; +BOOST_TEST_DECL extern std::string DETECT_FP_EXCEPT; +BOOST_TEST_DECL extern std::string DETECT_MEM_LEAKS; +BOOST_TEST_DECL extern std::string LIST_CONTENT; +BOOST_TEST_DECL extern std::string LIST_LABELS; +BOOST_TEST_DECL extern std::string LOG_FORMAT; +BOOST_TEST_DECL extern std::string LOG_LEVEL; +BOOST_TEST_DECL extern std::string LOG_SINK; +BOOST_TEST_DECL extern std::string OUTPUT_FORMAT; +BOOST_TEST_DECL extern std::string RANDOM_SEED; +BOOST_TEST_DECL extern std::string REPORT_FORMAT; +BOOST_TEST_DECL extern std::string REPORT_LEVEL; +BOOST_TEST_DECL extern std::string REPORT_MEM_LEAKS; +BOOST_TEST_DECL extern std::string REPORT_SINK; +BOOST_TEST_DECL extern std::string RESULT_CODE; +BOOST_TEST_DECL extern std::string RUN_FILTERS; +BOOST_TEST_DECL extern std::string SAVE_TEST_PATTERN; +BOOST_TEST_DECL extern std::string SHOW_PROGRESS; +BOOST_TEST_DECL extern std::string USE_ALT_STACK; +BOOST_TEST_DECL extern std::string WAIT_FOR_DEBUGGER; + +BOOST_TEST_DECL void init( int& argc, char** argv ); + +// ************************************************************************** // +// ************** runtime_param::get ************** // +// ************************************************************************** // + +/// Access to arguments +BOOST_TEST_DECL runtime::arguments_store const& argument_store(); + +template<typename T> +inline T const& +get( runtime::cstring parameter_name ) +{ + return argument_store().get<T>( parameter_name ); +} + +/// For public access +BOOST_TEST_DECL bool save_pattern(); + +// ************************************************************************** // +// ************** stream_holder ************** // +// ************************************************************************** // + +class stream_holder { +public: + // Constructor + explicit stream_holder( std::ostream& default_stream ) + : m_stream( &default_stream ) + { + } + + void setup( runtime::cstring param_name ) + { + if( !runtime_config::argument_store().has( param_name ) ) + return; + + std::string const& file_name = runtime_config::get<std::string>( param_name ); + + if( file_name == "stderr" ) + m_stream = &std::cerr; + else if( file_name == "stdout" ) + m_stream = &std::cout; + else { + m_file.open( file_name.c_str() ); + m_stream = &m_file; + } + } + + // Access methods + std::ostream& ref() const { return *m_stream; } + +private: + // Data members + std::ofstream m_file; + std::ostream* m_stream; +}; } // namespace runtime_config } // namespace unit_test diff --git a/boost/test/unit_test_suite.hpp b/boost/test/unit_test_suite.hpp index 41d6151354..1dbcece78a 100644 --- a/boost/test/unit_test_suite.hpp +++ b/boost/test/unit_test_suite.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) @@ -18,8 +18,14 @@ #include <boost/test/tree/test_case_template.hpp> #include <boost/test/tree/global_fixture.hpp> + +#include <boost/test/detail/suppress_warnings.hpp> + + #include <boost/test/detail/pp_variadic.hpp> + + //____________________________________________________________________________// // ************************************************************************** // @@ -353,5 +359,8 @@ init_unit_test_suite( int, char* [] ) { //____________________________________________________________________________// +#include <boost/test/detail/enable_warnings.hpp> + + #endif // BOOST_TEST_UNIT_TEST_SUITE_HPP_071894GER diff --git a/boost/test/utils/algorithm.hpp b/boost/test/utils/algorithm.hpp index 7a70654718..76625cbd91 100644 --- a/boost/test/utils/algorithm.hpp +++ b/boost/test/utils/algorithm.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2004-2014. +// (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) @@ -22,8 +22,8 @@ //____________________________________________________________________________// namespace boost { - namespace unit_test { +namespace utils { /// @brief this algorithm search through two collections for first mismatch position that get returned as a pair /// of iterators, first pointing to the mismatch position in first collection, second iterator in second one @@ -213,11 +213,10 @@ find_last_not_of( BidirectionalIterator1 first1, BidirectionalIterator1 last1, //____________________________________________________________________________// +} // namespace utils } // namespace unit_test } // namespace boost #include <boost/test/detail/enable_warnings.hpp> #endif // BOOST_TEST_UTILS_ALGORITHM_HPP - - diff --git a/boost/test/utils/assign_op.hpp b/boost/test/utils/assign_op.hpp index ea49b5148b..89d8bfa956 100644 --- a/boost/test/utils/assign_op.hpp +++ b/boost/test/utils/assign_op.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) diff --git a/boost/test/utils/basic_cstring/basic_cstring.hpp b/boost/test/utils/basic_cstring/basic_cstring.hpp index 7cbd36b328..d6259990e0 100644 --- a/boost/test/utils/basic_cstring/basic_cstring.hpp +++ b/boost/test/utils/basic_cstring/basic_cstring.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2004-2014. +// (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) diff --git a/boost/test/utils/basic_cstring/basic_cstring_fwd.hpp b/boost/test/utils/basic_cstring/basic_cstring_fwd.hpp index a1865f4f94..f0622263d1 100644 --- a/boost/test/utils/basic_cstring/basic_cstring_fwd.hpp +++ b/boost/test/utils/basic_cstring/basic_cstring_fwd.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2004-2014. +// (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) diff --git a/boost/test/utils/basic_cstring/bcs_char_traits.hpp b/boost/test/utils/basic_cstring/bcs_char_traits.hpp index 4700d14291..eb77f474c7 100644 --- a/boost/test/utils/basic_cstring/bcs_char_traits.hpp +++ b/boost/test/utils/basic_cstring/bcs_char_traits.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2004-2014. +// (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) diff --git a/boost/test/utils/basic_cstring/compare.hpp b/boost/test/utils/basic_cstring/compare.hpp index f071a2540c..b416b1f2b9 100644 --- a/boost/test/utils/basic_cstring/compare.hpp +++ b/boost/test/utils/basic_cstring/compare.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2004-2014. +// (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) diff --git a/boost/test/utils/basic_cstring/io.hpp b/boost/test/utils/basic_cstring/io.hpp index 218ae6a520..02ccb126f8 100644 --- a/boost/test/utils/basic_cstring/io.hpp +++ b/boost/test/utils/basic_cstring/io.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2004-2014. +// (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) diff --git a/boost/test/utils/class_properties.hpp b/boost/test/utils/class_properties.hpp index 1781a17dd0..d4f3db3f2d 100644 --- a/boost/test/utils/class_properties.hpp +++ b/boost/test/utils/class_properties.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. +// (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) diff --git a/boost/test/utils/custom_manip.hpp b/boost/test/utils/custom_manip.hpp index 43b581df16..d5ddaf5c07 100644 --- a/boost/test/utils/custom_manip.hpp +++ b/boost/test/utils/custom_manip.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) @@ -24,6 +24,7 @@ namespace boost { namespace unit_test { +namespace utils { // ************************************************************************** // // ************** custom manipulators helpers ************** // @@ -51,6 +52,7 @@ operator<<( std::ostream& ostr, custom_manip<Uniq> const& ) { return custom_prin //____________________________________________________________________________// +} // namespace utils } // namespace unit_test } // namespace boost diff --git a/boost/test/utils/fixed_mapping.hpp b/boost/test/utils/fixed_mapping.hpp deleted file mode 100644 index 299a77b789..0000000000 --- a/boost/test/utils/fixed_mapping.hpp +++ /dev/null @@ -1,120 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2001-2014. -// 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : fixed sized mapping with specified invalid value -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_FIXED_MAPPING_HPP -#define BOOST_TEST_UTILS_FIXED_MAPPING_HPP - -// Boost -#include <boost/preprocessor/repetition/repeat.hpp> -#include <boost/preprocessor/arithmetic/add.hpp> -#include <boost/call_traits.hpp> -#include <boost/detail/binary_search.hpp> - -// STL -#include <vector> -#include <functional> -#include <algorithm> -#include <utility> - -#include <boost/test/detail/suppress_warnings.hpp> - -//____________________________________________________________________________// - -namespace boost { -namespace unit_test { - -// configurable maximum fixed sized mapping size supported by this header. -// You can redefine it before inclusion of this file. -#ifndef MAX_MAP_SIZE -#define MAX_MAP_SIZE 20 -#endif - -#define CONSTR_DECL_MID( z, i, dummy1 ) key_param_type key##i, value_param_type v##i, -#define CONSTR_BODY_MID( z, i, dummy1 ) add_pair( key##i, v##i ); - -#define CONSTR_DECL( z, n, dummy1 ) \ - fixed_mapping( BOOST_PP_REPEAT_ ## z( n, CONSTR_DECL_MID, "" ) \ - value_param_type invalid_value ) \ - : m_invalid_value( invalid_value ) \ - { \ - BOOST_PP_REPEAT_ ## z( n, CONSTR_BODY_MID, "" ) \ - init(); \ - } \ -/**/ - -#define CONTRUCTORS( n ) BOOST_PP_REPEAT( n, CONSTR_DECL, "" ) - -template<typename Key, typename Value, typename Compare = std::less<Key> > -class fixed_mapping -{ - typedef std::pair<Key,Value> elem_type; - typedef std::vector<elem_type> map_type; - typedef typename std::vector<elem_type>::const_iterator iterator; - - typedef typename call_traits<Key>::param_type key_param_type; - typedef typename call_traits<Value>::param_type value_param_type; - typedef typename call_traits<Value>::const_reference value_ref_type; - -#if BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(60590042)) - struct p1; friend struct p1; - struct p2; friend struct p2; -#endif - - // bind( Compare(), bind(select1st<elem_type>(), _1), bind(identity<Key>(), _2) ) - struct p1 : public std::binary_function<elem_type,Key,bool> - { - bool operator()( elem_type const& x, Key const& y ) const { return Compare()( x.first, y ); } - }; - - // bind( Compare(), bind(select1st<elem_type>(), _1), bind(select1st<elem_type>(), _2) ) - struct p2 : public std::binary_function<elem_type,elem_type,bool> - { - bool operator()( elem_type const& x, elem_type const& y ) const { return Compare()( x.first, y.first ); } - }; - -public: - // Constructors - CONTRUCTORS( BOOST_PP_ADD( MAX_MAP_SIZE, 1 ) ) - - // key -> value access - value_ref_type operator[]( key_param_type key ) const - { - iterator it = boost::detail::lower_bound( m_map.begin(), m_map.end(), key, p1() ); - - return (it == m_map.end() || Compare()( key, it->first ) ) ? m_invalid_value : it->second; - } - -private: - // Implementation - void init() { std::sort( m_map.begin(), m_map.end(), p2() ); } - void add_pair( key_param_type key, value_param_type value ) { m_map.push_back( elem_type( key, value ) ); } - - // Data members - Value m_invalid_value; - map_type m_map; -}; - -} // namespace unit_test -} // namespace boost - -#include <boost/test/detail/enable_warnings.hpp> - -#undef MAX_MAP_SIZE -#undef CONSTR_DECL_MID -#undef CONSTR_BODY_MID -#undef CONSTR_DECL -#undef CONTRUCTORS - -#endif // BOOST_TEST_UTILS_FIXED_MAPPING_HPP - diff --git a/boost/test/utils/foreach.hpp b/boost/test/utils/foreach.hpp index d57b628cd3..68462ae719 100644 --- a/boost/test/utils/foreach.hpp +++ b/boost/test/utils/foreach.hpp @@ -1,5 +1,5 @@ // (C) Copyright Eric Niebler 2004-2005 -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) diff --git a/boost/test/utils/is_cstring.hpp b/boost/test/utils/is_cstring.hpp index 5172246c67..75af0f348d 100644 --- a/boost/test/utils/is_cstring.hpp +++ b/boost/test/utils/is_cstring.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2012-2014. +// (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) diff --git a/boost/test/utils/is_forward_iterable.hpp b/boost/test/utils/is_forward_iterable.hpp index 8b46b1b268..a7259b82c3 100644 --- a/boost/test/utils/is_forward_iterable.hpp +++ b/boost/test/utils/is_forward_iterable.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2012-2014. +// (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) @@ -12,10 +12,15 @@ #ifndef BOOST_TEST_UTILS_IS_FORWARD_ITERABLE_HPP #define BOOST_TEST_UTILS_IS_FORWARD_ITERABLE_HPP -#if defined(BOOST_NO_CXX11_DECLTYPE) || defined(BOOST_NO_CXX11_NULLPTR) || defined(BOOST_NO_CXX11_TRAILING_RESULT_TYPES) - #define BOOST_TEST_FWD_ITERABLE_CXX03 -#endif +#if defined(BOOST_NO_CXX11_DECLTYPE) || \ + defined(BOOST_NO_CXX11_NULLPTR) || \ + defined(BOOST_NO_CXX11_TRAILING_RESULT_TYPES) + // some issues with boost.config + #if !defined(BOOST_MSVC) || BOOST_MSVC_FULL_VER < 170061030 /* VC2012 upd 5 */ + #define BOOST_TEST_FWD_ITERABLE_CXX03 + #endif +#endif #if defined(BOOST_TEST_FWD_ITERABLE_CXX03) // Boost @@ -76,72 +81,81 @@ struct is_forward_iterable< std::set<K, C, A> > : public mpl::true_ {}; namespace ut_detail { - template<typename T> - struct is_present : public mpl::true_ {}; +template<typename T> +struct is_present : public mpl::true_ {}; + +//____________________________________________________________________________// - // some compiler do not implement properly decltype non expression involving members (eg. VS2013) - // a workaround is to use -> decltype syntax. - template <class T> - struct has_member_size { - private: +// some compiler do not implement properly decltype non expression involving members (eg. VS2013) +// a workaround is to use -> decltype syntax. +template <class T> +struct has_member_size { +private: struct nil_t {}; - template<typename U> static auto test(U*) -> decltype( boost::declval<U>().size() ); - template<typename> static nil_t test(...); + template<typename U> static auto test( U* ) -> decltype(boost::declval<U>().size()); + template<typename> static nil_t test( ... ); + +public: + static bool const value = !std::is_same< decltype(test<T>( nullptr )), nil_t>::value; +}; - public: - static bool const value = !std::is_same< decltype(test<T>(nullptr)), nil_t>::value; - }; +//____________________________________________________________________________// - template <class T> - struct has_member_begin { - private: +template <class T> +struct has_member_begin { +private: struct nil_t {}; - template<typename U> static auto test(U*) -> decltype( boost::declval<U>().begin() ); - template<typename> static nil_t test(...); - public: - static bool const value = !std::is_same< decltype(test<T>(nullptr)), nil_t>::value; - }; - - template <class T> - struct has_member_end { - private: + template<typename U> static auto test( U* ) -> decltype(boost::declval<U>().begin()); + template<typename> static nil_t test( ... ); +public: + static bool const value = !std::is_same< decltype(test<T>( nullptr )), nil_t>::value; +}; + +//____________________________________________________________________________// + +template <class T> +struct has_member_end { +private: struct nil_t {}; - template<typename U> static auto test(U*) -> decltype( boost::declval<U>().end() ); - template<typename> static nil_t test(...); - public: - static bool const value = !std::is_same< decltype(test<T>(nullptr)), nil_t>::value; - }; - - template <class T, class enabled = void> - struct is_forward_iterable_impl : std::false_type - {}; - - template <class T> - struct is_forward_iterable_impl< + template<typename U> static auto test( U* ) -> decltype(boost::declval<U>().end()); + template<typename> static nil_t test( ... ); +public: + static bool const value = !std::is_same< decltype(test<T>( nullptr )), nil_t>::value; +}; + +//____________________________________________________________________________// + +template <class T, class enabled = void> +struct is_forward_iterable_impl : std::false_type { +}; + +//____________________________________________________________________________// + +template <class T> +struct is_forward_iterable_impl< T, typename std::enable_if< - is_present<typename T::const_iterator>::value && - is_present<typename T::value_type>::value && - has_member_size<T>::value && - has_member_begin<T>::value && - has_member_end<T>::value && - !is_cstring<T>::value - >::type - > : std::true_type - {}; + is_present<typename T::const_iterator>::value && + is_present<typename T::value_type>::value && + has_member_size<T>::value && + has_member_begin<T>::value && + has_member_end<T>::value && + !is_cstring<T>::value + >::type +> : std::true_type +{}; +//____________________________________________________________________________// } // namespace ut_detail - -/*! Indicates that a specific type implements the forward iterable concept. - */ -template<typename T> -struct is_forward_iterable { - typedef typename std::remove_reference<T>::type T_ref; - typedef ut_detail::is_forward_iterable_impl<T_ref> is_fwd_it_t; - typedef mpl::bool_<is_fwd_it_t::value> type; - enum { value = is_fwd_it_t::value }; +/*! Indicates that a specific type implements the forward iterable concept. */ +template<typename T> +struct is_forward_iterable { + typedef typename std::remove_reference<T>::type T_ref; + typedef ut_detail::is_forward_iterable_impl<T_ref> is_fwd_it_t; + typedef mpl::bool_<is_fwd_it_t::value> type; + enum { value = is_fwd_it_t::value }; }; #endif /* defined(BOOST_TEST_FWD_ITERABLE_CXX03) */ diff --git a/boost/test/utils/iterator/ifstream_line_iterator.hpp b/boost/test/utils/iterator/ifstream_line_iterator.hpp deleted file mode 100644 index 9a2154828c..0000000000 --- a/boost/test/utils/iterator/ifstream_line_iterator.hpp +++ /dev/null @@ -1,105 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2004-2014. -// 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_IFSTREAM_LINE_ITERATOR_HPP -#define BOOST_TEST_UTILS_IFSTREAM_LINE_ITERATOR_HPP - -// Boost -#include <boost/test/utils/iterator/istream_line_iterator.hpp> - -// STL -#include <fstream> - -#include <boost/test/detail/suppress_warnings.hpp> - -//____________________________________________________________________________// - -namespace boost { - -namespace unit_test { - -namespace ut_detail { - -// ************************************************************************** // -// ************** ifstream_holder ************** // -// ************************************************************************** // - -template<typename CharT> -class ifstream_holder { -public: - // Constructor - explicit ifstream_holder( basic_cstring<CharT const> file_name ) - { - if( file_name.is_empty() ) - return; - - m_stream.open( file_name.begin(), std::ios::in ); - } - - bool is_valid() - { - return m_stream.is_open(); - } - -protected: -#ifdef BOOST_CLASSIC_IOSTREAMS - typedef std::ifstream stream_t; -#else - typedef std::basic_ifstream<CharT,std::char_traits<CharT> > stream_t; -#endif - - // Data members - stream_t m_stream; -}; - -} // namespace ut_detail - -// ************************************************************************** // -// ************** basic_ifstream_line_iterator ************** // -// ************************************************************************** // - -#ifdef BOOST_MSVC -# pragma warning(push) -# pragma warning(disable: 4355) // 'this' : used in base member initializer list -#endif - -template<typename CharT> -class basic_ifstream_line_iterator : ut_detail::ifstream_holder<CharT>, public basic_istream_line_iterator<CharT> -{ -public: - basic_ifstream_line_iterator( basic_cstring<CharT const> file_name, CharT delimeter ) - : ut_detail::ifstream_holder<CharT>( file_name ), basic_istream_line_iterator<CharT>( this->m_stream, delimeter ) {} - - explicit basic_ifstream_line_iterator( basic_cstring<CharT const> file_name = basic_cstring<CharT const>() ) - : ut_detail::ifstream_holder<CharT>( file_name ), basic_istream_line_iterator<CharT>( this->m_stream ) {} -}; - -#ifdef BOOST_MSVC -# pragma warning(default: 4355) -# pragma warning(pop) -#endif - -typedef basic_ifstream_line_iterator<char> ifstream_line_iterator; -typedef basic_ifstream_line_iterator<wchar_t> wifstream_line_iterator; - -} // namespace unit_test - -} // namespace boost - -//____________________________________________________________________________// - -#include <boost/test/detail/enable_warnings.hpp> - -#endif // BOOST_TEST_UTILS_IFSTREAM_LINE_ITERATOR_HPP - diff --git a/boost/test/utils/iterator/input_iterator_facade.hpp b/boost/test/utils/iterator/input_iterator_facade.hpp index a160808971..d695ee3a87 100644 --- a/boost/test/utils/iterator/input_iterator_facade.hpp +++ b/boost/test/utils/iterator/input_iterator_facade.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2004-2014. +// (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) @@ -20,8 +20,8 @@ //____________________________________________________________________________// namespace boost { - namespace unit_test { +namespace utils { // ************************************************************************** // // ************** input_iterator_core_access ************** // @@ -94,8 +94,8 @@ private: } }; +} // namespace utils } // namespace unit_test - } // namespace boost //____________________________________________________________________________// @@ -103,4 +103,3 @@ private: #include <boost/test/detail/enable_warnings.hpp> #endif // BOOST_TEST_UTILS_INPUT_ITERATOR_FACADE_HPP - diff --git a/boost/test/utils/iterator/istream_line_iterator.hpp b/boost/test/utils/iterator/istream_line_iterator.hpp deleted file mode 100644 index f75be9ca77..0000000000 --- a/boost/test/utils/iterator/istream_line_iterator.hpp +++ /dev/null @@ -1,93 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2004-2014. -// 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_ISTREAM_LINE_ITERATOR_HPP -#define BOOST_TEST_UTILS_ISTREAM_LINE_ITERATOR_HPP - -// Boost -#include <boost/test/utils/basic_cstring/basic_cstring.hpp> -#include <boost/test/utils/iterator/input_iterator_facade.hpp> - -// STL -#include <iosfwd> - -#include <boost/test/detail/suppress_warnings.hpp> - -//____________________________________________________________________________// - -namespace boost { - -namespace unit_test { - -// ************************************************************************** // -// ************** basic_istream_line_iterator ************** // -// ************************************************************************** // - -// !! Should we support policy based delimitation - -template<typename CharT> -class basic_istream_line_iterator -: public input_iterator_facade<basic_istream_line_iterator<CharT>, - std::basic_string<CharT>, - basic_cstring<CharT const> > { - typedef input_iterator_facade<basic_istream_line_iterator<CharT>, - std::basic_string<CharT>, - basic_cstring<CharT const> > base; -#ifdef BOOST_CLASSIC_IOSTREAMS - typedef std::istream istream_type; -#else - typedef std::basic_istream<CharT> istream_type; -#endif -public: - // Constructors - basic_istream_line_iterator() {} - basic_istream_line_iterator( istream_type& input, CharT delimeter ) - : m_input_stream( &input ), m_delimeter( delimeter ) - { - this->init(); - } - explicit basic_istream_line_iterator( istream_type& input ) - : m_input_stream( &input ) - , m_delimeter( input.widen( '\n' ) ) - { - this->init(); - } - -private: - friend class input_iterator_core_access; - - // increment implementation - bool get() - { - return !!std::getline( *m_input_stream, this->m_value, m_delimeter ); - } - - // Data members - istream_type* m_input_stream; - CharT m_delimeter; -}; - -typedef basic_istream_line_iterator<char> istream_line_iterator; -typedef basic_istream_line_iterator<wchar_t> wistream_line_iterator; - -} // namespace unit_test - -} // namespace boost - -//____________________________________________________________________________// - -#include <boost/test/detail/enable_warnings.hpp> - -#endif // BOOST_TEST_UTILS_ISTREAM_LINE_ITERATOR_HPP - diff --git a/boost/test/utils/iterator/token_iterator.hpp b/boost/test/utils/iterator/token_iterator.hpp index c41f071739..abc530041d 100644 --- a/boost/test/utils/iterator/token_iterator.hpp +++ b/boost/test/utils/iterator/token_iterator.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2004-2014. +// (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) @@ -40,8 +40,8 @@ namespace std{ using ::ispunct; using ::isspace; } #endif namespace boost { - namespace unit_test { +namespace utils { // ************************************************************************** // // ************** ti_delimeter_type ************** // @@ -82,22 +82,21 @@ class delim_policy { typedef basic_cstring<CharT const> cstring; public: // Constructor - explicit delim_policy( ti_delimeter_type t = dt_char, cstring d = cstring() ) - : m_type( t ) + explicit delim_policy( ti_delimeter_type type_ = dt_char, cstring delimeters_ = cstring() ) + : m_type( type_ ) { - set_delimeters( d ); + set_delimeters( delimeters_ ); } - void set_delimeters( ti_delimeter_type t ) { m_type = t; } - template<typename Src> - void set_delimeters( Src d ) + void set_delimeters( ti_delimeter_type type_ ) { m_type = type_; } + void set_delimeters( cstring delimeters_ ) { - nfp::optionally_assign( m_delimeters, d ); + m_delimeters = delimeters_; if( !m_delimeters.is_empty() ) m_type = dt_char; } - + void set_delimeters( nfp::nil ) {} bool operator()( CharT c ) { switch( m_type ) { @@ -210,7 +209,7 @@ protected: if( m.has( keep_empty_tokens ) ) m_keep_empty_tokens = true; - nfp::optionally_assign( m_tokens_left, m, max_tokens ); + nfp::opt_assign( m_tokens_left, m, max_tokens ); } template<typename Iter> @@ -406,8 +405,8 @@ make_range_token_iterator( Iter begin, Iter end, Modifier const& m ) //____________________________________________________________________________// +} // namespace utils } // namespace unit_test - } // namespace boost //____________________________________________________________________________// diff --git a/boost/test/utils/lazy_ostream.hpp b/boost/test/utils/lazy_ostream.hpp index 8aef34133b..26bd8ed385 100644 --- a/boost/test/utils/lazy_ostream.hpp +++ b/boost/test/utils/lazy_ostream.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2008-2014. +// (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) @@ -123,8 +123,6 @@ operator<<( lazy_ostream_impl<PrevPrevType,TPrev> const& prev, R& (BOOST_TEST_CA } // namespace unit_test } // namespace boost -//____________________________________________________________________________// - #include <boost/test/detail/enable_warnings.hpp> #endif // BOOST_TEST_UTILS_LAZY_OSTREAM_HPP diff --git a/boost/test/utils/named_params.hpp b/boost/test/utils/named_params.hpp index 0e66dc39c5..ebd5a6a751 100644 --- a/boost/test/utils/named_params.hpp +++ b/boost/test/utils/named_params.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) @@ -9,7 +9,7 @@ // // Version : $Revision$ // -// Description : facilities for named function parameters support +// Description : named function parameters library // *************************************************************************** #ifndef BOOST_TEST_UTILS_NAMED_PARAM @@ -18,7 +18,6 @@ // Boost #include <boost/config.hpp> #include <boost/detail/workaround.hpp> -#include <boost/mpl/bool.hpp> // Boost.Test #include <boost/test/utils/rtti.hpp> @@ -29,6 +28,14 @@ #include <boost/test/detail/throw_exception.hpp> +// Boost +#include <boost/mpl/if.hpp> +#include <boost/mpl/or.hpp> +#include <boost/type_traits/is_same.hpp> +#include <boost/type_traits/remove_cv.hpp> +#include <boost/utility/enable_if.hpp> +#include <boost/mpl/bool.hpp> + #include <boost/test/detail/suppress_warnings.hpp> //____________________________________________________________________________// @@ -40,29 +47,78 @@ namespace nfp { // named function parameters // ************** forward declarations ************** // // ************************************************************************** // -template<typename T, typename unique_id,typename RefType> struct named_parameter; -template<typename unique_id,bool required> struct keyword; +template<typename unique_id, bool required> struct keyword; +template<typename T, typename unique_id, bool required = false> struct typed_keyword; -namespace nfp_detail { +template<typename T, typename unique_id, typename RefType=T&> struct named_parameter; +template<typename NP1,typename NP2> struct named_parameter_combine; + +// ************************************************************************** // +// ************** is_named_param_pack ************** // +// ************************************************************************** // + +/// is_named_param_pack<T>::value is true if T is parameters pack + +template<typename T> +struct is_named_param_pack : public mpl::false_ {}; + +template<typename T, typename unique_id, typename RefType> +struct is_named_param_pack<named_parameter<T,unique_id,RefType> > : public mpl::true_ {}; -template<typename NP1,typename NP2> struct named_parameter_combine; +template<typename NP, typename Rest> +struct is_named_param_pack<named_parameter_combine<NP,Rest> > : public mpl::true_ {}; + +// ************************************************************************** // +// ************** param_type ************** // +// ************************************************************************** // + +/// param_type<Params,Keyword,Default>::type is is the type of the parameter +/// corresponding to the Keyword (if parameter is present) or Default + +template<typename NP, typename Keyword, typename DefaultType=void> +struct param_type +: mpl::if_<typename is_same<typename NP::id,typename Keyword::id>::type, + typename remove_cv<typename NP::data_type>::type, + DefaultType> {}; + +template<typename NP, typename Rest, typename Keyword, typename DefaultType> +struct param_type<named_parameter_combine<NP,Rest>,Keyword,DefaultType> +: mpl::if_<typename is_same<typename NP::id,typename Keyword::id>::type, + typename remove_cv<typename NP::data_type>::type, + typename param_type<Rest,Keyword,DefaultType>::type> {}; + +// ************************************************************************** // +// ************** has_param ************** // +// ************************************************************************** // + +/// has_param<Params,Keyword>::value is true id Params has parameter corresponding +/// to the Keyword + +template<typename NP, typename Keyword> +struct has_param : is_same<typename NP::id,typename Keyword::id> {}; + +template<typename NP, typename Rest, typename Keyword> +struct has_param<named_parameter_combine<NP,Rest>,Keyword> +: mpl::or_<typename is_same<typename NP::id,typename Keyword::id>::type, + typename has_param<Rest,Keyword>::type> {}; // ************************************************************************** // // ************** access_to_invalid_parameter ************** // // ************************************************************************** // +namespace nfp_detail { + struct access_to_invalid_parameter {}; //____________________________________________________________________________// inline void -report_access_to_invalid_parameter(bool v) +report_access_to_invalid_parameter( bool v ) { - if(v) - BOOST_TEST_IMPL_THROW( access_to_invalid_parameter() ); + BOOST_TEST_I_ASSRT( !v, access_to_invalid_parameter() ); } -//____________________________________________________________________________// +} // namespace nfp_detail // ************************************************************************** // // ************** nil ************** // @@ -75,23 +131,23 @@ struct nil { #else operator T const&() const #endif - { report_access_to_invalid_parameter(true); static T* v = 0; return *v; } + { nfp_detail::report_access_to_invalid_parameter(true); static T* v = 0; return *v; } template<typename T> T any_cast() const - { report_access_to_invalid_parameter(true); static typename remove_reference<T>::type* v = 0; return *v; } + { nfp_detail::report_access_to_invalid_parameter(true); static typename remove_reference<T>::type* v = 0; return *v; } template<typename Arg1> nil operator()( Arg1 const& ) - { report_access_to_invalid_parameter(true); return nil(); } + { nfp_detail::report_access_to_invalid_parameter(true); return nil(); } template<typename Arg1,typename Arg2> nil operator()( Arg1 const&, Arg2 const& ) - { report_access_to_invalid_parameter(true); return nil(); } + { nfp_detail::report_access_to_invalid_parameter(true); return nil(); } template<typename Arg1,typename Arg2,typename Arg3> nil operator()( Arg1 const&, Arg2 const&, Arg3 const& ) - { report_access_to_invalid_parameter(true); return nil(); } + { nfp_detail::report_access_to_invalid_parameter(true); return nil(); } // Visitation support template<typename Visitor> @@ -106,6 +162,8 @@ private: // ************** named_parameter_base ************** // // ************************************************************************** // +namespace nfp_detail { + template<typename Derived> struct named_parameter_base { template<typename NP> @@ -113,7 +171,7 @@ struct named_parameter_base { operator,( NP const& np ) const { return named_parameter_combine<NP,Derived>( np, *static_cast<Derived const*>(this) ); } }; -//____________________________________________________________________________// +} // namespace nfp_detail // ************************************************************************** // // ************** named_parameter_combine ************** // @@ -122,7 +180,7 @@ struct named_parameter_base { template<typename NP, typename Rest = nil> struct named_parameter_combine : Rest -, named_parameter_base<named_parameter_combine<NP,Rest> > { +, nfp_detail::named_parameter_base<named_parameter_combine<NP,Rest> > { typedef typename NP::ref_type res_type; typedef named_parameter_combine<NP,Rest> self_type; @@ -130,7 +188,8 @@ struct named_parameter_combine named_parameter_combine( NP const& np, Rest const& r ) : Rest( r ) , m_param( np ) - {} + { + } // Access methods res_type operator[]( keyword<typename NP::id,true> kw ) const { return m_param[kw]; } @@ -143,14 +202,7 @@ struct named_parameter_combine void erase( keyword<typename NP::id,false> kw ) const { m_param.erase( kw ); } using Rest::erase; -#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206)) || \ - BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0610)) - template<typename NP> - named_parameter_combine<NP,self_type> operator,( NP const& np ) const - { return named_parameter_combine<NP,self_type>( np, *this ); } -#else - using named_parameter_base<named_parameter_combine<NP,Rest> >::operator,; -#endif + using nfp_detail::named_parameter_base<named_parameter_combine<NP,Rest> >::operator,; // Visitation support template<typename Visitor> @@ -165,19 +217,16 @@ private: NP m_param; }; -} // namespace nfp_detail - // ************************************************************************** // // ************** named_parameter ************** // // ************************************************************************** // -template<typename T, typename unique_id, typename ReferenceType=T&> +template<typename T, typename unique_id, typename RefType> struct named_parameter -: nfp_detail::named_parameter_base<named_parameter<T, unique_id,ReferenceType> > +: nfp_detail::named_parameter_base<named_parameter<T,unique_id,RefType> > { - typedef nfp_detail::nil nil_t; typedef T data_type; - typedef ReferenceType ref_type; + typedef RefType ref_type; typedef unique_id id; // Constructor @@ -191,10 +240,10 @@ struct named_parameter {} // Access methods - ref_type operator[]( keyword<unique_id,true> ) const { return m_erased ? nil_t::inst().template any_cast<ref_type>() : m_value; } - ref_type operator[]( keyword<unique_id,false> ) const { return m_erased ? nil_t::inst().template any_cast<ref_type>() : m_value; } + ref_type operator[]( keyword<unique_id,true> ) const { return m_erased ? nil::inst().template any_cast<ref_type>() : m_value; } + ref_type operator[]( keyword<unique_id,false> ) const { return m_erased ? nil::inst().template any_cast<ref_type>() : m_value; } template<typename UnknownId> - nil_t operator[]( keyword<UnknownId,false> ) const { return nil_t::inst(); } + nil operator[]( keyword<UnknownId,false> ) const { return nil::inst(); } bool has( keyword<unique_id,false> ) const { return !m_erased; } template<typename UnknownId> @@ -217,22 +266,16 @@ private: mutable bool m_erased; }; -//____________________________________________________________________________// - // ************************************************************************** // // ************** no_params ************** // // ************************************************************************** // -namespace nfp_detail { typedef named_parameter<char, struct no_params_type_t,char> no_params_type; -} // namespace nfp_detail namespace { -nfp_detail::no_params_type no_params( '\0' ); +no_params_type no_params( '\0' ); } // local namespace -//____________________________________________________________________________// - // ************************************************************************** // // ************** keyword ************** // // ************************************************************************** // @@ -247,10 +290,10 @@ struct keyword { template<typename T> named_parameter<T,unique_id> - operator=( T& t ) const { return named_parameter<T,unique_id>( t ); } + operator=( T& t ) const { return named_parameter<T,unique_id>( t ); } named_parameter<char const*,unique_id,char const*> - operator=( char const* t ) const { return named_parameter<char const*,unique_id,char const*>( t ); } + operator=( char const* t ) const { return named_parameter<char const*,unique_id,char const*>( t ); } }; //____________________________________________________________________________// @@ -259,7 +302,7 @@ struct keyword { // ************** typed_keyword ************** // // ************************************************************************** // -template<typename T, typename unique_id, bool required = false> +template<typename T, typename unique_id, bool required> struct typed_keyword : keyword<unique_id,required> { named_parameter<T const,unique_id> operator=( T const& t ) const { return named_parameter<T const,unique_id>( t ); } @@ -270,9 +313,9 @@ struct typed_keyword : keyword<unique_id,required> { //____________________________________________________________________________// -template<typename unique_id> -struct typed_keyword<bool,unique_id,false> -: keyword<unique_id,false> +template<typename unique_id, bool required> +struct typed_keyword<bool,unique_id,required> +: keyword<unique_id,required> , named_parameter<bool,unique_id,bool> { typedef unique_id id; @@ -282,84 +325,60 @@ struct typed_keyword<bool,unique_id,false> operator!() const { return named_parameter<bool,unique_id,bool>( false ); } }; -//____________________________________________________________________________// - // ************************************************************************** // -// ************** optionally_assign ************** // +// ************** opt_assign ************** // // ************************************************************************** // -template<typename T> -inline void -optionally_assign( T&, nfp_detail::nil ) +template<typename T, typename Params, typename Keyword> +inline typename enable_if_c<!has_param<Params,Keyword>::value,void>::type +opt_assign( T& target, Params const& p, Keyword k ) { - nfp_detail::report_access_to_invalid_parameter(true); } //____________________________________________________________________________// -template<typename T, typename Source> -inline void -#if BOOST_WORKAROUND( __MWERKS__, BOOST_TESTED_AT( 0x3003 ) ) \ - || BOOST_WORKAROUND( __DECCXX_VER, BOOST_TESTED_AT(60590042) ) -optionally_assign( T& target, Source src ) -#else -optionally_assign( T& target, Source const& src ) -#endif +template<typename T, typename Params, typename Keyword> +inline typename enable_if_c<has_param<Params,Keyword>::value,void>::type +opt_assign( T& target, Params const& p, Keyword k ) { using namespace unit_test; - assign_op( target, src, static_cast<int>(0) ); + assign_op( target, p[k], static_cast<int>(0) ); } -//____________________________________________________________________________// - -template<typename T, typename Params, typename Keyword> -inline void -optionally_assign( T& target, Params const& p, Keyword k ) -{ - if( p.has(k) ) - optionally_assign( target, p[k] ); -} - -//____________________________________________________________________________// - // ************************************************************************** // -// ************** is_named_params ************** // +// ************** opt_get ************** // // ************************************************************************** // -template<typename T> -struct is_named_params : public boost::mpl::false_ {}; - -template<typename T, typename unique_id, typename ReferenceType> -struct is_named_params<named_parameter<T,unique_id,ReferenceType> > : public boost::mpl::true_ {}; +template<typename T, typename Params, typename Keyword> +inline T +opt_get( Params const& p, Keyword k, T default_val ) +{ + opt_assign( default_val, p, k ); -template<typename NP, typename Rest> -struct is_named_params<nfp_detail::named_parameter_combine<NP,Rest> > : public boost::mpl::true_ {}; + return default_val; +} // ************************************************************************** // -// ************** param_type ************** // +// ************** opt_get ************** // // ************************************************************************** // -template<typename Params,typename KeywordType,typename DefaultType=void> -struct param_type { - typedef DefaultType type; -}; - -template<typename NP,typename Rest,typename Keyword,typename DefaultType> -struct param_type<nfp_detail::named_parameter_combine<NP,Rest>,Keyword,DefaultType> : param_type<Rest,Keyword,DefaultType> { -}; +template<typename Params, typename NP> +inline typename enable_if_c<!has_param<Params,keyword<typename NP::id> >::value, +named_parameter_combine<NP,Params> >::type +opt_append( Params const& params, NP const& np ) +{ + return (params,np); +} -template<typename T, typename unique_id, typename ReferenceType,bool required,typename DefaultType> -struct param_type<named_parameter<T,unique_id,ReferenceType>,keyword<unique_id,required>,DefaultType> { - typedef typename boost::remove_cv<T>::type type; -}; +//____________________________________________________________________________// -template<typename T, typename unique_id, typename ReferenceType,typename Rest,bool required,typename DefaultType> -struct param_type<nfp_detail::named_parameter_combine<named_parameter<T,unique_id,ReferenceType>,Rest>, - keyword<unique_id,required>, - DefaultType> { - typedef typename boost::remove_cv<T>::type type; -}; +template<typename Params, typename NP> +inline typename enable_if_c<has_param<Params,keyword<typename NP::id> >::value,Params>::type +opt_append( Params const& params, NP const& ) +{ + return params; +} } // namespace nfp } // namespace boost @@ -367,4 +386,3 @@ struct param_type<nfp_detail::named_parameter_combine<named_parameter<T,unique_i #include <boost/test/detail/enable_warnings.hpp> #endif // BOOST_TEST_UTILS_NAMED_PARAM - diff --git a/boost/test/utils/nullstream.hpp b/boost/test/utils/nullstream.hpp index b4cedd0842..27b17fae14 100644 --- a/boost/test/utils/nullstream.hpp +++ b/boost/test/utils/nullstream.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2002-2014. +// (C) Copyright Gennadiy Rozental 2001. // (C) Copyright Daryle Walker 2000-2001. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at diff --git a/boost/test/utils/rtti.hpp b/boost/test/utils/rtti.hpp index 42f2bc648b..b230692d80 100644 --- a/boost/test/utils/rtti.hpp +++ b/boost/test/utils/rtti.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) @@ -36,7 +36,7 @@ struct rttid_holder { private: struct rttid {}; - static rttid const& inst() { static rttid s_inst; return s_inst; } + static rttid const& inst() { static rttid s_inst; return s_inst; } }; } // namespace rtti_detail diff --git a/boost/test/utils/runtime/argument.hpp b/boost/test/utils/runtime/argument.hpp index b5133e23c3..879ee96f9f 100644 --- a/boost/test/utils/runtime/argument.hpp +++ b/boost/test/utils/runtime/argument.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) @@ -15,45 +15,40 @@ #ifndef BOOST_TEST_UTILS_RUNTIME_ARGUMENT_HPP #define BOOST_TEST_UTILS_RUNTIME_ARGUMENT_HPP -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> +// Boost.Test Runtime parameters #include <boost/test/utils/runtime/fwd.hpp> -#include <boost/test/utils/runtime/validation.hpp> +#include <boost/test/utils/runtime/errors.hpp> // Boost.Test #include <boost/test/utils/class_properties.hpp> #include <boost/test/utils/rtti.hpp> +#include <boost/test/utils/basic_cstring/compare.hpp> +#include <boost/test/detail/throw_exception.hpp> // STL #include <cassert> -namespace boost { +#include <boost/test/detail/suppress_warnings.hpp> -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { +namespace boost { +namespace runtime { // ************************************************************************** // // ************** runtime::argument ************** // // ************************************************************************** // -#ifdef BOOST_MSVC -# pragma warning(push) -# pragma warning(disable:4244) -#endif - class argument { public: // Constructor - argument( parameter const& p, rtti::id_t value_type ) - : p_formal_parameter( p ) - , p_value_type( value_type ) + argument( rtti::id_t value_type ) + : p_value_type( value_type ) {} // Destructor virtual ~argument() {} // Public properties - unit_test::readonly_property<parameter const&> p_formal_parameter; - unit_test::readonly_property<rtti::id_t> p_value_type; + rtti::id_t const p_value_type; }; // ************************************************************************** // @@ -64,49 +59,73 @@ template<typename T> class typed_argument : public argument { public: // Constructor - explicit typed_argument( parameter const& p ) - : argument( p, rtti::type_id<T>() ) - {} - typed_argument( parameter const& p, T const& t ) - : argument( p, rtti::type_id<T>() ) - , p_value( t ) + explicit typed_argument( T const& v ) + : argument( rtti::type_id<T>() ) + , p_value( v ) {} unit_test::readwrite_property<T> p_value; }; // ************************************************************************** // -// ************** runtime::arg_value ************** // +// ************** runtime::arguments_store ************** // // ************************************************************************** // -template<typename T> -inline T const& -arg_value( argument const& arg_ ) -{ - assert( arg_.p_value_type == rtti::type_id<T>() ); // detect logic error - - return static_cast<typed_argument<T> const&>( arg_ ).p_value.value; -} - -//____________________________________________________________________________// - -template<typename T> -inline T& -arg_value( argument& arg_ ) -{ - assert( arg_.p_value_type == rtti::type_id<T>() ); // detect logic error - - return static_cast<typed_argument<T>&>( arg_ ).p_value.value; -} - -#ifdef BOOST_MSVC -# pragma warning(pop) -#endif - -//____________________________________________________________________________// - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE +class arguments_store { +public: + typedef std::map<cstring, argument_ptr> storage_type; + + /// Returns number of arguments in the store; mostly used for testing + std::size_t size() const { return m_arguments.size(); } + + /// Clears the store for reuse + void clear() { m_arguments.clear(); } + + /// Returns true if there is an argument corresponding to the specified parameter name + bool has( cstring parameter_name ) const + { + return m_arguments.find( parameter_name ) != m_arguments.end(); + } + + /// Provides types access to argument value by parameter name + template<typename T> + T const& get( cstring parameter_name ) const { + return const_cast<arguments_store*>(this)->get<T>( parameter_name ); + } + + template<typename T> + T& get( cstring parameter_name ) { + storage_type::const_iterator found = m_arguments.find( parameter_name ); + BOOST_TEST_I_ASSRT( found != m_arguments.end(), + access_to_missing_argument() + << "There is no argument provided for parameter " + << parameter_name ); + + argument_ptr arg = found->second; + + BOOST_TEST_I_ASSRT( arg->p_value_type == rtti::type_id<T>(), + arg_type_mismatch() + << "Access with invalid type for argument corresponding to parameter " + << parameter_name ); + + return static_cast<typed_argument<T>&>( *arg ).p_value.value; + } + + /// Set's the argument value for specified parameter name + template<typename T> + void set( cstring parameter_name, T const& value ) + { + m_arguments[parameter_name] = argument_ptr( new typed_argument<T>( value ) ); + } + +private: + // Data members + storage_type m_arguments; +}; +} // namespace runtime } // namespace boost +#include <boost/test/detail/enable_warnings.hpp> + #endif // BOOST_TEST_UTILS_RUNTIME_ARGUMENT_HPP diff --git a/boost/test/utils/runtime/argument_factory.hpp b/boost/test/utils/runtime/argument_factory.hpp new file mode 100644 index 0000000000..a163deb9a2 --- /dev/null +++ b/boost/test/utils/runtime/argument_factory.hpp @@ -0,0 +1,242 @@ +// (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 : $RCSfile$ +// +// Version : $Revision$ +// +// Description : argument factories for different kinds of parameters +// *************************************************************************** + +#ifndef BOOST_TEST_UTILS_RUNTIME_ARGUMENT_FACTORY_HPP +#define BOOST_TEST_UTILS_RUNTIME_ARGUMENT_FACTORY_HPP + +// Boost.Test Runtime parameters +#include <boost/test/utils/runtime/errors.hpp> +#include <boost/test/utils/runtime/argument.hpp> + +// Boost.Test +#include <boost/test/utils/basic_cstring/io.hpp> +#include <boost/test/utils/basic_cstring/compare.hpp> +#include <boost/test/utils/string_cast.hpp> + +// Boost +#include <boost/function/function2.hpp> + +// STL +#include <vector> + +#include <boost/test/detail/suppress_warnings.hpp> + +namespace boost { +namespace runtime { + +// ************************************************************************** // +// ************** runtime::value_interpreter ************** // +// ************************************************************************** // + +template<typename ValueType, bool is_enum> +struct value_interpreter; + +//____________________________________________________________________________// + +template<typename ValueType> +struct value_interpreter<ValueType, false> { + template<typename Modifiers> + explicit value_interpreter( Modifiers const& ) {} + + ValueType interpret( cstring param_name, cstring source ) const + { + ValueType res; + if( !unit_test::utils::string_as<ValueType>( source, res ) ) + BOOST_TEST_I_THROW( format_error( param_name ) << source << + " can't be interpreted as value of parameter " << param_name << "." ); + return res; + } +}; + +//____________________________________________________________________________// + +template<> +struct value_interpreter<std::string, false> { + template<typename Modifiers> + explicit value_interpreter( Modifiers const& ) {} + + std::string interpret( cstring, cstring source ) const + { + return std::string( source.begin(), source.size() ); + } +}; + +//____________________________________________________________________________// + +template<> +struct value_interpreter<cstring, false> { + template<typename Modifiers> + explicit value_interpreter( Modifiers const& ) {} + + cstring interpret( cstring, cstring source ) const + { + return source; + } +}; + +//____________________________________________________________________________// + +template<> +struct value_interpreter<bool, false> { + template<typename Modifiers> + explicit value_interpreter( Modifiers const& ) {} + + bool interpret( cstring param_name, cstring source ) const + { + static cstring const s_YES( "YES" ); + static cstring const s_Y( "Y" ); + static cstring const s_NO( "NO" ); + static cstring const s_N( "N" ); + static cstring const s_TRUE( "TRUE" ); + static cstring const s_FALSE( "FALSE" ); + static cstring const s_one( "1" ); + static cstring const s_zero( "0" ); + + source.trim(); + + if( source.is_empty() || + case_ins_eq( source, s_YES ) || + case_ins_eq( source, s_Y ) || + case_ins_eq( source, s_one ) || + case_ins_eq( source, s_TRUE ) ) + return true; + + if( case_ins_eq( source, s_NO ) || + case_ins_eq( source, s_N ) || + case_ins_eq( source, s_zero ) || + case_ins_eq( source, s_FALSE ) ) + return false; + + BOOST_TEST_I_THROW( format_error( param_name ) << source << " can't be interpreted as bool value." ); + } +}; + +//____________________________________________________________________________// + +template<typename EnumType> +struct value_interpreter<EnumType, true> { + template<typename Modifiers> + explicit value_interpreter( Modifiers const& m ) +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) + : m_name_to_value( m[enum_values<EnumType>::value] ) + { + } +#else + { + std::vector<std::pair<cstring,EnumType> > const& values = m[enum_values<EnumType>::value]; + + m_name_to_value.insert( values.begin(), values.end() ); + } +#endif + + EnumType interpret( cstring param_name, cstring source ) const + { + typename std::map<cstring,EnumType>::const_iterator found = m_name_to_value.find( source ); + + BOOST_TEST_I_ASSRT( found != m_name_to_value.end(), + format_error( param_name ) << source << + " is not a valid enumeration value name for parameter " << param_name << "." ); + + return found->second; + } + +private: + // Data members + std::map<cstring,EnumType> m_name_to_value; +}; + +//____________________________________________________________________________// + +// ************************************************************************** // +// ************** runtime::argument_factory ************** // +// ************************************************************************** // + +template<typename ValueType, bool is_enum, bool repeatable> +class argument_factory; + +//____________________________________________________________________________// + +template<typename ValueType, bool is_enum> +class argument_factory<ValueType, is_enum, false> { +public: + template<typename Modifiers> + explicit argument_factory( Modifiers const& m ) + : m_interpreter( m ) + , m_optional_value( nfp::opt_get( m, optional_value, ValueType() ) ) + , m_default_value( nfp::opt_get( m, default_value, ValueType() ) ) + { + } + + void produce_argument( cstring source, cstring param_name, arguments_store& store ) const + { + store.set( param_name, source.empty() ? m_optional_value : m_interpreter.interpret( param_name, source ) ); + } + + void produce_default( cstring param_name, arguments_store& store ) const + { + store.set( param_name, m_default_value ); + } + +private: + // Data members + typedef value_interpreter<ValueType, is_enum> interp_t; + interp_t m_interpreter; + ValueType m_optional_value; + ValueType m_default_value; +}; + +//____________________________________________________________________________// + +template<typename ValueType, bool is_enum> +class argument_factory<ValueType, is_enum, true> { +public: + template<typename Modifiers> + explicit argument_factory( Modifiers const& m ) + : m_interpreter( m ) + { + } + + void produce_argument( cstring source, cstring param_name, arguments_store& store ) const + { + ValueType value = m_interpreter.interpret( param_name, source ); + + if( store.has( param_name ) ) { + std::vector<ValueType>& values = store.get<std::vector<ValueType> >( param_name ); + values.push_back( value ); + } + else { + std::vector<ValueType> values( 1, value ); + + store.set( param_name, values ); + } + + } + void produce_default( cstring param_name, arguments_store& store ) const + { + store.set( param_name, std::vector<ValueType>() ); + } + +private: + // Data members + value_interpreter<ValueType, is_enum> m_interpreter; +}; + +//____________________________________________________________________________// + +} // namespace runtime +} // namespace boost + +#include <boost/test/detail/enable_warnings.hpp> + +#endif // BOOST_TEST_UTILS_RUNTIME_ARGUMENT_FACTORY_HPP diff --git a/boost/test/utils/runtime/cla/argument_factory.hpp b/boost/test/utils/runtime/cla/argument_factory.hpp deleted file mode 100644 index 6683540612..0000000000 --- a/boost/test/utils/runtime/cla/argument_factory.hpp +++ /dev/null @@ -1,216 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : generic typed_argument_factory implementation -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_ARGUMENT_FACTORY_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_ARGUMENT_FACTORY_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/fwd.hpp> -#include <boost/test/utils/runtime/validation.hpp> -#include <boost/test/utils/runtime/argument.hpp> -#include <boost/test/utils/runtime/trace.hpp> -#include <boost/test/utils/runtime/interpret_argument_value.hpp> - -#include <boost/test/utils/runtime/cla/fwd.hpp> -#include <boost/test/utils/runtime/cla/value_generator.hpp> -#include <boost/test/utils/runtime/cla/value_handler.hpp> -#include <boost/test/utils/runtime/cla/validation.hpp> -#include <boost/test/utils/runtime/cla/argv_traverser.hpp> -#include <boost/test/utils/runtime/cla/detail/argument_value_usage.hpp> - -#include <boost/test/utils/runtime/cla/iface/argument_factory.hpp> - -// Boost -#include <boost/optional.hpp> -#include <boost/function/function2.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** default_value_interpreter ************** // -// ************************************************************************** // - -namespace rt_cla_detail { - -struct default_value_interpreter { - template<typename T> - void operator()( argv_traverser& tr, boost::optional<T>& value ) - { - if( interpret_argument_value( tr.token(), value, 0 ) ) - tr.next_token(); - } -}; - -} // namespace rt_cla_detail - -// ************************************************************************** // -// ************** typed_argument_factory ************** // -// ************************************************************************** // - -template<typename T> -struct typed_argument_factory : public argument_factory { - // Constructor - typed_argument_factory() - : m_value_interpreter( rt_cla_detail::default_value_interpreter() ) - {} - BOOST_TEST_UTILS_RUNTIME_PARAM_UNNEEDED_VIRTUAL ~typed_argument_factory() {} - - // properties modification - template<typename Modifier> - void accept_modifier( Modifier const& m ) - { - optionally_assign( m_value_handler, m, handler ); - optionally_assign( m_value_interpreter, m, interpreter ); - - if( m.has( default_value ) ) { - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( !m_value_generator, - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "multiple value generators for parameter" ) ); - - T const& dv_ref = m[default_value]; - m_value_generator = rt_cla_detail::const_generator<T>( dv_ref ); - } - - if( m.has( default_refer_to ) ) { - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( !m_value_generator, - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "multiple value generators for parameter" ) ); - - cstring ref_id = m[default_refer_to]; - m_value_generator = rt_cla_detail::ref_generator<T>( ref_id ); - } - - if( m.has( assign_to ) ) { - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( !m_value_handler, - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "multiple value handlers for parameter" ) ); - - m_value_handler = rt_cla_detail::assigner<T>( m[assign_to] ); - } - } - - // Argument factory implementation - virtual argument_ptr produce_using( parameter& p, argv_traverser& tr ); - virtual argument_ptr produce_using( parameter& p, parser const& ); - virtual void argument_usage_info( format_stream& fs ); - -// !! private? - // Data members - boost::function<void (parameter const&,T&)> m_value_handler; - boost::function<void (parser const&,boost::optional<T>&)> m_value_generator; - boost::function<void (argv_traverser&,boost::optional<T>&)> m_value_interpreter; -}; - -//____________________________________________________________________________// - -template<typename T> -inline argument_ptr -typed_argument_factory<T>::produce_using( parameter& p, argv_traverser& tr ) -{ - boost::optional<T> value; - - BOOST_TEST_IMPL_TRY { - m_value_interpreter( tr, value ); - } - BOOST_TEST_IMPL_CATCHALL() { // !! should we do that? - BOOST_TEST_UTILS_RUNTIME_PARAM_TRACE( "Fail to parse argument value" ); - - if( !p.p_optional_value ) - BOOST_TEST_IMPL_RETHROW; - } - - argument_ptr actual_arg = p.actual_argument(); - - BOOST_TEST_UTILS_RUNTIME_CLA_VALIDATE_INPUT( !!value || p.p_optional_value, tr, - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "Argument value missing for parameter " ) << p.id_2_report() ); - - BOOST_TEST_UTILS_RUNTIME_CLA_VALIDATE_INPUT( !actual_arg || p.p_multiplicable, tr, - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "Unexpected repetition of the parameter " ) << p.id_2_report() ); - - if( !!value && !!m_value_handler ) - m_value_handler( p, *value ); - - if( !p.p_multiplicable ) - actual_arg.reset( p.p_optional_value && (rtti::type_id<T>() != rtti::type_id<bool>()) - ? static_cast<argument*>(new typed_argument<boost::optional<T> >( p, value )) - : static_cast<argument*>(new typed_argument<T>( p, *value )) ); - else { - typedef std::list<boost::optional<T> > optional_list; - - if( !actual_arg ) - actual_arg.reset( p.p_optional_value - ? static_cast<argument*>(new typed_argument<optional_list>( p )) - : static_cast<argument*>(new typed_argument<std::list<T> >( p )) ); - - if( p.p_optional_value ) { - optional_list& values = arg_value<optional_list>( *actual_arg ); - - values.push_back( value ); - } - else { - std::list<T>& values = arg_value<std::list<T> >( *actual_arg ); - - values.push_back( *value ); - } - } - - return actual_arg; -} - -//____________________________________________________________________________// - -template<typename T> -inline argument_ptr -typed_argument_factory<T>::produce_using( parameter& p, parser const& pa ) -{ - argument_ptr actual_arg; - - if( !m_value_generator ) - return actual_arg; - - boost::optional<T> value; - m_value_generator( pa, value ); - - if( !value ) - return actual_arg; - - if( !!m_value_handler ) - m_value_handler( p, *value ); - - actual_arg.reset( new typed_argument<T>( p, *value ) ); - - return actual_arg; -} - -//____________________________________________________________________________// - -template<typename T> -inline void -typed_argument_factory<T>::argument_usage_info( format_stream& fs ) -{ - rt_cla_detail::argument_value_usage( fs, 0, reinterpret_cast<T*>(0) ); -} - -//____________________________________________________________________________// - -} // namespace boost - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace cla - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_ARGUMENT_FACTORY_HPP diff --git a/boost/test/utils/runtime/cla/argv_traverser.cpp b/boost/test/utils/runtime/cla/argv_traverser.cpp deleted file mode 100644 index 9716b8fb9c..0000000000 --- a/boost/test/utils/runtime/cla/argv_traverser.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : offline implementation for argc/argv traverser -// *************************************************************************** - -#define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -#include <boost/test/utils/runtime/cla/argv_traverser.ipp> diff --git a/boost/test/utils/runtime/cla/argv_traverser.hpp b/boost/test/utils/runtime/cla/argv_traverser.hpp index 6f6e03dfc8..10fb67bde4 100644 --- a/boost/test/utils/runtime/cla/argv_traverser.hpp +++ b/boost/test/utils/runtime/cla/argv_traverser.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (C) Copyright Gennadiy Rozental 2001. // Use, modification, and distribution are subject to 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) @@ -15,86 +15,91 @@ #ifndef BOOST_TEST_UTILS_RUNTIME_CLA_ARGV_TRAVERSER_HPP #define BOOST_TEST_UTILS_RUNTIME_CLA_ARGV_TRAVERSER_HPP -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> +// Boost.Test Runtime parameters +#include <boost/test/utils/runtime/fwd.hpp> -// Boost.Test -#include <boost/test/utils/class_properties.hpp> - -// Boost -#include <boost/noncopyable.hpp> -#include <boost/shared_array.hpp> +#include <boost/test/detail/suppress_warnings.hpp> namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - +namespace runtime { namespace cla { // ************************************************************************** // // ************** runtime::cla::argv_traverser ************** // // ************************************************************************** // -class argv_traverser : noncopyable { - class parser; +class argv_traverser { + typedef char const** argv_type; public: - // Constructor - argv_traverser(); - - // public_properties - unit_test::readwrite_property<bool> p_ignore_mismatch; - unit_test::readwrite_property<char_type> p_separator; - - // argc+argv <-> internal buffer exchange - void init( int argc, char_type** argv ); - void remainder( int& argc, char_type** argv ); - - // token based parsing - cstring token() const; - void next_token(); - - // whole input parsing - cstring input() const; - void trim( std::size_t size ); - bool match_front( cstring ); - bool match_front( char_type c ); - bool eoi() const; - - // transaction logic support - void commit(); - void rollback(); - - // current position access; used to save some reference points in input - std::size_t input_pos() const; - - // returns true if mismatch detected during input parsing handled successfully - bool handle_mismatch(); + /// Constructs traverser based on argc/argv pair + /// argv is taken "by reference" and later can be + /// updated in remainder method + argv_traverser( int argc, argv_type argv ) + : m_argc( argc ) + , m_curr_token( 0 ) + , m_token_size( 0 ) + , m_argv( argv ) + { + // save program name + save_token(); + } + + /// Returns new argc + int remainder() + { + return m_argc; + } + + /// Returns true, if we reached end on input + bool eoi() const + { + return m_curr_token == m_argc; + } + + /// Returns current token in the input + cstring current_token() + { + if( eoi() ) + return cstring(); + + return cstring( m_argv[m_curr_token], m_token_size ); + } + + /// Saves current token for remainder + void save_token() + { + ++m_curr_token; + + if( !eoi() ) + m_token_size = ::strlen( m_argv[m_curr_token] ); + } + + /// Commit current token and iterate to next one + void next_token() + { + if( !eoi() ) { + for( std::size_t i = m_curr_token; i < m_argc-1; ++i ) + m_argv[i] = m_argv[i + 1]; + + --m_argc; + + m_token_size = ::strlen( m_argv[m_curr_token] ); + } + } private: - // Data members - dstring m_buffer; - cstring m_work_buffer; - cstring m_token; - cstring::iterator m_commited_end; - - shared_array<char_type> m_remainder; - std::size_t m_remainder_size; + // Data members + std::size_t m_argc; // total number of arguments + std::size_t m_curr_token; // current token index in argv + std::size_t m_token_size; // current token size + argv_type m_argv; // all arguments }; } // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - +} // namespace runtime } // namespace boost -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_OFFLINE - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -# define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE inline -#endif -# include <boost/test/utils/runtime/cla/argv_traverser.ipp> - -#endif +#include <boost/test/detail/enable_warnings.hpp> #endif // BOOST_TEST_UTILS_RUNTIME_CLA_ARGV_TRAVERSER_HPP diff --git a/boost/test/utils/runtime/cla/argv_traverser.ipp b/boost/test/utils/runtime/cla/argv_traverser.ipp deleted file mode 100644 index d1ae93be82..0000000000 --- a/boost/test/utils/runtime/cla/argv_traverser.ipp +++ /dev/null @@ -1,212 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : implements facility to hide input traversing details -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_ARGV_TRAVERSER_IPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_ARGV_TRAVERSER_IPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/trace.hpp> - -#include <boost/test/utils/runtime/cla/argv_traverser.hpp> - -// STL -#include <memory> -#include <cstring> - -#ifdef BOOST_NO_STDC_NAMESPACE -namespace std { using ::memcpy; } -#endif - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** runtime::cla::argv_traverser ************** // -// ************************************************************************** // - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -argv_traverser::argv_traverser() -: p_ignore_mismatch( false ), p_separator( BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( ' ' ) ) -{ -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -argv_traverser::init( int argc, char_type** argv ) -{ - m_buffer.clear(); - - for( int index = 1; index < argc; ++index ) { - m_buffer += argv[index]; - if( index != argc-1 ) - m_buffer += BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( ' ' ); - } - - m_remainder.reset( new char_type[m_buffer.size()+1] ); - m_remainder_size = 0; - m_work_buffer = m_buffer; - m_commited_end = m_work_buffer.begin(); - - BOOST_TEST_UTILS_RUNTIME_PARAM_TRACE( "Input buffer: " << m_buffer ); - - next_token(); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -argv_traverser::remainder( int& argc, char_type** argv ) -{ - argc = 1; - std::size_t pos = 0; - while(pos < m_remainder_size ) { - argv[argc++] = m_remainder.get() + pos; - - pos = static_cast<size_t>(std::find( m_remainder.get() + pos, m_remainder.get() + m_remainder_size, - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( ' ' ) ) - - m_remainder.get()); - m_remainder[pos++] = BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( '\0' ); - } -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE cstring -argv_traverser::token() const -{ - return m_token; -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -argv_traverser::next_token() -{ - if( m_work_buffer.is_empty() ) - return; - - m_work_buffer.trim_left( m_token.size() ); // skip remainder of current token - - if( m_work_buffer.size() != m_buffer.size() ) // !! is there a better way to identify first token - m_work_buffer.trim_left( 1 ); // skip separator if not first token; - - m_token.assign( m_work_buffer.begin(), - std::find( m_work_buffer.begin(), m_work_buffer.end(), p_separator ) ); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE cstring -argv_traverser::input() const -{ - return m_work_buffer; -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -argv_traverser::trim( std::size_t size ) -{ - m_work_buffer.trim_left( size ); - - if( size <= m_token.size() ) - m_token.trim_left( size ); - else { - m_token.assign( m_work_buffer.begin(), - std::find( m_work_buffer.begin(), m_work_buffer.end(), p_separator ) ); - } -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -argv_traverser::match_front( cstring str ) -{ - return m_work_buffer.size() < str.size() ? false : m_work_buffer.substr( 0, str.size() ) == str; -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -argv_traverser::match_front( char_type c ) -{ - return first_char( m_work_buffer ) == c; -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -argv_traverser::eoi() const -{ - return m_work_buffer.is_empty(); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -argv_traverser::commit() -{ - m_commited_end = m_work_buffer.begin(); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -argv_traverser::rollback() -{ - m_work_buffer.assign( m_commited_end, m_work_buffer.end() ); - m_token.assign( m_work_buffer.begin(), - std::find( m_work_buffer.begin(), m_work_buffer.end(), p_separator ) ); - -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE std::size_t -argv_traverser::input_pos() const -{ - return static_cast<std::size_t>(m_work_buffer.begin() - m_commited_end); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -argv_traverser::handle_mismatch() -{ - if( !p_ignore_mismatch ) - return false; - - std::memcpy( m_remainder.get() + m_remainder_size, token().begin(), token().size() ); - m_remainder_size += token().size(); - m_remainder[m_remainder_size++] = p_separator; - - next_token(); - commit(); - - return true; -} - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_ARGV_TRAVERSER_IPP diff --git a/boost/test/utils/runtime/cla/basic_parameter.hpp b/boost/test/utils/runtime/cla/basic_parameter.hpp deleted file mode 100644 index 817b12a301..0000000000 --- a/boost/test/utils/runtime/cla/basic_parameter.hpp +++ /dev/null @@ -1,85 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : generic custom parameter generator -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_BASIC_PARAMETER_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_BASIC_PARAMETER_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/typed_parameter.hpp> - -// Boost.Test -#include <boost/test/utils/rtti.hpp> - -// Boost -#include <boost/utility/base_from_member.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** runtime::cla::basic_parameter ************** // -// ************************************************************************** // - -template<typename T, typename IdPolicy> -class basic_parameter : private base_from_member<IdPolicy>, public typed_parameter<T> { -public: - // Constructors - explicit basic_parameter( cstring n ) - : base_from_member<IdPolicy>() - , typed_parameter<T>( base_from_member<IdPolicy>::member ) - { - this->accept_modifier( name = n ); - } - - // parameter properties modification - template<typename Modifier> - void accept_modifier( Modifier const& m ) - { - typed_parameter<T>::accept_modifier( m ); - - base_from_member<IdPolicy>::member.accept_modifier( m ); - } -}; - -//____________________________________________________________________________// - -#define BOOST_TEST_UTILS_RUNTIME_CLA_NAMED_PARAM_GENERATORS( param_type ) \ -template<typename T> \ -inline shared_ptr<param_type ## _t<T> > \ -param_type( cstring name = cstring() ) \ -{ \ - return shared_ptr<param_type ## _t<T> >( new param_type ## _t<T>( name ) ); \ -} \ - \ -inline shared_ptr<param_type ## _t<cstring> > \ -param_type( cstring name = cstring() ) \ -{ \ - return shared_ptr<param_type ## _t<cstring> >( new param_type ## _t<cstring>( name ) ); \ -} \ -/**/ - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_BASIC_PARAMETER_HPP diff --git a/boost/test/utils/runtime/cla/char_parameter.cpp b/boost/test/utils/runtime/cla/char_parameter.cpp deleted file mode 100644 index 6e85fe4136..0000000000 --- a/boost/test/utils/runtime/cla/char_parameter.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : offline implementation of char parameter -// *************************************************************************** - -#define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -#include <boost/test/utils/runtime/cla/char_parameter.ipp> diff --git a/boost/test/utils/runtime/cla/char_parameter.hpp b/boost/test/utils/runtime/cla/char_parameter.hpp deleted file mode 100644 index 0e2928b1af..0000000000 --- a/boost/test/utils/runtime/cla/char_parameter.hpp +++ /dev/null @@ -1,100 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : defines model of parameter with single char name -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_CHAR_PARAMETER_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_CHAR_PARAMETER_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> -#include <boost/test/utils/runtime/validation.hpp> - -#include <boost/test/utils/runtime/cla/basic_parameter.hpp> -#include <boost/test/utils/runtime/cla/id_policy.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** char_name_policy ************** // -// ************************************************************************** // - -class char_name_policy : public basic_naming_policy { -public: - // Constructor - char_name_policy(); - BOOST_TEST_UTILS_RUNTIME_PARAM_UNNEEDED_VIRTUAL ~char_name_policy() {} - - // policy interface - virtual bool conflict_with( identification_policy const& ) const; - - // Accept modifier - template<typename Modifier> - void accept_modifier( Modifier const& m ) - { - basic_naming_policy::accept_modifier( m ); - - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( p_name->size() <= 1, "Invalid parameter name " << p_name ); - } -}; - -// ************************************************************************** // -// ************** runtime::cla::char_parameter ************** // -// ************************************************************************** // - -template<typename T> -class char_parameter_t : public basic_parameter<T,char_name_policy> { - typedef basic_parameter<T,char_name_policy> base; -public: - // Constructors - explicit char_parameter_t( char_type name ) : base( cstring( &name, 1 ) ) {} -}; - -//____________________________________________________________________________// - -template<typename T> -inline shared_ptr<char_parameter_t<T> > -char_parameter( char_type name ) -{ - return shared_ptr<char_parameter_t<T> >( new char_parameter_t<T>( name ) ); -} - -//____________________________________________________________________________// - -inline shared_ptr<char_parameter_t<cstring> > -char_parameter( char_type name ) -{ - return shared_ptr<char_parameter_t<cstring> >( new char_parameter_t<cstring>( name ) ); -} - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_OFFLINE - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -# define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE inline -#endif -# include <boost/test/utils/runtime/cla/char_parameter.ipp> - -#endif - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_CHAR_PARAMETER_HPP diff --git a/boost/test/utils/runtime/cla/char_parameter.ipp b/boost/test/utils/runtime/cla/char_parameter.ipp deleted file mode 100644 index 398ce79ac4..0000000000 --- a/boost/test/utils/runtime/cla/char_parameter.ipp +++ /dev/null @@ -1,57 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : implements model of parameter with single char name -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_CHAR_PARAMETER_IPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_CHAR_PARAMETER_IPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/char_parameter.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** char_name_policy ************** // -// ************************************************************************** // - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -char_name_policy::char_name_policy() -: basic_naming_policy( rtti::type_id<char_name_policy>() ) -{ - assign_op( p_prefix.value, BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "-" ), 0 ); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -char_name_policy::conflict_with( identification_policy const& id ) const -{ - return id.p_type_id == p_type_id && - p_name == static_cast<char_name_policy const&>( id ).p_name; -} - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_CHAR_PARAMETER_IPP diff --git a/boost/test/utils/runtime/cla/detail/argument_value_usage.hpp b/boost/test/utils/runtime/cla/detail/argument_value_usage.hpp deleted file mode 100644 index a70b6d1fb7..0000000000 --- a/boost/test/utils/runtime/cla/detail/argument_value_usage.hpp +++ /dev/null @@ -1,81 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : argument usage printing helpers -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_ARGUMENT_VALUE_USAGE_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_ARGUMENT_VALUE_USAGE_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> -#include <boost/test/utils/runtime/cla/argv_traverser.hpp> - -// Boost.Test -#include <boost/test/utils/basic_cstring/io.hpp> -#include <boost/test/utils/basic_cstring/compare.hpp> - -#include <boost/lexical_cast.hpp> - -// STL -// !! can we eliminate these includes? -#include <list> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -namespace rt_cla_detail { - -// ************************************************************************** // -// ************** argument_value_usage ************** // -// ************************************************************************** // - -// generic case -template<typename T> -inline void -argument_value_usage( format_stream& fs, long, T* = 0 ) -{ - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "<value>" ); -} - -//____________________________________________________________________________// - -// specialization for list of values -template<typename T> -inline void -argument_value_usage( format_stream& fs, int, std::list<T>* = 0 ) -{ - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "(<value1>, ..., <valueN>)" ); -} - -//____________________________________________________________________________// - -// specialization for type bool -inline void -argument_value_usage( format_stream& fs, int, bool* = 0 ) -{ - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "yes|y|no|n" ); -} - -//____________________________________________________________________________// - -} // namespace rt_cla_detail - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_ARGUMENT_VALUE_USAGE_HPP diff --git a/boost/test/utils/runtime/cla/dual_name_parameter.cpp b/boost/test/utils/runtime/cla/dual_name_parameter.cpp deleted file mode 100644 index ab034ff04c..0000000000 --- a/boost/test/utils/runtime/cla/dual_name_parameter.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : offline implementation of generic parameter with dual naming -// *************************************************************************** - -#define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -#include <boost/test/utils/runtime/cla/dual_name_parameter.ipp> diff --git a/boost/test/utils/runtime/cla/dual_name_parameter.hpp b/boost/test/utils/runtime/cla/dual_name_parameter.hpp deleted file mode 100644 index 789b67ad1d..0000000000 --- a/boost/test/utils/runtime/cla/dual_name_parameter.hpp +++ /dev/null @@ -1,98 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : defines model of generic parameter with dual naming -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_DUAL_NAME_PARAMETER_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_DUAL_NAME_PARAMETER_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/named_parameter.hpp> -#include <boost/test/utils/runtime/cla/char_parameter.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** dual_name_policy ************** // -// ************************************************************************** // - -class dual_name_policy : public dual_id_policy<dual_name_policy,string_name_policy,char_name_policy> { -public: - dual_name_policy(); - - // Accept modifier - template<typename Modifier> - void accept_modifier( Modifier const& m ) - { - if( m.has( prefix ) ) { - set_prefix( m[prefix] ); - m.erase( prefix ); - } - - if( m.has( name ) ) { - set_name( m[name] ); - m.erase( name ); - } - - if( m.has( separator ) ) { - set_separator( m[separator] ); - m.erase( separator ); - } - - dual_id_policy<dual_name_policy,string_name_policy,char_name_policy>::accept_modifier( m ); - } -private: - void set_prefix( cstring ); - void set_name( cstring ); - void set_separator( cstring ); -}; - -// ************************************************************************** // -// ************** runtime::cla::dual_name_parameter ************** // -// ************************************************************************** // - -template<typename T> -class dual_name_parameter_t : public basic_parameter<T,dual_name_policy> { - typedef basic_parameter<T,dual_name_policy> base; -public: - // Constructors - explicit dual_name_parameter_t( cstring name ) : base( name ) {} -}; - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_CLA_NAMED_PARAM_GENERATORS( dual_name_parameter ) - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_OFFLINE - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -# define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE inline -#endif -# include <boost/test/utils/runtime/cla/dual_name_parameter.ipp> - -#endif - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_DUAL_NAME_PARAMETER_HPP diff --git a/boost/test/utils/runtime/cla/dual_name_parameter.ipp b/boost/test/utils/runtime/cla/dual_name_parameter.ipp deleted file mode 100644 index e39d132d62..0000000000 --- a/boost/test/utils/runtime/cla/dual_name_parameter.ipp +++ /dev/null @@ -1,90 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : implements model of generic parameter with dual naming -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_DUAL_NAME_PARAMETER_IPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_DUAL_NAME_PARAMETER_IPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> -#include <boost/test/utils/runtime/validation.hpp> - -#include <boost/test/utils/runtime/cla/dual_name_parameter.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** dual_name_policy ************** // -// ************************************************************************** // - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -dual_name_policy::dual_name_policy() -{ - m_primary.accept_modifier( prefix = BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "--" ) ); - m_secondary.accept_modifier( prefix = BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "-" ) ); -} - -//____________________________________________________________________________// - -namespace { - -template<typename K> -inline void -split( string_name_policy& snp, char_name_policy& cnp, cstring src, K const& k ) -{ - cstring::iterator sep = std::find( src.begin(), src.end(), BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( '|' ) ); - - if( sep != src.begin() ) - snp.accept_modifier( k = cstring( src.begin(), sep ) ); - - if( sep != src.end() ) - cnp.accept_modifier( k = cstring( sep+1, src.end() ) ); -} - -} // local namespace - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -dual_name_policy::set_prefix( cstring src ) -{ - split( m_primary, m_secondary, src, prefix ); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -dual_name_policy::set_name( cstring src ) -{ - split( m_primary, m_secondary, src, name ); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -dual_name_policy::set_separator( cstring src ) -{ - split( m_primary, m_secondary, src, separator ); -} - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_DUAL_NAME_PARAMETER_IPP diff --git a/boost/test/utils/runtime/cla/fwd.hpp b/boost/test/utils/runtime/cla/fwd.hpp deleted file mode 100644 index df02974345..0000000000 --- a/boost/test/utils/runtime/cla/fwd.hpp +++ /dev/null @@ -1,55 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : cla subsystem forward declarations -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_FWD_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_FWD_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -// Boost -#include <boost/shared_ptr.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -class parser; -class parameter; -typedef shared_ptr<parameter> parameter_ptr; -class naming_policy; -typedef shared_ptr<naming_policy> naming_policy_ptr; -class argv_traverser; - -namespace rt_cla_detail { - -template<typename T> class const_generator; -template<typename T> class ref_generator; - -template<typename T> class assigner; - -class named_parameter_base; -class positional_parameter_base; - -} // namespace rt_cla_detail - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_FWD_HPP diff --git a/boost/test/utils/runtime/cla/id_policy.cpp b/boost/test/utils/runtime/cla/id_policy.cpp deleted file mode 100644 index b000e26f94..0000000000 --- a/boost/test/utils/runtime/cla/id_policy.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : some generic identification policies offline implementation -// *************************************************************************** - -#define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -#include <boost/test/utils/runtime/cla/id_policy.ipp> diff --git a/boost/test/utils/runtime/cla/id_policy.hpp b/boost/test/utils/runtime/cla/id_policy.hpp deleted file mode 100644 index 3308b07c61..0000000000 --- a/boost/test/utils/runtime/cla/id_policy.hpp +++ /dev/null @@ -1,147 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : some generic identification policies definition -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_ID_POLICY_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_ID_POLICY_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/fwd.hpp> -#include <boost/test/utils/runtime/cla/modifier.hpp> -#include <boost/test/utils/runtime/cla/argv_traverser.hpp> - -#include <boost/test/utils/runtime/cla/iface/id_policy.hpp> - -// Boost.Test -#include <boost/test/utils/class_properties.hpp> -#include <boost/test/utils/rtti.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** naming_policy_base ************** // -// ************************************************************************** // -// model: <prefix> <name> <separtor> - -class basic_naming_policy : public identification_policy { -public: - // Public properties - unit_test::readwrite_property<dstring> p_prefix; - unit_test::readwrite_property<dstring> p_name; - unit_test::readwrite_property<dstring> p_separator; - - // Policy interface - virtual bool responds_to( cstring name ) const { return p_name == name; } - virtual cstring id_2_report() const { return p_name.get(); } - virtual void usage_info( format_stream& fs ) const; - virtual bool matching( parameter const& p, argv_traverser& tr, bool primary ) const; - - // Accept modifier - template<typename Modifier> - void accept_modifier( Modifier const& m ) - { - nfp::optionally_assign( p_prefix.value, m, prefix ); - nfp::optionally_assign( p_name.value, m, name ); - nfp::optionally_assign( p_separator.value, m, separator ); - } - -protected: - explicit basic_naming_policy( rtti::id_t dyn_type ) - : identification_policy( dyn_type ) - {} - BOOST_TEST_UTILS_RUNTIME_PARAM_UNNEEDED_VIRTUAL ~basic_naming_policy() {} - - // Naming policy interface - virtual bool match_prefix( argv_traverser& tr ) const; - virtual bool match_name( argv_traverser& tr ) const; - virtual bool match_separator( argv_traverser& tr, bool optional_value ) const; -}; - -// ************************************************************************** // -// ************** dual_id_policy ************** // -// ************************************************************************** // - -template<typename MostDerived,typename PrimaryId,typename SecondId> -class dual_id_policy : public identification_policy { -public: - // Constructor - dual_id_policy() - : identification_policy( rtti::type_id<MostDerived>() ) - , m_primary() - , m_secondary() - {} - - // Policy interface - virtual bool responds_to( cstring name ) const - { - return m_primary.responds_to( name ) || m_secondary.responds_to( name ); - } - virtual bool conflict_with( identification_policy const& id_p ) const - { - return id_p.conflict_with( m_primary ) || id_p.conflict_with( m_secondary ); - } - virtual cstring id_2_report() const - { - return m_primary.id_2_report(); - } - virtual void usage_info( format_stream& fs ) const - { - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( '{' ); - m_primary.usage_info( fs ); - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( '|' ); - m_secondary.usage_info( fs ); - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( '}' ); - } - virtual bool matching( parameter const& p, argv_traverser& tr, bool primary ) const - { - return m_primary.matching( p, tr, primary ) || m_secondary.matching( p, tr, primary ); - } - - // Accept modifier - template<typename Modifier> - void accept_modifier( Modifier const& m ) - { - m_primary.accept_modifier( m ); - m_secondary.accept_modifier( m ); - } - -protected: - BOOST_TEST_UTILS_RUNTIME_PARAM_UNNEEDED_VIRTUAL ~dual_id_policy() {} - - // Data members - PrimaryId m_primary; - SecondId m_secondary; -}; - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_OFFLINE - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -# define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE inline -#endif -# include <boost/test/utils/runtime/cla/id_policy.ipp> - -#endif - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_ID_POLICY_HPP diff --git a/boost/test/utils/runtime/cla/id_policy.ipp b/boost/test/utils/runtime/cla/id_policy.ipp deleted file mode 100644 index 879ccfd1e1..0000000000 --- a/boost/test/utils/runtime/cla/id_policy.ipp +++ /dev/null @@ -1,118 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : some generic identification policies implementation -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_ID_POLICY_IPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_ID_POLICY_IPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/id_policy.hpp> -#include <boost/test/utils/runtime/cla/parameter.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** basic_naming_policy ************** // -// ************************************************************************** // - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -basic_naming_policy::usage_info( format_stream& fs ) const -{ - fs << p_prefix << p_name << p_separator; - - if( p_separator->empty() ) - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( ' ' ); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -basic_naming_policy::match_prefix( argv_traverser& tr ) const -{ - if( !tr.match_front( p_prefix.get() ) ) - return false; - - tr.trim( p_prefix->size() ); - return true; -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -basic_naming_policy::match_name( argv_traverser& tr ) const -{ - if( !tr.match_front( p_name.get() ) ) - return false; - - tr.trim( p_name->size() ); - return true; -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -basic_naming_policy::match_separator( argv_traverser& tr, bool optional_value ) const -{ - if( p_separator->empty() ) { - if( !tr.token().is_empty() ) - return false; - - tr.trim( 1 ); - } - else { - if( !tr.match_front( p_separator.get() ) ) { - // if parameter has optional value separator is optional as well - if( optional_value && ( tr.eoi() || tr.match_front( ' ' ) ) ) { - return true; - } - return false; - } - - tr.trim( p_separator->size() ); - } - - return true; -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -basic_naming_policy::matching( parameter const& p, argv_traverser& tr, bool ) const -{ - if( !match_prefix( tr ) ) - return false; - - if( !match_name( tr ) ) - return false; - - if( !match_separator( tr, p.p_optional_value ) ) - return false; - - return true; -} - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_ID_POLICY_IPP diff --git a/boost/test/utils/runtime/cla/iface/argument_factory.hpp b/boost/test/utils/runtime/cla/iface/argument_factory.hpp deleted file mode 100644 index cbca713bd3..0000000000 --- a/boost/test/utils/runtime/cla/iface/argument_factory.hpp +++ /dev/null @@ -1,51 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : defines interface for argument_factory -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_IFACE_ARGUMENT_FACTORY_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_IFACE_ARGUMENT_FACTORY_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> -#include <boost/test/utils/runtime/fwd.hpp> - -#include <boost/test/utils/runtime/cla/fwd.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** argument_factory ************** // -// ************************************************************************** // -// another name can be argument production policy - -class argument_factory { -public: - // Argument factory interface - virtual argument_ptr produce_using( parameter& p, argv_traverser& tr ) = 0; /// produce argument based on input - virtual argument_ptr produce_using( parameter& p, parser const& ) = 0; /// produce argument based on internal generator and/or values of other parameters - virtual void argument_usage_info( format_stream& fs ) = 0; /// argument value format information -protected: - BOOST_TEST_PROTECTED_VIRTUAL ~argument_factory() {} -}; - -} // namespace boost - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace cla - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_IFACE_ARGUMENT_FACTORY_HPP diff --git a/boost/test/utils/runtime/cla/iface/id_policy.hpp b/boost/test/utils/runtime/cla/iface/id_policy.hpp deleted file mode 100644 index 5fa13e6bc7..0000000000 --- a/boost/test/utils/runtime/cla/iface/id_policy.hpp +++ /dev/null @@ -1,73 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : defines interface for identification_policy -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_IFACE_ID_POLICY_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_IFACE_ID_POLICY_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/fwd.hpp> - -// Boost.Test -#include <boost/test/utils/class_properties.hpp> -#include <boost/test/utils/rtti.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** identification_policy ************** // -// ************************************************************************** // - -#ifdef BOOST_MSVC -# pragma warning(push) -# pragma warning(disable:4244) -#endif - -class identification_policy { -public: - // Public properties - unit_test::readwrite_property<rtti::id_t> p_type_id; - - // Policy interface - virtual bool responds_to( cstring name ) const = 0; - virtual cstring id_2_report() const = 0; - virtual void usage_info( format_stream& fs ) const = 0; - virtual bool matching( parameter const& p, argv_traverser& tr, bool primary ) const = 0; - - virtual bool conflict_with( identification_policy const& ) const = 0; - -protected: - // Constructor - explicit identification_policy( rtti::id_t dyn_type ) - : p_type_id( dyn_type ) - {} - BOOST_TEST_PROTECTED_VIRTUAL ~identification_policy() {} -}; - -#ifdef BOOST_MSVC -# pragma warning(pop) -#endif - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_IFACE_ID_POLICY_HPP diff --git a/boost/test/utils/runtime/cla/modifier.hpp b/boost/test/utils/runtime/cla/modifier.hpp deleted file mode 100644 index 4b55536b73..0000000000 --- a/boost/test/utils/runtime/cla/modifier.hpp +++ /dev/null @@ -1,69 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : parameter modifiers -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_MODIFIER_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_MODIFIER_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -// Boost.Test -#include <boost/test/utils/named_params.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** environment variable modifiers ************** // -// ************************************************************************** // - -namespace { - -nfp::typed_keyword<bool,struct optional_t> optional_m; -nfp::named_parameter<bool,optional_t,bool> optional( true ); -nfp::typed_keyword<bool,struct required_t> required_m; -nfp::named_parameter<bool,required_t,bool> required( true ); -nfp::typed_keyword<bool,struct multiplicable_t> multiplicable_m; -nfp::named_parameter<bool,multiplicable_t,bool> multiplicable( true ); -nfp::typed_keyword<bool,struct guess_name_t> guess_name_m; -nfp::named_parameter<bool,guess_name_t,bool> guess_name( true ); -nfp::typed_keyword<bool,struct ignore_mismatch_t> ignore_mismatch_m; -nfp::named_parameter<bool,ignore_mismatch_t,bool> ignore_mismatch( true ); -nfp::typed_keyword<bool,struct optional_value_t> optional_value_m; -nfp::named_parameter<bool,optional_value_t,bool> optional_value( true ); - -nfp::typed_keyword<char_type,struct input_separator_t> input_separator; -nfp::typed_keyword<cstring,struct prefix_t> prefix; -nfp::typed_keyword<cstring,struct name_t> name; -nfp::typed_keyword<cstring,struct separator_t> separator; -nfp::typed_keyword<cstring,struct description_t> description; -nfp::typed_keyword<cstring,struct refer_to_t> default_refer_to; - -nfp::keyword<struct default_value_t> default_value; -nfp::keyword<struct handler_t> handler; -nfp::keyword<struct interpreter_t> interpreter; -nfp::keyword<struct assign_to_t> assign_to; - -} // local namespace - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_MODIFIER_HPP diff --git a/boost/test/utils/runtime/cla/named_parameter.cpp b/boost/test/utils/runtime/cla/named_parameter.cpp deleted file mode 100644 index 7e94722dc9..0000000000 --- a/boost/test/utils/runtime/cla/named_parameter.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : offline implementation of named parameter -// *************************************************************************** - -#define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -#include <boost/test/utils/runtime/cla/named_parameter.ipp> diff --git a/boost/test/utils/runtime/cla/named_parameter.hpp b/boost/test/utils/runtime/cla/named_parameter.hpp deleted file mode 100644 index be3f9c570b..0000000000 --- a/boost/test/utils/runtime/cla/named_parameter.hpp +++ /dev/null @@ -1,95 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : defines model of named parameter -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_NAMED_PARAMETER_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_NAMED_PARAMETER_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/basic_parameter.hpp> -#include <boost/test/utils/runtime/cla/id_policy.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** string_name_policy ************** // -// ************************************************************************** // - -class string_name_policy : public basic_naming_policy { -public: - // Constructor - string_name_policy(); - BOOST_TEST_UTILS_RUNTIME_PARAM_UNNEEDED_VIRTUAL ~string_name_policy() {} - - // policy interface - virtual bool responds_to( cstring name ) const; - virtual bool conflict_with( identification_policy const& ) const; - - // Accept modifier - template<typename Modifier> - void accept_modifier( Modifier const& m ) - { - basic_naming_policy::accept_modifier( m ); - - if( m.has( guess_name_m ) ) - m_guess_name = true; - } - -private: - // Naming policy interface - virtual bool match_name( argv_traverser& tr ) const; - - // Data members - bool m_guess_name; -}; - -// ************************************************************************** // -// ************** runtime::cla::named_parameter ************** // -// ************************************************************************** // - -template<typename T> -class named_parameter_t : public basic_parameter<T,string_name_policy> { - typedef basic_parameter<T,string_name_policy> base; -public: - // Constructors - explicit named_parameter_t( cstring name ) : base( name ) {} -}; - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_CLA_NAMED_PARAM_GENERATORS( named_parameter ) - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_OFFLINE - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -# define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE inline -#endif -# include <boost/test/utils/runtime/cla/named_parameter.ipp> - -#endif - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_NAMED_PARAMETER_HPP diff --git a/boost/test/utils/runtime/cla/named_parameter.ipp b/boost/test/utils/runtime/cla/named_parameter.ipp deleted file mode 100644 index e59ebdf89c..0000000000 --- a/boost/test/utils/runtime/cla/named_parameter.ipp +++ /dev/null @@ -1,129 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : implements model of named parameter -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_NAMED_PARAMETER_IPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_NAMED_PARAMETER_IPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/named_parameter.hpp> -#include <boost/test/utils/runtime/cla/char_parameter.hpp> - -// Boost.Test -#include <boost/test/utils/algorithm.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** string_name_policy ************** // -// ************************************************************************** // - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -string_name_policy::string_name_policy() -: basic_naming_policy( rtti::type_id<string_name_policy>() ) -, m_guess_name( false ) -{ - assign_op( p_prefix.value, BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "-" ), 0 ); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -string_name_policy::responds_to( cstring name ) const -{ - std::pair<cstring::iterator,dstring::const_iterator> mm_pos; - - mm_pos = unit_test::mismatch( name.begin(), name.end(), p_name->begin(), p_name->end() ); - - return mm_pos.first == name.end() && (m_guess_name || (mm_pos.second == p_name->end()) ); -} - -//____________________________________________________________________________// - -#ifdef BOOST_MSVC -# pragma warning(push) -# pragma warning(disable:4244) -#endif - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -string_name_policy::conflict_with( identification_policy const& id ) const -{ - if( id.p_type_id == p_type_id ) { - string_name_policy const& snp = static_cast<string_name_policy const&>( id ); - - if( p_name->empty() || snp.p_name->empty() ) - return false; - - if( p_prefix != snp.p_prefix ) - return false; - - std::pair<dstring::const_iterator,dstring::const_iterator> mm_pos = - unit_test::mismatch( p_name->begin(), p_name->end(), snp.p_name->begin(), snp.p_name->end() ); - - return mm_pos.first != p_name->begin() && // there is common substring - ((m_guess_name && (mm_pos.second == snp.p_name->end()) ) || // that match other guy and I am guessing - (snp.m_guess_name && (mm_pos.first == p_name->end()) )); // or me and the other guy is - } - - if( id.p_type_id == rtti::type_id<char_name_policy>() ) { - char_name_policy const& cnp = static_cast<char_name_policy const&>( id ); - - return m_guess_name && - (p_prefix == cnp.p_prefix) && - unit_test::first_char( cstring( p_name ) ) == unit_test::first_char( cstring( cnp.p_name ) ); - } - - return false; -} - -#ifdef BOOST_MSVC -# pragma warning(pop) -#endif - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE bool -string_name_policy::match_name( argv_traverser& tr ) const -{ - if( !m_guess_name ) - return basic_naming_policy::match_name( tr ); - - cstring in = tr.input(); - - std::pair<cstring::iterator,dstring::const_iterator> mm_pos; - - mm_pos = unit_test::mismatch( in.begin(), in.end(), p_name->begin(), p_name->end() ); - - if( mm_pos.first == in.begin() ) - return false; - - tr.trim( static_cast<std::size_t>(mm_pos.first - in.begin()) ); - - return true; -} - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_NAMED_PARAMETER_IPP diff --git a/boost/test/utils/runtime/cla/parameter.hpp b/boost/test/utils/runtime/cla/parameter.hpp deleted file mode 100644 index 9e26d25007..0000000000 --- a/boost/test/utils/runtime/cla/parameter.hpp +++ /dev/null @@ -1,151 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : defines model of formal parameter -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_PARAMETER_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_PARAMETER_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/fwd.hpp> -#include <boost/test/utils/runtime/parameter.hpp> -#include <boost/test/utils/runtime/validation.hpp> - -#include <boost/test/utils/runtime/cla/fwd.hpp> -#include <boost/test/utils/runtime/cla/modifier.hpp> -#include <boost/test/utils/runtime/cla/iface/argument_factory.hpp> -#include <boost/test/utils/runtime/cla/iface/id_policy.hpp> - -// Boost.Test -#include <boost/test/utils/rtti.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** runtime::cla::parameter ************** // -// ************************************************************************** // - -class parameter : public BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE::parameter { -public: - parameter( identification_policy& ID, argument_factory& F, bool optional_value = false ) - : p_optional( false ) - , p_multiplicable( false ) - , p_optional_value( optional_value ) - , m_id_policy( ID ) - , m_arg_factory( F ) - {} - - // Destructor - virtual ~parameter() {} - - unit_test::readwrite_property<bool> p_optional; - unit_test::readwrite_property<bool> p_multiplicable; - unit_test::readwrite_property<bool> p_optional_value; - unit_test::readwrite_property<dstring> p_description; - - // parameter properties modification - template<typename Modifier> - void accept_modifier( Modifier const& m ) - { - if( m.has( optional_m ) ) - p_optional.value = true; - - if( m.has( required_m ) ) - p_optional.value = false; - - if( m.has( multiplicable_m ) ) - p_multiplicable.value = true; - - if( m.has( optional_value_m ) ) - p_optional_value.value = true; - - nfp::optionally_assign( p_description.value, m, description ); - } - - // access methods - bool has_argument() const { return !!m_actual_argument; } - argument const& actual_argument() const { return *m_actual_argument; } - argument_ptr actual_argument() { return m_actual_argument; } - void reset() { m_actual_argument.reset(); } - - - // identification interface - bool responds_to( cstring name ) const { return m_id_policy.responds_to( name ); } - bool conflict_with( parameter const& p ) const - { - return (id_2_report() == p.id_2_report() && !id_2_report().is_empty()) || - m_id_policy.conflict_with( p.m_id_policy ) || - ((m_id_policy.p_type_id != p.m_id_policy.p_type_id) && p.m_id_policy.conflict_with( m_id_policy )); - } - cstring id_2_report() const { return m_id_policy.id_2_report(); } - void usage_info( format_stream& fs ) const - { - m_id_policy.usage_info( fs ); - if( p_optional_value ) - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( '[' ); - - m_arg_factory.argument_usage_info( fs ); - - if( p_optional_value ) - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( ']' ); - } - - // argument match/produce based on input - bool matching( argv_traverser& tr, bool primary ) const - { - return m_id_policy.matching( *this, tr, primary ); - } - - // argument production based on different source - void produce_argument( argv_traverser& tr ) - { - m_id_policy.matching( *this, tr, true ); // !! can we save this position somehow - m_actual_argument = m_arg_factory.produce_using( *this, tr ); - } - void produce_argument( parser const& p ) - { - m_actual_argument = m_arg_factory.produce_using( *this, p ); - } - -private: - //Data members - identification_policy& m_id_policy; - argument_factory& m_arg_factory; - argument_ptr m_actual_argument; -}; - -//____________________________________________________________________________// - -template<typename Parameter,typename Modifier> -inline shared_ptr<Parameter> -operator-( shared_ptr<Parameter> p, Modifier const& m ) -{ - p->accept_modifier( m ); - - return p; -} - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_PARAMETER_HPP diff --git a/boost/test/utils/runtime/cla/parser.cpp b/boost/test/utils/runtime/cla/parser.cpp deleted file mode 100644 index 8efc17d3b2..0000000000 --- a/boost/test/utils/runtime/cla/parser.cpp +++ /dev/null @@ -1,18 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : offline implementation for parser -// *************************************************************************** - -#include <boost/test/utils/runtime/config.hpp> - -#define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -#include <boost/test/utils/runtime/cla/parser.ipp> diff --git a/boost/test/utils/runtime/cla/parser.hpp b/boost/test/utils/runtime/cla/parser.hpp index ffe09e4adc..effde33a52 100644 --- a/boost/test/utils/runtime/cla/parser.hpp +++ b/boost/test/utils/runtime/cla/parser.hpp @@ -1,158 +1,491 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (C) Copyright Gennadiy Rozental 2001. // Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : defines parser - public interface for CLA parsing and accessing +//!@file +//!@brief CLA parser // *************************************************************************** #ifndef BOOST_TEST_UTILS_RUNTIME_CLA_PARSER_HPP #define BOOST_TEST_UTILS_RUNTIME_CLA_PARSER_HPP -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> -#include <boost/test/utils/runtime/fwd.hpp> +// Boost.Test Runtime parameters #include <boost/test/utils/runtime/argument.hpp> +#include <boost/test/utils/runtime/modifier.hpp> +#include <boost/test/utils/runtime/parameter.hpp> -#include <boost/test/utils/runtime/cla/fwd.hpp> -#include <boost/test/utils/runtime/cla/modifier.hpp> #include <boost/test/utils/runtime/cla/argv_traverser.hpp> -// Boost -#include <boost/optional.hpp> +// Boost.Test +#include <boost/test/utils/foreach.hpp> +#include <boost/test/utils/algorithm.hpp> +#include <boost/test/detail/throw_exception.hpp> -// STL -#include <list> +#include <boost/algorithm/cxx11/all_of.hpp> // !! ?? unnecessary after cxx11 -namespace boost { +// STL +// !! ?? #include <unordered_set> +#include <set> +#include <iostream> -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { +#include <boost/test/detail/suppress_warnings.hpp> +namespace boost { +namespace runtime { namespace cla { // ************************************************************************** // -// ************** runtime::cla::parser ************** // +// ************** runtime::cla::parameter_trie ************** // // ************************************************************************** // -namespace cla_detail { +namespace rt_cla_detail { -template<typename Modifier> -class global_mod_parser { -public: - global_mod_parser( parser& p, Modifier const& m ) - : m_parser( p ) - , m_modifiers( m ) - {} - - template<typename Param> - global_mod_parser const& - operator<<( shared_ptr<Param> param ) const +struct parameter_trie; +typedef shared_ptr<parameter_trie> parameter_trie_ptr; +typedef std::map<char,parameter_trie_ptr> trie_per_char; +typedef std::vector<boost::reference_wrapper<parameter_cla_id const> > param_cla_id_list; + +struct parameter_trie { + parameter_trie() : m_has_final_candidate( false ) {} + + /// If subtrie corresponding to the char c exists returns it otherwise creates new + parameter_trie_ptr make_subtrie( char c ) { - param->accept_modifier( m_modifiers ); + trie_per_char::const_iterator it = m_subtrie.find( c ); - m_parser << param; + if( it == m_subtrie.end() ) + it = m_subtrie.insert( std::make_pair( c, parameter_trie_ptr( new parameter_trie ) ) ).first; - return *this; + return it->second; } -private: - // Data members; - parser& m_parser; - Modifier const& m_modifiers; + /// Creates series of sub-tries per characters in a string + parameter_trie_ptr make_subtrie( cstring s ) + { + parameter_trie_ptr res; + + BOOST_TEST_FOREACH( char, c, s ) + res = (res ? res->make_subtrie( c ) : make_subtrie( c )); + + return res; + } + + /// Registers candidate parameter for this subtrie. If final, it needs to be unique + void add_candidate_id( parameter_cla_id const& param_id, basic_param_ptr param_candidate, bool final ) + { + BOOST_TEST_I_ASSRT( !m_has_final_candidate && (!final || m_id_candidates.empty()), + conflicting_param() << "Parameter cla id " << param_id.m_tag << " conflicts with the " + << "parameter cla id " << m_id_candidates.back().get().m_tag ); + + m_has_final_candidate = final; + m_id_candidates.push_back( ref(param_id) ); + + if( m_id_candidates.size() == 1 ) + m_param_candidate = param_candidate; + else + m_param_candidate.reset(); + } + + /// Gets subtrie for specified char if present or nullptr otherwise + parameter_trie_ptr get_subtrie( char c ) const + { + trie_per_char::const_iterator it = m_subtrie.find( c ); + + return it != m_subtrie.end() ? it->second : parameter_trie_ptr(); + } + + // Data members + trie_per_char m_subtrie; + param_cla_id_list m_id_candidates; + basic_param_ptr m_param_candidate; + bool m_has_final_candidate; }; +// ************************************************************************** // +// ************** runtime::cla::report_foreing_token ************** // +// ************************************************************************** // + +static void +report_foreing_token( cstring program_name, cstring token ) +{ + std::cerr << "Boost.Test WARNING: token \"" << token << "\" does not correspond to the Boost.Test argument \n" + << " and should be placed after all Boost.Test arguments and the -- separator.\n" + << " For example: " << program_name << " --random -- " << token << "\n"; } +} // namespace rt_cla_detail + // ************************************************************************** // // ************** runtime::cla::parser ************** // // ************************************************************************** // class parser { public: - typedef std::list<parameter_ptr>::const_iterator param_iterator; - typedef std::list<parameter_ptr>::size_type param_size_type; - - // Constructor - explicit parser( cstring program_name = cstring() ); + /// Initializes a parser and builds internal trie representation used for + /// parsing based on the supplied parameters +#ifndef BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS + template<typename Modifiers=nfp::no_params_type> + parser( parameters_store const& parameters, Modifiers const& m = nfp::no_params ) +#else + template<typename Modifiers> + parser( parameters_store const& parameters, Modifiers const& m ) +#endif + { + nfp::opt_assign( m_end_of_param_indicator, m, end_of_params ); + nfp::opt_assign( m_negation_prefix, m, negation_prefix ); - // parameter list construction interface - parser& operator<<( parameter_ptr param ); + BOOST_TEST_I_ASSRT( algorithm::all_of( m_end_of_param_indicator.begin(), + m_end_of_param_indicator.end(), + parameter_cla_id::valid_prefix_char ), + invalid_cla_id() << "End of parameters indicator can only consist of prefix characters." ); - // parser and global parameters modifiers - template<typename Modifier> - cla_detail::global_mod_parser<Modifier> - operator-( Modifier const& m ) - { - nfp::optionally_assign( m_traverser.p_separator.value, m, input_separator ); - nfp::optionally_assign( m_traverser.p_ignore_mismatch.value, m, ignore_mismatch_m ); + BOOST_TEST_I_ASSRT( algorithm::all_of( m_negation_prefix.begin(), + m_negation_prefix.end(), + parameter_cla_id::valid_name_char ), + invalid_cla_id() << "Negation prefix can only consist of prefix characters." ); - return cla_detail::global_mod_parser<Modifier>( *this, m ); + build_trie( parameters ); } // input processing method - void parse( int& argc, char_type** argv ); + int + parse( int argc, char** argv, runtime::arguments_store& res ) + { + // save program name for help message + m_program_name = argv[0]; + cstring path_sep( "\\/" ); + + cstring::iterator it = unit_test::utils::find_last_of( m_program_name.begin(), m_program_name.end(), + path_sep.begin(), path_sep.end() ); + if( it != m_program_name.end() ) + m_program_name.trim_left( it + 1 ); + + // Set up the traverser + argv_traverser tr( argc, (char const**)argv ); + + // Loop till we reach end of input + while( !tr.eoi() ) { + cstring curr_token = tr.current_token(); + + cstring prefix; + cstring name; + cstring value_separator; + bool negative_form = false; + + // Perform format validations and split the argument into prefix, name and separator + // False return value indicates end of params indicator is met + if( !validate_token_format( curr_token, prefix, name, value_separator, negative_form ) ) { + // get rid of "end of params" token + tr.next_token(); + break; + } + + // Locate trie corresponding to found prefix and skip it in the input + trie_ptr curr_trie = m_param_trie[prefix]; + + if( !curr_trie ) { + // format_error() << "Unrecognized parameter prefix in the argument " << tr.current_token() + rt_cla_detail::report_foreing_token( m_program_name, curr_token ); + tr.save_token(); + continue; + } + + curr_token.trim_left( prefix.size() ); + + // Locate parameter based on a name and skip it in the input + locate_result locate_res = locate_parameter( curr_trie, name, curr_token ); + parameter_cla_id const& found_id = locate_res.first; + basic_param_ptr found_param = locate_res.second; + + if( negative_form ) { + BOOST_TEST_I_ASSRT( found_id.m_negatable, + format_error( found_param->p_name ) + << "Parameter tag " << found_id.m_tag << " is not negatable." ); + + curr_token.trim_left( m_negation_prefix.size() ); + } + + curr_token.trim_left( name.size() ); + + cstring value; + + // Skip validations if parameter has optional value and we are at the end of token + if( !value_separator.is_empty() || !found_param->p_has_optional_value ) { + // Validate and skip value separator in the input + BOOST_TEST_I_ASSRT( found_id.m_value_separator == value_separator, + format_error( found_param->p_name ) + << "Invalid separator for the parameter " + << found_param->p_name + << " in the argument " << tr.current_token() ); + + curr_token.trim_left( value_separator.size() ); + + // Deduce value source + value = curr_token; + if( value.is_empty() ) { + tr.next_token(); + value = tr.current_token(); + } + + BOOST_TEST_I_ASSRT( !value.is_empty(), + format_error( found_param->p_name ) + << "Missing an argument value for the parameter " + << found_param->p_name + << " in the argument " << tr.current_token() ); + } + + // Validate against argument duplication + BOOST_TEST_I_ASSRT( !res.has( found_param->p_name ) || found_param->p_repeatable, + duplicate_arg( found_param->p_name ) + << "Duplicate argument value for the parameter " + << found_param->p_name + << " in the argument " << tr.current_token() ); + + // Produce argument value + found_param->produce_argument( value, negative_form, res ); + + tr.next_token(); + } + + // generate the remainder and return it's size + return tr.remainder(); + } - // parameters access - param_iterator first_param() const; - param_iterator last_param() const; - param_size_type num_params() const { return m_parameters.size(); } - void reset(); + // help/usage + void + usage( std::ostream& ostr, cstring param_name = cstring() ) + { + if( !param_name.is_empty() ) { + basic_param_ptr param = locate_parameter( m_param_trie[help_prefix], param_name, "" ).second; + param->usage( ostr, m_negation_prefix ); + } + else { + ostr << "Usage: " << m_program_name << " [Boost.Test argument]... "; + if( !m_end_of_param_indicator.empty() ) + ostr << m_end_of_param_indicator << " [custom test module argument]..."; + ostr << "\n"; + } + + ostr << "\nFor detailed help on Boost.Test parameters use:\n" + << " " << m_program_name << " --help\n" + << "or\n" + << " " << m_program_name << " --help=<parameter name>\n"; + } - // arguments access - const_argument_ptr operator[]( cstring string_id ) const; - cstring get( cstring string_id ) const; + void + help( std::ostream& ostr, parameters_store const& parameters, cstring param_name ) + { + if( !param_name.is_empty() ) { + basic_param_ptr param = locate_parameter( m_param_trie[help_prefix], param_name, "" ).second; + param->help( ostr, m_negation_prefix ); + return; + } + + ostr << "Usage: " << m_program_name << " [Boost.Test argument]... "; + if( !m_end_of_param_indicator.empty() ) + ostr << m_end_of_param_indicator << " [custom test module argument]..."; + + ostr << "\n\nBoost.Test arguments correspond to parameters listed below. " + "All parameters are optional. You can use specify parameter value either " + "as a command line argument or as a value of corresponding environment " + "variable. In case if argument for the same parameter is specified in both " + "places, command line is taking precedence. Command line argument format " + "supports parameter name guessing, so you can use any unambiguous " + "prefix to identify a parameter."; + if( !m_end_of_param_indicator.empty() ) + ostr << " All the arguments after the " << m_end_of_param_indicator << " are ignored by the Boost.Test."; + + ostr << "\n\nBoost.Test supports following parameters:\n"; + + BOOST_TEST_FOREACH( parameters_store::storage_type::value_type const&, v, parameters.all() ) { + basic_param_ptr param = v.second; + + param->usage( ostr, m_negation_prefix ); + } + + ostr << "\nUse --help=<parameter name> to display detailed help for specific parameter.\n"; + } - template<typename T> - T const& get( cstring string_id ) const +private: + typedef rt_cla_detail::parameter_trie_ptr trie_ptr; + typedef rt_cla_detail::trie_per_char trie_per_char; + typedef std::map<cstring,trie_ptr> str_to_trie; + + void + build_trie( parameters_store const& parameters ) { - return arg_value<T>( valid_argument( string_id ) ); + // Iterate over all parameters + BOOST_TEST_FOREACH( parameters_store::storage_type::value_type const&, v, parameters.all() ) { + basic_param_ptr param = v.second; + + // Register all parameter's ids in trie. + BOOST_TEST_FOREACH( parameter_cla_id const&, id, param->cla_ids() ) { + // This is the trie corresponding to the prefix. + trie_ptr next_trie = m_param_trie[id.m_prefix]; + if( !next_trie ) + next_trie = m_param_trie[id.m_prefix] = trie_ptr( new rt_cla_detail::parameter_trie ); + + // Build the trie, by following name's characters + // and register this parameter as candidate on each level + for( size_t index = 0; index < id.m_tag.size(); ++index ) { + next_trie = next_trie->make_subtrie( id.m_tag[index] ); + + next_trie->add_candidate_id( id, param, index == (id.m_tag.size() - 1) ); + } + } + } } - template<typename T> - void get( cstring string_id, boost::optional<T>& res ) const + bool + validate_token_format( cstring token, cstring& prefix, cstring& name, cstring& separator, bool& negative_form ) { - const_argument_ptr actual_arg = (*this)[string_id]; + // Match prefix + cstring::iterator it = token.begin(); + while( it != token.end() && parameter_cla_id::valid_prefix_char( *it ) ) + ++it; - if( actual_arg ) - res = arg_value<T>( *actual_arg ); - else - res.reset(); - } + prefix.assign( token.begin(), it ); - // help/usage - void usage( out_stream& ostr ); - void help( out_stream& ostr ); + if( prefix.empty() ) + return true; -private: - argument const& valid_argument( cstring string_id ) const; + // Match name + while( it != token.end() && parameter_cla_id::valid_name_char( *it ) ) + ++it; - // Data members - argv_traverser m_traverser; - std::list<parameter_ptr> m_parameters; - dstring m_program_name; -}; + name.assign( prefix.end(), it ); -//____________________________________________________________________________// + if( name.empty() ) { + if( prefix == m_end_of_param_indicator ) + return false; -} // namespace cla + BOOST_TEST_I_THROW( format_error() << "Invalid format for an actual argument " << token ); + } -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE + // Match value separator + while( it != token.end() && parameter_cla_id::valid_separator_char( *it ) ) + ++it; -} // namespace boost + separator.assign( name.end(), it ); -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_OFFLINE + // Match negation prefix + negative_form = !m_negation_prefix.empty() && ( name.substr( 0, m_negation_prefix.size() ) == m_negation_prefix ); + if( negative_form ) + name.trim_left( m_negation_prefix.size() ); -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -# define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE inline -#endif -# include <boost/test/utils/runtime/cla/parser.ipp> + return true; + } + // C++03: cannot have references as types + typedef std::pair<parameter_cla_id, basic_param_ptr> locate_result; + + locate_result + locate_parameter( trie_ptr curr_trie, cstring name, cstring token ) + { + std::vector<trie_ptr> typo_candidates; + std::vector<trie_ptr> next_typo_candidates; + trie_ptr next_trie; + + BOOST_TEST_FOREACH( char, c, name ) { + if( curr_trie ) { + // locate next subtrie corresponding to the char + next_trie = curr_trie->get_subtrie( c ); + + if( next_trie ) + curr_trie = next_trie; + else { + // Initiate search for typo candicates. We will account for 'wrong char' typo + // 'missing char' typo and 'extra char' typo + BOOST_TEST_FOREACH( trie_per_char::value_type const&, typo_cand, curr_trie->m_subtrie ) { + // 'wrong char' typo + typo_candidates.push_back( typo_cand.second ); + + // 'missing char' typo + if( (next_trie = typo_cand.second->get_subtrie( c )) ) + typo_candidates.push_back( next_trie ); + } + + // 'extra char' typo + typo_candidates.push_back( curr_trie ); + + curr_trie.reset(); + } + } + else { + // go over existing typo candidates and see if they are still viable + BOOST_TEST_FOREACH( trie_ptr, typo_cand, typo_candidates ) { + trie_ptr next_typo_cand = typo_cand->get_subtrie( c ); + + if( next_typo_cand ) + next_typo_candidates.push_back( next_typo_cand ); + } + + next_typo_candidates.swap( typo_candidates ); + next_typo_candidates.clear(); + } + } + + if( !curr_trie ) { + std::vector<cstring> typo_candidate_names; + std::set<parameter_cla_id const*> unique_typo_candidate; // !! ?? unordered_set + typo_candidate_names.reserve( typo_candidates.size() ); +// !! ?? unique_typo_candidate.reserve( typo_candidates.size() ); + + BOOST_TEST_FOREACH( trie_ptr, trie_cand, typo_candidates ) { + // avoid ambiguos candidate trie + if( trie_cand->m_id_candidates.size() > 1 ) + continue; + + BOOST_TEST_FOREACH( parameter_cla_id const&, param_cand, trie_cand->m_id_candidates ) { + if( !unique_typo_candidate.insert( ¶m_cand ).second ) + continue; + + typo_candidate_names.push_back( param_cand.m_tag ); + } + } + +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + BOOST_TEST_I_THROW( unrecognized_param( std::move(typo_candidate_names) ) + << "An unrecognized parameter in the argument " + << token ); +#else + BOOST_TEST_I_THROW( unrecognized_param( typo_candidate_names ) + << "An unrecognized parameter in the argument " + << token ); #endif + } + + if( curr_trie->m_id_candidates.size() > 1 ) { + std::vector<cstring> amb_names; + BOOST_TEST_FOREACH( parameter_cla_id const&, param_id, curr_trie->m_id_candidates ) + amb_names.push_back( param_id.m_tag ); + +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + BOOST_TEST_I_THROW( ambiguous_param( std::move( amb_names ) ) + << "An ambiguous parameter name in the argument " << token ); +#else + BOOST_TEST_I_THROW( ambiguous_param( amb_names ) + << "An ambiguous parameter name in the argument " << token ); +#endif + } + + return locate_result( curr_trie->m_id_candidates.back().get(), curr_trie->m_param_candidate ); + } + + // Data members + cstring m_program_name; + std::string m_end_of_param_indicator; + std::string m_negation_prefix; + str_to_trie m_param_trie; +}; + +} // namespace cla +} // namespace runtime +} // namespace boost + +#include <boost/test/detail/enable_warnings.hpp> #endif // BOOST_TEST_UTILS_RUNTIME_CLA_PARSER_HPP diff --git a/boost/test/utils/runtime/cla/parser.ipp b/boost/test/utils/runtime/cla/parser.ipp deleted file mode 100644 index b8a4ca4636..0000000000 --- a/boost/test/utils/runtime/cla/parser.ipp +++ /dev/null @@ -1,267 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : implements parser - public interface for CLA parsing and accessing -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_PARSER_IPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_PARSER_IPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> -#include <boost/test/utils/runtime/trace.hpp> -#include <boost/test/utils/runtime/argument.hpp> - -#include <boost/test/utils/runtime/cla/argv_traverser.hpp> -#include <boost/test/utils/runtime/cla/parameter.hpp> -#include <boost/test/utils/runtime/cla/modifier.hpp> -#include <boost/test/utils/runtime/cla/validation.hpp> -#include <boost/test/utils/runtime/cla/parser.hpp> - -// Boost.Test -#include <boost/test/utils/basic_cstring/io.hpp> -#include <boost/test/utils/foreach.hpp> - -// Boost -#include <boost/lexical_cast.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** runtime::cla::parser ************** // -// ************************************************************************** // - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -parser::parser( cstring program_name ) -{ - assign_op( m_program_name, program_name, 0 ); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE parser::param_iterator -parser::first_param() const -{ - return m_parameters.begin(); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE parser::param_iterator -parser::last_param() const -{ - return m_parameters.end(); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE argument const& -parser::valid_argument( cstring string_id ) const -{ - const_argument_ptr arg = (*this)[string_id]; - - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( !!arg, "Actual argument for parameter " << string_id << " is not present" ); - - return *arg; -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE parser& -parser::operator<<( parameter_ptr new_param ) -{ - BOOST_TEST_FOREACH( parameter_ptr, old_param, m_parameters ) { - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( !old_param->conflict_with( *new_param ), - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "Definition of parameter " ) << new_param->id_2_report() << - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( " conflicts with defintion of parameter " ) << old_param->id_2_report() ); - } - - m_parameters.push_back( new_param ); - - return *this; -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -parser::parse( int& argc, char_type** argv ) -{ - if( m_program_name.empty() ) { - m_program_name.assign( argv[0] ); - dstring::size_type pos = m_program_name.find_last_of( BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "/\\" ) ); - - if( pos != static_cast<dstring::size_type>(cstring::npos) ) - m_program_name.erase( 0, pos+1 ); - } - - m_traverser.init( argc, argv ); - - BOOST_TEST_IMPL_TRY { - while( !m_traverser.eoi() ) { - parameter_ptr found_param; - - BOOST_TEST_UTILS_RUNTIME_PARAM_TRACE( "Total " << m_parameters.size() << " parameters registered" ); - - BOOST_TEST_FOREACH( parameter_ptr const&, curr_param, m_parameters ) { - BOOST_TEST_UTILS_RUNTIME_PARAM_TRACE( "Try parameter " << curr_param->id_2_report() ); - - if( curr_param->matching( m_traverser, !found_param ) ) { - BOOST_TEST_UTILS_RUNTIME_PARAM_TRACE( "Match found" ); - BOOST_TEST_UTILS_RUNTIME_CLA_VALIDATE_INPUT( !found_param, (m_traverser.rollback(),m_traverser), "Ambiguous input" ); - - found_param = curr_param; - } - - m_traverser.rollback(); - } - - if( !found_param ) { - BOOST_TEST_UTILS_RUNTIME_PARAM_TRACE( "No match found" ); - BOOST_TEST_UTILS_RUNTIME_CLA_VALIDATE_INPUT( m_traverser.handle_mismatch(), m_traverser, - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "Unexpected input" ) ); - - continue; - } - - BOOST_TEST_UTILS_RUNTIME_PARAM_TRACE( "Parse argument value" ); - found_param->produce_argument( m_traverser ); - - m_traverser.commit(); - } - - BOOST_TEST_FOREACH( parameter_ptr const&, curr_param, m_parameters ) { - if( !curr_param->p_optional && !curr_param->actual_argument() ) { - curr_param->produce_argument( *this ); - - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( curr_param->actual_argument(), - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "Required argument for parameter " ) << curr_param->id_2_report() - << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( " is missing" ) ); - } - } - } - BOOST_TEST_IMPL_CATCH0( bad_lexical_cast ) { - BOOST_TEST_UTILS_RUNTIME_PARAM_REPORT_LOGIC_ERROR( - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "String to value convertion error during input parsing" ) ); - }; - - m_traverser.remainder( argc, argv ); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE const_argument_ptr -parser::operator[]( cstring string_id ) const -{ - parameter_ptr found_param; - - BOOST_TEST_FOREACH( parameter_ptr const&, curr_param, m_parameters ) { - if( curr_param->responds_to( string_id ) ) { - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( !found_param, - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "Ambiguous parameter string id: " ) << string_id ); - - found_param = curr_param; - } - } - - return found_param ? found_param->actual_argument() : argument_ptr(); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE cstring -parser::get( cstring string_id ) const -{ - return get<cstring>( string_id ); -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -parser::usage( out_stream& ostr ) -{ - if( m_program_name.empty() ) - assign_op( m_program_name, BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "<program>" ), 0 ); - - format_stream fs; - - fs << m_program_name; - - BOOST_TEST_FOREACH( parameter_ptr const&, curr_param, m_parameters ) { - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( ' ' ); - - if( curr_param->p_optional ) - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( '[' ); - - curr_param->usage_info( fs ); - - if( curr_param->p_optional ) - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( ']' ); - - if( curr_param->p_multiplicable ) { - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( " ... " ); - - if( curr_param->p_optional ) - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( '[' ); - - curr_param->usage_info( fs ); - - if( curr_param->p_optional ) - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( ']' ); - } - } - - ostr << BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "Usage:\n" ) << fs.str() << std::endl; -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -parser::help( out_stream& ostr ) -{ - usage( ostr ); - - bool need_where = true; - - BOOST_TEST_FOREACH( parameter_ptr const&, curr_param, m_parameters ) { - if( curr_param->p_description->empty() ) - continue; - - if( need_where ) { - ostr << BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "where:\n" ); - need_where = false; - } - - ostr << curr_param->id_2_report() << BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( " - " ) << curr_param->p_description << std::endl; - } -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -parser::reset() -{ - BOOST_TEST_FOREACH( parameter_ptr const&, param, m_parameters ) - param->reset(); -} - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_PARSER_IPP diff --git a/boost/test/utils/runtime/cla/positional_parameter.hpp b/boost/test/utils/runtime/cla/positional_parameter.hpp deleted file mode 100644 index f378743dd5..0000000000 --- a/boost/test/utils/runtime/cla/positional_parameter.hpp +++ /dev/null @@ -1,91 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : positional parameter model -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_POSITIONAL_PARAMETER_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_POSITIONAL_PARAMETER_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/basic_parameter.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** trivial_id_policy ************** // -// ************************************************************************** // - -class trivial_id_policy : public identification_policy { -public: - trivial_id_policy() - : identification_policy( rtti::type_id<trivial_id_policy>() ) - {} - BOOST_TEST_UTILS_RUNTIME_PARAM_UNNEEDED_VIRTUAL ~trivial_id_policy() {} - - virtual bool responds_to( cstring name ) const { return m_name == name; } - virtual bool conflict_with( identification_policy const& ) const { return false; } - virtual cstring id_2_report() const { return m_name; } - virtual void usage_info( format_stream& fs ) const - { - if( !m_name.empty() ) - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( '<' ) << m_name << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( '>' ); - else - fs << BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "<value>" ); - } - - virtual bool matching( parameter const& p, argv_traverser&, bool primary ) const - { - return primary && ( !p.has_argument() || p.p_multiplicable ); - } - - template<typename Modifier> - void accept_modifier( Modifier const& m ) - { - nfp::optionally_assign( m_name, m, name ); - } - -private: - // Data members - dstring m_name; -}; - -// ************************************************************************** // -// ************** runtime::cla::positional_parameter ************** // -// ************************************************************************** // - -template<typename T> -class positional_parameter_t : public basic_parameter<T,trivial_id_policy> { - typedef basic_parameter<T,trivial_id_policy> base; -public: - // Constructors - explicit positional_parameter_t( cstring name ) - : base( name ) - {} -}; - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_CLA_NAMED_PARAM_GENERATORS( positional_parameter ) - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_POSITIONAL_PARAMETER_HPP diff --git a/boost/test/utils/runtime/cla/typed_parameter.hpp b/boost/test/utils/runtime/cla/typed_parameter.hpp deleted file mode 100644 index 70c5bbc009..0000000000 --- a/boost/test/utils/runtime/cla/typed_parameter.hpp +++ /dev/null @@ -1,70 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : generic typed parameter model -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_TYPED_PARAMETER_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_TYPED_PARAMETER_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/fwd.hpp> -#include <boost/test/utils/runtime/validation.hpp> - -#include <boost/test/utils/runtime/cla/parameter.hpp> -#include <boost/test/utils/runtime/cla/argument_factory.hpp> - -// Boost.Test -#include <boost/test/utils/rtti.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** runtime::cla::typed_parameter ************** // -// ************************************************************************** // - -template<typename T> -class typed_parameter : public cla::parameter { -public: - explicit typed_parameter( identification_policy& ID ) - : cla::parameter( ID, m_arg_factory, rtti::type_id<T>() == rtti::type_id<bool>() ) - {} - - // parameter properties modification - template<typename Modifier> - void accept_modifier( Modifier const& m ) - { - cla::parameter::accept_modifier( m ); - - m_arg_factory.accept_modifier( m ); - - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( !p_optional || !m_arg_factory.m_value_generator, - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "can't define a value generator for optional parameter " ) << id_2_report() ); - } - -private: - // Data members - typed_argument_factory<T> m_arg_factory; -}; - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_TYPED_PARAMETER_HPP diff --git a/boost/test/utils/runtime/cla/validation.cpp b/boost/test/utils/runtime/cla/validation.cpp deleted file mode 100644 index 7f19a5ca45..0000000000 --- a/boost/test/utils/runtime/cla/validation.cpp +++ /dev/null @@ -1,16 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : input validation helpers offline implementation -// *************************************************************************** - -#define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -#include <boost/test/utils/runtime/cla/validation.ipp> diff --git a/boost/test/utils/runtime/cla/validation.hpp b/boost/test/utils/runtime/cla/validation.hpp deleted file mode 100644 index 8a3da14c5b..0000000000 --- a/boost/test/utils/runtime/cla/validation.hpp +++ /dev/null @@ -1,57 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : input validation helpers definition -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_VALIDATION_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_VALIDATION_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/fwd.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** runtime::cla::report_input_error ************** // -// ************************************************************************** // - -void report_input_error( argv_traverser const& tr, format_stream& msg ); - -//____________________________________________________________________________// - -#define BOOST_TEST_UTILS_RUNTIME_CLA_VALIDATE_INPUT( b, tr, msg ) \ - if( b ) ; else ::boost::BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE::cla::report_input_error( tr, format_stream().ref() << msg ) - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_OFFLINE - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -# define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE inline -#endif -# include <boost/test/utils/runtime/cla/validation.ipp> - -#endif - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_VALIDATION_HPP diff --git a/boost/test/utils/runtime/cla/validation.ipp b/boost/test/utils/runtime/cla/validation.ipp deleted file mode 100644 index 9d8cd27b4a..0000000000 --- a/boost/test/utils/runtime/cla/validation.ipp +++ /dev/null @@ -1,61 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 Input validation helpers implementation -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_VALIDATION_IPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_VALIDATION_IPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/argv_traverser.hpp> -#include <boost/test/utils/runtime/cla/validation.hpp> -#include <boost/test/utils/runtime/validation.hpp> // BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE::logic_error - -// Boost.Test -#include <boost/test/utils/basic_cstring/io.hpp> -#include <boost/test/detail/throw_exception.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -// ************************************************************************** // -// ************** runtime::cla::validation ************** // -// ************************************************************************** // - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -report_input_error( argv_traverser const& tr, format_stream& msg ) -{ - if( tr.eoi() ) - msg << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( " at the end of input" ); - else { - msg << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( " in the following position: " ); - - if( tr.input().size() > 5 ) - msg << tr.input().substr( 0, 5 ) << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "..." ); - else - msg << tr.input(); - } - - BOOST_TEST_IMPL_THROW( BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE::logic_error( msg.str() ) ); -} - -//____________________________________________________________________________// - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_VALIDATION_IPP diff --git a/boost/test/utils/runtime/cla/value_generator.hpp b/boost/test/utils/runtime/cla/value_generator.hpp deleted file mode 100644 index 0efc25def1..0000000000 --- a/boost/test/utils/runtime/cla/value_generator.hpp +++ /dev/null @@ -1,81 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : specific value generators -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_VALUE_GENERATOR_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_VALUE_GENERATOR_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/fwd.hpp> -#include <boost/test/utils/runtime/cla/parser.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -namespace rt_cla_detail { - -// ************************************************************************** // -// ************** runtime::cla::const_generator ************** // -// ************************************************************************** // - -template<typename T> -class const_generator { -public: - // Constructor - explicit const_generator( T const& t ) : m_const_value( t ) {} - - // generator interface - void operator()( parser const&, boost::optional<T>& t ) const { t = m_const_value; } - -private: - // Data members - T m_const_value; -}; - -// ************************************************************************** // -// ************** runtime::cla::ref_generator ************** // -// ************************************************************************** // - -template<typename T> -class ref_generator { -public: - // Constructor - explicit ref_generator( cstring ref_id ) : m_ref_id( ref_id ) {} - - // generator interface - void operator()( parser const& p, boost::optional<T>& t ) const - { - p.get( m_ref_id, t ); - } - -private: - // Data members - cstring m_ref_id; -}; - -//____________________________________________________________________________// - -} // namespace rt_cla_detail - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_VALUE_GENERATOR_HPP diff --git a/boost/test/utils/runtime/cla/value_handler.hpp b/boost/test/utils/runtime/cla/value_handler.hpp deleted file mode 100644 index 38792602ac..0000000000 --- a/boost/test/utils/runtime/cla/value_handler.hpp +++ /dev/null @@ -1,57 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : specific value handlers -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CLA_VALUE_HANDLER_HPP -#define BOOST_TEST_UTILS_RUNTIME_CLA_VALUE_HANDLER_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/cla/fwd.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace cla { - -namespace rt_cla_detail { - -// ************************************************************************** // -// ************** runtime::cla::assigner ************** // -// ************************************************************************** // - -template<typename T> -class assigner { -public: - // Constructor - explicit assigner( T& loc ) : m_target( loc ) {} - - // value handler implementation - void operator()( parameter const&, T& t ) { m_target = t; } - -private: - // Data members - T& m_target; -}; - -} // namespace rt_cla_detail - -} // namespace cla - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CLA_VALUE_HANDLER_HPP diff --git a/boost/test/utils/runtime/config.hpp b/boost/test/utils/runtime/config.hpp deleted file mode 100644 index dfa9ae30de..0000000000 --- a/boost/test/utils/runtime/config.hpp +++ /dev/null @@ -1,162 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : Runtime.Param library configuration -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CONFIG_HPP -#define BOOST_TEST_UTILS_RUNTIME_CONFIG_HPP - -// Boost -#include <boost/config.hpp> -#ifdef BOOST_MSVC -# pragma warning(disable: 4511) // copy constructor could not be generated -# pragma warning(disable: 4512) // assignment operator could not be generated -# pragma warning(disable: 4181) // qualifier applied to reference type; ignored -# pragma warning(disable: 4675) // resolved overload was found by argument-dependent lookup -#endif - -// Boost.Test -#include <boost/test/detail/config.hpp> -#include <boost/test/utils/basic_cstring/basic_cstring.hpp> -#include <boost/test/utils/wrap_stringstream.hpp> -#include <boost/test/utils/basic_cstring/io.hpp> // operator<<(boost::runtime::cstring) - -// STL -#include <string> -#include <cstdlib> - -#ifdef __SUNPRO_CC - #include <stdlib.h> -#endif - -//____________________________________________________________________________// - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_CUSTOM_STRING -# ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_WIDE_STRING -# define BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE runtime -# else -# define BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE wide_runtime -# endif -#endif - - - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_CUSTOM_STRING -# ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_WIDE_STRING - -typedef char char_type; -typedef std::string dstring; -typedef unit_test::const_string cstring; -typedef unit_test::literal_string literal_cstring; -typedef wrap_stringstream format_stream; - -#ifdef BOOST_CLASSIC_IOSTREAMS -typedef std::ostream out_stream; -#else -typedef std::basic_ostream<char_type> out_stream; -#endif - -#ifdef BOOST_MSVC -#pragma warning(push) -#pragma warning(disable:4996) // putenv -#endif - -#if defined(__MINGW32__) -extern "C" int putenv( const char * ); -#endif - -#ifndef UNDER_CE -#if defined(__COMO__) && 0 -inline void -putenv_impl( cstring name, cstring value ) -{ - using namespace std; - // !! this may actually fail. What should we do? - setenv( name.begin(), value.begin(), 1 ); -} -#else -inline void -putenv_impl( cstring name, cstring value ) -{ - format_stream fs; - - fs << name << '=' << value; - - // !! this may actually fail. What should we do? - // const_cast is used to satisfy putenv interface - using namespace std; - putenv( const_cast<char*>( fs.str().c_str() ) ); -} -#endif -#endif - -#ifdef BOOST_MSVC -#pragma warning(pop) -#endif - -#define BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( l ) l -#define BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( l ) cstring( l, sizeof( l ) - 1 ) -#define BOOST_TEST_UTILS_RUNTIME_PARAM_GETENV getenv -#define BOOST_TEST_UTILS_RUNTIME_PARAM_PUTENV ::boost::BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE::putenv_impl -#define BOOST_TEST_UTILS_RUNTIME_PARAM_EXCEPTION_INHERIT_STD - -//____________________________________________________________________________// - -# else - -typedef wchar_t char_type; -typedef std::basic_string<char_type> dstring; -typedef unit_test::basic_cstring<wchar_t const> cstring; -typedef const unit_test::basic_cstring<wchar_t const> literal_cstring; -typedef wrap_wstringstream format_stream; -typedef std::wostream out_stream; - -#ifndef UNDER_CE -inline void -putenv_impl( cstring name, cstring value ) -{ - format_stream fs; - - fs << name << '=' << value; - - // !! this may actually fail. What should we do? - // const_cast is used to satisfy putenv interface - using namespace std; - wputenv( const_cast<wchar_t*>( fs.str().c_str() ) ); -} -#endif - -#define BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( l ) L ## l -#define BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( l ) cstring( L ## l, sizeof( L ## l )/sizeof(wchar_t) - 1 ) -#define BOOST_TEST_UTILS_RUNTIME_PARAM_GETENV wgetenv -#define BOOST_TEST_UTILS_RUNTIME_PARAM_PUTENV putenv_impl - -# endif -#endif - -#ifdef __GNUC__ -#define BOOST_TEST_UTILS_RUNTIME_PARAM_UNNEEDED_VIRTUAL virtual -#else -#define BOOST_TEST_UTILS_RUNTIME_PARAM_UNNEEDED_VIRTUAL -#endif - -//____________________________________________________________________________// - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CONFIG_HPP diff --git a/boost/test/utils/runtime/configuration.hpp b/boost/test/utils/runtime/configuration.hpp deleted file mode 100644 index bf731736ee..0000000000 --- a/boost/test/utils/runtime/configuration.hpp +++ /dev/null @@ -1,61 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : abstract interface for the formal parameter -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_CONFIGURATION_HPP -#define BOOST_TEST_UTILS_RUNTIME_CONFIGURATION_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> -#include <boost/test/utils/runtime/parameter.hpp> -#include <boost/test/utils/runtime/argument.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -// ************************************************************************** // -// ************** runtime::configuration ************** // -// ************************************************************************** // - -class config_source { - virtual parameter const& config_param_begin() const = 0; - virtual parameter const& config_param_end() const = 0; - -protected: - config_source() {} - ~config_source() {} -}; - -// ************************************************************************** // -// ************** runtime::configuration ************** // -// ************************************************************************** // - -template<typename StoragePolicy,typename IdentificationPlicy,typename ConflictResolutionPolicy> -class configuration : public StoragePolicy, public IdentificationPlicy, public ConflictResolutionPolicy { -public: - // Constructor - configuration(); - - void use( config_source const& ) - { - - } -private: -}; - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_CONFIGURATION_HPP diff --git a/boost/test/utils/runtime/env/environment.cpp b/boost/test/utils/runtime/env/environment.cpp deleted file mode 100644 index ddf47b342c..0000000000 --- a/boost/test/utils/runtime/env/environment.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2004-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : implements offline model of program environment -// *************************************************************************** - -#include <boost/test/utils/runtime/config.hpp> - -#ifdef BOOST_MSVC -# pragma warning(disable: 4127) // conditional expression is constant -# pragma warning(disable: 4701) // local environment 'result' may be used without having been initialized -#endif - -#define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -#include <boost/test/utils/runtime/env/environment.ipp> diff --git a/boost/test/utils/runtime/env/environment.hpp b/boost/test/utils/runtime/env/environment.hpp deleted file mode 100644 index 62b2ae6dc1..0000000000 --- a/boost/test/utils/runtime/env/environment.hpp +++ /dev/null @@ -1,171 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : defines and implements inline model of program environment -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_ENV_ENVIRONMENT_HPP -#define BOOST_TEST_UTILS_RUNTIME_ENV_ENVIRONMENT_HPP - -#ifdef UNDER_CE -#error Windows CE does not support environment variables. -#endif - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> -#include <boost/test/utils/runtime/fwd.hpp> -#include <boost/test/utils/runtime/argument.hpp> -#include <boost/test/utils/runtime/interpret_argument_value.hpp> - -#include <boost/test/utils/runtime/env/fwd.hpp> -#include <boost/test/utils/runtime/env/modifier.hpp> -#include <boost/test/utils/runtime/env/variable.hpp> - -// Boost -#include <boost/optional.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -// ************************************************************************** // -// ************** runtime::environment implementation ************** // -// ************************************************************************** // - -namespace environment { - -namespace rt_env_detail { - -template<typename T, typename Modifiers> -variable_data& -init_new_var( cstring var_name, Modifiers m = nfp::no_params ) -{ - rt_env_detail::variable_data& new_vd = new_var_record( var_name ); - - cstring str_value = sys_read_var( new_vd.m_var_name ); - - if( !str_value.is_empty() ) { - BOOST_TEST_IMPL_TRY { - boost::optional<T> value; - - if( m.has( interpreter ) ) - m[interpreter]( str_value, value ); - else - interpret_argument_value( str_value, value, 0 ); - - if( !!value ) { - new_vd.m_value.reset( new typed_argument<T>( new_vd ) ); - - arg_value<T>( *new_vd.m_value ) = *value; - } - } - BOOST_TEST_IMPL_CATCHALL() { // !! could we do that - // !! should we report an error? - } - } - - if( !new_vd.m_value && m.has( default_value ) ) { - new_vd.m_value.reset( new typed_argument<T>( new_vd ) ); - - nfp::optionally_assign( arg_value<T>( *new_vd.m_value ), m[default_value] ); - } - - nfp::optionally_assign( new_vd.m_global_id, m, global_id ); - - return new_vd; -} - -//____________________________________________________________________________// - -} // namespace rt_env_detail - -} // namespace environment - -// ************************************************************************** // -// ************** runtime::environment ************** // -// ************************************************************************** // - -namespace environment { - - // variable access - variable_base - var( cstring var_name ); - - //________________________________________________________________________// - - template<typename T> - inline variable<T> - var( cstring var_name ) - { - rt_env_detail::variable_data* vd = rt_env_detail::find_var_record( var_name ); - - return environment::variable<T>( !vd ? rt_env_detail::init_new_var<T>( var_name, nfp::no_params ) : *vd ); - } - - //________________________________________________________________________// - - template<typename T, typename Modifiers> - inline variable<T> - var( cstring var_name, Modifiers const& m ) - { - rt_env_detail::variable_data* vd = rt_env_detail::find_var_record( var_name ); - - return environment::variable<T>( !vd ? rt_env_detail::init_new_var<T>( var_name, m ) : *vd ); - } - - //________________________________________________________________________// - - // direct variable value access - inline cstring - get( cstring var_name ) - { - return environment::var<cstring>( var_name ).value(); - } - - //________________________________________________________________________// - - template<typename T> - inline T const& - get( cstring var_name ) - { - return environment::var<T>( var_name ).value(); - } - - //________________________________________________________________________// - - template<typename T> - inline void - get( cstring var_name, boost::optional<T>& res ) - { - variable<T> const& v = environment::var<T>( var_name ); - v.value( res ); - } - - //________________________________________________________________________// - -} // namespace environment - -namespace env = environment; - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_OFFLINE - -#ifndef BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE -# define BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE inline -#endif -# include <boost/test/utils/runtime/env/environment.ipp> - -#endif - -#endif // BOOST_TEST_UTILS_RUNTIME_ENV_ENVIRONMENT_HPP diff --git a/boost/test/utils/runtime/env/environment.ipp b/boost/test/utils/runtime/env/environment.ipp deleted file mode 100644 index 6baf72f430..0000000000 --- a/boost/test/utils/runtime/env/environment.ipp +++ /dev/null @@ -1,125 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : implements model of program environment -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_ENV_ENVIRONMENT_IPP -#define BOOST_TEST_UTILS_RUNTIME_ENV_ENVIRONMENT_IPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> -#include <boost/test/utils/runtime/validation.hpp> - -#include <boost/test/utils/runtime/env/variable.hpp> - -// Boost.Test -#include <boost/test/utils/basic_cstring/compare.hpp> -#include <boost/test/utils/basic_cstring/io.hpp> - -// STL -#include <map> -#include <list> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace environment { - -// ************************************************************************** // -// ************** runtime::environment ************** // -// ************************************************************************** // - -namespace rt_env_detail { - -typedef std::map<cstring,rt_env_detail::variable_data> registry; -typedef std::list<dstring> keys; - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE registry& s_registry() { static registry instance; return instance; } -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE keys& s_keys() { static keys instance; return instance; } - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE variable_data& -new_var_record( cstring var_name ) -{ - // save the name in list of keys - s_keys().push_back( dstring() ); - dstring& key = s_keys().back(); - assign_op( key, var_name, 0 ); - - // create and return new record - variable_data& new_var_data = s_registry()[key]; - - new_var_data.m_var_name = key; - - return new_var_data; -} - -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE variable_data* -find_var_record( cstring var_name ) -{ - registry::iterator it = s_registry().find( var_name ); - - return it == s_registry().end() ? 0 : &(it->second); -} - -//____________________________________________________________________________// - -#ifdef BOOST_MSVC -#pragma warning(push) -#pragma warning(disable:4996) // getenv -#endif - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE cstring -sys_read_var( cstring var_name ) -{ - using namespace std; - return BOOST_TEST_UTILS_RUNTIME_PARAM_GETENV( var_name.begin() ); -} - -#ifdef BOOST_MSVC -#pragma warning(pop) -#endif -//____________________________________________________________________________// - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE void -sys_write_var( cstring var_name, format_stream& var_value ) -{ - BOOST_TEST_UTILS_RUNTIME_PARAM_PUTENV( var_name, cstring( var_value.str() ) ); -} - -//____________________________________________________________________________// - -} // namespace rt_env_detail - -BOOST_TEST_UTILS_RUNTIME_PARAM_INLINE variable_base -var( cstring var_name ) -{ - rt_env_detail::variable_data* vd = rt_env_detail::find_var_record( var_name ); - - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( !!vd, - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "First access to the environment variable " ) - << var_name << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( " should be typed" ) ); - - return variable_base( *vd ); -} - -//____________________________________________________________________________// - -} // namespace environment - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_ENV_ENVIRONMENT_IPP_062904GER diff --git a/boost/test/utils/runtime/env/fetch.hpp b/boost/test/utils/runtime/env/fetch.hpp new file mode 100644 index 0000000000..97d54d4905 --- /dev/null +++ b/boost/test/utils/runtime/env/fetch.hpp @@ -0,0 +1,108 @@ +// (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 : $RCSfile$ +// +// Version : $Revision$ +// +// Description : implements fetching absent parameter athuments from environment +// *************************************************************************** + +#ifndef BOOST_TEST_UTILS_RUNTIME_ENV_FETCH_HPP +#define BOOST_TEST_UTILS_RUNTIME_ENV_FETCH_HPP + +// Boost.Test Runtime parameters +#include <boost/test/utils/runtime/parameter.hpp> +#include <boost/test/utils/runtime/argument.hpp> + +#include <boost/test/detail/suppress_warnings.hpp> + +// C Runtime +#include <stdlib.h> + +namespace boost { +namespace runtime { +namespace env { + +namespace env_detail { + +#ifndef UNDER_CE + +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:4996) // getenv +#endif + +inline std::pair<cstring,bool> +sys_read_var( cstring var_name ) +{ + using namespace std; + char const* res = getenv( var_name.begin() ); + + return std::make_pair( cstring(res), res != NULL ); +} + +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif + +#else + +inline std::pair<cstring,bool> +sys_read_var( cstring var_name ) +{ + return std::make_pair( cstring(), false ); +} + +#endif + +//____________________________________________________________________________// + +template<typename ReadFunc> +inline void +fetch_absent( parameters_store const& params, runtime::arguments_store& args, ReadFunc read_func ) +{ + BOOST_TEST_FOREACH( parameters_store::storage_type::value_type const&, v, params.all() ) { + basic_param_ptr param = v.second; + + if( args.has( param->p_name ) || param->p_env_var.empty() ) + continue; + + std::pair<cstring,bool> value = read_func( param->p_env_var ); + + if( !value.second ) + continue; + + // Validate against unexpected empty value + BOOST_TEST_I_ASSRT( !value.first.is_empty() || param->p_has_optional_value, + format_error( param->p_name ) + << "Missing an argument value for the parameter " << param->p_name + << " in the environment." ); + + // Produce argument value + param->produce_argument( value.first, false, args ); + + } +} + +//____________________________________________________________________________// + +} // namespace env_detail + +inline void +fetch_absent( parameters_store const& params, runtime::arguments_store& args ) +{ + env_detail::fetch_absent( params, args, &env_detail::sys_read_var ); +} + +} // namespace env +} // namespace runtime +} // namespace boost + +#include <boost/test/detail/enable_warnings.hpp> + +#endif // BOOST_TEST_UTILS_RUNTIME_ENV_FETCH_HPP diff --git a/boost/test/utils/runtime/env/fwd.hpp b/boost/test/utils/runtime/env/fwd.hpp deleted file mode 100644 index 438795ea8f..0000000000 --- a/boost/test/utils/runtime/env/fwd.hpp +++ /dev/null @@ -1,61 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : environment subsystem forward declarations -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_ENV_FWD_HPP -#define BOOST_TEST_UTILS_RUNTIME_ENV_FWD_HPP - -#ifdef UNDER_CE -#error Windows CE does not support environment variables. -#endif - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace environment { - -template<typename T> -class variable; - -class variable_base; -variable_base var( cstring var_name ); - -template<typename T> -inline variable<T> - var( cstring var_name ); - -namespace rt_env_detail { - -struct variable_data; - -variable_data& new_var_record( cstring var_name ); -variable_data* find_var_record( cstring var_name ); - -cstring sys_read_var( cstring var_name ); -void sys_write_var( cstring var_name, format_stream& var_value ); - -} - -template <typename T> class variable; - -} // namespace environment - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_ENV_FWD_HPP diff --git a/boost/test/utils/runtime/env/modifier.hpp b/boost/test/utils/runtime/env/modifier.hpp deleted file mode 100644 index 536461a549..0000000000 --- a/boost/test/utils/runtime/env/modifier.hpp +++ /dev/null @@ -1,47 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : defines variable modifiers -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_ENV_MODIFIER_HPP -#define BOOST_TEST_UTILS_RUNTIME_ENV_MODIFIER_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -// Boost.Test -#include <boost/test/utils/named_params.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace environment { - -// ************************************************************************** // -// ************** environment variable modifiers ************** // -// ************************************************************************** // - -namespace { - -nfp::typed_keyword<cstring,struct global_id_t> global_id; -nfp::keyword<struct default_value_t> default_value; -nfp::keyword<struct interpreter_t> interpreter; - -} // local namespace -} // namespace environment - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_ENV_MODIFIER_HPP diff --git a/boost/test/utils/runtime/env/variable.hpp b/boost/test/utils/runtime/env/variable.hpp deleted file mode 100644 index df776a619a..0000000000 --- a/boost/test/utils/runtime/env/variable.hpp +++ /dev/null @@ -1,223 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : defines model of program environment variable -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_ENV_VARIABLE_HPP -#define BOOST_TEST_UTILS_RUNTIME_ENV_VARIABLE_HPP - -#ifdef UNDER_CE -#error Windows CE does not support environment variables. -#endif - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> -#include <boost/test/utils/runtime/fwd.hpp> -#include <boost/test/utils/runtime/parameter.hpp> -#include <boost/test/utils/runtime/argument.hpp> - -#include <boost/test/utils/runtime/env/fwd.hpp> - -// Boost -#include <boost/optional.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace environment { - -// ************************************************************************** // -// ************** runtime::environment::variable_data ************** // -// ************************************************************************** // - -namespace rt_env_detail { - -struct variable_data : public runtime::parameter { - cstring m_var_name; - dstring m_global_id; - argument_ptr m_value; -}; - -} // namespace rt_env_detail - -// ************************************************************************** // -// ************** runtime::environment::variable_base ************** // -// ************************************************************************** // - -class variable_base { -public: - explicit variable_base( rt_env_detail::variable_data& data ) : m_data( &data ) {} - - // arguments access - template<typename T> - T const& value() const - { - return arg_value<T>( *m_data->m_value ); - } - - template<typename T> - void value( boost::optional<T>& res ) const - { - if( has_value() ) - res = arg_value<T>( *m_data->m_value ); - else - res.reset(); - } - - bool has_value() const { return !!m_data->m_value; } - cstring name() const { return m_data->m_var_name; } - -protected: - // Data members - rt_env_detail::variable_data* m_data; -} ; - -// ************************************************************************** // -// ************** runtime::environment::variable ************** // -// ************************************************************************** // - -template<typename T = cstring> -class variable : public variable_base { -public: - // Constructors - explicit variable( cstring var_name ); - - template<typename Modifiers> - explicit variable( cstring var_name, Modifiers const& m ); - - explicit variable( rt_env_detail::variable_data& data ) - : variable_base( data ) {} - - // other variable assignment - void operator=( variable const& v ) { m_data = v.m_data; } - - // access methods - T const& value() const { return variable_base::value<T>(); } - -#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206)) || \ - BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0593)) - template<typename T> - void value( boost::optional<T>& res ) const { variable_base::value( res ); } -#else - using variable_base::value; -#endif - - // Value assignment - template<typename V> - void operator=( V const& v ) - { - if( !has_value() ) - m_data->m_value.reset( new typed_argument<T>( *m_data ) ); - - arg_value<T>( *m_data->m_value ) = v; - - rt_env_detail::sys_write_var( m_data->m_var_name, format_stream().ref() << value() ); - } -}; // class variable - -//____________________________________________________________________________// - -template<typename CharT, typename Tr,typename T> -inline std::basic_ostream<CharT,Tr>& -operator<<( std::basic_ostream<CharT,Tr>& os, variable<T> const& v ) -{ - os << v.name() << '='; - - if( v.has_value() ) - os << v.value(); - - return os; -} - -//____________________________________________________________________________// - -template<typename T, typename V> -inline bool -operator==( variable<T> ev, V const& v ) -{ - return ev.has_value() && ev.value() == v; -} - -//____________________________________________________________________________// - -template<typename T, typename V> -inline bool -operator==( V const& v, variable<T> ev ) -{ - return ev.has_value() && ev.value() == v; -} - -//____________________________________________________________________________// - -template<typename T, typename V> -inline bool -operator!=( variable<T> ev, V const& v ) -{ - return !ev.has_value() || ev.value() != v; -} - -//____________________________________________________________________________// - -template<typename T, typename V> -inline bool -operator!=( V const& v, variable<T> ev ) -{ - return !ev.has_value() || ev.value() != v; -} - -//____________________________________________________________________________// - -} // namespace environment - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -// ************************************************************************** // -// ************************************************************************** // -// Implementation - -#include <boost/test/utils/runtime/env/environment.hpp> - -// ************************************************************************** // -// ************** runtime::environment::variable ************** // -// ************************************************************************** // - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace environment { - -template<typename T> -variable<T>::variable( cstring var_name ) -: variable_base( environment::var<T>( var_name ) ) -{} - -//____________________________________________________________________________// - -template<typename T> -template<typename Modifiers> -variable<T>::variable( cstring var_name, Modifiers const& m ) -: variable_base( environment::var<T>( var_name, m ) ) -{} - -//____________________________________________________________________________// - -} // namespace environment - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_ENV_VARIABLE_HPP diff --git a/boost/test/utils/runtime/errors.hpp b/boost/test/utils/runtime/errors.hpp new file mode 100644 index 0000000000..c11686132c --- /dev/null +++ b/boost/test/utils/runtime/errors.hpp @@ -0,0 +1,195 @@ +// (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 : $RCSfile$ +// +// Version : $Revision$ +// +// Description : defines runtime parameters setup error +// *************************************************************************** + +#ifndef BOOST_TEST_UTILS_RUNTIME_INIT_ERROR_HPP +#define BOOST_TEST_UTILS_RUNTIME_INIT_ERROR_HPP + +// Boost.Test Runtime parameters +#include <boost/test/utils/runtime/fwd.hpp> + +// Boost.Test +#include <boost/test/utils/string_cast.hpp> + +// Boost.Test +#include <boost/config.hpp> + +// STL +#include <exception> +#include <vector> + +#include <boost/test/detail/suppress_warnings.hpp> + +namespace boost { +namespace runtime { + +// ************************************************************************** // +// ************** runtime::param_error ************** // +// ************************************************************************** // + +class param_error : public std::exception { +public: + ~param_error() BOOST_NOEXCEPT_OR_NOTHROW {} + + virtual const char * what() const BOOST_NOEXCEPT_OR_NOTHROW + { + return msg.c_str(); + } + + cstring param_name; + std::string msg; + +protected: + explicit param_error( cstring param_name_ ) : param_name( param_name_) {} +}; + +//____________________________________________________________________________// + +class init_error : public param_error { +protected: + explicit init_error( cstring param_name ) : param_error( param_name ) {} + ~init_error() BOOST_NOEXCEPT_OR_NOTHROW {} +}; + +class input_error : public param_error { +protected: + explicit input_error( cstring param_name ) : param_error( param_name ) {} + ~input_error() BOOST_NOEXCEPT_OR_NOTHROW {} +}; + +//____________________________________________________________________________// + +template<typename Derived, typename Base> +class specific_param_error : public Base { +protected: + explicit specific_param_error( cstring param_name ) : Base( param_name ) {} + ~specific_param_error() BOOST_NOEXCEPT_OR_NOTHROW {} +}; + +//____________________________________________________________________________// + +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + +template<typename Derived, typename Base> +inline Derived +operator<<(specific_param_error<Derived, Base>&& ex, char const* val) +{ + ex.msg.append( val ); + + return reinterpret_cast<Derived&&>(ex); +} + +//____________________________________________________________________________// + +template<typename Derived, typename Base, typename T> +inline Derived +operator<<(specific_param_error<Derived, Base>&& ex, T const& val) +{ + ex.msg.append( unit_test::utils::string_cast( val ) ); + + return reinterpret_cast<Derived&&>(ex); +} + +//____________________________________________________________________________// + +#else + +template<typename Derived, typename Base> +inline Derived +operator<<(specific_param_error<Derived, Base> const& ex, char const* val) +{ + const_cast<specific_param_error<Derived, Base>&>(ex).msg.append( val ); + + return static_cast<Derived const&>(ex); +} + +//____________________________________________________________________________// + +template<typename Derived, typename Base, typename T> +inline Derived +operator<<(specific_param_error<Derived, Base> const& ex, T const& val) +{ + const_cast<specific_param_error<Derived, Base>&>(ex).msg.append( unit_test::utils::string_cast( val ) ); + + return static_cast<Derived const&>(ex); +} + +//____________________________________________________________________________// + +#endif + +// ************************************************************************** // +// ************** specific exception types ************** // +// ************************************************************************** // + +#define SPECIFIC_EX_TYPE( type, base ) \ +class type : public specific_param_error<type,base> { \ +public: \ + explicit type( cstring param_name = cstring() ) \ + : specific_param_error<type,base>( param_name ) \ + {} \ +} \ +/**/ + +SPECIFIC_EX_TYPE( invalid_cla_id, init_error ); +SPECIFIC_EX_TYPE( duplicate_param, init_error ); +SPECIFIC_EX_TYPE( conflicting_param, init_error ); +SPECIFIC_EX_TYPE( unknown_param, init_error ); +SPECIFIC_EX_TYPE( access_to_missing_argument, init_error ); +SPECIFIC_EX_TYPE( arg_type_mismatch, init_error ); +SPECIFIC_EX_TYPE( invalid_param_spec, init_error ); + +SPECIFIC_EX_TYPE( format_error, input_error ); +SPECIFIC_EX_TYPE( duplicate_arg, input_error ); +SPECIFIC_EX_TYPE( missing_req_arg, input_error ); + +#undef SPECIFIC_EX_TYPE + +class ambiguous_param : public specific_param_error<ambiguous_param, input_error> { +public: +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + explicit ambiguous_param( std::vector<cstring>&& amb_candidates ) + : specific_param_error<ambiguous_param,input_error>( "" ) + , m_amb_candidates( std::move( amb_candidates ) ) {} +#else + explicit ambiguous_param( std::vector<cstring> const& amb_candidates ) + : specific_param_error<ambiguous_param,input_error>( "" ) + , m_amb_candidates( amb_candidates ) {} +#endif + ~ambiguous_param() BOOST_NOEXCEPT_OR_NOTHROW {} + + std::vector<cstring> m_amb_candidates; +}; + +class unrecognized_param : public specific_param_error<unrecognized_param, input_error> { +public: +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + explicit unrecognized_param( std::vector<cstring>&& type_candidates ) + : specific_param_error<unrecognized_param,input_error>( "" ) + , m_typo_candidates( std::move( type_candidates ) ) {} +#else + explicit unrecognized_param( std::vector<cstring> const& type_candidates ) + : specific_param_error<unrecognized_param,input_error>( "" ) + , m_typo_candidates( type_candidates ) {} +#endif + ~unrecognized_param() BOOST_NOEXCEPT_OR_NOTHROW {} + + std::vector<cstring> m_typo_candidates; +}; + +} // namespace runtime +} // namespace boost + +#include <boost/test/detail/enable_warnings.hpp> + +#endif // BOOST_TEST_UTILS_RUNTIME_INIT_ERROR_HPP diff --git a/boost/test/utils/runtime/file/config_file.cpp b/boost/test/utils/runtime/file/config_file.cpp deleted file mode 100644 index 1e13d66eee..0000000000 --- a/boost/test/utils/runtime/file/config_file.cpp +++ /dev/null @@ -1,249 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : implements models configuration file, it's parameter and parameter namespaces -// *************************************************************************** - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/file/config_file.hpp> -#include <boost/test/utils/runtime/validation.hpp> - -// Boost.Test -#include <boost/test/utils/foreach.hpp> -#include <boost/test/utils/basic_cstring/basic_cstring.hpp> -#include <boost/test/utils/basic_cstring/io.hpp> -#include <boost/test/utils/iterator/token_iterator.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace file { - -// ************************************************************************** // -// ************** runtime::file::parameter ************** // -// ************************************************************************** // - -parameter::parameter( cstring name, cstring value, param_namespace const& parent ) -: m_parent( parent ) -{ - assign_op( p_name.value, name, 0 ); - assign_op( p_value.value, value, 0 ); -} - -//____________________________________________________________________________// - -std::ostream& -operator<<( std::ostream& os, parameter const& p ) -{ - p.m_parent.print_full_name( os ); - - return os << p.p_name << " = \"" << p.p_value << "\""; -} - -//____________________________________________________________________________// - -// ************************************************************************** // -// ************** runtime::file::param_namespace ************** // -// ************************************************************************** // - -param_namespace::param_namespace( cstring name, param_namespace const* parent ) -: p_parent( parent ) -{ - assign_op( p_name.value, name, 0 ); -} - -//____________________________________________________________________________// - -void -param_namespace::insert_param( cstring param_name, cstring param_value ) -{ - BOOST_TEST_FOREACH( parameter const&, p, m_parameters ) - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( p.p_name != param_name, - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "Duplicate parameter " ) << param_name ); - - m_parameters.push_back( parameter( param_name, param_value, *this ) ); -} - -//____________________________________________________________________________// - -param_namespace& -param_namespace::subnamespace( cstring namespace_name ) -{ - BOOST_TEST_FOREACH( param_namespace&, subns, m_subnamespaces ) - if( subns.p_name == namespace_name ) - return subns; - - m_subnamespaces.push_back( param_namespace( namespace_name, this ) ); - - return m_subnamespaces.back(); -} - -//____________________________________________________________________________// - -void -param_namespace::clear() -{ - m_parameters.clear(); - m_subnamespaces.clear(); -} - -//____________________________________________________________________________// - -void -param_namespace::print_full_name( std::ostream& os ) const -{ - if( !p_parent ) - return; - - p_parent.get()->print_full_name( os ); - - os << p_name << "::"; -} - -//____________________________________________________________________________// - -boost::optional<cstring> -get_param_value( param_namespace const& where_from, - cstring name_part1, - cstring name_part2, - cstring name_part3, - cstring name_part4, - cstring name_part5 ) -{ - if( name_part2.is_empty() ) { - boost::optional<cstring> res; - - BOOST_TEST_FOREACH( parameter const&, p, where_from ) { - if( p.p_name == name_part1 ) { - res = cstring( p.p_value ); - break; - } - } - - return res; - } - - param_namespace const* sns = get_param_subns( where_from, name_part1 ); - - return sns ? get_param_value( *sns, name_part2, name_part3, name_part4, name_part5 ) - : boost::optional<cstring>(); -} - -//____________________________________________________________________________// - -cstring -get_requ_param_value( param_namespace const& where_from, - cstring name_part1, - cstring name_part2, - cstring name_part3, - cstring name_part4, - cstring name_part5 ) -{ - boost::optional<cstring> v = get_param_value( where_from, name_part1, name_part2, name_part3, name_part4, name_part5 ); - -#define APPEND_PART( part ) (part.is_empty() ? "" : "::") << (part.is_empty() ? cstring() : part) - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( !!v, BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "Required parameter " ) - << name_part1 - << APPEND_PART( name_part2 ) - << APPEND_PART( name_part3 ) - << APPEND_PART( name_part4 ) - << APPEND_PART( name_part5 ) - << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( " value is missing" ) ); -#undef APPEND_PART - - return *v; -} - -//____________________________________________________________________________// - -param_namespace const* -get_param_subns( param_namespace const& where_from, cstring namespace_name ) -{ - param_namespace::sub_ns_const_iterator it = where_from.sub_ns_begin(); - param_namespace::sub_ns_const_iterator end = where_from.sub_ns_end(); - - while( it != end ) { - if( it->p_name == namespace_name ) - return &*it; - - ++it; - } - - return 0; -} - -//____________________________________________________________________________// - -void -param_namespace::load_impl( config_file_iterator cf_it, - cstring value_marker, cstring value_delimeter, cstring namespace_delimeter ) -{ - using namespace unit_test; - - while( cf_it != config_file_iterator() ) { - string_token_iterator ti( *cf_it, (max_tokens = 2,kept_delimeters = dt_none, dropped_delimeters = value_delimeter) ); - - cstring param_name = *ti; - cstring param_value = *(++ti); - - param_value.trim( value_marker ); - - param_namespace* targ_ns = this; - - while( !param_name.is_empty() ) { - cstring::size_type pos = param_name.find( namespace_delimeter ); - cstring subname( param_name.begin(), pos == cstring::npos ? param_name.size() : pos ); - - if( subname.size() == param_name.size() ) { - targ_ns->insert_param( param_name, param_value ); - break; - } - else { - targ_ns = &targ_ns->subnamespace( subname ); - - param_name.trim_left( subname.size() + namespace_delimeter.size() ); - } - } - ++cf_it; - } -} - -//____________________________________________________________________________// - -// ************************************************************************** // -// ************** runtime::file::config_file ************** // -// ************************************************************************** // - -config_file::config_file() -: param_namespace( cstring() ) -{ -} - -//____________________________________________________________________________// - -config_file::config_file( cstring file_name ) -: param_namespace( cstring() ) -{ - load( file_name ); -} - -//____________________________________________________________________________// - -} // namespace file - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -// EOF diff --git a/boost/test/utils/runtime/file/config_file.hpp b/boost/test/utils/runtime/file/config_file.hpp deleted file mode 100644 index e7baf08bf2..0000000000 --- a/boost/test/utils/runtime/file/config_file.hpp +++ /dev/null @@ -1,182 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : defines models configuration file, it's parameter and parameter namespaces -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_FILE_CONFIG_FILE_HPP -#define BOOST_TEST_UTILS_RUNTIME_FILE_CONFIG_FILE_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/file/config_file_iterator.hpp> - -// Boost.Test -#include <boost/test/utils/class_properties.hpp> -#include <boost/test/utils/named_params.hpp> - -// Boost -#include <boost/optional.hpp> - -// STL -#include <list> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace file { - -// ************************************************************************** // -// ************** runtime::file::parameter ************** // -// ************************************************************************** // - -class param_namespace; - -class parameter { -public: - // Constructor - parameter( cstring name, cstring value, param_namespace const& parent ); - - BOOST_READONLY_PROPERTY( dstring, (parameter)) p_name; - BOOST_READONLY_PROPERTY( dstring, (parameter)) p_value; - - friend std::ostream& operator<<( std::ostream& os, parameter const& ); - -private: - // Data members - param_namespace const& m_parent; -}; - -// ************************************************************************** // -// ************** runtime::file::modifiers ************** // -// ************************************************************************** // - -namespace { -nfp::typed_keyword<cstring, struct value_marker_t> value_marker; -nfp::typed_keyword<cstring, struct value_delimeter_t> value_delimeter; -nfp::typed_keyword<cstring, struct namespace_delimeter_t> namespace_delimeter; -} // local namespace - -// ************************************************************************** // -// ************** runtime::file::param_namespace ************** // -// ************************************************************************** // - -class param_namespace { -public: - typedef std::list<parameter>::iterator iterator; - typedef std::list<parameter>::const_iterator const_iterator; - typedef std::list<param_namespace>::iterator sub_ns_iterator; - typedef std::list<param_namespace>::const_iterator sub_ns_const_iterator; - - // Public properties - BOOST_READONLY_PROPERTY( dstring, (param_namespace)) p_name; - unit_test::readonly_property<param_namespace const*> p_parent; - - void load( config_file_iterator cf_it ) { load( cf_it, nfp::no_params ); } - template<typename Modifier> - void load( config_file_iterator cf_it, Modifier const& m ) - { - cstring vm = m.has( value_marker ) ? m[value_marker] : BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "\"" ); - cstring vd = m.has( value_delimeter ) ? m[value_delimeter] : BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "= \t\n\r" ); - cstring nd = m.has( namespace_delimeter ) ? m[namespace_delimeter] : BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "::" ); - - load_impl( cf_it, vm, vd, nd ); - } - void load( cstring file_name ) - { - load( file_name, nfp::no_params ); - } - template<typename Modifier> - void load( cstring file_name, Modifier const& m ) - { - config_file_iterator cfi( file_name, m ); - - load( cfi, m ); - } - - void insert_param( cstring param_name, cstring param_value ); - param_namespace& subnamespace( cstring namespace_name ); // find and insert if not present - void clear(); - - iterator begin() { return m_parameters.begin(); } - const_iterator begin() const { return m_parameters.begin(); } - - iterator end() { return m_parameters.end(); } - const_iterator end() const { return m_parameters.end(); } - - sub_ns_iterator sub_ns_begin() { return m_subnamespaces.begin(); } - sub_ns_const_iterator sub_ns_begin() const { return m_subnamespaces.begin(); } - - sub_ns_iterator sub_ns_end() { return m_subnamespaces.end(); } - sub_ns_const_iterator sub_ns_end() const { return m_subnamespaces.end(); } - - void print_full_name( std::ostream& os ) const; - -protected: - explicit param_namespace( cstring name, param_namespace const* parent = 0 ); - -private: - void load_impl( config_file_iterator cf_it, - cstring value_marker_, cstring value_delimeter_, cstring namespace_delimeter_ ); - - // Data members - std::list<parameter> m_parameters; - std::list<param_namespace> m_subnamespaces; -}; - -//____________________________________________________________________________// - -boost::optional<cstring> -get_param_value( param_namespace const& where_from, - cstring name_part1, - cstring name_part2 = cstring(), - cstring name_part3 = cstring(), - cstring name_part4 = cstring(), - cstring name_part5 = cstring() ); - -//____________________________________________________________________________// - -cstring -get_requ_param_value( param_namespace const& where_from, - cstring name_part1, - cstring name_part2 = cstring(), - cstring name_part3 = cstring(), - cstring name_part4 = cstring(), - cstring name_part5 = cstring() ); - -//____________________________________________________________________________// - -param_namespace const* -get_param_subns( param_namespace const& where_from, - cstring namespace_name ); - -//____________________________________________________________________________// - -// ************************************************************************** // -// ************** runtime::file::config_file ************** // -// ************************************************************************** // - -class config_file : public param_namespace { -public: - // Constructor - config_file(); - config_file( cstring file_name ); -}; - -} // namespace file - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_FILE_CONFIG_FILE_HPP_010105GER diff --git a/boost/test/utils/runtime/file/config_file_iterator.cpp b/boost/test/utils/runtime/file/config_file_iterator.cpp deleted file mode 100644 index 5d6cbdf7dc..0000000000 --- a/boost/test/utils/runtime/file/config_file_iterator.cpp +++ /dev/null @@ -1,685 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : flexible configuration file iterator implementation -// *************************************************************************** - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/file/config_file_iterator.hpp> -#include <boost/test/utils/runtime/validation.hpp> - -#ifndef UNDER_CE -#include <boost/test/utils/runtime/env/environment.hpp> -#endif - - -// Boost -#include <boost/scoped_array.hpp> -#include <boost/bind.hpp> -#include <boost/noncopyable.hpp> - -// Boost.Test -#include <boost/test/utils/basic_cstring/compare.hpp> -#include <boost/test/utils/algorithm.hpp> -#include <boost/test/utils/iterator/token_iterator.hpp> -#include <boost/test/utils/assign_op.hpp> - -// STL -#include <memory> -#include <map> -#include <list> -#include <vector> -#include <fstream> -#include <cctype> -#include <iostream> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace file { - -// ************************************************************************** // -// ************** symbol_to_value_map ************** // -// ************************************************************************** // - -template<typename ValueType> -struct symbol_to_value_map : std::map<cstring, ValueType> { - template<typename ParamType> - void add( cstring name, ParamType const& value ) - { - using namespace unit_test; - - m_name_store.push_back( dstring() ); - - assign_op( m_name_store.back(), name, 0 ); - assign_op( (*this)[m_name_store.back()], value, 0 ); - } - void remove( cstring name ) - { - std::list<dstring>::iterator it = std::find( m_name_store.begin(), m_name_store.end(), name ); - - m_name_store.erase( it ); - - this->erase( name ); - } - -private: - std::list<dstring> m_name_store; -}; - -// ************************************************************************** // -// ************** symbol_table_t ************** // -// ************************************************************************** // - -typedef symbol_to_value_map<dstring> symbol_table_t; - -// ************************************************************************** // -// ************** command_handler_map ************** // -// ************************************************************************** // - -typedef symbol_to_value_map<config_file_iterator::command_handler> command_handler_map; - -// ************************************************************************** // -// ************** is_valid_identifier ************** // -// ************************************************************************** // - -static bool -is_valid_identifier( cstring const& source ) -{ - if( source.is_empty() ) - return false; - - cstring::const_iterator it = source.begin(); - - if( !std::isalpha( *it ) ) - return false; - - while( ++it < source.end() ) { - if( !std::isalnum( *it ) && *it != BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( '_' ) && *it != BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( '-' ) ) - return false; - } - - return true; -} - -// ************************************************************************** // -// ************** include_level ************** // -// ************************************************************************** // - -struct include_level; -typedef std::auto_ptr<include_level> include_level_ptr; - -struct include_level : noncopyable -{ - // Constructor - explicit include_level( cstring file_name, cstring path_separators, include_level* parent = 0 ); - - // Data members - std::ifstream m_stream; - location m_curr_location; - include_level_ptr m_parent; -}; - -//____________________________________________________________________________// - -include_level::include_level( cstring file_name, cstring path_separators, include_level* parent_ ) -: m_parent( parent_ ) -{ - if( file_name.is_empty() ) - return; - - assign_op( m_curr_location.first, file_name, 0 ); - m_curr_location.second = 0; - - m_stream.open( m_curr_location.first.c_str() ); - - if( !m_stream.is_open() && !!m_parent.get() ) { - cstring parent_path = m_parent->m_curr_location.first; - cstring::iterator it = unit_test::find_last_of( parent_path.begin(), parent_path.end(), - path_separators.begin(), - path_separators.end() ); - - if( it != parent_path.end() ) { - assign_op( m_curr_location.first, cstring( parent_path.begin(), it+1 ), 0 ); - m_curr_location.first.append( file_name.begin(), file_name.end() ); - m_stream.clear(); - m_stream.open( m_curr_location.first.c_str() ); - } - } - - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( m_stream.is_open(), BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "can't open file " ) << file_name ); -} - -//____________________________________________________________________________// - -// ************************************************************************** // -// ************** config_file_iterator::Impl ************** // -// ************************************************************************** // - -struct config_file_iterator::Impl : noncopyable { - // Constructor - Impl(); - - bool get_next_line( cstring& next_line ); - - void process_command_line( cstring line ); - void process_include( cstring line ); - void process_define( cstring line ); - void process_undef( cstring line ); - void process_ifdef( cstring line ); - void process_ifndef( cstring line ); - void process_else( cstring line ); - void process_endif( cstring line ); - - boost::optional<cstring> - get_macro_value( cstring macro_name, bool ignore_missing = true ); - void substitute_macros( cstring& where ); - - bool is_active_line() { return m_inactive_ifdef_level == 0; } - - static bool match_front( cstring str, cstring pattern ) - { - return str.size() >= pattern.size() && str.substr( 0, pattern.size() ) == pattern; - } - static bool match_back( cstring str, cstring pattern ) - { - return str.size() >= pattern.size() && str.substr( str.size() - pattern.size() ) == pattern; - } - - // Configurable parameters - dstring m_path_separators; - char_type m_line_delimeter; - dstring m_sl_comment_delimeter; - dstring m_command_delimeter; - dstring m_line_beak; - dstring m_macro_ref_begin; - dstring m_macro_ref_end; - - dstring m_include_kw; - dstring m_define_kw; - dstring m_undef_kw; - dstring m_ifdef_kw; - dstring m_ifndef_kw; - dstring m_else_kw; - dstring m_endif_kw; - - std::size_t m_buffer_size; - - bool m_trim_trailing_spaces; - bool m_trim_leading_spaces; - bool m_skip_empty_lines; - bool m_detect_missing_macro; - - // Data members - dstring m_post_subst_line; - scoped_array<char> m_buffer; - include_level_ptr m_curr_level; - symbol_table_t m_symbols_table; - std::vector<bool> m_conditional_states; - std::size_t m_inactive_ifdef_level; - command_handler_map m_command_handler_map; -}; - -//____________________________________________________________________________// - -config_file_iterator::Impl::Impl() -: m_path_separators( BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "/\\" ) ) -, m_line_delimeter( BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( '\n' ) ) -, m_sl_comment_delimeter( BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "#" ) ) -, m_command_delimeter( BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "$" ) ) -, m_line_beak( BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "\\" ) ) -, m_macro_ref_begin( BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "$" ) ) -, m_macro_ref_end( BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "$" ) ) - -, m_include_kw( BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "include" ) ) -, m_define_kw( BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "define" ) ) -, m_undef_kw( BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "undef" ) ) -, m_ifdef_kw( BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "ifdef" ) ) -, m_ifndef_kw( BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "ifndef" ) ) -, m_else_kw( BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "else" ) ) -, m_endif_kw( BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "endif" ) ) - -, m_buffer_size( 8192 ) - -, m_trim_trailing_spaces( true ) -, m_trim_leading_spaces( false ) -, m_skip_empty_lines( true ) -, m_detect_missing_macro( true ) - -, m_inactive_ifdef_level( 0 ) -{} - -//____________________________________________________________________________// - -bool -config_file_iterator::Impl::get_next_line( cstring& line ) -{ - bool broken_line = false; - - line.clear(); - - while( !m_curr_level->m_stream.eof() || !!m_curr_level->m_parent.get() ) { - // 10. Switch to upper include level if current one is finished - // 20. Read/append next file line - // 30. Increment line number - // 40. Remove comments - // 50. Remove trailing and leading spaces - // 60. Skip empty string - // 70. Concatenate broken lines if needed. Put the result into line - // 80. If line is not completed, try to finish it by reading the next line - // 90. Process command line - // 100. Substitute macros references with their definitions - // 110. Next line found. - - if( m_curr_level->m_stream.eof() ) { // 10 // - m_curr_level = m_curr_level->m_parent; - continue; - } - - std::ifstream& input = m_curr_level->m_stream; - char_type* buffer_insert_pos = broken_line ? m_buffer.get() + line.size() : m_buffer.get(); - - input.getline( buffer_insert_pos, (std::streamsize)(m_buffer_size - line.size()), // 20 // - m_line_delimeter ); - - cstring next_line( buffer_insert_pos, - input.gcount() > 0 - ? buffer_insert_pos + (input.eof() ? input.gcount() : (input.gcount()-1)) - : buffer_insert_pos ); - - - m_curr_level->m_curr_location.second++; // 30 // - - cstring::size_type comment_pos = next_line.find( m_sl_comment_delimeter ); - if( comment_pos != cstring::npos ) - next_line.trim_right( next_line.begin()+comment_pos ); // 40 // - - if( m_trim_trailing_spaces ) // 50 // - next_line.trim_right(); - if( m_trim_leading_spaces && !broken_line ) - next_line.trim_left(); - - if( next_line.is_empty() ) { // 60 // - if( m_skip_empty_lines ) - continue; - else - next_line.assign( buffer_insert_pos, buffer_insert_pos ); - } - - line = broken_line ? cstring( line.begin(), next_line.end() ) : next_line; // 70 // - - broken_line = match_back( line, m_line_beak ); - if( broken_line ) { // 80 // - line.trim_right( 1 ); - continue; - } - - if( match_front( line, m_command_delimeter ) ) { // 90 // - process_command_line( line ); - continue; - } - - if( !is_active_line() ) - continue; - - substitute_macros( line ); // 100 // - - return true; // 110 // - } - - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( !broken_line, BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "broken line is not completed" ) ); - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( m_conditional_states.size() == 0, - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "matching endif command is missing" ) ); - - return false; -} - -//____________________________________________________________________________// - -boost::optional<cstring> -config_file_iterator::Impl::get_macro_value( cstring macro_name, bool ignore_missing ) -{ - symbol_table_t::const_iterator it = m_symbols_table.find( macro_name ); - - if( it == m_symbols_table.end() ) { - boost::optional<cstring> macro_value; // !! variable actually may have different type - - #ifndef UNDER_CE - env::get( macro_name, macro_value ); - #endif - - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( macro_value || ignore_missing || !m_detect_missing_macro, - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "Unknown macro \"" ) << macro_name << BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "\"" ) ); - - if( !macro_value ) { - if( !ignore_missing ) - macro_value = cstring(); - } - else - m_symbols_table.add( macro_name, *macro_value ); - - return macro_value; - } - - return boost::optional<cstring>( cstring( it->second ) ); -} - -//____________________________________________________________________________// - -void -config_file_iterator::Impl::process_command_line( cstring line ) -{ - line.trim_left( m_command_delimeter.size() ); - - unit_test::string_token_iterator tit( line, unit_test::max_tokens = 2 ); - - command_handler_map::const_iterator it = m_command_handler_map.find( *tit ); - - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( it != m_command_handler_map.end(), BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "Invalid command " ) << *tit ); - - ++tit; - - (it->second)( *tit ); -} - -//____________________________________________________________________________// - -void -config_file_iterator::Impl::process_include( cstring line ) -{ - using namespace unit_test; - - if( !is_active_line() ) - return; - - string_token_iterator tit( line, kept_delimeters = dt_none ); - - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( tit != string_token_iterator(), - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "include file name missing" ) ); - - cstring include_file_name = *tit; - - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( ++tit == string_token_iterator(), - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "unexpected tokens at the end of include command" ) ); - - substitute_macros( include_file_name ); - - m_curr_level.reset( new include_level( include_file_name, m_path_separators, m_curr_level.release() ) ); -} - -//____________________________________________________________________________// - -void -config_file_iterator::Impl::process_define( cstring line ) -{ - using namespace unit_test; - - if( !is_active_line() ) - return; - - string_token_iterator tit( line, (kept_delimeters = dt_none, max_tokens = 2 )); - - cstring macro_name = *tit; - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( is_valid_identifier( macro_name ), - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "invalid macro name" ) ); - - cstring macro_value = *(++tit); - substitute_macros( macro_value ); - - m_symbols_table.add( macro_name, macro_value ); -} - -//____________________________________________________________________________// - -void -config_file_iterator::Impl::process_undef( cstring line ) -{ - if( !is_active_line() ) - return; - - cstring macro_name = line; - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( is_valid_identifier( macro_name ), - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "invalid macro name" ) ); - - m_symbols_table.remove( macro_name ); -} - -//____________________________________________________________________________// - -void -config_file_iterator::Impl::process_ifdef( cstring line ) -{ - m_conditional_states.push_back( true ); - if( !is_active_line() ) - return; - - cstring macro_name = line; - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( is_valid_identifier( macro_name ), - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "invalid macro name" ) ); - - if( !get_macro_value( macro_name ) ) - m_inactive_ifdef_level = m_conditional_states.size(); -} - -//____________________________________________________________________________// - -void -config_file_iterator::Impl::process_ifndef( cstring line ) -{ - m_conditional_states.push_back( true ); - if( !is_active_line() ) - return; - - cstring macro_name = line; - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( is_valid_identifier( macro_name ), - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "invalid macro name" ) ); - - if( get_macro_value( macro_name ) ) - m_inactive_ifdef_level = m_conditional_states.size(); -} - -//____________________________________________________________________________// - -void -config_file_iterator::Impl::process_else( cstring line ) -{ - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( m_conditional_states.size() > 0 && m_conditional_states.back(), - BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "else without matching if" ) ); - - m_inactive_ifdef_level = m_conditional_states.size() == m_inactive_ifdef_level ? 0 : m_conditional_states.size(); - - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( line.is_empty(), BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "unexpected tokens at the end of else command" ) ); -} - -//____________________________________________________________________________// - -void -config_file_iterator::Impl::process_endif( cstring line ) -{ - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( m_conditional_states.size() > 0, BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "endif without matching if" ) ); - - if( m_conditional_states.size() == m_inactive_ifdef_level ) - m_inactive_ifdef_level = 0; - - m_conditional_states.pop_back(); - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( line.is_empty(), BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "unexpected tokens at the end of endif command" ) ); -} - -//____________________________________________________________________________// - -void -config_file_iterator::Impl::substitute_macros( cstring& where ) -{ - m_post_subst_line.clear(); - cstring::size_type pos; - - while( (pos = where.find( m_macro_ref_begin )) != cstring::npos ) { - m_post_subst_line.append( where.begin(), pos ); - - where.trim_left( where.begin() + pos + m_macro_ref_begin.size() ); - - pos = where.find( m_macro_ref_end ); - - BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( pos != cstring::npos, BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( "incomplete macro reference" ) ); - - cstring value = *get_macro_value( where.substr( 0, pos ), false ); - m_post_subst_line.append( value.begin(), value.size() ); - - where.trim_left( where.begin() + pos + m_macro_ref_end.size() ); - } - - if( !m_post_subst_line.empty() ) { - m_post_subst_line.append( where.begin(), where.size() ); - where = m_post_subst_line; - } -} - -//____________________________________________________________________________// - -// ************************************************************************** // -// ************** runtime::file::config_file_iterator ************** // -// ************************************************************************** // - -void -config_file_iterator::construct() -{ - m_pimpl.reset( new Impl ); -} - -//____________________________________________________________________________// - -void -config_file_iterator::load( cstring file_name ) -{ - m_pimpl->m_curr_level.reset( new include_level( file_name, m_pimpl->m_path_separators ) ); - m_pimpl->m_buffer.reset( new char[m_pimpl->m_buffer_size] ); - - register_command_handler( m_pimpl->m_include_kw, boost::bind( &Impl::process_include, m_pimpl.get(), _1 ) ); - register_command_handler( m_pimpl->m_define_kw, boost::bind( &Impl::process_define, m_pimpl.get(), _1 ) ); - register_command_handler( m_pimpl->m_undef_kw, boost::bind( &Impl::process_undef, m_pimpl.get(), _1 ) ); - register_command_handler( m_pimpl->m_ifdef_kw, boost::bind( &Impl::process_ifdef, m_pimpl.get(), _1 ) ); - register_command_handler( m_pimpl->m_ifndef_kw, boost::bind( &Impl::process_ifndef, m_pimpl.get(), _1 ) ); - register_command_handler( m_pimpl->m_else_kw, boost::bind( &Impl::process_else, m_pimpl.get(), _1 ) ); - register_command_handler( m_pimpl->m_endif_kw, boost::bind( &Impl::process_endif, m_pimpl.get(), _1 ) ); - - init(); -} - -//____________________________________________________________________________// - -location const& -config_file_iterator::curr_location() -{ - return m_pimpl->m_curr_level->m_curr_location; -} - -//____________________________________________________________________________// - -void -config_file_iterator::register_command_handler( cstring command_kw, command_handler const& ch ) -{ - m_pimpl->m_command_handler_map.add( command_kw, ch ); -} - -//____________________________________________________________________________// - -bool -config_file_iterator::get() -{ - return m_pimpl->get_next_line( m_value ); -} - -//____________________________________________________________________________// - -void -config_file_iterator::set_parameter( rtti::id_t id, cstring value ) -{ - BOOST_RTTI_SWITCH( id ) { - BOOST_RTTI_CASE( cfg_detail::path_separators_t ) - assign_op( m_pimpl->m_path_separators , value, 0 ); - BOOST_RTTI_CASE( cfg_detail::sl_comment_delimeter_t ) - assign_op( m_pimpl->m_sl_comment_delimeter , value, 0 ); - BOOST_RTTI_CASE( cfg_detail::command_delimeter_t ) - assign_op( m_pimpl->m_command_delimeter , value, 0 ); - BOOST_RTTI_CASE( cfg_detail::line_beak_t ) - assign_op( m_pimpl->m_line_beak , value, 0 ); - BOOST_RTTI_CASE( cfg_detail::macro_ref_begin_t ) - assign_op( m_pimpl->m_macro_ref_begin , value, 0 ); - BOOST_RTTI_CASE( cfg_detail::macro_ref_end_t ) - assign_op( m_pimpl->m_macro_ref_end , value, 0 ); - BOOST_RTTI_CASE( cfg_detail::include_kw_t ) - assign_op( m_pimpl->m_include_kw , value, 0 ); - BOOST_RTTI_CASE( cfg_detail::define_kw_t ) - assign_op( m_pimpl->m_define_kw , value, 0 ); - BOOST_RTTI_CASE( cfg_detail::undef_kw_t ) - assign_op( m_pimpl->m_undef_kw , value, 0 ); - BOOST_RTTI_CASE( cfg_detail::ifdef_kw_t ) - assign_op( m_pimpl->m_ifdef_kw , value, 0 ); - BOOST_RTTI_CASE( cfg_detail::ifndef_kw_t ) - assign_op( m_pimpl->m_ifndef_kw , value, 0 ); - BOOST_RTTI_CASE( cfg_detail::else_kw_t ) - assign_op( m_pimpl->m_else_kw , value, 0 ); - BOOST_RTTI_CASE( cfg_detail::endif_kw_t ) - assign_op( m_pimpl->m_endif_kw , value, 0 ); - } -} - -//____________________________________________________________________________// - -void -config_file_iterator::set_parameter( rtti::id_t id, bool value ) -{ - BOOST_RTTI_SWITCH( id ) { - BOOST_RTTI_CASE( cfg_detail::trim_leading_spaces_t ) - m_pimpl->m_trim_leading_spaces = value; - BOOST_RTTI_CASE( cfg_detail::trim_trailing_spaces_t ) - m_pimpl->m_trim_trailing_spaces = value; - BOOST_RTTI_CASE( cfg_detail::skip_empty_lines_t ) - m_pimpl->m_skip_empty_lines = value; - BOOST_RTTI_CASE( cfg_detail::detect_missing_macro_t ) - m_pimpl->m_detect_missing_macro = value; - } -} - -//____________________________________________________________________________// - -void -config_file_iterator::set_parameter( rtti::id_t id, char_type value ) -{ - BOOST_RTTI_SWITCH( id ) { - BOOST_RTTI_CASE( cfg_detail::line_delimeter_t ) - m_pimpl->m_line_delimeter = value; - } -} - -//____________________________________________________________________________// - -void -config_file_iterator::set_parameter( rtti::id_t id, std::size_t value ) -{ - BOOST_RTTI_SWITCH( id ) { - BOOST_RTTI_CASE( cfg_detail::buffer_size_t ) - m_pimpl->m_buffer_size = value; - } -} - -//____________________________________________________________________________// - -} // namespace file - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -// EOF diff --git a/boost/test/utils/runtime/file/config_file_iterator.hpp b/boost/test/utils/runtime/file/config_file_iterator.hpp deleted file mode 100644 index 6c6273fca1..0000000000 --- a/boost/test/utils/runtime/file/config_file_iterator.hpp +++ /dev/null @@ -1,166 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// Use, modification, and distribution are subject to 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : flexible configuration file iterator definition -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_FILE_CONFIG_FILE_ITERATOR_HPP -#define BOOST_TEST_UTILS_RUNTIME_FILE_CONFIG_FILE_ITERATOR_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#include <boost/test/utils/runtime/fwd.hpp> - -// Boost.Test -#include <boost/test/utils/iterator/input_iterator_facade.hpp> -#include <boost/test/utils/named_params.hpp> - -// Boost -#include <boost/shared_ptr.hpp> -#include <boost/function.hpp> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -namespace file { - -// Public typedef -typedef std::pair<dstring,long> location; - -// ************************************************************************** // -// ************** modifiers ************** // -// ************************************************************************** // - -namespace cfg_detail { - struct path_separators_t; - struct line_delimeter_t; - struct sl_comment_delimeter_t; - struct command_delimeter_t; - struct line_beak_t; - struct macro_ref_begin_t; - struct macro_ref_end_t; - struct include_kw_t; - struct define_kw_t; - struct undef_kw_t; - struct ifdef_kw_t; - struct ifndef_kw_t; - struct else_kw_t; - struct endif_kw_t; - - struct buffer_size_t; - - struct trim_leading_spaces_t; - struct trim_trailing_spaces_t; - struct skip_empty_lines_t; - struct detect_missing_macro_t; -} // namespace cfg_detail - -namespace { - -nfp::typed_keyword<cstring,cfg_detail::path_separators_t> path_separators; -nfp::typed_keyword<char_type ,cfg_detail::line_delimeter_t> line_delimeter; -nfp::typed_keyword<cstring,cfg_detail::sl_comment_delimeter_t> single_line_comment_delimeter; -nfp::typed_keyword<cstring,cfg_detail::command_delimeter_t> command_delimeter; -nfp::typed_keyword<cstring,cfg_detail::line_beak_t> line_beak; -nfp::typed_keyword<cstring,cfg_detail::macro_ref_begin_t> macro_ref_begin; -nfp::typed_keyword<cstring,cfg_detail::macro_ref_end_t> macro_ref_end; -nfp::typed_keyword<cstring,cfg_detail::include_kw_t> include_kw; -nfp::typed_keyword<cstring,cfg_detail::define_kw_t> define_kw; -nfp::typed_keyword<cstring,cfg_detail::undef_kw_t> undef_kw; -nfp::typed_keyword<cstring,cfg_detail::ifdef_kw_t> ifdef_kw; -nfp::typed_keyword<cstring,cfg_detail::ifndef_kw_t> ifndef_kw; -nfp::typed_keyword<cstring,cfg_detail::else_kw_t> else_kw; -nfp::typed_keyword<cstring,cfg_detail::endif_kw_t> endif_kw; - -nfp::typed_keyword<std::size_t,cfg_detail::buffer_size_t> buffer_size; - -nfp::typed_keyword<bool,cfg_detail::trim_leading_spaces_t> trim_leading_spaces; -nfp::typed_keyword<bool,cfg_detail::trim_trailing_spaces_t> trim_trailing_spaces; -nfp::typed_keyword<bool,cfg_detail::skip_empty_lines_t> skip_empty_lines; -nfp::typed_keyword<bool,cfg_detail::detect_missing_macro_t> detect_missing_macro; - -} // local namespace - -// ************************************************************************** // -// ************** runtime::file::config_file_iterator ************** // -// ************************************************************************** // - -class config_file_iterator : public unit_test::input_iterator_facade<config_file_iterator,cstring,cstring> { - typedef unit_test::input_iterator_facade<config_file_iterator,cstring,cstring> base; -public: - // Public typedefs - typedef boost::function<void (cstring)> command_handler; - - // Constructors - config_file_iterator() {} - explicit config_file_iterator( cstring file_name ) - { - construct(); - load( file_name ); - } - template<typename Modifiers> - config_file_iterator( cstring file_name, Modifiers const& m ) - { - construct(); - m.apply_to( *this ); - load( file_name ); - } - config_file_iterator( config_file_iterator const& rhs ) - : base( rhs ) - , m_pimpl( rhs.m_pimpl ) - { - rhs.m_valid = false; - } - - void operator=( config_file_iterator const& rhs ) - { - if( this == &rhs ) - return; - - (base&)(*this) = rhs; - m_pimpl = rhs.m_pimpl; - rhs.m_valid = false; - } // Assignment - - - // Access methods - location const& curr_location(); - void register_command_handler( cstring command_kw, command_handler const& ); - - // Parameters setters - void set_parameter( rtti::id_t, cstring ); - void set_parameter( rtti::id_t, bool ); - void set_parameter( rtti::id_t, char_type ); - void set_parameter( rtti::id_t, std::size_t ); - -private: - friend class unit_test::input_iterator_core_access; - - void construct(); - void load( cstring file_name ); - - // increment implementation - bool get(); - - // Data members - struct Impl; - shared_ptr<Impl> m_pimpl; -}; - -} // namespace file - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_FILE_CONFIG_FILE_ITERATOR_HPP diff --git a/boost/test/utils/runtime/finalize.hpp b/boost/test/utils/runtime/finalize.hpp new file mode 100644 index 0000000000..181428550c --- /dev/null +++ b/boost/test/utils/runtime/finalize.hpp @@ -0,0 +1,56 @@ +// (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 : $RCSfile$ +// +// Version : $Revision$ +// +// Description : runtime parameters initialization final step +// *************************************************************************** + +#ifndef BOOST_TEST_UTILS_RUNTIME_FINALIZE_HPP +#define BOOST_TEST_UTILS_RUNTIME_FINALIZE_HPP + +// Boost.Test Runtime parameters +#include <boost/test/utils/runtime/parameter.hpp> +#include <boost/test/utils/runtime/argument.hpp> + +// Boost.Test +#include <boost/test/utils/foreach.hpp> + +#include <boost/test/detail/suppress_warnings.hpp> + +namespace boost { +namespace runtime { + +inline void +finalize_arguments( parameters_store const& params, runtime::arguments_store& args ) +{ + BOOST_TEST_FOREACH( parameters_store::storage_type::value_type const&, v, params.all() ) { + basic_param_ptr param = v.second; + + if( !args.has( param->p_name ) ) { + if( param->p_has_default_value ) + param->produce_default( args ); + + if( !args.has( param->p_name ) ) { + BOOST_TEST_I_ASSRT( param->p_optional, + missing_req_arg( param->p_name ) << "Missing argument for required parameter " << param->p_name << "." ); + } + } + + if( args.has( param->p_name ) && !!param->p_callback ) + param->p_callback( param->p_name ); + } +} + +} // namespace runtime +} // namespace boost + +#include <boost/test/detail/enable_warnings.hpp> + +#endif // BOOST_TEST_UTILS_RUNTIME_FINALIZE_HPP diff --git a/boost/test/utils/runtime/fwd.hpp b/boost/test/utils/runtime/fwd.hpp index 2647184c5d..17ae881222 100644 --- a/boost/test/utils/runtime/fwd.hpp +++ b/boost/test/utils/runtime/fwd.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) @@ -9,33 +9,37 @@ // // Version : $Revision$ // -// Description : global framework level forward declaration +// Description : runtime parameters forward declaration // *************************************************************************** #ifndef BOOST_TEST_UTILS_RUNTIME_FWD_HPP #define BOOST_TEST_UTILS_RUNTIME_FWD_HPP -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> +// Boost.Test +#include <boost/test/detail/config.hpp> +#include <boost/test/utils/basic_cstring/basic_cstring.hpp> +#include <boost/test/utils/basic_cstring/io.hpp> // operator<<(boost::runtime::cstring) // Boost #include <boost/shared_ptr.hpp> -namespace boost { +// STL +#include <map> -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { +namespace boost { +namespace runtime { -class parameter; +typedef unit_test::const_string cstring; class argument; typedef shared_ptr<argument> argument_ptr; -typedef shared_ptr<argument const> const_argument_ptr; -template<typename T> class value_interpreter; template<typename T> class typed_argument; -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE +class basic_param; +typedef shared_ptr<basic_param> basic_param_ptr; +} // namespace runtime } // namespace boost #endif // BOOST_TEST_UTILS_RUNTIME_FWD_HPP diff --git a/boost/test/utils/runtime/interpret_argument_value.hpp b/boost/test/utils/runtime/interpret_argument_value.hpp deleted file mode 100644 index 016caa017f..0000000000 --- a/boost/test/utils/runtime/interpret_argument_value.hpp +++ /dev/null @@ -1,163 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : default algorithms for string to specific type convertions -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_INTERPRET_ARGUMENT_VALUE_HPP -#define BOOST_TEST_UTILS_RUNTIME_INTERPRET_ARGUMENT_VALUE_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> -#include <boost/test/utils/runtime/trace.hpp> - -// Boost.Test -#include <boost/test/utils/basic_cstring/io.hpp> -#include <boost/test/utils/basic_cstring/compare.hpp> - -// Boost -#include <boost/optional.hpp> -#include <boost/lexical_cast.hpp> - -// STL -// !! could we eliminate these includes? -#include <list> - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -// ************************************************************************** // -// ************** runtime::interpret_argument_value ************** // -// ************************************************************************** // -// returns true if source is used false otherwise - -// generic case -template<typename T> -struct interpret_argument_value_impl { - static bool _( cstring source, boost::optional<T>& res ) - { - BOOST_TEST_UTILS_RUNTIME_PARAM_TRACE( "In interpret_argument_value_impl<" << typeid(T).name() << ">" ); - - res = lexical_cast<T>( source ); - - BOOST_TEST_UTILS_RUNTIME_PARAM_TRACE( "String " << source << " is interpreted as " << *res ); - return true; - } -}; - - -//____________________________________________________________________________// - -// dstring case -template<> -struct interpret_argument_value_impl<dstring> { - static bool _( cstring source, boost::optional<dstring>& res ) - { - BOOST_TEST_UTILS_RUNTIME_PARAM_TRACE( "In interpret_argument_value_impl<dstring>" ); - - res = dstring(); - assign_op( *res, source, 0 ); - - return true; - } -}; - -//____________________________________________________________________________// - -// cstring case -template<> -struct interpret_argument_value_impl<cstring> { - static bool _( cstring source, boost::optional<cstring>& res ) - { - BOOST_TEST_UTILS_RUNTIME_PARAM_TRACE( "In interpret_argument_value_impl<cstring>" ); - - res = source; - - return true; - } -}; - -//____________________________________________________________________________// - -// specialization for type bool -template<> -struct interpret_argument_value_impl<bool> { - static bool _( cstring source, boost::optional<bool>& res ) - { - BOOST_TEST_UTILS_RUNTIME_PARAM_TRACE( "In interpret_argument_value_impl<bool>" ); - - static literal_cstring YES( BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "YES" ) ); - static literal_cstring Y( BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "Y" ) ); - static literal_cstring NO( BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "NO" ) ); - static literal_cstring N( BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "N" ) ); - static literal_cstring one( BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "1" ) ); - static literal_cstring zero( BOOST_TEST_UTILS_RUNTIME_PARAM_CSTRING_LITERAL( "0" ) ); - - source.trim(); - - if( case_ins_eq( source, YES ) || case_ins_eq( source, Y ) || case_ins_eq( source, one ) ) { - res = true; - return true; - } - else if( case_ins_eq( source, NO ) || case_ins_eq( source, N ) || case_ins_eq( source, zero ) ) { - res = false; - return true; - } - else { - res = true; - return source.is_empty(); - } - } -}; - -//____________________________________________________________________________// - -template<typename T> -inline bool -interpret_argument_value( cstring source, boost::optional<T>& res, long ) -{ - return interpret_argument_value_impl<T>::_( source, res ); -} - -//____________________________________________________________________________// - -// specialization for list of values -template<typename T> -inline bool -interpret_argument_value( cstring source, boost::optional<std::list<T> >& res, int ) -{ - BOOST_TEST_UTILS_RUNTIME_PARAM_TRACE( "In interpret_argument_value<std::list<T>>" ); - - res = std::list<T>(); - - while( !source.is_empty() ) { - // !! should we use token_iterator - cstring::iterator single_value_end = std::find( source.begin(), source.end(), BOOST_TEST_UTILS_RUNTIME_PARAM_LITERAL( ',' ) ); - - boost::optional<T> value; - interpret_argument_value( cstring( source.begin(), single_value_end ), value, 0 ); - - res->push_back( *value ); - - source.trim_left( single_value_end + 1 ); - } - - return true; -} - -//____________________________________________________________________________// - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_INTERPRET_ARGUMENT_VALUE_HPP diff --git a/boost/test/utils/runtime/modifier.hpp b/boost/test/utils/runtime/modifier.hpp new file mode 100644 index 0000000000..ed77ca0afe --- /dev/null +++ b/boost/test/utils/runtime/modifier.hpp @@ -0,0 +1,101 @@ +// (C) Copyright Gennadiy Rozental 2001. +// Use, modification, and distribution are subject to 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 : $RCSfile$ +// +// Version : $Revision$ +// +// Description : parameter modifiers +// *************************************************************************** + +#ifndef BOOST_TEST_UTILS_RUNTIME_MODIFIER_HPP +#define BOOST_TEST_UTILS_RUNTIME_MODIFIER_HPP + +// Boost.Test Runtime parameters +#include <boost/test/utils/runtime/fwd.hpp> + +// Boost.Test +#include <boost/test/utils/named_params.hpp> + +#include <boost/test/detail/suppress_warnings.hpp> + +namespace boost { +namespace runtime { + +// ************************************************************************** // +// ************** environment variable modifiers ************** // +// ************************************************************************** // + +namespace { + +#if !defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) +#define BOOST_TEST_CLA_NEW_API +#endif + +#ifdef BOOST_TEST_CLA_NEW_API +auto const& description = unit_test::static_constant<nfp::typed_keyword<cstring,struct description_t>>::value; +auto const& help = unit_test::static_constant<nfp::typed_keyword<cstring,struct help_t>>::value; +auto const& env_var = unit_test::static_constant<nfp::typed_keyword<cstring,struct env_var_t>>::value; +auto const& end_of_params = unit_test::static_constant<nfp::typed_keyword<cstring,struct end_of_params_t>>::value; +auto const& negation_prefix = unit_test::static_constant<nfp::typed_keyword<cstring,struct neg_prefix_t>>::value; +auto const& value_hint = unit_test::static_constant<nfp::typed_keyword<cstring,struct value_hint_t>>::value; +auto const& optional_value = unit_test::static_constant<nfp::keyword<struct optional_value_t>>::value; +auto const& default_value = unit_test::static_constant<nfp::keyword<struct default_value_t>>::value; +auto const& callback = unit_test::static_constant<nfp::keyword<struct callback_t>>::value; + +template<typename EnumType> +using enum_values = unit_test::static_constant< + nfp::typed_keyword<std::initializer_list<std::pair<const cstring,EnumType>>, struct enum_values_t> +>; + +#else + +nfp::typed_keyword<cstring,struct description_t> description; +nfp::typed_keyword<cstring,struct help_t> help; +nfp::typed_keyword<cstring,struct env_var_t> env_var; +nfp::typed_keyword<cstring,struct end_of_params_t> end_of_params; +nfp::typed_keyword<cstring,struct neg_prefix_t> negation_prefix; +nfp::typed_keyword<cstring,struct value_hint_t> value_hint; +nfp::keyword<struct optional_value_t> optional_value; +nfp::keyword<struct default_value_t> default_value; +nfp::keyword<struct callback_t> callback; + +template<typename EnumType> +struct enum_values_list { + typedef std::pair<cstring,EnumType> ElemT; + typedef std::vector<ElemT> ValuesT; + + enum_values_list const& + operator()( cstring k, EnumType v ) const + { + const_cast<enum_values_list*>(this)->m_values.push_back( ElemT( k, v ) ); + + return *this; + } + + operator ValuesT const&() const { return m_values; } + +private: + ValuesT m_values; +}; + +template<typename EnumType> +struct enum_values : unit_test::static_constant< + nfp::typed_keyword<enum_values_list<EnumType>, struct enum_values_t> > +{ +}; + +#endif + +} // local namespace + +} // namespace runtime +} // namespace boost + +#include <boost/test/detail/enable_warnings.hpp> + +#endif // BOOST_TEST_UTILS_RUNTIME_MODIFIER_HPP diff --git a/boost/test/utils/runtime/parameter.hpp b/boost/test/utils/runtime/parameter.hpp index 2dd4ba725c..c198688493 100644 --- a/boost/test/utils/runtime/parameter.hpp +++ b/boost/test/utils/runtime/parameter.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) @@ -9,30 +9,464 @@ // // Version : $Revision$ // -// Description : abstract interface for the formal parameter +// Description : formal parameter definition // *************************************************************************** #ifndef BOOST_TEST_UTILS_RUNTIME_PARAMETER_HPP #define BOOST_TEST_UTILS_RUNTIME_PARAMETER_HPP -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> +// Boost.Test Runtime parameters +#include <boost/test/utils/runtime/fwd.hpp> +#include <boost/test/utils/runtime/modifier.hpp> +#include <boost/test/utils/runtime/argument.hpp> +#include <boost/test/utils/runtime/argument_factory.hpp> + +// Boost.Test +#include <boost/test/utils/class_properties.hpp> +#include <boost/test/utils/foreach.hpp> + +// Boost +#include <boost/function/function2.hpp> +#include <boost/algorithm/cxx11/all_of.hpp> + +// STL +#include <algorithm> + +#include <boost/test/detail/suppress_warnings.hpp> namespace boost { +namespace runtime { + +// ************************************************************************** // +// ************** runtime::parameter_cla_id ************** // +// ************************************************************************** // +// set of attributes identifying the parameter in the command line + +struct parameter_cla_id { + parameter_cla_id( cstring prefix, cstring tag, cstring value_separator, bool negatable ) + : m_prefix( prefix.begin(), prefix.size() ) + , m_tag( tag.begin(), tag.size() ) + , m_value_separator( value_separator.begin(), value_separator.size() ) + , m_negatable( negatable ) + { + + BOOST_TEST_I_ASSRT( algorithm::all_of( m_prefix.begin(), m_prefix.end(), valid_prefix_char ), + invalid_cla_id() << "Parameter " << m_tag + << " has invalid characters in prefix." ); + + BOOST_TEST_I_ASSRT( algorithm::all_of( m_tag.begin(), m_tag.end(), valid_name_char ), + invalid_cla_id() << "Parameter " << m_tag + << " has invalid characters in name." ); + + BOOST_TEST_I_ASSRT( algorithm::all_of( m_value_separator.begin(), m_value_separator.end(), valid_separator_char ), + invalid_cla_id() << "Parameter " << m_tag + << " has invalid characters in value separator." ); + } + + static bool valid_prefix_char( char c ) + { + return c == '-' || c == '/' ; + } + static bool valid_separator_char( char c ) + { + return c == '=' || c == ':' || c == ' ' || c == '\0'; + } + static bool valid_name_char( char c ) + { + return std::isalnum( c ) || c == '+' || c == '_' || c == '?'; + } + + std::string m_prefix; + std::string m_tag; + std::string m_value_separator; + bool m_negatable; +}; + +typedef std::vector<parameter_cla_id> param_cla_ids; + +// ************************************************************************** // +// ************** runtime::basic_param ************** // +// ************************************************************************** // + +cstring const help_prefix("////"); + +class basic_param { + typedef function<void (cstring)> callback_type; + typedef unit_test::readwrite_property<bool> bool_property; + +protected: + /// Constructor with modifiers + template<typename Modifiers> + basic_param( cstring name, bool is_optional, bool is_repeatable, Modifiers const& m ) + : p_name( name.begin(), name.end() ) + , p_description( nfp::opt_get( m, description, std::string() ) ) + , p_help( nfp::opt_get( m, runtime::help, std::string() ) ) + , p_env_var( nfp::opt_get( m, env_var, std::string() ) ) + , p_value_hint( nfp::opt_get( m, value_hint, std::string() ) ) + , p_optional( is_optional ) + , p_repeatable( is_repeatable ) + , p_has_optional_value( m.has( optional_value ) ) + , p_has_default_value( m.has( default_value ) || is_repeatable ) + , p_callback( nfp::opt_get( m, callback, callback_type() ) ) + { + add_cla_id( help_prefix, name, ":" ); + } + +public: + virtual ~basic_param() {} + + // Pubic properties + std::string const p_name; + std::string const p_description; + std::string const p_help; + std::string const p_env_var; + std::string const p_value_hint; + bool const p_optional; + bool const p_repeatable; + bool_property p_has_optional_value; + bool_property p_has_default_value; + callback_type const p_callback; + + /// interface for cloning typed parameters + virtual basic_param_ptr clone() const = 0; + + /// Access methods + param_cla_ids const& cla_ids() const { return m_cla_ids; } + void add_cla_id( cstring prefix, cstring tag, cstring value_separator ) + { + add_cla_id_impl( prefix, tag, value_separator, false, true ); + } + + /// interface for producing argument values for this parameter + virtual void produce_argument( cstring token, bool negative_form, arguments_store& store ) const = 0; + virtual void produce_default( arguments_store& store ) const = 0; + + /// interfaces for help message reporting + virtual void usage( std::ostream& ostr, cstring negation_prefix_ ) + { + ostr << "Parameter: " << p_name << '\n'; + if( !p_description.empty() ) + ostr << ' ' << p_description << '\n'; + + ostr << " Command line formats:\n"; + BOOST_TEST_FOREACH( parameter_cla_id const&, id, cla_ids() ) { + if( id.m_prefix == help_prefix ) + continue; + + ostr << " " << id.m_prefix; + if( id.m_negatable ) + cla_name_help( ostr, id.m_tag, negation_prefix_ ); + else + cla_name_help( ostr, id.m_tag, "" ); + + bool optional_value_ = false; + + if( p_has_optional_value ) { + optional_value_ = true; + ostr << '['; + } + + if( id.m_value_separator.empty() ) + ostr << ' '; + else { + ostr << id.m_value_separator; + } + + value_help( ostr ); + + if( optional_value_ ) + ostr << ']'; + + ostr << '\n'; + } + if( !p_env_var.empty() ) + ostr << " Environment variable: " << p_env_var << '\n'; + } + + virtual void help( std::ostream& ostr, cstring negation_prefix_ ) + { + usage( ostr, negation_prefix_ ); + + if( !p_help.empty() ) + ostr << '\n' << p_help << '\n'; + } + +protected: + void add_cla_id_impl( cstring prefix, + cstring tag, + cstring value_separator, + bool negatable, + bool validate_value_separator ) + { + BOOST_TEST_I_ASSRT( !tag.is_empty(), + invalid_cla_id() << "Parameter can't have an empty name." ); + + BOOST_TEST_I_ASSRT( !prefix.is_empty(), + invalid_cla_id() << "Parameter " << tag + << " can't have an empty prefix." ); + + BOOST_TEST_I_ASSRT( !value_separator.is_empty(), + invalid_cla_id() << "Parameter " << tag + << " can't have an empty value separator." ); -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { + // We trim value separator from all the spaces, so token end will indicate separator + value_separator.trim(); + BOOST_TEST_I_ASSRT( !validate_value_separator || !value_separator.is_empty() || !p_has_optional_value, + invalid_cla_id() << "Parameter " << tag + << " with optional value attribute can't use space as value separator." ); + + m_cla_ids.push_back( parameter_cla_id( prefix, tag, value_separator, negatable ) ); + } + +private: + /// interface for usage/help customization + virtual void cla_name_help( std::ostream& ostr, cstring cla_tag, cstring negation_prefix_ ) const + { + ostr << cla_tag; + } + virtual void value_help( std::ostream& ostr ) const + { + if( p_value_hint.empty() ) + ostr << "<value>"; + else + ostr << p_value_hint; + } + + // Data members + param_cla_ids m_cla_ids; +}; // ************************************************************************** // // ************** runtime::parameter ************** // // ************************************************************************** // -class parameter { +enum args_amount { + OPTIONAL_PARAM, // 0-1 + REQUIRED_PARAM, // exactly 1 + REPEATABLE_PARAM // 0-N +}; + +//____________________________________________________________________________// + +template<typename ValueType, args_amount a = runtime::OPTIONAL_PARAM, bool is_enum = false> +class parameter : public basic_param { public: - virtual ~parameter() {} + /// Constructor with modifiers +#ifndef BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS + template<typename Modifiers=nfp::no_params_type> + parameter( cstring name, Modifiers const& m = nfp::no_params ) +#else + template<typename Modifiers> + parameter( cstring name, Modifiers const& m ) +#endif + : basic_param( name, a != runtime::REQUIRED_PARAM, a == runtime::REPEATABLE_PARAM, m ) + , m_arg_factory( m ) + { + BOOST_TEST_I_ASSRT( !m.has( default_value ) || a == runtime::OPTIONAL_PARAM, + invalid_param_spec() << "Parameter " << name + << " is not optional and can't have default_value." ); + + BOOST_TEST_I_ASSRT( !m.has( optional_value ) || !this->p_repeatable, + invalid_param_spec() << "Parameter " << name + << " is repeatable and can't have optional_value." ); + } + +private: + virtual basic_param_ptr clone() const + { + return basic_param_ptr( new parameter( *this ) ); + } + virtual void produce_argument( cstring token, bool , arguments_store& store ) const + { + m_arg_factory.produce_argument( token, this->p_name, store ); + } + virtual void produce_default( arguments_store& store ) const + { + if( !this->p_has_default_value ) + return; + + m_arg_factory.produce_default( this->p_name, store ); + } + + // Data members + typedef argument_factory<ValueType, is_enum, a == runtime::REPEATABLE_PARAM> factory_t; + factory_t m_arg_factory; +}; + +//____________________________________________________________________________// + +class option : public basic_param { +public: + /// Constructor with modifiers +#ifndef BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS + template<typename Modifiers=nfp::no_params_type> + option( cstring name, Modifiers const& m = nfp::no_params ) +#else + template<typename Modifiers> + option( cstring name, Modifiers const& m ) +#endif + : basic_param( name, true, false, nfp::opt_append( nfp::opt_append( m, optional_value = true), default_value = false) ) + , m_arg_factory( nfp::opt_append( nfp::opt_append( m, optional_value = true), default_value = false) ) + { + } + + void add_cla_id( cstring prefix, cstring tag, cstring value_separator, bool negatable = false ) + { + add_cla_id_impl( prefix, tag, value_separator, negatable, false ); + } + +private: + virtual basic_param_ptr clone() const + { + return basic_param_ptr( new option( *this ) ); + } + + virtual void produce_argument( cstring token, bool negative_form, arguments_store& store ) const + { + if( token.empty() ) + store.set( p_name, !negative_form ); + else { + BOOST_TEST_I_ASSRT( !negative_form, + format_error( p_name ) << "Can't set value to negative form of the argument." ); + + m_arg_factory.produce_argument( token, p_name, store ); + } + } + + virtual void produce_default( arguments_store& store ) const + { + m_arg_factory.produce_default( p_name, store ); + } + virtual void cla_name_help( std::ostream& ostr, cstring cla_tag, cstring negation_prefix_ ) const + { + if( negation_prefix_.is_empty() ) + ostr << cla_tag; + else + ostr << '[' << negation_prefix_ << ']' << cla_tag; + } + virtual void value_help( std::ostream& ostr ) const + { + if( p_value_hint.empty() ) + ostr << "<boolean value>"; + else + ostr << p_value_hint; + } + + // Data members + typedef argument_factory<bool, false, false> factory_t; + factory_t m_arg_factory; }; -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE +//____________________________________________________________________________// +template<typename EnumType, args_amount a = runtime::OPTIONAL_PARAM> +class enum_parameter : public parameter<EnumType, a, true> { + typedef parameter<EnumType, a, true> base; +public: + /// Constructor with modifiers +#ifndef BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS + template<typename Modifiers=nfp::no_params_type> + enum_parameter( cstring name, Modifiers const& m = nfp::no_params ) +#else + template<typename Modifiers> + enum_parameter( cstring name, Modifiers const& m ) +#endif + : base( name, m ) + { +#ifdef BOOST_TEST_CLA_NEW_API + auto const& values = m[enum_values<EnumType>::value]; + auto it = values.begin(); +#else + std::vector<std::pair<cstring, EnumType> > const& values = m[enum_values<EnumType>::value]; + typename std::vector<std::pair<cstring, EnumType> >::const_iterator it = values.begin(); +#endif + while( it != values.end() ) { + m_valid_names.push_back( it->first ); + ++it; + } + } + +private: + virtual basic_param_ptr clone() const + { + return basic_param_ptr( new enum_parameter( *this ) ); + } + + virtual void value_help( std::ostream& ostr ) const + { + if( this->p_value_hint.empty() ) { + ostr << "<"; + bool first = true; + BOOST_TEST_FOREACH( cstring, name, m_valid_names ) { + if( first ) + first = false; + else + ostr << '|'; + ostr << name; + } + ostr << ">"; + } + else + ostr << this->p_value_hint; + } + + // Data members + std::vector<cstring> m_valid_names; +}; + + +// ************************************************************************** // +// ************** runtime::parameters_store ************** // +// ************************************************************************** // + +class parameters_store { + struct lg_compare { + bool operator()( cstring lh, cstring rh ) const + { + return std::lexicographical_compare(lh.begin(), lh.end(), + rh.begin(), rh.end()); + } + }; +public: + + typedef std::map<cstring, basic_param_ptr, lg_compare> storage_type; + + /// Adds parameter into the persistent store + void add( basic_param const& in ) + { + basic_param_ptr p = in.clone(); + + BOOST_TEST_I_ASSRT( m_parameters.insert( std::make_pair( cstring(p->p_name), p ) ).second, + duplicate_param() << "Parameter " << p->p_name << " is duplicate." ); + } + + /// Returns true if there is no parameters registered + bool is_empty() const { return m_parameters.empty(); } + /// Returns map of all the registered parameter + storage_type const& all() const { return m_parameters; } + /// Returns true if parameter with psecified name is registered + bool has( cstring name ) const + { + return m_parameters.find( name ) != m_parameters.end(); + } + /// Returns map of all the registered parameter + basic_param_ptr get( cstring name ) const + { + storage_type::const_iterator const& found = m_parameters.find( name ); + BOOST_TEST_I_ASSRT( found != m_parameters.end(), + unknown_param() << "Parameter " << name << " is unknown." ); + + return found->second; + } + +private: + // Data members + storage_type m_parameters; +}; + +} // namespace runtime } // namespace boost +#include <boost/test/detail/enable_warnings.hpp> + #endif // BOOST_TEST_UTILS_RUNTIME_PARAMETER_HPP diff --git a/boost/test/utils/runtime/trace.hpp b/boost/test/utils/runtime/trace.hpp deleted file mode 100644 index 17a169b283..0000000000 --- a/boost/test/utils/runtime/trace.hpp +++ /dev/null @@ -1,30 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : optional internal tracing -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_TRACE_HPP -#define BOOST_TEST_UTILS_RUNTIME_TRACE_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -#ifdef BOOST_TEST_UTILS_RUNTIME_PARAM_DEBUG - -#include <iostream> - -# define BOOST_TEST_UTILS_RUNTIME_PARAM_TRACE( str ) std::cerr << str << std::endl -#else -# define BOOST_TEST_UTILS_RUNTIME_PARAM_TRACE( str ) -#endif - -#endif // BOOST_TEST_UTILS_RUNTIME_TRACE_HPP diff --git a/boost/test/utils/runtime/validation.hpp b/boost/test/utils/runtime/validation.hpp deleted file mode 100644 index 54163dc6a6..0000000000 --- a/boost/test/utils/runtime/validation.hpp +++ /dev/null @@ -1,85 +0,0 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. -// 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 : $RCSfile$ -// -// Version : $Revision$ -// -// Description : defines exceptions and validation tools -// *************************************************************************** - -#ifndef BOOST_TEST_UTILS_RUNTIME_VALIDATION_HPP -#define BOOST_TEST_UTILS_RUNTIME_VALIDATION_HPP - -// Boost.Runtime.Parameter -#include <boost/test/utils/runtime/config.hpp> - -// Boost.Test -#include <boost/test/utils/class_properties.hpp> -#include <boost/test/detail/throw_exception.hpp> - -// Boost -#include <boost/shared_ptr.hpp> - -// STL -#ifdef BOOST_TEST_UTILS_RUNTIME_PARAM_EXCEPTION_INHERIT_STD -#include <stdexcept> -#endif - -namespace boost { - -namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE { - -// ************************************************************************** // -// ************** runtime::logic_error ************** // -// ************************************************************************** // - -class logic_error -#ifdef BOOST_TEST_UTILS_RUNTIME_PARAM_EXCEPTION_INHERIT_STD -: public std::exception -#endif -{ - typedef shared_ptr<dstring> dstring_ptr; -public: - // Constructor // !! could we eliminate shared_ptr - explicit logic_error( cstring msg ) : m_msg( new dstring( msg.begin(), msg.size() ) ) {} - ~logic_error() BOOST_NOEXCEPT_OR_NOTHROW - {} - - dstring const& msg() const { return *m_msg; } - virtual char_type const* what() const BOOST_NOEXCEPT_OR_NOTHROW - { return m_msg->c_str(); } - -private: - dstring_ptr m_msg; -}; - -// ************************************************************************** // -// ************** runtime::report_logic_error ************** // -// ************************************************************************** // - -inline void -report_logic_error( format_stream& msg ) -{ - BOOST_TEST_IMPL_THROW( BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE::logic_error( msg.str() ) ); -} - -//____________________________________________________________________________// - -#define BOOST_TEST_UTILS_RUNTIME_PARAM_REPORT_LOGIC_ERROR( msg ) \ - boost::BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE::report_logic_error( format_stream().ref() << msg ) - -#define BOOST_TEST_UTILS_RUNTIME_PARAM_VALIDATE_LOGIC( b, msg ) \ - if( b ) {} else BOOST_TEST_UTILS_RUNTIME_PARAM_REPORT_LOGIC_ERROR( msg ) - -//____________________________________________________________________________// - -} // namespace BOOST_TEST_UTILS_RUNTIME_PARAM_NAMESPACE - -} // namespace boost - -#endif // BOOST_TEST_UTILS_RUNTIME_VALIDATION_HPP diff --git a/boost/test/utils/setcolor.hpp b/boost/test/utils/setcolor.hpp index f47ec84d8d..c70209038a 100644 --- a/boost/test/utils/setcolor.hpp +++ b/boost/test/utils/setcolor.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2009-2014. +// (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) @@ -28,6 +28,7 @@ namespace boost { namespace unit_test { +namespace utils { // ************************************************************************** // // ************** term_attr ************** // @@ -102,13 +103,21 @@ struct scope_setcolor { ~scope_setcolor() { if( m_os ) - *m_os << setcolor(); + *m_os << setcolor(); } private: // Data members std::ostream* m_os; }; +#define BOOST_TEST_SCOPE_SETCOLOR( is_color_output, os, attr, color ) \ + utils::scope_setcolor const& sc = is_color_output \ + ? utils::scope_setcolor( os, utils::attr, utils::color ) \ + : utils::scope_setcolor(); \ + ut_detail::ignore_unused_variable_warning( sc ) \ +/**/ + +} // namespace utils } // namespace unit_test } // namespace boost diff --git a/boost/test/utils/string_cast.hpp b/boost/test/utils/string_cast.hpp new file mode 100644 index 0000000000..3c069a8403 --- /dev/null +++ b/boost/test/utils/string_cast.hpp @@ -0,0 +1,69 @@ +// (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 : $RCSfile$ +// +// Version : $Revision$ +// +// Description : trivial utility to cast to/from strings +// *************************************************************************** + +#ifndef BOOST_TEST_UTILS_STRING_CAST_HPP +#define BOOST_TEST_UTILS_STRING_CAST_HPP + +// Boost.Test +#include <boost/test/utils/basic_cstring/basic_cstring.hpp> + +// STL +#include <sstream> + +#include <boost/test/detail/suppress_warnings.hpp> + +//____________________________________________________________________________// + +namespace boost { +namespace unit_test { +namespace utils { + +// ************************************************************************** // +// ************** string_cast ************** // +// ************************************************************************** // + +template<typename T> +inline std::string +string_cast( T const& t ) +{ + std::ostringstream buff; + buff << t; + return buff.str(); +} + +//____________________________________________________________________________// + +// ************************************************************************** // +// ************** string_as ************** // +// ************************************************************************** // + +template<typename T> +inline bool +string_as( const_string str, T& res ) +{ + std::istringstream buff( std::string( str.begin(), str.end() ) ); + buff >> res; + + return !buff.fail() && buff.eof(); +} + +//____________________________________________________________________________// + +} // namespace utils +} // namespace unit_test +} // namespace boost + +#include <boost/test/detail/enable_warnings.hpp> + +#endif // BOOST_TEST_UTILS_STRING_CAST_HPP diff --git a/boost/test/utils/trivial_singleton.hpp b/boost/test/utils/trivial_singleton.hpp index 818bad73ea..ac612b6393 100644 --- a/boost/test/utils/trivial_singleton.hpp +++ b/boost/test/utils/trivial_singleton.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2005-2014. +// (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) diff --git a/boost/test/utils/wrap_stringstream.hpp b/boost/test/utils/wrap_stringstream.hpp index e42adbd3ad..425d7ed75b 100644 --- a/boost/test/utils/wrap_stringstream.hpp +++ b/boost/test/utils/wrap_stringstream.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2002-2014. +// (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) diff --git a/boost/test/utils/xml_printer.hpp b/boost/test/utils/xml_printer.hpp index 8552a173f9..ffaf8fcc05 100644 --- a/boost/test/utils/xml_printer.hpp +++ b/boost/test/utils/xml_printer.hpp @@ -1,4 +1,4 @@ -// (C) Copyright Gennadiy Rozental 2004-2014. +// (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) @@ -17,7 +17,6 @@ // Boost.Test #include <boost/test/utils/basic_cstring/basic_cstring.hpp> -#include <boost/test/utils/fixed_mapping.hpp> #include <boost/test/utils/custom_manip.hpp> #include <boost/test/utils/foreach.hpp> #include <boost/test/utils/basic_cstring/io.hpp> @@ -34,6 +33,7 @@ namespace boost { namespace unit_test { +namespace utils { // ************************************************************************** // // ************** xml print helpers ************** // @@ -42,21 +42,31 @@ namespace unit_test { inline void print_escaped( std::ostream& where_to, const_string value ) { - static fixed_mapping<char,char const*> char_type( - '<' , "lt", - '>' , "gt", - '&' , "amp", - '\'', "apos" , - '"' , "quot", - - 0 - ); +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) + static std::map<char,char const*> const char_type{{ + {'<' , "lt"}, + {'>' , "gt"}, + {'&' , "amp"}, + {'\'', "apos"}, + {'"' , "quot"} + }}; +#else + static std::map<char,char const*> char_type; + + if( char_type.empty() ) { + char_type['<'] = "lt"; + char_type['>'] = "gt"; + char_type['&'] = "amp"; + char_type['\'']= "apos"; + char_type['"'] = "quot"; + } +#endif BOOST_TEST_FOREACH( char, c, value ) { - char const* ref = char_type[c]; + std::map<char,char const*>::const_iterator found_ref = char_type.find( c ); - if( ref ) - where_to << '&' << ref << ';'; + if( found_ref != char_type.end() ) + where_to << '&' << found_ref->second << ';'; else where_to << c; } @@ -124,6 +134,7 @@ operator<<( custom_printer<cdata> const& p, const_string value ) //____________________________________________________________________________// +} // namespace utils } // namespace unit_test } // namespace boost |