mirror of
https://github.com/boostorg/utility.git
synced 2025-05-09 15:04:00 +00:00
Switch the test to use std::stringstream, not std::ostrstream, since
the latter is deprecated and gcc warns whenever one tries to use it. [SVN r23896]
This commit is contained in:
parent
35d3c03d19
commit
d5a5b84a40
@ -24,7 +24,7 @@
|
||||
#include <cstring> // for std::strcmp
|
||||
#include <iostream> // for std::cout (std::endl, ends, and flush indirectly)
|
||||
#include <string> // for std::string
|
||||
#include <strstream> // for std::ostrstream
|
||||
#include <sstream> // for std::stringstream
|
||||
|
||||
# ifdef BOOST_NO_STDC_NAMESPACE
|
||||
namespace std { using ::strcmp; }
|
||||
@ -65,20 +65,16 @@ class test_opr_base
|
||||
protected:
|
||||
// Test data and types
|
||||
BOOST_STATIC_CONSTANT( std::size_t, fruit_length = 6u );
|
||||
BOOST_STATIC_CONSTANT( std::size_t, scratch_length = 40u );
|
||||
|
||||
typedef std::string fruit_array_type[ fruit_length ];
|
||||
typedef char scratch_array_type[ scratch_length ];
|
||||
|
||||
static fruit_array_type fruit;
|
||||
static scratch_array_type scratch;
|
||||
|
||||
}; // test_opr_base
|
||||
|
||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
// A definition is required even for integral static constants
|
||||
const std::size_t test_opr_base::fruit_length;
|
||||
const std::size_t test_opr_base::scratch_length;
|
||||
#endif
|
||||
|
||||
template <typename T, typename R = T&, typename P = T*>
|
||||
@ -120,9 +116,6 @@ private:
|
||||
test_opr_base::fruit_array_type
|
||||
test_opr_base::fruit = { "apple", "orange", "pear", "peach", "grape", "plum" };
|
||||
|
||||
test_opr_base::scratch_array_type
|
||||
test_opr_base::scratch = "";
|
||||
|
||||
template <typename T, typename R, typename P>
|
||||
typename test_opr<T, R, P>::iter_type const
|
||||
test_opr<T, R, P>::fruit_begin = test_iter<T,R,P>( fruit );
|
||||
@ -176,15 +169,13 @@ test_opr<T, R, P>::post_increment_test
|
||||
{
|
||||
std::cout << "\tDoing post-increment test." << std::endl;
|
||||
|
||||
std::ostrstream oss( scratch, scratch_length );
|
||||
std::stringstream oss;
|
||||
for ( iter_type i = fruit_begin ; i != fruit_end ; )
|
||||
{
|
||||
oss << *i++ << ' ';
|
||||
}
|
||||
|
||||
oss << std::ends;
|
||||
BOOST_TEST( std::strcmp(oss.str(), "apple orange pear peach grape plum ")
|
||||
== 0 );
|
||||
BOOST_TEST( oss.str() == "apple orange pear peach grape plum ");
|
||||
}
|
||||
|
||||
// Test post-decrement
|
||||
@ -196,16 +187,14 @@ test_opr<T, R, P>::post_decrement_test
|
||||
{
|
||||
std::cout << "\tDoing post-decrement test." << std::endl;
|
||||
|
||||
std::ostrstream oss( scratch, scratch_length );
|
||||
std::stringstream oss;
|
||||
for ( iter_type i = fruit_end ; i != fruit_begin ; )
|
||||
{
|
||||
i--;
|
||||
oss << *i << ' ';
|
||||
}
|
||||
|
||||
oss << std::ends;
|
||||
BOOST_TEST( std::strcmp(oss.str(), "plum grape peach pear orange apple ")
|
||||
== 0 );
|
||||
BOOST_TEST( oss.str() == "plum grape peach pear orange apple ");
|
||||
}
|
||||
|
||||
// Test indirect structure referral
|
||||
@ -217,14 +206,13 @@ test_opr<T, R, P>::indirect_referral_test
|
||||
{
|
||||
std::cout << "\tDoing indirect reference test." << std::endl;
|
||||
|
||||
std::ostrstream oss( scratch, scratch_length );
|
||||
std::stringstream oss;
|
||||
for ( iter_type i = fruit_begin ; i != fruit_end ; ++i )
|
||||
{
|
||||
oss << i->size() << ' ';
|
||||
}
|
||||
|
||||
oss << std::ends;
|
||||
BOOST_TEST( std::strcmp(oss.str(), "5 6 4 5 5 4 ") == 0 );
|
||||
BOOST_TEST( oss.str() == "5 6 4 5 5 4 ");
|
||||
}
|
||||
|
||||
// Test offset addition
|
||||
@ -237,14 +225,13 @@ test_opr<T, R, P>::offset_addition_test
|
||||
std::cout << "\tDoing offset addition test." << std::endl;
|
||||
|
||||
std::ptrdiff_t const two = 2;
|
||||
std::ostrstream oss( scratch, scratch_length );
|
||||
std::stringstream oss;
|
||||
for ( iter_type i = fruit_begin ; i != fruit_end ; i = i + two )
|
||||
{
|
||||
oss << *i << ' ';
|
||||
}
|
||||
|
||||
oss << std::ends;
|
||||
BOOST_TEST( std::strcmp(oss.str(), "apple pear grape ") == 0 );
|
||||
BOOST_TEST( oss.str() == "apple pear grape ");
|
||||
}
|
||||
|
||||
// Test offset addition, in reverse order
|
||||
@ -257,14 +244,13 @@ test_opr<T, R, P>::reverse_offset_addition_test
|
||||
std::cout << "\tDoing reverse offset addition test." << std::endl;
|
||||
|
||||
std::ptrdiff_t const two = 2;
|
||||
std::ostrstream oss( scratch, scratch_length );
|
||||
std::stringstream oss;
|
||||
for ( iter_type i = fruit_begin ; i != fruit_end ; i = two + i )
|
||||
{
|
||||
oss << *i << ' ';
|
||||
}
|
||||
|
||||
oss << std::ends;
|
||||
BOOST_TEST( std::strcmp(oss.str(), "apple pear grape ") == 0 );
|
||||
BOOST_TEST( oss.str() == "apple pear grape ");
|
||||
}
|
||||
|
||||
// Test offset subtraction
|
||||
@ -277,7 +263,7 @@ test_opr<T, R, P>::offset_subtraction_test
|
||||
std::cout << "\tDoing offset subtraction test." << std::endl;
|
||||
|
||||
std::ptrdiff_t const two = 2;
|
||||
std::ostrstream oss( scratch, scratch_length );
|
||||
std::stringstream oss;
|
||||
for ( iter_type i = fruit_end ; fruit_begin < i ; )
|
||||
{
|
||||
i = i - two;
|
||||
@ -287,8 +273,7 @@ test_opr<T, R, P>::offset_subtraction_test
|
||||
}
|
||||
}
|
||||
|
||||
oss << std::ends;
|
||||
BOOST_TEST( std::strcmp(oss.str(), "grape pear apple ") == 0 );
|
||||
BOOST_TEST( oss.str() == "grape pear apple ");
|
||||
}
|
||||
|
||||
// Test comparisons
|
||||
@ -330,13 +315,11 @@ test_opr<T, R, P>::indexing_test
|
||||
{
|
||||
std::cout << "\tDoing indexing test." << std::endl;
|
||||
|
||||
std::ostrstream oss( scratch, scratch_length );
|
||||
std::stringstream oss;
|
||||
for ( std::size_t k = 0u ; k < fruit_length ; ++k )
|
||||
{
|
||||
oss << fruit_begin[ k ] << ' ';
|
||||
}
|
||||
|
||||
oss << std::ends;
|
||||
BOOST_TEST( std::strcmp(oss.str(), "apple orange pear peach grape plum ")
|
||||
== 0 );
|
||||
BOOST_TEST( oss.str() == "apple orange pear peach grape plum ");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user