pipe_fwd.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #define BOOST_TEST_MAIN
  10. #define BOOST_TEST_IGNORE_SIGCHLD
  11. #include <boost/test/included/unit_test.hpp>
  12. #include <system_error>
  13. #include <boost/asio.hpp>
  14. #include <boost/algorithm/string/predicate.hpp>
  15. #include <boost/process/args.hpp>
  16. #include <boost/process/exe.hpp>
  17. #include <boost/process/error.hpp>
  18. #include <boost/process/io.hpp>
  19. #include <boost/process/child.hpp>
  20. #include <string>
  21. #include <istream>
  22. #include <iostream>
  23. #include <cstdlib>
  24. BOOST_AUTO_TEST_SUITE( pipe_tests );
  25. namespace bp = boost::process;
  26. BOOST_AUTO_TEST_CASE(sync_io, *boost::unit_test::timeout(5))
  27. {
  28. using boost::unit_test::framework::master_test_suite;
  29. bp::ipstream is;
  30. bp::opstream os;
  31. bp::pipe p;
  32. std::error_code ec;
  33. bp::child c1(
  34. master_test_suite().argv[1],
  35. bp::args={"test", "--prefix-once", "dear "},
  36. bp::std_in<os,
  37. bp::std_out>p,
  38. ec
  39. );
  40. BOOST_REQUIRE(!ec);
  41. BOOST_TEST_INFO("Launching child 2");
  42. bp::child c2(
  43. master_test_suite().argv[1],
  44. bp::args={"test", "--prefix-once", "hello "},
  45. bp::std_in<p,
  46. bp::std_out>is,
  47. ec
  48. );
  49. BOOST_REQUIRE(!ec);
  50. os << "boost-user!" << std::endl;
  51. std::string s;
  52. std::getline(is, s);
  53. std::string cmp = "hello dear boost-user!";
  54. s.resize(cmp.size());
  55. BOOST_CHECK_EQUAL_COLLECTIONS(s.cbegin(), s.cend(),cmp.cbegin(), cmp.cend());
  56. }
  57. BOOST_AUTO_TEST_SUITE_END();