istream_range.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. namespace
  20. {
  21. template <typename CharT>
  22. void test_istream_range_impl()
  23. {
  24. std::basic_stringstream<CharT> s;
  25. std::vector<int> reference;
  26. for (int i = 0; i < 10; ++i)
  27. {
  28. reference.push_back(i);
  29. s << i << CharT(' ');
  30. }
  31. std::vector<int> target;
  32. boost::push_back(target, boost::range::istream_range<int>(s));
  33. BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
  34. target.begin(), target.end() );
  35. }
  36. // Test an istream range.
  37. void test_istream_range()
  38. {
  39. test_istream_range_impl<char>();
  40. test_istream_range_impl<wchar_t>();
  41. }
  42. } // namespace anonymous namespace
  43. boost::unit_test::test_suite*
  44. init_unit_test_suite(int argc, char* argv[])
  45. {
  46. boost::unit_test::test_suite* test
  47. = BOOST_TEST_SUITE( "RangeTestSuite.istream_range" );
  48. test->add(BOOST_TEST_CASE( &test_istream_range ));
  49. return test;
  50. }