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 <gtest/gtest.h>
17 #include "display.h"
18 #include "display_info.h"
19 #include "oh_display_capture.h"
20 #include "oh_display_manager.h"
21 #include "oh_display_manager_inner.h"
22 #include "pixelmap_native_impl.h"
23 #include "scene_board_judgement.h"
24
25 using namespace testing;
26 using namespace testing::ext;
27
28 namespace OHOS {
29 namespace Rosen {
30 class OHDisplayManagerTest : public testing::Test {
31 public:
32 static void SetUpTestCase();
33 static void TearDownTestCase();
34 static void FoldDisplayModeChangeCallback(NativeDisplayManager_FoldDisplayMode displayMode);
35 static void DisplayChangeCallback(uint64_t displayId);
36 static void AvailableAreaChangeCallback(uint64_t displayId);
37 static void DisplayAddCallback(uint64_t displayId);
38 static void DisplayRemoveCallback(uint64_t displayId);
39 void SetUp() override;
40 void TearDown() override;
41 };
42
43
SetUpTestCase()44 void OHDisplayManagerTest::SetUpTestCase()
45 {
46 }
47
TearDownTestCase()48 void OHDisplayManagerTest::TearDownTestCase()
49 {
50 }
51
SetUp()52 void OHDisplayManagerTest::SetUp()
53 {
54 }
55
TearDown()56 void OHDisplayManagerTest::TearDown()
57 {
58 }
59
FoldDisplayModeChangeCallback(NativeDisplayManager_FoldDisplayMode displayMode)60 void OHDisplayManagerTest::FoldDisplayModeChangeCallback(NativeDisplayManager_FoldDisplayMode displayMode)
61 {
62 }
63
DisplayChangeCallback(uint64_t displayId)64 void OHDisplayManagerTest::DisplayChangeCallback(uint64_t displayId)
65 {
66 }
67
AvailableAreaChangeCallback(uint64_t displayId)68 void OHDisplayManagerTest::AvailableAreaChangeCallback(uint64_t displayId)
69 {
70 }
71
DisplayAddCallback(uint64_t displayId)72 void OHDisplayManagerTest::DisplayAddCallback(uint64_t displayId)
73 {
74 }
75
DisplayRemoveCallback(uint64_t displayId)76 void OHDisplayManagerTest::DisplayRemoveCallback(uint64_t displayId)
77 {
78 }
79 namespace {
80
81 /**
82 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayId
83 * @tc.desc: displayId == nullptr
84 * @tc.type: FUNC
85 */
86 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayId01, TestSize.Level1)
87 {
88 uint64_t *displayId = nullptr;
89 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayId(displayId);
90 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM);
91 }
92
93 /**
94 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayId
95 * @tc.desc: displayId != nullptr
96 * @tc.type: FUNC
97 */
98 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayId02, TestSize.Level1)
99 {
100 uint64_t testParm = 4000;
101 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayId(&testParm);
102 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
103 }
104
105 /**
106 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayWidth
107 * @tc.desc: displayWidth == nullptr
108 * @tc.type: FUNC
109 */
110 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayWidth01, TestSize.Level1)
111 {
112 int32_t *displayWidth = nullptr;
113 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayWidth(displayWidth);
114 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM);
115 }
116
117 /**
118 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayWidth
119 * @tc.desc: displayWidth != nullptr
120 * @tc.type: FUNC
121 */
122 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayWidth02, TestSize.Level1)
123 {
124 int32_t testWidth = 200;
125 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayWidth(&testWidth);
126 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
127 }
128
129 /**
130 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayHeight
131 * @tc.desc: displayHeight == nullptr
132 * @tc.type: FUNC
133 */
134 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayHeight01, TestSize.Level1)
135 {
136 int32_t *displayHeight = nullptr;
137 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayHeight(displayHeight);
138 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM);
139 }
140
141 /**
142 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayHeight
143 * @tc.desc: displayHeight != nullptr
144 * @tc.type: FUNC
145 */
146 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayHeight02, TestSize.Level1)
147 {
148 int32_t testHeight = 200;
149 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayHeight(&testHeight);
150 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
151 }
152
153 /**
154 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayRotation
155 * @tc.desc: displayRotation == nullptr
156 * @tc.type: FUNC
157 */
158 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayRotation01, TestSize.Level1)
159 {
160 NativeDisplayManager_Rotation *displayRotation = nullptr;
161 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayRotation(displayRotation);
162 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM);
163 }
164
165 /**
166 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayRotation
167 * @tc.desc: displayRotation != nullptr
168 * @tc.type: FUNC
169 */
170 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayRotation02, TestSize.Level1)
171 {
172 NativeDisplayManager_Rotation testRotation = NativeDisplayManager_Rotation::DISPLAY_MANAGER_ROTATION_180;
173 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayRotation(&testRotation);
174 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
175 }
176
177 /**
178 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayOrientation
179 * @tc.desc: displayOrientation == nullptr
180 * @tc.type: FUNC
181 */
182 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayOrientation01, TestSize.Level1)
183 {
184 NativeDisplayManager_Orientation *displayOrientation = nullptr;
185 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayOrientation(displayOrientation);
186 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM);
187 }
188
189 /**
190 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayOrientation
191 * @tc.desc: displayOrientation != nullptr
192 * @tc.type: FUNC
193 */
194 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayOrientation02, TestSize.Level1)
195 {
196 NativeDisplayManager_Orientation testOrientation = NativeDisplayManager_Orientation::DISPLAY_MANAGER_LANDSCAPE;
197 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayOrientation(&testOrientation);
198 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
199 }
200
201 /**
202 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayVirtualPixelRatio
203 * @tc.desc: virtualPixel == nullptr
204 * @tc.type: FUNC
205 */
206 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayVirtualPixelRatio01,
207 TestSize.Level1)
208 {
209 float *virtualPixel = nullptr;
210 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayVirtualPixelRatio(virtualPixel);
211 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM);
212 }
213
214 /**
215 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayVirtualPixelRatio
216 * @tc.desc: virtualPixel != nullptr
217 * @tc.type: FUNC
218 */
219 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayVirtualPixelRatio02,
220 TestSize.Level1)
221 {
222 float testPixel = 3.14;
223 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayVirtualPixelRatio(&testPixel);
224 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
225 }
226
227 /**
228 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayRefreshRate
229 * @tc.desc: refreshRate == nullptr
230 * @tc.type: FUNC
231 */
232 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayRefreshRate01, TestSize.Level1)
233 {
234 uint32_t *refreshRate = nullptr;
235 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayRefreshRate(refreshRate);
236 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM);
237 }
238
239 /**
240 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayRefreshRate
241 * @tc.desc: refreshRate != nullptr
242 * @tc.type: FUNC
243 */
244 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayRefreshRate02, TestSize.Level1)
245 {
246 uint32_t testRate = 60;
247 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayRefreshRate(&testRate);
248 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
249 }
250
251 /**
252 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayDensityDpi
253 * @tc.desc: densityDpi == nullptr
254 * @tc.type: FUNC
255 */
256 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayDensityDpi01, TestSize.Level1)
257 {
258 int32_t *densityDpi = nullptr;
259 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayDensityDpi(densityDpi);
260 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM);
261 }
262
263 /**
264 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayDensityDpi
265 * @tc.desc: densityDpi != nullptr
266 * @tc.type: FUNC
267 */
268 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayDensityDpi02, TestSize.Level1)
269 {
270 int32_t testDpi = 160;
271 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayDensityDpi(&testDpi);
272 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
273 }
274
275 /**
276 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayDensityPixels
277 * @tc.desc: densityPixels == nullptr
278 * @tc.type: FUNC
279 */
280 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayDensityPixels01, TestSize.Level1)
281 {
282 float *densityPixels = nullptr;
283 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayDensityPixels(densityPixels);
284 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM);
285 }
286
287 /**
288 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayDensityPixels
289 * @tc.desc: densityPixels != nullptr
290 * @tc.type: FUNC
291 */
292 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayDensityPixels02, TestSize.Level1)
293 {
294 float testPixels = 1.0;
295 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayDensityPixels(&testPixels);
296 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
297 }
298
299 /**
300 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayScaledDensity
301 * @tc.desc: scaledDensity == nullptr
302 * @tc.type: FUNC
303 */
304 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayScaledDensity01, TestSize.Level1)
305 {
306 float *scaledDensity = nullptr;
307 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayScaledDensity(scaledDensity);
308 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM);
309 }
310
311 /**
312 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayScaledDensity
313 * @tc.desc: scaledDensity != nullptr
314 * @tc.type: FUNC
315 */
316 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayScaledDensity02, TestSize.Level1)
317 {
318 float testDensity = 1.0;
319 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayScaledDensity(&testDensity);
320 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
321 }
322
323 /**
324 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayDensityXdpi
325 * @tc.desc: xDpi == nullptr
326 * @tc.type: FUNC
327 */
328 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayDensityXdpi01, TestSize.Level1)
329 {
330 float *xDpi = nullptr;
331 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayDensityXdpi(xDpi);
332 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM);
333 }
334
335 /**
336 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayDensityXdpi
337 * @tc.desc: xDpi != nullptr
338 * @tc.type: FUNC
339 */
340 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayDensityXdpi02, TestSize.Level1)
341 {
342 float testXDpi = 2.0;
343 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayDensityXdpi(&testXDpi);
344 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
345 }
346
347 /**
348 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayDensityYdpi
349 * @tc.desc: yDpi == nullptr
350 * @tc.type: FUNC
351 */
352 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayDensityYdpi01, TestSize.Level1)
353 {
354 float *yDpi = nullptr;
355 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayDensityYdpi(yDpi);
356 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM);
357 }
358
359 /**
360 * @tc.name: OH_NativeDisplayManager_GetDefaultDisplayDensityYdpi
361 * @tc.desc: yDpi != nullptr
362 * @tc.type: FUNC
363 */
364 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDefaultDisplayDensityYdpi02, TestSize.Level1)
365 {
366 float testYDpi = 2.0;
367 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDefaultDisplayDensityYdpi(&testYDpi);
368 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
369 }
370
371 /**
372 * @tc.name: OH_NativeDisplayManager_GetFoldDisplayMode
373 * @tc.desc: foldDisplayMode == nullptr
374 * @tc.type: FUNC
375 */
376 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetFoldDisplayMode01, TestSize.Level1)
377 {
378 NativeDisplayManager_FoldDisplayMode *foldDisplayMode = nullptr;
379 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetFoldDisplayMode(foldDisplayMode);
380 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_INVALID_PARAM);
381 }
382
383 /**
384 * @tc.name: OH_NativeDisplayManager_GetFoldDisplayMode
385 * @tc.desc: foldDisplayMode != nullptr
386 * @tc.type: FUNC
387 */
388 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetFoldDisplayMode02, TestSize.Level1)
389 {
390 NativeDisplayManager_FoldDisplayMode testDisplayMode =
391 NativeDisplayManager_FoldDisplayMode::DISPLAY_MANAGER_FOLD_DISPLAY_MODE_MAIN;
392 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetFoldDisplayMode(&testDisplayMode);
393 if (OH_NativeDisplayManager_IsFoldable()) {
394 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
395 } else {
396 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_DEVICE_NOT_SUPPORTED);
397 }
398 }
399
400 /**
401 * @tc.name: FoldDisplayModeChangeListener
402 * @tc.desc: register and unregister
403 * @tc.type: FUNC
404 */
405 HWTEST_F(OHDisplayManagerTest, FoldDisplayModeChangeListener, TestSize.Level1)
406 {
407 uint32_t testIndex;
408 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_RegisterFoldDisplayModeChangeListener(
409 FoldDisplayModeChangeCallback, &testIndex);
410 if (OH_NativeDisplayManager_IsFoldable()) {
411 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
412 NativeDisplayManager_ErrorCode ret1 = OH_NativeDisplayManager_UnregisterFoldDisplayModeChangeListener(
413 testIndex);
414 EXPECT_EQ(ret1, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
415 } else {
416 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_DEVICE_NOT_SUPPORTED);
417 }
418 }
419
420 /**
421 * @tc.name: DisplayChangeListener
422 * @tc.desc: register and unregister
423 * @tc.type: FUNC
424 */
425 HWTEST_F(OHDisplayManagerTest, DisplayChangeListener, TestSize.Level1)
426 {
427 uint32_t testIndex;
428 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_RegisterDisplayChangeListener(
429 DisplayChangeCallback, &testIndex);
430 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
431 ret = OH_NativeDisplayManager_UnregisterDisplayChangeListener(testIndex);
432 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
433 }
434
435 /**
436 * @tc.name: AllDisplays
437 * @tc.desc: create and destroy
438 * @tc.type: FUNC
439 */
440 HWTEST_F(OHDisplayManagerTest, CreateAndDestroyAllDisplays, TestSize.Level1)
441 {
442 NativeDisplayManager_DisplaysInfo *displayInfo = nullptr;
443 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_CreateAllDisplays(&displayInfo);
444 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
445 ASSERT_NE(displayInfo, nullptr);
446
447 OH_NativeDisplayManager_DestroyAllDisplays(displayInfo);
448 }
449
450 /**
451 * @tc.name: CreateAndDestroyDisplayById
452 * @tc.desc: CreateAndDestroyDisplayById
453 * @tc.type: FUNC
454 */
455 HWTEST_F(OHDisplayManagerTest, CreateAndDestroyDisplayById, TestSize.Level1)
456 {
457 uint32_t testDisplayId = 0;
458 NativeDisplayManager_DisplayInfo *testPtr = nullptr;
459 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_CreateDisplayById(testDisplayId, &testPtr);
460 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
461
462 OH_NativeDisplayManager_DestroyDisplay(testPtr);
463 }
464
465 /**
466 * @tc.name: CreatePrimaryDisplay
467 * @tc.desc: CreatePrimaryDisplay
468 * @tc.type: FUNC
469 */
470 HWTEST_F(OHDisplayManagerTest, CreatePrimaryDisplay, TestSize.Level1)
471 {
472 NativeDisplayManager_DisplayInfo *testPtr = nullptr;
473 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_CreatePrimaryDisplay(&testPtr);
474 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
475 }
476
477 /**
478 * @tc.name: CaptureScreenPixelmap
479 * @tc.desc: CaptureScreenPixelmap
480 * @tc.type: FUNC
481 */
482 HWTEST_F(OHDisplayManagerTest, CaptureScreenPixelmap, TestSize.Level1)
483 {
484 uint32_t testDisplayId = 1001;
485 OH_PixelmapNative *pixelMap = nullptr;
486 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_CaptureScreenPixelmap(testDisplayId, &pixelMap);
487 EXPECT_NE(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_NO_PERMISSION);
488 }
489
490 /**
491 * @tc.name: AvailableAreaChangeListener
492 * @tc.desc: register and unregister
493 * @tc.type: FUNC
494 */
495 HWTEST_F(OHDisplayManagerTest, AvailableAreaChangeListener, TestSize.Level1)
496 {
497 uint32_t testIndex;
498 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_RegisterAvailableAreaChangeListener(
499 AvailableAreaChangeCallback, &testIndex);
500 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
501 ret = OH_NativeDisplayManager_UnregisterAvailableAreaChangeListener(testIndex);
502 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
503 }
504
505 /**
506 * @tc.name: AvailableAreaChangeListener
507 * @tc.desc: register and unregister
508 * @tc.type: FUNC
509 */
510 HWTEST_F(OHDisplayManagerTest, AvailableAreaChangeListener02, TestSize.Level1)
511 {
512 uint32_t* testIndex = nullptr;
513 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_RegisterAvailableAreaChangeListener(
514 AvailableAreaChangeCallback, testIndex);
515 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_ILLEGAL_PARAM);
516 }
517
518 /**
519 * @tc.name: DisplayAddListener
520 * @tc.desc: register and unregister
521 * @tc.type: FUNC
522 */
523 HWTEST_F(OHDisplayManagerTest, DisplayAddListener, TestSize.Level1)
524 {
525 uint32_t testIndex;
526 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_RegisterDisplayAddListener(
527 DisplayAddCallback, &testIndex);
528 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
529 ret = OH_NativeDisplayManager_UnregisterDisplayAddListener(testIndex);
530 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
531 }
532
533 /**
534 * @tc.name: DisplayAddListener
535 * @tc.desc: register and unregister
536 * @tc.type: FUNC
537 */
538 HWTEST_F(OHDisplayManagerTest, DisplayAddListener02, TestSize.Level1)
539 {
540 uint32_t* testIndex = nullptr;
541 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_RegisterDisplayAddListener(
542 DisplayAddCallback, testIndex);
543 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_ILLEGAL_PARAM);
544 }
545
546 /**
547 * @tc.name: DisplayRemoveListener
548 * @tc.desc: register and unregister
549 * @tc.type: FUNC
550 */
551 HWTEST_F(OHDisplayManagerTest, DisplayRemoveListener, TestSize.Level1)
552 {
553 uint32_t testIndex;
554 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_RegisterDisplayRemoveListener(
555 DisplayRemoveCallback, &testIndex);
556 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
557 ret = OH_NativeDisplayManager_UnregisterDisplayRemoveListener(testIndex);
558 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
559 }
560
561 /**
562 * @tc.name: DisplayRemoveListener
563 * @tc.desc: register and unregister
564 * @tc.type: FUNC
565 */
566 HWTEST_F(OHDisplayManagerTest, DisplayRemoveListener02, TestSize.Level1)
567 {
568 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
569 return;
570 }
571 uint32_t* testIndex = nullptr;
572 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_RegisterDisplayRemoveListener(
573 DisplayRemoveCallback, testIndex);
574 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
575 }
576
577 /**
578 * @tc.name: OH_NativeDisplayManager_CreateAvailableArea
579
580 * @tc.desc: availableArea
581 * @tc.type: FUNC
582 */
583 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_CreateAvailableArea01, TestSize.Level1)
584 {
585 uint64_t testId = 0;
586 NativeDisplayManager_Rect *availableArea;
587 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_CreateAvailableArea(testId, &availableArea);
588 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
589 if (ret == NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK) {
590 ret = OH_NativeDisplayManager_DestroyAvailableArea(availableArea);
591 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
592 }
593 }
594
595 /**
596 * @tc.name: OH_NativeDisplayManager_CreateAvailableArea02
597
598 * @tc.desc: availableArea
599 * @tc.type: FUNC
600 */
601 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_CreateAvailableArea02, TestSize.Level1)
602 {
603 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
604 return;
605 }
606 uint64_t testId = 0;
607 NativeDisplayManager_Rect *availableArea = nullptr;
608 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_CreateAvailableArea(testId, &availableArea);
609 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
610 if (ret == NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK) {
611 ret = OH_NativeDisplayManager_DestroyAvailableArea(availableArea);
612 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_ILLEGAL_PARAM);
613 }
614 }
615
616 /**
617 * @tc.name: OH_NativeDisplayManager_CreateAvailableArea03
618
619 * @tc.desc: availableArea
620 * @tc.type: FUNC
621 */
622 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_CreateAvailableArea03, TestSize.Level1)
623 {
624 uint64_t testId = 0;
625 NativeDisplayManager_Rect **availableArea = nullptr;
626 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_CreateAvailableArea(testId, availableArea);
627 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_ILLEGAL_PARAM);
628 }
629
630 /**
631 * @tc.name: OH_NativeDisplayManager_CreateAvailableArea04
632
633 * @tc.desc: availableArea
634 * @tc.type: FUNC
635 */
636 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_CreateAvailableArea04, TestSize.Level1)
637 {
638 uint64_t testId = -1;
639 NativeDisplayManager_Rect *availableArea = nullptr;
640 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_CreateAvailableArea(testId, &availableArea);
641 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_ILLEGAL_PARAM);
642 }
643
644 /**
645 * @tc.name: OH_NativeDisplayManager_DestroyAvailableArea01
646 * @tc.desc: availableArea = nullptr
647 * @tc.type: FUNC
648 */
649 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_DestroyAvailableArea01, TestSize.Level1)
650 {
651 NativeDisplayManager_Rect *availableArea = nullptr;
652 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_DestroyAvailableArea(availableArea);
653 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_ILLEGAL_PARAM);
654 }
655
656 /**
657 * @tc.name: OH_NativeDisplayManager_GetDisplaySourceMode
658 * @tc.desc: sourcemode
659 * @tc.type: FUNC
660 */
661 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDisplaySourceMode01, TestSize.Level1)
662 {
663 uint64_t testIndex = 0;
664 NativeDisplayManager_SourceMode sourceMode = DISPLAY_SOURCE_MODE_NONE;
665 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDisplaySourceMode(testIndex, &sourceMode);
666 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
667 }
668
669 /**
670 * @tc.name: OH_NativeDisplayManager_GetDisplaySourceMode
671 * @tc.desc: sourcemode == null
672 * @tc.type: FUNC
673 */
674 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDisplaySourceMode02, TestSize.Level1)
675 {
676 uint64_t testId = 0;
677 NativeDisplayManager_SourceMode *sourceMode = nullptr;
678 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDisplaySourceMode(testId, sourceMode);
679 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_ILLEGAL_PARAM);
680 }
681
682 /**
683 * @tc.name: OH_NativeDisplayManager_GetDisplaySourceMode_03
684 * @tc.desc: sourcemode == null
685 * @tc.type: FUNC
686 */
687 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDisplaySourceMode03, TestSize.Level1)
688 {
689 uint64_t testId = -1;
690 NativeDisplayManager_SourceMode sourceMode = DISPLAY_SOURCE_MODE_NONE;
691 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDisplaySourceMode(testId, &sourceMode);
692 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_ILLEGAL_PARAM);
693 }
694
695 /**
696 * @tc.name: OH_NativeDisplayManager_GetDisplayPosition
697 * @tc.desc: x,y != nullptr
698 * @tc.type: FUNC
699 */
700 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDisplayPosition01, TestSize.Level1)
701 {
702 uint64_t testId = 0;
703 int32_t x = -1;
704 int32_t y = -1;
705 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDisplayPosition(testId, &x, &y);
706 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_OK);
707 EXPECT_NE(x, -1);
708 EXPECT_NE(y, -1);
709 }
710
711 /**
712 * @tc.name: OH_NativeDisplayManager_GetDisplayPosition
713 * @tc.desc: x = nullptr y!=nullptr
714 * @tc.type: FUNC
715 */
716 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDisplayPosition02, TestSize.Level1)
717 {
718 uint64_t testId = 0;
719 int32_t *x = nullptr;
720 int32_t y;
721 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDisplayPosition(testId, x, &y);
722 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_ILLEGAL_PARAM);
723 }
724
725 /**
726 * @tc.name: OH_NativeDisplayManager_GetDisplayPosition
727 * @tc.desc: x != nullptr y=nullptr
728 * @tc.type: FUNC
729 */
730 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDisplayPosition03, TestSize.Level1)
731 {
732 uint64_t testId = 0;
733 int32_t x;
734 int32_t *y = nullptr;
735 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDisplayPosition(testId, &x, y);
736 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_ILLEGAL_PARAM);
737 }
738
739 /**
740 * @tc.name: OH_NativeDisplayManager_GetDisplayPosition
741 * @tc.desc: x = nullptr y=nullptr
742 * @tc.type: FUNC
743 */
744 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDisplayPosition04, TestSize.Level1)
745 {
746 uint64_t testId = 0;
747 int32_t *x = nullptr;
748 int32_t *y = nullptr;
749 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDisplayPosition(testId, x, y);
750 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_ILLEGAL_PARAM);
751 }
752
753 /**
754 * @tc.name: OH_NativeDisplayManager_GetDisplayPosition_EXTEND
755 * @tc.desc: x,y
756 * @tc.type: FUNC
757 */
758 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDisplayPosition05, TestSize.Level1)
759 {
760 uint64_t testId = 11; // 扩展屏
761 int32_t x = -1;
762 int32_t y = -1;
763 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDisplayPosition(testId, &x, &y);
764 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_SYSTEM_ABNORMAL);
765 }
766
767 /**
768 * @tc.name: OH_NativeDisplayManager_GetDisplayPosition_ERROR
769 * @tc.desc: x,y
770 * @tc.type: FUNC
771 */
772 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDisplayPosition06, TestSize.Level1)
773 {
774 if (!SceneBoardJudgement::IsSceneBoardEnabled()) {
775 return;
776 }
777 uint64_t testId = 2; // 异常屏幕
778 int32_t x = -1;
779 int32_t y = -1;
780 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDisplayPosition(testId, &x, &y);
781 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_ILLEGAL_PARAM);
782 }
783
784 /**
785 * @tc.name: OH_NativeDisplayManager_GetDisplayPosition_07
786 * @tc.desc: x,y
787 * @tc.type: FUNC
788 */
789 HWTEST_F(OHDisplayManagerTest, OH_NativeDisplayManager_GetDisplayPosition07, TestSize.Level1)
790 {
791 uint64_t testId = -1; // 异常屏幕
792 int32_t x = -1;
793 int32_t y = -1;
794 NativeDisplayManager_ErrorCode ret = OH_NativeDisplayManager_GetDisplayPosition(testId, &x, &y);
795 EXPECT_EQ(ret, NativeDisplayManager_ErrorCode::DISPLAY_MANAGER_ERROR_ILLEGAL_PARAM);
796 }
797
798 }
799 } // namespace Rosen
800 } // namespace OHOS