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

Side by Side Diff: chromecast/base/process_utils_unittest.cc

Issue 1154383006: Adding crash utilities to chromecast/crash. (Closed) Base URL: https://eureka-internal.googlesource.com/chromium/src@master
Patch Set: Refactored crash dependencies Created 5 years, 6 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 unified diff | Download patch
OLDNEW
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698