1/* 2 * Copyright (C) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import hiSysEvent from "@ohos.hiSysEvent" 17 18import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' 19 20describe('hiSysEventJsUnitTest', function () { 21 beforeAll(function() { 22 23 /** 24 * @tc.setup: setup invoked before all test cases 25 */ 26 console.info('hiSysEventJsUnitTest beforeAll called') 27 }) 28 29 afterAll(function() { 30 31 /** 32 * @tc.teardown: teardown invoked after all test cases 33 */ 34 console.info('hiSysEventJsUnitTest afterAll called') 35 }) 36 37 beforeEach(function() { 38 39 /** 40 * @tc.setup: setup invoked before each test case 41 */ 42 console.info('hiSysEventJsUnitTest beforeEach called') 43 }) 44 45 afterEach(function() { 46 47 /** 48 * @tc.teardown: teardown invoked after each test case 49 */ 50 console.info('hiSysEventJsUnitTest afterEach called') 51 }) 52 53 /** 54 * @tc.name: hiSysEventJsUnitTest001 55 * @tc.desc: Test hisysevent writing with calling AsyncCallback 56 * @tc.type: FUNC 57 */ 58 it('hiSysEventJsUnitTest001', 0, async function (done) { 59 console.info('hiSysEventJsUnitTest001 start') 60 try { 61 hiSysEvent.write({ 62 domain: "RELIABILITY", 63 name: "STACK", 64 eventType: hiSysEvent.EventType.FAULT, 65 params: { 66 PID: 1, 67 UID: 1, 68 PACKAGE_NAME: "com.huawei.testHiSysEvent", 69 PROCESS_NAME: "hiview js test suite", 70 MSG: "no msg." 71 } 72 }, (err, val) => { 73 if (err) { 74 console.error('in hiSysEventJsUnitTest001 test callback: err.code = ' + err.code) 75 expect(false).assertTrue() 76 } else { 77 console.info('in hiSysEventJsUnitTest001 test callback: result = ' + val); 78 expect(val).assertEqual(0) 79 } 80 console.info('hiSysEventJsUnitTest001 end') 81 done() 82 }) 83 } catch (err) { 84 console.error(`hiSysEventJsUnitTest001 > error code: ${err.code}, error msg: ${err.message}`) 85 expect(false).assertTrue() 86 console.info('hiSysEventJsUnitTest001 end') 87 done() 88 } 89 }) 90 91 /** 92 * @tc.name: hiSysEventJsUnitTest002 93 * @tc.desc: Test hisysevent writing with returning Promise. 94 * @tc.type: FUNC 95 */ 96 it('hiSysEventJsUnitTest002', 0, async function (done) { 97 console.info('hiSysEventJsUnitTest002 start') 98 try { 99 hiSysEvent.write({ 100 domain: "RELIABILITY", 101 name: "STACK", 102 eventType: hiSysEvent.EventType.FAULT, 103 params: { 104 PID: 1, 105 UID: 1, 106 PACKAGE_NAME: "com.huawei.testHiSysEvent", 107 PROCESS_NAME: "hiview js test suite", 108 MSG: "no msg." 109 } 110 }).then( 111 (val) => { 112 console.info('in hiSysEventJsUnitTest002 test callback: result = ' + val) 113 expect(val).assertEqual(0) 114 console.info('hiSysEventJsUnitTest002 end') 115 done() 116 } 117 ).catch( 118 (err) => { 119 console.error('in hiSysEventJsUnitTest002 test callback: err.code = ' + err.code) 120 expect(false).assertTrue() 121 console.info('hiSysEventJsUnitTest002 end') 122 done() 123 } 124 ); 125 } catch (err) { 126 console.error(`hiSysEventJsUnitTest002 > error code: ${err.code}, error msg: ${err.message}`) 127 expect(false).assertTrue() 128 console.info('hiSysEventJsUnitTest002 end') 129 done() 130 } 131 }) 132 133 /** 134 * @tc.name: hiSysEventJsUnitTest003 135 * @tc.desc: Test function return of adding/remove hisysevent watcher result. 136 * @tc.type: FUNC 137 */ 138 it('hiSysEventJsUnitTest003', 0, async function (done) { 139 console.info('hiSysEventJsUnitTest003 start') 140 let watcher = { 141 rules: [{ 142 domain: "RELIABILITY", 143 name: "STACK", 144 ruleType: hiSysEvent.RuleType.WHOLE_WORD, 145 }], 146 onEvent: (info) => { 147 }, 148 onServiceDied: () => { 149 } 150 } 151 try { 152 hiSysEvent.addWatcher(watcher) 153 hiSysEvent.removeWatcher(watcher) 154 expect(true).assertTrue() 155 console.info('hiSysEventJsUnitTest003 end') 156 done(); 157 } catch (err) { 158 console.error(`hiSysEventJsUnitTest003 > error code: ${err.code}, error msg: ${err.message}`) 159 expect(err.code == 201).assertTrue() 160 console.info('hiSysEventJsUnitTest003 end') 161 done() 162 } 163 }) 164 165 /** 166 * @tc.name: hiSysEventJsUnitTest004 167 * @tc.desc: Test watcher callback 168 * @tc.type: FUNC 169 */ 170 it('hiSysEventJsUnitTest004', 0, async function (done) { 171 console.info('hiSysEventJsUnitTest004 start') 172 let watcher = { 173 rules: [{ 174 domain: "RELIABILITY", 175 name: "STACK", 176 tag: "STABILITY", 177 ruleType: hiSysEvent.RuleType.WHOLE_WORD, 178 }], 179 onEvent: (info) => { 180 console.info(`hiSysEventJsUnitTest004: OnEvent...`) 181 expect(Object.keys(info).length > 0).assertTrue() 182 console.info(`hiSysEventJsUnitTest004: domain is : ${info.domain}, name is ${info.name}, eventType is ${info.eventType}`) 183 if (info.params instanceof Object) { 184 for (const key in info.params) { 185 console.info(`hiSysEventJsUnitTest004: ${key}: ${info.params[key]}`) 186 } 187 } 188 }, 189 onServiceDied: () => { 190 console.info(`hiSysEventJsUnitTest004: OnServiceDie...`) 191 } 192 } 193 try { 194 hiSysEvent.addWatcher(watcher) 195 hiSysEvent.write({ 196 domain: "RELIABILITY", 197 name: "STACK", 198 eventType: hiSysEvent.EventType.FAULT, 199 params: { 200 PID: 1, 201 UID: 1, 202 PACKAGE_NAME: "com.huawei.testHiSysEvent", 203 PROCESS_NAME: "hiview js test suite", 204 MSG: "no msg." 205 } 206 }, (err, val) => { 207 if (err) { 208 console.error('in hiSysEventJsUnitTest004 test callback: err.code = ' + err.code) 209 } else { 210 console.info('in hiSysEventJsUnitTest004 test callback: result = ' + val); 211 } 212 }) 213 setTimeout(() => { 214 try { 215 hiSysEvent.removeWatcher(watcher) 216 expect(true).assertTrue() 217 console.info('hiSysEventJsUnitTest004 end') 218 done() 219 } catch (err) { 220 console.error(`hiSysEventJsUnitTest004 delay > error code: ${err.code}, error msg: ${err.message}`) 221 expect(err.code == 201).assertTrue() 222 console.info('hiSysEventJsUnitTest004 end') 223 done() 224 } 225 }, 1000) 226 } catch (err) { 227 console.error(`hiSysEventJsUnitTest004 > error code: ${err.code}, error msg: ${err.message}`) 228 expect(err.code == 201).assertTrue() 229 console.info('hiSysEventJsUnitTest004 end') 230 done() 231 } 232 }) 233 234 /** 235 * @tc.name: hiSysEventJsUnitTest005 236 * @tc.desc: Test query callback 237 * @tc.type: FUNC 238 */ 239 it('hiSysEventJsUnitTest005', 0, async function (done) { 240 console.info('hiSysEventJsUnitTest005 start') 241 try { 242 hiSysEvent.write({ 243 domain: "RELIABILITY", 244 name: "STACK", 245 eventType: hiSysEvent.EventType.FAULT, 246 params: { 247 PID: 1, 248 UID: 1, 249 PACKAGE_NAME: "com.huawei.testHiSysEvent", 250 PROCESS_NAME: "hiview napi test suite", 251 MSG: "no msg." 252 } 253 }, (err, val) => { 254 if (err) { 255 console.error('in hiSysEventJsUnitTest005 test callback: err.code = ' + err.code) 256 } else { 257 console.info('in hiSysEventJsUnitTest005 test callback: result = ' + val) 258 } 259 }) 260 setTimeout(() => { 261 try { 262 hiSysEvent.query({ 263 beginTime: -1, 264 endTime: -1, 265 maxEvents: 2, 266 }, [{ 267 domain: "RELIABILITY", 268 names: ["STACK"], 269 }], { 270 onQuery: function (infos) { 271 console.info(`hiSysEventJsUnitTest005: onQuery...`) 272 expect(infos.length >= 0).assertTrue() 273 console.info(`hiSysEventJsUnitTest005: infos.size is ${infos.length}`) 274 if (infos instanceof Array) { 275 for (let i = 0; i < infos.length; i++) { 276 let item = infos[i]; 277 console.info(`hiSysEventJsUnitTest005: domain is ${item.domain}, name is ${item.name}, eventType is ${item.eventType}`) 278 if (item.params instanceof Object) { 279 for (const key in item.params) { 280 console.info(`hiSysEventJsUnitTest005: ${key}: ${item.params[key]}`) 281 } 282 } 283 } 284 } 285 }, 286 onComplete: function(reason, total) { 287 console.info(`hiSysEventJsUnitTest005: onComplete...`) 288 console.info(`hiSysEventJsUnitTest005: reason is ${reason}, total is ${total}`) 289 expect(true).assertTrue() 290 console.info(`hiSysEventJsUnitTest005 end`) 291 done() 292 } 293 }) 294 } catch (err) { 295 console.error(`hiSysEventJsUnitTest005 delay > error code: ${err.code}, error msg: ${err.message}`) 296 expect(err.code == 201).assertTrue() 297 console.info('hiSysEventJsUnitTest005 end') 298 done() 299 } 300 }, 1000); 301 } catch (err) { 302 console.error(`hiSysEventJsUnitTest005 > error code: ${err.code}, error msg: ${err.message}`) 303 expect(err.code == 201).assertTrue() 304 console.info('hiSysEventJsUnitTest005 end') 305 done() 306 } 307 }) 308 309 /** 310 * @tc.name: hiSysEventJsUnitTest006 311 * @tc.desc: Test query callback with domain which length is over 16 312 * @tc.type: FUNC 313 */ 314 it('hiSysEventJsUnitTest006', 0, async function (done) { 315 console.info('hiSysEventJsUnitTest006 start') 316 try { 317 hiSysEvent.write({ 318 domain: "RELIABILITY", 319 name: "STACK", 320 eventType: hiSysEvent.EventType.FAULT, 321 params: { 322 PID: 1, 323 UID: 1, 324 PACKAGE_NAME: "com.huawei.testHiSysEvent", 325 PROCESS_NAME: "hiview napi test suite", 326 MSG: "no msg." 327 } 328 }, (err, val) => { 329 if (err) { 330 console.error('in hiSysEventJsUnitTest006 test callback: err.code = ' + err.code) 331 } else { 332 console.info('in hiSysEventJsUnitTest006 test callback: result = ' + val) 333 } 334 }) 335 setTimeout(() => { 336 try { 337 hiSysEvent.query({ 338 beginTime: -1, 339 endTime: -1, 340 maxEvents: 2, 341 }, [{ 342 domain: "RELIABILITY_RELIABILITY", 343 names: ["STACK"], 344 }], { 345 onQuery: function (infos) { 346 console.info(`hiSysEventJsUnitTest006: onQuery...`) 347 expect(infos.length >= 0).assertTrue() 348 console.info(`hiSysEventJsUnitTest006: infos.size is ${infos.length}`) 349 if (infos instanceof Array) { 350 for (let i = 0; i < infos.length; i++) { 351 let item = infos[i]; 352 console.info(`hiSysEventJsUnitTest005: domain is ${item.domain}, name is ${item.name}, eventType is ${item.eventType}`) 353 if (item.params instanceof Object) { 354 for (const key in item.params) { 355 console.info(`hiSysEventJsUnitTest005: ${key}: ${item.params[key]}`) 356 } 357 } 358 } 359 } 360 }, 361 onComplete: function(reason, total) { 362 console.info(`hiSysEventJsUnitTest006: onComplete...`) 363 console.info(`hiSysEventJsUnitTest006: reason is ${reason}, total is ${total}`) 364 expect(true).assertTrue() 365 console.info(`hiSysEventJsUnitTest006 end`) 366 done() 367 } 368 }) 369 } catch (err) { 370 console.error(`hiSysEventJsUnitTest006 delay > error code: ${err.code}, error msg: ${err.message}`) 371 expect(err.code == 11200302 || err.code == 11200304).assertTrue() 372 console.info('hiSysEventJsUnitTest006 end') 373 done() 374 } 375 }, 1000); 376 } catch (err) { 377 console.error(`hiSysEventJsUnitTest006 > error code: ${err.code}, error msg: ${err.message}`) 378 expect(false).assertTrue() 379 console.info('hiSysEventJsUnitTest006 end') 380 done() 381 } 382 }) 383 384 /** 385 * @tc.name: hiSysEventJsUnitTest007 386 * @tc.desc: Test query callback with domain which length is over 32 387 * @tc.type: FUNC 388 */ 389 it('hiSysEventJsUnitTest007', 0, async function (done) { 390 console.info('hiSysEventJsUnitTest007 start') 391 try { 392 hiSysEvent.write({ 393 domain: "RELIABILITY", 394 name: "STACK", 395 eventType: hiSysEvent.EventType.FAULT, 396 params: { 397 PID: 1, 398 UID: 1, 399 PACKAGE_NAME: "com.huawei.testHiSysEvent", 400 PROCESS_NAME: "hiview napi test suite", 401 MSG: "no msg." 402 } 403 }, (err, val) => { 404 if (err) { 405 console.error('in hiSysEventJsUnitTest007 test callback: err.code = ' + err.code) 406 } else { 407 console.info('in hiSysEventJsUnitTest007 test callback: result = ' + val) 408 } 409 }) 410 setTimeout(() => { 411 try { 412 hiSysEvent.query({ 413 beginTime: -1, 414 endTime: -1, 415 maxEvents: 2, 416 }, [{ 417 domain: "RELIABILITY", 418 names: ["STACK_STACK_STACK_STACK_STACK_STACK"], 419 }], { 420 onQuery: function (infos) { 421 console.info(`hiSysEventJsUnitTest007: onQuery...`) 422 expect(infos.length >= 0).assertTrue() 423 console.info(`hiSysEventJsUnitTest007: infos.size is ${infos.length}`) 424 if (infos instanceof Array) { 425 for (let i = 0; i < infos.length; i++) { 426 let item = infos[i]; 427 console.info(`hiSysEventJsUnitTest005: domain is ${item.domain}, name is ${item.name}, eventType is ${item.eventType}`) 428 if (item.params instanceof Object) { 429 for (const key in item.params) { 430 console.info(`hiSysEventJsUnitTest005: ${key}: ${item.params[key]}`) 431 } 432 } 433 } 434 } 435 }, 436 onComplete: function(reason, total) { 437 console.info(`hiSysEventJsUnitTest007: onComplete...`) 438 console.info(`hiSysEventJsUnitTest007: reason is ${reason}, total is ${total}`) 439 expect(true).assertTrue() 440 console.info(`hiSysEventJsUnitTest007 end`) 441 done() 442 } 443 }) 444 } catch (err) { 445 console.error(`hiSysEventJsUnitTest007 delay > error code: ${err.code}, error msg: ${err.message}`) 446 expect(err.code == 11200302 || err.code == 11200304).assertTrue() 447 console.info('hiSysEventJsUnitTest007 end') 448 done() 449 } 450 }, 1000); 451 } catch (err) { 452 console.error(`hiSysEventJsUnitTest007 > error code: ${err.code}, error msg: ${err.message}`) 453 expect(false).assertTrue() 454 console.info('hiSysEventJsUnitTest007 end') 455 done() 456 } 457 }) 458 459 /** 460 * @tc.name: hiSysEventJsUnitTest008 461 * @tc.desc: Test hisysevent of invalid domain writing with calling AsyncCallback 462 * @tc.type: FUNC 463 */ 464 it('hiSysEventJsUnitTest008', 0, async function (done) { 465 console.info('hiSysEventJsUnitTest008 start') 466 try { 467 hiSysEvent.write({ 468 domain: "RELIABILITY_RELIABILITY", 469 name: "STACK", 470 eventType: hiSysEvent.EventType.FAULT, 471 params: { 472 PID: 1, 473 UID: 1, 474 PACKAGE_NAME: "com.huawei.testHiSysEvent", 475 PROCESS_NAME: "hiview js test suite", 476 MSG: "no msg." 477 } 478 }, (err, val) => { 479 if (err) { 480 console.error(`in hiSysEventJsUnitTest008 test callback: err.code = ${err.code}, error msg is ${err.message}`) 481 expect(err.code == 11200001).assertTrue() 482 } else { 483 console.info(`in hiSysEventJsUnitTest008 test callback: result = ${val}`) 484 expect(false).assertTrue() 485 } 486 console.info('hiSysEventJsUnitTest008 end') 487 done() 488 }) 489 } catch (err) { 490 console.error(`hiSysEventJsUnitTest008 > error code: ${err.code}, error msg: ${err.message}`) 491 expect(false).assertTrue() 492 console.info('hiSysEventJsUnitTest008 end') 493 done() 494 } 495 }) 496 497 /** 498 * @tc.name: hiSysEventJsUnitTest009 499 * @tc.desc: Test hisysevent of invalid event name writing with calling AsyncCallback 500 * @tc.type: FUNC 501 */ 502 it('hiSysEventJsUnitTest009', 0, async function (done) { 503 console.info('hiSysEventJsUnitTest009 start') 504 try { 505 hiSysEvent.write({ 506 domain: "RELIABILITY", 507 name: "STACK_STACK_STACK_STACK_STACK_STACK", 508 eventType: hiSysEvent.EventType.FAULT, 509 params: { 510 PID: 1, 511 UID: 1, 512 PACKAGE_NAME: "com.huawei.testHiSysEvent", 513 PROCESS_NAME: "hiview js test suite", 514 MSG: "no msg." 515 } 516 }, (err, val) => { 517 if (err) { 518 console.error(`in hiSysEventJsUnitTest009 test callback: err.code = ${err.code}, error msg is ${err.message}`) 519 expect(err.code == 11200002).assertTrue() 520 } else { 521 console.info(`in hiSysEventJsUnitTest009 test callback: result = ${val}`) 522 expect(false).assertTrue() 523 } 524 console.info('hiSysEventJsUnitTest009 end') 525 done() 526 }) 527 } catch (err) { 528 console.error(`hiSysEventJsUnitTest009 > error code: ${err.code}, error msg: ${err.message}`) 529 expect(false).assertTrue() 530 console.info('hiSysEventJsUnitTest009 end') 531 done() 532 } 533 }) 534 535 /** 536 * @tc.name: hiSysEventJsUnitTest010 537 * @tc.desc: Test hisysevent which is over size writing with calling AsyncCallback 538 * @tc.type: FUNC 539 */ 540 it('hiSysEventJsUnitTest010', 0, async function (done) { 541 console.info('hiSysEventJsUnitTest010 start') 542 let params = { 543 PID: 1, 544 UID: 1, 545 PACKAGE_NAME: "com.huawei.testHiSysEvent", 546 PROCESS_NAME: "just a testcase", 547 MSG: "no msg." 548 } 549 for (let i = 0; i < 40; i++) { 550 params[`bundle${i}`] = Array.from({length: 10 * 1024}).join("ohos") 551 } 552 try { 553 hiSysEvent.write({ 554 domain: "RELIABILITY", 555 name: "STACK", 556 eventType: hiSysEvent.EventType.FAULT, 557 params: params, 558 }, (err, val) => { 559 if (err) { 560 console.error(`in hiSysEventJsUnitTest010 test callback: err.code = ${err.code}, error msg is ${err.message}`) 561 expect(err.code == 11200004).assertTrue() 562 } else { 563 console.info(`in hiSysEventJsUnitTest010 test callback: result = ${val}`) 564 expect(false).assertTrue() 565 } 566 console.info('hiSysEventJsUnitTest010 end') 567 done() 568 }) 569 } catch (err) { 570 console.error(`hiSysEventJsUnitTest010 > error code: ${err.code}, error msg: ${err.message}`) 571 expect(false).assertTrue() 572 console.info('hiSysEventJsUnitTest010 end') 573 done() 574 } 575 }) 576 577 /** 578 * @tc.name: hiSysEventJsUnitTest011 579 * @tc.desc: Test hisysevent of invalid param name writing with calling AsyncCallback 580 * @tc.type: FUNC 581 */ 582 it('hiSysEventJsUnitTest011', 0, async function (done) { 583 console.info('hiSysEventJsUnitTest011 start') 584 try { 585 hiSysEvent.write({ 586 domain: "RELIABILITY", 587 name: "STACK", 588 eventType: hiSysEvent.EventType.FAULT, 589 params: { 590 PID: 1, 591 UID: 1, 592 STACK_STACK_STACK_STACK_STACK_STACK_STACK_STACK_STACK_STACK_STACK_STACK: "com.huawei.testHiSysEvent", 593 PROCESS_NAME: "hiview js test suite", 594 MSG: "no msg." 595 } 596 }, (err, val) => { 597 if (err) { 598 console.error(`in hiSysEventJsUnitTest011 test callback: err.code = ${err.code}, error msg is ${err.message}`) 599 expect(err.code == 11200051).assertTrue() 600 } else { 601 console.info(`in hiSysEventJsUnitTest011 test callback: result = ${val}`) 602 expect(false).assertTrue() 603 } 604 console.info('hiSysEventJsUnitTest011 end') 605 done() 606 }) 607 } catch (err) { 608 console.error(`hiSysEventJsUnitTest011 > error code: ${err.code}, error msg: ${err.message}`) 609 expect(false).assertTrue() 610 console.info('hiSysEventJsUnitTest011 end') 611 done() 612 } 613 }) 614 615 /** 616 * @tc.name: hiSysEventJsUnitTest012 617 * @tc.desc: Test hisysevent with string over limit writing with calling AsyncCallback 618 * @tc.type: FUNC 619 */ 620 it('hiSysEventJsUnitTest012', 0, async function (done) { 621 console.info('hiSysEventJsUnitTest012 start') 622 try { 623 hiSysEvent.write({ 624 domain: "RELIABILITY", 625 name: "STACK", 626 eventType: hiSysEvent.EventType.FAULT, 627 params: { 628 PID: 1, 629 UID: 1, 630 PACKAGE_NAME: "com.huawei.testHiSysEvent", 631 PROCESS_NAME: Array.from({length: 10 * 1024 + 10}).join("ohos"), 632 MSG: "no msg." 633 } 634 }, (err, val) => { 635 if (err) { 636 console.error(`in hiSysEventJsUnitTest012 test callback: err.code = ${err.code}, error msg is ${err.message}`) 637 expect(err.code == 11200052).assertTrue() 638 } else { 639 console.info(`in hiSysEventJsUnitTest012 test callback: result = ${val}`) 640 expect(false).assertTrue() 641 } 642 console.info('hiSysEventJsUnitTest012 end') 643 done() 644 }) 645 } catch (err) { 646 console.error(`hiSysEventJsUnitTest012 > error code: ${err.code}, error msg: ${err.message}`) 647 expect(false).assertTrue() 648 console.info('hiSysEventJsUnitTest012 end') 649 done() 650 } 651 }) 652 653 /** 654 * @tc.name: hiSysEventJsUnitTest013 655 * @tc.desc: Test hisysevent with param count over limit writing with calling AsyncCallback 656 * @tc.type: FUNC 657 */ 658 it('hiSysEventJsUnitTest013', 0, async function (done) { 659 console.info('hiSysEventJsUnitTest013 start') 660 let largeParams = {} 661 for (let i = 0; i < 200; i++) { 662 largeParams["name" + i] = i 663 } 664 try { 665 hiSysEvent.write({ 666 domain: "RELIABILITY", 667 name: "STACK", 668 eventType: hiSysEvent.EventType.FAULT, 669 params: largeParams 670 }, (err, val) => { 671 if (err) { 672 console.error(`in hiSysEventJsUnitTest013 test callback: err.code = ${err.code}, error msg is ${err.message}`) 673 expect(err.code == 11200053).assertTrue() 674 } else { 675 console.info(`in hiSysEventJsUnitTest013 test callback: result = ${val}`) 676 expect(false).assertTrue() 677 } 678 console.info('hiSysEventJsUnitTest013 end') 679 done() 680 }) 681 } catch (err) { 682 console.error(`hiSysEventJsUnitTest013 > error code: ${err.code}, error msg: ${err.message}`) 683 expect(false).assertTrue() 684 console.info('hiSysEventJsUnitTest013 end') 685 done() 686 } 687 }) 688 689 /** 690 * @tc.name: hiSysEventJsUnitTest014 691 * @tc.desc: Test hisysevent with array size over limit writing with calling AsyncCallback 692 * @tc.type: FUNC 693 */ 694 it('hiSysEventJsUnitTest014', 0, async function (done) { 695 console.info('hiSysEventJsUnitTest014 start') 696 let msgArray = [] 697 for (let i = 0; i < 200; i++) { 698 msgArray[i] = i 699 } 700 try { 701 hiSysEvent.write({ 702 domain: "RELIABILITY", 703 name: "STACK", 704 eventType: hiSysEvent.EventType.FAULT, 705 params: { 706 PID: 1, 707 UID: 1, 708 PACKAGE_NAME: "com.huawei.testHiSysEvent", 709 PROCESS_NAME: "hiview js test suite", 710 MSG: msgArray 711 } 712 }, (err, val) => { 713 if (err) { 714 console.error(`in hiSysEventJsUnitTest014 test callback: err.code = ${err.code}, error msg is ${err.message}`) 715 expect(err.code == 11200054).assertTrue() 716 } else { 717 console.info(`in hiSysEventJsUnitTest014 test callback: result = ${val}`) 718 expect(false).assertTrue() 719 } 720 console.info('hiSysEventJsUnitTest014 end') 721 done() 722 }) 723 } catch (err) { 724 console.error(`hiSysEventJsUnitTest014 > error code: ${err.code}, error msg: ${err.message}`) 725 expect(false).assertTrue() 726 console.info('hiSysEventJsUnitTest014 end') 727 done() 728 } 729 }) 730 731 /** 732 * @tc.name: hiSysEventJsUnitTest015 733 * @tc.desc: Test hisysevent query with sequence 734 * @tc.type: FUNC 735 */ 736 it('hiSysEventJsUnitTest015', 0, async function (done) { 737 console.info('hiSysEventJsUnitTest015 start') 738 try { 739 hiSysEvent.query({ 740 maxEvents: 10000, 741 fromSeq: 100, 742 toSeq: 1000, 743 }, [{ 744 domain: "AAFWK", 745 names: ["CONNECT_SERVICE"], 746 }], { 747 onQuery: function (infos) { 748 console.info(`hiSysEventJsUnitTest015: onQuery...`) 749 expect(infos.length >= 0).assertTrue() 750 console.info(`hiSysEventJsUnitTest015: infos.size is ${infos.length}`) 751 if (infos instanceof Array) { 752 for (let i = 0; i < infos.length; i++) { 753 let item = infos[i]; 754 console.info(`hiSysEventJsUnitTest015: domain is ${item.domain}, name is ${item.name}, eventType is ${item.eventType}`) 755 if (item.params instanceof Object) { 756 for (const key in item.params) { 757 console.info(`hiSysEventJsUnitTest015: ${key}: ${item.params[key]}`) 758 } 759 } 760 } 761 } 762 }, 763 onComplete: function(reason, total, seq) { 764 console.info(`hiSysEventJsUnitTest015: onComplete...`) 765 console.info(`hiSysEventJsUnitTest015: reason is ${reason}, total is ${total}, seq is ${seq}`) 766 expect(true).assertTrue() 767 console.info(`hiSysEventJsUnitTest015 end`) 768 done() 769 } 770 }) 771 } catch (err) { 772 console.error(`hiSysEventJsUnitTest015 delay > error code: ${err.code}, error msg: ${err.message}`) 773 expect(err.code == 201).assertTrue() 774 console.info('hiSysEventJsUnitTest015 end') 775 done() 776 } 777 }) 778 779 /** 780 * @tc.name: hiSysEventJsUnitTest016 781 * @tc.desc: Test hisysevent get max sequence 782 * @tc.type: FUNC 783 */ 784 it('hiSysEventJsUnitTest016', 0, async function (done) { 785 console.info('hiSysEventJsUnitTest016 start') 786 try { 787 hiSysEvent.query({ 788 maxEvents: 0, 789 fromSeq: 0, 790 toSeq: 1000, 791 }, [{ 792 domain: "AAFWK", 793 names: ["CONNECT_SERVICE"], 794 }], { 795 onQuery: function (infos) { 796 console.info(`hiSysEventJsUnitTest016: onQuery...`) 797 expect(infos.length >= 0).assertTrue() 798 console.info(`hiSysEventJsUnitTest016: infos.size is ${infos.length}`) 799 if (infos instanceof Array) { 800 for (let i = 0; i < infos.length; i++) { 801 let item = infos[i]; 802 console.info(`hiSysEventJsUnitTest016: domain is ${item.domain}, name is ${item.name}, eventType is ${item.eventType}`) 803 if (item.params instanceof Object) { 804 for (const key in item.params) { 805 console.info(`hiSysEventJsUnitTest016: ${key}: ${item.params[key]}`) 806 } 807 } 808 } 809 } 810 }, 811 onComplete: function(reason, total, seq) { 812 console.info(`hiSysEventJsUnitTest016: onComplete...`) 813 console.info(`hiSysEventJsUnitTest016: reason is ${reason}, total is ${total}, seq is ${seq}`) 814 expect(true).assertTrue() 815 console.info(`hiSysEventJsUnitTest016 end`) 816 done() 817 } 818 }) 819 } catch (err) { 820 console.error(`hiSysEventJsUnitTest016 delay > error code: ${err.code}, error msg: ${err.message}`) 821 expect(err.code == 201).assertTrue() 822 console.info('hiSysEventJsUnitTest016 end') 823 done() 824 } 825 }) 826});