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_test.h"
17 #include "display_log.h"
18 #include "display_mgr_errors.h"
19 #include "display_power_mgr_client.h"
20 #include "display_power_mgr_proxy.h"
21 #include "ipc_object_stub.h"
22 #include "mock_display_remote_object.h"
23 #include "power_state_machine_info.h"
24 #include <hisysevent.h>
25
26 using namespace testing::ext;
27 using namespace OHOS::HiviewDFX;
28 using namespace OHOS::PowerMgr;
29 using namespace OHOS::DisplayPowerMgr;
30 using namespace OHOS;
31 using namespace std;
32
33 namespace {
34 static constexpr uint32_t BRIGHTNESS_SETTING_VALUE = 50;
35 static constexpr uint32_t BRIGHTNESS_OVERRIDE_VALUE = 100;
36 static constexpr uint32_t BRIGHTNESS_DURATION = 0;
37 static constexpr uint32_t BRIGHTNESS_NONE_VALUE = 0;
38 static constexpr uint32_t CODE_VALUE = 100;
39 static constexpr uint32_t DISPLAY_ID = 0;
40 static constexpr uint32_t MAIN_ID = 0;
41 static constexpr uint32_t REASON = 0;
42 static constexpr int32_t BRIGHTNESS_ADJUST_VALUE = 150;
43 static constexpr int32_t TIMEOUT_MS = 500;
44 static constexpr double DISCOUNT_VALUE = 0.30;
45 } // namespace
46
OnDisplayStateChanged(uint32_t displayId,DisplayPowerMgr::DisplayState state)47 void DisplayMockTest::DisplayPowerMgrTestCallback::OnDisplayStateChanged(
48 uint32_t displayId, DisplayPowerMgr::DisplayState state)
49 {
50 DISPLAY_HILOGI(LABEL_TEST, "DisplayPowerMgrTestCallback::OnDisplayStateChangedStub");
51 }
52
53 namespace {
54 /**
55 * @tc.name: DisplayMockTest_001
56 * @tc.desc: test DisplayPowerCallbackStub function
57 * @tc.type: FUNC
58 * @tc.require: issueI5YZQR
59 */
60 HWTEST_F(DisplayMockTest, DisplayMockTest_001, TestSize.Level0)
61 {
62 sptr<DisplayPowerCallbackStub> callbackPtr = new DisplayMockTest::DisplayPowerMgrTestCallback();
63 MessageParcel data;
64 MessageParcel reply;
65 MessageOption option;
66 EXPECT_NE(ERR_OK, callbackPtr->OnRemoteRequest(CODE_VALUE, data, reply, option));
67 }
68
69 /**
70 * @tc.name: DisplayMockTest_002
71 * @tc.desc: test DisplayPowerCallbackStub function
72 * @tc.type: FUNC
73 * @tc.require: issueI5YZQR
74 */
75 HWTEST_F(DisplayMockTest, DisplayMockTest_002, TestSize.Level0)
76 {
77 sptr<DisplayPowerCallbackStub> callbackPtr = new DisplayMockTest::DisplayPowerMgrTestCallback();
78 MessageParcel data;
79 MessageParcel reply;
80 MessageOption option;
81 uint32_t code = static_cast<int32_t>(IDisplayPowerCallback::ON_DISPLAY_STATE_CHANGED);
82 EXPECT_NE(ERR_OK, callbackPtr->OnRemoteRequest(code, data, reply, option));
83 }
84
85 /**
86 * @tc.name: DisplayMockTest_003
87 * @tc.desc: test DisplayPowerMgrProxy function(IRemoteObject and IDisplayPowerCallback is not null)
88 * @tc.type: FUNC
89 * @tc.require: issueI5YZQR
90 */
91 HWTEST_F(DisplayMockTest, DisplayMockTest_003, TestSize.Level0)
92 {
93 sptr<MockDisplayRemoteObject> sptrRemoteObj = new MockDisplayRemoteObject();
94 auto sptrDisplayProxy = std::make_shared<DisplayPowerMgr::DisplayPowerMgrProxy>(sptrRemoteObj);
95 EXPECT_FALSE(sptrDisplayProxy->SetDisplayState(DISPLAY_ID, DisplayPowerMgr::DisplayState::DISPLAY_ON, REASON));
96 EXPECT_NE(DisplayPowerMgr::DisplayState::DISPLAY_ON, sptrDisplayProxy->GetDisplayState(DISPLAY_ID));
97 std::vector<uint32_t> result;
98 result.push_back(DISPLAY_ID);
99 EXPECT_NE(result, sptrDisplayProxy->GetDisplayIds());
100 EXPECT_EQ(MAIN_ID, sptrDisplayProxy->GetMainDisplayId());
101 EXPECT_FALSE(sptrDisplayProxy->SetBrightness(BRIGHTNESS_SETTING_VALUE, DISPLAY_ID));
102 EXPECT_FALSE(sptrDisplayProxy->DiscountBrightness(DISCOUNT_VALUE, DISPLAY_ID));
103 EXPECT_FALSE(sptrDisplayProxy->OverrideBrightness(BRIGHTNESS_OVERRIDE_VALUE, DISPLAY_ID));
104 EXPECT_FALSE(sptrDisplayProxy->RestoreBrightness(DISPLAY_ID));
105 EXPECT_EQ(BRIGHTNESS_NONE_VALUE, sptrDisplayProxy->GetBrightness(DISPLAY_ID));
106 EXPECT_EQ(BRIGHTNESS_NONE_VALUE, sptrDisplayProxy->GetDeviceBrightness(DISPLAY_ID));
107 EXPECT_EQ(BRIGHTNESS_NONE_VALUE, sptrDisplayProxy->GetDefaultBrightness());
108 EXPECT_EQ(BRIGHTNESS_NONE_VALUE, sptrDisplayProxy->GetMaxBrightness());
109 EXPECT_EQ(BRIGHTNESS_NONE_VALUE, sptrDisplayProxy->GetMinBrightness());
110 EXPECT_FALSE(sptrDisplayProxy->AdjustBrightness(DISPLAY_ID, BRIGHTNESS_ADJUST_VALUE, BRIGHTNESS_DURATION));
111 EXPECT_FALSE(sptrDisplayProxy->AutoAdjustBrightness(true));
112 EXPECT_FALSE(sptrDisplayProxy->AutoAdjustBrightness(false));
113 EXPECT_FALSE(sptrDisplayProxy->IsAutoAdjustBrightness());
114 EXPECT_FALSE(sptrDisplayProxy->BoostBrightness(TIMEOUT_MS, DISPLAY_ID));
115 EXPECT_FALSE(sptrDisplayProxy->CancelBoostBrightness(DISPLAY_ID));
116 }
117 } // namespace
118