• 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 #include "subcommand_list_test.h"
17 
18 #include "subcommand_list.h"
19 #include "subcommand.h"
20 
21 using namespace testing::ext;
22 namespace OHOS {
23 namespace Developtools {
24 namespace HiPerf {
25 class SubCommandListTest : public testing::Test {
26 public:
27     static void SetUpTestCase(void);
28     static void TearDownTestCase(void);
29     void SetUp();
30     void TearDown();
31 
32     SubCommandList subCommandList;
33 };
34 
SetUpTestCase()35 void SubCommandListTest::SetUpTestCase() {}
36 
TearDownTestCase()37 void SubCommandListTest::TearDownTestCase() {}
38 
SetUp()39 void SubCommandListTest::SetUp() {}
40 
TearDown()41 void SubCommandListTest::TearDown() {}
42 
43 /**
44  * @tc.name: TestOnSubCommandHW
45  * @tc.desc:
46  * @tc.type: FUNC
47  */
48 HWTEST_F(SubCommandListTest, TestOnSubCommandHW, TestSize.Level0)
49 {
50     std::vector<std::string> args;
51     StdoutRecord stdoutRecord;
52     stdoutRecord.Start();
53 
54     args = {"hw"};
55     EXPECT_EQ(subCommandList.OnSubCommand(args), HiperfError::NO_ERR);
56     std::string stringOut = stdoutRecord.Stop();
57 }
58 
59 /**
60  * @tc.name: TestOnSubCommandSW
61  * @tc.desc:
62  * @tc.type: FUNC
63  */
64 HWTEST_F(SubCommandListTest, TestOnSubCommandSW, TestSize.Level1)
65 {
66     std::vector<std::string> args;
67     StdoutRecord stdoutRecord;
68     stdoutRecord.Start();
69 
70     args = {"sw"};
71     EXPECT_EQ(subCommandList.OnSubCommand(args), HiperfError::NO_ERR);
72     std::string stringOut = stdoutRecord.Stop();
73 }
74 
75 /**
76  * @tc.name: TestOnSubCommandTP
77  * @tc.desc:
78  * @tc.type: FUNC
79  */
80 HWTEST_F(SubCommandListTest, TestOnSubCommandTP, TestSize.Level2)
81 {
82     std::vector<std::string> args;
83     StdoutRecord stdoutRecord;
84     stdoutRecord.Start();
85 
86     args = {"tp"};
87     EXPECT_EQ(subCommandList.OnSubCommand(args), HiperfError::NO_ERR); // still not support
88     std::string stringOut = stdoutRecord.Stop();
89 }
90 
91 /**
92  * @tc.name: TestOnSubCommandCACHE
93  * @tc.desc:
94  * @tc.type: FUNC
95  */
96 HWTEST_F(SubCommandListTest, TestOnSubCommandCACHE, TestSize.Level1)
97 {
98     std::vector<std::string> args;
99     StdoutRecord stdoutRecord;
100     stdoutRecord.Start();
101 
102     args = {"cache"};
103     EXPECT_EQ(subCommandList.OnSubCommand(args), HiperfError::NO_ERR);
104     std::string stringOut = stdoutRecord.Stop();
105 }
106 
107 /**
108  * @tc.name: TestOnSubCommandRAW
109  * @tc.desc:
110  * @tc.type: FUNC
111  */
112 HWTEST_F(SubCommandListTest, TestOnSubCommandRAW, TestSize.Level1)
113 {
114     std::vector<std::string> args;
115     StdoutRecord stdoutRecord;
116     stdoutRecord.Start();
117 
118     args = {"raw"};
119     EXPECT_EQ(subCommandList.OnSubCommand(args), HiperfError::NO_ERR);
120     std::string stringOut = stdoutRecord.Stop();
121 }
122 
123 /**
124  * @tc.name: TestOnSubCommandERROR
125  * @tc.desc:
126  * @tc.type: FUNC
127  */
128 HWTEST_F(SubCommandListTest, TestOnSubCommandERROR, TestSize.Level3)
129 {
130     std::vector<std::string> args;
131     StdoutRecord stdoutRecord;
132     stdoutRecord.Start();
133 
134     args = {"error"};
135     EXPECT_EQ(subCommandList.OnSubCommand(args), HiperfError::OPTION_NOT_SUPPORT);
136     std::string stringOut = stdoutRecord.Stop();
137 }
138 
139 /**
140  * @tc.name: TestOnSubCommandEmpty
141  * @tc.desc:
142  * @tc.type: FUNC
143  */
144 HWTEST_F(SubCommandListTest, TestOnSubCommandEmpty, TestSize.Level2)
145 {
146     std::vector<std::string> args;
147     StdoutRecord stdoutRecord;
148     stdoutRecord.Start();
149 
150     args.clear();
151     EXPECT_EQ(subCommandList.OnSubCommand(args), HiperfError::NO_ERR);
152     std::string stringOut = stdoutRecord.Stop();
153 }
154 
155 /**
156  * @tc.name: TestRegisterSubCommandList
157  * @tc.desc:
158  * @tc.type: FUNC
159  */
160 HWTEST_F(SubCommandListTest, TestRegisterSubCommandList, TestSize.Level1)
161 {
162     SubCommand::ClearSubCommands();
163     ASSERT_EQ(SubCommand::GetSubCommands().size(), 0u);
164     subCommandList.RegisterSubCommandList();
165     SubCommand::RegisterSubCommand("list", std::make_unique<SubCommandList>());
166     ASSERT_EQ(SubCommand::GetSubCommands().size(), 1u);
167 }
168 
169 /**
170  * @tc.name: GetInstance
171  * @tc.desc:
172  * @tc.type: FUNC
173  */
174 HWTEST_F(SubCommandListTest, GetInstance, TestSize.Level1)
175 {
176     StdoutRecord stdoutRecord;
177     stdoutRecord.Start();
178 
179     EXPECT_EQ(SubCommandList::GetInstance().Name(), "list");
180 }
181 } // namespace HiPerf
182 } // namespace Developtools
183 } // namespace OHOS
184