OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chromecast/base/process_utils.h" | 5 #include "chromecast/base/process_utils.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 | 7 |
8 namespace chromecast { | 8 namespace chromecast { |
9 | 9 |
10 // Verify that a simple process works as expected. | 10 // Verify that a simple process works as expected. |
11 TEST(ProcessUtilsTest, SimpleProcess) { | 11 TEST(ProcessUtilsTest, SimpleProcess) { |
12 // Create a simple command. | 12 // Create a simple command. |
13 std::vector<std::string> args; | 13 std::vector<std::string> args; |
14 args.push_back("echo"); | 14 args.push_back("echo"); |
15 args.push_back("Hello World"); | 15 args.push_back("Hello World"); |
16 | 16 |
17 // Execute the command and collect the output. | 17 // Execute the command and collect the output. |
18 std::string stdout; | 18 std::string stdout_str; |
19 ASSERT_TRUE(GetAppOutput(args, &stdout)); | 19 ASSERT_TRUE(GetAppOutput(args, &stdout_str)); |
20 | 20 |
21 // Echo will append a newline to the stdout. | 21 // Echo will append a newline to the stdout. |
22 EXPECT_EQ("Hello World\n", stdout); | 22 EXPECT_EQ("Hello World\n", stdout_str); |
23 } | 23 } |
24 | 24 |
25 // Verify that false is returned for an invalid command. | 25 // Verify that false is returned for an invalid command. |
26 TEST(ProcessUtilsTest, InvalidCommand) { | 26 TEST(ProcessUtilsTest, InvalidCommand) { |
27 // Create a command which is not valid. | 27 // Create a command which is not valid. |
28 std::vector<std::string> args; | 28 std::vector<std::string> args; |
29 args.push_back("invalid_command"); | 29 args.push_back("invalid_command"); |
30 | 30 |
31 // The command should not run. | 31 // The command should not run. |
32 std::string stdout; | 32 std::string stdout_str; |
33 ASSERT_FALSE(GetAppOutput(args, &stdout)); | 33 ASSERT_FALSE(GetAppOutput(args, &stdout_str)); |
34 ASSERT_TRUE(stdout.empty()); | 34 ASSERT_TRUE(stdout_str.empty()); |
35 } | 35 } |
36 | 36 |
37 // Verify that false is returned when a command an error code. | 37 // Verify that false is returned when a command an error code. |
38 TEST(ProcessUtilsTest, ProcessReturnsError) { | 38 TEST(ProcessUtilsTest, ProcessReturnsError) { |
39 // Create a simple command. | 39 // Create a simple command. |
40 std::vector<std::string> args; | 40 std::vector<std::string> args; |
41 args.push_back("cd"); | 41 args.push_back("cd"); |
42 args.push_back("path/to/invalid/directory"); | 42 args.push_back("path/to/invalid/directory"); |
43 args.push_back("2>&1"); // Pipe the stderr into stdout. | 43 args.push_back("2>&1"); // Pipe the stderr into stdout. |
44 | 44 |
45 // Execute the command and collect the output. Verify that the output of the | 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. | 46 // process is collected, even when the process returns an error code. |
47 std::string stderr; | 47 std::string stderr_str; |
48 ASSERT_FALSE(GetAppOutput(args, &stderr)); | 48 ASSERT_FALSE(GetAppOutput(args, &stderr_str)); |
49 ASSERT_FALSE(stderr.empty()); | 49 ASSERT_FALSE(stderr_str.empty()); |
50 } | 50 } |
51 | 51 |
52 } // namespace chromecast | 52 } // namespace chromecast |
OLD | NEW |