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