|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r64740 - in sandbox/SOC/2010/process: boost/process libs/process/test libs/process/test/util
From: boris_at_[hidden]
Date: 2010-08-11 10:49:39
Author: bschaeling
Date: 2010-08-11 10:49:29 EDT (Wed, 11 Aug 2010)
New Revision: 64740
URL: http://svn.boost.org/trac/boost/changeset/64740
Log:
Added test cases for dummy stream behavior
Text files modified:
sandbox/SOC/2010/process/boost/process/stream_behavior.hpp | 7 ++
sandbox/SOC/2010/process/libs/process/test/child.cpp | 93 ++++++++++++++++++++++++++++++++++++---
sandbox/SOC/2010/process/libs/process/test/util/helpers.cpp | 33 ++++++++++++++
3 files changed, 124 insertions(+), 9 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 10:49:29 EDT (Wed, 11 Aug 2010)
@@ -318,7 +318,8 @@
#if defined(BOOST_POSIX_API)
std::string filename = (stream == input_stream) ? "/dev/zero" :
"/dev/null";
- child_end_ = open(filename.c_str(), O_RDONLY);
+ int flag = (stream == input_stream) ? O_RDONLY : O_WRONLY;
+ child_end_ = open(filename.c_str(), flag);
if (!child_end_.valid())
BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("open(2) failed");
#elif defined(BOOST_WINDOWS_API)
@@ -327,6 +328,10 @@
FILE_ATTRIBUTE_NORMAL, NULL);
if (!child_end_.valid())
BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR("CreateFile() failed");
+ if (!SetHandleInformation(child_end_.native(), HANDLE_FLAG_INHERIT,
+ HANDLE_FLAG_INHERIT))
+ BOOST_PROCESS_THROW_LAST_SYSTEM_ERROR(
+ "SetHandleInformation() failed");
#endif
}
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 10:49:29 EDT (Wed, 11 Aug 2010)
@@ -495,15 +495,92 @@
#endif
}
-BOOST_AUTO_TEST_CASE(test_shell)
-{
- child c = bp::shell(get_helpers_path() + " exit_success")
+BOOST_AUTO_TEST_CASE(test_shell)
+{
+#if defined(BOOST_POSIX_API)
+ std::string cmd = "echo test | sed 's,^,LINE-,'";
+#elif defined(BOOST_WINDOWS_API)
+ std::string cmd = "if foo==foo echo LINE-test";
+#endif
+
+ bp::context ctx;
+ ctx.stdout_behavior = bpb::pipe::create(bpb::pipe::output_stream);
+
+ bp::child c = bp::shell(cmd, ctx);
+
+ std::string word;
+ bp::pistream &is = c.get_stdout();
+ is >> word;
+ BOOST_CHECK_EQUAL(word, "LINE-test");
+
+ int s = c.wait();
+#if defined(BOOST_POSIX_API)
+ BOOST_REQUIRE(WIFEXITED(s));
+ BOOST_CHECK_EQUAL(WEXITSTATUS(s), EXIT_SUCCESS);
+#elif defined(BOOST_WINDOWS_API)
+ BOOST_CHECK_EQUAL(s, EXIT_SUCCESS);
+#endif
+}
+
+BOOST_AUTO_TEST_CASE(test_dummy_stdin)
+{
+ check_helpers();
+
+ std::vector<std::string> args;
+ args.push_back("is-nul-stdin");
+
+ bp::context ctx;
+ ctx.stdin_behavior = bpb::dummy::create(bpb::dummy::input_stream);
+
+ bp::child c = bp::create_child(get_helpers_path(), args, ctx);
+
+ int s = c.wait();
+#if defined(BOOST_POSIX_API)
+ BOOST_REQUIRE(WIFEXITED(s));
+ BOOST_CHECK_EQUAL(WEXITSTATUS(s), EXIT_SUCCESS);
+#elif defined(BOOST_WINDOWS_API)
+ BOOST_CHECK_EQUAL(s, EXIT_SUCCESS);
+#endif
+}
+
+BOOST_AUTO_TEST_CASE(test_dummy_stdout)
+{
+ check_helpers();
+
+ std::vector<std::string> args;
+ args.push_back("is-nul-stdout");
- int exit_code = c.wait();
+ bp::context ctx;
+ ctx.stdout_behavior = bpb::dummy::create(bpb::dummy::output_stream);
+
+ bp::child c = bp::create_child(get_helpers_path(), args, ctx);
+
+ int s = c.wait();
#if defined(BOOST_POSIX_API)
- BOOST_REQUIRE(WIFEXITED(exit_code));
- BOOST_CHECK_EQUAL(WEXITSTATUS(exit_code), EXIT_SUCCESS);
+ BOOST_REQUIRE(WIFEXITED(s));
+ BOOST_CHECK_EQUAL(WEXITSTATUS(s), EXIT_SUCCESS);
#elif defined(BOOST_WINDOWS_API)
- BOOST_CHECK_EQUAL(exit_code, EXIT_SUCCESS);
+ BOOST_CHECK_EQUAL(s, EXIT_SUCCESS);
#endif
-}
+}
+
+BOOST_AUTO_TEST_CASE(test_dummy_stderr)
+{
+ check_helpers();
+
+ std::vector<std::string> args;
+ args.push_back("is-nul-stderr");
+
+ bp::context ctx;
+ ctx.stderr_behavior = bpb::dummy::create(bpb::dummy::output_stream);
+
+ bp::child c = bp::create_child(get_helpers_path(), args, ctx);
+
+ int s = c.wait();
+#if defined(BOOST_POSIX_API)
+ BOOST_REQUIRE(WIFEXITED(s));
+ BOOST_CHECK_EQUAL(WEXITSTATUS(s), EXIT_SUCCESS);
+#elif defined(BOOST_WINDOWS_API)
+ BOOST_CHECK_EQUAL(s, EXIT_SUCCESS);
+#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-11 10:49:29 EDT (Wed, 11 Aug 2010)
@@ -88,6 +88,36 @@
return std::cerr.bad() ? EXIT_SUCCESS : EXIT_FAILURE;
}
+int h_is_nul_stdin(int argc, char *argv[])
+{
+#if defined(BOOST_POSIX_API)
+ std::string word;
+ std::cin >> word;
+ return std::cin.eof() ? EXIT_FAILURE : EXIT_SUCCESS;
+#elif defined(BOOST_WINDOWS_API)
+ HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
+ if (h == INVALID_HANDLE_VALUE)
+ return EXIT_FAILURE;
+ char buffer[1];
+ DWORD read;
+ BOOL res = ReadFile(h, &buffer, 1, &read, NULL);
+ CloseHandle(h);
+ return res ? EXIT_SUCCESS : EXIT_FAILURE;
+#endif
+}
+
+int h_is_nul_stdout(int argc, char *argv[])
+{
+ std::cout << "foo" << std::endl;
+ return std::cout.bad() ? EXIT_FAILURE : EXIT_SUCCESS;
+}
+
+int h_is_nul_stderr(int argc, char *argv[])
+{
+ std::cerr << "foo" << std::endl;
+ return std::cerr.bad() ? EXIT_FAILURE : EXIT_SUCCESS;
+}
+
int h_loop(int argc, char *argv[])
{
for (;;)
@@ -208,6 +238,9 @@
{ "is-closed-stdin", h_is_closed_stdin, 1, "" },
{ "is-closed-stdout", h_is_closed_stdout, 1, "" },
{ "is-closed-stderr", h_is_closed_stderr, 1, "" },
+ { "is-nul-stdin", h_is_nul_stdin, 1, "" },
+ { "is-nul-stdout", h_is_nul_stdout, 1, "" },
+ { "is-nul-stderr", h_is_nul_stderr, 1, "" },
{ "loop", h_loop, 1, "" },
{ "prefix", h_prefix, 2, "string" },
{ "pwd", h_pwd, 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