diff --git a/packing_tool/frameworks/BUILD.gn b/packing_tool/frameworks/BUILD.gn index acfc1298062d0b9a2c0aa2a9ccfae4347f463105..0094eb897bf2be14a22591f98704f1a39d6ac573 100644 --- a/packing_tool/frameworks/BUILD.gn +++ b/packing_tool/frameworks/BUILD.gn @@ -44,6 +44,7 @@ ohos_executable("ohos_packing_tool") { "src/app_packager.cpp", "src/appqf_packager.cpp", "src/fast_app_packager.cpp", + "src/general_normalize.cpp", "src/hap_packager.cpp", "src/hqf_packager.cpp", "src/hqf_verify.cpp", diff --git a/packing_tool/frameworks/include/constants.h b/packing_tool/frameworks/include/constants.h index 1de895ff8a3c806a90d4199c62e5765a4c5411f9..0bff67c383bfffe68611b9031e40e4fb2c84a990 100644 --- a/packing_tool/frameworks/include/constants.h +++ b/packing_tool/frameworks/include/constants.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -34,6 +34,7 @@ const std::string MODE_APPQF = "appqf"; const std::string MODE_MULTIAPP = "multiApp"; const std::string MODE_VERSION_NORMALIZE = "versionNormalize"; const std::string MODE_PACKAGE_NORMALIZE = "packageNormalize"; +const std::string MODE_GENERAL_NORMALIZE = "generalNormalize"; const std::string MODE_FAST_APP = "fastApp"; const std::string MODE_RES = "res"; const std::string COMPRESSOR_TEMP_DIR = "temp"; @@ -42,6 +43,7 @@ const std::string COMPRESSOR_FAST_APP_TEMP_DIR = "fastApp_"; const std::string COMPRESSOR_MULTIAPP_TEMP_DIR = "multiApp_"; const std::string COMPRESSOR_PACKAGENORMALIZE_TEMP_DIR = "packageNormalize_"; const std::string COMPRESSOR_VERSIONNORMALIZE_TEMP_DIR = "versionNormalize_"; +const std::string COMPRESSOR_GENERALNORMALIZE_TEMP_DIR = "generalNormalize_"; const std::string PARAM_PREFIX = "--"; const std::string PARAM_MODE = "mode"; const std::string PARAM_JSON_PATH = "json-path"; @@ -85,6 +87,15 @@ const std::string PARAM_HQF_LIST = "hqf-list"; const std::string PARAM_INPUT_LIST = "input-list"; const std::string PARAM_VERSION_CODE = "version-code"; const std::string PARAM_VERSION_NAME = "version-name"; +const std::string PARAM_DEVICE_TYPES = "device-types"; +const std::string PARAM_MIN_COMPATIBLE_VERSION_CODE = "min-compatible-version-code"; +const std::string PARAM_MIN_API_VERSION = "min-api-version"; +const std::string PARAM_COMPILE_SDK_TYPE = "compile-sdk-type"; +const std::string PARAM_TARGET_API_VERSION = "target-api-version"; +const std::string PARAM_API_RELEASE_TYPE = "api-release-type"; +const std::string PARAM_BUNDLE_TYPE = "bundle-type"; +const std::string PARAM_INSTALLATION_FREE = "installation-free"; +const std::string PARAM_DELIVERY_WITH_INSTALL = "delivery-with-install"; const std::string PARAM_APP_PATH = "app-path"; const std::string PARAM_RPCID = "rpcid"; const std::string PARAM_APPQF_PATH = "appqf-path"; @@ -130,9 +141,12 @@ const std::string NULL_DIR_NAME = ""; const std::string DEVICE_TYPE_FITNESSWATCH = "fitnessWatch"; const std::string DEVICE_TYPE_FITNESSWATCH_NEW = "liteWearable"; const std::string VERSION_RECORD = "version_record.json"; +const std::string GENERAL_RECORD = "general_record.json"; const std::string VERSION_NAME_PATTERN = "^[0-9.]+|(?=.*[{])(?=.*[}])[0-9a-zA-Z_.{}]+$"; const std::string BUNDLE_NAME_PATTERN = "([a-zA-Z]|[a-zA-Z]+(_*[0-9a-zA-Z])+)(\\.[0-9a-zA-Z]|\\.[0-9a-zA-Z]+(_*[0-9a-zA-Z])+){2,}"; +const std::string API_RELEASE_TYPE_PATTERN = "^(Canary[1-9]\\d*)|(Beta[1-9]\\d*)|(Release[1-9]\\d*)$"; +const std::vector BUNDLE_TYPE_LIST = {"app", "appService", "atomicService", "shared", "appPlugin"}; const std::string JSON_SUFFIX = ".json"; const std::string HAP_SUFFIX = ".hap"; @@ -153,6 +167,8 @@ const int32_t BUNDLE_NAME_LEN_MIN = 7; const int32_t BUNDLE_NAME_LEN_MAX = 128; const int32_t APP_SUFFIX_LENGTH = 4; const char COMMA_SPLIT = ','; +const int32_t MAX_VERSION_NAME_LENGTH = 127; +const int32_t MAX_VERSION_CODE = 2147483647; constexpr const char* SHORT_OPTIONS = ""; const struct option LONG_OPTIONS[] = { @@ -200,6 +216,15 @@ const struct option LONG_OPTIONS[] = { {PARAM_ENTRYCARD_PATH.c_str(), required_argument, nullptr, 43}, {PARAM_BUNDLE_NAME.c_str(), required_argument, nullptr, 44}, {PARAM_TOTAL_LIMIT.c_str(), required_argument, nullptr, 45}, + {PARAM_DEVICE_TYPES.c_str(), required_argument, nullptr, 46}, + {PARAM_MIN_COMPATIBLE_VERSION_CODE.c_str(), required_argument, nullptr, 47}, + {PARAM_MIN_API_VERSION.c_str(), required_argument, nullptr, 48}, + {PARAM_COMPILE_SDK_TYPE.c_str(), required_argument, nullptr, 49}, + {PARAM_TARGET_API_VERSION.c_str(), required_argument, nullptr, 50}, + {PARAM_API_RELEASE_TYPE.c_str(), required_argument, nullptr, 51}, + {PARAM_BUNDLE_TYPE.c_str(), required_argument, nullptr, 52}, + {PARAM_INSTALLATION_FREE.c_str(), required_argument, nullptr, 53}, + {PARAM_DELIVERY_WITH_INSTALL.c_str(), required_argument, nullptr, 54}, {nullptr, 0, nullptr, 0}, }; constexpr const int32_t OPTIONS_SIZE = sizeof(LONG_OPTIONS) / sizeof(LONG_OPTIONS[0]); diff --git a/packing_tool/frameworks/include/general_normalize.h b/packing_tool/frameworks/include/general_normalize.h new file mode 100644 index 0000000000000000000000000000000000000000..971e2ac8a03d2990c87f7ca7f35a6b320dd1de57 --- /dev/null +++ b/packing_tool/frameworks/include/general_normalize.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_GENERAL_NORMALIZE_H +#define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_GENERAL_NORMALIZE_H + +#include "json/module_json.h" +#include "packager.h" +#include "unzip_wrapper.h" +#include "zip_wrapper.h" + +namespace OHOS { +namespace AppPackingTool { + +class GeneralNormalize : public Packager { +public: + GeneralNormalize(const std::map ¶meterMap, std::string &resultReceiver); + ~GeneralNormalize() override {} + +protected: + int32_t InitAllowedParam() override; + int32_t PreProcess() override; + int32_t Process() override; + int32_t PostProcess() override; + +private: + bool ModifyModuleJson(const std::string &moduleJsonPath, std::map &modifyMap, + std::string &bundleName, std::string &moduleName); + bool ModifyConfigJson(const std::string &moduleJsonPath, std::map &modifyMap, + std::string &bundleName, std::string &moduleName); + bool ModifyPackInfo(const std::string &packInfoPath); + bool ProcessJsonFiles(const std::string &tempPath, std::list> &modifyMapList, + std::string &bundleName, std::string &moduleName); + bool CompressDirToHap(const std::string &tempDir, const std::string &modifiedHapPath); + std::string ConvertMapListToString(const std::list>& modifyMapList); + ZipWrapper zipWrapper_; + UnzipWrapper unzipWrapper_; + std::list hspOrhapList_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_GENERAL_NORMALIZE_H \ No newline at end of file diff --git a/packing_tool/frameworks/include/json/module_json.h b/packing_tool/frameworks/include/json/module_json.h index ed158cf287fb187ea523a7304ce86daafe122db4..ab20207c3634b3da533266334915e6c19186a074 100644 --- a/packing_tool/frameworks/include/json/module_json.h +++ b/packing_tool/frameworks/include/json/module_json.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -52,6 +52,27 @@ public: bool GetApiVersionObject(std::unique_ptr& apiVersionObj); // stage funcs, module.json + bool SetStageBundleName(const std::string& bundleName); + bool SetStageMinCompatibleVersionCode(const int32_t& minCompatibleVersionCode); + bool SetStageMinAPIVersion(const int32_t& minAPIVersion); + bool SetStageTargetAPIVersion(const int32_t& targetAPIVersion); + bool SetStageApiReleaseType(const std::string& apiReleaseType); + bool SetStageBundleType(const std::string& bundleType); + bool SetStageInstallationFree(const bool& installationFree); + bool SetStageDeliveryWithInstall(const bool& deliveryWithInstall); + bool SetStageDeviceTypes(const std::list& deviceType); + + // fa funcs, module.json + bool SetFaBundleName(const std::string& bundleName); + bool SetFaMinCompatibleVersionCode(const int32_t& minCompatibleVersionCode); + bool SetFaMinAPIVersion(const int32_t& minAPIVersion); + bool SetFaTargetAPIVersion(const int32_t& targetAPIVersion); + bool SetFaApiReleaseType(const std::string& apiReleaseType); + bool SetFaBundleType(const std::string& bundleType); + bool SetFaInstallationFree(const bool& installationFree); + bool SetFaDeliveryWithInstall(const bool& deliveryWithInstall); + bool SetFaDeviceTypes(const std::list& deviceType); + bool GetStageVersion(Version& version); bool GetStageVersionByAppObj(std::unique_ptr& appObj, Version& version); bool SetStageVersionCode(const int32_t& versionCode); @@ -141,6 +162,7 @@ public: bool GetFaAsanEnabledByAppObj(std::unique_ptr& appObj, bool& asanEnabled); bool GetFaReleaseType(std::string& releaseType); bool GetFaReleaseTypeByAppObj(std::unique_ptr& appObj, std::string& releaseType); + bool GetFaDeliveryWithInstall(bool& deliveryWithInstall); // common funcs bool GetBundleName(std::string& bundleName); @@ -158,6 +180,7 @@ public: bool GetTargetPriorityByAppObj(std::unique_ptr& appObj, int32_t& targetPriority); bool GetTargetModulePriority(int32_t& targetModulePriority); bool GetTargetModulePriorityByModuleObj(std::unique_ptr& moduleObj, int32_t& targetModulePriority); + // config.json or module.json bool GetAbilityNames(std::list& abilityNames); bool GetAbilityNamesByModuleObj(std::unique_ptr& moduleObj, std::list& abilityNames); @@ -177,6 +200,9 @@ public: bool GetMultiAppMode(MultiAppMode& multiAppMode); bool GetMultiAppModeByAppObj(std::unique_ptr& appObj, MultiAppMode& multiAppMode); + bool GetMinApiVersion(int32_t& minAPIVersion); + bool GetTargetApiVersion(int32_t& targetAPIVersion); + bool GetDeliveryWithInstall(bool& deliveryWithInstall); bool IsModuleAtomicServiceValid(); bool CheckEntryInAtomicService(); @@ -198,6 +224,18 @@ public: // json function for hqf bool GetPatchModuleName(std::string& patchModuleName); + bool SetBundleName(const std::string& bundleName, const bool& isStage); + bool SetMinCompatibleVersionCode(const int32_t& minCompatibleVersionCode, const bool& isStage); + bool SetMinAPIVersion(const int32_t& minAPIVersion, const bool& isStage); + bool SetTargetAPIVersion(const int32_t& targetAPIVersion, const bool& isStage); + bool SetApiReleaseType(const std::string& apiReleaseType, const bool& isStage); + bool SetBundleType(const std::string& bundleType, const bool& isStage); + bool SetInstallationFree(const bool& installationFree, const bool& isStage); + bool SetDeliveryWithInstall(const bool& deliveryWithInstall, const bool& isStage); + bool SetVersionCode(const int32_t& versionCode, const bool& isStage); + bool SetVersionName(const std::string& versionName, const bool& isStage); + bool SetDeviceTypes(const std::list& deviceTypes, const bool& isStage); + protected: bool CheckStageBundleType(const std::string& moduleName, const std::string& moduleType, const std::string& bundleType, const bool& installationFree); diff --git a/packing_tool/frameworks/include/json/pack_info.h b/packing_tool/frameworks/include/json/pack_info.h index 2c6380cc866497ce1a097750e554d71bf3e6054b..35c61d9337fb6e1c01b265858d879e5066314085 100644 --- a/packing_tool/frameworks/include/json/pack_info.h +++ b/packing_tool/frameworks/include/json/pack_info.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -51,6 +51,8 @@ public: int32_t moduleIndex, std::unique_ptr& distroObj); bool GetDistroObjectByModuleObj(const std::unique_ptr& moduleObj, std::unique_ptr& distroObj); + bool GetApiVersionObjectByModuleObj(const std::unique_ptr& moduleObj, + std::unique_ptr& distroObj); bool GetPackageObject(int32_t packageIndex, std::unique_ptr& packageObj); bool GetExtensionAbilitiesObj(int32_t moduleIndex, std::unique_ptr& extensionAbilitiesObj); bool GetExtensionAbilitiesObjByModulesObj(const std::unique_ptr& modulesObj, @@ -85,6 +87,15 @@ public: bool GetPackageNames(std::list &packageNames); bool GetPackageNamesByPackagesObj(const std::unique_ptr& appObj, std::list &packageNames); + bool SetMinCompatibleVersionCode(const int32_t& minCompatibleVersionCode); + bool SetMinAPIVersion(const int32_t& minAPIVersion); + bool SetTargetAPIVersion(const int32_t& targetAPIVersion); + bool SetApiReleaseType(const std::string& apiReleaseType); + bool SetBundleType(const std::string& bundleType); + bool SetInstallationFree(const bool& installationFree); + bool SetDeliveryWithInstall(const bool& deliveryWithInstall); + bool SetDeviceTypes(const std::list& deviceTypes); + private: std::unique_ptr root_ = nullptr; }; diff --git a/packing_tool/frameworks/include/json/pt_json.h b/packing_tool/frameworks/include/json/pt_json.h index 05aa12b7c5a840ec429eb639442b69a2a2b459e9..1c6c8e6c7a4ae55cd7e319daad9f9a42e8762a01 100644 --- a/packing_tool/frameworks/include/json/pt_json.h +++ b/packing_tool/frameworks/include/json/pt_json.h @@ -16,6 +16,7 @@ #ifndef DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_JSON_PT_JSON_H #define DEVELOPTOOLS_PACKING_TOOL_APT_FRAMEWORKS_INCLUDE_JSON_PT_JSON_H +#include #include #include @@ -56,6 +57,7 @@ public: bool Add(const char *key, double value) const; bool Add(const char *key, const char *value) const; bool Add(const char *key, const std::unique_ptr &value) const; + bool Add(const char *key, const std::list& values) const; // Push back to array bool Push(bool value) const; @@ -116,6 +118,7 @@ public: Result SetUInt64(const char *key, const uint64_t& value); Result SetDouble(const char *key, const double& value); Result SetString(const char *key, const std::string& value); + Result SetArray(const char *key, const std::list& value); private: cJSON *object_ = nullptr; diff --git a/packing_tool/frameworks/include/utils.h b/packing_tool/frameworks/include/utils.h index 7b610a2c08b9199c65b9dd874cc50d6442f60aa0..33ef76ce3399ee7de2833340a4b9e604a2fe6450 100644 --- a/packing_tool/frameworks/include/utils.h +++ b/packing_tool/frameworks/include/utils.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -46,6 +46,8 @@ public: static bool IsPositiveInteger(const std::string& str, int min = 0, int max = INT32_MAX); static std::string ReplaceAll(std::string str, const std::string& from, const std::string& to); static bool EndsWith(const std::string& str, const std::string& suffix); + static bool StringToBool(const std::string& str); + static bool StringToArray(const std::string& str, std::list& array); // Algorithm static std::string GetSha256Str(const std::string &str); @@ -71,6 +73,9 @@ public: static bool GetFormattedPath(const std::string& path, std::string& formattedPath); static bool GetRealPath(const std::string& path, std::string& realPath); static bool GetRealPathOfNoneExistFile(const std::string& path, std::string& realPath); + static bool RemoveAllFilesInDirectory(const std::string& directoryPath); + static std::string ArrayToString(const std::list &array); + static std::string BoolToString(bool value); }; } // namespace AppPackingTool } // namespace OHOS diff --git a/packing_tool/frameworks/src/general_normalize.cpp b/packing_tool/frameworks/src/general_normalize.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dee595e1e87227edf2229322aa0f48d7c2f28509 --- /dev/null +++ b/packing_tool/frameworks/src/general_normalize.cpp @@ -0,0 +1,747 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "general_normalize.h" + +#include "hap_packager.h" +#include "hqf_packager.h" +#include "hsp_packager.h" +#include "json/json_utils.h" +#include "json/module_json.h" +#include "json/normalize_version_utils.h" +#include "json/pack_info.h" +#include "log.h" +#include "utils.h" +#include "zip_utils.h" + +namespace OHOS { +namespace AppPackingTool { +namespace { +const std::string BUNDLE_TYPE = "bundleType"; +const std::string BUNDLE_NAME = "bundleName"; +const std::string VERSION_CODE = "versionCode"; +const std::string VERSION_NAME = "versionName"; +const std::string MIN_COMPATIBLE_VERSION_CODE = "minCompatibleVersionCode"; +const std::string MIN_API_VERSION = "minAPIVersion"; +const std::string TARGET_API_VERSION = "targetAPIVersion"; +const std::string API_RELEASE_TYPE = "apiReleaseType"; +const std::string DEVICE_TYPES = "deviceTypes"; +const std::string INSTALLATION_FREE = "installationFree"; +const std::string DELIVERY_WITH_INSTALL = "deliveryWithInstall"; +const std::string MODULE_NAME = "moduleName"; +const std::vector DEVICE_TYPE_LIST = {"default", "tablet", "tv", "wearable", "car", "2in1"}; +} +GeneralNormalize::GeneralNormalize(const std::map ¶meterMap, std::string &resultReceiver) + : Packager(parameterMap, resultReceiver) +{} + +int32_t GeneralNormalize::InitAllowedParam() +{ + allowedParameters_ = { + {} + }; + return ERR_OK; +} + +int32_t GeneralNormalize::PreProcess() +{ + auto it = parameterMap_.find(Constants::PARAM_INPUT_LIST); + if (it == parameterMap_.end()) { + LOGE("Input input-list is empty."); + return ERR_INVALID_VALUE; + } + if (!CompatibleProcess(it->second, hspOrhapList_, Constants::HAP_SUFFIX, Constants::HSP_SUFFIX)) { + LOGE("Input input-list is invalid."); + return ERR_INVALID_VALUE; + } + if (hspOrhapList_.size() == 0) { + LOGE("Input input-list is empty."); + return ERR_INVALID_VALUE; + } + + it = parameterMap_.find(Constants::PARAM_VERSION_NAME); + std::regex pattern(Constants::VERSION_NAME_PATTERN); + if (it != parameterMap_.end()) { + if (!std::regex_match(it->second, pattern) || it->second.size() > Constants::MAX_VERSION_NAME_LENGTH) { + LOGE("Input version-name is not valid."); + return ERR_INVALID_VALUE; + } + } + + it = parameterMap_.find(Constants::PARAM_VERSION_CODE); + if (it != parameterMap_.end()) { + if (!Utils::IsPositiveInteger(it->second) || stoi(it->second)> Constants::MAX_VERSION_CODE) { + LOGE("Input version-code is invalid."); + return ERR_INVALID_VALUE; + } + } + + it = parameterMap_.find(Constants::PARAM_DEVICE_TYPES); + if (it != parameterMap_.end()) { + std::list deviceTypeList; + if (!Utils::StringToArray(it->second, deviceTypeList)) { + LOGE("Input device-type is invalid."); + return ERR_INVALID_VALUE; + } + for (auto& item : deviceTypeList) { + if ((std::find(DEVICE_TYPE_LIST.begin(), DEVICE_TYPE_LIST.end(), item) == DEVICE_TYPE_LIST.end())) { + LOGE("Input device-type is invalid."); + return ERR_INVALID_VALUE; + } + } + } + + it = parameterMap_.find(Constants::PARAM_BUNDLE_NAME); + std::regex bundleNamePattern(Constants::BUNDLE_NAME_PATTERN); + if (it != parameterMap_.end()) { + if (!std::regex_match(it->second, bundleNamePattern) || it->second.length() < Constants::BUNDLE_NAME_LEN_MIN || + it->second.length() > Constants::BUNDLE_NAME_LEN_MAX) { + LOGE("Input bundle-name is invalid."); + return ERR_INVALID_VALUE; + } + } + + it = parameterMap_.find(Constants::PARAM_MIN_COMPATIBLE_VERSION_CODE); + if (it != parameterMap_.end()) { + if (!Utils::IsPositiveInteger(it->second) || stoi(it->second) > Constants::MAX_VERSION_CODE) { + LOGE("Input min-compatible-version-code is invalid."); + return ERR_INVALID_VALUE; + } + } + + it = parameterMap_.find(Constants::PARAM_MIN_API_VERSION); + if (it != parameterMap_.end()) { + if (!Utils::IsPositiveInteger(it->second) || stoi(it->second) > Constants::MAX_VERSION_CODE) { + LOGE("Input min-api-version is invalid."); + return ERR_INVALID_VALUE; + } + } + + it = parameterMap_.find(Constants::PARAM_TARGET_API_VERSION); + if (it != parameterMap_.end()) { + if (!Utils::IsPositiveInteger(it->second) || stoi(it->second) > Constants::MAX_VERSION_CODE) { + LOGE("Input target-api-version is invalid."); + return ERR_INVALID_VALUE; + } + } + + it = parameterMap_.find(Constants::PARAM_API_RELEASE_TYPE); + std::regex releaseTypePattern(Constants::API_RELEASE_TYPE_PATTERN); + if (it != parameterMap_.end()) { + if (!std::regex_match(it->second, releaseTypePattern)) { + LOGE("Input api-release-type is invalid."); + return ERR_INVALID_VALUE; + } + } + + it = parameterMap_.find(Constants::PARAM_BUNDLE_TYPE); + if (it != parameterMap_.end()) { + if ((std::find(Constants::BUNDLE_TYPE_LIST.begin(), Constants::BUNDLE_TYPE_LIST.end(), it->second) == + Constants::BUNDLE_TYPE_LIST.end())) { + LOGE("Input bundle-type is invalid."); + return ERR_INVALID_VALUE; + } + } + + it = parameterMap_.find(Constants::PARAM_INSTALLATION_FREE); + if (it != parameterMap_.end()) { + if (it->second != "true" && it->second != "false") { + LOGE("Input installation-free is invalid."); + return ERR_INVALID_VALUE; + } + } + + it = parameterMap_.find(Constants::PARAM_DELIVERY_WITH_INSTALL); + if (it != parameterMap_.end()) { + if (it->second != "true" && it->second != "false") { + LOGE("Input delivery-with-install is invalid."); + return ERR_INVALID_VALUE; + } + } + + if (!IsOutDirectoryValid()) { + return ERR_INVALID_VALUE; + } + return ERR_OK; +} + +bool GeneralNormalize::ModifyModuleJson(const std::string &moduleJsonPath, + std::map &modifyMap, std::string &bundleName, std::string &moduleName) +{ + ModuleJson moduleJson; + if (!moduleJson.ParseFromFile(moduleJsonPath)) { + LOGE("Parse and modify module.json failed, parse module.json is null."); + return false; + } + auto it = parameterMap_.find(Constants::PARAM_VERSION_CODE); + if (it != parameterMap_.end()) { + int32_t versionCode = std::stoi(parameterMap_.at(Constants::PARAM_VERSION_CODE)); + Version version; + moduleJson.GetStageVersion(version); + modifyMap[VERSION_CODE] = std::to_string(version.versionCode); + if (!moduleJson.SetVersionCode(versionCode, true)) { + LOGE("SetVersionCode failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_VERSION_NAME); + if (it != parameterMap_.end()) { + std::string versionName = parameterMap_.at(Constants::PARAM_VERSION_NAME); + Version version; + moduleJson.GetStageVersion(version); + modifyMap[VERSION_NAME] = version.versionName; + if (!moduleJson.SetVersionName(versionName, true)) { + LOGE("SetVersionName failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_BUNDLE_NAME); + if (it != parameterMap_.end()) { + std::string targetBundleName = parameterMap_.at(Constants::PARAM_BUNDLE_NAME); + std::string originBundleName; + moduleJson.GetBundleName(originBundleName); + modifyMap[BUNDLE_NAME] = originBundleName; + if (!moduleJson.SetBundleName(targetBundleName, true)) { + LOGE("SetBundleName failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_MIN_COMPATIBLE_VERSION_CODE); + if (it != parameterMap_.end()) { + Version version; + moduleJson.GetStageVersion(version); + modifyMap[MIN_COMPATIBLE_VERSION_CODE] = std::to_string(version.minCompatibleVersionCode); + int32_t minCompatibleVersionCode = std::stoi(parameterMap_.at(Constants::PARAM_MIN_COMPATIBLE_VERSION_CODE)); + if (!moduleJson.SetMinCompatibleVersionCode(minCompatibleVersionCode, true)) { + LOGE("SetMinCompatibleVersionCode failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_MIN_API_VERSION); + if (it != parameterMap_.end()) { + int32_t minAPIVersion = std::stoi(parameterMap_.at(Constants::PARAM_MIN_API_VERSION)); + int32_t originMinAPIVersion = -1; + moduleJson.GetMinApiVersion(originMinAPIVersion); + modifyMap[MIN_API_VERSION] = std::to_string(originMinAPIVersion); + if (!moduleJson.SetMinAPIVersion(minAPIVersion, true)) { + LOGE("SetMinAPIVersion failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_TARGET_API_VERSION); + if (it != parameterMap_.end()) { + int32_t targetAPIVersion = std::stoi(parameterMap_.at(Constants::PARAM_TARGET_API_VERSION)); + int32_t originTargetAPIVersion = -1; + moduleJson.GetTargetApiVersion(originTargetAPIVersion); + modifyMap[TARGET_API_VERSION] = std::to_string(originTargetAPIVersion); + if (!moduleJson.SetTargetAPIVersion(targetAPIVersion, true)) { + LOGE("SetTargetAPIVersion failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_API_RELEASE_TYPE); + if (it != parameterMap_.end()) { + std::string apiReleaseType = parameterMap_.at(Constants::PARAM_API_RELEASE_TYPE); + std::string originApiReleaseType; + moduleJson.GetStageApiReleaseType(originApiReleaseType); + modifyMap[API_RELEASE_TYPE] = originApiReleaseType; + if (!moduleJson.SetApiReleaseType(apiReleaseType, true)) { + LOGE("SetApiReleaseType failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_BUNDLE_TYPE); + if (it != parameterMap_.end()) { + std::string bundleType = parameterMap_.at(Constants::PARAM_BUNDLE_TYPE); + std::string originBundleType; + moduleJson.GetStageBundleType(originBundleType); + modifyMap[BUNDLE_TYPE] = originBundleType; + if (!moduleJson.SetBundleType(bundleType, true)) { + LOGE("SetBundleType failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_INSTALLATION_FREE); + if (it != parameterMap_.end()) { + bool installationFree = Utils::StringToBool(parameterMap_.at(Constants::PARAM_INSTALLATION_FREE)); + bool originInstallationFree; + moduleJson.GetStageInstallationFree(originInstallationFree); + modifyMap[INSTALLATION_FREE] = Utils::BoolToString(originInstallationFree); + if (!moduleJson.SetInstallationFree(installationFree, true)) { + LOGE("SetInstallationFree failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_DELIVERY_WITH_INSTALL); + if (it != parameterMap_.end()) { + bool deliveryWithInstall = Utils::StringToBool(parameterMap_.at(Constants::PARAM_DELIVERY_WITH_INSTALL)); + bool originDeliveryWithInstall; + moduleJson.GetDeliveryWithInstall(originDeliveryWithInstall); + modifyMap[DELIVERY_WITH_INSTALL] = Utils::BoolToString(originDeliveryWithInstall); + if (!moduleJson.SetDeliveryWithInstall(deliveryWithInstall, true)) { + LOGE("SetDeliveryWithInstall failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_DEVICE_TYPES); + if (it != parameterMap_.end()) { + std::list deviceTypes; + Utils::StringToArray(parameterMap_.at(Constants::PARAM_DEVICE_TYPES), deviceTypes); + std::list originDeviceTypes; + moduleJson.GetStageDeviceTypes(originDeviceTypes); + modifyMap[DEVICE_TYPES] = Utils::ArrayToString(originDeviceTypes); + if (!moduleJson.SetDeviceTypes(deviceTypes, true)) { + LOGE("SetDeviceTypes failed"); + return false; + } + } + + moduleJson.GetBundleName(bundleName); + moduleJson.GetModuleName(moduleName); + modifyMap[MODULE_NAME] = moduleName; + if (!JsonUtils::StrToFile(moduleJson.ToString(), moduleJsonPath)) { + LOGE("Parse and modify module.json failed, write Json failed."); + return false; + } + return true; +} + +bool GeneralNormalize::ModifyConfigJson(const std::string &configJsonPath, + std::map &modifyMap, std::string &bundleName, std::string &moduleName) +{ + ModuleJson configJson; + if (!configJson.ParseFromFile(configJsonPath)) { + LOGE("Parse and modify config.json failed, parse json is null."); + return false; + } + auto it = parameterMap_.find(Constants::PARAM_VERSION_CODE); + if (it != parameterMap_.end()) { + Version version; + configJson.GetFaVersion(version); + modifyMap[VERSION_CODE] = std::to_string(version.versionCode); + int32_t versionCode = std::stoi(parameterMap_.at(Constants::PARAM_VERSION_CODE)); + if (!configJson.SetVersionCode(versionCode, false)) { + LOGE("SetVersionCode failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_VERSION_NAME); + if (it != parameterMap_.end()) { + Version version; + configJson.GetFaVersion(version); + modifyMap[VERSION_NAME] = version.versionName; + std::string versionName = parameterMap_.at(Constants::PARAM_VERSION_NAME); + if (!configJson.SetVersionName(versionName, false)) { + LOGE("SetVersionName failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_BUNDLE_NAME); + if (it != parameterMap_.end()) { + std::string originBundleName; + configJson.GetBundleName(originBundleName); + modifyMap[BUNDLE_NAME] = originBundleName; + std::string targetBundleName = parameterMap_.at(Constants::PARAM_BUNDLE_NAME); + if (!configJson.SetBundleName(targetBundleName, false)) { + LOGE("SetBundleName failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_MIN_COMPATIBLE_VERSION_CODE); + if (it != parameterMap_.end()) { + Version version; + configJson.GetFaVersion(version); + modifyMap[MIN_COMPATIBLE_VERSION_CODE] = std::to_string(version.minCompatibleVersionCode); + int32_t minCompatibleVersionCode = std::stoi(parameterMap_.at(Constants::PARAM_MIN_COMPATIBLE_VERSION_CODE)); + if (!configJson.SetMinCompatibleVersionCode(minCompatibleVersionCode, false)) { + LOGE("SetMinCompatibleVersionCode failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_MIN_API_VERSION); + if (it != parameterMap_.end()) { + ModuleApiVersion moduleApiVersion; + configJson.GetFaModuleApiVersion(moduleApiVersion); + modifyMap[MIN_API_VERSION] = std::to_string(moduleApiVersion.compatibleApiVersion); + int32_t minAPIVersion = std::stoi(parameterMap_.at(Constants::PARAM_MIN_API_VERSION)); + if (!configJson.SetMinAPIVersion(minAPIVersion, false)) { + LOGE("SetMinAPIVersion failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_TARGET_API_VERSION); + if (it != parameterMap_.end()) { + ModuleApiVersion moduleApiVersion; + configJson.GetFaModuleApiVersion(moduleApiVersion); + modifyMap[TARGET_API_VERSION] = std::to_string(moduleApiVersion.targetApiVersion); + int32_t targetAPIVersion = std::stoi(parameterMap_.at(Constants::PARAM_TARGET_API_VERSION)); + if (!configJson.SetTargetAPIVersion(targetAPIVersion, false)) { + LOGE("SetTargetAPIVersion failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_API_RELEASE_TYPE); + if (it != parameterMap_.end()) { + ModuleApiVersion moduleApiVersion; + configJson.GetFaModuleApiVersion(moduleApiVersion); + modifyMap[API_RELEASE_TYPE] = moduleApiVersion.releaseType; + std::string apiReleaseType = parameterMap_.at(Constants::PARAM_API_RELEASE_TYPE); + if (!configJson.SetApiReleaseType(apiReleaseType, false)) { + LOGE("SetApiReleaseType failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_BUNDLE_TYPE); + if (it != parameterMap_.end()) { + std::string originBundleType; + configJson.GetFaBundleType(originBundleType); + modifyMap[BUNDLE_TYPE] = originBundleType; + std::string bundleType = parameterMap_.at(Constants::PARAM_BUNDLE_TYPE); + if (!configJson.SetBundleType(bundleType, false)) { + LOGE("SetBundleType failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_INSTALLATION_FREE); + if (it != parameterMap_.end()) { + bool originInstallationFree; + configJson.GetFaInstallationFree(originInstallationFree); + modifyMap[INSTALLATION_FREE] = Utils::BoolToString(originInstallationFree); + bool installationFree = Utils::StringToBool(parameterMap_.at(Constants::PARAM_INSTALLATION_FREE)); + if (!configJson.SetInstallationFree(installationFree, false)) { + LOGE("SetInstallationFree failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_DELIVERY_WITH_INSTALL); + if (it != parameterMap_.end()) { + bool originDeliveryWithInstall; + configJson.GetFaDeliveryWithInstall(originDeliveryWithInstall); + modifyMap[DELIVERY_WITH_INSTALL] = Utils::BoolToString(originDeliveryWithInstall); + bool deliveryWithInstall = Utils::StringToBool(parameterMap_.at(Constants::PARAM_DELIVERY_WITH_INSTALL)); + if (!configJson.SetDeliveryWithInstall(deliveryWithInstall, false)) { + LOGE("SetDeliveryWithInstall failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_DEVICE_TYPES); + if (it != parameterMap_.end()) { + std::list originDeviceTypes; + configJson.GetFaDeviceTypes(originDeviceTypes); + modifyMap[DEVICE_TYPES] = Utils::ArrayToString(originDeviceTypes); + std::list deviceTypes; + Utils::StringToArray(parameterMap_.at(Constants::PARAM_DEVICE_TYPES), deviceTypes); + if (!configJson.SetDeviceTypes(deviceTypes, false)) { + LOGE("SetDeviceTypes failed"); + return false; + } + } + + configJson.GetBundleName(bundleName); + configJson.GetFaModuleName(moduleName); + modifyMap[MODULE_NAME] = moduleName; + if (!JsonUtils::StrToFile(configJson.ToString(), configJsonPath)) { + LOGE("Parse and modify config.json failed, writeJson failed."); + return false; + } + return true; +} + +bool GeneralNormalize::ModifyPackInfo(const std::string &packInfoPath) +{ + PackInfo packInfo; + if (!packInfo.ParseFromFile(packInfoPath)) { + LOGW("Parse and modify packInfo failed, json format invalid."); + return false; + } + + auto it = parameterMap_.find(Constants::PARAM_VERSION_CODE); + if (it != parameterMap_.end()) { + int32_t versionCode = std::stoi(parameterMap_.at(Constants::PARAM_VERSION_CODE)); + if (!packInfo.SetVersionCode(versionCode)) { + LOGW("SetVersionCode packInfo failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_VERSION_NAME); + if (it != parameterMap_.end()) { + std::string versionName = parameterMap_.at(Constants::PARAM_VERSION_NAME); + if (!packInfo.SetVersionName(versionName)) { + LOGW("SetVersionName packInfo failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_BUNDLE_NAME); + if (it != parameterMap_.end()) { + std::string bundleName = parameterMap_.at(Constants::PARAM_BUNDLE_NAME); + if (!packInfo.SetBundleName(bundleName)) { + LOGW("SetBundleName failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_MIN_COMPATIBLE_VERSION_CODE); + if (it != parameterMap_.end()) { + int32_t minCompatibleVersionCode = std::stoi(parameterMap_.at(Constants::PARAM_MIN_COMPATIBLE_VERSION_CODE)); + if (!packInfo.SetMinCompatibleVersionCode(minCompatibleVersionCode)) { + LOGW("SetMinCompatibleVersionCode failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_MIN_API_VERSION); + if (it != parameterMap_.end()) { + int32_t minAPIVersion = std::stoi(parameterMap_.at(Constants::PARAM_MIN_API_VERSION)); + if (!packInfo.SetMinAPIVersion(minAPIVersion)) { + LOGW("SetMinAPIVersion failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_TARGET_API_VERSION); + if (it != parameterMap_.end()) { + int32_t targetAPIVersion = std::stoi(parameterMap_.at(Constants::PARAM_TARGET_API_VERSION)); + if (!packInfo.SetTargetAPIVersion(targetAPIVersion)) { + LOGW("SetTargetAPIVersion failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_API_RELEASE_TYPE); + if (it != parameterMap_.end()) { + std::string apiReleaseType = parameterMap_.at(Constants::PARAM_API_RELEASE_TYPE); + if (!packInfo.SetApiReleaseType(apiReleaseType)) { + LOGW("SetApiReleaseType failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_BUNDLE_TYPE); + if (it != parameterMap_.end()) { + std::string bundleType = parameterMap_.at(Constants::PARAM_BUNDLE_TYPE); + if (!packInfo.SetBundleType(bundleType)) { + LOGW("SetBundleType failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_INSTALLATION_FREE); + if (it != parameterMap_.end()) { + bool installationFree = Utils::StringToBool(parameterMap_.at(Constants::PARAM_INSTALLATION_FREE)); + if (!packInfo.SetInstallationFree(installationFree)) { + LOGW("SetInstallationFree failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_DELIVERY_WITH_INSTALL); + if (it != parameterMap_.end()) { + bool deliveryWithInstall = Utils::StringToBool(parameterMap_.at(Constants::PARAM_DELIVERY_WITH_INSTALL)); + if (!packInfo.SetDeliveryWithInstall(deliveryWithInstall)) { + LOGW("SetDeliveryWithInstall failed"); + return false; + } + } + + it = parameterMap_.find(Constants::PARAM_DEVICE_TYPES); + if (it != parameterMap_.end()) { + std::list deviceTypes; + Utils::StringToArray(parameterMap_.at(Constants::PARAM_DEVICE_TYPES), deviceTypes); + if (!packInfo.SetDeviceTypes(deviceTypes)) { + LOGW("SetDeviceTypes failed"); + return false; + } + } + + if (!JsonUtils::StrToFile(packInfo.ToString(), packInfoPath)) { + LOGW("Parse and modify packInfo failed, writeJson failed."); + return false; + } + return true; +} + +bool GeneralNormalize::CompressDirToHap(const std::string &sourceDir, const std::string &zipFilePath) +{ + std::map parameterMap; + std::string resultReceiver = ""; + parameterMap[Constants::PARAM_OUT_PATH] = zipFilePath; + std::unique_ptr packager = nullptr; + for (const auto& entry : fs::directory_iterator(fs::path(sourceDir))) { + std::string fileName = entry.path().filename().string(); + std::string filePath = entry.path().string(); + if (fileName == Constants::ETS_PATH) { + parameterMap[Constants::PARAM_ETS_PATH] = filePath; + } else if (fileName == Constants::HNP_PATH) { + parameterMap[Constants::PARAM_HNP_PATH] = filePath; + } else if (fileName == Constants::LIB_PATH) { + parameterMap[Constants::PARAM_LIB_PATH] = filePath; + } else if (fileName == Constants::AN_PATH) { + parameterMap[Constants::PARAM_AN_PATH] = filePath; + } else if (fileName == Constants::AP_PATH) { + parameterMap[Constants::PARAM_AP_PATH] = filePath; + } else if (fileName == Constants::RESOURCES_PATH) { + parameterMap[Constants::PARAM_RESOURCES_PATH] = filePath; + } else if (fileName == Constants::JS_PATH) { + parameterMap[Constants::PARAM_JS_PATH] = filePath; + } else if (fileName == Constants::ASSETS_PATH) { + parameterMap[Constants::PARAM_ASSETS_PATH] = filePath; + } else if (fileName == Constants::SO_DIR) { + parameterMap[Constants::PARAM_MAPLE_SO_DIR] = filePath; + } else if (fileName == Constants::SHARED_LIBS_DIR) { + parameterMap[Constants::PARAM_SHAREDLIBS_PATH] = filePath; + } else if (fileName == Constants::CONFIG_JSON) { + parameterMap[Constants::PARAM_JSON_PATH] = filePath; + } else if (fileName == Constants::MODULE_JSON) { + parameterMap[Constants::PARAM_JSON_PATH] = filePath; + } else if (fileName == Constants::RESOURCES_INDEX) { + parameterMap[Constants::PARAM_INDEX_PATH] = filePath; + } else if (fileName == Constants::PACK_INFO) { + parameterMap[Constants::PARAM_PACK_INFO_PATH] = filePath; + } else if (fileName == Constants::RPCID_SC) { + parameterMap[Constants::PARAM_RPCID_PATH] = filePath; + } + } + if (Utils::EndsWith(zipFilePath, Constants::HAP_SUFFIX)) { + packager = std::make_unique(parameterMap, resultReceiver); + } else if (Utils::EndsWith(zipFilePath, Constants::HSP_SUFFIX)) { + packager = std::make_unique(parameterMap, resultReceiver); + } + + if (packager == nullptr || packager->PreProcess() != ERR_OK || packager->Process() != ERR_OK) { + return false; + } + return true; +} + + +bool GeneralNormalize::ProcessJsonFiles(const std::string &tempPath, + std::list> &modifyMapList, std::string &bundleName, std::string &moduleName) +{ + std::map modifyMap; + std::string moduleJsonPath = tempPath + Constants::LINUX_FILE_SEPARATOR + Constants::MODULE_JSON; + std::string configJsonPath = tempPath + Constants::LINUX_FILE_SEPARATOR + Constants::CONFIG_JSON; + std::string packInfoPath = tempPath + Constants::LINUX_FILE_SEPARATOR + Constants::PACK_INFO; + + bool isModuleFileExists = fs::exists(moduleJsonPath); + bool isConfigFileExists = fs::exists(configJsonPath); + bool isPackInfoFileExists = fs::exists(packInfoPath); + if (isModuleFileExists == isConfigFileExists) { + LOGE("GeneralNormalize failed, invalid hap structure."); + return false; + } + + bool modifyJsonSuccess = false; + if (isModuleFileExists) { + modifyJsonSuccess = ModifyModuleJson(moduleJsonPath, modifyMap, bundleName, moduleName); + } else { + modifyJsonSuccess = ModifyConfigJson(configJsonPath, modifyMap, bundleName, moduleName); + } + + if (!modifyJsonSuccess) { + modifyMapList.push_back(modifyMap); + return false; + } + + if (isPackInfoFileExists) { + if (!ModifyPackInfo(packInfoPath)) { + modifyMapList.push_back(modifyMap); + return false; + } + } + modifyMapList.push_back(modifyMap); + return true; +} + +int32_t GeneralNormalize::Process() +{ + std::string outPath = parameterMap_.at(Constants::PARAM_OUT_PATH); + std::string tempPath = outPath + Constants::LINUX_FILE_SEPARATOR + Constants::COMPRESSOR_GENERALNORMALIZE_TEMP_DIR + + Utils::GenerateUUID(); + std::list> modifyMapList; + bool isSuccess = true; + std::string bundleName; + std::string moduleName; + for (const std::string& path : hspOrhapList_) { + ZipUtils::Unzip(path, tempPath); + if (!ProcessJsonFiles(tempPath, modifyMapList, bundleName, moduleName)) { + Utils::ForceRemoveDirectory(tempPath); + isSuccess = false; + break; + } + if (!CompressDirToHap(tempPath, + outPath + Constants::LINUX_FILE_SEPARATOR + fs::path(path).filename().string())) { + Utils::ForceRemoveDirectory(tempPath); + isSuccess = false; + break; + } + Utils::ForceRemoveDirectory(tempPath); + } + if (!isSuccess) { + LOGE("GeneralNormalize failed, bundleName: %s, moduleName: %s", bundleName.c_str(), moduleName.c_str()); + Utils::RemoveAllFilesInDirectory(outPath); + return ERR_INVALID_VALUE; + } + if (!JsonUtils::StrToFile(ConvertMapListToString(modifyMapList), outPath + + Constants::LINUX_FILE_SEPARATOR + Constants::GENERAL_RECORD)) { + LOGE("WriteVersionRecord failed."); + return ERR_INVALID_VALUE; + } + return ERR_OK; +} + +std::string GeneralNormalize::ConvertMapListToString(const std::list>& + modifyMapList) +{ + std::unique_ptr jArray = PtJson::CreateArray(); + for (const auto& map : modifyMapList) { + std::unique_ptr jMap = PtJson::CreateObject(); + for (const auto& pair : map) { + if (!jMap->Add(pair.first.c_str(), pair.second.c_str())) { + return ""; + } + } + jArray->Push(jMap); + } + return jArray->Stringify(); +} + +int32_t GeneralNormalize::PostProcess() +{ + return ERR_OK; +} +} // namespace AppPackingTool +} // namespace OHOS \ No newline at end of file diff --git a/packing_tool/frameworks/src/json/module_json.cpp b/packing_tool/frameworks/src/json/module_json.cpp index ce994d913d4daa2c87493176f32e28c3e76043f3..f08ac2971661513df06f0e42499c7597cf5a8f19 100644 --- a/packing_tool/frameworks/src/json/module_json.cpp +++ b/packing_tool/frameworks/src/json/module_json.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -36,6 +36,7 @@ const std::string API_RELEASE_TYPE = "apiReleaseType"; const std::string DEBUG = "debug"; const std::string COMPATIBLE = "compatible"; const std::string RELEASE_TYPE = "releaseType"; +const std::string DELIVERY_WITH_INSTALL = "deliveryWithInstall"; const std::string TARGET = "target"; const std::string VERSION = "version"; const std::string CODE = "code"; @@ -242,8 +243,13 @@ bool ModuleJson::GetApiVersionObject(std::unique_ptr& apiVersionObj) return false; } if (!appObj->Contains(API_VERSION.c_str())) { - LOGE("App node has no %s node!", API_VERSION.c_str()); - return false; + cJSON *apiVersion = cJSON_CreateObject(); + apiVersionObj = std::make_unique(apiVersion); + if (appObj->Add(API_VERSION.c_str(), apiVersionObj)) { + LOGE("App node add %s node failed!", API_VERSION.c_str()); + return false; + } + return true; } if (appObj->GetObject(API_VERSION.c_str(), &apiVersionObj) != Result::SUCCESS) { LOGE("App node get %s node failed!", API_VERSION.c_str()); @@ -1405,5 +1411,241 @@ bool ModuleJson::SetBuildHash(const std::string& buildHash) } return true; } + +bool ModuleJson::SetVersionCode(const int32_t& versionCode, const bool& isStage) +{ + if (isStage) { + if (!SetStageVersionCode(versionCode)) { + LOGE("SetStageVersionCode failed!"); + return false; + } + } else { + if (!SetFaVersionCode(versionCode)) { + LOGE("SetFaVersionCode failed!"); + return false; + } + } + return true; +} + +bool ModuleJson::SetVersionName(const std::string& versionName, const bool& isStage) +{ + if (isStage) { + if (!SetStageVersionName(versionName)) { + LOGE("SetStageVersionName failed!"); + return false; + } + } else { + if (!SetFaVersionName(versionName)) { + LOGE("SetFaVersionName failed!"); + return false; + } + } + return true; +} + +bool ModuleJson::SetBundleName(const std::string& bundleName, const bool& isStage) +{ + if (isStage) { + if (!SetStageBundleName(bundleName)) { + LOGE("SetStageBundleName failed!"); + return false; + } + } else { + if (!SetFaBundleName(bundleName)) { + LOGE("SetFaBundleName failed!"); + return false; + } + } + return true; +} + +bool ModuleJson::SetMinCompatibleVersionCode(const int32_t& minCompatibleVersionCode, const bool& isStage) +{ + if (isStage) { + if (!SetStageMinCompatibleVersionCode(minCompatibleVersionCode)) { + LOGE("SetStageMinCompatibleVersionCode failed!"); + return false; + } + } else { + if (!SetFaMinCompatibleVersionCode(minCompatibleVersionCode)) { + LOGE("SetFaMinCompatibleVersionCode failed!"); + return false; + } + } + return true; +} + +bool ModuleJson::SetMinAPIVersion(const int32_t& minAPIVersion, const bool& isStage) +{ + if (isStage) { + if (!SetStageMinAPIVersion(minAPIVersion)) { + LOGE("SetStageMinAPIVersion failed!"); + return false; + } + } else { + if (!SetFaMinAPIVersion(minAPIVersion)) { + LOGE("SetFaMinAPIVersion failed!"); + return false; + } + } + return true; +} + +bool ModuleJson::SetTargetAPIVersion(const int32_t& targetAPIVersion, const bool& isStage) +{ + if (isStage) { + if (!SetStageTargetAPIVersion(targetAPIVersion)) { + LOGE("SetStageTargetAPIVersion failed!"); + return false; + } + } else { + if (!SetFaTargetAPIVersion(targetAPIVersion)) { + LOGE("SetFaTargetAPIVersion failed!"); + return false; + } + } + return true; +} + +bool ModuleJson::SetApiReleaseType(const std::string& apiReleaseType, const bool& isStage) +{ + if (isStage) { + if (!SetStageApiReleaseType(apiReleaseType)) { + LOGE("SetStageApiReleaseType failed!"); + return false; + } + } else { + if (!SetFaApiReleaseType(apiReleaseType)) { + LOGE("SetFaApiReleaseType failed!"); + return false; + } + } + return true; +} + +bool ModuleJson::SetBundleType(const std::string& bundleType, const bool& isStage) +{ + if (isStage) { + if (!SetStageBundleType(bundleType)) { + LOGE("SetStageBundleType failed!"); + return false; + } + } else { + if (!SetFaBundleType(bundleType)) { + LOGE("SetFaBundleType failed!"); + return false; + } + } + return true; +} + +bool ModuleJson::SetInstallationFree(const bool& installationFree, const bool& isStage) +{ + if (isStage) { + if (!SetStageInstallationFree(installationFree)) { + LOGE("SetStageInstallationFree failed!"); + return false; + } + } else { + if (!SetFaInstallationFree(installationFree)) { + LOGE("SetFaInstallationFree failed!"); + return false; + } + } + return true; +} + +bool ModuleJson::SetDeliveryWithInstall(const bool& deliveryWithInstall, const bool& isStage) +{ + if (isStage) { + if (!SetStageDeliveryWithInstall(deliveryWithInstall)) { + LOGE("SetStageDeliveryWithInstall failed!"); + return false; + } + } else { + if (!SetFaDeliveryWithInstall(deliveryWithInstall)) { + LOGE("SetFaDeliveryWithInstall failed!"); + return false; + } + } + return true; +} + +bool ModuleJson::SetDeviceTypes(const std::list& deviceTypes, const bool& isStage) +{ + if (isStage) { + if (!SetStageDeviceTypes(deviceTypes)) { + LOGE("SetStageDeviceTypen failed!"); + return false; + } + } else { + if (!SetFaDeviceTypes(deviceTypes)) { + LOGE("SetFaDeviceTypen failed!"); + return false; + } + } + return true; +} + +bool ModuleJson::GetMinApiVersion(int32_t& minAPIVersion) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + LOGE("GetAppObject failed!"); + return false; + } + if (!appObj) { + LOGE("App node is null!"); + return false; + } + if (appObj->Contains(MIN_API_VERSION.c_str())) { + if (appObj->GetInt(MIN_API_VERSION.c_str(), &minAPIVersion) != Result::SUCCESS) { + LOGE("App node get %s failed!", MIN_API_VERSION.c_str()); + return false; + } + } + return true; +} + +bool ModuleJson::GetTargetApiVersion(int32_t& targetAPIVersion) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + LOGE("GetAppObject failed!"); + return false; + } + if (!appObj) { + LOGE("App node is null!"); + return false; + } + if (appObj->Contains(TARGET_API_VERSION.c_str())) { + if (appObj->GetInt(TARGET_API_VERSION.c_str(), &targetAPIVersion) != Result::SUCCESS) { + LOGE("App node get %s failed!", TARGET_API_VERSION.c_str()); + return false; + } + } + return true; +} + +bool ModuleJson::GetDeliveryWithInstall(bool& deliveryWithInstall) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + LOGE("GetModuleObject failed!"); + return false; + } + if (!moduleObj) { + LOGE("Module node is null!"); + return false; + } + if (moduleObj->Contains(DELIVERY_WITH_INSTALL.c_str())) { + if (moduleObj->GetBool(DELIVERY_WITH_INSTALL.c_str(), &deliveryWithInstall) != Result::SUCCESS) { + LOGE("Module node get %s failed!", DELIVERY_WITH_INSTALL.c_str()); + return false; + } + } + return true; +} } // namespace AppPackingTool } // namespace OHOS diff --git a/packing_tool/frameworks/src/json/module_json_fa.cpp b/packing_tool/frameworks/src/json/module_json_fa.cpp index aa4a3acd2cae43a2826fa19a7f9ac9fdfcbdb512..1f7123818b70a43f2907318996ff17f4ba86f75e 100644 --- a/packing_tool/frameworks/src/json/module_json_fa.cpp +++ b/packing_tool/frameworks/src/json/module_json_fa.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -36,6 +36,7 @@ const std::string API_RELEASE_TYPE = "apiReleaseType"; const std::string DEBUG = "debug"; const std::string COMPATIBLE = "compatible"; const std::string RELEASE_TYPE = "releaseType"; +const std::string DELIVERY_WITH_INSTALL = "deliveryWithInstall"; const std::string TARGET = "target"; const std::string VERSION = "version"; const std::string CODE = "code"; @@ -221,6 +222,29 @@ bool ModuleJson::GetFaInstallationFreeByDistroObj(std::unique_ptr& distr return true; } +bool ModuleJson::GetFaDeliveryWithInstall(bool& deliveryWithInstall) +{ + std::unique_ptr distroObj; + if (!GetDistroObject(distroObj)) { + LOGE("GetDistroObject failed!"); + return false; + } + if (!distroObj) { + LOGE("Distro node is null!"); + return false; + } + if (distroObj->Contains(DELIVERY_WITH_INSTALL.c_str())) { + if (distroObj->GetBool(DELIVERY_WITH_INSTALL.c_str(), &deliveryWithInstall) != Result::SUCCESS) { + LOGE("Distro node get %s failed!", DELIVERY_WITH_INSTALL.c_str()); + return false; + } + } else { + LOGE("Distro node has no %s node!", DELIVERY_WITH_INSTALL.c_str()); + return false; + } + return true; +} + bool ModuleJson::GetFaBundleType(std::string& bundleType) { bool installationFree = false; @@ -814,5 +838,194 @@ bool ModuleJson::SetFaHapVerifyInfoByModuleObj(std::unique_ptr& moduleOb hapVerifyInfo.SetInstallationFree(installationFree); return true; } + +bool ModuleJson::SetFaBundleName(const std::string& bundleName) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + LOGE("GetAppObject failed!"); + return false; + } + if (!appObj->Contains(BUNDLE_NAME.c_str())) { + if (!appObj->Add(BUNDLE_NAME.c_str(), bundleName.c_str())) { + LOGE("App node add %s failed!", BUNDLE_NAME.c_str()); + return false; + } + return true; + } + if (appObj->SetString(BUNDLE_NAME.c_str(), bundleName) != Result::SUCCESS) { + LOGE("App node set %s failed!", BUNDLE_NAME.c_str()); + return false; + } + return true; +} + +bool ModuleJson::SetFaMinCompatibleVersionCode(const int32_t& minCompatibleVersionCode) +{ + std::unique_ptr versionObj; + if (!GetVersionObject(versionObj)) { + LOGE("GetVersionObject failed!"); + return false; + } + if (!versionObj->Contains(MIN_COMPATIBLE_VERSION_CODE.c_str())) { + if (!versionObj->Add(MIN_COMPATIBLE_VERSION_CODE.c_str(), minCompatibleVersionCode)) { + LOGE("Version node add %s failed!", MIN_COMPATIBLE_VERSION_CODE.c_str()); + return false; + } + return true; + } + if (versionObj->SetInt(MIN_COMPATIBLE_VERSION_CODE.c_str(), minCompatibleVersionCode) != Result::SUCCESS) { + LOGE("Version node set %s failed!", MIN_COMPATIBLE_VERSION_CODE.c_str()); + return false; + } + return true; +} + +bool ModuleJson::SetFaMinAPIVersion(const int32_t& minAPIVersion) +{ + std::unique_ptr apiVersionObj; + if (!GetApiVersionObject(apiVersionObj)) { + LOGE("GetAppObject failed!"); + return false; + } + if (!apiVersionObj->Contains(COMPATIBLE.c_str())) { + if (!apiVersionObj->Add(COMPATIBLE.c_str(), minAPIVersion)) { + LOGE("ApiVersion node add %s failed!", COMPATIBLE.c_str()); + return false; + } + return true; + } + if (apiVersionObj->SetInt(COMPATIBLE.c_str(), minAPIVersion) != Result::SUCCESS) { + LOGE("ApiVersion node set %s failed!", COMPATIBLE.c_str()); + return false; + } + return true; +} + +bool ModuleJson::SetFaTargetAPIVersion(const int32_t& targetAPIVersion) +{ + std::unique_ptr apiVersionObj; + if (!GetApiVersionObject(apiVersionObj)) { + LOGE("GetApiVersionObject failed!"); + return false; + } + if (!apiVersionObj->Contains(TARGET.c_str())) { + if (!apiVersionObj->Add(TARGET.c_str(), targetAPIVersion)) { + LOGE("ApiVersion node add %s failed!", TARGET.c_str()); + return false; + } + return true; + } + if (apiVersionObj->SetInt(TARGET.c_str(), targetAPIVersion) != Result::SUCCESS) { + LOGE("ApiVersion node set %s failed!", TARGET.c_str()); + return false; + } + return true; +} + +bool ModuleJson::SetFaApiReleaseType(const std::string& apiReleaseType) +{ + std::unique_ptr apiVersionObj; + if (!GetApiVersionObject(apiVersionObj)) { + LOGE("GetApiVersionObject failed!"); + return false; + } + if (!apiVersionObj->Contains(RELEASE_TYPE.c_str())) { + if (!apiVersionObj->Add(RELEASE_TYPE.c_str(), apiReleaseType.c_str())) { + LOGE("ApiVersion node add %s failed!", RELEASE_TYPE.c_str()); + return false; + } + return true; + } + if (apiVersionObj->SetString(RELEASE_TYPE.c_str(), apiReleaseType) != Result::SUCCESS) { + LOGE("ApiVersion node set %s failed!", RELEASE_TYPE.c_str()); + return false; + } + return true; +} + +bool ModuleJson::SetFaBundleType(const std::string& bundleType) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + LOGE("GetAppObject failed!"); + return false; + } + if (!appObj->Contains(BUNDLE_TYPE.c_str())) { + if (!appObj->Add(BUNDLE_TYPE.c_str(), bundleType.c_str())) { + LOGE("App node add %s failed!", BUNDLE_TYPE.c_str()); + return false; + } + return true; + } + if (appObj->SetString(BUNDLE_TYPE.c_str(), bundleType) != Result::SUCCESS) { + LOGE("App node set %s failed!", BUNDLE_TYPE.c_str()); + return false; + } + return true; +} + +bool ModuleJson::SetFaInstallationFree(const bool& installationFree) +{ + std::unique_ptr distroObj; + if (!GetDistroObject(distroObj)) { + LOGE("GetDistroObject failed!"); + return false; + } + if (!distroObj->Contains(INSTALLATION_FREE.c_str())) { + if (!distroObj->Add(INSTALLATION_FREE.c_str(), installationFree)) { + LOGE("Distro node add %s failed!", INSTALLATION_FREE.c_str()); + return false; + } + return true; + } + if (distroObj->SetBool(INSTALLATION_FREE.c_str(), installationFree) != Result::SUCCESS) { + LOGE("Distro node set %s failed!", INSTALLATION_FREE.c_str()); + return false; + } + return true; +} + +bool ModuleJson::SetFaDeliveryWithInstall(const bool& deliveryWithInstall) +{ + std::unique_ptr distroObj; + if (!GetDistroObject(distroObj)) { + LOGE("GetDistroObject failed!"); + return false; + } + if (!distroObj->Contains(DELIVERY_WITH_INSTALL.c_str())) { + if (!distroObj->Add(DELIVERY_WITH_INSTALL.c_str(), deliveryWithInstall)) { + LOGE("Distro node add %s failed!", DELIVERY_WITH_INSTALL.c_str()); + return false; + } + return true; + } + if (distroObj->SetBool(DELIVERY_WITH_INSTALL.c_str(), deliveryWithInstall) != Result::SUCCESS) { + LOGE("Distro node set %s failed!", DELIVERY_WITH_INSTALL.c_str()); + return false; + } + return true; +} + +bool ModuleJson::SetFaDeviceTypes(const std::list& deviceTypes) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + LOGE("GetModuleObject failed!"); + return false; + } + if (!moduleObj->Contains(DEVICE_TYPE.c_str())) { + if (!moduleObj->Add(DEVICE_TYPE.c_str(), deviceTypes)) { + LOGE("Module node add %s failed!", DEVICE_TYPE.c_str()); + return false; + } + return true; + } + if (moduleObj->SetArray(DEVICE_TYPE.c_str(), deviceTypes) != Result::SUCCESS) { + LOGE("Module node set %s failed!", DEVICE_TYPE.c_str()); + return false; + } + return true; +} } // namespace AppPackingTool } // namespace OHOS diff --git a/packing_tool/frameworks/src/json/module_json_stage.cpp b/packing_tool/frameworks/src/json/module_json_stage.cpp index dfb25e1b57011e4dfc49f20bb20aeb39c7ce802a..c500083ff95930c3da20893c1fca68b579f7538d 100644 --- a/packing_tool/frameworks/src/json/module_json_stage.cpp +++ b/packing_tool/frameworks/src/json/module_json_stage.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -36,6 +36,7 @@ const std::string API_RELEASE_TYPE = "apiReleaseType"; const std::string DEBUG = "debug"; const std::string COMPATIBLE = "compatible"; const std::string RELEASE_TYPE = "releaseType"; +const std::string DELIVERY_WITH_INSTALL = "deliveryWithInstall"; const std::string TARGET = "target"; const std::string VERSION = "version"; const std::string CODE = "code"; @@ -123,6 +124,195 @@ bool ModuleJson::SetStageVersionName(const std::string& versionName) return true; } +bool ModuleJson::SetStageBundleName(const std::string& bundleName) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + LOGE("GetAppObject failed!"); + return false; + } + if (!appObj->Contains(BUNDLE_NAME.c_str())) { + if (!appObj->Add(BUNDLE_NAME.c_str(), bundleName.c_str())) { + LOGE("App node add %s failed!", BUNDLE_NAME.c_str()); + return false; + } + return true; + } + if (appObj->SetString(BUNDLE_NAME.c_str(), bundleName) != Result::SUCCESS) { + LOGE("App node set %s failed!", BUNDLE_NAME.c_str()); + return false; + } + return true; +} + +bool ModuleJson::SetStageMinCompatibleVersionCode(const int32_t& minCompatibleVersionCode) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + LOGE("GetAppObject failed!"); + return false; + } + if (!appObj->Contains(MIN_COMPATIBLE_VERSION_CODE.c_str())) { + if (!appObj->Add(MIN_COMPATIBLE_VERSION_CODE.c_str(), minCompatibleVersionCode)) { + LOGE("App node add %s failed!", MIN_COMPATIBLE_VERSION_CODE.c_str()); + return false; + } + return true; + } + if (appObj->SetInt(MIN_COMPATIBLE_VERSION_CODE.c_str(), minCompatibleVersionCode) != Result::SUCCESS) { + LOGE("App node set %s failed!", MIN_COMPATIBLE_VERSION_CODE.c_str()); + return false; + } + return true; +} + +bool ModuleJson::SetStageMinAPIVersion(const int32_t& minAPIVersion) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + LOGE("GetAppObject failed!"); + return false; + } + if (!appObj->Contains(MIN_API_VERSION.c_str())) { + if (!appObj->Add(MIN_API_VERSION.c_str(), minAPIVersion)) { + LOGE("App node add %s failed!", MIN_API_VERSION.c_str()); + return false; + } + return true; + } + if (appObj->SetInt(MIN_API_VERSION.c_str(), minAPIVersion) != Result::SUCCESS) { + LOGE("App node set %s failed!", MIN_API_VERSION.c_str()); + return false; + } + return true; +} + +bool ModuleJson::SetStageTargetAPIVersion(const int32_t& targetAPIVersion) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + LOGE("GetAppObject failed!"); + return false; + } + if (!appObj->Contains(TARGET_API_VERSION.c_str())) { + if (!appObj->Add(TARGET_API_VERSION.c_str(), targetAPIVersion)) { + LOGE("App node add %s failed!", TARGET_API_VERSION.c_str()); + return false; + } + return true; + } + if (appObj->SetInt(TARGET_API_VERSION.c_str(), targetAPIVersion) != Result::SUCCESS) { + LOGE("App node set %s failed!", TARGET_API_VERSION.c_str()); + return false; + } + return true; +} + +bool ModuleJson::SetStageApiReleaseType(const std::string& apiReleaseType) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + LOGE("GetAppObject failed!"); + return false; + } + if (!appObj->Contains(API_RELEASE_TYPE.c_str())) { + if (!appObj->Add(API_RELEASE_TYPE.c_str(), apiReleaseType.c_str())) { + LOGE("App node add %s failed!", API_RELEASE_TYPE.c_str()); + return false; + } + return true; + } + if (appObj->SetString(API_RELEASE_TYPE.c_str(), apiReleaseType) != Result::SUCCESS) { + LOGE("App node set %s failed!", API_RELEASE_TYPE.c_str()); + return false; + } + return true; +} + +bool ModuleJson::SetStageBundleType(const std::string& bundleType) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + LOGE("GetAppObject failed!"); + return false; + } + if (!appObj->Contains(BUNDLE_TYPE.c_str())) { + if (!appObj->Add(BUNDLE_TYPE.c_str(), bundleType.c_str())) { + LOGE("App node add %s failed!", BUNDLE_TYPE.c_str()); + return false; + } + return true; + } + if (appObj->SetString(BUNDLE_TYPE.c_str(), bundleType) != Result::SUCCESS) { + LOGE("App node set %s failed!", BUNDLE_TYPE.c_str()); + return false; + } + return true; +} + +bool ModuleJson::SetStageInstallationFree(const bool& installationFree) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + LOGE("GetModuleObject failed!"); + return false; + } + if (!moduleObj->Contains(INSTALLATION_FREE.c_str())) { + if (!moduleObj->Add(INSTALLATION_FREE.c_str(), installationFree)) { + LOGE("App node add %s failed!", INSTALLATION_FREE.c_str()); + return false; + } + return true; + } + if (moduleObj->SetBool(INSTALLATION_FREE.c_str(), installationFree) != Result::SUCCESS) { + LOGE("Module node set %s failed!", INSTALLATION_FREE.c_str()); + return false; + } + return true; +} + +bool ModuleJson::SetStageDeliveryWithInstall(const bool& deliveryWithInstall) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + LOGE("GetModuleObject failed!"); + return false; + } + if (!moduleObj->Contains(DELIVERY_WITH_INSTALL.c_str())) { + if (!moduleObj->Add(DELIVERY_WITH_INSTALL.c_str(), deliveryWithInstall)) { + LOGE("App node add %s failed!", DELIVERY_WITH_INSTALL.c_str()); + return false; + } + return true; + } + if (moduleObj->SetBool(DELIVERY_WITH_INSTALL.c_str(), deliveryWithInstall) != Result::SUCCESS) { + LOGE("Module node set %s failed!", DELIVERY_WITH_INSTALL.c_str()); + return false; + } + return true; +} + +bool ModuleJson::SetStageDeviceTypes(const std::list& deviceTypes) +{ + std::unique_ptr moduleObj; + if (!GetModuleObject(moduleObj)) { + LOGE("GetModuleObject failed!"); + return false; + } + if (!moduleObj->Contains(DEVICE_TYPES.c_str())) { + if (!moduleObj->Add(DEVICE_TYPES.c_str(), deviceTypes)) { + LOGE("App node add %s failed!", DEVICE_TYPES.c_str()); + return false; + } + return true; + } + if (moduleObj->SetArray(DEVICE_TYPES.c_str(), deviceTypes) != Result::SUCCESS) { + LOGE("Module node set %s failed!", DEVICE_TYPES.c_str()); + return false; + } + return true; +} + bool ModuleJson::GetStageVersion(Version& version) { std::unique_ptr appObj; diff --git a/packing_tool/frameworks/src/json/pack_info.cpp b/packing_tool/frameworks/src/json/pack_info.cpp index d15db147a0583fc542d04368f5774906a468c3d1..9cebaccfdf139ae71d09727036d5c587ebefd760 100644 --- a/packing_tool/frameworks/src/json/pack_info.cpp +++ b/packing_tool/frameworks/src/json/pack_info.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -40,6 +40,18 @@ const std::string FORMS = "forms"; const std::string DEFAULT_DIMENSION = "defaultDimension"; const std::string SUPPORT_DIMENSIONS = "supportDimensions"; const char ASTERISK = '*'; +const std::string MIN_COMPATIBLE_VERSION_CODE = "minCompatibleVersionCode"; +const std::string MIN_API_VERSION = "minAPIVersion"; +const std::string TARGET_API_VERSION = "targetAPIVersion"; +const std::string API_RELEASE_TYPE = "apiReleaseType"; +const std::string INSTALLATION_FREE = "installationFree"; +const std::string DELIVERY_WITH_INSTALL = "deliveryWithInstall"; +const std::string COMPILE_SDK_TYPE = "compileSdkType"; +const std::string DEVICE_TYPE = "deviceType"; +const std::string COMPATIBLE = "compatible"; +const std::string RELEASE_TYPE = "releaseType"; +const std::string TARGET = "target"; +const std::string API_VERSION = "apiVersion"; } bool PackInfo::ParseFromString(const std::string& jsonString) @@ -294,6 +306,29 @@ bool PackInfo::GetDistroObjectByModuleObj(const std::unique_ptr& moduleO return true; } +bool PackInfo::GetApiVersionObjectByModuleObj(const std::unique_ptr& moduleObj, + std::unique_ptr& apiVersionObj) +{ + if (!moduleObj) { + LOGE("Module node is null!"); + return false; + } + if (!moduleObj->Contains(API_VERSION.c_str())) { + cJSON *apiVersion = cJSON_CreateObject(); + apiVersionObj = std::make_unique(apiVersion); + if (!moduleObj->Add(API_VERSION.c_str(), apiVersionObj)) { + LOGE("Module node add %s node failed!", API_VERSION.c_str()); + return false; + } + return true; + } + if (moduleObj->GetObject(API_VERSION.c_str(), &apiVersionObj) != Result::SUCCESS) { + LOGE("Module node get %s node failed!", API_VERSION.c_str()); + return false; + } + return true; +} + bool PackInfo::GetExtensionAbilitiesObj(int32_t moduleIndex, std::unique_ptr& extensionAbilitiesObj) { std::unique_ptr modulesObj; @@ -657,5 +692,294 @@ bool PackInfo::GetPackageNamesByPackagesObj(const std::unique_ptr& packa } return true; } + +bool PackInfo::SetMinCompatibleVersionCode(const int32_t& minCompatibleVersionCode) +{ + std::unique_ptr versionObj; + if (!GetVersionObject(versionObj)) { + LOGE("GetVersionObject failed!"); + return false; + } + if (!versionObj->Contains(MIN_COMPATIBLE_VERSION_CODE.c_str())) { + if (!versionObj->Add(MIN_COMPATIBLE_VERSION_CODE.c_str(), minCompatibleVersionCode)) { + LOGE("App node add %s failed!", MIN_COMPATIBLE_VERSION_CODE.c_str()); + return false; + } + return true; + } + if (versionObj->SetInt(MIN_COMPATIBLE_VERSION_CODE.c_str(), minCompatibleVersionCode) != Result::SUCCESS) { + LOGE("Version node set %s failed!", CODE.c_str()); + return false; + } + return true; +} + +bool PackInfo::SetMinAPIVersion(const int32_t& minAPIVersion) +{ + std::unique_ptr modulesObj; + if (!GetModulesObject(modulesObj)) { + LOGE("GetModulesObject failed!"); + return false; + } + int32_t modulesSize = modulesObj->GetSize(); + for (int i = 0; i < modulesSize; i++) { + std::unique_ptr moduleObj = modulesObj->Get(i); + if (moduleObj == nullptr) { + LOGE("GetModuleObject failed!"); + return false; + } + std::unique_ptr apiVersionObj; + if (!GetApiVersionObjectByModuleObj(moduleObj, apiVersionObj)) { + LOGE("GetApiVersionObjectByModuleObj failed!"); + return false; + } + if (!apiVersionObj->Contains(COMPATIBLE.c_str())) { + if (!apiVersionObj->Add(COMPATIBLE.c_str(), minAPIVersion)) { + LOGE("App node add %s failed!", COMPATIBLE.c_str()); + return false; + } + return true; + } + if (apiVersionObj->SetInt(COMPATIBLE.c_str(), minAPIVersion) != Result::SUCCESS) { + LOGE("Module node set %s failed!", COMPATIBLE.c_str()); + return false; + } + } + return true; +} + +bool PackInfo::SetTargetAPIVersion(const int32_t& targetAPIVersion) +{ + std::unique_ptr modulesObj; + if (!GetModulesObject(modulesObj)) { + LOGE("GetModulesObject failed!"); + return false; + } + int32_t modulesSize = modulesObj->GetSize(); + for (int i = 0; i < modulesSize; i++) { + std::unique_ptr moduleObj = modulesObj->Get(i); + if (moduleObj == nullptr) { + LOGE("GetModuleObject failed!"); + return false; + } + std::unique_ptr apiVersionObj; + if (!GetApiVersionObjectByModuleObj(moduleObj, apiVersionObj)) { + LOGE("GetApiVersionObjectByModuleObj failed!"); + return false; + } + if (!apiVersionObj->Contains(TARGET.c_str())) { + if (!apiVersionObj->Add(TARGET.c_str(), targetAPIVersion)) { + LOGE("App node add %s failed!", TARGET.c_str()); + return false; + } + return true; + } + if (apiVersionObj->SetInt(TARGET.c_str(), targetAPIVersion) != Result::SUCCESS) { + LOGE("Module node set %s failed!", TARGET.c_str()); + return false; + } + } + return true; +} + +bool PackInfo::SetApiReleaseType(const std::string& apiReleaseType) +{ + std::unique_ptr modulesObj; + if (!GetModulesObject(modulesObj)) { + LOGE("GetModulesObject failed!"); + return false; + } + int32_t modulesSize = modulesObj->GetSize(); + for (int i = 0; i < modulesSize; i++) { + std::unique_ptr moduleObj = modulesObj->Get(i); + if (moduleObj == nullptr) { + LOGE("GetModuleObject failed!"); + return false; + } + std::unique_ptr apiVersionObj; + if (!GetApiVersionObjectByModuleObj(moduleObj, apiVersionObj)) { + LOGE("GetApiVersionObjectByModuleObj failed!"); + return false; + } + if (!apiVersionObj->Contains(RELEASE_TYPE.c_str())) { + if (!apiVersionObj->Add(RELEASE_TYPE.c_str(), apiReleaseType.c_str())) { + LOGE("App node add %s failed!", RELEASE_TYPE.c_str()); + return false; + } + return true; + } + if (apiVersionObj->SetString(RELEASE_TYPE.c_str(), apiReleaseType) != Result::SUCCESS) { + LOGE("Module node set %s failed!", RELEASE_TYPE.c_str()); + return false; + } + } + return true; +} + +bool PackInfo::SetBundleType(const std::string& bundleType) +{ + std::unique_ptr appObj; + if (!GetAppObject(appObj)) { + LOGE("GetAppObject failed!"); + return false; + } + if (!appObj->Contains(BUNDLE_TYPE.c_str())) { + if (!appObj->Add(BUNDLE_TYPE.c_str(), bundleType.c_str())) { + LOGE("App node add %s failed!", BUNDLE_TYPE.c_str()); + return false; + } + return true; + } + if (appObj->SetString(BUNDLE_TYPE.c_str(), bundleType) != Result::SUCCESS) { + LOGE("App node set %s failed!", BUNDLE_TYPE.c_str()); + return false; + } + return true; +} + +bool PackInfo::SetInstallationFree(const bool& installationFree) +{ + std::unique_ptr modulesObj; + if (!GetModulesObject(modulesObj)) { + LOGE("GetModulesObject failed!"); + return false; + } + int32_t modulesSize = modulesObj->GetSize(); + for (int i = 0; i < modulesSize; i++) { + std::unique_ptr moduleObj = modulesObj->Get(i); + if (moduleObj == nullptr) { + LOGE("GetModuleObject failed!"); + return false; + } + std::unique_ptr distroObj; + if (!GetDistroObject(i, distroObj)) { + LOGE("GetDistroObject failed!"); + return false; + } + if (!distroObj->Contains(INSTALLATION_FREE.c_str())) { + if (!distroObj->Add(INSTALLATION_FREE.c_str(), installationFree)) { + LOGE("App node add %s failed!", INSTALLATION_FREE.c_str()); + return false; + } + return true; + } + if (distroObj->SetBool(INSTALLATION_FREE.c_str(), installationFree) != Result::SUCCESS) { + LOGE("Module node set %s failed!", INSTALLATION_FREE.c_str()); + return false; + } + } + return true; +} + +bool PackInfo::SetDeliveryWithInstall(const bool& deliveryWithInstall) +{ + std::unique_ptr modulesObj; + if (!GetModulesObject(modulesObj)) { + LOGE("GetModulesObject failed!"); + return false; + } + int32_t modulesSize = modulesObj->GetSize(); + for (int i = 0; i < modulesSize; i++) { + std::unique_ptr moduleObj = modulesObj->Get(i); + if (moduleObj == nullptr) { + LOGE("GetModuleObject failed!"); + return false; + } + std::unique_ptr distroObj; + if (!GetDistroObject(i, distroObj)) { + LOGE("GetDistroObject failed!"); + return false; + } + if (!distroObj->Contains(DELIVERY_WITH_INSTALL.c_str())) { + if (!distroObj->Add(DELIVERY_WITH_INSTALL.c_str(), deliveryWithInstall)) { + LOGE("App node add %s failed!", DELIVERY_WITH_INSTALL.c_str()); + return false; + } + return true; + } + if (distroObj->SetBool(DELIVERY_WITH_INSTALL.c_str(), deliveryWithInstall) != Result::SUCCESS) { + LOGE("Module node set %s failed!", DELIVERY_WITH_INSTALL.c_str()); + return false; + } + } + std::unique_ptr packagesObj; + if (!GetPackagesObject(packagesObj)) { + LOGE("GetModuleObject failed!"); + return false; + } + int32_t packagesSize = packagesObj->GetSize(); + for (int i = 0; i < packagesSize; i++) { + std::unique_ptr packageObj = packagesObj->Get(i); + if (packageObj == nullptr) { + LOGE("GetModuleObject failed!"); + return false; + } + if (!packageObj->Contains(DELIVERY_WITH_INSTALL.c_str())) { + if (!packageObj->Add(DELIVERY_WITH_INSTALL.c_str(), deliveryWithInstall)) { + LOGE("App node add %s failed!", DELIVERY_WITH_INSTALL.c_str()); + return false; + } + return true; + } + if (packageObj->SetBool(DELIVERY_WITH_INSTALL.c_str(), deliveryWithInstall) != Result::SUCCESS) { + LOGE("Module node set %s failed!", DELIVERY_WITH_INSTALL.c_str()); + return false; + } + } + return true; +} + +bool PackInfo::SetDeviceTypes(const std::list& deviceTypes) +{ + std::unique_ptr modulesObj; + if (!GetModulesObject(modulesObj)) { + LOGE("GetModuleObject failed!"); + return false; + } + int32_t modulesSize = modulesObj->GetSize(); + for (int i = 0; i < modulesSize; i++) { + std::unique_ptr moduleObj = modulesObj->Get(i); + if (moduleObj == nullptr) { + LOGE("GetModuleObject failed!"); + return false; + } + if (!moduleObj->Contains(DEVICE_TYPE.c_str())) { + if (!moduleObj->Add(DEVICE_TYPE.c_str(), deviceTypes)) { + LOGE("App node add %s failed!", DEVICE_TYPE.c_str()); + return false; + } + return true; + } + if (moduleObj->SetArray(DEVICE_TYPE.c_str(), deviceTypes) != Result::SUCCESS) { + LOGE("Module node set %s failed!", DEVICE_TYPE.c_str()); + return false; + } + } + std::unique_ptr packagesObj; + if (!GetPackagesObject(packagesObj)) { + LOGE("GetModuleObject failed!"); + return false; + } + int32_t packagesSize = packagesObj->GetSize(); + for (int i = 0; i < packagesSize; i++) { + std::unique_ptr packageObj = packagesObj->Get(i); + if (packageObj == nullptr) { + LOGE("GetModuleObject failed!"); + return false; + } + if (!packageObj->Contains(DEVICE_TYPE.c_str())) { + if (!packageObj->Add(DEVICE_TYPE.c_str(), deviceTypes)) { + LOGE("App node add %s failed!", DEVICE_TYPE.c_str()); + return false; + } + return true; + } + if (packageObj->SetArray(DEVICE_TYPE.c_str(), deviceTypes) != Result::SUCCESS) { + LOGE("Module node set %s failed!", DEVICE_TYPE.c_str()); + return false; + } + } + return true; +} } // namespace AppPackingTool } // namespace OHOS diff --git a/packing_tool/frameworks/src/json/pt_json.cpp b/packing_tool/frameworks/src/json/pt_json.cpp index 9457de3ebfdcd34bbaa948ff64bd9945280168ca..a81b8b44ba3625778caa2ed2dd6443517fd0e8a1 100644 --- a/packing_tool/frameworks/src/json/pt_json.cpp +++ b/packing_tool/frameworks/src/json/pt_json.cpp @@ -156,6 +156,30 @@ bool PtJson::Add(const char *key, const std::unique_ptr &value) const return true; } +bool PtJson::Add(const char *key, const std::list& values) const +{ + if (key == nullptr || Contains(key)) { + return false; + } + + cJSON *node = cJSON_CreateArray(); + if (node == nullptr) { + return false; + } + + for (const auto &value : values) { + cJSON_AddItemToArray(node, cJSON_CreateString(value.c_str())); + } + + cJSON_bool ret = cJSON_AddItemToObject(object_, key, node); + if (ret == 0) { + cJSON_Delete(node); + return false; + } + + return true; +} + bool PtJson::Push(bool value) const { return Push(cJSON_CreateBool(value)); @@ -526,6 +550,31 @@ Result PtJson::GetArray(const char *key, std::unique_ptr *value) const return Result::SUCCESS; } +Result PtJson::SetArray(const char *key, const std::list& value) +{ + cJSON *item = cJSON_GetObjectItem(object_, key); + if (item == nullptr) { + return Result::NOT_EXIST; + } + if (cJSON_IsArray(item) == 0) { + return Result::TYPE_ERROR; + } + cJSON *newArray = cJSON_CreateArray(); + if (newArray == nullptr) { + return Result::TYPE_ERROR; + } + for (const auto& str : value) { + cJSON *strItem = cJSON_CreateString(str.c_str()); + if (strItem == nullptr) { + cJSON_Delete(newArray); + return Result::TYPE_ERROR; + } + cJSON_AddItemToArray(newArray, strItem); + } + cJSON_ReplaceItemInObject(object_, key, newArray); + return Result::SUCCESS; +} + Result PtJson::GetAny(const char *key, std::unique_ptr *value) const { cJSON *item = cJSON_GetObjectItem(object_, key); diff --git a/packing_tool/frameworks/src/shell_command.cpp b/packing_tool/frameworks/src/shell_command.cpp index 3ffdb920230e7edc7c5444cf7a061fa308b55a05..dd0835dce5d99006e4bc6849cecfe6d88b1b7fa1 100644 --- a/packing_tool/frameworks/src/shell_command.cpp +++ b/packing_tool/frameworks/src/shell_command.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -33,6 +33,7 @@ #include "package_normalize.h" #include "res_packager.h" #include "version_normalize.h" +#include "general_normalize.h" namespace OHOS { namespace AppPackingTool { @@ -190,6 +191,10 @@ std::unique_ptr ShellCommand::getPackager() std::unique_ptr packager = std::make_unique(parameterMap_, resultReceiver_); return packager; + } else if (mode == Constants::MODE_GENERAL_NORMALIZE) { + std::unique_ptr packager = + std::make_unique(parameterMap_, resultReceiver_); + return packager; } resultReceiver_.append("not support --mode: ").append(mode).append("\n"); return nullptr; diff --git a/packing_tool/frameworks/src/utils.cpp b/packing_tool/frameworks/src/utils.cpp index 87e231e1df8126cb48e9db43228f48e0337049a4..64fcaa8f259c5f26f71f28bc58266c27b3628326 100644 --- a/packing_tool/frameworks/src/utils.cpp +++ b/packing_tool/frameworks/src/utils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -30,6 +30,7 @@ #include #include "log.h" +#include "pt_json.h" namespace OHOS { namespace AppPackingTool { @@ -344,6 +345,28 @@ bool Utils::IsPositiveInteger(const std::string& str, int min, int max) return true; } +bool Utils::StringToBool(const std::string& str) +{ + std::string lowerStr = str; + std::transform(lowerStr.begin(), lowerStr.end(), lowerStr.begin(), ::tolower); + if (lowerStr == "true") { + return true; + } + return false; +} + +bool Utils::StringToArray(const std::string& str, std::list& array) +{ + array.clear(); + std::istringstream iss(str); + std::string item; + + while (std::getline(iss, item, ',')) { + array.push_back(item); + } + return true; +} + bool Utils::CheckFileName(const std::string& filePath, const std::string& fileName) { fs::path fsFilePath(filePath); @@ -458,5 +481,33 @@ bool Utils::GetRealPathOfNoneExistFile(const std::string& path, std::string& rea realPath = std::string(buffer) + fs::path::preferred_separator + fileName; return true; } + +bool Utils::RemoveAllFilesInDirectory(const std::string& directoryPath) +{ + fs::path fsPath(directoryPath); + if (!fs::exists(fsPath) || !fs::is_directory(fsPath)) { + return false; + } + for (auto& entry : fs::directory_iterator(fsPath)) { + if (fs::is_regular_file(entry)) { + fs::remove(entry); + } + } + return true; +} + +std::string Utils::ArrayToString(const std::list &array) +{ + std::unique_ptr jArray = PtJson::CreateArray(); + for (const auto& item : array) { + jArray->Push(item.c_str()); + } + return jArray->Stringify(); +} + +std::string Utils::BoolToString(bool value) +{ + return value ? "true" : "false"; +} } // namespace AppPackingTool } // namespace OHOS diff --git a/packing_tool/frameworks/test/unittest/BUILD.gn b/packing_tool/frameworks/test/unittest/BUILD.gn index de5faf0a4ae0f1c7c76eb87189195d584d236824..f2321d472917697adb5aa2e2fcaa19dc46d44e87 100644 --- a/packing_tool/frameworks/test/unittest/BUILD.gn +++ b/packing_tool/frameworks/test/unittest/BUILD.gn @@ -20,6 +20,7 @@ group("unittest") { "app_packager_test:unittest", "appqf_packager_test:unittest", "fast_app_packager_test:unittest", + "general_normalize_test:unittest", "hap_packager_test:unittest", "hqf_packager_test:unittest", "hqf_verify_test:unittest", @@ -28,6 +29,7 @@ group("unittest") { "json/hap_verify_info_test:unittest", "json/hap_verify_utils_test:unittest", "json/json_utils_test:unittest", + "json/module_json_fa_test:unittest", "json/module_json_stage_test:unittest", "json/module_json_test:unittest", "json/module_json_utils_test:unittest", diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/BUILD.gn b/packing_tool/frameworks/test/unittest/general_normalize_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a73c9b25a7373c89ab28dcba000c777440d52665 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/BUILD.gn @@ -0,0 +1,76 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("general_normalize_test_config") { + include_dirs = [ + "../../../include", + "../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("general_normalize_test") { + module_out_path = module_output_path + public_configs = [ ":general_normalize_test_config" ] + sources = [ + "../../../src/general_normalize.cpp", + "../../../src/hap_packager.cpp", + "../../../src/hsp_packager.cpp", + "../../../src/json/json_utils.cpp", + "../../../src/json/module_json.cpp", + "../../../src/json/module_json_fa.cpp", + "../../../src/json/module_json_stage.cpp", + "../../../src/json/normalize_version_utils.cpp", + "../../../src/json/pack_info.cpp", + "../../../src/json/pt_json.cpp", + "../../../src/log.cpp", + "../../../src/packager.cpp", + "../../../src/unzip_wrapper.cpp", + "../../../src/utils.cpp", + "../../../src/zip_utils.cpp", + "../../../src/zip_wrapper.cpp", + "general_normalize_test.cpp", + ] + + external_deps = [ + "bounds_checking_function:libsec_static", + "cJSON:cjson_static", + "hilog:libhilog", + "openssl:libcrypto_shared", + "zlib:libz", + ] + + deps = [ + ":copy_test_file", + "../ohos_test:copy_ohos_test", + ] +} + +group("unittest") { + testonly = true + deps = [ ":general_normalize_test" ] +} + +ohos_copy("copy_test_file") { + subsystem_name = "developtools" + part_name = "packing_tool" + sources = [ "./general_normalize_file" ] + outputs = [ "$root_out_dir/tests/unittest/developtools/packing_tool/test_file/general_normalize_file/" ] +} diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/app.js b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..6615ccb8c31a1fc86bf067d114c22852b3009d0d --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/app.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function () { +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var hilog = globalThis.requireNapi('hilog'); +var app = { + onCreate() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Application onCreate'); + }, + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Application onDestroy'); + }, +}; + +exports.default = app; +globalThis['app.js_8e74c152fb289caceeb880912823241e9d4b2806ecc0022940f4429f6d749b02'] + = globalThis['app.js_8e74c152fb289caceeb880912823241e9d4b2806ecc0022940f4429f6d749b02'] || { + default: app +} +})() +//# sourceMappingURL=app.js.map diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/app.js.map b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/app.js.map new file mode 100644 index 0000000000000000000000000000000000000000..93239c38965daaa450bb1d6ca013589202d2d2cf --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/app.js.map @@ -0,0 +1 @@ +{"version":3,"file":"app.js","sources":["D:/ArkTsProject/packingToolFaDemo/entry/src/main/ets/MainAbility/app.ets"],"sourcesContent":["import hilog from '@ohos.hilog';\n\nexport default {\n onCreate() {\n hilog.info(0x0000, 'testTag', '%{public}s', 'Application onCreate');\n },\n onDestroy() {\n hilog.info(0x0000, 'testTag', '%{public}s', 'Application onDestroy');\n },\n}"],"names":[],"mappings":"CAAA"} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/manifest.json b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/manifest.json new file mode 100644 index 0000000000000000000000000000000000000000..a4bfd1e2bd7ff2139238dd4e309c6f8c4f2b6abc --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/manifest.json @@ -0,0 +1 @@ +{"appID":"com.example.packingtoolfademo","versionName":"1.0.0","versionCode":1000000,"minPlatformVersion":9,"appName":".MainAbility","deviceType":["default","tablet"],"window":{"designWidth":720,"autoDesignWidth":false},"pages":["pages/index"],"mode":{"syntax":"ets","type":"pageAbility"}} diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/pages/index.js b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/pages/index.js new file mode 100644 index 0000000000000000000000000000000000000000..1ee1ad99532e0623fbd41bd8eaee3b13bea44ce9 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/pages/index.js @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function () { +'use strict'; + +"use strict"; +class Index extends ViewPU { + constructor(parent, params, __localStorage, elmtId = -1) { + super(parent, __localStorage, elmtId); + this.__message = new ObservedPropertySimplePU('Hello World', this, "message"); + this.setInitiallyProvidedValue(params); + } + setInitiallyProvidedValue(params) { + if (params.message !== undefined) { + this.message = params.message; + } + } + updateStateVars(params) { + } + purgeVariableDependenciesOnElmtId(rmElmtId) { + this.__message.purgeDependencyOnElmtId(rmElmtId); + } + aboutToBeDeleted() { + this.__message.aboutToBeDeleted(); + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal(); + } + get message() { + return this.__message.get(); + } + set message(newValue) { + this.__message.set(newValue); + } + initialRender() { + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Row.create(); + Row.height('100%'); + if (!isInitialRender) { + Row.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Column.create(); + Column.width('100%'); + if (!isInitialRender) { + Column.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Text.create(this.message); + Text.fontSize(50); + Text.fontWeight(FontWeight.Bold); + if (!isInitialRender) { + Text.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + Text.pop(); + Column.pop(); + Row.pop(); + } + rerender() { + this.updateDirtyElements(); + } +} +ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent()); +loadDocument(new Index(undefined, {})); +ViewStackProcessor.StopGetAccessRecording(); +})() +//# sourceMappingURL=index.js.map diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/pages/index.js.map b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/pages/index.js.map new file mode 100644 index 0000000000000000000000000000000000000000..275b007d949e329ae2ab40590930438b2ae10ab2 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/pages/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["D:/ArkTsProject/packingToolFaDemo/entry/src/main/ets/MainAbility/pages/index.ets"],"sourcesContent":["@Entry\n@Component\nstruct Index {\n @State message: string = 'Hello World'\n\n build() {\n Row() {\n Column() {\n Text(this.message)\n .fontSize(50)\n .fontWeight(FontWeight.Bold)\n }\n .width('100%')\n }\n .height('100%')\n }\n}"],"names":[],"mappings":"CAAA"} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/config.json b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/config.json new file mode 100644 index 0000000000000000000000000000000000000000..58e4106a4528142de32592f85f2259cbc12cda7e --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/config.json @@ -0,0 +1,96 @@ +{ + "app" : + { + "apiVersion" : + { + "compatible" : 9, + "releaseType" : "Release", + "target" : 9 + }, + "bundleName" : "com.example.packingtoolfademo", + "vendor" : "example", + "version" : + { + "code" : 1000000, + "name" : "1.0.0" + } + }, + "deviceConfig" : + { + "default" : + { + "debug" : true + } + }, + "module" : + { + "abilities" : + [ + { + "description" : "$string:MainAbility_desc", + "descriptionId" : 16777216, + "formsEnabled" : false, + "icon" : "$media:icon", + "iconId" : 16777220, + "label" : "$string:MainAbility_label", + "labelId" : 16777217, + "launchType" : "standard", + "name" : ".MainAbility", + "orientation" : "unspecified", + "skills" : + [ + { + "actions" : + [ + "action.system.home" + ], + "entities" : + [ + "entity.system.home" + ] + } + ], + "srcLanguage" : "ets", + "srcPath" : "MainAbility", + "type" : "page", + "visible" : true + } + ], + "deviceType" : + [ + "default", + "tablet" + ], + "distro" : + { + "deliveryWithInstall" : true, + "installationFree" : false, + "moduleName" : "entry", + "moduleType" : "entry", + "virtualMachine" : "ark9.0.0.0" + }, + "js" : + [ + { + "mode" : + { + "syntax" : "ets", + "type" : "pageAbility" + }, + "name" : ".MainAbility", + "pages" : + [ + "pages/index" + ], + "window" : + { + "autoDesignWidth" : false, + "designWidth" : 720 + } + } + ], + "mainAbility" : ".MainAbility", + "name" : ".entry", + "package" : "com.example.packingtoolfademo" + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/pack.json b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/pack.json new file mode 100644 index 0000000000000000000000000000000000000000..04870b2ba492f9ca56d31efaa15f4974c9926d1a --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/pack.json @@ -0,0 +1 @@ +{"summary":{"app":{"bundleName":"com.example.packingtoolfademo","version":{"code":1000000,"name":"1.0.0"}},"modules":[{"mainAbility":".MainAbility","deviceType":["default","tablet"],"abilities":[{"name":".MainAbility","label":"$string:MainAbility_label","visible":true}],"distro":{"deliveryWithInstall":true,"moduleName":"entry","moduleType":"entry","installationFree":false},"apiVersion":{"target":9,"compatible":9,"releaseType":"Release"}}]},"packages":[{"deviceType":["default","tablet"],"moduleType":"entry","deliveryWithInstall":true,"name":"entry-default"}]} diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/ets/sourceMaps.map b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/ets/sourceMaps.map new file mode 100644 index 0000000000000000000000000000000000000000..6e057157de749debffdcf95243c6ac95c4fba370 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/ets/sourceMaps.map @@ -0,0 +1,20 @@ +{ + "entry/build/default/cache/default/default@CompileArkTS/esmodule/debug/entry/src/main/ets/entryability/EntryAbility.js": { + "version": 3, + "file": "EntryAbility.ts", + "sources": [ + "entry/src/main/ets/entryability/EntryAbility.ts" + ], + "names": [], + "mappings": "AAAA" + }, + "entry/build/default/cache/default/default@CompileArkTS/esmodule/debug/entry/src/main/ets/pages/Index.js": { + "version": 3, + "file": "Index.ets", + "sources": [ + "entry/src/main/ets/pages/Index.ets" + ], + "names": [], + "mappings": "AAAA" + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/module.json b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/module.json new file mode 100644 index 0000000000000000000000000000000000000000..5427967a52f1b8cf4f641a56402cd3b39e8453ef --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/module.json @@ -0,0 +1,50 @@ +{ + "app": { + "bundleName": "com.example.packingtooldemo", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "targetAPIVersion": 12, + "minAPIVersion": 12, + "apiReleaseType": "Canary2", + "debug": true, + "iconId": 16777217, + "labelId": 16777216 + }, + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": ["default", "tablet"], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [{ + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [{ + "entities": ["entity.system.home"], + "actions": ["action.system.home"] + }], + "descriptionId": 16777218, + "iconId": 16777222, + "labelId": 16777219, + "startWindowIconId": 16777222, + "startWindowBackgroundId": 16777221 + }], + "generateBuildHash": true, + "virtualMachine": "ark12.0.1.0", + "compileMode": "esmodule", + "dependencies": [], + "descriptionId": 16777220 + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/pack.json b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/pack.json new file mode 100644 index 0000000000000000000000000000000000000000..b221fd946883c1f06110607139ff2d23ebc7d39d --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/pack.json @@ -0,0 +1 @@ +{"summary":{"app":{"bundleName":"com.example.packingtooldemo","version":{"code":1000000,"name":"1.0.0"}},"modules":[{"mainAbility":"EntryAbility","deviceType":["default","tablet"],"abilities":[{"name":"EntryAbility","label":"$string:EntryAbility_label"}],"distro":{"moduleType":"entry","installationFree":false,"deliveryWithInstall":true,"moduleName":"entry"},"apiVersion":{"compatible":12,"releaseType":"Canary2","target":12}}]},"packages":[{"deviceType":["default","tablet"],"moduleType":"entry","deliveryWithInstall":true,"name":"entry-default"}]} diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/resources/base/profile/main_pages.json b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_test.cpp b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cf8d6db62a3fa85b97bed00d59bebc7e895d3c87 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_test.cpp @@ -0,0 +1,2996 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#define private public +#define protected public +#include "module_json.h" +#include "pt_json.h" +#include "log.h" +#include "general_normalize.h" +#include "hap_packager.h" +#undef private +#undef protected + +#include "hqf_packager.h" +#include "hsp_packager.h" +#include "json/json_utils.h" +#include "json/normalize_version_utils.h" +#include "json/pack_info.h" +#include "log.h" +#include "utils.h" +#include "zip_utils.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::AppPackingTool; + +namespace OHOS { +namespace { +const std::string OUT_PATH = "/data/test/testouthap"; +const std::string HAP_OUT_PATH = "/data/test/entry-default-unsigned.hap"; +const std::string HAP_INPUT_LIST = "/data/test/entry-default-unsigned.hap"; +const std::string INPUT_LIST = "/data/test/testinputhap"; +const std::string VERSION_CODE = "9999999"; +const std::string VERSION_NAME = "30.11.22"; +const std::string STAGE_INDEX_PATH = "/data/test/resource/packingtool/test_file/stage/resources.index"; +const std::string STAGE_PACK_INFO_PATH = "/data/test/resource/packingtool/test_file/stage/pack.info"; +const std::string STAGE_ETS_PATH = "/data/test/resource/packingtool/test_file/stage/ets"; +const std::string STAGE_RESOURCES_PATH = "/data/test/resource/packingtool/test_file/stage/resources"; +const std::string STAGE_JSON_PATH = "/data/test/resource/packingtool/test_file/stage/module.json"; +const std::string STAGE_RPCID_PATH = "/data/test/resource/packingtool/test_file/stage/rpcid.sc"; +const std::string PATH = "/data/test/resource/packingtool/test_file/stage"; +const std::string BUNDLE_NAME = "com.example.packingtoolfademo"; +const std::string MIN_COMPATIBLE_VERSION_CODE = "99"; +const std::string MIN_API_VERSION = "11"; +const std::string TARGET_API_VERSION = "12"; +const std::string API_RELEASE_TYPE = "Canary1"; +const std::string INVAILD_INT_NUM = "2147483648"; +const std::string INVAILD_PATTERN = "-123"; +const std::string TOO_LONG_VERSION_NAME(OHOS::AppPackingTool::Constants::MAX_VERSION_NAME_LENGTH + 1, '1'); +const std::string TOO_SHORT_BUNDLE_NAME(OHOS::AppPackingTool::Constants::BUNDLE_NAME_LEN_MIN - 1, '1'); +const std::string TOO_LONG_BUNDLE_NAME(OHOS::AppPackingTool::Constants::BUNDLE_NAME_LEN_MAX + 1, '1'); +const std::string INVALID_DEVICE_TYPES = +"\"default\", \"tablet\", \"tv\", \"wearable\", \"car\", \"2in1\", \"abc\""; +const std::string CONFIG_JSON_STRING = "{" + "\"app\": {" + "\"apiVersion\": {" + "\"compatible\": 9," + "\"releaseType\": \"Release\"," + "\"target\": 9" + "}," + "\"bundleName\": \"com.example.packingtoolfademo\"," + "\"vendor\": \"example\"," + "\"version\": {" + "\"code\" : 1000000," + "\"name\" : \"1.0.0\"" + "}" + "}," + "\"deviceConfig\": {" + "\"default\": {" + "\"debug\": true" + "}" + "}," + "\"module\": {" + "\"abilities\": [" + "{" + "\"description\": \"$string:MainAbility_desc\"," + "\"descriptionId\": 16777216," + "\"formsEnabled\": false," + "\"icon\": \"$media:icon\"," + "\"iconId\": 16777220," + "\"label\": \"$string:MainAbility_label\"," + "\"labelId\": 16777217," + "\"launchType\": \"standard\"," + "\"name\": \".MainAbility\"," + "\"orientation\": \"unspecified\"," + "\"skills\": [" + "{" + "\"actions\": [" + "\"action.system.home\"" + "]," + "\"entities\": [" + "\"entity.system.home\"" + "]" + "}" + "]," + "\"srcLanguage\" : \"ets\"," + "\"srcPath\" : \"MainAbility\"," + "\"type\" : \"page\"," + "\"visible\" : true" + "}" + "]," + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"distro\": {" + "\"deliveryWithInstall\": true," + "\"installationFree\": false," + "\"moduleName\": \"entry\"," + "\"moduleType\": \"entry\"," + "\"virtualMachine\": \"ark9.0.0.0\"" + "}," + "\"js\": [" + "{" + "\"mode\": {" + "\"syntax\": \"ets\"," + "\"type\": \"pageAbility\"" + "}," + "\"name\": \".MainAbility\"," + "\"pages\": [" + "\"pages/index\"" + "]," + "\"window\": {" + "\"autoDesignWidth\": false," + "\"designWidth\": 720" + "}" + "}" + "]," + "\"mainAbility\" : \".MainAbility\"," + "\"name\" : \".entry\"," + "\"package\" : \"com.example.packingtoolfademo\"" + "}" +"}"; +const std::string CONFIG_JSON_STRING_NO_MODULE_NAME = "{" + "\"app\": {" + "\"apiVersion\": {" + "\"compatible\": 9," + "\"releaseType\": \"Release\"," + "\"target\": 9" + "}," + "\"bundleName\": \"com.example.packingtoolfademo\"," + "\"vendor\": \"example\"," + "\"version\": {" + "\"code\" : 1000000," + "\"name\" : \"1.0.0\"" + "}" + "}," + "\"deviceConfig\": {" + "\"default\": {" + "\"debug\": true" + "}" + "}," + "\"module\": {" + "\"abilities\": [" + "{" + "\"description\": \"$string:MainAbility_desc\"," + "\"descriptionId\": 16777216," + "\"formsEnabled\": false," + "\"icon\": \"$media:icon\"," + "\"iconId\": 16777220," + "\"label\": \"$string:MainAbility_label\"," + "\"labelId\": 16777217," + "\"launchType\": \"standard\"," + "\"name\": \".MainAbility\"," + "\"orientation\": \"unspecified\"," + "\"skills\": [" + "{" + "\"actions\": [" + "\"action.system.home\"" + "]," + "\"entities\": [" + "\"entity.system.home\"" + "]" + "}" + "]," + "\"srcLanguage\" : \"ets\"," + "\"srcPath\" : \"MainAbility\"," + "\"type\" : \"page\"," + "\"visible\" : true" + "}" + "]," + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"distro\": {" + "\"deliveryWithInstall\": true," + "\"installationFree\": false," + "\"moduleName\": \"entry\"," + "\"moduleType\": \"entry\"," + "\"virtualMachine\": \"ark9.0.0.0\"" + "}," + "\"js\": [" + "{" + "\"mode\": {" + "\"syntax\": \"ets\"," + "\"type\": \"pageAbility\"" + "}," + "\"name\": \".MainAbility\"," + "\"pages\": [" + "\"pages/index\"" + "]," + "\"window\": {" + "\"autoDesignWidth\": false," + "\"designWidth\": 720" + "}" + "}" + "]," + "\"mainAbility\" : \".MainAbility\"," + "\"package\" : \"com.example.packingtoolfademo\"" + "}" +"}"; +const std::string CONFIG_JSON_STRING_NO_APP_VERSION = "{" + "\"app\": {" + "\"apiVersion\": {" + "\"compatible\": 9," + "\"releaseType\": \"Release\"," + "\"target\": 9" + "}," + "\"bundleName\": \"com.example.packingtoolfademo\"," + "\"vendor\": \"example\"" + "}," + "\"deviceConfig\": {" + "\"default\": {" + "\"debug\": true" + "}" + "}," + "\"module\": {" + "\"abilities\": [" + "{" + "\"description\": \"$string:MainAbility_desc\"," + "\"descriptionId\": 16777216," + "\"formsEnabled\": false," + "\"icon\": \"$media:icon\"," + "\"iconId\": 16777220," + "\"label\": \"$string:MainAbility_label\"," + "\"labelId\": 16777217," + "\"launchType\": \"standard\"," + "\"name\": \".MainAbility\"," + "\"orientation\": \"unspecified\"," + "\"skills\": [" + "{" + "\"actions\": [" + "\"action.system.home\"" + "]," + "\"entities\": [" + "\"entity.system.home\"" + "]" + "}" + "]," + "\"srcLanguage\" : \"ets\"," + "\"srcPath\" : \"MainAbility\"," + "\"type\" : \"page\"," + "\"visible\" : true" + "}" + "]," + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"distro\": {" + "\"deliveryWithInstall\": true," + "\"installationFree\": false," + "\"moduleName\": \"entry\"," + "\"moduleType\": \"entry\"," + "\"virtualMachine\": \"ark9.0.0.0\"" + "}," + "\"js\": [" + "{" + "\"mode\": {" + "\"syntax\": \"ets\"," + "\"type\": \"pageAbility\"" + "}," + "\"name\": \".MainAbility\"," + "\"pages\": [" + "\"pages/index\"" + "]," + "\"window\": {" + "\"autoDesignWidth\": false," + "\"designWidth\": 720" + "}" + "}" + "]," + "\"mainAbility\" : \".MainAbility\"," + "\"name\" : \".entry\"," + "\"package\" : \"com.example.packingtoolfademo\"" + "}" +"}"; +const std::string CONFIG_JSON_STRING_NO_BUNDLE_NAME = "{" + "\"app\": {" + "\"apiVersion\": {" + "\"compatible\": 9," + "\"releaseType\": \"Release\"," + "\"target\": 9" + "}," + "\"vendor\": \"example\"," + "\"version\": {" + "\"code\" : 1000000," + "\"name\" : \"1.0.0\"" + "}" + "}," + "\"deviceConfig\": {" + "\"default\": {" + "\"debug\": true" + "}" + "}," + "\"module\": {" + "\"abilities\": [" + "{" + "\"description\": \"$string:MainAbility_desc\"," + "\"descriptionId\": 16777216," + "\"formsEnabled\": false," + "\"icon\": \"$media:icon\"," + "\"iconId\": 16777220," + "\"label\": \"$string:MainAbility_label\"," + "\"labelId\": 16777217," + "\"launchType\": \"standard\"," + "\"name\": \".MainAbility\"," + "\"orientation\": \"unspecified\"," + "\"skills\": [" + "{" + "\"actions\": [" + "\"action.system.home\"" + "]," + "\"entities\": [" + "\"entity.system.home\"" + "]" + "}" + "]," + "\"srcLanguage\" : \"ets\"," + "\"srcPath\" : \"MainAbility\"," + "\"type\" : \"page\"," + "\"visible\" : true" + "}" + "]," + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"distro\": {" + "\"deliveryWithInstall\": true," + "\"installationFree\": false," + "\"moduleName\": \"entry\"," + "\"moduleType\": \"entry\"," + "\"virtualMachine\": \"ark9.0.0.0\"" + "}," + "\"js\": [" + "{" + "\"mode\": {" + "\"syntax\": \"ets\"," + "\"type\": \"pageAbility\"" + "}," + "\"name\": \".MainAbility\"," + "\"pages\": [" + "\"pages/index\"" + "]," + "\"window\": {" + "\"autoDesignWidth\": false," + "\"designWidth\": 720" + "}" + "}" + "]," + "\"mainAbility\" : \".MainAbility\"," + "\"name\" : \".entry\"," + "\"package\" : \"com.example.packingtoolfademo\"" + "}" +"}"; +const std::string JSON_STRING = "{" + "\"summary\": {" + "\"app\": {" + "\"bundleName\": \"com.example.myapplication\"," + "\"bundleType\": \"bundleApp\"," + "\"version\": {" + "\"code\": 1000000," + "\"name\": \"1.0.0\"" + "}" + "}," + "\"modules\": [" + "{" + "\"mainAbility\": \"EntryAbility\"," + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"abilities\": [" + "{" + "\"name\": \"EntryAbility\"," + "\"label\": \"$string:EntryAbility_label\"" + "}" + "]," + "\"distro\": {" + "\"moduleType\": \"entry\"," + "\"installationFree\": false," + "\"deliveryWithInstall\": true," + "\"moduleName\": \"entry\"" + "}," + "\"extensionAbilities\": [" + "]," + "\"apiVersion\": {" + "\"compatible\": 12," + "\"releaseType\": \"Canary2\"," + "\"target\": 12" + "}" + "}" + "]" + "}," + "\"packages\":[" + "{" + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"moduleType\": \"entry\"," + "\"deliveryWithInstall\": true," + "\"name\": \"entry-default\"" + "}" + "]" +"}"; + +const std::string JSON_STRING_NO_APP_VERSION = "{" + "\"summary\": {" + "\"app\": {" + "\"bundleName\": \"com.example.myapplication\"," + "\"bundleType\": \"bundleApp\"" + "}," + "\"modules\": [" + "{" + "\"mainAbility\": \"EntryAbility\"," + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"abilities\": [" + "{" + "\"name\": \"EntryAbility\"," + "\"label\": \"$string:EntryAbility_label\"" + "}" + "]," + "\"distro\": {" + "\"moduleType\": \"entry\"," + "\"installationFree\": false," + "\"deliveryWithInstall\": true," + "\"moduleName\": \"entry\"" + "}," + "\"extensionAbilities\": [" + "]," + "\"apiVersion\": {" + "\"compatible\": 12," + "\"releaseType\": \"Canary2\"," + "\"target\": 12" + "}" + "}" + "]" + "}," + "\"packages\":[" + "{" + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"moduleType\": \"entry\"," + "\"deliveryWithInstall\": true," + "\"name\": \"entry-default\"" + "}" + "]" +"}"; + +const std::string JSON_STRING_NO_BUNDLE_NAME = "{" + "\"summary\": {" + "\"app\": {" + "\"bundleType\": \"bundleApp\"," + "\"version\": {" + "\"code\": 1000000," + "\"name\": \"1.0.0\"" + "}" + "}," + "\"modules\": [" + "{" + "\"mainAbility\": \"EntryAbility\"," + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"abilities\": [" + "{" + "\"name\": \"EntryAbility\"," + "\"label\": \"$string:EntryAbility_label\"" + "}" + "]," + "\"distro\": {" + "\"moduleType\": \"entry\"," + "\"installationFree\": false," + "\"deliveryWithInstall\": true," + "\"moduleName\": \"entry\"" + "}," + "\"extensionAbilities\": [" + "]," + "\"apiVersion\": {" + "\"compatible\": 12," + "\"releaseType\": \"Canary2\"," + "\"target\": 12" + "}" + "}" + "]" + "}," + "\"packages\":[" + "{" + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"moduleType\": \"entry\"," + "\"deliveryWithInstall\": true," + "\"name\": \"entry-default\"" + "}" + "]" +"}"; + +const std::string JSON_STRING_NO_BUNDLE_TYPE = "{" + "\"summary\": {" + "\"app\": {" + "\"bundleName\": \"com.example.myapplication\"," + "\"version\": {" + "\"code\": 1000000," + "\"name\": \"1.0.0\"" + "}" + "}," + "\"modules\": [" + "{" + "\"mainAbility\": \"EntryAbility\"," + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"abilities\": [" + "{" + "\"name\": \"EntryAbility\"," + "\"label\": \"$string:EntryAbility_label\"" + "}" + "]," + "\"distro\": {" + "\"moduleType\": \"entry\"," + "\"installationFree\": false," + "\"deliveryWithInstall\": true," + "\"moduleName\": \"entry\"" + "}," + "\"extensionAbilities\": [" + "]," + "\"apiVersion\": {" + "\"compatible\": 12," + "\"releaseType\": \"Canary2\"," + "\"target\": 12" + "}" + "}" + "]" + "}," + "\"packages\":[" + "{" + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"moduleType\": \"entry\"," + "\"deliveryWithInstall\": true," + "\"name\": \"entry-default\"" + "}" + "]" +"}"; +const std::string MODULE_JSON_STRING_ONLY_VERSION = "{" + "\"app\": {" + "\"version\": {" + "\"code\": 666," + "\"name\": \"test_version\"," + "\"minCompatibleVersionCode\": 555" + "}" + "}," + "\"module\": {" + "\"name\": \"entry\"," + "\"type\": \"entry\"" + "}," + "\"deviceConfig\": {" + "\"default\": {\"debug\": true}" + "}" +"}"; +const std::string MODULE_JSON_STRING = "{" + "\"app\": {" + "\"bundleName\": \"test_bundle_name\"," + "\"bundleType\": \"atomicService\"," + "\"vendor\": \"\"," + "\"versionCode\": 1000000," + "\"versionName\": \"test_version_name\"," + "\"icon\": \"media:app_icon\"," + "\"label\": \"string:app_name\"," + "\"apiReleaseType\": \"Canary\"," + "\"compileSdkVersion\": \"test_compileSdkVersion\"," + "\"targetAPIVersion\": 10," + "\"minAPIVersion\": 10," + "\"compileSdkType\": \"OpenHarmony\"," + "\"debug\": true," + "\"iconId\": 16777217," + "\"labelId\": 16777216," + "\"version\": {" + "\"code\": 666," + "\"name\": \"test_version\"," + "\"minCompatibleVersionCode\": 555" + "}," + "\"apiVersion\": {" + "\"compileSdkType\": \"OpenHarmony\"," + "\"compileSdkVersion\": \"test_apiVersion_compileSdkVersion\"," + "\"releaseType\": \"test_apiVersion_release\"," + "\"compatible\": 7," + "\"target\": 10" + "}," + "\"targetBundleName\": \"test_app_targetBundleName\"," + "\"multiAppMode\": {" + "\"multiAppModeType\": \"test_multiAppMode\"," + "\"maxCount\": 9" + "}," + "\"generateBuildHash\": true," + "\"minCompatibleVersionCode\": 99," + "\"asanEnabled\": true," + "\"tsanEnabled\": false," + "\"compressNativeLibs\": true," + "\"targetPriority\": 5" + "}," + "\"module\": {" + "\"name\": \"entry\"," + "\"type\": \"entry\"," + "\"description\": \"string:module_desc\"," + "\"mainElement\": \"EntryAbility\"," + "\"deviceTypes\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"deliveryWithInstall\": true," + "\"installationFree\": true," + "\"pages\": \"profile:main_pages\"," + "\"abilities\": [" + "{" + "\"name\": \"EntryAbility\"," + "\"moduleName\": \"test_module_name\"," + "\"srcEntry\": \"./ets/entryability/EntryAbility.ts\"," + "\"description\": \"string:EntryAbility_desc\"," + "\"icon\": \"media:icon\"," + "\"label\": \"string:EntryAbility_label\"," + "\"startWindowIcon\": \"media:icon\"," + "\"startWindowBackground\": \"color:start_window_background\"," + "\"exported\": true," + "\"skills\": [" + "{" + "\"entities\": [\"entity.system.home\"]," + "\"actions\": [\"action.system.home\"]" + "}" + "]," + "\"descriptionId\": 16777218," + "\"iconId\": 16777222," + "\"labelId\": 16777219," + "\"startWindowIconId\": 16777222," + "\"startWindowBackgroundId\": 16777221," + "\"continueType\":[]" + "}" + "]," + "\"virtualMachine\": \"test_virtualMachine\"," + "\"compileMode\": \"esmodule\"," + "\"dependencies\": [" + "{" + "\"bundleName\": \"test_modules_dependency_1\"," + "\"moduleName\": \"entry_1\"" + "}," + "{" + "\"bundleName\": \"test_modules_dependency_2\"," + "\"moduleName\": \"entry_1\"" + "}" + "]," + "\"descriptionId\": 16777220," + "\"distro\": {" + "\"installationFree\": false," + "\"moduleType\": \"entry\"," + "\"moduleName\": \"test_module_name\"" + "}," + "\"preloads\": [" + "{" + "\"name\": \"test_name_1\"," + "\"moduleName\": \"test_module_name_1\"" + "}" + "]," + "\"package\": \"test_package\"," + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"targetModuleName\": \"test_module_targetBundleName\"," + "\"targetPriority\": 6," + "\"proxyDatas\": [" + "{" + "\"uri\": \"test_uri1\"" + "}," + "{" + "\"uri\": \"test_uri2\"" + "}" + "]," + "\"atomicService\": {" + "\"preloads\": [" + "{" + "\"atomicServiceObj\": \"test_atomicService\"" + "}" + "]" + "}," + "\"metadata\": [" + "{" + "\"name\": \"test_metadata\"," + "\"value\": \"test_value\"," + "\"resource\": \"test_resource\"" + "}" + "]," + "\"extensionAbilities\": [" + "{" + "\"name\": \"test_extension_abilities\"" + "}" + "]" + "}," + "\"deviceConfig\": {" + "\"default\": {\"debug\": true}" + "}" +"}"; +const std::string MODULE_JSON_STRING_NO_APP_VERSION = "{" + "\"app\": {" + "\"bundleName\": \"test_bundle_name\"," + "\"bundleType\": \"atomicService\"," + "\"vendor\": \"\"," + "\"versionCode\": 1000000," + "\"versionName\": \"test_version_name\"," + "\"icon\": \"media:app_icon\"," + "\"label\": \"string:app_name\"," + "\"apiReleaseType\": \"Canary\"," + "\"compileSdkVersion\": \"test_compileSdkVersion\"," + "\"targetAPIVersion\": 10," + "\"minAPIVersion\": 10," + "\"compileSdkType\": \"OpenHarmony\"," + "\"debug\": true," + "\"iconId\": 16777217," + "\"labelId\": 16777216," + "\"apiVersion\": {" + "\"compileSdkType\": \"OpenHarmony\"," + "\"compileSdkVersion\": \"test_apiVersion_compileSdkVersion\"," + "\"releaseType\": \"test_apiVersion_release\"," + "\"compatible\": 7," + "\"target\": 10" + "}," + "\"targetBundleName\": \"test_app_targetBundleName\"," + "\"multiAppMode\": {" + "\"multiAppModeType\": \"test_multiAppMode\"," + "\"maxCount\": 9" + "}," + "\"generateBuildHash\": true," + "\"minCompatibleVersionCode\": 99," + "\"asanEnabled\": true," + "\"tsanEnabled\": false," + "\"compressNativeLibs\": true," + "\"targetPriority\": 5" + "}," + "\"module\": {" + "\"name\": \"entry\"," + "\"type\": \"entry\"," + "\"description\": \"string:module_desc\"," + "\"mainElement\": \"EntryAbility\"," + "\"deviceTypes\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"deliveryWithInstall\": true," + "\"installationFree\": true," + "\"pages\": \"profile:main_pages\"," + "\"abilities\": [" + "{" + "\"name\": \"EntryAbility\"," + "\"moduleName\": \"test_module_name\"," + "\"srcEntry\": \"./ets/entryability/EntryAbility.ts\"," + "\"description\": \"string:EntryAbility_desc\"," + "\"icon\": \"media:icon\"," + "\"label\": \"string:EntryAbility_label\"," + "\"startWindowIcon\": \"media:icon\"," + "\"startWindowBackground\": \"color:start_window_background\"," + "\"exported\": true," + "\"skills\": [" + "{" + "\"entities\": [\"entity.system.home\"]," + "\"actions\": [\"action.system.home\"]" + "}" + "]," + "\"descriptionId\": 16777218," + "\"iconId\": 16777222," + "\"labelId\": 16777219," + "\"startWindowIconId\": 16777222," + "\"startWindowBackgroundId\": 16777221," + "\"continueType\":[]" + "}" + "]," + "\"virtualMachine\": \"test_virtualMachine\"," + "\"compileMode\": \"esmodule\"," + "\"dependencies\": [" + "{" + "\"bundleName\": \"test_modules_dependency_1\"," + "\"moduleName\": \"entry_1\"" + "}," + "{" + "\"bundleName\": \"test_modules_dependency_2\"," + "\"moduleName\": \"entry_1\"" + "}" + "]," + "\"descriptionId\": 16777220," + "\"distro\": {" + "\"installationFree\": false," + "\"moduleType\": \"entry\"," + "\"moduleName\": \"test_module_name\"" + "}," + "\"preloads\": [" + "{" + "\"name\": \"test_name_1\"," + "\"moduleName\": \"test_module_name_1\"" + "}" + "]," + "\"package\": \"test_package\"," + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"targetModuleName\": \"test_module_targetBundleName\"," + "\"targetPriority\": 6," + "\"proxyDatas\": [" + "{" + "\"uri\": \"test_uri1\"" + "}," + "{" + "\"uri\": \"test_uri2\"" + "}" + "]," + "\"atomicService\": {" + "\"preloads\": [" + "{" + "\"atomicServiceObj\": \"test_atomicService\"" + "}" + "]" + "}," + "\"metadata\": [" + "{" + "\"name\": \"test_metadata\"," + "\"value\": \"test_value\"," + "\"resource\": \"test_resource\"" + "}" + "]," + "\"extensionAbilities\": [" + "{" + "\"name\": \"test_extension_abilities\"" + "}" + "]" + "}," + "\"deviceConfig\": {" + "\"default\": {\"debug\": true}" + "}" +"}"; +const std::string MODULE_JSON_STRING_NO_BUNDLE_NAME = "{" + "\"app\": {" + "\"bundleType\": \"atomicService\"," + "\"vendor\": \"\"," + "\"versionCode\": 1000000," + "\"versionName\": \"test_version_name\"," + "\"icon\": \"media:app_icon\"," + "\"label\": \"string:app_name\"," + "\"apiReleaseType\": \"Canary\"," + "\"compileSdkVersion\": \"test_compileSdkVersion\"," + "\"targetAPIVersion\": 10," + "\"minAPIVersion\": 10," + "\"compileSdkType\": \"OpenHarmony\"," + "\"debug\": true," + "\"iconId\": 16777217," + "\"labelId\": 16777216," + "\"version\": {" + "\"code\": 666," + "\"name\": \"test_version\"," + "\"minCompatibleVersionCode\": 555" + "}," + "\"apiVersion\": {" + "\"compileSdkType\": \"OpenHarmony\"," + "\"compileSdkVersion\": \"test_apiVersion_compileSdkVersion\"," + "\"releaseType\": \"test_apiVersion_release\"," + "\"compatible\": 7," + "\"target\": 10" + "}," + "\"targetBundleName\": \"test_app_targetBundleName\"," + "\"multiAppMode\": {" + "\"multiAppModeType\": \"test_multiAppMode\"," + "\"maxCount\": 9" + "}," + "\"generateBuildHash\": true," + "\"minCompatibleVersionCode\": 99," + "\"asanEnabled\": true," + "\"tsanEnabled\": false," + "\"compressNativeLibs\": true," + "\"targetPriority\": 5" + "}," + "\"module\": {" + "\"name\": \"entry\"," + "\"type\": \"entry\"," + "\"description\": \"string:module_desc\"," + "\"mainElement\": \"EntryAbility\"," + "\"deviceTypes\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"deliveryWithInstall\": true," + "\"installationFree\": true," + "\"pages\": \"profile:main_pages\"," + "\"abilities\": [" + "{" + "\"name\": \"EntryAbility\"," + "\"moduleName\": \"test_module_name\"," + "\"srcEntry\": \"./ets/entryability/EntryAbility.ts\"," + "\"description\": \"string:EntryAbility_desc\"," + "\"icon\": \"media:icon\"," + "\"label\": \"string:EntryAbility_label\"," + "\"startWindowIcon\": \"media:icon\"," + "\"startWindowBackground\": \"color:start_window_background\"," + "\"exported\": true," + "\"skills\": [" + "{" + "\"entities\": [\"entity.system.home\"]," + "\"actions\": [\"action.system.home\"]" + "}" + "]," + "\"descriptionId\": 16777218," + "\"iconId\": 16777222," + "\"labelId\": 16777219," + "\"startWindowIconId\": 16777222," + "\"startWindowBackgroundId\": 16777221," + "\"continueType\":[]" + "}" + "]," + "\"virtualMachine\": \"test_virtualMachine\"," + "\"compileMode\": \"esmodule\"," + "\"dependencies\": [" + "{" + "\"bundleName\": \"test_modules_dependency_1\"," + "\"moduleName\": \"entry_1\"" + "}," + "{" + "\"bundleName\": \"test_modules_dependency_2\"," + "\"moduleName\": \"entry_1\"" + "}" + "]," + "\"descriptionId\": 16777220," + "\"distro\": {" + "\"installationFree\": false," + "\"moduleType\": \"entry\"," + "\"moduleName\": \"test_module_name\"" + "}," + "\"preloads\": [" + "{" + "\"name\": \"test_name_1\"," + "\"moduleName\": \"test_module_name_1\"" + "}" + "]," + "\"package\": \"test_package\"," + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"targetModuleName\": \"test_module_targetBundleName\"," + "\"targetPriority\": 6," + "\"proxyDatas\": [" + "{" + "\"uri\": \"test_uri1\"" + "}," + "{" + "\"uri\": \"test_uri2\"" + "}" + "]," + "\"atomicService\": {" + "\"preloads\": [" + "{" + "\"atomicServiceObj\": \"test_atomicService\"" + "}" + "]" + "}," + "\"metadata\": [" + "{" + "\"name\": \"test_metadata\"," + "\"value\": \"test_value\"," + "\"resource\": \"test_resource\"" + "}" + "]," + "\"extensionAbilities\": [" + "{" + "\"name\": \"test_extension_abilities\"" + "}" + "]" + "}," + "\"deviceConfig\": {" + "\"default\": {\"debug\": true}" + "}" +"}"; +const std::string MODULE_JSON_STRING_NO_BUNDLE_TYPE = "{" + "\"app\": {" + "\"bundleName\": \"test_bundle_name\"," + "\"vendor\": \"\"," + "\"versionCode\": 1000000," + "\"versionName\": \"test_version_name\"," + "\"icon\": \"media:app_icon\"," + "\"label\": \"string:app_name\"," + "\"apiReleaseType\": \"Canary\"," + "\"compileSdkVersion\": \"test_compileSdkVersion\"," + "\"targetAPIVersion\": 10," + "\"minAPIVersion\": 10," + "\"compileSdkType\": \"OpenHarmony\"," + "\"debug\": true," + "\"iconId\": 16777217," + "\"labelId\": 16777216," + "\"version\": {" + "\"code\": 666," + "\"name\": \"test_version\"," + "\"minCompatibleVersionCode\": 555" + "}," + "\"apiVersion\": {" + "\"compileSdkType\": \"OpenHarmony\"," + "\"compileSdkVersion\": \"test_apiVersion_compileSdkVersion\"," + "\"releaseType\": \"test_apiVersion_release\"," + "\"compatible\": 7," + "\"target\": 10" + "}," + "\"targetBundleName\": \"test_app_targetBundleName\"," + "\"multiAppMode\": {" + "\"multiAppModeType\": \"test_multiAppMode\"," + "\"maxCount\": 9" + "}," + "\"generateBuildHash\": true," + "\"minCompatibleVersionCode\": 99," + "\"asanEnabled\": true," + "\"tsanEnabled\": false," + "\"compressNativeLibs\": true," + "\"targetPriority\": 5" + "}," + "\"module\": {" + "\"name\": \"entry\"," + "\"type\": \"entry\"," + "\"description\": \"string:module_desc\"," + "\"mainElement\": \"EntryAbility\"," + "\"deviceTypes\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"deliveryWithInstall\": true," + "\"installationFree\": true," + "\"pages\": \"profile:main_pages\"," + "\"abilities\": [" + "{" + "\"name\": \"EntryAbility\"," + "\"moduleName\": \"test_module_name\"," + "\"srcEntry\": \"./ets/entryability/EntryAbility.ts\"," + "\"description\": \"string:EntryAbility_desc\"," + "\"icon\": \"media:icon\"," + "\"label\": \"string:EntryAbility_label\"," + "\"startWindowIcon\": \"media:icon\"," + "\"startWindowBackground\": \"color:start_window_background\"," + "\"exported\": true," + "\"skills\": [" + "{" + "\"entities\": [\"entity.system.home\"]," + "\"actions\": [\"action.system.home\"]" + "}" + "]," + "\"descriptionId\": 16777218," + "\"iconId\": 16777222," + "\"labelId\": 16777219," + "\"startWindowIconId\": 16777222," + "\"startWindowBackgroundId\": 16777221," + "\"continueType\":[]" + "}" + "]," + "\"virtualMachine\": \"test_virtualMachine\"," + "\"compileMode\": \"esmodule\"," + "\"dependencies\": [" + "{" + "\"bundleName\": \"test_modules_dependency_1\"," + "\"moduleName\": \"entry_1\"" + "}," + "{" + "\"bundleName\": \"test_modules_dependency_2\"," + "\"moduleName\": \"entry_1\"" + "}" + "]," + "\"descriptionId\": 16777220," + "\"distro\": {" + "\"installationFree\": false," + "\"moduleType\": \"entry\"," + "\"moduleName\": \"test_module_name\"" + "}," + "\"preloads\": [" + "{" + "\"name\": \"test_name_1\"," + "\"moduleName\": \"test_module_name_1\"" + "}" + "]," + "\"package\": \"test_package\"," + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"targetModuleName\": \"test_module_targetBundleName\"," + "\"targetPriority\": 6," + "\"proxyDatas\": [" + "{" + "\"uri\": \"test_uri1\"" + "}," + "{" + "\"uri\": \"test_uri2\"" + "}" + "]," + "\"atomicService\": {" + "\"preloads\": [" + "{" + "\"atomicServiceObj\": \"test_atomicService\"" + "}" + "]" + "}," + "\"metadata\": [" + "{" + "\"name\": \"test_metadata\"," + "\"value\": \"test_value\"," + "\"resource\": \"test_resource\"" + "}" + "]," + "\"extensionAbilities\": [" + "{" + "\"name\": \"test_extension_abilities\"" + "}" + "]" + "}," + "\"deviceConfig\": {" + "\"default\": {\"debug\": true}" + "}" +"}"; +const std::string MODULE_JSON_STRING_NO_MODULE_NAME = "{" + "\"app\": {" + "\"bundleName\": \"test_bundle_name\"," + "\"bundleType\": \"atomicService\"," + "\"vendor\": \"\"," + "\"versionCode\": 1000000," + "\"versionName\": \"test_version_name\"," + "\"icon\": \"media:app_icon\"," + "\"label\": \"string:app_name\"," + "\"apiReleaseType\": \"Canary\"," + "\"compileSdkVersion\": \"test_compileSdkVersion\"," + "\"targetAPIVersion\": 10," + "\"minAPIVersion\": 10," + "\"compileSdkType\": \"OpenHarmony\"," + "\"debug\": true," + "\"iconId\": 16777217," + "\"labelId\": 16777216," + "\"version\": {" + "\"code\": 666," + "\"name\": \"test_version\"," + "\"minCompatibleVersionCode\": 555" + "}," + "\"apiVersion\": {" + "\"compileSdkType\": \"OpenHarmony\"," + "\"compileSdkVersion\": \"test_apiVersion_compileSdkVersion\"," + "\"releaseType\": \"test_apiVersion_release\"," + "\"compatible\": 7," + "\"target\": 10" + "}," + "\"targetBundleName\": \"test_app_targetBundleName\"," + "\"multiAppMode\": {" + "\"multiAppModeType\": \"test_multiAppMode\"," + "\"maxCount\": 9" + "}," + "\"generateBuildHash\": true," + "\"minCompatibleVersionCode\": 99," + "\"asanEnabled\": true," + "\"tsanEnabled\": false," + "\"compressNativeLibs\": true," + "\"targetPriority\": 5" + "}," + "\"module\": {" + "\"type\": \"entry\"," + "\"description\": \"string:module_desc\"," + "\"mainElement\": \"EntryAbility\"," + "\"deviceTypes\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"deliveryWithInstall\": true," + "\"installationFree\": true," + "\"pages\": \"profile:main_pages\"," + "\"abilities\": [" + "{" + "\"name\": \"EntryAbility\"," + "\"moduleName\": \"test_module_name\"," + "\"srcEntry\": \"./ets/entryability/EntryAbility.ts\"," + "\"description\": \"string:EntryAbility_desc\"," + "\"icon\": \"media:icon\"," + "\"label\": \"string:EntryAbility_label\"," + "\"startWindowIcon\": \"media:icon\"," + "\"startWindowBackground\": \"color:start_window_background\"," + "\"exported\": true," + "\"skills\": [" + "{" + "\"entities\": [\"entity.system.home\"]," + "\"actions\": [\"action.system.home\"]" + "}" + "]," + "\"descriptionId\": 16777218," + "\"iconId\": 16777222," + "\"labelId\": 16777219," + "\"startWindowIconId\": 16777222," + "\"startWindowBackgroundId\": 16777221," + "\"continueType\":[]" + "}" + "]," + "\"virtualMachine\": \"test_virtualMachine\"," + "\"compileMode\": \"esmodule\"," + "\"dependencies\": [" + "{" + "\"bundleName\": \"test_modules_dependency_1\"," + "\"moduleName\": \"entry_1\"" + "}," + "{" + "\"bundleName\": \"test_modules_dependency_2\"," + "\"moduleName\": \"entry_1\"" + "}" + "]," + "\"descriptionId\": 16777220," + "\"distro\": {" + "\"installationFree\": false," + "\"moduleType\": \"entry\"," + "\"moduleName\": \"test_module_name\"" + "}," + "\"preloads\": [" + "{" + "\"name\": \"test_name_1\"," + "\"moduleName\": \"test_module_name_1\"" + "}" + "]," + "\"package\": \"test_package\"," + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"targetModuleName\": \"test_module_targetBundleName\"," + "\"targetPriority\": 6," + "\"proxyDatas\": [" + "{" + "\"uri\": \"test_uri1\"" + "}," + "{" + "\"uri\": \"test_uri2\"" + "}" + "]," + "\"atomicService\": {" + "\"preloads\": [" + "{" + "\"atomicServiceObj\": \"test_atomicService\"" + "}" + "]" + "}," + "\"metadata\": [" + "{" + "\"name\": \"test_metadata\"," + "\"value\": \"test_value\"," + "\"resource\": \"test_resource\"" + "}" + "]," + "\"extensionAbilities\": [" + "{" + "\"name\": \"test_extension_abilities\"" + "}" + "]" + "}," + "\"deviceConfig\": {" + "\"default\": {\"debug\": true}" + "}" +"}"; +const std::string MAPLIST_CONVERT_STRING = "{" + "[" + "{" + "\"key\": \"value\"" + "}" + "]" +"}"; +const std::string TEST_STRING_NOTHING = "{" +"}"; +} + +class GeneralNormalizeTest : public testing::Test { +public: + GeneralNormalizeTest() {} + virtual ~GeneralNormalizeTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void GeneralNormalizeTest::SetUpTestCase() +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, HAP_OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "true"}, + {OHOS::AppPackingTool::Constants::PARAM_JSON_PATH, STAGE_JSON_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_ETS_PATH, STAGE_ETS_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_RESOURCES_PATH, STAGE_RESOURCES_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_INDEX_PATH, STAGE_INDEX_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_PACK_INFO_PATH, STAGE_PACK_INFO_PATH}, + }; + + OHOS::AppPackingTool::HapPackager hapPackager(parameterMap, resultReceiver); + system("mv /data/test/resource/packingtool/test_file/stage/pack.json " + "/data/test/resource/packingtool/test_file/stage/pack.info"); + system("mkdir /data/test/resource/packingtool/test_file/stage/ets"); + system("touch /data/test/resource/packingtool/test_file/stage/resources.index"); + EXPECT_EQ(hapPackager.InitAllowedParam(), 0); + EXPECT_EQ(hapPackager.PreProcess(), 0); + EXPECT_EQ(hapPackager.Process(), 0); + EXPECT_EQ(hapPackager.PostProcess(), 0); + system("rm -rf /data/test/resource/packingtool/test_file/stage"); + system("rm -rf /data/test/resource/packingtool/test_file/fa"); +} + +void GeneralNormalizeTest::TearDownTestCase() +{ + system("rm -rf /data/test/testouthap"); + system("rm -rf /data/test/entry-default-unsigned.hap"); +} + +void GeneralNormalizeTest::SetUp() {} + +void GeneralNormalizeTest::TearDown() {} + +/* + * @tc.name: InitAllowedParam_0100 + * @tc.desc: InitAllowedParam. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, InitAllowedParam_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = {}; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.InitAllowedParam(), 0); +} + +/* + * @tc.name: Process_0100 + * @tc.desc: Process + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, Process_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, HAP_INPUT_LIST}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_NAME, VERSION_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + }; + + system("mkdir /data/test/testouthap"); + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 0); + EXPECT_EQ(generalNormalize.Process(), 0); + system("rm -rf /data/test/testouthap"); +} + +/* + * @tc.name: Process_0200 + * @tc.desc: Process + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, Process_0200, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, HAP_INPUT_LIST}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_NAME, VERSION_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + }; + + system("mkdir /data/test/testouthap"); + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 0); + system("rm -rf /data/test/entry-default-unsigned.hap"); + system("touch /data/test/entry-default-unsigned.hap"); + EXPECT_EQ(generalNormalize.Process(), 1); + system("rm -rf /data/test/testouthap"); +} + +/* + * @tc.name: PreProcess_0100 + * @tc.desc: PreProcess + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, PreProcess_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); +} + +/* + * @tc.name: PreProcess_0200 + * @tc.desc: PreProcess + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, PreProcess_0200, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + }; + system("mkdir /data/test/testouthap"); + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); + system("rm -rf /data/test/testouthap"); +} + +/* + * @tc.name: PreProcess_0300 + * @tc.desc: PreProcess + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, PreProcess_0300, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, "module.json"}, + }; + system("mkdir /data/test/testouthap"); + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); + system("rm -rf /data/test/testouthap"); +} + +/* + * @tc.name: PreProcess_0400 + * @tc.desc: PreProcess + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, PreProcess_0400, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, INPUT_LIST}, + }; + system("mkdir /data/test/testouthap"); + system("mkdir /data/test/testinputhap"); + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); + system("rm -rf /data/test/testouthap"); + system("rm -rf /data/test/testinputhap"); +} + +/* + * @tc.name: PreProcess_0500 + * @tc.desc: PreProcess + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, PreProcess_0500, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, INPUT_LIST}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_NAME, INVAILD_PATTERN}, + }; + system("mkdir /data/test/testouthap"); + system("mkdir /data/test/testinputhap"); + system("touch /data/test/testinputhap/test.hap"); + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); + parameterMap[OHOS::AppPackingTool::Constants::PARAM_VERSION_NAME] = TOO_LONG_VERSION_NAME; + OHOS::AppPackingTool::GeneralNormalize generalNormalize2(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); + system("rm -rf /data/test/testouthap"); + system("rm -rf /data/test/testinputhap"); +} + +/* + * @tc.name: PreProcess_0600 + * @tc.desc: PreProcess + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, PreProcess_0600, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, INPUT_LIST}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_NAME, VERSION_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, INVAILD_PATTERN}, + }; + system("mkdir /data/test/testouthap"); + system("mkdir /data/test/testinputhap"); + system("touch /data/test/testinputhap/test.hap"); + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); + parameterMap[OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE] = INVAILD_INT_NUM; + OHOS::AppPackingTool::GeneralNormalize generalNormalize2(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); + system("rm -rf /data/test/testouthap"); + system("rm -rf /data/test/testinputhap"); +} + +/* + * @tc.name: PreProcess_0700 + * @tc.desc: PreProcess + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, PreProcess_0700, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, INPUT_LIST}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_NAME, VERSION_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_BUNDLE_NAME, INVAILD_PATTERN}, + }; + system("mkdir /data/test/testouthap"); + system("mkdir /data/test/testinputhap"); + system("touch /data/test/testinputhap/test.hap"); + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); + parameterMap[OHOS::AppPackingTool::Constants::PARAM_BUNDLE_NAME] = TOO_SHORT_BUNDLE_NAME; + OHOS::AppPackingTool::GeneralNormalize generalNormalize2(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); + parameterMap[OHOS::AppPackingTool::Constants::PARAM_BUNDLE_NAME] = TOO_LONG_BUNDLE_NAME; + OHOS::AppPackingTool::GeneralNormalize generalNormalize3(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); + system("rm -rf /data/test/testouthap"); + system("rm -rf /data/test/testinputhap"); +} + +/* + * @tc.name: PreProcess_0800 + * @tc.desc: PreProcess + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, PreProcess_0800, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, INPUT_LIST}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_NAME, VERSION_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_BUNDLE_NAME, BUNDLE_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_MIN_COMPATIBLE_VERSION_CODE, INVAILD_PATTERN}, + }; + system("mkdir /data/test/testouthap"); + system("mkdir /data/test/testinputhap"); + system("touch /data/test/testinputhap/test.hap"); + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); + parameterMap[OHOS::AppPackingTool::Constants::PARAM_MIN_COMPATIBLE_VERSION_CODE] = INVAILD_INT_NUM; + OHOS::AppPackingTool::GeneralNormalize generalNormalize2(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); + system("rm -rf /data/test/testouthap"); + system("rm -rf /data/test/testinputhap"); +} + +/* + * @tc.name: PreProcess_0900 + * @tc.desc: PreProcess + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, PreProcess_0900, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, INPUT_LIST}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_NAME, VERSION_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_BUNDLE_NAME, BUNDLE_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_MIN_COMPATIBLE_VERSION_CODE, MIN_COMPATIBLE_VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_MIN_API_VERSION, INVAILD_PATTERN}, + }; + system("mkdir /data/test/testouthap"); + system("mkdir /data/test/testinputhap"); + system("touch /data/test/testinputhap/test.hap"); + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); + parameterMap[OHOS::AppPackingTool::Constants::PARAM_MIN_API_VERSION] = INVAILD_INT_NUM; + OHOS::AppPackingTool::GeneralNormalize generalNormalize2(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); + system("rm -rf /data/test/testouthap"); + system("rm -rf /data/test/testinputhap"); +} + +/* + * @tc.name: PreProcess_1000 + * @tc.desc: PreProcess + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, PreProcess_1000, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, INPUT_LIST}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_NAME, VERSION_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_BUNDLE_NAME, BUNDLE_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_MIN_COMPATIBLE_VERSION_CODE, MIN_COMPATIBLE_VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_MIN_API_VERSION, MIN_API_VERSION}, + {OHOS::AppPackingTool::Constants::PARAM_TARGET_API_VERSION, INVAILD_PATTERN}, + }; + system("mkdir /data/test/testouthap"); + system("mkdir /data/test/testinputhap"); + system("touch /data/test/testinputhap/test.hap"); + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); + parameterMap[OHOS::AppPackingTool::Constants::PARAM_TARGET_API_VERSION] = INVAILD_INT_NUM; + OHOS::AppPackingTool::GeneralNormalize generalNormalize2(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); + system("rm -rf /data/test/testouthap"); + system("rm -rf /data/test/testinputhap"); +} + +/* + * @tc.name: PreProcess_1100 + * @tc.desc: PreProcess + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, PreProcess_1100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, INPUT_LIST}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_NAME, VERSION_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_BUNDLE_NAME, BUNDLE_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_MIN_COMPATIBLE_VERSION_CODE, MIN_COMPATIBLE_VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_MIN_API_VERSION, MIN_API_VERSION}, + {OHOS::AppPackingTool::Constants::PARAM_TARGET_API_VERSION, TARGET_API_VERSION}, + {OHOS::AppPackingTool::Constants::PARAM_API_RELEASE_TYPE, INVAILD_PATTERN}, + }; + system("mkdir /data/test/testouthap"); + system("mkdir /data/test/testinputhap"); + system("touch /data/test/testinputhap/test.hap"); + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); + system("rm -rf /data/test/testouthap"); + system("rm -rf /data/test/testinputhap"); +} + +/* + * @tc.name: PreProcess_1200 + * @tc.desc: PreProcess + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, PreProcess_1200, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, INPUT_LIST}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_NAME, VERSION_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_BUNDLE_NAME, BUNDLE_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_MIN_COMPATIBLE_VERSION_CODE, MIN_COMPATIBLE_VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_MIN_API_VERSION, MIN_API_VERSION}, + {OHOS::AppPackingTool::Constants::PARAM_TARGET_API_VERSION, TARGET_API_VERSION}, + {OHOS::AppPackingTool::Constants::PARAM_API_RELEASE_TYPE, API_RELEASE_TYPE}, + {OHOS::AppPackingTool::Constants::PARAM_BUNDLE_TYPE, INVAILD_PATTERN}, + }; + system("mkdir /data/test/testouthap"); + system("mkdir /data/test/testinputhap"); + system("touch /data/test/testinputhap/test.hap"); + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); + system("rm -rf /data/test/testouthap"); + system("rm -rf /data/test/testinputhap"); +} + +/* + * @tc.name: PreProcess_1300 + * @tc.desc: PreProcess + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, PreProcess_1300, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, INPUT_LIST}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_NAME, VERSION_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_BUNDLE_NAME, BUNDLE_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_MIN_COMPATIBLE_VERSION_CODE, MIN_COMPATIBLE_VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_MIN_API_VERSION, MIN_API_VERSION}, + {OHOS::AppPackingTool::Constants::PARAM_TARGET_API_VERSION, TARGET_API_VERSION}, + }; + system("mkdir /data/test/testouthap"); + system("mkdir /data/test/testinputhap"); + system("touch /data/test/testinputhap/test.hap"); + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 0); + system("rm -rf /data/test/testouthap"); + system("rm -rf /data/test/testinputhap"); +} + +/* + * @tc.name: PreProcess_1400 + * @tc.desc: PreProcess + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, PreProcess_1400, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, INPUT_LIST}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_NAME, VERSION_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_BUNDLE_NAME, BUNDLE_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_MIN_COMPATIBLE_VERSION_CODE, MIN_COMPATIBLE_VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_MIN_API_VERSION, MIN_API_VERSION}, + {OHOS::AppPackingTool::Constants::PARAM_TARGET_API_VERSION, TARGET_API_VERSION}, + {OHOS::AppPackingTool::Constants::PARAM_DEVICE_TYPES, INVALID_DEVICE_TYPES}, + }; + system("mkdir /data/test/testouthap"); + system("mkdir /data/test/testinputhap"); + system("touch /data/test/testinputhap/test.hap"); + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); + system("rm -rf /data/test/testouthap"); + system("rm -rf /data/test/testinputhap"); +} + +/* + * @tc.name: ModifyModuleJson_0100 + * @tc.desc: ModifyModuleJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyModuleJson_0100, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string moduleJsonPath = ""; + std::map modifyMap; + EXPECT_FALSE(generalNormalize.ModifyModuleJson(moduleJsonPath, modifyMap, bundleName, moduleName)); +} + +/* + * @tc.name: ModifyModuleJson_0200 + * @tc.desc: ModifyModuleJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyModuleJson_0200, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string moduleJsonPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << MODULE_JSON_STRING; + file.close(); + } + std::map modifyMap; + EXPECT_TRUE(generalNormalize.ModifyModuleJson(moduleJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyModuleJson_0300 + * @tc.desc: ModifyModuleJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyModuleJson_0300, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string moduleJsonPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + std::map modifyMap; + EXPECT_FALSE(generalNormalize.ModifyModuleJson(moduleJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyModuleJson_0400 + * @tc.desc: ModifyModuleJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyModuleJson_0400, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_VERSION_NAME, ""}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string moduleJsonPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + std::map modifyMap; + EXPECT_FALSE(generalNormalize.ModifyModuleJson(moduleJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyModuleJson_0500 + * @tc.desc: ModifyModuleJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyModuleJson_0500, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_BUNDLE_NAME, ""}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string moduleJsonPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + std::map modifyMap; + EXPECT_FALSE(generalNormalize.ModifyModuleJson(moduleJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyModuleJson_0600 + * @tc.desc: ModifyModuleJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyModuleJson_0600, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_MIN_COMPATIBLE_VERSION_CODE, MIN_COMPATIBLE_VERSION_CODE}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string moduleJsonPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + std::map modifyMap; + EXPECT_FALSE(generalNormalize.ModifyModuleJson(moduleJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyModuleJson_0700 + * @tc.desc: ModifyModuleJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyModuleJson_0700, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_MIN_API_VERSION, MIN_API_VERSION}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string moduleJsonPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + std::map modifyMap; + EXPECT_FALSE(generalNormalize.ModifyModuleJson(moduleJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyModuleJson_0800 + * @tc.desc: ModifyModuleJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyModuleJson_0800, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_TARGET_API_VERSION, TARGET_API_VERSION}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string moduleJsonPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + std::map modifyMap; + EXPECT_FALSE(generalNormalize.ModifyModuleJson(moduleJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyModuleJson_0900 + * @tc.desc: ModifyModuleJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyModuleJson_0900, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_API_RELEASE_TYPE, ""}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string moduleJsonPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + std::map modifyMap; + EXPECT_FALSE(generalNormalize.ModifyModuleJson(moduleJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyModuleJson_1000 + * @tc.desc: ModifyModuleJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyModuleJson_1000, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_BUNDLE_TYPE, ""}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string moduleJsonPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + std::map modifyMap; + EXPECT_FALSE(generalNormalize.ModifyModuleJson(moduleJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyModuleJson_1100 + * @tc.desc: ModifyModuleJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyModuleJson_1100, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_INSTALLATION_FREE, ""}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string moduleJsonPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + std::map modifyMap; + EXPECT_FALSE(generalNormalize.ModifyModuleJson(moduleJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyModuleJson_1200 + * @tc.desc: ModifyModuleJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyModuleJson_1200, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_DELIVERY_WITH_INSTALL, ""}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string moduleJsonPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + std::map modifyMap; + EXPECT_FALSE(generalNormalize.ModifyModuleJson(moduleJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyModuleJson_1300 + * @tc.desc: ModifyModuleJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyModuleJson_1300, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_DEVICE_TYPES, ""}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string moduleJsonPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + std::map modifyMap; + EXPECT_FALSE(generalNormalize.ModifyModuleJson(moduleJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyConfigJson_0100 + * @tc.desc: ModifyConfigJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyConfigJson_0100, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string configJsonPath = ""; + std::map modifyMap; + EXPECT_FALSE(generalNormalize.ModifyConfigJson(configJsonPath, modifyMap, bundleName, moduleName)); +} + +/* + * @tc.name: ModifyConfigJson_0200 + * @tc.desc: ModifyConfigJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyConfigJson_0200, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string configJsonPath = "/data/test/config.json"; + std::map modifyMap; + system("touch /data/test/config.json"); + system("chmod 777 /data/test/config.json"); + std::ofstream file("/data/test/config.json"); + if (file.is_open()) { + file << CONFIG_JSON_STRING; + file.close(); + } + EXPECT_TRUE(generalNormalize.ModifyConfigJson(configJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyConfigJson_0300 + * @tc.desc: ModifyConfigJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyConfigJson_0300, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string configJsonPath = "/data/test/config.json"; + std::map modifyMap; + system("touch /data/test/config.json"); + system("chmod 777 /data/test/config.json"); + std::ofstream file("/data/test/config.json"); + if (file.is_open()) { + file << CONFIG_JSON_STRING_NO_APP_VERSION; + file.close(); + } + EXPECT_FALSE(generalNormalize.ModifyConfigJson(configJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyConfigJson_0400 + * @tc.desc: ModifyConfigJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyConfigJson_0400, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_VERSION_NAME, ""}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string configJsonPath = "/data/test/config.json"; + std::map modifyMap; + system("touch /data/test/config.json"); + system("chmod 777 /data/test/config.json"); + std::ofstream file("/data/test/config.json"); + if (file.is_open()) { + file << CONFIG_JSON_STRING_NO_APP_VERSION; + file.close(); + } + EXPECT_FALSE(generalNormalize.ModifyConfigJson(configJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyConfigJson_0500 + * @tc.desc: ModifyConfigJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyConfigJson_0500, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_BUNDLE_NAME, ""}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string configJsonPath = "/data/test/config.json"; + std::map modifyMap; + system("touch /data/test/config.json"); + system("chmod 777 /data/test/config.json"); + std::ofstream file("/data/test/config.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + EXPECT_FALSE(generalNormalize.ModifyConfigJson(configJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyConfigJson_0600 + * @tc.desc: ModifyConfigJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyConfigJson_0600, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_MIN_COMPATIBLE_VERSION_CODE, MIN_COMPATIBLE_VERSION_CODE}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string configJsonPath = "/data/test/config.json"; + std::map modifyMap; + system("touch /data/test/config.json"); + system("chmod 777 /data/test/config.json"); + std::ofstream file("/data/test/config.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + EXPECT_FALSE(generalNormalize.ModifyConfigJson(configJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyConfigJson_0700 + * @tc.desc: ModifyConfigJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyConfigJson_0700, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_MIN_API_VERSION, MIN_API_VERSION}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string configJsonPath = "/data/test/config.json"; + std::map modifyMap; + system("touch /data/test/config.json"); + system("chmod 777 /data/test/config.json"); + std::ofstream file("/data/test/config.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + EXPECT_FALSE(generalNormalize.ModifyConfigJson(configJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyConfigJson_0800 + * @tc.desc: ModifyConfigJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyConfigJson_0800, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_TARGET_API_VERSION, TARGET_API_VERSION}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string configJsonPath = "/data/test/config.json"; + std::map modifyMap; + system("touch /data/test/config.json"); + system("chmod 777 /data/test/config.json"); + std::ofstream file("/data/test/config.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + EXPECT_FALSE(generalNormalize.ModifyConfigJson(configJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyConfigJson_0900 + * @tc.desc: ModifyConfigJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyConfigJson_0900, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_API_RELEASE_TYPE, ""}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string configJsonPath = "/data/test/config.json"; + std::map modifyMap; + system("touch /data/test/config.json"); + system("chmod 777 /data/test/config.json"); + std::ofstream file("/data/test/config.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + EXPECT_FALSE(generalNormalize.ModifyConfigJson(configJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyConfigJson_1000 + * @tc.desc: ModifyConfigJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyConfigJson_1000, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_BUNDLE_TYPE, ""}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string configJsonPath = "/data/test/config.json"; + std::map modifyMap; + system("touch /data/test/config.json"); + system("chmod 777 /data/test/config.json"); + std::ofstream file("/data/test/config.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + EXPECT_FALSE(generalNormalize.ModifyConfigJson(configJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} + + +/* + * @tc.name: ModifyConfigJson_1100 + * @tc.desc: ModifyConfigJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyConfigJson_1100, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_INSTALLATION_FREE, ""}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string configJsonPath = "/data/test/config.json"; + std::map modifyMap; + system("touch /data/test/config.json"); + system("chmod 777 /data/test/config.json"); + std::ofstream file("/data/test/config.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + EXPECT_FALSE(generalNormalize.ModifyConfigJson(configJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyConfigJson_1200 + * @tc.desc: ModifyConfigJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyConfigJson_1200, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_DELIVERY_WITH_INSTALL, ""}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string configJsonPath = "/data/test/config.json"; + std::map modifyMap; + system("touch /data/test/config.json"); + system("chmod 777 /data/test/config.json"); + std::ofstream file("/data/test/config.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + EXPECT_FALSE(generalNormalize.ModifyConfigJson(configJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} +/* + * @tc.name: ModifyConfigJson_1300 + * @tc.desc: ModifyConfigJson + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyConfigJson_1300, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_DEVICE_TYPES, ""}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string configJsonPath = "/data/test/config.json"; + std::map modifyMap; + system("touch /data/test/config.json"); + system("chmod 777 /data/test/config.json"); + std::ofstream file("/data/test/config.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + EXPECT_FALSE(generalNormalize.ModifyConfigJson(configJsonPath, modifyMap, bundleName, moduleName)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyPackInfo_0100 + * @tc.desc: ModifyPackInfo + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyPackInfo_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string packInfoPath = ""; + EXPECT_FALSE(generalNormalize.ModifyPackInfo(packInfoPath)); +} + +/* + * @tc.name: ModifyPackInfo_0200 + * @tc.desc: ModifyPackInfo + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyPackInfo_0200, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string packInfoPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << JSON_STRING; + file.close(); + } + EXPECT_TRUE(generalNormalize.ModifyPackInfo(packInfoPath)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyPackInfo_0300 + * @tc.desc: ModifyPackInfo + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyPackInfo_0300, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string packInfoPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << JSON_STRING_NO_APP_VERSION; + file.close(); + } + EXPECT_FALSE(generalNormalize.ModifyPackInfo(packInfoPath)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyPackInfo_0400 + * @tc.desc: ModifyPackInfo + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyPackInfo_0400, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_VERSION_NAME, ""}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string packInfoPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << JSON_STRING_NO_APP_VERSION; + file.close(); + } + EXPECT_FALSE(generalNormalize.ModifyPackInfo(packInfoPath)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyPackInfo_0500 + * @tc.desc: ModifyPackInfo + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyPackInfo_0500, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_BUNDLE_NAME, ""}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string packInfoPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << JSON_STRING_NO_BUNDLE_NAME; + file.close(); + } + EXPECT_FALSE(generalNormalize.ModifyPackInfo(packInfoPath)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyPackInfo_0600 + * @tc.desc: ModifyPackInfo + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyPackInfo_0600, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_MIN_COMPATIBLE_VERSION_CODE, MIN_COMPATIBLE_VERSION_CODE}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string packInfoPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + EXPECT_FALSE(generalNormalize.ModifyPackInfo(packInfoPath)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyPackInfo_0700 + * @tc.desc: ModifyPackInfo + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyPackInfo_0700, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_MIN_API_VERSION, MIN_API_VERSION}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string packInfoPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + EXPECT_FALSE(generalNormalize.ModifyPackInfo(packInfoPath)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyPackInfo_0800 + * @tc.desc: ModifyPackInfo + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyPackInfo_0800, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_TARGET_API_VERSION, TARGET_API_VERSION}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string packInfoPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + EXPECT_FALSE(generalNormalize.ModifyPackInfo(packInfoPath)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyPackInfo_0900 + * @tc.desc: ModifyPackInfo + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyPackInfo_0900, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_API_RELEASE_TYPE, ""}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string packInfoPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + EXPECT_FALSE(generalNormalize.ModifyPackInfo(packInfoPath)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyPackInfo_1000 + * @tc.desc: ModifyPackInfo + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyPackInfo_1000, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_BUNDLE_TYPE, ""}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string packInfoPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + EXPECT_FALSE(generalNormalize.ModifyPackInfo(packInfoPath)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyPackInfo_1100 + * @tc.desc: ModifyPackInfo + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyPackInfo_1100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_INSTALLATION_FREE, ""}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string packInfoPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + EXPECT_FALSE(generalNormalize.ModifyPackInfo(packInfoPath)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyPackInfo_1200 + * @tc.desc: ModifyPackInfo + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyPackInfo_1200, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_DELIVERY_WITH_INSTALL, ""}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string packInfoPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + EXPECT_FALSE(generalNormalize.ModifyPackInfo(packInfoPath)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ModifyPackInfo_1300 + * @tc.desc: ModifyPackInfo + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ModifyPackInfo_1300, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_DEVICE_TYPES, ""}, + }; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::string packInfoPath = "/data/test/module.json"; + system("touch /data/test/module.json"); + system("chmod 777 /data/test/module.json"); + std::ofstream file("/data/test/module.json"); + if (file.is_open()) { + file << TEST_STRING_NOTHING; + file.close(); + } + EXPECT_FALSE(generalNormalize.ModifyPackInfo(packInfoPath)); + system("rm -f /data/test/module.json"); +} + +/* + * @tc.name: ProcessJsonFiles_0100 + * @tc.desc: ProcessJsonFiles + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ProcessJsonFiles_0100, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap; + std::string packingPath = "/data/test/generalnormalize_packing"; + system("mkdir /data/test/generalnormalize_packing"); + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::list> modifyMapList; + EXPECT_FALSE(generalNormalize.ProcessJsonFiles(packingPath, modifyMapList, bundleName, moduleName)); + system("rm -rf /data/test/generalnormalize_packing"); +} + +/* + * @tc.name: ProcessJsonFiles_0200 + * @tc.desc: ProcessJsonFiles + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ProcessJsonFiles_0200, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap; + std::string packingPath = "/data/test/generalnormalize_packing"; + system("mkdir /data/test/generalnormalize_packing"); + system("touch /data/test/generalnormalize_packing/module.json"); + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::list> modifyMapList; + EXPECT_FALSE(generalNormalize.ProcessJsonFiles(packingPath, modifyMapList, bundleName, moduleName)); + system("rm -rf /data/test/generalnormalize_packing"); +} + +/* + * @tc.name: ProcessJsonFiles_0300 + * @tc.desc: ProcessJsonFiles + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ProcessJsonFiles_0300, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap; + std::string packingPath = "/data/test/generalnormalize_packing"; + system("mkdir /data/test/generalnormalize_packing"); + system("touch /data/test/generalnormalize_packing/module.json"); + system("chmod 777 /data/test/generalnormalize_packing/module.json"); + std::ofstream file("/data/test/generalnormalize_packing/module.json"); + if (file.is_open()) { + file << MODULE_JSON_STRING; + file.close(); + } + std::list> modifyMapList; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_TRUE(generalNormalize.ProcessJsonFiles(packingPath, modifyMapList, bundleName, moduleName)); + system("rm -rf /data/test/generalnormalize_packing"); +} + +/* + * @tc.name: ProcessJsonFiles_0400 + * @tc.desc: ProcessJsonFiles + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ProcessJsonFiles_0400, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap; + std::string packingPath = "/data/test/generalnormalize_packing"; + system("mkdir /data/test/generalnormalize_packing"); + system("touch /data/test/generalnormalize_packing/module.json"); + system("chmod 777 /data/test/generalnormalize_packing/module.json"); + std::ofstream file("/data/test/generalnormalize_packing/module.json"); + if (file.is_open()) { + file << MODULE_JSON_STRING; + file.close(); + } + system("touch /data/test/generalnormalize_packing/pack.info"); + std::list> modifyMapList; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_FALSE(generalNormalize.ProcessJsonFiles(packingPath, modifyMapList, bundleName, moduleName)); + system("rm -rf /data/test/generalnormalize_packing"); +} + +/* + * @tc.name: ProcessJsonFiles_0500 + * @tc.desc: ProcessJsonFiles + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ProcessJsonFiles_0500, Function | MediumTest | Level1) +{ + std::string bundleName = ""; + std::string moduleName = ""; + std::string resultReceiver; + std::map parameterMap; + std::string packingPath = "/data/test/generalnormalize_packing"; + system("mkdir /data/test/generalnormalize_packing"); + system("touch /data/test/generalnormalize_packing/config.json"); + system("chmod 777 /data/test/generalnormalize_packing/config.json"); + std::ofstream file("/data/test/generalnormalize_packing/config.json"); + if (file.is_open()) { + file << CONFIG_JSON_STRING; + file.close(); + } + std::list> modifyMapList; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_TRUE(generalNormalize.ProcessJsonFiles(packingPath, modifyMapList, bundleName, moduleName)); + system("rm -rf /data/test/generalnormalize_packing"); +} + +/* + * @tc.name: ConvertMapListToString_0100 + * @tc.desc: ConvertMapListToString + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ConvertMapListToString_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::list> modifyMapList; + EXPECT_EQ(generalNormalize.ConvertMapListToString(modifyMapList), "[]"); +} + +/* + * @tc.name: ConvertMapListToString_0200 + * @tc.desc: ConvertMapListToString + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, ConvertMapListToString_0200, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + std::list> modifyMapList; + std::map modifyMap; + modifyMap["key"] = "value"; + modifyMapList.push_back(modifyMap); + EXPECT_EQ(generalNormalize.ConvertMapListToString(modifyMapList), "[{\"key\":\"value\"}]"); +} + +/* + * @tc.name: CompressDirToHap_0100 + * @tc.desc: CompressDirToHap + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, CompressDirToHap_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap; + std::string sourceDir = "/data/test/sourcedir"; + system("mkdir /data/test/sourcedir"); + system("mkdir /data/test/sourcedir/ets"); + system("mkdir /data/test/sourcedir/hnp"); + system("mkdir /data/test/sourcedir/libs"); + system("mkdir /data/test/sourcedir/an"); + system("mkdir /data/test/sourcedir/ap"); + system("mkdir /data/test/sourcedir/resources"); + system("mkdir /data/test/sourcedir/js"); + system("mkdir /data/test/sourcedir/assets"); + system("mkdir /data/test/sourcedir/maple"); + system("mkdir /data/test/sourcedir/shared_libs"); + system("touch /data/test/sourcedir/config.json"); + system("chmod 777 /data/test/sourcedir/config.json"); + system("touch /data/test/sourcedir/resources.index"); + system("chmod 777 /data/test/sourcedir/resources.index"); + system("touch /data/test/sourcedir/pack.info"); + system("chmod 777 /data/test/sourcedir/pack.info"); + system("touch /data/test/sourcedir/rpcid.sc"); + system("chmod 777 /data/test/sourcedir/rpcid.sc"); + + std::string zipFilePath = "/data/test/sourcedir/test.hsp"; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_FALSE(generalNormalize.CompressDirToHap(sourceDir, zipFilePath)); + system("rm -rf /data/test/sourcedir"); +} +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/json/module_json_fa_test/BUILD.gn b/packing_tool/frameworks/test/unittest/json/module_json_fa_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f2305e59ec89ad42516aa45e558c07da05c23d46 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/module_json_fa_test/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("module_json_test_config") { + include_dirs = [ + "../../../../include", + "../../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("module_json_fa_test") { + module_out_path = module_output_path + public_configs = [ ":module_json_test_config" ] + sources = [ + "../../../../src/json/distro_filter.cpp", + "../../../../src/json/hap_verify_info.cpp", + "../../../../src/json/module_json.cpp", + "../../../../src/json/module_json_fa.cpp", + "../../../../src/json/module_json_stage.cpp", + "../../../../src/json/pt_json.cpp", + "../../../../src/log.cpp", + "../../../../src/utils.cpp", + "module_json_fa_test.cpp", + ] + external_deps = [ + "bounds_checking_function:libsec_static", + "cJSON:cjson_static", + "hilog:libhilog", + "openssl:libcrypto_shared", + "zlib:libz", + ] +} + +group("unittest") { + testonly = true + deps = [ ":module_json_fa_test" ] +} diff --git a/packing_tool/frameworks/test/unittest/json/module_json_fa_test/module_json_fa_test.cpp b/packing_tool/frameworks/test/unittest/json/module_json_fa_test/module_json_fa_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..def980803c099bfeb7f0fec078a1ec39a015c5e0 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/module_json_fa_test/module_json_fa_test.cpp @@ -0,0 +1,802 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "module_json.h" +#include "pt_json.h" +#include "log.h" + +using namespace testing; +using namespace testing::ext; +using namespace std; +using namespace OHOS::AppPackingTool; + +namespace OHOS { +namespace { +const std::string MODULE_JSON_TEST_STRING = "{" +"\"app\": {" + "\"bundleName\": \"test_bundle_name\"," + "\"iconId\": 16777217," + "\"labelId\": 16777216," + "\"version\": {" + "}," + "\"apiVersion\": {" + "}," + "\"targetBundleName\": \"test_app_targetBundleName\"," + "\"multiAppMode\": {" + "\"multiAppModeType\": \"test_multiAppMode\"," + "\"maxCount\": 9" + "}," + "\"generateBuildHash\": true," + "\"asanEnabled\": true," + "\"tsanEnabled\": false," + "\"compressNativeLibs\": true," + "\"targetPriority\": 5" + "}," + "\"module\": {" + "\"distro\": {" + "}" + "}" +"}"; + +const std::string MODULE_JSON_TEST_STRING_NOTHING = "{" +"}"; + +const std::string MODULE_JSON_TEST_ONLYAPP = "{" +"\"app\": {" + "\"bundleName\": \"test_bundle_name\"," + "\"bundleType\": \"atomicService\"," + "\"vendor\": \"\"," + "\"icon\": \"media:app_icon\"," + "\"label\": \"string:app_name\"," + "\"apiReleaseType\": \"Canary\"," + "\"compileSdkVersion\": \"test_compileSdkVersion\"," + "\"targetAPIVersion\": 10," + "\"minAPIVersion\": 10," + "\"compileSdkType\": \"OpenHarmony\"," + "\"debug\": true," + "\"iconId\": 16777217," + "\"labelId\": 16777216," + "\"version\": {" + "\"code\": 666," + "\"name\": \"test_version\"," + "\"minCompatibleVersionCode\": 555" + "}," + "\"apiVersion\": {" + "\"compileSdkType\": \"OpenHarmony\"," + "\"compileSdkVersion\": \"test_apiVersion_compileSdkVersion\"," + "\"releaseType\": \"test_apiVersion_release\"," + "\"compatible\": 7," + "\"target\": 10" + "}," + "\"targetBundleName\": \"test_app_targetBundleName\"," + "\"multiAppMode\": {" + "\"multiAppModeType\": \"test_multiAppMode\"," + "\"maxCount\": 9" + "}," + "\"generateBuildHash\": true," + "\"minCompatibleVersionCode\": 99," + "\"asanEnabled\": true," + "\"tsanEnabled\": false," + "\"compressNativeLibs\": true," + "\"targetPriority\": 5" + "}," + "\"module\": {" + "}" +"}"; + +const std::string MODULE_JSON_ERROR_APIRELEASETYPE = "{" +"\"app\": {" + "\"bundleName\": \"test_bundle_name\"," + "\"bundleType\": \"atomicService\"," + "\"vendor\": \"\"," + "\"icon\": \"media:app_icon\"," + "\"label\": \"string:app_name\"," + "\"apiReleaseType\": true," + "\"compileSdkVersion\": \"test_compileSdkVersion\"," + "\"targetAPIVersion\": 10," + "\"minAPIVersion\": 10," + "\"compileSdkType\": \"OpenHarmony\"," + "\"debug\": true," + "\"iconId\": 16777217," + "\"labelId\": 16777216," + "\"version\": {" + "\"code\": 666," + "\"name\": \"test_version\"," + "\"minCompatibleVersionCode\": 555" + "}," + "\"apiVersion\": {" + "\"compileSdkType\": \"OpenHarmony\"," + "\"compileSdkVersion\": \"test_apiVersion_compileSdkVersion\"," + "\"releaseType\": \"test_apiVersion_release\"," + "\"compatible\": 7," + "\"target\": 10" + "}," + "\"targetBundleName\": \"test_app_targetBundleName\"," + "\"multiAppMode\": {" + "\"multiAppModeType\": \"test_multiAppMode\"," + "\"maxCount\": 9" + "}," + "\"generateBuildHash\": true," + "\"minCompatibleVersionCode\": 99," + "\"asanEnabled\": true," + "\"tsanEnabled\": false," + "\"compressNativeLibs\": true," + "\"targetPriority\": 5" + "}" +"}"; + +const std::string MODULE_JSON_TEST_NOMODULETYPE = "{" + "\"app\": {" + "\"bundleName\": \"test_bundle_name\"," + "\"bundleType\": \"atomicService\"," + "\"vendor\": \"\"," + "\"icon\": \"media:app_icon\"," + "\"label\": \"string:app_name\"," + "\"apiReleaseType\": \"Canary\"," + "\"compileSdkVersion\": \"test_compileSdkVersion\"," + "\"targetAPIVersion\": 10," + "\"minAPIVersion\": 10," + "\"compileSdkType\": \"OpenHarmony\"," + "\"debug\": true," + "\"iconId\": 16777217," + "\"labelId\": 16777216," + "\"version\": {" + "\"code\": 666," + "\"name\": \"test_version\"," + "\"minCompatibleVersionCode\": 555" + "}," + "\"apiVersion\": {" + "\"compileSdkType\": \"OpenHarmony\"," + "\"compileSdkVersion\": \"test_apiVersion_compileSdkVersion\"," + "\"releaseType\": \"test_apiVersion_release\"," + "\"compatible\": 7," + "\"target\": 10" + "}," + "\"targetBundleName\": \"test_app_targetBundleName\"," + "\"multiAppMode\": {" + "\"multiAppModeType\": \"test_multiAppMode\"," + "\"maxCount\": 9" + "}," + "\"generateBuildHash\": true," + "\"minCompatibleVersionCode\": 99," + "\"asanEnabled\": true," + "\"tsanEnabled\": false," + "\"compressNativeLibs\": true," + "\"targetPriority\": 5" + "}," + "\"module\": {" + "\"name\": \"entry\"," + "\"description\": \"string:module_desc\"," + "\"mainElement\": \"EntryAbility\"," + "\"deviceTypes\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"deliveryWithInstall\": true," + "\"installationFree\": true," + "\"pages\": \"profile:main_pages\"," + "\"abilities\": [" + "{" + "\"name\": \"EntryAbility\"," + "\"moduleName\": \"test_module_name\"," + "\"srcEntry\": \"./ets/entryability/EntryAbility.ts\"," + "\"description\": \"string:EntryAbility_desc\"," + "\"icon\": \"media:icon\"," + "\"label\": \"string:EntryAbility_label\"," + "\"startWindowIcon\": \"media:icon\"," + "\"startWindowBackground\": \"color:start_window_background\"," + "\"exported\": true," + "\"skills\": [" + "{" + "\"entities\": [\"entity.system.home\"]," + "\"actions\": [\"action.system.home\"]" + "}" + "]," + "\"descriptionId\": 16777218," + "\"iconId\": 16777222," + "\"labelId\": 16777219," + "\"startWindowIconId\": 16777222," + "\"startWindowBackgroundId\": 16777221," + "\"continueType\":[]" + "}" + "]," + "\"virtualMachine\": \"test_virtualMachine\"," + "\"compileMode\": \"esmodule\"," + "\"dependencies\": [" + "{" + "\"bundleName\": \"test_modules_dependency_1\"," + "\"moduleName\": \"entry_1\"" + "}," + "{" + "\"bundleName\": \"test_modules_dependency_2\"," + "\"moduleName\": \"entry_1\"" + "}" + "]," + "\"descriptionId\": 16777220," + "\"distro\": {" + "\"installationFree\": false," + "\"moduleType\": \"entry\"," + "\"moduleName\": \"test_module_name\"" + "}," + "\"preloads\": [" + "{" + "\"name\": \"test_name_1\"," + "\"moduleName\": \"test_module_name_1\"" + "}" + "]," + "\"package\": \"test_package\"," + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"targetModuleName\": \"test_module_targetBundleName\"," + "\"targetPriority\": 6," + "\"proxyDatas\": [" + "{" + "\"uri\": \"test_uri1\"" + "}," + "{" + "\"uri\": \"test_uri2\"" + "}" + "]," + "\"atomicService\": {" + "\"preloads\": [" + "{" + "\"atomicServiceObj\": \"test_atomicService\"" + "}" + "]" + "}," + "\"metadata\": [" + "{" + "\"name\": \"test_metadata\"," + "\"value\": \"test_value\"," + "\"resource\": \"test_resource\"" + "}" + "]," + "\"extensionAbilities\": [" + "{" + "\"name\": \"test_extension_abilities\"" + "}" + "]" + "}," + "\"deviceConfig\": {" + "\"default\": {\"debug\": true}" + "}" +"}"; +} + +class ModuleJsonFaTest : public testing::Test { +public: + ModuleJsonFaTest() {} + virtual ~ModuleJsonFaTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void ModuleJsonFaTest::SetUpTestCase() {} + +void ModuleJsonFaTest::TearDownTestCase() {} + +void ModuleJsonFaTest::SetUp() {} + +void ModuleJsonFaTest::TearDown() {} + +/* + * @tc.name: SetFaBundleName_0100 + * @tc.desc: SetFaBundleName + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaBundleName_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string bundleName = "app"; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING_NOTHING)); + EXPECT_FALSE(moduleJson.SetFaBundleName(bundleName)); +} + +/* + * @tc.name: SetFaBundleName_0200 + * @tc.desc: SetFaBundleName + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaBundleName_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string bundleName = "app"; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING)); + EXPECT_TRUE(moduleJson.SetFaBundleName(bundleName)); +} + +/* + * @tc.name: SetFaBundleName_0300 + * @tc.desc: SetFaBundleName + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaBundleName_0300, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string bundleName = ""; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetFaBundleName(bundleName)); +} + +/* + * @tc.name: SetFaBundleName_0400 + * @tc.desc: SetFaBundleName + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaBundleName_0400, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string bundleName = "app"; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetFaBundleName(bundleName)); +} + +/* + * @tc.name: SetFaMinCompatibleVersionCode_0100 + * @tc.desc: SetFaMinCompatibleVersionCode + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaMinCompatibleVersionCode_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t minCompatibleVersionCode = 99; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING_NOTHING)); + EXPECT_FALSE(moduleJson.SetFaMinCompatibleVersionCode(minCompatibleVersionCode)); +} + +/* + * @tc.name: SetFaMinCompatibleVersionCode_0200 + * @tc.desc: SetFaMinCompatibleVersionCode + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaMinCompatibleVersionCode_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t minCompatibleVersionCode = 99; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING)); + EXPECT_TRUE(moduleJson.SetFaMinCompatibleVersionCode(minCompatibleVersionCode)); +} + +/* + * @tc.name: SetFaMinCompatibleVersionCode_0300 + * @tc.desc: SetFaMinCompatibleVersionCode + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaMinCompatibleVersionCode_0300, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t minCompatibleVersionCode = -1; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetFaMinCompatibleVersionCode(minCompatibleVersionCode)); +} + +/* + * @tc.name: SetFaMinCompatibleVersionCode_0400 + * @tc.desc: SetFaMinCompatibleVersionCode + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaMinCompatibleVersionCode_0400, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t minCompatibleVersionCode = 99; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetFaMinCompatibleVersionCode(minCompatibleVersionCode)); +} + +/* + * @tc.name: SetFaMinAPIVersion_0100 + * @tc.desc: SetFaMinAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaMinAPIVersion_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t minAPIVersion = 1; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING_NOTHING)); + EXPECT_FALSE(moduleJson.SetFaMinAPIVersion(minAPIVersion)); +} + +/* + * @tc.name: SetFaMinAPIVersion_0200 + * @tc.desc: SetFaMinAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaMinAPIVersion_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t minAPIVersion = 1; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING)); + EXPECT_TRUE(moduleJson.SetFaMinAPIVersion(minAPIVersion)); +} + +/* + * @tc.name: SetFaMinAPIVersion_0300 + * @tc.desc: SetFaMinAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaMinAPIVersion_0300, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t minAPIVersion = -1; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetFaMinAPIVersion(minAPIVersion)); +} + +/* + * @tc.name: SetFaMinAPIVersion_0400 + * @tc.desc: SetFaMinAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaMinAPIVersion_0400, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t minAPIVersion = 1; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetFaMinAPIVersion(minAPIVersion)); +} + +/* + * @tc.name: SetFaTargetAPIVersion_0100 + * @tc.desc: SetFaTargetAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaTargetAPIVersion_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t targetAPIVersion = 1; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING_NOTHING)); + EXPECT_FALSE(moduleJson.SetFaMinAPIVersion(targetAPIVersion)); +} + +/* + * @tc.name: SetFaTargetAPIVersion_0200 + * @tc.desc: SetFaTargetAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaTargetAPIVersion_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t targetAPIVersion = 1; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING)); + EXPECT_TRUE(moduleJson.SetFaMinAPIVersion(targetAPIVersion)); +} + + +/* + * @tc.name: SetFaTargetAPIVersion_0300 + * @tc.desc: SetFaTargetAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaTargetAPIVersion_0300, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t targetAPIVersion = -1; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetFaMinAPIVersion(targetAPIVersion)); +} + +/* + * @tc.name: SetFaTargetAPIVersion_0400 + * @tc.desc: SetFaTargetAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaTargetAPIVersion_0400, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t targetAPIVersion = 1; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetFaMinAPIVersion(targetAPIVersion)); +} + +/* + * @tc.name: SetFaApiReleaseType_0100 + * @tc.desc: SetFaApiReleaseType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaApiReleaseType_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string apiReleaseType = "Canary"; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING_NOTHING)); + EXPECT_FALSE(moduleJson.SetFaApiReleaseType(apiReleaseType)); +} + +/* + * @tc.name: SetFaApiReleaseType_0200 + * @tc.desc: SetFaApiReleaseType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaApiReleaseType_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string apiReleaseType = "Canary"; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING)); + EXPECT_TRUE(moduleJson.SetFaApiReleaseType(apiReleaseType)); +} + +/* + * @tc.name: SetFaApiReleaseType_0300 + * @tc.desc: SetFaApiReleaseType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaApiReleaseType_0300, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string apiReleaseType = ""; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetFaApiReleaseType(apiReleaseType)); +} + +/* + * @tc.name: SetFaApiReleaseType_0400 + * @tc.desc: SetFaApiReleaseType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaApiReleaseType_0400, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string apiReleaseType = "Canary"; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetFaApiReleaseType(apiReleaseType)); +} + +/* + * @tc.name: SetFaBundleType_0100 + * @tc.desc: SetFaBundleType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaBundleType_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string bundleType = "test_bundle_type"; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING_NOTHING)); + EXPECT_FALSE(moduleJson.SetFaBundleType(bundleType)); +} + +/* + * @tc.name: SetFaBundleType_0200 + * @tc.desc: SetFaBundleType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaBundleType_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string bundleType = "test_bundle_type"; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING)); + EXPECT_TRUE(moduleJson.SetFaBundleType(bundleType)); +} + +/* + * @tc.name: SetFaBundleType_0300 + * @tc.desc: SetFaBundleType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaBundleType_0300, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string bundleType = ""; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetFaBundleType(bundleType)); +} + +/* + * @tc.name: SetFaBundleType_0400 + * @tc.desc: SetFaBundleType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaBundleType_0400, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string bundleType = "test_bundle_type"; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetFaBundleType(bundleType)); +} + +/* + * @tc.name: SetFaInstallationFree_0100 + * @tc.desc: SetFaInstallationFree + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaInstallationFree_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + bool installationFree = false; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING_NOTHING)); + EXPECT_FALSE(moduleJson.SetFaInstallationFree(installationFree)); +} + +/* + * @tc.name: SetFaInstallationFree_0200 + * @tc.desc: SetFaInstallationFree + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaInstallationFree_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + bool installationFree = false; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING)); + EXPECT_TRUE(moduleJson.SetFaInstallationFree(installationFree)); +} + +/* + * @tc.name: SetFaInstallationFree_0300 + * @tc.desc: SetFaInstallationFree + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaInstallationFree_0300, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + bool installationFree = false; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_NOMODULETYPE)); + EXPECT_TRUE(moduleJson.SetFaInstallationFree(installationFree)); +} + +/* + * @tc.name: SetFaDeliveryWithInstall_0100 + * @tc.desc: SetFaDeliveryWithInstall + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaDeliveryWithInstall_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + bool deliveryWithInstall = false; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING_NOTHING)); + EXPECT_FALSE(moduleJson.SetFaDeliveryWithInstall(deliveryWithInstall)); +} + +/* + * @tc.name: SetFaDeliveryWithInstall_0200 + * @tc.desc: SetFaDeliveryWithInstall + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaDeliveryWithInstall_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + bool deliveryWithInstall = false; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING)); + EXPECT_TRUE(moduleJson.SetFaDeliveryWithInstall(deliveryWithInstall)); +} + +/* + * @tc.name: SetFaDeliveryWithInstall_0300 + * @tc.desc: SetFaDeliveryWithInstall + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaDeliveryWithInstall_0300, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + bool deliveryWithInstall = false; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_NOMODULETYPE)); + EXPECT_TRUE(moduleJson.SetFaDeliveryWithInstall(deliveryWithInstall)); +} + +/* + * @tc.name: SetFaDeviceTypes_0100 + * @tc.desc: SetFaDeviceTypes + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaDeviceTypes_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::list deviceTypes; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING_NOTHING)); + EXPECT_FALSE(moduleJson.SetFaDeviceTypes(deviceTypes)); +} + +/* + * @tc.name: SetFaDeviceTypes_0200 + * @tc.desc: SetFaDeviceTypes + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaDeviceTypes_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::list deviceTypes; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING)); + EXPECT_TRUE(moduleJson.SetFaDeviceTypes(deviceTypes)); +} + +/* + * @tc.name: SetFaDeviceTypes_0300 + * @tc.desc: SetFaDeviceTypes + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonFaTest, SetFaDeviceTypes_0300, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::list deviceTypes = {"default", "tablet"}; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_NOMODULETYPE)); + EXPECT_TRUE(moduleJson.SetFaDeviceTypes(deviceTypes)); +} +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/json/module_json_stage_test/module_json_stage_test.cpp b/packing_tool/frameworks/test/unittest/json/module_json_stage_test/module_json_stage_test.cpp index 4ee63b3b47d2212678472111096612e978038aee..06b5466bbf7232c612d1738462c7b9ba0b90589b 100644 --- a/packing_tool/frameworks/test/unittest/json/module_json_stage_test/module_json_stage_test.cpp +++ b/packing_tool/frameworks/test/unittest/json/module_json_stage_test/module_json_stage_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -2239,4 +2239,500 @@ HWTEST_F(ModuleJsonStageTest, GetStageBundleType_0500, Function | MediumTest | L EXPECT_TRUE(moduleJson.GetStageBundleType(bundleType)); EXPECT_STREQ(bundleType.c_str(), "atomicService"); } + +/* + * @tc.name: SetStageBundleName_0100 + * @tc.desc: SetStageBundleName + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageBundleName_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string bundleType = "app"; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING_NOTHING)); + EXPECT_FALSE(moduleJson.SetStageBundleName(bundleType)); +} + +/* + * @tc.name: SetStageBundleName_0200 + * @tc.desc: SetStageBundleName + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageBundleName_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string bundleType = "app"; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING)); + EXPECT_TRUE(moduleJson.SetStageBundleName(bundleType)); +} + +/* + * @tc.name: SetStageBundleName_0300 + * @tc.desc: SetStageBundleName + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageBundleName_0300, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string bundleType = ""; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetStageBundleName(bundleType)); +} + +/* + * @tc.name: SetStageBundleName_0400 + * @tc.desc: SetStageBundleName + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageBundleName_0400, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string bundleType = "app"; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetStageBundleName(bundleType)); +} + +/* + * @tc.name: SetStageMinCompatibleVersionCode_0100 + * @tc.desc: SetStageMinCompatibleVersionCode + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageMinCompatibleVersionCode_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t minCompatibleVersionCode = 99; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING_NOTHING)); + EXPECT_FALSE(moduleJson.SetStageMinCompatibleVersionCode(minCompatibleVersionCode)); +} + +/* + * @tc.name: SetStageMinCompatibleVersionCode_0200 + * @tc.desc: SetStageMinCompatibleVersionCode + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageMinCompatibleVersionCode_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t minCompatibleVersionCode = 99; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING)); + EXPECT_TRUE(moduleJson.SetStageMinCompatibleVersionCode(minCompatibleVersionCode)); +} + +/* + * @tc.name: SetStageMinCompatibleVersionCode_0300 + * @tc.desc: SetStageMinCompatibleVersionCode + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageMinCompatibleVersionCode_0300, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t minCompatibleVersionCode = -1; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetStageMinCompatibleVersionCode(minCompatibleVersionCode)); +} + +/* + * @tc.name: SetStageMinCompatibleVersionCode_0400 + * @tc.desc: SetStageMinCompatibleVersionCode + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageMinCompatibleVersionCode_0400, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t minCompatibleVersionCode = 99; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetStageMinCompatibleVersionCode(minCompatibleVersionCode)); +} + +/* + * @tc.name: SetStageMinAPIVersion_0100 + * @tc.desc: SetStageMinAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageMinAPIVersion_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t minAPIVersion = 1; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING_NOTHING)); + EXPECT_FALSE(moduleJson.SetStageMinAPIVersion(minAPIVersion)); +} + +/* + * @tc.name: SetStageMinAPIVersion_0200 + * @tc.desc: SetStageMinAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageMinAPIVersion_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t minAPIVersion = 1; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING)); + EXPECT_TRUE(moduleJson.SetStageMinAPIVersion(minAPIVersion)); +} + +/* + * @tc.name: SetStageMinAPIVersion_0300 + * @tc.desc: SetStageMinAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageMinAPIVersion_0300, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t minAPIVersion = -1; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetStageMinAPIVersion(minAPIVersion)); +} + +/* + * @tc.name: SetStageMinAPIVersion_0400 + * @tc.desc: SetStageMinAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageMinAPIVersion_0400, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t minAPIVersion = 1; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetStageMinAPIVersion(minAPIVersion)); +} + +/* + * @tc.name: SetStageTargetAPIVersion_0100 + * @tc.desc: SetStageTargetAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageTargetAPIVersion_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t targetAPIVersion = 1; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING_NOTHING)); + EXPECT_FALSE(moduleJson.SetStageMinAPIVersion(targetAPIVersion)); +} + +/* + * @tc.name: SetStageTargetAPIVersion_0200 + * @tc.desc: SetStageTargetAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageTargetAPIVersion_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t targetAPIVersion = 1; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING)); + EXPECT_TRUE(moduleJson.SetStageMinAPIVersion(targetAPIVersion)); +} + + +/* + * @tc.name: SetStageTargetAPIVersion_0300 + * @tc.desc: SetStageTargetAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageTargetAPIVersion_0300, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t targetAPIVersion = -1; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetStageMinAPIVersion(targetAPIVersion)); +} + +/* + * @tc.name: SetStageTargetAPIVersion_0400 + * @tc.desc: SetStageTargetAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageTargetAPIVersion_0400, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + int32_t targetAPIVersion = 1; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetStageMinAPIVersion(targetAPIVersion)); +} + +/* + * @tc.name: SetStageApiReleaseType_0100 + * @tc.desc: SetStageApiReleaseType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageApiReleaseType_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string apiReleaseType = "Canary"; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING_NOTHING)); + EXPECT_FALSE(moduleJson.SetStageApiReleaseType(apiReleaseType)); +} + +/* + * @tc.name: SetStageApiReleaseType_0200 + * @tc.desc: SetStageApiReleaseType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageApiReleaseType_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string apiReleaseType = "Canary"; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING)); + EXPECT_TRUE(moduleJson.SetStageApiReleaseType(apiReleaseType)); +} + +/* + * @tc.name: SetStageApiReleaseType_0300 + * @tc.desc: SetStageApiReleaseType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageApiReleaseType_0300, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string apiReleaseType = ""; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetStageApiReleaseType(apiReleaseType)); +} + +/* + * @tc.name: SetStageApiReleaseType_0400 + * @tc.desc: SetStageApiReleaseType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageApiReleaseType_0400, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string apiReleaseType = "Canary"; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetStageApiReleaseType(apiReleaseType)); +} + +/* + * @tc.name: SetStageBundleType_0100 + * @tc.desc: SetStageBundleType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageBundleType_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string bundleType = "test_bundle_type"; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING_NOTHING)); + EXPECT_FALSE(moduleJson.SetStageBundleType(bundleType)); +} + +/* + * @tc.name: SetStageBundleType_0200 + * @tc.desc: SetStageBundleType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageBundleType_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string bundleType = "test_bundle_type"; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING)); + EXPECT_TRUE(moduleJson.SetStageBundleType(bundleType)); +} + +/* + * @tc.name: SetStageBundleType_0300 + * @tc.desc: SetStageBundleType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageBundleType_0300, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string bundleType = ""; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetStageBundleType(bundleType)); +} + +/* + * @tc.name: SetStageBundleType_0400 + * @tc.desc: SetStageBundleType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageBundleType_0400, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string bundleType = "test_bundle_type"; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_ONLYAPP)); + EXPECT_TRUE(moduleJson.SetStageBundleType(bundleType)); +} + +/* + * @tc.name: SetStageInstallationFree_0100 + * @tc.desc: SetStageInstallationFree + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageInstallationFree_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + bool installationFree = false; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING_NOTHING)); + EXPECT_FALSE(moduleJson.SetStageInstallationFree(installationFree)); +} + +/* + * @tc.name: SetStageInstallationFree_0200 + * @tc.desc: SetStageInstallationFree + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageInstallationFree_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + bool installationFree = false; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING)); + EXPECT_TRUE(moduleJson.SetStageInstallationFree(installationFree)); +} + +/* + * @tc.name: SetStageInstallationFree_0300 + * @tc.desc: SetStageInstallationFree + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageInstallationFree_0300, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + bool installationFree = false; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_NOMODULETYPE)); + EXPECT_TRUE(moduleJson.SetStageInstallationFree(installationFree)); +} + +/* + * @tc.name: SetStageDeliveryWithInstall_0100 + * @tc.desc: SetStageDeliveryWithInstall + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageDeliveryWithInstall_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + bool deliveryWithInstall = false; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING_NOTHING)); + EXPECT_FALSE(moduleJson.SetStageDeliveryWithInstall(deliveryWithInstall)); +} + +/* + * @tc.name: SetStageDeliveryWithInstall_0200 + * @tc.desc: SetStageDeliveryWithInstall + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageDeliveryWithInstall_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + bool deliveryWithInstall = false; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING)); + EXPECT_TRUE(moduleJson.SetStageDeliveryWithInstall(deliveryWithInstall)); +} + +/* + * @tc.name: SetStageDeliveryWithInstall_0300 + * @tc.desc: SetStageDeliveryWithInstall + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageDeliveryWithInstall_0300, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + bool deliveryWithInstall = false; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_NOMODULETYPE)); + EXPECT_TRUE(moduleJson.SetStageDeliveryWithInstall(deliveryWithInstall)); +} + +/* + * @tc.name: SetStageDeviceTypes_0100 + * @tc.desc: SetStageDeviceTypes + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageDeviceTypes_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::list deviceTypes; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING_NOTHING)); + EXPECT_FALSE(moduleJson.SetStageDeviceTypes(deviceTypes)); +} + +/* + * @tc.name: SetStageDeviceTypes_0200 + * @tc.desc: SetStageDeviceTypes + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageDeviceTypes_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::list deviceTypes; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING)); + EXPECT_TRUE(moduleJson.SetStageDeviceTypes(deviceTypes)); +} + +/* + * @tc.name: SetStageDeviceTypes_0300 + * @tc.desc: SetStageDeviceTypes + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonStageTest, SetStageDeviceTypes_0300, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::list deviceTypes = {"default", "tablet"}; + moduleJson.Release(); + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_STRING)); + EXPECT_TRUE(moduleJson.SetStageDeviceTypes(deviceTypes)); +} } \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/json/module_json_test/module_json_test.cpp b/packing_tool/frameworks/test/unittest/json/module_json_test/module_json_test.cpp index e008ef6af24c911581bb1471b451949a9ce7c461..f0867ded29913ffeae9ed410a9127854a7f000ab 100755 --- a/packing_tool/frameworks/test/unittest/json/module_json_test/module_json_test.cpp +++ b/packing_tool/frameworks/test/unittest/json/module_json_test/module_json_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -1570,6 +1570,24 @@ const std::string MODULE_DEVICE_TYPE_NOT_ARRAY_TEST_JSON_STRING = "{" "\"deviceType\": \"test\"" "}" "}"; + +const std::string APP_ERROR_MIN_API_VERSION = "{" + "\"app\": {" + "\"minAPIVersion\": true" + "}" +"}"; + +const std::string APP_ERROR_TARGET_API_VERSION = "{" + "\"app\": {" + "\"targetAPIVersion\": true" + "}" +"}"; + +const std::string APP_ERROR_DELIVERY_WITH_INSTALL = "{" + "\"app\": {" + "\"deliveryWithInstall\": 123" + "}" +"}"; } class ModuleJsonTest : public testing::Test { public: @@ -1731,7 +1749,7 @@ HWTEST_F(ModuleJsonTest, GetApiVersionObject_0300, Function | MediumTest | Level EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_TEST_STRING_ERROR)); std::unique_ptr apiVersion; EXPECT_FALSE(moduleJson.GetApiVersionObject(apiVersion)); - EXPECT_EQ(apiVersion, nullptr); + EXPECT_NE(apiVersion, nullptr); } /* @@ -7942,4 +7960,625 @@ HWTEST_F(ModuleJsonTest, GetFaReleaseTypeByAppObj_0300, Function | MediumTest | std::string releaseType = ""; EXPECT_FALSE(moduleJson.GetFaReleaseTypeByAppObj(appObj, releaseType)); } + +/* + * @tc.name: SetVersionCode_0100 + * @tc.desc: test SetVersionCode + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetVersionCode_0100, Function | MediumTest | Level1) +{ + int32_t versionCode = 10000; + bool isStage = true; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.SetVersionCode(versionCode, isStage)); +} + +/* + * @tc.name: SetVersionCode_0200 + * @tc.desc: test SetVersionCode + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetVersionCode_0200, Function | MediumTest | Level1) +{ + int32_t versionCode = 10000; + bool isStage = false; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.SetVersionCode(versionCode, isStage)); +} + +/* + * @tc.name: SetVersionCode_0300 + * @tc.desc: test SetVersionCode + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetVersionCode_0300, Function | MediumTest | Level1) +{ + int32_t versionCode = 10000; + bool isStage = true; + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_STRING)); + EXPECT_TRUE(moduleJson.SetVersionCode(versionCode, isStage)); +} + +/* + * @tc.name: SetVersionName_0100 + * @tc.desc: test SetVersionName + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetVersionName_0100, Function | MediumTest | Level1) +{ + std::string versionName = "1.0.0"; + bool isStage = true; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.SetVersionName(versionName, isStage)); +} + +/* + * @tc.name: SetVersionName_0200 + * @tc.desc: test SetVersionName + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetVersionName_0200, Function | MediumTest | Level1) +{ + std::string versionName = "1.0.0"; + bool isStage = false; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.SetVersionName(versionName, isStage)); +} + +/* + * @tc.name: SetVersionName_0300 + * @tc.desc: test SetVersionName + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetVersionName_0300, Function | MediumTest | Level1) +{ + std::string versionName = "1.0.0"; + bool isStage = true; + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_STRING)); + EXPECT_TRUE(moduleJson.SetVersionName(versionName, isStage)); +} + +/* + * @tc.name: SetBundleNameTwoPrama_0100 + * @tc.desc: test SetBundleName + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetBundleNameTwoPrama_0100, Function | MediumTest | Level1) +{ + std::string bundleName = "1.0.0"; + bool isStage = true; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.SetBundleName(bundleName, isStage)); +} + +/* + * @tc.name: SetBundleNameTwoPrama_0200 + * @tc.desc: test SetBundleName + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetBundleNameTwoPrama_0200, Function | MediumTest | Level1) +{ + std::string bundleName = "1.0.0"; + bool isStage = false; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.SetBundleName(bundleName, isStage)); +} + +/* + * @tc.name: SetBundleNameTwoPrama_0300 + * @tc.desc: test SetBundleName + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetBundleNameTwoPrama_0300, Function | MediumTest | Level1) +{ + std::string bundleName = "1.0.0"; + bool isStage = true; + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_STRING)); + EXPECT_TRUE(moduleJson.SetBundleName(bundleName, isStage)); +} + +/* + * @tc.name: SetMinCompatibleVersionCode_0100 + * @tc.desc: test SetMinCompatibleVersionCode + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetMinCompatibleVersionCode_0100, Function | MediumTest | Level1) +{ + int32_t minCompatibleVersionCode = 12; + bool isStage = true; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.SetMinCompatibleVersionCode(minCompatibleVersionCode, isStage)); +} + +/* + * @tc.name: SetMinCompatibleVersionCode_0200 + * @tc.desc: test SetMinCompatibleVersionCode + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetMinCompatibleVersionCode_0200, Function | MediumTest | Level1) +{ + int32_t minCompatibleVersionCode = 12; + bool isStage = false; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.SetMinCompatibleVersionCode(minCompatibleVersionCode, isStage)); +} + +/* + * @tc.name: SetMinCompatibleVersionCode_0300 + * @tc.desc: test SetMinCompatibleVersionCode + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetMinCompatibleVersionCode_0300, Function | MediumTest | Level1) +{ + int32_t minCompatibleVersionCode = 12; + bool isStage = true; + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_STRING)); + EXPECT_TRUE(moduleJson.SetMinCompatibleVersionCode(minCompatibleVersionCode, isStage)); +} + +/* + * @tc.name: SetMinAPIVersion_0100 + * @tc.desc: test SetMinAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetMinAPIVersion_0100, Function | MediumTest | Level1) +{ + int32_t minAPIVersion = 12; + bool isStage = true; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.SetMinAPIVersion(minAPIVersion, isStage)); +} + +/* + * @tc.name: SetMinAPIVersion_0200 + * @tc.desc: test SetMinAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetMinAPIVersion_0200, Function | MediumTest | Level1) +{ + int32_t minAPIVersion = 12; + bool isStage = false; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.SetMinAPIVersion(minAPIVersion, isStage)); +} + +/* + * @tc.name: SetMinAPIVersion_0300 + * @tc.desc: test SetMinAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetMinAPIVersion_0300, Function | MediumTest | Level1) +{ + int32_t minAPIVersion = 12; + bool isStage = true; + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_STRING)); + EXPECT_TRUE(moduleJson.SetMinAPIVersion(minAPIVersion, isStage)); +} + +/* + * @tc.name: SetTargetAPIVersion_0100 + * @tc.desc: test SetTargetAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetTargetAPIVersion_0100, Function | MediumTest | Level1) +{ + int32_t targetAPIVersion = 12; + bool isStage = true; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.SetTargetAPIVersion(targetAPIVersion, isStage)); +} + +/* + * @tc.name: SetTargetAPIVersion_0200 + * @tc.desc: test SetTargetAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetTargetAPIVersion_0200, Function | MediumTest | Level1) +{ + int32_t targetAPIVersion = 12; + bool isStage = false; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.SetTargetAPIVersion(targetAPIVersion, isStage)); +} + +/* + * @tc.name: SetTargetAPIVersion_0300 + * @tc.desc: test SetTargetAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetTargetAPIVersion_0300, Function | MediumTest | Level1) +{ + int32_t targetAPIVersion = 12; + bool isStage = true; + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_STRING)); + EXPECT_TRUE(moduleJson.SetTargetAPIVersion(targetAPIVersion, isStage)); +} + +/* + * @tc.name: SetApiReleaseType_0100 + * @tc.desc: test SetApiReleaseType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetApiReleaseType_0100, Function | MediumTest | Level1) +{ + std::string apiReleaseType = "1.0.0"; + bool isStage = true; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.SetApiReleaseType(apiReleaseType, isStage)); +} + +/* + * @tc.name: SetApiReleaseType_0200 + * @tc.desc: test SetApiReleaseType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetApiReleaseType_0200, Function | MediumTest | Level1) +{ + std::string apiReleaseType = "1.0.0"; + bool isStage = false; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.SetApiReleaseType(apiReleaseType, isStage)); +} + +/* + * @tc.name: SetApiReleaseType_0300 + * @tc.desc: test SetApiReleaseType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetApiReleaseType_0300, Function | MediumTest | Level1) +{ + std::string apiReleaseType = "1.0.0"; + bool isStage = true; + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_STRING)); + EXPECT_TRUE(moduleJson.SetApiReleaseType(apiReleaseType, isStage)); +} + +/* + * @tc.name: SetBundleType_0100 + * @tc.desc: test SetBundleType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetBundleType_0100, Function | MediumTest | Level1) +{ + std::string bundleType = "app"; + bool isStage = true; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.SetBundleType(bundleType, isStage)); +} + +/* + * @tc.name: SetBundleType_0200 + * @tc.desc: test SetBundleType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetBundleType_0200, Function | MediumTest | Level1) +{ + std::string bundleType = "app"; + bool isStage = false; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.SetBundleType(bundleType, isStage)); +} + +/* + * @tc.name: SetBundleType_0300 + * @tc.desc: test SetBundleType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetBundleType_0300, Function | MediumTest | Level1) +{ + std::string bundleType = "app"; + bool isStage = true; + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_STRING)); + EXPECT_TRUE(moduleJson.SetBundleType(bundleType, isStage)); +} + +/* + * @tc.name: SetInstallationFree_0100 + * @tc.desc: test SetInstallationFree + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetInstallationFree_0100, Function | MediumTest | Level1) +{ + bool installationFree = false; + bool isStage = true; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.SetInstallationFree(installationFree, isStage)); +} + +/* + * @tc.name: SetInstallationFree_0200 + * @tc.desc: test SetInstallationFree + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetInstallationFree_0200, Function | MediumTest | Level1) +{ + bool installationFree = false; + bool isStage = false; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.SetInstallationFree(installationFree, isStage)); +} + +/* + * @tc.name: SetInstallationFree_0300 + * @tc.desc: test SetInstallationFree + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetInstallationFree_0300, Function | MediumTest | Level1) +{ + bool installationFree = false; + bool isStage = true; + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_STRING)); + EXPECT_TRUE(moduleJson.SetInstallationFree(installationFree, isStage)); +} + +/* + * @tc.name: SetDeliveryWithInstall_0100 + * @tc.desc: test SetDeliveryWithInstall + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetDeliveryWithInstall_0100, Function | MediumTest | Level1) +{ + bool deliveryWithInstall = false; + bool isStage = true; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.SetDeliveryWithInstall(deliveryWithInstall, isStage)); +} + +/* + * @tc.name: SetDeliveryWithInstall_0200 + * @tc.desc: test SetDeliveryWithInstall + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetDeliveryWithInstall_0200, Function | MediumTest | Level1) +{ + bool deliveryWithInstall = false; + bool isStage = false; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.SetDeliveryWithInstall(deliveryWithInstall, isStage)); +} + +/* + * @tc.name: SetDeliveryWithInstall_0300 + * @tc.desc: test SetDeliveryWithInstall + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetDeliveryWithInstall_0300, Function | MediumTest | Level1) +{ + bool deliveryWithInstall = false; + bool isStage = true; + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_STRING)); + EXPECT_TRUE(moduleJson.SetDeliveryWithInstall(deliveryWithInstall, isStage)); +} + +/* + * @tc.name: SetDeviceTypes_0100 + * @tc.desc: test SetDeviceTypes + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetDeviceTypes_0100, Function | MediumTest | Level1) +{ + std::list deviceTypes = {}; + bool isStage = true; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.SetDeviceTypes(deviceTypes, isStage)); +} + +/* + * @tc.name: SetDeviceTypes_0200 + * @tc.desc: test SetDeviceTypes + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetDeviceTypes_0200, Function | MediumTest | Level1) +{ + std::list deviceTypes = {}; + bool isStage = false; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.SetDeviceTypes(deviceTypes, isStage)); +} + +/* + * @tc.name: SetDeviceTypes_0300 + * @tc.desc: test SetDeviceTypes + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetDeviceTypes_0300, Function | MediumTest | Level1) +{ + std::list deviceTypes = {"default"}; + bool isStage = true; + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_STRING)); + EXPECT_TRUE(moduleJson.SetDeviceTypes(deviceTypes, isStage)); +} + +/* + * @tc.name: GetMinApiVersion_0100 + * @tc.desc: test GetMinApiVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetMinApiVersion_0100, Function | MediumTest | Level1) +{ + int32_t minAPIVersion = 99; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.GetMinApiVersion(minAPIVersion)); +} + +/* + * @tc.name: GetMinApiVersion_0200 + * @tc.desc: test GetMinApiVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetMinApiVersion_0200, Function | MediumTest | Level1) +{ + int32_t minAPIVersion = 99; + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(APP_ERROR_MIN_API_VERSION)); + EXPECT_FALSE(moduleJson.GetMinApiVersion(minAPIVersion)); +} + +/* + * @tc.name: GetMinApiVersion_0300 + * @tc.desc: test GetMinApiVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetMinApiVersion_0300, Function | MediumTest | Level1) +{ + int32_t minAPIVersion = 99; + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_STRING)); + EXPECT_TRUE(moduleJson.GetMinApiVersion(minAPIVersion)); +} + +/* + * @tc.name: GetTargetApiVersion_0100 + * @tc.desc: test GetTargetApiVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetTargetApiVersion_0100, Function | MediumTest | Level1) +{ + int32_t targetAPIVersion = 99; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.GetTargetApiVersion(targetAPIVersion)); +} + +/* + * @tc.name: GetTargetApiVersion_0200 + * @tc.desc: test GetTargetApiVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetTargetApiVersion_0200, Function | MediumTest | Level1) +{ + int32_t targetAPIVersion = 99; + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(APP_ERROR_TARGET_API_VERSION)); + EXPECT_FALSE(moduleJson.GetTargetApiVersion(targetAPIVersion)); +} + +/* + * @tc.name: GetTargetApiVersion_0300 + * @tc.desc: test GetTargetApiVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetTargetApiVersion_0300, Function | MediumTest | Level1) +{ + int32_t targetAPIVersion = 99; + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_STRING)); + EXPECT_TRUE(moduleJson.GetTargetApiVersion(targetAPIVersion)); +} + +/* + * @tc.name: GetDeliveryWithInstall_0100 + * @tc.desc: test GetDeliveryWithInstall + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetDeliveryWithInstall_0100, Function | MediumTest | Level1) +{ + bool deliveryWithInstall = false; + OHOS::AppPackingTool::ModuleJson moduleJson; + moduleJson.root_ = nullptr; + EXPECT_FALSE(moduleJson.GetDeliveryWithInstall(deliveryWithInstall)); +} + +/* + * @tc.name: GetDeliveryWithInstall_0200 + * @tc.desc: test GetDeliveryWithInstall + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetDeliveryWithInstall_0200, Function | MediumTest | Level1) +{ + bool deliveryWithInstall = false; + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(APP_ERROR_DELIVERY_WITH_INSTALL)); + EXPECT_FALSE(moduleJson.GetDeliveryWithInstall(deliveryWithInstall)); +} + +/* + * @tc.name: GetDeliveryWithInstall_0300 + * @tc.desc: test GetDeliveryWithInstall + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetDeliveryWithInstall_0300, Function | MediumTest | Level1) +{ + bool deliveryWithInstall = false; + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(MODULE_JSON_STRING)); + EXPECT_TRUE(moduleJson.GetDeliveryWithInstall(deliveryWithInstall)); +} } diff --git a/packing_tool/frameworks/test/unittest/json/pack_info_test/pack_info_test.cpp b/packing_tool/frameworks/test/unittest/json/pack_info_test/pack_info_test.cpp index 3872552e6dff718e3f73ff6aa23248c3a4e4c6a9..e7c45ff27f7227eb726be85e1f857e699b5b660e 100644 --- a/packing_tool/frameworks/test/unittest/json/pack_info_test/pack_info_test.cpp +++ b/packing_tool/frameworks/test/unittest/json/pack_info_test/pack_info_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -82,14 +82,135 @@ const std::string JSON_STRING = "{" "]" "}"; +const std::string PACKAGES_NO_DEVICETYPE_JSON_STRING = "{" + "\"summary\": {" + "\"app\": {" + "\"bundleName\": \"com.example.myapplication\"," + "\"bundleType\": \"bundleApp\"," + "\"version\": {" + "\"code\": 1000000," + "\"name\": \"1.0.0\"" + "}" + "}," + "\"modules\": [" + "{" + "\"mainAbility\": \"EntryAbility\"," + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"abilities\": [" + "{" + "\"name\": \"EntryAbility\"," + "\"label\": \"$string:EntryAbility_label\"" + "}" + "]," + "\"distro\": {" + "\"moduleType\": \"entry\"," + "\"installationFree\": false," + "\"deliveryWithInstall\": true," + "\"moduleName\": \"entry\"" + "}," + "\"extensionAbilities\": [" + "]," + "\"apiVersion\": {" + "\"compatible\": 12," + "\"releaseType\": \"Canary2\"," + "\"target\": 12" + "}" + "}" + "]" + "}," + "\"packages\":[" + "{" + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"moduleType\": \"entry\"," + "\"deliveryWithInstall\": true," + "\"name\": \"entry-default\"" + "}" + "]" +"}"; + +const std::string NO_PACKAGES_JSON_STRING = "{" + "\"summary\": {" + "\"app\": {" + "\"apiVersion\": {" + "}" + "\"bundleName\": \"com.example.myapplication\"," + "\"bundleType\": \"bundleApp\"," + "\"version\": {" + "\"code\": 1000000," + "\"name\": \"1.0.0\"" + "}" + "}," + "\"modules\": [" + "{" + "\"mainAbility\": \"EntryAbility\"," + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"abilities\": [" + "{" + "\"name\": \"EntryAbility\"," + "\"label\": \"$string:EntryAbility_label\"" + "}" + "]," + "\"distro\": {" + "\"moduleType\": \"entry\"," + "\"installationFree\": false," + "\"deliveryWithInstall\": true," + "\"moduleName\": \"entry\"" + "}," + "\"extensionAbilities\": [" + "]," + "\"apiVersion\": {" + "\"compatible\": 12," + "\"releaseType\": \"Canary2\"," + "\"target\": 12" + "}" + "}" + "]" + "}," +"}"; + const std::string JSON_STRING_NULL = "{}"; const std::string JSON_STRING_EMPTY = "{" "\"summary\": {" "\"app\": {" + "}," + "\"modules\": [" + "]" + "}," + "\"packages\":[" + "]" +"}"; + +const std::string JSON_STRING_EMPTY_MODULEOBJ = "{" + "\"summary\": {" + "\"app\": {" + "}," + "\"modules\": [" + "{" "}" + "]" + "}," + "\"packages\":[" + "]" +"}"; + +const std::string JSON_STRING_ERROR_MODULEOBJ = "{" + "\"summary\": {" + "\"app\": {" "}," "\"modules\": [" + "{" + "}," + "\"tablet\"" "]" "}," "\"packages\":[" @@ -484,6 +605,59 @@ const std::string NO_FORM_NAME_JSON_STRING = "{" "}" "}"; +const std::string NO_MODULES_API_VERSION_JSON_STRING = "{" + "\"summary\": {" + "\"modules\": [" + "{" + "\"apiVersion\": {" + "}" + "}" + "]" + "}" +"}"; + +const std::string EMPTY_MODULES_DISTRO_OBJECT_JSON_STRING = "{" + "\"summary\": {" + "\"modules\": [" + "{" + "\"distro\": {" + "}" + "}" + "]" + "}" +"}"; +const std::string NO_API_VERSION_JSON_STRING = "{" + "\"summary\": {" + "\"modules\": [" + "{" + "\"mainAbility\": \"EntryAbility\"," + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"abilities\": [" + "{" + "\"name\": \"EntryAbility\"," + "\"label\": \"$string:EntryAbility_label\"" + "}" + "]," + "\"distro\": {" + "\"moduleType\": \"entry\"," + "\"installationFree\": false," + "\"deliveryWithInstall\": true," + "\"moduleName\": \"entry\"" + "}," + "\"extensionAbilities\": [" + "{" + "\"name\": \"EntryFormAbility2\"," + "\"type\": \"form\"," + "\"forms\": \"form\"" + "}" + "]," + "}" + "]" + "}" +"}"; const std::string MODULES_NOT_ARRAY_TEST_JSON_STRING = "{" "\"summary\": {" "\"modules\": \"test\"" @@ -594,6 +768,88 @@ const std::string MODULES_EXTENSION_ABILITIES_FORMS_DEFAULT_DIMENSION_NOT_STRING "]" "}" "}"; +const std::string MODULES_VERSION_MIN_COMOATIBLE_TEST_JSON_STRING = "{" + "\"summary\": {" + "\"app\": {" + "\"version\": {" + "\"minCompatibleVersionCode\": 99" + "}" + "}" + "}" +"}"; +const std::string EMPTY_MODULES_API_VERSION_TEST_JSON_STRING = "{" + "\"summary\": {" + "\"modules\": [" + "{" + "\"apiVersion\": {" + "}" + "}" + "]" + "}" +"}"; +const std::string MODULES_API_VERSION_COMOATIBLE_TEST_JSON_STRING = "{" + "\"summary\": {" + "\"modules\": [" + "{" + "\"apiVersion\": {" + "\"compatible\": 12" + "}" + "}" + "]" + "}" +"}"; + +const std::string MODULES_APIVERSION_TARGET_JSON_STRING = "{" + "\"summary\": {" + "\"modules\": [" + "{" + "\"apiVersion\": {" + "\"target\": 10" + "}" + "}" + "]" + "}" +"}"; + +const std::string MODULES_APIVERSION_API_RELEASE_TYPE_JSON_STRING = "{" + "\"summary\": {" + "\"modules\": [" + "{" + "\"apiVersion\": {" + "\"releaseType\": \"Canary2\"" + "}" + "}" + "]" + "}" +"}"; + +const std::string MODULES_DISTRO_INSTALLATION_FREE_JSON_STRING = "{" + "\"summary\": {" + "\"modules\": [" + "{" + "\"distro\": {" + "\"installationFree\": false" + "}" + "}" + "]" + "}" +"}"; + +const std::string MODULES_PACKAGES_NO_DELIVERY_WITH_INSTALL_JSON_STRING = "{" + "\"summary\": {" + "\"modules\": [" + "]" + "}," + "\"packages\": [" + "{" + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"moduleType\": \"entry\"" + "}" + "]" +"}"; } class PackInfoTest : public testing::Test { @@ -2615,4 +2871,644 @@ HWTEST_F(PackInfoTest, GetPackageNamesByPackagesObj_0300, Function | MediumTest std::list packageNames; EXPECT_FALSE(packInfo.GetPackageNamesByPackagesObj(packagesObj, packageNames)); } + +/* + * @tc.name: SetMinCompatibleVersionCode_0100 + * @tc.desc: SetMinCompatibleVersionCode. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetMinCompatibleVersionCode_0100, Function | MediumTest | Level1) +{ + int32_t minCompatibleVersionCode = 99; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(JSON_STRING_NULL); + EXPECT_FALSE(packInfo.SetMinCompatibleVersionCode(minCompatibleVersionCode)); +} + +/* + * @tc.name: SetMinCompatibleVersionCode_0200 + * @tc.desc: SetMinCompatibleVersionCode. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetMinCompatibleVersionCode_0200, Function | MediumTest | Level1) +{ + int32_t minCompatibleVersionCode = 99; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(ERR_VERSION_CODE_JSON_STRING); + EXPECT_TRUE(packInfo.SetMinCompatibleVersionCode(minCompatibleVersionCode)); +} + +/* + * @tc.name: SetMinCompatibleVersionCode_0300 + * @tc.desc: SetMinCompatibleVersionCode + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetMinCompatibleVersionCode_0300, Function | MediumTest | Level1) +{ + int32_t minCompatibleVersionCode = 99; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(MODULES_VERSION_MIN_COMOATIBLE_TEST_JSON_STRING); + EXPECT_TRUE(packInfo.SetMinCompatibleVersionCode(minCompatibleVersionCode)); +} + +/* + * @tc.name: SetMinAPIVersion_0100 + * @tc.desc: SetMinAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetMinAPIVersion_0100, Function | MediumTest | Level1) +{ + int32_t minAPIVersion = 1; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(JSON_STRING_NULL); + EXPECT_FALSE(packInfo.SetMinAPIVersion(minAPIVersion)); +} + +/* + * @tc.name: SetMinAPIVersion_0200 + * @tc.desc: SetMinAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetMinAPIVersion_0200, Function | MediumTest | Level1) +{ + int32_t minAPIVersion = 1; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(EMPTY_MODULES_OBJECT_JSON_STRING); + EXPECT_TRUE(packInfo.SetMinAPIVersion(minAPIVersion)); +} + +/* + * @tc.name: SetMinAPIVersion_0300 + * @tc.desc: SetMinAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetMinAPIVersion_0300, Function | MediumTest | Level1) +{ + int32_t minAPIVersion = 1; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(NO_API_VERSION_JSON_STRING); + EXPECT_FALSE(packInfo.SetMinAPIVersion(minAPIVersion)); +} + +/* + * @tc.name: SetMinAPIVersion_0400 + * @tc.desc: SetMinAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetMinAPIVersion_0400, Function | MediumTest | Level1) +{ + int32_t minAPIVersion = 1; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(NO_MODULES_API_VERSION_JSON_STRING); + EXPECT_TRUE(packInfo.SetMinAPIVersion(minAPIVersion)); +} + +/* + * @tc.name: SetMinAPIVersion_0500 + * @tc.desc: SetMinAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetMinAPIVersion_0500, Function | MediumTest | Level1) +{ + int32_t minAPIVersion = 1; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(MODULES_API_VERSION_COMOATIBLE_TEST_JSON_STRING); + EXPECT_TRUE(packInfo.SetMinAPIVersion(minAPIVersion)); +} + +/* + * @tc.name: SetTargetAPIVersion_0100 + * @tc.desc: SetTargetAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetTargetAPIVersion_0100, Function | MediumTest | Level1) +{ + int32_t targetAPIVersion = 1; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(JSON_STRING_NULL); + EXPECT_FALSE(packInfo.SetTargetAPIVersion(targetAPIVersion)); +} + +/* + * @tc.name: SetTargetAPIVersion_0200 + * @tc.desc: SetTargetAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetTargetAPIVersion_0200, Function | MediumTest | Level1) +{ + int32_t targetAPIVersion = 1; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(EMPTY_MODULES_OBJECT_JSON_STRING); + EXPECT_TRUE(packInfo.SetTargetAPIVersion(targetAPIVersion)); +} + +/* + * @tc.name: SetTargetAPIVersion_0300 + * @tc.desc: SetTargetAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetTargetAPIVersion_0300, Function | MediumTest | Level1) +{ + int32_t targetAPIVersion = 1; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(NO_API_VERSION_JSON_STRING); + EXPECT_FALSE(packInfo.SetTargetAPIVersion(targetAPIVersion)); +} + +/* + * @tc.name: SetTargetAPIVersion_0400 + * @tc.desc: SetTargetAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetTargetAPIVersion_0400, Function | MediumTest | Level1) +{ + int32_t targetAPIVersion = 1; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(NO_MODULES_API_VERSION_JSON_STRING); + EXPECT_TRUE(packInfo.SetTargetAPIVersion(targetAPIVersion)); +} + +/* + * @tc.name: SetTargetAPIVersion_0500 + * @tc.desc: SetTargetAPIVersion + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetTargetAPIVersion_0500, Function | MediumTest | Level1) +{ + int32_t targetAPIVersion = 1; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(MODULES_APIVERSION_TARGET_JSON_STRING); + EXPECT_TRUE(packInfo.SetTargetAPIVersion(targetAPIVersion)); +} + +/* + * @tc.name: SetApiReleaseType_0100 + * @tc.desc: SetApiReleaseType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetApiReleaseType_0100, Function | MediumTest | Level1) +{ + std::string apiReleaseType = "Canary"; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(JSON_STRING_NULL); + EXPECT_FALSE(packInfo.SetApiReleaseType(apiReleaseType)); +} + +/* + * @tc.name: SetApiReleaseType_0200 + * @tc.desc: SetApiReleaseType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetApiReleaseType_0200, Function | MediumTest | Level1) +{ + std::string apiReleaseType = "Canary1"; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(EMPTY_MODULES_OBJECT_JSON_STRING); + EXPECT_TRUE(packInfo.SetApiReleaseType(apiReleaseType)); +} + +/* + * @tc.name: SetApiReleaseType_0300 + * @tc.desc: SetApiReleaseType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetApiReleaseType_0300, Function | MediumTest | Level1) +{ + std::string apiReleaseType = ""; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(NO_API_VERSION_JSON_STRING); + EXPECT_FALSE(packInfo.SetApiReleaseType(apiReleaseType)); +} + +/* + * @tc.name: SetApiReleaseType_0400 + * @tc.desc: SetApiReleaseType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetApiReleaseType_0400, Function | MediumTest | Level1) +{ + std::string apiReleaseType = "Canary1"; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(NO_MODULES_API_VERSION_JSON_STRING); + EXPECT_TRUE(packInfo.SetApiReleaseType(apiReleaseType)); +} + +/* + * @tc.name: SetApiReleaseType_0500 + * @tc.desc: SetApiReleaseType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetApiReleaseType_0500, Function | MediumTest | Level1) +{ + std::string apiReleaseType = "Canary1"; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(MODULES_APIVERSION_API_RELEASE_TYPE_JSON_STRING); + EXPECT_TRUE(packInfo.SetApiReleaseType(apiReleaseType)); +} + +/* + * @tc.name: SetBundleType_0100 + * @tc.desc: SetBundleType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetBundleType_0100, Function | MediumTest | Level1) +{ + std::string bundleType = "test_bundle_type"; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(JSON_STRING_NULL); + EXPECT_FALSE(packInfo.SetBundleType(bundleType)); +} + +/* + * @tc.name: SetBundleType_0200 + * @tc.desc: SetBundleType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetBundleType_0200, Function | MediumTest | Level1) +{ + std::string bundleType = "test_bundle_type"; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(JSON_STRING_EMPTY); + EXPECT_TRUE(packInfo.SetBundleType(bundleType)); +} + +/* + * @tc.name: SetBundleType_0300 + * @tc.desc: SetBundleType + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetBundleType_0300, Function | MediumTest | Level1) +{ + std::string bundleType = "test_bundle_type"; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(JSON_STRING); + EXPECT_TRUE(packInfo.SetBundleType(bundleType)); +} + +/* + * @tc.name: SetInstallationFree_0100 + * @tc.desc: SetInstallationFree + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetInstallationFree_0100, Function | MediumTest | Level1) +{ + bool installationFree = false; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(JSON_STRING_NULL); + EXPECT_FALSE(packInfo.SetInstallationFree(installationFree)); +} + +/* + * @tc.name: SetInstallationFree_0200 + * @tc.desc: SetInstallationFree + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetInstallationFree_0200, Function | MediumTest | Level1) +{ + bool installationFree = false; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(EMPTY_MODULES_OBJECT_JSON_STRING); + EXPECT_TRUE(packInfo.SetInstallationFree(installationFree)); +} + +/* + * @tc.name: SetInstallationFree_0300 + * @tc.desc: SetInstallationFree + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetInstallationFree_0300, Function | MediumTest | Level1) +{ + bool installationFree = false; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(NO_DISTRO_JSON_STRING); + EXPECT_FALSE(packInfo.SetInstallationFree(installationFree)); +} + +/* + * @tc.name: SetInstallationFree_0400 + * @tc.desc: SetInstallationFree + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetInstallationFree_0400, Function | MediumTest | Level1) +{ + bool installationFree = false; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(EMPTY_MODULES_DISTRO_OBJECT_JSON_STRING); + EXPECT_TRUE(packInfo.SetInstallationFree(installationFree)); +} + +/* + * @tc.name: SetInstallationFree_0500 + * @tc.desc: SetInstallationFree + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetInstallationFree_0500, Function | MediumTest | Level1) +{ + bool installationFree = false; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(MODULES_DISTRO_INSTALLATION_FREE_JSON_STRING); + EXPECT_TRUE(packInfo.SetInstallationFree(installationFree)); +} + +/* + * @tc.name: SetDeliveryWithInstall_0100 + * @tc.desc: SetDeliveryWithInstall + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetDeliveryWithInstall_0100, Function | MediumTest | Level1) +{ + bool deliveryWithInstall = false; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(JSON_STRING_NULL); + EXPECT_FALSE(packInfo.SetDeliveryWithInstall(deliveryWithInstall)); +} + +/* + * @tc.name: SetDeliveryWithInstall_0200 + * @tc.desc: SetDeliveryWithInstall + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetDeliveryWithInstall_0200, Function | MediumTest | Level1) +{ + bool deliveryWithInstall = false; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(EMPTY_MODULES_OBJECT_JSON_STRING); + EXPECT_TRUE(packInfo.SetDeliveryWithInstall(deliveryWithInstall)); +} + +/* + * @tc.name: SetDeliveryWithInstall_0300 + * @tc.desc: SetDeliveryWithInstall + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetDeliveryWithInstall_0300, Function | MediumTest | Level1) +{ + bool deliveryWithInstall = false; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(NO_DISTRO_JSON_STRING); + EXPECT_FALSE(packInfo.SetDeliveryWithInstall(deliveryWithInstall)); +} + +/* + * @tc.name: SetDeliveryWithInstall_0400 + * @tc.desc: SetDeliveryWithInstall + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetDeliveryWithInstall_0400, Function | MediumTest | Level1) +{ + bool deliveryWithInstall = false; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(EMPTY_MODULES_DISTRO_OBJECT_JSON_STRING); + EXPECT_TRUE(packInfo.SetDeliveryWithInstall(deliveryWithInstall)); +} + +/* + * @tc.name: SetDeliveryWithInstall_0500 + * @tc.desc: SetDeliveryWithInstall + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetDeliveryWithInstall_0500, Function | MediumTest | Level1) +{ + bool deliveryWithInstall = false; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(JSON_STRING); + EXPECT_TRUE(packInfo.SetDeliveryWithInstall(deliveryWithInstall)); +} + +/* + * @tc.name: SetDeliveryWithInstall_0600 + * @tc.desc: SetDeliveryWithInstall + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetDeliveryWithInstall_0600, Function | MediumTest | Level1) +{ + bool deliveryWithInstall = false; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(NO_PACKAGES_JSON_STRING); + EXPECT_FALSE(packInfo.SetDeliveryWithInstall(deliveryWithInstall)); +} + +/* + * @tc.name: SetDeliveryWithInstall_0700 + * @tc.desc: SetDeliveryWithInstall + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetDeliveryWithInstall_0700, Function | MediumTest | Level1) +{ + bool deliveryWithInstall = false; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(JSON_STRING_EMPTY); + EXPECT_TRUE(packInfo.SetDeliveryWithInstall(deliveryWithInstall)); +} + +/* + * @tc.name: SetDeliveryWithInstall_0800 + * @tc.desc: SetDeliveryWithInstall + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetDeliveryWithInstall_0800, Function | MediumTest | Level1) +{ + bool deliveryWithInstall = false; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(MODULES_PACKAGES_NO_DELIVERY_WITH_INSTALL_JSON_STRING); + EXPECT_TRUE(packInfo.SetDeliveryWithInstall(deliveryWithInstall)); +} + +/* + * @tc.name: GetApiVersionObjectByModuleObj_0100 + * @tc.desc: GetApiVersionObjectByModuleObj. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, GetApiVersionObjectByModuleObj_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PackInfo packInfo; + std::unique_ptr moduleObj; + std::unique_ptr apiVersionObj; + packInfo.ParseFromString(JSON_STRING_NULL); + EXPECT_FALSE(packInfo.GetApiVersionObjectByModuleObj(moduleObj, apiVersionObj)); +} + +/* + * @tc.name: GetApiVersionObjectByModuleObj_0200 + * @tc.desc: GetApiVersionObjectByModuleObj. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, GetApiVersionObjectByModuleObj_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PackInfo packInfo; + std::unique_ptr modulesObj; + std::unique_ptr apiVersionObj; + packInfo.ParseFromString(JSON_STRING_EMPTY_MODULEOBJ); + EXPECT_TRUE(packInfo.GetModulesObject(modulesObj)); + ASSERT_NE(modulesObj, nullptr); + EXPECT_TRUE(packInfo.GetApiVersionObjectByModuleObj(modulesObj->Get(0), apiVersionObj)); +} + +/* + * @tc.name: GetApiVersionObjectByModuleObj_0300 + * @tc.desc: GetApiVersionObjectByModuleObj. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, GetApiVersionObjectByModuleObj_0300, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(EMPTY_MODULES_API_VERSION_TEST_JSON_STRING); + std::unique_ptr modulesObj; + std::unique_ptr apiVersionObj; + EXPECT_TRUE(packInfo.GetModulesObject(modulesObj)); + ASSERT_NE(modulesObj, nullptr); + EXPECT_TRUE(packInfo.GetApiVersionObjectByModuleObj(modulesObj->Get(0), apiVersionObj)); +} + +/* + * @tc.name: GetApiVersionObjectByModuleObj_0400 + * @tc.desc: GetApiVersionObjectByModuleObj. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, GetApiVersionObjectByModuleObj_0400, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(NO_EXTENSION_JSON_STRING); + std::unique_ptr modulesObj; + std::unique_ptr apiVersionObj; + EXPECT_TRUE(packInfo.GetModulesObject(modulesObj)); + ASSERT_NE(modulesObj, nullptr); + EXPECT_TRUE(packInfo.GetApiVersionObjectByModuleObj(modulesObj->Get(0), apiVersionObj)); +} + +/* + * @tc.name: SetDeviceTypes_0100 + * @tc.desc: SetDeviceTypes + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetDeviceTypes_0100, Function | MediumTest | Level1) +{ + std::list deviceTypes; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(JSON_STRING_NULL); + EXPECT_FALSE(packInfo.SetDeviceTypes(deviceTypes)); +} + +/* + * @tc.name: SetDeviceTypes_0200 + * @tc.desc: SetDeviceTypes + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetDeviceTypes_0200, Function | MediumTest | Level1) +{ + std::list deviceTypes; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(JSON_STRING_ERROR_MODULEOBJ); + EXPECT_TRUE(packInfo.SetDeviceTypes(deviceTypes)); +} + +/* + * @tc.name: SetDeviceTypes_0300 + * @tc.desc: SetDeviceTypes + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetDeviceTypes_0300, Function | MediumTest | Level1) +{ + std::list deviceTypes; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(EMPTY_MODULES_DISTRO_OBJECT_JSON_STRING); + EXPECT_TRUE(packInfo.SetDeviceTypes(deviceTypes)); +} + +/* + * @tc.name: SetDeviceTypes_0400 + * @tc.desc: SetDeviceTypes + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetDeviceTypes_0400, Function | MediumTest | Level1) +{ + std::list deviceTypes; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(NO_PACKAGES_JSON_STRING); + EXPECT_FALSE(packInfo.SetDeviceTypes(deviceTypes)); +} + +/* + * @tc.name: SetDeviceTypes_0500 + * @tc.desc: SetDeviceTypes + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetDeviceTypes_0500, Function | MediumTest | Level1) +{ + std::list deviceTypes; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(JSON_STRING_EMPTY); + EXPECT_TRUE(packInfo.SetDeviceTypes(deviceTypes)); +} + +/* + * @tc.name: SetDeviceTypes_0600 + * @tc.desc: SetDeviceTypes + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetDeviceTypes_0600, Function | MediumTest | Level1) +{ + std::list deviceTypes; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(PACKAGES_NO_DEVICETYPE_JSON_STRING); + EXPECT_TRUE(packInfo.SetDeviceTypes(deviceTypes)); +} + +/* + * @tc.name: SetDeviceTypes_0700 + * @tc.desc: SetDeviceTypes + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetDeviceTypes_0700, Function | MediumTest | Level1) +{ + std::list deviceTypes; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(JSON_STRING); + EXPECT_TRUE(packInfo.SetDeviceTypes(deviceTypes)); +} } // namespace OHOS diff --git a/packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp b/packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp index 4fd45c3036e8229ab56af5e31d554c6d42339cc8..8b757e28a2346dc51deb5f9057b053ac92ae3f83 100644 --- a/packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp +++ b/packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * Copyright (c) 2024-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -161,11 +161,14 @@ HWTEST_F(PtJsonTest, Add_0600, Function | MediumTest | Level1) std::unique_ptr ptjsonObject = ptJson.CreateObject(); EXPECT_TRUE(ptjsonObject != NULL); + std::list values = {"a", "b", "c"}; + EXPECT_TRUE(ptJson.Add("AAA", true)); EXPECT_TRUE(ptJson.Add("BBB", 123)); EXPECT_TRUE(ptJson.Add("CCC", 123.5)); EXPECT_TRUE(ptJson.Add("DDD", "ABC")); EXPECT_TRUE(ptJson.Add("EEE", ptjsonObject)); + EXPECT_TRUE(ptJson.Add("FFF", values)); } /* @@ -1030,4 +1033,26 @@ HWTEST_F(PtJsonTest, GetAny_0100, Function | MediumTest | Level1) AppPackingTool::Result ret = ptJson.GetAny("key", value); EXPECT_EQ(ret, AppPackingTool::Result::NOT_EXIST); } + +/* + * @tc.name: SetArray_0100 + * @tc.desc: SetArray. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, SetArray_0100, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + std::list value; + EXPECT_EQ(ptJson.SetArray("AAA", value), OHOS::AppPackingTool::Result::NOT_EXIST); + + ptJson.Add("AAA", true); + EXPECT_EQ(ptJson.SetArray("AAA", value), OHOS::AppPackingTool::Result::TYPE_ERROR); + + value.push_back("123"); + value.push_back("456"); + ptJson.Add("BBB", value); + EXPECT_EQ(ptJson.SetArray("BBB", value), OHOS::AppPackingTool::Result::SUCCESS); +} } // namespace OHOS diff --git a/packing_tool/frameworks/test/unittest/ohos_test/ohos_test.xml b/packing_tool/frameworks/test/unittest/ohos_test/ohos_test.xml index f20ab1318434222a28a30b2ec0a0093fd411fca0..5b251da43122e62c90912d3a88ef2af7ec728d8c 100644 --- a/packing_tool/frameworks/test/unittest/ohos_test/ohos_test.xml +++ b/packing_tool/frameworks/test/unittest/ohos_test/ohos_test.xml @@ -120,4 +120,19 @@