提交 b354f160 编写于 作者: H HuangXW

ServiceClientTest测试套适配关联启动

Signed-off-by: NHuangXW <huangxinwei4@huawei.com>
Change-Id: I8ef54835fe4ad3e7a0b4259f7d2a9324a4b45784
上级 0247b0e1
......@@ -16,10 +16,6 @@ import("//test/xts/tools/build/suite.gni")
group("serviceability") {
testonly = true
if (is_standard_system) {
deps = [
"actsserviceabilityclienttest:ActsServiceAbilityClientTest",
"actsserviceabilityserverrelyhap:ActsServiceAbilityServerRelyHap",
"actsserviceabilityserversecondrelyhap:ActsServiceAbilityServerSecondRelyHap",
]
deps = [ "actsserviceabilityclienttest:ActsServiceAbilityClientTest" ]
}
}
......@@ -11,9 +11,7 @@
"kits": [
{
"test-file-name": [
"ActsServiceAbilityClientTest.hap",
"ActsServiceAbilityServerRelyHap.hap",
"ActsServiceAbilityServerSecondRelyHap.hap"
"ActsServiceAbilityClientTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
......
......@@ -63,6 +63,24 @@
"type": "page",
"visible": true,
"launchType": "standard"
},
{
"srcPath": "ServiceAbility1",
"name": ".ServiceAbility1",
"icon": "$media:icon",
"srcLanguage": "js",
"description": "$string:description_serviceability",
"visible": true,
"type": "service"
},
{
"srcPath": "ServiceAbility2",
"name": ".ServiceAbility2",
"icon": "$media:icon",
"srcLanguage": "js",
"description": "$string:description_serviceability",
"visible": true,
"type": "service"
}
],
"js": [
......
/*
* 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 rpc from "@ohos.rpc";
import particleAbility from '@ohos.ability.particleAbility'
import commonEvent from '@ohos.commonEvent'
var serversecond_bundleName = "com.amsst.stserviceabilityclient";
var serversecond_abilityName = "com.amsst.stserviceabilityclient.ServiceAbility2";
var mConnIdJs;
class StubTest extends rpc.RemoteObject {
constructor(des) {
console.info('ACTS_SerivceAbilityServer ====< des = ' + des);
if (typeof des === 'string') {
console.info('ACTS_ super');
super(des);
} else {
return null;
}
}
onRemoteRequest(code, data, reply, option) {
if (code === 1) {
console.info("ACTS_SerivceAbilityServer ====< onRemoteRequest code = 1");
let token = data.readInterfaceToken();
console.log('ACTS_SerivceAbilityServer ====< onRemoteRequest token:' + token);
let num = data.readInt();
console.log('ACTS_SerivceAbilityServer ====< onRemoteRequest num:' + num);
this.method();
num = num + 777;
reply.writeInt(num);
} else {
console.info("ACTS_SerivceAbilityServer ====< onRemoteRequest code not 1");
}
return true;
}
method() {
console.log('ACTS_SerivceAbilityServer ====< method called.')
}
}
function sleep(delay) {
let start = new Date().getTime();
while (true) {
if (new Date().getTime() - start > delay) {
break;
}
}
}
export default {
onStart(want) {
console.debug('ACTS_SerivceAbilityServer 0425 ====>onStart .ts 0851 ='
+ want + " , JSON." + JSON.stringify(want));
commonEvent.publish("ACTS_SerivceAbilityServer_onStart", (err) => { });
},
onStop() {
console.debug('ACTS_SerivceAbilityServer ====<onStop');
commonEvent.publish("ACTS_SerivceAbilityServer_onStop", (err) => { });
},
onCommand(want, restart, startId) {
console.debug('ACTS_SerivceAbilityServer ====>onCommand='
+ "JSON(want)=" + JSON.stringify(want)
+ " ,restart=" + restart + " ,startId=" + startId);
if (want.action == 'ServiceStartService_0900') {
particleAbility.startAbility(
{
want:
{
bundleName: serversecond_bundleName,
abilityName: serversecond_abilityName,
action: "ServiceStartService_0900",
},
}
);
sleep(600)
} else if (want.action == 'ServiceStartService_1000') {
particleAbility.startAbility(
{
want:
{
bundleName: serversecond_bundleName,
abilityName: serversecond_abilityName,
action: "ServiceStartService_1000",
},
}, (err, data) => {
console.debug('ACTS_SerivceAbilityServer start Ability 1000 callback====='
+ err + ', data= ' + data + " , JSON." + JSON.stringify(data));
}
);
} else {
commonEvent.publish("ACTS_SerivceAbilityServer_onCommand" + "_" + want.action, (err) => {
if (!err.code) {
if (want.action == 'PageStartService_0100' || want.action == 'PageStartService_0200'
|| want.action == 'PageStartService_0301' || want.action == 'PageStartService_0401') {
console.debug('ACTS_SerivceAbilityServer_onCommand 100 200 301 401.=====>'
+ want.action);
}
} else {
console.debug('ACTS_SerivceAbilityServer_onCommand publish err=====>' + err);
}
});
}
},
onConnect(want) {
console.info('ACTS_SerivceAbilityServer ====< onConnect');
try {
console.debug('ACTS_SerivceAbilityServer ====>onConnect='
+ want + " , JSON." + JSON.stringify(want));
commonEvent.publish("ACTS_SerivceAbilityServer_onConnect" + "_" + want.action, (err) => { });
function onConnectCallback(element, remote) {
console.debug('ACTS_SerivceAbilityServer_onConnectCallback ====> mConnIdJs='
+ JSON.stringify(mConnIdJs) + " , " + mConnIdJs);
console.debug('ACTS_SerivceAbilityServer_onConnectCallback ====> element='
+ JSON.stringify(element) + " , " + element);
console.debug('ACTS_SerivceAbilityServer_onConnectCallback ====> remote='
+ JSON.stringify(remote) + " , " + remote);
}
function onDisconnectCallback(element) {
console.debug('ACTS_SerivceAbilityServer_onDisconnectCallback ====> element='
+ JSON.stringify(element) + " , " + element);
}
function onFailedCallback(code) {
console.debug('ACTS_SerivceAbilityServer_onFailedCallback ====> code='
+ JSON.stringify(code) + " , " + code)
}
if (want.action == 'ServiceConnectService_1300' || want.action == 'ServiceConnectService_1400'
|| want.action == 'ServiceConnectService_1500' || want.action == 'ServiceConnectService_1600') {
mConnIdJs = particleAbility.connectAbility(
{
bundleName: serversecond_bundleName,
abilityName: serversecond_abilityName,
action: want.action,
},
{
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback,
onFailed: onFailedCallback,
},
)
}
} catch (err) {
console.log("ACTS_SerivceAbilityServer ====< error:" + err)
}
console.info('ACTS_SerivceAbilityServer ====< onConnect end');
return new StubTest("connect-test");
},
onDisconnect(want) {
console.debug('ACTS_SerivceAbilityServer ====>onDisConnect='
+ want + " , JSON." + JSON.stringify(want));
commonEvent.publish("ACTS_SerivceAbilityServer_onDisConnect_" + want.action, (err) => {
console.debug('ACTS_SerivceAbilityServer_onDisConnect ===' + want.action);
});
if (want.action == 'ServiceConnectService_1300' || want.action == 'ServiceConnectService_1400'
|| want.action == 'ServiceConnectService_1500' || want.action == 'ServiceConnectService_1501'
|| want.action == 'ServiceConnectService_1600' || want.action == 'ServiceConnectService_1601'
) {
particleAbility.disconnectAbility(mConnIdJs, (err) => {
console.debug("=ACTS_SerivceAbilityServer_onDisConnect 13 14 15 16 err====>"
+ ("json err=") + JSON.stringify(err) + " , " + want.action);
})
}
},
onReady() {
console.debug('ACTS_SerivceAbilityServer ====<onReady');
},
onReconnect(want) {
console.debug('ACTS_SerivceAbilityServer ====>onReconnect='
+ want + " , JSON." + JSON.stringify(want));
commonEvent.publish("ACTS_SerivceAbilityServer_onReconnect" + "_" + want.action, (err) => { });
},
OnAbilityConnectDone(element, remoteObject, resultCode) {
console.debug('ACTS_SerivceAbilityServer ====>OnAbilityConnectDone='
+ element + " , JSON." + JSON.stringify(element)
+ remoteObject + " , JSON." + JSON.stringify(remoteObject)
+ resultCode + " , JSON." + JSON.stringify(resultCode)
);
commonEvent.publish("ACTS_SerivceAbilityServer_OnAbilityConnectDone", (err) => { });
},
};
/*
* 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 rpc from "@ohos.rpc";
import particleAbility from '@ohos.ability.particleAbility'
import commonEvent from '@ohos.commonEvent'
var server_bundleName = "com.amsst.stserviceabilityclient";
var server_abilityName = "com.amsst.stserviceabilityclient.ServiceAbility1";
var mConnIdJs;
class StubTest extends rpc.RemoteObject {
constructor(des) {
console.info('ACTS_SerivceAbilityServerSecond ====< des = ' + des);
if (typeof des === 'string') {
console.info('ACTS_ super');
super(des);
} else {
return null;
}
}
onRemoteRequest(code, data, reply, option) {
if (code === 1) {
console.info("ACTS_SerivceAbilityServerSecond ====< onRemoteRequest code = 1");
let token = data.readInterfaceToken();
console.log('ACTS_SerivceAbilityServerSecond ====< onRemoteRequest token:' + token);
let num = data.readInt();
console.log('ACTS_SerivceAbilityServerSecond ====< onRemoteRequest num:' + num);
this.method();
num = num + 777;
reply.writeInt(num);
} else {
console.info("ACTS_SerivceAbilityServerSecond ====< onRemoteRequest code not 1");
}
return true;
}
method() {
console.log('ACTS_SerivceAbilityServerSecond ====< method called.')
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
export default {
onStart(want) {
console.debug('ACTS_SerivceAbilityServerSecond ====>onStart='
+ want + " , JSON." + JSON.stringify(want));
commonEvent.publish("ACTS_SerivceAbilityServerSecond_onStart", (err) => { });
},
onStop() {
console.debug('ACTS_SerivceAbilityServerSecond ====<onStop');
commonEvent.publish("ACTS_SerivceAbilityServerSecond_onStop", (err) => { });
},
onCommand(want, restart, startId) {
console.debug('ACTS_SerivceAbilityServerSecond ====>onCommand='
+ "JSON(want)=" + JSON.stringify(want)
+ " ,restart=" + restart + " ,startId=" + startId);
commonEvent.publish("ACTS_SerivceAbilityServerSecond_onCommand" + "_" + want.action, (err) => {
console.debug("ACTS_SerivceAbilityServerSecond_onCommand" + "_" + want.action +
"err: " + JSON.stringify(err))
});
sleep(500)
},
onConnect(want) {
console.info('ACTS_SerivceAbilityServerSecond ====< onConnect');
try {
console.debug('ACTS_SerivceAbilityServerSecond ====>onConnect='
+ want + " , JSON." + JSON.stringify(want));
function onConnectCallback(element, remote) {
console.debug('ACTS_SerivceAbilityServerSecond_onConnectCallback ====> want.action='
+ JSON.stringify(want.action) + " , " + want.action);
console.debug('ACTS_SerivceAbilityServerSecond_onConnectCallback ====> element='
+ JSON.stringify(element) + " , " + element);
console.debug('ACTS_SerivceAbilityServerSecond_onConnectCallback ====> remote='
+ JSON.stringify(remote) + " , " + remote);
if (want.action == 'ServiceConnectService_1500' || want.action == 'ServiceConnectService_1600') {
commonEvent.publish("ACTS_SerivceAbilityServerSecond_onConnect" + "_" + want.action, (err) => {
console.debug("publish = ACTS_SerivceAbilityServerSecond_onConnect" + "_" + want.action);
});
}
}
function onDisconnectCallback(element) {
console.debug('ACTS_SerivceAbilityServerSecond_onDisconnectCallback ====> element='
+ JSON.stringify(element) + " , " + element);
}
function onFailedCallback(code) {
console.debug('ACTS_SerivceAbilityServerSecond_onFailedCallback ====> code='
+ JSON.stringify(code) + " , " + code)
}
if (want.action == 'ServiceConnectService_1500') {
mConnIdJs = particleAbility.connectAbility(
{
bundleName: server_bundleName,
abilityName: server_abilityName,
action: "ServiceConnectService_1501",
},
{
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback,
onFailed: onFailedCallback,
},
)
} else if (want.action == 'ServiceConnectService_1600') {
mConnIdJs = particleAbility.connectAbility(
{
bundleName: server_bundleName,
abilityName: server_abilityName,
action: "ServiceConnectService_1601",
},
{
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback,
onFailed: onFailedCallback,
},
)
} else if (want.action == 'ServiceConnectService_1590') {
mConnIdJs = particleAbility.connectAbility(
{
bundleName: server_bundleName,
abilityName: server_abilityName,
action: "ServiceConnectService_1591",
},
{
onConnect: onConnectCallback,
onDisconnect: onDisconnectCallback,
onFailed: onFailedCallback,
},
)
} else {
commonEvent.publish("ACTS_SerivceAbilityServerSecond_onConnect" + "_" + want.action, (err) => { });
}
} catch (err) {
console.log("ACTS_SerivceAbilityServerSecond ====< error:" + err)
}
console.info('ACTS_SerivceAbilityServerSecond ====< onConnect end');
return new StubTest("connect-test");
},
onDisconnect(want) {
console.debug('ACTS_SerivceAbilityServerSecond ====>onDisConnect='
+ want + " , JSON." + JSON.stringify(want));
commonEvent.publish("ACTS_SerivceAbilityServerSecond_onDisConnect_" + want.action, (err) => {
if (err.code) {
console.debug('ACTS_SerivceAbilityServerSecond_onDisConnect publish err=====>' + err);
} else {
console.debug('ACTS_SerivceAbilityServerSecond_onDisConnect =====<'
+ want.action);
if (want.action == 'ServiceConnectService_1500' || want.action == 'ServiceConnectService_1501'
|| want.action == 'ServiceConnectService_1600' || want.action == 'ServiceConnectService_1601'
|| want.action == 'ServiceConnectService_1590') {
particleAbility.disconnectAbility(mConnIdJs, (err) => {
console.debug("=ACTS_SerivceAbilityServerSecond_onDisConnect err====>"
+ ("json err=") + JSON.stringify(err) + " , " + want.action);
})
}
}
});
},
onReady() {
console.debug('ACTS_SerivceAbilityServerSecond ====<onReady');
},
onReconnect(want) {
console.debug('ACTS_SerivceAbilityServerSecond ====>onReconnect='
+ want + " , JSON." + JSON.stringify(want));
},
OnAbilityConnectDone(element, remoteObject, resultCode) {
console.debug('ACTS_SerivceAbilityServerSecond ====>OnAbilityConnectDone='
+ element + " , JSON." + JSON.stringify(element)
+ remoteObject + " , JSON." + JSON.stringify(remoteObject)
+ resultCode + " , JSON." + JSON.stringify(resultCode)
);
commonEvent.publish("ACTS_SerivceAbilityServerSecond_OnAbilityConnectDone", (err) => { });
},
};
......@@ -19,8 +19,8 @@ import rpc from "@ohos.rpc";
import { describe, afterEach, it, expect } from '@ohos/hypium'
export default function ActsStServiceAbilityTest() {
describe('ActsStServiceAbilityTest', function () {
let bundleName = "com.amsst.stserviceabilityserver";
let abilityName = "com.amsst.stserviceabilityserver.ServiceAbility";
let bundleName = "com.amsst.stserviceabilityclient";
let abilityName = "com.amsst.stserviceabilityclient.ServiceAbility1";
let subscriber0100;
let CommonEventSubscribeInfo0100 = {
......
......@@ -23,6 +23,10 @@
{
"name": "TestAbility_label",
"value": "label"
},
{
"name": "description_serviceability",
"value": "hap sample empty service"
}
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册