summaryrefslogtreecommitdiffstats
path: root/base/process_util_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'base/process_util_unittest.cc')
-rw-r--r--base/process_util_unittest.cc42
1 files changed, 42 insertions, 0 deletions
diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc
index 3170b6a..d22a60a 100644
--- a/base/process_util_unittest.cc
+++ b/base/process_util_unittest.cc
@@ -294,6 +294,48 @@ 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;
+
+ env_changes.push_back(std::make_pair(std::string("BASE_TEST"),
+ std::string("bar")));
+ EXPECT_EQ("bar\n", TestLaunchApp(env_changes));
+ env_changes.clear();
+
+ 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));