• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2021-2023 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 hiAppEventV9 from "@ohos.hiviewdfx.hiAppEvent"
17import hiAppEvent from "@ohos.hiAppEvent"
18
19import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
20
21describe('HiAppEventJsTest', function () {
22    beforeAll(function() {
23        /*
24         * @tc.setup: setup invoked before all test cases
25         */
26        console.info('HiAppEventJsTest beforeAll called')
27    })
28
29    afterAll(function() {
30        /*
31         * @tc.teardown: teardown invoked after all test cases
32         */
33        console.info('HiAppEventJsTest afterAll called')
34    })
35
36    beforeEach(function() {
37        /*
38         * @tc.setup: setup invoked before each test case
39         */
40        console.info('HiAppEventJsTest beforeEach called')
41    })
42
43    afterEach(function() {
44        /*
45         * @tc.teardown: teardown invoked after each test case
46         */
47        console.info('HiAppEventJsTest afterEach called')
48    })
49
50    const TEST_DOMAIN = 'test_domain';
51    const TEST_NAME = 'test_name';
52    const TEST_TYPE = hiAppEvent.EventType.FAULT;
53    const TEST_TYPE_V9 = hiAppEventV9.EventType.FAULT;
54    const TEST_PARAMS = {};
55
56    function simpleTrigger(curRow, curSize, holder) {
57        console.info("HiAppEventJsTest onTrigger curRow=" + curRow);
58        console.info("HiAppEventJsTest onTrigger curSize=" + curSize);
59        if (holder == null) {
60            console.info("HiAppEventJsTest onTrigger holder is null");
61        }
62    }
63
64    function simpleWriteV9Test() {
65        hiAppEventV9.write({
66            domain: "test_domain",
67            name: "test_name",
68            eventType: hiAppEventV9.EventType.FAULT,
69            params: {}
70        }, (err) => {
71            expect(err).assertNull()
72        });
73    }
74
75    function createError(code, message) {
76        return { code: code.toString(), message: message };
77    }
78
79    function createError2(name, type) {
80        return { code: "401", message: "Parameter error. The type of " + name + " must be " + type + "." };
81    }
82
83    function createError3(name) {
84        return { code: "401", message: "Parameter error. The " + name + " parameter is mandatory." };
85    }
86
87    function assertErrorEqual(actualErr, expectErr) {
88        if (expectErr) {
89            expect(actualErr.code).assertEqual(expectErr.code)
90            expect(actualErr.message).assertEqual(expectErr.message)
91        } else {
92            expect(actualErr).assertNull();
93        }
94    }
95
96    function writeTest(name, type, params, code, done) {
97        hiAppEvent.write(name, type, params, (err, value) => {
98            let result = err ? err.code : value;
99            expect(result).assertEqual(code);
100            console.info('HiAppEventJsTest writeTest end, result=' + result);
101            done();
102        });
103    }
104
105    function writeParamsTest(params, code, done) {
106        writeTest(TEST_NAME, TEST_TYPE, params, code, done);
107    }
108
109    function writeNameTest(name, code, done) {
110        writeTest(name, TEST_TYPE, TEST_PARAMS, code, done);
111    }
112
113    function writeV9Test(eventInfo, expectErr, done, hasCatch) {
114        if (hasCatch) {
115            try {
116                hiAppEventV9.write(eventInfo, (err) => {
117                    expect(err).assertNull()
118                });
119            } catch (err) {
120                assertErrorEqual(err, expectErr);
121                console.info('HiAppEventJsTest writeV9Test_catch end');
122                done();
123            }
124        } else {
125            hiAppEventV9.write(eventInfo, (err) => {
126                assertErrorEqual(err, expectErr);
127                console.info('HiAppEventJsTest writeV9Test end');
128                done();
129            });
130        }
131    }
132
133    function writeParamsV9Test(params, expectErr, done, hasCatch) {
134        let eventInfo = {
135            domain: TEST_DOMAIN,
136            name: TEST_NAME,
137            eventType: TEST_TYPE_V9,
138            params: params
139        };
140        writeV9Test(eventInfo, expectErr, done, hasCatch);
141    }
142
143    function writeDomainV9Test(domain, expectErr, done, hasCatch) {
144        let eventInfo = {
145            domain: domain,
146            name: TEST_NAME,
147            eventType: TEST_TYPE_V9,
148            params: TEST_PARAMS
149        };
150        writeV9Test(eventInfo, expectErr, done, hasCatch);
151    }
152
153    function writeNameV9Test(name, expectErr, done, hasCatch) {
154        let eventInfo = {
155            domain: TEST_DOMAIN,
156            name: name,
157            eventType: TEST_TYPE_V9,
158            params: TEST_PARAMS
159        };
160        writeV9Test(eventInfo, expectErr, done, hasCatch);
161    }
162
163    function writeTypeV9Test(type, expectErr, done, hasCatch) {
164        let eventInfo = {
165            domain: TEST_DOMAIN,
166            name: TEST_NAME,
167            eventType: type,
168            params: TEST_PARAMS
169        };
170        writeV9Test(eventInfo, expectErr, done, hasCatch);
171    }
172
173    /**
174     * @tc.name: HiAppEventJsTest001_1
175     * @tc.desc: Test the write interface using callback.
176     * @tc.type: FUNC
177     * @tc.require: issueI4BY0R
178     */
179    it('HiAppEventJsTest001_1', 0, async function (done) {
180        console.info('HiAppEventJsTest001_1 start');
181        let params = {
182            "key_int": 100,
183            "key_string": "strValue",
184            "key_bool": true,
185            "key_float": 30949.374,
186            "key_int_arr": [1, 2, 3],
187            "key_string_arr": ["a", "b", "c"],
188            "key_float_arr": [1.1, 2.2, 3.0],
189            "key_bool_arr": [true, false, true]
190        };
191        writeParamsTest(params, 0, done);
192    });
193
194    /**
195     * @tc.name: HiAppEventJsTest001_2
196     * @tc.desc: Test the write interface using callback.
197     * @tc.type: FUNC
198     * @tc.require: issueI4BY0R
199     */
200    it('HiAppEventJsTest001_2', 0, async function (done) {
201        console.info('HiAppEventJsTest001_2 start');
202        let params = {
203            "key_int": 100,
204            "key_string": "strValue",
205            "key_bool": true,
206            "key_float": 30949.374,
207            "key_int_arr": [1, 2, 3],
208            "key_string_arr": ["a", "b", "c"],
209            "key_float_arr": [1.1, 2.2, 3.0],
210            "key_bool_arr": [true, false, true]
211        };
212        writeParamsV9Test(params, null, done);
213    });
214
215    /**
216     * @tc.name: HiAppEventJsTest002_1
217     * @tc.desc: Test the write interface using promise.
218     * @tc.type: FUNC
219     * @tc.require: issueI4BY0R
220     */
221    it('HiAppEventJsTest002_1', 0, async function (done) {
222        console.info('HiAppEventJsTest002_1 start');
223        hiAppEvent.write(TEST_NAME, TEST_TYPE_V9, TEST_PARAMS).then((value) => {
224            let result = value;
225            expect(result).assertEqual(0);
226            console.info('HiAppEventJsTest002_1 succ');
227            done()
228        }).catch((err) => {
229            expect().assertFail();
230            done()
231        });
232    });
233
234    /**
235     * @tc.name: HiAppEventJsTest002_2
236     * @tc.desc: Test the write interface using promise.
237     * @tc.type: FUNC
238     * @tc.require: issueI4BY0R
239     */
240    it('HiAppEventJsTest002_2', 0, async function (done) {
241        console.info('HiAppEventJsTest002_2 start');
242        let eventInfo = {
243            domain: TEST_DOMAIN,
244            name: TEST_NAME,
245            eventType: TEST_TYPE_V9,
246            params: TEST_PARAMS
247        };
248        hiAppEventV9.write(eventInfo).then(() => {
249            console.info('HiAppEventJsTest002_2 succ');
250            done();
251        }).catch((err) => {
252            expect().assertFail();
253            done();
254        });
255    });
256
257    /**
258     * @tc.name: HiAppEventJsTest003_1
259     * @tc.desc: Error code 1 is returned when the event has an invalid key name.
260     * @tc.type: FUNC
261     * @tc.require: issueI4BY0R
262     */
263    it('HiAppEventJsTest003_1', 0, async function (done) {
264        console.info('HiAppEventJsTest003_1 start');
265        let params = {
266            "**":"ha",
267            "key_int":1,
268            "HH22":"ha",
269            "key_str":"str",
270            "":"empty",
271            "aa_":"underscore"
272        };
273        writeParamsTest(params, 1, done);
274    });
275
276    /**
277     * @tc.name: HiAppEventJsTest003_2
278     * @tc.desc: Error code 11101005 is returned when the event has an invalid key name.
279     * @tc.type: FUNC
280     * @tc.require: issueI4BY0R
281     */
282    it('HiAppEventJsTest003_2', 0, async function (done) {
283        console.info('HiAppEventJsTest003_2 start');
284        let params = {
285            "**":"ha",
286            "key_int":1,
287            "HH22":"ha",
288            "key_str":"str",
289            "":"empty",
290            "aa_":"underscore"
291        };
292        let expectErr = createError(11101005, "Invalid event parameter name.");
293        writeParamsV9Test(params, expectErr, done);
294    });
295
296    /**
297     * @tc.name: HiAppEventJsTest004_1
298     * @tc.desc: Error code 3 is returned when the event has an invalid value type.
299     * @tc.type: FUNC
300     * @tc.require: issueI4BY0R
301     */
302    it('HiAppEventJsTest004_1', 0, async function (done) {
303        console.info('HiAppEventJsTest004_1 start');
304        let params = {
305            key_1_invalid: {},
306            key_2_invalid: null,
307            key_str: "str"
308        };
309        writeParamsTest(params, 3, done);
310    });
311
312    /**
313     * @tc.name: HiAppEventJsTest004_2
314     * @tc.desc: Error code 401 is returned when the event has an invalid value type.
315     * @tc.type: FUNC
316     * @tc.require: issueI4BY0R
317     */
318    it('HiAppEventJsTest004_2', 0, async function (done) {
319        console.info('HiAppEventJsTest004_2 start');
320        let params = {
321            key_1_invalid: {},
322            key_2_invalid: null,
323            key_str: "str"
324        };
325        let expectErr = createError2("param value", "boolean|number|string|array[boolean|number|string]");
326        writeParamsV9Test(params, expectErr, done, true);
327    });
328
329    /**
330     * @tc.name: HiAppEventJsTest005_1
331     * @tc.desc: Error code 4 is returned when the event has an invalid string length.
332     * @tc.type: FUNC
333     * @tc.require: issueI4BY0R
334     */
335    it('HiAppEventJsTest005_1', 0, async function (done) {
336        console.info('HiAppEventJsTest005_1 start');
337        let longStr = "a".repeat(8 * 1024);
338        let invalidStr = "a".repeat(8 * 1024 + 1);
339        let params = {
340            key_long: longStr,
341            key_i_long: invalidStr,
342            key_long_arr: ["ha", longStr],
343            key_i_long_arr: ["ha", invalidStr],
344            key_str: "str"
345        };
346        writeParamsTest(params, 4, done);
347    });
348
349    /**
350     * @tc.name: HiAppEventJsTest005_2
351     * @tc.desc: Error code 11101004 is returned when the event has an invalid string length.
352     * @tc.type: FUNC
353     * @tc.require: issueI4BY0R
354     */
355    it('HiAppEventJsTest005_2', 0, async function (done) {
356        console.info('HiAppEventJsTest005_2 start');
357        let longStr = "a".repeat(8 * 1024);
358        let invalidStr = "a".repeat(8 * 1024 + 1);
359        let params = {
360            key_long: longStr,
361            key_i_long: invalidStr,
362            key_long_arr: ["ha", longStr],
363            key_i_long_arr: ["ha", invalidStr],
364            key_str: "str"
365        };
366        let expectErr = createError(11101004, "Invalid string length of the event parameter.");
367        writeParamsV9Test(params, expectErr, done);
368    });
369
370    /**
371     * @tc.name: HiAppEventJsTest006_1
372     * @tc.desc: Error code 5 is returned when the event has too many params.
373     * @tc.type: FUNC
374     * @tc.require: issueI4BY0R
375     */
376    it('HiAppEventJsTest006_1', 0, async function (done) {
377        console.info('HiAppEventJsTest006_1 start');
378        let params = {};
379        for (var i = 1; i <= 33; i++) {
380            params["key" + i] = "value" + i;
381        }
382        writeParamsTest(params, 5, done);
383    });
384
385    /**
386     * @tc.name: HiAppEventJsTest006_2
387     * @tc.desc: Error code 11101003 is returned when the event has too many params.
388     * @tc.type: FUNC
389     * @tc.require: issueI4BY0R
390     */
391    it('HiAppEventJsTest006_2', 0, async function (done) {
392        console.info('HiAppEventJsTest006_2 start');
393        let params = {};
394        for (var i = 1; i <= 33; i++) {
395            params["key" + i] = "value" + i;
396        }
397        let expectErr = createError(11101003, "Invalid number of event parameters.");
398        writeParamsV9Test(params, expectErr, done);
399    });
400
401    /**
402     * @tc.name: HiAppEventJsTest007_1
403     * @tc.desc: Error code 6 is returned when there is an array with too many elements.
404     * @tc.type: FUNC
405     * @tc.require: issueI4BY0R
406     */
407    it('HiAppEventJsTest007_1', 0, async function (done) {
408        console.info('HiAppEventJsTest007_1 start');
409        let longArr = new Array(100).fill(1);
410        let iLongArr = new Array(101).fill("a");
411        let params = {
412            key_long_arr: longArr,
413            key_i_long_arr: iLongArr,
414            key_str: "str"
415        };
416        writeParamsTest(params, 6, done);
417    });
418
419    /**
420     * @tc.name: HiAppEventJsTest007_2
421     * @tc.desc: Error code 11101006 is returned when there is an array with too many elements.
422     * @tc.type: FUNC
423     * @tc.require: issueI4BY0R
424     */
425    it('HiAppEventJsTest007_2', 0, async function (done) {
426        console.info('HiAppEventJsTest007_2 start');
427        let longArr = new Array(100).fill(1);
428        let iLongArr = new Array(101).fill("a");
429        let params = {
430            key_long_arr: longArr,
431            key_i_long_arr: iLongArr,
432            key_str: "str"
433        };
434        let expectErr = createError(11101006, "Invalid array length of the event parameter.");
435        writeParamsV9Test(params, expectErr, done);
436    });
437
438    /**
439     * @tc.name: HiAppEventJsTest008_1
440     * @tc.desc: Error code 7 is returned when there is an array with inconsistent or illegal parameter types.
441     * @tc.type: FUNC
442     * @tc.require: issueI4BY0R
443     */
444    it('HiAppEventJsTest008_1', 0, async function (done) {
445        console.info('HiAppEventJsTest008_1 start');
446        let params = {
447            key_arr_null: [null, null],
448            key_arr_obj: [{}],
449            key_arr_test1:[true, "ha"],
450            key_arr_test2:[123, "ha"],
451            key_str: "str"
452        };
453        writeParamsTest(params, 7, done);
454    });
455
456    /**
457     * @tc.name: HiAppEventJsTest008_2
458     * @tc.desc: Error code 401 is returned when there is an array with inconsistent or illegal parameter types.
459     * @tc.type: FUNC
460     * @tc.require: issueI4BY0R
461     */
462    it('HiAppEventJsTest008_2', 0, async function (done) {
463        console.info('HiAppEventJsTest008_2 start');
464        let params = {
465            key_arr_null: [null, null],
466            key_arr_obj: [{}],
467            key_arr_test1:[true, "ha"],
468            key_arr_test2:[123, "ha"],
469            key_str: "str"
470        };
471        let expectErr = createError2("param value", "boolean|number|string|array[boolean|number|string]");
472        writeParamsV9Test(params, expectErr, done, true);
473    });
474
475    /**
476     * @tc.name: HiAppEventJsTest009_1
477     * @tc.desc: Error code -1 is returned when the event has invalid event name.
478     * @tc.type: FUNC
479     * @tc.require: issueI4BY0R
480     */
481    it('HiAppEventJsTest009_1', 0, async function (done) {
482        console.info('HiAppEventJsTest009_1 start');
483        writeNameTest("verify_test_1.**1", -1, done);
484    });
485
486    /**
487     * @tc.name: HiAppEventJsTest009_2
488     * @tc.desc: Error code 11101002 is returned when the event has invalid event name.
489     * @tc.type: FUNC
490     * @tc.require: issueI4BY0R
491     */
492    it('HiAppEventJsTest009_2', 0, async function (done) {
493        console.info('HiAppEventJsTest009_2 start');
494        let expectErr = createError(11101002, "Invalid event name.");
495        writeNameV9Test("", expectErr, done);
496    });
497
498    /**
499     * @tc.name: HiAppEventJsTest009_3
500     * @tc.desc: Error code 11101002 is returned when the event has invalid event name.
501     * @tc.type: FUNC
502     * @tc.require: issueI4BY0R
503     */
504    it('HiAppEventJsTest009_3', 0, async function (done) {
505        console.info('HiAppEventJsTest009_3 start');
506        let expectErr = createError(11101002, "Invalid event name.");
507        writeNameV9Test("VVtt_", expectErr, done);
508    });
509
510    /**
511     * @tc.name: HiAppEventJsTest009_4
512     * @tc.desc: Error code 11101002 is returned when the event has invalid event name.
513     * @tc.type: FUNC
514     * @tc.require: issueI4BY0R
515     */
516    it('HiAppEventJsTest009_4', 0, async function (done) {
517        console.info('HiAppEventJsTest009_3 start');
518        let expectErr = createError(11101002, "Invalid event name.");
519        writeNameV9Test("a".repeat(49), expectErr, done);
520    });
521
522    /**
523     * @tc.name: HiAppEventJsTest010_1
524     * @tc.desc: Error code -2 is returned when the event has invalid eventName type, eventType type, keyValues type.
525     * @tc.type: FUNC
526     * @tc.require: issueI4BY0R
527     */
528    it('HiAppEventJsTest010_1', 0, async function (done) {
529        console.info('HiAppEventJsTest010_1 start');
530        writeTest(null, TEST_TYPE, TEST_PARAMS, -2, done);
531    });
532
533    /**
534     * @tc.name: HiAppEventJsTest010_2
535     * @tc.desc: Error code -2 is returned when the event has invalid eventName type, eventType type, keyValues type.
536     * @tc.type: FUNC
537     * @tc.require: issueI4BY0R
538     */
539    it('HiAppEventJsTest010_1', 0, async function (done) {
540        console.info('HiAppEventJsTest010_1 start');
541        writeTest(TEST_NAME, "invalid", TEST_PARAMS, -2, done);
542    });
543
544    /**
545     * @tc.name: HiAppEventJsTest010_3
546     * @tc.desc: Error code 401 is returned when the event has invalid eventName type, eventType type, keyValues type.
547     * @tc.type: FUNC
548     * @tc.require: issueI4BY0R
549     */
550    it('HiAppEventJsTest010_3', 0, async function (done) {
551        console.info('HiAppEventJsTest010_3 start');
552
553        // invalid AppEventInfo type
554        let expectErr = createError2("info", "AppEventInfo");
555        writeV9Test(null, expectErr, done, true);
556    });
557
558    /**
559     * @tc.name: HiAppEventJsTest010_4
560     * @tc.desc: Error code 401 is returned when the event has invalid eventName type, eventType type, keyValues type.
561     * @tc.type: FUNC
562     * @tc.require: issueI4BY0R
563     */
564    it('HiAppEventJsTest010_4', 0, async function (done) {
565        console.info('HiAppEventJsTest010_4 start');
566
567        // invalid event domain type
568        let expectErr = createError2("domain", "string");
569        writeDomainV9Test(true, expectErr, done, true);
570    });
571
572    /**
573     * @tc.name: HiAppEventJsTest010_5
574     * @tc.desc: Error code 401 is returned when the event has invalid eventName type, eventType type, keyValues type.
575     * @tc.type: FUNC
576     * @tc.require: issueI4BY0R
577     */
578    it('HiAppEventJsTest010_5', 0, async function (done) {
579        console.info('HiAppEventJsTest010_5 start');
580
581        // invalid event name type
582        let expectErr = createError2("name", "string");
583        writeNameV9Test(null, expectErr, done, true);
584    });
585
586    /**
587     * @tc.name: HiAppEventJsTest010_6
588     * @tc.desc: Error code 401 is returned when the event has invalid eventName type, eventType type, keyValues type.
589     * @tc.type: FUNC
590     * @tc.require: issueI4BY0R
591     */
592    it('HiAppEventJsTest010_6', 0, async function (done) {
593        console.info('HiAppEventJsTest010_6 start');
594
595        // invalid eventType type
596        let expectErr = createError2("eventType", "EventType");
597        writeTypeV9Test(-1, expectErr, done, true);
598    });
599
600    /**
601     * @tc.name: HiAppEventJsTest010_7
602     * @tc.desc: Error code 401 is returned when the event has invalid eventName type, eventType type, keyValues type.
603     * @tc.type: FUNC
604     * @tc.require: issueI4BY0R
605     */
606    it('HiAppEventJsTest010_7', 0, async function (done) {
607        console.info('HiAppEventJsTest010_7 start');
608
609        // invalid event params type
610        let expectErr = createError2("params", "object");
611        writeParamsV9Test(null, expectErr, done, true);
612    });
613
614    /**
615     * @tc.name: HiAppEventJsTest011_1
616     * @tc.desc: Error code -3 is returned when the event has invalid num of args.
617     * @tc.type: FUNC
618     * @tc.require: issueI4BY0R
619     */
620    it('HiAppEventJsTest011_1', 0, async function (done) {
621        console.info('HiAppEventJsTest011_1 start');
622        hiAppEvent.write().then(() => {
623            expect().assertFail();
624            done();
625        }).catch((err) => {
626            let result = err.code;
627            expect(result).assertEqual(-3);
628            done();
629            console.info('HiAppEventJsTest011_1 end');
630        });
631    });
632
633    /**
634     * @tc.name: HiAppEventJsTest011_2
635     * @tc.desc: Error code 401 is returned when the event has invalid num of args.
636     * @tc.type: FUNC
637     * @tc.require: issueI4BY0R
638     */
639    it('HiAppEventJsTest011_2', 0, async function (done) {
640        console.info('HiAppEventJsTest011_2 start');
641
642        // AppEventInfo not passed in
643        try {
644            hiAppEventV9.write();
645        } catch (err) {
646            let expectErr = createError3("info")
647            assertErrorEqual(err, expectErr)
648            console.info('HiAppEventJsTest011_2 end');
649        }
650        done();
651    });
652
653    /**
654     * @tc.name: HiAppEventJsTest011_3
655     * @tc.desc: Error code 401 is returned when the event has invalid num of args.
656     * @tc.type: FUNC
657     * @tc.require: issueI4BY0R
658     */
659    it('HiAppEventJsTest011_3', 0, async function (done) {
660        console.info('HiAppEventJsTest011_3 start');
661
662        // event domain not passed in
663        try {
664            hiAppEventV9.write({
665                name: TEST_NAME,
666                eventType: TEST_TYPE_V9,
667                params: TEST_PARAMS,
668            });
669        } catch (err) {
670            let expectErr = createError3("domain")
671            assertErrorEqual(err, expectErr)
672            console.info('HiAppEventJsTest011_3 end');
673        }
674        done();
675    });
676
677    /**
678     * @tc.name: HiAppEventJsTest011_4
679     * @tc.desc: Error code 401 is returned when the event has invalid num of args.
680     * @tc.type: FUNC
681     * @tc.require: issueI4BY0R
682     */
683    it('HiAppEventJsTest011_4', 0, async function (done) {
684        console.info('HiAppEventJsTest011_4 start');
685
686        // event name not passed in
687        try {
688            hiAppEventV9.write({
689                domain: TEST_DOMAIN,
690                eventType: TEST_TYPE_V9,
691                params: TEST_PARAMS,
692            });
693        } catch (err) {
694            let expectErr = createError3("name")
695            assertErrorEqual(err, expectErr)
696            console.info('HiAppEventJsTest011_4 end');
697        }
698        done();
699    });
700
701    /**
702     * @tc.name: HiAppEventJsTest011_5
703     * @tc.desc: Error code 401 is returned when the event has invalid num of args.
704     * @tc.type: FUNC
705     * @tc.require: issueI4BY0R
706     */
707    it('HiAppEventJsTest011_5', 0, async function (done) {
708        console.info('HiAppEventJsTest011_5 start');
709
710        // event type not passed in
711        try {
712            hiAppEventV9.write({
713                domain: TEST_DOMAIN,
714                name: TEST_NAME,
715                params: TEST_PARAMS,
716            });
717        } catch (err) {
718            let expectErr = createError3("eventType")
719            assertErrorEqual(err, expectErr)
720            console.info('HiAppEventJsTest011_5 end');
721        }
722        done();
723    });
724
725    /**
726     * @tc.name: HiAppEventJsTest011_6
727     * @tc.desc: Error code 401 is returned when the event has invalid num of args.
728     * @tc.type: FUNC
729     * @tc.require: issueI4BY0R
730     */
731    it('HiAppEventJsTest011_6', 0, async function (done) {
732        console.info('HiAppEventJsTest011_6 start');
733
734        // event params not passed in
735        try {
736            hiAppEventV9.write({
737                domain: TEST_DOMAIN,
738                name: TEST_NAME,
739                eventType: TEST_TYPE_V9,
740            });
741        } catch (err) {
742            let expectErr = createError3("params")
743            assertErrorEqual(err, expectErr)
744            console.info('HiAppEventJsTest011_6 end');
745        }
746        done();
747    });
748
749    /**
750     * @tc.name: HiAppEventJsTest012_1
751     * @tc.desc: Error code 11101001 is returned when the event has invalid event domain.
752     * @tc.type: FUNC
753     * @tc.require: issueI4BY0R
754     */
755    it('HiAppEventJsTest012_1', 0, async function (done) {
756        console.info('HiAppEventJsTest012_1 start');
757        let expectErr = createError(11101001, "Invalid event domain.");
758        writeDomainV9Test("domain***", expectErr, done);
759    });
760
761    /**
762     * @tc.name: HiAppEventJsTest012_2
763     * @tc.desc: Error code 11101001 is returned when the event has invalid event domain.
764     * @tc.type: FUNC
765     * @tc.require: issueI4BY0R
766     */
767    it('HiAppEventJsTest012_2', 0, async function (done) {
768        console.info('HiAppEventJsTest012_2 start');
769        let expectErr = createError(11101001, "Invalid event domain.");
770        writeDomainV9Test("domainTest", expectErr, done);
771    });
772
773    /**
774     * @tc.name: HiAppEventJsTest012_3
775     * @tc.desc: Error code 11101001 is returned when the event has invalid event domain.
776     * @tc.type: FUNC
777     * @tc.require: issueI4BY0R
778     */
779    it('HiAppEventJsTest012_3', 0, async function (done) {
780        console.info('HiAppEventJsTest012_3 start');
781        let expectErr = createError(11101001, "Invalid event domain.");
782        writeDomainV9Test("", expectErr, done);
783    });
784
785    /**
786     * @tc.name: HiAppEventJsTest012_4
787     * @tc.desc: Error code 11101001 is returned when the event has invalid event domain.
788     * @tc.type: FUNC
789     * @tc.require: issueI4BY0R
790     */
791    it('HiAppEventJsTest012_4', 0, async function (done) {
792        console.info('HiAppEventJsTest012_4 start');
793        let expectErr = createError(11101001, "Invalid event domain.");
794        writeDomainV9Test("a".repeat(17), expectErr, done);
795    });
796
797    /**
798     * @tc.name: HiAppEventJsPresetTest001_1
799     * @tc.desc: Test preset events and preset parameters.
800     * @tc.type: FUNC
801     * @tc.require: issueI4BY0R
802     */
803    it('HiAppEventJsPresetTest001_1', 0, async function (done) {
804        console.info('HiAppEventJsPresetTest001_1 start');
805        writeTest(hiAppEvent.Event.USER_LOGIN, hiAppEvent.EventType.FAULT, {
806            [hiAppEvent.Param.USER_ID]: "123456"
807        }, 0, done);
808    });
809
810    /**
811     * @tc.name: HiAppEventJsPresetTest001_2
812     * @tc.desc: Test preset events and preset parameters.
813     * @tc.type: FUNC
814     * @tc.require: issueI4BY0R
815     */
816     it('HiAppEventJsPresetTest001_2', 0, async function (done) {
817        console.info('HiAppEventJsPresetTest001_2 start');
818        writeTest(hiAppEvent.Event.USER_LOGOUT, hiAppEvent.EventType.STATISTIC, {
819            [hiAppEvent.Param.USER_ID]: "123456"
820        }, 0, done);
821    });
822
823    /**
824     * @tc.name: HiAppEventJsPresetTest001_3
825     * @tc.desc: Test preset events and preset parameters.
826     * @tc.type: FUNC
827     * @tc.require: issueI4BY0R
828     */
829     it('HiAppEventJsPresetTest001_3', 0, async function (done) {
830        console.info('HiAppEventJsPresetTest001_3 start');
831        let eventInfo = {
832            domain: TEST_DOMAIN,
833            name: hiAppEventV9.event.DISTRIBUTED_SERVICE_START,
834            eventType: hiAppEventV9.EventType.SECURITY,
835            params: {
836                [hiAppEventV9.param.DISTRIBUTED_SERVICE_NAME]: "test_service",
837                [hiAppEventV9.param.DISTRIBUTED_SERVICE_INSTANCE_ID]: "123",
838            },
839        };
840        writeV9Test(eventInfo, null, done);
841    });
842
843    /**
844     * @tc.name: HiAppEventConfigureTest001_1
845     * @tc.desc: Error code -99 is returned when the logging function is disabled.
846     * @tc.type: FUNC
847     * @tc.require: issueI4BY0R
848     */
849    it('HiAppEventConfigureTest001_1', 0, async function (done) {
850        console.info('HiAppEventConfigureTest001_1 start');
851        let res = hiAppEvent.configure({
852            disable: true
853        });
854        expect(res).assertTrue();
855
856        writeNameTest("config_test", -99, done);
857    });
858
859    /**
860     * @tc.name: HiAppEventConfigureTest001_2
861     * @tc.desc: Error code 11100001 is returned when the logging function is disabled.
862     * @tc.type: FUNC
863     * @tc.require: issueI4BY0R
864     */
865     it('HiAppEventConfigureTest001_2', 0, async function (done) {
866        console.info('HiAppEventConfigureTest001_2 start');
867        hiAppEventV9.configure({
868            disable: true
869        });
870
871        let expectErr = createError(11100001, "Function is disabled.");
872        writeNameV9Test("config_test", expectErr, done);
873    });
874
875    /**
876     * @tc.name: HiAppEventConfigureTest002
877     * @tc.desc: Correctly configure the event logging function.
878     * @tc.type: FUNC
879     * @tc.require: issueI4BY0R
880     */
881    it('HiAppEventConfigureTest002', 0, function () {
882        console.info('HiAppEventConfigureTest002 start');
883        let result = false;
884        result = hiAppEvent.configure({
885            disable: false,
886            maxStorage: "10G"
887        });
888        expect(result).assertTrue()
889
890        try {
891            hiAppEventV9.configure({
892                disable: true,
893                maxStorage: "100m"
894            });
895            hiAppEventV9.configure({
896                disable: false,
897                maxStorage: "10M"
898            });
899        } catch (err) {
900            expect().assertFail();
901        }
902
903        console.info('HiAppEventConfigureTest002 end');
904    });
905
906    /**
907     * @tc.name: HiAppEventConfigureTest003
908     * @tc.desc: Incorrectly configure the event logging function.
909     * @tc.type: FUNC
910     * @tc.require: issueI4BY0R
911     */
912    it('HiAppEventConfigureTest003', 0, function () {
913        console.info('HiAppEventConfigureTest003 start');
914        let result = true;
915
916        result = hiAppEvent.configure({
917            disable: false,
918            maxStorage: "xxx"
919        })
920        expect(result).assertFalse()
921
922        result = hiAppEvent.configure(null)
923        expect(result).assertFalse()
924
925        result = hiAppEvent.configure({
926            disable: null,
927            maxStorage: {}
928        })
929        expect(result).assertFalse()
930
931        // ConfigOption not passed in
932        try {
933            hiAppEventV9.configure();
934        } catch (err) {
935            let expectErr = createError3("config")
936            assertErrorEqual(err, expectErr)
937        }
938
939        // invalid ConfigOption type
940        function configureTest(configOption, expectErr) {
941            try {
942                hiAppEventV9.configure(configOption);
943            } catch (err) {
944                assertErrorEqual(err, expectErr)
945            }
946        }
947        let expectErr = createError2("config", "ConfigOption")
948        configureTest(null, expectErr)
949        configureTest([], expectErr)
950
951        // invalid ConfigOption.disable type
952        expectErr = createError2("disable", "boolean")
953        configureTest({ disable: 123 }, expectErr)
954
955        // invalid ConfigOption.maxStorage type
956        expectErr = createError2("maxStorage", "string")
957        configureTest({ maxStorage: null }, expectErr)
958
959        // invalid ConfigOption.maxStorage value
960        expectErr = createError(11103001, "Invalid max storage quota value.")
961        configureTest({ maxStorage: "**22" }, expectErr)
962
963        console.info('HiAppEventConfigureTest003 end');
964    });
965
966    /**
967     * @tc.name: HiAppEventClearTest001
968     * @tc.desc: clear the local data.
969     * @tc.type: FUNC
970     * @tc.require: issueI5NTOS
971     */
972    it('HiAppEventClearTest001', 0, async function (done) {
973        console.info('HiAppEventClearTest001 start');
974
975        // 1. clear data
976        let result = hiAppEventV9.clearData();
977        expect(result).assertUndefined();
978
979        // 2. write event after clear data
980        writeNameV9Test("clear_test", null, done);
981    });
982
983    /**
984     * @tc.name: HiAppEventWatcherTest001
985     * @tc.desc: invalid watcher type.
986     * @tc.type: FUNC
987     * @tc.require: issueI5LB4N
988     */
989    it('HiAppEventWatcherTest001', 0, function () {
990        console.info('HiAppEventWatcherTest001 start');
991
992        // watcher not passed in
993        let expectErr = createError3("watcher")
994        try {
995            hiAppEventV9.addWatcher();
996        } catch (err) {
997            assertErrorEqual(err, expectErr)
998        }
999        try {
1000            hiAppEventV9.removeWatcher();
1001        } catch (err) {
1002            assertErrorEqual(err, expectErr)
1003        }
1004
1005        // invalid watcher type
1006        expectErr = createError2("watcher", "Watcher")
1007        function addWatcherTypeTest(watcher) {
1008            try {
1009                hiAppEventV9.addWatcher(watcher);
1010            } catch (err) {
1011                assertErrorEqual(err, expectErr)
1012            }
1013        }
1014        function removeWatcherTypeTest(watcher) {
1015            try {
1016                hiAppEventV9.removeWatcher(watcher);
1017            } catch (err) {
1018                assertErrorEqual(err, expectErr)
1019            }
1020        }
1021        addWatcherTypeTest(null);
1022        addWatcherTypeTest(123);
1023        removeWatcherTypeTest(null);
1024        removeWatcherTypeTest(123);
1025
1026        console.info('HiAppEventWatcherTest001 end');
1027    });
1028
1029    /**
1030     * @tc.name: HiAppEventWatcherTest002
1031     * @tc.desc: invalid watcher name.
1032     * @tc.type: FUNC
1033     * @tc.require: issueI5LB4N
1034     */
1035    it('HiAppEventWatcherTest002', 0, function () {
1036        console.info('HiAppEventWatcherTest002 start');
1037
1038        // watcher name not passed in
1039        try {
1040            hiAppEventV9.addWatcher({});
1041        } catch (err) {
1042            let expectErr = createError3("name")
1043            assertErrorEqual(err, expectErr)
1044        }
1045
1046        // invalid watcher name type
1047        function watcherNameTest(name, expectErr) {
1048            try {
1049                hiAppEventV9.addWatcher({
1050                    name: name
1051                });
1052            } catch (err) {
1053                assertErrorEqual(err, expectErr)
1054            }
1055        }
1056        let expectErr = createError2("name", "string");
1057        watcherNameTest(null, expectErr);
1058        watcherNameTest(true, expectErr);
1059        watcherNameTest(123, expectErr);
1060
1061        // invalid watcher name value
1062        expectErr = createError(11102001, "Invalid watcher name.")
1063        watcherNameTest("a".repeat(33), expectErr);
1064        watcherNameTest("", expectErr);
1065        watcherNameTest("domain_***", expectErr);
1066        watcherNameTest("Domain_test", expectErr);
1067        watcherNameTest("_domain_test", expectErr);
1068
1069        console.info('HiAppEventWatcherTest002 end');
1070    });
1071
1072    /**
1073     * @tc.name: HiAppEventWatcherTest003
1074     * @tc.desc: invalid watcher trigger condition.
1075     * @tc.type: FUNC
1076     * @tc.require: issueI5LB4N
1077     */
1078    it('HiAppEventWatcherTest003', 0, function () {
1079        console.info('HiAppEventWatcherTest003 start');
1080
1081        // invalid triggerCondition type
1082        function triggerConditionTest(condition, expectErr) {
1083            try {
1084                hiAppEventV9.addWatcher({
1085                    name: "watcher",
1086                    triggerCondition: condition
1087                });
1088            } catch (err) {
1089                assertErrorEqual(err, expectErr)
1090            }
1091        }
1092        let expectErr = createError2("triggerCondition", "TriggerCondition")
1093        triggerConditionTest(null, expectErr);
1094        triggerConditionTest(123, expectErr);
1095
1096        // invalid triggerCondition.row type
1097        function rowTest(row, expectErr) {
1098            triggerConditionTest({ row: row }, expectErr);
1099        }
1100        expectErr = createError2("row", "number")
1101        rowTest(null, expectErr)
1102        rowTest("str", expectErr)
1103
1104        // invalid triggerCondition.row value
1105        expectErr = createError(11102003, "Invalid row value.")
1106        rowTest(-1, expectErr)
1107        rowTest(-100, expectErr)
1108
1109        // invalid triggerCondition.size type
1110        function sizeTest(size, expectErr) {
1111            triggerConditionTest({ size: size }, expectErr);
1112        }
1113        expectErr = createError2("size", "number")
1114        sizeTest(null, expectErr)
1115        sizeTest(true, expectErr)
1116
1117        // invalid triggerCondition.size value
1118        expectErr = createError(11102004, "Invalid size value.")
1119        sizeTest(-1, expectErr)
1120        sizeTest(-100, expectErr)
1121
1122        // invalid triggerCondition.timeout type
1123        function timeoutTest(timeout) {
1124            triggerConditionTest({ timeout: timeout }, expectErr);
1125        }
1126        expectErr = createError2("timeout", "number")
1127        timeoutTest(null, expectErr)
1128        timeoutTest({}, expectErr)
1129
1130        // invalid triggerCondition.timeout value
1131        expectErr = createError(11102005, "Invalid timeout value.")
1132        timeoutTest(-1, expectErr)
1133        timeoutTest(-100, expectErr)
1134
1135        console.info('HiAppEventWatcherTest003 end');
1136    });
1137
1138    /**
1139     * @tc.name: HiAppEventWatcherTest004
1140     * @tc.desc: invalid watcher filters.
1141     * @tc.type: FUNC
1142     * @tc.require: issueI5LB4N
1143     */
1144    it('HiAppEventWatcherTest004', 0, function () {
1145        console.info('HiAppEventWatcherTest004 start');
1146
1147        // invalid appEventFilters type
1148        function appEventFiltersTest(filters, expectErr) {
1149            try {
1150                hiAppEventV9.addWatcher({
1151                    name: "watcher",
1152                    appEventFilters: filters
1153                });
1154            } catch (err) {
1155                assertErrorEqual(err, expectErr)
1156            }
1157        }
1158        let expectErr = createError2("appEventFilters", "AppEventFilter[]")
1159        appEventFiltersTest(null, expectErr)
1160        appEventFiltersTest({}, expectErr)
1161        appEventFiltersTest("invalid", expectErr)
1162        appEventFiltersTest([1, 2], expectErr)
1163        appEventFiltersTest(["str1", "str2"], expectErr)
1164
1165        // appEventFilter.domain not passed in
1166        function appEventFilterTest(filter, expectErr) {
1167            appEventFiltersTest([filter], expectErr)
1168        }
1169        expectErr = createError3("domain")
1170        appEventFilterTest({}, expectErr)
1171
1172        // invalid appEventFilter.domain type
1173        function domainTest(domain, expectErr) {
1174            appEventFilterTest({ domain: domain }, expectErr)
1175        }
1176        expectErr = createError2("domain", "string")
1177        domainTest(null, expectErr)
1178        domainTest(123, expectErr)
1179
1180        // invalid appEventFilter.domain value
1181        expectErr = createError(11102002, "Invalid filtering event domain.")
1182        domainTest("**xx", expectErr)
1183        domainTest("123test", expectErr)
1184        domainTest("a".repeat(17), expectErr)
1185        domainTest("", expectErr)
1186
1187        // invalid appEventFilter.eventTypes type
1188        function eventTypesTest(eventTypes, expectErr) {
1189            appEventFilterTest({
1190                domain: "test_domain",
1191                eventTypes: eventTypes
1192            }, expectErr)
1193        }
1194        expectErr = createError2("eventTypes", "EventType[]")
1195        eventTypesTest(null, expectErr)
1196        eventTypesTest("invalid", expectErr)
1197        eventTypesTest(["invalid"], expectErr)
1198        eventTypesTest([10, -1], expectErr)
1199
1200        console.info('HiAppEventWatcherTest004 end');
1201    });
1202
1203    /**
1204     * @tc.name: HiAppEventWatcherTest005
1205     * @tc.desc: invalid watcher onTrigger.
1206     * @tc.type: FUNC
1207     * @tc.require: issueI5LB4N
1208     */
1209    it('HiAppEventWatcherTest005', 0, function () {
1210        console.info('HiAppEventWatcherTest005 start');
1211
1212        function onTriggerTest(onTrigger, expectErr) {
1213            try {
1214                hiAppEventV9.addWatcher({
1215                    name: "watcher",
1216                    onTrigger: onTrigger
1217                });
1218            } catch (err) {
1219                assertErrorEqual(err, expectErr)
1220            }
1221        }
1222        let expectErr = createError2("onTrigger", "function")
1223        onTriggerTest(null, expectErr)
1224        onTriggerTest("invalid", expectErr)
1225
1226        console.info('HiAppEventWatcherTest005 end');
1227    });
1228
1229    /**
1230     * @tc.name: HiAppEventWatcherTest006
1231     * @tc.desc: add valid watcher.
1232     * @tc.type: FUNC
1233     * @tc.require: issueI5LB4N
1234     */
1235    it('HiAppEventWatcherTest006', 0, function () {
1236        console.info('HiAppEventWatcherTest006 start');
1237        let result = true;
1238        let watcher1 = {
1239            name: "watcher1",
1240        };
1241        result = hiAppEventV9.addWatcher(watcher1);
1242        expect(result != null).assertTrue()
1243
1244        let watcher2 = {
1245            name: "watcher2",
1246            triggerCondition: {}
1247        };
1248        result = hiAppEventV9.addWatcher(watcher2);
1249        expect(result != null).assertTrue()
1250
1251        let watcher3 = {
1252            name: "watcher3",
1253            triggerCondition: {
1254                row: 5
1255            },
1256            onTrigger: simpleTrigger
1257        };
1258        result = hiAppEventV9.addWatcher(watcher3);
1259        expect(result != null).assertTrue()
1260
1261        let watcher4 = {
1262            name: "watcher4",
1263            triggerCondition: {
1264                size: 1000
1265            },
1266            onTrigger: simpleTrigger
1267        };
1268        result = hiAppEventV9.addWatcher(watcher4);
1269        expect(result != null).assertTrue()
1270
1271        let watcher5 = {
1272            name: "watcher5",
1273            triggerCondition: {
1274                timeOut: 2
1275            },
1276            onTrigger: simpleTrigger
1277        };
1278        result = hiAppEventV9.addWatcher(watcher5);
1279        expect(result != null).assertTrue()
1280
1281        let watcher6 = {
1282            name: "watcher6",
1283            triggerCondition: {
1284                row: 5,
1285                size: 1000,
1286                timeOut: 2
1287            },
1288            onTrigger: simpleTrigger
1289        };
1290        result = hiAppEventV9.addWatcher(watcher6);
1291        expect(result != null).assertTrue()
1292
1293        let watcher7 = {
1294            name: "watcher7",
1295            appEventFilters: []
1296        };
1297        result = hiAppEventV9.addWatcher(watcher7);
1298        expect(result != null).assertTrue()
1299
1300        let watcher8 = {
1301            name: "watcher8",
1302            appEventFilters: [
1303                {domain: "domain_test", eventTypes: []},
1304                {domain: "default", eventTypes: [hiAppEventV9.EventType.FAULT, hiAppEventV9.EventType.BEHAVIOR]},
1305            ]
1306        };
1307        result = hiAppEventV9.addWatcher(watcher8);
1308        expect(result != null).assertTrue()
1309
1310        hiAppEventV9.removeWatcher(watcher1);
1311        hiAppEventV9.removeWatcher(watcher2);
1312        hiAppEventV9.removeWatcher(watcher3);
1313        hiAppEventV9.removeWatcher(watcher4);
1314        hiAppEventV9.removeWatcher(watcher5);
1315        hiAppEventV9.removeWatcher(watcher6);
1316        hiAppEventV9.removeWatcher(watcher7);
1317        hiAppEventV9.removeWatcher(watcher8);
1318        console.info('HiAppEventWatcherTest006 end');
1319    });
1320
1321    /**
1322     * @tc.name: HiAppEventWatcherTest007
1323     * @tc.desc: watcher.onTrigger row test.
1324     * @tc.type: FUNC
1325     * @tc.require: issueI5KYYI
1326     */
1327    it('HiAppEventWatcherTest007', 0, async function (done) {
1328        console.info('HiAppEventWatcherTest007 start');
1329        let watcher = {
1330            name: "watcher",
1331            triggerCondition: {
1332                row: 1
1333            },
1334            onTrigger: function (curRow, curSize, holder) {
1335                console.info('HiAppEventWatcherTest007.onTrigger start');
1336                expect(curRow).assertEqual(1)
1337                expect(curSize > 0).assertTrue()
1338                expect(holder != null).assertTrue()
1339
1340                let eventPkg = holder.takeNext();
1341                expect(eventPkg != null).assertTrue()
1342                expect(eventPkg.packageId).assertEqual(0)
1343                expect(eventPkg.row).assertEqual(1)
1344                expect(eventPkg.size > 0).assertTrue()
1345                expect(eventPkg.data.length).assertEqual(1)
1346                expect(eventPkg.data[0].length > 0).assertTrue()
1347                console.info('HiAppEventWatcherTest007.onTrigger end');
1348            }
1349        };
1350        let result = hiAppEventV9.addWatcher(watcher);
1351        expect(result != null).assertTrue()
1352
1353        simpleWriteV9Test();
1354
1355        setTimeout(() => {
1356            hiAppEventV9.removeWatcher(watcher);
1357            console.info('HiAppEventWatcherTest007 end');
1358            done();
1359        }, 1000);
1360    });
1361
1362    /**
1363     * @tc.name: HiAppEventWatcherTest008
1364     * @tc.desc: watcher.onTrigger size test.
1365     * @tc.type: FUNC
1366     * @tc.require: issueI5KYYI
1367     */
1368    it('HiAppEventWatcherTest008', 0, async function (done) {
1369        console.info('HiAppEventWatcherTest008 start');
1370        let watcher = {
1371            name: "watcher",
1372            triggerCondition: {
1373                row: 10,
1374                size: 200,
1375            },
1376            onTrigger: function (curRow, curSize, holder) {
1377                console.info('HiAppEventWatcherTest008.onTrigger start');
1378                expect(curRow).assertEqual(2)
1379                expect(curSize >= 200).assertTrue()
1380                expect(holder != null).assertTrue()
1381
1382                let eventPkg = holder.takeNext();
1383                expect(eventPkg != null).assertTrue()
1384                expect(eventPkg.packageId).assertEqual(0)
1385                expect(eventPkg.row).assertEqual(2)
1386                expect(eventPkg.size >= 200).assertTrue()
1387                expect(eventPkg.data.length).assertEqual(2)
1388                expect(eventPkg.data[0].length > 0).assertTrue()
1389                expect(eventPkg.data[1].length > 0).assertTrue()
1390                console.info('HiAppEventWatcherTest008.onTrigger end');
1391            }
1392        };
1393        let result = hiAppEventV9.addWatcher(watcher);
1394        expect(result != null).assertTrue()
1395
1396        simpleWriteV9Test();
1397        simpleWriteV9Test();
1398
1399        setTimeout(() => {
1400            hiAppEventV9.removeWatcher(watcher);
1401            console.info('HiAppEventWatcherTest008 end');
1402            done();
1403        }, 1000);
1404    });
1405
1406    /**
1407     * @tc.name: HiAppEventWatcherTest009
1408     * @tc.desc: watcher.onTrigger timeout test.
1409     * @tc.type: FUNC
1410     * @tc.require: issueI5KYYI
1411     */
1412    it('HiAppEventWatcherTest009', 0, async function (done) {
1413        console.info('HiAppEventWatcherTest009 start');
1414        let watcher = {
1415            name: "watcher",
1416            triggerCondition: {
1417                timeOut: 1
1418            },
1419            onTrigger: function (curRow, curSize, holder) {
1420                console.info('HiAppEventWatcherTest009.onTrigger start');
1421                expect(curRow).assertEqual(1)
1422                expect(curSize > 0).assertTrue()
1423                expect(holder != null).assertTrue()
1424
1425                let eventPkg = holder.takeNext();
1426                expect(eventPkg != null).assertTrue()
1427                expect(eventPkg.packageId).assertEqual(0)
1428                expect(eventPkg.row).assertEqual(1)
1429                expect(eventPkg.size > 0).assertTrue()
1430                expect(eventPkg.data.length).assertEqual(1)
1431                expect(eventPkg.data[0].length > 0).assertTrue()
1432                console.info('HiAppEventWatcherTest009.onTrigger end');
1433            }
1434        };
1435        let result = hiAppEventV9.addWatcher(watcher);
1436        expect(result != null).assertTrue()
1437
1438        simpleWriteV9Test();
1439
1440        setTimeout(() => {
1441            hiAppEventV9.removeWatcher(watcher);
1442            console.info('HiAppEventWatcherTest009 end');
1443            done();
1444        }, 3000);
1445    });
1446
1447    /**
1448     * @tc.name: HiAppEventWatcherTest010
1449     * @tc.desc: watcher.holder test.
1450     * @tc.type: FUNC
1451     * @tc.require: issueI5NTOD
1452     */
1453    it('HiAppEventWatcherTest010', 0, async function (done) {
1454        console.info('HiAppEventWatcherTest010 start');
1455        let watcher = {
1456            name: "watcher",
1457        };
1458        let holder = hiAppEventV9.addWatcher(watcher);
1459        expect(holder != null).assertTrue()
1460
1461        simpleWriteV9Test();
1462
1463        setTimeout(() => {
1464            let eventPkg = holder.takeNext();
1465            expect(eventPkg != null).assertTrue();
1466            expect(eventPkg.packageId).assertEqual(0);
1467            expect(eventPkg.row).assertEqual(1);
1468            expect(eventPkg.size > 0).assertTrue();
1469            expect(eventPkg.data.length).assertEqual(1);
1470            expect(eventPkg.data[0].length > 0).assertTrue();
1471            hiAppEventV9.removeWatcher(watcher);
1472            console.info('HiAppEventWatcherTest010 end');
1473            done();
1474        }, 1000);
1475    });
1476
1477    /**
1478     * @tc.name: HiAppEventWatcherTest011
1479     * @tc.desc: invalid watcher.holder test.
1480     * @tc.type: FUNC
1481     * @tc.require: issueI5NTOD
1482     */
1483    it('HiAppEventWatcherTest011', 0, function () {
1484        console.info('HiAppEventWatcherTest011 start');
1485        let watcher = {
1486            name: "watcher",
1487        };
1488        let holder = hiAppEventV9.addWatcher(watcher);
1489        expect(holder != null).assertTrue()
1490
1491        // size not passed in
1492        try {
1493            holder.setSize()
1494        } catch (err) {
1495            let expectErr = createError3("size");
1496            assertErrorEqual(err, expectErr)
1497        }
1498
1499        // invalid size type
1500        function holderSetSizeTest(holder, size, expectErr) {
1501            try {
1502                holder.setSize(size)
1503            } catch (err) {
1504                assertErrorEqual(err, expectErr)
1505            }
1506        }
1507        let expectErr = createError2("size", "number");
1508        holderSetSizeTest(holder, null, expectErr);
1509        holderSetSizeTest(holder, {}, expectErr);
1510
1511        // invalid size value
1512        expectErr = createError(11104001, "Invalid size value.");
1513        holderSetSizeTest(holder, -1, expectErr);
1514        holderSetSizeTest(holder, -100, expectErr);
1515
1516        hiAppEventV9.removeWatcher(watcher)
1517        console.info('HiAppEventWatcherTest011 end')
1518    });
1519});