Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3284)

Unified Diff: base/process_util_unittest.cc

Issue 672003: POSIX: don't allocate memory after forking. (Closed)
Patch Set: ... Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/process_util_posix.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process_util_unittest.cc
diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc
index 3170b6a60c062b92b01030f52ec53e881c670b43..f32f7ba5b48f05aa8be36d05e949a9a5ee24e1e6 100644
--- a/base/process_util_unittest.cc
+++ b/base/process_util_unittest.cc
@@ -294,6 +294,43 @@ TEST_F(ProcessUtilTest, FDRemapping) {
DPCHECK(ret == 0);
}
+static std::string TestLaunchApp(const base::environment_vector& env_changes) {
+ std::vector<std::string> args;
+ base::file_handle_mapping_vector fds_to_remap;
+ ProcessHandle handle;
+
+ args.push_back("bash");
+ args.push_back("-c");
+ args.push_back("echo $BASE_TEST");
+
+ int fds[2];
+ PCHECK(pipe(fds) == 0);
+
+ fds_to_remap.push_back(std::make_pair(fds[1], 1));
+ EXPECT_TRUE(LaunchApp(args, env_changes, fds_to_remap,
+ true /* wait for exit */, &handle));
+ PCHECK(close(fds[1]) == 0);
+
+ char buf[32];
+ const ssize_t n = HANDLE_EINTR(read(fds[0], buf, sizeof(buf)));
+ PCHECK(n > 0);
+ return std::string(buf, n);
+}
+
+TEST_F(ProcessUtilTest, LaunchApp) {
+ base::environment_vector env_changes;
+
+ setenv("BASE_TEST", "testing", 1 /* override */);
+ EXPECT_EQ("testing\n", TestLaunchApp(env_changes));
+
+ env_changes.push_back(std::make_pair(std::string("BASE_TEST"),
+ std::string("")));
+ EXPECT_EQ("\n", TestLaunchApp(env_changes));
+
+ env_changes[0].second = "foo";
+ EXPECT_EQ("foo\n", TestLaunchApp(env_changes));
+}
+
TEST_F(ProcessUtilTest, GetAppOutput) {
std::string output;
EXPECT_TRUE(GetAppOutput(CommandLine(FilePath("true")), &output));
« no previous file with comments | « base/process_util_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698