From b7ab5aef69220b49822b56fd572a8dd4bdf5e99e Mon Sep 17 00:00:00 2001 From: yuechunyang Date: Thu, 29 May 2025 20:21:29 +0800 Subject: [PATCH] add_general_normalize_test Signed-off-by: yuechunyang --- .../frameworks/test/unittest/BUILD.gn | 4 +- .../unittest/general_normalize_test/BUILD.gn | 77 +++ .../default/js/MainAbility/app.js | 37 ++ .../default/js/MainAbility/app.js.map | 1 + .../default/js/MainAbility/manifest.json | 1 + .../default/js/MainAbility/pages/index.js | 88 +++ .../default/js/MainAbility/pages/index.js.map | 1 + .../general_normalize_file/fa/config.json | 96 +++ .../general_normalize_file/fa/pack.json | 1 + .../stage/ets/sourceMaps.map | 20 + .../general_normalize_file/stage/module.json | 50 ++ .../general_normalize_file/stage/pack.json | 1 + .../resources/base/profile/main_pages.json | 5 + .../general_normalize_test.cpp | 571 ++++++++++++++++++ .../json/module_json_fa_test/BUILD.gn | 2 +- .../test/unittest/ohos_test/ohos_test.xml | 2 +- .../test/unittest/shell_command_test/BUILD.gn | 2 +- .../test/unittest/utils_Test/BUILD.gn | 2 +- .../zip_utils_test/zip_utils_test.cpp | 2 +- 19 files changed, 957 insertions(+), 6 deletions(-) create mode 100644 packing_tool/frameworks/test/unittest/general_normalize_test/BUILD.gn create mode 100644 packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/app.js create mode 100644 packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/app.js.map create mode 100644 packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/manifest.json create mode 100644 packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/pages/index.js create mode 100644 packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/pages/index.js.map create mode 100644 packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/config.json create mode 100644 packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/pack.json create mode 100644 packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/ets/sourceMaps.map create mode 100644 packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/module.json create mode 100644 packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/pack.json create mode 100644 packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/resources/base/profile/main_pages.json create mode 100644 packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_test.cpp diff --git a/packing_tool/frameworks/test/unittest/BUILD.gn b/packing_tool/frameworks/test/unittest/BUILD.gn index de5faf0a..4782ef98 100644 --- a/packing_tool/frameworks/test/unittest/BUILD.gn +++ b/packing_tool/frameworks/test/unittest/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. +# Copyright (c) 2024-2025 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -20,6 +20,7 @@ group("unittest") { "app_packager_test:unittest", "appqf_packager_test:unittest", "fast_app_packager_test:unittest", + "general_normalize_test:unittest", "hap_packager_test:unittest", "hqf_packager_test:unittest", "hqf_verify_test:unittest", @@ -28,6 +29,7 @@ group("unittest") { "json/hap_verify_info_test:unittest", "json/hap_verify_utils_test:unittest", "json/json_utils_test:unittest", + "json/module_json_fa_test:unittest", "json/module_json_stage_test:unittest", "json/module_json_test:unittest", "json/module_json_utils_test:unittest", diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/BUILD.gn b/packing_tool/frameworks/test/unittest/general_normalize_test/BUILD.gn new file mode 100644 index 00000000..d4caa2b0 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/BUILD.gn @@ -0,0 +1,77 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//build/test.gni") + +config("general_normalize_test_config") { + include_dirs = [ + "../../../include", + "../../../include/json", + ] + + cflags_cc = [ "-fexceptions" ] + cflags_objcc = cflags_cc +} + +module_output_path = "packing_tool/packing_tool" + +ohos_unittest("general_normalize_test") { + module_out_path = module_output_path + public_configs = [ ":general_normalize_test_config" ] + sources = [ + "../../../src/general_normalize.cpp", + "../../../src/hap_packager.cpp", + "../../../src/hsp_packager.cpp", + "../../../src/json/general_normalize_version_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/normalize_version_utils.cpp", + "../../../src/json/pack_info.cpp", + "../../../src/json/pt_json.cpp", + "../../../src/log.cpp", + "../../../src/packager.cpp", + "../../../src/unzip_wrapper.cpp", + "../../../src/utils.cpp", + "../../../src/zip_utils.cpp", + "../../../src/zip_wrapper.cpp", + "general_normalize_test.cpp", + ] + + external_deps = [ + "bounds_checking_function:libsec_static", + "cJSON:cjson_static", + "hilog:libhilog", + "openssl:libcrypto_shared", + "zlib:libz", + ] + + deps = [ + ":copy_test_file", + "../ohos_test:copy_ohos_test", + ] +} + +group("unittest") { + testonly = true + deps = [ ":general_normalize_test" ] +} + +ohos_copy("copy_test_file") { + subsystem_name = "developtools" + part_name = "packing_tool" + sources = [ "./general_normalize_file" ] + outputs = [ "$root_out_dir/tests/unittest/packing_tool/packing_tool/test_file/general_normalize_file/" ] +} diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/app.js b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/app.js new file mode 100644 index 00000000..e70b250f --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/app.js @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function () { +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var hilog = globalThis.requireNapi('hilog'); +var app = { + onCreate() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Application onCreate'); + }, + onDestroy() { + hilog.info(0x0000, 'testTag', '%{public}s', 'Application onDestroy'); + }, +}; + +exports.default = app; +globalThis['app.js_8e74c152fb289caceeb880912823241e9d4b2806ecc0022940f4429f6d749b02'] + = globalThis['app.js_8e74c152fb289caceeb880912823241e9d4b2806ecc0022940f4429f6d749b02'] || { + default: app +} +})() +//# sourceMappingURL=app.js.map diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/app.js.map b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/app.js.map new file mode 100644 index 00000000..93239c38 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/app.js.map @@ -0,0 +1 @@ +{"version":3,"file":"app.js","sources":["D:/ArkTsProject/packingToolFaDemo/entry/src/main/ets/MainAbility/app.ets"],"sourcesContent":["import hilog from '@ohos.hilog';\n\nexport default {\n onCreate() {\n hilog.info(0x0000, 'testTag', '%{public}s', 'Application onCreate');\n },\n onDestroy() {\n hilog.info(0x0000, 'testTag', '%{public}s', 'Application onDestroy');\n },\n}"],"names":[],"mappings":"CAAA"} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/manifest.json b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/manifest.json new file mode 100644 index 00000000..a4bfd1e2 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/manifest.json @@ -0,0 +1 @@ +{"appID":"com.example.packingtoolfademo","versionName":"1.0.0","versionCode":1000000,"minPlatformVersion":9,"appName":".MainAbility","deviceType":["default","tablet"],"window":{"designWidth":720,"autoDesignWidth":false},"pages":["pages/index"],"mode":{"syntax":"ets","type":"pageAbility"}} diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/pages/index.js b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/pages/index.js new file mode 100644 index 00000000..1d5415ae --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/pages/index.js @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +(function () { +'use strict'; + +"use strict"; +class Index extends ViewPU { + constructor(parent, params, __localStorage, elmtId = -1) { + super(parent, __localStorage, elmtId); + this.__message = new ObservedPropertySimplePU('Hello World', this, "message"); + this.setInitiallyProvidedValue(params); + } + setInitiallyProvidedValue(params) { + if (params.message !== undefined) { + this.message = params.message; + } + } + updateStateVars(params) { + } + purgeVariableDependenciesOnElmtId(rmElmtId) { + this.__message.purgeDependencyOnElmtId(rmElmtId); + } + aboutToBeDeleted() { + this.__message.aboutToBeDeleted(); + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal(); + } + get message() { + return this.__message.get(); + } + set message(newValue) { + this.__message.set(newValue); + } + initialRender() { + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Row.create(); + Row.height('100%'); + if (!isInitialRender) { + Row.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Column.create(); + Column.width('100%'); + if (!isInitialRender) { + Column.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + this.observeComponentCreation((elmtId, isInitialRender) => { + ViewStackProcessor.StartGetAccessRecordingFor(elmtId); + Text.create(this.message); + Text.fontSize(50); + Text.fontWeight(FontWeight.Bold); + if (!isInitialRender) { + Text.pop(); + } + ViewStackProcessor.StopGetAccessRecording(); + }); + Text.pop(); + Column.pop(); + Row.pop(); + } + rerender() { + this.updateDirtyElements(); + } +} +ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent()); +loadDocument(new Index(undefined, {})); +ViewStackProcessor.StopGetAccessRecording(); +})() +//# sourceMappingURL=index.js.map diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/pages/index.js.map b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/pages/index.js.map new file mode 100644 index 00000000..275b007d --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/assets_jsbundle/default/js/MainAbility/pages/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["D:/ArkTsProject/packingToolFaDemo/entry/src/main/ets/MainAbility/pages/index.ets"],"sourcesContent":["@Entry\n@Component\nstruct Index {\n @State message: string = 'Hello World'\n\n build() {\n Row() {\n Column() {\n Text(this.message)\n .fontSize(50)\n .fontWeight(FontWeight.Bold)\n }\n .width('100%')\n }\n .height('100%')\n }\n}"],"names":[],"mappings":"CAAA"} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/config.json b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/config.json new file mode 100644 index 00000000..58e4106a --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/config.json @@ -0,0 +1,96 @@ +{ + "app" : + { + "apiVersion" : + { + "compatible" : 9, + "releaseType" : "Release", + "target" : 9 + }, + "bundleName" : "com.example.packingtoolfademo", + "vendor" : "example", + "version" : + { + "code" : 1000000, + "name" : "1.0.0" + } + }, + "deviceConfig" : + { + "default" : + { + "debug" : true + } + }, + "module" : + { + "abilities" : + [ + { + "description" : "$string:MainAbility_desc", + "descriptionId" : 16777216, + "formsEnabled" : false, + "icon" : "$media:icon", + "iconId" : 16777220, + "label" : "$string:MainAbility_label", + "labelId" : 16777217, + "launchType" : "standard", + "name" : ".MainAbility", + "orientation" : "unspecified", + "skills" : + [ + { + "actions" : + [ + "action.system.home" + ], + "entities" : + [ + "entity.system.home" + ] + } + ], + "srcLanguage" : "ets", + "srcPath" : "MainAbility", + "type" : "page", + "visible" : true + } + ], + "deviceType" : + [ + "default", + "tablet" + ], + "distro" : + { + "deliveryWithInstall" : true, + "installationFree" : false, + "moduleName" : "entry", + "moduleType" : "entry", + "virtualMachine" : "ark9.0.0.0" + }, + "js" : + [ + { + "mode" : + { + "syntax" : "ets", + "type" : "pageAbility" + }, + "name" : ".MainAbility", + "pages" : + [ + "pages/index" + ], + "window" : + { + "autoDesignWidth" : false, + "designWidth" : 720 + } + } + ], + "mainAbility" : ".MainAbility", + "name" : ".entry", + "package" : "com.example.packingtoolfademo" + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/pack.json b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/pack.json new file mode 100644 index 00000000..04870b2b --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/fa/pack.json @@ -0,0 +1 @@ +{"summary":{"app":{"bundleName":"com.example.packingtoolfademo","version":{"code":1000000,"name":"1.0.0"}},"modules":[{"mainAbility":".MainAbility","deviceType":["default","tablet"],"abilities":[{"name":".MainAbility","label":"$string:MainAbility_label","visible":true}],"distro":{"deliveryWithInstall":true,"moduleName":"entry","moduleType":"entry","installationFree":false},"apiVersion":{"target":9,"compatible":9,"releaseType":"Release"}}]},"packages":[{"deviceType":["default","tablet"],"moduleType":"entry","deliveryWithInstall":true,"name":"entry-default"}]} diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/ets/sourceMaps.map b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/ets/sourceMaps.map new file mode 100644 index 00000000..6e057157 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/ets/sourceMaps.map @@ -0,0 +1,20 @@ +{ + "entry/build/default/cache/default/default@CompileArkTS/esmodule/debug/entry/src/main/ets/entryability/EntryAbility.js": { + "version": 3, + "file": "EntryAbility.ts", + "sources": [ + "entry/src/main/ets/entryability/EntryAbility.ts" + ], + "names": [], + "mappings": "AAAA" + }, + "entry/build/default/cache/default/default@CompileArkTS/esmodule/debug/entry/src/main/ets/pages/Index.js": { + "version": 3, + "file": "Index.ets", + "sources": [ + "entry/src/main/ets/pages/Index.ets" + ], + "names": [], + "mappings": "AAAA" + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/module.json b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/module.json new file mode 100644 index 00000000..5427967a --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/module.json @@ -0,0 +1,50 @@ +{ + "app": { + "bundleName": "com.example.packingtooldemo", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "targetAPIVersion": 12, + "minAPIVersion": 12, + "apiReleaseType": "Canary2", + "debug": true, + "iconId": 16777217, + "labelId": 16777216 + }, + "module": { + "name": "entry", + "type": "entry", + "description": "$string:module_desc", + "mainElement": "EntryAbility", + "deviceTypes": ["default", "tablet"], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "abilities": [{ + "name": "EntryAbility", + "srcEntry": "./ets/entryability/EntryAbility.ts", + "description": "$string:EntryAbility_desc", + "icon": "$media:icon", + "label": "$string:EntryAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "exported": true, + "skills": [{ + "entities": ["entity.system.home"], + "actions": ["action.system.home"] + }], + "descriptionId": 16777218, + "iconId": 16777222, + "labelId": 16777219, + "startWindowIconId": 16777222, + "startWindowBackgroundId": 16777221 + }], + "generateBuildHash": true, + "virtualMachine": "ark12.0.1.0", + "compileMode": "esmodule", + "dependencies": [], + "descriptionId": 16777220 + } +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/pack.json b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/pack.json new file mode 100644 index 00000000..b221fd94 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/pack.json @@ -0,0 +1 @@ +{"summary":{"app":{"bundleName":"com.example.packingtooldemo","version":{"code":1000000,"name":"1.0.0"}},"modules":[{"mainAbility":"EntryAbility","deviceType":["default","tablet"],"abilities":[{"name":"EntryAbility","label":"$string:EntryAbility_label"}],"distro":{"moduleType":"entry","installationFree":false,"deliveryWithInstall":true,"moduleName":"entry"},"apiVersion":{"compatible":12,"releaseType":"Canary2","target":12}}]},"packages":[{"deviceType":["default","tablet"],"moduleType":"entry","deliveryWithInstall":true,"name":"entry-default"}]} diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/resources/base/profile/main_pages.json b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/resources/base/profile/main_pages.json new file mode 100644 index 00000000..1898d94f --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_file/stage/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/Index" + ] +} diff --git a/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_test.cpp b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_test.cpp new file mode 100644 index 00000000..d596ade7 --- /dev/null +++ b/packing_tool/frameworks/test/unittest/general_normalize_test/general_normalize_test.cpp @@ -0,0 +1,571 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#define private public +#define protected public +#include "module_json.h" +#include "general_normalize.h" +#include "general_normalize_version_utils.h" +#include "hap_packager.h" +#include "log.h" +#include "pt_json.h" +#undef private +#undef protected + +#include "hqf_packager.h" +#include "hsp_packager.h" +#include "json/json_utils.h" +#include "json/normalize_version_utils.h" +#include "json/pack_info.h" +#include "utils.h" +#include "zip_utils.h" + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::AppPackingTool; + +namespace OHOS { +namespace { +const std::string OUT_PATH = "/data/test/testouthap"; +const std::string HAP_OUT_PATH = "/data/test/entry-default-unsigned.hap"; +const std::string HAP_INPUT_LIST = "/data/test/entry-default-unsigned.hap"; +const std::string INPUT_LIST = "/data/test/testinputhap"; +const std::string VERSION_CODE = "9999999"; +const std::string VERSION_NAME = "30.11.22"; +const std::string STAGE_INDEX_PATH = "/data/test/resource/packingtool/test_file/stage/resources.index"; +const std::string STAGE_PACK_INFO_PATH = "/data/test/resource/packingtool/test_file/stage/pack.info"; +const std::string STAGE_ETS_PATH = "/data/test/resource/packingtool/test_file/stage/ets"; +const std::string STAGE_RESOURCES_PATH = "/data/test/resource/packingtool/test_file/stage/resources"; +const std::string STAGE_JSON_PATH = "/data/test/resource/packingtool/test_file/stage/module.json"; +const std::string STAGE_RPCID_PATH = "/data/test/resource/packingtool/test_file/stage/rpcid.sc"; +const std::string PATH = "/data/test/resource/packingtool/test_file/stage"; +const std::string BUNDLE_NAME = "com.example.packingtoolfademo"; +const std::string MIN_COMPATIBLE_VERSION_CODE = "99"; +const std::string MIN_API_VERSION = "11"; +const std::string TARGET_API_VERSION = "12"; +const std::string API_RELEASE_TYPE = "Canary1"; +const std::string INVAILD_INT_NUM = "2147483648"; +const std::string INVAILD_PATTERN = "-123"; +const std::string TOO_LONG_VERSION_NAME(OHOS::AppPackingTool::Constants::MAX_VERSION_NAME_LENGTH + 1, '1'); +const std::string TOO_SHORT_BUNDLE_NAME(OHOS::AppPackingTool::Constants::BUNDLE_NAME_LEN_MIN - 1, '1'); +const std::string TOO_LONG_BUNDLE_NAME(OHOS::AppPackingTool::Constants::BUNDLE_NAME_LEN_MAX + 1, '1'); +const std::string INVALID_DEVICE_TYPES = +"\"default\", \"tablet\", \"tv\", \"wearable\", \"car\", \"2in1\", \"abc\""; +const std::string CONFIG_JSON_STRING = "{" + "\"app\": {" + "\"apiVersion\": {" + "\"compatible\": 9," + "\"releaseType\": \"Release\"," + "\"target\": 9" + "}," + "\"bundleName\": \"com.example.packingtoolfademo\"," + "\"vendor\": \"example\"," + "\"version\": {" + "\"code\" : 1000000," + "\"name\" : \"1.0.0\"" + "}" + "}," + "\"deviceConfig\": {" + "\"default\": {" + "\"debug\": true" + "}" + "}," + "\"module\": {" + "\"abilities\": [" + "{" + "\"description\": \"$string:MainAbility_desc\"," + "\"descriptionId\": 16777216," + "\"formsEnabled\": false," + "\"icon\": \"$media:icon\"," + "\"iconId\": 16777220," + "\"label\": \"$string:MainAbility_label\"," + "\"labelId\": 16777217," + "\"launchType\": \"standard\"," + "\"name\": \".MainAbility\"," + "\"orientation\": \"unspecified\"," + "\"skills\": [" + "{" + "\"actions\": [" + "\"action.system.home\"" + "]," + "\"entities\": [" + "\"entity.system.home\"" + "]" + "}" + "]," + "\"srcLanguage\" : \"ets\"," + "\"srcPath\" : \"MainAbility\"," + "\"type\" : \"page\"," + "\"visible\" : true" + "}" + "]," + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"distro\": {" + "\"deliveryWithInstall\": true," + "\"installationFree\": false," + "\"moduleName\": \"entry\"," + "\"moduleType\": \"entry\"," + "\"virtualMachine\": \"ark9.0.0.0\"" + "}," + "\"js\": [" + "{" + "\"mode\": {" + "\"syntax\": \"ets\"," + "\"type\": \"pageAbility\"" + "}," + "\"name\": \".MainAbility\"," + "\"pages\": [" + "\"pages/index\"" + "]," + "\"window\": {" + "\"autoDesignWidth\": false," + "\"designWidth\": 720" + "}" + "}" + "]," + "\"mainAbility\" : \".MainAbility\"," + "\"name\" : \".entry\"," + "\"package\" : \"com.example.packingtoolfademo\"" + "}" +"}"; +const std::string CONFIG_JSON_STRING_NO_MODULE_NAME = "{" + "\"app\": {" + "\"apiVersion\": {" + "\"compatible\": 9," + "\"releaseType\": \"Release\"," + "\"target\": 9" + "}," + "\"bundleName\": \"com.example.packingtoolfademo\"," + "\"vendor\": \"example\"," + "\"version\": {" + "\"code\" : 1000000," + "\"name\" : \"1.0.0\"" + "}" + "}," + "\"deviceConfig\": {" + "\"default\": {" + "\"debug\": true" + "}" + "}," + "\"module\": {" + "\"abilities\": [" + "{" + "\"description\": \"$string:MainAbility_desc\"," + "\"descriptionId\": 16777216," + "\"formsEnabled\": false," + "\"icon\": \"$media:icon\"," + "\"iconId\": 16777220," + "\"label\": \"$string:MainAbility_label\"," + "\"labelId\": 16777217," + "\"launchType\": \"standard\"," + "\"name\": \".MainAbility\"," + "\"orientation\": \"unspecified\"," + "\"skills\": [" + "{" + "\"actions\": [" + "\"action.system.home\"" + "]," + "\"entities\": [" + "\"entity.system.home\"" + "]" + "}" + "]," + "\"srcLanguage\" : \"ets\"," + "\"srcPath\" : \"MainAbility\"," + "\"type\" : \"page\"," + "\"visible\" : true" + "}" + "]," + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"distro\": {" + "\"deliveryWithInstall\": true," + "\"installationFree\": false," + "\"moduleName\": \"entry\"," + "\"moduleType\": \"entry\"," + "\"virtualMachine\": \"ark9.0.0.0\"" + "}," + "\"js\": [" + "{" + "\"mode\": {" + "\"syntax\": \"ets\"," + "\"type\": \"pageAbility\"" + "}," + "\"name\": \".MainAbility\"," + "\"pages\": [" + "\"pages/index\"" + "]," + "\"window\": {" + "\"autoDesignWidth\": false," + "\"designWidth\": 720" + "}" + "}" + "]," + "\"mainAbility\" : \".MainAbility\"," + "\"package\" : \"com.example.packingtoolfademo\"" + "}" +"}"; +const std::string CONFIG_JSON_STRING_NO_APP_VERSION = "{" + "\"app\": {" + "\"apiVersion\": {" + "\"compatible\": 9," + "\"releaseType\": \"Release\"," + "\"target\": 9" + "}," + "\"bundleName\": \"com.example.packingtoolfademo\"," + "\"vendor\": \"example\"" + "}," + "\"deviceConfig\": {" + "\"default\": {" + "\"debug\": true" + "}" + "}," + "\"module\": {" + "\"abilities\": [" + "{" + "\"description\": \"$string:MainAbility_desc\"," + "\"descriptionId\": 16777216," + "\"formsEnabled\": false," + "\"icon\": \"$media:icon\"," + "\"iconId\": 16777220," + "\"label\": \"$string:MainAbility_label\"," + "\"labelId\": 16777217," + "\"launchType\": \"standard\"," + "\"name\": \".MainAbility\"," + "\"orientation\": \"unspecified\"," + "\"skills\": [" + "{" + "\"actions\": [" + "\"action.system.home\"" + "]," + "\"entities\": [" + "\"entity.system.home\"" + "]" + "}" + "]," + "\"srcLanguage\" : \"ets\"," + "\"srcPath\" : \"MainAbility\"," + "\"type\" : \"page\"," + "\"visible\" : true" + "}" + "]," + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"distro\": {" + "\"deliveryWithInstall\": true," + "\"installationFree\": false," + "\"moduleName\": \"entry\"," + "\"moduleType\": \"entry\"," + "\"virtualMachine\": \"ark9.0.0.0\"" + "}," + "\"js\": [" + "{" + "\"mode\": {" + "\"syntax\": \"ets\"," + "\"type\": \"pageAbility\"" + "}," + "\"name\": \".MainAbility\"," + "\"pages\": [" + "\"pages/index\"" + "]," + "\"window\": {" + "\"autoDesignWidth\": false," + "\"designWidth\": 720" + "}" + "}" + "]," + "\"mainAbility\" : \".MainAbility\"," + "\"name\" : \".entry\"," + "\"package\" : \"com.example.packingtoolfademo\"" + "}" +"}"; +const std::string CONFIG_JSON_STRING_NO_BUNDLE_NAME = "{" + "\"app\": {" + "\"apiVersion\": {" + "\"compatible\": 9," + "\"releaseType\": \"Release\"," + "\"target\": 9" + "}," + "\"vendor\": \"example\"," + "\"version\": {" + "\"code\" : 1000000," + "\"name\" : \"1.0.0\"" + "}" + "}," + "\"deviceConfig\": {" + "\"default\": {" + "\"debug\": true" + "}" + "}," + "\"module\": {" + "\"abilities\": [" + "{" + "\"description\": \"$string:MainAbility_desc\"," + "\"descriptionId\": 16777216," + "\"formsEnabled\": false," + "\"icon\": \"$media:icon\"," + "\"iconId\": 16777220," + "\"label\": \"$string:MainAbility_label\"," + "\"labelId\": 16777217," + "\"launchType\": \"standard\"," + "\"name\": \".MainAbility\"," + "\"orientation\": \"unspecified\"," + "\"skills\": [" + "{" + "\"actions\": [" + "\"action.system.home\"" + "]," + "\"entities\": [" + "\"entity.system.home\"" + "]" + "}" + "]," + "\"srcLanguage\" : \"ets\"," + "\"srcPath\" : \"MainAbility\"," + "\"type\" : \"page\"," + "\"visible\" : true" + "}" + "]," + "\"deviceType\": [" + "\"default\"," + "\"tablet\"" + "]," + "\"distro\": {" + "\"deliveryWithInstall\": true," + "\"installationFree\": false," + "\"moduleName\": \"entry\"," + "\"moduleType\": \"entry\"," + "\"virtualMachine\": \"ark9.0.0.0\"" + "}," + "\"js\": [" + "{" + "\"mode\": {" + "\"syntax\": \"ets\"," + "\"type\": \"pageAbility\"" + "}," + "\"name\": \".MainAbility\"," + "\"pages\": [" + "\"pages/index\"" + "]," + "\"window\": {" + "\"autoDesignWidth\": false," + "\"designWidth\": 720" + "}" + "}" + "]," + "\"mainAbility\" : \".MainAbility\"," + "\"name\" : \".entry\"," + "\"package\" : \"com.example.packingtoolfademo\"" + "}" +"}"; +} + +class GeneralNormalizeTest : public testing::Test { +public: + GeneralNormalizeTest() {} + virtual ~GeneralNormalizeTest() {} + + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp(); + + void TearDown(); +}; + +void GeneralNormalizeTest::SetUpTestCase() +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, HAP_OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_FORCE, "true"}, + {OHOS::AppPackingTool::Constants::PARAM_JSON_PATH, STAGE_JSON_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_ETS_PATH, STAGE_ETS_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_RESOURCES_PATH, STAGE_RESOURCES_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_INDEX_PATH, STAGE_INDEX_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_PACK_INFO_PATH, STAGE_PACK_INFO_PATH}, + }; + + OHOS::AppPackingTool::HapPackager hapPackager(parameterMap, resultReceiver); + system("mv /data/test/resource/packingtool/test_file/stage/pack.json " + "/data/test/resource/packingtool/test_file/stage/pack.info"); + system("mkdir /data/test/resource/packingtool/test_file/stage/ets"); + system("touch /data/test/resource/packingtool/test_file/stage/resources.index"); + EXPECT_EQ(hapPackager.InitAllowedParam(), 0); + EXPECT_EQ(hapPackager.PreProcess(), 0); + EXPECT_EQ(hapPackager.Process(), 0); + EXPECT_EQ(hapPackager.PostProcess(), 0); + system("rm -rf /data/test/resource/packingtool/test_file/stage"); + system("rm -rf /data/test/resource/packingtool/test_file/fa"); +} + +void GeneralNormalizeTest::TearDownTestCase() +{ + system("rm -rf /data/test/testouthap"); + system("rm -rf /data/test/entry-default-unsigned.hap"); +} + +void GeneralNormalizeTest::SetUp() {} + +void GeneralNormalizeTest::TearDown() {} + +/* + * @tc.name: InitAllowedParam_0100 + * @tc.desc: InitAllowedParam. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, InitAllowedParam_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = {}; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.InitAllowedParam(), 0); +} + +/* + * @tc.name: Process_0100 + * @tc.desc: Process + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, Process_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, HAP_INPUT_LIST}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_NAME, VERSION_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + }; + + system("mkdir /data/test/testouthap"); + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 0); + EXPECT_EQ(generalNormalize.Process(), 0); + system("rm -rf /data/test/testouthap"); +} + +/* + * @tc.name: Process_0200 + * @tc.desc: Process + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, Process_0200, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, HAP_INPUT_LIST}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_CODE, VERSION_CODE}, + {OHOS::AppPackingTool::Constants::PARAM_VERSION_NAME, VERSION_NAME}, + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + }; + + system("mkdir /data/test/testouthap"); + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 0); + system("rm -rf /data/test/entry-default-unsigned.hap"); + system("touch /data/test/entry-default-unsigned.hap"); + EXPECT_EQ(generalNormalize.Process(), 1); + system("rm -rf /data/test/testouthap"); +} + +/* + * @tc.name: PreProcess_0100 + * @tc.desc: PreProcess + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, PreProcess_0100, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap; + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); +} + +/* + * @tc.name: PreProcess_0200 + * @tc.desc: PreProcess + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, PreProcess_0200, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + }; + system("mkdir /data/test/testouthap"); + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); + system("rm -rf /data/test/testouthap"); +} + +/* + * @tc.name: PreProcess_0300 + * @tc.desc: PreProcess + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, PreProcess_0300, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, "module.json"}, + }; + system("mkdir /data/test/testouthap"); + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); + system("rm -rf /data/test/testouthap"); +} + +/* + * @tc.name: PreProcess_0400 + * @tc.desc: PreProcess + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(GeneralNormalizeTest, PreProcess_0400, Function | MediumTest | Level1) +{ + std::string resultReceiver; + std::map parameterMap = { + {OHOS::AppPackingTool::Constants::PARAM_OUT_PATH, OUT_PATH}, + {OHOS::AppPackingTool::Constants::PARAM_INPUT_LIST, INPUT_LIST}, + }; + system("mkdir /data/test/testouthap"); + system("mkdir /data/test/testinputhap"); + OHOS::AppPackingTool::GeneralNormalize generalNormalize(parameterMap, resultReceiver); + EXPECT_EQ(generalNormalize.PreProcess(), 1); + system("rm -rf /data/test/testouthap"); + system("rm -rf /data/test/testinputhap"); +} +} \ No newline at end of file diff --git a/packing_tool/frameworks/test/unittest/json/module_json_fa_test/BUILD.gn b/packing_tool/frameworks/test/unittest/json/module_json_fa_test/BUILD.gn index f2305e59..760e58cc 100644 --- a/packing_tool/frameworks/test/unittest/json/module_json_fa_test/BUILD.gn +++ b/packing_tool/frameworks/test/unittest/json/module_json_fa_test/BUILD.gn @@ -24,7 +24,7 @@ config("module_json_test_config") { cflags_objcc = cflags_cc } -module_output_path = "developtools/packing_tool" +module_output_path = "packing_tool/packing_tool" ohos_unittest("module_json_fa_test") { module_out_path = module_output_path diff --git a/packing_tool/frameworks/test/unittest/ohos_test/ohos_test.xml b/packing_tool/frameworks/test/unittest/ohos_test/ohos_test.xml index 5b251da4..818dabc0 100644 --- a/packing_tool/frameworks/test/unittest/ohos_test/ohos_test.xml +++ b/packing_tool/frameworks/test/unittest/ohos_test/ohos_test.xml @@ -1,6 +1,6 @@