blob: a324abab6f4bcb16a09b63142b679124387d0a3e [file] [log] [blame]
Ben Chan6f391cb2012-03-21 17:38:21 -07001// 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
10namespace cros_disks {
11
12// A mock process class for testing the process base class.
13class ProcessUnderTest : public Process {
14 public:
15 ProcessUnderTest() {}
16
17 MOCK_METHOD0(Start, bool());
18};
19
20class ProcessTest : public ::testing::Test {
21 protected:
22 ProcessUnderTest process_;
23};
24
25TEST_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 Chan44e7ea62014-08-29 18:13:37 -070035 EXPECT_NE(nullptr, arguments);
Ben Chan6f391cb2012-03-21 17:38:21 -070036 for (size_t i = 0; i < kNumTestArguments; ++i) {
37 EXPECT_STREQ(kTestArguments[i], arguments[i]);
38 }
Ben Chan44e7ea62014-08-29 18:13:37 -070039 EXPECT_EQ(nullptr, arguments[kNumTestArguments]);
Ben Chan6f391cb2012-03-21 17:38:21 -070040}
41
42TEST_F(ProcessTest, GetArgumentsWithNoArgumentsAdded) {
Ben Chan44e7ea62014-08-29 18:13:37 -070043 EXPECT_EQ(nullptr, process_.GetArguments());
Ben Chan6f391cb2012-03-21 17:38:21 -070044}
45
46} // namespace cros_disks