diff --git a/ability/ability_runtime/BUILD.gn b/ability/ability_runtime/BUILD.gn index c94523228f9517d53caaba0031c3d36b439f4987..25e5ef05aa27f6c889f3dd99439e9cfb7901af18 100644 --- a/ability/ability_runtime/BUILD.gn +++ b/ability/ability_runtime/BUILD.gn @@ -24,6 +24,8 @@ group("ability_runtime") { "actsabilitydelegatorcase:ActsAbilityDelegatorCaseTest", "actsabilitymanageretstest:ActsAbilityManagerEtsTest", "actsabilityusertest:ActsAbilityuserTest", + "actscalldataabilitytest:ActsCallDataAbilityTest", + "actscalldataabilitytest:ActsCallDataAbilityTest", "actscalltest:actscalltest", "actsfwkdataaccessortest:dataability", "actsqueryfunctiontest:actsqueryfunctiontest", diff --git a/ability/ability_runtime/actscalldataabilitytest/BUILD.gn b/ability/ability_runtime/actscalldataabilitytest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..da3fc144cdd030cc89abdaf8cdc8582bef81a0b9 --- /dev/null +++ b/ability/ability_runtime/actscalldataabilitytest/BUILD.gn @@ -0,0 +1,34 @@ +# 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" +} diff --git a/ability/ability_runtime/actscalldataabilitytest/Test.json b/ability/ability_runtime/actscalldataabilitytest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..3b870295fefc32b94e8a96c0cfd16b52af303a5a --- /dev/null +++ b/ability/ability_runtime/actscalldataabilitytest/Test.json @@ -0,0 +1,20 @@ +{ + "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 + } + ] +} diff --git a/ability/ability_runtime/actscalldataabilitytest/entry/src/main/config.json b/ability/ability_runtime/actscalldataabilitytest/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..2ec7fe991480c6457418e7f0f56dfdb3932e6c4f --- /dev/null +++ b/ability/ability_runtime/actscalldataabilitytest/entry/src/main/config.json @@ -0,0 +1,114 @@ +{ + "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 diff --git a/ability/ability_runtime/actscalldataabilitytest/entry/src/main/ets/DataAbility/data.ts b/ability/ability_runtime/actscalldataabilitytest/entry/src/main/ets/DataAbility/data.ts new file mode 100644 index 0000000000000000000000000000000000000000..4e3f90dbb321b579784ae66dcda33198dbc7ec80 --- /dev/null +++ b/ability/ability_runtime/actscalldataabilitytest/entry/src/main/ets/DataAbility/data.ts @@ -0,0 +1,50 @@ +/** + * 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 diff --git a/ability/ability_runtime/actscalldataabilitytest/entry/src/main/ets/MainAbility/app.ets b/ability/ability_runtime/actscalldataabilitytest/entry/src/main/ets/MainAbility/app.ets new file mode 100644 index 0000000000000000000000000000000000000000..c9b470c5e030646dc074678531eec7ca122a98cc --- /dev/null +++ b/ability/ability_runtime/actscalldataabilitytest/entry/src/main/ets/MainAbility/app.ets @@ -0,0 +1,35 @@ +/** + * 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 diff --git a/ability/ability_runtime/actscalldataabilitytest/entry/src/main/ets/MainAbility/pages/index.ets b/ability/ability_runtime/actscalldataabilitytest/entry/src/main/ets/MainAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..22bb82767483c2cad8397d386cd47c9eeedb3a8c --- /dev/null +++ b/ability/ability_runtime/actscalldataabilitytest/entry/src/main/ets/MainAbility/pages/index.ets @@ -0,0 +1,46 @@ +// @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 diff --git a/ability/ability_runtime/actscalldataabilitytest/entry/src/main/ets/MainAbility/test/List.test.ets b/ability/ability_runtime/actscalldataabilitytest/entry/src/main/ets/MainAbility/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..24619881faa373aa2cdb6c3716e3a8020209b53e --- /dev/null +++ b/ability/ability_runtime/actscalldataabilitytest/entry/src/main/ets/MainAbility/test/List.test.ets @@ -0,0 +1,20 @@ +/** + * 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 diff --git a/ability/ability_runtime/actscalldataabilitytest/entry/src/main/ets/MainAbility/test/Utils.ets b/ability/ability_runtime/actscalldataabilitytest/entry/src/main/ets/MainAbility/test/Utils.ets new file mode 100644 index 0000000000000000000000000000000000000000..78a775bc36e3828f6bb4292a2effa58fd940d9f1 --- /dev/null +++ b/ability/ability_runtime/actscalldataabilitytest/entry/src/main/ets/MainAbility/test/Utils.ets @@ -0,0 +1,47 @@ +/** + * 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; + } +} + + + + diff --git a/ability/ability_runtime/actscalldataabilitytest/entry/src/main/ets/MainAbility/test/callTest.test.ets b/ability/ability_runtime/actscalldataabilitytest/entry/src/main/ets/MainAbility/test/callTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..ea9106e1ff5e6cf13469231b001d94ee221910ed --- /dev/null +++ b/ability/ability_runtime/actscalldataabilitytest/entry/src/main/ets/MainAbility/test/callTest.test.ets @@ -0,0 +1,91 @@ +// @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 diff --git a/ability/ability_runtime/actscalldataabilitytest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/ability/ability_runtime/actscalldataabilitytest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..1a4f0a7ebdd1edda79fae1ca7c5eb84881d08fc3 --- /dev/null +++ b/ability/ability_runtime/actscalldataabilitytest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,69 @@ +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 diff --git a/ability/ability_runtime/actscalldataabilitytest/entry/src/main/resources/base/element/string.json b/ability/ability_runtime/actscalldataabilitytest/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b404f7231b36547b1d28897502630b90c19772fd --- /dev/null +++ b/ability/ability_runtime/actscalldataabilitytest/entry/src/main/resources/base/element/string.json @@ -0,0 +1,44 @@ +{ + "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 diff --git a/ability/ability_runtime/actscalldataabilitytest/entry/src/main/resources/base/media/icon.png b/ability/ability_runtime/actscalldataabilitytest/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ability/ability_runtime/actscalldataabilitytest/entry/src/main/resources/base/media/icon.png differ diff --git a/ability/ability_runtime/actscalldataabilitytest/signature/openharmony_sx.p7b b/ability/ability_runtime/actscalldataabilitytest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..66b4457a8a81fb8d3356cf46d67226c850944858 Binary files /dev/null and b/ability/ability_runtime/actscalldataabilitytest/signature/openharmony_sx.p7b differ