• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef HIPERF_SUBCOMMAND_TEST_H
17 #define HIPERF_SUBCOMMAND_TEST_H
18 
19 #include <gmock/gmock.h>
20 #include <gtest/gtest.h>
21 
22 #include "subcommand.h"
23 namespace OHOS {
24 namespace Developtools {
25 namespace HiPerf {
26 static std::string TEST_CMD_1 = "TEST_CMD_1";
27 static std::string TEST_CMD_2 = "TEST_CMD_2";
28 static std::string TEST_CMD_3 = "TEST_CMD_3";
29 static std::string TEST_NOREG_CMD = "TEST_NOREG_CMD";
30 static std::string TEST_BRIEF = " TEST_BRIEF\n";
31 static std::string TEST_HELP = " TEST_HELP\n";
32 
33 static const std::vector<std::string> EMPTY_ARGS = {""};
34 static const std::vector<std::string> TEST_REG_ARG_1 = {TEST_CMD_1};
35 static const std::vector<std::string> TEST_REG_ARG_2 = {TEST_CMD_2};
36 static const std::vector<std::string> TEST_REG_ARG_3 = {TEST_CMD_3};
37 static const std::vector<std::string> TEST_REG_ARG_3S = {TEST_CMD_3, TEST_CMD_2, TEST_CMD_1};
38 static const std::vector<std::string> TEST_NOREG_ARG_1 = {TEST_NOREG_CMD};
39 
40 class SubCommandTest : public SubCommand {
41 public:
SubCommandTest(std::string name)42     explicit SubCommandTest(std::string name) : SubCommand(name, TEST_BRIEF, TEST_HELP) {}
43 
OnSubCommand(std::vector<std::string> & args)44     bool OnSubCommand(std::vector<std::string> &args) override
45     {
46         return true;
47     }
48 };
49 
50 using ::testing::_;
51 using ::testing::Return;
52 
53 class MockSubCommand : public SubCommand {
54 public:
MockSubCommand(std::string name)55     explicit MockSubCommand(std::string name) : SubCommand(name, TEST_BRIEF, TEST_HELP) {}
MockSubCommand()56     MockSubCommand() : MockSubCommand("mock") {}
57     MOCK_METHOD1(OnSubCommand, bool(std::vector<std::string> &args));
58 };
59 } // namespace HiPerf
60 } // namespace Developtools
61 } // namespace OHOS
62 #endif // HIPERF_SUBCOMMAND_TEST_H
63