]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/process/test/async_fut.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / process / test / async_fut.cpp
1 // Copyright (c) 2006, 2007 Julio M. Merino Vidal
2 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
3 // Copyright (c) 2009 Boris Schaeling
4 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
5 // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9
10 #define BOOST_TEST_MAIN
11 #define BOOST_TEST_IGNORE_SIGCHLD
12 #include <boost/test/included/unit_test.hpp>
13
14 #include <boost/process/error.hpp>
15 #include <boost/process/async.hpp>
16 #include <boost/process/io.hpp>
17 #include <boost/process/spawn.hpp>
18 #include <boost/process/child.hpp>
19
20 #include <boost/thread.hpp>
21 #include <future>
22
23 #include <boost/system/error_code.hpp>
24
25 #include <boost/algorithm/string/predicate.hpp>
26
27
28 using namespace std;
29
30 namespace bp = boost::process;
31
32 BOOST_AUTO_TEST_CASE(async_out_future, *boost::unit_test::timeout(2))
33 {
34
35 using boost::unit_test::framework::master_test_suite;
36
37 boost::asio::io_context io_context;
38
39
40 std::error_code ec;
41
42 std::future<std::string> fut;
43 std::future<void> fut_in;
44 boost::asio::streambuf in_buf;
45
46
47 std::ostream ostr(&in_buf);
48 ostr << "-string" << endl ;
49
50 bp::spawn(
51 master_test_suite().argv[1],
52 "test", "--prefix-once", "test",
53 bp::std_in < in_buf > fut_in,
54 bp::std_out > fut,
55 io_context,
56 ec
57 );
58 BOOST_REQUIRE(!ec);
59
60
61 io_context.run();
62
63 BOOST_REQUIRE(fut.valid());
64 BOOST_REQUIRE(fut_in.valid());
65 BOOST_CHECK_NO_THROW(fut_in.get());
66
67 std::string line;
68
69 BOOST_CHECK_NO_THROW(line = fut.get());
70
71 std::string val = "test-string";
72 BOOST_REQUIRE_GE(line.size(), val.size());
73 if (line >= val)
74 BOOST_CHECK(boost::algorithm::starts_with(line, val));
75 }
76
77
78 BOOST_AUTO_TEST_CASE(emtpy_out, *boost::unit_test::timeout(2))
79 {
80 using boost::unit_test::framework::master_test_suite;
81
82 boost::asio::io_context io_context;
83
84
85 std::error_code ec;
86 std::future<std::string> fut;
87
88 bp::spawn(
89 master_test_suite().argv[1],
90 "test", "--exit-code", "0",
91 bp::std_out > fut,
92 io_context,
93 ec
94 );
95 BOOST_REQUIRE(!ec);
96
97
98 io_context.run();
99
100 BOOST_REQUIRE(fut.valid());
101 BOOST_CHECK_EQUAL(fut.get(), "");
102 }
103