bind_stdin_stdout.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 <boost/process/error.hpp>
  13. #include <boost/process/io.hpp>
  14. #include <boost/process/child.hpp>
  15. #include <boost/process/args.hpp>
  16. #include <system_error>
  17. #include <boost/system/error_code.hpp>
  18. #include <string>
  19. #include <iostream>
  20. namespace bp = boost::process;
  21. BOOST_AUTO_TEST_SUITE( bind_stdin_stdout );
  22. BOOST_AUTO_TEST_CASE(sync_io, *boost::unit_test::timeout(10))
  23. {
  24. using boost::unit_test::framework::master_test_suite;
  25. bp::opstream os;
  26. bp::ipstream is;
  27. std::error_code ec;
  28. bp::child c(
  29. master_test_suite().argv[1],
  30. bp::args+={"test", "--stdin-to-stdout"},
  31. bp::std_in<os,
  32. bp::std_out>is,
  33. ec
  34. );
  35. BOOST_REQUIRE(!ec);
  36. std::string s = "abcdefghi j";
  37. for (std::string::const_iterator it = s.begin(); it != s.end(); ++it)
  38. {
  39. os << *it << std::flush;
  40. char c;
  41. is >> std::noskipws >> c;
  42. BOOST_CHECK_EQUAL(*it, c);
  43. }
  44. os.pipe().close();
  45. BOOST_CHECK(c.wait_for(std::chrono::seconds(3)));
  46. }
  47. BOOST_AUTO_TEST_SUITE_END();