Ben Chan | 6f391cb | 2012-03-21 17:38:21 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS 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. |
| 4 | |
| 5 | #include "cros-disks/process.h" |
| 6 | |
| 7 | #include <gmock/gmock.h> |
| 8 | #include <gtest/gtest.h> |
| 9 | |
| 10 | namespace cros_disks { |
| 11 | |
| 12 | // A mock process class for testing the process base class. |
| 13 | class ProcessUnderTest : public Process { |
| 14 | public: |
| 15 | ProcessUnderTest() {} |
| 16 | |
| 17 | MOCK_METHOD0(Start, bool()); |
| 18 | }; |
| 19 | |
| 20 | class ProcessTest : public ::testing::Test { |
| 21 | protected: |
| 22 | ProcessUnderTest process_; |
| 23 | }; |
| 24 | |
| 25 | TEST_F(ProcessTest, GetArguments) { |
| 26 | static const char* const kTestArguments[] = { |
| 27 | "/bin/ls", "-l", "", "." |
| 28 | }; |
| 29 | static const size_t kNumTestArguments = arraysize(kTestArguments); |
| 30 | for (size_t i = 0; i < kNumTestArguments; ++i) { |
| 31 | process_.AddArgument(kTestArguments[i]); |
| 32 | } |
| 33 | |
| 34 | char** arguments = process_.GetArguments(); |
Ben Chan | 44e7ea6 | 2014-08-29 18:13:37 -0700 | [diff] [blame^] | 35 | EXPECT_NE(nullptr, arguments); |
Ben Chan | 6f391cb | 2012-03-21 17:38:21 -0700 | [diff] [blame] | 36 | for (size_t i = 0; i < kNumTestArguments; ++i) { |
| 37 | EXPECT_STREQ(kTestArguments[i], arguments[i]); |
| 38 | } |
Ben Chan | 44e7ea6 | 2014-08-29 18:13:37 -0700 | [diff] [blame^] | 39 | EXPECT_EQ(nullptr, arguments[kNumTestArguments]); |
Ben Chan | 6f391cb | 2012-03-21 17:38:21 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | TEST_F(ProcessTest, GetArgumentsWithNoArgumentsAdded) { |
Ben Chan | 44e7ea6 | 2014-08-29 18:13:37 -0700 | [diff] [blame^] | 43 | EXPECT_EQ(nullptr, process_.GetArguments()); |
Ben Chan | 6f391cb | 2012-03-21 17:38:21 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | } // namespace cros_disks |