• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15import hiSysEvent from '@ohos.hiSysEvent'
16import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
17
18export default function hiSysEventJsTest() {
19describe('hiSysEventJsTest', function () {
20    beforeAll(function() {
21        console.info('hiSysEventJsTest beforeAll called')
22    })
23
24    afterAll(function() {
25        console.info('hiSysEventJsTest afterAll called')
26    })
27
28    beforeEach(function() {
29        console.info('hiSysEventJsTest beforeEach called')
30    })
31
32    afterEach(function() {
33        console.info('hiSysEventJsTest afterEach called')
34    })
35
36	/**
37	 * @tc.number DFX_DFT_HiSysEvent_JS_0100
38	 * @tc.name testHiSysEventApi01
39	 * @tc.desc 添加Js打点事件-callback方式进行回调处理
40	 */
41	it('testHiSysEventApi01', 1, async function (done) {
42		console.info('testHiSysEventApi01 start')
43		hiSysEvent.write({
44			domain: "RELIABILITY",
45			name: "STACK",
46			eventType: hiSysEvent.EventType.FAULT,
47		},(err, value) => {
48			console.log('HiSysEvent into json-callback');
49			if (err) {
50				console.error(`HiSysEvent json-callback-error code=${err.code}`);
51				expect(err.code == 0).assertFail();
52				done();
53			} else {
54				console.log(`HiSysEvent json-callback-success value=${value}`);
55				expect(value == 0).assertTrue();
56				done();
57			}
58		});
59		console.info('testHiSysEventApi01 end')
60	})
61
62	/**
63	 * @tc.number DFX_DFT_HiSysEvent_JS_0200
64	 * @tc.name testHiSysEventApi02
65	 * @tc.desc 添加Js打点事件-Promise方式中then()方法进行打点成功回调处理
66	 */
67	it('testHiSysEventApi02', 1, async function (done) {
68		console.info('testHiSysEventApi02 start')
69		hiSysEvent.write({
70		domain: "RELIABILITY",
71		name: "STACK",
72		eventType: hiSysEvent.EventType.FAULT,
73		}).then(
74			(value) => {
75				console.log(`HiSysEvent json-callback-success value=${value}`);
76				expect(value == 0).assertTrue();
77				done();
78			}
79		).catch(
80			(err) => {
81				console.error(`HiSysEvent json-callback-error code=${err.code}`);
82				expect(err.code == 0).assertFail();
83			}
84		)
85		console.info('testHiSysEventApi02 end')
86	})
87
88	/**
89	 * @tc.number DFX_DFT_HiSysEvent_JS_0400
90	 * @tc.name testHiSysEventApi04
91	 * @tc.desc HiSysEvent添加Js打点事件-添加成功后回调函数被调用(domain+eventName, eventType=FAULT)
92	 */
93	it('testHiSysEventApi04', 3, async function (done) {
94		console.info('testHiSysEventApi04 start')
95		hiSysEvent.write({
96			domain: "RELIABILITY",
97			name: "STACK",
98			eventType: hiSysEvent.EventType.FAULT,
99		},(err, value) => {
100			console.log('HiSysEvent into json-callback');
101			if (err) {
102				console.error(`HiSysEvent json-callback-error code=${err.code}`);
103				expect(err.code == 0).assertFail();
104				done();
105			} else {
106				console.log(`HiSysEvent json-callback-success value=${value}`);
107				expect(value == 0).assertTrue();
108				done();
109			}
110		});
111		console.info('testHiSysEventApi04 end')
112	})
113
114	/**
115	 * @tc.number DFX_DFT_HiSysEvent_JS_0500
116	 * @tc.name testHiSysEventApi05
117	 * @tc.desc 添加Js打点事件-添加成功后回调函数被调用(domain+eventName, eventType=STATISTIC)
118	 */
119	it('testHiSysEventApi05', 3, async function (done) {
120		console.info('testHiSysEventApi05 start')
121		hiSysEvent.write({
122			domain: "HIVIEWDFX",
123			name: "PLUGIN_STATS",
124			eventType: hiSysEvent.EventType.STATISTIC,
125		},(err, value) => {
126			console.log('HiSysEvent into json-callback');
127			if (err) {
128				console.error(`HiSysEvent json-callback-error code=${err.code}`);
129				expect(err.code == 0).assertFail();
130				done();
131			} else {
132				console.log(`HiSysEvent json-callback-success value=${value}`);
133				expect(value == 0).assertTrue();
134				done();
135			}
136		});
137		console.info('testHiSysEventApi05 end')
138	})
139
140	/**
141	 * @tc.number DFX_DFT_HiSysEvent_JS_0600
142	 * @tc.name testHiSysEventApi06
143	 * @tc.desc 添加Js打点事件-添加成功后回调函数被调用(domain+eventName, eventType=SECURITY)
144	 */
145	it('testHiSysEventApi06', 3, async function (done) {
146		console.info('testHiSysEventApi06 start')
147		hiSysEvent.write({
148			domain: "ACCOUNT",
149			name: "PERMISSION_EXCEPTION",
150			eventType: hiSysEvent.EventType.SECURITY,
151		},(err, value) => {
152			console.log('HiSysEvent into json-callback');
153			if (err) {
154				console.error(`HiSysEvent json-callback-error code=${err.code}`);
155				expect(err.code == 0).assertFail();
156				done();
157			} else {
158				console.log(`HiSysEvent json-callback-success value=${value}`);
159				expect(value == 0).assertTrue();
160				done();
161			}
162		});
163		console.info('testHiSysEventApi06 end')
164	})
165
166	/**
167	 * @tc.number DFX_DFT_HiSysEvent_JS_0700
168	 * @tc.name testHiSysEventApi07
169	 * @tc.desc 添加Js打点事件-添加成功后回调函数被调用(domain+eventName, eventType=BEHAVIOR)
170	 */
171	it('testHiSysEventApi07', 3, async function (done) {
172		console.info('testHiSysEventApi07 start')
173		hiSysEvent.write({
174			domain: "HIVIEWDFX",
175			name: "PLUGIN_LOAD",
176			eventType: hiSysEvent.EventType.BEHAVIOR,
177		},(err, value) => {
178			console.log('HiSysEvent into json-callback');
179			if (err) {
180				console.error(`HiSysEvent json-callback-error code=${err.code}`);
181				expect(err.code == 0).assertFail();
182				done();
183			} else {
184				console.log(`HiSysEvent json-callback-success value=${value}`);
185				expect(value == 0).assertTrue();
186				done();
187			}
188		});
189		console.info('testHiSysEventApi07 end')
190	})
191
192    /**
193	 * @tc.number DFX_DFT_HiSysEvent_JS_0800
194	 * @tc.name testHiSysEventApi08
195	 * @tc.desc 添加Js打点事件-添加成功后回调函数被调用(domain+eventName+params, eventType=FAULT)
196     */
197	it('testHiSysEventApi08', 3, async function (done) {
198		console.info('testHiSysEventApi08 start')
199		hiSysEvent.write({
200			domain: "RELIABILITY",
201			name: "STACK",
202			eventType: hiSysEvent.EventType.FAULT,
203			params: {
204				PID: 487,
205				UID: 103,
206				PACKAGE_NAME: "com.ohos.hisysevent.test",
207				PROCESS_NAME: "syseventservice",
208				MSG: "no msg."
209			}
210		},(err, value) => {
211			console.log('HiSysEvent into json-callback');
212			if (err) {
213				console.error(`HiSysEvent json-callback-error code=${err.code}`);
214				expect(err.code == 0).assertFail();
215				done();
216			} else {
217				console.log(`HiSysEvent json-callback-success value=${value}`);
218				expect(value == 0).assertTrue();
219				done();
220			}
221		});
222		console.info('testHiSysEventApi08 end')
223	})
224
225	/**
226	 * @tc.number DFX_DFT_HiSysEvent_JS_0900
227	 * @tc.name testHiSysEventApi09
228	 * @tc.desc HiSysEvent添加Js打点事件-添加成功后回调函数被调用(domain+eventName+params, eventType=STATISTIC)
229	 */
230	it('testHiSysEventApi09', 3, async function (done) {
231		console.info('testHiSysEventApi09 start')
232		hiSysEvent.write({
233			domain: "HIVIEWDFX",
234			name: "PLUGIN_STATS",
235			eventType: hiSysEvent.EventType.STATISTIC,
236			params: {
237				PID: 487,
238				UID: 103,
239				PACKAGE_NAME: "com.ohos.hisysevent.test",
240				PROCESS_NAME: "syseventservice",
241				MSG: "no msg."
242			}
243		},(err, value) => {
244			console.log('HiSysEvent into json-callback');
245			if (err) {
246				console.error(`HiSysEvent json-callback-error code=${err.code}`);
247				expect(err.code == 0).assertFail();
248				done();
249			} else {
250				console.log(`HiSysEvent json-callback-success value=${value}`);
251				expect(value == 0).assertTrue();
252				done();
253			}
254		});
255		console.info('testHiSysEventApi09 end')
256	})
257
258	/**
259	 * @tc.number DFX_DFT_HiSysEvent_JS_1000
260	 * @tc.name testHiSysEventApi10
261	 * @tc.desc HiSysEvent添加Js打点事件-添加成功后回调函数被调用(domain+eventName+params, eventType=SECURITY)
262	 */
263	it('testHiSysEventApi10', 3, async function (done) {
264		console.info('testHiSysEventApi10 start')
265		hiSysEvent.write({
266			domain: "ACCOUNT",
267			name: "PERMISSION_EXCEPTION",
268			eventType: hiSysEvent.EventType.SECURITY,
269			params: {
270				PID: 487,
271				UID: 103,
272				PACKAGE_NAME: "com.ohos.hisysevent.test",
273				PROCESS_NAME: "syseventservice",
274				MSG: "no msg."
275			}
276		},(err, value) => {
277			console.log('testHiSysEventApi10 into json-callback');
278			if (err) {
279				console.error(`testHiSysEventApi10 json-callback-error code=${err.code}`);
280				expect(err.code == 0).assertFail();
281				done();
282			} else {
283				console.log(`testHiSysEventApi10 json-callback-success value=${value}`);
284				expect(value == 0).assertTrue();
285				done();
286			}
287		});
288		console.info('testHiSysEventApi10 end')
289	})
290
291	/**
292	 * @tc.number DFX_DFT_HiSysEvent_JS_1100
293	 * @tc.name testHiSysEventApi11
294	 * @tc.desc HiSysEvent添加Js打点事件-添加成功后回调函数被调用(domain+eventName+params, eventType=BEHAVIOR)
295	 */
296	it('testHiSysEventApi11', 3, async function (done) {
297		console.info('testHiSysEventApi11 start')
298		hiSysEvent.write({
299			domain: "HIVIEWDFX",
300			name: "PLUGIN_LOAD",
301			eventType: hiSysEvent.EventType.BEHAVIOR,
302			params: {
303				PID: 487,
304				UID: 103,
305				PACKAGE_NAME: "com.ohos.hisysevent.test",
306				PROCESS_NAME: "syseventservice",
307				MSG: "no msg."
308			}
309		},(err, value) => {
310			console.log('testHiSysEventApi11 into json-callback');
311			if (err) {
312				console.error(`testHiSysEventApi11 json-callback-error code=${err.code}`);
313				expect(err.code == 0).assertFail();
314				done();
315			} else {
316				console.log(`testHiSysEventApi11 json-callback-success value=${value}`);
317				expect(value == 0).assertTrue();
318				done();
319			}
320		});
321		console.info('testHiSysEventApi11 end')
322	})
323
324	/**
325	 * @tc.number DFX_DFT_HiSysEvent_JS_1200
326	 * @tc.name testHiSysEventApi12
327	 * @tc.desc HiSysEvent订阅接口测试-订阅成功回调函数被调用(domain+eventName, rule=PREFIX)
328	 */
329	it('testHiSysEventApi12', 3, async function (done) {
330		console.info('testHiSysEventApi12 start')
331		let watcher = {
332			rules: [{
333				domain: "RELIABILITY",
334				name: "STACK",
335				tag: "STABILITY",
336				ruleType: hiSysEvent.RuleType.PREFIX
337			}],
338			onEvent: (info) => {
339				console.info(`testHiSysEventApi12: OnEvent...`)
340				expect(Object.keys(info).length > 0).assertTrue()
341				console.info(`testHiSysEventApi12: domain is : ${info.domain}, name is ${info.name},
342				                                               eventType is ${info.eventType}`)
343				if (info.params instanceof Object) {
344					for (const key in info.params) {
345						console.info(`testHiSysEventApi12: ${key}: ${info.params[key]}`)
346					}
347				}
348			},
349			onServiceDied: () => {
350				console.info(`testHiSysEventApi12 Onservice died`);
351			}
352		}
353		try {
354			hiSysEvent.addWatcher(watcher)
355			expect(true).assertTrue()
356			console.info('testHiSysEventApi12 end')
357			done();
358		} catch (err) {
359			console.error(`testHiSysEventApi12 > error code: ${err.code}, error msg: ${err.message}`)
360			expect(err.code == 201).assertTrue()
361			console.info('testHiSysEventApi12 end')
362			done()
363		}
364		hiSysEvent.removeWatcher(watcher)
365	})
366
367	/**
368	 * @tc.number DFX_DFT_HiSysEvent_JS_1300
369	 * @tc.name testHiSysEventApi13
370	 * @tc.desc HiSysEvent订阅接口测试-订阅成功回调函数被调用(domain+eventName, rule=REGULAR)
371	 */
372	it('testHiSysEventApi13', 3, async function (done) {
373		console.info('testHiSysEventApi13 start')
374		let watcher = {
375			rules: [{
376				domain: "RELIABILITY",
377				name: "STACK",
378				ruleType: hiSysEvent.RuleType.REGULAR
379			}],
380			onEvent: (info) => {
381				console.info(`testHiSysEventApi13: OnEvent...`)
382				expect(Object.keys(info).length > 0).assertTrue()
383				console.info(`testHiSysEventApi13: domain is : ${info.domain}, name is ${info.name},
384				                                                               eventType is ${info.eventType}`)
385				if (info.params instanceof Object) {
386					for (const key in info.params) {
387						console.info(`testHiSysEventApi13: ${key}: ${info.params[key]}`)
388					}
389				}
390			},
391			onServiceDied: () => {
392				console.info(`testHiSysEventApi13 Onservice died`);
393			}
394		}
395		try {
396			hiSysEvent.addWatcher(watcher)
397			expect(true).assertTrue()
398			console.info('testHiSysEventApi13 end')
399			done();
400		} catch (err) {
401			console.error(`testHiSysEventApi13 > error code: ${err.code}, error msg: ${err.message}`)
402			expect(err.code == 201).assertTrue()
403			console.info('testHiSysEventApi13 end')
404			done()
405		}
406		hiSysEvent.removeWatcher(watcher)
407	})
408
409	/**
410	 * @tc.number DFX_DFT_HiSysEvent_JS_1400
411	 * @tc.name testHiSysEventApi14
412	 * @tc.desc HiSysEvent订阅接口测试-订阅成功回调函数被调用(domain+eventName, rule=WHOLE_WORD)
413	 */
414	it('testHiSysEventApi14', 3, async function (done) {
415		console.info('testHiSysEventApi14 start')
416		let watcher = {
417			rules: [{
418				domain: "RELIABILITY",
419				name: "STACK",
420				ruleType: hiSysEvent.RuleType.WHOLE_WORD
421			}],
422			onEvent: (info) => {
423				console.info(`testHiSysEventApi14: OnEvent...`)
424				expect(Object.keys(info).length > 0).assertTrue()
425				console.info(`testHiSysEventApi14: domain is : ${info.domain}, name is ${info.name},
426				                                                               eventType is ${info.eventType}`)
427				if (info.params instanceof Object) {
428					for (const key in info.params) {
429						console.info(`testHiSysEventApi14: ${key}: ${info.params[key]}`)
430					}
431				}
432			},
433			onServiceDied: () => {
434				console.info(`testHiSysEventApi14 Onservice died`);
435			}
436		}
437		try {
438			hiSysEvent.addWatcher(watcher)
439			expect(true).assertTrue()
440			console.info('testHiSysEventApi14 end')
441			done();
442		} catch (err) {
443			console.error(`testHiSysEventApi14 > error code: ${err.code}, error msg: ${err.message}`)
444			expect(err.code == 201)
445			console.info('testHiSysEventApi14 end')
446			done()
447		}
448		hiSysEvent.removeWatcher(watcher)
449	})
450
451	/**
452	 * @tc.number DFX_DFT_HiSysEvent_JS_1500
453	 * @tc.name testHiSysEventApi15
454	 * @tc.desc HiSysEvent订阅接口测试-订阅成功回调函数被调用(domain+eventName+tag, rule=PREFIX)
455	 */
456	it('testHiSysEventApi15', 3, async function (done) {
457		console.info('testHiSysEventApi15 start')
458		let watcher = {
459			rules: [{
460				domain: "RELIABILITY",
461				name: "STACK",
462				tag: "STABILITY",
463				ruleType: hiSysEvent.RuleType.PREFIX
464			}],
465			onEvent: (info) => {
466				console.info(`testHiSysEventApi15: OnEvent...`)
467				expect(Object.keys(info).length > 0).assertTrue()
468				console.info(`testHiSysEventApi15: domain is : ${info.domain}, name is ${info.name},
469				                                   eventType is ${info.eventType}`)
470				if (info.params instanceof Object) {
471					for (const key in info.params) {
472						console.info(`testHiSysEventApi15: ${key}: ${info.params[key]}`)
473					}
474				}
475			},
476			onServiceDied: () => {
477				console.info(`testHiSysEventApi15 Onservice died`);
478			}
479		}
480		try {
481			hiSysEvent.addWatcher(watcher)
482			expect(true).assertTrue()
483			console.info('testHiSysEventApi15 end')
484			done();
485		} catch (err) {
486			console.error(`testHiSysEventApi15 > error code: ${err.code}, error msg: ${err.message}`)
487			expect(err.code == 201).assertTrue()
488			console.info('testHiSysEventApi15 end')
489			done()
490		}
491		hiSysEvent.removeWatcher(watcher)
492	})
493
494	/**
495	 * @tc.number DFX_DFT_HiSysEvent_JS_1600
496	 * @tc.name testHiSysEventApi16
497	 * @tc.desc HiSysEvent订阅接口测试-订阅成功回调函数被调用(domain+eventName+tag, rule=REGULAR)
498	 */
499	it('testHiSysEventApi16', 3, async function (done) {
500		console.info('testHiSysEventApi16 start')
501		let watcher = {
502			rules: [{
503				domain: "RELIABILITY",
504				name: "STACK",
505				tag: "STABILITY",
506				ruleType: hiSysEvent.RuleType.REGULAR
507			}],
508			onEvent: (info) => {
509				console.info(`testHiSysEventApi16: OnEvent...`)
510				expect(Object.keys(info).length > 0).assertTrue()
511				console.info(`testHiSysEventApi16: domain is : ${info.domain},
512				              name is ${info.name}, eventType is ${info.eventType}`)
513				if (info.params instanceof Object) {
514					for (const key in info.params) {
515						console.info(`testHiSysEventApi16: ${key}: ${info.params[key]}`)
516					}
517				}
518			},
519			onServiceDied: () => {
520				console.info(`testHiSysEventApi16 Onservice died`);
521			}
522		}
523		try {
524			hiSysEvent.addWatcher(watcher)
525			expect(true).assertTrue()
526			console.info('testHiSysEventApi16 end')
527			done();
528		} catch (err) {
529			console.error(`testHiSysEventApi16 > error code: ${err.code}, error msg: ${err.message}`)
530			expect(err.code == 201).assertTrue()
531			console.info('testHiSysEventApi16 end')
532			done()
533		}
534		hiSysEvent.removeWatcher(watcher)
535	})
536
537	/**
538	 * @tc.number DFX_DFT_HiSysEvent_JS_1700
539	 * @tc.name testHiSysEventApi17
540	 * @tc.desc HiSysEvent订阅接口测试-订阅成功回调函数被调用(domain+eventName+tag, rule=WHOLE_WORD)
541	 */
542	it('testHiSysEventApi17', 3, async function (done) {
543		console.info('testHiSysEventApi17 start')
544		let watcher = {
545			rules: [{
546				domain: "RELIABILITY",
547				name: "STACK",
548				tag: "STABILITY",
549				ruleType: hiSysEvent.RuleType.WHOLE_WORD
550			}],
551			onEvent: (info) => {
552				console.info(`testHiSysEventApi17: OnEvent...`)
553				expect(Object.keys(info).length > 0).assertTrue()
554				console.info(`testHiSysEventApi17: domain is : ${info.domain}, name is ${info.name},
555				                                   eventType is ${info.eventType}`)
556				if (info.params instanceof Object) {
557					for (const key in info.params) {
558						console.info(`testHiSysEventApi17: ${key}: ${info.params[key]}`)
559					}
560				}
561			},
562			onServiceDied: () => {
563				console.info(`testHiSysEventApi17 Onservice died`);
564			}
565		}
566		try {
567			hiSysEvent.addWatcher(watcher)
568			expect(true).assertTrue()
569			console.info('testHiSysEventApi17 end')
570			done();
571		} catch (err) {
572			console.error(`testHiSysEventApi17 > error code: ${err.code}, error msg: ${err.message}`)
573			expect(err.code == 201).assertTrue()
574			console.info('testHiSysEventApi17 end')
575			done()
576		}
577		hiSysEvent.removeWatcher(watcher)
578	})
579
580	/**
581	 * @tc.number DFX_DFT_HiSysEvent_JS_1800
582	 * @tc.name testHiSysEventApi18
583	 * @tc.desc HiSysEvent删除订阅接口测试-删除订阅成功回调函数被调用(domain+eventName, rule=PREFIX)
584	 */
585	it('testHiSysEventApi18', 3, async function (done) {
586		console.info('testHiSysEventApi18 start')
587		let watcher = {
588			rules: [{
589				domain: "RELIABILITY",
590				name: "STACK",
591				ruleType: hiSysEvent.RuleType.PREFIX
592			}],
593			onEvent: (info) => {
594				console.info(`testHiSysEventApi18: OnEvent...`)
595				expect(Object.keys(info).length > 0).assertTrue()
596				console.info(`testHiSysEventApi18: domain is : ${info.domain}, name is ${info.name},
597				                                                               eventType is ${info.eventType}`)
598				if (info.params instanceof Object) {
599					for (const key in info.params) {
600						console.info(`testHiSysEventApi18: ${key}: ${info.params[key]}`)
601					}
602				}
603			},
604			onServiceDied: () => {
605				console.info(`testHiSysEventApi18 Onservice died`);
606			}
607		}
608		hiSysEvent.addWatcher(watcher)
609		setTimeout(() => {
610			try {
611				hiSysEvent.removeWatcher(watcher)
612				expect(true).assertTrue()
613				console.info('testHiSysEventApi18 end')
614				done();
615			} catch (err) {
616				console.error(`testHiSysEventApi18 > error code: ${err.code}, error msg: ${err.message}`)
617				expect(err.code == 201).assertTrue()
618				console.info('testHiSysEventApi18 end')
619				done()
620			}
621        }, 1000)
622	})
623
624	/**
625	 * @tc.number DFX_DFT_HiSysEvent_JS_1900
626	 * @tc.name testHiSysEventApi19
627	 * @tc.desc HiSysEvent删除订阅接口测试-删除订阅成功回调函数被调用(domain+eventName, rule=REGULAR)
628	 */
629	it('testHiSysEventApi19', 3, async function (done) {
630		console.info('testHiSysEventApi19 start')
631		let watcher = {
632			rules: [{
633				domain: "RELIABILITY",
634				name: "STACK",
635				ruleType: hiSysEvent.RuleType.REGULAR
636			}],
637			onEvent: (info) => {
638				console.info(`testHiSysEventApi19: OnEvent...`)
639				expect(Object.keys(info).length > 0).assertTrue()
640				console.info(`testHiSysEventApi19: domain is : ${info.domain}, name is ${info.name},
641				                                                               eventType is ${info.eventType}`)
642				if (info.params instanceof Object) {
643					for (const key in info.params) {
644						console.info(`testHiSysEventApi19: ${key}: ${info.params[key]}`)
645					}
646				}
647			},
648			onServiceDied: () => {
649				console.info(`testHiSysEventApi19 Onservice died`);
650			}
651		}
652		hiSysEvent.addWatcher(watcher)
653		setTimeout(() => {
654			try {
655				hiSysEvent.removeWatcher(watcher)
656				expect(true).assertTrue()
657				console.info('testHiSysEventApi19 end')
658				done();
659			} catch (err) {
660				console.error(`testHiSysEventApi19 > error code: ${err.code}, error msg: ${err.message}`)
661				expect(err.code == 201).assertTrue()
662				console.info('testHiSysEventApi19 end')
663				done()
664			}
665        }, 1000)
666	})
667
668	/**
669	 * @tc.number DFX_DFT_HiSysEvent_JS_2000
670	 * @tc.name testHiSysEventApi20
671	 * @tc.desc HiSysEvent删除订阅接口测试-删除订阅成功回调函数被调用(domain+eventName, rule=WHOLE_WORD)
672	 */
673	it('testHiSysEventApi20', 3, async function (done) {
674		console.info('testHiSysEventApi14 start')
675		let watcher = {
676			rules: [{
677				domain: "RELIABILITY",
678				name: "STACK",
679				ruleType: hiSysEvent.RuleType.WHOLE_WORD
680			}],
681			onEvent: (info) => {
682				console.info(`testHiSysEventApi20: OnEvent...`)
683				expect(Object.keys(info).length > 0).assertTrue()
684				console.info(`testHiSysEventApi20: domain is : ${info.domain}, name is ${info.name},
685				                                                               eventType is ${info.eventType}`)
686				if (info.params instanceof Object) {
687					for (const key in info.params) {
688						console.info(`testHiSysEventApi20: ${key}: ${info.params[key]}`)
689					}
690				}
691			},
692			onServiceDied: () => {
693				console.info(`testHiSysEventApi20 Onservice died`);
694			}
695		}
696		hiSysEvent.addWatcher(watcher)
697		setTimeout(() => {
698			try {
699				hiSysEvent.removeWatcher(watcher)
700				expect(true).assertTrue()
701				console.info('testHiSysEventApi20 end')
702				done();
703			} catch (err) {
704				console.error(`testHiSysEventApi20 > error code: ${err.code}, error msg: ${err.message}`)
705				expect(err.code == 201).assertTrue()
706				console.info('testHiSysEventApi20 end')
707				done()
708			}
709        }, 1000)
710	})
711
712	/**
713	 * @tc.number DFX_DFT_HiSysEvent_JS_2100
714	 * @tc.name testHiSysEventApi21
715	 * @tc.desc HiSysEvent删除订阅接口测试-删除订阅成功回调函数被调用(domain+eventName+tag, rule=PREFIX)
716	 */
717	it('testHiSysEventApi21', 3, async function (done) {
718		console.info('testHiSysEventApi21 start')
719		let watcher = {
720			rules: [{
721				domain: "RELIABILITY",
722				name: "STACK",
723				tag: "STABILITY",
724				ruleType: hiSysEvent.RuleType.PREFIX
725			}],
726			onEvent: (info) => {
727				console.info(`testHiSysEventApi21: OnEvent...`)
728				expect(Object.keys(info).length > 0).assertTrue()
729				console.info(`testHiSysEventApi21: domain is : ${info.domain}, name is ${info.name},
730				                                                               eventType is ${info.eventType}`)
731				if (info.params instanceof Object) {
732					for (const key in info.params) {
733						console.info(`testHiSysEventApi21: ${key}: ${info.params[key]}`)
734					}
735				}
736			},
737			onServiceDied: () => {
738				console.info(`testHiSysEventApi21 Onservice died`);
739			}
740		}
741		hiSysEvent.addWatcher(watcher)
742		setTimeout(() => {
743			try {
744				hiSysEvent.removeWatcher(watcher)
745				expect(true).assertTrue()
746				console.info('testHiSysEventApi21 end')
747				done();
748			} catch (err) {
749				console.error(`testHiSysEventApi21 > error code: ${err.code}, error msg: ${err.message}`)
750				expect(err.code == 201).assertTrue()
751				console.info('testHiSysEventApi21 end')
752				done()
753			}
754        }, 1000)
755	})
756
757	/**
758	 * @tc.number DFX_DFT_HiSysEvent_JS_2200
759	 * @tc.name testHiSysEventApi22
760	 * @tc.desc HiSysEvent删除订阅接口测试-删除订阅成功回调函数被调用(domain+eventName+tag, rule=REGULAR)
761	 */
762	it('testHiSysEventApi22', 3, async function (done) {
763		console.info('testHiSysEventApi22 start')
764		let watcher = {
765			rules: [{
766				domain: "RELIABILITY",
767				name: "STACK",
768				tag: "STABILITY",
769				ruleType: hiSysEvent.RuleType.REGULAR
770			}],
771			onEvent: (info) => {
772				console.info(`testHiSysEventApi22: OnEvent...`)
773				expect(Object.keys(info).length > 0).assertTrue()
774				console.info(`testHiSysEventApi22: domain is : ${info.domain}, name is ${info.name},
775				                                                               eventType is ${info.eventType}`)
776				if (info.params instanceof Object) {
777					for (const key in info.params) {
778						console.info(`testHiSysEventApi22: ${key}: ${info.params[key]}`)
779					}
780				}
781			},
782			onServiceDied: () => {
783				console.info(`testHiSysEventApi22 Onservice died`);
784			}
785		}
786		hiSysEvent.addWatcher(watcher)
787		setTimeout(() => {
788			try {
789				hiSysEvent.removeWatcher(watcher)
790				expect(true).assertTrue()
791				console.info('testHiSysEventApi22 end')
792				done();
793			} catch (err) {
794				console.error(`testHiSysEventApi22 > error code: ${err.code}, error msg: ${err.message}`)
795				expect(err.code == 201).assertTrue()
796				console.info('testHiSysEventApi22 end')
797				done()
798			}
799        }, 1000)
800	})
801
802	/**
803	 * @tc.number DFX_DFT_HiSysEvent_JS_2300
804	 * @tc.name testHiSysEventApi23
805	 * @tc.desc HiSysEvent删除订阅接口测试-删除订阅成功回调函数被调用(domain+eventName+tag, rule=WHOLE_WORD)
806	 */
807	it('testHiSysEventApi23', 3, async function (done) {
808		console.info('testHiSysEventApi23 start')
809		let watcher = {
810			rules: [{
811				domain: "RELIABILITY",
812				name: "STACK",
813				tag: "STABILITY",
814				ruleType: hiSysEvent.RuleType.WHOLE_WORD
815			}],
816			onEvent: (info) => {
817				console.info(`testHiSysEventApi23: OnEvent...`)
818				expect(Object.keys(info).length > 0).assertTrue()
819				console.info(`testHiSysEventApi23: domain is : ${info.domain}, name is ${info.name},
820				                                                               eventType is ${info.eventType}`)
821				if (info.params instanceof Object) {
822					for (const key in info.params) {
823						console.info(`testHiSysEventApi23: ${key}: ${info.params[key]}`)
824					}
825				}
826			},
827			onServiceDied: () => {
828				console.info(`testHiSysEventApi23 Onservice died`);
829			}
830		}
831		hiSysEvent.addWatcher(watcher)
832		setTimeout(() => {
833			try {
834				hiSysEvent.removeWatcher(watcher)
835				expect(true).assertTrue()
836				console.info('testHiSysEventApi23 end')
837				done();
838			} catch (err) {
839				console.error(`testHiSysEventApi23 > error code: ${err.code}, error msg: ${err.message}`)
840				expect(err.code == 201).assertTrue()
841				console.info('testHiSysEventApi23 end')
842				done()
843			}
844        }, 1000)
845	})
846
847	/**
848	 * @tc.number DFX_DFT_HiSysEvent_JS_2400
849	 * @tc.name testHiSysEventApi24
850	 * @tc.desc HiSysEvent查询接口测试-查询成功回调函数被调用(查询一个事件)
851	 */
852	it('testHiSysEventApi24', 1, async function (done) {
853		console.info('testHiSysEventApi24 start')
854		try {
855			hiSysEvent.write({
856				domain: "ACCOUNT",
857				name: "PERMISSION_EXCEPTION",
858				eventType: hiSysEvent.EventType.SECURITY,
859				params: {
860					PID: 487,
861					UID: 103,
862					PACKAGE_NAME: "com.ohos.hisysevent.test",
863					PROCESS_NAME: "syseventservice",
864					MSG: "no msg."
865				}
866			},(err, value) => {
867				console.log('testHiSysEventApi24 into json-callback');
868				if (err) {
869					console.error('in testHiSysEventApi24 test callback: err.code = ' + err.code)
870				} else {
871					console.info('in testHiSysEventApi24 test callback: result = ' + value)
872				}
873			});
874			setTimeout(() => {
875				hiSysEvent.query({
876					beginTime: -1,
877					endTime: -1,
878					maxEvents: 1,
879				}, [{
880					domain: "ACCOUNT",
881					names: ["PERMISSION_EXCEPTION"],
882				}], {
883					onQuery: function (infos) {
884						console.info(`testHiSysEventApi24: onQuery...`)
885						expect(infos.length >= 0).assertTrue()
886						console.info(`testHiSysEventApi24: infos.size is ${infos.length}`)
887						if (infos instanceof Array) {
888							for (let i = 0; i < infos.length; i++) {
889								let item = infos[i];
890								console.info(`testHiSysEventApi24: domain is ${item.domain}, name is ${item.name},
891																   eventType is ${item.eventType}`)
892								if (item.params instanceof Object) {
893									for (const key in item.params) {
894										console.info(`testHiSysEventApi24: ${key}: ${item.params[key]}`)
895									}
896								}
897							}
898						}
899					},
900					onComplete: function(reason, total) {
901						console.info(`testHiSysEventApi24: onComplete...`)
902						console.info(`testHiSysEventApi24: reason is ${reason}, total is ${total}`)
903						done()
904						console.info(`testHiSysEventApi24 end`)
905					}
906				})
907			}, 1000);
908		} catch (error) {
909			console.error(`error code: ${error.code}, error msg: ${error.message}`);
910		}
911	})
912
913	/**
914	 * @tc.number DFX_DFT_HiSysEvent_JS_2500
915	 * @tc.name testHiSysEventApi25
916	 * @tc.desc HiSysEvent查询接口测试-查询成功回调函数被调用(查询多个事件)
917	 */
918	it('testHiSysEventApi25', 1, async function (done) {
919		console.info('testHiSysEventApi25 start')
920		try {
921			hiSysEvent.write({
922				domain: "HIVIEWDFX",
923				name: "SYS_USAGE",
924				eventType: hiSysEvent.EventType.STATISTIC,
925			},(err, value) => {
926				console.log('testHiSysEventApi25 into json-callback');
927				if (err) {
928					console.error('in testHiSysEventApi25 test callback: err.code = ' + err.code)
929				} else {
930					console.info('in testHiSysEventApi25 test callback: result = ' + value)
931				}
932			});
933			console.info('add second..')
934			setTimeout(() => {
935				hiSysEvent.write({
936					domain: "HIVIEWDFX",
937					name: "PLUGIN_STATS",
938					eventType: hiSysEvent.EventType.STATISTIC,
939				},(err, value) => {
940					console.log('testHiSysEventApi25 into json-callback');
941					if (err) {
942						console.error('in testHiSysEventApi25 test callback: err.code = ' + err.code)
943					} else {
944						console.info('in testHiSysEventApi25 test callback: result = ' + value)
945					}
946				})
947			},1000)
948			setTimeout(() => {
949				hiSysEvent.query({
950					beginTime: -1,
951					endTime: -1,
952					maxEvents: 5,
953				}, [{
954					domain: "HIVIEWDFX",
955					names: ["SYS_USAGE","PLUGIN_STATS"],
956				}], {
957					onQuery: function (infos) {
958						console.info(`testHiSysEventApi25: onQuery...`)
959						expect(infos.length >= 0).assertTrue()
960						console.info(`testHiSysEventApi25: infos.size is ${infos.length}`)
961						if (infos instanceof Array) {
962							for (let i = 0; i < infos.length; i++) {
963								let item = infos[i];
964								console.info(`testHiSysEventApi25: domain is ${item.domain}, name is ${item.name},
965																   eventType is ${item.eventType}`)
966								if (item.params instanceof Object) {
967									for (const key in item.params) {
968										console.info(`testHiSysEventApi25: ${key}: ${item.params[key]}`)
969									}
970								}
971							}
972						}
973					},
974					onComplete: function(reason, total) {
975						console.info(`testHiSysEventApi25: onComplete...`)
976						console.info(`testHiSysEventApi25: reason is ${reason}, total is ${total}`)
977						done()
978						console.info(`testHiSysEventApi25 end`)
979					}
980				})
981			}, 2000);
982		} catch (error) {
983			console.error(`error code: ${error.code}, error msg: ${error.message}`);
984		}
985	})
986})
987}
988