1 /*
2 * Copyright (c) 2023 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 <libxml/globals.h>
19 #include <libxml/xmlstring.h>
20 #include "screen_scene_config.h"
21 #include "xml_config_base.h"
22 #include "window_manager_hilog.h"
23
24 using namespace testing;
25 using namespace testing::ext;
26
27 namespace OHOS {
28 namespace Rosen {
29 class ScreenSceneConfigTest : public testing::Test {
30 public:
31 static void SetUpTestCase();
32 static void TearDownTestCase();
33 void SetUp() override;
34 void TearDown() override;
35 };
36
SetUpTestCase()37 void ScreenSceneConfigTest::SetUpTestCase()
38 {
39 }
40
TearDownTestCase()41 void ScreenSceneConfigTest::TearDownTestCase()
42 {
43 }
44
SetUp()45 void ScreenSceneConfigTest::SetUp()
46 {
47 }
48
TearDown()49 void ScreenSceneConfigTest::TearDown()
50 {
51 }
52
53 namespace {
54 /**
55 * @tc.name: IsNumber
56 * @tc.desc: test function : IsNumber
57 * @tc.type: FUNC
58 */
59 HWTEST_F(ScreenSceneConfigTest, IsNumber, Function | SmallTest | Level1)
60 {
61 bool result = ScreenSceneConfig::IsNumber("123");
62 ASSERT_EQ(true, result);
63 result = ScreenSceneConfig::IsNumber("a123");
64 ASSERT_EQ(false, result);
65 }
66
67 /**
68 * @tc.name: GetConfigPath1
69 * @tc.desc: test function : GetConfigPath
70 * @tc.type: FUNC
71 */
72 HWTEST_F(ScreenSceneConfigTest, GetConfigPath1, Function | SmallTest | Level1)
73 {
74 auto result = ScreenSceneConfig::GetConfigPath("");
75 ASSERT_STRNE("/system/", result.c_str());
76 }
77
78 /**
79 * @tc.name: GetConfigPath2
80 * @tc.desc: test function : GetConfigPath
81 * @tc.type: FUNC
82 */
83 HWTEST_F(ScreenSceneConfigTest, GetConfigPath2, Function | SmallTest | Level1)
84 {
85 auto result = ScreenSceneConfig::GetConfigPath("a.xml");
86 ASSERT_STREQ("/system/a.xml", result.c_str());
87 }
88
89 /**
90 * @tc.name: LoadConfigXml
91 * @tc.desc: test function : loadConfigXml
92 * @tc.type: FUNC
93 */
94 HWTEST_F(ScreenSceneConfigTest, LoadConfigXml, Function | SmallTest | Level1)
95 {
96 auto result = ScreenSceneConfig::LoadConfigXml();
97 ASSERT_EQ(true, result);
98 }
99
100 /**
101 * @tc.name: IsValidNode1
102 * @tc.desc: test function : IsValidNode
103 * @tc.type: FUNC
104 */
105 HWTEST_F(ScreenSceneConfigTest, IsValidNode1, Function | SmallTest | Level1)
106 {
107 xmlNode node;
108 auto result = ScreenSceneConfig::IsValidNode(node);
109 ASSERT_EQ(false, result);
110 }
111
112 /**
113 * @tc.name: IsValidNode2
114 * @tc.desc: test function : IsValidNode
115 * @tc.type: FUNC
116 */
117 HWTEST_F(ScreenSceneConfigTest, IsValidNode2, Function | SmallTest | Level1)
118 {
119 const xmlChar xmlStringText[] = { 't', 'e', 'x', 't', 0 };
120 xmlNode node;
121 node.name = xmlStringText;
122 node.type = XML_TEXT_NODE;
123 auto result = ScreenSceneConfig::IsValidNode(node);
124 ASSERT_EQ(true, result);
125 }
126
127 /**
128 * @tc.name: ReadIntNumbersConfigInfo
129 * @tc.desc: test function : ReadIntNumbersConfigInfo
130 * @tc.type: FUNC
131 */
132 HWTEST_F(ScreenSceneConfigTest, ReadIntNumbersConfigInfo, Function | SmallTest | Level1)
133 {
134 ScreenSceneConfig::enableConfig_.clear();
135
136 auto configFilePath = ScreenSceneConfig::GetConfigPath("etc/window/resources/display_manager_config.xml");
137 xmlDocPtr docPtr = xmlReadFile(configFilePath.c_str(), nullptr, XML_PARSE_NOBLANKS);
138 if (docPtr == nullptr) {
139 return;
140 }
141
142 xmlNodePtr rootPtr = xmlDocGetRootElement(docPtr);
143 if (rootPtr == nullptr || rootPtr->name == nullptr ||
144 xmlStrcmp(rootPtr->name, reinterpret_cast<const xmlChar*>("Configs"))) {
145 xmlFreeDoc(docPtr);
146 return;
147 }
148 uint32_t readCount = 0;
149 for (xmlNodePtr curNodePtr = rootPtr->xmlChildrenNode; curNodePtr != nullptr; curNodePtr = curNodePtr->next) {
150 if (!ScreenSceneConfig::IsValidNode(*curNodePtr)) {
151 continue;
152 }
153 auto nodeName = curNodePtr->name;
154 if (!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("dpi")) ||
155 !xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("defaultDeviceRotationOffset")) ||
156 !xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("cutoutArea")) ||
157 !xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("curvedScreenBoundary"))) {
158 ScreenSceneConfig::ReadIntNumbersConfigInfo(curNodePtr);
159 readCount++;
160 continue;
161 }
162 }
163 ASSERT_GE(ScreenSceneConfig::intNumbersConfig_.size(), readCount);
164 ScreenSceneConfig::DumpConfig();
165 xmlFreeDoc(docPtr);
166 }
167
168
169 /**
170 * @tc.name: ReadEnableConfigInfo
171 * @tc.desc: test function : ReadEnableConfigInfo
172 * @tc.type: FUNC
173 */
174 HWTEST_F(ScreenSceneConfigTest, ReadEnableConfigInfo, Function | SmallTest | Level1)
175 {
176 ScreenSceneConfig::enableConfig_.clear();
177
178 auto configFilePath = ScreenSceneConfig::GetConfigPath("etc/window/resources/display_manager_config.xml");
179 xmlDocPtr docPtr = xmlReadFile(configFilePath.c_str(), nullptr, XML_PARSE_NOBLANKS);
180 if (docPtr == nullptr) {
181 return;
182 }
183
184 xmlNodePtr rootPtr = xmlDocGetRootElement(docPtr);
185 if (rootPtr == nullptr || rootPtr->name == nullptr ||
186 xmlStrcmp(rootPtr->name, reinterpret_cast<const xmlChar*>("Configs"))) {
187 xmlFreeDoc(docPtr);
188 return;
189 }
190 uint32_t readCount = 0;
191 for (xmlNodePtr curNodePtr = rootPtr->xmlChildrenNode; curNodePtr != nullptr; curNodePtr = curNodePtr->next) {
192 if (!ScreenSceneConfig::IsValidNode(*curNodePtr)) {
193 continue;
194 }
195
196 auto nodeName = curNodePtr->name;
197 if (!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("isWaterfallDisplay"))) {
198 ScreenSceneConfig::ReadEnableConfigInfo(curNodePtr);
199 readCount++;
200 continue;
201 }
202
203 if (!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("dpi"))) {
204 ScreenSceneConfig::ReadEnableConfigInfo(curNodePtr);
205 readCount++;
206 continue;
207 }
208 }
209
210 ASSERT_LE(ScreenSceneConfig::enableConfig_.size(), readCount);
211
212 ScreenSceneConfig::DumpConfig();
213 xmlFreeDoc(docPtr);
214 }
215
216 /**
217 * @tc.name: ReadStringConfigInfo
218 * @tc.desc: test function : ReadStringConfigInfo
219 * @tc.type: FUNC
220 */
221 HWTEST_F(ScreenSceneConfigTest, ReadStringConfigInfo, Function | SmallTest | Level1)
222 {
223 ScreenSceneConfig::enableConfig_.clear();
224
225 auto configFilePath = ScreenSceneConfig::GetConfigPath("etc/window/resources/display_manager_config.xml");
226 xmlDocPtr docPtr = xmlReadFile(configFilePath.c_str(), nullptr, XML_PARSE_NOBLANKS);
227 if (docPtr == nullptr) {
228 return;
229 }
230
231 xmlNodePtr rootPtr = xmlDocGetRootElement(docPtr);
232 if (rootPtr == nullptr || rootPtr->name == nullptr ||
233 xmlStrcmp(rootPtr->name, reinterpret_cast<const xmlChar*>("Configs"))) {
234 xmlFreeDoc(docPtr);
235 return;
236 }
237 uint32_t readCount = 0;
238 for (xmlNodePtr curNodePtr = rootPtr->xmlChildrenNode; curNodePtr != nullptr; curNodePtr = curNodePtr->next) {
239 if (!ScreenSceneConfig::IsValidNode(*curNodePtr)) {
240 continue;
241 }
242
243 auto nodeName = curNodePtr->name;
244 if (!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("defaultDisplayCutoutPath"))) {
245 ScreenSceneConfig::ReadStringConfigInfo(curNodePtr);
246 readCount++;
247 continue;
248 }
249
250 if (!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("dpi"))) {
251 ScreenSceneConfig::ReadStringConfigInfo(curNodePtr);
252 readCount++;
253 continue;
254 }
255 }
256
257 ASSERT_LE(ScreenSceneConfig::stringConfig_.size(), readCount);
258 ScreenSceneConfig::DumpConfig();
259 xmlFreeDoc(docPtr);
260 }
261
262 /**
263 * @tc.name: GetEnableConfig1
264 * @tc.desc: test function : GetEnableConfig
265 * @tc.type: FUNC
266 */
267 HWTEST_F(ScreenSceneConfigTest, GetEnableConfig, Function | SmallTest | Level1)
268 {
269 auto result = ScreenSceneConfig::GetEnableConfig();
270 ASSERT_EQ(true, result.size() == 0);
271 }
272
273 /**
274 * @tc.name: GetIntNumbersConfig
275 * @tc.desc: test function : GetIntNumbersConfig
276 * @tc.type: FUNC
277 */
278 HWTEST_F(ScreenSceneConfigTest, GetIntNumbersConfig, Function | SmallTest | Level1)
279 {
280 auto result = ScreenSceneConfig::GetIntNumbersConfig();
281 ASSERT_NE(true, result.size() == 0);
282 }
283
284 /**
285 * @tc.name: GetStringConfig
286 * @tc.desc: test function : GetStringConfig
287 * @tc.type: FUNC
288 */
289 HWTEST_F(ScreenSceneConfigTest, GetStringConfig, Function | SmallTest | Level1)
290 {
291 auto result = ScreenSceneConfig::GetStringConfig();
292 ASSERT_NE(0, result.size());
293 }
294
295 /**
296 * @tc.name: GetCurvedScreenBoundaryConfig
297 * @tc.desc: test function : GetCurvedScreenBoundaryConfig
298 * @tc.type: FUNC
299 */
300 HWTEST_F(ScreenSceneConfigTest, GetCurvedScreenBoundaryConfig, Function | SmallTest | Level1)
301 {
302 auto result = ScreenSceneConfig::GetCurvedScreenBoundaryConfig();
303 ASSERT_NE(0, result.size());
304 }
305
306 /**
307 * @tc.name: GetCutoutBoundaryRect
308 * @tc.desc: GetCutoutBoundaryRect func
309 * @tc.type: FUNC
310 */
311 HWTEST_F(ScreenSceneConfigTest, GetCutoutBoundaryRect, Function | SmallTest | Level3)
312 {
313 auto result = ScreenSceneConfig::GetCutoutBoundaryRect();
314 ASSERT_FALSE(result.size() > 0);
315 }
316
317 /**
318 * @tc.name: IsWaterfallDisplay
319 * @tc.desc: IsWaterfallDisplay func
320 * @tc.type: FUNC
321 */
322 HWTEST_F(ScreenSceneConfigTest, IsWaterfallDisplay, Function | SmallTest | Level3)
323 {
324 auto result = ScreenSceneConfig::IsWaterfallDisplay();
325 if (result) {
326 ASSERT_EQ(true, result);
327 }
328 }
329
330 /**
331 * @tc.name: GetCurvedCompressionAreaInLandscape
332 * @tc.desc: GetCurvedCompressionAreaInLandscape func
333 * @tc.type: FUNC
334 */
335 HWTEST_F(ScreenSceneConfigTest, GetCurvedCompressionAreaInLandscape, Function | SmallTest | Level3)
336 {
337 auto result = ScreenSceneConfig::GetCurvedCompressionAreaInLandscape();
338 ASSERT_TRUE(result == 0);
339 }
340
341 /**
342 * @tc.name: Split
343 * @tc.desc: Split func
344 * @tc.type: FUNC
345 */
346 HWTEST_F(ScreenSceneConfigTest, Split, Function | SmallTest | Level3)
347 {
348 auto result = ScreenSceneConfig::Split("oo", "+9");
349 ASSERT_NE(0, result.size());
350 }
351
352 /**
353 * @tc.name: CalcCutoutBoundaryRect
354 * @tc.desc: CalcCutoutBoundaryRect func
355 * @tc.type: FUNC
356 */
357 HWTEST_F(ScreenSceneConfigTest, CalcCutoutBoundaryRect, Function | SmallTest | Level3)
358 {
359 DMRect emptyRect = {0, 0, 0, 0};
360 auto result = ScreenSceneConfig::CalcCutoutBoundaryRect("oo");
361 ASSERT_FALSE(result != emptyRect);
362 }
363
364 /**
365 * @tc.name: SetCutoutSvgPath
366 * @tc.desc: SetCutoutSvgPath func
367 * @tc.type: FUNC
368 */
369 HWTEST_F(ScreenSceneConfigTest, SetCutoutSvgPath, Function | SmallTest | Level3)
370 {
371 ScreenSceneConfig::SetCutoutSvgPath("oo");
372 auto result_ = ScreenSceneConfig::GetCutoutBoundaryRect();
373 ASSERT_NE(0, result_.size());
374 }
375
376 /**
377 * @tc.name: SetCurvedCompressionAreaInLandscape
378 * @tc.desc: SetCurvedCompressionAreaInLandscape func
379 * @tc.type: FUNC
380 */
381 HWTEST_F(ScreenSceneConfigTest, SetCurvedCompressionAreaInLandscape, Function | SmallTest | Level3)
382 {
383 int res = 0;
384 ScreenSceneConfig::SetCurvedCompressionAreaInLandscape();
385 ASSERT_EQ(0, res);
386 }
387 }
388 } // namespace Rosen
389 } // namespace OHOS
390