diff --git a/OAT.xml b/OAT.xml old mode 100755 new mode 100644 diff --git a/README.md b/README.md index 456e3aa939d39d823b941f69edbde0621d99c8c9..afc70f5970eae80b52bf8f6a624f13a674690444 100644 --- a/README.md +++ b/README.md @@ -16,14 +16,14 @@ The directory structure for the resource management module is as follows: ``` /base/global/ -├── resmgr_lite # Code repository for the resource management module -│ ├── frameworks # Core code of the resource management module -│ │ ├── resmgr_lite # Core code for resource parsing -│ │ │ ├── include # Header files of the resource management module -│ │ │ ├── src # Implementation code of the resource management module -│ │ │ └── test # Test code -│ ├── interfaces # APIs of the resource management module -│ │ └── innerkits # APIs of the resource management module for internal subsystems +├── resource_management_lite # Code repository for the resource management module +│ ├── frameworks # Core code of the resource management module +│ │ ├── resource_management_lite # Core code for resource parsing +│ │ │ ├── include # Header files of the resource management module +│ │ │ ├── src # Implementation code of the resource management module +│ │ │ └── test # Test code +│ ├── interfaces # APIs of the resource management module +│ │ └── inner_api # APIs of the resource management module for internal subsystems ``` ## Usage @@ -52,9 +52,7 @@ if (values != NULL) { [Globalization subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/globalization.md) -global\_resmgr\_lite +**global\_resmgr\_lite** [global\_i18n\_lite](https://gitee.com/openharmony/global_i18n_lite/blob/master/README.md) -[global\_cust\_lite](https://gitee.com/openharmony/global_cust_lite/blob/master/README.md) - diff --git a/README_zh.md b/README_zh.md index dd1884153a76fe0d48fedec355e8f9f5fa92f8e1..2f242080a2d551f45fdc874b3d471a7e587146c4 100644 --- a/README_zh.md +++ b/README_zh.md @@ -16,14 +16,14 @@ ``` /base/global/ -├── resmgr_lite # 资源管理代码仓 -│ ├── frameworks # 资源管理核心代码 -│ │ ├── resmgr_lite # 资源解析核心代码 -│ │ │ ├── include # 资源管理头文件 -│ │ │ ├── src # 资源管理实现代码 -│ │ │ └── test # 资源管理测试代码 -│ ├── interfaces # 资源管理接口 -│ │ └── innerkits # 资源管理对子系统间接口 +├── resource_management_lite # 资源管理代码仓 +│ ├── frameworks # 资源管理核心代码 +│ │ ├── resource_management_lite # 资源解析核心代码 +│ │ │ ├── include # 资源管理头文件 +│ │ │ ├── src # 资源管理实现代码 +│ │ │ └── test # 资源管理测试代码 +│ ├── interfaces # 资源管理接口 +│ │ └── inner_api # 资源管理对子系统间接口 ``` ## 说明 @@ -52,9 +52,7 @@ if (values != NULL) { [全球化子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E5%85%A8%E7%90%83%E5%8C%96%E5%AD%90%E7%B3%BB%E7%BB%9F.md) -global\_resmgr\_lite +**global\_resmgr\_lite** [global\_i18n\_lite](https://gitee.com/openharmony/global_i18n_lite/blob/master/README_zh.md) -[global\_cust\_lite](https://gitee.com/openharmony/global_cust_lite/blob/master/README_zh.md) - diff --git a/bundle.json b/bundle.json new file mode 100644 index 0000000000000000000000000000000000000000..9150456a76db1ec765946ce2bc8df228e6cb2226 --- /dev/null +++ b/bundle.json @@ -0,0 +1,66 @@ +{ + "name": "@ohos/global_resource_management_lite", + "version": "", + "description": "Obtains resource information based on the device type and configuration", + "homePage": "https://gitee.com/openharmony", + "license": "Apache V2", + "repository": "https://gitee.com/openharmony/global_resource_management_lite", + "domain": "os", + "language": "", + "publishAs": "code-segment", + "private": false, + "scripts": {}, + "tags": [ + "base" + ], + "keywords": [ + "global", + "resmgr", + "lite" + ], + "envs": [], + "dirs": [], + "author": { + "name": "", + "email": "", + "url": "" + }, + "contributors": [ + { + "name": "", + "email": "", + "url": "" + } + ], + "segment": { + "destPath": "base/global/resource_management_lite" + }, + "component": { + "name": "resource_management_lite", + "subsystem": "global", + "syscap": [], + "features": [], + "adapted_system_type": [ + "small" + ], + "rom": "", + "ram": "", + "deps": { + "components": [ + "utils_base" + ], + "third_party": [ + "bounds_checking_function" + ] + }, + "build": { + "sub_component": [ + "//base/global/resource_management_lite/frameworks/resmgr_lite:global_resmgr" + ], + "inner_kits": [], + "test": [ + "//base/global/resource_management_lite/frameworks/resmgr_lite/test:unittest" + ] + } + } +} \ No newline at end of file diff --git a/frameworks/resmgr_lite/BUILD.gn b/frameworks/resmgr_lite/BUILD.gn index ce3ca97e97e60a4336ac3dbd9d33a011ea7365ea..9b0dcf263ff5f597addfe4eece8c949f1e35467f 100644 --- a/frameworks/resmgr_lite/BUILD.gn +++ b/frameworks/resmgr_lite/BUILD.gn @@ -23,8 +23,6 @@ if (defined(ohos_lite) && ohos_kernel_type == "liteos_a") { "src/global.cpp", "src/hap_manager.cpp", "src/hap_resource.cpp", - "src/likely_subtags_key_data.cpp", - "src/likely_subtags_value_data.cpp", "src/locale_matcher.cpp", "src/lock.cpp", "src/res_config_impl.cpp", @@ -45,7 +43,7 @@ if (defined(ohos_lite) && ohos_kernel_type == "liteos_a") { config("global_resmgr_config") { include_dirs = [ "include", - "//base/global/resmgr_lite/interfaces/innerkits/include", + "//base/global/resource_management_lite/interfaces/inner_api/include", "//utils/native/lite/include", "//third_party/bounds_checking_function/include", ] @@ -62,8 +60,8 @@ config("global_resmgr_config") { config("global_public_config") { include_dirs = [ - "//base/global/resmgr_lite/frameworks/resmgr_lite/include", - "//base/global/resmgr_lite/interfaces/innerkits/include", + "//base/global/resource_management_lite/frameworks/resmgr_lite/include", + "//base/global/resource_management_lite/interfaces/inner_api/include", ] } @@ -80,16 +78,24 @@ config("global_resmgr_mingw_config") { } if (defined(ohos_lite)) { - shared_library("global_resmgr") { - sources = global_sources - configs += [ ":global_resmgr_config" ] - deps = [ "//third_party/bounds_checking_function:libsec_shared" ] - if (ohos_kernel_type == "liteos_a") { - public_deps = [ - "//base/global/i18n_lite/frameworks/i18n:global_i18n", - "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", - "//build/lite/config/component/zlib:zlib_shared", - ] + if (ohos_kernel_type == "liteos_m") { + static_library("global_resmgr") { + sources = global_sources + public_configs = [ ":global_resmgr_config" ] + deps = [ "//third_party/bounds_checking_function:libsec_static" ] + } + } else { + shared_library("global_resmgr") { + sources = global_sources + configs += [ ":global_resmgr_config" ] + deps = [ "//third_party/bounds_checking_function:libsec_shared" ] + if (ohos_kernel_type == "liteos_a") { + public_deps = [ + "//base/global/i18n_lite/frameworks/i18n:global_i18n", + "//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared", + "//build/lite/config/component/zlib:zlib_shared", + ] + } } } diff --git a/frameworks/resmgr_lite/CMakeLists.txt b/frameworks/resmgr_lite/CMakeLists.txt index d561265cf69dc2ea5e4b506b533e65a0f4257d5d..276159a5286115a397bdfaf88b04c141a7bcbeaa 100644 --- a/frameworks/resmgr_lite/CMakeLists.txt +++ b/frameworks/resmgr_lite/CMakeLists.txt @@ -13,9 +13,9 @@ cmake_minimum_required(VERSION 3.16.5) -set(GlobalSrc "${PROJECT_SOURCE_DIR}/base/global/resmgr_lite/frameworks/resmgr_lite/src") -set(GlobalInc "${PROJECT_SOURCE_DIR}/base/global/resmgr_lite/frameworks/resmgr_lite/include") -set(GlobalKitInc "${PROJECT_SOURCE_DIR}/base/global/resmgr_lite/interfaces/innerkits/include") +set(GlobalSrc "${PROJECT_SOURCE_DIR}/base/global/resource_management_lite/frameworks/resmgr_lite/src") +set(GlobalInc "${PROJECT_SOURCE_DIR}/base/global/resource_management_lite/frameworks/resmgr_lite/include") +set(GlobalKitInc "${PROJECT_SOURCE_DIR}/base/global/resource_management_lite/interfaces/inner_api/include") include_directories(${PROJECT_SOURCE_DIR}/third_party/bounds_checking_function/include) diff --git a/frameworks/resmgr_lite/include/auto_mutex.h b/frameworks/resmgr_lite/include/auto_mutex.h index 58e1026678770566f2d40dc61917ea3d378f0965..756eec091c24578a132d32678daaa51e5f02a5c6 100644 --- a/frameworks/resmgr_lite/include/auto_mutex.h +++ b/frameworks/resmgr_lite/include/auto_mutex.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -22,10 +22,10 @@ namespace Global { namespace Resource { class AutoMutex { public: - inline AutoMutex(Lock &lock) : lock_(lock) + explicit inline AutoMutex(Lock &lock) : lock_(lock) { lock_.lock(); } - inline AutoMutex(Lock *lock) : lock_(*lock) + explicit inline AutoMutex(Lock *lock) : lock_(*lock) { lock_.lock(); } inline ~AutoMutex() diff --git a/frameworks/resmgr_lite/include/global_utils.h b/frameworks/resmgr_lite/include/global_utils.h index 6bd8c486161f855f8bcd2bf1fea6724248ffb0e7..a2cedd46d7811f4125abd8da09e697add8ffa003 100644 --- a/frameworks/resmgr_lite/include/global_utils.h +++ b/frameworks/resmgr_lite/include/global_utils.h @@ -114,7 +114,7 @@ typedef struct LocaleItem { GlobalUtilsImpl *GetGlobalUtilsImpl(void); -#define MC_FAILURE -1 +#define MC_FAILURE (-1) #define MC_SUCCESS 0 #ifdef __cplusplus diff --git a/frameworks/resmgr_lite/include/hap_manager.h b/frameworks/resmgr_lite/include/hap_manager.h index 8c2485c10387a21df91123813ffb3faf4fdcc29f..1c3da3e98872388105b65ce9cdd4d4ae4a5c14a6 100644 --- a/frameworks/resmgr_lite/include/hap_manager.h +++ b/frameworks/resmgr_lite/include/hap_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -29,24 +29,71 @@ namespace Global { namespace Resource { class HapManager { public: - HapManager(ResConfigImpl *resConfig); - + /** + * The constructor of HapManager + */ + explicit HapManager(ResConfigImpl *resConfig); + + /** + * The destructor of HapManager + */ ~HapManager(); + /** + * Update the resConfig + * @param resConfig the resource config + * @return SUCCESS if the resConfig updated success, else HAP_INIT_FAILED + */ RState UpdateResConfig(ResConfig &resConfig); + /** + * Get the resConfig + * @param resConfig the resource config + */ void GetResConfig(ResConfig &resConfig); + /** + * Add resource path to hap paths + * @param path the resource path + * @return true if add resource path success, else false + */ bool AddResource(const char *path); + /** + * Find resource by resource id + * @param id the resource id + * @return the resources related to resource id + */ const IdItem *FindResourceById(uint32_t id); + /** + * Find resource by resource name + * @param name the resource name + * @param resType the resource type + * @return the resources related to resource name + */ const IdItem *FindResourceByName(const char *name, const ResType resType); + /** + * Find best resource path by resource id + * @param id the resource id + * @return the best resource path + */ const HapResource::ValueUnderQualifierDir *FindQualifierValueById(uint32_t id); + /** + * Find best resource path by resource name + * @param name the resource name + * @param resType the resource type + * @return the best resource path + */ const HapResource::ValueUnderQualifierDir *FindQualifierValueByName(const char *name, const ResType resType); + /** + * Get the language pluralRule related to quantity + * @param quantity the language quantity + * @return the language pluralRule related to quantity + */ std::string GetPluralRulesAndSelect(int quantity); private: diff --git a/frameworks/resmgr_lite/include/hap_parser.h b/frameworks/resmgr_lite/include/hap_parser.h index 85dd13d7835506aaf1c3c3c890d551aa53e0fbf8..900149fd1ee6c5a51581de5c7a1f01ccba9a47ec 100644 --- a/frameworks/resmgr_lite/include/hap_parser.h +++ b/frameworks/resmgr_lite/include/hap_parser.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -51,16 +51,45 @@ public: static int32_t ReadIndexFromFile(const char *zipFile, void **buffer, size_t &bufLen, std::string &errInfo); + /** + * Parse resource hex to resDesc + * @param buffer the resource bytes + * @param bufLen length in bytes + * @param resDesc index file in hap + * @param defaultConfig the default config + * @return OK if the resource hex parse success, else SYS_ERROR + */ static int32_t ParseResHex(const char *buffer, const size_t bufLen, ResDesc &resDesc, const ResConfigImpl *defaultConfig = nullptr); + /** + * Create resource config from KeyParams + * @param keyParams the keyParams contain type and value + * @return the resource config related to the keyParams + */ static ResConfigImpl *CreateResConfigFromKeyParams(const std::vector &keyParams); + /** + * To resource folder path + * @param keyParams the keyParams contain type and value + * @return the resources folder path + */ static std::string ToFolderPath(const std::vector &keyParams); + /** + * Get screen density + * @param value the type of screen density + * @return the screen density related to the value + */ static ScreenDensity GetScreenDensity(uint32_t value); + /** + * Get device type + * @param value the type of device + * @return the device type related to the value + */ static DeviceType GetDeviceType(uint32_t value); + private: static const char *RES_FILE_NAME; }; diff --git a/frameworks/resmgr_lite/include/hap_resource.h b/frameworks/resmgr_lite/include/hap_resource.h index 007b8990d5bbabf5ce1095dfd9ba21b30aa9fc48..59397a1b08122283edc6d84974f5d552a9a0a15c 100644 --- a/frameworks/resmgr_lite/include/hap_resource.h +++ b/frameworks/resmgr_lite/include/hap_resource.h @@ -15,12 +15,12 @@ #ifndef RESOURCE_MANAGER_HAPRESOURCE_H #define RESOURCE_MANAGER_HAPRESOURCE_H -#include "res_desc.h" -#include "res_config_impl.h" #include #include #include #include +#include "res_desc.h" +#include "res_config_impl.h" namespace OHOS { namespace Global { @@ -43,20 +43,29 @@ public: */ static const HapResource *LoadFromIndex(const char *path, const ResConfigImpl *defaultConfig, bool system = false); + /** + * The destructor of HapResource + */ ~HapResource(); + /** + * Get the resource.index file path + */ inline const std::string GetIndexPath() const { return indexPath_; } + /** + * Get the resource path + */ inline const std::string GetResourcePath() const { return resourcePath_; } /** - * describe limitpath and value under the path + * Describe limitpath and value under the path */ class ValueUnderQualifierDir { public: @@ -133,10 +142,27 @@ public: std::vector limitPaths_; }; + /** + * Get the resource value by resource id + * @param id the resource id + * @return the resource value related to id + */ const IdValues *GetIdValues(const uint32_t id) const; + /** + * Get the resource value by resource name + * @param name the resource name + * @param resType the resource type + * @return the resource value related to resource name + */ const IdValues *GetIdValuesByName(const std::string name, const ResType resType) const; + /** + * Get the resource id by resource name + * @param name the resource name + * @param resType the resource type + * @return the resource id related to resource name + */ int GetIdByName(const char *name, const ResType resType) const; size_t IdSize() const diff --git a/frameworks/resmgr_lite/include/locale_matcher.h b/frameworks/resmgr_lite/include/locale_matcher.h index 4e92c9226a71ab1d409b2f04dfb195a4d8a00a41..e997b98e455835eb5caa5c8d665ead8b05db5765 100644 --- a/frameworks/resmgr_lite/include/locale_matcher.h +++ b/frameworks/resmgr_lite/include/locale_matcher.h @@ -25,16 +25,52 @@ public: const ResLocale *other, const ResLocale *request); + /** + * Whether the current ResLocale same to the other ResLocale + * @param current the current ResLocale + * @param other the other ResLocale + * @return true if the current ResLocale same to the other ResLocale, else false + */ static bool Match(const ResLocale *current, const ResLocale *other); + /** + * Whether the string is the language tag + * @param str the tag string + * @param len the tag length + * @return true if the str is language tag, else false + */ static bool IsLanguageTag(const char *str, int32_t len); + /** + * Whether the string is the script tag + * @param str the tag string + * @param len the tag length + * @return true if the str is script tag, else false + */ static bool IsScriptTag(const char *str, int32_t len); + /** + * Whether the string is the Region tag + * @param str the tag string + * @param len the tag length + * @return true if the str is Region tag, else false + */ static bool IsRegionTag(const char *str, int32_t len); + /** + * Get the resLocale script + * @param resLocale the resLocale infomation + * @return true if get the resLocale script, else false + */ static bool Normalize(ResLocale *resLocale); + /** + * Whether the current resLocale more specific than target resLocale + * @param current the current resLocale + * @param target the target resLocale + * @return 0 means current resLocale same to target resLocale, + * 1 means current resLocale more specific than target resLocale, else -1 + */ static int8_t IsMoreSpecificThan(const ResLocale *current, const ResLocale *target); public: diff --git a/frameworks/resmgr_lite/include/lock.h b/frameworks/resmgr_lite/include/lock.h index d200f07e7d19e267f67bf24dffadb822e43a97e7..a1414d0bf1304bf6e41e587bbeaadac1d9a23ce6 100644 --- a/frameworks/resmgr_lite/include/lock.h +++ b/frameworks/resmgr_lite/include/lock.h @@ -31,6 +31,8 @@ public: private: std::mutex* mtx_; + + Lock(const Lock &src) = delete; }; } // namespace Resource } // namespace Global diff --git a/frameworks/resmgr_lite/include/res_common.h b/frameworks/resmgr_lite/include/res_common.h index f846876813c032338db1661ae9dbc30b22985076..a3e93ffbee53c7a16a3dae968e657dca8a191835 100644 --- a/frameworks/resmgr_lite/include/res_common.h +++ b/frameworks/resmgr_lite/include/res_common.h @@ -16,8 +16,6 @@ #ifndef OHOS_RES_COMMON_H #define OHOS_RES_COMMON_H -#include - namespace OHOS { namespace Global { namespace Resource { @@ -29,7 +27,7 @@ static const char *HORIZONTAL = "horizontal"; static const char *PHONE_STR = "phone"; static const char *TABLET_STR = "tablet"; static const char *CAR_STR = "car"; -static const char *PC_STR = "pc"; +static const char *PAD_STR = "pad"; static const char *TV_STR = "tv"; static const char *WEARABLE_STR = "wearable"; @@ -90,7 +88,7 @@ enum DeviceType { DEVICE_PHONE = 0, DEVICE_TABLET = 1, DEVICE_CAR = 2, - DEVICE_PC = 3, + DEVICE_PAD = 3, DEVICE_TV = 4, DEVICE_WEARABLE = 6, }; diff --git a/frameworks/resmgr_lite/include/res_config_impl.h b/frameworks/resmgr_lite/include/res_config_impl.h index c8ca03ce6f44288fe9c8f94b1c7b3c01d1bfc2fa..7cf6671f99771be41a9df8ddf869840ba2127351 100644 --- a/frameworks/resmgr_lite/include/res_config_impl.h +++ b/frameworks/resmgr_lite/include/res_config_impl.h @@ -29,16 +29,46 @@ class ResConfigImpl : public ResConfig { public: ResConfigImpl(); + /** + * Whether this resConfig more match request resConfig + * @param other the other resConfig + * @param request the request resConfig + * @return true if this resConfig more match request resConfig than other resConfig, else false + */ bool IsMoreSuitable(const ResConfigImpl *other, const ResConfigImpl *request) const; + /** + * Set locale information + * @param language the locale language + * @param script the locale script + * @param region the locale region + * @return SUCCESS if set locale information success, else false + */ RState SetLocaleInfo(const char *language, const char *script, const char *region); - + + /** + * Set locale information + * @param localeInfo the localeInfo + * @return SUCCESS if set locale information success, else false + */ RState SetLocaleInfo(LocaleInfo &localeInfo); + /** + * Set resConfig device type + * @param deviceType the device type + */ void SetDeviceType(DeviceType deviceType); + /** + * Set resConfig direction + * @param direction the resConfig direction + */ void SetDirection(Direction direction); + /** + * Set resConfig screenDensity + * @param screenDensity the resConfig screenDensity + */ void SetScreenDensity(ScreenDensity screenDensity); const LocaleInfo *GetLocaleInfo() const; @@ -51,12 +81,29 @@ public: DeviceType GetDeviceType() const; + /** + * Whether this resConfig match other resConfig + * @param other the other resConfig + * @return true if this resConfig match other resConfig, else false + */ bool Match(const ResConfigImpl *other) const; + /** + * Copy other resConfig to this resConfig + * @param other the other resConfig + * @return true if copy other resConfig to this resConfig success, else false + */ bool Copy(ResConfig &other); + /** + * Complete the local script + */ void CompleteScript(); + /** + * Whether this resLocal script completed + * @return true if resLocal script completed, else false + */ bool IsCompletedScript() const; virtual ~ResConfigImpl(); diff --git a/frameworks/resmgr_lite/include/res_desc.h b/frameworks/resmgr_lite/include/res_desc.h index 18cdb6f3daf9505d4de915cd264589b1a09e6bc3..f335659afd77da22c062fbe94b7db4a1a9e9b82f 100644 --- a/frameworks/resmgr_lite/include/res_desc.h +++ b/frameworks/resmgr_lite/include/res_desc.h @@ -16,11 +16,11 @@ #ifndef OHOS_RESOURCE_MANAGER_RES_DESC_H #define OHOS_RESOURCE_MANAGER_RES_DESC_H -#include "res_common.h" #include #include #include #include +#include "res_common.h" namespace OHOS { namespace Global { @@ -48,6 +48,11 @@ class IdItem { public: static const uint32_t HEADER_LEN = 12; + /** + * Whether the resType is array or not + * @param type the resType + * @return true if the resType is array, else false + */ static bool IsArrayOfType(ResType type) { if (type == ResType::STRINGARRAY || type == ResType::INTARRAY || type == ResType::THEME || diff --git a/frameworks/resmgr_lite/include/res_locale.h b/frameworks/resmgr_lite/include/res_locale.h index 832eb7c335d5cef15676eeb17507bed45764f704..0851727345862c98e5551cffbdf7a40714b8b767 100644 --- a/frameworks/resmgr_lite/include/res_locale.h +++ b/frameworks/resmgr_lite/include/res_locale.h @@ -45,16 +45,41 @@ public: ResLocale(); + /** + * Copy from other LocaleInfo to this + * @param other the other LocaleInfo copy to this localeInfo + * @return SUCCESS if copy other LocaleInfo success, else ERROR + */ RState CopyFromLocaleInfo(const LocaleInfo *other); + /** + * Copy from other ResLocale to this + * @param other the other ResLocale copy to this ResLocale + * @return SUCCESS if copy other ResLocale success, else ERROR + */ RState Copy(const ResLocale *other); static const LocaleInfo *GetDefault(); static bool UpdateDefault(const LocaleInfo &localeInfo, bool needNotify); + /** + * Build resLocal from string + * @param bcp47String the target string + * @param sep the parse string position + * @param rState the parse status + * @return the resLocal after parse bcp47String + */ static ResLocale *BuildFromString(const char *bcp47String, char sep, RState &rState); + /** + * Build resLocal from parts + * @param language the resLocal language + * @param script the resLocal script + * @param region the resLocal region + * @param rState the Build status + * @return the resLocal after Build resLocal from parts if success, else return nullptr + */ static ResLocale *BuildFromParts(const char *language, const char *script, const char *region, RState &rState); ~ResLocale(); diff --git a/frameworks/resmgr_lite/include/resource_manager.h b/frameworks/resmgr_lite/include/resource_manager.h index 560fc84bffaf7aa7202763b6c685d37eac2d9c29..940cd9d17a3c7253038f01788889cad5cafba253 100644 --- a/frameworks/resmgr_lite/include/resource_manager.h +++ b/frameworks/resmgr_lite/include/resource_manager.h @@ -15,10 +15,10 @@ #ifndef OHOS_RESOURCE_MANAGER_RESOURCEMANAGER_H #define OHOS_RESOURCE_MANAGER_RESOURCEMANAGER_H -#include "res_config.h" #include #include #include +#include "res_config.h" namespace OHOS { namespace Global { diff --git a/frameworks/resmgr_lite/include/resource_manager_impl.h b/frameworks/resmgr_lite/include/resource_manager_impl.h index 6070a8871f2159a72e010afe3488df26cd71b282..3fba09bbe2f3ceeb19ce602baacb5a97be4c33d1 100644 --- a/frameworks/resmgr_lite/include/resource_manager_impl.h +++ b/frameworks/resmgr_lite/include/resource_manager_impl.h @@ -15,11 +15,11 @@ #ifndef OHOS_RESOURCE_MANAGER_RESOURCEMANAGERIMPL_H #define OHOS_RESOURCE_MANAGER_RESOURCEMANAGERIMPL_H -#include "hap_manager.h" -#include "resource_manager.h" #include #include #include +#include "hap_manager.h" +#include "resource_manager.h" namespace OHOS { namespace Global { @@ -32,66 +32,252 @@ public: bool Init(); + /** + * Add resource path to hap paths + * @param path the resource path + * @return true if add resource path success, else false + */ virtual bool AddResource(const char *path); + /** + * Update the resConfig + * @param resConfig the resource config + * @return the resConfig after update + */ virtual RState UpdateResConfig(ResConfig &resConfig); + /** + * Get the resConfig + * @param resConfig the resource config + */ virtual void GetResConfig(ResConfig &resConfig); + /** + * Get string resource by id + * @param id the resource id + * @param outValue the string resource write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ virtual RState GetStringById(uint32_t id, std::string &outValue); + /** + * Get string by resource name + * @param name the resource name + * @param outValue the resource write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ virtual RState GetStringByName(const char *name, std::string &outValue); + /** + * Get formatstring by resource id + * @param id the resource id + * @param outValue the resource write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ virtual RState GetStringFormatById(std::string &outValue, uint32_t id, ...); + /** + * Get formatstring by resource name + * @param name the resource name + * @param outValue the resource write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ virtual RState GetStringFormatByName(std::string &outValue, const char *name, ...); + /** + * Get the STRINGARRAY 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 GetStringArrayById(uint32_t id, std::vector &outValue); + /** + * Get the STRINGARRAY 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 GetStringArrayByName(const char *name, std::vector &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 GetPatternById(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 GetPatternByName(const char *name, std::map &outValue); + /** + * Get the plural string by resource id + * @param id the resource id + * @param quantity the language quantity + * @param outValue the resource write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ virtual RState GetPluralStringById(uint32_t id, int quantity, std::string &outValue); + /** + * Get the plural string by resource name + * @param name the resource name + * @param quantity the language quantity + * @param outValue the resource write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ virtual RState GetPluralStringByName(const char *name, int quantity, std::string &outValue); + /** + * Get the plural format string by resource id + * @param outValue the resource write to + * @param id the resource id + * @param quantity the language quantity + * @return SUCCESS if resource exist, else NOT_FOUND + */ virtual RState GetPluralStringByIdFormat(std::string &outValue, uint32_t id, int quantity, ...); + /** + * Get the plural format string by resource name + * @param outValue the resource write to + * @param id the resource id + * @param quantity the language quantity + * @return SUCCESS if resource exist, else NOT_FOUND + */ virtual RState GetPluralStringByNameFormat(std::string &outValue, const char *name, int quantity, ...); + /** + * 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 GetThemeById(uint32_t id, std::map &outValue); + /** + * 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 GetThemeByName(const char *name, std::map &outValue); + /** + * Get the BOOLEAN resource by resource id + * @param id the resource id + * @param outValue the obtain boolean value write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ virtual RState GetBooleanById(uint32_t id, bool &outValue); + /** + * Get the BOOLEAN resource by resource name + * @param name the resource name + * @param outValue the obtain boolean value write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ virtual RState GetBooleanByName(const char *name, bool &outValue); + /** + * Get the INTEGER resource by resource id + * @param id the resource id + * @param outValue the obtain Integer value write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ virtual RState GetIntegerById(uint32_t id, int &outValue); + /** + * Get the INTEGER resource by resource name + * @param name the resource name + * @param outValue the obtain Integer value write to + * @return SUCCESS if resource path exist, else NOT_FOUND + */ virtual RState GetIntegerByName(const char *name, int &outValue); + /** + * Get the FLOAT resource by resource id + * @param id the resource id + * @param outValue the obtain float value write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ virtual RState GetFloatById(uint32_t id, float &outValue); + /** + * Get the FLOAT resource by resource name + * @param name the resource name + * @param outValue the obtain float value write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ virtual RState GetFloatByName(const char *name, float &outValue); + /** + * Get the INTARRAY resource by resource id + * @param id the resource id + * @param outValue the obtain resource value convert to vector write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ virtual RState GetIntArrayById(uint32_t id, std::vector &outValue); + /** + * Get the NTARRAY resource by resource name + * @param name the resource name + * @param outValue the obtain resource value convert to vector write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ virtual RState GetIntArrayByName(const char *name, std::vector &outValue); + /** + * Get the COLOR resource by resource id + * @param id the resource id + * @param outValue the obtain resource value convert to uint32_t write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ virtual RState GetColorById(uint32_t id, uint32_t &outValue); + /** + * Get the COLOR resource by resource name + * @param name the resource name + * @param outValue the obtain resource value convert to uint32_t write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ virtual RState GetColorByName(const char *name, uint32_t &outValue); + /** + * Get the PROF resource by resource id + * @param id the resource id + * @param outValue the obtain resource path write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ virtual RState GetProfileById(uint32_t id, std::string &outValue); + /** + * Get the PROF resource by resource name + * @param name the resource name + * @param outValue the obtain resource path write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ virtual RState GetProfileByName(const char *name, std::string &outValue); + /** + * Get the MEDIA resource by resource id + * @param id the resource id + * @param outValue the obtain resource path write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ virtual RState GetMediaById(uint32_t id, std::string &outValue); + /** + * Get the MEDIA resource by resource name + * @param name the resource name + * @param outValue the obtain resource path write to + * @return SUCCESS if resource exist, else NOT_FOUND + */ virtual RState GetMediaByName(const char *name, std::string &outValue); private: diff --git a/frameworks/resmgr_lite/include/rstate.h b/frameworks/resmgr_lite/include/rstate.h index 310a3c8d18a9e5b532b0210e57ad9bf5f52eb514..f9a3213b45f67678def1a9056ce424adaa1bad88 100644 --- a/frameworks/resmgr_lite/include/rstate.h +++ b/frameworks/resmgr_lite/include/rstate.h @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #ifndef OHOS_RESOURCE_MANAGER_RSTATE_H #define OHOS_RESOURCE_MANAGER_RSTATE_H diff --git a/frameworks/resmgr_lite/include/utils/date_utils.h b/frameworks/resmgr_lite/include/utils/date_utils.h index 88024ae7f36aed32731e03f25b98310624d8138a..3937ca14586643af2398d1c462a231972d8a7e27 100644 --- a/frameworks/resmgr_lite/include/utils/date_utils.h +++ b/frameworks/resmgr_lite/include/utils/date_utils.h @@ -17,8 +17,6 @@ #define RESOURCE_MANAGER_DATEUTILS_H #include -#include - #include "common.h" namespace OHOS { diff --git a/frameworks/resmgr_lite/src/global.c b/frameworks/resmgr_lite/src/global.c index c132ff7fc4fe7499a0f3797863f8d82e495440e9..cf86ef01bfd884fe341cfd07828256a072fc87a4 100644 --- a/frameworks/resmgr_lite/src/global.c +++ b/frameworks/resmgr_lite/src/global.c @@ -24,6 +24,7 @@ #include #include "global_utils.h" +#include "hilog_wrapper.h" /* * locale format as below, use '-' or '_' to link, e.g. en_Latn_US @@ -35,6 +36,7 @@ #define MAX_LOCALE_LENGTH 13 #define UI_LOCALE_ELEMENT_NUM 2 +#define MAX_SCRIPT_LENGTH 5 static char g_locale[MAX_LOCALE_LENGTH] = {0}; void GLOBAL_ConfigLanguage(const char *appLanguage) @@ -72,6 +74,39 @@ int32_t GLOBAL_GetLanguage(char *language, uint8_t len) return (strncpy_s(language, len, localeArray[0], MAX_LANGUAGE_LENGTH - 1) != EOK) ? MC_FAILURE : MC_SUCCESS; } +int32_t GLOBAL_IsRTL(void) +{ + char *localeArray[LOCALE_ELEMENT_NUM] = { NULL }; + char tempLocale[MAX_LOCALE_LENGTH] = { '\0' }; + int32_t ret = strcpy_s(tempLocale, MAX_LOCALE_LENGTH, g_locale); + if (ret != EOK) { + return 0; + } + int32_t count = 0; + ret = GetGlobalUtilsImpl()->SplitLocale(tempLocale, localeArray, &count); + if (ret == MC_FAILURE || count != UI_LOCALE_ELEMENT_NUM) { + return 0; + } + char script[MAX_SCRIPT_LENGTH] = { 0 }; + if (strncpy_s(script, MAX_SCRIPT_LENGTH, localeArray[1], MAX_SCRIPT_LENGTH - 1) != EOK) { + return 0; + } + // if script is set and script != arab or script != hebr, return false; + if ((strlen(script) == MAX_SCRIPT_LENGTH - 1) && + (strcmp(script, "Arab") != 0) && (strcmp(script, "Hebr") != 0)) { + return 0; + } + char language[MAX_LANGUAGE_LENGTH] = { 0 }; + if (strncpy_s(language, MAX_LANGUAGE_LENGTH, localeArray[0], MAX_LANGUAGE_LENGTH - 1) != EOK) { + return 0; + } + if ((strcmp(language, "fa") == 0) || (strcmp(language, "ar") == 0) || (strcmp(language, "ur") == 0) || + (strcmp(language, "ug") == 0) || (strcmp(language, "he") == 0) || (strcmp(language, "iw") == 0)) { + return 1; + } + return 0; +} + int32_t GLOBAL_GetRegion(char *region, uint8_t len) { if (region == NULL || len == 0) { @@ -112,93 +147,106 @@ static void FreeValue(char **value) } } -int32_t GLOBAL_GetValueById(uint32_t id, const char *path, char **value) +static int32_t GLOBAL_GetValueByIdInternal(uint32_t id, const char *path, const char *locale, char **value) { - if (path == NULL || path[0] == '\0' || value == NULL) { - return MC_FAILURE; - } - - char tempLocale[MAX_LOCALE_LENGTH] = {'\0'}; - int32_t ret = strcpy_s(tempLocale, MAX_LOCALE_LENGTH, g_locale); - if (ret != EOK) { - return MC_FAILURE; - } - char realResourcePath[PATH_MAX] = {'\0'}; GlobalUtilsImpl *utilsImpl = GetGlobalUtilsImpl(); if (utilsImpl->CheckFilePath(path, realResourcePath, PATH_MAX) == MC_FAILURE) { + HILOG_ERROR("GLOBAL_GetValueByIdInternal failed to check file %s", path); return MC_FAILURE; } - uint32_t idHeaderOffset = utilsImpl->GetOffsetByLocale(realResourcePath, tempLocale, MAX_LOCALE_LENGTH); + uint32_t idHeaderOffset = utilsImpl->GetOffsetByLocale(realResourcePath, locale, MAX_LOCALE_LENGTH); IdHeader idHeader = {0, NULL}; int32_t file = open(realResourcePath, O_RDONLY, S_IRUSR | S_IRGRP | S_IROTH); if (file < 0) { + HILOG_ERROR("GLOBAL_GetValueByIdInternal failed to open file %s", realResourcePath); return MC_FAILURE; } - ret = utilsImpl->GetIdHeaderByOffset(file, idHeaderOffset, &idHeader); + int32_t ret = utilsImpl->GetIdHeaderByOffset(file, idHeaderOffset, &idHeader); if (ret != MC_SUCCESS) { + HILOG_ERROR("GLOBAL_GetValueByIdInternal failed to git id header by offset %u", idHeaderOffset); close(file); return ret; } + int32_t result = MC_FAILURE; IdItem idItem = {0, INVALID_RES_TYPE, 0, 0, NULL, 0, NULL}; for (uint32_t i = 0; i < idHeader.count; i++) { if (idHeader.idParams[i].id == id) { - int32_t ret = utilsImpl->GetIdItem(file, idHeader.idParams[i].offset, &idItem); + ret = utilsImpl->GetIdItem(file, idHeader.idParams[i].offset, &idItem); if (ret != MC_SUCCESS) { + HILOG_ERROR("GLOBAL_GetValueByIdInternal failed to get id item. ret: %d", ret); close(file); free(idHeader.idParams); return ret; } *value = (char *)malloc(idItem.valueLen); if (*value == NULL || strcpy_s(*value, idItem.valueLen, idItem.value) != EOK) { + HILOG_ERROR("GLOBAL_GetValueByIdInternal failed to copy id item value %s", idItem.value); close(file); free(idHeader.idParams); FreeIdItem(&idItem); FreeValue(value); return MC_FAILURE; } + result = MC_SUCCESS; break; } } close(file); free(idHeader.idParams); FreeIdItem(&idItem); - return MC_SUCCESS; + return result; } -int32_t GLOBAL_GetValueByName(const char *name, const char *path, char **value) +int32_t GLOBAL_GetValueById(uint32_t id, const char *path, char **value) { - if (name == NULL || strlen(name) == 0 || path == NULL || strlen(path) == 0 || value == NULL) { + if (path == NULL || path[0] == '\0' || value == NULL) { + HILOG_ERROR("GLOBAL_GetValueById input params invalid"); return MC_FAILURE; } char tempLocale[MAX_LOCALE_LENGTH] = {'\0'}; int32_t ret = strcpy_s(tempLocale, MAX_LOCALE_LENGTH, g_locale); if (ret != EOK) { + HILOG_ERROR("GLOBAL_GetValueById failed to copy g_locale %s", g_locale); return MC_FAILURE; } + + char *locales[] = {tempLocale, ""}; + for (int i = 0; i < 2; i++) { // 2 current language and the default. + if (GLOBAL_GetValueByIdInternal(id, path, locales[i], value) == MC_SUCCESS) { + return MC_SUCCESS; + } + } + HILOG_ERROR("GLOBAL_GetValueById failed to get value by id internal, id:%u, path:%s, tempLocale:%s", id, path, tempLocale); + return MC_FAILURE; +} + +static int32_t GLOBAL_GetValueByNameInternal(const char *name, const char *path, const char *locale, char **value) +{ char realResourcePath[PATH_MAX] = {'\0'}; GlobalUtilsImpl *utilsImpl = GetGlobalUtilsImpl(); if (utilsImpl->CheckFilePath(path, realResourcePath, PATH_MAX) == MC_FAILURE) { return MC_FAILURE; } - uint32_t idHeaderOffset = utilsImpl->GetOffsetByLocale(realResourcePath, tempLocale, MAX_LOCALE_LENGTH); + uint32_t idHeaderOffset = utilsImpl->GetOffsetByLocale(realResourcePath, locale, MAX_LOCALE_LENGTH); IdHeader idHeader = {0, NULL}; int32_t file = open(realResourcePath, O_RDONLY, S_IRUSR | S_IRGRP | S_IROTH); if (file < 0) { return MC_FAILURE; } - ret = utilsImpl->GetIdHeaderByOffset(file, idHeaderOffset, &idHeader); + int32_t ret = utilsImpl->GetIdHeaderByOffset(file, idHeaderOffset, &idHeader); if (ret != MC_SUCCESS) { close(file); return ret; } + int32_t result = MC_FAILURE; IdItem idItem = {0, INVALID_RES_TYPE, 0, 0, NULL, 0, NULL}; for (uint32_t i = 0; i < idHeader.count; i++) { - int32_t ret = utilsImpl->GetIdItem(file, idHeader.idParams[i].offset, &idItem); + ret = utilsImpl->GetIdItem(file, idHeader.idParams[i].offset, &idItem); if (ret != MC_SUCCESS) { close(file); free(idHeader.idParams); @@ -216,11 +264,33 @@ int32_t GLOBAL_GetValueByName(const char *name, const char *path, char **value) FreeValue(value); return MC_FAILURE; } + result = MC_SUCCESS; break; } close(file); free(idHeader.idParams); FreeIdItem(&idItem); - return MC_SUCCESS; + return result; +} + +int32_t GLOBAL_GetValueByName(const char *name, const char *path, char **value) +{ + if (name == NULL || strlen(name) == 0 || path == NULL || strlen(path) == 0 || value == NULL) { + return MC_FAILURE; + } + + char tempLocale[MAX_LOCALE_LENGTH] = {'\0'}; + int32_t ret = strcpy_s(tempLocale, MAX_LOCALE_LENGTH, g_locale); + if (ret != EOK) { + return MC_FAILURE; + } + + char *locales[] = {tempLocale, ""}; + for (int i = 0; i < 2; i++) { // 2 current language and the default. + if (GLOBAL_GetValueByNameInternal(name, path, locales[i], value) == MC_SUCCESS) { + return MC_SUCCESS; + } + } + return MC_FAILURE; } diff --git a/frameworks/resmgr_lite/src/global.cpp b/frameworks/resmgr_lite/src/global.cpp index db0dc1a96ce78874e07ad9da642f207794db9317..a66a833c61b74deb8c38d8a27b851f5b02f12ae5 100644 --- a/frameworks/resmgr_lite/src/global.cpp +++ b/frameworks/resmgr_lite/src/global.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -119,20 +119,23 @@ int32_t GLOBAL_GetRegion(char *region, uint8_t len) int32_t GetValue(const IdItem *idItem, char **value) { + if (idItem == nullptr) { + return SYS_ERROR; + } if (idItem->isArray_) { std::string ret("["); for (size_t i = 0; i < idItem->values_.size(); ++i) { ret.append(FormatString("'%s',", idItem->values_[i].c_str())); } ret.append("]"); - *value = (char *)malloc(ret.size() + 1); + *value = static_cast(malloc(ret.size() + 1)); if (*value == nullptr || strcpy_s(*value, ret.size() + 1, ret.c_str()) != EOK) { FreeValue(value); return SYS_ERROR; } (*value)[ret.size()] = '\0'; } else { - *value = (char *)malloc(idItem->valueLen_ + 1); + *value = static_cast(malloc(idItem->valueLen_ + 1)); if (*value == nullptr || strcpy_s(*value, idItem->valueLen_ + 1, idItem->value_.c_str()) != EOK) { FreeValue(value); return SYS_ERROR; diff --git a/frameworks/resmgr_lite/src/global_utils.c b/frameworks/resmgr_lite/src/global_utils.c index 64f54ec6785020b28ef6c25adb8a38aa7c4711ee..f052d9a13e24cb351d93e77e8ca0ed7ab1ed2cb0 100644 --- a/frameworks/resmgr_lite/src/global_utils.c +++ b/frameworks/resmgr_lite/src/global_utils.c @@ -27,8 +27,10 @@ #include #include +#include "hilog_wrapper.h" + #define MAX_ID_ITEM_NUM 0x7F -#define MAX_RES_CONFIG_NUM 0x10 +#define MAX_RES_CONFIG_NUM 0xFFFF #define MAX_ITEM_LENGTH 0xFF enum LocaleIndex { @@ -76,14 +78,15 @@ static int32_t Split(const char *src, const char *separator, char **dest, int32_ if (src == NULL || src[0] == '\0' || separator == NULL || separator[0] == '\0' || dest == NULL || num == NULL) { return MC_FAILURE; } - next = strtok((char *)src, separator); + char *temp = NULL; + next = strtok_r((char *)src, separator, &temp); while (next != NULL) { if (count >= LOCALE_ELEMENT_NUM) { return MC_FAILURE; } *dest++ = next; ++count; - next = strtok(NULL, separator); + next = strtok_r(NULL, separator, &temp); } *num = count; return MC_SUCCESS; @@ -257,6 +260,7 @@ static uint32_t FindOffsetByAllParam(char **resConfig, const Key *keys, uint32_t static uint32_t GetIdHeaderOffsetByCount(char **resConfig, const Key *keys, uint32_t configNum, int32_t count) { if (resConfig == NULL || keys == NULL) { + HILOG_ERROR("GetIdHeaderOffsetByCount resConfig or keys is null"); return INVALID_OFFSET; } uint32_t offset = INVALID_OFFSET; @@ -293,12 +297,14 @@ static void FreeKeyParams(Key *keys, int32_t count) static int32_t GetKeyParams(int32_t file, Key *keys, uint32_t resConfigNum) { if (file < 0 || keys == NULL) { + HILOG_ERROR("GetKeyParams file negative or keys is null"); return MC_FAILURE; } g_defaultIdHeaderOffset = INVALID_OFFSET; for (uint32_t i = 0; i < resConfigNum; ++i) { int seekRet = lseek(file, INDEX_DEFAULT_OFFSET, SEEK_CUR); // skip the "KEYS" header if (seekRet < 0) { + HILOG_ERROR("GetKeyParams file %d seek failed, seekRet: %d", file, seekRet); FreeKeyParams(keys, i); return MC_FAILURE; } @@ -309,11 +315,13 @@ static int32_t GetKeyParams(int32_t file, Key *keys, uint32_t resConfigNum) continue; } if (keys[i].keysCount > KEY_TYPE_MAX) { + HILOG_ERROR("GetKeyParams keysCount %u invalid, i: %u", keys[i].keysCount, i); FreeKeyParams(keys, i); return MC_FAILURE; } keys[i].keyParams = (KeyParam *)malloc(sizeof(KeyParam) * keys[i].keysCount); if (keys[i].keyParams == NULL) { + HILOG_ERROR("GetKeyParams keyParams is null, i: %u", i); FreeKeyParams(keys, i); return MC_FAILURE; } @@ -328,21 +336,25 @@ static int32_t GetKeyParams(int32_t file, Key *keys, uint32_t resConfigNum) static int32_t CheckFilePath(const char *path, char *realResourcePath, int32_t length) { if (length > PATH_MAX || length < 0) { + HILOG_ERROR("CheckFilePath length %d invalid", length); return MC_FAILURE; } #if (defined(_WIN32) || defined(_WIN64)) if (!PathCanonicalizeA((char*)path, realResourcePath)) { + HILOG_ERROR("CheckFilePath path %s canonicalize failed", path); return MC_FAILURE; } return MC_SUCCESS; #elif defined(I18N_PRODUCT) int ret = strcpy_s(realResourcePath, PATH_MAX, path); if (ret != 0) { + HILOG_ERROR("CheckFilePath path %s copy failed", path); return MC_FAILURE; } return MC_SUCCESS; #else if (realpath(path, realResourcePath) == NULL) { + HILOG_ERROR("CheckFilePath path %s realpath failed, realResourcePath %s", path, realResourcePath); return MC_FAILURE; } return MC_SUCCESS; @@ -352,40 +364,48 @@ static int32_t CheckFilePath(const char *path, char *realResourcePath, int32_t l static uint32_t GetOffsetByLocale(const char *path, const char *locale, uint32_t length) { if (path == NULL || strlen(path) == 0 || locale == NULL || length == 0) { + HILOG_ERROR("GetOffsetByLocale input params invalid"); return INVALID_OFFSET; } char realResourcePath[PATH_MAX] = {0}; if (CheckFilePath(path, realResourcePath, PATH_MAX) == MC_FAILURE) { + HILOG_ERROR("GetOffsetByLocale check file path %s failed", path); return INVALID_OFFSET; } int32_t file = open(realResourcePath, O_RDONLY, S_IRUSR | S_IRGRP | S_IROTH); if (file < 0) { + HILOG_ERROR("GetOffsetByLocale open file %s failed", realResourcePath); return INVALID_OFFSET; } int seekRet = lseek(file, RES_CONFIG_NUM_OFFSET, SEEK_SET); // goto resConfigNum index, now is fixed at 132 if (seekRet < 0) { + HILOG_ERROR("GetOffsetByLocale file %s seek failed, seekRet: %d", realResourcePath, seekRet); close(file); return INVALID_OFFSET; } uint32_t resConfigNum = GetDefaultOffsetValue(file); if (resConfigNum == 0 || resConfigNum > MAX_RES_CONFIG_NUM) { + HILOG_ERROR("GetOffsetByLocale file %s get default offset value failed, resConfigNum: %u", realResourcePath, resConfigNum); close(file); return INVALID_OFFSET; } int size = sizeof(Key) * resConfigNum; Key *keys = (Key *)malloc(size); if (keys == NULL) { + HILOG_ERROR("GetOffsetByLocale keys is null, resConfigNum: %u", resConfigNum); close(file); return INVALID_OFFSET; } (void)memset_s(keys, size, 0, size); int32_t ret = GetKeyParams(file, keys, resConfigNum); if (ret != MC_SUCCESS) { + HILOG_ERROR("GetOffsetByLocale get key params failed, ret: %d", ret); close(file); free(keys); return INVALID_OFFSET; } close(file); + HILOG_INFO("GetOffsetByLocale locale: %s, resConfigNum: %d", locale, resConfigNum); uint32_t offset = GetIdHeaderOffsetByLocale(locale, keys, resConfigNum); if (offset == INVALID_OFFSET) { offset = g_defaultIdHeaderOffset; @@ -398,11 +418,13 @@ static uint32_t GetOffsetByLocale(const char *path, const char *locale, uint32_t static uint32_t GetDefaultOffsetValue(int32_t file) { if (file < 0) { + HILOG_ERROR("GetDefaultOffsetValue file %d negative", file); return 0; } uint8_t cache[INDEX_DEFAULT_OFFSET] = {0}; int32_t ret = read(file, cache, INDEX_DEFAULT_OFFSET); if (ret != INDEX_DEFAULT_OFFSET) { + HILOG_ERROR("GetDefaultOffsetValue file %d read failed, ret: %d", file, ret); return 0; } return ConvertUint8ArrayToUint32(cache, INDEX_DEFAULT_OFFSET); @@ -424,12 +446,14 @@ static uint32_t GetKeyValue(int32_t file) static int32_t GetIdItem(int32_t file, uint32_t offset, IdItem *idItem) { if (offset == INVALID_OFFSET || file == -1 || idItem == NULL) { + HILOG_ERROR("GetIdItem input params invalid"); return MC_FAILURE; } uint8_t defaultCache[INDEX_DEFAULT_OFFSET] = {0}; uint8_t lengthCache[VALUE_LENGTH_OFFSET] = {0}; int seekRet = lseek(file, offset, SEEK_SET); if (seekRet < 0) { + HILOG_ERROR("GetIdItem file %d seek failed, seekRet: %d", file, seekRet); return MC_FAILURE; } (void)read(file, defaultCache, INDEX_DEFAULT_OFFSET); @@ -444,19 +468,23 @@ static int32_t GetIdItem(int32_t file, uint32_t offset, IdItem *idItem) (void)read(file, lengthCache, VALUE_LENGTH_OFFSET); idItem->valueLen = (uint16_t)ConvertUint8ArrayToUint32(lengthCache, VALUE_LENGTH_OFFSET); if (idItem->valueLen == 0 || idItem->valueLen > MAX_ITEM_LENGTH) { + HILOG_ERROR("GetIdItem idItem valueLen %u invalid", idItem->valueLen); return MC_FAILURE; } idItem->value = (char *)malloc(idItem->valueLen); if (idItem->value == NULL) { + HILOG_ERROR("GetIdItem idItem value is null"); return MC_FAILURE; } + HILOG_INFO("GetIdItem file: %d, idItem->value: %s, idItem->valueLen: %u", file, idItem->value, idItem->valueLen); (void)memset_s(idItem->value, idItem->valueLen, 0, idItem->valueLen); (void)read(file, idItem->value, idItem->valueLen); (void)read(file, lengthCache, VALUE_LENGTH_OFFSET); idItem->nameLen = (uint16_t)ConvertUint8ArrayToUint32(lengthCache, VALUE_LENGTH_OFFSET); if (idItem->nameLen == 0 || idItem->nameLen > MAX_ITEM_LENGTH) { + HILOG_ERROR("GetIdItem idItem nameLen %u invalid", idItem->nameLen); free(idItem->value); idItem->value = NULL; return MC_FAILURE; @@ -464,10 +492,12 @@ static int32_t GetIdItem(int32_t file, uint32_t offset, IdItem *idItem) idItem->name = (char *)malloc(idItem->nameLen); if (idItem->name == NULL) { + HILOG_ERROR("GetIdItem idItem name is null"); free(idItem->value); idItem->value = NULL; return MC_FAILURE; } + HILOG_INFO("GetIdItem file: %d, idItem->name: %s, idItem->nameLen: %u", file, idItem->name, idItem->nameLen); (void)memset_s(idItem->name, idItem->nameLen, 0, idItem->nameLen); (void)read(file, idItem->name, idItem->nameLen); @@ -487,6 +517,7 @@ static uint32_t GetIdHeaderOffsetByLocale(const char *locale, const Key *keys, u (void)Split(locale, "_", resConfig, &count); } else { resConfig[0] = (char *)locale; + count = 1; } return GetIdHeaderOffsetByCount(resConfig, keys, configNum, count); } @@ -494,18 +525,22 @@ static uint32_t GetIdHeaderOffsetByLocale(const char *locale, const Key *keys, u static int32_t GetIdHeaderByOffset(int32_t file, uint32_t offset, IdHeader *idHeader) { if (file == -1 || offset == INVALID_OFFSET || idHeader == NULL) { + HILOG_ERROR("GetIdHeaderByOffset input params invalid"); return MC_FAILURE; } (void)lseek(file, (int32_t)offset + INDEX_DEFAULT_OFFSET, SEEK_SET); // skip the "IDSS" header idHeader->count = GetDefaultOffsetValue(file); if (idHeader->count == 0 || idHeader->count > MAX_ID_ITEM_NUM) { + HILOG_ERROR("GetIdHeaderByOffset idHeader count %u invalid", idHeader->count); return MC_FAILURE; } idHeader->idParams = (IdParam *)malloc(sizeof(IdParam) * idHeader->count); if (idHeader->idParams == NULL) { + HILOG_ERROR("GetIdHeaderByOffset idHeader idParams is null, idHeader->count: %u", idHeader->count); return MC_FAILURE; } + HILOG_INFO("GetIdHeaderByOffset file: %d, idHeader->count: %u", file, idHeader->count); for (uint32_t i = 0; i < idHeader->count; i++) { idHeader->idParams[i].id = GetDefaultOffsetValue(file); idHeader->idParams[i].offset = GetDefaultOffsetValue(file); diff --git a/frameworks/resmgr_lite/src/hap_manager.cpp b/frameworks/resmgr_lite/src/hap_manager.cpp index b5f5e40b9a9aa7b84581139ad647ec36d6479d89..218d5e77ed2ec0ee3e14f0474bd17b47580818aa 100644 --- a/frameworks/resmgr_lite/src/hap_manager.cpp +++ b/frameworks/resmgr_lite/src/hap_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -133,16 +133,17 @@ const HapResource::ValueUnderQualifierDir *HapManager::FindQualifierValueByName( for (i = 0; i < len; i++) { HapResource::ValueUnderQualifierDir *path = paths[i]; const ResConfigImpl *resConfig = path->GetResConfig(); - if (this->resConfig_->Match(resConfig)) { - if (bestResConfig == nullptr) { - bestIndex = i; - bestResConfig = resConfig; - } else if (bestResConfig->IsMoreSuitable(resConfig, currentResConfig)) { - continue; - } else { - bestResConfig = resConfig; - bestIndex = i; - } + if (!this->resConfig_->Match(resConfig)) { + continue; + } + if (bestResConfig == nullptr) { + bestIndex = i; + bestResConfig = resConfig; + continue; + } + if (!bestResConfig->IsMoreSuitable(resConfig, currentResConfig)) { + bestResConfig = resConfig; + bestIndex = i; } } return paths[bestIndex]; @@ -164,18 +165,17 @@ const HapResource::ValueUnderQualifierDir *HapManager::FindQualifierValueById(ui for (i = 0; i < len; i++) { HapResource::ValueUnderQualifierDir *path = paths[i]; const ResConfigImpl *resConfig = path->GetResConfig(); - if (this->resConfig_->Match(resConfig)) { - if (bestResConfig == nullptr) { - bestIndex = i; - bestResConfig = resConfig; - } else { - if (bestResConfig->IsMoreSuitable(resConfig, currentResConfig)) { - continue; - } else { - bestResConfig = resConfig; - bestIndex = i; - } - } + if (!this->resConfig_->Match(resConfig)) { + continue; + } + if (bestResConfig == nullptr) { + bestIndex = i; + bestResConfig = resConfig; + continue; + } + if (!bestResConfig->IsMoreSuitable(resConfig, currentResConfig)) { + bestResConfig = resConfig; + bestIndex = i; } } return paths[bestIndex]; @@ -260,7 +260,7 @@ bool HapManager::AddResourcePath(const char *path) if (pResource == nullptr) { return false; } - this->hapResources_.push_back((HapResource *)pResource); + this->hapResources_.push_back(const_cast(pResource)); this->loadedHapPaths_.push_back(sPath); return true; } @@ -274,12 +274,12 @@ RState HapManager::ReloadAll() for (size_t i = 0; i < hapResources_.size(); ++i) { const HapResource *pResource = HapResource::LoadFromIndex(hapResources_[i]->GetIndexPath().c_str(), resConfig_); if (pResource == nullptr) { - for (size_t i = 0; i < newResources.size(); ++i) { - delete (newResources[i]); + for (size_t j = 0; j < newResources.size(); ++j) { + delete (newResources[j]); } return HAP_INIT_FAILED; } - newResources.push_back((HapResource *)pResource); + newResources.push_back(const_cast(pResource)); } for (size_t i = 0; i < hapResources_.size(); ++i) { delete (hapResources_[i]); diff --git a/frameworks/resmgr_lite/src/hap_resource.cpp b/frameworks/resmgr_lite/src/hap_resource.cpp index 741fc5214e8eb077f189c6b2755d2ed4eeaf67ef..c40d0932223eda6a7ae6091fe29c53f6fe19b568 100644 --- a/frameworks/resmgr_lite/src/hap_resource.cpp +++ b/frameworks/resmgr_lite/src/hap_resource.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -70,7 +70,7 @@ HapResource::~HapResource() { delete (resDesc_); std::map::iterator iter; - for (iter = idValuesMap_.begin(); iter != idValuesMap_.end(); iter++) { + for (iter = idValuesMap_.begin(); iter != idValuesMap_.end(); ++iter) { IdValues *ptr = iter->second; delete (ptr); } @@ -90,7 +90,7 @@ const HapResource *HapResource::LoadFromIndex(const char *path, const ResConfigI return nullptr; } inFile.seekg(0, std::ios::end); - size_t bufLen = inFile.tellg(); + int bufLen = inFile.tellg(); if (bufLen <= 0) { HILOG_ERROR("file size is zero"); inFile.close(); @@ -103,17 +103,18 @@ const HapResource *HapResource::LoadFromIndex(const char *path, const ResConfigI return nullptr; } inFile.seekg(0, std::ios::beg); - inFile.read((char *)buf, bufLen); + inFile.read(static_cast(buf), bufLen); inFile.close(); - HILOG_DEBUG("extract success, bufLen:%zu", bufLen); + HILOG_DEBUG("extract success, bufLen:%d", bufLen); ResDesc *resDesc = new (std::nothrow) ResDesc(); if (resDesc == nullptr) { HILOG_ERROR("new ResDesc failed when LoadFromIndex"); + free(buf); return nullptr; } - int32_t out = HapParser::ParseResHex((char *)buf, bufLen, *resDesc, defaultConfig); + int32_t out = HapParser::ParseResHex(static_cast(buf), bufLen, *resDesc, defaultConfig); if (out != OK) { delete (resDesc); free(buf); diff --git a/frameworks/resmgr_lite/src/locale_matcher.cpp b/frameworks/resmgr_lite/src/locale_matcher.cpp index 7ccac934819e7ce519adfae1f6b4a9de0db8a3ec..2d197df0655749f02c2e3bc4ba0800f9e3c9c6cf 100644 --- a/frameworks/resmgr_lite/src/locale_matcher.cpp +++ b/frameworks/resmgr_lite/src/locale_matcher.cpp @@ -232,7 +232,7 @@ size_t ComputeTrackPathDistance(const uint64_t *requestPaths, } } } - return len * 2; + return len * 2; } int8_t CompareRegionWhenQaag(const ResLocale *current, @@ -269,6 +269,7 @@ bool CompareLanguage(const ResLocale *current, const ResLocale *other) Utils::EncodeLanguageByResLocale(current); uint16_t otherEncodedLanguage = Utils::EncodeLanguageByResLocale( other); + // 0-4 NEW/OLD language code means iw/he,tl/fil,ji/yi,jw/jv,in/id return ((currentEncodedLanguage == otherEncodedLanguage) || ((currentEncodedLanguage == NEW_LANGUAGES_CODES[0]) && (otherEncodedLanguage == OLD_LANGUAGES_CODES[0])) || @@ -524,7 +525,7 @@ bool LocaleMatcher::Normalize(ResLocale *localeInfo) } uint32_t encodedScript = FindDefaultScriptEncode(localeInfo->GetLanguage(), localeInfo->GetRegion()); - if (encodedScript == NULL_SCRIPT) { + if (encodedScript == LocaleMatcher::NULL_SCRIPT) { return true; } char *tempScript = new(std::nothrow) char[SCRIPT_ARRAY_LEN]; @@ -608,10 +609,10 @@ int8_t LocaleMatcher::IsMoreSuitable(const ResLocale *current, return 0; } bool isLangEqual = CompareLanguage(current, other); - if (isLangEqual == false) { + if (!isLangEqual) { // current or other language is null, not null language is better bool result = CompareRegionWhenLangIsNotEqual(current, other, request); - return (result == true) ? 1 : -1; + return result ? 1 : -1; } uint16_t currentEncodedRegion = Utils::EncodeRegionByResLocale(current); @@ -687,9 +688,11 @@ bool LocaleMatcher::IsRegionTag(const char *str, int32_t len) if (len < 0) { len = strlen(str); } + // region is 2 letters if is alpha string if (len == 2 && Utils::IsAlphaString(str, len)) { return true; } + // region is 3 letters if is numeric string if (len == 3 && Utils::IsNumericString(str, len)) { return true; } diff --git a/frameworks/resmgr_lite/src/lock.cpp b/frameworks/resmgr_lite/src/lock.cpp index 293db1275b38025b79e8e7570abf5b4527171d41..2a9d3055818ec8dbaf32789349e4249d25ef8226 100644 --- a/frameworks/resmgr_lite/src/lock.cpp +++ b/frameworks/resmgr_lite/src/lock.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ #include "lock.h" -#include namespace OHOS { namespace Global { diff --git a/frameworks/resmgr_lite/src/res_config_impl.cpp b/frameworks/resmgr_lite/src/res_config_impl.cpp index 5fb6068d10a09a9dc7ee6ddbb8a5dd0d7c5aa15d..a758bec9605b6a65c16de6a0c3f24c95eadd5787 100644 --- a/frameworks/resmgr_lite/src/res_config_impl.cpp +++ b/frameworks/resmgr_lite/src/res_config_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -181,7 +181,10 @@ bool ResConfigImpl::Copy(ResConfig &other) bool ResConfigImpl::Match(const ResConfigImpl *other) const { - if (LocaleMatcher::Match(this->resLocale_, other->GetResLocale()) == false) { + if (other == nullptr) { + return false; + } + if (!(LocaleMatcher::Match(this->resLocale_, other->GetResLocale()))) { return false; } if (this->direction_ != DIRECTION_NOT_SET && @@ -209,7 +212,7 @@ bool ResConfigImpl::Match(const ResConfigImpl *other) const bool ResConfigImpl::IsMoreSuitable(const ResConfigImpl *other, const ResConfigImpl *request) const { - if (request != nullptr) { + if (request != nullptr && other != nullptr) { int8_t result = LocaleMatcher::IsMoreSuitable(this->GetResLocale(), other->GetResLocale(), request->GetResLocale()); diff --git a/frameworks/resmgr_lite/src/res_desc.cpp b/frameworks/resmgr_lite/src/res_desc.cpp index 7ea551600fbf891cb961ec336a6f897503479dce..81c7b1b88ac3af7874229f6dc981cb997a2d7070 100644 --- a/frameworks/resmgr_lite/src/res_desc.cpp +++ b/frameworks/resmgr_lite/src/res_desc.cpp @@ -13,9 +13,6 @@ * limitations under the License. */ #include "res_desc.h" - -#include - #include "hilog_wrapper.h" #include "securec.h" #include "utils/common.h" @@ -67,8 +64,8 @@ std::string KeyParam::GetDeviceTypeStr() const case DeviceType::DEVICE_CAR: ret = std::string(CAR_STR); break; - case DeviceType::DEVICE_PC: - ret = std::string(PC_STR); + case DeviceType::DEVICE_PAD: + ret = std::string(PAD_STR); break; case DeviceType::DEVICE_TV: ret = std::string(TV_STR); @@ -91,7 +88,9 @@ const std::string KeyParam::ConvertToStr() const HILOG_ERROR("memcpy_s error : %d", eret); } int j = 0; + // 4 means langauages/region/script key value max length for (int i = 0; i < 4; ++i) { + // 3 means reverse temp value to temp2 if (tmp[3 - i]) { tmp2[j++] = tmp[3 - i]; } @@ -145,6 +144,8 @@ bool IdItem::HaveParent() const if (!(resType_ == THEME || resType_ == PATTERN)) { return false; } + // the values_ storage map(key, value) and parent ref + // if have parent, size would be odd number return (values_.size() % 2 == 1); } @@ -156,6 +157,7 @@ bool IdItem::IsRef(const std::string &value, ResType &resType, int &id) return false; } auto index = value.find(":"); + // there are atleast one letter between '$' and ':' if (index == std::string::npos || index < 2) { return false; } diff --git a/frameworks/resmgr_lite/src/res_locale.cpp b/frameworks/resmgr_lite/src/res_locale.cpp index 6a061bc46aba59ed952e236ca2e9f30ce20cbca5..45e99a5134df093c6c4a2735ef904a9bb89c1388 100644 --- a/frameworks/resmgr_lite/src/res_locale.cpp +++ b/frameworks/resmgr_lite/src/res_locale.cpp @@ -32,7 +32,7 @@ namespace OHOS { namespace Global { namespace Resource { LocaleInfo *ResLocale::defaultLocale_ = nullptr; -Lock ResLocale::lock_ = Lock(); +Lock ResLocale::lock_; ResLocale::ResLocale() : language_(nullptr), region_(nullptr), script_(nullptr) { @@ -128,12 +128,18 @@ RState ResLocale::Init(const char *language, size_t languageLen, const char *scr RState ResLocale::CopyFromLocaleInfo(const LocaleInfo *other) { + if (other == nullptr) { + return ERROR; + } return this->Init(other->GetLanguage(), Utils::StrLen(other->GetLanguage()), other->GetScript(), Utils::StrLen(other->GetScript()), other->GetRegion(), Utils::StrLen(other->GetRegion())); } RState ResLocale::Copy(const ResLocale *other) { + if (other == nullptr) { + return ERROR; + } return this->Init(other->GetLanguage(), Utils::StrLen(other->GetLanguage()), other->GetScript(), Utils::StrLen(other->GetScript()), other->GetRegion(), Utils::StrLen(other->GetRegion())); } @@ -340,9 +346,20 @@ bool ResLocale::UpdateDefault(const LocaleInfo &localeInfo, bool needNotify) ResLocale::~ResLocale() { - delete this->language_; - delete this->script_; - delete this->region_; + if (this->language_ != nullptr) { + delete[] this->language_; + this->language_ = nullptr; + } + + if (this->script_ != nullptr) { + delete[] this->script_; + this->script_ = nullptr; + } + + if (this->region_ != nullptr) { + delete[] this->region_; + this->region_ = nullptr; + } } LocaleInfo *BuildFromString(const char *str, char sep, RState &rState) @@ -368,7 +385,7 @@ LocaleInfo *BuildFromParts(const char *language, const char *script, const char rState = INVALID_BCP47_LANGUAGE_SUBTAG; return nullptr; } - if (LocaleMatcher::IsLanguageTag(language, len) == false) { + if (!(LocaleMatcher::IsLanguageTag(language, len))) { rState = INVALID_BCP47_LANGUAGE_SUBTAG; return nullptr; } @@ -415,7 +432,7 @@ void FindAndSort(std::string localeStr, std::vector &candidateLocal ResLocale *currentLocale = ResLocale::BuildFromString(localeStr.c_str(), DASH_SEP, state); LocaleMatcher::Normalize(currentLocale); std::vector::const_iterator iter; - for (iter = candidateLocale.cbegin(); iter != candidateLocale.cend(); iter++) { + for (iter = candidateLocale.cbegin(); iter != candidateLocale.cend(); ++iter) { ResLocale *resLocale = ResLocale::BuildFromString(iter->c_str(), DASH_SEP, state); if (state == SUCCESS) { LocaleMatcher::Normalize(resLocale); diff --git a/frameworks/resmgr_lite/src/resource_manager_impl.cpp b/frameworks/resmgr_lite/src/resource_manager_impl.cpp index b2c466597b76d61f345d64fa5b2f5ab3eec2a043..ec0be78a1464c1abe5b0e0e365c5fc25a53553c7 100644 --- a/frameworks/resmgr_lite/src/resource_manager_impl.cpp +++ b/frameworks/resmgr_lite/src/resource_manager_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -227,7 +227,7 @@ RState ResourceManagerImpl::GetPluralStringByNameFormat(std::string &outValue, c RState ResourceManagerImpl::GetPluralString(const HapResource::ValueUnderQualifierDir *vuqd, int quantity, std::string &outValue) { -// not found or type invalid + // not found or type invalid if (vuqd == nullptr) { return NOT_FOUND; } @@ -240,6 +240,7 @@ RState ResourceManagerImpl::GetPluralString(const HapResource::ValueUnderQualifi size_t startIdx = 0; size_t loop = idItem->values_.size() / 2; for (size_t i = 0; i < loop; ++i) { + // 2 means key and value appear in pairs std::string key(idItem->values_[startIdx + i * 2]); std::string value(idItem->values_[startIdx + i * 2 + 1]); auto iter = map.find(key); @@ -331,18 +332,20 @@ RState ResourceManagerImpl::ResolveParentReference(const IdItem *idItem, std::ma // this make sure child covers parent size_t loop = currItem->values_.size() / 2; for (size_t i = 0; i < loop; ++i) { + // 2 means key and value appear in pairs std::string key(currItem->values_[startIdx + i * 2]); std::string value(currItem->values_[startIdx + i * 2 + 1]); auto iter = outValue.find(key); - if (iter == outValue.end()) { - std::string resolvedValue; - RState rrRet = ResolveReference(value, resolvedValue); - if (rrRet != SUCCESS) { - HILOG_ERROR("ResolveReference failed, value:%s", value.c_str()); - return ERROR; - } - outValue[key] = resolvedValue; + if (iter != outValue.end()) { + continue; } + std::string resolvedValue; + RState rrRet = ResolveReference(value, resolvedValue); + if (rrRet != SUCCESS) { + HILOG_ERROR("ResolveReference failed, value:%s", value.c_str()); + return ERROR; + } + outValue[key] = resolvedValue; } if (haveParent) { // get parent @@ -448,7 +451,7 @@ RState ResourceManagerImpl::GetInteger(const IdItem *idItem, int &outValue) std::string temp; RState state = ResolveReference(idItem->value_, temp); if (state == SUCCESS) { - outValue = atoi(temp.c_str()); + outValue = stoi(temp); return SUCCESS; } return state; @@ -506,7 +509,7 @@ RState ResourceManagerImpl::GetIntArray(const IdItem *idItem, std::vector & HILOG_ERROR("ResolveReference failed, value:%s", idItem->values_[i].c_str()); return ERROR; } - outValue.push_back(atoi(resolvedValue.c_str())); + outValue.push_back(stoi(resolvedValue)); } return SUCCESS; } @@ -572,6 +575,9 @@ RState ResourceManagerImpl::GetRawFile(const HapResource::ValueUnderQualifierDir std::string &outValue) { // not found or type invalid + if (vuqd == nullptr) { + return NOT_FOUND; + } const IdItem *idItem = vuqd->GetIdItem(); if (idItem == nullptr || idItem->resType_ != resType) { return NOT_FOUND; diff --git a/frameworks/resmgr_lite/src/utils/hap_parser.cpp b/frameworks/resmgr_lite/src/utils/hap_parser.cpp index 02d49ae92055c5fa92a01802743c30e3e8fa6d62..61fa19dba6e87bea793d791c4988440789ae226f 100644 --- a/frameworks/resmgr_lite/src/utils/hap_parser.cpp +++ b/frameworks/resmgr_lite/src/utils/hap_parser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -69,7 +69,7 @@ int32_t HapParser::ReadFileFromZip(const char *zipFile, const char *fileName, vo return UNKNOWN_ERROR; } // obtained the necessary details about file inside zip - *buffer = (void *)malloc(fileInfo.uncompressed_size); // setup buffer + *buffer = static_cast(malloc(fileInfo.uncompressed_size)); // setup buffer bufLen = fileInfo.uncompressed_size; if ((*buffer) == nullptr) { unzClose(uf); @@ -137,7 +137,7 @@ int32_t HapParser::ReadIndexFromFile(const char *zipFile, void **buffer, } // parse config.json - std::string mName = GetModuleName((char *)tmpBuf); + std::string mName = GetModuleName(static_cast(tmpBuf)); if (mName.size() == 0) { errInfo = "parse moduleName from config.json error"; free(tmpBuf); @@ -167,7 +167,7 @@ int32_t ParseString(const char *buffer, uint32_t &offset, std::string &id, bool return SYS_ERROR; } offset += 2; - std::string tmp = std::string((char *)buffer + offset, includeTemi ? (strLen - 1) : strLen); + std::string tmp = std::string(const_cast(buffer) + offset, includeTemi ? (strLen - 1) : strLen); offset += includeTemi ? strLen : (strLen + 1); id = tmp; return OK; @@ -450,8 +450,8 @@ DeviceType HapParser::GetDeviceType(uint32_t value) DeviceType deviceType = DEVICE_NOT_SET; if (value == DEVICE_CAR) { deviceType = DEVICE_CAR; - } else if (value == DEVICE_PC) { - deviceType = DEVICE_PC; + } else if (value == DEVICE_PAD) { + deviceType = DEVICE_PAD; } else if (value == DEVICE_PHONE) { deviceType = DEVICE_PHONE; } else if (value == DEVICE_TABLET) { diff --git a/frameworks/resmgr_lite/src/utils/utils.cpp b/frameworks/resmgr_lite/src/utils/utils.cpp index fc5bf2f43887b624541e57076a67050b834e4511..d98dcc578205ee3344f88088e6bce25d76035d3b 100644 --- a/frameworks/resmgr_lite/src/utils/utils.cpp +++ b/frameworks/resmgr_lite/src/utils/utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -25,6 +25,9 @@ namespace Global { namespace Resource { bool Utils::IsAlphaString(const char *s, int32_t len) { + if (s == nullptr) { + return false; + } int32_t i; for (i = 0; i < len; i++) { char c = *(s + i); @@ -37,6 +40,9 @@ bool Utils::IsAlphaString(const char *s, int32_t len) bool Utils::IsNumericString(const char *s, int32_t len) { + if (s == nullptr) { + return false; + } int32_t i; for (i = 0; i < len; i++) { char c = *(s + i); @@ -60,6 +66,9 @@ bool Utils::IsNumericString(const char *s, int32_t len) */ void Utils::DecodeScript(uint32_t encodeScript, char *outValue) { + if (outValue == nullptr) { + return; + } outValue[0] = (encodeScript & 0xFF000000) >> 24; outValue[1] = (encodeScript & 0x00FF0000) >> 16; outValue[2] = (encodeScript & 0x0000FF00) >> 8; @@ -160,7 +169,7 @@ uint32_t Utils::EncodeScript(const char *script) if (Utils::IsStrEmpty(script)) { return NULL_SCRIPT; } - return (script[0] << 24) | (script[1] << 16) | (script[2] << 8) | script[3]; + return ((uint8_t)script[0] << 24) | ((uint8_t)script[1] << 16) | ((uint8_t)script[2] << 8) | (uint8_t)script[3]; } /** @@ -187,50 +196,43 @@ uint32_t Utils::EncodeScript(const char *script) uint16_t Utils::EncodeLanguageOrRegion(const char *str, char base) { if (str[2] == 0 || str[2] == '-' || str[2] == '_') { - return (str[0] << 8) | str[1]; + return ((uint8_t)str[0] << 8) | ((uint8_t)str[1]); } - uint8_t first = (str[0] - base) & 0x7f; - uint8_t second = (str[1] - base) & 0x7f; - uint8_t third = (str[2] - base) & 0x7f; + uint8_t first = ((uint8_t)(str[0] - base)) & 0x7f; + uint8_t second = ((uint8_t)(str[1] - base)) & 0x7f; + uint8_t third = ((uint8_t)(str[2] - base)) & 0x7f; return ((0x80 | (first << 2) | (second >> 3)) << 8) | ((second << 5) | third); }; bool Utils::StrCompare(const char *left, const char *right, size_t len, bool isCaseSensitive) { - if (left == nullptr) { - if (right == nullptr) { + if (left == nullptr && right == nullptr) { + return true; + } + if (left == nullptr || right == nullptr) { + return false; + } + int rc; + unsigned char c1, c2; + while (len--) { + c1 = (unsigned char)*left; + c2 = (unsigned char)*right; + if (c1 == 0 && c2 == 0) { return true; - } else { + } + if (c1 == 0 || c2 == 0) { return false; } - } else if (right == nullptr) { - return false; - } else { - int rc; - unsigned char c1, c2; - while (len--) { - c1 = (unsigned char)*left; - c2 = (unsigned char)*right; - if (c1 == 0) { - if (c2 == 0) { - return true; - } - return false; - } else if (c2 == 0) { - return false; - } else { - if (isCaseSensitive) { - rc = (int)(c1) - (int)(c2); - } else { - rc = tolower(c1) - tolower(c2); - } - if (rc != 0) { - return false; - } - } - ++left; - ++right; + if (isCaseSensitive) { + rc = (int)(c1) - (int)(c2); + } else { + rc = tolower(c1) - tolower(c2); } + if (rc != 0) { + return false; + } + ++left; + ++right; } return true; } @@ -270,11 +272,14 @@ static uint32_t ParseHex(char c, RState &state) */ RState Utils::ConvertColorToUInt32(const char *s, uint32_t &outValue) { + if (s == nullptr) { + return INVALID_FORMAT; + } uint32_t color = 0; RState parseState = SUCCESS; size_t len = strlen(s); if (*s == '#') { - if (len == 4) { + if (len == 4) { // 4 means #rgb color |= 0xFF000000; color |= ParseHex(s[1], parseState) << 20; color |= ParseHex(s[1], parseState) << 16; @@ -282,7 +287,7 @@ RState Utils::ConvertColorToUInt32(const char *s, uint32_t &outValue) color |= ParseHex(s[2], parseState) << 8; color |= ParseHex(s[3], parseState) << 4; color |= ParseHex(s[3], parseState); - } else if (len == 5) { + } else if (len == 5) { // 5 means #argb color |= ParseHex(s[1], parseState) << 28; color |= ParseHex(s[1], parseState) << 24; color |= ParseHex(s[2], parseState) << 20; @@ -291,7 +296,7 @@ RState Utils::ConvertColorToUInt32(const char *s, uint32_t &outValue) color |= ParseHex(s[3], parseState) << 8; color |= ParseHex(s[4], parseState) << 4; color |= ParseHex(s[4], parseState); - } else if (len == 7) { + } else if (len == 7) { // 7 means #rrggbb color |= 0xFF000000; color |= ParseHex(s[1], parseState) << 20; color |= ParseHex(s[2], parseState) << 16; @@ -299,7 +304,7 @@ RState Utils::ConvertColorToUInt32(const char *s, uint32_t &outValue) color |= ParseHex(s[4], parseState) << 8; color |= ParseHex(s[5], parseState) << 4; color |= ParseHex(s[6], parseState); - } else if (len == 9) { + } else if (len == 9) { // 9 means #aarrggbb color |= ParseHex(s[1], parseState) << 28; color |= ParseHex(s[2], parseState) << 24; color |= ParseHex(s[3], parseState) << 20; diff --git a/frameworks/resmgr_lite/test/BUILD.gn b/frameworks/resmgr_lite/test/BUILD.gn index 3c66b4d40807b0cbeef86fbc77897b65107212f8..9eadf9f34a3cdbdcc0712579bc5ddcc9decf1990 100644 --- a/frameworks/resmgr_lite/test/BUILD.gn +++ b/frameworks/resmgr_lite/test/BUILD.gn @@ -35,12 +35,12 @@ if (ohos_kernel_type == "liteos_a") { include_dirs = [ "unittest/lite/common", - "//base/global/resmgr_lite/frameworks/resmgr_lite/include", - "//base/global/resmgr_lite/interfaces/innerkits/include", + "//base/global/resource_management_lite/frameworks/resmgr_lite/include", + "//base/global/resource_management_lite/interfaces/inner_api/include", "//base/global/i18n_lite/interfaces/kits/i18n/include/", ] - deps = [ "//base/global/resmgr_lite/frameworks/resmgr_lite:global_resmgr" ] + deps = [ "//base/global/resource_management_lite/frameworks/resmgr_lite:global_resmgr" ] output_dir = "$root_out_dir/test/unittest/global" } diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/global_test.cpp b/frameworks/resmgr_lite/test/unittest/lite/common/global_test.cpp index 00e964b1ee474d887f32ea6223bb8628ffb71647..f70df4870b9fbd50d5a9af7b7bd711c82249f5c4 100644 --- a/frameworks/resmgr_lite/test/unittest/lite/common/global_test.cpp +++ b/frameworks/resmgr_lite/test/unittest/lite/common/global_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -27,7 +27,7 @@ using namespace OHOS::Global::Resource; using namespace testing::ext; - +namespace { class GlobalTest : public testing::Test { public: static void SetUpTestCase(void); @@ -174,3 +174,4 @@ HWTEST_F(GlobalTest, GlobalFuncTest004, TestSize.Level1) EXPECT_EQ(std::string("App Name"), values); free(values); } +} diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/global_test.h b/frameworks/resmgr_lite/test/unittest/lite/common/global_test.h index beccf53b0095855b9c1b83ad3c0d1f60d27c68aa..e7bd4822c8ca15da924b93200b86fc2c32da4599 100644 --- a/frameworks/resmgr_lite/test/unittest/lite/common/global_test.h +++ b/frameworks/resmgr_lite/test/unittest/lite/common/global_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,9 +16,9 @@ #ifndef RESOURCE_MANAGER_GLOBAL_TEST_H #define RESOURCE_MANAGER_GLOBAL_TEST_H -int GlobalFuncTest001(); -int GlobalFuncTest002(); -int GlobalFuncTest003(); -int GlobalFuncTest004(); +int GlobalFuncTest001(void); +int GlobalFuncTest002(void); +int GlobalFuncTest003(void); +int GlobalFuncTest004(void); #endif diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/hap_manager_test.cpp b/frameworks/resmgr_lite/test/unittest/lite/common/hap_manager_test.cpp index 67186bb20d1249fcbf8c2eb1d36e68489f99c75e..1df22ddc3c883c66fcd9a8acbe5009019089355e 100644 --- a/frameworks/resmgr_lite/test/unittest/lite/common/hap_manager_test.cpp +++ b/frameworks/resmgr_lite/test/unittest/lite/common/hap_manager_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -26,7 +26,7 @@ using namespace OHOS::Global::Resource; using namespace testing::ext; - +namespace { class HapManagerTest : public testing::Test { public: static void SetUpTestCase(void); @@ -151,4 +151,5 @@ HWTEST_F(HapManagerTest, HapManagerFuncTest002, TestSize.Level1) delete (hapManager); delete (rc2); delete (rc); +} } \ No newline at end of file diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/hap_manager_test.h b/frameworks/resmgr_lite/test/unittest/lite/common/hap_manager_test.h index 93b053760fb97a05080967ad338f81f3c9e1dad9..3da4fc407d7f81b4e43494658e0a6e48fb67dfa0 100644 --- a/frameworks/resmgr_lite/test/unittest/lite/common/hap_manager_test.h +++ b/frameworks/resmgr_lite/test/unittest/lite/common/hap_manager_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,7 +16,7 @@ #ifndef RESOURCE_MANAGER_HAP_MANAGER_TEST_H #define RESOURCE_MANAGER_HAP_MANAGER_TEST_H -int HapManagerFuncTest001(); -int HapManagerFuncTest002(); +int HapManagerFuncTest001(void); +int HapManagerFuncTest002(void); #endif diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/hap_parser_test.cpp b/frameworks/resmgr_lite/test/unittest/lite/common/hap_parser_test.cpp index 13decd68f7e1157c7e796a0dafabb203fb9b5329..6374fd783857311453969dcc7f7eef9a2f0fb926 100644 --- a/frameworks/resmgr_lite/test/unittest/lite/common/hap_parser_test.cpp +++ b/frameworks/resmgr_lite/test/unittest/lite/common/hap_parser_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -26,7 +26,7 @@ using namespace OHOS::Global::Resource; using namespace testing::ext; - +namespace { class HapParserTest : public testing::Test { public: static void SetUpTestCase(void); @@ -118,7 +118,7 @@ HWTEST_F(HapParserTest, HapParserFuncTest001, TestSize.Level1) HWTEST_F(HapParserTest, HapParserFuncTest002, TestSize.Level1) { ASSERT_EQ(DEVICE_CAR, HapParser::GetDeviceType(DEVICE_CAR)); - ASSERT_EQ(DEVICE_PC, HapParser::GetDeviceType(DEVICE_PC)); + ASSERT_EQ(DEVICE_PAD, HapParser::GetDeviceType(DEVICE_PAD)); ASSERT_EQ(DEVICE_PHONE, HapParser::GetDeviceType(DEVICE_PHONE)); ASSERT_EQ(DEVICE_TABLET, HapParser::GetDeviceType(DEVICE_TABLET)); ASSERT_EQ(DEVICE_TV, HapParser::GetDeviceType(DEVICE_TV)); @@ -180,4 +180,5 @@ HWTEST_F(HapParserTest, HapParserFuncTest004, TestSize.Level1) for (auto kp = keyParams.begin(); kp != keyParams.end(); kp++) { delete *kp; } +} } \ No newline at end of file diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/hap_parser_test.h b/frameworks/resmgr_lite/test/unittest/lite/common/hap_parser_test.h index 7c5ef8d407c0902def1871732eb6ee376548ac65..f2945d7b2c71fa0a5d07b0cdd37bff73e802c013 100644 --- a/frameworks/resmgr_lite/test/unittest/lite/common/hap_parser_test.h +++ b/frameworks/resmgr_lite/test/unittest/lite/common/hap_parser_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,9 +16,9 @@ #ifndef RESOURCE_MANAGER_HAP_RESOURCE_TEST_H #define RESOURCE_MANAGER_HAP_RESOURCE_TEST_H -int HapParserFuncTest001(); -int HapParserFuncTest002(); -int HapParserFuncTest003(); -int HapParserFuncTest004(); +int HapParserFuncTest001(void); +int HapParserFuncTest002(void); +int HapParserFuncTest003(void); +int HapParserFuncTest004(void); #endif diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/hap_resource_test.cpp b/frameworks/resmgr_lite/test/unittest/lite/common/hap_resource_test.cpp index 872646f88c6e525baef00cec8bf2b5afee6f066b..b27767c47cdf180e6420c5d23dcee2074040c590 100644 --- a/frameworks/resmgr_lite/test/unittest/lite/common/hap_resource_test.cpp +++ b/frameworks/resmgr_lite/test/unittest/lite/common/hap_resource_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -29,7 +29,7 @@ using namespace OHOS::Global::Resource; using namespace testing::ext; - +namespace { class HapResourceTest : public testing::Test { public: static void SetUpTestCase(void); @@ -301,4 +301,5 @@ HWTEST_F(HapResourceTest, HapResourceFuncTest004, TestSize.Level1) // 3. hap file exists, config.json error: missing "moduleName" resDesc = LoadFromHap(FormatFullPath("err-config.json-2.hap").c_str(), nullptr); ASSERT_TRUE(resDesc == nullptr); +} } \ No newline at end of file diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/hap_resource_test.h b/frameworks/resmgr_lite/test/unittest/lite/common/hap_resource_test.h index 7ea1b99256d8ee8a9bd6a00c5a13921e1cc73179..1e037edf6cbd9f09d14d5331b66b1d18d5b7afa9 100644 --- a/frameworks/resmgr_lite/test/unittest/lite/common/hap_resource_test.h +++ b/frameworks/resmgr_lite/test/unittest/lite/common/hap_resource_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,9 +16,9 @@ #ifndef RESOURCE_MANAGER_HAP_RESOURCE_TEST_H #define RESOURCE_MANAGER_HAP_RESOURCE_TEST_H -int HapResourceFuncTest001(); -int HapResourceFuncTest002(); -int HapResourceFuncTest003(); -int HapResourceFuncTest004(); +int HapResourceFuncTest001(void); +int HapResourceFuncTest002(void); +int HapResourceFuncTest003(void); +int HapResourceFuncTest004(void); #endif diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/locale_info_test.cpp b/frameworks/resmgr_lite/test/unittest/lite/common/locale_info_test.cpp old mode 100755 new mode 100644 index eb0af69dd1fc56aed889b8a938c460d0bfefcd76..4cc3763367fbfa4a9c136946722b03cd2f1eb362 --- a/frameworks/resmgr_lite/test/unittest/lite/common/locale_info_test.cpp +++ b/frameworks/resmgr_lite/test/unittest/lite/common/locale_info_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -25,7 +25,7 @@ using namespace OHOS::Global::Resource; using namespace testing::ext; - +namespace { class LocaleInfoTest : public testing::Test { public: static void SetUpTestCase(void); @@ -606,4 +606,5 @@ HWTEST_F(LocaleInfoTest, LocaleInfoPerformanceFuncTest001, TestSize.Level1) average = total / 1000.0; HILOG_DEBUG("avg cost FindAndSort: %f us", average); EXPECT_LT(average, 500); -}; \ No newline at end of file +}; +} \ No newline at end of file diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/locale_info_test.h b/frameworks/resmgr_lite/test/unittest/lite/common/locale_info_test.h old mode 100755 new mode 100644 index 6512ab3cb0f20178afe6aed75e4afa820c104cba..65d7fd7d8c61a8604b4bef8ffded83d9d3cc6438 --- a/frameworks/resmgr_lite/test/unittest/lite/common/locale_info_test.h +++ b/frameworks/resmgr_lite/test/unittest/lite/common/locale_info_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,32 +16,32 @@ #ifndef RESOURCE_MANAGER_LOCALE_INFO_TEST_H #define RESOURCE_MANAGER_LOCALE_INFO_TEST_H -int LocaleInfoFindAndSortTest001(); -int LocaleInfoFindAndSortTest002(); -int LocaleInfoFindAndSortTest003(); -int LocaleInfoFindAndSortTest004(); -int LocaleInfoFindAndSortTest005(); -int LocaleInfoUpdateSysDefaultTest001(); -int LocaleInfoGetSysDefaultTest001(); -int LocaleInfoGetLanguageTest001(); -int LocaleInfoGetRegionTest001(); -int LocaleInfoGetScriptTest001(); -int LocaleInfoBuildFromPartsTest001(); -int LocaleInfoBuildFromPartsTest002(); -int LocaleInfoBuildFromPartsTest003(); -int LocaleInfoBuildFromPartsTest004(); -int LocaleInfoBuildFromPartsTest005(); -int LocaleInfoBuildFromPartsTest006(); -int LocaleInfoBuildFromStringTest001(); -int LocaleInfoBuildFromStringTest002(); -int LocaleInfoBuildFromStringTest003(); -int LocaleInfoBuildFromStringTest004(); -int LocaleInfoBuildFromStringTest005(); -int LocaleInfoBuildFromStringTest006(); -int LocaleInfoBuildFromStringTest007(); -int LocaleInfoBuildFromStringTest008(); -int LocaleInfoBuildFromStringTest009(); -int LocaleInfoBuildFromStringTest0010(); -int LocaleInfoPerformanceFuncTest001(); +int LocaleInfoFindAndSortTest001(void); +int LocaleInfoFindAndSortTest002(void); +int LocaleInfoFindAndSortTest003(void); +int LocaleInfoFindAndSortTest004(void); +int LocaleInfoFindAndSortTest005(void); +int LocaleInfoUpdateSysDefaultTest001(void); +int LocaleInfoGetSysDefaultTest001(void); +int LocaleInfoGetLanguageTest001(void); +int LocaleInfoGetRegionTest001(void); +int LocaleInfoGetScriptTest001(void); +int LocaleInfoBuildFromPartsTest001(void); +int LocaleInfoBuildFromPartsTest002(void); +int LocaleInfoBuildFromPartsTest003(void); +int LocaleInfoBuildFromPartsTest004(void); +int LocaleInfoBuildFromPartsTest005(void); +int LocaleInfoBuildFromPartsTest006(void); +int LocaleInfoBuildFromStringTest001(void); +int LocaleInfoBuildFromStringTest002(void); +int LocaleInfoBuildFromStringTest003(void); +int LocaleInfoBuildFromStringTest004(void); +int LocaleInfoBuildFromStringTest005(void); +int LocaleInfoBuildFromStringTest006(void); +int LocaleInfoBuildFromStringTest007(void); +int LocaleInfoBuildFromStringTest008(void); +int LocaleInfoBuildFromStringTest009(void); +int LocaleInfoBuildFromStringTest0010(void); +int LocaleInfoPerformanceFuncTest001(void); #endif // RESOURCE_MANAGER_LOCALE_INFO_TEST_H diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/res_config_impl_test.cpp b/frameworks/resmgr_lite/test/unittest/lite/common/res_config_impl_test.cpp index b58d3b84b3e54fbf4bcaddf202e8b19b12a8d52e..6f022d4484ceb0e3735736bd5dc942dc7c88befc 100644 --- a/frameworks/resmgr_lite/test/unittest/lite/common/res_config_impl_test.cpp +++ b/frameworks/resmgr_lite/test/unittest/lite/common/res_config_impl_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -23,7 +23,7 @@ using namespace OHOS::Global::Resource; using namespace testing::ext; - +namespace { class ResConfigImplTest : public testing::Test { public: static void SetUpTestCase(void); @@ -342,7 +342,7 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest020, TestSize.Level1) ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); current->SetDeviceType(DeviceType::DEVICE_CAR); - other->SetDeviceType(DeviceType::DEVICE_PC); + other->SetDeviceType(DeviceType::DEVICE_PAD); EXPECT_FALSE(current->Match(other)); delete current; delete other; @@ -357,7 +357,7 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest021, TestSize.Level1) { ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); - other->SetDeviceType(DeviceType::DEVICE_PC); + other->SetDeviceType(DeviceType::DEVICE_PAD); EXPECT_TRUE(current->Match(other)); delete current; delete other; @@ -372,7 +372,7 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest022, TestSize.Level1) { ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); - current->SetDeviceType(DeviceType::DEVICE_PC); + current->SetDeviceType(DeviceType::DEVICE_PAD); EXPECT_TRUE(current->Match(other)); delete current; delete other; @@ -1392,4 +1392,5 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest050, TestSize.Level1) delete request; delete current; delete other; +} } \ No newline at end of file diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/res_config_impl_test.h b/frameworks/resmgr_lite/test/unittest/lite/common/res_config_impl_test.h index 3a102ee5ea467446ee8a4a69f8aa857eed8f8379..2eb6e005af87b502bf1cda2980b960fabc57ccd5 100644 --- a/frameworks/resmgr_lite/test/unittest/lite/common/res_config_impl_test.h +++ b/frameworks/resmgr_lite/test/unittest/lite/common/res_config_impl_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,84 +16,84 @@ #ifndef RESOURCE_MANAGER_RES_CONFIG_IMPL_TEST_H #define RESOURCE_MANAGER_RES_CONFIG_IMPL_TEST_H -int ResConfigImplMatchTest001(); -int ResConfigImplMatchTest002(); -int ResConfigImplMatchTest003(); -int ResConfigImplMatchTest004(); -int ResConfigImplMatchTest005(); -int ResConfigImplMatchTest006(); -int ResConfigImplMatchTest007(); -int ResConfigImplMatchTest008(); -int ResConfigImplMatchTest009(); -int ResConfigImplMatchTest010(); -int ResConfigImplMatchTest011(); -int ResConfigImplMatchTest012(); -int ResConfigImplMatchTest013(); -int ResConfigImplMatchTest014(); -int ResConfigImplMatchTest015(); -int ResConfigImplMatchTest016(); -int ResConfigImplMatchTest017(); -int ResConfigImplMatchTest018(); -int ResConfigImplMatchTest019(); -int ResConfigImplMatchTest020(); -int ResConfigImplMatchTest021(); -int ResConfigImplMatchTest022(); -int ResConfigImplMatchTest023(); -int ResConfigImplMatchTest024(); -int ResConfigImplMatchTest025(); -int ResConfigImplMatchTest026(); -int ResConfigImplMatchTest027(); -int ResConfigImplMatchTest028(); -int ResConfigImplMatchTest029(); -int ResConfigImplIsMoreSuitableTest001(); -int ResConfigImplIsMoreSuitableTest002(); -int ResConfigImplIsMoreSuitableTest003(); -int ResConfigImplIsMoreSuitableTest004(); -int ResConfigImplIsMoreSuitableTest005(); -int ResConfigImplIsMoreSuitableTest006(); -int ResConfigImplIsMoreSuitableTest007(); -int ResConfigImplIsMoreSuitableTest008(); -int ResConfigImplIsMoreSuitableTest009(); -int ResConfigImplIsMoreSuitableTest010(); -int ResConfigImplIsMoreSuitableTest011(); -int ResConfigImplIsMoreSuitableTest012(); -int ResConfigImplIsMoreSuitableTest013(); -int ResConfigImplIsMoreSuitableTest014(); -int ResConfigImplIsMoreSuitableTest015(); -int ResConfigImplIsMoreSuitableTest016(); -int ResConfigImplIsMoreSuitableTest017(); -int ResConfigImplIsMoreSuitableTest018(); -int ResConfigImplIsMoreSuitableTest019(); -int ResConfigImplIsMoreSuitableTest020(); -int ResConfigImplIsMoreSuitableTest021(); -int ResConfigImplIsMoreSuitableTest022(); -int ResConfigImplIsMoreSuitableTest023(); -int ResConfigImplIsMoreSuitableTest024(); -int ResConfigImplIsMoreSuitableTest025(); -int ResConfigImplIsMoreSuitableTest026(); -int ResConfigImplIsMoreSuitableTest027(); -int ResConfigImplIsMoreSuitableTest028(); -int ResConfigImplIsMoreSuitableTest029(); -int ResConfigImplIsMoreSuitableTest030(); -int ResConfigImplIsMoreSuitableTest031(); -int ResConfigImplIsMoreSuitableTest032(); -int ResConfigImplIsMoreSuitableTest033(); -int ResConfigImplIsMoreSuitableTest034(); -int ResConfigImplIsMoreSuitableTest035(); -int ResConfigImplIsMoreSuitableTest036(); -int ResConfigImplIsMoreSuitableTest037(); -int ResConfigImplIsMoreSuitableTest038(); -int ResConfigImplIsMoreSuitableTest039(); -int ResConfigImplIsMoreSuitableTest040(); -int ResConfigImplIsMoreSuitableTest041(); -int ResConfigImplIsMoreSuitableTest042(); -int ResConfigImplIsMoreSuitableTest043(); -int ResConfigImplIsMoreSuitableTest044(); -int ResConfigImplIsMoreSuitableTest045(); -int ResConfigImplIsMoreSuitableTest046(); -int ResConfigImplIsMoreSuitableTest047(); -int ResConfigImplIsMoreSuitableTest048(); -int ResConfigImplIsMoreSuitableTest049(); -int ResConfigImplIsMoreSuitableTest050(); +int ResConfigImplMatchTest001(void); +int ResConfigImplMatchTest002(void); +int ResConfigImplMatchTest003(void); +int ResConfigImplMatchTest004(void); +int ResConfigImplMatchTest005(void); +int ResConfigImplMatchTest006(void); +int ResConfigImplMatchTest007(void); +int ResConfigImplMatchTest008(void); +int ResConfigImplMatchTest009(void); +int ResConfigImplMatchTest010(void); +int ResConfigImplMatchTest011(void); +int ResConfigImplMatchTest012(void); +int ResConfigImplMatchTest013(void); +int ResConfigImplMatchTest014(void); +int ResConfigImplMatchTest015(void); +int ResConfigImplMatchTest016(void); +int ResConfigImplMatchTest017(void); +int ResConfigImplMatchTest018(void); +int ResConfigImplMatchTest019(void); +int ResConfigImplMatchTest020(void); +int ResConfigImplMatchTest021(void); +int ResConfigImplMatchTest022(void); +int ResConfigImplMatchTest023(void); +int ResConfigImplMatchTest024(void); +int ResConfigImplMatchTest025(void); +int ResConfigImplMatchTest026(void); +int ResConfigImplMatchTest027(void); +int ResConfigImplMatchTest028(void); +int ResConfigImplMatchTest029(void); +int ResConfigImplIsMoreSuitableTest001(void); +int ResConfigImplIsMoreSuitableTest002(void); +int ResConfigImplIsMoreSuitableTest003(void); +int ResConfigImplIsMoreSuitableTest004(void); +int ResConfigImplIsMoreSuitableTest005(void); +int ResConfigImplIsMoreSuitableTest006(void); +int ResConfigImplIsMoreSuitableTest007(void); +int ResConfigImplIsMoreSuitableTest008(void); +int ResConfigImplIsMoreSuitableTest009(void); +int ResConfigImplIsMoreSuitableTest010(void); +int ResConfigImplIsMoreSuitableTest011(void); +int ResConfigImplIsMoreSuitableTest012(void); +int ResConfigImplIsMoreSuitableTest013(void); +int ResConfigImplIsMoreSuitableTest014(void); +int ResConfigImplIsMoreSuitableTest015(void); +int ResConfigImplIsMoreSuitableTest016(void); +int ResConfigImplIsMoreSuitableTest017(void); +int ResConfigImplIsMoreSuitableTest018(void); +int ResConfigImplIsMoreSuitableTest019(void); +int ResConfigImplIsMoreSuitableTest020(void); +int ResConfigImplIsMoreSuitableTest021(void); +int ResConfigImplIsMoreSuitableTest022(void); +int ResConfigImplIsMoreSuitableTest023(void); +int ResConfigImplIsMoreSuitableTest024(void); +int ResConfigImplIsMoreSuitableTest025(void); +int ResConfigImplIsMoreSuitableTest026(void); +int ResConfigImplIsMoreSuitableTest027(void); +int ResConfigImplIsMoreSuitableTest028(void); +int ResConfigImplIsMoreSuitableTest029(void); +int ResConfigImplIsMoreSuitableTest030(void); +int ResConfigImplIsMoreSuitableTest031(void); +int ResConfigImplIsMoreSuitableTest032(void); +int ResConfigImplIsMoreSuitableTest033(void); +int ResConfigImplIsMoreSuitableTest034(void); +int ResConfigImplIsMoreSuitableTest035(void); +int ResConfigImplIsMoreSuitableTest036(void); +int ResConfigImplIsMoreSuitableTest037(void); +int ResConfigImplIsMoreSuitableTest038(void); +int ResConfigImplIsMoreSuitableTest039(void); +int ResConfigImplIsMoreSuitableTest040(void); +int ResConfigImplIsMoreSuitableTest041(void); +int ResConfigImplIsMoreSuitableTest042(void); +int ResConfigImplIsMoreSuitableTest043(void); +int ResConfigImplIsMoreSuitableTest044(void); +int ResConfigImplIsMoreSuitableTest045(void); +int ResConfigImplIsMoreSuitableTest046(void); +int ResConfigImplIsMoreSuitableTest047(void); +int ResConfigImplIsMoreSuitableTest048(void); +int ResConfigImplIsMoreSuitableTest049(void); +int ResConfigImplIsMoreSuitableTest050(void); #endif diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/res_config_test.cpp b/frameworks/resmgr_lite/test/unittest/lite/common/res_config_test.cpp index 2682b32ec6ef016bf557d0450102742f8b9e925c..0e25998ab35bf7cc4fd2e4eec44e7f2585b188ef 100644 --- a/frameworks/resmgr_lite/test/unittest/lite/common/res_config_test.cpp +++ b/frameworks/resmgr_lite/test/unittest/lite/common/res_config_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -25,7 +25,7 @@ using namespace OHOS::Global::Resource; using namespace testing::ext; - +namespace { class ResConfigTest : public testing::Test { public: static void SetUpTestCase(void); @@ -70,8 +70,9 @@ HWTEST_F(ResConfigTest, ResConfigFuncTest001, TestSize.Level1) ResConfigImpl *target = new ResConfigImpl; target->SetLocaleInfo("zh", nullptr, "CN"); EXPECT_TRUE(rc->Match(current)); - EXPECT_TRUE(rc->Match(target) == false); + EXPECT_TRUE(!(rc->Match(target))); delete target; delete current; delete rc; -}; \ No newline at end of file +}; +} \ No newline at end of file diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/res_config_test.h b/frameworks/resmgr_lite/test/unittest/lite/common/res_config_test.h index 2b689eda164b35be5bfa6e7118fa939342980e22..7e23721997c719ac81b046f37b72aa50e48ffef3 100644 --- a/frameworks/resmgr_lite/test/unittest/lite/common/res_config_test.h +++ b/frameworks/resmgr_lite/test/unittest/lite/common/res_config_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,6 +16,6 @@ #ifndef RESOURCE_MANAGER_RES_CONFIG_TEST_H #define RESOURCE_MANAGER_RES_CONFIG_TEST_H -int ResConfigFuncTest001(); +int ResConfigFuncTest001(void); #endif diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/res_desc_test.cpp b/frameworks/resmgr_lite/test/unittest/lite/common/res_desc_test.cpp index 7b19f0b7eb5e9c1ba5655a8eb8292fe592a73b9c..d6aa12922513c36e082f7f988a02ffe15a160f2c 100644 --- a/frameworks/resmgr_lite/test/unittest/lite/common/res_desc_test.cpp +++ b/frameworks/resmgr_lite/test/unittest/lite/common/res_desc_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -23,7 +23,7 @@ using namespace OHOS::Global::Resource; using namespace testing::ext; - +namespace { class ResDescTest : public testing::Test { public: static void SetUpTestCase(void); @@ -141,7 +141,7 @@ HWTEST_F(ResDescTest, ResDescFuncTest002, TestSize.Level1) TestKeyParam(KeyType::DEVICETYPE, DeviceType::DEVICE_PHONE, PHONE_STR); TestKeyParam(KeyType::DEVICETYPE, DeviceType::DEVICE_TABLET, TABLET_STR); TestKeyParam(KeyType::DEVICETYPE, DeviceType::DEVICE_CAR, CAR_STR); - TestKeyParam(KeyType::DEVICETYPE, DeviceType::DEVICE_PC, PC_STR); + TestKeyParam(KeyType::DEVICETYPE, DeviceType::DEVICE_PAD, PAD_STR); TestKeyParam(KeyType::DEVICETYPE, DeviceType::DEVICE_TV, TV_STR); TestKeyParam(KeyType::DEVICETYPE, DeviceType::DEVICE_WEARABLE, WEARABLE_STR); TestKeyParam(KeyType::DEVICETYPE, DeviceType::DEVICE_NOT_SET, "not_device_type"); @@ -153,4 +153,5 @@ HWTEST_F(ResDescTest, ResDescFuncTest002, TestSize.Level1) TestKeyParam(KeyType::SCREEN_DENSITY, ScreenDensity::SCREEN_DENSITY_XXLDPI, RE_480_STR); TestKeyParam(KeyType::SCREEN_DENSITY, ScreenDensity::SCREEN_DENSITY_XXXLDPI, RE_640_STR); TestKeyParam(KeyType::SCREEN_DENSITY, ScreenDensity::SCREEN_DENSITY_NOT_SET, "not_screen_density"); +} } \ No newline at end of file diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/res_desc_test.h b/frameworks/resmgr_lite/test/unittest/lite/common/res_desc_test.h index 416f3486ebafe64a9147e58fa5db62249525da51..a36486bee4316eb9ee06f494e452520d13646e33 100644 --- a/frameworks/resmgr_lite/test/unittest/lite/common/res_desc_test.h +++ b/frameworks/resmgr_lite/test/unittest/lite/common/res_desc_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,7 +16,7 @@ #ifndef RESOURCE_MANAGER_RES_DESC_TEST_H #define RESOURCE_MANAGER_RES_DESC_TEST_H -int ResDescFuncTest001(); -int ResDescFuncTest002(); +int ResDescFuncTest001(void); +int ResDescFuncTest002(void); #endif diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/resource_manager_performance_test.cpp b/frameworks/resmgr_lite/test/unittest/lite/common/resource_manager_performance_test.cpp index 844420f9a60224bbcc7bf444c04b2685dcf8c585..07b614e27bfe6839f7e211e2e295fbb278cec6ba 100644 --- a/frameworks/resmgr_lite/test/unittest/lite/common/resource_manager_performance_test.cpp +++ b/frameworks/resmgr_lite/test/unittest/lite/common/resource_manager_performance_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -35,7 +35,7 @@ using namespace OHOS::Global::Resource; using namespace testing::ext; using namespace std; - +namespace { class ResourceManagerPerformanceTest : public testing::Test { public: static void SetUpTestCase(void); @@ -184,7 +184,7 @@ int TestLoadFromIndex(const char *filePath) average = total / 1000.0; g_logLevel = LOG_DEBUG; HILOG_DEBUG("parse index avg cost 001: %f us", average); - EXPECT_LT(average, 2000); + EXPECT_LT(average, 4000); return OK; } @@ -1119,3 +1119,4 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest032, HILOG_DEBUG("avg cost 032: %f us", average); EXPECT_LT(average, 100); }; +} diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/resource_manager_performance_test.h b/frameworks/resmgr_lite/test/unittest/lite/common/resource_manager_performance_test.h index 7269ed78ad136a794094e58cdfc7b3ab32e94d8e..af3f4dcc2da8c534a03ceacf61ea25886a876c9f 100644 --- a/frameworks/resmgr_lite/test/unittest/lite/common/resource_manager_performance_test.h +++ b/frameworks/resmgr_lite/test/unittest/lite/common/resource_manager_performance_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,37 +16,37 @@ #ifndef RESOURCE_MANAGER_RESOURCE_MANANGER_PERF_TEST_H #define RESOURCE_MANAGER_RESOURCE_MANANGER_PERF_TEST_H -int ResourceManagerPerformanceFuncTest001(); -int ResourceManagerPerformanceFuncTest002(); -int ResourceManagerPerformanceFuncTest003(); -int ResourceManagerPerformanceFuncTest004(); -int ResourceManagerPerformanceFuncTest005(); -int ResourceManagerPerformanceFuncTest006(); -int ResourceManagerPerformanceFuncTest007(); -int ResourceManagerPerformanceFuncTest008(); -int ResourceManagerPerformanceFuncTest009(); -int ResourceManagerPerformanceFuncTest010(); -int ResourceManagerPerformanceFuncTest011(); -int ResourceManagerPerformanceFuncTest012(); -int ResourceManagerPerformanceFuncTest013(); -int ResourceManagerPerformanceFuncTest014(); -int ResourceManagerPerformanceFuncTest015(); -int ResourceManagerPerformanceFuncTest016(); -int ResourceManagerPerformanceFuncTest017(); -int ResourceManagerPerformanceFuncTest018(); -int ResourceManagerPerformanceFuncTest019(); -int ResourceManagerPerformanceFuncTest020(); -int ResourceManagerPerformanceFuncTest021(); -int ResourceManagerPerformanceFuncTest022(); -int ResourceManagerPerformanceFuncTest023(); -int ResourceManagerPerformanceFuncTest024(); -int ResourceManagerPerformanceFuncTest025(); -int ResourceManagerPerformanceFuncTest026(); -int ResourceManagerPerformanceFuncTest027(); -int ResourceManagerPerformanceFuncTest028(); -int ResourceManagerPerformanceFuncTest029(); -int ResourceManagerPerformanceFuncTest030(); -int ResourceManagerPerformanceFuncTest031(); -int ResourceManagerPerformanceFuncTest032(); +int ResourceManagerPerformanceFuncTest001(void); +int ResourceManagerPerformanceFuncTest002(void); +int ResourceManagerPerformanceFuncTest003(void); +int ResourceManagerPerformanceFuncTest004(void); +int ResourceManagerPerformanceFuncTest005(void); +int ResourceManagerPerformanceFuncTest006(void); +int ResourceManagerPerformanceFuncTest007(void); +int ResourceManagerPerformanceFuncTest008(void); +int ResourceManagerPerformanceFuncTest009(void); +int ResourceManagerPerformanceFuncTest010(void); +int ResourceManagerPerformanceFuncTest011(void); +int ResourceManagerPerformanceFuncTest012(void); +int ResourceManagerPerformanceFuncTest013(void); +int ResourceManagerPerformanceFuncTest014(void); +int ResourceManagerPerformanceFuncTest015(void); +int ResourceManagerPerformanceFuncTest016(void); +int ResourceManagerPerformanceFuncTest017(void); +int ResourceManagerPerformanceFuncTest018(void); +int ResourceManagerPerformanceFuncTest019(void); +int ResourceManagerPerformanceFuncTest020(void); +int ResourceManagerPerformanceFuncTest021(void); +int ResourceManagerPerformanceFuncTest022(void); +int ResourceManagerPerformanceFuncTest023(void); +int ResourceManagerPerformanceFuncTest024(void); +int ResourceManagerPerformanceFuncTest025(void); +int ResourceManagerPerformanceFuncTest026(void); +int ResourceManagerPerformanceFuncTest027(void); +int ResourceManagerPerformanceFuncTest028(void); +int ResourceManagerPerformanceFuncTest029(void); +int ResourceManagerPerformanceFuncTest030(void); +int ResourceManagerPerformanceFuncTest031(void); +int ResourceManagerPerformanceFuncTest032(void); #endif diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/resource_manager_test.cpp b/frameworks/resmgr_lite/test/unittest/lite/common/resource_manager_test.cpp index 78896733b748ddbc80bbe9476b667016a8fbec9f..838ce67dd4053640413de075f4dc818d05d6257b 100644 --- a/frameworks/resmgr_lite/test/unittest/lite/common/resource_manager_test.cpp +++ b/frameworks/resmgr_lite/test/unittest/lite/common/resource_manager_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -29,7 +29,7 @@ using namespace OHOS::Global::Resource; using namespace testing::ext; - +namespace { static const int NON_EXIST_ID = 1111; static const char *g_nonExistName = "non_existent_name"; @@ -628,6 +628,7 @@ HWTEST_F(ResourceManagerTest, ResourceManagerGetPatternByIdTest001, TestSize.Lev RState state; id = GetResId("base", ResType::PATTERN); + ASSERT_TRUE(id > 0); state = rm->GetPatternById(id, outValue); ASSERT_EQ(SUCCESS, state); ASSERT_EQ(static_cast(3), outValue.size()); @@ -648,6 +649,7 @@ HWTEST_F(ResourceManagerTest, ResourceManagerGetPatternByIdTest002, TestSize.Lev RState state; id = GetResId("child", ResType::PATTERN); + ASSERT_TRUE(id > 0); state = rm->GetPatternById(id, outValue); ASSERT_EQ(SUCCESS, state); ASSERT_EQ(static_cast(4), outValue.size()); @@ -668,6 +670,7 @@ HWTEST_F(ResourceManagerTest, ResourceManagerGetPatternByIdTest003, TestSize.Lev RState state; id = GetResId("ccchild", ResType::PATTERN); + ASSERT_TRUE(id > 0); state = rm->GetPatternById(id, outValue); ASSERT_EQ(SUCCESS, state); ASSERT_EQ(static_cast(5), outValue.size()); @@ -995,7 +998,7 @@ HWTEST_F(ResourceManagerTest, ResourceManagerGetThemeByNameTest001, TestSize.Lev ASSERT_EQ(SUCCESS, state); PrintMapString(outValue); - state = rm->GetThemeByName("activity_theme", outValue); + state = rm->GetThemeByName("test_theme", outValue); ASSERT_EQ(SUCCESS, state); PrintMapString(outValue); } @@ -1636,6 +1639,7 @@ HWTEST_F(ResourceManagerTest, ResourceManagerResolveParentReferenceTest001, Test RState ret; id = GetResId("base", ResType::PATTERN); + ASSERT_TRUE(id > 0); idItem = ((ResourceManagerImpl *)rm)->hapManager_->FindResourceById(id); ASSERT_TRUE(idItem != nullptr); ret = ((ResourceManagerImpl *)rm)->ResolveParentReference(idItem, outValue); @@ -1644,6 +1648,7 @@ HWTEST_F(ResourceManagerTest, ResourceManagerResolveParentReferenceTest001, Test HILOG_DEBUG("====="); id = GetResId("child", ResType::PATTERN); + ASSERT_TRUE(id > 0); idItem = ((ResourceManagerImpl *)rm)->hapManager_->FindResourceById(id); ASSERT_TRUE(idItem != nullptr); ret = ((ResourceManagerImpl *)rm)->ResolveParentReference(idItem, outValue); @@ -1652,6 +1657,7 @@ HWTEST_F(ResourceManagerTest, ResourceManagerResolveParentReferenceTest001, Test HILOG_DEBUG("====="); id = GetResId("ccchild", ResType::PATTERN); + ASSERT_TRUE(id > 0); idItem = ((ResourceManagerImpl *)rm)->hapManager_->FindResourceById(id); ASSERT_TRUE(idItem != nullptr); ret = ((ResourceManagerImpl *)rm)->ResolveParentReference(idItem, outValue); @@ -1701,3 +1707,4 @@ HWTEST_F(ResourceManagerTest, ResourceManagerSameNameTest001, TestSize.Level1) EXPECT_TRUE(state == SUCCESS); EXPECT_EQ(999, outValueI); } +} diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/resource_manager_test.h b/frameworks/resmgr_lite/test/unittest/lite/common/resource_manager_test.h index c637d048f6a07ae2b11bf5980c2e4aedbdec0c5c..ee8e4ede8bb3007c00b8655782b9bbe926097b0d 100644 --- a/frameworks/resmgr_lite/test/unittest/lite/common/resource_manager_test.h +++ b/frameworks/resmgr_lite/test/unittest/lite/common/resource_manager_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,83 +16,83 @@ #ifndef RESOURCE_MANAGER_RESOURCE_MANANGER_TEST_H #define RESOURCE_MANAGER_RESOURCE_MANANGER_TEST_H -int ResourceManagerAddResourceTest001(); -int ResourceManagerAddResourceTest002(); -int ResourceManagerAddResourceTest003(); -int ResourceManagerUpdateResConfigTest001(); -int ResourceManagerUpdateResConfigTest002(); -int ResourceManagerUpdateResConfigTest003(); -int ResourceManagerUpdateResConfigTest004(); -int ResourceManagerUpdateResConfigTest005(); -int ResourceManagerGetResConfigTest001(); -int ResourceManagerGetResConfigTest002(); -int ResourceManagerGetStringByIdTest001(); -int ResourceManagerGetStringByIdTest002(); -int ResourceManagerGetStringByIdTest003(); -int ResourceManagerGetStringByNameTest001(); -int ResourceManagerGetStringByNameTest002(); -int ResourceManagerGetStringByNameTest003(); -int ResourceManagerGetStringFormatByIdTest001(); -int ResourceManagerGetStringFormatByIdTest002(); -int ResourceManagerGetStringFormatByNameTest001(); -int ResourceManagerGetStringFormatByNameTest002(); -int ResourceManagerGetStringArrayByIdTest001(); -int ResourceManagerGetStringArrayByIdTest002(); -int ResourceManagerGetStringArrayByNameTest001(); -int ResourceManagerGetStringArrayByNameTest002(); -int ResourceManagerGetPatternByIdTest001(); -int ResourceManagerGetPatternByIdTest002(); -int ResourceManagerGetPatternByIdTest003(); -int ResourceManagerGetPatternByIdTest004(); -int ResourceManagerGetPatternByNameTest001(); -int ResourceManagerGetPatternByNameTest002(); -int ResourceManagerGetPatternByNameTest003(); -int ResourceManagerGetPatternByNameTest004(); -int ResourceManagerGetPluralStringByIdTest001(); -int ResourceManagerGetPluralStringByIdTest002(); -int ResourceManagerGetPluralStringByIdTest003(); -int ResourceManagerGetPluralStringByIdTest004(); -int ResourceManagerGetPluralStringByIdTest005(); -int ResourceManagerGetPluralStringByNameTest001(); -int ResourceManagerGetPluralStringByNameTest002(); -int ResourceManagerGetPluralStringByIdFormatTest001(); -int ResourceManagerGetPluralStringByIdFormatTest002(); -int ResourceManagerGetPluralStringByNameFormatTest001(); -int ResourceManagerGetPluralStringByNameFormatTest002(); -int ResourceManagerGetThemeByIdTest001(); -int ResourceManagerGetThemeByIdTest002(); -int ResourceManagerGetThemeByNameTest001(); -int ResourceManagerGetThemeByNameTest002(); -int ResourceManagerGetBooleanByIdTest001(); -int ResourceManagerGetBooleanByIdTest002(); -int ResourceManagerGetBooleanByNameTest001(); -int ResourceManagerGetBooleanByNameTest002(); -int ResourceManagerGetIntegerByIdTest001(); -int ResourceManagerGetIntegerByIdTest002(); -int ResourceManagerGetIntegerByNameTest001(); -int ResourceManagerGetIntegerByNameTest002(); -int ResourceManagerGetFloatByIdTest001(); -int ResourceManagerGetFloatByIdTest002(); -int ResourceManagerGetFloatByNameTest001(); -int ResourceManagerGetFloatByNameTest002(); -int ResourceManagerGetIntArrayByIdTest001(); -int ResourceManagerGetIntArrayByIdTest002(); -int ResourceManagerGetIntArrayByNameTest001(); -int ResourceManagerGetIntArrayByNameTest002(); -int ResourceManagerGetColorByIdTest001(); -int ResourceManagerGetColorByIdTest002(); -int ResourceManagerGetColorByNameTest001(); -int ResourceManagerGetColorByNameTest002(); -int ResourceManagerGetProfileByIdTest001(); -int ResourceManagerGetProfileByIdTest002(); -int ResourceManagerGetProfileByNameTest001(); -int ResourceManagerGetProfileByNameTest002(); -int ResourceManagerGetMediaByIdTest001(); -int ResourceManagerGetMediaByIdTest002(); -int ResourceManagerGetMediaByNameTest001(); -int ResourceManagerGetMediaByNameTest002(); -int ResourceManagerResolveReferenceTest001(); -int ResourceManagerResolveParentReferenceTest001(); -int ResourceManagerSameNameTest001(); +int ResourceManagerAddResourceTest001(void); +int ResourceManagerAddResourceTest002(void); +int ResourceManagerAddResourceTest003(void); +int ResourceManagerUpdateResConfigTest001(void); +int ResourceManagerUpdateResConfigTest002(void); +int ResourceManagerUpdateResConfigTest003(void); +int ResourceManagerUpdateResConfigTest004(void); +int ResourceManagerUpdateResConfigTest005(void); +int ResourceManagerGetResConfigTest001(void); +int ResourceManagerGetResConfigTest002(void); +int ResourceManagerGetStringByIdTest001(void); +int ResourceManagerGetStringByIdTest002(void); +int ResourceManagerGetStringByIdTest003(void); +int ResourceManagerGetStringByNameTest001(void); +int ResourceManagerGetStringByNameTest002(void); +int ResourceManagerGetStringByNameTest003(void); +int ResourceManagerGetStringFormatByIdTest001(void); +int ResourceManagerGetStringFormatByIdTest002(void); +int ResourceManagerGetStringFormatByNameTest001(void); +int ResourceManagerGetStringFormatByNameTest002(void); +int ResourceManagerGetStringArrayByIdTest001(void); +int ResourceManagerGetStringArrayByIdTest002(void); +int ResourceManagerGetStringArrayByNameTest001(void); +int ResourceManagerGetStringArrayByNameTest002(void); +int ResourceManagerGetPatternByIdTest001(void); +int ResourceManagerGetPatternByIdTest002(void); +int ResourceManagerGetPatternByIdTest003(void); +int ResourceManagerGetPatternByIdTest004(void); +int ResourceManagerGetPatternByNameTest001(void); +int ResourceManagerGetPatternByNameTest002(void); +int ResourceManagerGetPatternByNameTest003(void); +int ResourceManagerGetPatternByNameTest004(void); +int ResourceManagerGetPluralStringByIdTest001(void); +int ResourceManagerGetPluralStringByIdTest002(void); +int ResourceManagerGetPluralStringByIdTest003(void); +int ResourceManagerGetPluralStringByIdTest004(void); +int ResourceManagerGetPluralStringByIdTest005(void); +int ResourceManagerGetPluralStringByNameTest001(void); +int ResourceManagerGetPluralStringByNameTest002(void); +int ResourceManagerGetPluralStringByIdFormatTest001(void); +int ResourceManagerGetPluralStringByIdFormatTest002(void); +int ResourceManagerGetPluralStringByNameFormatTest001(void); +int ResourceManagerGetPluralStringByNameFormatTest002(void); +int ResourceManagerGetThemeByIdTest001(void); +int ResourceManagerGetThemeByIdTest002(void); +int ResourceManagerGetThemeByNameTest001(void); +int ResourceManagerGetThemeByNameTest002(void); +int ResourceManagerGetBooleanByIdTest001(void); +int ResourceManagerGetBooleanByIdTest002(void); +int ResourceManagerGetBooleanByNameTest001(void); +int ResourceManagerGetBooleanByNameTest002(void); +int ResourceManagerGetIntegerByIdTest001(void); +int ResourceManagerGetIntegerByIdTest002(void); +int ResourceManagerGetIntegerByNameTest001(void); +int ResourceManagerGetIntegerByNameTest002(void); +int ResourceManagerGetFloatByIdTest001(void); +int ResourceManagerGetFloatByIdTest002(void); +int ResourceManagerGetFloatByNameTest001(void); +int ResourceManagerGetFloatByNameTest002(void); +int ResourceManagerGetIntArrayByIdTest001(void); +int ResourceManagerGetIntArrayByIdTest002(void); +int ResourceManagerGetIntArrayByNameTest001(void); +int ResourceManagerGetIntArrayByNameTest002(void); +int ResourceManagerGetColorByIdTest001(void); +int ResourceManagerGetColorByIdTest002(void); +int ResourceManagerGetColorByNameTest001(void); +int ResourceManagerGetColorByNameTest002(void); +int ResourceManagerGetProfileByIdTest001(void); +int ResourceManagerGetProfileByIdTest002(void); +int ResourceManagerGetProfileByNameTest001(void); +int ResourceManagerGetProfileByNameTest002(void); +int ResourceManagerGetMediaByIdTest001(void); +int ResourceManagerGetMediaByIdTest002(void); +int ResourceManagerGetMediaByNameTest001(void); +int ResourceManagerGetMediaByNameTest002(void); +int ResourceManagerResolveReferenceTest001(void); +int ResourceManagerResolveParentReferenceTest001(void); +int ResourceManagerSameNameTest001(void); #endif diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/string_utils_test.cpp b/frameworks/resmgr_lite/test/unittest/lite/common/string_utils_test.cpp index 08cfbcaa4f30a176c4e449ff44234b913691e14c..8ff7e186e65b875f7900ae9caa1cd9e58c03588b 100644 --- a/frameworks/resmgr_lite/test/unittest/lite/common/string_utils_test.cpp +++ b/frameworks/resmgr_lite/test/unittest/lite/common/string_utils_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -24,7 +24,7 @@ using namespace OHOS::Global::Resource; using namespace testing::ext; using namespace OHOS::I18N; - +namespace { class StringUtilsTest : public testing::Test { public: static void SetUpTestCase(void); @@ -100,7 +100,8 @@ HWTEST_F(StringUtilsTest, LockFuncTest001, TestSize.Level1) int num = 0; int threadNum = 3; int result = num + threadNum; - Lock lock = Lock(); + Lock lock; TestThread(&num, threadNum, &lock); EXPECT_EQ(result, num); +} } \ No newline at end of file diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/string_utils_test.h b/frameworks/resmgr_lite/test/unittest/lite/common/string_utils_test.h index f2ee91958775912bbeb9df52432ff1b95c5f609b..8a268e65c59640b300b55e5da47b2749dd051e4c 100644 --- a/frameworks/resmgr_lite/test/unittest/lite/common/string_utils_test.h +++ b/frameworks/resmgr_lite/test/unittest/lite/common/string_utils_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,7 +16,7 @@ #ifndef RESOURCE_MANAGER_STRING_UTILS_TEST_H #define RESOURCE_MANAGER_STRING_UTILS_TEST_H -int StringUtilsFuncTest001(); -int LockFuncTest001(); +int StringUtilsFuncTest001(void); +int LockFuncTest001(void); #endif diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/test_common.cpp b/frameworks/resmgr_lite/test/unittest/lite/common/test_common.cpp index a8d261dfe074c6c9aef10c23c3230126ad560694..1a11c6c453b651644d3c6d2cc78bd651b1dbd397 100644 --- a/frameworks/resmgr_lite/test/unittest/lite/common/test_common.cpp +++ b/frameworks/resmgr_lite/test/unittest/lite/common/test_common.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -41,7 +41,6 @@ std::string FormatFullPath(const char *fileRelativePath) void PrintIdValues(const HapResource::IdValues *idValues) { - HILOG_DEBUG("idvalues size: %u", idValues->GetLimitPathsConst().size()); for (size_t i = 0; i < idValues->GetLimitPathsConst().size(); ++i) { auto limitPath = idValues->GetLimitPathsConst()[i]; HILOG_DEBUG("%zu: folder is: %s, value: %s", i, limitPath->GetFolder().c_str(), diff --git a/frameworks/resmgr_lite/test/unittest/lite/common/test_common.h b/frameworks/resmgr_lite/test/unittest/lite/common/test_common.h index 53dd723c6ba31e2686657e584d6fb04e3fb513aa..ee596b648cd7e4d1afc977d459141437fb8971ae 100644 --- a/frameworks/resmgr_lite/test/unittest/lite/common/test_common.h +++ b/frameworks/resmgr_lite/test/unittest/lite/common/test_common.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/interfaces/innerkits/include/global.h b/interfaces/inner_api/include/global.h similarity index 98% rename from interfaces/innerkits/include/global.h rename to interfaces/inner_api/include/global.h index 3a6f4889b3919694358f1cbef50a3f068ee3f24f..2eb2b504e2a2977d3d41987463ba685e6876c419 100644 --- a/interfaces/innerkits/include/global.h +++ b/interfaces/inner_api/include/global.h @@ -38,6 +38,7 @@ int32_t GLOBAL_GetValueByName(const char *name, const char *path, char **value); void GLOBAL_ConfigLanguage(const char *appLanguage); int32_t GLOBAL_GetLanguage(char *language, uint8_t len); int32_t GLOBAL_GetRegion(char *region, uint8_t len); +int32_t GLOBAL_IsRTL(void); #ifdef __cplusplus #if __cplusplus diff --git a/test/resource/data/all.hap b/test/resource/data/all.hap index 3faf9885d7e781c78e6682f427c639d99b0db1cd..e5244c5585ef4b9ab7132911e18706278a7f2a3d 100644 Binary files a/test/resource/data/all.hap and b/test/resource/data/all.hap differ diff --git a/test/resource/data/all/assets/entry/resources.index b/test/resource/data/all/assets/entry/resources.index index b06d9dcecc508f954d3352843118a6e35d452a22..9162b5ead5ae90415e9e5e4e382af8d0d25cab57 100644 Binary files a/test/resource/data/all/assets/entry/resources.index and b/test/resource/data/all/assets/entry/resources.index differ diff --git a/test/resource/data/err-config.json-1.hap b/test/resource/data/err-config.json-1.hap old mode 100755 new mode 100644 diff --git a/test/resource/data/err-config.json-2.hap b/test/resource/data/err-config.json-2.hap old mode 100755 new mode 100644