wargs_cmd.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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/exe.hpp>
  13. #include <boost/process/args.hpp>
  14. #include <boost/process/cmd.hpp>
  15. #include <boost/process/io.hpp>
  16. #include <boost/process/error.hpp>
  17. #include <boost/process/child.hpp>
  18. #include <boost/algorithm/string/predicate.hpp>
  19. namespace bp = boost::process;
  20. BOOST_AUTO_TEST_CASE(wargs, *boost::unit_test::timeout(2))
  21. {
  22. using boost::unit_test::framework::master_test_suite;
  23. bp::ipstream is;
  24. std::error_code ec;
  25. bp::child c(
  26. master_test_suite().argv[1],
  27. L"test", "--echo-argv", L"hello thingy", "\"stuff\"", static_cast<const wchar_t*>(L" spa ce "),
  28. bp::std_out>is,
  29. ec
  30. );
  31. if (ec)
  32. std::cout << "EC: " << ec.message() << std::endl;
  33. BOOST_REQUIRE(!ec);
  34. std::string s;
  35. std::getline(is, s);
  36. s.resize(4);
  37. BOOST_CHECK_EQUAL(s, "test");
  38. std::getline(is, s);
  39. s.resize(11);
  40. BOOST_CHECK_EQUAL(s, "--echo-argv");
  41. std::getline(is, s);
  42. s.resize(12);
  43. BOOST_CHECK_EQUAL(s, "hello thingy");
  44. std::getline(is, s);
  45. s.resize(7);
  46. BOOST_CHECK_EQUAL(s, "\"stuff\"");
  47. std::getline(is, s);
  48. s.resize(10);
  49. BOOST_CHECK_EQUAL(s, " spa ce ");
  50. }
  51. BOOST_AUTO_TEST_CASE(wcmd, *boost::unit_test::timeout(2))
  52. {
  53. using boost::unit_test::framework::master_test_suite;
  54. bp::ipstream is;
  55. std::error_code ec;
  56. std::wstring cmd =
  57. bp::detail::convert(master_test_suite().argv[1]);
  58. cmd+= L" test --echo-argv \"hello thingy\" \\\"stuff\\\" \" spa ce \"";
  59. bp::child c(cmd,
  60. bp::std_out>is,
  61. ec
  62. );
  63. BOOST_REQUIRE(!ec);
  64. std::string s;
  65. std::getline(is, s);
  66. s.resize(4);
  67. BOOST_CHECK_EQUAL(s, "test");
  68. std::getline(is, s);
  69. s.resize(11);
  70. BOOST_CHECK_EQUAL(s, "--echo-argv");
  71. std::getline(is, s);
  72. s.resize(12);
  73. BOOST_CHECK_EQUAL(s, "hello thingy");
  74. std::getline(is, s);
  75. s.resize(7);
  76. BOOST_CHECK_EQUAL(s, "\"stuff\"");
  77. std::getline(is, s);
  78. s.resize(10);
  79. BOOST_CHECK_EQUAL(s, " spa ce ");
  80. }