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