1 /*
2  * Copyright (c) 2024 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 <gtest/gtest.h>
17 
18 #include "screen_session_dumper.h"
19 #include "screen_session_manager.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace Rosen {
26 namespace {
27 constexpr uint32_t SLEEP_TIME_US = 100000;
28 }
29 class ScreenSessionDumperTest : public testing::Test {
30 public:
31     static void SetUpTestCase();
32     static void TearDownTestCase();
33     void SetUp() override;
34     void TearDown() override;
35 };
36 
SetUpTestCase()37 void ScreenSessionDumperTest::SetUpTestCase()
38 {
39 }
40 
TearDownTestCase()41 void ScreenSessionDumperTest::TearDownTestCase()
42 {
43 }
44 
SetUp()45 void ScreenSessionDumperTest::SetUp()
46 {
47 }
48 
TearDown()49 void ScreenSessionDumperTest::TearDown()
50 {
51     usleep(SLEEP_TIME_US);
52 }
53 
54 namespace {
55 /**
56  * @tc.name: Dump01
57  * @tc.desc: Dump
58  * @tc.type: FUNC
59  */
60 HWTEST_F(ScreenSessionDumperTest, Dump01, Function | SmallTest | Level1)
61 {
62     int fd = 1;
63     std::vector<std::u16string> args;
64     sptr<ScreenSessionDumper> dumper = new ScreenSessionDumper(fd, args);
65     ASSERT_NE(nullptr, dumper);
66 }
67 
68 /**
69  * @tc.name: Dump02
70  * @tc.desc: Dump input for -h
71  * @tc.type: FUNC
72  */
73 HWTEST_F(ScreenSessionDumperTest, Dump02, Function | SmallTest | Level1)
74 {
75     int fd = 1;
76     std::vector<std::u16string> args = {u"-h"};
77     sptr<ScreenSessionDumper> dumper = new ScreenSessionDumper(fd, args);
78     dumper->ExcuteDumpCmd();
79     ASSERT_TRUE(true);
80 }
81 
82 /**
83  * @tc.name: Dump03
84  * @tc.desc: Dump input for -a
85  * @tc.type: FUNC
86  */
87 HWTEST_F(ScreenSessionDumperTest, Dump03, Function | SmallTest | Level1)
88 {
89     int fd = 1;
90     std::vector<std::u16string> args = {u"-a"};
91     sptr<ScreenSessionDumper> dumper = new ScreenSessionDumper(fd, args);
92     dumper->ExcuteDumpCmd();
93     ASSERT_TRUE(true);
94 }
95 
96 /**
97  * @tc.name: Dump04
98  * @tc.desc: Dump input for abnormal
99  * @tc.type: FUNC
100  */
101 HWTEST_F(ScreenSessionDumperTest, Dump04, Function | SmallTest | Level1)
102 {
103     int fd = 1;
104     std::vector<std::u16string> args = {u"-abnormal"};
105     sptr<ScreenSessionDumper> dumper = new ScreenSessionDumper(fd, args);
106     dumper->ExcuteDumpCmd();
107     ASSERT_TRUE(true);
108 }
109 
110 /**
111  * @tc.name: Dump05
112  * @tc.desc: Dump fd less 0
113  * @tc.type: FUNC
114  */
115 HWTEST_F(ScreenSessionDumperTest, Dump05, Function | SmallTest | Level1)
116 {
117     int fd = -1;
118     std::vector<std::u16string> args = {u"-h"};
119     sptr<ScreenSessionDumper> dumper = new ScreenSessionDumper(fd, args);
120     dumper->ExcuteDumpCmd();
121     ASSERT_TRUE(true);
122 }
123 
124 /**
125  * @tc.name: OutputDumpInfo
126  * @tc.desc: test function : OutputDumpInfo
127  * @tc.type: FUNC
128  */
129 HWTEST_F(ScreenSessionDumperTest, OutputDumpInfo, Function | SmallTest | Level1)
130 {
131     int fd = -1;
132     std::vector<std::u16string> args = {u"-h"};
133     sptr<ScreenSessionDumper> dumper = new ScreenSessionDumper(fd, args);
134     dumper->OutputDumpInfo();
135     ASSERT_EQ(dumper->fd_, -1);
136 }
137 
138 /**
139  * @tc.name: ExcuteDumpCmd
140  * @tc.desc: test function : ExcuteDumpCmd
141  * @tc.type: FUNC
142  */
143 HWTEST_F(ScreenSessionDumperTest, ExcuteDumpCmd, Function | SmallTest | Level1)
144 {
145     int fd = 1;
146     std::vector<std::u16string> args;
147     sptr<ScreenSessionDumper> dumper1 = new ScreenSessionDumper(fd, args);
148     dumper1->ExcuteDumpCmd();
149     ASSERT_EQ(dumper1->fd_, 1);
150 
151     fd = 1;
152     args = {u"-h"};
153     sptr<ScreenSessionDumper> dumper2 = new ScreenSessionDumper(fd, args);
154     dumper2->ExcuteDumpCmd();
155     ASSERT_EQ(dumper2->fd_, 1);
156 
157     fd = 1;
158     args = {u"-a"};
159     sptr<ScreenSessionDumper> dumper3 = new ScreenSessionDumper(fd, args);
160     dumper3->ExcuteDumpCmd();
161     ASSERT_EQ(dumper3->fd_, 1);
162 
163     fd = 1;
164     args = {u"-f"};
165     sptr<ScreenSessionDumper> dumper4 = new ScreenSessionDumper(fd, args);
166     dumper4->ExcuteDumpCmd();
167     ASSERT_EQ(dumper4->fd_, 1);
168 
169     fd = 1;
170     args = {u"-z"};
171     sptr<ScreenSessionDumper> dumper5 = new ScreenSessionDumper(fd, args);
172     dumper5->ExcuteDumpCmd();
173     ASSERT_EQ(dumper5->fd_, 1);
174 
175     fd = 1;
176     args = {u"-y"};
177     sptr<ScreenSessionDumper> dumper6 = new ScreenSessionDumper(fd, args);
178     dumper6->ExcuteDumpCmd();
179     ASSERT_EQ(dumper6->fd_, 1);
180 
181     fd = 1;
182     args = {u"-p"};
183     sptr<ScreenSessionDumper> dumper7 = new ScreenSessionDumper(fd, args);
184     dumper7->ExcuteDumpCmd();
185     ASSERT_EQ(dumper7->fd_, 1);
186 
187     fd = 1;
188     args = {u"-g"};
189     sptr<ScreenSessionDumper> dumper8 = new ScreenSessionDumper(fd, args);
190     dumper8->ExcuteDumpCmd();
191     ASSERT_EQ(dumper8->fd_, 1);
192 }
193 
194 /**
195  * @tc.name: DumpEventTracker
196  * @tc.desc: test function : DumpEventTracker
197  * @tc.type: FUNC
198  */
199 HWTEST_F(ScreenSessionDumperTest, DumpEventTracker, Function | SmallTest | Level1)
200 {
201     int fd = 1;
202     std::vector<std::u16string> args = {u"-h"};
203     sptr<ScreenSessionDumper> dumper = new ScreenSessionDumper(fd, args);
204     EventTracker tracker;
205     dumper->DumpEventTracker(tracker);
206     ASSERT_EQ(dumper->fd_, 1);
207 }
208 
209 /**
210  * @tc.name: DumpFreezedPidList
211  * @tc.desc: test function : DumpFreezedPidList
212  * @tc.type: FUNC
213  */
214 HWTEST_F(ScreenSessionDumperTest, DumpFreezedPidList, Function | SmallTest | Level1)
215 {
216     int fd = 1;
217     std::vector<std::u16string> args = {u"-h"};
218     sptr<ScreenSessionDumper> dumper = new ScreenSessionDumper(fd, args);
219     std::set<int32_t> pidList = {1, 2, 3};
220     dumper->DumpFreezedPidList(pidList);
221     ASSERT_EQ(dumper->fd_, 1);
222 }
223 
224 /**
225  * @tc.name: ShowHelpInfo
226  * @tc.desc: test function : ShowHelpInfo
227  * @tc.type: FUNC
228  */
229 HWTEST_F(ScreenSessionDumperTest, ShowHelpInfo, Function | SmallTest | Level1)
230 {
231     int fd = 1;
232     std::vector<std::u16string> args = {u"-h"};
233     sptr<ScreenSessionDumper> dumper = new ScreenSessionDumper(fd, args);
234     dumper->ShowHelpInfo();
235     ASSERT_EQ(dumper->fd_, 1);
236 }
237 
238 /**
239  * @tc.name: ShowAllScreenInfo
240  * @tc.desc: test function : ShowAllScreenInfo
241  * @tc.type: FUNC
242  */
243 HWTEST_F(ScreenSessionDumperTest, ShowAllScreenInfo, Function | SmallTest | Level1)
244 {
245     int fd = 1;
246     std::vector<std::u16string> args = {u"-h"};
247     sptr<ScreenSessionDumper> dumper = new ScreenSessionDumper(fd, args);
248     dumper->ShowAllScreenInfo();
249     ASSERT_EQ(dumper->fd_, 1);
250 }
251 
252 /**
253  * @tc.name: DumpFoldStatus
254  * @tc.desc: test function : DumpFoldStatus
255  * @tc.type: FUNC
256  */
257 HWTEST_F(ScreenSessionDumperTest, DumpFoldStatus, Function | SmallTest | Level1)
258 {
259     int fd = 1;
260     std::vector<std::u16string> args = {u"-h"};
261     sptr<ScreenSessionDumper> dumper = new ScreenSessionDumper(fd, args);
262     dumper->DumpFoldStatus();
263     ASSERT_EQ(dumper->fd_, 1);
264 }
265 
266 /**
267  * @tc.name: DumpScreenSessionById
268  * @tc.desc: test function : DumpScreenSessionById
269  * @tc.type: FUNC
270  */
271 HWTEST_F(ScreenSessionDumperTest, DumpScreenSessionById, Function | SmallTest | Level1)
272 {
273     int fd = 1;
274     std::vector<std::u16string> args = {u"-h"};
275     sptr<ScreenSessionDumper> dumper = new ScreenSessionDumper(fd, args);
276     ScreenId id = 0;
277     dumper->DumpScreenSessionById(id);
278     ASSERT_EQ(dumper->fd_, 1);
279 
280     id = 5;
281     dumper->DumpScreenSessionById(id);
282     ASSERT_EQ(dumper->fd_, 1);
283 }
284 
285 /**
286  * @tc.name: DumpRsInfoById
287  * @tc.desc: test function : DumpRsInfoById
288  * @tc.type: FUNC
289  */
290 HWTEST_F(ScreenSessionDumperTest, DumpRsInfoById, Function | SmallTest | Level1)
291 {
292     int fd = 1;
293     std::vector<std::u16string> args = {u"-h"};
294     sptr<ScreenSessionDumper> dumper = new ScreenSessionDumper(fd, args);
295     ScreenId id = 0;
296     dumper->DumpRsInfoById(id);
297     ASSERT_EQ(dumper->fd_, 1);
298 
299     id = 5;
300     dumper->DumpRsInfoById(id);
301     ASSERT_EQ(dumper->fd_, 1);
302 }
303 
304 /**
305  * @tc.name: DumpCutoutInfoById
306  * @tc.desc: test function : DumpCutoutInfoById
307  * @tc.type: FUNC
308  */
309 HWTEST_F(ScreenSessionDumperTest, DumpCutoutInfoById, Function | SmallTest | Level1)
310 {
311     int fd = 1;
312     std::vector<std::u16string> args = {u"-h"};
313     sptr<ScreenSessionDumper> dumper = new ScreenSessionDumper(fd, args);
314     ScreenId id = 0;
315     dumper->DumpCutoutInfoById(id);
316     ASSERT_EQ(dumper->fd_, 1);
317 
318     id = 5;
319     dumper->DumpCutoutInfoById(id);
320     ASSERT_EQ(dumper->fd_, 1);
321 }
322 
323 /**
324  * @tc.name: DumpScreenInfoById
325  * @tc.desc: test function : DumpScreenInfoById
326  * @tc.type: FUNC
327  */
328 HWTEST_F(ScreenSessionDumperTest, DumpScreenInfoById, Function | SmallTest | Level1)
329 {
330     int fd = 1;
331     std::vector<std::u16string> args = {u"-h"};
332     sptr<ScreenSessionDumper> dumper = new ScreenSessionDumper(fd, args);
333     ScreenId id = 0;
334     dumper->DumpScreenInfoById(id);
335     ASSERT_EQ(dumper->fd_, 1);
336 
337     id = 5;
338     dumper->DumpScreenInfoById(id);
339     ASSERT_EQ(dumper->fd_, 1);
340 }
341 
342 /**
343  * @tc.name: DumpScreenPropertyById
344  * @tc.desc: test function : DumpScreenPropertyById
345  * @tc.type: FUNC
346  */
347 HWTEST_F(ScreenSessionDumperTest, DumpScreenPropertyById, Function | SmallTest | Level1)
348 {
349     int fd = 1;
350     std::vector<std::u16string> args = {u"-h"};
351     sptr<ScreenSessionDumper> dumper = new ScreenSessionDumper(fd, args);
352     ScreenId id = 0;
353     dumper->DumpScreenPropertyById(id);
354     ASSERT_EQ(dumper->fd_, 1);
355 
356     id = 5;
357     dumper->DumpScreenPropertyById(id);
358     ASSERT_EQ(dumper->fd_, 1);
359 }
360 
361 /**
362  * @tc.name: ShowNotifyFoldStatusChangedInfo
363  * @tc.desc: test function : ShowNotifyFoldStatusChangedInfo
364  * @tc.type: FUNC
365  */
366 HWTEST_F(ScreenSessionDumperTest, ShowNotifyFoldStatusChangedInfo, Function | SmallTest | Level1)
367 {
368     int fd = 1;
369     std::vector<std::u16string> args = {u"-h"};
370     sptr<ScreenSessionDumper> dumper = new ScreenSessionDumper(fd, args);
371     dumper->params_[0] = "0";
372     dumper->ShowNotifyFoldStatusChangedInfo();
373     ASSERT_EQ(dumper->fd_, 1);
374 
375     dumper->params_[0] = "1";
376     dumper->ShowNotifyFoldStatusChangedInfo();
377     ASSERT_EQ(dumper->fd_, 1);
378 
379     dumper->params_[0] = "5";
380     dumper->ShowNotifyFoldStatusChangedInfo();
381     ASSERT_EQ(dumper->fd_, 1);
382 }
383 
384 /**
385  * @tc.name: ShowIllegalArgsInfo
386  * @tc.desc: test function : ShowIllegalArgsInfo
387  * @tc.type: FUNC
388  */
389 HWTEST_F(ScreenSessionDumperTest, ShowIllegalArgsInfo, Function | SmallTest | Level1)
390 {
391     int fd = 1;
392     std::vector<std::u16string> args = {u"-h"};
393     sptr<ScreenSessionDumper> dumper = new ScreenSessionDumper(fd, args);
394     dumper->params_[0] = "0";
395     dumper->ShowIllegalArgsInfo();
396     ASSERT_EQ(dumper->fd_, 1);
397 }
398 
399 /**
400  * @tc.name: SetHoverStatusChange
401  * @tc.desc: test function : SetHoverStatusChange
402  * @tc.type: FUNC
403  */
404 HWTEST_F(ScreenSessionDumperTest, SetHoverStatusChange, Function | SmallTest | Level1)
405 {
406     int fd = 1;
407     std::vector<std::u16string> args = {u"-h"};
408     sptr<ScreenSessionDumper> dumper = new ScreenSessionDumper(fd, args);
409     dumper ->SetHoverStatusChange("-hoverStatus,-1");
410     dumper ->SetHoverStatusChange("-hoverStatus,-0");
411     dumper ->SetHoverStatusChange("-hoverStatus,1");
412     dumper ->SetHoverStatusChange("-hoverStatus,4");
413     ASSERT_EQ(true, true);
414 }
415 
416 /**
417  * @tc.name: DumpTentMode
418  * @tc.desc: test function : DumpTentMode
419  * @tc.type: FUNC
420  */
421 HWTEST_F(ScreenSessionDumperTest, DumpTentMode, Function | SmallTest | Level1)
422 {
423     int fd = 1;
424     std::vector<std::u16string> args = {u"-h"};
425     sptr<ScreenSessionDumper> dumper = new ScreenSessionDumper(fd, args);
426     dumper->DumpTentMode();
427     ASSERT_EQ(dumper->fd_, 1);
428 }
429 
430 /**
431  * @tc.name: SetEnterOrExitTentMode
432  * @tc.desc: test function : SetEnterOrExitTentMode
433  * @tc.type: FUNC
434  */
435 HWTEST_F(ScreenSessionDumperTest, SetEnterOrExitTentMode, Function | SmallTest | Level1)
436 {
437     int fd = 1;
438     std::vector<std::u16string> args = {u"-h"};
439     sptr<ScreenSessionDumper> dumper = new ScreenSessionDumper(fd, args);
440 
441     dumper->SetEnterOrExitTentMode("-offtent");
442     bool tentMode = ScreenSessionManager::GetInstance().GetTentMode();
443     ASSERT_EQ(tentMode, false);
444 }
445 }
446 }
447 }