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 */ 15 16// @ts-nocheck 17import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' 18import systemTimer from '@ohos.systemTimer' 19 20describe('SystemTimerNormalTest', function () { 21 console.log('start################################start'); 22 let timerCount = 0 23 24 async function createTimerCallback(options ,done){ 25 systemTimer.createTimer(options, async (err, timer) => { 26 if (err) { 27 expect(false).assertTrue(); 28 } 29 await systemTimer.destroyTimer(timer) 30 expect(timer > 0).assertEqual(true) 31 done(); 32 }) 33 } 34 35 async function createTimerPromise(options, done){ 36 systemTimer.createTimer(options).then((timerId) => { 37 systemTimer.destroyTimer(timerId) 38 expect(true).assertTrue(); 39 done(); 40 }).catch((err) => { 41 expect(false).assertTrue(); 42 done(); 43 }) 44 } 45 46 /** 47 * @tc.number: TestCreateTimerType001 48 * @tc.name: TestCreateTimerType001 49 * @tc.desc: Test createTimer for callback with type is TIMER_TYPE_REALTIME. 50 * @tc.size: MediumTest 51 * @tc.type: Function 52 * @tc.level: Level 1 53 * @tc.require: 54 */ 55 it('testCreateTimerType001', 0, async (done) => { 56 console.log("testCreateTimerType001 start") 57 let options = { 58 type: systemTimer.TIMER_TYPE_REALTIME, 59 repeat: false, 60 } 61 systemTimer.createTimer(options, async (err, timerId) => { 62 if (err) { 63 expect(false).assertTrue(); 64 } 65 await systemTimer.destroyTimer(timerId) 66 expect(timerId > 0).assertTrue(); 67 done(); 68 }) 69 console.log('testCreateTimerType001 end'); 70 }); 71 72 /** 73 * @tc.number: TestCreateTimerType002 74 * @tc.name: TestCreateTimerType002 75 * @tc.desc: Test createTimer for callback with type is TIMER_TYPE_WAKEUP. 76 * @tc.size: MediumTest 77 * @tc.type: Function 78 * @tc.level: Level 1 79 * @tc.require: 80 */ 81 it('testCreateTimerType002', 0, async (done) => { 82 console.log("testCreateTimerType002 start") 83 let options = { 84 type: systemTimer.TIMER_TYPE_WAKEUP, 85 repeat: false, 86 } 87 await createTimerCallback(options ,done); 88 console.log('testCreateTimerType002 end'); 89 }); 90 91 /** 92 * @tc.number: TestCreateTimerType003 93 * @tc.name: TestCreateTimerType003 94 * @tc.desc: Test createTimer for callback with type is TIMER_TYPE_EXACT. 95 * @tc.size: MediumTest 96 * @tc.type: Function 97 * @tc.level: Level 1 98 * @tc.require: 99 */ 100 it('testCreateTimerType003', 0, async (done) => { 101 console.log("testCreateTimerType003 start") 102 let options = { 103 type: systemTimer.TIMER_TYPE_EXACT, 104 repeat: false, 105 } 106 await createTimerCallback(options ,done); 107 console.log('testCreateTimerType003 end'); 108 }); 109 110 /** 111 * @tc.number: TestCreateTimerType004 112 * @tc.name: TestCreateTimerType004 113 * @tc.desc: Test createTimer for callback with type is TIMER_TYPE_REALTIME | TIMER_TYPE_WAKEUP. 114 * @tc.size: MediumTest 115 * @tc.type: Function 116 * @tc.level: Level 1 117 * @tc.require: 118 */ 119 it('testCreateTimerType004', 0, async (done) => { 120 console.log("testCreateTimerType004 start") 121 let options = { 122 type: systemTimer.TIMER_TYPE_REALTIME | systemTimer.TIMER_TYPE_WAKEUP, 123 repeat: false, 124 } 125 await createTimerCallback(options ,done); 126 console.log('testCreateTimerType004 end'); 127 }); 128 129 /** 130 * @tc.number: TestCreateTimerType005 131 * @tc.name: TestCreateTimerType005 132 * @tc.desc: Test createTimer for callback with type is TIMER_TYPE_REALTIME | TIMER_TYPE_EXACT. 133 * @tc.size: MediumTest 134 * @tc.type: Function 135 * @tc.level: Level 1 136 * @tc.require: 137 */ 138 it('testCreateTimerType005', 0, async (done) => { 139 console.log("testCreateTimerType005 start") 140 let options = { 141 type: systemTimer.TIMER_TYPE_REALTIME | systemTimer.TIMER_TYPE_EXACT, 142 repeat: false, 143 } 144 await createTimerCallback(options ,done); 145 console.log('testCreateTimerType005 end'); 146 }); 147 148 /** 149 * @tc.number: TestCreateTimerType006 150 * @tc.name: TestCreateTimerType006 151 * @tc.desc: Test createTimer for callback with type is TIMER_TYPE_WAKEUP | TIMER_TYPE_EXACT. 152 * @tc.size: MediumTest 153 * @tc.type: Function 154 * @tc.level: Level 1 155 * @tc.require: 156 */ 157 it('testCreateTimerType006', 0, async (done) => { 158 console.log("testCreateTimerType006 start") 159 let options = { 160 type: systemTimer.TIMER_TYPE_WAKEUP | systemTimer.TIMER_TYPE_EXACT, 161 repeat: false, 162 } 163 await createTimerCallback(options ,done); 164 console.log('testCreateTimerType006 end'); 165 }); 166 167 /** 168 * @tc.number: TestCreateTimerRepeat007 169 * @tc.name: TestCreateTimerRepeat007 170 * @tc.desc: Test createTimer for callback with repeat is true. 171 * @tc.size: MediumTest 172 * @tc.type: Function 173 * @tc.level: Level 1 174 * @tc.require: 175 */ 176 it('testCreateTimerRepeat007', 0, async (done) => { 177 console.log("testCreateTimerRepeat007 start") 178 let options = { 179 type: systemTimer.TIMER_TYPE_EXACT, 180 repeat: true, 181 } 182 await createTimerCallback(options ,done); 183 console.log('testCreateTimerRepeat007 end'); 184 }); 185 186 /** 187 * @tc.number: TestCreateTimerInterval008 188 * @tc.name: TestCreateTimerInterval008 189 * @tc.desc: Test createTimer for callback with repeat is true, interval is 0. 190 * @tc.size: MediumTest 191 * @tc.type: Function 192 * @tc.level: Level 1 193 * @tc.require: 194 */ 195 it('testCreateTimerInterval008', 0, async (done) => { 196 console.log("testCreateTimerInterval008 start") 197 let options = { 198 type: systemTimer.TIMER_TYPE_EXACT, 199 repeat: true, 200 interval: 0 201 } 202 await createTimerCallback(options ,done); 203 console.log('testCreateTimerInterval008 end'); 204 }); 205 206 /** 207 * @tc.number: TestCreateTimerInterval009 208 * @tc.name: TestCreateTimerInterval009 209 * @tc.desc: Test createTimer for callback with interval is 5000. 210 * @tc.size: MediumTest 211 * @tc.type: Function 212 * @tc.level: Level 1 213 * @tc.require: 214 */ 215 it('testCreateTimerInterval009', 0, async (done) => { 216 console.log("testCreateTimerInterval009 start") 217 let options = { 218 type: systemTimer.TIMER_TYPE_EXACT, 219 repeat: true, 220 interval: 5000 221 } 222 systemTimer.createTimer(options, async (err, timerId) => { 223 if (err) { 224 expect(false).assertTrue(); 225 } 226 await systemTimer.destroyTimer(timerId); 227 expect(typeof (timerId) === 'number' && timerId > 0).assertEqual(true); 228 done(); 229 }) 230 console.log('testCreateTimerInterval009 end'); 231 }); 232 233 /** 234 * @tc.number: TestCreateTimerType010 235 * @tc.name: TestCreateTimerType010 236 * @tc.desc: Test createTimer for promise with type is TIMER_TYPE_REALTIME. 237 * @tc.size: MediumTest 238 * @tc.type: Function 239 * @tc.level: Level 1 240 * @tc.require: 241 */ 242 it('testCreateTimerType010', 0, async (done) => { 243 console.log("testCreateTimerType010 start") 244 let options = { 245 type: systemTimer.TIMER_TYPE_REALTIME, 246 repeat: false, 247 } 248 await createTimerPromise(options, done); 249 console.log('testCreateTimerType010 end'); 250 }); 251 252 /** 253 * @tc.number: TestCreateTimerType011 254 * @tc.name: TestCreateTimerType011 255 * @tc.desc: Test createTimer for promise with type is TIMER_TYPE_WAKEUP. 256 * @tc.size: MediumTest 257 * @tc.type: Function 258 * @tc.level: Level 1 259 * @tc.require: 260 */ 261 it('testCreateTimerType011', 0, async (done) => { 262 console.log("testCreateTimerType011 start") 263 let options = { 264 type: systemTimer.TIMER_TYPE_WAKEUP, 265 repeat: false, 266 } 267 await createTimerPromise(options, done); 268 console.log('testCreateTimerType011 end'); 269 }); 270 271 /** 272 * @tc.number: TestCreateTimerType012 273 * @tc.name: TestCreateTimerType012 274 * @tc.desc: Test createTimer for promise with type is TIMER_TYPE_EXACT. 275 * @tc.size: MediumTest 276 * @tc.type: Function 277 * @tc.level: Level 1 278 * @tc.require: 279 */ 280 it('testCreateTimerType012', 0, async (done) => { 281 console.log("testCreateTimerType012 start") 282 let options = { 283 type: systemTimer.TIMER_TYPE_EXACT, 284 repeat: false, 285 } 286 await createTimerPromise(options, done); 287 console.log('testCreateTimerType012 end'); 288 }); 289 290 /** 291 * @tc.number: TestCreateTimerType013 292 * @tc.name: TestCreateTimerType013 293 * @tc.desc: Test createTimer for promise with type is TIMER_TYPE_REALTIME | TIMER_TYPE_WAKEUP. 294 * @tc.size: MediumTest 295 * @tc.type: Function 296 * @tc.level: Level 1 297 * @tc.require: 298 */ 299 it('testCreateTimerType013', 0, async (done) => { 300 console.log("testCreateTimerType013 start") 301 let options = { 302 type: systemTimer.TIMER_TYPE_REALTIME | systemTimer.TIMER_TYPE_WAKEUP, 303 repeat: false, 304 } 305 await createTimerPromise(options, done); 306 console.log('testCreateTimerType013 end'); 307 }); 308 309 /** 310 * @tc.number: TestCreateTimerType014 311 * @tc.name: TestCreateTimerType014 312 * @tc.desc: Test createTimer for promise with type is TIMER_TYPE_REALTIME | TIMER_TYPE_EXACT. 313 * @tc.size: MediumTest 314 * @tc.type: Function 315 * @tc.level: Level 1 316 * @tc.require: 317 */ 318 it('testCreateTimerType014', 0, async (done) => { 319 console.log("testCreateTimerType014 start") 320 let options = { 321 type: systemTimer.TIMER_TYPE_REALTIME | systemTimer.TIMER_TYPE_EXACT, 322 repeat: false, 323 } 324 await createTimerPromise(options, done); 325 console.log('testCreateTimerType014 end'); 326 }); 327 328 /** 329 * @tc.number: TestCreateTimerType015 330 * @tc.name: TestCreateTimerType015 331 * @tc.desc: Test createTimer for promise with type is TIMER_TYPE_WAKEUP | TIMER_TYPE_EXACT. 332 * @tc.size: MediumTest 333 * @tc.type: Function 334 * @tc.level: Level 1 335 * @tc.require: 336 */ 337 it('testCreateTimerType015', 0, async (done) => { 338 console.log("testCreateTimerType015 start") 339 let options = { 340 type: systemTimer.TIMER_TYPE_WAKEUP | systemTimer.TIMER_TYPE_EXACT, 341 repeat: false, 342 } 343 await createTimerPromise(options, done); 344 console.log('testCreateTimerType015 end'); 345 }); 346 347 /** 348 * @tc.number: TestCreateTimerRepeat016 349 * @tc.name: TestCreateTimerRepeat016 350 * @tc.desc: Test createTimer for promise with repeat is true. 351 * @tc.size: MediumTest 352 * @tc.type: Function 353 * @tc.level: Level 1 354 * @tc.require: 355 */ 356 it('testCreateTimerRepeat016', 0, async (done) => { 357 console.log("testCreateTimerRepeat016 start") 358 let options = { 359 type: systemTimer.TIMER_TYPE_EXACT, 360 repeat: true, 361 } 362 await createTimerPromise(options, done); 363 console.log('testCreateTimerRepeat016 end'); 364 }); 365 366 /** 367 * @tc.number: TestCreateTimerInterval016 368 * @tc.name: TestCreateTimerInterval016 369 * @tc.desc: Test createTimer for promise with repeat is true, interval is 0. 370 * @tc.size: MediumTest 371 * @tc.type: Function 372 * @tc.level: Level 1 373 * @tc.require: 374 */ 375 it('testCreateTimerInterval016', 0, async (done) => { 376 console.log("testCreateTimerInterval016 start") 377 let options = { 378 type: systemTimer.TIMER_TYPE_EXACT, 379 repeat: true, 380 interval: 0 381 } 382 await createTimerPromise(options, done); 383 console.log('testCreateTimerInterval016 end'); 384 }); 385 386 /** 387 * @tc.number: TestCreateTimerInterval018 388 * @tc.name: TestCreateTimerInterval018 389 * @tc.desc: Test createTimer for promise with interval is 5000. 390 * @tc.size: MediumTest 391 * @tc.type: Function 392 * @tc.level: Level 1 393 * @tc.require: 394 */ 395 it('testCreateTimerInterval018', 0, async (done) => { 396 console.log("testCreateTimerInterval018 start") 397 let options = { 398 type: systemTimer.TIMER_TYPE_EXACT, 399 repeat: true, 400 interval: 5000 401 } 402 await createTimerPromise(options, done); 403 console.log('testCreateTimerInterval018 end'); 404 }); 405 406 /** 407 * @tc.number: TestCreateTimerType019 408 * @tc.name: TestCreateTimerType019 409 * @tc.desc: Test createTimer for promise with type is TIMER_TYPE_IDLE. 410 * @tc.size: MediumTest 411 * @tc.type: Function 412 * @tc.level: Level 1 413 * @tc.require: 414 */ 415 it('TestCreateTimerType019', 0, async (done) => { 416 console.log("TestCreateTimerType019 start") 417 let options = { 418 type: systemTimer.TIMER_TYPE_IDLE, 419 repeat: false, 420 } 421 await createTimerPromise(options, done); 422 console.log('TestCreateTimerType019 end'); 423 }); 424 425 /** 426 * @tc.number: TestCreateTimerType020 427 * @tc.name: TestCreateTimerType020 428 * @tc.desc: Test createTimer for callback with type is TIMER_TYPE_IDLE. 429 * @tc.size: MediumTest 430 * @tc.type: Function 431 * @tc.level: Level 1 432 * @tc.require: 433 */ 434 it('TestCreateTimerType020', 0, async (done) => { 435 console.log("TestCreateTimerType020 start") 436 let options = { 437 type: systemTimer.TIMER_TYPE_IDLE, 438 repeat: false, 439 } 440 systemTimer.createTimer(options, (err, data) => { 441 if (err) { 442 expect(false).assertTrue(); 443 } 444 systemTimer.destroyTimer(data) 445 expect(true).assertTrue(); 446 done(); 447 }) 448 console.log('TestCreateTimerType020 end'); 449 }); 450 451 /** 452 * @tc.number: TestStartTimer001 453 * @tc.name: TestStartTimer001 454 * @tc.desc: Test startTimer for promise with triggerTime 0. 455 * @tc.size: MediumTest 456 * @tc.type: Function 457 * @tc.level: Level 1 458 * @tc.require: 459 */ 460 it('testStartTimer001', 0, async (done) => { 461 console.log("testStartTimer001 start") 462 let options = { 463 type: systemTimer.TIMER_TYPE_REALTIME, 464 repeat: false, 465 } 466 let timerId = await systemTimer.createTimer(options); 467 systemTimer.startTimer(timerId, 0).then(() => { 468 systemTimer.destroyTimer(timerId) 469 expect(true).assertTrue(); 470 done(); 471 }).catch((err) => { 472 expect(false).assertTrue(); 473 done(); 474 }) 475 console.log('testStartTimer001 end'); 476 }); 477 478 /** 479 * @tc.number: TestStartTimer002 480 * @tc.name: TestStartTimer002 481 * @tc.desc: Test startTimer for promise with start timer twice. 482 * @tc.size: MediumTest 483 * @tc.type: Function 484 * @tc.level: Level 1 485 * @tc.require: 486 */ 487 it('testStartTimer002', 0, async (done) => { 488 console.log("testStartTimer002 start") 489 let options = { 490 type: systemTimer.TIMER_TYPE_EXACT, 491 repeat: false, 492 } 493 let timerId = await systemTimer.createTimer(options); 494 systemTimer.startTimer(timerId, new Date().getTime() + 1000).then(() => { 495 expect(true).assertTrue(); 496 done(); 497 }).catch((err) => { 498 expect(false).assertTrue(); 499 done(); 500 }) 501 systemTimer.startTimer(timerId, new Date().getTime() + 1000).then(() => { 502 expect(true).assertTrue(); 503 done(); 504 }).catch((err) => { 505 expect(false).assertTrue(); 506 done(); 507 }) 508 await systemTimer.stopTimer(timerId) 509 await systemTimer.destroyTimer(timerId) 510 console.log('testStartTimer002 end'); 511 }); 512 513 /** 514 * @tc.number: TestStartTimer003 515 * @tc.name: TestStartTimer003 516 * @tc.desc: Test startTimer for callback with triggerTime 0. 517 * @tc.size: MediumTest 518 * @tc.type: Function 519 * @tc.level: Level 1 520 * @tc.require: 521 */ 522 it('testStartTimer003', 0, async (done) => { 523 console.log("testStartTimer003 start") 524 let options = { 525 type: systemTimer.TIMER_TYPE_REALTIME, 526 repeat: false, 527 } 528 let timerId = await systemTimer.createTimer(options); 529 systemTimer.startTimer(timerId, 0, (err, data) => { 530 if (err) { 531 expect(false).assertTrue(); 532 } 533 systemTimer.destroyTimer(timerId) 534 expect(typeof (data) === 'undefined').assertTrue(); 535 done(); 536 }) 537 console.log('testStartTimer003 end'); 538 }); 539 540 /** 541 * @tc.number: TestStartTimer004 542 * @tc.name: TestStartTimer004 543 * @tc.desc: Test startTimer for callback with start timer twice. 544 * @tc.size: MediumTest 545 * @tc.type: Function 546 * @tc.level: Level 1 547 * @tc.require: 548 */ 549 it('testStartTimer004', 0, async (done) => { 550 console.log("testStartTimer004 start") 551 let options = { 552 type: systemTimer.TIMER_TYPE_REALTIME, 553 repeat: false, 554 } 555 let timerId = await systemTimer.createTimer(options); 556 systemTimer.startTimer(timerId, new Date().getTime() + 1000, (err) => { 557 if (err) { 558 expect(false).assertTrue(); 559 } 560 expect(true).assertTrue(); 561 done(); 562 }) 563 systemTimer.startTimer(timerId, new Date().getTime() + 2000, (err) => { 564 if (err) { 565 expect(false).assertTrue(); 566 } 567 systemTimer.stopTimer(timerId) 568 systemTimer.destroyTimer(timerId) 569 expect(true).assertTrue(); 570 done(); 571 }) 572 console.log('testStartTimer004 end'); 573 }); 574 575 /** 576 * @tc.number: TestStopTimer001 577 * @tc.name: TestStopTimer001 578 * @tc.desc: Test stopTimer for promise not start timer. 579 * @tc.size: MediumTest 580 * @tc.type: Function 581 * @tc.level: Level 1 582 * @tc.require: 583 */ 584 it('testStopTimer001', 0, async (done) => { 585 console.log("testStopTimer001 start") 586 let options = { 587 type: systemTimer.TIMER_TYPE_REALTIME, 588 repeat: false, 589 } 590 let timerId = await systemTimer.createTimer(options); 591 systemTimer.stopTimer(timerId).then((data) => { 592 systemTimer.destroyTimer(timerId); 593 expect(typeof (data) === 'undefined').assertTrue(); 594 done(); 595 }).catch((err) => { 596 expect(false).assertTrue(); 597 done(); 598 }); 599 console.log('testStopTimer001 end'); 600 }); 601 602 /** 603 * @tc.number: TestStopTimer002 604 * @tc.name: TestStopTimer002 605 * @tc.desc: Test stopTimer for promise. 606 * @tc.size: MediumTest 607 * @tc.type: Function 608 * @tc.level: Level 1 609 * @tc.require: 610 */ 611 it('testStopTimer002', 0, async (done) => { 612 console.log("testStopTimer002 start") 613 let options = { 614 type: systemTimer.TIMER_TYPE_REALTIME, 615 repeat: false, 616 } 617 let timerId = await systemTimer.createTimer(options) 618 await systemTimer.startTimer(timerId, new Date().getTime() + 1000); 619 systemTimer.stopTimer(timerId).then(() => { 620 expect(true).assertTrue(); 621 done(); 622 }).catch((err) => { 623 expect(false).assertTrue(); 624 done(); 625 }) 626 console.log('testStopTimer002 end'); 627 }); 628 629 /** 630 * @tc.number: TestStopTimer003 631 * @tc.name: TestStopTimer003 632 * @tc.desc: Test stopTimer for promise stop timer twice. 633 * @tc.size: MediumTest 634 * @tc.type: Function 635 * @tc.level: Level 1 636 * @tc.require: 637 */ 638 it('testStopTimer003', 0, async (done) => { 639 console.log("testStopTimer003 start") 640 let options = { 641 type: systemTimer.TIMER_TYPE_EXACT, 642 repeat: false, 643 } 644 let timerId = await systemTimer.createTimer(options) 645 await systemTimer.startTimer(timerId, new Date().getTime() + 1000) 646 await systemTimer.stopTimer(timerId) 647 systemTimer.stopTimer(timerId).then(() => { 648 systemTimer.destroyTimer(timerId) 649 expect(true).assertTrue(); 650 done(); 651 }).catch((err) => { 652 expect(false).assertTrue(); 653 done(); 654 }) 655 console.log('testStopTimer003 end'); 656 }); 657 658 /** 659 * @tc.number: TestStopTimer004 660 * @tc.name: TestStopTimer004 661 * @tc.desc: Test stopTimer for promise with start and stop timer twice. 662 * @tc.size: MediumTest 663 * @tc.type: Function 664 * @tc.level: Level 1 665 * @tc.require: 666 */ 667 it('systemTimer_stopTimer_test4', 0, async (done) => { 668 console.log("SUB_systemTimer_stopTimer_JS_API_004 start") 669 let options = { 670 type: systemTimer.TIMER_TYPE_EXACT, 671 repeat: false, 672 } 673 let timerId = await systemTimer.createTimer(options) 674 await systemTimer.startTimer(timerId, new Date().getTime() + 1000) 675 await systemTimer.stopTimer(timerId) 676 systemTimer.startTimer(timerId, new Date().getTime() + 1000).then(() => { 677 systemTimer.destroyTimer(timerId) 678 expect(true).assertTrue(); 679 done(); 680 }).catch((err) => { 681 expect(false).assertTrue(); 682 done(); 683 }) 684 console.log('SUB_systemTimer_stopTimer_JS_API_004 end'); 685 }); 686 687 /** 688 * @tc.number: TestStopTimer005 689 * @tc.name: TestStopTimer005 690 * @tc.desc: Test stopTimer for callback not start timer. 691 * @tc.size: MediumTest 692 * @tc.type: Function 693 * @tc.level: Level 1 694 * @tc.require: 695 */ 696 it('testStopTimer005', 0, async (done) => { 697 console.log("testStopTimer005 start") 698 let options = { 699 type: systemTimer.TIMER_TYPE_REALTIME, 700 repeat: false, 701 } 702 let timerId = await systemTimer.createTimer(options); 703 systemTimer.stopTimer(timerId, (err, data) => { 704 if (err) { 705 expect(false).assertTrue(); 706 } 707 systemTimer.destroyTimer(timerId); 708 expect(typeof (data) === 'undefined').assertTrue(); 709 done(); 710 }) 711 console.log('testStopTimer005 end'); 712 }); 713 714 /** 715 * @tc.number: TestStopTimer006 716 * @tc.name: TestStopTimer006 717 * @tc.desc: Test stopTimer for callback. 718 * @tc.size: MediumTest 719 * @tc.type: Function 720 * @tc.level: Level 1 721 * @tc.require: 722 */ 723 it('testStopTimer006', 0, async (done) => { 724 console.log("testStopTimer006 start") 725 let options = { 726 type: systemTimer.TIMER_TYPE_REALTIME, 727 repeat: false, 728 } 729 let timerId = await systemTimer.createTimer(options) 730 await systemTimer.startTimer(timerId, new Date().getTime() + 1000); 731 systemTimer.stopTimer(timerId, (err) => { 732 if (err) { 733 expect(false).assertTrue(); 734 } 735 systemTimer.destroyTimer(timerId); 736 expect(true).assertTrue(); 737 done(); 738 }) 739 console.log('testStopTimer006 end'); 740 }); 741 742 /** 743 * @tc.number: TestStopTimer007 744 * @tc.name: TestStopTimer007 745 * @tc.desc: Test stopTimer for callback stop timer twice. 746 * @tc.size: MediumTest 747 * @tc.type: Function 748 * @tc.level: Level 1 749 * @tc.require: 750 */ 751 it('testStopTimer007', 0, async (done) => { 752 console.log("testStopTimer007 start") 753 let options = { 754 type: systemTimer.TIMER_TYPE_EXACT, 755 repeat: false, 756 } 757 let timerId = await systemTimer.createTimer(options) 758 await systemTimer.startTimer(timerId, new Date().getTime() + 1000) 759 await systemTimer.stopTimer(timerId) 760 systemTimer.stopTimer(timerId, (err) => { 761 if (err) { 762 expect(false).assertTrue(); 763 } 764 systemTimer.destroyTimer(timerId); 765 expect(true).assertTrue(); 766 done(); 767 }) 768 console.log('testStopTimer007 end'); 769 }); 770 771 /** 772 * @tc.number: TestStopTimer008 773 * @tc.name: TestStopTimer008 774 * @tc.desc: Test stopTimer for callback with start and stop timer twice. 775 * @tc.size: MediumTest 776 * @tc.type: Function 777 * @tc.level: Level 1 778 * @tc.require: 779 */ 780 it('testStopTimer008', 0, async (done) => { 781 console.log("testStopTimer008 start") 782 let options = { 783 type: systemTimer.TIMER_TYPE_EXACT, 784 repeat: false, 785 } 786 let timerId = await systemTimer.createTimer(options) 787 await systemTimer.startTimer(timerId, new Date().getTime() + 1000) 788 systemTimer.stopTimer(timerId, (err) => { 789 if (err) { 790 expect(false).assertTrue(); 791 } 792 }) 793 systemTimer.startTimer(timerId, new Date().getTime() + 1000).then(() => { 794 systemTimer.destroyTimer(timerId) 795 expect(true).assertTrue(); 796 done(); 797 }).catch((err) => { 798 expect(false).assertTrue(); 799 done(); 800 }) 801 console.log('testStopTimer008 end'); 802 }); 803 804 /** 805 * @tc.number: TestDestroyTimer001 806 * @tc.name: TestDestroyTimer001 807 * @tc.desc: Test destroyTimer for promise. 808 * @tc.size: MediumTest 809 * @tc.type: Function 810 * @tc.level: Level 1 811 * @tc.require: 812 */ 813 it('testDestroyTimer001', 0, async (done) => { 814 console.log("testDestroyTimer001 start") 815 let options = { 816 type: systemTimer.TIMER_TYPE_EXACT, 817 repeat: false, 818 } 819 let timerId = await systemTimer.createTimer(options) 820 await systemTimer.startTimer(timerId, new Date().getTime() + 1000) 821 systemTimer.destroyTimer(timerId).then((data) => { 822 expect(typeof (data) === 'undefined').assertTrue(); 823 done(); 824 }).catch((err) => { 825 expect(false).assertTrue(); 826 done(); 827 }) 828 console.log('testDestroyTimer001 end'); 829 }); 830 831 /** 832 * @tc.number: TestDestroyTimer002 833 * @tc.name: TestDestroyTimer002 834 * @tc.desc: Test destroyTimer for promise twice. 835 * @tc.size: MediumTest 836 * @tc.type: Function 837 * @tc.level: Level 1 838 * @tc.require: 839 */ 840 it('testDestroyTimer002', 0, async (done) => { 841 console.log("testDestroyTimer002 start") 842 let options = { 843 type: systemTimer.TIMER_TYPE_EXACT, 844 repeat: false, 845 } 846 let timerId = await systemTimer.createTimer(options) 847 await systemTimer.startTimer(timerId, new Date().getTime() + 1000) 848 await systemTimer.destroyTimer(timerId) 849 systemTimer.destroyTimer(timerId).then((data) => { 850 expect(false).assertTrue(); 851 done(); 852 }).catch((err) => { 853 expect(true).assertTrue(); 854 done(); 855 }) 856 console.log('testDestroyTimer002 end'); 857 }); 858 859 /** 860 * @tc.number: TestDestroyTimer003 861 * @tc.name: TestDestroyTimer003 862 * @tc.desc: Test destroyTimer for promise before start timer. 863 * @tc.size: MediumTest 864 * @tc.type: Function 865 * @tc.level: Level 1 866 * @tc.require: 867 */ 868 it('testDestroyTimer003', 0, async (done) => { 869 console.log("testDestroyTimer003 start") 870 let options = { 871 type: systemTimer.TIMER_TYPE_EXACT, 872 repeat: false, 873 } 874 let timerId = await systemTimer.createTimer(options) 875 await systemTimer.startTimer(timerId, new Date().getTime() + 1000) 876 await systemTimer.destroyTimer(timerId) 877 systemTimer.startTimer(timerId, new Date().getTime() + 1000).then((data) => { 878 expect(false).assertTrue(); 879 done(); 880 }).catch((err) => { 881 expect(true).assertTrue(); 882 done(); 883 }) 884 console.log('testDestroyTimer003 end'); 885 }); 886 887 /** 888 * @tc.number: TestDestroyTimer004 889 * @tc.name: TestDestroyTimer004 890 * @tc.desc: Test destroyTimer for callback. 891 * @tc.size: MediumTest 892 * @tc.type: Function 893 * @tc.level: Level 1 894 * @tc.require: 895 */ 896 it('testDestroyTimer004', 0, async (done) => { 897 console.log("testDestroyTimer004 start") 898 let options = { 899 type: systemTimer.TIMER_TYPE_EXACT, 900 repeat: false, 901 } 902 let timerId = await systemTimer.createTimer(options) 903 await systemTimer.startTimer(timerId, new Date().getTime() + 1000) 904 systemTimer.destroyTimer(timerId, (err, data) => { 905 if (err) { 906 expect(false).assertTrue(); 907 } 908 expect(typeof (data) === 'undefined').assertTrue(); 909 done(); 910 }) 911 console.log('testDestroyTimer004 end'); 912 }); 913 914 /** 915 * @tc.number: TestDestroyTimer005 916 * @tc.name: TestDestroyTimer005 917 * @tc.desc: Test destroyTimer for callback twice. 918 * @tc.size: MediumTest 919 * @tc.type: Function 920 * @tc.level: Level 1 921 * @tc.require: 922 */ 923 it('systemTimer_destroyTimer_test5', 0, async (done) => { 924 console.log("SUB_systemTimer_destroyTimer_JS_API_005 start") 925 let options = { 926 type: systemTimer.TIMER_TYPE_EXACT, 927 repeat: false, 928 } 929 let timerId = await systemTimer.createTimer(options) 930 await systemTimer.startTimer(timerId, new Date().getTime() + 1000) 931 await systemTimer.destroyTimer(timerId) 932 systemTimer.destroyTimer(timerId, (err) => { 933 if (err) { 934 expect(true).assertTrue(); 935 } else { 936 expect(false).assertTrue(); 937 } 938 done(); 939 }) 940 console.log('SUB_systemTimer_destroyTimer_JS_API_005 end'); 941 }); 942 943 /** 944 * @tc.number: TestDestroyTimer006 945 * @tc.name: TestDestroyTimer006 946 * @tc.desc: Test destroyTimer for callback before start timer. 947 * @tc.size: MediumTest 948 * @tc.type: Function 949 * @tc.level: Level 1 950 * @tc.require: 951 */ 952 it('testDestroyTimer006', 0, async (done) => { 953 console.log("testDestroyTimer006 start") 954 let options = { 955 type: systemTimer.TIMER_TYPE_EXACT, 956 repeat: false, 957 } 958 let timerId = await systemTimer.createTimer(options) 959 await systemTimer.startTimer(timerId, new Date().getTime() + 1000) 960 systemTimer.destroyTimer(timerId, (err) => { 961 if (err) { 962 expect(false).assertTrue(); 963 } else { 964 systemTimer.startTimer(timerId, new Date().getTime() + 1000).then(() => { 965 expect(false).assertTrue(); 966 done(); 967 }).catch((err) => { 968 expect(true).assertTrue(); 969 done(); 970 }) 971 } 972 done(); 973 }) 974 console.log('testDestroyTimer006 end'); 975 }); 976})