1/* 2 * Copyright (C) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import hiSysEvent from '@ohos.hiSysEvent' 16import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, TestType, Level, Size} from '@ohos/hypium' 17 18export default function hiSysEventErrcodeTest() { 19describe('hiSysEventErrcodeTest', function () { 20 beforeAll(function() { 21 console.info('hiSysEventErrcodeTest beforeAll called') 22 }) 23 24 afterAll(function() { 25 console.info('hiSysEventErrcodeTest afterAll called') 26 }) 27 28 beforeEach(function() { 29 console.info('hiSysEventErrcodeTest beforeEach called') 30 }) 31 32 afterEach(function() { 33 console.info('hiSysEventErrcodeTest afterEach called') 34 }) 35 36 /** 37 * @tc.number DFX_DFT_HiSysEvent_JS_2700 38 * @tc.name testHiSysEventApi27 39 * @tc.desc 验证调用write接口系统事件打点,领域名称长度超16个字符,忽略事件打点,错误码11200001 40 */ 41 it('testHiSysEventApi27', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) { 42 console.info('testHiSysEventApi27 start') 43 try { 44 hiSysEvent.write({ 45 domain: "RELIABILITY_RELIABILITY", 46 name: "STACK", 47 eventType: hiSysEvent.EventType.FAULT, 48 params: { 49 PID: 487, 50 UID: 103, 51 PACKAGE_NAME: "com.ohos.hisysevent.test", 52 PROCESS_NAME: "syseventservice", 53 MSG: "no msg." 54 } 55 }, (err, val) => { 56 if (err) { 57 console.error(`in testHiSysEventApi27 test callback: err.code = ${err.code}, error msg is ${err.message}`) 58 expect(err.code == 11200001).assertTrue() 59 } else { 60 console.info(`in testHiSysEventApi27 test callback: result = ${val}`) 61 expect(false).assertTrue() 62 } 63 console.info('testHiSysEventApi27 end') 64 done() 65 }) 66 } catch (error) { 67 console.error(`error code: ${error.code}, error msg: ${error.message}`); 68 expect(false).assertTrue() 69 console.info('testHiSysEventApi27 end') 70 done() 71 } 72 }) 73 74 /** 75 * @tc.number DFX_DFT_HiSysEvent_JS_2800 76 * @tc.name testHiSysEventApi28 77 * @tc.desc 验证调用write接口系统事件打点,领域名称包含特殊字符,忽略事件打点,错误码11200001 78 */ 79 it('testHiSysEventApi28', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) { 80 console.info('testHiSysEventApi28 start') 81 try { 82 hiSysEvent.write({ 83 domain: "RELIABILITY#?", 84 name: "STACK", 85 eventType: hiSysEvent.EventType.FAULT, 86 params: { 87 PID: 487, 88 UID: 103, 89 PACKAGE_NAME: "com.ohos.hisysevent.test", 90 PROCESS_NAME: "syseventservice", 91 MSG: "no msg." 92 } 93 }, (err, val) => { 94 if (err) { 95 console.error(`in testHiSysEventApi28 test callback: err.code = ${err.code}, error msg is ${err.message}`) 96 expect(err.code == 11200001).assertTrue() 97 } else { 98 console.info(`in testHiSysEventApi28 test callback: result = ${val}`) 99 expect(false).assertTrue() 100 } 101 console.info('testHiSysEventApi28 end') 102 done() 103 }) 104 } catch (error) { 105 console.error(`error code: ${error.code}, error msg: ${error.message}`); 106 expect(false).assertTrue() 107 console.info('testHiSysEventApi28 end') 108 done() 109 } 110 }) 111 112 /** 113 * @tc.number DFX_DFT_HiSysEvent_JS_2900 114 * @tc.name testHiSysEventApi29 115 * @tc.desc 验证调用write接口系统事件打点,领域名称为空,忽略事件打点,错误码11200001。 116 */ 117 it('testHiSysEventApi29', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) { 118 console.info('testHiSysEventApi29 start') 119 try { 120 hiSysEvent.write({ 121 domain: "", 122 name: "STACK", 123 eventType: hiSysEvent.EventType.FAULT, 124 params: { 125 PID: 487, 126 UID: 103, 127 PACKAGE_NAME: "com.ohos.hisysevent.test", 128 PROCESS_NAME: "syseventservice", 129 MSG: "no msg." 130 } 131 }, (err, val) => { 132 if (err) { 133 console.error(`in testHiSysEventApi29 test callback: err.code = ${err.code}, error msg is ${err.message}`) 134 expect(err.code == 11200001).assertTrue() 135 } else { 136 console.info(`in testHiSysEventApi29 test callback: result = ${val}`) 137 expect(false).assertTrue() 138 } 139 console.info('testHiSysEventApi29 end') 140 done() 141 }) 142 } catch (error) { 143 console.error(`error code: ${error.code}, error msg: ${error.message}`); 144 expect(false).assertTrue() 145 console.info('testHiSysEventApi29 end') 146 done() 147 } 148 }) 149 150 /** 151 * @tc.number DFX_DFT_HiSysEvent_JS_3000 152 * @tc.name testHiSysEventApi30 153 * @tc.desc 验证调用write接口系统事件打点,系统事件名称长度超32个字符,忽略事件打点,错误码11200002。 154 */ 155 it('testHiSysEventApi30', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) { 156 console.info('testHiSysEventApi30 start') 157 try { 158 hiSysEvent.write({ 159 domain: "RELIABILITY", 160 name: "STACK_STACK_STACK_STACK_STACK_STACK", 161 eventType: hiSysEvent.EventType.FAULT, 162 params: { 163 PID: 1, 164 UID: 1, 165 PACKAGE_NAME: "com.ohos.hisysevent.test", 166 PROCESS_NAME: "hiview js test suite", 167 MSG: "no msg." 168 } 169 }, (err, val) => { 170 if (err) { 171 console.error(`in testHiSysEventApi30 test callback: err.code = ${err.code}, error msg is ${err.message}`) 172 expect(err.code == 11200002).assertTrue() 173 } else { 174 console.info(`in testHiSysEventApi30 test callback: result = ${val}`) 175 expect(false).assertTrue() 176 } 177 console.info('testHiSysEventApi30 end') 178 done() 179 }) 180 } catch (err) { 181 console.error(`testHiSysEventApi30 > error code: ${err.code}, error msg: ${err.message}`) 182 expect(false).assertTrue() 183 console.info('testHiSysEventApi30 end') 184 done() 185 } 186 }) 187 188 /** 189 * @tc.number DFX_DFT_HiSysEvent_JS_3100 190 * @tc.name testHiSysEventApi31 191 * @tc.desc 验证调用write接口系统事件打点,系统事件名称包含特殊字符,忽略事件打点,错误码11200002。 192 */ 193 it('testHiSysEventApi31', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) { 194 console.info('testHiSysEventApi31 start') 195 try { 196 hiSysEvent.write({ 197 domain: "RELIABILITY", 198 name: "STACK#?", 199 eventType: hiSysEvent.EventType.FAULT, 200 params: { 201 PID: 1, 202 UID: 1, 203 PACKAGE_NAME: "com.ohos.hisysevent.test", 204 PROCESS_NAME: "hiview js test suite", 205 MSG: "no msg." 206 } 207 }, (err, val) => { 208 if (err) { 209 console.error(`in testHiSysEventApi31 test callback: err.code = ${err.code}, error msg is ${err.message}`) 210 expect(err.code == 11200002).assertTrue() 211 } else { 212 console.info(`in testHiSysEventApi31 test callback: result = ${val}`) 213 expect(false).assertTrue() 214 } 215 console.info('testHiSysEventApi31 end') 216 done() 217 }) 218 } catch (err) { 219 console.error(`testHiSysEventApi31 > error code: ${err.code}, error msg: ${err.message}`) 220 expect(false).assertTrue() 221 console.info('testHiSysEventApi31 end') 222 done() 223 } 224 }) 225 226 /** 227 * @tc.number DFX_DFT_HiSysEvent_JS_3200 228 * @tc.name testHiSysEventApi32 229 * @tc.desc 验证调用write接口系统事件打点,系统事件名称为空,忽略事件打点,错误码11200002。 230 */ 231 it('testHiSysEventApi32', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL0, async function (done) { 232 console.info('testHiSysEventApi32 start') 233 try { 234 hiSysEvent.write({ 235 domain: "RELIABILITY", 236 name: "", 237 eventType: hiSysEvent.EventType.FAULT, 238 params: { 239 PID: 1, 240 UID: 1, 241 PACKAGE_NAME: "com.ohos.hisysevent.test", 242 PROCESS_NAME: "hiview js test suite", 243 MSG: "no msg." 244 } 245 }, (err, val) => { 246 if (err) { 247 console.error(`in testHiSysEventApi32 test callback: err.code = ${err.code}, error msg is ${err.message}`) 248 expect(err.code == 11200002).assertTrue() 249 } else { 250 console.info(`in testHiSysEventApi32 test callback: result = ${val}`) 251 expect(false).assertTrue() 252 } 253 console.info('testHiSysEventApi32 end') 254 done() 255 }) 256 } catch (err) { 257 console.error(`testHiSysEventApi32 > error code: ${err.code}, error msg: ${err.message}`) 258 expect(false).assertTrue() 259 console.info('testHiSysEventApi32 end') 260 done() 261 } 262 }) 263 264 /** 265 * @tc.number DFX_DFT_HiSysEvent_JS_3500 266 * @tc.name testHiSysEventApi35 267 * @tc.desc 验证调用write接口系统事件打点,系统事件总长度超过384K,忽略事件打点,错误码11200004。 268 */ 269 it('testHiSysEventApi35', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 270 console.info('testHiSysEventApi35 start') 271 try { 272 let params = { 273 PID: 1, 274 UID: 1, 275 PACKAGE_NAME: "com.ohos.hisysevent.test", 276 PROCESS_NAME: "just a testcase", 277 MSG: "no msg." 278 } 279 for (let i = 0; i < 40; i++) { 280 params[`bundle${i}`] = Array.from({length: 10 * 1024}).join("ohos") 281 } 282 hiSysEvent.write({ 283 domain: "RELIABILITY", 284 name: "STACK", 285 eventType: hiSysEvent.EventType.FAULT, 286 params:params 287 }, (err, val) => { 288 if (err) { 289 console.error(`in testHiSysEventApi35 test callback: err.code = ${err.code}, error msg is ${err.message}`) 290 expect(err.code == 11200004).assertTrue() 291 } else { 292 console.info(`in testHiSysEventApi35 test callback: result = ${val}`) 293 expect(false).assertTrue() 294 } 295 console.info('testHiSysEventApi35 end') 296 done() 297 }) 298 } catch (err) { 299 console.error(`testHiSysEventApi35 > error code: ${err.code}, error msg: ${err.message}`) 300 expect(false).assertTrue() 301 console.info('testHiSysEventApi35 end') 302 done() 303 } 304 }) 305 306 /** 307 * @tc.number DFX_DFT_HiSysEvent_JS_3600 308 * @tc.name testHiSysEventApi36 309 * @tc.desc 验证调用write接口系统事件打点,领系统事件参数名称长度超32个字符,忽略事件打点,错误码11200051。 310 */ 311 it('testHiSysEventApi36', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 312 console.info('testHiSysEventApi36 start') 313 try { 314 hiSysEvent.write({ 315 domain: "RELIABILITY", 316 name: "STACK", 317 eventType: hiSysEvent.EventType.FAULT, 318 params: { 319 PID: 1, 320 UID: 1, 321 STACK_STACK_STACK_STACK_STACK_STACK_STACK_STACK_STACK_STACK_STACK_STACK: "com.ohos.hisysevent.test", 322 PROCESS_NAME: "hiview js test suite", 323 MSG: "no msg." 324 } 325 }, (err, val) => { 326 if (err) { 327 console.error(`in testHiSysEventApi36 test callback: err.code = ${err.code}, error msg is ${err.message}`) 328 expect(err.code == 11200051).assertTrue() 329 } else { 330 console.info(`in testHiSysEventApi36 test callback: result = ${val}`) 331 expect(false).assertTrue() 332 } 333 console.info('testHiSysEventApi36 end') 334 done() 335 }) 336 } catch (err) { 337 console.error(`testHiSysEventApi36 > error code: ${err.code}, error msg: ${err.message}`) 338 expect(false).assertTrue() 339 console.info('testHiSysEventApi36 end') 340 done() 341 } 342 }) 343 344 /** 345 * @tc.number DFX_DFT_HiSysEvent_JS_3700 346 * @tc.name testHiSysEventApi37 347 * @tc.desc 验证调用write接口系统事件打点,系统事件参数名称包含特殊字符,忽略事件打点,错误码11200051。 348 */ 349 it('testHiSysEventApi37', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 350 console.info('testHiSysEventApi37 start') 351 try { 352 hiSysEvent.write({ 353 domain: "RELIABILITY", 354 name: "STACK", 355 eventType: hiSysEvent.EventType.FAULT, 356 params: { 357 PID: 1, 358 UID: 1, 359 "STACK#?": "com.ohos.hisysevent.test", 360 PROCESS_NAME: "hiview js test suite", 361 MSG: "no msg." 362 } 363 }, (err, val) => { 364 if (err) { 365 console.error(`in testHiSysEventApi37 test callback: err.code = ${err.code}, error msg is ${err.message}`) 366 expect(err.code == 11200051).assertTrue() 367 } else { 368 console.info(`in testHiSysEventApi37 test callback: result = ${val}`) 369 expect(false).assertTrue() 370 } 371 console.info('testHiSysEventApi37 end') 372 done() 373 }) 374 } catch (err) { 375 console.error(`testHiSysEventApi37 > error code: ${err.code}, error msg: ${err.message}`) 376 expect(false).assertTrue() 377 console.info('testHiSysEventApi37 end') 378 done() 379 } 380 }) 381 382 /** 383 * @tc.number DFX_DFT_HiSysEvent_JS_3800 384 * @tc.name testHiSysEventApi38 385 * @tc.desc 验证调用write接口系统事件打点,系统事件参数名称为空,忽略事件打点,错误码11200051。 386 */ 387 it('testHiSysEventApi38', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 388 console.info('testHiSysEventApi38 start') 389 try { 390 hiSysEvent.write({ 391 domain: "RELIABILITY", 392 name: "STACK", 393 eventType: hiSysEvent.EventType.FAULT, 394 params: { 395 PID: 1, 396 UID: 1, 397 "": "com.ohos.hisysevent.test", 398 PROCESS_NAME: "hiview js test suite", 399 MSG: "no msg." 400 } 401 }, (err, val) => { 402 if (err) { 403 console.error(`in testHiSysEventApi38 test callback: err.code = ${err.code}, error msg is ${err.message}`) 404 expect(err.code == 11200051).assertTrue() 405 } else { 406 console.info(`in testHiSysEventApi38 test callback: result = ${val}`) 407 expect(false).assertTrue() 408 } 409 console.info('testHiSysEventApi38 end') 410 done() 411 }) 412 } catch (err) { 413 console.error(`testHiSysEventApi38 > error code: ${err.code}, error msg: ${err.message}`) 414 expect(false).assertTrue() 415 console.info('testHiSysEventApi38 end') 416 done() 417 } 418 }) 419 420 /** 421 * @tc.number DFX_DFT_HiSysEvent_JS_3900 422 * @tc.name testHiSysEventApi39 423 * @tc.desc 验证调用write接口系统事件打点,字符串类型的参数值的长度超过10K,忽略事件打点,错误码11200052。 424 */ 425 it('testHiSysEventApi39', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 426 console.info('testHiSysEventApi39 start') 427 try { 428 hiSysEvent.write({ 429 domain: "RELIABILITY", 430 name: "STACK", 431 eventType: hiSysEvent.EventType.FAULT, 432 params: { 433 PID: 1, 434 UID: 1, 435 PACKAGE_NAME: "com.ohos.hisysevent.test", 436 PROCESS_NAME: Array.from({length: 10 * 1024 + 10}).join("ohos"), 437 MSG: "no msg." 438 } 439 }, (err, val) => { 440 if (err) { 441 console.error(`in testHiSysEventApi39 test callback: err.code = ${err.code}, error msg is ${err.message}`) 442 expect(err.code == 11200052).assertTrue() 443 } else { 444 console.info(`in testHiSysEventApi39 test callback: result = ${val}`) 445 expect(false).assertTrue() 446 } 447 console.info('testHiSysEventApi39 end') 448 done() 449 }) 450 } catch (err) { 451 console.error(`testHiSysEventApi39 > error code: ${err.code}, error msg: ${err.message}`) 452 expect(false).assertTrue() 453 console.info('testHiSysEventApi39 end') 454 done() 455 } 456 }) 457 458 /** 459 * @tc.number DFX_DFT_HiSysEvent_JS_4000 460 * @tc.name testHiSysEventApi40 461 * @tc.desc 验证调用write接口系统事件打点,系统事件的参数数量超过128个,忽略事件打点,错误码11200053。 462 */ 463 it('testHiSysEventApi40', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 464 console.info('testHiSysEventApi40 start') 465 let largeParams = {} 466 for (let i = 0; i < 200; i++) { 467 largeParams["name" + i] = i 468 } 469 try { 470 hiSysEvent.write({ 471 domain: "RELIABILITY", 472 name: "STACK", 473 eventType: hiSysEvent.EventType.FAULT, 474 params: largeParams 475 }, (err, val) => { 476 if (err) { 477 console.error(`in testHiSysEventApi40 test callback: err.code = ${err.code}, error msg is ${err.message}`) 478 expect(err.code == 11200053).assertTrue() 479 } else { 480 console.info(`in testHiSysEventApi40 test callback: result = ${val}`) 481 expect(false).assertTrue() 482 } 483 console.info('testHiSysEventApi40 end') 484 done() 485 }) 486 } catch (err) { 487 console.error(`testHiSysEventApi40 > error code: ${err.code}, error msg: ${err.message}`) 488 expect(false).assertTrue() 489 console.info('testHiSysEventApi40 end') 490 done() 491 } 492 }) 493 494 /** 495 * @tc.number DFX_DFT_HiSysEvent_JS_4100 496 * @tc.name testHiSysEventApi41 497 * @tc.desc 验证调用write接口系统事件打点,系统事件中有数组类型的参数值的长度超过100,忽略事件打点,错误码11200054。 498 */ 499 it('testHiSysEventApi41', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 500 console.info('testHiSysEventApi41 start') 501 let msgArray = [] 502 for (let i = 0; i < 200; i++) { 503 msgArray[i] = i 504 } 505 try { 506 hiSysEvent.write({ 507 domain: "RELIABILITY", 508 name: "STACK", 509 eventType: hiSysEvent.EventType.FAULT, 510 params: { 511 PID: 1, 512 UID: 1, 513 PACKAGE_NAME: "com.ohos.hisysevent.test", 514 PROCESS_NAME: "hiview js test suite", 515 MSG: msgArray 516 } 517 }, (err, val) => { 518 if (err) { 519 console.error(`in testHiSysEventApi41 test callback: err.code = ${err.code}, error msg is ${err.message}`) 520 expect(err.code == 11200054).assertTrue() 521 } else { 522 console.info(`in testHiSysEventApi41 test callback: result = ${val}`) 523 expect(false).assertTrue() 524 } 525 console.info('testHiSysEventApi41 end') 526 done() 527 }) 528 } catch (err) { 529 console.error(`testHiSysEventApi41 > error code: ${err.code}, error msg: ${err.message}`) 530 expect(false).assertTrue() 531 console.info('testHiSysEventApi41 end') 532 done() 533 } 534 }) 535 /** 536 * @tc.number DFX_DFT_HiSysEvent_JS_4200 537 * @tc.name testHiSysEventApi42 538 * @tc.desc 验证调用addWatcher接口添加系统事件监听者,监听者数量超过限制,拒绝添加此监听者,错误码11200101。 539 */ 540 it('testHiSysEventApi42', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 541 console.info('testHiSysEventApi42 start') 542 var watcher = [] 543 try { 544 for (var i = 0; i < 31; i++) { 545 watcher[i] = { 546 rules: [{ 547 domain: "RELIABILITY" + i, 548 name: "STACK", 549 ruleType: hiSysEvent.RuleType.WHOLE_WORD, 550 }], 551 onEvent: (info) => { 552 }, 553 onServiceDied: () => { 554 } 555 } 556 hiSysEvent.addWatcher(watcher[i]) 557 } 558 }catch (err) { 559 console.error(`testHiSysEventApi42 > addWatcher error code: ${err.code}, error msg: ${err.message}`) 560 expect(err.code == 11200101).assertTrue() 561 console.info('testHiSysEventApi42 addWatcher end') 562 done() 563 } 564 setTimeout(() => { 565 try { 566 for (var i = 0; i < 31; i++) { 567 hiSysEvent.removeWatcher(watcher[i]) 568 } 569 }catch (err) { 570 console.error(`testHiSysEventApi42 > remove error code: ${err.code}, error msg: ${err.message}`) 571 expect(err.code == 11200201).assertTrue() 572 console.info('testHiSysEventApi42 remove end') 573 done() 574 } 575 }, 5000) 576 done() 577 }) 578 579 /** 580 * @tc.number DFX_DFT_HiSysEvent_JS_4300 581 * @tc.name testHiSysEventApi43 582 * @tc.desc 验证调用addWatcher接口添加系统事件监听者,监听规则数量超过限制,拒绝添加此监听者,错误码11200102。 583 */ 584 it('testHiSysEventApi43', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 585 console.info('testHiSysEventApi43 start') 586 let msgArray = [] 587 for (let i = 0; i < 21; i++) { 588 msgArray[i] = { 589 domain: "RELIABILITY" + i, 590 name: "STACK", 591 ruleType: hiSysEvent.RuleType.WHOLE_WORD, 592 } 593 } 594 try { 595 let watcher = { 596 rules: msgArray, 597 onEvent: (info) => { 598 }, 599 onServiceDied: () => { 600 } 601 } 602 hiSysEvent.addWatcher(watcher) 603 done() 604 }catch (err) { 605 console.error(`testHiSysEventApi43 > error code: ${err.code}, error msg: ${err.message}`) 606 expect(err.code == 11200102).assertTrue() 607 console.info('testHiSysEventApi43 end') 608 done() 609 } 610 }) 611 612 /** 613 * @tc.number DFX_DFT_HiSysEvent_JS_4400 614 * @tc.name testHiSysEventApi44 615 * @tc.desc 验证调用removeWatcher接口删除系统事件监听者,事件监听者为空,拒绝移除此监听者,错误码11200201。 616 */ 617 it('testHiSysEventApi44', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 618 console.info('testHiSysEventApi44 start') 619 let watcher11 = { 620 rules: [{ 621 domain: "RELIABILITY", 622 name: "STACK", 623 ruleType: hiSysEvent.RuleType.WHOLE_WORD, 624 }], 625 onEvent: (info) => { 626 }, 627 onServiceDied: () => { 628 } 629 } 630 setTimeout(() => { 631 try { 632 hiSysEvent.removeWatcher("") 633 expect(true).assertTrue() 634 console.info('testHiSysEventApi44 end') 635 done() 636 }catch (err) { 637 console.error(`testHiSysEventApi44 > error code: ${err.code}, error msg: ${err.message}`) 638 expect(err.code == 11200201).assertTrue() 639 console.info('testHiSysEventApi44 end') 640 done() 641 } 642 }, 1000) 643 }) 644 645 /** 646 * @tc.number DFX_DFT_HiSysEvent_JS_4500 647 * @tc.name testHiSysEventApi45 648 * @tc.desc 验证调用removeWatcher接口删除系统事件监听者,事件监听者不在监听队列,拒绝移除此监听者,错误码11200201。 649 */ 650 it('testHiSysEventApi45', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 651 console.info('testHiSysEventApi45 start') 652 let watcher11 = { 653 rules: [{ 654 domain: "RELIABILITY", 655 name: "STACK", 656 ruleType: hiSysEvent.RuleType.WHOLE_WORD, 657 }], 658 onEvent: (info) => { 659 }, 660 onServiceDied: () => { 661 } 662 } 663 setTimeout(() => { 664 try { 665 hiSysEvent.removeWatcher(watcher11) 666 expect(true).assertTrue() 667 console.info('testHiSysEventApi45 end') 668 done() 669 }catch (err) { 670 console.error(`testHiSysEventApi45 > error code: ${err.code}, error msg: ${err.message}`) 671 expect(err.code == 11200201).assertTrue() 672 console.info('testHiSysEventApi45 end') 673 done() 674 } 675 }, 1000) 676 }) 677 678 /** 679 * @tc.number DFX_DFT_HiSysEvent_JS_4600 680 * @tc.name testHiSysEventApi46 681 * @tc.desc 验证调用query接口查询系统事件,查询规则个数超过100个,忽略此次系统事件的查询,错误码11200301。 682 */ 683 it('testHiSysEventApi46', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 684 console.info('testHiSysEventApi46 start') 685 setTimeout(() => { 686 try { 687 let msgArray = [] 688 for (let i = 0; i < 101; i++) { 689 msgArray[i] = { 690 domain: "RELIABILITY", 691 names: ["STACK"], 692 } 693 } 694 hiSysEvent.query({ 695 beginTime: -1, 696 endTime: -1, 697 maxEvents: 2, 698 }, msgArray, { 699 onQuery: function (infos) { 700 }, 701 onComplete: function(reason, total) { 702 console.info(`testHiSysEventApi46: reason is ${reason}, total is ${total}`) 703 expect(reason != 0).assertTrue() 704 done() 705 } 706 }) 707 } catch (err) { 708 console.error(`testHiSysEventApi46 delay > error code: ${err.code}, error msg: ${err.message}`) 709 expect(err.code == 11200301).assertTrue() 710 console.info('hiSysEventJsUnitTest006 end') 711 done() 712 } 713 }, 1000); 714 }) 715 716 /** 717 * @tc.number DFX_DFT_HiSysEvent_JS_4700 718 * @tc.name testHiSysEventApi47 719 * @tc.desc 验证调用query接口查询系统事件,事件领域名称长度超过16个字符,忽略此次系统事件的查询,错误码11200302。 720 */ 721 it('testHiSysEventApi47', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 722 console.info('testHiSysEventApi47 start') 723 setTimeout(() => { 724 try { 725 hiSysEvent.query({ 726 beginTime: -1, 727 endTime: -1, 728 maxEvents: 2, 729 }, [{ 730 domain: "RELIABILITY_RELIABILITY", 731 names: ["STACK"], 732 }], { 733 onQuery: function (infos) { 734 }, 735 onComplete: function(reason, total) { 736 console.info(`testHiSysEventApi47: reason is ${reason}, total is ${total}`) 737 expect(reason != 0).assertTrue() 738 done() 739 } 740 }) 741 } catch (err) { 742 console.error(`testHiSysEventApi47 delay > error code: ${err.code}, error msg: ${err.message}`) 743 expect(err.code == 11200302 || err.code == 11200304).assertTrue() 744 console.info('testHiSysEventApi47 end') 745 done() 746 } 747 }, 2000); 748 }) 749 750 /** 751 * @tc.number DFX_DFT_HiSysEvent_JS_4800 752 * @tc.name testHiSysEventApi48 753 * @tc.desc 验证调用query接口查询系统事件,事件名称长度超过32个字符,忽略此次系统事件的查询,错误码11200302。 754 */ 755 it('testHiSysEventApi48', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 756 console.info('testHiSysEventApi48 start') 757 setTimeout(() => { 758 try { 759 hiSysEvent.query({ 760 beginTime: -1, 761 endTime: -1, 762 maxEvents: 2, 763 }, [{ 764 domain: "RELIABILITY", 765 names: ["STACK_STACK_STACK_STACK_STACK_STACK"], 766 }], { 767 onQuery: function (infos) { 768 }, 769 onComplete: function(reason, total) { 770 console.info(`testHiSysEventApi48: reason is ${reason}, total is ${total}`) 771 expect(reason != 0).assertTrue() 772 done() 773 } 774 }) 775 } catch (err) { 776 console.error(`testHiSysEventApi48 delay > error code: ${err.code}, error msg: ${err.message}`) 777 expect(err.code == 11200302 || err.code == 11200304).assertTrue() 778 console.info('testHiSysEventApi48 end') 779 done() 780 } 781 }, 2000); 782 }) 783 784 /** 785 * @tc.number DFX_DFT_HiSysEvent_JS_4900 786 * @tc.name testHiSysEventApi49 787 * @tc.desc 验证调用query接口查询系统事件,事件领域名称包含特殊字符,忽略此次系统事件的查询,错误码11200302。 788 */ 789 it('testHiSysEventApi49', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 790 console.info('testHiSysEventApi49 start') 791 setTimeout(() => { 792 try { 793 hiSysEvent.query({ 794 beginTime: -1, 795 endTime: -1, 796 maxEvents: 2, 797 }, [{ 798 domain: "RELIABILITY?#", 799 names: ["STACK"], 800 }], { 801 onQuery: function (infos) { 802 }, 803 onComplete: function(reason, total) { 804 console.info(`testHiSysEventApi49: reason is ${reason}, total is ${total}`) 805 expect(reason != 0).assertTrue() 806 done() 807 } 808 }) 809 } catch (err) { 810 console.error(`testHiSysEventApi49 delay > error code: ${err.code}, error msg: ${err.message}`) 811 expect(err.code == 11200302 || err.code == 11200304).assertTrue() 812 console.info('testHiSysEventApi49 end') 813 done() 814 } 815 }, 2000); 816 }) 817 818 /** 819 * @tc.number DFX_DFT_HiSysEvent_JS_5000 820 * @tc.name testHiSysEventApi50 821 * @tc.desc 验证调用query接口查询系统事件,事件名称包含特殊字符,忽略此次系统事件的查询,错误码11200302。 822 */ 823 it('testHiSysEventApi50', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 824 console.info('testHiSysEventApi50 start') 825 setTimeout(() => { 826 try { 827 hiSysEvent.query({ 828 beginTime: -1, 829 endTime: -1, 830 maxEvents: 2, 831 }, [{ 832 domain: "RELIABILITY", 833 names: ["STACK?#"], 834 }], { 835 onQuery: function (infos) { 836 }, 837 onComplete: function(reason, total) { 838 console.info(`testHiSysEventApi50: reason is ${reason}, total is ${total}`) 839 expect(reason != 0).assertTrue() 840 done() 841 } 842 }) 843 } catch (err) { 844 console.error(`testHiSysEventApi50 delay > error code: ${err.code}, error msg: ${err.message}`) 845 expect(err.code == 11200302 || err.code == 11200304).assertTrue() 846 console.info('testHiSysEventApi50 end') 847 done() 848 } 849 }, 2000); 850 }) 851 852 /** 853 * @tc.number DFX_DFT_HiSysEvent_JS_5100 854 * @tc.name testHiSysEventApi51 855 * @tc.desc 验证调用query接口查询系统事件,事件领域名称为空,忽略此次系统事件的查询,错误码11200302。 856 */ 857 it('testHiSysEventApi51', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 858 console.info('testHiSysEventApi51 start') 859 setTimeout(() => { 860 try { 861 hiSysEvent.query({ 862 beginTime: -1, 863 endTime: -1, 864 maxEvents: 2, 865 }, [{ 866 domain: "", 867 names: ["STACK"], 868 }], { 869 onQuery: function (infos) { 870 }, 871 onComplete: function(reason, total) { 872 console.info(`testHiSysEventApi51: reason is ${reason}, total is ${total}`) 873 expect(reason != 0).assertTrue() 874 done() 875 } 876 }) 877 } catch (err) { 878 console.error(`testHiSysEventApi51 delay > error code: ${err.code}, error msg: ${err.message}`) 879 expect(err.code == 11200302 || err.code == 11200304).assertTrue() 880 console.info('testHiSysEventApi51 end') 881 done() 882 } 883 }, 2000); 884 }) 885 886 /** 887 * @tc.number DFX_DFT_HiSysEvent_JS_5200 888 * @tc.name testHiSysEventApi52 889 * @tc.desc 验证调用query接口查询系统事件,事件名称为空,忽略此次系统事件的查询,错误码11200302。 890 */ 891 it('testHiSysEventApi52', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 892 console.info('testHiSysEventApi52 start') 893 setTimeout(() => { 894 try { 895 hiSysEvent.query({ 896 beginTime: -1, 897 endTime: -1, 898 maxEvents: 2, 899 }, [{ 900 domain: "RELIABILITY" , 901 names: [], 902 }], { 903 onQuery: function (infos) { 904 }, 905 onComplete: function(reason, total) { 906 console.info(`testHiSysEventApi52: reason is ${reason}, total is ${total}`) 907 expect(reason != 0).assertTrue() 908 done() 909 } 910 }) 911 } catch (err) { 912 console.error(`testHiSysEventApi52 delay > error code: ${err.code}, error msg: ${err.message}`) 913 expect(err.code == 11200302 || err.code == 11200304).assertTrue() 914 console.info('testHiSysEventApi52 end') 915 done() 916 } 917 }, 2000); 918 }) 919 920 /** 921 * @tc.number DFX_DFT_HiSysEvent_JS_5300 922 * @tc.name testHiSysEventApi53 923 * @tc.desc 验证调用write接口,缺少write参数,无法打点,错误码401。 924 */ 925 it('testHiSysEventApi53', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 926 console.info('testHiSysEventApi53 start') 927 try { 928 hiSysEvent.write({}, (err, val) => { 929 if (err) { 930 console.error('in testHiSysEventApi53 test callback: err.code = ' + err.code) 931 } else { 932 console.info('in testHiSysEventApi53 test callback: result = ' + val) 933 } 934 }) 935 } catch (err) { 936 console.error(`testHiSysEventApi53 > error code: ${err.code}, error msg: ${err.message}`) 937 expect(err.code == 401).assertTrue() 938 console.info('testHiSysEventApi53 end') 939 done() 940 } 941 }) 942 943 /** 944 * @tc.number DFX_DFT_HiSysEvent_JS_5400 945 * @tc.name testHiSysEventApi54 946 * @tc.desc 验证调用query接口,缺少订阅规则,错误码401。 947 */ 948 it('testHiSysEventApi54', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 949 console.info('testHiSysEventApi54 start') 950 setTimeout(() => { 951 try { 952 hiSysEvent.query( { 953 onQuery: function (infos) { 954 }, 955 onComplete: function(reason, total) { 956 console.info(`testHiSysEventApi54: reason is ${reason}, total is ${total}`) 957 expect(false).assertTrue() 958 done() 959 } 960 }) 961 } catch (err) { 962 console.error(`testHiSysEventApi54 delay > error code: ${err.code}, error msg: ${err.message}`) 963 expect(err.code == 401).assertTrue() 964 console.info('testHiSysEventApi54 end') 965 done() 966 } 967 }, 1000); 968 }) 969 970 /** 971 * @tc.number DFX_DFT_HiSysEvent_JS_5500 972 * @tc.name testHiSysEventApi55 973 * @tc.desc 验证调用addwatcher接口,缺少watcher参数,错误码401。 974 */ 975 it('testHiSysEventApi55', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 976 console.info('testHiSysEventApi55 start') 977 try { 978 let watcher = { 979 onEvent: (info) => { 980 console.info(`testHiSysEventApi12: OnEvent...`) 981 expect(Object.keys(info).length > 0).assertTrue() 982 console.info(`testHiSysEventApi12: domain is : ${info.domain}, name is ${info.name}, 983 eventType is ${info.eventType}`) 984 if (info.params instanceof Object) { 985 for (const key in info.params) { 986 console.info(`testHiSysEventApi12: ${key}: ${info.params[key]}`) 987 } 988 } 989 }, 990 onServiceDied: () => { 991 console.info(`testHiSysEventApi12 Onservice died`); 992 } 993 } 994 hiSysEvent.addWatcher(watcher) 995 } catch (err) { 996 console.error(`testHiSysEventApi55 > error code: ${err.code}, error msg: ${err.message}`) 997 expect(err.code == 401).assertTrue() 998 console.info('testHiSysEventApi55 end') 999 done() 1000 } 1001 }) 1002 1003 /** 1004 * @tc.number DFX_DFT_HiSysEvent_JS_5700 1005 * @tc.name testHiSysEventApi57 1006 * @tc.desc 验证调用query接口,查询频率超过限制,忽略此次查询,错误码11200304。。 1007 */ 1008 it('testHiSysEventApi57', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 1009 console.info('testHiSysEventApi57 start') 1010 try { 1011 for (let i = 0; i < 51; i++) { 1012 hiSysEvent.query({ 1013 beginTime: 1686827195833, 1014 endTime: 1686827195834, 1015 maxEvents: 1, 1016 }, [{ 1017 domain: "HIVIEWDFX" , 1018 names: ["SYS_USAGE"], 1019 }], { 1020 onQuery: function (infos) { 1021 }, 1022 onComplete: function(reason, total) { 1023 } 1024 }) 1025 } 1026 } catch (err) { 1027 console.error(`testHiSysEventApi57 delay > error code: ${err.code}, error msg: ${err.message}`) 1028 expect(err.code == 11200304).assertTrue() 1029 console.info('testHiSysEventApi57 end') 1030 done() 1031 } 1032 }) 1033}) 1034}