diff --git a/request/RequestTest_Stage/signature/actsRequestStageTest.p7b b/request/RequestTest_Stage/signature/actsRequestStageTest.p7b index ddafda90ca473d3c2ccba130ce913b65736dbe6e..7fae19c6741e61d78f517879d3f67511ce818b28 100644 Binary files a/request/RequestTest_Stage/signature/actsRequestStageTest.p7b and b/request/RequestTest_Stage/signature/actsRequestStageTest.p7b differ diff --git a/request/RequestTest_ets/signature/ActsRequestETSApiTest.p7b b/request/RequestTest_ets/signature/ActsRequestETSApiTest.p7b index 195dba074b7a27be36d9759719a6d074afa3d5f5..abc9839b9ce3d8445cf5d2cdba41f7e330f93da4 100644 Binary files a/request/RequestTest_ets/signature/ActsRequestETSApiTest.p7b and b/request/RequestTest_ets/signature/ActsRequestETSApiTest.p7b differ diff --git a/time/BUILD.gn b/time/BUILD.gn index cf1161ba135ee9c2e941f4173b24607f6e80446b..a3240b5654d0c1f504e8f1261cb4213fdbc70df3 100644 --- a/time/BUILD.gn +++ b/time/BUILD.gn @@ -17,5 +17,6 @@ group("time") { deps = [ "dateTimeTest:ActsDateTimeAPITest", "timeTest:ActsTimeAPITest", + "timeauthorityTest:ActsTimeAuthorityAPITest", ] } diff --git a/time/dateTimeTest/signature/ActsDateTimeAPITest.p7b b/time/dateTimeTest/signature/ActsDateTimeAPITest.p7b index 20a967239492a1f648da7f57a3afe85c0bc2a92a..b4b377cc7f0865d99cce1d2bb0e36591541c57c2 100644 Binary files a/time/dateTimeTest/signature/ActsDateTimeAPITest.p7b and b/time/dateTimeTest/signature/ActsDateTimeAPITest.p7b differ diff --git a/time/timeTest/Test.json b/time/timeTest/Test.json index 0e91ba878d1edb68beda4b9ebcc32158bbd561bd..fbe350a09fdba066aeac1eb7b9077d1753c3e41e 100644 --- a/time/timeTest/Test.json +++ b/time/timeTest/Test.json @@ -5,8 +5,7 @@ "test-timeout": "180000", "bundle-name": "com.acts.time.test", "module-name": "entry_test", - "shell-timeout": "180000", - "testcase-timeout": 600000 + "shell-timeout": "180000" }, "kits": [{ "test-file-name": [ diff --git a/time/timeTest/entry/src/main/ets/test/List.test.ets b/time/timeTest/entry/src/main/ets/test/List.test.ets index 37b99442f5f03e091cfbdfa2f64f6bcea7fb6cfc..66ced2dadb5fea0ae1f5fdc868351c3336a73305 100644 --- a/time/timeTest/entry/src/main/ets/test/List.test.ets +++ b/time/timeTest/entry/src/main/ets/test/List.test.ets @@ -13,9 +13,9 @@ * limitations under the License. */ import systemTimeJsunit from './systemTimeTest'; -import systemTimeCommonEventTest from './systemTimeCommonEvent.test' +import systemTimeNoPermissionTest from './timeNoPermission.test' export default function testsuite() { systemTimeJsunit(); - systemTimeCommonEventTest(); + systemTimeNoPermissionTest(); } \ No newline at end of file diff --git a/time/timeTest/entry/src/main/ets/test/systemTimeTest.ets b/time/timeTest/entry/src/main/ets/test/systemTimeTest.ets index 2983a27d0c4df09f1d5277748ad3ab235fd8edc6..68549e735dbe0b98a3565335280be5131e2ed44a 100644 --- a/time/timeTest/entry/src/main/ets/test/systemTimeTest.ets +++ b/time/timeTest/entry/src/main/ets/test/systemTimeTest.ets @@ -20,37 +20,6 @@ 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 @@ -203,339 +172,106 @@ export default function systemTimeJsunit() { }); /** - * @tc.number SUB_systemTime_setTime_JS_API_0100 - * @tc.name Test systemTime.setTime - * @tc.desc Test systemTime_setTime API functionality. + * @tc.number SUB_systemTime_getDate_JS_API_0100 + * @tc.name Test systemTime.getDate true value + * @tc.desc Test systemTime_getDate 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)); + it('SUB_systemTime_getDate_JS_API_0100', 0, async function (done) { + console.info("====>SUB_systemTime_getDate_JS_API_0100 start"); + systemTime.getDate((error, data) => { + try { + if(error){ + console.info("====>SUB_systemTime_getDate_JS_API_0100 getDate fail: " + JSON.stringify(error)); expect().assertFail(); done(); } - console.info('====>SUB_systemTime_setTime_JS_API_0100 success: ' + data); - expect(true).assertTrue(); + console.info("====>SUB_systemTime_getDate_JS_API_0100 getDate: " + JSON.stringify(data)); + console.info("====>SUB_systemTime_getDate_JS_API_0100 getDate: " + typeof(data)); + expect(typeof(data) === "object").assertTrue(); done(); - }catch(err){ - console.info("====>SUB_systemTime_setTime_JS_API_0100 catch error: " + JSON.stringify(err)); + } catch (err) { + console.info("====>SUB_systemTime_getDate_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.number SUB_systemTime_getDate_JS_API_0200 + * @tc.name Test systemTime.getDate true value + * @tc.desc Test systemTime_getDate 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(); + it('SUB_systemTime_getDate_JS_API_0200', 0, async function (done) { + console.info("====>SUB_systemTime_getDate_JS_API_0200 start"); + try { + let data = await systemTime.getDate(); + console.info("====>SUB_systemTime_getDate_JS_API_0200 getDate: " + JSON.stringify(data)); + console.info("====>SUB_systemTime_getDate_JS_API_0200 getDate: " + typeof(data)); + expect(typeof(data) === "object").assertTrue(); done(); - }; - }); - - /** - * @tc.number SUB_systemTime_setDate_JS_API_0200 - * @tc.name Test systemTime.setDate Invalid value - * @tc.desc Test systemTime_setDate API functionality. - * @tc.size : MEDIUM - * @tc.type : Function - * @tc.level : Level 0 - */ - 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); + } catch (err) { + console.info("====>SUB_systemTime_getDate_JS_API_0200 catch error " + JSON.stringify(err)); 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.number SUB_systemTime_getTimezone_JS_API_0100 + * @tc.name Test systemTime.getTimezone true value + * @tc.desc Test systemTime_getTimezone 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) => { + it('SUB_systemTime_getTimezone_JS_API_0100', 0, async function (done) { + console.info("====>SUB_systemTime_getTimezone_JS_API_0100 start"); + systemTime.getTimezone((error, data) => { try { 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(); 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(); - } - }) + console.info("====>SUB_systemTime_getTimezone_JS_API_0100 getTimezone: " + JSON.stringify(data)); + console.info("====>SUB_systemTime_getTimezone_JS_API_0100 getTimezone: " + typeof(data)); + expect(typeof(data) === "string").assertTrue(); + done(); } 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(); } }); }); /** - * @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.number SUB_systemTime_getTimezone_JS_API_0200 + * @tc.name Test systemTime.getTimezone true value + * @tc.desc Test systemTime_getTimezone 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(); + it('SUB_systemTime_getTimezone_JS_API_0200', 0, async function (done) { + console.info("====>SUB_systemTime_getTimezone_JS_API_0200 start"); + try { + let data = await systemTime.getTimezone(); + 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(); - }).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); + } catch (err) { + console.info("====>SUB_systemTime_getTimezone_JS_API_0200 catch error " + JSON.stringify(err)); 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(); - }; - }); }); }; diff --git a/time/timeTest/entry/src/main/ets/test/timeNoPermission.test.ets b/time/timeTest/entry/src/main/ets/test/timeNoPermission.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..dfae0fcd5a16825d3bf5f73ed4558ad8f4586c8a --- /dev/null +++ b/time/timeTest/entry/src/main/ets/test/timeNoPermission.test.ets @@ -0,0 +1,188 @@ +// @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 diff --git a/time/timeTest/entry/src/main/module.json b/time/timeTest/entry/src/main/module.json index 6fe24d93bf4c7dc4fe6e1c9aead29de800b99d0f..2845db4428662ce78666aa0798642212d214e565 100644 --- a/time/timeTest/entry/src/main/module.json +++ b/time/timeTest/entry/src/main/module.json @@ -7,8 +7,7 @@ "mainElement": "MainAbility", "deviceTypes": [ "tablet", - "default", - "phone" + "default" ], "deliveryWithInstall": true, "installationFree": false, @@ -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 diff --git a/time/timeTest/signature/ActsTimeAPITest.p7b b/time/timeTest/signature/ActsTimeAPITest.p7b index e1caf6086a82e9791735e52954e2d5cdc0d40624..9cc5f9273f033b2df9fcdb18ea7d681b18a8ae10 100644 Binary files a/time/timeTest/signature/ActsTimeAPITest.p7b and b/time/timeTest/signature/ActsTimeAPITest.p7b differ diff --git a/time/timeauthorityTest/AppScope/app.json b/time/timeauthorityTest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..536aba0a0d31c35d9d6587a91c1c153263210970 --- /dev/null +++ b/time/timeauthorityTest/AppScope/app.json @@ -0,0 +1,15 @@ +{ + "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 + } +} diff --git a/time/timeauthorityTest/AppScope/resources/base/element/string.json b/time/timeauthorityTest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..488c395f854f6c43ac14efc49d2adb0f92ab3960 --- /dev/null +++ b/time/timeauthorityTest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ActsTimeAuthorityAPITest" + } + ] +} diff --git a/time/timeauthorityTest/AppScope/resources/base/media/app_icon.png b/time/timeauthorityTest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/time/timeauthorityTest/AppScope/resources/base/media/app_icon.png differ diff --git a/time/timeauthorityTest/BUILD.gn b/time/timeauthorityTest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d4fc9a9aaf0293f65b6ddc16d4dc41569b199ca4 --- /dev/null +++ b/time/timeauthorityTest/BUILD.gn @@ -0,0 +1,43 @@ +# 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" +} diff --git a/time/timeauthorityTest/Test.json b/time/timeauthorityTest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..dc1005bd422d2e4a597f9a2b29090ffc7ec3a356 --- /dev/null +++ b/time/timeauthorityTest/Test.json @@ -0,0 +1,18 @@ +{ + "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 + }] +} diff --git a/time/timeauthorityTest/entry/src/main/ets/Application/MyAbilityStage.ts b/time/timeauthorityTest/entry/src/main/ets/Application/MyAbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..82324f4c7fc0c9285ddf1c142cf3a0c2094fc9a3 --- /dev/null +++ b/time/timeauthorityTest/entry/src/main/ets/Application/MyAbilityStage.ts @@ -0,0 +1,9 @@ +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 diff --git a/time/timeauthorityTest/entry/src/main/ets/MainAbility/MainAbility.ts b/time/timeauthorityTest/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..946c1d8885f831d10bf0d4f0835a7dbfd4aa22a3 --- /dev/null +++ b/time/timeauthorityTest/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,66 @@ +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'); + } +} diff --git a/time/timeauthorityTest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/time/timeauthorityTest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..b8d6c3289a436a8d0eb9a0f0c320b5d7ff0ed443 --- /dev/null +++ b/time/timeauthorityTest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,71 @@ +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 diff --git a/time/timeauthorityTest/entry/src/main/ets/pages/index.ets b/time/timeauthorityTest/entry/src/main/ets/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6a23c90b5265a129db7c8cda8bb2e4978f38d386 --- /dev/null +++ b/time/timeauthorityTest/entry/src/main/ets/pages/index.ets @@ -0,0 +1,40 @@ + +// @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 diff --git a/time/timeauthorityTest/entry/src/main/ets/test/List.test.ets b/time/timeauthorityTest/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..ca3029b058906c27fb0292f58e0783d2fde14d41 --- /dev/null +++ b/time/timeauthorityTest/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,21 @@ +/* + * 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 diff --git a/time/timeauthorityTest/entry/src/main/ets/test/systemTimeCommonEvent.test.ets b/time/timeauthorityTest/entry/src/main/ets/test/systemTimeCommonEvent.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..68d4e21c95170ff6585a52aa2d9735f03f3e4aa4 --- /dev/null +++ b/time/timeauthorityTest/entry/src/main/ets/test/systemTimeCommonEvent.test.ets @@ -0,0 +1,162 @@ +/* + * 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) + }) + }); + + + }); +}; diff --git a/time/timeauthorityTest/entry/src/main/ets/test/timeAuthority.test.ets b/time/timeauthorityTest/entry/src/main/ets/test/timeAuthority.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..48932c4e35374c1621b6332069b3f72a6e15cb8c --- /dev/null +++ b/time/timeauthorityTest/entry/src/main/ets/test/timeAuthority.test.ets @@ -0,0 +1,392 @@ + +// @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(); + }; + }); + }); +}; diff --git a/time/timeauthorityTest/entry/src/main/module.json b/time/timeauthorityTest/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..87b537ae9fe409bddf1b28cf31e27c34c6723ae6 --- /dev/null +++ b/time/timeauthorityTest/entry/src/main/module.json @@ -0,0 +1,54 @@ +{ + "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 diff --git a/time/timeauthorityTest/entry/src/main/resources/base/element/color.json b/time/timeauthorityTest/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..62a137a61b90c14f109ed8c81d9d551ea0a5888a --- /dev/null +++ b/time/timeauthorityTest/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/time/timeauthorityTest/entry/src/main/resources/base/element/string.json b/time/timeauthorityTest/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..cbca3dab0000e5025fdc02a6dddb138221250421 --- /dev/null +++ b/time/timeauthorityTest/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_desc", + "value": "description" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "ActsTimeAuthorityAPITest" + } + ] +} \ No newline at end of file diff --git a/time/timeauthorityTest/entry/src/main/resources/base/media/icon.png b/time/timeauthorityTest/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/time/timeauthorityTest/entry/src/main/resources/base/media/icon.png differ diff --git a/time/timeauthorityTest/entry/src/main/resources/base/profile/main_pages.json b/time/timeauthorityTest/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..feec276e105eeb8d621c20aaf838f318b0a94150 --- /dev/null +++ b/time/timeauthorityTest/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/index" + ] +} diff --git a/time/timeauthorityTest/signature/ActsTimeAuthorityAPITest.p7b b/time/timeauthorityTest/signature/ActsTimeAuthorityAPITest.p7b new file mode 100644 index 0000000000000000000000000000000000000000..a31c82526be0eeaf2822991109065a09d59ffd1c Binary files /dev/null and b/time/timeauthorityTest/signature/ActsTimeAuthorityAPITest.p7b differ