1e0dac50fSopenharmony_ci/*
2e0dac50fSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3e0dac50fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4e0dac50fSopenharmony_ci * you may not use this file except in compliance with the License.
5e0dac50fSopenharmony_ci * You may obtain a copy of the License at
6e0dac50fSopenharmony_ci *
7e0dac50fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8e0dac50fSopenharmony_ci *
9e0dac50fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10e0dac50fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11e0dac50fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12e0dac50fSopenharmony_ci * See the License for the specific language governing permissions and
13e0dac50fSopenharmony_ci * limitations under the License.
14e0dac50fSopenharmony_ci */
15e0dac50fSopenharmony_ci
16e0dac50fSopenharmony_ci#include <gtest/gtest.h>
17e0dac50fSopenharmony_ci#include "display_manager.h"
18e0dac50fSopenharmony_ci#include "display_manager_proxy.h"
19e0dac50fSopenharmony_ci#include "mock_display_manager_adapter.h"
20e0dac50fSopenharmony_ci#include "singleton_mocker.h"
21e0dac50fSopenharmony_ci#include "display_cutout_controller.h"
22e0dac50fSopenharmony_ci#include "scene_board_judgement.h"
23e0dac50fSopenharmony_ci
24e0dac50fSopenharmony_ciusing namespace testing;
25e0dac50fSopenharmony_ciusing namespace testing::ext;
26e0dac50fSopenharmony_ci
27e0dac50fSopenharmony_cinamespace OHOS {
28e0dac50fSopenharmony_cinamespace Rosen {
29e0dac50fSopenharmony_ciusing Mocker = SingletonMocker<DisplayManagerAdapter, MockDisplayManagerAdapter>;
30e0dac50fSopenharmony_ciusing ScreenMocker = SingletonMocker<ScreenManagerAdapter, MockScreenManagerAdapter>;
31e0dac50fSopenharmony_ciclass DisplayTest : public testing::Test {
32e0dac50fSopenharmony_cipublic:
33e0dac50fSopenharmony_ci    static void SetUpTestCase();
34e0dac50fSopenharmony_ci    static void TearDownTestCase();
35e0dac50fSopenharmony_ci    virtual void SetUp() override;
36e0dac50fSopenharmony_ci    virtual void TearDown() override;
37e0dac50fSopenharmony_ci
38e0dac50fSopenharmony_ci    static sptr<Display> defaultDisplay_;
39e0dac50fSopenharmony_ci    static DisplayId defaultDisplayId_;
40e0dac50fSopenharmony_ci};
41e0dac50fSopenharmony_cisptr<Display> DisplayTest::defaultDisplay_ = nullptr;
42e0dac50fSopenharmony_ciDisplayId DisplayTest::defaultDisplayId_ = DISPLAY_ID_INVALID;
43e0dac50fSopenharmony_ci
44e0dac50fSopenharmony_civoid DisplayTest::SetUpTestCase()
45e0dac50fSopenharmony_ci{
46e0dac50fSopenharmony_ci    defaultDisplay_ = DisplayManager::GetInstance().GetDefaultDisplay();
47e0dac50fSopenharmony_ci    defaultDisplayId_ = static_cast<DisplayId>(defaultDisplay_->GetId());
48e0dac50fSopenharmony_ci}
49e0dac50fSopenharmony_ci
50e0dac50fSopenharmony_civoid DisplayTest::TearDownTestCase()
51e0dac50fSopenharmony_ci{
52e0dac50fSopenharmony_ci    defaultDisplay_ = nullptr;
53e0dac50fSopenharmony_ci}
54e0dac50fSopenharmony_ci
55e0dac50fSopenharmony_civoid DisplayTest::SetUp()
56e0dac50fSopenharmony_ci{
57e0dac50fSopenharmony_ci}
58e0dac50fSopenharmony_ci
59e0dac50fSopenharmony_civoid DisplayTest::TearDown()
60e0dac50fSopenharmony_ci{
61e0dac50fSopenharmony_ci}
62e0dac50fSopenharmony_ci
63e0dac50fSopenharmony_cinamespace {
64e0dac50fSopenharmony_ci/**
65e0dac50fSopenharmony_ci * @tc.name: GetCutoutInfo01
66e0dac50fSopenharmony_ci * @tc.desc: GetCutoutInfo with valid defaultDisplayId and return success
67e0dac50fSopenharmony_ci * @tc.type: FUNC
68e0dac50fSopenharmony_ci * @tc.require: issueI5K0JP
69e0dac50fSopenharmony_ci */
70e0dac50fSopenharmony_ciHWTEST_F(DisplayTest, GetCutoutInfo01, Function | SmallTest | Level1)
71e0dac50fSopenharmony_ci{
72e0dac50fSopenharmony_ci    auto cutoutInfo = defaultDisplay_->GetCutoutInfo();
73e0dac50fSopenharmony_ci    ASSERT_NE(nullptr, cutoutInfo);
74e0dac50fSopenharmony_ci}
75e0dac50fSopenharmony_ci
76e0dac50fSopenharmony_ci/**
77e0dac50fSopenharmony_ci * @tc.name: UpdateDisplayInfo01
78e0dac50fSopenharmony_ci * @tc.desc: UpdateDisplayInfo with nullptr
79e0dac50fSopenharmony_ci * @tc.type: FUNC
80e0dac50fSopenharmony_ci * @tc.require: issueI5K0JP
81e0dac50fSopenharmony_ci */
82e0dac50fSopenharmony_ciHWTEST_F(DisplayTest, UpdateDisplayInfo01, Function | SmallTest | Level1)
83e0dac50fSopenharmony_ci{
84e0dac50fSopenharmony_ci    auto baseInfo = defaultDisplay_->GetDisplayInfo();
85e0dac50fSopenharmony_ci    auto defaultName = baseInfo->GetName();
86e0dac50fSopenharmony_ci    auto defaultDpi = baseInfo->GetName();
87e0dac50fSopenharmony_ci    defaultDisplay_->UpdateDisplayInfo(nullptr);
88e0dac50fSopenharmony_ci
89e0dac50fSopenharmony_ci    auto changedInfo = defaultDisplay_->GetDisplayInfo();
90e0dac50fSopenharmony_ci    ASSERT_EQ(changedInfo->GetName(), defaultName);
91e0dac50fSopenharmony_ci}
92e0dac50fSopenharmony_ci
93e0dac50fSopenharmony_ci/**
94e0dac50fSopenharmony_ci * @tc.name: SetWaterfallCompression01
95e0dac50fSopenharmony_ci * @tc.desc: Set waterfall compression related values with valid input.
96e0dac50fSopenharmony_ci * @tc.type: FUNC
97e0dac50fSopenharmony_ci * @tc.require: issueI5P8CI
98e0dac50fSopenharmony_ci */
99e0dac50fSopenharmony_ciHWTEST_F(DisplayTest, SetWaterfallCompression01, Function | SmallTest | Level1)
100e0dac50fSopenharmony_ci{
101e0dac50fSopenharmony_ci    bool isWaterfallDisplayOrigin = DisplayCutoutController::IsWaterfallDisplay();
102e0dac50fSopenharmony_ci    DisplayCutoutController::SetIsWaterfallDisplay(true);
103e0dac50fSopenharmony_ci    bool isCompressionEnableOrigin =
104e0dac50fSopenharmony_ci        DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal();
105e0dac50fSopenharmony_ci    DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(true);
106e0dac50fSopenharmony_ci    uint32_t testSizeOrigin = DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal();
107e0dac50fSopenharmony_ci    uint32_t testSize = 20;
108e0dac50fSopenharmony_ci    DisplayCutoutController::SetWaterfallAreaCompressionSizeWhenHorizontal(testSize);
109e0dac50fSopenharmony_ci    ASSERT_EQ(true, DisplayCutoutController::IsWaterfallDisplay());
110e0dac50fSopenharmony_ci    ASSERT_EQ(true, DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal());
111e0dac50fSopenharmony_ci    ASSERT_EQ(testSize, DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal());
112e0dac50fSopenharmony_ci    DisplayCutoutController::SetWaterfallAreaCompressionSizeWhenHorizontal(testSizeOrigin);
113e0dac50fSopenharmony_ci    ASSERT_EQ(testSizeOrigin, DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal());
114e0dac50fSopenharmony_ci    DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(isCompressionEnableOrigin);
115e0dac50fSopenharmony_ci    ASSERT_EQ(isWaterfallDisplayOrigin, DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal());
116e0dac50fSopenharmony_ci    DisplayCutoutController::SetIsWaterfallDisplay(isWaterfallDisplayOrigin);
117e0dac50fSopenharmony_ci    ASSERT_EQ(isWaterfallDisplayOrigin, DisplayCutoutController::IsWaterfallDisplay());
118e0dac50fSopenharmony_ci}
119e0dac50fSopenharmony_ci
120e0dac50fSopenharmony_ci/**
121e0dac50fSopenharmony_ci * @tc.name: SetWaterfallCompression02
122e0dac50fSopenharmony_ci * @tc.desc: Set waterfall compression related values with invalid input.
123e0dac50fSopenharmony_ci * @tc.type: FUNC
124e0dac50fSopenharmony_ci * @tc.require: issueI5P8CI
125e0dac50fSopenharmony_ci */
126e0dac50fSopenharmony_ciHWTEST_F(DisplayTest, SetWaterfallCompression02, Function | SmallTest | Level1)
127e0dac50fSopenharmony_ci{
128e0dac50fSopenharmony_ci    bool isWaterfallDisplayOrigin = DisplayCutoutController::IsWaterfallDisplay();
129e0dac50fSopenharmony_ci    DisplayCutoutController::SetIsWaterfallDisplay(true);
130e0dac50fSopenharmony_ci    bool isCompressionEnableOrigin =
131e0dac50fSopenharmony_ci        DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal();
132e0dac50fSopenharmony_ci    DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(true);
133e0dac50fSopenharmony_ci    uint32_t testSizeOrigin = DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal();
134e0dac50fSopenharmony_ci
135e0dac50fSopenharmony_ci    DisplayCutoutController::SetIsWaterfallDisplay(false);
136e0dac50fSopenharmony_ci    DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(true);
137e0dac50fSopenharmony_ci    ASSERT_EQ(false, DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal());
138e0dac50fSopenharmony_ci
139e0dac50fSopenharmony_ci    uint32_t testSize = 20;
140e0dac50fSopenharmony_ci    DisplayCutoutController::SetIsWaterfallDisplay(true);
141e0dac50fSopenharmony_ci    DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(false);
142e0dac50fSopenharmony_ci    DisplayCutoutController::SetWaterfallAreaCompressionSizeWhenHorizontal(testSize);
143e0dac50fSopenharmony_ci    ASSERT_EQ(0, DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal());
144e0dac50fSopenharmony_ci
145e0dac50fSopenharmony_ci    DisplayCutoutController::SetIsWaterfallDisplay(false);
146e0dac50fSopenharmony_ci    DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(false);
147e0dac50fSopenharmony_ci    DisplayCutoutController::SetWaterfallAreaCompressionSizeWhenHorizontal(testSize);
148e0dac50fSopenharmony_ci    ASSERT_EQ(0, DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal());
149e0dac50fSopenharmony_ci
150e0dac50fSopenharmony_ci    DisplayCutoutController::SetWaterfallAreaCompressionSizeWhenHorizontal(testSizeOrigin);
151e0dac50fSopenharmony_ci    ASSERT_EQ(testSizeOrigin, DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal());
152e0dac50fSopenharmony_ci    DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(isCompressionEnableOrigin);
153e0dac50fSopenharmony_ci    ASSERT_EQ(isWaterfallDisplayOrigin, DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal());
154e0dac50fSopenharmony_ci    DisplayCutoutController::SetIsWaterfallDisplay(isWaterfallDisplayOrigin);
155e0dac50fSopenharmony_ci    ASSERT_EQ(isWaterfallDisplayOrigin, DisplayCutoutController::IsWaterfallDisplay());
156e0dac50fSopenharmony_ci}
157e0dac50fSopenharmony_ci/**
158e0dac50fSopenharmony_ci * @tc.name: GetName01
159e0dac50fSopenharmony_ci * @tc.desc: GetName function cover
160e0dac50fSopenharmony_ci * @tc.type: FUNC
161e0dac50fSopenharmony_ci */
162e0dac50fSopenharmony_ciHWTEST_F(DisplayTest, GetName01, Function | SmallTest | Level1)
163e0dac50fSopenharmony_ci{
164e0dac50fSopenharmony_ci    auto name = defaultDisplay_->GetName();
165e0dac50fSopenharmony_ci    ASSERT_FALSE(name.empty());
166e0dac50fSopenharmony_ci}
167e0dac50fSopenharmony_ci
168e0dac50fSopenharmony_ci/**
169e0dac50fSopenharmony_ci * @tc.name: GetDpi01
170e0dac50fSopenharmony_ci * @tc.desc: GetDpi function cover
171e0dac50fSopenharmony_ci * @tc.type: FUNC
172e0dac50fSopenharmony_ci */
173e0dac50fSopenharmony_ciHWTEST_F(DisplayTest, GetDpi01, Function | SmallTest | Level1)
174e0dac50fSopenharmony_ci{
175e0dac50fSopenharmony_ci    auto dpi = defaultDisplay_->GetDpi();
176e0dac50fSopenharmony_ci
177e0dac50fSopenharmony_ci    auto vpr = defaultDisplay_->GetVirtualPixelRatio();
178e0dac50fSopenharmony_ci    ASSERT_EQ(vpr * DOT_PER_INCH, dpi);
179e0dac50fSopenharmony_ci}
180e0dac50fSopenharmony_ci
181e0dac50fSopenharmony_ci/**
182e0dac50fSopenharmony_ci * @tc.name: HasImmersiveWindow
183e0dac50fSopenharmony_ci * @tc.desc: test HasImmersiveWindow
184e0dac50fSopenharmony_ci * @tc.type: FUNC
185e0dac50fSopenharmony_ci */
186e0dac50fSopenharmony_ciHWTEST_F(DisplayTest, HasImmersiveWindow, Function | SmallTest | Level1)
187e0dac50fSopenharmony_ci{
188e0dac50fSopenharmony_ci    std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
189e0dac50fSopenharmony_ci    EXPECT_CALL(m->Mock(), HasImmersiveWindow(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
190e0dac50fSopenharmony_ci    bool immersive = false;
191e0dac50fSopenharmony_ci    DMError ret = defaultDisplay_->HasImmersiveWindow(immersive);
192e0dac50fSopenharmony_ci    ASSERT_EQ(ret, DMError::DM_OK);
193e0dac50fSopenharmony_ci}
194e0dac50fSopenharmony_ci
195e0dac50fSopenharmony_ci/**
196e0dac50fSopenharmony_ci * @tc.name: GetPhysicalWidth
197e0dac50fSopenharmony_ci * @tc.desc: test GetPhysicalWidth
198e0dac50fSopenharmony_ci * @tc.type: FUNC
199e0dac50fSopenharmony_ci */
200e0dac50fSopenharmony_ciHWTEST_F(DisplayTest, GetPhysicalWidth, Function | SmallTest | Level1)
201e0dac50fSopenharmony_ci{
202e0dac50fSopenharmony_ci    auto physicalwidth = defaultDisplay_->GetPhysicalWidth();
203e0dac50fSopenharmony_ci    if (SceneBoardJudgement::IsSceneBoardEnabled()) {
204e0dac50fSopenharmony_ci        ASSERT_NE(physicalwidth, 0);
205e0dac50fSopenharmony_ci    } else {
206e0dac50fSopenharmony_ci        ASSERT_EQ(physicalwidth, 0);
207e0dac50fSopenharmony_ci    }
208e0dac50fSopenharmony_ci}
209e0dac50fSopenharmony_ci
210e0dac50fSopenharmony_ci/**
211e0dac50fSopenharmony_ci * @tc.name: GetPhysicalHeight
212e0dac50fSopenharmony_ci * @tc.desc: test GetPhysicalHeight
213e0dac50fSopenharmony_ci * @tc.type: FUNC
214e0dac50fSopenharmony_ci */
215e0dac50fSopenharmony_ciHWTEST_F(DisplayTest, GetPhysicalHeight, Function | SmallTest | Level1)
216e0dac50fSopenharmony_ci{
217e0dac50fSopenharmony_ci    auto physicalheight = defaultDisplay_->GetPhysicalHeight();
218e0dac50fSopenharmony_ci    if (SceneBoardJudgement::IsSceneBoardEnabled()) {
219e0dac50fSopenharmony_ci        ASSERT_NE(physicalheight, 0);
220e0dac50fSopenharmony_ci    } else {
221e0dac50fSopenharmony_ci        ASSERT_EQ(physicalheight, 0);
222e0dac50fSopenharmony_ci    }
223e0dac50fSopenharmony_ci}
224e0dac50fSopenharmony_ci
225e0dac50fSopenharmony_ci/**
226e0dac50fSopenharmony_ci * @tc.name: GetAvailableArea
227e0dac50fSopenharmony_ci * @tc.desc: test GetAvailableArea
228e0dac50fSopenharmony_ci * @tc.type: FUNC
229e0dac50fSopenharmony_ci */
230e0dac50fSopenharmony_ciHWTEST_F(DisplayTest, GetAvailableArea, Function | SmallTest | Level1)
231e0dac50fSopenharmony_ci{
232e0dac50fSopenharmony_ci    std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
233e0dac50fSopenharmony_ci    EXPECT_CALL(m->Mock(), GetAvailableArea(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
234e0dac50fSopenharmony_ci    DMRect area;
235e0dac50fSopenharmony_ci    auto res = defaultDisplay_ ->GetAvailableArea(area);
236e0dac50fSopenharmony_ci    ASSERT_EQ(DMError::DM_OK, res);
237e0dac50fSopenharmony_ci}
238e0dac50fSopenharmony_ci
239e0dac50fSopenharmony_ci/**
240e0dac50fSopenharmony_ci * @tc.name: GetSupportedHDRFormats
241e0dac50fSopenharmony_ci * @tc.desc: test GetSupportedHDRFormats
242e0dac50fSopenharmony_ci * @tc.type: FUNC
243e0dac50fSopenharmony_ci */
244e0dac50fSopenharmony_ciHWTEST_F(DisplayTest, GetSupportedHDRFormats, Function | SmallTest | Level1)
245e0dac50fSopenharmony_ci{
246e0dac50fSopenharmony_ci    std::unique_ptr<ScreenMocker> m = std::make_unique<ScreenMocker>();
247e0dac50fSopenharmony_ci    EXPECT_CALL(m->Mock(), GetSupportedHDRFormats(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
248e0dac50fSopenharmony_ci    std::vector<uint32_t> hdrFormats;
249e0dac50fSopenharmony_ci    auto res = defaultDisplay_ ->GetSupportedHDRFormats(hdrFormats);
250e0dac50fSopenharmony_ci    ASSERT_EQ(DMError::DM_OK, res);
251e0dac50fSopenharmony_ci}
252e0dac50fSopenharmony_ci
253e0dac50fSopenharmony_ci/**
254e0dac50fSopenharmony_ci * @tc.name: GetSupportedColorSpaces
255e0dac50fSopenharmony_ci * @tc.desc: test GetSupportedColorSpaces
256e0dac50fSopenharmony_ci * @tc.type: FUNC
257e0dac50fSopenharmony_ci */
258e0dac50fSopenharmony_ciHWTEST_F(DisplayTest, GetSupportedColorSpaces, Function | SmallTest | Level1)
259e0dac50fSopenharmony_ci{
260e0dac50fSopenharmony_ci    std::unique_ptr<ScreenMocker> m = std::make_unique<ScreenMocker>();
261e0dac50fSopenharmony_ci    EXPECT_CALL(m->Mock(), GetSupportedColorSpaces(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
262e0dac50fSopenharmony_ci    std::vector<uint32_t> colorSpaces;
263e0dac50fSopenharmony_ci    auto res = defaultDisplay_ -> GetSupportedColorSpaces(colorSpaces);
264e0dac50fSopenharmony_ci    ASSERT_EQ(DMError::DM_OK, res);
265e0dac50fSopenharmony_ci}
266e0dac50fSopenharmony_ci}
267e0dac50fSopenharmony_ci} // namespace Rosen
268e0dac50fSopenharmony_ci} // namespace OHOS