update boost
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
#ifndef BOOST_TEST_UTILS_ALGORITHM_HPP
|
||||
#define BOOST_TEST_UTILS_ALGORITHM_HPP
|
||||
|
||||
#include <boost/test/detail/config.hpp>
|
||||
|
||||
// STL
|
||||
#include <utility>
|
||||
#include <algorithm> // std::find
|
||||
|
||||
@@ -26,6 +26,10 @@
|
||||
// STL
|
||||
#include <string>
|
||||
|
||||
#if defined(BOOST_TEST_STRING_VIEW)
|
||||
#include <string_view>
|
||||
#endif
|
||||
|
||||
#include <boost/test/detail/suppress_warnings.hpp>
|
||||
|
||||
//____________________________________________________________________________//
|
||||
@@ -166,6 +170,30 @@ private:
|
||||
static CharT null;
|
||||
};
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** cstring_string_view_helper ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
|
||||
#if defined(BOOST_TEST_STRING_VIEW)
|
||||
// Helper for instanciating a subclass of cstring using a string_view. We do not
|
||||
// change the API of cstring using BOOST_TEST_STRING_VIEW as the code should remain
|
||||
// compatible between boost.test and test module using different compiler options.
|
||||
//! @internal
|
||||
template <class CharT, class string_view_t = std::basic_string_view<CharT>>
|
||||
class BOOST_SYMBOL_VISIBLE stringview_cstring_helper : public basic_cstring<CharT> {
|
||||
public:
|
||||
stringview_cstring_helper(string_view_t const& sv)
|
||||
: basic_cstring<CharT>(const_cast<CharT*>(sv.data()), sv.size())
|
||||
{}
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
// ************************************************************************** //
|
||||
// ************** basic_cstring::impl ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
template<typename CharT>
|
||||
@@ -373,17 +401,22 @@ template<typename CharT>
|
||||
inline basic_cstring<CharT>&
|
||||
basic_cstring<CharT>::trim_right( basic_cstring exclusions )
|
||||
{
|
||||
if(!size()) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
if( exclusions.is_empty() )
|
||||
exclusions = default_trim_ex();
|
||||
|
||||
iterator it;
|
||||
iterator it = end();
|
||||
|
||||
for( it = end()-1; it != begin()-1; --it ) {
|
||||
do {
|
||||
--it;
|
||||
if( self_type::traits_type::find( exclusions.begin(), exclusions.size(), *it ) == reinterpret_cast<pointer>(0) )
|
||||
break;
|
||||
}
|
||||
} while(it != begin());
|
||||
|
||||
return trim_right( it+1 );
|
||||
return trim_right( it + 1 );
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
@@ -515,19 +548,16 @@ inline typename basic_cstring<CharT>::size_type
|
||||
basic_cstring<CharT>::find( basic_cstring<CharT> str ) const
|
||||
{
|
||||
if( str.is_empty() || str.size() > size() )
|
||||
return static_cast<size_type>(npos);
|
||||
return npos;
|
||||
|
||||
const_iterator it = begin();
|
||||
const_iterator last = end() - str.size() + 1;
|
||||
|
||||
while( it != last ) {
|
||||
for( const_iterator it = begin(); it != last; ++it ) {
|
||||
if( traits_type::compare( it, str.begin(), str.size() ) == 0 )
|
||||
break;
|
||||
|
||||
++it;
|
||||
return static_cast<size_type>(it - begin());
|
||||
}
|
||||
|
||||
return it == last ? npos : static_cast<size_type>(it - begin());
|
||||
return npos;
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
@@ -537,19 +567,18 @@ inline typename basic_cstring<CharT>::size_type
|
||||
basic_cstring<CharT>::rfind( basic_cstring<CharT> str ) const
|
||||
{
|
||||
if( str.is_empty() || str.size() > size() )
|
||||
return static_cast<size_type>(npos);
|
||||
return npos;
|
||||
|
||||
const_iterator it = end() - str.size();
|
||||
const_iterator last = begin()-1;
|
||||
const_iterator first = begin();
|
||||
|
||||
while( it != last ) {
|
||||
for( const_iterator it = end() - str.size(); it != first; --it ) {
|
||||
if( traits_type::compare( it, str.begin(), str.size() ) == 0 )
|
||||
break;
|
||||
|
||||
--it;
|
||||
return static_cast<size_type>(it - begin());
|
||||
}
|
||||
|
||||
return it == last ? static_cast<size_type>(npos) : static_cast<size_type>(it - begin());
|
||||
if( traits_type::compare( first, str.begin(), str.size() ) == 0 )
|
||||
return static_cast<size_type>(0);
|
||||
else
|
||||
return npos;
|
||||
}
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <boost/test/detail/config.hpp>
|
||||
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace unit_test {
|
||||
@@ -32,6 +33,12 @@ typedef const_string const literal_string;
|
||||
|
||||
typedef char const* const c_literal_string;
|
||||
|
||||
#if defined(BOOST_TEST_STRING_VIEW)
|
||||
template <class CharT, class string_view_t>
|
||||
class BOOST_SYMBOL_VISIBLE stringview_cstring_helper;
|
||||
#endif
|
||||
|
||||
|
||||
} // namespace unit_test
|
||||
|
||||
} // namespace boost
|
||||
|
||||
@@ -39,7 +39,7 @@ template<typename CharT> struct bcs_base_char { typedef CharT type; };
|
||||
|
||||
template<> struct bcs_base_char<char const> { typedef char type; };
|
||||
template<> struct bcs_base_char<unsigned char> { typedef char type; };
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
|
||||
#if !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x551))
|
||||
template<> struct bcs_base_char<unsigned char const> { typedef char type; };
|
||||
#endif
|
||||
|
||||
@@ -52,7 +52,7 @@ template<> struct bcs_base_char<wchar_t const> { typedef wchar_t type;
|
||||
template<typename CharT>
|
||||
struct bcs_char_traits_impl
|
||||
{
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
|
||||
#if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
|
||||
typedef CharT const const_char;
|
||||
#else
|
||||
typedef typename boost::add_const<CharT>::type const_char;
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
# if defined(BOOST_NO_STDC_NAMESPACE) && !BOOST_WORKAROUND(__BORLANDC__, <= 0x570)
|
||||
# if defined(BOOST_NO_STDC_NAMESPACE) && !BOOST_WORKAROUND(BOOST_BORLANDC, <= 0x570)
|
||||
namespace std { using ::toupper; }
|
||||
# endif
|
||||
|
||||
|
||||
@@ -5,11 +5,8 @@
|
||||
|
||||
// See http://www.boost.org/libs/test for the library home page.
|
||||
//
|
||||
// File : $RCSfile$
|
||||
//
|
||||
// Version : $Revision$
|
||||
//
|
||||
// Description : defines the is_cstring type trait
|
||||
//! @file
|
||||
//! Defines the is_cstring type trait
|
||||
// ***************************************************************************
|
||||
|
||||
#ifndef BOOST_TEST_UTILS_IS_CSTRING_HPP
|
||||
@@ -26,6 +23,10 @@
|
||||
#include <boost/test/utils/basic_cstring/basic_cstring_fwd.hpp>
|
||||
#include <string>
|
||||
|
||||
#if defined(BOOST_TEST_STRING_VIEW)
|
||||
#include <string_view>
|
||||
#endif
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
namespace boost {
|
||||
@@ -53,16 +54,16 @@ template<>
|
||||
struct is_cstring_impl<wchar_t*> : public mpl::true_ {};
|
||||
|
||||
template <typename T, bool is_cstring = is_cstring_impl<typename boost::decay<T>::type>::value >
|
||||
struct deduce_cstring_impl;
|
||||
struct deduce_cstring_transform_impl;
|
||||
|
||||
template <typename T, bool is_cstring >
|
||||
struct deduce_cstring_impl<T&, is_cstring> : public deduce_cstring_impl<T, is_cstring>{};
|
||||
struct deduce_cstring_transform_impl<T&, is_cstring> : public deduce_cstring_transform_impl<T, is_cstring>{};
|
||||
|
||||
template <typename T, bool is_cstring >
|
||||
struct deduce_cstring_impl<T const, is_cstring> : public deduce_cstring_impl<T, is_cstring>{};
|
||||
struct deduce_cstring_transform_impl<T const, is_cstring> : public deduce_cstring_transform_impl<T, is_cstring>{};
|
||||
|
||||
template <typename T>
|
||||
struct deduce_cstring_impl<T, true> {
|
||||
struct deduce_cstring_transform_impl<T, true> {
|
||||
typedef typename boost::add_const<
|
||||
typename boost::remove_pointer<
|
||||
typename boost::decay<T>::type
|
||||
@@ -72,7 +73,7 @@ struct deduce_cstring_impl<T, true> {
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct deduce_cstring_impl< T, false > {
|
||||
struct deduce_cstring_transform_impl< T, false > {
|
||||
typedef typename
|
||||
boost::remove_const<
|
||||
typename boost::remove_reference<T>::type
|
||||
@@ -80,10 +81,21 @@ struct deduce_cstring_impl< T, false > {
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct deduce_cstring_impl< std::basic_string<T, std::char_traits<T> >, false > {
|
||||
struct deduce_cstring_transform_impl< std::basic_string<T, std::char_traits<T> >, false > {
|
||||
typedef boost::unit_test::basic_cstring<typename boost::add_const<T>::type> type;
|
||||
};
|
||||
|
||||
#if defined(BOOST_TEST_STRING_VIEW)
|
||||
template <typename T>
|
||||
struct deduce_cstring_transform_impl< std::basic_string_view<T, std::char_traits<T> >, false > {
|
||||
private:
|
||||
using sv_t = std::basic_string_view<T, std::char_traits<T> > ;
|
||||
|
||||
public:
|
||||
using type = stringview_cstring_helper<typename boost::add_const<T>::type, sv_t>;
|
||||
};
|
||||
#endif
|
||||
|
||||
} // namespace ut_detail
|
||||
|
||||
template<typename T>
|
||||
@@ -98,16 +110,21 @@ struct is_cstring_comparable< T, true > : public mpl::true_ {};
|
||||
template<typename T>
|
||||
struct is_cstring_comparable< std::basic_string<T, std::char_traits<T> >, false > : public mpl::true_ {};
|
||||
|
||||
#if defined(BOOST_TEST_STRING_VIEW)
|
||||
template<typename T>
|
||||
struct is_cstring_comparable< std::basic_string_view<T, std::char_traits<T> >, false > : public mpl::true_ {};
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
struct is_cstring_comparable< boost::unit_test::basic_cstring<T>, false > : public mpl::true_ {};
|
||||
|
||||
template <class T>
|
||||
struct deduce_cstring {
|
||||
struct deduce_cstring_transform {
|
||||
typedef typename
|
||||
boost::remove_const<
|
||||
typename boost::remove_reference<T>::type
|
||||
>::type U;
|
||||
typedef typename ut_detail::deduce_cstring_impl<typename boost::decay<U>::type>::type type;
|
||||
typedef typename ut_detail::deduce_cstring_transform_impl<typename boost::decay<U>::type>::type type;
|
||||
};
|
||||
|
||||
} // namespace unit_test
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace utils {
|
||||
|
||||
class input_iterator_core_access
|
||||
{
|
||||
#if defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
|
||||
#if defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS) || BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x551))
|
||||
public:
|
||||
#else
|
||||
template <class I, class V, class R, class TC> friend class input_iterator_facade;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
// Boost.Test
|
||||
#include <boost/test/detail/config.hpp>
|
||||
#include <boost/test/tools/detail/print_helper.hpp>
|
||||
|
||||
// STL
|
||||
#include <iosfwd>
|
||||
@@ -34,8 +35,16 @@ public:
|
||||
|
||||
static lazy_ostream& instance() { return inst; }
|
||||
|
||||
#if !defined(BOOST_EMBTC)
|
||||
|
||||
friend std::ostream& operator<<( std::ostream& ostr, lazy_ostream const& o ) { return o( ostr ); }
|
||||
|
||||
#else
|
||||
|
||||
friend std::ostream& operator<<( std::ostream& ostr, lazy_ostream const& o );
|
||||
|
||||
#endif
|
||||
|
||||
// access method
|
||||
bool empty() const { return m_empty; }
|
||||
|
||||
@@ -50,6 +59,12 @@ private:
|
||||
static lazy_ostream inst;
|
||||
};
|
||||
|
||||
#if defined(BOOST_EMBTC)
|
||||
|
||||
inline std::ostream& operator<<( std::ostream& ostr, lazy_ostream const& o ) { return o( ostr ); }
|
||||
|
||||
#endif
|
||||
|
||||
//____________________________________________________________________________//
|
||||
|
||||
template<typename PrevType, typename T, typename StorageT=T const&>
|
||||
@@ -62,9 +77,9 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
virtual std::ostream& operator()( std::ostream& ostr ) const
|
||||
std::ostream& operator()( std::ostream& ostr ) const BOOST_OVERRIDE
|
||||
{
|
||||
return m_prev(ostr) << m_value;
|
||||
return m_prev(ostr) << test_tools::tt_detail::print_helper(m_value);
|
||||
}
|
||||
private:
|
||||
// Data members
|
||||
|
||||
@@ -126,7 +126,7 @@ report_access_to_invalid_parameter( bool v )
|
||||
|
||||
struct nil {
|
||||
template<typename T>
|
||||
#if defined(__GNUC__) || defined(__HP_aCC) || defined(__EDG__) || defined(__SUNPRO_CC)
|
||||
#if defined(__GNUC__) || defined(__HP_aCC) || defined(__EDG__) || defined(__SUNPRO_CC) || defined(BOOST_EMBTC)
|
||||
operator T() const
|
||||
#else
|
||||
operator T const&() const
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
/// Returns new argc
|
||||
int remainder()
|
||||
{
|
||||
return m_argc;
|
||||
return static_cast<int>(m_argc);
|
||||
}
|
||||
|
||||
/// Returns true, if we reached end on input
|
||||
|
||||
@@ -39,9 +39,9 @@ namespace runtime {
|
||||
|
||||
class BOOST_SYMBOL_VISIBLE param_error : public std::exception {
|
||||
public:
|
||||
~param_error() BOOST_NOEXCEPT_OR_NOTHROW {}
|
||||
BOOST_TEST_DEFAULTED_FUNCTION(~param_error() BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE, {})
|
||||
|
||||
virtual const char * what() const BOOST_NOEXCEPT_OR_NOTHROW
|
||||
const char * what() const BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE
|
||||
{
|
||||
return msg.c_str();
|
||||
}
|
||||
@@ -58,13 +58,13 @@ protected:
|
||||
class BOOST_SYMBOL_VISIBLE init_error : public param_error {
|
||||
protected:
|
||||
explicit init_error( cstring param_name ) : param_error( param_name ) {}
|
||||
~init_error() BOOST_NOEXCEPT_OR_NOTHROW {}
|
||||
BOOST_TEST_DEFAULTED_FUNCTION(~init_error() BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE, {})
|
||||
};
|
||||
|
||||
class BOOST_SYMBOL_VISIBLE input_error : public param_error {
|
||||
protected:
|
||||
explicit input_error( cstring param_name ) : param_error( param_name ) {}
|
||||
~input_error() BOOST_NOEXCEPT_OR_NOTHROW {}
|
||||
BOOST_TEST_DEFAULTED_FUNCTION(~input_error() BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE, {})
|
||||
};
|
||||
|
||||
//____________________________________________________________________________//
|
||||
@@ -73,7 +73,7 @@ template<typename Derived, typename Base>
|
||||
class BOOST_SYMBOL_VISIBLE specific_param_error : public Base {
|
||||
protected:
|
||||
explicit specific_param_error( cstring param_name ) : Base( param_name ) {}
|
||||
~specific_param_error() BOOST_NOEXCEPT_OR_NOTHROW {}
|
||||
BOOST_TEST_DEFAULTED_FUNCTION(~specific_param_error() BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE, {})
|
||||
|
||||
public:
|
||||
|
||||
@@ -166,7 +166,7 @@ public:
|
||||
: specific_param_error<ambiguous_param,input_error>( "" )
|
||||
, m_amb_candidates( amb_candidates ) {}
|
||||
#endif
|
||||
~ambiguous_param() BOOST_NOEXCEPT_OR_NOTHROW {}
|
||||
BOOST_TEST_DEFAULTED_FUNCTION(~ambiguous_param() BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE, {})
|
||||
|
||||
std::vector<cstring> m_amb_candidates;
|
||||
};
|
||||
@@ -182,7 +182,7 @@ public:
|
||||
: specific_param_error<unrecognized_param,input_error>( "" )
|
||||
, m_typo_candidates( type_candidates ) {}
|
||||
#endif
|
||||
~unrecognized_param() BOOST_NOEXCEPT_OR_NOTHROW {}
|
||||
BOOST_TEST_DEFAULTED_FUNCTION(~unrecognized_param(), BOOST_NOEXCEPT_OR_NOTHROW BOOST_OVERRIDE {})
|
||||
|
||||
std::vector<cstring> m_typo_candidates;
|
||||
};
|
||||
|
||||
@@ -148,7 +148,7 @@ protected:
|
||||
}
|
||||
|
||||
public:
|
||||
virtual ~basic_param() {}
|
||||
BOOST_TEST_DEFAULTED_FUNCTION(virtual ~basic_param(), {})
|
||||
|
||||
// Pubic properties
|
||||
std::string const p_name;
|
||||
@@ -322,15 +322,15 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
virtual basic_param_ptr clone() const
|
||||
basic_param_ptr clone() const BOOST_OVERRIDE
|
||||
{
|
||||
return basic_param_ptr( new parameter( *this ) );
|
||||
}
|
||||
virtual void produce_argument( cstring token, bool , arguments_store& store ) const
|
||||
void produce_argument( cstring token, bool , arguments_store& store ) const BOOST_OVERRIDE
|
||||
{
|
||||
m_arg_factory.produce_argument( token, this->p_name, store );
|
||||
}
|
||||
virtual void produce_default( arguments_store& store ) const
|
||||
void produce_default( arguments_store& store ) const BOOST_OVERRIDE
|
||||
{
|
||||
if( !this->p_has_default_value )
|
||||
return;
|
||||
@@ -366,12 +366,12 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
virtual basic_param_ptr clone() const
|
||||
basic_param_ptr clone() const BOOST_OVERRIDE
|
||||
{
|
||||
return basic_param_ptr( new option( *this ) );
|
||||
}
|
||||
|
||||
virtual void produce_argument( cstring token, bool negative_form, arguments_store& store ) const
|
||||
void produce_argument( cstring token, bool negative_form, arguments_store& store ) const BOOST_OVERRIDE
|
||||
{
|
||||
if( token.empty() )
|
||||
store.set( p_name, !negative_form );
|
||||
@@ -383,11 +383,11 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
virtual void produce_default( arguments_store& store ) const
|
||||
void produce_default( arguments_store& store ) const BOOST_OVERRIDE
|
||||
{
|
||||
m_arg_factory.produce_default( p_name, store );
|
||||
}
|
||||
virtual void cla_name_help( std::ostream& ostr, cstring cla_tag, cstring negation_prefix_, bool use_color = true ) const
|
||||
void cla_name_help( std::ostream& ostr, cstring cla_tag, cstring negation_prefix_, bool use_color = true ) const BOOST_OVERRIDE
|
||||
{
|
||||
namespace utils = unit_test::utils;
|
||||
namespace ut_detail = unit_test::ut_detail;
|
||||
@@ -398,7 +398,7 @@ private:
|
||||
}
|
||||
ostr << cla_tag;
|
||||
}
|
||||
virtual void value_help( std::ostream& ostr ) const
|
||||
void value_help( std::ostream& ostr ) const BOOST_OVERRIDE
|
||||
{
|
||||
if( p_value_hint.empty() )
|
||||
ostr << "<boolean value>";
|
||||
@@ -441,12 +441,12 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
virtual basic_param_ptr clone() const
|
||||
basic_param_ptr clone() const BOOST_OVERRIDE
|
||||
{
|
||||
return basic_param_ptr( new enum_parameter( *this ) );
|
||||
}
|
||||
|
||||
virtual void value_help( std::ostream& ostr ) const
|
||||
void value_help( std::ostream& ostr ) const BOOST_OVERRIDE
|
||||
{
|
||||
if( this->p_value_hint.empty() ) {
|
||||
ostr << "<";
|
||||
@@ -498,7 +498,7 @@ public:
|
||||
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
|
||||
/// Returns true if parameter with specified name is registered
|
||||
bool has( cstring name ) const
|
||||
{
|
||||
return m_parameters.find( name ) != m_parameters.end();
|
||||
|
||||
@@ -19,10 +19,12 @@
|
||||
#include <boost/test/detail/config.hpp>
|
||||
|
||||
#include <boost/core/ignore_unused.hpp>
|
||||
#include <boost/core/snprintf.hpp>
|
||||
|
||||
// STL
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include <cassert>
|
||||
|
||||
#include <boost/test/detail/suppress_warnings.hpp>
|
||||
|
||||
@@ -78,20 +80,44 @@ struct term_color { enum _ {
|
||||
#ifndef _WIN32
|
||||
class setcolor {
|
||||
public:
|
||||
typedef int state;
|
||||
|
||||
// Constructor
|
||||
explicit setcolor( bool is_color_output = false,
|
||||
term_attr::_ attr = term_attr::NORMAL,
|
||||
term_color::_ fg = term_color::ORIGINAL,
|
||||
term_color::_ bg = term_color::ORIGINAL )
|
||||
term_color::_ bg = term_color::ORIGINAL,
|
||||
state* /* unused */= NULL)
|
||||
: m_is_color_output(is_color_output)
|
||||
{
|
||||
m_command_size = std::sprintf( m_control_command, "%c[%c;3%c;4%cm",
|
||||
#ifdef BOOST_MSVC
|
||||
m_command_size = std::sprintf( m_control_command,
|
||||
#else
|
||||
m_command_size = boost::core::snprintf( m_control_command, sizeof(m_control_command),
|
||||
#endif
|
||||
"%c[%c;3%c;4%cm",
|
||||
0x1B,
|
||||
static_cast<char>(attr + '0'),
|
||||
static_cast<char>(fg + '0'),
|
||||
static_cast<char>(bg + '0'));
|
||||
}
|
||||
|
||||
explicit setcolor(bool is_color_output,
|
||||
state* /* unused */)
|
||||
: m_is_color_output(is_color_output)
|
||||
{
|
||||
#ifdef BOOST_MSVC
|
||||
m_command_size = std::sprintf( m_control_command,
|
||||
#else
|
||||
m_command_size = boost::core::snprintf(m_control_command, sizeof(m_control_command),
|
||||
#endif
|
||||
"%c[%c;3%c;4%cm",
|
||||
0x1B,
|
||||
static_cast<char>(term_attr::NORMAL + '0'),
|
||||
static_cast<char>(term_color::ORIGINAL + '0'),
|
||||
static_cast<char>(term_color::ORIGINAL + '0'));
|
||||
}
|
||||
|
||||
friend std::ostream&
|
||||
operator<<( std::ostream& os, setcolor const& sc )
|
||||
{
|
||||
@@ -114,7 +140,7 @@ class setcolor {
|
||||
|
||||
protected:
|
||||
void set_console_color(std::ostream& os, WORD *attributes = NULL) const {
|
||||
if (!m_is_color_output) {
|
||||
if (!m_is_color_output || m_state_saved) {
|
||||
return;
|
||||
}
|
||||
DWORD console_type;
|
||||
@@ -132,14 +158,30 @@ protected:
|
||||
if(hConsole == INVALID_HANDLE_VALUE || hConsole == NULL )
|
||||
return;
|
||||
|
||||
if(attributes != NULL) {
|
||||
SetConsoleTextAttribute(hConsole, *attributes);
|
||||
state console_attributes;
|
||||
if(attributes != NULL || (m_restore_state && m_s)) {
|
||||
if (attributes != NULL) {
|
||||
console_attributes = *attributes;
|
||||
}
|
||||
else {
|
||||
console_attributes = *m_s;
|
||||
*m_s = state();
|
||||
}
|
||||
SetConsoleTextAttribute(hConsole, console_attributes);
|
||||
return;
|
||||
}
|
||||
|
||||
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
|
||||
GetConsoleScreenBufferInfo(hConsole, &consoleInfo);
|
||||
saved_attributes = consoleInfo.wAttributes;
|
||||
console_attributes = consoleInfo.wAttributes;
|
||||
|
||||
if (!m_state_saved && m_s) {
|
||||
assert(!m_restore_state);
|
||||
// we can save the state only the first time this object is used
|
||||
// for modifying the console.
|
||||
*m_s = console_attributes;
|
||||
m_state_saved = true;
|
||||
}
|
||||
|
||||
WORD fg_attr = 0;
|
||||
switch(m_fg)
|
||||
@@ -168,9 +210,9 @@ protected:
|
||||
case term_color::YELLOW:
|
||||
fg_attr = FOREGROUND_RED | FOREGROUND_GREEN;
|
||||
break;
|
||||
case term_color::ORIGINAL:
|
||||
case term_color::ORIGINAL:
|
||||
default:
|
||||
fg_attr = saved_attributes & (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
|
||||
fg_attr = console_attributes & (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -192,9 +234,9 @@ protected:
|
||||
case term_color::BLUE:
|
||||
bg_attr = BACKGROUND_BLUE;
|
||||
break;
|
||||
case term_color::ORIGINAL:
|
||||
case term_color::ORIGINAL:
|
||||
default:
|
||||
bg_attr = saved_attributes & (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
|
||||
bg_attr = console_attributes & (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -216,16 +258,34 @@ protected:
|
||||
}
|
||||
|
||||
public:
|
||||
typedef WORD state;
|
||||
|
||||
// Constructor
|
||||
explicit setcolor(
|
||||
bool is_color_output = false,
|
||||
term_attr::_ attr = term_attr::NORMAL,
|
||||
term_color::_ fg = term_color::ORIGINAL,
|
||||
term_color::_ bg = term_color::ORIGINAL )
|
||||
term_color::_ bg = term_color::ORIGINAL,
|
||||
state* s = NULL)
|
||||
: m_is_color_output(is_color_output)
|
||||
, m_attr(attr)
|
||||
, m_fg(fg)
|
||||
, m_bg(bg)
|
||||
, m_s(s)
|
||||
, m_restore_state(false)
|
||||
, m_state_saved(false)
|
||||
{}
|
||||
|
||||
explicit setcolor(
|
||||
bool is_color_output,
|
||||
state* s)
|
||||
: m_is_color_output(is_color_output)
|
||||
, m_attr(term_attr::NORMAL)
|
||||
, m_fg(term_color::ORIGINAL)
|
||||
, m_bg(term_color::ORIGINAL)
|
||||
, m_s(s)
|
||||
, m_restore_state(true)
|
||||
, m_state_saved(false)
|
||||
{}
|
||||
|
||||
friend std::ostream&
|
||||
@@ -240,10 +300,12 @@ private:
|
||||
term_attr::_ m_attr;
|
||||
term_color::_ m_fg;
|
||||
term_color::_ m_bg;
|
||||
|
||||
protected:
|
||||
// Data members
|
||||
mutable WORD saved_attributes;
|
||||
state* m_s;
|
||||
// indicates that the instance has been initialized to restore a previously
|
||||
// stored state
|
||||
bool m_restore_state;
|
||||
// indicates the first time we pull and set the console information.
|
||||
mutable bool m_state_saved;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -251,53 +313,29 @@ protected:
|
||||
// ************** scope_setcolor ************** //
|
||||
// ************************************************************************** //
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
struct scope_setcolor {
|
||||
scope_setcolor() : m_os( 0 ) {}
|
||||
explicit scope_setcolor( bool is_color_output,
|
||||
std::ostream& os,
|
||||
term_attr::_ attr = term_attr::NORMAL,
|
||||
term_color::_ fg = term_color::ORIGINAL,
|
||||
term_color::_ bg = term_color::ORIGINAL )
|
||||
: m_os( &os )
|
||||
, m_is_color_output( is_color_output )
|
||||
{
|
||||
os << setcolor( is_color_output, attr, fg, bg );
|
||||
}
|
||||
~scope_setcolor()
|
||||
{
|
||||
if( m_os )
|
||||
*m_os << setcolor( m_is_color_output );
|
||||
}
|
||||
private:
|
||||
scope_setcolor(const scope_setcolor& r);
|
||||
scope_setcolor& operator=(const scope_setcolor& r);
|
||||
// Data members
|
||||
std::ostream* m_os;
|
||||
bool m_is_color_output;
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
struct scope_setcolor : setcolor {
|
||||
scope_setcolor() : m_os( 0 ) {}
|
||||
explicit scope_setcolor(
|
||||
scope_setcolor()
|
||||
: m_os( 0 )
|
||||
, m_state()
|
||||
, m_is_color_output(false)
|
||||
{}
|
||||
|
||||
explicit scope_setcolor(
|
||||
bool is_color_output,
|
||||
std::ostream& os,
|
||||
term_attr::_ attr = term_attr::NORMAL,
|
||||
term_color::_ fg = term_color::ORIGINAL,
|
||||
term_color::_ bg = term_color::ORIGINAL )
|
||||
: setcolor(is_color_output, attr, fg, bg)
|
||||
, m_os( &os )
|
||||
: m_os( &os )
|
||||
, m_is_color_output(is_color_output)
|
||||
{
|
||||
os << *this;
|
||||
os << setcolor(is_color_output, attr, fg, bg, &m_state);
|
||||
}
|
||||
|
||||
~scope_setcolor()
|
||||
{
|
||||
if (m_os) {
|
||||
set_console_color(*m_os, &this->saved_attributes);
|
||||
*m_os << setcolor(m_is_color_output, &m_state);
|
||||
}
|
||||
}
|
||||
private:
|
||||
@@ -305,11 +343,11 @@ private:
|
||||
scope_setcolor& operator=(const scope_setcolor& r);
|
||||
// Data members
|
||||
std::ostream* m_os;
|
||||
setcolor::state m_state;
|
||||
bool m_is_color_output;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#define BOOST_TEST_SCOPE_SETCOLOR( is_color_output, os, attr, color ) \
|
||||
utils::scope_setcolor const sc(is_color_output, os, utils::attr, utils::color); \
|
||||
boost::ignore_unused( sc ) \
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
# if defined(_WIN32) || defined(__CYGWIN__)
|
||||
# define BOOST_TEST_TIMER_WINDOWS_API
|
||||
# elif defined(__MACH__)// && !defined(CLOCK_MONOTONIC)
|
||||
# elif defined(__MACH__) && defined(__APPLE__)// && !defined(CLOCK_MONOTONIC)
|
||||
# // we compile for all macs the same, CLOCK_MONOTONIC introduced in 10.12
|
||||
# define BOOST_TEST_TIMER_MACH_API
|
||||
# else
|
||||
@@ -133,6 +133,7 @@ namespace timer {
|
||||
return_value.wall = static_cast<nanosecond_type>((clock * timebase.first) / timebase.second);
|
||||
#else
|
||||
struct timespec end_time;
|
||||
return_value.wall = 0;
|
||||
if( ::clock_gettime( CLOCK_MONOTONIC, &end_time ) == 0 )
|
||||
{
|
||||
return_value.wall = static_cast<nanosecond_type>((end_time.tv_sec - _start_time_wall.tv_sec) * 1E9 + (end_time.tv_nsec - _start_time_wall.tv_nsec));
|
||||
|
||||
Reference in New Issue
Block a user