提交 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();
};
});
});
};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册