systemTimer.test.ets 28.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Copyright (C) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import WantAgent from '@ohos.wantAgent';
import systemTimer from "@ohos.systemTimer";
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';

export default function systemTimerTest() {
  describe('systemTimerTest', function () {
22
    console.info('====>systemTimer Test start');
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
    //wantAgent对象
    var wantAgent;

    //WantAgentInfo对象
    let wantAgentInfo = {
      wants: [
        {
          bundleName: "com.acts.time.test",
          abilityName: "MainAbility"
        }
      ],
      operationType: WantAgent.OperationType.SEND_COMMON_EVENT,
      requestCode: 0,
      wantAgentFlags:[WantAgent.WantAgentFlags.NO_BUILD_FLAG]
    }

    let interval_time = 5000;
    let globalTimerID = undefined;

    /**
     * beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.
     */
    beforeAll(function () {
46
      console.info('====>beforeAll: Prerequisites are executed.');
47 48 49
      WantAgent.getWantAgent(wantAgentInfo)
        .then((data) => {
          if ( data != undefined || data != null) {
50
            console.info('====>beforeAll: success to get wantAgent: ' + typeof(data));
51 52 53 54 55 56 57 58 59 60 61 62
            wantAgent = data;
          }
        })
        .catch(error => {
          console.error('beforeAll: failed to get wantAgent!');
        });
    });

    /**
     * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed.
     */
    beforeEach(function () {
63
      console.info('====>beforeEach: Prerequisites is executed.');
64 65 66 67 68 69
    });

    /**
     * afterEach: Test case-level clearance conditions, which are executed after each test case is executed.
     */
    afterEach(function () {
70
      console.info('====>afterEach: Test case-level clearance conditions is executed.');
71 72 73 74 75 76
    });

    /**
     * afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed.
     */
    afterAll(function () {
77
      console.info('====>afterAll: Test suite-level cleanup condition is executed.');
78 79 80 81 82 83 84 85 86 87 88
    });

    /**
     * @tc.number SUB_time_systemTimer_createTimer_0000
     * @tc.name SUB_time_systemTimer_createTimer_0000
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_REALTIME, repeat = false (Callback)
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 0
     */
    it('SUB_time_systemTimer_createTimer_0000', 0, async function (done) {
89
      console.info('====>SUB_time_systemTimer_createTimer_0000 start.');
90 91 92 93 94
      let options = {
        type: systemTimer.TIMER_TYPE_REALTIME,
        repeat: false
      };
      try {
95
        console.info('====>SUB_time_systemTimer_createTimer_0000 create timer.');
96 97 98 99 100 101
        systemTimer.createTimer(options, function (err, timerID) {
          if (err) {
            // 处理业务逻辑错误
            expect().assertTrue();
            done();
          }
102
          console.info('====>SUB_time_systemTimer_createTimer_0000 timerID: ' + timerID);
103 104 105 106 107 108
          globalTimerID = timerID;
          expect(Number.isInteger(timerID)).assertTrue();
          done();
        });
      } catch (err) {
        // 捕获参数错误
109
        console.info('====>SUB_time_systemTimer_createTimer_0000 has failed for ' + err);
110 111
        expect().assertTrue();
        done();
112
      };
113 114 115 116 117
    });

    /**
     * @tc.number SUB_time_systemTimer_createTimer_0001
     * @tc.name SUB_time_systemTimer_createTimer_0001
118
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_IDLE, repeat = true (callback)
119 120 121 122 123
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 0
     */
    it('SUB_time_systemTimer_createTimer_0001', 0, async function (done) {
124
      console.info('====>SUB_time_systemTimer_createTimer_0001 start.');
125
      let options = {
126
        type: systemTimer.TIMER_TYPE_IDLE,
127
        repeat: false
128
      };
129 130 131
      try {
        systemTimer.createTimer(options, function (err, timerID) {
          if (err) {
132
            console.info('====>SUB_time_systemTimer_createTimer_0001 wrong since ' + err.code);
133 134
            expect().assertTrue();
            done();
135
          };
136
          console.info('====>SUB_time_systemTimer_createTimer_0001 timerID: ' + timerID);
137 138 139 140
          expect(Number.isInteger(timerID)).assertTrue();
          done();
        });
      } catch (e) {
141
        console.info('====>SUB_time_systemTimer_createTimer_0001 arv wrong since ' + e.code);
142 143
        expect().assertTrue();
        done();
144
      };
145 146 147 148 149 150 151 152 153 154 155
    });

    /**
     * @tc.number SUB_time_systemTimer_createTimer_0002
     * @tc.name SUB_time_systemTimer_createTimer_0002
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_WAKEUP, repeat = true, interval (Callback)
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
    it('SUB_time_systemTimer_createTimer_0002', 2, async function (done) {
156
      console.info("====>SUB_time_systemTimer_createTimer_0002 start");
157
      WantAgent.getBundleName(wantAgent, (err, data)=>{
158
        console.info('====>SUB_time_systemTimer_createTimer_0002 BundleName: ' + data);
159 160 161 162 163 164
      })
      let options = {
        type: systemTimer.TIMER_TYPE_WAKEUP,
        repeat: true,
        wantAgent: wantAgent,
        interval: interval_time
165
      };
166
      try {
167
        console.info("====>SUB_time_systemTimer_createTimer_0002 create timer")
168 169
        systemTimer.createTimer(options, function (err, timerID) {
          if (err) {
170
            console.info('====>SUB_time_systemTimer_createTimer_0002 wrong since ' + err.code);
171 172 173
            expect().assertTrue();
            done();
          }
174
          console.info('====>SUB_time_systemTimer_createTimer_0002 timerID: ' + timerID);
175 176 177 178
          expect(Number.isInteger(timerID)).assertTrue();
          done();
        });
      } catch (e) {
179
        console.info('====>SUB_time_systemTimer_createTimer_0002 arv wrong since ' + e);
180 181
        expect().assertTrue();
        done();
182
      };
183 184 185 186 187 188 189 190 191 192 193
    });

    /**
     * @tc.number SUB_time_systemTimer_createTimer_0003
     * @tc.name SUB_time_systemTimer_createTimer_0003
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_EXACT, repeat = false (Callback)
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
    it('SUB_time_systemTimer_createTimer_0003', 2, async function (done) {
194
      console.info("====>SUB_time_systemTimer_createTimer_0003 start");
195 196 197
      let options = {
        type: systemTimer.TIMER_TYPE_EXACT,
        repeat: false
198
      };
199
      try {
200
        console.info("====>SUB_time_systemTimer_createTimer_0003 create timer")
201 202
        systemTimer.createTimer(options, function (err, timerID) {
          if (err) {
203
            console.info('====>SUB_time_systemTimer_createTimer_0003 wrong since ' + err.code);
204 205 206 207 208 209 210
            expect().assertTrue();
            done();
          }
          expect(Number.isInteger(timerID)).assertTrue();
          done();
        });
      } catch (e) {
Z
zwx1016320 已提交
211
        console.info('====>SUB_time_systemTimer_createTimer_0003 arv wrong since ' + e);
212 213
        expect().assertTrue();
        done();
214
      };
215 216 217 218 219
    });

    /**
     * @tc.number SUB_time_systemTimer_createTimer_0004
     * @tc.name SUB_time_systemTimer_createTimer_0004
220
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_REALTIME, repeat = false, wantAgent(callback)
221 222 223 224 225
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
    it('SUB_time_systemTimer_createTimer_0004', 2, async function (done) {
226
      console.info("====>SUB_time_systemTimer_createTimer_0004 start");
227
      WantAgent.getBundleName(wantAgent, (err, data)=>{
228
        console.info("====>SUB_time_systemTimer_createTimer_0004 BundleName: " + data);
229
      });
230 231 232 233 234
      let options = {
        type: systemTimer.TIMER_TYPE_REALTIME,
        repeat: true,
        wantAgent: wantAgent,
        interval: interval_time
235
      };
236
      try {
237
        console.info("====>SUB_time_systemTimer_createTimer_0004 create timer")
238 239 240 241
        systemTimer.createTimer(options, function (err, timerID) {
          if (err) {
            expect().assertTrue();
            done();
242
          };
243 244 245 246
          expect(Number.isInteger(timerID)).assertTrue();
          done();
        });
      } catch (e) {
247
        console.info('====>SUB_time_systemTimer_createTimer_0004 has failed for ' + e);
248 249
        expect().assertTrue();
        done();
250
      };
251 252 253 254
    });


    /**
255 256 257 258 259 260 261
     * @tc.number SUB_time_systemTimer_createTimer_0005
     * @tc.name SUB_time_systemTimer_createTimer_0005
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_REALTIME, repeat = false (Callback)
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 0
     */
262
    it('SUB_time_systemTimer_createTimer_0005', 0, async function (done) {
263
      console.info('====>SUB_time_systemTimer_createTimer_0005 start.');
264 265 266 267 268
      let options = {
        type: systemTimer.TIMER_TYPE_REALTIME,
        repeat: false
      };
      try {
269
        console.info('====>SUB_time_systemTimer_createTimer_0005 create timer.');
270
        systemTimer.createTimer(options).then((timerID) =>{
271
          console.info('====>SUB_time_systemTimer_createTimer_0005 timerID: ' + timerID);
272 273 274
          expect(Number.isInteger(timerID)).assertTrue();
          done();
        }).catch(err => {
275
          console.info('====>SUB_time_systemTimer_createTimer_0005 promise failed ' + err);
276 277 278 279
          expect().assertTrue();
          done();
        });
      } catch (err) {
280
        console.info('====>SUB_time_systemTimer_createTimer_0005 has failed for ' + err);
281 282
        expect().assertTrue();
        done();
283
      };
284 285 286 287 288
    });

    /**
     * @tc.number SUB_time_systemTimer_createTimer_0006
     * @tc.name SUB_time_systemTimer_createTimer_0006
289
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_IDLE, repeat = true (callback)
290 291 292 293 294
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 0
     */
    it('SUB_time_systemTimer_createTimer_0006', 0, async function (done) {
295
      console.info('====>SUB_time_systemTimer_createTimer_0006 start.');
296
      let options = {
297
        type: systemTimer.TIMER_TYPE_IDLE,
298
        repeat: false
299
      };
300 301
      try {
        systemTimer.createTimer(options).then((timerID) => {
302
          console.info('====>SUB_time_systemTimer_createTimer_0006 timerID: ' + timerID);
303 304 305
          expect(Number.isInteger(timerID)).assertTrue();
          done();
        }).catch(err => {
306
          console.info('====>SUB_time_systemTimer_createTimer_0006 promise failed ' + err);
307 308 309 310
          expect().assertTrue();
          done();
        });
      } catch (e) {
311
        console.info('====>SUB_time_systemTimer_createTimer_0006 arv wrong since ' + e.code);
312 313
        expect().assertTrue();
        done();
314
      };
315 316 317 318 319 320 321 322 323 324 325
    });

    /**
     * @tc.number SUB_time_systemTimer_createTimer_0007
     * @tc.name SUB_time_systemTimer_createTimer_0007
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_WAKEUP, repeat = true, interval (Callback)
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
    it('SUB_time_systemTimer_createTimer_0007', 2, async function (done) {
326
      console.info("====>SUB_time_systemTimer_createTimer_0007 start");
327
      WantAgent.getBundleName(wantAgent, (err, data)=>{
328
        console.info('====>SUB_time_systemTimer_createTimer_0007 BundleName: ' + data);
329 330 331 332 333 334
      })
      let options = {
        type: systemTimer.TIMER_TYPE_WAKEUP,
        repeat: true,
        wantAgent: wantAgent,
        interval: interval_time
335
      };
336
      try {
337
        console.info("====>SUB_time_systemTimer_createTimer_0007 create timer");
338
        systemTimer.createTimer(options).then((timerID) => {
339
          console.info('====>SUB_time_systemTimer_createTimer_0007 timerID: ' + timerID);
340 341 342
          expect(Number.isInteger(timerID)).assertTrue();
          done();
        }).catch(err => {
343
          console.info('====>SUB_time_systemTimer_createTimer_0007 promise failed ' + err);
344 345 346 347
          expect().assertTrue();
          done();
        });
      } catch (e) {
348
        console.info('====>SUB_time_systemTimer_createTimer_0007 arv wrong since ' + e);
349 350
        expect().assertTrue();
        done();
351
      };
352 353 354 355 356 357 358 359 360 361 362
    });

    /**
     * @tc.number SUB_time_systemTimer_createTimer_0008
     * @tc.name SUB_time_systemTimer_createTimer_0008
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_EXACT, repeat = false (Callback)
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
    it('SUB_time_systemTimer_createTimer_0008', 2, async function (done) {
363
      console.info("====>SUB_time_systemTimer_createTimer_0008 start");
364 365 366
      let options = {
        type: systemTimer.TIMER_TYPE_EXACT,
        repeat: false
367
      };
368
      try {
369
        console.info("====>SUB_time_systemTimer_createTimer_0008 create timer")
370 371 372 373
        systemTimer.createTimer(options).then((timerID) => {
          expect(Number.isInteger(timerID)).assertTrue();
          done();
        }).catch(err => {
374
          console.info('====>SUB_time_systemTimer_createTimer_0008 promise failed ' + err);
375 376 377 378
          expect().assertTrue();
          done();
        });
      } catch (e) {
379
        console.info('====>SUB_time_systemTimer_createTimer_0008 arv wrong since ' + e);
380 381
        expect().assertTrue();
        done();
382
      };
383 384 385 386 387
    });

    /**
     * @tc.number SUB_time_systemTimer_createTimer_0009
     * @tc.name SUB_time_systemTimer_createTimer_0009
388
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_REALTIME, repeat = false, wantAgent(callback)
389 390 391 392 393
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
    it('SUB_time_systemTimer_createTimer_0009', 2, async function (done) {
394
      console.info("====>SUB_time_systemTimer_createTimer_0009 start");
395
      WantAgent.getBundleName(wantAgent, (err, data)=>{
396
        console.info("====>SUB_time_systemTimer_createTimer_0009 BundleName: " + data);
397
      });
398 399 400 401 402
      let options = {
        type: systemTimer.TIMER_TYPE_REALTIME,
        repeat: true,
        wantAgent: wantAgent,
        interval: interval_time
403
      };
404
      try {
405
        console.info("====>SUB_time_systemTimer_createTimer_0009 create timer")
406 407 408 409
        systemTimer.createTimer(options).then((timerID) => {
          expect(Number.isInteger(timerID)).assertTrue();
          done();
        }).catch(err => {
410
          console.info('====>SUB_time_systemTimer_createTimer_0009 promise failed ' + err);
411 412 413 414
          expect().assertTrue();
          done();
        });
      } catch (e) {
415
        console.info('====>SUB_time_systemTimer_createTimer_0009 has failed for ' + e);
416 417
        expect().assertTrue();
        done();
418
      };
419 420 421 422 423 424 425 426 427 428 429
    });

    /**
     * @tc.number SUB_time_systemTimer_startTimer_0001
     * @tc.name SUB_time_systemTimer_startTimer_0001
     * @tc.desc Test startTimer() interfaces, normal call(callback)
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 0
     */
    it('SUB_time_systemTimer_startTimer_0001', 0, async function (done) {
430
      console.info("====>SUB_time_systemTimer_startTimer_0001 start");
431
      try {
432
        console.info("====>SUB_time_systemTimer_startTimer_0001 start timer, timerID: " + globalTimerID)
433 434 435
        let triggerTime = new Date().getTime() + interval_time * 1.2;
        systemTimer.startTimer(globalTimerID, triggerTime, function (err, data) {
          if (err) {
436
            console.info('====>SUB_time_systemTimer_startTimer_0001 wrong since ' + err.code);
437 438 439
            expect().assertTrue();
            done();
          }
440
          console.info("====>SUB_time_systemTimer_startTimer_0001 success to start timerID: " + globalTimerID);
441 442 443
          done();
        });
      } catch (e) {
444
        console.info('====>SUB_time_systemTimer_startTimer_0001 has failed for ' + e);
445 446
        expect().assertTrue();
        done();
447
      };
448 449 450 451 452 453 454 455 456 457 458
    });

    /**
     * @tc.number SUB_time_systemTimer_stopTimer_0001
     * @tc.name SUB_time_systemTimer_stopTimer_0001
     * @tc.desc Test startTimer() interfaces, normal call(callback)
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 0
     */
    it('SUB_time_systemTimer_stopTimer_0001', 0, async function (done) {
459
      console.info("====>SUB_time_systemTimer_stopTimer_0001 start");
460
      try {
461
        console.info("====>SUB_time_systemTimer_stopTimer_0001 stop timer, timerID: " + globalTimerID)
462 463 464 465
        systemTimer.stopTimer(globalTimerID, function (err, data) {
          if (err) {
            expect().assertTrue();
            done();
466
          };
467
          console.info("====>SUB_time_systemTimer_stopTimer_0001 success to stop timerID: " + globalTimerID);
468 469 470
          done();
        });
      } catch (e) {
471
        console.info('====>SUB_time_systemTimer_stopTimer_0001 has failed for ' + e);
472 473
        expect().assertTrue();
        done();
474
      };
475 476 477 478 479 480 481 482 483 484 485
    });

    /**
     * @tc.number SUB_time_systemTimer_destroyTimer_0001
     * @tc.name SUB_time_systemTimer_destroyTimer_0001
     * @tc.desc Test startTimer() interfaces, normal call(callback)
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 0
     */
    it('SUB_time_systemTimer_destroyTimer_0001', 0, async function (done) {
486
      console.info("====>SUB_time_systemTimer_destroyTimer_0001 start");
487
      try {
488
        console.info("====>SUB_time_systemTimer_destroyTimer_0001 destroy timer, timerID: " + globalTimerID)
489 490 491 492
        systemTimer.destroyTimer(globalTimerID, function (err, data) {
          if (err) {
            expect().assertTrue();
            done();
493
          };
494
          console.info("====>SUB_time_systemTimer_destroyTimer_0001 success to destroy timerID: " + globalTimerID);
495 496 497
          done();
        });
      } catch (e) {
498
        console.info('====>SUB_time_systemTimer_destroyTimer_0001 has failed for ' + e);
499 500
        expect().assertTrue();
        done();
501
      };
502 503 504
    });

    /**
Z
zwx1016320 已提交
505 506
     * @tc.number SUB_time_systemTimer_createTimerPromise_0001
     * @tc.name SUB_time_systemTimer_createTimerPromise_0001
507 508 509 510 511
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_REALTIME, repeat = false (Promise)
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 0
     */
Z
zwx1016320 已提交
512 513
    it('SUB_time_systemTimer_createTimerPromise_0001', 0, async function (done) {
      console.info('====>SUB_time_systemTimer_createTimerPromise_0001 start.');
514 515 516 517 518
      let options = {
        type: systemTimer.TIMER_TYPE_REALTIME,
        repeat: false
      };
      try {
Z
zwx1016320 已提交
519
        console.info('====>SUB_time_systemTimer_createTimerPromise_0001 create timer.');
520
        systemTimer.createTimer(options).then((timerID)=>{
Z
zwx1016320 已提交
521
          console.info('====>SUB_time_systemTimer_createTimerPromise_0001 timerID:' + timerID);
522 523 524
          expect(Number.isInteger(timerID)).assertTrue();
          globalTimerID = timerID;
          done();
525
        }).catch( error => {
526
          // 捕获业务逻辑错误
Z
zwx1016320 已提交
527
          console.info('====>SUB_time_systemTimer_createTimerPromise_0001 failed to create timer.');
528 529 530 531 532
          expect().assertTrue();
          done();
        });
      } catch (err) {
        // 捕获参数错误
Z
zwx1016320 已提交
533
        console.info('====>SUB_time_systemTimer_createTimerPromise_0001 has failed for ' + err);
534 535
        expect().assertTrue();
        done();
536
      };
537 538 539 540 541 542 543 544 545 546 547
    });

    /**
     * @tc.number SUB_time_systemTimer_startTimer_0002
     * @tc.name SUB_time_systemTimer_startTimer_0002
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_REALTIME, repeat = true (Promise)
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 0
     */
    it('SUB_time_systemTimer_startTimer_0002', 0, async function (done) {
548
      console.info('====>SUB_time_systemTimer_startTimer_0002 start.');
549
      try {
550
        console.info('====>SUB_time_systemTimer_startTimer_0002 start timer, timerID: ' + globalTimerID);
551 552 553
        let triggerTime = new Date().getTime() + interval_time * 2;
        systemTimer.startTimer(globalTimerID, triggerTime)
          .then(()=>{
554
            console.info('====>SUB_time_systemTimer_startTimer_0002 timerID:' + globalTimerID);
555
            done();
556 557
          }).catch(()=>{
          // 捕获业务逻辑错误
558
          console.info('====>SUB_time_systemTimer_startTimer_0002 failed to start timer.');
559 560 561
          expect().assertTrue();
          done();
        });
562 563
      } catch (err) {
        // 捕获参数错误
564
        console.info('====>SUB_time_systemTimer_startTimer_0002 has failed for ' + err);
565 566 567 568 569 570 571 572 573 574 575 576 577 578
        expect().assertTrue();
        done();
      }
    });

    /**
     * @tc.number SUB_time_systemTimer_stopTimer_0002
     * @tc.name SUB_time_systemTimer_stopTimer_0002
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_REALTIME, repeat = true (Promise)
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 0
     */
    it('SUB_time_systemTimer_stopTimer_0002', 0, async function (done) {
579
      console.info('====>SUB_time_systemTimer_stopTimer_0002 start.');
580
      try {
581
        console.info('====>SUB_time_systemTimer_stopTimer_0002 stop timer, timerID: ' + globalTimerID);
582 583
        systemTimer.stopTimer(globalTimerID)
          .then(()=>{
584
            console.info('====>SUB_time_systemTimer_stopTimer_0002 timerID:' + globalTimerID);
585
            done();
586 587
          }).catch(()=>{
          // 捕获业务逻辑错误
588
          console.info('====>SUB_time_systemTimer_stopTimer_0002 failed to stop timer.');
589 590 591
          expect().assertTrue();
          done();
        });
592 593
      } catch (err) {
        // 捕获参数错误
594
        console.info('====>SUB_time_systemTimer_stopTimer_0002 has failed for ' + err);
595 596
        expect().assertTrue();
        done();
597
      };
598 599 600 601 602 603 604 605 606 607 608
    });

    /**
     * @tc.number SUB_time_systemTimer_destroyTimer_0002
     * @tc.name SUB_time_systemTimer_destroyTimer_0002
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_REALTIME, repeat = true (Promise)
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 0
     */
    it('SUB_time_systemTimer_destroyTimer_0002', 0, async function (done) {
609
      console.info('====>SUB_time_systemTimer_destroyTimer_0002 start.');
610
      try {
611
        console.info('====>SUB_time_systemTimer_destroyTimer_0002 destroy timer, timerID: ' + globalTimerID);
612 613
        systemTimer.destroyTimer(globalTimerID)
          .then(()=>{
614
            console.info('====>SUB_time_systemTimer_destroyTimer_0002 timerID:' + globalTimerID);
615
            done();
616 617
          }).catch(()=>{
          // 捕获业务逻辑错误
618
          console.info('====>SUB_time_systemTimer_destroyTimer_0002 failed to destroy timer.');
619 620 621
          expect().assertTrue();
          done();
        });
622 623
      } catch (err) {
        // 捕获参数错误
624
        console.info('====>SUB_time_systemTimer_stopTimer_0002 has failed for ' + err);
625 626
        expect().assertTrue();
        done();
627
      };
628 629 630 631 632
    });

    /**
      * @tc.number SUB_time_systemTimer_ALL_Promise_0008
      * @tc.name SUB_time_systemTimer_ALL_Promise_0008
633
      * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_WAKEUP, repeat = false (Promise)
634 635 636 637 638
      * @tc.size MEDIUM
      * @tc.type Function
      * @tc.level Level 0
      */
    it('SUB_time_systemTimer_ALL_Promise_0008', 0, async function (done) {
639
      console.info('====>SUB_time_systemTimer_ALL_Promise_0008 start.');
640 641 642 643 644
      let options = {
        type: systemTimer.TIMER_TYPE_WAKEUP,
        repeat: false
      };
      try {
645
        console.info('====>SUB_time_systemTimer_ALL_Promise_0008 create timer.');
646 647
        systemTimer.createTimer(options)
          .then((timerID)=>{
648
            console.info('====>SUB_time_systemTimer_ALL_Promise_0008 timerID:' + timerID);
649 650 651 652 653
            expect(Number.isInteger(timerID)).assertTrue();
            try {
              let triggerTime = new Date().getTime() + interval_time * 1.2;
              systemTimer.startTimer(timerID, triggerTime)
                .then(()=>{
654
                  console.info('====>SUB_time_systemTimer_ALL_Promise_0008 start timerID: ' + timerID);
655 656 657 658
                  try {
                    systemTimer.stopTimer(timerID)
                      .then(()=>{
                        systemTimer.destroyTimer(timerID, function (err, data) {
659
                          console.info('====>SUB_time_systemTimer_ALL_Promise_0008 destroyTimer: ' + timerID);
660 661 662 663 664
                          done();
                        });
                      })
                      .catch(()=>{
                        // 捕获stopTimer业务逻辑错误
665
                        console.info('====>SUB_time_systemTimer_ALL_Promise_0008 failed to stop timer.');
666 667 668 669 670
                        expect().assertTrue();
                        done();
                      })
                  } catch (err) {
                    // 捕获stopTimer参数错误
671
                    console.info('====>SUB_time_systemTimer_ALL_Promise_0008 stopTimer with wrong arg: ' + err);
672 673 674 675 676 677
                    expect().assertTrue();
                    done();
                  }
                })
                .catch(()=>{
                  // 捕获startTimer业务逻辑错误
678
                  console.info('====>SUB_time_systemTimer_ALL_Promise_0008 failed to stop timer.');
679 680 681 682 683
                  expect().assertTrue();
                  done();
                });
            } catch (err) {
              // 捕获参数错误
684
              console.info('====>SUB_time_systemTimer_ALL_Promise_0008 startTimer with wrong arg: ' + err);
685 686 687 688 689 690
              expect().assertTrue();
              done();
            }
          })
          .catch(()=>{
            // 捕获业务逻辑错误
691
            console.info('====>SUB_time_systemTimer_ALL_Promise_0008 failed to create timer.');
692 693 694 695 696
            expect().assertTrue();
            done();
          });
      } catch (err) {
        // 捕获参数错误
697
        console.info('====>SUB_time_systemTimer_ALL_Promise_0008 createTimer with wrong arg: ' + err);
698 699 700 701 702 703 704 705
        expect().assertTrue();
        done();
      }
    });

    /**
     * @tc.number SUB_time_systemTimer_ALL_Callback_0009
     * @tc.name SUB_time_systemTimer_ALL_Callback_0009
706
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_WAKEUP, repeat = false (Promise)
707 708 709 710 711
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 0
     */
    it('SUB_time_systemTimer_ALL_Callback_0009', 0, async function (done) {
712
      console.info('====>SUB_time_systemTimer_ALL_Callback_0009 start.');
713 714 715 716 717
      let options = {
        type: systemTimer.TIMER_TYPE_WAKEUP,
        repeat: false
      };
      try {
718
        console.info('====>SUB_time_systemTimer_ALL_Callback_0009 create timer.');
719 720
        systemTimer.createTimer(options)
          .then((timerID)=>{
721
            console.info('====>SUB_time_systemTimer_ALL_Callback_0009 timerID:' + timerID);
722 723 724 725
            expect(Number.isInteger(timerID)).assertTrue();
            try {
              let triggerTime = new Date().getTime() + interval_time * 1.2;
              systemTimer.startTimer(timerID, triggerTime, ()=>{
726
                console.info('====>SUB_time_systemTimer_ALL_Callback_0009 start timerID: ' + timerID);
727 728 729
                try {
                  systemTimer.stopTimer(timerID, ()=>{
                    systemTimer.destroyTimer(timerID, function (err, data) {
730
                      console.info('====>SUB_time_systemTimer_ALL_Callback_0009 destroyTimer: ' + timerID);
731 732 733 734
                      done();
                    });
                  })
                } catch (err) {
735
                  console.info('====>SUB_time_systemTimer_ALL_Callback_0009 stopTimer with wrong arg: ' + err);
736 737 738 739 740
                  expect().assertTrue();
                  done();
                }
              })
            } catch (err) {
741
              console.info('====>SUB_time_systemTimer_ALL_Callback_0009 startTimer with wrong arg: ' + err);
742 743 744 745 746
              expect().assertTrue();
              done();
            }
          })
      } catch (err) {
747
        console.info('====>SUB_time_systemTimer_ALL_Callback_0009 createTimer with wrong arg: ' + err);
748 749 750 751 752 753
        expect().assertTrue();
        done();
      }
    });
  });
}