提交 abcc6f72 编写于 作者: Z zwx1016320

optimization time API 2

Signed-off-by: Nzwx1016320 <zhangyushuai1@huawei-partners.com>
上级 63e674ec
...@@ -20,6 +20,38 @@ import systemTime from "@ohos.systemTime"; ...@@ -20,6 +20,38 @@ import systemTime from "@ohos.systemTime";
export default function systemTimeJsunit() { export default function systemTimeJsunit() {
describe('systemTimeTest', function () { describe('systemTimeTest', function () {
console.info('====>---------------systemTimeTest start-----------------------'); 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.number SUB_systemTime_getCurrentTime_JS_API_0001
* @tc.name Test systemTime.getCurrentTime * @tc.name Test systemTime.getCurrentTime
...@@ -31,14 +63,20 @@ export default function systemTimeJsunit() { ...@@ -31,14 +63,20 @@ export default function systemTimeJsunit() {
it("SUB_systemTime_getCurrentTime_JS_API_0001", 0, async function (done) { it("SUB_systemTime_getCurrentTime_JS_API_0001", 0, async function (done) {
console.info("====>----------UB_systemTime_getCurrentTime_JS_API_0001 start----------------"); console.info("====>----------UB_systemTime_getCurrentTime_JS_API_0001 start----------------");
systemTime.getCurrentTime(true, (error, data) => { systemTime.getCurrentTime(true, (error, data) => {
try {
if (error) { if (error) {
console.error('failed to systemTime.getCurrentTime because ' + JSON.stringify(error)); console.error('====>UB_systemTime_getCurrentTime_JS_API_0001 fail: ' + JSON.stringify(error));
expect().assertFail(); expect().assertFail();
done();
}; };
console.info('====>SystemTime.getCurrentTime success data : ' + JSON.stringify(data)); console.info('====>SystemTime.getCurrentTime success data : ' + JSON.stringify(data));
expect(data != null).assertEqual(true); expect(data != null).assertEqual(true);
console.info("====>----------SUB_systemTime_getRealActiveTime_JS_API_0100 end-----------------");
done(); 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-----------------");
}); });
}); });
...@@ -52,16 +90,16 @@ export default function systemTimeJsunit() { ...@@ -52,16 +90,16 @@ export default function systemTimeJsunit() {
*/ */
it("SUB_systemTime_getCurrentTime_JS_API_0002", 0, async function (done) { it("SUB_systemTime_getCurrentTime_JS_API_0002", 0, async function (done) {
console.info("====>-----SUB_systemTime_getCurrentTime_JS_API_0002 start----------------"); console.info("====>-----SUB_systemTime_getCurrentTime_JS_API_0002 start----------------");
systemTime.getCurrentTime(true).then((data) => { await systemTime.getCurrentTime(false).then((data) => {
console.info('====>SUB_systemTime_getCurrentTime_JS_API_0002 data : ' + JSON.stringify(data)); console.info('====>SUB_systemTime_getCurrentTime_JS_API_0002 success data : ' + JSON.stringify(data));
expect(data != null).assertEqual(true); expect(data != null).assertEqual(true);
console.info("====>-----SUB_systemTime_getCurrentTime_JS_API_0002 end------------");
done(); done();
}).catch(err => { }).catch(err => {
console.error('SUB_systemTime_getCurrentTime_JS_API_0002 err: ' + JSON.stringify(error)); console.error('====>SUB_systemTime_getCurrentTime_JS_API_0002 fail: ' + JSON.stringify(err));
expect().assertFail() expect().assertFail()
done(); done();
}); });
console.info("====>-----SUB_systemTime_getCurrentTime_JS_API_0002 end------------");
}); });
/** /**
...@@ -75,14 +113,20 @@ export default function systemTimeJsunit() { ...@@ -75,14 +113,20 @@ export default function systemTimeJsunit() {
it("SUB_systemTime_getRealActiveTime_JS_API_0001", 0, async function (done) { it("SUB_systemTime_getRealActiveTime_JS_API_0001", 0, async function (done) {
console.info("====>----------SUB_systemTime_getRealActiveTime_JS_API_0001 start----------------"); console.info("====>----------SUB_systemTime_getRealActiveTime_JS_API_0001 start----------------");
systemTime.getRealActiveTime(true, (error, data) => { systemTime.getRealActiveTime(true, (error, data) => {
try {
if (error) { if (error) {
console.error('SUB_systemTime_getRealActiveTime_JS_API_0001 err: ' + JSON.stringify(error)); console.error('====>SUB_systemTime_getRealActiveTime_JS_API_0001 fail: ' + JSON.stringify(error));
expect().assertFail() expect().assertFail()
done();
}; };
console.info('====>SUB_systemTime_getRealActiveTime_JS_API_0001 data : ' + JSON.stringify(data)); console.info('====>SUB_systemTime_getRealActiveTime_JS_API_0001 success data : ' + JSON.stringify(data));
expect(data != null).assertEqual(true); expect(data != null).assertEqual(true);
console.info("====>----------SUB_systemTime_getRealActiveTime_JS_API_0001 end-----------------");
done(); 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-----------------");
}); });
}); });
...@@ -96,16 +140,16 @@ export default function systemTimeJsunit() { ...@@ -96,16 +140,16 @@ export default function systemTimeJsunit() {
*/ */
it("SUB_systemTime_getRealActiveTime_JS_API_0002", 0, async function (done) { it("SUB_systemTime_getRealActiveTime_JS_API_0002", 0, async function (done) {
console.info("====>-----SUB_systemTime_getRealActiveTime_JS_API_0002 start----------------"); console.info("====>-----SUB_systemTime_getRealActiveTime_JS_API_0002 start----------------");
systemTime.getRealActiveTime(true).then((data) => { await systemTime.getRealActiveTime(false).then((data) => {
console.log('SUB_systemTime_getRealActiveTime_JS_API_0002 data : ' + JSON.stringify(data)); console.log('SUB_systemTime_getRealActiveTime_JS_API_0002 success data : ' + JSON.stringify(data));
expect(data != null).assertEqual(true); expect(data != null).assertEqual(true);
console.info("====>-----SUB_systemTime_getRealActiveTime_JS_API_0002 end------------");
done(); done();
}).catch(err => { }).catch(err => {
console.error('SUB_systemTime_getRealActiveTime_JS_API_0002 err: ' + JSON.stringify(error)); console.error('====>SUB_systemTime_getRealActiveTime_JS_API_0002 err: ' + JSON.stringify(err));
expect().assertFail() expect().assertFail()
done(); done();
}); });
console.info("====>-----SUB_systemTime_getRealActiveTime_JS_API_0002 end------------");
}); });
/** /**
...@@ -119,16 +163,21 @@ export default function systemTimeJsunit() { ...@@ -119,16 +163,21 @@ export default function systemTimeJsunit() {
it("SUB_systemTime_getRealTime_JS_API_0001", 0, async function (done) { it("SUB_systemTime_getRealTime_JS_API_0001", 0, async function (done) {
console.info("====>----------SUB_systemTime_getRealTime_JS_API_0001 start----------------"); console.info("====>----------SUB_systemTime_getRealTime_JS_API_0001 start----------------");
systemTime.getRealTime(true, (error, data) => { systemTime.getRealTime(true, (error, data) => {
try {
if (error) { if (error) {
console.error('SUB_systemTime_getRealTime_JS_API_0001 err: ' + JSON.stringify(error)); console.error('SUB_systemTime_getRealTime_JS_API_0001 fail: ' + JSON.stringify(error));
expect().assertFail() expect().assertFail();
done();
}; };
console.info('====>SUB_systemTime_getRealTime_JS_API_0001 data : ' + JSON.stringify(data)); console.info('====>SUB_systemTime_getRealTime_JS_API_0001 success data : ' + JSON.stringify(data));
expect(data != null).assertEqual(true); expect(data != null).assertEqual(true);
console.info("====>----------SUB_systemTime_getRealTime_JS_API_0001 end-----------------");
done(); 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-----------------");
}); });
}); });
/** /**
...@@ -141,15 +190,16 @@ export default function systemTimeJsunit() { ...@@ -141,15 +190,16 @@ export default function systemTimeJsunit() {
*/ */
it("SUB_systemTime_getRealTime_JS_API_0002", 0, async function (done) { it("SUB_systemTime_getRealTime_JS_API_0002", 0, async function (done) {
console.info("====>-----SUB_systemTime_getRealTime_JS_API_0002 start----------------"); console.info("====>-----SUB_systemTime_getRealTime_JS_API_0002 start----------------");
systemTime.getRealTime(true).then((data) => { await systemTime.getRealTime(false).then((data) => {
console.info('====>SUB_systemTime_getRealTime_JS_API_0002 data : ' + JSON.stringify(data)); console.info('====>SUB_systemTime_getRealTime_JS_API_0002 success data : ' + JSON.stringify(data));
expect(data != null).assertEqual(true); expect(data != null).assertEqual(true);
}).catch(err => { done();
console.error('SUB_systemTime_getRealTime_JS_API_0002 err: ' + JSON.stringify(error)); }).catch(error => {
console.error('====>SUB_systemTime_getRealTime_JS_API_0002 err: ' + JSON.stringify(error));
expect().assertFail(); expect().assertFail();
done();
}); });
console.info("====>-----SUB_systemTime_getRealTime_JS_API_0002 end------------"); console.info("====>-----SUB_systemTime_getRealTime_JS_API_0002 end------------");
done();
}); });
/** /**
...@@ -163,16 +213,23 @@ export default function systemTimeJsunit() { ...@@ -163,16 +213,23 @@ export default function systemTimeJsunit() {
it('SUB_systemTime_setTime_JS_API_0100', 0, async function (done) { it('SUB_systemTime_setTime_JS_API_0100', 0, async function (done) {
console.info("====>SUB_systemTime_setTime_JS_API_0100 start"); console.info("====>SUB_systemTime_setTime_JS_API_0100 start");
let currentTime = new Date().getTime() + 2000 let currentTime = new Date().getTime() + 2000
systemTime.setTime(currentTime, (err, data) => {
try{ try{
await systemTime.setTime(currentTime) 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(); expect(true).assertTrue();
done(); done();
}catch(err){ }catch(err){
console.info("====>SUB_systemTime_setTime_JS_API_0100 error " + err); console.info("====>SUB_systemTime_setTime_JS_API_0100 catch error: " + JSON.stringify(err));
expect().assertFail();
done(); done();
} }
}); });
console.info("====>SUB_systemTime_setTime_JS_API_0100 end");
});
/** /**
* @tc.number SUB_systemTime_setTime_JS_API_0200 * @tc.number SUB_systemTime_setTime_JS_API_0200
...@@ -213,17 +270,16 @@ export default function systemTimeJsunit() { ...@@ -213,17 +270,16 @@ export default function systemTimeJsunit() {
it('SUB_systemTime_setTime_JS_API_0300', 0, async function (done) { it('SUB_systemTime_setTime_JS_API_0300', 0, async function (done) {
console.info("====>SUB_systemTime_setTime_JS_API_0300 start"); console.info("====>SUB_systemTime_setTime_JS_API_0300 start");
let currentTime = new Date().getTime() + 2000 let currentTime = new Date().getTime() + 2000
systemTime.setTime(currentTime, (err) => { await systemTime.setTime(currentTime).then(() => {
try{ console.info('====>SUB_systemTime_setTime_JS_API_0300 success')
expect(true).assertTrue(); expect(true).assertTrue();
console.info('====>SUB_systemTime_setTime_JS_API_0300 end');
done(); done();
}catch(err){ }).catch((err)=>{
console.info("====>SUB_systemTime_setTime_JS_API_0300 error: " + err); console.debug('====>SUB_systemTime_setTime_JS_API_0300 setTime fail:' + JSON.stringify(err))
expect().assertFail(); expect().assertFail();
done(); done();
} })
}); console.info("====>SUB_systemTime_setTime_JS_API_0300 end");
}); });
/** /**
...@@ -240,8 +296,8 @@ export default function systemTimeJsunit() { ...@@ -240,8 +296,8 @@ export default function systemTimeJsunit() {
systemTime.setTime(18, (err, data) => { systemTime.setTime(18, (err, data) => {
console.info("====>SUB_systemTime_setTime_JS_API_0400 data: " + 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 error: " + err);
expect(true).assertTrue();
console.info('====>SUB_systemTime_setTime_JS_API_0400 end'); console.info('====>SUB_systemTime_setTime_JS_API_0400 end');
expect(true).assertTrue();
done(); done();
}) })
}catch(err) { }catch(err) {
...@@ -260,8 +316,8 @@ export default function systemTimeJsunit() { ...@@ -260,8 +316,8 @@ export default function systemTimeJsunit() {
*/ */
it('SUB_systemTime_setDate_JS_API_0100', 0, async function (done) { it('SUB_systemTime_setDate_JS_API_0100', 0, async function (done) {
console.info("====>SUB_systemTime_setDate_JS_API_0100 start"); console.info("====>SUB_systemTime_setDate_JS_API_0100 start");
var data = new Date("October 13, 2020 11:13:00"); let data = new Date("October 13, 2020 11:13:00");
systemTime.setDate(1).then(data => { systemTime.setDate(data).then(data => {
console.info("====>SUB_systemTime_setDate_JS_API_0100 data " + data); console.info("====>SUB_systemTime_setDate_JS_API_0100 data " + data);
expect().assertFail(); expect().assertFail();
done(); done();
...@@ -303,8 +359,9 @@ export default function systemTimeJsunit() { ...@@ -303,8 +359,9 @@ export default function systemTimeJsunit() {
*/ */
it('SUB_systemTime_setDate_JS_API_0300', 0, async function (done) { it('SUB_systemTime_setDate_JS_API_0300', 0, async function (done) {
console.info("====>SUB_systemTime_setDate_JS_API_0300 start"); console.info("====>SUB_systemTime_setDate_JS_API_0300 start");
var data = new Date("October 13, 2020 11:13:00"); let data = new Date("October 13, 2020 11:13:00");
systemTime.setDate(data, (error, data) => { systemTime.setDate(data, (error, data) => {
try {
if(error){ if(error){
console.info("====>SUB_systemTime_setDate_JS_API_0300 error " + error); console.info("====>SUB_systemTime_setDate_JS_API_0300 error " + error);
expect(true).assertTrue(); expect(true).assertTrue();
...@@ -313,7 +370,82 @@ export default function systemTimeJsunit() { ...@@ -313,7 +370,82 @@ export default function systemTimeJsunit() {
console.info("====>SUB_systemTime_setDate_JS_API_0300 data " + data); console.info("====>SUB_systemTime_setDate_JS_API_0300 data " + data);
expect().assertFail(); expect().assertFail();
done(); done();
}; }
} 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_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();
}); });
}); });
...@@ -330,6 +462,7 @@ export default function systemTimeJsunit() { ...@@ -330,6 +462,7 @@ export default function systemTimeJsunit() {
systemTime.setTimezone('Asia, Shanghai').then(data => { systemTime.setTimezone('Asia, Shanghai').then(data => {
console.info("====>SUB_systemTime_setTimezone_JS_API_0100 data " + data); console.info("====>SUB_systemTime_setTimezone_JS_API_0100 data " + data);
expect().assertFail(); expect().assertFail();
done();
}).catch(error => { }).catch(error => {
console.info("====>SUB_systemTime_setTimezone_JS_API_0100 error " + error); console.info("====>SUB_systemTime_setTimezone_JS_API_0100 error " + error);
expect(true).assertTrue(); expect(true).assertTrue();
...@@ -350,6 +483,7 @@ export default function systemTimeJsunit() { ...@@ -350,6 +483,7 @@ export default function systemTimeJsunit() {
systemTime.setTimezone('Beijing,China').then(data => { systemTime.setTimezone('Beijing,China').then(data => {
console.info("====>SUB_systemTime_setTimezone_JS_API_0200 data " + data); console.info("====>SUB_systemTime_setTimezone_JS_API_0200 data " + data);
expect().assertFail(); expect().assertFail();
done();
}).catch(error => { }).catch(error => {
console.info("====>SUB_systemTime_setTimezone_JS_API_0200 error " + error); console.info("====>SUB_systemTime_setTimezone_JS_API_0200 error " + error);
expect(true).assertTrue(); expect(true).assertTrue();
...@@ -370,11 +504,89 @@ export default function systemTimeJsunit() { ...@@ -370,11 +504,89 @@ export default function systemTimeJsunit() {
systemTime.setTimezone('Baker Island, U.S.A.').then(data => { systemTime.setTimezone('Baker Island, U.S.A.').then(data => {
console.info("====>SUB_systemTime_setTimezone_JS_API_0300 data " + data); console.info("====>SUB_systemTime_setTimezone_JS_API_0300 data " + data);
expect().assertFail(); expect().assertFail();
done();
}).catch(error => { }).catch(error => {
console.info("====>SUB_systemTime_setTimezone_JS_API_0300 error " + error); console.info("====>SUB_systemTime_setTimezone_JS_API_0300 error " + error);
expect(true).assertTrue(); expect(true).assertTrue();
done(); 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();
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_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();
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();
};
});
});
};
...@@ -31,13 +31,12 @@ export default function systemTimerTest() { ...@@ -31,13 +31,12 @@ export default function systemTimerTest() {
abilityName: "MainAbility" abilityName: "MainAbility"
} }
], ],
operationType: WantAgent.OperationType.SEND_COMMON_EVENT, operationType: WantAgent.OperationType.START_SERVICE,
requestCode: 0, requestCode: 0,
wantAgentFlags:[WantAgent.WantAgentFlags.NO_BUILD_FLAG] wantAgentFlags: [WantAgent.WantAgentFlags.ONE_TIME_FLAG]
} }
let interval_time = 5000; let interval_time = 5000;
let globalTimerID = undefined;
/** /**
* beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed. * beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed.
...@@ -46,8 +45,8 @@ export default function systemTimerTest() { ...@@ -46,8 +45,8 @@ export default function systemTimerTest() {
console.info('====>beforeAll: Prerequisites are executed.'); console.info('====>beforeAll: Prerequisites are executed.');
WantAgent.getWantAgent(wantAgentInfo) WantAgent.getWantAgent(wantAgentInfo)
.then((data) => { .then((data) => {
if ( data != undefined || data != null) { if (data != undefined || data != null) {
console.info('====>beforeAll: success to get wantAgent: ' + typeof(data)); console.info('====>beforeAll: success to get wantAgent: ' + typeof (data));
wantAgent = data; wantAgent = data;
} }
}) })
...@@ -91,26 +90,24 @@ export default function systemTimerTest() { ...@@ -91,26 +90,24 @@ export default function systemTimerTest() {
type: systemTimer.TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat: false repeat: false
}; };
try {
console.info('====>SUB_time_systemTimer_createTimer_0000 create timer.'); console.info('====>SUB_time_systemTimer_createTimer_0000 create timer.');
systemTimer.createTimer(options, function (err, timerID) { systemTimer.createTimer(options, function (err, timerID) {
try {
if (err) { if (err) {
// 处理业务逻辑错误 console.info('====>SUB_time_systemTimer_createTimer_0000 create fail: ' + err);
expect().assertTrue(); expect().assertTrue();
done(); done();
} }
console.info('====>SUB_time_systemTimer_createTimer_0000 timerID: ' + timerID); console.info('====>SUB_time_systemTimer_createTimer_0000 timerID: ' + timerID);
globalTimerID = timerID;
expect(Number.isInteger(timerID)).assertTrue(); expect(Number.isInteger(timerID)).assertTrue();
done(); done();
}); } catch (error) {
} catch (err) { console.info('====>SUB_time_systemTimer_createTimer_0000 catch err ' + error);
// 捕获参数错误
console.info('====>SUB_time_systemTimer_createTimer_0000 has failed for ' + err);
expect().assertTrue();
done(); done();
}; };
}); });
console.info('====>SUB_time_systemTimer_createTimer_0000 end.');
});
/** /**
* @tc.number SUB_time_systemTimer_createTimer_0001 * @tc.number SUB_time_systemTimer_createTimer_0001
...@@ -126,23 +123,24 @@ export default function systemTimerTest() { ...@@ -126,23 +123,24 @@ export default function systemTimerTest() {
type: systemTimer.TIMER_TYPE_IDLE, type: systemTimer.TIMER_TYPE_IDLE,
repeat: false repeat: false
}; };
try { console.info('====>SUB_time_systemTimer_createTimer_0001 create timer.');
systemTimer.createTimer(options, function (err, timerID) { systemTimer.createTimer(options, function (err, timerID) {
try {
if (err) { 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(); expect().assertTrue();
done(); done();
}; }
console.info('====>SUB_time_systemTimer_createTimer_0001 timerID: ' + timerID); console.info('====>SUB_time_systemTimer_createTimer_0001 timerID: ' + timerID);
expect(Number.isInteger(timerID)).assertTrue(); expect(Number.isInteger(timerID)).assertTrue();
done(); done();
}); } catch (error) {
} catch (e) { console.info('====>SUB_time_systemTimer_createTimer_0001 catch err ' + error);
console.info('====>SUB_time_systemTimer_createTimer_0001 arv wrong since ' + e.code);
expect().assertTrue();
done(); done();
}; };
}); });
console.info('====>SUB_time_systemTimer_createTimer_0001 end.');
});
/** /**
* @tc.number SUB_time_systemTimer_createTimer_0002 * @tc.number SUB_time_systemTimer_createTimer_0002
...@@ -154,7 +152,7 @@ export default function systemTimerTest() { ...@@ -154,7 +152,7 @@ export default function systemTimerTest() {
*/ */
it('SUB_time_systemTimer_createTimer_0002', 2, async function (done) { it('SUB_time_systemTimer_createTimer_0002', 2, async function (done) {
console.info("====>SUB_time_systemTimer_createTimer_0002 start"); 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); console.info('====>SUB_time_systemTimer_createTimer_0002 BundleName: ' + data);
}) })
let options = { let options = {
...@@ -163,24 +161,24 @@ export default function systemTimerTest() { ...@@ -163,24 +161,24 @@ export default function systemTimerTest() {
wantAgent: wantAgent, wantAgent: wantAgent,
interval: interval_time interval: interval_time
}; };
try { console.info('====>SUB_time_systemTimer_createTimer_0002 create timer.');
console.info("====>SUB_time_systemTimer_createTimer_0002 create timer")
systemTimer.createTimer(options, function (err, timerID) { systemTimer.createTimer(options, function (err, timerID) {
try {
if (err) { 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(); expect().assertTrue();
done(); done();
} }
console.info('====>SUB_time_systemTimer_createTimer_0002 timerID: ' + timerID); console.info('====>SUB_time_systemTimer_createTimer_0002 timerID: ' + timerID);
expect(Number.isInteger(timerID)).assertTrue(); expect(Number.isInteger(timerID)).assertTrue();
done(); done();
}); } catch (error) {
} catch (e) { console.info('====>SUB_time_systemTimer_createTimer_0002 catch err ' + error);
console.info('====>SUB_time_systemTimer_createTimer_0002 arv wrong since ' + e);
expect().assertTrue();
done(); done();
}; };
}); });
console.info('====>SUB_time_systemTimer_createTimer_0002 end.');
});
/** /**
* @tc.number SUB_time_systemTimer_createTimer_0003 * @tc.number SUB_time_systemTimer_createTimer_0003
...@@ -196,23 +194,24 @@ export default function systemTimerTest() { ...@@ -196,23 +194,24 @@ export default function systemTimerTest() {
type: systemTimer.TIMER_TYPE_EXACT, type: systemTimer.TIMER_TYPE_EXACT,
repeat: false repeat: false
}; };
try { console.info('====>SUB_time_systemTimer_createTimer_0003 create timer.');
console.info("====>SUB_time_systemTimer_createTimer_0003 create timer")
systemTimer.createTimer(options, function (err, timerID) { systemTimer.createTimer(options, function (err, timerID) {
try {
if (err) { 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(); expect().assertTrue();
done(); done();
} }
console.info('====>SUB_time_systemTimer_createTimer_0003 timerID: ' + timerID);
expect(Number.isInteger(timerID)).assertTrue(); expect(Number.isInteger(timerID)).assertTrue();
done(); done();
}); } catch (error) {
} catch (e) { console.info('====>SUB_time_systemTimer_createTimer_0003 catch err ' + error);
console.info('====>SUB_time_systemTimer_createTimer_0003 arv wrong since ' + e);
expect().assertTrue();
done(); done();
}; };
}); });
console.info('====>SUB_time_systemTimer_createTimer_0003 end.');
});
/** /**
* @tc.number SUB_time_systemTimer_createTimer_0004 * @tc.number SUB_time_systemTimer_createTimer_0004
...@@ -224,7 +223,7 @@ export default function systemTimerTest() { ...@@ -224,7 +223,7 @@ export default function systemTimerTest() {
*/ */
it('SUB_time_systemTimer_createTimer_0004', 2, async function (done) { it('SUB_time_systemTimer_createTimer_0004', 2, async function (done) {
console.info("====>SUB_time_systemTimer_createTimer_0004 start"); 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); console.info("====>SUB_time_systemTimer_createTimer_0004 BundleName: " + data);
}); });
let options = { let options = {
...@@ -233,23 +232,24 @@ export default function systemTimerTest() { ...@@ -233,23 +232,24 @@ export default function systemTimerTest() {
wantAgent: wantAgent, wantAgent: wantAgent,
interval: interval_time interval: interval_time
}; };
try { console.info('====>SUB_time_systemTimer_createTimer_0004 create timer.');
console.info("====>SUB_time_systemTimer_createTimer_0004 create timer")
systemTimer.createTimer(options, function (err, timerID) { systemTimer.createTimer(options, function (err, timerID) {
try {
if (err) { if (err) {
console.info('====>SUB_time_systemTimer_createTimer_0004 create fail: ' + err);
expect().assertTrue(); expect().assertTrue();
done(); done();
}; }
console.info('====>SUB_time_systemTimer_createTimer_0004 timerID: ' + timerID);
expect(Number.isInteger(timerID)).assertTrue(); expect(Number.isInteger(timerID)).assertTrue();
done(); done();
}); } catch (error) {
} catch (e) { console.info('====>SUB_time_systemTimer_createTimer_0004 catch err ' + error);
console.info('====>SUB_time_systemTimer_createTimer_0004 has failed for ' + e);
expect().assertTrue();
done(); done();
}; };
}); });
console.info('====>SUB_time_systemTimer_createTimer_0004 end.');
});
/** /**
* @tc.number SUB_time_systemTimer_createTimer_0005 * @tc.number SUB_time_systemTimer_createTimer_0005
...@@ -265,22 +265,16 @@ export default function systemTimerTest() { ...@@ -265,22 +265,16 @@ export default function systemTimerTest() {
type: systemTimer.TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat: false repeat: false
}; };
try { await systemTimer.createTimer(options).then((timerID) => {
console.info('====>SUB_time_systemTimer_createTimer_0005 create timer.');
systemTimer.createTimer(options).then((timerID) =>{
console.info('====>SUB_time_systemTimer_createTimer_0005 timerID: ' + timerID); console.info('====>SUB_time_systemTimer_createTimer_0005 timerID: ' + timerID);
expect(Number.isInteger(timerID)).assertTrue(); expect(Number.isInteger(timerID)).assertTrue();
done(); done();
}).catch(err => { }).catch(err => {
console.info('====>SUB_time_systemTimer_createTimer_0005 promise failed ' + err); console.info('====>SUB_time_systemTimer_createTimer_0005 createTimer fail: ' + err);
expect().assertTrue(); expect().assertTrue();
done(); done();
}); });
} catch (err) { console.info('====>SUB_time_systemTimer_createTimer_0005 end.');
console.info('====>SUB_time_systemTimer_createTimer_0005 has failed for ' + err);
expect().assertTrue();
done();
};
}); });
/** /**
...@@ -297,21 +291,16 @@ export default function systemTimerTest() { ...@@ -297,21 +291,16 @@ export default function systemTimerTest() {
type: systemTimer.TIMER_TYPE_IDLE, type: systemTimer.TIMER_TYPE_IDLE,
repeat: false repeat: false
}; };
try { await systemTimer.createTimer(options).then((timerID) => {
systemTimer.createTimer(options).then((timerID) => {
console.info('====>SUB_time_systemTimer_createTimer_0006 timerID: ' + timerID); console.info('====>SUB_time_systemTimer_createTimer_0006 timerID: ' + timerID);
expect(Number.isInteger(timerID)).assertTrue(); expect(Number.isInteger(timerID)).assertTrue();
done(); done();
}).catch(err => { }).catch(err => {
console.info('====>SUB_time_systemTimer_createTimer_0006 promise failed ' + err); console.info('====>SUB_time_systemTimer_createTimer_0006 createTimer fail: ' + err);
expect().assertTrue(); expect().assertTrue();
done(); done();
}); });
} catch (e) { console.info('====>SUB_time_systemTimer_createTimer_0006 end.');
console.info('====>SUB_time_systemTimer_createTimer_0006 arv wrong since ' + e.code);
expect().assertTrue();
done();
};
}); });
/** /**
...@@ -324,7 +313,7 @@ export default function systemTimerTest() { ...@@ -324,7 +313,7 @@ export default function systemTimerTest() {
*/ */
it('SUB_time_systemTimer_createTimer_0007', 2, async function (done) { it('SUB_time_systemTimer_createTimer_0007', 2, async function (done) {
console.info("====>SUB_time_systemTimer_createTimer_0007 start"); 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); console.info('====>SUB_time_systemTimer_createTimer_0007 BundleName: ' + data);
}) })
let options = { let options = {
...@@ -333,22 +322,16 @@ export default function systemTimerTest() { ...@@ -333,22 +322,16 @@ export default function systemTimerTest() {
wantAgent: wantAgent, wantAgent: wantAgent,
interval: interval_time interval: interval_time
}; };
try { await systemTimer.createTimer(options).then((timerID) => {
console.info("====>SUB_time_systemTimer_createTimer_0007 create timer");
systemTimer.createTimer(options).then((timerID) => {
console.info('====>SUB_time_systemTimer_createTimer_0007 timerID: ' + timerID); console.info('====>SUB_time_systemTimer_createTimer_0007 timerID: ' + timerID);
expect(Number.isInteger(timerID)).assertTrue(); expect(Number.isInteger(timerID)).assertTrue();
done(); done();
}).catch(err => { }).catch(err => {
console.info('====>SUB_time_systemTimer_createTimer_0007 promise failed ' + err); console.info('====>SUB_time_systemTimer_createTimer_0007 createTimer fail: ' + err);
expect().assertTrue(); expect().assertTrue();
done(); done();
}); });
} catch (e) { console.info('====>SUB_time_systemTimer_createTimer_0007 end.');
console.info('====>SUB_time_systemTimer_createTimer_0007 arv wrong since ' + e);
expect().assertTrue();
done();
};
}); });
/** /**
...@@ -365,21 +348,16 @@ export default function systemTimerTest() { ...@@ -365,21 +348,16 @@ export default function systemTimerTest() {
type: systemTimer.TIMER_TYPE_EXACT, type: systemTimer.TIMER_TYPE_EXACT,
repeat: false repeat: false
}; };
try { await systemTimer.createTimer(options).then((timerID) => {
console.info("====>SUB_time_systemTimer_createTimer_0008 create timer") console.info('====>SUB_time_systemTimer_createTimer_0008 timerID: ' + timerID);
systemTimer.createTimer(options).then((timerID) => {
expect(Number.isInteger(timerID)).assertTrue(); expect(Number.isInteger(timerID)).assertTrue();
done(); done();
}).catch(err => { }).catch(err => {
console.info('====>SUB_time_systemTimer_createTimer_0008 promise failed ' + err); console.info('====>SUB_time_systemTimer_createTimer_0008 createTimer fail: ' + err);
expect().assertTrue(); expect().assertTrue();
done(); done();
}); });
} catch (e) { console.info('====>SUB_time_systemTimer_createTimer_0008 end.');
console.info('====>SUB_time_systemTimer_createTimer_0008 arv wrong since ' + e);
expect().assertTrue();
done();
};
}); });
/** /**
...@@ -392,7 +370,7 @@ export default function systemTimerTest() { ...@@ -392,7 +370,7 @@ export default function systemTimerTest() {
*/ */
it('SUB_time_systemTimer_createTimer_0009', 2, async function (done) { it('SUB_time_systemTimer_createTimer_0009', 2, async function (done) {
console.info("====>SUB_time_systemTimer_createTimer_0009 start"); 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); console.info("====>SUB_time_systemTimer_createTimer_0009 BundleName: " + data);
}); });
let options = { let options = {
...@@ -401,21 +379,16 @@ export default function systemTimerTest() { ...@@ -401,21 +379,16 @@ export default function systemTimerTest() {
wantAgent: wantAgent, wantAgent: wantAgent,
interval: interval_time interval: interval_time
}; };
try { await systemTimer.createTimer(options).then((timerID) => {
console.info("====>SUB_time_systemTimer_createTimer_0009 create timer") console.info('====>SUB_time_systemTimer_createTimer_0009 timerID: ' + timerID);
systemTimer.createTimer(options).then((timerID) => {
expect(Number.isInteger(timerID)).assertTrue(); expect(Number.isInteger(timerID)).assertTrue();
done(); done();
}).catch(err => { }).catch(err => {
console.info('====>SUB_time_systemTimer_createTimer_0009 promise failed ' + err); console.info('====>SUB_time_systemTimer_createTimer_0009 createTimer fail: ' + err);
expect().assertTrue(); expect().assertTrue();
done(); done();
}); });
} catch (e) { console.info('====>SUB_time_systemTimer_createTimer_0009 end.');
console.info('====>SUB_time_systemTimer_createTimer_0009 has failed for ' + e);
expect().assertTrue();
done();
};
}); });
/** /**
...@@ -428,24 +401,35 @@ export default function systemTimerTest() { ...@@ -428,24 +401,35 @@ export default function systemTimerTest() {
*/ */
it('SUB_time_systemTimer_startTimer_0001', 0, async function (done) { it('SUB_time_systemTimer_startTimer_0001', 0, async function (done) {
console.info("====>SUB_time_systemTimer_startTimer_0001 start"); 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; 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) { systemTimer.startTimer(globalTimerID, triggerTime, function (err, data) {
try {
if (err) { if (err) {
console.info('====>SUB_time_systemTimer_startTimer_0001 wrong since ' + err.code); console.info('====>SUB_time_systemTimer_startTimer_0001 wrong since ' + err.code);
expect().assertTrue(); expect().assertTrue();
done(); done();
} }
console.info("====>SUB_time_systemTimer_startTimer_0001 success to start timerID: " + globalTimerID); console.info("====>SUB_time_systemTimer_startTimer_0001 success to start timerID: " + globalTimerID);
expect(true).assertTrue();
done(); done();
});
} catch (e) { } catch (e) {
console.info('====>SUB_time_systemTimer_startTimer_0001 has failed for ' + e); console.info('====>SUB_time_systemTimer_startTimer_0001 has failed for ' + e);
expect().assertTrue();
done(); done();
}; };
}); });
console.info("====>SUB_time_systemTimer_startTimer_0001 end");
});
/** /**
* @tc.number SUB_time_systemTimer_stopTimer_0001 * @tc.number SUB_time_systemTimer_stopTimer_0001
...@@ -457,22 +441,34 @@ export default function systemTimerTest() { ...@@ -457,22 +441,34 @@ export default function systemTimerTest() {
*/ */
it('SUB_time_systemTimer_stopTimer_0001', 0, async function (done) { it('SUB_time_systemTimer_stopTimer_0001', 0, async function (done) {
console.info("====>SUB_time_systemTimer_stopTimer_0001 start"); console.info("====>SUB_time_systemTimer_stopTimer_0001 start");
try { let options = {
console.info("====>SUB_time_systemTimer_stopTimer_0001 stop timer, timerID: " + globalTimerID) 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) { systemTimer.stopTimer(globalTimerID, function (err, data) {
try {
if (err) { if (err) {
console.info("====>SUB_time_systemTimer_stopTimer_0001 stop fail timerID: " + globalTimerID);
expect().assertTrue(); expect().assertTrue();
done(); done();
}; };
console.info("====>SUB_time_systemTimer_stopTimer_0001 success to stop timerID: " + globalTimerID); console.info("====>SUB_time_systemTimer_stopTimer_0001 success to stop timerID: " + globalTimerID);
expect(true).assertTrue();
done(); done();
});
} catch (e) { } catch (e) {
console.info('====>SUB_time_systemTimer_stopTimer_0001 has failed for ' + e); console.info('====>SUB_time_systemTimer_stopTimer_0001 has failed for ' + e);
expect().assertTrue();
done(); done();
}; };
}); });
console.info("====>SUB_time_systemTimer_stopTimer_0001 end");
});
/** /**
* @tc.number SUB_time_systemTimer_destroyTimer_0001 * @tc.number SUB_time_systemTimer_destroyTimer_0001
...@@ -484,22 +480,34 @@ export default function systemTimerTest() { ...@@ -484,22 +480,34 @@ export default function systemTimerTest() {
*/ */
it('SUB_time_systemTimer_destroyTimer_0001', 0, async function (done) { it('SUB_time_systemTimer_destroyTimer_0001', 0, async function (done) {
console.info("====>SUB_time_systemTimer_destroyTimer_0001 start"); console.info("====>SUB_time_systemTimer_destroyTimer_0001 start");
try { let options = {
console.info("====>SUB_time_systemTimer_destroyTimer_0001 destroy timer, timerID: " + globalTimerID) 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) { systemTimer.destroyTimer(globalTimerID, function (err, data) {
try {
if (err) { if (err) {
console.info("====>SUB_time_systemTimer_destroyTimer_0001 destroy timer, timerID: " + globalTimerID)
expect().assertTrue(); expect().assertTrue();
done(); done();
}; };
console.info("====>SUB_time_systemTimer_destroyTimer_0001 success to destroy timerID: " + globalTimerID); console.info("====>SUB_time_systemTimer_destroyTimer_0001 success to destroy timerID: " + globalTimerID);
expect(true).assertTrue();
done(); done();
});
} catch (e) { } catch (e) {
console.info('====>SUB_time_systemTimer_destroyTimer_0001 has failed for ' + e); console.info('====>SUB_time_systemTimer_destroyTimer_0001 has failed for ' + e);
expect().assertTrue();
done(); done();
}; };
}); });
console.info("====>SUB_time_systemTimer_destroyTimer_0001 end");
});
/** /**
* @tc.number SUB_time_systemTimer_createTimerPromise_0001 * @tc.number SUB_time_systemTimer_createTimerPromise_0001
...@@ -515,25 +523,16 @@ export default function systemTimerTest() { ...@@ -515,25 +523,16 @@ export default function systemTimerTest() {
type: systemTimer.TIMER_TYPE_REALTIME, type: systemTimer.TIMER_TYPE_REALTIME,
repeat: false repeat: false
}; };
try {
console.info('====>SUB_time_systemTimer_createTimerPromise_0001 create timer.'); console.info('====>SUB_time_systemTimer_createTimerPromise_0001 create timer.');
systemTimer.createTimer(options).then((timerID)=>{ await systemTimer.createTimer(options).then((timerID) => {
console.info('====>SUB_time_systemTimer_createTimerPromise_0001 timerID:' + timerID); console.info('====>SUB_time_systemTimer_createTimerPromise_0001 timerID:' + timerID);
expect(Number.isInteger(timerID)).assertTrue(); expect(Number.isInteger(timerID)).assertTrue();
globalTimerID = timerID;
done(); done();
}).catch( error => { }).catch(error => {
// 捕获业务逻辑错误 console.info('====>SUB_time_systemTimer_createTimerPromise_0001 failed to create timer: ' + error);
console.info('====>SUB_time_systemTimer_createTimerPromise_0001 failed to create timer.');
expect().assertTrue(); expect().assertTrue();
done(); done();
}); });
} catch (err) {
// 捕获参数错误
console.info('====>SUB_time_systemTimer_createTimerPromise_0001 has failed for ' + err);
expect().assertTrue();
done();
};
}); });
/** /**
...@@ -546,25 +545,28 @@ export default function systemTimerTest() { ...@@ -546,25 +545,28 @@ export default function systemTimerTest() {
*/ */
it('SUB_time_systemTimer_startTimer_0002', 0, async function (done) { it('SUB_time_systemTimer_startTimer_0002', 0, async function (done) {
console.info('====>SUB_time_systemTimer_startTimer_0002 start.'); console.info('====>SUB_time_systemTimer_startTimer_0002 start.');
try { let options = {
console.info('====>SUB_time_systemTimer_startTimer_0002 start timer, timerID: ' + globalTimerID); 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; let triggerTime = new Date().getTime() + interval_time * 2;
systemTimer.startTimer(globalTimerID, triggerTime) await systemTimer.startTimer(globalTimerID, triggerTime).then(() => {
.then(()=>{
console.info('====>SUB_time_systemTimer_startTimer_0002 timerID:' + globalTimerID); console.info('====>SUB_time_systemTimer_startTimer_0002 timerID:' + globalTimerID);
expect(true).assertTrue();
done(); done();
}).catch(()=>{ }).catch((err) => {
// 捕获业务逻辑错误 console.info('====>SUB_time_systemTimer_startTimer_0002 failed to start timer: ' + err);
console.info('====>SUB_time_systemTimer_startTimer_0002 failed to start timer.');
expect().assertTrue(); expect().assertTrue();
done(); done();
}); });
} catch (err) { console.info('====>SUB_time_systemTimer_startTimer_0002 end.');
// 捕获参数错误
console.info('====>SUB_time_systemTimer_startTimer_0002 has failed for ' + err);
expect().assertTrue();
done();
}
}); });
/** /**
...@@ -577,24 +579,27 @@ export default function systemTimerTest() { ...@@ -577,24 +579,27 @@ export default function systemTimerTest() {
*/ */
it('SUB_time_systemTimer_stopTimer_0002', 0, async function (done) { it('SUB_time_systemTimer_stopTimer_0002', 0, async function (done) {
console.info('====>SUB_time_systemTimer_stopTimer_0002 start.'); console.info('====>SUB_time_systemTimer_stopTimer_0002 start.');
try { let options = {
console.info('====>SUB_time_systemTimer_stopTimer_0002 stop timer, timerID: ' + globalTimerID); type: systemTimer.TIMER_TYPE_EXACT,
systemTimer.stopTimer(globalTimerID) repeat: false
.then(()=>{ };
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); console.info('====>SUB_time_systemTimer_stopTimer_0002 timerID:' + globalTimerID);
expect(true).assertTrue();
done(); done();
}).catch(()=>{ }).catch((err) => {
// 捕获业务逻辑错误 console.info('====>SUB_time_systemTimer_stopTimer_0002 failed to stop timer:' + err);
console.info('====>SUB_time_systemTimer_stopTimer_0002 failed to stop timer.');
expect().assertTrue(); expect().assertTrue();
done(); done();
}); });
} catch (err) { console.info('====>SUB_time_systemTimer_stopTimer_0002 end.');
// 捕获参数错误
console.info('====>SUB_time_systemTimer_stopTimer_0002 has failed for ' + err);
expect().assertTrue();
done();
};
}); });
/** /**
...@@ -607,24 +612,27 @@ export default function systemTimerTest() { ...@@ -607,24 +612,27 @@ export default function systemTimerTest() {
*/ */
it('SUB_time_systemTimer_destroyTimer_0002', 0, async function (done) { it('SUB_time_systemTimer_destroyTimer_0002', 0, async function (done) {
console.info('====>SUB_time_systemTimer_destroyTimer_0002 start.'); console.info('====>SUB_time_systemTimer_destroyTimer_0002 start.');
try { let options = {
console.info('====>SUB_time_systemTimer_destroyTimer_0002 destroy timer, timerID: ' + globalTimerID); type: systemTimer.TIMER_TYPE_REALTIME,
systemTimer.destroyTimer(globalTimerID) repeat: false
.then(()=>{ };
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); console.info('====>SUB_time_systemTimer_destroyTimer_0002 timerID:' + globalTimerID);
expect(true).assertTrue();
done(); done();
}).catch(()=>{ }).catch((err ) => {
// 捕获业务逻辑错误 console.info('====>SUB_time_systemTimer_destroyTimer_0002 failed to destroy timer:' + err);
console.info('====>SUB_time_systemTimer_destroyTimer_0002 failed to destroy timer.');
expect().assertTrue(); expect().assertTrue();
done(); done();
}); });
} catch (err) { console.info('====>SUB_time_systemTimer_destroyTimer_0002 end.');
// 捕获参数错误
console.info('====>SUB_time_systemTimer_stopTimer_0002 has failed for ' + err);
expect().assertTrue();
done();
};
}); });
/** /**
...@@ -644,23 +652,23 @@ export default function systemTimerTest() { ...@@ -644,23 +652,23 @@ export default function systemTimerTest() {
try { try {
console.info('====>SUB_time_systemTimer_ALL_Promise_0008 create timer.'); console.info('====>SUB_time_systemTimer_ALL_Promise_0008 create timer.');
systemTimer.createTimer(options) systemTimer.createTimer(options)
.then((timerID)=>{ .then((timerID) => {
console.info('====>SUB_time_systemTimer_ALL_Promise_0008 timerID:' + timerID); console.info('====>SUB_time_systemTimer_ALL_Promise_0008 timerID:' + timerID);
expect(Number.isInteger(timerID)).assertTrue();
try { try {
expect(Number.isInteger(timerID)).assertTrue();
let triggerTime = new Date().getTime() + interval_time * 1.2; let triggerTime = new Date().getTime() + interval_time * 1.2;
systemTimer.startTimer(timerID, triggerTime) systemTimer.startTimer(timerID, triggerTime)
.then(()=>{ .then(() => {
console.info('====>SUB_time_systemTimer_ALL_Promise_0008 start timerID: ' + timerID); console.info('====>SUB_time_systemTimer_ALL_Promise_0008 start timerID: ' + timerID);
try { try {
systemTimer.stopTimer(timerID) systemTimer.stopTimer(timerID)
.then(()=>{ .then(() => {
systemTimer.destroyTimer(timerID, function (err, data) { systemTimer.destroyTimer(timerID, function (err, data) {
console.info('====>SUB_time_systemTimer_ALL_Promise_0008 destroyTimer: ' + timerID); console.info('====>SUB_time_systemTimer_ALL_Promise_0008 destroyTimer: ' + timerID);
done(); done();
}); });
}) })
.catch(()=>{ .catch(() => {
// 捕获stopTimer业务逻辑错误 // 捕获stopTimer业务逻辑错误
console.info('====>SUB_time_systemTimer_ALL_Promise_0008 failed to stop timer.'); console.info('====>SUB_time_systemTimer_ALL_Promise_0008 failed to stop timer.');
expect().assertTrue(); expect().assertTrue();
...@@ -673,7 +681,7 @@ export default function systemTimerTest() { ...@@ -673,7 +681,7 @@ export default function systemTimerTest() {
done(); done();
} }
}) })
.catch(()=>{ .catch(() => {
// 捕获startTimer业务逻辑错误 // 捕获startTimer业务逻辑错误
console.info('====>SUB_time_systemTimer_ALL_Promise_0008 failed to stop timer.'); console.info('====>SUB_time_systemTimer_ALL_Promise_0008 failed to stop timer.');
expect().assertTrue(); expect().assertTrue();
...@@ -686,7 +694,7 @@ export default function systemTimerTest() { ...@@ -686,7 +694,7 @@ export default function systemTimerTest() {
done(); done();
} }
}) })
.catch(()=>{ .catch(() => {
// 捕获业务逻辑错误 // 捕获业务逻辑错误
console.info('====>SUB_time_systemTimer_ALL_Promise_0008 failed to create timer.'); console.info('====>SUB_time_systemTimer_ALL_Promise_0008 failed to create timer.');
expect().assertTrue(); expect().assertTrue();
...@@ -717,15 +725,15 @@ export default function systemTimerTest() { ...@@ -717,15 +725,15 @@ export default function systemTimerTest() {
try { try {
console.info('====>SUB_time_systemTimer_ALL_Callback_0009 create timer.'); console.info('====>SUB_time_systemTimer_ALL_Callback_0009 create timer.');
systemTimer.createTimer(options) systemTimer.createTimer(options)
.then((timerID)=>{ .then((timerID) => {
console.info('====>SUB_time_systemTimer_ALL_Callback_0009 timerID:' + timerID); console.info('====>SUB_time_systemTimer_ALL_Callback_0009 timerID:' + timerID);
expect(Number.isInteger(timerID)).assertTrue();
try { try {
expect(Number.isInteger(timerID)).assertTrue();
let triggerTime = new Date().getTime() + interval_time * 1.2; 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); console.info('====>SUB_time_systemTimer_ALL_Callback_0009 start timerID: ' + timerID);
try { try {
systemTimer.stopTimer(timerID, ()=>{ systemTimer.stopTimer(timerID, () => {
systemTimer.destroyTimer(timerID, function (err, data) { systemTimer.destroyTimer(timerID, function (err, data) {
console.info('====>SUB_time_systemTimer_ALL_Callback_0009 destroyTimer: ' + timerID); console.info('====>SUB_time_systemTimer_ALL_Callback_0009 destroyTimer: ' + timerID);
done(); done();
...@@ -747,7 +755,7 @@ export default function systemTimerTest() { ...@@ -747,7 +755,7 @@ export default function systemTimerTest() {
console.info('====>SUB_time_systemTimer_ALL_Callback_0009 createTimer with wrong arg: ' + err); console.info('====>SUB_time_systemTimer_ALL_Callback_0009 createTimer with wrong arg: ' + err);
expect().assertTrue(); expect().assertTrue();
done(); done();
} };
}); });
}); });
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册