1 // Boost.Range library 2 // 3 // Copyright Neil Groves 2010. Use, modification and 4 // distribution is subject to the Boost Software License, Version 5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6 // http://www.boost.org/LICENSE_1_0.txt) 7 // 8 // 9 // For more information, see http://www.boost.org/libs/range/ 10 // 11 #include <boost/range/istream_range.hpp> 12 #include <boost/range/algorithm_ext.hpp> 13 #include <boost/range/begin.hpp> 14 #include <boost/range/end.hpp> 15 #include <boost/test/test_tools.hpp> 16 #include <boost/test/unit_test.hpp> 17 #include <sstream> 18 #include <vector> 19 20 namespace 21 { 22 template <typename CharT> test_istream_range_impl()23 void test_istream_range_impl() 24 { 25 std::basic_stringstream<CharT> s; 26 std::vector<int> reference; 27 for (int i = 0; i < 10; ++i) 28 { 29 reference.push_back(i); 30 s << i << CharT(' '); 31 } 32 33 std::vector<int> target; 34 boost::push_back(target, boost::range::istream_range<int>(s)); 35 36 BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), 37 target.begin(), target.end() ); 38 } 39 40 // Test an istream range. test_istream_range()41 void test_istream_range() 42 { 43 test_istream_range_impl<char>(); 44 test_istream_range_impl<wchar_t>(); 45 } 46 47 } // namespace anonymous namespace 48 49 boost::unit_test::test_suite* init_unit_test_suite(int argc,char * argv[])50init_unit_test_suite(int argc, char* argv[]) 51 { 52 boost::unit_test::test_suite* test 53 = BOOST_TEST_SUITE( "RangeTestSuite.istream_range" ); 54 55 test->add(BOOST_TEST_CASE( &test_istream_range )); 56 57 return test; 58 } 59