diff --git a/ability/ability_runtime/actsshellcommandfunctionalitytest/BUILD.gn b/ability/ability_runtime/actsshellcommandfunctionalitytest/BUILD.gn index 8dbba44f84b033ac930d0b90fe9f89ccf7b574f6..c90c665f6ffdca140ba6dae01b11afeb277ee80e 100755 --- a/ability/ability_runtime/actsshellcommandfunctionalitytest/BUILD.gn +++ b/ability/ability_runtime/actsshellcommandfunctionalitytest/BUILD.gn @@ -19,6 +19,7 @@ group("actsshellcommandfunctionalitytest") { deps = [ "ActsExecuteShellCommandTest:ActsExecuteShellCommandTest", "ActsKillProcessWithAccountCloseRelyHap:ActsKillProcessWithAccountCloseRelyHap", + "actsshellcommandcontroltest:ActsShellCommandControlTest", ] } } diff --git a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/AppScope/app.json b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..03180e1433f4b621c2e140fd11e9075ff836dd4f --- /dev/null +++ b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "app": { + "bundleName": "com.acts.shellcommandcontroltest", + "vendor": "huawei", + "versionCode": 1000000, + "versionName": "1.0.0", + "debug": false, + "icon" : "$media:icon", + "label" : "$string:app_name", + "description" : "$string:description_application", + "distributedNotificationEnabled": true, + "keepAlive" : true, + "singleUser": true, + "minAPIVersion": 9, + "targetAPIVersion": 9, + "car": { + "apiCompatibleVersion": 9, + "singleUser": false + } + } +} diff --git a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/AppScope/resources/base/element/string.json b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ec48a8748ea2b8c0babde132baba30c5503a0918 --- /dev/null +++ b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "AbilityStageMonitor" + } + ] +} diff --git a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/AppScope/resources/base/media/app_icon.png b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/AppScope/resources/base/media/app_icon.png differ diff --git a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/BUILD.gn b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..1cf32345390c8ec2da60908324fb7425d6cfbc3a --- /dev/null +++ b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/BUILD.gn @@ -0,0 +1,43 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("ActsShellCommandControlTest") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":shellcommandcontrol_js_assets", + ":shellcommandcontrol_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsShellCommandControlTest" + subsystem_name = "ability" + part_name = "ability_runtime" +} + +ohos_app_scope("shellcommandcontrol_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("shellcommandcontrol_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("shellcommandcontrol_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":shellcommandcontrol_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/Test.json b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..72f0ef43cfcdd33a34f995cbeaa20882532e269d --- /dev/null +++ b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/Test.json @@ -0,0 +1,21 @@ +{ + "description": "Configuration for ShellCommand Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "600000", + "bundle-name": "com.acts.shellcommandcontroltest", + "module-name": "entry_test", + "shell-timeout": "600000", + "testcase-timeout": "15000" + }, + "kits": [ + { + "test-file-name": [ + "ActsShellCommandControlTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} + diff --git a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/Application/MyAbilityStage.ts b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/Application/MyAbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..8a0fce1233f517b4baa8396228da2b63de8f91e2 --- /dev/null +++ b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/Application/MyAbilityStage.ts @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import AbilityStage from "@ohos.app.ability.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.info("MyAbilityStageMonitor onCreate"); + globalThis.abilityStageContext = this.context; + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/MainAbility/MainAbility.ts b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..7cdfc5138176ed4585216d1cc3bd647c04c165a1 --- /dev/null +++ b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import Ability from '@ohos.app.ability.UIAbility' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../test/List.test' + +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + // Ability is creating, initialize resources for this ability + console.log("ActsShellCommandControlTest MainAbility onCreate"); + globalThis.abilityWant = want; + globalThis.abilityContext = this.context; + let abilityDelegator: any; + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + let abilityDelegatorArguments: any; + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); + console.info('start run testcase!!!'); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite); + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log("ActsShellCommandControlTest MainAbility onDestroy"); + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("ActsShellCommandControlTest MainAbility onWindowStageCreate"); + + windowStage.setUIContent(this.context, "pages/index/index", null); + console.log("ActsShellCommandControlTest MainAbility onWindowStageCreate finish"); + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("ActsShellCommandControlTest MainAbility onWindowStageDestroy"); + } + + onForeground() { + // Ability has brought to foreground + console.log("ActsShellCommandControlTest MainAbility onForeground"); + } + + onBackground() { + // Ability has back to background + console.log("ActsShellCommandControlTest MainAbility onBackground"); + } +}; \ No newline at end of file diff --git a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..0ddb2de4273812f773af0f5bf0369cde447ded8d --- /dev/null +++ b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,75 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import TestRunner from '@ohos.application.testRunner' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +let abilityDelegator = undefined; +let abilityDelegatorArguments = undefined; + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s it', + '-s level', '-s testType', '-s size', '-s timeout', + '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams = `${targetParams} ${key} ${parameters[key]}`; + } + } + return targetParams.trim(); +} + +async function onAbilityCreateCallback() { + console.log("onAbilityCreateCallback"); +} + +async function addAbilityMonitorCallback(err: any) { + console.info("addAbilityMonitorCallback : " + JSON.stringify(err)); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info("OpenHarmonyTestRunner OnPrepare "); + } + + async onRun() { + console.log('OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + globalThis.abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + let testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility'; + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback); + let cmd = 'aa start -d 0 -a MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName; + cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters); + console.info('cmd : '+cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }) + console.info('OpenHarmonyTestRunner onRun end'); + } +}; \ No newline at end of file diff --git a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/pages/index/index.ets b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/pages/index/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..536912f24725740b1ad54026a059886230152d56 --- /dev/null +++ b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/pages/index/index.ets @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +@Entry +@Component +struct Index { + build() { + Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('MainAbility Hello World') + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + }) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/test/List.test.ets b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..f909390bf9151c3c97ac0ea06ee0ce4a51a4a6ce --- /dev/null +++ b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* +* Copyright (c) 2023 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import shellCommandControlTest from './ShellCommandControl.test' + +export default function testsuite() { + shellCommandControlTest(); +} \ No newline at end of file diff --git a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/test/ShellCommandControl.test.ets b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/test/ShellCommandControl.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..dc86ce23c8f32190a0b36ac6a524b0efa9832169 --- /dev/null +++ b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/ets/test/ShellCommandControl.test.ets @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, it, expect } from '@ohos/hypium' + +let TAG; +export default function shellCommandControlTest() { + describe('ShellCommandControlTest', function () { + + /** + * @tc.number: Acts_Ability_ShellCommandControl__0100 + * @tc.name: Verify that the aa command aa help can be executed + * @tc.desc: Error code 0 is returned + * @tc.level 0 + */ + it('Acts_Ability_ShellCommandControl__0100', 0, async function (done) { + TAG = 'Acts_Ability_ShellCommandControl__0100'; + console.log(`${TAG} --- start`); + let cmd = 'aa help' + globalThis.abilityDelegator.executeShellCommand(cmd, (err, data) => { + console.log(`${TAG} stdResult = ${data.stdResult}`); + console.log(`${TAG} stdResult = ${JSON.stringify(err)}`); + expect(data.exitCode).assertEqual(0); + console.log(`${TAG} --- end`); + done(); + }) + }) + + /** + * @tc.number: Acts_Ability_ShellCommandControl__0200 + * @tc.name: Verify that the aa command ls -l cannot be executed + * @tc.desc: Error code -1 is returned + * @tc.level 3 + */ + it('Acts_Ability_ShellCommandControl__0200', 0, async function (done) { + TAG = 'Acts_Ability_ShellCommandControl__0200'; + console.log(`${TAG} --- start`); + let cmd = 'ls -l'; + globalThis.abilityDelegator.executeShellCommand(cmd, (err, data) => { + console.log(`${TAG} stdResult = ${data.stdResult}`); + console.log(`${TAG} stdResult = ${JSON.stringify(err)}`); + expect(data.exitCode).assertEqual(-1); + console.log(`${TAG} --- end`); + done(); + }) + }) + }) +} \ No newline at end of file diff --git a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/module.json b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..f737641a3b1559e7c64a66f1efb68309f23df16a --- /dev/null +++ b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/module.json @@ -0,0 +1,27 @@ +{ + "module": { + "name": "entry_test", + "type": "entry", + "srcEntrance": "./ets/Application/MyAbilityStage.ts", + "description": "$string:entry_test_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "default", + "tablet" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:MainAbility_desc", + "icon": "$media:icon", + "label": "$string:MainAbility_label", + "visible": true + } + ] + } +} \ No newline at end of file diff --git a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/resources/base/element/string.json b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b744e36fe4671b89dcaac6069cf31ac5b8522115 --- /dev/null +++ b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/resources/base/element/string.json @@ -0,0 +1,24 @@ +{ + "string": [ + { + "name": "entry_test_desc", + "value": "description" + }, + { + "name": "app_name", + "value": "ActsShellCommandControlTest" + }, + { + "name": "description_application", + "value": "demo for test" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "entry_MainAbility" + } + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/resources/base/media/icon.png b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/resources/base/media/icon.png differ diff --git a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/resources/base/profile/main_pages.json b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..821ecf2358ec52ffa8b0812267be3793be71896a --- /dev/null +++ b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/index/index" + ] +} \ No newline at end of file diff --git a/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/signature/openharmony_sx.p7b b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..0789a885c9a517f23617d7442790309b8248f3aa Binary files /dev/null and b/ability/ability_runtime/actsshellcommandfunctionalitytest/actsshellcommandcontroltest/signature/openharmony_sx.p7b differ