Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64747 - in sandbox/SOC/2010/process: boost/process libs/process/test libs/process/test/util
From: boris_at_[hidden]
Date: 2010-08-11 19:01:42


Author: bschaeling
Date: 2010-08-11 19:01:41 EDT (Wed, 11 Aug 2010)
New Revision: 64747
URL: http://svn.boost.org/trac/boost/changeset/64747

Log:
Fixed test case for asynchronous read/write operations
Text files modified:
   sandbox/SOC/2010/process/boost/process/stream_behavior.hpp | 6 ++++++
   sandbox/SOC/2010/process/libs/process/test/child.cpp | 12 ++++++------
   sandbox/SOC/2010/process/libs/process/test/util/helpers.cpp | 9 +++++++++
   3 files changed, 21 insertions(+), 6 deletions(-)

Modified: sandbox/SOC/2010/process/boost/process/stream_behavior.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/stream_behavior.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/stream_behavior.hpp 2010-08-11 19:01:41 EDT (Wed, 11 Aug 2010)
@@ -213,6 +213,12 @@
         child_end_ = open(s.c_str(), O_RDONLY | O_NONBLOCK);
         if (!child_end_.valid())
             BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("open(2) failed");
+ int opts = fcntl(child_end_.native(), F_GETFL);
+ if (opts == -1)
+ BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("fcntl(2) failed");
+ opts ^= O_NONBLOCK;
+ if (fcntl(child_end_.native(), F_SETFL, opts) == -1)
+ BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("fcntl(2) failed");
         parent_end_ = open(s.c_str(), O_WRONLY);
         if (!parent_end_.valid())
             BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("open(2) failed");

Modified: sandbox/SOC/2010/process/libs/process/test/child.cpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/test/child.cpp (original)
+++ sandbox/SOC/2010/process/libs/process/test/child.cpp 2010-08-11 19:01:41 EDT (Wed, 11 Aug 2010)
@@ -442,7 +442,7 @@
     std::size_t bytes_transferred)
 {
     BOOST_REQUIRE_EQUAL(ec, boost::system::error_code());
- BOOST_CHECK_EQUAL(bytes_transferred, 4u);
+ BOOST_CHECK_EQUAL(bytes_transferred, 5u);
 }
 
 void read_handler(const boost::system::error_code &ec,
@@ -453,17 +453,17 @@
     std::string line;
     std::getline(is, line);
 #if defined(BOOST_POSIX_API)
- BOOST_CHECK_EQUAL(line, "test");
+ BOOST_CHECK_EQUAL(line, "async-test");
 #elif defined(BOOST_WINDOWS_API)
- BOOST_CHECK_EQUAL(line, "test\r");
+ BOOST_CHECK_EQUAL(line, "async-test\r");
 #endif
 }
 
 BOOST_AUTO_TEST_CASE(test_async)
 {
     std::vector<std::string> args;
- args.push_back("echo-stdout");
- args.push_back("test");
+ args.push_back("prefix-once");
+ args.push_back("async-");
 
     bp::context ctx;
     ctx.stdin_behavior = bp::behavior::named_pipe::create(
@@ -479,7 +479,7 @@
     bp::pipe write_end(ioservice, os.handle().release());
     bp::pipe read_end(ioservice, is.handle().release());
 
- ba::async_write(write_end, ba::buffer("test", 4), write_handler);
+ ba::async_write(write_end, ba::buffer("test\n", 5), write_handler);
     ba::streambuf buf;
     ba::async_read_until(read_end, buf, '\n', boost::bind(read_handler,
         ba::placeholders::error, ba::placeholders::bytes_transferred,

Modified: sandbox/SOC/2010/process/libs/process/test/util/helpers.cpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/test/util/helpers.cpp (original)
+++ sandbox/SOC/2010/process/libs/process/test/util/helpers.cpp 2010-08-11 19:01:41 EDT (Wed, 11 Aug 2010)
@@ -135,6 +135,14 @@
     return EXIT_SUCCESS;
 }
 
+int h_prefix_once(int argc, char *argv[])
+{
+ std::string line;
+ std::getline(std::cin, line);
+ std::cout << argv[1] << line << std::endl;
+ return EXIT_SUCCESS;
+}
+
 int h_pwd(int argc, char *argv[])
 {
     std::cout << bfs::current_path().string() << std::endl;
@@ -243,6 +251,7 @@
     { "is-nul-stderr", h_is_nul_stderr, 1, "" },
     { "loop", h_loop, 1, "" },
     { "prefix", h_prefix, 2, "string" },
+ { "prefix-once", h_prefix_once, 2, "string" },
     { "pwd", h_pwd, 1, "" },
     { "query-env", h_query_env, 2, "variable" },
     { "stdin-to-stdout", h_stdin_to_stdout, 1, "" },


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk