1 /*
2 * Copyright (c) 2022-2024 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 "dscreen_maprelation_test.h"
17
18 using json = nlohmann::json;
19
20 using namespace testing::ext;
21
22 namespace OHOS {
23 namespace DistributedHardware {
SetUpTestCase(void)24 void DScreenMapRelationTest::SetUpTestCase(void) {}
25
TearDownTestCase(void)26 void DScreenMapRelationTest::TearDownTestCase(void) {}
27
SetUp()28 void DScreenMapRelationTest::SetUp()
29 {
30 dscreenMapRelation = std::make_shared<DScreenMapRelation>();
31 }
32
TearDown()33 void DScreenMapRelationTest::TearDown() {}
34
35 /**
36 * @tc.name: GetDisplayId_001
37 * @tc.desc: Verify the GetDisplayId function.
38 * @tc.type: FUNC
39 * @tc.require: Issue Number
40 */
41 HWTEST_F(DScreenMapRelationTest, GetDisplayId_001, TestSize.Level1)
42 {
43 uint64_t displayId = 0;
44 dscreenMapRelation->SetDisplayId(displayId);
45 uint64_t actual = dscreenMapRelation->GetDisplayId();
46 EXPECT_EQ(displayId, actual);
47 }
48
49 /**
50 * @tc.name: GetScreenId_001
51 * @tc.desc: Verify the GetScreenId function.
52 * @tc.type: FUNC
53 * @tc.require: Issue Number
54 */
55 HWTEST_F(DScreenMapRelationTest, GetScreenId_001, TestSize.Level1)
56 {
57 uint64_t screenId = 0;
58 dscreenMapRelation->SetScreenId(screenId);
59 uint64_t actual = dscreenMapRelation->GetScreenId();
60 EXPECT_EQ(screenId, actual);
61 }
62
63 /**
64 * @tc.name: GetDisplayRect_001
65 * @tc.desc: Verify the GetDisplayRect function.
66 * @tc.type: FUNC
67 * @tc.require: Issue Number
68 */
69 HWTEST_F(DScreenMapRelationTest, GetDisplayRect_001, TestSize.Level1)
70 {
71 DisplayRect res;
72 int32_t startX = 10;
73 res.startX = startX;
74 dscreenMapRelation->SetDisplayRect(res);
75 DisplayRect actual = dscreenMapRelation->GetDisplayRect();
76 EXPECT_EQ(startX, actual.startX);
77 }
78
79 /**
80 * @tc.name: GetScreenRect_001
81 * @tc.desc: Verify the GetScreenRect function.
82 * @tc.type: FUNC
83 * @tc.require: Issue Number
84 */
85 HWTEST_F(DScreenMapRelationTest, GetScreenRect_001, TestSize.Level1)
86 {
87 ScreenRect res;
88 int32_t startX = 10;
89 res.startX = startX;
90 dscreenMapRelation->SetScreenRect(res);
91 ScreenRect actual = dscreenMapRelation->GetScreenRect();
92 EXPECT_EQ(startX, actual.startX);
93 }
94
95 /**
96 * @tc.name: to_json_001
97 * @tc.desc: Verify the to_json function.
98 * @tc.type: FUNC
99 * @tc.require: Issue Number
100 */
101 HWTEST_F(DScreenMapRelationTest, to_json_001, TestSize.Level1)
102 {
103 json j;
104 uint64_t displayId = 1;
105 uint64_t screenId = 2;
106 ScreenRect screenRect = {0, 0, 200, 200};
107 DisplayRect displayRect = {0, 0, 100, 100};
108 DScreenMapRelation dScreenMapRelation;
109 dScreenMapRelation.SetDisplayId(displayId);
110 dScreenMapRelation.SetScreenId(screenId);
111 dScreenMapRelation.SetDisplayRect(displayRect);
112 dScreenMapRelation.SetScreenRect(screenRect);
113 to_json(j, dScreenMapRelation);
114
115 uint64_t jsonDisplayId = 0;
116 j.at(KEY_DISPLAY_ID).get_to(jsonDisplayId);
117 EXPECT_EQ(displayId, jsonDisplayId);
118 }
119
120 /**
121 * @tc.name: from_json_001
122 * @tc.desc: Verify the from_json function.
123 * @tc.type: FUNC
124 * @tc.require: Issue Number
125 */
126 HWTEST_F(DScreenMapRelationTest, from_json_001, TestSize.Level1)
127 {
128 json j;
129 uint64_t displayId = 1;
130 uint64_t screenId = 2;
131 DisplayRect displayRect = {0, 0, 100, 100};
132 ScreenRect screenRect = {0, 0, 200, 200};
133 DScreenMapRelation dScreenMapRelation;
134 dScreenMapRelation.SetDisplayId(displayId);
135 dScreenMapRelation.SetScreenId(screenId);
136 dScreenMapRelation.SetDisplayRect(displayRect);
137 dScreenMapRelation.SetScreenRect(screenRect);
138 to_json(j, dScreenMapRelation);
139
140 DScreenMapRelation jsonDScreenMapRelation;
141 from_json(j, jsonDScreenMapRelation);
142 EXPECT_EQ(displayId, jsonDScreenMapRelation.GetDisplayId());
143 }
144
145 /**
146 * @tc.name: from_json_002
147 * @tc.desc: Verify the from_json function.
148 * @tc.type: FUNC
149 * @tc.require: Issue Number
150 */
151 HWTEST_F(DScreenMapRelationTest, from_json_002, TestSize.Level1)
152 {
153 json j;
154 uint64_t displayId = 1;
155 uint64_t screenId = 2;
156 DScreenMapRelation jsonDScreenMapRelation;
157 from_json(j, jsonDScreenMapRelation);
158 j[KEY_DISPLAY_ID] = displayId;
159 from_json(j, jsonDScreenMapRelation);
160 j[KEY_SCREEN_ID] = screenId;
161 from_json(j, jsonDScreenMapRelation);
162 j[KEY_DISPLAY_RECT] = 2;
163 from_json(j, jsonDScreenMapRelation);
164 DisplayRect displayRect = {0, 0, 100, 100};
165 j[KEY_SCREEN_ID] = displayRect;
166 from_json(j, jsonDScreenMapRelation);
167 EXPECT_EQ(displayId, jsonDScreenMapRelation.GetDisplayId());
168 }
169
170 /**
171 * @tc.name: from_json_003
172 * @tc.desc: Verify the from_json function.
173 * @tc.type: FUNC
174 * @tc.require: Issue Number
175 */
176 HWTEST_F(DScreenMapRelationTest, from_json_003, TestSize.Level1)
177 {
178 json j;
179 int32_t startX = 1;
180 int32_t startY = 2;
181 int32_t width = 3;
182 int32_t height = 4;
183 DisplayRect displayRect;
184 from_json(j, displayRect);
185 EXPECT_EQ(0, displayRect.startX);
186 j[KEY_POINT_START_X] = startX;
187 from_json(j, displayRect);
188 EXPECT_EQ(0, displayRect.startX);
189 j[KEY_POINT_START_Y] = startY;
190 from_json(j, displayRect);
191 EXPECT_EQ(0, displayRect.startY);
192 j[KEY_WIDTH] = width;
193 from_json(j, displayRect);
194 EXPECT_EQ(0, displayRect.width);
195 j[KEY_HEIGHT] = height;
196 from_json(j, displayRect);
197 EXPECT_EQ(height, displayRect.height);
198 }
199
200 /**
201 * @tc.name: from_json_004
202 * @tc.desc: Verify the from_json function.
203 * @tc.type: FUNC
204 * @tc.require: Issue Number
205 */
206 HWTEST_F(DScreenMapRelationTest, from_json_004, TestSize.Level1)
207 {
208 json j;
209 int32_t startX = 1;
210 int32_t startY = 2;
211 uint32_t width = 3;
212 uint32_t height = 4;
213 ScreenRect screenRect;
214 from_json(j, screenRect);
215 EXPECT_EQ(0, screenRect.startX);
216 j[KEY_POINT_START_X] = startX;
217 from_json(j, screenRect);
218 EXPECT_EQ(0, screenRect.startX);
219 j[KEY_POINT_START_Y] = startY;
220 from_json(j, screenRect);
221 EXPECT_EQ(0, screenRect.startY);
222 j[KEY_WIDTH] = width;
223 from_json(j, screenRect);
224 EXPECT_EQ(0, screenRect.width);
225 j[KEY_HEIGHT] = height;
226 from_json(j, screenRect);
227 EXPECT_EQ(height, screenRect.height);
228 }
229 } // namespace DistributedHardware
230 } // namespace OHOS