From d5a5b84a408d1e4e303b48735612f5dba16f3aec Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Wed, 21 Jul 2004 12:28:18 +0000 Subject: [PATCH] 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] --- iterators_test.cpp | 47 +++++++++++++++------------------------------- 1 file changed, 15 insertions(+), 32 deletions(-) diff --git a/iterators_test.cpp b/iterators_test.cpp index b316e79..458a487 100644 --- a/iterators_test.cpp +++ b/iterators_test.cpp @@ -24,7 +24,7 @@ #include // for std::strcmp #include // for std::cout (std::endl, ends, and flush indirectly) #include // for std::string -#include // for std::ostrstream +#include // 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 @@ -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 test_opr::iter_type const test_opr::fruit_begin = test_iter( fruit ); @@ -176,15 +169,13 @@ test_opr::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::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::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::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::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::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::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::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 "); }