| | 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 | |
| | 18 | namespace |
| | 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 | |
| | 29 | void 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 |