]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/process/test/pipe.cpp
1 // Copyright (c) 2016 Klemens D. Morgenstern
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)
7 #define BOOST_TEST_MAIN
9 #include <boost/test/included/unit_test.hpp>
13 #include <boost/process/pipe.hpp>
16 namespace bp
= boost::process
;
18 BOOST_AUTO_TEST_CASE(plain
, *boost::unit_test::timeout(2))
22 std::string in
= "test";
23 pipe
.write(in
.c_str(), in
.size());
27 pipe
.read(&out
.front(), out
.size());
29 BOOST_CHECK_EQUAL(out
, in
);
32 BOOST_AUTO_TEST_CASE(named
, *boost::unit_test::timeout(2))
35 #if defined( BOOST_WINDOWS_API )
36 bp::pipe
pipe("\\\\.\\pipe\\pipe_name");
37 #elif defined( BOOST_POSIX_API )
38 bp::pipe
pipe("./test_pipe");
41 std::string in
= "xyz";
42 pipe
.write(in
.c_str(), in
.size());
47 pipe
.read(&out
.front(), out
.size());
50 BOOST_CHECK_EQUAL(out
, in
);
53 BOOST_AUTO_TEST_CASE(copy_pipe
, *boost::unit_test::timeout(2))
57 std::string in
= "test";
58 pipe
.write(in
.c_str(), in
.size());
63 p2
.read(&out
.front(), out
.size());
65 BOOST_CHECK_EQUAL(out
, in
);
68 BOOST_AUTO_TEST_CASE(move_pipe
, *boost::unit_test::timeout(2))
72 std::string in
= "test";
73 pipe
.write(in
.c_str(), in
.size());
77 auto p2
= std::move(pipe
);
78 p2
.read(&out
.front(), out
.size());
80 BOOST_CHECK_EQUAL(out
, in
);
83 BOOST_AUTO_TEST_CASE(stream
, *boost::unit_test::timeout(2))
89 bp::ipstream
is(pipe
);
97 BOOST_CHECK_EQUAL(i
, j
);
100 BOOST_AUTO_TEST_CASE(stream_line
, *boost::unit_test::timeout(2))
105 std::string s
= "My Test String";
109 os
<< s
<< std::endl
;
111 std::getline(os
, out
);
113 auto size
= (out
.size() < s
.size()) ? out
.size() : s
.size();
116 BOOST_CHECK_EQUAL_COLLECTIONS(
117 s
.begin(), s
. begin() + size
,
118 out
.begin(), out
.begin() + size
123 BOOST_AUTO_TEST_CASE(large_data
, *boost::unit_test::timeout(20))
127 bp::pipebuf
is_buf(pipe
);
128 bp::pipebuf
os_buf(std::move(pipe
));
130 std::istream
is(&is_buf
);
131 std::ostream
os(&os_buf
);
133 std::string
in(1000000, '0');
138 c
= (cnt
++ % 26) + 'A';
140 std::thread
th([&]{os
<< in
<< std::endl
;});
143 BOOST_REQUIRE_EQUAL_COLLECTIONS(out
.begin(), out
.end(), in
.begin(), in
.end());
147 BOOST_AUTO_TEST_CASE(closed
, *boost::unit_test::timeout(2))
157 BOOST_CHECK(!(os
<< 42 << endl
));
158 BOOST_CHECK(!(is
>> i
));
162 BOOST_AUTO_TEST_CASE(coverage
, *boost::unit_test::timeout(5))
164 //more of a syntax check, since template.
167 bp::ipstream
is1(p1
);
168 bp::ipstream
is2(std::move(p1
));
170 is2
.pipe(is1
.pipe());
174 BOOST_REQUIRE_NO_THROW(p2_
== p2
);
175 BOOST_CHECK(p2_
== p2
);
177 bp::opstream
os1(p2
);
178 bp::opstream
os2(std::move(p2
));
180 os2
.pipe(os1
.pipe());
187 bp::pipe p4
= std::move(p4_
);
190 BOOST_REQUIRE_NO_THROW(p4_
!= p4
);
191 BOOST_CHECK(p4_
!= p4
);
193 BOOST_REQUIRE_NO_THROW(p5
!= p4
);
194 BOOST_CHECK(p4
!= p5
);
202 bp::wpstream
ws2(std::move(p
));
204 ws2
.pipe(std::move(ws1
.pipe()));
211 const bp::wpstream
& ws2c
= ws2
;
212 ws1
.pipe(ws2c
.pipe());
218 bp::wpipebuf
ws2(std::move(p
));
220 ws2
.pipe(std::move(ws1
.pipe()));
227 const bp::wpipebuf
& ws2c
= ws2
;
228 ws1
.pipe(ws2c
.pipe());