]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/process/test/system_test1.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / process / test / system_test1.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/system/error_code.hpp>
15
16 #include <iostream>
17
18 #include <boost/asio.hpp>
19 #include <boost/chrono.hpp>
20 #include <boost/algorithm/string/predicate.hpp>
21 #include <boost/asio/steady_timer.hpp>
22
23 #include <boost/process/error.hpp>
24 #include <boost/process/io.hpp>
25 #include <boost/process/args.hpp>
26 #include <boost/process/system.hpp>
27 #include <boost/process/async_pipe.hpp>
28 #include <boost/process/async.hpp>
29 #include <system_error>
30
31 #include <boost/filesystem.hpp>
32
33 #include <string>
34 #include <chrono>
35 #include <istream>
36 #include <cstdlib>
37 #if defined(BOOST_WINDOWS_API)
38 # include <windows.h>
39 typedef boost::asio::windows::stream_handle pipe_end;
40 #elif defined(BOOST_POSIX_API)
41 # include <sys/wait.h>
42 # include <unistd.h>
43 typedef boost::asio::posix::stream_descriptor pipe_end;
44 #endif
45
46 namespace fs = boost::filesystem;
47 namespace bp = boost::process;
48
49 BOOST_AUTO_TEST_CASE(exit_code, *boost::unit_test::timeout(5))
50 {
51 using boost::unit_test::framework::master_test_suite;
52
53 std::error_code ec;
54 //I need to spawn a thread for that to work
55
56 BOOST_CHECK_EQUAL(
57 bp::system(
58 master_test_suite().argv[1],
59 "test", "--exit-code", "123", ec), 123);
60
61 BOOST_CHECK(!ec);
62 }
63
64 BOOST_AUTO_TEST_CASE(implicit_async_io, *boost::unit_test::timeout(2))
65 {
66 using boost::unit_test::framework::master_test_suite;
67
68 std::future<std::string> fut;
69 std::error_code ec;
70 bp::system(
71 master_test_suite().argv[1],
72 "test", "--echo-stdout", "abc",
73 bp::std_out > fut,
74 ec
75 );
76 BOOST_REQUIRE(!ec);
77
78 BOOST_REQUIRE(fut.valid());
79 BOOST_CHECK(boost::starts_with(
80 fut.get(), "abc"));
81 }