1 /*
2  * Copyright (c) 2022-2023 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 "distributed_sched_dumper_test.h"
17 #include "distributed_sched_test_util.h"
18 #include "test_log.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 namespace DistributedSchedule {
25 namespace {
26 const char* HIDUMPER_PROCESS_NAME = "hidumper_service";
27 }
SetUpTestCase()28 void DistributedSchedDumperTest::SetUpTestCase()
29 {
30     DTEST_LOG << "DistributedSchedDumperTest::SetUpTestCase" << std::endl;
31 }
32 
TearDownTestCase()33 void DistributedSchedDumperTest::TearDownTestCase()
34 {
35     DTEST_LOG << "DistributedSchedDumperTest::TearDownTestCase" << std::endl;
36 }
37 
TearDown()38 void DistributedSchedDumperTest::TearDown()
39 {
40     DTEST_LOG << "DistributedSchedDumperTest::TearDown" << std::endl;
41 }
42 
SetUp()43 void DistributedSchedDumperTest::SetUp()
44 {
45     DTEST_LOG << "DistributedSchedDumperTest::SetUp" << std::endl;
46 }
47 
48 /**
49  * @tc.name: DumpDefault_001
50  * @tc.desc: dump default info
51  * @tc.type: FUNC
52  * @tc.require: I60TOK
53  */
HWTEST_F(DistributedSchedDumperTest, DumpDefault_001, TestSize.Level3)54 HWTEST_F(DistributedSchedDumperTest, DumpDefault_001, TestSize.Level3)
55 {
56     DTEST_LOG << "DistributedSchedDumperTest DumpDefault_001 begin" << std::endl;
57     std::string result = "";
58     bool res = DistributedSchedDumper::DumpDefault(result);
59     EXPECT_EQ(res, true);
60     DTEST_LOG << "DistributedSchedDumperTest DumpDefault_001 end" << std::endl;
61 }
62 
63 /**
64  * @tc.name: Dump_001
65  * @tc.desc: dump info with null arg
66  * @tc.type: FUNC
67  * @tc.require: I60TOK
68  */
HWTEST_F(DistributedSchedDumperTest, Dump_001, TestSize.Level3)69 HWTEST_F(DistributedSchedDumperTest, Dump_001, TestSize.Level3)
70 {
71     DTEST_LOG << "DistributedSchedDumperTest Dump_001 begin" << std::endl;
72     const std::vector<std::string> args = {};
73     std::string result = "";
74     bool res = DistributedSchedDumper::Dump(args, result);
75     EXPECT_EQ(res, false);
76     DTEST_LOG << "DistributedSchedDumperTest Dump_001 end" << std::endl;
77 }
78 
79 /**
80  * @tc.name: Dump_002
81  * @tc.desc: dump info with a correct arg
82  * @tc.type: FUNC
83  * @tc.require: I60TOK
84  */
HWTEST_F(DistributedSchedDumperTest, Dump_002, TestSize.Level3)85 HWTEST_F(DistributedSchedDumperTest, Dump_002, TestSize.Level3)
86 {
87     DTEST_LOG << "DistributedSchedDumperTest Dump_002 begin" << std::endl;
88     const std::vector<std::string> args = {"-connect"};
89     std::string result = "";
90     bool res = DistributedSchedDumper::Dump(args, result);
91     EXPECT_EQ(res, false);
92     DTEST_LOG << "DistributedSchedDumperTest Dump_002 end" << std::endl;
93 }
94 
95 /**
96  * @tc.name: Dump_003
97  * @tc.desc: dump info with a invalid arg
98  * @tc.type: FUNC
99  * @tc.require: I60TOK
100  */
HWTEST_F(DistributedSchedDumperTest, Dump_003, TestSize.Level3)101 HWTEST_F(DistributedSchedDumperTest, Dump_003, TestSize.Level3)
102 {
103     DTEST_LOG << "DistributedSchedDumperTest Dump_003 begin" << std::endl;
104     const std::vector<std::string> args = {"-invalid"};
105     std::string result = "";
106     bool res = DistributedSchedDumper::Dump(args, result);
107     EXPECT_EQ(res, false);
108     DTEST_LOG << "DistributedSchedDumperTest Dump_003 end" << std::endl;
109 }
110 
111 /**
112  * @tc.name: Dump_004
113  * @tc.desc: dump info with two args
114  * @tc.type: FUNC
115  * @tc.require: I60TOK
116  */
HWTEST_F(DistributedSchedDumperTest, Dump_004, TestSize.Level3)117 HWTEST_F(DistributedSchedDumperTest, Dump_004, TestSize.Level3)
118 {
119     DTEST_LOG << "DistributedSchedDumperTest Dump_004 begin" << std::endl;
120     const std::vector<std::string> args = {"-invalid1", "-invalid2"};
121     std::string result = "";
122     bool res = DistributedSchedDumper::Dump(args, result);
123     EXPECT_EQ(res, false);
124     DTEST_LOG << "DistributedSchedDumperTest Dump_004 end" << std::endl;
125 }
126 
127 /**
128  * @tc.name: Dump_005
129  * @tc.desc: dump info with one arg
130  * @tc.type: FUNC
131  * @tc.require: I6ONQ3
132  */
HWTEST_F(DistributedSchedDumperTest, Dump_005, TestSize.Level3)133 HWTEST_F(DistributedSchedDumperTest, Dump_005, TestSize.Level3)
134 {
135     DTEST_LOG << "DistributedSchedDumperTest Dump_005 begin" << std::endl;
136     DistributedSchedUtil::MockProcess(HIDUMPER_PROCESS_NAME);
137     const std::vector<std::string> args = {"-h"};
138     std::string result = "";
139     bool res = DistributedSchedDumper::Dump(args, result);
140     EXPECT_TRUE(res);
141     DTEST_LOG << "DistributedSchedDumperTest Dump_005 end" << std::endl;
142 }
143 
144 /**
145  * @tc.name: Dump_006
146  * @tc.desc: dump info with one arg
147  * @tc.type: FUNC
148  * @tc.require: I6ONQ3
149  */
HWTEST_F(DistributedSchedDumperTest, Dump_006, TestSize.Level3)150 HWTEST_F(DistributedSchedDumperTest, Dump_006, TestSize.Level3)
151 {
152     DTEST_LOG << "DistributedSchedDumperTest Dump_006 begin" << std::endl;
153     DistributedSchedUtil::MockProcess(HIDUMPER_PROCESS_NAME);
154     const std::vector<std::string> args = {"-connect"};
155     std::string result = "";
156     bool res = DistributedSchedDumper::Dump(args, result);
157     EXPECT_TRUE(res);
158     DTEST_LOG << "DistributedSchedDumperTest Dump_006 end" << std::endl;
159 }
160 
161 /**
162  * @tc.name: Dump_007
163  * @tc.desc: dump info with one arg
164  * @tc.type: FUNC
165  * @tc.require: I6ONQ3
166  */
HWTEST_F(DistributedSchedDumperTest, Dump_007, TestSize.Level3)167 HWTEST_F(DistributedSchedDumperTest, Dump_007, TestSize.Level3)
168 {
169     DTEST_LOG << "DistributedSchedDumperTest Dump_007 begin" << std::endl;
170     DistributedSchedUtil::MockProcess(HIDUMPER_PROCESS_NAME);
171     const std::vector<std::string> args = {"-invalid"};
172     std::string result = "";
173     bool res = DistributedSchedDumper::Dump(args, result);
174     EXPECT_FALSE(res);
175     DTEST_LOG << "DistributedSchedDumperTest Dump_007 end" << std::endl;
176 }
177 
178 /**
179  * @tc.name: Dump_008
180  * @tc.desc: dump info with two arg
181  * @tc.type: FUNC
182  * @tc.require: I6ONQ3
183  */
HWTEST_F(DistributedSchedDumperTest, Dump_008, TestSize.Level3)184 HWTEST_F(DistributedSchedDumperTest, Dump_008, TestSize.Level3)
185 {
186     DTEST_LOG << "DistributedSchedDumperTest Dump_008 begin" << std::endl;
187     DistributedSchedUtil::MockProcess(HIDUMPER_PROCESS_NAME);
188     const std::vector<std::string> args = {"-invalid1", "-invalid2"};
189     std::string result = "";
190     bool res = DistributedSchedDumper::Dump(args, result);
191     EXPECT_FALSE(res);
192     DTEST_LOG << "DistributedSchedDumperTest Dump_008 end" << std::endl;
193 }
194 
195 /**
196  * @tc.name: Dump_009
197  * @tc.desc: dump info with 0 arg
198  * @tc.type: FUNC
199  * @tc.require: I6ONQ3
200  */
HWTEST_F(DistributedSchedDumperTest, Dump_009, TestSize.Level3)201 HWTEST_F(DistributedSchedDumperTest, Dump_009, TestSize.Level3)
202 {
203     DTEST_LOG << "DistributedSchedDumperTest Dump_009 begin" << std::endl;
204     DistributedSchedUtil::MockProcess(HIDUMPER_PROCESS_NAME);
205     const std::vector<std::string> args = {};
206     std::string result = "";
207     bool res = DistributedSchedDumper::Dump(args, result);
208     EXPECT_TRUE(res);
209     DTEST_LOG << "DistributedSchedDumperTest Dump_009 end" << std::endl;
210 }
211 
212 /**
213  * @tc.name: CanDump_001
214  * @tc.desc: CanDump
215  * @tc.type: FUNC
216  * @tc.require: I6ONQ3
217  */
HWTEST_F(DistributedSchedDumperTest, CanDump_001, TestSize.Level3)218 HWTEST_F(DistributedSchedDumperTest, CanDump_001, TestSize.Level3)
219 {
220     DTEST_LOG << "DistributedSchedDumperTest CanDump_001 begin" << std::endl;
221     DistributedSchedUtil::MockProcess(HIDUMPER_PROCESS_NAME);
222     bool res = DistributedSchedDumper::CanDump();
223     EXPECT_TRUE(res);
224     DTEST_LOG << "DistributedSchedDumperTest CanDump_001 end" << std::endl;
225 }
226 }
227 }