1eace7efcSopenharmony_ci/* 2eace7efcSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 3eace7efcSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4eace7efcSopenharmony_ci * you may not use this file except in compliance with the License. 5eace7efcSopenharmony_ci * You may obtain a copy of the License at 6eace7efcSopenharmony_ci * 7eace7efcSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8eace7efcSopenharmony_ci * 9eace7efcSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10eace7efcSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11eace7efcSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12eace7efcSopenharmony_ci * See the License for the specific language governing permissions and 13eace7efcSopenharmony_ci * limitations under the License. 14eace7efcSopenharmony_ci */ 15eace7efcSopenharmony_ci 16eace7efcSopenharmony_ci#include <gtest/gtest.h> 17eace7efcSopenharmony_ci#define private public 18eace7efcSopenharmony_ci#define protected public 19eace7efcSopenharmony_ci#include "ability_manager_service.h" 20eace7efcSopenharmony_ci#include "configuration.h" 21eace7efcSopenharmony_ci#include "configuration_convertor.h" 22eace7efcSopenharmony_ci#include "configuration_utils.h" 23eace7efcSopenharmony_ci#include "hilog_tag_wrapper.h" 24eace7efcSopenharmony_ci#ifdef SUPPORT_GRAPHICS 25eace7efcSopenharmony_ci#include "locale_config.h" 26eace7efcSopenharmony_ci#include "window_scene.h" 27eace7efcSopenharmony_ci#endif 28eace7efcSopenharmony_ci#undef private 29eace7efcSopenharmony_ci#undef protected 30eace7efcSopenharmony_ci 31eace7efcSopenharmony_ciusing namespace testing::ext; 32eace7efcSopenharmony_ciusing namespace OHOS::AppExecFwk; 33eace7efcSopenharmony_cinamespace OHOS { 34eace7efcSopenharmony_cinamespace AAFwk { 35eace7efcSopenharmony_ciclass ConfigurationTest : public testing::Test { 36eace7efcSopenharmony_cipublic: 37eace7efcSopenharmony_ci static void SetUpTestCase(void); 38eace7efcSopenharmony_ci static void TearDownTestCase(void); 39eace7efcSopenharmony_ci void SetUp(); 40eace7efcSopenharmony_ci void TearDown(); 41eace7efcSopenharmony_ci 42eace7efcSopenharmony_ci void InitResourceManager(std::shared_ptr<Global::Resource::ResourceManager> resourceManager); 43eace7efcSopenharmony_ci}; 44eace7efcSopenharmony_ci 45eace7efcSopenharmony_civoid ConfigurationTest::SetUpTestCase(void) 46eace7efcSopenharmony_ci{} 47eace7efcSopenharmony_ci 48eace7efcSopenharmony_civoid ConfigurationTest::TearDownTestCase(void) 49eace7efcSopenharmony_ci{} 50eace7efcSopenharmony_ci 51eace7efcSopenharmony_civoid ConfigurationTest::SetUp(void) 52eace7efcSopenharmony_ci{} 53eace7efcSopenharmony_ci 54eace7efcSopenharmony_civoid ConfigurationTest::TearDown(void) 55eace7efcSopenharmony_ci{} 56eace7efcSopenharmony_ci 57eace7efcSopenharmony_civoid ConfigurationTest::InitResourceManager(std::shared_ptr<Global::Resource::ResourceManager> resourceManager) 58eace7efcSopenharmony_ci{ 59eace7efcSopenharmony_ci std::unique_ptr<Global::Resource::ResConfig> resConfig(Global::Resource::CreateResConfig()); 60eace7efcSopenharmony_ci if (resConfig == nullptr) { 61eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::TEST, "res config is invalid."); 62eace7efcSopenharmony_ci return; 63eace7efcSopenharmony_ci } 64eace7efcSopenharmony_ci 65eace7efcSopenharmony_ci#ifdef SUPPORT_GRAPHICS 66eace7efcSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 67eace7efcSopenharmony_ci icu::Locale locale = icu::Locale::forLanguageTag("zh", status); 68eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::TEST, "language: %{public}s, script: %{public}s, region: %{public}s", 69eace7efcSopenharmony_ci locale.getLanguage(), locale.getScript(), locale.getCountry()); 70eace7efcSopenharmony_ci resConfig->SetLocaleInfo(locale); 71eace7efcSopenharmony_ci#endif 72eace7efcSopenharmony_ci Global::Resource::RState updateRet = resourceManager->UpdateResConfig(*resConfig); 73eace7efcSopenharmony_ci if (updateRet != Global::Resource::RState::SUCCESS) { 74eace7efcSopenharmony_ci TAG_LOGE(AAFwkTag::TEST, "Init locale failed."); 75eace7efcSopenharmony_ci } 76eace7efcSopenharmony_ci} 77eace7efcSopenharmony_ci 78eace7efcSopenharmony_ci/* 79eace7efcSopenharmony_ci * Feature: Configuration 80eace7efcSopenharmony_ci * Function: AddItem 81eace7efcSopenharmony_ci * SubFunction: NA 82eace7efcSopenharmony_ci * FunctionPoints: NA 83eace7efcSopenharmony_ci * EnvConditions:NA 84eace7efcSopenharmony_ci * CaseDescription: Update Configuration 85eace7efcSopenharmony_ci */ 86eace7efcSopenharmony_ciHWTEST_F(ConfigurationTest, AddItem_001, TestSize.Level1) 87eace7efcSopenharmony_ci{ 88eace7efcSopenharmony_ci AppExecFwk::Configuration config; 89eace7efcSopenharmony_ci config.RemoveItem(AAFwk::GlobalConfigurationKey::APP_FONT_SIZE_SCALE); 90eace7efcSopenharmony_ci int displayId = 1001; 91eace7efcSopenharmony_ci std::string val{ "中文" }; 92eace7efcSopenharmony_ci EXPECT_EQ(0, config.GetItemSize()); 93eace7efcSopenharmony_ci config.AddItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, val); 94eace7efcSopenharmony_ci EXPECT_EQ(1, config.GetItemSize()); 95eace7efcSopenharmony_ci 96eace7efcSopenharmony_ci // replace 97eace7efcSopenharmony_ci config.AddItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, val); 98eace7efcSopenharmony_ci EXPECT_EQ(1, config.GetItemSize()); 99eace7efcSopenharmony_ci} 100eace7efcSopenharmony_ci 101eace7efcSopenharmony_ci/* 102eace7efcSopenharmony_ci * Feature: Configuration 103eace7efcSopenharmony_ci * Function: AddItem 104eace7efcSopenharmony_ci * SubFunction: NA 105eace7efcSopenharmony_ci * FunctionPoints: NA 106eace7efcSopenharmony_ci * EnvConditions:NA 107eace7efcSopenharmony_ci * CaseDescription: Update Configuration 108eace7efcSopenharmony_ci */ 109eace7efcSopenharmony_ciHWTEST_F(ConfigurationTest, AddItem_002, TestSize.Level1) 110eace7efcSopenharmony_ci{ 111eace7efcSopenharmony_ci AppExecFwk::Configuration config; 112eace7efcSopenharmony_ci config.RemoveItem(AAFwk::GlobalConfigurationKey::APP_FONT_SIZE_SCALE); 113eace7efcSopenharmony_ci std::string val{ "中文" }; 114eace7efcSopenharmony_ci EXPECT_EQ(0, config.GetItemSize()); 115eace7efcSopenharmony_ci config.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, val); 116eace7efcSopenharmony_ci EXPECT_EQ(1, config.GetItemSize()); 117eace7efcSopenharmony_ci 118eace7efcSopenharmony_ci // replace 119eace7efcSopenharmony_ci config.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, val); 120eace7efcSopenharmony_ci EXPECT_EQ(1, config.GetItemSize()); 121eace7efcSopenharmony_ci} 122eace7efcSopenharmony_ci 123eace7efcSopenharmony_ci/* 124eace7efcSopenharmony_ci * Feature: Configuration 125eace7efcSopenharmony_ci * Function: AddItem 126eace7efcSopenharmony_ci * SubFunction: NA 127eace7efcSopenharmony_ci * FunctionPoints: NA 128eace7efcSopenharmony_ci * EnvConditions:NA 129eace7efcSopenharmony_ci * CaseDescription: Update Configuration 130eace7efcSopenharmony_ci */ 131eace7efcSopenharmony_ciHWTEST_F(ConfigurationTest, AddItem_003, TestSize.Level1) 132eace7efcSopenharmony_ci{ 133eace7efcSopenharmony_ci AppExecFwk::Configuration config; 134eace7efcSopenharmony_ci config.RemoveItem(AAFwk::GlobalConfigurationKey::APP_FONT_SIZE_SCALE); 135eace7efcSopenharmony_ci std::string val{ "中文" }; 136eace7efcSopenharmony_ci std::string key{ "test_key" }; 137eace7efcSopenharmony_ci EXPECT_EQ(0, config.GetItemSize()); 138eace7efcSopenharmony_ci auto ref = config.AddItem(key, val); 139eace7efcSopenharmony_ci EXPECT_FALSE(ref); 140eace7efcSopenharmony_ci} 141eace7efcSopenharmony_ci 142eace7efcSopenharmony_ci/* 143eace7efcSopenharmony_ci * Feature: Configuration 144eace7efcSopenharmony_ci * Function: GetItem 145eace7efcSopenharmony_ci * SubFunction: NA 146eace7efcSopenharmony_ci * FunctionPoints: NA 147eace7efcSopenharmony_ci * EnvConditions:NA 148eace7efcSopenharmony_ci * CaseDescription: Process Configuration Change 149eace7efcSopenharmony_ci */ 150eace7efcSopenharmony_ciHWTEST_F(ConfigurationTest, GetItem_001, TestSize.Level1) 151eace7efcSopenharmony_ci{ 152eace7efcSopenharmony_ci AppExecFwk::Configuration config; 153eace7efcSopenharmony_ci config.RemoveItem(AAFwk::GlobalConfigurationKey::APP_FONT_SIZE_SCALE); 154eace7efcSopenharmony_ci int displayId = 1001; 155eace7efcSopenharmony_ci std::string val{ "中文" }; 156eace7efcSopenharmony_ci config.AddItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, val); 157eace7efcSopenharmony_ci 158eace7efcSopenharmony_ci auto item = config.GetItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); 159eace7efcSopenharmony_ci EXPECT_EQ(item, val); 160eace7efcSopenharmony_ci 161eace7efcSopenharmony_ci // replace 162eace7efcSopenharmony_ci std::string english{ "英文" }; 163eace7efcSopenharmony_ci config.AddItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, english); 164eace7efcSopenharmony_ci item = config.GetItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); 165eace7efcSopenharmony_ci EXPECT_EQ(item, english); 166eace7efcSopenharmony_ci 167eace7efcSopenharmony_ci int displayId2 = 1002; 168eace7efcSopenharmony_ci std::string non{ "" }; 169eace7efcSopenharmony_ci item = config.GetItem(displayId2, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); 170eace7efcSopenharmony_ci EXPECT_EQ(item, non); 171eace7efcSopenharmony_ci} 172eace7efcSopenharmony_ci 173eace7efcSopenharmony_ci/* 174eace7efcSopenharmony_ci * Feature: Configuration 175eace7efcSopenharmony_ci * Function: GetItem 176eace7efcSopenharmony_ci * SubFunction: NA 177eace7efcSopenharmony_ci * FunctionPoints: NA 178eace7efcSopenharmony_ci * EnvConditions:NA 179eace7efcSopenharmony_ci * CaseDescription: Process Configuration Change 180eace7efcSopenharmony_ci */ 181eace7efcSopenharmony_ciHWTEST_F(ConfigurationTest, GetItem_002, TestSize.Level1) 182eace7efcSopenharmony_ci{ 183eace7efcSopenharmony_ci AppExecFwk::Configuration config; 184eace7efcSopenharmony_ci config.RemoveItem(AAFwk::GlobalConfigurationKey::APP_FONT_SIZE_SCALE); 185eace7efcSopenharmony_ci std::string val{ "中文" }; 186eace7efcSopenharmony_ci config.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, val); 187eace7efcSopenharmony_ci 188eace7efcSopenharmony_ci auto item = config.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); 189eace7efcSopenharmony_ci EXPECT_EQ(item, val); 190eace7efcSopenharmony_ci 191eace7efcSopenharmony_ci // replace 192eace7efcSopenharmony_ci std::string english{ "英文" }; 193eace7efcSopenharmony_ci config.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, english); 194eace7efcSopenharmony_ci item = config.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); 195eace7efcSopenharmony_ci EXPECT_EQ(item, english); 196eace7efcSopenharmony_ci 197eace7efcSopenharmony_ci int displayId2 = 1002; 198eace7efcSopenharmony_ci std::string non{ "" }; 199eace7efcSopenharmony_ci item = config.GetItem(displayId2, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); 200eace7efcSopenharmony_ci EXPECT_EQ(item, non); 201eace7efcSopenharmony_ci} 202eace7efcSopenharmony_ci 203eace7efcSopenharmony_ci/* 204eace7efcSopenharmony_ci * Feature: Configuration 205eace7efcSopenharmony_ci * Function: GetItem 206eace7efcSopenharmony_ci * SubFunction: NA 207eace7efcSopenharmony_ci * FunctionPoints: NA 208eace7efcSopenharmony_ci * EnvConditions:NA 209eace7efcSopenharmony_ci * CaseDescription: Process Configuration Change 210eace7efcSopenharmony_ci */ 211eace7efcSopenharmony_ciHWTEST_F(ConfigurationTest, GetItem_003, TestSize.Level1) 212eace7efcSopenharmony_ci{ 213eace7efcSopenharmony_ci AppExecFwk::Configuration config; 214eace7efcSopenharmony_ci config.RemoveItem(AAFwk::GlobalConfigurationKey::APP_FONT_SIZE_SCALE); 215eace7efcSopenharmony_ci std::string non{ "" }; 216eace7efcSopenharmony_ci auto item = config.GetItem("test_kay"); 217eace7efcSopenharmony_ci EXPECT_EQ(item, non); 218eace7efcSopenharmony_ci} 219eace7efcSopenharmony_ci/* 220eace7efcSopenharmony_ci * Feature: Configuration 221eace7efcSopenharmony_ci * Function: RemoveItem 222eace7efcSopenharmony_ci * SubFunction: NA 223eace7efcSopenharmony_ci * FunctionPoints: NA 224eace7efcSopenharmony_ci * EnvConditions:NA 225eace7efcSopenharmony_ci * CaseDescription: Process Configuration Change 226eace7efcSopenharmony_ci */ 227eace7efcSopenharmony_ciHWTEST_F(ConfigurationTest, RemoveItem_001, TestSize.Level1) 228eace7efcSopenharmony_ci{ 229eace7efcSopenharmony_ci AppExecFwk::Configuration config; 230eace7efcSopenharmony_ci config.RemoveItem(AAFwk::GlobalConfigurationKey::APP_FONT_SIZE_SCALE); 231eace7efcSopenharmony_ci int displayId = 1001; 232eace7efcSopenharmony_ci std::string val{ "中文" }; 233eace7efcSopenharmony_ci config.AddItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, val); 234eace7efcSopenharmony_ci 235eace7efcSopenharmony_ci auto item = config.GetItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); 236eace7efcSopenharmony_ci EXPECT_EQ(item, val); 237eace7efcSopenharmony_ci 238eace7efcSopenharmony_ci // remove it 239eace7efcSopenharmony_ci bool canRemove = config.RemoveItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); 240eace7efcSopenharmony_ci EXPECT_TRUE(canRemove); 241eace7efcSopenharmony_ci 242eace7efcSopenharmony_ci std::string non{ "" }; 243eace7efcSopenharmony_ci item = config.GetItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); 244eace7efcSopenharmony_ci EXPECT_EQ(item, non); 245eace7efcSopenharmony_ci 246eace7efcSopenharmony_ci canRemove = config.RemoveItem(displayId, non); 247eace7efcSopenharmony_ci EXPECT_FALSE(canRemove); 248eace7efcSopenharmony_ci 249eace7efcSopenharmony_ci int displayId2 = 1002; 250eace7efcSopenharmony_ci canRemove = config.RemoveItem(displayId2, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); 251eace7efcSopenharmony_ci EXPECT_FALSE(canRemove); 252eace7efcSopenharmony_ci} 253eace7efcSopenharmony_ci 254eace7efcSopenharmony_ci/* 255eace7efcSopenharmony_ci * Feature: Configuration 256eace7efcSopenharmony_ci * Function: RemoveItem 257eace7efcSopenharmony_ci * SubFunction: NA 258eace7efcSopenharmony_ci * FunctionPoints: NA 259eace7efcSopenharmony_ci * EnvConditions:NA 260eace7efcSopenharmony_ci * CaseDescription: Process Configuration Change 261eace7efcSopenharmony_ci */ 262eace7efcSopenharmony_ciHWTEST_F(ConfigurationTest, RemoveItem_002, TestSize.Level1) 263eace7efcSopenharmony_ci{ 264eace7efcSopenharmony_ci AppExecFwk::Configuration config; 265eace7efcSopenharmony_ci config.RemoveItem(AAFwk::GlobalConfigurationKey::APP_FONT_SIZE_SCALE); 266eace7efcSopenharmony_ci std::string val{ "中文" }; 267eace7efcSopenharmony_ci config.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, val); 268eace7efcSopenharmony_ci 269eace7efcSopenharmony_ci auto item = config.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); 270eace7efcSopenharmony_ci EXPECT_EQ(item, val); 271eace7efcSopenharmony_ci 272eace7efcSopenharmony_ci // remove it 273eace7efcSopenharmony_ci bool canRemove = config.RemoveItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); 274eace7efcSopenharmony_ci EXPECT_TRUE(canRemove); 275eace7efcSopenharmony_ci 276eace7efcSopenharmony_ci std::string non{ "" }; 277eace7efcSopenharmony_ci item = config.GetItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); 278eace7efcSopenharmony_ci EXPECT_EQ(item, non); 279eace7efcSopenharmony_ci 280eace7efcSopenharmony_ci canRemove = config.RemoveItem(non); 281eace7efcSopenharmony_ci EXPECT_FALSE(canRemove); 282eace7efcSopenharmony_ci 283eace7efcSopenharmony_ci canRemove = config.RemoveItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); 284eace7efcSopenharmony_ci EXPECT_FALSE(canRemove); 285eace7efcSopenharmony_ci} 286eace7efcSopenharmony_ci 287eace7efcSopenharmony_ci/* 288eace7efcSopenharmony_ci * Feature: Configuration 289eace7efcSopenharmony_ci * Function: GetItemSize 290eace7efcSopenharmony_ci * SubFunction: Process Configuration Change Inner 291eace7efcSopenharmony_ci * FunctionPoints: NA 292eace7efcSopenharmony_ci * EnvConditions:NA 293eace7efcSopenharmony_ci * CaseDescription: Process Configuration Change Inner 294eace7efcSopenharmony_ci */ 295eace7efcSopenharmony_ciHWTEST_F(ConfigurationTest, GetItemSize_001, TestSize.Level1) 296eace7efcSopenharmony_ci{ 297eace7efcSopenharmony_ci AppExecFwk::Configuration config; 298eace7efcSopenharmony_ci config.RemoveItem(AAFwk::GlobalConfigurationKey::APP_FONT_SIZE_SCALE); 299eace7efcSopenharmony_ci int displayId = 1001; 300eace7efcSopenharmony_ci std::string val{ "中文" }; 301eace7efcSopenharmony_ci EXPECT_EQ(0, config.GetItemSize()); 302eace7efcSopenharmony_ci config.AddItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, val); 303eace7efcSopenharmony_ci EXPECT_EQ(1, config.GetItemSize()); 304eace7efcSopenharmony_ci 305eace7efcSopenharmony_ci int displayId2 = 1002; 306eace7efcSopenharmony_ci config.AddItem(displayId2, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, val); 307eace7efcSopenharmony_ci EXPECT_EQ(2, config.GetItemSize()); 308eace7efcSopenharmony_ci} 309eace7efcSopenharmony_ci 310eace7efcSopenharmony_ci/* 311eace7efcSopenharmony_ci * Feature: Configuration 312eace7efcSopenharmony_ci * Function: CompareDifferent 313eace7efcSopenharmony_ci * SubFunction: Process Configuration Change Inner 314eace7efcSopenharmony_ci * FunctionPoints: NA 315eace7efcSopenharmony_ci * EnvConditions:NA 316eace7efcSopenharmony_ci * CaseDescription: Check according to key 317eace7efcSopenharmony_ci */ 318eace7efcSopenharmony_ciHWTEST_F(ConfigurationTest, CompareDifferent_001, TestSize.Level1) 319eace7efcSopenharmony_ci{ 320eace7efcSopenharmony_ci AppExecFwk::Configuration config; 321eace7efcSopenharmony_ci int displayId = 1001; 322eace7efcSopenharmony_ci std::string val{ "中文" }; 323eace7efcSopenharmony_ci config.AddItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, val); 324eace7efcSopenharmony_ci 325eace7efcSopenharmony_ci 326eace7efcSopenharmony_ci AppExecFwk::Configuration config2; 327eace7efcSopenharmony_ci int displayId2 = 1001; 328eace7efcSopenharmony_ci std::string English{ "英文" }; 329eace7efcSopenharmony_ci config2.AddItem(displayId2, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, English); 330eace7efcSopenharmony_ci 331eace7efcSopenharmony_ci std::vector<std::string> changeKeyV; 332eace7efcSopenharmony_ci 333eace7efcSopenharmony_ci config.CompareDifferent(changeKeyV, config2); 334eace7efcSopenharmony_ci int size = changeKeyV.size(); 335eace7efcSopenharmony_ci EXPECT_EQ(size, 1); 336eace7efcSopenharmony_ci} 337eace7efcSopenharmony_ci 338eace7efcSopenharmony_ci/* 339eace7efcSopenharmony_ci * Feature: Configuration 340eace7efcSopenharmony_ci * Function: CompareDifferent 341eace7efcSopenharmony_ci * SubFunction: Process Configuration Change Inner 342eace7efcSopenharmony_ci * FunctionPoints: NA 343eace7efcSopenharmony_ci * EnvConditions:NA 344eace7efcSopenharmony_ci * CaseDescription: Check according to key 345eace7efcSopenharmony_ci */ 346eace7efcSopenharmony_ciHWTEST_F(ConfigurationTest, CompareDifferent_002, TestSize.Level1) 347eace7efcSopenharmony_ci{ 348eace7efcSopenharmony_ci AppExecFwk::Configuration config; 349eace7efcSopenharmony_ci int displayId = 1001; 350eace7efcSopenharmony_ci std::string val{ "中文" }; 351eace7efcSopenharmony_ci config.AddItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, val); 352eace7efcSopenharmony_ci 353eace7efcSopenharmony_ci 354eace7efcSopenharmony_ci AppExecFwk::Configuration config2; 355eace7efcSopenharmony_ci int displayId2 = 1002; 356eace7efcSopenharmony_ci std::string English{ "英文" }; 357eace7efcSopenharmony_ci config2.AddItem(displayId2, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, English); 358eace7efcSopenharmony_ci 359eace7efcSopenharmony_ci std::vector<std::string> changeKeyV; 360eace7efcSopenharmony_ci 361eace7efcSopenharmony_ci config.CompareDifferent(changeKeyV, config2); 362eace7efcSopenharmony_ci int size = changeKeyV.size(); 363eace7efcSopenharmony_ci EXPECT_EQ(size, 1); 364eace7efcSopenharmony_ci} 365eace7efcSopenharmony_ci 366eace7efcSopenharmony_ci/* 367eace7efcSopenharmony_ci * Feature: Configuration 368eace7efcSopenharmony_ci * Function: Merge 369eace7efcSopenharmony_ci * SubFunction: Process Configuration Change Inner 370eace7efcSopenharmony_ci * FunctionPoints: NA 371eace7efcSopenharmony_ci * EnvConditions:NA 372eace7efcSopenharmony_ci * CaseDescription: Check according to key 373eace7efcSopenharmony_ci */ 374eace7efcSopenharmony_ciHWTEST_F(ConfigurationTest, Merge_001, TestSize.Level1) 375eace7efcSopenharmony_ci{ 376eace7efcSopenharmony_ci AppExecFwk::Configuration config; 377eace7efcSopenharmony_ci int displayId = 1001; 378eace7efcSopenharmony_ci std::string val{ "中文" }; 379eace7efcSopenharmony_ci config.AddItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, val); 380eace7efcSopenharmony_ci 381eace7efcSopenharmony_ci 382eace7efcSopenharmony_ci AppExecFwk::Configuration config2; 383eace7efcSopenharmony_ci int displayId2 = 1002; 384eace7efcSopenharmony_ci std::string English{ "英文" }; 385eace7efcSopenharmony_ci config2.AddItem(displayId2, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, English); 386eace7efcSopenharmony_ci 387eace7efcSopenharmony_ci std::vector<std::string> changeKeyV; 388eace7efcSopenharmony_ci 389eace7efcSopenharmony_ci config.CompareDifferent(changeKeyV, config2); 390eace7efcSopenharmony_ci int size = changeKeyV.size(); 391eace7efcSopenharmony_ci EXPECT_EQ(size, 1); 392eace7efcSopenharmony_ci 393eace7efcSopenharmony_ci config.Merge(changeKeyV, config2); 394eace7efcSopenharmony_ci 395eace7efcSopenharmony_ci auto item = config.GetItem(displayId2, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); 396eace7efcSopenharmony_ci EXPECT_EQ(item, English); 397eace7efcSopenharmony_ci} 398eace7efcSopenharmony_ci 399eace7efcSopenharmony_ci/* 400eace7efcSopenharmony_ci * Feature: Configuration 401eace7efcSopenharmony_ci * Function: Merge 402eace7efcSopenharmony_ci * SubFunction: Process Configuration Change Inner 403eace7efcSopenharmony_ci * FunctionPoints: NA 404eace7efcSopenharmony_ci * EnvConditions:NA 405eace7efcSopenharmony_ci * CaseDescription: Check according to key 406eace7efcSopenharmony_ci */ 407eace7efcSopenharmony_ciHWTEST_F(ConfigurationTest, Merge_002, TestSize.Level1) 408eace7efcSopenharmony_ci{ 409eace7efcSopenharmony_ci AppExecFwk::Configuration config; 410eace7efcSopenharmony_ci int displayId = 1001; 411eace7efcSopenharmony_ci std::string chinese{ "Chinese " }; 412eace7efcSopenharmony_ci config.AddItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, chinese); 413eace7efcSopenharmony_ci 414eace7efcSopenharmony_ci 415eace7efcSopenharmony_ci AppExecFwk::Configuration config2; 416eace7efcSopenharmony_ci std::string english{ "English" }; 417eace7efcSopenharmony_ci config2.AddItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, english); 418eace7efcSopenharmony_ci 419eace7efcSopenharmony_ci std::vector<std::string> changeKeyV; 420eace7efcSopenharmony_ci 421eace7efcSopenharmony_ci config.CompareDifferent(changeKeyV, config2); 422eace7efcSopenharmony_ci int size = changeKeyV.size(); 423eace7efcSopenharmony_ci EXPECT_EQ(size, 1); 424eace7efcSopenharmony_ci 425eace7efcSopenharmony_ci config.Merge(changeKeyV, config2); 426eace7efcSopenharmony_ci 427eace7efcSopenharmony_ci auto item = config.GetItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); 428eace7efcSopenharmony_ci EXPECT_EQ(item, english); 429eace7efcSopenharmony_ci} 430eace7efcSopenharmony_ci/* 431eace7efcSopenharmony_ci * Feature: Configuration 432eace7efcSopenharmony_ci * Function: GetName 433eace7efcSopenharmony_ci * SubFunction: Process Configuration Change Inner 434eace7efcSopenharmony_ci * FunctionPoints: NA 435eace7efcSopenharmony_ci * EnvConditions:NA 436eace7efcSopenharmony_ci * CaseDescription: Check according to key 437eace7efcSopenharmony_ci */ 438eace7efcSopenharmony_ciHWTEST_F(ConfigurationTest, GetName_001, TestSize.Level1) 439eace7efcSopenharmony_ci{ 440eace7efcSopenharmony_ci AppExecFwk::Configuration config; 441eace7efcSopenharmony_ci int displayId = 1001; 442eace7efcSopenharmony_ci std::string chinese{ "Chinese " }; 443eace7efcSopenharmony_ci config.AddItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, chinese); 444eace7efcSopenharmony_ci 445eace7efcSopenharmony_ci int displayId2 = 1002; 446eace7efcSopenharmony_ci std::string english{ "English" }; 447eace7efcSopenharmony_ci config.AddItem(displayId2, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, english); 448eace7efcSopenharmony_ci 449eace7efcSopenharmony_ci auto name = config.GetName(); 450eace7efcSopenharmony_ci EXPECT_TRUE(name != ""); 451eace7efcSopenharmony_ci GTEST_LOG_(INFO) << "get name pair [" << name << "]"; 452eace7efcSopenharmony_ci} 453eace7efcSopenharmony_ci 454eace7efcSopenharmony_ci/* 455eace7efcSopenharmony_ci * Feature: Configuration 456eace7efcSopenharmony_ci * Function: Assignment structure 457eace7efcSopenharmony_ci * SubFunction: Process Configuration Change Inner 458eace7efcSopenharmony_ci * FunctionPoints: NA 459eace7efcSopenharmony_ci * EnvConditions:NA 460eace7efcSopenharmony_ci * CaseDescription: Check according to key 461eace7efcSopenharmony_ci */ 462eace7efcSopenharmony_ciHWTEST_F(ConfigurationTest, structure_001, TestSize.Level1) 463eace7efcSopenharmony_ci{ 464eace7efcSopenharmony_ci AppExecFwk::Configuration config; 465eace7efcSopenharmony_ci int displayId = 1001; 466eace7efcSopenharmony_ci std::string chinese{ "Chinese " }; 467eace7efcSopenharmony_ci config.AddItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, chinese); 468eace7efcSopenharmony_ci 469eace7efcSopenharmony_ci AppExecFwk::Configuration configOther(config); 470eace7efcSopenharmony_ci auto item = configOther.GetItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); 471eace7efcSopenharmony_ci EXPECT_TRUE(item == chinese); 472eace7efcSopenharmony_ci 473eace7efcSopenharmony_ci AppExecFwk::Configuration configThird; 474eace7efcSopenharmony_ci configThird = configOther; 475eace7efcSopenharmony_ci 476eace7efcSopenharmony_ci auto item2 = configThird.GetItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); 477eace7efcSopenharmony_ci EXPECT_TRUE(item2 == chinese); 478eace7efcSopenharmony_ci 479eace7efcSopenharmony_ci AppExecFwk::Configuration configFourth = configThird; 480eace7efcSopenharmony_ci auto item3 = configFourth.GetItem(displayId, AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE); 481eace7efcSopenharmony_ci EXPECT_TRUE(item3 == chinese); 482eace7efcSopenharmony_ci} 483eace7efcSopenharmony_ci 484eace7efcSopenharmony_ci/** 485eace7efcSopenharmony_ci * @tc.name: UpdateConfigToResMgr_001 486eace7efcSopenharmony_ci * @tc.desc: Update configuration to resource manager. 487eace7efcSopenharmony_ci * @tc.type: FUNC 488eace7efcSopenharmony_ci * @tc.require: issueI6CWJD 489eace7efcSopenharmony_ci */ 490eace7efcSopenharmony_ciHWTEST_F(ConfigurationTest, UpdateConfigToResMgr_001, TestSize.Level1) 491eace7efcSopenharmony_ci{ 492eace7efcSopenharmony_ci // init configuration, "en", "dark", "false" 493eace7efcSopenharmony_ci AppExecFwk::Configuration configuration; 494eace7efcSopenharmony_ci bool addItemRet; 495eace7efcSopenharmony_ci addItemRet = configuration.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, "en"); 496eace7efcSopenharmony_ci EXPECT_EQ(addItemRet, true); 497eace7efcSopenharmony_ci addItemRet = configuration.AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_COLORMODE, "dark"); 498eace7efcSopenharmony_ci EXPECT_EQ(addItemRet, true); 499eace7efcSopenharmony_ci addItemRet = configuration.AddItem(AAFwk::GlobalConfigurationKey::INPUT_POINTER_DEVICE, "false"); 500eace7efcSopenharmony_ci EXPECT_EQ(addItemRet, true); 501eace7efcSopenharmony_ci 502eace7efcSopenharmony_ci // init resource manager, "zh", "light", "true" 503eace7efcSopenharmony_ci std::shared_ptr<Global::Resource::ResourceManager> resourceManager(Global::Resource::CreateResourceManager()); 504eace7efcSopenharmony_ci ASSERT_NE(resourceManager, nullptr); 505eace7efcSopenharmony_ci std::unique_ptr<Global::Resource::ResConfig> resConfig(Global::Resource::CreateResConfig()); 506eace7efcSopenharmony_ci ASSERT_NE(resConfig, nullptr); 507eace7efcSopenharmony_ci 508eace7efcSopenharmony_ci#ifdef SUPPORT_GRAPHICS 509eace7efcSopenharmony_ci UErrorCode status = U_ZERO_ERROR; 510eace7efcSopenharmony_ci icu::Locale locale = icu::Locale::forLanguageTag("zh", status); 511eace7efcSopenharmony_ci EXPECT_EQ(status, U_ZERO_ERROR); 512eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::TEST, "language: %{public}s, script: %{public}s, region: %{public}s", 513eace7efcSopenharmony_ci locale.getLanguage(), locale.getScript(), locale.getCountry()); 514eace7efcSopenharmony_ci resConfig->SetLocaleInfo(locale); 515eace7efcSopenharmony_ci#endif 516eace7efcSopenharmony_ci resConfig->SetColorMode(ConvertColorMode("light")); 517eace7efcSopenharmony_ci resConfig->SetInputDevice(ConvertHasPointerDevice("true")); 518eace7efcSopenharmony_ci Global::Resource::RState updateRet = resourceManager->UpdateResConfig(*resConfig); 519eace7efcSopenharmony_ci EXPECT_EQ(updateRet, Global::Resource::RState::SUCCESS); 520eace7efcSopenharmony_ci 521eace7efcSopenharmony_ci // update configuration to resource manager 522eace7efcSopenharmony_ci auto configUtils = std::make_shared<AbilityRuntime::ConfigurationUtils>(); 523eace7efcSopenharmony_ci ASSERT_NE(configUtils, nullptr); 524eace7efcSopenharmony_ci configUtils->UpdateGlobalConfig(configuration, nullptr); 525eace7efcSopenharmony_ci configUtils->UpdateGlobalConfig(configuration, resourceManager); 526eace7efcSopenharmony_ci 527eace7efcSopenharmony_ci // check resource manager has updated to "en", "dark", "false" 528eace7efcSopenharmony_ci std::unique_ptr<Global::Resource::ResConfig> updatedResConfig(Global::Resource::CreateResConfig()); 529eace7efcSopenharmony_ci ASSERT_NE(updatedResConfig, nullptr); 530eace7efcSopenharmony_ci resourceManager->GetResConfig(*updatedResConfig); 531eace7efcSopenharmony_ci#ifdef SUPPORT_GRAPHICS 532eace7efcSopenharmony_ci const icu::Locale *localeInfo = updatedResConfig->GetLocaleInfo(); 533eace7efcSopenharmony_ci ASSERT_NE(localeInfo, nullptr); 534eace7efcSopenharmony_ci TAG_LOGI(AAFwkTag::TEST, "language: %{public}s, script: %{public}s, region: %{public}s", 535eace7efcSopenharmony_ci localeInfo->getLanguage(), localeInfo->getScript(), localeInfo->getCountry()); 536eace7efcSopenharmony_ci EXPECT_EQ(strcmp(localeInfo->getLanguage(), "en"), 0); 537eace7efcSopenharmony_ci#endif 538eace7efcSopenharmony_ci EXPECT_EQ(updatedResConfig->GetColorMode(), ConvertColorMode("dark")); 539eace7efcSopenharmony_ci EXPECT_EQ(updatedResConfig->GetInputDevice(), ConvertHasPointerDevice("false")); 540eace7efcSopenharmony_ci} 541eace7efcSopenharmony_ci 542eace7efcSopenharmony_ci/** 543eace7efcSopenharmony_ci * @tc.name: InitDisplayConfig_0100 544eace7efcSopenharmony_ci * @tc.desc: Init display config. 545eace7efcSopenharmony_ci * @tc.type: FUNC 546eace7efcSopenharmony_ci * @tc.require: issueI7HPHB 547eace7efcSopenharmony_ci */ 548eace7efcSopenharmony_ciHWTEST_F(ConfigurationTest, InitDisplayConfig_0100, TestSize.Level1) 549eace7efcSopenharmony_ci{ 550eace7efcSopenharmony_ci auto configUtils = std::make_shared<AbilityRuntime::ConfigurationUtils>(); 551eace7efcSopenharmony_ci ASSERT_NE(configUtils, nullptr); 552eace7efcSopenharmony_ci 553eace7efcSopenharmony_ci int displayId = Rosen::WindowScene::DEFAULT_DISPLAY_ID; 554eace7efcSopenharmony_ci float originDensity; 555eace7efcSopenharmony_ci std::string originDirection; 556eace7efcSopenharmony_ci auto ret = configUtils->GetDisplayConfig(displayId, originDensity, originDirection); 557eace7efcSopenharmony_ci EXPECT_EQ(ret, true); 558eace7efcSopenharmony_ci 559eace7efcSopenharmony_ci configUtils->InitDisplayConfig(displayId, nullptr, nullptr); 560eace7efcSopenharmony_ci 561eace7efcSopenharmony_ci AppExecFwk::Configuration originConfig; 562eace7efcSopenharmony_ci auto configuration = std::make_shared<Configuration>(originConfig); 563eace7efcSopenharmony_ci ASSERT_NE(configuration, nullptr); 564eace7efcSopenharmony_ci configUtils->InitDisplayConfig(displayId, configuration, nullptr); 565eace7efcSopenharmony_ci 566eace7efcSopenharmony_ci std::shared_ptr<Global::Resource::ResourceManager> resourceManager(Global::Resource::CreateResourceManager()); 567eace7efcSopenharmony_ci ASSERT_NE(resourceManager, nullptr); 568eace7efcSopenharmony_ci InitResourceManager(resourceManager); 569eace7efcSopenharmony_ci configUtils->InitDisplayConfig(displayId, configuration, resourceManager); 570eace7efcSopenharmony_ci 571eace7efcSopenharmony_ci // check configurtion 572eace7efcSopenharmony_ci std::string displayIdStr = configuration->GetItem(ConfigurationInner::APPLICATION_DISPLAYID); 573eace7efcSopenharmony_ci EXPECT_EQ(displayIdStr, std::to_string(displayId)); 574eace7efcSopenharmony_ci std::string densityStr = configuration->GetItem(displayId, ConfigurationInner::APPLICATION_DENSITYDPI); 575eace7efcSopenharmony_ci EXPECT_EQ(densityStr, GetDensityStr(originDensity)); 576eace7efcSopenharmony_ci std::string directionStr = configuration->GetItem(displayId, ConfigurationInner::APPLICATION_DIRECTION); 577eace7efcSopenharmony_ci EXPECT_EQ(directionStr, originDirection); 578eace7efcSopenharmony_ci 579eace7efcSopenharmony_ci // check resourcemanager 580eace7efcSopenharmony_ci std::unique_ptr<Global::Resource::ResConfig> resConfig(Global::Resource::CreateResConfig()); 581eace7efcSopenharmony_ci resourceManager->GetResConfig(*resConfig); 582eace7efcSopenharmony_ci EXPECT_EQ(originDensity, resConfig->GetScreenDensity()); 583eace7efcSopenharmony_ci EXPECT_EQ(ConvertDirection(originDirection), resConfig->GetDirection()); 584eace7efcSopenharmony_ci} 585eace7efcSopenharmony_ci 586eace7efcSopenharmony_ci/** 587eace7efcSopenharmony_ci * @tc.name: InitDisplayConfig_0200 588eace7efcSopenharmony_ci * @tc.desc: Init display config. 589eace7efcSopenharmony_ci * @tc.type: FUNC 590eace7efcSopenharmony_ci */ 591eace7efcSopenharmony_ciHWTEST_F(ConfigurationTest, InitDisplayConfig_0200, TestSize.Level1) 592eace7efcSopenharmony_ci{ 593eace7efcSopenharmony_ci auto configUtils = std::make_shared<AbilityRuntime::ConfigurationUtils>(); 594eace7efcSopenharmony_ci ASSERT_NE(configUtils, nullptr); 595eace7efcSopenharmony_ci 596eace7efcSopenharmony_ci int displayId = Rosen::WindowScene::DEFAULT_DISPLAY_ID; 597eace7efcSopenharmony_ci float originDensity; 598eace7efcSopenharmony_ci std::string originDirection; 599eace7efcSopenharmony_ci auto ret = configUtils->GetDisplayConfig(displayId, originDensity, originDirection); 600eace7efcSopenharmony_ci EXPECT_EQ(ret, true); 601eace7efcSopenharmony_ci 602eace7efcSopenharmony_ci configUtils->InitDisplayConfig(nullptr, nullptr, displayId, originDensity, 0); 603eace7efcSopenharmony_ci 604eace7efcSopenharmony_ci AppExecFwk::Configuration originConfig; 605eace7efcSopenharmony_ci auto configuration = std::make_shared<Configuration>(originConfig); 606eace7efcSopenharmony_ci ASSERT_NE(configuration, nullptr); 607eace7efcSopenharmony_ci configUtils->InitDisplayConfig(configuration, nullptr, displayId, originDensity, 0); 608eace7efcSopenharmony_ci 609eace7efcSopenharmony_ci std::shared_ptr<Global::Resource::ResourceManager> resourceManager(Global::Resource::CreateResourceManager()); 610eace7efcSopenharmony_ci ASSERT_NE(resourceManager, nullptr); 611eace7efcSopenharmony_ci InitResourceManager(resourceManager); 612eace7efcSopenharmony_ci configUtils->InitDisplayConfig(configuration, resourceManager, displayId, originDensity, 0); 613eace7efcSopenharmony_ci 614eace7efcSopenharmony_ci // check configurtion 615eace7efcSopenharmony_ci std::string displayIdStr = configuration->GetItem(ConfigurationInner::APPLICATION_DISPLAYID); 616eace7efcSopenharmony_ci EXPECT_EQ(displayIdStr, std::to_string(displayId)); 617eace7efcSopenharmony_ci std::string densityStr = configuration->GetItem(displayId, ConfigurationInner::APPLICATION_DENSITYDPI); 618eace7efcSopenharmony_ci EXPECT_EQ(densityStr, GetDensityStr(originDensity)); 619eace7efcSopenharmony_ci std::string directionStr = configuration->GetItem(displayId, ConfigurationInner::APPLICATION_DIRECTION); 620eace7efcSopenharmony_ci EXPECT_EQ(directionStr, ConfigurationInner::DIRECTION_VERTICAL); 621eace7efcSopenharmony_ci 622eace7efcSopenharmony_ci // check resourcemanager 623eace7efcSopenharmony_ci std::unique_ptr<Global::Resource::ResConfig> resConfig(Global::Resource::CreateResConfig()); 624eace7efcSopenharmony_ci resourceManager->GetResConfig(*resConfig); 625eace7efcSopenharmony_ci EXPECT_EQ(originDensity, resConfig->GetScreenDensity()); 626eace7efcSopenharmony_ci EXPECT_EQ(ConvertDirection(ConfigurationInner::DIRECTION_VERTICAL), resConfig->GetDirection()); 627eace7efcSopenharmony_ci} 628eace7efcSopenharmony_ci 629eace7efcSopenharmony_ci/** 630eace7efcSopenharmony_ci * @tc.name: UpdateDisplayConfig_0100 631eace7efcSopenharmony_ci * @tc.desc: Update display config with changed config. 632eace7efcSopenharmony_ci * @tc.type: FUNC 633eace7efcSopenharmony_ci * @tc.require: issueI7HPHB 634eace7efcSopenharmony_ci */ 635eace7efcSopenharmony_ciHWTEST_F(ConfigurationTest, UpdateDisplayConfig_0100, TestSize.Level1) 636eace7efcSopenharmony_ci{ 637eace7efcSopenharmony_ci auto configUtils = std::make_shared<AbilityRuntime::ConfigurationUtils>(); 638eace7efcSopenharmony_ci ASSERT_NE(configUtils, nullptr); 639eace7efcSopenharmony_ci 640eace7efcSopenharmony_ci int displayId = Rosen::WindowScene::DEFAULT_DISPLAY_ID; 641eace7efcSopenharmony_ci float originDensity; 642eace7efcSopenharmony_ci std::string originDirection; 643eace7efcSopenharmony_ci auto ret = configUtils->GetDisplayConfig(displayId, originDensity, originDirection); 644eace7efcSopenharmony_ci EXPECT_EQ(ret, true); 645eace7efcSopenharmony_ci 646eace7efcSopenharmony_ci bool configChanged; 647eace7efcSopenharmony_ci configUtils->UpdateDisplayConfig(displayId, nullptr, nullptr, configChanged); 648eace7efcSopenharmony_ci 649eace7efcSopenharmony_ci AppExecFwk::Configuration originConfig; 650eace7efcSopenharmony_ci auto configuration = std::make_shared<Configuration>(originConfig); 651eace7efcSopenharmony_ci ASSERT_NE(configuration, nullptr); 652eace7efcSopenharmony_ci configUtils->UpdateDisplayConfig(displayId, configuration, nullptr, configChanged); 653eace7efcSopenharmony_ci 654eace7efcSopenharmony_ci std::shared_ptr<Global::Resource::ResourceManager> resourceManager(Global::Resource::CreateResourceManager()); 655eace7efcSopenharmony_ci ASSERT_NE(resourceManager, nullptr); 656eace7efcSopenharmony_ci InitResourceManager(resourceManager); 657eace7efcSopenharmony_ci configUtils->UpdateDisplayConfig(displayId, configuration, resourceManager, configChanged); 658eace7efcSopenharmony_ci EXPECT_EQ(configChanged, true); 659eace7efcSopenharmony_ci 660eace7efcSopenharmony_ci // check configurtion 661eace7efcSopenharmony_ci std::string densityStr = configuration->GetItem(displayId, ConfigurationInner::APPLICATION_DENSITYDPI); 662eace7efcSopenharmony_ci EXPECT_EQ(densityStr, GetDensityStr(originDensity)); 663eace7efcSopenharmony_ci std::string directionStr = configuration->GetItem(displayId, ConfigurationInner::APPLICATION_DIRECTION); 664eace7efcSopenharmony_ci EXPECT_EQ(directionStr, originDirection); 665eace7efcSopenharmony_ci 666eace7efcSopenharmony_ci // check resourcemanager 667eace7efcSopenharmony_ci std::unique_ptr<Global::Resource::ResConfig> resConfig(Global::Resource::CreateResConfig()); 668eace7efcSopenharmony_ci resourceManager->GetResConfig(*resConfig); 669eace7efcSopenharmony_ci EXPECT_EQ(originDensity, resConfig->GetScreenDensity()); 670eace7efcSopenharmony_ci EXPECT_EQ(ConvertDirection(originDirection), resConfig->GetDirection()); 671eace7efcSopenharmony_ci} 672eace7efcSopenharmony_ci 673eace7efcSopenharmony_ci/** 674eace7efcSopenharmony_ci * @tc.name: UpdateDisplayConfig_0200 675eace7efcSopenharmony_ci * @tc.desc: Update display config with unchanged config. 676eace7efcSopenharmony_ci * @tc.type: FUNC 677eace7efcSopenharmony_ci * @tc.require: issueI7HPHB 678eace7efcSopenharmony_ci */ 679eace7efcSopenharmony_ciHWTEST_F(ConfigurationTest, UpdateDisplayConfig_0200, TestSize.Level1) 680eace7efcSopenharmony_ci{ 681eace7efcSopenharmony_ci auto configUtils = std::make_shared<AbilityRuntime::ConfigurationUtils>(); 682eace7efcSopenharmony_ci ASSERT_NE(configUtils, nullptr); 683eace7efcSopenharmony_ci 684eace7efcSopenharmony_ci int displayId = Rosen::WindowScene::DEFAULT_DISPLAY_ID; 685eace7efcSopenharmony_ci float originDensity; 686eace7efcSopenharmony_ci std::string originDirection; 687eace7efcSopenharmony_ci auto ret = configUtils->GetDisplayConfig(displayId, originDensity, originDirection); 688eace7efcSopenharmony_ci EXPECT_EQ(ret, true); 689eace7efcSopenharmony_ci 690eace7efcSopenharmony_ci bool configChanged; 691eace7efcSopenharmony_ci configUtils->UpdateDisplayConfig(displayId, nullptr, nullptr, configChanged); 692eace7efcSopenharmony_ci 693eace7efcSopenharmony_ci AppExecFwk::Configuration originConfig; 694eace7efcSopenharmony_ci auto configuration = std::make_shared<Configuration>(originConfig); 695eace7efcSopenharmony_ci ASSERT_NE(configuration, nullptr); 696eace7efcSopenharmony_ci configUtils->UpdateDisplayConfig(displayId, configuration, nullptr, configChanged); 697eace7efcSopenharmony_ci 698eace7efcSopenharmony_ci // Add configuration. 699eace7efcSopenharmony_ci configuration->AddItem(displayId, ConfigurationInner::APPLICATION_DENSITYDPI, GetDensityStr(originDensity)); 700eace7efcSopenharmony_ci configuration->AddItem(displayId, ConfigurationInner::APPLICATION_DIRECTION, originDirection); 701eace7efcSopenharmony_ci configuration->AddItem(ConfigurationInner::APPLICATION_DISPLAYID, std::to_string(displayId)); 702eace7efcSopenharmony_ci 703eace7efcSopenharmony_ci std::shared_ptr<Global::Resource::ResourceManager> resourceManager(Global::Resource::CreateResourceManager()); 704eace7efcSopenharmony_ci ASSERT_NE(resourceManager, nullptr); 705eace7efcSopenharmony_ci configUtils->UpdateDisplayConfig(displayId, configuration, resourceManager, configChanged); 706eace7efcSopenharmony_ci EXPECT_EQ(configChanged, false); 707eace7efcSopenharmony_ci} 708eace7efcSopenharmony_ci 709eace7efcSopenharmony_ci/** 710eace7efcSopenharmony_ci * @tc.name: UpdateDisplayConfig_0300 711eace7efcSopenharmony_ci * @tc.desc: Update display config with changed config. 712eace7efcSopenharmony_ci * @tc.type: FUNC 713eace7efcSopenharmony_ci */ 714eace7efcSopenharmony_ciHWTEST_F(ConfigurationTest, UpdateDisplayConfig_0300, TestSize.Level1) 715eace7efcSopenharmony_ci{ 716eace7efcSopenharmony_ci auto configUtils = std::make_shared<AbilityRuntime::ConfigurationUtils>(); 717eace7efcSopenharmony_ci ASSERT_NE(configUtils, nullptr); 718eace7efcSopenharmony_ci 719eace7efcSopenharmony_ci int displayId = Rosen::WindowScene::DEFAULT_DISPLAY_ID; 720eace7efcSopenharmony_ci float originDensity; 721eace7efcSopenharmony_ci std::string originDirection; 722eace7efcSopenharmony_ci auto ret = configUtils->GetDisplayConfig(displayId, originDensity, originDirection); 723eace7efcSopenharmony_ci EXPECT_EQ(ret, true); 724eace7efcSopenharmony_ci 725eace7efcSopenharmony_ci bool configChanged = false; 726eace7efcSopenharmony_ci configChanged = configUtils->UpdateDisplayConfig( 727eace7efcSopenharmony_ci nullptr, nullptr, displayId, originDensity, Rosen::DisplayOrientation::PORTRAIT); 728eace7efcSopenharmony_ci EXPECT_EQ(configChanged, false); 729eace7efcSopenharmony_ci 730eace7efcSopenharmony_ci AppExecFwk::Configuration originConfig; 731eace7efcSopenharmony_ci auto configuration = std::make_shared<Configuration>(originConfig); 732eace7efcSopenharmony_ci ASSERT_NE(configuration, nullptr); 733eace7efcSopenharmony_ci configChanged = configUtils->UpdateDisplayConfig( 734eace7efcSopenharmony_ci configuration, nullptr, displayId, originDensity, Rosen::DisplayOrientation::PORTRAIT); 735eace7efcSopenharmony_ci EXPECT_EQ(configChanged, false); 736eace7efcSopenharmony_ci 737eace7efcSopenharmony_ci std::shared_ptr<Global::Resource::ResourceManager> resourceManager(Global::Resource::CreateResourceManager()); 738eace7efcSopenharmony_ci ASSERT_NE(resourceManager, nullptr); 739eace7efcSopenharmony_ci InitResourceManager(resourceManager); 740eace7efcSopenharmony_ci configChanged = configUtils->UpdateDisplayConfig( 741eace7efcSopenharmony_ci configuration, resourceManager, displayId, originDensity, Rosen::DisplayOrientation::PORTRAIT); 742eace7efcSopenharmony_ci EXPECT_EQ(configChanged, true); 743eace7efcSopenharmony_ci 744eace7efcSopenharmony_ci // check configurtion 745eace7efcSopenharmony_ci std::string densityStr = configuration->GetItem(displayId, ConfigurationInner::APPLICATION_DENSITYDPI); 746eace7efcSopenharmony_ci EXPECT_EQ(densityStr, GetDensityStr(originDensity)); 747eace7efcSopenharmony_ci std::string directionStr = configuration->GetItem(displayId, ConfigurationInner::APPLICATION_DIRECTION); 748eace7efcSopenharmony_ci EXPECT_EQ(directionStr, ConfigurationInner::DIRECTION_VERTICAL); 749eace7efcSopenharmony_ci 750eace7efcSopenharmony_ci // check resourcemanager 751eace7efcSopenharmony_ci std::unique_ptr<Global::Resource::ResConfig> resConfig(Global::Resource::CreateResConfig()); 752eace7efcSopenharmony_ci resourceManager->GetResConfig(*resConfig); 753eace7efcSopenharmony_ci EXPECT_EQ(originDensity, resConfig->GetScreenDensity()); 754eace7efcSopenharmony_ci EXPECT_EQ(ConvertDirection(ConfigurationInner::DIRECTION_VERTICAL), resConfig->GetDirection()); 755eace7efcSopenharmony_ci} 756eace7efcSopenharmony_ci 757eace7efcSopenharmony_ci/** 758eace7efcSopenharmony_ci * @tc.name: UpdateDisplayConfig_0400 759eace7efcSopenharmony_ci * @tc.desc: Update display config with unchanged config. 760eace7efcSopenharmony_ci * @tc.type: FUNC 761eace7efcSopenharmony_ci */ 762eace7efcSopenharmony_ciHWTEST_F(ConfigurationTest, UpdateDisplayConfig_0400, TestSize.Level1) 763eace7efcSopenharmony_ci{ 764eace7efcSopenharmony_ci auto configUtils = std::make_shared<AbilityRuntime::ConfigurationUtils>(); 765eace7efcSopenharmony_ci ASSERT_NE(configUtils, nullptr); 766eace7efcSopenharmony_ci 767eace7efcSopenharmony_ci int displayId = Rosen::WindowScene::DEFAULT_DISPLAY_ID; 768eace7efcSopenharmony_ci float originDensity; 769eace7efcSopenharmony_ci std::string originDirection; 770eace7efcSopenharmony_ci auto ret = configUtils->GetDisplayConfig(displayId, originDensity, originDirection); 771eace7efcSopenharmony_ci EXPECT_EQ(ret, true); 772eace7efcSopenharmony_ci 773eace7efcSopenharmony_ci AppExecFwk::Configuration originConfig; 774eace7efcSopenharmony_ci auto configuration = std::make_shared<Configuration>(originConfig); 775eace7efcSopenharmony_ci ASSERT_NE(configuration, nullptr); 776eace7efcSopenharmony_ci 777eace7efcSopenharmony_ci // Add configuration. 778eace7efcSopenharmony_ci configuration->AddItem(displayId, ConfigurationInner::APPLICATION_DENSITYDPI, GetDensityStr(originDensity)); 779eace7efcSopenharmony_ci configuration->AddItem( 780eace7efcSopenharmony_ci displayId, ConfigurationInner::APPLICATION_DIRECTION, ConfigurationInner::DIRECTION_VERTICAL); 781eace7efcSopenharmony_ci configuration->AddItem(ConfigurationInner::APPLICATION_DISPLAYID, std::to_string(displayId)); 782eace7efcSopenharmony_ci 783eace7efcSopenharmony_ci std::shared_ptr<Global::Resource::ResourceManager> resourceManager(Global::Resource::CreateResourceManager()); 784eace7efcSopenharmony_ci ASSERT_NE(resourceManager, nullptr); 785eace7efcSopenharmony_ci bool configChanged = configUtils->UpdateDisplayConfig( 786eace7efcSopenharmony_ci configuration, resourceManager, displayId, originDensity, Rosen::DisplayOrientation::PORTRAIT); 787eace7efcSopenharmony_ci EXPECT_EQ(configChanged, false); 788eace7efcSopenharmony_ci} 789eace7efcSopenharmony_ci} // namespace AAFwk 790eace7efcSopenharmony_ci} // namespace OHOS 791