提交 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";
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
......@@ -31,14 +63,20 @@ export default function systemTimeJsunit() {
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) => {
try {
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();
done();
};
console.info('====>SystemTime.getCurrentTime success data : ' + JSON.stringify(data));
expect(data != null).assertEqual(true);
console.info("====>----------SUB_systemTime_getRealActiveTime_JS_API_0100 end-----------------");
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() {
*/
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));
await systemTime.getCurrentTime(false).then((data) => {
console.info('====>SUB_systemTime_getCurrentTime_JS_API_0002 success 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));
console.error('====>SUB_systemTime_getCurrentTime_JS_API_0002 fail: ' + JSON.stringify(err));
expect().assertFail()
done();
});
console.info("====>-----SUB_systemTime_getCurrentTime_JS_API_0002 end------------");
});
/**
......@@ -75,14 +113,20 @@ export default function systemTimeJsunit() {
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) => {
try {
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()
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);
console.info("====>----------SUB_systemTime_getRealActiveTime_JS_API_0001 end-----------------");
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() {
*/
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));
await systemTime.getRealActiveTime(false).then((data) => {
console.log('SUB_systemTime_getRealActiveTime_JS_API_0002 success 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));
console.error('====>SUB_systemTime_getRealActiveTime_JS_API_0002 err: ' + JSON.stringify(err));
expect().assertFail()
done();
});
console.info("====>-----SUB_systemTime_getRealActiveTime_JS_API_0002 end------------");
});
/**
......@@ -119,16 +163,21 @@ export default function systemTimeJsunit() {
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) => {
try {
if (error) {
console.error('SUB_systemTime_getRealTime_JS_API_0001 err: ' + JSON.stringify(error));
expect().assertFail()
console.error('SUB_systemTime_getRealTime_JS_API_0001 fail: ' + JSON.stringify(error));
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);
console.info("====>----------SUB_systemTime_getRealTime_JS_API_0001 end-----------------");
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() {
*/
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));
await systemTime.getRealTime(false).then((data) => {
console.info('====>SUB_systemTime_getRealTime_JS_API_0002 success data : ' + JSON.stringify(data));
expect(data != null).assertEqual(true);
}).catch(err => {
console.error('SUB_systemTime_getRealTime_JS_API_0002 err: ' + JSON.stringify(error));
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------------");
done();
});
/**
......@@ -163,16 +213,23 @@ export default function systemTimeJsunit() {
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
systemTime.setTime(currentTime, (err, data) => {
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();
done();
}catch(err){
console.info("====>SUB_systemTime_setTime_JS_API_0100 error " + err);
expect().assertFail();
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
......@@ -213,17 +270,16 @@ export default function systemTimeJsunit() {
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{
await systemTime.setTime(currentTime).then(() => {
console.info('====>SUB_systemTime_setTime_JS_API_0300 success')
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);
}).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");
});
/**
......@@ -240,8 +296,8 @@ export default function systemTimeJsunit() {
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');
expect(true).assertTrue();
done();
})
}catch(err) {
......@@ -260,8 +316,8 @@ export default function systemTimeJsunit() {
*/
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 => {
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();
......@@ -303,8 +359,9 @@ export default function systemTimeJsunit() {
*/
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");
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();
......@@ -313,7 +370,82 @@ export default function systemTimeJsunit() {
console.info("====>SUB_systemTime_setDate_JS_API_0300 data " + data);
expect().assertFail();
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() {
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();
......@@ -350,6 +483,7 @@ export default function systemTimeJsunit() {
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();
......@@ -370,11 +504,89 @@ export default function systemTimeJsunit() {
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();
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() {
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,26 +90,24 @@ 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) {
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();
} catch (error) {
console.info('====>SUB_time_systemTimer_createTimer_0000 catch err ' + error);
done();
};
});
console.info('====>SUB_time_systemTimer_createTimer_0000 end.');
});
/**
* @tc.number SUB_time_systemTimer_createTimer_0001
......@@ -126,23 +123,24 @@ export default function systemTimerTest() {
type: systemTimer.TIMER_TYPE_IDLE,
repeat: false
};
try {
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();
} catch (error) {
console.info('====>SUB_time_systemTimer_createTimer_0001 catch err ' + error);
done();
};
});
console.info('====>SUB_time_systemTimer_createTimer_0001 end.');
});
/**
* @tc.number SUB_time_systemTimer_createTimer_0002
......@@ -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,24 +161,24 @@ export default function systemTimerTest() {
wantAgent: wantAgent,
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) {
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();
} catch (error) {
console.info('====>SUB_time_systemTimer_createTimer_0002 catch err ' + error);
done();
};
});
console.info('====>SUB_time_systemTimer_createTimer_0002 end.');
});
/**
* @tc.number SUB_time_systemTimer_createTimer_0003
......@@ -196,23 +194,24 @@ export default function systemTimerTest() {
type: systemTimer.TIMER_TYPE_EXACT,
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) {
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();
} catch (error) {
console.info('====>SUB_time_systemTimer_createTimer_0003 catch err ' + error);
done();
};
});
console.info('====>SUB_time_systemTimer_createTimer_0003 end.');
});
/**
* @tc.number SUB_time_systemTimer_createTimer_0004
......@@ -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,23 +232,24 @@ export default function systemTimerTest() {
wantAgent: wantAgent,
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) {
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();
} 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
......@@ -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) =>{
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 promise failed ' + err);
console.info('====>SUB_time_systemTimer_createTimer_0005 createTimer fail: ' + err);
expect().assertTrue();
done();
});
} catch (err) {
console.info('====>SUB_time_systemTimer_createTimer_0005 has failed for ' + 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) => {
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 promise failed ' + err);
console.info('====>SUB_time_systemTimer_createTimer_0006 createTimer fail: ' + err);
expect().assertTrue();
done();
});
} catch (e) {
console.info('====>SUB_time_systemTimer_createTimer_0006 arv wrong since ' + e.code);
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) => {
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 promise failed ' + err);
console.info('====>SUB_time_systemTimer_createTimer_0007 createTimer fail: ' + err);
expect().assertTrue();
done();
});
} catch (e) {
console.info('====>SUB_time_systemTimer_createTimer_0007 arv wrong since ' + e);
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) => {
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 promise failed ' + err);
console.info('====>SUB_time_systemTimer_createTimer_0008 createTimer fail: ' + err);
expect().assertTrue();
done();
});
} catch (e) {
console.info('====>SUB_time_systemTimer_createTimer_0008 arv wrong since ' + e);
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) => {
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 promise failed ' + err);
console.info('====>SUB_time_systemTimer_createTimer_0009 createTimer fail: ' + err);
expect().assertTrue();
done();
});
} catch (e) {
console.info('====>SUB_time_systemTimer_createTimer_0009 has failed for ' + e);
expect().assertTrue();
done();
};
console.info('====>SUB_time_systemTimer_createTimer_0009 end.');
});
/**
......@@ -428,24 +401,35 @@ 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;
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();
};
});
console.info("====>SUB_time_systemTimer_startTimer_0001 end");
});
/**
* @tc.number SUB_time_systemTimer_stopTimer_0001
......@@ -457,22 +441,34 @@ 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)
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();
};
});
console.info("====>SUB_time_systemTimer_stopTimer_0001 end");
});
/**
* @tc.number SUB_time_systemTimer_destroyTimer_0001
......@@ -484,22 +480,34 @@ 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)
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();
};
});
console.info("====>SUB_time_systemTimer_destroyTimer_0001 end");
});
/**
* @tc.number SUB_time_systemTimer_createTimerPromise_0001
......@@ -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)=>{
await 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.');
}).catch(error => {
console.info('====>SUB_time_systemTimer_createTimerPromise_0001 failed to create timer: ' + error);
expect().assertTrue();
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() {
*/
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 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;
systemTimer.startTimer(globalTimerID, triggerTime)
.then(()=>{
await systemTimer.startTimer(globalTimerID, triggerTime).then(() => {
console.info('====>SUB_time_systemTimer_startTimer_0002 timerID:' + globalTimerID);
expect(true).assertTrue();
done();
}).catch(()=>{
// 捕获业务逻辑错误
console.info('====>SUB_time_systemTimer_startTimer_0002 failed to start timer.');
}).catch((err) => {
console.info('====>SUB_time_systemTimer_startTimer_0002 failed to start timer: ' + err);
expect().assertTrue();
done();
});
} catch (err) {
// 捕获参数错误
console.info('====>SUB_time_systemTimer_startTimer_0002 has failed for ' + 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(()=>{
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(()=>{
// 捕获业务逻辑错误
console.info('====>SUB_time_systemTimer_stopTimer_0002 failed to stop timer.');
}).catch((err) => {
console.info('====>SUB_time_systemTimer_stopTimer_0002 failed to stop timer:' + err);
expect().assertTrue();
done();
});
} catch (err) {
// 捕获参数错误
console.info('====>SUB_time_systemTimer_stopTimer_0002 has failed for ' + err);
expect().assertTrue();
done();
};
console.info('====>SUB_time_systemTimer_stopTimer_0002 end.');
});
/**
......@@ -607,24 +612,27 @@ 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(()=>{
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(()=>{
// 捕获业务逻辑错误
console.info('====>SUB_time_systemTimer_destroyTimer_0002 failed to destroy timer.');
}).catch((err ) => {
console.info('====>SUB_time_systemTimer_destroyTimer_0002 failed to destroy timer:' + err);
expect().assertTrue();
done();
});
} catch (err) {
// 捕获参数错误
console.info('====>SUB_time_systemTimer_stopTimer_0002 has failed for ' + err);
expect().assertTrue();
done();
};
console.info('====>SUB_time_systemTimer_destroyTimer_0002 end.');
});
/**
......@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册