• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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_power_mgr_client.h"
18 #include "setting_provider.h"
19 #include "system_ability_definition.h"
20 #include "display_log.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 using namespace OHOS;
25 using namespace OHOS::DisplayPowerMgr;
26 
27 namespace {
28 const std::string SETTING_BRIGHTNESS_KEY {"settings.display.screen_brightness_status"};
29 const double NO_DISCOUNT = 1.00;
30 }
31 
32 class DisplayPowerMgrBrightnessTest : public Test {
33 public:
SetUp()34     void SetUp()
35     {
36         DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_ON);
37         DisplayPowerMgrClient::GetInstance().DiscountBrightness(NO_DISCOUNT);
38     }
39 
TearDown()40     void TearDown()
41     {
42         DisplayPowerMgrClient::GetInstance().RestoreBrightness();
43         DisplayPowerMgrClient::GetInstance().CancelBoostBrightness();
44     }
45 };
46 
47 namespace {
48 /**
49  * @tc.name: DisplayPowerMgrSetBrightness001
50  * @tc.desc: Test SetBrightness
51  * @tc.type: FUNC
52  */
53 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrSetBrightness001, TestSize.Level0)
54 {
55     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrSetBrightness001: fun is start");
56     const uint32_t SET_BRIGHTNESS = 90;
57     bool ret = DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS);
58     EXPECT_TRUE(ret);
59     uint32_t deviceBrightness = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
60     EXPECT_EQ(deviceBrightness, SET_BRIGHTNESS);
61     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrSetBrightness001: fun is end");
62 }
63 
64 /**
65  * @tc.name: DisplayPowerMgrSettingBrightness001
66  * @tc.desc: Test setting brightness value changed when SetBrightness
67  * @tc.type: FUNC
68  */
69 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrSettingBrightness001, TestSize.Level0)
70 {
71     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrSettingBrightness001: fun is start");
72     const uint32_t SET_BRIGHTNESS_VALUE = 223;
73     bool ret = DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS_VALUE);
74     EXPECT_TRUE(ret);
75     const int sleepTime = 100000;
76     usleep(sleepTime); // sleep 100ms, wait for setting update
77     uint32_t brightness = DisplayPowerMgrClient::GetInstance().GetBrightness();
78     EXPECT_EQ(brightness, SET_BRIGHTNESS_VALUE);
79     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrSettingBrightness001: fun is end");
80 }
81 
82 /**
83  * @tc.name: DisplayPowerMgrDiscountBrightnessNormal
84  * @tc.desc: Test DiscountBrightness the normal test
85  * @tc.type: FUNC
86  * @tc.require: issueI5HWMN
87  */
88 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightnessNormal, TestSize.Level0)
89 {
90     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessNormal: fun is start");
91     const uint32_t SET_BRIGHTNESS = 91;
92     const int32_t SLEEP_TIME = 200000;
93     DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS);
94     usleep(SLEEP_TIME); // sleep 200ms, wait for setBrightness
95     const double DISCOUNT_NORMAL = 0.8;
96     bool ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_NORMAL);
97     EXPECT_TRUE(ret);
98 
99     uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
100     EXPECT_EQ(value, static_cast<uint32_t>(SET_BRIGHTNESS * DISCOUNT_NORMAL));
101     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessNormal: fun is end");
102 }
103 
104 /**
105  * @tc.name: DisplayPowerMgrDiscountBrightnessNormal
106  * @tc.desc: Test DiscountBrightness when screen is off
107  * @tc.type: FUNC
108  * @tc.require: issueI5HWMN
109  */
110 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightnessScreenOff, TestSize.Level0)
111 {
112     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessScreenOff: fun is start");
113     DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_OFF);
114     const double DISCOUNT_VALUE = 0.8;
115     bool ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_VALUE);
116     EXPECT_FALSE(ret);
117     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessScreenOff: fun is end");
118 }
119 
120 /**
121  * @tc.name: DisplayPowerMgrDiscountBrightnessBoundary001
122  * @tc.desc: Test DiscountBrightness the boundary test
123  * @tc.type: FUNC
124  * @tc.require: issueI5HWMN
125  */
126 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightnessBoundary001, TestSize.Level0)
127 {
128     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessBoundary001: fun is start");
129     const uint32_t SET_BRIGHTNESS = 92;
130     DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS);
131     const double DISCOUNT_LOWER_BOUNDARY = 0.01;
132     bool ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_LOWER_BOUNDARY);
133     EXPECT_TRUE(ret);
134 
135     uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
136     uint32_t minBrightness = DisplayPowerMgrClient::GetInstance().GetMinBrightness();
137     EXPECT_EQ(value, minBrightness);
138     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessBoundary001: fun is end");
139 }
140 
141 /**
142  * @tc.name: DisplayPowerMgrDiscountBrightnessBoundary002
143  * @tc.desc: Test DiscountBrightness the boundary test
144  * @tc.type: FUNC
145  * @tc.require: issueI5HWMN
146  */
147 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightnessBoundary002, TestSize.Level0)
148 {
149     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessBoundary002: fun is start");
150     const uint32_t SET_BRIGHTNESS = 93;
151     const int32_t SLEEP_TIME = 200000;
152     DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS);
153     usleep(SLEEP_TIME); // sleep 200ms, wait for setBrightness
154     const double DISCOUNT_UPPER_BOUNDARY = 1.0;
155     bool ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_UPPER_BOUNDARY);
156     EXPECT_TRUE(ret);
157 
158     uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
159     EXPECT_EQ(value, static_cast<uint32_t>(SET_BRIGHTNESS * DISCOUNT_UPPER_BOUNDARY));
160     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessBoundary002: fun is end");
161 }
162 
163 /**
164  * @tc.name: DisplayPowerMgrDiscountBrightnessAbnormal001
165  * @tc.desc: Test DiscountBrightness the abnormal test
166  * @tc.type: FUNC
167  * @tc.require: issueI5HWMN
168  */
169 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightnessAbnormal001, TestSize.Level0)
170 {
171     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessAbnormal001: fun is start");
172     const uint32_t SET_BRIGHTNESS = 94;
173     DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS);
174     const double DISCOUNT_BEYOND_LOWER_BOUNDARY = 0.0;
175     bool ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_BEYOND_LOWER_BOUNDARY);
176     EXPECT_TRUE(ret);
177 
178     uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
179     uint32_t minBrightness = DisplayPowerMgrClient::GetInstance().GetMinBrightness();
180     EXPECT_EQ(value, minBrightness);
181     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessAbnormal001: fun is end");
182 }
183 
184 /**
185  * @tc.name: DisplayPowerMgrDiscountBrightnessAbnormal002
186  * @tc.desc: Test DiscountBrightness the abnormal test
187  * @tc.type: FUNC
188  * @tc.require: issueI5HWMN
189  */
190 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightnessAbnormal002, TestSize.Level0)
191 {
192     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessAbnormal002: fun is start");
193     const uint32_t SET_BRIGHTNESS = 95;
194     const int32_t SLEEP_TIME = 200000;
195     DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS);
196     usleep(SLEEP_TIME); // sleep 200ms, wait for setBrightness
197     const double DISCOUNT_BEYOND_UPPER_BOUNDARY = 2.0;
198     bool ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_BEYOND_UPPER_BOUNDARY);
199     EXPECT_TRUE(ret);
200 
201     uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
202     const double DISCOUNT_MAX_VALUE = 1.0;
203     EXPECT_EQ(value, static_cast<uint32_t>(SET_BRIGHTNESS * DISCOUNT_MAX_VALUE));
204     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessAbnormal002: fun is end");
205 }
206 
207 /**
208  * @tc.name: DisplayPowerMgrDiscountBrightnessAbnormal003
209  * @tc.desc: Test DiscountBrightness the abnormal test
210  * @tc.type: FUNC
211  * @tc.require: issueI5HWMN
212  */
213 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightnessAbnormal003, TestSize.Level0)
214 {
215     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessAbnormal003: fun is start");
216     const uint32_t SET_BRIGHTNESS = 96;
217     DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS);
218     const double DISCOUNT_NEGATIVE_VALUE = -1.0;
219     bool ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_NEGATIVE_VALUE);
220     EXPECT_TRUE(ret);
221 
222     uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
223     uint32_t minBrightness = DisplayPowerMgrClient::GetInstance().GetMinBrightness();
224     EXPECT_EQ(value, minBrightness);
225     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessAbnormal003: fun is end");
226 }
227 
228 /**
229  * @tc.name: DisplayPowerMgrDiscountBrightness001
230  * @tc.desc: Test OverrideBrightness after DiscountBrightness, then RestoreBrightness
231  * @tc.type: FUNC
232  * @tc.require: issueI5HWMN
233  */
234 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightness001, TestSize.Level0)
235 {
236     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightness001: fun is start");
237     const uint32_t SET_BRIGHTNESS = 97;
238     const int32_t SLEEP_TIME = 200000;
239     DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS);
240     usleep(SLEEP_TIME); // sleep 200ms, wait for setBrightness
241     const double DISCOUNT_VALUE = 0.8;
242     bool ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_VALUE);
243     EXPECT_TRUE(ret);
244 
245     uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
246     EXPECT_EQ(value, static_cast<uint32_t>(DISCOUNT_VALUE * SET_BRIGHTNESS));
247 
248     const uint32_t SET_OVERRIDE_BRIGHTNESS = 200;
249     DisplayPowerMgrClient::GetInstance().OverrideBrightness(SET_OVERRIDE_BRIGHTNESS);
250     value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
251     EXPECT_EQ(value, static_cast<uint32_t>(DISCOUNT_VALUE * SET_OVERRIDE_BRIGHTNESS));
252 
253     DisplayPowerMgrClient::GetInstance().RestoreBrightness();
254     value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
255     EXPECT_EQ(value, static_cast<uint32_t>(DISCOUNT_VALUE * SET_BRIGHTNESS));
256     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightness001: fun is end");
257 }
258 
259 /**
260  * @tc.name: DisplayPowerMgrDiscountBrightness002
261  * @tc.desc: Test DiscountBrightness after OverrideBrightness, then RestoreBrightness
262  * @tc.type: FUNC
263  * @tc.require: issueI5HWMN
264  */
265 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightness002, TestSize.Level0)
266 {
267     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightness002: fun is start");
268     const uint32_t SET_BRIGHTNESS = 150;
269     DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS);
270     const int32_t SLEEP_TIME = 200000;
271     usleep(SLEEP_TIME); // sleep 200ms, wait for setBrightness
272     const uint32_t SET_OVERRIDE_BRIGHTNESS = 200;
273     DisplayPowerMgrClient::GetInstance().OverrideBrightness(SET_OVERRIDE_BRIGHTNESS);
274 
275     const double DISCOUNT_VALUE = 0.8;
276     double ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_VALUE);
277     EXPECT_TRUE(ret);
278     uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
279     EXPECT_EQ(value, static_cast<uint32_t>(DISCOUNT_VALUE * SET_OVERRIDE_BRIGHTNESS));
280 
281     ret = DisplayPowerMgrClient::GetInstance().RestoreBrightness();
282     EXPECT_TRUE(ret);
283 
284     value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
285     EXPECT_EQ(value, static_cast<uint32_t>(DISCOUNT_VALUE * SET_BRIGHTNESS));
286     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightness002: fun is end");
287 }
288 
289 /**
290  * @tc.name: DisplayPowerMgrDiscountBrightness003
291  * @tc.desc: Test DisconutBrightness after BoostBrightness and CancelBoostBrightness
292  * @tc.type: FUNC
293  * @tc.require: issueI5HWMN
294  */
295 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightness003, TestSize.Level0)
296 {
297     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightness003: fun is start");
298     const uint32_t SET_BRIGHTNESS = 99;
299     DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS);
300     const int32_t SLEEP_TIME = 200000;
301     usleep(SLEEP_TIME); // sleep 200ms, wait for setBrightness
302     const uint32_t SET_BOOST_BRIGHTNESS_TIME = 10000;
303     DisplayPowerMgrClient::GetInstance().BoostBrightness(SET_BOOST_BRIGHTNESS_TIME);
304 
305     const double DISCOUNT_VALUE = 0.8;
306     bool ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_VALUE);
307     EXPECT_TRUE(ret);
308 
309     uint32_t maxBrightness = DisplayPowerMgrClient::GetInstance().GetMaxBrightness();
310     uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
311     EXPECT_EQ(value, static_cast<uint32_t>(DISCOUNT_VALUE * maxBrightness));
312 
313     DisplayPowerMgrClient::GetInstance().CancelBoostBrightness();
314 
315     value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
316     EXPECT_EQ(value, static_cast<uint32_t>(DISCOUNT_VALUE * SET_BRIGHTNESS));
317     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightness003: fun is end");
318 }
319 
320 /**
321  * @tc.name: DisplayPowerMgrDiscountBrightness004
322  * @tc.desc: Test BoostBrightness after DiscountBrightness, then CancelBoostBrightness
323  * @tc.type: FUNC
324  * @tc.require: issueI5HWMN
325  */
326 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightness004, TestSize.Level0)
327 {
328     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightness004: fun is start");
329     const uint32_t SET_BRIGHTNESS = 100;
330     DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS);
331     const int32_t SLEEP_TIME = 200000;
332     usleep(SLEEP_TIME); // sleep 200ms, wait for setBrightness
333     const double DISCOUNT_VALUE = 0.8;
334     bool ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_VALUE);
335     EXPECT_TRUE(ret);
336 
337     const uint32_t SET_BOOST_BRIGHTNESS_TIME = 10000;
338     DisplayPowerMgrClient::GetInstance().BoostBrightness(SET_BOOST_BRIGHTNESS_TIME);
339     uint32_t maxBrightness = DisplayPowerMgrClient::GetInstance().GetMaxBrightness();
340     uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
341     EXPECT_EQ(value, static_cast<uint32_t>(DISCOUNT_VALUE * maxBrightness));
342 
343     DisplayPowerMgrClient::GetInstance().CancelBoostBrightness();
344 
345     value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
346     EXPECT_EQ(value, static_cast<uint32_t>(DISCOUNT_VALUE * SET_BRIGHTNESS));
347     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightness004: fun is end");
348 }
349 
350 /**
351  * @tc.name: DisplayPowerMgrDiscountBrightness005
352  * @tc.desc: Test DisconutBrightness after SetBrightness, then GetBrightness
353  * @tc.type: FUNC
354  * @tc.require: issueI5HWMN
355  */
356 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightness005, TestSize.Level0)
357 {
358     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightness005: fun is start");
359     const uint32_t SET_BRIGHTNESS = 103;
360     DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS);
361     const double DISCOUNT_VALUE = 0.8;
362     bool ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_VALUE);
363     EXPECT_TRUE(ret);
364 
365     uint32_t beforeBrightness = DisplayPowerMgrClient::GetInstance().GetBrightness();
366     EXPECT_EQ(SET_BRIGHTNESS, beforeBrightness);
367     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightness005: fun is end");
368 }
369 
370 /**
371  * @tc.name: DisplayPowerMgrOverrideBrightness001
372  * @tc.desc: Test OverrideBrightness
373  * @tc.type: FUNC
374  */
375 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrOverrideBrightness001, TestSize.Level0)
376 {
377     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrOverrideBrightness001: fun is start");
378     const uint32_t OVERRIDE_BRIGHTNESS = 255;
379     bool ret = DisplayPowerMgrClient::GetInstance().OverrideBrightness(OVERRIDE_BRIGHTNESS);
380     EXPECT_TRUE(ret);
381     uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
382     EXPECT_EQ(value, OVERRIDE_BRIGHTNESS);
383     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrOverrideBrightness001: fun is end");
384 }
385 
386 /**
387  * @tc.name: DisplayPowerMgrOverrideBrightness002
388  * @tc.desc: Test RestoreBrightness after OverrideBrightness
389  * @tc.type: FUNC
390  */
391 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrOverrideBrightness002, TestSize.Level0)
392 {
393     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrOverrideBrightness002: fun is start");
394     const uint32_t SET_BRIGHTNESS = 104;
395     const uint32_t OVERRIDE_BRIGHTNESS = 255;
396     const int32_t SLEEP_TIME = 200000;
397     bool ret = DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS);
398     usleep(SLEEP_TIME); // sleep 200ms, wait for setBrightness
399     EXPECT_TRUE(ret);
400     ret = DisplayPowerMgrClient::GetInstance().OverrideBrightness(OVERRIDE_BRIGHTNESS);
401     EXPECT_TRUE(ret);
402     uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
403     EXPECT_EQ(value, OVERRIDE_BRIGHTNESS);
404     ret = DisplayPowerMgrClient::GetInstance().RestoreBrightness(); // restore
405     EXPECT_TRUE(ret);
406     value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
407     EXPECT_EQ(value, SET_BRIGHTNESS);
408     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrOverrideBrightness002: fun is end");
409 }
410 
411 /**
412  * @tc.name: DisplayPowerMgrOverrideBrightness003
413  * @tc.desc: Test SetBrightness after OverrideBrightness
414  * @tc.type: FUNC
415  */
416 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrOverrideBrightness003, TestSize.Level0)
417 {
418     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrOverrideBrightness003: fun is start");
419     const uint32_t SET_BRIGHTNESS = 105;
420     const uint32_t OVERRIDE_BRIGHTNESS = 255;
421     bool ret = DisplayPowerMgrClient::GetInstance().OverrideBrightness(OVERRIDE_BRIGHTNESS);
422     EXPECT_TRUE(ret);
423     ret = DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS);
424     EXPECT_FALSE(ret);
425     uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
426     EXPECT_EQ(value, OVERRIDE_BRIGHTNESS);
427     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrOverrideBrightness003: fun is end");
428 }
429 
430 /**
431  * @tc.name: DisplayPowerMgrOverrideBrightness004
432  * @tc.desc: Test RestoreBrightness after not override
433  * @tc.type: FUNC
434  */
435 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrOverrideBrightness004, TestSize.Level0)
436 {
437     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrOverrideBrightness004: fun is start");
438     const uint32_t SET_BRIGHTNESS = 106;
439     bool ret = DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS);
440     EXPECT_TRUE(ret);
441     ret = DisplayPowerMgrClient::GetInstance().RestoreBrightness();
442     EXPECT_FALSE(ret);
443     uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
444     EXPECT_EQ(value, SET_BRIGHTNESS);
445     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrOverrideBrightness004: fun is end");
446 }
447 
448 /**
449  * @tc.name: DisplayPowerMgrOverrideBrightness005
450  * @tc.desc: Test OverrideBrightness off Disable the call
451  * @tc.type: FUNC
452  */
453 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrOverrideBrightness005, TestSize.Level0)
454 {
455     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrOverrideBrightness005: fun is start");
456     DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_OFF);
457     const uint32_t OVERRIDE_BRIGHTNESS = 100;
458     bool isBoost = DisplayPowerMgrClient::GetInstance().OverrideBrightness(OVERRIDE_BRIGHTNESS);
459     EXPECT_FALSE(isBoost);
460     bool isRestore = DisplayPowerMgrClient::GetInstance().RestoreBrightness();
461     EXPECT_FALSE(isRestore);
462     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrOverrideBrightness005: fun is end");
463 }
464 
465 /**
466  * @tc.name: DisplayPowerMgrOverrideBrightness006
467  * @tc.desc: Test device brightness when override brightness is 256
468  * @tc.type: FUNC
469  * @tc.require: issueI5YZQR
470  */
471 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrOverrideBrightness006, TestSize.Level0)
472 {
473     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrOverrideBrightness006: fun is start");
474     uint32_t overrideValue = 256;
475     uint32_t brightnessMax = 255;
476     DisplayPowerMgrClient::GetInstance().OverrideBrightness(overrideValue);
477     uint32_t deviceBrightness = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
478     EXPECT_EQ(brightnessMax, deviceBrightness);
479     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrOverrideBrightness006: fun is end");
480 }
481 
482 /**
483  * @tc.name: DisplayPowerMgrOverrideBrightness007
484  * @tc.desc: Test device brightness when override brightness is 0
485  * @tc.type: FUNC
486  * @tc.require: issueI5YZQR
487  */
488 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrOverrideBrightness007, TestSize.Level0)
489 {
490     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrOverrideBrightness007: fun is start");
491     uint32_t overrideValue = 0;
492     uint32_t brightnessMin = 5;
493     EXPECT_TRUE(DisplayPowerMgrClient::GetInstance().OverrideBrightness(overrideValue));
494     uint32_t deviceBrightness = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
495     EXPECT_EQ(brightnessMin, deviceBrightness);
496     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrOverrideBrightness007: fun is end");
497 }
498 
499 /**
500  * @tc.name: DisplayPowerMgrOverrideBrightness008
501  * @tc.desc: Test device brightness when override brightness is -1
502  * @tc.type: FUNC
503  * @tc.require: issueI5YZQR
504  */
505 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrOverrideBrightness008, TestSize.Level0)
506 {
507     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrOverrideBrightness008: fun is start");
508     uint32_t overrideValue = -1;
509     uint32_t brightnessMax = 255;
510     EXPECT_TRUE(DisplayPowerMgrClient::GetInstance().OverrideBrightness(overrideValue));
511     uint32_t deviceBrightness = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
512     EXPECT_EQ(brightnessMax, deviceBrightness);
513     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrOverrideBrightness008: fun is end");
514 }
515 
516 /**
517  * @tc.name: DisplayPowerMgrOverrideBrightness009
518  * @tc.desc: Set brightness after override brightness, then exit override brightness, the
519  *           restore brightness should be the latest set brightness
520  * @tc.type: FUNC
521  * @tc.require: issueI6ACLX
522  */
523 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrOverrideBrightness009, TestSize.Level0)
524 {
525     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrOverrideBrightness009: fun is start");
526     const uint32_t OVERRIDE_BRIGHTNESS = 156;
527     const uint32_t SET_BRIGHTNESS = 66;
528     DisplayPowerMgrClient::GetInstance().OverrideBrightness(OVERRIDE_BRIGHTNESS);
529     bool ret = DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS);
530     EXPECT_FALSE(ret);
531     DisplayPowerMgrClient::GetInstance().RestoreBrightness();
532     uint32_t deviceBrightness = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
533     EXPECT_EQ(SET_BRIGHTNESS, deviceBrightness);
534     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrOverrideBrightness009: fun is end");
535 }
536 
537 /**
538  * @tc.name: DisplayPowerMgrMaxBrightness001
539  * @tc.desc: Test GetMaxBrightness less equals 255
540  * @tc.type: FUNC
541  */
542 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrMaxBrightness001, TestSize.Level0)
543 {
544     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrMaxBrightness001: fun is start");
545     uint32_t max = DisplayPowerMgrClient::GetInstance().GetMaxBrightness();
546     EXPECT_LE(max, 255);
547     bool ret = DisplayPowerMgrClient::GetInstance().SetBrightness(max + 100);
548     EXPECT_TRUE(ret);
549     uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
550     EXPECT_EQ(value, max);
551     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrMaxBrightness001: fun is end");
552 }
553 
554 /**
555  * @tc.name: DisplayPowerMgrMinBrightness001
556  * @tc.desc: Test GetMinBrightness greater equals 0
557  * @tc.type: FUNC
558  */
559 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrMinBrightness001, TestSize.Level0)
560 {
561     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrMinBrightness001: fun is start");
562     const uint32_t SET_BRIGHTNESS_VALUE = 0;
563     uint32_t min = DisplayPowerMgrClient::GetInstance().GetMinBrightness();
564     EXPECT_GE(min, 0);
565     bool ret = DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS_VALUE);
566     EXPECT_TRUE(ret);
567     uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
568     EXPECT_EQ(value, min);
569     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrMinBrightness001: fun is end");
570 }
571 
572 /**
573  * @tc.name: DisplayPowerMgrDefaultBrightness001
574  * @tc.desc: Test GetDefaultnBrightness greater equals 0 and less equals 255
575  * @tc.type: FUNC
576  */
577 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDefaultBrightness001, TestSize.Level0)
578 {
579     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDefaultBrightness001: fun is start");
580     uint32_t value = DisplayPowerMgrClient::GetInstance().GetDefaultBrightness();
581     EXPECT_GE(value, 0);
582     EXPECT_LE(value, 255);
583     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDefaultBrightness001: fun is end");
584 }
585 
586 /**
587  * @tc.name: DisplayPowerMgrBoostBrightnessNormal
588  * @tc.desc: Test BoostBrightness the normal test
589  * @tc.type: FUNC
590  */
591 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrBoostBrightnessNormal, TestSize.Level0)
592 {
593     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessNormal: fun is start");
594     const uint32_t BOOST_TIME = 100; // keep BoostBrightness 100ms
595     bool isSucc = DisplayPowerMgrClient::GetInstance().BoostBrightness(BOOST_TIME);
596     EXPECT_TRUE(isSucc);
597     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessNormal: fun is end");
598 }
599 
600 /**
601  * @tc.name: DisplayPowerMgrBoostBrightnessAbnormal
602  * @tc.desc: Test BoostBrightness the abnormal value
603  * @tc.type: FUNC
604  */
605 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrBoostBrightnessAbnormal, TestSize.Level0)
606 {
607     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessAbnormal: fun is start");
608     const uint32_t BOOST_TIME = -1;
609     bool isSucc = DisplayPowerMgrClient::GetInstance().BoostBrightness(BOOST_TIME);
610     EXPECT_FALSE(isSucc);
611     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessAbnormal: fun is end");
612 }
613 
614 /**
615  * @tc.name: DisplayPowerMgrCancelBoostBrightnessNormal
616  * @tc.desc: Test CancelBoostBrightness the normal test
617  * @tc.type: FUNC
618  */
619 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrCancelBoostBrightnessNormal, TestSize.Level0)
620 {
621     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrCancelBoostBrightnessNormal: fun is start");
622     const uint32_t BOOST_TIME = 50000;
623     bool isSucc = DisplayPowerMgrClient::GetInstance().BoostBrightness(BOOST_TIME);
624     EXPECT_TRUE(isSucc);
625     bool isCancel = DisplayPowerMgrClient::GetInstance().CancelBoostBrightness();
626     EXPECT_TRUE(isCancel);
627     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrCancelBoostBrightnessNormal: fun is end");
628 }
629 
630 /**
631  * @tc.name: BoostAndOverrideMutuallyExclusive1
632  * @tc.desc: Test BoostBrightness and OverrideBrightness are mutually exclusive
633  * @tc.type: FUNC
634  */
635 HWTEST_F(DisplayPowerMgrBrightnessTest, BoostAndOverrideMutuallyExclusive1, TestSize.Level0)
636 {
637     DISPLAY_HILOGI(LABEL_TEST, "BoostAndOverrideMutuallyExclusive: fun is start");
638     const uint32_t BOOST_TIME = 50000;
639     const uint32_t OVERRIDE_BIRGHTNESS = 100;
640     bool isBoost = DisplayPowerMgrClient::GetInstance().BoostBrightness(BOOST_TIME);
641     EXPECT_TRUE(isBoost);
642     bool isOverride = DisplayPowerMgrClient::GetInstance().OverrideBrightness(OVERRIDE_BIRGHTNESS);
643     EXPECT_FALSE(isOverride);
644     bool isRestore = DisplayPowerMgrClient::GetInstance().RestoreBrightness();
645     EXPECT_FALSE(isRestore);
646     DISPLAY_HILOGI(LABEL_TEST, "BoostAndOverrideMutuallyExclusive: fun is end");
647 }
648 
649 /**
650  * @tc.name: BoostAndOverrideMutuallyExclusive2
651  * @tc.desc: Test BoostBrightness and OverrideBrightness are mutually exclusive
652  * @tc.type: FUNC
653  */
654 HWTEST_F(DisplayPowerMgrBrightnessTest, BoostAndOverrideMutuallyExclusive2, TestSize.Level0)
655 {
656     DISPLAY_HILOGI(LABEL_TEST, "BoostAndOverrideMutuallyExclusive2: fun is start");
657     const uint32_t BOOST_TIME = 50000;
658     const uint32_t OVERRIDE_BIRGHTNESS = 255;
659     bool isOverride = DisplayPowerMgrClient::GetInstance().OverrideBrightness(OVERRIDE_BIRGHTNESS);
660     EXPECT_TRUE(isOverride);
661     bool isBoost = DisplayPowerMgrClient::GetInstance().BoostBrightness(BOOST_TIME);
662     EXPECT_FALSE(isBoost);
663     bool isCancel = DisplayPowerMgrClient::GetInstance().CancelBoostBrightness();
664     EXPECT_FALSE(isCancel);
665     DISPLAY_HILOGI(LABEL_TEST, "BoostAndOverrideMutuallyExclusive2: fun is end");
666 }
667 
668 /**
669  * @tc.name: DisplayPowerMgrBoostBrightnessTimeout1
670  * @tc.desc: Test BoostBrightness timeout restore system brightness
671  * @tc.type: FUNC
672  */
673 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrBoostBrightnessTimeout1, TestSize.Level0)
674 {
675     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessTimeout1: fun is start");
676     uint32_t beforeValue = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
677     const uint32_t BOOST_BRIGHTNESS_TIME = 100;
678     bool isBoost = DisplayPowerMgrClient::GetInstance().BoostBrightness(BOOST_BRIGHTNESS_TIME);
679     EXPECT_TRUE(isBoost);
680     const int sleepTime = 200000;
681     usleep(sleepTime); // sleep 200ms, wait for setting update
682     uint32_t currentValue = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
683     EXPECT_EQ(beforeValue, currentValue);
684     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessTimeout1: fun is end");
685 }
686 
687 /**
688  * @tc.name: DisplayPowerMgrBoostBrightnessTimeout2
689  * @tc.desc: Test BoostBrightness timeout brightness adjustment can be called
690  * @tc.type: FUNC
691  */
692 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrBoostBrightnessTimeout2, TestSize.Level0)
693 {
694     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessTimeout2: fun is start");
695     const uint32_t SET_BRIGHTNESS = 106;
696     const uint32_t BOOST_BRIGHTNESS_TIME = 100;
697     const int sleepTime = 100000;
698     bool isBoost = DisplayPowerMgrClient::GetInstance().BoostBrightness(BOOST_BRIGHTNESS_TIME);
699     EXPECT_TRUE(isBoost);
700     usleep(sleepTime); // sleep 100ms, wait for cancel BoostBrightness
701     bool isSet = DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS);
702     EXPECT_TRUE(isSet);
703     uint32_t currentValue = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
704     EXPECT_EQ(SET_BRIGHTNESS, currentValue);
705     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessTimeout2: fun is end");
706 }
707 
708 /**
709  * @tc.name: DisplayPowerMgrBoostBrightnessCancel1
710  * @tc.desc: Test BoostBrightness Cancel restore system brightness
711  * @tc.type: FUNC
712  */
713 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrBoostBrightnessCancel1, TestSize.Level0)
714 {
715     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessCancel1: fun is start");
716     const uint32_t SET_BRIGHTNESS = 106;
717     DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS);
718     const int32_t SET_SLEEP_TIME = 200000;
719     usleep(SET_SLEEP_TIME); // sleep 200ms, wait for setBrightness
720     const uint32_t BOOST_BRIGHTNESS_TIME = 10000;
721     const int SLEEP_TIME = 100000;
722     bool isBoost = DisplayPowerMgrClient::GetInstance().BoostBrightness(BOOST_BRIGHTNESS_TIME);
723     EXPECT_TRUE(isBoost);
724     bool isCancel = DisplayPowerMgrClient::GetInstance().CancelBoostBrightness();
725     EXPECT_TRUE(isCancel);
726     usleep(SLEEP_TIME); // sleep 100ms, wait for cancel BoostBrightness
727     uint32_t currentValue = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
728     EXPECT_EQ(SET_BRIGHTNESS, currentValue) << "beforeValue: " << SET_BRIGHTNESS << " currentVal: " << currentValue;
729     DISPLAY_HILOGI(LABEL_TEST, "BoostBrightnessCancel1: beforeValue: %{public}d, currentVal: %{public}d",
730         SET_BRIGHTNESS, currentValue);
731     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessCancel1: fun is end");
732 }
733 
734 /**
735  * @tc.name: DisplayPowerMgrBoostBrightnessCancel2
736  * @tc.desc: Test BoostBrightness Cancel brightness adjustment can be called
737  * @tc.type: FUNC
738  */
739 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrBoostBrightnessCancel2, TestSize.Level0)
740 {
741     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessCancel2: fun is start");
742     const uint32_t BOOST_BRIGHTNESS_TIME = 10000;
743     bool isBoost = DisplayPowerMgrClient::GetInstance().BoostBrightness(BOOST_BRIGHTNESS_TIME);
744     EXPECT_TRUE(isBoost);
745     bool isCancel = DisplayPowerMgrClient::GetInstance().CancelBoostBrightness();
746     EXPECT_TRUE(isCancel);
747     const uint32_t SET_BRIGHTNESS_VALUE = 111;
748     bool isSet = DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS_VALUE);
749     EXPECT_TRUE(isSet);
750     uint32_t currentValue = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
751     EXPECT_EQ(SET_BRIGHTNESS_VALUE, currentValue);
752     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessCancel2: fun is end");
753 }
754 
755 /**
756  * @tc.name: DisplayPowerMgrBoostBrightnessNotAdjust
757  * @tc.desc: Test BoostBrightness do not adjust brightness, but update cachedSettingBrightness
758  * @tc.type: FUNC
759  */
760 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrBoostBrightnessNotAdjust, TestSize.Level0)
761 {
762     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessNotAdjust: fun is start");
763     const uint32_t SET_BRIGHTNESS = 107;
764     const uint32_t BOOST_BRIGHTNESS_TIME = 10000;
765     bool isBoost = DisplayPowerMgrClient::GetInstance().BoostBrightness(BOOST_BRIGHTNESS_TIME);
766     EXPECT_TRUE(isBoost);
767     bool isSet = DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS);
768     EXPECT_FALSE(isSet);
769     DisplayPowerMgrClient::GetInstance().CancelBoostBrightness();
770     uint32_t currentValue = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
771     EXPECT_EQ(SET_BRIGHTNESS, currentValue);
772     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessNotAdjust: fun is end");
773 }
774 
775 /**
776  * @tc.name: DisplayPowerMgrBoostBrightnessScreenOff
777  * @tc.desc: Test BoostBrightness off Disable the call
778  * @tc.type: FUNC
779  */
780 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrBoostBrightnessScreenOff, TestSize.Level0)
781 {
782     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessScreenOff: fun is start");
783     DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_OFF);
784     const uint32_t BOOST_BRIGHTNESS_TIME = 10000;
785     bool isBoost = DisplayPowerMgrClient::GetInstance().BoostBrightness(BOOST_BRIGHTNESS_TIME);
786     EXPECT_FALSE(isBoost);
787     bool isCancel = DisplayPowerMgrClient::GetInstance().CancelBoostBrightness();
788     EXPECT_FALSE(isCancel);
789     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessScreenOff: fun is end");
790 }
791 
792 /**
793  * @tc.name: DisplayPowerMgrBoostBrightnessMultipleCalls
794  * @tc.desc: Test BoostBrightness multiple calls
795  * @tc.type: FUNC
796  */
797 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrBoostBrightnessMultipleCalls, TestSize.Level0)
798 {
799     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessMultipleCalls: fun is start");
800     const uint32_t SET_BRIGHTNESS = 108;
801     const uint32_t COUNT = 3;
802     const uint32_t TIMEOUT = 100;
803     const uint32_t SLEEP_TIME = 200000;
804     const uint32_t UPDATE_TIME = 20000;
805     for (uint32_t i = 0; i < COUNT; ++i) {
806         bool isBoost = DisplayPowerMgrClient::GetInstance().BoostBrightness(TIMEOUT);
807         usleep(UPDATE_TIME); // wait for set newest BoostBrightness time
808         EXPECT_TRUE(isBoost);
809     }
810     // Brightness adjustment is not allowed
811     bool isSet = DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS);
812     EXPECT_FALSE(isSet);
813     // Wait for a timeout
814     usleep(SLEEP_TIME);
815     bool isCancel = DisplayPowerMgrClient::GetInstance().CancelBoostBrightness();
816     EXPECT_FALSE(isCancel);
817     const uint32_t SET_BRIGHTNESS_VALUE = 222;
818     isSet = DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS_VALUE);
819     EXPECT_TRUE(isSet);
820     uint32_t currentVal = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
821     EXPECT_EQ(SET_BRIGHTNESS_VALUE, currentVal);
822     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessMultipleCalls: fun is end");
823 }
824 
825 /**
826  * @tc.name: DisplayPowerMgrAdjustBrightness001
827  * @tc.desc: Test AdjustBrightness
828  * @tc.type: FUNC
829  */
830 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrAdjustBrightness001, TestSize.Level0)
831 {
832     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrAdjustBrightness001: fun is start");
833     bool ret = DisplayPowerMgrClient::GetInstance().AdjustBrightness(0, 3000);
834     EXPECT_TRUE(ret);
835     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrAdjustBrightness001: fun is end");
836 }
837 
838 /**
839  * @tc.name: DisplayPowerMgrAdjustBrightness002
840  * @tc.desc: Test AutoAdjustBrightness
841  * @tc.type: FUNC
842  */
843 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrAdjustBrightness002, TestSize.Level0)
844 {
845     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrAdjustBrightness002: fun is start");
846     bool ret = DisplayPowerMgrClient::GetInstance().AutoAdjustBrightness(true);
847     if (ret) {
848         DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrAdjustBrightness002: is supported");
849         ret = DisplayPowerMgrClient::GetInstance().AutoAdjustBrightness(false);
850         EXPECT_TRUE(ret);
851     } else {
852         DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrAdjustBrightness002: is not supported");
853         EXPECT_FALSE(ret);
854     }
855 }
856 
857 /**
858  * @tc.name: DisplayPowerMgrAdjustBrightness003
859  * @tc.desc: Test IsAutoAdjustBrightness
860  * @tc.type: FUNC
861  * @tc.require: issueI5YZQR
862  */
863 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrAdjustBrightness003, TestSize.Level0)
864 {
865     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrAdjustBrightness003: fun is start");
866     bool ret = DisplayPowerMgrClient::GetInstance().IsAutoAdjustBrightness();
867     DisplayPowerMgrClient::GetInstance().AutoAdjustBrightness(false);
868     EXPECT_EQ(DisplayPowerMgrClient::GetInstance().IsAutoAdjustBrightness(), false);
869     DisplayPowerMgrClient::GetInstance().AutoAdjustBrightness(ret);
870     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrAdjustBrightness003: fun is end");
871 }
872 
873 /**
874  * @tc.name: DisplayPowerMgrScreenBrightnessEquality001
875  * @tc.desc: Test whether the screen brightness is equal after the screen is on and before the screen is off
876  * @tc.type: FUNC
877  * @tc.require: issueI5YZQR
878  */
879 HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrScreenBrightnessEquality001, TestSize.Level0)
880 {
881     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrScreenBrightnessEquality001: fun is start");
882     uint32_t deviceBrightness1 = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
883     DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_OFF);
884     DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_ON);
885     uint32_t deviceBrightness2 = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness();
886     EXPECT_EQ(deviceBrightness1, deviceBrightness2);
887     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrScreenBrightnessEquality001: fun is end");
888 }
889 } // namespace
890