]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/iostreams/test/copy_test.cpp
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 #include <algorithm> // Equal
10 #include <boost/config.hpp> // MSVC.
11 #include <boost/detail/workaround.hpp>
12 #include <boost/iostreams/concepts.hpp> // sink
13 #include <boost/iostreams/copy.hpp>
14 #include <boost/iostreams/device/array.hpp>
15 #include <boost/iostreams/device/file.hpp>
16 #include <boost/iostreams/stream.hpp>
17 #include <boost/test/test_tools.hpp>
18 #include <boost/test/unit_test.hpp>
19 #include "../example/container_device.hpp"
20 #include "detail/sequence.hpp"
23 using namespace boost
;
24 using namespace boost::iostreams
;
25 using namespace boost::iostreams::example
;
26 using namespace boost::iostreams::test
;
27 using boost::unit_test::test_suite
;
29 //------------------Definition of fixed_sink----------------------------------//
31 /*class fixed_sink : public sink {
33 fixed_sink(vector<char>& storage)
34 : storage_(storage), pos_(0)
36 std::streamsize write(const char_type* s, std::streamsize n)
38 streamsize capacity = static_cast<streamsize>(storage_.size() - pos_);
39 streamsize result = (min)(n, capacity);
40 std::copy(s, s + result, storage_.begin() + pos_);
45 fixed_sink operator=(const fixed_sink&);
46 typedef vector<char>::size_type size_type;
47 vector<char>& storage_;
51 //------------------Definition of stream types--------------------------------//
53 typedef container_source
< vector
<char> > vector_source
;
54 typedef container_sink
< vector
<char> > vector_sink
;
55 typedef stream
<vector_source
> vector_istream
;
56 typedef stream
<vector_sink
> vector_ostream
;
57 //typedef stream<fixed_sink> fixed_ostream;
59 //------------------Definition of copy_test-----------------------------------//
68 vector_ostream second
;
69 first
.open(vector_source(src
));
70 second
.open(vector_sink(dest
));
72 boost::iostreams::copy(first
, second
) ==
73 static_cast<streamsize
>(src
.size()) &&
75 "failed copying from stream to stream"
79 // Stream to indirect sink
84 vector_sink
out(dest
);
85 in
.open(vector_source(src
));
87 boost::iostreams::copy(in
, out
) ==
88 static_cast<streamsize
>(src
.size()) &&
90 "failed copying from stream to indirect sink"
94 // Indirect source to stream
98 vector_source
in(src
);
100 out
.open(vector_sink(dest
));
102 boost::iostreams::copy(in
, out
) ==
103 static_cast<streamsize
>(src
.size()) &&
105 "failed copying from indirect source to stream"
109 // Indirect source to indirect sink
113 vector_source
in(src
);
114 vector_sink
out(dest
);
116 boost::iostreams::copy(in
, out
) ==
117 static_cast<streamsize
>(src
.size()) &&
119 "failed copying from indirect source to indirect sink"
123 // Direct source to direct sink
126 vector
<char> dest(src
.size(), '?');
127 array_source
in(&src
[0], &src
[0] + src
.size());
128 array_sink
out(&dest
[0], &dest
[0] + dest
.size());
130 boost::iostreams::copy(in
, out
) ==
131 static_cast<streamsize
>(src
.size()) &&
133 "failed copying from direct source to direct sink"
137 // Direct source to indirect sink
141 array_source
in(&src
[0], &src
[0] + src
.size());
142 vector_ostream
out(dest
);
144 boost::iostreams::copy(in
, out
) ==
145 static_cast<streamsize
>(src
.size()) &&
147 "failed copying from direct source to indirect sink"
151 // Indirect source to direct sink
154 vector
<char> dest(src
.size(), '?');
156 array_sink
out(&dest
[0], &dest
[0] + dest
.size());
157 in
.open(vector_source(src
));
159 boost::iostreams::copy(in
, out
) ==
160 static_cast<streamsize
>(src
.size()) &&
162 "failed copying from indirect source to direct sink"
167 test_suite
* init_unit_test_suite(int, char* [])
169 test_suite
* test
= BOOST_TEST_SUITE("copy test");
170 test
->add(BOOST_TEST_CASE(©_test
));