提交 cb65769a 编写于 作者: C chengxingzhen

shell命令管控新增用例

Signed-off-by: Nchengxingzhen <chengxingzhen@huawei.com>
上级 7fd02cdd
......@@ -19,6 +19,7 @@ group("actsshellcommandfunctionalitytest") {
deps = [
"ActsExecuteShellCommandTest:ActsExecuteShellCommandTest",
"ActsKillProcessWithAccountCloseRelyHap:ActsKillProcessWithAccountCloseRelyHap",
"actsshellcommandcontroltest:ActsShellCommandControlTest",
]
}
}
{
"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
}
}
}
# 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"
}
{
"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
}
]
}
/*
* 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
/*
* 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
/*
* 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
/*
* 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
/*
* 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
/*
* 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
{
"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
{
"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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册