diff --git a/frameworks/resmgr/include/hap_manager.h b/frameworks/resmgr/include/hap_manager.h index 6aefb5c..5e7fb44 100644 --- a/frameworks/resmgr/include/hap_manager.h +++ b/frameworks/resmgr/include/hap_manager.h @@ -37,7 +37,7 @@ public: * @param resConfig resource config * @param isSystem system flag, default value is false */ - HapManager(ResConfigImpl *resConfig, bool isSystem = false); + HapManager(std::shared_ptr resConfig, bool isSystem = false); /** * The destructor of HapManager @@ -108,7 +108,7 @@ public: * @param id the resource id * @return the resources related to resource id */ - const IdItem *FindResourceById(uint32_t id); + const std::shared_ptr FindResourceById(uint32_t id); /** * Find resource by resource name @@ -116,7 +116,7 @@ public: * @param resType the resource type * @return the resources related to resource name */ - const IdItem *FindResourceByName(const char *name, const ResType resType); + const std::shared_ptr FindResourceByName(const char *name, const ResType resType); /** * Find best resource path by resource id @@ -124,7 +124,8 @@ public: * @param density the input screen density * @return the best resource path */ - const HapResource::ValueUnderQualifierDir *FindQualifierValueById(uint32_t id, uint32_t density = 0); + const std::shared_ptr FindQualifierValueById(uint32_t id, + uint32_t density = 0); /** * Find best resource path by resource name @@ -133,8 +134,8 @@ public: * @param density the input screen density * @return the best resource path */ - const HapResource::ValueUnderQualifierDir *FindQualifierValueByName(const char *name, const ResType resType, - uint32_t density = 0); + const std::shared_ptr FindQualifierValueByName(const char *name, + const ResType resType, uint32_t density = 0); /** * Find the raw file path @@ -163,7 +164,7 @@ public: * @param outValue the media data * @return SUCCESS if get the media data success, else NOT_FOUND */ - RState GetMediaData(const HapResource::ValueUnderQualifierDir *qd, size_t& len, + RState GetMediaData(const std::shared_ptr qd, size_t& len, std::unique_ptr &outValue); /** @@ -172,7 +173,7 @@ public: * @param outValue the mediabase64 data * @return SUCCESS if get the mediabase64 data success, else NOT_FOUND */ - RState GetMediaBase64Data(const HapResource::ValueUnderQualifierDir *qd, std::string &outValue); + RState GetMediaBase64Data(const std::shared_ptr qd, std::string &outValue); /** * Get the Profile data @@ -181,7 +182,7 @@ public: * @param outValue the profile data * @return SUCCESS if get the profile data success, else NOT_FOUND */ - RState GetProfileData(const HapResource::ValueUnderQualifierDir *qd, size_t &len, + RState GetProfileData(const std::shared_ptr qd, size_t &len, std::unique_ptr &outValue); /** @@ -238,7 +239,7 @@ public: * @param outValue the resource path write to * @return SUCCESS if resource exist, else not found */ - RState GetFilePath(const HapResource::ValueUnderQualifierDir *qd, const ResType resType, + RState GetFilePath(const std::shared_ptr qd, const ResType resType, std::string &outValue); /** @@ -248,7 +249,7 @@ public: * @param outValue the media data write to * @return SUCCESS if resource exist, else not found */ - RState GetMediaDataFromHap(const HapResource::ValueUnderQualifierDir *qd, size_t &len, + RState GetMediaDataFromHap(const std::shared_ptr qd, size_t &len, std::unique_ptr &outValue); /** @@ -258,7 +259,7 @@ public: * @param outValue the media data write to * @return SUCCESS if resource exist, else not found */ - RState GetMediaDataFromIndex(const HapResource::ValueUnderQualifierDir *qd, size_t &len, + RState GetMediaDataFromIndex(const std::shared_ptr qd, size_t &len, std::unique_ptr &outValue); /** @@ -267,7 +268,8 @@ public: * @param outValue the mediabase64 data write to * @return SUCCESS if resource exist, else not found */ - RState GetMediaBase64DataFromHap(const HapResource::ValueUnderQualifierDir *qd, std::string &outValue); + RState GetMediaBase64DataFromHap(const std::shared_ptr qd, + std::string &outValue); /** * Get the raw file list @@ -275,7 +277,8 @@ public: * @param outValue the mediabase64 data write to * @return SUCCESS if resource exist, else not found */ - RState GetMediaBase64DataFromIndex(const HapResource::ValueUnderQualifierDir *qd, std::string &outValue); + RState GetMediaBase64DataFromIndex(const std::shared_ptr qd, + std::string &outValue); /** * Get the raw file list @@ -297,14 +300,14 @@ public: * * @return HapResource vector of manager */ - std::vector GetHapResource(); + std::vector> GetHapResource(); /** * Add system resourc to app resource vector * * @param systemHapManager system manager */ - void AddSystemResource(const HapManager *systemHapManager); + void AddSystemResource(const std::shared_ptr &systemHapManager); /** * Get the resource limit keys value which every binary bit corresponds to existing limit key {@link KeyType} @@ -346,12 +349,13 @@ private: void GetResConfigImpl(ResConfigImpl &resConfig); - std::vector GetResourceList(uint32_t ident) const; + std::vector> GetResourceList(uint32_t ident) const; - std::vector GetResourceListByName(const char *name, const ResType resType) const; + std::vector> GetResourceListByName(const char *name, + const ResType resType) const; - const HapResource::ValueUnderQualifierDir *GetBestMatchResource(std::vector - candidates, uint32_t density); + const std::shared_ptr GetBestMatchResource( + std::vector> candidates, uint32_t density); bool AddResourcePath(const char *path); @@ -363,10 +367,10 @@ private: static bool icuInitialized; // app res config - ResConfigImpl *resConfig_; + std::shared_ptr resConfig_; // set of hap Resources - std::vector hapResources_; + std::vector> hapResources_; // set of loaded hap path std::unordered_map> loadedHapPaths_; diff --git a/frameworks/resmgr/include/hap_parser.h b/frameworks/resmgr/include/hap_parser.h index 642fd70..5aade1b 100644 --- a/frameworks/resmgr/include/hap_parser.h +++ b/frameworks/resmgr/include/hap_parser.h @@ -137,21 +137,22 @@ public: * @return OK if the resource hex parse success, else SYS_ERROR */ static int32_t ParseResHex(const char *buffer, const size_t bufLen, ResDesc &resDesc, - const ResConfigImpl *defaultConfig = nullptr); + const std::shared_ptr defaultConfig = nullptr); /** * Create resource config from KeyParams * @param keyParams the keyParams contain type and value * @return the resource config related to the keyParams */ - static ResConfigImpl *CreateResConfigFromKeyParams(const std::vector &keyParams); + static std::shared_ptr CreateResConfigFromKeyParams( + const std::vector> &keyParams); /** * To resource folder path * @param keyParams the keyParams contain type and value * @return the resources folder path */ - static std::string ToFolderPath(const std::vector &keyParams); + static std::string ToFolderPath(const std::vector> &keyParams); /** * Get screen density @@ -224,7 +225,7 @@ private: }; static std::string BuildFolderPath(Determiner *determiner); - static ResConfigImpl *BuildResConfig(ResConfigKey *configKey); + static std::shared_ptr BuildResConfig(ResConfigKey *configKey); }; } // namespace Resource } // namespace Global diff --git a/frameworks/resmgr/include/hap_resource.h b/frameworks/resmgr/include/hap_resource.h index fd3fd28..c7fa66f 100644 --- a/frameworks/resmgr/include/hap_resource.h +++ b/frameworks/resmgr/include/hap_resource.h @@ -44,8 +44,8 @@ public: * replace non-overlay resource. * @return pResource if create pResource success, else nullptr */ - static const HapResource *LoadFromIndex(const char *path, const ResConfigImpl *defaultConfig, - bool isSystem = false, bool isOverlay = false); + static const std::shared_ptr LoadFromIndex(const char *path, + const std::shared_ptr defaultConfig, bool isSystem = false, bool isOverlay = false); /** * Creates an HapResource. @@ -59,8 +59,8 @@ public: * replace non-overlay resource. * @return pResource if create pResource success, else nullptr */ - static const HapResource *LoadFromHap(const char *path, const ResConfigImpl *defaultConfig, - bool isSystem = false, bool isOverlay = false); + static const std::shared_ptr LoadFromHap(const char *path, + const std::shared_ptr defaultConfig, bool isSystem = false, bool isOverlay = false); /** * Creates an HapResource. @@ -74,8 +74,8 @@ public: * replace non-overlay resource. * @return pResource if create pResource success, else nullptr */ - static const HapResource *Load(const char* path, const ResConfigImpl* defaultConfig, - bool isSystem = false, bool isOverlay = false); + static const std::shared_ptr Load(const char* path, + const std::shared_ptr defaultConfig, bool isSystem = false, bool isOverlay = false); /** * Load overlay resources @@ -85,8 +85,9 @@ public: * @param isSystem judge the overlay is system or not * @return the map of overlay resource path and resource info if success, else null */ - static const std::unordered_map LoadOverlays(const std::string &path, - const std::vector &overlayPath, const ResConfigImpl *defaultConfig, bool isSystem = false); + static const std::unordered_map> LoadOverlays( + const std::string &path, const std::vector &overlayPath, + const std::shared_ptr defaultConfig, bool isSystem = false); /** * The destructor of HapResource @@ -139,7 +140,7 @@ public: */ class ValueUnderQualifierDir { public: - inline const std::vector GetKeyParams() const + inline const std::vector> GetKeyParams() const { return keyParams_; } @@ -149,12 +150,12 @@ public: return folder_; } - inline const IdItem *GetIdItem() const + inline const std::shared_ptr GetIdItem() const { return idItem_; } - inline const ResConfigImpl *GetResConfig() const + inline const std::shared_ptr GetResConfig() const { return resConfig_; } @@ -188,7 +189,7 @@ public: * @param isOverlay the overlay flag, default value is false. * @param isSystemResource the system flag, default value is false. */ - ValueUnderQualifierDir(const ResKey *resKey, IdItem *idItem, + ValueUnderQualifierDir(const std::shared_ptr resKey, std::shared_ptr idItem, const std::pair &resPath, bool isOverlay = false, bool isSystemResource = false); ~ValueUnderQualifierDir(); @@ -198,14 +199,14 @@ public: /* * keyParams_, folder_, resConfig_ are 3 different ways to describe Qualifiers Sub-directory */ - std::vector keyParams_; + std::vector> keyParams_; // the qualifier path name std::string folder_; // this resConfig_ point to the ResKey resConfig_ and resConfig_ will be unified free in ResKey destruct. - const ResConfigImpl *resConfig_; + std::shared_ptr resConfig_; // the value - IdItem *idItem_; + std::shared_ptr idItem_; friend class HapResource; @@ -223,12 +224,12 @@ public: */ class IdValues { public: - inline void AddLimitPath(ValueUnderQualifierDir *vuqd) + inline void AddLimitPath(std::shared_ptr vuqd) { limitPaths_.push_back(vuqd); } - inline const std::vector &GetLimitPathsConst() const + inline const std::vector> &GetLimitPathsConst() const { return limitPaths_; } @@ -237,7 +238,7 @@ public: private: // the folder desc - std::vector limitPaths_; + std::vector> limitPaths_; }; /** @@ -245,7 +246,7 @@ public: * @param id the resource id * @return the resource value related to id */ - const IdValues *GetIdValues(const uint32_t id) const; + const std::shared_ptr GetIdValues(const uint32_t id) const; /** * Get the resource value by resource name @@ -253,7 +254,7 @@ public: * @param resType the resource type * @return the resource value related to resource name */ - const IdValues *GetIdValuesByName(const std::string name, const ResType resType) const; + const std::shared_ptr GetIdValuesByName(const std::string name, const ResType resType) const; /** * Get the resource id by resource name @@ -287,16 +288,16 @@ public: */ void GetLocales(std::set &outValue, bool includeSystem); -private: - HapResource(const std::string path, time_t lastModTime, ResDesc *resDes, + HapResource(const std::string path, time_t lastModTime, std::shared_ptr resDes, bool isSystem = false, bool isOverlay = false); +private: void UpdateOverlayInfo(std::unordered_map> &nameTypeId); - uint32_t GetLimitPathsKeys(const std::vector &limitPaths, + uint32_t GetLimitPathsKeys(const std::vector> &limitPaths, std::vector &keyTypes) const; - void GetKeyParamsLocales(const std::vector keyParams, std::set &outValue); + void GetKeyParamsLocales(const std::vector> keyParams, std::set &outValue); // must call Init() after constructor bool Init(); @@ -314,13 +315,13 @@ private: time_t lastModTime_; // resource information stored in resDesc_ - ResDesc *resDesc_; + std::shared_ptr resDesc_; - std::map idValuesMap_; + std::map> idValuesMap_; // the key is name, each restype holds one map // name may conflict in same restype ! - std::vector *> idValuesNameMap_; + std::vector> *> idValuesNameMap_; // judge the hap resource is system or not. bool isSystem_; diff --git a/frameworks/resmgr/include/res_config_impl.h b/frameworks/resmgr/include/res_config_impl.h index 39ed235..c1e7871 100644 --- a/frameworks/resmgr/include/res_config_impl.h +++ b/frameworks/resmgr/include/res_config_impl.h @@ -37,7 +37,8 @@ public: * @param density the input screen density * @return true if this resConfig more match request resConfig than other resConfig, else false */ - bool IsMoreSuitable(const ResConfigImpl *other, const ResConfigImpl *request, uint32_t density = 0) const; + bool IsMoreSuitable(const std::shared_ptr other, const std::shared_ptr request, + uint32_t density = 0) const; /** * Set locale information @@ -116,7 +117,7 @@ public: * @param other the other resConfig * @return true if this resConfig match other resConfig, else false */ - bool Match(const ResConfigImpl *other) const; + bool Match(const std::shared_ptr other) const; /** * Copy other resConfig to this resConfig @@ -157,7 +158,7 @@ public: virtual ~ResConfigImpl(); private: - bool IsMoreSpecificThan(const ResConfigImpl *other, uint32_t density = 0) const; + bool IsMoreSpecificThan(const std::shared_ptr other, uint32_t density = 0) const; bool CopyLocale(ResConfig &other); diff --git a/frameworks/resmgr/include/res_desc.h b/frameworks/resmgr/include/res_desc.h index a8c06f1..4be5fd5 100644 --- a/frameworks/resmgr/include/res_desc.h +++ b/frameworks/resmgr/include/res_desc.h @@ -124,7 +124,7 @@ public: uint32_t id_; uint32_t offset_; - IdItem *idItem_; + std::shared_ptr idItem_; }; class ResId { @@ -137,7 +137,7 @@ public: char tag_[4]; uint32_t count_; // ID count - std::vector idParams_; + std::vector> idParams_; }; /** @@ -200,13 +200,13 @@ public: uint32_t keyParamsCount_; // the qualifiers - std::vector keyParams_; + std::vector> keyParams_; // the resource ID data - ResId *resId_; + std::shared_ptr resId_; // the resConfig of each ResKey and all resConfig_ in ValueUnderQualifierDir will point to this resConfig_ - ResConfigImpl *resConfig_; + std::shared_ptr resConfig_; }; /** * a ResDesc means a index file in hap zip @@ -221,7 +221,7 @@ public: ResHeader *resHeader_; - std::vector keys_; + std::vector> keys_; std::string GetCurrentDeviceType(); }; diff --git a/frameworks/resmgr/include/resource_manager_impl.h b/frameworks/resmgr/include/resource_manager_impl.h index 29d05bc..a071b16 100644 --- a/frameworks/resmgr/include/resource_manager_impl.h +++ b/frameworks/resmgr/include/resource_manager_impl.h @@ -625,62 +625,65 @@ public: virtual std::string GetThemeMask(); private: - RState GetString(const IdItem *idItem, std::string &outValue); + RState GetString(const std::shared_ptr idItem, std::string &outValue); - RState GetStringArray(const IdItem *idItem, std::vector &outValue); + RState GetStringArray(const std::shared_ptr idItem, std::vector &outValue); - RState GetPattern(const IdItem *idItem, std::map &outValue); + RState GetPattern(const std::shared_ptr idItem, std::map &outValue); - RState GetTheme(const IdItem *idItem, std::map &outValue); + RState GetTheme(const std::shared_ptr idItem, std::map &outValue); - RState GetPluralString(const HapResource::ValueUnderQualifierDir *vuqd, int quantity, std::string &outValue); + RState GetPluralString(const std::shared_ptr vuqd, int quantity, + std::string &outValue); RState ResolveReference(const std::string value, std::string &outValue); - RState GetBoolean(const IdItem *idItem, bool &outValue); + RState GetBoolean(const std::shared_ptr idItem, bool &outValue); RState ParseFloat(const std::string &strValue, float &result, std::string &unit); RState RecalculateFloat(const std::string &unit, float &result); - RState GetFloat(const IdItem *idItem, float &outValue, std::string &unit); + RState GetFloat(const std::shared_ptr idItem, float &outValue, std::string &unit); - RState GetInteger(const IdItem *idItem, int &outValue); + RState GetInteger(const std::shared_ptr idItem, int &outValue); - RState GetColor(const IdItem *idItem, uint32_t &outValue); + RState GetColor(const std::shared_ptr idItem, uint32_t &outValue); - RState GetIntArray(const IdItem *idItem, std::vector &outValue); + RState GetIntArray(const std::shared_ptr idItem, std::vector &outValue); - RState GetSymbol(const IdItem *idItem, uint32_t &outValue); + RState GetSymbol(const std::shared_ptr idItem, uint32_t &outValue); void ProcessPsuedoTranslate(std::string &outValue); - RState ResolveParentReference(const IdItem *idItem, std::map &outValue); + RState ResolveParentReference(const std::shared_ptr idItem, std::map &outValue); bool IsDensityValid(uint32_t density); bool IsFileExist(const std::string& path); - RState GetThemeColor(const IdItem *idItem, uint32_t &outValue); + RState GetThemeColor(const std::shared_ptr idItem, uint32_t &outValue); - RState GetThemeFloat(const IdItem *idItem, float &outValue); + RState GetThemeFloat(const std::shared_ptr idItem, float &outValue); - RState GetThemeMedia(const IdItem *idItem, size_t &len, std::unique_ptr &outValue, uint32_t density); + RState GetThemeMedia(const std::shared_ptr idItem, size_t &len, + std::unique_ptr &outValue, uint32_t density); - RState GetThemeMediaBase64(const IdItem *idItem, std::string &outValue); + RState GetThemeMediaBase64(const std::shared_ptr idItem, std::string &outValue); - RState GetThemeDrawable(const IdItem *idItem, size_t &len, std::unique_ptr &outValue, + RState GetThemeDrawable(const std::shared_ptr idItem, size_t &len, std::unique_ptr &outValue, uint32_t iconType, uint32_t density); - RState GetThemeIcon(const IdItem *idItem, size_t &len, std::unique_ptr &outValue, uint32_t density); + RState GetThemeIcon(const std::shared_ptr idItem, size_t &len, std::unique_ptr &outValue, + uint32_t density); - RState ProcessReference(const std::string value, std::vector &idItems); + RState ProcessReference(const std::string value, std::vector> &idItems); RState GetThemeIconInfo(const std::string &iconName, size_t &len, std::unique_ptr &outValue); RState GetThemeValues(const std::string &value, std::string &outValue); - HapManager *hapManager_; + std::shared_ptr hapManager_; float fontRatio_ = 0.0f; diff --git a/frameworks/resmgr/include/theme_pack_manager.h b/frameworks/resmgr/include/theme_pack_manager.h index 468fd74..f5946b5 100644 --- a/frameworks/resmgr/include/theme_pack_manager.h +++ b/frameworks/resmgr/include/theme_pack_manager.h @@ -83,7 +83,7 @@ public: * @return the best resource or empty */ const std::string FindThemeResource(const std::pair &bundleInfo, - std::vector idItems, const ResConfigImpl &resConfig); + std::vector> idItems, const ResConfigImpl &resConfig); /** * Find the best icon resource related to bundlename, modulename, resource name. diff --git a/frameworks/resmgr/src/hap_manager.cpp b/frameworks/resmgr/src/hap_manager.cpp index f0306a4..f9b7f4e 100644 --- a/frameworks/resmgr/src/hap_manager.cpp +++ b/frameworks/resmgr/src/hap_manager.cpp @@ -56,7 +56,7 @@ namespace Resource { constexpr uint32_t PLURAL_CACHE_MAX_COUNT = 3; #endif Lock g_rawFileLock; -HapManager::HapManager(ResConfigImpl *resConfig, bool isSystem) +HapManager::HapManager(std::shared_ptr resConfig, bool isSystem) : resConfig_(resConfig), isSystem_(isSystem) { } @@ -150,7 +150,7 @@ std::string HapManager::GetPluralRulesAndSelect(int quantity) #endif } -const IdItem *HapManager::FindResourceById(uint32_t id) +const std::shared_ptr HapManager::FindResourceById(uint32_t id) { auto qualifierValue = FindQualifierValueById(id); if (qualifierValue == nullptr) { @@ -159,7 +159,7 @@ const IdItem *HapManager::FindResourceById(uint32_t id) return qualifierValue->GetIdItem(); } -const IdItem *HapManager::FindResourceByName(const char *name, const ResType resType) +const std::shared_ptr HapManager::FindResourceByName(const char *name, const ResType resType) { auto qualifierValue = FindQualifierValueByName(name, resType); if (qualifierValue == nullptr) { @@ -168,44 +168,45 @@ const IdItem *HapManager::FindResourceByName(const char *name, const ResType res return qualifierValue->GetIdItem(); } -const HapResource::ValueUnderQualifierDir *HapManager::FindQualifierValueByName( +const std::shared_ptr HapManager::FindQualifierValueByName( const char *name, const ResType resType, uint32_t density) { AutoMutex mutex(this->lock_); - std::vector candidates = this->GetResourceListByName(name, resType); + std::vector> candidates = this->GetResourceListByName(name, resType); if (candidates.size() == 0) { return nullptr; } return this->GetBestMatchResource(candidates, density); } -const HapResource::ValueUnderQualifierDir *HapManager::FindQualifierValueById(uint32_t id, uint32_t density) +const std::shared_ptr HapManager::FindQualifierValueById(uint32_t id, + uint32_t density) { AutoMutex mutex(this->lock_); - std::vector candidates = this->GetResourceList(id); + std::vector> candidates = this->GetResourceList(id); if (candidates.size() == 0) { return nullptr; } return this->GetBestMatchResource(candidates, density); } -const HapResource::ValueUnderQualifierDir *HapManager::GetBestMatchResource(std::vector - candidates, uint32_t density) +const std::shared_ptr HapManager::GetBestMatchResource( + std::vector> candidates, uint32_t density) { - const ResConfigImpl *bestResConfig = nullptr; - const ResConfigImpl *bestOverlayResConfig = nullptr; - const HapResource::ValueUnderQualifierDir *result = nullptr; - const HapResource::ValueUnderQualifierDir *overlayResult = nullptr; - const ResConfigImpl *currentResConfig = this->resConfig_; + std::shared_ptr bestResConfig = nullptr; + std::shared_ptr bestOverlayResConfig = nullptr; + std::shared_ptr result = nullptr; + std::shared_ptr overlayResult = nullptr; + const std::shared_ptr currentResConfig = this->resConfig_; // When there are multiple overlays, reverse the search to find the first match resource. for (auto iter = candidates.rbegin(); iter != candidates.rend(); iter++) { - const std::vector paths = (*iter)->GetLimitPathsConst(); + const std::vector> paths = (*iter)->GetLimitPathsConst(); size_t len = paths.size(); size_t i = 0; bool isOverlayHapResource = paths[0]->IsOverlay(); for (i = 0; i < len; i++) { - HapResource::ValueUnderQualifierDir *path = paths[i]; - const ResConfigImpl *resConfig = path->GetResConfig(); + std::shared_ptr path = paths[i]; + const auto resConfig = path->GetResConfig(); if (!this->resConfig_->Match(resConfig)) { continue; } @@ -312,7 +313,7 @@ bool HapManager::AddResource(const std::string &path, const std::vector result = HapResource::LoadOverlays(path, overlayPaths, + std::unordered_map> result = HapResource::LoadOverlays(path, overlayPaths, resConfig_, isSystem_); if (result.size() > 0) { for (auto iter = result.begin(); iter != result.end(); iter++) { @@ -368,21 +369,7 @@ bool HapManager::RemoveAppOverlay(const std::string &overlayPath) HapManager::~HapManager() { - for (size_t i = 0; i < hapResources_.size(); ++i) { - if (hapResources_[i] == nullptr) { - continue; - } - // system resource is static, no need to release in each hap manager - if (hapResources_[i]->IsSystemResource()) { - continue; - } - delete hapResources_[i]; - hapResources_[i] = nullptr; - } - if (resConfig_ != nullptr) { - delete resConfig_; - resConfig_ = nullptr; - } + hapResources_.clear(); #ifdef SUPPORT_GRAPHICS auto iter = plurRulesCache_.begin(); @@ -397,13 +384,13 @@ HapManager::~HapManager() #endif } -std::vector HapManager::GetResourceList(uint32_t ident) const +std::vector> HapManager::GetResourceList(uint32_t ident) const { - std::vector result; + std::vector> result; // one id only exit in one hap for (size_t i = 0; i < hapResources_.size(); ++i) { - HapResource *pResource = hapResources_[i]; - const HapResource::IdValues *out = pResource->GetIdValues(ident); + std::shared_ptr pResource = hapResources_[i]; + const std::shared_ptrout = pResource->GetIdValues(ident); if (out != nullptr) { result.emplace_back(out); } @@ -411,14 +398,14 @@ std::vector HapManager::GetResourceList(uint32_t return result; } -std::vector HapManager::GetResourceListByName(const char *name, +std::vector> HapManager::GetResourceListByName(const char *name, const ResType resType) const { - std::vector result; + std::vector> result; // all match will return for (size_t i = 0; i < hapResources_.size(); ++i) { - HapResource *pResource = hapResources_[i]; - const HapResource::IdValues *out = pResource->GetIdValuesByName(std::string(name), resType); + std::shared_ptr pResource = hapResources_[i]; + const std::shared_ptr out = pResource->GetIdValuesByName(std::string(name), resType); if (out != nullptr) { result.emplace_back(out); } @@ -433,44 +420,34 @@ bool HapManager::AddResourcePath(const char *path) if (it != loadedHapPaths_.end()) { return false; } - const HapResource *pResource = HapResource::Load(path, resConfig_, isSystem_); + const std::shared_ptr pResource = HapResource::Load(path, resConfig_, isSystem_); if (pResource == nullptr) { return false; } - this->hapResources_.push_back(const_cast(pResource)); + this->hapResources_.push_back(pResource); this->loadedHapPaths_[sPath] = std::vector(); return true; } -void DeleteNewResource(std::vector &newResources) -{ - for (size_t i = 0; i < newResources.size(); ++i) { - if (newResources[i] != nullptr) { - delete (newResources[i]); - newResources[i] = nullptr; - } - } -} - RState HapManager::ReloadAll() { if (hapResources_.size() == 0) { return SUCCESS; } - std::vector newResources; + std::vector> newResources; for (auto iter = loadedHapPaths_.begin(); iter != loadedHapPaths_.end(); iter++) { std::vector &overlayPaths = iter->second; if (overlayPaths.size() == 0) { - const HapResource *pResource = HapResource::Load(iter->first.c_str(), resConfig_); + const auto pResource = HapResource::Load(iter->first.c_str(), resConfig_); if (pResource == nullptr) { - DeleteNewResource(newResources); + newResources.clear(); return HAP_INIT_FAILED; } - newResources.push_back(const_cast(pResource)); + newResources.push_back(pResource); continue; } - std::unordered_map result = HapResource::LoadOverlays(iter->first.c_str(), - overlayPaths, resConfig_); + std::unordered_map> result = HapResource::LoadOverlays( + iter->first.c_str(), overlayPaths, resConfig_); if (result.size() == 0) { continue; } @@ -478,9 +455,7 @@ RState HapManager::ReloadAll() newResources.push_back(iter->second); } } - for (size_t i = 0; i < hapResources_.size(); ++i) { - delete (hapResources_[i]); - } + hapResources_.clear(); hapResources_ = newResources; return SUCCESS; } @@ -514,10 +489,10 @@ std::string GetImageType(const std::string fileName) #if !defined(__WINNT__) && !defined(__IDE_PREVIEW__) && !defined(__ARKUI_CROSS__) std::string GetFilePathFromHap(std::shared_ptr &extractor, - const HapResource::ValueUnderQualifierDir *qd, const ResType resType) + const std::shared_ptr qd, const ResType resType) { std::string filePath; - const IdItem *idItem = qd->GetIdItem(); + const std::shared_ptr idItem = qd->GetIdItem(); if (idItem == nullptr || idItem->resType_ != resType) { std::string hapPath = qd->GetIndexPath(); HILOG_ERROR("actual resType = %{public}d, expect resType = %{public}d, hapPath = %{public}s", @@ -541,7 +516,8 @@ std::string GetFilePathFromHap(std::shared_ptr &extracto return filePath; } -std::shared_ptr GetAbilityExtractor(const HapResource::ValueUnderQualifierDir *qd) +std::shared_ptr GetAbilityExtractor( + const std::shared_ptr qd) { std::string hapPath = qd->GetIndexPath(); bool isNewExtractor = false; @@ -550,7 +526,7 @@ std::shared_ptr GetAbilityExtractor(const HapResource::V } #endif -RState HapManager::GetProfileData(const HapResource::ValueUnderQualifierDir *qd, size_t &len, +RState HapManager::GetProfileData(const std::shared_ptr qd, size_t &len, std::unique_ptr &outValue) { #if !defined(__WINNT__) && !defined(__IDE_PREVIEW__) && !defined(__ARKUI_CROSS__) @@ -573,7 +549,7 @@ RState HapManager::GetProfileData(const HapResource::ValueUnderQualifierDir *qd, return SUCCESS; } -RState HapManager::GetMediaData(const HapResource::ValueUnderQualifierDir *qd, size_t &len, +RState HapManager::GetMediaData(const std::shared_ptr qd, size_t &len, std::unique_ptr &outValue) { std::string filePath = qd->GetIndexPath(); @@ -586,7 +562,7 @@ RState HapManager::GetMediaData(const HapResource::ValueUnderQualifierDir *qd, s return state; } -RState HapManager::GetMediaDataFromHap(const HapResource::ValueUnderQualifierDir *qd, size_t &len, +RState HapManager::GetMediaDataFromHap(const std::shared_ptr qd, size_t &len, std::unique_ptr &outValue) { #if !defined(__WINNT__) && !defined(__IDE_PREVIEW__) && !defined(__ARKUI_CROSS__) @@ -610,7 +586,7 @@ RState HapManager::GetMediaDataFromHap(const HapResource::ValueUnderQualifierDir return SUCCESS; } -RState HapManager::GetMediaDataFromIndex(const HapResource::ValueUnderQualifierDir *qd, size_t &len, +RState HapManager::GetMediaDataFromIndex(const std::shared_ptr qd, size_t &len, std::unique_ptr &outValue) { std::string filePath; @@ -622,7 +598,8 @@ RState HapManager::GetMediaDataFromIndex(const HapResource::ValueUnderQualifierD return SUCCESS; } -RState HapManager::GetMediaBase64Data(const HapResource::ValueUnderQualifierDir *qd, std::string &outValue) +RState HapManager::GetMediaBase64Data(const std::shared_ptr qd, + std::string &outValue) { std::string filePath = qd->GetIndexPath(); RState state; @@ -634,7 +611,8 @@ RState HapManager::GetMediaBase64Data(const HapResource::ValueUnderQualifierDir return state; } -RState HapManager::GetMediaBase64DataFromHap(const HapResource::ValueUnderQualifierDir *qd, std::string &outValue) +RState HapManager::GetMediaBase64DataFromHap(const std::shared_ptr qd, + std::string &outValue) { #if !defined(__WINNT__) && !defined(__IDE_PREVIEW__) && !defined(__ARKUI_CROSS__) auto extractor = GetAbilityExtractor(qd); @@ -656,7 +634,8 @@ RState HapManager::GetMediaBase64DataFromHap(const HapResource::ValueUnderQualif return SUCCESS; } -RState HapManager::GetMediaBase64DataFromIndex(const HapResource::ValueUnderQualifierDir *qd, std::string &outValue) +RState HapManager::GetMediaBase64DataFromIndex(const std::shared_ptr qd, + std::string &outValue) { std::string filePath; RState state = HapManager::GetFilePath(qd, ResType::MEDIA, filePath); @@ -773,14 +752,14 @@ bool HapManager::IsLoadHap(std::string &hapPath) return HapManager::GetValidHapPath(hapPath) == OK ? true : false; } -RState HapManager::GetFilePath(const HapResource::ValueUnderQualifierDir *vuqd, const ResType resType, +RState HapManager::GetFilePath(const std::shared_ptr vuqd, const ResType resType, std::string &outValue) { // not found or type invalid if (vuqd == nullptr) { return NOT_FOUND; } - const IdItem *idItem = vuqd->GetIdItem(); + const std::shared_ptr idItem = vuqd->GetIdItem(); if (idItem == nullptr || idItem->resType_ != resType) { return NOT_FOUND; } @@ -899,12 +878,12 @@ bool HapManager::RemoveResource(const std::string &path, const std::vector HapManager::GetHapResource() +std::vector> HapManager::GetHapResource() { return hapResources_; } -void HapManager::AddSystemResource(const HapManager *systemHapManager) +void HapManager::AddSystemResource(const std::shared_ptr &systemHapManager) { if (systemHapManager == nullptr) { HILOG_ERROR("add system resource failed, systemHapManager is nullptr"); @@ -916,7 +895,7 @@ void HapManager::AddSystemResource(const HapManager *systemHapManager) } AutoMutex mutex(this->lock_); // add system resource to app resource vector - const std::vector &systemResources = systemHapManager->hapResources_; + const std::vector> &systemResources = systemHapManager->hapResources_; for (size_t i = 0; i < systemResources.size(); i++) { this->hapResources_.push_back(systemResources[i]); } diff --git a/frameworks/resmgr/src/hap_resource.cpp b/frameworks/resmgr/src/hap_resource.cpp index 531ce54..67a3141 100644 --- a/frameworks/resmgr/src/hap_resource.cpp +++ b/frameworks/resmgr/src/hap_resource.cpp @@ -42,8 +42,9 @@ namespace OHOS { namespace Global { namespace Resource { -HapResource::ValueUnderQualifierDir::ValueUnderQualifierDir(const ResKey *resKey, IdItem *idItem, - const std::pair &resPath, bool isOverlay, bool systemResource) +HapResource::ValueUnderQualifierDir::ValueUnderQualifierDir(const std::shared_ptr resKey, + std::shared_ptr idItem, const std::pair &resPath, bool isOverlay, + bool systemResource) { keyParams_ = resKey->keyParams_; folder_ = HapParser::ToFolderPath(keyParams_); @@ -61,34 +62,18 @@ HapResource::ValueUnderQualifierDir::~ValueUnderQualifierDir() // IdValues HapResource::IdValues::~IdValues() { - for (size_t i = 0; i < limitPaths_.size(); ++i) { - if (limitPaths_[i] != nullptr) { - delete limitPaths_[i]; - limitPaths_[i] = nullptr; - } - } + limitPaths_.clear(); } // HapResource -HapResource::HapResource(const std::string path, time_t lastModTime, ResDesc *resDes, bool isSystem, bool isOverlay) - : indexPath_(path), lastModTime_(lastModTime), resDesc_(resDes), isSystem_(isSystem), isOverlay_(isOverlay) +HapResource::HapResource(const std::string path, time_t lastModTime, std::shared_ptr resDes, + bool isSystem, bool isOverlay) : indexPath_(path), lastModTime_(lastModTime), resDesc_(resDes), + isSystem_(isSystem), isOverlay_(isOverlay) {} HapResource::~HapResource() { - if (resDesc_ != nullptr) { - delete (resDesc_); - resDesc_ = nullptr; - } - std::map::iterator iter; - for (iter = idValuesMap_.begin(); iter != idValuesMap_.end(); ++iter) { - if (iter->second != nullptr) { - IdValues *ptr = iter->second; - delete (ptr); - iter->second = nullptr; - } - } - + idValuesMap_.clear(); for (size_t i = 0; i < idValuesNameMap_.size(); ++i) { if (idValuesNameMap_[i] != nullptr) { delete (idValuesNameMap_[i]); @@ -98,8 +83,8 @@ HapResource::~HapResource() lastModTime_ = 0; } -const HapResource* HapResource::Load(const char *path, const ResConfigImpl* defaultConfig, - bool isSystem, bool isOverlay) +const std::shared_ptr HapResource::Load(const char *path, + const std::shared_ptr defaultConfig, bool isSystem, bool isOverlay) { if (Utils::ContainsTail(path, Utils::tailSet)) { return LoadFromHap(path, defaultConfig, isSystem, isOverlay); @@ -108,8 +93,8 @@ const HapResource* HapResource::Load(const char *path, const ResConfigImpl* defa } } -const HapResource* HapResource::LoadFromIndex(const char *path, const ResConfigImpl *defaultConfig, - bool isSystem, bool isOverlay) +const std::shared_ptr HapResource::LoadFromIndex(const char *path, + const std::shared_ptr defaultConfig, bool isSystem, bool isOverlay) { char outPath[PATH_MAX + 1] = {0}; Utils::CanonicalizePath(path, outPath, PATH_MAX); @@ -136,7 +121,7 @@ const HapResource* HapResource::LoadFromIndex(const char *path, const ResConfigI HILOG_DEBUG("extract success, bufLen:%d", bufLen); - ResDesc *resDesc = new (std::nothrow) ResDesc(); + std::shared_ptr resDesc = std::make_shared(); if (resDesc == nullptr) { HILOG_ERROR("new ResDesc failed when LoadFromIndex"); free(buf); @@ -144,21 +129,19 @@ const HapResource* HapResource::LoadFromIndex(const char *path, const ResConfigI } int32_t out = HapParser::ParseResHex(static_cast(buf), bufLen, *resDesc, defaultConfig); if (out != OK) { - delete (resDesc); free(buf); HILOG_ERROR("ParseResHex failed! retcode:%d", out); return nullptr; } free(buf); - HapResource *pResource = new (std::nothrow) HapResource(std::string(path), 0, resDesc, isSystem, isOverlay); + std::shared_ptr pResource = std::make_shared(std::string(path), + 0, resDesc, isSystem, isOverlay); if (pResource == nullptr) { HILOG_ERROR("new HapResource failed when LoadFromIndex"); - delete (resDesc); return nullptr; } if (!pResource->Init()) { - delete (pResource); return nullptr; } return pResource; @@ -199,8 +182,8 @@ bool GetIndexData(const char *path, std::unique_ptr &tmpBuf, size_t & return true; } -const HapResource* HapResource::LoadFromHap(const char *path, const ResConfigImpl *defaultConfig, - bool isSystem, bool isOverlay) +const std::shared_ptr HapResource::LoadFromHap(const char *path, + const std::shared_ptr defaultConfig, bool isSystem, bool isOverlay) { std::unique_ptr tmpBuf; size_t tmpLen = 0; @@ -209,7 +192,7 @@ const HapResource* HapResource::LoadFromHap(const char *path, const ResConfigImp HILOG_ERROR("read Index from file failed path, %{public}s", path); return nullptr; } - ResDesc *resDesc = new (std::nothrow) ResDesc(); + std::shared_ptr resDesc = std::make_shared(); if (resDesc == nullptr) { HILOG_ERROR("new ResDesc failed when LoadFromHap"); return nullptr; @@ -217,46 +200,43 @@ const HapResource* HapResource::LoadFromHap(const char *path, const ResConfigImp int32_t out = HapParser::ParseResHex(reinterpret_cast(tmpBuf.get()), tmpLen, *resDesc, defaultConfig); if (out != OK) { HILOG_ERROR("ParseResHex failed! retcode:%d", out); - delete (resDesc); return nullptr; } - HapResource *pResource = new (std::nothrow) HapResource(path, 0, resDesc, isSystem, isOverlay); + auto pResource = std::make_shared(path, 0, resDesc, isSystem, isOverlay); if (pResource == nullptr) { - delete (resDesc); return nullptr; } if (!pResource->Init()) { - delete (pResource); return nullptr; } return pResource; } -const std::unordered_map HapResource::LoadOverlays(const std::string &path, - const std::vector &overlayPaths, const ResConfigImpl *defaultConfig, bool isSystem) +const std::unordered_map> HapResource::LoadOverlays(const std::string &path, + const std::vector &overlayPaths, const std::shared_ptr defaultConfig, bool isSystem) { - std::unordered_map result; + std::unordered_map> result; do { - const HapResource *targetResource = Load(path.c_str(), defaultConfig, isSystem); + const std::shared_ptr targetResource = Load(path.c_str(), defaultConfig, isSystem); if (targetResource == nullptr) { HILOG_ERROR("load target failed"); break; } - result[path] = const_cast(targetResource); + result[path] = targetResource; bool success = true; std::unordered_map> mapping = targetResource->BuildNameTypeIdMapping(); for (auto iter = overlayPaths.begin(); iter != overlayPaths.end(); iter++) { // load overlay hap, the isOverlay flag set true. - const HapResource *overlayResource = Load(iter->c_str(), defaultConfig, isSystem, true); + const std::shared_ptr overlayResource = Load(iter->c_str(), defaultConfig, isSystem, true); if (overlayResource == nullptr) { HILOG_ERROR("load overlay failed"); success = false; break; } - result[*iter] = const_cast(overlayResource); + result[*iter] = overlayResource; } if (!success) { @@ -273,19 +253,17 @@ const std::unordered_map HapResource::LoadOverlays(c return result; } while (false); - for_each (result.begin(), result.end(), [](auto &iter) { - delete iter.second; - }); - return std::unordered_map(); + result.clear(); + return std::unordered_map>(); } std::unordered_map> HapResource::BuildNameTypeIdMapping() const { std::unordered_map> result; for (auto iter = idValuesMap_.begin(); iter != idValuesMap_.end(); iter++) { - const std::vector &limitPaths = iter->second->GetLimitPathsConst(); + const std::vector> &limitPaths = iter->second->GetLimitPathsConst(); if (limitPaths.size() > 0) { - ValueUnderQualifierDir* value = limitPaths[0]; + std::shared_ptr value = limitPaths[0]; result[value->idItem_->name_][value->idItem_->resType_] = value->idItem_->id_; } } @@ -294,11 +272,11 @@ std::unordered_map> HapResour void HapResource::UpdateOverlayInfo(std::unordered_map> &nameTypeId) { - std::map newIdValuesMap; + std::map> newIdValuesMap; for (auto iter = idValuesMap_.begin(); iter != idValuesMap_.end(); iter++) { - const std::vector &limitPaths = iter->second->GetLimitPathsConst(); + const std::vector> &limitPaths = iter->second->GetLimitPathsConst(); if (limitPaths.size() > 0) { - ValueUnderQualifierDir *value = limitPaths[0]; + std::shared_ptr value = limitPaths[0]; std::string name = value->idItem_->name_; ResType type = value->idItem_->resType_; if (nameTypeId.find(name) == nameTypeId.end()) { @@ -341,7 +319,7 @@ bool HapResource::Init() resourcePath_ = indexPath_.substr(0, index + 1); #endif for (int i = 0; i < ResType::MAX_RES_TYPE; ++i) { - auto mptr = new (std::nothrow) std::map(); + auto mptr = new (std::nothrow) std::map>(); if (mptr == nullptr) { HILOG_ERROR("new std::map failed in HapResource::Init"); return false; @@ -359,25 +337,24 @@ bool HapResource::InitIdList() } auto resPath = std::make_pair(indexPath_, resourcePath_); for (size_t i = 0; i < resDesc_->keys_.size(); i++) { - ResKey *resKey = resDesc_->keys_[i]; + std::shared_ptr resKey = resDesc_->keys_[i]; // init resConfig of each resKey. resKey->resConfig_ = HapParser::CreateResConfigFromKeyParams(resKey->keyParams_); for (size_t j = 0; j < resKey->resId_->idParams_.size(); ++j) { - IdParam *idParam = resKey->resId_->idParams_[j]; + std::shared_ptr idParam = resKey->resId_->idParams_[j]; uint32_t id = idParam->id_; - std::map::iterator iter = idValuesMap_.find(id); + std::map>::iterator iter = idValuesMap_.find(id); if (iter == idValuesMap_.end()) { - auto idValues = new (std::nothrow) HapResource::IdValues(); + auto idValues = std::make_shared(); if (idValues == nullptr) { HILOG_ERROR("new IdValues failed in HapResource::InitIdList"); return false; } - auto limitPath = new (std::nothrow) HapResource::ValueUnderQualifierDir(resKey, + auto limitPath = std::make_shared(resKey, idParam->idItem_, resPath, isOverlay_, isSystem_); if (limitPath == nullptr) { HILOG_ERROR("new ValueUnderQualifierDir failed in HapResource::InitIdList"); - delete (idValues); return false; } idValues->AddLimitPath(limitPath); @@ -385,8 +362,8 @@ bool HapResource::InitIdList() std::string name = std::string(idParam->idItem_->name_); idValuesNameMap_[idParam->idItem_->resType_]->insert(std::make_pair(name, idValues)); } else { - HapResource::IdValues *idValues = iter->second; - auto limitPath = new (std::nothrow) HapResource::ValueUnderQualifierDir(resKey, + std::shared_ptr idValues = iter->second; + auto limitPath = std::make_shared(resKey, idParam->idItem_, resPath, isOverlay_, isSystem_); if (limitPath == nullptr) { HILOG_ERROR("new ValueUnderQualifierDir failed in HapResource::InitIdList"); @@ -399,14 +376,14 @@ bool HapResource::InitIdList() return true; }; -const HapResource::IdValues *HapResource::GetIdValues(const uint32_t id) const +const std::shared_ptr HapResource::GetIdValues(const uint32_t id) const { if (idValuesMap_.empty()) { HILOG_ERROR("idValuesMap_ is empty"); return nullptr; } uint32_t uid = id; - std::map::const_iterator iter = idValuesMap_.find(uid); + std::map>::const_iterator iter = idValuesMap_.find(uid); if (iter == idValuesMap_.end()) { return nullptr; } @@ -414,11 +391,11 @@ const HapResource::IdValues *HapResource::GetIdValues(const uint32_t id) const return iter->second; } -const HapResource::IdValues *HapResource::GetIdValuesByName( +const std::shared_ptr HapResource::GetIdValuesByName( const std::string name, const ResType resType) const { - const std::map *map = idValuesNameMap_[resType]; - std::map::const_iterator iter = map->find(name); + const std::map> *map = idValuesNameMap_[resType]; + std::map>::const_iterator iter = map->find(name); if (iter == map->end()) { return nullptr; } @@ -431,12 +408,12 @@ int HapResource::GetIdByName(const char *name, const ResType resType) const if (name == nullptr) { return -1; } - const std::map *map = idValuesNameMap_[resType]; - std::map::const_iterator iter = map->find(name); + const std::map> *map = idValuesNameMap_[resType]; + std::map>::const_iterator iter = map->find(name); if (iter == map->end()) { return OBJ_NOT_FOUND; } - const IdValues *ids = iter->second; + const std::shared_ptr ids = iter->second; if (ids->GetLimitPathsConst().size() == 0) { HILOG_ERROR("limitPaths empty"); @@ -467,7 +444,7 @@ uint32_t HapResource::GetResourceLimitKeys() const if (iter->second == nullptr) { continue; } - const std::vector &limitPaths = iter->second->GetLimitPathsConst(); + const std::vector> &limitPaths = iter->second->GetLimitPathsConst(); if (limitPaths.size() <= 0) { continue; } @@ -476,13 +453,13 @@ uint32_t HapResource::GetResourceLimitKeys() const return limitKeyValue; } -uint32_t HapResource::GetLimitPathsKeys(const std::vector &limitPaths, +uint32_t HapResource::GetLimitPathsKeys(const std::vector> &limitPaths, std::vector &keyTypes) const { uint32_t limitKeyValue = 0; const uint32_t limitKeysBase = 0x00000001; for_each(limitPaths.begin(), limitPaths.end(), [&](auto &item) { - const std::vector &keyParams = item->keyParams_; + const std::vector> &keyParams = item->keyParams_; for_each(keyParams.begin(), keyParams.end(), [&](auto &keyParam) { uint32_t typeValue = static_cast(keyParam->type_); if (keyParam->type_ < KeyType::KEY_TYPE_MAX && !keyTypes[typeValue]) { @@ -504,7 +481,8 @@ void HapResource::GetLocales(std::set &outValue, bool includeSystem } } -void HapResource::GetKeyParamsLocales(const std::vector keyParams, std::set &outValue) +void HapResource::GetKeyParamsLocales(const std::vector> keyParams, + std::set &outValue) { std::string locale; bool isLocale = false; diff --git a/frameworks/resmgr/src/res_config_impl.cpp b/frameworks/resmgr/src/res_config_impl.cpp index faeb8e6..cfef25f 100644 --- a/frameworks/resmgr/src/res_config_impl.cpp +++ b/frameworks/resmgr/src/res_config_impl.cpp @@ -352,7 +352,7 @@ bool ResConfigImpl::Copy(ResConfig &other) return true; } -bool ResConfigImpl::Match(const ResConfigImpl *other) const +bool ResConfigImpl::Match(const std::shared_ptr other) const { if (other == nullptr) { return false; @@ -453,8 +453,8 @@ bool ResConfigImpl::IsInputDeviceMatch(InputDevice inputDevice) const * return false * */ -bool ResConfigImpl::IsMoreSuitable(const ResConfigImpl *other, - const ResConfigImpl *request, uint32_t density) const +bool ResConfigImpl::IsMoreSuitable(const std::shared_ptr other, + const std::shared_ptr request, uint32_t density) const { if (request != nullptr && other != nullptr) { int ret = IsMccMncMoreSuitable(other->mcc_, other->mnc_, request->mcc_, request->mnc_); @@ -632,7 +632,7 @@ bool ResConfigImpl::IsCompletedScript() const return isCompletedScript_; } -bool ResConfigImpl::IsMoreSpecificThan(const ResConfigImpl *other, uint32_t density) const +bool ResConfigImpl::IsMoreSpecificThan(const std::shared_ptr other, uint32_t density) const { if (other == nullptr) { return true; diff --git a/frameworks/resmgr/src/res_desc.cpp b/frameworks/resmgr/src/res_desc.cpp index 7f9c6ae..a4f57ac 100644 --- a/frameworks/resmgr/src/res_desc.cpp +++ b/frameworks/resmgr/src/res_desc.cpp @@ -277,12 +277,7 @@ std::string IdItem::ToString() const } IdParam::~IdParam() -{ - if (idItem_ != nullptr) { - delete (idItem_); - idItem_ = nullptr; - } -} +{} std::string IdParam::ToString() const { @@ -292,12 +287,7 @@ std::string IdParam::ToString() const ResId::~ResId() { - for (size_t i = 0; i < idParams_.size(); ++i) { - if (idParams_[i] != nullptr) { - delete idParams_[i]; - idParams_[i] = nullptr; - } - } + idParams_.clear(); } std::string ResId::ToString() const @@ -312,21 +302,7 @@ std::string ResId::ToString() const ResKey::~ResKey() { HILOG_DEBUG("~ResKey()"); - if (resConfig_ != nullptr) { - delete (resConfig_); - resConfig_ = nullptr; - } - - for (size_t i = 0; i < keyParams_.size(); ++i) { - if (keyParams_[i] != nullptr) { - delete keyParams_[i]; - keyParams_[i] = nullptr; - } - } - if (resId_ != nullptr) { - delete (resId_); - resId_ = nullptr; - } + keyParams_.clear(); } std::string ResKey::ToString() const @@ -350,13 +326,7 @@ ResDesc::~ResDesc() delete (resHeader_); resHeader_ = nullptr; } - - for (size_t i = 0; i < keys_.size(); ++i) { - if (keys_[i] != nullptr) { - delete keys_[i]; - keys_[i] = nullptr; - } - } + keys_.clear(); } std::string ResDesc::ToString() const diff --git a/frameworks/resmgr/src/resource_manager_impl.cpp b/frameworks/resmgr/src/resource_manager_impl.cpp index 4618a57..5b20d04 100644 --- a/frameworks/resmgr/src/resource_manager_impl.cpp +++ b/frameworks/resmgr/src/resource_manager_impl.cpp @@ -66,14 +66,13 @@ ResourceManagerImpl::ResourceManagerImpl() : hapManager_(nullptr) bool ResourceManagerImpl::Init(bool isSystem) { - ResConfigImpl *resConfig = new (std::nothrow) ResConfigImpl; + auto resConfig = std::make_shared(); if (resConfig == nullptr) { HILOG_ERROR("new ResConfigImpl failed when ResourceManagerImpl::Init"); return false; } - hapManager_ = new (std::nothrow) HapManager(resConfig, isSystem); + hapManager_ = std::make_shared(resConfig, isSystem); if (hapManager_ == nullptr) { - delete (resConfig); HILOG_ERROR("new HapManager failed when ResourceManagerImpl::Init"); return false; } @@ -82,7 +81,7 @@ bool ResourceManagerImpl::Init(bool isSystem) RState ResourceManagerImpl::GetStringById(uint32_t id, std::string &outValue) { - const IdItem *idItem = hapManager_->FindResourceById(id); + const std::shared_ptr idItem = hapManager_->FindResourceById(id); if (idItem == nullptr) { HILOG_ERROR("find resource by string id error id = %{public}d", id); return ERROR_CODE_RES_ID_NOT_FOUND; @@ -96,7 +95,7 @@ RState ResourceManagerImpl::GetStringById(uint32_t id, std::string &outValue) RState ResourceManagerImpl::GetStringByName(const char *name, std::string &outValue) { - const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::STRING); + const std::shared_ptr idItem = hapManager_->FindResourceByName(name, ResType::STRING); if (idItem == nullptr) { HILOG_ERROR("find resource by string name error name = %{public}s", name); return ERROR_CODE_RES_NAME_NOT_FOUND; @@ -110,7 +109,7 @@ RState ResourceManagerImpl::GetStringByName(const char *name, std::string &outVa RState ResourceManagerImpl::GetStringFormatById(std::string &outValue, uint32_t id, ...) { - const IdItem *idItem = hapManager_->FindResourceById(id); + const std::shared_ptr idItem = hapManager_->FindResourceById(id); std::string temp; RState rState = GetString(idItem, temp); if (rState != SUCCESS) { @@ -125,7 +124,7 @@ RState ResourceManagerImpl::GetStringFormatById(std::string &outValue, uint32_t RState ResourceManagerImpl::GetStringFormatByName(std::string &outValue, const char *name, ...) { - const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::STRING); + const std::shared_ptr idItem = hapManager_->FindResourceByName(name, ResType::STRING); std::string temp; RState rState = GetString(idItem, temp); if (rState != SUCCESS) { @@ -138,7 +137,7 @@ RState ResourceManagerImpl::GetStringFormatByName(std::string &outValue, const c return SUCCESS; } -RState ResourceManagerImpl::GetString(const IdItem *idItem, std::string &outValue) +RState ResourceManagerImpl::GetString(const std::shared_ptr idItem, std::string &outValue) { // not found or type invalid if (idItem == nullptr || idItem->resType_ != ResType::STRING) { @@ -159,7 +158,7 @@ RState ResourceManagerImpl::GetString(const IdItem *idItem, std::string &outValu RState ResourceManagerImpl::GetStringArrayById(uint32_t id, std::vector &outValue) { - const IdItem *idItem = hapManager_->FindResourceById(id); + const std::shared_ptr idItem = hapManager_->FindResourceById(id); if (idItem == nullptr) { HILOG_ERROR("find resource by string array id error id = %{public}d", id); return ERROR_CODE_RES_ID_NOT_FOUND; @@ -173,7 +172,7 @@ RState ResourceManagerImpl::GetStringArrayById(uint32_t id, std::vector &outValue) { - const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::STRINGARRAY); + const std::shared_ptr idItem = hapManager_->FindResourceByName(name, ResType::STRINGARRAY); if (idItem == nullptr) { HILOG_ERROR("find resource by string array name error name = %{public}s", name); return ERROR_CODE_RES_NAME_NOT_FOUND; @@ -185,7 +184,7 @@ RState ResourceManagerImpl::GetStringArrayByName(const char *name, std::vector &outValue) +RState ResourceManagerImpl::GetStringArray(const std::shared_ptr idItem, std::vector &outValue) { // not found or type invalid if (idItem == nullptr || idItem->resType_ != ResType::STRINGARRAY) { @@ -217,7 +216,7 @@ RState ResourceManagerImpl::GetStringArray(const IdItem *idItem, std::vector &outValue) { - const IdItem *idItem = hapManager_->FindResourceById(id); + const std::shared_ptr idItem = hapManager_->FindResourceById(id); if (idItem == nullptr) { HILOG_ERROR("find resource by pattern id error id = %{public}d", id); return ERROR_CODE_RES_ID_NOT_FOUND; @@ -231,7 +230,7 @@ RState ResourceManagerImpl::GetPatternById(uint32_t id, std::map &outValue) { - const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::PATTERN); + const std::shared_ptr idItem = hapManager_->FindResourceByName(name, ResType::PATTERN); if (idItem == nullptr) { HILOG_ERROR("find resource by Pattern name error name = %{public}s", name); return ERROR_CODE_RES_NAME_NOT_FOUND; @@ -243,7 +242,8 @@ RState ResourceManagerImpl::GetPatternByName(const char *name, std::map &outValue) +RState ResourceManagerImpl::GetPattern(const std::shared_ptr idItem, std::map &outValue) { //type invalid if (idItem->resType_ != ResType::PATTERN) { @@ -255,20 +255,20 @@ RState ResourceManagerImpl::GetPattern(const IdItem *idItem, std::mapFindQualifierValueById(id); + const std::shared_ptr vuqd = hapManager_->FindQualifierValueById(id); return GetPluralString(vuqd, quantity, outValue); } RState ResourceManagerImpl::GetPluralStringByName(const char *name, int quantity, std::string &outValue) { - const HapResource::ValueUnderQualifierDir *vuqd = + const std::shared_ptr vuqd = hapManager_->FindQualifierValueByName(name, ResType::PLURALS); return GetPluralString(vuqd, quantity, outValue); } RState ResourceManagerImpl::GetPluralStringByIdFormat(std::string &outValue, uint32_t id, int quantity, ...) { - const HapResource::ValueUnderQualifierDir *vuqd = hapManager_->FindQualifierValueById(id); + const std::shared_ptr vuqd = hapManager_->FindQualifierValueById(id); if (vuqd == nullptr) { HILOG_ERROR("find qualifier value by plural id error id = %{public}d", id); return ERROR_CODE_RES_ID_NOT_FOUND; @@ -292,7 +292,7 @@ RState ResourceManagerImpl::GetPluralStringByIdFormat(std::string &outValue, uin RState ResourceManagerImpl::GetPluralStringByNameFormat(std::string &outValue, const char *name, int quantity, ...) { - const HapResource::ValueUnderQualifierDir *vuqd = + const std::shared_ptr vuqd = hapManager_->FindQualifierValueByName(name, ResType::PLURALS); if (vuqd == nullptr) { HILOG_ERROR("find qualifier value by plural name error name = %{public}s", name); @@ -315,7 +315,7 @@ RState ResourceManagerImpl::GetPluralStringByNameFormat(std::string &outValue, c return SUCCESS; } -RState ResourceManagerImpl::GetPluralString(const HapResource::ValueUnderQualifierDir *vuqd, +RState ResourceManagerImpl::GetPluralString(const std::shared_ptr vuqd, int quantity, std::string &outValue) { // not found or type invalid @@ -383,7 +383,7 @@ RState ResourceManagerImpl::ResolveReference(const std::string value, std::strin HILOG_DEBUG("ref %{public}s can't be array", refStr.c_str()); return ERROR; } - const IdItem *idItem = hapManager_->FindResourceById(id); + const std::shared_ptr idItem = hapManager_->FindResourceById(id); if (idItem == nullptr) { HILOG_ERROR("ref %s id not found", refStr.c_str()); return ERROR; @@ -408,7 +408,7 @@ RState ResourceManagerImpl::GetThemeValues(const std::string &value, std::string { ResConfigImpl resConfig; GetResConfig(resConfig); - std::vector idItems; + std::vector> idItems; if (ProcessReference(value, idItems) != SUCCESS) { return NOT_FOUND; } @@ -416,7 +416,8 @@ RState ResourceManagerImpl::GetThemeValues(const std::string &value, std::string return outValue.empty() ? NOT_FOUND : SUCCESS; } -RState ResourceManagerImpl::ResolveParentReference(const IdItem *idItem, std::map &outValue) +RState ResourceManagerImpl::ResolveParentReference(const std::shared_ptr idItem, std::map &outValue) { // only pattern and theme // ref always at idx 0 @@ -425,7 +426,7 @@ RState ResourceManagerImpl::ResolveParentReference(const IdItem *idItem, std::ma bool haveParent = false; int count = 0; - const IdItem *currItem = idItem; + std::shared_ptr currItem = idItem; do { haveParent = currItem->HaveParent(); size_t startIdx = haveParent ? 1 : 0; @@ -479,7 +480,7 @@ RState ResourceManagerImpl::ResolveParentReference(const IdItem *idItem, std::ma RState ResourceManagerImpl::GetBooleanById(uint32_t id, bool &outValue) { - const IdItem *idItem = hapManager_->FindResourceById(id); + const std::shared_ptr idItem = hapManager_->FindResourceById(id); if (idItem == nullptr) { HILOG_ERROR("find resource by Boolean id error id = %{public}d", id); return ERROR_CODE_RES_ID_NOT_FOUND; @@ -493,7 +494,7 @@ RState ResourceManagerImpl::GetBooleanById(uint32_t id, bool &outValue) RState ResourceManagerImpl::GetBooleanByName(const char *name, bool &outValue) { - const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::BOOLEAN); + const std::shared_ptr idItem = hapManager_->FindResourceByName(name, ResType::BOOLEAN); if (idItem == nullptr) { HILOG_ERROR("find resource by Boolean name error name = %{public}s", name); return ERROR_CODE_RES_NAME_NOT_FOUND; @@ -505,7 +506,7 @@ RState ResourceManagerImpl::GetBooleanByName(const char *name, bool &outValue) return state; } -RState ResourceManagerImpl::GetBoolean(const IdItem *idItem, bool &outValue) +RState ResourceManagerImpl::GetBoolean(const std::shared_ptr idItem, bool &outValue) { if (idItem == nullptr || idItem->resType_ != ResType::BOOLEAN) { return NOT_FOUND; @@ -526,11 +527,11 @@ RState ResourceManagerImpl::GetBoolean(const IdItem *idItem, bool &outValue) return state; } -RState ResourceManagerImpl::GetThemeFloat(const IdItem *idItem, float &outValue) +RState ResourceManagerImpl::GetThemeFloat(const std::shared_ptr idItem, float &outValue) { ResConfigImpl resConfig; GetResConfig(resConfig); - std::vector idItems; + std::vector> idItems; idItems.emplace_back(idItem); ProcessReference(idItem->value_, idItems); std::string result = ThemePackManager::GetThemePackManager()->FindThemeResource(bundleInfo, idItems, resConfig); @@ -544,7 +545,7 @@ RState ResourceManagerImpl::GetThemeFloat(const IdItem *idItem, float &outValue) RState ResourceManagerImpl::GetFloatById(uint32_t id, float &outValue) { - const IdItem *idItem = hapManager_->FindResourceById(id); + const std::shared_ptr idItem = hapManager_->FindResourceById(id); if (idItem == nullptr) { HILOG_ERROR("find resource by Float id error id = %{public}d", id); return ERROR_CODE_RES_ID_NOT_FOUND; @@ -568,13 +569,13 @@ RState ResourceManagerImpl::GetFloatById(uint32_t id, float &outValue) RState ResourceManagerImpl::GetFloatById(uint32_t id, float &outValue, std::string &unit) { - const IdItem *idItem = hapManager_->FindResourceById(id); + const std::shared_ptr idItem = hapManager_->FindResourceById(id); return GetFloat(idItem, outValue, unit); } RState ResourceManagerImpl::GetFloatByName(const char *name, float &outValue) { - const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::FLOAT); + const std::shared_ptr idItem = hapManager_->FindResourceByName(name, ResType::FLOAT); if (idItem == nullptr) { HILOG_ERROR("find resource by Float name error name = %{public}s", name); return ERROR_CODE_RES_NAME_NOT_FOUND; @@ -598,7 +599,7 @@ RState ResourceManagerImpl::GetFloatByName(const char *name, float &outValue) RState ResourceManagerImpl::GetFloatByName(const char *name, float &outValue, std::string &unit) { - const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::FLOAT); + const std::shared_ptr idItem = hapManager_->FindResourceByName(name, ResType::FLOAT); return GetFloat(idItem, outValue, unit); } @@ -637,7 +638,7 @@ RState ResourceManagerImpl::ParseFloat(const std::string &strValue, float &resul return SUCCESS; } -RState ResourceManagerImpl::GetFloat(const IdItem *idItem, float &outValue, std::string &unit) +RState ResourceManagerImpl::GetFloat(const std::shared_ptr idItem, float &outValue, std::string &unit) { if (idItem == nullptr || idItem->resType_ != ResType::FLOAT) { return NOT_FOUND; @@ -652,7 +653,7 @@ RState ResourceManagerImpl::GetFloat(const IdItem *idItem, float &outValue, std: RState ResourceManagerImpl::GetIntegerById(uint32_t id, int &outValue) { - const IdItem *idItem = hapManager_->FindResourceById(id); + const std::shared_ptr idItem = hapManager_->FindResourceById(id); if (idItem == nullptr) { HILOG_ERROR("find resource by Integer id error id = %{public}d", id); return ERROR_CODE_RES_ID_NOT_FOUND; @@ -666,7 +667,7 @@ RState ResourceManagerImpl::GetIntegerById(uint32_t id, int &outValue) RState ResourceManagerImpl::GetIntegerByName(const char *name, int &outValue) { - const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::INTEGER); + const std::shared_ptr idItem = hapManager_->FindResourceByName(name, ResType::INTEGER); if (idItem == nullptr) { HILOG_ERROR("find resource by Integer name error name = %{public}s", name); return ERROR_CODE_RES_NAME_NOT_FOUND; @@ -678,7 +679,7 @@ RState ResourceManagerImpl::GetIntegerByName(const char *name, int &outValue) return state; } -RState ResourceManagerImpl::GetInteger(const IdItem *idItem, int &outValue) +RState ResourceManagerImpl::GetInteger(const std::shared_ptr idItem, int &outValue) { if (idItem == nullptr || idItem->resType_ != ResType::INTEGER) { return NOT_FOUND; @@ -692,7 +693,8 @@ RState ResourceManagerImpl::GetInteger(const IdItem *idItem, int &outValue) return state; } -RState ResourceManagerImpl::ProcessReference(const std::string value, std::vector &idItems) +RState ResourceManagerImpl::ProcessReference(const std::string value, + std::vector> &idItems) { int id; ResType resType; @@ -710,7 +712,7 @@ RState ResourceManagerImpl::ProcessReference(const std::string value, std::vecto HILOG_DEBUG("ref %{public}s can't be array", refStr.c_str()); return ERROR; } - const IdItem *idItem = hapManager_->FindResourceById(id); + const std::shared_ptr idItem = hapManager_->FindResourceById(id); idItems.emplace_back(idItem); if (idItem == nullptr) { HILOG_ERROR("ref %s id not found", refStr.c_str()); @@ -732,11 +734,11 @@ RState ResourceManagerImpl::ProcessReference(const std::string value, std::vecto return SUCCESS; } -RState ResourceManagerImpl::GetThemeColor(const IdItem *idItem, uint32_t &outValue) +RState ResourceManagerImpl::GetThemeColor(const std::shared_ptr idItem, uint32_t &outValue) { ResConfigImpl resConfig; GetResConfig(resConfig); - std::vector idItems; + std::vector > idItems; idItems.emplace_back(idItem); RState state = ProcessReference(idItem->value_, idItems); std::string result = ThemePackManager::GetThemePackManager()->FindThemeResource(bundleInfo, idItems, resConfig); @@ -748,7 +750,7 @@ RState ResourceManagerImpl::GetThemeColor(const IdItem *idItem, uint32_t &outVal RState ResourceManagerImpl::GetColorById(uint32_t id, uint32_t &outValue) { - const IdItem *idItem = hapManager_->FindResourceById(id); + const std::shared_ptr idItem = hapManager_->FindResourceById(id); if (idItem == nullptr) { HILOG_ERROR("find resource by string id error id = %{public}d", id); return ERROR_CODE_RES_ID_NOT_FOUND; @@ -768,7 +770,7 @@ RState ResourceManagerImpl::GetColorById(uint32_t id, uint32_t &outValue) RState ResourceManagerImpl::GetColorByName(const char *name, uint32_t &outValue) { - const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::COLOR); + const std::shared_ptr idItem = hapManager_->FindResourceByName(name, ResType::COLOR); if (idItem == nullptr) { HILOG_ERROR("find resource by string id error name = %{public}s", name); return ERROR_CODE_RES_NAME_NOT_FOUND; @@ -786,7 +788,7 @@ RState ResourceManagerImpl::GetColorByName(const char *name, uint32_t &outValue) return state; } -RState ResourceManagerImpl::GetColor(const IdItem *idItem, uint32_t &outValue) +RState ResourceManagerImpl::GetColor(const std::shared_ptr idItem, uint32_t &outValue) { if (idItem == nullptr || idItem->resType_ != ResType::COLOR) { return NOT_FOUND; @@ -801,7 +803,7 @@ RState ResourceManagerImpl::GetColor(const IdItem *idItem, uint32_t &outValue) RState ResourceManagerImpl::GetSymbolById(uint32_t id, uint32_t &outValue) { - const IdItem *idItem = hapManager_->FindResourceById(id); + const std::shared_ptr idItem = hapManager_->FindResourceById(id); if (idItem == nullptr) { HILOG_ERROR("find resource by symbol id error id = %{public}d", id); return ERROR_CODE_RES_ID_NOT_FOUND; @@ -815,7 +817,7 @@ RState ResourceManagerImpl::GetSymbolById(uint32_t id, uint32_t &outValue) RState ResourceManagerImpl::GetSymbolByName(const char *name, uint32_t &outValue) { - const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::SYMBOL); + const std::shared_ptr idItem = hapManager_->FindResourceByName(name, ResType::SYMBOL); if (idItem == nullptr) { HILOG_ERROR("find resource by symbol name error name = %{public}s", name); return ERROR_CODE_RES_NAME_NOT_FOUND; @@ -827,7 +829,7 @@ RState ResourceManagerImpl::GetSymbolByName(const char *name, uint32_t &outValue return state; } -RState ResourceManagerImpl::GetSymbol(const IdItem *idItem, uint32_t &outValue) +RState ResourceManagerImpl::GetSymbol(const std::shared_ptr idItem, uint32_t &outValue) { if (idItem == nullptr || idItem->resType_ != ResType::SYMBOL) { return NOT_FOUND; @@ -842,17 +844,17 @@ RState ResourceManagerImpl::GetSymbol(const IdItem *idItem, uint32_t &outValue) RState ResourceManagerImpl::GetIntArrayById(uint32_t id, std::vector &outValue) { - const IdItem *idItem = hapManager_->FindResourceById(id); + const std::shared_ptr idItem = hapManager_->FindResourceById(id); return GetIntArray(idItem, outValue); } RState ResourceManagerImpl::GetIntArrayByName(const char *name, std::vector &outValue) { - const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::INTARRAY); + const std::shared_ptr idItem = hapManager_->FindResourceByName(name, ResType::INTARRAY); return GetIntArray(idItem, outValue); } -RState ResourceManagerImpl::GetIntArray(const IdItem *idItem, std::vector &outValue) +RState ResourceManagerImpl::GetIntArray(const std::shared_ptr idItem, std::vector &outValue) { // not found or type invalid if (idItem == nullptr || idItem->resType_ != ResType::INTARRAY) { @@ -874,7 +876,7 @@ RState ResourceManagerImpl::GetIntArray(const IdItem *idItem, std::vector & RState ResourceManagerImpl::GetThemeById(uint32_t id, std::map &outValue) { - const IdItem *idItem = hapManager_->FindResourceById(id); + const std::shared_ptr idItem = hapManager_->FindResourceById(id); if (idItem == nullptr) { HILOG_ERROR("find resource by Theme id error id = %{public}d", id); return ERROR_CODE_RES_ID_NOT_FOUND; @@ -888,7 +890,7 @@ RState ResourceManagerImpl::GetThemeById(uint32_t id, std::map &outValue) { - const IdItem *idItem = hapManager_->FindResourceByName(name, ResType::THEME); + const std::shared_ptr idItem = hapManager_->FindResourceByName(name, ResType::THEME); if (idItem == nullptr) { HILOG_ERROR("find resource by Theme name error name = %{public}s", name); return ERROR_CODE_RES_NAME_NOT_FOUND; @@ -900,7 +902,7 @@ RState ResourceManagerImpl::GetThemeByName(const char *name, std::map &outValue) +RState ResourceManagerImpl::GetTheme(const std::shared_ptr idItem, std::map &outValue) { //type invalid if (idItem->resType_ != ResType::THEME) { @@ -991,10 +993,6 @@ void ResourceManagerImpl::ProcessPsuedoTranslate(std::string &outValue) ResourceManagerImpl::~ResourceManagerImpl() { - if (hapManager_ != nullptr) { - delete hapManager_; - hapManager_ = nullptr; - } if (psueManager_ != nullptr) { delete (psueManager_); psueManager_ = nullptr; @@ -1091,12 +1089,12 @@ bool ResourceManagerImpl::IsDensityValid(uint32_t density) } } -RState ResourceManagerImpl::GetThemeMedia(const IdItem *idItem, size_t &len, +RState ResourceManagerImpl::GetThemeMedia(const std::shared_ptr idItem, size_t &len, std::unique_ptr &outValue, uint32_t density) { ResConfigImpl resConfig; GetResConfig(resConfig); - std::vector idItems; + std::vector> idItems; idItems.emplace_back(idItem); std::string result = ThemePackManager::GetThemePackManager()->FindThemeResource(bundleInfo, idItems, resConfig); outValue = Utils::LoadResourceFile(result, len); @@ -1117,7 +1115,7 @@ RState ResourceManagerImpl::GetMediaDataById(uint32_t id, size_t &len, std::uniq } // find in theme - const IdItem *idItem = qd->GetIdItem(); + const std::shared_ptr idItem = qd->GetIdItem(); if (GetThemeMedia(idItem, len, outValue, density) == SUCCESS) { return SUCCESS; } @@ -1140,7 +1138,7 @@ RState ResourceManagerImpl::GetMediaDataByName(const char *name, size_t &len, st return ERROR_CODE_RES_NAME_NOT_FOUND; } - const IdItem *idItem = qd->GetIdItem(); + const std::shared_ptr idItem = qd->GetIdItem(); if (GetThemeMedia(idItem, len, outValue, density) == SUCCESS) { return SUCCESS; } @@ -1149,13 +1147,16 @@ RState ResourceManagerImpl::GetMediaDataByName(const char *name, size_t &len, st return state == SUCCESS ? state : ERROR_CODE_RES_NOT_FOUND_BY_NAME; } -RState ResourceManagerImpl::GetThemeMediaBase64(const IdItem *idItem, std::string &outValue) +RState ResourceManagerImpl::GetThemeMediaBase64(const std::shared_ptr idItem, std::string &outValue) { ResConfigImpl resConfig; GetResConfig(resConfig); - std::vector idItems; + std::vector> idItems; idItems.emplace_back(idItem); std::string result = ThemePackManager::GetThemePackManager()->FindThemeResource(bundleInfo, idItems, resConfig); + if (result.empty()) { + return NOT_FOUND; + } return Utils::GetMediaBase64Data(result, outValue); } @@ -1172,7 +1173,7 @@ RState ResourceManagerImpl::GetMediaBase64DataById(uint32_t id, std::string &out return ERROR_CODE_RES_ID_NOT_FOUND; } - const IdItem *idItem = qd->GetIdItem(); + const std::shared_ptr idItem = qd->GetIdItem(); if (GetThemeMediaBase64(idItem, outValue) == SUCCESS) { return SUCCESS; } @@ -1193,7 +1194,7 @@ RState ResourceManagerImpl::GetMediaBase64DataByName(const char *name, std::stri return ERROR_CODE_RES_NAME_NOT_FOUND; } - const IdItem *idItem = qd->GetIdItem(); + const std::shared_ptr idItem = qd->GetIdItem(); if (GetThemeMediaBase64(idItem, outValue) == SUCCESS) { return SUCCESS; } @@ -1256,9 +1257,9 @@ RState ResourceManagerImpl::GetRawFileList(const std::string &rawDirPath, std::v return hapManager_->GetRawFileList(rawDirPath, rawfileList); } -std::string GetSuffix(const HapResource::ValueUnderQualifierDir *qd) +std::string GetSuffix(const std::shared_ptr qd) { - const IdItem *idItem = qd->GetIdItem(); + const std::shared_ptr idItem = qd->GetIdItem(); if (idItem == nullptr || idItem->resType_ != ResType::MEDIA) { return std::string(); } @@ -1270,7 +1271,7 @@ std::string GetSuffix(const HapResource::ValueUnderQualifierDir *qd) return mediaPath.substr(pos + 1); } -RState ResourceManagerImpl::GetThemeIcon(const IdItem *idItem, size_t &len, +RState ResourceManagerImpl::GetThemeIcon(const std::shared_ptr idItem, size_t &len, std::unique_ptr &outValue, uint32_t density) { std::string iconName = idItem->GetItemResName(); @@ -1284,7 +1285,7 @@ RState ResourceManagerImpl::GetThemeIcon(const IdItem *idItem, size_t &len, return SUCCESS; } -RState ResourceManagerImpl::GetThemeDrawable(const IdItem *idItem, size_t &len, +RState ResourceManagerImpl::GetThemeDrawable(const std::shared_ptr idItem, size_t &len, std::unique_ptr &outValue, uint32_t iconType, uint32_t density) { if (iconType == 0 && GetThemeMedia(idItem, len, outValue, density) == SUCCESS) { @@ -1357,7 +1358,7 @@ RState ResourceManagerImpl::GetDrawableInfoById(uint32_t id, } size_t len = 0; // find in theme - const IdItem *idItem = qd->GetIdItem(); + const std::shared_ptr idItem = qd->GetIdItem(); std::string themeMask = ThemePackManager::GetThemePackManager()->GetMask(); if (GetThemeDrawable(idItem, len, outValue, iconType, density) == SUCCESS) { drawableInfo = std::make_tuple(type, len, themeMask); @@ -1390,7 +1391,7 @@ RState ResourceManagerImpl::GetDrawableInfoByName(const char *name, size_t len = 0; // find in theme std::string themeMask = ThemePackManager::GetThemePackManager()->GetMask(); - const IdItem *idItem = qd->GetIdItem(); + const std::shared_ptr idItem = qd->GetIdItem(); if (GetThemeDrawable(idItem, len, outValue, iconType, density) == SUCCESS) { drawableInfo = std::make_tuple(type, len, themeMask); return SUCCESS; diff --git a/frameworks/resmgr/src/theme_pack_manager.cpp b/frameworks/resmgr/src/theme_pack_manager.cpp index c590951a..68a22e0 100644 --- a/frameworks/resmgr/src/theme_pack_manager.cpp +++ b/frameworks/resmgr/src/theme_pack_manager.cpp @@ -148,7 +148,7 @@ void ThemePackManager::LoadThemeRes(const std::string &bundleName, const std::st } const std::string ThemePackManager::FindThemeResource(const std::pair &bundleInfo, - std::vector idItems, const ResConfigImpl &resConfig) + std::vector> idItems, const ResConfigImpl &resConfig) { std::string result; for (size_t i = 0; i < idItems.size(); i++) { diff --git a/frameworks/resmgr/src/utils/hap_parser.cpp b/frameworks/resmgr/src/utils/hap_parser.cpp index aceb8e3..d73daf3 100644 --- a/frameworks/resmgr/src/utils/hap_parser.cpp +++ b/frameworks/resmgr/src/utils/hap_parser.cpp @@ -418,9 +418,9 @@ int32_t ParseStringArray(const char *buffer, uint32_t &offset, std::vector idItem) { - errno_t eret = memcpy_s(idItem, sizeof(IdItem), buffer + offset, IdItem::HEADER_LEN); + errno_t eret = memcpy_s(idItem.get(), sizeof(IdItem), buffer + offset, IdItem::HEADER_LEN); if (eret != OK) { return SYS_ERROR; } @@ -450,9 +450,9 @@ int32_t ParseIdItem(const char *buffer, uint32_t &offset, IdItem *idItem) return OK; } -int32_t ParseId(const char *buffer, uint32_t &offset, ResId *id) +int32_t ParseId(const char *buffer, uint32_t &offset, std::shared_ptr id) { - errno_t eret = memcpy_s(id, sizeof(ResId), buffer + offset, ResId::RESID_HEADER_LEN); + errno_t eret = memcpy_s(id.get(), sizeof(ResId), buffer + offset, ResId::RESID_HEADER_LEN); if (eret != OK) { return SYS_ERROR; } @@ -462,28 +462,24 @@ int32_t ParseId(const char *buffer, uint32_t &offset, ResId *id) return -1; } for (uint32_t i = 0; i < id->count_; ++i) { - IdParam *ip = new (std::nothrow) IdParam(); + std::shared_ptr ip = std::make_shared(); if (ip == nullptr) { HILOG_ERROR("new IdParam failed when ParseId"); return SYS_ERROR; } - errno_t eret = memcpy_s(ip, sizeof(IdParam), buffer + offset, ResId::IDPARAM_HEADER_LEN); + errno_t eret = memcpy_s(ip.get(), sizeof(IdParam), buffer + offset, ResId::IDPARAM_HEADER_LEN); if (eret != OK) { - delete (ip); return SYS_ERROR; } offset += ResId::IDPARAM_HEADER_LEN; - IdItem *idItem = new (std::nothrow) IdItem(); + std::shared_ptr idItem = std::make_shared(); if (idItem == nullptr) { HILOG_ERROR("new IdItem failed when ParseId"); - delete (ip); return SYS_ERROR; } uint32_t ipOffset = ip->offset_; int32_t ret = ParseIdItem(buffer, ipOffset, idItem); if (ret != OK) { - delete (ip); - delete (idItem); return ret; } ip->idItem_ = idItem; @@ -493,28 +489,27 @@ int32_t ParseId(const char *buffer, uint32_t &offset, ResId *id) return OK; } -bool IsLocaleMatch(const ResConfigImpl *defaultConfig, const std::vector &keyParams) +bool IsLocaleMatch(const std::shared_ptr defaultConfig, + const std::vector> &keyParams) { if (defaultConfig == nullptr) { return true; } - ResConfigImpl *config = HapParser::CreateResConfigFromKeyParams(keyParams); + auto config = HapParser::CreateResConfigFromKeyParams(keyParams); if (config == nullptr) { return false; } if (LocaleMatcher::Match(defaultConfig->GetResLocale(), config->GetResLocale())) { - delete (config); return true; } HILOG_DEBUG("mismatch, do not parse %s", HapParser::ToFolderPath(keyParams).c_str()); - delete (config); return false; } -int32_t ParseKey(const char *buffer, uint32_t &offset, ResKey *key, - bool &match, const ResConfigImpl *defaultConfig, const std::string &deviceType) +int32_t ParseKey(const char *buffer, uint32_t &offset, std::shared_ptr key, + bool &match, const std::shared_ptr defaultConfig, const std::string &deviceType) { - errno_t eret = memcpy_s(key, sizeof(ResKey), buffer + offset, ResKey::RESKEY_HEADER_LEN); + errno_t eret = memcpy_s(key.get(), sizeof(ResKey), buffer + offset, ResKey::RESKEY_HEADER_LEN); if (eret != OK) { return SYS_ERROR; } @@ -524,14 +519,13 @@ int32_t ParseKey(const char *buffer, uint32_t &offset, ResKey *key, return -1; } for (uint32_t i = 0; i < key->keyParamsCount_; ++i) { - KeyParam *kp = new (std::nothrow) KeyParam(); + std::shared_ptr kp = std::make_shared(); if (kp == nullptr) { HILOG_ERROR("new KeyParam failed when ParseKey"); return SYS_ERROR; } - errno_t eret = memcpy_s(kp, sizeof(KeyParam), buffer + offset, ResKey::KEYPARAM_HEADER_LEN); + errno_t eret = memcpy_s(kp.get(), sizeof(KeyParam), buffer + offset, ResKey::KEYPARAM_HEADER_LEN); if (eret != OK) { - delete (kp); return SYS_ERROR; } offset += ResKey::KEYPARAM_HEADER_LEN; @@ -545,14 +539,13 @@ int32_t ParseKey(const char *buffer, uint32_t &offset, ResKey *key, key->keyParams_.push_back(kp); } uint32_t idOffset = key->offset_; - ResId *id = new (std::nothrow) ResId(); + std::shared_ptr id = std::make_shared(); if (id == nullptr) { HILOG_ERROR("new ResId failed when ParseKey"); return SYS_ERROR; } int32_t ret = ParseId(buffer, idOffset, id); if (ret != OK) { - delete (id); return ret; } key->resId_ = id; @@ -561,7 +554,7 @@ int32_t ParseKey(const char *buffer, uint32_t &offset, ResKey *key, int32_t HapParser::ParseResHex(const char *buffer, const size_t bufLen, ResDesc &resDesc, - const ResConfigImpl *defaultConfig) + const std::shared_ptr defaultConfig) { ResHeader *resHeader = new (std::nothrow) ResHeader(); if (resHeader == nullptr) { @@ -583,7 +576,7 @@ int32_t HapParser::ParseResHex(const char *buffer, const size_t bufLen, ResDesc resDesc.resHeader_ = resHeader; const std::string deviceType = resDesc.GetCurrentDeviceType(); for (uint32_t i = 0; i < resHeader->keyCount_; i++) { - ResKey *key = new (std::nothrow) ResKey(); + std::shared_ptr key = std::make_shared(); if (key == nullptr) { HILOG_ERROR("new ResKey failed when ParseResHex"); return SYS_ERROR; @@ -591,21 +584,19 @@ int32_t HapParser::ParseResHex(const char *buffer, const size_t bufLen, ResDesc bool match = true; int32_t ret = ParseKey(buffer, offset, key, match, defaultConfig, deviceType); if (ret != OK) { - delete (key); return ret; } if (match) { resDesc.keys_.push_back(key); - } else { - delete (key); } } return OK; } -ResConfigImpl *HapParser::CreateResConfigFromKeyParams(const std::vector &keyParams) +std::shared_ptr HapParser::CreateResConfigFromKeyParams( + const std::vector> &keyParams) { - ResConfigImpl *resConfig = new (std::nothrow) ResConfigImpl; + auto resConfig = std::make_shared(); if (resConfig == nullptr) { HILOG_ERROR("new ResConfigImpl failed when CreateResConfigFromKeyParams"); return nullptr; @@ -616,11 +607,10 @@ ResConfigImpl *HapParser::CreateResConfigFromKeyParams(const std::vectorSetColorMode(COLOR_MODE_NOT_SET); return resConfig; } - delete resConfig; size_t i = 0; ResConfigKey configKey; for (i = 0; i < len; ++i) { - const KeyParam *kp = keyParams.at(i); + const std::shared_ptr kp = keyParams.at(i); if (kp->type_ == LANGUAGES) { configKey.language = kp->GetStr().c_str(); } else if (kp->type_ == REGION) { @@ -651,13 +641,13 @@ ResConfigImpl *HapParser::CreateResConfigFromKeyParams(const std::vector HapParser::BuildResConfig(ResConfigKey *configKey) { if (configKey == nullptr) { HILOG_ERROR("configKey is null"); return nullptr; } - ResConfigImpl *resConfig = new (std::nothrow) ResConfigImpl; + auto resConfig = std::make_shared(); if (resConfig == nullptr) { HILOG_ERROR("new ResConfigImpl failed when BuildResConfig"); return nullptr; @@ -758,7 +748,7 @@ void PathAppend(std::string &path, const std::string &append, const std::string } } -std::string HapParser::ToFolderPath(const std::vector &keyParams) +std::string HapParser::ToFolderPath(const std::vector> &keyParams) { if (keyParams.size() == 0) { return std::string("default"); @@ -766,7 +756,7 @@ std::string HapParser::ToFolderPath(const std::vector &keyParams) // mcc-mnc-language_script_region-direction-deviceType-colorMode-inputDevice-screenDensity Determiner determiner; for (size_t i = 0; i < keyParams.size(); ++i) { - KeyParam *keyParam = keyParams[i]; + std::shared_ptr keyParam = keyParams[i]; switch (keyParam->type_) { case KeyType::LANGUAGES: determiner.language = keyParam->GetStr(); diff --git a/frameworks/resmgr/test/unittest/common/hap_manager_test.cpp b/frameworks/resmgr/test/unittest/common/hap_manager_test.cpp index 8ffcb0d..0e073a2 100644 --- a/frameworks/resmgr/test/unittest/common/hap_manager_test.cpp +++ b/frameworks/resmgr/test/unittest/common/hap_manager_test.cpp @@ -70,13 +70,13 @@ void HapManagerTest::TearDown() */ HWTEST_F(HapManagerTest, HapManagerFuncTest001, TestSize.Level1) { - HapManager *hapManager = new HapManager(new ResConfigImpl); + HapManager *hapManager = new HapManager(std::make_shared()); bool ret = hapManager->AddResourcePath(FormatFullPath(g_resFilePath).c_str()); EXPECT_TRUE(ret); int id = 16777217; - std::vector idValues = hapManager->GetResourceList(id); + auto idValues = hapManager->GetResourceList(id); if (idValues.size() == 0) { delete hapManager; EXPECT_TRUE(false); @@ -95,7 +95,7 @@ HWTEST_F(HapManagerTest, HapManagerFuncTest001, TestSize.Level1) */ HWTEST_F(HapManagerTest, HapManagerFuncTest002, TestSize.Level1) { - ResConfig *rc = CreateResConfig(); + auto rc = CreateResConfig(); if (rc == nullptr) { EXPECT_TRUE(false); return; @@ -103,7 +103,7 @@ HWTEST_F(HapManagerTest, HapManagerFuncTest002, TestSize.Level1) rc->SetLocaleInfo("en", nullptr, "US"); std::string resPath = FormatFullPath(g_resFilePath); const char *path = resPath.c_str(); - HapManager *hapManager = new HapManager(new ResConfigImpl); + HapManager *hapManager = new HapManager(std::make_shared()); if (hapManager == nullptr) { delete (rc); EXPECT_TRUE(false); @@ -115,7 +115,7 @@ HWTEST_F(HapManagerTest, HapManagerFuncTest002, TestSize.Level1) EXPECT_TRUE(ret); uint32_t id = 16777237; // 16777237 means string_ref - std::vector idValues = hapManager->GetResourceList(id); + auto idValues = hapManager->GetResourceList(id); if (idValues.size() == 0) { delete (hapManager); delete (rc); @@ -128,7 +128,7 @@ HWTEST_F(HapManagerTest, HapManagerFuncTest002, TestSize.Level1) // reload - ResConfig *rc2 = CreateResConfig(); + auto rc2 = CreateResConfig(); if (rc2 == nullptr) { delete (hapManager); delete (rc); @@ -162,13 +162,13 @@ HWTEST_F(HapManagerTest, HapManagerFuncTest002, TestSize.Level1) */ HWTEST_F(HapManagerTest, HapManagerFuncTest003, TestSize.Level1) { - ResConfig *rc = CreateResConfig(); + auto rc = CreateResConfig(); if (rc == nullptr) { EXPECT_TRUE(false); return; } rc->SetLocaleInfo("zh", nullptr, "CN"); - HapManager *hapManager = new HapManager(new ResConfigImpl); + HapManager *hapManager = new HapManager(std::make_shared()); hapManager->UpdateResConfig(*rc); if (hapManager == nullptr) { EXPECT_TRUE(false); @@ -179,7 +179,7 @@ HWTEST_F(HapManagerTest, HapManagerFuncTest003, TestSize.Level1) EXPECT_TRUE(ret); int id = 16777221; // 16777221 means 'aboutPage_title_primary' - std::vector idValues = hapManager->GetResourceList(id); + auto idValues = hapManager->GetResourceList(id); if (idValues.size() == 0) { delete hapManager; EXPECT_TRUE(false); @@ -204,13 +204,13 @@ HWTEST_F(HapManagerTest, HapManagerFuncTest003, TestSize.Level1) */ HWTEST_F(HapManagerTest, HapManagerFuncTest004, TestSize.Level1) { - ResConfig *rc = CreateResConfig(); + auto rc = CreateResConfig(); if (rc == nullptr) { EXPECT_TRUE(false); return; } rc->SetLocaleInfo("en", nullptr, "US"); - HapManager *hapManager = new HapManager(new ResConfigImpl); + HapManager *hapManager = new HapManager(std::make_shared()); hapManager->UpdateResConfig(*rc); if (hapManager == nullptr) { EXPECT_TRUE(false); @@ -219,7 +219,7 @@ HWTEST_F(HapManagerTest, HapManagerFuncTest004, TestSize.Level1) bool ret = hapManager->AddResourcePath(FormatFullPath(g_hapPath).c_str()); EXPECT_TRUE(ret); int id = 16777221; // 16777221 means 'AboutPageFA' 'aboutPage_title_primary' - std::vector idValues = hapManager->GetResourceList(id); + auto idValues = hapManager->GetResourceList(id); if (idValues.size() == 0) { delete hapManager; EXPECT_TRUE(false); diff --git a/frameworks/resmgr/test/unittest/common/hap_parser_test.cpp b/frameworks/resmgr/test/unittest/common/hap_parser_test.cpp index 9ebf6e2..b396fd8 100644 --- a/frameworks/resmgr/test/unittest/common/hap_parser_test.cpp +++ b/frameworks/resmgr/test/unittest/common/hap_parser_test.cpp @@ -67,37 +67,37 @@ void HapParserTest::TearDown() */ HWTEST_F(HapParserTest, HapParserFuncTest001, TestSize.Level1) { - std::vector keyParams; - auto kp = new KeyParam(); + std::vector> keyParams; + auto kp = std::make_shared(); kp->type_ = LANGUAGES; kp->value_ = 31336; kp->InitStr(); keyParams.push_back(kp); - kp = new KeyParam(); - kp->type_ = REGION; - kp->value_ = 17230; + auto kp1 = std::make_shared(); + kp1->type_ = REGION; + kp1->value_ = 17230; + kp1->InitStr(); + keyParams.push_back(kp1); + auto kp2 = std::make_shared(); + kp2->type_ = SCREEN_DENSITY; + kp2->value_ = SCREEN_DENSITY_SDPI; kp->InitStr(); - keyParams.push_back(kp); - kp = new KeyParam(); - kp->type_ = SCREEN_DENSITY; - kp->value_ = SCREEN_DENSITY_SDPI; - kp->InitStr(); - keyParams.push_back(kp); - kp = new KeyParam(); - kp->type_ = DEVICETYPE; - kp->value_ = DEVICE_CAR; - kp->InitStr(); - keyParams.push_back(kp); - kp = new KeyParam(); - kp->type_ = DIRECTION; - kp->value_ = DIRECTION_VERTICAL; - kp->InitStr(); - keyParams.push_back(kp); - kp = new KeyParam(); - kp->type_ = COLORMODE; - kp->value_ = DARK; - kp->InitStr(); - keyParams.push_back(kp); + keyParams.push_back(kp2); + auto kp3 = std::make_shared(); + kp3->type_ = DEVICETYPE; + kp3->value_ = DEVICE_CAR; + kp3->InitStr(); + keyParams.push_back(kp3); + auto kp4 = std::make_shared(); + kp4->type_ = DIRECTION; + kp4->value_ = DIRECTION_VERTICAL; + kp4->InitStr(); + keyParams.push_back(kp4); + auto kp5 = std::make_shared(); + kp5->type_ = COLORMODE; + kp5->value_ = DARK; + kp5->InitStr(); + keyParams.push_back(kp5); auto config = HapParser::CreateResConfigFromKeyParams(keyParams); if (config != nullptr) { EXPECT_EQ(std::string("zh"), config->GetLocaleInfo()->getLanguage()); @@ -110,11 +110,7 @@ HWTEST_F(HapParserTest, HapParserFuncTest001, TestSize.Level1) } else { EXPECT_TRUE(false); } - - for (auto kp = keyParams.begin(); kp != keyParams.end(); kp++) { - delete *kp; - } - delete config; + keyParams.clear(); } #endif @@ -157,42 +153,40 @@ HWTEST_F(HapParserTest, HapParserFuncTest003, TestSize.Level1) */ HWTEST_F(HapParserTest, HapParserFuncTest004, TestSize.Level1) { - std::vector keyParams; - auto kp = new KeyParam(); - kp->type_ = LANGUAGES; - kp->value_ = 31336; - kp->InitStr(); - keyParams.push_back(kp); - kp = new KeyParam(); - kp->type_ = REGION; - kp->value_ = 17230; - kp->InitStr(); - keyParams.push_back(kp); - kp = new KeyParam(); - kp->type_ = SCREEN_DENSITY; - kp->value_ = SCREEN_DENSITY_SDPI; - kp->InitStr(); - keyParams.push_back(kp); - kp = new KeyParam(); - kp->type_ = DEVICETYPE; - kp->value_ = DEVICE_CAR; - kp->InitStr(); - keyParams.push_back(kp); - kp = new KeyParam(); - kp->type_ = DIRECTION; - kp->value_ = DIRECTION_VERTICAL; - kp->InitStr(); - keyParams.push_back(kp); - kp = new KeyParam(); - kp->type_ = COLORMODE; - kp->value_ = DARK; - kp->InitStr(); - keyParams.push_back(kp); + std::vector> keyParams; + auto kp1 = std::make_shared(); + kp1->type_ = LANGUAGES; + kp1->value_ = 31336; + kp1->InitStr(); + keyParams.push_back(kp1); + auto kp2 = std::make_shared(); + kp2->type_ = REGION; + kp2->value_ = 17230; + kp2->InitStr(); + keyParams.push_back(kp2); + auto kp3 = std::make_shared(); + kp3->type_ = SCREEN_DENSITY; + kp3->value_ = SCREEN_DENSITY_SDPI; + kp3->InitStr(); + keyParams.push_back(kp3); + auto kp4 = std::make_shared(); + kp4->type_ = DEVICETYPE; + kp4->value_ = DEVICE_CAR; + kp4->InitStr(); + keyParams.push_back(kp4); + auto kp5 = std::make_shared(); + kp5->type_ = DIRECTION; + kp5->value_ = DIRECTION_VERTICAL; + kp5->InitStr(); + keyParams.push_back(kp5); + auto kp6 = std::make_shared(); + kp6->type_ = COLORMODE; + kp6->value_ = DARK; + kp6->InitStr(); + keyParams.push_back(kp6); std::string folder = HapParser::ToFolderPath(keyParams); ASSERT_EQ("zh_CN-vertical-car-dark-sdpi", folder); - for (auto kp = keyParams.begin(); kp != keyParams.end(); kp++) { - delete *kp; - } + keyParams.clear(); } /* diff --git a/frameworks/resmgr/test/unittest/common/hap_resource_test.cpp b/frameworks/resmgr/test/unittest/common/hap_resource_test.cpp index b3c8230..5013e4d 100644 --- a/frameworks/resmgr/test/unittest/common/hap_resource_test.cpp +++ b/frameworks/resmgr/test/unittest/common/hap_resource_test.cpp @@ -62,7 +62,8 @@ void HapResourceTest::TearDown() // step 4: input testcase teardown step } -void TestGetIdValuesByName(const HapResource *pResource) +//void TestGetIdValuesByName(const HapResource *pResource) +void TestGetIdValuesByName(const std::shared_ptr pResource) { std::string name = std::string("app_name"); auto start = CurrentTimeUsec(); @@ -101,7 +102,7 @@ void TestGetIdValuesByName(const HapResource *pResource) HWTEST_F(HapResourceTest, HapResourceFuncTest001, TestSize.Level0) { auto start = CurrentTimeUsec(); - const HapResource *pResource = HapResource::LoadFromIndex(FormatFullPath(g_resFilePath).c_str(), nullptr); + auto pResource = HapResource::LoadFromIndex(FormatFullPath(g_resFilePath).c_str(), nullptr); auto cost = CurrentTimeUsec() - start; HILOG_DEBUG("load cost: %ld us.", cost); @@ -136,11 +137,10 @@ HWTEST_F(HapResourceTest, HapResourceFuncTest001, TestSize.Level0) EXPECT_TRUE(limitPath->GetIdItem()->value_ == "应用名称"); } TestGetIdValuesByName(pResource); - - delete (pResource); } -void GetIdValuesByNameFuncTest002(const HapResource *pResource, int id) +//void GetIdValuesByNameFuncTest002(const HapResource *pResource, int id) +void GetIdValuesByNameFuncTest002(const std::shared_ptr pResource, int id) { std::string name = std::string("app_name"); auto start = CurrentTimeUsec(); @@ -172,18 +172,17 @@ void GetIdValuesByNameFuncTest002(const HapResource *pResource, int id) */ HWTEST_F(HapResourceTest, HapResourceFuncTest002, TestSize.Level1) { - ResConfigImpl *rc = new ResConfigImpl; + auto rc = std::make_shared(); rc->SetLocaleInfo("en", nullptr, "US"); std::string resPath = FormatFullPath(g_resFilePath); const char *path = resPath.c_str(); auto start = CurrentTimeUsec(); - const HapResource *pResource = HapResource::LoadFromIndex(path, rc); + auto pResource = HapResource::LoadFromIndex(path, rc); auto cost = CurrentTimeUsec() - start; HILOG_DEBUG("load cost: %ld us.", cost); if (pResource == nullptr) { - delete rc; EXPECT_TRUE(false); return; } @@ -210,8 +209,6 @@ HWTEST_F(HapResourceTest, HapResourceFuncTest002, TestSize.Level1) } GetIdValuesByNameFuncTest002(pResource, id); - delete pResource; - delete rc; } /* @@ -223,7 +220,7 @@ HWTEST_F(HapResourceTest, HapResourceFuncTest002, TestSize.Level1) HWTEST_F(HapResourceTest, HapResourceFuncTest003, TestSize.Level1) { auto start = CurrentTimeUsec(); - const HapResource *pResource = HapResource::LoadFromIndex(FormatFullPath(g_resFilePath).c_str(), nullptr); + auto pResource = HapResource::LoadFromIndex(FormatFullPath(g_resFilePath).c_str(), nullptr); auto cost = CurrentTimeUsec() - start; HILOG_DEBUG("load cost: %ld us.", cost); @@ -260,7 +257,7 @@ HWTEST_F(HapResourceTest, HapResourceFuncTest003, TestSize.Level1) PrintIdValues(idv); } -ResDesc *LoadFromHap(const char *hapPath, const ResConfigImpl *defaultConfig) +ResDesc *LoadFromHap(const char *hapPath, const std::shared_ptr defaultConfig) { std::unique_ptr buf; size_t bufLen; diff --git a/frameworks/resmgr/test/unittest/common/res_config_impl_test.cpp b/frameworks/resmgr/test/unittest/common/res_config_impl_test.cpp index 0398a34..d08a9e7 100644 --- a/frameworks/resmgr/test/unittest/common/res_config_impl_test.cpp +++ b/frameworks/resmgr/test/unittest/common/res_config_impl_test.cpp @@ -53,9 +53,9 @@ void ResConfigImplTest::TearDown() { } -ResConfigImpl *CreateResConfigImpl(const char *language, const char *script, const char *region) +std::shared_ptr CreateResConfigImpl(const char *language, const char *script, const char *region) { - ResConfigImpl *resConfigImpl = new ResConfigImpl; + auto resConfigImpl = std::make_shared() ; resConfigImpl->SetLocaleInfo(language, script, region); return resConfigImpl; } @@ -67,11 +67,9 @@ ResConfigImpl *CreateResConfigImpl(const char *language, const char *script, con */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest001, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl(nullptr, nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("fr", nullptr, "CA"); + auto other = CreateResConfigImpl(nullptr, nullptr, nullptr); + auto current = CreateResConfigImpl("fr", nullptr, "CA"); EXPECT_TRUE(current->Match(other)); - delete current; - delete other; }; /* @@ -81,16 +79,14 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest001, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest002, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "CA"); - ResConfigImpl *current = CreateResConfigImpl("fr", nullptr, "CA"); + auto other = CreateResConfigImpl("en", nullptr, "CA"); + auto current = CreateResConfigImpl("fr", nullptr, "CA"); EXPECT_FALSE(current->Match(other)); Locale locale; locale = GetLocale("en", nullptr, "CA"); current->SetPreferredLocaleInfo(locale); EXPECT_TRUE(current->Match(other)); - delete current; - delete other; }; /* @@ -100,16 +96,14 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest002, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest003, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("tl", nullptr, "PH"); - ResConfigImpl *current = CreateResConfigImpl("fil", nullptr, "PH"); + auto other = CreateResConfigImpl("tl", nullptr, "PH"); + auto current = CreateResConfigImpl("fil", nullptr, "PH"); EXPECT_TRUE(current->Match(other)); Locale locale; locale = GetLocale("en", nullptr, "CA"); current->SetPreferredLocaleInfo(locale); EXPECT_TRUE(current->Match(other)); - delete current; - delete other; }; /* @@ -119,11 +113,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest003, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest004, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("qaa", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("qaa", nullptr, "CA"); + auto other = CreateResConfigImpl("qaa", nullptr, nullptr); + auto current = CreateResConfigImpl("qaa", nullptr, "CA"); EXPECT_TRUE(current->Match(other)); - delete current; - delete other; }; /* @@ -133,11 +125,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest004, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest005, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("qaa", nullptr, "CA"); - ResConfigImpl *current = CreateResConfigImpl("qaa", nullptr, "CA"); + auto other = CreateResConfigImpl("qaa", nullptr, "CA"); + auto current = CreateResConfigImpl("qaa", nullptr, "CA"); EXPECT_TRUE(current->Match(other)); - delete current; - delete other; }; /* @@ -147,11 +137,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest005, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest006, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("az", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("az", "Latn", nullptr); + auto other = CreateResConfigImpl("az", nullptr, nullptr); + auto current = CreateResConfigImpl("az", "Latn", nullptr); EXPECT_TRUE(current->Match(other)); - delete current; - delete other; }; /* @@ -161,11 +149,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest006, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest007, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("az", nullptr, "IR"); - ResConfigImpl *current = CreateResConfigImpl("az", "Arab", nullptr); + auto other = CreateResConfigImpl("az", nullptr, "IR"); + auto current = CreateResConfigImpl("az", "Arab", nullptr); EXPECT_TRUE(current->Match(other)); - delete current; - delete other; }; /* @@ -175,11 +161,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest007, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest008, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("ar", nullptr, "EG"); - ResConfigImpl *current = CreateResConfigImpl("ar", nullptr, "TN"); + auto other = CreateResConfigImpl("ar", nullptr, "EG"); + auto current = CreateResConfigImpl("ar", nullptr, "TN"); EXPECT_TRUE(current->Match(other)); - delete current; - delete other; }; /* @@ -189,16 +173,14 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest008, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest009, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("qaa", "Latn", "FR"); - ResConfigImpl *current = CreateResConfigImpl("qaa", nullptr, "CA"); + auto other = CreateResConfigImpl("qaa", "Latn", "FR"); + auto current = CreateResConfigImpl("qaa", nullptr, "CA"); EXPECT_FALSE(current->Match(other)); Locale locale; locale = GetLocale("qaa", "Latn", "FR"); current->SetPreferredLocaleInfo(locale); EXPECT_TRUE(current->Match(other)); - delete current; - delete other; }; /* @@ -208,16 +190,14 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest009, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest010, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("qaa", nullptr, "FR"); - ResConfigImpl *current = CreateResConfigImpl("qaa", "Latn", "CA"); + auto other = CreateResConfigImpl("qaa", nullptr, "FR"); + auto current = CreateResConfigImpl("qaa", "Latn", "CA"); EXPECT_FALSE(current->Match(other)); Locale locale; locale = GetLocale("qaa", nullptr, "FR"); current->SetPreferredLocaleInfo(locale); EXPECT_TRUE(current->Match(other)); - delete current; - delete other; }; /* @@ -227,8 +207,8 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest010, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest011, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("az", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("az", "Cyrl", nullptr); + auto other = CreateResConfigImpl("az", nullptr, nullptr); + auto current = CreateResConfigImpl("az", "Cyrl", nullptr); EXPECT_FALSE(current->Match(other)); Locale locale; @@ -239,8 +219,6 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest011, TestSize.Level1) locale = GetLocale("qaa", "Latn", "CA"); current->SetPreferredLocaleInfo(locale); EXPECT_FALSE(current->Match(other)); - delete current; - delete other; }; /* @@ -250,11 +228,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest011, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest012, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("az", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("az", nullptr, "IR"); + auto other = CreateResConfigImpl("az", nullptr, nullptr); + auto current = CreateResConfigImpl("az", nullptr, "IR"); EXPECT_FALSE(current->Match(other)); - delete current; - delete other; }; /* @@ -264,11 +240,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest012, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest013, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("qaa", nullptr, "FR"); - ResConfigImpl *current = CreateResConfigImpl("qaa", nullptr, "CA"); + auto other = CreateResConfigImpl("qaa", nullptr, "FR"); + auto current = CreateResConfigImpl("qaa", nullptr, "CA"); EXPECT_FALSE(current->Match(other)); - delete current; - delete other; }; /* @@ -278,12 +252,10 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest013, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest014, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("he", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("iw", nullptr, nullptr); + auto other = CreateResConfigImpl("he", nullptr, nullptr); + auto current = CreateResConfigImpl("iw", nullptr, nullptr); EXPECT_TRUE(current->Match(other)); EXPECT_TRUE(other->Match(current)); - delete current; - delete other; }; /* @@ -293,12 +265,10 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest014, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest015, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("ji", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("yi", nullptr, nullptr); + auto other = CreateResConfigImpl("ji", nullptr, nullptr); + auto current = CreateResConfigImpl("yi", nullptr, nullptr); EXPECT_TRUE(current->Match(other)); EXPECT_TRUE(other->Match(current)); - delete current; - delete other; }; /* @@ -308,12 +278,10 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest015, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest016, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("jw", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("jv", nullptr, nullptr); + auto other = CreateResConfigImpl("jw", nullptr, nullptr); + auto current = CreateResConfigImpl("jv", nullptr, nullptr); EXPECT_TRUE(current->Match(other)); EXPECT_TRUE(other->Match(current)); - delete current; - delete other; }; /* @@ -323,12 +291,10 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest016, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest017, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("in", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("id", nullptr, nullptr); + auto other = CreateResConfigImpl("in", nullptr, nullptr); + auto current = CreateResConfigImpl("id", nullptr, nullptr); EXPECT_TRUE(current->Match(other)); EXPECT_TRUE(other->Match(current)); - delete current; - delete other; }; /* @@ -338,11 +304,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest017, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest018, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("en", "Latn", nullptr); - ResConfigImpl *current = CreateResConfigImpl("en", "Qaag", nullptr); + auto other = CreateResConfigImpl("en", "Latn", nullptr); + auto current = CreateResConfigImpl("en", "Qaag", nullptr); EXPECT_TRUE(current->Match(other)); - delete current; - delete other; }; /* @@ -352,13 +316,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest018, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest019, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, nullptr); + auto current = CreateResConfigImpl("en", nullptr, nullptr); current->SetDeviceType(DeviceType::DEVICE_CAR); other->SetDeviceType(DeviceType::DEVICE_CAR); EXPECT_TRUE(current->Match(other)); - delete current; - delete other; }; /* @@ -368,13 +330,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest019, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest020, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, nullptr); + auto current = CreateResConfigImpl("en", nullptr, nullptr); current->SetDeviceType(DeviceType::DEVICE_CAR); other->SetDeviceType(DeviceType::DEVICE_PAD); EXPECT_FALSE(current->Match(other)); - delete current; - delete other; }; /* @@ -384,12 +344,10 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest020, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest021, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, nullptr); + auto current = CreateResConfigImpl("en", nullptr, nullptr); other->SetDeviceType(DeviceType::DEVICE_PAD); EXPECT_TRUE(current->Match(other)); - delete current; - delete other; }; /* @@ -399,12 +357,10 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest021, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest022, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, nullptr); + auto current = CreateResConfigImpl("en", nullptr, nullptr); current->SetDeviceType(DeviceType::DEVICE_PAD); EXPECT_TRUE(current->Match(other)); - delete current; - delete other; }; /* @@ -414,13 +370,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest022, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest023, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, nullptr); + auto current = CreateResConfigImpl("en", nullptr, nullptr); current->SetDirection(Direction::DIRECTION_HORIZONTAL); other->SetDirection(Direction::DIRECTION_HORIZONTAL); EXPECT_TRUE(current->Match(other)); - delete current; - delete other; }; /* @@ -430,13 +384,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest023, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest024, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, nullptr); + auto current = CreateResConfigImpl("en", nullptr, nullptr); current->SetDirection(Direction::DIRECTION_HORIZONTAL); other->SetDirection(Direction::DIRECTION_VERTICAL); EXPECT_FALSE(current->Match(other)); - delete current; - delete other; }; /* @@ -446,12 +398,10 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest024, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest025, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, nullptr); + auto current = CreateResConfigImpl("en", nullptr, nullptr); other->SetDirection(Direction::DIRECTION_HORIZONTAL); EXPECT_TRUE(current->Match(other)); - delete current; - delete other; }; /* @@ -461,12 +411,10 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest025, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest026, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, nullptr); + auto current = CreateResConfigImpl("en", nullptr, nullptr); current->SetDirection(Direction::DIRECTION_VERTICAL); EXPECT_TRUE(current->Match(other)); - delete current; - delete other; }; /* @@ -476,15 +424,13 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest026, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest027, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, nullptr); + auto 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; }; /* @@ -494,14 +440,12 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest027, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest028, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, nullptr); + auto 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; }; /* @@ -511,15 +455,13 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest028, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest029, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, nullptr); + auto 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; }; /* @@ -529,14 +471,12 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest029, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest030, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, nullptr); + auto current = CreateResConfigImpl("en", nullptr, nullptr); current->SetColorMode(ColorMode::LIGHT); other->SetColorMode(ColorMode::DARK); EXPECT_FALSE(current->Match(other)); EXPECT_FALSE(other->Match(current)); - delete current; - delete other; }; /* @@ -546,13 +486,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest030, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest031, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, nullptr); + auto current = CreateResConfigImpl("en", nullptr, nullptr); current->SetColorMode(ColorMode::LIGHT); other->SetColorMode(ColorMode::LIGHT); EXPECT_TRUE(current->Match(other)); - delete current; - delete other; }; /* @@ -562,14 +500,12 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest031, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest032, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, nullptr); + auto current = CreateResConfigImpl("en", nullptr, nullptr); current->SetColorMode(ColorMode::LIGHT); other->SetColorMode(ColorMode::COLOR_MODE_NOT_SET); EXPECT_TRUE(current->Match(other)); EXPECT_TRUE(other->Match(current)); - delete current; - delete other; }; /* @@ -579,13 +515,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest032, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest033, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, nullptr); + auto current = CreateResConfigImpl("en", nullptr, nullptr); current->SetColorMode(ColorMode::DARK); other->SetColorMode(ColorMode::DARK); EXPECT_TRUE(current->Match(other)); - delete current; - delete other; }; /* @@ -595,14 +529,12 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest033, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest034, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, nullptr); + auto current = CreateResConfigImpl("en", nullptr, nullptr); current->SetColorMode(ColorMode::DARK); other->SetColorMode(ColorMode::COLOR_MODE_NOT_SET); EXPECT_TRUE(current->Match(other)); EXPECT_TRUE(other->Match(current)); - delete current; - delete other; }; /* @@ -612,13 +544,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest034, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest035, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, nullptr); + auto current = CreateResConfigImpl("en", nullptr, nullptr); current->SetColorMode(ColorMode::COLOR_MODE_NOT_SET); other->SetColorMode(ColorMode::COLOR_MODE_NOT_SET); EXPECT_TRUE(current->Match(other)); - delete current; - delete other; }; /* @@ -628,8 +558,8 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest035, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest036, TestSize.Level1) { - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "CA"); - ResConfigImpl *current = CreateResConfigImpl("fr", nullptr, "CA"); + auto other = CreateResConfigImpl("en", nullptr, "CA"); + auto current = CreateResConfigImpl("fr", nullptr, "CA"); EXPECT_FALSE(current->Match(other)); Locale locale; @@ -644,9 +574,6 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest036, TestSize.Level1) locale = GetLocale("en", nullptr, "CA"); current->SetPreferredLocaleInfo(locale); EXPECT_TRUE(current->Match(other)); - - delete current; - delete other; }; /* @@ -656,14 +583,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplMatchTest036, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest001, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl(nullptr, nullptr, nullptr); - ResConfigImpl *current = CreateResConfigImpl("fr", nullptr, "FR"); - ResConfigImpl *other = CreateResConfigImpl("fr", nullptr, "CA"); + auto request = CreateResConfigImpl(nullptr, nullptr, nullptr); + auto current = CreateResConfigImpl("fr", nullptr, "FR"); + auto other = CreateResConfigImpl("fr", nullptr, "CA"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_TRUE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -673,9 +597,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest001, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest002, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("fr", nullptr, "CA"); - ResConfigImpl *current = CreateResConfigImpl(nullptr, nullptr, nullptr); - ResConfigImpl *other = CreateResConfigImpl(nullptr, nullptr, nullptr); + auto request = CreateResConfigImpl("fr", nullptr, "CA"); + auto current = CreateResConfigImpl(nullptr, nullptr, nullptr); + auto other = CreateResConfigImpl(nullptr, nullptr, nullptr); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_TRUE(other->IsMoreSuitable(current, request)); @@ -684,9 +608,6 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest002, TestSize.Level1) request->SetPreferredLocaleInfo(locale); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_TRUE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -696,14 +617,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest002, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest003, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("fr", nullptr, "CA"); - ResConfigImpl *current = CreateResConfigImpl("fr", nullptr, "FR"); - ResConfigImpl *other = CreateResConfigImpl(nullptr, nullptr, nullptr); + auto request = CreateResConfigImpl("fr", nullptr, "CA"); + auto current = CreateResConfigImpl("fr", nullptr, "FR"); + auto other = CreateResConfigImpl(nullptr, nullptr, nullptr); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -713,9 +631,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest003, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest004, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("fil", nullptr, "PH"); - ResConfigImpl *current = CreateResConfigImpl("tl", nullptr, "PH"); - ResConfigImpl *other = CreateResConfigImpl("fil", nullptr, "US"); + auto request = CreateResConfigImpl("fil", nullptr, "PH"); + auto current = CreateResConfigImpl("tl", nullptr, "PH"); + auto other = CreateResConfigImpl("fil", nullptr, "US"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); @@ -724,10 +642,6 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest004, TestSize.Level1) request->SetPreferredLocaleInfo(locale); EXPECT_FALSE(current->IsMoreSuitable(other, request)); EXPECT_TRUE(other->IsMoreSuitable(current, request)); - - delete request; - delete current; - delete other; } /* @@ -737,14 +651,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest004, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest005, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("fil", nullptr, "PH"); - ResConfigImpl *current = CreateResConfigImpl("fil", nullptr, "PH"); - ResConfigImpl *other = CreateResConfigImpl("tl", nullptr, "PH"); + auto request = CreateResConfigImpl("fil", nullptr, "PH"); + auto current = CreateResConfigImpl("fil", nullptr, "PH"); + auto other = CreateResConfigImpl("tl", nullptr, "PH"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -754,14 +665,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest005, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest006, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); - ResConfigImpl *current = CreateResConfigImpl("es", nullptr, "419"); - ResConfigImpl *other = CreateResConfigImpl("es", nullptr, "419"); + auto request = CreateResConfigImpl("es", nullptr, "AR"); + auto current = CreateResConfigImpl("es", nullptr, "419"); + auto other = CreateResConfigImpl("es", nullptr, "419"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_TRUE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -771,14 +679,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest006, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest007, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); - ResConfigImpl *current = CreateResConfigImpl("es", nullptr, "AR"); - ResConfigImpl *other = CreateResConfigImpl("es", nullptr, "419"); + auto request = CreateResConfigImpl("es", nullptr, "AR"); + auto current = CreateResConfigImpl("es", nullptr, "AR"); + auto other = CreateResConfigImpl("es", nullptr, "419"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -788,14 +693,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest007, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest008, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); - ResConfigImpl *current = CreateResConfigImpl("es", nullptr, "419"); - ResConfigImpl *other = CreateResConfigImpl("es", nullptr, nullptr); + auto request = CreateResConfigImpl("es", nullptr, "AR"); + auto current = CreateResConfigImpl("es", nullptr, "419"); + auto other = CreateResConfigImpl("es", nullptr, nullptr); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -805,14 +707,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest008, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest009, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); - ResConfigImpl *current = CreateResConfigImpl("es", nullptr, "419"); - ResConfigImpl *other = CreateResConfigImpl("es", nullptr, "ES"); + auto request = CreateResConfigImpl("es", nullptr, "AR"); + auto current = CreateResConfigImpl("es", nullptr, "419"); + auto other = CreateResConfigImpl("es", nullptr, "ES"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -822,14 +721,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest009, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest010, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); - ResConfigImpl *current = CreateResConfigImpl("es", nullptr, nullptr); - ResConfigImpl *other = CreateResConfigImpl("es", nullptr, "ES"); + auto request = CreateResConfigImpl("es", nullptr, "AR"); + auto current = CreateResConfigImpl("es", nullptr, nullptr); + auto other = CreateResConfigImpl("es", nullptr, "ES"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -839,9 +735,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest010, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest011, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); - ResConfigImpl *current = CreateResConfigImpl("es", nullptr, "PE"); - ResConfigImpl *other = CreateResConfigImpl("es", nullptr, "ES"); + auto request = CreateResConfigImpl("es", nullptr, "AR"); + auto current = CreateResConfigImpl("es", nullptr, "PE"); + auto other = CreateResConfigImpl("es", nullptr, "ES"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); @@ -850,9 +746,6 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest011, TestSize.Level1) request->SetPreferredLocaleInfo(locale); EXPECT_FALSE(current->IsMoreSuitable(other, request)); EXPECT_TRUE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -862,14 +755,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest011, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest012, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); - ResConfigImpl *current = CreateResConfigImpl("es", nullptr, "AR"); - ResConfigImpl *other = CreateResConfigImpl("es", nullptr, nullptr); + auto request = CreateResConfigImpl("es", nullptr, "AR"); + auto current = CreateResConfigImpl("es", nullptr, "AR"); + auto other = CreateResConfigImpl("es", nullptr, nullptr); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -879,14 +769,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest012, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest013, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "AR"); - ResConfigImpl *current = CreateResConfigImpl("es", nullptr, "US"); - ResConfigImpl *other = CreateResConfigImpl("es", nullptr, "BO"); + auto request = CreateResConfigImpl("es", nullptr, "AR"); + auto current = CreateResConfigImpl("es", nullptr, "US"); + auto other = CreateResConfigImpl("es", nullptr, "BO"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -896,14 +783,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest013, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest014, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "IC"); - ResConfigImpl *current = CreateResConfigImpl("es", nullptr, "ES"); - ResConfigImpl *other = CreateResConfigImpl("es", nullptr, "GQ"); + auto request = CreateResConfigImpl("es", nullptr, "IC"); + auto current = CreateResConfigImpl("es", nullptr, "ES"); + auto other = CreateResConfigImpl("es", nullptr, "GQ"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -913,14 +797,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest014, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest015, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("es", nullptr, "GQ"); - ResConfigImpl *current = CreateResConfigImpl("es", nullptr, "IC"); - ResConfigImpl *other = CreateResConfigImpl("es", nullptr, "419"); + auto request = CreateResConfigImpl("es", nullptr, "GQ"); + auto current = CreateResConfigImpl("es", nullptr, "IC"); + auto other = CreateResConfigImpl("es", nullptr, "419"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -930,14 +811,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest015, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest016, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "GB"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "001"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, nullptr); + auto request = CreateResConfigImpl("en", nullptr, "GB"); + auto current = CreateResConfigImpl("en", nullptr, "001"); + auto other = CreateResConfigImpl("en", nullptr, nullptr); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -947,14 +825,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest016, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest017, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "PR"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "001"); + auto request = CreateResConfigImpl("en", nullptr, "PR"); + auto current = CreateResConfigImpl("en", nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, "001"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -964,14 +839,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest017, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest018, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "DE"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "150"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "001"); + auto request = CreateResConfigImpl("en", nullptr, "DE"); + auto current = CreateResConfigImpl("en", nullptr, "150"); + auto other = CreateResConfigImpl("en", nullptr, "001"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -981,14 +853,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest018, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest019, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "IN"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "AU"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + auto request = CreateResConfigImpl("en", nullptr, "IN"); + auto current = CreateResConfigImpl("en", nullptr, "AU"); + auto other = CreateResConfigImpl("en", nullptr, "US"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -998,14 +867,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest019, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest020, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "PR"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "001"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "GB"); + auto request = CreateResConfigImpl("en", nullptr, "PR"); + auto current = CreateResConfigImpl("en", nullptr, "001"); + auto other = CreateResConfigImpl("en", nullptr, "GB"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1015,14 +881,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest020, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest021, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "IN"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "GB"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "AU"); + auto request = CreateResConfigImpl("en", nullptr, "IN"); + auto current = CreateResConfigImpl("en", nullptr, "GB"); + auto other = CreateResConfigImpl("en", nullptr, "AU"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1032,14 +895,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest021, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest022, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "IN"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "AU"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "CA"); + auto request = CreateResConfigImpl("en", nullptr, "IN"); + auto current = CreateResConfigImpl("en", nullptr, "AU"); + auto other = CreateResConfigImpl("en", nullptr, "CA"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1049,14 +909,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest022, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest023, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("pt", nullptr, "MZ"); - ResConfigImpl *current = CreateResConfigImpl("pt", nullptr, "PT"); - ResConfigImpl *other = CreateResConfigImpl("pt", nullptr, nullptr); + auto request = CreateResConfigImpl("pt", nullptr, "MZ"); + auto current = CreateResConfigImpl("pt", nullptr, "PT"); + auto other = CreateResConfigImpl("pt", nullptr, nullptr); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1066,14 +923,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest023, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest024, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("pt", nullptr, "MZ"); - ResConfigImpl *current = CreateResConfigImpl("pt", nullptr, "PT"); - ResConfigImpl *other = CreateResConfigImpl("pt", nullptr, "BR"); + auto request = CreateResConfigImpl("pt", nullptr, "MZ"); + auto current = CreateResConfigImpl("pt", nullptr, "PT"); + auto other = CreateResConfigImpl("pt", nullptr, "BR"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1083,9 +937,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest024, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest025, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("zh", "Hant", "MO"); - ResConfigImpl *current = CreateResConfigImpl("zh", "Hant", "HK"); - ResConfigImpl *other = CreateResConfigImpl("zh", "Hant", "TW"); + auto request = CreateResConfigImpl("zh", "Hant", "MO"); + auto current = CreateResConfigImpl("zh", "Hant", "HK"); + auto other = CreateResConfigImpl("zh", "Hant", "TW"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); @@ -1094,10 +948,6 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest025, TestSize.Level1) request->SetPreferredLocaleInfo(locale); EXPECT_FALSE(current->IsMoreSuitable(other, request)); EXPECT_TRUE(other->IsMoreSuitable(current, request)); - - delete request; - delete current; - delete other; } /* @@ -1107,14 +957,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest025, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest026, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("zh", "Hant", "US"); - ResConfigImpl *current = CreateResConfigImpl("zh", "Hant", "TW"); - ResConfigImpl *other = CreateResConfigImpl("zh", "Hant", "HK"); + auto request = CreateResConfigImpl("zh", "Hant", "US"); + auto current = CreateResConfigImpl("zh", "Hant", "TW"); + auto other = CreateResConfigImpl("zh", "Hant", "HK"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1124,14 +971,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest026, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest027, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("ar", nullptr, "DZ"); - ResConfigImpl *current = CreateResConfigImpl("ar", nullptr, "015"); - ResConfigImpl *other = CreateResConfigImpl("ar", nullptr, nullptr); + auto request = CreateResConfigImpl("ar", nullptr, "DZ"); + auto current = CreateResConfigImpl("ar", nullptr, "015"); + auto other = CreateResConfigImpl("ar", nullptr, nullptr); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1141,14 +985,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest027, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest028, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("ar", nullptr, "EG"); - ResConfigImpl *current = CreateResConfigImpl("ar", nullptr, nullptr); - ResConfigImpl *other = CreateResConfigImpl("ar", nullptr, "015"); + auto request = CreateResConfigImpl("ar", nullptr, "EG"); + auto current = CreateResConfigImpl("ar", nullptr, nullptr); + auto other = CreateResConfigImpl("ar", nullptr, "015"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1158,14 +999,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest028, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest029, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("ar", nullptr, "QA"); - ResConfigImpl *current = CreateResConfigImpl("ar", nullptr, "EG"); - ResConfigImpl *other = CreateResConfigImpl("ar", nullptr, "BH"); + auto request = CreateResConfigImpl("ar", nullptr, "QA"); + auto current = CreateResConfigImpl("ar", nullptr, "EG"); + auto other = CreateResConfigImpl("ar", nullptr, "BH"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1175,14 +1013,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest029, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest030, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("ar", nullptr, "QA"); - ResConfigImpl *current = CreateResConfigImpl("ar", nullptr, "SA"); - ResConfigImpl *other = CreateResConfigImpl("ar", nullptr, "015"); + auto request = CreateResConfigImpl("ar", nullptr, "QA"); + auto current = CreateResConfigImpl("ar", nullptr, "SA"); + auto other = CreateResConfigImpl("ar", nullptr, "015"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1192,14 +1027,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest030, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest031, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl(nullptr, nullptr, nullptr); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "001"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl(nullptr, nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, "001"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1209,14 +1041,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest031, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest032, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl(nullptr, nullptr, nullptr); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "GB"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl(nullptr, nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, "GB"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1226,14 +1055,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest032, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest033, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "PR"); - ResConfigImpl *current = CreateResConfigImpl(nullptr, nullptr, nullptr); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "001"); + auto request = CreateResConfigImpl("en", nullptr, "PR"); + auto current = CreateResConfigImpl(nullptr, nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, "001"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1243,14 +1069,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest033, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest034, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); - ResConfigImpl *other = CreateResConfigImpl(nullptr, nullptr, nullptr); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl("en", nullptr, nullptr); + auto other = CreateResConfigImpl(nullptr, nullptr, nullptr); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1260,14 +1083,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest034, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest035, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "PR"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, nullptr); - ResConfigImpl *other = CreateResConfigImpl(nullptr, nullptr, nullptr); + auto request = CreateResConfigImpl("en", nullptr, "PR"); + auto current = CreateResConfigImpl("en", nullptr, nullptr); + auto other = CreateResConfigImpl(nullptr, nullptr, nullptr); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1277,14 +1097,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest035, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest036, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl(nullptr, nullptr, nullptr); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "PR"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl(nullptr, nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, "PR"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1294,14 +1111,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest036, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest037, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "CN"); - ResConfigImpl *current = CreateResConfigImpl(nullptr, nullptr, nullptr); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "GB"); + auto request = CreateResConfigImpl("en", nullptr, "CN"); + auto current = CreateResConfigImpl(nullptr, nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, "GB"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1311,9 +1125,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest037, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest038, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", "Qaag", nullptr); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "GB"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "CA"); + auto request = CreateResConfigImpl("en", "Qaag", nullptr); + auto current = CreateResConfigImpl("en", nullptr, "GB"); + auto other = CreateResConfigImpl("en", nullptr, "CA"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); @@ -1322,9 +1136,6 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest038, TestSize.Level1) request->SetPreferredLocaleInfo(locale); EXPECT_FALSE(current->IsMoreSuitable(other, request)); EXPECT_TRUE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1334,14 +1145,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest038, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest039, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", "Qaag", nullptr); - ResConfigImpl *current = CreateResConfigImpl(nullptr, nullptr, nullptr); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "CA"); + auto request = CreateResConfigImpl("en", "Qaag", nullptr); + auto current = CreateResConfigImpl(nullptr, nullptr, nullptr); + auto other = CreateResConfigImpl("en", nullptr, "CA"); EXPECT_FALSE(current->IsMoreSuitable(other, request)); EXPECT_TRUE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1351,14 +1159,11 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest039, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest040, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "CN"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "GB"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl("en", nullptr, "CN"); + auto other = CreateResConfigImpl("en", nullptr, "GB"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1368,16 +1173,13 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest040, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest041, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl("en", nullptr, "US"); + auto 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; } /* @@ -1387,9 +1189,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest041, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest042, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl("en", nullptr, "US"); + auto other = CreateResConfigImpl("en", nullptr, "US"); request->SetDirection(Direction::DIRECTION_HORIZONTAL); request->SetDeviceType(DeviceType::DEVICE_PHONE); current->SetDirection(Direction::DIRECTION_HORIZONTAL); @@ -1397,9 +1199,6 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest042, TestSize.Level1) other->SetDeviceType(DeviceType::DEVICE_PHONE); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1409,9 +1208,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest042, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest043, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl("en", nullptr, "US"); + auto other = CreateResConfigImpl("en", nullptr, "US"); request->SetDirection(Direction::DIRECTION_HORIZONTAL); request->SetDeviceType(DeviceType::DEVICE_PHONE); request->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI / BASE_DPI); @@ -1422,9 +1221,6 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest043, TestSize.Level1) other->SetDeviceType(DeviceType::DEVICE_PHONE); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1434,9 +1230,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest043, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest044, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl("en", nullptr, "US"); + auto other = CreateResConfigImpl("en", nullptr, "US"); request->SetDirection(Direction::DIRECTION_HORIZONTAL); request->SetDeviceType(DeviceType::DEVICE_PHONE); request->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI / BASE_DPI); @@ -1445,9 +1241,6 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest044, TestSize.Level1) other->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI / BASE_DPI); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1457,9 +1250,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest044, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest045, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl("en", nullptr, "US"); + auto other = CreateResConfigImpl("en", nullptr, "US"); request->SetDirection(Direction::DIRECTION_HORIZONTAL); request->SetDeviceType(DeviceType::DEVICE_PHONE); request->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI / BASE_DPI); @@ -1471,9 +1264,6 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest045, TestSize.Level1) other->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_XXLDPI / BASE_DPI); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1483,9 +1273,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest045, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest046, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl("en", nullptr, "US"); + auto other = CreateResConfigImpl("en", nullptr, "US"); request->SetDirection(Direction::DIRECTION_HORIZONTAL); request->SetDeviceType(DeviceType::DEVICE_PHONE); request->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI / BASE_DPI); @@ -1497,9 +1287,6 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest046, TestSize.Level1) other->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_SDPI / BASE_DPI); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1509,9 +1296,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest046, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest047, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl("en", nullptr, "US"); + auto other = CreateResConfigImpl("en", nullptr, "US"); request->SetDirection(Direction::DIRECTION_HORIZONTAL); request->SetDeviceType(DeviceType::DEVICE_PHONE); request->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI / BASE_DPI); @@ -1523,9 +1310,6 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest047, TestSize.Level1) other->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_SDPI / BASE_DPI); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1535,15 +1319,12 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest047, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest048, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl("en", nullptr, "US"); + auto 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; } /* @@ -1553,15 +1334,12 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest048, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest049, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl("en", nullptr, "US"); + auto 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; } /* @@ -1571,15 +1349,12 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest049, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest050, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl("en", nullptr, "US"); + auto other = CreateResConfigImpl("en", nullptr, "US"); current->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_SDPI / BASE_DPI); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1589,16 +1364,13 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest050, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest051, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl("en", nullptr, "US"); + auto other = CreateResConfigImpl("en", nullptr, "US"); request->SetColorMode(ColorMode::LIGHT); current->SetColorMode(ColorMode::LIGHT); other->SetColorMode(ColorMode::LIGHT); EXPECT_TRUE(current->IsMoreSuitable(other, request)); - delete request; - delete current; - delete other; } /* @@ -1608,17 +1380,14 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest051, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest052, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl("en", nullptr, "US"); + auto other = CreateResConfigImpl("en", nullptr, "US"); request->SetColorMode(ColorMode::LIGHT); current->SetColorMode(ColorMode::LIGHT); other->SetColorMode(ColorMode::COLOR_MODE_NOT_SET); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1628,16 +1397,13 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest052, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest053, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl("en", nullptr, "US"); + auto other = CreateResConfigImpl("en", nullptr, "US"); request->SetColorMode(ColorMode::LIGHT); current->SetColorMode(ColorMode::COLOR_MODE_NOT_SET); other->SetColorMode(ColorMode::COLOR_MODE_NOT_SET); EXPECT_TRUE(current->IsMoreSuitable(other, request)); - delete request; - delete current; - delete other; } /* @@ -1647,16 +1413,13 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest053, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest054, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl("en", nullptr, "US"); + auto other = CreateResConfigImpl("en", nullptr, "US"); request->SetColorMode(ColorMode::DARK); current->SetColorMode(ColorMode::DARK); other->SetColorMode(ColorMode::DARK); EXPECT_TRUE(current->IsMoreSuitable(other, request)); - delete request; - delete current; - delete other; } /* @@ -1666,17 +1429,14 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest054, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest055, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl("en", nullptr, "US"); + auto other = CreateResConfigImpl("en", nullptr, "US"); request->SetColorMode(ColorMode::DARK); current->SetColorMode(ColorMode::DARK); other->SetColorMode(ColorMode::COLOR_MODE_NOT_SET); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1686,16 +1446,13 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest055, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest056, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl("en", nullptr, "US"); + auto other = CreateResConfigImpl("en", nullptr, "US"); request->SetColorMode(ColorMode::DARK); current->SetColorMode(ColorMode::COLOR_MODE_NOT_SET); other->SetColorMode(ColorMode::COLOR_MODE_NOT_SET); EXPECT_TRUE(current->IsMoreSuitable(other, request)); - delete request; - delete current; - delete other; } /* @@ -1705,9 +1462,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest056, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest057, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl("en", nullptr, "US"); + auto other = CreateResConfigImpl("en", nullptr, "US"); request->SetColorMode(ColorMode::LIGHT); request->SetDeviceType(DeviceType::DEVICE_PHONE); current->SetColorMode(ColorMode::COLOR_MODE_NOT_SET); @@ -1716,9 +1473,6 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest057, TestSize.Level1) other->SetDeviceType(DeviceType::DEVICE_NOT_SET); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1728,9 +1482,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest057, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest058, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl("en", nullptr, "US"); + auto other = CreateResConfigImpl("en", nullptr, "US"); request->SetColorMode(ColorMode::LIGHT); request->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI / BASE_DPI); current->SetColorMode(ColorMode::COLOR_MODE_NOT_SET); @@ -1739,9 +1493,6 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest058, TestSize.Level1) other->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_NOT_SET); EXPECT_FALSE(current->IsMoreSuitable(other, request)); EXPECT_TRUE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1751,9 +1502,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest058, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest059, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl("en", nullptr, "US"); + auto other = CreateResConfigImpl("en", nullptr, "US"); request->SetColorMode(ColorMode::LIGHT); request->SetInputDevice(InputDevice::INPUTDEVICE_POINTINGDEVICE); current->SetColorMode(ColorMode::COLOR_MODE_NOT_SET); @@ -1762,9 +1513,6 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest059, TestSize.Level1) other->SetInputDevice(InputDevice::INPUTDEVICE_NOT_SET); EXPECT_FALSE(current->IsMoreSuitable(other, request)); EXPECT_TRUE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1774,9 +1522,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest059, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest060, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "US"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "US"); + auto request = CreateResConfigImpl("en", nullptr, "US"); + auto current = CreateResConfigImpl("en", nullptr, "US"); + auto other = CreateResConfigImpl("en", nullptr, "US"); request->SetInputDevice(InputDevice::INPUTDEVICE_POINTINGDEVICE); request->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_LDPI / BASE_DPI); current->SetInputDevice(InputDevice::INPUTDEVICE_NOT_SET); @@ -1785,9 +1533,6 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest060, TestSize.Level1) other->SetScreenDensity(ScreenDensity::SCREEN_DENSITY_NOT_SET); EXPECT_FALSE(current->IsMoreSuitable(other, request)); EXPECT_TRUE(other->IsMoreSuitable(current, request)); - delete request; - delete current; - delete other; } /* @@ -1797,9 +1542,9 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest060, TestSize.Level1) */ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest061, TestSize.Level1) { - ResConfigImpl *request = CreateResConfigImpl("en", nullptr, "IN"); - ResConfigImpl *current = CreateResConfigImpl("en", nullptr, "AU"); - ResConfigImpl *other = CreateResConfigImpl("en", nullptr, "CA"); + auto request = CreateResConfigImpl("en", nullptr, "IN"); + auto current = CreateResConfigImpl("en", nullptr, "AU"); + auto other = CreateResConfigImpl("en", nullptr, "CA"); EXPECT_TRUE(current->IsMoreSuitable(other, request)); EXPECT_FALSE(other->IsMoreSuitable(current, request)); @@ -1808,10 +1553,5 @@ HWTEST_F(ResConfigImplTest, ResConfigImplIsMoreSuitableTest061, TestSize.Level1) request->SetPreferredLocaleInfo(currentLocale); EXPECT_FALSE(current->IsMoreSuitable(other, request)); EXPECT_TRUE(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_test.cpp b/frameworks/resmgr/test/unittest/common/res_config_test.cpp index 0e25998..c0fd6f1 100644 --- a/frameworks/resmgr/test/unittest/common/res_config_test.cpp +++ b/frameworks/resmgr/test/unittest/common/res_config_test.cpp @@ -63,16 +63,13 @@ void ResConfigTest::TearDown() */ HWTEST_F(ResConfigTest, ResConfigFuncTest001, TestSize.Level1) { - ResConfigImpl *rc = new ResConfigImpl; + auto rc = std::make_shared(); rc->SetLocaleInfo("en", nullptr, "AU"); - ResConfigImpl *current = new ResConfigImpl; + auto current = std::make_shared(); current->SetLocaleInfo("en", nullptr, "GB"); - ResConfigImpl *target = new ResConfigImpl; + auto target = std::make_shared(); target->SetLocaleInfo("zh", nullptr, "CN"); EXPECT_TRUE(rc->Match(current)); EXPECT_TRUE(!(rc->Match(target))); - delete target; - delete current; - delete rc; }; } \ No newline at end of file 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 986de60..176e358 100644 --- a/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp +++ b/frameworks/resmgr/test/unittest/common/resource_manager_performance_test.cpp @@ -115,7 +115,7 @@ int ParseIndexCost(const std::string &pstr, char *buf, const size_t& bufLen) long long total = 0; for (int k = 0; k < 1000; ++k) { auto t1 = std::chrono::high_resolution_clock::now(); - ResDesc *resDesc = new(std::nothrow) ResDesc(); + auto resDesc = std::make_shared(); if (resDesc == nullptr) { HILOG_ERROR("new ResDesc failed when LoadFromIndex"); free(buf); @@ -123,7 +123,6 @@ int ParseIndexCost(const std::string &pstr, char *buf, const size_t& bufLen) } 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; @@ -131,21 +130,18 @@ int ParseIndexCost(const std::string &pstr, char *buf, const size_t& bufLen) HILOG_DEBUG("ParseResHex success:\n%s", resDesc->ToString().c_str()); } - HapResource *pResource = new(std::nothrow) HapResource(pstr, 0, resDesc); + auto pResource = new(std::nothrow) HapResource(pstr, 0, 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 pResource; } double average = total / 1000.0; g_logLevel = LOG_DEBUG; diff --git a/frameworks/resmgr/test/unittest/common/resource_manager_test.cpp b/frameworks/resmgr/test/unittest/common/resource_manager_test.cpp index 81ac0e6..65f6d2a 100644 --- a/frameworks/resmgr/test/unittest/common/resource_manager_test.cpp +++ b/frameworks/resmgr/test/unittest/common/resource_manager_test.cpp @@ -267,7 +267,7 @@ HWTEST_F(ResourceManagerTest, ResourceManagerUpdateResConfigTest005, TestSize.Le rmc->AddResource("zh", nullptr, nullptr); // make a fake hapResource, then reload will fail - HapResource *hapResource = new HapResource("/data/test/non_exist", 0, nullptr); + auto hapResource = std::make_shared("/data/test/non_exist", 0, nullptr); ((ResourceManagerImpl *)rm)->hapManager_->hapResources_.push_back(hapResource); ((ResourceManagerImpl *)rm)->hapManager_->loadedHapPaths_["/data/test/non_exist"] = std::vector(); RState state; @@ -1769,12 +1769,11 @@ HWTEST_F(ResourceManagerTest, ResourceManagerResolveParentReferenceTest001, Test rm->AddResource(FormatFullPath(g_resFilePath).c_str()); int id; std::map outValue; - const IdItem *idItem; RState ret; id = rmc->GetResId("base", ResType::PATTERN); EXPECT_TRUE(id > 0); - idItem = ((ResourceManagerImpl *)rm)->hapManager_->FindResourceById(id); + auto idItem = ((ResourceManagerImpl *)rm)->hapManager_->FindResourceById(id); ASSERT_TRUE(idItem != nullptr); ret = ((ResourceManagerImpl *)rm)->ResolveParentReference(idItem, outValue); ASSERT_EQ(SUCCESS, ret); diff --git a/frameworks/resmgr/test/unittest/common/test_common.cpp b/frameworks/resmgr/test/unittest/common/test_common.cpp index 93b75ce..0c07d44 100644 --- a/frameworks/resmgr/test/unittest/common/test_common.cpp +++ b/frameworks/resmgr/test/unittest/common/test_common.cpp @@ -39,7 +39,7 @@ std::string FormatFullPath(const char *fileRelativePath) return result; } -void PrintIdValues(const HapResource::IdValues *idValues) +void PrintIdValues(const std::shared_ptr &idValues) { if (idValues == nullptr) { return; diff --git a/frameworks/resmgr/test/unittest/common/test_common.h b/frameworks/resmgr/test/unittest/common/test_common.h index c06ae0f..d8ee109 100644 --- a/frameworks/resmgr/test/unittest/common/test_common.h +++ b/frameworks/resmgr/test/unittest/common/test_common.h @@ -38,7 +38,7 @@ static const float BASE_DPI = 160.0f; static const int NON_EXIST_ID = 1111; std::string FormatFullPath(const char *fileRelativePath); -void PrintIdValues(const HapResource::IdValues *idValues); +void PrintIdValues(const std::shared_ptr &idValues); void PrintMapString(const std::map &value);