diff options
author | benwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-06 06:14:48 +0000 |
---|---|---|
committer | benwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-06 06:14:48 +0000 |
commit | d03b05c28ce4dd5da89bee73e507d92506b41958 (patch) | |
tree | 69f988c9d3b18b7408ad6b1c975bacb5a2905485 /base/process_util_unittest.cc | |
parent | 031c073b907cd540604377687d49792cf86fdf20 (diff) | |
download | chromium_src-d03b05c28ce4dd5da89bee73e507d92506b41958.zip chromium_src-d03b05c28ce4dd5da89bee73e507d92506b41958.tar.gz chromium_src-d03b05c28ce4dd5da89bee73e507d92506b41958.tar.bz2 |
Added ability to run a command, getting output and exit status on POSIX.
Register protocol handler needs to check the return value of scripts it runs and
collects output from. There needs a variant of GetAppOutput which returns the
exit code of the application run, not just a success or failure, so this function
has been added.
BUG=83557
TEST=Unit test added
Review URL: http://codereview.chromium.org/7198034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@91527 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_unittest.cc')
-rw-r--r-- | base/process_util_unittest.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc index 06b7537..9d82b42 100644 --- a/base/process_util_unittest.cc +++ b/base/process_util_unittest.cc @@ -660,6 +660,21 @@ TEST_F(ProcessUtilTest, GetAppOutputRestricted) { EXPECT_STREQ("", output.c_str()); } +#if !(OS_MACOSX) +// TODO(benwells): GetAppOutputRestricted should terminate applications +// with SIGPIPE when we have enough output. http://crbug.com/88502 +TEST_F(ProcessUtilTest, GetAppOutputRestrictedSIGPIPE) { + std::vector<std::string> argv; + std::string output; + + argv.push_back("/bin/sh"); + argv.push_back("-c"); + argv.push_back("yes"); + EXPECT_TRUE(base::GetAppOutputRestricted(CommandLine(argv), &output, 10)); + EXPECT_STREQ("y\ny\ny\ny\ny\n", output.c_str()); +} +#endif + TEST_F(ProcessUtilTest, GetAppOutputRestrictedNoZombies) { std::vector<std::string> argv; argv.push_back("/bin/sh"); // argv[0] @@ -682,6 +697,29 @@ TEST_F(ProcessUtilTest, GetAppOutputRestrictedNoZombies) { } } +TEST_F(ProcessUtilTest, GetAppOutputWithExitCode) { + // Test getting output from a successful application. + std::vector<std::string> argv; + std::string output; + int exit_code; + argv.push_back("/bin/sh"); // argv[0] + argv.push_back("-c"); // argv[1] + argv.push_back("echo foo"); // argv[2]; + EXPECT_TRUE(base::GetAppOutputWithExitCode(CommandLine(argv), &output, + &exit_code)); + EXPECT_STREQ("foo\n", output.c_str()); + EXPECT_EQ(exit_code, 0); + + // Test getting output from an application which fails with a specific exit + // code. + output.clear(); + argv[2] = "echo foo; exit 2"; + EXPECT_TRUE(base::GetAppOutputWithExitCode(CommandLine(argv), &output, + &exit_code)); + EXPECT_STREQ("foo\n", output.c_str()); + EXPECT_EQ(exit_code, 2); +} + TEST_F(ProcessUtilTest, GetParentProcessId) { base::ProcessId ppid = base::GetParentProcessId(base::GetCurrentProcId()); EXPECT_EQ(ppid, getppid()); |