1/* 2 * Copyright (C) 2021-2025 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 function setEventConfigV9Test(name, configInfo, expectErr, done) { 174 hiAppEventV9.setEventConfig(name, configInfo).then((data) => { 175 expect(data).assertEqual(0); 176 done(); 177 }).catch((err) => { 178 assertErrorEqual(err, expectErr); 179 done(); 180 }); 181 } 182 183 function setEventConfigV9TestCatch(name, configInfo, expectErr, done) { 184 try { 185 setEventConfigV9Test(name, configInfo, expectErr, done); 186 } catch (err) { 187 assertErrorEqual(err, expectErr); 188 done(); 189 } 190 } 191 192 /** 193 * @tc.number HiAppEventJsTest001_1 194 * @tc.name: HiAppEventJsTest001_1 195 * @tc.desc: Test the write interface using callback. 196 * @tc.type: FUNC 197 * @tc.require: issueI4BY0R 198 */ 199 it('HiAppEventJsTest001_1', 0, async function (done) { 200 console.info('HiAppEventJsTest001_1 start'); 201 let params = { 202 "key_int": 100, 203 "key_string": "strValue", 204 "key_bool": true, 205 "key_float": 30949.374, 206 "key_int_arr": [1, 2, 3], 207 "key_string_arr": ["a", "b", "c"], 208 "key_float_arr": [1.1, 2.2, 3.0], 209 "key_bool_arr": [true, false, true] 210 }; 211 writeParamsTest(params, 0, done); 212 }); 213 214 /** 215 * @tc.number HiAppEventJsTest001_2 216 * @tc.name: HiAppEventJsTest001_2 217 * @tc.desc: Test the write interface using callback. 218 * @tc.type: FUNC 219 * @tc.require: issueI4BY0R 220 */ 221 it('HiAppEventJsTest001_2', 0, async function (done) { 222 console.info('HiAppEventJsTest001_2 start'); 223 let params = { 224 "key_int": 100, 225 "key_string": "strValue", 226 "key_bool": true, 227 "key_float": 30949.374, 228 "key_int_arr": [1, 2, 3], 229 "key_string_arr": ["a", "b", "c"], 230 "key_float_arr": [1.1, 2.2, 3.0], 231 "key_bool_arr": [true, false, true] 232 }; 233 writeParamsV9Test(params, null, done); 234 }); 235 236 /** 237 * @tc.number HiAppEventJsTest002_1 238 * @tc.name: HiAppEventJsTest002_1 239 * @tc.desc: Test the write interface using promise. 240 * @tc.type: FUNC 241 * @tc.require: issueI4BY0R 242 */ 243 it('HiAppEventJsTest002_1', 0, async function (done) { 244 console.info('HiAppEventJsTest002_1 start'); 245 hiAppEvent.write(TEST_NAME, TEST_TYPE_V9, TEST_PARAMS).then((value) => { 246 let result = value; 247 expect(result).assertEqual(0); 248 console.info('HiAppEventJsTest002_1 succ'); 249 done() 250 }).catch((err) => { 251 expect().assertFail(); 252 done() 253 }); 254 }); 255 256 /** 257 * @tc.number HiAppEventJsTest002_2 258 * @tc.name: HiAppEventJsTest002_2 259 * @tc.desc: Test the write interface using promise. 260 * @tc.type: FUNC 261 * @tc.require: issueI4BY0R 262 */ 263 it('HiAppEventJsTest002_2', 0, async function (done) { 264 console.info('HiAppEventJsTest002_2 start'); 265 let eventInfo = { 266 domain: TEST_DOMAIN, 267 name: TEST_NAME, 268 eventType: TEST_TYPE_V9, 269 params: TEST_PARAMS 270 }; 271 hiAppEventV9.write(eventInfo).then(() => { 272 console.info('HiAppEventJsTest002_2 succ'); 273 done(); 274 }).catch((err) => { 275 expect().assertFail(); 276 done(); 277 }); 278 }); 279 280 /** 281 * @tc.number HiAppEventJsTest003_1 282 * @tc.name: HiAppEventJsTest003_1 283 * @tc.desc: Error code 1 is returned when the event has an invalid key name. 284 * @tc.type: FUNC 285 * @tc.require: issueI4BY0R 286 */ 287 it('HiAppEventJsTest003_1', 0, async function (done) { 288 console.info('HiAppEventJsTest003_1 start'); 289 let params = { 290 "**":"ha", 291 "key_int":1, 292 "HH22":"ha", 293 "key_str":"str", 294 "":"empty", 295 "aa_":"underscore" 296 }; 297 writeParamsTest(params, 1, done); 298 }); 299 300 /** 301 * @tc.number HiAppEventJsTest003_2 302 * @tc.name: HiAppEventJsTest003_2 303 * @tc.desc: Error code 11101005 is returned when the event has an invalid key name. 304 * @tc.type: FUNC 305 * @tc.require: issueI4BY0R 306 */ 307 it('HiAppEventJsTest003_2', 0, async function (done) { 308 console.info('HiAppEventJsTest003_2 start'); 309 let params = { 310 "**":"ha", 311 "key_int":1, 312 "HH22":"ha", 313 "key_str":"str", 314 "":"empty", 315 "aa_":"underscore" 316 }; 317 let expectErr = createError(11101005, "Invalid event parameter name. Possible causes: 1. Contain invalid " + 318 "characters; 2. Length is invalid."); 319 writeParamsV9Test(params, expectErr, done); 320 321 const MAX_LENGTH_OF_PARAM_NAME = 32; 322 params = {}; 323 params['a'.repeat(MAX_LENGTH_OF_PARAM_NAME + 1)] = "value"; 324 writeParamsV9Test(params, expectErr, done); 325 326 params = {}; 327 params['a'.repeat(MAX_LENGTH_OF_PARAM_NAME - 1) + "_"] = "value"; 328 writeParamsV9Test(params, expectErr, done); 329 330 params = {}; 331 params['a'.repeat(MAX_LENGTH_OF_PARAM_NAME)] = "value"; 332 writeParamsV9Test(params, null, done); 333 }); 334 335 /** 336 * @tc.number HiAppEventJsTest004_1 337 * @tc.name: HiAppEventJsTest004_1 338 * @tc.desc: Error code 3 is returned when the event has an invalid value type. 339 * @tc.type: FUNC 340 * @tc.require: issueI4BY0R 341 */ 342 it('HiAppEventJsTest004_1', 0, async function (done) { 343 console.info('HiAppEventJsTest004_1 start'); 344 let params = { 345 key_1_invalid: {}, 346 key_2_invalid: null, 347 key_str: "str" 348 }; 349 writeParamsTest(params, 3, done); 350 }); 351 352 /** 353 * @tc.number HiAppEventJsTest004_2 354 * @tc.name: HiAppEventJsTest004_2 355 * @tc.desc: Error code 401 is returned when the event has an invalid value type. 356 * @tc.type: FUNC 357 * @tc.require: issueI4BY0R 358 */ 359 it('HiAppEventJsTest004_2', 0, async function (done) { 360 console.info('HiAppEventJsTest004_2 start'); 361 let params = { 362 key_1_invalid: {}, 363 key_2_invalid: null, 364 key_str: "str" 365 }; 366 let expectErr = createError2("param value", "boolean|number|string|array[boolean|number|string]"); 367 writeParamsV9Test(params, expectErr, done, true); 368 }); 369 370 /** 371 * @tc.number HiAppEventJsTest005_1 372 * @tc.name: HiAppEventJsTest005_1 373 * @tc.desc: Error code 4 is returned when the event has an invalid string length. 374 * @tc.type: FUNC 375 * @tc.require: issueI4BY0R 376 */ 377 it('HiAppEventJsTest005_1', 0, async function (done) { 378 console.info('HiAppEventJsTest005_1 start'); 379 let longStr = "a".repeat(8 * 1024); 380 let invalidStr = "a".repeat(8 * 1024 + 1); 381 let params = { 382 key_long: longStr, 383 key_i_long: invalidStr, 384 key_long_arr: ["ha", longStr], 385 key_i_long_arr: ["ha", invalidStr], 386 key_str: "str" 387 }; 388 writeParamsTest(params, 4, done); 389 }); 390 391 /** 392 * @tc.number HiAppEventJsTest005_2 393 * @tc.name: HiAppEventJsTest005_2 394 * @tc.desc: Error code 11101004 is returned when the event has an invalid string length. 395 * @tc.type: FUNC 396 * @tc.require: issueI4BY0R 397 */ 398 it('HiAppEventJsTest005_2', 0, async function (done) { 399 console.info('HiAppEventJsTest005_2 start'); 400 let longStr = "a".repeat(8 * 1024); 401 let invalidStr = "a".repeat(8 * 1024 + 1); 402 let params = { 403 key_long: longStr, 404 key_i_long: invalidStr, 405 key_long_arr: ["ha", longStr], 406 key_i_long_arr: ["ha", invalidStr], 407 key_str: "str" 408 }; 409 let expectErr = createError(11101004, "Invalid string length of the event parameter."); 410 writeParamsV9Test(params, expectErr, done); 411 }); 412 413 /** 414 * @tc.number HiAppEventJsTest006_1 415 * @tc.name: HiAppEventJsTest006_1 416 * @tc.desc: Error code 5 is returned when the event has too many params. 417 * @tc.type: FUNC 418 * @tc.require: issueI4BY0R 419 */ 420 it('HiAppEventJsTest006_1', 0, async function (done) { 421 console.info('HiAppEventJsTest006_1 start'); 422 let params = {}; 423 for (var i = 1; i <= 33; i++) { 424 params["key" + i] = "value" + i; 425 } 426 writeParamsTest(params, 5, done); 427 }); 428 429 /** 430 * @tc.number HiAppEventJsTest006_2 431 * @tc.name: HiAppEventJsTest006_2 432 * @tc.desc: Error code 11101003 is returned when the event has too many params. 433 * @tc.type: FUNC 434 * @tc.require: issueI4BY0R 435 */ 436 it('HiAppEventJsTest006_2', 0, async function (done) { 437 console.info('HiAppEventJsTest006_2 start'); 438 let params = {}; 439 for (var i = 1; i <= 33; i++) { 440 params["key" + i] = "value" + i; 441 } 442 let expectErr = createError(11101003, "Invalid number of event parameters. Possible caused by the number of " + 443 "parameters is over 32."); 444 writeParamsV9Test(params, expectErr, done); 445 }); 446 447 /** 448 * @tc.number HiAppEventJsTest007_1 449 * @tc.name: HiAppEventJsTest007_1 450 * @tc.desc: Error code 6 is returned when there is an array with too many elements. 451 * @tc.type: FUNC 452 * @tc.require: issueI4BY0R 453 */ 454 it('HiAppEventJsTest007_1', 0, async function (done) { 455 console.info('HiAppEventJsTest007_1 start'); 456 let longArr = new Array(100).fill(1); 457 let iLongArr = new Array(101).fill("a"); 458 let params = { 459 key_long_arr: longArr, 460 key_i_long_arr: iLongArr, 461 key_str: "str" 462 }; 463 writeParamsTest(params, 6, done); 464 }); 465 466 /** 467 * @tc.number HiAppEventJsTest007_2 468 * @tc.name: HiAppEventJsTest007_2 469 * @tc.desc: Error code 11101006 is returned when there is an array with too many elements. 470 * @tc.type: FUNC 471 * @tc.require: issueI4BY0R 472 */ 473 it('HiAppEventJsTest007_2', 0, async function (done) { 474 console.info('HiAppEventJsTest007_2 start'); 475 let longArr = new Array(100).fill(1); 476 let iLongArr = new Array(101).fill("a"); 477 let params = { 478 key_long_arr: longArr, 479 key_i_long_arr: iLongArr, 480 key_str: "str" 481 }; 482 let expectErr = createError(11101006, "Invalid array length of the event parameter."); 483 writeParamsV9Test(params, expectErr, done); 484 }); 485 486 /** 487 * @tc.number HiAppEventJsTest008_1 488 * @tc.name: HiAppEventJsTest008_1 489 * @tc.desc: Error code 7 is returned when there is an array with inconsistent or illegal parameter types. 490 * @tc.type: FUNC 491 * @tc.require: issueI4BY0R 492 */ 493 it('HiAppEventJsTest008_1', 0, async function (done) { 494 console.info('HiAppEventJsTest008_1 start'); 495 let params = { 496 key_arr_null: [null, null], 497 key_arr_obj: [{}], 498 key_arr_test1:[true, "ha"], 499 key_arr_test2:[123, "ha"], 500 key_str: "str" 501 }; 502 writeParamsTest(params, 7, done); 503 }); 504 505 /** 506 * @tc.number HiAppEventJsTest008_2 507 * @tc.name: HiAppEventJsTest008_2 508 * @tc.desc: Error code 401 is returned when there is an array with inconsistent or illegal parameter types. 509 * @tc.type: FUNC 510 * @tc.require: issueI4BY0R 511 */ 512 it('HiAppEventJsTest008_2', 0, async function (done) { 513 console.info('HiAppEventJsTest008_2 start'); 514 let params = { 515 key_arr_null: [null, null], 516 key_arr_obj: [{}], 517 key_arr_test1:[true, "ha"], 518 key_arr_test2:[123, "ha"], 519 key_str: "str" 520 }; 521 let expectErr = createError2("param value", "boolean|number|string|array[boolean|number|string]"); 522 writeParamsV9Test(params, expectErr, done, true); 523 }); 524 525 /** 526 * @tc.number HiAppEventJsTest009_1 527 * @tc.name: HiAppEventJsTest009_1 528 * @tc.desc: Error code -1 is returned when the event has invalid event name. 529 * @tc.type: FUNC 530 * @tc.require: issueI4BY0R 531 */ 532 it('HiAppEventJsTest009_1', 0, async function (done) { 533 console.info('HiAppEventJsTest009_1 start'); 534 writeNameTest("verify_test_1.**1", -1, done); 535 }); 536 537 /** 538 * @tc.number HiAppEventJsTest009_2 539 * @tc.name: HiAppEventJsTest009_2 540 * @tc.desc: Error code 11101002 is returned when the event has invalid event name. 541 * @tc.type: FUNC 542 * @tc.require: issueI4BY0R 543 */ 544 it('HiAppEventJsTest009_2', 0, async function (done) { 545 console.info('HiAppEventJsTest009_2 start'); 546 let expectErr = createError(11101002, "Invalid event name. Possible causes: 1. Contain invalid characters; " + 547 "2. Length is invalid."); 548 writeNameV9Test("", expectErr, done); 549 }); 550 551 /** 552 * @tc.number HiAppEventJsTest009_3 553 * @tc.name: HiAppEventJsTest009_3 554 * @tc.desc: Error code 11101002 is returned when the event has invalid event name. 555 * @tc.type: FUNC 556 * @tc.require: issueI4BY0R 557 */ 558 it('HiAppEventJsTest009_3', 0, async function (done) { 559 console.info('HiAppEventJsTest009_3 start'); 560 let expectErr = createError(11101002, "Invalid event name. Possible causes: 1. Contain invalid characters; " + 561 "2. Length is invalid."); 562 writeNameV9Test("VVtt_", expectErr, done); 563 }); 564 565 /** 566 * @tc.number HiAppEventJsTest009_4 567 * @tc.name: HiAppEventJsTest009_4 568 * @tc.desc: Error code 11101002 is returned when the event has invalid event name. 569 * @tc.type: FUNC 570 * @tc.require: issueI4BY0R 571 */ 572 it('HiAppEventJsTest009_4', 0, async function (done) { 573 console.info('HiAppEventJsTest009_3 start'); 574 const MAX_LENGTH_OF_EVENT_NAME = 48; 575 let expectErr = createError(11101002, "Invalid event name. Possible causes: 1. Contain invalid characters; " + 576 "2. Length is invalid."); 577 writeNameV9Test("a".repeat(MAX_LENGTH_OF_EVENT_NAME + 1), expectErr, done); 578 579 writeNameV9Test("a".repeat(MAX_LENGTH_OF_EVENT_NAME - 1) + "_", expectErr, done); 580 581 writeNameV9Test("a".repeat(MAX_LENGTH_OF_EVENT_NAME), null, done); 582 }); 583 584 /** 585 * @tc.number HiAppEventJsTest010_1 586 * @tc.name: HiAppEventJsTest010_1 587 * @tc.desc: Error code -2 is returned when the event has invalid eventName type, eventType type, keyValues type. 588 * @tc.type: FUNC 589 * @tc.require: issueI4BY0R 590 */ 591 it('HiAppEventJsTest010_1', 0, async function (done) { 592 console.info('HiAppEventJsTest010_1 start'); 593 writeTest(null, TEST_TYPE, TEST_PARAMS, -2, done); 594 }); 595 596 /** 597 * @tc.number HiAppEventJsTest010_2 598 * @tc.name: HiAppEventJsTest010_2 599 * @tc.desc: Error code -2 is returned when the event has invalid eventName type, eventType type, keyValues type. 600 * @tc.type: FUNC 601 * @tc.require: issueI4BY0R 602 */ 603 it('HiAppEventJsTest010_1', 0, async function (done) { 604 console.info('HiAppEventJsTest010_1 start'); 605 writeTest(TEST_NAME, "invalid", TEST_PARAMS, -2, done); 606 }); 607 608 /** 609 * @tc.number HiAppEventJsTest010_3 610 * @tc.name: HiAppEventJsTest010_3 611 * @tc.desc: Error code 401 is returned when the event has invalid eventName type, eventType type, keyValues type. 612 * @tc.type: FUNC 613 * @tc.require: issueI4BY0R 614 */ 615 it('HiAppEventJsTest010_3', 0, async function (done) { 616 console.info('HiAppEventJsTest010_3 start'); 617 618 // invalid AppEventInfo type 619 let expectErr = createError2("info", "AppEventInfo"); 620 writeV9Test(null, expectErr, done, true); 621 }); 622 623 /** 624 * @tc.number HiAppEventJsTest010_4 625 * @tc.name: HiAppEventJsTest010_4 626 * @tc.desc: Error code 401 is returned when the event has invalid eventName type, eventType type, keyValues type. 627 * @tc.type: FUNC 628 * @tc.require: issueI4BY0R 629 */ 630 it('HiAppEventJsTest010_4', 0, async function (done) { 631 console.info('HiAppEventJsTest010_4 start'); 632 633 // invalid event domain type 634 let expectErr = createError2("domain", "string"); 635 writeDomainV9Test(true, expectErr, done, true); 636 }); 637 638 /** 639 * @tc.number HiAppEventJsTest010_5 640 * @tc.name: HiAppEventJsTest010_5 641 * @tc.desc: Error code 401 is returned when the event has invalid eventName type, eventType type, keyValues type. 642 * @tc.type: FUNC 643 * @tc.require: issueI4BY0R 644 */ 645 it('HiAppEventJsTest010_5', 0, async function (done) { 646 console.info('HiAppEventJsTest010_5 start'); 647 648 // invalid event name type 649 let expectErr = createError2("name", "string"); 650 writeNameV9Test(null, expectErr, done, true); 651 }); 652 653 /** 654 * @tc.number HiAppEventJsTest010_6 655 * @tc.name: HiAppEventJsTest010_6 656 * @tc.desc: Error code 401 is returned when the event has invalid eventName type, eventType type, keyValues type. 657 * @tc.type: FUNC 658 * @tc.require: issueI4BY0R 659 */ 660 it('HiAppEventJsTest010_6', 0, async function (done) { 661 console.info('HiAppEventJsTest010_6 start'); 662 663 // invalid eventType type 664 let expectErr = createError2("eventType", "EventType"); 665 writeTypeV9Test(-1, expectErr, done, true); 666 }); 667 668 /** 669 * @tc.number HiAppEventJsTest010_7 670 * @tc.name: HiAppEventJsTest010_7 671 * @tc.desc: Error code 401 is returned when the event has invalid eventName type, eventType type, keyValues type. 672 * @tc.type: FUNC 673 * @tc.require: issueI4BY0R 674 */ 675 it('HiAppEventJsTest010_7', 0, async function (done) { 676 console.info('HiAppEventJsTest010_7 start'); 677 678 // invalid event params type 679 let expectErr = createError2("params", "object"); 680 writeParamsV9Test(null, expectErr, done, true); 681 }); 682 683 /** 684 * @tc.number HiAppEventJsTest011_1 685 * @tc.name: HiAppEventJsTest011_1 686 * @tc.desc: Error code -3 is returned when the event has invalid num of args. 687 * @tc.type: FUNC 688 * @tc.require: issueI4BY0R 689 */ 690 it('HiAppEventJsTest011_1', 0, async function (done) { 691 console.info('HiAppEventJsTest011_1 start'); 692 hiAppEvent.write().then(() => { 693 expect().assertFail(); 694 done(); 695 }).catch((err) => { 696 let result = err.code; 697 expect(result).assertEqual(-3); 698 done(); 699 console.info('HiAppEventJsTest011_1 end'); 700 }); 701 }); 702 703 /** 704 * @tc.number HiAppEventJsTest011_2 705 * @tc.name: HiAppEventJsTest011_2 706 * @tc.desc: Error code 401 is returned when the event has invalid num of args. 707 * @tc.type: FUNC 708 * @tc.require: issueI4BY0R 709 */ 710 it('HiAppEventJsTest011_2', 0, async function (done) { 711 console.info('HiAppEventJsTest011_2 start'); 712 713 // AppEventInfo not passed in 714 try { 715 hiAppEventV9.write(); 716 } catch (err) { 717 let expectErr = createError3("info") 718 assertErrorEqual(err, expectErr) 719 console.info('HiAppEventJsTest011_2 end'); 720 } 721 done(); 722 }); 723 724 /** 725 * @tc.number HiAppEventJsTest011_3 726 * @tc.name: HiAppEventJsTest011_3 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_3', 0, async function (done) { 732 console.info('HiAppEventJsTest011_3 start'); 733 734 // event domain not passed in 735 try { 736 hiAppEventV9.write({ 737 name: TEST_NAME, 738 eventType: TEST_TYPE_V9, 739 params: TEST_PARAMS, 740 }); 741 } catch (err) { 742 let expectErr = createError3("domain") 743 assertErrorEqual(err, expectErr) 744 console.info('HiAppEventJsTest011_3 end'); 745 } 746 done(); 747 }); 748 749 /** 750 * @tc.number HiAppEventJsTest011_4 751 * @tc.name: HiAppEventJsTest011_4 752 * @tc.desc: Error code 401 is returned when the event has invalid num of args. 753 * @tc.type: FUNC 754 * @tc.require: issueI4BY0R 755 */ 756 it('HiAppEventJsTest011_4', 0, async function (done) { 757 console.info('HiAppEventJsTest011_4 start'); 758 759 // event name not passed in 760 try { 761 hiAppEventV9.write({ 762 domain: TEST_DOMAIN, 763 eventType: TEST_TYPE_V9, 764 params: TEST_PARAMS, 765 }); 766 } catch (err) { 767 let expectErr = createError3("name") 768 assertErrorEqual(err, expectErr) 769 console.info('HiAppEventJsTest011_4 end'); 770 } 771 done(); 772 }); 773 774 /** 775 * @tc.number HiAppEventJsTest011_5 776 * @tc.name: HiAppEventJsTest011_5 777 * @tc.desc: Error code 401 is returned when the event has invalid num of args. 778 * @tc.type: FUNC 779 * @tc.require: issueI4BY0R 780 */ 781 it('HiAppEventJsTest011_5', 0, async function (done) { 782 console.info('HiAppEventJsTest011_5 start'); 783 784 // event type not passed in 785 try { 786 hiAppEventV9.write({ 787 domain: TEST_DOMAIN, 788 name: TEST_NAME, 789 params: TEST_PARAMS, 790 }); 791 } catch (err) { 792 let expectErr = createError3("eventType") 793 assertErrorEqual(err, expectErr) 794 console.info('HiAppEventJsTest011_5 end'); 795 } 796 done(); 797 }); 798 799 /** 800 * @tc.number HiAppEventJsTest011_6 801 * @tc.name: HiAppEventJsTest011_6 802 * @tc.desc: Error code 401 is returned when the event has invalid num of args. 803 * @tc.type: FUNC 804 * @tc.require: issueI4BY0R 805 */ 806 it('HiAppEventJsTest011_6', 0, async function (done) { 807 console.info('HiAppEventJsTest011_6 start'); 808 809 // event params not passed in 810 try { 811 hiAppEventV9.write({ 812 domain: TEST_DOMAIN, 813 name: TEST_NAME, 814 eventType: TEST_TYPE_V9, 815 }); 816 } catch (err) { 817 let expectErr = createError3("params") 818 assertErrorEqual(err, expectErr) 819 console.info('HiAppEventJsTest011_6 end'); 820 } 821 done(); 822 }); 823 824 /** 825 * @tc.number HiAppEventJsTest012 826 * @tc.name: HiAppEventJsTest012 827 * @tc.desc: Test event domain. 828 * @tc.type: FUNC 829 * @tc.require: issueI4BY0R 830 */ 831 it('HiAppEventJsTest012', 0, async function (done) { 832 console.info('HiAppEventJsTest012 start'); 833 834 const MAX_LEN_OF_DOMAIN = 32; 835 // Error code 11101001 is returned when the event has invalid event domain. 836 let expectErr = createError(11101001, "Invalid event domain. Possible causes: 1. Contain invalid characters; " + 837 "2. Length is invalid."); 838 writeDomainV9Test("domain***", expectErr, done); 839 writeDomainV9Test("123domain", expectErr, done); 840 writeDomainV9Test("_domain", expectErr, done); 841 writeDomainV9Test("domain_", expectErr, done); 842 writeDomainV9Test("a".repeat(MAX_LEN_OF_DOMAIN - 1) + "_", expectErr, done); 843 writeDomainV9Test("", expectErr, done); 844 writeDomainV9Test("a".repeat(MAX_LEN_OF_DOMAIN + 1), expectErr, done); 845 846 // valid event domain. 847 writeDomainV9Test("a", null, done); 848 writeDomainV9Test("a1", null, done); 849 writeDomainV9Test("domainTest", null, done); 850 writeDomainV9Test("a".repeat(MAX_LEN_OF_DOMAIN), null, done); 851 }); 852 853 /** 854 * @tc.number HiAppEventJsTest013 855 * @tc.name: HiAppEventJsTest013 856 * @tc.desc: The number of event params exceeds 32 and invalid params exist. 857 * @tc.type: FUNC 858 * @tc.require: issueI8GWHC 859 */ 860 it('HiAppEventJsTest013', 0, async function (done) { 861 console.info('HiAppEventJsTest013 start'); 862 let params = {}; 863 for (var i = 1; i <= 33; i++) { 864 params["key" + i] = "value" + i; 865 } 866 let invalidKey = 'a'.repeat(17); 867 params[invalidKey] = 'value_invalid'; 868 let expectErr = createError(11101003, "Invalid number of event parameters. Possible caused by the number of " + 869 "parameters is over 32."); 870 writeParamsV9Test(params, expectErr, done); 871 }); 872 873 /** 874 * @tc.number HiAppEventJsTest014 875 * @tc.name: HiAppEventJsTest014 876 * @tc.desc: The number of event params exceeds 32 and invalid params exist. 877 * @tc.type: FUNC 878 * @tc.require: issueI8GWHC 879 */ 880 it('HiAppEventJsTest014', 0, async function (done) { 881 console.info('HiAppEventJsTest014 start'); 882 let params = {}; 883 params["123xxx"] = "value_invalid"; // invalid param name 884 params["xxx_"] = "value_invalid"; // invalid param name 885 for (var i = 1; i <= 33; i++) { 886 params["key" + i] = "value" + i; 887 } 888 params['a'.repeat(33)] = 'value_invalid'; // invalid param name 889 let expectErr = createError(11101003, "Invalid number of event parameters. Possible caused by the number of " + 890 "parameters is over 32."); 891 writeParamsV9Test(params, expectErr, done); 892 }); 893 894 /** 895 * @tc.number HiAppEventJsPresetTest001_1 896 * @tc.name: HiAppEventJsPresetTest001_1 897 * @tc.desc: Test preset events and preset parameters. 898 * @tc.type: FUNC 899 * @tc.require: issueI4BY0R 900 */ 901 it('HiAppEventJsPresetTest001_1', 0, async function (done) { 902 console.info('HiAppEventJsPresetTest001_1 start'); 903 writeTest(hiAppEvent.Event.USER_LOGIN, hiAppEvent.EventType.FAULT, { 904 [hiAppEvent.Param.USER_ID]: "123456" 905 }, 0, done); 906 }); 907 908 /** 909 * @tc.number HiAppEventJsPresetTest001_2 910 * @tc.name: HiAppEventJsPresetTest001_2 911 * @tc.desc: Test preset events and preset parameters. 912 * @tc.type: FUNC 913 * @tc.require: issueI4BY0R 914 */ 915 it('HiAppEventJsPresetTest001_2', 0, async function (done) { 916 console.info('HiAppEventJsPresetTest001_2 start'); 917 writeTest(hiAppEvent.Event.USER_LOGOUT, hiAppEvent.EventType.STATISTIC, { 918 [hiAppEvent.Param.USER_ID]: "123456" 919 }, 0, done); 920 }); 921 922 /** 923 * @tc.number HiAppEventJsPresetTest001_3 924 * @tc.name: HiAppEventJsPresetTest001_3 925 * @tc.desc: Test preset events and preset parameters. 926 * @tc.type: FUNC 927 * @tc.require: issueI4BY0R 928 */ 929 it('HiAppEventJsPresetTest001_3', 0, async function (done) { 930 console.info('HiAppEventJsPresetTest001_3 start'); 931 let eventInfo = { 932 domain: TEST_DOMAIN, 933 name: hiAppEventV9.event.DISTRIBUTED_SERVICE_START, 934 eventType: hiAppEventV9.EventType.SECURITY, 935 params: { 936 [hiAppEventV9.param.DISTRIBUTED_SERVICE_NAME]: "test_service", 937 [hiAppEventV9.param.DISTRIBUTED_SERVICE_INSTANCE_ID]: "123", 938 }, 939 }; 940 writeV9Test(eventInfo, null, done); 941 }); 942 943 /** 944 * @tc.number HiAppEventConfigureTest001_1 945 * @tc.name: HiAppEventConfigureTest001_1 946 * @tc.desc: Error code -99 is returned when the logging function is disabled. 947 * @tc.type: FUNC 948 * @tc.require: issueI4BY0R 949 */ 950 it('HiAppEventConfigureTest001_1', 0, async function (done) { 951 console.info('HiAppEventConfigureTest001_1 start'); 952 let res = hiAppEvent.configure({ 953 disable: true 954 }); 955 expect(res).assertTrue(); 956 957 writeNameTest("config_test", -99, done); 958 }); 959 960 /** 961 * @tc.number HiAppEventConfigureTest001_2 962 * @tc.name: HiAppEventConfigureTest001_2 963 * @tc.desc: Error code 11100001 is returned when the logging function is disabled. 964 * @tc.type: FUNC 965 * @tc.require: issueI4BY0R 966 */ 967 it('HiAppEventConfigureTest001_2', 0, async function (done) { 968 console.info('HiAppEventConfigureTest001_2 start'); 969 hiAppEventV9.configure({ 970 disable: true 971 }); 972 973 let expectErr = createError(11100001, "Function disabled. Possible caused by the param disable in " + 974 "ConfigOption is true."); 975 writeNameV9Test("config_test", expectErr, done); 976 }); 977 978 /** 979 * @tc.number HiAppEventConfigureTest002 980 * @tc.name: HiAppEventConfigureTest002 981 * @tc.desc: Correctly configure the event logging function. 982 * @tc.type: FUNC 983 * @tc.require: issueI4BY0R 984 */ 985 it('HiAppEventConfigureTest002', 0, function () { 986 console.info('HiAppEventConfigureTest002 start'); 987 let result = false; 988 result = hiAppEvent.configure({ 989 disable: false, 990 maxStorage: "10G" 991 }); 992 expect(result).assertTrue() 993 994 try { 995 hiAppEventV9.configure({ 996 disable: true, 997 maxStorage: "100m" 998 }); 999 hiAppEventV9.configure({ 1000 disable: false, 1001 maxStorage: "10M" 1002 }); 1003 } catch (err) { 1004 expect().assertFail(); 1005 } 1006 1007 console.info('HiAppEventConfigureTest002 end'); 1008 }); 1009 1010 /** 1011 * @tc.number HiAppEventConfigureTest003 1012 * @tc.name: HiAppEventConfigureTest003 1013 * @tc.desc: Incorrectly configure the event logging function. 1014 * @tc.type: FUNC 1015 * @tc.require: issueI4BY0R 1016 */ 1017 it('HiAppEventConfigureTest003', 0, function () { 1018 console.info('HiAppEventConfigureTest003 start'); 1019 let result = true; 1020 1021 result = hiAppEvent.configure({ 1022 disable: false, 1023 maxStorage: "xxx" 1024 }) 1025 expect(result).assertFalse() 1026 1027 result = hiAppEvent.configure(null) 1028 expect(result).assertFalse() 1029 1030 result = hiAppEvent.configure({ 1031 disable: null, 1032 maxStorage: {} 1033 }) 1034 expect(result).assertFalse() 1035 1036 // ConfigOption not passed in 1037 try { 1038 hiAppEventV9.configure(); 1039 } catch (err) { 1040 let expectErr = createError3("config") 1041 assertErrorEqual(err, expectErr) 1042 } 1043 1044 // invalid ConfigOption type 1045 function configureTest(configOption, expectErr) { 1046 try { 1047 hiAppEventV9.configure(configOption); 1048 } catch (err) { 1049 assertErrorEqual(err, expectErr) 1050 } 1051 } 1052 let expectErr = createError2("config", "ConfigOption") 1053 configureTest(null, expectErr) 1054 configureTest([], expectErr) 1055 1056 // invalid ConfigOption.disable type 1057 expectErr = createError2("disable", "boolean") 1058 configureTest({ disable: 123 }, expectErr) 1059 1060 // invalid ConfigOption.maxStorage type 1061 expectErr = createError2("maxStorage", "string") 1062 configureTest({ maxStorage: null }, expectErr) 1063 1064 // invalid ConfigOption.maxStorage value 1065 expectErr = createError(11103001, "Invalid max storage quota value. Possible caused by incorrectly formatted.") 1066 configureTest({ maxStorage: "**22" }, expectErr) 1067 1068 console.info('HiAppEventConfigureTest003 end'); 1069 }); 1070 1071 /** 1072 * @tc.number HiAppEventClearTest001 1073 * @tc.name: HiAppEventClearTest001 1074 * @tc.desc: clear the local data. 1075 * @tc.type: FUNC 1076 * @tc.require: issueI5NTOS 1077 */ 1078 it('HiAppEventClearTest001', 0, async function (done) { 1079 console.info('HiAppEventClearTest001 start'); 1080 1081 // 1. clear data 1082 let result = hiAppEventV9.clearData(); 1083 expect(result).assertUndefined(); 1084 1085 // 2. write event after clear data 1086 writeNameV9Test("clear_test", null, done); 1087 }); 1088 1089 /** 1090 * @tc.number HiAppEventWatcherTest001 1091 * @tc.name: HiAppEventWatcherTest001 1092 * @tc.desc: invalid watcher type. 1093 * @tc.type: FUNC 1094 * @tc.require: issueI5LB4N 1095 */ 1096 it('HiAppEventWatcherTest001', 0, function () { 1097 console.info('HiAppEventWatcherTest001 start'); 1098 1099 // watcher not passed in 1100 let expectErr = createError3("watcher") 1101 try { 1102 hiAppEventV9.addWatcher(); 1103 } catch (err) { 1104 assertErrorEqual(err, expectErr) 1105 } 1106 try { 1107 hiAppEventV9.removeWatcher(); 1108 } catch (err) { 1109 assertErrorEqual(err, expectErr) 1110 } 1111 1112 // invalid watcher type 1113 expectErr = createError2("watcher", "Watcher") 1114 function addWatcherTypeTest(watcher) { 1115 try { 1116 hiAppEventV9.addWatcher(watcher); 1117 } catch (err) { 1118 assertErrorEqual(err, expectErr) 1119 } 1120 } 1121 function removeWatcherTypeTest(watcher) { 1122 try { 1123 hiAppEventV9.removeWatcher(watcher); 1124 } catch (err) { 1125 assertErrorEqual(err, expectErr) 1126 } 1127 } 1128 addWatcherTypeTest(null); 1129 addWatcherTypeTest(123); 1130 removeWatcherTypeTest(null); 1131 removeWatcherTypeTest(123); 1132 1133 console.info('HiAppEventWatcherTest001 end'); 1134 }); 1135 1136 /** 1137 * @tc.number HiAppEventWatcherTest002 1138 * @tc.name: HiAppEventWatcherTest002 1139 * @tc.desc: invalid watcher name. 1140 * @tc.type: FUNC 1141 * @tc.require: issueI5LB4N 1142 */ 1143 it('HiAppEventWatcherTest002', 0, function () { 1144 console.info('HiAppEventWatcherTest002 start'); 1145 1146 // watcher name not passed in 1147 try { 1148 hiAppEventV9.addWatcher({}); 1149 } catch (err) { 1150 let expectErr = createError3("name") 1151 assertErrorEqual(err, expectErr) 1152 } 1153 1154 // invalid watcher name type 1155 function watcherNameTest(name, expectErr) { 1156 try { 1157 hiAppEventV9.addWatcher({ 1158 name: name 1159 }); 1160 } catch (err) { 1161 assertErrorEqual(err, expectErr) 1162 } 1163 } 1164 let expectErr = createError2("name", "string"); 1165 watcherNameTest(null, expectErr); 1166 watcherNameTest(true, expectErr); 1167 watcherNameTest(123, expectErr); 1168 1169 const MAX_LEN_OF_WATCHER = 32; 1170 // invalid watcher name value 1171 expectErr = createError(11102001, "Invalid watcher name. Possible causes: 1. Contain invalid characters; " + 1172 "2. Length is invalid.") 1173 watcherNameTest("a".repeat(MAX_LEN_OF_WATCHER + 1), expectErr); 1174 watcherNameTest("", expectErr); 1175 watcherNameTest("watcher_***", expectErr); 1176 watcherNameTest("Watcher_test", null); 1177 watcherNameTest("_watcher_test", expectErr); 1178 watcherNameTest("watcher_", expectErr); 1179 watcherNameTest("123watcher", expectErr); 1180 watcherNameTest("a".repeat(MAX_LEN_OF_WATCHER - 1) + "_", expectErr); 1181 watcherNameTest("a", null); 1182 watcherNameTest("a1", null); 1183 watcherNameTest("a".repeat(MAX_LEN_OF_WATCHER), null); 1184 1185 console.info('HiAppEventWatcherTest002 end'); 1186 }); 1187 1188 /** 1189 * @tc.number HiAppEventWatcherTest003 1190 * @tc.name: HiAppEventWatcherTest003 1191 * @tc.desc: invalid watcher trigger condition. 1192 * @tc.type: FUNC 1193 * @tc.require: issueI5LB4N 1194 */ 1195 it('HiAppEventWatcherTest003', 0, function () { 1196 console.info('HiAppEventWatcherTest003 start'); 1197 1198 // invalid triggerCondition type 1199 function triggerConditionTest(condition, expectErr) { 1200 try { 1201 hiAppEventV9.addWatcher({ 1202 name: "watcher", 1203 triggerCondition: condition 1204 }); 1205 } catch (err) { 1206 assertErrorEqual(err, expectErr) 1207 } 1208 } 1209 let expectErr = createError2("triggerCondition", "TriggerCondition") 1210 triggerConditionTest(null, expectErr); 1211 triggerConditionTest(123, expectErr); 1212 1213 // invalid triggerCondition.row type 1214 function rowTest(row, expectErr) { 1215 triggerConditionTest({ row: row }, expectErr); 1216 } 1217 expectErr = createError2("row", "number") 1218 rowTest(null, expectErr) 1219 rowTest("str", expectErr) 1220 1221 // invalid triggerCondition.row value 1222 expectErr = createError(11102003, "Invalid row value. Possible caused by the row value is less than zero.") 1223 rowTest(-1, expectErr) 1224 rowTest(-100, expectErr) 1225 1226 // invalid triggerCondition.size type 1227 function sizeTest(size, expectErr) { 1228 triggerConditionTest({ size: size }, expectErr); 1229 } 1230 expectErr = createError2("size", "number") 1231 sizeTest(null, expectErr) 1232 sizeTest(true, expectErr) 1233 1234 // invalid triggerCondition.size value 1235 expectErr = createError(11102004, "Invalid size value. Possible caused by the size value is less than zero."); 1236 sizeTest(-1, expectErr) 1237 sizeTest(-100, expectErr) 1238 1239 // invalid triggerCondition.timeout type 1240 function timeoutTest(timeout) { 1241 triggerConditionTest({ timeout: timeout }, expectErr); 1242 } 1243 expectErr = createError2("timeout", "number") 1244 timeoutTest(null, expectErr) 1245 timeoutTest({}, expectErr) 1246 1247 // invalid triggerCondition.timeout value 1248 expectErr = createError(11102005, "Invalid timeout value. Possible caused by the timeout value is less than " + 1249 "zero.") 1250 timeoutTest(-1, expectErr) 1251 timeoutTest(-100, expectErr) 1252 1253 console.info('HiAppEventWatcherTest003 end'); 1254 }); 1255 1256 /** 1257 * @tc.number HiAppEventWatcherTest004 1258 * @tc.name: HiAppEventWatcherTest004 1259 * @tc.desc: invalid watcher filters. 1260 * @tc.type: FUNC 1261 * @tc.require: issueI5LB4N 1262 */ 1263 it('HiAppEventWatcherTest004', 0, function () { 1264 console.info('HiAppEventWatcherTest004 start'); 1265 1266 // invalid appEventFilters type 1267 function appEventFiltersTest(filters, expectErr) { 1268 try { 1269 hiAppEventV9.addWatcher({ 1270 name: "watcher", 1271 appEventFilters: filters 1272 }); 1273 } catch (err) { 1274 assertErrorEqual(err, expectErr) 1275 } 1276 } 1277 let expectErr = createError2("appEventFilters", "AppEventFilter[]") 1278 appEventFiltersTest(null, expectErr) 1279 appEventFiltersTest({}, expectErr) 1280 appEventFiltersTest("invalid", expectErr) 1281 appEventFiltersTest([1, 2], expectErr) 1282 appEventFiltersTest(["str1", "str2"], expectErr) 1283 1284 // appEventFilter.domain not passed in 1285 function appEventFilterTest(filter, expectErr) { 1286 appEventFiltersTest([filter], expectErr) 1287 } 1288 expectErr = createError3("domain") 1289 appEventFilterTest({}, expectErr) 1290 1291 // invalid appEventFilter.domain type 1292 function domainTest(domain, expectErr) { 1293 appEventFilterTest({ domain: domain }, expectErr) 1294 } 1295 expectErr = createError2("domain", "string") 1296 domainTest(null, expectErr) 1297 domainTest(123, expectErr) 1298 1299 // invalid appEventFilter.domain value 1300 expectErr = createError(11102002, "Invalid filtering event domain. Possible causes: 1. Contain invalid " + 1301 "characters; 2. Length is invalid.") 1302 domainTest("**xx", expectErr) 1303 domainTest("123test", expectErr) 1304 domainTest("test_", expectErr) 1305 domainTest("a".repeat(33), expectErr) 1306 domainTest("", expectErr) 1307 domainTest("a", null) 1308 domainTest("a1", null) 1309 domainTest("Domain_1", null) 1310 1311 // invalid appEventFilter.eventTypes type 1312 function eventTypesTest(eventTypes, expectErr) { 1313 appEventFilterTest({ 1314 domain: "test_domain", 1315 eventTypes: eventTypes 1316 }, expectErr) 1317 } 1318 expectErr = createError2("eventTypes", "EventType[]") 1319 eventTypesTest(null, expectErr) 1320 eventTypesTest("invalid", expectErr) 1321 eventTypesTest(["invalid"], expectErr) 1322 eventTypesTest([10, -1], expectErr) 1323 1324 console.info('HiAppEventWatcherTest004 end'); 1325 }); 1326 1327 /** 1328 * @tc.number HiAppEventWatcherTest005 1329 * @tc.name: HiAppEventWatcherTest005 1330 * @tc.desc: invalid watcher onTrigger. 1331 * @tc.type: FUNC 1332 * @tc.require: issueI5LB4N 1333 */ 1334 it('HiAppEventWatcherTest005', 0, function () { 1335 console.info('HiAppEventWatcherTest005 start'); 1336 1337 function onTriggerTest(onTrigger, expectErr) { 1338 try { 1339 hiAppEventV9.addWatcher({ 1340 name: "watcher", 1341 onTrigger: onTrigger 1342 }); 1343 } catch (err) { 1344 assertErrorEqual(err, expectErr) 1345 } 1346 } 1347 let expectErr = createError2("onTrigger", "function") 1348 onTriggerTest(null, expectErr) 1349 onTriggerTest("invalid", expectErr) 1350 1351 console.info('HiAppEventWatcherTest005 end'); 1352 }); 1353 1354 /** 1355 * @tc.number HiAppEventWatcherTest006 1356 * @tc.name: HiAppEventWatcherTest006 1357 * @tc.desc: add valid watcher. 1358 * @tc.type: FUNC 1359 * @tc.require: issueI5LB4N 1360 */ 1361 it('HiAppEventWatcherTest006', 0, function () { 1362 console.info('HiAppEventWatcherTest006 start'); 1363 let result = true; 1364 let watcher1 = { 1365 name: "watcher1", 1366 }; 1367 result = hiAppEventV9.addWatcher(watcher1); 1368 expect(result != null).assertTrue() 1369 1370 let watcher2 = { 1371 name: "watcher2", 1372 triggerCondition: {} 1373 }; 1374 result = hiAppEventV9.addWatcher(watcher2); 1375 expect(result != null).assertTrue() 1376 1377 let watcher3 = { 1378 name: "watcher3", 1379 triggerCondition: { 1380 row: 5 1381 }, 1382 onTrigger: simpleTrigger 1383 }; 1384 result = hiAppEventV9.addWatcher(watcher3); 1385 expect(result != null).assertTrue() 1386 1387 let watcher4 = { 1388 name: "watcher4", 1389 triggerCondition: { 1390 size: 1000 1391 }, 1392 onTrigger: simpleTrigger 1393 }; 1394 result = hiAppEventV9.addWatcher(watcher4); 1395 expect(result != null).assertTrue() 1396 1397 let watcher5 = { 1398 name: "watcher5", 1399 triggerCondition: { 1400 timeOut: 2 1401 }, 1402 onTrigger: simpleTrigger 1403 }; 1404 result = hiAppEventV9.addWatcher(watcher5); 1405 expect(result != null).assertTrue() 1406 1407 let watcher6 = { 1408 name: "watcher6", 1409 triggerCondition: { 1410 row: 5, 1411 size: 1000, 1412 timeOut: 2 1413 }, 1414 onTrigger: simpleTrigger 1415 }; 1416 result = hiAppEventV9.addWatcher(watcher6); 1417 expect(result != null).assertTrue() 1418 1419 let watcher7 = { 1420 name: "watcher7", 1421 appEventFilters: [] 1422 }; 1423 result = hiAppEventV9.addWatcher(watcher7); 1424 expect(result != null).assertTrue() 1425 1426 let watcher8 = { 1427 name: "watcher8", 1428 appEventFilters: [ 1429 {domain: "domain_test", eventTypes: []}, 1430 {domain: "default", eventTypes: [hiAppEventV9.EventType.FAULT, hiAppEventV9.EventType.BEHAVIOR]}, 1431 ] 1432 }; 1433 result = hiAppEventV9.addWatcher(watcher8); 1434 expect(result != null).assertTrue() 1435 1436 hiAppEventV9.removeWatcher(watcher1); 1437 hiAppEventV9.removeWatcher(watcher2); 1438 hiAppEventV9.removeWatcher(watcher3); 1439 hiAppEventV9.removeWatcher(watcher4); 1440 hiAppEventV9.removeWatcher(watcher5); 1441 hiAppEventV9.removeWatcher(watcher6); 1442 hiAppEventV9.removeWatcher(watcher7); 1443 hiAppEventV9.removeWatcher(watcher8); 1444 console.info('HiAppEventWatcherTest006 end'); 1445 }); 1446 1447 /** 1448 * @tc.number HiAppEventWatcherTest007 1449 * @tc.name: HiAppEventWatcherTest007 1450 * @tc.desc: watcher.onTrigger row test. 1451 * @tc.type: FUNC 1452 * @tc.require: issueI5KYYI 1453 */ 1454 it('HiAppEventWatcherTest007', 0, async function (done) { 1455 console.info('HiAppEventWatcherTest007 start'); 1456 let watcher = { 1457 name: "watcher_007", 1458 appEventFilters: [ 1459 { domain: TEST_DOMAIN }, 1460 ], 1461 triggerCondition: { 1462 row: 1 1463 }, 1464 onTrigger: function (curRow, curSize, holder) { 1465 console.info('HiAppEventWatcherTest007.onTrigger start'); 1466 expect(curRow).assertEqual(1) 1467 expect(curSize > 0).assertTrue() 1468 expect(holder != null).assertTrue() 1469 1470 let eventPkg = holder.takeNext(); 1471 expect(eventPkg != null).assertTrue() 1472 expect(eventPkg.packageId).assertEqual(0) 1473 expect(eventPkg.row).assertEqual(1) 1474 expect(eventPkg.size > 0).assertTrue() 1475 expect(eventPkg.data.length).assertEqual(1) 1476 expect(eventPkg.data[0].length > 0).assertTrue() 1477 console.info('HiAppEventWatcherTest007.onTrigger end'); 1478 } 1479 }; 1480 let result = hiAppEventV9.addWatcher(watcher); 1481 expect(result != null).assertTrue() 1482 1483 simpleWriteV9Test(); 1484 1485 setTimeout(() => { 1486 hiAppEventV9.removeWatcher(watcher); 1487 console.info('HiAppEventWatcherTest007 end'); 1488 done(); 1489 }, 1000); 1490 }); 1491 1492 /** 1493 * @tc.number HiAppEventWatcherTest008 1494 * @tc.name: HiAppEventWatcherTest008 1495 * @tc.desc: watcher.onTrigger size test. 1496 * @tc.type: FUNC 1497 * @tc.require: issueI5KYYI 1498 */ 1499 it('HiAppEventWatcherTest008', 0, async function (done) { 1500 console.info('HiAppEventWatcherTest008 start'); 1501 let watcher = { 1502 name: "watcher_008", 1503 appEventFilters: [ 1504 { domain: TEST_DOMAIN }, 1505 ], 1506 triggerCondition: { 1507 row: 10, 1508 size: 200, 1509 }, 1510 onTrigger: function (curRow, curSize, holder) { 1511 console.info('HiAppEventWatcherTest008.onTrigger start'); 1512 expect(curRow).assertEqual(2) 1513 expect(curSize >= 200).assertTrue() 1514 expect(holder != null).assertTrue() 1515 1516 holder.setSize(curSize); 1517 let eventPkg = holder.takeNext(); 1518 expect(eventPkg != null).assertTrue() 1519 expect(eventPkg.packageId).assertEqual(0) 1520 expect(eventPkg.row).assertEqual(2) 1521 expect(eventPkg.size >= 200).assertTrue() 1522 expect(eventPkg.data.length).assertEqual(2) 1523 expect(eventPkg.data[0].length > 0).assertTrue() 1524 expect(eventPkg.data[1].length > 0).assertTrue() 1525 console.info('HiAppEventWatcherTest008.onTrigger end'); 1526 } 1527 }; 1528 let result = hiAppEventV9.addWatcher(watcher); 1529 expect(result != null).assertTrue() 1530 1531 simpleWriteV9Test(); 1532 simpleWriteV9Test(); 1533 1534 setTimeout(() => { 1535 hiAppEventV9.removeWatcher(watcher); 1536 console.info('HiAppEventWatcherTest008 end'); 1537 done(); 1538 }, 1000); 1539 }); 1540 1541 /** 1542 * @tc.number HiAppEventWatcherTest009 1543 * @tc.name: HiAppEventWatcherTest009 1544 * @tc.desc: watcher.onTrigger timeout test. 1545 * @tc.type: FUNC 1546 * @tc.require: issueI5KYYI 1547 */ 1548 it('HiAppEventWatcherTest009', 0, async function (done) { 1549 console.info('HiAppEventWatcherTest009 start'); 1550 let watcher = { 1551 name: "watcher", 1552 appEventFilters: [ 1553 { domain: TEST_DOMAIN }, 1554 ], 1555 triggerCondition: { 1556 timeOut: 1 1557 }, 1558 onTrigger: function (curRow, curSize, holder) { 1559 console.info('HiAppEventWatcherTest009.onTrigger start'); 1560 expect(curRow).assertEqual(1) 1561 expect(curSize > 0).assertTrue() 1562 expect(holder != null).assertTrue() 1563 1564 let eventPkg = holder.takeNext(); 1565 expect(eventPkg != null).assertTrue() 1566 expect(eventPkg.packageId).assertEqual(0) 1567 expect(eventPkg.row).assertEqual(1) 1568 expect(eventPkg.size > 0).assertTrue() 1569 expect(eventPkg.data.length).assertEqual(1) 1570 expect(eventPkg.data[0].length > 0).assertTrue() 1571 console.info('HiAppEventWatcherTest009.onTrigger end'); 1572 } 1573 }; 1574 let result = hiAppEventV9.addWatcher(watcher); 1575 expect(result != null).assertTrue() 1576 1577 simpleWriteV9Test(); 1578 1579 setTimeout(() => { 1580 hiAppEventV9.removeWatcher(watcher); 1581 console.info('HiAppEventWatcherTest009 end'); 1582 done(); 1583 }, 3000); 1584 }); 1585 1586 /** 1587 * @tc.number HiAppEventWatcherTest010 1588 * @tc.name: HiAppEventWatcherTest010 1589 * @tc.desc: watcher.holder test. 1590 * @tc.type: FUNC 1591 * @tc.require: issueI5NTOD 1592 */ 1593 it('HiAppEventWatcherTest010', 0, async function (done) { 1594 console.info('HiAppEventWatcherTest010 start'); 1595 let watcher = { 1596 name: "watcher", 1597 }; 1598 let holder = hiAppEventV9.addWatcher(watcher); 1599 expect(holder != null).assertTrue() 1600 1601 simpleWriteV9Test(); 1602 1603 setTimeout(() => { 1604 let eventPkg = holder.takeNext(); 1605 expect(eventPkg != null).assertTrue(); 1606 expect(eventPkg.packageId).assertEqual(0); 1607 expect(eventPkg.row).assertEqual(1); 1608 expect(eventPkg.size > 0).assertTrue(); 1609 expect(eventPkg.data.length).assertEqual(1); 1610 expect(eventPkg.data[0].length > 0).assertTrue(); 1611 hiAppEventV9.removeWatcher(watcher); 1612 console.info('HiAppEventWatcherTest010 end'); 1613 done(); 1614 }, 1000); 1615 }); 1616 1617 /** 1618 * @tc.number HiAppEventWatcherTest011 1619 * @tc.name: HiAppEventWatcherTest011 1620 * @tc.desc: invalid watcher.holder test. 1621 * @tc.type: FUNC 1622 * @tc.require: issueI5NTOD 1623 */ 1624 it('HiAppEventWatcherTest011', 0, function () { 1625 console.info('HiAppEventWatcherTest011 start'); 1626 let watcher = { 1627 name: "watcher", 1628 }; 1629 let holder = hiAppEventV9.addWatcher(watcher); 1630 expect(holder != null).assertTrue() 1631 1632 // size not passed in 1633 try { 1634 holder.setSize() 1635 } catch (err) { 1636 let expectErr = createError3("size"); 1637 assertErrorEqual(err, expectErr) 1638 } 1639 1640 // invalid size type 1641 function holderSetSizeTest(holder, size, expectErr) { 1642 try { 1643 holder.setSize(size) 1644 } catch (err) { 1645 assertErrorEqual(err, expectErr) 1646 } 1647 } 1648 let expectErr = createError2("size", "number"); 1649 holderSetSizeTest(holder, null, expectErr); 1650 holderSetSizeTest(holder, {}, expectErr); 1651 1652 // invalid size value 1653 expectErr = createError(11104001, 1654 "Invalid size value. Possible caused by the size value is less than or equal to zero."); 1655 holderSetSizeTest(holder, -1, expectErr); 1656 holderSetSizeTest(holder, -100, expectErr); 1657 1658 hiAppEventV9.removeWatcher(watcher) 1659 console.info('HiAppEventWatcherTest011 end') 1660 }); 1661 1662 /** 1663 * @tc.number HiAppEventWatcherTest012 1664 * @tc.name: HiAppEventWatcherTest012 1665 * @tc.desc: watcher.holder constructor test. 1666 * @tc.type: FUNC 1667 * @tc.require: issueI5KYYI 1668 */ 1669 it('HiAppEventWatcherTest012', 0, async function (done) { 1670 console.info('HiAppEventWatcherTest012 start'); 1671 let watcher = { 1672 name: "watcher", 1673 }; 1674 hiAppEventV9.addWatcher(watcher); 1675 1676 let params = { 1677 "key_int": 100, 1678 "key_string": "strValue", 1679 "key_bool": true, 1680 "key_float": 30949.374, 1681 "key_int_arr": [1, 2, 3], 1682 "key_string_arr": ["a", "b", "c"], 1683 "key_float_arr": [1.1, 2.2, 3.0], 1684 "key_bool_arr": [true, false, true] 1685 }; 1686 hiAppEventV9.write({ 1687 domain: "test_domain", 1688 name: "test_name", 1689 eventType: hiAppEventV9.EventType.FAULT, 1690 params: params 1691 }, (err) => { 1692 expect(err).assertNull(); 1693 1694 let holder = new hiAppEventV9.AppEventPackageHolder("watcher"); 1695 let eventPkg = holder.takeNext(); 1696 expect(eventPkg != null).assertTrue(); 1697 expect(eventPkg.data.length == 1).assertTrue(); 1698 let paramJsonStr = JSON.stringify(params);; 1699 expect(eventPkg.data[0].includes(paramJsonStr.substr(1, paramJsonStr.length - 2))).assertTrue(); 1700 hiAppEventV9.removeWatcher(watcher); 1701 console.info('HiAppEventWatcherTest012 end'); 1702 done(); 1703 }); 1704 }); 1705 1706 /** 1707 * @tc.number HiAppEventWatcherTest013 1708 * @tc.name: HiAppEventWatcherTest013 1709 * @tc.desc: watcher.onTrigger test after clear up. 1710 * @tc.type: FUNC 1711 * @tc.require: issueI8H07G 1712 */ 1713 it('HiAppEventWatcherTest013', 0, async function (done) { 1714 console.info('HiAppEventWatcherTest013 start'); 1715 let testRow = 5; 1716 let watcher = { 1717 name: "watcher", 1718 triggerCondition: { 1719 row: testRow 1720 }, 1721 onTrigger: function (curRow, curSize, holder) { 1722 console.info('HiAppEventWatcherTest013.onTrigger start'); 1723 holder.setRow(testRow); 1724 let eventPkg = holder.takeNext(); 1725 expect(eventPkg.data.length).assertEqual(testRow) 1726 console.info('HiAppEventWatcherTest013.onTrigger end'); 1727 } 1728 }; 1729 hiAppEventV9.addWatcher(watcher); 1730 1731 setTimeout(() => { 1732 for (var i = 1; i <= 3; i++) { 1733 simpleWriteV9Test(); 1734 } 1735 }, 1000); 1736 1737 setTimeout(() => { 1738 hiAppEventV9.clearData(); 1739 }, 2000); 1740 1741 setTimeout(() => { 1742 for (var i = 1; i <= testRow; i++) { 1743 simpleWriteV9Test(); 1744 } 1745 }, 3000); 1746 1747 setTimeout(() => { 1748 hiAppEventV9.removeWatcher(watcher); 1749 console.info('HiAppEventWatcherTest013 end'); 1750 done(); 1751 }, 4000); 1752 }); 1753 1754 function simpleReceive(domain, eventArray) { 1755 console.info('HiAppEventWatcherTest.onReceive start domain=' + domain + ', event size=' + 1756 eventArray.length); 1757 for (var key in eventArray) { 1758 console.info('HiAppEventWatcherTest event_name=' + eventArray[key]['name'] + ', size=' + 1759 eventArray[key]['appEventInfos'].length); 1760 } 1761 console.info('HiAppEventWatcherTest.onReceive end'); 1762 } 1763 1764 /** 1765 * @tc.number HiAppEventWatcherTest014 1766 * @tc.name: HiAppEventWatcherTest014 1767 * @tc.desc: watcher.onReceive test. 1768 * @tc.type: FUNC 1769 * @tc.require: issueI5KYYI 1770 */ 1771 it('HiAppEventWatcherTest014', 0, async function (done) { 1772 console.info('HiAppEventWatcherTest014 start'); 1773 let watcher = { 1774 name: "watcheros1", 1775 appEventFilters: [ 1776 { 1777 domain: hiAppEventV9.domain.OS, 1778 names: [ 1779 hiAppEventV9.event.APP_CRASH, 1780 hiAppEventV9.event.APP_FREEZE, 1781 "APP_START", 1782 hiAppEventV9.event.APP_LAUNCH, 1783 hiAppEventV9.event.SCROLL_JANK, 1784 hiAppEventV9.event.CPU_USAGE_HIGH, 1785 hiAppEventV9.event.BATTERY_USAGE, 1786 hiAppEventV9.event.RESOURCE_OVERLIMIT, 1787 hiAppEventV9.event.ADDRESS_SANITIZER 1788 ] 1789 }, 1790 ], 1791 onReceive: simpleReceive 1792 }; 1793 let result = hiAppEventV9.addWatcher(watcher); 1794 expect(result != null).assertTrue(); 1795 1796 setTimeout(() => { 1797 hiAppEventV9.removeWatcher(watcher); 1798 console.info('HiAppEventWatcherTest014 end'); 1799 done(); 1800 }, 1000); 1801 }); 1802 1803 /** 1804 * @tc.number HiAppEventWatcherTest015 1805 * @tc.name: HiAppEventWatcherTest015 1806 * @tc.desc: watcher.onReceive test. 1807 * @tc.type: FUNC 1808 * @tc.require: issueI5KYYI 1809 */ 1810 it('HiAppEventWatcherTest015', 0, async function (done) { 1811 console.info('HiAppEventWatcherTest015 start'); 1812 let watcher = { 1813 name: "watcher", 1814 appEventFilters: [ 1815 {domain: "test_domain", names: ["test_name"]}, 1816 ], 1817 onReceive: simpleReceive 1818 }; 1819 let result = hiAppEventV9.addWatcher(watcher); 1820 expect(result != null).assertTrue(); 1821 1822 simpleWriteV9Test(); 1823 1824 setTimeout(() => { 1825 hiAppEventV9.removeWatcher(watcher); 1826 console.info('HiAppEventWatcherTest015 end'); 1827 done(); 1828 }, 1000); 1829 }); 1830 1831 /** 1832 * @tc.number HiAppEventWatcherTest016 1833 * @tc.name: HiAppEventWatcherTest016 1834 * @tc.desc: watcher.onReceive test. 1835 * @tc.type: FUNC 1836 * @tc.require: issueI5KYYI 1837 */ 1838 it('HiAppEventWatcherTest016', 0, async function (done) { 1839 console.info('HiAppEventWatcherTest016 start'); 1840 let result = true; 1841 let watcher1 = { 1842 name: "watcheros1", 1843 appEventFilters: [ 1844 { 1845 domain: hiAppEventV9.domain.OS, 1846 names: [hiAppEventV9.event.APP_CRASH, hiAppEventV9.event.APP_FREEZE, "APP_START"] 1847 }, 1848 ], 1849 onReceive: simpleReceive 1850 }; 1851 result = hiAppEventV9.addWatcher(watcher1); 1852 expect(result != null).assertTrue(); 1853 1854 let watcher2 = { 1855 name: "watcheros2", 1856 appEventFilters: [ 1857 { 1858 domain: hiAppEventV9.domain.OS, 1859 names: [hiAppEventV9.event.APP_CRASH, hiAppEventV9.event.APP_FREEZE, "APP_START"] 1860 }, 1861 ], 1862 onReceive: simpleReceive, 1863 onTrigger: simpleTrigger 1864 }; 1865 result = hiAppEventV9.addWatcher(watcher2); 1866 expect(result != null).assertTrue(); 1867 1868 let watcher3 = { 1869 name: "watcheros3", 1870 appEventFilters: [ 1871 { 1872 domain: hiAppEventV9.domain.OS, 1873 names: [hiAppEventV9.event.APP_CRASH, hiAppEventV9.event.APP_FREEZE, "APP_START"] 1874 }, 1875 ], 1876 onTrigger: simpleTrigger 1877 }; 1878 result = hiAppEventV9.addWatcher(watcher3); 1879 expect(result != null).assertTrue(); 1880 1881 setTimeout(() => { 1882 hiAppEventV9.removeWatcher(watcher1); 1883 hiAppEventV9.removeWatcher(watcher2); 1884 hiAppEventV9.removeWatcher(watcher3); 1885 console.info('HiAppEventWatcherTest016 end'); 1886 done(); 1887 }, 1000); 1888 }); 1889 1890 /** 1891 * @tc.number HiAppEventSetEventConfigTest001 1892 * @tc.name: HiAppEventSetEventConfigTest001 1893 * @tc.desc: Test the SetEventConfig interface. 1894 * @tc.type: FUNC 1895 * @tc.require: issueI8U2VO 1896 */ 1897 it('HiAppEventSetEventConfigTest001', 0, async function (done) { 1898 console.info('HiAppEventSetEventConfigTest001 start'); 1899 let configInfo1 = { // default, collect stack and trace 1900 "log_type": "0", 1901 }; 1902 let configInfo2 = { // collect stack 1903 "log_type": "1", 1904 "ignore_startup_time": "10", 1905 "sample_interval": "100", 1906 "sample_count": "21", 1907 "report_times_per_app": "3" 1908 }; 1909 let configInfo3 = { // collect trace 1910 "log_type": "2", 1911 }; 1912 setEventConfigV9Test("MAIN_THREAD_JANK", configInfo1, null, done); 1913 setEventConfigV9Test("MAIN_THREAD_JANK", configInfo2, null, done); 1914 setEventConfigV9Test("MAIN_THREAD_JANK", configInfo3, null, done); 1915 console.info('HiAppEventSetEventConfigTest001 end'); 1916 }); 1917 1918 /** 1919 * @tc.number HiAppEventSetEventConfigTest002 1920 * @tc.name: HiAppEventSetEventConfigTest002 1921 * @tc.desc: Test the SetEventConfig interface with invalid name. 1922 * @tc.type: FUNC 1923 * @tc.require: issueI8U2VO 1924 */ 1925 it('HiAppEventSetEventConfigTest002', 0, async function (done) { 1926 console.info('HiAppEventSetEventConfigTest002 start'); 1927 let configInfo = { 1928 "log_type": "0", 1929 }; 1930 let expectErr1 = createError2("name", "string"); 1931 setEventConfigV9TestCatch(0, configInfo, expectErr1, done); 1932 setEventConfigV9TestCatch(true, configInfo, expectErr1, done); 1933 1934 let expectErr2 = createError(401, "Invalid param value for event config."); 1935 setEventConfigV9Test("", configInfo, expectErr2, done); 1936 setEventConfigV9Test(null, configInfo, expectErr2, done); 1937 setEventConfigV9Test("INVALID_NAME", configInfo, expectErr2, done); 1938 console.info('HiAppEventSetEventConfigTest002 end'); 1939 }); 1940 1941 /** 1942 * @tc.number HiAppEventSetEventConfigTest003 1943 * @tc.name: HiAppEventSetEventConfigTest003 1944 * @tc.desc: Test the SetEventConfig interface with invalid config type. 1945 * @tc.type: FUNC 1946 * @tc.require: issueI8U2VO 1947 */ 1948 it('HiAppEventSetEventConfigTest003', 0, async function (done) { 1949 console.info('HiAppEventSetEventConfigTest003 start'); 1950 let expectErr = createError2("value", "object"); 1951 setEventConfigV9TestCatch("MAIN_THREAD_JANK", 0, expectErr, done); 1952 setEventConfigV9TestCatch("MAIN_THREAD_JANK", "", expectErr, done); 1953 setEventConfigV9TestCatch("MAIN_THREAD_JANK", true, expectErr, done); 1954 setEventConfigV9TestCatch("MAIN_THREAD_JANK", null, expectErr, done); 1955 console.info('HiAppEventSetEventConfigTest003 end'); 1956 }); 1957 1958 /** 1959 * @tc.number HiAppEventSetEventConfigTest004 1960 * @tc.name: HiAppEventSetEventConfigTest004 1961 * @tc.desc: Test the SetEventConfig interface when the config is empty. 1962 * @tc.type: FUNC 1963 * @tc.require: issueI8U2VO 1964 */ 1965 it('HiAppEventSetEventConfigTest004', 0, async function (done) { 1966 console.info('HiAppEventSetEventConfigTest004 start'); 1967 let configInfo = {}; 1968 let expectErr = createError(401, "Invalid param value for event config."); 1969 setEventConfigV9Test("MAIN_THREAD_JANK", configInfo, expectErr, done); 1970 console.info('HiAppEventSetEventConfigTest004 end'); 1971 }); 1972 1973 /** 1974 * @tc.number HiAppEventSetEventConfigTest005 1975 * @tc.name: HiAppEventSetEventConfigTest005 1976 * @tc.desc: Error code 401 is returned when the config log_type is invalid. 1977 * @tc.type: FUNC 1978 * @tc.require: issueI8U2VO 1979 */ 1980 it('HiAppEventSetEventConfigTest005', 0, async function (done) { 1981 console.info('HiAppEventSetEventConfigTest005 start'); 1982 let configInfo1 = { 1983 "log_type": "-1", 1984 }; 1985 let configInfo2 = { 1986 "log_type": "abc", 1987 }; 1988 let configInfo3 = { 1989 "log_type": "", 1990 }; 1991 let configInfo4 = { 1992 "log_type": null, 1993 }; 1994 let expectErr = createError(401, "Invalid param value for event config."); 1995 setEventConfigV9Test("MAIN_THREAD_JANK", configInfo1, expectErr, done); 1996 setEventConfigV9Test("MAIN_THREAD_JANK", configInfo2, expectErr, done); 1997 setEventConfigV9Test("MAIN_THREAD_JANK", configInfo3, expectErr, done); 1998 setEventConfigV9Test("MAIN_THREAD_JANK", configInfo4, expectErr, done); 1999 console.info('HiAppEventSetEventConfigTest005 end'); 2000 }); 2001 2002 /** 2003 * @tc.number HiAppEventSetEventConfigTest006 2004 * @tc.name: HiAppEventSetEventConfigTest006 2005 * @tc.desc: Error code 401 is returned when the config log_type=1, but item number is not 5. 2006 * @tc.type: FUNC 2007 * @tc.require: issueI8U2VO 2008 */ 2009 it('HiAppEventSetEventConfigTest006', 0, async function (done) { 2010 console.info('HiAppEventSetEventConfigTest006 start'); 2011 let configInfo = { 2012 "log_type": "1", 2013 "sample_interval": "100", 2014 "sample_count": "21", 2015 }; 2016 let expectErr = createError(401, "Invalid param value for event config."); 2017 setEventConfigV9Test("MAIN_THREAD_JANK", configInfo, expectErr, done); 2018 console.info('HiAppEventSetEventConfigTest006 end'); 2019 }); 2020 2021 /** 2022 * @tc.number HiAppEventSetEventConfigTest007 2023 * @tc.name: HiAppEventSetEventConfigTest007 2024 * @tc.desc: Error code 401 is returned when the value param item value is invalid. 2025 * @tc.type: FUNC 2026 * @tc.require: issueI8U2VO 2027 */ 2028 it('HiAppEventSetEventConfigTest007', 0, async function (done) { 2029 console.info('HiAppEventSetEventConfigTest007 start'); 2030 let configInfo1 = { 2031 "log_type": "1", 2032 "ignore_startup_time": "10", 2033 "sample_interval": "-1", 2034 "sample_count": "21", 2035 "report_times_per_app": "3" 2036 }; 2037 let configInfo2 = { 2038 "log_type": "1", 2039 "ignore_startup_time": "10", 2040 "sample_interval": "49", 2041 "sample_count": "21", 2042 "report_times_per_app": "3" 2043 }; 2044 let configInfo3 = { 2045 "log_type": "1", 2046 "ignore_startup_time": "10", 2047 "sample_interval": "50", 2048 "sample_count": "21", 2049 "report_times_per_app": "3" 2050 }; 2051 let configInfo4 = { 2052 "log_type": "1", 2053 "ignore_startup_time": "10", 2054 "sample_interval": "92233720368547758079223372036854775807", 2055 "sample_count": "21", 2056 "report_times_per_app": "3" 2057 }; 2058 let configInfo5 = { 2059 "log_type": "1", 2060 "ignore_startup_time": "10", 2061 "sample_interval": "aa", 2062 "sample_count": "21", 2063 "report_times_per_app": "3" 2064 }; 2065 let expectErr = createError(401, "Invalid param value for event config."); 2066 setEventConfigV9Test("MAIN_THREAD_JANK", configInfo1, expectErr, done); 2067 setEventConfigV9Test("MAIN_THREAD_JANK", configInfo2, expectErr, done); 2068 setEventConfigV9Test("MAIN_THREAD_JANK", configInfo3, expectErr, done); 2069 setEventConfigV9Test("MAIN_THREAD_JANK", configInfo4, expectErr, done); 2070 setEventConfigV9Test("MAIN_THREAD_JANK", configInfo5, expectErr, done); 2071 console.info('HiAppEventSetEventConfigTest007 end'); 2072 }); 2073 2074 /** 2075 * @tc.number HiAppEventSetEventConfigTest008 2076 * @tc.name: HiAppEventSetEventConfigTest008 2077 * @tc.desc: Test the SetEventConfig interface for APP_CRASH. 2078 * @tc.type: FUNC 2079 * @tc.require: issueI8U2VO 2080 */ 2081 it('HiAppEventSetEventConfigTest008', 0, async function (done) { 2082 console.info('HiAppEventSetEventConfigTest008 start'); 2083 let configInfo1 = { 2084 "extend_pc_lr_printing": true, 2085 }; 2086 let configInfo2 = { 2087 "log_file_cutoff_sz_bytes": 10, 2088 }; 2089 let configInfo3 = { 2090 "simplify_vma_printing": true, 2091 }; 2092 let configInfo4 = { 2093 "extend_pc_lr_printing": true, 2094 "log_file_cutoff_sz_bytes": 10, 2095 "simplify_vma_printing": true, 2096 }; 2097 setEventConfigV9Test("APP_CRASH", configInfo1, null, done); 2098 setEventConfigV9Test("APP_CRASH", configInfo2, null, done); 2099 setEventConfigV9Test("APP_CRASH", configInfo3, null, done); 2100 setEventConfigV9Test("APP_CRASH", configInfo4, null, done); 2101 console.info('HiAppEventSetEventConfigTest008 end'); 2102 }); 2103 2104 /** 2105 * @tc.number HiAppEventSetEventConfigTest009 2106 * @tc.name: HiAppEventSetEventConfigTest009 2107 * @tc.desc: Test the SetEventConfig interface for APP_CRASH with invalid param type. 2108 * @tc.type: FUNC 2109 * @tc.require: issueI8U2VO 2110 */ 2111 it('HiAppEventSetEventConfigTest009', 0, async function (done) { 2112 console.info('HiAppEventSetEventConfigTest009 start'); 2113 let configInfo1 = { 2114 "extend_pc_lr_printing": 10, 2115 }; 2116 let configInfo2 = { 2117 "extend_pc_lr_printing": "123abc", 2118 }; 2119 let configInfo3 = { 2120 "extend_pc_lr_printing": null, 2121 }; 2122 let configInfo4 = { 2123 "log_file_cutoff_sz_bytes": true, 2124 } 2125 let configInfo5 = { 2126 "log_file_cutoff_sz_bytes": "123abc", 2127 } 2128 let configInfo6 = { 2129 "log_file_cutoff_sz_bytes": null, 2130 } 2131 let configInfo7 = { 2132 "simplify_vma_printing": 10, 2133 } 2134 let configInfo8 = { 2135 "simplify_vma_printing": "123abc", 2136 } 2137 let configInfo9 = { 2138 "simplify_vma_printing": null, 2139 } 2140 let expectErr = createError(401, "Invalid param value for event config."); 2141 setEventConfigV9Test("APP_CRASH", configInfo1, expectErr, done); 2142 setEventConfigV9Test("APP_CRASH", configInfo2, expectErr, done); 2143 setEventConfigV9Test("APP_CRASH", configInfo3, expectErr, done); 2144 setEventConfigV9Test("APP_CRASH", configInfo4, expectErr, done); 2145 setEventConfigV9Test("APP_CRASH", configInfo5, expectErr, done); 2146 setEventConfigV9Test("APP_CRASH", configInfo6, expectErr, done); 2147 setEventConfigV9Test("APP_CRASH", configInfo7, expectErr, done); 2148 setEventConfigV9Test("APP_CRASH", configInfo8, expectErr, done); 2149 setEventConfigV9Test("APP_CRASH", configInfo9, expectErr, done); 2150 console.info('HiAppEventSetEventConfigTest009 end'); 2151 }); 2152 2153 /** 2154 * @tc.number HiAppEventSetEventConfigTest010 2155 * @tc.name: HiAppEventSetEventConfigTest010 2156 * @tc.desc: Test the SetEventConfig interface for APP_CRASH with not all params are valid. 2157 * @tc.type: FUNC 2158 * @tc.require: issueI8U2VO 2159 */ 2160 it('HiAppEventSetEventConfigTest010', 0, async function (done) { 2161 console.info('HiAppEventSetEventConfigTest010 start'); 2162 let configInfo1 = { 2163 "extend_pc_lr_printing": true, 2164 "log_file_cutoff_sz_bytes": 10, 2165 "simplify_vma_printing": "123abc", 2166 }; 2167 setEventConfigV9Test("APP_CRASH", configInfo1, null, done); 2168 console.info('HiAppEventSetEventConfigTest010 end'); 2169 }); 2170 2171 /** 2172 * @tc.number HiAppEventSetEventConfigTest011 2173 * @tc.name: HiAppEventSetEventConfigTest011 2174 * @tc.desc: Test the SetEventConfig interface for APP_CRASH with all params are invalid. 2175 * @tc.type: FUNC 2176 * @tc.require: issueI8U2VO 2177 */ 2178 it('HiAppEventSetEventConfigTest011', 0, async function (done) { 2179 console.info('HiAppEventSetEventConfigTest011 start'); 2180 let configInfo1 = { 2181 "extend_pc_lr_printing": 10, 2182 "log_file_cutoff_sz_bytes": true, 2183 "simplify_vma_printing": 10, 2184 }; 2185 let expectErr = createError(401, "Invalid param value for event config."); 2186 setEventConfigV9Test("APP_CRASH", configInfo1, expectErr, done); 2187 console.info('HiAppEventSetEventConfigTest011 end'); 2188 }); 2189 2190 /** 2191 * @tc.number HiAppEventSetEventConfigTest012 2192 * @tc.name: HiAppEventSetEventConfigTest012 2193 * @tc.desc: Test the SetEventConfig interface for APP_CRASH with numeric param. 2194 * @tc.type: FUNC 2195 * @tc.require: issueI8U2VO 2196 */ 2197 it('HiAppEventSetEventConfigTest012', 0, async function (done) { 2198 console.info('HiAppEventSetEventConfigTest012 start'); 2199 let configInfo1 = { 2200 "log_file_cutoff_sz_bytes": -1, 2201 }; 2202 let configInfo2 = { 2203 "log_file_cutoff_sz_bytes": 0, 2204 }; 2205 let configInfo3 = { 2206 "log_file_cutoff_sz_bytes": 5 * 1024 * 1024, 2207 }; 2208 let configInfo4 = { 2209 "log_file_cutoff_sz_bytes": 5 * 1024 * 1024 + 1, 2210 }; 2211 let configInfo5 = { 2212 "log_file_cutoff_sz_bytes": 123.456, 2213 }; 2214 let configInfo6 = { 2215 "log_file_cutoff_sz_bytes": "123", 2216 }; 2217 let configInfo7 = { 2218 "log_file_cutoff_sz_bytes": "123.456", 2219 }; 2220 let configInfo8 = { 2221 "log_file_cutoff_sz_bytes": "123.456.789", 2222 }; 2223 let configInfo9 = { 2224 "log_file_cutoff_sz_bytes": "", 2225 }; 2226 let expectErr = createError(401, "Invalid param value for event config."); 2227 setEventConfigV9Test("APP_CRASH", configInfo1, expectErr, done); 2228 setEventConfigV9Test("APP_CRASH", configInfo2, null, done); 2229 setEventConfigV9Test("APP_CRASH", configInfo3, null, done); 2230 setEventConfigV9Test("APP_CRASH", configInfo4, expectErr, done); 2231 setEventConfigV9Test("APP_CRASH", configInfo5, null, done); 2232 setEventConfigV9Test("APP_CRASH", configInfo6, expectErr, done); 2233 setEventConfigV9Test("APP_CRASH", configInfo7, expectErr, done); 2234 setEventConfigV9Test("APP_CRASH", configInfo8, expectErr, done); 2235 setEventConfigV9Test("APP_CRASH", configInfo9, expectErr, done); 2236 console.info('HiAppEventSetEventConfigTest012 end'); 2237 }); 2238 2239 /** 2240 * @tc.number HiAppEventSetEventConfigTest013 2241 * @tc.name: HiAppEventSetEventConfigTest013 2242 * @tc.desc: Test the SetEventConfig interface for APP_CRASH with invalid param item. 2243 * @tc.type: FUNC 2244 * @tc.require: issueI8U2VO 2245 */ 2246 it('HiAppEventSetEventConfigTest013', 0, async function (done) { 2247 console.info('HiAppEventSetEventConfigTest013 start'); 2248 let configInfo1 = { 2249 "extend_pc_lr_printing": true, 2250 "testKey": "testValue", 2251 }; 2252 setEventConfigV9Test("APP_CRASH", configInfo1, null, done); 2253 console.info('HiAppEventSetEventConfigTest013 end'); 2254 }); 2255 2256 /** 2257 * @tc.number HiAppEventSetEventConfigTest014 2258 * @tc.name: HiAppEventSetEventConfigTest014 2259 * @tc.desc: Test the SetEventConfig interface for APP_CRASH with boolean param. 2260 * @tc.type: FUNC 2261 * @tc.require: issueI8U2VO 2262 */ 2263 it('HiAppEventSetEventConfigTest014', 0, async function (done) { 2264 console.info('HiAppEventSetEventConfigTest014 start'); 2265 let configInfo1 = { 2266 "extend_pc_lr_printing": true, 2267 }; 2268 let configInfo2 = { 2269 "extend_pc_lr_printing": "true", 2270 }; 2271 let configInfo3 = { 2272 "simplify_vma_printing": true, 2273 }; 2274 let configInfo4 = { 2275 "simplify_vma_printing": "true", 2276 }; 2277 2278 let expectErr = createError(401, "Invalid param value for event config."); 2279 setEventConfigV9Test("APP_CRASH", configInfo1, null, done); 2280 setEventConfigV9Test("APP_CRASH", configInfo2, expectErr, done); 2281 setEventConfigV9Test("APP_CRASH", configInfo3, null, done); 2282 setEventConfigV9Test("APP_CRASH", configInfo4, expectErr, done); 2283 console.info('HiAppEventSetEventConfigTest014 end'); 2284 }); 2285 2286 /** 2287 * @tc.number HiAppEventSetEventConfigTest015 2288 * @tc.name: HiAppEventSetEventConfigTest015 2289 * @tc.desc: Test the SetEventConfig interface for MAIN_THREAD_JANK with string param. 2290 * @tc.type: FUNC 2291 * @tc.require: issueI8U2VO 2292 */ 2293 it('HiAppEventSetEventConfigTest015', 0, async function (done) { 2294 console.info('HiAppEventSetEventConfigTest015 start'); 2295 let configInfo1 = { 2296 "log_type": "0", 2297 }; 2298 let configInfo2 = { 2299 "log_type": 0, 2300 }; 2301 let configInfo3 = { 2302 "log_type": "1", 2303 "ignore_startup_time": "10", 2304 "sample_interval": "100", 2305 "sample_count": "21", 2306 "report_times_per_app": "3" 2307 }; 2308 let configInfo4 = { 2309 "log_type": "1", 2310 "ignore_startup_time": 10, 2311 "sample_interval": "100", 2312 "sample_count": "21", 2313 "report_times_per_app": "3" 2314 }; 2315 let configInfo5 = { 2316 "log_type": "1", 2317 "ignore_startup_time": "10", 2318 "sample_interval": 100, 2319 "sample_count": "21", 2320 "report_times_per_app": "3" 2321 }; 2322 let configInfo6 = { 2323 "log_type": "1", 2324 "ignore_startup_time": "10", 2325 "sample_interval": "100", 2326 "sample_count": 21, 2327 "report_times_per_app": "3" 2328 }; 2329 let configInfo7 = { 2330 "log_type": "1", 2331 "ignore_startup_time": "10", 2332 "sample_interval": "100", 2333 "sample_count": "21", 2334 "report_times_per_app": 3 2335 }; 2336 2337 let expectErr = createError(401, "Invalid param value for event config."); 2338 setEventConfigV9Test("MAIN_THREAD_JANK", configInfo1, null, done); 2339 setEventConfigV9Test("MAIN_THREAD_JANK", configInfo2, expectErr, done); 2340 setEventConfigV9Test("MAIN_THREAD_JANK", configInfo3, null, done); 2341 setEventConfigV9Test("MAIN_THREAD_JANK", configInfo4, expectErr, done); 2342 setEventConfigV9Test("MAIN_THREAD_JANK", configInfo5, expectErr, done); 2343 setEventConfigV9Test("MAIN_THREAD_JANK", configInfo6, expectErr, done); 2344 setEventConfigV9Test("MAIN_THREAD_JANK", configInfo7, expectErr, done); 2345 console.info('HiAppEventSetEventConfigTest015 end'); 2346 }); 2347});