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 <gtest/gtest.h>
17
18#include "abstract_display.h"
19#include "abstract_screen_controller.h"
20
21using namespace testing;
22using namespace testing::ext;
23
24namespace OHOS {
25namespace Rosen {
26class AbstractDisplayTest : public testing::Test {
27public:
28    static void SetUpTestCase();
29    static void TearDownTestCase();
30    void SetUp() override;
31    void TearDown() override;
32
33    DisplayId id = 1;
34    std::string name = "abstract_display_test";
35    SupportedScreenModes modesInfo;
36    std::recursive_mutex mutex;
37    sptr<AbstractScreenController> absController;
38    sptr<AbstractScreen> absScreen;
39    sptr<AbstractDisplay> absDisplay;
40    sptr<AbstractDisplay> absDisplay2;
41    sptr<AbstractDisplay> absDisplay3;
42    sptr<AbstractDisplay> absDisplay4;
43};
44
45void AbstractDisplayTest::SetUpTestCase()
46{
47}
48
49void AbstractDisplayTest::TearDownTestCase()
50{
51}
52
53void AbstractDisplayTest::SetUp()
54{
55    modesInfo.width_ = 2160;
56    modesInfo.height_ = 1600;
57    modesInfo.refreshRate_ = 60;
58    sptr<SupportedScreenModes> info = new SupportedScreenModes(modesInfo);
59    absController = nullptr;
60    absScreen = new AbstractScreen(absController, name, 1, 1);
61    absDisplay = new AbstractDisplay(id, info, absScreen);
62    modesInfo.width_ = 800;
63    modesInfo.height_ = 2560;
64    absDisplay2 = new AbstractDisplay(id, info, absScreen);
65    modesInfo.width_ = 2560;
66    modesInfo.height_ = 2560;
67    absDisplay3 = new AbstractDisplay(id, info, absScreen);
68    modesInfo.width_ = 2560;
69    modesInfo.height_ = 1600;
70    absDisplay4 = new AbstractDisplay(id, info, absScreen);
71}
72
73void AbstractDisplayTest::TearDown()
74{
75}
76
77namespace {
78/**
79 * @tc.name: BindAbstractScreen
80 * @tc.desc: BindAbstractScreen test
81 * @tc.type: FUNC
82 */
83HWTEST_F(AbstractDisplayTest, BindAbstractScreen01, Function | SmallTest | Level3)
84{
85    sptr<AbstractScreen> abstractScreen = nullptr;
86    ASSERT_EQ(false, absDisplay->BindAbstractScreen(abstractScreen));
87}
88/**
89 * @tc.name: BindAbstractScreen
90 * @tc.desc: BindAbstractScreen test
91 * @tc.type: FUNC
92 */
93HWTEST_F(AbstractDisplayTest, BindAbstractScreen02, Function | SmallTest | Level3)
94{
95    sptr<AbstractScreen> abstractScreen = absScreen;
96    abstractScreen->activeIdx_ = -1;
97    ASSERT_EQ(false, absDisplay->BindAbstractScreen(abstractScreen));
98}
99/**
100 * @tc.name: CalculateXYDpi
101 * @tc.desc: CalculateXYDpi test
102 * @tc.type: FUNC
103 */
104HWTEST_F(AbstractDisplayTest, CalculateXYDpi, Function | SmallTest | Level3)
105{
106    uint32_t phyWidth = 0;
107    uint32_t phyHeight = 0;
108    absDisplay->CalculateXYDpi(phyWidth, phyHeight);
109    phyWidth = 1;
110    absDisplay->CalculateXYDpi(phyWidth, phyHeight);
111    phyHeight = 1;
112    absDisplay->CalculateXYDpi(phyWidth, phyHeight);
113    phyWidth = 0;
114    absDisplay->CalculateXYDpi(phyWidth, phyHeight);
115    ASSERT_EQ(1, absDisplay->phyHeight_);
116}
117/**
118 * @tc.name: GetRefreshRate
119 * @tc.desc: GetRefreshRate test
120 * @tc.type: FUNC
121 */
122HWTEST_F(AbstractDisplayTest, GetRefreshRate, Function | SmallTest | Level3)
123{
124    uint32_t refreshRate = 1;
125    absDisplay->SetRefreshRate(refreshRate);
126    absDisplay->GetRefreshRate();
127    ASSERT_EQ(1, absDisplay->refreshRate_);
128}
129/**
130 * @tc.name: GetOffsetX
131 * @tc.desc: GetOffsetX test
132 * @tc.type: FUNC
133 */
134HWTEST_F(AbstractDisplayTest, GetOffsetX, Function | SmallTest | Level3)
135{
136    int32_t offsetX = 1;
137    absDisplay->SetOffsetX(offsetX);
138    ASSERT_EQ(1, absDisplay->GetOffsetX());
139}
140/**
141 * @tc.name: GetOffsetY
142 * @tc.desc: GetOffsetX test
143 * @tc.type: FUNC
144 */
145HWTEST_F(AbstractDisplayTest, GetOffsetY, Function | SmallTest | Level3)
146{
147    int32_t offsetY = 1;
148    absDisplay->SetOffsetY(offsetY);
149    ASSERT_EQ(1, absDisplay->GetOffsetY());
150}
151/**
152 * @tc.name: UpdateXDpi
153 * @tc.desc: UpdateXDpi test
154 * @tc.type: FUNC
155 */
156HWTEST_F(AbstractDisplayTest, UpdateXDpi, Function | SmallTest | Level3)
157{
158    uint32_t phyWidth = UINT32_MAX;
159    uint32_t phyHeight = 0;
160    absDisplay->CalculateXYDpi(phyWidth, phyHeight);
161    absDisplay->UpdateXDpi();
162    ASSERT_EQ(UINT32_MAX, absDisplay->phyWidth_);
163}
164/**
165 * @tc.name: UpdateYDpi
166 * @tc.desc: UpdateYDpi test
167 * @tc.type: FUNC
168 */
169HWTEST_F(AbstractDisplayTest, UpdateYDpi, Function | SmallTest | Level3)
170{
171    uint32_t phyWidth = UINT32_MAX;
172    uint32_t phyHeight = UINT32_MAX;
173    absDisplay->CalculateXYDpi(phyWidth, phyHeight);
174    absDisplay->UpdateYDpi();
175    ASSERT_EQ(UINT32_MAX, absDisplay->phyHeight_);
176}
177/**
178 * @tc.name: SetId
179 * @tc.desc: SetId test
180 * @tc.type: FUNC
181 */
182HWTEST_F(AbstractDisplayTest, SetId, Function | SmallTest | Level3)
183{
184    DisplayId id = 1;
185    absDisplay->SetId(id);
186    ASSERT_EQ(1, absDisplay->GetId());
187}
188/**
189 * @tc.name: SetDisplayOrientation
190 * @tc.desc: SetDisplayOrientation test
191 * @tc.type: FUNC
192 */
193HWTEST_F(AbstractDisplayTest, SetDisplayOrientation, Function | SmallTest | Level3)
194{
195    DisplayOrientation displayOrientation = DisplayOrientation::PORTRAIT;
196    absDisplay->SetDisplayOrientation(displayOrientation);
197    ASSERT_EQ(DisplayOrientation::PORTRAIT, absDisplay->GetDisplayOrientation());
198}
199/**
200 * @tc.name: GetRotationAndGetOrientation
201 * @tc.desc: GetRotationAndGetOrientation test
202 * @tc.type: FUNC
203 */
204HWTEST_F(AbstractDisplayTest, GetRotationAndGetOrientation, Function | SmallTest | Level3)
205{
206    DisplayId id = 1;
207    absDisplay->SetId(id);
208    absDisplay->GetRotation();
209    absDisplay->GetOrientation();
210    ASSERT_EQ(1, absDisplay->GetId());
211}
212/**
213 * @tc.name: SetFreezeFlag
214 * @tc.desc: SetFreezeFlag test
215 * @tc.type: FUNC
216 */
217HWTEST_F(AbstractDisplayTest, SetFreezeFlag, Function | SmallTest | Level3)
218{
219    FreezeFlag freezeFlag = FreezeFlag::FREEZING;
220    absDisplay->SetFreezeFlag(freezeFlag);
221    ASSERT_EQ(FreezeFlag::FREEZING, absDisplay->GetFreezeFlag());
222}
223}
224} // namespace Rosen
225} // namespace OHOS
226