Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / chromecast / base / process_utils_unittest.cc
blobf9c2a0d7d8cad42c0adce5abe36bd7067074a5f3
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chromecast/base/process_utils.h"
6 #include "testing/gtest/include/gtest/gtest.h"
8 namespace chromecast {
10 // Verify that a simple process works as expected.
11 TEST(ProcessUtilsTest, SimpleProcess) {
12 // Create a simple command.
13 std::vector<std::string> args;
14 args.push_back("echo");
15 args.push_back("Hello World");
17 // Execute the command and collect the output.
18 std::string stdout_result;
19 ASSERT_TRUE(GetAppOutput(args, &stdout_result));
21 // Echo will append a newline to the stdout.
22 EXPECT_EQ("Hello World\n", stdout_result);
25 // Verify that false is returned for an invalid command.
26 TEST(ProcessUtilsTest, InvalidCommand) {
27 // Create a command which is not valid.
28 std::vector<std::string> args;
29 args.push_back("invalid_command");
31 // The command should not run.
32 std::string stdout_result;
33 ASSERT_FALSE(GetAppOutput(args, &stdout_result));
34 ASSERT_TRUE(stdout_result.empty());
37 // Verify that false is returned when a command an error code.
38 TEST(ProcessUtilsTest, ProcessReturnsError) {
39 // Create a simple command.
40 std::vector<std::string> args;
41 args.push_back("cd");
42 args.push_back("path/to/invalid/directory");
43 args.push_back("2>&1"); // Pipe the stderr into stdout.
45 // Execute the command and collect the output. Verify that the output of the
46 // process is collected, even when the process returns an error code.
47 std::string stderr_result;
48 ASSERT_FALSE(GetAppOutput(args, &stderr_result));
49 ASSERT_FALSE(stderr_result.empty());
52 } // namespace chromecast