• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "display_mock_object_test.h"
17 #include "display_log.h"
18 #include "display_power_mgr_client.h"
19 #include "display_power_mgr_proxy.h"
20 #include "mock_display_remote_object.h"
21 #include "power_state_machine_info.h"
22 
23 using namespace testing::ext;
24 using namespace OHOS::PowerMgr;
25 using namespace OHOS::DisplayPowerMgr;
26 using namespace OHOS;
27 using namespace std;
28 
29 namespace {
30 static constexpr uint32_t BRIGHTNESS_SETTING_VALUE = 50;
31 static constexpr uint32_t BRIGHTNESS_OVERRIDE_VALUE = 100;
32 static constexpr uint32_t BRIGHTNESS_DURATION = 0;
33 static constexpr uint32_t BRIGHTNESS_NONE_VALUE = 0;
34 static constexpr uint32_t DISPLAY_ID = 0;
35 static constexpr uint32_t MAIN_ID_PROXY = 0;
36 static constexpr uint32_t REASON = 0;
37 static constexpr int32_t BRIGHTNESS_ADJUST_VALUE = 150;
38 static constexpr int32_t TIMEOUT_MS = 500;
39 static constexpr double DISCOUNT_VALUE = 0.30;
40 } // namespace
41 
OnDisplayStateChanged(uint32_t displayId,DisplayPowerMgr::DisplayState state,uint32_t reason)42 void DisplayMockObjectTest::DisplayPowerMgrTestCallback::OnDisplayStateChanged(
43     uint32_t displayId, DisplayPowerMgr::DisplayState state, uint32_t reason)
44 {
45     DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrTestCallback::OnDisplayStateChangedStub");
46 }
47 
48 namespace {
49 /**
50  * @tc.name: DisplayMockObjectTest_001
51  * @tc.desc: test DisplayPowerMgrProxy function(IRemoteObject is mock, "SendRequest" function return false)
52  * @tc.type: FUNC
53  * @tc.require: issueI5YZQR
54  */
55 HWTEST_F(DisplayMockObjectTest, DisplayMockObjectTest_001, TestSize.Level0)
56 {
57     sptr<MockDisplayRemoteObject> sptrRemoteObj = new MockDisplayRemoteObject();
58     auto sptrDisplayProxy = std::make_shared<DisplayPowerMgr::DisplayPowerMgrProxy>(sptrRemoteObj);
59     EXPECT_FALSE(sptrDisplayProxy->SetDisplayState(DISPLAY_ID, DisplayPowerMgr::DisplayState::DISPLAY_ON, REASON));
60     EXPECT_NE(DisplayPowerMgr::DisplayState::DISPLAY_ON, sptrDisplayProxy->GetDisplayState(DISPLAY_ID));
61     std::vector<uint32_t> result;
62     result.push_back(DISPLAY_ID);
63     EXPECT_NE(result, sptrDisplayProxy->GetDisplayIds());
64     EXPECT_EQ(MAIN_ID_PROXY, sptrDisplayProxy->GetMainDisplayId());
65     EXPECT_FALSE(sptrDisplayProxy->SetBrightness(BRIGHTNESS_SETTING_VALUE, DISPLAY_ID));
66     EXPECT_FALSE(sptrDisplayProxy->DiscountBrightness(DISCOUNT_VALUE, DISPLAY_ID));
67     EXPECT_FALSE(sptrDisplayProxy->OverrideBrightness(BRIGHTNESS_OVERRIDE_VALUE, DISPLAY_ID));
68     EXPECT_FALSE(sptrDisplayProxy->RestoreBrightness(DISPLAY_ID));
69     EXPECT_EQ(BRIGHTNESS_NONE_VALUE, sptrDisplayProxy->GetBrightness(DISPLAY_ID));
70     EXPECT_EQ(BRIGHTNESS_NONE_VALUE, sptrDisplayProxy->GetDeviceBrightness(DISPLAY_ID));
71     EXPECT_EQ(BRIGHTNESS_NONE_VALUE, sptrDisplayProxy->GetDefaultBrightness());
72     EXPECT_EQ(BRIGHTNESS_NONE_VALUE, sptrDisplayProxy->GetMaxBrightness());
73     EXPECT_EQ(BRIGHTNESS_NONE_VALUE, sptrDisplayProxy->GetMinBrightness());
74     EXPECT_FALSE(sptrDisplayProxy->AutoAdjustBrightness(true));
75     EXPECT_FALSE(sptrDisplayProxy->AdjustBrightness(DISPLAY_ID, BRIGHTNESS_ADJUST_VALUE, BRIGHTNESS_DURATION));
76     EXPECT_FALSE(sptrDisplayProxy->AutoAdjustBrightness(false));
77     EXPECT_FALSE(sptrDisplayProxy->IsAutoAdjustBrightness());
78     EXPECT_FALSE(sptrDisplayProxy->BoostBrightness(TIMEOUT_MS, DISPLAY_ID));
79     EXPECT_FALSE(sptrDisplayProxy->CancelBoostBrightness(DISPLAY_ID));
80 }
81 } //namespace
82