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
30BOOST_AUTO_TEST_SUITE( pipe_tests );
31
32namespace bp = boost::process;
33
34BOOST_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&: is, str&: s);
70
71 std::string cmp = "hello dear boost-user!";
72
73 s.resize(n: cmp.size());
74
75 BOOST_CHECK_EQUAL_COLLECTIONS(s.cbegin(), s.cend(),cmp.cbegin(), cmp.cend());
76
77
78}
79
80BOOST_AUTO_TEST_SUITE_END();

source code of boost/libs/process/test/pipe_fwd.cpp