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