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..f811a18ab5c5553dc3b91dbfae662719c23bd245 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 @@ -752,7 +752,6 @@ const std::string MODULE_JSON_TEST_NOMODULETYPE = "{" "\"atomicServiceObj\": \"test_atomicService\"" "}" "]" - "}," "\"metadata\": [" "{" @@ -2239,4 +2238,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/pt_json_test/pt_json_test.cpp b/packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp index 4fd45c3036e8229ab56af5e31d554c6d42339cc8..74c0ed2d8d05dadf55302789b5b0a594da518582 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,25 @@ 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 @@