systemTimer.test.ets 30.6 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
    //wantAgent对象
    var wantAgent;

    //WantAgentInfo对象
    let wantAgentInfo = {
      wants: [
        {
          bundleName: "com.acts.time.test",
          abilityName: "MainAbility"
        }
      ],
Z
zwx1016320 已提交
34
      operationType: WantAgent.OperationType.START_SERVICE,
35
      requestCode: 0,
Z
zwx1016320 已提交
36
      wantAgentFlags: [WantAgent.WantAgentFlags.ONE_TIME_FLAG]
37 38 39 40 41 42 43 44
    }

    let interval_time = 5000;

    /**
     * beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.
     */
    beforeAll(function () {
45
      console.info('====>beforeAll: Prerequisites are executed.');
46 47
      WantAgent.getWantAgent(wantAgentInfo)
        .then((data) => {
Z
zwx1016320 已提交
48 49
          if (data != undefined || data != null) {
            console.info('====>beforeAll: success to get wantAgent: ' + typeof (data));
50 51 52 53 54 55 56 57 58 59 60 61
            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 () {
62
      console.info('====>beforeEach: Prerequisites is executed.');
63 64 65 66 67 68
    });

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

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

    /**
     * @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) {
88
      console.info('====>SUB_time_systemTimer_createTimer_0000 start.');
89 90 91 92
      let options = {
        type: systemTimer.TIMER_TYPE_REALTIME,
        repeat: false
      };
Z
zwx1016320 已提交
93
      console.info('====>SUB_time_systemTimer_createTimer_0000 create timer.');
94
      systemTimer.createTimer(options, async (err, timerID) => {
Z
zwx1016320 已提交
95
        try {
96
          if (err) {
Z
zwx1016320 已提交
97
            console.info('====>SUB_time_systemTimer_createTimer_0000 create fail: ' + err);
98 99 100
            expect().assertTrue();
            done();
          }
101
          console.info('====>SUB_time_systemTimer_createTimer_0000 timerID: ' + timerID);
102
          expect(Number.isInteger(timerID)).assertTrue();
103
          await systemTimer.destroyTimer(timerID)
104
          done();
Z
zwx1016320 已提交
105 106 107 108 109 110
        } catch (error) {
          console.info('====>SUB_time_systemTimer_createTimer_0000 catch err ' + error);
          done();
        };
      });
      console.info('====>SUB_time_systemTimer_createTimer_0000 end.');
111 112 113 114 115
    });

    /**
     * @tc.number SUB_time_systemTimer_createTimer_0001
     * @tc.name SUB_time_systemTimer_createTimer_0001
116
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_IDLE, repeat = true (callback)
117 118 119 120 121
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 0
     */
    it('SUB_time_systemTimer_createTimer_0001', 0, async function (done) {
122
      console.info('====>SUB_time_systemTimer_createTimer_0001 start.');
123
      let options = {
124
        type: systemTimer.TIMER_TYPE_IDLE,
125
        repeat: false
126
      };
Z
zwx1016320 已提交
127
      console.info('====>SUB_time_systemTimer_createTimer_0001 create timer.');
128
      systemTimer.createTimer(options, async (err, timerID) => {
Z
zwx1016320 已提交
129
        try {
130
          if (err) {
Z
zwx1016320 已提交
131
            console.info('====>SUB_time_systemTimer_createTimer_0001 create fail: ' + err);
132 133
            expect().assertTrue();
            done();
Z
zwx1016320 已提交
134
          }
135
          console.info('====>SUB_time_systemTimer_createTimer_0001 timerID: ' + timerID);
136
          expect(Number.isInteger(timerID)).assertTrue();
137
          await systemTimer.destroyTimer(timerID)
138
          done();
Z
zwx1016320 已提交
139 140 141 142 143 144
        } catch (error) {
          console.info('====>SUB_time_systemTimer_createTimer_0001 catch err ' + error);
          done();
        };
      });
      console.info('====>SUB_time_systemTimer_createTimer_0001 end.');
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");
Z
zwx1016320 已提交
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
      };
Z
zwx1016320 已提交
166
      console.info('====>SUB_time_systemTimer_createTimer_0002 create timer.');
167
      systemTimer.createTimer(options, async (err, timerID) => {
Z
zwx1016320 已提交
168
        try {
169
          if (err) {
Z
zwx1016320 已提交
170
            console.info('====>SUB_time_systemTimer_createTimer_0002 create fail: ' + err);
171 172 173
            expect().assertTrue();
            done();
          }
174
          console.info('====>SUB_time_systemTimer_createTimer_0002 timerID: ' + timerID);
175
          expect(Number.isInteger(timerID)).assertTrue();
176
          await systemTimer.destroyTimer(timerID)
177
          done();
Z
zwx1016320 已提交
178 179 180 181 182 183
        } catch (error) {
          console.info('====>SUB_time_systemTimer_createTimer_0002 catch err ' + error);
          done();
        };
      });
      console.info('====>SUB_time_systemTimer_createTimer_0002 end.');
184 185 186 187 188 189 190 191 192 193 194
    });

    /**
     * @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) {
195
      console.info("====>SUB_time_systemTimer_createTimer_0003 start");
196 197 198
      let options = {
        type: systemTimer.TIMER_TYPE_EXACT,
        repeat: false
199
      };
Z
zwx1016320 已提交
200
      console.info('====>SUB_time_systemTimer_createTimer_0003 create timer.');
201
      systemTimer.createTimer(options, async (err, timerID) => {
Z
zwx1016320 已提交
202
        try {
203
          if (err) {
Z
zwx1016320 已提交
204
            console.info('====>SUB_time_systemTimer_createTimer_0003 create fail: ' + err);
205 206 207
            expect().assertTrue();
            done();
          }
Z
zwx1016320 已提交
208
          console.info('====>SUB_time_systemTimer_createTimer_0003 timerID: ' + timerID);
209
          expect(Number.isInteger(timerID)).assertTrue();
210
          await systemTimer.destroyTimer(timerID)
211
          done();
Z
zwx1016320 已提交
212 213 214 215 216 217
        } catch (error) {
          console.info('====>SUB_time_systemTimer_createTimer_0003 catch err ' + error);
          done();
        };
      });
      console.info('====>SUB_time_systemTimer_createTimer_0003 end.');
218 219 220 221 222
    });

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

    /**
260 261 262 263 264 265 266
     * @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
     */
267
    it('SUB_time_systemTimer_createTimer_0005', 0, async function (done) {
268
      console.info('====>SUB_time_systemTimer_createTimer_0005 start.');
269 270 271 272
      let options = {
        type: systemTimer.TIMER_TYPE_REALTIME,
        repeat: false
      };
273
      let globalTimerID;
Z
zwx1016320 已提交
274 275
      await systemTimer.createTimer(options).then((timerID) => {
        console.info('====>SUB_time_systemTimer_createTimer_0005 timerID: ' + timerID);
276
        globalTimerID = timerID;
Z
zwx1016320 已提交
277 278 279
        expect(Number.isInteger(timerID)).assertTrue();
      }).catch(err => {
        console.info('====>SUB_time_systemTimer_createTimer_0005 createTimer fail: ' + err);
280 281
        expect().assertTrue();
        done();
Z
zwx1016320 已提交
282 283
      });
      console.info('====>SUB_time_systemTimer_createTimer_0005 end.');
284 285
      await systemTimer.destroyTimer(globalTimerID)
      done();
286 287 288 289 290
    });

    /**
     * @tc.number SUB_time_systemTimer_createTimer_0006
     * @tc.name SUB_time_systemTimer_createTimer_0006
291
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_IDLE, repeat = true (callback)
292 293 294 295 296
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 0
     */
    it('SUB_time_systemTimer_createTimer_0006', 0, async function (done) {
297
      console.info('====>SUB_time_systemTimer_createTimer_0006 start.');
298
      let options = {
299
        type: systemTimer.TIMER_TYPE_IDLE,
300
        repeat: false
301
      };
302
      let globalTimerID;
Z
zwx1016320 已提交
303 304
      await systemTimer.createTimer(options).then((timerID) => {
        console.info('====>SUB_time_systemTimer_createTimer_0006 timerID: ' + timerID);
305
        globalTimerID = timerID;
Z
zwx1016320 已提交
306 307 308
        expect(Number.isInteger(timerID)).assertTrue();
      }).catch(err => {
        console.info('====>SUB_time_systemTimer_createTimer_0006 createTimer fail: ' + err);
309 310
        expect().assertTrue();
        done();
Z
zwx1016320 已提交
311 312
      });
      console.info('====>SUB_time_systemTimer_createTimer_0006 end.');
313 314
      await systemTimer.destroyTimer(globalTimerID)
      done();
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");
Z
zwx1016320 已提交
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
      let globalTimerID;
Z
zwx1016320 已提交
337 338
      await systemTimer.createTimer(options).then((timerID) => {
        console.info('====>SUB_time_systemTimer_createTimer_0007 timerID: ' + timerID);
339
        globalTimerID = timerID;
Z
zwx1016320 已提交
340 341 342
        expect(Number.isInteger(timerID)).assertTrue();
      }).catch(err => {
        console.info('====>SUB_time_systemTimer_createTimer_0007 createTimer fail: ' + err);
343 344
        expect().assertTrue();
        done();
Z
zwx1016320 已提交
345 346
      });
      console.info('====>SUB_time_systemTimer_createTimer_0007 end.');
347 348
      await systemTimer.destroyTimer(globalTimerID)
      done();
349 350 351 352 353 354 355 356 357 358 359
    });

    /**
     * @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) {
360
      console.info("====>SUB_time_systemTimer_createTimer_0008 start");
361 362 363
      let options = {
        type: systemTimer.TIMER_TYPE_EXACT,
        repeat: false
364
      };
365
      let globalTimerID;
Z
zwx1016320 已提交
366 367
      await systemTimer.createTimer(options).then((timerID) => {
        console.info('====>SUB_time_systemTimer_createTimer_0008 timerID: ' + timerID);
368
        globalTimerID = timerID;
Z
zwx1016320 已提交
369 370 371
        expect(Number.isInteger(timerID)).assertTrue();
      }).catch(err => {
        console.info('====>SUB_time_systemTimer_createTimer_0008 createTimer fail: ' + err);
372 373
        expect().assertTrue();
        done();
Z
zwx1016320 已提交
374 375
      });
      console.info('====>SUB_time_systemTimer_createTimer_0008 end.');
376 377
      await systemTimer.destroyTimer(globalTimerID)
      done();
378 379 380 381 382
    });

    /**
     * @tc.number SUB_time_systemTimer_createTimer_0009
     * @tc.name SUB_time_systemTimer_createTimer_0009
383
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_REALTIME, repeat = false, wantAgent(callback)
384 385 386 387 388
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
    it('SUB_time_systemTimer_createTimer_0009', 2, async function (done) {
389
      console.info("====>SUB_time_systemTimer_createTimer_0009 start");
Z
zwx1016320 已提交
390
      WantAgent.getBundleName(wantAgent, (err, data) => {
391
        console.info("====>SUB_time_systemTimer_createTimer_0009 BundleName: " + data);
392
      });
393 394 395 396 397
      let options = {
        type: systemTimer.TIMER_TYPE_REALTIME,
        repeat: true,
        wantAgent: wantAgent,
        interval: interval_time
398
      };
399
      let globalTimerID;
Z
zwx1016320 已提交
400 401
      await systemTimer.createTimer(options).then((timerID) => {
        console.info('====>SUB_time_systemTimer_createTimer_0009 timerID: ' + timerID);
402
        globalTimerID = timerID;
Z
zwx1016320 已提交
403 404 405
        expect(Number.isInteger(timerID)).assertTrue();
      }).catch(err => {
        console.info('====>SUB_time_systemTimer_createTimer_0009 createTimer fail: ' + err);
406 407
        expect().assertTrue();
        done();
Z
zwx1016320 已提交
408 409
      });
      console.info('====>SUB_time_systemTimer_createTimer_0009 end.');
410 411
      await systemTimer.destroyTimer(globalTimerID)
      done();
412 413 414 415 416 417 418 419 420 421 422
    });

    /**
     * @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) {
423
      console.info("====>SUB_time_systemTimer_startTimer_0001 start");
Z
zwx1016320 已提交
424 425 426 427 428 429 430 431 432 433 434 435
      let triggerTime = new Date().getTime() + interval_time * 1.2;
      let options = {
        type: systemTimer.TIMER_TYPE_EXACT,
        repeat: false
      };
      let globalTimerID;
      await systemTimer.createTimer(options).then((timerID) => {
        console.info('====>SUB_time_systemTimer_createTimer_0009 timerID: ' + timerID);
        globalTimerID = timerID;
      }).catch(err => {
        console.info('====>SUB_time_systemTimer_createTimer_0009 createTimer fail: ' + err);
      });
436
      systemTimer.startTimer(globalTimerID, triggerTime, async (err, data) => {
Z
zwx1016320 已提交
437
        try {
438
          if (err) {
439
            console.info('====>SUB_time_systemTimer_startTimer_0001 wrong since ' + err.code);
440 441 442
            expect().assertTrue();
            done();
          }
443
          console.info("====>SUB_time_systemTimer_startTimer_0001 success to start timerID: " + globalTimerID);
Z
zwx1016320 已提交
444
          expect(true).assertTrue();
445
          await systemTimer.destroyTimer(globalTimerID)
446
          done();
Z
zwx1016320 已提交
447 448 449 450 451 452
        } catch (e) {
          console.info('====>SUB_time_systemTimer_startTimer_0001 has failed for ' + e);
          done();
        };
      });
      console.info("====>SUB_time_systemTimer_startTimer_0001 end");
453 454 455 456 457 458 459 460 461 462 463
    });

    /**
     * @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) {
464
      console.info("====>SUB_time_systemTimer_stopTimer_0001 start");
Z
zwx1016320 已提交
465 466 467 468 469 470 471 472 473 474 475
      let options = {
        type: systemTimer.TIMER_TYPE_REALTIME,
        repeat: false
      };
      let globalTimerID;
      await systemTimer.createTimer(options).then((timerID) => {
        console.info('====>SUB_time_systemTimer_createTimer_0009 timerID: ' + timerID);
        globalTimerID = timerID;
      }).catch(err => {
        console.info('====>SUB_time_systemTimer_createTimer_0009 createTimer fail: ' + err);
      });
476
      systemTimer.stopTimer(globalTimerID, async (err, data) => {
Z
zwx1016320 已提交
477
        try {
478
          if (err) {
Z
zwx1016320 已提交
479
            console.info("====>SUB_time_systemTimer_stopTimer_0001 stop fail timerID: " + globalTimerID);
480 481
            expect().assertTrue();
            done();
482
          };
483
          console.info("====>SUB_time_systemTimer_stopTimer_0001 success to stop timerID: " + globalTimerID);
Z
zwx1016320 已提交
484
          expect(true).assertTrue();
485
          await systemTimer.destroyTimer(globalTimerID)
486
          done();
Z
zwx1016320 已提交
487 488 489 490 491 492
        } catch (e) {
          console.info('====>SUB_time_systemTimer_stopTimer_0001 has failed for ' + e);
          done();
        };
      });
      console.info("====>SUB_time_systemTimer_stopTimer_0001 end");
493 494 495 496 497 498 499 500 501 502 503
    });

    /**
     * @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) {
504
      console.info("====>SUB_time_systemTimer_destroyTimer_0001 start");
Z
zwx1016320 已提交
505 506 507 508 509 510 511 512 513 514 515 516 517
      let options = {
        type: systemTimer.TIMER_TYPE_WAKEUP,
        repeat: true
      };
      let globalTimerID;
      await systemTimer.createTimer(options).then((timerID) => {
        console.info('====>SUB_time_systemTimer_createTimer_0009 timerID: ' + timerID);
        globalTimerID = timerID;
      }).catch(err => {
        console.info('====>SUB_time_systemTimer_createTimer_0009 createTimer fail: ' + err);
      });
      systemTimer.destroyTimer(globalTimerID, function (err, data) {
        try {
518
          if (err) {
Z
zwx1016320 已提交
519
            console.info("====>SUB_time_systemTimer_destroyTimer_0001 destroy timer, timerID: " + globalTimerID)
520 521
            expect().assertTrue();
            done();
522
          };
523
          console.info("====>SUB_time_systemTimer_destroyTimer_0001 success to destroy timerID: " + globalTimerID);
Z
zwx1016320 已提交
524
          expect(true).assertTrue();
525
          done();
Z
zwx1016320 已提交
526 527 528 529 530 531
        } catch (e) {
          console.info('====>SUB_time_systemTimer_destroyTimer_0001 has failed for ' + e);
          done();
        };
      });
      console.info("====>SUB_time_systemTimer_destroyTimer_0001 end");
532 533 534
    });

    /**
Z
zwx1016320 已提交
535 536
     * @tc.number SUB_time_systemTimer_createTimerPromise_0001
     * @tc.name SUB_time_systemTimer_createTimerPromise_0001
537 538 539 540 541
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_REALTIME, repeat = false (Promise)
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 0
     */
Z
zwx1016320 已提交
542 543
    it('SUB_time_systemTimer_createTimerPromise_0001', 0, async function (done) {
      console.info('====>SUB_time_systemTimer_createTimerPromise_0001 start.');
544 545 546 547
      let options = {
        type: systemTimer.TIMER_TYPE_REALTIME,
        repeat: false
      };
548
      let globalTimerID;
Z
zwx1016320 已提交
549 550 551
      console.info('====>SUB_time_systemTimer_createTimerPromise_0001 create timer.');
      await systemTimer.createTimer(options).then((timerID) => {
        console.info('====>SUB_time_systemTimer_createTimerPromise_0001 timerID:' + timerID);
552
        globalTimerID = timerID;
Z
zwx1016320 已提交
553 554 555
        expect(Number.isInteger(timerID)).assertTrue();
      }).catch(error => {
        console.info('====>SUB_time_systemTimer_createTimerPromise_0001 failed to create timer: ' + error);
556 557
        expect().assertTrue();
        done();
Z
zwx1016320 已提交
558
      });
559 560
      await systemTimer.destroyTimer(globalTimerID)
      done();
561 562 563 564 565 566 567 568 569 570 571
    });

    /**
     * @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) {
572
      console.info('====>SUB_time_systemTimer_startTimer_0002 start.');
Z
zwx1016320 已提交
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
      let options = {
        type: systemTimer.TIMER_TYPE_IDLE,
        repeat: true
      };
      let globalTimerID;
      await systemTimer.createTimer(options).then((timerID) => {
        console.info('====>SUB_time_systemTimer_createTimer_0009 timerID: ' + timerID);
        globalTimerID = timerID;
      }).catch(err => {
        console.info('====>SUB_time_systemTimer_createTimer_0009 createTimer fail: ' + err);
      });
      let triggerTime = new Date().getTime() + interval_time * 2;
      await systemTimer.startTimer(globalTimerID, triggerTime).then(() => {
        console.info('====>SUB_time_systemTimer_startTimer_0002 timerID:' + globalTimerID);
        expect(true).assertTrue();
      }).catch((err) => {
        console.info('====>SUB_time_systemTimer_startTimer_0002 failed to start timer: ' + err);
590 591
        expect().assertTrue();
        done();
Z
zwx1016320 已提交
592 593
      });
      console.info('====>SUB_time_systemTimer_startTimer_0002 end.');
594 595
      await systemTimer.destroyTimer(globalTimerID)
      done();
596 597 598 599 600 601 602 603 604 605 606
    });

    /**
     * @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) {
607
      console.info('====>SUB_time_systemTimer_stopTimer_0002 start.');
Z
zwx1016320 已提交
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
      let options = {
        type: systemTimer.TIMER_TYPE_EXACT,
        repeat: false
      };
      let globalTimerID;
      await systemTimer.createTimer(options).then((timerID) => {
        console.info('====>SUB_time_systemTimer_createTimer_0009 timerID: ' + timerID);
        globalTimerID = timerID;
      }).catch(err => {
        console.info('====>SUB_time_systemTimer_createTimer_0009 createTimer fail: ' + err);
      });
      await systemTimer.stopTimer(globalTimerID).then(() => {
        console.info('====>SUB_time_systemTimer_stopTimer_0002 timerID:' + globalTimerID);
        expect(true).assertTrue();
      }).catch((err) => {
        console.info('====>SUB_time_systemTimer_stopTimer_0002 failed to stop timer:' + err);
624 625
        expect().assertTrue();
        done();
Z
zwx1016320 已提交
626 627
      });
      console.info('====>SUB_time_systemTimer_stopTimer_0002 end.');
628 629
      await systemTimer.destroyTimer(globalTimerID)
      done();
630 631 632 633 634 635 636 637 638 639 640
    });

    /**
     * @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) {
641
      console.info('====>SUB_time_systemTimer_destroyTimer_0002 start.');
Z
zwx1016320 已提交
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
      let options = {
        type: systemTimer.TIMER_TYPE_REALTIME,
        repeat: false
      };
      let globalTimerID;
      await systemTimer.createTimer(options).then((timerID) => {
        console.info('====>SUB_time_systemTimer_createTimer_0009 timerID: ' + timerID);
        globalTimerID = timerID;
      }).catch(err => {
        console.info('====>SUB_time_systemTimer_createTimer_0009 createTimer fail: ' + err);
      });
      await systemTimer.destroyTimer(globalTimerID).then(() => {
        console.info('====>SUB_time_systemTimer_destroyTimer_0002 timerID:' + globalTimerID);
        expect(true).assertTrue();
        done();
      }).catch((err ) => {
        console.info('====>SUB_time_systemTimer_destroyTimer_0002 failed to destroy timer:' + err);
659 660
        expect().assertTrue();
        done();
Z
zwx1016320 已提交
661 662
      });
      console.info('====>SUB_time_systemTimer_destroyTimer_0002 end.');
663 664 665
    });

    /**
Z
zwx1016320 已提交
666 667 668 669 670 671 672
     * @tc.number SUB_time_systemTimer_ALL_Promise_0008
     * @tc.name SUB_time_systemTimer_ALL_Promise_0008
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_WAKEUP, repeat = false (Promise)
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 0
     */
673
    it('SUB_time_systemTimer_ALL_Promise_0008', 0, async function (done) {
674
      console.info('====>SUB_time_systemTimer_ALL_Promise_0008 start.');
675 676 677 678 679
      let options = {
        type: systemTimer.TIMER_TYPE_WAKEUP,
        repeat: false
      };
      try {
680
        console.info('====>SUB_time_systemTimer_ALL_Promise_0008 create timer.');
681
        systemTimer.createTimer(options)
Z
zwx1016320 已提交
682
          .then((timerID) => {
683
            console.info('====>SUB_time_systemTimer_ALL_Promise_0008 timerID:' + timerID);
684
            try {
Z
zwx1016320 已提交
685
              expect(Number.isInteger(timerID)).assertTrue();
686 687
              let triggerTime = new Date().getTime() + interval_time * 1.2;
              systemTimer.startTimer(timerID, triggerTime)
Z
zwx1016320 已提交
688
                .then(() => {
689
                  console.info('====>SUB_time_systemTimer_ALL_Promise_0008 start timerID: ' + timerID);
690 691
                  try {
                    systemTimer.stopTimer(timerID)
Z
zwx1016320 已提交
692
                      .then(() => {
693
                        systemTimer.destroyTimer(timerID, async (err, data) => {
694
                          console.info('====>SUB_time_systemTimer_ALL_Promise_0008 destroyTimer: ' + timerID);
695 696 697
                          done();
                        });
                      })
Z
zwx1016320 已提交
698
                      .catch(() => {
699
                        // 捕获stopTimer业务逻辑错误
700
                        console.info('====>SUB_time_systemTimer_ALL_Promise_0008 failed to stop timer.');
701 702 703 704 705
                        expect().assertTrue();
                        done();
                      })
                  } catch (err) {
                    // 捕获stopTimer参数错误
706
                    console.info('====>SUB_time_systemTimer_ALL_Promise_0008 stopTimer with wrong arg: ' + err);
707 708 709 710
                    expect().assertTrue();
                    done();
                  }
                })
Z
zwx1016320 已提交
711
                .catch(() => {
712
                  // 捕获startTimer业务逻辑错误
713
                  console.info('====>SUB_time_systemTimer_ALL_Promise_0008 failed to stop timer.');
714 715 716 717 718
                  expect().assertTrue();
                  done();
                });
            } catch (err) {
              // 捕获参数错误
719
              console.info('====>SUB_time_systemTimer_ALL_Promise_0008 startTimer with wrong arg: ' + err);
720 721 722 723
              expect().assertTrue();
              done();
            }
          })
Z
zwx1016320 已提交
724
          .catch(() => {
725
            // 捕获业务逻辑错误
726
            console.info('====>SUB_time_systemTimer_ALL_Promise_0008 failed to create timer.');
727 728 729 730 731
            expect().assertTrue();
            done();
          });
      } catch (err) {
        // 捕获参数错误
732
        console.info('====>SUB_time_systemTimer_ALL_Promise_0008 createTimer with wrong arg: ' + err);
733 734 735 736 737 738 739 740
        expect().assertTrue();
        done();
      }
    });

    /**
     * @tc.number SUB_time_systemTimer_ALL_Callback_0009
     * @tc.name SUB_time_systemTimer_ALL_Callback_0009
741
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_WAKEUP, repeat = false (Promise)
742 743 744 745 746
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 0
     */
    it('SUB_time_systemTimer_ALL_Callback_0009', 0, async function (done) {
747
      console.info('====>SUB_time_systemTimer_ALL_Callback_0009 start.');
748 749 750 751 752
      let options = {
        type: systemTimer.TIMER_TYPE_WAKEUP,
        repeat: false
      };
      try {
753
        console.info('====>SUB_time_systemTimer_ALL_Callback_0009 create timer.');
754
        systemTimer.createTimer(options)
Z
zwx1016320 已提交
755
          .then((timerID) => {
756
            console.info('====>SUB_time_systemTimer_ALL_Callback_0009 timerID:' + timerID);
757
            try {
Z
zwx1016320 已提交
758
              expect(Number.isInteger(timerID)).assertTrue();
759
              let triggerTime = new Date().getTime() + interval_time * 1.2;
Z
zwx1016320 已提交
760
              systemTimer.startTimer(timerID, triggerTime, () => {
761
                console.info('====>SUB_time_systemTimer_ALL_Callback_0009 start timerID: ' + timerID);
762
                try {
Z
zwx1016320 已提交
763
                  systemTimer.stopTimer(timerID, () => {
764
                    systemTimer.destroyTimer(timerID, function (err, data) {
765
                      console.info('====>SUB_time_systemTimer_ALL_Callback_0009 destroyTimer: ' + timerID);
766 767 768 769
                      done();
                    });
                  })
                } catch (err) {
770
                  console.info('====>SUB_time_systemTimer_ALL_Callback_0009 stopTimer with wrong arg: ' + err);
771 772 773 774 775
                  expect().assertTrue();
                  done();
                }
              })
            } catch (err) {
776
              console.info('====>SUB_time_systemTimer_ALL_Callback_0009 startTimer with wrong arg: ' + err);
777 778 779 780 781
              expect().assertTrue();
              done();
            }
          })
      } catch (err) {
782
        console.info('====>SUB_time_systemTimer_ALL_Callback_0009 createTimer with wrong arg: ' + err);
783 784
        expect().assertTrue();
        done();
Z
zwx1016320 已提交
785
      };
786 787 788
    });
  });
}