• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "display_group_info.h"
18 #include "wm_common.h"
19 #include "dm_common.h"
20 #include "common_test_utils.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Rosen {
27 
28 class DisplayGroupInfoTest : public testing::Test {
29 public:
30     static void SetUpTestCase();
31     static void TearDownTestCase();
32     void SetUp() override;
33     void TearDown() override;
34 
35     void AddTestDisplayInfo(std::map<DisplayId, sptr<DisplayInfo>>& displayInfosMap_);
36     sptr<DisplayGroupInfo> displayGroupInfo_;
37 };
38 
SetUpTestCase()39 void DisplayGroupInfoTest::SetUpTestCase()
40 {
41 }
42 
TearDownTestCase()43 void DisplayGroupInfoTest::TearDownTestCase()
44 {
45 }
46 
SetUp()47 void DisplayGroupInfoTest::SetUp()
48 {
49     ScreenId displayGroupId = 0;
50     sptr<DisplayInfo> displayInfo = new DisplayInfo();
51     DisplayId displayId = 0;
52     displayInfo->SetDisplayId(displayId);
53     displayInfo->SetOffsetX(1);
54     displayInfo->SetOffsetY(1);
55     displayInfo->SetWidth(1);
56     displayInfo->SetHeight(1);
57     displayGroupInfo_ = new DisplayGroupInfo(displayGroupId, displayInfo);
58     AddTestDisplayInfo(displayGroupInfo_->displayInfosMap_);
59 }
60 
TearDown()61 void DisplayGroupInfoTest::TearDown()
62 {
63 }
64 
AddTestDisplayInfo(std::map<DisplayId,sptr<DisplayInfo>> & displayInfosMap_)65 void DisplayGroupInfoTest::AddTestDisplayInfo(std::map<DisplayId, sptr<DisplayInfo>>& displayInfosMap_)
66 {
67     sptr<DisplayInfo> displayInfo1 = new DisplayInfo();
68     DisplayId displayId1 = 1;
69     int32_t offsetX1 = 0;
70     int32_t offsetY1 = 0;
71     int32_t height1 = 0;
72     int32_t width1 = 0;
73     displayInfo1->SetDisplayId(displayId1);
74     displayInfo1->SetOffsetX(offsetX1);
75     displayInfo1->SetOffsetY(offsetY1);
76     displayInfo1->SetHeight(height1);
77     displayInfo1->SetWidth(width1);
78     displayInfosMap_.insert(std::make_pair(displayId1, displayInfo1));
79     sptr<DisplayInfo> displayInfo2 = new DisplayInfo();
80     DisplayId displayId2 = 2;
81     int32_t offsetX2 = 2;
82     int32_t offsetY2 = 2;
83     int32_t height2 = 2;
84     int32_t width2 = 2;
85     displayInfo2->SetDisplayId(displayId2);
86     displayInfo2->SetOffsetX(offsetX2);
87     displayInfo2->SetOffsetY(offsetY2);
88     displayInfo2->SetHeight(height2);
89     displayInfo2->SetWidth(width2);
90     displayInfosMap_.insert(std::make_pair(displayId2, displayInfo2));
91 }
92 
93 namespace {
94 /**
95  * @tc.name: AddDisplayInfo0
96  * @tc.desc: normal function
97  * @tc.type: FUNC
98  */
99 HWTEST_F(DisplayGroupInfoTest, AddDisplayInfo01, Function | SmallTest | Level2)
100 {
101     sptr<DisplayInfo> displayInfo = new DisplayInfo();
102     displayInfo->SetDisplayId(0);
103     displayGroupInfo_->AddDisplayInfo(displayInfo);
104     ASSERT_EQ(3u, displayGroupInfo_->displayInfosMap_.size());
105 }
106 
107 /**
108  * @tc.name: AddDisplayInfo1
109  * @tc.desc: normal function
110  * @tc.type: FUNC
111  */
112 HWTEST_F(DisplayGroupInfoTest, AddDisplayInfo02, Function | SmallTest | Level2)
113 {
114     sptr<DisplayInfo> displayInfo = new DisplayInfo();
115     displayInfo->SetDisplayId(3);
116     displayGroupInfo_->AddDisplayInfo(displayInfo);
117     ASSERT_EQ(4u, displayGroupInfo_->displayInfosMap_.size());
118 }
119 
120 /**
121  * @tc.name: RemoveDisplayInfo01
122  * @tc.desc: normal function
123  * @tc.type: FUNC
124  */
125 HWTEST_F(DisplayGroupInfoTest, RemoveDisplayInfo01, Function | SmallTest | Level2)
126 {
127     DisplayId displayId = 0;
128     displayGroupInfo_->RemoveDisplayInfo(displayId);
129     ASSERT_EQ(2u, displayGroupInfo_->displayInfosMap_.size());
130 }
131 
132 /**
133  * @tc.name: RemoveDisplayInfo02
134  * @tc.desc: normal function
135  * @tc.type: FUNC
136  */
137 HWTEST_F(DisplayGroupInfoTest, RemoveDisplayInfo02, Function | SmallTest | Level2)
138 {
139     DisplayId displayId = 3;
140     displayGroupInfo_->RemoveDisplayInfo(displayId);
141     ASSERT_EQ(3u, displayGroupInfo_->displayInfosMap_.size());
142 }
143 
144 /**
145  * @tc.name: GetAllDisplayRects01
146  * @tc.desc: normal function
147  * @tc.type: FUNC
148  */
149 HWTEST_F(DisplayGroupInfoTest, GetAllDisplayRects01, Function | SmallTest | Level2)
150 {
151     ASSERT_EQ(3u, displayGroupInfo_->GetAllDisplayRects().size());
152 }
153 
154 /**
155  * @tc.name: UpdateLeftAndRightDisplayId01
156  * @tc.desc: normal function
157  * @tc.type: FUNC
158  */
159 HWTEST_F(DisplayGroupInfoTest, UpdateLeftAndRightDisplayId01, Function | SmallTest | Level2)
160 {
161     displayGroupInfo_->UpdateLeftAndRightDisplayId();
162     ASSERT_EQ(1u, displayGroupInfo_->GetLeftDisplayId());
163     ASSERT_EQ(2u, displayGroupInfo_->GetRightDisplayId());
164 }
165 
166 /**
167  * @tc.name: SetDisplayRotation01 and GetDisplayRotation01
168  * @tc.desc: normal function
169  * @tc.type: FUNC
170  */
171 HWTEST_F(DisplayGroupInfoTest, SetDisplayRotation01, Function | SmallTest | Level2)
172 {
173     DisplayId displayId = 0;
174     displayGroupInfo_->SetDisplayRotation(displayId, Rotation::ROTATION_90);
175     ASSERT_EQ(Rotation::ROTATION_90, displayGroupInfo_->GetDisplayRotation(displayId));
176 }
177 
178 /**
179  * @tc.name: SetDisplayRotation02 and GetDisplayRotation02
180  * @tc.desc: normal function
181  * @tc.type: FUNC
182  */
183 HWTEST_F(DisplayGroupInfoTest, SetDisplayRotation02, Function | SmallTest | Level2)
184 {
185     DisplayId displayId = 3;
186     displayGroupInfo_->SetDisplayRotation(displayId, Rotation::ROTATION_90);
187     ASSERT_EQ(Rotation::ROTATION_0, displayGroupInfo_->GetDisplayRotation(displayId));
188 }
189 
190 /**
191  * @tc.name: SetDisplayVirtualPixelRatio01 and GetDisplayVirtualPixelRatio01
192  * @tc.desc: normal function
193  * @tc.type: FUNC
194  */
195 HWTEST_F(DisplayGroupInfoTest, SetDisplayVirtualPixelRatio01, Function | SmallTest | Level2)
196 {
197     DisplayId displayId = 0;
198     displayGroupInfo_->SetDisplayVirtualPixelRatio(displayId, 0.1f);
199     ASSERT_FLOAT_EQ(0.1f, displayGroupInfo_->GetDisplayVirtualPixelRatio(displayId));
200 }
201 
202 /**
203  * @tc.name: SetDisplayVirtualPixelRatio02 and GetDisplayVirtualPixelRatio02
204  * @tc.desc: normal function
205  * @tc.type: FUNC
206  */
207 HWTEST_F(DisplayGroupInfoTest, SetDisplayVirtualPixelRatio02, Function | SmallTest | Level2)
208 {
209     DisplayId displayId = 3;
210     displayGroupInfo_->SetDisplayVirtualPixelRatio(displayId, 0.1f);
211     ASSERT_EQ(1.0f, displayGroupInfo_->GetDisplayVirtualPixelRatio(displayId));
212 }
213 
214 /**
215  * @tc.name: SetDisplayRect01 and GetDisplayRect01
216  * @tc.desc: normal function
217  * @tc.type: FUNC
218  */
219 HWTEST_F(DisplayGroupInfoTest, SetDisplayRect01, Function | SmallTest | Level2)
220 {
221     DisplayId displayId = 0;
222     Rect rect = {3, 3, 3, 3};
223     displayGroupInfo_->SetDisplayRect(displayId, rect);
224     ASSERT_EQ(rect, displayGroupInfo_->GetDisplayRect(displayId));
225 }
226 
227 /**
228  * @tc.name: SetDisplayRect02 and GetDisplayRect02
229  * @tc.desc: normal function
230  * @tc.type: FUNC
231  */
232 HWTEST_F(DisplayGroupInfoTest, SetDisplayRect02, Function | SmallTest | Level2)
233 {
234     DisplayId displayId = 3;
235     Rect rect1 = {3, 3, 3, 3};
236     displayGroupInfo_->SetDisplayRect(displayId, rect1);
237     Rect rect2 = {0, 0, 0, 0};
238     ASSERT_EQ(rect2, displayGroupInfo_->GetDisplayRect(displayId));
239 }
240 
241 /**
242  * @tc.name: UpdateDisplayInfo01
243  * @tc.desc: normal function
244  * @tc.type: FUNC
245  */
246 HWTEST_F(DisplayGroupInfoTest, UpdateDisplayInfo01, Function | SmallTest | Level2)
247 {
248     sptr<DisplayInfo> displayInfo = new DisplayInfo();
249     DisplayId displayId = 0;
250     displayInfo->SetDisplayId(displayId);
251     ScreenId screenId = 1;
252     displayInfo->SetScreenId(screenId);
253     displayGroupInfo_->UpdateDisplayInfo(displayInfo);
254     ASSERT_EQ(1u, displayGroupInfo_->GetDisplayInfo(displayId)->GetScreenId());
255 }
256 
257 /**
258  * @tc.name: UpdateDisplayInfo02
259  * @tc.desc: normal function
260  * @tc.type: FUNC
261  */
262 HWTEST_F(DisplayGroupInfoTest, UpdateDisplayInfo02, Function | SmallTest | Level2)
263 {
264     sptr<DisplayInfo> displayInfo = new DisplayInfo();
265     DisplayId displayId = 3;
266     displayInfo->SetDisplayId(displayId);
267     ScreenId screenId = 1;
268     displayInfo->SetScreenId(screenId);
269     displayGroupInfo_->UpdateDisplayInfo(displayInfo);
270     ASSERT_EQ(nullptr, displayGroupInfo_->GetDisplayInfo(displayId));
271 }
272 }
273 }
274 }