mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Initial import
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@2 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
8081e7006f
commit
8e18676b92
31 changed files with 4062 additions and 0 deletions
79
src/tests/turtle_test/format_test.cpp
Normal file
79
src/tests/turtle_test/format_test.cpp
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
|
||||
#include <turtle/format.hpp>
|
||||
#include <ostream>
|
||||
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
#define BOOST_LIB_NAME boost_unit_test_framework
|
||||
#include <boost/config/auto_link.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
struct non_serializable_type {};
|
||||
|
||||
struct serializable_type {};
|
||||
std::ostream& operator<<( std::ostream& s, const serializable_type& )
|
||||
{
|
||||
return s << "serializable_type";
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( type_not_serializable_in_standard_stream_yields_an_interrogation_mark_when_serialized )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "?", mock::detail::format( non_serializable_type() ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( base_type_serializable_in_standard_stream_yields_its_value_when_serialized )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "42", mock::detail::format( 42 ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( custom_type_serializable_in_standard_stream_yields_its_value_when_serialized )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "serializable_type", mock::detail::format( serializable_type() ) );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
struct convertible_to_int
|
||||
{
|
||||
operator int() const { return 0; }
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( custom_type_convertible_to_base_type_yields_its_value_when_serialized )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "0", mock::detail::format( convertible_to_int() ) );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
struct serializable
|
||||
{
|
||||
friend std::ostream& operator<<( std::ostream& s, const serializable& )
|
||||
{
|
||||
return s << "serializable";
|
||||
}
|
||||
};
|
||||
struct convertible_to_serializable
|
||||
{
|
||||
operator serializable() const { return serializable(); }
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( custom_type_convertible_to_another_type_serializable_in_standard_stream_yields_its_value_when_serialized )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "serializable", mock::detail::format( convertible_to_serializable() ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( booleans_are_serialized_as_booleans )
|
||||
{
|
||||
BOOST_CHECK_EQUAL( "true", mock::detail::format( true ) );
|
||||
BOOST_CHECK_EQUAL( "false", mock::detail::format( false ) );
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue