diff --git a/frameworks/resmgr/include/resource_manager_impl.h b/frameworks/resmgr/include/resource_manager_impl.h index 6b3b07dc1764d4b138187e99e645a2f1f1c4c385..5407f07aa6d640009cad9f681957a2abb8dada16 100644 --- a/frameworks/resmgr/include/resource_manager_impl.h +++ b/frameworks/resmgr/include/resource_manager_impl.h @@ -733,6 +733,38 @@ public: */ virtual RState GetStringFormatByName(std::string &outValue, const char *name, va_list args); + /** + * Get the THEME resource by resource name + * @param name the resource name + * @param outValue the resource write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetThemeDataByName(const char *name, std::map &outValue); + + /** + * Get the THEME resource by resource id + * @param id the resource id + * @param outValue the resource write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetThemeDataById(uint32_t id, std::map &outValue); + + /** + * Get the PATTERN resource by resource id + * @param id the resource id + * @param outValue the resource write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetPatternDataById(uint32_t id, std::map &outValue); + + /** + * Get the PATTERN resource by resource name + * @param name the resource name + * @param outValue the resource write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ + virtual RState GetPatternDataByName(const char *name, std::map &outValue); + private: RState GetString(const std::shared_ptr idItem, std::string &outValue); @@ -797,6 +829,17 @@ private: RState UpdateFakeLocaleFlag(ResConfig &resConfig); + RState GetThemeData(const std::shared_ptr idItem, std::map &outValue); + + RState ResolveResData(const std::shared_ptr idItem, std::map &outValue); + + RState ResolveDataReference(const std::string key, const std::string value, + std::map &outValue); + + RState GetPatternData(const std::shared_ptr idItem, std::map &outValue); + + RState ProcessItem(std::shared_ptr idItem, std::map &outValue); + std::shared_ptr GetHapManager(); std::shared_ptr hapManager_; diff --git a/frameworks/resmgr/src/resource_manager_impl.cpp b/frameworks/resmgr/src/resource_manager_impl.cpp index 0e7efbce303e467a1574b73928f9e98b5ef80f51..237598aa309f6b1ca5400fe98d64f9060b9c35e7 100644 --- a/frameworks/resmgr/src/resource_manager_impl.cpp +++ b/frameworks/resmgr/src/resource_manager_impl.cpp @@ -288,6 +288,20 @@ RState ResourceManagerImpl::GetPatternById(uint32_t id, std::map &outValue) +{ + const std::shared_ptr idItem = hapManager_->FindResourceById(id, isOverrideResMgr_); + if (idItem == nullptr) { + RESMGR_HILOGE(RESMGR_TAG, "GetPatternDataById error id = %{public}d", id); + return ERROR_CODE_RES_ID_NOT_FOUND; + } + RState state = GetPatternData(idItem, outValue); + if (state != SUCCESS && state != ERROR_CODE_RES_REF_TOO_MUCH) { + return ERROR_CODE_RES_NOT_FOUND_BY_ID; + } + return state; +} + RState ResourceManagerImpl::GetPatternByName(const char *name, std::map &outValue) { const std::shared_ptr idItem = hapManager_->FindResourceByName(name, ResType::PATTERN, isOverrideResMgr_); @@ -302,6 +316,20 @@ RState ResourceManagerImpl::GetPatternByName(const char *name, std::map &outValue) +{ + const std::shared_ptr idItem = hapManager_->FindResourceByName(name, ResType::PATTERN, isOverrideResMgr_); + if (idItem == nullptr) { + RESMGR_HILOGE(RESMGR_TAG, "GetPatternDataByName error name = %{public}s", name); + return ERROR_CODE_RES_NAME_NOT_FOUND; + } + RState state = GetPatternData(idItem, outValue); + if (state != SUCCESS && state != ERROR_CODE_RES_REF_TOO_MUCH) { + return ERROR_CODE_RES_NOT_FOUND_BY_NAME; + } + return state; +} + RState ResourceManagerImpl::GetPattern(const std::shared_ptr idItem, std::map &outValue) { @@ -314,6 +342,18 @@ RState ResourceManagerImpl::GetPattern(const std::shared_ptr idItem, std return ResolveParentReference(idItem, outValue); } +RState ResourceManagerImpl::GetPatternData(const std::shared_ptr idItem, + std::map &outValue) +{ + //type invalid + if (idItem->resType_ != ResType::PATTERN) { + RESMGR_HILOGE(RESMGR_TAG, + "actual resType = %{public}d, expect resType = %{public}d", idItem->resType_, ResType::PATTERN); + return NOT_FOUND; + } + return ResolveResData(idItem, outValue); +} + RState ResourceManagerImpl::GetPluralStringById(uint32_t id, int quantity, std::string &outValue) { const std::shared_ptr vuqd = hapManager_->FindQualifierValueById(id, @@ -467,6 +507,48 @@ RState ResourceManagerImpl::ResolveReference(const std::string value, std::strin return SUCCESS; } +RState ResourceManagerImpl::ResolveDataReference(const std::string key, const std::string value, + std::map &outValue) +{ + uint32_t id; + ResType resType; + bool isRef = true; + int count = 0; + std::string refStr(value); + while (isRef) { + isRef = IdItem::IsRef(refStr, resType, id); + if (!isRef) { + outValue[key] = { .resType = ResType::STRING, .value = refStr }; + return SUCCESS; + } + + if (IdItem::IsArrayOfType(resType)) { + // can't be array + outValue[key] = { .resType = resType, .value = std::to_string(id) }; + return SUCCESS; + } + const std::shared_ptr idItem = hapManager_->FindResourceById(id, isOverrideResMgr_); + if (idItem == nullptr) { + RESMGR_HILOGE(RESMGR_TAG, "ref %s id not found", refStr.c_str()); + return ERROR; + } + // unless compile bug + if (resType != idItem->resType_) { + RESMGR_HILOGE(RESMGR_TAG, + "impossible. ref %s type mismatch, found type: %d", refStr.c_str(), idItem->resType_); + return ERROR; + } + + refStr = idItem->value_; + + if (++count > MAX_DEPTH_REF_SEARCH) { + RESMGR_HILOGE(RESMGR_TAG, "ref %s has re-ref too much", value.c_str()); + return ERROR_CODE_RES_REF_TOO_MUCH; + } + } + return SUCCESS; +} + RState ResourceManagerImpl::GetThemeValues(const std::string &value, std::string &outValue) { ResConfigImpl resConfig; @@ -542,6 +624,81 @@ RState ResourceManagerImpl::ResolveParentReference(const std::shared_ptr return SUCCESS; } +RState ResourceManagerImpl::ProcessItem(std::shared_ptr idItem, + std::map &outValue) +{ + size_t startIdx = idItem->HaveParent() ? 1 : 0; + // add currItem values into map when key is absent + // this make sure child covers parent + size_t loop = idItem->values_.size() / 2; + for (size_t i = 0; i < loop; ++i) { + std::string key(idItem->values_[startIdx + i * 2]); // 2 means key appear in pairs + std::string value(idItem->values_[startIdx + i * 2 + 1]); // 2 means value appear in pairs + auto iter = outValue.find(key); + if (iter != outValue.end()) { + continue; + } + std::string resolvedValue; + if (GetThemeValues(value, resolvedValue) == SUCCESS) { + outValue[key] = { .resType = ResType::STRING, .value = resolvedValue }; + continue; + } + RState rrRet = ResolveDataReference(key, value, outValue); + if (rrRet != SUCCESS) { + RESMGR_HILOGD(RESMGR_TAG, "ResolveReference failed, value:%{public}s", value.c_str()); + return ERROR; + } + } + return SUCCESS; +} + +RState ResourceManagerImpl::ResolveResData(const std::shared_ptr idItem, + std::map &outValue) +{ + // only pattern and theme + // ref always at idx 0 + // child will cover parent + outValue.clear(); + + bool haveParent = false; + int count = 0; + std::shared_ptr currItem = idItem; + do { + RState ret = ProcessItem(currItem, outValue); + if (ret != SUCCESS) { + outValue.clear(); + return ret; + } + haveParent = currItem->HaveParent(); + if (haveParent) { + // get parent + uint32_t id; + ResType resType; + bool isRef = IdItem::IsRef(currItem->values_[0], resType, id); + if (!isRef) { + RESMGR_HILOGE(RESMGR_TAG, + "something wrong, pls check HaveParent(). idItem: %{public}s", idItem->ToString().c_str()); + outValue.clear(); + return ERROR; + } + currItem = hapManager_->FindResourceById(id, isOverrideResMgr_); + if (currItem == nullptr) { + RESMGR_HILOGE(RESMGR_TAG, "ref %s id not found", idItem->values_[0].c_str()); + outValue.clear(); + return ERROR; + } + } + + if (++count > MAX_DEPTH_REF_SEARCH) { + RESMGR_HILOGE(RESMGR_TAG, " %u has too many parents", idItem->id_); + outValue.clear(); + return ERROR; + } + } while (haveParent); + + return SUCCESS; +} + RState ResourceManagerImpl::GetBooleanById(uint32_t id, bool &outValue) { const std::shared_ptr idItem = hapManager_->FindResourceById(id, isOverrideResMgr_); @@ -998,6 +1155,20 @@ RState ResourceManagerImpl::GetThemeById(uint32_t id, std::map &outValue) +{ + const std::shared_ptr idItem = hapManager_->FindResourceById(id, isOverrideResMgr_); + if (idItem == nullptr) { + RESMGR_HILOGE(RESMGR_TAG, "GetThemeDataById error id = %{public}d", id); + return ERROR_CODE_RES_ID_NOT_FOUND; + } + RState state = GetThemeData(idItem, outValue); + if (state != SUCCESS && state != ERROR_CODE_RES_REF_TOO_MUCH) { + return ERROR_CODE_RES_NOT_FOUND_BY_ID; + } + return state; +} + RState ResourceManagerImpl::GetThemeByName(const char *name, std::map &outValue) { const std::shared_ptr idItem = hapManager_->FindResourceByName(name, ResType::THEME, isOverrideResMgr_); @@ -1012,6 +1183,20 @@ RState ResourceManagerImpl::GetThemeByName(const char *name, std::map &outValue) +{ + const std::shared_ptr idItem = hapManager_->FindResourceByName(name, ResType::THEME, isOverrideResMgr_); + if (idItem == nullptr) { + RESMGR_HILOGE(RESMGR_TAG, "GetThemeDataByName error name = %{public}s", name); + return ERROR_CODE_RES_NAME_NOT_FOUND; + } + RState state = GetThemeData(idItem, outValue); + if (state != SUCCESS && state != ERROR_CODE_RES_REF_TOO_MUCH) { + return ERROR_CODE_RES_NOT_FOUND_BY_NAME; + } + return state; +} + RState ResourceManagerImpl::GetTheme(const std::shared_ptr idItem, std::map &outValue) { //type invalid @@ -1023,6 +1208,17 @@ RState ResourceManagerImpl::GetTheme(const std::shared_ptr idItem, std:: return ResolveParentReference(idItem, outValue); } +RState ResourceManagerImpl::GetThemeData(const std::shared_ptr idItem, std::map &outValue) +{ + //type invalid + if (idItem->resType_ != ResType::THEME) { + RESMGR_HILOGE(RESMGR_TAG, + "actual resType = %{public}d, expect resType = %{public}d", idItem->resType_, ResType::THEME); + return NOT_FOUND; + } + return ResolveResData(idItem, outValue); +} + RState ResourceManagerImpl::GetProfileById(uint32_t id, std::string &outValue) { auto qd = hapManager_->FindQualifierValueById(id, isOverrideResMgr_); diff --git a/frameworks/resmgr/test/unittest/common/theme_manager_test.cpp b/frameworks/resmgr/test/unittest/common/theme_manager_test.cpp index 85a177620d79a8dd3266a30d91cc8aacff94bc5a..c983f4768a51839c475eb89237084170858883f1 100644 --- a/frameworks/resmgr/test/unittest/common/theme_manager_test.cpp +++ b/frameworks/resmgr/test/unittest/common/theme_manager_test.cpp @@ -93,7 +93,7 @@ HWTEST_F(ThemeManagerTest, ThemeManagerTestLoadThemeSkinResourceTest001, TestSiz } /* - * @tc.name: ThemeManagerTestLoadThemeSkinResourceTest003 + * @tc.name: ThemeManagerTestLoadThemeSkinResourceTest002 * @tc.desc: Test AddResource function, file case. * @tc.type: FUNC */ @@ -116,6 +116,220 @@ HWTEST_F(ThemeManagerTest, ThemeManagerTestLoadThemeSkinResourceTest002, TestSiz ASSERT_EQ(4294967295, outValue); // base_only theme value is #ffffff(4294967295) } +/* + * @tc.name: ThemeManagerTestLoadThemeSkinResourceTest003 + * @tc.desc: Test GetThemeDataById function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ThemeManagerTest, ThemeManagerTestLoadThemeSkinResourceTest003, TestSize.Level1) +{ + // success cases + bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str()); + ASSERT_TRUE(ret); + int id = rmc->GetResId("ohos_device_theme", ResType::THEME); + std::map outValue; + rm->GetThemeDataById(id, outValue); + ASSERT_EQ(ResType::STRING, outValue["width1"].resType); + ASSERT_EQ(ResType::STRING, outValue["width2"].resType); + ASSERT_EQ(ResType::STRING, outValue["height1"].resType); + ASSERT_EQ(ResType::STRING, outValue["height2"].resType); + ASSERT_EQ(ResType::STRING, outValue["textColor1"].resType); + ASSERT_EQ(ResType::STRING, outValue["textColor2"].resType); + ASSERT_EQ(ResType::PATTERN, outValue["button_pattern"].resType); + ASSERT_EQ(ResType::THEME, outValue["ohosTheme"].resType); + ASSERT_EQ(ResType::PATTERN, outValue["text_pattern"].resType); + ASSERT_EQ(ResType::PATTERN, outValue["list_pattern"].resType); + ASSERT_EQ("100fp", outValue["width1"].value); + ASSERT_EQ("100fp", outValue["width2"].value); + ASSERT_EQ("100vp", outValue["height1"].value); + ASSERT_EQ("100vp", outValue["height2"].value); + ASSERT_EQ("#000000FF", outValue["textColor1"].value); + ASSERT_EQ("#000000FF", outValue["textColor2"].value); + ASSERT_EQ("16777333", outValue["button_pattern"].value); + ASSERT_EQ("16777328", outValue["ohosTheme"].value); + ASSERT_EQ("16777332", outValue["text_pattern"].value); + ASSERT_EQ("16777331", outValue["list_pattern"].value); + + std::vector rootDirs; + std::string rootDir = "/data/test/theme/skin/ohos.global.test.all"; + rootDirs.emplace_back(rootDir); + int32_t userId = 100; // userId is 100 + tm->LoadThemeSkinResource("ohos.global.test.all", "entry", rootDirs, userId); + rm->GetThemeDataById(id, outValue); + ASSERT_EQ(ResType::STRING, outValue["width1"].resType); + ASSERT_EQ(ResType::STRING, outValue["width2"].resType); + ASSERT_EQ(ResType::STRING, outValue["height1"].resType); + ASSERT_EQ(ResType::STRING, outValue["height2"].resType); + ASSERT_EQ(ResType::STRING, outValue["textColor1"].resType); + ASSERT_EQ(ResType::STRING, outValue["textColor2"].resType); + ASSERT_EQ("1000fp", outValue["width1"].value); + ASSERT_EQ("100fp", outValue["width2"].value); + ASSERT_EQ("1000vp", outValue["height1"].value); + ASSERT_EQ("100vp", outValue["height2"].value); + ASSERT_EQ("#000000AA", outValue["textColor1"].value); + ASSERT_EQ("#000000FF", outValue["textColor2"].value); + ASSERT_EQ("16777333", outValue["button_pattern"].value); + ASSERT_EQ("16777328", outValue["ohosTheme"].value); + ASSERT_EQ("16777332", outValue["text_pattern"].value); + ASSERT_EQ("16777331", outValue["list_pattern"].value); +} + +/* + * @tc.name: ThemeManagerTestLoadThemeSkinResourceTest004 + * @tc.desc: Test GetThemeDataByName function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ThemeManagerTest, ThemeManagerTestLoadThemeSkinResourceTest004, TestSize.Level1) +{ + // success cases + bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str()); + ASSERT_TRUE(ret); + std::map outValue; + rm->GetThemeDataByName("ohos_device_theme", outValue); + ASSERT_EQ(ResType::STRING, outValue["width1"].resType); + ASSERT_EQ(ResType::STRING, outValue["width2"].resType); + ASSERT_EQ(ResType::STRING, outValue["height1"].resType); + ASSERT_EQ(ResType::STRING, outValue["height2"].resType); + ASSERT_EQ(ResType::STRING, outValue["textColor1"].resType); + ASSERT_EQ(ResType::STRING, outValue["textColor2"].resType); + ASSERT_EQ(ResType::PATTERN, outValue["button_pattern"].resType); + ASSERT_EQ(ResType::THEME, outValue["ohosTheme"].resType); + ASSERT_EQ(ResType::PATTERN, outValue["text_pattern"].resType); + ASSERT_EQ(ResType::PATTERN, outValue["list_pattern"].resType); + ASSERT_EQ("100fp", outValue["width1"].value); + ASSERT_EQ("100fp", outValue["width2"].value); + ASSERT_EQ("100vp", outValue["height1"].value); + ASSERT_EQ("100vp", outValue["height2"].value); + ASSERT_EQ("#000000FF", outValue["textColor1"].value); + ASSERT_EQ("#000000FF", outValue["textColor2"].value); + ASSERT_EQ("16777333", outValue["button_pattern"].value); + ASSERT_EQ("16777328", outValue["ohosTheme"].value); + ASSERT_EQ("16777332", outValue["text_pattern"].value); + ASSERT_EQ("16777331", outValue["list_pattern"].value); + + std::vector rootDirs; + std::string rootDir = "/data/test/theme/skin/ohos.global.test.all"; + rootDirs.emplace_back(rootDir); + int32_t userId = 100; // userId is 100 + tm->LoadThemeSkinResource("ohos.global.test.all", "entry", rootDirs, userId); + rm->GetThemeDataByName("ohos_device_theme", outValue); + ASSERT_EQ(ResType::STRING, outValue["width1"].resType); + ASSERT_EQ(ResType::STRING, outValue["width2"].resType); + ASSERT_EQ(ResType::STRING, outValue["height1"].resType); + ASSERT_EQ(ResType::STRING, outValue["height2"].resType); + ASSERT_EQ(ResType::STRING, outValue["textColor1"].resType); + ASSERT_EQ(ResType::STRING, outValue["textColor2"].resType); + ASSERT_EQ("1000fp", outValue["width1"].value); + ASSERT_EQ("100fp", outValue["width2"].value); + ASSERT_EQ("1000vp", outValue["height1"].value); + ASSERT_EQ("100vp", outValue["height2"].value); + ASSERT_EQ("#000000AA", outValue["textColor1"].value); + ASSERT_EQ("#000000FF", outValue["textColor2"].value); + ASSERT_EQ("16777333", outValue["button_pattern"].value); + ASSERT_EQ("16777328", outValue["ohosTheme"].value); + ASSERT_EQ("16777332", outValue["text_pattern"].value); + ASSERT_EQ("16777331", outValue["list_pattern"].value); +} + +/* + * @tc.name: ThemeManagerTestLoadThemeSkinResourceTest005 + * @tc.desc: Test GetPatternDataByName function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ThemeManagerTest, ThemeManagerTestLoadThemeSkinResourceTest005, TestSize.Level1) +{ + // success cases + bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str()); + ASSERT_TRUE(ret); + std::map outValue; + rm->GetPatternDataByName("ohos_button_pattern", outValue); + ASSERT_EQ(ResType::STRING, outValue["width"].resType); + ASSERT_EQ(ResType::STRING, outValue["height"].resType); + ASSERT_EQ(ResType::STRING, outValue["bgColor"].resType); + ASSERT_EQ(ResType::STRING, outValue["fgColor"].resType); + ASSERT_EQ(ResType::PATTERN, outValue["fontPattern"].resType); + ASSERT_EQ(ResType::STRING, outValue["marginColor"].resType); + ASSERT_EQ(ResType::PATTERN, outValue["baseFontPattern"].resType); + ASSERT_EQ("10vp", outValue["width"].value); + ASSERT_EQ("66vp", outValue["height"].value); + ASSERT_EQ("#FF0000BB", outValue["bgColor"].value); + ASSERT_EQ("#FF0000CC", outValue["fgColor"].value); + ASSERT_EQ("16777334", outValue["fontPattern"].value); + ASSERT_EQ("#FF00AA00", outValue["marginColor"].value); + ASSERT_EQ("16777335", outValue["baseFontPattern"].value); + + std::vector rootDirs; + std::string rootDir = "/data/test/theme/skin/ohos.global.test.all"; + rootDirs.emplace_back(rootDir); + int32_t userId = 100; // userId is 100 + tm->LoadThemeSkinResource("ohos.global.test.all", "entry", rootDirs, userId); + rm->GetPatternDataByName("ohos_button_pattern", outValue); + ASSERT_EQ(ResType::STRING, outValue["width"].resType); + ASSERT_EQ(ResType::STRING, outValue["height"].resType); + ASSERT_EQ(ResType::STRING, outValue["bgColor"].resType); + ASSERT_EQ(ResType::STRING, outValue["fgColor"].resType); + ASSERT_EQ(ResType::PATTERN, outValue["fontPattern"].resType); + ASSERT_EQ(ResType::STRING, outValue["marginColor"].resType); + ASSERT_EQ(ResType::PATTERN, outValue["baseFontPattern"].resType); + ASSERT_EQ("10vp", outValue["width"].value); + ASSERT_EQ("666vp", outValue["height"].value); + ASSERT_EQ("#FF0000BB", outValue["bgColor"].value); + ASSERT_EQ("#FF0000CC", outValue["fgColor"].value); + ASSERT_EQ("16777334", outValue["fontPattern"].value); + ASSERT_EQ("#FF00AA00", outValue["marginColor"].value); + ASSERT_EQ("16777335", outValue["baseFontPattern"].value); +} + +/* + * @tc.name: ThemeManagerTestLoadThemeSkinResourceTest006 + * @tc.desc: Test GetPatternDataById function, file case. + * @tc.type: FUNC + */ +HWTEST_F(ThemeManagerTest, ThemeManagerTestLoadThemeSkinResourceTest006, TestSize.Level1) +{ + // success cases + bool ret = rm->AddResource(FormatFullPath(g_hapPath).c_str()); + ASSERT_TRUE(ret); + int id = rmc->GetResId("ohos_button_pattern", ResType::PATTERN); + std::map outValue; + rm->GetPatternDataById(id, outValue); + ASSERT_EQ(ResType::STRING, outValue["width"].resType); + ASSERT_EQ(ResType::STRING, outValue["height"].resType); + ASSERT_EQ(ResType::STRING, outValue["bgColor"].resType); + ASSERT_EQ(ResType::STRING, outValue["fgColor"].resType); + ASSERT_EQ(ResType::PATTERN, outValue["fontPattern"].resType); + ASSERT_EQ(ResType::STRING, outValue["marginColor"].resType); + ASSERT_EQ(ResType::PATTERN, outValue["baseFontPattern"].resType); + ASSERT_EQ("10vp", outValue["width"].value); + ASSERT_EQ("66vp", outValue["height"].value); + ASSERT_EQ("#FF0000BB", outValue["bgColor"].value); + ASSERT_EQ("#FF0000CC", outValue["fgColor"].value); + ASSERT_EQ("16777334", outValue["fontPattern"].value); + ASSERT_EQ("#FF00AA00", outValue["marginColor"].value); + ASSERT_EQ("16777335", outValue["baseFontPattern"].value); + + std::vector rootDirs; + std::string rootDir = "/data/test/theme/skin/ohos.global.test.all"; + rootDirs.emplace_back(rootDir); + int32_t userId = 100; // userId is 100 + tm->LoadThemeSkinResource("ohos.global.test.all", "entry", rootDirs, userId); + rm->GetPatternDataById(id, outValue); + ASSERT_EQ(ResType::STRING, outValue["width"].resType); + ASSERT_EQ(ResType::STRING, outValue["height"].resType); + ASSERT_EQ(ResType::STRING, outValue["bgColor"].resType); + ASSERT_EQ(ResType::STRING, outValue["fgColor"].resType); + ASSERT_EQ(ResType::PATTERN, outValue["fontPattern"].resType); + ASSERT_EQ(ResType::STRING, outValue["marginColor"].resType); + ASSERT_EQ(ResType::PATTERN, outValue["baseFontPattern"].resType); + ASSERT_EQ("10vp", outValue["width"].value); + ASSERT_EQ("666vp", outValue["height"].value); + ASSERT_EQ("#FF0000BB", outValue["bgColor"].value); + ASSERT_EQ("#FF0000CC", outValue["fgColor"].value); + ASSERT_EQ("16777334", outValue["fontPattern"].value); + ASSERT_EQ("#FF00AA00", outValue["marginColor"].value); + ASSERT_EQ("16777335", outValue["baseFontPattern"].value); +} + /* * @tc.name: ThemeManagerTestLoadThemeIconsResourceTest001 * @tc.desc: Test GetThemeIcons function, file case. diff --git a/interfaces/inner_api/include/resource_manager.h b/interfaces/inner_api/include/resource_manager.h index a9c844fe191a78ff5cd0eef97592cc80fe57d91c..e670d3a1f13936db823474423cc7be8566de63d4 100644 --- a/interfaces/inner_api/include/resource_manager.h +++ b/interfaces/inner_api/include/resource_manager.h @@ -57,6 +57,14 @@ public: uint32_t id; }; + struct ResData { + /** the resource type */ + ResType resType; + + /** the resource value */ + std::string value; + }; + enum class NapiValueType { NAPI_NUMBER = 0, NAPI_STRING = 1 @@ -244,6 +252,14 @@ public: std::vector> &jsParams) = 0; virtual bool AddPatchResource(const char *path, const char *patchPath) = 0; + + virtual RState GetThemeDataByName(const char *name, std::map &outValue) = 0; + + virtual RState GetThemeDataById(uint32_t id, std::map &outValue) = 0; + + virtual RState GetPatternDataById(uint32_t id, std::map &outValue) = 0; + + virtual RState GetPatternDataByName(const char *name, std::map &outValue) = 0; }; EXPORT_FUNC ResourceManager *CreateResourceManager(); diff --git a/test/resource/data/all.hap b/test/resource/data/all.hap old mode 100644 new mode 100755 index 03f22ab6e100778c1fe785897a8f20a4ff3d959a..cb75423b52deba6a451c03c5a38c9ab6917cae55 Binary files a/test/resource/data/all.hap and b/test/resource/data/all.hap differ diff --git a/test/resource/data/theme/base/element/pattern.json b/test/resource/data/theme/base/element/pattern.json index 1fa716fab474d6f0ebe9ca342c13450df53018e6..646b2c0073cb43e96eb62128537f23550c7ee59c 100644 --- a/test/resource/data/theme/base/element/pattern.json +++ b/test/resource/data/theme/base/element/pattern.json @@ -7,6 +7,10 @@ { "name": "normal_background_color", "value": "#00000000" + }, + { + "name": "color1", + "value": "#000000AA" } ], "float": [ @@ -17,6 +21,18 @@ { "name": "card_margin_start", "value": "48vp" + }, + { + "name": "float1", + "value": "1000fp" + }, + { + "name": "float2", + "value": "1000vp" + }, + { + "name": "button_height", + "value": "666vp" } ] } \ No newline at end of file diff --git a/test/resource/src/all/resources/base/element/color.json b/test/resource/src/all/resources/base/element/color.json index 545818e4c97ea3849a7fd5d4988bba118efb8133..31563fb05663fd44228d95511af753171921e738 100755 --- a/test/resource/src/all/resources/base/element/color.json +++ b/test/resource/src/all/resources/base/element/color.json @@ -59,6 +59,10 @@ { "name": "base_only", "value": "#00000000" + }, + { + "name": "color1", + "value": "#000000FF" } ] } \ No newline at end of file diff --git a/test/resource/src/all/resources/base/element/float.json b/test/resource/src/all/resources/base/element/float.json index f24e5b516cf65cbc6fe9ee5e69efd76a30ed80cb..b44e45eb5f67dcf8aee475deb28768838a2cc595 100755 --- a/test/resource/src/all/resources/base/element/float.json +++ b/test/resource/src/all/resources/base/element/float.json @@ -127,6 +127,18 @@ { "name":"float_ref", "value":"$float:aboutPage_minHeight" + }, + { + "name":"float1", + "value":"100fp" + }, + { + "name":"float2", + "value":"100vp" + }, + { + "name":"button_height", + "value":"66vp" } ] } \ No newline at end of file diff --git a/test/resource/src/all/resources/base/element/id_defined.json b/test/resource/src/all/resources/base/element/id_defined.json index 8a63183cb4ff9952946624d1a2cb70995aae7356..a0b4e1d359333e09686c403083a120fdbc92462a 100644 --- a/test/resource/src/all/resources/base/element/id_defined.json +++ b/test/resource/src/all/resources/base/element/id_defined.json @@ -435,5 +435,49 @@ "type": "profile", "name": "test_profile", "id": "0x0100006C" + }, { + "type": "theme", + "name": "base_theme", + "id": "0x0100006D" + }, { + "type": "theme", + "name": "ohos_base_theme", + "id": "0x0100006E" + }, { + "type": "theme", + "name": "ohos_device_theme", + "id": "0x0100006F" + }, { + "type": "theme", + "name": "ohos_theme", + "id": "0x01000070" + }, { + "type": "pattern", + "name": "base_button_pattern", + "id": "0x01000071" + }, { + "type": "pattern", + "name": "ohos_button_pattern", + "id": "0x01000072" + }, { + "type": "pattern", + "name": "base_list_pattern", + "id": "0x01000073" + }, { + "type": "pattern", + "name": "ohos_text_pattern", + "id": "0x01000074" + }, { + "type": "pattern", + "name": "ohos_phone_button_pattern", + "id": "0x01000075" + }, { + "type": "pattern", + "name": "ohos_font_pattern", + "id": "0x01000076" + }, { + "type": "pattern", + "name": "base_font_pattern", + "id": "0x01000077" }] } \ No newline at end of file diff --git a/test/resource/src/all/resources/base/element/pattern.json b/test/resource/src/all/resources/base/element/pattern.json index 10b05df67de0ac0992a3f55ae75b70c247ed483c..d3f801517a5743ae37625be5e491a89e29948158 100755 --- a/test/resource/src/all/resources/base/element/pattern.json +++ b/test/resource/src/all/resources/base/element/pattern.json @@ -44,6 +44,106 @@ "value":"222vp" } ] + }, + { + "name": "base_button_pattern", + "value": [ + { + "name": "bgColor", + "value": "#FF00AABB" + }, + { + "name": "fgColor", + "value": "#FF00AACC" + }, + { + "name": "marginColor", + "value": "#FF00AA00" + }, + { + "name": "baseFontPattern", + "value": "$pattern:base_font_pattern" + } + ] + }, + { + "name": "ohos_button_pattern", + "parent": "base_button_pattern", + "value": [ + { + "name":"width", + "value":"10vp" + }, + { + "name":"height", + "value":"$float:button_height" + }, + { + "name": "bgColor", + "value": "#FF0000BB" + }, + { + "name": "fgColor", + "value": "#FF0000CC" + }, + { + "name": "fontPattern", + "value": "$pattern:ohos_font_pattern" + } + ] + }, + { + "name": "base_list_pattern", + "value": [ + { + "name": "bgColor", + "value": "#FF1100BB" + }, + { + "name": "fgColor", + "value": "#FF1100CC" + } + ] + }, + { + "name": "ohos_text_pattern", + "value": [ + { + "name": "bgColor", + "value": "#FF2200BB" + }, + { + "name": "fgColor", + "value": "#FF2200CC" + } + ] + }, + { + "name": "ohos_font_pattern", + "value": [ + { + "name": "bgColor", + "value": "#FF3300BB" + }, + { + "name": "fgColor", + "value": "#FF3300CC" + } + ] + }, + { + "name": "base_font_pattern", + "value": [ + { + "name": "bgColor", + "value": "#FF3300BB" + }, + { + "name": "fgColor", + "value": "#FF3300CC" + } + ] } + ] } \ No newline at end of file diff --git a/test/resource/src/all/resources/base/element/theme.json b/test/resource/src/all/resources/base/element/theme.json index 365505dd5cf3bcdd5f598c8d84ada4f807cd01a2..50c883942b0ef0d6d085b9e6cf5194855e73d63f 100755 --- a/test/resource/src/all/resources/base/element/theme.json +++ b/test/resource/src/all/resources/base/element/theme.json @@ -54,6 +54,56 @@ "value":"true" } ] + }, + { + "name":"base_theme", + "value":[ + { + "name":"button_pattern", + "value":"$pattern:base_button_pattern" + }, + { + "name":"list_pattern", + "value":"$pattern:base_list_pattern" + } + ] + }, + { + "name":"ohos_base_theme", + "parent": "base_theme", + "value":[ + { + "name":"button_pattern", + "value":"$pattern:ohos_button_pattern" + }, + { + "name":"text_pattern", + "value":"$pattern:ohos_text_pattern" + }, + { + "name":"ohosTheme", + "value":"$theme:ohos_theme" + } + ] + }, + { + "name":"ohos_device_theme", + "parent": "ohos_base_theme", + "value":[ + { + "name":"button_pattern", + "value":"$pattern:ohos_button_pattern" + } + ] + }, + { + "name":"ohos_theme", + "value":[ + { + "name":"ohos_theme_float", + "value":"100vp" + } + ] } ] } \ No newline at end of file diff --git a/test/resource/src/all/resources/phone/element/pattern.json b/test/resource/src/all/resources/phone/element/pattern.json new file mode 100644 index 0000000000000000000000000000000000000000..0f85f1efec6f3d5274e5ba7957b85188e62e31c7 --- /dev/null +++ b/test/resource/src/all/resources/phone/element/pattern.json @@ -0,0 +1,22 @@ +{ + "pattern":[ + { + "name":"ohos_phone_button_pattern", + "parent": "ohos_button_pattern", + "value":[ + { + "name":"width", + "value":"100vp" + }, + { + "name": "bgColor", + "value": "#FF0033BB" + }, + { + "name": "fgColor", + "value": "#FF0033CC" + } + ] + } + ] + } \ No newline at end of file diff --git a/test/resource/src/all/resources/phone/element/theme.json b/test/resource/src/all/resources/phone/element/theme.json new file mode 100644 index 0000000000000000000000000000000000000000..319895b1263db6e7b32b91ed7d8079433bb9c77c --- /dev/null +++ b/test/resource/src/all/resources/phone/element/theme.json @@ -0,0 +1,38 @@ +{ + "theme": [ + { + "name":"ohos_device_theme", + "parent": "ohos_base_theme", + "value":[ + { + "name":"button_pattern", + "value":"$pattern:ohos_phone_button_pattern" + }, + { + "name":"width1", + "value":"$float:float1" + }, + { + "name":"width2", + "value":"100fp" + }, + { + "name":"height1", + "value":"$float:float2" + }, + { + "name":"height2", + "value":"100vp" + }, + { + "name":"textColor1", + "value":"$color:color1" + }, + { + "name":"textColor2", + "value":"#000000FF" + } + ] + } + ] + } \ No newline at end of file