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

!4799 【XTS】【事件通知子系统】EmitterTest 整改_master

Merge pull request !4799 from 郅建文/master
...@@ -17,139 +17,138 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' ...@@ -17,139 +17,138 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '
export default function EmitterTest() { export default function EmitterTest() {
describe('EmitterTest', function () { describe('EmitterTest', function () {
console.info("===========EmitterTest start====================>"); const TAG = 'EmitterTest ===> '
console.info(TAG + 'EmitterTest START')
var eventData = { let innerEvent = {
data: { eventId: undefined,
"id": 1, priority: undefined
"content": "message",
}
} }
var InnerEventImmediate = { let eventData = {
eventId: 1, data: {
priority: emitter.EventPriority.IMMEDIATE 'id': undefined,
'content': undefined
} }
var InnerEventLow = {
eventId: 2,
priority: emitter.EventPriority.LOW
} }
function callback(data){ function EmitterCallback(eventData) {
console.info('callback success'); console.info(TAG + 'eventData.id: ' + JSON.stringify(eventData.data.id));
expect(data.eventId).assertEqual("message"); console.info(TAG + 'eventData.content: ' + JSON.stringify(eventData.data.content));
if (eventData.data.id == 0) {
expect(eventData.data.content).assertEqual('message_0');
} else if (eventData.data.id == 1) {
expect(eventData.data.content).assertEqual('message_1');
} else if (eventData.data.id == 2) {
expect(eventData.data.content).assertEqual('message_2');
} else if (eventData.data.id == 3) {
expect(eventData.data.content).assertEqual('message_3');
} else if (eventData.data.id == 4) {
expect(eventData.data.content).assertEqual('message_4');
} else if (eventData.data.id == 5) {
expect(eventData.data.content).assertEqual('message_5');
} }
function callback01(data){
console.info('callback success');
expect(data.data.id).assertEqual(1);
expect(data.data.content).assertEqual("message");
} }
/* /*
* @tc.number : EmitterOnTest * @tc.number : EmitterTest_0100
* @tc.name : verify on : Check subscribe same on common ordered event * @tc.name : verify on : on(event: InnerEvent, callback: Callback<EventData>): void
* @tc.desc : Check the subscriber can receive event "EmitterOnTest" type of the interface (by Promise) * @tc.desc : emitter.EventPriority.IDLE
*/ */
it('EmitterOnTest', 0, async function (done) { it('EmitterTest_0100', 0, async function (done) {
console.info("===========EmitterOnTest====================>"); console.info(TAG + 'EmitterTest_0100 START')
emitter.on(InnerEventImmediate, callback); innerEvent.eventId = 1
done(); innerEvent.priority = emitter.EventPriority.IDLE
})
/* eventData.data.id = 0
* @tc.number : EmitterOnceTest eventData.data.content = 'message_0'
* @tc.name : verify once : Check subscribe same once common ordered event
* @tc.desc : Check the subscriber can receive event "EmitterOnceTest" type of the interface (by Promise) emitter.on(innerEvent, EmitterCallback)
*/ emitter.emit(innerEvent, eventData)
it('EmitterOnceTest', 0, async function (done){ eventData.data.id = 1
console.info("===========EmitterOnceTest====================>"); eventData.data.content = 'message_1'
emitter.once(InnerEventImmediate, callback); emitter.emit(innerEvent, eventData)
done(); console.info(TAG + 'EmitterTest_0100 END')
done()
}) })
/* /*
* @tc.number : EmitterEmitTest * @tc.number : EmitterTest_0200
* @tc.name : verify emit : Check subscribe same emit common ordered event * @tc.name : verify on : once(event: InnerEvent, callback: Callback<EventData>): void
* @tc.desc : Check the subscriber can receive event "EmitterEmitTest" type of the interface (by Promise) * @tc.desc : emitter.EventPriority.LOW
*/ */
it('EmitterEmitTest', 0, async function (done){ it('EmitterTest_0200', 0, async function (done) {
console.info("===========EmitterEmitTest====================>"); console.info(TAG + 'EmitterTest_0200 START')
emitter.once(InnerEventImmediate, callback01); innerEvent.eventId = 2
emitter.emit(InnerEventImmediate, eventData); innerEvent.priority = emitter.EventPriority.LOW
done();
eventData.data.id = 2
eventData.data.content = 'message_2'
emitter.once(innerEvent, EmitterCallback)
emitter.emit(innerEvent, eventData)
console.info(TAG + 'EmitterTest_0200 END')
done()
}) })
/* /*
* @tc.number : EmitterLowTest * @tc.number : EmitterTest_0300
* @tc.name : verify low : Check subscribe same low common ordered event * @tc.name : verify on : emit(event: InnerEvent, data?: EventData): void
* @tc.desc : Check the subscriber can receive event "EmitterLowTest" type of the interface (by Promise) * @tc.desc : emitter.EventPriority.HIGH
*/ */
it('EmitterLowTest', 0, async function (done){ it('EmitterTest_0300', 0, async function (done) {
console.info("===========EmitterLowTest====================>"); console.info(TAG + 'EmitterTest_0300 START')
emitter.once(InnerEventLow, callback01); innerEvent.eventId = 3
emitter.emit(InnerEventLow,eventData); innerEvent.priority = emitter.EventPriority.HIGH
done();
})
eventData.data.id = 3
eventData.data.content = 'message_3'
/* emitter.once(innerEvent, EmitterCallback)
* @tc.number : EmitterOffTest emitter.emit(innerEvent, eventData)
* @tc.name : verify off : Check subscribe same off common ordered event console.info(TAG + 'EmitterTest_0300 END')
* @tc.desc : Check the subscriber can receive event "EmitterOffTest" type of the interface (by Promise) done()
*/
it('EmitterOffTest', 0, async function (done){
console.info("===========EmitterOffTest111====================>");
emitter.once(InnerEventLow, callback01);
emitter.emit(InnerEventImmediate, eventData);
emitter.off(1);
done();
}) })
/* /*
* @tc.number : EmitterEmitTest_0100 * @tc.number : EmitterTest_0400
* @tc.name : verify off : Check subscribe same off common ordered event * @tc.name : verify on : emit(event: InnerEvent, data?: EventData): void
* @tc.desc : Check the subscriber can receive event "EmitterOffTest" type of the interface (by Promise) * @tc.desc : emitter.EventPriority.IMMEDIATE
*/ */
it('EmitterEmitTest_0100', 0, async function (done){ it('EmitterTest_0400', 0, async function (done) {
console.info("===========EmitterEmitTest_0100====================>"); console.info(TAG + 'EmitterTest_0400 START')
var eventData2 = { innerEvent.eventId = 4
data: { innerEvent.priority = emitter.EventPriority.IMMEDIATE
"content": "c",
"id": 2, eventData.data.id = 4
}}; eventData.data.content = 'message_4'
var innerEventHigh = {
eventId: 3, emitter.once(innerEvent, EmitterCallback)
priority: emitter.EventPriority.HIGH emitter.emit(innerEvent, eventData)
}; console.info(TAG + 'EmitterTest_0400 END')
emitter.once(InnerEventLow, callback01); done()
emitter.emit(innerEventHigh, eventData2);
expect(emitter.EventPriority.HIGH).assertEqual(1)
done();
}) })
/* /*
* @tc.number : EmitterEmitTest_0200 * @tc.number : EmitterTest_0500
* @tc.name : verify off : emitter.EventPriority.IDLE * @tc.name : verify on : off(eventId: number): void
* @tc.desc : emitter.EventPriority.IDLE * @tc.desc : emitter.EventPriority.IMMEDIATE
*/ */
it('EmitterEmitTest_0200', 0, async function (done){ it('EmitterTest_0500', 0, async function (done) {
console.info("===========EmitterEmitTest_0100====================>"); console.info(TAG + 'EmitterTest_0500 START')
var eventData3 = { innerEvent.eventId = 5
data: { innerEvent.priority = emitter.EventPriority.IMMEDIATE
"content": "d",
"id": 3, eventData.data.id = 5
}}; eventData.data.content = 'message_5'
var innerEventIdle = {
eventId: 4, emitter.once(innerEvent, EmitterCallback)
priority: emitter.EventPriority.IDLE emitter.emit(innerEvent, eventData)
}; emitter.off(5)
emitter.once(innerEventIdle, callback01); console.info(TAG + 'EmitterTest_0500 END')
emitter.emit(InnerEventImmediate, eventData3); done()
expect(emitter.EventPriority.IDLE).assertEqual(3)
done();
}) })
console.info(TAG + 'EmitterTest END')
}) })
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册