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.)
6 // See http://www.boost.org/libs/iostreams/ for documentation.
8 #ifndef BOOST_IOSTREAMS_TEST_PUTBACK_HPP_INCLUDED
9 #define BOOST_IOSTREAMS_TEST_PUTBACK_HPP_INCLUDED
11 #include <boost/iostreams/device/file.hpp>
12 #include <boost/iostreams/filtering_stream.hpp>
13 #include <boost/iostreams/putback.hpp>
14 #include "detail/constants.hpp"
15 #include "detail/temp_file.hpp"
17 using boost::iostreams::test::chunk_size;
19 bool putback_test_one(std::istream& is)
24 is.read(buf, chunk_size);
25 if (is.gcount() < static_cast<std::streamsize>(chunk_size))
32 } catch (std::exception&) { return false; }
35 bool putback_test_two(std::istream& is)
40 is.read(buf, chunk_size);
41 if (is.gcount() < static_cast<std::streamsize>(chunk_size))
47 if ( is.get() != 'd' || is.get() != 'c' ||
48 is.get() != 'b' || is.get() != 'a' )
54 } catch (std::exception&) { return false; }
57 template<typename Source>
58 bool putback_test_three(Source& src)
63 if (boost::iostreams::read(src, buf, chunk_size) < chunk_size)
65 boost::iostreams::putback(src, 'a');
66 if (boost::iostreams::get(src) != 'a')
70 } catch (std::exception&) { return false; }
73 template<typename Source>
74 bool putback_test_four(Source& src)
79 if (boost::iostreams::read(src, buf, chunk_size) < chunk_size)
81 boost::iostreams::putback(src, 'a');
82 boost::iostreams::putback(src, 'b');
83 boost::iostreams::putback(src, 'c');
84 boost::iostreams::putback(src, 'd');
85 if ( boost::iostreams::get(src) != 'd' ||
86 boost::iostreams::get(src) != 'c' ||
87 boost::iostreams::get(src) != 'b' ||
88 boost::iostreams::get(src) != 'a' )
94 } catch (std::exception&) { return false; }
100 using namespace boost;
101 using namespace boost::iostreams;
102 using namespace boost::iostreams::test;
107 filtering_istream is;
108 is.set_device_buffer_size(0);
109 is.push(file_source(test.name()));
111 putback_test_one(is),
112 "failed putting back to unbuffered filtering_istream"
117 filtering_istream is;
118 is.set_pback_size(4);
119 is.push(file_source(test.name()));
121 putback_test_two(is),
122 "failed putting back to buffered filtering_istream"
127 filtering_istream is;
128 is.set_device_buffer_size(0);
129 is.push(file_source(test.name()));
131 putback_test_three(is),
132 "failed putting back to unbuffered filtering_istream"
137 filtering_istream is;
138 is.set_pback_size(4);
139 is.push(file_source(test.name()));
141 putback_test_four(is),
142 "failed putting back to buffered filtering_istream"
147 filtering_istreambuf sb;
148 sb.set_device_buffer_size(0);
149 sb.push(file_source(test.name()));
151 putback_test_three(sb),
152 "failed putting back to unbuffered filtering_istream"
157 filtering_istreambuf sb;
158 sb.set_pback_size(4);
159 sb.push(file_source(test.name()));
161 putback_test_four(sb),
162 "failed putting back to buffered filtering_istream"
167 #endif // #ifndef BOOST_IOSTREAMS_TEST_PUTBACK_HPP_INCLUDED