diff --git a/OAT.xml b/OAT.xml index bea7f063422b9d6eafb73430a8d19b6f54201948..447da4d32211be19b3d15a63b0f0b253566935e3 100644 --- a/OAT.xml +++ b/OAT.xml @@ -64,6 +64,8 @@ Note:If the text contains special characters, please escape them according to th + + diff --git a/bundle.json b/bundle.json index 3946e38565b2682199bbb8d3c27bc0db626df607..323cff70b53219f1256b08533e27e7e350758c71 100755 --- a/bundle.json +++ b/bundle.json @@ -28,6 +28,9 @@ "sub_component": [ "//developtools/packing_tool:packing_tool", "//developtools/packing_tool:ohos_packing_tool" + ], + "test": [ + "//developtools/packing_tool/packing_tool/frameworks/test/unittest:unittest" ] } } diff --git a/packing_tool/frameworks/test/unittest/BUILD.gn b/packing_tool/frameworks/test/unittest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..9e15625d1a35fa51b21a2eeba726bb4e05796b2c --- /dev/null +++ b/packing_tool/frameworks/test/unittest/BUILD.gn @@ -0,0 +1,47 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +group("unittest") { + testonly = true + deps = [ + "app_packager_test:unittest", + "appqf_packager_test:unittest", + "fast_app_packager_test:unittest", + "hap_packager_test:unittest", + "hqf_packager_test:unittest", + "hsp_packager_test:unittest", + "json/distro_filter_test:unittest", + "json/hap_verify_utils_test:unittest", + "json/json_utils_test:unittest", + "json/module_json_test:unittest", + "json/module_json_utils_test:unittest", + "json/normalize_version_utils_test:unittest", + "json/pack_info_test:unittest", + "json/pack_info_utils_test:unittest", + "json/patch_json_test:unittest", + "json/patch_json_utils_test:unittest", + "json/pt_json_test:unittest", + "multiapp_packager_test:unittest", + "package_normalize_test:unittest", + "packager_test:unittest", + "shell_command_test:unittest", + "unzip_wrapper_test:unittest", + "utils_Test:unittest", + "version_normalize_test:unittest", + "zip_utils_test:unittest", + "zip_wrapper_test:unittest", + ] +} diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/BUILD.gn b/packing_tool/frameworks/test/unittest/app_packager_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b8ba6848c0186ef3ce9d80632657648d66616c07 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/BUILD.gn @@ -0,0 +1,75 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("app_packager_test_config") { + include_dirs = [ + "../../../include", + "../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("app_packager_test") { + module_out_path = module_output_path + public_configs = [ ":app_packager_test_config" ] + sources = [ + "../../../src/app_packager.cpp", + "../../../src/json/distro_filter.cpp", + "../../../src/json/hap_verify_info.cpp", + "../../../src/json/hap_verify_utils.cpp", + "../../../src/json/module_json.cpp", + "../../../src/json/module_json_fa.cpp", + "../../../src/json/module_json_stage.cpp", + "../../../src/json/module_json_utils.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", + "app_packager_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", + "./appPackagerHapTest:appPackagerHapTest", + "./appPackagerHspTest:appPackagerHspTest", + ] +} + +group("unittest") { + testonly = true + deps = [ ":app_packager_test" ] +} + +ohos_copy("copy_test_file") { + subsystem_name = "developtools" + part_name = "packing_tool" + sources = [ "./app_packager_file" ] + outputs = [ "$root_out_dir/tests/unittest/developtools/packing_tool/test_file/app_packager_file/" ] +} diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/AppScope/app.json b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..5470c22e225cb61e721cda383f7074711b2b0911 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/AppScope/app.json @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.example.myapplication", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/AppScope/resources/base/element/string.json b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1080233f01384411ec684b58955cb8808746fdd3 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication" + } + ] +} diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/AppScope/resources/base/media/app_icon.png b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/AppScope/resources/base/media/app_icon.png differ diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/BUILD.gn b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4c60d32e55cfa56c9dee037a8b9e67490d14b91c --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/BUILD.gn @@ -0,0 +1,41 @@ +# Copyright (c) 2023 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") + +ohos_hap("appPackagerHapTest") { + hap_profile = "entry/src/main/module.json" + hap_name = "appPackagerHapTest" + final_hap_path = "$root_out_dir/tests/unittest/developtools/packing_tool/test_file/test_bundle_app/${hap_name}.hap" + testonly = true + deps = [ + ":hjs_demo_js_assets", + ":hjs_demo_resources", + ] + certificate_profile = "../app_packager_file/com.test.apppackagertest.p7b" +} + +ohos_app_scope("bmsstagedemoone_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("hjs_demo_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("hjs_demo_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":bmsstagedemoone_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/ets/entryability/EntryAbility.ts b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/ets/entryability/EntryAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..aa5530d3497f025d1da5f1082f7d1d08893a59ae --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/ets/entryability/EntryAbility.ts @@ -0,0 +1,56 @@ +/* + * 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. + */ + +import UIAbility from '@ohos.app.ability.UIAbility'; +import hilog from '@ohos.hilog'; +import window from '@ohos.window'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/ets/pages/Index.ets b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..aa56579e8586af7bc8d35ba914031d0b19b2dcf8 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,32 @@ +/* + * 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. + */ + +@Entry +@Component +struct Index { + @State message: string = 'Hello World' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/module.json b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..9b07af70a189c0165e30b9f4bedc3bfd22b53cda --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/module.json @@ -0,0 +1,37 @@ +{ + "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" + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/resources/base/element/color.json b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/resources/base/element/string.json b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/resources/base/media/app_icon.png b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/resources/base/media/app_icon.png differ diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/resources/base/media/icon.png b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/resources/base/media/icon.png differ diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/resources/base/profile/main_pages.json b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHapTest/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/AppScope/app.json b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..5470c22e225cb61e721cda383f7074711b2b0911 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/AppScope/app.json @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.example.myapplication", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/AppScope/resources/base/element/string.json b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1080233f01384411ec684b58955cb8808746fdd3 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication" + } + ] +} diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/AppScope/resources/base/media/app_icon.png b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/AppScope/resources/base/media/app_icon.png differ diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/BUILD.gn b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e52b661f1ae3983a9d9c2bd4065a716994df9965 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/BUILD.gn @@ -0,0 +1,41 @@ +# Copyright (c) 2023 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") + +ohos_hap("appPackagerHspTest") { + hap_profile = "entry/src/main/module.json" + hap_name = "appPackagerHspTest" + final_hap_path = "$root_out_dir/tests/unittest/developtools/packing_tool/test_file/test_bundle_app/${hap_name}.hsp" + testonly = true + deps = [ + ":hjs_demo_js_assets", + ":hjs_demo_resources", + ] + certificate_profile = "../app_packager_file/com.test.apppackagertest.p7b" +} + +ohos_app_scope("bmsstagedemoone_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("hjs_demo_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("hjs_demo_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":bmsstagedemoone_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/ets/Index.ets b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/ets/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..3d41603b1dd13ae13d65d12d2569b1798c9cf88e --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/ets/Index.ets @@ -0,0 +1,16 @@ +/* + * 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. + */ + +export { add } from "./utils/Calc" \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/ets/pages/Index.ets b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..aa56579e8586af7bc8d35ba914031d0b19b2dcf8 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,32 @@ +/* + * 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. + */ + +@Entry +@Component +struct Index { + @State message: string = 'Hello World' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/ets/utils/Calc.ts b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/ets/utils/Calc.ts new file mode 100644 index 0000000000000000000000000000000000000000..ea3f851147dabf67fb68408d43d3e9011527890c --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/ets/utils/Calc.ts @@ -0,0 +1,18 @@ +/* + * 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. + */ + +export function add(a:number, b:number) { + return a + b; +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/module.json b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..10dc9bb580dfe706a76fc9c1199f75a6666ea4be --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/module.json @@ -0,0 +1,13 @@ +{ + "module": { + "name": "library1", + "type": "shared", + "description": "$string:shared_desc", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "pages": "$profile:main_pages" + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/resources/base/element/color.json b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..1bbc9aa9617e97c45440e1d3d66afc1154837012 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/resources/base/element/string.json b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..98e1d8a84b3d8539ea33e79fe2ac593a05d23bb4 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "shared_desc", + "value": "description" + } + ] +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/resources/base/media/icon.png b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/resources/base/media/icon.png differ diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/resources/base/media/setting.jpeg b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/resources/base/media/setting.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..57e67dd49d39ad64ef090f59db3db9dfe6632106 Binary files /dev/null and b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/resources/base/media/setting.jpeg differ diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/resources/base/profile/main_pages.json b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/appPackagerHspTest/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/app_packager_file/com.test.apppackagertest.csr b/packing_tool/frameworks/test/unittest/app_packager_test/app_packager_file/com.test.apppackagertest.csr new file mode 100644 index 0000000000000000000000000000000000000000..9ecf65601c3374a1d86f9cdeb913d0292a1a4af2 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/app_packager_file/com.test.apppackagertest.csr @@ -0,0 +1,24 @@ +/* + * 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. + */ + +-----BEGIN NEW CERTIFICATE REQUEST----- +MIIBNTCB3AIBADBKMRUwEwYDVQQDDAxpZGVfZGVtb19hcHAxDTALBgNVBAsTBFVu +aXQxFTATBgNVBAoTDE9yZ2FuaXphdGlvbjELMAkGA1UEBhMCQ04wWTATBgcqhkjO +PQIBBggqhkjOPQMBBwNCAAQequmvdgw5WvAULQXbK+oVaUYYSvjPWPwJicgE138+ +kDHiui2XgyWekVTz/JxH/98FiqCreVErXVofHsXqUTomoDAwLgYJKoZIhvcNAQkO +MSEwHzAdBgNVHQ4EFgQUIIMj4znts1On5EASmikrPOHI1acwCgYIKoZIzj0EAwID +SAAwRQIgN1VW6nzLSNpyf5f7/6SXq45cA0vzZqnat/EjetnJeNkCIQD6larwB7Up +M52qsxP8dGVlVCKbIFrWUQGUnrtdJ8cjEQ== +-----END NEW CERTIFICATE REQUEST----- diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/app_packager_file/com.test.apppackagertest.p7b b/packing_tool/frameworks/test/unittest/app_packager_test/app_packager_file/com.test.apppackagertest.p7b new file mode 100644 index 0000000000000000000000000000000000000000..1f83705e81172e9c781535036808fc14c3230393 Binary files /dev/null and b/packing_tool/frameworks/test/unittest/app_packager_test/app_packager_file/com.test.apppackagertest.p7b differ diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/app_packager_file/pack.info b/packing_tool/frameworks/test/unittest/app_packager_test/app_packager_file/pack.info new file mode 100644 index 0000000000000000000000000000000000000000..fa287952c95ba61f4de226417ca098291bf46c10 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/app_packager_file/pack.info @@ -0,0 +1,179 @@ +/* + * 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. + */ + +{ + "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" + }, + "apiVersion": { + "compatible": 9, + "releaseType": "Release", + "target": 9 + } + }, + { + "deviceType": [ + "default", + "tablet" + ], + "distro": { + "moduleType": "shared", + "deliveryWithInstall": true, + "moduleName": "library1" + }, + "apiVersion": { + "compatible": 9, + "releaseType": "Release", + "target": 9 + } + }, + { + "mainAbility": "ApplicationAbility", + "deviceType": [ + "default", + "tablet" + ], + "abilities": [ + { + "name": "ApplicationAbility", + "label": "$string:ApplicationAbility_label" + } + ], + "distro": { + "moduleType": "feature", + "installationFree": false, + "deliveryWithInstall": true, + "moduleName": "application" + }, + "apiVersion": { + "compatible": 9, + "releaseType": "Release", + "target": 9 + } + }, + { + "mainAbility": "Application1Ability", + "deviceType": [ + "default", + "tablet" + ], + "abilities": [ + { + "name": "Application1Ability", + "label": "$string:Application1Ability_label" + } + ], + "distro": { + "moduleType": "feature", + "installationFree": false, + "deliveryWithInstall": true, + "moduleName": "application1" + }, + "apiVersion": { + "compatible": 9, + "releaseType": "Release", + "target": 9 + } + }, + { + "deviceType": [ + "default", + "tablet" + ], + "distro": { + "moduleType": "shared", + "deliveryWithInstall": true, + "moduleName": "library2" + }, + "apiVersion": { + "compatible": 9, + "releaseType": "Release", + "target": 9 + } + } + ] + }, + "packages": [ + { + "deviceType": [ + "default", + "tablet" + ], + "moduleType": "entry", + "deliveryWithInstall": true, + "name": "entry-default" + }, + { + "deviceType": [ + "default", + "tablet" + ], + "moduleType": "shared", + "deliveryWithInstall": true, + "name": "library1-default" + }, + { + "deviceType": [ + "default", + "tablet" + ], + "moduleType": "feature", + "deliveryWithInstall": true, + "name": "application-entry-default" + }, + { + "deviceType": [ + "default", + "tablet" + ], + "moduleType": "feature", + "deliveryWithInstall": true, + "name": "application1-entry-default" + }, + { + "deviceType": [ + "default", + "tablet" + ], + "moduleType": "shared", + "deliveryWithInstall": true, + "name": "library2-default" + } + ] +} diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/app_packager_file/pack.res b/packing_tool/frameworks/test/unittest/app_packager_test/app_packager_file/pack.res new file mode 100644 index 0000000000000000000000000000000000000000..7804ec9015eac272d99a465eb2745a5bd4445b03 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/app_packager_file/pack.res @@ -0,0 +1,16 @@ +/* + * 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. + */ + +test \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/app_packager_test/app_packager_test.cpp b/packing_tool/frameworks/test/unittest/app_packager_test/app_packager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..64a272fa94fb78bca8d8b51970eb9b96b4758b1f --- /dev/null +++ b/packing_tool/frameworks/test/unittest/app_packager_test/app_packager_test.cpp @@ -0,0 +1,95 @@ +/* + * 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. + */ + +#include + +#include +#include "constants.h" +#define private public +#define protected public +#include "packager.h" +#include "app_packager.h" +#include "zip_wrapper.h" +#include "log.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +#define OUT_PATH "/data/test.app" +#define HAP_PATH "/data/test/resource/packingtool/test_file/hap/appPackagerHapTest.hap" +#define HSP_PATH "/data/test/resource/packingtool/test_file/hsp/appPackagerHspTest.hsp" +#define PACK_INFO_PATH "/data/test/resource/packingtool/test_file/packinfo/pack.info" +#define SIGNATURE_PATH "/data/test/resource/packingtool/test_file/signature/com.test.apppackagertest.csr" +#define CERTIFICATE_PATH "/data/test/resource/packingtool/test_file/certificate/com.test.apppackagertest.p7b" +#define PACK_RES_PATH "/data/test/resource/packingtool/test_file/packres/pack.res" + +class AppPackagerTest : public testing::Test { +public: + AppPackagerTest() {} + virtual ~AppPackagerTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void AppPackagerTest::SetUpTestCase() {} + +void AppPackagerTest::TearDownTestCase() {} + +void AppPackagerTest::SetUp() {} + +void AppPackagerTest::TearDown() {} + +/* + * @tc.name: InitAllowedParam_0100 + * @tc.desc: InitAllowedParam. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(AppPackagerTest, InitAllowedParam_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "true"}, + {OHOS::AppPackingTool::Constants::PARAM_HAP_PATH, HAP_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_HSP_PATH, HSP_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_PACK_INFO_PATH, PACK_INFO_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_SIGNATURE_PATH, SIGNATURE_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_CERTIFICATE_PATH, CERTIFICATE_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_PACK_RES_PATH, PACK_RES_PATH}, + }; + + OHOS::AppPackingTool::AppPackager appPackager(parameterMap, resultReceiver); + EXPECT_EQ(appPackager.InitAllowedParam(), 0); + EXPECT_EQ(appPackager.PreProcess(), 0); + EXPECT_EQ(appPackager.Process(), 0); + EXPECT_EQ(appPackager.PostProcess(), 0); + + + std::string cmd = {"rm -f "}; + cmd += OUT_PATH; + system(cmd.c_str()); +} +} // namespace OHOS \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/appqf_packager_test/BUILD.gn b/packing_tool/frameworks/test/unittest/appqf_packager_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..31119582325e9ba5db16eaac054dc213cd700c0b --- /dev/null +++ b/packing_tool/frameworks/test/unittest/appqf_packager_test/BUILD.gn @@ -0,0 +1,73 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("appqf_packager_test_config") { + include_dirs = [ + "../../../include", + "../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("appqf_packager_test") { + module_out_path = module_output_path + public_configs = [ ":appqf_packager_test_config" ] + sources = [ + "../../../src/appqf_packager.cpp", + "../../../src/hqf_packager.cpp", + "../../../src/hqf_verify.cpp", + "../../../src/json/json_utils.cpp", + "../../../src/json/module_json.cpp", + "../../../src/json/normalize_version_utils.cpp", + "../../../src/json/pack_info.cpp", + "../../../src/json/patch_json.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", + "appqf_packager_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 = [ ":appqf_packager_test" ] +} + +ohos_copy("copy_test_file") { + subsystem_name = "developtools" + part_name = "packing_tool" + sources = [ "../hqf_packager_test/hqf_packager_file" ] + outputs = [ "$root_out_dir/tests/unittest/developtools/packing_tool/test_file/appqf_packager_file/" ] +} diff --git a/packing_tool/frameworks/test/unittest/appqf_packager_test/appqf_packager_test.cpp b/packing_tool/frameworks/test/unittest/appqf_packager_test/appqf_packager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ac8afa35d6e0565d8d6b09613442dc548701d119 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/appqf_packager_test/appqf_packager_test.cpp @@ -0,0 +1,167 @@ +/* + * 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. + */ + +#include + +#include +#include "constants.h" +#define private public +#define protected public +#include "hqf_packager.h" +#include "appqf_packager.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +#define FILE_PATH "/data/utils_Test" +#define HQF_ETS_PATH_ONE "/data/test/resource/packingtool/test_file/appqf_packager_file/hqfFileExample1/ets" +#define HQF_ETS_PATH_TWO "/data/test/resource/packingtool/test_file/appqf_packager_file/hqfFileExample2/ets" +#define HQF_LIST "/data/test/testPack/testHqfPack1.hqf,/data/test/testPack/testHqfPack2.hqf" +#define HQF_JSON_PATH_ONE "/data/test/resource/packingtool/test_file/appqf_packager_file/hqfFileExample1/patch.json" +#define HQF_JSON_PATH_TWO "/data/test/resource/packingtool/test_file/appqf_packager_file/hqfFileExample2/patch.json" +#define HQF_OUT_PATH_ONE "/data/test/testPack/testHqfPack1.hqf" +#define HQF_OUT_PATH_TWO "/data/test/testPack/testHqfPack2.hqf" +#define HQF_RESOURCES_PATH_ONE "/data/test/resource/packingtool/test_file/appqf_packager_file/hqfFileExample2/resources" +#define HQF_RESOURCES_PATH_TWO "/data/test/resource/packingtool/test_file/appqf_packager_file/hqfFileExample2/resources" +#define OUT_PATH "/data/test/testAppQFPack/testappqfPack.appqf" +#define TEMP_PATH "/data" +class AppqfPackagetTest : public testing::Test { +public: + AppqfPackagetTest() {} + virtual ~AppqfPackagetTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void AppqfPackagetTest::SetUpTestCase() +{ + std::string resultReceiver; + std::map parameterMap1 = { + {OHOS::AppPackingTool::Constants::PARAM_JSON_PATH, HQF_JSON_PATH_ONE}, + {OHOS::AppPackingTool::Constants::PARAM_ETS_PATH, HQF_ETS_PATH_ONE}, + {OHOS::AppPackingTool::Constants::PARAM_RESOURCES_PATH, HQF_RESOURCES_PATH_ONE}, + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "true"}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, HQF_OUT_PATH_ONE}, + }; + + std::map parameterMap2 = { + {OHOS::AppPackingTool::Constants::PARAM_JSON_PATH, HQF_JSON_PATH_TWO}, + {OHOS::AppPackingTool::Constants::PARAM_ETS_PATH, HQF_ETS_PATH_TWO}, + {OHOS::AppPackingTool::Constants::PARAM_RESOURCES_PATH, HQF_RESOURCES_PATH_TWO}, + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "true"}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, HQF_OUT_PATH_TWO}, + }; + + OHOS::AppPackingTool::HqfPackager hqfPackager1(parameterMap1, resultReceiver); + EXPECT_EQ(hqfPackager1.PreProcess(), 0); + EXPECT_EQ(hqfPackager1.Process(), 0); + OHOS::AppPackingTool::HqfPackager hqfPackager2(parameterMap2, resultReceiver); + EXPECT_EQ(hqfPackager2.PreProcess(), 0); + EXPECT_EQ(hqfPackager2.Process(), 0); +} + +void AppqfPackagetTest::TearDownTestCase() {} + +void AppqfPackagetTest::SetUp() {} + +void AppqfPackagetTest::TearDown() {} + +/* + * @tc.name: AppqfPackage_0100 + * @tc.desc: AppqfPackage + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(AppqfPackagetTest, AppqfPackage_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap1 = { + {OHOS::AppPackingTool::Constants::PARAM_HQF_LIST, HQF_LIST}, + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "true"}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + }; + + OHOS::AppPackingTool::APPQFPackager appQFPackager(parameterMap1, resultReceiver); + EXPECT_EQ(appQFPackager.PreProcess(), 0); + EXPECT_EQ(appQFPackager.Process(), 0); + std::string cmd = {"rm -f "}; + cmd +=OUT_PATH; + system(cmd.c_str()); +} + +/* + * @tc.name: PreProcess_0100 + * @tc.desc: Output file not end with .apphqf. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(AppqfPackagetTest, PreProcess_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap1 = { + {OHOS::AppPackingTool::Constants::PARAM_HQF_LIST, HQF_LIST}, + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "true"}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, "/data/test/testPack/testAppQFPack"} + }; + OHOS::AppPackingTool::APPQFPackager appQFPackager(parameterMap1, resultReceiver); + EXPECT_EQ(appQFPackager.PreProcess(), 1); +} + +/* + * @tc.name: PreProcess_0200 + * @tc.desc: Input hqf list is empty. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(AppqfPackagetTest, PreProcess_0200, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap1 = { + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "true"}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH} + }; + OHOS::AppPackingTool::APPQFPackager appQFPackager(parameterMap1, resultReceiver); + EXPECT_EQ(appQFPackager.PreProcess(), 1); +} + +/* + * @tc.name: PreProcess_0300 + * @tc.desc: Input hqf list is invalid. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(AppqfPackagetTest, PreProcess_0300, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap1 = { + {OHOS::AppPackingTool::Constants::PARAM_HQF_LIST, "/data/test/testPack/testHqfPackerr.hqf"}, + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "true"}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH} + }; + + OHOS::AppPackingTool::APPQFPackager appQFPackager(parameterMap1, resultReceiver); + EXPECT_EQ(appQFPackager.PreProcess(), 1); +} +} // namespace OHOS \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/BUILD.gn b/packing_tool/frameworks/test/unittest/fast_app_packager_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e51577d560f1c341c265e521b92a851e4a0bdef0 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/BUILD.gn @@ -0,0 +1,75 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("fast_app_packager_test_config") { + include_dirs = [ + "../../../include", + "../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} +module_output_path = "developtools/packing_tool" + +ohos_unittest("fast_app_packager_test") { + module_out_path = module_output_path + public_configs = [ ":fast_app_packager_test_config" ] + sources = [ + "../../../src/fast_app_packager.cpp", + "../../../src/json/distro_filter.cpp", + "../../../src/json/hap_verify_info.cpp", + "../../../src/json/hap_verify_utils.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/module_json_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", + "fast_app_packager_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", + "./hspTestFile:fastAppPackagerHspTest", + ] +} + +group("unittest") { + testonly = true + deps = [ ":fast_app_packager_test" ] +} + +ohos_copy("copy_test_file") { + subsystem_name = "developtools" + part_name = "packing_tool" + sources = [ "./fast_app_packager_file" ] + outputs = [ "$root_out_dir/tests/unittest/developtools/packing_tool/test_file/fast_app_packager_file/" ] +} diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_file/hap/entry/module.json b/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_file/hap/entry/module.json new file mode 100644 index 0000000000000000000000000000000000000000..39936d49a5f0e685e23a1a268421ec45b77e3d3c --- /dev/null +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_file/hap/entry/module.json @@ -0,0 +1 @@ +{"app":{"iconId":16777217,"labelId":16777216,"vendor":"example","icon":"$media:app_icon","bundleName":"com.example.packingtooldemo","label":"$string:app_name","versionName":"1.0.0","apiReleaseType":"Release","versionCode":1000000},"module":{"virtualMachine":"ark12.0.6.0","mainElement":"EntryAbility","buildHash":"a06e3167c6700f3fe721b26fdc6c7473c106f0cf2f35dbdd65e50405a51f740d","installationFree":false,"deliveryWithInstall":true,"description":"$string:module_desc","compileMode":"esmodule","type":"entry","dependencies":[],"abilities":[{"exported":true,"iconId":16777222,"startWindowIconId":16777222,"icon":"$media:icon","startWindowIcon":"$media:icon","startWindowBackgroundId":16777221,"description":"$string:EntryAbility_desc","label":"$string:EntryAbility_label","skills":[{"entities":["entity.system.home"],"actions":["action.system.home"]}],"srcEntry":"./ets/entryability/EntryAbility.ts","descriptionId":16777218,"labelId":16777219,"startWindowBackground":"$color:start_window_background","name":"EntryAbility"}],"deviceTypes":["default","tablet"],"pages":"$profile:main_pages","descriptionId":16777220,"name":"entry"}} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_file/hap/entry/pack.json b/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_file/hap/entry/pack.json new file mode 100644 index 0000000000000000000000000000000000000000..b221fd946883c1f06110607139ff2d23ebc7d39d --- /dev/null +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_file/hap/entry/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/fast_app_packager_test/fast_app_packager_file/hap/entry/resources/base/profile/main_pages.json b/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_file/hap/entry/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..396cce19930fc7a3ce7f585fb7858106a33e779c --- /dev/null +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_file/hap/entry/resources/base/profile/main_pages.json @@ -0,0 +1 @@ +{"src":["pages/Index"]} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_file/pack.json b/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_file/pack.json new file mode 100644 index 0000000000000000000000000000000000000000..bb3551099b99a5ed04477730409d4bc086a6f295 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_file/pack.json @@ -0,0 +1,73 @@ +{ + "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 + } + }, + { + "deviceType": [ + "default", + "tablet" + ], + "distro": { + "moduleType": "shared", + "deliveryWithInstall": true, + "moduleName": "library" + }, + "apiVersion": { + "compatible": 12, + "releaseType": "Canary2", + "target": 12 + } + } + ] + }, + "packages": [ + { + "deviceType": [ + "default", + "tablet" + ], + "moduleType": "entry", + "deliveryWithInstall": true, + "name": "entry-default" + }, + { + "deviceType": [ + "default", + "tablet" + ], + "moduleType": "shared", + "deliveryWithInstall": true, + "name": "fastAppPackagerHspTest" + } + ] +} diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_test.cpp b/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..23d82edbb94a9dbdcc9351c02d758f3d5d4dddfa --- /dev/null +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/fast_app_packager_test.cpp @@ -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. + */ + +#include +#include + +#define private public +#define protected public +#include "fast_app_packager.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +#define OUT_PATH "/data/test/packingToolDemo-default-unsigned.app" +#define HAP_PATH "/data/test/resource/packingtool/test_file/hap/entry" +#define PACK_INFO_PATH "/data/test/resource/packingtool/test_file/pack.info" +#define HSP_PATH "/data/test/resource/packingtool/test_file/fastAppPackagerHspTest.hsp" + +class FastAppPackagerTest : public testing::Test { +public: + FastAppPackagerTest() {} + virtual ~FastAppPackagerTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void FastAppPackagerTest::SetUpTestCase() {} + +void FastAppPackagerTest::TearDownTestCase() {} + +void FastAppPackagerTest::SetUp() {} + +void FastAppPackagerTest::TearDown() {} + +/* + * @tc.name: fastAppPackager_0100 + * @tc.desc: fastAppPackager. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(FastAppPackagerTest, fastAppPackager_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "true"}, + {OHOS::AppPackingTool::Constants::PARAM_HAP_PATH, HAP_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_HSP_PATH, HSP_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_PACK_INFO_PATH, PACK_INFO_PATH}, + }; + + OHOS::AppPackingTool::FastAppPackager fastAppackager(parameterMap, resultReceiver); + system("mv /data/test/resource/packingtool/test_file/pack.json " + "/data/test/resource/packingtool/test_file/pack.info"); + system("mv /data/test/resource/packingtool/test_file/hap/entry/pack.json " + "/data/test/resource/packingtool/test_file/hap/entry/pack.info"); + EXPECT_EQ(fastAppackager.InitAllowedParam(), 0); + EXPECT_EQ(fastAppackager.PreProcess(), 0); + EXPECT_EQ(fastAppackager.Process(), 0); + EXPECT_EQ(fastAppackager.PostProcess(), 0); + + std::string cmd = {"rm -f "}; + cmd +=OUT_PATH; + system(cmd.c_str()); +} +} // namespace OHOS \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/AppScope/app.json b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..94824fae2b933ccb152705266ae6331c0eadfc7a --- /dev/null +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/AppScope/app.json @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.example.packingtooldemo", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/AppScope/resources/base/element/string.json b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..93e8b7fa2fa78c1793d02ae5bc6042d234e832c2 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "packingToolDemo" + } + ] +} diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/AppScope/resources/base/media/app_icon.png b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..cd45accb1dfd2fd0da16c732c72faa6e46b26521 Binary files /dev/null and b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/AppScope/resources/base/media/app_icon.png differ diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/BUILD.gn b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..1f7a3e626b610dc1c6bbcdd8e4e6757d1718dc5a --- /dev/null +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/BUILD.gn @@ -0,0 +1,41 @@ +# 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. + +import("//build/ohos.gni") + +ohos_hap("fastAppPackagerHspTest") { + hap_profile = "library/src/main/module.json" + hap_name = "fastAppPackagerHspTest" + final_hap_path = "$root_out_dir/tests/unittest/developtools/packing_tool/test_file/fast_app_packager_file/${hap_name}.hsp" + testonly = true + deps = [ + ":hjs_demo_js_assets", + ":hjs_demo_resources", + ] + certificate_profile = "./com.test.packingtooldemo.p7b" +} + +ohos_app_scope("bmsstagedemoone_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("hjs_demo_js_assets") { + source_dir = "library/src/main/ets" +} + +ohos_resources("hjs_demo_resources") { + sources = [ "library/src/main/resources" ] + deps = [ ":bmsstagedemoone_app_profile" ] + hap_profile = "library/src/main/module.json" +} diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/com.test.packingtooldemo.p7b b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/com.test.packingtooldemo.p7b new file mode 100644 index 0000000000000000000000000000000000000000..b4a8d1550d163689f65b5b01180fda3f481782ac Binary files /dev/null and b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/com.test.packingtooldemo.p7b differ diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/ets/Index.ets b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/ets/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..3d41603b1dd13ae13d65d12d2569b1798c9cf88e --- /dev/null +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/ets/Index.ets @@ -0,0 +1,16 @@ +/* + * 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. + */ + +export { add } from "./utils/Calc" \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/ets/pages/Index.ets b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..aa56579e8586af7bc8d35ba914031d0b19b2dcf8 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/ets/pages/Index.ets @@ -0,0 +1,32 @@ +/* + * 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. + */ + +@Entry +@Component +struct Index { + @State message: string = 'Hello World' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/ets/utils/Calc.ts b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/ets/utils/Calc.ts new file mode 100644 index 0000000000000000000000000000000000000000..ea3f851147dabf67fb68408d43d3e9011527890c --- /dev/null +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/ets/utils/Calc.ts @@ -0,0 +1,18 @@ +/* + * 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. + */ + +export function add(a:number, b:number) { + return a + b; +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/module.json b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..1e65fa598dc4f647354a588d333aa07eb6efc291 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/module.json @@ -0,0 +1,14 @@ +{ + "module": { + "name": "library", + "type": "shared", + "description": "$string:shared_desc", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "pages": "$profile:main_pages", + "generateBuildHash": true + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/resources/base/element/color.json b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..1bbc9aa9617e97c45440e1d3d66afc1154837012 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/resources/base/element/string.json b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..95ba6cbabb98622d7723dcd5f616d3326345eb95 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "shared_desc", + "value": "description" + } + ] +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/resources/base/media/icon.png b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/resources/base/media/icon.png differ diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/resources/base/media/setting.jpeg b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/resources/base/media/setting.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..57e67dd49d39ad64ef090f59db3db9dfe6632106 Binary files /dev/null and b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/resources/base/media/setting.jpeg differ diff --git a/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/resources/base/profile/main_pages.json b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/packing_tool/frameworks/test/unittest/fast_app_packager_test/hspTestFile/library/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/packing_tool/frameworks/test/unittest/hap_packager_test/BUILD.gn b/packing_tool/frameworks/test/unittest/hap_packager_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7983d211d38422f8cd61281be02adefa57b7334f --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hap_packager_test/BUILD.gn @@ -0,0 +1,68 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("hap_packager_test_config") { + include_dirs = [ + "../../../include", + "../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("hap_packager_test") { + module_out_path = module_output_path + public_configs = [ ":hap_packager_test_config" ] + sources = [ + "../../../src/hap_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/pt_json.cpp", + "../../../src/log.cpp", + "../../../src/packager.cpp", + "../../../src/utils.cpp", + "../../../src/zip_wrapper.cpp", + "hap_packager_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 = [ ":hap_packager_test" ] +} + +ohos_copy("copy_test_file") { + subsystem_name = "developtools" + part_name = "packing_tool" + sources = [ "./hap_packager_file" ] + outputs = [ "$root_out_dir/tests/unittest/developtools/packing_tool/test_file/hap_packager_file/" ] +} diff --git a/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_file/fa/assets_jsbundle/default/js/MainAbility/app.js b/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_file/fa/assets_jsbundle/default/js/MainAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..6615ccb8c31a1fc86bf067d114c22852b3009d0d --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_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/hap_packager_test/hap_packager_file/fa/assets_jsbundle/default/js/MainAbility/app.js.map b/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_file/fa/assets_jsbundle/default/js/MainAbility/app.js.map new file mode 100644 index 0000000000000000000000000000000000000000..4166a633646ff1cc6eba0a0b96c27387984b7f11 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_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":";;;;;AAAA,CAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAK,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,WAAc,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAEhC,CAAe,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;IACb,QAAQ,CAAA,CAAA,CAAA,CAAA,CAAA;QACN,CAAK,CAAA,CAAA,CAAA,CAAA,CAAC,CAAI,CAAA,CAAA,CAAA,CAAC,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAE,CAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAE,CAAY,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAE,CAAsB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAC,CAAC,CAAA;CACrE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;IACD,SAAS,CAAA,CAAA,CAAA,CAAA,CAAA;QACP,CAAK,CAAA,CAAA,CAAA,CAAA,CAAC,CAAI,CAAA,CAAA,CAAA,CAAC,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAE,CAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAE,CAAY,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAE,CAAuB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAC,CAAC,CAAA;CACtE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;CACH,CAAA;;"} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_file/fa/assets_jsbundle/default/js/MainAbility/manifest.json b/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_file/fa/assets_jsbundle/default/js/MainAbility/manifest.json new file mode 100644 index 0000000000000000000000000000000000000000..a4bfd1e2bd7ff2139238dd4e309c6f8c4f2b6abc --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_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/hap_packager_test/hap_packager_file/fa/assets_jsbundle/default/js/MainAbility/pages/index.js b/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_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/hap_packager_test/hap_packager_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/hap_packager_test/hap_packager_file/fa/assets_jsbundle/default/js/MainAbility/pages/index.js.map b/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_file/fa/assets_jsbundle/default/js/MainAbility/pages/index.js.map new file mode 100644 index 0000000000000000000000000000000000000000..d77a1f9f0e7a7175944fb7688f1920846c92a7d8 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_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":";;;;CAEO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAK,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAFZ,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;sDAG2B,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;AAHxC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;;;;;;;;;;;;;;;QAGS,OAAO,CAAA,CAAA,CAAA,CAAA,CAAA;;;KAAP,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;;AAEd,CAAA,CAAA,CAAA,CAAA,aAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;;YACE,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;YAAH,GAAG,CAQF,CAAA,CAAA,CAAA,CAAA,CAAA,CAAM,CAAC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAM,CAAA,CAAA,CAAA;;gBARd,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;;;;;YACD,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;YAAN,MAAM,CAKL,CAAA,CAAA,CAAA,CAAA,CAAK,CAAC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAM,CAAA,CAAA,CAAA;;gBALb,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;;;;;CACJ,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAC,IAAI,CAAC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAA,CAAA,CAAA;YAAjB,IAAI,CACD,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAQ,CAAC,CAAA,CAAE,CAAA,CAAA,CAAA;AADd,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAI,CAED,CAAU,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAC,UAAU,CAAC,CAAA,CAAA,CAAA,CAAI,CAAA,CAAA,CAAA;;gBAF7B,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;;;QAAJ,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;QADN,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;QADR,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AASJ,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;;;;;;"} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_file/fa/config.json b/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_file/fa/config.json new file mode 100644 index 0000000000000000000000000000000000000000..58e4106a4528142de32592f85f2259cbc12cda7e --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_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/hap_packager_test/hap_packager_file/fa/pack.json b/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_file/fa/pack.json new file mode 100644 index 0000000000000000000000000000000000000000..04870b2ba492f9ca56d31efaa15f4974c9926d1a --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_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/hap_packager_test/hap_packager_file/stage/ets/sourceMaps.map b/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_file/stage/ets/sourceMaps.map new file mode 100644 index 0000000000000000000000000000000000000000..027a060231c8f4b58efeb820e33c187d4cd565e8 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_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;AACA;AAGA;;;;;;;AASE;;;;;AAMM;;AAED;AACD;AACF;;;;;;;;;;;;;;AAiBH;" + }, + "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;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;AAKE;;;;;;;;;;;;AAGM;;;;;AAOL;;;;;;;;;" + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_file/stage/module.json b/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_file/stage/module.json new file mode 100644 index 0000000000000000000000000000000000000000..5427967a52f1b8cf4f641a56402cd3b39e8453ef --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_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/hap_packager_test/hap_packager_file/stage/pack.json b/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_file/stage/pack.json new file mode 100644 index 0000000000000000000000000000000000000000..b221fd946883c1f06110607139ff2d23ebc7d39d --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_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/hap_packager_test/hap_packager_file/stage/resources/base/profile/main_pages.json b/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_file/stage/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_file/stage/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_test.cpp b/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0ca87910a7b516972cd4c9262af7062f55c2d52f --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hap_packager_test/hap_packager_test.cpp @@ -0,0 +1,153 @@ +/* + * 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. + */ + +#include +#include + +#define private public +#define protected public +#include "hap_packager.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +#define OUT_PATH "/data/test/entry-default-unsigned.hap" +#define STAGE_INDEX_PATH "/data/test/resource/packingtool/test_file/stage/resources.index" +#define STAGE_PACK_INFO_PATH "/data/test/resource/packingtool/test_file/stage/pack.info" +#define STAGE_ETS_PATH "/data/test/resource/packingtool/test_file/stage/ets" +#define STAGE_RESOURCES_PATH "/data/test/resource/packingtool/test_file/stage/resources" +#define STAGE_JSON_PATH "/data/test/resource/packingtool/test_file/stage/module.json" +#define STAGE_RPCID_PATH "/data/test/resource/packingtool/test_file/stage/rpcid.sc" + +#define FA_INDEX_PATH "/data/test/resource/packingtool/test_file/fa/resources.index" +#define FA_PACK_INFO_PATH "/data/test/resource/packingtool/test_file/fa/pack.info" +#define FA_RESOURCES_PATH "/data/test/resource/packingtool/test_file/fa/resources" +#define FA_JSON_PATH "/data/test/resource/packingtool/test_file/fa/config.json" +#define FA_ASSETS_PATH "/data/test/resource/packingtool/test_file/fa/assets_jsbundle/default" + +class HapPackagerTest : public testing::Test { +public: + HapPackagerTest() {} + virtual ~HapPackagerTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void HapPackagerTest::SetUpTestCase() {} + +void HapPackagerTest::TearDownTestCase() {} + +void HapPackagerTest::SetUp() {} + +void HapPackagerTest::TearDown() {} + +/* + * @tc.name: hapPackager_0100 + * @tc.desc: hapPackager. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapPackagerTest, hapPackager_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, 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("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 -f /data/test/resource/packingtool/test_file/stage/resources.index"); + + std::string cmd = {"rm -f "}; + cmd +=OUT_PATH; + system(cmd.c_str()); +} + +/* + * @tc.name: hapPackager_0200 + * @tc.desc: hapPackager. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapPackagerTest, hapPackager_0200, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "true"}, + {OHOS::AppPackingTool::Constants::PARAM_JSON_PATH, FA_JSON_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_ASSETS_PATH, FA_ASSETS_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_RESOURCES_PATH, FA_RESOURCES_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_INDEX_PATH, FA_INDEX_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_PACK_INFO_PATH, FA_PACK_INFO_PATH}, + }; + + OHOS::AppPackingTool::HapPackager hapPackager(parameterMap, resultReceiver); + system("touch /data/test/resource/packingtool/test_file/fa/resources.index"); + system("mkdir /data/test/resource/packingtool/test_file/fa/resources"); + system("mv /data/test/resource/packingtool/test_file/fa/pack.json " + "/data/test/resource/packingtool/test_file/fa/pack.info"); + 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/fa/resources"); + system("rm -f /data/test/resource/packingtool/test_file/fa/resources.index"); + + std::string cmd = {"rm -f "}; + cmd +=OUT_PATH; + system(cmd.c_str()); +} + +/* + * @tc.name: IsValidRpcid_0300 + * @tc.desc: IsValidRpcid. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapPackagerTest, IsValidRpcid_0300, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_RPCID_PATH, STAGE_RPCID_PATH}, + }; + system("touch /data/test/resource/packingtool/test_file/stage/rpcid.sc"); + OHOS::AppPackingTool::HapPackager hapPackager(parameterMap, resultReceiver); + EXPECT_TRUE(hapPackager.IsValidRpcid()); + system("rm -f /data/test/resource/packingtool/test_file/stage/rpcid.sc"); +} +} // namespace OHOS \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/hqf_packager_test/BUILD.gn b/packing_tool/frameworks/test/unittest/hqf_packager_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8617c9a8886018a52360a90e3103d9b88ad4784b --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hqf_packager_test/BUILD.gn @@ -0,0 +1,70 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("hqf_packager_test_config") { + include_dirs = [ + "../../../include", + "../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("hqf_packager_test") { + module_out_path = module_output_path + public_configs = [ ":hqf_packager_test_config" ] + sources = [ + "../../../src/hqf_packager.cpp", + "../../../src/json/json_utils.cpp", + "../../../src/json/module_json.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", + "hqf_packager_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 = [ ":hqf_packager_test" ] +} + +ohos_copy("copy_test_file") { + subsystem_name = "developtools" + part_name = "packing_tool" + sources = [ "./hqf_packager_file" ] + outputs = [ "$root_out_dir/tests/unittest/developtools/packing_tool/test_file/hqf_packager_file/" ] +} diff --git a/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample1/ets/sourceMaps.map b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample1/ets/sourceMaps.map new file mode 100644 index 0000000000000000000000000000000000000000..c8256e69588d9850d5df52643b803b5708e65443 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample1/ets/sourceMaps.map @@ -0,0 +1,22 @@ +{ + "entry/build/default/cache/default/default@CompileArkTS/esmodule/debug/entry/src/main/ets/entryability/EntryAbility.ts": { + "version": 3, + "file": "EntryAbility.ets", + "sourceRoot": "", + "sources": [ + "entry/src/main/ets/entryability/EntryAbility.ets" + ], + "names": [], + "mappings": ";;;;;AAIA,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,SAAS;IACjD,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,eAAe,CAAC,WAAW,GAAG,IAAI;QAClE,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,kBAAkB,CAAC,CAAC;IAClE,CAAC;IAED,SAAS,IAAI,IAAI;QACf,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,mBAAmB,CAAC,CAAC;IACnE,CAAC;IAED,mBAAmB,CAAC,WAAW,EAAE,MAAM,CAAC,WAAW,GAAG,IAAI;QACxD,yDAAyD;QACzD,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,6BAA6B,CAAC,CAAC;QAE3E,WAAW,CAAC,WAAW,CAAC,aAAa,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;YACnD,IAAI,GAAG,CAAC,IAAI,EAAE;gBACZ,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,+CAA+C,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;gBAC3G,OAAO;aACR;YACD,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,oDAAoD,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAClH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,oBAAoB,IAAI,IAAI;QAC1B,yDAAyD;QACzD,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,8BAA8B,CAAC,CAAC;IAC9E,CAAC;IAED,YAAY,IAAI,IAAI;QAClB,oCAAoC;QACpC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,sBAAsB,CAAC,CAAC;IACtE,CAAC;IAED,YAAY,IAAI,IAAI;QAClB,iCAAiC;QACjC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,sBAAsB,CAAC,CAAC;IACtE,CAAC;CACF" + }, + "entry/build/default/cache/default/default@CompileArkTS/esmodule/debug/entry/src/main/ets/pages/Index.ts": { + "version": 3, + "file": "Index.ets", + "sourceRoot": "", + "sources": [ + "entry/src/main/ets/pages/Index.ets" + ], + "names": [], + "mappings": ";;;;IAGS,OAAO,GAAE,MAAM;;MADjB,KAAK;IAFZ;;;;;sDAG2B,WAAW;;;KAHtC;;;;;;;;;;;;;;;;IAGE,4CAAgB,MAAM,EAAe;QAA9B,OAAO;;;QAAP,OAAO,WAAE,MAAM;;;IAEtB;;YACE,GAAG;YAAH,GAAG,CAQF,MAAM,CAAC,MAAM;;;YAPZ,MAAM;YAAN,MAAM,CAKL,KAAK,CAAC,MAAM;;;YAJX,IAAI,QAAC,IAAI,CAAC,OAAO;YAAjB,IAAI,CACD,QAAQ,CAAC,EAAE;YADd,IAAI,CAED,UAAU,CAAC,UAAU,CAAC,IAAI;;QAF7B,IAAI;QADN,MAAM;QADR,GAAG;KASJ" + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample1/patch.json b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample1/patch.json new file mode 100644 index 0000000000000000000000000000000000000000..5e2ac2b15fda5dbf3e87021f9381643c6b385587 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample1/patch.json @@ -0,0 +1,18 @@ +{ + "app": { + "bundleName": "com.example.testquickfix", + "versionCode": 1000000, + "versionName": "1.0.0.1", + "patchVersionCode": 1000000, + "patchVersionName": "1.0.0.1" + }, + "module": { + "name": "entry1", + "type": "patch", + "deviceTypes": [ + "default1", + "tablet1" + ], + "originalModuleHash": "c97441c96c84b2ffcb7c85570fb60a0be114ca1f438f8af51b33004081ddb782" + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample1/resources/base/media/aa_icon.png b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample1/resources/base/media/aa_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample1/resources/base/media/aa_icon.png differ diff --git a/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample1/resources/base/media/app_icon.png b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample1/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample1/resources/base/media/app_icon.png differ diff --git a/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample1/resources/base/profile/main_pages.json b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample1/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..194c81ade2d953008c5e80fa42a67ed7c354f356 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample1/resources/base/profile/main_pages.json @@ -0,0 +1 @@ +{"src":["pages/index/index","pages/second/second"]} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample2/ets/sourceMaps.map b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample2/ets/sourceMaps.map new file mode 100644 index 0000000000000000000000000000000000000000..c8256e69588d9850d5df52643b803b5708e65443 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample2/ets/sourceMaps.map @@ -0,0 +1,22 @@ +{ + "entry/build/default/cache/default/default@CompileArkTS/esmodule/debug/entry/src/main/ets/entryability/EntryAbility.ts": { + "version": 3, + "file": "EntryAbility.ets", + "sourceRoot": "", + "sources": [ + "entry/src/main/ets/entryability/EntryAbility.ets" + ], + "names": [], + "mappings": ";;;;;AAIA,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,SAAS;IACjD,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,eAAe,CAAC,WAAW,GAAG,IAAI;QAClE,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,kBAAkB,CAAC,CAAC;IAClE,CAAC;IAED,SAAS,IAAI,IAAI;QACf,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,mBAAmB,CAAC,CAAC;IACnE,CAAC;IAED,mBAAmB,CAAC,WAAW,EAAE,MAAM,CAAC,WAAW,GAAG,IAAI;QACxD,yDAAyD;QACzD,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,6BAA6B,CAAC,CAAC;QAE3E,WAAW,CAAC,WAAW,CAAC,aAAa,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;YACnD,IAAI,GAAG,CAAC,IAAI,EAAE;gBACZ,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,+CAA+C,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;gBAC3G,OAAO;aACR;YACD,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,oDAAoD,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAClH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,oBAAoB,IAAI,IAAI;QAC1B,yDAAyD;QACzD,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,8BAA8B,CAAC,CAAC;IAC9E,CAAC;IAED,YAAY,IAAI,IAAI;QAClB,oCAAoC;QACpC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,sBAAsB,CAAC,CAAC;IACtE,CAAC;IAED,YAAY,IAAI,IAAI;QAClB,iCAAiC;QACjC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,sBAAsB,CAAC,CAAC;IACtE,CAAC;CACF" + }, + "entry/build/default/cache/default/default@CompileArkTS/esmodule/debug/entry/src/main/ets/pages/Index.ts": { + "version": 3, + "file": "Index.ets", + "sourceRoot": "", + "sources": [ + "entry/src/main/ets/pages/Index.ets" + ], + "names": [], + "mappings": ";;;;IAGS,OAAO,GAAE,MAAM;;MADjB,KAAK;IAFZ;;;;;sDAG2B,WAAW;;;KAHtC;;;;;;;;;;;;;;;;IAGE,4CAAgB,MAAM,EAAe;QAA9B,OAAO;;;QAAP,OAAO,WAAE,MAAM;;;IAEtB;;YACE,GAAG;YAAH,GAAG,CAQF,MAAM,CAAC,MAAM;;;YAPZ,MAAM;YAAN,MAAM,CAKL,KAAK,CAAC,MAAM;;;YAJX,IAAI,QAAC,IAAI,CAAC,OAAO;YAAjB,IAAI,CACD,QAAQ,CAAC,EAAE;YADd,IAAI,CAED,UAAU,CAAC,UAAU,CAAC,IAAI;;QAF7B,IAAI;QADN,MAAM;QADR,GAAG;KASJ" + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample2/patch.json b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample2/patch.json new file mode 100644 index 0000000000000000000000000000000000000000..b600b8809dc6217857c32854c03874bd01b6f856 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample2/patch.json @@ -0,0 +1,18 @@ +{ + "app": { + "bundleName": "com.example.testquickfix", + "versionCode": 1000000, + "versionName": "1.0.0.1", + "patchVersionCode": 1000000, + "patchVersionName": "1.0.0.1" + }, + "module": { + "name": "entry2", + "type": "patch", + "deviceTypes": [ + "default2", + "tablet2" + ], + "originalModuleHash": "c97441c96c84b2ffcb7c85570fb60a0be114ca1f438f8af51b33004081ddb782" + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample2/resources/base/media/aa_icon.png b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample2/resources/base/media/aa_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample2/resources/base/media/aa_icon.png differ diff --git a/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample2/resources/base/media/app_icon.png b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample2/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample2/resources/base/media/app_icon.png differ diff --git a/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample2/resources/base/media/icon.png b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample2/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample2/resources/base/media/icon.png differ diff --git a/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample2/resources/base/profile/main_pages.json b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample2/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..194c81ade2d953008c5e80fa42a67ed7c354f356 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_file/hqfFileExample2/resources/base/profile/main_pages.json @@ -0,0 +1 @@ +{"src":["pages/index/index","pages/second/second"]} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_test.cpp b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6a3555069fcf768c956af50bd38787b3832b0250 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hqf_packager_test/hqf_packager_test.cpp @@ -0,0 +1,185 @@ +/* + * 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. + */ + +#include + +#include +#include "constants.h" +#define private public +#define protected public +#include "hqf_packager.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +#define FILE_PATH "/data/utils_Test" +#define TEMP_PATH "/data" +#define HQF_ETS_PATH_ONE "/data/test/resource/packingtool/test_file/hqf_packager_file/hqfFileExample1/ets" +#define HQF_JSON_PATH_ONE "/data/test/resource/packingtool/test_file/hqf_packager_file/hqfFileExample1/patch.json" +#define HQF_RESOURCES_PATH_ONE "/data/test/resource/packingtool/test_file/hqf_packager_file/hqfFileExample1/resources" +#define OUT_PATH "/data/test/testPack/testHqfPack.hqf" +class HqfPackagetTest : public testing::Test { +public: + HqfPackagetTest() {} + virtual ~HqfPackagetTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void HqfPackagetTest::SetUpTestCase() {} + +void HqfPackagetTest::TearDownTestCase() {} + +void HqfPackagetTest::SetUp() {} + +void HqfPackagetTest::TearDown() {} + +/* + * @tc.name: HqfPackage_0100 + * @tc.desc: HqfPackage + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HqfPackagetTest, HqfPackage_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_JSON_PATH, HQF_JSON_PATH_ONE}, + {OHOS::AppPackingTool::Constants::PARAM_ETS_PATH, HQF_ETS_PATH_ONE}, + {OHOS::AppPackingTool::Constants::PARAM_RESOURCES_PATH, HQF_RESOURCES_PATH_ONE}, + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "true"}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH} + }; + + OHOS::AppPackingTool::HqfPackager hqfPackager(parameterMap, resultReceiver); + EXPECT_EQ(hqfPackager.PreProcess(), 0); + EXPECT_EQ(hqfPackager.Process(), 0); + std::string cmd = {"rm -f "}; + cmd +=OUT_PATH; + system(cmd.c_str()); +} + +/* + * @tc.name: PreProcess_0100 + * @tc.desc: PreProcess_0100. + * @tc.type: FUNC + * @tc.require: out file not end with .hqf. + */ +HWTEST_F(HqfPackagetTest, PreProcess_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_JSON_PATH, HQF_JSON_PATH_ONE}, + {OHOS::AppPackingTool::Constants::PARAM_ETS_PATH, HQF_ETS_PATH_ONE}, + {OHOS::AppPackingTool::Constants::PARAM_RESOURCES_PATH, HQF_RESOURCES_PATH_ONE}, + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "true"}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, "/data/test/testPack/testHqfPack/testHqfPack.hqfx"} + }; + + OHOS::AppPackingTool::HqfPackager hqfPackager(parameterMap, resultReceiver); + EXPECT_EQ(hqfPackager.PreProcess(), 1); +} + +/* + * @tc.name: PreProcess_0200 + * @tc.desc: param json path is invalid. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HqfPackagetTest, PreProcess_0200, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_JSON_PATH, + "/data/test/resource/packingtool/test_file/hqf_packager_file/hqfFileExample1/patcherr.json"}, + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "false"}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH} + }; + + OHOS::AppPackingTool::HqfPackager hqfPackager(parameterMap, resultReceiver); + EXPECT_EQ(hqfPackager.PreProcess(), 1); +} + +/* + * @tc.name: PreProcess_0400 + * @tc.desc: libs path is invalid. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HqfPackagetTest, PreProcess_0300, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_JSON_PATH, HQF_JSON_PATH_ONE}, + {OHOS::AppPackingTool::Constants::PARAM_LIB_PATH, + "/data/test/resource/packingtool/test_file/hqf_packager_file/hqfFileExample1/errlibs"}, + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "false"}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH} + }; + + OHOS::AppPackingTool::HqfPackager hqfPackager(parameterMap, resultReceiver); + EXPECT_EQ(hqfPackager.PreProcess(), 1); +} +/* + * @tc.name: PreProcess_0500 + * @tc.desc: ets path is invalid. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HqfPackagetTest, PreProcess_0400, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_JSON_PATH, HQF_JSON_PATH_ONE}, + {OHOS::AppPackingTool::Constants::PARAM_ETS_PATH, + "/data/test/resource/packingtool/test_file/hqf_packager_file/hqfFileExample1/errets"}, + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "false"}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH} + }; + + OHOS::AppPackingTool::HqfPackager hqfPackager(parameterMap, resultReceiver); + EXPECT_EQ(hqfPackager.PreProcess(), 1); +} +/* + * @tc.name: PreProcess_0600 + * @tc.desc: resources path is invalid. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HqfPackagetTest, PreProcess_0500, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_JSON_PATH, HQF_JSON_PATH_ONE}, + {OHOS::AppPackingTool::Constants::PARAM_RESOURCES_PATH, + "/data/test/resource/packingtool/test_file/hqf_packager_file/hqfFileExample1/errresources"}, + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "false"}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH} + }; + + OHOS::AppPackingTool::HqfPackager hqfPackager(parameterMap, resultReceiver); + EXPECT_EQ(hqfPackager.PreProcess(), 1); +} +} // namespace OHOS \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/hsp_packager_test/BUILD.gn b/packing_tool/frameworks/test/unittest/hsp_packager_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a1bf3f97c54c73400f3b9f6fc6d688cf5ac36dcc --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hsp_packager_test/BUILD.gn @@ -0,0 +1,67 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("hsp_packager_test_config") { + include_dirs = [ + "../../../include", + "../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} +module_output_path = "developtools/packing_tool" + +ohos_unittest("hsp_packager_test") { + module_out_path = module_output_path + public_configs = [ ":hsp_packager_test_config" ] + sources = [ + "../../../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/pt_json.cpp", + "../../../src/log.cpp", + "../../../src/packager.cpp", + "../../../src/utils.cpp", + "../../../src/zip_wrapper.cpp", + "hsp_packager_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 = [ ":hsp_packager_test" ] +} + +ohos_copy("copy_test_file") { + subsystem_name = "developtools" + part_name = "packing_tool" + sources = [ "./hsp_packager_file" ] + outputs = [ "$root_out_dir/tests/unittest/developtools/packing_tool/test_file/hsp_packager_file/" ] +} diff --git a/packing_tool/frameworks/test/unittest/hsp_packager_test/hsp_packager_file/module.json b/packing_tool/frameworks/test/unittest/hsp_packager_test/hsp_packager_file/module.json new file mode 100644 index 0000000000000000000000000000000000000000..453852dc74a4096a7ba7ceffbc5e1be821c567e0 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hsp_packager_test/hsp_packager_file/module.json @@ -0,0 +1,27 @@ +{ + "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", + "iconId": 33554433, + "labelId": 33554432 + }, + "module": { + "name": "library", + "type": "shared", + "description": "$string:shared_desc", + "deviceTypes": ["default", "tablet"], + "deliveryWithInstall": true, + "pages": "$profile:main_pages", + "virtualMachine": "ark12.0.1.0", + "compileMode": "esmodule", + "dependencies": [], + "descriptionId": 33554434 + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/hsp_packager_test/hsp_packager_file/pack.json b/packing_tool/frameworks/test/unittest/hsp_packager_test/hsp_packager_file/pack.json new file mode 100644 index 0000000000000000000000000000000000000000..e8a818ea4d6a79883b160dcd0153117443525751 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hsp_packager_test/hsp_packager_file/pack.json @@ -0,0 +1 @@ +{"summary":{"app":{"bundleName":"com.example.packingtooldemo","version":{"code":1000000,"name":"1.0.0"}},"modules":[{"deviceType":["default","tablet"],"distro":{"moduleType":"shared","deliveryWithInstall":true,"moduleName":"library"},"apiVersion":{"compatible":12,"releaseType":"Canary2","target":12}}]},"packages":[{"deviceType":["default","tablet"],"moduleType":"shared","deliveryWithInstall":true,"name":"library-default"}]} diff --git a/packing_tool/frameworks/test/unittest/hsp_packager_test/hsp_packager_file/resources/base/profile/main_pages.json b/packing_tool/frameworks/test/unittest/hsp_packager_test/hsp_packager_file/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hsp_packager_test/hsp_packager_file/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/packing_tool/frameworks/test/unittest/hsp_packager_test/hsp_packager_test.cpp b/packing_tool/frameworks/test/unittest/hsp_packager_test/hsp_packager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..60c0828f1726d35b46de48764196266d70382089 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/hsp_packager_test/hsp_packager_test.cpp @@ -0,0 +1,94 @@ +/* + * 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. + */ + +#include +#include + +#define private public +#define protected public +#include "hsp_packager.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +#define OUT_PATH "/data/test/library-default-unsigned.hsp" +#define INDEX_PATH "/data/test/resource/packingtool/test_file/resources.index" +#define PACK_INFO_PATH "/data/test/resource/packingtool/test_file/pack.info" +#define ETS_PATH "/data/test/resource/packingtool/test_file/ets" +#define RESOURCES_PATH "/data/test/resource/packingtool/test_file/resources" +#define JSON_PATH "/data/test/resource/packingtool/test_file/module.json" + +class HspPackagerTest : public testing::Test { +public: + HspPackagerTest() {} + virtual ~HspPackagerTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void HspPackagerTest::SetUpTestCase() {} + +void HspPackagerTest::TearDownTestCase() {} + +void HspPackagerTest::SetUp() {} + +void HspPackagerTest::TearDown() {} + +/* + * @tc.name: hspPackager_0100 + * @tc.desc: hspPackager. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HspPackagerTest, hspPackager_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "true"}, + {OHOS::AppPackingTool::Constants::PARAM_JSON_PATH, JSON_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_ETS_PATH, ETS_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_RESOURCES_PATH, RESOURCES_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_INDEX_PATH, INDEX_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_PACK_INFO_PATH, PACK_INFO_PATH}, + }; + + OHOS::AppPackingTool::HspPackager hspPackager(parameterMap, resultReceiver); + system("touch /data/test/resource/packingtool/test_file/resources.index"); + system("mkdir /data/test/resource/packingtool/test_file/ets"); + system("mv /data/test/resource/packingtool/test_file/pack.json " + "/data/test/resource/packingtool/test_file/pack.info"); + EXPECT_EQ(hspPackager.InitAllowedParam(), 0); + EXPECT_EQ(hspPackager.PreProcess(), 0); + EXPECT_EQ(hspPackager.Process(), 0); + EXPECT_EQ(hspPackager.PostProcess(), 0); + system("rm -rf /data/test/resource/packingtool/test_file/ets"); + system("rm -f /data/test/resource/packingtool/test_file/resources.index"); + + std::string cmd = {"rm -f "}; + cmd +=OUT_PATH; + system(cmd.c_str()); +} +} // namespace OHOS \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/json/distro_filter_test/BUILD.gn b/packing_tool/frameworks/test/unittest/json/distro_filter_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a78d58f6a94915ee102f6e3a6ba0becd75efd674 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/distro_filter_test/BUILD.gn @@ -0,0 +1,51 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("distro_filter_test_config") { + include_dirs = [ + "../../../../include", + "../../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("distro_filter_test") { + module_out_path = module_output_path + public_configs = [ ":distro_filter_test_config" ] + sources = [ + "../../../../src/json/distro_filter.cpp", + "../../../../src/json/pt_json.cpp", + "../../../../src/log.cpp", + "../../../../src/utils.cpp", + "distro_filter_test.cpp", + ] + external_deps = [ + "bounds_checking_function:libsec_static", + "cJSON:cjson_static", + "hilog:libhilog", + "openssl:libcrypto_shared", + "zlib:libz", + ] +} + +group("unittest") { + testonly = true + deps = [ ":distro_filter_test" ] +} diff --git a/packing_tool/frameworks/test/unittest/json/distro_filter_test/distro_filter_test.cpp b/packing_tool/frameworks/test/unittest/json/distro_filter_test/distro_filter_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dde2617745754e4b08af921c540ebe29b0b8c90c --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/distro_filter_test/distro_filter_test.cpp @@ -0,0 +1,165 @@ +/* + * 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. + */ + +#include + +#include +#define private public +#define protected public +#include "distro_filter.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +std::string policyValueJsonString = "{" + "\"policy\": \"\"," + "\"value\": [" + "\"xxx\"" + "]" +"}"; + +std::string policyValueString = "{" + "\\\"policy\\\": \\\"\\\"," + "\\\"value\\\": [" + "\\\"xxx\\\"" + "]" +"}"; + +std::string distroFilterJsonString = "{" + "\"apiVersion\": \"" + policyValueString + "\"," + "\"screenShape\": \"" + policyValueString + "\"," + "\"screenDensity\": \"" + policyValueString + "\"," + "\"screenWindow\": \"" + policyValueString + "\"," + "\"countryCode\": \"" + policyValueString + "\"" +"}"; + +std::string policyValueJsonString2 = "{" + "\"policy\": \"xxx\"," + "\"value\": [" + "\"xxx\"" + "]" +"}"; + +std::string policyValueString2 = "{" + "\\\"policy\\\": \\\"xxx\\\"," + "\\\"value\\\": [" + "\\\"xxx\\\"" + "]" +"}"; + +std::string distroFilterJsonString2 = "{" + "\"apiVersion\": \"" + policyValueString2 + "\"," + "\"screenShape\": \"" + policyValueString2 + "\"," + "\"screenDensity\": \"" + policyValueString2 + "\"," + "\"screenWindow\": \"" + policyValueString2 + "\"," + "\"countryCode\": \"" + policyValueString2 + "\"" +"}"; + +class DistroFilterTest : public testing::Test { +public: + DistroFilterTest() {} + virtual ~DistroFilterTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void DistroFilterTest::SetUpTestCase() {} + +void DistroFilterTest::TearDownTestCase() {} + +void DistroFilterTest::SetUp() {} + +void DistroFilterTest::TearDown() {} + +/* + * @tc.name: PolicyValue_ParseFromString_0100 + * @tc.desc: PolicyValue Function Test. + * ParseFromString/IsEmpty + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistroFilterTest, PolicyValue_ParseFromString_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PolicyValue policyValue; + EXPECT_TRUE(policyValue.ParseFromString(policyValueJsonString)); + EXPECT_TRUE(policyValue.IsEmpty()); +} + +/* + * @tc.name: PolicyValue_ParseFromString_0200 + * @tc.desc: PolicyValue Function Test. + * ParseFromString/IsEmpty + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistroFilterTest, PolicyValue_ParseFromString_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PolicyValue policyValue; + EXPECT_TRUE(policyValue.ParseFromString(policyValueJsonString2)); + EXPECT_FALSE(policyValue.IsEmpty()); +} + +/* + * @tc.name: DistroFilter_ParseFromString_0100 + * @tc.desc: DistroFilter Function Test. + * ParseFromString/ParseApiVersion/ParseScreenShape/ParseScreenDensity/ParseScreenWindow/ParseCountryCode + * /IsEmpty/Dump + * PolicyValue Function Test. + * ParseFromString/IsEmpty + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistroFilterTest, DistroFilter_ParseFromString_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::DistroFilter distroFilter; + EXPECT_TRUE(distroFilter.ParseFromString(distroFilterJsonString)); + EXPECT_TRUE(distroFilter.IsEmpty()); + EXPECT_EQ(distroFilter.Dump(), ""); +} + +/* + * @tc.name: DistroFilter_ParseFromString_0200 + * @tc.desc: DistroFilter Function Test. + * ParseFromString/ParseApiVersion/ParseScreenShape/ParseScreenDensity/ParseScreenWindow/ParseCountryCode + * /IsEmpty/Dump + * PolicyValue Function Test. + * ParseFromString/IsEmpty + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(DistroFilterTest, DistroFilter_ParseFromString_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::DistroFilter distroFilter; + EXPECT_TRUE(distroFilter.ParseFromString(distroFilterJsonString2)); + EXPECT_FALSE(distroFilter.IsEmpty()); + EXPECT_EQ(distroFilter.Dump(), + "distroFilter: apiVersion: policy is xxx, " + "value is xxx screenShape: policy is xxx, " + "value is xxx screenDensity: policy is xxx, " + "value is xxx screenWindow: policy is xxx, " + "value is xxx countryCode: policy is xxx, " + "value is xxx"); +} +} diff --git a/packing_tool/frameworks/test/unittest/json/hap_verify_utils_test/BUILD.gn b/packing_tool/frameworks/test/unittest/json/hap_verify_utils_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..00e4c20cc6fa3ffb47ef25d892db1e68bed3d311 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/hap_verify_utils_test/BUILD.gn @@ -0,0 +1,53 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("hap_verify_utils_test_config") { + include_dirs = [ + "../../../../include", + "../../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("hap_verify_utils_test") { + module_out_path = module_output_path + public_configs = [ ":hap_verify_utils_test_config" ] + sources = [ + "../../../../src/json/distro_filter.cpp", + "../../../../src/json/hap_verify_info.cpp", + "../../../../src/json/hap_verify_utils.cpp", + "../../../../src/json/pt_json.cpp", + "../../../../src/log.cpp", + "../../../../src/utils.cpp", + "hap_verify_utils_test.cpp", + ] + external_deps = [ + "bounds_checking_function:libsec_static", + "cJSON:cjson_static", + "hilog:libhilog", + "openssl:libcrypto_shared", + "zlib:libz", + ] +} + +group("unittest") { + testonly = true + deps = [ ":hap_verify_utils_test" ] +} diff --git a/packing_tool/frameworks/test/unittest/json/hap_verify_utils_test/hap_verify_utils_test.cpp b/packing_tool/frameworks/test/unittest/json/hap_verify_utils_test/hap_verify_utils_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..aa6db906783d45aae3ae74047a3bcf594836a26f --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/hap_verify_utils_test/hap_verify_utils_test.cpp @@ -0,0 +1,198 @@ +/* + * 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. + */ + +#include + +#include +#define private public +#define protected public +#include "hap_verify_utils.h" +#include "hap_verify_info.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +class HapVerifyUtilsTest : public testing::Test { +public: + HapVerifyUtilsTest() {} + virtual ~HapVerifyUtilsTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void HapVerifyUtilsTest::SetUpTestCase() {} + +void HapVerifyUtilsTest::TearDownTestCase() {} + +void HapVerifyUtilsTest::SetUp() {} + +void HapVerifyUtilsTest::TearDown() {} + +namespace { + OHOS::AppPackingTool::HapVerifyInfo hapVerifyInfo1; + OHOS::AppPackingTool::HapVerifyInfo hapVerifyInfo2; +} + +void InitHapVerifyInfo1() +{ + // hapVerifyInfo1 + hapVerifyInfo1.SetBundleName("test"); + hapVerifyInfo1.SetBundleType("hap"); + hapVerifyInfo1.SetVendor("vendor"); + + OHOS::AppPackingTool::Version version1; + version1.versionCode = 1; + version1.versionName = "1.0.0"; + version1.minCompatibleVersionCode = 1; + hapVerifyInfo1.SetVersion(version1); + + OHOS::AppPackingTool::ModuleApiVersion moduleApiVersion1; + moduleApiVersion1.compatibleApiVersion = 1; + moduleApiVersion1.targetApiVersion = 1; + moduleApiVersion1.releaseType = "release"; + hapVerifyInfo1.SetApiVersion(moduleApiVersion1); + + hapVerifyInfo1.SetTargetBundleName("test"); + hapVerifyInfo1.SetTargetPriority(1); + hapVerifyInfo1.SetDebug(false); + hapVerifyInfo1.SetModuleName("test"); + hapVerifyInfo1.SetModuleType("entry"); + + OHOS::AppPackingTool::MultiAppMode multiAppMode1; + multiAppMode1.multiAppModeType = "standard"; + multiAppMode1.maxCount = 1; + hapVerifyInfo1.SetMultiAppMode(multiAppMode1); + + const std::list deviceTypes1 = {"phone", "watch"}; + hapVerifyInfo1.SetDeviceTypes(deviceTypes1); + + OHOS::AppPackingTool::ApiVersion apiVersion1; + apiVersion1.policy = "include"; + + OHOS::AppPackingTool::ScreenShape screenShape1; + screenShape1.policy = "include"; + + OHOS::AppPackingTool::ScreenDensity screenDensity1; + screenDensity1.policy = "include"; + + OHOS::AppPackingTool::ScreenWindow screenWindow1; + screenWindow1.policy = "include"; + + OHOS::AppPackingTool::CountryCode countryCode1; + countryCode1.policy = "include"; + + OHOS::AppPackingTool::DistroFilter distroFilter1; + distroFilter1.apiVersion = apiVersion1; + distroFilter1.screenShape = screenShape1; + distroFilter1.screenDensity = screenDensity1; + distroFilter1.screenWindow = screenWindow1; + distroFilter1.countryCode = countryCode1; + + hapVerifyInfo1.SetDistroFilter(distroFilter1); +} + +void InitHapVerifyInfo2() +{ + // hapVerifyInfo2 + hapVerifyInfo2.SetBundleName("test"); + hapVerifyInfo2.SetBundleType("hap"); + hapVerifyInfo2.SetVendor("vendor"); + + OHOS::AppPackingTool::Version version2; + version2.versionCode = 1; + version2.versionName = "1.0.0"; + version2.minCompatibleVersionCode = 1; + hapVerifyInfo2.SetVersion(version2); + + OHOS::AppPackingTool::ModuleApiVersion moduleApiVersion2; + moduleApiVersion2.compatibleApiVersion = 1; + moduleApiVersion2.targetApiVersion = 1; + moduleApiVersion2.releaseType = "release"; + hapVerifyInfo2.SetApiVersion(moduleApiVersion2); + + hapVerifyInfo2.SetTargetBundleName("test"); + hapVerifyInfo2.SetTargetPriority(1); + hapVerifyInfo2.SetDebug(false); + hapVerifyInfo2.SetModuleName("test2"); + hapVerifyInfo2.SetModuleType("entry"); + + OHOS::AppPackingTool::MultiAppMode multiAppMode2; + multiAppMode2.multiAppModeType = "standard"; + multiAppMode2.maxCount = 1; + hapVerifyInfo2.SetMultiAppMode(multiAppMode2); + + const std::list deviceTypes2 = {"computer", "ipad"}; + hapVerifyInfo2.SetDeviceTypes(deviceTypes2); + + OHOS::AppPackingTool::ApiVersion apiVersion2; + apiVersion2.policy = "exclude"; + apiVersion2.value = {"c", "d"}; + + OHOS::AppPackingTool::ScreenShape screenShape2; + screenShape2.policy = "exclude"; + screenShape2.value = {"c", "d"}; + + OHOS::AppPackingTool::ScreenDensity screenDensity2; + screenDensity2.policy = "exclude"; + screenDensity2.value = {"c", "d"}; + + OHOS::AppPackingTool::ScreenWindow screenWindow2; + screenWindow2.policy = "exclude"; + screenWindow2.value = {"c", "d"}; + + OHOS::AppPackingTool::CountryCode countryCode2; + countryCode2.policy = "exclude"; + countryCode2.value = {"c", "d"}; + + OHOS::AppPackingTool::DistroFilter distroFilter2; + distroFilter2.apiVersion = apiVersion2; + distroFilter2.screenShape = screenShape2; + distroFilter2.screenDensity = screenDensity2; + distroFilter2.screenWindow = screenWindow2; + distroFilter2.countryCode = countryCode2; + + hapVerifyInfo2.SetDistroFilter(distroFilter2); +} + +/* + * @tc.name: CheckHapIsValid_0100 + * @tc.desc: CheckHapIsValid + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(HapVerifyUtilsTest, CheckHapIsValid_0100, Function | MediumTest | Level1) +{ + InitHapVerifyInfo1(); + InitHapVerifyInfo2(); + + // hapVerifyInfos + std::list hapVerifyInfos; + hapVerifyInfos.push_back(hapVerifyInfo1); + hapVerifyInfos.push_back(hapVerifyInfo2); + + OHOS::AppPackingTool::HapVerifyUtils utils; + EXPECT_TRUE(utils.CheckHapIsValid(hapVerifyInfos)); +} +} diff --git a/packing_tool/frameworks/test/unittest/json/json_utils_test/BUILD.gn b/packing_tool/frameworks/test/unittest/json/json_utils_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e97df751061920258410e48634cfd4f08c5510f9 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/json_utils_test/BUILD.gn @@ -0,0 +1,51 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("json_utils_test_config") { + include_dirs = [ + "../../../../include", + "../../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("json_utils_test") { + module_out_path = module_output_path + public_configs = [ ":json_utils_test_config" ] + sources = [ + "../../../../src/json/json_utils.cpp", + "../../../../src/json/pt_json.cpp", + "../../../../src/log.cpp", + "../../../../src/utils.cpp", + "json_utils_test.cpp", + ] + external_deps = [ + "bounds_checking_function:libsec_static", + "cJSON:cjson_static", + "hilog:libhilog", + "openssl:libcrypto_shared", + "zlib:libz", + ] +} + +group("unittest") { + testonly = true + deps = [ ":json_utils_test" ] +} diff --git a/packing_tool/frameworks/test/unittest/json/json_utils_test/json_utils_test.cpp b/packing_tool/frameworks/test/unittest/json/json_utils_test/json_utils_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4ac38d28bbc0a80f5119ddc49399658c2b8ee3f7 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/json_utils_test/json_utils_test.cpp @@ -0,0 +1,207 @@ +/* + * 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. + */ + +#include + +#include +#define private public +#define protected public +#include "json_utils.h" +#include "utils.h" +#include "pt_json.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +#define FILE_PATH "/data/test/resource/packingtool/json_utils_test/" +const std::string MODULE_JSON_NAME = "module.json"; +const std::string CONFIG_JSON_NAME = "config.json"; +const std::string PATCH_JSON_NAME = "patch.json"; +const std::string TEST_JSON_NAME = "test.json"; + +const std::string JSON_STRING = "{" + "\"name\": \"Json.CN\"," + "\"app\": \"apptest\"," + "\"module\": {" + "\"name\": \"nametest\"," + "\"type\": \"typetest\"," + "\"deviceTypes\": [" + "\"aaaaaaaaaaa\"," + "\"bbbbbbbbbbb\"," + "\"ccccccccccc\"" + "]" + "}" +"}"; + +class JsonUtilsTest : public testing::Test { +public: + JsonUtilsTest() {} + virtual ~JsonUtilsTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); + + bool CheckFilePath(const std::string& filePath); + + void CreateFilePath(const std::string& filePath); + + void CreateFile(const std::string& filePath); + + void DeleteFilePath(const std::string& filePath); +}; + +void JsonUtilsTest::SetUpTestCase() {} + +void JsonUtilsTest::TearDownTestCase() {} + +void JsonUtilsTest::SetUp() +{ + CreateFilePath(FILE_PATH); + + std::string moduleJsonPath = std::string(FILE_PATH) + MODULE_JSON_NAME; + CreateFile(moduleJsonPath); + std::string configJsonPath = std::string(FILE_PATH) + CONFIG_JSON_NAME; + CreateFile(configJsonPath); + std::string patchJsonPath = std::string(FILE_PATH) + PATCH_JSON_NAME; + CreateFile(patchJsonPath); +} + +void JsonUtilsTest::TearDown() {} + + +bool JsonUtilsTest::CheckFilePath(const std::string& filePath) +{ + std::string prefix = "/data/test/"; + if (filePath.empty()) { + return false; + } + if (filePath.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), filePath.begin())) { + return true; + } + return false; +} + +void JsonUtilsTest::CreateFilePath(const std::string& filePath) +{ + if (!CheckFilePath(filePath)) { + return; + } + std::string cmdStr = std::string("mkdir -p ") + filePath; + system(cmdStr.c_str()); +} + +void JsonUtilsTest::CreateFile(const std::string& filePath) +{ + if (!CheckFilePath(filePath)) { + return; + } + std::string cmdStr = std::string("touch ") + filePath; + system(cmdStr.c_str()); + FILE *fp = fopen(filePath.c_str(), "w"); + if (fp != nullptr) { + fwrite(JSON_STRING.c_str(), JSON_STRING.size(), 1, fp); + fclose(fp); + fp = nullptr; + } +} + +void JsonUtilsTest::DeleteFilePath(const std::string& filePath) +{ + if (!CheckFilePath(filePath)) { + return; + } + std::string cmdStr = std::string("rm -rf ") + filePath; + system(cmdStr.c_str()); +} + +/* + * @tc.name: IsModuleJson_0100 + * @tc.desc: IsModuleJson/CheckFileName + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(JsonUtilsTest, IsModuleJson_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::JsonUtils jsonUtils; + std::string moduleJsonPath = std::string(FILE_PATH) + MODULE_JSON_NAME; + EXPECT_TRUE(jsonUtils.IsModuleJson(moduleJsonPath)); +} + +/* + * @tc.name: IsConfigJson_0100 + * @tc.desc: IsConfigJson/CheckFileName + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(JsonUtilsTest, IsConfigJson_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::JsonUtils jsonUtils; + std::string configJsonPath = std::string(FILE_PATH) + CONFIG_JSON_NAME; + EXPECT_TRUE(jsonUtils.IsConfigJson(configJsonPath)); +} + +/* + * @tc.name: IsPatchJson_0100 + * @tc.desc: IsPatchJson/CheckFileName + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(JsonUtilsTest, IsPatchJson_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::JsonUtils jsonUtils; + std::string patchJsonPath = std::string(FILE_PATH) + PATCH_JSON_NAME; + EXPECT_TRUE(jsonUtils.IsPatchJson(patchJsonPath)); +} + +/* + * @tc.name: JsonFromFile_0100 + * @tc.desc: JsonFromFile. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(JsonUtilsTest, JsonFromFile_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::JsonUtils jsonUtils; + std::string testJsonPath = std::string(FILE_PATH) + TEST_JSON_NAME; + CreateFile(testJsonPath); + EXPECT_TRUE(OHOS::AppPackingTool::Utils::IsFileExists(testJsonPath)); + EXPECT_NE(jsonUtils.JsonFromFile(testJsonPath), nullptr); + DeleteFilePath(testJsonPath); +} + +/* + * @tc.name: JsonToFile_0100 + * @tc.desc: JsonToFile/StrToFile + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(JsonUtilsTest, JsonToFile_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::JsonUtils jsonUtils; + std::string testJsonPath = std::string(FILE_PATH) + TEST_JSON_NAME; + CreateFile(testJsonPath); + EXPECT_TRUE(jsonUtils.JsonToFile(OHOS::AppPackingTool::PtJson::Parse(JSON_STRING), testJsonPath)); + DeleteFilePath(testJsonPath); +} +}ls - diff --git a/packing_tool/frameworks/test/unittest/json/module_json_test/BUILD.gn b/packing_tool/frameworks/test/unittest/json/module_json_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..389bcae539e9619d64bd17d27d35cd888788e4e4 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/module_json_test/BUILD.gn @@ -0,0 +1,55 @@ +# 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. + +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_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_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_test" ] +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..a83cdcd1be0ccfe0ffc9dc96da7dd535f95a85e3 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/module_json_test/module_json_test.cpp @@ -0,0 +1,1638 @@ +/* + * 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. + */ + +#include +#include +#include +#define private public +#define protected public +#include "module_json.h" +#include "pt_json.h" +#include "log.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; +using namespace std; +using namespace OHOS::AppPackingTool; + +namespace OHOS { + +string jsonString = "{" + "\"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\"" + "}" + "]," + "\"extensionAbilities\": [" + "{" + "\"name\": \"test_extension_abilities\"" + "}" + "]" + "}," + "\"deviceConfig\": {" + "\"default\": true" + "}" +"}"; + +string jsonStr = "{" + "\"app\": {" + "\"apiVersion\": {" + + "}" + "}," + "\"module\": {" + "\"requestPermissions\": true," + "\"proxyData\": [" + "{" + "\"uri\": \"test_uri1\"" + "}," + "{" + "\"uri\": \"test_uri2\"" + "}" + "]," + "\"generateBuildHash\": true" + "}" +"}"; + +class ModuleJsonTest : public testing::Test { +public: + ModuleJsonTest() {} + virtual ~ModuleJsonTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void ModuleJsonTest::SetUpTestCase() {} + +void ModuleJsonTest::TearDownTestCase() {} + +void ModuleJsonTest::SetUp() {} + +void ModuleJsonTest::TearDown() {} + + /* + * @tc.name: ParseFromString_0100 + * @tc.desc: test parse from string + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, ParseFromString_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); +} + + /* + * @tc.name: ParseFromFile_0100 + * @tc.desc: test parse from file + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, ParseFromFile_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + std::string test("test_module.json"); + FILE *fp = fopen(test.c_str(), "w"); + EXPECT_TRUE(fp != nullptr); + if (fp != nullptr) + { + fwrite(jsonString.c_str(), jsonString.size(), 1, fp); + fclose(fp); + EXPECT_TRUE(moduleJson.ParseFromFile(test)); + system("rm -f test_module.json"); + } +} + + /* + * @tc.name: ToString + * @tc.desc: test parse from string + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, ToString_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string str =moduleJson.ToString(); + EXPECT_TRUE(!str.empty()); +} + + /* + * @tc.name: Release + * @tc.desc: test release + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, Release_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + + moduleJson.Release(); + EXPECT_TRUE(moduleJson.root_ == nullptr); +} + + /* + * @tc.name: IsValid + * @tc.desc: test is valid + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, IsValid_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + + EXPECT_TRUE(moduleJson.IsValid()); +} + + /* + * @tc.name: GetApiVersionObject + * @tc.desc: test get api version object + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetApiVersionObject_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + std::unique_ptr apiVersion; + EXPECT_TRUE(moduleJson.GetApiVersionObject(apiVersion)); + EXPECT_NE(apiVersion, nullptr); +} + + /* + * @tc.name: GetVersionObject + * @tc.desc: test get version object + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetVersionObject_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + std::unique_ptr versionObj; + EXPECT_TRUE(moduleJson.GetVersionObject(versionObj)); + EXPECT_NE(versionObj, nullptr); +} + + /* + * @tc.name: GetFaHapVerifyInfo + * @tc.desc: test get fa hap verify info + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetFaHapVerifyInfo_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + HapVerifyInfo hapVerifyInfo; + EXPECT_TRUE(moduleJson.GetFaHapVerifyInfo(hapVerifyInfo)); +} + + /* + * @tc.name: GetFaBundleType + * @tc.desc: test get fa bundle type + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetFaBundleType_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string bundleType = ""; + EXPECT_TRUE(moduleJson.GetFaBundleType(bundleType)); + EXPECT_STREQ(bundleType.c_str(), "app"); +} + + /* + * @tc.name: GetDistroObject + * @tc.desc: test get distro object + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetDistroObject_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + unique_ptr distroObj; + EXPECT_TRUE(moduleJson.GetDistroObject(distroObj)); + EXPECT_NE(distroObj, nullptr); +} + + /* + * @tc.name: GetFaInstallationFree + * @tc.desc: test get fa installation free + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetFaInstallationFree_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + bool installationFree = true; + EXPECT_TRUE(moduleJson.GetFaInstallationFree(installationFree)); + EXPECT_EQ(installationFree, false); +} + + /* + * @tc.name: GetStageVersion + * @tc.desc: test get normalize version + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetStageVersion_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + Version version; + EXPECT_TRUE(moduleJson.GetStageVersion(version)); + EXPECT_EQ(version.versionCode, 1000000); + EXPECT_STREQ(version.versionName.c_str(), "test_version_name"); + EXPECT_EQ(version.minCompatibleVersionCode, 99); +} + + /* + * @tc.name: SetStageVersionCode + * @tc.desc: test set stage version code + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetStageVersionCode_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + int versionCode = 99; + EXPECT_TRUE(moduleJson.SetStageVersionCode(versionCode)); + Version version; + EXPECT_TRUE(moduleJson.GetStageVersion(version)); + EXPECT_EQ(version.versionCode, 99); +} + + /* + * @tc.name: SetStageVersionName + * @tc.desc: test set stage version name + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetStageVersionName_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string versionName = "2.2.2"; + EXPECT_TRUE(moduleJson.SetStageVersionName(versionName)); + Version version; + EXPECT_TRUE(moduleJson.GetStageVersion(version)); + EXPECT_STREQ(version.versionName.c_str(), "2.2.2"); +} + + /* + * @tc.name: GetStageModuleApiVersion + * @tc.desc: test get stage module api version + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetStageModuleApiVersion_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + ModuleApiVersion moduleApiVersion; + EXPECT_TRUE(moduleJson.GetStageModuleApiVersion(moduleApiVersion)); + EXPECT_EQ(moduleApiVersion.compatibleApiVersion, 10); + EXPECT_EQ(moduleApiVersion.targetApiVersion, 10); + EXPECT_STREQ(moduleApiVersion.releaseType.c_str(), "Canary"); +} + + /* + * @tc.name: GetStageModuleName + * @tc.desc: test get stage module name + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetStageModuleName_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string stageModuleName = ""; + EXPECT_TRUE(moduleJson.GetStageModuleName(stageModuleName)); + EXPECT_STREQ(stageModuleName.c_str(), "entry"); +} + + /* + * @tc.name: GetStageEntry + * @tc.desc: test get stage entry + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetStageEntry_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + list deviceTypes; + EXPECT_TRUE(moduleJson.GetStageEntry(deviceTypes)); + EXPECT_NE(deviceTypes.size(), 0); +} + + /* + * @tc.name: GetStageDeviceTypes + * @tc.desc: test get stage device types + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetStageDeviceTypes_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + list deviceTypes; + EXPECT_TRUE(moduleJson.GetStageDeviceTypes(deviceTypes)); + EXPECT_NE(deviceTypes.size(), 0); +} + + /* + * @tc.name: GetStageHapVerifyInfo + * @tc.desc: test get stage hap verify info + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetStageHapVerifyInfo_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + HapVerifyInfo hapVerifyInfo; + EXPECT_TRUE(moduleJson.GetStageHapVerifyInfo(hapVerifyInfo)); +} + + /*lq + * @tc.name: GetStageDistroFilter + * @tc.desc: test get stage distro filter + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetStageDistroFilter_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + DistroFilter distroFilter; + EXPECT_TRUE(moduleJson.GetStageDistroFilter(distroFilter)); +} + + /* + * @tc.name: GetStageInstallationFree + * @tc.desc: test get stage installation free + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetStageInstallationFree_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + bool installationFree = false; + EXPECT_TRUE(moduleJson.GetStageInstallationFree(installationFree)); + EXPECT_EQ(installationFree, true); +} + + /* + * @tc.name: GetStageCompileSdkType + * @tc.desc: test get stage compilation + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetStageCompileSdkType_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string compileSdkType = ""; + EXPECT_TRUE(moduleJson.GetStageCompileSdkType(compileSdkType)); + EXPECT_STREQ(compileSdkType.c_str(), "OpenHarmony"); +} + + /* + * @tc.name: GetStageCompileSdkVersion + * @tc.desc: test get stage compile sdk version + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetStageCompileSdkVersion_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string compileSdkVersion = ""; + EXPECT_TRUE(moduleJson.GetStageCompileSdkVersion(compileSdkVersion)); + EXPECT_STREQ(compileSdkVersion.c_str(), "test_compileSdkVersion"); +} + + /* + * @tc.name: GetStageModuleType + * @tc.desc: test get stage module type + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetStageModuleType_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string moduleType = ""; + EXPECT_TRUE(moduleJson.GetStageModuleType(moduleType)); + EXPECT_STREQ(moduleType.c_str(), "entry"); +} + + /* + * @tc.name: GetStageDebug + * @tc.desc: test get stage debug + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetStageDebug_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + bool debug = false; + EXPECT_TRUE(moduleJson.GetStageDebug(debug)); + EXPECT_EQ(debug, true); +} + + /* + * @tc.name: GetStageAsanEnabled + * @tc.desc: test get stage asan enabled + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetStageAsanEnabled_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + bool asanEnabled = false; + EXPECT_TRUE(moduleJson.GetStageAsanEnabled(asanEnabled)); + EXPECT_EQ(asanEnabled, true); +} + + /* + * @tc.name: GetStageAsanEnabled + * @tc.desc: test get stage asan enabled + * @tc.type: FUNC + * @tc.require: + */ + +HWTEST_F(ModuleJsonTest, GetStageAsanEnabled_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonStr)); + bool asanEnabled = true; + EXPECT_TRUE(moduleJson.GetStageAsanEnabled(asanEnabled)); + EXPECT_EQ(asanEnabled, false); +} + + /* + * @tc.name: GetStageTsanEnabled + * @tc.desc: test get stage tsan enabled + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetStageTsanEnabled_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + bool tsanEnabled = true; + EXPECT_TRUE(moduleJson.GetStageTsanEnabled(tsanEnabled)); + EXPECT_EQ(tsanEnabled, false); +} + + /* + * @tc.name: GetStageTsanEnabled + * @tc.desc: test get stage tsan enabled + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetStageTsanEnabled_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonStr)); + bool tsanEnabled = true; + EXPECT_TRUE(moduleJson.GetStageTsanEnabled(tsanEnabled)); + EXPECT_EQ(tsanEnabled, false); +} + + /* + * @tc.name: GetStageApiReleaseType + * @tc.desc: test get stage api release type + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetStageApiReleaseType_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string apiReleaseType = ""; + EXPECT_TRUE(moduleJson.GetStageApiReleaseType(apiReleaseType)); + EXPECT_STREQ(apiReleaseType.c_str(), "Canary"); +} + + /* + * @tc.name: GetStageApiReleaseType + * @tc.desc: test get stage api release type + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetStageApiReleaseType_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonStr)); + string apiReleaseType = "test"; + EXPECT_TRUE(moduleJson.GetStageApiReleaseType(apiReleaseType)); + EXPECT_STREQ(apiReleaseType.c_str(), ""); +} + + /* + * @tc.name: GetStageCompressNativeLibs + * @tc.desc: test get stage compress native libs + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetStageCompressNativeLibs_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + bool compressNativeLibs = false; + EXPECT_TRUE(moduleJson.GetStageCompressNativeLibs(compressNativeLibs)); + EXPECT_EQ(compressNativeLibs, true); +} + + /* + * @tc.name: GetStageCompressNativeLibs + * @tc.desc: test get stage compress native libs + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetStageCompressNativeLibs_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonStr)); + bool compressNativeLibs = true; + EXPECT_TRUE(moduleJson.GetStageCompressNativeLibs(compressNativeLibs)); + EXPECT_EQ(compressNativeLibs, false); +} + + /* + * @tc.name: GetAbilityContinueTypeMap + * @tc.desc: test get ability continue type map + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetAbilityContinueTypeMap_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + map> abilityContinueTypeMap; + EXPECT_TRUE(moduleJson.GetAbilityContinueTypeMap(abilityContinueTypeMap)); + EXPECT_NE(abilityContinueTypeMap.size(), 0); +} + + /* + * @tc.name: GetExtensionAbilityNames + * @tc.desc: test get extension ability names + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetExtensionAbilityNames_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + list extensionAbilityNames; + EXPECT_TRUE(moduleJson.GetExtensionAbilityNames(extensionAbilityNames)); + EXPECT_NE(extensionAbilityNames.size(), 0); +} + + /* + * @tc.name: IsExistedStageRequestPermissions + * @tc.desc: test is existed stage request permissions + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, IsExistedStageRequestPermissions_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + EXPECT_FALSE(moduleJson.IsExistedStageRequestPermissions()); +} + + /* + * @tc.name: IsExistedStageModuleTargetPriority + * @tc.desc: test is existed stage app target priority + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, IsExistedStageModuleTargetPriority_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + EXPECT_TRUE(moduleJson.IsExistedStageModuleTargetPriority()); +} + + /* + * @tc.name: IsExistedStageAppTargetPriority + * @tc.desc: test is existed stage app target priority + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, IsExistedStageAppTargetPriority_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + EXPECT_TRUE(moduleJson.IsExistedStageAppTargetPriority()); +} + + /* + * @tc.name: GetFaVersion + * @tc.desc: test get fa version + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetFaVersion_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + Version version; + EXPECT_TRUE(moduleJson.GetFaVersion(version)); + EXPECT_EQ(version.versionCode, 666); + EXPECT_STREQ(version.versionName.c_str(), "test_version"); + EXPECT_EQ(version.minCompatibleVersionCode, 555); +} + + /* + * @tc.name: SetFaVersionCode + * @tc.desc: test set fa version code + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetFaVersionCode_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + int versionCode = 9; + EXPECT_TRUE(moduleJson.SetFaVersionCode(versionCode)); + Version version; + EXPECT_TRUE(moduleJson.GetFaVersion(version)); + EXPECT_EQ(version.versionCode, 9); +} + + /* + * @tc.name: SetFaVersionName + * @tc.desc: test set fa version name + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetFaVersionName_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string versionName = "1.1.1"; + EXPECT_TRUE(moduleJson.SetFaVersionName(versionName)); + Version version; + EXPECT_TRUE(moduleJson.GetFaVersion(version)); + EXPECT_STREQ(version.versionName.c_str(), "1.1.1"); +} + + /* + * @tc.name: GetFaModuleApiVersion + * @tc.desc: test get fa module api version + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetFaModuleApiVersion_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + ModuleApiVersion moduleApiVersion; + EXPECT_TRUE(moduleJson.GetFaModuleApiVersion(moduleApiVersion)); + EXPECT_EQ(moduleApiVersion.compatibleApiVersion, 7); + EXPECT_EQ(moduleApiVersion.targetApiVersion, 10); + EXPECT_STREQ(moduleApiVersion.releaseType.c_str(), "test_apiVersion_release"); +} + + /* + * @tc.name: GetFaModuleName + * @tc.desc: test get fa module name + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetFaModuleName_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string faModuleName = ""; + EXPECT_TRUE(moduleJson.GetFaModuleName(faModuleName)); + EXPECT_STREQ(faModuleName.c_str(), "test_module_name"); +} + + /* + * @tc.name: GetFaPackageStr + * @tc.desc: test get fa package string + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetFaPackageStr_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string packageStr = ""; + EXPECT_TRUE(moduleJson.GetFaPackageStr(packageStr)); + EXPECT_STREQ(packageStr.c_str(), "test_package"); +} + + /* + * @tc.name: GetFaEntry + * @tc.desc: test get fa entry + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetFaEntry_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + list deviceTypes; + EXPECT_TRUE(moduleJson.GetFaEntry(deviceTypes)); + EXPECT_NE(deviceTypes.size(), 0); +} + + /* + * @tc.name: GetFaDeviceTypes + * @tc.desc: test fa deviceTypes + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetFaDeviceTypes_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + list deviceTypes; + EXPECT_TRUE(moduleJson.GetFaDeviceTypes(deviceTypes)); + EXPECT_NE(deviceTypes.size(), 0); +} + + /*lq + * @tc.name: GetFaDistroFilter + * @tc.desc: test get fa distro filter + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetFaDistroFilter_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + DistroFilter distroFilter; + EXPECT_TRUE(moduleJson.GetFaDistroFilter(distroFilter)); +} + + /* + * @tc.name: GetFaCompileSdkType + * @tc.desc: test get fa compile sdk type + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetFaCompileSdkType_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string compileSdkType = ""; + EXPECT_TRUE(moduleJson.GetFaCompileSdkType(compileSdkType)); + EXPECT_STREQ(compileSdkType.c_str(), "OpenHarmony"); +} + + /* + * @tc.name: GetFaCompileSdkType + * @tc.desc: test get fa compile sdk type + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetFaCompileSdkType_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonStr)); + string compileSdkType = "test"; + EXPECT_TRUE(moduleJson.GetFaCompileSdkType(compileSdkType)); + EXPECT_STREQ(compileSdkType.c_str(), ""); +} + + /* + * @tc.name: GetFaCompileSdkVersion + * @tc.desc: test get fa compile sdk version + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetFaCompileSdkVersion_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string compileSdkVersion = ""; + EXPECT_TRUE(moduleJson.GetFaCompileSdkVersion(compileSdkVersion)); + EXPECT_STREQ(compileSdkVersion.c_str(), "test_apiVersion_compileSdkVersion"); +} + + /* + * @tc.name: GetFaCompileSdkVersion + * @tc.desc: test get fa compile sdk version + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetFaCompileSdkVersion_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonStr)); + string compileSdkVersion = "test"; + EXPECT_TRUE(moduleJson.GetFaCompileSdkVersion(compileSdkVersion)); + EXPECT_STREQ(compileSdkVersion.c_str(), ""); +} + + /* + * @tc.name: GetFaModuleType + * @tc.desc: test get fa module type + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetFaModuleType_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string moduleType = ""; + EXPECT_TRUE(moduleJson.GetFaModuleType(moduleType)); + EXPECT_STREQ(moduleType.c_str(), "entry"); +} + + /* + * @tc.name: GetFaDebug + * @tc.desc: test get fa debug + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetFaDebug_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + bool debug = false; + EXPECT_TRUE(moduleJson.GetFaDebug(debug)); + EXPECT_EQ(debug, true); +} + + /* + * @tc.name: GetFaAsanEnabled + * @tc.desc: test get fa asan enabled + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetFaAsanEnabled_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + bool asanEnabled = false; + EXPECT_TRUE(moduleJson.GetFaAsanEnabled(asanEnabled)); + EXPECT_EQ(asanEnabled, true); +} + + /* + * @tc.name: GetFaAsanEnabled + * @tc.desc: test get fa asan enabled + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetFaAsanEnabled_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonStr)); + bool asanEnabled = true; + EXPECT_TRUE(moduleJson.GetFaAsanEnabled(asanEnabled)); + EXPECT_EQ(asanEnabled, false); +} + + /* + * @tc.name: GetFaReleaseType + * @tc.desc: test get fa release type + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetFaReleaseType_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string releaseType = ""; + EXPECT_TRUE(moduleJson.GetFaReleaseType(releaseType)); + EXPECT_STREQ(releaseType.c_str(), "test_apiVersion_release"); +} + + /* + * @tc.name: GetBundleName + * @tc.desc: test get bundle name + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetBundleName_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string bundleName = ""; + EXPECT_TRUE(moduleJson.GetBundleName(bundleName)); + EXPECT_STREQ(bundleName.c_str(), "test_bundle_name"); +} + + /* + * @tc.name: SetBundleName + * @tc.desc: test set bundle name + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetBundleName_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string setBundleName = "com.example.test"; + string getBundleName = ""; + EXPECT_TRUE(moduleJson.SetBundleName(setBundleName)); + moduleJson.GetBundleName(getBundleName); + EXPECT_STREQ(getBundleName.c_str(), setBundleName.c_str()); +} + + /* + * @tc.name: GetModuleName + * @tc.desc: test get module name + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetModuleName_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string moduleName = ""; + EXPECT_TRUE(moduleJson.GetModuleName(moduleName)); + EXPECT_STREQ(moduleName.c_str(), "entry"); +} + + /* + * @tc.name: GetVendor + * @tc.desc: test get vendor + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetVendor_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string vendor = "test"; + EXPECT_TRUE(moduleJson.GetVendor(vendor)); + EXPECT_STREQ(vendor.c_str(), ""); +} + + /* + * @tc.name: GetTargetBundleName + * @tc.desc: test get target bundle name + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetTargetBundleName_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string targetBundleName = ""; + EXPECT_TRUE(moduleJson.GetTargetBundleName(targetBundleName)); + EXPECT_STREQ(targetBundleName.c_str(), "test_app_targetBundleName"); +} + + /* + * @tc.name: GetTargetBundleName + * @tc.desc: test get target bundle name + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetTargetBundleName_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonStr)); + string targetBundleName = "test"; + EXPECT_TRUE(moduleJson.GetTargetBundleName(targetBundleName)); + EXPECT_STREQ(targetBundleName.c_str(), ""); +} + + /* + * @tc.name: GetTargetModuleName + * @tc.desc: test get target module name + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetTargetModuleName_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string targetModuleName = ""; + EXPECT_TRUE(moduleJson.GetTargetModuleName(targetModuleName)); + EXPECT_STREQ(targetModuleName.c_str(), "test_module_targetBundleName"); +} + + /* + * @tc.name: GetTargetModuleName + * @tc.desc: test get target module name + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetTargetModuleName_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonStr)); + string targetModuleName = "test"; + EXPECT_TRUE(moduleJson.GetTargetModuleName(targetModuleName)); + EXPECT_STREQ(targetModuleName.c_str(), ""); +} + + /* + * @tc.name: GetTargetPriority + * @tc.desc: test get target priority + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetTargetPriority_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + int32_t targetPriority = -1; + EXPECT_TRUE(moduleJson.GetTargetPriority(targetPriority)); + EXPECT_EQ(targetPriority, 5); +} + + /* + * @tc.name: GetTargetPriority + * @tc.desc: test get target priority + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetTargetPriority_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonStr)); + int32_t targetPriority = -1; + EXPECT_TRUE(moduleJson.GetTargetPriority(targetPriority)); + EXPECT_EQ(targetPriority, 0); +} + + /* + * @tc.name: GetTargetModulePriority + * @tc.desc: test target module priority + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetTargetModulePriority_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + int32_t targetModulePriority = -1; + EXPECT_TRUE(moduleJson.GetTargetModulePriority(targetModulePriority)); + EXPECT_EQ(targetModulePriority, 6); +} + + /* + * @tc.name: GetTargetModulePriority + * @tc.desc: test target module priority + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetTargetModulePriority_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonStr)); + int32_t targetModulePriority = -1; + EXPECT_TRUE(moduleJson.GetTargetModulePriority(targetModulePriority)); + EXPECT_EQ(targetModulePriority, 0); +} + + /* + * @tc.name: GetAbilityNames + * @tc.desc: test get ability names + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetAbilityNames_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + list abilityNames; + EXPECT_TRUE(moduleJson.GetAbilityNames(abilityNames)); + EXPECT_NE(abilityNames.size(), 0); +} + + /* + * @tc.name: GetDependencyItems + * @tc.desc: test get dependency items + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetDependencyItems_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + list dependencyItems; + string defaultBundleName = "defaultBundleName"; + EXPECT_TRUE(moduleJson.GetDependencyItems(dependencyItems, defaultBundleName)); + EXPECT_NE(dependencyItems.size(), 0); +} + + /* + * @tc.name: GetAtomicServicePreloads + * @tc.desc: test get atomics service preloads + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetAtomicServicePreloads_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + list preloadItems; + EXPECT_TRUE(moduleJson.GetAtomicServicePreloads(preloadItems)); + EXPECT_NE(preloadItems.size(), 0); +} + + /* + * @tc.name: GetProxyDataUris + * @tc.desc: test get proxy data uris + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetProxyDataUris_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + list proxyDataUris; + EXPECT_TRUE(moduleJson.GetProxyDataUris(proxyDataUris)); + EXPECT_NE(proxyDataUris.size(), 0); +} + + /* + * @tc.name: GetProxyDataUris + * @tc.desc: test get proxy data uris + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetProxyDataUris_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonStr)); + list proxyDataUris; + EXPECT_TRUE(moduleJson.GetProxyDataUris(proxyDataUris)); + EXPECT_NE(proxyDataUris.size(), 0); +} + + /* + * @tc.name: GetMultiAppMode + * @tc.desc: test get multi app mode + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetMultiAppMode_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + MultiAppMode multiAppMode; + EXPECT_TRUE(moduleJson.GetMultiAppMode(multiAppMode)); + EXPECT_STREQ(multiAppMode.multiAppModeType.c_str(), "test_multiAppMode"); + EXPECT_EQ(multiAppMode.maxCount, 9); +} + + /* + * @tc.name: IsModuleAtomicServiceValid + * @tc.desc: test is module atomic service valid + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, IsModuleAtomicServiceValid_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + EXPECT_TRUE(moduleJson.IsModuleAtomicServiceValid()); +} + + /* + * @tc.name: CheckEntryInAtomicService + * @tc.desc: test check entry in atomic service + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, CheckEntryInAtomicService_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + EXPECT_TRUE(moduleJson.CheckEntryInAtomicService()); +} + + /* + * @tc.name: CheckAtomicServiceInstallationFree + * @tc.desc: test check atomic service installation free + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, CheckAtomicServiceInstallationFree_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + EXPECT_TRUE(moduleJson.CheckAtomicServiceInstallationFree()); +} + + /* + * @tc.name: GetGenerateBuildHash + * @tc.desc: test get generate build hash + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetGenerateBuildHash_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + bool generateBuildHash = false; + EXPECT_TRUE(moduleJson.GetGenerateBuildHash(generateBuildHash)); + EXPECT_EQ(generateBuildHash, true); +} + + /* + * @tc.name: GetGenerateBuildHash + * @tc.desc: test get generate build hash + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetGenerateBuildHash_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonStr)); + bool generateBuildHash = false; + EXPECT_TRUE(moduleJson.GetGenerateBuildHash(generateBuildHash)); + EXPECT_EQ(generateBuildHash, true); +} + + /* + * @tc.name: RemoveGenerateBuildHash + * @tc.desc: test remove generate build hash + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, RemoveGenerateBuildHash_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + EXPECT_TRUE(moduleJson.RemoveGenerateBuildHash()); +} + + /* + * @tc.name: RemoveGenerateBuildHashFromAppObj + * @tc.desc: test remove generate build hash from app object + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, RemoveGenerateBuildHashFromAppObj_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + EXPECT_TRUE(moduleJson.RemoveGenerateBuildHashFromAppObj()); +} + + /* + * @tc.name: RemoveGenerateBuildHashFromModuleObj + * @tc.desc: test remove generate build hash from module object + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, RemoveGenerateBuildHashFromModuleObj_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + EXPECT_TRUE(moduleJson.RemoveGenerateBuildHashFromModuleObj()); +} + + /* + * @tc.name: GetNormalizeVersion + * @tc.desc: test get normalize version + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetNormalizeVersion_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + NormalizeVersion normalizeVersion; + bool isStage = false; + EXPECT_TRUE(moduleJson.GetNormalizeVersion(normalizeVersion, isStage)); + EXPECT_EQ(normalizeVersion.originVersionCode, 666); + EXPECT_STREQ(normalizeVersion.originVersionName.c_str(), "test_version"); + EXPECT_STREQ(normalizeVersion.moduleName.c_str(), "entry"); +} + + /* + * @tc.name: GetNormalizeVersion + * @tc.desc: test get normalize version + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetNormalizeVersion_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + NormalizeVersion normalizeVersion; + bool isStage = true; + EXPECT_TRUE(moduleJson.GetNormalizeVersion(normalizeVersion, isStage)); + EXPECT_EQ(normalizeVersion.originVersionCode, 1000000); + EXPECT_STREQ(normalizeVersion.originVersionName.c_str(), "test_version_name"); + EXPECT_STREQ(normalizeVersion.moduleName.c_str(), "entry"); +} + + /* + * @tc.name: SetVersionCodeAndName + * @tc.desc: test set version code and name + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetVersionCodeAndName_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + int versionCode = 10; + string versionName = "1.1.1"; + bool isStage = true; + EXPECT_TRUE(moduleJson.SetVersionCodeAndName(versionCode, versionName, isStage)); + Version version; + EXPECT_TRUE(moduleJson.GetStageVersion(version)); + EXPECT_EQ(version.versionCode, 10); + EXPECT_STREQ(version.versionName.c_str(), "1.1.1"); +} + + /* + * @tc.name: SetVersionCodeAndName + * @tc.desc: test set version code and name + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetVersionCodeAndName_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + int versionCode = 8; + string versionName = "2.2.2"; + bool isStage = false; + EXPECT_TRUE(moduleJson.SetVersionCodeAndName(versionCode, versionName, isStage)); + Version version; + EXPECT_TRUE(moduleJson.GetFaVersion(version)); + EXPECT_EQ(version.versionCode, 8); + EXPECT_STREQ(version.versionName.c_str(), "2.2.2"); +} + + /* + * @tc.name: SetBuildHash + * @tc.desc: test set build hash + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetBuildHash_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string buildHash = "00000000000000000000000000000000"; + EXPECT_TRUE(moduleJson.SetBuildHash(buildHash)); +} + + /* + * @tc.name: GetPatchModuleName + * @tc.desc: test get patch module name + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetPatchModuleName_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string patchModuleName = ""; + EXPECT_TRUE(moduleJson.GetPatchModuleName(patchModuleName)); + EXPECT_STREQ(patchModuleName.c_str(), "entry"); +} + + /* + * @tc.name: GetStageBundleType + * @tc.desc: test get stage bundle type + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetStageBundleType_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + string bundleType = ""; + EXPECT_TRUE(moduleJson.GetStageBundleType(bundleType)); + EXPECT_STREQ(bundleType.c_str(), "atomicService"); +} + + /* + * @tc.name: CheckStageAsanTsanEnabledValid + * @tc.desc: test check stage asan tsan enabled + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, CheckStageAsanTsanEnabledValid_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + EXPECT_TRUE(moduleJson.CheckStageAsanTsanEnabledValid()); +} + + /* + * @tc.name: CheckStageAtomicService + * @tc.desc: test check stage atomic service + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, CheckStageAtomicService_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + EXPECT_TRUE(moduleJson.CheckStageAtomicService()); +} + + /* + * @tc.name: CheckStageOverlayCfg + * @tc.desc: test check stage overlay config + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, CheckStageOverlayCfg_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + EXPECT_TRUE(moduleJson.CheckStageOverlayCfg()); +} + + /* + * @tc.name: GetModuleMetadatas + * @tc.desc: test get module meta datas + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, GetModuleMetadatas_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + list moduleMetadataInfos; + EXPECT_TRUE(moduleJson.GetModuleMetadatas(moduleMetadataInfos)); + EXPECT_NE(moduleMetadataInfos.size(), 0); +} + + /* + * @tc.name: SetStageHapVerifyInfoExtByModuleObj + * @tc.desc: test set stage hap verify info ext by module obj + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonTest, SetStageHapVerifyInfoExtByModuleObj_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ModuleJson moduleJson; + EXPECT_TRUE(moduleJson.ParseFromString(jsonString)); + std::unique_ptr moduleObj; + EXPECT_TRUE(moduleJson.GetModuleObject(moduleObj)); + HapVerifyInfo hapVerifyInfo; + EXPECT_TRUE(moduleJson.SetStageHapVerifyInfoExtByModuleObj(moduleObj, hapVerifyInfo)); +} + +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/json/module_json_utils_test/BUILD.gn b/packing_tool/frameworks/test/unittest/json/module_json_utils_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..3fad8619c2a8f253c7e37695be51908df282835e --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/module_json_utils_test/BUILD.gn @@ -0,0 +1,59 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("module_json_utils_test_config") { + include_dirs = [ + "../../../../include", + "../../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("module_json_utils_test") { + module_out_path = module_output_path + public_configs = [ ":module_json_utils_test_config" ] + sources = [ + "../../../../src/json/distro_filter.cpp", + "../../../../src/json/hap_verify_info.cpp", + "../../../../src/json/hap_verify_utils.cpp", + "../../../../src/json/module_json.cpp", + "../../../../src/json/module_json_fa.cpp", + "../../../../src/json/module_json_stage.cpp", + "../../../../src/json/module_json_utils.cpp", + "../../../../src/json/pt_json.cpp", + "../../../../src/log.cpp", + "../../../../src/utils.cpp", + "../../../../src/zip_utils.cpp", + "../../../../src/zip_wrapper.cpp", + "module_json_utils_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_utils_test" ] +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/json/module_json_utils_test/module_json_utils_test.cpp b/packing_tool/frameworks/test/unittest/json/module_json_utils_test/module_json_utils_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6735583d0a3b8bed90be16e29db766649297845f --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/module_json_utils_test/module_json_utils_test.cpp @@ -0,0 +1,355 @@ +/* + * 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. + */ + +#include + +#include +#define private public +#define protected public +#include "module_json_utils.h" +#include "constants.h" +#include "pt_json.h" +#include "log.h" +#include "zip_wrapper.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::AppPackingTool; +using namespace std; + +namespace OHOS { + +#define HAP_FILE_PATH_FA "/data/test.hap" +#define HAP_FILE_PATH_TEST "/data/demo.hap" +#define MODULE_JSON_FILE "/data/module.json" +#define CONFIG_JSON_FILE "/data/config.json" + +string str = "{" + "\"app\": {" + "\"iconId\":16777217," + "\"debug\":true," + "\"minAPIVersion\":9," + "\"icon\":\"media:app_icon\"," + "\"label\":\"string:app_name\"," + "\"versionName\":\"1.0.0\"," + "\"versionCode\":1000000," + "\"compileSdkType\":\"OpenHarmony\"," + "\"labelId\":16777216," + "\"compileSdkVersion\":\"test_compileSdkVersion\"," + "\"targetAPIVersion\":9," + "\"vendor\":\"\"," + "\"bundleName\":\"com.example.demo\"," + "\"distributedNotificationEnabled\":true," + "\"apiReleaseType\":\"Release\"" + "}," + "\"module\":{" + "\"virtualMachine\":\"test_virtualMachine\"," + "\"mainElement\":\"EntryAbility\"," + "\"installationFree\":false," + "\"deliveryWithInstall\":true," + "\"description\":\"string:module_desc\"," + "\"compileMode\":\"esmodule\"," + "\"type\":\"entry\"," + "\"dependencies\":[]," + "\"abilities\":[" + "{" + "\"iconId\":16777222," + "\"startWindowIconId\":16777222," + "\"visible\":true," + "\"icon\":\"media:icon\"," + "\"startWindowBackgroundId\":16777221," + "\"startWindowIcon\":\"media:icon\"," + "\"description\":\"string:EntryAbility_desc\"," + "\"label\":\"string:EntryAbility_label\"," + "\"skills\":[{\"entities\":[\"entity.system.home\"]," + "\"actions\":[\"action.system.home\"]}]," + "\"descriptionId\":16777218," + "\"labelId\":16777219," + "\"startWindowBackground\":\"color:start_window_background\"," + "\"srcEntrance\":\"./ets/entryability/EntryAbility.ts\"," + "\"name\":\"EntryAbility\"" + "}" + "]," + "\"descriptionId\":16777220," + "\"deviceTypes\":[\"default\",\"tablet\"]," + "\"pages\":\"$profile:main_pages\"," + "\"name\":\"entry\"" + "}" +"}"; + +string str1 = "{" + "\"app\" :{" + "\"apiVersion\" :{" + "\"compatible\" : 9," + "\"releaseType\" : \"Release\"," + "\"target\" : 9" + "}," + "\"bundleName\" : \"test_bundl_name\"," + "\"vendor\" : \"\"," + "\"version\" :{" + "\"code\" : 1000000," + "\"name\" : \"test_name\"" + "}" + "}," + "\"deviceConfig\": {" + "\"default\": 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\" :[" + "\"phone\"," + "\"tablet\"" + "]," + "\"distro\" :{" + "\"deliveryWithInstall\" : true," + "\"installationFree\" : false," + "\"moduleName\" : \"entry\"," + "\"moduleType\" : \"entry\"," + "\"virtualMachine\" : \"test_virtualMachine\"" + "}," + "\"js\" :[" + "{" + "\"mode\" :{" + "\"syntax\" : \"ets\"," + "\"type\" : \"pageAbility\"" + "}," + "\"name\" : \".MainAbility\"," + "\"pages\" :[" + "\"pages/index\"" + "]," + "\"window\" :{" + "\"autoDesignWidth\" : false," + "\"designWidth\" : 720" + "}" + "}" + "]," + "\"mainAbility\" : \".MainAbility\"," + "\"name\" : \".entry\"," + "\"package\" : \"test_package\"" + "}" +"}"; +class ModuleJsonUtilsTest : public testing::Test { +public: + ModuleJsonUtilsTest() {} + virtual ~ModuleJsonUtilsTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void ModuleJsonUtilsTest::SetUpTestCase() {} + +void ModuleJsonUtilsTest::TearDownTestCase() {} + +void ModuleJsonUtilsTest::SetUp() {} + +void ModuleJsonUtilsTest::TearDown() {} + +bool CreateModuleJsonFile(std::string filename) +{ + std::string module_test(filename); + FILE *fp = fopen(module_test.c_str(), "w"); + EXPECT_TRUE(fp != nullptr); + if (fp != nullptr) { + fwrite(str.c_str(), str.size(), 1, fp); + fclose(fp); + } else { + return false; + } + return true; +} + +bool CreateModuleJsonHap(string hapFilePath, string filename) +{ + EXPECT_TRUE(CreateModuleJsonFile(filename)); + ZipWrapper zipWrapper(hapFilePath); + zipWrapper.Open(APPEND_STATUS_CREATE); + std::string filepath(filename); + std::string zippath(OHOS::AppPackingTool::Constants::MODULE_JSON); + zipWrapper.AddFileOrDirectoryToZip(filepath, zippath); + zipWrapper.Close(); + return true; +} + +bool CreateConfigJsonFile(std::string filename) +{ + std::string config_test(filename); + FILE *fp = fopen(config_test.c_str(), "w"); + EXPECT_TRUE(fp != nullptr); + if (fp != nullptr) { + fwrite(str1.c_str(), str1.size(), 1, fp); + fclose(fp); + } else { + return false; + } + return true; +} + +bool CreateConfigJsonHap(string hapFilePath, string filename) +{ + EXPECT_TRUE(CreateConfigJsonFile(filename)); + ZipWrapper zipWrapper(hapFilePath); + zipWrapper.Open(APPEND_STATUS_CREATE); + std::string filepath(filename); + std::string zippath(OHOS::AppPackingTool::Constants::CONFIG_JSON); + zipWrapper.AddFileOrDirectoryToZip(filepath, zippath); + zipWrapper.Close(); + return true; +} + + /* + * @tc.name: GetStageHapVerifyInfo_0100 + * @tc.desc: GetStageHapVerifyInfo + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonUtilsTest, GetStageHapVerifyInfo_0100, Function | MediumTest | Level1) +{ + std::string hapFilePath(HAP_FILE_PATH_TEST); + EXPECT_TRUE(CreateModuleJsonHap(hapFilePath, MODULE_JSON_FILE)); + HapVerifyInfo hapVerifyInfo; + EXPECT_TRUE(ModuleJsonUtils::GetStageHapVerifyInfo(hapFilePath, hapVerifyInfo)); + + std::string cmd = {"rm -f "}; + cmd += HAP_FILE_PATH_TEST; + cmd += " "; + cmd += MODULE_JSON_FILE; + system(cmd.c_str()); +} + + /* + * @tc.name: GetFaHapVerifyInfo_0100 + * @tc.desc: GetFaHapVerifyInfo + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonUtilsTest, GetFaHapVerifyInfo_0100, Function | MediumTest | Level1) +{ + std::string hapFilePath(HAP_FILE_PATH_FA); + EXPECT_TRUE(CreateConfigJsonHap(hapFilePath, CONFIG_JSON_FILE)); + HapVerifyInfo hapVerifyInfo; + EXPECT_TRUE(ModuleJsonUtils::GetFaHapVerifyInfo(hapFilePath, hapVerifyInfo)); + + std::string cmd = {"rm -f "}; + cmd += HAP_FILE_PATH_FA; + cmd += " "; + cmd += CONFIG_JSON_FILE; + system(cmd.c_str()); +} + + /* + * @tc.name: CheckSharedAppIsValid_0100 + * @tc.desc: CheckSharedAppIsValid + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonUtilsTest, CheckSharedAppIsValid_0100, Function | MediumTest | Level1) +{ + std::list hapVerifyInfos; + HapVerifyInfo hapVerifyInfo; + hapVerifyInfo.SetTargetBundleName("test1_target_bundle_name"); + hapVerifyInfo.SetModuleName("test1_module_name"); + + std::list dependencyItemList; + DependencyItem dependencyItem; + dependencyItem.bundleName = "test1_bundle_name"; + dependencyItem.moduleName = "test1_module_name"; + dependencyItem.versionCode = 5; + dependencyItemList.emplace_back(dependencyItem); + + hapVerifyInfo.SetDependencyItemList(dependencyItemList); + hapVerifyInfo.SetModuleType("test1_module_type"); + hapVerifyInfos.emplace_back(hapVerifyInfo); + + bool isOverlay = false; + EXPECT_TRUE(ModuleJsonUtils::CheckSharedAppIsValid(hapVerifyInfos, isOverlay)); +} + + /* + * @tc.name: CheckHapsIsValid_0100 + * @tc.desc: CheckHapsIsValid + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonUtilsTest, CheckHapsIsValid_0100, Function | MediumTest | Level1) +{ + std::string hapFilePath(HAP_FILE_PATH_TEST); + EXPECT_TRUE(CreateModuleJsonHap(hapFilePath, MODULE_JSON_FILE)); + + std::list fileList; + fileList.emplace_back(hapFilePath); + bool isSharedApp = false; + EXPECT_TRUE(ModuleJsonUtils::CheckHapsIsValid(fileList, isSharedApp)); + + std::string cmd = {"rm -f "}; + cmd += HAP_FILE_PATH_TEST; + cmd += " "; + cmd += MODULE_JSON_FILE; + system(cmd.c_str()); +} + + /* + * @tc.name: IsModuleHap_0100 + * @tc.desc: IsModuleHap + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ModuleJsonUtilsTest, IsModuleHap_0100, Function | MediumTest | Level1) +{ + std::string hapFilePath(HAP_FILE_PATH_TEST); + EXPECT_TRUE(CreateModuleJsonHap(hapFilePath, MODULE_JSON_FILE)); + EXPECT_TRUE(ModuleJsonUtils::IsModuleHap(hapFilePath)); + + std::string cmd = {"rm -f "}; + cmd += HAP_FILE_PATH_TEST; + cmd += " "; + cmd += MODULE_JSON_FILE; + system(cmd.c_str()); +} +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/json/normalize_version_utils_test/BUILD.gn b/packing_tool/frameworks/test/unittest/json/normalize_version_utils_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d9a46bb6c6f84790b8dad1e80fa692761d3e4115 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/normalize_version_utils_test/BUILD.gn @@ -0,0 +1,51 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("normalize_version_utils_test_config") { + include_dirs = [ + "../../../../include", + "../../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("normalize_version_utils_test") { + module_out_path = module_output_path + public_configs = [ ":normalize_version_utils_test_config" ] + sources = [ + "../../../../src/json/normalize_version_utils.cpp", + "../../../../src/json/pt_json.cpp", + "../../../../src/log.cpp", + "../../../../src/utils.cpp", + "normalize_version_utils_test.cpp", + ] + external_deps = [ + "bounds_checking_function:libsec_static", + "cJSON:cjson_static", + "hilog:libhilog", + "openssl:libcrypto_shared", + "zlib:libz", + ] +} + +group("unittest") { + testonly = true + deps = [ ":normalize_version_utils_test" ] +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/json/normalize_version_utils_test/normalize_version_utils_test.cpp b/packing_tool/frameworks/test/unittest/json/normalize_version_utils_test/normalize_version_utils_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bb964cadc81cfcb423938ae0e83173978eed53eb --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/normalize_version_utils_test/normalize_version_utils_test.cpp @@ -0,0 +1,98 @@ +/* + * 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. + */ + +#include + +#include +#include +#define private public +#define protected public +#include "normalize_version_utils.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +class NormalizeVersionUtilsTest : public testing::Test { +public: + NormalizeVersionUtilsTest() {} + virtual ~NormalizeVersionUtilsTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void NormalizeVersionUtilsTest::SetUpTestCase() {} + +void NormalizeVersionUtilsTest::TearDownTestCase() {} + +void NormalizeVersionUtilsTest::SetUp() {} + +void NormalizeVersionUtilsTest::TearDown() {} + +/* + * @tc.name: ToString_0100 + * @tc.desc: ToString. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(NormalizeVersionUtilsTest, ToString_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::NormalizeVersion normalizeVersion; + normalizeVersion.originVersionCode = 100; + normalizeVersion.originVersionName = "versionNameTest"; + normalizeVersion.moduleName = "nameTest"; + + OHOS::AppPackingTool::NormalizeVersionUtils utils; + EXPECT_EQ(utils.ToString(normalizeVersion), "{\"moduleName\":\"nameTest\",\"originVersionCode\":100," + "\"originVersionName\":\"versionNameTest\"}"); +} + +/* + * @tc.name: ArrayToString_0100 + * @tc.desc: ArrayToString. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(NormalizeVersionUtilsTest, ArrayToString_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::NormalizeVersion normalizeVersion1; + normalizeVersion1.originVersionCode = 100; + normalizeVersion1.originVersionName = "versionNameTest"; + normalizeVersion1.moduleName = "nameTest"; + + OHOS::AppPackingTool::NormalizeVersion normalizeVersion2; + normalizeVersion2.originVersionCode = 200; + normalizeVersion2.originVersionName = "versionNameTest2"; + normalizeVersion2.moduleName = "nameTest2"; + + std::list normalizeVersions; + normalizeVersions.push_back(normalizeVersion1); + normalizeVersions.push_back(normalizeVersion2); + + OHOS::AppPackingTool::NormalizeVersionUtils utils; + EXPECT_EQ(utils.ArrayToString(normalizeVersions), "[{\"moduleName\":\"nameTest\",\"originVersionCode\":100," + "\"originVersionName\":\"versionNameTest\"},{\"moduleName\":\"nameTest2\",\"originVersionCode\":200," + "\"originVersionName\":\"versionNameTest2\"}]"); +} +} diff --git a/packing_tool/frameworks/test/unittest/json/pack_info_test/BUILD.gn b/packing_tool/frameworks/test/unittest/json/pack_info_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..48142d2a8c7ea39ab18e1166758c449076a218e4 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/pack_info_test/BUILD.gn @@ -0,0 +1,51 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("pack_info_test_config") { + include_dirs = [ + "../../../../include", + "../../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("pack_info_test") { + module_out_path = module_output_path + public_configs = [ ":pack_info_test_config" ] + sources = [ + "../../../../src/json/pack_info.cpp", + "../../../../src/json/pt_json.cpp", + "../../../../src/log.cpp", + "../../../../src/utils.cpp", + "pack_info_test.cpp", + ] + external_deps = [ + "bounds_checking_function:libsec_static", + "cJSON:cjson_static", + "hilog:libhilog", + "openssl:libcrypto_shared", + "zlib:libz", + ] +} + +group("unittest") { + testonly = true + deps = [ ":pack_info_test" ] +} \ No newline at end of file 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 new file mode 100644 index 0000000000000000000000000000000000000000..2cba5ab273ddfceac8b69a979ca1af68ea0e2bfe --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/pack_info_test/pack_info_test.cpp @@ -0,0 +1,351 @@ +/* + * 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. + */ + +#include + +#include +#define private public +#define protected public +#include "pack_info.h" +#include "pt_json.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; +using namespace std; + +namespace OHOS { + +const std::string jsonString = "{" + "\"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\"" + "}" + "]" +"}"; + +class PackInfoTest : public testing::Test { +public: + PackInfoTest() {} + virtual ~PackInfoTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void PackInfoTest::SetUpTestCase() {} + +void PackInfoTest::TearDownTestCase() {} + +void PackInfoTest::SetUp() {} + +void PackInfoTest::TearDown() {} + +/* + * @tc.name: ParseFromString_0100 + * @tc.desc: ParseFromString. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, ParseFromString_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PackInfo packInfo; + EXPECT_TRUE(packInfo.ParseFromString(jsonString)); +} + +/* + * @tc.name: GetSummaryObject_0100 + * @tc.desc: GetSummaryObject. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, GetSummaryObject_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(jsonString); + std::unique_ptr summaryObj; + EXPECT_TRUE(packInfo.GetSummaryObject(summaryObj)); + EXPECT_NE(summaryObj, nullptr); +} + +/* + * @tc.name: GetAppObject_0100 + * @tc.desc: GetAppObject. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, GetAppObject_0100, Function | MediumTest | Level1) +{ + std::unique_ptr appObj; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(jsonString); + EXPECT_TRUE(packInfo.GetAppObject(appObj)); + EXPECT_NE(appObj, nullptr); +} + +/* + * @tc.name: GetBundleName_0100 + * @tc.desc: GetBundleName. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, GetBundleName_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(jsonString); + std::string bundleName = ""; + EXPECT_TRUE(packInfo.GetBundleName(bundleName)); + EXPECT_NE(bundleName, ""); +} + +/* + * @tc.name: SetBundleName_0100 + * @tc.desc: SetBundleName. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetBundleName_0100, Function | MediumTest | Level1) +{ + std::string bundleName = "com.example.myapplication"; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(jsonString); + EXPECT_TRUE(packInfo.SetBundleName(bundleName)); +} + +/* + * @tc.name: GetBundleType_0100 + * @tc.desc: GetBundleType. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, GetBundleType_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(jsonString); + std::string bundleType = ""; + std::string defaultBundleType = "app"; + EXPECT_TRUE(packInfo.GetBundleType(bundleType, defaultBundleType)); + EXPECT_EQ(bundleType, "bundleApp"); +} + +/* + * @tc.name: GetVersionObject_0100 + * @tc.desc: GetVersionObject. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, GetVersionObject_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(jsonString); + std::unique_ptr versionObj; + EXPECT_TRUE(packInfo.GetVersionObject(versionObj)); + EXPECT_NE(versionObj, nullptr); +} + +/* + * @tc.name: GetDistroObject_0100 + * @tc.desc: GetDistroObject. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, GetDistroObject_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(jsonString); + int32_t moduleIndex = 0; + std::unique_ptr distroObj; + EXPECT_TRUE(packInfo.GetDistroObject(moduleIndex, distroObj)); + EXPECT_NE(distroObj, nullptr); +} + +/* + * @tc.name: GetExtensionAbilitiesObj_0100 + * @tc.desc: GetExtensionAbilitiesObj. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, GetExtensionAbilitiesObj_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(jsonString); + int32_t moduleIndex = 0; + std::unique_ptr extensionAbilitiesObj; + EXPECT_TRUE(packInfo.GetExtensionAbilitiesObj(moduleIndex, extensionAbilitiesObj)); + EXPECT_NE(extensionAbilitiesObj, nullptr); +} + +/* + * @tc.name: GetExtensionAbilitiesObjByModulesObj_0100 + * @tc.desc: GetExtensionAbilitiesObjByModulesObj. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, GetExtensionAbilitiesObjByModulesObj_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(jsonString); + std::unique_ptr modulesObj; + packInfo.GetModulesObject(modulesObj); + int32_t moduleIndex = 0; + std::unique_ptr extensionAbilitiesObj; + EXPECT_TRUE(packInfo.GetExtensionAbilitiesObjByModulesObj(modulesObj, moduleIndex, extensionAbilitiesObj)); + EXPECT_NE(extensionAbilitiesObj, nullptr); +} + +/* + * @tc.name: GetPackageObject_0100 + * @tc.desc: GetPackageObject. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, GetPackageObject_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(jsonString); + int32_t packageIndex = 0; + std::unique_ptr packageObj; + EXPECT_TRUE(packInfo.GetPackageObject(packageIndex, packageObj)); + EXPECT_NE(packageObj, nullptr); +} + +/* + * @tc.name: GetVersion_0100 + * @tc.desc: GetVersion. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, GetVersion_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PackInfoVersion version; + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(jsonString); + EXPECT_TRUE(packInfo.GetVersion(version)); + EXPECT_EQ(version.code, 1000000); + EXPECT_EQ(version.name, "1.0.0"); +} + +/* + * @tc.name: SetVersionCode_0100 + * @tc.desc: SetVersionCode. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetVersionCode_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(jsonString); + int versionCode = 1; + EXPECT_TRUE(packInfo.SetVersionCode(versionCode)); +} + +/* + * @tc.name: SetVersionName_0100 + * @tc.desc: SetVersionName. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, SetVersionName_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(jsonString); + std::string versionName = "2.0.0"; + EXPECT_TRUE(packInfo.SetVersionName(versionName)); +} + +/* + * @tc.name: GetNameByPackageObj_0100 + * @tc.desc: GetNameByPackageObj. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, GetNameByPackageObj_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(jsonString); + int32_t packageIndex = 0; + std::unique_ptr packageObj; + packInfo.GetPackageObject(packageIndex, packageObj); + EXPECT_NE(packageObj, nullptr); + std::string name = ""; + EXPECT_TRUE(packInfo.GetNameByPackageObj(packageObj, name)); + EXPECT_EQ(name, "entry-default"); +} + +/* + * @tc.name: GetFormNames_0100 + * @tc.desc: GetFormNames. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoTest, GetFormNames_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PackInfo packInfo; + packInfo.ParseFromString(jsonString); + std::list formNames; + std::list formFullNames; + EXPECT_TRUE(packInfo.GetFormNames(formNames, formFullNames)); +} +} diff --git a/packing_tool/frameworks/test/unittest/json/pack_info_utils_test/BUILD.gn b/packing_tool/frameworks/test/unittest/json/pack_info_utils_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f9d50f1064636b64a8c91072a9139eea8f142ee2 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/pack_info_utils_test/BUILD.gn @@ -0,0 +1,52 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("pack_info_utils_test_config") { + include_dirs = [ + "../../../../include", + "../../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("pack_info_utils_test") { + module_out_path = module_output_path + public_configs = [ ":pack_info_utils_test_config" ] + sources = [ + "../../../../src/json/pack_info.cpp", + "../../../../src/json/pack_info_utils.cpp", + "../../../../src/json/pt_json.cpp", + "../../../../src/log.cpp", + "../../../../src/utils.cpp", + "pack_info_utils_test.cpp", + ] + external_deps = [ + "bounds_checking_function:libsec_static", + "cJSON:cjson_static", + "hilog:libhilog", + "openssl:libcrypto_shared", + "zlib:libz", + ] +} + +group("unittest") { + testonly = true + deps = [ ":pack_info_utils_test" ] +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/json/pack_info_utils_test/pack_info_utils_test.cpp b/packing_tool/frameworks/test/unittest/json/pack_info_utils_test/pack_info_utils_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4704f26afb908314242fc3ed79257ffd1f4ce160 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/pack_info_utils_test/pack_info_utils_test.cpp @@ -0,0 +1,188 @@ +/* + * 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. + */ + +#include + +#include +#define private public +#define protected public +#include "pack_info_utils.h" +#include "pt_json.h" +#include "utils.h" +#include "log.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; +using namespace std; + +namespace OHOS { + +string content1 = "{" + "\"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\"" + "}" + "]" +"}"; + +string content2 = "{" + "\"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\"" + "}" + "]" +"}"; + +class PackInfoUtilsTest : public testing::Test { +public: + PackInfoUtilsTest() {} + virtual ~PackInfoUtilsTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void PackInfoUtilsTest::SetUpTestCase() {} + +void PackInfoUtilsTest::TearDownTestCase() {} + +void PackInfoUtilsTest::SetUp() {} + +void PackInfoUtilsTest::TearDown() {} + +/* + * @tc.name: MergeTwoPackInfos_0100 + * @tc.desc: MergeTwoPackInfos. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoUtilsTest, MergeTwoPackInfos_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PackInfoUtils packInfoUtils; + std::string dstPackInfoJsonStr; + EXPECT_TRUE(packInfoUtils.MergeTwoPackInfos(content1, content2, dstPackInfoJsonStr)); +} + +/* + * @tc.name: MergeTwoPackInfosByPackagePair_0100 + * @tc.desc: MergeTwoPackInfosByPackagePair. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackInfoUtilsTest, MergeTwoPackInfosByPackagePair_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PackInfoUtils packInfoUtils; + std::map packagesMap; + std::string dstPackInfoJsonStr = ""; + packagesMap.insert((make_pair("entry-default", "entry"))); + + EXPECT_TRUE(packInfoUtils.MergeTwoPackInfosByPackagePair(content1, content2, packagesMap, dstPackInfoJsonStr)); +} +} diff --git a/packing_tool/frameworks/test/unittest/json/patch_json_test/BUILD.gn b/packing_tool/frameworks/test/unittest/json/patch_json_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..95b60cc1cbfaf13fd3b2a7553db746ce9f6f9386 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/patch_json_test/BUILD.gn @@ -0,0 +1,50 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("patch_json_test_config") { + include_dirs = [ + "../../../../include", + "../../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("patch_json_test") { + module_out_path = module_output_path + public_configs = [ ":patch_json_test_config" ] + sources = [ + "../../../../src/json/patch_json.cpp", + "../../../../src/json/pt_json.cpp", + "../../../../src/log.cpp", + "patch_json_test.cpp", + ] + external_deps = [ + "bounds_checking_function:libsec_static", + "cJSON:cjson_static", + "hilog:libhilog", + "openssl:libcrypto_shared", + "zlib:libz", + ] +} + +group("unittest") { + testonly = true + deps = [ ":patch_json_test" ] +} diff --git a/packing_tool/frameworks/test/unittest/json/patch_json_test/patch_json_test.cpp b/packing_tool/frameworks/test/unittest/json/patch_json_test/patch_json_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..be7ffff9816975980b58d426e8ea97c0271d1c13 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/patch_json_test/patch_json_test.cpp @@ -0,0 +1,344 @@ +/* + * 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. + */ + +#include + +#include +#define private public +#define protected public +#include "patch_json.h" +#include "pt_json.h" +#include "log.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +std::string content = "{" + "\"name\": \"Json.CN\"," + "\"app\": {" + "\"bundleName\": \"bundleNametest\"," + "\"versionCode\": 100," + "\"versionName\": \"versionNametest\"," + "\"patchVersionCode\": 200," + "\"patchVersionName\": \"patchVersionNametest\"" + "}," + "\"module\": {" + "\"name\": \"nametest\"," + "\"type\": \"typetest\"," + "\"originalModuleHash\": \"originalModuleHashtest\"," + "\"deviceTypes\": [" + "\"aaaaaaaaaaa\"," + "\"bbbbbbbbbbb\"," + "\"ccccccccccc\"" + "]" + "}" +"}"; + +class PatchJsonTest : public testing::Test { +public: + PatchJsonTest() {} + virtual ~PatchJsonTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void PatchJsonTest::SetUpTestCase() {} + +void PatchJsonTest::TearDownTestCase() {} + +void PatchJsonTest::SetUp() {} + +void PatchJsonTest::TearDown() {} + +/* + * @tc.name: ParseFromString_0100 + * @tc.desc: ParseFromString. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, ParseFromString_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); +} + +/* + * @tc.name: ParseFromFile_0100 + * @tc.desc: ParseFromFile. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, ParseFromFile_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + std::string test("test.json"); + FILE *fp = fopen(test.c_str(), "w"); + EXPECT_TRUE(fp != nullptr); + if (fp != nullptr) + { + fwrite(content.c_str(), content.size(), 1, fp); + fclose(fp); + EXPECT_TRUE(patchJson.ParseFromFile(test)); + system("rm -f test.json"); + } +} + +/* + * @tc.name: Release_0100 + * @tc.desc: Release. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, Release_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + patchJson.Release(); + EXPECT_TRUE(patchJson.root_ == nullptr); +} + +/* + * @tc.name: IsValid_0100 + * @tc.desc: IsValid. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, IsValid_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + EXPECT_TRUE(patchJson.IsValid()); +} + +/* + * @tc.name: ToString_0100 + * @tc.desc: ToString. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, ToString_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + std::string contents = patchJson.ToString(); + EXPECT_TRUE(!contents.empty()); + EXPECT_TRUE(patchJson.IsValid()); +} + +/* + * @tc.name: GetAppObject_0100 + * @tc.desc: GetAppObject. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetAppObject_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + std::unique_ptr appObj; + EXPECT_TRUE(patchJson.GetAppObject(appObj)); +} + +/* + * @tc.name: GetModuleObject_0100 + * @tc.desc: GetModuleObject. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetModuleObject_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + std::unique_ptr appObj; + EXPECT_TRUE(patchJson.GetModuleObject(appObj)); +} + +/* + * @tc.name: GetBundleName_0100 + * @tc.desc: GetBundleName. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetBundleName_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + std::string bundleName; + EXPECT_TRUE(patchJson.GetBundleName(bundleName)); + EXPECT_STREQ(bundleName.c_str(), "bundleNametest"); +} + +/* + * @tc.name: GetVersionCode_0100 + * @tc.desc: GetVersionCode. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetVersionCode_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + int32_t versionCode; + EXPECT_TRUE(patchJson.GetVersionCode(versionCode)); + EXPECT_EQ(versionCode, 100); +} + +/* + * @tc.name: GetVersionName_0100 + * @tc.desc: GetVersionName. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetVersionName_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + std::string versionName; + EXPECT_TRUE(patchJson.GetVersionName(versionName)); + EXPECT_STREQ(versionName.c_str(), "versionNametest");; +} + +/* + * @tc.name: GetPatchVersionCode_0100 + * @tc.desc: GetPatchVersionCode. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetPatchVersionCode_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + int32_t patchVersionCode; + EXPECT_TRUE(patchJson.GetPatchVersionCode(patchVersionCode)); + EXPECT_EQ(patchVersionCode, 200); +} + +/* + * @tc.name: GetPatchVersionName_0100 + * @tc.desc: GetPatchVersionName. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetPatchVersionName_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + std::string patchVersionName; + EXPECT_TRUE(patchJson.GetPatchVersionName(patchVersionName)); + EXPECT_STREQ(patchVersionName.c_str(), "patchVersionNametest"); +} + +/* + * @tc.name: GetName_0100 + * @tc.desc: GetName. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetName_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + std::string name; + EXPECT_TRUE(patchJson.GetName(name)); + EXPECT_STREQ(name.c_str(), "nametest"); +} + +/* + * @tc.name: GetType_0100 + * @tc.desc: GetType. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetType_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + std::string type; + EXPECT_TRUE(patchJson.GetType(type)); + EXPECT_STREQ(type.c_str(), "typetest"); +} + +/* + * @tc.name: GetDeviceTypes_0100 + * @tc.desc: GetDeviceTypes. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetDeviceTypes_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + std::list deviceTypes; + EXPECT_TRUE(patchJson.GetDeviceTypes(deviceTypes)); + EXPECT_STREQ(deviceTypes.front().c_str(), "aaaaaaaaaaa"); +} + +/* + * @tc.name: GetOriginalModuleHash_0100 + * @tc.desc: GetOriginalModuleHash. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetOriginalModuleHash_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + std::string originalModuleHash; + EXPECT_TRUE(patchJson.GetOriginalModuleHash(originalModuleHash)); + EXPECT_STREQ(originalModuleHash.c_str(), "originalModuleHashtest"); +} + +/* + * @tc.name: GetHqfInfo_0100 + * @tc.desc: GetHqfInfo. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonTest, GetHqfInfo_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::PatchJson patchJson; + EXPECT_TRUE(patchJson.ParseFromString(content)); + + OHOS::AppPackingTool::HqfInfo hqfInfo; + EXPECT_TRUE(patchJson.GetHqfInfo(hqfInfo)); + EXPECT_STREQ(hqfInfo.GetBundleName().c_str(), "bundleNametest"); +} +} // namespace OHOS \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/json/patch_json_utils_test/BUILD.gn b/packing_tool/frameworks/test/unittest/json/patch_json_utils_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..aec158e66f76b8a0b5d000217ba1fb46cbfa7006 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/patch_json_utils_test/BUILD.gn @@ -0,0 +1,52 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("patch_json_utils_test_config") { + include_dirs = [ + "../../../../include", + "../../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("patch_json_utils_test") { + module_out_path = module_output_path + public_configs = [ ":patch_json_utils_test_config" ] + sources = [ + "../../../../src/json/patch_json.cpp", + "../../../../src/json/patch_json_utils.cpp", + "../../../../src/json/pt_json.cpp", + "../../../../src/log.cpp", + "../../../../src/utils.cpp", + "patch_json_utils_test.cpp", + ] + external_deps = [ + "bounds_checking_function:libsec_static", + "cJSON:cjson_static", + "hilog:libhilog", + "openssl:libcrypto_shared", + "zlib:libz", + ] +} + +group("unittest") { + testonly = true + deps = [ ":patch_json_utils_test" ] +} diff --git a/packing_tool/frameworks/test/unittest/json/patch_json_utils_test/patch_json_utils_test.cpp b/packing_tool/frameworks/test/unittest/json/patch_json_utils_test/patch_json_utils_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9f6c0f217b7f9d8da265acdfec9ac92165a36ff0 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/patch_json_utils_test/patch_json_utils_test.cpp @@ -0,0 +1,109 @@ +/* + * 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. + */ + +#include + +#include +#define private public +#define protected public +#include "patch_json_utils.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; +using namespace std; + +namespace OHOS { + +std::string content = "{" + "\"name\": \"Json.CN\"," + "\"app\": {" + "\"bundleName\": \"bundleNametest\"," + "\"versionCode\": 100," + "\"versionName\": \"versionNametest\"," + "\"patchVersionCode\": 200," + "\"patchVersionName\": \"patchVersionNametest\"" + "}," + "\"module\": {" + "\"name\": \"nametest\"," + "\"type\": \"typetest\"," + "\"originalModuleHash\": \"originalModuleHashtest\"," + "\"deviceTypes\": [" + "\"aaaaaaaaaaa\"," + "\"bbbbbbbbbbb\"," + "\"ccccccccccc\"" + "]" + "}" +"}"; + +class PatchJsonUtilsTest : public testing::Test { +public: + PatchJsonUtilsTest() {} + virtual ~PatchJsonUtilsTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void PatchJsonUtilsTest::SetUpTestCase() {} + +void PatchJsonUtilsTest::TearDownTestCase() {} + +void PatchJsonUtilsTest::SetUp() {} + +void PatchJsonUtilsTest::TearDown() {} + + /* + * @@tc.name: ParsePatchByJsonFilePath_0100 + * @tc.desc: test parse patch by json file path + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonUtilsTest, ParsePatchByJsonFilePath_0100, Function | MediumTest | Level1) +{ + std::string patchJsonFilePath("test.json"); + OHOS::AppPackingTool::HqfInfo hqfInfo; + + FILE *fp = fopen(patchJsonFilePath.c_str(), "w"); + EXPECT_TRUE(fp != nullptr); + if (fp != nullptr) + { + fwrite(content.c_str(), content.size(), 1, fp); + fclose(fp); + } + EXPECT_TRUE(OHOS::AppPackingTool::PatchJsonUtils::ParsePatchByJsonFilePath(patchJsonFilePath, hqfInfo)); + + system("rm -rf test.json"); +} + + /* + * @@tc.name: ParsePatchByJsonStr_0100 + * @tc.desc: test parse patch by json string + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PatchJsonUtilsTest, ParsePatchByJsonStr_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::HqfInfo hqfInfo; + EXPECT_TRUE(OHOS::AppPackingTool::PatchJsonUtils::ParsePatchByJsonStr(content, hqfInfo)); +} + +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/json/pt_json_test/BUILD.gn b/packing_tool/frameworks/test/unittest/json/pt_json_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..47b161565c4d10e5f8a01dbdd3695e302abfcacd --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/pt_json_test/BUILD.gn @@ -0,0 +1,49 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("pt_json_test_config") { + include_dirs = [ + "../../../../include", + "../../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("pt_json_test") { + module_out_path = module_output_path + public_configs = [ ":pt_json_test_config" ] + sources = [ + "../../../../src/json/pt_json.cpp", + "../../../../src/log.cpp", + "pt_json_test.cpp", + ] + external_deps = [ + "bounds_checking_function:libsec_static", + "cJSON:cjson_static", + "hilog:libhilog", + "openssl:libcrypto_shared", + "zlib:libz", + ] +} + +group("unittest") { + testonly = true + deps = [ ":pt_json_test" ] +} 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 new file mode 100644 index 0000000000000000000000000000000000000000..3b8793ec5160d8919b5017aab32e02910ecdc93b --- /dev/null +++ b/packing_tool/frameworks/test/unittest/json/pt_json_test/pt_json_test.cpp @@ -0,0 +1,498 @@ +/* + * 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. + */ + +#include + +#include +#define private public +#define protected public +#include "pt_json.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +std::string content = "{" + "\"name\": \"Json.CN\"," + "\"app\": \"apptest\"," + "\"module\": {" + "\"name\": \"nametest\"," + "\"type\": \"typetest\"," + "\"deviceTypes\": [" + "\"aaaaaaaaaaa\"," + "\"bbbbbbbbbbb\"," + "\"ccccccccccc\"" + "]" + "}," + "\"bundleName\": \"bundleNametest\"," + "\"versionCode\": 100," + "\"versionName\": \"versionNametest\"," + "\"patchVersionCode\": 200," + "\"patchVersionName\": \"patchVersionNametest\"," + "\"originalModuleHash\": \"originalModuleHashtest\"" +"}"; + +class PtJsonTest : public testing::Test { +public: + PtJsonTest() {} + virtual ~PtJsonTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void PtJsonTest::SetUpTestCase() {} + +void PtJsonTest::TearDownTestCase() {} + +void PtJsonTest::SetUp() {} + +void PtJsonTest::TearDown() {} + +/* + * @tc.name: CreateObject_0100 + * @tc.desc: CreateObject. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, CreateObject_0100, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + std::unique_ptr ptjsonObject = ptJson.CreateObject(); + EXPECT_TRUE(ptjsonObject != NULL); +} + +/* + * @tc.name: CreateArray_0200 + * @tc.desc: CreateArray. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, CreateArray_0200, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + std::unique_ptr ptjsonArray = ptJson.CreateArray(); + EXPECT_TRUE(ptjsonArray != NULL); +} + +/* + * @tc.name: ReleaseRoot_0300 + * @tc.desc: ReleaseRoot. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, ReleaseRoot_0300, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + ptJson.ReleaseRoot(); + EXPECT_TRUE(ptJson.object_ == NULL); +} + +/* + * @tc.name: Parse_0400 + * @tc.desc: Parse. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, Parse_0400, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + std::unique_ptr ptjson = ptJson.Parse(content); + EXPECT_TRUE(ptjson != NULL); +} + +/* + * @tc.name: Stringify_0500 + * @tc.desc: Stringify. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, Stringify_0500, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + std::unique_ptr ptjson = ptJson.Parse(content); + EXPECT_TRUE(ptjson != NULL); + EXPECT_TRUE(!ptjson->Stringify().empty()); +} + +/* + * @tc.name: Add_0600 + * @tc.desc: Add. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, Add_0600, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + std::unique_ptr ptjsonObject = ptJson.CreateObject(); + EXPECT_TRUE(ptjsonObject != NULL); + + 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)); +} + +/* + * @tc.name: Push_0700 + * @tc.desc: Push. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, Push_0700, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + std::unique_ptr ptjsonObject = ptJson.CreateObject(); + EXPECT_TRUE(ptjsonObject != NULL); + + std::unique_ptr ptjsonArray = ptJson.CreateArray(); + EXPECT_TRUE(ptjsonArray != NULL); + + 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.Push(true)); + EXPECT_TRUE(ptJson.Push(123)); + EXPECT_TRUE(ptJson.Push(123.5)); + EXPECT_TRUE(ptJson.Push("ABC")); + EXPECT_TRUE(ptJson.Push(ptjsonArray)); +} + +/* + * @tc.name: Contains_0800 + * @tc.desc: Contains. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, Contains_0800, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + EXPECT_TRUE(ptJson.Add("AAA", true)); + EXPECT_TRUE(ptJson.Remove("AAA")); +} + +/* + * @tc.name: Contains_0900 + * @tc.desc: Contains. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, Contains_0900, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + EXPECT_TRUE(ptJson.Add("AAA", true)); + EXPECT_TRUE(ptJson.Contains("AAA")); +} + +/* + * @tc.name: GetKey_1000 + * @tc.desc: GetKey. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, GetKey_1000, Function | MediumTest | Level1) +{ + char a[] = "{\"firstName\":\"Brett\"}"; + cJSON*root = cJSON_Parse(a); + cJSON*item = cJSON_GetObjectItem(root, "firstName"); + OHOS::AppPackingTool::PtJson ptJson(item); + EXPECT_TRUE(!ptJson.GetKey().empty()); + EXPECT_TRUE(!ptJson.Stringify().empty()); +} + +/* + * @tc.name: GetJson_1100 + * @tc.desc: GetJson. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, GetJson_1100, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + EXPECT_TRUE(ptJson.GetJson() != nullptr); +} + +/* + * @tc.name: IsBool_1200 + * @tc.desc: IsBool. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, IsBool_1200, Function | MediumTest | Level1) +{ + cJSON *node = cJSON_CreateBool(true); + OHOS::AppPackingTool::PtJson ptJsonBool(node); + + EXPECT_TRUE(ptJsonBool.IsBool()); + EXPECT_TRUE(ptJsonBool.GetBool(true)); +} + +/* + * @tc.name: IsNumber_1300 + * @tc.desc: IsNumber. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, IsNumber_1300, Function | MediumTest | Level1) +{ + cJSON *node = cJSON_CreateNumber(12345); + OHOS::AppPackingTool::PtJson ptJsonNumber(node); + + EXPECT_TRUE(ptJsonNumber.IsNumber()); + EXPECT_EQ(ptJsonNumber.GetInt(12345), 12345); + EXPECT_EQ(ptJsonNumber.GetInt64(12345), 12345); + EXPECT_EQ(ptJsonNumber.GetUInt(12345), 12345); + EXPECT_EQ(ptJsonNumber.GetUInt64(12345), 12345); + EXPECT_EQ(ptJsonNumber.GetDouble(12345.5), 12345); +} + +/* + * @tc.name: IsString_1400 + * @tc.desc: IsString. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, IsString_1400, Function | MediumTest | Level1) +{ + cJSON *node = cJSON_CreateString("abcd"); + OHOS::AppPackingTool::PtJson ptJsonString(node); + + EXPECT_TRUE(ptJsonString.IsString()); + EXPECT_STREQ(ptJsonString.GetString().c_str(), "abcd"); +} + +/* + * @tc.name: IsObject_1500 + * @tc.desc: IsObject. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, IsObject_1500, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + std::unique_ptr ptjsonObject = ptJson.CreateObject(); + EXPECT_TRUE(ptjsonObject != NULL); + EXPECT_TRUE(ptjsonObject->IsObject()); +} + +/* + * @tc.name: IsArray_1600 + * @tc.desc: IsArray. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, IsArray_1600, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + std::unique_ptr ptjsonArray = ptJson.CreateArray(); + EXPECT_TRUE(ptjsonArray != NULL); + EXPECT_TRUE(ptjsonArray->IsArray()); + ptjsonArray->Push("11111"); + ptjsonArray->Push("22222"); + EXPECT_STREQ(ptjsonArray->Get(1)->GetString().c_str(), "22222"); + EXPECT_TRUE(ptjsonArray->GetSize() > 0); +} + +/* + * @tc.name: IsNull_1700 + * @tc.desc: IsNull. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, IsNull_1700, Function | MediumTest | Level1) +{ + cJSON *cjson = cJSON_CreateNull(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + EXPECT_TRUE(ptJson.IsNull()); +} + +/* + * @tc.name: SetBool_1800 + * @tc.desc: SetBool. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, SetBool_1800, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + bool flag = false; + ptJson.Add("AAA", true); + EXPECT_EQ(ptJson.SetBool("AAA", flag), OHOS::AppPackingTool::Result::SUCCESS); + ptJson.GetBool("AAA", &flag); + EXPECT_FALSE(flag); +} + +/* + * @tc.name: SetInt_1900 + * @tc.desc: SetInt. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, SetInt_1900, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + EXPECT_TRUE(ptJson.Add("BBB", 123)); + int number = 0; + EXPECT_EQ(ptJson.SetInt("BBB", 321), OHOS::AppPackingTool::Result::SUCCESS); + ptJson.GetInt("BBB", &number); + EXPECT_EQ(number, 321); +} + +/* + * @tc.name: SetInt64_2000 + * @tc.desc: SetInt64. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, SetInt64_2000, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + EXPECT_TRUE(ptJson.Add("BBB", 123)); + EXPECT_TRUE(ptJson.Add("CCC", 123.5)); + + int64_t value64 = 11111; + EXPECT_EQ(ptJson.SetInt64("BBB", value64), OHOS::AppPackingTool::Result::SUCCESS); + int64_t value642; + EXPECT_EQ(ptJson.GetInt64("BBB", &value642), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_EQ(value642, 11111); + + uint32_t value32 = 2222; + EXPECT_EQ(ptJson.SetUInt("BBB", value32), OHOS::AppPackingTool::Result::SUCCESS); + uint32_t value322; + EXPECT_EQ(ptJson.GetUInt("BBB", &value322), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_EQ(value322, 2222); + + uint64_t valueInt64 = 3333; + EXPECT_EQ(ptJson.SetUInt64("BBB", valueInt64), OHOS::AppPackingTool::Result::SUCCESS); + uint64_t valueInt642; + EXPECT_EQ(ptJson.GetUInt64("BBB", &valueInt642), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_EQ(valueInt642, 3333); + + double valueDouble = 4444; + EXPECT_EQ(ptJson.SetDouble("CCC", valueDouble), OHOS::AppPackingTool::Result::SUCCESS); + double valueDouble2; + EXPECT_EQ(ptJson.GetDouble("CCC", &valueDouble2), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_EQ(valueDouble2, 4444); +} + +/* + * @tc.name: SetString_2100 + * @tc.desc: SetString. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, SetString_2100, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + EXPECT_TRUE(ptJson.Add("DDD", "ABC")); + std::string str("1234567890"); + EXPECT_EQ(ptJson.SetString("DDD", str), OHOS::AppPackingTool::Result::SUCCESS); + std::string str2; + EXPECT_EQ(ptJson.GetString("DDD", &str2), OHOS::AppPackingTool::Result::SUCCESS); + EXPECT_STREQ(str2.c_str(), str.c_str()); +} + +/* + * @tc.name: GetObject_2200 + * @tc.desc: GetObject. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, GetObject_2200, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + std::unique_ptr ptjsonObject = ptJson.CreateObject(); + EXPECT_TRUE(ptjsonObject != NULL); + EXPECT_TRUE(ptJson.Add("EEE", ptjsonObject)); + std::unique_ptr Object; + EXPECT_EQ(ptJson.GetObject("EEE", &Object), OHOS::AppPackingTool::Result::SUCCESS); +} + +/* + * @tc.name: GetArray_2300 + * @tc.desc: GetArray. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, GetArray_2300, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + ptJson.Add("FFF", ptJson.CreateArray()); + std::unique_ptr Array; + EXPECT_EQ(ptJson.GetArray("FFF", &Array), OHOS::AppPackingTool::Result::SUCCESS); +} + +/* + * @tc.name: GetAny_2400 + * @tc.desc: GetAny. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PtJsonTest, GetAny_2400, Function | MediumTest | Level1) +{ + cJSON *cjson = new cJSON(); + OHOS::AppPackingTool::PtJson ptJson(cjson); + + ptJson.Add("FFF", ptJson.CreateArray()); + std::unique_ptr Object; + EXPECT_EQ(ptJson.GetAny("FFF", &Object), OHOS::AppPackingTool::Result::SUCCESS); +} +} // namespace OHOS \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/BUILD.gn b/packing_tool/frameworks/test/unittest/multiapp_packager_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..1f167f6064f08c82690749045bf6665f05e6bd63 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/BUILD.gn @@ -0,0 +1,68 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("multiapp_packager_test_config") { + include_dirs = [ + "../../../include", + "../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("multiapp_packager_test") { + module_out_path = module_output_path + public_configs = [ ":multiapp_packager_test_config" ] + sources = [ + "../../../src/json/distro_filter.cpp", + "../../../src/json/hap_verify_info.cpp", + "../../../src/json/hap_verify_utils.cpp", + "../../../src/json/module_json.cpp", + "../../../src/json/module_json_fa.cpp", + "../../../src/json/module_json_stage.cpp", + "../../../src/json/module_json_utils.cpp", + "../../../src/json/pack_info.cpp", + "../../../src/json/pack_info_utils.cpp", + "../../../src/json/pt_json.cpp", + "../../../src/log.cpp", + "../../../src/multiapp_packager.cpp", + "../../../src/packager.cpp", + "../../../src/unzip_wrapper.cpp", + "../../../src/utils.cpp", + "../../../src/zip_utils.cpp", + "../../../src/zip_wrapper.cpp", + "multiapp_packager_test.cpp", + ] + external_deps = [ + "bounds_checking_function:libsec_static", + "cJSON:cjson_static", + "hilog:libhilog", + "openssl:libcrypto_shared", + "zlib:libz", + ] + deps = [ + "./multiappPackagerHapTest:multiappPackagerHapTest", + "./multiappPackagerHspTest:multiappPackagerHspTest", + ] +} + +group("unittest") { + testonly = true + deps = [ ":multiapp_packager_test" ] +} diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/AppScope/app.json b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..5470c22e225cb61e721cda383f7074711b2b0911 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/AppScope/app.json @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.example.myapplication", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/AppScope/resources/base/element/string.json b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1080233f01384411ec684b58955cb8808746fdd3 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication" + } + ] +} diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/AppScope/resources/base/media/app_icon.png b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/AppScope/resources/base/media/app_icon.png differ diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/BUILD.gn b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d5bfd314487954a2dca8ca809a0988e597b645c5 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/BUILD.gn @@ -0,0 +1,41 @@ +# Copyright (c) 2023 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") + +ohos_hap("multiappPackagerHapTest") { + hap_profile = "entry/src/main/module.json" + hap_name = "multiappPackagerHapTest" + final_hap_path = "$root_out_dir/tests/unittest/developtools/packing_tool/test_file/test_bundle_multiapp/${hap_name}.hap" + testonly = true + deps = [ + ":hjs_demo_js_assets", + ":hjs_demo_resources", + ] + certificate_profile = "../multiapp_packager_file/com.test.apppackagertest.p7b" +} + +ohos_app_scope("bmsstagedemoone_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("hjs_demo_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("hjs_demo_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":bmsstagedemoone_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/ets/entryability/EntryAbility.ts b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/ets/entryability/EntryAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..aa5530d3497f025d1da5f1082f7d1d08893a59ae --- /dev/null +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/ets/entryability/EntryAbility.ts @@ -0,0 +1,56 @@ +/* + * 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. + */ + +import UIAbility from '@ohos.app.ability.UIAbility'; +import hilog from '@ohos.hilog'; +import window from '@ohos.window'; + +export default class EntryAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); + } + + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + // Main window is created, set main page for this ability + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); + + windowStage.loadContent('pages/Index', (err, data) => { + if (err.code) { + hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); + return; + } + hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); + }); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy'); + } + + onForeground() { + // Ability has brought to foreground + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground'); + } + + onBackground() { + // Ability has back to background + hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground'); + } +} diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/ets/pages/Index.ets b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..aa56579e8586af7bc8d35ba914031d0b19b2dcf8 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,32 @@ +/* + * 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. + */ + +@Entry +@Component +struct Index { + @State message: string = 'Hello World' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/module.json b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..9b07af70a189c0165e30b9f4bedc3bfd22b53cda --- /dev/null +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/module.json @@ -0,0 +1,37 @@ +{ + "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" + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/resources/base/element/color.json b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/resources/base/element/string.json b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f94595515a99e0c828807e243494f57f09251930 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_desc", + "value": "module description" + }, + { + "name": "EntryAbility_desc", + "value": "description" + }, + { + "name": "EntryAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/resources/base/media/app_icon.png b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/resources/base/media/app_icon.png differ diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/resources/base/media/icon.png b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/resources/base/media/icon.png differ diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/resources/base/profile/main_pages.json b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHapTest/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/AppScope/app.json b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..5470c22e225cb61e721cda383f7074711b2b0911 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/AppScope/app.json @@ -0,0 +1,10 @@ +{ + "app": { + "bundleName": "com.example.myapplication", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name" + } +} diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/AppScope/resources/base/element/string.json b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..1080233f01384411ec684b58955cb8808746fdd3 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication" + } + ] +} diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/AppScope/resources/base/media/app_icon.png b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/AppScope/resources/base/media/app_icon.png differ diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/BUILD.gn b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a096386913cd68ba7afa794a4d07f74e53b96611 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/BUILD.gn @@ -0,0 +1,41 @@ +# Copyright (c) 2023 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") + +ohos_hap("multiappPackagerHspTest") { + hap_profile = "entry/src/main/module.json" + hap_name = "multiappPackagerHspTest" + final_hap_path = "$root_out_dir/tests/unittest/developtools/packing_tool/test_file/test_bundle_multiapp/${hap_name}.hsp" + testonly = true + deps = [ + ":hjs_demo_js_assets", + ":hjs_demo_resources", + ] + certificate_profile = "../multiapp_packager_file/com.test.apppackagertest.p7b" +} + +ohos_app_scope("bmsstagedemoone_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("hjs_demo_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("hjs_demo_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":bmsstagedemoone_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/ets/Index.ets b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/ets/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..3d41603b1dd13ae13d65d12d2569b1798c9cf88e --- /dev/null +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/ets/Index.ets @@ -0,0 +1,16 @@ +/* + * 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. + */ + +export { add } from "./utils/Calc" \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/ets/pages/Index.ets b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/ets/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..aa56579e8586af7bc8d35ba914031d0b19b2dcf8 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/ets/pages/Index.ets @@ -0,0 +1,32 @@ +/* + * 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. + */ + +@Entry +@Component +struct Index { + @State message: string = 'Hello World' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + } + .height('100%') + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/ets/utils/Calc.ts b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/ets/utils/Calc.ts new file mode 100644 index 0000000000000000000000000000000000000000..ea3f851147dabf67fb68408d43d3e9011527890c --- /dev/null +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/ets/utils/Calc.ts @@ -0,0 +1,18 @@ +/* + * 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. + */ + +export function add(a:number, b:number) { + return a + b; +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/module.json b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..10dc9bb580dfe706a76fc9c1199f75a6666ea4be --- /dev/null +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/module.json @@ -0,0 +1,13 @@ +{ + "module": { + "name": "library1", + "type": "shared", + "description": "$string:shared_desc", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "pages": "$profile:main_pages" + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/resources/base/element/color.json b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..1bbc9aa9617e97c45440e1d3d66afc1154837012 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/resources/base/element/string.json b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..98e1d8a84b3d8539ea33e79fe2ac593a05d23bb4 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "shared_desc", + "value": "description" + } + ] +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/resources/base/media/icon.png b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/resources/base/media/icon.png differ diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/resources/base/media/setting.jpeg b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/resources/base/media/setting.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..57e67dd49d39ad64ef090f59db3db9dfe6632106 Binary files /dev/null and b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/resources/base/media/setting.jpeg differ diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/resources/base/profile/main_pages.json b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiappPackagerHspTest/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiapp_packager_file/com.test.apppackagertest.p7b b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiapp_packager_file/com.test.apppackagertest.p7b new file mode 100644 index 0000000000000000000000000000000000000000..1f83705e81172e9c781535036808fc14c3230393 Binary files /dev/null and b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiapp_packager_file/com.test.apppackagertest.p7b differ diff --git a/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiapp_packager_test.cpp b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiapp_packager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8b687fd8ae96c576db345bdaf7d00d4ffafc6567 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/multiapp_packager_test/multiapp_packager_test.cpp @@ -0,0 +1,87 @@ +/* + * 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. + */ + +#include + +#include +#include "constants.h" +#define private public +#define protected public +#include "packager.h" +#include "multiapp_packager.h" +#include "zip_wrapper.h" +#include "log.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +#define OUT_PATH "/data/test_1.app" +#define HAP_LIST "/data/test/resource/packingtool/test_file/multiApp/hap/multiappPackagerHapTest.hap" +#define HSP_LIST "/data/test/resource/packingtool/test_file/multiApp/hsp/multiappPackagerHspTest.hsp" + + +class MultiAppPackagerTest : public testing::Test { +public: + MultiAppPackagerTest() {} + virtual ~MultiAppPackagerTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void MultiAppPackagerTest::SetUpTestCase() +{} + +void MultiAppPackagerTest::TearDownTestCase() +{} + +void MultiAppPackagerTest::SetUp() +{} + +void MultiAppPackagerTest::TearDown() +{} + +/* + * @tc.name: MultiAppPackager_0100 + * @tc.desc: InitAllowedParam. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(MultiAppPackagerTest, MultiAppPackager_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "true"}, + {OHOS::AppPackingTool::Constants::PARAM_HAP_LIST, HAP_LIST}, + {OHOS::AppPackingTool::Constants::PARAM_HSP_LIST, HSP_LIST}, + }; + + OHOS::AppPackingTool::MultiAppPackager multiAppPackager(parameterMap, resultReceiver); + EXPECT_EQ(multiAppPackager.InitAllowedParam(), 0); + EXPECT_EQ(multiAppPackager.PreProcess(), 0); + EXPECT_EQ(multiAppPackager.Process(), 0); + EXPECT_EQ(multiAppPackager.PostProcess(), 0); +} +} // namespace OHOS \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/ohos_test/BUILD.gn b/packing_tool/frameworks/test/unittest/ohos_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e081c62b42442f668ab652f6c45c3807fffd796a --- /dev/null +++ b/packing_tool/frameworks/test/unittest/ohos_test/BUILD.gn @@ -0,0 +1,21 @@ +# 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. + +import("//build/ohos.gni") + +ohos_copy("copy_ohos_test") { + subsystem_name = "developtools" + part_name = "packing_tool" + sources = [ "./ohos_test.xml" ] + outputs = [ "$root_out_dir/tests/unittest/developtools/packing_tool/resource/ohos_test.xml" ] +} diff --git a/packing_tool/frameworks/test/unittest/ohos_test/ohos_test.xml b/packing_tool/frameworks/test/unittest/ohos_test/ohos_test.xml new file mode 100644 index 0000000000000000000000000000000000000000..d419e31dd265eb019c32a19dc71153ffbb595b89 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/ohos_test/ohos_test.xml @@ -0,0 +1,118 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/package_normalize_test/BUILD.gn b/packing_tool/frameworks/test/unittest/package_normalize_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e1b798d8b9e572f8af33a315ca179dd1355eb2a1 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/package_normalize_test/BUILD.gn @@ -0,0 +1,74 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("packager_normalize_test_config") { + include_dirs = [ + "../../../include", + "../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("package_normalize_test") { + module_out_path = module_output_path + public_configs = [ ":packager_normalize_test_config" ] + sources = [ + "../../../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/package_normalize.cpp", + "../../../src/packager.cpp", + "../../../src/unzip_wrapper.cpp", + "../../../src/utils.cpp", + "../../../src/zip_utils.cpp", + "../../../src/zip_wrapper.cpp", + "package_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 = [ ":package_normalize_test" ] +} + +ohos_copy("copy_test_file") { + subsystem_name = "developtools" + part_name = "packing_tool" + sources = [ "./package_normalize_file" ] + outputs = [ "$root_out_dir/tests/unittest/developtools/packing_tool/test_file/package_normalize_file/" ] +} diff --git a/packing_tool/frameworks/test/unittest/package_normalize_test/package_normalize_file/module.json b/packing_tool/frameworks/test/unittest/package_normalize_test/package_normalize_file/module.json new file mode 100644 index 0000000000000000000000000000000000000000..453852dc74a4096a7ba7ceffbc5e1be821c567e0 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/package_normalize_test/package_normalize_file/module.json @@ -0,0 +1,27 @@ +{ + "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", + "iconId": 33554433, + "labelId": 33554432 + }, + "module": { + "name": "library", + "type": "shared", + "description": "$string:shared_desc", + "deviceTypes": ["default", "tablet"], + "deliveryWithInstall": true, + "pages": "$profile:main_pages", + "virtualMachine": "ark12.0.1.0", + "compileMode": "esmodule", + "dependencies": [], + "descriptionId": 33554434 + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/package_normalize_test/package_normalize_file/pack.json b/packing_tool/frameworks/test/unittest/package_normalize_test/package_normalize_file/pack.json new file mode 100644 index 0000000000000000000000000000000000000000..e8a818ea4d6a79883b160dcd0153117443525751 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/package_normalize_test/package_normalize_file/pack.json @@ -0,0 +1 @@ +{"summary":{"app":{"bundleName":"com.example.packingtooldemo","version":{"code":1000000,"name":"1.0.0"}},"modules":[{"deviceType":["default","tablet"],"distro":{"moduleType":"shared","deliveryWithInstall":true,"moduleName":"library"},"apiVersion":{"compatible":12,"releaseType":"Canary2","target":12}}]},"packages":[{"deviceType":["default","tablet"],"moduleType":"shared","deliveryWithInstall":true,"name":"library-default"}]} diff --git a/packing_tool/frameworks/test/unittest/package_normalize_test/package_normalize_file/resources/base/profile/main_pages.json b/packing_tool/frameworks/test/unittest/package_normalize_test/package_normalize_file/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/packing_tool/frameworks/test/unittest/package_normalize_test/package_normalize_file/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/packing_tool/frameworks/test/unittest/package_normalize_test/package_normalize_test.cpp b/packing_tool/frameworks/test/unittest/package_normalize_test/package_normalize_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..aa944373ac781f2740f46b6e3abf8f09a2b1ec69 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/package_normalize_test/package_normalize_test.cpp @@ -0,0 +1,193 @@ +/* + * 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. + */ + +#include + +#include +#include "constants.h" +#define private public +#define protected public +#include "package_normalize.h" +#include "hsp_packager.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +#define BUNDLE_NAME "dd.dd.dd" +#define HSP_LIST "/data/test/hsp_example" +#define OUT_PATH "/data/test/packagenormalize_packing" +#define VERSION_CODE "1000098" +#define HSP_OUT_PATH "/data/test/hsp_example/library-default-unsigned.hsp" +#define HSP_INDEX_PATH "/data/test/resource/packingtool/test_file/resources.index" +#define HSP_PACK_INFO_PATH "/data/test/resource/packingtool/test_file/pack.info" +#define HSP_ETS_PATH "/data/test/resource/packingtool/test_file/ets" +#define HSP_RESOURCES_PATH "/data/test/resource/packingtool/test_file/resources" +#define HSP_JSON_PATH "/data/test/resource/packingtool/test_file/module.json" +class PackageNormalizeTest : public testing::Test { +public: + PackageNormalizeTest() {} + virtual ~PackageNormalizeTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void PackageNormalizeTest::SetUpTestCase() +{ + std::string resultReceiver; + system("mkdir /data/test/hsp_example"); + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, HSP_OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "true"}, + {OHOS::AppPackingTool::Constants::PARAM_JSON_PATH, HSP_JSON_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_ETS_PATH, HSP_ETS_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_RESOURCES_PATH, HSP_RESOURCES_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_INDEX_PATH, HSP_INDEX_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_PACK_INFO_PATH, HSP_PACK_INFO_PATH}, + }; + + OHOS::AppPackingTool::HspPackager hspPackager(parameterMap, resultReceiver); + system("mkdir /data/test/resource/packingtool/test_file/ets"); + system("mv /data/test/resource/packingtool/test_file/pack.json " + "/data/test/resource/packingtool/test_file/pack.info"); + EXPECT_EQ(hspPackager.InitAllowedParam(), 0); + EXPECT_EQ(hspPackager.PreProcess(), 0); + EXPECT_EQ(hspPackager.Process(), 0); + EXPECT_EQ(hspPackager.PostProcess(), 0); +} + +void PackageNormalizeTest::TearDownTestCase() +{ + std::string cmd = {"rm -f /data/test/packagenormalize_packing/*"}; + system(cmd.c_str()); +} + +void PackageNormalizeTest::SetUp() {} + +void PackageNormalizeTest::TearDown() {} + +/* + * @tc.name: PackageNormalize_0100 + * @tc.desc: PackageNormalize. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackageNormalizeTest, PackageNormalize_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_HSP_LIST, HSP_LIST}, + {OHOS::AppPackingTool::Constants::PARAM_BUNDLE_NAME, BUNDLE_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH} + }; + OHOS::AppPackingTool::PackageNormalize packageNormalize(parameterMap, resultReceiver); + EXPECT_EQ(packageNormalize.PreProcess(), 0); + EXPECT_EQ(packageNormalize.Process(), 0); + std::string cmd = {"rm -rf "}; + cmd +=OUT_PATH; + system(cmd.c_str()); +} + +/* + * @tc.name: PreProcess_0100 + * @tc.desc: hsp-list is empty. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackageNormalizeTest, PreProcess_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_BUNDLE_NAME, BUNDLE_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + }; + + OHOS::AppPackingTool::PackageNormalize packageNormalize(parameterMap, resultReceiver); + EXPECT_EQ(packageNormalize.PreProcess(), 1); +} + +/* + * @tc.name: PreProcess_0200 + * @tc.desc: hsp-list is invalid. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackageNormalizeTest, PreProcess_0200, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_HSP_LIST, + "/data/test/pnerr.hsp."}, + {OHOS::AppPackingTool::Constants::PARAM_BUNDLE_NAME, BUNDLE_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + }; + + OHOS::AppPackingTool::PackageNormalize packageNormalize(parameterMap, resultReceiver); + EXPECT_EQ(packageNormalize.PreProcess(), 1); +} + +/* + * @tc.name: PreProcess_0300 + * @tc.desc: bundle-name is invalid. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackageNormalizeTest, PreProcess_0300, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_HSP_LIST, HSP_LIST}, + {OHOS::AppPackingTool::Constants::PARAM_BUNDLE_NAME, "123456"}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + }; + + OHOS::AppPackingTool::PackageNormalize packageNormalize(parameterMap, resultReceiver); + EXPECT_EQ(packageNormalize.PreProcess(), 1); +} + +/* + * @tc.name: PreProcess_0400 + * @tc.desc: version-code is invalid. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackageNormalizeTest, PreProcess_0400, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_HSP_LIST, + "/data/test/package_normalize_test"}, + {OHOS::AppPackingTool::Constants::PARAM_BUNDLE_NAME, BUNDLE_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, "-12345"}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + }; + + OHOS::AppPackingTool::PackageNormalize packageNormalize(parameterMap, resultReceiver); + EXPECT_EQ(packageNormalize.PreProcess(), 1); +} +} // namespace OHOS \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/packager_test/BUILD.gn b/packing_tool/frameworks/test/unittest/packager_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..71aaf3b1ad18fc9827451e105ee34f7774bf2c59 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/packager_test/BUILD.gn @@ -0,0 +1,56 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("packager_test_config") { + include_dirs = [ + "../../../include", + "../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} +module_output_path = "developtools/packing_tool" + +ohos_unittest("packager_test") { + module_out_path = module_output_path + public_configs = [ ":packager_test_config" ] + sources = [ + "../../../src/hap_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/pt_json.cpp", + "../../../src/log.cpp", + "../../../src/packager.cpp", + "../../../src/utils.cpp", + "../../../src/zip_wrapper.cpp", + "packager_test.cpp", + ] + external_deps = [ + "bounds_checking_function:libsec_static", + "cJSON:cjson_static", + "hilog:libhilog", + "openssl:libcrypto_shared", + "zlib:libz", + ] +} + +group("unittest") { + testonly = true + deps = [ ":packager_test" ] +} diff --git a/packing_tool/frameworks/test/unittest/packager_test/packager_test.cpp b/packing_tool/frameworks/test/unittest/packager_test/packager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..db82aab4846a500d617926a1cfd402ddff58c0f7 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/packager_test/packager_test.cpp @@ -0,0 +1,140 @@ +/* + * 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. + */ + +#include +#include + +#include "constants.h" +#define private public +#define protected public +#include "hap_packager.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +#define OUT_PATH "/data/test/entry-default-unsigned.hap" +#define SUFFIX ".hap" +#define DIR_PATH "/data/test" + +class PackagerTest : public testing::Test { +public: + PackagerTest() {} + virtual ~PackagerTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void PackagerTest::SetUpTestCase() {} + +void PackagerTest::TearDownTestCase() {} + +void PackagerTest::SetUp() {} + +void PackagerTest::TearDown() {} + +/* + * @tc.name: CheckForceFlag_0100 + * @tc.desc: CheckForceFlag. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackagerTest, CheckForceFlag_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "true"}, + }; + + OHOS::AppPackingTool::HapPackager packager(parameterMap, resultReceiver); + EXPECT_TRUE(packager.CheckForceFlag()); +} + +/* + * @tc.name: IsPathValid_0200 + * @tc.desc: IsPathValid. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackagerTest, IsPathValid_0200, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = {}; + + OHOS::AppPackingTool::HapPackager packager(parameterMap, resultReceiver); + system("touch /data/test/entry-default-unsigned.hap"); + EXPECT_TRUE(packager.IsPathValid(OUT_PATH, true, SUFFIX)); + system("rm -f /data/test/entry-default-unsigned.hap"); +} + +/* + * @tc.name: SplitDirList_0300 + * @tc.desc: SplitDirList. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackagerTest, SplitDirList_0300, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = {}; + + OHOS::AppPackingTool::HapPackager packager(parameterMap, resultReceiver); + const std::string dirList; + std::list fileList; + EXPECT_TRUE(packager.SplitDirList(dirList, fileList)); +} + +/* + * @tc.name: CompatibleProcess_0400 + * @tc.desc: CompatibleProcess. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackagerTest, CompatibleProcess_0400, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = {}; + + OHOS::AppPackingTool::HapPackager packager(parameterMap, resultReceiver); + const std::string inPutPath; + std::list fileList; + const std::string suffix; + EXPECT_TRUE(packager.CompatibleProcess(inPutPath, fileList, suffix)); +} + +/* + * @tc.name: IsOutPathValid_0500 + * @tc.desc: IsOutPathValid. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(PackagerTest, IsOutPathValid_0500, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = {}; + + OHOS::AppPackingTool::HapPackager packager(parameterMap, resultReceiver); + EXPECT_TRUE(packager.IsOutPathValid(OUT_PATH, "true", SUFFIX)); +} +} // namespace OHOS \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/shell_command_test/BUILD.gn b/packing_tool/frameworks/test/unittest/shell_command_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..3a1683fb433c63d4151184e716081bf4635b56de --- /dev/null +++ b/packing_tool/frameworks/test/unittest/shell_command_test/BUILD.gn @@ -0,0 +1,79 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("shell_command_test_config") { + include_dirs = [ + "../../../include", + "../../../include/json", + "../../../../../../../third_party/json/include", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("shell_command_test") { + module_out_path = module_output_path + public_configs = [ ":shell_command_test_config" ] + sources = [ + "../../../src/app_packager.cpp", + "../../../src/appqf_packager.cpp", + "../../../src/fast_app_packager.cpp", + "../../../src/hap_packager.cpp", + "../../../src/hqf_packager.cpp", + "../../../src/hqf_verify.cpp", + "../../../src/hsp_packager.cpp", + "../../../src/json/distro_filter.cpp", + "../../../src/json/hap_verify_info.cpp", + "../../../src/json/hap_verify_utils.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/module_json_utils.cpp", + "../../../src/json/normalize_version_utils.cpp", + "../../../src/json/pack_info.cpp", + "../../../src/json/pack_info_utils.cpp", + "../../../src/json/patch_json.cpp", + "../../../src/json/patch_json_utils.cpp", + "../../../src/json/pt_json.cpp", + "../../../src/log.cpp", + "../../../src/multiapp_packager.cpp", + "../../../src/package_normalize.cpp", + "../../../src/packager.cpp", + "../../../src/shell_command.cpp", + "../../../src/unzip_wrapper.cpp", + "../../../src/utils.cpp", + "../../../src/version_normalize.cpp", + "../../../src/zip_utils.cpp", + "../../../src/zip_wrapper.cpp", + "shell_command_test.cpp", + ] + external_deps = [ + "bounds_checking_function:libsec_static", + "cJSON:cjson_static", + "hilog:libhilog", + "openssl:libcrypto_shared", + "zlib:libz", + ] +} + +group("unittest") { + testonly = true + deps = [ ":shell_command_test" ] +} diff --git a/packing_tool/frameworks/test/unittest/shell_command_test/shell_command_test.cpp b/packing_tool/frameworks/test/unittest/shell_command_test/shell_command_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..710d4f1c2d617900f596b0cef6c813eea247d1fa --- /dev/null +++ b/packing_tool/frameworks/test/unittest/shell_command_test/shell_command_test.cpp @@ -0,0 +1,228 @@ +/* + * 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. + */ + +#include + +#include +#include "constants.h" +#include "zip_constants.h" +#define private public +#define protected public +#include "packager.h" +#include "shell_command.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +class ShellCommandTest : public testing::Test { +public: + ShellCommandTest() {} + virtual ~ShellCommandTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void ShellCommandTest::SetUpTestCase() {} + +void ShellCommandTest::TearDownTestCase() {} + +void ShellCommandTest::SetUp() {} + +void ShellCommandTest::TearDown() {} + +/* + * @tc.name: CreateCommandMap_0100 + * @tc.desc: CreateCommandMap. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ShellCommandTest, CreateCommandMap_0100, Function | MediumTest | Level1) +{ + int argc = 2; + const char *argv[] = { + "ohos_packing_tool", + "pack", + }; + + OHOS::AppPackingTool::ShellCommand shellcmd(argc, const_cast(argv), OHOS::AppPackingTool::TOOL_NAME); + int ret = shellcmd.CreateCommandMap(); + EXPECT_EQ(ret, 0); +} + +/* + * @tc.name: getPackager_0200 + * @tc.desc: getPackager. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ShellCommandTest, getPackager_0200, Function | MediumTest | Level1) +{ + int argc = 16; + const char *argv[] = { + "ohos_packing_tool", + "pack", + "--mode", + "hap", + "--json-path", + "/data/testunpack/test_hqf_unpacking/patch.json", + "--lib-path", + "/data/testunpack/test_hqf_unpacking/libs", + "--resources-path", + "/data/testunpack/test_hqf_unpacking/resources", + "--ets-pat", + "/data/testunpack/test_hqf_unpacking/ets", + "--out-path", + "/data/hqfpacking/test_1.hqf", + "--force", + "true", + }; + + OHOS::AppPackingTool::ShellCommand shellcmd(argc, const_cast(argv), OHOS::AppPackingTool::TOOL_NAME); + int ret = shellcmd.ParseParam(); + EXPECT_EQ(ret, 0); + std::unique_ptr packager = shellcmd.getPackager(); + EXPECT_TRUE(packager != nullptr); + shellcmd.parameterMap_[OHOS::AppPackingTool::Constants::PARAM_MODE] = "hsp"; + std::unique_ptr packager2 = shellcmd.getPackager(); + EXPECT_TRUE(packager2 != nullptr); + shellcmd.parameterMap_[OHOS::AppPackingTool::Constants::PARAM_MODE] = ""; + std::unique_ptr packager3 = shellcmd.getPackager(); + EXPECT_TRUE(packager3 == nullptr); +} + +/* + * @tc.name: OnCommand_0300 + * @tc.desc: OnCommand. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ShellCommandTest, OnCommand_0300, Function | MediumTest | Level1) +{ + int argc = 2; + const char *argv[] = { + "ohos_packing_tool", + "help", + }; + + OHOS::AppPackingTool::ShellCommand shellcmd(argc, const_cast(argv), OHOS::AppPackingTool::TOOL_NAME); + int ret = shellcmd.CreateCommandMap(); + EXPECT_EQ(ret, 0); + ret = shellcmd.OnCommand(); + EXPECT_EQ(ret, 0); +} + +/* + * @tc.name: ExecCommand_0400 + * @tc.desc: ExecCommand. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ShellCommandTest, ExecCommand_0400, Function | MediumTest | Level1) +{ + int argc = 16; + const char *argv[] = { + "ohos_packing_tool", + "pack", + "--mode", + "hqf", + "--json-path", + "/data/testunpack/test_hqf_unpacking/patch.json", + "--lib-path", + "/data/testunpack/test_hqf_unpacking/libs", + "--resources-path", + "/data/testunpack/test_hqf_unpacking/resources", + "--ets-pat", + "/data/testunpack/test_hqf_unpacking/ets", + "--out-path", + "/data/hqfpacking/test_1.hqf", + "--force", + "true", + }; + + OHOS::AppPackingTool::ShellCommand shellcmd(argc, const_cast(argv), OHOS::AppPackingTool::TOOL_NAME); + std::string resultReceiver = shellcmd.ExecCommand(); + EXPECT_FALSE(resultReceiver.empty()); +} + +/* + * @tc.name: RunAsHelpCommand_0500 + * @tc.desc: RunAsHelpCommand. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ShellCommandTest, RunAsHelpCommand_0500, Function | MediumTest | Level1) +{ + int argc = 4; + const char *argv[] = { + "ohos_packing_tool", + "pack", + "--mode", + "hqf", + }; + + OHOS::AppPackingTool::ShellCommand shellcmd(argc, const_cast(argv), OHOS::AppPackingTool::TOOL_NAME); + EXPECT_EQ(shellcmd.RunAsHelpCommand(), 0); +} + +/* + * @tc.name: RunAsPackCommand_0600 + * @tc.desc: RunAsPackCommand. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ShellCommandTest, RunAsPackCommand_0600, Function | MediumTest | Level1) +{ + int argc = 4; + const char *argv[] = { + "ohos_packing_tool", + "pack", + "--mode", + "hqf", + }; + + OHOS::AppPackingTool::ShellCommand shellcmd(argc, const_cast(argv), OHOS::AppPackingTool::TOOL_NAME); + EXPECT_EQ(shellcmd.RunAsPackCommand(), 0); +} + +/* + * @tc.name: RunAsUnpackCommand_0700 + * @tc.desc: RunAsUnpackCommand. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ShellCommandTest, RunAsUnpackCommand_0700, Function | MediumTest | Level1) +{ + int argc = 4; + const char *argv[] = { + "ohos_packing_tool", + "pack", + "--mode", + "hqf", + }; + + OHOS::AppPackingTool::ShellCommand shellcmd(argc, const_cast(argv), OHOS::AppPackingTool::TOOL_NAME); + EXPECT_EQ(shellcmd.RunAsUnpackCommand(), 0); +} +} // namespace OHOS \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/unzip_wrapper_test/BUILD.gn b/packing_tool/frameworks/test/unittest/unzip_wrapper_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..df158da11299b2c328c1c3530796d606be1c5846 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/unzip_wrapper_test/BUILD.gn @@ -0,0 +1,50 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("unzip_wrapper_test_config") { + include_dirs = [ + "../../../include", + "../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("unzip_wrapper_test") { + module_out_path = module_output_path + public_configs = [ ":unzip_wrapper_test_config" ] + sources = [ + "../../../src/log.cpp", + "../../../src/unzip_wrapper.cpp", + "../../../src/zip_wrapper.cpp", + "unzip_wrapper_test.cpp", + ] + external_deps = [ + "bounds_checking_function:libsec_static", + "cJSON:cjson_static", + "hilog:libhilog", + "openssl:libcrypto_shared", + "zlib:libz", + ] +} + +group("unittest") { + testonly = true + deps = [ ":unzip_wrapper_test" ] +} diff --git a/packing_tool/frameworks/test/unittest/unzip_wrapper_test/unzip_wrapper_test.cpp b/packing_tool/frameworks/test/unittest/unzip_wrapper_test/unzip_wrapper_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a9476d18dfc375293ed06cd1397f98a98b0b0892 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/unzip_wrapper_test/unzip_wrapper_test.cpp @@ -0,0 +1,120 @@ +/* + * 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. + */ + +#include + +#include +#include "constants.h" +#define private public +#define protected public +#include "zip_wrapper.h" +#include "unzip_wrapper.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +#define OUT_PATH "/data/test_1.hqf" +#define FILE_PATH "/data/unzip_wrapper_test" +#define TEMP_PATH "/data/temp" + +class UnzipWrapperTest : public testing::Test { +public: + UnzipWrapperTest() {} + virtual ~UnzipWrapperTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void UnzipWrapperTest::SetUpTestCase() {} + +void UnzipWrapperTest::TearDownTestCase() {} + +void UnzipWrapperTest::SetUp() {} + +void UnzipWrapperTest::TearDown() {} + +/* + * @tc.name: Open_0100 + * @tc.desc: Open. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UnzipWrapperTest, Open_0100, Function | MediumTest | Level1) +{ + std::string path(OUT_PATH); + std::string filepath(FILE_PATH); + OHOS::AppPackingTool::ZipWrapper zipWrapper(path); + + zipWrapper.Open(APPEND_STATUS_CREATE); + int ret = zipWrapper.AddFileOrDirectoryToZip(filepath, OHOS::AppPackingTool::Constants::PARAM_ETS_PATH); + EXPECT_EQ(ret, 0); + zipWrapper.Close(); + + OHOS::AppPackingTool::UnzipWrapper unzipWrapper; + unzipWrapper.Open(path); + EXPECT_TRUE(unzipWrapper.IsOpen()); + + unzipWrapper.Close(); +} + +/* + * @tc.name: Open_0200 + * @tc.desc: Open. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UnzipWrapperTest, Open_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::UnzipWrapper unzipWrapper(OUT_PATH); + unzipWrapper.Open(); + EXPECT_TRUE(unzipWrapper.IsOpen()); + + unzipWrapper.Close(); +} + +/* + * @tc.name: UnzipFile_0300 + * @tc.desc: UnzipFile. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UnzipWrapperTest, UnzipFile_0300, Function | MediumTest | Level1) +{ + std::string filepath(TEMP_PATH); + OHOS::AppPackingTool::UnzipWrapper unzipWrapper(OUT_PATH); + unzipWrapper.Open(); + int ret = unzipWrapper.UnzipFile(TEMP_PATH); + EXPECT_EQ(ret, 0); + + unzipWrapper.Close(); + + std::string cmd("rm -rf "); + cmd += TEMP_PATH; + system(cmd.c_str()); + std::string cmd2("rm -rf "); + cmd2 += OUT_PATH; + system(cmd2.c_str()); +} +} // namespace OHOS \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/utils_Test/BUILD.gn b/packing_tool/frameworks/test/unittest/utils_Test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..364a98d7621ec5b3f3464b1275f6be2816acd671 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/utils_Test/BUILD.gn @@ -0,0 +1,49 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("utils_Test_config") { + include_dirs = [ + "../../../include", + "../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("utils_Test") { + module_out_path = module_output_path + public_configs = [ ":utils_Test_config" ] + sources = [ + "../../../src/log.cpp", + "../../../src/utils.cpp", + "utils_test.cpp", + ] + external_deps = [ + "bounds_checking_function:libsec_static", + "cJSON:cjson_static", + "hilog:libhilog", + "openssl:libcrypto_shared", + "zlib:libz", + ] +} + +group("unittest") { + testonly = true + deps = [ ":utils_Test" ] +} diff --git a/packing_tool/frameworks/test/unittest/utils_Test/utils_test.cpp b/packing_tool/frameworks/test/unittest/utils_Test/utils_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..22b9f67212cde3dd2104b29ee427e6920e3c439c --- /dev/null +++ b/packing_tool/frameworks/test/unittest/utils_Test/utils_test.cpp @@ -0,0 +1,469 @@ +/* + * 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. + */ + +#include + +#include +#include "constants.h" +#define private public +#define protected public +#include "utils.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +#define FILE_PATH "/data/test/resource/packingtool/utils_Test/" +#define FILE_NAME "module.json" +#define TEMP_PATH "/data/test/resource/packingtool/utils_Test/temp/" + +class UtilsTest : public testing::Test { +public: + UtilsTest() {} + virtual ~UtilsTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); + + bool CheckFilePath(const std::string& filePath); + + void CreateFilePath(const std::string& filePath); + + void CreateFile(const std::string& filePath); + + void DeleteFilePath(const std::string& filePath); +}; + +void UtilsTest::SetUpTestCase() {} + +void UtilsTest::TearDownTestCase() {} + +void UtilsTest::SetUp() +{ + CreateFilePath(TEMP_PATH); + + std::string filePath = std::string(FILE_PATH) + std::string(FILE_NAME); + CreateFile(filePath); +} + +void UtilsTest::TearDown() {} + +bool UtilsTest::CheckFilePath(const std::string& filePath) +{ + std::string prefix = "/data/test/"; + if (filePath.empty()) { + return false; + } + if (filePath.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), filePath.begin())) { + return true; + } + return false; +} + +void UtilsTest::CreateFilePath(const std::string& filePath) +{ + if (!CheckFilePath(filePath)) { + return; + } + std::string cmdStr = std::string("mkdir -p ") + filePath; + system(cmdStr.c_str()); +} + +void UtilsTest::CreateFile(const std::string& filePath) +{ + if (!CheckFilePath(filePath)) { + return; + } + std::string cmdStr = std::string("touch ") + filePath; + system(cmdStr.c_str()); + cmdStr = std::string("echo \"{\\\"name\\\": \\\"packing_tool\\\"}\" > ") + filePath; + system(cmdStr.c_str()); +} + +void UtilsTest::DeleteFilePath(const std::string& filePath) +{ + if (!CheckFilePath(filePath)) { + return; + } + std::string cmdStr = std::string("rm -rf ") + filePath; + system(cmdStr.c_str()); +} + +/* + * @tc.name: GetFileContent_0100 + * @tc.desc: GetFileContent. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, GetFileContent_0100, Function | MediumTest | Level1) +{ + std::string filePath = std::string(FILE_PATH) + std::string(FILE_NAME); + std::string content = OHOS::AppPackingTool::Utils::GetFileContent(filePath); + EXPECT_TRUE(!content.empty()); +} + +/* + * @tc.name: ListToString_0100 + * @tc.desc: ListToString. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, ListToString_0100, Function | MediumTest | Level1) +{ + std::list lst = { + "aaaaaaa", + "bbbbbbb", + "ccccccc" + }; + + std::string str = OHOS::AppPackingTool::Utils::ListToString(lst); + EXPECT_TRUE(!str.empty()); +} + +/* + * @tc.name: ReplaceAll_0200 + * @tc.desc: ReplaceAll. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, ReplaceAll_0200, Function | MediumTest | Level1) +{ + std::string str = {"1234567890"}; + std::string from = {"456"}; + std::string to = {"AAA"}; + str = OHOS::AppPackingTool::Utils::ReplaceAll(str, from, to); + EXPECT_NE(str.find(to), 0); +} + +/* + * @tc.name: GetFileLength_0300 + * @tc.desc: GetFileLength. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, GetFileLength_0300, Function | MediumTest | Level1) +{ + int64_t len = OHOS::AppPackingTool::Utils::GetFileLength(FILE_PATH); + EXPECT_NE(len, 0); +} + +/* + * @tc.name: EndsWith_0400 + * @tc.desc: EndsWith. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, EndsWith_0400, Function | MediumTest | Level1) +{ + std::string str = {"test.txt"}; + std::string suffix = {".txt"}; + EXPECT_TRUE(OHOS::AppPackingTool::Utils::EndsWith(str, suffix)); +} + +/* + * @tc.name: CheckDisjoint_0500 + * @tc.desc: CheckDisjoint. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, CheckDisjoint_0500, Function | MediumTest | Level1) +{ + std::list list1 = {"111111", "2222222"}; + std::list list2 = {"3333333", "4444444"}; + EXPECT_TRUE(OHOS::AppPackingTool::Utils::CheckDisjoint(list1, list2)); +} + +/* + * @tc.name: CheckContainsAll_0600 + * @tc.desc: CheckContainsAll. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, CheckContainsAll_0600, Function | MediumTest | Level1) +{ + std::list list1 = {"111111", "2222222", "3333333", "4444444"}; + std::list list2 = {"111111", "2222222"}; + EXPECT_TRUE(OHOS::AppPackingTool::Utils::CheckContainsAll(list1, list2)); +} + +/* + * @tc.name: GetSha256Str_0700 + * @tc.desc: GetSha256Str. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, GetSha256Str_0700, Function | MediumTest | Level1) +{ + std::string str = {"1111112222222"}; + EXPECT_TRUE(!OHOS::AppPackingTool::Utils::GetSha256Str(str).empty()); +} + +/* + * @tc.name: GetSha256File_0800 + * @tc.desc: GetSha256File. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, GetSha256File_0800, Function | MediumTest | Level1) +{ + std::string filePath = std::string(FILE_PATH) + std::string(FILE_NAME); + EXPECT_TRUE(!OHOS::AppPackingTool::Utils::GetSha256File(filePath).empty()); +} + +/* + * @tc.name: IsFileExists_0900 + * @tc.desc: IsFileExists. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, IsFileExists_0900, Function | MediumTest | Level1) +{ + std::string filePath = std::string(FILE_PATH) + std::string(FILE_NAME); + EXPECT_TRUE(OHOS::AppPackingTool::Utils::IsFileExists(filePath)); +} + +/* + * @tc.name: IsFile_1000 + * @tc.desc: IsFile. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, IsFile_1000, Function | MediumTest | Level1) +{ + std::string filePath = std::string(FILE_PATH) + std::string(FILE_NAME); + EXPECT_TRUE(OHOS::AppPackingTool::Utils::IsFile(filePath)); +} + +/* + * @tc.name: IsDirectory_1100 + * @tc.desc: IsDirectory. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, IsDirectory_1100, Function | MediumTest | Level1) +{ + EXPECT_TRUE(OHOS::AppPackingTool::Utils::IsDirectory(TEMP_PATH)); +} + +/* + * @tc.name: RemoveFile_1200 + * @tc.desc: RemoveFile. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, RemoveFile_1200, Function | MediumTest | Level1) +{ + system("touch patch.json"); + std::string file("patch.json"); + EXPECT_TRUE(OHOS::AppPackingTool::Utils::RemoveFile(file)); +} + +/* + * @tc.name: RemoveDirectory_1300 + * @tc.desc: RemoveDirectory. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, RemoveDirectory_1300, Function | MediumTest | Level1) +{ + system("mkdir tempdir"); + std::string path("tempdir"); + EXPECT_TRUE(OHOS::AppPackingTool::Utils::RemoveDirectory(path)); +} + +/* + * @tc.name: GetFilePathByDir_1400 + * @tc.desc: GetFilePathByDir. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, GetFilePathByDir_1400, Function | MediumTest | Level1) +{ + std::string path("tempdir"); + std::string file("testfile"); + std::string filePath("tempdir/testfile"); + std::string temp = OHOS::AppPackingTool::Utils::GetFilePathByDir(path, file); + EXPECT_EQ(temp.compare(filePath), 0); +} + +/* + * @tc.name: ForceCreateDirectory_1500 + * @tc.desc: ForceCreateDirectory. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, ForceCreateDirectory_1500, Function | MediumTest | Level1) +{ + std::string path("tempdir"); + EXPECT_TRUE(OHOS::AppPackingTool::Utils::ForceCreateDirectory(path)); +} + +/* + * @tc.name: ForceRemoveDirectory_1600 + * @tc.desc: ForceRemoveDirectory. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, ForceRemoveDirectory_1600, Function | MediumTest | Level1) +{ + std::string path("tempdir"); + EXPECT_TRUE(OHOS::AppPackingTool::Utils::ForceCreateDirectory(path)); + + EXPECT_TRUE(OHOS::AppPackingTool::Utils::ForceRemoveDirectory(path)); +} + +/* + * @tc.name: CopyListToSet_1700 + * @tc.desc: CopyListToSet. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, CopyListToSet_1700, Function | MediumTest | Level1) +{ + std::list lst; + lst.push_front("test"); + std::set st; + OHOS::AppPackingTool::Utils::CopyListToSet(lst, st); + auto it = st.find("test"); + EXPECT_TRUE(it != st.end()); +} + +/* + * @tc.name: CheckListContain_1800 + * @tc.desc: CheckListContain. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, CheckListContain_1800, Function | MediumTest | Level1) +{ + std::string value("test"); + std::list lst; + lst.push_front(value.c_str()); + + EXPECT_TRUE(OHOS::AppPackingTool::Utils::CheckListContain(lst, std::string(value))); +} + +/* + * @tc.name: GetListDistinctCount_1900 + * @tc.desc: GetListDistinctCount. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, GetListDistinctCount_1900, Function | MediumTest | Level1) +{ + std::string value("test"); + std::list lst; + lst.push_front(value.c_str()); + + EXPECT_EQ(OHOS::AppPackingTool::Utils::GetListDistinctCount(lst), 1); +} + +/* + * @tc.name: GetCeilFileSize_2000 + * @tc.desc: GetCeilFileSize. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, GetCeilFileSize_2000, Function | MediumTest | Level1) +{ + long fileSize = 12 * 1024 * 1014L; + int sizeLimit = 12; + + EXPECT_TRUE(OHOS::AppPackingTool::Utils::GetCeilFileSize(fileSize, sizeLimit) < 12); +} + +/* + * @tc.name: IsPositiveInteger_2100 + * @tc.desc: IsPositiveInteger. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, IsPositiveInteger_2100, Function | MediumTest | Level1) +{ + EXPECT_TRUE(OHOS::AppPackingTool::Utils::IsPositiveInteger(std::string("123"), 0, 200)); +} + +/* + * @tc.name: CheckFileName_2200 + * @tc.desc: CheckFileName. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, CheckFileName_2200, Function | MediumTest | Level1) +{ + std::string filePath = std::string(FILE_PATH) + std::string(FILE_NAME); + EXPECT_TRUE(OHOS::AppPackingTool::Utils::CheckFileName(filePath, FILE_NAME)); +} + +/* + * @tc.name: CheckFileSuffix_2300 + * @tc.desc: CheckFileSuffix. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, CheckFileSuffix_2300, Function | MediumTest | Level1) +{ + std::string filePath = std::string(FILE_PATH) + std::string(FILE_NAME); + std::string suffix("json"); + EXPECT_TRUE(OHOS::AppPackingTool::Utils::CheckFileSuffix(filePath, suffix)); +} + +/* + * @tc.name: GenerateUUID_2400 + * @tc.desc: GenerateUUID. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, GenerateUUID_2400, Function | MediumTest | Level1) +{ + std::string id = OHOS::AppPackingTool::Utils::GenerateUUID(); + EXPECT_TRUE(!id.empty()); +} + +/* + * @tc.name: CopyFile_2500 + * @tc.desc: CopyFile. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, CopyFile_2500, Function | MediumTest | Level1) +{ + std::string srcPath = std::string(FILE_PATH) + std::string(FILE_NAME); + std::string dstPath = std::string(FILE_PATH) + std::string("dstFile"); + EXPECT_TRUE(OHOS::AppPackingTool::Utils::CopyFile(srcPath, dstPath)); + DeleteFilePath(dstPath); +} + +/* + * @tc.name: GetFormattedPath_2600 + * @tc.desc: GetFormattedPath. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(UtilsTest, GetFormattedPath_2600, Function | MediumTest | Level1) +{ + std::string path(FILE_PATH); + std::string formattedPath; + EXPECT_TRUE(OHOS::AppPackingTool::Utils::GetFormattedPath(path, formattedPath)); +} +} // namespace OHOS diff --git a/packing_tool/frameworks/test/unittest/version_normalize_test/BUILD.gn b/packing_tool/frameworks/test/unittest/version_normalize_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..03ea97396fd02cb98721df283c90511d95b7b687 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/version_normalize_test/BUILD.gn @@ -0,0 +1,75 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("version_normalize_test_config") { + include_dirs = [ + "../../../include", + "../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("version_normalize_test") { + module_out_path = module_output_path + public_configs = [ ":version_normalize_test_config" ] + sources = [ + "../../../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/version_normalize.cpp", + "../../../src/zip_utils.cpp", + "../../../src/zip_wrapper.cpp", + "version_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 = [ ":version_normalize_test" ] +} + +ohos_copy("copy_test_file") { + subsystem_name = "developtools" + part_name = "packing_tool" + sources = [ "./version_normalize_file" ] + outputs = [ "$root_out_dir/tests/unittest/developtools/packing_tool/test_file/version_normalize_file/" ] +} diff --git a/packing_tool/frameworks/test/unittest/version_normalize_test/version_normalize_file/fa/assets_jsbundle/default/js/MainAbility/app.js b/packing_tool/frameworks/test/unittest/version_normalize_test/version_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/version_normalize_test/version_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/version_normalize_test/version_normalize_file/fa/assets_jsbundle/default/js/MainAbility/app.js.map b/packing_tool/frameworks/test/unittest/version_normalize_test/version_normalize_file/fa/assets_jsbundle/default/js/MainAbility/app.js.map new file mode 100644 index 0000000000000000000000000000000000000000..4166a633646ff1cc6eba0a0b96c27387984b7f11 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/version_normalize_test/version_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":";;;;;AAAA,CAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAK,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,WAAc,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAEhC,CAAe,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;IACb,QAAQ,CAAA,CAAA,CAAA,CAAA,CAAA;QACN,CAAK,CAAA,CAAA,CAAA,CAAA,CAAC,CAAI,CAAA,CAAA,CAAA,CAAC,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAE,CAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAE,CAAY,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAE,CAAsB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAC,CAAC,CAAA;CACrE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;IACD,SAAS,CAAA,CAAA,CAAA,CAAA,CAAA;QACP,CAAK,CAAA,CAAA,CAAA,CAAA,CAAC,CAAI,CAAA,CAAA,CAAA,CAAC,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAE,CAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAE,CAAY,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAE,CAAuB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAC,CAAC,CAAA;CACtE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;CACH,CAAA;;"} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/version_normalize_test/version_normalize_file/fa/assets_jsbundle/default/js/MainAbility/manifest.json b/packing_tool/frameworks/test/unittest/version_normalize_test/version_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/version_normalize_test/version_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/version_normalize_test/version_normalize_file/fa/assets_jsbundle/default/js/MainAbility/pages/index.js b/packing_tool/frameworks/test/unittest/version_normalize_test/version_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/version_normalize_test/version_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/version_normalize_test/version_normalize_file/fa/assets_jsbundle/default/js/MainAbility/pages/index.js.map b/packing_tool/frameworks/test/unittest/version_normalize_test/version_normalize_file/fa/assets_jsbundle/default/js/MainAbility/pages/index.js.map new file mode 100644 index 0000000000000000000000000000000000000000..d77a1f9f0e7a7175944fb7688f1920846c92a7d8 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/version_normalize_test/version_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":";;;;CAEO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAK,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAFZ,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;sDAG2B,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAa,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;AAHxC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;;;;;;;;;;;;;;;QAGS,OAAO,CAAA,CAAA,CAAA,CAAA,CAAA;;;KAAP,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;;AAEd,CAAA,CAAA,CAAA,CAAA,aAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;;YACE,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;YAAH,GAAG,CAQF,CAAA,CAAA,CAAA,CAAA,CAAA,CAAM,CAAC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAM,CAAA,CAAA,CAAA;;gBARd,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;;;;;YACD,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;YAAN,MAAM,CAKL,CAAA,CAAA,CAAA,CAAA,CAAK,CAAC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAM,CAAA,CAAA,CAAA;;gBALb,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;;;;;CACJ,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAC,IAAI,CAAC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAA,CAAA,CAAA;YAAjB,IAAI,CACD,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAQ,CAAC,CAAA,CAAE,CAAA,CAAA,CAAA;AADd,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAI,CAED,CAAU,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAC,UAAU,CAAC,CAAA,CAAA,CAAA,CAAI,CAAA,CAAA,CAAA;;gBAF7B,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;;;QAAJ,CAAI,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;QADN,CAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;QADR,CAAG,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AASJ,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;;;;;;;"} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/version_normalize_test/version_normalize_file/fa/config.json b/packing_tool/frameworks/test/unittest/version_normalize_test/version_normalize_file/fa/config.json new file mode 100644 index 0000000000000000000000000000000000000000..58e4106a4528142de32592f85f2259cbc12cda7e --- /dev/null +++ b/packing_tool/frameworks/test/unittest/version_normalize_test/version_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/version_normalize_test/version_normalize_file/fa/pack.json b/packing_tool/frameworks/test/unittest/version_normalize_test/version_normalize_file/fa/pack.json new file mode 100644 index 0000000000000000000000000000000000000000..04870b2ba492f9ca56d31efaa15f4974c9926d1a --- /dev/null +++ b/packing_tool/frameworks/test/unittest/version_normalize_test/version_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/version_normalize_test/version_normalize_file/stage/ets/sourceMaps.map b/packing_tool/frameworks/test/unittest/version_normalize_test/version_normalize_file/stage/ets/sourceMaps.map new file mode 100644 index 0000000000000000000000000000000000000000..027a060231c8f4b58efeb820e33c187d4cd565e8 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/version_normalize_test/version_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;AACA;AAGA;;;;;;;AASE;;;;;AAMM;;AAED;AACD;AACF;;;;;;;;;;;;;;AAiBH;" + }, + "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;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;AAKE;;;;;;;;;;;;AAGM;;;;;AAOL;;;;;;;;;" + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/version_normalize_test/version_normalize_file/stage/module.json b/packing_tool/frameworks/test/unittest/version_normalize_test/version_normalize_file/stage/module.json new file mode 100644 index 0000000000000000000000000000000000000000..5427967a52f1b8cf4f641a56402cd3b39e8453ef --- /dev/null +++ b/packing_tool/frameworks/test/unittest/version_normalize_test/version_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/version_normalize_test/version_normalize_file/stage/pack.json b/packing_tool/frameworks/test/unittest/version_normalize_test/version_normalize_file/stage/pack.json new file mode 100644 index 0000000000000000000000000000000000000000..b221fd946883c1f06110607139ff2d23ebc7d39d --- /dev/null +++ b/packing_tool/frameworks/test/unittest/version_normalize_test/version_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/version_normalize_test/version_normalize_file/stage/resources/base/profile/main_pages.json b/packing_tool/frameworks/test/unittest/version_normalize_test/version_normalize_file/stage/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..1898d94f58d6128ab712be2c68acc7c98e9ab9ce --- /dev/null +++ b/packing_tool/frameworks/test/unittest/version_normalize_test/version_normalize_file/stage/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/packing_tool/frameworks/test/unittest/version_normalize_test/version_normalize_test.cpp b/packing_tool/frameworks/test/unittest/version_normalize_test/version_normalize_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9c0d5ade1b1a44e3f949a015a33321be464537a9 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/version_normalize_test/version_normalize_test.cpp @@ -0,0 +1,231 @@ +/* + * 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. + */ + +#include + +#include +#include "constants.h" +#define private public +#define protected public +#include "version_normalize.h" +#include "hap_packager.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +#define HAP_OUT_PATH "/data/test/entry-default-unsigned.hap" +#define INPUT_LIST "/data/test/entry-default-unsigned.hap" +#define VERSION_CODE "9999999" +#define VERSION_NAME "30.11.22" +#define OUT_PATH "/data/test/packagenormalize_packing" +#define STAGE_INDEX_PATH "/data/test/resource/packingtool/test_file/stage/resources.index" +#define STAGE_PACK_INFO_PATH "/data/test/resource/packingtool/test_file/stage/pack.info" +#define STAGE_ETS_PATH "/data/test/resource/packingtool/test_file/stage/ets" +#define STAGE_RESOURCES_PATH "/data/test/resource/packingtool/test_file/stage/resources" +#define STAGE_JSON_PATH "/data/test/resource/packingtool/test_file/stage/module.json" +#define STAGE_RPCID_PATH "/data/test/resource/packingtool/test_file/stage/rpcid.sc" +class VersionNormalizeTest : public testing::Test { +public: + VersionNormalizeTest() {} + virtual ~VersionNormalizeTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void VersionNormalizeTest::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/ets"); + system("rm -f /data/test/resource/packingtool/test_file/stage/resources.index"); +} + +void VersionNormalizeTest::TearDownTestCase() +{ + std::string cmd = {"rm -f /data/test/packagenormalize_packing/*"}; + system(cmd.c_str()); +} + +void VersionNormalizeTest::SetUp() {} + +void VersionNormalizeTest::TearDown() {} + +/* + * @tc.name: VersionNormalize_0100 + * @tc.desc: VersionNormalize_0100. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(VersionNormalizeTest, VersionNormalize_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, 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}, + }; + + OHOS::AppPackingTool::VersionNormalize versionNormalize(parameterMap, resultReceiver); + EXPECT_EQ(versionNormalize.PreProcess(), 0); + EXPECT_EQ(versionNormalize.Process(), 0); +} + +/* + * @tc.name: PreProcess_0100 + * @tc.desc: input-list is empty. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(VersionNormalizeTest, PreProcess_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_NAME, VERSION_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + }; + + OHOS::AppPackingTool::VersionNormalize versionNormalize(parameterMap, resultReceiver); + EXPECT_EQ(versionNormalize.PreProcess(), 1); +} + +/* + * @tc.name: PreProcess_0200 + * @tc.desc: input-list is invalid. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(VersionNormalizeTest, PreProcess_0200, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, + "/data/test/resource/packingtool/test_file/thumbnailTest2err.hap"}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_NAME, VERSION_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + }; + + OHOS::AppPackingTool::VersionNormalize versionNormalize(parameterMap, resultReceiver); + EXPECT_EQ(versionNormalize.PreProcess(), 1); +} + + +/* + * @tc.name: PreProcess_0300 + * @tc.desc: version-name is empty. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(VersionNormalizeTest, PreProcess_0300, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, INPUT_LIST}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + }; + OHOS::AppPackingTool::VersionNormalize versionNormalize(parameterMap, resultReceiver); + EXPECT_EQ(versionNormalize.PreProcess(), 1); +} + +/* + * @tc.name: PreProcess_0400 + * @tc.desc: version-name is not valid. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(VersionNormalizeTest, PreProcess_0400, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, INPUT_LIST}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_NAME, "aabbc"}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + }; + OHOS::AppPackingTool::VersionNormalize versionNormalize(parameterMap, resultReceiver); + EXPECT_EQ(versionNormalize.PreProcess(), 1); +} + + +/* + * @tc.name: PreProcess_0500 + * @tc.desc: version-code is empty. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(VersionNormalizeTest, PreProcess_0500, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, INPUT_LIST}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_NAME, VERSION_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + }; + + OHOS::AppPackingTool::VersionNormalize versionNormalize(parameterMap, resultReceiver); + EXPECT_EQ(versionNormalize.PreProcess(), 1); +} + +/* + * @tc.name: PreProcess_0600 + * @tc.desc: version-code is invalid. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(VersionNormalizeTest, PreProcess_0600, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, INPUT_LIST}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, "-123456"}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_NAME, VERSION_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + }; + + OHOS::AppPackingTool::VersionNormalize versionNormalize(parameterMap, resultReceiver); + EXPECT_EQ(versionNormalize.PreProcess(), 1); +} +} // namespace OHOS \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/zip_utils_test/BUILD.gn b/packing_tool/frameworks/test/unittest/zip_utils_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..eb81608c7669f1014dbbac2eef65d5d764c8c721 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/zip_utils_test/BUILD.gn @@ -0,0 +1,52 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("zip_utils_test_config") { + include_dirs = [ + "../../../include", + "../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("zip_utils_test") { + module_out_path = module_output_path + public_configs = [ ":zip_utils_test_config" ] + sources = [ + "../../../src/log.cpp", + "../../../src/unzip_wrapper.cpp", + "../../../src/utils.cpp", + "../../../src/zip_utils.cpp", + "../../../src/zip_wrapper.cpp", + "zip_utils_test.cpp", + ] + external_deps = [ + "bounds_checking_function:libsec_static", + "cJSON:cjson_static", + "hilog:libhilog", + "openssl:libcrypto_shared", + "zlib:libz", + ] +} + +group("unittest") { + testonly = true + deps = [ ":zip_utils_test" ] +} diff --git a/packing_tool/frameworks/test/unittest/zip_utils_test/zip_utils_test.cpp b/packing_tool/frameworks/test/unittest/zip_utils_test/zip_utils_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3f52c4a71c40c0d92e1e435168fc5321370b668e --- /dev/null +++ b/packing_tool/frameworks/test/unittest/zip_utils_test/zip_utils_test.cpp @@ -0,0 +1,286 @@ +/* + * 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. + */ + +#include + +#include +#include "constants.h" +#include "zip_constants.h" +#define private public +#define protected public +#include "utils.h" +#include "unzip_wrapper.h" +#include "zip_wrapper.h" +#include "zip_utils.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +#define OUT_PATH "/data/test/zip_utils_test.hqf" +#define FILE_PATH "/data/test/resource/packingtool/zip_utils_test/" +#define FILE_NAME "module.json" +#define TEMP_PATH "/data/test/resource/packingtool/" + +class ZipUtilsTest : public testing::Test { +public: + ZipUtilsTest() {} + virtual ~ZipUtilsTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); + + bool CheckFilePath(const std::string& filePath); + + void CreateFilePath(const std::string& filePath); + + void CreateFile(const std::string& filePath); + + void DeleteFilePath(const std::string& filePath); +}; + +void ZipUtilsTest::SetUpTestCase() {} + +void ZipUtilsTest::TearDownTestCase() {} + +void ZipUtilsTest::SetUp() +{ + CreateFilePath(FILE_PATH); + + std::string filePath = std::string(FILE_PATH) + std::string(FILE_NAME); + CreateFile(filePath); +} + +void ZipUtilsTest::TearDown() {} + +bool ZipUtilsTest::CheckFilePath(const std::string& filePath) +{ + std::string prefix = "/data/test/"; + if (filePath.empty()) { + return false; + } + if (filePath.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), filePath.begin())) { + return true; + } + return false; +} + +void ZipUtilsTest::CreateFilePath(const std::string& filePath) +{ + if (!CheckFilePath(filePath)) { + return; + } + std::string cmdStr = std::string("mkdir -p ") + filePath; + system(cmdStr.c_str()); +} + +void ZipUtilsTest::CreateFile(const std::string& filePath) +{ + if (!CheckFilePath(filePath)) { + return; + } + std::string cmdStr = std::string("touch ") + filePath; + system(cmdStr.c_str()); + cmdStr = std::string("echo \"{\\\"name\\\": \\\"packing_tool\\\"}\" > ") + filePath; + system(cmdStr.c_str()); +} + +void ZipUtilsTest::DeleteFilePath(const std::string& filePath) +{ + if (!CheckFilePath(filePath)) { + return; + } + std::string cmdStr = std::string("rm -rf ") + filePath; + system(cmdStr.c_str()); +} + +/* + * @tc.name: Zip_0100 + * @tc.desc: zip. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipUtilsTest, Zip_0100, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ZipUtils zipUtils; + std::string filePath(FILE_PATH); + std::string zipPath(OUT_PATH); + + int ret = zipUtils.Zip(filePath, zipPath, OHOS::AppPackingTool::Constants::LIB_PATH); + EXPECT_EQ(ret, 0); + + DeleteFilePath(OUT_PATH); +} + +/* + * @tc.name: Unzip_0200 + * @tc.desc: Unzip. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipUtilsTest, Unzip_0200, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ZipUtils zipUtils; + std::string filePath(FILE_PATH); + std::string tempPath(TEMP_PATH); + std::string zipPath(OUT_PATH); + + int ret = zipUtils.Zip(filePath, zipPath, OHOS::AppPackingTool::Constants::LIB_PATH); + + ret = zipUtils.Unzip(zipPath, tempPath); + EXPECT_EQ(ret, 0); + + DeleteFilePath(TEMP_PATH); + DeleteFilePath(OUT_PATH); +} + +/* + * @tc.name: IsFileExistsInZip_0300 + * @tc.desc: IsFileExistsInZip. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipUtilsTest, IsFileExistsInZip_0300, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ZipUtils zipUtils; + std::string filePath = std::string(FILE_PATH) + std::string(FILE_NAME); + std::string zipPath(OUT_PATH); + + int ret = zipUtils.Zip(filePath, zipPath, FILE_NAME); + EXPECT_EQ(ret, 0); + + bool exist = zipUtils.IsFileExistsInZip(zipPath, FILE_NAME); + EXPECT_TRUE(exist); + + DeleteFilePath(OUT_PATH); +} + +/* + * @tc.name: IsFileNameExistsInZip_0400 + * @tc.desc: IsFileNameExistsInZip. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipUtilsTest, IsFileNameExistsInZip_0400, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ZipUtils zipUtils; + std::string filePath = std::string(FILE_PATH) + std::string(FILE_NAME); + std::string zipPath(OUT_PATH); + + int ret = zipUtils.Zip(filePath, zipPath, FILE_NAME); + EXPECT_EQ(ret, 0); + + auto exist = zipUtils.IsFileNameExistsInZip(zipPath, FILE_NAME); + EXPECT_TRUE(exist); + + DeleteFilePath(OUT_PATH); +} + +/* + * @tc.name: GetFileContentFromZip_0500 + * @tc.desc: GetFileContentFromZip. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipUtilsTest, GetFileContentFromZip_0500, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ZipUtils zipUtils; + std::string filePath = std::string(FILE_PATH) + std::string(FILE_NAME); + std::string zipPath(OUT_PATH); + std::string fileContent; + + int ret = zipUtils.Zip(filePath, zipPath, FILE_NAME); + EXPECT_EQ(ret, 0); + + EXPECT_TRUE(zipUtils.GetFileContentFromZip(zipPath, FILE_NAME, fileContent)); + EXPECT_TRUE(!fileContent.empty()); + + DeleteFilePath(OUT_PATH); +} + +/* + * @tc.name: GetUnzipCurrentFileContent_0600 + * @tc.desc: GetUnzipCurrentFileContent. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipUtilsTest, GetUnzipCurrentFileContent_0600, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ZipUtils zipUtils; + std::string filePath = std::string(FILE_PATH) + std::string(FILE_NAME); + std::string zipPath(OUT_PATH); + std::string fileContent; + + int ret = zipUtils.Zip(filePath, zipPath, FILE_NAME); + EXPECT_EQ(ret, 0); + + unzFile unzipFile = unzOpen64(zipPath.c_str()); + EXPECT_TRUE(zipUtils.GetUnzipCurrentFileContent(unzipFile, fileContent)); + EXPECT_TRUE(!fileContent.empty()); + + DeleteFilePath(OUT_PATH); +} + +/* + * @tc.name: GetResourceMapFromZip_0700 + * @tc.desc: GetResourceMapFromZip. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipUtilsTest, GetResourceMapFromZip_0700, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ZipUtils zipUtils; + std::string filePath = std::string(FILE_PATH) + std::string(FILE_NAME); + std::string zipPath(OUT_PATH); + std::map resourceMap; + + int ret = zipUtils.Zip(filePath, zipPath, FILE_NAME); + EXPECT_EQ(ret, 0); + + EXPECT_TRUE(zipUtils.GetResourceMapFromZip(zipPath, resourceMap)); + + DeleteFilePath(OUT_PATH); +} + +/* + * @tc.name: AddToResourceMap_0800 + * @tc.desc: AddToResourceMap. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipUtilsTest, AddToResourceMap_0800, Function | MediumTest | Level1) +{ + OHOS::AppPackingTool::ZipUtils zipUtils; + std::string filePath(FILE_PATH); + std::string zipPath(OUT_PATH); + std::string filePathInZip(FILE_NAME); + std::map resourceMap; + + int ret = zipUtils.Zip(filePath, zipPath, FILE_NAME); + EXPECT_EQ(ret, 0); + unzFile unzipFile = unzOpen64(zipPath.c_str()); + EXPECT_TRUE(zipUtils.AddToResourceMap(unzipFile, filePathInZip, resourceMap)); + + DeleteFilePath(OUT_PATH); +} +} // namespace OHOS \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/zip_wrapper_test/BUILD.gn b/packing_tool/frameworks/test/unittest/zip_wrapper_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..edce0ce60526c7795d556d73dd4fd35c9903074e --- /dev/null +++ b/packing_tool/frameworks/test/unittest/zip_wrapper_test/BUILD.gn @@ -0,0 +1,49 @@ +# 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. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("zip_wrapper_test_config") { + include_dirs = [ + "../../../include", + "../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "developtools/packing_tool" + +ohos_unittest("zip_wrapper_test") { + module_out_path = module_output_path + public_configs = [ ":zip_wrapper_test_config" ] + sources = [ + "../../../src/log.cpp", + "../../../src/zip_wrapper.cpp", + "zip_wrapper_test.cpp", + ] + external_deps = [ + "bounds_checking_function:libsec_static", + "cJSON:cjson_static", + "hilog:libhilog", + "openssl:libcrypto_shared", + "zlib:libz", + ] +} + +group("unittest") { + testonly = true + deps = [ ":zip_wrapper_test" ] +} diff --git a/packing_tool/frameworks/test/unittest/zip_wrapper_test/zip_wrapper_test.cpp b/packing_tool/frameworks/test/unittest/zip_wrapper_test/zip_wrapper_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..de1dc4fecd4f32db86007681bb79249d39e30536 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/zip_wrapper_test/zip_wrapper_test.cpp @@ -0,0 +1,172 @@ +/* + * 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. + */ + +#include + +#include +#include "constants.h" +#include "zip_constants.h" +#define private public +#define protected public +#include "zip_wrapper.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { + +#define OUT_PATH "/data/test_1.hqf" +#define FILE_PATH "/data/packager_test" + +std::string content = "{" + "\"name\": \"xxx.CN\"," + "\"url\": \"http://www.xxx.cn\"," + "\"page\": 88," + "\"isNonProfit\": true" +"}"; + +class ZipWrapperTest : public testing::Test { +public: + ZipWrapperTest() {} + virtual ~ZipWrapperTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void ZipWrapperTest::SetUpTestCase() {} + +void ZipWrapperTest::TearDownTestCase() {} + +void ZipWrapperTest::SetUp() {} + +void ZipWrapperTest::TearDown() {} + +/* + * @tc.name: Open_0100 + * @tc.desc: Open. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipWrapperTest, Open_0100, Function | MediumTest | Level1) +{ + std::string path(OUT_PATH); + OHOS::AppPackingTool::ZipWrapper zipWrapper; + zipWrapper.Open(path); + EXPECT_TRUE(zipWrapper.IsOpen()); + + zipWrapper.Close(); + EXPECT_FALSE(zipWrapper.IsOpen()); +} + +/* + * @tc.name: Open_0200 + * @tc.desc: Open. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipWrapperTest, Open_0200, Function | MediumTest | Level1) +{ + std::string path(OUT_PATH); + OHOS::AppPackingTool::ZipWrapper zipWrapper(path); + zipWrapper.Open(APPEND_STATUS_CREATE); + EXPECT_TRUE(zipWrapper.IsOpen()); + + zipWrapper.Close(); + EXPECT_FALSE(zipWrapper.IsOpen()); +} + +/* + * @tc.name: AddFileOrDirectoryToZip_0400 + * @tc.desc: AddFileOrDirectoryToZip. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipWrapperTest, AddFileOrDirectoryToZip_0400, Function | MediumTest | Level1) +{ + std::string path(OUT_PATH); + OHOS::AppPackingTool::ZipWrapper zipWrapper(path); + + zipWrapper.Open(APPEND_STATUS_CREATE); + std::string filepath(FILE_PATH); + std::string zippath(OUT_PATH); + int ret = zipWrapper.AddFileOrDirectoryToZip(filepath, zippath); + EXPECT_EQ(ret, 0); + + zipWrapper.Close(); +} + +/* + * @tc.name: WriteStringToZip_0500 + * @tc.desc: WriteStringToZip. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipWrapperTest, WriteStringToZip_0500, Function | MediumTest | Level1) +{ + std::string path(OUT_PATH); + OHOS::AppPackingTool::ZipWrapper zipWrapper(path); + + zipWrapper.Open(APPEND_STATUS_CREATE); + int ret = zipWrapper.WriteStringToZip(content, OHOS::AppPackingTool::Constants::PARAM_JSON_PATH); + EXPECT_EQ(ret, 0); + + std::string filepath(FILE_PATH); + ret = zipWrapper.AddFileOrDirectoryToZip(filepath, OHOS::AppPackingTool::Constants::PARAM_LIB_PATH); + EXPECT_EQ(ret, 0); + + ret = zipWrapper.AddFileOrDirectoryToZip(filepath, OHOS::AppPackingTool::Constants::PARAM_RESOURCES_PATH); + EXPECT_EQ(ret, 0); + + ret = zipWrapper.AddFileOrDirectoryToZip(filepath, OHOS::AppPackingTool::Constants::PARAM_ETS_PATH); + EXPECT_EQ(ret, 0); + + zipWrapper.Close(); + + std::string cmd = {"rm -f "}; + cmd += OUT_PATH; + system(cmd.c_str()); +} + +/* + * @tc.name: AddEmptyDirToZip_0600 + * @tc.desc: AddEmptyDirToZip. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(ZipWrapperTest, AddEmptyDirToZip_0600, Function | MediumTest | Level1) +{ + std::string path(OUT_PATH); + OHOS::AppPackingTool::ZipWrapper zipWrapper(path); + fs::create_directories("temp"); + std::string emptypath("./temp"); + zipWrapper.Open(APPEND_STATUS_CREATE); + int ret = zipWrapper.AddEmptyDirToZip(emptypath); + EXPECT_EQ(ret, ZIP_OK); + + zipWrapper.Close(); + + std::string cmd = {"rm -f "}; + cmd += OUT_PATH; + system(cmd.c_str()); +} +} // namespace OHOS \ No newline at end of file