diff --git a/time/BUILD.gn b/time/BUILD.gn index 9c1a67e0c20a88c2da86f0d9b3717e2ae88e1b32..cf1161ba135ee9c2e941f4173b24607f6e80446b 100644 --- a/time/BUILD.gn +++ b/time/BUILD.gn @@ -14,5 +14,8 @@ import("//build/ohos_var.gni") group("time") { testonly = true - deps = [ "timeTest:ActsTimeAPITest" ] + deps = [ + "dateTimeTest:ActsDateTimeAPITest", + "timeTest:ActsTimeAPITest", + ] } diff --git a/time/dateTimeTest/AppScope/app.json b/time/dateTimeTest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..800aff1b9946c27c508e090f7fa38631b2b703da --- /dev/null +++ b/time/dateTimeTest/AppScope/app.json @@ -0,0 +1,15 @@ +{ + "app": { + "bundleName": "com.acts.dateTime.test", + "vendor": "huawei", + "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/dateTimeTest/AppScope/resources/base/element/string.json b/time/dateTimeTest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..adc1e65b876deedd62c9ad2f3030bfb2f72eb617 --- /dev/null +++ b/time/dateTimeTest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ActsDateTimeAPITest" + } + ] +} diff --git a/time/dateTimeTest/AppScope/resources/base/media/app_icon.png b/time/dateTimeTest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/time/dateTimeTest/AppScope/resources/base/media/app_icon.png differ diff --git a/time/dateTimeTest/BUILD.gn b/time/dateTimeTest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a505bce458765a01877d9d148e57971228e8c283 --- /dev/null +++ b/time/dateTimeTest/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("ActsDateTimeAPITest") { + deps = [ + ":time_assets", + ":time_resources", + ] + ets2abc = true + js_build_mode = "debug" + subsystem_name = "time" + part_name = "time_service" + hap_name = "ActsDateTimeAPITest" + hap_profile = "entry/src/main/module.json" + certificate_profile = "signature/ActsDateTimeAPITest.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/dateTimeTest/Test.json b/time/dateTimeTest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..ba15d4bd7edfe7253f40fb71e15df0284805ae08 --- /dev/null +++ b/time/dateTimeTest/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "180000", + "bundle-name": "com.acts.dateTime.test", + "module-name": "entry_test", + "shell-timeout": "180000", + "testcase-timeout": 600000 + }, + "kits": [{ + "test-file-name": [ + "ActsDateTimeAPITest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + }] +} diff --git a/time/dateTimeTest/entry/src/main/ets/Application/MyAbilityStage.ts b/time/dateTimeTest/entry/src/main/ets/Application/MyAbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..63c0efb17ceebd35073960da80893eb3040b0426 --- /dev/null +++ b/time/dateTimeTest/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/dateTimeTest/entry/src/main/ets/MainAbility/MainAbility.ts b/time/dateTimeTest/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..946c1d8885f831d10bf0d4f0835a7dbfd4aa22a3 --- /dev/null +++ b/time/dateTimeTest/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/dateTimeTest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/time/dateTimeTest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..127844c9babcbb9d962d798b9d23460ff603d734 --- /dev/null +++ b/time/dateTimeTest/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/dateTimeTest/entry/src/main/ets/pages/index.ets b/time/dateTimeTest/entry/src/main/ets/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6a23c90b5265a129db7c8cda8bb2e4978f38d386 --- /dev/null +++ b/time/dateTimeTest/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/dateTimeTest/entry/src/main/ets/test/List.test.ets b/time/dateTimeTest/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..4e009d9e8e2bd56d76f52884bdc42fdc78e1649f --- /dev/null +++ b/time/dateTimeTest/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,19 @@ +/* + * 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 systemDateTimeJsunit from './systemDateTimeJsunit.test'; + +export default function testsuite() { + systemDateTimeJsunit(); +} \ No newline at end of file diff --git a/time/dateTimeTest/entry/src/main/ets/test/systemDateTimeJsunit.test.ets b/time/dateTimeTest/entry/src/main/ets/test/systemDateTimeJsunit.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..6e8ca22f4f64f862898756563d09c41ed29579b0 --- /dev/null +++ b/time/dateTimeTest/entry/src/main/ets/test/systemDateTimeJsunit.test.ets @@ -0,0 +1,426 @@ +/* + * 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 systemDateTime from "@ohos.systemDateTime"; + +export default function systemDateTimeJsunit() { + describe('systemDateTimeTest', function () { + console.info('====>---------------systemDateTimeTest start-----------------------'); + + /** + * @tc.number SUB_systemDateTime_getCurrentTime_JS_API_0001 + * @tc.name Test systemTimeDate.getCurrentTime + * @tc.desc Obtains the number of milliseconds that have elapsed since the Unix epoch. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it("SUB_systemDateTime_getCurrentTime_JS_API_0001", 0, async function (done) { + console.info("====>----------SUB_systemDateTime_getCurrentTime_JS_API_0001 start----------------"); + systemDateTime.getCurrentTime(true, (error, data) => { + try { + if (error) { + console.error('====>SUB_systemDateTime_getCurrentTime_JS_API_0001 fail: ' + JSON.stringify(error)); + expect().assertFail(); + done(); + }; + console.info('====>systemDateTime.getCurrentTime success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + } catch (error) { + console.error('====>SUB_systemDateTime_getCurrentTime_JS_API_0001 catch error: ' + JSON.stringify(error)); + done(); + } + console.info("====>----------SUB_systemDateTime_getCurrentTime_JS_API_0001 end-----------------"); + }); + }); + + /** + * @tc.number SUB_systemDateTime_getCurrentTime_JS_API_0002 + * @tc.name Test systemTimeDate.getCurrentTime + * @tc.desc Obtains the number of milliseconds that have elapsed since the Unix epoch. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it("SUB_systemDateTime_getCurrentTime_JS_API_0002", 0, async function (done) { + console.info("====>-----SUB_systemDateTime_getCurrentTime_JS_API_0002 start----------------"); + await systemDateTime.getCurrentTime(false).then((data) => { + console.info('====>SUB_systemDateTime_getCurrentTime_JS_API_0002 success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + }).catch(err => { + console.error('====>SUB_systemDateTime_getCurrentTime_JS_API_0002 fail: ' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info("====>-----SUB_systemDateTime_getCurrentTime_JS_API_0002 end------------"); + }); + + /** + * @tc.number SUB_systemDateTime_getCurrentTime_JS_API_0003 + * @tc.name Test systemTimeDate.getCurrentTime + * @tc.desc Obtains the number of milliseconds that have elapsed since the Unix epoch. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it("SUB_systemDateTime_getCurrentTime_JS_API_0003", 0, async function (done) { + console.info("====>-----SUB_systemDateTime_getCurrentTime_JS_API_0003 start----------------"); + await systemDateTime.getCurrentTime().then((data) => { + console.info('====>SUB_systemDateTime_getCurrentTime_JS_API_0003 success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + }).catch(err => { + console.error('====>SUB_systemDateTime_getCurrentTime_JS_API_0003 fail: ' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info("====>-----SUB_systemDateTime_getCurrentTime_JS_API_0003 end------------"); + }); + + /** + * @tc.number SUB_systemDateTime_getCurrentTime_JS_API_0004 + * @tc.name Test systemTimeDate.getCurrentTime + * @tc.desc Obtains the number of milliseconds that have elapsed since the Unix epoch. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it("SUB_systemDateTime_getCurrentTime_JS_API_0004", 0, async function (done) { + console.info("====>----------SUB_systemDateTime_getCurrentTime_JS_API_0004 start----------------"); + systemDateTime.getCurrentTime((error, data) => { + try { + if (error) { + console.error('====>SUB_systemDateTime_getCurrentTime_JS_API_0004 fail: ' + JSON.stringify(error)); + expect().assertFail(); + done(); + }; + console.info('====>systemDateTime.getCurrentTime success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + } catch (error) { + console.error('====>SUB_systemDateTime_getCurrentTime_JS_API_0004 catch error: ' + JSON.stringify(error)); + done(); + } + console.info("====>----------SUB_systemDateTime_getCurrentTime_JS_API_0004 end-----------------"); + }); + }); + + /** + * @tc.number SUB_systemDateTime_getRealActiveTime_JS_API_0001 + * @tc.name Test systemTimeDate.getCurrentTime + * @tc.desc Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it("SUB_systemDateTime_getRealActiveTime_JS_API_0001", 0, async function (done) { + console.info("====>----------SUB_systemDateTime_getRealActiveTime_JS_API_0001 start----------------"); + systemDateTime.getRealActiveTime(true, (error, data) => { + try { + if (error) { + console.error('====>SUB_systemDateTime_getRealActiveTime_JS_API_0001 fail: ' + JSON.stringify(error)); + expect().assertFail(); + done(); + }; + console.info('====>SUB_systemDateTime_getRealActiveTime_JS_API_0001 success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + } catch (error) { + console.error('====>SUB_systemDateTime_getRealActiveTime_JS_API_0001 catch err: ' + JSON.stringify(error)); + done(); + } + console.info("====>----------SUB_systemDateTime_getRealActiveTime_JS_API_0001 end-----------------"); + }); + }); + + /** + * @tc.number SUB_systemDateTime_getRealActiveTime_JS_API_0002 + * @tc.name Test systemTimeDate.getCurrentTime + * @tc.desc Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it("SUB_systemDateTime_getRealActiveTime_JS_API_0002", 0, async function (done) { + console.info("====>-----SUB_systemDateTime_getRealActiveTime_JS_API_0002 start----------------"); + await systemDateTime.getRealActiveTime(false).then((data) => { + console.log('SUB_systemDateTime_getRealActiveTime_JS_API_0002 success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + }).catch(err => { + console.error('====>SUB_systemDateTime_getRealActiveTime_JS_API_0002 err: ' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info("====>-----SUB_systemDateTime_getRealActiveTime_JS_API_0002 end------------"); + }); + + /** + * @tc.number SUB_systemDateTime_getRealActiveTime_JS_API_0003 + * @tc.name Test systemTimeDate.getCurrentTime + * @tc.desc Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it("SUB_systemDateTime_getRealActiveTime_JS_API_0003", 0, async function (done) { + console.info("====>-----SUB_systemDateTime_getRealActiveTime_JS_API_0003 start----------------"); + await systemDateTime.getRealActiveTime().then((data) => { + console.log('SUB_systemDateTime_getRealActiveTime_JS_API_0003 success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + }).catch(err => { + console.error('====>SUB_systemDateTime_getRealActiveTime_JS_API_0003 err: ' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info("====>-----SUB_systemDateTime_getRealActiveTime_JS_API_0003 end------------"); + }); + + /** + * @tc.number SUB_systemDateTime_getRealActiveTime_JS_API_0004 + * @tc.name Test systemTimeDate.getCurrentTime + * @tc.desc Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it("SUB_systemDateTime_getRealActiveTime_JS_API_0004", 0, async function (done) { + console.info("====>----------SUB_systemDateTime_getRealActiveTime_JS_API_0004 start----------------"); + systemDateTime.getRealActiveTime((error, data) => { + try { + if (error) { + console.error('====>SUB_systemDateTime_getRealActiveTime_JS_API_0004 fail: ' + JSON.stringify(error)); + expect().assertFail(); + done(); + }; + console.info('====>SUB_systemDateTime_getRealActiveTime_JS_API_0004 success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + } catch (error) { + console.error('====>SUB_systemDateTime_getRealActiveTime_JS_API_0004 catch err: ' + JSON.stringify(error)); + done(); + } + console.info("====>----------SUB_systemDateTime_getRealActiveTime_JS_API_0004 end-----------------"); + }); + }); + + /** + * @tc.number SUB_systemDateTime_getRealTime_JS_API_0001 + * @tc.name Test systemTimeDate.getCurrentTime + * @tc.desc Obtains the number of milliseconds elapsed since the system was booted, including deep sleep time. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it("SUB_systemDateTime_getRealTime_JS_API_0001", 0, async function (done) { + console.info("====>----------SUB_systemDateTime_getRealTime_JS_API_0001 start----------------"); + systemDateTime.getRealTime(true, (error, data) => { + try { + if (error) { + console.error('SUB_systemDateTime_getRealTime_JS_API_0001 fail: ' + JSON.stringify(error)); + expect().assertFail(); + done(); + }; + console.info('====>SUB_systemDateTime_getRealTime_JS_API_0001 success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + } catch (error) { + console.error('====>SUB_systemDateTime_getRealTime_JS_API_0001 catch err: ' + JSON.stringify(error)); + done(); + } + console.info("====>----------SUB_systemDateTime_getRealTime_JS_API_0001 end-----------------"); + }); + }); + + /** + * @tc.number SUB_systemDateTime_getRealTime_JS_API_0002 + * @tc.name Test systemTimeDate.getCurrentTime + * @tc.desc Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it("SUB_systemDateTime_getRealTime_JS_API_0002", 0, async function (done) { + console.info("====>-----SUB_systemDateTime_getRealTime_JS_API_0002 start----------------"); + await systemDateTime.getRealTime(false).then((data) => { + console.info('====>SUB_systemDateTime_getRealTime_JS_API_0002 success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + }).catch(error => { + console.error('====>SUB_systemDateTime_getRealTime_JS_API_0002 err: ' + JSON.stringify(error)); + expect().assertFail(); + done(); + }); + console.info("====>-----SUB_systemDateTime_getRealTime_JS_API_0002 end------------"); + }); + + /** + * @tc.number SUB_systemDateTime_getRealTime_JS_API_0003 + * @tc.name Test systemTimeDate.getCurrentTime + * @tc.desc Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it("SUB_systemDateTime_getRealTime_JS_API_0003", 0, async function (done) { + console.info("====>-----SUB_systemDateTime_getRealTime_JS_API_0003 start----------------"); + await systemDateTime.getRealTime().then((data) => { + console.info('====>SUB_systemDateTime_getRealTime_JS_API_0003 success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + }).catch(error => { + console.error('====>SUB_systemDateTime_getRealTime_JS_API_0003 err: ' + JSON.stringify(error)); + expect().assertFail(); + done(); + }); + console.info("====>-----SUB_systemDateTime_getRealTime_JS_API_0003 end------------"); + }); + + /** + * @tc.number SUB_systemDateTime_getRealTime_JS_API_0004 + * @tc.name Test systemTimeDate.getCurrentTime + * @tc.desc Obtains the number of milliseconds elapsed since the system was booted, including deep sleep time. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it("SUB_systemDateTime_getRealTime_JS_API_0004", 0, async function (done) { + console.info("====>----------SUB_systemDateTime_getRealTime_JS_API_0004 start----------------"); + systemDateTime.getRealTime((error, data) => { + try { + if (error) { + console.error('SUB_systemDateTime_getRealTime_JS_API_0004 fail: ' + JSON.stringify(error)); + expect().assertFail(); + done(); + }; + console.info('====>SUB_systemDateTime_getRealTime_JS_API_0004 success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + } catch (error) { + console.error('====>SUB_systemDateTime_getRealTime_JS_API_0004 catch err: ' + JSON.stringify(error)); + done(); + } + console.info("====>----------SUB_systemDateTime_getRealTime_JS_API_0004 end-----------------"); + }); + }); + + /** + * @tc.number SUB_systemDateTime_getDate_JS_API_0100 + * @tc.name Test systemTimeDate.setDate true value + * @tc.desc Test systemTimeDate_setDate API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_systemDateTime_getDate_JS_API_0100', 0, async function (done) { + console.info("====>SUB_systemDateTime_getDate_JS_API_0100 start"); + await systemDateTime.getDate().then((data) => { + console.info("====>SUB_systemDateTime_getDate_JS_API_0100 getDate: " + data); + expect(data != null).assertTrue(); + done(); + }).catch(error => { + console.info("====>SUB_systemDateTime_getDate_JS_API_0100 getDate fail: " + error); + expect().assertFail(); + done(); + }) + console.info("====>SUB_systemDateTime_getDate_JS_API_0100 end"); + + }); + + /** + * @tc.number SUB_systemDateTime_getDate_JS_API_0200 + * @tc.name Test systemTimeDate.setDate true value + * @tc.desc Test systemTimeDate_setDate API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_systemDateTime_getDate_JS_API_0200', 0, async function (done) { + console.info("====>SUB_systemDateTime_getDate_JS_API_0200 start"); + systemDateTime.getDate((err, data) => { + try{ + if(err){ + console.info("====>SUB_systemDateTime_getDate_JS_API_0200 getTimezone fail: " + err); + expect().assertFail(); + done(); + } + console.info("====>SUB_systemDateTime_getDate_JS_API_0200 getTimezone success: " + data); + expect(data != null).assertTrue(); + done(); + }catch(error){ + console.info("====>SUB_systemDateTime_getDate_JS_API_0200 catch error " + error); + done(); + } + }) + console.info("====>SUB_systemDateTime_getDate_JS_API_0200 end"); + }); + + + /** + * @tc.number SUB_systemDateTime_getTimezone_JS_API_0100 + * @tc.name Test systemTime.SUB_systemDateTime_getTimezone_JS_API_0100 true value + * @tc.desc Test systemTimeDate_setTimezone API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_systemDateTime_getTimezone_JS_API_0100', 0, async function (done) { + console.info("====>SUB_systemDateTime_getTimezone_JS_API_0100 start"); + await systemDateTime.getTimezone().then( data => { + console.info("====>SUB_systemDateTime_getTimezone_JS_API_0100 getTimezone success: " + data); + expect(data != null).assertTrue(); + done(); + }).catch(error => { + console.info("====>SUB_systemDateTime_getTimezone_JS_API_0100 getTimezone fail: " + error); + expect().assertFail(); + done(); + }); + console.info("====>SUB_systemDateTime_getTimezone_JS_API_0100 end"); + }); + + /** + * @tc.number SUB_systemDateTime_getTimezone_JS_API_0200 + * @tc.name Test systemTimeDate.setTimezone true value + * @tc.desc Test systemTimeDate_setTimezone API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_systemDateTime_getTimezone_JS_API_0200', 0, async function (done) { + console.info("====>SUB_systemDateTime_getTimezone_JS_API_0200 start"); + systemDateTime.getTimezone((err, data) => { + try{ + if(err){ + console.info("====>SUB_systemDateTime_getTimezone_JS_API_0200 getTimezone fail: " + err); + expect().assertFail(); + done(); + } + console.info("====>SUB_systemDateTime_getTimezone_JS_API_0200 getTimezone success: " + data); + expect(data != null).assertTrue(); + done(); + }catch(error){ + console.info("====>SUB_systemDateTime_getTimezone_JS_API_0200 catch error " + error); + done(); + } + }) + console.info("====>SUB_systemDateTime_getTimezone_JS_API_0200 end"); + }); + + }); +}; diff --git a/time/dateTimeTest/entry/src/main/module.json b/time/dateTimeTest/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..f68134834bc24b6743e9fe8ed848a2741e58fae8 --- /dev/null +++ b/time/dateTimeTest/entry/src/main/module.json @@ -0,0 +1,45 @@ +{ + "module": { + "name": "entry_test", + "type": "entry", + "srcEntrance": "./ets/Application/MyAbilityStage.ts", + "description": "$string:entry_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "tablet", + "default", + "phone" + ], + "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" + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/time/dateTimeTest/entry/src/main/resources/base/element/color.json b/time/dateTimeTest/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..62a137a61b90c14f109ed8c81d9d551ea0a5888a --- /dev/null +++ b/time/dateTimeTest/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/dateTimeTest/entry/src/main/resources/base/element/string.json b/time/dateTimeTest/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..276031920bc5302d124e99ea162deef8532a870e --- /dev/null +++ b/time/dateTimeTest/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": "ActsDateTimeAPITest" + } + ] +} \ No newline at end of file diff --git a/time/dateTimeTest/entry/src/main/resources/base/media/icon.png b/time/dateTimeTest/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/time/dateTimeTest/entry/src/main/resources/base/media/icon.png differ diff --git a/time/dateTimeTest/entry/src/main/resources/base/profile/main_pages.json b/time/dateTimeTest/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..feec276e105eeb8d621c20aaf838f318b0a94150 --- /dev/null +++ b/time/dateTimeTest/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/index" + ] +} diff --git a/time/dateTimeTest/signature/ActsDateTimeAPITest.p7b b/time/dateTimeTest/signature/ActsDateTimeAPITest.p7b new file mode 100644 index 0000000000000000000000000000000000000000..20a967239492a1f648da7f57a3afe85c0bc2a92a Binary files /dev/null and b/time/dateTimeTest/signature/ActsDateTimeAPITest.p7b differ