From 2d1031afa5af08a01877fc1de764c60c225d3282 Mon Sep 17 00:00:00 2001 From: zblue Date: Tue, 9 Aug 2022 12:38:13 +0800 Subject: [PATCH] test: add DiscountBrightness Interface unittest case Signed-off-by: zblue --- .../native/display_power_mgr_client.cpp | 9 + .../native/include/display_power_mgr_client.h | 1 + .../native/include/idisplay_power_mgr.h | 4 +- .../include/display_power_mgr_service.h | 4 +- service/native/include/screen_controller.h | 2 +- .../native/src/display_power_mgr_service.cpp | 29 +- service/native/src/screen_controller.cpp | 10 +- .../zidl/include/display_power_mgr_proxy.h | 1 + service/zidl/include/display_power_mgr_stub.h | 1 + service/zidl/src/display_power_mgr_proxy.cpp | 33 ++ service/zidl/src/display_power_mgr_stub.cpp | 17 + .../src/display_power_mgr_brightness_test.cpp | 296 +++++++++++++++++- 12 files changed, 376 insertions(+), 31 deletions(-) diff --git a/frameworks/native/display_power_mgr_client.cpp b/frameworks/native/display_power_mgr_client.cpp index fd57b1d..7129d56 100644 --- a/frameworks/native/display_power_mgr_client.cpp +++ b/frameworks/native/display_power_mgr_client.cpp @@ -238,5 +238,14 @@ bool DisplayPowerMgrClient::CancelBoostBrightness(uint32_t displayId) RETURN_IF_WITH_RET(proxy == nullptr, false); return proxy->CancelBoostBrightness(displayId); } + +uint32_t DisplayPowerMgrClient::GetDeviceBrightness(uint32_t displayId) +{ + auto proxy = GetProxy(); + if (proxy == nullptr) { + return false; + } + return proxy->GetDeviceBrightness(displayId); +} } // namespace DisplayPowerMgr } // namespace OHOS diff --git a/interfaces/innerkits/native/include/display_power_mgr_client.h b/interfaces/innerkits/native/include/display_power_mgr_client.h index aecb575..6a13219 100644 --- a/interfaces/innerkits/native/include/display_power_mgr_client.h +++ b/interfaces/innerkits/native/include/display_power_mgr_client.h @@ -51,6 +51,7 @@ public: bool RegisterCallback(sptr callback); bool BoostBrightness(int32_t timeoutMs, uint32_t displayId = 0); bool CancelBoostBrightness(uint32_t displayId = 0); + uint32_t GetDeviceBrightness(uint32_t displayId = 0); private: class DisplayDeathRecipient : public IRemoteObject::DeathRecipient { diff --git a/interfaces/innerkits/native/include/idisplay_power_mgr.h b/interfaces/innerkits/native/include/idisplay_power_mgr.h index ff4304d..006508f 100644 --- a/interfaces/innerkits/native/include/idisplay_power_mgr.h +++ b/interfaces/innerkits/native/include/idisplay_power_mgr.h @@ -44,7 +44,8 @@ public: IS_AUTO_ADJUST_BRIGHTNESS, REGISTER_CALLBACK, BOOST_BRIGHTNESS, - CANCEL_BOOST_BRIGHTNESS + CANCEL_BOOST_BRIGHTNESS, + GET_DEVICE_BRIGHTNESS }; virtual bool SetDisplayState(uint32_t id, DisplayState state, uint32_t reason) = 0; @@ -65,6 +66,7 @@ public: virtual bool RegisterCallback(sptr callback) = 0; virtual bool BoostBrightness(int32_t timeoutMs, uint32_t displayId) = 0; virtual bool CancelBoostBrightness(uint32_t displayId) = 0; + virtual uint32_t GetDeviceBrightness(uint32_t displayId) = 0; DECLARE_INTERFACE_DESCRIPTOR(u"ohos.displaypowermgr.IDisplayPowerMgr"); }; diff --git a/service/native/include/display_power_mgr_service.h b/service/native/include/display_power_mgr_service.h index 14c3fa3..e38d5a6 100644 --- a/service/native/include/display_power_mgr_service.h +++ b/service/native/include/display_power_mgr_service.h @@ -17,7 +17,6 @@ #define DISPLAYMGR_DISPLAY_MGR_SERVICE_H #include -#include #include #include #include @@ -59,13 +58,14 @@ public: virtual bool RegisterCallback(sptr callback) override; virtual bool BoostBrightness(int32_t timeoutMs, uint32_t displayId) override; virtual bool CancelBoostBrightness(uint32_t displayId) override; + virtual uint32_t GetDeviceBrightness(uint32_t displayId) override; virtual int32_t Dump(int32_t fd, const std::vector& args) override; void NotifyStateChangeCallback(uint32_t displayId, DisplayState state); void Init(); [[maybe_unused]] void RegisterSettings(); [[maybe_unused]] void UnregisterSettings(); static uint32_t GetSafeBrightness(uint32_t value); - static double GetSafeDiscount(double discount); + static double GetSafeDiscount(double discount, uint32_t brightness); private: class CallbackDeathRecipient : public IRemoteObject::DeathRecipient { diff --git a/service/native/include/screen_controller.h b/service/native/include/screen_controller.h index f4e1888..775fec0 100644 --- a/service/native/include/screen_controller.h +++ b/service/native/include/screen_controller.h @@ -50,6 +50,7 @@ public: bool SetBrightness(uint32_t value, uint32_t gradualDuration = 0); uint32_t GetBrightness(); + uint32_t GetDeviceBrightness(); bool DiscountBrightness(double discount, uint32_t gradualDuration = 0); bool OverrideBrightness(uint32_t value, uint32_t gradualDuration = 0); @@ -73,7 +74,6 @@ private: bool CanOverrideBrightness(); bool CanBoostBrightness(); bool UpdateBrightness(uint32_t value, uint32_t gradualDuration = 0); - uint32_t GetDeviceBrightness(); void SetSettingBrightness(); uint32_t GetScreenOnBrightness() const; void BrightnessSettingUpdateFunc(const std::string& key); diff --git a/service/native/src/display_power_mgr_service.cpp b/service/native/src/display_power_mgr_service.cpp index 18d9dde..2171c34 100644 --- a/service/native/src/display_power_mgr_service.cpp +++ b/service/native/src/display_power_mgr_service.cpp @@ -139,13 +139,14 @@ bool DisplayPowerMgrService::SetBrightness(uint32_t value, uint32_t displayId) bool DisplayPowerMgrService::DiscountBrightness(double discount, uint32_t displayId) { - auto safeDiscount = GetSafeDiscount(discount); - DISPLAY_HILOGI(FEAT_BRIGHTNESS, "DiscountBrightness displayId=%{public}u, discount-%{public}lf", - displayId, safeDiscount); auto iter = controllerMap_.find(displayId); if (iter == controllerMap_.end()) { return false; } + auto brightness = iter->second->GetBrightness(); + auto safeDiscount = GetSafeDiscount(discount, brightness); + DISPLAY_HILOGI(FEAT_BRIGHTNESS, "DiscountBrightness displayId=%{public}u, discount-%{public}lf", + displayId, safeDiscount); return iter->second->DiscountBrightness(safeDiscount); } @@ -313,6 +314,16 @@ bool DisplayPowerMgrService::CancelBoostBrightness(uint32_t displayId) return iter->second->CancelBoostBrightness(); } +uint32_t DisplayPowerMgrService::GetDeviceBrightness(uint32_t displayId) +{ + DISPLAY_HILOGD(FEAT_BRIGHTNESS, "GetDeviceBrightness displayId=%{public}u", displayId); + auto iter = controllerMap_.find(displayId); + if (iter == controllerMap_.end()) { + return BRIGHTNESS_OFF; + } + return iter->second->GetDeviceBrightness(); +} + void DisplayPowerMgrService::NotifyStateChangeCallback(uint32_t displayId, DisplayState state) { if (callback_ != nullptr) { @@ -419,7 +430,7 @@ void DisplayPowerMgrService::AmbientLightCallback(SensorEvent *event) } AmbientLightData* data = (AmbientLightData*)event->data; DISPLAY_HILOGI(FEAT_BRIGHTNESS, "AmbientLightCallback: %{public}f", data->intensity); - int32_t brightness = static_cast(mainDisp->second->GetBrightness()); + int32_t brightness = static_cast(mainDisp->second->GetDeviceBrightness()); if (pms->CalculateBrightness(data->intensity, brightness)) { pms->AdjustBrightness(mainDispId, brightness, AUTO_ADJUST_BRIGHTNESS_DURATION); } @@ -490,9 +501,9 @@ uint32_t DisplayPowerMgrService::GetSafeBrightness(uint32_t value) return brightnessValue; } -double DisplayPowerMgrService::GetSafeDiscount(double discount) +double DisplayPowerMgrService::GetSafeDiscount(double discount, uint32_t brightness) { - auto safeDiscount = round(discount * 100) / 100; + auto safeDiscount = discount; if (safeDiscount > DISCOUNT_MAX) { DISPLAY_HILOGD(COMP_SVC, "discount value is greater than max, discount=%{public}lf", discount); safeDiscount = DISCOUNT_MAX; @@ -501,6 +512,12 @@ double DisplayPowerMgrService::GetSafeDiscount(double discount) DISPLAY_HILOGD(COMP_SVC, "discount value is less than min, discount=%{public}lf", discount); safeDiscount = DISCOUNT_MIN; } + if (static_cast(BRIGHTNESS_MIN / discount) > BRIGHTNESS_MAX) { + DISPLAY_HILOGD(COMP_SVC, "brightness than max, brightness=%{public}u, discount=%{public}lf", + static_cast(BRIGHTNESS_MIN / discount), discount); + safeDiscount = static_cast(BRIGHTNESS_MIN / static_cast(brightness)); + } + return safeDiscount; } diff --git a/service/native/src/screen_controller.cpp b/service/native/src/screen_controller.cpp index c5543ef..132b869 100644 --- a/service/native/src/screen_controller.cpp +++ b/service/native/src/screen_controller.cpp @@ -143,6 +143,11 @@ uint32_t ScreenController::GetBrightness() return static_cast(GetDeviceBrightness() / discount_); } +uint32_t ScreenController::GetDeviceBrightness() +{ + return action_->GetBrightness(); +} + bool ScreenController::DiscountBrightness(double discount, uint32_t gradualDuration) { if (!CanDiscountBrightness()) { @@ -376,10 +381,5 @@ double ScreenController::GetDiscount() const { return discount_; } - -uint32_t ScreenController::GetDeviceBrightness() -{ - return action_->GetBrightness(); -} } // namespace DisplayPowerMgr } // namespace OHOS diff --git a/service/zidl/include/display_power_mgr_proxy.h b/service/zidl/include/display_power_mgr_proxy.h index fcc727a..a8318fd 100644 --- a/service/zidl/include/display_power_mgr_proxy.h +++ b/service/zidl/include/display_power_mgr_proxy.h @@ -54,6 +54,7 @@ public: virtual bool RegisterCallback(sptr callback) override; virtual bool BoostBrightness(int32_t timeoutMs, uint32_t displayId) override; virtual bool CancelBoostBrightness(uint32_t displayId) override; + virtual uint32_t GetDeviceBrightness(uint32_t displayId) override; private: static inline BrokerDelegator delegator_; diff --git a/service/zidl/include/display_power_mgr_stub.h b/service/zidl/include/display_power_mgr_stub.h index 257aa9b..1709bf0 100644 --- a/service/zidl/include/display_power_mgr_stub.h +++ b/service/zidl/include/display_power_mgr_stub.h @@ -48,6 +48,7 @@ private: int32_t RegisterCallbackStub(MessageParcel& data, MessageParcel& reply); int32_t BoostBrightnessStub(MessageParcel& data, MessageParcel& reply); int32_t CancelBoostBrightnessStub(MessageParcel& data, MessageParcel& reply); + int32_t GetDeviceBrightnessStub(MessageParcel& data, MessageParcel& reply); }; } // namespace DisplayPowerMgr } // namespace OHOS diff --git a/service/zidl/src/display_power_mgr_proxy.cpp b/service/zidl/src/display_power_mgr_proxy.cpp index 833fc8e..af1dba1 100644 --- a/service/zidl/src/display_power_mgr_proxy.cpp +++ b/service/zidl/src/display_power_mgr_proxy.cpp @@ -613,5 +613,38 @@ bool DisplayPowerMgrProxy::CancelBoostBrightness(uint32_t displayId) return result; } + +uint32_t DisplayPowerMgrProxy::GetDeviceBrightness(uint32_t displayId) +{ + sptr remote = Remote(); + uint32_t result = 0; + + RETURN_IF_WITH_RET(remote == nullptr, result); + + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!data.WriteInterfaceToken(DisplayPowerMgrProxy::GetDescriptor())) { + DISPLAY_HILOGE(COMP_FWK, "DisplayPowerMgrClient::%{public}s write descriptor failed!", __func__); + return result; + } + + WRITE_PARCEL_WITH_RET(data, Uint32, displayId, false); + + int ret = remote->SendRequest(static_cast(IDisplayPowerMgr::GET_DEVICE_BRIGHTNESS), + data, reply, option); + if (ret != ERR_OK) { + DISPLAY_HILOGE(COMP_FWK, "DisplayPowerMgrProxy::%{public}s SendRequest is failed,%d", __func__, ret); + return result; + } + + if (!reply.ReadUint32(result)) { + DISPLAY_HILOGE(COMP_FWK, "Readback fail!"); + return result; + } + + return result; +} } // namespace DisplayPowerMgr } // namespace OHOS diff --git a/service/zidl/src/display_power_mgr_stub.cpp b/service/zidl/src/display_power_mgr_stub.cpp index 5fc84f2..3a8bd6a 100644 --- a/service/zidl/src/display_power_mgr_stub.cpp +++ b/service/zidl/src/display_power_mgr_stub.cpp @@ -98,6 +98,9 @@ int32_t DisplayPowerMgrStub::OnRemoteRequest(uint32_t code, MessageParcel &data, case static_cast(IDisplayPowerMgr::CANCEL_BOOST_BRIGHTNESS): ret = CancelBoostBrightnessStub(data, reply); break; + case static_cast(IDisplayPowerMgr::GET_DEVICE_BRIGHTNESS): + ret = GetDeviceBrightnessStub(data, reply); + break; default: ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option); break; @@ -350,5 +353,19 @@ int32_t DisplayPowerMgrStub::CancelBoostBrightnessStub(MessageParcel& data, Mess } return ERR_OK; } + +int32_t DisplayPowerMgrStub::GetDeviceBrightnessStub(MessageParcel& data, MessageParcel& reply) +{ + uint32_t displayId = 0; + + READ_PARCEL_WITH_RET(data, Uint32, displayId, E_READ_PARCEL_ERROR); + + uint32_t ret = GetDeviceBrightness(displayId); + if (!reply.WriteUint32(ret)) { + DISPLAY_HILOGE(COMP_SVC, "Failed to write GetDeviceBrightness return value"); + return E_WRITE_PARCEL_ERROR; + } + return ERR_OK; +} } // namespace DisplayPowerMgr } // namespace OHOS diff --git a/test/unittest/common/native/src/display_power_mgr_brightness_test.cpp b/test/unittest/common/native/src/display_power_mgr_brightness_test.cpp index 7281c64..8a360e7 100644 --- a/test/unittest/common/native/src/display_power_mgr_brightness_test.cpp +++ b/test/unittest/common/native/src/display_power_mgr_brightness_test.cpp @@ -31,6 +31,8 @@ public: void SetUp() { DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_ON); + const double DISCOUNT = 1.00; + DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT); } void TearDown() @@ -54,7 +56,7 @@ HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrSetBrightness001, TestSiz bool ret = DisplayPowerMgrClient::GetInstance().SetBrightness(100); EXPECT_TRUE(ret); sleep(1); // wait for gradual animation - uint32_t value = DisplayPowerMgrClient::GetInstance().GetBrightness(); + uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); EXPECT_EQ(value, 100); DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBrightness001: fun is end"); } @@ -99,11 +101,273 @@ HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrSettingBrightness002, Tes } sleep(1); // wait for gradual animation - uint32_t value = DisplayPowerMgrClient::GetInstance().GetBrightness(); + uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); EXPECT_EQ(value, 233); DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrSettingBrightness002: fun is end"); } +/** + * @tc.name: DisplayPowerMgrDiscountBrightnessNormal + * @tc.desc: Test DiscountBrightness the normal test + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightnessNormal, TestSize.Level0) +{ + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessNormal: fun is start"); + const uint32_t SET_BRIGHTNESS = 100; + DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS); + const double DISCOUNT_NORMAL = 0.8; + bool ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_NORMAL); + EXPECT_TRUE(ret); + + uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); + EXPECT_EQ(value, static_cast(SET_BRIGHTNESS * DISCOUNT_NORMAL)); + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessNormal: fun is end"); +} + +/** + * @tc.name: DisplayPowerMgrDiscountBrightnessNormal + * @tc.desc: Test DiscountBrightness when screen is off + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightnessScreenOff, TestSize.Level0) +{ + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessScreenOff: fun is start"); + DisplayPowerMgrClient::GetInstance().SetDisplayState(DisplayState::DISPLAY_OFF); + const double DISCOUNT_VALUE = 0.8; + bool ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_VALUE); + EXPECT_FALSE(ret); + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessScreenOff: fun is end"); +} + +/** + * @tc.name: DisplayPowerMgrDiscountBrightnessBoundary001 + * @tc.desc: Test DiscountBrightness the boundary test + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightnessBoundary001, TestSize.Level0) +{ + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessBoundary001: fun is start"); + const uint32_t SET_BRIGHTNESS = 100; + DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS); + const double DISCOUNT_LOWER_BOUNDARY = 0.01; + bool ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_LOWER_BOUNDARY); + EXPECT_TRUE(ret); + + uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); + uint32_t minBrightness = DisplayPowerMgrClient::GetInstance().GetMinBrightness(); + EXPECT_EQ(value, minBrightness); + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessBoundary001: fun is end"); +} + +/** + * @tc.name: DisplayPowerMgrDiscountBrightnessBoundary002 + * @tc.desc: Test DiscountBrightness the boundary test + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightnessBoundary002, TestSize.Level0) +{ + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessBoundary002: fun is start"); + const uint32_t SET_BRIGHTNESS = 100; + DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS); + const double DISCOUNT_UPPER_BOUNDARY = 1.0; + bool ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_UPPER_BOUNDARY); + EXPECT_TRUE(ret); + + uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); + EXPECT_EQ(value, static_cast(SET_BRIGHTNESS * DISCOUNT_UPPER_BOUNDARY)); + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessBoundary002: fun is end"); +} + +/** + * @tc.name: DisplayPowerMgrDiscountBrightnessAbnormal001 + * @tc.desc: Test DiscountBrightness the abnormal test + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightnessAbnormal001, TestSize.Level0) +{ + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessAbnormal001: fun is start"); + const uint32_t SET_BRIGHTNESS = 100; + DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS); + const double DISCOUNT_BEYOND_LOWER_BOUNDARY = 0.0; + bool ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_BEYOND_LOWER_BOUNDARY); + EXPECT_TRUE(ret); + + uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); + uint32_t minBrightness = DisplayPowerMgrClient::GetInstance().GetMinBrightness(); + EXPECT_EQ(value, minBrightness); + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessAbnormal001: fun is end"); +} + +/** + * @tc.name: DisplayPowerMgrDiscountBrightnessAbnormal002 + * @tc.desc: Test DiscountBrightness the abnormal test + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightnessAbnormal002, TestSize.Level0) +{ + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessAbnormal002: fun is start"); + const uint32_t SET_BRIGHTNESS = 100; + DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS); + const double DISCOUNT_BEYOND_UPPER_BOUNDARY = 2.0; + bool ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_BEYOND_UPPER_BOUNDARY); + EXPECT_TRUE(ret); + + uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); + const double DISCOUNT_MAX_VALUE = 1.0; + EXPECT_EQ(value, static_cast(SET_BRIGHTNESS * DISCOUNT_MAX_VALUE)); + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessAbnormal002: fun is end"); +} + +/** + * @tc.name: DisplayPowerMgrDiscountBrightnessAbnormal003 + * @tc.desc: Test DiscountBrightness the abnormal test + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightnessAbnormal003, TestSize.Level0) +{ + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessAbnormal003: fun is start"); + const uint32_t SET_BRIGHTNESS = 100; + DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS); + const double DISCOUNT_NEGATIVE_VALUE = -1.0; + bool ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_NEGATIVE_VALUE); + EXPECT_TRUE(ret); + + uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); + uint32_t minBrightness = DisplayPowerMgrClient::GetInstance().GetMinBrightness(); + EXPECT_EQ(value, minBrightness); + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightnessAbnormal003: fun is end"); +} + +/** + * @tc.name: DisplayPowerMgrDiscountBrightness001 + * @tc.desc: Test OverrideBrightness after DiscountBrightness, then RestoreBrightness + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightness001, TestSize.Level0) +{ + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightness001: fun is start"); + const uint32_t SET_BRIGHTNESS = 100; + DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS); + const double DISCOUNT_VALUE = 0.8; + bool ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_VALUE); + EXPECT_TRUE(ret); + + uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); + EXPECT_EQ(value, static_cast(DISCOUNT_VALUE * SET_BRIGHTNESS)); + + const uint32_t SET_OVERRIDE_BRIGHTNESS = 200; + DisplayPowerMgrClient::GetInstance().OverrideBrightness(SET_OVERRIDE_BRIGHTNESS); + value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); + EXPECT_EQ(value, static_cast(DISCOUNT_VALUE * SET_OVERRIDE_BRIGHTNESS)); + + DisplayPowerMgrClient::GetInstance().RestoreBrightness(); + value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); + EXPECT_EQ(value, static_cast(DISCOUNT_VALUE * SET_BRIGHTNESS)); + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightness001: fun is end"); +} + +/** + * @tc.name: DisplayPowerMgrDiscountBrightness002 + * @tc.desc: Test DiscountBrightness after OverrideBrightness, then RestoreBrightness + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightness002, TestSize.Level0) +{ + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightness002: fun is start"); + const uint32_t SET_BRIGHTNESS = 100; + DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS); + const uint32_t SET_OVERRIDE_BRIGHTNESS = 200; + DisplayPowerMgrClient::GetInstance().OverrideBrightness(SET_OVERRIDE_BRIGHTNESS); + + const double DISCOUNT_VALUE = 0.8; + double ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_VALUE); + EXPECT_TRUE(ret); + uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); + EXPECT_EQ(value, static_cast(DISCOUNT_VALUE * SET_OVERRIDE_BRIGHTNESS)); + + ret = DisplayPowerMgrClient::GetInstance().RestoreBrightness(); + EXPECT_TRUE(ret); + + value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); + EXPECT_EQ(value, static_cast(DISCOUNT_VALUE * SET_BRIGHTNESS)); + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightness002: fun is end"); +} + +/** + * @tc.name: DisplayPowerMgrDiscountBrightness003 + * @tc.desc: Test DisconutBrightness after BoostBrightness and CancelBoostBrightness + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightness003, TestSize.Level0) +{ + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightness003: fun is start"); + const uint32_t SET_BRIGHTNESS = 100; + DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS); + const uint32_t SET_BOOST_BRIGHTNESS = 10000; + DisplayPowerMgrClient::GetInstance().BoostBrightness(SET_BOOST_BRIGHTNESS); + + const double DISCOUNT_VALUE = 0.8; + bool ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_VALUE); + EXPECT_TRUE(ret); + + uint32_t maxBrightness = DisplayPowerMgrClient::GetInstance().GetMaxBrightness(); + uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); + EXPECT_EQ(value, static_cast(DISCOUNT_VALUE * maxBrightness)); + + DisplayPowerMgrClient::GetInstance().CancelBoostBrightness(); + + value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); + EXPECT_EQ(value, static_cast(DISCOUNT_VALUE * SET_BRIGHTNESS)); + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightness003: fun is end"); +} + +/** + * @tc.name: DisplayPowerMgrDiscountBrightness004 + * @tc.desc: Test BoostBrightness after DisconutBrightness, then CancelBoostBrightness + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightness004, TestSize.Level0) +{ + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightness004: fun is start"); + const uint32_t SET_BRIGHTNESS = 100; + DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS); + const double DISCOUNT_VALUE = 0.8; + bool ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_VALUE); + EXPECT_TRUE(ret); + + const uint32_t SET_BOOST_BRIGHTNESS = 10000; + DisplayPowerMgrClient::GetInstance().BoostBrightness(SET_BOOST_BRIGHTNESS); + uint32_t maxBrightness = DisplayPowerMgrClient::GetInstance().GetMaxBrightness(); + uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); + EXPECT_EQ(value, static_cast(DISCOUNT_VALUE * maxBrightness)); + + DisplayPowerMgrClient::GetInstance().CancelBoostBrightness(); + + value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); + EXPECT_EQ(value, static_cast(DISCOUNT_VALUE * SET_BRIGHTNESS)); + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightness004: fun is end"); +} + +/** + * @tc.name: DisplayPowerMgrDiscountBrightness005 + * @tc.desc: Test DisconutBrightness after SetBrightness, then GetBrightness + * @tc.type: FUNC + */ +HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrDiscountBrightness005, TestSize.Level0) +{ + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightness005: fun is start"); + const uint32_t SET_BRIGHTNESS = 100; + DisplayPowerMgrClient::GetInstance().SetBrightness(SET_BRIGHTNESS); + const double DISCOUNT_VALUE = 0.8; + bool ret = DisplayPowerMgrClient::GetInstance().DiscountBrightness(DISCOUNT_VALUE); + EXPECT_TRUE(ret); + + uint32_t beforeBrightness = DisplayPowerMgrClient::GetInstance().GetBrightness(); + EXPECT_EQ(SET_BRIGHTNESS, beforeBrightness); + DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrDiscountBrightness005: fun is end"); +} + /** * @tc.name: DisplayPowerMgrOverrideBrightness001 * @tc.desc: Test OverrideBrightness @@ -115,7 +379,7 @@ HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrOverrideBrightness001, Te bool ret = DisplayPowerMgrClient::GetInstance().OverrideBrightness(255); EXPECT_TRUE(ret); sleep(1); // wait for gradual animation - uint32_t value = DisplayPowerMgrClient::GetInstance().GetBrightness(); + uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); EXPECT_EQ(value, 255); DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBrightness002: fun is end"); } @@ -134,12 +398,12 @@ HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrOverrideBrightness002, Te ret = DisplayPowerMgrClient::GetInstance().OverrideBrightness(255); EXPECT_TRUE(ret); sleep(1); // wait for gradual animation - uint32_t value = DisplayPowerMgrClient::GetInstance().GetBrightness(); + uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); EXPECT_EQ(value, 255); ret = DisplayPowerMgrClient::GetInstance().RestoreBrightness(); // restore EXPECT_TRUE(ret); sleep(1); // wait for gradual animation - value = DisplayPowerMgrClient::GetInstance().GetBrightness(); + value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); EXPECT_EQ(value, 100); DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBrightness003: fun is end"); } @@ -158,7 +422,7 @@ HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrOverrideBrightness003, Te ret = DisplayPowerMgrClient::GetInstance().SetBrightness(100); EXPECT_FALSE(ret); sleep(1); // wait for gradual animation - uint32_t value = DisplayPowerMgrClient::GetInstance().GetBrightness(); + uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); EXPECT_EQ(value, 255); DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBrightness004: fun is end"); } @@ -176,7 +440,7 @@ HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrOverrideBrightness004, Te sleep(1); // wait for gradual animation ret = DisplayPowerMgrClient::GetInstance().RestoreBrightness(); EXPECT_FALSE(ret); - uint32_t value = DisplayPowerMgrClient::GetInstance().GetBrightness(); + uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); EXPECT_EQ(value, 100); DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBrightness005: fun is end"); } @@ -210,7 +474,7 @@ HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrMaxBrightness001, TestSiz bool ret = DisplayPowerMgrClient::GetInstance().SetBrightness(max + 100); EXPECT_TRUE(ret); sleep(1); // wait for gradual animation - uint32_t value = DisplayPowerMgrClient::GetInstance().GetBrightness(); + uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); EXPECT_EQ(value, max); DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrMaxBrightness001: fun is end"); } @@ -228,7 +492,7 @@ HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrMinBrightness001, TestSiz bool ret = DisplayPowerMgrClient::GetInstance().SetBrightness(0); EXPECT_TRUE(ret); sleep(1); // wait for gradual animation - uint32_t value = DisplayPowerMgrClient::GetInstance().GetBrightness(); + uint32_t value = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); EXPECT_EQ(value, min); DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrMinBrightness001: fun is end"); } @@ -333,11 +597,11 @@ HWTEST_F(DisplayPowerMgrBrightnessTest, BoostAndOverrideMutuallyExclusive2, Test HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrBoostBrightnessTimeout1, TestSize.Level0) { DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessTimeout1: fun is start"); - uint32_t beforeValue = DisplayPowerMgrClient::GetInstance().GetBrightness(); + uint32_t beforeValue = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); bool isBoost = DisplayPowerMgrClient::GetInstance().BoostBrightness(1000); EXPECT_TRUE(isBoost); sleep(2); - uint32_t currentValue = DisplayPowerMgrClient::GetInstance().GetBrightness(); + uint32_t currentValue = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); EXPECT_EQ(beforeValue, currentValue); DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessTimeout1: fun is end"); } @@ -355,7 +619,7 @@ HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrBoostBrightnessTimeout2, sleep(2); bool isSet = DisplayPowerMgrClient::GetInstance().SetBrightness(100); EXPECT_TRUE(isSet); - uint32_t currentValue = DisplayPowerMgrClient::GetInstance().GetBrightness(); + uint32_t currentValue = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); EXPECT_EQ(100, currentValue); DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessTimeout2: fun is end"); } @@ -368,14 +632,14 @@ HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrBoostBrightnessTimeout2, HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrBoostBrightnessCancel1, TestSize.Level0) { DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessCancel1: fun is start"); - uint32_t beforeValue = DisplayPowerMgrClient::GetInstance().GetBrightness(); + uint32_t beforeValue = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); bool isBoost = DisplayPowerMgrClient::GetInstance().BoostBrightness(10000); EXPECT_TRUE(isBoost); sleep(1); bool isCancel = DisplayPowerMgrClient::GetInstance().CancelBoostBrightness(); EXPECT_TRUE(isCancel); sleep(1); - uint32_t currentValue = DisplayPowerMgrClient::GetInstance().GetBrightness(); + uint32_t currentValue = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); EXPECT_EQ(beforeValue, currentValue) << "beforeValue: " << beforeValue << " currentVal: " << currentValue; DISPLAY_HILOGI(LABEL_TEST, "BoostBrightnessCancel1: beforeValue: %{public}d, currentVal: %{public}d", beforeValue, currentValue); @@ -397,7 +661,7 @@ HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrBoostBrightnessCancel2, T EXPECT_TRUE(isCancel); bool isSet = DisplayPowerMgrClient::GetInstance().SetBrightness(111); EXPECT_TRUE(isSet); - uint32_t currentValue = DisplayPowerMgrClient::GetInstance().GetBrightness(); + uint32_t currentValue = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); EXPECT_EQ(111, currentValue); DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessCancel2: fun is end"); } @@ -457,7 +721,7 @@ HWTEST_F(DisplayPowerMgrBrightnessTest, DisplayPowerMgrBoostBrightnessMultipleCa EXPECT_FALSE(isCancel); isSet = DisplayPowerMgrClient::GetInstance().SetBrightness(222); EXPECT_TRUE(isSet); - uint32_t currentVal = DisplayPowerMgrClient::GetInstance().GetBrightness(); + uint32_t currentVal = DisplayPowerMgrClient::GetInstance().GetDeviceBrightness(); EXPECT_EQ(222, currentVal); DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrBoostBrightnessMultipleCalls: fun is end"); } -- Gitee