Imported Upstream version 1.64.0
[platform/upstream/boost.git] / libs / process / test / system_test2.cpp
1 // Copyright (c) 2006, 2007 Julio M. Merino Vidal\r
2 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling\r
3 // Copyright (c) 2009 Boris Schaeling\r
4 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling\r
5 // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling\r
6 //\r
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying\r
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)\r
9
10 #define BOOST_TEST_MAIN\r
11 #define BOOST_TEST_IGNORE_SIGCHLD\r
12 #include <boost/test/included/unit_test.hpp>\r
13
14 #include <boost/system/error_code.hpp>\r
15
16 #include <iostream>\r
17
18 #include <boost/asio.hpp>\r
19 #include <boost/chrono.hpp>\r
20 #include <boost/algorithm/string/predicate.hpp>\r
21 #include <boost/asio/steady_timer.hpp>\r
22 #include <boost/asio/deadline_timer.hpp>\r
23
24 #include <boost/process/error.hpp>\r
25 #include <boost/process/io.hpp>\r
26 #include <boost/process/args.hpp>\r
27 #include <boost/process/system.hpp>\r
28 #include <boost/process/async_pipe.hpp>\r
29 #include <boost/process/async.hpp>\r
30 #include <system_error>\r
31
32 #include <boost/filesystem.hpp>\r
33
34 #include <atomic>\r
35 #include <string>\r
36 #include <chrono>\r
37 #include <istream>\r
38 #include <cstdlib>\r
39
40 namespace fs = boost::filesystem;\r
41 namespace bp = boost::process;\r
42
43 BOOST_AUTO_TEST_CASE(explicit_async_io, *boost::unit_test::timeout(2))\r
44 {\r
45     using boost::unit_test::framework::master_test_suite;\r
46
47     boost::asio::io_service ios;\r
48
49     std::future<std::string> fut;\r
50
51     std::error_code ec;\r
52     bp::system(\r
53         master_test_suite().argv[1],\r
54         "test", "--echo-stdout", "abc",\r
55         bp::std_out > fut,\r
56         ios,\r
57         ec\r
58     );\r
59     BOOST_REQUIRE(!ec);\r
60
61     BOOST_REQUIRE(fut.valid());\r
62     BOOST_REQUIRE(boost::starts_with(fut.get(), "abc"));\r
63 }\r
64
65 BOOST_AUTO_TEST_CASE(explicit_async_io_running, *boost::unit_test::timeout(10))\r
66 {\r
67     using boost::unit_test::framework::master_test_suite;\r
68
69     boost::asio::io_service ios;\r
70     std::future<std::string> fut;\r
71     std::error_code ec;\r
72
73     ios.post([&]\r
74               {\r
75                 bp::system(\r
76                     master_test_suite().argv[1],\r
77                     "test", "--echo-stdout", "abc",\r
78                     bp::std_out > fut,\r
79                     ios,\r
80                     ec\r
81                 );\r
82                 BOOST_REQUIRE(!ec);\r
83               });\r
84
85
86     ios.run();\r
87
88     BOOST_REQUIRE(fut.valid());\r
89     BOOST_REQUIRE(boost::starts_with(\r
90             fut.get(), "abc"));\r
91
92
93 }\r