|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r64257 - in sandbox/SOC/2010/process: boost/process boost/process/detail libs/process/example libs/process/test libs/process/test/util
From: boris_at_[hidden]
Date: 2010-07-22 07:41:15
Author: bschaeling
Date: 2010-07-22 07:41:12 EDT (Thu, 22 Jul 2010)
New Revision: 64257
URL: http://svn.boost.org/trac/boost/changeset/64257
Log:
Added first test case
Added:
sandbox/SOC/2010/process/libs/process/test/
sandbox/SOC/2010/process/libs/process/test/Jamfile.jam (contents, props changed)
sandbox/SOC/2010/process/libs/process/test/arguments.cpp (contents, props changed)
sandbox/SOC/2010/process/libs/process/test/util/
sandbox/SOC/2010/process/libs/process/test/util/boost.hpp (contents, props changed)
sandbox/SOC/2010/process/libs/process/test/util/helpers.cpp (contents, props changed)
sandbox/SOC/2010/process/libs/process/test/util/use_helpers.hpp (contents, props changed)
Text files modified:
sandbox/SOC/2010/process/boost/process/detail/posix_helpers.hpp | 24 +++++++++---------
sandbox/SOC/2010/process/boost/process/detail/status_impl.hpp | 17 ++++++++----
sandbox/SOC/2010/process/boost/process/detail/systembuf.hpp | 8 +++---
sandbox/SOC/2010/process/boost/process/detail/win32_helpers.hpp | 13 ++++-----
sandbox/SOC/2010/process/boost/process/operations.hpp | 52 ++++++++++++++++++++--------------------
sandbox/SOC/2010/process/libs/process/example/read_from_child.cpp | 2
6 files changed, 60 insertions(+), 56 deletions(-)
Modified: sandbox/SOC/2010/process/boost/process/detail/posix_helpers.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/detail/posix_helpers.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/detail/posix_helpers.hpp 2010-07-22 07:41:12 EDT (Thu, 22 Jul 2010)
@@ -41,14 +41,18 @@
* NULL-terminated string of the form var=value; these must also be
* released by the caller.
*
- * \return A dynamically allocated char** array that represents
- * the environment's content. Each array entry is a
- * NULL-terminated string of the form var=value.
+ * \return The first argument of the pair is an integer that indicates
+ * how many strings are stored in the second argument. The
+ * second argument is a NULL-terminated, dynamically allocated
+ * array of dynamically allocated strings representing the
+ * enviroment's content. Each array entry is a NULL-terminated
+ * string of the form var=value. The caller is responsible of
+ * freeing them.
*/
-inline char **environment_to_envp(const environment_t &env)
+inline std::pair<std::size_t, char**> environment_to_envp(const environment_t &env)
{
- char **envp = new char*[env.size() + 1];
-
+ std::size_t nargs = env.size();
+ char **envp = new char*[nargs + 1];
environment_t::size_type i = 0;
for (environment_t::const_iterator it = env.begin(); it != env.end(); ++it)
{
@@ -58,8 +62,7 @@
++i;
}
envp[i] = 0;
-
- return envp;
+ return std::pair<std::size_t, char**>(nargs, envp);
}
/**
@@ -77,11 +80,9 @@
* to the executable. The caller is responsible of freeing them.
*/
template <class Arguments>
-inline std::pair<std::size_t, char**> collection_to_posix_argv(const Arguments &args)
+inline std::pair<std::size_t, char**> collection_to_argv(const Arguments &args)
{
std::size_t nargs = args.size();
- BOOST_ASSERT(nargs >= 0);
-
char **argv = new char*[nargs + 1];
typename Arguments::size_type i = 0;
for (typename Arguments::const_iterator it = args.begin(); it != args.end(); ++it)
@@ -91,7 +92,6 @@
++i;
}
argv[nargs] = 0;
-
return std::pair<std::size_t, char**>(nargs, argv);
}
Modified: sandbox/SOC/2010/process/boost/process/detail/status_impl.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/detail/status_impl.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/detail/status_impl.hpp 2010-07-22 07:41:12 EDT (Thu, 22 Jul 2010)
@@ -37,7 +37,7 @@
namespace process {
namespace detail {
-#elif defined(BOOST_POSIX_API)
+#if defined(BOOST_POSIX_API)
typedef pid_t phandle;
#elif defined(BOOST_WINDOWS_API)
typedef HANDLE phandle;
@@ -82,7 +82,8 @@
} while (p == -1 && errno == EINTR);
if (p == -1)
{
- ec = boost::system::system_error(boost::system::error_code(errno, boost::system::get_system_category()), BOOST_PROCESS_SOURCE_LOCATION "waitpid(2) failed");
+ ec = boost::system::error_code(errno,
+ boost::system::get_system_category());
return -1;
}
return status;
@@ -90,14 +91,16 @@
HANDLE h = OpenProcess(PROCESS_QUERY_INFORMATION | SYNCHRONIZE, FALSE, pid);
if (h == NULL)
{
- ec = boost::system::system_error(boost::system::error_code(errno, boost::system::get_system_category()), BOOST_PROCESS_SOURCE_LOCATION "OpenProcess() failed");
+ ec = boost::system::error_code(GetLastError(),
+ boost::system::get_system_category());
return -1;
}
if (WaitForSingleObject(h, INFINITE) == WAIT_FAILED)
{
CloseHandle(h);
- ec = boost::system::system_error(boost::system::error_code(errno, boost::system::get_system_category()), BOOST_PROCESS_SOURCE_LOCATION "WaitForSingleObject() failed");
+ ec = boost::system::error_code(GetLastError(),
+ boost::system::get_system_category());
return -1;
}
@@ -105,12 +108,14 @@
if (!GetExitCodeProcess(h, &exit_code))
{
CloseHandle(h);
- ec = boost::system::system_error(boost::system::error_code(errno, boost::system::get_system_category()), BOOST_PROCESS_SOURCE_LOCATION "GetExitCodeProcess() failed");
+ ec = boost::system::error_code(GetLastError(),
+ boost::system::get_system_category());
return -1;
}
if (!CloseHandle(h))
{
- ec = boost::system::system_error(boost::system::error_code(errno, boost::system::get_system_category()), BOOST_PROCESS_SOURCE_LOCATION "CloseHandle() failed");
+ ec = boost::system::error_code(GetLastError(),
+ boost::system::get_system_category());
return -1;
}
return exit_code;
Modified: sandbox/SOC/2010/process/boost/process/detail/systembuf.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/detail/systembuf.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/detail/systembuf.hpp 2010-07-22 07:41:12 EDT (Thu, 22 Jul 2010)
@@ -121,11 +121,11 @@
bool ok;
#if defined(BOOST_POSIX_API)
- ssize_t cnt = ::read(handle_, read_buf_.get(), bufsize_);
+ ssize_t cnt = read(handle_, read_buf_.get(), bufsize_);
ok = (cnt != -1 && cnt != 0);
#elif defined(BOOST_WINDOWS_API)
DWORD cnt;
- BOOL res = ::ReadFile(handle_, read_buf_.get(), bufsize_, &cnt, NULL);
+ BOOL res = ReadFile(handle_, read_buf_.get(), bufsize_, &cnt, NULL);
ok = (res && cnt > 0);
#endif
@@ -186,7 +186,7 @@
ssize_t cnt = pptr() - pbase();
bool ok;
- ok = (::write(handle_, pbase(), cnt) == cnt);
+ ok = (write(handle_, pbase(), cnt) == cnt);
if (ok)
pbump(-cnt);
return ok ? 0 : -1;
@@ -197,7 +197,7 @@
long cnt = pptr() - pbase();
bool ok;
DWORD rcnt;
- BOOL res = ::WriteFile(handle_, pbase(), cnt, &rcnt, NULL);
+ BOOL res = WriteFile(handle_, pbase(), cnt, &rcnt, NULL);
ok = (res && static_cast<long>(rcnt) == cnt);
if (ok)
Modified: sandbox/SOC/2010/process/boost/process/detail/win32_helpers.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/detail/win32_helpers.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/detail/win32_helpers.hpp 2010-07-22 07:41:12 EDT (Thu, 22 Jul 2010)
@@ -53,22 +53,21 @@
if (env.empty())
{
envp.reset(new char[2]);
- ::ZeroMemory(envp.get(), 2);
+ ZeroMemory(envp.get(), 2);
}
else
{
std::string s;
for (environment_t::const_iterator it = env.begin(); it != env.end(); ++it)
{
- s += (*it).first + "=" + (*it).second;
+ s += it->first + "=" + it->second;
s.push_back(0);
}
-
envp.reset(new char[s.size() + 1]);
#if defined(__CYGWIN__) || defined(_SCL_SECURE_NO_DEPRECATE)
- ::memcpy(envp.get(), s.c_str(), s.size() + 1);
+ memcpy(envp.get(), s.c_str(), s.size() + 1);
#else
- ::memcpy_s(envp.get(), s.size() + 1, s.c_str(), s.size() + 1);
+ memcpy_s(envp.get(), s.size() + 1, s.c_str(), s.size() + 1);
#endif
}
@@ -118,9 +117,9 @@
cmdline.get()[0] = '\0';
for (arguments_t::size_type i = 0; i < args.size(); ++i)
#if defined(__CYGWIN__) || defined(_SCL_SECURE_NO_DEPRECATE)
- ::strncat(cmdline.get(), args2[i].c_str(), args2[i].size());
+ strncat(cmdline.get(), args2[i].c_str(), args2[i].size());
#else
- ::strcat_s(cmdline.get(), size, args2[i].c_str());
+ strcat_s(cmdline.get(), size, args2[i].c_str());
#endif
return cmdline;
Modified: sandbox/SOC/2010/process/boost/process/operations.hpp
==============================================================================
--- sandbox/SOC/2010/process/boost/process/operations.hpp (original)
+++ sandbox/SOC/2010/process/boost/process/operations.hpp 2010-07-22 07:41:12 EDT (Thu, 22 Jul 2010)
@@ -178,17 +178,17 @@
args.insert(args.begin(), p_name);
#if defined(BOOST_POSIX_API)
- pid_t pid = ::fork();
+ pid_t pid = fork();
if (pid == -1)
BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("fork(2) failed");
else if (pid == 0)
{
#if defined(F_MAXFD)
- int maxdescs = ::fcntl(-1, F_MAXFD, 0);
+ int maxdescs = fcntl(-1, F_MAXFD, 0);
if (maxdescs == -1)
- maxdescs = ::sysconf(_SC_OPEN_MAX);
+ maxdescs = sysconf(_SC_OPEN_MAX);
#else
- int maxdescs = ::sysconf(_SC_OPEN_MAX);
+ int maxdescs = sysconf(_SC_OPEN_MAX);
#endif
if (maxdescs == -1)
maxdescs = 1024;
@@ -201,7 +201,7 @@
int stdin_fd = ctx.stdin_behavior->get_child_end();
if (stdin_fd != -1 && stdin_fd < maxdescs)
{
- if (::dup2(stdin_fd, STDIN_FILENO) == -1)
+ if (dup2(stdin_fd, STDIN_FILENO) == -1)
BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("dup2() failed");
closeflags[STDIN_FILENO] = false;
}
@@ -209,7 +209,7 @@
int stdout_fd = ctx.stdout_behavior->get_child_end();
if (stdout_fd != -1 && stdout_fd < maxdescs)
{
- if (::dup2(stdout_fd, STDOUT_FILENO) == -1)
+ if (dup2(stdout_fd, STDOUT_FILENO) == -1)
BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("dup2() failed");
closeflags[STDOUT_FILENO] = false;
}
@@ -217,7 +217,7 @@
int stderr_fd = ctx.stderr_behavior->get_child_end();
if (stderr_fd != -1 && stderr_fd < maxdescs)
{
- if (::dup2(stderr_fd, STDERR_FILENO) == -1)
+ if (dup2(stderr_fd, STDERR_FILENO) == -1)
BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("dup2() failed");
closeflags[STDERR_FILENO] = false;
}
@@ -225,32 +225,32 @@
for (int i = 0; i < maxdescs; ++i)
{
if (closeflags[i])
- ::close(i);
+ close(i);
}
}
catch (const boost::system::system_error &e)
{
- ::write(STDERR_FILENO, e.what(), std::strlen(e.what()));
- ::write(STDERR_FILENO, "\n", 1);
+ write(STDERR_FILENO, e.what(), std::strlen(e.what()));
+ write(STDERR_FILENO, "\n", 1);
std::exit(127);
}
- std::pair<std::size_t, char**> argcv = detail::collection_to_posix_argv(args);
- char **envp = detail::environment_to_envp(ctx.environment);
+ std::pair<std::size_t, char**> argv = detail::collection_to_argv(args);
+ std::pair<std::size_t, char**> envp = detail::environment_to_envp(ctx.environment);
- ::execve(executable.c_str(), argcv.second, envp);
+ execve(executable.c_str(), argv.second, envp.second);
- for (std::size_t i = 0; i < argcv.first; ++i)
- delete[] argcv.second[i];
- delete[] argcv.second;
-
- for (std::size_t i = 0; i < ctx.environment.size(); ++i)
- delete[] envp[i];
- delete[] envp;
+ for (std::size_t i = 0; i < argv.first; ++i)
+ delete[] argv.second[i];
+ delete[] argv.second;
+
+ for (std::size_t i = 0; i < envp.first; ++i)
+ delete[] envp.second[i];
+ delete[] envp.second;
boost::system::system_error e(boost::system::error_code(errno, boost::system::get_system_category()), BOOST_PROCESS_SOURCE_LOCATION "execve(2) failed");
- ::write(STDERR_FILENO, e.what(), std::strlen(e.what()));
- ::write(STDERR_FILENO, "\n", 1);
+ write(STDERR_FILENO, e.what(), std::strlen(e.what()));
+ write(STDERR_FILENO, "\n", 1);
std::exit(127);
}
else
@@ -271,7 +271,7 @@
}
#elif defined(BOOST_WINDOWS_API)
STARTUPINFOA startup_info;
- ::ZeroMemory(&startup_info, sizeof(startup_info));
+ ZeroMemory(&startup_info, sizeof(startup_info));
startup_info.cb = sizeof(startup_info);
startup_info.dwFlags |= STARTF_USESTDHANDLES;
startup_info.hStdInput = ctx.stdin_behavior->get_child_end();
@@ -279,7 +279,7 @@
startup_info.hStdError = ctx.stderr_behavior->get_child_end();
PROCESS_INFORMATION pi;
- ::ZeroMemory(&pi, sizeof(pi));
+ ZeroMemory(&pi, sizeof(pi));
boost::shared_array<char> cmdline = detail::collection_to_win32_cmdline(args);
@@ -291,10 +291,10 @@
boost::shared_array<char> envstrs = detail::environment_to_win32_strings(ctx.environment);
- if (::CreateProcessA(exe.get(), cmdline.get(), NULL, NULL, TRUE, 0, envstrs.get(), workdir.get(), &startup_info, &pi) == 0)
+ if (CreateProcessA(exe.get(), cmdline.get(), NULL, NULL, TRUE, 0, envstrs.get(), workdir.get(), &startup_info, &pi) == 0)
BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("CreateProcess() failed");
- if (!::CloseHandle(pi.hThread))
+ if (!CloseHandle(pi.hThread))
BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("CloseHandle() failed");
return child(pi.dwProcessId,
Modified: sandbox/SOC/2010/process/libs/process/example/read_from_child.cpp
==============================================================================
--- sandbox/SOC/2010/process/libs/process/example/read_from_child.cpp (original)
+++ sandbox/SOC/2010/process/libs/process/example/read_from_child.cpp 2010-07-22 07:41:12 EDT (Thu, 22 Jul 2010)
@@ -21,7 +21,7 @@
std::string exe = find_executable_in_path("hostname");
context ctx;
ctx.stdout_behavior = behavior::pipe::def(behavior::pipe::stream_type::output_stream);
- child c = create_child(exe,ctx);
+ child c = create_child(exe, ctx);
pistream &is = c.get_stdout();
std::cout << is.rdbuf();
c.wait();
Added: sandbox/SOC/2010/process/libs/process/test/Jamfile.jam
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/process/libs/process/test/Jamfile.jam 2010-07-22 07:41:12 EDT (Thu, 22 Jul 2010)
@@ -0,0 +1,26 @@
+#
+# 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)
+#
+
+alias butf : /boost//unit_test_framework ;
+explicit butf ;
+
+alias bfs : /boost//filesystem : : : <link>shared:<source>/boost//system ;
+explicit bfs ;
+
+project : requirements <target-os>windows:<define>WIN32_LEAN_AND_MEAN ;
+
+exe helpers : util/helpers.cpp bfs ;
+explicit helpers ;
+
+using testing ;
+run arguments.cpp butf bfs : : helpers : <dependency>helpers ;
Added: sandbox/SOC/2010/process/libs/process/test/arguments.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/process/libs/process/test/arguments.cpp 2010-07-22 07:41:12 EDT (Thu, 22 Jul 2010)
@@ -0,0 +1,121 @@
+//
+// Boost.Process
+// ~~~~~~~~~~~~~
+//
+// Copyright (c) 2006, 2007 Julio M. Merino Vidal
+// Copyright (c) 2008, 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 <utility>
+# include <cstddef>
+# include <sys/wait.h>
+#elif defined(BOOST_WINDOWS_API)
+#else
+# error "Unsupported platform."
+#endif
+
+#define BOOST_TEST_MAIN
+#include "util/boost.hpp"
+#include "util/use_helpers.hpp"
+#include <string>
+#include <vector>
+#include <cstring>
+#include <cstdlib>
+
+std::string get_argument(const std::string &word)
+{
+ std::vector<std::string> args;
+ args.push_back("echo-quoted");
+ args.push_back(word);
+
+ bp::context ctx;
+ ctx.stdout_behavior = bpb::pipe::def(bpb::pipe::output_stream);
+
+ bp::child c = bp::create_child(get_helpers_path(), args, ctx);
+ bp::pistream &is = c.get_stdout();
+
+ std::string result;
+ std::getline(is, result);
+ std::string::size_type pos = result.rfind('\r');
+ if (pos != std::string::npos)
+ result.erase(pos);
+
+ int status = c.wait();
+#if defined(BOOST_POSIX_API)
+ BOOST_REQUIRE(WIFEXITED(status));
+ BOOST_CHECK_EQUAL(WEXITSTATUS(status), EXIT_SUCCESS);
+#elif defined(BOOST_WINDOWS_API)
+ BOOST_CHECK_EQUAL(status, EXIT_SUCCESS);
+#endif
+
+ return result;
+}
+
+BOOST_AUTO_TEST_CASE(test_quoting)
+{
+ check_helpers();
+
+ BOOST_CHECK_EQUAL(get_argument("foo"), ">>>foo<<<");
+ BOOST_CHECK_EQUAL(get_argument("foo "), ">>>foo <<<");
+ BOOST_CHECK_EQUAL(get_argument(" foo"), ">>> foo<<<");
+ BOOST_CHECK_EQUAL(get_argument("foo bar"), ">>>foo bar<<<");
+
+ BOOST_CHECK_EQUAL(get_argument("foo\"bar"), ">>>foo\"bar<<<");
+ BOOST_CHECK_EQUAL(get_argument("foo\"bar\""), ">>>foo\"bar\"<<<");
+ BOOST_CHECK_EQUAL(get_argument("\"foo\"bar"), ">>>\"foo\"bar<<<");
+ BOOST_CHECK_EQUAL(get_argument("\"foo bar\""), ">>>\"foo bar\"<<<");
+
+ BOOST_CHECK_EQUAL(get_argument("*"), ">>>*<<<");
+ BOOST_CHECK_EQUAL(get_argument("?*"), ">>>?*<<<");
+ BOOST_CHECK_EQUAL(get_argument("[a-z]*"), ">>>[a-z]*<<<");
+}
+
+#if defined(BOOST_POSIX_API)
+BOOST_AUTO_TEST_CASE(test_collection_to_posix_argv)
+{
+ std::vector<std::string> args;
+ args.push_back("program");
+ args.push_back("arg1");
+ args.push_back("arg2");
+ args.push_back("arg3");
+
+ std::pair<std::size_t, char**> p = bpd::collection_to_argv(args);
+ std::size_t argc = p.first;
+ char **argv = p.second;
+
+ BOOST_REQUIRE_EQUAL(argc, static_cast<std::size_t>(4));
+
+ BOOST_REQUIRE(std::strcmp(argv[0], "program") == 0);
+ BOOST_REQUIRE(std::strcmp(argv[1], "arg1") == 0);
+ BOOST_REQUIRE(std::strcmp(argv[2], "arg2") == 0);
+ BOOST_REQUIRE(std::strcmp(argv[3], "arg3") == 0);
+ BOOST_REQUIRE(argv[4] == 0);
+
+ delete[] argv[0];
+ delete[] argv[1];
+ delete[] argv[2];
+ delete[] argv[3];
+ delete[] argv;
+}
+#endif
+
+#if defined(BOOST_WINDOWS_API)
+BOOST_AUTO_TEST_CASE(test_collection_to_win32_cmdline)
+{
+ std::vector<std::string> args;
+ args.push_back("program");
+ args.push_back("arg1");
+ args.push_back("arg2");
+ args.push_back("arg3");
+
+ boost::shared_array<char> cmdline = bpd::collection_to_win32_cmdline(args);
+ BOOST_REQUIRE(std::strcmp(cmdline.get(), "program arg1 arg2 arg3") == 0);
+}
+#endif
Added: sandbox/SOC/2010/process/libs/process/test/util/boost.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/process/libs/process/test/util/boost.hpp 2010-07-22 07:41:12 EDT (Thu, 22 Jul 2010)
@@ -0,0 +1,27 @@
+//
+// Boost.Process
+// ~~~~~~~~~~~~~
+//
+// Copyright (c) 2006, 2007 Julio M. Merino Vidal
+// Copyright (c) 2008, 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)
+//
+
+#ifndef BOOST_PROCESS_TEST_UTIL_BOOST_HPP
+#define BOOST_PROCESS_TEST_UTIL_BOOST_HPP
+
+#include <boost/process/all.hpp>
+#include <boost/test/unit_test.hpp>
+#include <boost/filesystem.hpp>
+
+namespace bp = boost::process;
+namespace bpb = boost::process::behavior;
+namespace bpd = boost::process::detail;
+namespace but = boost::unit_test;
+namespace butf = boost::unit_test::framework;
+namespace bfs = boost::filesystem;
+
+#endif
Added: sandbox/SOC/2010/process/libs/process/test/util/helpers.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/process/libs/process/test/util/helpers.cpp 2010-07-22 07:41:12 EDT (Thu, 22 Jul 2010)
@@ -0,0 +1,247 @@
+//
+// 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));
+ std::cout << (res ? buf : "undefined") << std::endl;
+#else
+ const char *value = getenv(argv[1]);
+ std::cout << (value ? value : "undefined") << 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
+
+}
+
+struct helper
+{
+ const char *name;
+ int (*entry)(int, char*[]);
+ int min_argc;
+ const char *syntax;
+} helpers[] = {
+ { "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;
+}
Added: sandbox/SOC/2010/process/libs/process/test/util/use_helpers.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2010/process/libs/process/test/util/use_helpers.hpp 2010-07-22 07:41:12 EDT (Thu, 22 Jul 2010)
@@ -0,0 +1,36 @@
+//
+// 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)
+//
+
+#ifndef BOOST_PROCESS_TEST_UTIL_USE_HELPERS_HPP
+#define BOOST_PROCESS_TEST_UTIL_USE_HELPERS_HPP
+
+#include "boost.hpp"
+#include <string>
+
+const std::string &get_helpers_path()
+{
+ static const std::string hp =
+ (bfs::initial_path() / butf::master_test_suite().argv[1]).string();
+ return hp;
+}
+
+void check_helpers()
+{
+ if (butf::master_test_suite().argc < 2)
+ throw butf::setup_error("path to helper expected");
+ if (!bfs::exists(get_helpers_path()))
+ throw butf::setup_error(
+ "helper's path '" + get_helpers_path() + "' does not exists");
+}
+
+#endif
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