• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2021-2022 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 */
15
16import hiSysEvent from "@ohos.hiSysEvent"
17
18import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
19
20describe('hiSysEventJsUnitTest', function () {
21  beforeAll(function() {
22
23    /**
24     * @tc.setup: setup invoked before all test cases
25     */
26    console.info('hiSysEventJsUnitTest beforeAll called')
27  })
28
29  afterAll(function() {
30
31    /**
32     * @tc.teardown: teardown invoked after all test cases
33     */
34    console.info('hiSysEventJsUnitTest afterAll called')
35  })
36
37  beforeEach(function() {
38
39    /**
40     * @tc.setup: setup invoked before each test case
41     */
42    console.info('hiSysEventJsUnitTest beforeEach called')
43  })
44
45  afterEach(function() {
46
47    /**
48     * @tc.teardown: teardown invoked after each test case
49     */
50    console.info('hiSysEventJsUnitTest afterEach called')
51  })
52
53  function GetParam(src, key) {
54    return src["params"][key]
55  }
56
57  function GetArrayIemParamByIndex(src, key, index) {
58    let arrayInSrc = src["params"][key]
59    if (index > arrayInSrc.length) {
60      return undefined
61    }
62    return arrayInSrc[index]
63  }
64
65  function writeEventWithAsyncWork(domain, name, eventType, params, errCallback, normalCallback, done) {
66    try {
67      hiSysEvent.write({
68        domain: domain,
69        name: name,
70        eventType: eventType,
71        params: params
72      }, (err, val) => {
73        if (err) {
74          errCallback(err)
75        } else {
76          normalCallback(val)
77        }
78        done()
79      })
80    } catch (err) {
81      expect(false).assertTrue()
82      done()
83    }
84  }
85
86  function writeEventWithPromise(domain, name, eventType, params, errCallback, normalCallback, done) {
87    try {
88      hiSysEvent.write({
89        domain: domain,
90        name: name,
91        eventType: eventType,
92        params: params
93      }).then((val) => {
94        normalCallback(val)
95        done()
96      }).catch((err) => {
97        errCallback(err)
98        done()
99      })
100    } catch (err) {
101      expect(false).assertTrue()
102      done()
103    }
104  }
105
106  function writeCustomizedSysEvent(customized) {
107    try {
108      hiSysEvent.write({
109        domain: "RELIABILITY",
110        name: "STACK",
111        eventType: hiSysEvent.EventType.FAULT,
112        params: customized
113      }, (err, val) => {
114        if (err) {
115          console.error(`callback: err.code = ${err.code}, error msg is ${err.message}`)
116          expect(false).assertTrue()
117          done()
118        }
119      })
120    } catch (err) {
121      expect(false).assertTrue()
122      done()
123    }
124  }
125
126  function writeDefaultSysEvent() {
127    writeCustomizedSysEvent({
128      PID: 1,
129      UID: 1,
130      PACKAGE_NAME: "com.ohos.testHiSysEvent",
131      PROCESS_NAME: "hiview js test suite",
132      MSG: "no msg."
133    })
134  }
135
136  function querySysEvent(queryArgs, querRules, onQueryCallback, onCompleteCallback,
137    errCallback, done) {
138    try {
139      hiSysEvent.query(queryArgs, querRules, {
140        onQuery: function (infos) {
141          onQueryCallback(infos)
142        },
143        onComplete: function(reason, total) {
144          onCompleteCallback(reason, total)
145          done()
146        }
147      })
148    } catch (err) {
149      errCallback(err)
150      done()
151    }
152  }
153
154  /**
155   * @tc.desc: Test hisysevent writing with calling AsyncCallback.
156   * @tc.level: Level 0
157   * @tc.name: hiSysEventJsUnitTest001
158   * @tc.number: hiSysEventJsUnitTest001
159   * @tc.type: Function
160   * @tc.size: MediumTest
161   */
162  it('hiSysEventJsUnitTest001', 0, async function (done) {
163    writeEventWithAsyncWork("RELIABILITY", "STACK", hiSysEvent.EventType.FAULT,
164      {
165        PID: 1,
166        UID: 1,
167        PACKAGE_NAME: "com.ohos.testHiSysEvent",
168        PROCESS_NAME: "hiview js test suite",
169        MSG: "no msg."
170      },
171      (err) => {
172        expect(false).assertTrue()
173      },
174      (val) => {
175        expect(val).assertEqual(0)
176      }, done)
177  })
178
179  /**
180   * @tc.desc: Test hisysevent writing with returning Promise.
181   * @tc.level: Level 0
182   * @tc.name: hiSysEventJsUnitTest002
183   * @tc.number: hiSysEventJsUnitTest002
184   * @tc.type: Function
185   * @tc.size: MediumTest
186   */
187  it('hiSysEventJsUnitTest002', 0, async function (done) {
188    writeEventWithPromise("RELIABILITY", "STACK", hiSysEvent.EventType.FAULT,
189      {
190        PID: 1,
191        UID: 1,
192        PACKAGE_NAME: "com.ohos.testHiSysEvent",
193        PROCESS_NAME: "hiview js test suite",
194        MSG: "no msg."
195      },
196      (err) => {
197        expect(false).assertTrue()
198      },
199      (val) => {
200        expect(val).assertEqual(0)
201      }, done)
202  })
203
204  /**
205   * @tc.desc: Test function return of adding/remove hisysevent watcher result.
206   * @tc.level: Level 0
207   * @tc.name: hiSysEventJsUnitTest003
208   * @tc.number: hiSysEventJsUnitTest003
209   * @tc.type: Function
210   * @tc.size: MediumTest
211   */
212  it('hiSysEventJsUnitTest003', 0, async function (done) {
213    let watcher = {
214      rules: [{
215        domain: "RELIABILITY",
216        name: "STACK",
217        ruleType: hiSysEvent.RuleType.WHOLE_WORD,
218      }],
219      onEvent: (info) => {
220      },
221      onServiceDied: () => {
222      }
223    }
224    try {
225      hiSysEvent.addWatcher(watcher)
226      hiSysEvent.removeWatcher(watcher)
227      expect(true).assertTrue()
228      done();
229    } catch (err) {
230      expect(err.code == 201).assertTrue()
231      done()
232    }
233  })
234
235  /**
236   * @tc.desc: Test watcher callback.
237   * @tc.level: Level 0
238   * @tc.name: hiSysEventJsUnitTest004
239   * @tc.number: hiSysEventJsUnitTest004
240   * @tc.type: Function
241   * @tc.size: MediumTest
242   */
243  it('hiSysEventJsUnitTest004', 0, async function (done) {
244    let watcher = {
245      rules: [{
246        domain: "RELIABILITY",
247        name: "STACK",
248        tag: "STABILITY",
249        ruleType: hiSysEvent.RuleType.WHOLE_WORD,
250      }],
251      onEvent: (info) => {
252        expect(Object.keys(info).length > 0).assertTrue()
253      },
254      onServiceDied: () => {
255      }
256    }
257    try {
258      hiSysEvent.addWatcher(watcher)
259      writeDefaultSysEvent()
260      setTimeout(() => {
261        try {
262          hiSysEvent.removeWatcher(watcher)
263          expect(true).assertTrue()
264          done()
265        } catch (err) {
266          expect(err.code == 201).assertTrue()
267          done()
268        }
269      }, 1000)
270    } catch (err) {
271      expect(err.code == 201).assertTrue()
272      done()
273    }
274  })
275
276  /**
277   * @tc.desc: Test query callback.
278   * @tc.level: Level 0
279   * @tc.name: hiSysEventJsUnitTest005
280   * @tc.number: hiSysEventJsUnitTest005
281   * @tc.type: Function
282   * @tc.size: MediumTest
283   */
284  it('hiSysEventJsUnitTest005', 0, async function (done) {
285    try {
286      writeDefaultSysEvent()
287      setTimeout(() => {
288        querySysEvent({
289          beginTime: -1,
290          endTime: -1,
291          maxEvents: 2,
292        }, [{
293          domain: "RELIABILITY",
294          names: ["STACK"],
295        }], (infos) => {
296          expect(infos.length >= 0).assertTrue()
297        }, (reason, total) => {
298          expect(true).assertTrue()
299        }, (err) => {
300          expect(err.code == 201).assertTrue()
301        }, done)
302      }, 1000);
303    } catch (err) {
304      expect(err.code == 201).assertTrue()
305      done()
306    }
307  })
308
309  /**
310   * @tc.desc: Test query callback with domain which length is over 16.
311   * @tc.level: Level 0
312   * @tc.name: hiSysEventJsUnitTest006
313   * @tc.number: hiSysEventJsUnitTest006
314   * @tc.type: Function
315   * @tc.size: MediumTest
316   */
317  it('hiSysEventJsUnitTest006', 0, async function (done) {
318    console.info('hiSysEventJsUnitTest006 start')
319    try {
320      writeDefaultSysEvent()
321      setTimeout(() => {
322        querySysEvent({
323          beginTime: -1,
324          endTime: -1,
325          maxEvents: 2,
326        }, [{
327          domain: "RELIABILITY_RELIABILITY",
328          names: ["STACK"],
329        }], (infos) => {
330          expect(infos.length >= 0).assertTrue()
331        }, (reason, total) => {
332          expect(true).assertTrue()
333        }, (err) => {
334          expect(err.code == 11200302 || err.code == 11200304).assertTrue()
335        }, done)
336      }, 1000);
337    } catch (err) {
338      expect(false).assertTrue()
339      done()
340    }
341  })
342
343  /**
344   * @tc.desc: Test query callback with domain which length is over 32.
345   * @tc.level: Level 0
346   * @tc.name: hiSysEventJsUnitTest007
347   * @tc.number: hiSysEventJsUnitTest007
348   * @tc.type: Function
349   * @tc.size: MediumTest
350   */
351   it('hiSysEventJsUnitTest007', 0, async function (done) {
352    try {
353      writeDefaultSysEvent()
354      setTimeout(() => {
355        querySysEvent({
356          beginTime: -1,
357          endTime: -1,
358          maxEvents: 2,
359        }, [{
360          domain: "RELIABILITY",
361          names: ["STACK_STACK_STACK_STACK_STACK_STACK"],
362        }], (infos) => {
363          expect(infos.length >= 0).assertTrue()
364        }, (reason, total) => {
365          expect(true).assertTrue()
366        }, (err) => {
367          expect(err.code == 11200302 || err.code == 11200304).assertTrue()
368        }, done)
369      }, 1000);
370    } catch (err) {
371      expect(false).assertTrue()
372      done()
373    }
374  })
375
376  /**
377   * @tc.desc: Test hisysevent of invalid domain writing with calling AsyncCallback.
378   * @tc.level: Level 0
379   * @tc.name: hiSysEventJsUnitTest008
380   * @tc.number: hiSysEventJsUnitTest008
381   * @tc.type: Function
382   * @tc.size: MediumTest
383   */
384  it('hiSysEventJsUnitTest008', 0, async function (done) {
385    writeEventWithAsyncWork("RELIABILITY_RELIABILITY", "STACK", hiSysEvent.EventType.FAULT,
386      {
387        PID: 1,
388        UID: 1,
389        PACKAGE_NAME: "com.ohos.testHiSysEvent",
390        PROCESS_NAME: "hiview js test suite",
391        MSG: "no msg."
392      }, (err) => {
393        expect(err.code == 11200001).assertTrue()
394      }, (val) => {
395        expect(false).assertTrue()
396      }, done)
397  })
398
399  /**
400   * @tc.desc: Test hisysevent of invalid event name writing with calling AsyncCallback.
401   * @tc.level: Level 0
402   * @tc.name: hiSysEventJsUnitTest009
403   * @tc.number: hiSysEventJsUnitTest009
404   * @tc.type: Function
405   * @tc.size: MediumTest
406   */
407  it('hiSysEventJsUnitTest009', 0, async function (done) {
408    writeEventWithAsyncWork("RELIABILITY", "STACK_STACK_STACK_STACK_STACK_STACK", hiSysEvent.EventType.FAULT,
409      {
410        PID: 1,
411        UID: 1,
412        PACKAGE_NAME: "com.ohos.testHiSysEvent",
413        PROCESS_NAME: "hiview js test suite",
414        MSG: "no msg."
415      }, (err) => {
416        expect(err.code == 11200002).assertTrue()
417      }, (val) => {
418        expect(false).assertTrue()
419      }, done)
420  })
421
422  /**
423   * @tc.desc: Test hisysevent which is over size writing with calling AsyncCallback.
424   * @tc.level: Level 0
425   * @tc.name: hiSysEventJsUnitTest010
426   * @tc.number: hiSysEventJsUnitTest010
427   * @tc.type: Function
428   * @tc.size: MediumTest
429   */
430   it('hiSysEventJsUnitTest010', 0, async function (done) {
431    let params = {
432      PID: 1,
433      UID: 1,
434      PACKAGE_NAME: "com.ohos.testHiSysEvent",
435      PROCESS_NAME: "just a testcase",
436      MSG: "no msg."
437    }
438    for (let i = 0; i < 40; i++) {
439      params[`bundle${i}`] = Array.from({length: 10 * 1024}).join("ohos")
440    }
441    writeEventWithAsyncWork("RELIABILITY", "STACK", hiSysEvent.EventType.FAULT,
442      params, (err) => {
443        expect(err.code == 11200004).assertTrue()
444      }, (val) => {
445        expect(false).assertTrue()
446      }, done)
447  })
448
449  /**
450   * @tc.desc: Test hisysevent of invalid param name writing with calling AsyncCallback.
451   * @tc.level: Level 0
452   * @tc.name: hiSysEventJsUnitTest011
453   * @tc.number: hiSysEventJsUnitTest011
454   * @tc.type: Function
455   * @tc.size: MediumTest
456   */
457  it('hiSysEventJsUnitTest011', 0, async function (done) {
458    writeEventWithAsyncWork("RELIABILITY", "STACK", hiSysEvent.EventType.FAULT,
459      {
460        PID: 1,
461        UID: 1,
462        STACK_STACK_STACK_STACK_STACK_STACK_STACK_STACK_STACK_STACK_STACK_STACK: "com.ohos.testHiSysEvent",
463        PROCESS_NAME: "hiview js test suite",
464        MSG: "no msg."
465      }, (err) => {
466        expect(err.code == 11200051).assertTrue()
467      }, (val) => {
468        expect(false).assertTrue()
469      }, done)
470  })
471
472  /**
473   * @tc.desc: Test hisysevent with string over limit writing with calling AsyncCallback.
474   * @tc.level: Level 0
475   * @tc.name: hiSysEventJsUnitTest012
476   * @tc.number: hiSysEventJsUnitTest012
477   * @tc.type: Function
478   * @tc.size: MediumTest
479   */
480   it('hiSysEventJsUnitTest012', 0, async function (done) {
481    writeEventWithAsyncWork("RELIABILITY", "STACK", hiSysEvent.EventType.FAULT,
482      {
483        PID: 1,
484        UID: 1,
485        PACKAGE_NAME: "com.ohos.testHiSysEvent",
486        PROCESS_NAME: Array.from({length: 10 * 1024 + 10}).join("ohos"),
487        MSG: "no msg."
488      }, (err) => {
489        expect(err.code == 11200052).assertTrue()
490      }, (val) => {
491        expect(false).assertTrue()
492      }, done)
493  })
494
495  /**
496   * @tc.desc: Test hisysevent with param count over limit writing with calling AsyncCallback.
497   * @tc.level: Level 0
498   * @tc.name: hiSysEventJsUnitTest013
499   * @tc.number: hiSysEventJsUnitTest013
500   * @tc.type: Function
501   * @tc.size: MediumTest
502   */
503   it('hiSysEventJsUnitTest013', 0, async function (done) {
504    let largeParams = {}
505    for (let i = 0; i < 200; i++) {
506      largeParams["name" + i] = i
507    }
508    writeEventWithAsyncWork("RELIABILITY", "STACK", hiSysEvent.EventType.FAULT,
509      largeParams, (err) => {
510        expect(err.code == 11200053).assertTrue()
511      }, (val) => {
512        expect(false).assertTrue()
513      }, done)
514  })
515
516  /**
517   * @tc.desc: Test hisysevent with array size over limit writing with calling AsyncCallback.
518   * @tc.level: Level 0
519   * @tc.name: hiSysEventJsUnitTest014
520   * @tc.number: hiSysEventJsUnitTest014
521   * @tc.type: Function
522   * @tc.size: MediumTest
523   */
524   it('hiSysEventJsUnitTest014', 0, async function (done) {
525    let msgArray = []
526    for (let i = 0; i < 200; i++) {
527      msgArray[i] = i
528    }
529    writeEventWithAsyncWork("RELIABILITY", "STACK", hiSysEvent.EventType.FAULT,
530      {
531        PID: 1,
532        UID: 1,
533        PACKAGE_NAME: "com.ohos.testHiSysEvent",
534        PROCESS_NAME: "hiview js test suite",
535        MSG: msgArray
536      }, (err) => {
537        expect(err.code == 11200054).assertTrue()
538      }, (val) => {
539        expect(false).assertTrue()
540      }, done)
541  })
542
543  /**
544   * @tc.desc: Test hisysevent query with sequence.
545   * @tc.level: Level 0
546   * @tc.name: hiSysEventJsUnitTest015
547   * @tc.number: hiSysEventJsUnitTest015
548   * @tc.type: Function
549   * @tc.size: MediumTest
550   */
551  it('hiSysEventJsUnitTest015', 0, async function (done) {
552    querySysEvent({
553      maxEvents: 10000,
554      fromSeq: 100,
555      toSeq: 1000,
556    }, [{
557      domain: "AAFWK",
558      names: ["CONNECT_SERVICE"],
559    }], (infos) => {
560      expect(infos.length >= 0).assertTrue()
561    }, (reason, total) => {
562      expect(true).assertTrue()
563    }, (err) => {
564      expect(err.code == 201).assertTrue()
565    }, done)
566  })
567
568  /**
569   * @tc.desc: Test hisysevent get max sequence.
570   * @tc.level: Level 0
571   * @tc.name: hiSysEventJsUnitTest016
572   * @tc.number: hiSysEventJsUnitTest016
573   * @tc.type: Function
574   * @tc.size: MediumTest
575   */
576  it('hiSysEventJsUnitTest016', 0, async function (done) {
577    querySysEvent({
578      maxEvents: 0,
579      fromSeq: 0,
580      toSeq: 1000,
581    }, [{
582      domain: "AAFWK",
583      names: ["CONNECT_SERVICE"],
584    }], (infos) => {
585      expect(infos.length >= 0).assertTrue()
586    }, (reason, total) => {
587      expect(true).assertTrue()
588    }, (err) => {
589      expect(err.code == 201).assertTrue()
590    }, done)
591  })
592
593  /**
594   * @tc.desc: Test writing sysevents more than 100 times in 5 seconds.
595   * @tc.level: Level 0
596   * @tc.name: hiSysEventJsUnitTest017
597   * @tc.number: hiSysEventJsUnitTest017
598   * @tc.type: Function
599   * @tc.size: MediumTest
600   */
601  it('hiSysEventJsUnitTest017', 0, async function (done) {
602    try {
603      for (let index = 0; index < 102; index++) {
604        writeEventWithAsyncWork("USERIAM_PIN", "USERIAM_TEMPLATE_CHANGE",
605          hiSysEvent.EventType.SECURITY,
606          {
607            PID: 1,
608            UID: 1,
609            PACKAGE_NAME: "com.ohos.testHiSysEvent",
610            PROCESS_NAME: "hiview js test suite",
611          }, (err) => {
612            expect(err.code == 11200003).assertTrue()
613          }, (val) => {}, done)
614      }
615    } catch (err) {
616      expect(false).assertTrue()
617      done()
618    }
619  })
620
621  /**
622   * @tc.desc: Test query sysevent with 2 conditions: == & ==.
623   * @tc.level: Level 0
624   * @tc.name: hiSysEventJsUnitTest018
625   * @tc.number: hiSysEventJsUnitTest018
626   * @tc.type: Function
627   * @tc.size: MediumTest
628   */
629  it('hiSysEventJsUnitTest018', 0, async function (done) {
630    writeCustomizedSysEvent({
631      PID: 323232388,
632      UID: 1,
633      PACKAGE_NAME: "com.ohos.hiSysEventJsUnitTest018",
634      PROCESS_NAME: "hiview js test suite"
635    })
636    writeCustomizedSysEvent({
637      PID: 1000,
638      UID: 1,
639      PACKAGE_NAME: "com.ohos.hiSysEventJsUnitTest018",
640      PROCESS_NAME: "hiview js test suite"
641    })
642    writeCustomizedSysEvent({
643      PID: 1000,
644      UID: 1,
645      PACKAGE_NAME: "com.ohos.testHiSysEvent2",
646      PROCESS_NAME: "hiview js test suite"
647    })
648    setTimeout(() => {
649      querySysEvent({
650        beginTime: -1,
651        endTime: -1,
652        maxEvents: 5,
653      }, [{
654        domain: "RELIABILITY",
655        names: ["STACK"],
656        condition: '{"version":"V1","condition":{"and":[{"param":"PID","op":"=","value":1000},' +
657          '{"param":"PACKAGE_NAME","op":"=","value":"com.ohos.testHiSysEvent2"}]}}'
658      }], (infos) => {
659        expect(infos.length >= 0).assertTrue()
660      }, (reason, total) => {
661        expect(total >= 1).assertTrue()
662      }, (err) => {
663        expect(false).assertTrue()
664      }, done)
665    }, 1000)
666  })
667
668  /**
669   * @tc.desc: Test query sysevent with conditions: <= & >=.
670   * @tc.level: Level 0
671   * @tc.name: hiSysEventJsUnitTest019
672   * @tc.number: hiSysEventJsUnitTest019
673   * @tc.type: Function
674   * @tc.size: MediumTest
675   */
676  it('hiSysEventJsUnitTest019', 0, async function (done) {
677    writeCustomizedSysEvent({
678      PID: 222,
679      UID: 10,
680      PACKAGE_NAME: "com.ohos.hiSysEventJsUnitTest019",
681      PROCESS_NAME: "hiview js test suite"
682    })
683    writeCustomizedSysEvent({
684      PID: 222,
685      UID: 20,
686      PACKAGE_NAME: "com.ohos.hiSysEventJsUnitTest019",
687      PROCESS_NAME: "hiview js test suite"
688    })
689    writeCustomizedSysEvent({
690      PID: 222,
691      UID: 23,
692      PACKAGE_NAME: "com.ohos.hiSysEventJsUnitTest019",
693      PROCESS_NAME: "hiview js test suite"
694    })
695    setTimeout(() => {
696      querySysEvent({
697        beginTime: -1,
698        endTime: -1,
699        maxEvents: 5,
700      }, [{
701        domain: "RELIABILITY",
702        names: ["STACK"],
703        condition: '{"version":"V1","condition":{"and":[{"param":"PID","op":"<=","value":222},' +
704          '{"param":"UID","op":">=","value":19.0}]}}'
705      }], (infos) => {
706        expect(infos.length >= 0).assertTrue()
707      }, (reason, total) => {
708        expect(total >= 2).assertTrue()
709      }, (err) => {
710        expect(false).assertTrue()
711      }, done)
712    }, 1500)
713  })
714
715  /**
716   * @tc.desc: Test query sysevent with conditions: > & <.
717   * @tc.level: Level 0
718   * @tc.name: hiSysEventJsUnitTest020
719   * @tc.number: hiSysEventJsUnitTest020
720   * @tc.type: Function
721   * @tc.size: MediumTest
722   */
723  it('hiSysEventJsUnitTest020', 0, async function (done) {
724    writeCustomizedSysEvent({
725      PID: 2009,
726      UID: 20001,
727      PACKAGE_NAME: "com.ohos.hiSysEventJsUnitTest020",
728      PROCESS_NAME: "hiview js test suite"
729    })
730    writeCustomizedSysEvent({
731      PID: 2010,
732      UID: 20002,
733      PACKAGE_NAME: "com.ohos.hiSysEventJsUnitTest020",
734      PROCESS_NAME: "hiview js test suite"
735    })
736    writeCustomizedSysEvent({
737      PID: 2020,
738      UID: 20003,
739      PACKAGE_NAME: "com.ohos.hiSysEventJsUnitTest020",
740      PROCESS_NAME: "hiview js test suite"
741    })
742    setTimeout(() => {
743      querySysEvent({
744        beginTime: -1,
745        endTime: -1,
746        maxEvents: 5,
747      }, [{
748        domain: "RELIABILITY",
749        names: ["STACK"],
750        condition: '{"version":"V1","condition":{"and":[{"param":"PID","op":">","value":2000},' +
751          '{"param":"UID","op":"<","value":20003}]}}'
752      }], (infos) => {
753        expect(infos.length >= 0).assertTrue()
754      }, (reason, total) => {
755        expect(total >= 2).assertTrue()
756      }, (err) => {
757        expect(false).assertTrue()
758      }, done)
759    }, 2000)
760  })
761
762  /**
763   * @tc.desc: Test query sysevent with 2 conditions: != & ==.
764   * @tc.level: Level 0
765   * @tc.name: hiSysEventJsUnitTest021
766   * @tc.number: hiSysEventJsUnitTest021
767   * @tc.type: Function
768   * @tc.size: MediumTest
769   */
770  it('hiSysEventJsUnitTest021', 0, async function (done) {
771    writeCustomizedSysEvent({
772      PID: 22,
773      UID: 88888,
774      PACKAGE_NAME: "com.ohos.hiSysEventJsUnitTest021",
775      PROCESS_NAME: "hiview js test suite"
776    })
777    writeCustomizedSysEvent({
778      PID: 23,
779      UID: 88888,
780      PACKAGE_NAME: "com.ohos.hiSysEventJsUnitTest021",
781      PROCESS_NAME: "hiview js test suite"
782    })
783    writeCustomizedSysEvent({
784      PID: 24,
785      UID: 88888,
786      PACKAGE_NAME: "com.ohos.hiSysEventJsUnitTest021",
787      PROCESS_NAME: "hiview js test suite"
788    })
789    setTimeout(() => {
790      querySysEvent({
791        beginTime: -1,
792        endTime: -1,
793        maxEvents: 5,
794      }, [{
795        domain: "RELIABILITY",
796        names: ["STACK"],
797        condition: '{"version":"V1","condition":{"and":[{"param":"PID","op":"!=","value":22}, ' +
798          '{"param":"UID","op":"=","value":88888}]}}'
799      }], (infos) => {
800        expect(infos.length >= 0).assertTrue()
801      }, (reason, total) => {
802        expect(total >= 2).assertTrue()
803      }, (err) => {
804        expect(false).assertTrue()
805      }, done)
806    }, 2500)
807  })
808
809  /**
810   * @tc.desc: Test query sysevent with null condition.
811   * @tc.level: Level 0
812   * @tc.name: hiSysEventJsUnitTest022
813   * @tc.number: hiSysEventJsUnitTest022
814   * @tc.type: Function
815   * @tc.size: MediumTest
816   */
817  it('hiSysEventJsUnitTest022', 0, async function (done) {
818    setTimeout(() => {
819      querySysEvent({
820        beginTime: -1,
821        endTime: -1,
822        maxEvents: 5,
823      }, [{
824        domain: "RELIABILITY",
825        names: ["STACK"],
826        condition: null
827      }], (infos) => {
828        expect(infos.length >= 0).assertTrue()
829      }, (reason, total) => {
830        expect(total > 0).assertTrue()
831      }, (err) => {
832        expect(false).assertTrue()
833      }, done)
834    }, 2500)
835  })
836
837  /**
838   * @tc.desc: Test query sysevent with default query argument.
839   * @tc.level: Level 0
840   * @tc.name: hiSysEventJsUnitTest023
841   * @tc.number: hiSysEventJsUnitTest023
842   * @tc.type: Function
843   * @tc.size: MediumTest
844   */
845  it('hiSysEventJsUnitTest023', 0, async function (done) {
846    setTimeout(() => {
847      querySysEvent({
848        beginTime: -1,
849        endTime: -1,
850        maxEvents: -1,
851      }, [{
852        domain: "RELIABILITY",
853        names: ["STACK"],
854        condition: null
855      }], (infos) => {
856        expect(infos.length >= 0).assertTrue()
857      }, (reason, total) => {
858        expect(total > 0).assertTrue()
859      }, (err) => {
860        expect(false).assertTrue()
861      }, done)
862    }, 2500)
863  })
864
865  /**
866   * @tc.desc: Test write with integer number
867   * @tc.level: Level 0
868   * @tc.name: hiSysEventJsUnitTest024
869   * @tc.number: hiSysEventJsUnitTest024
870   * @tc.type: Function
871   * @tc.size: MediumTest
872   */
873  it('hiSysEventJsUnitTest024', 0, async function (done) {
874    writeCustomizedSysEvent({
875      PID: 2222222,
876      UID: 2222222,
877      FIRST_INT_VAL: 1,
878      SECOND_INT_VAL: -1,
879      THIRD_INT_VAL: 123456789,
880      FORTH_INT_VAL: -123456789,
881    })
882    setTimeout(() => {
883      querySysEvent({
884        beginTime: -1,
885        endTime: -1,
886        maxEvents: 1,
887      }, [{
888        domain: "RELIABILITY",
889        names: ["STACK"],
890        condition: '{"version":"V1","condition":{"and":[{"param":"PID","op":"=","value":2222222},' +
891          '{"param":"UID","op":"=","value":2222222}]}}'
892      }], (infos) => {
893        expect(infos.length >= 0).assertTrue()
894        expect(GetParam(infos[0], "FIRST_INT_VAL")).assertEqual(1)
895        expect(GetParam(infos[0], "SECOND_INT_VAL")).assertEqual(-1)
896        expect(GetParam(infos[0], "THIRD_INT_VAL")).assertEqual(123456789)
897        expect(GetParam(infos[0], "FORTH_INT_VAL")).assertEqual(-123456789)
898      }, (reason, total) => {
899        expect(total == 1).assertTrue()
900      }, (err) => {
901        expect(false).assertTrue()
902      }, done)
903    }, 1500)
904  })
905
906  /**
907   * @tc.desc: Test write with big integer number
908   * @tc.level: Level 0
909   * @tc.name: hiSysEventJsUnitTest025
910   * @tc.number: hiSysEventJsUnitTest025
911   * @tc.type: Function
912   * @tc.size: MediumTest
913   */
914  it('hiSysEventJsUnitTest025', 0, async function (done) {
915    writeCustomizedSysEvent({
916      PID: 3333333,
917      UID: 3333333,
918      FIRST_BIG_INT_VAL: 1n,
919      SECOND_BIG_INT_VAL: -1n,
920      THIRD_BIG_INT_VAL: 123456789n,
921      FORTH_BIG_INT_VAL: -123456789n,
922    })
923    setTimeout(() => {
924      querySysEvent({
925        beginTime: -1,
926        endTime: -1,
927        maxEvents: 1,
928      }, [{
929        domain: "RELIABILITY",
930        names: ["STACK"],
931        condition: '{"version":"V1","condition":{"and":[{"param":"PID","op":"=","value":3333333},' +
932          '{"param":"UID","op":"=","value":3333333}]}}'
933      }], (infos) => {
934        expect(infos.length >= 0).assertTrue()
935        expect(GetParam(infos[0], "FIRST_BIG_INT_VAL")).assertEqual(1)
936        expect(GetParam(infos[0], "SECOND_BIG_INT_VAL")).assertEqual(-1)
937        expect(GetParam(infos[0], "THIRD_BIG_INT_VAL")).assertEqual(123456789)
938        expect(GetParam(infos[0], "FORTH_BIG_INT_VAL")).assertEqual(-123456789)
939      }, (reason, total) => {
940        expect(total == 1).assertTrue()
941      }, (err) => {
942        expect(false).assertTrue()
943      }, done)
944    }, 1500)
945  })
946
947  /**
948   * @tc.desc: Test write with max or min big integer number
949   * @tc.level: Level 0
950   * @tc.name: hiSysEventJsUnitTest026
951   * @tc.number: hiSysEventJsUnitTest026
952   * @tc.type: Function
953   * @tc.size: MediumTest
954   */
955  it('hiSysEventJsUnitTest026', 0, async function (done) {
956    writeCustomizedSysEvent({
957      PID: 4444444,
958      UID: 4444444,
959      UINT64_MAX: 18446744073709551615n,
960      INT64_MAX: 9223372036854775807n,
961      INT64_MIN: -9223372036854775808n,
962    })
963    setTimeout(() => {
964      querySysEvent({
965        beginTime: -1,
966        endTime: -1,
967        maxEvents: 1,
968      }, [{
969        domain: "RELIABILITY",
970        names: ["STACK"],
971        condition: '{"version":"V1","condition":{"and":[{"param":"PID","op":"=","value":4444444},' +
972          '{"param":"UID","op":"=","value":4444444}]}}'
973      }], (infos) => {
974        expect(infos.length >= 0).assertTrue()
975        expect(GetParam(infos[0], "UINT64_MAX")).assertEqual(18446744073709551615n)
976        expect(GetParam(infos[0], "INT64_MAX")).assertEqual(9223372036854775807n)
977        expect(GetParam(infos[0], "INT64_MIN")).assertEqual(-9223372036854775808n)
978      }, (reason, total) => {
979        expect(total == 1).assertTrue()
980      }, (err) => {
981        expect(false).assertTrue()
982      }, done)
983    }, 1500)
984  })
985
986  /**
987   * @tc.desc: Test write with big integer number array
988   * @tc.level: Level 0
989   * @tc.name: hiSysEventJsUnitTest027
990   * @tc.number: hiSysEventJsUnitTest027
991   * @tc.type: Function
992   * @tc.size: MediumTest
993   */
994  it('hiSysEventJsUnitTest027', 0, async function (done) {
995    writeCustomizedSysEvent({
996      PID: 55555555,
997      UID: 55555555,
998      FIRST_BIG_INT_ARR: [4n, 5n, 6n],
999      SECOND_BIG_INT_ARR: [-4n, -5n, -6n],
1000      THIRD_BIG_INT_ARR: [123456789n, -2232333n, 2222223344n],
1001      FORTH_BIG_INT_ARR: [-123456789n, -2232333n, -2222223344n],
1002    })
1003    setTimeout(() => {
1004      querySysEvent({
1005        beginTime: -1,
1006        endTime: -1,
1007        maxEvents: 1,
1008      }, [{
1009        domain: "RELIABILITY",
1010        names: ["STACK"],
1011        condition: '{"version":"V1","condition":{"and":[{"param":"PID","op":"=","value":55555555},' +
1012          '{"param":"UID","op":"=","value":55555555}]}}'
1013      }], (infos) => {
1014        expect(infos.length >= 0).assertTrue()
1015        expect(GetArrayIemParamByIndex(infos[0], "FIRST_BIG_INT_ARR", 1)).assertEqual(5)
1016        expect(GetArrayIemParamByIndex(infos[0], "SECOND_BIG_INT_ARR", 2)).assertEqual(-6)
1017        expect(GetArrayIemParamByIndex(infos[0], "THIRD_BIG_INT_ARR", 1)).assertEqual(-2232333)
1018        expect(GetArrayIemParamByIndex(infos[0], "FORTH_BIG_INT_ARR", 2)).assertEqual(-2222223344n)
1019      }, (reason, total) => {
1020        expect(total == 1).assertTrue()
1021      }, (err) => {
1022        expect(false).assertTrue()
1023      }, done)
1024    }, 1500)
1025  })
1026
1027  /**
1028   * @tc.desc: Test write with integer number array
1029   * @tc.level: Level 0
1030   * @tc.name: hiSysEventJsUnitTest028
1031   * @tc.number: hiSysEventJsUnitTest028
1032   * @tc.type: Function
1033   * @tc.size: MediumTest
1034   */
1035    it('hiSysEventJsUnitTest028', 0, async function (done) {
1036      writeCustomizedSysEvent({
1037        PID: 66666666,
1038        UID: 66666666,
1039        FIRST_INT_ARR: [1, 2, 3],
1040        SECOND_INT_ARR: [-1, -2, -3],
1041        THIRD_INT_ARR: [123456789, -2232333, 2222223344],
1042        FORTH_INT_ARR: [-123456, 222333, -222222],
1043      })
1044      setTimeout(() => {
1045        querySysEvent({
1046          beginTime: -1,
1047          endTime: -1,
1048          maxEvents: 1,
1049        }, [{
1050          domain: "RELIABILITY",
1051          names: ["STACK"],
1052          condition: '{"version":"V1","condition":{"and":[{"param":"PID","op":"=","value":66666666},' +
1053            '{"param":"UID","op":"=","value":66666666}]}}'
1054        }], (infos) => {
1055          expect(infos.length >= 0).assertTrue()
1056          expect(GetArrayIemParamByIndex(infos[0], "FIRST_INT_ARR", 1)).assertEqual(2)
1057          expect(GetArrayIemParamByIndex(infos[0], "SECOND_INT_ARR", 2)).assertEqual(-3)
1058          expect(GetArrayIemParamByIndex(infos[0], "THIRD_INT_ARR", 1)).assertEqual(-2232333)
1059          expect(GetArrayIemParamByIndex(infos[0], "FORTH_INT_ARR", 2)).assertEqual(-222222)
1060        }, (reason, total) => {
1061          expect(total == 1).assertTrue()
1062        }, (err) => {
1063          expect(false).assertTrue()
1064        }, done)
1065      }, 1500)
1066    })
1067});