systemTimer.test.ets 29.5 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 94 95
      console.info('====>SUB_time_systemTimer_createTimer_0000 create timer.');
      systemTimer.createTimer(options, function (err, timerID) {
        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 103
          expect(Number.isInteger(timerID)).assertTrue();
          done();
Z
zwx1016320 已提交
104 105 106 107 108 109
        } catch (error) {
          console.info('====>SUB_time_systemTimer_createTimer_0000 catch err ' + error);
          done();
        };
      });
      console.info('====>SUB_time_systemTimer_createTimer_0000 end.');
110 111 112 113 114
    });

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

    /**
     * @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) {
154
      console.info("====>SUB_time_systemTimer_createTimer_0002 start");
Z
zwx1016320 已提交
155
      WantAgent.getBundleName(wantAgent, (err, data) => {
156
        console.info('====>SUB_time_systemTimer_createTimer_0002 BundleName: ' + data);
157 158 159 160 161 162
      })
      let options = {
        type: systemTimer.TIMER_TYPE_WAKEUP,
        repeat: true,
        wantAgent: wantAgent,
        interval: interval_time
163
      };
Z
zwx1016320 已提交
164 165 166
      console.info('====>SUB_time_systemTimer_createTimer_0002 create timer.');
      systemTimer.createTimer(options, function (err, timerID) {
        try {
167
          if (err) {
Z
zwx1016320 已提交
168
            console.info('====>SUB_time_systemTimer_createTimer_0002 create fail: ' + err);
169 170 171
            expect().assertTrue();
            done();
          }
172
          console.info('====>SUB_time_systemTimer_createTimer_0002 timerID: ' + timerID);
173 174
          expect(Number.isInteger(timerID)).assertTrue();
          done();
Z
zwx1016320 已提交
175 176 177 178 179 180
        } catch (error) {
          console.info('====>SUB_time_systemTimer_createTimer_0002 catch err ' + error);
          done();
        };
      });
      console.info('====>SUB_time_systemTimer_createTimer_0002 end.');
181 182 183 184 185 186 187 188 189 190 191
    });

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

    /**
     * @tc.number SUB_time_systemTimer_createTimer_0004
     * @tc.name SUB_time_systemTimer_createTimer_0004
219
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_REALTIME, repeat = false, wantAgent(callback)
220 221 222 223 224
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
    it('SUB_time_systemTimer_createTimer_0004', 2, async function (done) {
225
      console.info("====>SUB_time_systemTimer_createTimer_0004 start");
Z
zwx1016320 已提交
226
      WantAgent.getBundleName(wantAgent, (err, data) => {
227
        console.info("====>SUB_time_systemTimer_createTimer_0004 BundleName: " + data);
228
      });
229 230 231 232 233
      let options = {
        type: systemTimer.TIMER_TYPE_REALTIME,
        repeat: true,
        wantAgent: wantAgent,
        interval: interval_time
234
      };
Z
zwx1016320 已提交
235 236 237
      console.info('====>SUB_time_systemTimer_createTimer_0004 create timer.');
      systemTimer.createTimer(options, function (err, timerID) {
        try {
238
          if (err) {
Z
zwx1016320 已提交
239
            console.info('====>SUB_time_systemTimer_createTimer_0004 create fail: ' + err);
240 241
            expect().assertTrue();
            done();
Z
zwx1016320 已提交
242 243
          }
          console.info('====>SUB_time_systemTimer_createTimer_0004 timerID: ' + timerID);
244 245
          expect(Number.isInteger(timerID)).assertTrue();
          done();
Z
zwx1016320 已提交
246 247 248 249 250 251
        } catch (error) {
          console.info('====>SUB_time_systemTimer_createTimer_0004 catch err ' + error);
          done();
        };
      });
      console.info('====>SUB_time_systemTimer_createTimer_0004 end.');
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
      let options = {
        type: systemTimer.TIMER_TYPE_REALTIME,
        repeat: false
      };
Z
zwx1016320 已提交
268 269 270 271 272 273
      await systemTimer.createTimer(options).then((timerID) => {
        console.info('====>SUB_time_systemTimer_createTimer_0005 timerID: ' + timerID);
        expect(Number.isInteger(timerID)).assertTrue();
        done();
      }).catch(err => {
        console.info('====>SUB_time_systemTimer_createTimer_0005 createTimer fail: ' + err);
274 275
        expect().assertTrue();
        done();
Z
zwx1016320 已提交
276 277
      });
      console.info('====>SUB_time_systemTimer_createTimer_0005 end.');
278 279 280 281 282
    });

    /**
     * @tc.number SUB_time_systemTimer_createTimer_0006
     * @tc.name SUB_time_systemTimer_createTimer_0006
283
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_IDLE, repeat = true (callback)
284 285 286 287 288
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 0
     */
    it('SUB_time_systemTimer_createTimer_0006', 0, async function (done) {
289
      console.info('====>SUB_time_systemTimer_createTimer_0006 start.');
290
      let options = {
291
        type: systemTimer.TIMER_TYPE_IDLE,
292
        repeat: false
293
      };
Z
zwx1016320 已提交
294 295 296 297 298 299
      await systemTimer.createTimer(options).then((timerID) => {
        console.info('====>SUB_time_systemTimer_createTimer_0006 timerID: ' + timerID);
        expect(Number.isInteger(timerID)).assertTrue();
        done();
      }).catch(err => {
        console.info('====>SUB_time_systemTimer_createTimer_0006 createTimer fail: ' + err);
300 301
        expect().assertTrue();
        done();
Z
zwx1016320 已提交
302 303
      });
      console.info('====>SUB_time_systemTimer_createTimer_0006 end.');
304 305 306 307 308 309 310 311 312 313 314
    });

    /**
     * @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) {
315
      console.info("====>SUB_time_systemTimer_createTimer_0007 start");
Z
zwx1016320 已提交
316
      WantAgent.getBundleName(wantAgent, (err, data) => {
317
        console.info('====>SUB_time_systemTimer_createTimer_0007 BundleName: ' + data);
318 319 320 321 322 323
      })
      let options = {
        type: systemTimer.TIMER_TYPE_WAKEUP,
        repeat: true,
        wantAgent: wantAgent,
        interval: interval_time
324
      };
Z
zwx1016320 已提交
325 326 327 328 329 330
      await systemTimer.createTimer(options).then((timerID) => {
        console.info('====>SUB_time_systemTimer_createTimer_0007 timerID: ' + timerID);
        expect(Number.isInteger(timerID)).assertTrue();
        done();
      }).catch(err => {
        console.info('====>SUB_time_systemTimer_createTimer_0007 createTimer fail: ' + err);
331 332
        expect().assertTrue();
        done();
Z
zwx1016320 已提交
333 334
      });
      console.info('====>SUB_time_systemTimer_createTimer_0007 end.');
335 336 337 338 339 340 341 342 343 344 345
    });

    /**
     * @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) {
346
      console.info("====>SUB_time_systemTimer_createTimer_0008 start");
347 348 349
      let options = {
        type: systemTimer.TIMER_TYPE_EXACT,
        repeat: false
350
      };
Z
zwx1016320 已提交
351 352 353 354 355 356
      await systemTimer.createTimer(options).then((timerID) => {
        console.info('====>SUB_time_systemTimer_createTimer_0008 timerID: ' + timerID);
        expect(Number.isInteger(timerID)).assertTrue();
        done();
      }).catch(err => {
        console.info('====>SUB_time_systemTimer_createTimer_0008 createTimer fail: ' + err);
357 358
        expect().assertTrue();
        done();
Z
zwx1016320 已提交
359 360
      });
      console.info('====>SUB_time_systemTimer_createTimer_0008 end.');
361 362 363 364 365
    });

    /**
     * @tc.number SUB_time_systemTimer_createTimer_0009
     * @tc.name SUB_time_systemTimer_createTimer_0009
366
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_REALTIME, repeat = false, wantAgent(callback)
367 368 369 370 371
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 2
     */
    it('SUB_time_systemTimer_createTimer_0009', 2, async function (done) {
372
      console.info("====>SUB_time_systemTimer_createTimer_0009 start");
Z
zwx1016320 已提交
373
      WantAgent.getBundleName(wantAgent, (err, data) => {
374
        console.info("====>SUB_time_systemTimer_createTimer_0009 BundleName: " + data);
375
      });
376 377 378 379 380
      let options = {
        type: systemTimer.TIMER_TYPE_REALTIME,
        repeat: true,
        wantAgent: wantAgent,
        interval: interval_time
381
      };
Z
zwx1016320 已提交
382 383 384 385 386 387
      await systemTimer.createTimer(options).then((timerID) => {
        console.info('====>SUB_time_systemTimer_createTimer_0009 timerID: ' + timerID);
        expect(Number.isInteger(timerID)).assertTrue();
        done();
      }).catch(err => {
        console.info('====>SUB_time_systemTimer_createTimer_0009 createTimer fail: ' + err);
388 389
        expect().assertTrue();
        done();
Z
zwx1016320 已提交
390 391
      });
      console.info('====>SUB_time_systemTimer_createTimer_0009 end.');
392 393 394 395 396 397 398 399 400 401 402
    });

    /**
     * @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) {
403
      console.info("====>SUB_time_systemTimer_startTimer_0001 start");
Z
zwx1016320 已提交
404 405 406 407 408 409 410 411 412 413 414 415 416 417
      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);
      });
      systemTimer.startTimer(globalTimerID, triggerTime, function (err, data) {
        try {
418
          if (err) {
419
            console.info('====>SUB_time_systemTimer_startTimer_0001 wrong since ' + err.code);
420 421 422
            expect().assertTrue();
            done();
          }
423
          console.info("====>SUB_time_systemTimer_startTimer_0001 success to start timerID: " + globalTimerID);
Z
zwx1016320 已提交
424
          expect(true).assertTrue();
425
          done();
Z
zwx1016320 已提交
426 427 428 429 430 431
        } catch (e) {
          console.info('====>SUB_time_systemTimer_startTimer_0001 has failed for ' + e);
          done();
        };
      });
      console.info("====>SUB_time_systemTimer_startTimer_0001 end");
432 433 434 435 436 437 438 439 440 441 442
    });

    /**
     * @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) {
443
      console.info("====>SUB_time_systemTimer_stopTimer_0001 start");
Z
zwx1016320 已提交
444 445 446 447 448 449 450 451 452 453 454 455 456
      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);
      });
      systemTimer.stopTimer(globalTimerID, function (err, data) {
        try {
457
          if (err) {
Z
zwx1016320 已提交
458
            console.info("====>SUB_time_systemTimer_stopTimer_0001 stop fail timerID: " + globalTimerID);
459 460
            expect().assertTrue();
            done();
461
          };
462
          console.info("====>SUB_time_systemTimer_stopTimer_0001 success to stop timerID: " + globalTimerID);
Z
zwx1016320 已提交
463
          expect(true).assertTrue();
464
          done();
Z
zwx1016320 已提交
465 466 467 468 469 470
        } catch (e) {
          console.info('====>SUB_time_systemTimer_stopTimer_0001 has failed for ' + e);
          done();
        };
      });
      console.info("====>SUB_time_systemTimer_stopTimer_0001 end");
471 472 473 474 475 476 477 478 479 480 481
    });

    /**
     * @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) {
482
      console.info("====>SUB_time_systemTimer_destroyTimer_0001 start");
Z
zwx1016320 已提交
483 484 485 486 487 488 489 490 491 492 493 494 495
      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 {
496
          if (err) {
Z
zwx1016320 已提交
497
            console.info("====>SUB_time_systemTimer_destroyTimer_0001 destroy timer, timerID: " + globalTimerID)
498 499
            expect().assertTrue();
            done();
500
          };
501
          console.info("====>SUB_time_systemTimer_destroyTimer_0001 success to destroy timerID: " + globalTimerID);
Z
zwx1016320 已提交
502
          expect(true).assertTrue();
503
          done();
Z
zwx1016320 已提交
504 505 506 507 508 509
        } catch (e) {
          console.info('====>SUB_time_systemTimer_destroyTimer_0001 has failed for ' + e);
          done();
        };
      });
      console.info("====>SUB_time_systemTimer_destroyTimer_0001 end");
510 511 512
    });

    /**
Z
zwx1016320 已提交
513 514
     * @tc.number SUB_time_systemTimer_createTimerPromise_0001
     * @tc.name SUB_time_systemTimer_createTimerPromise_0001
515 516 517 518 519
     * @tc.desc Test createTimer() interfaces, type = TIMER_TYPE_REALTIME, repeat = false (Promise)
     * @tc.size MEDIUM
     * @tc.type Function
     * @tc.level Level 0
     */
Z
zwx1016320 已提交
520 521
    it('SUB_time_systemTimer_createTimerPromise_0001', 0, async function (done) {
      console.info('====>SUB_time_systemTimer_createTimerPromise_0001 start.');
522 523 524 525
      let options = {
        type: systemTimer.TIMER_TYPE_REALTIME,
        repeat: false
      };
Z
zwx1016320 已提交
526 527 528 529 530 531 532
      console.info('====>SUB_time_systemTimer_createTimerPromise_0001 create timer.');
      await systemTimer.createTimer(options).then((timerID) => {
        console.info('====>SUB_time_systemTimer_createTimerPromise_0001 timerID:' + timerID);
        expect(Number.isInteger(timerID)).assertTrue();
        done();
      }).catch(error => {
        console.info('====>SUB_time_systemTimer_createTimerPromise_0001 failed to create timer: ' + error);
533 534
        expect().assertTrue();
        done();
Z
zwx1016320 已提交
535
      });
536 537 538 539 540 541 542 543 544 545 546
    });

    /**
     * @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) {
547
      console.info('====>SUB_time_systemTimer_startTimer_0002 start.');
Z
zwx1016320 已提交
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
      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();
        done();
      }).catch((err) => {
        console.info('====>SUB_time_systemTimer_startTimer_0002 failed to start timer: ' + err);
566 567
        expect().assertTrue();
        done();
Z
zwx1016320 已提交
568 569
      });
      console.info('====>SUB_time_systemTimer_startTimer_0002 end.');
570 571 572 573 574 575 576 577 578 579 580
    });

    /**
     * @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) {
581
      console.info('====>SUB_time_systemTimer_stopTimer_0002 start.');
Z
zwx1016320 已提交
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
      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();
        done();
      }).catch((err) => {
        console.info('====>SUB_time_systemTimer_stopTimer_0002 failed to stop timer:' + err);
599 600
        expect().assertTrue();
        done();
Z
zwx1016320 已提交
601 602
      });
      console.info('====>SUB_time_systemTimer_stopTimer_0002 end.');
603 604 605 606 607 608 609 610 611 612 613
    });

    /**
     * @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) {
614
      console.info('====>SUB_time_systemTimer_destroyTimer_0002 start.');
Z
zwx1016320 已提交
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631
      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);
632 633
        expect().assertTrue();
        done();
Z
zwx1016320 已提交
634 635
      });
      console.info('====>SUB_time_systemTimer_destroyTimer_0002 end.');
636 637 638
    });

    /**
Z
zwx1016320 已提交
639 640 641 642 643 644 645
     * @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
     */
646
    it('SUB_time_systemTimer_ALL_Promise_0008', 0, async function (done) {
647
      console.info('====>SUB_time_systemTimer_ALL_Promise_0008 start.');
648 649 650 651 652
      let options = {
        type: systemTimer.TIMER_TYPE_WAKEUP,
        repeat: false
      };
      try {
653
        console.info('====>SUB_time_systemTimer_ALL_Promise_0008 create timer.');
654
        systemTimer.createTimer(options)
Z
zwx1016320 已提交
655
          .then((timerID) => {
656
            console.info('====>SUB_time_systemTimer_ALL_Promise_0008 timerID:' + timerID);
657
            try {
Z
zwx1016320 已提交
658
              expect(Number.isInteger(timerID)).assertTrue();
659 660
              let triggerTime = new Date().getTime() + interval_time * 1.2;
              systemTimer.startTimer(timerID, triggerTime)
Z
zwx1016320 已提交
661
                .then(() => {
662
                  console.info('====>SUB_time_systemTimer_ALL_Promise_0008 start timerID: ' + timerID);
663 664
                  try {
                    systemTimer.stopTimer(timerID)
Z
zwx1016320 已提交
665
                      .then(() => {
666
                        systemTimer.destroyTimer(timerID, function (err, data) {
667
                          console.info('====>SUB_time_systemTimer_ALL_Promise_0008 destroyTimer: ' + timerID);
668 669 670
                          done();
                        });
                      })
Z
zwx1016320 已提交
671
                      .catch(() => {
672
                        // 捕获stopTimer业务逻辑错误
673
                        console.info('====>SUB_time_systemTimer_ALL_Promise_0008 failed to stop timer.');
674 675 676 677 678
                        expect().assertTrue();
                        done();
                      })
                  } catch (err) {
                    // 捕获stopTimer参数错误
679
                    console.info('====>SUB_time_systemTimer_ALL_Promise_0008 stopTimer with wrong arg: ' + err);
680 681 682 683
                    expect().assertTrue();
                    done();
                  }
                })
Z
zwx1016320 已提交
684
                .catch(() => {
685
                  // 捕获startTimer业务逻辑错误
686
                  console.info('====>SUB_time_systemTimer_ALL_Promise_0008 failed to stop timer.');
687 688 689 690 691
                  expect().assertTrue();
                  done();
                });
            } catch (err) {
              // 捕获参数错误
692
              console.info('====>SUB_time_systemTimer_ALL_Promise_0008 startTimer with wrong arg: ' + err);
693 694 695 696
              expect().assertTrue();
              done();
            }
          })
Z
zwx1016320 已提交
697
          .catch(() => {
698
            // 捕获业务逻辑错误
699
            console.info('====>SUB_time_systemTimer_ALL_Promise_0008 failed to create timer.');
700 701 702 703 704
            expect().assertTrue();
            done();
          });
      } catch (err) {
        // 捕获参数错误
705
        console.info('====>SUB_time_systemTimer_ALL_Promise_0008 createTimer with wrong arg: ' + err);
706 707 708 709 710 711 712 713
        expect().assertTrue();
        done();
      }
    });

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