• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <system_error>
14 
15 #include <boost/asio.hpp>
16 #include <boost/algorithm/string/predicate.hpp>
17 
18 #include <boost/process/args.hpp>
19 #include <boost/process/exe.hpp>
20 #include <boost/process/error.hpp>
21 #include <boost/process/io.hpp>
22 #include <boost/process/child.hpp>
23 
24 
25 #include <string>
26 #include <istream>
27 #include <iostream>
28 #include <cstdlib>
29 
30 BOOST_AUTO_TEST_SUITE( pipe_tests );
31 
32 namespace bp = boost::process;
33 
34 BOOST_AUTO_TEST_CASE(sync_io, *boost::unit_test::timeout(5))
35 {
36     using boost::unit_test::framework::master_test_suite;
37 
38 
39     bp::ipstream is;
40     bp::opstream os;
41 
42     bp::pipe p;
43 
44     std::error_code ec;
45     bp::child c1(
46         master_test_suite().argv[1],
47         bp::args={"test", "--prefix-once", "dear "},
48         bp::std_in<os,
49         bp::std_out>p,
50         ec
51     );
52     BOOST_REQUIRE(!ec);
53 
54     BOOST_TEST_INFO("Launching child 2");
55 
56     bp::child c2(
57         master_test_suite().argv[1],
58         bp::args={"test", "--prefix-once", "hello "},
59         bp::std_in<p,
60         bp::std_out>is,
61         ec
62     );
63     BOOST_REQUIRE(!ec);
64 
65     os << "boost-user!" << std::endl;
66 
67 
68     std::string s;
69     std::getline(is, s);
70 
71     std::string cmp = "hello dear boost-user!";
72 
73     s.resize(cmp.size());
74 
75     BOOST_CHECK_EQUAL_COLLECTIONS(s.cbegin(), s.cend(),cmp.cbegin(), cmp.cend());
76 
77 
78 }
79 
80 BOOST_AUTO_TEST_SUITE_END();