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

!5570 ActsServiceAbilityClientTest测试套用例优化

Merge pull request !5570 from chengxingzhen/cherry-pick-1663732072
...@@ -15,72 +15,72 @@ ...@@ -15,72 +15,72 @@
import featureAbility from '@ohos.ability.featureAbility' import featureAbility from '@ohos.ability.featureAbility'
import commonEvent from '@ohos.commonEvent' import commonEvent from '@ohos.commonEvent'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' import { describe, afterEach, it, expect } from '@ohos/hypium'
export default function ActsStServiceAbilityTest() { export default function ActsStServiceAbilityTest() {
describe('ActsStServiceAbilityTest', function () { describe('ActsStServiceAbilityTest', function () {
let bundleName = "com.amsst.stserviceabilityserver"; let bundleName = "com.amsst.stserviceabilityserver";
let abilityName = "com.amsst.stserviceabilityserver.ServiceAbility"; let abilityName = "com.amsst.stserviceabilityserver.ServiceAbility";
var subscriber0100; let subscriber0100;
var CommonEventSubscribeInfo0100 = { let CommonEventSubscribeInfo0100 = {
events: ["ACTS_SerivceAbilityServer_onCommand_PageStartService_0100", events: ["ACTS_SerivceAbilityServer_onCommand_PageStartService_0100",
], ],
}; };
var subscriber0200; let subscriber0200;
var CommonEventSubscribeInfo0200 = { let CommonEventSubscribeInfo0200 = {
events: ["ACTS_SerivceAbilityServer_onCommand_PageStartService_0200", events: ["ACTS_SerivceAbilityServer_onCommand_PageStartService_0200",
], ],
}; };
var subscriber0300; let subscriber0300;
var CommonEventSubscribeInfo0300 = { let CommonEventSubscribeInfo0300 = {
events: ["ACTS_SerivceAbilityServer_onCommand_PageStartService_0300", events: ["ACTS_SerivceAbilityServer_onCommand_PageStartService_0300",
"ACTS_SerivceAbilityServer_onCommand_PageStartService_0301", "ACTS_SerivceAbilityServer_onCommand_PageStartService_0301",
], ],
}; };
var subscriber0400; let subscriber0400;
var CommonEventSubscribeInfo0400 = { let CommonEventSubscribeInfo0400 = {
events: ["ACTS_SerivceAbilityServer_onCommand_PageStartService_0400", events: ["ACTS_SerivceAbilityServer_onCommand_PageStartService_0400",
"ACTS_SerivceAbilityServer_onCommand_PageStartService_0401", "ACTS_SerivceAbilityServer_onCommand_PageStartService_0401",
], ],
}; };
var subscriber0500; let subscriber0500;
var CommonEventSubscribeInfo0500 = { let CommonEventSubscribeInfo0500 = {
events: ["ACTS_SerivceAbilityServer_onConnect_PageConnectService_0500", events: ["ACTS_SerivceAbilityServer_onConnect_PageConnectService_0500",
"ACTS_SerivceAbilityServer_onDisConnect", "ACTS_SerivceAbilityServer_onDisConnect_PageConnectService_0500",
], ],
}; };
var subscriber0600; let subscriber0600;
var CommonEventSubscribeInfo0600 = { let CommonEventSubscribeInfo0600 = {
events: ["ACTS_SerivceAbilityServer_onConnect_PageConnectService_0600", events: ["ACTS_SerivceAbilityServer_onConnect_PageConnectService_0600",
"ACTS_SerivceAbilityServer_onDisConnect", "ACTS_SerivceAbilityServer_onDisConnect_PageConnectService_0600",
], ],
}; };
var subscriber0900; let subscriber0900;
var CommonEventSubscribeInfo0900 = { let CommonEventSubscribeInfo0900 = {
events: ["ACTS_SerivceAbilityServerSecond_onCommand_ServiceStartService_0900", events: ["ACTS_SerivceAbilityServerSecond_onCommand_ServiceStartService_0900",
], ],
}; };
var subscriber1000; let subscriber1000;
var CommonEventSubscribeInfo1000 = { let CommonEventSubscribeInfo1000 = {
events: ["ACTS_SerivceAbilityServerSecond_onCommand_ServiceStartService_1000", events: ["ACTS_SerivceAbilityServerSecond_onCommand_ServiceStartService_1000",
], ],
}; };
var subscriber1300; let subscriber1300;
var CommonEventSubscribeInfo1300 = { let CommonEventSubscribeInfo1300 = {
events: ["ACTS_SerivceAbilityServerSecond_onConnect_ServiceConnectService_1300", events: ["ACTS_SerivceAbilityServerSecond_onConnect_ServiceConnectService_1300",
"ACTS_SerivceAbilityServerSecond_onDisConnect", "ACTS_SerivceAbilityServerSecond_onDisConnect_ServiceConnectService_1300",
], ],
}; };
var subscriber1400; let subscriber1400;
var CommonEventSubscribeInfo1400 = { let CommonEventSubscribeInfo1400 = {
events: ["ACTS_SerivceAbilityServerSecond_onConnect_ServiceConnectService_1400", events: ["ACTS_SerivceAbilityServerSecond_onConnect_ServiceConnectService_1400",
"ACTS_SerivceAbilityServerSecond_onDisConnect", "ACTS_SerivceAbilityServerSecond_onDisConnect_ServiceConnectService_1400",
], ],
}; };
var subscriber1500; let subscriber1500;
var CommonEventSubscribeInfo1500 = { let CommonEventSubscribeInfo1500 = {
events: ["ACTS_SerivceAbilityServerSecond_onConnect_ServiceConnectService_1500", events: ["ACTS_SerivceAbilityServerSecond_onConnect_ServiceConnectService_1500",
"ACTS_SerivceAbilityServer_onDisConnect", "ACTS_SerivceAbilityServer_onDisConnect_ServiceConnectService_1500",
], ],
}; };
...@@ -96,30 +96,12 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -96,30 +96,12 @@ describe('ActsStServiceAbilityTest', function () {
function sleep(ms) { function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms)); return new Promise(resolve => setTimeout(resolve, ms));
} }
let gSetTimeout = 1000 let gSetTimeout = 2000
beforeAll(async (done) => {
console.debug('= ACTS_beforeAll ====<begin');
console.debug('= ACTS_beforeAll ====<end');
done();
})
beforeEach(async (done) => {
setTimeout(function () {
done();
}, gSetTimeout);
})
afterEach(async (done) => { afterEach(async (done) => {
setTimeout(function () { setTimeout(function () {
done(); done();
}, gSetTimeout); }, gSetTimeout);
}) })
afterAll((done) => {
console.debug('= ACTS_afterAll ====<begin');
setTimeout(function () {
console.debug('= ACTS_afterAll ====<end');
featureAbility.terminateSelf();
done();
}, gSetTimeout);
})
/* /*
* @tc.number: ACTS_JsServiceAbility_0100 * @tc.number: ACTS_JsServiceAbility_0100
...@@ -129,12 +111,12 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -129,12 +111,12 @@ describe('ActsStServiceAbilityTest', function () {
it('ACTS_JsServiceAbility_0100', 0, async function (done) { it('ACTS_JsServiceAbility_0100', 0, async function (done) {
console.debug('ACTS_JsServiceAbility_0100====<begin'); console.debug('ACTS_JsServiceAbility_0100====<begin');
try { try {
await commonEvent.createSubscriber(CommonEventSubscribeInfo0100).then(async (data) => { await commonEvent.createSubscriber(CommonEventSubscribeInfo0100).then((data) => {
console.debug("=ACTS_JsServiceAbility_0100 createSubscriber .then(data)=======>" console.debug("=ACTS_JsServiceAbility_0100 createSubscriber .then(data)=======>"
+ ("json data【") + JSON.stringify(data) + ("") + ("json data【") + JSON.stringify(data) + ("")
+ " ,data=" + data); + " ,data=" + data);
subscriber0100 = data; subscriber0100 = data;
commonEvent.subscribe(subscriber0100, async (err, data) => { commonEvent.subscribe(subscriber0100, (err, data) => {
console.debug("=ACTS_JsServiceAbility_0100 subscribe (err,data)=======>" console.debug("=ACTS_JsServiceAbility_0100 subscribe (err,data)=======>"
+ ("json err【") + JSON.stringify(err) + ("") + ("json err【") + JSON.stringify(err) + ("")
+ ("json data【") + JSON.stringify(data) + ("") + ("json data【") + JSON.stringify(data) + ("")
...@@ -161,12 +143,12 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -161,12 +143,12 @@ describe('ActsStServiceAbilityTest', function () {
+ " ,data=" + data); + " ,data=" + data);
}).catch(err => { }).catch(err => {
expect(".catch").assertEqual(err); expect(".catch").assertEqual(err);
console.debug('ACTS_JsServiceAbility_0100====<end .catch(err):'+ JSON.stringify(err)); console.debug('ACTS_JsServiceAbility_0100====<end .catch(err):' + JSON.stringify(err));
done(); done();
}) })
} catch (err) { } catch (err) {
expect("catch").assertEqual(err); expect().assertFail()
console.debug('ACTS_JsServiceAbility_0100====<end catch(err)'); console.debug('ACTS_JsServiceAbility_0100==== err: ' + JSON.stringify(err));
done(); done();
} }
}) })
...@@ -179,12 +161,12 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -179,12 +161,12 @@ describe('ActsStServiceAbilityTest', function () {
it('ACTS_JsServiceAbility_0200', 0, async function (done) { it('ACTS_JsServiceAbility_0200', 0, async function (done) {
console.debug('ACTS_JsServiceAbility_0200====<begin'); console.debug('ACTS_JsServiceAbility_0200====<begin');
try { try {
await commonEvent.createSubscriber(CommonEventSubscribeInfo0200).then(async (data) => { await commonEvent.createSubscriber(CommonEventSubscribeInfo0200).then((data) => {
console.debug("=ACTS_JsServiceAbility_0200 createSubscriber .then(data)=======>" console.debug("=ACTS_JsServiceAbility_0200 createSubscriber .then(data)=======>"
+ ("json data【") + JSON.stringify(data) + ("") + ("json data【") + JSON.stringify(data) + ("")
+ " ,data=" + data); + " ,data=" + data);
subscriber0200 = data; subscriber0200 = data;
commonEvent.subscribe(subscriber0200, async (err, data) => { commonEvent.subscribe(subscriber0200, (err, data) => {
console.debug("=ACTS_JsServiceAbility_0200 subscribe (err,data)=======>" console.debug("=ACTS_JsServiceAbility_0200 subscribe (err,data)=======>"
+ ("json err【") + JSON.stringify(err) + ("") + ("json err【") + JSON.stringify(err) + ("")
+ ("json data【") + JSON.stringify(data) + ("") + ("json data【") + JSON.stringify(data) + ("")
...@@ -212,8 +194,8 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -212,8 +194,8 @@ describe('ActsStServiceAbilityTest', function () {
} }
) )
} catch (err) { } catch (err) {
expect("catch").assertEqual(err); expect().assertFail()
console.debug('ACTS_JsServiceAbility_0200====<end catch(err)'); console.debug('ACTS_JsServiceAbility_0200==== err: ' + JSON.stringify(err));
done(); done();
} }
}) })
...@@ -226,12 +208,12 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -226,12 +208,12 @@ describe('ActsStServiceAbilityTest', function () {
it('ACTS_JsServiceAbility_0300', 0, async function (done) { it('ACTS_JsServiceAbility_0300', 0, async function (done) {
console.debug('ACTS_JsServiceAbility_0300====<begin'); console.debug('ACTS_JsServiceAbility_0300====<begin');
try { try {
await commonEvent.createSubscriber(CommonEventSubscribeInfo0300).then(async (data) => { await commonEvent.createSubscriber(CommonEventSubscribeInfo0300).then((data) => {
console.debug("=ACTS_JsServiceAbility_0300 createSubscriber .then(data)=======>" console.debug("=ACTS_JsServiceAbility_0300 createSubscriber .then(data)=======>"
+ ("json data【") + JSON.stringify(data) + ("") + ("json data【") + JSON.stringify(data) + ("")
+ " ,data=" + data); + " ,data=" + data);
subscriber0300 = data; subscriber0300 = data;
commonEvent.subscribe(subscriber0300, async (err, data) => { commonEvent.subscribe(subscriber0300, (err, data) => {
console.debug("=ACTS_JsServiceAbility_0300 subscribe (err,data)=======>" console.debug("=ACTS_JsServiceAbility_0300 subscribe (err,data)=======>"
+ ("json err【") + JSON.stringify(err) + ("") + ("json err【") + JSON.stringify(err) + ("")
+ ("json data【") + JSON.stringify(data) + ("") + ("json data【") + JSON.stringify(data) + ("")
...@@ -253,8 +235,8 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -253,8 +235,8 @@ describe('ActsStServiceAbilityTest', function () {
+ ("json data【") + JSON.stringify(data) + ("") + ("json data【") + JSON.stringify(data) + ("")
+ " ,data=" + data); + " ,data=" + data);
}).catch(err => { }).catch(err => {
expect(".catch").assertEqual(err); expect().assertFail()
console.debug('ACTS_JsServiceAbility_0300====<end .catch(err) 2'); console.debug('ACTS_JsServiceAbility_0300==== err: ' + JSON.stringify(err));
done(); done();
}) })
} else { } else {
...@@ -285,8 +267,8 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -285,8 +267,8 @@ describe('ActsStServiceAbilityTest', function () {
done(); done();
}) })
} catch (err) { } catch (err) {
expect("catch").assertEqual(err); expect().assertFail()
console.debug('ACTS_JsServiceAbility_0300====<end catch(err)'); console.debug('ACTS_JsServiceAbility_0300==== err: ' + JSON.stringify(err));
done(); done();
} }
}) })
...@@ -299,12 +281,12 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -299,12 +281,12 @@ describe('ActsStServiceAbilityTest', function () {
it('ACTS_JsServiceAbility_0400', 0, async function (done) { it('ACTS_JsServiceAbility_0400', 0, async function (done) {
console.debug('ACTS_JsServiceAbility_0400====<begin'); console.debug('ACTS_JsServiceAbility_0400====<begin');
try { try {
await commonEvent.createSubscriber(CommonEventSubscribeInfo0400).then(async (data) => { await commonEvent.createSubscriber(CommonEventSubscribeInfo0400).then((data) => {
console.debug("=ACTS_JsServiceAbility_0400 createSubscriber .then(data)=======>" console.debug("=ACTS_JsServiceAbility_0400 createSubscriber .then(data)=======>"
+ ("json data【") + JSON.stringify(data) + ("") + ("json data【") + JSON.stringify(data) + ("")
+ " ,data=" + data); + " ,data=" + data);
subscriber0400 = data; subscriber0400 = data;
commonEvent.subscribe(subscriber0400, async (err, data) => { commonEvent.subscribe(subscriber0400, (err, data) => {
console.debug("=ACTS_JsServiceAbility_0400 subscribe (err,data)=======>" console.debug("=ACTS_JsServiceAbility_0400 subscribe (err,data)=======>"
+ ("json err【") + JSON.stringify(err) + ("") + ("json err【") + JSON.stringify(err) + ("")
+ ("json data【") + JSON.stringify(data) + ("") + ("json data【") + JSON.stringify(data) + ("")
...@@ -352,8 +334,8 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -352,8 +334,8 @@ describe('ActsStServiceAbilityTest', function () {
} }
) )
} catch (err) { } catch (err) {
expect("catch").assertEqual(err); expect().assertFail()
console.debug('ACTS_JsServiceAbility_0400====<end catch(err)'); console.debug('ACTS_JsServiceAbility_0400==== err: ' + JSON.stringify(err));
done(); done();
} }
}) })
...@@ -366,28 +348,30 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -366,28 +348,30 @@ describe('ActsStServiceAbilityTest', function () {
it('ACTS_JsServiceAbility_0500', 0, async function (done) { it('ACTS_JsServiceAbility_0500', 0, async function (done) {
console.log('ACTS_JsServiceAbility_0500====<begin'); console.log('ACTS_JsServiceAbility_0500====<begin');
try { try {
var mConnIdJsPromise; let mConnIdJsPromise;
await commonEvent.createSubscriber(CommonEventSubscribeInfo0500).then(async (data) => { await commonEvent.createSubscriber(CommonEventSubscribeInfo0500).then((data) => {
console.debug("=ACTS_JsServiceAbility_0500 createSubscriber .then(data)=======>" console.debug("=ACTS_JsServiceAbility_0500 createSubscriber .then(data)=======>"
+ ("json data【") + JSON.stringify(data) + ("") + ("json data【") + JSON.stringify(data) + ("")
+ " ,data=" + data); + " ,data=" + data);
subscriber0500 = data; subscriber0500 = data;
commonEvent.subscribe(subscriber0500, async (err, data) => { commonEvent.subscribe(subscriber0500, (err, data) => {
console.debug("=ACTS_JsServiceAbility_0500 subscribe (err,data)=======>" console.debug("=ACTS_JsServiceAbility_0500 subscribe (err,data)=======>"
+ ("json err【") + JSON.stringify(err) + ("") + ("json err【") + JSON.stringify(err) + ("")
+ ("json data【") + JSON.stringify(data) + ("") + ("json data【") + JSON.stringify(data) + ("")
+ " ,err=" + err + " ,data=" + data); + " ,err=" + err + " ,data=" + data);
if (data.event != "ACTS_SerivceAbilityServer_onDisConnect") { if (data.event == "ACTS_SerivceAbilityServer_onConnect_PageConnectService_0500") {
expect("ACTS_SerivceAbilityServer_onConnect_PageConnectService_0500").assertEqual( console.info("ACTS_JsServiceAbility_0500 disconnnectAbility start")
data.event); featureAbility.disconnectAbility(mConnIdJsPromise).then((err) => {
featureAbility.disconnectAbility(mConnIdJsPromise).then(() => { console.debug("=ACTS_JsServiceAbility_0500 disconnectAbility err====>"
+ ("json err=") + JSON.stringify(err));
}).catch(err => { }).catch(err => {
expect(".catch").assertEqual(err); expect().assertFail()
console.debug('ACTS_JsServiceAbility_0500====<end .catch(err)'); console.debug('ACTS_JsServiceAbility_0500==== err: ' + JSON.stringify(err));
done(); done()
}) })
} else { } else {
expect("ACTS_SerivceAbilityServer_onDisConnect").assertEqual(data.event); expect("ACTS_SerivceAbilityServer_onDisConnect_PageConnectService_0500")
.assertEqual(data.event);
unsubscribe("ACTS_JsServiceAbility_0500_unsubscribe", subscriber0500); unsubscribe("ACTS_JsServiceAbility_0500_unsubscribe", subscriber0500);
console.debug('ACTS_JsServiceAbility_0500====<end'); console.debug('ACTS_JsServiceAbility_0500====<end');
done(); done();
...@@ -428,8 +412,8 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -428,8 +412,8 @@ describe('ActsStServiceAbilityTest', function () {
}, },
) )
} catch (err) { } catch (err) {
expect("catch").assertEqual(err); expect().assertFail()
console.log('ACTS_JsServiceAbility_0500====<end err') console.log('ACTS_JsServiceAbility_0500==== err: ' + JSON.stringify(err))
done(); done();
} }
}) })
...@@ -442,34 +426,25 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -442,34 +426,25 @@ describe('ActsStServiceAbilityTest', function () {
it('ACTS_JsServiceAbility_0600', 0, async function (done) { it('ACTS_JsServiceAbility_0600', 0, async function (done) {
console.log('ACTS_JsServiceAbility_0600====<begin'); console.log('ACTS_JsServiceAbility_0600====<begin');
try { try {
var currentAlertTimeout; let mConnIdJsAsyncCallback;
var mConnIdJsAsyncCallback; await commonEvent.createSubscriber(CommonEventSubscribeInfo0600).then((data) => {
await commonEvent.createSubscriber(CommonEventSubscribeInfo0600).then(async (data) => {
console.debug("=ACTS_JsServiceAbility_0600 createSubscriber .then(data)=======>" console.debug("=ACTS_JsServiceAbility_0600 createSubscriber .then(data)=======>"
+ ("json data【") + JSON.stringify(data) + ("") + ("json data【") + JSON.stringify(data) + ("")
+ " ,data=" + data); + " ,data=" + data);
subscriber0600 = data; subscriber0600 = data;
commonEvent.subscribe(subscriber0600, async (err, data) => { commonEvent.subscribe(subscriber0600, (err, data) => {
console.debug("=ACTS_JsServiceAbility_0600 subscribe (err,data)=======>" console.debug("=ACTS_JsServiceAbility_0600 subscribe (err,data)=======>"
+ ("json err【") + JSON.stringify(err) + ("") + ("json err【") + JSON.stringify(err) + ("")
+ ("json data【") + JSON.stringify(data) + ("") + ("json data【") + JSON.stringify(data) + ("")
+ " ,err=" + err + " ,data=" + data); + " ,err=" + err + " ,data=" + data);
if (data.event != "ACTS_SerivceAbilityServer_onDisConnect") { if (data.event == "ACTS_SerivceAbilityServer_onConnect_PageConnectService_0600") {
expect("ACTS_SerivceAbilityServer_onConnect_PageConnectService_0600").assertEqual(
data.event);
featureAbility.disconnectAbility(mConnIdJsAsyncCallback, (err) => { featureAbility.disconnectAbility(mConnIdJsAsyncCallback, (err) => {
console.debug("=ACTS_JsServiceAbility_0600 disconnectAbility err====>" console.debug("=ACTS_JsServiceAbility_0600 disconnectAbility err====>"
+ ("json err=") + JSON.stringify(err)); + ("json err=") + JSON.stringify(err));
}) })
currentAlertTimeout = setTimeout(() => {
console.log('ACTS_JsServiceAbility_0600====<end steTimeout')
unsubscribe("ACTS_JsServiceAbility_0600_unsubscribe", subscriber0600);
done();
}, gSetTimeout);
} else { } else {
clearTimeout(currentAlertTimeout); expect("ACTS_SerivceAbilityServer_onDisConnect_PageConnectService_0600")
expect("ACTS_SerivceAbilityServer_onDisConnect").assertEqual( .assertEqual(data.event);
data.event);
unsubscribe("ACTS_JsServiceAbility_0600_unsubscribe", subscriber0600); unsubscribe("ACTS_JsServiceAbility_0600_unsubscribe", subscriber0600);
console.log('ACTS_JsServiceAbility_0600====<end') console.log('ACTS_JsServiceAbility_0600====<end')
done(); done();
...@@ -495,10 +470,10 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -495,10 +470,10 @@ describe('ActsStServiceAbilityTest', function () {
function onFailedCallback(code) { function onFailedCallback(code) {
console.debug('ACTS_JsServiceAbility_0600_onFailedCallback ====> code=' console.debug('ACTS_JsServiceAbility_0600_onFailedCallback ====> code='
+ JSON.stringify(code) + " , " + code) + JSON.stringify(code) + " , " + code)
expect(code==featureAbility.ErrorCode.ABILITY_NOT_FOUND expect(code == featureAbility.ErrorCode.ABILITY_NOT_FOUND
|| (code!=featureAbility.ErrorCode.NO_ERROR || (code != featureAbility.ErrorCode.NO_ERROR
|| code!=featureAbility.ErrorCode.INVALID_PARAMETER || code != featureAbility.ErrorCode.INVALID_PARAMETER
|| code!=featureAbility.ErrorCode.PERMISSION_DENY || code != featureAbility.ErrorCode.PERMISSION_DENY
)).assertTrue(); )).assertTrue();
} }
...@@ -515,8 +490,8 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -515,8 +490,8 @@ describe('ActsStServiceAbilityTest', function () {
}, },
) )
} catch (err) { } catch (err) {
expect("catch").assertEqual(err); expect().assertFail()
console.log('ACTS_JsServiceAbility_0600====<end err') console.log('ACTS_JsServiceAbility_0600==== err: ' + JSON.stringify(err))
done(); done();
} }
}) })
...@@ -529,19 +504,18 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -529,19 +504,18 @@ describe('ActsStServiceAbilityTest', function () {
it('ACTS_JsServiceAbility_0900', 0, async function (done) { it('ACTS_JsServiceAbility_0900', 0, async function (done) {
console.debug('ACTS_JsServiceAbility_0900====<begin'); console.debug('ACTS_JsServiceAbility_0900====<begin');
try { try {
await commonEvent.createSubscriber(CommonEventSubscribeInfo0900).then(async (data) => { await commonEvent.createSubscriber(CommonEventSubscribeInfo0900).then((data) => {
console.debug("=ACTS_JsServiceAbility_0900 createSubscriber .then(data)=======>" console.debug("=ACTS_JsServiceAbility_0900 createSubscriber .then(data)=======>"
+ ("json data【") + JSON.stringify(data) + ("") + ("json data【") + JSON.stringify(data) + ("")
+ " ,data=" + data); + " ,data=" + data);
subscriber0900 = data; subscriber0900 = data;
commonEvent.subscribe(subscriber0900, async (err, data) => { commonEvent.subscribe(subscriber0900, (err, data) => {
console.debug("=ACTS_JsServiceAbility_0900 subscribe (err,data)=======>" console.debug("=ACTS_JsServiceAbility_0900 subscribe (err,data)=======>"
+ ("json err【") + JSON.stringify(err) + ("") + ("json err【") + JSON.stringify(err) + ("")
+ ("json data【") + JSON.stringify(data) + ("") + ("json data【") + JSON.stringify(data) + ("")
+ " ,err=" + err + " ,data=" + data); + " ,err=" + err + " ,data=" + data);
expect("ACTS_SerivceAbilityServerSecond_onCommand_ServiceStartService_0900").assertEqual( expect("ACTS_SerivceAbilityServerSecond_onCommand_ServiceStartService_0900").assertEqual(
data.event); data.event);
await sleep(1000)
unsubscribe("ACTS_JsServiceAbility_0900_unsubscribe", subscriber0900); unsubscribe("ACTS_JsServiceAbility_0900_unsubscribe", subscriber0900);
console.debug('ACTS_JsServiceAbility_0900====<end'); console.debug('ACTS_JsServiceAbility_0900====<end');
done(); done();
...@@ -567,8 +541,8 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -567,8 +541,8 @@ describe('ActsStServiceAbilityTest', function () {
done(); done();
}) })
} catch (err) { } catch (err) {
expect("catch").assertEqual(err); expect().assertFail()
console.debug('ACTS_JsServiceAbility_0900====<end catch(err)'); console.debug('ACTS_JsServiceAbility_0900==== err: ' + JSON.stringify(err));
done(); done();
} }
}) })
...@@ -580,20 +554,20 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -580,20 +554,20 @@ describe('ActsStServiceAbilityTest', function () {
*/ */
it('ACTS_JsServiceAbility_1000', 0, async function (done) { it('ACTS_JsServiceAbility_1000', 0, async function (done) {
console.debug('ACTS_JsServiceAbility_1000====<begin'); console.debug('ACTS_JsServiceAbility_1000====<begin');
await sleep(2000)
try { try {
await commonEvent.createSubscriber(CommonEventSubscribeInfo1000).then(async (data) => { await commonEvent.createSubscriber(CommonEventSubscribeInfo1000).then((data) => {
console.debug("=ACTS_JsServiceAbility_1000 createSubscriber .then(data)=======>" console.debug("=ACTS_JsServiceAbility_1000 createSubscriber .then(data)=======>"
+ ("json data【") + JSON.stringify(data) + ("") + ("json data【") + JSON.stringify(data) + ("")
+ " ,data=" + data); + " ,data=" + data);
subscriber1000 = data; subscriber1000 = data;
commonEvent.subscribe(subscriber1000, async (err, data) => { commonEvent.subscribe(subscriber1000, (err, data) => {
console.debug("=ACTS_JsServiceAbility_1000 subscribe (err,data)=======>" console.debug("=ACTS_JsServiceAbility_1000 subscribe (err,data)=======>"
+ ("json err【") + JSON.stringify(err) + ("") + ("json err【") + JSON.stringify(err) + ("")
+ ("json data【") + JSON.stringify(data) + ("") + ("json data【") + JSON.stringify(data) + ("")
+ " ,err=" + err + " ,data=" + data); + " ,err=" + err + " ,data=" + data);
expect("ACTS_SerivceAbilityServerSecond_onCommand_ServiceStartService_1000").assertEqual( expect("ACTS_SerivceAbilityServerSecond_onCommand_ServiceStartService_1000")
data.event); .assertEqual(data.event);
await sleep(1000)
unsubscribe("ACTS_JsServiceAbility_1000_unsubscribe", subscriber1000); unsubscribe("ACTS_JsServiceAbility_1000_unsubscribe", subscriber1000);
console.debug('ACTS_JsServiceAbility_1000====<end'); console.debug('ACTS_JsServiceAbility_1000====<end');
done() done()
...@@ -616,8 +590,8 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -616,8 +590,8 @@ describe('ActsStServiceAbilityTest', function () {
} }
) )
} catch (err) { } catch (err) {
expect("catch").assertEqual(err); expect().assertFail()
console.debug('ACTS_JsServiceAbility_1000====<end catch(err)'); console.debug('ACTS_JsServiceAbility_1000==== err: ' + JSON.stringify(err));
done(); done();
} }
}) })
...@@ -630,27 +604,26 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -630,27 +604,26 @@ describe('ActsStServiceAbilityTest', function () {
it('ACTS_JsServiceAbility_1300', 0, async function (done) { it('ACTS_JsServiceAbility_1300', 0, async function (done) {
console.log('ACTS_JsServiceAbility_1300====<begin'); console.log('ACTS_JsServiceAbility_1300====<begin');
try { try {
var mConnIdJsPromise; let mConnIdJsPromise;
await commonEvent.createSubscriber(CommonEventSubscribeInfo1300).then(async (data) => { await commonEvent.createSubscriber(CommonEventSubscribeInfo1300).then((data) => {
console.debug("=ACTS_JsServiceAbility_1300 createSubscriber .then(data)=======>" console.debug("=ACTS_JsServiceAbility_1300 createSubscriber .then(data)=======>"
+ ("json data【") + JSON.stringify(data) + ("") + ("json data【") + JSON.stringify(data) + ("")
+ " ,data=" + data); + " ,data=" + data);
subscriber1300 = data; subscriber1300 = data;
commonEvent.subscribe(subscriber1300, async (err, data) => { commonEvent.subscribe(subscriber1300, (err, data) => {
console.debug("=ACTS_JsServiceAbility_1300 subscribe (err,data)=======>" console.debug("=ACTS_JsServiceAbility_1300 subscribe (err,data)=======>"
+ ("json err【") + JSON.stringify(err) + ("") + ("json err【") + JSON.stringify(err) + ("")
+ ("json data【") + JSON.stringify(data) + ("") + ("json data【") + JSON.stringify(data) + ("")
+ " ,err=" + err + " ,data=" + data); + " ,err=" + err + " ,data=" + data);
if (data.event != "ACTS_SerivceAbilityServerSecond_onDisConnect") { if (data.event == "ACTS_SerivceAbilityServerSecond_onConnect_ServiceConnectService_1300") {
expect("ACTS_SerivceAbilityServerSecond_onConnect_ServiceConnectService_1300"
).assertEqual(data.event);
featureAbility.disconnectAbility(mConnIdJsPromise).then((err) => { featureAbility.disconnectAbility(mConnIdJsPromise).then((err) => {
console.debug("=ACTS_JsServiceAbility_1300 disconnectAbility err====>" console.debug("=ACTS_JsServiceAbility_1300 disconnectAbility err====>"
+ ("json err=") + JSON.stringify(err)); + ("json err=") + JSON.stringify(err));
}) })
} else { }
expect("ACTS_SerivceAbilityServerSecond_onDisConnect").assertEqual( else {
data.event); expect("ACTS_SerivceAbilityServerSecond_onDisConnect_ServiceConnectService_1300")
.assertEqual(data.event);
unsubscribe("ACTS_JsServiceAbility_1300_unsubscribe", subscriber1300); unsubscribe("ACTS_JsServiceAbility_1300_unsubscribe", subscriber1300);
console.log('ACTS_JsServiceAbility_1300====<end') console.log('ACTS_JsServiceAbility_1300====<end')
done(); done();
...@@ -694,8 +667,8 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -694,8 +667,8 @@ describe('ActsStServiceAbilityTest', function () {
}, },
) )
} catch (err) { } catch (err) {
expect("catch").assertEqual(err); expect().assertFail()
console.log('ACTS_JsServiceAbility_1300====<end err') console.log('ACTS_JsServiceAbility_1300====<end err: ' + JSON.stringify(err))
done(); done();
} }
}) })
...@@ -708,34 +681,25 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -708,34 +681,25 @@ describe('ActsStServiceAbilityTest', function () {
it('ACTS_JsServiceAbility_1400', 0, async function (done) { it('ACTS_JsServiceAbility_1400', 0, async function (done) {
console.log('ACTS_JsServiceAbility_1400====<begin'); console.log('ACTS_JsServiceAbility_1400====<begin');
try { try {
var currentAlertTimeout; let mConnIdJsAsyncCallback;
var mConnIdJsAsyncCallback; await commonEvent.createSubscriber(CommonEventSubscribeInfo1400).then((data) => {
await commonEvent.createSubscriber(CommonEventSubscribeInfo1400).then(async (data) => {
console.debug("=ACTS_JsServiceAbility_1400 createSubscriber .then(data)=======>" console.debug("=ACTS_JsServiceAbility_1400 createSubscriber .then(data)=======>"
+ ("json data【") + JSON.stringify(data) + ("") + ("json data【") + JSON.stringify(data) + ("")
+ " ,data=" + data); + " ,data=" + data);
subscriber1400 = data; subscriber1400 = data;
commonEvent.subscribe(subscriber1400, async (err, data) => { commonEvent.subscribe(subscriber1400, (err, data) => {
console.debug("=ACTS_JsServiceAbility_1400 subscribe (err,data)=======>" console.debug("=ACTS_JsServiceAbility_1400 subscribe (err,data)=======>"
+ ("json err【") + JSON.stringify(err) + ("") + ("json err【") + JSON.stringify(err) + ("")
+ ("json data【") + JSON.stringify(data) + ("") + ("json data【") + JSON.stringify(data) + ("")
+ " ,err=" + err + " ,data=" + data); + " ,err=" + err + " ,data=" + data);
if (data.event != "ACTS_SerivceAbilityServerSecond_onDisConnect") { if (data.event == "ACTS_SerivceAbilityServerSecond_onConnect_ServiceConnectService_1400") {
expect("ACTS_SerivceAbilityServerSecond_onConnect_ServiceConnectService_1400"
).assertEqual(data.event);
featureAbility.disconnectAbility(mConnIdJsAsyncCallback, (err) => { featureAbility.disconnectAbility(mConnIdJsAsyncCallback, (err) => {
console.debug("=ACTS_JsServiceAbility_1400 disconnectAbility err====>" console.debug("=ACTS_JsServiceAbility_1400 disconnectAbility err====>"
+ ("json err=") + JSON.stringify(err)); + ("json err=") + JSON.stringify(err));
}) })
currentAlertTimeout = setTimeout(() => {
console.log('ACTS_JsServiceAbility_1400====<end steTimeout')
unsubscribe("ACTS_JsServiceAbility_1400_unsubscribe", subscriber1400);
done();
}, gSetTimeout);
} else { } else {
clearTimeout(currentAlertTimeout); expect("ACTS_SerivceAbilityServerSecond_onDisConnect_ServiceConnectService_1400")
expect("ACTS_SerivceAbilityServerSecond_onDisConnect").assertEqual( .assertEqual(data.event);
data.event);
unsubscribe("ACTS_JsServiceAbility_1400_unsubscribe", subscriber1400); unsubscribe("ACTS_JsServiceAbility_1400_unsubscribe", subscriber1400);
console.log('ACTS_JsServiceAbility_1400====<end') console.log('ACTS_JsServiceAbility_1400====<end')
done(); done();
...@@ -776,8 +740,8 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -776,8 +740,8 @@ describe('ActsStServiceAbilityTest', function () {
}, },
) )
} catch (err) { } catch (err) {
expect("catch").assertEqual(err); expect().assertFail()
console.log('ACTS_JsServiceAbility_1400====<end err') console.log('ACTS_JsServiceAbility_1400====<end err: ' + JSON.stringify(err))
done(); done();
} }
}) })
...@@ -790,29 +754,29 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -790,29 +754,29 @@ describe('ActsStServiceAbilityTest', function () {
it('ACTS_JsServiceAbility_1500', 0, async function (done) { it('ACTS_JsServiceAbility_1500', 0, async function (done) {
console.log('ACTS_JsServiceAbility_1500====<begin'); console.log('ACTS_JsServiceAbility_1500====<begin');
try { try {
var mConnIdJsPromise; let mConnIdJsPromise;
await commonEvent.createSubscriber(CommonEventSubscribeInfo1500).then(async (data) => { await commonEvent.createSubscriber(CommonEventSubscribeInfo1500).then((data) => {
console.debug("=ACTS_JsServiceAbility_1500 createSubscriber .then(data)=======>" console.debug("=ACTS_JsServiceAbility_1500 createSubscriber .then(data)=======>"
+ ("json data【") + JSON.stringify(data) + ("") + ("json data【") + JSON.stringify(data) + ("")
+ " ,data=" + data); + " ,data=" + data);
subscriber1500 = data; subscriber1500 = data;
commonEvent.subscribe(subscriber1500, async (err, data) => { commonEvent.subscribe(subscriber1500, (err, data) => {
console.debug("=ACTS_JsServiceAbility_1500 subscribe (err,data)=======>" console.debug("=ACTS_JsServiceAbility_1500 subscribe (err,data)=======>"
+ ("json err【") + JSON.stringify(err) + ("") + ("json err【") + JSON.stringify(err) + ("")
+ ("json data【") + JSON.stringify(data) + ("") + ("json data【") + JSON.stringify(data) + ("")
+ " ,err=" + err + " ,data=" + data); + " ,err=" + err + " ,data=" + data);
if (data.event != "ACTS_SerivceAbilityServer_onDisConnect") { if (data.event == "ACTS_SerivceAbilityServerSecond_onConnect_ServiceConnectService_1500") {
expect("ACTS_SerivceAbilityServerSecond_onConnect_ServiceConnectService_1500").assertEqual( featureAbility.disconnectAbility(mConnIdJsPromise).then((err) => {
data.event); console.debug('ACTS_JsServiceAbility_1500===disconnectAbility data:' +
featureAbility.disconnectAbility(mConnIdJsPromise).then(() => { JSON.stringify(err));
}).catch(err => { }).catch(err => {
expect(".catch").assertEqual(err); expect().assertFail()
console.debug('ACTS_JsServiceAbility_1500====<end .catch(err)'); console.debug('ACTS_JsServiceAbility_1500==== err: ' + JSON.stringify(err));
done(); done();
}) })
} else { } else {
expect("ACTS_SerivceAbilityServer_onDisConnect").assertEqual( expect("ACTS_SerivceAbilityServer_onDisConnect_ServiceConnectService_1500")
data.event); .assertEqual(data.event);
unsubscribe("ACTS_JsServiceAbility_1500_unsubscribe", subscriber1500); unsubscribe("ACTS_JsServiceAbility_1500_unsubscribe", subscriber1500);
console.log('ACTS_JsServiceAbility_1500====<end') console.log('ACTS_JsServiceAbility_1500====<end')
done(); done();
...@@ -859,5 +823,5 @@ describe('ActsStServiceAbilityTest', function () { ...@@ -859,5 +823,5 @@ describe('ActsStServiceAbilityTest', function () {
done(); done();
} }
}) })
}) })
} }
\ No newline at end of file
...@@ -48,7 +48,6 @@ class StubTest extends rpc.RemoteObject { ...@@ -48,7 +48,6 @@ class StubTest extends rpc.RemoteObject {
console.log('ACTS_SerivceAbilityServer ====< method called.') console.log('ACTS_SerivceAbilityServer ====< method called.')
} }
} }
export default { export default {
onStart(want) { onStart(want) {
console.debug('ACTS_SerivceAbilityServer 0425 ====>onStart .ts 0851 =' console.debug('ACTS_SerivceAbilityServer 0425 ====>onStart .ts 0851 ='
...@@ -127,6 +126,7 @@ export default { ...@@ -127,6 +126,7 @@ export default {
try { try {
console.debug('ACTS_SerivceAbilityServer ====>onConnect=' console.debug('ACTS_SerivceAbilityServer ====>onConnect='
+ want + " , JSON." + JSON.stringify(want)); + want + " , JSON." + JSON.stringify(want));
commonEvent.publish("ACTS_SerivceAbilityServer_onConnect" + "_" + want.action, (err) => { });
function onConnectCallback(element, remote) { function onConnectCallback(element, remote) {
console.debug('ACTS_SerivceAbilityServer_onConnectCallback ====> mConnIdJs=' console.debug('ACTS_SerivceAbilityServer_onConnectCallback ====> mConnIdJs='
+ JSON.stringify(mConnIdJs) + " , " + mConnIdJs); + JSON.stringify(mConnIdJs) + " , " + mConnIdJs);
...@@ -157,8 +157,6 @@ export default { ...@@ -157,8 +157,6 @@ export default {
onFailed: onFailedCallback, onFailed: onFailedCallback,
}, },
) )
} else {
commonEvent.publish("ACTS_SerivceAbilityServer_onConnect" + "_" + want.action, (err) => { });
} }
} catch (err) { } catch (err) {
console.log("ACTS_SerivceAbilityServer ====< error:" + err) console.log("ACTS_SerivceAbilityServer ====< error:" + err)
...@@ -169,12 +167,9 @@ export default { ...@@ -169,12 +167,9 @@ export default {
onDisconnect(want) { onDisconnect(want) {
console.debug('ACTS_SerivceAbilityServer ====>onDisConnect=' console.debug('ACTS_SerivceAbilityServer ====>onDisConnect='
+ want + " , JSON." + JSON.stringify(want)); + want + " , JSON." + JSON.stringify(want));
commonEvent.publish("ACTS_SerivceAbilityServer_onDisConnect", (err) => { commonEvent.publish("ACTS_SerivceAbilityServer_onDisConnect_" + want.action, (err) => {
if (err.code) { console.debug('ACTS_SerivceAbilityServer_onDisConnect ===' + want.action);
console.debug('ACTS_SerivceAbilityServer_onDisConnect publish err=====>' + err); });
} else {
console.debug('ACTS_SerivceAbilityServer_onDisConnect featureAbility.terminateSelf()=====<'
+ want.action);
if (want.action == 'ServiceConnectService_1300' || want.action == 'ServiceConnectService_1400' if (want.action == 'ServiceConnectService_1300' || want.action == 'ServiceConnectService_1400'
|| want.action == 'ServiceConnectService_1500' || want.action == 'ServiceConnectService_1501' || want.action == 'ServiceConnectService_1500' || want.action == 'ServiceConnectService_1501'
|| want.action == 'ServiceConnectService_1600' || want.action == 'ServiceConnectService_1601' || want.action == 'ServiceConnectService_1600' || want.action == 'ServiceConnectService_1601'
...@@ -189,8 +184,6 @@ export default { ...@@ -189,8 +184,6 @@ export default {
}).catch((error) => { }).catch((error) => {
console.log('ACTS_SerivceAbilityServer terminateSelf error:' + JSON.stringify(error)); console.log('ACTS_SerivceAbilityServer terminateSelf error:' + JSON.stringify(error));
}); });
}
});
}, },
onReady() { onReady() {
console.debug('ACTS_SerivceAbilityServer ====<onReady'); console.debug('ACTS_SerivceAbilityServer ====<onReady');
......
...@@ -49,6 +49,9 @@ class StubTest extends rpc.RemoteObject { ...@@ -49,6 +49,9 @@ class StubTest extends rpc.RemoteObject {
} }
} }
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
export default { export default {
onStart(want) { onStart(want) {
console.debug('ACTS_SerivceAbilityServerSecond ====>onStart=' console.debug('ACTS_SerivceAbilityServerSecond ====>onStart='
...@@ -68,7 +71,11 @@ export default { ...@@ -68,7 +71,11 @@ export default {
console.debug('ACTS_SerivceAbilityServerSecond ====>onCommand=' console.debug('ACTS_SerivceAbilityServerSecond ====>onCommand='
+ "JSON(want)=" + JSON.stringify(want) + "JSON(want)=" + JSON.stringify(want)
+ " ,restart=" + restart + " ,startId=" + startId); + " ,restart=" + restart + " ,startId=" + startId);
commonEvent.publish("ACTS_SerivceAbilityServerSecond_onCommand" + "_" + want.action, (err) => { }); commonEvent.publish("ACTS_SerivceAbilityServerSecond_onCommand" + "_" + want.action, (err) => {
console.debug("ACTS_SerivceAbilityServerSecond_onCommand" + "_" + want.action +
"err: " + JSON.stringify(err))
});
sleep(500)
particleAbility.terminateSelf().then((data) => { particleAbility.terminateSelf().then((data) => {
console.log('ACTS_SerivceAbilityServer terminateSelf data:' + JSON.stringify(data)); console.log('ACTS_SerivceAbilityServer terminateSelf data:' + JSON.stringify(data));
}).catch((error) => { }).catch((error) => {
...@@ -154,7 +161,7 @@ export default { ...@@ -154,7 +161,7 @@ export default {
onDisconnect(want) { onDisconnect(want) {
console.debug('ACTS_SerivceAbilityServerSecond ====>onDisConnect=' console.debug('ACTS_SerivceAbilityServerSecond ====>onDisConnect='
+ want + " , JSON." + JSON.stringify(want)); + want + " , JSON." + JSON.stringify(want));
commonEvent.publish("ACTS_SerivceAbilityServerSecond_onDisConnect", (err) => { commonEvent.publish("ACTS_SerivceAbilityServerSecond_onDisConnect_" + want.action, (err) => {
if (err.code) { if (err.code) {
console.debug('ACTS_SerivceAbilityServerSecond_onDisConnect publish err=====>' + err); console.debug('ACTS_SerivceAbilityServerSecond_onDisConnect publish err=====>' + err);
} else { } else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册