diff --git a/time/timeTest/entry/src/main/ets/test/systemTimeTest.ets b/time/timeTest/entry/src/main/ets/test/systemTimeTest.ets index 47ac6f8f603534cbd972c83f2d6d4bc11ee76daa..91a674722003c5a82128df80b80f011a51267996 100644 --- a/time/timeTest/entry/src/main/ets/test/systemTimeTest.ets +++ b/time/timeTest/entry/src/main/ets/test/systemTimeTest.ets @@ -20,6 +20,38 @@ import systemTime from "@ohos.systemTime"; export default function systemTimeJsunit() { describe('systemTimeTest', function () { console.info('====>---------------systemTimeTest start-----------------------'); + /** + * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. + */ + + var dates; + var zone; + beforeEach(async function (done) { + let currentTime = new Date().getTime() + dates = currentTime + console.info("====>beforeEach data " + dates); + + systemTime.getTimezone().then( data => { + console.info("====>beforeEach data " + data); + zone = data + done() + }).catch(error => { + console.info("====>beforeEach error " + error); + }); + }); + + /** + * afterEach: Test case-level clearance conditions, which are executed after each test case is executed. + */ + afterEach(async function (done) { + systemTime.setTimezone(zone).then( data => { + console.info("====>afterEach zone " + zone); + done() + }).catch(error => { + console.info("====>afterEach error " + error); + }); + }); + /** * @tc.number SUB_systemTime_getCurrentTime_JS_API_0001 * @tc.name Test systemTime.getCurrentTime @@ -29,352 +61,532 @@ export default function systemTimeJsunit() { * @tc.level : Level 1 */ it("SUB_systemTime_getCurrentTime_JS_API_0001", 0, async function (done) { - console.info("====>----------UB_systemTime_getCurrentTime_JS_API_0001 start----------------"); - systemTime.getCurrentTime(true, (error, data) => { - if (error) { - console.error('failed to systemTime.getCurrentTime because ' + JSON.stringify(error)); - expect().assertFail(); - }; - console.info('====>SystemTime.getCurrentTime success data : ' + JSON.stringify(data)); - expect(data != null).assertEqual(true); - console.info("====>----------SUB_systemTime_getRealActiveTime_JS_API_0100 end-----------------"); + console.info("====>----------UB_systemTime_getCurrentTime_JS_API_0001 start----------------"); + systemTime.getCurrentTime(true, (error, data) => { + try { + if (error) { + console.error('====>UB_systemTime_getCurrentTime_JS_API_0001 fail: ' + JSON.stringify(error)); + expect().assertFail(); done(); - }); + }; + console.info('====>SystemTime.getCurrentTime success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + } catch (error) { + console.error('====>UB_systemTime_getCurrentTime_JS_API_0001 catch error: ' + JSON.stringify(error)); + done(); + } + console.info("====>----------SUB_systemTime_getRealActiveTime_JS_API_0100 end-----------------"); + }); }); /** - * @tc.number SUB_systemTime_getCurrentTime_JS_API_0002 - * @tc.name Test systemTime.getCurrentTime - * @tc.desc Obtains the number of milliseconds that have elapsed since the Unix epoch. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 1 - */ + * @tc.number SUB_systemTime_getCurrentTime_JS_API_0002 + * @tc.name Test systemTime.getCurrentTime + * @tc.desc Obtains the number of milliseconds that have elapsed since the Unix epoch. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ it("SUB_systemTime_getCurrentTime_JS_API_0002", 0, async function (done) { - console.info("====>-----SUB_systemTime_getCurrentTime_JS_API_0002 start----------------"); - systemTime.getCurrentTime(true).then((data) => { - console.info('====>SUB_systemTime_getCurrentTime_JS_API_0002 data : ' + JSON.stringify(data)); - expect(data != null).assertEqual(true); - console.info("====>-----SUB_systemTime_getCurrentTime_JS_API_0002 end------------"); - done(); - }).catch(err => { - console.error('SUB_systemTime_getCurrentTime_JS_API_0002 err: ' + JSON.stringify(error)); - expect().assertFail() - done(); - }); + console.info("====>-----SUB_systemTime_getCurrentTime_JS_API_0002 start----------------"); + await systemTime.getCurrentTime(false).then((data) => { + console.info('====>SUB_systemTime_getCurrentTime_JS_API_0002 success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + }).catch(err => { + console.error('====>SUB_systemTime_getCurrentTime_JS_API_0002 fail: ' + JSON.stringify(err)); + expect().assertFail() + done(); + }); + console.info("====>-----SUB_systemTime_getCurrentTime_JS_API_0002 end------------"); }); /** - * @tc.number SUB_systemTime_getRealActiveTime_JS_API_0001 - * @tc.name Test systemTime.getCurrentTime - * @tc.desc Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 1 - */ + * @tc.number SUB_systemTime_getRealActiveTime_JS_API_0001 + * @tc.name Test systemTime.getCurrentTime + * @tc.desc Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ it("SUB_systemTime_getRealActiveTime_JS_API_0001", 0, async function (done) { - console.info("====>----------SUB_systemTime_getRealActiveTime_JS_API_0001 start----------------"); - systemTime.getRealActiveTime(true, (error, data) => { - if (error) { - console.error('SUB_systemTime_getRealActiveTime_JS_API_0001 err: ' + JSON.stringify(error)); - expect().assertFail() - }; - console.info('====>SUB_systemTime_getRealActiveTime_JS_API_0001 data : ' + JSON.stringify(data)); - expect(data != null).assertEqual(true); - console.info("====>----------SUB_systemTime_getRealActiveTime_JS_API_0001 end-----------------"); + console.info("====>----------SUB_systemTime_getRealActiveTime_JS_API_0001 start----------------"); + systemTime.getRealActiveTime(true, (error, data) => { + try { + if (error) { + console.error('====>SUB_systemTime_getRealActiveTime_JS_API_0001 fail: ' + JSON.stringify(error)); + expect().assertFail() done(); - }); + }; + console.info('====>SUB_systemTime_getRealActiveTime_JS_API_0001 success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + } catch (error) { + console.error('====>SUB_systemTime_getRealActiveTime_JS_API_0001 catch err: ' + JSON.stringify(error)); + done(); + } + console.info("====>----------SUB_systemTime_getRealActiveTime_JS_API_0001 end-----------------"); + }); }); /** - * @tc.number SUB_systemTime_getRealActiveTime_JS_API_0002 - * @tc.name Test systemTime.getCurrentTime - * @tc.desc Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 1 - */ + * @tc.number SUB_systemTime_getRealActiveTime_JS_API_0002 + * @tc.name Test systemTime.getCurrentTime + * @tc.desc Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ it("SUB_systemTime_getRealActiveTime_JS_API_0002", 0, async function (done) { - console.info("====>-----SUB_systemTime_getRealActiveTime_JS_API_0002 start----------------"); - systemTime.getRealActiveTime(true).then((data) => { - console.log('SUB_systemTime_getRealActiveTime_JS_API_0002 data : ' + JSON.stringify(data)); - expect(data != null).assertEqual(true); - console.info("====>-----SUB_systemTime_getRealActiveTime_JS_API_0002 end------------"); - done(); - }).catch(err => { - console.error('SUB_systemTime_getRealActiveTime_JS_API_0002 err: ' + JSON.stringify(error)); - expect().assertFail() - done(); - }); + console.info("====>-----SUB_systemTime_getRealActiveTime_JS_API_0002 start----------------"); + await systemTime.getRealActiveTime(false).then((data) => { + console.log('SUB_systemTime_getRealActiveTime_JS_API_0002 success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + }).catch(err => { + console.error('====>SUB_systemTime_getRealActiveTime_JS_API_0002 err: ' + JSON.stringify(err)); + expect().assertFail() + done(); + }); + console.info("====>-----SUB_systemTime_getRealActiveTime_JS_API_0002 end------------"); }); /** - * @tc.number SUB_systemTime_getRealTime_JS_API_0001 - * @tc.name Test systemTime.getCurrentTime - * @tc.desc Obtains the number of milliseconds elapsed since the system was booted, including deep sleep time. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 1 - */ + * @tc.number SUB_systemTime_getRealTime_JS_API_0001 + * @tc.name Test systemTime.getCurrentTime + * @tc.desc Obtains the number of milliseconds elapsed since the system was booted, including deep sleep time. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ it("SUB_systemTime_getRealTime_JS_API_0001", 0, async function (done) { - console.info("====>----------SUB_systemTime_getRealTime_JS_API_0001 start----------------"); - systemTime.getRealTime(true, (error, data) => { - if (error) { - console.error('SUB_systemTime_getRealTime_JS_API_0001 err: ' + JSON.stringify(error)); - expect().assertFail() - }; - console.info('====>SUB_systemTime_getRealTime_JS_API_0001 data : ' + JSON.stringify(data)); - expect(data != null).assertEqual(true); - console.info("====>----------SUB_systemTime_getRealTime_JS_API_0001 end-----------------"); + console.info("====>----------SUB_systemTime_getRealTime_JS_API_0001 start----------------"); + systemTime.getRealTime(true, (error, data) => { + try { + if (error) { + console.error('SUB_systemTime_getRealTime_JS_API_0001 fail: ' + JSON.stringify(error)); + expect().assertFail(); done(); - }); - + }; + console.info('====>SUB_systemTime_getRealTime_JS_API_0001 success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + } catch (error) { + console.error('====>SUB_systemTime_getRealTime_JS_API_0001 catch err: ' + JSON.stringify(error)); + done(); + } + console.info("====>----------SUB_systemTime_getRealTime_JS_API_0001 end-----------------"); + }); }); /** - * @tc.number SUB_systemTime_getRealTime_JS_API_0002 - * @tc.name Test systemTime.getCurrentTime - * @tc.desc Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 1 - */ + * @tc.number SUB_systemTime_getRealTime_JS_API_0002 + * @tc.name Test systemTime.getCurrentTime + * @tc.desc Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ it("SUB_systemTime_getRealTime_JS_API_0002", 0, async function (done) { - console.info("====>-----SUB_systemTime_getRealTime_JS_API_0002 start----------------"); - systemTime.getRealTime(true).then((data) => { - console.info('====>SUB_systemTime_getRealTime_JS_API_0002 data : ' + JSON.stringify(data)); - expect(data != null).assertEqual(true); - }).catch(err => { - console.error('SUB_systemTime_getRealTime_JS_API_0002 err: ' + JSON.stringify(error)); - expect().assertFail(); - }); - console.info("====>-----SUB_systemTime_getRealTime_JS_API_0002 end------------"); + console.info("====>-----SUB_systemTime_getRealTime_JS_API_0002 start----------------"); + await systemTime.getRealTime(false).then((data) => { + console.info('====>SUB_systemTime_getRealTime_JS_API_0002 success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + }).catch(error => { + console.error('====>SUB_systemTime_getRealTime_JS_API_0002 err: ' + JSON.stringify(error)); + expect().assertFail(); done(); + }); + console.info("====>-----SUB_systemTime_getRealTime_JS_API_0002 end------------"); }); /** - * @tc.number SUB_systemTime_setTime_JS_API_0100 - * @tc.name Test systemTime.setTime - * @tc.desc Test systemTime_setTime API functionality. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ + * @tc.number SUB_systemTime_setTime_JS_API_0100 + * @tc.name Test systemTime.setTime + * @tc.desc Test systemTime_setTime API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ it('SUB_systemTime_setTime_JS_API_0100', 0, async function (done) { - console.info("====>SUB_systemTime_setTime_JS_API_0100 start"); - let currentTime = new Date().getTime() + 2000 + console.info("====>SUB_systemTime_setTime_JS_API_0100 start"); + let currentTime = new Date().getTime() + 2000 + systemTime.setTime(currentTime, (err, data) => { try{ - await systemTime.setTime(currentTime) - expect(true).assertTrue(); - done(); - }catch(err){ - console.info("====>SUB_systemTime_setTime_JS_API_0100 error " + err); + if(err){ + console.info("====>SUB_systemTime_setTime_JS_API_0100 setTime fail: " + JSON.stringify(err)); expect().assertFail(); done(); + } + console.info('====>SUB_systemTime_setTime_JS_API_0100 success: ' + data); + expect(true).assertTrue(); + done(); + }catch(err){ + console.info("====>SUB_systemTime_setTime_JS_API_0100 catch error: " + JSON.stringify(err)); + done(); } + }); + console.info("====>SUB_systemTime_setTime_JS_API_0100 end"); }); /** - * @tc.number SUB_systemTime_setTime_JS_API_0200 - * @tc.name Test systemTime.setTime Invalid value - * @tc.desc Test systemTime_setTime API functionality. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ + * @tc.number SUB_systemTime_setTime_JS_API_0200 + * @tc.name Test systemTime.setTime Invalid value + * @tc.desc Test systemTime_setTime API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ it('SUB_systemTime_setTime_JS_API_0200', 0, async function (done) { - console.info("====>SUB_systemTime_setTime_JS_API_0200 start"); - try{ - systemTime.setTime(15222).then(() => { - console.debug('====>SUB_systemTime_setTime_JS_API_0200 setTime fail') - expect().assertFail(); - done(); - }).catch((err)=>{ - console.debug('====>SUB_systemTime_setTime_JS_API_0200 setTime err:' + JSON.stringify(err)) - expect(true).assertTrue(); - console.debug('====>SUB_systemTime_setTime_JS_API_0200 end'); - done(); - }) - }catch(err){ - console.debug('====>SUB_systemTime_setTime_JS_API_0200 setTime throw_err' + JSON.stringify(err)) - expect(err.code).assertEqual('401'); - done(); - } + console.info("====>SUB_systemTime_setTime_JS_API_0200 start"); + try{ + systemTime.setTime(15222).then(() => { + console.debug('====>SUB_systemTime_setTime_JS_API_0200 setTime fail') + expect().assertFail(); + done(); + }).catch((err)=>{ + console.debug('====>SUB_systemTime_setTime_JS_API_0200 setTime err:' + JSON.stringify(err)) + expect(true).assertTrue(); + console.debug('====>SUB_systemTime_setTime_JS_API_0200 end'); + done(); + }) + }catch(err){ + console.debug('====>SUB_systemTime_setTime_JS_API_0200 setTime throw_err' + JSON.stringify(err)) + expect(err.code).assertEqual('401'); + done(); + } }); /** - * @tc.number SUB_systemTime_setTime_JS_API_0300 - * @tc.name Test systemTime.setTime3 - * @tc.desc Test systemTime_setTime API functionality. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ + * @tc.number SUB_systemTime_setTime_JS_API_0300 + * @tc.name Test systemTime.setTime3 + * @tc.desc Test systemTime_setTime API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ it('SUB_systemTime_setTime_JS_API_0300', 0, async function (done) { - console.info("====>SUB_systemTime_setTime_JS_API_0300 start"); - let currentTime = new Date().getTime() + 2000 - systemTime.setTime(currentTime, (err) => { - try{ - expect(true).assertTrue(); - console.info('====>SUB_systemTime_setTime_JS_API_0300 end'); - done(); - }catch(err){ - console.info("====>SUB_systemTime_setTime_JS_API_0300 error: " + err); - expect().assertFail(); - done(); - } - }); + console.info("====>SUB_systemTime_setTime_JS_API_0300 start"); + let currentTime = new Date().getTime() + 2000 + await systemTime.setTime(currentTime).then(() => { + console.info('====>SUB_systemTime_setTime_JS_API_0300 success') + expect(true).assertTrue(); + done(); + }).catch((err)=>{ + console.debug('====>SUB_systemTime_setTime_JS_API_0300 setTime fail:' + JSON.stringify(err)) + expect().assertFail(); + done(); + }) + console.info("====>SUB_systemTime_setTime_JS_API_0300 end"); }); /** - * @tc.number SUB_systemTime_setTime_JS_API_0400 - * @tc.name Test systemTime.setTime4 Invalid value - * @tc.desc Test systemTime_setTime API functionality. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ + * @tc.number SUB_systemTime_setTime_JS_API_0400 + * @tc.name Test systemTime.setTime4 Invalid value + * @tc.desc Test systemTime_setTime API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ it('SUB_systemTime_setTime_JS_API_0400', 0, async function (done) { - console.info("====>SUB_systemTime_setTime_JS_API_0400 start"); - try{ - systemTime.setTime(18, (err, data) => { - console.info("====>SUB_systemTime_setTime_JS_API_0400 data: " + data); - console.info("====>SUB_systemTime_setTime_JS_API_0400 error: " + err); - expect(true).assertTrue(); - console.info('====>SUB_systemTime_setTime_JS_API_0400 end'); - done(); - }) - }catch(err) { - expect().assertFail(); - done(); - }; + console.info("====>SUB_systemTime_setTime_JS_API_0400 start"); + try{ + systemTime.setTime(18, (err, data) => { + console.info("====>SUB_systemTime_setTime_JS_API_0400 data: " + data); + console.info("====>SUB_systemTime_setTime_JS_API_0400 error: " + err); + console.info('====>SUB_systemTime_setTime_JS_API_0400 end'); + expect(true).assertTrue(); + done(); + }) + }catch(err) { + expect().assertFail(); + done(); + }; }); /** - * @tc.number SUB_systemTime_setDate_JS_API_0100 - * @tc.name Test systemTime.setDate Invalid value - * @tc.desc Test systemTime_setDate API functionality. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ + * @tc.number SUB_systemTime_setDate_JS_API_0100 + * @tc.name Test systemTime.setDate Invalid value + * @tc.desc Test systemTime_setDate API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ it('SUB_systemTime_setDate_JS_API_0100', 0, async function (done) { - console.info("====>SUB_systemTime_setDate_JS_API_0100 start"); - var data = new Date("October 13, 2020 11:13:00"); - systemTime.setDate(1).then(data => { - console.info("====>SUB_systemTime_setDate_JS_API_0100 data " + data); - expect().assertFail(); - done(); - }).catch(error => { - console.info("====>SUB_systemTime_setDate_JS_API_0100 error " + error); - expect(true).assertTrue(); - done(); - }); + console.info("====>SUB_systemTime_setDate_JS_API_0100 start"); + let data = new Date("October 13, 2020 11:13:00"); + systemTime.setDate(data).then(data => { + console.info("====>SUB_systemTime_setDate_JS_API_0100 data " + data); + expect().assertFail(); + done(); + }).catch(error => { + console.info("====>SUB_systemTime_setDate_JS_API_0100 error " + error); + expect(true).assertTrue(); + done(); + }); }); /** - * @tc.number SUB_systemTime_setDate_JS_API_0200 - * @tc.name Test systemTime.setDate Invalid value - * @tc.desc Test systemTime_setDate API functionality. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ + * @tc.number SUB_systemTime_setDate_JS_API_0200 + * @tc.name Test systemTime.setDate Invalid value + * @tc.desc Test systemTime_setDate API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ it('SUB_systemTime_setDate_JS_API_0200', 0, async function (done) { - console.info("====>SUB_systemTime_setDate_JS_API_0200 start"); - systemTime.setDate(0).then(data => { - console.info("====>SUB_systemTime_setDate_JS_API_0200 data " + data); + console.info("====>SUB_systemTime_setDate_JS_API_0200 start"); + systemTime.setDate(0).then(data => { + console.info("====>SUB_systemTime_setDate_JS_API_0200 data " + data); + expect().assertFail(); + done(); + }).catch(error => { + console.info("====>SUB_systemTime_setDate_JS_API_0200 error " + error); + expect(true).assertTrue(); + done(); + }); + }); + + /** + * @tc.number SUB_systemTime_setDate_JS_API_0300 + * @tc.name Test systemTime.setDate Invalid value + * @tc.desc Test systemTime_setDate API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_systemTime_setDate_JS_API_0300', 0, async function (done) { + console.info("====>SUB_systemTime_setDate_JS_API_0300 start"); + let data = new Date("October 13, 2020 11:13:00"); + systemTime.setDate(data, (error, data) => { + try { + if(error){ + console.info("====>SUB_systemTime_setDate_JS_API_0300 error " + error); + expect(true).assertTrue(); + done(); + }else{ + console.info("====>SUB_systemTime_setDate_JS_API_0300 data " + data); expect().assertFail(); done(); - }).catch(error => { - console.info("====>SUB_systemTime_setDate_JS_API_0200 error " + error); - expect(true).assertTrue(); + } + } catch (error) { + console.info("====>SUB_systemTime_setDate_JS_API_0300 catch error " + error); + done(); + } + }); + }); + + /** + * @tc.number SUB_systemTime_setDate_JS_API_0400 + * @tc.name Test systemTime.setDate true value + * @tc.desc Test systemTime_setDate API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_systemTime_setDate_JS_API_0400', 0, async function (done) { + console.info("====>SUB_systemTime_setDate_JS_API_0400 start"); + let data = new Date("Tue Oct 13 2020 11:13:00 GMT+0800"); + systemTime.setDate(data, (error, data) => { + try { + if(error){ + console.info("====>SUB_systemTime_setDate_JS_API_0400 setDate fail: " + JSON.stringify(error)); + expect().assertFail(); done(); - }); + } + systemTime.getDate().then(async (data) => { + try { + console.info("====>SUB_systemTime_setDate_JS_API_0400 getDate: " + data); + console.info("====>SUB_systemTime_setDate_JS_API_0400 setTime: " + dates); + console.info("====>SUB_systemTime_setDate_JS_API_0400 getDate: " + JSON.stringify(data).slice(1,17)); + expect(JSON.stringify(data).slice(1,17) == '2020-10-13T03:13').assertTrue(); + await systemTime.setTime(dates + 1000) + done(); + } catch (err) { + console.info("====>SUB_systemTime_setDate_JS_API_0400 catch err: " + err); + done(); + } + }) + } catch (err) { + console.info("====>SUB_systemTime_setDate_JS_API_0400 catch error " + JSON.stringify(err)); + done(); + } + }); }); /** - * @tc.number SUB_systemTime_setDate_JS_API_0300 - * @tc.name Test systemTime.setDate Invalid value - * @tc.desc Test systemTime_setDate API functionality. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_systemTime_setDate_JS_API_0300', 0, async function (done) { - console.info("====>SUB_systemTime_setDate_JS_API_0300 start"); - var data = new Date("October 13, 2020 11:13:00"); - systemTime.setDate(data, (error, data) => { - if(error){ - console.info("====>SUB_systemTime_setDate_JS_API_0300 error " + error); - expect(true).assertTrue(); - done(); - }else{ - console.info("====>SUB_systemTime_setDate_JS_API_0300 data " + data); - expect().assertFail(); - done(); - }; - }); + * @tc.number SUB_systemTime_setDate_JS_API_0500 + * @tc.name Test systemTime.setDate true value + * @tc.desc Test systemTime_setDate API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_systemTime_setDate_JS_API_0500', 0, async function (done) { + console.info("====>SUB_systemTime_setDate_JS_API_0500 start"); + let data = new Date("Tue Oct 13 2020 11:13:00 GMT+0800"); + await systemTime.setDate(data).then( () => { + console.info("====>SUB_systemTime_setDate_JS_API_0500 successful "); + systemTime.getDate().then(async data => { + try { + console.info("====>SUB_systemTime_setDate_JS_API_0500 getDate: " + data); + console.info("====>SUB_systemTime_setDate_JS_API_0500 setTime: " + dates); + console.info("====>SUB_systemTime_setDate_JS_API_0500 getDate: " + JSON.stringify(data).slice(1,17)); + expect(JSON.stringify(data).slice(1,17) == '2020-10-13T03:13').assertTrue(); + await systemTime.setTime(dates + 1000) + done(); + } catch (err) { + console.info("====>SUB_systemTime_setDate_JS_API_0500 catch err: " + err); + done(); + } + }) + }).catch(error => { + console.info("====>SUB_systemTime_setDate_JS_API_0500 setDate fail: " + JSON.stringify(error)); + expect().assertFail(); + done(); + }); }); /** - * @tc.number SUB_systemTime_setTimezone_JS_API_0100 - * @tc.name Test systemTime.setTimezone Invalid value - * @tc.desc Test systemTime_setTimezone API functionality. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ + * @tc.number SUB_systemTime_setTimezone_JS_API_0100 + * @tc.name Test systemTime.setTimezone Invalid value + * @tc.desc Test systemTime_setTimezone API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ it('SUB_systemTime_setTimezone_JS_API_0100', 0, async function (done) { - console.info("====>SUB_systemTime_setTimezone_JS_API_0100 start"); - systemTime.setTimezone('Asia, Shanghai').then(data => { - console.info("====>SUB_systemTime_setTimezone_JS_API_0100 data " + data); - expect().assertFail(); - }).catch(error => { - console.info("====>SUB_systemTime_setTimezone_JS_API_0100 error " + error); - expect(true).assertTrue(); - done(); - }); + console.info("====>SUB_systemTime_setTimezone_JS_API_0100 start"); + systemTime.setTimezone('Asia, Shanghai').then(data => { + console.info("====>SUB_systemTime_setTimezone_JS_API_0100 data " + data); + expect().assertFail(); + done(); + }).catch(error => { + console.info("====>SUB_systemTime_setTimezone_JS_API_0100 error " + error); + expect(true).assertTrue(); + done(); + }); }); /** - * @tc.number SUB_systemTime_setTimezone_JS_API_0200 - * @tc.name Test systemTime.setTimezone Invalid value - * @tc.desc Test systemTime_setTimezone API functionality. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ + * @tc.number SUB_systemTime_setTimezone_JS_API_0200 + * @tc.name Test systemTime.setTimezone Invalid value + * @tc.desc Test systemTime_setTimezone API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ it('SUB_systemTime_setTimezone_JS_API_0200', 0, async function (done) { - console.info("====>SUB_systemTime_setTimezone_JS_API_0200 start"); - systemTime.setTimezone('Beijing,China').then(data => { - console.info("====>SUB_systemTime_setTimezone_JS_API_0200 data " + data); + console.info("====>SUB_systemTime_setTimezone_JS_API_0200 start"); + systemTime.setTimezone('Beijing,China').then(data => { + console.info("====>SUB_systemTime_setTimezone_JS_API_0200 data " + data); + expect().assertFail(); + done(); + }).catch(error => { + console.info("====>SUB_systemTime_setTimezone_JS_API_0200 error " + error); + expect(true).assertTrue(); + done(); + }); + }); + + /** + * @tc.number SUB_systemTime_setTimezone_JS_API_0300 + * @tc.name Test systemTime.setTimezone Invalid value + * @tc.desc Test systemTime_setTimezone API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_systemTime_setTimezone_JS_API_0300', 0, async function (done) { + console.info("====>SUB_systemTime_setTimezone_JS_API_0300 start"); + systemTime.setTimezone('Baker Island, U.S.A.').then(data => { + console.info("====>SUB_systemTime_setTimezone_JS_API_0300 data " + data); + expect().assertFail(); + done(); + }).catch(error => { + console.info("====>SUB_systemTime_setTimezone_JS_API_0300 error " + error); + expect(true).assertTrue(); + done(); + }); + }); + + /** + * @tc.number SUB_systemTime_setTimezone_JS_API_0400 + * @tc.name Test systemTime.setTimezone true value + * @tc.desc Test systemTime_setTimezone API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_systemTime_setTimezone_JS_API_0400', 0, function (done) { + console.info("====>SUB_systemTime_setTimezone_JS_API_0400 start"); + systemTime.setTimezone('Asia/Jakarta',async (err) => { + try{ + if(err){ + console.info("====>SUB_systemTime_setTimezone_JS_API_0400 setTimezone fail: " + JSON.stringify(err)); expect().assertFail(); - }).catch(error => { - console.info("====>SUB_systemTime_setTimezone_JS_API_0200 error " + error); - expect(true).assertTrue(); done(); - }); + } + console.info("====>SUB_systemTime_setTimezone_JS_API_0400 success "); + systemTime.getTimezone().then( data => { + try { + console.info("====>SUB_systemTime_setTimezone_JS_API_0400 getTimezone " + data); + expect(data == 'Asia/Jakarta').assertTrue(); + done(); + } catch (error) { + console.info("====>SUB_systemTime_setTimezone_JS_API_0400 getTimezone catch error " + error); + done(); + } + }).catch(error => { + console.info("====>SUB_systemTime_setTimezone_JS_API_0400 error " + error); + done(); + }); + }catch(err){ + console.info("====>SUB_systemTime_setTimezone_JS_API_0400 error " + err); + done(); + } + }) }); /** - * @tc.number SUB_systemTime_setTimezone_JS_API_0300 - * @tc.name Test systemTime.setTimezone Invalid value - * @tc.desc Test systemTime_setTimezone API functionality. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - it('SUB_systemTime_setTimezone_JS_API_0300', 0, async function (done) { - console.info("====>SUB_systemTime_setTimezone_JS_API_0300 start"); - systemTime.setTimezone('Baker Island, U.S.A.').then(data => { - console.info("====>SUB_systemTime_setTimezone_JS_API_0300 data " + data); + * @tc.number SUB_systemTime_setTimezone_JS_API_0500 + * @tc.name Test systemTime.setTimezone true value + * @tc.desc Test systemTime_setTimezone API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_systemTime_setTimezone_JS_API_0500', 0, async function (done) { + console.info("====>SUB_systemTime_setTimezone_JS_API_0500 start"); + try{ + await systemTime.setTimezone('Europe/Moscow').then(() => { + console.info("====>SUB_systemTime_setTimezone_JS_API_0500 promise successful " ); + systemTime.getTimezone().then( data => { + try { + console.info("====>SUB_systemTime_setTimezone_JS_API_0500 getTimezone " + data); + expect(data == 'Europe/Moscow').assertTrue(); + done(); + } catch (error) { + console.info("====>SUB_systemTime_setTimezone_JS_API_0500 getTimezone catch error " + error); + done(); + } + }).catch(error => { + console.info("====>SUB_systemTime_setTimezone_JS_API_0500 error " + error); expect().assertFail(); - }).catch(error => { - console.info("====>SUB_systemTime_setTimezone_JS_API_0300 error " + error); - expect(true).assertTrue(); done(); + }); + }).catch(error => { + console.info("====>SUB_systemTime_setTimezone_JS_API_0500 error " + error.code); + expect().assertFail(); + done(); }); + }catch(err){ + console.info("====>SUB_systemTime_setTimezone_JS_API_0500 catch error: " + err.code); + expect().assertFail(); + done(); + }; }); - }) -} + }); +}; diff --git a/time/timeTest/entry/src/main/ets/test/systemTimer.test.ets b/time/timeTest/entry/src/main/ets/test/systemTimer.test.ets index cdd265ac29c23b23cead764d7dc9f59d5f7a923d..db00d91b8bc0b5cc434ab48e2bc9bb88f1d6f3f2 100644 --- a/time/timeTest/entry/src/main/ets/test/systemTimer.test.ets +++ b/time/timeTest/entry/src/main/ets/test/systemTimer.test.ets @@ -31,13 +31,12 @@ export default function systemTimerTest() { abilityName: "MainAbility" } ], - operationType: WantAgent.OperationType.SEND_COMMON_EVENT, + operationType: WantAgent.OperationType.START_SERVICE, requestCode: 0, - wantAgentFlags:[WantAgent.WantAgentFlags.NO_BUILD_FLAG] + wantAgentFlags: [WantAgent.WantAgentFlags.ONE_TIME_FLAG] } let interval_time = 5000; - let globalTimerID = undefined; /** * beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed. @@ -46,8 +45,8 @@ export default function systemTimerTest() { console.info('====>beforeAll: Prerequisites are executed.'); WantAgent.getWantAgent(wantAgentInfo) .then((data) => { - if ( data != undefined || data != null) { - console.info('====>beforeAll: success to get wantAgent: ' + typeof(data)); + if (data != undefined || data != null) { + console.info('====>beforeAll: success to get wantAgent: ' + typeof (data)); wantAgent = data; } }) @@ -91,25 +90,23 @@ export default function systemTimerTest() { type: systemTimer.TIMER_TYPE_REALTIME, repeat: false }; - try { - console.info('====>SUB_time_systemTimer_createTimer_0000 create timer.'); - systemTimer.createTimer(options, function (err, timerID) { + console.info('====>SUB_time_systemTimer_createTimer_0000 create timer.'); + systemTimer.createTimer(options, function (err, timerID) { + try { if (err) { - // 处理业务逻辑错误 + console.info('====>SUB_time_systemTimer_createTimer_0000 create fail: ' + err); expect().assertTrue(); done(); } console.info('====>SUB_time_systemTimer_createTimer_0000 timerID: ' + timerID); - globalTimerID = timerID; expect(Number.isInteger(timerID)).assertTrue(); done(); - }); - } catch (err) { - // 捕获参数错误 - console.info('====>SUB_time_systemTimer_createTimer_0000 has failed for ' + err); - expect().assertTrue(); - done(); - }; + } catch (error) { + console.info('====>SUB_time_systemTimer_createTimer_0000 catch err ' + error); + done(); + }; + }); + console.info('====>SUB_time_systemTimer_createTimer_0000 end.'); }); /** @@ -126,22 +123,23 @@ export default function systemTimerTest() { type: systemTimer.TIMER_TYPE_IDLE, repeat: false }; - try { - systemTimer.createTimer(options, function (err, timerID) { + console.info('====>SUB_time_systemTimer_createTimer_0001 create timer.'); + systemTimer.createTimer(options, function (err, timerID) { + try { if (err) { - console.info('====>SUB_time_systemTimer_createTimer_0001 wrong since ' + err.code); + console.info('====>SUB_time_systemTimer_createTimer_0001 create fail: ' + err); expect().assertTrue(); done(); - }; + } console.info('====>SUB_time_systemTimer_createTimer_0001 timerID: ' + timerID); expect(Number.isInteger(timerID)).assertTrue(); done(); - }); - } catch (e) { - console.info('====>SUB_time_systemTimer_createTimer_0001 arv wrong since ' + e.code); - expect().assertTrue(); - done(); - }; + } catch (error) { + console.info('====>SUB_time_systemTimer_createTimer_0001 catch err ' + error); + done(); + }; + }); + console.info('====>SUB_time_systemTimer_createTimer_0001 end.'); }); /** @@ -154,7 +152,7 @@ export default function systemTimerTest() { */ it('SUB_time_systemTimer_createTimer_0002', 2, async function (done) { console.info("====>SUB_time_systemTimer_createTimer_0002 start"); - WantAgent.getBundleName(wantAgent, (err, data)=>{ + WantAgent.getBundleName(wantAgent, (err, data) => { console.info('====>SUB_time_systemTimer_createTimer_0002 BundleName: ' + data); }) let options = { @@ -163,23 +161,23 @@ export default function systemTimerTest() { wantAgent: wantAgent, interval: interval_time }; - try { - console.info("====>SUB_time_systemTimer_createTimer_0002 create timer") - systemTimer.createTimer(options, function (err, timerID) { + console.info('====>SUB_time_systemTimer_createTimer_0002 create timer.'); + systemTimer.createTimer(options, function (err, timerID) { + try { if (err) { - console.info('====>SUB_time_systemTimer_createTimer_0002 wrong since ' + err.code); + console.info('====>SUB_time_systemTimer_createTimer_0002 create fail: ' + err); expect().assertTrue(); done(); } console.info('====>SUB_time_systemTimer_createTimer_0002 timerID: ' + timerID); expect(Number.isInteger(timerID)).assertTrue(); done(); - }); - } catch (e) { - console.info('====>SUB_time_systemTimer_createTimer_0002 arv wrong since ' + e); - expect().assertTrue(); - done(); - }; + } catch (error) { + console.info('====>SUB_time_systemTimer_createTimer_0002 catch err ' + error); + done(); + }; + }); + console.info('====>SUB_time_systemTimer_createTimer_0002 end.'); }); /** @@ -196,22 +194,23 @@ export default function systemTimerTest() { type: systemTimer.TIMER_TYPE_EXACT, repeat: false }; - try { - console.info("====>SUB_time_systemTimer_createTimer_0003 create timer") - systemTimer.createTimer(options, function (err, timerID) { + console.info('====>SUB_time_systemTimer_createTimer_0003 create timer.'); + systemTimer.createTimer(options, function (err, timerID) { + try { if (err) { - console.info('====>SUB_time_systemTimer_createTimer_0003 wrong since ' + err.code); + console.info('====>SUB_time_systemTimer_createTimer_0003 create fail: ' + err); expect().assertTrue(); done(); } + console.info('====>SUB_time_systemTimer_createTimer_0003 timerID: ' + timerID); expect(Number.isInteger(timerID)).assertTrue(); done(); - }); - } catch (e) { - console.info('====>SUB_time_systemTimer_createTimer_0003 arv wrong since ' + e); - expect().assertTrue(); - done(); - }; + } catch (error) { + console.info('====>SUB_time_systemTimer_createTimer_0003 catch err ' + error); + done(); + }; + }); + console.info('====>SUB_time_systemTimer_createTimer_0003 end.'); }); /** @@ -224,7 +223,7 @@ export default function systemTimerTest() { */ it('SUB_time_systemTimer_createTimer_0004', 2, async function (done) { console.info("====>SUB_time_systemTimer_createTimer_0004 start"); - WantAgent.getBundleName(wantAgent, (err, data)=>{ + WantAgent.getBundleName(wantAgent, (err, data) => { console.info("====>SUB_time_systemTimer_createTimer_0004 BundleName: " + data); }); let options = { @@ -233,24 +232,25 @@ export default function systemTimerTest() { wantAgent: wantAgent, interval: interval_time }; - try { - console.info("====>SUB_time_systemTimer_createTimer_0004 create timer") - systemTimer.createTimer(options, function (err, timerID) { + console.info('====>SUB_time_systemTimer_createTimer_0004 create timer.'); + systemTimer.createTimer(options, function (err, timerID) { + try { if (err) { + console.info('====>SUB_time_systemTimer_createTimer_0004 create fail: ' + err); expect().assertTrue(); done(); - }; + } + console.info('====>SUB_time_systemTimer_createTimer_0004 timerID: ' + timerID); expect(Number.isInteger(timerID)).assertTrue(); done(); - }); - } catch (e) { - console.info('====>SUB_time_systemTimer_createTimer_0004 has failed for ' + e); - expect().assertTrue(); - done(); - }; + } catch (error) { + console.info('====>SUB_time_systemTimer_createTimer_0004 catch err ' + error); + done(); + }; + }); + console.info('====>SUB_time_systemTimer_createTimer_0004 end.'); }); - /** * @tc.number SUB_time_systemTimer_createTimer_0005 * @tc.name SUB_time_systemTimer_createTimer_0005 @@ -265,22 +265,16 @@ export default function systemTimerTest() { type: systemTimer.TIMER_TYPE_REALTIME, repeat: false }; - try { - console.info('====>SUB_time_systemTimer_createTimer_0005 create timer.'); - 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 promise failed ' + err); - expect().assertTrue(); - done(); - }); - } catch (err) { - console.info('====>SUB_time_systemTimer_createTimer_0005 has failed for ' + err); + 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); expect().assertTrue(); done(); - }; + }); + console.info('====>SUB_time_systemTimer_createTimer_0005 end.'); }); /** @@ -297,21 +291,16 @@ export default function systemTimerTest() { type: systemTimer.TIMER_TYPE_IDLE, repeat: false }; - try { - 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 promise failed ' + err); - expect().assertTrue(); - done(); - }); - } catch (e) { - console.info('====>SUB_time_systemTimer_createTimer_0006 arv wrong since ' + e.code); + 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); expect().assertTrue(); done(); - }; + }); + console.info('====>SUB_time_systemTimer_createTimer_0006 end.'); }); /** @@ -324,7 +313,7 @@ export default function systemTimerTest() { */ it('SUB_time_systemTimer_createTimer_0007', 2, async function (done) { console.info("====>SUB_time_systemTimer_createTimer_0007 start"); - WantAgent.getBundleName(wantAgent, (err, data)=>{ + WantAgent.getBundleName(wantAgent, (err, data) => { console.info('====>SUB_time_systemTimer_createTimer_0007 BundleName: ' + data); }) let options = { @@ -333,22 +322,16 @@ export default function systemTimerTest() { wantAgent: wantAgent, interval: interval_time }; - try { - console.info("====>SUB_time_systemTimer_createTimer_0007 create timer"); - 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 promise failed ' + err); - expect().assertTrue(); - done(); - }); - } catch (e) { - console.info('====>SUB_time_systemTimer_createTimer_0007 arv wrong since ' + e); + 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); expect().assertTrue(); done(); - }; + }); + console.info('====>SUB_time_systemTimer_createTimer_0007 end.'); }); /** @@ -365,21 +348,16 @@ export default function systemTimerTest() { type: systemTimer.TIMER_TYPE_EXACT, repeat: false }; - try { - console.info("====>SUB_time_systemTimer_createTimer_0008 create timer") - systemTimer.createTimer(options).then((timerID) => { - expect(Number.isInteger(timerID)).assertTrue(); - done(); - }).catch(err => { - console.info('====>SUB_time_systemTimer_createTimer_0008 promise failed ' + err); - expect().assertTrue(); - done(); - }); - } catch (e) { - console.info('====>SUB_time_systemTimer_createTimer_0008 arv wrong since ' + e); + 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); expect().assertTrue(); done(); - }; + }); + console.info('====>SUB_time_systemTimer_createTimer_0008 end.'); }); /** @@ -392,7 +370,7 @@ export default function systemTimerTest() { */ it('SUB_time_systemTimer_createTimer_0009', 2, async function (done) { console.info("====>SUB_time_systemTimer_createTimer_0009 start"); - WantAgent.getBundleName(wantAgent, (err, data)=>{ + WantAgent.getBundleName(wantAgent, (err, data) => { console.info("====>SUB_time_systemTimer_createTimer_0009 BundleName: " + data); }); let options = { @@ -401,21 +379,16 @@ export default function systemTimerTest() { wantAgent: wantAgent, interval: interval_time }; - try { - console.info("====>SUB_time_systemTimer_createTimer_0009 create timer") - systemTimer.createTimer(options).then((timerID) => { - expect(Number.isInteger(timerID)).assertTrue(); - done(); - }).catch(err => { - console.info('====>SUB_time_systemTimer_createTimer_0009 promise failed ' + err); - expect().assertTrue(); - done(); - }); - } catch (e) { - console.info('====>SUB_time_systemTimer_createTimer_0009 has failed for ' + e); + 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); expect().assertTrue(); done(); - }; + }); + console.info('====>SUB_time_systemTimer_createTimer_0009 end.'); }); /** @@ -428,23 +401,34 @@ export default function systemTimerTest() { */ it('SUB_time_systemTimer_startTimer_0001', 0, async function (done) { console.info("====>SUB_time_systemTimer_startTimer_0001 start"); - try { - console.info("====>SUB_time_systemTimer_startTimer_0001 start timer, timerID: " + globalTimerID) - let triggerTime = new Date().getTime() + interval_time * 1.2; - systemTimer.startTimer(globalTimerID, triggerTime, function (err, data) { + 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 { if (err) { console.info('====>SUB_time_systemTimer_startTimer_0001 wrong since ' + err.code); expect().assertTrue(); done(); } console.info("====>SUB_time_systemTimer_startTimer_0001 success to start timerID: " + globalTimerID); + expect(true).assertTrue(); done(); - }); - } catch (e) { - console.info('====>SUB_time_systemTimer_startTimer_0001 has failed for ' + e); - expect().assertTrue(); - done(); - }; + } catch (e) { + console.info('====>SUB_time_systemTimer_startTimer_0001 has failed for ' + e); + done(); + }; + }); + console.info("====>SUB_time_systemTimer_startTimer_0001 end"); }); /** @@ -457,21 +441,33 @@ export default function systemTimerTest() { */ it('SUB_time_systemTimer_stopTimer_0001', 0, async function (done) { console.info("====>SUB_time_systemTimer_stopTimer_0001 start"); - try { - console.info("====>SUB_time_systemTimer_stopTimer_0001 stop timer, timerID: " + globalTimerID) - systemTimer.stopTimer(globalTimerID, function (err, data) { + 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 { if (err) { + console.info("====>SUB_time_systemTimer_stopTimer_0001 stop fail timerID: " + globalTimerID); expect().assertTrue(); done(); }; console.info("====>SUB_time_systemTimer_stopTimer_0001 success to stop timerID: " + globalTimerID); + expect(true).assertTrue(); done(); - }); - } catch (e) { - console.info('====>SUB_time_systemTimer_stopTimer_0001 has failed for ' + e); - expect().assertTrue(); - done(); - }; + } catch (e) { + console.info('====>SUB_time_systemTimer_stopTimer_0001 has failed for ' + e); + done(); + }; + }); + console.info("====>SUB_time_systemTimer_stopTimer_0001 end"); }); /** @@ -484,21 +480,33 @@ export default function systemTimerTest() { */ it('SUB_time_systemTimer_destroyTimer_0001', 0, async function (done) { console.info("====>SUB_time_systemTimer_destroyTimer_0001 start"); - try { - console.info("====>SUB_time_systemTimer_destroyTimer_0001 destroy timer, timerID: " + globalTimerID) - systemTimer.destroyTimer(globalTimerID, function (err, data) { + 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 { if (err) { + console.info("====>SUB_time_systemTimer_destroyTimer_0001 destroy timer, timerID: " + globalTimerID) expect().assertTrue(); done(); }; console.info("====>SUB_time_systemTimer_destroyTimer_0001 success to destroy timerID: " + globalTimerID); + expect(true).assertTrue(); done(); - }); - } catch (e) { - console.info('====>SUB_time_systemTimer_destroyTimer_0001 has failed for ' + e); - expect().assertTrue(); - done(); - }; + } catch (e) { + console.info('====>SUB_time_systemTimer_destroyTimer_0001 has failed for ' + e); + done(); + }; + }); + console.info("====>SUB_time_systemTimer_destroyTimer_0001 end"); }); /** @@ -515,25 +523,16 @@ export default function systemTimerTest() { type: systemTimer.TIMER_TYPE_REALTIME, repeat: false }; - try { - console.info('====>SUB_time_systemTimer_createTimerPromise_0001 create timer.'); - systemTimer.createTimer(options).then((timerID)=>{ - console.info('====>SUB_time_systemTimer_createTimerPromise_0001 timerID:' + timerID); - expect(Number.isInteger(timerID)).assertTrue(); - globalTimerID = timerID; - done(); - }).catch( error => { - // 捕获业务逻辑错误 - console.info('====>SUB_time_systemTimer_createTimerPromise_0001 failed to create timer.'); - expect().assertTrue(); - done(); - }); - } catch (err) { - // 捕获参数错误 - console.info('====>SUB_time_systemTimer_createTimerPromise_0001 has failed for ' + err); + 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); expect().assertTrue(); done(); - }; + }); }); /** @@ -546,25 +545,28 @@ export default function systemTimerTest() { */ it('SUB_time_systemTimer_startTimer_0002', 0, async function (done) { console.info('====>SUB_time_systemTimer_startTimer_0002 start.'); - try { - console.info('====>SUB_time_systemTimer_startTimer_0002 start timer, timerID: ' + globalTimerID); - let triggerTime = new Date().getTime() + interval_time * 2; - systemTimer.startTimer(globalTimerID, triggerTime) - .then(()=>{ - console.info('====>SUB_time_systemTimer_startTimer_0002 timerID:' + globalTimerID); - done(); - }).catch(()=>{ - // 捕获业务逻辑错误 - console.info('====>SUB_time_systemTimer_startTimer_0002 failed to start timer.'); - expect().assertTrue(); - done(); - }); - } catch (err) { - // 捕获参数错误 - console.info('====>SUB_time_systemTimer_startTimer_0002 has failed for ' + err); + 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); expect().assertTrue(); done(); - } + }); + console.info('====>SUB_time_systemTimer_startTimer_0002 end.'); }); /** @@ -577,24 +579,27 @@ export default function systemTimerTest() { */ it('SUB_time_systemTimer_stopTimer_0002', 0, async function (done) { console.info('====>SUB_time_systemTimer_stopTimer_0002 start.'); - try { - console.info('====>SUB_time_systemTimer_stopTimer_0002 stop timer, timerID: ' + globalTimerID); - systemTimer.stopTimer(globalTimerID) - .then(()=>{ - console.info('====>SUB_time_systemTimer_stopTimer_0002 timerID:' + globalTimerID); - done(); - }).catch(()=>{ - // 捕获业务逻辑错误 - console.info('====>SUB_time_systemTimer_stopTimer_0002 failed to stop timer.'); - expect().assertTrue(); - done(); - }); - } catch (err) { - // 捕获参数错误 - console.info('====>SUB_time_systemTimer_stopTimer_0002 has failed for ' + err); + 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); expect().assertTrue(); done(); - }; + }); + console.info('====>SUB_time_systemTimer_stopTimer_0002 end.'); }); /** @@ -607,34 +612,37 @@ export default function systemTimerTest() { */ it('SUB_time_systemTimer_destroyTimer_0002', 0, async function (done) { console.info('====>SUB_time_systemTimer_destroyTimer_0002 start.'); - try { - console.info('====>SUB_time_systemTimer_destroyTimer_0002 destroy timer, timerID: ' + globalTimerID); - systemTimer.destroyTimer(globalTimerID) - .then(()=>{ - console.info('====>SUB_time_systemTimer_destroyTimer_0002 timerID:' + globalTimerID); - done(); - }).catch(()=>{ - // 捕获业务逻辑错误 - console.info('====>SUB_time_systemTimer_destroyTimer_0002 failed to destroy timer.'); - expect().assertTrue(); - done(); - }); - } catch (err) { - // 捕获参数错误 - console.info('====>SUB_time_systemTimer_stopTimer_0002 has failed for ' + err); + 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); expect().assertTrue(); done(); - }; + }); + console.info('====>SUB_time_systemTimer_destroyTimer_0002 end.'); }); /** - * @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 - */ + * @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 + */ it('SUB_time_systemTimer_ALL_Promise_0008', 0, async function (done) { console.info('====>SUB_time_systemTimer_ALL_Promise_0008 start.'); let options = { @@ -644,23 +652,23 @@ export default function systemTimerTest() { try { console.info('====>SUB_time_systemTimer_ALL_Promise_0008 create timer.'); systemTimer.createTimer(options) - .then((timerID)=>{ + .then((timerID) => { console.info('====>SUB_time_systemTimer_ALL_Promise_0008 timerID:' + timerID); - expect(Number.isInteger(timerID)).assertTrue(); try { + expect(Number.isInteger(timerID)).assertTrue(); let triggerTime = new Date().getTime() + interval_time * 1.2; systemTimer.startTimer(timerID, triggerTime) - .then(()=>{ + .then(() => { console.info('====>SUB_time_systemTimer_ALL_Promise_0008 start timerID: ' + timerID); try { systemTimer.stopTimer(timerID) - .then(()=>{ + .then(() => { systemTimer.destroyTimer(timerID, function (err, data) { console.info('====>SUB_time_systemTimer_ALL_Promise_0008 destroyTimer: ' + timerID); done(); }); }) - .catch(()=>{ + .catch(() => { // 捕获stopTimer业务逻辑错误 console.info('====>SUB_time_systemTimer_ALL_Promise_0008 failed to stop timer.'); expect().assertTrue(); @@ -673,7 +681,7 @@ export default function systemTimerTest() { done(); } }) - .catch(()=>{ + .catch(() => { // 捕获startTimer业务逻辑错误 console.info('====>SUB_time_systemTimer_ALL_Promise_0008 failed to stop timer.'); expect().assertTrue(); @@ -686,7 +694,7 @@ export default function systemTimerTest() { done(); } }) - .catch(()=>{ + .catch(() => { // 捕获业务逻辑错误 console.info('====>SUB_time_systemTimer_ALL_Promise_0008 failed to create timer.'); expect().assertTrue(); @@ -717,15 +725,15 @@ export default function systemTimerTest() { try { console.info('====>SUB_time_systemTimer_ALL_Callback_0009 create timer.'); systemTimer.createTimer(options) - .then((timerID)=>{ + .then((timerID) => { console.info('====>SUB_time_systemTimer_ALL_Callback_0009 timerID:' + timerID); - expect(Number.isInteger(timerID)).assertTrue(); try { + expect(Number.isInteger(timerID)).assertTrue(); let triggerTime = new Date().getTime() + interval_time * 1.2; - systemTimer.startTimer(timerID, triggerTime, ()=>{ + systemTimer.startTimer(timerID, triggerTime, () => { console.info('====>SUB_time_systemTimer_ALL_Callback_0009 start timerID: ' + timerID); try { - systemTimer.stopTimer(timerID, ()=>{ + systemTimer.stopTimer(timerID, () => { systemTimer.destroyTimer(timerID, function (err, data) { console.info('====>SUB_time_systemTimer_ALL_Callback_0009 destroyTimer: ' + timerID); done(); @@ -747,7 +755,7 @@ export default function systemTimerTest() { console.info('====>SUB_time_systemTimer_ALL_Callback_0009 createTimer with wrong arg: ' + err); expect().assertTrue(); done(); - } + }; }); }); } \ No newline at end of file