mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Use explicit streaming ops instead of Boost.LexicalCast
This commit is contained in:
parent
898a5a4524
commit
04dff97fde
5 changed files with 24 additions and 17 deletions
|
|
@ -8,14 +8,16 @@
|
|||
|
||||
#include <turtle/detail/type_name.hpp>
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <sstream>
|
||||
|
||||
namespace
|
||||
{
|
||||
template< typename T >
|
||||
std::string to_string( const T& t)
|
||||
{
|
||||
return boost::lexical_cast< std::string >( mock::detail::make_type_name(t) );
|
||||
std::ostringstream s;
|
||||
s << mock::detail::make_type_name(t); // Typename can be streamed
|
||||
return s.str();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -111,7 +113,7 @@ BOOST_AUTO_TEST_CASE( name_of_type_in_unnamed_inner_namespace_is_extracted )
|
|||
BOOST_AUTO_TEST_CASE( name_of_local_type_is_extracted )
|
||||
{
|
||||
struct my_local_type {};
|
||||
BOOST_CHECK_EQUAL( "my_local_type", boost::lexical_cast< std::string >( mock::detail::make_type_name<my_local_type>() ) );
|
||||
BOOST_CHECK_EQUAL( "my_local_type", to_string( my_local_type() ) );
|
||||
}
|
||||
|
||||
namespace
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@
|
|||
|
||||
#define MOCK_ERROR_POLICY mock_error
|
||||
#include <turtle/detail/singleton.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
|
||||
struct mock_error_data_t : mock::detail::singleton< mock_error_data_t >
|
||||
{
|
||||
|
|
@ -68,18 +68,17 @@ struct mock_error
|
|||
{}
|
||||
|
||||
template< typename Context >
|
||||
static void call( const Context& /*context*/,
|
||||
const char* /*file*/, int /*line*/ )
|
||||
static void call( const Context& /*context*/, const char* /*file*/, int /*line*/ )
|
||||
{
|
||||
mock_error_data.call();
|
||||
}
|
||||
|
||||
template< typename Context >
|
||||
static void fail( const std::string& message, const Context& context,
|
||||
const char* file = "", int line = 0 )
|
||||
static void fail( const std::string& message, const Context& context, const char* file = "", int line = 0 )
|
||||
{
|
||||
mock_error_data.fail( message,
|
||||
boost::lexical_cast< std::string >( context ), file, line );
|
||||
std::ostringstream s;
|
||||
s << context; // Context can be streamed
|
||||
mock_error_data.fail( message, s.str(), file, line );
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@
|
|||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <boost/assign.hpp>
|
||||
#include <boost/weak_ptr.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning( push, 0 )
|
||||
|
|
@ -55,13 +54,19 @@ BOOST_AUTO_TEST_CASE( pointer_yields_its_value_when_serialized )
|
|||
{
|
||||
{
|
||||
int i = 0;
|
||||
std::ostringstream s;
|
||||
s << &i;
|
||||
const std::string pointerValue = s.str();
|
||||
BOOST_CHECK_NE( "?", to_string( &i ) );
|
||||
BOOST_CHECK_EQUAL( boost::lexical_cast< std::string >( &i ), to_string( &i ) );
|
||||
BOOST_CHECK_EQUAL( pointerValue, to_string( &i ) );
|
||||
}
|
||||
{
|
||||
const int i = 0;
|
||||
std::ostringstream s;
|
||||
s << &i;
|
||||
const std::string pointerValue = s.str();
|
||||
BOOST_CHECK_NE( "?", to_string( &i ) );
|
||||
BOOST_CHECK_EQUAL( boost::lexical_cast< std::string >( &i ), to_string( &i ) );
|
||||
BOOST_CHECK_EQUAL( pointerValue, to_string( &i ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -630,7 +635,7 @@ BOOST_AUTO_TEST_CASE( mock_detail_template_template_streamable_yields_its_value_
|
|||
|
||||
BOOST_AUTO_TEST_CASE( unsigned_char_is_serialized_as_int )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( boost::lexical_cast< std::string >( static_cast< int >( 'a' ) ), to_string< unsigned char >( 'a' ) );
|
||||
BOOST_CHECK_EQUAL( std::to_string( static_cast< int >( 'a' ) ), to_string< unsigned char >( 'a' ) );
|
||||
}
|
||||
|
||||
namespace
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
#include "mock_error.hpp"
|
||||
#include <turtle/mock.hpp>
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <functional>
|
||||
|
||||
namespace
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue