/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include "window_scene_config.h" #include "window_manager_hilog.h" using namespace testing; using namespace testing::ext; namespace OHOS { namespace Rosen { using ConfigItem = WindowSceneConfig::ConfigItem; const std::string XML_STR = R"( 100 50 50 50 0.1 0.9 0.5 0.33 0.67 1 350 0.7 0.7 0 0 1 0 0 0 0 500 0.2 0.0 0.2 1.0 300 0.2 0.0 0.2 1.0 off off off 0 #000000 0 0 0 0 #000000 0 0 0 )"; class WindowSceneConfigTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); void SetUp() override; void TearDown() override; ConfigItem ReadConfig(const std::string& xmlStr); }; void WindowSceneConfigTest::SetUpTestCase() { } void WindowSceneConfigTest::TearDownTestCase() { } void WindowSceneConfigTest::SetUp() { } void WindowSceneConfigTest::TearDown() { } ConfigItem WindowSceneConfigTest::ReadConfig(const std::string& xmlStr) { ConfigItem cfgItem; xmlDocPtr docPtr = xmlParseMemory(xmlStr.c_str(), xmlStr.length() + 1); if (docPtr == nullptr) { return cfgItem; } xmlNodePtr rootPtr = xmlDocGetRootElement(docPtr); if (rootPtr == nullptr || rootPtr->name == nullptr || xmlStrcmp(rootPtr->name, reinterpret_cast("Configs"))) { xmlFreeDoc(docPtr); return cfgItem; } std::map configMap; cfgItem.SetValue(configMap); WindowSceneConfig::ReadConfig(rootPtr, *cfgItem.mapValue_); xmlFreeDoc(docPtr); return cfgItem; } namespace { /** * @tc.name: AnimationConfig * @tc.desc: animation config test * @tc.type: FUNC * @tc.require issueI5N26H */ HWTEST_F(WindowSceneConfigTest, AnimationConfig, Function | SmallTest | Level2) { WindowSceneConfig::config_ = ReadConfig(XML_STR); ConfigItem item = WindowSceneConfig::config_["windowAnimation"]; ASSERT_EQ(true, item.IsMap()); item = WindowSceneConfig::config_["windowAnimation"]["timing"]["duration"]; ASSERT_EQ(true, item.IsInts()); auto value = *item.intsValue_; ASSERT_EQ(true, value.size() == 1); ASSERT_EQ(350, value[0]); item = WindowSceneConfig::config_["windowAnimation"]["timing"]["curve"].GetProp("name"); ASSERT_EQ(true, item.IsString()); ASSERT_EQ("easeOut", item.stringValue_); item = WindowSceneConfig::config_["windowAnimation"]["scale"]; ASSERT_EQ(true, item.IsFloats()); ASSERT_EQ(true, item.floatsValue_->size() == 2); item = WindowSceneConfig::config_["windowAnimation"]["rotation"]; ASSERT_EQ(true, item.IsFloats()); ASSERT_EQ(true, item.floatsValue_->size() == 4); item = WindowSceneConfig::config_["windowAnimation"]["translate"]; ASSERT_EQ(true, item.IsFloats()); ASSERT_EQ(true, item.floatsValue_->size() == 2); item = WindowSceneConfig::config_["windowAnimation"]["opacity"]; ASSERT_EQ(true, item.IsFloats()); ASSERT_EQ(true, item.floatsValue_->size() == 1); } /** * @tc.name: maxAppWindowNumber * @tc.desc: maxAppWindowNumber test * @tc.type: FUNC */ HWTEST_F(WindowSceneConfigTest, MaxAppWindowNumber, Function | SmallTest | Level2) { std::string xmlStr = "" "" "0" ""; WindowSceneConfig::config_ = ReadConfig(xmlStr); WindowSceneConfig::ConfigItem item; std::vector value; item = WindowSceneConfig::config_["maxAppWindowNumber"]; ASSERT_EQ(false, item.IsMap()); ASSERT_EQ(true, item.IsInts()); value = *item.intsValue_; ASSERT_EQ(true, value.size() >= 1); ASSERT_EQ(0, value[0]); xmlStr = "" "" "-2" ""; WindowSceneConfig::config_ = ReadConfig(xmlStr); item = WindowSceneConfig::config_["maxAppWindowNumber"]; ASSERT_EQ(false, item.IsMap()); ASSERT_EQ(true, item.IsInts()); ASSERT_EQ(true, item.intsValue_->size() == 0); xmlStr = "" "" "4" ""; WindowSceneConfig::config_ = ReadConfig(xmlStr); item = WindowSceneConfig::config_["maxAppWindowNumber"]; ASSERT_EQ(false, item.IsMap()); ASSERT_EQ(true, item.IsInts()); ASSERT_EQ(1, item.intsValue_->size()); value = *item.intsValue_; ASSERT_EQ(4, value[0]); xmlStr = "" "" "1000" ""; WindowSceneConfig::config_ = ReadConfig(xmlStr); item = WindowSceneConfig::config_["maxAppWindowNumber"]; ASSERT_EQ(false, item.IsMap()); ASSERT_EQ(true, item.IsInts()); ASSERT_EQ(1, item.intsValue_->size()); value = *item.intsValue_; ASSERT_EQ(1000, value[0]); } /** * @tc.name: DecorConfig01 * @tc.desc: set decor true and false without mode support. * @tc.type: FUNC * @tc.require: issueI68QCO */ HWTEST_F(WindowSceneConfigTest, DecorConfig01, Function | SmallTest | Level2) { std::string xmlStr = "" "" "" ""; WindowSceneConfig::config_ = ReadConfig(xmlStr); ASSERT_EQ(true, WindowSceneConfig::config_["decor"].GetProp("enable").boolValue_); xmlStr = "" "" "" ""; WindowSceneConfig::config_ = ReadConfig(xmlStr); ASSERT_EQ(false, WindowSceneConfig::config_["decor"].GetProp("enable").boolValue_); } /** * @tc.name: DecorConfig02 * @tc.desc: set decor true and mode support fullscreen. * @tc.type: FUNC * @tc.require: issueI68QCO */ HWTEST_F(WindowSceneConfigTest, DecorConfig02, Function | SmallTest | Level2) { std::string xmlStr = "" "" "" "fullscreen" "" ""; WindowSceneConfig::config_ = ReadConfig(xmlStr); WindowSceneConfig::ConfigItem item = WindowSceneConfig::config_["decor"]["supportedMode"]; ASSERT_EQ(true, item.IsStrings()); ASSERT_EQ(1, item.stringsValue_->size()); ASSERT_EQ(false, item.IsMap()); ASSERT_EQ(false, item.IsString()); std::vector supportedModes; supportedModes = *item.stringsValue_; ASSERT_EQ("fullscreen", supportedModes[0]); } /** * @tc.name: DecorConfig03 * @tc.desc: set decor true and mode support floating. * @tc.type: FUNC * @tc.require: issueI68QCO */ HWTEST_F(WindowSceneConfigTest, DecorConfig03, Function | SmallTest | Level2) { std::string xmlStr = "" "" "" "floating" "" ""; WindowSceneConfig::config_ = ReadConfig(xmlStr); WindowSceneConfig::ConfigItem item = WindowSceneConfig::config_["decor"]["supportedMode"]; ASSERT_EQ(false, item.IsMap()); ASSERT_EQ(false, item.IsString()); ASSERT_EQ(true, item.IsStrings()); ASSERT_EQ(1, item.stringsValue_->size()); std::vector supportedModes; supportedModes = *item.stringsValue_; ASSERT_EQ("floating", supportedModes[0]); } /** * @tc.name: DecorConfig04 * @tc.desc: set decor true and mode support fullscreen|floating. * @tc.type: FUNC * @tc.require: issueI68QCO */ HWTEST_F(WindowSceneConfigTest, DecorConfig04, Function | SmallTest | Level2) { std::string xmlStr = "" "" "" "fullscreen floating" "" ""; WindowSceneConfig::config_ = ReadConfig(xmlStr); WindowSceneConfig::ConfigItem item = WindowSceneConfig::config_["decor"]["supportedMode"]; ASSERT_EQ(false, item.IsMap()); ASSERT_EQ(false, item.IsString()); ASSERT_EQ(true, item.IsStrings()); ASSERT_EQ(2, item.stringsValue_->size()); std::vector supportedModes; supportedModes = *item.stringsValue_; ASSERT_NE("fullscreen floating", supportedModes[0]); } /** * @tc.name: LoadconfigXml * @tc.desc: load config xml * @tc.type: FUNC * @tc.require: */ HWTEST_F(WindowSceneConfigTest, LoadConfigXml, Function | SmallTest | Level2) { auto result = WindowSceneConfig::LoadConfigXml(); ASSERT_EQ(true, result); } /** * @tc.name: ReadFloatNumbersConfigInfo * @tc.desc: ReadFloatNumbersConfigInfo test * @tc.type: FUNC */ HWTEST_F(WindowSceneConfigTest, ReadFloatNumbersConfigInfo, Function | SmallTest | Level2) { xmlNodePtr currNode = xmlNewNode(NULL, BAD_CAST"nodeName"); auto result = WindowSceneConfig::ReadFloatNumbersConfigInfo(currNode, false); ASSERT_EQ(0, result.size()); } /** * @tc.name: ReadStringConfigInfo * @tc.desc: ReadStringConfigInfo test * @tc.type: FUNC */ HWTEST_F(WindowSceneConfigTest, ReadStringConfigInfo, Function | SmallTest | Level2) { xmlNodePtr currNode = xmlNewNode(NULL, BAD_CAST"nodeName"); auto result = WindowSceneConfig::ReadStringConfigInfo(currNode); ASSERT_EQ(0, result.size()); } /** * @tc.name: MaxMidSceneNumConfig01 * @tc.desc: set maxMidSceneNum with 3. * @tc.type: FUNC * @tc.require: issueI68QCO */ HWTEST_F(WindowSceneConfigTest, MaxMidSceneNumConfig01, Function | SmallTest | Level2) { std::string xmlStr = "" "" "3" ""; WindowSceneConfig::config_ = ReadConfig(xmlStr); WindowSceneConfig::ConfigItem item = WindowSceneConfig::config_["maxMidSceneNum"]; ASSERT_EQ(false, item.IsMap()); ASSERT_EQ(true, item.IsInts()); auto value = *item.intsValue_; ASSERT_EQ(true, value.size() >= 1); ASSERT_EQ(3, value[0]); } } // namespace } // namespace Rosen } // namespace OHOS