未验证 提交 82089446 编写于 作者: O openharmony_ci 提交者: Gitee

!8418 【杂散】【时间时区】新增时间无权限用例

Merge pull request !8418 from 张育帅/master
...@@ -17,5 +17,6 @@ group("time") { ...@@ -17,5 +17,6 @@ group("time") {
deps = [ deps = [
"dateTimeTest:ActsDateTimeAPITest", "dateTimeTest:ActsDateTimeAPITest",
"timeTest:ActsTimeAPITest", "timeTest:ActsTimeAPITest",
"timeauthorityTest:ActsTimeAuthorityAPITest",
] ]
} }
...@@ -5,8 +5,7 @@ ...@@ -5,8 +5,7 @@
"test-timeout": "180000", "test-timeout": "180000",
"bundle-name": "com.acts.time.test", "bundle-name": "com.acts.time.test",
"module-name": "entry_test", "module-name": "entry_test",
"shell-timeout": "180000", "shell-timeout": "180000"
"testcase-timeout": 600000
}, },
"kits": [{ "kits": [{
"test-file-name": [ "test-file-name": [
......
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
* limitations under the License. * limitations under the License.
*/ */
import systemTimeJsunit from './systemTimeTest'; import systemTimeJsunit from './systemTimeTest';
import systemTimeCommonEventTest from './systemTimeCommonEvent.test' import systemTimeNoPermissionTest from './timeNoPermission.test'
export default function testsuite() { export default function testsuite() {
systemTimeJsunit(); systemTimeJsunit();
systemTimeCommonEventTest(); systemTimeNoPermissionTest();
} }
\ No newline at end of file
...@@ -20,37 +20,6 @@ import systemTime from "@ohos.systemTime"; ...@@ -20,37 +20,6 @@ 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
...@@ -203,339 +172,106 @@ export default function systemTimeJsunit() { ...@@ -203,339 +172,106 @@ export default function systemTimeJsunit() {
}); });
/** /**
* @tc.number SUB_systemTime_setTime_JS_API_0100 * @tc.number SUB_systemTime_getDate_JS_API_0100
* @tc.name Test systemTime.setTime * @tc.name Test systemTime.getDate true value
* @tc.desc Test systemTime_setTime API functionality. * @tc.desc Test systemTime_getDate API functionality.
* @tc.size : MEDIUM * @tc.size : MEDIUM
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_systemTime_setTime_JS_API_0100', 0, async function (done) { it('SUB_systemTime_getDate_JS_API_0100', 0, async function (done) {
console.info("====>SUB_systemTime_setTime_JS_API_0100 start"); console.info("====>SUB_systemTime_getDate_JS_API_0100 start");
let currentTime = new Date().getTime() + 2000 systemTime.getDate((error, data) => {
systemTime.setTime(currentTime, (err, data) => { try {
try{ if(error){
if(err){ console.info("====>SUB_systemTime_getDate_JS_API_0100 getDate fail: " + JSON.stringify(error));
console.info("====>SUB_systemTime_setTime_JS_API_0100 setTime fail: " + JSON.stringify(err));
expect().assertFail(); expect().assertFail();
done(); done();
} }
console.info('====>SUB_systemTime_setTime_JS_API_0100 success: ' + data); console.info("====>SUB_systemTime_getDate_JS_API_0100 getDate: " + JSON.stringify(data));
expect(true).assertTrue(); console.info("====>SUB_systemTime_getDate_JS_API_0100 getDate: " + typeof(data));
expect(typeof(data) === "object").assertTrue();
done(); done();
}catch(err){ } catch (err) {
console.info("====>SUB_systemTime_setTime_JS_API_0100 catch error: " + JSON.stringify(err)); console.info("====>SUB_systemTime_getDate_JS_API_0100 catch error " + JSON.stringify(err));
done(); done();
} }
}); });
console.info("====>SUB_systemTime_setTime_JS_API_0100 end");
});
/**
* @tc.number SUB_systemTime_setTime_JS_API_0200
* @tc.name Test systemTime.setTime Invalid value
* @tc.desc Test systemTime_setTime API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_systemTime_setTime_JS_API_0200', 0, async function (done) {
console.info("====>SUB_systemTime_setTime_JS_API_0200 start");
try{
systemTime.setTime(15222).then(() => {
console.debug('====>SUB_systemTime_setTime_JS_API_0200 setTime fail')
expect().assertFail();
done();
}).catch((err)=>{
console.debug('====>SUB_systemTime_setTime_JS_API_0200 setTime err:' + JSON.stringify(err))
expect(true).assertTrue();
console.debug('====>SUB_systemTime_setTime_JS_API_0200 end');
done();
})
}catch(err){
console.debug('====>SUB_systemTime_setTime_JS_API_0200 setTime throw_err' + JSON.stringify(err))
expect(err.code).assertEqual('401');
done();
}
});
/**
* @tc.number SUB_systemTime_setTime_JS_API_0300
* @tc.name Test systemTime.setTime3
* @tc.desc Test systemTime_setTime API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_systemTime_setTime_JS_API_0300', 0, async function (done) {
console.info("====>SUB_systemTime_setTime_JS_API_0300 start");
let currentTime = new Date().getTime() + 2000
await systemTime.setTime(currentTime).then(() => {
console.info('====>SUB_systemTime_setTime_JS_API_0300 success')
expect(true).assertTrue();
done();
}).catch((err)=>{
console.debug('====>SUB_systemTime_setTime_JS_API_0300 setTime fail:' + JSON.stringify(err))
expect().assertFail();
done();
})
console.info("====>SUB_systemTime_setTime_JS_API_0300 end");
}); });
/** /**
* @tc.number SUB_systemTime_setTime_JS_API_0400 * @tc.number SUB_systemTime_getDate_JS_API_0200
* @tc.name Test systemTime.setTime4 Invalid value * @tc.name Test systemTime.getDate true value
* @tc.desc Test systemTime_setTime API functionality. * @tc.desc Test systemTime_getDate API functionality.
* @tc.size : MEDIUM * @tc.size : MEDIUM
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_systemTime_setTime_JS_API_0400', 0, async function (done) { it('SUB_systemTime_getDate_JS_API_0200', 0, async function (done) {
console.info("====>SUB_systemTime_setTime_JS_API_0400 start"); console.info("====>SUB_systemTime_getDate_JS_API_0200 start");
try{ try {
systemTime.setTime(18, (err, data) => { let data = await systemTime.getDate();
console.info("====>SUB_systemTime_setTime_JS_API_0400 data: " + data); console.info("====>SUB_systemTime_getDate_JS_API_0200 getDate: " + JSON.stringify(data));
console.info("====>SUB_systemTime_setTime_JS_API_0400 error: " + err); console.info("====>SUB_systemTime_getDate_JS_API_0200 getDate: " + typeof(data));
console.info('====>SUB_systemTime_setTime_JS_API_0400 end'); expect(typeof(data) === "object").assertTrue();
expect(true).assertTrue();
done();
})
}catch(err) {
expect().assertFail();
done(); done();
}; } catch (err) {
}); console.info("====>SUB_systemTime_getDate_JS_API_0200 catch error " + JSON.stringify(err));
/**
* @tc.number SUB_systemTime_setDate_JS_API_0200
* @tc.name Test systemTime.setDate Invalid value
* @tc.desc Test systemTime_setDate API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_systemTime_setDate_JS_API_0200', 0, async function (done) {
console.info("====>SUB_systemTime_setDate_JS_API_0200 start");
systemTime.setDate(0).then(data => {
console.info("====>SUB_systemTime_setDate_JS_API_0200 data " + data);
expect().assertFail(); expect().assertFail();
done(); done();
}).catch(error => { }
console.info("====>SUB_systemTime_setDate_JS_API_0200 error " + error);
expect(true).assertTrue();
done();
});
}); });
/** /**
* @tc.number SUB_systemTime_setDate_JS_API_0400 * @tc.number SUB_systemTime_getTimezone_JS_API_0100
* @tc.name Test systemTime.setDate true value * @tc.name Test systemTime.getTimezone true value
* @tc.desc Test systemTime_setDate API functionality. * @tc.desc Test systemTime_getTimezone API functionality.
* @tc.size : MEDIUM * @tc.size : MEDIUM
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_systemTime_setDate_JS_API_0400', 0, async function (done) { it('SUB_systemTime_getTimezone_JS_API_0100', 0, async function (done) {
console.info("====>SUB_systemTime_setDate_JS_API_0400 start"); console.info("====>SUB_systemTime_getTimezone_JS_API_0100 start");
let date = new Date("Tue Oct 13 2020 11:13:00 GMT+0800"); systemTime.getTimezone((error, data) => {
systemTime.setDate(date, (error, data) => {
try { try {
if(error){ if(error){
console.info("====>SUB_systemTime_setDate_JS_API_0400 setDate fail: " + JSON.stringify(error)); console.info("====>SUB_systemTime_getTimezone_JS_API_0100 getTimezone fail: " + JSON.stringify(error));
expect().assertFail(); expect().assertFail();
done(); done();
} }
systemTime.getDate().then(async (data) => { console.info("====>SUB_systemTime_getTimezone_JS_API_0100 getTimezone: " + JSON.stringify(data));
try { console.info("====>SUB_systemTime_getTimezone_JS_API_0100 getTimezone: " + typeof(data));
console.info("====>SUB_systemTime_setDate_JS_API_0400 getDate: " + data); expect(typeof(data) === "string").assertTrue();
console.info("====>SUB_systemTime_setDate_JS_API_0400 setTime: " + dates); done();
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) { } catch (err) {
console.info("====>SUB_systemTime_setDate_JS_API_0400 catch error " + JSON.stringify(err)); console.info("====>SUB_systemTime_getTimezone_JS_API_0100 catch error " + JSON.stringify(err));
done(); done();
} }
}); });
}); });
/** /**
* @tc.number SUB_systemTime_setDate_JS_API_0500 * @tc.number SUB_systemTime_getTimezone_JS_API_0200
* @tc.name Test systemTime.setDate true value * @tc.name Test systemTime.getTimezone true value
* @tc.desc Test systemTime_setDate API functionality. * @tc.desc Test systemTime_getTimezone 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 date = new Date("Tue Oct 13 2020 11:13:00 GMT+0800");
await systemTime.setDate(date).then( () => {
console.info("====>SUB_systemTime_setDate_JS_API_0500 successful ");
systemTime.getDate().then(async data => {
try {
console.info("====>SUB_systemTime_setDate_JS_API_0500 getDate: " + data);
console.info("====>SUB_systemTime_setDate_JS_API_0500 setTime: " + dates);
console.info("====>SUB_systemTime_setDate_JS_API_0500 getDate: " + JSON.stringify(data).slice(1,17));
expect(JSON.stringify(data).slice(1,17) == '2020-10-13T03:13').assertTrue();
await systemTime.setTime(dates + 1000)
done();
} catch (err) {
console.info("====>SUB_systemTime_setDate_JS_API_0500 catch err: " + err);
done();
}
})
}).catch(error => {
console.info("====>SUB_systemTime_setDate_JS_API_0500 setDate fail: " + JSON.stringify(error));
expect().assertFail();
done();
});
});
/**
* @tc.number SUB_systemTime_setTimezone_JS_API_0100
* @tc.name Test systemTime.setTimezone Invalid value
* @tc.desc Test systemTime_setTimezone API functionality.
* @tc.size : MEDIUM * @tc.size : MEDIUM
* @tc.type : Function * @tc.type : Function
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
it('SUB_systemTime_setTimezone_JS_API_0100', 0, async function (done) { it('SUB_systemTime_getTimezone_JS_API_0200', 0, async function (done) {
console.info("====>SUB_systemTime_setTimezone_JS_API_0100 start"); console.info("====>SUB_systemTime_getTimezone_JS_API_0200 start");
systemTime.setTimezone('Asia, Shanghai').then(data => { try {
console.info("====>SUB_systemTime_setTimezone_JS_API_0100 data " + data); let data = await systemTime.getTimezone();
expect().assertFail(); console.info("====>SUB_systemTime_getTimezone_JS_API_0200 getTimezone: " + JSON.stringify(data));
console.info("====>SUB_systemTime_getTimezone_JS_API_0200 getTimezone: " + typeof(data));
expect(typeof(data) === "string").assertTrue();
done(); done();
}).catch(error => { } catch (err) {
console.info("====>SUB_systemTime_setTimezone_JS_API_0100 error " + error); console.info("====>SUB_systemTime_getTimezone_JS_API_0200 catch error " + JSON.stringify(err));
expect(true).assertTrue();
done();
});
});
/**
* @tc.number SUB_systemTime_setTimezone_JS_API_0200
* @tc.name Test systemTime.setTimezone Invalid value
* @tc.desc Test systemTime_setTimezone API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_systemTime_setTimezone_JS_API_0200', 0, async function (done) {
console.info("====>SUB_systemTime_setTimezone_JS_API_0200 start");
systemTime.setTimezone('Beijing,China').then(data => {
console.info("====>SUB_systemTime_setTimezone_JS_API_0200 data " + data);
expect().assertFail();
done();
}).catch(error => {
console.info("====>SUB_systemTime_setTimezone_JS_API_0200 error " + error);
expect(true).assertTrue();
done();
});
});
/**
* @tc.number SUB_systemTime_setTimezone_JS_API_0300
* @tc.name Test systemTime.setTimezone Invalid value
* @tc.desc Test systemTime_setTimezone API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_systemTime_setTimezone_JS_API_0300', 0, async function (done) {
console.info("====>SUB_systemTime_setTimezone_JS_API_0300 start");
systemTime.setTimezone('Baker Island, U.S.A.').then(data => {
console.info("====>SUB_systemTime_setTimezone_JS_API_0300 data " + data);
expect().assertFail(); expect().assertFail();
done(); 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();
};
});
}); });
}; };
// @ts-nocheck
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
import systemTime from "@ohos.systemTime";
export default function systemTimeNoPermissionJsunit() {
describe('systemTimeNoPermissionTest', function () {
console.info('====>---------------systemTimeNNoPermissionTest start-----------------------');
/**
* @tc.number SUB_Misc_systemTime_NoPermission_setTime_0010
* @tc.name Test systemTime.setTime
* @tc.desc Test systemTime_setTime API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_Misc_systemTime_NoPermission_setTime_0010', 0, async function (done) {
console.info("====>SUB_Misc_systemTime_NoPermission_setTime_0010 start");
let currentTime = new Date().getTime() + 2000
systemTime.setTime(currentTime, (err, data) => {
try{
if(err){
console.info("====>SUB_Misc_systemTime_NoPermission_setTime_0010 setTime permission fail: " + JSON.stringify(err));
expect(err.code).assertEqual(-1);
done();
}else{
console.info('====>SUB_Misc_systemTime_NoPermission_setTime_0010 success: ' + data);
expect().assertFail();
done();
}
}catch(err){
console.error("====>SUB_Misc_systemTime_NoPermission_setTime_0010 catch err: " + JSON.stringify(err));
done();
console.info("====>SUB_Misc_systemTime_NoPermission_setTime_0010 end");
}
});
});
/**
* @tc.number SUB_Misc_systemTime_NoPermission_setTime_0020
* @tc.name Test systemTime.setTime Invalid value
* @tc.desc Test systemTime_setTime API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_Misc_systemTime_NoPermission_setTime_0020', 0, async function (done) {
console.info("====>SUB_Misc_systemTime_NoPermission_setTime_0020 start");
try{
console.info('====>SUB_Misc_systemTime_NoPermission_setTime_0020 setTime permission fail')
let currentTime = new Date().getTime() + 2000
await systemTime.setTime(currentTime);
expect().assertFail();
done();
}catch(err){
console.error('====>SUB_Misc_systemTime_NoPermission_setTime_0020 setTime catch err' + JSON.stringify(err))
expect(err.code).assertEqual(-1);
expect(err.message).assertContain("permission denied");
done();
console.info("====>SUB_Misc_systemTime_NoPermission_setTime_0020 end");
}
});
/**
* @tc.number SUB_Misc_systemTime_NoPermission_setDate_0010
* @tc.name Test systemTime.setDate Invalid value
* @tc.desc Test systemTime_setDate API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_Misc_systemTime_NoPermission_setDate_0010', 0, async function (done) {
console.info("====>SUB_Misc_systemTime_NoPermission_setDate_0010 start");
let date = new Date("Tue Oct 13 2020 11:13:00 GMT+0800");
systemTime.setDate(date, (err, data) => {
try{
if(err){
console.info("====>SUB_Misc_systemTime_NoPermission_setDate_0010 setTime permission fail: " + JSON.stringify(err));
expect(err.code).assertEqual(-1);
done();
}else{
console.info('====>SUB_Misc_systemTime_NoPermission_setDate_0010 success: ' + data);
expect().assertFail();
done();
}
}catch(err){
console.error("====>SUB_Misc_systemTime_NoPermission_setDate_0010 catch err: " + JSON.stringify(err));
done();
console.info("====>SUB_Misc_systemTime_NoPermission_setDate_0010 end");
}
});
});
/**
* @tc.number SUB_Misc_systemTime_NoPermission_setDate_0020
* @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_Misc_systemTime_NoPermission_setDate_0020', 0, async function (done) {
console.info("====>SUB_Misc_systemTime_NoPermission_setDate_0020 start");
try{
console.debug('====>SUB_Misc_systemTime_NoPermission_setDate_0020 setTime permission fail')
let date = new Date("Tue Oct 13 2020 11:13:00 GMT+0800");
await systemTime.setDate(date)
expect().assertFail();
done();
}catch(err){
console.error('====>SUB_Misc_systemTime_NoPermission_setDate_0020 setTime catch err: ' + JSON.stringify(err))
expect(err.code).assertEqual(-1);
expect(err.message).assertContain("permission denied");
done();
console.info("====>SUB_Misc_systemTime_NoPermission_setDate_0020 end");
}
});
/**
* @tc.number SUB_Misc_systemTime_NoPermission_setTimezone_0010
* @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_Misc_systemTime_NoPermission_setTimezone_0010', 0, function (done) {
console.info("====>SUB_Misc_systemTime_NoPermission_setTimezone_0010 start");
systemTime.setTimezone('Asia/Jakarta', (err, data) => {
try{
if(err){
console.info("====>SUB_Misc_systemTime_NoPermission_setTimezone_0010 setTime permission fail: " + JSON.stringify(err));
expect(err.code).assertEqual(-1);
done();
}else{
console.info('====>SUB_Misc_systemTime_NoPermission_setTimezone_0010 success: ' + data);
expect().assertFail();
done();
}
}catch(err){
console.error("====>SUB_Misc_systemTime_NoPermission_setTimezone_0010 catch error: " + JSON.stringify(err));
done();
console.info("====>SUB_Misc_systemTime_NoPermission_setTimezone_0010 end");
}
});
});
/**
* @tc.number SUB_Misc_systemTime_NoPermission_setTimezone_0020
* @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_Misc_systemTime_NoPermission_setTimezone_0020', 0, async function (done) {
console.info("====>SUB_Misc_systemTime_NoPermission_setTimezone_0020 start");
try{
console.debug('====>SUB_Misc_systemTime_NoPermission_setTimezone_0020 setTime permission fail')
await systemTime.setTimezone('Europe/Moscow')
expect().assertFail();
done();
}catch(err){
console.error('====>SUB_Misc_systemTime_NoPermission_setTimezone_0020 setTime catch err: ' + JSON.stringify(err))
expect(err.code).assertEqual(-1);
expect(err.message).assertContain("permission denied");
done();
console.info("====>SUB_Misc_systemTime_NoPermission_setTimezone_0020 end");
}
});
});
};
\ No newline at end of file
...@@ -7,8 +7,7 @@ ...@@ -7,8 +7,7 @@
"mainElement": "MainAbility", "mainElement": "MainAbility",
"deviceTypes": [ "deviceTypes": [
"tablet", "tablet",
"default", "default"
"phone"
], ],
"deliveryWithInstall": true, "deliveryWithInstall": true,
"installationFree": false, "installationFree": false,
...@@ -40,16 +39,6 @@ ...@@ -40,16 +39,6 @@
} }
] ]
} }
],
"requestPermissions": [
{
"name":"ohos.permission.SET_TIME",
"reason":"need use ohos.permission.SET_TIME."
},
{
"name":"ohos.permission.SET_TIME_ZONE",
"reason":"need use ohos.permission.SET_TIME_ZONE."
}
] ]
} }
} }
\ No newline at end of file
{
"app": {
"bundleName": "com.acts.timenauthority.test",
"vendor": "hw",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"distributedNotificationEnabled": true,
"keepAlive":true,
"singleUser":true,
"minAPIVersion":9,
"targetAPIVersion":9
}
}
{
"string": [
{
"name": "app_name",
"value": "ActsTimeAuthorityAPITest"
}
]
}
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsTimeAuthorityAPITest") {
deps = [
":time_assets",
":time_resources",
]
ets2abc = true
js_build_mode = "debug"
subsystem_name = "time"
part_name = "time_service"
hap_name = "ActsTimeAuthorityAPITest"
hap_profile = "entry/src/main/module.json"
certificate_profile = "signature/ActsTimeAuthorityAPITest.p7b"
}
ohos_app_scope("time_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("time_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("time_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":time_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "180000",
"bundle-name": "com.acts.timenauthority.test",
"module-name": "entry_test",
"shell-timeout": "180000",
"testcase-timeout": 600000
},
"kits": [{
"test-file-name": [
"ActsTimeAuthorityAPITest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}]
}
import hilog from '@ohos.hilog';
import AbilityStage from "@ohos.app.ability.AbilityStage";
export default class MyAbilityStage extends AbilityStage {
onCreate() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'AbilityStage onCreate');
}
}
\ No newline at end of file
import hilog from '@ohos.hilog';
import Window from '@ohos.window';
import { Hypium } from '@ohos/hypium';
import testsuite from '../test/List.test';
import Ability from '@ohos.app.ability.UIAbility';
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry';
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:' + JSON.stringify(launchParam) ?? '');
var abilityDelegator: any;
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
var abilityDelegatorArguments: any;
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments();
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
if (abilityDelegator != undefined && abilityDelegatorArguments != undefined) {
hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite);
} else {
hilog.info(0x0000, 'testTag', '%{public}s', 'abilityDelegator or abilityDelegatorArguments is undefined!!!');
}
}
onDestroy() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
}
onWindowStageCreate(windowStage: Window.WindowStage) {
// Main window is created, set main page for this ability
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/index', (err, data) => {
if (err.code) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.ERROR);
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
});
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
}
onForeground() {
// Ability has brought to foreground
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
}
onBackground() {
// Ability has back to background
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
}
}
import hilog from '@ohos.hilog';
import TestRunner from '@ohos.application.testRunner';
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry';
var abilityDelegator = undefined;
var abilityDelegatorArguments = undefined;
function translateParamsToString(parameters) {
const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s it',
'-s level', '-s testType', '-s size', '-s timeout',
'-s dryRun'
]);
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
targetParams = `${targetParams} ${key} ${parameters[key]}`;
}
}
return targetParams.trim();
}
async function onAbilityCreateCallback() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
}
async function addAbilityMonitorCallback(err: any) {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ');
}
async onRun() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run');
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments();
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
var testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility';
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback);
var cmd = 'aa start -d 0 -a MainAbility ' + ' -b ' + abilityDelegatorArguments.bundleName;
cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters);
var debug = abilityDelegatorArguments.parameters['-D'];
if (debug == 'true')
{
cmd += ' -D';
}
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd);
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? '');
});
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');
}
}
\ No newline at end of file
// @ts-nocheck
/**
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import hilog from '@ohos.hilog';
@Entry
@Component
struct Index {
aboutToAppear() {
hilog.isLoggable(0x0000, 'testTag', hilog.LogLevel.INFO);
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear');
}
@State message: string = 'TIME ETS TEST'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import systemTimeAuthorityJsunit from './timeAuthority.test';
import systemTimeCommonEventTest from './systemTimeCommonEvent.test';
export default function testsuite() {
systemTimeAuthorityJsunit();
systemTimeCommonEventTest();
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
import systemTime from "@ohos.systemTime";
import commonEvent from '@ohos.commonEvent'
export default function systemTimeCommonEventTest() {
describe('systemTimeCommonEventTest', function () {
console.info('====>---------------systemTimeCommonEventTest start-----------------------');
/**
* @tc.number SUB_systemTime_commonEnevt_timeChanged_0010
* @tc.name
* @tc.desc
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 3
*/
it('SUB_systemTime_commonEvent_timeChanged_0010', 0, async function (done) {
function unSubscriberCallback (err){
console.debug("====>SUB_systemTime_commonEvent_timeChanged_0010 unSubscriberCallback start");
if (err){
console.debug("====>SUB_systemTime_commonEvent_timeChanged_0010 unSubscriberCallback failed:" +
JSON.stringify(err));
} else {
console.debug("====>SUB_systemTime_commonEvent_timeChanged_0010 unSubscriberCallback finish")
}
}
function subscriberCallback (err, data){
console.debug("====>SUB_systemTime_commonEvent_timeChanged_0010 subscriberCallback data:"
+ JSON.stringify(data));
commonEvent.unsubscribe(subscriber, unSubscriberCallback);
expect(data.event).assertEqual('usual.event.TIME_CHANGED');
console.debug("====>SUB_systemTime_commonEvent_timeChanged_0010 end")
done();
}
var commonEventSubscribeInfo = {
events: ['usual.event.TIME_CHANGED']
}
var subscriber;
commonEvent.createSubscriber(commonEventSubscribeInfo).then((data)=>{
subscriber = data;
console.debug("====>SUB_systemTime_commonEvent_timeChanged_0010 subscriber data:" + JSON.stringify(data))
commonEvent.subscribe(subscriber, subscriberCallback);
console.debug("====>SUB_systemTime_commonEvent_timeChanged_0010 subscriber finish")
let t = setTimeout(async ()=>{
let currentTime= new Date().getTime() + 1500
await systemTime.setTime(currentTime)
clearTimeout(t)
}, 500)
})
});
/**
* @tc.number SUB_systemTime_commonEvent_timeTick_0010
* @tc.name
* @tc.desc
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 3
*/
it('SUB_systemTime_commonEvent_timeTick_0010', 0, async function (done) {
function unSubscriberCallback (err){
console.debug("====>SUB_systemTime_commonEvent_timeTick_0010 unSubscriberCallback start");
if (err){
console.debug("====>SUB_systemTime_commonEvent_timeTick_0010 unSubscriberCallback failed:" +
JSON.stringify(err));
} else {
console.debug("====>SUB_systemTime_commonEvent_timeTick_0010 unSubscriberCallback finish")
}
}
function subscriberCallback (err, data){
console.debug("====>SUB_systemTime_commonEvent_timeTick_0010 subscriberCallback data:"
+ JSON.stringify(data));
commonEvent.unsubscribe(subscriber, unSubscriberCallback);
expect(data.event).assertEqual('usual.event.TIME_TICK');
console.debug("====>SUB_systemTime_commonEnevt_timeTick_0010 end")
done();
}
var commonEventSubscribeInfo = {
events: ['usual.event.TIME_TICK']
}
var subscriber;
commonEvent.createSubscriber(commonEventSubscribeInfo).then((data)=>{
subscriber = data;
console.debug("====>SUB_systemTime_commonEvent_timeTick_0010 subscriber data:" + JSON.stringify(data))
commonEvent.subscribe(subscriber, subscriberCallback);
console.debug("====>SUB_systemTime_commonEvent_timeTick_0010 subscriber finish")
let t = setTimeout(async ()=>{
let currentTime= new Date().getTime()
currentTime = currentTime + (58000- (currentTime % 60000))
await systemTime.setTime(currentTime)
clearTimeout(t)
}, 500)
})
});
/**
* @tc.number SUB_systemTime_commonEvent_timezoneChanged_0010
* @tc.name
* @tc.desc
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 3
*/
it('SUB_systemTime_commonEvent_timezoneChanged_0010', 0, async function (done) {
function unSubscriberCallback (err){
console.debug("====>SUB_systemTime_commonEvent_timezoneChanged_0010 unSubscriberCallback start");
if (err){
console.debug("====>SUB_systemTime_commonEvent_timezoneChanged_0010 unSubscriberCallback failed:" +
JSON.stringify(err));
} else {
console.debug("====>SUB_systemTime_commonEvent_timezoneChanged_0010 unSubscriberCallback finish")
}
}
function subscriberCallback (err, data){
console.debug("====>SUB_systemTime_commonEvent_timezoneChanged_0010 subscriberCallback data:"
+ JSON.stringify(data));
commonEvent.unsubscribe(subscriber, unSubscriberCallback);
expect(data.event).assertEqual('usual.event.TIMEZONE_CHANGED');
console.debug("====>SUB_systemTime_commonEvent_timezoneChanged_0010 end")
done();
}
var commonEventSubscribeInfo = {
events: ['usual.event.TIMEZONE_CHANGED']
}
var subscriber;
commonEvent.createSubscriber(commonEventSubscribeInfo).then((data)=>{
subscriber = data;
console.debug("====>SUB_systemTime_commonEvent_timezoneChanged_0010 subscriber data:" + JSON.stringify(data))
commonEvent.subscribe(subscriber, subscriberCallback);
console.debug("====>SUB_systemTime_commonEvent_timezoneChanged_0010 subscriber finish")
let t = setTimeout(async ()=>{
await systemTime.setTimezone('Europe/Moscow')
clearTimeout(t)
}, 500)
})
});
});
};
// @ts-nocheck
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
import systemTime from "@ohos.systemTime";
export default function systemTimeAuthorityJsunit() {
describe('systemTimeAuthorityTest', function () {
console.info('====>---------------systemTimeAuthorityTest 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_setTime_JS_API_0100
* @tc.name Test systemTime.setTime
* @tc.desc Test systemTime_setTime API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_systemTime_setTime_JS_API_0100', 0, async function (done) {
console.info("====>SUB_systemTime_setTime_JS_API_0100 start");
let currentTime = new Date().getTime() + 2000
systemTime.setTime(currentTime, (err, data) => {
try{
if(err){
console.info("====>SUB_systemTime_setTime_JS_API_0100 setTime fail: " + JSON.stringify(err));
expect().assertFail();
done();
}
console.info('====>SUB_systemTime_setTime_JS_API_0100 success: ' + data);
expect(true).assertTrue();
done();
}catch(err){
console.info("====>SUB_systemTime_setTime_JS_API_0100 catch error: " + JSON.stringify(err));
done();
}
});
console.info("====>SUB_systemTime_setTime_JS_API_0100 end");
});
/**
* @tc.number SUB_systemTime_setTime_JS_API_0200
* @tc.name Test systemTime.setTime Invalid value
* @tc.desc Test systemTime_setTime API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_systemTime_setTime_JS_API_0200', 0, async function (done) {
console.info("====>SUB_systemTime_setTime_JS_API_0200 start");
try{
systemTime.setTime(15222).then(() => {
console.debug('====>SUB_systemTime_setTime_JS_API_0200 setTime fail')
expect().assertFail();
done();
}).catch((err)=>{
console.debug('====>SUB_systemTime_setTime_JS_API_0200 setTime err:' + JSON.stringify(err))
expect(true).assertTrue();
console.debug('====>SUB_systemTime_setTime_JS_API_0200 end');
done();
})
}catch(err){
console.debug('====>SUB_systemTime_setTime_JS_API_0200 setTime throw_err' + JSON.stringify(err))
expect(err.code).assertEqual('401');
done();
}
});
/**
* @tc.number SUB_systemTime_setTime_JS_API_0300
* @tc.name Test systemTime.setTime3
* @tc.desc Test systemTime_setTime API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_systemTime_setTime_JS_API_0300', 0, async function (done) {
console.info("====>SUB_systemTime_setTime_JS_API_0300 start");
let currentTime = new Date().getTime() + 2000
await systemTime.setTime(currentTime).then(() => {
console.info('====>SUB_systemTime_setTime_JS_API_0300 success')
expect(true).assertTrue();
done();
}).catch((err)=>{
console.debug('====>SUB_systemTime_setTime_JS_API_0300 setTime fail:' + JSON.stringify(err))
expect().assertFail();
done();
})
console.info("====>SUB_systemTime_setTime_JS_API_0300 end");
});
/**
* @tc.number SUB_systemTime_setTime_JS_API_0400
* @tc.name Test systemTime.setTime4 Invalid value
* @tc.desc Test systemTime_setTime API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_systemTime_setTime_JS_API_0400', 0, async function (done) {
console.info("====>SUB_systemTime_setTime_JS_API_0400 start");
try{
systemTime.setTime(18, (err, data) => {
console.info("====>SUB_systemTime_setTime_JS_API_0400 data: " + data);
console.info("====>SUB_systemTime_setTime_JS_API_0400 error: " + err);
console.info('====>SUB_systemTime_setTime_JS_API_0400 end');
expect(true).assertTrue();
done();
})
}catch(err) {
expect().assertFail();
done();
};
});
/**
* @tc.number SUB_systemTime_setDate_JS_API_0200
* @tc.name Test systemTime.setDate Invalid value
* @tc.desc Test systemTime_setDate API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_systemTime_setDate_JS_API_0200', 0, async function (done) {
console.info("====>SUB_systemTime_setDate_JS_API_0200 start");
systemTime.setDate(0).then(data => {
console.info("====>SUB_systemTime_setDate_JS_API_0200 data " + data);
expect().assertFail();
done();
}).catch(error => {
console.info("====>SUB_systemTime_setDate_JS_API_0200 error " + error);
expect(true).assertTrue();
done();
});
});
/**
* @tc.number SUB_systemTime_setDate_JS_API_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 date = new Date("Tue Oct 13 2020 11:13:00 GMT+0800");
systemTime.setDate(date, (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 date = new Date("Tue Oct 13 2020 11:13:00 GMT+0800");
await systemTime.setDate(date).then( () => {
console.info("====>SUB_systemTime_setDate_JS_API_0500 successful ");
systemTime.getDate().then(async data => {
try {
console.info("====>SUB_systemTime_setDate_JS_API_0500 getDate: " + data);
console.info("====>SUB_systemTime_setDate_JS_API_0500 setTime: " + dates);
console.info("====>SUB_systemTime_setDate_JS_API_0500 getDate: " + JSON.stringify(data).slice(1,17));
expect(JSON.stringify(data).slice(1,17) == '2020-10-13T03:13').assertTrue();
await systemTime.setTime(dates + 1000)
done();
} catch (err) {
console.info("====>SUB_systemTime_setDate_JS_API_0500 catch err: " + err);
done();
}
})
}).catch(error => {
console.info("====>SUB_systemTime_setDate_JS_API_0500 setDate fail: " + JSON.stringify(error));
expect().assertFail();
done();
});
});
/**
* @tc.number SUB_systemTime_setTimezone_JS_API_0100
* @tc.name Test systemTime.setTimezone Invalid value
* @tc.desc Test systemTime_setTimezone API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_systemTime_setTimezone_JS_API_0100', 0, async function (done) {
console.info("====>SUB_systemTime_setTimezone_JS_API_0100 start");
systemTime.setTimezone('Asia, Shanghai').then(data => {
console.info("====>SUB_systemTime_setTimezone_JS_API_0100 data " + data);
expect().assertFail();
done();
}).catch(error => {
console.info("====>SUB_systemTime_setTimezone_JS_API_0100 error " + error);
expect(true).assertTrue();
done();
});
});
/**
* @tc.number SUB_systemTime_setTimezone_JS_API_0200
* @tc.name Test systemTime.setTimezone Invalid value
* @tc.desc Test systemTime_setTimezone API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_systemTime_setTimezone_JS_API_0200', 0, async function (done) {
console.info("====>SUB_systemTime_setTimezone_JS_API_0200 start");
systemTime.setTimezone('Beijing,China').then(data => {
console.info("====>SUB_systemTime_setTimezone_JS_API_0200 data " + data);
expect().assertFail();
done();
}).catch(error => {
console.info("====>SUB_systemTime_setTimezone_JS_API_0200 error " + error);
expect(true).assertTrue();
done();
});
});
/**
* @tc.number SUB_systemTime_setTimezone_JS_API_0300
* @tc.name Test systemTime.setTimezone Invalid value
* @tc.desc Test systemTime_setTimezone API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_systemTime_setTimezone_JS_API_0300', 0, async function (done) {
console.info("====>SUB_systemTime_setTimezone_JS_API_0300 start");
systemTime.setTimezone('Baker Island, U.S.A.').then(data => {
console.info("====>SUB_systemTime_setTimezone_JS_API_0300 data " + data);
expect().assertFail();
done();
}).catch(error => {
console.info("====>SUB_systemTime_setTimezone_JS_API_0300 error " + error);
expect(true).assertTrue();
done();
});
});
/**
* @tc.number SUB_systemTime_setTimezone_JS_API_0400
* @tc.name Test systemTime.setTimezone true value
* @tc.desc Test systemTime_setTimezone API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 0
*/
it('SUB_systemTime_setTimezone_JS_API_0400', 0, function (done) {
console.info("====>SUB_systemTime_setTimezone_JS_API_0400 start");
systemTime.setTimezone('Asia/Jakarta',async (err) => {
try{
if(err){
console.info("====>SUB_systemTime_setTimezone_JS_API_0400 setTimezone fail: " + JSON.stringify(err));
expect().assertFail();
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();
};
});
});
};
{
"module": {
"name": "entry_test",
"type": "entry",
"srcEntrance": "./ets/Application/MyAbilityStage.ts",
"description": "$string:entry_desc",
"mainElement": "MainAbility",
"deviceTypes": [
"tablet",
"default"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"metadata": [
{
"name": "ArkTSPartialUpdate",
"value": "false"
}
],
"abilities": [
{
"name": "MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:MainAbility_desc",
"icon": "$media:icon",
"label": "$string:MainAbility_label",
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:white",
"visible": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
}
],
"requestPermissions": [
{
"name":"ohos.permission.SET_TIME",
"reason":"need use ohos.permission.SET_TIME."
},
{
"name":"ohos.permission.SET_TIME_ZONE",
"reason":"need use ohos.permission.SET_TIME_ZONE."
}
]
}
}
\ No newline at end of file
{
"color": [
{
"name": "white",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "entry_desc",
"value": "description"
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "ActsTimeAuthorityAPITest"
}
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册