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