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 #include <libxml/globals.h>
18 #include <libxml/xmlstring.h>
19 #include "window_scene_config.h"
20 #include "window_manager_hilog.h"
21
22 using namespace testing;
23 using namespace testing::ext;
24
25 namespace OHOS {
26 namespace Rosen {
27 using ConfigItem = WindowSceneConfig::ConfigItem;
28 const std::string XML_STR = R"(<?xml version='1.0' encoding="utf-8"?>
29 <!--
30 * Copyright (c) 2022 Huawei Device Co., Ltd.
31 * Licensed under the Apache License, Version 2.0 (the "License");
32 * you may not use this file except in compliance with the License.
33 * You may obtain a copy of the License at
34 *
35 * http://www.apache.org/licenses/LICENSE-2.0
36 *
37 * Unless required by applicable law or agreed to in writing, software
38 * distributed under the License is distributed on an "AS IS" BASIS,
39 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40 * See the License for the specific language governing permissions and
41 * limitations under the License.
42 -->
43 <Configs>
44 <!--decor enable is true means app main window show decoration-->
45 <decor enable="false"></decor>
46 <!--max number of main window that could be shown on display-->
47 <maxAppWindowNumber>100</maxAppWindowNumber>
48 <!--minimizeByOther enable is true means fullscreen window will be minmized by other fullscreen window-->
49 <minimizeByOther enable="true"></minimizeByOther>
50 <!--window mdoe change hot zones config, fullscreen primary secondary-->
51 <modeChangeHotZones>50 50 50</modeChangeHotZones>
52 <!--stretchable enable is true means all window be stretchable-->
53 <stretchable enable="false"></stretchable>
54 <!--exit split screen mode ratio config-->
55 <exitSplitRatios>0.1 0.9</exitSplitRatios>
56 <!--split screen ratios config-->
57 <splitRatios>0.5 0.33 0.67</splitRatios>
58 <!--default window mode config-->
59 <defaultWindowMode>1</defaultWindowMode>
60 <!--window animation config-->
61 <windowAnimation>
62 <timing>
63 <!--duration of animation when add/remove window, unit is ms-->
64 <duration>350</duration>
65 <!--timing curve of animation, config it as below:
66 name=ease, easeIn, easeOut, easeInOut, default, linear,
67 spring, interactiveSpring, cubic(float float float float)-->
68 <curve name="easeOut"></curve>
69 </timing>
70 <!--scaleX and scaleY of animation start state-->
71 <scale>0.7 0.7</scale>
72 <!--rotation of animation start state, 4 numbers is axis and angle-->
73 <rotation>0 0 1 0</rotation>
74 <!--translateX and translateY of animation start state-->
75 <translate>0 0</translate>
76 <!--opacity of animation start state-->
77 <opacity>0</opacity>
78 </windowAnimation>
79 <!--keyboard animation config-->
80 <keyboardAnimation>
81 <animationIn>
82 <timing>
83 <!--duration of animation when add keyboard, unit is ms-->
84 <duration>500</duration>
85 <!--friction curve-->
86 <curve name="cubic">0.2 0.0 0.2 1.0</curve>
87 </timing>
88 </animationIn>
89 <animationOut>
90 <timing>
91 <!--duration of animation when remove keyboard, unit is ms-->
92 <duration>300</duration>
93 <!--friction curve-->
94 <curve name="cubic">0.2 0.0 0.2 1.0</curve>
95 </timing>
96 </animationOut>
97 </keyboardAnimation>
98 <!--enable/disable remote animation-->
99 <remoteAnimation enable="true"></remoteAnimation>
100 <!--window effect config-->
101 <windowEffect>
102 <appWindows>
103 <cornerRadius>
104 <!--off: no corner, defaultCornerRadiusXS: 4vp, defaultCornerRadiusS: 8vp-->
105 <!--defaultCornerRadiusM: 12vp, defaultCornerRadiusL: 16vp, defaultCornerRadiusXL: 24vp-->
106 <fullScreen>off</fullScreen>
107 <split>off</split>
108 <float>off</float>
109 </cornerRadius>
110 <shadow>
111 <focused>
112 <elevation>0</elevation>
113 <color>#000000</color>
114 <offsetX>0</offsetX>
115 <offsetY>0</offsetY>
116 <alpha>0</alpha>
117 </focused>
118 <unfocused>
119 <elevation>0</elevation>
120 <color>#000000</color>
121 <offsetX>0</offsetX>
122 <offsetY>0</offsetY>
123 <alpha>0</alpha>
124 </unfocused>
125 </shadow>
126 </appWindows>
127 </windowEffect>
128 </Configs>
129 )";
130
131 class WindowSceneConfigTest : public testing::Test {
132 public:
133 static void SetUpTestCase();
134 static void TearDownTestCase();
135 void SetUp() override;
136 void TearDown() override;
137 ConfigItem ReadConfig(const std::string& xmlStr);
138 };
139
SetUpTestCase()140 void WindowSceneConfigTest::SetUpTestCase() {}
141
TearDownTestCase()142 void WindowSceneConfigTest::TearDownTestCase() {}
143
SetUp()144 void WindowSceneConfigTest::SetUp() {}
145
TearDown()146 void WindowSceneConfigTest::TearDown() {}
147
ReadConfig(const std::string & xmlStr)148 ConfigItem WindowSceneConfigTest::ReadConfig(const std::string& xmlStr)
149 {
150 ConfigItem cfgItem;
151 xmlDocPtr docPtr = xmlParseMemory(xmlStr.c_str(), xmlStr.length());
152 if (docPtr == nullptr) {
153 return cfgItem;
154 }
155
156 xmlNodePtr rootPtr = xmlDocGetRootElement(docPtr);
157 if (rootPtr == nullptr || rootPtr->name == nullptr ||
158 xmlStrcmp(rootPtr->name, reinterpret_cast<const xmlChar*>("Configs"))) {
159 xmlFreeDoc(docPtr);
160 return cfgItem;
161 }
162
163 std::map<std::string, ConfigItem> configMap;
164 cfgItem.SetValue(configMap);
165 WindowSceneConfig::ReadConfig(rootPtr, *cfgItem.mapValue_);
166 xmlFreeDoc(docPtr);
167 return cfgItem;
168 }
169 namespace {
170 /**
171 * @tc.name: AnimationConfig
172 * @tc.desc: animation config test
173 * @tc.type: FUNC
174 * @tc.require issueI5N26H
175 */
176 HWTEST_F(WindowSceneConfigTest, AnimationConfig, TestSize.Level1)
177 {
178 WindowSceneConfig::config_ = ReadConfig(XML_STR);
179 ConfigItem item = WindowSceneConfig::config_["windowAnimation"];
180 ASSERT_EQ(true, item.IsMap());
181 item = WindowSceneConfig::config_["windowAnimation"]["timing"]["duration"];
182 ASSERT_EQ(true, item.IsInts());
183
184 auto value = *item.intsValue_;
185 ASSERT_EQ(true, value.size() == 1);
186 ASSERT_EQ(350, value[0]);
187
188 item = WindowSceneConfig::config_["windowAnimation"]["timing"]["curve"].GetProp("name");
189 ASSERT_EQ(true, item.IsString());
190 ASSERT_EQ("easeOut", item.stringValue_);
191
192 item = WindowSceneConfig::config_["windowAnimation"]["scale"];
193 ASSERT_EQ(true, item.IsFloats());
194 ASSERT_EQ(true, item.floatsValue_->size() == 2);
195
196 item = WindowSceneConfig::config_["windowAnimation"]["rotation"];
197 ASSERT_EQ(true, item.IsFloats());
198 ASSERT_EQ(true, item.floatsValue_->size() == 4);
199
200 item = WindowSceneConfig::config_["windowAnimation"]["translate"];
201 ASSERT_EQ(true, item.IsFloats());
202 ASSERT_EQ(true, item.floatsValue_->size() == 2);
203
204 item = WindowSceneConfig::config_["windowAnimation"]["opacity"];
205 ASSERT_EQ(true, item.IsFloats());
206 ASSERT_EQ(true, item.floatsValue_->size() == 1);
207 }
208
209 /**
210 * @tc.name: maxAppWindowNumber
211 * @tc.desc: maxAppWindowNumber test
212 * @tc.type: FUNC
213 */
214 HWTEST_F(WindowSceneConfigTest, MaxAppWindowNumber, TestSize.Level1)
215 {
216 std::string xmlStr =
217 "<?xml version='1.0' encoding=\"utf-8\"?>"
218 "<Configs>"
219 "<maxAppWindowNumber>0</maxAppWindowNumber>"
220 "</Configs>";
221 WindowSceneConfig::config_ = ReadConfig(xmlStr);
222 WindowSceneConfig::ConfigItem item;
223 std::vector<int> value;
224 item = WindowSceneConfig::config_["maxAppWindowNumber"];
225 ASSERT_EQ(false, item.IsMap());
226 ASSERT_EQ(true, item.IsInts());
227 value = *item.intsValue_;
228 ASSERT_EQ(true, value.size() >= 1);
229 ASSERT_EQ(0, value[0]);
230
231 xmlStr =
232 "<?xml version='1.0' encoding=\"utf-8\"?>"
233 "<Configs>"
234 "<maxAppWindowNumber>-2</maxAppWindowNumber>"
235 "</Configs>";
236 WindowSceneConfig::config_ = ReadConfig(xmlStr);
237 item = WindowSceneConfig::config_["maxAppWindowNumber"];
238 ASSERT_EQ(false, item.IsMap());
239 ASSERT_EQ(true, item.IsInts());
240 ASSERT_EQ(true, item.intsValue_->size() == 0);
241
242 xmlStr =
243 "<?xml version='1.0' encoding=\"utf-8\"?>"
244 "<Configs>"
245 "<maxAppWindowNumber>4</maxAppWindowNumber>"
246 "</Configs>";
247 WindowSceneConfig::config_ = ReadConfig(xmlStr);
248 item = WindowSceneConfig::config_["maxAppWindowNumber"];
249 ASSERT_EQ(false, item.IsMap());
250 ASSERT_EQ(true, item.IsInts());
251 ASSERT_EQ(1, item.intsValue_->size());
252 value = *item.intsValue_;
253 ASSERT_EQ(4, value[0]);
254
255 xmlStr =
256 "<?xml version='1.0' encoding=\"utf-8\"?>"
257 "<Configs>"
258 "<maxAppWindowNumber>1000</maxAppWindowNumber>"
259 "</Configs>";
260 WindowSceneConfig::config_ = ReadConfig(xmlStr);
261 item = WindowSceneConfig::config_["maxAppWindowNumber"];
262 ASSERT_EQ(false, item.IsMap());
263 ASSERT_EQ(true, item.IsInts());
264 ASSERT_EQ(1, item.intsValue_->size());
265 value = *item.intsValue_;
266 ASSERT_EQ(1000, value[0]);
267 }
268
269 /**
270 * @tc.name: DecorConfig01
271 * @tc.desc: set decor true and false without mode support.
272 * @tc.type: FUNC
273 * @tc.require: issueI68QCO
274 */
275 HWTEST_F(WindowSceneConfigTest, DecorConfig01, TestSize.Level1)
276 {
277 std::string xmlStr =
278 "<?xml version='1.0' encoding=\"utf-8\"?>"
279 "<Configs>"
280 "<decor enable=\"true\"/>"
281 "</Configs>";
282 WindowSceneConfig::config_ = ReadConfig(xmlStr);
283 ASSERT_EQ(true, WindowSceneConfig::config_["decor"].GetProp("enable").boolValue_);
284
285 xmlStr =
286 "<?xml version='1.0' encoding=\"utf-8\"?>"
287 "<Configs>"
288 "<decor enable=\"false\"/>"
289 "</Configs>";
290 WindowSceneConfig::config_ = ReadConfig(xmlStr);
291 ASSERT_EQ(false, WindowSceneConfig::config_["decor"].GetProp("enable").boolValue_);
292 }
293
294 /**
295 * @tc.name: DecorConfig02
296 * @tc.desc: set decor true and mode support fullscreen.
297 * @tc.type: FUNC
298 * @tc.require: issueI68QCO
299 */
300 HWTEST_F(WindowSceneConfigTest, DecorConfig02, TestSize.Level1)
301 {
302 std::string xmlStr =
303 "<?xml version='1.0' encoding=\"utf-8\"?>"
304 "<Configs>"
305 "<decor enable=\"true\">"
306 "<supportedMode>fullscreen</supportedMode>"
307 "</decor>"
308 "</Configs>";
309 WindowSceneConfig::config_ = ReadConfig(xmlStr);
310 WindowSceneConfig::ConfigItem item = WindowSceneConfig::config_["decor"]["supportedMode"];
311 ASSERT_EQ(true, item.IsStrings());
312 ASSERT_EQ(1, item.stringsValue_->size());
313 ASSERT_EQ(false, item.IsMap());
314 ASSERT_EQ(false, item.IsString());
315 std::vector<std::string> supportedModes;
316 supportedModes = *item.stringsValue_;
317 ASSERT_EQ("fullscreen", supportedModes[0]);
318 }
319
320 /**
321 * @tc.name: DecorConfig03
322 * @tc.desc: set decor true and mode support floating.
323 * @tc.type: FUNC
324 * @tc.require: issueI68QCO
325 */
326 HWTEST_F(WindowSceneConfigTest, DecorConfig03, TestSize.Level1)
327 {
328 std::string xmlStr =
329 "<?xml version='1.0' encoding=\"utf-8\"?>"
330 "<Configs>"
331 "<decor enable=\"true\">"
332 "<supportedMode>floating</supportedMode>"
333 "</decor>"
334 "</Configs>";
335 WindowSceneConfig::config_ = ReadConfig(xmlStr);
336 WindowSceneConfig::ConfigItem item = WindowSceneConfig::config_["decor"]["supportedMode"];
337 ASSERT_EQ(false, item.IsMap());
338 ASSERT_EQ(false, item.IsString());
339 ASSERT_EQ(true, item.IsStrings());
340 ASSERT_EQ(1, item.stringsValue_->size());
341 std::vector<std::string> supportedModes;
342 supportedModes = *item.stringsValue_;
343 ASSERT_EQ("floating", supportedModes[0]);
344 }
345
346 /**
347 * @tc.name: DecorConfig04
348 * @tc.desc: set decor true and mode support fullscreen|floating.
349 * @tc.type: FUNC
350 * @tc.require: issueI68QCO
351 */
352 HWTEST_F(WindowSceneConfigTest, DecorConfig04, TestSize.Level1)
353 {
354 std::string xmlStr =
355 "<?xml version='1.0' encoding=\"utf-8\"?>"
356 "<Configs>"
357 "<decor enable=\"true\">"
358 "<supportedMode>fullscreen floating</supportedMode>"
359 "</decor>"
360 "</Configs>";
361 WindowSceneConfig::config_ = ReadConfig(xmlStr);
362 WindowSceneConfig::ConfigItem item = WindowSceneConfig::config_["decor"]["supportedMode"];
363 ASSERT_EQ(false, item.IsMap());
364 ASSERT_EQ(false, item.IsString());
365 ASSERT_EQ(true, item.IsStrings());
366 ASSERT_EQ(2, item.stringsValue_->size());
367 std::vector<std::string> supportedModes;
368 supportedModes = *item.stringsValue_;
369 ASSERT_NE("fullscreen floating", supportedModes[0]);
370 }
371
372 /**
373 * @tc.name: LoadconfigXml
374 * @tc.desc: load config xml
375 * @tc.type: FUNC
376 * @tc.require:
377 */
378 HWTEST_F(WindowSceneConfigTest, LoadConfigXml, TestSize.Level1)
379 {
380 auto result = WindowSceneConfig::LoadConfigXml();
381 ASSERT_EQ(true, result);
382 }
383
384 /**
385 * @tc.name: ReadFloatNumbersConfigInfo
386 * @tc.desc: ReadFloatNumbersConfigInfo test
387 * @tc.type: FUNC
388 */
389 HWTEST_F(WindowSceneConfigTest, ReadFloatNumbersConfigInfo, TestSize.Level1)
390 {
391 xmlNodePtr currNode = xmlNewNode(NULL, BAD_CAST "nodeName");
392 auto result = WindowSceneConfig::ReadFloatNumbersConfigInfo(currNode, false);
393 ASSERT_EQ(0, result.size());
394 }
395
396 /**
397 * @tc.name: ReadStringConfigInfo
398 * @tc.desc: ReadStringConfigInfo test
399 * @tc.type: FUNC
400 */
401 HWTEST_F(WindowSceneConfigTest, ReadStringConfigInfo, TestSize.Level1)
402 {
403 xmlNodePtr currNode = xmlNewNode(NULL, BAD_CAST "nodeName");
404 auto result = WindowSceneConfig::ReadStringConfigInfo(currNode);
405 ASSERT_EQ(0, result.size());
406 }
407
408 /**
409 * @tc.name: MaxMidSceneNumConfig01
410 * @tc.desc: set maxMidSceneNum with 3.
411 * @tc.type: FUNC
412 * @tc.require: issueI68QCO
413 */
414 HWTEST_F(WindowSceneConfigTest, MaxMidSceneNumConfig01, Function | SmallTest | Level2)
415 {
416 std::string xmlStr =
417 "<?xml version='1.0' encoding=\"utf-8\"?>"
418 "<Configs>"
419 "<maxMidSceneNum>3</maxMidSceneNum>"
420 "</Configs>";
421 WindowSceneConfig::config_ = ReadConfig(xmlStr);
422 WindowSceneConfig::ConfigItem item = WindowSceneConfig::config_["maxMidSceneNum"];
423 ASSERT_EQ(false, item.IsMap());
424 ASSERT_EQ(true, item.IsInts());
425 auto value = *item.intsValue_;
426 ASSERT_EQ(true, value.size() >= 1);
427 ASSERT_EQ(3, value[0]);
428 }
429
430 } // namespace
431 } // namespace Rosen
432 } // namespace OHOS
433