system_test2.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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/system/error_code.hpp>
  13. #include <iostream>
  14. #include <boost/asio.hpp>
  15. #include <boost/chrono.hpp>
  16. #include <boost/algorithm/string/predicate.hpp>
  17. #include <boost/asio/steady_timer.hpp>
  18. #include <boost/asio/deadline_timer.hpp>
  19. #include <boost/process/error.hpp>
  20. #include <boost/process/io.hpp>
  21. #include <boost/process/args.hpp>
  22. #include <boost/process/system.hpp>
  23. #include <boost/process/async_pipe.hpp>
  24. #include <boost/process/async.hpp>
  25. #include <system_error>
  26. #include <boost/filesystem.hpp>
  27. #include <atomic>
  28. #include <string>
  29. #include <chrono>
  30. #include <istream>
  31. #include <cstdlib>
  32. namespace fs = boost::filesystem;
  33. namespace bp = boost::process;
  34. BOOST_AUTO_TEST_CASE(explicit_async_io, *boost::unit_test::timeout(2))
  35. {
  36. using boost::unit_test::framework::master_test_suite;
  37. boost::asio::io_context ios;
  38. std::future<std::string> fut;
  39. std::error_code ec;
  40. bp::system(
  41. master_test_suite().argv[1],
  42. "test", "--echo-stdout", "abc",
  43. bp::std_out > fut,
  44. ios,
  45. ec
  46. );
  47. BOOST_REQUIRE(!ec);
  48. BOOST_REQUIRE(fut.valid());
  49. BOOST_REQUIRE(boost::starts_with(fut.get(), "abc"));
  50. }
  51. BOOST_AUTO_TEST_CASE(explicit_async_io_running, *boost::unit_test::timeout(10))
  52. {
  53. using boost::unit_test::framework::master_test_suite;
  54. boost::asio::io_context ios;
  55. std::future<std::string> fut;
  56. std::error_code ec;
  57. boost::asio::post(
  58. ios.get_executor(),
  59. [&] {
  60. bp::system(
  61. master_test_suite().argv[1],
  62. "test", "--echo-stdout", "abc",
  63. bp::std_out > fut,
  64. ios,
  65. ec
  66. );
  67. BOOST_REQUIRE(!ec);
  68. }
  69. );
  70. ios.run();
  71. BOOST_REQUIRE(fut.valid());
  72. BOOST_REQUIRE(boost::starts_with(
  73. fut.get(), "abc"));
  74. }