]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/process/test/extensions.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / process / test / extensions.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 #include <boost/process/error.hpp>
14 #include <system_error>
15 #include <boost/bind.hpp>
16 #include <boost/ref.hpp>
17 #include <boost/process/child.hpp>
18 #include <boost/process/extend.hpp>
19
20
21 namespace bp = boost::process;
22
23
24 struct run_exe
25 {
26 std::string exe;
27 template<typename T>
28 void operator()(T &e) const
29 {
30 e.exe = exe.c_str();
31 }
32
33 };
34
35 struct set_on_error
36 {
37 mutable std::error_code ec;
38 template<typename T>
39 void operator()(T &, const std::error_code & ec) const
40 {
41 this->ec = ec;
42 }
43 };
44
45 BOOST_AUTO_TEST_CASE(extensions)
46 {
47 using boost::unit_test::framework::master_test_suite;
48
49 run_exe re;
50
51 re.exe = master_test_suite().argv[1];
52
53 set_on_error se;
54 std::error_code ec;
55 bp::child c(
56 "Wrong-Command",
57 "test",
58 bp::extend::on_setup=re,
59 bp::extend::on_error=se,
60 bp::ignore_error
61 );
62 BOOST_CHECK(!se.ec);
63 }
64
65
66 namespace ex = boost::process::extend;
67
68
69 std::string st = "not called";
70
71 struct overload_handler : ex::handler
72 {
73 template <class Char, class Sequence>
74 void on_setup(ex::windows_executor<Char, Sequence>& exec) const
75 {
76 st = "windows";
77 const char* env = exec.env;
78 }
79 template <class Sequence>
80 void on_setup(ex::posix_executor<Sequence>& exec) const
81 {
82 st = "posix";
83 char** env = exec.env;
84 }
85 };
86
87 BOOST_AUTO_TEST_CASE(overload)
88 {
89 bp::child c(
90 overload_handler(),
91 bp::ignore_error
92 );
93 #if defined(BOOST_WINDOWS_API)
94 BOOST_CHECK_EQUAL(st, "windows");
95 #else
96 BOOST_CHECK_EQUAL(st, "posix");
97 #endif
98 }
99
100
101