From cced3b17c4880dbd8404db5d98c88330edb26ca0 Mon Sep 17 00:00:00 2001 From: seaky Date: Wed, 7 Jul 2021 22:47:28 +0800 Subject: [PATCH 01/19] copy from lite Signed-off-by: seaky --- frameworks/resmgr/include/auto_mutex.h | 0 frameworks/resmgr/include/hap_manager.h | 15 +- frameworks/resmgr/include/hap_parser.h | 0 frameworks/resmgr/include/hap_resource.h | 2 +- frameworks/resmgr/include/hilog_wrapper.h | 0 frameworks/resmgr/include/locale_matcher.h | 14 +- frameworks/resmgr/include/lock.h | 0 frameworks/resmgr/include/res_config_impl.h | 14 +- frameworks/resmgr/include/res_desc.h | 6 +- .../{locale_info_impl.h => res_locale.h} | 53 +- .../resmgr/include/resource_manager_impl.h | 26 +- frameworks/resmgr/include/utils/common.h | 0 frameworks/resmgr/include/utils/date_utils.h | 4 +- frameworks/resmgr/include/utils/errors.h | 4 +- frameworks/resmgr/include/utils/locale_data.h | 0 .../resmgr/include/utils/string_utils.h | 0 frameworks/resmgr/include/utils/utils.h | 18 +- frameworks/resmgr/src/hap_manager.cpp | 78 +- frameworks/resmgr/src/hap_resource.cpp | 7 +- .../resmgr/src/likely_subtags_key_data.cpp | 0 .../resmgr/src/likely_subtags_value_data.cpp | 0 frameworks/resmgr/src/locale_matcher.cpp | 117 ++- frameworks/resmgr/src/lock.cpp | 2 +- frameworks/resmgr/src/res_config_impl.cpp | 115 ++- frameworks/resmgr/src/res_desc.cpp | 1 - .../{locale_info_impl.cpp => res_locale.cpp} | 202 ++--- .../resmgr/src/resource_manager_impl.cpp | 12 +- frameworks/resmgr/src/utils/hap_parser.cpp | 16 +- frameworks/resmgr/src/utils/string_utils.cpp | 0 frameworks/resmgr/src/utils/utils.cpp | 59 +- .../test/unittest/common/hap_manager_test.cpp | 2 +- .../test/unittest/common/hap_manager_test.h | 0 .../test/unittest/common/hap_parser_test.cpp | 6 +- .../test/unittest/common/hap_parser_test.h | 0 .../unittest/common/hap_resource_test.cpp | 4 +- .../test/unittest/common/hap_resource_test.h | 0 .../test/unittest/common/locale_info_test.cpp | 150 +++- .../test/unittest/common/locale_info_test.h | 13 +- .../unittest/common/res_config_impl_test.cpp | 701 +++++++++++++++++- .../unittest/common/res_config_impl_test.h | 22 + .../test/unittest/common/res_config_test.cpp | 5 + .../test/unittest/common/res_config_test.h | 0 .../test/unittest/common/res_desc_test.cpp | 5 + .../test/unittest/common/res_desc_test.h | 0 .../resource_manager_performance_test.cpp | 108 ++- .../resource_manager_performance_test.h | 0 .../unittest/common/resource_manager_test.cpp | 6 + .../unittest/common/resource_manager_test.h | 0 .../unittest/common/string_utils_test.cpp | 73 ++ .../test/unittest/common/string_utils_test.h | 35 +- .../test/unittest/common/test_common.cpp | 0 .../resmgr/test/unittest/common/test_common.h | 0 interfaces/innerkits/include/res_common.h | 6 +- interfaces/innerkits/include/res_config.h | 16 +- .../innerkits/include/resource_manager.h | 20 +- interfaces/innerkits/include/rstate.h | 0 56 files changed, 1462 insertions(+), 475 deletions(-) mode change 100755 => 100644 frameworks/resmgr/include/auto_mutex.h mode change 100755 => 100644 frameworks/resmgr/include/hap_manager.h mode change 100755 => 100644 frameworks/resmgr/include/hap_parser.h mode change 100755 => 100644 frameworks/resmgr/include/hap_resource.h mode change 100755 => 100644 frameworks/resmgr/include/hilog_wrapper.h mode change 100755 => 100644 frameworks/resmgr/include/locale_matcher.h mode change 100755 => 100644 frameworks/resmgr/include/lock.h mode change 100755 => 100644 frameworks/resmgr/include/res_config_impl.h mode change 100755 => 100644 frameworks/resmgr/include/res_desc.h rename frameworks/resmgr/include/{locale_info_impl.h => res_locale.h} (52%) mode change 100755 => 100644 mode change 100755 => 100644 frameworks/resmgr/include/resource_manager_impl.h mode change 100755 => 100644 frameworks/resmgr/include/utils/common.h mode change 100755 => 100644 frameworks/resmgr/include/utils/date_utils.h mode change 100755 => 100644 frameworks/resmgr/include/utils/errors.h mode change 100755 => 100644 frameworks/resmgr/include/utils/locale_data.h mode change 100755 => 100644 frameworks/resmgr/include/utils/string_utils.h mode change 100755 => 100644 frameworks/resmgr/include/utils/utils.h mode change 100755 => 100644 frameworks/resmgr/src/hap_manager.cpp mode change 100755 => 100644 frameworks/resmgr/src/hap_resource.cpp mode change 100755 => 100644 frameworks/resmgr/src/likely_subtags_key_data.cpp mode change 100755 => 100644 frameworks/resmgr/src/likely_subtags_value_data.cpp mode change 100755 => 100644 frameworks/resmgr/src/locale_matcher.cpp mode change 100755 => 100644 frameworks/resmgr/src/lock.cpp mode change 100755 => 100644 frameworks/resmgr/src/res_config_impl.cpp mode change 100755 => 100644 frameworks/resmgr/src/res_desc.cpp rename frameworks/resmgr/src/{locale_info_impl.cpp => res_locale.cpp} (60%) mode change 100755 => 100644 mode change 100755 => 100644 frameworks/resmgr/src/resource_manager_impl.cpp mode change 100755 => 100644 frameworks/resmgr/src/utils/hap_parser.cpp mode change 100755 => 100644 frameworks/resmgr/src/utils/string_utils.cpp mode change 100755 => 100644 frameworks/resmgr/src/utils/utils.cpp mode change 100755 => 100644 frameworks/resmgr/test/unittest/common/hap_manager_test.cpp mode change 100755 => 100644 frameworks/resmgr/test/unittest/common/hap_manager_test.h mode change 100755 => 100644 frameworks/resmgr/test/unittest/common/hap_parser_test.cpp mode change 100755 => 100644 frameworks/resmgr/test/unittest/common/hap_parser_test.h mode change 100755 => 100644 frameworks/resmgr/test/unittest/common/hap_resource_test.cpp mode change 100755 => 100644 frameworks/resmgr/test/unittest/common/hap_resource_test.h mode change 100755 => 100644 frameworks/resmgr/test/unittest/common/res_config_impl_test.cpp mode change 100755 => 100644 frameworks/resmgr/test/unittest/common/res_config_impl_test.h mode change 100755 => 100644 frameworks/resmgr/test/unittest/common/res_config_test.cpp mode change 100755 => 100644 frameworks/resmgr/test/unittest/common/res_config_test.h mode change 100755 => 100644 frameworks/resmgr/test/unittest/common/res_desc_test.cpp mode change 100755 => 100644 frameworks/resmgr/test/unittest/common/res_desc_test.h mode change 100755 => 100644 frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp mode change 100755 => 100644 frameworks/resmgr/test/unittest/common/resource_manager_performance_test.h mode change 100755 => 100644 frameworks/resmgr/test/unittest/common/resource_manager_test.cpp mode change 100755 => 100644 frameworks/resmgr/test/unittest/common/resource_manager_test.h create mode 100644 frameworks/resmgr/test/unittest/common/string_utils_test.cpp rename interfaces/innerkits/include/locale_info.h => frameworks/resmgr/test/unittest/common/string_utils_test.h (40%) mode change 100755 => 100644 mode change 100755 => 100644 frameworks/resmgr/test/unittest/common/test_common.cpp mode change 100755 => 100644 frameworks/resmgr/test/unittest/common/test_common.h mode change 100755 => 100644 interfaces/innerkits/include/res_common.h mode change 100755 => 100644 interfaces/innerkits/include/res_config.h mode change 100755 => 100644 interfaces/innerkits/include/resource_manager.h mode change 100755 => 100644 interfaces/innerkits/include/rstate.h diff --git a/frameworks/resmgr/include/auto_mutex.h b/frameworks/resmgr/include/auto_mutex.h old mode 100755 new mode 100644 diff --git a/frameworks/resmgr/include/hap_manager.h b/frameworks/resmgr/include/hap_manager.h old mode 100755 new mode 100644 index a02a71b..372aa66 --- a/frameworks/resmgr/include/hap_manager.h +++ b/frameworks/resmgr/include/hap_manager.h @@ -20,7 +20,8 @@ #include "res_desc.h" #include "lock.h" -#include +#include +#include #include namespace OHOS { @@ -36,7 +37,7 @@ public: void GetResConfig(ResConfig& resConfig); - bool AddResource(const char* path); + bool AddResource(const char *path); const IdItem *FindResourceById(uint32_t id); @@ -55,17 +56,13 @@ private: const HapResource::IdValues *GetResourceList(uint32_t ident) const; - const HapResource::IdValues *GetResourceListByName(const char* name, const ResType resType) const; + const HapResource::IdValues *GetResourceListByName(const char *name, const ResType resType) const; - bool AddResourcePath(const char* path); + bool AddResourcePath(const char *path); // when resConfig_ updated we must call ReloadAll() RState ReloadAll(); - static bool Init(); - - static bool icuInitialized; - // app res config ResConfigImpl *resConfig_; @@ -76,7 +73,7 @@ private: std::vector loadedHapPaths_; // key is language - std::vector> plurRulesCache_; + std::vector> plurRulesCache_; Lock lock_; }; diff --git a/frameworks/resmgr/include/hap_parser.h b/frameworks/resmgr/include/hap_parser.h old mode 100755 new mode 100644 diff --git a/frameworks/resmgr/include/hap_resource.h b/frameworks/resmgr/include/hap_resource.h old mode 100755 new mode 100644 index 6722664..007b899 --- a/frameworks/resmgr/include/hap_resource.h +++ b/frameworks/resmgr/include/hap_resource.h @@ -17,10 +17,10 @@ #include "res_desc.h" #include "res_config_impl.h" +#include #include #include #include -#include namespace OHOS { namespace Global { diff --git a/frameworks/resmgr/include/hilog_wrapper.h b/frameworks/resmgr/include/hilog_wrapper.h old mode 100755 new mode 100644 diff --git a/frameworks/resmgr/include/locale_matcher.h b/frameworks/resmgr/include/locale_matcher.h old mode 100755 new mode 100644 index eabdbed..4e92c92 --- a/frameworks/resmgr/include/locale_matcher.h +++ b/frameworks/resmgr/include/locale_matcher.h @@ -14,18 +14,18 @@ */ #ifndef OHOS_RESOURCE_MANAGER_LOCALEMATCHER_H #define OHOS_RESOURCE_MANAGER_LOCALEMATCHER_H -#include "locale_info_impl.h" +#include "res_locale.h" namespace OHOS { namespace Global { namespace Resource { class LocaleMatcher { public: - static int8_t IsMoreSuitable(const LocaleInfoImpl *current, - const LocaleInfoImpl *other, - const LocaleInfoImpl *request); + static int8_t IsMoreSuitable(const ResLocale *current, + const ResLocale *other, + const ResLocale *request); - static bool Match(const LocaleInfoImpl *current, const LocaleInfoImpl *other); + static bool Match(const ResLocale *current, const ResLocale *other); static bool IsLanguageTag(const char *str, int32_t len); @@ -33,9 +33,9 @@ public: static bool IsRegionTag(const char *str, int32_t len); - static bool Normalize(LocaleInfoImpl *localeInfo); + static bool Normalize(ResLocale *resLocale); - static int8_t IsMoreSpecificThan(const LocaleInfoImpl *current, const LocaleInfoImpl *target); + static int8_t IsMoreSpecificThan(const ResLocale *current, const ResLocale *target); public: static uint64_t EN_US_ENCODE; diff --git a/frameworks/resmgr/include/lock.h b/frameworks/resmgr/include/lock.h old mode 100755 new mode 100644 diff --git a/frameworks/resmgr/include/res_config_impl.h b/frameworks/resmgr/include/res_config_impl.h old mode 100755 new mode 100644 index 79c889a..768384a --- a/frameworks/resmgr/include/res_config_impl.h +++ b/frameworks/resmgr/include/res_config_impl.h @@ -14,12 +14,12 @@ */ #ifndef OHOS_RESOURCE_MANAGER_RESCONFIG_IMPL_H #define OHOS_RESOURCE_MANAGER_RESCONFIG_IMPL_H - -#include "locale_info_impl.h" #include +#include "locale_info.h" +#include "res_locale.h" #include "res_common.h" #include "res_config.h" - +using OHOS::I18N::LocaleInfo; namespace OHOS { namespace Global { namespace Resource { @@ -31,6 +31,8 @@ public: RState SetLocaleInfo(const char *language, const char *script, const char *region); + RState SetLocaleInfo(LocaleInfo& localeInfo); + void SetDeviceType(DeviceType deviceType); void SetDirection(Direction direction); @@ -39,7 +41,7 @@ public: const LocaleInfo *GetLocaleInfo() const; - const LocaleInfoImpl *GetLocaleInfoImpl() const; + const ResLocale *GetResLocale() const; Direction GetDirection() const; @@ -59,13 +61,15 @@ public: private: bool IsMoreSpecificThan(const ResConfigImpl *other) const; + bool CopyLocale(ResConfig &other); private: - LocaleInfoImpl *localeInfo_; + ResLocale *resLocale_; Direction direction_; ScreenDensity screenDensity_; DeviceType deviceType_; bool isCompletedScript_; + LocaleInfo *localeInfo_; }; } // namespace Resource } // namespace Global diff --git a/frameworks/resmgr/include/res_desc.h b/frameworks/resmgr/include/res_desc.h old mode 100755 new mode 100644 index 816c7fd..18cdb6f --- a/frameworks/resmgr/include/res_desc.h +++ b/frameworks/resmgr/include/res_desc.h @@ -13,14 +13,14 @@ * limitations under the License. */ -#ifndef RESOURCE_MANAGER_INDEXDESC_H -#define RESOURCE_MANAGER_INDEXDESC_H +#ifndef OHOS_RESOURCE_MANAGER_RES_DESC_H +#define OHOS_RESOURCE_MANAGER_RES_DESC_H #include "res_common.h" +#include #include #include #include -#include namespace OHOS { namespace Global { diff --git a/frameworks/resmgr/include/locale_info_impl.h b/frameworks/resmgr/include/res_locale.h old mode 100755 new mode 100644 similarity index 52% rename from frameworks/resmgr/include/locale_info_impl.h rename to frameworks/resmgr/include/res_locale.h index 1c3b04a..2cff83a --- a/frameworks/resmgr/include/locale_info_impl.h +++ b/frameworks/resmgr/include/res_locale.h @@ -13,14 +13,14 @@ * limitations under the License. */ -#ifndef OHOS_RESOURCE_MANAGER_LOCALEINFO_IMPL_H -#define OHOS_RESOURCE_MANAGER_LOCALEINFO_IMPL_H +#ifndef OHOS_RESOURCE_MANAGER_RES_LOCALE_H +#define OHOS_RESOURCE_MANAGER_RES_LOCALE_H #include #include #include "rstate.h" #include "lock.h" #include "locale_info.h" - +using OHOS::I18N::LocaleInfo; namespace OHOS { namespace Global { namespace Resource { @@ -32,29 +32,29 @@ struct ParseResult { int16_t scriptTagLen = 0; int16_t regionTagLen = 0; }; -class LocaleInfoImpl : public LocaleInfo { +class ResLocale { public: - virtual const char* GetLanguage() const; + const char* GetLanguage() const; - virtual const char* GetRegion() const; + const char* GetRegion() const; - virtual const char* GetScript() const; + const char* GetScript() const; - LocaleInfoImpl(); + ResLocale(); - RState CopyImpl(const LocaleInfoImpl* other); + RState CopyFromLocaleInfo(const LocaleInfo *other); - RState Copy(const LocaleInfo* other); + RState Copy(const ResLocale *other); - static const LocaleInfoImpl* GetSysDefault(); + static const LocaleInfo* GetDefault(); - static bool UpdateSysDefault(const LocaleInfo& LocaleInfo, bool needNotify); + static bool UpdateDefault(const LocaleInfo& localeInfo, bool needNotify); - static LocaleInfoImpl* BuildFromString(const char* bcp47String, char sep, RState& rState); + static ResLocale* BuildFromString(const char *bcp47String, char sep, RState& rState); - static LocaleInfoImpl* BuildFromParts(const char* language, const char* script, const char* region, RState& rState); + static ResLocale* BuildFromParts(const char *language, const char *script, const char *region, RState& rState); - virtual ~LocaleInfoImpl(); + ~ResLocale(); static constexpr uint16_t END_TYPE = 0x0000; // language parse @@ -67,26 +67,26 @@ public: static constexpr size_t MIN_BCP47_STR_LEN = 2; private: - RState SetLanguage(const char* language, size_t len); + RState SetLanguage(const char *language, size_t len); - RState SetScript(const char* script, size_t len); + RState SetScript(const char *script, size_t len); - RState SetRegion(const char* region, size_t len); + RState SetRegion(const char *region, size_t len); - static LocaleInfoImpl* DoParse(const char* bcp47String, char sep, RState& rState); + static ResLocale* DoParse(const char *bcp47String, char sep, RState& rState); - static LocaleInfoImpl* CreateLocaleInfo(ParseResult& parseResult, RState& rState); + static ResLocale* CreateResLocale(ParseResult& parseResult, RState& rState); - RState Init(const char* language, size_t languageLen, const char* script, size_t scriptLen, - const char* region, size_t regionLen); + RState Init(const char *language, size_t languageLen, const char *script, size_t scriptLen, + const char *region, size_t regionLen); - const char* language_; + const char *language_; - const char* region_; + const char *region_; - const char* script_; + const char *script_; - static LocaleInfoImpl* defaultLocale_; + static LocaleInfo *defaultLocale_; static Lock lock_; @@ -96,4 +96,3 @@ private: } // namespace Global } // namespace OHOS #endif - diff --git a/frameworks/resmgr/include/resource_manager_impl.h b/frameworks/resmgr/include/resource_manager_impl.h old mode 100755 new mode 100644 index e229308..8ca90ac --- a/frameworks/resmgr/include/resource_manager_impl.h +++ b/frameworks/resmgr/include/resource_manager_impl.h @@ -15,11 +15,11 @@ #ifndef OHOS_RESOURCE_MANAGER_RESOURCEMANAGERIMPL_H #define OHOS_RESOURCE_MANAGER_RESOURCEMANAGERIMPL_H -#include "resource_manager.h" #include "hap_manager.h" +#include "resource_manager.h" +#include #include #include -#include namespace OHOS { namespace Global { @@ -40,19 +40,19 @@ public: virtual RState GetStringById(uint32_t id, std::string &outValue); - virtual RState GetStringByName(const char* name, std::string &outValue); + virtual RState GetStringByName(const char *name, std::string &outValue); virtual RState GetStringFormatById(std::string &outValue, uint32_t id, ...); - virtual RState GetStringFormatByName(std::string& outValue, const char* name, ...); + virtual RState GetStringFormatByName(std::string& outValue, const char *name, ...); virtual RState GetStringArrayById(uint32_t id, std::vector& outValue); - virtual RState GetStringArrayByName(const char* name, std::vector& outValue); + virtual RState GetStringArrayByName(const char *name, std::vector& outValue); virtual RState GetPatternById(uint32_t id, std::map& outValue); - virtual RState GetPatternByName(const char* name, std::map& outValue); + virtual RState GetPatternByName(const char *name, std::map& outValue); virtual RState GetPluralStringById(uint32_t id, int quantity, std::string &outValue); @@ -68,31 +68,31 @@ public: virtual RState GetBooleanById(uint32_t id, bool& outValue); - virtual RState GetBooleanByName(const char* name, bool& outValue); + virtual RState GetBooleanByName(const char *name, bool& outValue); virtual RState GetIntegerById(uint32_t id, int& outValue); - virtual RState GetIntegerByName(const char* name, int& outValue); + virtual RState GetIntegerByName(const char *name, int& outValue); virtual RState GetFloatById(uint32_t id, float& outValue); - virtual RState GetFloatByName(const char* name, float& outValue); + virtual RState GetFloatByName(const char *name, float& outValue); virtual RState GetIntArrayById(uint32_t id, std::vector& outValue); - virtual RState GetIntArrayByName(const char* name, std::vector& outValue); + virtual RState GetIntArrayByName(const char *name, std::vector& outValue); virtual RState GetColorById(uint32_t id, uint32_t& outValue); - virtual RState GetColorByName(const char* name, uint32_t& outValue); + virtual RState GetColorByName(const char *name, uint32_t& outValue); virtual RState GetProfileById(uint32_t id, std::string &outValue); - virtual RState GetProfileByName(const char* name, std::string &outValue); + virtual RState GetProfileByName(const char *name, std::string &outValue); virtual RState GetMediaById(uint32_t id, std::string &outValue); - virtual RState GetMediaByName(const char* name, std::string &outValue); + virtual RState GetMediaByName(const char *name, std::string &outValue); private: RState GetString(const IdItem *idItem, std::string &outValue); diff --git a/frameworks/resmgr/include/utils/common.h b/frameworks/resmgr/include/utils/common.h old mode 100755 new mode 100644 diff --git a/frameworks/resmgr/include/utils/date_utils.h b/frameworks/resmgr/include/utils/date_utils.h old mode 100755 new mode 100644 index 0345682..88024ae --- a/frameworks/resmgr/include/utils/date_utils.h +++ b/frameworks/resmgr/include/utils/date_utils.h @@ -33,7 +33,7 @@ namespace Resource { inline long CurrentTimeMillis() { struct timeval time; - gettimeofday(&time, NULL); + gettimeofday(&time, nullptr); return (time.tv_sec * KILO + time.tv_usec / KILO); } @@ -46,7 +46,7 @@ inline long CurrentTimeMillis() inline long CurrentTimeUsec() { struct timeval time; - gettimeofday(&time, NULL); + gettimeofday(&time, nullptr); return (time.tv_sec * MILLION + time.tv_usec); } } // namespace Resource diff --git a/frameworks/resmgr/include/utils/errors.h b/frameworks/resmgr/include/utils/errors.h old mode 100755 new mode 100644 index 08c9cc6..ed4e86c --- a/frameworks/resmgr/include/utils/errors.h +++ b/frameworks/resmgr/include/utils/errors.h @@ -13,7 +13,8 @@ * limitations under the License. */ -#pragma once +#ifndef OHOS_RESOURCE_MANAGER_ERRORS_H +#define OHOS_RESOURCE_MANAGER_ERRORS_H #include #include @@ -34,3 +35,4 @@ enum InnerState { } // namespace Resource } // namespace Global } // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/resmgr/include/utils/locale_data.h b/frameworks/resmgr/include/utils/locale_data.h old mode 100755 new mode 100644 diff --git a/frameworks/resmgr/include/utils/string_utils.h b/frameworks/resmgr/include/utils/string_utils.h old mode 100755 new mode 100644 diff --git a/frameworks/resmgr/include/utils/utils.h b/frameworks/resmgr/include/utils/utils.h old mode 100755 new mode 100644 index 5bc4a00..2538407 --- a/frameworks/resmgr/include/utils/utils.h +++ b/frameworks/resmgr/include/utils/utils.h @@ -16,7 +16,7 @@ #define OHOS_RESOURCE_MANAGER_UTILS_H #include #include -#include "locale_info.h" +#include "res_locale.h" #include "rstate.h" namespace OHOS { @@ -28,38 +28,28 @@ public: static bool IsNumericString(const char *s, int32_t len); - static void ToLower(char *s, int32_t len); - static bool IsStrEmpty(const char *s); static size_t StrLen(const char *s); - static int32_t FindIndex(const char * const *list, - size_t listLen, - const char *key, - int32_t keyLen, - bool isCaseSensitive); - static uint16_t EncodeLanguage(const char *language); - static uint16_t EncodeLanguageByLocaleInfo(const LocaleInfo *locale); + static uint16_t EncodeLanguageByResLocale(const ResLocale *locale); static uint32_t EncodeScript(const char *script); - static uint32_t EncodeScriptByLocaleInfo(const LocaleInfo *locale); + static uint32_t EncodeScriptByResLocale(const ResLocale *locale); static void DecodeScript(uint32_t encodeScript, char *outValue); static uint16_t EncodeRegion(const char *region); - static uint16_t EncodeRegionByLocaleInfo(const LocaleInfo *locale); + static uint16_t EncodeRegionByResLocale(const ResLocale *locale); static uint64_t EncodeLocale(const char *language, const char *script, const char *region); - static uint64_t EncodeLocaleByLocaleInfo(const LocaleInfo *locale); - static RState ConvertColorToUInt32(const char *s, uint32_t &outValue); private: diff --git a/frameworks/resmgr/src/hap_manager.cpp b/frameworks/resmgr/src/hap_manager.cpp old mode 100755 new mode 100644 index fed8f32..b5f5e40 --- a/frameworks/resmgr/src/hap_manager.cpp +++ b/frameworks/resmgr/src/hap_manager.cpp @@ -15,7 +15,7 @@ #include "hap_manager.h" #include -#include +#include #include "auto_mutex.h" #include "hilog_wrapper.h" @@ -31,64 +31,74 @@ HapManager::HapManager(ResConfigImpl *resConfig) { } -bool HapManager::icuInitialized = HapManager::Init(); - -bool HapManager::Init() +std::string ConvertToPluralStr(int idxRet) { - SetHwIcuDirectory(); - return true; + switch (idxRet) { + case OHOS::I18N::PluralRuleType::ZERO: + return "zero"; + case OHOS::I18N::PluralRuleType::ONE: + return "one"; + case OHOS::I18N::PluralRuleType::TWO: + return "two"; + case OHOS::I18N::PluralRuleType::FEW: + return "few"; + case OHOS::I18N::PluralRuleType::MANY: + return "many"; + case OHOS::I18N::PluralRuleType::OTHER: + default: + return "other"; + } } std::string HapManager::GetPluralRulesAndSelect(int quantity) { AutoMutex mutex(this->lock_); std::string defaultRet("other"); - if (this->resConfig_ == nullptr || this->resConfig_->GetLocaleInfo() == nullptr || - this->resConfig_->GetLocaleInfo()->GetLanguage() == nullptr) { + if (this->resConfig_ == nullptr || this->resConfig_->GetResLocale() == nullptr || + this->resConfig_->GetResLocale()->GetLanguage() == nullptr) { HILOG_ERROR("GetPluralRules language is null!"); return defaultRet; } - std::string language = this->resConfig_->GetLocaleInfo()->GetLanguage(); + std::string language = this->resConfig_->GetResLocale()->GetLanguage(); - icu::PluralRules *pluralRules = nullptr; + OHOS::I18N::PluralFormat *pluralFormat = nullptr; for (uint32_t i = 0; i < plurRulesCache_.size(); i++) { auto pair = plurRulesCache_[i]; if (language == pair.first) { // cache hit - pluralRules = pair.second; + pluralFormat = pair.second; break; } } - if (pluralRules == nullptr) { + OHOS::I18N::I18nStatus status = OHOS::I18N::I18nStatus::ISUCCESS; + if (pluralFormat == nullptr) { // no cache hit - icu::Locale locale(language.c_str()); - if (locale.isBogus()) { - HILOG_ERROR("icu::Locale init error : %s", language.c_str()); + OHOS::I18N::LocaleInfo locale(language.c_str(), "", ""); + pluralFormat = new(std::nothrow) OHOS::I18N::PluralFormat(locale, status); + if (pluralFormat == nullptr) { + HILOG_ERROR("new PluralFormat failed"); return defaultRet; } - UErrorCode status = U_ZERO_ERROR; - pluralRules = icu::PluralRules::forLocale(locale, status); - if (status != U_ZERO_ERROR) { - HILOG_ERROR("icu::PluralRules::forLocale error : %d", status); + if (status != OHOS::I18N::I18nStatus::ISUCCESS) { + HILOG_ERROR("PluralFormat init failed"); + delete pluralFormat; return defaultRet; } - // after PluralRules created, we add it to cache, if > 3 delete oldest one + // after pluralFormat created, we add it to cache, if > 3 delete oldest one if (plurRulesCache_.size() >= PLURAL_CACHE_MAX_COUNT) { HILOG_DEBUG("cache rotate delete plurRulesMap_ %s", plurRulesCache_[0].first.c_str()); delete (plurRulesCache_[0].second); plurRulesCache_.erase(plurRulesCache_.begin()); } - auto plPair = std::make_pair(language, pluralRules); + auto plPair = std::make_pair(language, pluralFormat); plurRulesCache_.push_back(plPair); } - std::string converted; - icu::UnicodeString us = pluralRules->select(quantity); - us.toUTF8String(converted); - return converted; + int idxRet = pluralFormat->GetPluralRuleIndex(quantity, status); + return ConvertToPluralStr(idxRet); } -const IdItem* HapManager::FindResourceById(uint32_t id) +const IdItem *HapManager::FindResourceById(uint32_t id) { auto qualifierValue = FindQualifierValueById(id); if (qualifierValue == nullptr) { @@ -97,7 +107,7 @@ const IdItem* HapManager::FindResourceById(uint32_t id) return qualifierValue->GetIdItem(); } -const IdItem* HapManager::FindResourceByName(const char *name, const ResType resType) +const IdItem *HapManager::FindResourceByName(const char *name, const ResType resType) { auto qualifierValue = FindQualifierValueByName(name, resType); if (qualifierValue == nullptr) { @@ -127,13 +137,11 @@ const HapResource::ValueUnderQualifierDir *HapManager::FindQualifierValueByName( if (bestResConfig == nullptr) { bestIndex = i; bestResConfig = resConfig; + } else if (bestResConfig->IsMoreSuitable(resConfig, currentResConfig)) { + continue; } else { - if (bestResConfig->IsMoreSuitable(resConfig, currentResConfig)) { - continue; - } else { - bestResConfig = resConfig; - bestIndex = i; - } + bestResConfig = resConfig; + bestIndex = i; } } } @@ -252,7 +260,7 @@ bool HapManager::AddResourcePath(const char *path) if (pResource == nullptr) { return false; } - this->hapResources_.push_back((HapResource *) pResource); + this->hapResources_.push_back((HapResource *)pResource); this->loadedHapPaths_.push_back(sPath); return true; } @@ -271,7 +279,7 @@ RState HapManager::ReloadAll() } return HAP_INIT_FAILED; } - newResources.push_back((HapResource *) pResource); + newResources.push_back((HapResource *)pResource); } for (size_t i = 0; i < hapResources_.size(); ++i) { delete (hapResources_[i]); diff --git a/frameworks/resmgr/src/hap_resource.cpp b/frameworks/resmgr/src/hap_resource.cpp old mode 100755 new mode 100644 index b58e109..8c6d6bb --- a/frameworks/resmgr/src/hap_resource.cpp +++ b/frameworks/resmgr/src/hap_resource.cpp @@ -18,9 +18,6 @@ #include #include -#include -#include - #include "hap_parser.h" #include "hilog_wrapper.h" #include "locale_matcher.h" @@ -101,7 +98,7 @@ const HapResource *HapResource::LoadFromIndex(const char *path, const ResConfigI HILOG_ERROR("Error allocating memory"); return nullptr; } - inFile2.read((char *) buf, bufLen); + inFile2.read((char *)buf, bufLen); inFile2.close(); HILOG_DEBUG("extract success, bufLen:%zu", bufLen); @@ -111,7 +108,7 @@ const HapResource *HapResource::LoadFromIndex(const char *path, const ResConfigI HILOG_ERROR("new ResDesc failed when LoadFromIndex"); return nullptr; } - int32_t out = HapParser::ParseResHex((char *) buf, bufLen, *resDesc, defaultConfig); + int32_t out = HapParser::ParseResHex((char *)buf, bufLen, *resDesc, defaultConfig); if (out != OK) { delete (resDesc); free(buf); diff --git a/frameworks/resmgr/src/likely_subtags_key_data.cpp b/frameworks/resmgr/src/likely_subtags_key_data.cpp old mode 100755 new mode 100644 diff --git a/frameworks/resmgr/src/likely_subtags_value_data.cpp b/frameworks/resmgr/src/likely_subtags_value_data.cpp old mode 100755 new mode 100644 diff --git a/frameworks/resmgr/src/locale_matcher.cpp b/frameworks/resmgr/src/locale_matcher.cpp old mode 100755 new mode 100644 index 9ff8d5b..0e0be8a --- a/frameworks/resmgr/src/locale_matcher.cpp +++ b/frameworks/resmgr/src/locale_matcher.cpp @@ -15,7 +15,7 @@ #include "locale_matcher.h" #include - +#include #include "likely_subtags_key_data.cpp" #include "likely_subtags_value_data.cpp" @@ -56,10 +56,10 @@ uint64_t AddScript(uint64_t encodedLocale, uint32_t encodedScript) * @param encodedLocale locale encode * @return uint64_t parent locale encode */ -uint64_t SearchParentLocale(uint64_t encodedLocale, const LocaleInfo *request) +uint64_t SearchParentLocale(uint64_t encodedLocale, const ResLocale *request) { uint64_t tempEncodedLocale = encodedLocale; - if (Utils::EncodeScriptByLocaleInfo(request) == LocaleMatcher::HANT_ENCODE) { + if (Utils::EncodeScriptByResLocale(request) == LocaleMatcher::HANT_ENCODE) { tempEncodedLocale = AddScript(encodedLocale, LocaleMatcher::HANT_ENCODE); if (tempEncodedLocale == LocaleMatcher::ZH_HANT_MO_ENCODE) { return LocaleMatcher::ZH_HK_ENCODE; @@ -84,7 +84,7 @@ uint64_t SearchParentLocale(uint64_t encodedLocale, const LocaleInfo *request) * @param len * @param encodedLocale */ -void FindTrackPath(uint64_t *result, size_t len, uint64_t encodedLocale, const LocaleInfo *request) +void FindTrackPath(const ResLocale *request, size_t len, uint64_t encodedLocale, uint64_t *result) { uint64_t currentEncodedLocale = encodedLocale; size_t i = 0; @@ -235,9 +235,9 @@ size_t ComputeTrackPathDistance(const uint64_t *requestPaths, return len * 2; } -int8_t CompareRegionWhenQaag(const LocaleInfo *current, - const LocaleInfo *other, - const LocaleInfo *request) +int8_t CompareRegionWhenQaag(const ResLocale *current, + const ResLocale *other, + const ResLocale *request) { if ((request != nullptr) && (Utils::EncodeLocale(request->GetLanguage(), request->GetScript(), nullptr) == LocaleMatcher::EN_QAAG_ENCODE)) { @@ -263,11 +263,11 @@ int8_t CompareRegionWhenQaag(const LocaleInfo *current, * @return true * @return false */ -bool CompareLanguage(const LocaleInfo *current, const LocaleInfo *other) +bool CompareLanguage(const ResLocale *current, const ResLocale *other) { uint16_t currentEncodedLanguage = - Utils::EncodeLanguageByLocaleInfo(current); - uint16_t otherEncodedLanguage = Utils::EncodeLanguageByLocaleInfo( + Utils::EncodeLanguageByResLocale(current); + uint16_t otherEncodedLanguage = Utils::EncodeLanguageByResLocale( other); return ((currentEncodedLanguage == otherEncodedLanguage) || ((currentEncodedLanguage == NEW_LANGUAGES_CODES[0]) @@ -292,7 +292,7 @@ bool CompareLanguage(const LocaleInfo *current, const LocaleInfo *other) && (currentEncodedLanguage == OLD_LANGUAGES_CODES[4]))); } -bool CompareScript(const LocaleInfo *current, const LocaleInfo *other) +bool CompareScript(const ResLocale *current, const ResLocale *other) { uint32_t currentEncodedScript = 0; uint32_t otherEncodedScript = 0; @@ -300,13 +300,13 @@ bool CompareScript(const LocaleInfo *current, const LocaleInfo *other) currentEncodedScript = FindDefaultScriptEncode(current->GetLanguage(), current->GetRegion()); } else { - currentEncodedScript = Utils::EncodeScriptByLocaleInfo(current); + currentEncodedScript = Utils::EncodeScriptByResLocale(current); } if ((other != nullptr) && (other->GetScript() == nullptr)) { otherEncodedScript = FindDefaultScriptEncode(other->GetLanguage(), other->GetRegion()); } else { - otherEncodedScript = Utils::EncodeScriptByLocaleInfo(other); + otherEncodedScript = Utils::EncodeScriptByResLocale(other); } if (current != nullptr && other != nullptr) { // when current locale is en-Qaag is equal en-Latn @@ -319,31 +319,21 @@ bool CompareScript(const LocaleInfo *current, const LocaleInfo *other) } } bool compareRegion = false; - if (current == nullptr || (current->GetScript() == nullptr)) { + if ((currentEncodedScript == LocaleMatcher::NULL_SCRIPT) || (otherEncodedScript== LocaleMatcher::NULL_SCRIPT)) { // if request script is null, region must be same compareRegion = true; - } else { - if (other == nullptr) { - compareRegion = true; - } else { - if (other->GetScript() == nullptr) { - if (currentEncodedScript == LocaleMatcher::NULL_SCRIPT) { - compareRegion = true; - } - } - } } if (compareRegion) { - uint16_t currentRegionEncode = Utils::EncodeRegionByLocaleInfo(current); - uint16_t otherRegionEncode = Utils::EncodeRegionByLocaleInfo(other); + uint16_t currentRegionEncode = Utils::EncodeRegionByResLocale(current); + uint16_t otherRegionEncode = Utils::EncodeRegionByResLocale(other); return (otherRegionEncode == LocaleMatcher::NULL_REGION) || (currentRegionEncode == otherRegionEncode); } return currentEncodedScript == otherEncodedScript; } -int8_t AlphabeticallyCompare(const LocaleInfo *current, +int8_t AlphabeticallyCompare(const ResLocale *current, uint64_t currentEncodedLocale, - const LocaleInfo *other, + const ResLocale *other, uint64_t otherEncodedLocale) { if (currentEncodedLocale == otherEncodedLocale) { @@ -377,9 +367,9 @@ int8_t AlphabeticallyCompare(const LocaleInfo *current, } int8_t CompareWhenRegionIsNull(uint16_t currentEncodedRegion, uint16_t otherEncodedRegion, - const LocaleInfo *current, - const LocaleInfo *other, - const LocaleInfo *request) + const ResLocale *current, + const ResLocale *other, + const ResLocale *request) { if (current == nullptr || current->GetRegion() == nullptr) { return 1; @@ -410,12 +400,12 @@ int8_t CompareWhenRegionIsNull(uint16_t currentEncodedRegion, uint16_t otherEnco } int8_t CompareDistance(uint64_t currentEncodedLocale, uint64_t otherEncodedLocale, - const uint64_t *requestEncodedTrackPath, const LocaleInfo *request) + const uint64_t *requestEncodedTrackPath, const ResLocale *request) { uint64_t currentEncodedTrackPath[LocaleMatcher::TRACKPATH_ARRAY_SIZE] = {0, 0, 0, 0, 0}; - FindTrackPath(currentEncodedTrackPath, LocaleMatcher::TRACKPATH_ARRAY_SIZE, currentEncodedLocale, request); + FindTrackPath(request, LocaleMatcher::TRACKPATH_ARRAY_SIZE, currentEncodedLocale, currentEncodedTrackPath); uint64_t otherEncodedTrackPath[LocaleMatcher::TRACKPATH_ARRAY_SIZE] = {0, 0, 0, 0, 0}; - FindTrackPath(otherEncodedTrackPath, LocaleMatcher::TRACKPATH_ARRAY_SIZE, otherEncodedLocale, request); + FindTrackPath(request, LocaleMatcher::TRACKPATH_ARRAY_SIZE, otherEncodedLocale, otherEncodedTrackPath); const size_t currentDistance = ComputeTrackPathDistance( requestEncodedTrackPath, currentEncodedTrackPath, LocaleMatcher::TRACKPATH_ARRAY_SIZE); const size_t targetDistance = ComputeTrackPathDistance( @@ -429,9 +419,9 @@ int8_t CompareDistance(uint64_t currentEncodedLocale, uint64_t otherEncodedLocal return 0; } -int8_t CompareDefaultRegion(const LocaleInfo *current, - const LocaleInfo *other, - const LocaleInfo *request) +int8_t CompareDefaultRegion(const ResLocale *current, + const ResLocale *other, + const ResLocale *request) { int8_t qaagResult = CompareRegionWhenQaag(current, other, request); if (qaagResult != 0) { @@ -461,19 +451,19 @@ int8_t CompareDefaultRegion(const LocaleInfo *current, * @return int8_t if current region is better than target region,return 1. if current region is equal target region, * return 0. If target region is better than current region, return -1. */ -int8_t CompareRegion(const LocaleInfo *current, - const LocaleInfo *other, - const LocaleInfo *request) +int8_t CompareRegion(const ResLocale *current, + const ResLocale *other, + const ResLocale *request) { - uint16_t currentEncodedRegion = Utils::EncodeRegionByLocaleInfo(current); - uint16_t otherEncodedRegion = Utils::EncodeRegionByLocaleInfo(other); + uint16_t currentEncodedRegion = Utils::EncodeRegionByResLocale(current); + uint16_t otherEncodedRegion = Utils::EncodeRegionByResLocale(other); if (request == nullptr || request->GetRegion() == nullptr) { return CompareWhenRegionIsNull(currentEncodedRegion, otherEncodedRegion, current, other, request); } uint64_t requestEncodedLocale = Utils::EncodeLocale( request->GetLanguage(), nullptr, request->GetRegion()); uint64_t requestEncodedTrackPath[LocaleMatcher::TRACKPATH_ARRAY_SIZE] = {0, 0, 0, 0, 0}; - FindTrackPath(requestEncodedTrackPath, LocaleMatcher::TRACKPATH_ARRAY_SIZE, requestEncodedLocale, request); + FindTrackPath(request, LocaleMatcher::TRACKPATH_ARRAY_SIZE, requestEncodedLocale, requestEncodedTrackPath); uint64_t currentEncodedLocale = Utils::EncodeLocale( request->GetLanguage(), nullptr, (current == nullptr) ? nullptr : current->GetRegion()); uint64_t otherEncodedLocale = Utils::EncodeLocale( @@ -511,7 +501,7 @@ int8_t CompareRegion(const LocaleInfo *current, return AlphabeticallyCompare(current, currentEncodedLocale, other, otherEncodedLocale); } -bool LocaleMatcher::Match(const LocaleInfoImpl *current, const LocaleInfoImpl *other) +bool LocaleMatcher::Match(const ResLocale *current, const ResLocale *other) { if (current == nullptr || other == nullptr) { return true; @@ -524,7 +514,7 @@ bool LocaleMatcher::Match(const LocaleInfoImpl *current, const LocaleInfoImpl *o return CompareScript(current, other); }; -bool LocaleMatcher::Normalize(LocaleInfoImpl *localeInfo) +bool LocaleMatcher::Normalize(ResLocale *localeInfo) { if (localeInfo == nullptr) { return true; @@ -547,23 +537,26 @@ bool LocaleMatcher::Normalize(LocaleInfoImpl *localeInfo) return true; } -int8_t CompareLanguageIgnoreOldNewCode(const LocaleInfo *current, const LocaleInfo *other, const LocaleInfo *request) +int8_t CompareLanguageIgnoreOldNewCode(const ResLocale *current, const ResLocale *other, const ResLocale *request) { - uint16_t currentLanguageEncode = Utils::EncodeLanguageByLocaleInfo(current); - uint16_t otherLanguageEncode = Utils::EncodeLanguageByLocaleInfo(other); - uint16_t requestLanguageEncode = Utils::EncodeLanguageByLocaleInfo(request); + uint16_t currentLanguageEncode = Utils::EncodeLanguageByResLocale(current); + uint16_t otherLanguageEncode = Utils::EncodeLanguageByResLocale(other); + uint16_t requestLanguageEncode = Utils::EncodeLanguageByResLocale(request); if ((currentLanguageEncode == requestLanguageEncode) && (otherLanguageEncode != requestLanguageEncode)) { return 1; } - return -1; + if ((otherLanguageEncode == requestLanguageEncode) && (currentLanguageEncode != requestLanguageEncode)) { + return -1; + } + return 0; } -bool IsSimilarToUsEnglish(const LocaleInfoImpl *localeInfo) +bool IsSimilarToUsEnglish(const ResLocale *localeInfo) { uint64_t localeEncode = Utils::EncodeLocale("en", nullptr, (localeInfo == nullptr) ? nullptr : localeInfo->GetRegion()); uint64_t loclaeEncodedTrackPath[LocaleMatcher::TRACKPATH_ARRAY_SIZE] = {0, 0, 0, 0, 0}; - FindTrackPath(loclaeEncodedTrackPath, LocaleMatcher::TRACKPATH_ARRAY_SIZE, localeEncode, nullptr); + FindTrackPath(nullptr, LocaleMatcher::TRACKPATH_ARRAY_SIZE, localeEncode, loclaeEncodedTrackPath); uint8_t len = LocaleMatcher::TRACKPATH_ARRAY_SIZE; for (uint8_t i = 0; i < len; ++i) { if (loclaeEncodedTrackPath[i] == Utils::EncodeLocale("en", nullptr, nullptr)) { @@ -575,9 +568,9 @@ bool IsSimilarToUsEnglish(const LocaleInfoImpl *localeInfo) } return false; } -bool CompareRegionWhenLangIsNotEqual(const LocaleInfoImpl *current, - const LocaleInfoImpl *other, - const LocaleInfoImpl *request) +bool CompareRegionWhenLangIsNotEqual(const ResLocale *current, + const ResLocale *other, + const ResLocale *request) { int8_t qaagResult = CompareRegionWhenQaag(current, other, request); if (qaagResult != 0) { @@ -604,9 +597,9 @@ bool CompareRegionWhenLangIsNotEqual(const LocaleInfoImpl *current, return current != nullptr; } -int8_t LocaleMatcher::IsMoreSuitable(const LocaleInfoImpl *current, - const LocaleInfoImpl *other, - const LocaleInfoImpl *request) +int8_t LocaleMatcher::IsMoreSuitable(const ResLocale *current, + const ResLocale *other, + const ResLocale *request) { if (request == nullptr) { return 0; @@ -621,15 +614,15 @@ int8_t LocaleMatcher::IsMoreSuitable(const LocaleInfoImpl *current, return (result == true) ? 1 : -1; } uint16_t currentEncodedRegion = - Utils::EncodeRegionByLocaleInfo(current); + Utils::EncodeRegionByResLocale(current); uint16_t otherEncodedRegion = - Utils::EncodeRegionByLocaleInfo(other); + Utils::EncodeRegionByResLocale(other); if (currentEncodedRegion == otherEncodedRegion) { // same language,same script,same region return CompareLanguageIgnoreOldNewCode(current, other, request); } // equal request region is better - uint16_t requestEncodedRegion = Utils::EncodeRegionByLocaleInfo(request); + uint16_t requestEncodedRegion = Utils::EncodeRegionByResLocale(request); if (currentEncodedRegion == requestEncodedRegion) { return 1; } @@ -703,7 +696,7 @@ bool LocaleMatcher::IsRegionTag(const char *str, int32_t len) return false; } -int8_t LocaleMatcher::IsMoreSpecificThan(const LocaleInfoImpl *current, const LocaleInfoImpl *other) +int8_t LocaleMatcher::IsMoreSpecificThan(const ResLocale *current, const ResLocale *other) { // compare language if (current == nullptr && other == nullptr) { diff --git a/frameworks/resmgr/src/lock.cpp b/frameworks/resmgr/src/lock.cpp old mode 100755 new mode 100644 index a79c8fb..b7dfb85 --- a/frameworks/resmgr/src/lock.cpp +++ b/frameworks/resmgr/src/lock.cpp @@ -30,7 +30,7 @@ bool Lock::lock() bool Lock::unlock() { - return false; + return true; } } // namespace Resource } // namespace Global diff --git a/frameworks/resmgr/src/res_config_impl.cpp b/frameworks/resmgr/src/res_config_impl.cpp old mode 100755 new mode 100644 index c8de048..db1e5b7 --- a/frameworks/resmgr/src/res_config_impl.cpp +++ b/frameworks/resmgr/src/res_config_impl.cpp @@ -13,45 +13,63 @@ * limitations under the License. */ #include "res_config_impl.h" -#include "locale_info_impl.h" + +#include "locale_info.h" #include "locale_matcher.h" +#include "res_locale.h" #include "utils/utils.h" + namespace OHOS { namespace Global { namespace Resource { ResConfigImpl::ResConfigImpl() - : localeInfo_(nullptr), + : resLocale_(nullptr), direction_(DIRECTION_NOT_SET), screenDensity_(SCREEN_DENSITY_NOT_SET), deviceType_(DEVICE_NOT_SET), - isCompletedScript_(false) + isCompletedScript_(false), localeInfo_(nullptr) {} +RState ResConfigImpl::SetLocaleInfo(LocaleInfo& localeInfo) +{ + return this->SetLocaleInfo(localeInfo.GetLanguage(), localeInfo.GetScript(), localeInfo.GetRegion()); +} + RState ResConfigImpl::SetLocaleInfo(const char *language, const char *script, const char *region) { RState state = SUCCESS; if (Utils::IsStrEmpty(language)) { + delete this->resLocale_; delete this->localeInfo_; + this->resLocale_ = nullptr; this->localeInfo_ = nullptr; return state; } - LocaleInfoImpl *localeInfo = - LocaleInfoImpl::BuildFromParts(language, script, region, state); + ResLocale *resLocale = + ResLocale::BuildFromParts(language, script, region, state); if (state == SUCCESS) { - delete localeInfo_; - localeInfo_ = localeInfo; this->isCompletedScript_ = false; if (script == nullptr || script[0] == '\0') { - if (LocaleMatcher::Normalize(localeInfo_)) { + if (LocaleMatcher::Normalize(resLocale)) { this->isCompletedScript_ = true; } else { - delete localeInfo_; - localeInfo_ = nullptr; + delete resLocale; return NOT_ENOUGH_MEM; } } + LocaleInfo *tempLocale = new(std::nothrow) LocaleInfo(resLocale->GetLanguage(), + resLocale->GetScript(), resLocale->GetRegion()); + if (tempLocale == nullptr) { + state = NOT_ENOUGH_MEM; + delete resLocale; + return state; + } + delete resLocale_; + delete localeInfo_; + resLocale_ = resLocale; + localeInfo_ = tempLocale; } return state; @@ -74,12 +92,12 @@ void ResConfigImpl::SetScreenDensity(ScreenDensity screenDensity) const LocaleInfo *ResConfigImpl::GetLocaleInfo() const { - return this->localeInfo_; + return localeInfo_; } -const LocaleInfoImpl *ResConfigImpl::GetLocaleInfoImpl() const +const ResLocale *ResConfigImpl::GetResLocale() const { - return this->localeInfo_; + return this->resLocale_; } Direction ResConfigImpl::GetDirection() const @@ -96,36 +114,59 @@ DeviceType ResConfigImpl::GetDeviceType() const { return this->deviceType_; } - -bool ResConfigImpl::Copy(ResConfig &other) +bool ResConfigImpl::CopyLocale(ResConfig &other) { + bool needCopy = false; if (this->GetLocaleInfo() == nullptr && other.GetLocaleInfo() != nullptr) { - LocaleInfoImpl* temp = new(std::nothrow) LocaleInfoImpl; - if (temp == nullptr) { - return false; - } - RState rs = temp->Copy(other.GetLocaleInfo()); - if (rs != SUCCESS) { - delete temp; - return false; - } - this->localeInfo_ = temp; + needCopy = true; } if (this->GetLocaleInfo() != nullptr && other.GetLocaleInfo() == nullptr) { + delete this->resLocale_; delete this->localeInfo_; + this->resLocale_ = nullptr; this->localeInfo_ = nullptr; + return true; } - if (this->GetLocaleInfo() != nullptr && other.GetLocaleInfo() != nullptr) { + if (this->GetResLocale() != nullptr && other.GetLocaleInfo() != nullptr) { uint64_t encodedLocale = Utils::EncodeLocale( - this->GetLocaleInfo()->GetLanguage(), - this->GetLocaleInfo()->GetScript(), this->GetLocaleInfo()->GetRegion()); + this->GetResLocale()->GetLanguage(), + this->GetResLocale()->GetScript(), this->GetResLocale()->GetRegion()); uint64_t otherEncodedLocale = Utils::EncodeLocale( other.GetLocaleInfo()->GetLanguage(), other.GetLocaleInfo()->GetScript(), other.GetLocaleInfo()->GetRegion()); if (encodedLocale != otherEncodedLocale) { - this->localeInfo_->Copy(other.GetLocaleInfo()); + needCopy = true; } } + if (needCopy) { + ResLocale *temp = new(std::nothrow) ResLocale; + if (temp == nullptr) { + return false; + } + RState rs = temp->CopyFromLocaleInfo(other.GetLocaleInfo()); + if (rs != SUCCESS) { + delete temp; + return false; + } + LocaleInfo *tempLocale = new(std::nothrow) LocaleInfo(*other.GetLocaleInfo()); + if (tempLocale == nullptr) { + delete tempLocale; + delete temp; + return false; + } + delete this->resLocale_; + delete this->localeInfo_; + this->resLocale_ = temp; + this->localeInfo_ = tempLocale; + } + return true; +} +bool ResConfigImpl::Copy(ResConfig &other) +{ + bool isSuccess = this->CopyLocale(other); + if (!isSuccess) { + return false; + } if (this->GetDeviceType() != other.GetDeviceType()) { this->SetDeviceType(other.GetDeviceType()); } @@ -140,7 +181,7 @@ bool ResConfigImpl::Copy(ResConfig &other) bool ResConfigImpl::Match(const ResConfigImpl *other) const { - if (LocaleMatcher::Match(this->localeInfo_, other->GetLocaleInfoImpl()) == + if (LocaleMatcher::Match(this->resLocale_, other->GetResLocale()) == false) { return false; } @@ -171,8 +212,8 @@ bool ResConfigImpl::IsMoreSuitable(const ResConfigImpl *other, { if (request != nullptr) { int8_t result = - LocaleMatcher::IsMoreSuitable(this->GetLocaleInfoImpl(), other->GetLocaleInfoImpl(), - request->GetLocaleInfoImpl()); + LocaleMatcher::IsMoreSuitable(this->GetResLocale(), other->GetResLocale(), + request->GetResLocale()); if (result > 0) { return true; } @@ -207,13 +248,13 @@ bool ResConfigImpl::IsMoreSuitable(const ResConfigImpl *other, } return (thisDistance >= otherDistance); } - return true; } return this->IsMoreSpecificThan(other); } ResConfigImpl::~ResConfigImpl() { + delete resLocale_; delete localeInfo_; } @@ -222,7 +263,7 @@ void ResConfigImpl::CompleteScript() if (isCompletedScript_) { return; } - if (LocaleMatcher::Normalize(this->localeInfo_)) { + if (LocaleMatcher::Normalize(this->resLocale_)) { isCompletedScript_ = true; } } @@ -238,8 +279,8 @@ bool ResConfigImpl::IsMoreSpecificThan(const ResConfigImpl *other) const return true; } int8_t result = LocaleMatcher::IsMoreSpecificThan( - this->GetLocaleInfoImpl(), - (other == nullptr) ? nullptr : other->GetLocaleInfoImpl()); + this->GetResLocale(), + (other == nullptr) ? nullptr : other->GetResLocale()); if (result > 0) { return true; } @@ -260,7 +301,7 @@ bool ResConfigImpl::IsMoreSpecificThan(const ResConfigImpl *other) const ResConfig *CreateResConfig() { - ResConfigImpl* temp = new(std::nothrow) ResConfigImpl; + ResConfigImpl *temp = new(std::nothrow) ResConfigImpl; return temp; } } // namespace Resource diff --git a/frameworks/resmgr/src/res_desc.cpp b/frameworks/resmgr/src/res_desc.cpp old mode 100755 new mode 100644 index 05f0a2a..7ea5516 --- a/frameworks/resmgr/src/res_desc.cpp +++ b/frameworks/resmgr/src/res_desc.cpp @@ -21,7 +21,6 @@ #include "utils/common.h" #include "utils/string_utils.h" - namespace OHOS { namespace Global { namespace Resource { diff --git a/frameworks/resmgr/src/locale_info_impl.cpp b/frameworks/resmgr/src/res_locale.cpp old mode 100755 new mode 100644 similarity index 60% rename from frameworks/resmgr/src/locale_info_impl.cpp rename to frameworks/resmgr/src/res_locale.cpp index ba6e244..14dc22b --- a/frameworks/resmgr/src/locale_info_impl.cpp +++ b/frameworks/resmgr/src/res_locale.cpp @@ -13,15 +13,17 @@ * limitations under the License. */ -#include "locale_info_impl.h" +#include "res_locale.h" #include #include #include +#include #include "auto_mutex.h" #include "hilog_wrapper.h" #include "locale_matcher.h" +#include "res_config.h" #include "rstate.h" #include "utils/common.h" #include "utils/utils.h" @@ -29,21 +31,21 @@ namespace OHOS { namespace Global { namespace Resource { -LocaleInfoImpl* LocaleInfoImpl::defaultLocale_ = nullptr; -Lock LocaleInfoImpl::lock_ = Lock(); +LocaleInfo *ResLocale::defaultLocale_ = nullptr; +Lock ResLocale::lock_ = Lock(); -LocaleInfoImpl::LocaleInfoImpl() : language_(nullptr), region_(nullptr), script_(nullptr) +ResLocale::ResLocale() : language_(nullptr), region_(nullptr), script_(nullptr) { } -RState LocaleInfoImpl::SetLanguage(const char* language, size_t len) +RState ResLocale::SetLanguage(const char *language, size_t len) { if (len == 0) { delete this->language_; this->language_ = nullptr; return SUCCESS; } - char* temp = new(std::nothrow) char[len + 1]; + char *temp = new(std::nothrow) char[len + 1]; if (temp == nullptr) { return NOT_ENOUGH_MEM; } @@ -58,14 +60,14 @@ RState LocaleInfoImpl::SetLanguage(const char* language, size_t len) return SUCCESS; } -RState LocaleInfoImpl::SetRegion(const char* region, size_t len) +RState ResLocale::SetRegion(const char *region, size_t len) { if (len == 0) { delete this->region_; this->region_ = nullptr; return SUCCESS; } - char* temp = new(std::nothrow) char[len + 1]; + char *temp = new(std::nothrow) char[len + 1]; if (temp == nullptr) { return NOT_ENOUGH_MEM; } @@ -80,14 +82,14 @@ RState LocaleInfoImpl::SetRegion(const char* region, size_t len) return SUCCESS; } -RState LocaleInfoImpl::SetScript(const char* script, size_t len) +RState ResLocale::SetScript(const char *script, size_t len) { if (len == 0) { delete this->script_; this->script_ = nullptr; return SUCCESS; } - char* temp = new(std::nothrow) char[len + 1]; + char *temp = new(std::nothrow) char[len + 1]; if (temp == nullptr) { return NOT_ENOUGH_MEM; } @@ -106,8 +108,8 @@ RState LocaleInfoImpl::SetScript(const char* script, size_t len) return SUCCESS; } -RState LocaleInfoImpl::Init(const char* language, size_t languageLen, const char* script, size_t scriptLen, - const char* region, size_t regionLen) +RState ResLocale::Init(const char *language, size_t languageLen, const char *script, size_t scriptLen, + const char *region, size_t regionLen) { RState r = this->SetLanguage(language, languageLen); if (r != SUCCESS) { @@ -124,57 +126,57 @@ RState LocaleInfoImpl::Init(const char* language, size_t languageLen, const char return SUCCESS; } -RState LocaleInfoImpl::Copy(const LocaleInfo* other) +RState ResLocale::CopyFromLocaleInfo(const LocaleInfo *other) { return this->Init(other->GetLanguage(), Utils::StrLen(other->GetLanguage()), other->GetScript(), Utils::StrLen(other->GetScript()), other->GetRegion(), Utils::StrLen(other->GetRegion())); } -RState LocaleInfoImpl::CopyImpl(const LocaleInfoImpl* other) +RState ResLocale::Copy(const ResLocale *other) { return this->Init(other->GetLanguage(), Utils::StrLen(other->GetLanguage()), other->GetScript(), Utils::StrLen(other->GetScript()), other->GetRegion(), Utils::StrLen(other->GetRegion())); } -const char* LocaleInfoImpl::GetLanguage() const +const char *ResLocale::GetLanguage() const { return this->language_; } -const char* LocaleInfoImpl::GetRegion() const +const char *ResLocale::GetRegion() const { return this->region_; } -const char* LocaleInfoImpl::GetScript() const +const char *ResLocale::GetScript() const { return this->script_; } -RState ProcessSubtag(const char* curPos, int32_t subTagLen, uint16_t& nextType, ParseResult& r) +RState ProcessSubtag(const char *curPos, int32_t subTagLen, uint16_t& nextType, ParseResult& r) { - if ((LocaleInfoImpl::LANG_TYPE & nextType) && (LocaleMatcher::IsLanguageTag(curPos, subTagLen))) { + if ((ResLocale::LANG_TYPE & nextType) && (LocaleMatcher::IsLanguageTag(curPos, subTagLen))) { r.tempLanguage = curPos; r.languageTagLen = subTagLen; - nextType = LocaleInfoImpl::SCRIPT_TYPE | LocaleInfoImpl::REGION_TYPE; + nextType = ResLocale::SCRIPT_TYPE | ResLocale::REGION_TYPE; return SUCCESS; } - if ((LocaleInfoImpl::SCRIPT_TYPE & nextType) && LocaleMatcher::IsScriptTag(curPos, subTagLen)) { + if ((ResLocale::SCRIPT_TYPE & nextType) && LocaleMatcher::IsScriptTag(curPos, subTagLen)) { r.tempScript = curPos; r.scriptTagLen = subTagLen; - nextType = LocaleInfoImpl::REGION_TYPE; + nextType = ResLocale::REGION_TYPE; return SUCCESS; } - if ((LocaleInfoImpl::REGION_TYPE & nextType) && LocaleMatcher::IsRegionTag(curPos, subTagLen)) { + if ((ResLocale::REGION_TYPE & nextType) && LocaleMatcher::IsRegionTag(curPos, subTagLen)) { r.tempRegion = curPos; r.regionTagLen = subTagLen; - nextType = LocaleInfoImpl::END_TYPE; + nextType = ResLocale::END_TYPE; return SUCCESS; } return ERROR; } -void CheckArg(const char* str, char sep, RState& rState) +void CheckArg(char sep, RState &rState) { rState = SUCCESS; if (sep != DASH_SEP && sep != UNDERLINE_SEP) { @@ -182,33 +184,33 @@ void CheckArg(const char* str, char sep, RState& rState) } } -LocaleInfoImpl* LocaleInfoImpl::CreateLocaleInfo(ParseResult& r, RState& rState) +ResLocale *ResLocale::CreateResLocale(ParseResult& r, RState& rState) { - LocaleInfoImpl* localeInfo = new (std::nothrow) LocaleInfoImpl; - if (localeInfo == nullptr) { + ResLocale *resLocale = new(std::nothrow) ResLocale; + if (resLocale == nullptr) { rState = NOT_ENOUGH_MEM; return nullptr; } - rState = localeInfo->Init(r.tempLanguage, r.languageTagLen, r.tempScript, r.scriptTagLen, + rState = resLocale->Init(r.tempLanguage, r.languageTagLen, r.tempScript, r.scriptTagLen, r.tempRegion, r.regionTagLen); if (rState == SUCCESS) { - return localeInfo; + return resLocale; } - delete localeInfo; + delete resLocale; return nullptr; } -LocaleInfoImpl* LocaleInfoImpl::DoParse(const char* str, char sep, RState& rState) +ResLocale *ResLocale::DoParse(const char *str, char sep, RState &rState) { uint16_t nextType = LANG_TYPE; - const char* nextPos = str; - const char* curPos = nextPos; + const char *nextPos = str; + const char *curPos = nextPos; ParseResult r; while (nextPos) { if (nextType == END_TYPE) { break; } - const char* pSep = nextPos; + const char *pSep = nextPos; curPos = nextPos; while (*pSep) { if (*pSep == sep) { @@ -243,12 +245,12 @@ LocaleInfoImpl* LocaleInfoImpl::DoParse(const char* str, char sep, RState& rStat return nullptr; } } - return CreateLocaleInfo(r, rState); + return CreateResLocale(r, rState); } -LocaleInfoImpl* LocaleInfoImpl::BuildFromString(const char* str, char sep, RState& rState) +ResLocale *ResLocale::BuildFromString(const char *str, char sep, RState &rState) { - CheckArg(str, sep, rState); + CheckArg(sep, rState); if (rState != SUCCESS) { return nullptr; } @@ -259,10 +261,10 @@ LocaleInfoImpl* LocaleInfoImpl::BuildFromString(const char* str, char sep, RStat return DoParse(str, sep, rState); } // end of ParseBCP47Tag -LocaleInfoImpl* LocaleInfoImpl::BuildFromParts(const char* language, - const char* script, - const char* region, - RState& rState) +ResLocale *ResLocale::BuildFromParts(const char *language, + const char *script, + const char *region, + RState &rState) { size_t len = Utils::StrLen(language); if (len == 0) { @@ -270,9 +272,9 @@ LocaleInfoImpl* LocaleInfoImpl::BuildFromParts(const char* language, return nullptr; } - const char* tempLanguage = nullptr; - const char* tempScript = nullptr; - const char* tempRegion = nullptr; + const char *tempLanguage = nullptr; + const char *tempScript = nullptr; + const char *tempRegion = nullptr; size_t languageTagLen = 0; size_t scriptTagLen = 0; size_t regionTagLen = 0; @@ -304,69 +306,103 @@ LocaleInfoImpl* LocaleInfoImpl::BuildFromParts(const char* language, return nullptr; } } - LocaleInfoImpl* localeInfo = new(std::nothrow) LocaleInfoImpl; - if (localeInfo == nullptr) { + ResLocale *resLocale = new(std::nothrow) ResLocale; + if (resLocale == nullptr) { rState = NOT_ENOUGH_MEM; return nullptr; } - rState = localeInfo->Init(tempLanguage, languageTagLen, tempScript, scriptTagLen, tempRegion, regionTagLen); + rState = resLocale->Init(tempLanguage, languageTagLen, tempScript, scriptTagLen, tempRegion, regionTagLen); if (rState == SUCCESS) { - return localeInfo; + return resLocale; } - delete localeInfo; + delete resLocale; return nullptr; }; -const LocaleInfoImpl* LocaleInfoImpl::GetSysDefault() +const LocaleInfo *ResLocale::GetDefault() { - AutoMutex mutex(LocaleInfoImpl::lock_); - return LocaleInfoImpl::defaultLocale_; + AutoMutex mutex(ResLocale::lock_); + return ResLocale::defaultLocale_; } -bool LocaleInfoImpl::UpdateSysDefault(const LocaleInfo& localeInfo, - bool needNotify) +bool ResLocale::UpdateDefault(const LocaleInfo& localeInfo, bool needNotify) { - AutoMutex mutex(LocaleInfoImpl::lock_); - LocaleInfoImpl* temp = new(std::nothrow) LocaleInfoImpl; + AutoMutex mutex(ResLocale::lock_); + LocaleInfo *temp = new(std::nothrow) LocaleInfo(localeInfo.GetLanguage(), + localeInfo.GetScript(), localeInfo.GetRegion()); if (temp == nullptr) { return false; } - RState rs = temp->Init(localeInfo.GetLanguage(), Utils::StrLen(localeInfo.GetLanguage()), localeInfo.GetScript(), - Utils::StrLen(localeInfo.GetScript()), localeInfo.GetRegion(), Utils::StrLen(localeInfo.GetRegion())); - if (rs == SUCCESS) { - delete LocaleInfoImpl::defaultLocale_; - LocaleInfoImpl::defaultLocale_ = temp; - return true; - } - delete temp; - return false; + delete ResLocale::defaultLocale_; + ResLocale::defaultLocale_ = temp; + return true; }; -LocaleInfoImpl::~LocaleInfoImpl() +ResLocale::~ResLocale() { delete this->language_; delete this->script_; delete this->region_; } -LocaleInfo* BuildFromString(const char* str, char sep, RState& rState) +LocaleInfo *BuildFromString(const char *str, char sep, RState& rState) { - return LocaleInfoImpl::BuildFromString(str, sep, rState); + ResLocale *resLocale = ResLocale::BuildFromString(str, sep, rState); + if (rState == SUCCESS) { + LocaleInfo *localeInfo = new(std::nothrow) LocaleInfo(resLocale->GetLanguage(), + resLocale->GetScript(), resLocale->GetRegion()); + if (localeInfo == nullptr) { + delete resLocale; + rState = ERROR; + return nullptr; + } + return localeInfo; + } + return nullptr; }; -LocaleInfo* BuildFromParts(const char* language, const char* script, const char* region, RState& rState) +LocaleInfo *BuildFromParts(const char *language, const char *script, const char *region, RState& rState) { - return LocaleInfoImpl::BuildFromParts(language, script, region, rState); + size_t len = Utils::StrLen(language); + if (len == 0) { + rState = INVALID_BCP47_LANGUAGE_SUBTAG; + return nullptr; + } + if (LocaleMatcher::IsLanguageTag(language, len) == false) { + rState = INVALID_BCP47_LANGUAGE_SUBTAG; + return nullptr; + } + + len = Utils::StrLen(script); + if (len > 0) { + if (LocaleMatcher::IsScriptTag(script, len) == 0) { + rState = INVALID_BCP47_SCRIPT_SUBTAG; + return nullptr; + } + } + len = Utils::StrLen(region); + if (len > 0) { + if (LocaleMatcher::IsRegionTag(region, len) == 0) { + rState = INVALID_BCP47_REGION_SUBTAG; + return nullptr; + } + } + LocaleInfo *localeInfo = new(std::nothrow) LocaleInfo(language, script, region); + if (localeInfo == nullptr) { + rState = ERROR; + return nullptr; + } + return localeInfo; } -const LocaleInfo* GetSysDefault() +const LocaleInfo *GetSysDefault() { - return LocaleInfoImpl::GetSysDefault(); + return ResLocale::GetDefault(); } void UpdateSysDefault(const LocaleInfo& localeInfo, bool needNotify) { - LocaleInfoImpl::UpdateSysDefault(localeInfo, needNotify); + ResLocale::UpdateDefault(localeInfo, needNotify); } void FindAndSort(std::string localeStr, std::vector& candidateLocale, std::vector& outValue) @@ -374,24 +410,24 @@ void FindAndSort(std::string localeStr, std::vector& candidateLocal if (candidateLocale.size() == 0) { return; } - std::vector tempCandidate; + std::vector tempCandidate; RState state = SUCCESS; - LocaleInfoImpl* currentLocale = LocaleInfoImpl::BuildFromString(localeStr.c_str(), DASH_SEP, state); + 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++) { - LocaleInfoImpl* localeInfo = LocaleInfoImpl::BuildFromString(iter->c_str(), DASH_SEP, state); + ResLocale *resLocale = ResLocale::BuildFromString(iter->c_str(), DASH_SEP, state); if (state == SUCCESS) { - LocaleMatcher::Normalize(localeInfo); - bool isMatch = LocaleMatcher::Match(currentLocale, localeInfo); + LocaleMatcher::Normalize(resLocale); + bool isMatch = LocaleMatcher::Match(currentLocale, resLocale); if (isMatch) { - tempCandidate.push_back(localeInfo); + tempCandidate.push_back(resLocale); outValue.push_back(*iter); } else { - delete localeInfo; + delete resLocale; } } else { - delete localeInfo; + delete resLocale; } } // sort @@ -403,7 +439,7 @@ void FindAndSort(std::string localeStr, std::vector& candidateLocal for (std::size_t i = 0; i < len - 1; i++) { for (std::size_t j = 0; j < len - 1 - i; j++) { if (LocaleMatcher::IsMoreSuitable(tempCandidate.at(j), tempCandidate.at(j + 1), currentLocale) <= 0) { - LocaleInfoImpl* temp = tempCandidate.at(j + 1); + ResLocale *temp = tempCandidate.at(j + 1); tempCandidate.at(j + 1) = tempCandidate.at(j); tempCandidate.at(j) = temp; std::string tempStr = outValue.at(j + 1); diff --git a/frameworks/resmgr/src/resource_manager_impl.cpp b/frameworks/resmgr/src/resource_manager_impl.cpp old mode 100755 new mode 100644 index 8c3592c..b2c4665 --- a/frameworks/resmgr/src/resource_manager_impl.cpp +++ b/frameworks/resmgr/src/resource_manager_impl.cpp @@ -31,7 +31,7 @@ namespace Resource { // default logLevel LogLevel g_logLevel = LOG_INFO; -ResourceManager* CreateResourceManager() +ResourceManager *CreateResourceManager() { ResourceManagerImpl *impl = new (std::nothrow) ResourceManagerImpl; if (impl == nullptr) { @@ -255,14 +255,14 @@ RState ResourceManagerImpl::GetPluralString(const HapResource::ValueUnderQualifi } std::string converted = hapManager_->GetPluralRulesAndSelect(quantity); - auto iter = map.find(converted); - if (iter == map.end()) { - iter = map.find("other"); - if (iter == map.end()) { + auto mapIter = map.find(converted); + if (mapIter == map.end()) { + mapIter = map.find("other"); + if (mapIter == map.end()) { return NOT_FOUND; } } - outValue = iter->second; + outValue = mapIter->second; return SUCCESS; } diff --git a/frameworks/resmgr/src/utils/hap_parser.cpp b/frameworks/resmgr/src/utils/hap_parser.cpp old mode 100755 new mode 100644 index 19eed2f..02d49ae --- a/frameworks/resmgr/src/utils/hap_parser.cpp +++ b/frameworks/resmgr/src/utils/hap_parser.cpp @@ -51,7 +51,7 @@ int32_t HapParser::ReadFileFromZip(const char *zipFile, const char *fileName, vo unz_file_info fileInfo; // for unzGetCurrentFileInfo unzFile uf = unzOpen64(zipFile); // open zipfile stream - if (uf == NULL) { + if (uf == nullptr) { errInfo = FormatString("Cannot open %s", zipFile); return UNKNOWN_ERROR; } // file is open @@ -63,21 +63,21 @@ int32_t HapParser::ReadFileFromZip(const char *zipFile, const char *fileName, vo return UNKNOWN_ERROR; } // file inside zip found - if (unzGetCurrentFileInfo(uf, &fileInfo, filenameInzip, sizeof(filenameInzip), NULL, 0, NULL, 0)) { + if (unzGetCurrentFileInfo(uf, &fileInfo, filenameInzip, sizeof(filenameInzip), nullptr, 0, nullptr, 0)) { unzClose(uf); errInfo = FormatString("Error %d with zipfile %s in unzGetCurrentFileInfo.", err, zipFile); return UNKNOWN_ERROR; } // obtained the necessary details about file inside zip - *buffer = (void *) malloc(fileInfo.uncompressed_size); // setup buffer + *buffer = (void *)malloc(fileInfo.uncompressed_size); // setup buffer bufLen = fileInfo.uncompressed_size; - if ((*buffer) == NULL) { + if ((*buffer) == nullptr) { unzClose(uf); errInfo = FormatString("Error allocating memory for read buffer"); return UNKNOWN_ERROR; } // buffer ready - err = unzOpenCurrentFilePassword(uf, NULL); // Open the file inside the zip (password = NULL) + err = unzOpenCurrentFilePassword(uf, nullptr); // Open the file inside the zip (password = NULL) if (err != UNZ_OK) { errInfo = FormatString("Error %d with zipfile %s in unzOpenCurrentFilePassword.", err, zipFile); free(*buffer); @@ -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((char *)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((char *)buffer + offset, includeTemi ? (strLen - 1) : strLen); offset += includeTemi ? strLen : (strLen + 1); id = tmp; return OK; @@ -294,7 +294,7 @@ bool IsLocaleMatch(const ResConfigImpl *defaultConfig, const std::vectorGetLocaleInfoImpl(), config->GetLocaleInfoImpl())) { + if (!LocaleMatcher::Match(defaultConfig->GetResLocale(), config->GetResLocale())) { HILOG_DEBUG("mismatch, do not parse %s", HapParser::ToFolderPath(keyParams).c_str()); delete (config); return false; diff --git a/frameworks/resmgr/src/utils/string_utils.cpp b/frameworks/resmgr/src/utils/string_utils.cpp old mode 100755 new mode 100644 diff --git a/frameworks/resmgr/src/utils/utils.cpp b/frameworks/resmgr/src/utils/utils.cpp old mode 100755 new mode 100644 index 7ffd117..5076b58 --- a/frameworks/resmgr/src/utils/utils.cpp +++ b/frameworks/resmgr/src/utils/utils.cpp @@ -66,17 +66,6 @@ void Utils::DecodeScript(uint32_t encodeScript, char *outValue) outValue[3] = (encodeScript & 0x000000FF); } -void Utils::ToLower(char *s, int32_t len) -{ - if (s == nullptr) { - return; - } - int32_t i = 0; - for (i = 0; i < len; ++i) { - *(s + i) = tolower(*(s + i)); - } -}; - bool Utils::IsStrEmpty(const char *s) { return (s == nullptr || *s == '\0'); @@ -90,28 +79,6 @@ size_t Utils::StrLen(const char *s) return strlen(s); } -int32_t Utils::FindIndex(const char * const *list, - size_t listLen, - const char *key, - int32_t keyLen, - bool isCaseSensitive) -{ - if (list == nullptr || key == nullptr) { - return -1; - } - if (listLen <= 0) - return -1; - if (keyLen < 0) { - keyLen = strlen(key); - } - for (size_t i = 0; i < listLen; ++i) { - if (Utils::StrCompare(*(list + i), key, keyLen, isCaseSensitive)) { - return i; - } - } - return -1; -}; - uint16_t Utils::EncodeLanguage(const char *language) { if (Utils::IsStrEmpty(language)) { @@ -120,14 +87,6 @@ uint16_t Utils::EncodeLanguage(const char *language) return Utils::EncodeLanguageOrRegion(language, 'a'); } -uint64_t Utils::EncodeLocaleByLocaleInfo(const LocaleInfo *locale) -{ - if (locale == nullptr) { - return NULL_LOCALE; - } - return Utils::EncodeLocale(locale->GetLanguage(), locale->GetScript(), locale->GetRegion()); -} - /** * @brief locale compose of language,script and region,encode as 64bits. * 63-48 bits represent language,detail format see EncodeLanguageOrRegion method @@ -147,11 +106,11 @@ uint64_t Utils::EncodeLocale(const char *language, uint32_t scriptData = Utils::EncodeScript(script); uint16_t regionData = Utils::EncodeRegion(region); - return (uint64_t) (0xffff000000000000 & (((uint64_t) languageData) << 48)) | - (0x0000ffffffff0000 & (((uint64_t) scriptData) << 16)) | (0x000000000000ffff & (uint64_t) (regionData)); + return (uint64_t) (0xffff000000000000 & (((uint64_t)languageData) << 48)) | + (0x0000ffffffff0000 & (((uint64_t)scriptData) << 16)) | (0x000000000000ffff & (uint64_t)(regionData)); } -uint16_t Utils::EncodeRegionByLocaleInfo(const LocaleInfo *locale) +uint16_t Utils::EncodeRegionByResLocale(const ResLocale *locale) { if (locale == nullptr) { return NULL_REGION; @@ -159,7 +118,7 @@ uint16_t Utils::EncodeRegionByLocaleInfo(const LocaleInfo *locale) return Utils::EncodeRegion(locale->GetRegion()); } -uint16_t Utils::EncodeLanguageByLocaleInfo(const LocaleInfo *locale) +uint16_t Utils::EncodeLanguageByResLocale(const ResLocale *locale) { if (locale == nullptr) { return NULL_LANGUAGE; @@ -167,7 +126,7 @@ uint16_t Utils::EncodeLanguageByLocaleInfo(const LocaleInfo *locale) return Utils::EncodeLanguage(locale->GetLanguage()); } -uint32_t Utils::EncodeScriptByLocaleInfo(const LocaleInfo *locale) +uint32_t Utils::EncodeScriptByResLocale(const ResLocale *locale) { if (locale == nullptr) { return NULL_SCRIPT; @@ -250,8 +209,8 @@ bool Utils::StrCompare(const char *left, const char *right, size_t len, bool isC int rc; unsigned char c1, c2; while (len--) { - c1 = (unsigned char) *left; - c2 = (unsigned char) *right; + c1 = (unsigned char)*left; + c2 = (unsigned char)*right; if (c1 == 0) { if (c2 == 0) { return true; @@ -261,10 +220,10 @@ bool Utils::StrCompare(const char *left, const char *right, size_t len, bool isC return false; } else { if (isCaseSensitive) { - rc = (int) (unsigned char) (c1) - (int) (unsigned char) (c2); + rc = (int)(unsigned char)(c1) - (int)(unsigned char)(c2); } else { rc = - (int) (unsigned char) tolower(c1) - (int) (unsigned char) tolower(c2); + (int)(unsigned char)tolower(c1) - (int)(unsigned char)tolower(c2); } if (rc != 0) { return false; diff --git a/frameworks/resmgr/test/unittest/common/hap_manager_test.cpp b/frameworks/resmgr/test/unittest/common/hap_manager_test.cpp old mode 100755 new mode 100644 index 86803f5..1dd1311 --- a/frameworks/resmgr/test/unittest/common/hap_manager_test.cpp +++ b/frameworks/resmgr/test/unittest/common/hap_manager_test.cpp @@ -88,7 +88,7 @@ HWTEST_F(HapManagerTest, HapManagerFuncTest001, TestSize.Level1) /* * this test shows how to reload a hap - * @tc.name: HapManagerFuncTest001 + * @tc.name: HapManagerFuncTest002 * @tc.desc: Test UpdateResConfig & AddResourcePath function, file case. * @tc.type: FUNC */ diff --git a/frameworks/resmgr/test/unittest/common/hap_manager_test.h b/frameworks/resmgr/test/unittest/common/hap_manager_test.h old mode 100755 new mode 100644 diff --git a/frameworks/resmgr/test/unittest/common/hap_parser_test.cpp b/frameworks/resmgr/test/unittest/common/hap_parser_test.cpp old mode 100755 new mode 100644 index 89ee45b..13decd6 --- a/frameworks/resmgr/test/unittest/common/hap_parser_test.cpp +++ b/frameworks/resmgr/test/unittest/common/hap_parser_test.cpp @@ -111,7 +111,7 @@ HWTEST_F(HapParserTest, HapParserFuncTest001, TestSize.Level1) } /* - * @tc.name: GetDeviceType + * @tc.name: HapParserFuncTest002 * @tc.desc: Test GetDeviceType * @tc.type: FUNC */ @@ -127,7 +127,7 @@ HWTEST_F(HapParserTest, HapParserFuncTest002, TestSize.Level1) } /* - * @tc.name: GetScreenDensity + * @tc.name: HapParserFuncTest003 * @tc.desc: Test GetScreenDensity * @tc.type: FUNC */ @@ -143,7 +143,7 @@ HWTEST_F(HapParserTest, HapParserFuncTest003, TestSize.Level1) } /* - * @tc.name: ToFolderPath + * @tc.name: HapParserFuncTest004 * @tc.desc: Test ToFolderPath * @tc.type: FUNC */ diff --git a/frameworks/resmgr/test/unittest/common/hap_parser_test.h b/frameworks/resmgr/test/unittest/common/hap_parser_test.h old mode 100755 new mode 100644 diff --git a/frameworks/resmgr/test/unittest/common/hap_resource_test.cpp b/frameworks/resmgr/test/unittest/common/hap_resource_test.cpp old mode 100755 new mode 100644 index 16acfc5..872646f --- a/frameworks/resmgr/test/unittest/common/hap_resource_test.cpp +++ b/frameworks/resmgr/test/unittest/common/hap_resource_test.cpp @@ -255,7 +255,7 @@ HWTEST_F(HapResourceTest, HapResourceFuncTest003, TestSize.Level1) PrintIdValues(idv); } -ResDesc *LoadFromHap(const char *hapPath, const ResConfigImpl *defaultConfig, bool system = false) +ResDesc *LoadFromHap(const char *hapPath, const ResConfigImpl *defaultConfig) { std::string errOut; void *buf = nullptr; @@ -269,7 +269,7 @@ ResDesc *LoadFromHap(const char *hapPath, const ResConfigImpl *defaultConfig, bo HILOG_DEBUG("extract success, bufLen:%zu", bufLen); ResDesc *resDesc = new ResDesc(); - out = HapParser::ParseResHex((char *) buf, bufLen, *resDesc, defaultConfig); + out = HapParser::ParseResHex((char *)buf, bufLen, *resDesc, defaultConfig); if (out != OK) { delete (resDesc); free(buf); diff --git a/frameworks/resmgr/test/unittest/common/hap_resource_test.h b/frameworks/resmgr/test/unittest/common/hap_resource_test.h old mode 100755 new mode 100644 diff --git a/frameworks/resmgr/test/unittest/common/locale_info_test.cpp b/frameworks/resmgr/test/unittest/common/locale_info_test.cpp index 5259603..eb0af69 100755 --- a/frameworks/resmgr/test/unittest/common/locale_info_test.cpp +++ b/frameworks/resmgr/test/unittest/common/locale_info_test.cpp @@ -57,7 +57,7 @@ void LocaleInfoTest::TearDown() /* * @tc.name: LocaleInfoFindAndSortTest001 - * @tc.desc: Test AddResource + * @tc.desc: Test FindAndSort * @tc.type: FUNC */ HWTEST_F(LocaleInfoTest, LocaleInfoFindAndSortTest001, TestSize.Level1) @@ -78,6 +78,11 @@ HWTEST_F(LocaleInfoTest, LocaleInfoFindAndSortTest001, TestSize.Level1) EXPECT_TRUE(outValue.at(4) == "en-GB"); } +/* + * @tc.name: LocaleInfoFindAndSortTest002 + * @tc.desc: Test FindAndSort + * @tc.type: FUNC + */ HWTEST_F(LocaleInfoTest, LocaleInfoFindAndSortTest002, TestSize.Level1) { std::vector request; @@ -94,6 +99,11 @@ HWTEST_F(LocaleInfoTest, LocaleInfoFindAndSortTest002, TestSize.Level1) EXPECT_TRUE(outValue.at(2) == ""); } +/* + * @tc.name: LocaleInfoFindAndSortTest003 + * @tc.desc: Test FindAndSort + * @tc.type: FUNC + */ HWTEST_F(LocaleInfoTest, LocaleInfoFindAndSortTest003, TestSize.Level1) { std::vector request; @@ -110,6 +120,11 @@ HWTEST_F(LocaleInfoTest, LocaleInfoFindAndSortTest003, TestSize.Level1) EXPECT_TRUE(outValue.at(3) == "en-GB"); } +/* + * @tc.name: LocaleInfoFindAndSortTest004 + * @tc.desc: Test FindAndSort + * @tc.type: FUNC + */ HWTEST_F(LocaleInfoTest, LocaleInfoFindAndSortTest004, TestSize.Level1) { std::vector request; @@ -126,6 +141,11 @@ HWTEST_F(LocaleInfoTest, LocaleInfoFindAndSortTest004, TestSize.Level1) EXPECT_TRUE(outValue.at(3) == ""); } +/* + * @tc.name: LocaleInfoFindAndSortTest005 + * @tc.desc: Test FindAndSort + * @tc.type: FUNC + */ HWTEST_F(LocaleInfoTest, LocaleInfoFindAndSortTest005, TestSize.Level1) { std::vector request; @@ -144,6 +164,11 @@ HWTEST_F(LocaleInfoTest, LocaleInfoFindAndSortTest005, TestSize.Level1) EXPECT_TRUE(outValue.at(4) == ""); } +/* + * @tc.name: LocaleInfoGetSysDefaultTest001 + * @tc.desc: Test GetSysDefault + * @tc.type: FUNC + */ HWTEST_F(LocaleInfoTest, LocaleInfoGetSysDefaultTest001, TestSize.Level1) { RState state = SUCCESS; @@ -165,6 +190,11 @@ HWTEST_F(LocaleInfoTest, LocaleInfoGetSysDefaultTest001, TestSize.Level1) localeInfo = nullptr; } +/* + * @tc.name: LocaleInfoUpdateSysDefaultTest001 + * @tc.desc: Test UpdateSysDefault + * @tc.type: FUNC + */ HWTEST_F(LocaleInfoTest, LocaleInfoUpdateSysDefaultTest001, TestSize.Level1) { RState state = SUCCESS; @@ -213,6 +243,11 @@ HWTEST_F(LocaleInfoTest, LocaleInfoUpdateSysDefaultTest001, TestSize.Level1) localeInfo = nullptr; } +/* + * @tc.name: LocaleInfoGetLanguageTest001 + * @tc.desc: Test LocaleInfo GetLanguage + * @tc.type: FUNC + */ HWTEST_F(LocaleInfoTest, LocaleInfoGetLanguageTest001, TestSize.Level1) { RState state = SUCCESS; @@ -226,6 +261,11 @@ HWTEST_F(LocaleInfoTest, LocaleInfoGetLanguageTest001, TestSize.Level1) localeInfo = nullptr; } +/* + * @tc.name: LocaleInfoGetRegionTest001 + * @tc.desc: Test LocaleInfo GetRegion + * @tc.type: FUNC + */ HWTEST_F(LocaleInfoTest, LocaleInfoGetRegionTest001, TestSize.Level1) { RState state = SUCCESS; @@ -239,6 +279,11 @@ HWTEST_F(LocaleInfoTest, LocaleInfoGetRegionTest001, TestSize.Level1) localeInfo = nullptr; } +/* + * @tc.name: LocaleInfoGetScriptTest001 + * @tc.desc: Test LocaleInfo GetScript + * @tc.type: FUNC + */ HWTEST_F(LocaleInfoTest, LocaleInfoGetScriptTest001, TestSize.Level1) { RState state = SUCCESS; @@ -252,7 +297,12 @@ HWTEST_F(LocaleInfoTest, LocaleInfoGetScriptTest001, TestSize.Level1) localeInfo = nullptr; } -HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromParsTest001, TestSize.Level1) +/* + * @tc.name: LocaleInfoBuildFromPartsTest001 + * @tc.desc: Test BuildFromParts + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest001, TestSize.Level1) { RState state = SUCCESS; LocaleInfo* localeInfo = BuildFromParts("zh", "Hant", "CN", state); @@ -268,7 +318,12 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromParsTest001, TestSize.Level1) localeInfo = nullptr; } -HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromParsTest002, TestSize.Level1) +/* + * @tc.name: LocaleInfoBuildFromPartsTest002 + * @tc.desc: Test BuildFromParts + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest002, TestSize.Level1) { RState state = SUCCESS; LocaleInfo* localeInfo = BuildFromParts("zh1", "Hant", "CN", state); @@ -278,7 +333,12 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromParsTest002, TestSize.Level1) localeInfo = nullptr; } -HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromParsTest003, TestSize.Level1) +/* + * @tc.name: LocaleInfoBuildFromPartsTest003 + * @tc.desc: Test BuildFromParts + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest003, TestSize.Level1) { RState state = SUCCESS; LocaleInfo* localeInfo = BuildFromParts("zh", "Hants", "CN", state); @@ -288,7 +348,12 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromParsTest003, TestSize.Level1) localeInfo = nullptr; } -HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromParsTest004, TestSize.Level1) +/* + * @tc.name: LocaleInfoBuildFromPartsTest004 + * @tc.desc: Test BuildFromParts + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest004, TestSize.Level1) { RState state = SUCCESS; LocaleInfo* localeInfo = BuildFromParts("zh", "Hant", "C", state); @@ -298,7 +363,12 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromParsTest004, TestSize.Level1) localeInfo = nullptr; } -HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromParsTest005, TestSize.Level1) +/* + * @tc.name: LocaleInfoBuildFromPartsTest005 + * @tc.desc: Test BuildFromParts + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest005, TestSize.Level1) { RState state = SUCCESS; LocaleInfo* localeInfo = BuildFromParts(nullptr, "Hants", "CN", state); @@ -308,7 +378,12 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromParsTest005, TestSize.Level1) localeInfo = nullptr; } -HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromParsTest006, TestSize.Level1) +/* + * @tc.name: LocaleInfoBuildFromPartsTest006 + * @tc.desc: Test BuildFromParts + * @tc.type: FUNC + */ +HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest006, TestSize.Level1) { RState state = SUCCESS; LocaleInfo* localeInfo = BuildFromParts("zh", nullptr, nullptr, state); @@ -324,6 +399,11 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromParsTest006, TestSize.Level1) localeInfo = nullptr; } +/* + * @tc.name: LocaleInfoBuildFromStringTest001 + * @tc.desc: Test BuildFromString + * @tc.type: FUNC + */ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest001, TestSize.Level1) { RState state = SUCCESS; @@ -340,6 +420,11 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest001, TestSize.Level1) localeInfo = nullptr; } +/* + * @tc.name: LocaleInfoBuildFromStringTest002 + * @tc.desc: Test BuildFromString + * @tc.type: FUNC + */ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest002, TestSize.Level1) { RState state = SUCCESS; @@ -350,6 +435,11 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest002, TestSize.Level1) localeInfo = nullptr; } +/* + * @tc.name: LocaleInfoBuildFromStringTest003 + * @tc.desc: Test BuildFromString + * @tc.type: FUNC + */ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest003, TestSize.Level1) { RState state = SUCCESS; @@ -360,6 +450,11 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest003, TestSize.Level1) localeInfo = nullptr; } +/* + * @tc.name: LocaleInfoBuildFromStringTest004 + * @tc.desc: Test BuildFromString + * @tc.type: FUNC + */ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest004, TestSize.Level1) { RState state = SUCCESS; @@ -376,22 +471,32 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest004, TestSize.Level1) localeInfo = nullptr; } +/* + * @tc.name: LocaleInfoBuildFromStringTest005 + * @tc.desc: Test BuildFromString + * @tc.type: FUNC + */ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest005, TestSize.Level1) { RState state = SUCCESS; - LocaleInfo* localeInfo = BuildFromString("en_Latn_US", '_', state); + LocaleInfo* localeInfo = BuildFromString("en_US", '_', state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; } EXPECT_TRUE(state == SUCCESS); EXPECT_TRUE(std::strcmp("en", localeInfo->GetLanguage()) == 0); - EXPECT_TRUE(std::strcmp("Latn", localeInfo->GetScript()) == 0); + EXPECT_TRUE(localeInfo->GetScript() == nullptr); EXPECT_TRUE(std::strcmp("US", localeInfo->GetRegion()) == 0); delete localeInfo; localeInfo = nullptr; } +/* + * @tc.name: LocaleInfoBuildFromStringTest006 + * @tc.desc: Test BuildFromString + * @tc.type: FUNC + */ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest006, TestSize.Level1) { RState state = SUCCESS; @@ -402,6 +507,11 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest006, TestSize.Level1) localeInfo = nullptr; } +/* + * @tc.name: LocaleInfoBuildFromStringTest007 + * @tc.desc: Test BuildFromString + * @tc.type: FUNC + */ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest007, TestSize.Level1) { RState state = SUCCESS; @@ -418,6 +528,11 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest007, TestSize.Level1) localeInfo = nullptr; } +/* + * @tc.name: LocaleInfoBuildFromStringTest008 + * @tc.desc: Test BuildFromString + * @tc.type: FUNC + */ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest008, TestSize.Level1) { RState state = SUCCESS; @@ -428,6 +543,11 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest008, TestSize.Level1) localeInfo = nullptr; } +/* + * @tc.name: LocaleInfoBuildFromStringTest009 + * @tc.desc: Test BuildFromString + * @tc.type: FUNC + */ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest009, TestSize.Level1) { RState state = SUCCESS; @@ -438,6 +558,11 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest009, TestSize.Level1) localeInfo = nullptr; } +/* + * @tc.name: LocaleInfoBuildFromStringTest0010 + * @tc.desc: Test BuildFromString + * @tc.type: FUNC + */ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest0010, TestSize.Level1) { RState state = SUCCESS; @@ -454,6 +579,11 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest0010, TestSize.Level1) localeInfo = nullptr; } +/* + * @tc.name: LocaleInfoPerformanceFuncTest001 + * @tc.desc: Test FindAndSort Performance + * @tc.type: FUNC + */ HWTEST_F(LocaleInfoTest, LocaleInfoPerformanceFuncTest001, TestSize.Level1) { unsigned long long total = 0; @@ -474,6 +604,6 @@ HWTEST_F(LocaleInfoTest, LocaleInfoPerformanceFuncTest001, TestSize.Level1) total += std::chrono::duration_cast(t2 - t1).count(); } average = total / 1000.0; - HILOG_INFO("avg cost: %f us", average); + HILOG_DEBUG("avg cost FindAndSort: %f us", average); EXPECT_LT(average, 500); }; \ No newline at end of file diff --git a/frameworks/resmgr/test/unittest/common/locale_info_test.h b/frameworks/resmgr/test/unittest/common/locale_info_test.h index 83ff884..6512ab3 100755 --- a/frameworks/resmgr/test/unittest/common/locale_info_test.h +++ b/frameworks/resmgr/test/unittest/common/locale_info_test.h @@ -21,16 +21,17 @@ int LocaleInfoFindAndSortTest002(); int LocaleInfoFindAndSortTest003(); int LocaleInfoFindAndSortTest004(); int LocaleInfoFindAndSortTest005(); +int LocaleInfoUpdateSysDefaultTest001(); int LocaleInfoGetSysDefaultTest001(); int LocaleInfoGetLanguageTest001(); int LocaleInfoGetRegionTest001(); int LocaleInfoGetScriptTest001(); -int LocaleInfoBuildFromParsTest001(); -int LocaleInfoBuildFromParsTest002(); -int LocaleInfoBuildFromParsTest003(); -int LocaleInfoBuildFromParsTest004(); -int LocaleInfoBuildFromParsTest005(); -int LocaleInfoBuildFromParsTest006(); +int LocaleInfoBuildFromPartsTest001(); +int LocaleInfoBuildFromPartsTest002(); +int LocaleInfoBuildFromPartsTest003(); +int LocaleInfoBuildFromPartsTest004(); +int LocaleInfoBuildFromPartsTest005(); +int LocaleInfoBuildFromPartsTest006(); int LocaleInfoBuildFromStringTest001(); int LocaleInfoBuildFromStringTest002(); int LocaleInfoBuildFromStringTest003(); diff --git a/frameworks/resmgr/test/unittest/common/res_config_impl_test.cpp b/frameworks/resmgr/test/unittest/common/res_config_impl_test.cpp old mode 100755 new mode 100644 index dc78a40..b58d3b8 --- a/frameworks/resmgr/test/unittest/common/res_config_impl_test.cpp +++ b/frameworks/resmgr/test/unittest/common/res_config_impl_test.cpp @@ -60,6 +60,11 @@ ResConfigImpl *CreateResConfigImpl(const char *language, const char *script, con return resConfigImpl; } +/* + * @tc.name: ResConfigImplMatchTest001 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest001, TestSize.Level1) { ResConfigImpl *other = CreateResConfigImpl(nullptr, nullptr, nullptr); @@ -69,6 +74,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest001, TestSize.Level1) delete other; }; +/* + * @tc.name: ResConfigImplMatchTest002 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest002, TestSize.Level1) { ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "CA"); @@ -78,6 +88,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest002, TestSize.Level1) delete other; }; +/* + * @tc.name: ResConfigImplMatchTest003 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest003, TestSize.Level1) { ResConfigImpl *other = CreateResConfigImpl("tl", nullptr, "PH"); @@ -87,6 +102,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest003, TestSize.Level1) delete other; }; +/* + * @tc.name: ResConfigImplMatchTest004 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest004, TestSize.Level1) { ResConfigImpl *other = CreateResConfigImpl("qaa", nullptr, nullptr); @@ -96,6 +116,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest004, TestSize.Level1) delete other; }; +/* + * @tc.name: ResConfigImplMatchTest005 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest005, TestSize.Level1) { ResConfigImpl *other = CreateResConfigImpl("qaa", nullptr, "CA"); @@ -105,6 +130,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest005, TestSize.Level1) delete other; }; +/* + * @tc.name: ResConfigImplMatchTest006 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest006, TestSize.Level1) { ResConfigImpl *other = CreateResConfigImpl("az", nullptr, nullptr); @@ -114,6 +144,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest006, TestSize.Level1) delete other; }; +/* + * @tc.name: ResConfigImplMatchTest007 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest007, TestSize.Level1) { ResConfigImpl *other = CreateResConfigImpl("az", nullptr, "IR"); @@ -123,6 +158,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest007, TestSize.Level1) delete other; }; +/* + * @tc.name: ResConfigImplMatchTest008 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest008, TestSize.Level1) { ResConfigImpl *other = CreateResConfigImpl("ar", nullptr, "EG"); @@ -132,6 +172,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest008, TestSize.Level1) delete other; }; +/* + * @tc.name: ResConfigImplMatchTest009 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest009, TestSize.Level1) { ResConfigImpl *other = CreateResConfigImpl("qaa", "Latn", "FR"); @@ -141,6 +186,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest009, TestSize.Level1) delete other; }; +/* + * @tc.name: ResConfigImplMatchTest010 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest010, TestSize.Level1) { ResConfigImpl *other = CreateResConfigImpl("qaa", nullptr, "FR"); @@ -150,6 +200,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest010, TestSize.Level1) delete other; }; +/* + * @tc.name: ResConfigImplMatchTest011 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest011, TestSize.Level1) { ResConfigImpl *other = CreateResConfigImpl("az", nullptr, nullptr); @@ -159,6 +214,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest011, TestSize.Level1) delete other; }; +/* + * @tc.name: ResConfigImplMatchTest012 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest012, TestSize.Level1) { ResConfigImpl *other = CreateResConfigImpl("az", nullptr, nullptr); @@ -168,6 +228,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest012, TestSize.Level1) delete other; }; +/* + * @tc.name: ResConfigImplMatchTest013 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest013, TestSize.Level1) { ResConfigImpl *other = CreateResConfigImpl("qaa", nullptr, "FR"); @@ -177,6 +242,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest013, TestSize.Level1) delete other; }; +/* + * @tc.name: ResConfigImplMatchTest014 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest014, TestSize.Level1) { ResConfigImpl *other = CreateResConfigImpl("he", nullptr, nullptr); @@ -187,6 +257,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest014, TestSize.Level1) delete other; }; +/* + * @tc.name: ResConfigImplMatchTest015 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest015, TestSize.Level1) { ResConfigImpl *other = CreateResConfigImpl("ji", nullptr, nullptr); @@ -197,6 +272,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest015, TestSize.Level1) delete other; }; +/* + * @tc.name: ResConfigImplMatchTest016 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest016, TestSize.Level1) { ResConfigImpl *other = CreateResConfigImpl("jw", nullptr, nullptr); @@ -207,6 +287,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest016, TestSize.Level1) delete other; }; +/* + * @tc.name: ResConfigImplMatchTest017 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest017, TestSize.Level1) { ResConfigImpl *other = CreateResConfigImpl("in", nullptr, nullptr); @@ -217,6 +302,202 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest017, TestSize.Level1) delete other; }; +/* + * @tc.name: ResConfigImplMatchTest018 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest018, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", "Latn", nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", "Qaag", nullptr); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest019 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest019, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + current->SetDeviceType(DeviceType::DEVICE_CAR); + other->SetDeviceType(DeviceType::DEVICE_CAR); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest020 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +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); + EXPECT_FALSE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest021 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest021, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + other->SetDeviceType(DeviceType::DEVICE_PC); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest022 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest022, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + current->SetDeviceType(DeviceType::DEVICE_PC); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest023 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest023, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + current->SetDirection(Direction::DIRECTION_HORIZONTAL); + other->SetDirection(Direction::DIRECTION_HORIZONTAL); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest024 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest024, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + current->SetDirection(Direction::DIRECTION_HORIZONTAL); + other->SetDirection(Direction::DIRECTION_VERTICAL); + EXPECT_FALSE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest025 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest025, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + other->SetDirection(Direction::DIRECTION_HORIZONTAL); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest026 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest026, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + current->SetDirection(Direction::DIRECTION_VERTICAL); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest027 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest027, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + current->SetDirection(Direction::DIRECTION_VERTICAL); + current->SetDeviceType(DeviceType::DEVICE_PHONE); + other->SetDirection(Direction::DIRECTION_VERTICAL); + other->SetDeviceType(DeviceType::DEVICE_PHONE); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest028 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest028, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + current->SetDirection(Direction::DIRECTION_VERTICAL); + current->SetDeviceType(DeviceType::DEVICE_PHONE); + other->SetDeviceType(DeviceType::DEVICE_PHONE); + EXPECT_TRUE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplMatchTest029 + * @tc.desc: Test ResConfig Match + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest029, TestSize.Level1) +{ + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + current->SetDirection(Direction::DIRECTION_VERTICAL); + current->SetDeviceType(DeviceType::DEVICE_PHONE); + other->SetDeviceType(DeviceType::DEVICE_PHONE); + other->SetDirection(Direction::DIRECTION_HORIZONTAL); + EXPECT_FALSE(current->Match(other)); + delete current; + delete other; +}; + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest001 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest001, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl(nullptr, nullptr, nullptr); @@ -229,6 +510,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest001, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest002 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest002, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("fr", nullptr, "CA"); @@ -241,6 +527,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest002, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest003 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest003, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("fr", nullptr, "CA"); @@ -253,6 +544,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest003, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest004 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest004, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("fil", nullptr, "PH"); @@ -265,6 +561,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest004, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest005 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest005, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("fil", nullptr, "PH"); @@ -277,18 +578,28 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest005, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest006 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest006, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); ResConfigImpl *current = CreateResConfigImpl("es", nullptr, "419"); ResConfigImpl *other = CreateResConfigImpl("es", nullptr, "419"); - EXPECT_FALSE(current->IsMoreSuitable(other, request)); - EXPECT_FALSE(other->IsMoreSuitable(current, request)); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_TRUE(other->IsMoreSuitable(current, request)); delete request; delete current; delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest007 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest007, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); @@ -301,6 +612,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest007, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest008 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest008, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); @@ -313,6 +629,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest008, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest009 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest009, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); @@ -325,6 +646,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest009, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest010 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest010, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); @@ -337,6 +663,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest010, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest011 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest011, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); @@ -349,6 +680,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest011, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest012 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest012, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); @@ -361,6 +697,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest012, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest013 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest013, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); @@ -373,6 +714,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest013, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest014 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest014, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "IC"); @@ -385,6 +731,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest014, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest015 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest015, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "GQ"); @@ -397,6 +748,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest015, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest016 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest016, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "GB"); @@ -409,6 +765,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest016, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest017 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest017, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "PR"); @@ -421,6 +782,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest017, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest018 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest018, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "DE"); @@ -433,6 +799,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest018, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest019 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest019, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "IN"); @@ -445,6 +816,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest019, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest020 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest020, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "PR"); @@ -457,6 +833,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest020, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest021 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest021, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "IN"); @@ -469,6 +850,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest021, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest022 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest022, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "IN"); @@ -481,6 +867,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest022, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest023 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest023, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("pt", nullptr, "MZ"); @@ -493,6 +884,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest023, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest024 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest024, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("pt", nullptr, "MZ"); @@ -505,6 +901,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest024, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest025 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest025, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("zh", "Hant", "MO"); @@ -517,6 +918,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest025, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest026 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest026, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("zh", "Hant", "US"); @@ -529,6 +935,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest026, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest027 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest027, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("ar", nullptr, "DZ"); @@ -541,6 +952,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest027, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest028 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest028, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("ar", nullptr, "EG"); @@ -553,6 +969,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest028, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest029 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest029, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("ar", nullptr, "QA"); @@ -565,6 +986,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest029, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest030 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest030, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("ar", nullptr, "QA"); @@ -577,6 +1003,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest030, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest031 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest031, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); @@ -589,6 +1020,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest031, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest032 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest032, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); @@ -601,6 +1037,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest032, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest033 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest033, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "PR"); @@ -613,6 +1054,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest033, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest034 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest034, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); @@ -625,6 +1071,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest034, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest035 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest035, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "PR"); @@ -637,6 +1088,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest035, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest036 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest036, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); @@ -649,6 +1105,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest036, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest037 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest037, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "CN"); @@ -661,6 +1122,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest037, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest038 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest038, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("en", "Qaag", nullptr); @@ -673,6 +1139,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest038, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest039 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest039, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("en", "Qaag", nullptr); @@ -685,6 +1156,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest039, TestSize.Level1) delete other; } +/* + * @tc.name: ResConfigImplIsMoreSuitableTest040 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest040, TestSize.Level1) { ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); @@ -695,4 +1171,225 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest040, TestSize.Level1) delete request; delete current; delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest041 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest041, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + request->SetDirection(Direction::DIRECTION_HORIZONTAL); + current->SetDirection(Direction::DIRECTION_HORIZONTAL); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest042 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest042, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + request->SetDirection(Direction::DIRECTION_HORIZONTAL); + request->SetDeviceType(DeviceType::DEVICE_PHONE); + current->SetDirection(Direction::DIRECTION_HORIZONTAL); + current->SetDeviceType(DeviceType::DEVICE_PHONE); + other->SetDeviceType(DeviceType::DEVICE_PHONE); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest043 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest043, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + request->SetDirection(Direction::DIRECTION_HORIZONTAL); + request->SetDeviceType(DeviceType::DEVICE_PHONE); + request->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI); + current->SetDirection(Direction::DIRECTION_HORIZONTAL); + current->SetDeviceType(DeviceType::DEVICE_PHONE); + current->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI); + other->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI); + other->SetDeviceType(DeviceType::DEVICE_PHONE); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest044 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest044, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + request->SetDirection(Direction::DIRECTION_HORIZONTAL); + request->SetDeviceType(DeviceType::DEVICE_PHONE); + request->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI); + current->SetDeviceType(DeviceType::DEVICE_PHONE); + current->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI); + other->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest045 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest045, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + request->SetDirection(Direction::DIRECTION_HORIZONTAL); + request->SetDeviceType(DeviceType::DEVICE_PHONE); + request->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI); + current->SetDeviceType(DeviceType::DEVICE_PHONE); + current->SetDirection(Direction::DIRECTION_HORIZONTAL); + current->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_XLDPI); + other->SetDeviceType(DeviceType::DEVICE_PHONE); + other->SetDirection(Direction::DIRECTION_HORIZONTAL); + other->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_XXLDPI); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest046 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest046, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + request->SetDirection(Direction::DIRECTION_HORIZONTAL); + request->SetDeviceType(DeviceType::DEVICE_PHONE); + request->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI); + current->SetDeviceType(DeviceType::DEVICE_PHONE); + current->SetDirection(Direction::DIRECTION_HORIZONTAL); + current->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_MDPI); + other->SetDeviceType(DeviceType::DEVICE_PHONE); + other->SetDirection(Direction::DIRECTION_HORIZONTAL); + other->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_SDPI); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest047 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest047, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + request->SetDirection(Direction::DIRECTION_HORIZONTAL); + request->SetDeviceType(DeviceType::DEVICE_PHONE); + request->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI); + current->SetDeviceType(DeviceType::DEVICE_PHONE); + current->SetDirection(Direction::DIRECTION_HORIZONTAL); + current->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_XXXLDPI); + other->SetDeviceType(DeviceType::DEVICE_PHONE); + other->SetDirection(Direction::DIRECTION_HORIZONTAL); + other->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_SDPI); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest048 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest048, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + current->SetDeviceType(DeviceType::DEVICE_PHONE); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest049 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest049, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + current->SetDirection(Direction::DIRECTION_HORIZONTAL); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; +} + +/* + * @tc.name: ResConfigImplIsMoreSuitableTest050 + * @tc.desc: Test ResConfig IsMoreSuitable + * @tc.type: FUNC + */ +HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest050, TestSize.Level1) +{ + ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); + ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + current->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_SDPI); + EXPECT_TRUE(current->IsMoreSuitable(other, request)); + EXPECT_FALSE(other->IsMoreSuitable(current, request)); + delete request; + delete current; + delete other; } \ No newline at end of file diff --git a/frameworks/resmgr/test/unittest/common/res_config_impl_test.h b/frameworks/resmgr/test/unittest/common/res_config_impl_test.h old mode 100755 new mode 100644 index a28cf9a..3a102ee --- a/frameworks/resmgr/test/unittest/common/res_config_impl_test.h +++ b/frameworks/resmgr/test/unittest/common/res_config_impl_test.h @@ -33,6 +33,18 @@ 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(); @@ -73,5 +85,15 @@ 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(); #endif diff --git a/frameworks/resmgr/test/unittest/common/res_config_test.cpp b/frameworks/resmgr/test/unittest/common/res_config_test.cpp old mode 100755 new mode 100644 index f8ed200..2682b32 --- a/frameworks/resmgr/test/unittest/common/res_config_test.cpp +++ b/frameworks/resmgr/test/unittest/common/res_config_test.cpp @@ -56,6 +56,11 @@ void ResConfigTest::TearDown() { } +/* + * @tc.name: ResConfigFuncTest001 + * @tc.desc: Test Config function, non file case. + * @tc.type: FUNC + */ HWTEST_F(ResConfigTest, ResConfigFuncTest001, TestSize.Level1) { ResConfigImpl *rc = new ResConfigImpl; diff --git a/frameworks/resmgr/test/unittest/common/res_config_test.h b/frameworks/resmgr/test/unittest/common/res_config_test.h old mode 100755 new mode 100644 diff --git a/frameworks/resmgr/test/unittest/common/res_desc_test.cpp b/frameworks/resmgr/test/unittest/common/res_desc_test.cpp old mode 100755 new mode 100644 index 683f452..7b19f0b --- a/frameworks/resmgr/test/unittest/common/res_desc_test.cpp +++ b/frameworks/resmgr/test/unittest/common/res_desc_test.cpp @@ -122,6 +122,11 @@ void TestKeyParam(KeyType keyType, int value, std::string expectStr) EXPECT_EQ(expectStr, keyParam.str_); } +/* + * @tc.name: ResDescFuncTest002 + * @tc.desc: Test IsRef function, non file case. + * @tc.type: FUNC + */ HWTEST_F(ResDescTest, ResDescFuncTest002, TestSize.Level1) { TestKeyParam(KeyType::LANGUAGES, 25966, "en"); diff --git a/frameworks/resmgr/test/unittest/common/res_desc_test.h b/frameworks/resmgr/test/unittest/common/res_desc_test.h old mode 100755 new mode 100644 diff --git a/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp b/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp old mode 100755 new mode 100644 index d4be348..0e028d4 --- a/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp +++ b/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp @@ -42,6 +42,12 @@ public: void TearDown(); + ResourceManagerPerformanceTest() : rm(nullptr) + {} + + ~ResourceManagerPerformanceTest() + {} + public: ResourceManager *rm; @@ -50,7 +56,7 @@ public: int ResourceManagerPerformanceTest::GetResId(std::string name, ResType resType) const { - auto idv = ((ResourceManagerImpl *) rm)->hapManager_->GetResourceListByName(name.c_str(), resType); + auto idv = ((ResourceManagerImpl *)rm)->hapManager_->GetResourceListByName(name.c_str(), resType); if (idv == nullptr) { return -1; } @@ -64,8 +70,6 @@ int ResourceManagerPerformanceTest::GetResId(std::string name, ResType resType) void ResourceManagerPerformanceTest::SetUpTestCase(void) { // step 1: input testsuit setup step - // PerformanceTest need higher log level - g_logLevel = LOG_INFO; } void ResourceManagerPerformanceTest::TearDownTestCase(void) @@ -75,6 +79,8 @@ void ResourceManagerPerformanceTest::TearDownTestCase(void) void ResourceManagerPerformanceTest::SetUp(void) { + // PerformanceTest need higher log level + g_logLevel = LOG_INFO; this->rm = CreateResourceManager(); if (rm == nullptr) { return; @@ -122,7 +128,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest001, delete tmpRm; } average = total / 1000.0; - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 001: %f us", average); EXPECT_LT(average, 9000); }; @@ -157,7 +164,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest002, delete tmpRm; delete rc; average = total / 1000.0; - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 002: %f us", average); EXPECT_LT(average, 500); }; @@ -190,7 +198,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest003, } delete rc; average = total / 1000.0; - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 003: %f us", average); EXPECT_LT(average, 500); }; @@ -226,7 +235,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest004, } } average = total / (1000.0 * count); - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 004: %f us", average); EXPECT_LT(average, 500); }; @@ -255,7 +265,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest005, } } average = total / (1000.0 * count); - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 005: %f us", average); EXPECT_LT(average, 500); }; @@ -284,7 +295,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest006, } } average = total / (1000.0 * count); - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 006: %f us", average); EXPECT_LT(average, 500); }; @@ -320,7 +332,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest007, } } average = total / (1000.0 * count); - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 007: %f us", average); EXPECT_LT(average, 500); }; @@ -349,7 +362,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest008, } } average = total / (1000.0 * count); - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 008: %f us", average); EXPECT_LT(average, 500); }; @@ -377,7 +391,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest009, total += std::chrono::duration_cast(t2 - t1).count(); } average = total / 1000.0; - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 009: %f us", average); EXPECT_LT(average, 500); }; @@ -402,7 +417,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest010, total += std::chrono::duration_cast(t2 - t1).count(); } average = total / 1000.0; - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 010: %f us", average); EXPECT_LT(average, 500); }; @@ -437,7 +453,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest011, } } average = total / (1000.0 * count); - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 011: %f us", average); EXPECT_LT(average, 500); }; @@ -466,7 +483,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest012, } } average = total / (1000.0 * count); - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 012: %f us", average); EXPECT_LT(average, 500); }; @@ -498,7 +516,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest013, } } average = total / (1000.0 * count); - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 013: %f us", average); EXPECT_LT(average, 500); }; @@ -527,7 +546,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest014, } } average = total / (1000.0 * count); - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 014: %f us", average); EXPECT_LT(average, 500); }; @@ -559,7 +579,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest015, } } average = total / (1000.0 * count); - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 015: %f us", average); EXPECT_LT(average, 500); }; @@ -588,7 +609,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest016, } } average = total / (1000.0 * count); - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 016: %f us", average); EXPECT_LT(average, 500); }; @@ -616,7 +638,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest017, total += std::chrono::duration_cast(t2 - t1).count(); } average = total / 1000.0; - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 017: %f us", average); EXPECT_LT(average, 500); }; @@ -641,7 +664,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest018, total += std::chrono::duration_cast(t2 - t1).count(); } average = total / 1000.0; - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 018: %f us", average); EXPECT_LT(average, 500); }; @@ -669,7 +693,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest019, total += std::chrono::duration_cast(t2 - t1).count(); } average = total / 1000.0; - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 019: %f us", average); EXPECT_LT(average, 500); }; @@ -694,7 +719,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest020, total += std::chrono::duration_cast(t2 - t1).count(); } average = total / 1000.0; - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 020: %f us", average); EXPECT_LT(average, 500); }; @@ -722,7 +748,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest021, total += std::chrono::duration_cast(t2 - t1).count(); } average = total / 1000.0; - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 021: %f us", average); EXPECT_LT(average, 500); }; @@ -747,7 +774,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest022, total += std::chrono::duration_cast(t2 - t1).count(); } average = total / 1000.0; - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 022: %f us", average); EXPECT_LT(average, 500); }; @@ -775,7 +803,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest023, total += std::chrono::duration_cast(t2 - t1).count(); } average = total / 1000.0; - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 023: %f us", average); EXPECT_LT(average, 500); }; @@ -800,7 +829,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest024, total += std::chrono::duration_cast(t2 - t1).count(); } average = total / 1000.0; - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 024: %f us", average); EXPECT_LT(average, 500); }; @@ -828,7 +858,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest025, total += std::chrono::duration_cast(t2 - t1).count(); } average = total / 1000.0; - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 025: %f us", average); EXPECT_LT(average, 500); }; @@ -853,7 +884,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest026, total += std::chrono::duration_cast(t2 - t1).count(); } average = total / 1000.0; - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 026: %f us", average); EXPECT_LT(average, 500); }; @@ -881,7 +913,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest027, total += std::chrono::duration_cast(t2 - t1).count(); } average = total / 1000.0; - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 027: %f us", average); EXPECT_LT(average, 500); }; @@ -906,7 +939,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest028, total += std::chrono::duration_cast(t2 - t1).count(); } average = total / 1000.0; - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 028: %f us", average); EXPECT_LT(average, 500); }; @@ -934,7 +968,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest029, total += std::chrono::duration_cast(t2 - t1).count(); } average = total / 1000.0; - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 029: %f us", average); EXPECT_LT(average, 500); }; @@ -959,7 +994,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest030, total += std::chrono::duration_cast(t2 - t1).count(); } average = total / 1000.0; - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 030: %f us", average); EXPECT_LT(average, 500); }; @@ -987,7 +1023,8 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest031, total += std::chrono::duration_cast(t2 - t1).count(); } average = total / 1000.0; - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 031: %f us", average); EXPECT_LT(average, 500); }; @@ -1012,6 +1049,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest032, total += std::chrono::duration_cast(t2 - t1).count(); } average = total / 1000.0; - HILOG_INFO("avg cost: %f us", average); + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("avg cost 032: %f us", average); EXPECT_LT(average, 500); }; diff --git a/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.h b/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.h old mode 100755 new mode 100644 diff --git a/frameworks/resmgr/test/unittest/common/resource_manager_test.cpp b/frameworks/resmgr/test/unittest/common/resource_manager_test.cpp old mode 100755 new mode 100644 index 47afbb6..7889673 --- a/frameworks/resmgr/test/unittest/common/resource_manager_test.cpp +++ b/frameworks/resmgr/test/unittest/common/resource_manager_test.cpp @@ -43,6 +43,12 @@ public: void TearDown(); + ResourceManagerTest() : rm(nullptr) + {} + + ~ResourceManagerTest() + {} + public: ResourceManager *rm; diff --git a/frameworks/resmgr/test/unittest/common/resource_manager_test.h b/frameworks/resmgr/test/unittest/common/resource_manager_test.h old mode 100755 new mode 100644 diff --git a/frameworks/resmgr/test/unittest/common/string_utils_test.cpp b/frameworks/resmgr/test/unittest/common/string_utils_test.cpp new file mode 100644 index 0000000..cfe24af --- /dev/null +++ b/frameworks/resmgr/test/unittest/common/string_utils_test.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "string_utils_test.h" + +#include +#include +#include + +#include "test_common.h" +#include "utils/string_utils.h" + +using namespace OHOS::Global::Resource; +using namespace testing::ext; +using namespace OHOS::I18N; + +class StringUtilsTest : public testing::Test { +public: + static void SetUpTestCase(void); + + static void TearDownTestCase(void); + + void SetUp(); + + void TearDown(); +}; + +void StringUtilsTest::SetUpTestCase(void) +{ + // step 1: input testsuit setup step + g_logLevel = LOG_DEBUG; +} + +void StringUtilsTest::TearDownTestCase(void) +{ + // step 2: input testsuit teardown step +} + +void StringUtilsTest::SetUp() +{ + // step 3: input testcase setup step +} + +void StringUtilsTest::TearDown() +{ + // step 4: input testcase teardown step +} + +/* + * @tc.name: StringUtilsFuncTest001 + * @tc.desc: Test FormatString, none file case. + * @tc.type: FUNC + */ +HWTEST_F(StringUtilsTest, StringUtilsFuncTest001, TestSize.Level1) +{ + std::string result = FormatString("%d", 10001); + EXPECT_EQ("10001", result); + + result = FormatString("I'm %s, I'm %d", "cici", 5); + EXPECT_EQ("I'm cici, I'm 5", result); +} \ No newline at end of file diff --git a/interfaces/innerkits/include/locale_info.h b/frameworks/resmgr/test/unittest/common/string_utils_test.h old mode 100755 new mode 100644 similarity index 40% rename from interfaces/innerkits/include/locale_info.h rename to frameworks/resmgr/test/unittest/common/string_utils_test.h index bcf6667..0e5642f --- a/interfaces/innerkits/include/locale_info.h +++ b/frameworks/resmgr/test/unittest/common/string_utils_test.h @@ -13,38 +13,9 @@ * limitations under the License. */ -#ifndef OHOS_RESOURCE_MANAGER_LOCALEINFO_H -#define OHOS_RESOURCE_MANAGER_LOCALEINFO_H -#include -#include -#include -#include -#include "rstate.h" +#ifndef RESOURCE_MANAGER_STRING_UTILS_TEST_H +#define RESOURCE_MANAGER_STRING_UTILS_TEST_H -namespace OHOS { -namespace Global { -namespace Resource { -class LocaleInfo { -public: - virtual const char* GetLanguage() const = 0; +int StringUtilsFuncTest001(); - virtual const char* GetRegion() const = 0; - - virtual const char* GetScript() const = 0; - - virtual ~LocaleInfo() {}; -}; -const LocaleInfo* GetSysDefault(); - -void UpdateSysDefault(const LocaleInfo& localeInfo, bool needNotify); - -LocaleInfo* BuildFromString(const char* str, char sep, RState& rState); - -LocaleInfo* BuildFromParts(const char* language, const char* script, const char* region, RState& rState); - -void FindAndSort(std::string localeStr, std::vector& candidateLocale, std::vector& outValue); -} // namespace Resource -} // namespace Global -} // namespace OHOS #endif - diff --git a/frameworks/resmgr/test/unittest/common/test_common.cpp b/frameworks/resmgr/test/unittest/common/test_common.cpp old mode 100755 new mode 100644 diff --git a/frameworks/resmgr/test/unittest/common/test_common.h b/frameworks/resmgr/test/unittest/common/test_common.h old mode 100755 new mode 100644 diff --git a/interfaces/innerkits/include/res_common.h b/interfaces/innerkits/include/res_common.h old mode 100755 new mode 100644 index 89e1e3a..f846876 --- a/interfaces/innerkits/include/res_common.h +++ b/interfaces/innerkits/include/res_common.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef OHOS_GLOBAL_H -#define OHOS_GLOBAL_H +#ifndef OHOS_RES_COMMON_H +#define OHOS_RES_COMMON_H #include @@ -118,4 +118,4 @@ enum Direction { } // namespace Resource } // namespace Global } // namespace OHOS -#endif // OHOS_GLOBAL_H \ No newline at end of file +#endif // OHOS_RES_COMMON_H \ No newline at end of file diff --git a/interfaces/innerkits/include/res_config.h b/interfaces/innerkits/include/res_config.h old mode 100755 new mode 100644 index 137fbd9..b708d0d --- a/interfaces/innerkits/include/res_config.h +++ b/interfaces/innerkits/include/res_config.h @@ -15,9 +15,11 @@ #ifndef OHOS_RESOURCE_MANAGER_RESCONFIG_H #define OHOS_RESOURCE_MANAGER_RESCONFIG_H +#include #include "locale_info.h" #include "res_common.h" - +#include "rstate.h" +using OHOS::I18N::LocaleInfo; namespace OHOS { namespace Global { namespace Resource { @@ -25,6 +27,8 @@ class ResConfig { public: virtual RState SetLocaleInfo(const char *language, const char *script, const char *region) = 0; + virtual RState SetLocaleInfo(LocaleInfo& localeInfo) = 0; + virtual void SetDeviceType(DeviceType deviceType) = 0; virtual void SetDirection(Direction direction) = 0; @@ -44,6 +48,16 @@ public: virtual ~ResConfig() {} }; ResConfig *CreateResConfig(); + +const LocaleInfo* GetSysDefault(); + +void UpdateSysDefault(const LocaleInfo& localeInfo, bool needNotify); + +LocaleInfo* BuildFromString(const char *str, char sep, RState& rState); + +LocaleInfo* BuildFromParts(const char *language, const char *script, const char *region, RState& rState); + +void FindAndSort(std::string localeStr, std::vector& candidateLocale, std::vector& outValue); } // namespace Resource } // namespace Global } // namespace OHOS diff --git a/interfaces/innerkits/include/resource_manager.h b/interfaces/innerkits/include/resource_manager.h old mode 100755 new mode 100644 index 292efb7..d013a90 --- a/interfaces/innerkits/include/resource_manager.h +++ b/interfaces/innerkits/include/resource_manager.h @@ -16,9 +16,9 @@ #define OHOS_RESOURCE_MANAGER_RESOURCEMANAGER_H #include "res_config.h" +#include #include #include -#include namespace OHOS { namespace Global { @@ -36,15 +36,15 @@ public: virtual RState GetStringById(uint32_t id, std::string &outValue) = 0; - virtual RState GetStringByName(const char* name, std::string &outValue) = 0; + virtual RState GetStringByName(const char *name, std::string &outValue) = 0; virtual RState GetStringFormatById(std::string &outValue, uint32_t id, ...) = 0; - virtual RState GetStringFormatByName(std::string& outValue, const char* name, ...) = 0; + virtual RState GetStringFormatByName(std::string& outValue, const char *name, ...) = 0; virtual RState GetStringArrayById(uint32_t id, std::vector& outValue) = 0; - virtual RState GetStringArrayByName(const char* name, std::vector& outValue) = 0; + virtual RState GetStringArrayByName(const char *name, std::vector& outValue) = 0; virtual RState GetPatternById(uint32_t id, std::map& outValue) = 0; @@ -60,11 +60,11 @@ public: virtual RState GetThemeById(uint32_t id, std::map &outValue) = 0; - virtual RState GetThemeByName(const char* name, std::map &outValue) = 0; + virtual RState GetThemeByName(const char *name, std::map &outValue) = 0; virtual RState GetBooleanById(uint32_t id, bool& outValue) = 0; - virtual RState GetBooleanByName(const char* name, bool& outValue) = 0; + virtual RState GetBooleanByName(const char *name, bool& outValue) = 0; virtual RState GetIntegerById(uint32_t id, int& outValue) = 0; @@ -72,11 +72,11 @@ public: virtual RState GetFloatById(uint32_t id, float& outValue) = 0; - virtual RState GetFloatByName(const char* name, float& outValue) = 0; + virtual RState GetFloatByName(const char *name, float& outValue) = 0; virtual RState GetIntArrayById(uint32_t id, std::vector& outValue) = 0; - virtual RState GetIntArrayByName(const char* name, std::vector& outValue) = 0; + virtual RState GetIntArrayByName(const char *name, std::vector& outValue) = 0; virtual RState GetColorById(uint32_t id, uint32_t& outValue) = 0; @@ -84,11 +84,11 @@ public: virtual RState GetProfileById(uint32_t id, std::string &outValue) = 0; - virtual RState GetProfileByName(const char* name, std::string &outValue) = 0; + virtual RState GetProfileByName(const char *name, std::string &outValue) = 0; virtual RState GetMediaById(uint32_t id, std::string &outValue) = 0; - virtual RState GetMediaByName(const char* name, std::string &outValue) = 0; + virtual RState GetMediaByName(const char *name, std::string &outValue) = 0; }; ResourceManager *CreateResourceManager(); diff --git a/interfaces/innerkits/include/rstate.h b/interfaces/innerkits/include/rstate.h old mode 100755 new mode 100644 -- Gitee From c163eaaa198d64aefcf79bfd125c8231c250fabe Mon Sep 17 00:00:00 2001 From: caisirius Date: Wed, 7 Jul 2021 23:19:25 +0800 Subject: [PATCH 02/19] change i18n to icu Signed-off-by: caisirius --- frameworks/resmgr/include/hap_manager.h | 9 +++-- frameworks/resmgr/src/hap_manager.cpp | 54 ++++++++++--------------- 2 files changed, 28 insertions(+), 35 deletions(-) diff --git a/frameworks/resmgr/include/hap_manager.h b/frameworks/resmgr/include/hap_manager.h index 372aa66..59f04cc 100644 --- a/frameworks/resmgr/include/hap_manager.h +++ b/frameworks/resmgr/include/hap_manager.h @@ -20,8 +20,7 @@ #include "res_desc.h" #include "lock.h" -#include -#include +#include #include namespace OHOS { @@ -63,6 +62,10 @@ private: // when resConfig_ updated we must call ReloadAll() RState ReloadAll(); + static bool Init(); + + static bool icuInitialized; + // app res config ResConfigImpl *resConfig_; @@ -73,7 +76,7 @@ private: std::vector loadedHapPaths_; // key is language - std::vector> plurRulesCache_; + std::vector> plurRulesCache_; Lock lock_; }; diff --git a/frameworks/resmgr/src/hap_manager.cpp b/frameworks/resmgr/src/hap_manager.cpp index b5f5e40..504bd59 100644 --- a/frameworks/resmgr/src/hap_manager.cpp +++ b/frameworks/resmgr/src/hap_manager.cpp @@ -15,7 +15,7 @@ #include "hap_manager.h" #include -#include +#include #include "auto_mutex.h" #include "hilog_wrapper.h" @@ -31,23 +31,12 @@ HapManager::HapManager(ResConfigImpl *resConfig) { } -std::string ConvertToPluralStr(int idxRet) +bool HapManager::icuInitialized = HapManager::Init(); + +bool HapManager::Init() { - switch (idxRet) { - case OHOS::I18N::PluralRuleType::ZERO: - return "zero"; - case OHOS::I18N::PluralRuleType::ONE: - return "one"; - case OHOS::I18N::PluralRuleType::TWO: - return "two"; - case OHOS::I18N::PluralRuleType::FEW: - return "few"; - case OHOS::I18N::PluralRuleType::MANY: - return "many"; - case OHOS::I18N::PluralRuleType::OTHER: - default: - return "other"; - } + SetHwIcuDirectory(); + return true; } std::string HapManager::GetPluralRulesAndSelect(int quantity) @@ -61,41 +50,42 @@ std::string HapManager::GetPluralRulesAndSelect(int quantity) } std::string language = this->resConfig_->GetResLocale()->GetLanguage(); - OHOS::I18N::PluralFormat *pluralFormat = nullptr; + icu::PluralRules *pluralRules = nullptr; for (uint32_t i = 0; i < plurRulesCache_.size(); i++) { auto pair = plurRulesCache_[i]; if (language == pair.first) { // cache hit - pluralFormat = pair.second; + pluralRules = pair.second; break; } } - OHOS::I18N::I18nStatus status = OHOS::I18N::I18nStatus::ISUCCESS; - if (pluralFormat == nullptr) { + if (pluralRules == nullptr) { // no cache hit - OHOS::I18N::LocaleInfo locale(language.c_str(), "", ""); - pluralFormat = new(std::nothrow) OHOS::I18N::PluralFormat(locale, status); - if (pluralFormat == nullptr) { - HILOG_ERROR("new PluralFormat failed"); + icu::Locale locale(language.c_str()); + if (locale.isBogus()) { + HILOG_ERROR("icu::Locale init error : %s", language.c_str()); return defaultRet; } - if (status != OHOS::I18N::I18nStatus::ISUCCESS) { - HILOG_ERROR("PluralFormat init failed"); - delete pluralFormat; + UErrorCode status = U_ZERO_ERROR; + pluralRules = icu::PluralRules::forLocale(locale, status); + if (status != U_ZERO_ERROR) { + HILOG_ERROR("icu::PluralRules::forLocale error : %d", status); return defaultRet; } - // after pluralFormat created, we add it to cache, if > 3 delete oldest one + // after PluralRules created, we add it to cache, if > 3 delete oldest one if (plurRulesCache_.size() >= PLURAL_CACHE_MAX_COUNT) { HILOG_DEBUG("cache rotate delete plurRulesMap_ %s", plurRulesCache_[0].first.c_str()); delete (plurRulesCache_[0].second); plurRulesCache_.erase(plurRulesCache_.begin()); } - auto plPair = std::make_pair(language, pluralFormat); + auto plPair = std::make_pair(language, pluralRules); plurRulesCache_.push_back(plPair); } - int idxRet = pluralFormat->GetPluralRuleIndex(quantity, status); - return ConvertToPluralStr(idxRet); + std::string converted; + icu::UnicodeString us = pluralRules->select(quantity); + us.toUTF8String(converted); + return converted; } const IdItem *HapManager::FindResourceById(uint32_t id) -- Gitee From 2599180e59cdc3c8d62e9dccd380bea0a4bf389d Mon Sep 17 00:00:00 2001 From: seaky Date: Thu, 8 Jul 2021 15:19:43 +0800 Subject: [PATCH 03/19] add icu locale Signed-off-by: seaky --- frameworks/resmgr/include/res_config_impl.h | 10 +- frameworks/resmgr/include/res_locale.h | 13 +- frameworks/resmgr/src/res_config_impl.cpp | 35 +++--- frameworks/resmgr/src/res_locale.cpp | 48 ++++---- .../resmgr/src/resource_manager_impl.cpp | 2 +- .../test/unittest/common/hap_parser_test.cpp | 6 +- .../test/unittest/common/locale_info_test.cpp | 114 +++++++++--------- .../unittest/common/resource_manager_test.cpp | 2 +- interfaces/innerkits/include/res_config.h | 16 +-- 9 files changed, 128 insertions(+), 118 deletions(-) diff --git a/frameworks/resmgr/include/res_config_impl.h b/frameworks/resmgr/include/res_config_impl.h index 768384a..7dfb76c 100644 --- a/frameworks/resmgr/include/res_config_impl.h +++ b/frameworks/resmgr/include/res_config_impl.h @@ -15,11 +15,11 @@ #ifndef OHOS_RESOURCE_MANAGER_RESCONFIG_IMPL_H #define OHOS_RESOURCE_MANAGER_RESCONFIG_IMPL_H #include -#include "locale_info.h" +#include #include "res_locale.h" #include "res_common.h" #include "res_config.h" -using OHOS::I18N::LocaleInfo; +using icu::Locale; namespace OHOS { namespace Global { namespace Resource { @@ -31,7 +31,7 @@ public: RState SetLocaleInfo(const char *language, const char *script, const char *region); - RState SetLocaleInfo(LocaleInfo& localeInfo); + RState SetLocaleInfo(Locale& localeInfo); void SetDeviceType(DeviceType deviceType); @@ -39,7 +39,7 @@ public: void SetScreenDensity(ScreenDensity screenDensity); - const LocaleInfo *GetLocaleInfo() const; + const Locale *GetLocaleInfo() const; const ResLocale *GetResLocale() const; @@ -69,7 +69,7 @@ private: ScreenDensity screenDensity_; DeviceType deviceType_; bool isCompletedScript_; - LocaleInfo *localeInfo_; + Locale *localeInfo_; }; } // namespace Resource } // namespace Global diff --git a/frameworks/resmgr/include/res_locale.h b/frameworks/resmgr/include/res_locale.h index 2cff83a..6c997f4 100644 --- a/frameworks/resmgr/include/res_locale.h +++ b/frameworks/resmgr/include/res_locale.h @@ -17,10 +17,11 @@ #define OHOS_RESOURCE_MANAGER_RES_LOCALE_H #include #include +#include + #include "rstate.h" #include "lock.h" -#include "locale_info.h" -using OHOS::I18N::LocaleInfo; +using icu::Locale; namespace OHOS { namespace Global { namespace Resource { @@ -42,13 +43,13 @@ public: ResLocale(); - RState CopyFromLocaleInfo(const LocaleInfo *other); + RState CopyFromLocaleInfo(const Locale *other); RState Copy(const ResLocale *other); - static const LocaleInfo* GetDefault(); + static const Locale* GetDefault(); - static bool UpdateDefault(const LocaleInfo& localeInfo, bool needNotify); + static bool UpdateDefault(const Locale& localeInfo, bool needNotify); static ResLocale* BuildFromString(const char *bcp47String, char sep, RState& rState); @@ -86,7 +87,7 @@ private: const char *script_; - static LocaleInfo *defaultLocale_; + static Locale *defaultLocale_; static Lock lock_; diff --git a/frameworks/resmgr/src/res_config_impl.cpp b/frameworks/resmgr/src/res_config_impl.cpp index db1e5b7..46bdc7e 100644 --- a/frameworks/resmgr/src/res_config_impl.cpp +++ b/frameworks/resmgr/src/res_config_impl.cpp @@ -14,11 +14,13 @@ */ #include "res_config_impl.h" -#include "locale_info.h" +#include +#include #include "locale_matcher.h" #include "res_locale.h" #include "utils/utils.h" - +using icu::Locale; +using icu::LocaleBuilder; namespace OHOS { namespace Global { namespace Resource { @@ -30,9 +32,9 @@ ResConfigImpl::ResConfigImpl() isCompletedScript_(false), localeInfo_(nullptr) {} -RState ResConfigImpl::SetLocaleInfo(LocaleInfo& localeInfo) +RState ResConfigImpl::SetLocaleInfo(Locale& localeInfo) { - return this->SetLocaleInfo(localeInfo.GetLanguage(), localeInfo.GetScript(), localeInfo.GetRegion()); + return this->SetLocaleInfo(localeInfo.getLanguage(), localeInfo.getScript(), localeInfo.getCountry()); } RState ResConfigImpl::SetLocaleInfo(const char *language, @@ -59,9 +61,11 @@ RState ResConfigImpl::SetLocaleInfo(const char *language, return NOT_ENOUGH_MEM; } } - LocaleInfo *tempLocale = new(std::nothrow) LocaleInfo(resLocale->GetLanguage(), - resLocale->GetScript(), resLocale->GetRegion()); - if (tempLocale == nullptr) { + UErrorCode errCode; + Locale temp = icu::LocaleBuilder().setLanguage(resLocale->GetLanguage()) + .setRegion(resLocale->GetRegion()).setScript(resLocale->GetScript()).build(errCode); + + if (!U_SUCCESS(errCode)) { state = NOT_ENOUGH_MEM; delete resLocale; return state; @@ -69,7 +73,7 @@ RState ResConfigImpl::SetLocaleInfo(const char *language, delete resLocale_; delete localeInfo_; resLocale_ = resLocale; - localeInfo_ = tempLocale; + localeInfo_ = &temp; } return state; @@ -90,7 +94,7 @@ void ResConfigImpl::SetScreenDensity(ScreenDensity screenDensity) this->screenDensity_ = screenDensity; } -const LocaleInfo *ResConfigImpl::GetLocaleInfo() const +const Locale *ResConfigImpl::GetLocaleInfo() const { return localeInfo_; } @@ -132,8 +136,8 @@ bool ResConfigImpl::CopyLocale(ResConfig &other) this->GetResLocale()->GetLanguage(), this->GetResLocale()->GetScript(), this->GetResLocale()->GetRegion()); uint64_t otherEncodedLocale = Utils::EncodeLocale( - other.GetLocaleInfo()->GetLanguage(), - other.GetLocaleInfo()->GetScript(), other.GetLocaleInfo()->GetRegion()); + other.GetLocaleInfo()->getLanguage(), + other.GetLocaleInfo()->getScript(), other.GetLocaleInfo()->getCountry()); if (encodedLocale != otherEncodedLocale) { needCopy = true; } @@ -148,16 +152,17 @@ bool ResConfigImpl::CopyLocale(ResConfig &other) delete temp; return false; } - LocaleInfo *tempLocale = new(std::nothrow) LocaleInfo(*other.GetLocaleInfo()); - if (tempLocale == nullptr) { - delete tempLocale; + UErrorCode errCode; + Locale tempLocale = icu::LocaleBuilder().setLocale(*other.GetLocaleInfo()).build(errCode); + + if (!U_SUCCESS(errCode)) { delete temp; return false; } delete this->resLocale_; delete this->localeInfo_; this->resLocale_ = temp; - this->localeInfo_ = tempLocale; + this->localeInfo_ = &tempLocale; } return true; } diff --git a/frameworks/resmgr/src/res_locale.cpp b/frameworks/resmgr/src/res_locale.cpp index 14dc22b..76ebc66 100644 --- a/frameworks/resmgr/src/res_locale.cpp +++ b/frameworks/resmgr/src/res_locale.cpp @@ -19,7 +19,7 @@ #include #include #include - +#include #include "auto_mutex.h" #include "hilog_wrapper.h" #include "locale_matcher.h" @@ -31,7 +31,7 @@ namespace OHOS { namespace Global { namespace Resource { -LocaleInfo *ResLocale::defaultLocale_ = nullptr; +Locale *ResLocale::defaultLocale_ = nullptr; Lock ResLocale::lock_ = Lock(); ResLocale::ResLocale() : language_(nullptr), region_(nullptr), script_(nullptr) @@ -126,10 +126,10 @@ RState ResLocale::Init(const char *language, size_t languageLen, const char *scr return SUCCESS; } -RState ResLocale::CopyFromLocaleInfo(const LocaleInfo *other) +RState ResLocale::CopyFromLocaleInfo(const Locale *other) { - return this->Init(other->GetLanguage(), Utils::StrLen(other->GetLanguage()), other->GetScript(), - Utils::StrLen(other->GetScript()), other->GetRegion(), Utils::StrLen(other->GetRegion())); + return this->Init(other->getLanguage(), Utils::StrLen(other->getLanguage()), other->getScript(), + Utils::StrLen(other->getScript()), other->getCountry(), Utils::StrLen(other->getCountry())); } RState ResLocale::Copy(const ResLocale *other) @@ -319,22 +319,22 @@ ResLocale *ResLocale::BuildFromParts(const char *language, return nullptr; }; -const LocaleInfo *ResLocale::GetDefault() +const Locale *ResLocale::GetDefault() { AutoMutex mutex(ResLocale::lock_); return ResLocale::defaultLocale_; } -bool ResLocale::UpdateDefault(const LocaleInfo& localeInfo, bool needNotify) +bool ResLocale::UpdateDefault(const Locale& localeInfo, bool needNotify) { AutoMutex mutex(ResLocale::lock_); - LocaleInfo *temp = new(std::nothrow) LocaleInfo(localeInfo.GetLanguage(), - localeInfo.GetScript(), localeInfo.GetRegion()); - if (temp == nullptr) { + UErrorCode errCode; + Locale temp = icu::LocaleBuilder().setLocale(localeInfo).build(errCode); + if (!U_SUCCESS(errCode)) { return false; } delete ResLocale::defaultLocale_; - ResLocale::defaultLocale_ = temp; + ResLocale::defaultLocale_ = &temp; return true; }; @@ -345,23 +345,25 @@ ResLocale::~ResLocale() delete this->region_; } -LocaleInfo *BuildFromString(const char *str, char sep, RState& rState) +Locale *BuildFromString(const char *str, char sep, RState& rState) { ResLocale *resLocale = ResLocale::BuildFromString(str, sep, rState); if (rState == SUCCESS) { - LocaleInfo *localeInfo = new(std::nothrow) LocaleInfo(resLocale->GetLanguage(), - resLocale->GetScript(), resLocale->GetRegion()); - if (localeInfo == nullptr) { + UErrorCode errCode; + Locale temp = icu::LocaleBuilder().setLanguage(resLocale->GetLanguage()) + .setRegion(resLocale->GetRegion()).setScript(resLocale->GetScript()).build(errCode); + + if (!U_SUCCESS(errCode)) { delete resLocale; rState = ERROR; return nullptr; } - return localeInfo; + return &temp; } return nullptr; }; -LocaleInfo *BuildFromParts(const char *language, const char *script, const char *region, RState& rState) +Locale *BuildFromParts(const char *language, const char *script, const char *region, RState& rState) { size_t len = Utils::StrLen(language); if (len == 0) { @@ -387,20 +389,22 @@ LocaleInfo *BuildFromParts(const char *language, const char *script, const char return nullptr; } } - LocaleInfo *localeInfo = new(std::nothrow) LocaleInfo(language, script, region); - if (localeInfo == nullptr) { + UErrorCode errCode; + Locale localeInfo = icu::LocaleBuilder().setLanguage(language) + .setRegion(region).setScript(script).build(errCode); + if (!U_SUCCESS(errCode)) { rState = ERROR; return nullptr; } - return localeInfo; + return &localeInfo; } -const LocaleInfo *GetSysDefault() +const Locale *GetSysDefault() { return ResLocale::GetDefault(); } -void UpdateSysDefault(const LocaleInfo& localeInfo, bool needNotify) +void UpdateSysDefault(const Locale& localeInfo, bool needNotify) { ResLocale::UpdateDefault(localeInfo, needNotify); } diff --git a/frameworks/resmgr/src/resource_manager_impl.cpp b/frameworks/resmgr/src/resource_manager_impl.cpp index b2c4665..b802d4b 100644 --- a/frameworks/resmgr/src/resource_manager_impl.cpp +++ b/frameworks/resmgr/src/resource_manager_impl.cpp @@ -598,7 +598,7 @@ RState ResourceManagerImpl::UpdateResConfig(ResConfig &resConfig) if (resConfig.GetLocaleInfo() == nullptr) { return LOCALEINFO_IS_NULL; } - if (resConfig.GetLocaleInfo()->GetLanguage() == nullptr) { + if (resConfig.GetLocaleInfo()->getLanguage() == nullptr) { return LOCALEINFO_IS_NULL; } return this->hapManager_->UpdateResConfig(resConfig); diff --git a/frameworks/resmgr/test/unittest/common/hap_parser_test.cpp b/frameworks/resmgr/test/unittest/common/hap_parser_test.cpp index 13decd6..8601e1b 100644 --- a/frameworks/resmgr/test/unittest/common/hap_parser_test.cpp +++ b/frameworks/resmgr/test/unittest/common/hap_parser_test.cpp @@ -94,9 +94,9 @@ HWTEST_F(HapParserTest, HapParserFuncTest001, TestSize.Level1) keyParams.push_back(kp); auto config = HapParser::CreateResConfigFromKeyParams(keyParams); if (config != nullptr) { - EXPECT_EQ(std::string("zh"), config->GetLocaleInfo()->GetLanguage()); - EXPECT_EQ(std::string("CN"), config->GetLocaleInfo()->GetRegion()); - EXPECT_EQ(std::string("Hans"), config->GetLocaleInfo()->GetScript()); + EXPECT_EQ(std::string("zh"), config->GetLocaleInfo()->getLanguage()); + EXPECT_EQ(std::string("CN"), config->GetLocaleInfo()->getCountry()); + EXPECT_EQ(std::string("Hans"), config->GetLocaleInfo()->getScript()); EXPECT_EQ(DEVICE_CAR, config->GetDeviceType()); EXPECT_EQ(DIRECTION_VERTICAL, config->GetDirection()); EXPECT_EQ(SCREEN_DENSITY_SDPI, config->GetScreenDensity()); diff --git a/frameworks/resmgr/test/unittest/common/locale_info_test.cpp b/frameworks/resmgr/test/unittest/common/locale_info_test.cpp index eb0af69..1aba733 100755 --- a/frameworks/resmgr/test/unittest/common/locale_info_test.cpp +++ b/frameworks/resmgr/test/unittest/common/locale_info_test.cpp @@ -172,20 +172,20 @@ HWTEST_F(LocaleInfoTest, LocaleInfoFindAndSortTest005, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoGetSysDefaultTest001, TestSize.Level1) { RState state = SUCCESS; - LocaleInfo* localeInfo = BuildFromString("zh-CN", '-', state); + Locale* localeInfo = BuildFromString("zh-CN", '-', state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; } UpdateSysDefault(*localeInfo, false); - const LocaleInfo* currentLocaleInfo = GetSysDefault(); + const Locale* currentLocaleInfo = GetSysDefault(); if (currentLocaleInfo == nullptr) { EXPECT_TRUE(false); delete localeInfo; return; } - EXPECT_TRUE(std::strcmp("zh", currentLocaleInfo->GetLanguage()) == 0); - EXPECT_TRUE(std::strcmp("CN", currentLocaleInfo->GetRegion()) == 0); + EXPECT_TRUE(std::strcmp("zh", currentLocaleInfo->getLanguage()) == 0); + EXPECT_TRUE(std::strcmp("CN", currentLocaleInfo->getCountry()) == 0); delete localeInfo; localeInfo = nullptr; } @@ -198,20 +198,20 @@ HWTEST_F(LocaleInfoTest, LocaleInfoGetSysDefaultTest001, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoUpdateSysDefaultTest001, TestSize.Level1) { RState state = SUCCESS; - LocaleInfo* localeInfo = BuildFromString("zh-CN", '-', state); + Locale* localeInfo = BuildFromString("zh-CN", '-', state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; } UpdateSysDefault(*localeInfo, false); - const LocaleInfo* currentLocaleInfo = GetSysDefault(); + const Locale* currentLocaleInfo = GetSysDefault(); if (currentLocaleInfo == nullptr) { EXPECT_TRUE(false); delete localeInfo; return; } - EXPECT_TRUE(std::strcmp("zh", currentLocaleInfo->GetLanguage()) == 0); - EXPECT_TRUE(std::strcmp("CN", currentLocaleInfo->GetRegion()) == 0); + EXPECT_TRUE(std::strcmp("zh", currentLocaleInfo->getLanguage()) == 0); + EXPECT_TRUE(std::strcmp("CN", currentLocaleInfo->getCountry()) == 0); delete localeInfo; localeInfo = BuildFromString("en-US", '-', state); UpdateSysDefault(*localeInfo, false); @@ -221,8 +221,8 @@ HWTEST_F(LocaleInfoTest, LocaleInfoUpdateSysDefaultTest001, TestSize.Level1) delete localeInfo; return; } - EXPECT_TRUE(std::strcmp("en", currentLocaleInfo->GetLanguage()) == 0); - EXPECT_TRUE(std::strcmp("US", currentLocaleInfo->GetRegion()) == 0); + EXPECT_TRUE(std::strcmp("en", currentLocaleInfo->getLanguage()) == 0); + EXPECT_TRUE(std::strcmp("US", currentLocaleInfo->getCountry()) == 0); delete localeInfo; localeInfo = BuildFromString("en-Qaag-US", '-', state); if (localeInfo == nullptr) { @@ -236,27 +236,27 @@ HWTEST_F(LocaleInfoTest, LocaleInfoUpdateSysDefaultTest001, TestSize.Level1) delete localeInfo; return; } - EXPECT_TRUE(std::strcmp("en", currentLocaleInfo->GetLanguage()) == 0); - EXPECT_TRUE(std::strcmp("US", currentLocaleInfo->GetRegion()) == 0); - EXPECT_TRUE(std::strcmp("Qaag", currentLocaleInfo->GetScript()) == 0); + EXPECT_TRUE(std::strcmp("en", currentLocaleInfo->getLanguage()) == 0); + EXPECT_TRUE(std::strcmp("US", currentLocaleInfo->getCountry()) == 0); + EXPECT_TRUE(std::strcmp("Qaag", currentLocaleInfo->getScript()) == 0); delete localeInfo; localeInfo = nullptr; } /* * @tc.name: LocaleInfoGetLanguageTest001 - * @tc.desc: Test LocaleInfo GetLanguage + * @tc.desc: Test LocaleInfo getLanguage * @tc.type: FUNC */ HWTEST_F(LocaleInfoTest, LocaleInfoGetLanguageTest001, TestSize.Level1) { RState state = SUCCESS; - LocaleInfo* localeInfo = BuildFromString("zh-CN", '-', state); + Locale* localeInfo = BuildFromString("zh-CN", '-', state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; } - EXPECT_TRUE(std::strcmp("zh", localeInfo->GetLanguage()) == 0); + EXPECT_TRUE(std::strcmp("zh", localeInfo->getLanguage()) == 0); delete localeInfo; localeInfo = nullptr; } @@ -269,12 +269,12 @@ HWTEST_F(LocaleInfoTest, LocaleInfoGetLanguageTest001, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoGetRegionTest001, TestSize.Level1) { RState state = SUCCESS; - LocaleInfo* localeInfo = BuildFromString("zh-CN", '-', state); + Locale* localeInfo = BuildFromString("zh-CN", '-', state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; } - EXPECT_TRUE(std::strcmp("CN", localeInfo->GetRegion()) == 0); + EXPECT_TRUE(std::strcmp("CN", localeInfo->getCountry()) == 0); delete localeInfo; localeInfo = nullptr; } @@ -287,12 +287,12 @@ HWTEST_F(LocaleInfoTest, LocaleInfoGetRegionTest001, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoGetScriptTest001, TestSize.Level1) { RState state = SUCCESS; - LocaleInfo* localeInfo = BuildFromString("zh-Hant-CN", '-', state); + Locale* localeInfo = BuildFromString("zh-Hant-CN", '-', state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; } - EXPECT_TRUE(std::strcmp("Hant", localeInfo->GetScript()) == 0); + EXPECT_TRUE(std::strcmp("Hant", localeInfo->getScript()) == 0); delete localeInfo; localeInfo = nullptr; } @@ -305,15 +305,15 @@ HWTEST_F(LocaleInfoTest, LocaleInfoGetScriptTest001, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest001, TestSize.Level1) { RState state = SUCCESS; - LocaleInfo* localeInfo = BuildFromParts("zh", "Hant", "CN", state); + Locale* localeInfo = BuildFromParts("zh", "Hant", "CN", state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; } EXPECT_TRUE(state == SUCCESS); - EXPECT_TRUE(std::strcmp("zh", localeInfo->GetLanguage()) == 0); - EXPECT_TRUE(std::strcmp("Hant", localeInfo->GetScript()) == 0); - EXPECT_TRUE(std::strcmp("CN", localeInfo->GetRegion()) == 0); + EXPECT_TRUE(std::strcmp("zh", localeInfo->getLanguage()) == 0); + EXPECT_TRUE(std::strcmp("Hant", localeInfo->getScript()) == 0); + EXPECT_TRUE(std::strcmp("CN", localeInfo->getCountry()) == 0); delete localeInfo; localeInfo = nullptr; } @@ -326,7 +326,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest001, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest002, TestSize.Level1) { RState state = SUCCESS; - LocaleInfo* localeInfo = BuildFromParts("zh1", "Hant", "CN", state); + Locale* localeInfo = BuildFromParts("zh1", "Hant", "CN", state); EXPECT_TRUE(state == INVALID_BCP47_LANGUAGE_SUBTAG); EXPECT_TRUE(localeInfo == nullptr); delete localeInfo; @@ -341,7 +341,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest002, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest003, TestSize.Level1) { RState state = SUCCESS; - LocaleInfo* localeInfo = BuildFromParts("zh", "Hants", "CN", state); + Locale* localeInfo = BuildFromParts("zh", "Hants", "CN", state); EXPECT_TRUE(state == INVALID_BCP47_SCRIPT_SUBTAG); EXPECT_TRUE(localeInfo == nullptr); delete localeInfo; @@ -356,7 +356,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest003, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest004, TestSize.Level1) { RState state = SUCCESS; - LocaleInfo* localeInfo = BuildFromParts("zh", "Hant", "C", state); + Locale* localeInfo = BuildFromParts("zh", "Hant", "C", state); EXPECT_TRUE(state == INVALID_BCP47_REGION_SUBTAG); EXPECT_TRUE(localeInfo == nullptr); delete localeInfo; @@ -371,7 +371,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest004, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest005, TestSize.Level1) { RState state = SUCCESS; - LocaleInfo* localeInfo = BuildFromParts(nullptr, "Hants", "CN", state); + Locale* localeInfo = BuildFromParts(nullptr, "Hants", "CN", state); EXPECT_TRUE(state == INVALID_BCP47_LANGUAGE_SUBTAG); EXPECT_TRUE(localeInfo == nullptr); delete localeInfo; @@ -386,15 +386,15 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest005, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest006, TestSize.Level1) { RState state = SUCCESS; - LocaleInfo* localeInfo = BuildFromParts("zh", nullptr, nullptr, state); + Locale* localeInfo = BuildFromParts("zh", nullptr, nullptr, state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; } EXPECT_TRUE(state == SUCCESS); - EXPECT_TRUE(std::strcmp("zh", localeInfo->GetLanguage()) == 0); - EXPECT_TRUE(localeInfo->GetScript() == nullptr); - EXPECT_TRUE(localeInfo->GetRegion() == nullptr); + EXPECT_TRUE(std::strcmp("zh", localeInfo->getLanguage()) == 0); + EXPECT_TRUE(localeInfo->getScript() == nullptr); + EXPECT_TRUE(localeInfo->getCountry() == nullptr); delete localeInfo; localeInfo = nullptr; } @@ -407,15 +407,15 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest006, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest001, TestSize.Level1) { RState state = SUCCESS; - LocaleInfo* localeInfo = BuildFromString("zh-Hant-CN", '-', state); + Locale* localeInfo = BuildFromString("zh-Hant-CN", '-', state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; } EXPECT_TRUE(state == SUCCESS); - EXPECT_TRUE(std::strcmp("zh", localeInfo->GetLanguage()) == 0); - EXPECT_TRUE(std::strcmp("Hant", localeInfo->GetScript()) == 0); - EXPECT_TRUE(std::strcmp("CN", localeInfo->GetRegion()) == 0); + EXPECT_TRUE(std::strcmp("zh", localeInfo->getLanguage()) == 0); + EXPECT_TRUE(std::strcmp("Hant", localeInfo->getScript()) == 0); + EXPECT_TRUE(std::strcmp("CN", localeInfo->getCountry()) == 0); delete localeInfo; localeInfo = nullptr; } @@ -428,7 +428,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest001, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest002, TestSize.Level1) { RState state = SUCCESS; - LocaleInfo* localeInfo = BuildFromString("zh1-Hant-CN", '-', state); + Locale* localeInfo = BuildFromString("zh1-Hant-CN", '-', state); EXPECT_TRUE(state == INVALID_BCP47_LANGUAGE_SUBTAG); EXPECT_TRUE(localeInfo == nullptr); delete localeInfo; @@ -443,7 +443,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest002, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest003, TestSize.Level1) { RState state = SUCCESS; - LocaleInfo* localeInfo = BuildFromString("-Hant-CN", '-', state); + Locale* localeInfo = BuildFromString("-Hant-CN", '-', state); EXPECT_TRUE(state == INVALID_BCP47_LANGUAGE_SUBTAG); EXPECT_TRUE(localeInfo == nullptr); delete localeInfo; @@ -458,15 +458,15 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest003, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest004, TestSize.Level1) { RState state = SUCCESS; - LocaleInfo* localeInfo = BuildFromString("zh", '-', state); + Locale* localeInfo = BuildFromString("zh", '-', state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; } EXPECT_TRUE(state == SUCCESS); - EXPECT_TRUE(std::strcmp("zh", localeInfo->GetLanguage()) == 0); - EXPECT_TRUE(localeInfo->GetScript() == nullptr); - EXPECT_TRUE(localeInfo->GetRegion() == nullptr); + EXPECT_TRUE(std::strcmp("zh", localeInfo->getLanguage()) == 0); + EXPECT_TRUE(localeInfo->getScript() == nullptr); + EXPECT_TRUE(localeInfo->getCountry() == nullptr); delete localeInfo; localeInfo = nullptr; } @@ -479,15 +479,15 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest004, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest005, TestSize.Level1) { RState state = SUCCESS; - LocaleInfo* localeInfo = BuildFromString("en_US", '_', state); + Locale* localeInfo = BuildFromString("en_US", '_', state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; } EXPECT_TRUE(state == SUCCESS); - EXPECT_TRUE(std::strcmp("en", localeInfo->GetLanguage()) == 0); - EXPECT_TRUE(localeInfo->GetScript() == nullptr); - EXPECT_TRUE(std::strcmp("US", localeInfo->GetRegion()) == 0); + EXPECT_TRUE(std::strcmp("en", localeInfo->getLanguage()) == 0); + EXPECT_TRUE(localeInfo->getScript() == nullptr); + EXPECT_TRUE(std::strcmp("US", localeInfo->getCountry()) == 0); delete localeInfo; localeInfo = nullptr; } @@ -500,7 +500,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest005, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest006, TestSize.Level1) { RState state = SUCCESS; - LocaleInfo* localeInfo = BuildFromString("en_Latn_US", '&', state); + Locale* localeInfo = BuildFromString("en_Latn_US", '&', state); EXPECT_TRUE(state == NOT_SUPPORT_SEP); EXPECT_TRUE(localeInfo == nullptr); delete localeInfo; @@ -515,15 +515,15 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest006, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest007, TestSize.Level1) { RState state = SUCCESS; - LocaleInfo* localeInfo = BuildFromString("en_Latn_US", '_', state); + Locale* localeInfo = BuildFromString("en_Latn_US", '_', state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; } EXPECT_TRUE(state == SUCCESS); - EXPECT_TRUE(std::strcmp("en", localeInfo->GetLanguage()) == 0); - EXPECT_TRUE(std::strcmp("Latn", localeInfo->GetScript()) == 0); - EXPECT_TRUE(std::strcmp("US", localeInfo->GetRegion()) == 0); + EXPECT_TRUE(std::strcmp("en", localeInfo->getLanguage()) == 0); + EXPECT_TRUE(std::strcmp("Latn", localeInfo->getScript()) == 0); + EXPECT_TRUE(std::strcmp("US", localeInfo->getCountry()) == 0); delete localeInfo; localeInfo = nullptr; } @@ -536,7 +536,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest007, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest008, TestSize.Level1) { RState state = SUCCESS; - LocaleInfo* localeInfo = BuildFromString("zh-Hants-CN", '-', state); + Locale* localeInfo = BuildFromString("zh-Hants-CN", '-', state); EXPECT_TRUE(state == INVALID_BCP47_SCRIPT_SUBTAG); EXPECT_TRUE(localeInfo == nullptr); delete localeInfo; @@ -551,7 +551,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest008, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest009, TestSize.Level1) { RState state = SUCCESS; - LocaleInfo* localeInfo = BuildFromString("zh-Hant-C", '-', state); + Locale* localeInfo = BuildFromString("zh-Hant-C", '-', state); EXPECT_TRUE(state == INVALID_BCP47_REGION_SUBTAG); EXPECT_TRUE(localeInfo == nullptr); delete localeInfo; @@ -566,15 +566,15 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest009, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest0010, TestSize.Level1) { RState state = SUCCESS; - LocaleInfo* localeInfo = BuildFromString("zh-CN-xxxx", '-', state); + Locale* localeInfo = BuildFromString("zh-CN-xxxx", '-', state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; } EXPECT_TRUE(state == SUCCESS); - EXPECT_TRUE(std::strcmp("zh", localeInfo->GetLanguage()) == 0); - EXPECT_TRUE(localeInfo->GetScript() == nullptr); - EXPECT_TRUE(std::strcmp("CN", localeInfo->GetRegion()) == 0); + EXPECT_TRUE(std::strcmp("zh", localeInfo->getLanguage()) == 0); + EXPECT_TRUE(localeInfo->getScript() == nullptr); + EXPECT_TRUE(std::strcmp("CN", localeInfo->getCountry()) == 0); delete localeInfo; localeInfo = nullptr; } diff --git a/frameworks/resmgr/test/unittest/common/resource_manager_test.cpp b/frameworks/resmgr/test/unittest/common/resource_manager_test.cpp index 7889673..266b3d7 100644 --- a/frameworks/resmgr/test/unittest/common/resource_manager_test.cpp +++ b/frameworks/resmgr/test/unittest/common/resource_manager_test.cpp @@ -369,7 +369,7 @@ HWTEST_F(ResourceManagerTest, ResourceManagerGetResConfigTest002, TestSize.Level ResConfigImpl rc; rm->GetResConfig(rc); - EXPECT_EQ("en", std::string(rc.GetLocaleInfo()->GetLanguage())); + EXPECT_EQ("en", std::string(rc.GetLocaleInfo()->getLanguage())); EXPECT_EQ(DEVICE_CAR, rc.GetDeviceType()); } diff --git a/interfaces/innerkits/include/res_config.h b/interfaces/innerkits/include/res_config.h index b708d0d..8ac6b08 100644 --- a/interfaces/innerkits/include/res_config.h +++ b/interfaces/innerkits/include/res_config.h @@ -15,11 +15,11 @@ #ifndef OHOS_RESOURCE_MANAGER_RESCONFIG_H #define OHOS_RESOURCE_MANAGER_RESCONFIG_H +#include #include -#include "locale_info.h" #include "res_common.h" #include "rstate.h" -using OHOS::I18N::LocaleInfo; +using icu::Locale; namespace OHOS { namespace Global { namespace Resource { @@ -27,7 +27,7 @@ class ResConfig { public: virtual RState SetLocaleInfo(const char *language, const char *script, const char *region) = 0; - virtual RState SetLocaleInfo(LocaleInfo& localeInfo) = 0; + virtual RState SetLocaleInfo(Locale& localeInfo) = 0; virtual void SetDeviceType(DeviceType deviceType) = 0; @@ -35,7 +35,7 @@ public: virtual void SetScreenDensity(ScreenDensity screenDensity) = 0; - virtual const LocaleInfo *GetLocaleInfo() const = 0; + virtual const Locale *GetLocaleInfo() const = 0; virtual Direction GetDirection() const = 0; @@ -49,13 +49,13 @@ public: }; ResConfig *CreateResConfig(); -const LocaleInfo* GetSysDefault(); +const Locale* GetSysDefault(); -void UpdateSysDefault(const LocaleInfo& localeInfo, bool needNotify); +void UpdateSysDefault(const Locale& localeInfo, bool needNotify); -LocaleInfo* BuildFromString(const char *str, char sep, RState& rState); +Locale* BuildFromString(const char *str, char sep, RState& rState); -LocaleInfo* BuildFromParts(const char *language, const char *script, const char *region, RState& rState); +Locale* BuildFromParts(const char *language, const char *script, const char *region, RState& rState); void FindAndSort(std::string localeStr, std::vector& candidateLocale, std::vector& outValue); } // namespace Resource -- Gitee From 2aed4137b4b1bed197102eec85c94b008bc7d301 Mon Sep 17 00:00:00 2001 From: caisirius Date: Thu, 8 Jul 2021 15:37:57 +0800 Subject: [PATCH 04/19] delete i18n Signed-off-by: caisirius --- frameworks/resmgr/test/unittest/common/locale_info_test.cpp | 1 - frameworks/resmgr/test/unittest/common/string_utils_test.cpp | 2 -- 2 files changed, 3 deletions(-) diff --git a/frameworks/resmgr/test/unittest/common/locale_info_test.cpp b/frameworks/resmgr/test/unittest/common/locale_info_test.cpp index 1aba733..900d071 100755 --- a/frameworks/resmgr/test/unittest/common/locale_info_test.cpp +++ b/frameworks/resmgr/test/unittest/common/locale_info_test.cpp @@ -20,7 +20,6 @@ #include #include "hilog_wrapper.h" -#include "locale_info.h" #include "test_common.h" using namespace OHOS::Global::Resource; diff --git a/frameworks/resmgr/test/unittest/common/string_utils_test.cpp b/frameworks/resmgr/test/unittest/common/string_utils_test.cpp index cfe24af..48c5527 100644 --- a/frameworks/resmgr/test/unittest/common/string_utils_test.cpp +++ b/frameworks/resmgr/test/unittest/common/string_utils_test.cpp @@ -17,14 +17,12 @@ #include #include -#include #include "test_common.h" #include "utils/string_utils.h" using namespace OHOS::Global::Resource; using namespace testing::ext; -using namespace OHOS::I18N; class StringUtilsTest : public testing::Test { public: -- Gitee From 2eb83941073fc5bcf6cb2f792340ec5d2d28c5d0 Mon Sep 17 00:00:00 2001 From: caisirius Date: Thu, 8 Jul 2021 16:30:17 +0800 Subject: [PATCH 05/19] icu fix Signed-off-by: caisirius --- frameworks/resmgr/src/res_config_impl.cpp | 8 +-- frameworks/resmgr/src/res_locale.cpp | 14 +++-- .../test/unittest/common/locale_info_test.cpp | 58 +++++++++---------- 3 files changed, 41 insertions(+), 39 deletions(-) diff --git a/frameworks/resmgr/src/res_config_impl.cpp b/frameworks/resmgr/src/res_config_impl.cpp index 46bdc7e..5756b6f 100644 --- a/frameworks/resmgr/src/res_config_impl.cpp +++ b/frameworks/resmgr/src/res_config_impl.cpp @@ -61,7 +61,7 @@ RState ResConfigImpl::SetLocaleInfo(const char *language, return NOT_ENOUGH_MEM; } } - UErrorCode errCode; + UErrorCode errCode = U_ZERO_ERROR; Locale temp = icu::LocaleBuilder().setLanguage(resLocale->GetLanguage()) .setRegion(resLocale->GetRegion()).setScript(resLocale->GetScript()).build(errCode); @@ -73,7 +73,7 @@ RState ResConfigImpl::SetLocaleInfo(const char *language, delete resLocale_; delete localeInfo_; resLocale_ = resLocale; - localeInfo_ = &temp; + localeInfo_ = new Locale(temp); } return state; @@ -152,7 +152,7 @@ bool ResConfigImpl::CopyLocale(ResConfig &other) delete temp; return false; } - UErrorCode errCode; + UErrorCode errCode = U_ZERO_ERROR; Locale tempLocale = icu::LocaleBuilder().setLocale(*other.GetLocaleInfo()).build(errCode); if (!U_SUCCESS(errCode)) { @@ -162,7 +162,7 @@ bool ResConfigImpl::CopyLocale(ResConfig &other) delete this->resLocale_; delete this->localeInfo_; this->resLocale_ = temp; - this->localeInfo_ = &tempLocale; + this->localeInfo_ = new Locale(tempLocale); } return true; } diff --git a/frameworks/resmgr/src/res_locale.cpp b/frameworks/resmgr/src/res_locale.cpp index 76ebc66..19745e9 100644 --- a/frameworks/resmgr/src/res_locale.cpp +++ b/frameworks/resmgr/src/res_locale.cpp @@ -328,13 +328,13 @@ const Locale *ResLocale::GetDefault() bool ResLocale::UpdateDefault(const Locale& localeInfo, bool needNotify) { AutoMutex mutex(ResLocale::lock_); - UErrorCode errCode; + UErrorCode errCode = U_ZERO_ERROR; Locale temp = icu::LocaleBuilder().setLocale(localeInfo).build(errCode); if (!U_SUCCESS(errCode)) { return false; } delete ResLocale::defaultLocale_; - ResLocale::defaultLocale_ = &temp; + ResLocale::defaultLocale_ = new Locale(temp); return true; }; @@ -349,7 +349,7 @@ Locale *BuildFromString(const char *str, char sep, RState& rState) { ResLocale *resLocale = ResLocale::BuildFromString(str, sep, rState); if (rState == SUCCESS) { - UErrorCode errCode; + UErrorCode errCode = U_ZERO_ERROR; Locale temp = icu::LocaleBuilder().setLanguage(resLocale->GetLanguage()) .setRegion(resLocale->GetRegion()).setScript(resLocale->GetScript()).build(errCode); @@ -358,7 +358,8 @@ Locale *BuildFromString(const char *str, char sep, RState& rState) rState = ERROR; return nullptr; } - return &temp; + Locale *retLocal = new Locale(temp); + return retLocal; } return nullptr; }; @@ -389,14 +390,15 @@ Locale *BuildFromParts(const char *language, const char *script, const char *reg return nullptr; } } - UErrorCode errCode; + UErrorCode errCode = U_ZERO_ERROR; Locale localeInfo = icu::LocaleBuilder().setLanguage(language) .setRegion(region).setScript(script).build(errCode); if (!U_SUCCESS(errCode)) { rState = ERROR; return nullptr; } - return &localeInfo; + Locale *retLocal = new Locale(localeInfo); + return retLocal; } const Locale *GetSysDefault() diff --git a/frameworks/resmgr/test/unittest/common/locale_info_test.cpp b/frameworks/resmgr/test/unittest/common/locale_info_test.cpp index 900d071..03a8020 100755 --- a/frameworks/resmgr/test/unittest/common/locale_info_test.cpp +++ b/frameworks/resmgr/test/unittest/common/locale_info_test.cpp @@ -171,13 +171,13 @@ HWTEST_F(LocaleInfoTest, LocaleInfoFindAndSortTest005, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoGetSysDefaultTest001, TestSize.Level1) { RState state = SUCCESS; - Locale* localeInfo = BuildFromString("zh-CN", '-', state); + Locale *localeInfo = BuildFromString("zh-CN", '-', state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; } UpdateSysDefault(*localeInfo, false); - const Locale* currentLocaleInfo = GetSysDefault(); + const Locale *currentLocaleInfo = GetSysDefault(); if (currentLocaleInfo == nullptr) { EXPECT_TRUE(false); delete localeInfo; @@ -197,13 +197,13 @@ HWTEST_F(LocaleInfoTest, LocaleInfoGetSysDefaultTest001, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoUpdateSysDefaultTest001, TestSize.Level1) { RState state = SUCCESS; - Locale* localeInfo = BuildFromString("zh-CN", '-', state); + Locale *localeInfo = BuildFromString("zh-CN", '-', state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; } UpdateSysDefault(*localeInfo, false); - const Locale* currentLocaleInfo = GetSysDefault(); + const Locale *currentLocaleInfo = GetSysDefault(); if (currentLocaleInfo == nullptr) { EXPECT_TRUE(false); delete localeInfo; @@ -250,7 +250,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoUpdateSysDefaultTest001, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoGetLanguageTest001, TestSize.Level1) { RState state = SUCCESS; - Locale* localeInfo = BuildFromString("zh-CN", '-', state); + Locale *localeInfo = BuildFromString("zh-CN", '-', state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; @@ -268,7 +268,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoGetLanguageTest001, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoGetRegionTest001, TestSize.Level1) { RState state = SUCCESS; - Locale* localeInfo = BuildFromString("zh-CN", '-', state); + Locale *localeInfo = BuildFromString("zh-CN", '-', state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; @@ -286,7 +286,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoGetRegionTest001, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoGetScriptTest001, TestSize.Level1) { RState state = SUCCESS; - Locale* localeInfo = BuildFromString("zh-Hant-CN", '-', state); + Locale *localeInfo = BuildFromString("zh-Hant-CN", '-', state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; @@ -304,7 +304,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoGetScriptTest001, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest001, TestSize.Level1) { RState state = SUCCESS; - Locale* localeInfo = BuildFromParts("zh", "Hant", "CN", state); + Locale *localeInfo = BuildFromParts("zh", "Hant", "CN", state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; @@ -325,7 +325,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest001, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest002, TestSize.Level1) { RState state = SUCCESS; - Locale* localeInfo = BuildFromParts("zh1", "Hant", "CN", state); + Locale *localeInfo = BuildFromParts("zh1", "Hant", "CN", state); EXPECT_TRUE(state == INVALID_BCP47_LANGUAGE_SUBTAG); EXPECT_TRUE(localeInfo == nullptr); delete localeInfo; @@ -340,7 +340,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest002, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest003, TestSize.Level1) { RState state = SUCCESS; - Locale* localeInfo = BuildFromParts("zh", "Hants", "CN", state); + Locale *localeInfo = BuildFromParts("zh", "Hants", "CN", state); EXPECT_TRUE(state == INVALID_BCP47_SCRIPT_SUBTAG); EXPECT_TRUE(localeInfo == nullptr); delete localeInfo; @@ -355,7 +355,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest003, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest004, TestSize.Level1) { RState state = SUCCESS; - Locale* localeInfo = BuildFromParts("zh", "Hant", "C", state); + Locale *localeInfo = BuildFromParts("zh", "Hant", "C", state); EXPECT_TRUE(state == INVALID_BCP47_REGION_SUBTAG); EXPECT_TRUE(localeInfo == nullptr); delete localeInfo; @@ -370,7 +370,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest004, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest005, TestSize.Level1) { RState state = SUCCESS; - Locale* localeInfo = BuildFromParts(nullptr, "Hants", "CN", state); + Locale *localeInfo = BuildFromParts(nullptr, "Hants", "CN", state); EXPECT_TRUE(state == INVALID_BCP47_LANGUAGE_SUBTAG); EXPECT_TRUE(localeInfo == nullptr); delete localeInfo; @@ -385,15 +385,15 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest005, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest006, TestSize.Level1) { RState state = SUCCESS; - Locale* localeInfo = BuildFromParts("zh", nullptr, nullptr, state); + Locale *localeInfo = BuildFromParts("zh", nullptr, nullptr, state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; } EXPECT_TRUE(state == SUCCESS); EXPECT_TRUE(std::strcmp("zh", localeInfo->getLanguage()) == 0); - EXPECT_TRUE(localeInfo->getScript() == nullptr); - EXPECT_TRUE(localeInfo->getCountry() == nullptr); + EXPECT_TRUE(localeInfo->getScript()[0] == '\0'); + EXPECT_TRUE(localeInfo->getCountry()[0] == '\0'); delete localeInfo; localeInfo = nullptr; } @@ -406,7 +406,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromPartsTest006, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest001, TestSize.Level1) { RState state = SUCCESS; - Locale* localeInfo = BuildFromString("zh-Hant-CN", '-', state); + Locale *localeInfo = BuildFromString("zh-Hant-CN", '-', state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; @@ -427,7 +427,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest001, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest002, TestSize.Level1) { RState state = SUCCESS; - Locale* localeInfo = BuildFromString("zh1-Hant-CN", '-', state); + Locale *localeInfo = BuildFromString("zh1-Hant-CN", '-', state); EXPECT_TRUE(state == INVALID_BCP47_LANGUAGE_SUBTAG); EXPECT_TRUE(localeInfo == nullptr); delete localeInfo; @@ -442,7 +442,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest002, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest003, TestSize.Level1) { RState state = SUCCESS; - Locale* localeInfo = BuildFromString("-Hant-CN", '-', state); + Locale *localeInfo = BuildFromString("-Hant-CN", '-', state); EXPECT_TRUE(state == INVALID_BCP47_LANGUAGE_SUBTAG); EXPECT_TRUE(localeInfo == nullptr); delete localeInfo; @@ -457,15 +457,15 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest003, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest004, TestSize.Level1) { RState state = SUCCESS; - Locale* localeInfo = BuildFromString("zh", '-', state); + Locale *localeInfo = BuildFromString("zh", '-', state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; } EXPECT_TRUE(state == SUCCESS); EXPECT_TRUE(std::strcmp("zh", localeInfo->getLanguage()) == 0); - EXPECT_TRUE(localeInfo->getScript() == nullptr); - EXPECT_TRUE(localeInfo->getCountry() == nullptr); + EXPECT_TRUE(localeInfo->getScript()[0] == '\0'); + EXPECT_TRUE(localeInfo->getCountry()[0] == '\0'); delete localeInfo; localeInfo = nullptr; } @@ -478,14 +478,14 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest004, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest005, TestSize.Level1) { RState state = SUCCESS; - Locale* localeInfo = BuildFromString("en_US", '_', state); + Locale *localeInfo = BuildFromString("en_US", '_', state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; } EXPECT_TRUE(state == SUCCESS); EXPECT_TRUE(std::strcmp("en", localeInfo->getLanguage()) == 0); - EXPECT_TRUE(localeInfo->getScript() == nullptr); + EXPECT_TRUE(localeInfo->getScript()[0] == '\0'); EXPECT_TRUE(std::strcmp("US", localeInfo->getCountry()) == 0); delete localeInfo; localeInfo = nullptr; @@ -499,7 +499,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest005, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest006, TestSize.Level1) { RState state = SUCCESS; - Locale* localeInfo = BuildFromString("en_Latn_US", '&', state); + Locale *localeInfo = BuildFromString("en_Latn_US", '&', state); EXPECT_TRUE(state == NOT_SUPPORT_SEP); EXPECT_TRUE(localeInfo == nullptr); delete localeInfo; @@ -514,7 +514,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest006, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest007, TestSize.Level1) { RState state = SUCCESS; - Locale* localeInfo = BuildFromString("en_Latn_US", '_', state); + Locale *localeInfo = BuildFromString("en_Latn_US", '_', state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; @@ -535,7 +535,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest007, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest008, TestSize.Level1) { RState state = SUCCESS; - Locale* localeInfo = BuildFromString("zh-Hants-CN", '-', state); + Locale *localeInfo = BuildFromString("zh-Hants-CN", '-', state); EXPECT_TRUE(state == INVALID_BCP47_SCRIPT_SUBTAG); EXPECT_TRUE(localeInfo == nullptr); delete localeInfo; @@ -550,7 +550,7 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest008, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest009, TestSize.Level1) { RState state = SUCCESS; - Locale* localeInfo = BuildFromString("zh-Hant-C", '-', state); + Locale *localeInfo = BuildFromString("zh-Hant-C", '-', state); EXPECT_TRUE(state == INVALID_BCP47_REGION_SUBTAG); EXPECT_TRUE(localeInfo == nullptr); delete localeInfo; @@ -565,14 +565,14 @@ HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest009, TestSize.Level1) HWTEST_F(LocaleInfoTest, LocaleInfoBuildFromStringTest0010, TestSize.Level1) { RState state = SUCCESS; - Locale* localeInfo = BuildFromString("zh-CN-xxxx", '-', state); + Locale *localeInfo = BuildFromString("zh-CN-xxxx", '-', state); if (localeInfo == nullptr) { EXPECT_TRUE(false); return; } EXPECT_TRUE(state == SUCCESS); EXPECT_TRUE(std::strcmp("zh", localeInfo->getLanguage()) == 0); - EXPECT_TRUE(localeInfo->getScript() == nullptr); + EXPECT_TRUE(localeInfo->getScript()[0] == '\0'); EXPECT_TRUE(std::strcmp("CN", localeInfo->getCountry()) == 0); delete localeInfo; localeInfo = nullptr; -- Gitee From c0c61d2bb974a554c43a71de80b1f4d7c9d0fed7 Mon Sep 17 00:00:00 2001 From: caisirius Date: Thu, 8 Jul 2021 16:35:45 +0800 Subject: [PATCH 06/19] split HapResource::LoadFromIndex() for perf test Signed-off-by: caisirius --- .../resource_manager_performance_test.cpp | 92 ++++++++++++++++--- 1 file changed, 77 insertions(+), 15 deletions(-) diff --git a/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp b/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp index 0e028d4..64a0c26 100644 --- a/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp +++ b/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp @@ -19,10 +19,14 @@ #include #include #include +#include #include +#include #define private public +#include "hap_parser.h" +#include "hap_resource.h" #include "resource_manager.h" #include "resource_manager_impl.h" #include "test_common.h" @@ -106,31 +110,89 @@ void ResourceManagerPerformanceTest::TearDown(void) } } -/* - * @tc.name: ResourceManagerPerformanceFuncTest001 - * @tc.desc: Test AddResource - * @tc.type: FUNC - */ -HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest001, TestSize.Level1) +// test HapResource::LoadFromIndex(), spilt to two parts: 1. read from file, 2. parse buf to HapResource +int TestLoadFromIndex(const char *filePath) { unsigned long long total = 0; double average = 0; + std::string pstr = FormatFullPath(filePath); + const char *path = pstr.c_str(); + + auto start = std::chrono::high_resolution_clock::now(); + std::ifstream inFile(path, std::ios::binary | std::ios::in); + if (!inFile.good()) { + return -1; + } + inFile.seekg(0, std::ios::end); + size_t bufLen = inFile.tellg(); + inFile.close(); + std::ifstream inFile2(path, std::ios::binary | std::ios::in); + void *buf = malloc(bufLen); + if (buf == nullptr) { + HILOG_ERROR("Error allocating memory"); + return -1; + } + inFile2.read((char *)buf, bufLen); + inFile2.close(); + + auto end = std::chrono::high_resolution_clock::now(); + auto readFilecost = std::chrono::duration_cast(end - start).count(); + + g_logLevel = LOG_DEBUG; + HILOG_DEBUG("read index file cost 001: %d us", readFilecost); + g_logLevel = LOG_INFO; + for (int k = 0; k < 1000; ++k) { - auto tmpRm = CreateResourceManager(); - if (tmpRm == nullptr) { - EXPECT_TRUE(false); - return; - } auto t1 = std::chrono::high_resolution_clock::now(); - tmpRm->AddResource(FormatFullPath(g_resFilePath).c_str()); + ResDesc *resDesc = new(std::nothrow) ResDesc(); + if (resDesc == nullptr) { + HILOG_ERROR("new ResDesc failed when LoadFromIndex"); + free(buf); + return -1; + } + int32_t out = HapParser::ParseResHex((char *) buf, bufLen, *resDesc, nullptr); + if (out != OK) { + delete (resDesc); + free(buf); + HILOG_ERROR("ParseResHex failed! retcode:%d", out); + return -1; + } else { + HILOG_DEBUG("ParseResHex success:\n%s", resDesc->ToString().c_str()); + } + + HapResource *pResource = new(std::nothrow) HapResource(std::string(path), 0, nullptr, resDesc); + if (pResource == nullptr) { + HILOG_ERROR("new HapResource failed when LoadFromIndex"); + delete (resDesc); + free(buf); + return -1; + } + if (!pResource->Init()) { + delete (pResource); + free(buf); + return -1; + } auto t2 = std::chrono::high_resolution_clock::now(); total += std::chrono::duration_cast(t2 - t1).count(); - delete tmpRm; + delete pResource; } + free(buf); average = total / 1000.0; g_logLevel = LOG_DEBUG; - HILOG_DEBUG("avg cost 001: %f us", average); - EXPECT_LT(average, 9000); + HILOG_DEBUG("parse index avg cost 001: %f us", average); + EXPECT_LT(average, 4000); + return OK; +} + +/* + * @tc.name: ResourceManagerPerformanceFuncTest001 + * @tc.desc: Test AddResource + * @tc.type: FUNC + */ +HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest001, TestSize.Level1) +{ + int ret = TestLoadFromIndex(g_resFilePath); + EXPECT_EQ(OK, ret); }; /* -- Gitee From 204bfc8b280d730c7e8bf4db3f73d133ce7692d5 Mon Sep 17 00:00:00 2001 From: caisirius Date: Mon, 12 Jul 2021 13:48:18 +0800 Subject: [PATCH 07/19] fix code scan Signed-off-by: caisirius --- frameworks/resmgr/src/res_config_impl.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frameworks/resmgr/src/res_config_impl.cpp b/frameworks/resmgr/src/res_config_impl.cpp index 5756b6f..0156a57 100644 --- a/frameworks/resmgr/src/res_config_impl.cpp +++ b/frameworks/resmgr/src/res_config_impl.cpp @@ -14,8 +14,9 @@ */ #include "res_config_impl.h" -#include #include +#include + #include "locale_matcher.h" #include "res_locale.h" #include "utils/utils.h" -- Gitee From 9f6205d78677e917b39f8ce9379a713515451731 Mon Sep 17 00:00:00 2001 From: caisirius Date: Mon, 12 Jul 2021 15:12:49 +0800 Subject: [PATCH 08/19] BUILD.gn Signed-off-by: caisirius --- frameworks/resmgr/BUILD.gn | 2 +- frameworks/resmgr/test/BUILD.gn | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/frameworks/resmgr/BUILD.gn b/frameworks/resmgr/BUILD.gn index 0887fa5..866be56 100755 --- a/frameworks/resmgr/BUILD.gn +++ b/frameworks/resmgr/BUILD.gn @@ -17,11 +17,11 @@ ohos_shared_library("global_resmgr") { sources = [ "src/hap_manager.cpp", "src/hap_resource.cpp", - "src/locale_info_impl.cpp", "src/locale_matcher.cpp", "src/lock.cpp", "src/res_config_impl.cpp", "src/res_desc.cpp", + "src/res_locale.cpp", "src/resource_manager_impl.cpp", "src/utils/hap_parser.cpp", "src/utils/string_utils.cpp", diff --git a/frameworks/resmgr/test/BUILD.gn b/frameworks/resmgr/test/BUILD.gn index 8922ef7..be1abb2 100755 --- a/frameworks/resmgr/test/BUILD.gn +++ b/frameworks/resmgr/test/BUILD.gn @@ -26,6 +26,7 @@ ohos_unittest("resmgr_test") { "unittest/common/res_desc_test.cpp", "unittest/common/resource_manager_performance_test.cpp", "unittest/common/resource_manager_test.cpp", + "unittest/common/string_utils_test.cpp", "unittest/common/test_common.cpp", ] -- Gitee From 2193dea0fc9a86ff25366574b3578ff0c809cf94 Mon Sep 17 00:00:00 2001 From: caisirius Date: Mon, 12 Jul 2021 16:08:42 +0800 Subject: [PATCH 09/19] ohos.build Signed-off-by: caisirius --- ohos.build | 1 - 1 file changed, 1 deletion(-) diff --git a/ohos.build b/ohos.build index 884be5f..03c943c 100755 --- a/ohos.build +++ b/ohos.build @@ -11,7 +11,6 @@ "header": { "header_base": "//base/global/resmgr_standard/interfaces/innerkits/include/", "header_files": [ - "locale_info.h", "res_common.h", "res_config.h", "resource_manager.h", -- Gitee From 1304918ed16ece7106e1966c0c1126e18ac37df0 Mon Sep 17 00:00:00 2001 From: caisirius Date: Mon, 12 Jul 2021 18:24:31 +0800 Subject: [PATCH 10/19] log Signed-off-by: caisirius --- .../test/unittest/common/resource_manager_performance_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp b/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp index 64a0c26..d2a21c0 100644 --- a/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp +++ b/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp @@ -139,7 +139,7 @@ int TestLoadFromIndex(const char *filePath) auto readFilecost = std::chrono::duration_cast(end - start).count(); g_logLevel = LOG_DEBUG; - HILOG_DEBUG("read index file cost 001: %d us", readFilecost); + HILOG_DEBUG("read index file cost 001: %lld us", readFilecost); g_logLevel = LOG_INFO; for (int k = 0; k < 1000; ++k) { -- Gitee From 370d17653628e6ddad6a102d227b720303fbc8c1 Mon Sep 17 00:00:00 2001 From: caisirius Date: Tue, 13 Jul 2021 10:38:54 +0800 Subject: [PATCH 11/19] fix code scan Signed-off-by: caisirius --- frameworks/resmgr/src/locale_matcher.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/resmgr/src/locale_matcher.cpp b/frameworks/resmgr/src/locale_matcher.cpp index 0e0be8a..7ccac93 100644 --- a/frameworks/resmgr/src/locale_matcher.cpp +++ b/frameworks/resmgr/src/locale_matcher.cpp @@ -319,8 +319,8 @@ bool CompareScript(const ResLocale *current, const ResLocale *other) } } bool compareRegion = false; - if ((currentEncodedScript == LocaleMatcher::NULL_SCRIPT) || (otherEncodedScript== LocaleMatcher::NULL_SCRIPT)) { - // if request script is null, region must be same + if ((currentEncodedScript == LocaleMatcher::NULL_SCRIPT) || (otherEncodedScript == LocaleMatcher::NULL_SCRIPT)) { + // if request script is null, region must be same compareRegion = true; } if (compareRegion) { -- Gitee From 46d28a30fd2f3adbaad5f7e099756bd935200b86 Mon Sep 17 00:00:00 2001 From: seaky Date: Tue, 13 Jul 2021 14:15:07 +0800 Subject: [PATCH 12/19] add lock implement Signed-off-by: seaky --- frameworks/resmgr/BUILD.gn | 2 +- frameworks/resmgr/include/lock.h | 3 ++ frameworks/resmgr/src/lock.cpp | 9 +++-- frameworks/resmgr/test/BUILD.gn | 2 ++ .../unittest/common/string_utils_test.cpp | 36 +++++++++++++++++++ .../test/unittest/common/string_utils_test.h | 1 + 6 files changed, 50 insertions(+), 3 deletions(-) diff --git a/frameworks/resmgr/BUILD.gn b/frameworks/resmgr/BUILD.gn index 0887fa5..3307dc8 100755 --- a/frameworks/resmgr/BUILD.gn +++ b/frameworks/resmgr/BUILD.gn @@ -17,7 +17,7 @@ ohos_shared_library("global_resmgr") { sources = [ "src/hap_manager.cpp", "src/hap_resource.cpp", - "src/locale_info_impl.cpp", + "src/res_locale.cpp", "src/locale_matcher.cpp", "src/lock.cpp", "src/res_config_impl.cpp", diff --git a/frameworks/resmgr/include/lock.h b/frameworks/resmgr/include/lock.h index d98b19e..ebb1a0d 100644 --- a/frameworks/resmgr/include/lock.h +++ b/frameworks/resmgr/include/lock.h @@ -14,6 +14,7 @@ */ #ifndef OHOS_RESOURCE_MANAGER_LOCK_H #define OHOS_RESOURCE_MANAGER_LOCK_H +#include namespace OHOS { namespace Global { @@ -29,6 +30,8 @@ public: bool unlock(); private: + std::mutex* mtx_; + }; } // namespace Resource } // namespace Global diff --git a/frameworks/resmgr/src/lock.cpp b/frameworks/resmgr/src/lock.cpp index b7dfb85..293db12 100644 --- a/frameworks/resmgr/src/lock.cpp +++ b/frameworks/resmgr/src/lock.cpp @@ -13,23 +13,28 @@ * limitations under the License. */ #include "lock.h" +#include namespace OHOS { namespace Global { namespace Resource { -Lock::Lock() +Lock::Lock():mtx_(new std::mutex) {} Lock::~Lock() -{} +{ + delete mtx_; +} bool Lock::lock() { + this->mtx_->lock(); return true; } bool Lock::unlock() { + this->mtx_->unlock(); return true; } } // namespace Resource diff --git a/frameworks/resmgr/test/BUILD.gn b/frameworks/resmgr/test/BUILD.gn index 8922ef7..c039228 100755 --- a/frameworks/resmgr/test/BUILD.gn +++ b/frameworks/resmgr/test/BUILD.gn @@ -26,7 +26,9 @@ ohos_unittest("resmgr_test") { "unittest/common/res_desc_test.cpp", "unittest/common/resource_manager_performance_test.cpp", "unittest/common/resource_manager_test.cpp", + "unittest/common/string_utils_test.cpp", "unittest/common/test_common.cpp", + ] include_dirs = [ diff --git a/frameworks/resmgr/test/unittest/common/string_utils_test.cpp b/frameworks/resmgr/test/unittest/common/string_utils_test.cpp index 48c5527..2f21ee9 100644 --- a/frameworks/resmgr/test/unittest/common/string_utils_test.cpp +++ b/frameworks/resmgr/test/unittest/common/string_utils_test.cpp @@ -17,7 +17,9 @@ #include #include +#include +#include "auto_mutex.h" #include "test_common.h" #include "utils/string_utils.h" @@ -68,4 +70,38 @@ HWTEST_F(StringUtilsTest, StringUtilsFuncTest001, TestSize.Level1) result = FormatString("I'm %s, I'm %d", "cici", 5); EXPECT_EQ("I'm cici, I'm 5", result); +} + +void FuncMultiThread(int* num, Lock* lock) +{ + AutoMutex mtx(*lock); + auto tmp = (*num); + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + (*num) = tmp + 1; +} + +void TestThread(int* num, int threadNum, Lock* lock) +{ + std::vector threads; + for (int i = 0; i < threadNum; ++i) { + threads.push_back(std::thread(FuncMultiThread, num, lock)); + } + for (auto &thread : threads) { + thread.join(); + } +} + +/* + * @tc.name: LockFuncTest001 + * @tc.desc: Test lock, none file case. + * @tc.type: FUNC + */ +HWTEST_F(StringUtilsTest, LockFuncTest001, TestSize.Level1) +{ + int num = 0; + int threadNum = 3; + int result = num + threadNum; + Lock lock = Lock(); + TestThread(&num, threadNum, &lock); + EXPECT_EQ(result, num); } \ No newline at end of file diff --git a/frameworks/resmgr/test/unittest/common/string_utils_test.h b/frameworks/resmgr/test/unittest/common/string_utils_test.h index 0e5642f..f2ee919 100644 --- a/frameworks/resmgr/test/unittest/common/string_utils_test.h +++ b/frameworks/resmgr/test/unittest/common/string_utils_test.h @@ -17,5 +17,6 @@ #define RESOURCE_MANAGER_STRING_UTILS_TEST_H int StringUtilsFuncTest001(); +int LockFuncTest001(); #endif -- Gitee From b015e52353b92f3e41d7d6d1f4f56fd1caca09de Mon Sep 17 00:00:00 2001 From: seaky Date: Tue, 20 Jul 2021 11:32:26 +0800 Subject: [PATCH 13/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=98=88=E5=80=BC=20Signed-off-by:=20seaky?= =?UTF-8?q?=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frameworks/resmgr/include/res_locale.h | 1 - .../resource_manager_performance_test.cpp | 64 +++++++++---------- .../unittest/common/string_utils_test.cpp | 2 - 3 files changed, 32 insertions(+), 35 deletions(-) diff --git a/frameworks/resmgr/include/res_locale.h b/frameworks/resmgr/include/res_locale.h index 6c997f4..14b8058 100644 --- a/frameworks/resmgr/include/res_locale.h +++ b/frameworks/resmgr/include/res_locale.h @@ -18,7 +18,6 @@ #include #include #include - #include "rstate.h" #include "lock.h" using icu::Locale; diff --git a/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp b/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp index d2a21c0..e43ef85 100644 --- a/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp +++ b/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp @@ -180,7 +180,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, 4000); + EXPECT_LT(average, 2000); return OK; } @@ -228,7 +228,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest002, average = total / 1000.0; g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 002: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -262,7 +262,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest003, average = total / 1000.0; g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 003: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -299,7 +299,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest004, average = total / (1000.0 * count); g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 004: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -329,7 +329,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest005, average = total / (1000.0 * count); g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 005: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -359,7 +359,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest006, average = total / (1000.0 * count); g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 006: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -396,7 +396,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest007, average = total / (1000.0 * count); g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 007: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -426,7 +426,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest008, average = total / (1000.0 * count); g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 008: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -455,7 +455,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest009, average = total / 1000.0; g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 009: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -481,7 +481,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest010, average = total / 1000.0; g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 010: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -517,7 +517,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest011, average = total / (1000.0 * count); g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 011: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -547,7 +547,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest012, average = total / (1000.0 * count); g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 012: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -580,7 +580,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest013, average = total / (1000.0 * count); g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 013: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -610,7 +610,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest014, average = total / (1000.0 * count); g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 014: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -643,7 +643,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest015, average = total / (1000.0 * count); g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 015: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -673,7 +673,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest016, average = total / (1000.0 * count); g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 016: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -702,7 +702,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest017, average = total / 1000.0; g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 017: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -728,7 +728,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest018, average = total / 1000.0; g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 018: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -757,7 +757,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest019, average = total / 1000.0; g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 019: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -783,7 +783,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest020, average = total / 1000.0; g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 020: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -812,7 +812,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest021, average = total / 1000.0; g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 021: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -838,7 +838,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest022, average = total / 1000.0; g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 022: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -867,7 +867,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest023, average = total / 1000.0; g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 023: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -893,7 +893,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest024, average = total / 1000.0; g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 024: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -922,7 +922,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest025, average = total / 1000.0; g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 025: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -948,7 +948,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest026, average = total / 1000.0; g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 026: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -977,7 +977,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest027, average = total / 1000.0; g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 027: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -1003,7 +1003,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest028, average = total / 1000.0; g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 028: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -1032,7 +1032,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest029, average = total / 1000.0; g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 029: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -1058,7 +1058,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest030, average = total / 1000.0; g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 030: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -1087,7 +1087,7 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest031, average = total / 1000.0; g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 031: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; /* @@ -1113,5 +1113,5 @@ HWTEST_F(ResourceManagerPerformanceTest, ResourceManagerPerformanceFuncTest032, average = total / 1000.0; g_logLevel = LOG_DEBUG; HILOG_DEBUG("avg cost 032: %f us", average); - EXPECT_LT(average, 500); + EXPECT_LT(average, 100); }; diff --git a/frameworks/resmgr/test/unittest/common/string_utils_test.cpp b/frameworks/resmgr/test/unittest/common/string_utils_test.cpp index 2f21ee9..cc88354 100644 --- a/frameworks/resmgr/test/unittest/common/string_utils_test.cpp +++ b/frameworks/resmgr/test/unittest/common/string_utils_test.cpp @@ -14,11 +14,9 @@ */ #include "string_utils_test.h" - #include #include #include - #include "auto_mutex.h" #include "test_common.h" #include "utils/string_utils.h" -- Gitee From 94d2348dd2c071f793ff340f9742d86bff34816e Mon Sep 17 00:00:00 2001 From: caisirius Date: Tue, 20 Jul 2021 12:37:39 +0800 Subject: [PATCH 14/19] malloc check length Signed-off-by: caisirius --- frameworks/resmgr/src/hap_resource.cpp | 6 +++++- .../unittest/common/resource_manager_performance_test.cpp | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/frameworks/resmgr/src/hap_resource.cpp b/frameworks/resmgr/src/hap_resource.cpp index 8c6d6bb..45b351f 100644 --- a/frameworks/resmgr/src/hap_resource.cpp +++ b/frameworks/resmgr/src/hap_resource.cpp @@ -92,12 +92,16 @@ const HapResource *HapResource::LoadFromIndex(const char *path, const ResConfigI inFile.seekg(0, std::ios::end); size_t bufLen = inFile.tellg(); inFile.close(); - std::ifstream inFile2(path, std::ios::binary | std::ios::in); + if (bufLen <= 0) { + HILOG_ERROR("file size is zero"); + return nullptr; + } void *buf = malloc(bufLen); if (buf == nullptr) { HILOG_ERROR("Error allocating memory"); return nullptr; } + std::ifstream inFile2(path, std::ios::binary | std::ios::in); inFile2.read((char *)buf, bufLen); inFile2.close(); diff --git a/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp b/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp index e43ef85..fb99631 100644 --- a/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp +++ b/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp @@ -126,12 +126,16 @@ int TestLoadFromIndex(const char *filePath) inFile.seekg(0, std::ios::end); size_t bufLen = inFile.tellg(); inFile.close(); - std::ifstream inFile2(path, std::ios::binary | std::ios::in); + if (bufLen <= 0) { + HILOG_ERROR("file size is zero"); + return -1; + } void *buf = malloc(bufLen); if (buf == nullptr) { HILOG_ERROR("Error allocating memory"); return -1; } + std::ifstream inFile2(path, std::ios::binary | std::ios::in); inFile2.read((char *)buf, bufLen); inFile2.close(); -- Gitee From 0e5b0b7fcf069ad9553e2e015773e8f7a8ffbe19 Mon Sep 17 00:00:00 2001 From: seaky Date: Tue, 27 Jul 2021 14:41:17 +0800 Subject: [PATCH 15/19] change js innerkit to icu locale Signed-off-by: seaky --- interfaces/js/kits/src/resource_manager_addon.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/interfaces/js/kits/src/resource_manager_addon.cpp b/interfaces/js/kits/src/resource_manager_addon.cpp index ec0e972..923747c 100755 --- a/interfaces/js/kits/src/resource_manager_addon.cpp +++ b/interfaces/js/kits/src/resource_manager_addon.cpp @@ -17,11 +17,13 @@ #include #include +#include #include #include "hilog/log.h" #include "node_api.h" +using icu::Locale; namespace OHOS { namespace Global { namespace Resource { @@ -598,22 +600,22 @@ napi_value ResourceManagerAddon::GetMediaBase64(napi_env env, napi_callback_info std::string ResourceManagerAddon::GetLocale(std::unique_ptr &cfg) { std::string result; - const LocaleInfo *localeInfo = cfg->GetLocaleInfo(); + const Locale *localeInfo = cfg->GetLocaleInfo(); if (localeInfo == nullptr) { return result; } - const char *lang = localeInfo->GetLanguage(); + const char *lang = localeInfo->getLanguage(); if (lang == nullptr) { return result; } result = lang; - const char *script = localeInfo->GetScript(); + const char *script = localeInfo->getScript(); if (script != nullptr) { result += std::string("_") + script; } - const char *region = localeInfo->GetRegion(); + const char *region = localeInfo->getCountry(); if (region != nullptr) { result += std::string("_") + region; } -- Gitee From 5fd8530e52a727c2a24cab722b0e2a702f1a1d00 Mon Sep 17 00:00:00 2001 From: seaky Date: Tue, 27 Jul 2021 21:53:58 +0800 Subject: [PATCH 16/19] change localeinfo to icu loclae Signed-off-by: seaky --- frameworks/resmgr/BUILD.gn | 40 ++++++++++++++++++++++++++----------- interfaces/js/kits/BUILD.gn | 4 ++-- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/frameworks/resmgr/BUILD.gn b/frameworks/resmgr/BUILD.gn index 866be56..d8f1362 100755 --- a/frameworks/resmgr/BUILD.gn +++ b/frameworks/resmgr/BUILD.gn @@ -13,6 +13,28 @@ import("//build/ohos.gni") +config("resmgr_config") { + include_dirs = [ + "include", + "//third_party/zlib", + "//third_party/zlib/contrib/minizip", + "//base/global/resmgr_standard/interfaces/innerkits/include", + "//third_party/bounds_checking_function/include", + "//third_party/icu/icu4c/source", + "//third_party/icu/icu4c/source/common", + "//third_party/icu/icu4c/source/i18n", + ] +} + +config("resmgr_public_config") { + visibility = [ ":*" ] + + include_dirs = [ + "//base/global/resmgr_standard/interfaces/innerkits/include", + "//third_party/icu/icu4c/source/common", + ] +} + ohos_shared_library("global_resmgr") { sources = [ "src/hap_manager.cpp", @@ -28,17 +50,11 @@ ohos_shared_library("global_resmgr") { "src/utils/utils.cpp", ] - include_dirs = [ - "include", - "//third_party/zlib", - "//third_party/zlib/contrib/minizip", - "//base/global/resmgr_standard/interfaces/innerkits/include", - "//third_party/bounds_checking_function/include", - "//third_party/icu/icu4c/source", - "//third_party/icu/icu4c/source/common", - "//third_party/icu/icu4c/source/i18n", - ] - public_deps = [ + configs = [ ":resmgr_config" ] + + public_configs = [ ":resmgr_public_config" ] + + deps = [ "//third_party/bounds_checking_function:libsec_static", "//third_party/icu/icu4c:shared_icui18n", "//third_party/icu/icu4c:shared_icuuc", @@ -48,4 +64,4 @@ ohos_shared_library("global_resmgr") { subsystem_name = "global" part_name = "resmgr_standard" -} +} \ No newline at end of file diff --git a/interfaces/js/kits/BUILD.gn b/interfaces/js/kits/BUILD.gn index 48ae3d2..3d219fc 100755 --- a/interfaces/js/kits/BUILD.gn +++ b/interfaces/js/kits/BUILD.gn @@ -23,7 +23,7 @@ ohos_shared_library("resmgr") { sources = [ "src/resource_manager_addon.cpp" ] - deps = [ + public_deps = [ "//base/global/resmgr_standard/frameworks/resmgr:global_resmgr", "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", "//foundation/ace/napi:ace_napi", @@ -41,4 +41,4 @@ ohos_shared_library("resmgr") { relative_install_dir = "module" subsystem_name = "global" part_name = "resmgr_standard" -} +} \ No newline at end of file -- Gitee From a0f07af026d270462867542f35261b2915b275a5 Mon Sep 17 00:00:00 2001 From: seaky Date: Tue, 27 Jul 2021 22:17:17 +0800 Subject: [PATCH 17/19] change localeinfo to icu locale Signed-off-by: seaky --- interfaces/js/kits/src/resource_manager_addon.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/interfaces/js/kits/src/resource_manager_addon.cpp b/interfaces/js/kits/src/resource_manager_addon.cpp index 923747c..3967b48 100755 --- a/interfaces/js/kits/src/resource_manager_addon.cpp +++ b/interfaces/js/kits/src/resource_manager_addon.cpp @@ -17,13 +17,11 @@ #include #include -#include #include #include "hilog/log.h" #include "node_api.h" -using icu::Locale; namespace OHOS { namespace Global { namespace Resource { @@ -600,7 +598,7 @@ napi_value ResourceManagerAddon::GetMediaBase64(napi_env env, napi_callback_info std::string ResourceManagerAddon::GetLocale(std::unique_ptr &cfg) { std::string result; - const Locale *localeInfo = cfg->GetLocaleInfo(); + const icu::Locale *localeInfo = cfg->GetLocaleInfo(); if (localeInfo == nullptr) { return result; } -- Gitee From e8ec9707cc5dea77ab717be01aa7046dc3555136 Mon Sep 17 00:00:00 2001 From: caisirius Date: Thu, 29 Jul 2021 19:07:04 +0800 Subject: [PATCH 18/19] fix code scan by human Signed-off-by: caisirius --- frameworks/resmgr/include/res_config_impl.h | 5 ++++- frameworks/resmgr/src/hap_resource.cpp | 9 +++++---- frameworks/resmgr/src/res_config_impl.cpp | 9 ++++----- frameworks/resmgr/src/res_locale.cpp | 18 +++++++++--------- frameworks/resmgr/src/utils/utils.cpp | 7 +++---- .../test/unittest/common/locale_info_test.cpp | 1 - .../resource_manager_performance_test.cpp | 9 +++++---- interfaces/innerkits/include/res_config.h | 16 +++++++++------- .../js/kits/src/resource_manager_addon.cpp | 2 +- 9 files changed, 40 insertions(+), 36 deletions(-) diff --git a/frameworks/resmgr/include/res_config_impl.h b/frameworks/resmgr/include/res_config_impl.h index 7dfb76c..9131bab 100644 --- a/frameworks/resmgr/include/res_config_impl.h +++ b/frameworks/resmgr/include/res_config_impl.h @@ -14,11 +14,13 @@ */ #ifndef OHOS_RESOURCE_MANAGER_RESCONFIG_IMPL_H #define OHOS_RESOURCE_MANAGER_RESCONFIG_IMPL_H + #include #include #include "res_locale.h" #include "res_common.h" #include "res_config.h" + using icu::Locale; namespace OHOS { namespace Global { @@ -31,7 +33,7 @@ public: RState SetLocaleInfo(const char *language, const char *script, const char *region); - RState SetLocaleInfo(Locale& localeInfo); + RState SetLocaleInfo(Locale &localeInfo); void SetDeviceType(DeviceType deviceType); @@ -61,6 +63,7 @@ public: private: bool IsMoreSpecificThan(const ResConfigImpl *other) const; + bool CopyLocale(ResConfig &other); private: diff --git a/frameworks/resmgr/src/hap_resource.cpp b/frameworks/resmgr/src/hap_resource.cpp index 45b351f..741fc52 100644 --- a/frameworks/resmgr/src/hap_resource.cpp +++ b/frameworks/resmgr/src/hap_resource.cpp @@ -91,19 +91,20 @@ const HapResource *HapResource::LoadFromIndex(const char *path, const ResConfigI } inFile.seekg(0, std::ios::end); size_t bufLen = inFile.tellg(); - inFile.close(); if (bufLen <= 0) { HILOG_ERROR("file size is zero"); + inFile.close(); return nullptr; } void *buf = malloc(bufLen); if (buf == nullptr) { HILOG_ERROR("Error allocating memory"); + inFile.close(); return nullptr; } - std::ifstream inFile2(path, std::ios::binary | std::ios::in); - inFile2.read((char *)buf, bufLen); - inFile2.close(); + inFile.seekg(0, std::ios::beg); + inFile.read((char *)buf, bufLen); + inFile.close(); HILOG_DEBUG("extract success, bufLen:%zu", bufLen); diff --git a/frameworks/resmgr/src/res_config_impl.cpp b/frameworks/resmgr/src/res_config_impl.cpp index 0156a57..3aafc89 100644 --- a/frameworks/resmgr/src/res_config_impl.cpp +++ b/frameworks/resmgr/src/res_config_impl.cpp @@ -33,7 +33,7 @@ ResConfigImpl::ResConfigImpl() isCompletedScript_(false), localeInfo_(nullptr) {} -RState ResConfigImpl::SetLocaleInfo(Locale& localeInfo) +RState ResConfigImpl::SetLocaleInfo(Locale &localeInfo) { return this->SetLocaleInfo(localeInfo.getLanguage(), localeInfo.getScript(), localeInfo.getCountry()); } @@ -63,7 +63,7 @@ RState ResConfigImpl::SetLocaleInfo(const char *language, } } UErrorCode errCode = U_ZERO_ERROR; - Locale temp = icu::LocaleBuilder().setLanguage(resLocale->GetLanguage()) + Locale temp = icu::LocaleBuilder().setLanguage(resLocale->GetLanguage()) .setRegion(resLocale->GetRegion()).setScript(resLocale->GetScript()).build(errCode); if (!U_SUCCESS(errCode)) { @@ -154,7 +154,7 @@ bool ResConfigImpl::CopyLocale(ResConfig &other) return false; } UErrorCode errCode = U_ZERO_ERROR; - Locale tempLocale = icu::LocaleBuilder().setLocale(*other.GetLocaleInfo()).build(errCode); + Locale tempLocale = icu::LocaleBuilder().setLocale(*other.GetLocaleInfo()).build(errCode); if (!U_SUCCESS(errCode)) { delete temp; @@ -187,8 +187,7 @@ bool ResConfigImpl::Copy(ResConfig &other) bool ResConfigImpl::Match(const ResConfigImpl *other) const { - if (LocaleMatcher::Match(this->resLocale_, other->GetResLocale()) == - false) { + if (LocaleMatcher::Match(this->resLocale_, other->GetResLocale()) == false) { return false; } if (this->direction_ != DIRECTION_NOT_SET && diff --git a/frameworks/resmgr/src/res_locale.cpp b/frameworks/resmgr/src/res_locale.cpp index 19745e9..731b582 100644 --- a/frameworks/resmgr/src/res_locale.cpp +++ b/frameworks/resmgr/src/res_locale.cpp @@ -153,7 +153,7 @@ const char *ResLocale::GetScript() const return this->script_; } -RState ProcessSubtag(const char *curPos, int32_t subTagLen, uint16_t& nextType, ParseResult& r) +RState ProcessSubtag(const char *curPos, int32_t subTagLen, uint16_t &nextType, ParseResult &r) { if ((ResLocale::LANG_TYPE & nextType) && (LocaleMatcher::IsLanguageTag(curPos, subTagLen))) { r.tempLanguage = curPos; @@ -184,7 +184,7 @@ void CheckArg(char sep, RState &rState) } } -ResLocale *ResLocale::CreateResLocale(ParseResult& r, RState& rState) +ResLocale *ResLocale::CreateResLocale(ParseResult &r, RState &rState) { ResLocale *resLocale = new(std::nothrow) ResLocale; if (resLocale == nullptr) { @@ -325,7 +325,7 @@ const Locale *ResLocale::GetDefault() return ResLocale::defaultLocale_; } -bool ResLocale::UpdateDefault(const Locale& localeInfo, bool needNotify) +bool ResLocale::UpdateDefault(const Locale &localeInfo, bool needNotify) { AutoMutex mutex(ResLocale::lock_); UErrorCode errCode = U_ZERO_ERROR; @@ -345,12 +345,12 @@ ResLocale::~ResLocale() delete this->region_; } -Locale *BuildFromString(const char *str, char sep, RState& rState) +Locale *BuildFromString(const char *str, char sep, RState &rState) { ResLocale *resLocale = ResLocale::BuildFromString(str, sep, rState); if (rState == SUCCESS) { UErrorCode errCode = U_ZERO_ERROR; - Locale temp = icu::LocaleBuilder().setLanguage(resLocale->GetLanguage()) + Locale temp = icu::LocaleBuilder().setLanguage(resLocale->GetLanguage()) .setRegion(resLocale->GetRegion()).setScript(resLocale->GetScript()).build(errCode); if (!U_SUCCESS(errCode)) { @@ -364,7 +364,7 @@ Locale *BuildFromString(const char *str, char sep, RState& rState) return nullptr; }; -Locale *BuildFromParts(const char *language, const char *script, const char *region, RState& rState) +Locale *BuildFromParts(const char *language, const char *script, const char *region, RState &rState) { size_t len = Utils::StrLen(language); if (len == 0) { @@ -391,7 +391,7 @@ Locale *BuildFromParts(const char *language, const char *script, const char *reg } } UErrorCode errCode = U_ZERO_ERROR; - Locale localeInfo = icu::LocaleBuilder().setLanguage(language) + Locale localeInfo = icu::LocaleBuilder().setLanguage(language) .setRegion(region).setScript(script).build(errCode); if (!U_SUCCESS(errCode)) { rState = ERROR; @@ -406,12 +406,12 @@ const Locale *GetSysDefault() return ResLocale::GetDefault(); } -void UpdateSysDefault(const Locale& localeInfo, bool needNotify) +void UpdateSysDefault(const Locale &localeInfo, bool needNotify) { ResLocale::UpdateDefault(localeInfo, needNotify); } -void FindAndSort(std::string localeStr, std::vector& candidateLocale, std::vector& outValue) +void FindAndSort(std::string localeStr, std::vector &candidateLocale, std::vector &outValue) { if (candidateLocale.size() == 0) { return; diff --git a/frameworks/resmgr/src/utils/utils.cpp b/frameworks/resmgr/src/utils/utils.cpp index 5076b58..fc5bf2f 100644 --- a/frameworks/resmgr/src/utils/utils.cpp +++ b/frameworks/resmgr/src/utils/utils.cpp @@ -106,7 +106,7 @@ uint64_t Utils::EncodeLocale(const char *language, uint32_t scriptData = Utils::EncodeScript(script); uint16_t regionData = Utils::EncodeRegion(region); - return (uint64_t) (0xffff000000000000 & (((uint64_t)languageData) << 48)) | + return (uint64_t)(0xffff000000000000 & (((uint64_t)languageData) << 48)) | (0x0000ffffffff0000 & (((uint64_t)scriptData) << 16)) | (0x000000000000ffff & (uint64_t)(regionData)); } @@ -220,10 +220,9 @@ bool Utils::StrCompare(const char *left, const char *right, size_t len, bool isC return false; } else { if (isCaseSensitive) { - rc = (int)(unsigned char)(c1) - (int)(unsigned char)(c2); + rc = (int)(c1) - (int)(c2); } else { - rc = - (int)(unsigned char)tolower(c1) - (int)(unsigned char)tolower(c2); + rc = tolower(c1) - tolower(c2); } if (rc != 0) { return false; diff --git a/frameworks/resmgr/test/unittest/common/locale_info_test.cpp b/frameworks/resmgr/test/unittest/common/locale_info_test.cpp index 03a8020..ad5a4d8 100755 --- a/frameworks/resmgr/test/unittest/common/locale_info_test.cpp +++ b/frameworks/resmgr/test/unittest/common/locale_info_test.cpp @@ -186,7 +186,6 @@ HWTEST_F(LocaleInfoTest, LocaleInfoGetSysDefaultTest001, TestSize.Level1) EXPECT_TRUE(std::strcmp("zh", currentLocaleInfo->getLanguage()) == 0); EXPECT_TRUE(std::strcmp("CN", currentLocaleInfo->getCountry()) == 0); delete localeInfo; - localeInfo = nullptr; } /* diff --git a/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp b/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp index fb99631..425e205 100644 --- a/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp +++ b/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp @@ -125,19 +125,20 @@ int TestLoadFromIndex(const char *filePath) } inFile.seekg(0, std::ios::end); size_t bufLen = inFile.tellg(); - inFile.close(); if (bufLen <= 0) { HILOG_ERROR("file size is zero"); + inFile.close(); return -1; } void *buf = malloc(bufLen); if (buf == nullptr) { HILOG_ERROR("Error allocating memory"); + inFile.close(); return -1; } - std::ifstream inFile2(path, std::ios::binary | std::ios::in); - inFile2.read((char *)buf, bufLen); - inFile2.close(); + inFile.seekg(0, std::ios::beg); + inFile.read((char *)buf, bufLen); + inFile.close(); auto end = std::chrono::high_resolution_clock::now(); auto readFilecost = std::chrono::duration_cast(end - start).count(); diff --git a/interfaces/innerkits/include/res_config.h b/interfaces/innerkits/include/res_config.h index 8ac6b08..5a04cd6 100644 --- a/interfaces/innerkits/include/res_config.h +++ b/interfaces/innerkits/include/res_config.h @@ -19,6 +19,7 @@ #include #include "res_common.h" #include "rstate.h" + using icu::Locale; namespace OHOS { namespace Global { @@ -27,7 +28,7 @@ class ResConfig { public: virtual RState SetLocaleInfo(const char *language, const char *script, const char *region) = 0; - virtual RState SetLocaleInfo(Locale& localeInfo) = 0; + virtual RState SetLocaleInfo(Locale &localeInfo) = 0; virtual void SetDeviceType(DeviceType deviceType) = 0; @@ -43,21 +44,22 @@ public: virtual DeviceType GetDeviceType() const = 0; - virtual bool Copy(ResConfig& other) = 0; + virtual bool Copy(ResConfig &other) = 0; virtual ~ResConfig() {} }; + ResConfig *CreateResConfig(); -const Locale* GetSysDefault(); +const Locale *GetSysDefault(); -void UpdateSysDefault(const Locale& localeInfo, bool needNotify); +void UpdateSysDefault(const Locale &localeInfo, bool needNotify); -Locale* BuildFromString(const char *str, char sep, RState& rState); +Locale *BuildFromString(const char *str, char sep, RState &rState); -Locale* BuildFromParts(const char *language, const char *script, const char *region, RState& rState); +Locale *BuildFromParts(const char *language, const char *script, const char *region, RState &rState); -void FindAndSort(std::string localeStr, std::vector& candidateLocale, std::vector& outValue); +void FindAndSort(std::string localeStr, std::vector &candidateLocale, std::vector &outValue); } // namespace Resource } // namespace Global } // namespace OHOS diff --git a/interfaces/js/kits/src/resource_manager_addon.cpp b/interfaces/js/kits/src/resource_manager_addon.cpp index 3967b48..e1ed187 100755 --- a/interfaces/js/kits/src/resource_manager_addon.cpp +++ b/interfaces/js/kits/src/resource_manager_addon.cpp @@ -64,7 +64,7 @@ void ResourceManagerAddon::Destructor(napi_env env, void *nativeObject, void *hi delete addonPtr; } -void ResMgrAsyncContext::SetErrorMsg(const std::string& msg, bool withResId) +void ResMgrAsyncContext::SetErrorMsg(const std::string &msg, bool withResId) { errMsg_ = msg; success_ = false; -- Gitee From c091908d94da78cae897fc7aaabc11d2aac3d9b6 Mon Sep 17 00:00:00 2001 From: caisirius Date: Fri, 30 Jul 2021 17:24:35 +0800 Subject: [PATCH 19/19] fix code scan Signed-off-by: caisirius --- frameworks/resmgr/include/lock.h | 1 - 1 file changed, 1 deletion(-) diff --git a/frameworks/resmgr/include/lock.h b/frameworks/resmgr/include/lock.h index ebb1a0d..d200f07 100644 --- a/frameworks/resmgr/include/lock.h +++ b/frameworks/resmgr/include/lock.h @@ -31,7 +31,6 @@ public: private: std::mutex* mtx_; - }; } // namespace Resource } // namespace Global -- Gitee