mirror of
https://gitee.com/openharmony/global_resource_management
synced 2024-11-27 02:00:55 +00:00
overlay添加TDD用例
Signed-off-by: huangjie <huangjie125@huawei.com>
This commit is contained in:
parent
66d47b6fd6
commit
5ebd519c08
@ -171,8 +171,8 @@ private:
|
||||
|
||||
std::vector<const HapResource::IdValues *> GetResourceListByName(const char *name, const ResType resType) const;
|
||||
|
||||
const HapResource::ValueUnderQualifierDir *GetBestMatchResource(std::vector<const HapResource::IdValues *> candidates,
|
||||
uint32_t density);
|
||||
const HapResource::ValueUnderQualifierDir *GetBestMatchResource(std::vector<const HapResource::IdValues *>
|
||||
candidates, uint32_t density);
|
||||
|
||||
bool AddResourcePath(const char *path);
|
||||
|
||||
|
@ -539,7 +539,10 @@ private:
|
||||
"systemResources/SystemResources.hap";
|
||||
|
||||
const std::string SYSTEM_RESOURCE_OVERLAY_PATH = "/data/storage/el1/bundle/" \
|
||||
"ohos.global.systemres.overlay/ohos.global.systemres.overlay/assets/entry/resources.index";
|
||||
"ohos.global.systemres.overlay/ohos.global.systemres.overlay/assets/entry/resources.index";
|
||||
|
||||
const std::string SYSTEM_RESOURCE_OVERLAY_PATH_COMPRESSED = "/data/storage/el1/bundle/" \
|
||||
"ohos.global.systemres.overlay/ohos.global.systemres.overlay/SystemResourcesOverlay.hap";
|
||||
|
||||
const float DEFAULT_DENSITY = 160.0f;
|
||||
|
||||
|
@ -181,8 +181,8 @@ const HapResource::ValueUnderQualifierDir *HapManager::FindQualifierValueById(ui
|
||||
return this->GetBestMatchResource(candidates, density);
|
||||
}
|
||||
|
||||
const HapResource::ValueUnderQualifierDir *HapManager::GetBestMatchResource(std::vector<const HapResource::IdValues *> candidates,
|
||||
uint32_t density)
|
||||
const HapResource::ValueUnderQualifierDir *HapManager::GetBestMatchResource(std::vector<const HapResource::IdValues *>
|
||||
candidates, uint32_t density)
|
||||
{
|
||||
const ResConfigImpl *bestResConfig = nullptr;
|
||||
const ResConfigImpl *bestOverlayResConfig = nullptr;
|
||||
@ -211,7 +211,7 @@ const HapResource::ValueUnderQualifierDir *HapManager::GetBestMatchResource(std:
|
||||
overlayResult = paths[i];
|
||||
}
|
||||
} else {
|
||||
if (bestResConfig == nullptr) {
|
||||
if (bestResConfig == nullptr) {
|
||||
bestResConfig = resConfig;
|
||||
result = paths[i];
|
||||
continue;
|
||||
@ -223,8 +223,8 @@ const HapResource::ValueUnderQualifierDir *HapManager::GetBestMatchResource(std:
|
||||
}
|
||||
}
|
||||
}
|
||||
if (bestOverlayResConfig != nullptr && result->IsSystemResource()) {
|
||||
if(bestOverlayResConfig->IsMoreSuitable(bestResConfig, currentResConfig, density)){
|
||||
if (bestOverlayResConfig != nullptr && result != nullptr && result->IsSystemResource()) {
|
||||
if (bestOverlayResConfig->IsMoreSuitable(bestResConfig, currentResConfig, density)) {
|
||||
return overlayResult;
|
||||
}
|
||||
}
|
||||
|
@ -122,10 +122,6 @@ void CanonicalizePath(const char *path, char *outPath, size_t len)
|
||||
|
||||
const HapResource* HapResource::Load(const char *path, const ResConfigImpl* defaultConfig, bool system)
|
||||
{
|
||||
if (strcmp(path, "/data/storage/el1/bundle/ohos.global.systemres/"
|
||||
"ohos.global.systemres/assets/entry/resources.index") == 0) {
|
||||
system = true;
|
||||
}
|
||||
if (Utils::endWithTail(path, "hap")) {
|
||||
return LoadFromHap(path, defaultConfig, system);
|
||||
} else {
|
||||
@ -227,7 +223,7 @@ const std::unordered_map<std::string, HapResource *> HapResource::LoadOverlays(c
|
||||
{
|
||||
std::unordered_map<std::string, HapResource *> result;
|
||||
do {
|
||||
const HapResource *targetResource = LoadFromIndex(path.c_str(), defaultConfig);
|
||||
const HapResource *targetResource = Load(path.c_str(), defaultConfig, true);
|
||||
if (targetResource == nullptr) {
|
||||
HILOG_ERROR("load target failed");
|
||||
break;
|
||||
@ -237,7 +233,7 @@ const std::unordered_map<std::string, HapResource *> HapResource::LoadOverlays(c
|
||||
std::unordered_map<std::string, std::unordered_map<ResType, uint32_t>> mapping =
|
||||
targetResource->BuildNameTypeIdMapping();
|
||||
for (auto iter = overlayPaths.begin(); iter != overlayPaths.end(); iter++) {
|
||||
const HapResource *overlayResource = LoadFromIndex(iter->c_str(), defaultConfig);
|
||||
const HapResource *overlayResource = Load(iter->c_str(), defaultConfig);
|
||||
if (overlayResource == nullptr) {
|
||||
HILOG_ERROR("load overlay failed");
|
||||
success = false;
|
||||
|
@ -80,18 +80,26 @@ bool ResourceManagerImpl::Init()
|
||||
HILOG_ERROR("new HapManager failed when ResourceManagerImpl::Init");
|
||||
return false;
|
||||
}
|
||||
if (Utils::isFileExist(SYSTEM_RESOURCE_OVERLAY_PATH) && Utils::isFileExist(SYSTEM_RESOURCE_PATH)) {
|
||||
vector<string> overlayPaths;
|
||||
overlayPaths.push_back(SYSTEM_RESOURCE_OVERLAY_PATH);
|
||||
AddResource(SYSTEM_RESOURCE_PATH.c_str(), overlayPaths);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Utils::isFileExist(SYSTEM_RESOURCE_OVERLAY_PATH_COMPRESSED) &&
|
||||
Utils::isFileExist(SYSTEM_RESOURCE_PATH_COMPRESSED)) {
|
||||
vector<string> overlayPaths;
|
||||
overlayPaths.push_back(SYSTEM_RESOURCE_OVERLAY_PATH_COMPRESSED);
|
||||
AddResource(SYSTEM_RESOURCE_PATH_COMPRESSED.c_str(), overlayPaths);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Utils::isFileExist(SYSTEM_RESOURCE_PATH)) {
|
||||
AddResource(SYSTEM_RESOURCE_PATH.c_str());
|
||||
} else {
|
||||
AddResource(SYSTEM_RESOURCE_PATH_COMPRESSED.c_str());
|
||||
}
|
||||
|
||||
bool overlay_hap_exist = Utils::isFileExist(SYSTEM_RESOURCE_OVERLAY_PATH);
|
||||
if (overlay_hap_exist) {
|
||||
vector<string> overlayPaths;
|
||||
overlayPaths.push_back(SYSTEM_RESOURCE_OVERLAY_PATH);
|
||||
AddResource(SYSTEM_RESOURCE_PATH.c_str(), overlayPaths);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -624,6 +624,19 @@ HWTEST_F(ResourceManagerTest, ResourceManagerAddResourceTest003, TestSize.Level1
|
||||
ASSERT_TRUE(!ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: ResourceManagerAddResourceTest004
|
||||
* @tc.desc: Test AddResource function, file case.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ResourceManagerTest, ResourceManagerAddResourceTest004, TestSize.Level1)
|
||||
{
|
||||
std::vector<std::string> overlayPaths;
|
||||
overlayPaths.push_back(FormatFullPath(g_overlay_resFilePath).c_str());
|
||||
bool ret = ((ResourceManagerImpl *)rm)->AddResource(FormatFullPath(g_system_resFilePath).c_str(), overlayPaths);
|
||||
ASSERT_TRUE(ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: ResourceManagerUpdateResConfigTest001
|
||||
* @tc.desc: Test UpdateResConfig function
|
||||
@ -845,6 +858,21 @@ HWTEST_F(ResourceManagerTest, ResourceManagerGetStringByIdTest003, TestSize.Leve
|
||||
ASSERT_EQ(ERROR_CODE_RES_ID_NOT_FOUND, state);
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: ResourceManagerGetStringByIdTest004
|
||||
* @tc.desc: Test GetStringById function
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ResourceManagerTest, ResourceManagerGetStringByIdTest004, TestSize.Level1)
|
||||
{
|
||||
AddResource("en", nullptr, nullptr);
|
||||
std::vector<std::string> overlayPaths;
|
||||
overlayPaths.push_back(FormatFullPath(g_overlay_resFilePath).c_str());
|
||||
bool ret = ((ResourceManagerImpl* )rm)->AddResource(FormatFullPath(g_system_resFilePath).c_str(), overlayPaths);
|
||||
ASSERT_TRUE(ret);
|
||||
TestStringById("ohos_app_name", "SystemOverlay");
|
||||
}
|
||||
|
||||
/*
|
||||
* @tc.name: ResourceManagerGetStringByNameTest001
|
||||
* @tc.desc: Test GetStringByName function
|
||||
|
@ -22,6 +22,7 @@ namespace Resource {
|
||||
int ResourceManagerAddResourceTest001(void);
|
||||
int ResourceManagerAddResourceTest002(void);
|
||||
int ResourceManagerAddResourceTest003(void);
|
||||
int ResourceManagerAddResourceTest004(void);
|
||||
int ResourceManagerUpdateResConfigTest001(void);
|
||||
int ResourceManagerUpdateResConfigTest002(void);
|
||||
int ResourceManagerUpdateResConfigTest003(void);
|
||||
@ -32,6 +33,7 @@ int ResourceManagerGetResConfigTest002(void);
|
||||
int ResourceManagerGetStringByIdTest001(void);
|
||||
int ResourceManagerGetStringByIdTest002(void);
|
||||
int ResourceManagerGetStringByIdTest003(void);
|
||||
int ResourceManagerGetStringByIdTest004(void);
|
||||
int ResourceManagerGetStringByNameTest001(void);
|
||||
int ResourceManagerGetStringByNameTest002(void);
|
||||
int ResourceManagerGetStringByNameTest003(void);
|
||||
|
@ -27,6 +27,10 @@
|
||||
static const char *g_resFilePath = "all/assets/entry/resources.index";
|
||||
static const char *g_hapPath = "all.hap";
|
||||
|
||||
// this is overlay relative path
|
||||
static const char *g_system_resFilePath = "system/assets/entry/resources.index";
|
||||
static const char *g_overlay_resFilePath = "overlay/assets/entry/resources.index";
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace Resource {
|
||||
|
@ -190,7 +190,7 @@ struct ResMgrAsyncContext {
|
||||
std::shared_ptr<ResourceManager::Resource> resource_;
|
||||
|
||||
ResMgrAsyncContext() : work_(nullptr), resId_(0), param_(0), iValue_(0), fValue_(0.0f), bValue_(false),
|
||||
createValueFunc_(nullptr), len_(0), deferred_(nullptr), callbackRef_(nullptr), success_(true) {}
|
||||
createValueFunc_(nullptr), len_(0), deferred_(nullptr), callbackRef_(nullptr), success_(true), errCode_(0) {}
|
||||
|
||||
void SetErrorMsg(const std::string &msg, bool withResId = false, int32_t errCode = 0);
|
||||
|
||||
|
BIN
test/resource/data/overlay/assets/entry/resources.index
Normal file
BIN
test/resource/data/overlay/assets/entry/resources.index
Normal file
Binary file not shown.
BIN
test/resource/data/system/assets/entry/resources.index
Normal file
BIN
test/resource/data/system/assets/entry/resources.index
Normal file
Binary file not shown.
@ -25,6 +25,8 @@
|
||||
<option name="push" value="data/all/assets/entry/resources/base/profile/test_profile.json -> /data/test/all/assets/entry/resources/base/profile/" src="res"/>
|
||||
<option name="push" value="data/colormode/assets/entry/resources.index -> /data/test/colormode/assets/entry/" src="res"/>
|
||||
<option name="push" value="data/mccmnc/assets/entry/resources.index -> /data/test/mccmnc/assets/entry/" src="res"/>
|
||||
<option name="push" value="data/overlay/assets/entry/resources.index -> /data/test/overlay/assets/entry/" src="res"/>
|
||||
<option name="push" value="data/system/assets/entry/resources.index -> /data/test/system/assets/entry/" src="res"/>
|
||||
</preparer>
|
||||
</target>
|
||||
</configuration>
|
||||
|
61
test/resource/src/overlay/config.json
Normal file
61
test/resource/src/overlay/config.json
Normal file
@ -0,0 +1,61 @@
|
||||
{
|
||||
"app": {
|
||||
"bundleName": "ohos.global.test.overlay",
|
||||
"vendor": "global",
|
||||
"version": {
|
||||
"code": 1000000,
|
||||
"name": "1.0.0"
|
||||
}
|
||||
},
|
||||
"deviceConfig": {},
|
||||
"module": {
|
||||
"package": "ohos.global.test.overlay",
|
||||
"name": ".MyApplication",
|
||||
"mainAbility": "ohos.global.test.overlay.MainAbility",
|
||||
"deviceType": [
|
||||
"phone",
|
||||
"tablet",
|
||||
"tv",
|
||||
"wearable"
|
||||
],
|
||||
"distro": {
|
||||
"deliveryWithInstall": true,
|
||||
"moduleName": "entry",
|
||||
"moduleType": "entry",
|
||||
"installationFree": false
|
||||
},
|
||||
"abilities": [
|
||||
{
|
||||
"skills": [
|
||||
{
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
],
|
||||
"actions": [
|
||||
"action.system.home"
|
||||
]
|
||||
}
|
||||
],
|
||||
"visible": true,
|
||||
"name": "ohos.global.test.overlay.MainAbility",
|
||||
"icon": "$media:ohos_app_icon",
|
||||
"description": "overlay Ability",
|
||||
"label": "entry_MainAbility",
|
||||
"type": "page",
|
||||
"launchType": "standard"
|
||||
}
|
||||
],
|
||||
"js": [
|
||||
{
|
||||
"pages": [
|
||||
"pages/index/index"
|
||||
],
|
||||
"name": "default",
|
||||
"window": {
|
||||
"designWidth": 720,
|
||||
"autoDesignWidth": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
16
test/resource/src/overlay/resources/base/element/color.json
Normal file
16
test/resource/src/overlay/resources/base/element/color.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"color": [
|
||||
{
|
||||
"name": "ohos_id_color_progress",
|
||||
"value": "#f5dc6200"
|
||||
},
|
||||
{
|
||||
"name": "ohos_id_color_background",
|
||||
"value": "#f5dc6200"
|
||||
},
|
||||
{
|
||||
"name": "ohos_id_color_emphasize",
|
||||
"value": "#f5dc6200"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"color": [
|
||||
{
|
||||
"name": "ohos_id_color_foreground_dark",
|
||||
"value": "#f5dc6200"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"color": [
|
||||
{
|
||||
"name": "ohos_id_color_foreground_transparent",
|
||||
"value": "#f5dc6200"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"float": [
|
||||
{
|
||||
"name": "ohos_id_alpha_content_primary",
|
||||
"value": "1.9"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
"startId": "0x07800000",
|
||||
"record": [
|
||||
{
|
||||
"type": "color",
|
||||
"name": "ohos_id_color_foreground",
|
||||
"order": 0
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
{
|
||||
"pattern": [
|
||||
{
|
||||
"name": "ohos_button_pattern",
|
||||
"value": [
|
||||
{
|
||||
"name": "bg_color",
|
||||
"value": "$color:ohos_id_color_emphasize"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
]
|
||||
}
|
16
test/resource/src/overlay/resources/base/element/string.json
Normal file
16
test/resource/src/overlay/resources/base/element/string.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "ohos_app_name",
|
||||
"value": "SystemOverlay"
|
||||
},
|
||||
{
|
||||
"name": "ohos_lab_answer_call",
|
||||
"value": "overlay接听电话Base"
|
||||
},
|
||||
{
|
||||
"name": "app_name",
|
||||
"value": "overlayAbout"
|
||||
}
|
||||
]
|
||||
}
|
13
test/resource/src/overlay/resources/base/element/theme.json
Normal file
13
test/resource/src/overlay/resources/base/element/theme.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"theme": [
|
||||
{
|
||||
"name": "ohos_theme",
|
||||
"value": [
|
||||
{
|
||||
"name": "bg_color",
|
||||
"value": "$color:ohos_id_color_background"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
BIN
test/resource/src/overlay/resources/base/media/ohos_app_icon.png
Normal file
BIN
test/resource/src/overlay/resources/base/media/ohos_app_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.8 KiB |
@ -0,0 +1,8 @@
|
||||
{
|
||||
"color": [
|
||||
{
|
||||
"name": "ohos_id_color_foreground",
|
||||
"value": "#f5dc6200"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"float": [
|
||||
{
|
||||
"name": "ohos_id_alpha_content_primary",
|
||||
"value": "2.0"
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "ohos_lab_answer_call",
|
||||
"value": "overlay接听电话"
|
||||
},
|
||||
{
|
||||
"name": "ohos_lab_internet",
|
||||
"value": "overlay访问网络"
|
||||
},
|
||||
{
|
||||
"name": "ohos_lab_internet",
|
||||
"value": "overlay访问网络多配"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user