1 /*
2 * Copyright (c) 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 <gtest/gtest.h>
17 #include "display_dumper.h"
18 #include "display_manager_service.h"
19 #include "scene_board_judgement.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace Rosen {
26 class DisplayDumperTest : public testing::Test {
27 public:
28 static void SetUpTestCase();
29 static void TearDownTestCase();
30 void SetUp() override;
31 void TearDown() override;
32 };
33
SetUpTestCase()34 void DisplayDumperTest::SetUpTestCase()
35 {
36 }
37
TearDownTestCase()38 void DisplayDumperTest::TearDownTestCase()
39 {
40 }
41
SetUp()42 void DisplayDumperTest::SetUp()
43 {
44 }
45
TearDown()46 void DisplayDumperTest::TearDown()
47 {
48 }
49
50 namespace {
51 /**
52 * @tc.name: Dump01
53 * @tc.desc: Dump
54 * @tc.type: FUNC
55 */
56 HWTEST_F(DisplayDumperTest, Dump01, TestSize.Level1)
57 {
58 sptr<DisplayDumper> displayDumper;
59 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
60 DisplayManagerService::GetInstance().abstractScreenController_,
61 DisplayManagerService::GetInstance().mutex_);
62 int fd = 1;
63 std::vector<std::u16string> args;
64 DMError ret = displayDumper->Dump(fd, args);
65 ASSERT_EQ(ret, DMError::DM_OK);
66 }
67
68 /**
69 * @tc.name: Dump02
70 * @tc.desc: Dump fd less 0
71 * @tc.type: FUNC
72 */
73 HWTEST_F(DisplayDumperTest, Dump02, TestSize.Level1)
74 {
75 sptr<DisplayDumper> displayDumper;
76 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
77 DisplayManagerService::GetInstance().abstractScreenController_,
78 DisplayManagerService::GetInstance().mutex_);
79 int fd = -1;
80 std::vector<std::u16string> args;
81 DMError ret = displayDumper->Dump(fd, args);
82 ASSERT_EQ(ret, DMError::DM_ERROR_INVALID_PARAM);
83 }
84
85 /**
86 * @tc.name: Dump03
87 * @tc.desc: Dump one param with '-h'
88 * @tc.type: FUNC
89 */
90 HWTEST_F(DisplayDumperTest, Dump03, TestSize.Level1)
91 {
92 sptr<DisplayDumper> displayDumper;
93 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
94 DisplayManagerService::GetInstance().abstractScreenController_,
95 DisplayManagerService::GetInstance().mutex_);
96 int fd = 3;
97 std::vector<std::u16string> args;
98 const std::u16string DUMP_HELP = u"-h";
99 args.emplace_back(DUMP_HELP);
100 DMError ret = displayDumper->Dump(fd, args);
101 ASSERT_TRUE(ret == DMError::DM_OK || ret == DMError::DM_ERROR_UNKNOWN);
102 }
103
104 /**
105 * @tc.name: Dump04
106 * @tc.desc: Dump one param with '-x'
107 * @tc.type: FUNC
108 */
109 HWTEST_F(DisplayDumperTest, Dump04, TestSize.Level1)
110 {
111 sptr<DisplayDumper> displayDumper;
112 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
113 DisplayManagerService::GetInstance().abstractScreenController_,
114 DisplayManagerService::GetInstance().mutex_);
115 int fd = 4;
116 std::vector<std::u16string> args;
117 const std::u16string DUMP_HELP = u"-x";
118 args.emplace_back(DUMP_HELP);
119 DMError ret = displayDumper->Dump(fd, args);
120 ASSERT_TRUE(ret == DMError::DM_OK || ret == DMError::DM_ERROR_UNKNOWN);
121 }
122
123 /**
124 * @tc.name: Dump05
125 * @tc.desc: Dump two param with '-s -a'
126 * @tc.type: FUNC
127 */
128 HWTEST_F(DisplayDumperTest, Dump05, TestSize.Level1)
129 {
130 sptr<DisplayDumper> displayDumper;
131 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
132 DisplayManagerService::GetInstance().abstractScreenController_,
133 DisplayManagerService::GetInstance().mutex_);
134 int fd = 5;
135 std::vector<std::u16string> args;
136 const std::u16string DUMP_SCREEN = u"-s";
137 const std::u16string DUMP_ALL = u"-a";
138 args.emplace_back(DUMP_SCREEN);
139 args.emplace_back(DUMP_ALL);
140 DMError ret = displayDumper->Dump(fd, args);
141 ASSERT_TRUE(ret == DMError::DM_OK || ret == DMError::DM_ERROR_UNKNOWN);
142 }
143
144 /**
145 * @tc.name: Dump06
146 * @tc.desc: Dump two param with '-d -a'
147 * @tc.type: FUNC
148 */
149 HWTEST_F(DisplayDumperTest, Dump06, TestSize.Level1)
150 {
151 sptr<DisplayDumper> displayDumper;
152 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
153 DisplayManagerService::GetInstance().abstractScreenController_,
154 DisplayManagerService::GetInstance().mutex_);
155 int fd = 6;
156 std::vector<std::u16string> args;
157 const std::u16string DUMP_DISPLAY = u"-d";
158 const std::u16string DUMP_ALL = u"-a";
159 args.emplace_back(DUMP_DISPLAY);
160 args.emplace_back(DUMP_ALL);
161 DMError ret = displayDumper->Dump(fd, args);
162 ASSERT_TRUE(ret == DMError::DM_OK || ret == DMError::DM_ERROR_UNKNOWN);
163 }
164
165 /**
166 * @tc.name: Dump07
167 * @tc.desc: Dump two param with '-s 1'
168 * @tc.type: FUNC
169 */
170 HWTEST_F(DisplayDumperTest, Dump071, TestSize.Level1)
171 {
172 sptr<DisplayDumper> displayDumper;
173 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
174 DisplayManagerService::GetInstance().abstractScreenController_,
175 DisplayManagerService::GetInstance().mutex_);
176 int fd = 71;
177 std::vector<std::u16string> args;
178 const std::u16string DUMP_SCREEN = u"-s";
179 const std::u16string DUMP_NUMBER = u"0";
180 args.emplace_back(DUMP_SCREEN);
181 args.emplace_back(DUMP_NUMBER);
182 DMError ret = displayDumper->Dump(fd, args);
183 ASSERT_TRUE(ret == DMError::DM_OK || ret == DMError::DM_ERROR_UNKNOWN);
184 }
185
186 /**
187 * @tc.name: Dump07
188 * @tc.desc: Dump two param with '-s -1'
189 * @tc.type: FUNC
190 */
191 HWTEST_F(DisplayDumperTest, Dump07, TestSize.Level1)
192 {
193 sptr<DisplayDumper> displayDumper;
194 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
195 DisplayManagerService::GetInstance().abstractScreenController_,
196 DisplayManagerService::GetInstance().mutex_);
197 int fd = 7;
198 std::vector<std::u16string> args;
199 const std::u16string DUMP_SCREEN = u"-s";
200 const std::u16string DUMP_NUMBER = u"-1";
201 args.emplace_back(DUMP_SCREEN);
202 args.emplace_back(DUMP_NUMBER);
203 DMError ret = displayDumper->Dump(fd, args);
204 ASSERT_TRUE(ret == DMError::DM_OK || ret == DMError::DM_ERROR_UNKNOWN);
205 }
206
207 /**
208 * @tc.name: Dump08
209 * @tc.desc: Dump two param with '-d 1'
210 * @tc.type: FUNC
211 */
212 HWTEST_F(DisplayDumperTest, Dump08, TestSize.Level1)
213 {
214 sptr<DisplayDumper> displayDumper;
215 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
216 DisplayManagerService::GetInstance().abstractScreenController_,
217 DisplayManagerService::GetInstance().mutex_);
218 int fd = 8;
219 std::vector<std::u16string> args;
220 const std::u16string DUMP_DISPLAY = u"-d";
221 const std::u16string DUMP_NUMBER = u"1";
222 args.emplace_back(DUMP_DISPLAY);
223 args.emplace_back(DUMP_NUMBER);
224 DMError ret = displayDumper->Dump(fd, args);
225 ASSERT_TRUE(ret == DMError::DM_OK || ret == DMError::DM_ERROR_UNKNOWN);
226 }
227
228 /**
229 * @tc.name: Dump09
230 * @tc.desc: Dump two param with '-d -1'
231 * @tc.type: FUNC
232 */
233 HWTEST_F(DisplayDumperTest, Dump09, TestSize.Level1)
234 {
235 sptr<DisplayDumper> displayDumper;
236 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
237 DisplayManagerService::GetInstance().abstractScreenController_,
238 DisplayManagerService::GetInstance().mutex_);
239 int fd = 9;
240 std::vector<std::u16string> args;
241 const std::u16string DUMP_DISPLAY = u"-d";
242 const std::u16string DUMP_NUMBER = u"-1";
243 args.emplace_back(DUMP_DISPLAY);
244 args.emplace_back(DUMP_NUMBER);
245 DMError ret = displayDumper->Dump(fd, args);
246 ASSERT_TRUE(ret == DMError::DM_OK || ret == DMError::DM_ERROR_UNKNOWN);
247 }
248
249 /**
250 * @tc.name: Dump10
251 * @tc.desc: Dump three param with '-d -a 1'
252 * @tc.type: FUNC
253 */
254 HWTEST_F(DisplayDumperTest, Dump10, TestSize.Level1)
255 {
256 sptr<DisplayDumper> displayDumper;
257 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
258 DisplayManagerService::GetInstance().abstractScreenController_,
259 DisplayManagerService::GetInstance().mutex_);
260 int fd = 10;
261 std::vector<std::u16string> args;
262 const std::u16string DUMP_DISPLAY = u"-d";
263 const std::u16string DUMP_ALL = u"-a";
264 const std::u16string DUMP_NUMBER = u"1";
265 args.emplace_back(DUMP_DISPLAY);
266 args.emplace_back(DUMP_ALL);
267 args.emplace_back(DUMP_NUMBER);
268 DMError ret = displayDumper->Dump(fd, args);
269 ASSERT_TRUE(ret == DMError::DM_OK || ret == DMError::DM_ERROR_UNKNOWN);
270 }
271
272 /**
273 * @tc.name: IsValidDigitString01
274 * @tc.desc: IsValidDigitString "06w"
275 * @tc.type: FUNC
276 */
277 HWTEST_F(DisplayDumperTest, IsValidDigitString01, TestSize.Level1)
278 {
279 sptr<DisplayDumper> displayDumper;
280 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
281 DisplayManagerService::GetInstance().abstractScreenController_,
282 DisplayManagerService::GetInstance().mutex_);
283 std::string idStr = "06w";
284 bool ret = displayDumper->IsValidDigitString(idStr);
285 ASSERT_EQ(ret, false);
286 }
287
288 /**
289 * @tc.name: IsValidDigitString02
290 * @tc.desc: IsValidDigitString "96+"
291 * @tc.type: FUNC
292 */
293 HWTEST_F(DisplayDumperTest, IsValidDigitString02, TestSize.Level1)
294 {
295 sptr<DisplayDumper> displayDumper;
296 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
297 DisplayManagerService::GetInstance().abstractScreenController_,
298 DisplayManagerService::GetInstance().mutex_);
299 std::string idStr = "96+";
300 bool ret = displayDumper->IsValidDigitString(idStr);
301 ASSERT_EQ(ret, false);
302 }
303
304 /**
305 * @tc.name: IsValidDigitString03
306 * @tc.desc: IsValidDigitString empty
307 * @tc.type: FUNC
308 */
309 HWTEST_F(DisplayDumperTest, IsValidDigitString03, TestSize.Level1)
310 {
311 sptr<DisplayDumper> displayDumper;
312 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
313 DisplayManagerService::GetInstance().abstractScreenController_,
314 DisplayManagerService::GetInstance().mutex_);
315 std::string idStr;
316 bool ret = displayDumper->IsValidDigitString(idStr);
317 ASSERT_EQ(ret, false);
318 }
319
320 /**
321 * @tc.name: IsValidDigitString04
322 * @tc.desc: IsValidDigitString empty
323 * @tc.type: FUNC
324 */
325 HWTEST_F(DisplayDumperTest, IsValidDigitString04, TestSize.Level1)
326 {
327 sptr<DisplayDumper> displayDumper;
328 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
329 DisplayManagerService::GetInstance().abstractScreenController_,
330 DisplayManagerService::GetInstance().mutex_);
331 std::string idStr = "1909";
332 bool ret = displayDumper->IsValidDigitString(idStr);
333 EXPECT_EQ(ret, true);
334 }
335
336 /**
337 * @tc.name: DumpAllScreenInfo01
338 * @tc.desc: DumpAllScreenInfo
339 * @tc.type: FUNC
340 */
341 HWTEST_F(DisplayDumperTest, DumpAllScreenInfo01, TestSize.Level1)
342 {
343 sptr<DisplayDumper> displayDumper;
344 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
345 DisplayManagerService::GetInstance().abstractScreenController_,
346 DisplayManagerService::GetInstance().mutex_);
347 std::string dumpInfo;
348 displayDumper->DumpAllScreenInfo(dumpInfo);
349 ASSERT_NE(dumpInfo.size(), 0);
350 }
351
352 /**
353 * @tc.name: DumpScreenInfo01
354 * @tc.desc: DumpScreenInfo
355 * @tc.type: FUNC
356 */
357 HWTEST_F(DisplayDumperTest, DumpScreenInfo01, TestSize.Level1)
358 {
359 sptr<DisplayDumper> displayDumper;
360 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
361 DisplayManagerService::GetInstance().abstractScreenController_,
362 DisplayManagerService::GetInstance().mutex_);
363 sptr<AbstractScreenGroup> screenGroup = nullptr;
364 std::string dumpInfo;
365 DMError result = displayDumper->DumpScreenInfo(screenGroup, dumpInfo);
366 EXPECT_EQ(result, DMError::DM_ERROR_NULLPTR);
367 }
368
369 /**
370 * @tc.name: DumpScreenInfo02
371 * @tc.desc: DumpScreenInfo
372 * @tc.type: FUNC
373 */
374 HWTEST_F(DisplayDumperTest, DumpScreenInfo02, TestSize.Level1)
375 {
376 sptr<DisplayDumper> displayDumper;
377 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
378 DisplayManagerService::GetInstance().abstractScreenController_,
379 DisplayManagerService::GetInstance().mutex_);
380 std::string name = "testDisplay";
381 sptr<SupportedScreenModes> info = new SupportedScreenModes();
382 info->width_ = 100;
383 info->height_ = 200;
384 sptr<AbstractScreen> absScreen = new AbstractScreen(DisplayManagerService::GetInstance().abstractScreenController_,
385 name, 0, 0);
386 absScreen->activeIdx_ = 0;
387 absScreen->modes_.clear();
388 absScreen->modes_ = { { info } };
389 absScreen->groupDmsId_ = SCREEN_ID_INVALID;
390 sptr<AbstractScreenGroup> screenGroup = new AbstractScreenGroup(
391 DisplayManagerService::GetInstance().abstractScreenController_, 0, 0, name, ScreenCombination::SCREEN_ALONE);
392 std::string dumpInfo;
393 DMError result = displayDumper->DumpScreenInfo(screenGroup, dumpInfo);
394 EXPECT_EQ(result, DMError::DM_OK);
395 }
396
397 /**
398 * @tc.name: TransferTypeToString
399 * @tc.desc: TransferTypeToString
400 * @tc.type: FUNC
401 */
402 HWTEST_F(DisplayDumperTest, TransferTypeToString, TestSize.Level1)
403 {
404 sptr<DisplayDumper> displayDumper;
405 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
406 DisplayManagerService::GetInstance().abstractScreenController_,
407 DisplayManagerService::GetInstance().mutex_);
408 ScreenType type = ScreenType::REAL;
409 EXPECT_STREQ(displayDumper->TransferTypeToString(type).c_str(), "REAL");
410
411 type = ScreenType::VIRTUAL;
412 EXPECT_STREQ(displayDumper->TransferTypeToString(type).c_str(), "VIRTUAL");
413
414 type = ScreenType::UNDEFINED;
415 EXPECT_STREQ(displayDumper->TransferTypeToString(type).c_str(), "UNDEFINED");
416 }
417
418 /**
419 * @tc.name: GetScreenInfo01
420 * @tc.desc: GetScreenInfo
421 * @tc.type: FUNC
422 */
423 HWTEST_F(DisplayDumperTest, GetScreenInfo01, TestSize.Level1)
424 {
425 sptr<DisplayDumper> displayDumper;
426 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
427 DisplayManagerService::GetInstance().abstractScreenController_,
428 DisplayManagerService::GetInstance().mutex_);
429 std::ostringstream oss;
430 displayDumper->GetScreenInfo(nullptr, oss);
431 std::string result = oss.str();
432 ASSERT_EQ(result.size(), 0);
433 }
434
435 /**
436 * @tc.name: GetScreenInfo02
437 * @tc.desc: GetScreenInfo
438 * @tc.type: FUNC
439 */
440 HWTEST_F(DisplayDumperTest, GetScreenInfo02, TestSize.Level1)
441 {
442 sptr<DisplayDumper> displayDumper;
443 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
444 DisplayManagerService::GetInstance().abstractScreenController_,
445 DisplayManagerService::GetInstance().mutex_);
446 std::ostringstream oss;
447 std::string name = "testDisplay";
448 sptr<SupportedScreenModes> info = new SupportedScreenModes();
449 info->width_ = 100;
450 info->height_ = 200;
451 sptr<AbstractScreen> absScreen = new AbstractScreen(DisplayManagerService::GetInstance().abstractScreenController_,
452 name, 0, 0);
453 absScreen->activeIdx_ = 0;
454 absScreen->modes_.clear();
455 absScreen->modes_ = { { info } };
456 displayDumper->GetScreenInfo(absScreen, oss);
457 std::string result = oss.str();
458 ASSERT_EQ(result.size(), 165);
459 }
460
461 /**
462 * @tc.name: GetDisplayInfo01
463 * @tc.desc: GetDisplayInfo
464 * @tc.type: FUNC
465 */
466 HWTEST_F(DisplayDumperTest, GetDisplayInfo01, TestSize.Level1)
467 {
468 sptr<DisplayDumper> displayDumper;
469 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
470 DisplayManagerService::GetInstance().abstractScreenController_,
471 DisplayManagerService::GetInstance().mutex_);
472 std::ostringstream oss;
473 displayDumper->GetDisplayInfo(nullptr, oss);
474 std::string result = oss.str();
475 ASSERT_EQ(result.size(), 0);
476 }
477
478 /**
479 * @tc.name: GetDisplayInfo02
480 * @tc.desc: GetDisplayInfo
481 * @tc.type: FUNC
482 */
483 HWTEST_F(DisplayDumperTest, GetDisplayInfo02, TestSize.Level1)
484 {
485 sptr<DisplayDumper> displayDumper;
486 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
487 DisplayManagerService::GetInstance().abstractScreenController_,
488 DisplayManagerService::GetInstance().mutex_);
489 std::ostringstream oss;
490
491 std::string name = "testDisplay";
492 sptr<SupportedScreenModes> info = new SupportedScreenModes();
493 info->width_ = 100;
494 info->height_ = 200;
495 sptr<AbstractScreen> absScreen = new AbstractScreen(DisplayManagerService::GetInstance().abstractScreenController_,
496 name, 0, 0);
497 absScreen->activeIdx_ = 0;
498 absScreen->modes_.clear();
499 absScreen->modes_ = { { info } };
500 sptr<AbstractDisplay> absDisplay = new AbstractDisplay(0, info, absScreen);
501 displayDumper->GetDisplayInfo(absDisplay, oss);
502 std::string result = oss.str();
503
504 EXPECT_EQ(result.size(), 109);
505 }
506
507 /**
508 * @tc.name: ShowIllegalArgsInfo
509 * @tc.desc: ShowIllegalArgsInfo
510 * @tc.type: FUNC
511 */
512 HWTEST_F(DisplayDumperTest, ShowIllegalArgsInfo, TestSize.Level1)
513 {
514 sptr<DisplayDumper> displayDumper;
515 displayDumper = new DisplayDumper(DisplayManagerService::GetInstance().abstractDisplayController_,
516 DisplayManagerService::GetInstance().abstractScreenController_,
517 DisplayManagerService::GetInstance().mutex_);
518
519 std::string dumpInfo = "DTtest";
520 DMError errCode = DMError::DM_OK;
521 displayDumper->ShowIllegalArgsInfo(dumpInfo, errCode);
522
523 EXPECT_NE(displayDumper, nullptr);
524 }
525 }
526 }
527 }