1e0dac50fSopenharmony_ci/*
2e0dac50fSopenharmony_ci * Copyright (c) 2021-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
18e0dac50fSopenharmony_ci#include "display_cutout_controller.h"
19e0dac50fSopenharmony_ci#include "display_info.h"
20e0dac50fSopenharmony_ci#include "display_manager.h"
21e0dac50fSopenharmony_ci#include "display_manager_proxy.h"
22e0dac50fSopenharmony_ci#include "screen_manager.h"
23e0dac50fSopenharmony_ci#include "screen_manager/rs_screen_mode_info.h"
24e0dac50fSopenharmony_ci#include "window_manager_hilog.h"
25e0dac50fSopenharmony_ci
26e0dac50fSopenharmony_ciusing namespace testing;
27e0dac50fSopenharmony_ciusing namespace testing::ext;
28e0dac50fSopenharmony_ci
29e0dac50fSopenharmony_cinamespace OHOS {
30e0dac50fSopenharmony_cinamespace Rosen {
31e0dac50fSopenharmony_cinamespace {
32e0dac50fSopenharmony_ciconstexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayChangeTest"};
33e0dac50fSopenharmony_ciconstexpr uint32_t MAX_TIME_WAITING_FOR_CALLBACK = 20;
34e0dac50fSopenharmony_ciconstexpr uint32_t SLEEP_TIME_IN_US = 10000; // 10ms
35e0dac50fSopenharmony_ciconstexpr uint32_t SPLIT_TEST_SLEEP_S = 2;
36e0dac50fSopenharmony_ci}
37e0dac50fSopenharmony_ci
38e0dac50fSopenharmony_ciclass DisplayChangeEventListener : public DisplayManager::IDisplayListener {
39e0dac50fSopenharmony_cipublic:
40e0dac50fSopenharmony_ci    virtual void OnCreate(DisplayId displayId)
41e0dac50fSopenharmony_ci    {
42e0dac50fSopenharmony_ci        WLOGI("DisplayChangeEventListener::OnCreate displayId=%{public}" PRIu64"", displayId);
43e0dac50fSopenharmony_ci    }
44e0dac50fSopenharmony_ci
45e0dac50fSopenharmony_ci    virtual void OnDestroy(DisplayId displayId)
46e0dac50fSopenharmony_ci    {
47e0dac50fSopenharmony_ci        WLOGI("DisplayChangeEventListener::OnDestroy displayId=%{public}" PRIu64"", displayId);
48e0dac50fSopenharmony_ci    }
49e0dac50fSopenharmony_ci
50e0dac50fSopenharmony_ci    virtual void OnChange(DisplayId displayId)
51e0dac50fSopenharmony_ci    {
52e0dac50fSopenharmony_ci        WLOGI("DisplayChangeEventListener::OnChange displayId=%{public}" PRIu64"", displayId);
53e0dac50fSopenharmony_ci        isCallbackCalled_ = true;
54e0dac50fSopenharmony_ci        displayId_ = displayId;
55e0dac50fSopenharmony_ci    }
56e0dac50fSopenharmony_ci    bool isCallbackCalled_ = false;
57e0dac50fSopenharmony_ci    DisplayId displayId_ = DISPLAY_ID_INVALID;
58e0dac50fSopenharmony_ci};
59e0dac50fSopenharmony_ci
60e0dac50fSopenharmony_ciclass DisplayChangeTest : public testing::Test {
61e0dac50fSopenharmony_cipublic:
62e0dac50fSopenharmony_ci    static void SetUpTestCase();
63e0dac50fSopenharmony_ci    static void TearDownTestCase();
64e0dac50fSopenharmony_ci    virtual void SetUp() override;
65e0dac50fSopenharmony_ci    virtual void TearDown() override;
66e0dac50fSopenharmony_ci    void ResetDisplayChangeListener();
67e0dac50fSopenharmony_ci    bool CheckDisplayChangeEventCallback(bool valueExpected);
68e0dac50fSopenharmony_ci    bool ScreenSizeEqual(const sptr<Screen> screen, const sptr<SupportedScreenModes> curInfo) const;
69e0dac50fSopenharmony_ci    bool DisplaySizeEqual(const sptr<Display> display, const sptr<SupportedScreenModes> curInfo) const;
70e0dac50fSopenharmony_ci    inline bool CheckModeSizeChange(const sptr<SupportedScreenModes> usedInfo,
71e0dac50fSopenharmony_ci        const sptr<SupportedScreenModes> curInfo) const;
72e0dac50fSopenharmony_ci
73e0dac50fSopenharmony_ci    static DisplayId defaultDisplayId_;
74e0dac50fSopenharmony_ci    static sptr<Screen> defaultScreen_;
75e0dac50fSopenharmony_ci    static sptr<DisplayChangeEventListener> listener_;
76e0dac50fSopenharmony_ci    static uint32_t originalDisplayDpi;
77e0dac50fSopenharmony_ci    static inline uint32_t times_ = 0;
78e0dac50fSopenharmony_ci};
79e0dac50fSopenharmony_ciDisplayId DisplayChangeTest::defaultDisplayId_ = DISPLAY_ID_INVALID;
80e0dac50fSopenharmony_cisptr<Screen> DisplayChangeTest::defaultScreen_ = nullptr;
81e0dac50fSopenharmony_cisptr<DisplayChangeEventListener> DisplayChangeTest::listener_ = new DisplayChangeEventListener();
82e0dac50fSopenharmony_ciuint32_t DisplayChangeTest::originalDisplayDpi = 0;
83e0dac50fSopenharmony_ci
84e0dac50fSopenharmony_civoid DisplayChangeTest::SetUpTestCase()
85e0dac50fSopenharmony_ci{
86e0dac50fSopenharmony_ci    defaultDisplayId_ = DisplayManager::GetInstance().GetDefaultDisplayId();
87e0dac50fSopenharmony_ci    ASSERT_NE(DISPLAY_ID_INVALID, defaultDisplayId_);
88e0dac50fSopenharmony_ci    sptr<Display> defaultDisplay = DisplayManager::GetInstance().GetDisplayById(defaultDisplayId_);
89e0dac50fSopenharmony_ci    ASSERT_NE(nullptr, defaultDisplay);
90e0dac50fSopenharmony_ci    ScreenId screenId = defaultDisplay->GetScreenId();
91e0dac50fSopenharmony_ci    ASSERT_NE(INVALID_SCREEN_ID, screenId);
92e0dac50fSopenharmony_ci    defaultScreen_ = ScreenManager::GetInstance().GetScreenById(screenId);
93e0dac50fSopenharmony_ci    ASSERT_NE(nullptr, defaultScreen_);
94e0dac50fSopenharmony_ci
95e0dac50fSopenharmony_ci    ASSERT_EQ(DMError::DM_OK, DisplayManager::GetInstance().RegisterDisplayListener(listener_));
96e0dac50fSopenharmony_ci}
97e0dac50fSopenharmony_ci
98e0dac50fSopenharmony_civoid DisplayChangeTest::TearDownTestCase()
99e0dac50fSopenharmony_ci{
100e0dac50fSopenharmony_ci    DisplayManager::GetInstance().UnregisterDisplayListener(listener_);
101e0dac50fSopenharmony_ci}
102e0dac50fSopenharmony_ci
103e0dac50fSopenharmony_civoid DisplayChangeTest::SetUp()
104e0dac50fSopenharmony_ci{
105e0dac50fSopenharmony_ci    times_ = 0;
106e0dac50fSopenharmony_ci    ResetDisplayChangeListener();
107e0dac50fSopenharmony_ci}
108e0dac50fSopenharmony_ci
109e0dac50fSopenharmony_civoid DisplayChangeTest::TearDown()
110e0dac50fSopenharmony_ci{
111e0dac50fSopenharmony_ci}
112e0dac50fSopenharmony_ci
113e0dac50fSopenharmony_civoid DisplayChangeTest::ResetDisplayChangeListener()
114e0dac50fSopenharmony_ci{
115e0dac50fSopenharmony_ci    ASSERT_NE(nullptr, listener_);
116e0dac50fSopenharmony_ci    listener_->isCallbackCalled_ = false;
117e0dac50fSopenharmony_ci    listener_->displayId_ = DISPLAY_ID_INVALID;
118e0dac50fSopenharmony_ci}
119e0dac50fSopenharmony_ci
120e0dac50fSopenharmony_cibool DisplayChangeTest::CheckDisplayChangeEventCallback(bool valueExpected)
121e0dac50fSopenharmony_ci{
122e0dac50fSopenharmony_ci    WLOGI("CheckDisplayChangeEventCallback in");
123e0dac50fSopenharmony_ci    do {
124e0dac50fSopenharmony_ci        if (listener_->isCallbackCalled_ == valueExpected) {
125e0dac50fSopenharmony_ci            WLOGI("CheckDisplayChangeEventCallback: get valueExpected %{public}d for display %{public}" PRIu64"",
126e0dac50fSopenharmony_ci                static_cast<int>(valueExpected), listener_->displayId_);
127e0dac50fSopenharmony_ci            WLOGI("CheckDisplayChangeEventCallback: already wait times %{public}d", times_);
128e0dac50fSopenharmony_ci            return true;
129e0dac50fSopenharmony_ci        }
130e0dac50fSopenharmony_ci        usleep(SLEEP_TIME_IN_US);
131e0dac50fSopenharmony_ci        ++times_;
132e0dac50fSopenharmony_ci    } while (times_ <= MAX_TIME_WAITING_FOR_CALLBACK);
133e0dac50fSopenharmony_ci    WLOGI("CheckDisplayChangeEventCallback: cannot get valueExpected");
134e0dac50fSopenharmony_ci    return false;
135e0dac50fSopenharmony_ci}
136e0dac50fSopenharmony_ci
137e0dac50fSopenharmony_cibool DisplayChangeTest::ScreenSizeEqual(const sptr<Screen> screen, const sptr<SupportedScreenModes> curInfo) const
138e0dac50fSopenharmony_ci{
139e0dac50fSopenharmony_ci    if (screen == nullptr || curInfo == nullptr) {
140e0dac50fSopenharmony_ci        WLOGI("param is nullptr");
141e0dac50fSopenharmony_ci        return false;
142e0dac50fSopenharmony_ci    }
143e0dac50fSopenharmony_ci    uint32_t sWidth = screen->GetWidth();
144e0dac50fSopenharmony_ci    uint32_t sHeight = screen->GetHeight();
145e0dac50fSopenharmony_ci    WLOGI("ScreenSizeEqual: ScreenSize: %{public}u %{public}u, ActiveModeInfoSize: %{public}u %{public}u",
146e0dac50fSopenharmony_ci        sWidth, sHeight, curInfo->width_, curInfo->height_);
147e0dac50fSopenharmony_ci    return ((curInfo->width_ == sWidth) && (curInfo->height_ == sHeight));
148e0dac50fSopenharmony_ci}
149e0dac50fSopenharmony_ci
150e0dac50fSopenharmony_cibool DisplayChangeTest::DisplaySizeEqual(const sptr<Display> display, const sptr<SupportedScreenModes> curInfo) const
151e0dac50fSopenharmony_ci{
152e0dac50fSopenharmony_ci    if (display == nullptr || curInfo == nullptr) {
153e0dac50fSopenharmony_ci        WLOGI("param is nullptr");
154e0dac50fSopenharmony_ci        return false;
155e0dac50fSopenharmony_ci    }
156e0dac50fSopenharmony_ci    uint32_t dWidth = static_cast<uint32_t>(display->GetWidth());
157e0dac50fSopenharmony_ci    uint32_t dHeight = static_cast<uint32_t>(display->GetHeight());
158e0dac50fSopenharmony_ci    WLOGI("DisplaySizeEqual:: DisplaySize: %{public}u %{public}u, ActiveModeInfoSize: %{public}u %{public}u",
159e0dac50fSopenharmony_ci        dWidth, dHeight, curInfo->width_, curInfo->height_);
160e0dac50fSopenharmony_ci    return ((curInfo->width_ == dWidth) && (curInfo->height_ == dHeight));
161e0dac50fSopenharmony_ci}
162e0dac50fSopenharmony_ci
163e0dac50fSopenharmony_ci
164e0dac50fSopenharmony_ciinline bool DisplayChangeTest::CheckModeSizeChange(const sptr<SupportedScreenModes> usedInfo,
165e0dac50fSopenharmony_ci    const sptr<SupportedScreenModes> curInfo) const
166e0dac50fSopenharmony_ci{
167e0dac50fSopenharmony_ci    if (usedInfo == nullptr || curInfo == nullptr) {
168e0dac50fSopenharmony_ci        return false;
169e0dac50fSopenharmony_ci    }
170e0dac50fSopenharmony_ci    return (usedInfo->width_ != curInfo->width_ || usedInfo->height_ != curInfo->height_);
171e0dac50fSopenharmony_ci}
172e0dac50fSopenharmony_ci
173e0dac50fSopenharmony_cinamespace {
174e0dac50fSopenharmony_ci/**
175e0dac50fSopenharmony_ci * @tc.name: RegisterDisplayChangeListener01
176e0dac50fSopenharmony_ci * @tc.desc: Register displayChangeListener with valid listener and check return true
177e0dac50fSopenharmony_ci * @tc.type: FUNC
178e0dac50fSopenharmony_ci */
179e0dac50fSopenharmony_ciHWTEST_F(DisplayChangeTest, RegisterDisplayChangeListener01, Function | SmallTest | Level2)
180e0dac50fSopenharmony_ci{
181e0dac50fSopenharmony_ci    sptr<DisplayChangeEventListener> listener = new DisplayChangeEventListener();
182e0dac50fSopenharmony_ci    DMError ret = DisplayManager::GetInstance().RegisterDisplayListener(listener);
183e0dac50fSopenharmony_ci    ASSERT_EQ(DMError::DM_OK, ret);
184e0dac50fSopenharmony_ci}
185e0dac50fSopenharmony_ci
186e0dac50fSopenharmony_ci/**
187e0dac50fSopenharmony_ci * @tc.name: RegisterDisplayChangeListener02
188e0dac50fSopenharmony_ci * @tc.desc: Register displayChangeListener with nullptr and check return false
189e0dac50fSopenharmony_ci * @tc.type: FUNC
190e0dac50fSopenharmony_ci */
191e0dac50fSopenharmony_ciHWTEST_F(DisplayChangeTest, RegisterDisplayChangeListener02, Function | SmallTest | Level2)
192e0dac50fSopenharmony_ci{
193e0dac50fSopenharmony_ci    DMError ret = DisplayManager::GetInstance().RegisterDisplayListener(nullptr);
194e0dac50fSopenharmony_ci    ASSERT_EQ(DMError::DM_ERROR_NULLPTR, ret);
195e0dac50fSopenharmony_ci}
196e0dac50fSopenharmony_ci
197e0dac50fSopenharmony_ci/**
198e0dac50fSopenharmony_ci * @tc.name: UnregisterDisplayChangeListener01
199e0dac50fSopenharmony_ci * @tc.desc: Unregister displayChangeListener with valid listener and check return true
200e0dac50fSopenharmony_ci * @tc.type: FUNC
201e0dac50fSopenharmony_ci */
202e0dac50fSopenharmony_ciHWTEST_F(DisplayChangeTest, UnregisterDisplayChangeListener01, Function | SmallTest | Level2)
203e0dac50fSopenharmony_ci{
204e0dac50fSopenharmony_ci    sptr<DisplayChangeEventListener> listener = new DisplayChangeEventListener();
205e0dac50fSopenharmony_ci    DisplayManager::GetInstance().RegisterDisplayListener(listener);
206e0dac50fSopenharmony_ci    DMError ret = DisplayManager::GetInstance().UnregisterDisplayListener(listener);
207e0dac50fSopenharmony_ci    ASSERT_EQ(DMError::DM_OK, ret);
208e0dac50fSopenharmony_ci}
209e0dac50fSopenharmony_ci
210e0dac50fSopenharmony_ci/**
211e0dac50fSopenharmony_ci * @tc.name: UnregisterDisplayChangeListener02
212e0dac50fSopenharmony_ci * @tc.desc: Register displayChangeListener with nullptr and check return false
213e0dac50fSopenharmony_ci * @tc.type: FUNC
214e0dac50fSopenharmony_ci */
215e0dac50fSopenharmony_ciHWTEST_F(DisplayChangeTest, UnregisterDisplayChangeListener02, Function | SmallTest | Level2)
216e0dac50fSopenharmony_ci{
217e0dac50fSopenharmony_ci    DMError ret = DisplayManager::GetInstance().UnregisterDisplayListener(nullptr);
218e0dac50fSopenharmony_ci    ASSERT_EQ(DMError::DM_ERROR_NULLPTR, ret);
219e0dac50fSopenharmony_ci}
220e0dac50fSopenharmony_ci
221e0dac50fSopenharmony_ci/**
222e0dac50fSopenharmony_ci * @tc.name: UnregisterDisplayChangeListener03
223e0dac50fSopenharmony_ci * @tc.desc: Register displayChangeListener with invalid listener and check return false
224e0dac50fSopenharmony_ci * @tc.type: FUNC
225e0dac50fSopenharmony_ci */
226e0dac50fSopenharmony_ciHWTEST_F(DisplayChangeTest, UnregisterDisplayChangeListener03, Function | SmallTest | Level2)
227e0dac50fSopenharmony_ci{
228e0dac50fSopenharmony_ci    sptr<DisplayChangeEventListener> listener = new DisplayChangeEventListener();
229e0dac50fSopenharmony_ci    DMError ret = DisplayManager::GetInstance().UnregisterDisplayListener(listener);
230e0dac50fSopenharmony_ci    ASSERT_EQ(DMError::DM_ERROR_NULLPTR, ret);
231e0dac50fSopenharmony_ci}
232e0dac50fSopenharmony_ci
233e0dac50fSopenharmony_ci/**
234e0dac50fSopenharmony_ci * @tc.name: CheckDisplayStateChange01
235e0dac50fSopenharmony_ci * @tc.desc: DisplayState not change if screen sets same mode
236e0dac50fSopenharmony_ci * @tc.type: FUNC
237e0dac50fSopenharmony_ci */
238e0dac50fSopenharmony_ciHWTEST_F(DisplayChangeTest, CheckDisplayStateChange01, Function | SmallTest | Level2)
239e0dac50fSopenharmony_ci{
240e0dac50fSopenharmony_ci    WLOGI("CheckDisplayStateChange01");
241e0dac50fSopenharmony_ci    uint32_t usedModeIdx = defaultScreen_->GetModeId();
242e0dac50fSopenharmony_ci    defaultScreen_->SetScreenActiveMode(usedModeIdx);
243e0dac50fSopenharmony_ci    WLOGI("SetScreenActiveMode: %{public}u", usedModeIdx);
244e0dac50fSopenharmony_ci    if (CheckDisplayChangeEventCallback(true)) {
245e0dac50fSopenharmony_ci        ASSERT_EQ(true, CheckDisplayChangeEventCallback(true));
246e0dac50fSopenharmony_ci    }
247e0dac50fSopenharmony_ci}
248e0dac50fSopenharmony_ci
249e0dac50fSopenharmony_ci/**
250e0dac50fSopenharmony_ci * @tc.name: CheckDisplaySizeChange01
251e0dac50fSopenharmony_ci * @tc.desc: Check screen size change as screen mode set if screen sets another mode
252e0dac50fSopenharmony_ci * @tc.type: FUNC
253e0dac50fSopenharmony_ci */
254e0dac50fSopenharmony_ciHWTEST_F(DisplayChangeTest, CheckDisplaySizeChange01, Function | MediumTest | Level2)
255e0dac50fSopenharmony_ci{
256e0dac50fSopenharmony_ci    WLOGI("CheckDisplaySizeChange01");
257e0dac50fSopenharmony_ci    auto modes = defaultScreen_->GetSupportedModes();
258e0dac50fSopenharmony_ci    uint32_t usedModeIdx = defaultScreen_->GetModeId();
259e0dac50fSopenharmony_ci    WLOGI("usedModeIdx / SupportMode size: %{public}u %{public}zu", usedModeIdx, modes.size());
260e0dac50fSopenharmony_ci
261e0dac50fSopenharmony_ci    for (uint32_t modeIdx = 0; modeIdx < modes.size(); modeIdx++) {
262e0dac50fSopenharmony_ci        if (modeIdx != usedModeIdx && CheckModeSizeChange(modes[usedModeIdx], modes[modeIdx])) {
263e0dac50fSopenharmony_ci            defaultScreen_->SetScreenActiveMode(modeIdx);
264e0dac50fSopenharmony_ci            WLOGI("SetScreenActiveMode: %{public}u -> %{public}u", usedModeIdx, modeIdx);
265e0dac50fSopenharmony_ci            ASSERT_EQ(true, ScreenSizeEqual(defaultScreen_, modes[modeIdx]));
266e0dac50fSopenharmony_ci            ASSERT_EQ(true, CheckDisplayChangeEventCallback(true));
267e0dac50fSopenharmony_ci            // reset usedMode
268e0dac50fSopenharmony_ci            ResetDisplayChangeListener();
269e0dac50fSopenharmony_ci            defaultScreen_->SetScreenActiveMode(usedModeIdx);
270e0dac50fSopenharmony_ci            CheckDisplayChangeEventCallback(true);
271e0dac50fSopenharmony_ci            break;
272e0dac50fSopenharmony_ci        }
273e0dac50fSopenharmony_ci    }
274e0dac50fSopenharmony_ci}
275e0dac50fSopenharmony_ci
276e0dac50fSopenharmony_ci/**
277e0dac50fSopenharmony_ci * @tc.name: CheckDisplaySizeChange02
278e0dac50fSopenharmony_ci * @tc.desc: Check display size change as screen mode set if screen sets another mode
279e0dac50fSopenharmony_ci * @tc.type: FUNC
280e0dac50fSopenharmony_ci */
281e0dac50fSopenharmony_ciHWTEST_F(DisplayChangeTest, CheckDisplaySizeChange02, Function | MediumTest | Level2)
282e0dac50fSopenharmony_ci{
283e0dac50fSopenharmony_ci    WLOGI("CheckDisplaySizeChange02");
284e0dac50fSopenharmony_ci    auto modes = defaultScreen_->GetSupportedModes();
285e0dac50fSopenharmony_ci    uint32_t usedModeIdx = defaultScreen_->GetModeId();
286e0dac50fSopenharmony_ci    WLOGI("usedModeIdx / SupportMode size: %{public}u %{public}zu", usedModeIdx, modes.size());
287e0dac50fSopenharmony_ci
288e0dac50fSopenharmony_ci    for (uint32_t modeIdx = 0; modeIdx < modes.size(); modeIdx++) {
289e0dac50fSopenharmony_ci        if (modeIdx != usedModeIdx && CheckModeSizeChange(modes[usedModeIdx], modes[modeIdx])) {
290e0dac50fSopenharmony_ci            defaultScreen_->SetScreenActiveMode(modeIdx);
291e0dac50fSopenharmony_ci            WLOGI("SetScreenActiveMode: %{public}u -> %{public}u", usedModeIdx, modeIdx);
292e0dac50fSopenharmony_ci            ASSERT_EQ(true, ScreenSizeEqual(defaultScreen_, modes[modeIdx]));
293e0dac50fSopenharmony_ci            ASSERT_EQ(true, CheckDisplayChangeEventCallback(true));
294e0dac50fSopenharmony_ci            sptr<Display> defaultDisplay = DisplayManager::GetInstance().GetDisplayById(defaultDisplayId_);
295e0dac50fSopenharmony_ci            ASSERT_NE(nullptr, defaultDisplay);
296e0dac50fSopenharmony_ci            ASSERT_EQ(true, DisplaySizeEqual(defaultDisplay, modes[modeIdx]));
297e0dac50fSopenharmony_ci            // reset usedMode
298e0dac50fSopenharmony_ci            ResetDisplayChangeListener();
299e0dac50fSopenharmony_ci            defaultScreen_->SetScreenActiveMode(usedModeIdx);
300e0dac50fSopenharmony_ci            CheckDisplayChangeEventCallback(true);
301e0dac50fSopenharmony_ci            break;
302e0dac50fSopenharmony_ci        }
303e0dac50fSopenharmony_ci    }
304e0dac50fSopenharmony_ci}
305e0dac50fSopenharmony_ci
306e0dac50fSopenharmony_ci/**
307e0dac50fSopenharmony_ci * @tc.name: CheckScreenDensityChange01
308e0dac50fSopenharmony_ci * @tc.desc: Check screen density change as set another density for screen
309e0dac50fSopenharmony_ci * @tc.type: FUNC
310e0dac50fSopenharmony_ci */
311e0dac50fSopenharmony_ciHWTEST_F(DisplayChangeTest, CheckScreenDensityChange01, Function | SmallTest | Level2)
312e0dac50fSopenharmony_ci{
313e0dac50fSopenharmony_ci    DisplayChangeTest::originalDisplayDpi = static_cast<uint32_t>(DisplayManager::GetInstance().
314e0dac50fSopenharmony_ci        GetDisplayById(defaultDisplayId_)->GetVirtualPixelRatio() * BASELINE_DENSITY);
315e0dac50fSopenharmony_ci    ASSERT_NE(0, DisplayChangeTest::originalDisplayDpi);
316e0dac50fSopenharmony_ci    uint32_t densityDpi = 320;
317e0dac50fSopenharmony_ci    ASSERT_EQ(DMError::DM_OK, defaultScreen_->SetDensityDpi(densityDpi));
318e0dac50fSopenharmony_ci    sleep(SPLIT_TEST_SLEEP_S);
319e0dac50fSopenharmony_ci}
320e0dac50fSopenharmony_ci
321e0dac50fSopenharmony_ci/**
322e0dac50fSopenharmony_ci * @tc.name: CheckScreenDensityChange02
323e0dac50fSopenharmony_ci * @tc.desc: Check screen density change as set another density for screen
324e0dac50fSopenharmony_ci * @tc.type: FUNC
325e0dac50fSopenharmony_ci */
326e0dac50fSopenharmony_ciHWTEST_F(DisplayChangeTest, CheckScreenDensityChange02, Function | SmallTest | Level2)
327e0dac50fSopenharmony_ci{
328e0dac50fSopenharmony_ci    uint32_t densityDpi = 80;
329e0dac50fSopenharmony_ci    ASSERT_EQ(DMError::DM_OK, defaultScreen_->SetDensityDpi(densityDpi));
330e0dac50fSopenharmony_ci    sleep(SPLIT_TEST_SLEEP_S);
331e0dac50fSopenharmony_ci}
332e0dac50fSopenharmony_ci
333e0dac50fSopenharmony_ci/**
334e0dac50fSopenharmony_ci * @tc.name: CheckScreenDensityChange03
335e0dac50fSopenharmony_ci * @tc.desc: Check screen density change as set an invalid density for screen
336e0dac50fSopenharmony_ci * @tc.type: FUNC
337e0dac50fSopenharmony_ci */
338e0dac50fSopenharmony_ciHWTEST_F(DisplayChangeTest, CheckScreenDensityChange03, Function | SmallTest | Level2)
339e0dac50fSopenharmony_ci{
340e0dac50fSopenharmony_ci    uint32_t densityDpi = DOT_PER_INCH_MAXIMUM_VALUE + 1;
341e0dac50fSopenharmony_ci    ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, defaultScreen_->SetDensityDpi(densityDpi));
342e0dac50fSopenharmony_ci}
343e0dac50fSopenharmony_ci
344e0dac50fSopenharmony_ci/**
345e0dac50fSopenharmony_ci * @tc.name: CheckScreenDensityChange04
346e0dac50fSopenharmony_ci * @tc.desc: Check screen density change as set an invalid density for screen
347e0dac50fSopenharmony_ci * @tc.type: FUNC
348e0dac50fSopenharmony_ci */
349e0dac50fSopenharmony_ciHWTEST_F(DisplayChangeTest, CheckScreenDensityChange04, Function | SmallTest | Level2)
350e0dac50fSopenharmony_ci{
351e0dac50fSopenharmony_ci    uint32_t densityDpi = 40;
352e0dac50fSopenharmony_ci    ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, defaultScreen_->SetDensityDpi(densityDpi));
353e0dac50fSopenharmony_ci}
354e0dac50fSopenharmony_ci
355e0dac50fSopenharmony_ci/**
356e0dac50fSopenharmony_ci * @tc.name: CheckScreenDensityChange05
357e0dac50fSopenharmony_ci * @tc.desc: Restore original display density
358e0dac50fSopenharmony_ci * @tc.type: FUNC
359e0dac50fSopenharmony_ci */
360e0dac50fSopenharmony_ciHWTEST_F(DisplayChangeTest, CheckScreenDensityChange05, Function | SmallTest | Level2)
361e0dac50fSopenharmony_ci{
362e0dac50fSopenharmony_ci    ASSERT_EQ(DMError::DM_OK, defaultScreen_->SetDensityDpi(DisplayChangeTest::originalDisplayDpi));
363e0dac50fSopenharmony_ci    sleep(SPLIT_TEST_SLEEP_S);
364e0dac50fSopenharmony_ci}
365e0dac50fSopenharmony_ci
366e0dac50fSopenharmony_ci/**
367e0dac50fSopenharmony_ci * @tc.name: CheckWaterfallCompression01
368e0dac50fSopenharmony_ci * @tc.desc: check function of waterfall display compression.
369e0dac50fSopenharmony_ci * @tc.type: FUNC
370e0dac50fSopenharmony_ci */
371e0dac50fSopenharmony_ciHWTEST_F(DisplayChangeTest, CheckWaterfallCompression01, Function | SmallTest | Level2)
372e0dac50fSopenharmony_ci{
373e0dac50fSopenharmony_ci    bool originWaterfallEnable = DisplayCutoutController::IsWaterfallDisplay();
374e0dac50fSopenharmony_ci    DisplayCutoutController::SetIsWaterfallDisplay(true);
375e0dac50fSopenharmony_ci
376e0dac50fSopenharmony_ci    bool originStatus = DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal();
377e0dac50fSopenharmony_ci    DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(true);
378e0dac50fSopenharmony_ci
379e0dac50fSopenharmony_ci    uint32_t originSize = DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal();
380e0dac50fSopenharmony_ci    uint32_t testSizeInVp = 24;
381e0dac50fSopenharmony_ci    DisplayCutoutController::SetWaterfallAreaCompressionSizeWhenHorizontal(testSizeInVp);
382e0dac50fSopenharmony_ci
383e0dac50fSopenharmony_ci    ASSERT_EQ(true, DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal());
384e0dac50fSopenharmony_ci    ASSERT_EQ(testSizeInVp, DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal());
385e0dac50fSopenharmony_ci
386e0dac50fSopenharmony_ci    Orientation originOrientation = defaultScreen_->GetOrientation();
387e0dac50fSopenharmony_ci    DisplayCutoutController::SetWaterfallAreaCompressionSizeWhenHorizontal(originSize);
388e0dac50fSopenharmony_ci    ASSERT_EQ(originSize, DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal());
389e0dac50fSopenharmony_ci    DisplayCutoutController::SetWaterfallAreaCompressionEnableWhenHorzontal(originStatus);
390e0dac50fSopenharmony_ci    ASSERT_EQ(originStatus, DisplayCutoutController::IsWaterfallAreaCompressionEnableWhenHorizontal());
391e0dac50fSopenharmony_ci    DisplayCutoutController::SetIsWaterfallDisplay(originWaterfallEnable);
392e0dac50fSopenharmony_ci    ASSERT_EQ(originOrientation, defaultScreen_->GetOrientation());
393e0dac50fSopenharmony_ci}
394e0dac50fSopenharmony_ci}
395e0dac50fSopenharmony_ci} // namespace Rosen
396e0dac50fSopenharmony_ci} // namespace OHOS