1 /*
2 * Copyright (c) 2025 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 "display_service_test.h"
17 #include "display_log.h"
18 #include "display_mgr_errors.h"
19 #include "display_power_mgr_client.h"
20 #include "ipc_object_stub.h"
21 #include "power_state_machine_info.h"
22 #ifdef HAS_HIVIEWDFX_HISYSEVENT_PART
23 #include <hisysevent.h>
24 #endif
25 #include <memory>
26 #include <unistd.h>
27 #include "display_brightness_callback_stub.h"
28 #include "display_power_mgr_service.h"
29
30 using namespace testing::ext;
31 #ifdef HAS_HIVIEWDFX_HISYSEVENT_PART
32 using namespace OHOS::HiviewDFX;
33 #endif
34 using namespace OHOS::PowerMgr;
35 using namespace OHOS::DisplayPowerMgr;
36 using namespace OHOS;
37 using namespace std;
38
39 namespace {
40 static constexpr uint32_t BRIGHTNESS_SETTING_VALUE = 50;
41 static constexpr uint32_t BRIGHTNESS_OVERRIDE_VALUE = 100;
42 static constexpr uint32_t BRIGHTNESS_DURATION = 0;
43 static constexpr uint32_t BRIGHTNESS_MIN_VALUE = 1;
44 static constexpr uint32_t BRIGHTNESS_MAX_VALUE = 255;
45 static constexpr uint32_t BRIGHTNESS_NONE_VALUE = 0;
46 static constexpr uint32_t DISPLAY_ID = 0;
47 static constexpr uint32_t DISPLAY_MAIN_ID = 0;
48 static constexpr uint32_t DISPLAY_INVALID_ID = 211;
49 static constexpr uint32_t REASON = 0;
50 static constexpr int32_t BRIGHTNESS_ADJUST_VALUE = 150;
51 static constexpr int32_t TIMEOUT_MS = 500;
52 static constexpr int32_t INVALID_TIMEOUT_MS = 0;
53 static constexpr double DISCOUNT_VALUE = 0.30;
54 static constexpr uint32_t SET_SUCC = 1;
55 static constexpr uint32_t MAX_BRIGHTNESS_SET = 125;
56 static constexpr uint32_t TEST_MODE = 1;
57 static constexpr uint32_t DEFAULT_DURATION = 500;
58 static const uint32_t OVERRIDE_DELAY_TIME = 200;
59 static constexpr int32_t DEFAULT_VALUE = -1;
60 static constexpr uint32_t BRIGHTNESS_OFF = 0;
61 static const uint32_t TEST_DELAY_TIME_UNSET = 0;
62 static constexpr uint32_t DEFAULT_WAITING_TIME = 1200000;
63 sptr<DisplayPowerMgrService> g_service;
64 } // namespace
65
SetUpTestCase()66 void DisplayServiceTest::SetUpTestCase()
67 {
68 g_service = DelayedSpSingleton<DisplayPowerMgrService>::GetInstance();
69 g_service->Init();
70 }
71
TearDownTestCase()72 void DisplayServiceTest::TearDownTestCase()
73 {
74 g_service->Deinit();
75 g_service->Reset();
76 }
77
DisplayServiceInnerTestFunc()78 void DisplayServiceTest::DisplayServiceInnerTestFunc()
79 {
80 EXPECT_TRUE(g_service->SetDisplayStateInner(DISPLAY_ID, DisplayPowerMgr::DisplayState::DISPLAY_ON,
81 REASON));
82 EXPECT_EQ(DisplayPowerMgr::DisplayState::DISPLAY_ON, g_service->GetDisplayStateInner(DISPLAY_ID));
83 auto ret = g_service->GetDisplayIdsInner();
84 EXPECT_TRUE(ret.size() != 0);
85 EXPECT_EQ(DISPLAY_MAIN_ID, g_service->GetMainDisplayIdInner());
86 EXPECT_TRUE(g_service->SetBrightnessInner(BRIGHTNESS_SETTING_VALUE, DISPLAY_ID, false));
87 EXPECT_TRUE(g_service->DiscountBrightnessInner(DISCOUNT_VALUE, DISPLAY_ID));
88 EXPECT_TRUE(g_service->OverrideBrightnessInner(BRIGHTNESS_OVERRIDE_VALUE, DISPLAY_ID));
89 EXPECT_TRUE(g_service->RestoreBrightnessInner(DISPLAY_MAIN_ID));
90 EXPECT_NE(BRIGHTNESS_NONE_VALUE, g_service->GetBrightnessInner(DISPLAY_ID));
91 EXPECT_NE(BRIGHTNESS_NONE_VALUE, g_service->GetDefaultBrightnessInner());
92 EXPECT_EQ(BRIGHTNESS_MAX_VALUE, g_service->GetMaxBrightnessInner());
93 EXPECT_EQ(BRIGHTNESS_MIN_VALUE, g_service->GetMinBrightnessInner());
94 g_service->AdjustBrightnessInner(DISPLAY_MAIN_ID, BRIGHTNESS_ADJUST_VALUE, BRIGHTNESS_DURATION);
95 g_service->AutoAdjustBrightnessInner(false);
96 EXPECT_FALSE(g_service->IsAutoAdjustBrightnessInner());
97 EXPECT_FALSE(g_service->BoostBrightnessInner(INVALID_TIMEOUT_MS, DISPLAY_ID));
98 EXPECT_FALSE(g_service->CancelBoostBrightnessInner(DISPLAY_INVALID_ID));
99 EXPECT_TRUE(g_service->SetDisplayStateInner(DISPLAY_ID, DisplayPowerMgr::DisplayState::DISPLAY_OFF,
100 REASON));
101 EXPECT_EQ(DisplayPowerMgr::DisplayState::DISPLAY_OFF, g_service->GetDisplayStateInner(DISPLAY_ID));
102 }
103
OnDisplayStateChanged(uint32_t displayId,DisplayPowerMgr::DisplayState state,uint32_t reason)104 void DisplayServiceTest::DisplayPowerMgrTestCallback::OnDisplayStateChanged(
105 uint32_t displayId, DisplayPowerMgr::DisplayState state, uint32_t reason)
106 {
107 DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrTestCallback::OnDisplayStateChangedStub");
108 }
109
110 namespace {
111 /**
112 * @tc.name: DisplayServiceInnerTest001
113 * @tc.desc: test DisplayPowerMgrService function
114 * @tc.type: FUNC
115 * @tc.require:
116 */
117 HWTEST_F(DisplayServiceTest, DisplayServiceInnerTest001, TestSize.Level1)
118 {
119 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceInnerTest001 function start!");
120 const int sleepTime = DEFAULT_WAITING_TIME;
121 usleep(sleepTime);
122 EXPECT_TRUE(g_service != nullptr);
123 DisplayServiceTest::DisplayServiceInnerTestFunc();
124 EXPECT_NE(BRIGHTNESS_NONE_VALUE, g_service->GetDeviceBrightnessInner(DISPLAY_ID));
125 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceInnerTest001 function end!");
126 }
127
128 /**
129 * @tc.name: DisplayServiceInnerTest002
130 * @tc.desc: test DisplayPowerMgrService function
131 * @tc.type: FUNC
132 * @tc.require:
133 */
134 HWTEST_F(DisplayServiceTest, DisplayServiceInnerTest002, TestSize.Level1)
135 {
136 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceInnerTest002 function start!");
137 EXPECT_TRUE(g_service != nullptr);
138 sptr<IDisplayPowerCallback> callbackPtr = new DisplayServiceTest::DisplayPowerMgrTestCallback();
139
140 EXPECT_FALSE(g_service->RegisterCallbackInner(callbackPtr));
141 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceInnerTest002 function end!");
142 }
143
144 /**
145 * @tc.name: DisplayServiceInnerTest003
146 * @tc.desc: test DisplayPowerMgrService function
147 * @tc.type: FUNC
148 * @tc.require:
149 */
150 HWTEST_F(DisplayServiceTest, DisplayServiceInnerTest003, TestSize.Level1)
151 {
152 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceInnerTest003 function start!");
153 EXPECT_TRUE(g_service != nullptr);
154 std::vector<int32_t> threshold = {200, 200, 20};
155 sptr<DisplayBrightnessCallbackStub> callback = new DisplayBrightnessCallbackStub();
156 uint32_t result = g_service->SetLightBrightnessThresholdInner(threshold, callback);
157 EXPECT_EQ(result, SET_SUCC);
158 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceInnerTest003 function end!");
159 }
160
161 /**
162 * @tc.name: DisplayServiceTest001
163 * @tc.desc: test DisplayPowerMgrService function
164 * @tc.type: FUNC
165 * @tc.require:
166 */
167 HWTEST_F(DisplayServiceTest, DisplayServiceTest001, TestSize.Level1)
168 {
169 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest001 function start!");
170 EXPECT_TRUE(g_service != nullptr);
171 bool ret = false;
172 int32_t errCode = 0;
173 uint32_t result = g_service->SetMaxBrightness(MAX_BRIGHTNESS_SET, TEST_MODE, ret, errCode);
174 uint32_t maxBrightness = 0;
175 g_service->GetMaxBrightness(maxBrightness);
176 EXPECT_TRUE(ret);
177 EXPECT_NE(maxBrightness, MAX_BRIGHTNESS_SET);
178 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest001 function end!");
179 }
180
181 /**
182 * @tc.name: DisplayServiceTest002
183 * @tc.desc: test DisplayPowerMgrService function SetDisplayState id != DISPLAY_MAIN_ID
184 * @tc.type: FUNC
185 * @tc.require:
186 */
187 HWTEST_F(DisplayServiceTest, DisplayServiceTest002, TestSize.Level1)
188 {
189 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest002 function start!");
190 EXPECT_TRUE(g_service != nullptr);
191 bool ret = false;
192 g_service->SetDisplayState(DISPLAY_MAIN_ID, static_cast<uint32_t>(DisplayPowerMgr::DisplayState::DISPLAY_ON),
193 REASON, ret);
194 EXPECT_TRUE(ret);
195 int32_t displayState = 0;
196 g_service->GetDisplayState(DISPLAY_MAIN_ID, displayState);
197 EXPECT_EQ(static_cast<int32_t>(DisplayPowerMgr::DisplayState::DISPLAY_ON), displayState);
198 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest002 function end!");
199 }
200
201 /**
202 * @tc.name: DisplayServiceTest003
203 * @tc.desc: test DisplayPowerMgrService function SetDisplayState id != DISPLAY_MAIN_ID
204 * @tc.type: FUNC
205 * @tc.require:
206 */
207 HWTEST_F(DisplayServiceTest, DisplayServiceTest003, TestSize.Level1)
208 {
209 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest003 function start!");
210 EXPECT_TRUE(g_service != nullptr);
211 bool ret = false;
212 auto controller = g_service->controllerMap_[DISPLAY_MAIN_ID];
213 g_service->controllerMap_.erase(DISPLAY_MAIN_ID);
214 g_service->SetDisplayState(DISPLAY_MAIN_ID, static_cast<uint32_t>(DisplayPowerMgr::DisplayState::DISPLAY_ON),
215 REASON, ret);
216 EXPECT_FALSE(ret);
217 int32_t displayState = 0;
218 g_service->GetDisplayState(DISPLAY_MAIN_ID, displayState);
219 EXPECT_EQ(static_cast<int32_t>(DisplayPowerMgr::DisplayState::DISPLAY_UNKNOWN), displayState);
220 g_service->controllerMap_.emplace(DISPLAY_MAIN_ID, controller);
221 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest003 function end!");
222 }
223
224 /**
225 * @tc.name: DisplayServiceTest004
226 * @tc.desc: test DisplayPowerMgrService function GetDisplayIds
227 * @tc.type: FUNC
228 * @tc.require:
229 */
230 HWTEST_F(DisplayServiceTest, DisplayServiceTest004, TestSize.Level1)
231 {
232 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest004 function start!");
233 EXPECT_TRUE(g_service != nullptr);
234 std::vector<uint32_t> ids;
235 g_service->GetDisplayIds(ids);
236 EXPECT_FALSE(ids.empty());
237 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest004 function end!");
238 }
239
240 /**
241 * @tc.name: DisplayServiceTest005
242 * @tc.desc: test DisplayPowerMgrService function SetBrightness
243 * @tc.type: FUNC
244 * @tc.require:
245 */
246 HWTEST_F(DisplayServiceTest, DisplayServiceTest005, TestSize.Level1)
247 {
248 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest005 function start!");
249 EXPECT_TRUE(g_service != nullptr);
250 bool ret = false;
251 int32_t errCode = 0;
252 g_service->SetBrightness(BRIGHTNESS_SETTING_VALUE, DISPLAY_MAIN_ID, false, ret, errCode);
253 EXPECT_TRUE(ret);
254 EXPECT_EQ(errCode, ERR_OK);
255 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest005 function end!");
256 }
257
258 /**
259 * @tc.name: DisplayServiceTest006
260 * @tc.desc: test DisplayPowerMgrService function DiscountBrightness
261 * @tc.type: FUNC
262 * @tc.require:
263 */
264 HWTEST_F(DisplayServiceTest, DisplayServiceTest006, TestSize.Level1)
265 {
266 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest006 function start!");
267 EXPECT_TRUE(g_service != nullptr);
268 bool ret = false;
269 g_service->DiscountBrightness(DISCOUNT_VALUE, DISPLAY_MAIN_ID, ret);
270 EXPECT_TRUE(ret);
271 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest006 function end!");
272 }
273
274 /**
275 * @tc.name: DisplayServiceTest007
276 * @tc.desc: test DisplayPowerMgrService function OverrideDisplayOffDelay
277 * @tc.type: FUNC
278 * @tc.require:
279 */
280 HWTEST_F(DisplayServiceTest, DisplayServiceTest007, TestSize.Level1)
281 {
282 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest007 function start!");
283 EXPECT_TRUE(g_service != nullptr);
284 bool ret = false;
285 g_service->OverrideDisplayOffDelay(OVERRIDE_DELAY_TIME, ret);
286 EXPECT_TRUE(ret);
287 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest007 function end!");
288 }
289
290 /**
291 * @tc.name: DisplayServiceTest008
292 * @tc.desc: test DisplayPowerMgrService function RestoreBrightness
293 * @tc.type: FUNC
294 * @tc.require:
295 */
296 HWTEST_F(DisplayServiceTest, DisplayServiceTest008, TestSize.Level1)
297 {
298 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest008 function start!");
299 EXPECT_TRUE(g_service != nullptr);
300 bool ret = false;
301 g_service->RestoreBrightness(DISPLAY_MAIN_ID, DEFAULT_DURATION, ret);
302 EXPECT_FALSE(ret);
303 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest008 function end!");
304 }
305
306 /**
307 * @tc.name: DisplayServiceTest009
308 * @tc.desc: test DisplayPowerMgrService function GetBrightness
309 * @tc.type: FUNC
310 * @tc.require:
311 */
312 HWTEST_F(DisplayServiceTest, DisplayServiceTest009, TestSize.Level1)
313 {
314 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest009 function start!");
315 EXPECT_TRUE(g_service != nullptr);
316 uint32_t brightness = 0;
317 g_service->GetBrightness(DISPLAY_MAIN_ID, brightness);
318 EXPECT_NE(brightness, BRIGHTNESS_OFF);
319 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest009 function end!");
320 }
321
322 /**
323 * @tc.name: DisplayServiceTest010
324 * @tc.desc: test DisplayPowerMgrService function GetDefaultBrightness
325 * @tc.type: FUNC
326 * @tc.require:
327 */
328 HWTEST_F(DisplayServiceTest, DisplayServiceTest010, TestSize.Level1)
329 {
330 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest010 function start!");
331 EXPECT_TRUE(g_service != nullptr);
332 uint32_t brightness = 0;
333 g_service->GetDefaultBrightness(brightness);
334 EXPECT_EQ(brightness, DisplayPowerMgrService::BRIGHTNESS_DEFAULT);
335 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest010 function end!");
336 }
337
338 /**
339 * @tc.name: DisplayServiceTest011
340 * @tc.desc: test DisplayPowerMgrService function GetMinBrightness
341 * @tc.type: FUNC
342 * @tc.require:
343 */
344 HWTEST_F(DisplayServiceTest, DisplayServiceTest011, TestSize.Level1)
345 {
346 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest011 function start!");
347 EXPECT_TRUE(g_service != nullptr);
348 uint32_t brightness = 0;
349 g_service->GetMinBrightness(brightness);
350 EXPECT_EQ(brightness, DisplayPowerMgrService::BRIGHTNESS_MIN);
351 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest011 function end!");
352 }
353
354 /**
355 * @tc.name: DisplayServiceTest012
356 * @tc.desc: test DisplayPowerMgrService function AdjustBrightness
357 * @tc.type: FUNC
358 * @tc.require:
359 */
360 HWTEST_F(DisplayServiceTest, DisplayServiceTest012, TestSize.Level1)
361 {
362 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest012 function start!");
363 EXPECT_TRUE(g_service != nullptr);
364 bool ret = false;
365 g_service->AdjustBrightness(DISPLAY_MAIN_ID, BRIGHTNESS_ADJUST_VALUE, BRIGHTNESS_DURATION, ret);
366 EXPECT_TRUE(ret);
367 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest012 function end!");
368 }
369
370 /**
371 * @tc.name: DisplayServiceTest013
372 * @tc.desc: test DisplayPowerMgrService function NotifyScreenPowerStatus
373 * @tc.type: FUNC
374 * @tc.require:
375 */
376 HWTEST_F(DisplayServiceTest, DisplayServiceTest013, TestSize.Level1)
377 {
378 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest013 function start!");
379 EXPECT_TRUE(g_service != nullptr);
380 int32_t errCode = 0;
381 int32_t displayState = 0;
382 g_service->GetDisplayState(DISPLAY_MAIN_ID, displayState);
383 g_service->NotifyScreenPowerStatus(DISPLAY_MAIN_ID, displayState, errCode);
384 EXPECT_NE(errCode, DEFAULT_VALUE);
385 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest013 function end!");
386 }
387
388 /**
389 * @tc.name: DisplayServiceTest014
390 * @tc.desc: test DisplayPowerMgrService function IsAutoAdjustBrightness
391 * @tc.type: FUNC
392 * @tc.require:
393 */
394 HWTEST_F(DisplayServiceTest, DisplayServiceTest014, TestSize.Level1)
395 {
396 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest014 function start!");
397 EXPECT_TRUE(g_service != nullptr);
398 bool ret = false;
399 g_service->AutoAdjustBrightness(false, ret);
400 g_service->IsAutoAdjustBrightness(ret);
401 EXPECT_FALSE(ret);
402 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest014 function end!");
403 }
404
405 /**
406 * @tc.name: DisplayServiceTest015
407 * @tc.desc: test DisplayPowerMgrService function RegisterCallback
408 * @tc.type: FUNC
409 * @tc.require:
410 */
411 HWTEST_F(DisplayServiceTest, DisplayServiceTest015, TestSize.Level1)
412 {
413 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest015 function start!");
414 EXPECT_TRUE(g_service != nullptr);
415 bool ret = false;
416 sptr<IDisplayPowerCallback> callbackPtr = new DisplayServiceTest::DisplayPowerMgrTestCallback();
417 g_service->RegisterCallback(callbackPtr, ret);
418 EXPECT_FALSE(ret);
419 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest015 function end!");
420 }
421
422 /**
423 * @tc.name: DisplayServiceTest016
424 * @tc.desc: test DisplayPowerMgrService function BoostBrightness
425 * @tc.type: FUNC
426 * @tc.require:
427 */
428 HWTEST_F(DisplayServiceTest, DisplayServiceTest016, TestSize.Level1)
429 {
430 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest016 function start!");
431 EXPECT_TRUE(g_service != nullptr);
432 bool ret = false;
433 g_service->BoostBrightness(TIMEOUT_MS, DISPLAY_MAIN_ID, ret);
434 EXPECT_TRUE(ret);
435 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest016 function end!");
436 }
437
438 /**
439 * @tc.name: DisplayServiceTest017
440 * @tc.desc: test DisplayPowerMgrService function CancelBoostBrightness
441 * @tc.type: FUNC
442 * @tc.require:
443 */
444 HWTEST_F(DisplayServiceTest, DisplayServiceTest017, TestSize.Level1)
445 {
446 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest017 function start!");
447 EXPECT_TRUE(g_service != nullptr);
448 bool ret = false;
449 g_service->CancelBoostBrightness(DISPLAY_MAIN_ID, ret);
450 EXPECT_TRUE(ret);
451 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest017 function end!");
452 }
453
454 /**
455 * @tc.name: DisplayServiceTest018
456 * @tc.desc: test DisplayPowerMgrService function GetDeviceBrightness
457 * @tc.type: FUNC
458 * @tc.require:
459 */
460 HWTEST_F(DisplayServiceTest, DisplayServiceTest018, TestSize.Level1)
461 {
462 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest018 function start!");
463 EXPECT_TRUE(g_service != nullptr);
464 uint32_t brightness = 0;
465 g_service->GetDeviceBrightness(DISPLAY_MAIN_ID, brightness);
466 EXPECT_NE(brightness, BRIGHTNESS_NONE_VALUE);
467 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest018 function end!");
468 }
469
470 /**
471 * @tc.name: DisplayServiceTest019
472 * @tc.desc: test DisplayPowerMgrService function SetCoordinated
473 * @tc.type: FUNC
474 * @tc.require:
475 */
476 HWTEST_F(DisplayServiceTest, DisplayServiceTest019, TestSize.Level1)
477 {
478 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest019 function start!");
479 EXPECT_TRUE(g_service != nullptr);
480 bool ret = false;
481 g_service->SetCoordinated(true, DISPLAY_MAIN_ID, ret);
482 EXPECT_TRUE(ret);
483 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest019 function end!");
484 }
485
486 /**
487 * @tc.name: DisplayServiceTest020
488 * @tc.desc: test DisplayPowerMgrService function SetLightBrightnessThreshold
489 * @tc.type: FUNC
490 * @tc.require:
491 */
492 HWTEST_F(DisplayServiceTest, DisplayServiceTest020, TestSize.Level1)
493 {
494 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest020 function start!");
495 EXPECT_TRUE(g_service != nullptr);
496 uint32_t ret = 0;
497 std::vector<int32_t> threshold = {200, 200, 20};
498 sptr<DisplayBrightnessCallbackStub> callback = new DisplayBrightnessCallbackStub();
499 g_service->SetLightBrightnessThreshold(threshold, callback, ret);
500 EXPECT_EQ(ret, SET_SUCC);
501 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest020 function end!");
502 }
503
504 /**
505 * @tc.name: DisplayServiceTest021
506 * @tc.desc: test DisplayPowerMgrService function SetMaxBrightnessNit
507 * @tc.type: FUNC
508 * @tc.require:
509 */
510 HWTEST_F(DisplayServiceTest, DisplayServiceTest021, TestSize.Level1)
511 {
512 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest021 function start!");
513 EXPECT_TRUE(g_service != nullptr);
514 bool ret = false;
515 int32_t errCode = 0;
516 uint32_t result = g_service->SetMaxBrightnessNit(MAX_BRIGHTNESS_SET, TEST_MODE, ret, errCode);
517 EXPECT_TRUE(ret);
518 uint32_t maxBrightness = 0;
519 g_service->GetMaxBrightness(maxBrightness);
520 EXPECT_NE(maxBrightness, MAX_BRIGHTNESS_SET);
521 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest021 function end!");
522 }
523
524 /**
525 * @tc.name: DisplayServiceTest022
526 * @tc.desc: test DisplayPowerMgrService function SetBootCompletedBrightness
527 * @tc.type: FUNC
528 * @tc.require:
529 */
530 HWTEST_F(DisplayServiceTest, DisplayServiceTest022, TestSize.Level1)
531 {
532 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest022 function start!");
533 EXPECT_TRUE(g_service != nullptr);
534 const int sleepTime = DEFAULT_WAITING_TIME;
535 usleep(sleepTime);
536 uint32_t brightnessTemp = BRIGHTNESS_OFF;
537 g_service->GetBrightness(DISPLAY_MAIN_ID, brightnessTemp);
538 bool enable = g_service->GetSettingAutoBrightness();
539 g_service->SetBootCompletedBrightness();
540 g_service->SetBootCompletedAutoBrightness();
541 g_service->RegisterSettingObservers();
542 uint32_t brightness = BRIGHTNESS_OFF;
543 g_service->GetBrightness(DISPLAY_MAIN_ID, brightness);
544 EXPECT_EQ(brightness, brightnessTemp);
545 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest022 function end!");
546 }
547
548 /**
549 * @tc.name: DisplayServiceTest023
550 * @tc.desc: test DisplayPowerMgrService function OverrideBrightness
551 * @tc.type: FUNC
552 * @tc.require:
553 */
554 HWTEST_F(DisplayServiceTest, DisplayServiceTest023, TestSize.Level1)
555 {
556 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest023 function start!");
557 EXPECT_TRUE(g_service != nullptr);
558 bool ret = false;
559 g_service->OverrideBrightness(BRIGHTNESS_OVERRIDE_VALUE, DISPLAY_INVALID_ID, DEFAULT_DURATION, ret);
560 EXPECT_FALSE(ret);
561 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest023 function end!");
562 }
563
564 /**
565 * @tc.name: DisplayServiceTest024
566 * @tc.desc: test DisplayPowerMgrService function Dump
567 * @tc.type: FUNC
568 * @tc.require:
569 */
570 HWTEST_F(DisplayServiceTest, DisplayServiceTest024, TestSize.Level1)
571 {
572 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest024 function start!");
573 EXPECT_TRUE(g_service != nullptr);
574 int fd = 1;
575 std::vector<std::u16string> args;
576 g_service->isBootCompleted_ = false;
577 auto ret = g_service->Dump(fd, args);
578 EXPECT_EQ(ret, ERR_NO_INIT);
579 g_service->isBootCompleted_ = true;
580 ret = g_service->Dump(fd, args);
581 EXPECT_EQ(ret, ERR_OK);
582 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest024 function end!");
583 }
584
585 /**
586 * @tc.name: DisplayServiceTest025
587 * @tc.desc: test DisplayPowerMgrService function OverrideDisplayOffDelay
588 * @tc.type: FUNC
589 * @tc.require:
590 */
591 HWTEST_F(DisplayServiceTest, DisplayServiceTest025, TestSize.Level1)
592 {
593 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest025 function start!");
594 EXPECT_TRUE(g_service != nullptr);
595 bool ret = false;
596 g_service->OverrideDisplayOffDelay(TEST_DELAY_TIME_UNSET, ret);
597 EXPECT_FALSE(g_service->isDisplayDelayOff_);
598 EXPECT_FALSE(ret);
599 g_service->SetDisplayState(DISPLAY_MAIN_ID, static_cast<uint32_t>(DisplayPowerMgr::DisplayState::DISPLAY_OFF),
600 REASON, ret);
601 EXPECT_TRUE(ret);
602 g_service->OverrideDisplayOffDelay(OVERRIDE_DELAY_TIME, ret);
603 EXPECT_FALSE(g_service->isDisplayDelayOff_);
604 DISPLAY_HILOGI(LABEL_TEST, "DisplayServiceTest025 function end!");
605 }
606 } // namespace
607