1 /*
2 * Copyright (c) 2022-2024 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 static constexpr uint32_t DEFAULT_DURATION = 500;
41 static constexpr int32_t ERR_OK = 0;
42 } // namespace
43
OnDisplayStateChanged(uint32_t displayId,DisplayPowerMgr::DisplayState state,uint32_t reason)44 void DisplayMockObjectTest::DisplayPowerMgrTestCallback::OnDisplayStateChanged(
45 uint32_t displayId, DisplayPowerMgr::DisplayState state, uint32_t reason)
46 {
47 DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrTestCallback::OnDisplayStateChangedStub");
48 }
49
50 namespace {
51 /**
52 * @tc.name: DisplayMockObjectTest_001
53 * @tc.desc: test DisplayPowerMgrProxy function(IRemoteObject is mock, "SendRequest" function return false)
54 * @tc.type: FUNC
55 * @tc.require: issueI5YZQR
56 */
57 HWTEST_F(DisplayMockObjectTest, DisplayMockObjectTest_001, TestSize.Level0)
58 {
59 DISPLAY_HILOGI(LABEL_TEST, "DisplayMockObjectTest_001 function start!");
60 sptr<MockDisplayRemoteObject> sptrRemoteObj = new MockDisplayRemoteObject();
61 auto sptrDisplayProxy = std::make_shared<DisplayPowerMgr::DisplayPowerMgrProxy>(sptrRemoteObj);
62 bool bRet = false;
63 EXPECT_NE(sptrDisplayProxy->SetDisplayState(DISPLAY_ID,
64 static_cast<uint32_t>(DisplayPowerMgr::DisplayState::DISPLAY_ON), REASON, bRet), ERR_OK);
65 EXPECT_FALSE(bRet);
66 int32_t state = 0;
67 EXPECT_NE(sptrDisplayProxy->GetDisplayState(DISPLAY_ID, state), ERR_OK);
68 EXPECT_NE(DisplayPowerMgr::DisplayState::DISPLAY_ON, DisplayPowerMgr::DisplayState(state));
69 std::vector<uint32_t> result;
70 result.push_back(DISPLAY_ID);
71 std::vector<uint32_t> ids;
72 EXPECT_NE(sptrDisplayProxy->GetDisplayIds(ids), ERR_OK);
73 EXPECT_NE(result, ids);
74 uint32_t id = 0;
75 EXPECT_NE(sptrDisplayProxy->GetMainDisplayId(id), ERR_OK);
76 EXPECT_EQ(MAIN_ID_PROXY, id);
77 DISPLAY_HILOGI(LABEL_TEST, "DisplayMockObjectTest_001 function end!");
78 }
79
80 /**
81 * @tc.name: DisplayMockObjectTest_002
82 * @tc.desc: test DisplayPowerMgrProxy function(IRemoteObject is mock, "SendRequest" function return false)
83 * @tc.type: FUNC
84 * @tc.require:
85 */
86 HWTEST_F(DisplayMockObjectTest, DisplayMockObjectTest_002, TestSize.Level0)
87 {
88 DISPLAY_HILOGI(LABEL_TEST, "DisplayMockObjectTest_002 function start!");
89 sptr<MockDisplayRemoteObject> sptrRemoteObj = new MockDisplayRemoteObject();
90 auto sptrDisplayProxy = std::make_shared<DisplayPowerMgr::DisplayPowerMgrProxy>(sptrRemoteObj);
91 bool bRet = false;
92 uint32_t brightness = 0;
93 int32_t errCode = 0;
94 EXPECT_NE(sptrDisplayProxy->SetBrightness(BRIGHTNESS_SETTING_VALUE, DISPLAY_ID, false, bRet, errCode), ERR_OK);
95 EXPECT_FALSE(bRet);
96 EXPECT_NE(sptrDisplayProxy->DiscountBrightness(DISCOUNT_VALUE, DISPLAY_ID, bRet), ERR_OK);
97 EXPECT_FALSE(bRet);
98 EXPECT_NE(sptrDisplayProxy->OverrideBrightness(BRIGHTNESS_OVERRIDE_VALUE, DISPLAY_ID, DEFAULT_DURATION, bRet),
99 ERR_OK);
100 EXPECT_FALSE(bRet);
101 EXPECT_NE(sptrDisplayProxy->RestoreBrightness(DISPLAY_ID, DEFAULT_DURATION, bRet), ERR_OK);
102 EXPECT_FALSE(bRet);
103 EXPECT_NE(sptrDisplayProxy->GetBrightness(DISPLAY_ID, brightness), ERR_OK);
104 EXPECT_EQ(BRIGHTNESS_NONE_VALUE, brightness);
105 EXPECT_NE(sptrDisplayProxy->GetDeviceBrightness(DISPLAY_ID, brightness), ERR_OK);
106 EXPECT_EQ(BRIGHTNESS_NONE_VALUE, brightness);
107 EXPECT_NE(sptrDisplayProxy->GetDefaultBrightness(brightness), ERR_OK);
108 EXPECT_EQ(BRIGHTNESS_NONE_VALUE, brightness);
109 EXPECT_NE(sptrDisplayProxy->GetMaxBrightness(brightness), ERR_OK);
110 EXPECT_EQ(BRIGHTNESS_NONE_VALUE, brightness);
111 EXPECT_NE(sptrDisplayProxy->GetMinBrightness(brightness), ERR_OK);
112 EXPECT_EQ(BRIGHTNESS_NONE_VALUE, brightness);
113 EXPECT_NE(sptrDisplayProxy->AdjustBrightness(DISPLAY_ID, BRIGHTNESS_ADJUST_VALUE, BRIGHTNESS_DURATION, bRet),
114 ERR_OK);
115 EXPECT_FALSE(bRet);
116 EXPECT_NE(sptrDisplayProxy->AutoAdjustBrightness(true, bRet), ERR_OK);
117 EXPECT_FALSE(bRet);
118 EXPECT_NE(sptrDisplayProxy->AutoAdjustBrightness(false, bRet), ERR_OK);
119 EXPECT_FALSE(bRet);
120 EXPECT_NE(sptrDisplayProxy->IsAutoAdjustBrightness(bRet), ERR_OK);
121 EXPECT_FALSE(bRet);
122 EXPECT_NE(sptrDisplayProxy->BoostBrightness(TIMEOUT_MS, DISPLAY_ID, bRet), ERR_OK);
123 EXPECT_FALSE(bRet);
124 EXPECT_NE(sptrDisplayProxy->CancelBoostBrightness(DISPLAY_ID, bRet), ERR_OK);
125 EXPECT_FALSE(bRet);
126 DISPLAY_HILOGI(LABEL_TEST, "DisplayMockObjectTest_002 function end!");
127 }
128 } //namespace
129