Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64540 - in sandbox/SOC/2010/process/libs/process/test: . util
From: boris_at_[hidden]
Date: 2010-08-02 10:57:33


Author: bschaeling
Date: 2010-08-02 10:57:32 EDT (Mon, 02 Aug 2010)
New Revision: 64540
URL: http://svn.boost.org/trac/boost/changeset/64540

Log:
Fixed async child test
Removed:
   sandbox/SOC/2010/process/libs/process/test/helpers.cpp
Text files modified:
   sandbox/SOC/2010/process/libs/process/test/child.cpp | 73 ++++++++++++++++++++++-----------------
   sandbox/SOC/2010/process/libs/process/test/util/boost.hpp | 5 ++
   sandbox/SOC/2010/process/libs/process/test/util/helpers.cpp | 11 ------
   sandbox/SOC/2010/process/libs/process/test/wait.cpp | 3 -
   4 files changed, 45 insertions(+), 47 deletions(-)

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-02 10:57:32 EDT (Mon, 02 Aug 2010)
@@ -29,6 +29,7 @@
 #include <string>
 #include <vector>
 #include <utility>
+#include <istream>
 #include <cstdlib>
 
 BOOST_AUTO_TEST_CASE(test_close_stdin)
@@ -437,51 +438,59 @@
 #endif
 }
 
-void handler(const boost::system::error_code &ec, std::size_t bytes_transferred)
+void write_handler(const boost::system::error_code &ec,
+ std::size_t bytes_transferred)
 {
+ BOOST_REQUIRE_EQUAL(ec, boost::system::error_code());
+ BOOST_CHECK_EQUAL(bytes_transferred, 4);
 }
 
-ba::io_service ioservice;
-BOOST_AUTO_TEST_CASE(should_write_async)
-{
-
- std::vector<std::string> args;
- args.push_back("read-message");
- args.push_back("my_message");
-
- bp::context ctx;
- ctx.stdin_behavior = bp::behavior::named_pipe::create(bp::behavior::named_pipe::input_stream);
-
- bp::child c = bp::create_child(get_helpers_path(), args, ctx);
- bp::postream &os = c.get_stdin();
-
- bp::pipe write_end(ioservice, os.handle().release());
-
- write_end.async_write_some(ba::buffer("my_message\n"), handler);
- ioservice.run();
-
- //need to wait for value
-}
+void read_handler(const boost::system::error_code &ec,
+ std::size_t bytes_transferred, ba::streambuf &buf)
+{
+ BOOST_REQUIRE_EQUAL(ec, boost::system::error_code());
+ std::istream is(&buf);
+ std::string line;
+ std::getline(is, line);
+#if defined(BOOST_POSIX_API)
+ BOOST_CHECK_EQUAL(line, "test");
+#elif defined(BOOST_WINDOWS_API)
+ BOOST_CHECK_EQUAL(line, "test\r");
+#endif
+}
 
-BOOST_AUTO_TEST_CASE(should_write_async)
-{
+BOOST_AUTO_TEST_CASE(test_async)
+{
     std::vector<std::string> args;
     args.push_back("echo-stdout");
- args.push_back("my_message");
+ args.push_back("test");
 
     bp::context ctx;
- ctx.stdout_behavior = bp::behavior::named_pipe::create(bp::behavior::named_pipe::output_stream);
+ ctx.stdin_behavior = bp::behavior::named_pipe::create(
+ bp::behavior::named_pipe::input_stream);
+ ctx.stdout_behavior = bp::behavior::named_pipe::create(
+ bp::behavior::named_pipe::output_stream);
 
     bp::child c = bp::create_child(get_helpers_path(), args, ctx);
+ bp::postream &os = c.get_stdin();
     bp::pistream &is = c.get_stdout();
 
+ ba::io_service ioservice;
+ bp::pipe write_end(ioservice, os.handle().release());
     bp::pipe read_end(ioservice, is.handle().release());
 
- ba::buffer buff;
- read_end.async_read_some(buff, handler);
+ ba::async_write(write_end, ba::buffer("test", 4), write_handler);
+ ba::streambuf buf;
+ ba::async_read_until(read_end, buf, '\n', boost::bind(read_handler,
+ ba::placeholders::error, ba::placeholders::bytes_transferred,
+ boost::ref(buf)));
     ioservice.run();
 
- //need to wait for value
- BOOST_CHECK_EQUAL(buff, "my_message");
-
-}
+ int exit_code = c.wait();
+#if defined(BOOST_POSIX_API)
+ BOOST_REQUIRE(WIFEXITED(exit_code));
+ BOOST_CHECK_EQUAL(WEXITSTATUS(exit_code), EXIT_SUCCESS);
+#elif defined(BOOST_WINDOWS_API)
+ BOOST_CHECK_EQUAL(exit_code, EXIT_SUCCESS);
+#endif
+}

Deleted: sandbox/SOC/2010/process/libs/process/test/helpers.cpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/test/helpers.cpp 2010-08-02 10:57:32 EDT (Mon, 02 Aug 2010)
+++ (empty file)
@@ -1,270 +0,0 @@
-//
-// Boost.Process
-// ~~~~~~~~~~~~~
-//
-// Copyright (c) 2006, 2007 Julio M. Merino Vidal
-// Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
-// Copyright (c) 2009 Boris Schaeling
-// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
-//
-// Distributed under the Boost Software License, Version 1.0. (See accompanying
-// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-//
-
-#include <boost/process/config.hpp>
-
-#if defined(BOOST_POSIX_API)
-# include <stdlib.h>
-#elif defined(BOOST_WINDOWS_API)
-# include <windows.h>
-#else
-# error "Unsupported platform."
-#endif
-
-#include <boost/process/detail/systembuf.hpp>
-#include <boost/filesystem.hpp>
-#include <iostream>
-#include <string>
-#include <cstdlib>
-
-namespace bpd = boost::process::detail;
-namespace bfs = boost::filesystem;
-
-namespace {
-
-int h_echo_quoted(int argc, char *argv[])
-{
- std::cout << ">>>" << argv[1] << "<<<" << std::endl;
- return EXIT_SUCCESS;
-}
-
-int h_echo_stdout(int argc, char *argv[])
-{
- std::cout << argv[1] << std::endl;
- return EXIT_SUCCESS;
-}
-
-int h_echo_stderr(int argc, char *argv[])
-{
- std::cerr << argv[1] << std::endl;
- return EXIT_SUCCESS;
-}
-
-int h_echo_stdout_stderr(int argc, char *argv[])
-{
- std::cout << "stdout " << argv[1] << std::endl;
- std::cout.flush();
- std::cerr << "stderr " << argv[1] << std::endl;
- std::cerr.flush();
- return EXIT_SUCCESS;
-}
-
-int h_exit_failure(int argc, char *argv[])
-{
- return EXIT_FAILURE;
-}
-
-int h_exit_success(int argc, char *argv[])
-{
- return EXIT_SUCCESS;
-}
-
-int h_is_closed_stdin(int argc, char *argv[])
-{
- std::string word;
- std::cin >> word;
- return std::cin.eof() ? EXIT_SUCCESS : EXIT_FAILURE;
-}
-
-int h_is_closed_stdout(int argc, char *argv[])
-{
- std::cout << "foo" << std::endl;
- return std::cout.bad() ? EXIT_SUCCESS : EXIT_FAILURE;
-}
-
-int h_is_closed_stderr(int argc, char *argv[])
-{
- std::cerr << "foo" << std::endl;
- return std::cerr.bad() ? EXIT_SUCCESS : EXIT_FAILURE;
-}
-
-int h_loop(int argc, char *argv[])
-{
- for (;;)
- ;
-
- return EXIT_SUCCESS;
-}
-
-int h_prefix(int argc, char *argv[])
-{
- std::string line;
- while (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;
- return EXIT_SUCCESS;
-}
-
-int h_query_env(int argc, char *argv[])
-{
-#if defined(BOOST_WINDOWS_API)
- char buf[1024];
- DWORD res = GetEnvironmentVariableA(argv[1], buf, sizeof(buf));
- if (res == 0)
- std::cout << "undefined" << std::endl;
- else
- {
- std::cout << "defined" << std::endl;
- std::cout << "'" << buf << "'" << std::endl;
- }
-#else
- const char *value = getenv(argv[1]);
- if (value == NULL)
- std::cout << "undefined" << std::endl;
- else
- {
- std::cout << "defined" << std::endl;
- std::cout << "'" << value << "'" << std::endl;
- }
-#endif
-
- return EXIT_SUCCESS;
-}
-
-int h_stdin_to_stdout(int argc, char *argv[])
-{
- char ch;
- while (std::cin >> ch)
- std::cout << ch;
-
- return EXIT_SUCCESS;
-}
-
-#if defined(BOOST_POSIX_API)
-int h_posix_echo_one(int argc, char *argv[])
-{
- int desc = std::atoi(argv[1]);
-
- bpd::systembuf buf(desc);
- std::ostream os(&buf);
- os << argv[2] << std::endl;
-
- return EXIT_SUCCESS;
-}
-
-int h_posix_echo_two(int argc, char *argv[])
-{
- int desc1 = std::atoi(argv[1]);
- int desc2 = std::atoi(argv[2]);
-
- bpd::systembuf buf1(desc1);
- std::ostream os1(&buf1);
- os1 << argv[1] << " " << argv[3] << std::endl;
-
- bpd::systembuf buf2(desc2);
- std::ostream os2(&buf2);
- os2 << argv[2] << " " << argv[3] << std::endl;
-
- return EXIT_SUCCESS;
-}
-#endif
-
-#if defined(BOOST_WINDOWS_API)
-int h_win32_print_startupinfo(int argc, char *argv[])
-{
- STARTUPINFO si;
- GetStartupInfo(&si);
- std::cout << "dwFlags = " << si.dwFlags << std::endl;
- std::cout << "dwX = " << si.dwX << std::endl;
- std::cout << "dwY = " << si.dwY << std::endl;
- std::cout << "dwXSize = " << si.dwXSize << std::endl;
- std::cout << "dwYSize = " << si.dwYSize << std::endl;
-
- return EXIT_SUCCESS;
-}
-#endif
-
-int h_read_message(int argc, char *argv[]){
- std::string buff;
- std::cin >> buff;
- if(buff == argv[1])
- return EXIT_SUCCESS;
- else
- return -1;
-}
-
-
-}
-
-struct helper
-{
- const char *name;
- int (*entry)(int, char*[]);
- int min_argc;
- const char *syntax;
-} helpers[] = {
- { "read-message", h_read_message, 1, "message" },
- { "echo-quoted", h_echo_quoted, 2, "word" },
- { "echo-stdout", h_echo_stdout, 2, "message" },
- { "echo-stderr", h_echo_stderr, 2, "message" },
- { "echo-stdout-stderr", h_echo_stdout_stderr, 2, "message" },
- { "exit-failure", h_exit_failure, 1, "" },
- { "exit-success", h_exit_success, 1, "" },
- { "is-closed-stdin", h_is_closed_stdin, 1, "" },
- { "is-closed-stdout", h_is_closed_stdout, 1, "" },
- { "is-closed-stderr", h_is_closed_stderr, 1, "" },
- { "loop", h_loop, 1, "" },
- { "prefix", h_prefix, 2, "string" },
- { "pwd", h_pwd, 1, "" },
- { "query-env", h_query_env, 2, "variable" },
- { "stdin-to-stdout", h_stdin_to_stdout, 1, "" },
-#if defined(BOOST_POSIX_API)
- { "posix-echo-one", h_posix_echo_one, 3, "desc message" },
- { "posix-echo-two", h_posix_echo_two, 4, "desc1 desc2 message" },
-#elif defined(BOOST_WINDOWS_API)
- { "win32-print-startupinfo", h_win32_print_startupinfo, 1, "" },
-#endif
- { 0 }
-};
-
-int main(int argc, char *argv[])
-{
- if (argc < 2)
- {
- std::cerr << "helpers: Missing command" << std::endl;
- return 128;
- }
-
- std::string command(argv[1]);
- --argc;
- ++argv;
-
- struct helper *h = helpers;
- while (h->name != 0)
- {
- if (command == h->name)
- {
- int res;
- if (argc < h->min_argc)
- {
- std::cerr << "helpers: Command syntax: `" << command << " "
- << h->syntax << "'" << std::endl;
- res = 128;
- }
- else
- res = (*h->entry)(argc, argv);
- return res;
- }
- ++h;
- }
-
- std::cerr << "helpers: Invalid command `" << command << "'"
- << std::endl;
- return 128;
-}

Modified: sandbox/SOC/2010/process/libs/process/test/util/boost.hpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/test/util/boost.hpp (original)
+++ sandbox/SOC/2010/process/libs/process/test/util/boost.hpp 2010-08-02 10:57:32 EDT (Mon, 02 Aug 2010)
@@ -18,6 +18,9 @@
 #define BOOST_TEST_IGNORE_SIGCHLD
 #include <boost/test/included/unit_test.hpp>
 #include <boost/filesystem.hpp>
+#include <boost/asio.hpp>
+#include <boost/bind.hpp>
+#include <boost/ref.hpp>
 
 namespace bp = boost::process;
 namespace bpb = boost::process::behavior;
@@ -25,6 +28,6 @@
 namespace but = boost::unit_test;
 namespace butf = boost::unit_test::framework;
 namespace bfs = boost::filesystem;
-namespace ba = boost::asio;
+namespace ba = boost::asio;
 
 #endif

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-02 10:57:32 EDT (Mon, 02 Aug 2010)
@@ -190,16 +190,6 @@
 }
 #endif
 
-int h_read_message(int argc, char *argv[]){
- std::string buff;
- std::cin >> buff;
- if(buff == argv[1])
- return EXIT_SUCCESS;
- else
- return -1;
-}
-
-
 }
 
 struct helper
@@ -209,7 +199,6 @@
     int min_argc;
     const char *syntax;
 } helpers[] = {
- { "read-message", h_read_message, 1, "message" },
     { "echo-quoted", h_echo_quoted, 2, "word" },
     { "echo-stdout", h_echo_stdout, 2, "message" },
     { "echo-stderr", h_echo_stderr, 2, "message" },

Modified: sandbox/SOC/2010/process/libs/process/test/wait.cpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/test/wait.cpp (original)
+++ sandbox/SOC/2010/process/libs/process/test/wait.cpp 2010-08-02 10:57:32 EDT (Mon, 02 Aug 2010)
@@ -24,13 +24,10 @@
 #define BOOST_TEST_MAIN
 #include "util/boost.hpp"
 #include "util/use_helpers.hpp"
-#include <boost/asio.hpp>
 #include <string>
 #include <vector>
 #include <cstdlib>
 
-namespace ba = boost::asio;
-
 BOOST_AUTO_TEST_CASE(test_child_wait)
 {
     check_helpers();


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