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