diff --git a/aafwk/aafwk_standard/BUILD.gn b/aafwk/aafwk_standard/BUILD.gn index 34ac24cb12e04f1e21e6b707841ac490f11a1ea5..0fc782adf9fbed1473f1b23317c8e4f6e0172f56 100755 --- a/aafwk/aafwk_standard/BUILD.gn +++ b/aafwk/aafwk_standard/BUILD.gn @@ -9,7 +9,7 @@ # 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. +# limitations under the License. import("//build/ohos_var.gni") @@ -21,6 +21,7 @@ group("aafwk_standard") { "abilitymanager:actsabilitymanagertest", "actsabilitydistributetest:ActsAbilityDistributeTest", "actsabilitydistributetest:ActsAbilityDistributeTest", + "actsabilitymanageretstest:ActsAbilityManagerEtsTest", "amsabilitymanager/amsMissionSnapshotTest:ActsAmsMissionSnapshotTest", "amsabilitymanager/amsMissionSnapshotTestSingleton:ActsAmsMissionSnapshotTestSingleton", "amsabilitymanager/amsMissionSnapshotTestSingletonS:ActsAmsMissionSnapshotTestSingletonS", diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/BUILD.gn b/aafwk/aafwk_standard/actsabilitymanageretstest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0d799ef4ee841395559d3c59fb524fdf04b0570c --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/BUILD.gn @@ -0,0 +1,32 @@ +# Copyright (c) 2021 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("ActsAbilityManagerEtsTest") { + hap_profile = "./entry/src/main/config.json" + deps = [ + ":hjs_demo_ets_assets", + ":hjs_demo_ets_resources", + ] + ets2abc = true + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsAbilityManagerEtsTest" +} +ohos_js_assets("hjs_demo_ets_assets") { + source_dir = "./entry/src/main/ets/MainAbility" +} +ohos_resources("hjs_demo_ets_resources") { + sources = [ "./entry/src/main/resources" ] + hap_profile = "./entry/src/main/config.json" +} diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/Test.json b/aafwk/aafwk_standard/actsabilitymanageretstest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..6a84fb1bc2651c4320e869a3990bc98ce5ca1b28 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for aceceshi Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "600000", + "package": "com.ohos.acecollaboration", + "shell-timeout": "60000" + }, + "kits": [ + { + "test-file-name": [ + "ActsAbilityManagerEtsTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/config.json b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..0fb6c3d49860110029fe38061ee4fbbc8a236fe3 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/config.json @@ -0,0 +1,159 @@ +{ + "app": { + "bundleName": "com.ohos.acecollaboration", + "vendor": "ohos", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.ohos.acecollaboration", + "name": ".MyApplication", + "mainAbility": "com.ohos.acecollaboration.MainAbility", + "deviceType": [ + "phone" + ], + "reqPermissions": [ + { + "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" + }, + { + "name": "ohos.permission.GET_BUNDLE_INFO" + } + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "visible": true, + "srcPath": "MainAbility", + "srcLanguage": "ets", + "name": "com.ohos.acecollaboration.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard" + }, + { + "orientation": "unspecified", + "srcPath": "MainAbility2", + "name": ".MainAbility2", + "srcLanguage": "ets", + "icon": "$media:icon", + "description": "$string:description_mainability2", + "formsEnabled": false, + "label": "$string:entry_MainAbility2", + "type": "page", + "launchType": "standard" + }, + { + "srcPath": "ServiceAbility", + "name": ".ServiceAbility", + "icon": "$media:icon", + "srcLanguage": "ets", + "description": "$string:description_serviceability", + "type": "service" + }, + { + "srcPath": "ServiceAbility2", + "name": ".ServiceAbility2", + "icon": "$media:icon", + "srcLanguage": "ets", + "description": "$string:description_serviceability2", + "type": "service" + }, + { + "srcPath": "ServiceAbility3", + "name": ".ServiceAbility3", + "icon": "$media:icon", + "srcLanguage": "ets", + "description": "$string:description_serviceability3", + "type": "service" + }, + { + "srcPath": "ServiceAbility4", + "name": ".ServiceAbility4", + "icon": "$media:icon", + "srcLanguage": "ets", + "description": "$string:description_serviceability4", + "type": "service" + }, + { + "srcPath": "ServiceAbility5", + "name": ".ServiceAbility5", + "icon": "$media:icon", + "srcLanguage": "ets", + "description": "$string:description_serviceability5", + "type": "service" + }, + { + "srcPath": "ServiceAbility6", + "name": ".ServiceAbility6", + "icon": "$media:icon", + "srcLanguage": "ets", + "description": "$string:description_serviceability6", + "type": "service" + }, + { + "srcPath": "ServiceAbility7", + "name": ".ServiceAbility7", + "icon": "$media:icon", + "srcLanguage": "ets", + "description": "$string:description_serviceability7", + "type": "service" + } + ], + "js": [ + { + "mode": { + "syntax": "ets", + "type": "pageAbility" + }, + "pages": [ + "pages/index" + ], + "name": "MainAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + }, + { + "mode": { + "syntax": "ets", + "type": "pageAbility" + }, + "pages": [ + "pages/index" + ], + "name": ".MainAbility2", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ], + "defPermissions": [ + { + "name": "com.ohos.acecollaboration.DataAbilityShellProvider.PROVIDER" + } + ] + } +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/app.ets b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/app.ets new file mode 100644 index 0000000000000000000000000000000000000000..5d603333c7bf5167e7d1d3ead6c9daa9c4b2862d --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/app.ets @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2021 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 default { + onCreate() { + console.info('Application onCreate') + }, + onDestroy() { + console.info('Application onDestroy') + }, +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/pages/index.ets b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..a4ac0111471b4f1f725a67debb3f8d9fa2e80fa4 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/pages/index.ets @@ -0,0 +1,172 @@ +/** + * Copyright (c) 2021 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 file from '@system.file'; +import {Core, ExpectExtend, ReportExtend} from "deccjsunit/index.ets"; +import testsuite from "../test/List.test.ets"; +import featureAbility from "@ohos.ability.featureAbility"; + +async function startService2() { + var str = { + "want": { + "bundleName": "com.ohos.acecollaboration", + "abilityName": "com.ohos.acecollaboration.ServiceAbility2", + }, + }; + var data = featureAbility.startAbility(str); + console.info('particleAbility_connectAbility_test_0100 startAbility succeeded: ' + JSON.stringify(data)); +} +async function startService3() { + var str = { + "want": { + "bundleName": "com.ohos.acecollaboration", + "abilityName": "com.ohos.acecollaboration.ServiceAbility3", + }, + }; + var data = featureAbility.startAbility(str); + console.info('particleAbility_connectAbility_test_0200 startAbility succeeded: ' + JSON.stringify(data)); +} +async function startService4() { + var str = { + "want": { + "bundleName": "com.ohos.acecollaboration", + "abilityName": "com.ohos.acecollaboration.ServiceAbility4", + }, + }; + var data = featureAbility.startAbility(str); + console.info('particleAbility_connectAbility_test_0300 startAbility succeeded: ' + JSON.stringify(data)); +} +async function startService5() { + var str = { + "want": { + "bundleName": "com.ohos.acecollaboration", + "abilityName": "com.ohos.acecollaboration.ServiceAbility5", + }, + }; + var data = featureAbility.startAbility(str); + console.info('particleAbility_connectAbility_test_0400 startAbility succeeded: ' + JSON.stringify(data)); +} +async function startService6(){ + var str = { + "want": { + "bundleName": "com.ohos.acecollaboration", + "abilityName": "com.ohos.acecollaboration.ServiceAbility6", + }, + }; + var data = featureAbility.startAbility(str); + console.info('particleAbility_connectAbility_test_0500 startAbility succeeded: ' + JSON.stringify(data)); +} +async function startService7(){ + var str = { + "want": { + "bundleName": "com.ohos.acecollaboration", + "abilityName": "com.ohos.acecollaboration.ServiceAbility7", + }, + }; + var data = featureAbility.startAbility(str); + console.info('particleAbility_connectAbility_test_0600 startAbility succeeded: ' + JSON.stringify(data)); +} + +@Entry +@Component +struct MyComponent { + aboutToAppear() { + console.info("start run testcase!!!!") + featureAbility.getWant() + .then((Want) => { + const core = Core.getInstance(); + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }); + core.addService('expect', expectExtend); + const reportExtend = new ReportExtend(file); + core.addService('report', reportExtend); + core.init(); + core.subscribeEvent('task', reportExtend); + const configService = core.getDefaultService('config'); + console.info('parameters---->' + JSON.stringify(Want.parameters)); + configService.setConfig(Want.parameters); + testsuite(); + core.execute(); + console.info('Operation successful. Data: ' + JSON.stringify(Want)); + }) + .catch((error) => { + console.error('Operation failed. Cause: ' + JSON.stringify(error)); + }) + } + + build() { + Flex({ + direction: FlexDirection.Column, + alignItems: ItemAlign.Center, + justifyContent: FlexAlign.Center + }) { + Text('ACE ETS TEST 组件协同') + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button('disconnectAbility_promise') + .fontSize(40) + .height(40) + .margin({ top: 20 }) + .fontWeight(FontWeight.Bold) + .onClick(() => { + startService2(); + }); + Button('disconnectAbility_callback') + .fontSize(40) + .height(40) + .margin({ top: 20 }) + .fontWeight(FontWeight.Bold) + .onClick(() => { + startService3(); + }); + Button('connectotherAbility') + .fontSize(40) + .height(40) + .margin({ top: 20 }) + .fontWeight(FontWeight.Bold) + .onClick(() => { + startService4(); + }); + Button('connectnull') + .fontSize(40) + .height(40) + .margin({ top: 20 }) + .fontWeight(FontWeight.Bold) + .onClick(() => { + startService5(); + }); + Button('connecterror') + .fontSize(40) + .height(40) + .margin({top:20}) + .fontWeight(FontWeight.Bold) + .onClick(() => { + startService6(); + }); + Button('connectAPI8') + .fontSize(40) + .height(40) + .margin({top:20}) + .fontWeight(FontWeight.Bold) + .onClick(() => { + startService7(); + }); + + } + .width('100%') + .height('100%') + } +} + diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/ContextJsunit.test.ets b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/ContextJsunit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..bcf072662fb6f4c67f9e3d538ea2c8800f4a1de6 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/ContextJsunit.test.ets @@ -0,0 +1,249 @@ +/** + * Copyright (c) 2021 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 featureAbility from '@ohos.ability.featureAbility' +import {describe, beforeEach, afterEach, it, expect} from "deccjsunit/index.ets"; +import Utils from './Utils'; + +export default function contextJsunit() { + describe('appInfoTest', function () { + beforeEach(async function (done) { + console.info("context before each called"); + done() + }); + + afterEach(async function () { + await Utils.sleep(2000); + console.info("context after each called"); + }); + + /* + * @tc.number: context_getCacheDir_test_0100 + * @tc.name: getCacheDir : Obtains the Cache directory on internal storage. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it("context_getCacheDir_test_0100", 0, async function (done) { + console.log("------------------start context_getCacheDir_test_0100-------------------"); + try { + var timeOldStamp = await Utils.getNowTime(); + var context = await featureAbility.getContext(); + context.getCacheDir().then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('context_getCacheDir_test_0100', timeOldStamp, timeNewStamp) + console.log("context_getCacheDir_test_0100: CacheDir is " + data); + }) + } catch (error) { + console.log("logMessage context_getCacheDir_test_0100: error = " + error); + expect(error).assertEqual("/data/accounts/account_0/appdata/com.ohos.acecollaboration/cache"); + } + var data1 = await context.getCacheDir(); + expect(typeof (data1)).assertEqual("string"); + expect(data1).assertEqual("/data/accounts/account_0/appdata/com.ohos.acecollaboration/cache"); + done(); + console.log("------------------end context_getCacheDir_test_0100-------------------"); + }); + + /* + * @tc.number: context_getCacheDir_test_0200 + * @tc.name: getCacheDir : Obtains the Cache directory on internal storage. + * @tc.desc: Check the return value of the interface (by AsyncCallback) + * @tc.level 0 + */ + it("context_getCacheDir_test_0200", 0, async function (done) { + console.log("------------------start context_getCacheDir_test_0200-------------------"); + try { + var timeOldStamp = await Utils.getNowTime(); + var context = await featureAbility.getContext(); + context.getCacheDir((err, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('context_getCacheDir_test_0200', timeOldStamp, timeNewStamp) + console.log("context_getCacheDir_test_0200: getCacheDir successful, result = " + data); + }); + } catch (error) { + console.log("logMessage context_getCacheDir_test_0200: error = " + error); + expect(error).assertEqual("/data/accounts/account_0/appdata/com.ohos.acecollaboration/cache"); + } + var data1 = await context.getCacheDir(); + expect(typeof (data1)).assertEqual("string"); + expect(data1).assertEqual("/data/accounts/account_0/appdata/com.ohos.acecollaboration/cache"); + done(); + console.log("------------------end context_getCacheDir_test_0200-------------------"); + }); + + /* + * @tc.number: context_getFilesDir_test_0100 + * @tc.name: getFilesDir : Obtains the files directory on internal storage. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it("context_getFilesDir_test_0100", 0, async function (done) { + console.log("------------------start context_getFilesDir_test_0100-------------------"); + try { + var timeOldStamp = await Utils.getNowTime(); + var context = await featureAbility.getContext(); + context.getFilesDir().then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('context_getFilesDir_test_0100', timeOldStamp, timeNewStamp) + console.log("context_getFilesDir_test_0100:FilesDir is " + data); + }) + } catch (error) { + console.log("logMessage context_getFilesDir_test_0100: error = " + error); + expect(error).assertEqual("/data/accounts/account_0/appdata/com.ohos.acecollaboration/files"); + } + var data1 = await context.getFilesDir(); + expect(typeof (data1)).assertEqual("string"); + expect(data1).assertEqual("/data/accounts/account_0/appdata/com.ohos.acecollaboration/files"); + done(); + console.log("------------------end context_getFilesDir_test_0100-------------------"); + }); + + /* + * @tc.number: context_getFilesDir_test_0200 + * @tc.name: getFilesDir : Obtains the files directory on internal storage. + * @tc.desc: Check the return value of the interface (by AsyncCallback) + * @tc.level 0 + */ + it("context_getFilesDir_test_0200", 0, async function (done) { + console.log("------------------start context_getFilesDir_test_0200-------------------"); + try { + var timeOldStamp = await Utils.getNowTime(); + var context = await featureAbility.getContext(); + context.getFilesDir((err, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('context_getFilesDir_test_0200', timeOldStamp, timeNewStamp) + console.log("context_getFilesDir_test_0200: getFilesDir successful, result = " + data); + }); + } catch (error) { + console.log("logMessage context_getFilesDir_test_0200: error = " + error); + expect(error).assertEqual("/data/accounts/account_0/appdata/com.ohos.acecollaboration/files"); + } + var data1 = await context.getFilesDir(); + expect(typeof (data1)).assertEqual("string"); + expect(data1).assertEqual("/data/accounts/account_0/appdata/com.ohos.acecollaboration/files"); + done(); + console.log("------------------end context_getFilesDir_test_0200-------------------"); + }); + + + /* + * @tc.number: context_getOrCreateDistributedDir_test_0100 + * @tc.name: getOrCreateDistributedDir : Obtains the directory of Distributed files. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it("context_getOrCreateDistributedDir_0100", 0, async function (done) { + console.log("------------------start context_getOrCreateDistributedDir_0100-------------------"); + try { + var timeOldStamp = await Utils.getNowTime(); + var context = await featureAbility.getContext(); + context.getOrCreateDistributedDir().then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('context_getOrCreateDistributedDir_0100', timeOldStamp, timeNewStamp); + console.log("context_getOrCreateDistributedDir_0100: DistributedDir is " + data); + }) + } catch (error) { + console.log("logMessage context_getOrCreateDistributedDir_0100: error = " + error); + expect(error).assertEqual("/data/storage/el2/distributedfiles/entry"); + } + var data1 = await context.getOrCreateDistributedDir(); + expect(typeof (data1)).assertEqual("string"); + expect(data1).assertEqual("/data/storage/el2/distributedfiles/entry"); + done(); + console.log("------------------end context_getOrCreateDistributedDir_0100-------------------"); + }); + + /* + * @tc.number: context_getOrCreateDistributedDir_0200 + * @tc.name: getOrCreateDistributedDir : Obtains the directory of Distributed files. + * @tc.desc: Check the return value of the interface (by AsyncCallback) + * @tc.level 0 + */ + it("context_getOrCreateDistributedDir_0200", 0, async function (done) { + console.log("------------------start context_getOrCreateDistributedDir_0200-------------------"); + try { + var timeOldStamp = await Utils.getNowTime(); + var context = await featureAbility.getContext(); + context.getOrCreateDistributedDir((err, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('context_getOrCreateDistributedDir_0200', timeOldStamp, timeNewStamp); + console.log("context_getOrCreateDistributedDir_0200: getOrCreateDistributedDir successful, result = " + data); + }); + } catch (error) { + console.log("logMessage context_getOrCreateDistributedDir_0200: error = " + error); + expect(error).assertEqual("/data/storage/el2/distributedfiles/entry"); + } + var data1 = await context.getOrCreateDistributedDir(); + expect(typeof (data1)).assertEqual("string"); + expect(data1).assertEqual("/data/storage/el2/distributedfiles/entry"); + done(); + console.log("------------------end context_getOrCreateDistributedDir_0200-------------------"); + }); + + /* + * @tc.number: context_getAppType_0100 + * @tc.name: getAppType : Obtains the type of current application. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it("context_getAppType_0100", 0, async function (done) { + console.log("------------------start context_getAppType_0100-------------------"); + try { + var timeOldStamp = await Utils.getNowTime(); + var context = await featureAbility.getContext(); + context.getAppType().then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('context_getAppType_0100_0100', timeOldStamp, timeNewStamp); + console.log("context_getAppType_0100: AppType is " + data); + }) + } catch (error) { + console.log("logMessage context_getAppType_0100: error = " + error); + expect(error).assertEqual("system"); + } + var data1 = await context.getAppType(); + expect(typeof (data1)).assertEqual("string"); + expect(data1).assertEqual("system"); + done(); + console.log("------------------end context_getAppType_0100-------------------"); + }); + + /* + * @tc.number: context_getAppType_0200 + * @tc.name: getAppType : Obtains the type of current application. + * @tc.desc: Check the return value of the interface (by AsyncCallback) + * @tc.level 0 + */ + it("context_getAppType_0200", 0, async function (done) { + console.log("------------------start context_getAppType_0200-------------------"); + try { + var timeOldStamp = await Utils.getNowTime(); + var context = await featureAbility.getContext(); + context.getAppType((err, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('context_getAppType_0200_0100', timeOldStamp, timeNewStamp); + console.log("context_getAppType_0200: getAppType successful, result = " + data); + }); + } catch (error) { + console.log("logMessage context_getAppType_0200: error = " + error); + expect(error).assertEqual("system"); + } + var data1 = await context.getAppType(); + expect(typeof (data1)).assertEqual("string"); + expect(data1).assertEqual("system"); + done(); + console.log("------------------end context_getAppType_0200-------------------"); + }); + }) +} diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/DataAbility.test.ets b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/DataAbility.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f8ed690f0e208ab7048cf556a52abcfdf37be511 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/DataAbility.test.ets @@ -0,0 +1,818 @@ +/** + * Copyright (c) 2021 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 featureAbility from '@ohos.ability.featureAbility' +import {describe, expect, it} from 'deccjsunit/index.ets' + +const URI_CONTACTS = 'dataability:///com.ohos.contactsdataability'; +const contactUri = 'dataability:///com.ohos.contactsdataability/contacts/groups'; +const contactUri2 = 'dataability:///com.ohos.contactsdataability/contacts/groups2'; +import Utils from './Utils'; + +const INSERT_ONE = 'dataAbility_insert_test '; +const QUERY_TWO = 'dataAbility_query_test '; +const UPDATE_THREE = 'dataAbility_update_test '; +const DELETE_FOUR = 'dataAbility_delete_test '; + +export default function DataAbilityJsunit() { + var dataAbilityHelper = featureAbility.acquireDataAbilityHelper(URI_CONTACTS); + var pacMap = { + 'group_name': 'test1', + 'ringtone_modify_time': 28 + }; + + var pacMap_3 = { + 'group_name': 'test3', + 'ringtone_modify_time': 20 + }; + + var pacMap_4 = { + 'group_name': 'test4', + 'ringtone_modify_time': 40 + }; + + describe('appInfoTest', function () { + + /* + * @tc.number: dataAbility_insert_test_001 + * @tc.name: call : Inserts a single data record into the database. + * @tc.desc: Check the return value of the interface (by AsyncCallback) + * @tc.level 0 + */ + it(INSERT_ONE + '001', 0, async function (done) { + let details; + let wrong; + console.log(INSERT_ONE + '001 start......'); + var timeOldStamp = await Utils.getNowTime(); + dataAbilityHelper.call(contactUri, 'insert', '', pacMap, (err, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime(INSERT_ONE + '001', timeOldStamp, timeNewStamp); + if (err) { + wrong = err; + console.error(INSERT_ONE + '001 error: ' + JSON.stringify(err)); + } else { + details = data; + console.info(INSERT_ONE + '001 succeeded data: ' + JSON.stringify(data)); + } + }); + await Utils.sleep(1000); + details != null ? expectDetails(details, true, 1) : expectDetails(wrong, true, 2); + done(); + console.log(INSERT_ONE + '001 end ......'); + }); + + /* + * @tc.number: dataAbility_insert_test_002 + * @tc.name: call : Inserts a single data record into the database. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(INSERT_ONE + '002', 0, async function (done) { + let details; + let wrong; + console.log(INSERT_ONE + '002 start......'); + pacMap.group_name = 'test2'; + var timeOldStamp = await Utils.getNowTime(); + dataAbilityHelper.call(contactUri, 'insert', '', pacMap).then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime(INSERT_ONE + '002', timeOldStamp, timeNewStamp); + details = data; + console.info(INSERT_ONE + '002 succeeded data: ' + JSON.stringify(data)); + }).catch((error) => { + wrong = error; + console.error(INSERT_ONE + '002 error: ' + JSON.stringify(error)); + }); + await Utils.sleep(1000); + details != null ? expectDetails(details, true, 1) : expectDetails(wrong, true, 2); + done(); + console.log(INSERT_ONE + '002 end......'); + }); + + /* + * @tc.number: dataAbility_insert_test_003 + * @tc.name: call : Inserts a incorrect uri data record into the database. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + it(INSERT_ONE + '003', 0, async function (done) { + let details; + let wrong; + console.log(INSERT_ONE + '003 start......'); + dataAbilityHelper.call(contactUri2, 'insert', '', pacMap).then((data) => { + details = data + console.info(INSERT_ONE + '003 succeeded: ' + JSON.stringify(data)); + }).catch((error) => { + wrong = error; + console.error(INSERT_ONE + '003 error: ' + JSON.stringify(error)); + }); + await Utils.sleep(1000); + details != null ? expectDetails(details, true, 1) : expectDetails(wrong, true, 2); + done(); + console.log(INSERT_ONE + '003 end......'); + }); + + /* + * @tc.number: dataAbility_insert_test_004 + * @tc.name: call : Inserts a null uri data record into the database. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + it(INSERT_ONE + '004', 0, async function (done) { + let details; + let wrong; + console.log(INSERT_ONE + '004 start......'); + dataAbilityHelper.call('', 'insert', '', pacMap).then((data) => { + details = data; + console.info(INSERT_ONE + '004 succeeded: ' + JSON.stringify(data)); + }).catch((error) => { + wrong = error; + console.error(INSERT_ONE + '004 error: ' + JSON.stringify(error)); + }); + await Utils.sleep(1000); + details != null ? expectDetails(details, true, 1) : expectDetails(wrong, true, 2); + done(); + console.log(INSERT_ONE + '004 end......'); + }); + + /* + * @tc.number: dataAbility_insert_test_005 + * @tc.name: call : Inserts a null methold data record into the database. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + it(INSERT_ONE + '005', 0, async function (done) { + let details; + let wrong; + console.log(INSERT_ONE + '005 start......'); + let pacMap = { + 'group_name': 'test4', + 'ringtone_modify_time': 28 + }; + dataAbilityHelper.call(contactUri, "", "", pacMap).then((data) => { + details = data; + console.info(INSERT_ONE + '005 succeeded: ' + JSON.stringify(data)); + }).catch((error) => { + wrong = error; + console.error(INSERT_ONE + '005 error: ' + JSON.stringify(error)); + }); + await Utils.sleep(1000); + details != null ? expectDetails(details, true, 1) : expectDetails(wrong, true, 2); + done(); + console.log(INSERT_ONE + '005 end......'); + }); + + /* + * @tc.number: dataAbility_query_test_001 + * @tc.name: call : Queries data in the database. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + it(QUERY_TWO + '001', 0, async function (done) { + let details; + let wrong; + console.log(QUERY_TWO + '001 start......'); + let arg = "{\"equalTo\": \"group_name\"}"; + let pacMap = { + "group_name": "test1", + "columns": "group_name,ringtone_modify_time" + }; + var timeOldStamp = await Utils.getNowTime(); + dataAbilityHelper.call(contactUri, 'query', arg, pacMap, (err, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime(QUERY_TWO + '001', timeOldStamp, timeNewStamp); + wrong = err; + if (wrong) { + console.error(QUERY_TWO + '001 error: ' + JSON.stringify(wrong)); + } else { + details = data; + console.info(QUERY_TWO + '001 succeeded: ' + JSON.stringify(data)); + } + }); + await Utils.sleep(1000); + details != null ? expectDetails(details, false, 4) : expectDetails(wrong, true, 2); + done(); + console.log(QUERY_TWO + '001 end......'); + }); + + /* + * @tc.number: dataAbility_query_test_002 + * @tc.name: call : Queries data in the database. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + it(QUERY_TWO + '002', 0, async function (done) { + let details; + let wrong; + console.log(QUERY_TWO + '002 start......'); + let arg = "{\"between\": \"ringtone_modify_time\"}"; + let pacMap = { + 'ringtone_modify_time': "15, 30", + "columns": "group_name,ringtone_modify_time" + }; + var timeOldStamp = await Utils.getNowTime(); + dataAbilityHelper.call(contactUri, 'query', arg, pacMap, (err, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime(QUERY_TWO + '002', timeOldStamp, timeNewStamp); + wrong = err; + if (wrong) { + console.error(QUERY_TWO + '002 error: ' + JSON.stringify(wrong)); + } else { + details = data; + console.info(QUERY_TWO + '002 succeeded: ' + JSON.stringify(data)); + } + }); + await Utils.sleep(1000); + details != null ? expectDetails(details, false, 4) : expectDetails(wrong, true, 2); + done(); + console.log(QUERY_TWO + '002 end......'); + }); + + /* + * @tc.number: dataAbility_query_test_003 + * @tc.name: call : Queries data in the database. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + it(QUERY_TWO + '003', 0, async function (done) { + let details; + let wrong; + console.log(QUERY_TWO + '003 start......'); + let arg = { + 'like': 'group_name' + }; + let pacMap = { + 'group_name': '%test%', + 'columns': 'group_name,ringtone_modify_time' + }; + var timeOldStamp = await Utils.getNowTime(); + dataAbilityHelper.call(contactUri, 'query', arg, pacMap, (err, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime(QUERY_TWO + '003', timeOldStamp, timeNewStamp); + wrong = err; + if (wrong) { + console.error(QUERY_TWO + '003 error: ' + JSON.stringify(wrong)); + } else { + details = data; + console.info(QUERY_TWO + '003 succeeded: ' + JSON.stringify(data)); + } + }); + await Utils.sleep(1000); + details != null ? expectDetails(details, false, 4) : expectDetails(wrong, true, 2); + done(); + console.log(QUERY_TWO + '003 end......'); + }); + + /* + * @tc.number: dataAbility_query_test_004 + * @tc.name: call : Queries data in the database. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + it(QUERY_TWO + '004', 0, async function (done) { + let details; + let wrong; + console.log(QUERY_TWO + '004 start......'); + let arg = { + 'greaterThanOrEqualTo': 'ringtone_modify_time' + }; + let pacMap = { + 'ringtone_modify_time': 20, + 'columns': 'group_name,ringtone_modify_time' + }; + var timeOldStamp = await Utils.getNowTime(); + dataAbilityHelper.call(contactUri, 'query', arg, pacMap, (err, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime(QUERY_TWO + '004', timeOldStamp, timeNewStamp); + if (err) { + wrong = err; + console.error(QUERY_TWO + '004 error: ' + JSON.stringify(err)); + return; + } else { + details = data; + console.info(QUERY_TWO + '004 succeeded: ' + JSON.stringify(data)); + } + }); + await Utils.sleep(1000); + details != null ? expectDetails(details, false, 4) : expectDetails(wrong, true, 2); + done(); + console.log(QUERY_TWO + '004 end......'); + }); + + /* + * @tc.number: dataAbility_query_test_005 + * @tc.name: call : Queries abnormal data in the database. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + it(QUERY_TWO + '005', 0, async function (done) { + let details; + let wrong; + let pacMap = { + 'ringtone_modify_time': 20, + 'columns': 'group_name,ringtone_modify_time' + }; + console.log(INSERT_ONE + '003 start......'); + dataAbilityHelper.call(contactUri2, 'query', '', pacMap).then((data) => { + details = data + console.info(QUERY_TWO + '005 succeeded: ' + JSON.stringify(data)); + }).catch((error) => { + wrong = error; + console.error(QUERY_TWO + '005 error: ' + JSON.stringify(error)); + }); + await Utils.sleep(1000); + details != null ? expectDetails(details, false, 4) : expectDetails(wrong, true, 2); + done(); + console.log(QUERY_TWO + '005 end......'); + }); + + /* + * @tc.number: dataAbility_query_test_006 + * @tc.name: call : Queries abnormal data in the database. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + it(QUERY_TWO + '006', 0, async function (done) { + let details; + let wrong; + let pacMap = { + 'ringtone_modify_time': 20, + 'columns': 'group_name,ringtone_modify_time' + }; + console.log(QUERY_TWO + '004 start......'); + dataAbilityHelper.call('', 'query', '', pacMap).then((data) => { + details = data; + console.info(QUERY_TWO + '006 succeeded: ' + JSON.stringify(data)); + }).catch((error) => { + wrong = error; + console.error(QUERY_TWO + '006 error: ' + JSON.stringify(error)); + }); + await Utils.sleep(1000); + details != null ? expectDetails(details, false, 4) : expectDetails(wrong, true, 2); + done(); + console.log(QUERY_TWO + '006 end......'); + }); + + /* + * @tc.number: dataAbility_update_test_001 + * @tc.name: call : Updates data records in the database. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + it(UPDATE_THREE + '001', 0, async function (done) { + let details; + let wrong; + console.log(UPDATE_THREE + '001 start......'); + let arg = "{\"equalTo\": \"ringtone_modify_time\"}"; + let pacMap = { + 'ringtone_modify_time': 28, + 'group_name': 'testupdata1' + }; + var timeOldStamp = await Utils.getNowTime(); + dataAbilityHelper.call(contactUri, 'update', arg, pacMap, (err, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime(UPDATE_THREE + '001', timeOldStamp, timeNewStamp); + if (err) { + wrong = err; + console.error(UPDATE_THREE + '001 error: ' + JSON.stringify(err)); + } else { + details = data; + console.info(UPDATE_THREE + '001 succeeded: ' + JSON.stringify(data)); + } + }); + await Utils.sleep(1000); + details != null ? expectDetails(details, true, 3) : expectDetails(wrong, true, 2); + done(); + console.log(UPDATE_THREE + '001 end......'); + }); + + /* + * @tc.number: dataAbility_update_test_002 + * @tc.name: call : Updates data records in the database. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + it(UPDATE_THREE + '002', 0, async function (done) { + let details; + let wrong; + console.log(UPDATE_THREE + '002 start......'); + let arg = "{\"between\": \"ringtone_modify_time\"}"; + let pacMap = { + 'ringtone_modify_time': "15, 30", + 'group_name': 'testupdata2' + }; + var timeOldStamp = await Utils.getNowTime(); + dataAbilityHelper.call(contactUri, 'update', arg, pacMap, (err, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime(UPDATE_THREE + '002', timeOldStamp, timeNewStamp); + if (err) { + wrong = err; + console.error(UPDATE_THREE + '002 error: ' + JSON.stringify(err)); + } else { + details = data; + console.info(UPDATE_THREE + '002 succeeded: ' + JSON.stringify(data)); + } + }); + await Utils.sleep(1000); + details != null ? expectDetails(details, true, 3) : expectDetails(wrong, true, 2); + done(); + console.log(UPDATE_THREE + '002 end......'); + }); + + /* + * @tc.number: dataAbility_update_test_003 + * @tc.name: call : Updates data records in the database. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + it(UPDATE_THREE + '003', 0, async function (done) { + let details; + let wrong; + console.log(UPDATE_THREE + '003 start......'); + let arg = { + 'contains': 'group_name' + }; + let pacMap = { + 'group_name': 'ata2', + 'ringtone_modify_time': 100 + }; + var timeOldStamp = await Utils.getNowTime(); + dataAbilityHelper.call(contactUri, 'update', arg, pacMap, (err, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime(UPDATE_THREE + '003', timeOldStamp, timeNewStamp); + if (err) { + wrong = err; + console.error(UPDATE_THREE + '003 error: ' + JSON.stringify(err)); + } else { + details = data; + console.info(UPDATE_THREE + '003 succeeded: ' + JSON.stringify(data)); + } + }); + await Utils.sleep(1000); + details != null ? expectDetails(details, true, 3) : expectDetails(wrong, true, 2); + done(); + console.log(UPDATE_THREE + '003 end......'); + }); + + /* + * @tc.number: dataAbility_update_test_004 + * @tc.name: call : Updates data records in the database. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + it(UPDATE_THREE + '004', 0, async function (done) { + let details; + let wrong; + console.log(UPDATE_THREE + '004 start......'); + let arg = { + 'lessThan': 'ringtone_modify_time' + }; + let pacMap = { + 'ringtone_modify_time': 32, + 'group_name': 'testupdata2' + }; + var timeOldStamp = await Utils.getNowTime(); + dataAbilityHelper.call(contactUri, 'update', arg, pacMap, (err, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime(UPDATE_THREE + '004', timeOldStamp, timeNewStamp); + if (err) { + wrong = err; + console.error(UPDATE_THREE + '004 error: ' + JSON.stringify(err)); + } else { + details = data; + console.info(UPDATE_THREE + '004 succeeded: ' + JSON.stringify(data)); + } + }); + await Utils.sleep(1000); + details != null ? expectDetails(details, true, 3) : expectDetails(wrong, true, 2); + done(); + console.log(UPDATE_THREE + '004 end......'); + }); + + /* + * @tc.number: dataAbility_update_test_005 + * @tc.name: call : Updates abnormal data records in the database. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + it(UPDATE_THREE + '005', 0, async function (done) { + let details; + let wrong; + console.log(UPDATE_THREE + '005 start......'); + + let pacMap = { + 'ringtone_modify_time': 32, + 'group_name': 'testupdata2' + }; + var timeOldStamp = await Utils.getNowTime(); + dataAbilityHelper.call(contactUri2, 'update', '', pacMap, (err, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime(UPDATE_THREE + '005', timeOldStamp, timeNewStamp); + if (err) { + wrong = err; + console.error(UPDATE_THREE + '005 error: ' + JSON.stringify(err)); + } else { + details = data; + console.info(UPDATE_THREE + '005 succeeded: ' + JSON.stringify(data)); + } + }); + await Utils.sleep(1000); + details != null ? expectDetails(details, true, 3) : expectDetails(wrong, true, 2); + done(); + console.log(UPDATE_THREE + '005 end......'); + }); + + /* + * @tc.number: dataAbility_update_test_006 + * @tc.name: call : Updates abnormal data records in the database. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + it(UPDATE_THREE + '006', 0, async function (done) { + let details; + let wrong; + console.log(UPDATE_THREE + '006 start......'); + let pacMap = { + 'ringtone_modify_time': 32, + 'group_name': 'testupdata2' + }; + var timeOldStamp = await Utils.getNowTime(); + dataAbilityHelper.call('', 'update', '', pacMap, (err, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime(UPDATE_THREE + '006', timeOldStamp, timeNewStamp); + if (err) { + wrong = err; + console.error(UPDATE_THREE + '006 error: ' + JSON.stringify(err)); + } else { + details = data; + console.info(UPDATE_THREE + '006 succeeded: ' + JSON.stringify(data)); + } + }); + await Utils.sleep(1000); + details != null ? expectDetails(details, true, 3) : expectDetails(wrong, true, 2); + done(); + console.log(UPDATE_THREE + '006 end......'); + }); + + /* + * @tc.number: dataAbility_delete_test_001 + * @tc.name: call : Deletes one or more data records from the database. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + dataAbilityHelper.call(contactUri, 'insert', '', pacMap, (err, data) => { + if (err) { + console.error('Operation failed1. Cause: ' + JSON.stringify(err)); + return; + } + console.info('Operation succeeded1: ' + JSON.stringify(data)); + }); + it(DELETE_FOUR + '001', 0, async function (done) { + let details; + let wrong; + console.log(DELETE_FOUR + '001 start......'); + let arg2 = "{\"equalTo\": \"group_name\"}"; + let pacMap2 = { + 'group_name': 'test1' + }; + var timeOldStamp = await Utils.getNowTime(); + dataAbilityHelper.call(contactUri, 'delete', arg2, pacMap2, (err2, data2) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime(DELETE_FOUR + '001', timeOldStamp, timeNewStamp); + if (err2) { + wrong = err2; + console.error(DELETE_FOUR + '001 error: ' + JSON.stringify(err2)); + } else { + details = data2; + console.info(DELETE_FOUR + '001 succeeded: ' + JSON.stringify(data2)); + } + }); + await Utils.sleep(1000); + details != null ? expectDetails(details, true, 3) : expectDetails(wrong, true, 2); + done(); + console.log(DELETE_FOUR + '001 end......'); + }); + + /* + * @tc.number: dataAbility_delete_test_002 + * @tc.name: call : Deletes one or more data records from the database. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + it(DELETE_FOUR + '002', 0, async function (done) { + let details; + let wrong + console.log(DELETE_FOUR + '002 start......'); + let arg = "{\"lessThan\": \"ringtone_modify_time\"}"; + let pacMap = { + 'ringtone_modify_time': 32, + }; + var timeOldStamp = await Utils.getNowTime(); + dataAbilityHelper.call(contactUri, 'delete', arg, pacMap, (err, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime(DELETE_FOUR + '002', timeOldStamp, timeNewStamp); + if (err) { + wrong = err; + console.error(DELETE_FOUR + '002 error: ' + JSON.stringify(err)); + } else { + details = data; + console.info(DELETE_FOUR + '002 succeeded: ' + JSON.stringify(data)); + } + }); + await Utils.sleep(1000); + details != null ? expectDetails(details, true, 3) : expectDetails(wrong, true, 2); + done(); + console.log(DELETE_FOUR + '002 end......'); + }); + + /* + * @tc.number: dataAbility_delete_test_003 + * @tc.name: call : Deletes one or more data records from the database. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + dataAbilityHelper.call(contactUri, 'insert', '', pacMap_3, (err, data) => { + if (err) { + console.error('Operation failed3. Cause: ' + JSON.stringify(err)); + return; + } + console.info('Operation succeeded3: ' + JSON.stringify(data)); + }); + it(DELETE_FOUR + '003', 0, async function (done) { + let details; + let wrong; + console.log(DELETE_FOUR + '003 start......'); + let arg2 = { + 'like': 'group_name' + }; + let pacMap2 = { + 'group_name': '%test%' + }; + var timeOldStamp = await Utils.getNowTime(); + dataAbilityHelper.call(contactUri, 'delete', arg2, pacMap2, (err2, data2) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime(DELETE_FOUR + '003', timeOldStamp, timeNewStamp); + if (err2) { + wrong = err2; + console.error(DELETE_FOUR + '003 error: ' + JSON.stringify(err2)); + } else { + details = data2; + console.info(DELETE_FOUR + '003 delete succeeded: ' + JSON.stringify(data2)); + } + }); + await Utils.sleep(1000); + details != null ? expectDetails(details, true, 3) : expectDetails(wrong, true, 2); + done(); + console.log(DELETE_FOUR + '003 delete end......'); + }); + + /* + * @tc.number: dataAbility_delete_test_004 + * @tc.name: call : Deletes one or more data records from the database. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + dataAbilityHelper.call(contactUri, 'insert', '', pacMap_4, (err, data) => { + if (err) { + console.error('Operation failed4. Cause: ' + JSON.stringify(err)); + return; + } + console.info('Operation succeeded4: ' + JSON.stringify(data)); + }); + it(DELETE_FOUR + '004', 0, async function (done) { + let details; + let wrong; + console.log(DELETE_FOUR + '004 start......'); + let arg2 = { + 'greaterThanOrEqualTo': 'ringtone_modify_time' + }; + let pacMap2 = { + 'ringtone_modify_time': 40 + }; + var timeOldStamp = await Utils.getNowTime(); + dataAbilityHelper.call(contactUri, 'delete', arg2, pacMap2, (err2, data2) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime(DELETE_FOUR + '004', timeOldStamp, timeNewStamp); + if (err2) { + wrong = err2; + console.error(DELETE_FOUR + '004 error: ' + JSON.stringify(err2)); + } else { + details = data2; + console.info(DELETE_FOUR + '004 delete succeeded: ' + JSON.stringify(data2)); + } + }); + await Utils.sleep(1000); + details != null ? expectDetails(details, true, 3) : expectDetails(wrong, true, 2); + done(); + console.log(DELETE_FOUR + '004 delete end......'); + }); + + /* + * @tc.number: dataAbility_delete_test_005 + * @tc.name: call : Deletes abnormal data records from the database. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + dataAbilityHelper.call(contactUri, 'insert', '', pacMap_4, (err, data) => { + if (err) { + console.error('Operation failed4. Cause: ' + JSON.stringify(err)); + return; + } + console.info('Operation succeeded5: ' + JSON.stringify(data)); + }); + it(DELETE_FOUR + '005', 0, async function (done) { + let details; + let wrong; + console.log(DELETE_FOUR + '005 start......'); + let pacMap2 = { + 'ringtone_modify_time': 40 + }; + var timeOldStamp = await Utils.getNowTime(); + dataAbilityHelper.call(contactUri2, 'delete', '', pacMap2, (err2, data2) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime(DELETE_FOUR + '005', timeOldStamp, timeNewStamp); + if (err2) { + wrong = err2; + console.error(DELETE_FOUR + '005 error: ' + JSON.stringify(err2)); + } else { + details = data2; + console.info(DELETE_FOUR + '005 delete succeeded: ' + JSON.stringify(data2)); + } + }); + await Utils.sleep(1000); + details != null ? expectDetails(details, true, 3) : expectDetails(wrong, true, 2); + done(); + console.log(DELETE_FOUR + '005 delete end......'); + }); + + /* + * @tc.number: dataAbility_delete_test_006 + * @tc.name: call : Deletes abnormal data records from the database. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + dataAbilityHelper.call(contactUri, 'insert', '', pacMap_4, (err, data) => { + if (err) { + console.error('Operation failed4. Cause: ' + JSON.stringify(err)); + return; + } + console.info('Operation succeeded4: ' + JSON.stringify(data)); + }); + it(DELETE_FOUR + '006', 0, async function (done) { + let details; + let wrong; + console.log(DELETE_FOUR + '006 start......'); + let pacMap2 = { + 'ringtone_modify_time': 40 + }; + var timeOldStamp = await Utils.getNowTime(); + dataAbilityHelper.call('', 'delete', '', pacMap2, (err2, data2) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime(DELETE_FOUR + '006', timeOldStamp, timeNewStamp); + if (err2) { + wrong = err2; + console.error(DELETE_FOUR + '006 error: ' + JSON.stringify(err2)); + } else { + details = data2; + console.info(DELETE_FOUR + '006 delete succeeded: ' + JSON.stringify(data2)); + } + }); + await Utils.sleep(1000); + details != null ? expectDetails(details, true, 3) : expectDetails(wrong, true, 2); + done(); + console.log(DELETE_FOUR + '006 delete end......'); + }); + }) + + function expectDetails(data, isTrue, keyStatus) { + if (data != -1) { + expect(typeof (data)).assertEqual("object"); + expect(typeof (data.result)).assertEqual(isTrue ? 'number' : 'string'); + } + switch (keyStatus) { + case 1: + expect(data.result > 0).assertTrue(); + break + + case 2: + expect(data == -1).assertTrue(); + break + + case 3: + expect(data.result).assertEqual(0); + break + } + } +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/List.test.ets b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..023315f7c62d5e8ca4b19fef1d668d6c9dc74d82 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/List.test.ets @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2021 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 addContextAndAbilityJsunit from './addContextAndAbilityJsunit.test.ets'; +import getHapModuleInfoJsunit from './getHapModuleInfoJsunit.test.ets'; +import getAbilityInfoJsunit from './getAbilityInfoJsunit.test.ets'; +import getApplicationContext from './getApplicationContextJsunit.test.ets'; +import getAppVersionInfoJsunit from './getAppVersionInfoJsunit.test.ets'; +import ContextJsunit from './ContextJsunit.test.ets'; +import DataAbilityJsunit from './DataAbility.test.ets'; + +export default function testsuite() { + ContextJsunit(); + DataAbilityJsunit(); + addContextAndAbilityJsunit(); + getHapModuleInfoJsunit(); + getAbilityInfoJsunit(); + getApplicationContext(); + getAppVersionInfoJsunit(); +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/Utils.ets b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/Utils.ets new file mode 100644 index 0000000000000000000000000000000000000000..d347b04062965c665153e7ac358028d6ae274d53 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/Utils.ets @@ -0,0 +1,47 @@ +/** + * Copyright (c) 2021 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 default class Utils { + static sleep(time) { + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve(reject) + }, time) + }).then(() => { + console.info(`sleep ${time} over...`) + }) + } + + static getNowTime() { + return new Date().getTime(); + } + + /** + * 接口调用时间 + * @param startTime 接口调用开始时间 + * @param endTime 接口调用结束时间 + */ + static getDurationTime(msg, startTime, endTime) { + console.info(msg + 'Get Interface startTime: ' + startTime); + console.info(msg + 'Get Interface endTime: ' + endTime); + var duration = (endTime - startTime) + console.info(msg + 'Get Interface Duration: ' + duration); + return duration; + } +} + + + + diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/addContextAndAbilityJsunit.test.ets b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/addContextAndAbilityJsunit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..8aaedaf046defd0f66645c3170fe2ab31c05b222 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/addContextAndAbilityJsunit.test.ets @@ -0,0 +1,300 @@ +/** + * Copyright (c) 2021 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 {describe, it, expect} from "deccjsunit/index.ets"; +import Utils from './Utils'; +import ability_featureAbility from '@ohos.ability.featureAbility'; +import abilityManager from "@ohos.app.abilitymanager" + +const TAG_TEST_0100 = ' context_isUpdatingConfigurations_test_0100 '; +const TAG_TEST_0200 = ' context_isUpdatingConfigurations_test_0200 '; +const TAG_TEST_0300 = ' context_printDrawnCompleted_test_0100 '; +const TAG_TEST_0400 = ' context_printDrawnCompleted_test_0200 '; +const TAG_TEST_0500 = ' context_getAppMemorySize_test_0100 '; +const TAG_TEST_0600 = ' context_getAppMemorySize_test_0200 '; +const TAG_TEST_0700 = ' context_isRamConstrainedDevice_test_0100 '; +const TAG_TEST_0800 = ' context_isRamConstrainedDevice_test_0200 '; +const TAG_TEST_0900 = ' context_featureAbility_test_0100 '; +const TAG_TEST_0010 = ' context_featureAbility_test_0200 '; +const TAG_TEST_0011 = ' context_featureAbility_test_0300 '; +const TAG_TEST_0012 = ' context_featureAbility_test_0400 '; + +export default function addContextAndAbilityJsunit() { + describe('appInfoTest', function () { + /* + * @tc.number: context_isUpdatingConfigurations_test_0100 + * @tc.name: isUpdatingConfigurations : Obtains whether the configuration of the current ability is changing. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(TAG_TEST_0100, 0, async function (done) { + console.info(TAG_TEST_0100 + 'promise START'); + let detailed; + var startTime = await Utils.getNowTime(); + var context = ability_featureAbility.getContext(); + await context.isUpdatingConfigurations().then((data) => { + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0100, startTime, endTime) + console.info(TAG_TEST_0100 + ' promise data is:' + JSON.stringify(data)); + detailed = data; + }).catch((error) => { + console.error(TAG_TEST_0100 + 'promise errors is: ' + JSON.stringify(error)); + }) + expect(typeof (detailed)).assertEqual("boolean"); + expect(detailed).assertEqual(false); + done(); + console.log('------------------ ' + TAG_TEST_0100 + ' end -------------------'); + }); + + /* + * @tc.number: context_isUpdatingConfigurations_test_0200 + * @tc.name: isUpdatingConfigurations : Obtains whether the configuration of the current ability is changing. + * @tc.desc: Check the return value of the interface (by AsyncCallback) + * @tc.level 0 + */ + it(TAG_TEST_0200, 0, async function (done) { + let detailed; + console.info(TAG_TEST_0200 + 'callBack START'); + try { + var startTime = await Utils.getNowTime(); + var context = ability_featureAbility.getContext(); + context.isUpdatingConfigurations((error, data) => { + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0200, startTime, endTime) + detailed = data; + console.info(TAG_TEST_0200 + ' callBack succeeded. data is:' + JSON.stringify(data)); + }); + } catch (error) { + console.error(TAG_TEST_0200 + 'Operation failed. Cause: ' + JSON.stringify(error)); + } + await Utils.sleep(2000) + expect(typeof (detailed)).assertEqual("boolean"); + expect(detailed).assertEqual(false); + done(); + console.log('------------------ ' + TAG_TEST_0200 + ' end -------------------'); + }); + + /* + * @tc.number: context_printDrawnCompleted_test_0100 + * @tc.name: printDrawnCompleted : Inform the system of the time required to complete the drawing of the page + capability. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(TAG_TEST_0300, 0, async function (done) { + let detailed; + console.info(TAG_TEST_0300 + 'callBack START'); + var startTime = await Utils.getNowTime(); + var context = ability_featureAbility.getContext(); + await context.printDrawnCompleted().then((data) => { + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0300, startTime, endTime) + console.info(TAG_TEST_0300 + ' promise data is:' + JSON.stringify(data)); + detailed = data; + }).catch((error) => { + console.error(TAG_TEST_0300 + 'promise error is: ' + JSON.stringify(error)); + }); + await Utils.sleep(2000) + expect(detailed).assertEqual(null); + done(); + console.log('------------------ ' + TAG_TEST_0300 + ' end -------------------'); + }) + + + /* + * @tc.number: context_printDrawnCompleted_test_0200 + * @tc.name: printDrawnCompleted : Inform the system of the time required to complete the drawing of the page + capability. + * @tc.desc: Check the return value of the interface (by AsyncCallback) + * @tc.level 0 + */ + it(TAG_TEST_0400, 0, async function (done) { + let detailed; + console.info(TAG_TEST_0400 + 'callBack START'); + try { + var startTime = await Utils.getNowTime(); + var context = ability_featureAbility.getContext(); + context.printDrawnCompleted((error, data) => { + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0300, startTime, endTime) + detailed = data; + console.info(TAG_TEST_0400 + ' callBack succeeded. data is:' + JSON.stringify(data)); + }); + } catch (error) { + console.error(TAG_TEST_0400 + 'Operation failed. Cause: ' + JSON.stringify(error)); + } + await Utils.sleep(2000) + expect(detailed).assertEqual(null); + done(); + console.log('------------------ ' + TAG_TEST_0400 + ' end -------------------'); + }) + + + /* + * @tc.number: context_getAppMemorySize_test_0100 + * @tc.name: getAppMemorySize : Obtains the memory size of the application. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(TAG_TEST_0500, 0, async function (done) { + console.info(TAG_TEST_0500 + 'promise START'); + let detailed; + var startTime = await Utils.getNowTime(); + await abilityManager.getAppMemorySize() + .then((data) => { + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0500, startTime, endTime) + console.info(TAG_TEST_0500 + ' promise data is:' + JSON.stringify(data)); + detailed = data; + }).catch((error) => { + console.error(TAG_TEST_0500 + 'promise errors is: ' + JSON.stringify(error)); + }) + await Utils.sleep(2000) + expect(typeof (detailed)).assertEqual("number"); + expect(detailed).assertEqual(512); + done(); + console.log('------------------ ' + TAG_TEST_0500 + ' end -------------------'); + }); + + /* + * @tc.number: context_getAppMemorySize_test_0200 + * @tc.name: getAppMemorySize : Obtains the memory size of the application. + * @tc.desc: Check the return value of the interface (by AsyncCallback) + * @tc.level 0 + */ + it(TAG_TEST_0600, 0, async function (done) { + console.info(TAG_TEST_0600 + 'callBack START'); + var startTime = await Utils.getNowTime(); + abilityManager.getAppMemorySize((error, data) => { + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0500, startTime, endTime) + console.info(TAG_TEST_0600 + ' callBack error is: ' + JSON.stringify(error)); + console.info(TAG_TEST_0600 + ' callBack data is:' + JSON.stringify(data)); + expect(typeof (data)).assertEqual("number"); + expect(data).assertEqual(512); + console.log('------------------ ' + TAG_TEST_0600 + ' end -------------------'); + done(); + }) + }); + + /* + * @tc.number: context_isRamConstrainedDevice_test_0100 + * @tc.name: isRamConstrainedDevice : Obtains whether the current device has low ram. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(TAG_TEST_0700, 0, async function (done) { + let detailed; + console.info(TAG_TEST_0700 + 'promise START'); + var startTime = await Utils.getNowTime(); + await abilityManager.isRamConstrainedDevice().then((data) => { + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0500, startTime, endTime) + console.info(TAG_TEST_0700 + ' promise data is:' + JSON.stringify(data)); + detailed = data; + }).catch((error) => { + console.error(TAG_TEST_0700 + 'promise errors is: ' + JSON.stringify(error)); + }) + await Utils.sleep(1000) + expect(typeof (detailed)).assertEqual("boolean"); + expect(detailed).assertEqual(false) + done(); + console.log('------------------ ' + TAG_TEST_0700 + ' end -------------------'); + }); + + /* + * @tc.number: context_isRamConstrainedDevice_test_0200 + * @tc.name: isRamConstrainedDevice : Obtains whether the current device has low ram. + * @tc.desc: Check the return value of the interface (by AsyncCallback) + * @tc.level 0 + */ + it(TAG_TEST_0800, 0, async function (done) { + console.info(TAG_TEST_0800 + 'callBack START'); + var startTime = await Utils.getNowTime(); + abilityManager.isRamConstrainedDevice((error, data) => { + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0500, startTime, endTime) + console.info(TAG_TEST_0800 + ' callBack error is:' + error); + console.info(TAG_TEST_0800 + ' callBack data is:' + JSON.stringify(data)); + expect(typeof (data)).assertEqual("boolean"); + expect(data).assertEqual(false); + done(); + }) + console.log('------------------ ' + TAG_TEST_0800 + ' end -------------------'); + }); + /* + * @tc.number: context_featureAbility_test_0100 + * @tc.name: featureAbility.ErrorCode : featureAbility.ErrorCode + * @tc.desc: Check the featureAbility.ErrorCode.NO_ERROR + * @tc.level 0 + */ + it(TAG_TEST_0900, 0, async function (done) { + console.info(TAG_TEST_0900 + ' NO_ERROR START'); + var no_error = ability_featureAbility.ErrorCode.NO_ERROR + console.info(TAG_TEST_0900 + ' featureAbility no_error is: ' + no_error); + expect(typeof (no_error)).assertEqual("number"); + expect(no_error).assertEqual(0); + done(); + console.log('------------------ ' + TAG_TEST_0900 + ' end -------------------'); + }); + + /* + * @tc.number: context_featureAbility_test_0200 + * @tc.name: featureAbility.ErrorCode : featureAbility.ErrorCode + * @tc.desc: Check the featureAbility.ErrorCode.INVALID_PARAMETER + * @tc.level 0 + */ + it(TAG_TEST_0010, 0, async function (done) { + console.info(TAG_TEST_0010 + ' INVALID_PARAMETER START'); + var invalid_parameter = ability_featureAbility.ErrorCode.INVALID_PARAMETER + console.info(TAG_TEST_0010 + ' featureAbility invalid_parameter is: ' + invalid_parameter); + expect(typeof (invalid_parameter)).assertEqual("number"); + expect(invalid_parameter).assertEqual(-1); + done(); + console.log('------------------ ' + TAG_TEST_0010 + ' end -------------------'); + }); + + /* + * @tc.number: context_featureAbility_test_0300 + * @tc.name: featureAbility.ErrorCode : featureAbility.ErrorCode + * @tc.desc: Check the featureAbility.ErrorCode.ABILITY_NOT_FOUND + * @tc.level 0 + */ + it(TAG_TEST_0011, 0, async function (done) { + console.info(TAG_TEST_0011 + ' ABILITY_NOT_FOUND START'); + var ability_not_found = ability_featureAbility.ErrorCode.ABILITY_NOT_FOUND + console.info(TAG_TEST_0011 + ' featureAbility ability_not_found is: ' + ability_not_found); + expect(typeof (ability_not_found)).assertEqual("number"); + expect(ability_not_found).assertEqual(-2); + done(); + console.log('------------------ ' + TAG_TEST_0011 + ' end -------------------'); + }); + + /* + * @tc.number: context_featureAbility_test_0400 + * @tc.name: featureAbility.ErrorCode : featureAbility.ErrorCode + * @tc.desc: Check the featureAbility.ErrorCode.PERMISSION_DENY + * @tc.level 0 + */ + it(TAG_TEST_0012, 0, async function (done) { + console.info(TAG_TEST_0012 + ' PERMISSION_DENY START'); + var permission_deny = ability_featureAbility.ErrorCode.PERMISSION_DENY + console.info(TAG_TEST_0012 + ' featureAbility permission_deny is: ' + permission_deny); + expect(typeof (permission_deny)).assertEqual("number"); + expect(permission_deny).assertEqual(-3); + done(); + console.log('------------------ ' + TAG_TEST_0012 + ' end -------------------'); + }); + }) +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/getAbilityInfoJsunit.test.ets b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/getAbilityInfoJsunit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..447fc3ba91a560f2422bc4eba3d83b82063c4cf8 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/getAbilityInfoJsunit.test.ets @@ -0,0 +1,333 @@ +/** + * Copyright (c) 2021 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 {describe, it, expect} from "deccjsunit/index.ets"; +import Utils from './Utils'; +import ability_featureAbility from '@ohos.ability.featureAbility'; + +export default function getHapModuleInfoJsunit() { + describe('appInfoTest', function () { + + /** + * @tc.number: context_getAbilityInfo_test_0100 + * @tc.name: getAbilityInfo:Query the current attributionability details. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it('context_getAbilityInfo_test_0100', 0, async function (done) { + console.info('[context_getAbilityInfo_test_0100] START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + var context = ability_featureAbility.getContext(); + await context.getAbilityInfo() + .then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('context_getAbilityInfo_test_0100', timeOldStamp, timeNewStamp); + console.info('[context_getAbilityInfo_test_0100] data is:' + JSON.stringify(data)); + expect(typeof (data)).assertEqual("object"); + }).catch((error) => { + console.error('[context_getAbilityInfo_test_0100] failed:' + JSON.stringify(error)); + }) + var promise = await context.getAbilityInfo(); + console.info('--[context_getAbilityInfo_test_0100] check---'); + checkAbilityInfo('context_getAbilityInfo_test_0100', promise); + console.info('[context_getAbilityInfo_test_0100] FINISH'); + done(); + }); + + async function startAbility2() { + var str = { + "want": { + "bundleName": "com.ohos.acecollaboration", + "abilityName": "com.ohos.acecollaboration.MainAbility2", + }, + }; + ability_featureAbility.startAbility(str).then((data) => { + console.info('context_getAbilityInfo_test_0300 startMainAbility2 succeeded: ' + JSON.stringify(data)); + }).catch((error) => { + console.error('context_getAbilityInfo_test_0300 startMainAbility2 failed. Cause: ' + JSON.stringify(error)); + }); + } + + /** + * @tc.number: context_getAbilityInfo_test_0200 + * @tc.name: getAbilityInfo:Query the current attributionability details. + * @tc.desc: Check the return value of the interface (by AsyncCallback) + * @tc.level 0 + */ + it('context_getAbilityInfo_test_0200', 0, async function (done) { + try { + console.info('[context_getAbilityInfo_test_0200] START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + var context = ability_featureAbility.getContext(); + context.getAbilityInfo((error, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('context_getAbilityInfo_test_0200', timeOldStamp, timeNewStamp); + console.info('[context_getAbilityInfo_test_0200] data is:' + JSON.stringify(data)); + expect(typeof (data)).assertEqual("object"); + }); + } catch (error) { + console.error('[context_getAbilityInfo_test_0200] failed: ' + JSON.stringify(error)); + } + var callback = await context.getAbilityInfo(); + console.info('---[context_getAbilityInfo_test_0200] check---'); + checkAbilityInfo('context_getAbilityInfo_test_0200', callback); + console.info('[context_getAbilityInfo_test_0200] FINISH'); + done(); + }) + + + /** + * @tc.number: context_getAbilityInfo_test_0300_1 + * @tc.name: getAbilityInfo:Query the current attributionability details. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + it('context_getAbilityInfo_test_0300_1', 0, async function (done) { + console.info('[context_getAbilityInfo_test_0300] STARTability'); + startAbility2(); + done(); + }); + + /** + * @tc.number: context_getAbilityInfo_test_0400 + * @tc.name: getAbilityInfo:Query the current attributionability details. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it('context_getAbilityInfo_test_0400', 0, async function (done) { + console.info('[context_getAbilityInfo_test_0400] START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + var context = ability_featureAbility.getContext(); + await context.getAbilityInfo() + .then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('context_getAbilityInfo_test_0400', timeOldStamp, timeNewStamp); + console.info('[context_getAbilityInfo_test_0400] data is:' + JSON.stringify(data)); + expect(typeof (data)).assertEqual("object"); + }).catch((error) => { + console.error('[context_getAbilityInfo_test_0400] failed:' + JSON.stringify(error)); + }) + var promise = await context.getAbilityInfo(); + console.info('--[context_getAbilityInfo_test_0400] check---'); + checkAbilityInfo('context_getAbilityInfo_test_0400', promise); + console.info('[context_getAbilityInfo_test_0400] FINISH'); + done(); + }); + + function checkAbilityInfo(msg, data) { + console.log(msg + "checkAbilityInfo start " + JSON.stringify(data)); + console.log(msg + "checkAbilityInfo bundleName : " + data.bundleName); + console.log(msg + "checkAbilityInfo name : " + data.name); + console.log(msg + "checkAbilityInfo label : " + data.label); + console.log(msg + "checkAbilityInfo description : " + data.description); + console.log(msg + "checkAbilityInfo icon : " + data.icon); + console.log(msg + "checkAbilityInfo descriptionId : " + data.descriptionId); + console.log(msg + "checkAbilityInfo iconId : " + data.iconId); + console.log(msg + "checkAbilityInfo moduleName : " + data.moduleName); + console.log(msg + "checkAbilityInfo process : " + data.process); + console.log(msg + "checkAbilityInfo targetAbility : " + data.targetAbility); + console.log(msg + "checkAbilityInfo backgroundModes : " + data.backgroundModes); + console.log(msg + "checkAbilityInfo isVisible : " + data.isVisible); + console.log(msg + "checkAbilityInfo formEnabled : " + data.formEnabled); + console.log(msg + "checkAbilityInfo type : " + data.type) + console.log(msg + "checkAbilityInfo orientation : " + data.orientation); + console.log(msg + "checkAbilityInfo launchMode : " + data.launchMode); + console.log(msg + "checkAbilityInfo permissions length : " + data.permissions.length); + for (var j = 0; j < data.permissions.length; j++) { + console.log(msg + "getAbilityInfo data.permissions[" + j + "] : " + data.permissions[j]); + } + console.log(msg + "checkAbilityInfo deviceTypes length : " + data.deviceTypes.length); + for (var k = 0; k < data.deviceTypes.length; k++) { + console.log(msg + "getAbilityInfo data.deviceTypes[" + k + "] : " + data.deviceTypes[k]); + } + console.log(msg + "checkAbilityInfo deviceCapabilities length : " + data.deviceCapabilities.length); + for (var i = 0; i < data.deviceCapabilities.length; i++) { + console.log(msg + "getAbilityInfo data.deviceCapabilities[" + i + "] : " + data.deviceCapabilities[i]); + } + console.log(msg + "checkAbilityInfo readPermission : " + data.readPermission); + console.log(msg + "checkAbilityInfo writePermission : " + data.writePermission); + console.log(msg + "checkAbilityInfo formEntity : " + data.formEntity); + console.log(msg + "checkAbilityInfo minFormHeight : " + data.minFormHeight); + console.log(msg + "checkAbilityInfo defaultFormHeight : " + data.defaultFormHeight); + console.log(msg + "checkAbilityInfo minFormWidth : " + data.minFormWidth); + console.log(msg + "checkAbilityInfo defaultFormWidth : " + data.defaultFormWidth); + console.log(msg + "checkAbilityInfo uri : " + data.uri); + console.log(msg + "checkAbilityInfo customizeData : " + data.customizeData); + console.log(msg + "checkAbilityInfo labelId : " + data.labelId); + console.log(msg + "checkAbilityInfo subType : " + data.subType); + + expect(typeof (data)).assertEqual("object"); + expect(typeof (data.bundleName)).assertEqual("string"); + expect(typeof (data.name)).assertEqual("string"); + expect(typeof (data.label)).assertEqual("string"); + expect(typeof (data.description)).assertEqual("string"); + expect(typeof (data.icon)).assertEqual("string"); + expect(typeof (data.labelId)).assertEqual("number"); + expect(typeof (data.descriptionId)).assertEqual("number"); + expect(typeof (data.iconId)).assertEqual("number"); + expect(typeof (data.moduleName)).assertEqual("string"); + expect(typeof (data.process)).assertEqual("string"); + expect(typeof (data.targetAbility)).assertEqual("string"); + expect(typeof (data.backgroundModes)).assertEqual("number"); + expect(typeof (data.isVisible)).assertEqual("boolean"); + expect(typeof (data.formEnabled)).assertEqual("boolean"); + expect(typeof (data.type)).assertEqual("number"); + expect(typeof (data.subType)).assertEqual("number"); + expect(typeof (data.orientation)).assertEqual("number"); + expect(typeof (data.launchMode)).assertEqual("number"); + expect(Array.isArray(data.permissions)).assertEqual(true); + expect(Array.isArray(data.deviceTypes)).assertEqual(true); + expect(Array.isArray(data.deviceCapabilities)).assertEqual(true); + expect(typeof (data.readPermission)).assertEqual("string"); + expect(typeof (data.writePermission)).assertEqual("string"); + expect(typeof (data.applicationInfo)).assertEqual("object"); + expect(typeof (data.formEntity)).assertEqual("number"); + expect(typeof (data.minFormHeight)).assertEqual("number"); + expect(typeof (data.defaultFormHeight)).assertEqual("number"); + expect(typeof (data.minFormWidth)).assertEqual("number"); + expect(typeof (data.defaultFormWidth)).assertEqual("number"); + expect(typeof (data.uri)).assertEqual("string"); + + expect(data.bundleName).assertEqual("com.ohos.acecollaboration"); + expect(data.name).assertEqual("com.ohos.acecollaboration.MainAbility"); + expect(data.label).assertEqual("$string:entry_MainAbility"); + expect(data.description).assertEqual("$string:mainability_description"); + expect(data.icon).assertEqual("$media:icon"); + expect(data.descriptionId > 0).assertTrue(); + expect(data.iconId > 0).assertTrue(); + expect(data.moduleName).assertEqual("entry"); + expect(data.process).assertEqual(""); + expect(data.targetAbility).assertEqual(""); + expect(data.backgroundModes).assertEqual(0); + expect(data.isVisible).assertEqual(true); + expect(data.formEnabled).assertEqual(false); + expect(data.type).assertEqual(1); + expect(data.orientation).assertEqual(0); + expect(data.launchMode).assertEqual(1); + expect(data.deviceTypes[0]).assertEqual("phone"); + expect(data.readPermission).assertEqual(""); + expect(data.writePermission).assertEqual(""); + checkApplicationInfo(msg, data.applicationInfo); + expect(data.formEntity).assertEqual(0); + expect(data.minFormHeight).assertEqual(0); + expect(data.defaultFormHeight).assertEqual(0); + expect(data.minFormWidth).assertEqual(0); + expect(data.defaultFormWidth).assertEqual(0); + expect(data.uri).assertEqual(""); + expect(data.labelId > 0).assertTrue(); + expect(data.subType).assertEqual(0); + + console.log(msg + "---checkAbilityInfo End--- "); + } + + function checkApplicationInfo(msg, info) { + console.log(msg + "checkApplicationInfo start : " + JSON.stringify(info)); + console.log(msg + "checkApplicationInfo name : " + info.name); + console.log(msg + "checkApplicationInfo description : " + info.description); + console.log(msg + "checkApplicationInfo descriptionId : " + info.descriptionId); + console.log(msg + "checkApplicationInfo systemApp : " + info.systemApp); + console.log(msg + "checkApplicationInfo enabled : " + info.enabled); + console.log(msg + "checkApplicationInfo label : " + info.label); + console.log(msg + "checkApplicationInfo labelId : " + info.labelId); + console.log(msg + "checkApplicationInfo icon : " + info.icon); + console.log(msg + "checkApplicationInfo iconId : " + info.iconId); + console.log(msg + "checkApplicationInfo process : " + info.process); + console.log(msg + "checkApplicationInfo supportedModes : " + info.supportedModes); + + console.log(msg + "checkApplicationInfo moduleSourceDirs length : " + info.moduleSourceDirs.length); + for (var j = 0; j < info.moduleSourceDirs.length; j++) { + console.log(msg + "checkApplicationInfo info.moduleSourceDirs[" + j + "] : " + info.moduleSourceDirs[j]); + } + console.log(msg + "checkApplicationInfo permissions length : " + info.permissions.length); + for (var k = 0; k < info.permissions.length; k++) { + console.log(msg + "checkApplicationInfo info.permissions[" + k + "] : " + info.permissions[k]); + } + console.log(msg + "checkApplicationInfo moduleInfos length : " + info.moduleInfos.length); + for (var i = 0; i < info.moduleInfos.length; i++) { + console.log(msg + "checkApplicationInfo info.moduleInfos[" + i + "].moduleName : " + + info.moduleInfos[i].moduleName); + console.log(msg + "checkApplicationInfo info.moduleInfos[" + i + "].moduleSourceDir : " + + info.moduleInfos[i].moduleSourceDir); + } + console.log(msg + "checkApplicationInfo entryDir : " + info.entryDir); + + expect(typeof (info)).assertEqual("object"); + expect(typeof (info.name)).assertEqual("string"); + expect(typeof (info.description)).assertEqual("string"); + expect(typeof (info.descriptionId)).assertEqual("number"); + expect(typeof (info.systemApp)).assertEqual("boolean"); + expect(typeof (info.enabled)).assertEqual("boolean"); + expect(typeof (info.label)).assertEqual("string"); + expect(typeof (info.labelId)).assertEqual("string"); + expect(typeof (info.icon)).assertEqual("string"); + expect(typeof (info.iconId)).assertEqual("string"); + expect(typeof (info.process)).assertEqual("string"); + expect(typeof (info.supportedModes)).assertEqual("number"); + expect(Array.isArray(info.moduleSourceDirs)).assertEqual(true); + expect(Array.isArray(info.permissions)).assertEqual(true); + expect(Array.isArray(info.moduleInfos)).assertEqual(true); + expect(typeof (info.entryDir)).assertEqual("string"); + + expect(info.name).assertEqual("com.ohos.acecollaboration"); + expect(info.description).assertEqual("$string:mainability_description"); + expect(info.descriptionId > 0).assertTrue(); + expect(info.systemApp).assertEqual(true); + expect(info.enabled).assertEqual(true); + expect(info.label).assertEqual("$string:entry_MainAbility"); + expect(info.icon).assertEqual("$media:icon"); + expect(info.process).assertEqual(""); + expect(info.supportedModes).assertEqual(0); + expect(info.entryDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.ohos.acecollaboration"); + if (info.moduleSourceDirs.length == 1){ + expect(info.moduleInfos[0].moduleName).assertEqual("entry"); + expect(info.moduleInfos[0].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.ohos.acecollaboration"); + }else if(info.moduleSourceDirs.length == 2) { + if (info.moduleInfos[0].moduleName == "myapplication1") { + expect(info.moduleInfos[0].moduleName).assertEqual("myapplication1"); + expect(info.moduleInfos[0].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.example.myapplication1"); + expect(info.moduleInfos[1].moduleName).assertEqual("entry"); + expect(info.moduleInfos[1].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.ohos.acecollaboration"); + }else{ + expect(info.moduleInfos[0].moduleName).assertEqual("myapplication2"); + expect(info.moduleInfos[0].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.example.myapplication2"); + expect(info.moduleInfos[1].moduleName).assertEqual("entry"); + expect(info.moduleInfos[1].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.ohos.acecollaboration"); + } + }else { + expect(info.moduleInfos[0].moduleName).assertEqual("myapplication1"); + expect(info.moduleInfos[0].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.example.myapplication1"); + expect(info.moduleInfos[1].moduleName).assertEqual("myapplication2"); + expect(info.moduleInfos[1].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.example.myapplication2"); + expect(info.moduleInfos[2].moduleName).assertEqual("entry"); + expect(info.moduleInfos[2].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.ohos.acecollaboration"); + } + + console.log(msg + "---checkApplicationInfo End--- "); + + } + + }) +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/getAppVersionInfoJsunit.test.ets b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/getAppVersionInfoJsunit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..852ff5ee53828ce888492e87bfee2a8a8fc9f057 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/getAppVersionInfoJsunit.test.ets @@ -0,0 +1,92 @@ +/** + * Copyright (c) 2021 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 {describe, it, expect} from "deccjsunit/index.ets"; +import Utils from './Utils'; +import ability_featureAbility from '@ohos.ability.featureAbility'; + +export default function getHapModuleInfoJsunit() { + describe('appInfoTest', function () { + /** + * @tc.number: context_getAppVersionInfo_test_0100 + * @tc.name: getAppVersionInfo:Gets the version information for the application. + * @tc.desc: Check the return type of the interface (by Promise) + * @tc.level 0 + */ + it('context_getAppVersionInfo_test_0100', 0, async function (done) { + console.info('[context_getAppVersionInfo_test_0100] START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + var context = ability_featureAbility.getContext(); + context.getAppVersionInfo() + .then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('context_getAppVersionInfo_test_0100', timeOldStamp, timeNewStamp); + console.info('[context_getAppVersionInfo_test_0100] data is:' + JSON.stringify(data)); + expect(typeof (data)).assertEqual("object"); + }).catch((error) => { + console.error('[context_getAppVersionInfo_test_0100] failed:' + JSON.stringify(error)); + }) + var promise = await context.getAppVersionInfo(); + console.info('---[context_getAppVersionInfo_test_0100] check---'); + checkAppVersionInfo('context_getAppVersionInfo_test_0100', promise); + console.info('[context_getAppVersionInfo_test_0100] FINISH'); + done(); + }); + + /** + * @tc.number: context_getAppVersionInfo_test_0200 + * @tc.name: getAppVersionInfo:Gets the version information for the application. + * @tc.desc: Check the return type of the interface (by Callback) + * @tc.level 0 + */ + it('context_getAppVersionInfo_test_0200', 0, async function (done) { + try { + console.info('[context_getAppVersionInfo_test_0200] START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + var context = ability_featureAbility.getContext(); + context.getAppVersionInfo((error, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('context_getAppVersionInfo_test_0200', timeOldStamp, timeNewStamp); + console.info('[context_getAppVersionInfo_test_0200] data is:' + JSON.stringify(data)); + expect(typeof (data)).assertEqual("object"); + }); + } + catch (error) { + console.error('[context_getAppVersionInfo_test_0200] failed: ' + JSON.stringify(error)); + } + var callback = await context.getAppVersionInfo(); + console.info('---[context_getAppVersionInfo_test_0200] check---'); + checkAppVersionInfo('context_getAppVersionInfo_test_0200', callback); + console.info('[context_getAppVersionInfo_test_0200] FINISH'); + done(); + }); + + function checkAppVersionInfo(msg, data) { + console.log(msg + "checkAppVersionInfo start : " + JSON.stringify(data)); + console.log(msg + "checkAppVersionInfo appName : " + data.appName); + console.log(msg + "checkAppVersionInfo versionCode : " + data.versionCode); + console.log(msg + "checkAppVersionInfo versionName : " + data.versionName); + expect(typeof (data)).assertEqual("object"); + expect(typeof (data.appName)).assertEqual("string"); + expect(typeof (data.versionCode)).assertEqual("number"); + expect(typeof (data.versionName)).assertEqual("string"); + expect(data.appName).assertEqual(""); + expect(data.versionCode).assertEqual(1000000); + expect(data.versionName).assertEqual("1.0.0"); + console.log(msg + "---checkAppVersionInfo End--- "); + } + }) +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/getApplicationContextJsunit.test.ets b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/getApplicationContextJsunit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c342915a809774aaeaa389eb9571582ef5ae3996 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/getApplicationContextJsunit.test.ets @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2021 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 {describe, it, expect} from "deccjsunit/index.ets"; +import Utils from './Utils'; +import ability_featureAbility from '@ohos.ability.featureAbility'; + +export default function getHapModuleInfoJsunit() { + describe('appInfoTest', function () { + /** + * @tc.number: context_getApplicationContext_test_0100 + * @tc.name: getApplicationContext:Gets the application context information. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + it('context_getApplicationContext_test_0100', 0, async function (done) { + try { + console.info('[context_getApplicationContext_test_0100] START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + var context = ability_featureAbility.getContext().getApplicationContext(); + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('context_getApplicationContext_test_0100', timeOldStamp, timeNewStamp); + console.info('[context_getApplicationContext_test_0100] data is:' + JSON.stringify(context)); + } + catch (error) { + console.error('[context_getApplicationContext_test_0100] failed:' + JSON.stringify(error)); + } + expect(typeof (context)).assertEqual("object"); + console.info('[context_getApplicationContext_test_0100] FINISH'); + done(); + }); + + }) +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/getHapModuleInfoJsunit.test.ets b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/getHapModuleInfoJsunit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7d99f6be366de1d94e506061ae4af379bccd8c37 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility/test/getHapModuleInfoJsunit.test.ets @@ -0,0 +1,352 @@ +/** + * Copyright (c) 2021 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 {describe, it, expect} from "deccjsunit/index.ets"; +import Utils from './Utils'; +import ability_featureAbility from '@ohos.ability.featureAbility'; + +export default function getHapModuleInfoJsunit() { + describe('appInfoTest', function () { + /** + * @tc.number: context_getHapModuleInfo_test_0100 + * @tc.name: getHapModuleInfo:Obtains the HapModuleInfo object of the application. + * @tc.desc: Check the return type of the interface (by Promise) + * @tc.level 0 + */ + it('context_getHapModuleInfo_test_0100', 0, async function (done) { + console.info('[context_getHapModuleInfo_test_0100] START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + var context = ability_featureAbility.getContext(); + context.getHapModuleInfo() + .then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('context_getHapModuleInfo_test_0100', timeOldStamp, timeNewStamp); + console.info('[context_getHapModuleInfo_test_0100] data is:' + JSON.stringify(data)); + expect(typeof (data)).assertEqual("object"); + }) + .catch((error) => { + console.error('[context_getHapModuleInfo_test_0100] failed:' + JSON.stringify(error)); + }) + var promise = await context.getHapModuleInfo(); + console.info('---[context_getHapModuleInfo_test_0100] check---'); + checkHapModuleInfo('context_getHapModuleInfo_test_0100', promise); + console.info('[context_getHapModuleInfo_test_0100] FINISH'); + done(); + }); + + /** + * @tc.number: context_getHapModuleInfo_test_0200 + * @tc.name: getHapModuleInfo:Obtains the HapModuleInfo object of the application. + * @tc.desc: Check the return type of the interface (by Callback) + * @tc.level 0 + */ + it('context_getHapModuleInfo_test_0200', 0, async function (done) { + let callback; + try { + console.info('[context_getHapModuleInfo_test_0200] START'); + var timeOldStamp = await Utils.getNowTime(); + var context = ability_featureAbility.getContext(); + context.getHapModuleInfo((error, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('context_getHapModuleInfo_test_0200', timeOldStamp, timeNewStamp); + console.info('[context_getHapModuleInfo_test_0200] data is:' + JSON.stringify(data)); + callback = data; + expect(typeof (data)).assertEqual("object"); + }); + } catch (error) { + console.error('[context_getHapModuleInfo_test_0200] failed: ' + JSON.stringify(error)); + } + await Utils.sleep(1000); + console.info('---[context_getHapModuleInfo_test_0200] check---'); + checkHapModuleInfo('context_getHapModuleInfo_test_0200', callback); + console.info('[context_getHapModuleInfo_test_0200] FINISH'); + done(); + }); + + /** + * @tc.number: context_getHapModuleInfo_test_0300_1 + * @tc.name: getHapModuleInfo:Obtains the HapModuleInfo object of the application. + * @tc.desc: Check the return value of the interface + * @tc.level 0 + */ + it('context_getHapModuleInfo_test_0300_1', 0, async function (done) { + console.info('[context_getHapModuleInfo_test_0300_1] START'); + var str = { + "want": { + "bundleName": "com.ohos.acecollaboration", + "abilityName": "com.example.myapplication1.MainAbility", + }, + }; + ability_featureAbility.startAbility(str) + .then((data) => { + console.info('[context_getHapModuleInfo_test_0300_1] start myapplication1 successful: ' + JSON.stringify(data)) + }).catch((error) => { + console.error('[context_getHapModuleInfo_test_0300_1] start myapplication1 Cause: ' + JSON.stringify(error)); + }) + done(); + }); + + function checkHapModuleInfo(msg, data) { + console.log(msg + "checkHapModuleInfo start " + JSON.stringify(data)); + console.log(msg + "checkHapModuleInfo name : " + data.name); + console.log(msg + "checkHapModuleInfo description : " + data.description); + console.log(msg + "checkHapModuleInfo descriptionId : " + data.descriptionId); + console.log(msg + "checkHapModuleInfo icon : " + data.icon); + console.log(msg + "checkHapModuleInfo label : " + data.label); + console.log(msg + "checkHapModuleInfo labelId : " + data.labelId); + console.log(msg + "checkHapModuleInfo iconId : " + data.iconId); + console.log(msg + "checkHapModuleInfo backgroundImg : " + data.backgroundImg); + console.log(msg + "checkHapModuleInfo supportedModes : " + data.supportedModes); + console.log(msg + "checkHapModuleInfo reqCapabilities length : " + data.reqCapabilities.length); + for (var j = 0; j < data.reqCapabilities.length; j++) { + console.log(msg + "getHapModuleInfo data.reqCapabilities[" + j + "] : " + data.reqCapabilities[j]); + } + console.log(msg + "checkHapModuleInfo deviceTypes length : " + data.deviceTypes.length); + for (var k = 0; k < data.deviceTypes.length; k++) { + console.log(msg + "getHapModuleInfo data.deviceTypes[" + k + "] : " + data.deviceTypes[k]); + } + console.log(msg + "checkHapModuleInfo abilityInfos length : " + data.abilityInfos.length); + console.log(msg + "checkHapModuleInfo moduleName : " + data.moduleName); + console.log(msg + "checkHapModuleInfo mainAbilityName : " + data.mainAbilityName); + console.log(msg + "checkHapModuleInfo installationFree : " + data.installationFree); + expect(typeof (data)).assertEqual("object"); + expect(typeof (data.name)).assertEqual("string"); + expect(typeof (data.description)).assertEqual("string"); + expect(typeof (data.descriptionId)).assertEqual("number"); + expect(typeof (data.icon)).assertEqual("string"); + expect(typeof (data.label)).assertEqual("string"); + expect(typeof (data.labelId)).assertEqual("number"); + expect(typeof (data.iconId)).assertEqual("number"); + expect(typeof (data.backgroundImg)).assertEqual("string"); + expect(typeof (data.supportedModes)).assertEqual("number"); + expect(Array.isArray(data.reqCapabilities)).assertEqual(true); + expect(Array.isArray(data.deviceTypes)).assertEqual(true); + expect(Array.isArray(data.abilityInfos)).assertEqual(true); + expect(typeof (data.moduleName)).assertEqual("string"); + expect(typeof (data.mainAbilityName)).assertEqual("string"); + expect(typeof (data.installationFree)).assertEqual("boolean"); + expect(data.name).assertEqual("com.ohos.acecollaboration"); + expect(data.description).assertEqual(""); + expect(data.descriptionId).assertEqual(0); + expect(data.icon).assertEqual("$media:icon"); + expect(data.label).assertEqual("$string:entry_MainAbility"); + expect(data.labelId).assertEqual(0); + expect(data.iconId).assertEqual(0); + expect(data.backgroundImg).assertEqual(""); + expect(data.supportedModes).assertEqual(0); + expect(data.deviceTypes[0]).assertEqual("phone"); + for (var i = 0; i < data.abilityInfos.length; i++) { + console.log(msg + "-------AbilityInfo data.abilityInfos[" + i + "] : START ------" ); + checkAbilityInfo(msg,data.abilityInfos[i]); + } + expect(data.moduleName).assertEqual("entry") + expect(data.mainAbilityName).assertEqual(""); + expect(data.installationFree).assertEqual(false); + console.log(msg + "---checkHapModuleInfo End---"); + } + + function checkAbilityInfo(msg,data) { + console.log(msg+ "checkAbilityInfo start " + JSON.stringify(data)); + console.log(msg+ "checkAbilityInfo bundleName : " + data.bundleName); + console.log(msg+ "checkAbilityInfo name : " + data.name); + console.log(msg+ "checkAbilityInfo label : " + data.label); + console.log(msg+ "checkAbilityInfo description : " + data.description); + console.log(msg+ "checkAbilityInfo icon : " + data.icon); + console.log(msg+ "checkAbilityInfo descriptionId : " + data.descriptionId); + console.log(msg+ "checkAbilityInfo iconId : " + data.iconId); + console.log(msg+ "checkAbilityInfo moduleName : " + data.moduleName); + console.log(msg+ "checkAbilityInfo process : " + data.process); + console.log(msg+ "checkAbilityInfo targetAbility : " + data.targetAbility); + console.log(msg+ "checkAbilityInfo backgroundModes : " + data.backgroundModes); + console.log(msg+ "checkAbilityInfo isVisible : " + data.isVisible); + console.log(msg+ "checkAbilityInfo formEnabled : " + data.formEnabled); + console.log(msg+ "checkAbilityInfo type : " + data.type) + console.log(msg+ "checkAbilityInfo orientation : " + data.orientation); + console.log(msg+ "checkAbilityInfo launchMode : " + data.launchMode); + console.log(msg+ "checkAbilityInfo permissions length : " + data.permissions.length); + for (var j = 0; j < data.permissions.length; j++) { + console.log(msg+ "getAbilityInfo data.permissions[" + j + "] : " + data.permissions[j]); + } + console.log(msg+ "checkAbilityInfo deviceTypes length : " + data.deviceTypes.length); + for (var k = 0; k < data.deviceTypes.length; k++) { + console.log(msg+ "getAbilityInfo data.deviceTypes[" + k + "] : " + data.deviceTypes[k]); + } + console.log(msg+ "checkAbilityInfo deviceCapabilities length : " + data.deviceCapabilities.length); + for (var i = 0; i < data.deviceCapabilities.length; i++) { + console.log(msg+ "getAbilityInfo data.deviceCapabilities[" + i + "] : " + data.deviceCapabilities[i]); + } + console.log(msg+ "checkAbilityInfo readPermission : " + data.readPermission); + console.log(msg+ "checkAbilityInfo writePermission : " + data.writePermission); + console.log(msg+ "checkAbilityInfo formEntity : " + data.formEntity); + console.log(msg+ "checkAbilityInfo minFormHeight : " + data.minFormHeight); + console.log(msg+ "checkAbilityInfo defaultFormHeight : " + data.defaultFormHeight); + console.log(msg+ "checkAbilityInfo minFormWidth : " + data.minFormWidth); + console.log(msg+ "checkAbilityInfo defaultFormWidth : " + data.defaultFormWidth); + console.log(msg+ "checkAbilityInfo uri : " + data.uri); + console.log(msg+ "checkAbilityInfo labelId : " + data.labelId); + console.log(msg+ "checkAbilityInfo subType : " + data.subType); + expect(typeof (data)).assertEqual("object"); + expect(typeof (data.bundleName)).assertEqual("string"); + expect(typeof (data.name)).assertEqual("string"); + expect(typeof (data.label)).assertEqual("string"); + expect(typeof (data.description)).assertEqual("string"); + expect(typeof (data.icon)).assertEqual("string"); + expect(typeof (data.labelId)).assertEqual("number"); + expect(typeof (data.descriptionId)).assertEqual("number"); + expect(typeof (data.iconId)).assertEqual("number"); + expect(typeof (data.moduleName)).assertEqual("string"); + expect(typeof (data.process)).assertEqual("string"); + expect(typeof (data.targetAbility)).assertEqual("string"); + expect(typeof (data.backgroundModes)).assertEqual("number"); + expect(typeof (data.isVisible)).assertEqual("boolean"); + expect(typeof (data.formEnabled)).assertEqual("boolean"); + expect(typeof (data.type)).assertEqual("number"); + expect(typeof (data.subType)).assertEqual("number"); + expect(typeof (data.orientation)).assertEqual("number"); + expect(typeof (data.launchMode)).assertEqual("number"); + expect(Array.isArray(data.permissions)).assertEqual(true); + expect(Array.isArray(data.deviceTypes)).assertEqual(true); + expect(Array.isArray(data.deviceCapabilities)).assertEqual(true); + expect(typeof (data.readPermission)).assertEqual("string"); + expect(typeof (data.writePermission)).assertEqual("string"); + expect(typeof (data.applicationInfo)).assertEqual("object"); + expect(typeof (data.formEntity)).assertEqual("number"); + expect(typeof (data.minFormHeight)).assertEqual("number"); + expect(typeof (data.defaultFormHeight)).assertEqual("number"); + expect(typeof (data.minFormWidth)).assertEqual("number"); + expect(typeof (data.defaultFormWidth)).assertEqual("number"); + expect(typeof (data.uri)).assertEqual("string"); + expect(data.bundleName).assertEqual("com.ohos.acecollaboration"); + expect(data.name).assertEqual("com.ohos.acecollaboration.MainAbility"); + expect(data.label).assertEqual("$string:entry_MainAbility"); + expect(data.description).assertEqual("$string:mainability_description"); + expect(data.icon).assertEqual("$media:icon"); + expect(data.descriptionId > 0).assertTrue(); + expect(data.iconId > 0).assertTrue(); + expect(data.moduleName).assertEqual("entry"); + expect(data.process).assertEqual(""); + expect(data.targetAbility).assertEqual(""); + expect(data.backgroundModes).assertEqual(0); + expect(data.isVisible).assertEqual(true); + expect(data.formEnabled).assertEqual(false); + expect(data.type).assertEqual(1); + expect(data.orientation).assertEqual(0); + expect(data.launchMode).assertEqual(1); + expect(data.deviceTypes[0]).assertEqual("phone"); + expect(data.readPermission).assertEqual(""); + expect(data.writePermission).assertEqual(""); + checkApplicationInfo(msg,data.applicationInfo); + expect(data.formEntity).assertEqual(0); + expect(data.minFormHeight).assertEqual(0); + expect(data.defaultFormHeight).assertEqual(0); + expect(data.minFormWidth).assertEqual(0); + expect(data.defaultFormWidth).assertEqual(0); + expect(data.uri).assertEqual(""); + expect(data.labelId > 0).assertTrue(); + expect(data.subType).assertEqual(0); + console.log(msg+ "---checkAbilityInfo End--- "); + } + + function checkApplicationInfo(msg,info) { + console.log(msg+ "checkApplicationInfo start : " + JSON.stringify(info)); + console.log(msg+ "checkApplicationInfo name : " + info.name); + console.log(msg+ "checkApplicationInfo description : " + info.description); + console.log(msg+ "checkApplicationInfo descriptionId : " + info.descriptionId); + console.log(msg+ "checkApplicationInfo systemApp : " + info.systemApp); + console.log(msg+ "checkApplicationInfo enabled : " + info.enabled); + console.log(msg+ "checkApplicationInfo label : " + info.label); + console.log(msg+ "checkApplicationInfo labelId : " + info.labelId); + console.log(msg+ "checkApplicationInfo icon : " + info.icon); + console.log(msg+ "checkApplicationInfo iconId : " + info.iconId); + console.log(msg+ "checkApplicationInfo process : " + info.process); + console.log(msg+ "checkApplicationInfo supportedModes : " + info.supportedModes); + console.log(msg+ "checkApplicationInfo moduleSourceDirs length : " + info.moduleSourceDirs.length); + for (var j = 0; j < info.moduleSourceDirs.length; j++) { + console.log(msg+ "checkApplicationInfo info.moduleSourceDirs[" + j + "] : " + info.moduleSourceDirs[j]); + } + console.log(msg+ "checkApplicationInfo permissions length : " + info.permissions.length); + for (var k = 0; k < info.permissions.length; k++) { + console.log(msg+ "checkApplicationInfo info.permissions[" + k + "] : " + info.permissions[k]); + } + console.log(msg+ "checkApplicationInfo moduleInfos length : " + info.moduleInfos.length); + for (var i = 0; i < info.moduleInfos.length; i++) { + console.log(msg+ "checkApplicationInfo info.moduleInfos[" + i + "].moduleName : " + + info.moduleInfos[i].moduleName); + console.log(msg+ "checkApplicationInfo info.moduleInfos[" + i + "].moduleSourceDir : " + + info.moduleInfos[i].moduleSourceDir); + } + console.log(msg+ "checkApplicationInfo entryDir : " + info.entryDir); + expect(typeof (info)).assertEqual("object"); + expect(typeof (info.name)).assertEqual("string"); + expect(typeof (info.description)).assertEqual("string"); + expect(typeof (info.descriptionId)).assertEqual("number"); + expect(typeof (info.systemApp)).assertEqual("boolean"); + expect(typeof (info.enabled)).assertEqual("boolean"); + expect(typeof (info.label)).assertEqual("string"); + expect(typeof (info.labelId)).assertEqual("string"); + expect(typeof (info.icon)).assertEqual("string"); + expect(typeof (info.iconId)).assertEqual("string"); + expect(typeof (info.process)).assertEqual("string"); + expect(typeof (info.supportedModes)).assertEqual("number"); + expect(Array.isArray(info.moduleSourceDirs)).assertEqual(true); + expect(Array.isArray(info.permissions)).assertEqual(true); + expect(Array.isArray(info.moduleInfos)).assertEqual(true); + expect(typeof (info.entryDir)).assertEqual("string"); + if (info.moduleSourceDirs.length == 1){ + expect(info.moduleInfos[0].moduleName).assertEqual("entry"); + expect(info.moduleInfos[0].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.ohos.acecollaboration"); + }else if(info.moduleSourceDirs.length == 2) { + if (info.moduleInfos[0].moduleName == "myapplication1") { + expect(info.moduleInfos[0].moduleName).assertEqual("myapplication1"); + expect(info.moduleInfos[0].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.example.myapplication1"); + expect(info.moduleInfos[1].moduleName).assertEqual("entry"); + expect(info.moduleInfos[1].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.ohos.acecollaboration"); + }else{ + expect(info.moduleInfos[0].moduleName).assertEqual("myapplication2"); + expect(info.moduleInfos[0].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.example.myapplication2"); + expect(info.moduleInfos[1].moduleName).assertEqual("entry"); + expect(info.moduleInfos[1].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.ohos.acecollaboration"); + } + }else { + expect(info.moduleInfos[0].moduleName).assertEqual("myapplication1"); + expect(info.moduleInfos[0].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.example.myapplication1"); + expect(info.moduleInfos[1].moduleName).assertEqual("myapplication2"); + expect(info.moduleInfos[1].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.example.myapplication2"); + expect(info.moduleInfos[2].moduleName).assertEqual("entry"); + expect(info.moduleInfos[2].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.ohos.acecollaboration"); + } + expect(info.name).assertEqual("com.ohos.acecollaboration"); + expect(info.description).assertEqual("$string:mainability_description"); + expect(info.descriptionId > 0).assertTrue(); + expect(info.systemApp).assertEqual(true); + expect(info.enabled).assertEqual(true); + expect(info.label).assertEqual("$string:entry_MainAbility"); + expect(info.icon).assertEqual("$media:icon"); + expect(info.process).assertEqual(""); + expect(info.supportedModes).assertEqual(0); + expect(info.entryDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.ohos.acecollaboration"); + console.log(msg+ "---checkApplicationInfo End--- "); + } + }) +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility2/app.ets b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility2/app.ets new file mode 100644 index 0000000000000000000000000000000000000000..fc86a0485f5fa3d43dc0d7a7d858e3f41ed87304 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility2/app.ets @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2021 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 default { + onCreate() { + console.info('Application onCreate') + }, + onDestroy() { + console.info('Application onDestroy') + }, +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility2/pages/index.ets b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility2/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..e90a861b06feb9417415562b2421a432ac6d461d --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility2/pages/index.ets @@ -0,0 +1,66 @@ +/** + * Copyright (c) 2021 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 featureAbility from "@ohos.ability.featureAbility"; +import testsuite2 from "../test/List.test.ets"; +import file from '@system.file'; +import {Core, ExpectExtend, ReportExtend} from "deccjsunit/index.ets"; + +@Entry +@Component +struct MyComponent { + aboutToAppear() { + console.info("start run testcase2!!!!") + featureAbility.getWant() + .then((Want) => { + const core = Core.getInstance(); + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }); + core.addService('expect', expectExtend); + const reportExtend = new ReportExtend(file); + core.addService('report', reportExtend); + core.init(); + core.subscribeEvent('task', reportExtend); + const configService = core.getDefaultService('config'); + console.info('parameters2---->' + JSON.stringify(Want.parameters)); + configService.setConfig(Want.parameters); + testsuite2(); + core.execute(); + console.info('Operation successful2. Data: ' + JSON.stringify(Want)); + }) + .catch((error) => { + console.error('Operation failed2. Cause: ' + JSON.stringify(error)); + }) + } + + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World') + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility2/test/List.test.ets b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility2/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..3d3c47dce1c1f0a41a634b0d1559aa3b54c517e2 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility2/test/List.test.ets @@ -0,0 +1,20 @@ +/** + * Copyright (c) 2021 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 getAbilityInfoJsunit from './getAbilityInfoJsunit2.test.ets'; + +export default function testsuite2() { + getAbilityInfoJsunit(); +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility2/test/Utils.ets b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility2/test/Utils.ets new file mode 100644 index 0000000000000000000000000000000000000000..44eeb6fe62c02130e9d8dd290b157426e2af9d2f --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility2/test/Utils.ets @@ -0,0 +1,48 @@ +// @ts-nocheck +/** + * Copyright (c) 2021 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 default class Utils { + static sleep(time) { + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve() + }, time) + }).then(() => { + console.info(`sleep ${time} over...`) + }) + } + + static getNowTime() { + return new Date().getTime(); + } + + /** + * 接口调用时间 + * @param startTime 接口调用开始时间 + * @param endTime 接口调用结束时间 + */ + static getDurationTime(msg, startTime, endTime) { + console.info(msg + 'Get Interface startTime: ' + startTime); + console.info(msg + 'Get Interface endTime: ' + endTime); + var duration = (endTime - startTime) + console.info(msg + 'Get Interface Duration: ' + duration); + return duration; + } +} + + + + diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility2/test/getAbilityInfoJsunit2.test.ets b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility2/test/getAbilityInfoJsunit2.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..827da661a688dc43e67505489d4e27b7da6d4ecd --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/MainAbility2/test/getAbilityInfoJsunit2.test.ets @@ -0,0 +1,245 @@ +/** + * Copyright (c) 2021 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 {describe, it, expect} from "deccjsunit/index.ets"; +import Utils from './Utils'; +import ability_featureAbility from '@ohos.ability.featureAbility'; + +export default function getAbilityInfoJsunit() { + describe('appInfoTest', function () { + + /** + * @tc.number: context_getAbilityInfo_test_0300 + * @tc.name: getAbilityInfo:Query the current attributionability details. + * @tc.desc: Check the return type of the interface (by Callback) + * @tc.level 0 + */ + it('context_getAbilityInfo_test_0300', 0, async function (done) { + try{ + console.info('[context_getAbilityInfo_test_0300] START2'); + var timeOldStamp = await Utils.getNowTime(); + var context = ability_featureAbility.getContext(); + await context.getAbilityInfo((error, data)=>{ + var timeNewStamp= Utils.getNowTime(); + Utils.getDurationTime('context_getAbilityInfo_test_0300',timeOldStamp,timeNewStamp); + console.info('[context_getAbilityInfo_test_0300] data is:' + JSON.stringify(data)); + expect(typeof (data)).assertEqual("object"); + }); + } catch (error){ + console.error('[context_getAbilityInfo_test_0300] failed: ' + JSON.stringify(error)); + } + var callback = await context.getAbilityInfo(); + console.info('---[context_getAbilityInfo_test_0300] check---'); + checkAbilityInfo2('context_getAbilityInfo_test_0300',callback); + console.info('[context_getAbilityInfo_test_0300] FINISH'); + done(); + }) + + function checkAbilityInfo2(msg,data) { + console.log(msg+ "checkAbilityInfo2 start " + JSON.stringify(data)); + console.log(msg+ "checkAbilityInfo2 bundleName : " + data.bundleName); + console.log(msg+ "checkAbilityInfo2 name : " + data.name); + console.log(msg+ "checkAbilityInfo2 label : " + data.label); + console.log(msg+ "checkAbilityInfo2 description : " + data.description); + console.log(msg+ "checkAbilityInfo2 icon : " + data.icon); + console.log(msg+ "checkAbilityInfo2 descriptionId : " + data.descriptionId); + console.log(msg+ "checkAbilityInfo2 iconId : " + data.iconId); + console.log(msg+ "checkAbilityInfo2 moduleName : " + data.moduleName); + console.log(msg+ "checkAbilityInfo2 process : " + data.process); + console.log(msg+ "checkAbilityInfo2 targetAbility : " + data.targetAbility); + console.log(msg+ "checkAbilityInfo2 backgroundModes : " + data.backgroundModes); + console.log(msg+ "checkAbilityInfo2 isVisible : " + data.isVisible); + console.log(msg+ "checkAbilityInfo2 formEnabled : " + data.formEnabled); + console.log(msg+ "checkAbilityInfo2 type : " + data.type) + console.log(msg+ "checkAbilityInfo2 orientation : " + data.orientation); + console.log(msg+ "checkAbilityInfo2 launchMode : " + data.launchMode); + console.log(msg+ "checkAbilityInfo2 permissions length : " + data.permissions.length); + for (var j = 0; j < data.permissions.length; j++) { + console.log(msg+ "getAbilityInfo2 data.permissions[" + j + "] : " + data.permissions[j]); + } + console.log(msg+ "checkAbilityInfo2 deviceTypes length : " + data.deviceTypes.length); + for (var k = 0; k < data.deviceTypes.length; k++) { + console.log(msg+ "getAbilityInfo2 data.deviceTypes[" + k + "] : " + data.deviceTypes[k]); + } + console.log(msg+ "checkAbilityInfo2 deviceCapabilities length : " + data.deviceCapabilities.length); + for (var i = 0; i < data.deviceCapabilities.length; i++) { + console.log(msg+ "getAbilityInfo2 data.deviceCapabilities[" + i + "] : " + data.deviceCapabilities[i]); + } + console.log(msg+ "checkAbilityInfo2 readPermission : " + data.readPermission); + console.log(msg+ "checkAbilityInfo2 writePermission : " + data.writePermission); + console.log(msg+ "checkAbilityInfo2 formEntity : " + data.formEntity); + console.log(msg+ "checkAbilityInfo2 minFormHeight : " + data.minFormHeight); + console.log(msg+ "checkAbilityInfo2 defaultFormHeight : " + data.defaultFormHeight); + console.log(msg+ "checkAbilityInfo2 minFormWidth : " + data.minFormWidth); + console.log(msg+ "checkAbilityInfo2 defaultFormWidth : " + data.defaultFormWidth); + console.log(msg+ "checkAbilityInfo2 uri : " + data.uri); + console.log(msg+ "checkAbilityInfo2 customizeData : " + data.customizeData); + console.log(msg+ "checkAbilityInfo2 labelId : " + data.labelId); + console.log(msg+ "checkAbilityInfo2 subType : " + data.subType); + + expect(typeof (data)).assertEqual("object"); + expect(typeof (data.bundleName)).assertEqual("string"); + expect(typeof (data.name)).assertEqual("string"); + expect(typeof (data.label)).assertEqual("string"); + expect(typeof (data.description)).assertEqual("string"); + expect(typeof (data.icon)).assertEqual("string"); + expect(typeof (data.labelId)).assertEqual("number"); + expect(typeof (data.descriptionId)).assertEqual("number"); + expect(typeof (data.iconId)).assertEqual("number"); + expect(typeof (data.moduleName)).assertEqual("string"); + expect(typeof (data.process)).assertEqual("string"); + expect(typeof (data.targetAbility)).assertEqual("string"); + expect(typeof (data.backgroundModes)).assertEqual("number"); + expect(typeof (data.isVisible)).assertEqual("boolean"); + expect(typeof (data.formEnabled)).assertEqual("boolean"); + expect(typeof (data.type)).assertEqual("number"); + expect(typeof (data.subType)).assertEqual("number"); + expect(typeof (data.orientation)).assertEqual("number"); + expect(typeof (data.launchMode)).assertEqual("number"); + expect(Array.isArray(data.permissions)).assertEqual(true); + expect(Array.isArray(data.deviceTypes)).assertEqual(true); + expect(Array.isArray(data.deviceCapabilities)).assertEqual(true); + expect(typeof (data.readPermission)).assertEqual("string"); + expect(typeof (data.writePermission)).assertEqual("string"); + expect(typeof (data.applicationInfo)).assertEqual("object"); + expect(typeof (data.formEntity)).assertEqual("number"); + expect(typeof (data.minFormHeight)).assertEqual("number"); + expect(typeof (data.defaultFormHeight)).assertEqual("number"); + expect(typeof (data.minFormWidth)).assertEqual("number"); + expect(typeof (data.defaultFormWidth)).assertEqual("number"); + expect(typeof (data.uri)).assertEqual("string"); + + expect(data.bundleName).assertEqual("com.ohos.acecollaboration"); + expect(data.name).assertEqual("com.ohos.acecollaboration.MainAbility2"); + expect(data.label).assertEqual("$string:entry_MainAbility2"); + expect(data.description).assertEqual("$string:description_mainability2"); + expect(data.icon).assertEqual("$media:icon"); + expect(data.descriptionId > 0).assertTrue(); + expect(data.iconId > 0).assertTrue(); + expect(data.moduleName).assertEqual("entry"); + expect(data.process).assertEqual(""); + expect(data.targetAbility).assertEqual(""); + expect(data.backgroundModes).assertEqual(0); + expect(data.isVisible).assertEqual(false); + expect(data.formEnabled).assertEqual(false); + expect(data.type).assertEqual(1); + expect(data.orientation).assertEqual(0); + expect(data.launchMode).assertEqual(1); + expect(data.deviceTypes[0]).assertEqual("phone"); + expect(data.readPermission).assertEqual(""); + expect(data.writePermission).assertEqual(""); + checkApplicationInfo2(msg,data.applicationInfo); + expect(data.formEntity).assertEqual(0); + expect(data.minFormHeight).assertEqual(0); + expect(data.defaultFormHeight).assertEqual(0); + expect(data.minFormWidth).assertEqual(0); + expect(data.defaultFormWidth).assertEqual(0); + expect(data.uri).assertEqual(""); + expect(data.labelId >0).assertTrue(); + expect(data.subType).assertEqual(0); + console.log(msg+ "---checkAbilityInfo End--- "); + } + + function checkApplicationInfo2(msg,info) { + console.log(msg+ "checkApplicationInfo start : " + JSON.stringify(info)); + console.log(msg+ "checkApplicationInfo name : " + info.name); + console.log(msg+ "checkApplicationInfo description : " + info.description); + console.log(msg+ "checkApplicationInfo descriptionId : " + info.descriptionId); + console.log(msg+ "checkApplicationInfo systemApp : " + info.systemApp); + console.log(msg+ "checkApplicationInfo enabled : " + info.enabled); + console.log(msg+ "checkApplicationInfo label : " + info.label); + console.log(msg+ "checkApplicationInfo labelId : " + info.labelId); + console.log(msg+ "checkApplicationInfo icon : " + info.icon); + console.log(msg+ "checkApplicationInfo iconId : " + info.iconId); + console.log(msg+ "checkApplicationInfo process : " + info.process); + console.log(msg+ "checkApplicationInfo supportedModes : " + info.supportedModes); + + console.log(msg+ "checkApplicationInfo moduleSourceDirs length : " + info.moduleSourceDirs.length); + for (var j = 0; j < info.moduleSourceDirs.length; j++) { + console.log(msg+ "checkApplicationInfo info.moduleSourceDirs[" + j + "] : " + info.moduleSourceDirs[j]); + } + console.log(msg+ "checkApplicationInfo permissions length : " + info.permissions.length); + for (var k = 0; k < info.permissions.length; k++) { + console.log(msg+ "checkApplicationInfo info.permissions[" + k + "] : " + info.permissions[k]); + } + console.log(msg+ "checkApplicationInfo moduleInfos length : " + info.moduleInfos.length); + for (var i = 0; i < info.moduleInfos.length; i++) { + console.log(msg+ "checkApplicationInfo info.moduleInfos[" + i + "].moduleName : " + info.moduleInfos[i].moduleName); + console.log(msg+ "checkApplicationInfo info.moduleInfos[" + i + "].moduleSourceDir : " + info.moduleInfos[i].moduleSourceDir); + } + console.log(msg+ "checkApplicationInfo entryDir : " + info.entryDir); + + expect(typeof (info)).assertEqual("object"); + expect(typeof (info.name)).assertEqual("string"); + expect(typeof (info.description)).assertEqual("string"); + expect(typeof (info.descriptionId)).assertEqual("number"); + expect(typeof (info.systemApp)).assertEqual("boolean"); + expect(typeof (info.enabled)).assertEqual("boolean"); + expect(typeof (info.label)).assertEqual("string"); + expect(typeof (info.labelId)).assertEqual("string"); + expect(typeof (info.icon)).assertEqual("string"); + expect(typeof (info.iconId)).assertEqual("string"); + expect(typeof (info.process)).assertEqual("string"); + expect(typeof (info.supportedModes)).assertEqual("number"); + expect(Array.isArray(info.moduleSourceDirs)).assertEqual(true); + expect(Array.isArray(info.permissions)).assertEqual(true); + expect(Array.isArray(info.moduleInfos)).assertEqual(true); + expect(typeof (info.entryDir)).assertEqual("string"); + + expect(info.name).assertEqual("com.ohos.acecollaboration"); + expect(info.description).assertEqual("$string:mainability_description"); + expect(info.descriptionId > 0).assertTrue(); + expect(info.systemApp).assertEqual(true); + expect(info.enabled).assertEqual(true); + expect(info.label).assertEqual("$string:entry_MainAbility"); + expect(info.icon).assertEqual("$media:icon"); + expect(info.process).assertEqual(""); + expect(info.supportedModes).assertEqual(0); + expect(info.entryDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.ohos.acecollaboration"); + if (info.moduleSourceDirs.length == 1){ + expect(info.moduleInfos[0].moduleName).assertEqual("entry"); + expect(info.moduleInfos[0].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.ohos.acecollaboration"); + }else if(info.moduleSourceDirs.length == 2) { + if (info.moduleInfos[0].moduleName == "myapplication1") { + expect(info.moduleInfos[0].moduleName).assertEqual("myapplication1"); + expect(info.moduleInfos[0].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.example.myapplication1"); + expect(info.moduleInfos[1].moduleName).assertEqual("entry"); + expect(info.moduleInfos[1].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.ohos.acecollaboration"); + }else{ + expect(info.moduleInfos[0].moduleName).assertEqual("myapplication2"); + expect(info.moduleInfos[0].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.example.myapplication2"); + expect(info.moduleInfos[1].moduleName).assertEqual("entry"); + expect(info.moduleInfos[1].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.ohos.acecollaboration"); + } + }else { + expect(info.moduleInfos[0].moduleName).assertEqual("myapplication1"); + expect(info.moduleInfos[0].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.example.myapplication1"); + expect(info.moduleInfos[1].moduleName).assertEqual("myapplication2"); + expect(info.moduleInfos[1].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.example.myapplication2"); + expect(info.moduleInfos[2].moduleName).assertEqual("entry"); + expect(info.moduleInfos[2].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.ohos.acecollaboration"); + } + console.log(msg+ "---checkApplicationInfo End--- "); + } + }) +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/ServiceAbility/service.ts b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/ServiceAbility/service.ts new file mode 100644 index 0000000000000000000000000000000000000000..1503232a7024bbced8a52b26449f056600b0f0bf --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/ServiceAbility/service.ts @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2021 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 rpc from '@ohos.rpc'; + +class StubTest extends rpc.RemoteObject { + constructor(des) { + super(des) + } + + onRemoteRequest(code, data, reply, option) { + console.info('ServiceAbility onRemoteRequest'); + if (code === 1) { + let op1 = data.readInt(); + let op2 = data.readInt(); + reply.writeInt(op1 + op2); + console.info('ServiceAbility op1:' + op1 + ' op2:' + op2); + } + return true; + } +} + +export default { + onStart() { + console.info('ServiceAbility onStart'); + }, + onStop() { + console.info('ServiceAbility onStop'); + }, + onCommand(want, startId) { + console.info('ServiceAbility onCommand'); + }, + onConnect(want) { + console.info('ServiceAbility onConnect'); + return new StubTest("test"); + }, + onDisConnect(want) { + console.info('ServiceAbility onDisConnect'); + }, +}; diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/ServiceAbility2/service.ts b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/ServiceAbility2/service.ts new file mode 100644 index 0000000000000000000000000000000000000000..a3c5e888497e748d7b1953bcbcbef23a6c0d0486 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/ServiceAbility2/service.ts @@ -0,0 +1,132 @@ +/** + * Copyright (c) 2021 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 particleAbility from '@ohos.ability.particleAbility'; +import rpc from '@ohos.rpc' + +class StubTest2 extends rpc.RemoteObject { + constructor(des) { + super(des) + } + + onRemoteRequest(code, data, reply, option) { + console.info('ServiceAbility2 onRemoteRequest'); + if (code === 1) { + let op1 = data.readInt(); + let op2 = data.readInt(); + reply.writeInt(op1 + op2); + console.info('ServiceAbility2 op1:' + op1 + ' op2:' + op2); + } + return true; + } +} + +function getNowTime() { + return new Date().getTime(); +} + +function getDurationTime(msg, startTime, endTime) { + console.info(msg + 'Get Interface startTime: ' + startTime); + console.info(msg + 'Get Interface endTime: ' + endTime); + var duration = (endTime - startTime) + console.info(msg + 'Get Interface Duration: ' + duration); + return duration; +} + +async function sleep(time: any) { + var now = new Date(); + var exitTime = now.getTime() + time; + while (true) { + now = new Date(); + if (now.getTime() > exitTime) + break; + } + console.info(`sleep ${time} over...`); +} + +export default { + onStart() { + console.info('ServiceAbility2 onStart'); + }, + onStop() { + console.info('ServiceAbility2 onStop'); + }, + onCommand(want, startId) { + console.info('ServiceAbility2 onCommand'); + let request = { + "bundleName": "com.ohos.acecollaboration", + "abilityName": "com.ohos.acecollaboration.ServiceAbility", + } + let options = { + onConnect: async function (element: any, proxy: any) { + console.log('particleAbility_connectAbility_test_0100 ConnectAbility onConnect element.deviceId : ' + + JSON.stringify(element.deviceId)); + console.log('particleAbility_connectAbility_test_0100 ConnectAbility onConnect element.bundleName : ' + + JSON.stringify(element.bundleName)); + console.log('particleAbility_connectAbility_test_0100 ConnectAbility onConnect element.abilityName : ' + + JSON.stringify(element.abilityName)); + console.log('particleAbility_connectAbility_test_0100 ConnectAbility onConnect element.uri : ' + + JSON.stringify(element.uri)); + console.log('particleAbility_connectAbility_test_0100 ConnectAbility onConnect element.shortName : ' + + JSON.stringify(element.shortName)); + console.log('particleAbility_connectAbility_test_0100 ConnectAbility onConnect proxy : ' + + JSON.stringify(proxy)); + }, + onDisconnect: async function (element1: any) { + console.log('particleAbility_connectAbility_test_0100 ConnectAbility onDisconnect element.deviceId : ' + + JSON.stringify(element1.deviceId)); + console.log('particleAbility_connectAbility_test_0100 ConnectAbility onDisconnect element.bundleName : ' + + JSON.stringify(element1.bundleName)); + console.log('particleAbility_connectAbility_test_0100 ConnectAbility onDisconnect element.abilityName: ' + + JSON.stringify(element1.abilityName)); + console.log('particleAbility_connectAbility_test_0100 ConnectAbility onDisconnect element.uri : ' + + JSON.stringify(element1.uri)); + console.log('particleAbility_connectAbility_test_0100 ConnectAbility onDisconnect element.shortName : ' + + JSON.stringify(element1.shortName)); + }, + onFailed: async function (code: any) { + console.log('particleAbility_connectAbility_test_0100 ConnectAbility onFailed errCode : ' + code); + }, + } + + let connection_succeeded: any; + console.info('particleAbility_connectAbility_test_0100 start '); + var timeOldStamp = getNowTime(); + var connection = particleAbility.connectAbility(request, options); + var timeNewStamp = getNowTime(); + getDurationTime('particleAbility_connectAbility_test_0100 connectability', timeOldStamp, timeNewStamp); + connection_succeeded = connection; + console.info('particleAbility_connectAbility_test_0100 service request is:' + JSON.stringify(request)); + console.info('particleAbility_connectAbility_test_0100 options is:' + JSON.stringify(options)); + console.info('particleAbility_connectAbility_test_0100 data is: ' + JSON.stringify(connection)); + console.info('particleAbility_connectAbility_test_0100 connection=: ' + connection); + sleep(5000); + console.info('particleAbility_connectAbility_test_0100 disconnectability start '); + var timeOldStamp = getNowTime(); + particleAbility.disconnectAbility(connection_succeeded).then((data: any) => { + var timeNewStamp = getNowTime(); + getDurationTime('particleAbility_connectAbility_test_0100 disconnectability', timeOldStamp, timeNewStamp); + console.info('particleAbility_connectAbility_test_0100 disconnectability succeeded: ' + + JSON.stringify(data)); + }).catch((error: any) => { + console.error('particleAbility_connectAbility_test_0100 disconnectability failed. Cause: ' + + JSON.stringify(error)); + }) + }, + onConnect(want) { + console.info('ServiceAbility2 onConnect'); + return new StubTest2("test"); + }, +}; \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/ServiceAbility3/service.ts b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/ServiceAbility3/service.ts new file mode 100644 index 0000000000000000000000000000000000000000..72c61a28d0ce923795b0a7b8d5a0dfa2e598af64 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/ServiceAbility3/service.ts @@ -0,0 +1,133 @@ +/** + * Copyright (c) 2021 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 particleAbility from '@ohos.ability.particleAbility'; +import rpc from '@ohos.rpc'; + +class StubTest3 extends rpc.RemoteObject { + constructor(des) { + super(des) + } + + onRemoteRequest(code, data, reply, option) { + console.info('ServiceAbility3 onRemoteRequest'); + if (code === 1) { + let op1 = data.readInt(); + let op2 = data.readInt(); + reply.writeInt(op1 + op2); + console.info('ServiceAbility3 op1:' + op1 + ' op2:' + op2); + } + return true; + } +} + +function getNowTime() { + return new Date().getTime(); +} + +function getDurationTime(msg, startTime, endTime) { + console.info(msg + 'Get Interface startTime: ' + startTime); + console.info(msg + 'Get Interface endTime: ' + endTime); + var duration = (endTime - startTime) + console.info(msg + 'Get Interface Duration: ' + duration); + return duration; +} + +async function sleep(time: any) { + var now = new Date(); + var exitTime = now.getTime() + time; + while (true) { + now = new Date(); + if (now.getTime() > exitTime) + break; + } + console.info(`sleep ${time} over...`); +} + +export default { + onStart() { + console.info('ServiceAbility3 onStart'); + }, + onStop() { + console.info('ServiceAbility3 onStop'); + }, + onCommand(want, startId) { + console.info('ServiceAbility3 onCommand'); + let request = { + "bundleName": "com.ohos.acecollaboration", + "abilityName": "com.ohos.acecollaboration.ServiceAbility", + } + let options = { + onConnect: async function (element: any, proxy: any) { + console.log('particleAbility_connectAbility_test_0200 ConnectAbility onConnect element.deviceId : ' + + JSON.stringify(element.deviceId)) + console.log('particleAbility_connectAbility_test_0200 ConnectAbility onConnect element.bundleName : ' + + JSON.stringify(element.bundleName)) + console.log('particleAbility_connectAbility_test_0200 ConnectAbility onConnect element.abilityName : ' + + JSON.stringify(element.abilityName)) + console.log('particleAbility_connectAbility_test_0200 ConnectAbility onConnect element.uri : ' + + JSON.stringify(element.uri)) + console.log('particleAbility_connectAbility_test_0200 ConnectAbility onConnect element.shortName : ' + + JSON.stringify(element.shortName)) + console.log('particleAbility_connectAbility_test_0200 ConnectAbility onConnect proxy : ' + + JSON.stringify(proxy)); + }, + onDisconnect: async function (element1: any) { + console.log('particleAbility_connectAbility_test_0200 ConnectAbility onDisconnect element.deviceId :' + + JSON.stringify(element1.deviceId)); + console.log('particleAbility_connectAbility_test_0200 ConnectAbility onDisconnect element.bundleName :' + + JSON.stringify(element1.bundleName)); + console.log('particleAbility_connectAbility_test_0200 ConnectAbility onDisconnect element.abilityName :' + + JSON.stringify(element1.abilityName)); + console.log('particleAbility_connectAbility_test_0200 ConnectAbility onDisconnect element.uri : ' + + JSON.stringify(element1.uri)); + console.log('particleAbility_connectAbility_test_0200 ConnectAbility onDisconnect element.shortName : ' + + JSON.stringify(element1.shortName)); + }, + onFailed: function (code: any) { + console.log('particleAbility_connectAbility_test_0200 ConnectAbility onFailed errCode: ' + code) + }, + } + + let connection_succeeded: any; + console.info('particleAbility_connectAbility_test_0200 start '); + var timeOldStamp = getNowTime(); + var connection = particleAbility.connectAbility(request, options); + var timeNewStamp = getNowTime(); + getDurationTime('particleAbility_connectAbility_test_0200 connectability', timeOldStamp, timeNewStamp); + connection_succeeded = connection; + console.info('particleAbility_connectAbility_test_0200 service request is:' + JSON.stringify(request)); + console.info('particleAbility_connectAbility_test_0200 options is:' + JSON.stringify(options)); + console.info('particleAbility_connectAbility_test_0200 connection=: ' + connection); + sleep(5000); + console.info('particleAbility_connectAbility_test_0200 disconnectability start '); + try { + var timeOldStamp = getNowTime(); + particleAbility.disconnectAbility(connection_succeeded, (error, data) => { + var timeNewStamp = getNowTime(); + getDurationTime('particleAbility_connectAbility_test_0200 disconnectability', timeOldStamp, timeNewStamp); + console.info('particleAbility_connectAbility_test_0200 disconnectability succeeded: ' + JSON.stringify(data)); + }) + } + catch(error: any){ + console.error('particleAbility_connectAbility_test_0200 disconnectability failed. Cause: ' + + JSON.stringify(error)); + } + }, + onConnect(want) { + console.info('ServiceAbility3 onConnect'); + return new StubTest3("test"); + }, +}; \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/ServiceAbility4/service.ts b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/ServiceAbility4/service.ts new file mode 100644 index 0000000000000000000000000000000000000000..d35fb6c9b69ef69e536f5b53d8843a4e2fc39d00 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/ServiceAbility4/service.ts @@ -0,0 +1,132 @@ +/** + * Copyright (c) 2021 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 particleAbility from '@ohos.ability.particleAbility'; +import rpc from '@ohos.rpc' + +class StubTest4 extends rpc.RemoteObject { + constructor(des) { + super(des) + } + + onRemoteRequest(code, data, reply, option) { + console.info('ServiceAbility4 onRemoteRequest'); + if (code === 1) { + let op1 = data.readInt(); + let op2 = data.readInt(); + reply.writeInt(op1 + op2); + console.info('ServiceAbility4 op1:' + op1 + ' op2:' + op2); + } + return true; + } +} + +function getNowTime() { + return new Date().getTime(); +} + +function getDurationTime(msg, startTime, endTime) { + console.info(msg + 'Get Interface startTime: ' + startTime); + console.info(msg + 'Get Interface endTime: ' + endTime); + var duration = (endTime - startTime) + console.info(msg + 'Get Interface Duration: ' + duration); + return duration; +} + +async function sleep(time: any) { + var now = new Date(); + var exitTime = now.getTime() + time; + while (true) { + now = new Date(); + if (now.getTime() > exitTime) + break; + } + console.info(`sleep ${time} over...`); +} + +export default { + onStart() { + console.info('ServiceAbility4 onStart'); + }, + onStop() { + console.info('ServiceAbility4 onStop'); + }, + onCommand(want, startId) { + console.info('ServiceAbility4 onCommand'); + let request = { + "bundleName": "com.open.harmony.packagemag", + "abilityName": "com.open.harmony.packagemag.packServiceAbility", + } + let options = { + onConnect: async function (element: any, proxy: any) { + console.log('particleAbility_connectAbility_test_0300 ConnectAbility onConnect element.deviceId : ' + + JSON.stringify(element.deviceId)) + console.log('particleAbility_connectAbility_test_0300 ConnectAbility onConnect element.bundleName : ' + + JSON.stringify(element.bundleName)) + console.log('particleAbility_connectAbility_test_0300 ConnectAbility onConnect element.abilityName : ' + + JSON.stringify(element.abilityName)) + console.log('particleAbility_connectAbility_test_0300 ConnectAbility onConnect element.uri : ' + + JSON.stringify(element.uri)) + console.log('particleAbility_connectAbility_test_0300 ConnectAbility onConnect element.shortName : ' + + JSON.stringify(element.shortName)) + console.log('particleAbility_connectAbility_test_0300 ConnectAbility onConnect proxy : ' + + JSON.stringify(proxy)); + }, + onDisconnect: async function (element1: any) { + console.log('particleAbility_connectAbility_test_0300 ConnectAbility onDisconnect element.deviceId : ' + + JSON.stringify(element1.deviceId)); + console.log('particleAbility_connectAbility_test_0300 ConnectAbility onDisconnect element.bundleName: ' + + JSON.stringify(element1.bundleName)); + console.log('particleAbility_connectAbility_test_0300 ConnectAbility onDisconnect element.abilityName:' + + JSON.stringify(element1.abilityName)); + console.log('particleAbility_connectAbility_test_0300 ConnectAbility onDisconnect element.uri: ' + + JSON.stringify(element1.uri)); + console.log('particleAbility_connectAbility_test_0300 ConnectAbility onDisconnect element.shortName :' + + JSON.stringify(element1.shortName)); + }, + onFailed: function (code: any) { + console.log('particleAbility_connectAbility_test_0300 ConnectAbility onFailed errCode : '+ code); + }, + } + + let connection_succeeded: any; + console.info('particleAbility_connectAbility_test_0300 start '); + var timeOldStamp = getNowTime(); + var connection = particleAbility.connectAbility(request, options); + var timeNewStamp = getNowTime(); + getDurationTime('particleAbility_connectAbility_test_0300 connectability', timeOldStamp, timeNewStamp); + connection_succeeded = connection; + console.info('particleAbility_connectAbility_test_0300 service request is:' + JSON.stringify(request)); + console.info('particleAbility_connectAbility_test_0300 options is:' + JSON.stringify(options)); + console.info('particleAbility_connectAbility_test_0300 data is: ' + JSON.stringify(connection)); + console.info('particleAbility_connectAbility_test_0300 connection=: ' + connection); + sleep(5000); + console.info('particleAbility_connectAbility_test_0300 disconnectability start '); + var timeOldStamp = getNowTime(); + particleAbility.disconnectAbility(connection_succeeded).then((data: any) => { + var timeNewStamp = getNowTime(); + getDurationTime('particleAbility_connectAbility_test_0300 disconnectability', timeOldStamp, timeNewStamp); + console.info('particleAbility_connectAbility_test_0300 disconnectability succeeded:' + + JSON.stringify(data)); + }).catch ((error: any) =>{ + console.error('particleAbility_connectAbility_test_0300 disconnectability failed. Cause: ' + + JSON.stringify(error)); + }) + }, + onConnect(want) { + console.info('ServiceAbility4 onConnect'); + return new StubTest4("test"); + }, +}; \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/ServiceAbility5/service.ts b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/ServiceAbility5/service.ts new file mode 100644 index 0000000000000000000000000000000000000000..16a737c348c7c200b1ef49acc08c922c755f6e26 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/ServiceAbility5/service.ts @@ -0,0 +1,147 @@ +/** + * Copyright (c) 2021 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 particleAbility from '@ohos.ability.particleAbility'; +import rpc from '@ohos.rpc' + +class StubTest5 extends rpc.RemoteObject { + constructor(des) { + super(des) + } + + onRemoteRequest(code, data, reply, option) { + console.info('ServiceAbility5 onRemoteRequest'); + if (code === 1) { + let op1 = data.readInt(); + let op2 = data.readInt(); + reply.writeInt(op1 + op2); + console.info('ServiceAbility5 op1:' + op1 + ' op2:' + op2); + } + return true; + } +} + +function getNowTime() { + return new Date().getTime(); +} + +function getDurationTime(msg, startTime, endTime) { + console.info(msg + 'Get Interface startTime: ' + startTime); + console.info(msg + 'Get Interface endTime: ' + endTime); + var duration = (endTime - startTime) + console.info(msg + 'Get Interface Duration: ' + duration); + return duration; +} + +async function sleep(time: any) { + var now = new Date(); + var exitTime = now.getTime() + time; + while (true) { + now = new Date(); + if (now.getTime() > exitTime) + break; + } + console.info(`sleep ${time} over...`); +} + +export default { + onStart() { + console.info('ServiceAbility5 onStart'); + }, + onStop() { + console.info('ServiceAbility5 onStop'); + }, + onCommand(want, startId) { + console.info('ServiceAbility5 onCommand'); + let request = { + "bundleName": "", + "abilityName": "", + } + let options = { + onConnect: async function (element: any, proxy: any) { + console.log('particleAbility_connectAbility_test_0400 ConnectAbility onConnect element.deviceId : ' + + JSON.stringify(element.deviceId)) + console.log('particleAbility_connectAbility_test_0400 ConnectAbility onConnect element.bundleName : ' + + JSON.stringify(element.bundleName)) + console.log('particleAbility_connectAbility_test_0400 ConnectAbility onConnect element.abilityName : ' + + JSON.stringify(element.abilityName)) + console.log('particleAbility_connectAbility_test_0400 ConnectAbility onConnect element.uri : ' + + JSON.stringify(element.uri)) + console.log('particleAbility_connectAbility_test_0400 ConnectAbility onConnect element.shortName : ' + + JSON.stringify(element.shortName)) + console.log('particleAbility_connectAbility_test_0400 ConnectAbility onConnect proxy : ' + + JSON.stringify(proxy)); + }, + onDisconnect: function (element1: any) { + console.log('particleAbility_connectAbility_test_0400 ConnectAbility onDisconnect element.deviceId : ' + + JSON.stringify(element1.deviceId)); + console.log('particleAbility_connectAbility_test_0400 ConnectAbility onDisconnect element.bundleName: ' + + JSON.stringify(element1.bundleName)); + console.log('particleAbility_connectAbility_test_0400 ConnectAbility onDisconnect element.abilityName:' + + JSON.stringify(element1.abilityName)); + console.log('particleAbility_connectAbility_test_0400 ConnectAbility onDisconnect element.uri : ' + + JSON.stringify(element1.uri)); + console.log('particleAbility_connectAbility_test_0400 ConnectAbility onDisconnect element.shortName : ' + + JSON.stringify(element1.shortName)); + }, + onFailed: function (code: any) { + console.log('particleAbility_connectAbility_test_0400 ConnectAbility onFailed errCode:' + code); + }, + } + + let connection_succeeded: any; + console.info('particleAbility_connectAbility_test_0400 start '); + var timeOldStamp = getNowTime(); + var connection = particleAbility.connectAbility(request, options); + var timeNewStamp = getNowTime(); + getDurationTime('particleAbility_connectAbility_test_0400 connectability', timeOldStamp, timeNewStamp); + connection_succeeded = connection; + console.info('particleAbility_connectAbility_test_0400 service request is:' + JSON.stringify(request)); + console.info('particleAbility_connectAbility_test_0400 options is:' + JSON.stringify(options)); + console.info('particleAbility_connectAbility_test_0400 connection=: ' + connection); + sleep(5000); + console.info('particleAbility_connectAbility_test_0400 disconnectability start '); + var timeOldStamp = getNowTime(); + particleAbility.disconnectAbility(connection_succeeded).then((data: any) => { + var timeNewStamp = getNowTime(); + getDurationTime('particleAbility_connectAbility_test_0400 disconnectability', timeOldStamp, timeNewStamp); + console.info('particleAbility_connectAbility_test_0400 disconnectability succeeded: ' + + JSON.stringify(data)); + }).catch((error: any) => { + console.error('particleAbility_connectAbility_test_0400 disconnectability failed. Cause: ' + + JSON.stringify(error)); + }); + sleep(5000); + console.info('particleAbility_connectAbility_test_0400 disconnectability_fail start '); + try { + var timeOldStamp = getNowTime(); + particleAbility.disconnectAbility(-1).then((data: any) => { + var timeNewStamp = getNowTime(); + getDurationTime('particleAbility_connectAbility_test_0400 disconnectability_fail', + timeOldStamp, timeNewStamp); + console.info('particleAbility_connectAbility_test_0400 disconnectability_fail succeeded: ' + + JSON.stringify(data)); + }) + } + catch (error: any) { + console.error('particleAbility_connectAbility_test_0400 disconnectability_fail failed. Cause: ' + + JSON.stringify(error)); + } + }, + onConnect(want) { + console.info('ServiceAbility5 onConnect'); + return new StubTest5("test"); + }, +}; \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/ServiceAbility6/service.ts b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/ServiceAbility6/service.ts new file mode 100644 index 0000000000000000000000000000000000000000..b36d40babb5564311b59d2bb63837c2c6298a0a5 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/ServiceAbility6/service.ts @@ -0,0 +1,108 @@ +/** + * Copyright (c) 2021 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 particleAbility from '@ohos.ability.particleAbility'; +import rpc from '@ohos.rpc' + +class StubTest6 extends rpc.RemoteObject { + constructor(des) { + super(des) + } + + onRemoteRequest(code, data, reply, option) { + console.info('ServiceAbility6 onRemoteRequest'); + if (code === 1) { + let op1 = data.readInt(); + let op2 = data.readInt(); + reply.writeInt(op1 + op2); + console.info('ServiceAbility6 op1:' + op1 + ' op2:' + op2); + } + return true; + } +} +function getNowTime() { + return new Date().getTime(); +} + +function getDurationTime(msg, startTime, endTime) { + console.info(msg + 'Get Interface startTime: ' + startTime); + console.info(msg + 'Get Interface endTime: ' + endTime); + var duration = (endTime - startTime) + console.info(msg + 'Get Interface Duration: ' + duration); + return duration; +} + +export default { + onStart() { + console.info('ServiceAbility onStart'); + }, + onStop() { + console.info('ServiceAbility onStop'); + }, + onCommand(want, startId) { + console.info('ServiceAbility onCommand'); + + let request = { + "bundleName":"com.ohos.acecollaboration", + "abilityName":"com.ohos.acecollaboration.xxx", + } + let options = { + onConnect:async function (element:any, proxy:any) { + console.log('particleAbility_connectAbility_test_0500 ConnectAbility onConnect element.deviceId : ' + + JSON.stringify(element.deviceId)) + console.log('particleAbility_connectAbility_test_0500 ConnectAbility onConnect element.bundleName : ' + + JSON.stringify(element.bundleName)) + console.log('particleAbility_connectAbility_test_0500 ConnectAbility onConnect element.abilityName : ' + + JSON.stringify(element.abilityName)) + console.log('particleAbility_connectAbility_test_0500 ConnectAbility onConnect element.uri : ' + + JSON.stringify(element.uri)) + console.log('particleAbility_connectAbility_test_0500 ConnectAbility onConnect element.shortName : ' + + JSON.stringify(element.shortName)) + console.log('particleAbility_connectAbility_test_0500 ConnectAbility onConnect proxy : ' + + JSON.stringify(proxy)); + }, + onDisconnect:function (element1:any) { + console.log('particleAbility_connectAbility_test_0500 ConnectAbility onDisconnect element.deviceId : ' + + JSON.stringify(element1.deviceId)); + console.log('particleAbility_connectAbility_test_0500 ConnectAbility onDisconnect element.bundleName: ' + + JSON.stringify(element1.bundleName)); + console.log('particleAbility_connectAbility_test_0500 ConnectAbility onDisconnect element.abilityName:' + + JSON.stringify(element1.abilityName)); + console.log('particleAbility_connectAbility_test_0500 ConnectAbility onDisconnect element.uri : ' + + JSON.stringify(element1.uri)); + console.log('particleAbility_connectAbility_test_0500 ConnectAbility onDisconnect element.shortName : ' + + JSON.stringify(element1.shortName)); + }, + onFailed:function (code:any) { + console.log('particleAbility_connectAbility_test_0500 ConnectAbility service onFailed errCode:' + code) + }, + } + + console.info('particleAbility_connectAbility_test_0500 errorabilityName start'); + var timeOldStamp = getNowTime(); + var connection = particleAbility.connectAbility(request, options); + var timeNewStamp = getNowTime(); + getDurationTime('particleAbility_connectAbility_test_0500 connectability', timeOldStamp, timeNewStamp); + console.info('particleAbility_connectAbility_test_0500 errorabilityName request is:' + + JSON.stringify(request)); + console.info('particleAbility_connectAbility_test_0500 errorabilityName options is:' + + JSON.stringify(options)); + console.info('particleAbility_connectAbility_test_0500 errorabilityName connection=: ' + connection); + }, + onConnect(want) { + console.info('ServiceAbility6 onConnect'); + return new StubTest6("test"); + }, +}; \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/ServiceAbility7/service.ts b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/ServiceAbility7/service.ts new file mode 100644 index 0000000000000000000000000000000000000000..32fe65dec8ea4d8e89197d561f6cecc2785db423 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/ets/ServiceAbility7/service.ts @@ -0,0 +1,135 @@ +/** + * Copyright (c) 2021 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 particleAbility from '@ohos.ability.particleAbility'; +import rpc from '@ohos.rpc' + +class StubTest7 extends rpc.RemoteObject { + constructor(des) { + super(des) + } + + onRemoteRequest(code, data, reply, option) { + console.info('ServiceAbility7 onRemoteRequest'); + if (code === 1) { + let op1 = data.readInt(); + let op2 = data.readInt(); + reply.writeInt(op1 + op2); + console.info('ServiceAbility7 op1:' + op1 + ' op2:' + op2); + } + return true; + } +} + +function getNowTime() { + return new Date().getTime(); +} + +function getDurationTime(msg, startTime, endTime) { + console.info(msg + 'Get Interface startTime: ' + startTime); + console.info(msg + 'Get Interface endTime: ' + endTime); + var duration = (endTime - startTime) + console.info(msg + 'Get Interface Duration: ' + duration); + return duration; +} + +async function sleep(time: any) { + var now = new Date(); + var exitTime = now.getTime() + time; + while (true) { + now = new Date(); + if (now.getTime() > exitTime) + break; + } + console.info(`sleep ${time} over...`); +} +export default { + onStart() { + console.info('ServiceAbility7 onStart'); + }, + onStop() { + console.info('ServiceAbility7 onStop'); + }, + onCommand(want, startId) { + console.info('ServiceAbility7 onCommand'); + + let request = { + "bundleName":"com.example.myapplication", + "abilityName":"com.example.myapplication.ServiceAbility_API8", + } + let options = { + onConnect:async function (element:any, proxy:any) { + console.log('particleAbility_connectAbility_test_0600 ConnectAbility onConnect element.deviceId : ' + + JSON.stringify(element.deviceId)) + console.log('particleAbility_connectAbility_test_0600 ConnectAbility onConnect element.bundleName : ' + + JSON.stringify(element.bundleName)) + console.log('particleAbility_connectAbility_test_0600 ConnectAbility onConnect element.abilityName : ' + + JSON.stringify(element.abilityName)) + console.log('particleAbility_connectAbility_test_0600 ConnectAbility onConnect element.uri : ' + + JSON.stringify(element.uri)) + console.log('particleAbility_connectAbility_test_0600 ConnectAbility onConnect element.shortName : ' + + JSON.stringify(element.shortName)) + console.log('particleAbility_connectAbility_test_0600 ConnectAbility onConnect proxy : ' + + JSON.stringify(proxy)); + }, + onDisconnect:async function (element1:any) { + console.log('particleAbility_connectAbility_test_0600 ConnectAbility onDisconnect element.deviceId : ' + + JSON.stringify(element1.deviceId)); + console.log('particleAbility_connectAbility_test_0600 ConnectAbility onDisconnect element.bundleName: ' + + JSON.stringify(element1.bundleName)); + console.log('particleAbility_connectAbility_test_0600 ConnectAbility onDisconnect element.abilityName:' + + JSON.stringify(element1.abilityName)); + console.log('particleAbility_connectAbility_test_0600 ConnectAbility onDisconnect element.uri : ' + + JSON.stringify(element1.uri)); + console.log('particleAbility_connectAbility_test_0600 ConnectAbility onDisconnect element.shortName : ' + + JSON.stringify(element1.shortName)); + }, + onFailed:function (code:any) { + console.log('particleAbility_connectAbility_test_0600 ConnectAbility onFailed errCode:' + code); + }, + } + + let connection_succeeded:any; + console.info('particleAbility_connectAbility_test_0600 start '); + var timeOldStamp = getNowTime(); + var connection = particleAbility.connectAbility(request, options); + var timeNewStamp = getNowTime(); + getDurationTime('particleAbility_connectAbility_test_0600 connectability', timeOldStamp, timeNewStamp); + connection_succeeded = connection; + console.info('particleAbility_connectAbility_test_0600 service request is:' + JSON.stringify(request)); + console.info('particleAbility_connectAbility_test_0600 options is:' + JSON.stringify(options)); + console.info('particleAbility_connectAbility_test_0600 data is: ' + JSON.stringify(connection)); + console.info('particleAbility_connectAbility_test_0600 connection=: ' + connection); + sleep(5000); + console.info('particleAbility_connectAbility_test_0600 disconnectability start '); + var timeOldStamp = getNowTime(); + particleAbility.disconnectAbility(connection_succeeded).then((data: any) => { + var timeNewStamp = getNowTime(); + getDurationTime('particleAbility_connectAbility_test_0600 disconnectability', timeOldStamp, timeNewStamp); + console.info('particleAbility_connectAbility_test_0600 disconnectability succeeded: ' + + JSON.stringify(data)); + }).catch((error: any) =>{ + console.error('particleAbility_connectAbility_test_0600 disconnectability failed. Cause: ' + + JSON.stringify(error)); + }); + }, + onConnect(want) { + console.info('ServiceAbility7 onConnect'); + return new StubTest7("test"); + }, + onDisConnect(want) { + console.info('ServiceAbility7 onDisConnect'); + }, +}; \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/resources/base/element/string.json b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ffd4ec49bed1ed0a06d1373e4a8d1f19afc51ac8 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/resources/base/element/string.json @@ -0,0 +1,48 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "entry_MainAbility" + }, + { + "name": "mainability_description", + "value": "eTS_Empty Ability" + }, + { + "name": "description_serviceability", + "value": "hap sample empty service" + }, + { + "name": "description_serviceability2", + "value": "hap sample empty service" + }, + { + "name": "description_serviceability3", + "value": "hap sample empty service" + }, + { + "name": "description_serviceability4", + "value": "hap sample empty service" + }, + { + "name": "description_serviceability5", + "value": "hap sample empty service" + }, + { + "name": "description_mainability2", + "value": "eTS_Empty Ability2" + }, + { + "name": "entry_MainAbility2", + "value": "MainAbility2" + }, + { + "name": "description_serviceability6", + "value": "hap sample empty service" + }, + { + "name": "description_serviceability7", + "value": "hap sample empty service" + } + ] +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/resources/base/media/icon.png b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/aafwk/aafwk_standard/actsabilitymanageretstest/entry/src/main/resources/base/media/icon.png differ diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/config.json b/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..ebcff6d524d771d93a18e206afb0934260198e78 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/config.json @@ -0,0 +1,57 @@ +{ + "app": { + "bundleName": "com.ohos.acecollaboration", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.myapplication1", + "name": ".MyApplication", + "mainAbility": ".MainAbility", + "srcPath": "", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "myapplication1", + "moduleType": "feature", + "installationFree": false + }, + "abilities": [ + { + "orientation": "unspecified", + "visible": true, + "srcPath": "MainAbility", + "name": ".MainAbility", + "srcLanguage": "ets", + "icon": "$media:icon", + "description": "$string:description_mainability", + "formsEnabled": false, + "label": "$string:myapplication1_MainAbility", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "mode": { + "syntax": "ets", + "type": "pageAbility" + }, + "pages": [ + "pages/index" + ], + "name": ".MainAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/ets/MainAbility/app.ets b/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/ets/MainAbility/app.ets new file mode 100644 index 0000000000000000000000000000000000000000..7aa1eae37d7e14260b0f22a90c5a5f7560b8f0f2 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/ets/MainAbility/app.ets @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2021 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 default { + onCreate() { + console.info('Application onCreate') + }, + onDestroy() { + console.info('Application onDestroy') + }, +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/ets/MainAbility/pages/index.ets b/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/ets/MainAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..d39e37aa687879af8aa3ab6021f85353730243fb --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/ets/MainAbility/pages/index.ets @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2021 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 file from '@system.file'; +import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index.ets"; +import testsuite_app1 from "../test/List.test.ets"; +import featureAbility from "@ohos.ability.featureAbility"; + +@Entry +@Component +struct Index { + aboutToAppear() { + console.info("start run testcase!!!!") + featureAbility.getWant() + .then((Want) => { + const core = Core.getInstance(); + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }); + core.addService('expect', expectExtend); + const reportExtend = new ReportExtend(file); + core.addService('report', reportExtend); + core.init(); + core.subscribeEvent('task', reportExtend); + const configService = core.getDefaultService('config'); + console.info('parameters---->' + JSON.stringify(Want.parameters)); + configService.setConfig(Want.parameters); + testsuite_app1(); + core.execute(); + console.info('Operation successful. Data: ' + JSON.stringify(Want)); + }) + .catch((error) => { + console.error('Operation failed. Cause: ' + JSON.stringify(error)); + }) + } + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('myapplication1 page') + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/ets/MainAbility/test/List.test.ets b/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/ets/MainAbility/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..e5bd7d594d190f2b30c723d0f93c439f28d27375 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/ets/MainAbility/test/List.test.ets @@ -0,0 +1,21 @@ +/** + * Copyright (c) 2021 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 getHapModuleInfoJsunit_app1 from './getHapModuleInfoJsunit_app1.test.ets'; + +export default function testsuite_app1() { + getHapModuleInfoJsunit_app1(); + +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/ets/MainAbility/test/Utils.ets b/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/ets/MainAbility/test/Utils.ets new file mode 100644 index 0000000000000000000000000000000000000000..58900ffcdfc72e853714250ae84cda913c6c9947 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/ets/MainAbility/test/Utils.ets @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2021 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 default class Utils { + static sleep(time) { + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve(reject) + }, time) + }).then(() => { + console.info(`sleep ${time} over...`) + }) + } + + static getNowTime() { + return new Date().getTime(); + } + + static getDurationTime(msg,startTime, endTime) { + console.info(msg+'Get Interface startTime: ' + startTime); + console.info(msg+'Get Interface endTime: ' + endTime); + var duration = (endTime - startTime) + console.info(msg+'Get Interface Duration: ' + duration); + return duration; + } +} + + + + diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/ets/MainAbility/test/getHapModuleInfoJsunit_app1.test.ets b/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/ets/MainAbility/test/getHapModuleInfoJsunit_app1.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..685a71d103d5574b438ddfd73b934ec212570fc2 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/ets/MainAbility/test/getHapModuleInfoJsunit_app1.test.ets @@ -0,0 +1,301 @@ +/** + * Copyright (c) 2021 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 {describe, it, expect} from "deccjsunit/index.ets"; +import Utils from './Utils'; +import ability_featureAbility from '@ohos.ability.featureAbility'; + +export default function getHapModuleInfoJsunit() { + describe('appInfoTest', function () { + + /** + * @tc.number: context_getHapModuleInfo_test_0300 + * @tc.name: getHapModuleInfo:Obtains the HapModuleInfo object of the application. + * @tc.desc: Check the return type of the interface (by Promise) + * @tc.level 0 + */ + it('context_getHapModuleInfo_test_0300', 0, async function (done) { + console.info('[context_getHapModuleInfo_test_0300] START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + var context = ability_featureAbility.getContext(); + context.getHapModuleInfo() + .then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('context_getHapModuleInfo_test_0300', timeOldStamp, timeNewStamp); + console.info('[context_getHapModuleInfo_test_0300] data is:' + JSON.stringify(data)); + expect(typeof (data)).assertEqual("object"); + }) + .catch((error) => { + console.error('[context_getHapModuleInfo_test_0300] failed:' + JSON.stringify(error)); + }) + var promise = await context.getHapModuleInfo(); + console.info('---[context_getHapModuleInfo_test_0300] check---'); + checkHapModuleInfo_app('context_getHapModuleInfo_test_0300', promise); + console.info('[context_getHapModuleInfo_test_0300] FINISH'); + done(); + }); + + function checkHapModuleInfo_app(msg, data) { + console.log(msg + "checkHapModuleInfo start " + JSON.stringify(data)); + console.log(msg + "checkHapModuleInfo name : " + data.name); + console.log(msg + "checkHapModuleInfo description : " + data.description); + console.log(msg + "checkHapModuleInfo descriptionId : " + data.descriptionId); + console.log(msg + "checkHapModuleInfo icon : " + data.icon); + console.log(msg + "checkHapModuleInfo label : " + data.label); + console.log(msg + "checkHapModuleInfo labelId : " + data.labelId); + console.log(msg + "checkHapModuleInfo iconId : " + data.iconId); + console.log(msg + "checkHapModuleInfo backgroundImg : " + data.backgroundImg); + console.log(msg + "checkHapModuleInfo supportedModes : " + data.supportedModes); + console.log(msg + "checkHapModuleInfo reqCapabilities length : " + data.reqCapabilities.length); + for (var j = 0; j < data.reqCapabilities.length; j++) { + console.log(msg + "getHapModuleInfo data.reqCapabilities[" + j + "] : " + data.reqCapabilities[j]); + } + console.log(msg + "checkHapModuleInfo deviceTypes length : " + data.deviceTypes.length); + for (var k = 0; k < data.deviceTypes.length; k++) { + console.log(msg + "getHapModuleInfo data.deviceTypes[" + k + "] : " + data.deviceTypes[k]); + } + console.log(msg + "checkHapModuleInfo abilityInfos length : " + data.abilityInfos.length); + console.log(msg + "checkHapModuleInfo moduleName : " + data.moduleName); + console.log(msg + "checkHapModuleInfo mainAbilityName : " + data.mainAbilityName); + console.log(msg + "checkHapModuleInfo installationFree : " + data.installationFree); + + expect(typeof (data)).assertEqual("object"); + expect(typeof (data.name)).assertEqual("string"); + expect(typeof (data.description)).assertEqual("string"); + expect(typeof (data.descriptionId)).assertEqual("number"); + expect(typeof (data.icon)).assertEqual("string"); + expect(typeof (data.label)).assertEqual("string"); + expect(typeof (data.labelId)).assertEqual("number"); + expect(typeof (data.iconId)).assertEqual("number"); + expect(typeof (data.backgroundImg)).assertEqual("string"); + expect(typeof (data.supportedModes)).assertEqual("number"); + expect(Array.isArray(data.reqCapabilities)).assertEqual(true); + expect(Array.isArray(data.deviceTypes)).assertEqual(true); + expect(Array.isArray(data.abilityInfos)).assertEqual(true); + expect(typeof (data.moduleName)).assertEqual("string"); + expect(typeof (data.mainAbilityName)).assertEqual("string"); + expect(typeof (data.installationFree)).assertEqual("boolean"); + expect(data.name).assertEqual("com.example.myapplication1"); + expect(data.description).assertEqual(""); + expect(data.descriptionId).assertEqual(0); + expect(data.icon).assertEqual("$media:icon"); + expect(data.label).assertEqual("$string:myapplication1_MainAbility"); + expect(data.labelId).assertEqual(0); + expect(data.iconId).assertEqual(0); + expect(data.backgroundImg).assertEqual(""); + expect(data.supportedModes).assertEqual(0); + + expect(data.deviceTypes[0]).assertEqual("phone"); + checkAbilityInfo(msg,data.abilityInfos[0]); + + expect(data.moduleName).assertEqual("myapplication1") + expect(data.mainAbilityName).assertEqual(""); + expect(data.installationFree).assertEqual(false); + + console.log(msg + "---checkHapModuleInfo End---"); + } + + function checkAbilityInfo(msg,data) { + console.log(msg+ "checkAbilityInfo start " + JSON.stringify(data)); + console.log(msg+ "checkAbilityInfo bundleName : " + data.bundleName); + console.log(msg+ "checkAbilityInfo name : " + data.name); + console.log(msg+ "checkAbilityInfo label : " + data.label); + console.log(msg+ "checkAbilityInfo description : " + data.description); + console.log(msg+ "checkAbilityInfo icon : " + data.icon); + console.log(msg+ "checkAbilityInfo descriptionId : " + data.descriptionId); + console.log(msg+ "checkAbilityInfo iconId : " + data.iconId); + console.log(msg+ "checkAbilityInfo moduleName : " + data.moduleName); + console.log(msg+ "checkAbilityInfo process : " + data.process); + console.log(msg+ "checkAbilityInfo targetAbility : " + data.targetAbility); + console.log(msg+ "checkAbilityInfo backgroundModes : " + data.backgroundModes); + console.log(msg+ "checkAbilityInfo isVisible : " + data.isVisible); + console.log(msg+ "checkAbilityInfo formEnabled : " + data.formEnabled); + console.log(msg+ "checkAbilityInfo type : " + data.type) + console.log(msg+ "checkAbilityInfo orientation : " + data.orientation); + console.log(msg+ "checkAbilityInfo launchMode : " + data.launchMode); + console.log(msg+ "checkAbilityInfo permissions length : " + data.permissions.length); + for (var j = 0; j < data.permissions.length; j++) { + console.log(msg+ "getAbilityInfo data.permissions[" + j + "] : " + data.permissions[j]); + } + console.log(msg+ "checkAbilityInfo deviceTypes length : " + data.deviceTypes.length); + for (var k = 0; k < data.deviceTypes.length; k++) { + console.log(msg+ "getAbilityInfo data.deviceTypes[" + k + "] : " + data.deviceTypes[k]); + } + console.log(msg+ "checkAbilityInfo deviceCapabilities length : " + data.deviceCapabilities.length); + for (var i = 0; i < data.deviceCapabilities.length; i++) { + console.log(msg+ "getAbilityInfo data.deviceCapabilities[" + i + "] : " + data.deviceCapabilities[i]); + } + console.log(msg+ "checkAbilityInfo readPermission : " + data.readPermission); + console.log(msg+ "checkAbilityInfo writePermission : " + data.writePermission); + console.log(msg+ "checkAbilityInfo formEntity : " + data.formEntity); + console.log(msg+ "checkAbilityInfo minFormHeight : " + data.minFormHeight); + console.log(msg+ "checkAbilityInfo defaultFormHeight : " + data.defaultFormHeight); + console.log(msg+ "checkAbilityInfo minFormWidth : " + data.minFormWidth); + console.log(msg+ "checkAbilityInfo defaultFormWidth : " + data.defaultFormWidth); + console.log(msg+ "checkAbilityInfo uri : " + data.uri); + console.log(msg+ "checkAbilityInfo labelId : " + data.labelId); + console.log(msg+ "checkAbilityInfo subType : " + data.subType); + expect(typeof (data)).assertEqual("object"); + expect(typeof (data.bundleName)).assertEqual("string"); + expect(typeof (data.name)).assertEqual("string"); + expect(typeof (data.label)).assertEqual("string"); + expect(typeof (data.description)).assertEqual("string"); + expect(typeof (data.icon)).assertEqual("string"); + expect(typeof (data.labelId)).assertEqual("number"); + expect(typeof (data.descriptionId)).assertEqual("number"); + expect(typeof (data.iconId)).assertEqual("number"); + expect(typeof (data.moduleName)).assertEqual("string"); + expect(typeof (data.process)).assertEqual("string"); + expect(typeof (data.targetAbility)).assertEqual("string"); + expect(typeof (data.backgroundModes)).assertEqual("number"); + expect(typeof (data.isVisible)).assertEqual("boolean"); + expect(typeof (data.formEnabled)).assertEqual("boolean"); + expect(typeof (data.type)).assertEqual("number"); + expect(typeof (data.subType)).assertEqual("number"); + expect(typeof (data.orientation)).assertEqual("number"); + expect(typeof (data.launchMode)).assertEqual("number"); + expect(Array.isArray(data.permissions)).assertEqual(true); + expect(Array.isArray(data.deviceTypes)).assertEqual(true); + expect(Array.isArray(data.deviceCapabilities)).assertEqual(true); + expect(typeof (data.readPermission)).assertEqual("string"); + expect(typeof (data.writePermission)).assertEqual("string"); + expect(typeof (data.applicationInfo)).assertEqual("object"); + expect(typeof (data.formEntity)).assertEqual("number"); + expect(typeof (data.minFormHeight)).assertEqual("number"); + expect(typeof (data.defaultFormHeight)).assertEqual("number"); + expect(typeof (data.minFormWidth)).assertEqual("number"); + expect(typeof (data.defaultFormWidth)).assertEqual("number"); + expect(typeof (data.uri)).assertEqual("string"); + expect(data.bundleName).assertEqual("com.ohos.acecollaboration"); + expect(data.name).assertEqual("com.example.myapplication1.MainAbility"); + expect(data.label).assertEqual("$string:myapplication1_MainAbility"); + expect(data.description).assertEqual("$string:description_mainability"); + expect(data.icon).assertEqual("$media:icon"); + expect(data.descriptionId > 0).assertTrue(); + expect(data.iconId > 0).assertTrue(); + expect(data.moduleName).assertEqual("myapplication1"); + expect(data.process).assertEqual(""); + expect(data.targetAbility).assertEqual(""); + expect(data.backgroundModes).assertEqual(0); + expect(data.isVisible).assertEqual(true); + expect(data.formEnabled).assertEqual(false); + expect(data.type).assertEqual(1); + expect(data.orientation).assertEqual(0); + expect(data.launchMode).assertEqual(1); + expect(data.deviceTypes[0]).assertEqual("phone"); + expect(data.readPermission).assertEqual(""); + expect(data.writePermission).assertEqual(""); + checkApplicationInfo(msg,data.applicationInfo); + expect(data.formEntity).assertEqual(0); + expect(data.minFormHeight).assertEqual(0); + expect(data.defaultFormHeight).assertEqual(0); + expect(data.minFormWidth).assertEqual(0); + expect(data.defaultFormWidth).assertEqual(0); + expect(data.uri).assertEqual(""); + expect(data.labelId > 0).assertTrue(); + expect(data.subType).assertEqual(0); + console.log(msg+ "---checkAbilityInfo End--- "); + } + + function checkApplicationInfo(msg,info) { + console.log(msg+ "checkApplicationInfo start : " + JSON.stringify(info)); + console.log(msg+ "checkApplicationInfo name : " + info.name); + console.log(msg+ "checkApplicationInfo description : " + info.description); + console.log(msg+ "checkApplicationInfo descriptionId : " + info.descriptionId); + console.log(msg+ "checkApplicationInfo systemApp : " + info.systemApp); + console.log(msg+ "checkApplicationInfo enabled : " + info.enabled); + console.log(msg+ "checkApplicationInfo label : " + info.label); + console.log(msg+ "checkApplicationInfo labelId : " + info.labelId); + console.log(msg+ "checkApplicationInfo icon : " + info.icon); + console.log(msg+ "checkApplicationInfo iconId : " + info.iconId); + console.log(msg+ "checkApplicationInfo process : " + info.process); + console.log(msg+ "checkApplicationInfo supportedModes : " + info.supportedModes); + console.log(msg+ "checkApplicationInfo moduleSourceDirs length : " + info.moduleSourceDirs.length); + for (var j = 0; j < info.moduleSourceDirs.length; j++) { + console.log(msg+ "checkApplicationInfo info.moduleSourceDirs[" + j + "] : " + info.moduleSourceDirs[j]); + } + console.log(msg+ "checkApplicationInfo permissions length : " + info.permissions.length); + for (var k = 0; k < info.permissions.length; k++) { + console.log(msg+ "checkApplicationInfo info.permissions[" + k + "] : " + info.permissions[k]); + } + console.log(msg+ "checkApplicationInfo moduleInfos length : " + info.moduleInfos.length); + for (var i = 0; i < info.moduleInfos.length; i++) { + console.log(msg+ "checkApplicationInfo info.moduleInfos[" + i + "].moduleName : " + info.moduleInfos[i].moduleName); + console.log(msg+ "checkApplicationInfo info.moduleInfos[" + i + "].moduleSourceDir : " + info.moduleInfos[i].moduleSourceDir); + } + console.log(msg+ "checkApplicationInfo entryDir : " + info.entryDir); + expect(typeof (info)).assertEqual("object"); + expect(typeof (info.name)).assertEqual("string"); + expect(typeof (info.description)).assertEqual("string"); + expect(typeof (info.descriptionId)).assertEqual("number"); + expect(typeof (info.systemApp)).assertEqual("boolean"); + expect(typeof (info.enabled)).assertEqual("boolean"); + expect(typeof (info.label)).assertEqual("string"); + expect(typeof (info.labelId)).assertEqual("string"); + expect(typeof (info.icon)).assertEqual("string"); + expect(typeof (info.iconId)).assertEqual("string"); + expect(typeof (info.process)).assertEqual("string"); + expect(typeof (info.supportedModes)).assertEqual("number"); + expect(Array.isArray(info.moduleSourceDirs)).assertEqual(true); + expect(Array.isArray(info.permissions)).assertEqual(true); + expect(Array.isArray(info.moduleInfos)).assertEqual(true); + expect(typeof (info.entryDir)).assertEqual("string"); + expect(info.name).assertEqual("com.ohos.acecollaboration"); + expect(info.description).assertEqual("$string:mainability_description"); + expect(info.descriptionId > 0).assertTrue(); + expect(info.systemApp).assertEqual(true); + expect(info.enabled).assertEqual(true); + expect(info.label).assertEqual("$string:entry_MainAbility"); + expect(info.icon).assertEqual("$media:icon"); + expect(info.process).assertEqual(""); + expect(info.supportedModes).assertEqual(0); + if (info.moduleSourceDirs.length == 1){ + expect(info.moduleInfos[0].moduleName).assertEqual("entry"); + expect(info.moduleInfos[0].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.ohos.acecollaboration"); + }else if(info.moduleSourceDirs.length == 2) { + if (info.moduleInfos[0].moduleName == "myapplication1") { + expect(info.moduleInfos[0].moduleName).assertEqual("myapplication1"); + expect(info.moduleInfos[0].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.example.myapplication1"); + expect(info.moduleInfos[1].moduleName).assertEqual("entry"); + expect(info.moduleInfos[1].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.ohos.acecollaboration"); + }else{ + expect(info.moduleInfos[0].moduleName).assertEqual("myapplication2"); + expect(info.moduleInfos[0].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.example.myapplication2"); + expect(info.moduleInfos[1].moduleName).assertEqual("entry"); + expect(info.moduleInfos[1].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.ohos.acecollaboration"); + } + }else { + expect(info.moduleInfos[0].moduleName).assertEqual("myapplication1"); + expect(info.moduleInfos[0].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.example.myapplication1"); + expect(info.moduleInfos[1].moduleName).assertEqual("myapplication2"); + expect(info.moduleInfos[1].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.example.myapplication2"); + expect(info.moduleInfos[2].moduleName).assertEqual("entry"); + expect(info.moduleInfos[2].moduleSourceDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.ohos.acecollaboration"); + } + expect(info.entryDir).assertEqual("/data/app/el1/bundle/public/" + + "com.ohos.acecollaboration/com.ohos.acecollaboration"); + console.log(msg+ "---checkApplicationInfo End--- "); + } + + }) +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/resources/base/element/string.json b/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..c69dada1a3f8a111a6cfdb7743f45b8449bee1b2 --- /dev/null +++ b/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "myapplication1_MainAbility", + "value": "myapplication1_MainAbility" + }, + { + "name": "description_mainability", + "value": "eTS_Empty Ability" + } + ] +} \ No newline at end of file diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/resources/base/media/icon.png b/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/aafwk/aafwk_standard/actsabilitymanageretstest/myapplication1/src/main/resources/base/media/icon.png differ diff --git a/aafwk/aafwk_standard/actsabilitymanageretstest/signature/openharmony_sx.p7b b/aafwk/aafwk_standard/actsabilitymanageretstest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..9be1e98fa4c0c28ca997ed660112fa16b194f0f5 Binary files /dev/null and b/aafwk/aafwk_standard/actsabilitymanageretstest/signature/openharmony_sx.p7b differ diff --git a/appexecfwk/bundle_standard/bundlemanager/BUILD.gn b/appexecfwk/bundle_standard/bundlemanager/BUILD.gn index bdf77ff3285e7d4faf1f04ba1db4e9b57c215325..4ca6e4b6d6c9bef3378a584eacf897e1c3acde8d 100644 --- a/appexecfwk/bundle_standard/bundlemanager/BUILD.gn +++ b/appexecfwk/bundle_standard/bundlemanager/BUILD.gn @@ -9,7 +9,7 @@ # 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. +# limitations under the License. import("//test/xts/tools/build/suite.gni") @@ -25,6 +25,7 @@ group("bundlemanager") { "actsbmskittest:ActsBmsKitTest", "actsbmsmetadatatest:ActsBmsMetaDataTest", "actsbmsmoduleusagerecordtest:ActsBmsModuleUsageRecordTest", + "actsbundlemanageretstest:ActsBundleManagerEtsTest", "actsbundlemanagertest:ActsBundleManagerTest", "actsbundlemanageruninstall:ActsBundleManagerUninstallTest", "actsbundlemgrmultipleinstalltest:ActsBundleMgrMultipleInstallTest", diff --git a/appexecfwk/bundle_standard/bundlemanager/actsbmsjsunpermissiontest/entry/src/main/js/test/ActsBmsJsUnPermissionTest.test.js b/appexecfwk/bundle_standard/bundlemanager/actsbmsjsunpermissiontest/entry/src/main/js/test/ActsBmsJsUnPermissionTest.test.js index d3f886bfe158fdd0f954e64df17fa8b7a78257cd..39053503e73c1e871b79a3bd3a59afca5a72bd5b 100644 --- a/appexecfwk/bundle_standard/bundlemanager/actsbmsjsunpermissiontest/entry/src/main/js/test/ActsBmsJsUnPermissionTest.test.js +++ b/appexecfwk/bundle_standard/bundlemanager/actsbmsjsunpermissiontest/entry/src/main/js/test/ActsBmsJsUnPermissionTest.test.js @@ -15,7 +15,7 @@ import bundle from '@ohos.bundle' import innerBundleManager from '@ohos.bundle.innerBundleManager' -import { describe, it, expect } from 'deccjsunit/index' +import {describe, it, expect} from 'deccjsunit/index' const STATUS_INSTALL_PERMISSION_DENIED = 0X44; const STATUS_UNINSTALL_PERMISSION_DENIED = 0X45; @@ -47,7 +47,7 @@ describe('ActsBmsJsUnPermissionTest', function () { expect(data.status).assertEqual(STATUS_INSTALL_PERMISSION_DENIED); expect(data.statusMessage).assertEqual("STATUS_INSTALL_PERMISSION_DENIED"); done(); - }; + } }); /* @@ -69,7 +69,7 @@ describe('ActsBmsJsUnPermissionTest', function () { expect(data.status).assertEqual(STATUS_UNINSTALL_PERMISSION_DENIED); expect(data.statusMessage).assertEqual("STATUS_UNINSTALL_PERMISSION_DENIED"); done(); - }; + } }); /* @@ -144,8 +144,8 @@ describe('ActsBmsJsUnPermissionTest', function () { it('queryAbilityByWantTest_100', 0, async function (done) { console.debug('queryAbilityByWantTest_100 start'); bundle.queryAbilityByWant({ - bundleName : LAUNCHER_BUNDLE_NAME, - abilityName : LAUNCHER_MAIN_ABILITY + bundleName: LAUNCHER_BUNDLE_NAME, + abilityName: LAUNCHER_MAIN_ABILITY }, DEFAULT_FLAG, DEFAULT_USER_ID).then(data => { expect().assertFail(); done(); @@ -211,8 +211,8 @@ describe('ActsBmsJsUnPermissionTest', function () { it('setAbilityEnabledTest_100', 0, async function (done) { console.debug('setAbilityEnabledTest_100 start'); let abilityInfo = { - bundleName : LAUNCHER_BUNDLE_NAME, - name : LAUNCHER_MAIN_ABILITY + bundleName: LAUNCHER_BUNDLE_NAME, + name: LAUNCHER_MAIN_ABILITY }; bundle.setAbilityEnabled(abilityInfo, false).then(data => { expect().assertFail(); @@ -270,4 +270,40 @@ describe('ActsBmsJsUnPermissionTest', function () { done(); }); }); + + /* + * @tc.number: getAbilityLabelTest_100 + * @tc.name: getAbilityLabel : Gets the specified ability label + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it('getAbilityLabelTest_100', 0, async function (done) { + console.debug('[getAbilityLabelTest_100] promise START'); + await bundle.getAbilityLabel(LAUNCHER_BUNDLE_NAME, LAUNCHER_MAIN_ABILITY) + .then((data) => { + expect().assertFail(); + done(); + }) + .catch((error) => { + expect(error).assertEqual(INVALID_CODE); + done(); + }); + }); + + /* + * @tc.number: getAbilityInfo_100 + * @tc.name: test getAbilityInfo + * @tc.desc: test getAbilityInfo + */ + it('getAbilityInfo_100', 0, async function (done) { + console.debug('getAbilityInfo_100 start'); + bundle.getAbilityInfo(LAUNCHER_BUNDLE_NAME, LAUNCHER_MAIN_ABILITY).then(data => { + expect().assertFail(); + done(); + }).catch(err => { + expect(err).assertEqual(INVALID_CODE); + done(); + }); + }) + }) diff --git a/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/BUILD.gn b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..3c80521fd4aee6befa2e06d783ea6a440778f420 --- /dev/null +++ b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/BUILD.gn @@ -0,0 +1,32 @@ +# Copyright (c) 2021 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("ActsBundleManagerEtsTest") { + hap_profile = "./entry/src/main/config.json" + deps = [ + ":hjs_demo_ets_assets", + ":hjs_demo_ets_resources", + ] + ets2abc = true + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsBundleManagerEtsTest" +} +ohos_js_assets("hjs_demo_ets_assets") { + source_dir = "./entry/src/main/ets/MainAbility" +} +ohos_resources("hjs_demo_ets_resources") { + sources = [ "./entry/src/main/resources" ] + hap_profile = "./entry/src/main/config.json" +} diff --git a/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/Test.json b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..c916382f6a76a6f0191eff83bbc70ee6ed88f308 --- /dev/null +++ b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for actsbundleetsgetinfotest Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "600000", + "package": "com.open.harmony.packagemag", + "shell-timeout": "60000" + }, + "kits": [ + { + "test-file-name": [ + "ActsBundleManagerEtsTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/config.json b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..87603be2bc8c1c3e7f9918c6d2e8a83c7a502b17 --- /dev/null +++ b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/config.json @@ -0,0 +1,85 @@ +{ + "app": { + "bundleName": "com.open.harmony.packagemag", + "vendor": "ohos", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.open.harmony.packagemag", + "name": ".MyApplication", + "mainAbility": "com.open.harmony.packagemag.MainAbility", + "deviceType": [ + "phone" + ], + "reqPermissions": [ + { + "name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" + }, + { + "name": "ohos.permission.GET_BUNDLE_INFO" + }, + { + "name": "ohos.permission.CHANGE_ABILITY_ENABLED_STATE" + } + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "visible": true, + "srcPath": "MainAbility", + "name": ".MainAbility", + "srcLanguage": "ets", + "icon": "$media:icon", + "description": "$string:mainability_description", + "formsEnabled": false, + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard" + }, + { + "srcPath": "ServiceAbility", + "name": ".ServiceAbility", + "icon": "$media:icon", + "srcLanguage": "ets", + "description": "$string:description_serviceability", + "type": "service" + } + ], + "js": [ + { + "mode": { + "syntax": "ets", + "type": "pageAbility" + }, + "pages": [ + "pages/index", + "pages/second" + ], + "name": ".MainAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/app.ets b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/app.ets new file mode 100644 index 0000000000000000000000000000000000000000..6a47e22427b28a7af740c97ab4467f0872c41496 --- /dev/null +++ b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/app.ets @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2021 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 default { + onCreate() { + console.info('Application onCreate') + }, + onDestroy() { + console.info('Application onDestroy') + }, +} \ No newline at end of file diff --git a/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/pages/index.ets b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..e98a1ac989e8e7ca55ae68c551b07e252000e064 --- /dev/null +++ b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/pages/index.ets @@ -0,0 +1,83 @@ +/** + * Copyright (c) 2021 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 router from '@system.router'; +import file from '@system.file'; +import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index.ets"; +import testsuite from "../test/List.test.ets"; +import featureAbility from "@ohos.ability.featureAbility"; + +async function routePage() { + let options = { + uri: 'pages/second' + } + try { + await router.push(options) + } catch (err) { + console.error(`fail callback, code: ${err.code}, msg: ${err.msg}`) + } +} + +@Entry +@Component +struct Index { + + aboutToAppear() { + console.info("start run testcase!!!!") + featureAbility.getWant() + .then((Want) => { + const core = Core.getInstance(); + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }); + core.addService('expect', expectExtend); + const reportExtend = new ReportExtend(file); + core.addService('report', reportExtend); + core.init(); + core.subscribeEvent('task', reportExtend); + const configService = core.getDefaultService('config'); + console.info('parameters---->' + JSON.stringify(Want.parameters)); + configService.setConfig(Want.parameters); + testsuite(); + core.execute(); + console.info('Operation successful. Data: ' + JSON.stringify(Want)); + }) + .catch((error) => { + console.error('Operation failed. Cause: ' + JSON.stringify(error)); + }) + } + + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World') + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('ACE ETS TEST 包管理 2 ') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + routePage() + }) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/pages/second.ets b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/pages/second.ets new file mode 100644 index 0000000000000000000000000000000000000000..9002655f12f0ace700bf00ab324320cdd262bfa6 --- /dev/null +++ b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/pages/second.ets @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2021 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 router from '@system.router'; + +@Entry +@Component +struct Second { + private content: string = "Second Page" + + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text(`${this.content}`) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('back to index') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + router.back() + }) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/GetAbilityLabelJsUnit.test.ets b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/GetAbilityLabelJsUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b6e10c72ef77eeb03dd9325cf3bac456ff49e79b --- /dev/null +++ b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/GetAbilityLabelJsUnit.test.ets @@ -0,0 +1,248 @@ +/** + * Copyright (c) 2021 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index.ets'; +import Utils from './Utils'; +import Bundle from '@ohos.bundle'; + +const BUNDLE_NAME = 'com.open.harmony.packagemag' +const ABILITY_NAME = 'com.open.harmony.packagemag.MainAbility' +const SERVICE_ABILITY_NAME = 'com.open.harmony.packagemag.ServiceAbility' + +const OTHER_BUNDLE_NAME = 'com.ohos.acepackage' +const OTHER_ABILITY_NAME = 'com.ohos.acepackage.MainAbility' + +const BUNDLE_NAME_ERROR = 'com.ohos.acepackage.error' +const ABILITY_NAME_ERROR = 'com.ohos.acepackage.error.MainAbility' + +export default function getAbilityLabelJsUnit() { + + describe('context_getAbilityLabel_test', function () { + beforeEach(async function (done) { + console.info('context_getAbilityLabel_test before each called'); + done() + }); + + afterEach(async function () { + await Utils.sleep(2000); + console.info('context_getAbilityLabel_test after each called'); + }); + + /* + * @tc.number: context_getAbilityLabel_test_0100 + * @tc.name: getAbilityLabel : Gets the specified ability label + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it('context_getAbilityLabel_test_0100', 0, async function (done) { + console.info('[context_getAbilityLabel_test_0100] promise START'); + await Utils.sleep(1000); + let mData; + var timeOldStamp = await Utils.getNowTime(); + await Bundle.getAbilityLabel(BUNDLE_NAME, ABILITY_NAME) + .then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_getAbilityLabel_test_0100]', timeOldStamp, timeNewStamp); + mData = data; + console.info('[context_getAbilityLabel_test_0100] promise in '); + console.info('[context_getAbilityLabel_test_0100] promise data is: ' + JSON.stringify(data)); + }) + .catch((error) => { + console.info('[context_getAbilityLabel_test_0100] promise error is: ' + error); + }); + getAbilityLabelSuccess('[context_getAbilityLabel_test_0100]', mData); + done(); + }); + + /* + * @tc.number: context_getAbilityLabel_test_0200 + * @tc.name: getAbilityLabel : Gets the specified ability label + * @tc.desc: Check the return value of the interface (by callbac) + * @tc.level 0 + */ + it('context_getAbilityLabel_test_0200', 0, async function (done) { + console.info('[context_getAbilityLabel_test_0200] callBack START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + let mData; + Bundle.getAbilityLabel(BUNDLE_NAME, ABILITY_NAME, (error, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_getAbilityLabel_test_0200]', timeOldStamp, timeNewStamp); + mData = data; + console.info('[context_getAbilityLabel_test_0200] callBack in'); + console.info('[context_getAbilityLabel_test_0200] callBack error: ' + error); + console.info('[context_getAbilityLabel_test_0200] callBack data is:' + JSON.stringify(data)); + }); + await Utils.sleep(2000); + getAbilityLabelSuccess('[context_getAbilityLabel_test_0200]', mData); + done(); + }); + + /* + * @tc.number: context_getAbilityLabel_test_0300 + * @tc.name: getAbilityLabel : Gets the specified ability label + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it('context_getAbilityLabel_test_0300', 0, async function (done) { + console.info('[context_getAbilityLabel_test_0300] promise START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + let mError; + await Bundle.getAbilityLabel(BUNDLE_NAME_ERROR, ABILITY_NAME_ERROR) + .then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_getAbilityLabel_test_0300]', timeOldStamp, timeNewStamp); + + console.info('[context_getAbilityLabel_test_0300] promise in '); + console.info('[context_getAbilityLabel_test_0300] promise data is: ' + JSON.stringify(data)); + }) + .catch((error) => { + var timeNewStamp = Utils.getNowTime(); + mError = error; + Utils.getDurationTime('[context_getAbilityLabel_test_0300]', timeOldStamp, timeNewStamp); + console.info('[context_getAbilityLabel_test_0300] promise error is: ' + error); + }); + await Utils.sleep(2000); + getAbilityLabelFailure('[context_getAbilityLabel_test_0300]', mError); + done(); + }); + + /* + * @tc.number: context_getAbilityLabel_test_0400 + * @tc.name: getAbilityLabel : Gets the specified ability label + * @tc.desc: Check the return value of the interface (by callback) + * @tc.level 0 + */ + it('context_getAbilityLabel_test_0400', 0, async function (done) { + console.info('[context_getAbilityLabel_test_0400] callBack START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + let mError; + Bundle.getAbilityLabel(BUNDLE_NAME_ERROR, ABILITY_NAME_ERROR, (error, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_getAbilityLabel_test_0400]', timeOldStamp, timeNewStamp); + mError = error; + console.info('[context_getAbilityLabel_test_0400] callBack in'); + console.info('[context_getAbilityLabel_test_0400] callBack error: ' + error); + console.info('[context_getAbilityLabel_test_0400] callBack data is:' + JSON.stringify(data)); + + }); + await Utils.sleep(2000); + getAbilityLabelFailure('[context_getAbilityLabel_test_0400]', mError); + done(); + }); + + /* + * @tc.number: context_getAbilityLabel_test_0500 + * @tc.name: getAbilityLabel : Gets the specified ability label + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it('context_getAbilityLabel_test_0500', 0, async function (done) { + console.info('[context_getAbilityLabel_test_0500] promise START'); + await Utils.sleep(1000); + let mData; + let mError = null; + var timeOldStamp = await Utils.getNowTime(); + await Bundle.getAbilityLabel(OTHER_BUNDLE_NAME, OTHER_ABILITY_NAME) + .then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_getAbilityLabel_test_0500]', timeOldStamp, timeNewStamp); + mData = data; + console.info('[context_getAbilityLabel_test_0500] promise in '); + console.info('[context_getAbilityLabel_test_0500] promise data is: ' + JSON.stringify(data)); + }) + .catch((error) => { + mError = error; + console.info('[context_getAbilityLabel_test_0500] promise error is: ' + error); + }); + if (mError != null) { + getAbilityLabelFailure('[context_getAbilityLabel_test_0500]', mError); + } else { + getAbilityLabelSuccess('[context_getAbilityLabel_test_0500]', mData); + } + done(); + }); + + /* + * @tc.number: context_getAbilityLabel_test_0600 + * @tc.name: getAbilityLabel : Gets the specified ability label + * @tc.desc: Check the return value of the interface (by callbac) + * @tc.level 0 + */ + it('context_getAbilityLabel_test_0600', 0, async function (done) { + console.info('[context_getAbilityLabel_test_0600] callBack START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + let mData; + let mError = null; + Bundle.getAbilityLabel(OTHER_BUNDLE_NAME, OTHER_ABILITY_NAME, (error, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_getAbilityLabel_test_0600]', timeOldStamp, timeNewStamp); + mData = data; + mError = error; + console.info('[context_getAbilityLabel_test_0600] callBack in'); + console.info('[context_getAbilityLabel_test_0600] callBack error: ' + error); + console.info('[context_getAbilityLabel_test_0600] callBack data is:' + JSON.stringify(data)); + }); + await Utils.sleep(2000); + if (mError != null) { + getAbilityLabelFailure('[context_getAbilityLabel_test_0600]', mError); + } else { + getAbilityLabelSuccess('[context_getAbilityLabel_test_0600]', mData); + } + done(); + }); + + + /* + * @tc.number: context_getAbilityLabel_test_0700 + * @tc.name: getAbilityLabel : Gets the specified ability label + * @tc.desc: Check the return value of the interface (by callbac) + * @tc.level 0 + */ + it('context_getAbilityLabel_test_0700', 0, async function (done) { + console.info('[context_getAbilityLabel_test_0700] callBack START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + let mError; + Bundle.getAbilityLabel(BUNDLE_NAME, SERVICE_ABILITY_NAME, (error, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_getAbilityLabel_test_0700]', timeOldStamp, timeNewStamp); + mError = error; + console.info('[context_getAbilityLabel_test_0700] callBack in'); + console.info('[context_getAbilityLabel_test_0700] callBack error: ' + error); + console.info('[context_getAbilityLabel_test_0700] callBack data is:' + JSON.stringify(data)); + }); + await Utils.sleep(2000); + getAbilityLabelFailure('[context_getAbilityLabel_test_0700]', mError); + done(); + }); + + function getAbilityLabelSuccess(msg, data) { + console.log(msg + ' start ' + JSON.stringify(data)); + console.log(msg + ' result ' + data); + expect(typeof (data)).assertEqual('string'); + } + + function getAbilityLabelFailure(msg, error) { + console.log(msg + ' Failure '); + console.log(msg + ' error ' + JSON.stringify(error)); + expect(typeof (error)).assertEqual('number'); + } + + }) + +} \ No newline at end of file diff --git a/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/GetBundleGidsJsUnit.test.ets b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/GetBundleGidsJsUnit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..012a6540985127047bc45a335d49918d0c49f3a7 --- /dev/null +++ b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/GetBundleGidsJsUnit.test.ets @@ -0,0 +1,211 @@ +/** + * Copyright (c) 2021 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index.ets'; +import Utils from './Utils'; +import Bundle from '@ohos.bundle'; + +const BUNDLE_NAME = 'com.open.harmony.packagemag' +const OTHER_BUNDLE_NAME = 'com.ohos.acepackage' +const BUNDLE_NAME_ERROR = 'com.ohos.acepackage.error' + +export default function bundleGidsJsUnit() { + describe('context_getBundleGids_test', function () { + beforeEach(async function (done) { + console.info('context_getBundleGids_test before each called'); + done() + }); + + afterEach(async function () { + await Utils.sleep(2000); + console.info('context_getBundleGids_test after each called'); + }); + + /* + * @tc.number: context_getBundleGids_test_0100 + * @tc.name: getBundleGids : Gets the lists of bundle with gids + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it('context_getBundleGids_test_0100', 0, async function (done) { + console.info('[context_getBundleGids_test_0100] promise START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + let mData; + await Bundle.getBundleGids(BUNDLE_NAME) + .then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_getBundleGids_test_0100]', timeOldStamp, timeNewStamp); + mData = data; + console.info('[context_getBundleGids_test_0100] promise data is: ' + JSON.stringify(data)); + }) + .catch((error) => { + console.info('[context_getBundleGids_test_0100] promise error is: ' + error); + }); + getGidsSuccess('[context_getBundleGids_test_0100]', mData); + done(); + }); + + /* + * @tc.number: context_getBundleGids_test_0200 + * @tc.name: getBundleGids : Gets the lists of bundle with gids + * @tc.desc: Check the return value of the interface (by callback) + * @tc.level 0 + */ + it('context_getBundleGids_test_0200', 0, async function (done) { + console.info('[context_getBundleGids_test_0200] callBack START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + let mData; + Bundle.getBundleGids(BUNDLE_NAME, (error, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_getBundleGids_test_0200]', timeOldStamp, timeNewStamp); + mData = data; + console.info('[context_getBundleGids_test_0200] callBack in'); + console.info('[context_getBundleGids_test_0200] callBack error: ' + error); + console.info('[context_getBundleGids_test_0200] callBack data is:' + JSON.stringify(data)); + }); + await Utils.sleep(2000); + getGidsSuccess('[context_getBundleGids_test_0200]', mData); + done(); + }); + + /* + * @tc.number: context_getBundleGids_test_0300 + * @tc.name: getBundleGids : Gets the lists of bundle with gids + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it('context_getBundleGids_test_0300', 0, async function (done) { + console.info('[context_getBundleGids_test_0300] promise START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + let mError; + await Bundle.getBundleGids(BUNDLE_NAME_ERROR) + .then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_getBundleGids_test_0300]', timeOldStamp, timeNewStamp); + console.info('[context_getBundleGids_test_0300] promise data is: ' + JSON.stringify(data)); + }) + .catch((error) => { + var timeNewStamp = Utils.getNowTime(); + mError = error; + Utils.getDurationTime('[context_getBundleGids_test_0300]', timeOldStamp, timeNewStamp); + console.info('[context_getBundleGids_test_0300] promise error is: ' + error); + }); + getGidsFailure('[context_getBundleGids_test_0300]', mError); + done(); + }); + + /* + * @tc.number: context_getBundleGids_test_0400 + * @tc.name: getBundleGids : Gets the lists of bundle with gids + * @tc.desc: Check the return value of the interface (by callback) + * @tc.level 0 + */ + it('context_getBundleGids_test_0400', 0, async function (done) { + console.info('[context_getBundleGids_test_0400] callBack START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + let mError; + Bundle.getBundleGids(BUNDLE_NAME_ERROR, (error, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_getBundleGids_test_0400]', timeOldStamp, timeNewStamp); + + mError = error; + console.info('[context_getBundleGids_test_0400] callBack in'); + console.info('[context_getBundleGids_test_0400] callBack error: ' + error); + console.info('[context_getBundleGids_test_0400] callBack data is:' + JSON.stringify(data)); + }); + await Utils.sleep(2000); + getGidsFailure('[context_getBundleGids_test_0400]', mError); + done(); + }); + + /* + * @tc.number: context_getBundleGids_test_0500 + * @tc.name: getBundleGids : Gets the lists of bundle with gids + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it('context_getBundleGids_test_0500', 0, async function (done) { + console.info('[context_getBundleGids_test_0500] promise START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + let mData; + let mError; + await Bundle.getBundleGids(OTHER_BUNDLE_NAME) + .then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_getBundleGids_test_0500]', timeOldStamp, timeNewStamp); + mData = data; + console.info('[context_getBundleGids_test_0500] promise data is: ' + JSON.stringify(data)); + }) + .catch((error) => { + mError = error; + console.info('[context_getBundleGids_test_0500] promise error is: ' + error); + }); + if (mError != null) { + getGidsFailure('[context_getBundleGids_test_0500]', mError); + } else { + getGidsSuccess('[context_getBundleGids_test_0500]', mData); + } + done(); + }); + + /* + * @tc.number: context_getBundleGids_test_0600 + * @tc.name: getBundleGids : Gets the lists of bundle with gids + * @tc.desc: Check the return value of the interface (by callback) + * @tc.level 0 + */ + it('context_getBundleGids_test_0600', 0, async function (done) { + console.info('[context_getBundleGids_test_0600] callBack START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + let mData; + let mError = null; + Bundle.getBundleGids(OTHER_BUNDLE_NAME, (error, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_getBundleGids_test_0600]', timeOldStamp, timeNewStamp); + mData = data; + mError = error; + console.info('[context_getBundleGids_test_0600] callBack in'); + console.info('[context_getBundleGids_test_0600] callBack error: ' + error); + console.info('[context_getBundleGids_test_0600] callBack data is:' + JSON.stringify(data)); + }); + await Utils.sleep(2000); + if (mError != null) { + getGidsFailure('[context_getBundleGids_test_0600]', mError); + } else { + getGidsSuccess('[context_getBundleGids_test_0600]', mData); + } + done(); + }); + + function getGidsSuccess(msg, data) { + console.log(msg + ' start ' + JSON.stringify(data)); + for (var j = 0; j < data.length; j++) { + console.log(msg + 'data[' + j + '] : ' + data[j]); + expect((data[j] > 0)).assertEqual(true); + } + expect(Array.isArray(data)).assertEqual(true); + } + + function getGidsFailure(msg, error) { + console.log(msg + ' Failure '); + expect(typeof (error)).assertEqual('number'); + } + }) +} \ No newline at end of file diff --git a/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/GetabilityInfo.test.ets b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/GetabilityInfo.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..9a4f4351cc752ae3265159d931d06eb39c503bf1 --- /dev/null +++ b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/GetabilityInfo.test.ets @@ -0,0 +1,470 @@ +/** + * Copyright (c) 2021 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 {describe, beforeEach, afterEach, it, expect} from 'deccjsunit/index.ets'; +import Utils from './Utils'; +import bundleManager from '@ohos.bundle'; + +export default function GetabilityInfo() { + describe('GetabilityInfo', function () { + let bundleName = "com.open.harmony.packagemag"; + let abilityName = "com.open.harmony.packagemag.MainAbility"; + let bundleName_other = "com.ohos.acecollaboration"; + let abilityName_other = "com.ohos.acecollaboration.MainAbility"; + let bundleName1 = "com.harmony.packagemag"; + let abilityName1 = "com.harmony.packagemag1.MainAbility"; + + beforeEach(async function (done) { + console.info('GetabilityInfo before each called'); + done() + }); + + afterEach(async function () { + await Utils.sleep(2000); + console.info('GetabilityInfo after each called'); + }); + + /* + * @tc.number: bundle_getAllApplicationInfo_test_0100 + * @tc.name: getAbilityInfo : The basic ability is enhanced to obtain the specified Ability information + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it('bundle_GetabilityInfo_test_0100', 0, async function (done) { + console.info('[bundle_GetabilityInfo_test_0100] START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + bundleManager.getAbilityInfo(bundleName, abilityName) + .then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('bundle_GetabilityInfo_test_0100', timeOldStamp, timeNewStamp) + console.info('[bundle_GetabilityInfo_test_0100] getApplicationInfo in '); + console.info('[bundle_GetabilityInfo_test_0100] getApplicationInfo promise data is: ' + JSON.stringify(data)); + expect(typeof (data)).assertEqual("object"); + }).catch((error) => { + console.error('[bundle_GetabilityInfo_test_0100]Operation failed. Cause: ' + JSON.stringify(error)); + }) + var promise = await bundleManager.getAbilityInfo(bundleName, abilityName); + checkAbilityInfo(promise); + done(); + }); + + /* + * @tc.number: bundle_getAbilityInfo_test_0200 + * @tc.name: getAbilityInfo : The basic ability is enhanced to obtain the specified Ability information + * @tc.desc: Check the return value of the interface (by callback) + * @tc.level 0 + */ + it('bundle_GetabilityInfo_test_0200', 0, async function (done) { + console.info('[bundle_GetabilityInfo_test_0200] START'); + await Utils.sleep(1000); + let mData; + var timeOldStamp = await Utils.getNowTime(); + await bundleManager.getAbilityInfo(bundleName, abilityName, (err, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('bundle_GetabilityInfo_test_0200', timeOldStamp, timeNewStamp) + if (err) { + console.error('[bundle_GetabilityInfo_test_0200]Operation failed. Cause: ' + JSON.stringify(err)); + } + console.info('[bundle_GetabilityInfo_test_0200] getApplicationInfo callback data is: ' + JSON.stringify(data)); + mData = data; + }) + await Utils.sleep(2000); + checkAbilityInfo(mData); + done(); + }); + + /* + * @tc.number: bundle_getAllApplicationInfo_test_0300 + * @tc.name: getAbilityInfo : The basic ability is enhanced to obtain the specified Ability information + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it('bundle_GetabilityInfo_test_0300', 0, async function (done) { + console.info('[bundle_GetabilityInfo_test_0300] START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + let err = null + var mData + await bundleManager.getAbilityInfo(bundleName_other, abilityName_other) + .then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('bundle_GetabilityInfo_test_0300',timeOldStamp,timeNewStamp) + mData = data + console.info('[bundle_GetabilityInfo_test_0300] getApplicationInfo in '); + console.info('[bundle_GetabilityInfo_test_0300] getApplicationInfo promise data is: ' + JSON.stringify(data)); + expect(mData).assertEqual(false); + }).catch((error) => { + err = error + console.error('[bundle_GetabilityInfo_test_0300]Operation failed. Cause: ' + JSON.stringify(error)); + }); + if(err != null) { + await expect(err).assertEqual(1); + }else{ + checkAbilityInfo_other(mData); + } + done(); + }); + + + /* + * @tc.number: bundle_getAllApplicationInfo_test_0400 + * @tc.name: getAbilityInfo : The basic ability is enhanced to obtain the specified Ability information + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it('bundle_GetabilityInfo_test_0400', 0, async function (done) { + console.info('[bundle_GetabilityInfo_test_0400] START'); + let error1; + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + bundleManager.getAbilityInfo(bundleName1, abilityName) + .then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('bundle_GetabilityInfo_test_0400', timeOldStamp, timeNewStamp) + console.info('[bundle_GetabilityInfo_test_0400] getApplicationInfo in '); + console.info('[bundle_GetabilityInfo_test_0400] getApplicationInfo data is: ' + JSON.stringify(data)); + expect(typeof (data)).assertEqual("object"); + }).catch((error) => { + console.error('[bundle_GetabilityInfo_test_0400]Operation failed. Cause: ' + JSON.stringify(error)); + error1 = error; + }) + await Utils.sleep(1000); + await expect(error1).assertEqual(1); + done(); + }); + + /* + * @tc.number: bundle_getAllApplicationInfo_test_0500 + * @tc.name: getAbilityInfo : The basic ability is enhanced to obtain the specified Ability information + * @tc.desc: Check the return value of the interface (by callback) + * @tc.level 0 + */ + it('bundle_GetabilityInfo_test_0500', 0, async function (done) { + console.info('[bundle_GetabilityInfo_test_0500] START'); + let error + await bundleManager.getAbilityInfo(bundleName, abilityName1).then((data) => { + console.info('[bundle_GetabilityInfo_test_0500] START' + JSON.stringify(data)); + }).catch((err) => { + console.info('[bundle_GetabilityInfo_test_0500] err = ' + JSON.stringify(err)); + error = err + }) + expect(error).assertEqual(1); + done(); + console.info('[bundle_GetabilityInfo_test_0500] END'); + }); + + /* + * @tc.number: bundle_getAllApplicationInfo_test_0600 + * @tc.name: getAbilityInfo : The basic ability is enhanced to obtain the specified Ability information + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + let bundleName2 = ""; + it('bundle_GetabilityInfo_test_0600', 0, async function (done) { + console.info('[bundle_GetabilityInfo_test_0600] START'); + let error1; + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + bundleManager.getAbilityInfo(bundleName2, abilityName) + .then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('bundle_GetabilityInfo_test_0600', timeOldStamp, timeNewStamp) + console.info('[bundle_GetabilityInfo_test_0600] getApplicationInfo in '); + console.info('[bundle_GetabilityInfo_test_0600] getApplicationInfo data promise is: ' + JSON.stringify(data)); + expect(typeof (data)).assertEqual("object"); + }).catch((error) => { + console.error('[bundle_GetabilityInfo_test_0600]Operation failed. Cause: ' + JSON.stringify(error)); + error1 = error; + }) + await Utils.sleep(1000); + await expect(error1).assertEqual(1); + done(); + }); + + + /** + * 打印AbilityInfo属性信息 + * @param data + */ + function checkAbilityInfo(data) { + console.log("checkAbilityInfo start " + JSON.stringify(data)); + console.log("checkAbilityInfo bundleName : " + data.bundleName); + console.log("checkAbilityInfo name : " + data.name); + console.log("checkAbilityInfo label : " + data.label); + console.log("checkAbilityInfo description : " + data.description); + console.log("checkAbilityInfo icon : " + data.icon); + console.log("checkAbilityInfo descriptionId : " + data.descriptionId); + console.log("checkAbilityInfo iconId : " + data.iconId); + console.log("checkAbilityInfo moduleName : " + data.moduleName); + console.log("checkAbilityInfo process : " + data.process); + console.log("checkAbilityInfo targetAbility : " + data.targetAbility); + console.log("checkAbilityInfo backgroundModes : " + data.backgroundModes); + console.log("checkAbilityInfo isVisible : " + data.isVisible); + console.log("checkAbilityInfo formEnabled : " + data.formEnabled); + console.log("checkAbilityInfo type : " + data.type) + console.log("checkAbilityInfo orientation : " + data.orientation); + console.log("checkAbilityInfo launchMode : " + data.launchMode); + console.log("checkAbilityInfo permissions length : " + data.permissions.length); + for (var j = 0; j < data.permissions.length; j++) { + console.log("getAbilityInfo data.permissions[" + j + "] : " + data.permissions[j]); + } + console.log("checkAbilityInfo deviceTypes length : " + data.deviceTypes.length); + for (var k = 0; k < data.deviceTypes.length; k++) { + console.log("getAbilityInfo data.deviceTypes[" + k + "] : " + data.deviceTypes[k]); + } + console.log("checkAbilityInfo deviceCapabilities length : " + data.deviceCapabilities.length); + for (var i = 0; i < data.deviceCapabilities.length; i++) { + console.log("getAbilityInfo data.deviceCapabilities[" + i + "] : " + data.deviceCapabilities[i]); + } + console.log("checkAbilityInfo readPermission : " + data.readPermission); + console.log("checkAbilityInfo writePermission : " + data.writePermission); + console.log("checkAbilityInfo defaultFormWidth : " + data.defaultFormWidth); + console.log("checkAbilityInfo uri : " + data.uri); + console.log("checkAbilityInfo labelId : " + data.labelId); + console.log("checkAbilityInfo subType : " + data.subType); + expect(typeof (data.bundleName)).assertEqual("string"); + expect(typeof (data.name)).assertEqual("string"); + expect(data.label).assertEqual("$string:entry_MainAbility"); + expect(typeof (data.label)).assertEqual("string"); + expect(data.description).assertEqual("$string:mainability_description"); + expect(typeof (data.description)).assertEqual("string"); + expect(data.icon).assertEqual("$media:icon"); + expect(typeof (data.icon)).assertEqual("string"); + expect(typeof (data.srcPath)).assertEqual("string"); + expect(data.srcLanguage).assertEqual("ets"); + expect(typeof (data.srcLanguage)).assertEqual("string"); + expect(data.isVisible).assertEqual(true); + expect(Array.isArray(data.permissions)).assertEqual(true); + expect(Array.isArray(data.deviceCapabilities)).assertEqual(true); + expect(data.deviceTypes[0]).assertEqual("phone"); + expect(typeof (data.process)).assertEqual("string"); + expect(typeof (data.uri)).assertEqual("string"); + expect(data.uri).assertEqual(""); + expect(typeof (data.uri)).assertEqual("string"); + expect(data.moduleName).assertEqual("entry"); + expect(typeof (data.moduleName)).assertEqual("string"); + expect(typeof (data.applicationInfo)).assertEqual("object"); + expect(data.bundleName).assertEqual("com.open.harmony.packagemag") + expect(data.name).assertEqual("com.open.harmony.packagemag.MainAbility"); + checkApplicationInfo(data.applicationInfo); + console.log("---checkAbilityInfo End--- "); + } + + /** + * 打印ApplicationInfo属性信息 + * @param data + */ + function checkApplicationInfo(info) { + console.log("checkApplicationInfo getApplicationInfo : " + JSON.stringify(info)); + console.log("checkApplicationInfo name : " + info.name); + console.log("checkApplicationInfo description : " + info.description); + console.log("checkApplicationInfo descriptionId : " + info.descriptionId); + console.log("checkApplicationInfo systemApp : " + info.systemApp); + console.log("checkApplicationInfo enabled : " + info.enabled); + console.log("checkApplicationInfo label : " + info.label); + console.log("checkApplicationInfo labelId : " + info.labelId); + console.log("checkApplicationInfo icon : " + info.icon); + console.log("checkApplicationInfo process : " + info.process); + console.log("checkApplicationInfo supportedModes : " + info.supportedModes); + console.log("checkApplicationInfo moduleSourceDirs length : " + info.moduleSourceDirs.length); + for (var j = 0; j < info.moduleSourceDirs.length; j++) { + console.log("checkApplicationInfo info.moduleSourceDirs[" + j + "] : " + info.moduleSourceDirs[j]); + } + console.log("checkApplicationInfo permissions length : " + info.permissions.length); + for (var j = 0; j < info.permissions.length; j++) { + console.log("checkApplicationInfo info.permissions[" + j + "] : " + info.permissions[j]); + } + console.log("checkApplicationInfo moduleInfos length : " + info.moduleInfos.length); + for (var j = 0; j < info.moduleInfos.length; j++) { + console.log("checkApplicationInfo info.moduleInfos[" + j + "].moduleName : " + info.moduleInfos[j].moduleName); + console.log("checkApplicationInfo info.moduleInfos[" + j + "].moduleSourceDir : " + info.moduleInfos[j].moduleSourceDir); + } + console.log("checkApplicationInfo entryDir : " + info.entryDir); + expect(typeof (info)).assertEqual("object") + expect(typeof (info.name)).assertEqual("string") + expect(typeof (info.codePath)).assertEqual("string") + expect(info.accessTokenId > 0).assertTrue() + expect(typeof (info.accessTokenId)).assertEqual("number") + expect(typeof (info.description)).assertEqual("string") + expect(info.description).assertEqual("$string:mainability_description") + expect(info.descriptionId > 0).assertTrue() + expect(typeof (info.descriptionId)).assertEqual("number") + expect(typeof (info.icon)).assertEqual("string") + expect(info.icon).assertEqual("$media:icon") + expect(info.iconId > 0).assertTrue() + expect(typeof (info.iconId)).assertEqual("number") + expect(typeof (info.label)).assertEqual("string") + expect(info.label).assertEqual("$string:entry_MainAbility") + expect(info.labelId > 0).assertTrue() + expect(typeof (info.labelId)).assertEqual("number") + expect(info.systemApp).assertEqual(true) + expect(typeof (info.entryDir)).assertEqual("string") + expect(info.supportedModes).assertEqual(0) + expect(typeof (info.supportedModes)).assertEqual("number") + expect(typeof (info.process)).assertEqual("string") + expect(info.process).assertEqual("") + expect(Array.isArray(info.moduleSourceDirs)).assertEqual(true); + expect(info.entryDir) + .assertEqual("/data/app/el1/bundle/public/com.open.harmony.packagemag/com.open.harmony.packagemag"); + expect(Array.isArray(info.permissions)).assertEqual(true); + expect(info.codePath).assertEqual("/data/app/el1/bundle/public/com.open.harmony.packagemag"); + expect(info.moduleSourceDirs[0]) + .assertEqual("/data/app/el1/bundle/public/com.open.harmony.packagemag/com.open.harmony.packagemag"); + expect(info.enabled).assertEqual(true); + expect(info.flags).assertEqual(0); + expect(info.uid > 0).assertTrue() + expect(info.entityType).assertEqual("unspecified"); + expect(info.removable).assertEqual(true); + expect(info.accessTokenId > 0).assertTrue() + } + + /** + * 打印ApplicationInfo属性信息 + * @param data + */ + function checkAbilityInfo_other(data) { + console.log("checkAbilityInfo start " + JSON.stringify(data)); + console.log("checkAbilityInfo bundleName : " + data.bundleName); + console.log("checkAbilityInfo name : " + data.name); + console.log("checkAbilityInfo label : " + data.label); + console.log("checkAbilityInfo description : " + data.description); + console.log("checkAbilityInfo icon : " + data.icon); + console.log("checkAbilityInfo descriptionId : " + data.descriptionId); + console.log("checkAbilityInfo iconId : " + data.iconId); + console.log("checkAbilityInfo moduleName : " + data.moduleName); + console.log("checkAbilityInfo process : " + data.process); + console.log("checkAbilityInfo targetAbility : " + data.targetAbility); + console.log("checkAbilityInfo backgroundModes : " + data.backgroundModes); + console.log("checkAbilityInfo isVisible : " + data.isVisible); + console.log("checkAbilityInfo formEnabled : " + data.formEnabled); + console.log("checkAbilityInfo type : " + data.type) + console.log("checkAbilityInfo orientation : " + data.orientation); + console.log("checkAbilityInfo launchMode : " + data.launchMode); + console.log("checkAbilityInfo permissions length : " + data.permissions.length); + for (var j = 0; j < data.permissions.length; j++) { + console.log("getAbilityInfo data.permissions[" + j + "] : " + data.permissions[j]); + } + console.log("checkAbilityInfo deviceTypes length : " + data.deviceTypes.length); + for (var k = 0; k < data.deviceTypes.length; k++) { + console.log("getAbilityInfo data.deviceTypes[" + k + "] : " + data.deviceTypes[k]); + } + console.log("checkAbilityInfo deviceCapabilities length : " + data.deviceCapabilities.length); + for (var i = 0; i < data.deviceCapabilities.length; i++) { + console.log("getAbilityInfo data.deviceCapabilities[" + i + "] : " + data.deviceCapabilities[i]); + } + console.log("checkAbilityInfo readPermission : " + data.readPermission); + console.log("checkAbilityInfo writePermission : " + data.writePermission); + console.log("checkAbilityInfo defaultFormWidth : " + data.defaultFormWidth); + console.log("checkAbilityInfo uri : " + data.uri); + console.log("checkAbilityInfo labelId : " + data.labelId); + console.log("checkAbilityInfo subType : " + data.subType); + expect(typeof (data.bundleName)).assertEqual("string"); + expect(typeof (data.name)).assertEqual("string"); + expect(data.label).assertEqual("$string:entry_MainAbility"); + expect(typeof (data.label)).assertEqual("string"); + expect(data.description).assertEqual("$string:mainability_description"); + expect(typeof (data.description)).assertEqual("string"); + expect(data.icon).assertEqual("$media:icon"); + expect(typeof (data.icon)).assertEqual("string"); + expect(typeof (data.srcPath)).assertEqual("string"); + expect(data.srcLanguage).assertEqual("ets"); + expect(typeof (data.srcLanguage)).assertEqual("string"); + expect(data.isVisible).assertEqual(true); + expect(Array.isArray(data.permissions)).assertEqual(true); + expect(Array.isArray(data.deviceCapabilities)).assertEqual(true); + expect(data.deviceTypes[0]).assertEqual("phone"); + expect(typeof (data.process)).assertEqual("string"); + expect(typeof (data.uri)).assertEqual("string"); + expect(data.uri).assertEqual(""); + expect(typeof (data.uri)).assertEqual("string"); + expect(data.moduleName).assertEqual("entry"); + expect(typeof (data.moduleName)).assertEqual("string"); + expect(typeof (data.applicationInfo)).assertEqual("object"); + expect(data.bundleName).assertEqual("com.ohos.acecollaboration"); + expect(data.name).assertEqual("com.ohos.acecollaboration.MainAbility"); + checkApplicationInfo_other(data.applicationInfo); + console.log("---checkAbilityInfo End--- "); + } + + /** + * 打印ApplicationInfo属性信息 + * @param data + */ + function checkApplicationInfo_other(info) { + console.log("checkApplicationInfo getApplicationInfo : " + JSON.stringify(info)); + console.log("checkApplicationInfo name : " + info.name); + console.log("checkApplicationInfo description : " + info.description); + console.log("checkApplicationInfo descriptionId : " + info.descriptionId); + console.log("checkApplicationInfo systemApp : " + info.systemApp); + console.log("checkApplicationInfo enabled : " + info.enabled); + console.log("checkApplicationInfo label : " + info.label); + console.log("checkApplicationInfo labelId : " + info.labelId); + console.log("checkApplicationInfo icon : " + info.icon); + console.log("checkApplicationInfo process : " + info.process); + console.log("checkApplicationInfo supportedModes : " + info.supportedModes); + console.log("checkApplicationInfo moduleSourceDirs length : " + info.moduleSourceDirs.length); + for (var j = 0; j < info.moduleSourceDirs.length; j++) { + console.log("checkApplicationInfo info.moduleSourceDirs[" + j + "] : " + info.moduleSourceDirs[j]); + } + console.log("checkApplicationInfo permissions length : " + info.permissions.length); + for (var j = 0; j < info.permissions.length; j++) { + console.log("checkApplicationInfo info.permissions[" + j + "] : " + info.permissions[j]); + } + console.log("checkApplicationInfo moduleInfos length : " + info.moduleInfos.length); + for (var j = 0; j < info.moduleInfos.length; j++) { + console.log("checkApplicationInfo info.moduleInfos[" + j + "].moduleName : " + info.moduleInfos[j].moduleName); + console.log("checkApplicationInfo info.moduleInfos[" + j + "].moduleSourceDir : " + info.moduleInfos[j].moduleSourceDir); + } + console.log("checkApplicationInfo entryDir : " + info.entryDir); + expect(typeof (info)).assertEqual("object") + expect(typeof (info.name)).assertEqual("string") + expect(typeof (info.codePath)).assertEqual("string") + expect(info.accessTokenId > 0).assertTrue() + expect(typeof (info.accessTokenId)).assertEqual("number") + expect(typeof (info.description)).assertEqual("string") + expect(info.description).assertEqual("$string:mainability_description") + expect(info.descriptionId > 0).assertTrue() + expect(typeof (info.descriptionId)).assertEqual("number") + expect(typeof (info.icon)).assertEqual("string") + expect(info.icon).assertEqual("$media:icon") + expect(info.iconId > 0).assertTrue() + expect(typeof (info.iconId)).assertEqual("number") + expect(typeof (info.label)).assertEqual("string") + expect(info.label).assertEqual("$string:entry_MainAbility") + expect(info.labelId > 0).assertTrue() + expect(typeof (info.labelId)).assertEqual("number") + expect(info.systemApp).assertEqual(true) + expect(typeof (info.entryDir)).assertEqual("string") + expect(info.supportedModes).assertEqual(0) + expect(typeof (info.supportedModes)).assertEqual("number") + expect(typeof (info.process)).assertEqual("string") + expect(info.process).assertEqual("") + expect(Array.isArray(info.moduleSourceDirs)).assertEqual(true); + expect(info.entryDir) + .assertEqual("/data/app/el1/bundle/public/com.ohos.acecollaboration/com.ohos.acecollaboration"); + expect(Array.isArray(info.permissions)).assertEqual(true); + expect(info.codePath).assertEqual("/data/app/el1/bundle/public/com.ohos.acecollaboration"); + expect(info.moduleSourceDirs[0]) + .assertEqual("/data/app/el1/bundle/public/com.ohos.acecollaboration/com.ohos.acecollaboration"); + expect(info.enabled).assertEqual(true); + expect(info.flags).assertEqual(0); + expect(info.uid > 0).assertTrue() + expect(info.entityType).assertEqual("unspecified"); + expect(info.removable).assertEqual(true); + expect(info.accessTokenId > 0).assertTrue() + } + }); +} \ No newline at end of file diff --git a/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/IsAbilityEnabledETSUnit.ets b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/IsAbilityEnabledETSUnit.ets new file mode 100644 index 0000000000000000000000000000000000000000..5a6a21aa24850d74b21efec62c8598221933e526 --- /dev/null +++ b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/IsAbilityEnabledETSUnit.ets @@ -0,0 +1,313 @@ +/** + * Copyright (c) 2021 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index.ets'; +import Utils from './Utils'; +import Bundle from '@ohos.bundle'; + +const BUNDLE_NAME = 'com.open.harmony.packagemag' +const ABILITY_NAME = 'com.open.harmony.packagemag.MainAbility' + +const ABILITY = { + bundleName: BUNDLE_NAME, + name: ABILITY_NAME +} + +const BUNDLE_NAME_ERROR = 'com.ohos.acepackage.error' +const ABILITY_NAME_ERROR = 'com.ohos.acepackage.error.MainAbility' + +const ABILITY_ERROR = { + bundleName: BUNDLE_NAME_ERROR, + name: ABILITY_NAME_ERROR +} + +export default function isAbilityEnabledETSUnit() { + describe('context_isAbilityEnabled_test', function () { + beforeEach(async function (done) { + console.info('context_isAbilityEnabled_test before each called'); + done() + }); + + afterEach(async function () { + await Utils.sleep(2000); + console.info('context_isAbilityEnabled_test after each called'); + }); + + /* + * @tc.number: context_isAbilityEnabled_test_0100 + * @tc.name: isAbilityEnabled : Get whether to enable a specified ability + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it('context_isAbilityEnabled_test_0100', 0, async function (done) { + console.info('[context_isAbilityEnabled_test_0100] promise START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + let mData; + await Bundle.isAbilityEnabled(ABILITY) + .then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_isAbilityEnabled_test_0100]', timeOldStamp, timeNewStamp); + mData = data; + console.info('[context_isAbilityEnabled_test_0100] promise in '); + console.info('[context_isAbilityEnabled_test_0100] promise data is: ' + JSON.stringify(data)); + }) + .catch((error) => { + console.info('[context_isAbilityEnabled_test_0100] promise error is: ' + error); + }); + getAbilityEnabledSuccess('[context_isAbilityEnabled_test_0100]', mData); + done(); + }); + + /* + * @tc.number: context_isAbilityEnabled_test_0200 + * @tc.name: isAbilityEnabled : Get whether to enable a specified ability + * @tc.desc: Check the return value of the interface (by callback) + * @tc.level 0 + */ + it('context_isAbilityEnabled_test_0200', 0, async function (done) { + console.info('[context_isAbilityEnabled_test_0200] callBack START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + let mData; + Bundle.isAbilityEnabled(ABILITY, (error, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_isAbilityEnabled_test_0200]', timeOldStamp, timeNewStamp); + mData = data; + console.info('[context_isAbilityEnabled_test_0200] callBack in'); + console.info('[context_isAbilityEnabled_test_0200] callBack error: ' + error); + console.info('[context_isAbilityEnabled_test_0200] callBack data is:' + JSON.stringify(data)); + }); + await Utils.sleep(2000); + getAbilityEnabledSuccess('[context_isAbilityEnabled_test_0200]', mData); + done(); + }); + + /* + * @tc.number: context_isAbilityEnabled_test_0300 + * @tc.name: isAbilityEnabled : Get whether to enable a specified ability + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it('context_isAbilityEnabled_test_0300', 0, async function (done) { + console.info('[context_isAbilityEnabled_test_0300] promise START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + let mData; + await Bundle.isAbilityEnabled(ABILITY_ERROR) + .then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_isAbilityEnabled_test_0300]', timeOldStamp, timeNewStamp); + mData = data; + console.info('[context_isAbilityEnabled_test_0300] promise in '); + console.info('[context_isAbilityEnabled_test_0300] promise data is: ' + JSON.stringify(data)); + }) + .catch((error) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_isAbilityEnabled_test_0300]', timeOldStamp, timeNewStamp); + console.info('[context_isAbilityEnabled_test_0300] promise error is: ' + error); + }); + getAbilityEnabledFalse('[context_isAbilityEnabled_test_0300]', mData); + done(); + }); + + /* + * @tc.number: context_isAbilityEnabled_test_0400 + * @tc.name: isAbilityEnabled : Get whether to enable a specified ability + * @tc.desc: Check the return value of the interface (by callback) + * @tc.level 0 + */ + it('context_isAbilityEnabled_test_0400', 0, async function (done) { + console.info('[context_isAbilityEnabled_test_0400] callBack START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + let mData; + console.info('[context_isAbilityEnabled_test_0400] start c++ callBack '); + Bundle.isAbilityEnabled(ABILITY_ERROR, (error, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_isAbilityEnabled_test_0300]', timeOldStamp, timeNewStamp); + console.info('[context_isAbilityEnabled_test_0400] callBack in'); + mData = data; + console.info('[context_isAbilityEnabled_test_0400] callBack error: ' + error); + console.info('[context_isAbilityEnabled_test_0400] callBack data is:' + JSON.stringify(data)); + }); + console.info('[context_isAbilityEnabled_test_0400] end c++ callBack '); + await Utils.sleep(2000); + console.info('[context_isAbilityEnabled_test_0400] Failure '); + getAbilityEnabledFalse('[context_isAbilityEnabled_test_0300]', mData); + done(); + }); + + + /* + * @tc.number: context_isAbilityEnabled_test_0500 + * @tc.name: isAbilityEnabled : Get whether to enable a specified ability + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it('context_isAbilityEnabled_test_0500', 0, async function (done) { + console.info('[context_isAbilityEnabled_test_0500] promise START'); + await Utils.sleep(1000); + + await Bundle.setAbilityEnabled(ABILITY, true) + .then((data) => { + console.info('[context_isAbilityEnabled_test_0500] set enable true '); + console.info('[context_isAbilityEnabled_test_0500] set enable true data is: ' + JSON.stringify(data)); + }).catch((error) => { + console.info('[context_isAbilityEnabled_test_0500] set enable true error is: ' + error); + }) + + var timeOldStamp = await Utils.getNowTime(); + let mData; + await Bundle.isAbilityEnabled(ABILITY) + .then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_isAbilityEnabled_test_0500]', timeOldStamp, timeNewStamp); + mData = data; + console.info('[context_isAbilityEnabled_test_0500] promise in '); + console.info('[context_isAbilityEnabled_test_0500] promise data is: ' + JSON.stringify(data)); + }) + .catch((error) => { + console.info('[context_isAbilityEnabled_test_0500] promise error is: ' + error); + }); + getAbilityEnabledTrue('[context_isAbilityEnabled_test_0500]', mData); + done(); + }); + + /* + * @tc.number: context_isAbilityEnabled_test_0600 + * @tc.name: isAbilityEnabled : Get whether to enable a specified ability + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it('context_isAbilityEnabled_test_0600', 0, async function (done) { + console.info('[context_isAbilityEnabled_test_0600] promise START'); + await Utils.sleep(1000); + + await Bundle.setAbilityEnabled(ABILITY, false) + .then((data) => { + console.info('[context_isAbilityEnabled_test_0600] set enable false '); + console.info('[context_isAbilityEnabled_test_0600] set enable false data is: ' + JSON.stringify(data)); + }).catch((error) => { + console.info('[context_isAbilityEnabled_test_0600] set enable false error is: ' + error); + }) + + var timeOldStamp = await Utils.getNowTime(); + let mData; + await Bundle.isAbilityEnabled(ABILITY) + .then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_isAbilityEnabled_test_0600]', timeOldStamp, timeNewStamp); + mData = data; + console.info('[context_isAbilityEnabled_test_0600] promise in '); + console.info('[context_isAbilityEnabled_test_0600] promise data is: ' + JSON.stringify(data)); + }) + .catch((error) => { + console.info('[context_isAbilityEnabled_test_0600] promise error is: ' + error); + }); + getAbilityEnabledFalse('[context_isAbilityEnabled_test_0600]', mData); + done(); + }); + + /* + * @tc.number: context_isAbilityEnabled_test_0700 + * @tc.name: isAbilityEnabled : Get whether to enable a specified ability + * @tc.desc: Check the return value of the interface (by callback) + * @tc.level 0 + */ + it('context_isAbilityEnabled_test_0700', 0, async function (done) { + console.info('[context_isAbilityEnabled_test_0700] callBack START'); + await Utils.sleep(1000); + + await Bundle.setAbilityEnabled(ABILITY, true) + .then((data) => { + console.info('[context_isAbilityEnabled_test_0700] set enable true '); + console.info('[context_isAbilityEnabled_test_0700] set enable true data is: ' + JSON.stringify(data)); + }).catch((error) => { + console.info('[context_isAbilityEnabled_test_0700] set enable true error is: ' + error); + }) + + var timeOldStamp = await Utils.getNowTime(); + let mData; + Bundle.isAbilityEnabled(ABILITY, (error, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_isAbilityEnabled_test_0700]', timeOldStamp, timeNewStamp); + mData = data; + console.info('[context_isAbilityEnabled_test_0700] callBack in'); + console.info('[context_isAbilityEnabled_test_0700] callBack error: ' + error); + console.info('[context_isAbilityEnabled_test_0700] callBack data is:' + JSON.stringify(data)); + }); + await Utils.sleep(2000); + getAbilityEnabledTrue('[context_isAbilityEnabled_test_0700]', mData); + done(); + }); + + /* + * @tc.number: context_isAbilityEnabled_test_0800 + * @tc.name: isAbilityEnabled : Get whether to enable a specified ability + * @tc.desc: Check the return value of the interface (by callback) + * @tc.level 0 + */ + it('context_isAbilityEnabled_test_0800', 0, async function (done) { + console.info('[context_isAbilityEnabled_test_0800] callBack START'); + await Utils.sleep(1000); + + await Bundle.setAbilityEnabled(ABILITY, false) + .then((data) => { + console.info('[context_isAbilityEnabled_test_0800] set enable false '); + console.info('[context_isAbilityEnabled_test_0800] set enable false data is: ' + JSON.stringify(data)); + }).catch((error) => { + console.info('[context_isAbilityEnabled_test_0800] set enable false error is: ' + error); + }) + + var timeOldStamp = await Utils.getNowTime(); + let mData; + Bundle.isAbilityEnabled(ABILITY, (error, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_isAbilityEnabled_test_0800]', timeOldStamp, timeNewStamp); + mData = data; + console.info('[context_isAbilityEnabled_test_0800] callBack in'); + console.info('[context_isAbilityEnabled_test_0800] callBack error: ' + error); + console.info('[context_isAbilityEnabled_test_0800] callBack data is:' + JSON.stringify(data)); + }); + await Utils.sleep(2000); + getAbilityEnabledFalse('[context_isAbilityEnabled_test_0800]', mData); + done(); + }); + + + function getAbilityEnabledSuccess(msg, data) { + console.log(msg + ' start ' + JSON.stringify(data)); + console.log(msg + ' data : ' + data); + expect(typeof (data)).assertEqual('boolean') + } + + function getAbilityEnabledTrue(msg, data) { + getAbilityEnabledSuccess(msg, data); + expect(data).assertEqual(true); + } + + function getAbilityEnabledFalse(msg, data) { + getAbilityEnabledSuccess(msg, data); + expect(data).assertEqual(false); + } + + function getAbilityEnabledFailure(msg, error) { + console.log(msg + ' Failure '); + console.log(msg + ' error : ' + error); + expect(typeof (error)).assertEqual('number') + } + + }) +} \ No newline at end of file diff --git a/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/IsApplicationEnabledETSUnit.ets b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/IsApplicationEnabledETSUnit.ets new file mode 100644 index 0000000000000000000000000000000000000000..d99b7b821bb0b99381c3dc6e274408932688ee42 --- /dev/null +++ b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/IsApplicationEnabledETSUnit.ets @@ -0,0 +1,221 @@ +/** + * Copyright (c) 2021 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index.ets'; +import Utils from './Utils'; +import Bundle from '@ohos.bundle'; + +const BUNDLE_NAME = 'com.open.harmony.packagemag' + +const BUNDLE_NAME_ERROR = 'com.ohos.acepackage.error' + +export default function IsApplicationEnabledETSUnit() { + describe('context_isApplicationEnabled_test', function () { + beforeEach(async function (done) { + console.info('context_isApplicationEnabled_test before each called'); + done() + }); + + afterEach(async function () { + await Utils.sleep(2000); + console.info('context_isApplicationEnabled_test after each called'); + }); + + /* + * @tc.number: context_isApplicationEnabled_test_0100 + * @tc.name: isApplicationEnabled : Get whether to enable a specified application + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it('context_isApplicationEnabled_test_0100', 0, async function (done) { + console.info('[context_isApplicationEnabled_test_0100] promise START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + let mData; + await Bundle.isApplicationEnabled(BUNDLE_NAME) + .then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_isApplicationEnabled_test_0100]', timeOldStamp, timeNewStamp); + mData = data; + console.info('[context_isApplicationEnabled_test_0100] promise in '); + console.info('[context_isApplicationEnabled_test_0100] promise data is: ' + JSON.stringify(data)); + }) + .catch((error) => { + console.info('[context_isApplicationEnabled_test_0100] promise error is: ' + error); + }); + getApplicationEnabledSuccess('[context_isApplicationEnabled_test_0100]', mData); + done(); + }); + + /* + * @tc.number: context_isApplicationEnabled_test_0200 + * @tc.name: isApplicationEnabled : Get whether to enable a specified application + * @tc.desc: Check the return value of the interface (by callback) + * @tc.level 0 + */ + it('context_isApplicationEnabled_test_0200', 0, async function (done) { + console.info('[context_isApplicationEnabled_test_0200] callBack START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + let mData; + Bundle.isApplicationEnabled(BUNDLE_NAME, (error, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_isApplicationEnabled_test_0200]', timeOldStamp, timeNewStamp); + mData = data; + console.info('[context_isApplicationEnabled_test_0200] callBack in'); + console.info('[context_isApplicationEnabled_test_0200] callBack error: ' + error); + console.info('[context_isApplicationEnabled_test_0200] callBack data is:' + JSON.stringify(data)); + }); + await Utils.sleep(2000); + getApplicationEnabledSuccess('[context_isApplicationEnabled_test_0200]', mData); + done(); + }); + + /* + * @tc.number: context_isApplicationEnabled_test_0300 + * @tc.name: isApplicationEnabled : Get whether to enable a specified application + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it('context_isApplicationEnabled_test_0300', 0, async function (done) { + console.info('[context_isApplicationEnabled_test_0300] promise START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + let mData; + await Bundle.isApplicationEnabled(BUNDLE_NAME_ERROR) + .then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_isApplicationEnabled_test_0300]', timeOldStamp, timeNewStamp); + mData = data; + console.info('[context_isApplicationEnabled_test_0300] promise in '); + console.info('[context_isApplicationEnabled_test_0300] promise data is: ' + JSON.stringify(data)); + }) + .catch((error) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_isApplicationEnabled_test_0300]', timeOldStamp, timeNewStamp); + console.info('[context_isApplicationEnabled_test_0300] promise error is: ' + error); + }); + getApplicationEnabledFalse('[context_isApplicationEnabled_test_0300]', mData); + done(); + }); + + /* + * @tc.number: context_isApplicationEnabled_test_0400 + * @tc.name: isApplicationEnabled : Get whether to enable a specified application + * @tc.desc: Check the return value of the interface (by callback) + * @tc.level 0 + */ + it('context_isApplicationEnabled_test_0400', 0, async function (done) { + console.info('[context_isApplicationEnabled_test_0400] callBack START'); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + let mData; + Bundle.isApplicationEnabled(BUNDLE_NAME_ERROR, (error, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_isApplicationEnabled_test_0400]', timeOldStamp, timeNewStamp); + mData = data; + console.info('[context_isApplicationEnabled_test_0400] callBack in'); + console.info('[context_isApplicationEnabled_test_0400] callBack error: ' + error); + console.info('[context_isApplicationEnabled_test_0400] callBack data is:' + JSON.stringify(data)); + }); + await Utils.sleep(2000); + getApplicationEnabledFalse('[context_isApplicationEnabled_test_0300]', mData); + console.info('[context_isApplicationEnabled_test_0400] Failure '); + done(); + }); + + /* + * @tc.number: context_isApplicationEnabled_test_0500 + * @tc.name: isApplicationEnabled : Get whether to enable a specified application + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it('context_isApplicationEnabled_test_0500', 0, async function (done) { + console.info('[context_isApplicationEnabled_test_0500] promise START'); + + await Bundle.setApplicationEnabled(BUNDLE_NAME, true) + .then((data) => { + console.info('[context_isApplicationEnabled_test_0500] set enable true '); + console.info('[context_isApplicationEnabled_test_0500] set enable true data is: ' + JSON.stringify(data)); + }).catch((error) => { + console.info('[context_isApplicationEnabled_test_0500] set enable true error is: ' + error); + }); + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + let mData; + await Bundle.isApplicationEnabled(BUNDLE_NAME) + .then((data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_isApplicationEnabled_test_0500]', timeOldStamp, timeNewStamp); + mData = data; + console.info('[context_isApplicationEnabled_test_0500] promise in '); + console.info('[context_isApplicationEnabled_test_0500] promise data is: ' + JSON.stringify(data)); + }) + .catch((error) => { + console.info('[context_isApplicationEnabled_test_0500] promise error is: ' + error); + }); + getApplicationEnabledTrue('[context_isApplicationEnabled_test_0500]', mData); + done(); + }); + + /* + * @tc.number: context_isApplicationEnabled_test_0600 + * @tc.name: isApplicationEnabled : Get whether to enable a specified application + * @tc.desc: Check the return value of the interface (by callback) + * @tc.level 0 + */ + it('context_isApplicationEnabled_test_0600', 0, async function (done) { + console.info('[context_isApplicationEnabled_test_0600] callBack START'); + + await Bundle.setApplicationEnabled(BUNDLE_NAME, false) + .then((data) => { + console.info('[context_isApplicationEnabled_test_0600] set enable false '); + console.info('[context_isApplicationEnabled_test_0600] set enable false data is: ' + JSON.stringify(data)); + }).catch((error) => { + console.info('[context_isApplicationEnabled_test_0600] set enable false error is: ' + error); + }); + + await Utils.sleep(1000); + var timeOldStamp = await Utils.getNowTime(); + let mData; + Bundle.isApplicationEnabled(BUNDLE_NAME, (error, data) => { + var timeNewStamp = Utils.getNowTime(); + Utils.getDurationTime('[context_isApplicationEnabled_test_0600]', timeOldStamp, timeNewStamp); + mData = data; + console.info('[context_isApplicationEnabled_test_0600] callBack in'); + console.info('[context_isApplicationEnabled_test_0600] callBack error: ' + error); + console.info('[context_isApplicationEnabled_test_0600] callBack data is:' + JSON.stringify(data)); + }); + await Utils.sleep(2000); + getApplicationEnabledFalse('[context_isApplicationEnabled_test_0600]', mData); + done(); + }); + + function getApplicationEnabledSuccess(msg, data) { + console.log(msg + ' start ' + JSON.stringify(data)); + console.log(msg + ' data : ' + data); + expect(typeof (data)).assertEqual('boolean') + } + + function getApplicationEnabledTrue(msg, data) { + getApplicationEnabledSuccess(msg, data); + expect(data).assertEqual(true); + } + + function getApplicationEnabledFalse(msg, data) { + getApplicationEnabledSuccess(msg, data); + expect(data).assertEqual(false); + } + }) +} \ No newline at end of file diff --git a/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/List.test.ets b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..a962e2f545a3794aabd7f61f090ee348f378d97d --- /dev/null +++ b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/List.test.ets @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2021 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 getabilityInfo from './GetabilityInfo.test.ets'; +import getApplicationInfoJsunit from './getApplicationInfoJsunit.test.ets'; +import getAllAppInfoJsunit from './getAllApplicationInfoJsunit.test.ets'; +import getAbilityLabelJsUnit from "./GetAbilityLabelJsUnit.test.ets"; +import isAbilityEnableETSUnit from "./IsAbilityEnabledETSUnit.ets"; +import isApplicationEnabledETSUnit from "./IsApplicationEnabledETSUnit.ets"; + +export default function testsuite() { + //RM.007 + getApplicationInfoJsunit(); + getAllAppInfoJsunit(); + //RM.006 + getabilityInfo(); + //RM.014 + getAbilityLabelJsUnit(); + //RM.017 + isAbilityEnableETSUnit(); + isApplicationEnabledETSUnit(); +} \ No newline at end of file diff --git a/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/Utils.ets b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/Utils.ets new file mode 100644 index 0000000000000000000000000000000000000000..4d9553a5c660be0a6ae524110f2dd4a6477abfd6 --- /dev/null +++ b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/Utils.ets @@ -0,0 +1,130 @@ +// @ts-nocheck +/** + * Copyright (c) 2021 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 default class Utils { + static rect_left; + static rect_top; + static rect_right; + static rect_bottom; + static rect_value; + + static sleep(time) { + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve() + }, time) + }).then(() => { + console.info(`sleep ${time} over...`) + }) + } + + static getComponentRect(key) { + let strJson = getInspectorByKey(key); + let obj = JSON.parse(strJson); + console.info("[getInspectorByKey] current component obj is: " + JSON.stringify(obj)); + let rectInfo = JSON.parse('[' + obj.$rect + ']') + console.info("[getInspectorByKey] rectInfo is: " + rectInfo); + this.rect_left = JSON.parse('[' + rectInfo[0] + ']')[0] + this.rect_top = JSON.parse('[' + rectInfo[0] + ']')[1] + this.rect_right = JSON.parse('[' + rectInfo[1] + ']')[0] + this.rect_bottom = JSON.parse('[' + rectInfo[1] + ']')[1] + return this.rect_value = { + "left": this.rect_left, "top": this.rect_top, "right": this.rect_right, "bottom": this.rect_bottom + } + } + + static async swipe(downX, downY, upX, upY, steps) { + console.info('start to swipe') + this.drags(downX, downY, upX, upY, steps, false) + } + + static async drag(downX, downY, upX, upY, steps) { + console.info('start to drag') + this.drags(downX, downY, upX, upY, steps, true) + } + + static async drags(downX, downY, upX, upY, steps, drag) { + var xStep; + var yStep; + var swipeSteps; + var ret; + xStep = 0; + yStep = 0; + ret = false; + swipeSteps = steps; + if (swipeSteps == 0) { + swipeSteps = 1; + } + xStep = (upX - downX) / swipeSteps; + yStep = (upY - downY) / swipeSteps; + console.info('move step is: ' + 'xStep: ' + xStep + ' yStep: ' + yStep) + var downPonit: TouchObject = { + id: 1, + x: downX, + y: downY, + type: TouchType.Down, + } + console.info('down touch started: ' + JSON.stringify(downPonit)) + sendTouchEvent(downPonit); + console.info('start to move') + if (drag) { + await this.sleep(500) + } + for (var i = 1;i <= swipeSteps; i++) { + var movePoint: TouchObject = { + id: 1, + x: downX + (xStep * i), + y: downY + (yStep * i), + type: TouchType.Move + } + console.info('move touch started: ' + JSON.stringify(movePoint)) + ret = sendTouchEvent(movePoint) + if (ret == false) { + break; + } + await this.sleep(5) + } + console.info('start to up') + if (drag) { + await this.sleep(100) + } + var upPoint: TouchObject = { + id: 1, + x: upX, + y: upY, + type: TouchType.Up, + } + console.info('up touch started: ' + JSON.stringify(upPoint)) + sendTouchEvent(upPoint) + await this.sleep(500) + } + + static getNowTime() { + return new Date().getTime(); + } + + static getDurationTime(log,startTime, endTime) { + console.info("Get Interface startTime: " + startTime); + console.info("Get Interface endTime: " + endTime); + var duration = (endTime - startTime); + console.info("Get Interface duration: " + duration); + return duration; + } +} + + + + diff --git a/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/getAllApplicationInfoJsunit.test.ets b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/getAllApplicationInfoJsunit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c35fbbc138434cfccc26003a679b291cb5fd66eb --- /dev/null +++ b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/getAllApplicationInfoJsunit.test.ets @@ -0,0 +1,404 @@ +/** + * Copyright (c) 2021 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 {describe, beforeEach, afterEach, it, expect} from 'deccjsunit/index.ets'; +import Utils from './Utils'; +import Bundle from '@ohos.bundle'; + +const TAG_TEST_0100_001 = ' bundle_getAllApplicationInfo_test_0100_001 '; +const TAG_TEST_0100_002 = ' bundle_getAllApplicationInfo_test_0100_002 '; +const TAG_TEST_0100_003 = ' bundle_getAllApplicationInfo_test_0100_003 '; +const TAG_TEST_0200_001 = ' bundle_getAllApplicationInfo_test_0200_004 '; +const TAG_TEST_0200_002 = ' bundle_getAllApplicationInfo_test_0200_005 '; +const TAG_TEST_0200_003 = ' bundle_getAllApplicationInfo_test_0200_006 '; +const TAG_TEST_0300_001 = ' bundle_getAllApplicationInfo_test_0300_007 '; +const TAG_TEST_0400_001 = ' bundle_getAllApplicationInfo_test_0400_008 '; +const TAG_TEST_0500_001 = ' bundle_getAllApplicationInfo_test_0500_009 '; +const TAG_TEST_0500_002 = ' bundle_getAllApplicationInfo_test_0500_0010 '; +const USER_ID_100 = 100; +const SLEEP_TIME_1000 = 1000; +const SLEEP_TIME_2000 = 2000; + +export default function applicationBundleJsunit() { + describe('appInfoTest', function () { + beforeEach(async function (done) { + console.info('applicationBundle before each called'); + done() + }); + + afterEach(async function () { + await Utils.sleep(SLEEP_TIME_2000); + console.info('applicationBundle after each called'); + }); + + /** + * @tc.number: bundle_getApplicationInfo_test_0100_001 + * @tc.name: getApplicationInfo : Obtains based on a given bundle name. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(TAG_TEST_0100_001, 0, async function (done) { + console.info(TAG_TEST_0100_001 + 'promise START'); + await Utils.sleep(SLEEP_TIME_1000); + var startTime = await Utils.getNowTime(); + let data = await Bundle.getAllApplicationInfo(Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, USER_ID_100) + .catch((error) => { + console.info(TAG_TEST_0100_001 + 'UserId promise error is: ' + error); + }); + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0100_001, startTime, endTime); + console.info(TAG_TEST_0100_001 + ' UserId promise data is: ' + JSON.stringify(data)); + commonTest(TAG_TEST_0100_001, data) + getApplicationInfoSuccess(TAG_TEST_0100_001, data); + done(); + console.log('------------------ ' + TAG_TEST_0100_001 + ' end -------------------'); + }); + + /** + * @tc.number: bundle_getApplicationInfo_test_0100_002 + * @tc.name: getApplicationInfo : Obtains based on a given bundle name. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(TAG_TEST_0100_002, 0, async function (done) { + console.info(TAG_TEST_0100_002 + 'promise START'); + await Utils.sleep(SLEEP_TIME_1000); + var startTime = await Utils.getNowTime(); + let data = await Bundle.getAllApplicationInfo(Bundle.BundleFlag.GET_ALL_APPLICATION_INFO, USER_ID_100) + .catch((error) => { + console.info(TAG_TEST_0100_002 + 'UserId promise error is: ' + error); + }); + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0100_002, startTime, endTime); + console.info(TAG_TEST_0100_002 + ' UserId promise data is: ' + JSON.stringify(data)); + commonTest(TAG_TEST_0100_002, data) + getApplicationInfoSuccess(TAG_TEST_0100_002, data); + done(); + console.log('------------------ ' + TAG_TEST_0100_002 + ' end -------------------'); + }); + + /** + * @tc.number: bundle_getApplicationInfo_test_0100_003 + * @tc.name: getApplicationInfo : Obtains based on a given bundle name. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(TAG_TEST_0100_003, 0, async function (done) { + console.info(TAG_TEST_0100_003 + 'promise START'); + await Utils.sleep(SLEEP_TIME_1000); + var startTime = await Utils.getNowTime(); + let data = await Bundle.getAllApplicationInfo(Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_DISABLE, USER_ID_100) + .catch((error) => { + console.info(TAG_TEST_0100_003 + 'UserId promise error is: ' + error); + }); + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0100_003, startTime, endTime); + console.info(TAG_TEST_0100_003 + ' UserId promise data is: ' + JSON.stringify(data)); + commonTest(TAG_TEST_0100_003, data) + getApplicationInfoSuccess(TAG_TEST_0100_003, data); + done(); + console.log('------------------ ' + TAG_TEST_0100_003 + ' end -------------------'); + }); + + + /** + * @tc.number: bundle_getApplicationInfo_test_0200_004 + * @tc.name: getApplicationInfo : Obtains based on a given bundle name. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(TAG_TEST_0200_001, 0, async function (done) { + console.info(TAG_TEST_0200_001 + 'promise START'); + await Utils.sleep(SLEEP_TIME_1000); + var startTime = await Utils.getNowTime(); + let data = await Bundle.getAllApplicationInfo(Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION) + .catch((error) => { + console.info(TAG_TEST_0200_001 + 'onUserId promise error is: ' + error); + }); + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0200_001, startTime, endTime); + console.info(TAG_TEST_0200_001 + ' onUserId promise data is: ' + JSON.stringify(data)); + commonTest(TAG_TEST_0200_001, data) + getApplicationInfoSuccess(TAG_TEST_0200_001, data); + done(); + console.log('------------------ ' + TAG_TEST_0200_001 + ' end -------------------'); + }); + + /** + * @tc.number: bundle_getApplicationInfo_test_0200_005 + * @tc.name: getApplicationInfo : Obtains based on a given bundle name. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(TAG_TEST_0200_002, 0, async function (done) { + console.info(TAG_TEST_0200_002 + 'promise START'); + await Utils.sleep(SLEEP_TIME_1000); + var startTime = await Utils.getNowTime(); + let data = await Bundle.getAllApplicationInfo(Bundle.BundleFlag.GET_ALL_APPLICATION_INFO) + .catch((error) => { + console.info(TAG_TEST_0200_002 + 'onUserId promise error is: ' + error); + }); + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0200_002, startTime, endTime); + console.info(TAG_TEST_0200_002 + ' onUserId promise data is: ' + JSON.stringify(data)); + commonTest(TAG_TEST_0200_002, data) + getApplicationInfoSuccess(TAG_TEST_0200_002, data); + done(); + console.log('------------------ ' + TAG_TEST_0200_002 + ' end -------------------'); + }); + + /** + * @tc.number: bundle_getApplicationInfo_test_0200_006 + * @tc.name: getApplicationInfo : Obtains based on a given bundle name. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(TAG_TEST_0200_003, 0, async function (done) { + console.info(TAG_TEST_0200_003 + 'promise START'); + await Utils.sleep(SLEEP_TIME_1000); + var startTime = await Utils.getNowTime(); + let data = await Bundle.getAllApplicationInfo(Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_DISABLE) + .catch((error) => { + console.info(TAG_TEST_0200_003 + 'onUserId promise error is: ' + error); + }); + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0200_003, startTime, endTime); + console.info(TAG_TEST_0200_003 + ' onUserId promise data is: ' + JSON.stringify(data)); + commonTest(TAG_TEST_0200_003, data) + getApplicationInfoSuccess(TAG_TEST_0200_003, data); + done(); + console.log('------------------ ' + TAG_TEST_0200_003 + ' end -------------------'); + }); + + /** + * @tc.number: bundle_getApplicationInfo_test_0300_007 + * @tc.name: getApplicationInfo : Obtains based on a given bundle name. + * @tc.desc: Check the return value of the interface (by callBack) + * @tc.level 0 + */ + it(TAG_TEST_0300_001, 0, async function (done) { + console.info(TAG_TEST_0300_001 + 'callBack START'); + await Utils.sleep(SLEEP_TIME_1000); + let datas; + var startTime = await Utils.getNowTime(); + Bundle.getAllApplicationInfo(Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, USER_ID_100, + (error, data) => { + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0300_001, startTime, endTime); + console.info(TAG_TEST_0300_001 + 'UserId callBack in'); + console.info(TAG_TEST_0300_001 + 'UserId callBack error: ' + error); + console.info(TAG_TEST_0300_001 + 'UserId callBack data is:' + JSON.stringify(data)); + datas = data; + }); + await Utils.sleep(2000); + console.info(TAG_TEST_0300_001 + 'UserId callBack datas is:' + JSON.stringify(datas)); + commonTest(TAG_TEST_0300_001, datas) + getApplicationInfoSuccess(TAG_TEST_0300_001, datas); + done(); + console.log('------------------ ' + TAG_TEST_0300_001 + ' end -------------------'); + }); + + /** + * @tc.number: bundle_getApplicationInfo_test_0400_008 + * @tc.name: getApplicationInfo : Obtains based on a given bundle name. + * @tc.desc: Check the return value of the interface (by callBack) + * @tc.level 0 + */ + it(TAG_TEST_0400_001, 0, async function (done) { + console.info(TAG_TEST_0400_001 + 'callBack START'); + let datas; + var startTime = await Utils.getNowTime(); + Bundle.getAllApplicationInfo(Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, (error, data) => { + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0400_001, startTime, endTime); + console.info(TAG_TEST_0400_001 + 'noUserId callBack in'); + console.info(TAG_TEST_0400_001 + 'noUserId callBack error: ' + error); + console.info(TAG_TEST_0400_001 + 'noUserId callBack data is:' + JSON.stringify(data)); + datas = data; + }); + await Utils.sleep(2000); + console.info(TAG_TEST_0400_001 + 'noUserId callBack datas is:' + JSON.stringify(datas)); + commonTest(TAG_TEST_0400_001, datas) + getApplicationInfoSuccess(TAG_TEST_0400_001, datas); + done(); + console.log('------------------ ' + TAG_TEST_0400_001 + ' end -------------------'); + }); + + /** + * @tc.number: bundle_getApplicationInfo_test_0500_009 + * @tc.name: getApplicationInfo : Obtains based on a given bundle name. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(TAG_TEST_0500_001, 0, async function (done) { + console.info(TAG_TEST_0500_001 + 'promise START'); + await Utils.sleep(SLEEP_TIME_1000); + let errors; + var startTime = await Utils.getNowTime(); + let data = await Bundle.getAllApplicationInfo('0') + .catch((error) => { + console.info(TAG_TEST_0500_001 + 'noUserId promise error is: ' + error); + errors = error; + }); + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0500_001, startTime, endTime); + console.info(TAG_TEST_0500_001 + ' noUserId promise data is: ' + JSON.stringify(data)); + expect(errors).assertEqual(1); + done(); + console.log('------------------ ' + TAG_TEST_0500_001 + ' end -------------------'); + }); + + /** + * @tc.number: bundle_getApplicationInfo_test_0500_0010 + * @tc.name: getApplicationInfo : Obtains based on a given bundle name. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(TAG_TEST_0500_002, 0, async function (done) { + console.info(TAG_TEST_0500_002 + 'promise START'); + await Utils.sleep(SLEEP_TIME_1000); + let errors; + var startTime = await Utils.getNowTime(); + let data = await Bundle.getAllApplicationInfo('0', USER_ID_100) + .catch((error) => { + console.info(TAG_TEST_0500_002 + 'UserId promise error is: ' + error); + errors = error; + }); + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0500_002, startTime, endTime); + console.info(TAG_TEST_0500_002 + ' UserId promise data is: ' + JSON.stringify(data)); + expect(errors).assertEqual(1); + done(); + console.log('------------------ ' + TAG_TEST_0500_002 + ' end -------------------'); + }); + + /** + * 打印单个属性 + * @param msg log信息 + * @param data 数据源 + */ + function commonTest(msg, data) { + console.info(msg + 'commonTest data length [' + data.length + ']'); + for (var i = 0; i < data.length; i++) { + console.info(msg + i + ' [ + data[i] + ] :' + JSON.stringify(data[i])); + console.info(msg + '[' + i + '].name:' + data[i].name); + console.info(msg + '[' + i + '].codePath:' + data[i].codePath); + console.info(msg + '[' + i + '].accessTokenId:' + data[i].accessTokenId); + console.info(msg + '[' + i + '].description:' + data[i].description); + console.info(msg + '[' + i + '].descriptionId:' + data[i].descriptionId); + console.info(msg + '[' + i + '].icon:' + data[i].icon); + console.info(msg + '[' + i + '].iconId:' + data[i].iconId); + console.info(msg + '[' + i + '].label:' + data[i].label); + console.info(msg + '[' + i + '].labelId:' + data[i].labelId); + console.info(msg + '[' + i + '].systemApp:' + data[i].systemApp); + console.info(msg + '[' + i + '].supportedModes:' + data[i].supportedModes); + console.info(msg + '[' + i + '].process:' + data[i].process); + console.info(msg + '[' + i + '].entryDir:' + data[i].entryDir); + console.info('getAllApplicationInfo Async permissions length [' + data[i].permissions.length + ']'); + for (var j = 0; j < data[i].permissions.length; j++) { + console.info(msg + '[' + i + ']permissions[' + j + ']:' + data[i].permissions[j]); + } + console.info('getAllApplicationInfo Async moduleSourceDirs length [' + data[i].moduleSourceDirs.length + ']'); + for (var l = 0; l < data[i].moduleSourceDirs.length; l++) { + console.info(msg + '[' + i + ']moduleSourceDirs[' + l + ']:' + data[i].moduleSourceDirs[l]); + } + console.info('getAllApplicationInfo Async moduleInfos length [' + data[i].moduleInfos.length + ']'); + for (var k = 0; k < data[i].moduleInfos.length; k++) { + console.info(msg + '[' + i + ']moduleInfos[' + k + ']moduleName:' + data[i].moduleInfos[k].moduleName); + console.info(msg + '[' + i + ']moduleInfos[' + k + ']moduleSourceDir:' + data[i].moduleInfos[k].moduleSourceDir); + } + console.info(msg + '[' + i + '].metaData:' + data[i].metaData); + console.info(msg + '[' + i + '].metadata:' + data[i].metadata); + console.info(msg + '[' + i + '].enabled:' + data[i].enabled); + console.info(msg + '[' + i + '].flags:' + data[i].flags); + console.info(msg + '[' + i + '].uid:' + data[i].uid); + console.info(msg + '[' + i + '].entityType:' + data[i].entityType); + console.info(msg + '[' + i + '].removable:' + data[i].removable); + } + expectData(msg, data); + } + + /** + * expect属性 + * @param msg log信息 + * @param data 数据源 + */ + function expectData(msg, data) { + console.info(msg + 'commonTest data length [' + data.length + ']'); + for (var i = 0; i < data.length; i++) { + expect(typeof (data)).assertEqual('object'); + expect(typeof (data[i].name)).assertEqual('string'); + expect(typeof (data[i].codePath)).assertEqual('string'); + expect(typeof (data[i].accessTokenId)).assertEqual('number'); + expect(typeof (data[i].description)).assertEqual('string'); + expect(typeof (data[i].descriptionId)).assertEqual('number'); + expect(typeof (data[i].icon)).assertEqual('string'); + expect(typeof (data[i].iconId)).assertEqual('number'); + expect(typeof (data[i].label)).assertEqual('string'); + expect(typeof (data[i].labelId)).assertEqual('number'); + expect(typeof (data[i].systemApp)).assertEqual('boolean') + expect(typeof (data[i].supportedModes)).assertEqual('number'); + expect(typeof (data[i].entryDir)).assertEqual('string'); + expect(typeof (data[i].metaData)).assertEqual('object'); + expect(typeof (data[i].metadata)).assertEqual('object'); + expect(typeof (data[i].enabled)).assertEqual('boolean'); + expect(typeof (data[i].flags)).assertEqual('number'); + expect(typeof (data[i].uid)).assertEqual('number'); + expect(typeof (data[i].entityType)).assertEqual('string'); + expect(typeof (data[i].removable)).assertEqual('boolean'); + expect(Array.isArray(data[i].permissions)).assertEqual(true); + expect(Array.isArray(data[i].moduleSourceDirs)).assertEqual(true); + expect(Array.isArray(data[i].moduleInfos)).assertEqual(true); + } + } + + /** + * expect指定数据属性值 + * @param msg log信息 + * @param data 数据源 + */ + function getApplicationInfoSuccess(msg, data) { + console.info(msg + 'getApplicationInfoSuccess data length [' + data.length + ']'); + for (var i = 0; i < data.length; i++) { + if (data[i].name === 'com.open.harmony.packagemag' || i === 0 && data[i].name === '') { + console.info(msg + JSON.stringify(data[i])); + expect(data[i].name).assertEqual('com.open.harmony.packagemag'); + expect(data[i].codePath).assertEqual('/data/app/el1/bundle/public/com.open.harmony.packagemag'); + expect(data[i].description).assertEqual('$string:mainability_description'); + if (data[i].descriptionId !== 0) { + expect(data[i].descriptionId > 0).assertEqual(true); + } + expect(data[i].icon).assertEqual('$media:icon'); + expect(data[i].iconId > 0).assertEqual(true); + expect(data[i].label).assertEqual('$string:entry_MainAbility'); + if (data[i].label !== 0) { + expect(data[i].labelId > 0).assertEqual(true); + } + expect(data[i].systemApp).assertEqual(true); + expect(data[i].supportedModes).assertEqual(0); + expect(data[i].entryDir).assertEqual('/data/app/el1/bundle/public/com.open.harmony.packagemag' + + '/com.open.harmony.packagemag'); + expect(data[i].enabled).assertEqual(true); + expect(data[i].entityType).assertEqual('unspecified'); + expect(data[i].removable).assertEqual(true); + expect(data[i].moduleInfos[0].moduleName).assertEqual('entry'); + expect(data[i].moduleInfos[0].moduleSourceDir).assertEqual('/data/app/el1/bundle/public/' + + 'com.open.harmony.packagemag/com.open.harmony.packagemag'); + expect(data[i].moduleSourceDirs[0]).assertEqual('/data/app/el1/bundle/public/' + + 'com.open.harmony.packagemag/com.open.harmony.packagemag'); + } + } + } + }); +} \ No newline at end of file diff --git a/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/getApplicationInfoJsunit.test.ets b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/getApplicationInfoJsunit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7d3193b932deafda6e44cddcf0bf5de6836d87eb --- /dev/null +++ b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/MainAbility/test/getApplicationInfoJsunit.test.ets @@ -0,0 +1,595 @@ +/** + * Copyright (c) 2021 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 {describe, beforeEach, afterEach, it, expect} from 'deccjsunit/index.ets'; +import Utils from './Utils'; +import Bundle from '@ohos.bundle'; + +const TAG_TEST_0100_001 = ' bundle_getApplicationInfo_test_0100_001 '; +const TAG_TEST_0100_002 = ' bundle_getApplicationInfo_test_0100_002 '; +const TAG_TEST_0100_003 = ' bundle_getApplicationInfo_test_0100_003 '; +const TAG_TEST_0200_001 = ' bundle_getApplicationInfo_test_0200_004 '; +const TAG_TEST_0200_002 = ' bundle_getApplicationInfo_test_0200_005 '; +const TAG_TEST_0200_003 = ' bundle_getApplicationInfo_test_0200_006 '; +const TAG_TEST_0300_001 = ' bundle_getApplicationInfo_test_0300_007 '; +const TAG_TEST_0400_001 = ' bundle_getApplicationInfo_test_0400_008 '; +const TAG_TEST_0500_001 = ' bundle_getApplicationInfo_test_0500_009 '; +const TAG_TEST_0500_002 = ' bundle_getApplicationInfo_test_0500_0010 '; +const TAG_TEST_0600_001 = ' bundle_getApplicationInfo_test_0600_0011 '; +const TAG_TEST_0600_002 = ' bundle_getApplicationInfo_test_0600_0012 '; +const TAG_TEST_0600_003 = ' bundle_getApplicationInfo_test_0600_0013 '; +const BUNDLE_NAME = 'com.open.harmony.packagemag'; +const BUNDLE_NAME_OTHER = 'com.ohos.acepackage'; +const USER_ID_100 = 100; +const SLEEP_TIME_1000 = 1000; +const SLEEP_TIME_2000 = 2000; + +export default function applicationBundleJsunit() { + describe('appInfoTest', function () { + beforeEach(async function (done) { + console.info('applicationBundle before each called'); + done() + }); + + afterEach(async function () { + await Utils.sleep(SLEEP_TIME_2000); + console.info('applicationBundle after each called'); + }); + + /** + * @tc.number: bundle_getApplicationInfo_test_0100_001 + * @tc.name: getApplicationInfo : Obtains based on a given bundle name. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(TAG_TEST_0100_001, 0, async function (done) { + console.info(TAG_TEST_0100_001 + 'promise START'); + await Utils.sleep(SLEEP_TIME_1000); + let errors; + var startTime = await Utils.getNowTime(); + let data = await Bundle.getApplicationInfo(BUNDLE_NAME, Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, + USER_ID_100) + .catch((error) => { + console.info(TAG_TEST_0100_001 + 'UserId promise error is: ' + error); + errors = error; + }); + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0100_001, startTime, endTime); + console.info(TAG_TEST_0100_001 + ' UserId promise data is: ' + JSON.stringify(data)); + if (1 === errors) { + expect(errors).assertEqual(1); + } else { + commonTest(TAG_TEST_0100_001, data); + getApplicationInfoSuccess(TAG_TEST_0100_001, data); + } + done(); + console.log('------------------ ' + TAG_TEST_0100_001 + ' end -------------------'); + }); + + /** + * @tc.number: bundle_getApplicationInfo_test_0100_002 + * @tc.name: getApplicationInfo : Obtains based on a given bundle name. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(TAG_TEST_0100_002, 0, async function (done) { + console.info(TAG_TEST_0100_002 + 'promise START'); + await Utils.sleep(SLEEP_TIME_1000); + let errors; + var startTime = await Utils.getNowTime(); + let data = await Bundle.getApplicationInfo(BUNDLE_NAME, Bundle.BundleFlag.GET_ALL_APPLICATION_INFO, USER_ID_100) + .catch((error) => { + console.info(TAG_TEST_0100_002 + 'UserId promise error is: ' + error); + errors = error; + }); + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0100_002, startTime, endTime); + console.info(TAG_TEST_0100_002 + ' UserId promise data is: ' + JSON.stringify(data)); + if (1 === errors) { + expect(errors).assertEqual(1); + } else { + commonTest(TAG_TEST_0100_002, data); + getApplicationInfoSuccess(TAG_TEST_0100_002, data); + } + done(); + console.log('------------------ ' + TAG_TEST_0100_002 + ' end -------------------'); + }); + + /** + * @tc.number: bundle_getApplicationInfo_test_0100_003 + * @tc.name: getApplicationInfo : Obtains based on a given bundle name. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(TAG_TEST_0100_003, 0, async function (done) { + console.info(TAG_TEST_0100_003 + 'promise START'); + await Utils.sleep(SLEEP_TIME_1000); + let errors; + var startTime = await Utils.getNowTime(); + let data = await Bundle.getApplicationInfo(BUNDLE_NAME, Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_DISABLE, + USER_ID_100) + .catch((error) => { + console.info(TAG_TEST_0100_003 + 'UserId promise error is: ' + error); + errors = error; + }); + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0100_003, startTime, endTime); + console.info(TAG_TEST_0100_003 + ' UserId promise data is: ' + JSON.stringify(data)); + if (1 === errors) { + expect(errors).assertEqual(1); + } else { + commonTest(TAG_TEST_0100_003, data); + if ('' === data.name) { + getApplicationInfoFial(TAG_TEST_0100_003, data); + } else { + getApplicationInfoSuccess(TAG_TEST_0100_003, data); + } + } + done(); + console.log('------------------ ' + TAG_TEST_0100_003 + ' end -------------------'); + }); + + + /** + * @tc.number: bundle_getApplicationInfo_test_0200_004 + * @tc.name: getApplicationInfo : Obtains based on a given bundle name. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(TAG_TEST_0200_001, 0, async function (done) { + console.info(TAG_TEST_0200_001 + 'promise START'); + let errors; + await Utils.sleep(SLEEP_TIME_1000); + var startTime = await Utils.getNowTime(); + let data = await Bundle.getApplicationInfo(BUNDLE_NAME, Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION) + .catch((error) => { + console.info(TAG_TEST_0200_001 + 'onUserId promise error is: ' + error); + errors = error; + }); + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0200_001, startTime, endTime); + console.info(TAG_TEST_0200_001 + ' onUserId promise data is: ' + JSON.stringify(data)); + if (1 === errors) { + expect(errors).assertEqual(1); + } else { + commonTest(TAG_TEST_0200_001, data); + getApplicationInfoSuccess(TAG_TEST_0200_001, data); + } + done(); + console.log('------------------ ' + TAG_TEST_0200_001 + ' end -------------------'); + }); + + /** + * @tc.number: bundle_getApplicationInfo_test_0200_005 + * @tc.name: getApplicationInfo : Obtains based on a given bundle name. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(TAG_TEST_0200_002, 0, async function (done) { + console.info(TAG_TEST_0200_002 + 'promise START'); + await Utils.sleep(SLEEP_TIME_1000); + let errors; + var startTime = await Utils.getNowTime(); + let data = await Bundle.getApplicationInfo(BUNDLE_NAME, Bundle.BundleFlag.GET_ALL_APPLICATION_INFO) + .catch((error) => { + console.info(TAG_TEST_0200_002 + 'onUserId promise error is: ' + error); + errors = error; + }); + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0200_002, startTime, endTime); + console.info(TAG_TEST_0200_002 + ' onUserId promise data is: ' + JSON.stringify(data)); + if (1 === errors) { + expect(errors).assertEqual(1); + } else { + commonTest(TAG_TEST_0200_002, data); + getApplicationInfoSuccess(TAG_TEST_0200_002, data); + } + done(); + console.log('------------------ ' + TAG_TEST_0200_002 + ' end -------------------'); + }); + + /** + * @tc.number: bundle_getApplicationInfo_test_0200_006 + * @tc.name: getApplicationInfo : Obtains based on a given bundle name. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(TAG_TEST_0200_003, 0, async function (done) { + console.info(TAG_TEST_0200_003 + 'promise START'); + await Utils.sleep(SLEEP_TIME_1000); + let errors; + var startTime = await Utils.getNowTime(); + let data = await Bundle.getApplicationInfo(BUNDLE_NAME, Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_DISABLE) + .catch((error) => { + console.info(TAG_TEST_0200_003 + 'onUserId promise error is: ' + error); + errors = error; + }); + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0200_003, startTime, endTime); + console.info(TAG_TEST_0200_003 + ' onUserId promise data is: ' + JSON.stringify(data)); + if (1 === errors) { + expect(errors).assertEqual(1); + } else { + commonTest(TAG_TEST_0200_003, data); + getApplicationInfoSuccess(TAG_TEST_0200_003, data); + } + done(); + console.log('------------------ ' + TAG_TEST_0200_003 + ' end -------------------'); + }); + + /** + * @tc.number: bundle_getApplicationInfo_test_0300_007 + * @tc.name: getApplicationInfo : Obtains based on a given bundle name. + * @tc.desc: Check the return value of the interface (by callBack) + * @tc.level 0 + */ + it(TAG_TEST_0300_001, 0, async function (done) { + console.info(TAG_TEST_0300_001 + 'callBack START'); + await Utils.sleep(SLEEP_TIME_1000); + let errors; + let datas; + var startTime = await Utils.getNowTime(); + Bundle.getApplicationInfo(BUNDLE_NAME, Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, + USER_ID_100, (error, data) => { + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0300_001, startTime, endTime); + console.info(TAG_TEST_0300_001 + 'UserId callBack in'); + console.info(TAG_TEST_0300_001 + 'UserId callBack error: ' + error); + errors = error; + console.info(TAG_TEST_0300_001 + 'UserId callBack data is:' + JSON.stringify(data)); + datas = data; + }); + await Utils.sleep(2000); + console.info(TAG_TEST_0300_001 + 'UserId callBack data is: ' + JSON.stringify(datas)); + if (1 === errors) { + expect(errors).assertEqual(1); + } else { + commonTest(TAG_TEST_0300_001, datas); + getApplicationInfoSuccess(TAG_TEST_0300_001, datas); + } + done(); + console.log('------------------ ' + TAG_TEST_0300_001 + ' end -------------------'); + }); + + /** + * @tc.number: bundle_getApplicationInfo_test_0400_008 + * @tc.name: getApplicationInfo : Obtains based on a given bundle name. + * @tc.desc: Check the return value of the interface (by callBack) + * @tc.level 0 + */ + it(TAG_TEST_0400_001, 0, async function (done) { + console.info(TAG_TEST_0400_001 + 'callBack START'); + let errors; + let datas; + var startTime = await Utils.getNowTime(); + Bundle.getApplicationInfo(BUNDLE_NAME, Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, (error, data) => { + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0400_001, startTime, endTime); + console.info(TAG_TEST_0400_001 + 'noUserId callBack in'); + console.info(TAG_TEST_0400_001 + 'noUserId callBack error: ' + error); + errors = error; + console.info(TAG_TEST_0400_001 + 'noUserId callBack data is:' + JSON.stringify(data)); + datas = data; + }); + await Utils.sleep(2000); + console.info(TAG_TEST_0400_001 + 'noUserId callBack data is: ' + JSON.stringify(datas)); + if (1 === errors) { + expect(errors).assertEqual(1); + } else { + commonTest(TAG_TEST_0400_001, datas); + getApplicationInfoSuccess(TAG_TEST_0400_001, datas); + } + done(); + console.log('------------------ ' + TAG_TEST_0400_001 + ' end -------------------'); + }); + + /** + * @tc.number: bundle_getApplicationInfo_test_0500_009 + * @tc.name: getApplicationInfo : Obtains based on a given bundle name. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(TAG_TEST_0500_001, 0, async function (done) { + console.info(TAG_TEST_0500_001 + 'promise START'); + await Utils.sleep(SLEEP_TIME_1000); + let errors; + var startTime = await Utils.getNowTime(); + let data = await Bundle.getApplicationInfo('', 0) + .catch((error) => { + console.info(TAG_TEST_0500_001 + 'noUserId promise error is: ' + error); + errors = error; + }); + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0500_001, startTime, endTime); + console.info(TAG_TEST_0500_001 + ' noUserId promise data is: ' + JSON.stringify(data)); + if (1 === errors) { + expect(errors).assertEqual(1); + } + done(); + console.log('------------------ ' + TAG_TEST_0500_001 + ' end -------------------'); + }); + + /** + * @tc.number: bundle_getApplicationInfo_test_0500_0010 + * @tc.name: getApplicationInfo : Obtains based on a given bundle name. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(TAG_TEST_0500_002, 0, async function (done) { + console.info(TAG_TEST_0500_002 + 'promise START'); + await Utils.sleep(SLEEP_TIME_1000); + let errors; + var startTime = await Utils.getNowTime(); + let data = await Bundle.getApplicationInfo('', '0', USER_ID_100) + .catch((error) => { + console.info(TAG_TEST_0500_002 + 'UserId promise error is: ' + error); + errors = error; + }); + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0500_002, startTime, endTime); + console.info(TAG_TEST_0500_002 + ' UserId promise data is: ' + JSON.stringify(data)); + if (1 === errors) { + expect(errors).assertEqual(1); + } + done(); + console.log('------------------ ' + TAG_TEST_0500_002 + ' end -------------------'); + }); + + /** + * @tc.number: bundle_getApplicationInfo_test_0600_0011 + * @tc.name: getApplicationInfo : Obtains based on a given bundle name. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(TAG_TEST_0600_001, 0, async function (done) { + console.info(TAG_TEST_0600_001 + 'promise START'); + await Utils.sleep(SLEEP_TIME_1000); + let errors; + var startTime = await Utils.getNowTime(); + let data = await Bundle.getApplicationInfo(BUNDLE_NAME_OTHER, + Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION) + .catch((error) => { + console.info(TAG_TEST_0600_001 + 'other bundleName noUserId promise error is: ' + error); + errors = error; + }); + console.info(TAG_TEST_0600_001 + ' other bundleName noUserId promise errors is: ' + JSON.stringify(errors)); + console.info(TAG_TEST_0600_001 + ' other bundleName noUserId promise data is: ' + JSON.stringify(data)); + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0600_001, startTime, endTime); + if (1 === errors) { + expect(errors).assertEqual(1); + } else { + commonTest(TAG_TEST_0600_001, data); + getApplicationInfoOtherSuccess(TAG_TEST_0600_001, data); + } + done(); + console.log('------------------ ' + TAG_TEST_0600_001 + ' end -------------------'); + }); + + /** + * @tc.number: bundle_getApplicationInfo_test_0600_0012 + * @tc.name: getApplicationInfo : Obtains based on a given bundle name. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(TAG_TEST_0600_002, 0, async function (done) { + console.info(TAG_TEST_0600_002 + 'promise START'); + await Utils.sleep(SLEEP_TIME_1000); + let errors; + var startTime = await Utils.getNowTime(); + let data = + await Bundle.getApplicationInfo(BUNDLE_NAME_OTHER, Bundle.BundleFlag.GET_APPLICATION_INFO_WITH_PERMISSION, + USER_ID_100) + .catch((error) => { + console.info(TAG_TEST_0600_002 + 'other bundleName UserId promise error is: ' + error); + errors = error; + }); + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0600_002, startTime, endTime); + console.info(TAG_TEST_0600_002 + ' other bundleName UserId promise errors is: ' + JSON.stringify(errors)); + console.info(TAG_TEST_0600_002 + ' other bundleName UserId promise data is: ' + JSON.stringify(data)); + if (1 === errors) { + expect(errors).assertEqual(1); + } else { + commonTest(TAG_TEST_0600_002, data); + getApplicationInfoOtherSuccess(TAG_TEST_0600_002, data); + } + done(); + console.log('------------------ ' + TAG_TEST_0600_002 + ' end -------------------'); + }); + + /** + * @tc.number: bundle_getApplicationInfo_test_0500_009 + * @tc.name: getApplicationInfo : Obtains based on a given bundle name. + * @tc.desc: Check the return value of the interface (by promise) + * @tc.level 0 + */ + it(TAG_TEST_0600_003, 0, async function (done) { + console.info(TAG_TEST_0600_003 + 'promise START'); + await Utils.sleep(SLEEP_TIME_1000); + let errors; + var startTime = await Utils.getNowTime(); + let data = await Bundle.getApplicationInfo(BUNDLE_NAME, 0) + .catch((error) => { + console.info(TAG_TEST_0600_003 + 'noUserId promise error is: ' + error); + errors = error; + }); + var endTime = Utils.getNowTime(); + Utils.getDurationTime(TAG_TEST_0600_003, startTime, endTime); + console.info(TAG_TEST_0600_003 + ' noUserId promise data is: ' + JSON.stringify(data)); + if (1 === errors) { + expect(errors).assertEqual(1); + } else { + commonTest(TAG_TEST_0600_003, data); + getApplicationInfoSuccess(TAG_TEST_0600_003, data); + } + done(); + console.log('------------------ ' + TAG_TEST_0600_003 + ' end -------------------'); + }); + + /** + * 打印单和expect个属性 + * @param msg log信息 + * @param data 数据源 + */ + function commonTest(msg, data) { + console.log(msg + ' commonTest start ' + JSON.stringify(data)); + console.log(msg + ' name : ' + data.name); + console.log(msg + ' codePath : ' + data.codePath); + console.log(msg + ' accessTokenId : ' + data.accessTokenId); + console.log(msg + ' description : ' + data.description); + console.log(msg + ' descriptionId : ' + data.descriptionId); + console.log(msg + ' icon : ' + data.icon); + console.log(msg + ' iconId : ' + data.iconId); + console.log(msg + ' label : ' + data.label); + console.log(msg + ' labelId : ' + data.labelId); + console.log(msg + ' systemApp : ' + data.systemApp); + console.log(msg + ' supportedModes : ' + data.supportedModes); + console.log(msg + ' entryDir : ' + data.entryDir); + console.log(msg + ' metaData : ' + data.metaData); + console.log(msg + ' metadata : ' + data.metadata); + console.log(msg + ' enabled : ' + data.enabled); + console.log(msg + ' flags : ' + data.flags); + console.log(msg + ' uid : ' + data.uid); + console.log(msg + ' removable : ' + data.removable); + console.log(msg + ' permissions length : ' + data.permissions.length); + for (var j = 0; j < data.permissions.length; j++) { + console.log('getApplicationInfo0001 data.permissions[' + j + '] : ' + data.permissions[j]); + } + console.log(msg + ' moduleSourceDirs length : ' + data.moduleSourceDirs.length); + for (var i = 0; i < data.moduleSourceDirs.length; i++) { + console.log('getApplicationInfo0001 data.moduleSourceDirs[' + i + '] : ' + data.moduleSourceDirs[i]); + } + console.log(msg + ' moduleInfos length : ' + data.moduleInfos.length); + for (var k = 0; k < data.moduleInfos.length; k++) { + console.log('getApplicationInfo0001 data.moduleInfos[' + k + '] : ' + data.moduleInfos[k].moduleName); + console.log('getApplicationInfo0001 data.moduleInfos[' + k + '] : ' + data.moduleInfos[k].moduleSourceDir); + } + expectData(msg, data); + } + + /** + * expect属性 + * @param msg log信息 + * @param data 数据源 + */ + function expectData(msg, data) { + expect(typeof (data)).assertEqual('object'); + expect(typeof (data.name)).assertEqual('string'); + expect(typeof (data.codePath)).assertEqual('string'); + expect(typeof (data.accessTokenId)).assertEqual('number'); + expect(typeof (data.description)).assertEqual('string'); + expect(typeof (data.descriptionId)).assertEqual('number'); + expect(typeof (data.icon)).assertEqual('string'); + expect(typeof (data.iconId)).assertEqual('number'); + expect(typeof (data.label)).assertEqual('string'); + expect(typeof (data.labelId)).assertEqual('number'); + expect(typeof (data.systemApp)).assertEqual('boolean') + expect(typeof (data.supportedModes)).assertEqual('number'); + expect(typeof (data.entryDir)).assertEqual('string'); + expect(typeof (data.metaData)).assertEqual('object'); + expect(typeof (data.metadata)).assertEqual('object'); + expect(typeof (data.enabled)).assertEqual('boolean'); + expect(typeof (data.flags)).assertEqual('number'); + expect(typeof (data.uid)).assertEqual('number'); + expect(typeof (data.entityType)).assertEqual('string'); + expect(typeof (data.removable)).assertEqual('boolean'); + expect(Array.isArray(data.permissions)).assertEqual(true); + expect(Array.isArray(data.moduleSourceDirs)).assertEqual(true); + expect(Array.isArray(data.moduleInfos)).assertEqual(true); + } + + /** + * expect属性值 + * @param msg log信息 + * @param data 数据源 + */ + function getApplicationInfoSuccess(msg, data) { + expect(data.name).assertEqual('com.open.harmony.packagemag'); + expect(data.codePath).assertEqual('/data/app/el1/bundle/public/com.open.harmony.packagemag'); + expect(data.description).assertEqual('$string:mainability_description'); +// expect(data.descriptionId).assertEqual(16777217); + expect(data.icon).assertEqual('$media:icon'); +// expect(data.iconId).assertEqual(16777218); + expect(data.label).assertEqual('$string:entry_MainAbility'); +// expect(data.labelId).assertEqual(16777216); + expect(data.systemApp).assertEqual(true); + expect(data.supportedModes).assertEqual(0); + expect(data.entryDir).assertEqual('/data/app/el1/bundle/public/com.open.harmony.packagemag' + + '/com.open.harmony.packagemag'); + expect(data.enabled).assertEqual(true); + expect(data.entityType).assertEqual('unspecified'); + expect(data.removable).assertEqual(true); + expect(data.moduleInfos[0].moduleName).assertEqual('entry'); + expect(data.moduleInfos[0].moduleSourceDir).assertEqual('/data/app/el1/bundle/public/' + + 'com.open.harmony.packagemag/com.open.harmony.packagemag'); + expect(data.moduleSourceDirs[0]).assertEqual('/data/app/el1/bundle/public/' + + 'com.open.harmony.packagemag/com.open.harmony.packagemag'); + console.log(msg + ' end ' + JSON.stringify(data)); + } + + /** + * expect属性值 + * @param msg log信息 + * @param data 数据源 + */ + function getApplicationInfoFial(msg, data) { + expect(data.name).assertEqual(''); + expect(data.codePath).assertEqual(''); + expect(data.description).assertEqual(''); + expect(data.descriptionId).assertEqual(0); + expect(data.icon).assertEqual(''); + expect(data.iconId).assertEqual(0); + expect(data.label).assertEqual(''); + expect(data.labelId).assertEqual(0); + expect(data.systemApp).assertEqual(false); + expect(data.supportedModes).assertEqual(0); + expect(data.entryDir).assertEqual(''); + expect(data.enabled).assertEqual(false); + expect(data.entityType).assertEqual(''); + expect(data.removable).assertEqual(true); + console.log(msg + ' end ' + JSON.stringify(data)); + } + + + /** + * expect属性值 + * @param msg log信息 + * @param data 数据源 + */ + function getApplicationInfoOtherSuccess(msg, data) { + expect(data.name).assertEqual('com.ohos.acepackage'); + expect(data.codePath).assertEqual('/data/app/el1/bundle/public/com.ohos.acepackage'); + expect(data.description).assertEqual('$string:description_mainability'); + expect(data.descriptionId > 0).assertEqual(true); + expect(data.icon).assertEqual('$media:icon'); + expect(data.iconId > 0).assertEqual(true); + expect(data.label).assertEqual('$string:entry_MainAbility'); + expect(data.labelId > 0).assertEqual(true); + expect(data.systemApp).assertEqual(true); + expect(data.supportedModes).assertEqual(0); + expect(data.entryDir).assertEqual('/data/app/el1/bundle/public/com.ohos.acepackage' + + '/com.ohos.acepackage'); + expect(data.enabled).assertEqual(true); + expect(data.entityType).assertEqual('unspecified'); + expect(data.removable).assertEqual(true); + expect(data.moduleInfos[0].moduleName).assertEqual('entry'); + expect(data.moduleInfos[0].moduleSourceDir).assertEqual('/data/app/el1/bundle/public/' + + 'com.ohos.acepackage/com.ohos.acepackage'); + expect(data.moduleSourceDirs[0]).assertEqual('/data/app/el1/bundle/public/' + + 'com.ohos.acepackage/com.ohos.acepackage'); + console.log(msg + ' end ' + JSON.stringify(data)); + } + }); +} \ No newline at end of file diff --git a/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/ServiceAbility/service.ts b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/ServiceAbility/service.ts new file mode 100644 index 0000000000000000000000000000000000000000..383f9f0ebefc00d5761c83f88fcd1ba6c9500cd1 --- /dev/null +++ b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/ets/ServiceAbility/service.ts @@ -0,0 +1,11 @@ +export default { + onStart() { + console.info('ServiceAbility onStart'); + }, + onStop() { + console.info('ServiceAbility onStop'); + }, + onCommand(want, startId) { + console.info('ServiceAbility onCommand'); + } +}; \ No newline at end of file diff --git a/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/resources/base/element/string.json b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..2482e91c015e2e8d68406790782982adc4789b34 --- /dev/null +++ b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "entry_MainAbility" + }, + { + "name": "description_mainability", + "value": "eTS_Empty Ability" + }, + { + "name": "mainability_description", + "value": "eTS_Empty Ability" + }, + { + "name": "description_serviceability", + "value": "hap sample empty service" + } + ] +} \ No newline at end of file diff --git a/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/resources/base/media/icon.png b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/entry/src/main/resources/base/media/icon.png differ diff --git a/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/signature/openharmony_sx.p7b b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..9be1e98fa4c0c28ca997ed660112fa16b194f0f5 Binary files /dev/null and b/appexecfwk/bundle_standard/bundlemanager/actsbundlemanageretstest/signature/openharmony_sx.p7b differ