Ticket #6722: trunk.libs.iostreams.test.patch

File trunk.libs.iostreams.test.patch, 2.7 KB (added by jeffrey.hellrung, 10 years ago)
  • filtering_stream_test.cpp

     
    2424#include "seek_test.hpp"
    2525#include "putback_test.hpp"
    2626#include "filtering_stream_flush_test.hpp"
     27#include "range_filter_test.hpp"
    2728
    2829using boost::unit_test::test_suite;
    2930
     
    4849    test->add(BOOST_TEST_CASE(&seek_test));
    4950    test->add(BOOST_TEST_CASE(&putback_test));
    5051    test->add(BOOST_TEST_CASE(&test_filtering_ostream_flush));
     52    test->add(BOOST_TEST_CASE(&range_filter_test));
    5153    return test;
    5254}
  • range_filter_test.hpp

     
     1// (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
     2// (C) Copyright 2004-2007 Jonathan Turkanis
     3// Distributed under the Boost Software License, Version 1.0. (See accompanying
     4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
     5
     6// See http://www.boost.org/libs/iostreams for documentation.
     7
     8#ifndef BOOST_IOSTREAMS_TEST_RANGE_FILTER_HPP_INCLUDED
     9#define BOOST_IOSTREAMS_TEST_RANGE_FILTER_HPP_INCLUDED
     10
     11#include <sstream>
     12#include <string>
     13
     14#include <boost/iostreams/filtering_stream.hpp>
     15#include <boost/range/iterator_range.hpp>
     16#include <boost/test/test_tools.hpp>
     17
     18namespace
     19{
     20    template <class Stream>
     21    std::string read_to_string(Stream& stream)
     22    {
     23       std::ostringstream destStream;
     24       destStream << stream.rdbuf();
     25       return destStream.str();
     26    }
     27} // namespace
     28
     29void range_filter_test()
     30{
     31   std::istringstream sourceStream("123");
     32
     33   typedef std::istream_iterator<char> iterator;
     34   iterator begin(sourceStream);
     35   iterator end;
     36   boost::iterator_range< iterator > range(begin, end);
     37
     38   boost::iostreams::filtering_stream<boost::iostreams::input> sourceFilteringStream;
     39   sourceFilteringStream.push(range, 1);
     40
     41   std::string output = read_to_string(sourceFilteringStream);
     42   BOOST_CHECK_EQUAL("123", output);
     43}
     44
     45#endif // #ifndef BOOST_IOSTREAMS_TEST_RANGE_FILTER_HPP_INCLUDED
  • range_filter_test.hpp