未验证 提交 45902334 编写于 作者: O openharmony_ci 提交者: Gitee

!5019 commit ability_call xts

Merge pull request !5019 from dy/master0818
...@@ -24,6 +24,8 @@ group("ability_runtime") { ...@@ -24,6 +24,8 @@ group("ability_runtime") {
"actsabilitydelegatorcase:ActsAbilityDelegatorCaseTest", "actsabilitydelegatorcase:ActsAbilityDelegatorCaseTest",
"actsabilitymanageretstest:ActsAbilityManagerEtsTest", "actsabilitymanageretstest:ActsAbilityManagerEtsTest",
"actsabilityusertest:ActsAbilityuserTest", "actsabilityusertest:ActsAbilityuserTest",
"actscalldataabilitytest:ActsCallDataAbilityTest",
"actscalldataabilitytest:ActsCallDataAbilityTest",
"actscalltest:actscalltest", "actscalltest:actscalltest",
"actsfwkdataaccessortest:dataability", "actsfwkdataaccessortest:dataability",
"actsqueryfunctiontest:actsqueryfunctiontest", "actsqueryfunctiontest:actsqueryfunctiontest",
......
# Copyright (c) 2022 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("ActsCallDataAbilityTest") {
hap_profile = "./entry/src/main/config.json"
deps = [
":actscalldataabilitytest_ets_assets",
":actscalldataabilitytest_ets_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsCallDataAbilityTest"
}
ohos_js_assets("actscalldataabilitytest_ets_assets") {
source_dir = "./entry/src/main/ets"
hap_profile = "entry/src/main/config.json"
ets2abc = true
}
ohos_resources("actscalldataabilitytest_ets_resources") {
sources = [ "./entry/src/main/resources" ]
hap_profile = "./entry/src/main/config.json"
}
{
"description": "Configuration for ActsCallDataAbilityTest Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "300000",
"bundle-name": "ohos.acts.aafwk.test.fasupplement",
"package-name": "ohos.acts.aafwk.test.fasupplement",
"shell-timeout": "600000",
"testcase-timeout": "10000"
},
"kits": [
{
"test-file-name": [
"ActsCallDataAbilityTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
{
"app": {
"vendor": "example",
"bundleName": "ohos.acts.aafwk.test.fasupplement",
"version": {
"code": 1000000,
"name": "1.0.0"
},
"apiVersion": {
"compatible": 8,
"releaseType": "Release",
"target": 8
}
},
"deviceConfig": {},
"module": {
"mainAbility": ".MainAbility",
"deviceType": [
"default"
],
"reqPermissions": [
{
"name": "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
},
{
"name": "ohos.permission.GET_BUNDLE_INFO"
},
{
"name": "ohos.permission.READ_CONTACTS"
},
{
"name": "ohos.permission.WRITE_CONTACTS"
}
],
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"orientation": "unspecified",
"visible": true,
"srcPath": "MainAbility",
"name": ".MainAbility",
"srcLanguage": "ets",
"icon": "$media:icon",
"description": "$string:MainAbility_desc",
"formsEnabled": false,
"label": "$string:MainAbility_label",
"type": "page",
"launchType": "singleton"
},
{
"name": ".DataAbility",
"srcLanguage": "ets",
"srcPath": "DataAbility",
"icon": "$media:icon",
"description": "$string:DataAbility_desc",
"type": "data",
"uri": "dataability://ohos.acts.aafwk.test.fasupplement.DataAbility"
}
],
"distro": {
"moduleType": "entry",
"installationFree": false,
"deliveryWithInstall": true,
"moduleName": "entry"
},
"package": "ohos.acts.aafwk.test.fasupplement",
"srcPath": "",
"name": ".entry",
"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": "ohos.acts.aafwk.test.fasupplement.DataAbilityShellProvider.PROVIDER"
}
]
}
}
\ No newline at end of file
/**
* Copyright (c) 2022 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 commonEvent from '@ohos.commonEvent';
var publishOptions = {
parameters: {
"assertData": "{\"group_name\":{\"data\":\"test1\",\"type\":10},"
+"\"ringtone_modify_time\":{\"data\":\"28wTypeToString\",\"type\":9}}"
}
};
function PublishCallBack(err) {
if (err.code) {
console.error("callTest publish failed " + JSON.stringify(err));
} else {
console.info("callTest publish success!!!");
}
}
export default {
onInitialized(abilityInfo) {
console.info('DataAbility onInitialized');
},
call(method, arg, extras) {
console.info('DataAbility call test000');
console.info('call succeeded data111 ' + JSON.stringify(extras));
var temp = JSON.stringify(extras);
if(temp == "\"{\\\"group_name\\\":{\\\"data\\\":\\\"test1\\\",\\\"type\\\":10}," +
"\\\"ringtone_modify_time\\\":{\\\"data\\\":\\\"28wTypeToString\\\",\\\"type\\\":9}}\"")
{
console.info('call commonEvent.publish start!!!!');
commonEvent.publish("call_event", publishOptions, PublishCallBack);
}else {
console.info('call not commonEvent.publish!!!');
}
return extras;
}
};
\ No newline at end of file
/**
* Copyright (c) 2022 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('onCreate');
},
onDestroy() {
console.info('onDestroy');
},
onActive() {
console.info('onActive');
},
onInactive() {
console.info('onInactive');
},
onShow() {
console.info('onShow');
},
onHide() {
console.info('onHide');
}
}
\ No newline at end of file
// @ts-nocheck
/**
* Copyright (c) 2022 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from "../test/List.test";
@Entry
@Component
struct Index {
@State message: string = 'Hello World'
aboutToAppear() {
console.info("aboutToAppear start!!!!")
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
/**
* Copyright (c) 2022 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 callTest from "./callTest.test";
export default function testsuite() {
callTest();
}
\ No newline at end of file
/**
* Copyright (c) 2022 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;
}
}
// @ts-nocheck
/**
* Copyright (c) 2022 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 "@ohos/hypium";
import featureAbility from "@ohos.ability.featureAbility";
import commonEvent from '@ohos.commonEvent';
import Utils from './Utils';
export default function callTest() {
let TAG = "";
const URI_TEST = 'dataability:///ohos.acts.aafwk.test.fasupplement.DataAbility';
let dataAbilityHelper = featureAbility.acquireDataAbilityHelper(URI_TEST);
let pacMap = {
'group_name': 'test1',
'ringtone_modify_time': 28
};
var dataAssert = "";
var subscriber;
var subscribeInfo = {
events: ["call_event"]
};
function SubscribeCallBack(err, data) {
if (err.code) {
console.error("commonEvent subscribe failed " + JSON.stringify(err));
} else {
console.info("commonEvent subscribe service " + JSON.stringify(data));
for (var key in data.parameters) {
if (data.parameters[key]) {
dataAssert = data.parameters[key]
console.info("callTest dataAssert is : " + dataAssert);
}
}
}
}
function CreateSubscriberCallBack(err, commonEventSubscriber) {
if (err.code) {
console.error("commonEvent createSubscriber failed " + JSON.stringify(err));
} else {
console.info("----commonEvent createSubscriber------");
subscriber = commonEventSubscriber;
commonEvent.subscribe(subscriber, SubscribeCallBack);
}
}
describe('callTest', function () {
/*
* @tc.number CallTest_0100
* @tc.name The deviceid passed in is null, so the installation free process is implemented
* @tc.desc Function test
* @tc.level 0
*/
it("CallTest_0100", 0, async function (done) {
console.info("------------start CallTest_0100-------------");
console.info("CallTest_0100 commonEvent.createSubscriber start!!!");
commonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack);
await Utils.sleep(2000);
TAG = "CallTest_0100";
let details;
dataAbilityHelper.call(URI_TEST, 'insert', '', pacMap).then((data) => {
console.info(TAG + ' call succeeded, data: ' + JSON.stringify(data));
details = data;
}).catch((error) => {
console.error(TAG + ' call failed, error: ' + JSON.stringify(error));
});
await Utils.sleep(2000);
expect(details.result).assertEqual("{\"group_name\":{\"data\":\"test1\",\"type\":10}," +
"\"ringtone_modify_time\":{\"data\":\"28wTypeToString\",\"type\":9}}");
expect(dataAssert).assertEqual("{\"group_name\":{\"data\":\"test1\",\"type\":10}" +
",\"ringtone_modify_time\":{\"data\":\"28wTypeToString\",\"type\":9}}");
console.info("------------end CallTest_0100-------------");
done();
});
})
}
\ No newline at end of file
import TestRunner from '@ohos.application.testRunner'
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
function translateParamsToString(parameters) {
const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s itName',
'-s level', '-s testType', '-s size', '-s timeout',
'-s package','-s dryRun'
])
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
targetParams += ' ' + key + ' ' + parameters[key]
}
}
return targetParams.trim()
}
async function onAbilityCreateCallback() {
console.info('onAbilityCreateCallback');
}
async function addAbilityMonitorCallback(err: any) {
console.info('addAbilityMonitorCallback : ' + JSON.stringify(err))
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
console.info('OpenHarmonyTestRunner OnPrepare')
}
onRun() {
console.info('OpenHarmonyTestRunner onRun run')
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.MainAbility'
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters)
console.info('cmd : '+cmd)
var debug = abilityDelegatorArguments.parameters["-D"]
if (debug == 'true')
{
cmd += ' -D'
}
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 call abilityDelegator.getAppContext')
var context = abilityDelegator.getAppContext()
console.info('getAppContext : ' + JSON.stringify(context))
console.info('OpenHarmonyTestRunner onRun end')
}
};
\ No newline at end of file
{
"string": [
{
"name": "entry_desc",
"value": "description"
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "FaSupplement"
},
{
"name": "MainAbility2_desc",
"value": "description"
},
{
"name": "MainAbility2_label",
"value": "label"
},
{
"name": "MainAbility3_desc",
"value": "description"
},
{
"name": "MainAbility3_label",
"value": "label"
},
{
"name": "PageAbility_desc",
"value": "description"
},
{
"name": "PageAbility_label",
"value": "label"
},
{
"name": "DataAbility_desc",
"value": "hap sample empty provider"
}
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册