diff --git a/inputmethod/BUILD.gn b/inputmethod/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..c14bb038ca6de1cdf73711743ae8c6b9810c86b0 --- /dev/null +++ b/inputmethod/BUILD.gn @@ -0,0 +1,21 @@ +# Copyright (C) 2021 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("//build/ohos_var.gni") +group("inputmethod") { + testonly = true + deps = [ + "InputMethodTest_Stage:ActsImeAbilityTest", + "InputMethodTest_ets:ActsInputMethodEtsTest", + ] +} diff --git a/inputmethod/InputMethodTest_Stage/AppScope/app.json b/inputmethod/InputMethodTest_Stage/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..154fc890f254298cb556553301ac498d7b308873 --- /dev/null +++ b/inputmethod/InputMethodTest_Stage/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "app":{ + "bundleName":"com.acts.imeability.test", + "vendor":"huawei", + "versionCode":1000000, + "versionName":"1.0.0", + "debug":false, + "icon":"$media:icon", + "label":"$string:app_name", + "description":"$string:description_application", + "distributedNotificationEnabled":true, + "keepAlive":true, + "singleUser":true, + "minAPIVersion":8, + "targetAPIVersion":8, + "car":{ + "apiCompatibleVersion":8, + "singleUser":false + } + } +} diff --git a/inputmethod/InputMethodTest_Stage/AppScope/resources/base/element/string.json b/inputmethod/InputMethodTest_Stage/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ee69f9a861d9dc269ed6638735d52674583498e1 --- /dev/null +++ b/inputmethod/InputMethodTest_Stage/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string":[ + { + "name":"app_name", + "value":"ohosProject" + } + ] +} \ No newline at end of file diff --git a/inputmethod/InputMethodTest_Stage/AppScope/resources/base/media/app_icon.png b/inputmethod/InputMethodTest_Stage/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/inputmethod/InputMethodTest_Stage/AppScope/resources/base/media/app_icon.png differ diff --git a/inputmethod/InputMethodTest_Stage/BUILD.gn b/inputmethod/InputMethodTest_Stage/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..1740ea7d46b8040d7a35c8ed768532705d10daab --- /dev/null +++ b/inputmethod/InputMethodTest_Stage/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("ActsImeAbilityTest") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":IMExtAbility_ets_assets", + ":IMExtAbility_resources", + ] + ets2abc = true + certificate_profile = "signature/ActInputMethodStageAPITest.p7b" + hap_name = "ActsImeAbilityTest" + subsystem_name = "inputmethod" + part_name = "imf" +} + +ohos_app_scope("IMExtAbility_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("IMExtAbility_ets_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("IMExtAbility_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":IMExtAbility_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/inputmethod/InputMethodTest_Stage/Test.json b/inputmethod/InputMethodTest_Stage/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..5d2e5fb56b32cae8e4525e610f4bbe7b8980861a --- /dev/null +++ b/inputmethod/InputMethodTest_Stage/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "180000", + "bundle-name": "com.acts.imeability.test", + "module-name": "phone", + "shell-timeout": "600000", + "testcase-timeout": 10000 + }, + "kits": [{ + "test-file-name": [ + "ActsImeAbilityTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + }] +} diff --git a/inputmethod/InputMethodTest_Stage/entry/src/main/ets/Application/AbilityStage.ts b/inputmethod/InputMethodTest_Stage/entry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..f5c927f73644c144b4f4d05b9d1bdee54c5fc8ca --- /dev/null +++ b/inputmethod/InputMethodTest_Stage/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,23 @@ +/* + * 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 AbilityStage from "@ohos.app.ability.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("MyAbilityStage onCreate"); + globalThis.stageOnCreateRun = 1; + globalThis.stageContext = this.context; + } +} diff --git a/inputmethod/InputMethodTest_Stage/entry/src/main/ets/ImExtAbility/ImExtAbility.ets b/inputmethod/InputMethodTest_Stage/entry/src/main/ets/ImExtAbility/ImExtAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..2b5d95374ffdc18457464f8cfa75490acd005fff --- /dev/null +++ b/inputmethod/InputMethodTest_Stage/entry/src/main/ets/ImExtAbility/ImExtAbility.ets @@ -0,0 +1,54 @@ +/* + * 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 inputMethodExtensionAbility from '@ohos.InputMethodExtensionAbility' + +export default class ImExtAbility extends inputMethodExtensionAbility { + + onCreate(want) { + console.info("inputMethodExtensionAbility onCreate"); + let options = { + windowMode: 0 + } + console.info("inputMethodExtensionAbility want.bundleName is: " + want.bundleName); + console.info("inputMethodExtensionAbility want.moduleName is: " + want.moduleName); + console.info("inputMethodExtensionAbility want.abilityName is: " + want.abilityName); + + console.info("---------------------------1-----------------------------"); + try{ + this.context.destroy((err, data)=>{ + if(err){ + console.info('destroy001 destroy fail: ' + JSON.stringify(err)); + } + console.info("destroy001 inputMethodExtensionAbility destroy successfully." + JSON.stringify(data)); + }) + }catch(error){ + console.info('destroy001 destroy catch error: ' + JSON.stringify(error)); + } + + try{ + this.context.destroy().then((data) => { + console.info("destroy002 terminateSelf success:." + JSON.stringify(data)); + }).catch((err) => { + console.info('destroy002 terminateSelf fail: ' + JSON.stringify(err)); + }) + }catch(error){ + console.info('destroy002 destroy catch error: ' + JSON.stringify(error)); + } + } + + onDestroy() { + console.info("onDestroy: inputMethodExtensionAbility destroy."); + } +} diff --git a/inputmethod/InputMethodTest_Stage/entry/src/main/ets/MainAbility/MainAbility.ts b/inputmethod/InputMethodTest_Stage/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..ff7ec1c31b8842a64198b7dea08ca7b6a8c5c941 --- /dev/null +++ b/inputmethod/InputMethodTest_Stage/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,51 @@ +/* + * 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 Ability from '@ohos.app.ability.UIAbility' + +export default class MainAbility extends Ability { + onCreate(want,launchParam){ + // Ability is creating, initialize resources for this ability + console.info("ImExtAbility onCreate") + globalThis.abilityWant = want; + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.info("ImExtAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.info("ImExtAbility onWindowStageCreate") + globalThis.abilityContext = this.context + windowStage.setUIContent(this.context, "pages/index/index", null) + console.info("ImExtAbility onWindowStageCreate finish") + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.info("ImExtAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.info("ImExtAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.info("ImExtAbility onBackground") + } +}; \ No newline at end of file diff --git a/inputmethod/InputMethodTest_Stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/inputmethod/InputMethodTest_Stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..57aad0b6a9e2d137c5a225f15eb3476ad229b74a --- /dev/null +++ b/inputmethod/InputMethodTest_Stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,78 @@ +/* + * 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 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() { + console.log("onAbilityCreateCallback"); +} + +async function addAbilityMonitorCallback(err: any) { + console.info("addAbilityMonitorCallback : " + JSON.stringify(err)) +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info("OpenHarmonyTestRunner OnPrepare ") + } + + async onRun() { + console.log('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 com.acts.imeability.test.MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters["-D"] + if (debug == 'true') + { + cmd += ' -D' + } + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }) + console.info('OpenHarmonyTestRunner onRun end') + } +}; \ No newline at end of file diff --git a/inputmethod/InputMethodTest_Stage/entry/src/main/ets/pages/index/index.ets b/inputmethod/InputMethodTest_Stage/entry/src/main/ets/pages/index/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..e1942ec72fc60a6c599964b5145e31b564bac3a7 --- /dev/null +++ b/inputmethod/InputMethodTest_Stage/entry/src/main/ets/pages/index/index.ets @@ -0,0 +1,51 @@ +/* + * 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../../test/List.test' + +@Entry +@Component +struct Index { + build() { + Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World') + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => {}) + } + .width('100%') + .height('100%') + } + + aboutToAppear(){ + let abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + let abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } +} \ No newline at end of file diff --git a/inputmethod/InputMethodTest_Stage/entry/src/main/ets/pages/second/second.ets b/inputmethod/InputMethodTest_Stage/entry/src/main/ets/pages/second/second.ets new file mode 100644 index 0000000000000000000000000000000000000000..f9009a3e8567d1f4557ebc11dded54c7e27c0b0d --- /dev/null +++ b/inputmethod/InputMethodTest_Stage/entry/src/main/ets/pages/second/second.ets @@ -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 router from '@system.router'; + +@Entry +@Component +struct Second { + private content: string = "Second Page" + + build() { + Flex({ direction: FlexDirection.Column,alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text(`${this.content}`) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('back to index') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + router.back() + }) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/List.test.ets b/inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..7e02a072500d00dc853e6d0ee16b1d7c3dd4acee --- /dev/null +++ b/inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,22 @@ +/* + * 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 imeAbilityTest from './imeAbilityTest.test' +import inputMethodStageJSUnit from './inputMethodStageJSUnit'; + + +export default function testsuite() { + imeAbilityTest(globalThis.abilityContext); + inputMethodStageJSUnit(); +} \ No newline at end of file diff --git a/inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/imeAbilityTest.test.ets b/inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/imeAbilityTest.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..3f125b529ad291e25b4466b41d1864fa371d006f --- /dev/null +++ b/inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/imeAbilityTest.test.ets @@ -0,0 +1,113 @@ +/* + * 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 inputMethod from '@ohos.inputMethod' + +export default function imeAbilityTest(abilityContext) { + describe('imeAbilityTest', function () { + var prop = { + packageName: '', + methodId: '', + name:'', + id:'', + extra:{} + } + /** + * sleep function. + */ + function sleep(date, time){ + while(Date.now() - date <= time); + } + + + /** + * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. + */ + beforeAll(function () { + let inputM = inputMethod.getCurrentInputMethod() + console.info("====>beforeAll: switchInputMethod to: " + JSON.stringify(inputM)); + prop.packageName = inputM.packageName; + prop.methodId = inputM.methodId; + prop.name = inputM.packageName; + prop.id = inputM.methodId; + }); + + /** + * afterEach: Test case-level clearance conditions, which are executed after each test case is executed. + */ + afterAll(async function () { + console.info('====>afterAll: switchInputMethod to origionInput.' + JSON.stringify(prop)); + await inputMethod.switchInputMethod(prop).then((data)=>{ + console.info('====>afterAll switchInputMethod to origionInput :' + data); + expect(data == true).assertTrue(); + }).catch(err =>{ + console.info('====>afterAll switchInputMethod to origionInput error: ' + err); + }) + }); + + /** + * @tc.number SUB_InputMethod_IMEAbility_0001 + * @tc.desc Start a inputMethodExtension ability session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it('SUB_InputMethod_IMEAbility_0001', 0, async function (done) { + console.info('====>----------SUB_InputMethod_IMEAbility_0001 start-------------'); + let imExtAbilityProperty = { + packageName : "com.acts.imeability.test", + methodId : "com.acts.imeability.test.ImExtAbility", + name:"com.acts.imeability.test", + id:"com.acts.imeability.test.ImExtAbility", + extra:{} + } + + inputMethod.switchInputMethod(imExtAbilityProperty).then((data)=>{ + console.info('====>SUB_InputMethod_IMEAbility_0004 switchInputMethod to IME :' + data); + expect(data == true).assertTrue(); + }); + sleep(Date.now(), 3000); + console.info('====>----------SUB_InputMethod_IMEAbility_0001 end-------------'); + done(); + }) + + /** + * @tc.number SUB_InputMethod_IMEAbility_0002 + * @tc.desc Start a inputMethodExtension ability session + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it('SUB_InputMethod_IMEAbility_0002', 0, async function (done) { + console.info('====>-----------SUB_InputMethod_IMEAbility_0002 start-------------'); + + let imExtAbilityProperty = { + packageName : "com.acts.imeability.test", + methodId : "com.acts.imeability.test.ImExtAbility", + name:"com.acts.imeability.test", + id:"com.acts.imeability.test.ImExtAbility", + extra:{} + } + + inputMethod.switchInputMethod(imExtAbilityProperty).then((data)=>{ + console.info('====>SUB_InputMethod_IMEAbility_0002 switchInputMethod to IME :' + data); + expect(data == true).assertTrue(); + }); + sleep(Date.now(), 2500); + console.info('====>-----------SUB_InputMethod_IMEAbility_0002 end-------------'); + done(); + }) + }) +} diff --git a/inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/inputMethodStageJSUnit.ets b/inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/inputMethodStageJSUnit.ets new file mode 100644 index 0000000000000000000000000000000000000000..933393f0a8dc54f82323360936591fe4a6bdff48 --- /dev/null +++ b/inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/inputMethodStageJSUnit.ets @@ -0,0 +1,613 @@ +/** + * 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 inputMethod from '@ohos.inputMethod'; +import subtype from '@ohos.InputMethodSubtype'; + +export default function inputMethodStageJSUnit() { + describe('inputMethodTest', function () { + console.info("====>************* settings Test start*************"); + /* + * @tc.number inputMethod_test_getController_001 + * @tc.name get inputMethod controller + * @tc.desc Function test + * @tc.level 2 + */ + it('inputMethod_test_getController_001', 0, async function (done) { + console.info("====>-----------------inputMethod_test_getController_001 start---------------------"); + try{ + let inputMethodControl = inputMethod.getController(); + console.info("====>inputMethod_test_getController_001 result:" + typeof inputMethodControl); + if(typeof inputMethodControl == "object" ){ + console.info("====>inputMethod_test_getController_001 getController success"); + expect(true).assertTrue(); + }else{ + console.info("====>inputMethod_test_getController_001 getController failed"); + expect().assertFail(); + }; + }catch(error){ + console.info("====>inputMethod_test_getController_001 getController error" + JSON.stringify(error)); + expect().assertFail(); + }; + + console.info("====>-----------------inputMethod_test_getController_001 end---------------------"); + done(); + }); + + /* + * @tc.number inputMethod_test_listInputMethodSubtype_001 + * @tc.name List subtype of the specified input method + * @tc.desc Function test + * @tc.level 2 + */ + it('inputMethod_test_listInputMethodSubtype_001', 0, async function (done) { + console.info("====>-----------------inputMethod_test_listInputMethodSubtype_001 start---------------------"); + let inputM = inputMethod.getCurrentInputMethod() + console.info("inputMethod_test_listInputMethodSubtype_001 getCurrentInputMethod: " + JSON.stringify(inputM)); + let inputMethodProperty = { + packageName:inputM.packageName, + methodId:inputM.methodId, + name:inputM.packageName, + id:inputM.methodId, + label: "", + icon: "", + iconId: 124, + extra:{} + } + + let inputMethodSetting = inputMethod.getSetting(); + console.info("====>inputMethod_test_listInputMethodSubtype_001 getSetting result:" + inputMethodSetting); + inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err, data) => { + try { + if(err){ + console.info("====>inputMethod_test_listInputMethodSubtype_001 failed" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info("====>inputMethod_test_listInputMethodSubtype_001 listInputMethodSubtype: " + JSON.stringify(data)); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info("====>inputMethod_test_listInputMethodSubtype_001 listInputMethodSubtype catch error" + JSON.stringify(error)); + done(); + } + }); + console.info("====>-----------------inputMethod_test_listInputMethodSubtype_001 end---------------------"); + }); + + /* + * @tc.number inputMethod_test_listInputMethodSubtype_002 + * @tc.name List subtype of the specified input method + * @tc.desc Function test + * @tc.level 2 + */ + it('inputMethod_test_listInputMethodSubtype_002', 0, async function (done) { + console.info("====>-----------------inputMethod_test_listInputMethodSubtype_002 start---------------------"); + let inputM = inputMethod.getCurrentInputMethod() + console.info("inputMethod_test_listInputMethodSubtype_002 getCurrentInputMethod: " + JSON.stringify(inputM)); + let inputMethodProperty = { + packageName:inputM.packageName, + methodId:inputM.methodId, + name:inputM.packageName, + id:inputM.methodId, + label: "", + icon: "", + iconId: 124, + extra:{} + } + + let inputMethodSetting = inputMethod.getSetting(); + console.info("====>inputMethod_test_listInputMethodSubtype_002 getSetting result:" + inputMethodSetting); + inputMethodSetting.listInputMethodSubtype(inputMethodProperty, (err, data) => { + try { + if(err){ + console.info("====>inputMethod_test_listInputMethodSubtype_002 failed" + JSON.stringify(err)); + expect().assertFail(); + done() + }; + console.info("====>inputMethod_test_listInputMethodSubtype_002 listInputMethodSubtype:" + JSON.stringify(data)); + if(data.length >= 1){ + let inputMethodSubtype = data[0] + console.info("====>inputMethod_test_listInputMethodSubtype_002 inputMethodSubtype" + JSON.stringify(inputMethodSubtype)); + expect(inputMethodSubtype.id != null).assertTrue(); + expect(inputMethodSubtype.label != null).assertTrue(); + done(); + }else{ + console.info("====>inputMethod_test_listInputMethodSubtype_002 listInputMethodSubtype length less 1"); + expect().assertFail(); + done(); + }; + } catch (error) { + console.info("====>inputMethod_test_listInputMethodSubtype_002 listInputMethodSubtype catch error" + JSON.stringify(error)); + done(); + } + }); + console.info("====>-----------------inputMethod_test_listInputMethodSubtype_002 end---------------------"); + }); + + /* + * @tc.number inputMethod_test_listInputMethodSubtype_003 + * @tc.name List subtype of the specified input method + * @tc.desc Function test + * @tc.level 2 + */ + + it('inputMethod_test_listInputMethodSubtype_003', 0, async function (done) { + console.info("====>-----------------inputMethod_test_listInputMethodSubtype_003 start---------------------"); + let inputM = inputMethod.getCurrentInputMethod() + console.info("inputMethod_test_listInputMethodSubtype_003 getCurrentInputMethod: " + JSON.stringify(inputM)); + let inputMethodProperty = { + packageName:inputM.packageName, + methodId:inputM.methodId, + name:inputM.packageName, + id:inputM.methodId, + label: "", + icon: "", + iconId: 124, + extra:{} + } + + try{ + let inputMethodSetting = inputMethod.getSetting(); + console.info("====>inputMethod_test_listInputMethodSubtype_003 getSetting result:" + inputMethodSetting); + inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data) => { + console.info("====>inputMethod_test_listInputMethodSubtype_003 listInputMethodSubtype: " + JSON.stringify(data)); + expect(true).assertTrue(); + done(); + }).catch(err => { + console.info("====>inputMethod_test_listInputMethodSubtype_003 failed" + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + }catch(error){ + console.info("====>inputMethod_test_listInputMethodSubtype_003 listInputMethodSubtype catch error" + JSON.stringify(error)); + expect().assertFail(); + done(); + }; + console.info("====>-----------------inputMethod_test_listInputMethodSubtype_003 end---------------------"); + }); + + /* + * @tc.number inputMethod_test_listInputMethodSubtype_004 + * @tc.name List subtype of the specified input method + * @tc.desc Function test + * @tc.level 2 + */ + it('inputMethod_test_listInputMethodSubtype_004', 0, async function (done) { + console.info("====>-----------------inputMethod_test_listInputMethodSubtype_004 start---------------------"); + let inputM = inputMethod.getCurrentInputMethod() + console.info("inputMethod_test_listInputMethodSubtype_004 getCurrentInputMethod: " + JSON.stringify(inputM)); + let inputMethodProperty = { + packageName:inputM.packageName, + methodId:inputM.methodId, + name:inputM.packageName, + id:inputM.methodId, + label: "", + icon: "", + iconId: 124, + extra:{} + } + + let inputMethodSetting = inputMethod.getSetting(); + console.info("====>inputMethod_test_listInputMethodSubtype_004 getSetting result:" + inputMethodSetting); + inputMethodSetting.listInputMethodSubtype(inputMethodProperty).then((data) => { + try{ + console.info("====>inputMethod_test_listInputMethodSubtype_004 listInputMethodSubtype:" + JSON.stringify(data)); + if(data.length >= 1){ + let inputMethodSubtype = data[0] + console.info("====>inputMethod_test_listInputMethodSubtype_004 inputMethodSubtype" + JSON.stringify(inputMethodSubtype)); + expect(inputMethodSubtype.id != null).assertTrue(); + expect(inputMethodSubtype.label != null).assertTrue(); + done(); + }else{ + console.info("====>inputMethod_test_listInputMethodSubtype_004 listInputMethodSubtype length less 1"); + expect().assertFail(); + done(); + } + }catch(error){ + console.info("====>inputMethod_test_listInputMethodSubtype_004 listInputMethodSubtype catch error" + JSON.stringify(error)); + expect().assertFail(); + done(); + } + }).catch(err => { + console.info("====>inputMethod_test_listInputMethodSubtype_004 failed" + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info("====>-----------------inputMethod_test_listInputMethodSubtype_004 end---------------------"); + }); + + /* + * @tc.number inputMethod_test_listCurrentInputMethodSubtype_001 + * @tc.name List subtype of the specified input method + * @tc.desc Function test + * @tc.level 2 + */ + it('inputMethod_test_listCurrentInputMethodSubtype_001', 0, async function (done) { + console.info("====>-----------------inputMethod_test_listCurrentInputMethodSubtype_001 start---------------------"); + let inputMethodSetting = inputMethod.getSetting(); + console.info("====>inputMethod_test_listCurrentInputMethodSubtype_001 getSetting result:" + inputMethodSetting); + inputMethodSetting.listCurrentInputMethodSubtype((err, data) => { + try { + if(err){ + console.info("====>inputMethod_test_listCurrentInputMethodSubtype_001 failed" + JSON.stringify(err)); + expect().assertFail(); + done(); + }; + console.info("====>inputMethod_test_listCurrentInputMethodSubtype_001 listCurrentInputMethodSubtype: " + JSON.stringify(data)); + expect(true).assertTrue(); + done(); + } catch (error) { + console.info("====>inputMethod_test_listCurrentInputMethodSubtype_001 listCurrentInputMethodSubtype catch error" + JSON.stringify(error)); + done(); + } + }); + console.info("====>-----------------inputMethod_test_listCurrentInputMethodSubtype_001 end---------------------"); + }); + + /* + * @tc.number inputMethod_test_listInputMethodSubtype_003 + * @tc.name List subtype of current input method + * @tc.desc Function test + * @tc.level 2 + */ + it('inputMethod_test_listCurrentInputMethodSubtype_002', 0, async function (done) { + console.info("====>-----------------inputMethod_test_listCurrentInputMethodSubtype_002 start---------------------"); + try{ + let inputMethodSetting = inputMethod.getSetting(); + console.info("====>inputMethod_test_listCurrentInputMethodSubtype_002 getSetting result:" + inputMethodSetting); + inputMethodSetting.listCurrentInputMethodSubtype().then((data) => { + console.info("====>inputMethod_test_listCurrentInputMethodSubtype_002 listCurrentInputMethodSubtype: " + JSON.stringify(data)); + expect(true).assertTrue(); + done(); + }).catch(err => { + console.info("====>inputMethod_test_listCurrentInputMethodSubtype_002 failed" + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + }catch(error){ + console.info("====>inputMethod_test_listCurrentInputMethodSubtype_002 listCurrentInputMethodSubtype catch error" + JSON.stringify(error)); + expect().assertFail(); + done(); + }; + console.info("====>-----------------inputMethod_test_listCurrentInputMethodSubtype_002 end---------------------"); + }); + + /* + * @tc.number inputMethod_test_getCurrentInputMethodSubtype_001 + * @tc.name Get the current input method subtype + * @tc.desc Function test + * @tc.level 2 + */ + it('inputMethod_test_getCurrentInputMethodSubtype_001', 0, async function (done) { + console.info("====>-----------------inputMethod_test_getCurrentInputMethodSubtype_001 start---------------------"); + try{ + let inputMethodSubtype = inputMethod.getCurrentInputMethodSubtype(); + console.info("====>inputMethod_test_getCurrentInputMethodSubtype_001 result:" + typeof inputMethodSubtype); + if(typeof inputMethodSubtype == "object" ){ + console.info("====>inputMethod_test_getCurrentInputMethodSubtype_001 getCurrentInputMethodSubtype success"); + expect(true).assertTrue(); + }else{ + console.info("====>inputMethod_test_getCurrentInputMethodSubtype_001 getCurrentInputMethodSubtype failed"); + expect().assertFail(); + }; + }catch(error){ + console.info("====>inputMethod_test_getCurrentInputMethodSubtype_001 getCurrentInputMethodSubtype error" + JSON.stringify(error)); + expect().assertFail(); + } + console.info("====>-----------------inputMethod_test_getCurrentInputMethodSubtype_001 end---------------------"); + done(); + }); + + /* + * @tc.number inputMethod_test_switchCurrentInputMethodAndSubtype_001 + * @tc.name Switch current input method subtype. + * @tc.desc Function test + * @tc.level 2 + */ + it('inputMethod_test_switchCurrentInputMethodAndSubtype_001', 0, async function (done) { + console.info("====>************* inputMethod_test_switchCurrentInputMethodAndSubtype_001 Test start*************"); + let inputM = inputMethod.getCurrentInputMethod() + console.info("inputMethod_test_switchCurrentInputMethodAndSubtype_001 getCurrentInputMethod: " + JSON.stringify(inputM)); + let inputMethodProperty = { + packageName:inputM.packageName, + methodId:inputM.methodId, + name:inputM.packageName, + id:inputM.methodId, + label: "", + icon: "", + iconId: 124, + extra:{} + } + let inputMS = inputMethod.getCurrentInputMethodSubtype() + console.info("inputMethod_test_switchCurrentInputMethodAndSubtype_001 getCurrentInputMethodSubtype: " + JSON.stringify(inputMS)); + let inputMethodSubProperty : subtype = { + id: inputMS.id, + label: inputMS.label, + name: "", + mode: "lower", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} + }; + + inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty, (err,data) => { + try { + if (err) { + console.error('inputMethod_test_switchCurrentInputMethodAndSubtype_001 err: ' + JSON.stringify(err)); + expect( err.code === 12800008 ).assertTrue(); + done(); + } + console.info("====>inputMethod_test_switchCurrentInputMethodAndSubtype_001 data: " + JSON.stringify(data)); + expect(data != null).assertTrue(); + done(); + } catch (error) { + console.error('inputMethod_test_switchCurrentInputMethodAndSubtype_001 catch error: ' + JSON.stringify(error)); + done(); + } + }); + console.info("====>************* inputMethod_test_switchCurrentInputMethodAndSubtype_001 Test end*************"); + }); + + /* + * @tc.number inputMethod_test_switchCurrentInputMethodAndSubtype_002 + * @tc.name Switch current input method subtype. + * @tc.desc Function test + * @tc.level 2 + */ + it('inputMethod_test_switchCurrentInputMethodAndSubtype_002', 0, async function (done) { + console.info("====>************* inputMethod_test_switchCurrentInputMethodAndSubtype_002 Test start*************"); + let inputM = inputMethod.getCurrentInputMethod() + console.info("inputMethod_test_switchCurrentInputMethodAndSubtype_002 getCurrentInputMethod: " + JSON.stringify(inputM)); + let inputMethodProperty = { + packageName:inputM.packageName, + methodId:inputM.methodId, + name:inputM.packageName, + id:inputM.methodId, + label: "", + icon: "", + iconId: 124, + extra:{} + } + let inputMS = inputMethod.getCurrentInputMethodSubtype() + console.info("inputMethod_test_switchCurrentInputMethodAndSubtype_002 getCurrentInputMethodSubtype: " + JSON.stringify(inputMS)); + let inputMethodSubProperty : subtype = { + id: inputMS.id, + label: inputMS.label, + name: "", + mode: "lower", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} + }; + + try { + inputMethod.switchCurrentInputMethodAndSubtype(inputMethodProperty, inputMethodSubProperty).then((data) => { + console.info("====>inputMethod_test_switchCurrentInputMethodAndSubtype_002 data: " + JSON.stringify(data)); + expect(data != null).assertTrue(); + done(); + }).catch(err => { + console.error('inputMethod_test_switchCurrentInputMethodAndSubtype_002 err: ' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + }catch (error) { + console.error('inputMethod_test_switchCurrentInputMethodAndSubtype_002 catch error: ' + JSON.stringify(error)); + expect().assertFail(); + done(); + }; + console.info("====>************* inputMethod_test_switchCurrentInputMethodAndSubtype_002 Test end*************"); + }); + + /* + * @tc.number inputMethod_test_switchCurrentInputMethodSubtype_001 + * @tc.name Switch current input method subtype. + * @tc.desc Function test + * @tc.level 2 + */ + it('inputMethod_test_switchCurrentInputMethodSubtype_001', 0, async function (done) { + console.info("====>************* inputMethod_test_switchCurrentInputMethodSubtype_001 Test start*************"); + let inputMS = inputMethod.getCurrentInputMethodSubtype() + console.info("inputMethod_test_switchCurrentInputMethodSubtype_001 getCurrentInputMethodSubtype: " + JSON.stringify(inputMS)); + let inputMethodSubProperty : subtype = { + id: inputMS.id, + label: inputMS.label, + name: "", + mode: "lower", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} + }; + + inputMethod.switchCurrentInputMethodSubtype(inputMethodSubProperty, (err,data) => { + try { + if (err) { + console.error('inputMethod_test_switchCurrentInputMethodSubtype_001 err: ' + JSON.stringify(err)); + expect().assertFail(); + done(); + }; + console.info("====>inputMethod_test_switchCurrentInputMethodSubtype_001 data: " + JSON.stringify(data)); + expect(data != null).assertTrue(); + done(); + } catch (error) { + console.error('inputMethod_test_switchCurrentInputMethodSubtype_001 catch error: ' + JSON.stringify(error)); + done(); + } + }); + console.info("====>************* inputMethod_test_switchCurrentInputMethodSubtype_001 Test end*************"); + }); + + /* + * @tc.number inputMethod_test_switchCurrentInputMethodSubtype_002 + * @tc.name Switch current input method subtype. + * @tc.desc Function test + * @tc.level 2 + */ + it('inputMethod_test_switchCurrentInputMethodSubtype_002', 0, async function (done) { + console.info("====>************* inputMethod_test_switchCurrentInputMethodSubtype_002 Test start*************"); + let inputMS = inputMethod.getCurrentInputMethodSubtype() + console.info("inputMethod_test_switchCurrentInputMethodSubtype_002 getCurrentInputMethodSubtype: " + JSON.stringify(inputMS)); + let inputMethodSubProperty : subtype = { + id: inputMS.id, + label: inputMS.label, + name: "", + mode: "lower", + locale: "", + language: "", + icon: "", + iconId: 0, + extra: {} + }; + + try { + inputMethod.switchCurrentInputMethodSubtype(inputMethodSubProperty).then((data) => { + console.info("====>inputMethod_test_switchCurrentInputMethodSubtype_002 data: " + JSON.stringify(data)); + expect(data != null).assertTrue(); + done(); + }).catch(err => { + console.error('inputMethod_test_switchCurrentInputMethodSubtype_002 err: ' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + }catch (error) { + console.error('inputMethod_test_switchCurrentInputMethodSubtype_002 catch error: ' + JSON.stringify(error)); + expect().assertFail(); + done(); + }; + console.info("====>************* inputMethod_test_switchCurrentInputMethodSubtype_002 Test end*************"); + done(); + }); + + /* + * @tc.number inputMethod_test_showOptionalInputMethods_001 + * @tc.name Show input method setting extension dialog + * @tc.desc Function test + * @tc.level 2 + */ + it('inputMethod_test_showOptionalInputMethods_001', 0, async function (done) { + console.info("====>-----------------inputMethod_test_showOptionalInputMethods_001 start---------------------"); + let inputMethodSetting = inputMethod.getSetting(); + console.info("====>inputMethod_test_showOptionalInputMethods_001 result:" + inputMethodSetting); + inputMethodSetting.showOptionalInputMethods((err, data) => { + try { + if(err){ + console.info("====>inputMethod_test_showOptionalInputMethods_001 showOptionalInputMethods faild: " + JSON.stringify(err)); + expect().assertFail(); + done(); + }; + console.info("====>inputMethod_test_showOptionalInputMethods_001 showOptionalInputMethods success data is : " + data); + expect(true).assertTrue(); + setTimeout(() => { + done(); + }, 1500); + } catch (error) { + console.info("====>inputMethod_test_showOptionalInputMethods_001 showOptionalInputMethods catch error: " + JSON.stringify(error)); + done(); + } + }); + console.info("====>-----------------inputMethod_test_showOptionalInputMethods_001 end---------------------"); + }); + + /* + * @tc.number inputMethod_test_showOptionalInputMethods_002 + * @tc.name Show input method setting extension dialog + * @tc.desc Function test + * @tc.level 2 + */ + it('inputMethod_test_showOptionalInputMethods_002', 0, async function (done) { + console.info("====>-----------------inputMethod_test_showOptionalInputMethods_002 start---------------------"); + let inputMethodSetting = inputMethod.getSetting(); + try { + console.info("====>inputMethod_test_showOptionalInputMethods_002 result:" + JSON.stringify(inputMethodSetting)); + inputMethodSetting.showOptionalInputMethods().then((data) => { + console.info("====>inputMethod_test_showOptionalInputMethods_002 showOptionalInputMethods success data is: " + JSON.stringify(data)); + expect(true).assertTrue(); + done(); + }).catch(err => { + console.info("====>inputMethod_test_showOptionalInputMethods_002 showOptionalInputMethods faild: " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + } catch (error) { + console.info("====>inputMethod_test_showOptionalInputMethods_002 showOptionalInputMethods catch error: " + JSON.stringify(error)); + expect().assertFail(); + done(); + }; + console.info("====>-----------------inputMethod_test_showOptionalInputMethods_002 end---------------------"); + }); + + /* + * @tc.number inputMethod_test_stopInputSession_002 + * @tc.name Stop input + * @tc.desc Function test + * @tc.level 2 + */ + it('inputMethod_test_stopInputSession_002', 0, async function (done) { + console.info("====>-----------------inputMethod_test_stopInputSession_002 start---------------------"); + try{ + let inputMethodCtrl = inputMethod.getController(); + console.info("====>inputMethod_test_stopInputSession_002 result:" + typeof inputMethodCtrl); + await inputMethodCtrl.stopInputSession().then((data) => { + console.info("====>inputMethod_test_stopInputSession_002 data:" + data); + expect().assertFail(); + done(); + }).catch((err) => { + expect(err.code).assertEqual(12800003) + done(); + }) + }catch(error){ + console.info("====>inputMethod_test_stopInputSession_002 catch error" + JSON.stringify(error)); + expect().assertFail(); + done(); + }; + console.info("====>-----------------inputMethod_test_stopInputSession_002 end---------------------"); + }); + + /* + * @tc.number inputMethod_test_stopInputSession_001 + * @tc.name Stop input + * @tc.desc Function test + * @tc.level 2 + */ + it('inputMethod_test_stopInputSession_001', 0, async function (done) { + console.info("====>-----------------inputMethod_test_stopInputSession_001 start---------------------"); + let inputMethodCtrl = inputMethod.getController(); + console.debug("inputMethod_test_stopInputSession_001 result: " + typeof inputMethodCtrl); + inputMethodCtrl.stopInputSession((err)=>{ + try { + if(err){ + console.info("====>inputMethod_test_stopInputSession_001 faild: " + JSON.stringify(err)); + console.info("====>inputMethod_test_stopInputSession_001 faild: " + err.code); + console.info("====>inputMethod_test_stopInputSession_001 faild: " + typeof(err.code)); + expect(err.code).assertEqual(12800003); + done(); + }else{ + expect().assertFail(); + done(); + } + } catch (err) { + done(); + } + }) + }); + + }); +}; diff --git a/inputmethod/InputMethodTest_Stage/entry/src/main/module.json b/inputmethod/InputMethodTest_Stage/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..ebfbd6d84affbd1afb81143f66102b24668c9d3b --- /dev/null +++ b/inputmethod/InputMethodTest_Stage/entry/src/main/module.json @@ -0,0 +1,64 @@ +{ + "module": { + "name": "phone", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:phone_entry_dsc", + "mainElement": "MainAbility", + "deviceTypes": [ + "tablet", + "default", + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "uiSyntax": "ets", + "pages": "$profile:main_pages", + "metadata": [ + { + "name": "ArkTSPartialUpdate", + "value": "false" + } + ], + "abilities": [ + { + "name": "com.acts.imeability.test.MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:phone_entry_main", + "icon": "$media:icon", + "label": "$string:entry_label", + "visible": true, + "orientation": "portrait", + "launchType": "singleton", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities":[ + "entity.system.home" + ] + } + ] + } + ], + "extensionAbilities": [ + { + "name": "com.acts.imeability.test.ImExtAbility", + "srcEntrance": "./ets/ImExtAbility/ImExtAbility.ets", + "label": "$string:ime_label", + "description": "$string:ime_description", + "type": "inputMethod" + } + ], + "requestPermissions": [ + { + "name":"ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + "reason":"need use ohos.permission.GET_BUNDLE_INFO_PRIVILEGED" + }, + { + "name": "ohos.permission.CONNECT_IME_ABILITY" + } + ] + } +} diff --git a/inputmethod/InputMethodTest_Stage/entry/src/main/resources/base/element/string.json b/inputmethod/InputMethodTest_Stage/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..ea8ffb9ce5faaafb968771c65a5ac50db871e1ff --- /dev/null +++ b/inputmethod/InputMethodTest_Stage/entry/src/main/resources/base/element/string.json @@ -0,0 +1,36 @@ +{ + "string": [ + { + "name": "phone_entry_dsc", + "value": "i am an entry for phone" + }, + { + "name": "phone_entry_main", + "value": "the phone entry ability" + }, + { + "name": "entry_label", + "value": "ActsImeAbilityTest" + }, + { + "name": "ime_description", + "value": "input method extension ability." + }, + { + "name": "ime_label", + "value": "inputMethod extension ability services." + }, + { + "name": "ime_label_1", + "value": "inputMethod extension ability services_1." + }, + { + "name": "description_application", + "value": "demo for test" + }, + { + "name": "app_name", + "value": "Demo" + } + ] +} diff --git a/inputmethod/InputMethodTest_Stage/entry/src/main/resources/base/media/icon.png b/inputmethod/InputMethodTest_Stage/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/inputmethod/InputMethodTest_Stage/entry/src/main/resources/base/media/icon.png differ diff --git a/inputmethod/InputMethodTest_Stage/entry/src/main/resources/base/profile/main_pages.json b/inputmethod/InputMethodTest_Stage/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..6898b31d2085f478ee1ed9d933a5910cbf901d92 --- /dev/null +++ b/inputmethod/InputMethodTest_Stage/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,6 @@ +{ + "src": [ + "pages/index/index", + "pages/second/second" + ] +} \ No newline at end of file diff --git a/inputmethod/InputMethodTest_Stage/signature/ActInputMethodStageAPITest.p7b b/inputmethod/InputMethodTest_Stage/signature/ActInputMethodStageAPITest.p7b new file mode 100644 index 0000000000000000000000000000000000000000..d369743a0cfcf56368efb8c6b3ebc30c704b5c8e Binary files /dev/null and b/inputmethod/InputMethodTest_Stage/signature/ActInputMethodStageAPITest.p7b differ diff --git a/inputmethod/InputMethodTest_ets/BUILD.gn b/inputmethod/InputMethodTest_ets/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4954a98aff9db6d3996937a0b3e4e0517116ac5f --- /dev/null +++ b/inputmethod/InputMethodTest_ets/BUILD.gn @@ -0,0 +1,38 @@ +# 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("ActsInputMethodEtsTest") { + hap_profile = "./entry/src/main/config.json" + deps = [ + ":inputMethod_ets_assets", + ":inputMethod_ets_resources", + ":inputMethod_ets_test_assets", + ] + ets2abc = true + subsystem_name = "inputmethod" + part_name = "imf" + certificate_profile = "./signature/ActInputMethodEtsAPITest.p7b" + hap_name = "ActsInputMethodEtsTest" +} +ohos_js_assets("inputMethod_ets_assets") { + source_dir = "./entry/src/main/ets/MainAbility" +} +ohos_js_assets("inputMethod_ets_test_assets") { + source_dir = "./entry/src/main/ets/TestAbility" +} +ohos_resources("inputMethod_ets_resources") { + sources = [ "./entry/src/main/resources" ] + hap_profile = "./entry/src/main/config.json" +} diff --git a/inputmethod/InputMethodTest_ets/Test.json b/inputmethod/InputMethodTest_ets/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..e72008206b37d37b7eb4494ec6d2f008348225d0 --- /dev/null +++ b/inputmethod/InputMethodTest_ets/Test.json @@ -0,0 +1,19 @@ +{ + "description": "Configuration for inputMethod Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "600000", + "bundle-name": "com.acts.inputmethodtest", + "package-name": "com.acts.inputmethodtest", + "shell-timeout": "600000" + }, + "kits": [ + { + "test-file-name": [ + "ActsInputMethodEtsTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/inputmethod/InputMethodTest_ets/entry/src/main/config.json b/inputmethod/InputMethodTest_ets/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..abe55f0a627b6f481e4faf77e8752aa8858431d9 --- /dev/null +++ b/inputmethod/InputMethodTest_ets/entry/src/main/config.json @@ -0,0 +1,106 @@ +{ + "app": { + "bundleName": "com.acts.inputmethodtest", + "vendor": "open", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 7, + "releaseType": "Release", + "target": 9 + } + }, + "deviceConfig": {}, + "module": { + "package": "com.acts.inputmethodtest", + "name": ".MyApplication", + "mainAbility": "com.acts.inputmethodtest.MainAbility", + "deviceType": [ + "tablet", + "default", + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "visible": true, + "srcPath": "MainAbility", + "name": ".MainAbility", + "srcLanguage": "ets", + "icon": "$media:icon", + "description": "$string:description_mainability", + "formsEnabled": false, + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard" + }, + { + "orientation": "unspecified", + "visible": true, + "srcPath": "TestAbility", + "name": ".TestAbility", + "srcLanguage": "ets", + "icon": "$media:icon", + "description": "$string:TestAbility_desc", + "formsEnabled": false, + "label": "$string:TestAbility_label", + "type": "page", + "launchType": "standard" + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.CONNECT_IME_ABILITY" + } + ], + "js": [ + { + "mode": { + "syntax": "ets", + "type": "pageAbility" + }, + "pages": [ + "pages/index", + "pages/input" + ], + "name": ".MainAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + }, + { + "mode": { + "syntax": "ets", + "type": "pageAbility" + }, + "pages": [ + "pages/index" + ], + "name": ".TestAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} diff --git a/inputmethod/InputMethodTest_ets/entry/src/main/ets/MainAbility/app.ets b/inputmethod/InputMethodTest_ets/entry/src/main/ets/MainAbility/app.ets new file mode 100644 index 0000000000000000000000000000000000000000..08e6696db4d03fcac7ea35704d83904700f1fd92 --- /dev/null +++ b/inputmethod/InputMethodTest_ets/entry/src/main/ets/MainAbility/app.ets @@ -0,0 +1,32 @@ +/** + * 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../test/List.test' + +export default { + onCreate() { + console.info('Application onCreate') + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + }, + onDestroy() { + console.info('Application onDestroy') + }, +} \ No newline at end of file diff --git a/inputmethod/InputMethodTest_ets/entry/src/main/ets/MainAbility/pages/index.ets b/inputmethod/InputMethodTest_ets/entry/src/main/ets/MainAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..1a788d8fa2c4672e18e4efb60d7080a900892e9c --- /dev/null +++ b/inputmethod/InputMethodTest_ets/entry/src/main/ets/MainAbility/pages/index.ets @@ -0,0 +1,36 @@ +// @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. + */ +@Entry +@Component +struct MyComponent { + aboutToAppear() { + } + + build() { + Flex({ + direction: FlexDirection.Column, + alignItems: ItemAlign.Center, + justifyContent: FlexAlign.Center + }) { + Text('ACE ETS TEST') + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} + diff --git a/inputmethod/InputMethodTest_ets/entry/src/main/ets/MainAbility/pages/input.ets b/inputmethod/InputMethodTest_ets/entry/src/main/ets/MainAbility/pages/input.ets new file mode 100644 index 0000000000000000000000000000000000000000..309eb39d48f7758be858a6c6b5a23da41b9579e1 --- /dev/null +++ b/inputmethod/InputMethodTest_ets/entry/src/main/ets/MainAbility/pages/input.ets @@ -0,0 +1,45 @@ +// @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. + */ + +@Entry +@Component +struct TextInputTest { + @State text: string = ''; + + build() { + Column() { + TextInput({ placeholder: 'input your word' }) + .type(InputType.Normal) + .key('TextInput') + .placeholderColor(Color.Blue) + .placeholderFont({ size: 40, weight: FontWeight.Normal, family: "sans-serif", style: FontStyle.Normal }) + .enterKeyType(EnterKeyType.Search) + .caretColor(Color.Green) + .height(60) + .fontSize(30) + .fontWeight(FontWeight.Bold) + .fontFamily("cursive") + .fontStyle(FontStyle.Italic) + .fontColor(Color.Red) + .maxLength(20) + .onChange((value: string) => { + this.text = value + }) + Text(this.text) + } + } +} + diff --git a/inputmethod/InputMethodTest_ets/entry/src/main/ets/TestAbility/app.ets b/inputmethod/InputMethodTest_ets/entry/src/main/ets/TestAbility/app.ets new file mode 100644 index 0000000000000000000000000000000000000000..e6de87af12386aee0473fc24bd16b5a771c2fb22 --- /dev/null +++ b/inputmethod/InputMethodTest_ets/entry/src/main/ets/TestAbility/app.ets @@ -0,0 +1,32 @@ +/* + * 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../test/List.test' + +export default { + onCreate() { + console.info('Application onCreate') + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + }, + onDestroy() { + console.info('Application onDestroy') + }, +} \ No newline at end of file diff --git a/inputmethod/InputMethodTest_ets/entry/src/main/ets/TestAbility/pages/index.ets b/inputmethod/InputMethodTest_ets/entry/src/main/ets/TestAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..011878f2b989ed0798baafed2b6c14e241fad57e --- /dev/null +++ b/inputmethod/InputMethodTest_ets/entry/src/main/ets/TestAbility/pages/index.ets @@ -0,0 +1,49 @@ +/* + * 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 router from '@system.router'; + +@Entry +@Component +struct Index { + aboutToAppear() { + console.info('TestAbility index aboutToAppear') + } + + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/inputmethod/InputMethodTest_ets/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/inputmethod/InputMethodTest_ets/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..57fdc77f0a00bdbadc0523662577347c72998373 --- /dev/null +++ b/inputmethod/InputMethodTest_ets/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,77 @@ +/* + * 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 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 itName', + '-s level', '-s testType', '-s size', '-s timeout', + '-s package' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams += ' ' + key + ' ' + parameters[key] + } + } + return targetParams.trim() +} + +async function onAbilityCreateCallback() { + console.log('onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + console.info('addAbilityMonitorCallback : ' + JSON.stringify(err)) +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info('OpenHarmonyTestRunner OnPrepare') + } + + onRun() { + console.log('OpenHarmonyTestRunner onRun run') + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.MainAbility' + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }) + console.info('OpenHarmonyTestRunner onRun call abilityDelegator.getAppContext') + var context = abilityDelegator.getAppContext() + console.info('getAppContext : ' + JSON.stringify(context)) + console.info('OpenHarmonyTestRunner onRun end') + } +}; \ No newline at end of file diff --git a/inputmethod/InputMethodTest_ets/entry/src/main/ets/test/List.test.ets b/inputmethod/InputMethodTest_ets/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1321a1d7f4b4b3f1d74213703ca46f1a17abd26e --- /dev/null +++ b/inputmethod/InputMethodTest_ets/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 inputMethodJSUnit from './inputMethodJSUnit'; +import inputMethodEngineJSUnit from './inputMethodEngineJSUnit'; + +export default function testsuite() { + inputMethodJSUnit(); + inputMethodEngineJSUnit(); +} \ No newline at end of file diff --git a/inputmethod/InputMethodTest_ets/entry/src/main/ets/test/Utils.ets b/inputmethod/InputMethodTest_ets/entry/src/main/ets/test/Utils.ets new file mode 100644 index 0000000000000000000000000000000000000000..4d27274069336154724453066b05559e3bbb3ea1 --- /dev/null +++ b/inputmethod/InputMethodTest_ets/entry/src/main/ets/test/Utils.ets @@ -0,0 +1,118 @@ +// @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. + */ + +export default class Utils { + static rect_left; + static rect_top; + static rect_right; + static rect_bottom; + static rect_value; + + static sleep(time) { + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve() + }, time) + }).then(() => { + console.info(`sleep ${time} over...`) + }) + } + + static getComponentRect(key) { + let strJson = getInspectorByKey(key); + let obj = JSON.parse(strJson); + console.info("====>[getInspectorByKey] current component obj is: " + JSON.stringify(obj)); + let rectInfo = JSON.parse('[' + obj.$rect + ']') + console.info("====>[getInspectorByKey] rectInfo is: " + rectInfo); + this.rect_left = JSON.parse('[' + rectInfo[0] + ']')[0] + this.rect_top = JSON.parse('[' + rectInfo[0] + ']')[1] + this.rect_right = JSON.parse('[' + rectInfo[1] + ']')[0] + this.rect_bottom = JSON.parse('[' + rectInfo[1] + ']')[1] + return this.rect_value = { + "left": this.rect_left, "top": this.rect_top, "right": this.rect_right, "bottom": this.rect_bottom + } + } + + static async swipe(downX, downY, upX, upY, steps) { + console.info('====>start to swipe') + this.drags(downX, downY, upX, upY, steps, false) + } + + static async drag(downX, downY, upX, upY, steps) { + console.info('====>start to drag') + this.drags(downX, downY, upX, upY, steps, true) + } + + static async drags(downX, downY, upX, upY, steps, drag) { + let xStep; + let yStep; + let swipeSteps; + let ret; + xStep = 0; + yStep = 0; + ret = false; + swipeSteps = steps; + if (swipeSteps == 0) { + swipeSteps = 1; + } + xStep = (upX - downX) / swipeSteps; + yStep = (upY - downY) / swipeSteps; + console.info('====>move step is: ' + 'xStep: ' + xStep + ' yStep: ' + yStep) + let downPonit: TouchObject = { + id: 1, + x: downX, + y: downY, + type: TouchType.Down, + } + console.info('====>down touch started: ' + JSON.stringify(downPonit)) + sendTouchEvent(downPonit); + console.info('====>start to move') + if (drag) { + await this.sleep(500) + } + for (let i = 1;i <= swipeSteps; i++) { + let movePoint: TouchObject = { + id: 1, + x: downX + (xStep * i), + y: downY + (yStep * i), + type: TouchType.Move + } + console.info('====>move touch started: ' + JSON.stringify(movePoint)) + ret = sendTouchEvent(movePoint) + if (ret == false) { + break; + } + await this.sleep(5) + } + console.info('====>start to up') + if (drag) { + await this.sleep(100) + } + let upPoint: TouchObject = { + id: 1, + x: upX, + y: upY, + type: TouchType.Up, + } + console.info('====>up touch started: ' + JSON.stringify(upPoint)) + sendTouchEvent(upPoint) + await this.sleep(500) + } +} + + + + diff --git a/inputmethod/InputMethodTest_ets/entry/src/main/ets/test/inputMethodEngineJSUnit.ets b/inputmethod/InputMethodTest_ets/entry/src/main/ets/test/inputMethodEngineJSUnit.ets new file mode 100644 index 0000000000000000000000000000000000000000..7322bb92ac27d21d086b3acf89706e63abb6a9bf --- /dev/null +++ b/inputmethod/InputMethodTest_ets/entry/src/main/ets/test/inputMethodEngineJSUnit.ets @@ -0,0 +1,717 @@ +/** + * 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 inputMethodEngine from '@ohos.inputMethodEngine'; +import Utils from './Utils'; +import router from '@system.router'; +import events_emitter from '@ohos.events.emitter'; + +export default function inputMethodEngineJSUnit() { + describe('appInfoTest_input_1', function () { + let mKeyboardDelegate = null; + let inputMethodEngineObject = inputMethodEngine.getInputMethodEngine(); + let textInputClient = null; + let kbController = null; + let KeyboardDelegate = null; + + console.info("====>************* inputMethodEngine Test start*************"); + beforeEach(async function (done) { + let options = { + uri: 'pages/input', + } + try { + router.clear(); + let pages = router.getState(); + if (!("input" == pages.name)) { + let result = await router.push(options); + await Utils.sleep(1000); + } + done(); + } catch (err) { + console.error("push input page error: " + err); + done(); + } + }); + + afterEach(async function () { + console.info("====>inputMethodEngine afterEach start:" + inputMethodEngineObject); + await Utils.sleep(1000); + }); + + it('inputMethodEngine_testOff_000', 0 , async function (done) { + inputMethodEngineObject.off('inputStart', (kbController, textInputClient) => { + console.info("====>inputMethodEngine beforeEach inputStart:" + JSON.stringify(kbController)); + console.info("====>inputMethodEngine beforeEach inputStart:" + JSON.stringify(textInputClient)); + }); + inputMethodEngineObject.off('keyboardShow', () => { + console.info("====>inputMethodEngine beforeEach keyboardShow:"); + }); + inputMethodEngineObject.off('keyboardHide', () => { + console.info("====>inputMethodEngine beforeEach keyboardHide:"); + }); + KeyboardDelegate = inputMethodEngine.createKeyboardDelegate(); + KeyboardDelegate.off('keyDown', (keyEvent) => { + console.info("====>inputMethodEngine beforeEach keyDown:" + keyEvent.keyCode); + expect(keyEvent.keyCode).assertEqual('1'); + + console.info("====>inputMethodEngine beforeEach keyDown:" + keyEvent.keyAction); + expect(keyEvent.keyAction).assertEqual('1'); + + }); + KeyboardDelegate.off('keyUp', (keyEvent) => { + console.info("====>inputMethodEngine beforeEach keyUp:" + keyEvent.keyCode); + expect(keyEvent.keyCode).assertEqual('1'); + console.info("====>inputMethodEngine beforeEach keyDown:" + keyEvent.keyAction); + expect(keyEvent.keyAction).assertEqual('0'); + + }); + KeyboardDelegate.off('cursorContextChange', (x, y, height) => { + console.info("====>inputMethodEngine beforeEach cursorContextChange x:" + x); + console.info("====>inputMethodEngine beforeEach cursorContextChange y:" + y); + console.info("====>inputMethodEngine beforeEach cursorContextChange height:" + height); + }); + KeyboardDelegate.off('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => { + console.info("====>inputMethodEngine beforeEach selectionChange oldBegin:" + oldBegin); + console.info("====>inputMethodEngine beforeEach selectionChange oldEnd:" + oldEnd); + console.info("====>inputMethodEngine beforeEach selectionChange newBegin:" + newBegin); + console.info("====>inputMethodEngine beforeEach selectionChange newEnd:" + newEnd); + }); + KeyboardDelegate.off('textChange', (text) => { + console.info("====>inputMethodEngine beforeEach textChange:" + text); + }); + done(); + }); + + it('inputMethodEngine_test_000', 0, async function (done) { + inputMethodEngineObject.on('inputStart', (kbController, textInputClient) => { + console.info("====>inputMethodEngine beforeEach inputStart:" + JSON.stringify(kbController)); + console.info("====>inputMethodEngine beforeEach inputStart:" + JSON.stringify(textInputClient)); + textInputClient = textInputClient; + kbController = kbController; + }); + inputMethodEngineObject.on('keyboardShow', () => { + console.info("====>inputMethodEngine beforeEach keyboardShow:"); + }); + inputMethodEngineObject.on('keyboardHide', () => { + console.info("====>inputMethodEngine beforeEach keyboardHide:"); + }); + mKeyboardDelegate = inputMethodEngine.createKeyboardDelegate(); + mKeyboardDelegate.on('keyDown', (keyEvent) => { + console.info("====>inputMethodEngine beforeEach keyDown:" + keyEvent.keyCode); + expect(keyEvent.keyCode).assertEqual('1'); + + console.info("====>inputMethodEngine beforeEach keyDown:" + keyEvent.keyAction); + expect(keyEvent.keyAction).assertEqual('1'); + + + }); + mKeyboardDelegate.on('keyUp', (keyEvent) => { + console.info("====>inputMethodEngine beforeEach keyUp:" + keyEvent.keyCode); + expect(keyEvent.keyCode).assertEqual('1'); + console.info("====>inputMethodEngine beforeEach keyDown:" + keyEvent.keyAction); + expect(keyEvent.keyAction).assertEqual('0'); + + }); + mKeyboardDelegate.on('cursorContextChange', (x, y, height) => { + console.info("====>inputMethodEngine beforeEach cursorContextChange x:" + x); + console.info("====>inputMethodEngine beforeEach cursorContextChange y:" + y); + console.info("====>inputMethodEngine beforeEach cursorContextChange height:" + height); + }); + mKeyboardDelegate.on('selectionChange', (oldBegin, oldEnd, newBegin, newEnd) => { + console.info("====>inputMethodEngine beforeEach selectionChange oldBegin:" + oldBegin); + console.info("====>inputMethodEngine beforeEach selectionChange oldEnd:" + oldEnd); + console.info("====>inputMethodEngine beforeEach selectionChange newBegin:" + newBegin); + console.info("====>inputMethodEngine beforeEach selectionChange newEnd:" + newEnd); + }); + mKeyboardDelegate.on('textChange', (text) => { + console.info("====>inputMethodEngine beforeEach textChange:" + text); + }); + done(); + }); + + it('inputMethodEngine_test_001', 0, async function (done) { + let keyType = inputMethodEngine.ENTER_KEY_TYPE_UNSPECIFIED; + console.info("====>inputMethodEngine_test_001 result:" + keyType); + expect(keyType).assertEqual(0); + done(); + }); + + it('inputMethodEngine_test_002', 0, async function (done) { + let keyType = inputMethodEngine.ENTER_KEY_TYPE_GO; + console.info("====>inputMethodEngine_test_002 result:" + keyType); + expect(keyType).assertEqual(2); + done(); + }); + + it('inputMethodEngine_test_003', 0, async function (done) { + let keyType = inputMethodEngine.ENTER_KEY_TYPE_SEARCH; + console.info("====>inputMethodEngine_test_003 result:" + keyType); + expect(keyType).assertEqual(3); + done(); + }); + + it('inputMethodEngine_test_004', 0, async function (done) { + let keyType = inputMethodEngine.ENTER_KEY_TYPE_SEND; + console.info("====>inputMethodEngine_test_004 result:" + keyType); + expect(keyType).assertEqual(4); + done(); + }); + + it('inputMethodEngine_test_005', 0, async function (done) { + let keyType = inputMethodEngine.ENTER_KEY_TYPE_NEXT; + console.info("====>inputMethodEngine_test_005 result:" + keyType); + expect(keyType).assertEqual(5); + done(); + }); + + it('inputMethodEngine_test_006', 0, async function (done) { + let keyType = inputMethodEngine.ENTER_KEY_TYPE_DONE; + console.info("====>inputMethodEngine_test_006 result:" + keyType); + expect(keyType).assertEqual(6); + done(); + }); + + it('inputMethodEngine_test_007', 0, async function (done) { + let keyType = inputMethodEngine.ENTER_KEY_TYPE_PREVIOUS; + console.info("====>inputMethodEngine_test_007 result:" + keyType); + expect(keyType).assertEqual(7); + done(); + }); + + it('inputMethodEngine_test_008', 0, async function (done) { + let keyType = inputMethodEngine.PATTERN_NULL; + console.info("====>inputMethodEngine_test_008 result:" + keyType); + expect(keyType).assertEqual(-1); + done(); + }); + + it('inputMethodEngine_test_009', 0, async function (done) { + let keyType = inputMethodEngine.PATTERN_TEXT; + console.info("====>inputMethodEngine_test_009 result:" + keyType); + expect(keyType).assertEqual(0); + done(); + }); + + it('inputMethodEngine_test_010', 0, async function (done) { + let keyType = inputMethodEngine.PATTERN_NUMBER; + console.info("====>inputMethodEngine_test_010 result:" + keyType); + expect(keyType).assertEqual(2); + done(); + }); + + it('inputMethodEngine_test_011', 0, async function (done) { + let keyType = inputMethodEngine.PATTERN_PHONE; + console.info("====>inputMethodEngine_test_011 result:" + keyType); + expect(keyType).assertEqual(3); + done(); + }); + + it('inputMethodEngine_test_012', 0, async function (done) { + let keyType = inputMethodEngine.PATTERN_DATETIME; + console.info("====>inputMethodEngine_test_012 result:" + keyType); + expect(keyType).assertEqual(4); + done(); + }); + + it('inputMethodEngine_test_013', 0, async function (done) { + let keyType = inputMethodEngine.PATTERN_EMAIL; + console.info("====>inputMethodEngine_test_013 result:" + keyType); + expect(keyType).assertEqual(5); + done(); + }); + + it('inputMethodEngine_test_014', 0, async function (done) { + let keyType = inputMethodEngine.PATTERN_URI; + console.info("====>inputMethodEngine_test_014 result:" + keyType); + expect(keyType).assertEqual(6); + done(); + }); + + it('inputMethodEngine_test_015', 0, async function (done) { + let keyType = inputMethodEngine.PATTERN_PASSWORD; + console.info("====>inputMethodEngine_test_015 result:" + keyType); + expect(keyType).assertEqual(7); + done(); + }); + + it('inputMethodEngine_test_016', 0, async function (done) { + let keyType = inputMethodEngine.FLAG_SELECTING; + console.info("====>inputMethodEngine_test_016 result:" + keyType); + expect(keyType).assertEqual(2); + done(); + }); + + it('inputMethodEngine_test_017', 0, async function (done) { + let keyType = inputMethodEngine.FLAG_SINGLE_LINE; + console.info("====>inputMethodEngine_test_017 result:" + keyType); + expect(keyType).assertEqual(1); + done(); + }); + + it('inputMethodEngine_test_018', 0, async function (done) { + let keyType = inputMethodEngine.DISPLAY_MODE_PART; + console.info("====>inputMethodEngine_test_018 result:" + keyType); + expect(keyType).assertEqual(0); + done(); + }); + + it('inputMethodEngine_test_019', 0, async function (done) { + let keyType = inputMethodEngine.DISPLAY_MODE_FULL; + console.info("====>inputMethodEngine_test_019 result:" + keyType); + expect(keyType).assertEqual(1); + done(); + }); + + it('inputMethodEngine_test_020', 0, async function (done) { + let keyType = inputMethodEngine.OPTION_ASCII; + console.info("====>inputMethodEngine_test_020 result:" + keyType); + expect(keyType).assertEqual(20); + done(); + }); + + it('inputMethodEngine_test_021', 0, async function (done) { + let keyType = inputMethodEngine.OPTION_NONE; + console.info("====>inputMethodEngine_test_021 result:" + keyType); + expect(keyType).assertEqual(0); + done(); + }); + + it('inputMethodEngine_test_022', 0, async function (done) { + let keyType = inputMethodEngine.OPTION_AUTO_CAP_CHARACTERS; + console.info("====>inputMethodEngine_test_022 result:" + keyType); + expect(keyType).assertEqual(2); + done(); + }); + + it('inputMethodEngine_test_023', 0, async function (done) { + let keyType = inputMethodEngine.OPTION_AUTO_CAP_SENTENCES; + console.info("====>inputMethodEngine_test_023 result:" + keyType); + expect(keyType).assertEqual(8); + done(); + }); + + it('inputMethodEngine_test_024', 0, async function (done) { + let keyType = inputMethodEngine.OPTION_AUTO_WORDS; + console.info("====>inputMethodEngine_test_024 result:" + keyType); + expect(keyType).assertEqual(4); + done(); + }); + + it('inputMethodEngine_test_025', 0, async function (done) { + let keyType = inputMethodEngine.OPTION_MULTI_LINE; + console.info("====>inputMethodEngine_test_025 result:" + keyType); + expect(keyType).assertEqual(1); + done(); + }); + + it('inputMethodEngine_test_026', 0, async function (done) { + let keyType = inputMethodEngine.OPTION_NO_FULLSCREEN; + console.info("====>inputMethodEngine_test_026 result:" + keyType); + expect(keyType).assertEqual(10); + done(); + }); + + it('inputMethodEngine_test_027', 0, async function (done) { + + let rect = await Utils.getComponentRect('TextInput') + console.info("====>[inputMethodEngine_test_027] rectInfo is " + rect); + console.info("====>[inputMethodEngine_test_027] rectInfo is " + JSON.stringify(rect)); + let x_value = rect.left + (rect.right - rect.left) / 10 + + let y_value = rect.top + (rect.bottom - rect.top) / 10 + console.info("====>[inputMethodEngine_test_027] onTouch location is: " + "[x]=== " + x_value + " [y]===" + y_value); + let point: TouchObject = { + id: 1, + x: x_value, + y: y_value, + type: TouchType.Move, + screenX: rect.left + (rect.right - rect.left) / 10, + screenY: rect.left + (rect.right - rect.left) / 10, + } + console.info('====>[inputMethodEngine_test_027] testSendTouchEvent ' + sendTouchEvent(point)); + await Utils.sleep(1000) + console.info('====>[inputMethodEngine_test_027] END'); + done(); + }); + + it('inputMethodEngine_test_028', 0, async function (done) { + if (textInputClient == null) { + expect(textInputClient == null).assertEqual(true); + } else { + textInputClient.sendKeyFunction(0, (value) => { + console.info("====>inputMethodEngine_test_028 textInputClient sendKeyFunction:" + value); + expect(value).assertEqual(true); + }); + } + done(); + }); + + it('inputMethodEngine_test_029', 0, async function (done) { + if (textInputClient == null) { + expect(textInputClient == null).assertEqual(true); + } else { + let promise = textInputClient.sendKeyFunction(0); + promise.then(res => { + console.info("====>inputMethodEngine_test_029 listInputMethod promise result-----" + JSON.stringify(res)); + expect(res).assertEqual(true); + }).catch(err => { + console.info("====>inputMethodEngine_test_029 listInputMethod promise error----" + JSON.stringify(err)); + expect().assertFail(); + }); + } + done(); + }); + + it('inputMethodEngine_test_030', 0, async function (done) { + if (textInputClient == null) { + expect(textInputClient == null).assertEqual(true); + } else { + textInputClient.deleteForward(1, (value) => { + console.info("====>inputMethodEngine_test_030 deleteForward:" + value); + expect(value).assertEqual(true); + }); + } + done(); + }); + + it('inputMethodEngine_test_031', 0, async function (done) { + if (textInputClient == null) { + expect(textInputClient == null).assertEqual(true); + } else { + let promise = textInputClient.deleteForward(1); + promise.then(res => { + console.info("====>inputMethodEngine_test_031 deleteForward promise result-----" + JSON.stringify(res)); + expect(res).assertEqual(true); + }).catch(err => { + console.info("====>inputMethodEngine_test_031 deleteForward promise error----" + JSON.stringify(err)); + expect().assertFail(); + }); + } + done(); + }); + + it('inputMethodEngine_test_032', 0, async function (done) { + if (textInputClient == null) { + expect(textInputClient == null).assertEqual(true); + } else { + textInputClient.deleteBackward(1, (value) => { + console.info("====>inputMethodEngine_test_032 deleteBackward:" + value); + expect(value).assertEqual(true); + }); + } + done(); + }); + + it('inputMethodEngine_test_033', 0, async function (done) { + if (textInputClient == null) { + expect(textInputClient == null).assertEqual(true); + } else { + let promise = textInputClient.deleteBackward(1); + promise.then(res => { + console.info("====>inputMethodEngine_test_033 deleteBackward promise result-----" + JSON.stringify(res)); + expect(res).assertEqual(true); + }).catch(err => { + console.info("====>inputMethodEngine_test_033 deleteBackward promise error----" + JSON.stringify(err)); + expect().assertFail(); + }); + } + done(); + }); + + it('inputMethodEngine_test_034', 0, async function (done) { + if (textInputClient == null) { + expect(textInputClient == null).assertEqual(true); + } else { + textInputClient.InsertText('test', (value) => { + console.info("====>inputMethodEngine_test_034 InsertText:" + value); + expect(value).assertEqual(true); + }); + } + done(); + }); + + it('inputMethodEngine_test_035', 0, async function (done) { + if (textInputClient == null) { + expect(textInputClient == null).assertEqual(true); + } else { + let promise = textInputClient.InsertText('test'); + promise.then(res => { + console.info("====>inputMethodEngine_test_035 InsertText promise result-----" + JSON.stringify(res)); + expect(res).assertEqual(true); + }).catch(err => { + console.info("====>inputMethodEngine_test_035 InsertText promise error----" + JSON.stringify(err)); + expect().assertFail(); + }); + } + done(); + }); + + it('inputMethodEngine_test_036', 0, async function (done) { + if (textInputClient == null) { + expect(textInputClient == null).assertEqual(true); + } else { + textInputClient.getForward(1, (value) => { + console.info("====>inputMethodEngine_test_036 getForward:" + value); + expect(value).assertEqual(true); + }); + } + done(); + }); + + it('inputMethodEngine_test_037', 0, async function (done) { + if (textInputClient == null) { + expect(textInputClient == null).assertEqual(true); + } else { + let promise = textInputClient.getForward(1); + promise.then(res => { + console.info("====>inputMethodEngine_test_037 getForward promise result-----" + JSON.stringify(res)); + expect(res).assertEqual(true); + }).catch(err => { + console.info("====>inputMethodEngine_test_037 getForward promise error----" + JSON.stringify(err)); + expect().assertFail(); + }); + } + done(); + }); + + it('inputMethodEngine_test_038', 0, async function (done) { + if (textInputClient == null) { + expect(textInputClient == null).assertEqual(true); + } else { + textInputClient.getEditorAttribute(1, (editorAttribute) => { + console.info("====>inputMethodEngine_test_038 getEditorAttribute:" + editorAttribute); + expect(editorAttribute.inputPattern).assertEqual(1); + expect(editorAttribute.enterKeyType).assertEqual(1); + }); + } + done(); + }); + + it('inputMethodEngine_test_039', 0, async function (done) { + if (textInputClient == null) { + expect(textInputClient == null).assertEqual(true); + } else { + let promise = textInputClient.getEditorAttribute(); + promise.then(res => { + console.info("====>inputMethodEngine_test_039 getEditorAttribute promise result-----" + JSON.stringify(res)); + expect(res.inputPattern).assertEqual(1); + expect(res.enterKeyType).assertEqual(1); + }).catch(err => { + console.info("====>inputMethodEngine_test_039 getEditorAttribute promise error----" + JSON.stringify(err)); + expect().assertFail(); + }); + } + done(); + }); + + it('inputMethodEngine_test_040', 0, async function (done) { + if (kbController == null) { + expect(kbController == null).assertEqual(true); + } else { + kbController.hideKeyboard(() => { + console.info("====>inputMethodEngine_test_040 hideKeyboard"); + expect(1 == 1).assertTrue(); + }); + } + done(); + }); + + it('inputMethodEngine_test_041', 0, async function (done) { + if (kbController == null) { + expect(kbController == null).assertEqual(true); + } else { + let promise = kbController.hideKeyboard(); + promise.then(res => { + console.info("====>inputMethodEngine_test_041 hideKeyboard promise result-----" + JSON.stringify(res)); + expect(1 == 1).assertTrue(); + }).catch(err => { + console.info("====>inputMethodEngine_test_041 hideKeyboard promise error----" + JSON.stringify(err)); + expect().assertFail(); + }); + } + done(); + }); + + it('inputMethodEngine_test_042', 0, async function (done) { + if (textInputClient == null) { + expect(textInputClient == null).assertEqual(true); + } else { + textInputClient.getBackward(1, (value) => { + console.info("====>inputMethodEngine_test_042 getBackward:" + value); + expect(value).assertEqual(true); + }); + } + done(); + }); + + it('inputMethodEngine_test_043', 0, async function (done) { + if (textInputClient == null) { + expect(textInputClient == null).assertEqual(true); + } else { + let promise = textInputClient.getBackward(1); + promise.then(res => { + console.info("====>inputMethodEngine_test_043 getBackward promise result-----" + JSON.stringify(res)); + expect(res).assertEqual(true); + }).catch(err => { + console.info("====>inputMethodEngine_test_043 getBackward promise error----" + JSON.stringify(err)); + expect().assertFail(); + }); + } + done(); + }); + + it('inputMethodEngine_test_044', 0, async function (done) { + let keyType = inputMethodEngine.WINDOW_TYPE_INPUT_METHOD_FLOAT; + console.error("inputMethodEngine_test_044 result:" + keyType); + expect(keyType == 2105).assertTrue(); + done(); + }); + + it('inputMethodEngine_test_045', 0, async function (done) { + if (textInputClient == null) { + expect(textInputClient == null).assertEqual(true); + } else { + textInputClient.moveCursor(inputMethodEngine.CURSOR_UP, (value) => { + console.info("====>inputMethodEngine_test_045 moveCursor:" + value); + expect(value == null).assertEqual(true); + }); + } + done(); + }); + + it('inputMethodEngine_test_046', 0, async function (done) { + if (textInputClient == null) { + expect(textInputClient == null).assertEqual(true); + } else { + textInputClient.moveCursor(inputMethodEngine.CURSOR_DOWN, (value) => { + console.info("====>inputMethodEngine_test_046 moveCursor:" + value); + expect(value == null).assertEqual(true); + }); + } + done(); + }) + + it('inputMethodEngine_test_047', 0, async function (done) { + if (textInputClient == null) { + expect(textInputClient == null).assertEqual(true); + } else { + textInputClient.moveCursor(inputMethodEngine.CURSOR_LEFT).then(res => { + console.info("====>inputMethodEngine_test_047 moveCursor promise result-----" + JSON.stringify(res)); + expect(res == null).assertEqual(true); + }).catch(err => { + console.info("====>inputMethodEngine_test_047 moveCursor promise error----" + JSON.stringify(err)); + expect().assertFail(); + }); + } + done(); + }) + + it('inputMethodEngine_test_048', 0, async function (done) { + if (textInputClient == null) { + expect(textInputClient == null).assertEqual(true); + } else { + textInputClient.moveCursor(inputMethodEngine.CURSOR_RIGHT).then(res => { + console.info("====>inputMethodEngine_test_048 moveCursor promise result-----" + JSON.stringify(res)); + expect(res == null).assertEqual(true); + }).catch(err => { + console.info("====>inputMethodEngine_test_048 moveCursor promise error----" + JSON.stringify(err)); + expect().assertFail(); + }); + } + done(); + }) + + it('inputMethodEngine_test_049', 0, async function (done) { + if (kbController == null) { + expect(kbController == null).assertEqual(true); + } else { + kbController.hide(() => { + console.info("====>inputMethodEngine_test_049 hideKeyboard:"); + expect(1 == 1).assertTrue(); + }); + } + done(); + }); + + it('inputMethodEngine_test_050', 0, async function (done) { + if (kbController == null) { + expect(kbController == null).assertEqual(true); + } else { + let promise = kbController.hide(); + promise.then(res => { + console.info("====>inputMethodEngine_test_050 hideKeyboard promise result-----" + JSON.stringify(res)); + expect(1 == 1).assertTrue(); + }).catch(err => { + console.info("====>inputMethodEngine_test_050 hideKeyboard promise error----" + JSON.stringify(err)); + expect().assertFail(); + }); + } + done(); + }); + + /* + * @tc.number inputMethodEngine_test_getInputMethodAbility_001 + * @tc.name InputMethodAbility object of the current input method. + * @tc.desc Function test + * @tc.level 2 + */ + it('inputMethodEngine_test_getInputMethodAbility_001', 0, async function (done) { + console.info("====>-----------------inputMethodEngine_test_getInputMethodAbility_001 start---------------------"); + try{ + let inputMethodAbility = inputMethodEngine.getInputMethodAbility(); + console.info("====>inputMethodEngine_test_getInputMethodAbility_001 result:" + typeof inputMethodAbility); + if(typeof inputMethodAbility == "object" ){ + console.info("====>inputMethodEngine_test_getInputMethodAbility_001 getCurrentInputMethodSubtype success"); + expect(true).assertTrue(); + }else{ + console.info("====>inputMethodEngine_test_getInputMethodAbility_001 getCurrentInputMethodSubtype failed"); + expect().assertFail(); + }; + }catch(error){ + console.info("====>inputMethodEngine_test_getInputMethodAbility_001 getCurrentInputMethodSubtype error" + JSON.stringify(error)); + expect().assertFail(); + } + console.info("====>-----------------inputMethodEngine_test_getInputMethodAbility_001 end---------------------"); + done(); + }); + + /* + * @tc.number inputMethodEngine_test_getKeyboardDelegate_001 + * @tc.name KeyboardDelegate object of the current input method. + * @tc.desc Function test + * @tc.level 2 + */ + it('inputMethodEngine_test_getKeyboardDelegate_001', 0, async function (done) { + console.info("====>-----------------inputMethodEngine_test_getKeyboardDelegate_001 start---------------------"); + try{ + let inputMethodAbility = inputMethodEngine.getKeyboardDelegate(); + console.info("====>inputMethodEngine_test_getKeyboardDelegate_001 result:" + typeof inputMethodAbility); + if(typeof inputMethodAbility == "object" ){ + console.info("====>inputMethodEngine_test_getKeyboardDelegate_001 getCurrentInputMethodSubtype success"); + expect(true).assertTrue(); + }else{ + console.info("====>inputMethodEngine_test_getKeyboardDelegate_001 getCurrentInputMethodSubtype failed"); + expect().assertFail(); + }; + }catch(error){ + console.info("====>inputMethodEngine_test_getKeyboardDelegate_001 getCurrentInputMethodSubtype error" + JSON.stringify(error)); + expect().assertFail(); + } + console.info("====>-----------------inputMethodEngine_test_getKeyboardDelegate_001 end---------------------"); + done(); + }); + + }) +} diff --git a/inputmethod/InputMethodTest_ets/entry/src/main/ets/test/inputMethodJSUnit.ets b/inputmethod/InputMethodTest_ets/entry/src/main/ets/test/inputMethodJSUnit.ets new file mode 100644 index 0000000000000000000000000000000000000000..d1214bb56a776fd57108b6d3917b483149c5b76d --- /dev/null +++ b/inputmethod/InputMethodTest_ets/entry/src/main/ets/test/inputMethodJSUnit.ets @@ -0,0 +1,343 @@ +/** + * 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 inputMethod from '@ohos.inputMethod'; + +export default function inputMethodJSUnit() { + describe('appInfoTest_input_2', function () { + console.info("====>************* settings Test start*************"); + it('inputmethoh_test_001', 0, async function (done) { + let inputMethodSetting = inputMethod.getInputMethodSetting(); + console.info("====>inputmethoh_test_001 result:" + JSON.stringify(inputMethodSetting)); + inputMethodSetting.listInputMethod((arr) => { + console.info("====>appInfoTest_input_2 listInputMethod result---" + JSON.stringify(arr)); + expect(1 == 1).assertTrue(); + done(); + }); + }); + + it('inputmethoh_test_002', 0, async function (done) { + let inputMethodSetting = inputMethod.getInputMethodSetting(); + console.info("====>inputmethoh_test_002 result:" + JSON.stringify(inputMethodSetting)); + inputMethodSetting.listInputMethod().then(inputMethodProperty => { + if (inputMethodProperty.length > 0) { + let obj = inputMethodProperty[0] + console.info("====>inputmethoh_test_002 listInputMethod obj---" + JSON.stringify(obj)); + expect(obj.packageName != null).assertTrue(); + expect(obj.methodId != null).assertTrue(); + } else { + console.info("====>inputmethoh_test_002 listInputMethod is null"); + expect().assertFail() + } + done(); + }).catch(err => { + console.info("====>inputmethoh_test_002 listInputMethod is err: " + JSON.stringify(err)); + done(); + }); + }); + + it('inputmethoh_test_003', 0, async function (done) { + let inputMethodSetting = inputMethod.getInputMethodSetting(); + console.info("====>inputmethoh_test_003 result:" + JSON.stringify(inputMethodSetting)); + setTimeout(() => { + inputMethodSetting.displayOptionalInputMethod((err) => { + try { + if (err) { + console.info("====>inputmethoh_test_003 displayOptionalInputMethod err:" + JSON.stringify(err)); + expect().assertFail(); + done(); + } + expect(true).assertTrue(); + console.info("====>inputmethoh_test_003 displayOptionalInputMethod---"); + done(); + } catch (err) { + console.info("====>inputmethoh_test_004 displayOptionalInputMethod throw_err: " + JSON.stringify(err)); + done(); + } + }); + }, 500) + }); + + it('inputmethoh_test_004', 0, async function (done) { + let inputMethodSetting = inputMethod.getInputMethodSetting(); + console.info("====>inputmethoh_test_004 result:" + JSON.stringify(inputMethodSetting)); + setTimeout(() => { + inputMethodSetting.displayOptionalInputMethod().then(() => { + console.info("====>inputmethoh_test_004 displayOptionalInputMethod is called"); + expect(true).assertTrue() + done(); + }).catch(err => { + console.info("====>inputmethoh_test_004 displayOptionalInputMethod is err: " + JSON.stringify(err)); + expect().assertFail() + done(); + }); + }, 500) + }); + + it('inputmethoh_test_005', 0, async function (done) { + let inputMethodCtrl = inputMethod.getInputMethodController(); + console.info("====>inputmethoh_test_005 result:" + JSON.stringify(inputMethodCtrl)); + inputMethodCtrl.stopInput((res) => { + console.info("====>inputmethoh_test_005 stopInput result----" + res); + done(); + }); + }); + + it('inputmethoh_test_006', 0, async function (done) { + let inputMethodCtrl = inputMethod.getInputMethodController(); + console.info("====>inputmethoh_test_006 result:" + JSON.stringify(inputMethodCtrl)); + inputMethodCtrl.stopInput().then(() => { + expect().assertFail(); + done(); + }).catch((err) => { + console.info("====>inputmethoh_test_006 stopInput is err: " + JSON.stringify(err)); + expect().assertEqual(); + done(); + }); + }); + + /* + * @tc.number: inputmethod_test_MAX_TYPE_NUM_001 + * @tc.name: inputMethod::MAX_TYPE_NUM + * @tc.desc: Verify Max_ TYPE_ NUM + */ + it('inputmethod_test_MAX_TYPE_NUM_001', 0, async function (done) { + console.info("====>************* inputmethod_test_MAX_TYPE_NUM_001 Test start*************"); + let inputMethodSetting = inputMethod.MAX_TYPE_NUM; + console.info("====>inputmethod_test_001 result:" + inputMethodSetting); + expect(inputMethodSetting !== null).assertTrue(); + console.info("====>************* inputmethod_test_MAX_TYPE_NUM_001 Test end*************"); + done(); + }); + + /* + * @tc.number inputmethod_test_switchInputMethod_001 + * @tc.name Test Indicates the input method which will replace the current one. + * @tc.desc Function test + * @tc.level 2 + */ + it('inputmethod_test_switchInputMethod_001', 0, async function (done) { + console.info("====>************* inputmethod_test_switchInputMethod_001 Test start*************"); + let inputM = inputMethod.getCurrentInputMethod() + console.info("inputmethod_test_switchInputMethod_001 getCurrentInputMethod: " + JSON.stringify(inputM)); + let inputMethodProperty = { + packageName: inputM.packageName, + methodId: inputM.methodId, + name: inputM.packageName, + id: inputM.methodId, + extra: {} + } + inputMethod.switchInputMethod(inputMethodProperty).then(data => { + console.info("====>inputmethod_test_switchInputMethod_001 data:" + data) + expect(data == true).assertTrue(); + console.info("====>************* inputmethod_test_switchInputMethod_001 Test end*************"); + done(); + }).catch(err => { + console.info("====>inputmethod_test_switchInputMethod_001 err:" + err) + expect().assertFail(); + done(); + }); + }); + + /* + * @tc.number inputmethod_test_switchInputMethod_002 + * @tc.name Test Indicates the input method which will replace the current one. + * @tc.desc Function test + * @tc.level 2 + */ + it('inputmethod_test_switchInputMethod_002', 0, async function (done) { + console.info("====>************* inputmethod_test_switchInputMethod_002 Test start*************"); + let inputM = inputMethod.getCurrentInputMethod() + console.info("inputmethod_test_switchInputMethod_002 getCurrentInputMethod: " + JSON.stringify(inputM)); + let inputMethodProperty = { + packageName: inputM.packageName, + methodId: inputM.methodId, + name: inputM.packageName, + id: inputM.methodId, + extra: {} + } + inputMethod.switchInputMethod(inputMethodProperty, (err, data) => { + try { + if (err) { + console.info("====>inputmethod_test_switchInputMethod_002 error:" + err); + expect().assertFail(); + done(); + } + console.info("====>inputmethod_test_switchInputMethod_002 data:" + data) + console.info("====>************* inputmethod_test_switchInputMethod_002 Test end*************"); + expect(data == true).assertTrue(); + done(); + } catch (err) { + console.info("====>inputmethod_test_switchInputMethod_002 catch error:" + err); + done(); + } + }); + }); + + /* + * @tc.number inputmethod_test_showSoftKeyboard_001 + * @tc.name Test Indicates the input method which will show softboard with calback. + * @tc.desc Function test + * @tc.level 2 + */ + it('inputmethod_test_showSoftKeyboard_001', 0, async function (done) { + let inputMethodCtrl = inputMethod.getInputMethodController() + inputMethodCtrl.showSoftKeyboard((err) => { + try { + expect(err.code).assertEqual(12800003) + console.info("====>************* inputmethod_test_showSoftKeyboard_001 Test end*************"); + done(); + } catch (err) { + expect().assertFail() + done(); + } + }); + }); + + /* + * @tc.number inputmethod_test_showSoftKeyboard_002 + * @tc.name Test Indicates the input method which will show softboard with Promise. + * @tc.desc Function test + * @tc.level 2 + */ + it('inputmethod_test_showSoftKeyboard_002', 0, async function (done) { + let inputMethodCtrl = inputMethod.getInputMethodController() + inputMethodCtrl.showSoftKeyboard().then(() => { + expect().assertFail() + done(); + }).catch((err) => { + console.info('====>showSoftKeyboard promise failed : ' + JSON.stringify(err)) + console.info('====>showSoftKeyboard typeof(err.code): ' + typeof(err.code)) + console.info('====>showSoftKeyboard typeof(err.code): ' + err.code) + expect(err.code).assertEqual(12800003) + console.info("====>************* inputmethod_test_showSoftKeyboard_002 Test end*************"); + done(); + }) + }); + + /* + * @tc.number inputmethod_test_hideSoftKeyboard_001 + * @tc.name Test Indicates the input method which will hide softboard with calback. + * @tc.desc Function test + * @tc.level 2 + */ + it('inputmethod_test_hideSoftKeyboard_001', 0, async function (done) { + let inputMethodCtrl = inputMethod.getInputMethodController() + inputMethodCtrl.hideSoftKeyboard((err) => { + try { + console.info('====>hideSoftKeyboard callbacek failed : ' + JSON.stringify(err)) + expect(err.code).assertEqual(12800003) + console.info("====>************* inputmethod_test_hideSoftKeyboard_001 Test end*************"); + done(); + } catch (err) { + expect().assertFail(); + done(); + } + }) + }); + + /* + * @tc.number inputmethod_test_hideSoftKeyboard_002 + * @tc.name Test Indicates the input method which will hide softboard with Promise. + * @tc.desc Function test + * @tc.level 2 + */ + it('inputmethod_test_hideSoftKeyboard_002', 0, async function (done) { + let inputMethodCtrl = inputMethod.getInputMethodController() + inputMethodCtrl.hideSoftKeyboard().then(() => { + expect().assertFail(); + done(); + }).catch((err) => { + console.info('====>hideSoftKeyboard promise failed : ' + JSON.stringify(err)) + expect(err.code).assertEqual(12800003); + console.info("====>************* inputmethod_test_hideSoftKeyboard_002 Test end*************"); + done(); + }) + }); + + /* + * @tc.number inputmethod_test_getCurrentInputMethod_001 + * @tc.name return The InputMethodProperty object of the current input method. + * @tc.desc Function test + * @tc.level 2 + */ + it('inputmethod_test_getCurrentInputMethod_001', 0, async function (done) { + let currentIme = inputMethod.getCurrentInputMethod(); + console.info("====>inputmethod_test_getCurrentInputMethod_001 currentIme---" + JSON.stringify(currentIme)); + console.info(currentIme.packageName); + console.info(currentIme.methodId); + expect(currentIme.packageName !== null).assertTrue(); + expect(currentIme.methodId !== null).assertTrue(); + console.info("====>************* inputmethod_test_getCurrentInputMethod_001 Test end*************"); + done(); + }); + + /* + * @tc.number inputmethod_test_getInputMethods_001 + * @tc.name param enable : + * if true, collect enabled input methods. + * @tc.desc Function test + * @tc.level 2 + */ + it('inputmethod_test_getInputMethods_001', 0, async function (done) { + let inputMethodSetting = inputMethod.getInputMethodSetting(); + console.info("====>inputmethod_test_getInputMethods_001 result:" + JSON.stringify(inputMethodSetting)); + inputMethodSetting.getInputMethods(true, (err, arr) => { + try { + if (err) { + console.error("inputmethod_test_getInputMethods_001 failed because: " + JSON.stringify(err)); + expect().assertFail(); + done(); + } + ; + console.info("====>inputmethod_test_getInputMethods_001 listInputMethod result---" + JSON.stringify(arr)); + expect(arr != null).assertTrue(); + console.info("====>************* inputmethod_test_getInputMethods_001 Test end*************"); + done(); + } catch (err) { + console.error("inputmethod_test_getInputMethods_001 catch error: " + err); + done(); + } + }); + }); + + /* + * @tc.number inputmethod_test_getInputMethods_002 + * @tc.name param enable : + * if false, collect disabled input methods. + * @tc.desc Function test + * @tc.level 2 + */ + it('inputmethod_test_getInputMethods_002', 0, async function (done) { + let inputMethodSetting = inputMethod.getInputMethodSetting(); + console.info("====>inputmethod_test_getInputMethods_002 result:" + JSON.stringify(inputMethodSetting)); + inputMethodSetting.getInputMethods(false, (err, arr) => { + try { + if (err) { + console.error("inputmethod_test_getInputMethods_002 failed because: " + JSON.stringify(err)); + expect().assertFail(); + } + ; + console.info("====>inputmethod_test_getInputMethods_002 listInputMethod result---" + JSON.stringify(arr)); + expect(arr != null).assertTrue(); + done(); + } catch (err) { + console.error("inputmethod_test_getInputMethods_002 catch error: " + err); + done(); + } + }); + }); + }); +}; diff --git a/inputmethod/InputMethodTest_ets/entry/src/main/resources/base/element/string.json b/inputmethod/InputMethodTest_ets/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..9d5dbe2a5e0c1274e294aec1c41a47153896580a --- /dev/null +++ b/inputmethod/InputMethodTest_ets/entry/src/main/resources/base/element/string.json @@ -0,0 +1,32 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "entry_MainAbility" + }, + { + "name": "description_mainability", + "value": "ETS_Empty Ability" + }, + { + "name":"string_hello", + "value":"Hello" + }, + { + "name":"string_world", + "value":"World" + }, + { + "name":"message_arrive", + "value":"We will arrive at %s." + }, + { + "name": "TestAbility_desc", + "value": "description" + }, + { + "name": "TestAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/inputmethod/InputMethodTest_ets/entry/src/main/resources/base/media/icon.png b/inputmethod/InputMethodTest_ets/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/inputmethod/InputMethodTest_ets/entry/src/main/resources/base/media/icon.png differ diff --git a/inputmethod/InputMethodTest_ets/signature/ActInputMethodEtsAPITest.p7b b/inputmethod/InputMethodTest_ets/signature/ActInputMethodEtsAPITest.p7b new file mode 100644 index 0000000000000000000000000000000000000000..cb5e550bce8c1a5439a39a509c693f9609df65e8 Binary files /dev/null and b/inputmethod/InputMethodTest_ets/signature/ActInputMethodEtsAPITest.p7b differ diff --git a/request/BUILD.gn b/request/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..49c17cc8d89c1f0c19af744e30569fa008d3e4fb --- /dev/null +++ b/request/BUILD.gn @@ -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("//build/ohos_var.gni") +group("request") { + testonly = true + deps = [ + "RequestTest_Stage:ActsRequestStageTest", + "RequestTest_ets:ActsRequestETSApiTest", + ] +} diff --git a/request/RequestTest_Stage/AppScope/app.json b/request/RequestTest_Stage/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..403c65552d49f91d873b308f6c2b4deec59744e4 --- /dev/null +++ b/request/RequestTest_Stage/AppScope/app.json @@ -0,0 +1,15 @@ +{ + "app": { + "bundleName": "com.acts.request.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/request/RequestTest_Stage/AppScope/resources/base/element/string.json b/request/RequestTest_Stage/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..066e1ff18115359423b0e6d99014273b2408bdee --- /dev/null +++ b/request/RequestTest_Stage/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ActsTimeAPITest" + } + ] +} diff --git a/request/RequestTest_Stage/AppScope/resources/base/media/app_icon.png b/request/RequestTest_Stage/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/request/RequestTest_Stage/AppScope/resources/base/media/app_icon.png differ diff --git a/request/RequestTest_Stage/BUILD.gn b/request/RequestTest_Stage/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..2f161101b40861f0b9ad79b01a858dc3bd0637bf --- /dev/null +++ b/request/RequestTest_Stage/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("ActsRequestStageTest") { + deps = [ + ":requestStage_ets_assets", + ":requestStage_resources", + ] + ets2abc = true + js_build_mode = "debug" + part_name = "request" + subsystem_name = "request" + hap_name = "ActsRequestStageTest" + hap_profile = "entry/src/main/module.json" + certificate_profile = "signature/actsRequestStageTest.p7b" +} + +ohos_app_scope("requestStage_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("requestStage_ets_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("requestStage_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":requestStage_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/request/RequestTest_Stage/Test.json b/request/RequestTest_Stage/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..0f199b048b463f8d0eabfc7fe7c9a81db57b9e82 --- /dev/null +++ b/request/RequestTest_Stage/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "180000", + "bundle-name": "com.acts.request.test", + "module-name": "entry_test", + "shell-timeout": "180000", + "testcase-timeout": 600000 + }, + "kits": [{ + "test-file-name": [ + "ActsRequestStageTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + }] +} diff --git a/request/RequestTest_Stage/entry/src/main/ets/Application/MyAbilityStage.ts b/request/RequestTest_Stage/entry/src/main/ets/Application/MyAbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..63c0efb17ceebd35073960da80893eb3040b0426 --- /dev/null +++ b/request/RequestTest_Stage/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/request/RequestTest_Stage/entry/src/main/ets/MainAbility/MainAbility.ts b/request/RequestTest_Stage/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..ef31b90804bc66568248b24b04826f672614b2f6 --- /dev/null +++ b/request/RequestTest_Stage/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,68 @@ +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'); + + globalThis.abilityContext = this.context; + + 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/request/RequestTest_Stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/request/RequestTest_Stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..c085dc5e02f8e192b2d2653863c6052e4c5dfe2b --- /dev/null +++ b/request/RequestTest_Stage/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,77 @@ +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("echo \"123456\" > /data/app/el2/100/base/com.acts.requesttest.test/haps/entry_test/cache/test.txt", + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }) + 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/request/RequestTest_Stage/entry/src/main/ets/pages/index.ets b/request/RequestTest_Stage/entry/src/main/ets/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..e79e73a090b5eee999cdb4a58182cc5d4c391d8c --- /dev/null +++ b/request/RequestTest_Stage/entry/src/main/ets/pages/index.ets @@ -0,0 +1,38 @@ +/** + * 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 = 'REQUEST 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/request/RequestTest_Stage/entry/src/main/ets/test/List.test.ets b/request/RequestTest_Stage/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c4e084fa5c203a4ba67bdc4942054b94bb8c660c --- /dev/null +++ b/request/RequestTest_Stage/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,22 @@ +/* + * 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 requestUploadJSUnit from './requestUpload.test'; +import requestDownloadJSUnit from './requestDownload.test'; + +export default function testsuite() { + requestDownloadJSUnit() + requestUploadJSUnit() +} \ No newline at end of file diff --git a/request/RequestTest_Stage/entry/src/main/ets/test/requestDownload.test.ets b/request/RequestTest_Stage/entry/src/main/ets/test/requestDownload.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b50ebc73f4774a85def6bc1871d05b5f591dd356 --- /dev/null +++ b/request/RequestTest_Stage/entry/src/main/ets/test/requestDownload.test.ets @@ -0,0 +1,626 @@ +/* + * 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 request from "@ohos.request"; +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function requestDownloadJSUnit() { + describe('requestDownloadJSUnit', function () { + console.info('====>################################request download Test start'); + + /** + * beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed. + */ + beforeAll(function () { + console.info('====>beforeAll: Prerequisites are executed.'); + }); + + /** + * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. + */ + beforeEach(function () { + console.info('====>beforeEach: Prerequisites is executed.'); + }); + + /** + * afterEach: Test case-level clearance conditions, which are executed after each test case is executed. + */ + afterEach(function () { + console.info('====>afterEach: Test case-level clearance conditions is executed.'); + }); + + /** + * afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed. + */ + afterAll(function () { + console.info('====>afterAll: Test suite-level cleanup condition is executed'); + }); + + let downloadTask; + + /** + * @tc.number SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 + * @tc.desc Starts a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001', 0, async function (done) { + console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 is starting-----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001.txt` + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001.txt`) + let downloadFileConfig = { + url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + header: { + headers: 'http' + }, + enableMetered: false, + enableRoaming: false, + description: 'XTS download test!', + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: 'XTS download test!', + background: false + } + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, data)=>{ + downloadTask = data; + console.info("====>SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 downloadTask: " + downloadTask); + try{ + expect(true).assertEqual(downloadTask != undefined); + await downloadTask.delete() + }catch(e){ + console.info("====>SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 except error: " + e); + } + console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_CALLBACK_0001 end-----------------------"); + done(); + }); + }); + + /** + * @tc.number SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 + * @tc.desc Starts a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001', 0, async function (done) { + console.info("-----------------------SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 is starting-----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001.txt` + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001.txt`) + let downloadFileConfig = { + url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + header: { + headers: 'http' + }, + enableMetered: false, + enableRoaming: false, + description: 'XTS download test!', + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: 'XTS download test!', + background: false + } + try{ + request.downloadFile(globalThis.abilityContext, downloadFileConfig).then(async (data) => { + downloadTask = data; + console.info("====>SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 downloadTask: " + downloadTask); + expect(true).assertEqual(downloadTask != undefined); + await downloadTask.delete() + done(); + }).catch(err => { + console.error("====>SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 error: " + err); + done(); + }) + }catch(err){ + console.error("====>SUB_REQUEST_downloadFile_STAGE_API_PROMISE_0001 catch error: " + err); + done(); + } + + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_DELETE_0001 + * @tc.desc Delete the download task. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_DELETE_0001', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_delete_0001 is starting-----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_DELETE_0001.txt` + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_DELETE_0001.txt`) + let downloadFileConfig = { + url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + header: { + headers: 'http' + }, + enableMetered: false, + enableRoaming: false, + description: 'XTS download test!', + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: 'XTS download test!', + background: false + } + request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => { + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 downloadTask: " + downloadTask); + try { + expect(downloadTask != undefined).assertEqual(true); + downloadTask.delete((err, data) => { + try{ + if (err) { + console.error('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 Failed to delete the download task.'); + expect().assertFail(); + } + console.info('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 Download task delete success.'); + expect(typeof data == "boolean").assertTrue(); + }catch(err){ + console.error('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 delete throw error' + err); + } + done(); + }); + } catch (error) { + console.error('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0001 delete catch error' + error); + done(); + } + }) + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_DELETE_0002 + * @tc.desc Delete the download task. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_DELETE_0002', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DELETE_0002 is starting-----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_DELETE_0002.txt` + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_DELETE_0002.txt`) + let downloadFileConfig = { + url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + header: { + headers: 'http' + }, + enableMetered: false, + enableRoaming: false, + description: 'XTS download test!', + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: 'XTS download test!', + background: false + } + request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => { + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 downloadTask: " + downloadTask); + try { + expect(downloadTask != undefined).assertEqual(true); + downloadTask.delete().then(data => { + console.info('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 Download task delete success.'); + expect(data).assertEqual(true); + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DELETE_0002 end-----------------------"); + done(); + }).catch((err) => { + console.info('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 Failed to delete the download task.'); + expect().assertFail(); + done(); + }) + } catch (error) { + console.error('====>SUB_REQUEST_DOWNLOAD_API_DELETE_0002 delete catch error'); + done(); + } + }) + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 + * @tc.desc Suspend the download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 is starting-----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001.txt` + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001.txt`) + let downloadFileConfig = { + url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + header: { + headers: 'http' + }, + enableMetered: false, + enableRoaming: false, + description: 'XTS download test!', + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: 'XTS download test!', + background: false + } + request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => { + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 downloadTask: " + downloadTask); + try{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.suspend((err, data) => { + try{ + if (err) { + console.error('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 Failed to suspend the download task.'); + expect().assertFail(); + } + console.info('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 Download task suspend success.'); + expect(data == true).assertTrue(); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 throw_error: " + JSON.stringify(err)); + } + done(); + }); + }catch(err){ + console.error('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0001 suspend catch error' + JSON.stringify(err)); + done(); + } + }) + + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 + * @tc.desc Suspend the download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 is starting-----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002.txt` + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002.txt`) + let downloadFileConfig = { + url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + header: { + headers: 'http' + }, + enableMetered: false, + enableRoaming: false, + description: 'XTS download test!', + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: 'XTS download test!', + background: false + } + request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => { + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 downloadTask: " + downloadTask); + try{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.suspend().then(data => { + console.info('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 Download task suspend success.'); + expect(data == true).assertTrue(); + done(); + }).catch((err) => { + console.info('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 throw_err:' + JSON.stringify(err)); + done(); + }) + }catch(err){ + console.error('====>SUB_REQUEST_DOWNLOAD_API_SUSPEND_0002 suspend catch error' + JSON.stringify(err)); + done(); + } + }) + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 + * @tc.desc Restore the download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_RESTORE_0001', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 is starting-----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_RESTORE_0001.txt` + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_RESTORE_0001.txt`) + let downloadFileConfig = { + url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + header: { + headers: 'http' + }, + enableMetered: false, + enableRoaming: false, + description: 'XTS download test!', + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: 'XTS download test!', + background: false + } + request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => { + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 downloadTask: " + downloadTask); + try{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.restore((err, data) => { + try{ + if (err) { + console.error('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 Failed to restore the download task.'); + expect().assertFail(); + } + console.info('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 Download restore success.'); + expect(data == true).assertTrue(); + }catch(err){ + console.info('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 throw_err:' + JSON.stringify(err)); + } + done(); + }); + }catch(err){ + console.error('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0001 restore catch error' + JSON.stringify(err)); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 + * @tc.desc Restore the download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_RESTORE_0002', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 is starting-----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_RESTORE_0002.txt` + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_RESTORE_0002.txt`) + let downloadFileConfig = { + url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + header: { + headers: 'http' + }, + enableMetered: false, + enableRoaming: false, + description: 'XTS download test!', + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: 'XTS download test!', + background: false + } + request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => { + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 downloadTask: " + downloadTask); + try{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.restore().then(data => { + console.info('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 Download task restore.'); + expect(data == true).assertTrue(); + done(); + }).catch((err) => { + console.info('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 Failed to restore the download task.'); + done(); + }); + }catch(err){ + console.error('====>SUB_REQUEST_DOWNLOAD_API_RESTORE_0002 restore catch error' +JSON.stringify(err)); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 + * @tc.desc Get the download task info + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001', 0, async function (done) { + console.info("====>---------------------SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 is starting---------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001.txt` + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001.txt`) + let downloadFileConfig = { + url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + header: { + headers: 'http' + }, + enableMetered: false, + enableRoaming: false, + description: 'XTS download test!', + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: 'XTS download test!', + background: false + } + request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => { + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 downloadTask: " + downloadTask); + try{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.getTaskInfo((err, data) => { + try{ + if (err) { + console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 Failed to getTaskInfo the download task.'); + expect().assertFail(); + } + console.info('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 Download getTaskInfo success.'); + expect(typeof data == "object").assertTrue(); + }catch(err){ + console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 throw_error' +JSON.stringify(err)); + } + done(); + }); + }catch(err){ + console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0001 getTaskInfo catch error' + JSON.stringify(err)); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 + * @tc.desc Get the download task info + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002', 0, async function (done) { + console.info("====>-------------------SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 is starting----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002.txt` + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002.txt`) + let downloadFileConfig = { + url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + header: { + headers: 'http' + }, + enableMetered: false, + enableRoaming: false, + description: 'XTS download test!', + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: 'XTS download test!', + background: false + } + request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => { + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 downloadTask: " + downloadTask); + try{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.getTaskInfo().then(data => { + console.info('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 Download task getTaskInfo success.'); + expect(typeof data == "object").assertTrue(); + done(); + }).catch((err) => { + console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 Failed to getTaskInfo the download task.'); + done(); + }); + }catch(err){ + console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKINFO_0002 getTaskInfo catch error' + JSON.stringify(err)); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 + * @tc.desc Get mimetype of the download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001', 0, async function (done) { + console.info("====>---------------------SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 is starting---------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001.txt` + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001.txt`) + let downloadFileConfig = { + url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + header: { + headers: 'http' + }, + enableMetered: false, + enableRoaming: false, + description: 'XTS download test!', + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: 'XTS download test!', + background: false + } + request.downloadFile(globalThis.abilityContext, downloadFileConfig, (err, data) => { + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 downloadTask: " + downloadTask); + try{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.on('progress',(data1, data2) => { + try{ + if (data1 > 0){ + downloadTask.getTaskMimeType(async (err, data)=>{ + try{ + if(err) { + console.error('====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 err:'+ JSON.stringify(err)); + expect().assertFail(); + done(); + } + if (data) { + console.info('====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 data:' + JSON.stringify(data)); + expect(typeof data == "string").assertTrue(); + } else { + console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 error: " + JSON.stringify(err)); + expect().assertFail(); + } + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 throw_error: " + JSON.stringify(err)); + } + setTimeout(()=>{ + done(); + },1000) + }); + } + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 error: " + JSON.stringify(err)); + done(); + } + }) + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0001 error: " + JSON.stringify(err)); + done(); + } + }) + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 + * @tc.desc Get mimetype of the download task + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002', 0, async function (done) { + console.info("====>-------------------SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 is starting----------------------"); + let downloadFilePath = `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002.txt` + console.debug("====>downloadFileConfig:" + `${globalThis.abilityContext.tempDir}/SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002.txt`) + let downloadFileConfig = { + url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + header: { + headers: 'http' + }, + enableMetered: false, + enableRoaming: false, + description: 'XTS download test!', + networkType: request.NETWORK_WIFI, + filePath: downloadFilePath, + title: 'XTS download test!', + background: false + } + request.downloadFile(globalThis.abilityContext, downloadFileConfig, async (err, data) => { + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 downloadTask: " + downloadTask); + try{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.on('progress', async (data1, data2) => { + try{ + if(data1 > 0){ + let data = await downloadTask.getTaskMimeType() + console.info('====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 data:' + JSON.stringify(data)); + expect(typeof data == "string").assertTrue(); + } + setTimeout(()=>{ + done(); + },1000) + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 throw_error: " + JSON.stringify(err)); + done(); + } + }) + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_GETTASKMIMETYPE_0002 error: " + JSON.stringify(err)); + done(); + } + }) + }); + }); +} \ No newline at end of file diff --git a/request/RequestTest_Stage/entry/src/main/ets/test/requestUpload.test.ets b/request/RequestTest_Stage/entry/src/main/ets/test/requestUpload.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ae3541cf3dbc800cc0e92b941d4b8c20361ebe3 --- /dev/null +++ b/request/RequestTest_Stage/entry/src/main/ets/test/requestUpload.test.ets @@ -0,0 +1,208 @@ +/* + * 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 request from "@ohos.request"; +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'; + +export default function requestUploadJSUnit() { + describe('requestUploadJSUnit', function () { + console.info('====>################################request upload Test start'); + + /** + * beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed. + */ + beforeAll(function () { + console.info('====>beforeAll: Prerequisites are executed.'); + }); + + /** + * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. + */ + beforeEach(function () { + console.info('====>beforeEach: Prerequisites is executed.'); + }); + + /** + * afterEach: Test case-level clearance conditions, which are executed after each test case is executed. + */ + afterEach(function () { + console.info('====>afterEach: Test case-level clearance conditions is executed.'); + }); + + /** + * afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed. + */ + afterAll(function () { + console.info('====>afterAll: Test suite-level cleanup condition is executed'); + }); + + /** + * sleep function. + */ + function sleep(date, time){ + while(Date.now() - date <= time); + } + + let uploadTask; + let RequestData = { + name: 'name', + value: '123' + } + + let File = { + filename: 'test', + name: 'test', + uri: 'internal://cache/test.txt', + type: 'txt' + } + + let uploadConfig = { + url: 'http://127.0.0.1', + header: { + headers: 'http' + }, + method: 'POST', + files: [File], + data: [RequestData] + }; + + /** + * @tc.number SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 + * @tc.desc Starts a upload task. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001', 0, async function (done) { + console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 is starting-----------------------"); + try { + request.uploadFile(globalThis.abilityContext, uploadConfig, (err, data)=>{ + uploadTask = data; + console.info("====>SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 uploadFile: " + uploadTask); + try{ + expect(true).assertEqual(uploadTask != undefined); + }catch(e){ + console.info("====>SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 except error: " + e); + } + }); + } catch (err) { + console.error("====>SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 error: " + err); + }; + setTimeout(()=>{ + console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_CALLBACK_0001 end-----------------------"); + done(); + }, 10000); + }); + + /** + * @tc.number SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 + * @tc.desc Starts a upload task. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001', 0, async function (done) { + console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 is starting-----------------------"); + try{ + request.uploadFile(globalThis.abilityContext, uploadConfig).then(data => { + uploadTask = data; + console.info("====>SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 uploadFile: " + uploadTask); + try{ + expect(true).assertEqual(uploadTask != undefined); + }catch(e){ + console.info("====>SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 except error: " + e); + } + }).catch(err => { + console.error("====>SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 error: " + err); + expect().assertFail(); + }) + }catch(err){ + console.error("====>SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 catch error: " + err); + } + setTimeout(()=>{ + console.info("-----------------------SUB_REQUEST_uploadFile_STAGE_API_PROMISE_0001 end-----------------------"); + done(); + }, 10000); + }); + + /** + * @tc.number SUB_REQUEST_UPLOAD_API_DELETE_0001 + * @tc.desc Delete the upload task. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_UPLOAD_API_DELETE_0001', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0001 is starting-----------------------"); + request.uploadFile(globalThis.abilityContext, uploadConfig, (err, data) => { + try{ + uploadTask = data; + console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0001 uploadTask: " + uploadTask); + expect(uploadTask != undefined).assertEqual(true); + uploadTask.delete((err, data) => { + try{ + if (err) { + console.error('====>SUB_REQUEST_UPLOAD_API_DELETE_0001 Failed to delete the uploadTask task.'); + expect().assertFail(); + done(); + } + console.info('====>SUB_REQUEST_UPLOAD_API_DELETE_0001 uploadTask task delete success.'); + expect(typeof data == "boolean").assertTrue(); + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0001 end-----------------------"); + done(); + }catch(err){ + console.error('====>SUB_REQUEST_UPLOAD_API_DELETE_0001 delete error' + err); + done(); + } + }); + } catch (error) { + console.error('====>SUB_REQUEST_UPLOAD_API_DELETE_0001 delete catch error' + error); + done(); + } + }) + }); + + /** + * @tc.number SUB_REQUEST_UPLOAD_API_DELETE_0002 + * @tc.desc Delete the upload task. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_UPLOAD_API_DELETE_0002', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_DELETE_0002 is starting-----------------------"); + request.uploadFile(globalThis.abilityContext, uploadConfig, (err, data) => { + uploadTask = data; + console.info("====>SUB_REQUEST_UPLOAD_API_DELETE_0002 uploadTask: " + uploadTask); + try{ + expect(uploadTask != undefined).assertEqual(true); + uploadTask.delete().then(data => { + console.info('====>SUB_REQUEST_UPLOAD_API_DELETE_0002 delete data:' + JSON.stringify(data)); + expect(data).assertEqual(true); + done(); + }).catch((err) => { + console.info('====>SUB_REQUEST_UPLOAD_API_DELETE_0002 Failed to delete the uploadTask task.'); + expect().assertFail(); + done(); + }) + }catch(err){ + console.error('====>SUB_REQUEST_UPLOAD_API_DELETE_0002 delete catch err'); + done(); + } + }) + }); + }) +} diff --git a/request/RequestTest_Stage/entry/src/main/module.json b/request/RequestTest_Stage/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..6a33270fffbaffa702e19b230b25c412e7b84bad --- /dev/null +++ b/request/RequestTest_Stage/entry/src/main/module.json @@ -0,0 +1,69 @@ +{ + "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" + ] + } + ] + } + ], + "requestPermissions": [ + { + "name":"ohos.permission.INTERNET", + "reason":"need use ohos.permission.INTERNET." + }, + {"name": "ohos.permission.WRITE_MEDIA", + "reason": "need use ohos.permission.WRITE_MEDIA", + "usedScene": { + "ability": [ + "com.acts.request.test.MainAbility" + ], + "when":"always" + } + }, + {"name": "ohos.permission.READ_MEDIA", + "reason": "need use ohos.permission.WRITE_MEDIA", + "usedScene": { + "ability": [ + "com.acts.request.test.MainAbility" + ], + "when":"always" + } + } + ] + } +} \ No newline at end of file diff --git a/request/RequestTest_Stage/entry/src/main/resources/base/element/color.json b/request/RequestTest_Stage/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..62a137a61b90c14f109ed8c81d9d551ea0a5888a --- /dev/null +++ b/request/RequestTest_Stage/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/request/RequestTest_Stage/entry/src/main/resources/base/element/string.json b/request/RequestTest_Stage/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..03bb7d00f7c5bd5750f08b254e645f0d3f960804 --- /dev/null +++ b/request/RequestTest_Stage/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": "ActsTimeAPITest" + } + ] +} \ No newline at end of file diff --git a/request/RequestTest_Stage/entry/src/main/resources/base/media/icon.png b/request/RequestTest_Stage/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/request/RequestTest_Stage/entry/src/main/resources/base/media/icon.png differ diff --git a/request/RequestTest_Stage/entry/src/main/resources/base/profile/main_pages.json b/request/RequestTest_Stage/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..feec276e105eeb8d621c20aaf838f318b0a94150 --- /dev/null +++ b/request/RequestTest_Stage/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/index" + ] +} diff --git a/request/RequestTest_Stage/signature/actsRequestStageTest.p7b b/request/RequestTest_Stage/signature/actsRequestStageTest.p7b new file mode 100644 index 0000000000000000000000000000000000000000..ddafda90ca473d3c2ccba130ce913b65736dbe6e Binary files /dev/null and b/request/RequestTest_Stage/signature/actsRequestStageTest.p7b differ diff --git a/request/RequestTest_ets/BUILD.gn b/request/RequestTest_ets/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..fe28b739c45939b9b6a65555b26ed5e7548e4a24 --- /dev/null +++ b/request/RequestTest_ets/BUILD.gn @@ -0,0 +1,39 @@ +# 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("//build/ohos.gni") +import("//test/xts/tools/build/suite.gni") +ohos_js_hap_suite("ActsRequestETSApiTest") { + hap_profile = "./entry/src/main/config.json" + deps = [ + ":request_ets_assets", + ":request_ets_resources", + ":request_ets_test_assets", + ] + ets2abc = true + subsystem_name = "request" + part_name = "request" + certificate_profile = "./signature/ActsRequestETSApiTest.p7b" + hap_name = "ActsRequestETSApiTest" +} + +ohos_js_assets("request_ets_assets") { + source_dir = "./entry/src/main/ets/MainAbility" +} +ohos_js_assets("request_ets_test_assets") { + source_dir = "./entry/src/main/ets/TestAbility" +} +ohos_resources("request_ets_resources") { + sources = [ "./entry/src/main/resources" ] + hap_profile = "./entry/src/main/config.json" +} diff --git a/request/RequestTest_ets/Test.json b/request/RequestTest_ets/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..9a3c20b264d7bdb854fbb597ca465c1bd9df7388 --- /dev/null +++ b/request/RequestTest_ets/Test.json @@ -0,0 +1,22 @@ +{ + "description": "Configuration for MiscservicesRequestJSApiTest js api Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "600000", + "bundle-name": "com.acts.requesttest", + "package-name": "com.acts.requesttest", + "shell-timeout": "600000" + }, + "kits": [ + { + "test-file-name": ["ActsRequestETSApiTest.hap"], + "type": "AppInstallKit", + "cleanup-apps": true + }, + { + "type": "ShellKit", + "run-command": [ + ] + } + ] +} \ No newline at end of file diff --git a/request/RequestTest_ets/entry/src/main/config.json b/request/RequestTest_ets/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..d5b80105b0c7bb866ccf2d355cb506d077a41dfc --- /dev/null +++ b/request/RequestTest_ets/entry/src/main/config.json @@ -0,0 +1,112 @@ +{ + "app": { + "bundleName": "com.acts.requesttest", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 7, + "target": 9, + "releaseType": "Release" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.acts.requesttest", + "name": ".MyApplication", + "mainAbility": "com.acts.requesttest.MainAbility", + "deviceType": [ + "tablet", + "default", + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": true + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "visible": true, + "srcPath": "MainAbility", + "name": ".MainAbility", + "srcLanguage": "ets", + "icon": "$media:icon", + "description": "$string:description_mainability", + "formsEnabled": false, + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard" + }, + { + "orientation": "unspecified", + "visible": true, + "srcPath": "TestAbility", + "name": ".TestAbility", + "srcLanguage": "ets", + "icon": "$media:icon", + "description": "$string:TestAbility_desc", + "formsEnabled": false, + "label": "$string:TestAbility_label", + "type": "page", + "launchType": "standard" + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.INTERNET", + "reason": "need use ohos.permission.INTERNET", + "usedScene": { + "ability": [ + "com.acts.request.test.MainAbility" + ], + "when": "inuse" + } + } + ], + "js": [ + { + "mode": { + "syntax": "ets", + "type": "pageAbility" + }, + "pages": [ + "pages/index" + ], + "name": ".MainAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + }, + { + "mode": { + "syntax": "ets", + "type": "pageAbility" + }, + "pages": [ + "pages/index" + ], + "name": ".TestAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} diff --git a/request/RequestTest_ets/entry/src/main/ets/MainAbility/app.ets b/request/RequestTest_ets/entry/src/main/ets/MainAbility/app.ets new file mode 100644 index 0000000000000000000000000000000000000000..2e4e48f739b88cd4fbcc15d4e54b244d5af51d90 --- /dev/null +++ b/request/RequestTest_ets/entry/src/main/ets/MainAbility/app.ets @@ -0,0 +1,33 @@ +// @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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from 'hypium/index' +import testsuite from '../test/List.test' + +export default { + onCreate() { + console.info('Application onCreate') + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + }, + onDestroy() { + console.info('Application onDestroy') + }, +} \ No newline at end of file diff --git a/request/RequestTest_ets/entry/src/main/ets/MainAbility/pages/index.ets b/request/RequestTest_ets/entry/src/main/ets/MainAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..bb88bb3274a5bf7fdc8eb92cd80f809599e694da --- /dev/null +++ b/request/RequestTest_ets/entry/src/main/ets/MainAbility/pages/index.ets @@ -0,0 +1,37 @@ +// @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. + */ + +@Entry +@Component +struct MyComponent { + aboutToAppear() { + } + + build() { + Flex({ + direction: FlexDirection.Column, + alignItems: ItemAlign.Center, + justifyContent: FlexAlign.Center + }) { + Text('REQUEST TEST') + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} + diff --git a/request/RequestTest_ets/entry/src/main/ets/TestAbility/app.ets b/request/RequestTest_ets/entry/src/main/ets/TestAbility/app.ets new file mode 100644 index 0000000000000000000000000000000000000000..1471da3b550e5b2caecc292938994e40a1c62f62 --- /dev/null +++ b/request/RequestTest_ets/entry/src/main/ets/TestAbility/app.ets @@ -0,0 +1,33 @@ +// @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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../test/List.test' + +export default { + onCreate() { + console.info('Application onCreate') + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + }, + onDestroy() { + console.info('Application onDestroy') + }, +} \ No newline at end of file diff --git a/request/RequestTest_ets/entry/src/main/ets/TestAbility/pages/index.ets b/request/RequestTest_ets/entry/src/main/ets/TestAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b2497c3b2774b09a40f0db535735f3dbe5e6cb6e --- /dev/null +++ b/request/RequestTest_ets/entry/src/main/ets/TestAbility/pages/index.ets @@ -0,0 +1,50 @@ +// @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 router from '@system.router'; + +@Entry +@Component +struct Index { + aboutToAppear() { + console.info('TestAbility index aboutToAppear') + } + + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/request/RequestTest_ets/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/request/RequestTest_ets/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..c814bb9273d6d012e7724432c69a8d1d75d23026 --- /dev/null +++ b/request/RequestTest_ets/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,84 @@ +// @ts-nocheck +/** + * Copyright (c) 2021 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 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 itName', + '-s level', '-s testType', '-s size', '-s timeout', + '-s package' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams += ' ' + key + ' ' + parameters[key] + } + } + return targetParams.trim() +} + +async function onAbilityCreateCallback() { + console.log('onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + console.info('addAbilityMonitorCallback : ' + JSON.stringify(err)) +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info('OpenHarmonyTestRunner OnPrepare') + } + + onRun() { + console.log('OpenHarmonyTestRunner onRun run') + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.MainAbility' + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + abilityDelegator.executeShellCommand("echo 123456 > /data/app/el2/100/base/com.acts.requesttest/haps/entry/cache/test.txt", + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }) + var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }) + console.info('OpenHarmonyTestRunner onRun call abilityDelegator.getAppContext') + var context = abilityDelegator.getAppContext() + console.info('getAppContext : ' + JSON.stringify(context)) + console.info('OpenHarmonyTestRunner onRun end') + } +}; \ No newline at end of file diff --git a/request/RequestTest_ets/entry/src/main/ets/test/List.test.ets b/request/RequestTest_ets/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..de2cdf52c35115f16e5f736852bed16b77a3923b --- /dev/null +++ b/request/RequestTest_ets/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,24 @@ +/* + * 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 requestUploadJSUnit from './requestUpload.test'; +import requestDownloadJSUnit from './requestDownload.test'; +import requestSystemJSUnit from './requestSystem.test'; + +export default function testsuite() { + requestUploadJSUnit() + requestDownloadJSUnit() + requestSystemJSUnit() +} \ No newline at end of file diff --git a/request/RequestTest_ets/entry/src/main/ets/test/requestDownload.test.ets b/request/RequestTest_ets/entry/src/main/ets/test/requestDownload.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..eb1a01e8a1a44d06da30e9eeb2ba24c7c18489b4 --- /dev/null +++ b/request/RequestTest_ets/entry/src/main/ets/test/requestDownload.test.ets @@ -0,0 +1,839 @@ +/* + * 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 request from "@ohos.request"; +import featureAbility from '@ohos.ability.featureAbility' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "hypium/index"; + +export default function requestDownloadJSUnit() { + describe('requestDownloadTest', function () { + console.info('====>################################request download Test start'); + + /** + * beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed. + */ + beforeAll(async function () { + console.info('====>beforeAll: Prerequisites are executed.'); + }); + + /** + * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. + */ + beforeEach(async function () { + console.info('====>beforeEach: Prerequisites is executed.'); + await setDownLoadConfig() + }); + + /** + * afterEach: Test case-level clearance conditions, which are executed after each test case is executed. + */ + afterEach(function () { + console.info('====>afterEach: Test case-level clearance conditions is executed.'); + }); + + /** + * afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed. + */ + afterAll(function () { + console.info('====>afterAll: Test suite-level cleanup condition is executed'); + }); + + let downloadTask; + let downloadConfig + async function setDownLoadConfig(){ + let downloadFilePath = await featureAbility.getContext().getFilesDir() + downloadConfig = { + url: 'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png', + header: { + headers: 'http' + }, + enableMetered: false, + enableRoaming: false, + description: 'XTS download test!', + networkType: request.NETWORK_WIFI, + filePath: `${downloadFilePath}/`, + title: 'XTS download test!', + background: false + } + } + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 + * @tc.desc alled when the current download session is in process. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 is starting-----------------------"); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001.txt' + request.download(downloadConfig, (err, data)=>{ + try{ + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 downloadTask: " + JSON.stringify(downloadTask) ); + expect(true).assertEqual(downloadTask != undefined); + downloadTask.on('progress', (data1, data2) => { + try{ + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 on data1 =" + data1); + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0001 on data2 =" + data2); + expect(true).assertEqual(data1 != undefined); + expect(true).assertEqual(data2 != undefined); + if (data1 == data2){ + done(); + } + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_PROMISE_0001 throw_error: " + err); + done(); + } + }); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_PROMISE_0001 error: " + err); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 + * @tc.desc Called when the current download session complete、pause or remove. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 is starting-----------------------"); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002.txt' + request.download(downloadConfig, (err, data)=>{ + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 downloadTask: " + downloadTask); + try{ + expect(true).assertEqual(downloadTask != undefined); + downloadTask.on('complete', async () => { + try{ + console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 task completed.') + expect(true).assertTrue(); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 throw_error: " + err); + } + await downloadTask.remove() + done(); + }); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0002 error: " + err); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 + * @tc.desc Called when the current download session complete、pause or remove. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 is starting-----------------------"); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003.txt' + request.download(downloadConfig, (err, data)=>{ + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 downloadTask: " + downloadTask); + try{ + expect(true).assertEqual(downloadTask != undefined); + downloadTask.on('pause', async () => { + try{ + console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 task completed.') + expect(true).assertTrue(); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 throw_error: " + err); + } + await downloadTask.remove() + done(); + }); + downloadTask.on('progress', (data1, data2) => { + if(data1 > 0){ + downloadTask.pause() + } + }); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0003 error: " + err); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 + * @tc.desc Called when the current download session complete、pause or remove. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 is starting-----------------------"); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004.txt' + request.download(downloadConfig, (err, data)=>{ + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 downloadTask: " + downloadTask); + try{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.on('remove', () => { + try{ + console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 remove completed') + expect(true).assertTrue(); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 throw_error: " + err); + } + done(); + }); + downloadTask.on('progress', (data1, data2) => { + if(data1 > 0){ + downloadTask.remove() + } + }); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0004 error: " + err); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 + * @tc.desc Called when the current download session fails. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 is starting-----------------------"); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005.txt' + downloadConfig.url += 'xxxxxxxxxx' + request.download(downloadConfig, (err, data)=>{ + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 downloadTask: " + downloadTask); + try{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.on('fail', async()=>{ + try{ + console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 fail completed') + expect(true).assertTrue(); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 throw_error: " + err); + } + await downloadTask.remove() + done(); + }) + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0005 error: " + err); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006 + * @tc.desc Called when the current download session fails. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006 is starting-----------------------"); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006.txt' + request.download(downloadConfig, (err, data)=>{ + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006 downloadTask: " + downloadTask); + try{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.on('complete', async () => { + try{ + request.download(downloadConfig, (err, data)=>{ + }) + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006 second throw_error: " + err); + expect(err.code).assertEqual(13400002) + await downloadTask.remove() + done(); + } + }); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_ON_0006 error: " + err); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 + * @tc.desc alled when the current download session is in process. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 is starting-----------------------"); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001.txt' + request.download(downloadConfig, (err, data)=>{ + try{ + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 downloadTask: " + downloadTask); + expect(downloadTask != undefined).assertEqual(true); + downloadTask.on('progress', (data1, data2) => {}); + downloadTask.off('progress', async (data1, data2) => { + try{ + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 on data1 =" + data1); + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 on data2 =" + data2); + expect(data1).assertEqual(0); + expect(data2).assertEqual(0); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 off_err: " + err); + } + await downloadTask.remove() + done(); + }); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0001 error: " + err); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 + * @tc.desc alled when the current download session complete、pause or remove. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 is starting-----------------------"); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002.txt' + request.download(downloadConfig, (err, data)=>{ + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 downloadTask: " + downloadTask); + try{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.off('complete',async () => { + try{ + console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 task complete.') + expect(true).assertTrue(); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 off_err: " + err); + } + await downloadTask.remove() + done(); + }); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0002 error: " + err); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 + * @tc.desc alled when the current download session complete、pause or remove. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 is starting-----------------------"); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003.txt' + request.download( downloadConfig, (err, data)=>{ + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 downloadTask: " + downloadTask); + try{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.off('pause', async () => { + try{ + console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 task complete.') + expect(true).assertTrue(); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 off_err: " + err); + } + await downloadTask.remove() + done(); + }); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 error: " + err); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004 + * @tc.desc alled when the current download session complete、pause or remove. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004 is starting-----------------------"); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004.txt' + request.download( downloadConfig, (err, data)=>{ + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004 downloadTask: " + downloadTask); + try{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.off('remove', async (data) => { + try{ + console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 remove data:' +JSON.stringify(data)) + expect(true).assertTrue(); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0003 off_err: " + err); + } + await downloadTask.remove() + done(); + }); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0004 error: " + err); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 + * @tc.desc Called when the current download session fails. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 is starting-----------------------"); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005.txt' + request.download( downloadConfig, (err, data)=>{ + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 downloadTask: " + downloadTask); + try{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.on('fail', (data) => {}); + downloadTask.off('fail', async (data) => { + try{ + console.info('====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 fail_data:' + JSON.stringify(data)) + expect(data).assertEqual(0) + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 end-----------------------"); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 fail_error: " + err); + } + await downloadTask.remove() + done(); + }); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_DOWNLOADTASK_OFF_0005 error: " + err); + done(); + } + }); + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 + * @tc.desc Deletes a download session and the downloaded files. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_REMOVE_0001', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 is starting-----------------------"); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_REMOVE_0001.txt' + request.download( downloadConfig, (err, data)=>{ + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 downloadTask: " + downloadTask); + try{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.remove((err, data)=>{ + try{ + if(err) { + console.error('====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 Failed to remove the download task.'); + expect().assertFail(); + } + if (data) { + console.info('====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 removed data:' + JSON.stringify(data)); + expect(data == true).assertTrue(); + } else { + console.error('====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 Failed to remove the download task.'); + expect().assertFail(); + } + }catch(err){ + console.info('====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 remove_throw_err:' + JSON.stringify(err)) + } + done(); + }); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0001 error: " + err); + done(); + } + }) + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 + * @tc.desc Deletes a download session and the downloaded files. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_REMOVE_0002', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 is starting-----------------------"); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_REMOVE_0002.txt' + request.download( downloadConfig, (err, data)=>{ + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 downloadTask: " + downloadTask); + try{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.remove().then(data => { + if (data) { + console.info('====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 removed data:' + JSON.stringify(data)); + expect(data == true).assertTrue(); + } else { + console.error('====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 Failed to remove the download task.'); + expect().assertFail(); + } + done(); + }).catch((err) => { + console.error('====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 Failed to remove the download task.'); + done(); + }) + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_REMOVE_0002 error: " + err); + done(); + } + }) + + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_PAUSE_0001 + * @tc.desc Pause a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_PAUSE_0001', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_PAUSE_0001 is starting-----------------------"); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_PAUSE_0001.txt' + request.download( downloadConfig, (err, data)=>{ + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0001 downloadTask: " + downloadTask); + expect(downloadTask != undefined).assertEqual(true); + try{ + downloadTask.pause(async ()=>{ + try{ + console.info('====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0001 Download task pause success.'); + expect(true).assertTrue(); + }catch(err){ + console.info('====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0001 pause_throw_err:' + JSON.stringify(err)) + } + await downloadTask.remove() + done(); + }) + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0001 error: " + JSON.stringify(err)); + done(); + } + }) + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_PAUSE_0002 + * @tc.desc Pause a download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_PAUSE_0002', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_PAUSE_0002 is starting-----------------------"); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_PAUSE_0002.txt' + request.download( downloadConfig, (err, data)=>{ + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0002 downloadTask: " + downloadTask); + try{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.pause().then(async () => { + console.info('====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0002 Download task pause success.'); + expect(true).assertTrue(); + await downloadTask.remove() + done(); + }).catch((err) => { + console.error("====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0002 throw_error: " + JSON.stringify(err)); + done(); + }) + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_PAUSE_0002 error: " + JSON.stringify(err)); + done(); + } + }) + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_REMUSE_0001 + * @tc.desc Resume a paused download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_REMUSE_0001', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_REMUSE_0001 is starting-----------------------"); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_REMUSE_0001.txt' + request.download( downloadConfig, (err, data)=>{ + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0001 downloadTask: " + downloadTask); + expect(downloadTask != undefined).assertEqual(true); + try{ + downloadTask.resume(async ()=>{ + try{ + console.info('====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0001 Download task resume success.'); + expect(true).assertTrue(); + }catch(err){ + console.info('====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0001 pause_throw_err:' + JSON.stringify(err)) + } + await downloadTask.remove() + done(); + }) + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0001 error: " + JSON.stringify(err)); + done(); + } + }) + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_REMUSE_0002 + * @tc.desc Resume a paused download session. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_REMUSE_0002', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_REMUSE_0002 is starting-----------------------"); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_REMUSE_0002.txt' + request.download( downloadConfig, (err, data)=>{ + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0002 downloadTask: " + downloadTask); + try{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.resume().then(async () => { + console.info('====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0002 Download task resume success.'); + expect(true).assertTrue(); + await downloadTask.remove() + done() + }).catch((err) => { + console.error("====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0002 throw_error: " + JSON.stringify(err)); + done(); + }) + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_REMUSE_0002 error: " + JSON.stringify(err)); + done(); + } + }) + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_QUERY_0001 + * @tc.desc Queries download information of a session, which is defined in DownloadSession.DownloadInfo. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_QUERY_0001', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_QUERY_0001 is starting-----------------------"); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_QUERY_0001.txt' + request.download( downloadConfig, (err, data)=>{ + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 downloadTask: " + downloadTask); + try{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.query(async (err, downloadInfo)=>{ + try{ + if(err) { + console.error('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 Failed to query: ' + JSON.stringify(err)); + expect().assertFail(); + } else { + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.description); + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.downloadedBytes); + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.downloadId); + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.failedReason); + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.fileName); + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.filePath); + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.pausedReason); + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.status); + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.targetURI); + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.downloadTitle); + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 query info: '+ downloadInfo.downloadTotalBytes); + expect(true).assertTrue(); + } + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 throw_error: " + JSON.stringify(err)); + } + await downloadTask.remove() + done(); + }) + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERY_0001 error: " + JSON.stringify(err)); + done(); + } + }) + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_QUERY_0002 + * @tc.desc Queries download information of a session, which is defined in DownloadSession.DownloadInfo. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_QUERY_0002', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_DOWNLOAD_API_QUERY_0002 is starting-----------------------"); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_QUERY_0002.txt' + request.download( downloadConfig, (err, data)=>{ + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 downloadTask: " + downloadTask); + try{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.query().then(async (downloadInfo)=>{ + try{ + if(err) { + console.error('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 Failed to query: ' + JSON.stringify(err)); + expect().assertFail(); + } else { + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '+ downloadInfo.description); + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '+ downloadInfo.downloadedBytes); + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '+ downloadInfo.downloadId); + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '+ downloadInfo.failedReason); + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '+ downloadInfo.fileName); + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '+ downloadInfo.filePath); + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '+ downloadInfo.pausedReason); + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '+ downloadInfo.status); + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '+ downloadInfo.targetURI); + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '+ downloadInfo.downloadTitle); + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 query info: '+ downloadInfo.downloadTotalBytes); + expect(true).assertTrue(); + } + await downloadTask.remove() + done(); + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 error: " + JSON.stringify(err)); + done(); + } + }).catch((err)=>{ + console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 catch_error: " + JSON.stringify(err)); + expect().assertFail(); + done(); + }) + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERY_0002 error: " + JSON.stringify(err)); + done(); + } + }) + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 + * @tc.desc Queries the MIME type of the download file. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001', 0, async function (done) { + console.info("====>---------------------SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 is starting---------------------"); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001.txt' + request.download( downloadConfig, (err, data)=>{ + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 downloadTask: " + downloadTask); + try{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.on('progress', async (data1, data2)=>{ + try{ + if (data1 > 0 && downloadTask != null){ + downloadTask.queryMimeType((err, data) => { + try{ + if(err) { + console.error('====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 return_err:'+ JSON.stringify(err)); + expect().assertFail(); + done(); + } + if (data) { + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 data:' + JSON.stringify(data)); + expect(typeof data == "string").assertTrue(); + } else { + console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 data_error: " + JSON.stringify(err)); + expect().assertFail(); + } + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 throw_error: " + JSON.stringify(err)); + } + }); + } + if (data1 == data2){ + downloadTask = null + await downloadTask.remove() + done(); + } + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 error: " + JSON.stringify(err)); + done(); + } + }) + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0001 error: " + JSON.stringify(err)); + done(); + } + }) + }); + + /** + * @tc.number SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 + * @tc.desc Queries the MIME type of the download file. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 2 + */ + it('SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002', 0, async function (done) { + console.info("====>-------------------SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 is starting----------------------"); + downloadConfig.filePath += 'SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002.txt' + request.download( downloadConfig, (err, data)=>{ + downloadTask = data; + console.info("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 downloadTask: " + downloadTask); + try{ + expect(downloadTask != undefined).assertEqual(true); + downloadTask.on('progress', async (data1, data2) => { + try{ + if(data1 > 0 && downloadTask != null){ + let data = await downloadTask.queryMimeType() + console.info('====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 Download task queryMimeType.'); + expect(typeof data == "string").assertTrue(); + } + if(data1 == data2){ + downloadTask = null + await downloadTask.remove() + done(); + } + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 throw_error: " + JSON.stringify(err)); + done(); + } + }) + }catch(err){ + console.error("====>SUB_REQUEST_DOWNLOAD_API_QUERYMINETYPE_0002 error: " + JSON.stringify(err)); + done(); + } + }) + }); + }) +} diff --git a/request/RequestTest_ets/entry/src/main/ets/test/requestSystem.test.ets b/request/RequestTest_ets/entry/src/main/ets/test/requestSystem.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..1c52426b51eaf712b4c8b217be8e530f4abdf8ba --- /dev/null +++ b/request/RequestTest_ets/entry/src/main/ets/test/requestSystem.test.ets @@ -0,0 +1,146 @@ +/** + * 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 request from '@system.request'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "hypium/index"; + +export default function requestSystemJSUnit() { + describe('requestSystemJSUnit', function () { + console.info('====>****************start requestSystemTest*****************') + + /** + * @tc.name: ohos.SUB_REQUESTSYSTEM_UPLOAD_API_0001 + * @tc.desc: Upload files. + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level: Level 1 + */ + it('SUB_REQUESTSYSTEM_UPLOAD_API_0001', 0, async function (done) { + console.info("====>-----------------------SUB_REQUESTSYSTEM_UPLOAD_API_0001 start-----------------------"); + let UploadResponse = { + code: 200, + data: '', + headers: {RequestMethod: 'POST', + StatusCode: 200 } + } + let UploadRequestOptions = { + url: 'http://www.path.com', + method: 'POST', + files: [ + { + uri: 'internal://cache/path/to/file.txt', + name: 'file', + filename: 'file.txt', + }, + ], + data:[ + { + name: 'name1', + value: 'value', + }, + ], + success: function(UploadResponse) { + console.info('====>SUB_REQUESTSYSTEM_UPLOAD_API_0001 upload success, code:' + UploadResponse.code); + }, + fail: function(data, code) { + console.info('====>SUB_REQUESTSYSTEM_UPLOAD_API_0001 upload fail'); + }, + complete: function (){ + console.info('====>SUB_REQUESTSYSTEM_UPLOAD_API_0001 upload complete'); + } + } + try{ + let result = request.upload(UploadRequestOptions); + console.info('====>SUB_REQUESTSYSTEM_UPLOAD_API_0001 upload err:' + result); + expect(true).assertEqual(true); + }catch(err){ + console.info('====>SUB_REQUESTSYSTEM_UPLOAD_API_0001 upload err:' + err); + } + console.info("====>-----------------------SUB_REQUESTSYSTEM_UPLOAD_API_0001 end-----------------------"); + done(); + }); + + /** + * @tc.name: ohos.SUB_REQUESTSYSTEM_DOWNLOAD_API_0001 + * @tc.desc: This API is used to download files. + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level: Level 1 + */ + it('SUB_REQUESTSYSTEM_DOWNLOAD_API_0001', 0, async function (done) { + console.info("====>-----------------------SUB_REQUESTSYSTEM_DOWNLOAD_API_0001 start-----------------------"); + let DownloadResponse = { + token: "Hm_lpvt_1d6c34c1bc067f5746a5fca18d1c24ab" + } + + let DownloadRequestOptions = { + url: 'http://www.path.com', + filename: 'requestSystenTest', + header: '', + description: 'this is requeSystem download response', + success: function(DownloadResponse) { + console.info('====>SUB_REQUESTSYSTEM_DOWNLOAD_API_0001call success callback success: ' + DownloadResponse.token); + }, + fail: function(data, code) { + console.info('====>SUB_REQUESTSYSTEM_DOWNLOAD_API_0001 handling fail'); + }, + complete: function (){ + console.info('====>SUB_REQUESTSYSTEM_DOWNLOAD_API_0001 download complete'); + } + } + try{ + let result = request.download(DownloadRequestOptions); + console.info('====>SUB_REQUESTSYSTEM_DOWNLOAD_API_0001 upload err:' + result); + expect(result == null).assertEqual(true); + }catch(err){ + console.info('====>SUB_REQUESTSYSTEM_DOWNLOAD_API_0001 download complete' + err); + } + console.info("====>-----------------------SUB_REQUESTSYSTEM_DOWNLOAD_API_0001 end-----------------------"); + done(); + }); + + /** + * @tc.name: ohos.SUB_REQUESTSYSTEM_DOWNLOADCOMPLETE_API_0001 + * @tc.desc: Listens to download task status. + * @tc.size: MediumTest + * @tc.type: Function + * @tc.level: Level 1 + */ + it('SUB_REQUESTSYSTEM_DOWNLOADCOMPLETE_API_0001', 0, async function (done) { + console.info("====>-----------------------SUB_REQUESTSYSTEM_DOWNLOADCOMPLETE_API_0001 start-----------------------"); + let OnDownloadCompleteResponse = { + uri: "http://www.path.com" + } + let OnDownloadCompleteOptions = { + token: 'token-index', + success: function(OnDownloadCompleteResponse) { + console.info('====>SUB_REQUESTSYSTEM_DOWNLOADCOMPLETE_API_0001 download success,uri:' + + OnDownloadCompleteResponse.uri); + }, + fail: function(data, code) { + console.info('====>SUB_REQUESTSYSTEM_DOWNLOADCOMPLETE_API_0001 download fail'); + }, + complete: function (){ + console.info('====>SUB_REQUESTSYSTEM_DOWNLOADCOMPLETE_API_0001 download complete'); + } + } + let result = request.onDownloadComplete(OnDownloadCompleteOptions); + console.info('====>SUB_REQUESTSYSTEM_DOWNLOADCOMPLETE_API_0001 upload err:' + result); + expect(result == null).assertEqual(true); + console.info("====>-----------------------SUB_REQUESTSYSTEM_DOWNLOADCOMPLETE_API_0001 end-----------------------"); + done(); + }); + }) +} diff --git a/request/RequestTest_ets/entry/src/main/ets/test/requestUpload.test.ets b/request/RequestTest_ets/entry/src/main/ets/test/requestUpload.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..2fe8649b76c2ca848dc016e23ae04d66576774c9 --- /dev/null +++ b/request/RequestTest_ets/entry/src/main/ets/test/requestUpload.test.ets @@ -0,0 +1,337 @@ +/* + * 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 request from "@ohos.request"; +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "hypium/index"; + +export default function requestUploadJSUnit() { + describe('requestUploadTest', function () { + console.info('====>################################request upload Test start'); + + /** + * beforeAll: Prerequisites at the test suite level, which are executed before the test suite is executed. + */ + beforeAll(function () { + console.info('====>beforeAll: Prerequisites are executed.'); + }); + + /** + * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. + */ + beforeEach(function () { + console.info('====>beforeEach: Prerequisites is executed.'); + }); + + /** + * afterEach: Test case-level clearance conditions, which are executed after each test case is executed. + */ + afterEach(function () { + console.info('====>afterEach: Test case-level clearance conditions is executed.'); + }); + + /** + * afterAll: Test suite-level cleanup condition, which is executed after the test suite is executed. + */ + afterAll(function () { + console.info('====>afterAll: Test suite-level cleanup condition is executed'); + }); + + /** + * sleep function. + */ + function sleep(date, time){ + while(Date.now() - date <= time); + } + + let uploadTask; + let RequestData = { + name: 'name', + value: '123' + } + + let File = { + filename: 'test', + name: 'test', + uri: 'internal://cache/test.txt', + type: 'txt' + } + + let uploadConfig = { + url: 'http://127.0.0.1', + header: { + headers: 'http' + }, + method: 'POST', + files: [File], + data: [RequestData] + }; + + /** + * @tc.number SUB_REQUEST_UPLOAD_API_0001 + * @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME + * @tc.desc Test requestUploadTest API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_REQUEST_UPLOAD_API_0001', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_0001 is starting-----------------------"); + try { + console.info("====>SUB_REQUEST_UPLOAD_API_0001 request.NETWORK_MOBILE:" + request.NETWORK_MOBILE); + expect(request.NETWORK_MOBILE).assertEqual(1); + console.info("====>SUB_REQUEST_UPLOAD_API_0001 request.NETWORK_WIFI:" + request.NETWORK_WIFI); + expect(request.NETWORK_WIFI).assertEqual(65536); + console.info("====>SUB_REQUEST_UPLOAD_API_0001 request.ERROR_CANNOT_RESUME:" + request.ERROR_CANNOT_RESUME); + expect(request.ERROR_CANNOT_RESUME).assertEqual(0); + console.info("====>SUB_REQUEST_UPLOAD_API_0001 request.ERROR_DEVICE_NOT_FOUND:" + request.ERROR_DEVICE_NOT_FOUND); + expect(request.ERROR_DEVICE_NOT_FOUND).assertEqual(1); + } catch (err) { + expect().assertFail(); + console.error("====>SUB_REQUEST_UPLOAD_API_0001 error: " + err); + } + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_0001 end-----------------------"); + done(); + }); + + /** + * @tc.number SUB_REQUEST_UPLOAD_API_0002 + * @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME + * @tc.desc Test requestUploadTest API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_REQUEST_UPLOAD_API_0002', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_0002 is starting-----------------------"); + try { + console.info("====>SUB_REQUEST_UPLOAD_API_0002 request.ERROR_FILE_ALREADY_EXISTS:" + request.ERROR_FILE_ALREADY_EXISTS); + expect(request.ERROR_FILE_ALREADY_EXISTS).assertEqual(2); + console.info("====>SUB_REQUEST_UPLOAD_API_0002 request.ERROR_FILE_ERROR:" + request.ERROR_FILE_ERROR); + expect(request.ERROR_FILE_ERROR).assertEqual(3); + console.info("====>SUB_REQUEST_UPLOAD_API_0002 request.ERROR_HTTP_DATA_ERROR:" + request.ERROR_HTTP_DATA_ERROR); + expect(request.ERROR_HTTP_DATA_ERROR).assertEqual(4); + console.info("====>SUB_REQUEST_UPLOAD_API_0002 request.ERROR_INSUFFICIENT_SPACE:" + request.ERROR_INSUFFICIENT_SPACE); + expect(request.ERROR_INSUFFICIENT_SPACE).assertEqual(5); + } catch (err) { + expect().assertFail(); + console.error("====>SUB_REQUEST_UPLOAD_API_0002 error: " + err); + } + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_0002 end-----------------------"); + done(); + }); + + /** + * @tc.number SUB_REQUEST_UPLOAD_API_0003 + * @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME + * @tc.desc Test requestUploadTest API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_REQUEST_UPLOAD_API_0003', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_0003 is starting-----------------------"); + try { + console.info("====>SUB_REQUEST_UPLOAD_API_0003 request.ERROR_TOO_MANY_REDIRECTS:" + request.ERROR_TOO_MANY_REDIRECTS); + expect(request.ERROR_TOO_MANY_REDIRECTS).assertEqual(6); + console.info("====>SUB_REQUEST_UPLOAD_API_0003 request.ERROR_UNHANDLED_HTTP_CODE:" + request.ERROR_UNHANDLED_HTTP_CODE); + expect(request.ERROR_UNHANDLED_HTTP_CODE).assertEqual(7); + console.info("====>SUB_REQUEST_UPLOAD_API_0003 request.ERROR_UNKNOWN:" + request.ERROR_UNKNOWN); + expect(request.ERROR_UNKNOWN).assertEqual(8); + console.info("====>SUB_REQUEST_UPLOAD_API_0003 request.PAUSED_QUEUED_FOR_WIFI:" + request.PAUSED_QUEUED_FOR_WIFI); + expect(request.PAUSED_QUEUED_FOR_WIFI).assertEqual(0); + } catch (err) { + expect().assertFail(); + console.error("====>SUB_REQUEST_UPLOAD_API_0003 error: " + err); + } + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_0003 end-----------------------"); + done(); + }); + + /** + * @tc.number SUB_REQUEST_UPLOAD_API_0004 + * @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME + * @tc.desc Test requestUploadTest API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_REQUEST_UPLOAD_API_0004', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_0004 is starting-----------------------"); + try { + console.info("====>SUB_REQUEST_UPLOAD_API_0004 request.PAUSED_UNKNOWN:" + request.PAUSED_UNKNOWN); + expect(request.PAUSED_UNKNOWN).assertEqual(4); + console.info("====>SUB_REQUEST_UPLOAD_API_0004 request.PAUSED_WAITING_FOR_NETWORK:" + request.PAUSED_WAITING_FOR_NETWORK); + expect(request.PAUSED_WAITING_FOR_NETWORK).assertEqual(1); + console.info("====>SUB_REQUEST_UPLOAD_API_0004 request.PAUSED_WAITING_TO_RETRY:" + request.PAUSED_WAITING_TO_RETRY); + expect(request.PAUSED_WAITING_TO_RETRY).assertEqual(2); + console.info("====>SUB_REQUEST_UPLOAD_API_0004 request.PAUSED_BY_USER:" + request.PAUSED_BY_USER); + expect(request.PAUSED_BY_USER).assertEqual(3); + } catch (err) { + expect().assertFail(); + console.error("====>SUB_REQUEST_UPLOAD_API_0004 error: " + err); + } + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_0004 end-----------------------"); + done(); + }); + + /** + * @tc.number SUB_REQUEST_UPLOAD_API_0005 + * @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME + * @tc.desc Test requestUploadTest API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_REQUEST_UPLOAD_API_0005', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_0005 is starting-----------------------"); + try { + console.info("====>SUB_REQUEST_UPLOAD_API_0005 request.SESSION_FAILED:" + request.SESSION_FAILED); + expect(request.SESSION_FAILED).assertEqual(4); + console.info("====>SUB_REQUEST_UPLOAD_API_0005 request.SESSION_PAUSED:" + request.SESSION_PAUSED); + expect(request.SESSION_PAUSED).assertEqual(3); + console.info("====>SUB_REQUEST_UPLOAD_API_0005 request.SESSION_PENDING:" + request.SESSION_PENDING); + expect(request.SESSION_PENDING).assertEqual(2); + console.info("====>SUB_REQUEST_UPLOAD_API_0005 request.SESSION_RUNNING:" + request.SESSION_RUNNING); + expect(request.SESSION_RUNNING).assertEqual(1); + console.info("====>SUB_REQUEST_UPLOAD_API_0005 request.SESSION_SUCCESSFUL:" + request.SESSION_SUCCESSFUL); + expect(request.SESSION_SUCCESSFUL).assertEqual(0); + } catch (err) { + expect().assertFail(); + console.error("====>SUB_REQUEST_UPLOAD_API_0005 error: " + err); + } + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_0005 end-----------------------"); + done(); + }); + + /** + * @tc.number SUB_REQUEST_UPLOAD_API_0006 + * @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME + * @tc.desc Test requestUploadTest API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it('SUB_REQUEST_UPLOAD_API_0006', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_0006 is starting-----------------------"); + try { + console.info("====>SUB_REQUEST_UPLOAD_API_0006 request.EXCEPTION_PERMISSION:" + request.EXCEPTION_PERMISSION); + expect(request.EXCEPTION_PERMISSION).assertEqual(201); + console.info("====>SUB_REQUEST_UPLOAD_API_0006 request.EXCEPTION_PARAMCHECK:" + request.EXCEPTION_PARAMCHECK); + expect(request.EXCEPTION_PARAMCHECK).assertEqual(401); + console.info("====>SUB_REQUEST_UPLOAD_API_0006 request.EXCEPTION_UNSUPPORTED:" + request.EXCEPTION_UNSUPPORTED); + expect(request.EXCEPTION_UNSUPPORTED).assertEqual(801); + console.info("====>SUB_REQUEST_UPLOAD_API_0006 request.EXCEPTION_FILEIO:" + request.EXCEPTION_FILEIO); + expect(request.EXCEPTION_FILEIO).assertEqual(13400001); + console.info("====>SUB_REQUEST_UPLOAD_API_0006 request.EXCEPTION_FILEPATH:" + request.EXCEPTION_FILEPATH); + expect(request.EXCEPTION_FILEPATH).assertEqual(13400002); + console.info("====>SUB_REQUEST_UPLOAD_API_0006 request.EXCEPTION_SERVICE:" + request.EXCEPTION_SERVICE); + expect(request.EXCEPTION_SERVICE).assertEqual(13400003); + console.info("====>SUB_REQUEST_UPLOAD_API_0006 request.EXCEPTION_OTHERS:" + request.EXCEPTION_OTHERS); + expect(request.EXCEPTION_OTHERS).assertEqual(13499999); + console.info("====>SUB_REQUEST_UPLOAD_API_0006 request.ERROR_OFFLINE:" + request.ERROR_OFFLINE); + expect(request.ERROR_OFFLINE).assertEqual(9); + console.info("====>SUB_REQUEST_UPLOAD_API_0006 request.ERROR_UNSUPPORTED_NETWORK_TYPE:" + request.ERROR_UNSUPPORTED_NETWORK_TYPE); + expect(request.ERROR_UNSUPPORTED_NETWORK_TYPE).assertEqual(10); + } catch (err) { + expect().assertFail(); + console.error("====>SUB_REQUEST_UPLOAD_API_0006 error: " + err); + } + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_0006 end-----------------------"); + done(); + }); + + /** + * @tc.number SUB_REQUEST_UPLOAD_API_CALLBACK_0001 + * @tc.name Test requestUploadTest type = TIMER_TYPE_REALTIME + * @tc.desc Test requestUploadTest API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 1 + */ + it('SUB_REQUEST_UPLOAD_API_CALLBACK_0001', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_CALLBACK_0001 is starting-----------------------"); + try { + console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 uploadConfig = " + JSON.stringify(uploadConfig)); + request.upload(uploadConfig, (err, data) => { + uploadTask = data; + console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 progress uploadTask =" + JSON.stringify(uploadTask)); + expect(uploadTask != undefined).assertEqual(true); + + uploadTask.on('progress', function (data1, data2) { + console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 on data1 =" + data1); + console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 on data2 =" + data2); + }); + + uploadTask.off('progress', function (data1, data2) { + console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 off data1 =" + data1); + console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 off data2 =" + data2); + }); + + uploadTask.remove((err, data) => { + console.info("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 remove =" + data); + }); + }); + } catch (err) { + console.error("====>SUB_REQUEST_UPLOAD_API_CALLBACK_0001 error: " + err); + expect().assertFail(); + } + sleep(Date.now(), 20000); + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_CALLBACK_0001 end-----------------------"); + done(); + }); + + /** + * @tc.number : SUB_REQUEST_UPLOAD_API_PROMISE_0001 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Mixed strings value can be obtained correctly + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('SUB_REQUEST_UPLOAD_API_PROMISE_0001', 0, async function (done) { + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_PROMISE_0001 is starting-----------------------"); + try { + console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 UploadConfig = " + JSON.stringify(uploadConfig)); + request.upload(uploadConfig).then((data) => { + uploadTask = data; + console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 uploadTask = " + uploadTask); + expect(true).assertEqual((uploadTask != undefined) || (uploadTask != "") || (uploadTask != {})); + + uploadTask.on('headerReceive', (header) => { + console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 header = " + header); + expect(true).assertEqual((header != undefined) || (header != "") || (header != {})); + }); + + uploadTask.off('headerReceive', (header) => { + console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 header = " + header); + expect(true).assertEqual((header != undefined) || (header != "") || (header != {})); + }); + + uploadTask.remove().then((result)=>{ + console.info("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 remove result = " + result); + expect(result).assertEqual(true); + }); + }); + } catch (e) { + console.error("====>SUB_REQUEST_UPLOAD_API_PROMISE_0001 error: " + JSON.stringify(e)); + expect(true).assertFail(true); + } + sleep(Date.now(), 20000); + console.info("====>-----------------------SUB_REQUEST_UPLOAD_API_PROMISE_0001 end-----------------------"); + done(); + }); + }) +} diff --git a/request/RequestTest_ets/entry/src/main/resources/base/element/string.json b/request/RequestTest_ets/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..498677efbde065c36668727190d3613cbf278bfc --- /dev/null +++ b/request/RequestTest_ets/entry/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "entry_MainAbility" + }, + { + "name": "description_mainability", + "value": "ETS_Empty Ability" + }, + { + "name": "TestAbility_desc", + "value": "description" + }, + { + "name": "TestAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/request/RequestTest_ets/entry/src/main/resources/base/media/icon.png b/request/RequestTest_ets/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/request/RequestTest_ets/entry/src/main/resources/base/media/icon.png differ diff --git a/request/RequestTest_ets/signature/ActsRequestETSApiTest.p7b b/request/RequestTest_ets/signature/ActsRequestETSApiTest.p7b new file mode 100644 index 0000000000000000000000000000000000000000..195dba074b7a27be36d9759719a6d074afa3d5f5 Binary files /dev/null and b/request/RequestTest_ets/signature/ActsRequestETSApiTest.p7b differ diff --git a/theme/BUILD.gn b/theme/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..163c39526d738fb0d25fe4047c457a7dc075bc1f --- /dev/null +++ b/theme/BUILD.gn @@ -0,0 +1,21 @@ +# Copyright (C) 2021 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("//build/ohos_var.gni") +group("theme") { + testonly = true + deps = [ + "screenlock_ets:ActsScreenLockETSApiTest", + "wallpaper_ets:ActsWallpaperETSApiTest", + ] +} diff --git a/theme/screenlock_ets/BUILD.gn b/theme/screenlock_ets/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..715afe2f991d992ca160d43daedc335179d8aa6f --- /dev/null +++ b/theme/screenlock_ets/BUILD.gn @@ -0,0 +1,39 @@ +# 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("//build/ohos.gni") +import("//test/xts/tools/build/suite.gni") +ohos_js_hap_suite("ActsScreenLockETSApiTest") { + hap_profile = "./entry/src/main/config.json" + deps = [ + ":screenLock_ets_assets", + ":screenLock_ets_resources", + ":screenLock_ets_test_assets", + ] + ets2abc = true + subsystem_name = "theme" + part_name = "screenlock_mgr" + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsScreenLockETSApiTest" +} + +ohos_js_assets("screenLock_ets_assets") { + source_dir = "./entry/src/main/ets/MainAbility" +} +ohos_js_assets("screenLock_ets_resources") { + source_dir = "./entry/src/main/ets/TestAbility" +} +ohos_resources("screenLock_ets_test_assets") { + sources = [ "./entry/src/main/resources" ] + hap_profile = "./entry/src/main/config.json" +} diff --git a/theme/screenlock_ets/Test.json b/theme/screenlock_ets/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..406968a98790eb06cc1bb880d63b97d6c4079abd --- /dev/null +++ b/theme/screenlock_ets/Test.json @@ -0,0 +1,19 @@ +{ + "description": "Configuration for screenlock js api Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "600000", + "bundle-name": "com.acts.theme.screenlocktest", + "package-name": "com.acts.theme.screenlocktest", + "shell-timeout": "600000" + }, + "kits": [ + { + "test-file-name": [ + "ActsScreenLockETSApiTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/theme/screenlock_ets/entry/src/main/config.json b/theme/screenlock_ets/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..bd5497a32e934ed146a5855de22b7fb6b14afca1 --- /dev/null +++ b/theme/screenlock_ets/entry/src/main/config.json @@ -0,0 +1,101 @@ +{ + "app": { + "bundleName": "com.acts.theme.screenlocktest", + "vendor": "open", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 7, + "releaseType": "Release", + "target": 9 + } + }, + "deviceConfig": {}, + "module": { + "package": "com.acts.theme.screenlocktest", + "name": ".MyApplication", + "mainAbility": "com.acts.theme.screenlocktest.MainAbility", + + "deviceType": [ + "tablet", + "default", + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "visible": true, + "srcPath": "MainAbility", + "name": ".MainAbility", + "srcLanguage": "ets", + "icon": "$media:icon", + "description": "$string:description_mainability", + "formsEnabled": false, + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard" + }, + { + "orientation": "unspecified", + "visible": true, + "srcPath": "TestAbility", + "name": ".TestAbility", + "srcLanguage": "ets", + "icon": "$media:icon", + "description": "$string:TestAbility_desc", + "formsEnabled": false, + "label": "$string:TestAbility_label", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "mode": { + "syntax": "ets", + "type": "pageAbility" + }, + "pages": [ + "pages/index" + ], + "name": ".MainAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + }, + { + "mode": { + "syntax": "ets", + "type": "pageAbility" + }, + "pages": [ + "pages/index" + ], + "name": ".TestAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/theme/screenlock_ets/entry/src/main/ets/MainAbility/app.ets b/theme/screenlock_ets/entry/src/main/ets/MainAbility/app.ets new file mode 100644 index 0000000000000000000000000000000000000000..2e4e48f739b88cd4fbcc15d4e54b244d5af51d90 --- /dev/null +++ b/theme/screenlock_ets/entry/src/main/ets/MainAbility/app.ets @@ -0,0 +1,33 @@ +// @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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from 'hypium/index' +import testsuite from '../test/List.test' + +export default { + onCreate() { + console.info('Application onCreate') + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + }, + onDestroy() { + console.info('Application onDestroy') + }, +} \ No newline at end of file diff --git a/theme/screenlock_ets/entry/src/main/ets/MainAbility/pages/index.ets b/theme/screenlock_ets/entry/src/main/ets/MainAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..eb4afee1d15e74b4dd25ca165591798b4ba7c01e --- /dev/null +++ b/theme/screenlock_ets/entry/src/main/ets/MainAbility/pages/index.ets @@ -0,0 +1,38 @@ +// @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. + */ + +@Entry +@Component +struct MyComponent { + aboutToAppear() { + } + + + build() { + Flex({ + direction: FlexDirection.Column, + alignItems: ItemAlign.Center, + justifyContent: FlexAlign.Center + }) { + Text('SCREENLOCK ETS TEST') + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} + diff --git a/theme/screenlock_ets/entry/src/main/ets/TestAbility/app.ets b/theme/screenlock_ets/entry/src/main/ets/TestAbility/app.ets new file mode 100644 index 0000000000000000000000000000000000000000..2e4e48f739b88cd4fbcc15d4e54b244d5af51d90 --- /dev/null +++ b/theme/screenlock_ets/entry/src/main/ets/TestAbility/app.ets @@ -0,0 +1,33 @@ +// @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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from 'hypium/index' +import testsuite from '../test/List.test' + +export default { + onCreate() { + console.info('Application onCreate') + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + }, + onDestroy() { + console.info('Application onDestroy') + }, +} \ No newline at end of file diff --git a/theme/screenlock_ets/entry/src/main/ets/TestAbility/pages/index.ets b/theme/screenlock_ets/entry/src/main/ets/TestAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b2497c3b2774b09a40f0db535735f3dbe5e6cb6e --- /dev/null +++ b/theme/screenlock_ets/entry/src/main/ets/TestAbility/pages/index.ets @@ -0,0 +1,50 @@ +// @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 router from '@system.router'; + +@Entry +@Component +struct Index { + aboutToAppear() { + console.info('TestAbility index aboutToAppear') + } + + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/theme/screenlock_ets/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/theme/screenlock_ets/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..07cb0b784984c6c4cc6d911c3c82643bff9df263 --- /dev/null +++ b/theme/screenlock_ets/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,78 @@ +// @ts-nocheck +/** + * Copyright (c) 2021 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 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 itName', + '-s level', '-s testType', '-s size', '-s timeout', + '-s package' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams += ' ' + key + ' ' + parameters[key] + } + } + return targetParams.trim() +} + +async function onAbilityCreateCallback() { + console.log('onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + console.info('addAbilityMonitorCallback : ' + JSON.stringify(err)) +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info('OpenHarmonyTestRunner OnPrepare') + } + + onRun() { + console.log('OpenHarmonyTestRunner onRun run') + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.MainAbility' + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }) + console.info('OpenHarmonyTestRunner onRun call abilityDelegator.getAppContext') + var context = abilityDelegator.getAppContext() + console.info('getAppContext : ' + JSON.stringify(context)) + console.info('OpenHarmonyTestRunner onRun end') + } +}; \ No newline at end of file diff --git a/theme/screenlock_ets/entry/src/main/ets/test/List.test.ets b/theme/screenlock_ets/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..fd10a4e7cd4177f4a857951272c95969096a84cb --- /dev/null +++ b/theme/screenlock_ets/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,22 @@ +/* + * 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 screenLockJSUnit from './screenLockTest'; +import ScreenLockPromiseTest from './screenLockPromiseTest'; + +export default function testsuite() { + screenLockJSUnit(); + ScreenLockPromiseTest() +} \ No newline at end of file diff --git a/theme/screenlock_ets/entry/src/main/ets/test/screenLockPromiseTest.ets b/theme/screenlock_ets/entry/src/main/ets/test/screenLockPromiseTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..ad6c49af36daf0a59753bea8179f540f6f3df119 --- /dev/null +++ b/theme/screenlock_ets/entry/src/main/ets/test/screenLockPromiseTest.ets @@ -0,0 +1,135 @@ +// @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 screenLock from '@ohos.screenLock'; +import { describe, expect, it, beforeEach} from "hypium/index"; + +const SLEEP_TIME = 1000; + +export default function ScreenLockPromiseTest(){ + describe('ScreenLockServicePromiseTest', function () { + console.info("-----------------------ScreenlockPromiseTest is starting-----------------------"); + + let result = false + beforeEach(async function (done) { + result = await screenLock.isScreenLocked(); + done(); + }); + + /* + * @tc.number SUB_MISC_THEME_screenLock_API_Promise_001 + * @tc.name Set to locked screen, query the lock screen state is locked state + * @tc.desc Test ScreenLock API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it("SUB_MISC_THEME_screenLock_API_Promise_001", 0, async function (done) { + console.info("------------------start SUB_MISC_THEME_screenLock_API_Promise_001-------------------"); + try { + screenLock.isScreenLocked().then((data) => { + console.info("SUB_MISC_THEME_screenLock_API_Promise_001 isScreenLocked result is " + data); + expect(data == result).assertTrue() + console.info("------------------end SUB_MISC_THEME_screenLock_API_Promise_001-------------------"); + done(); + }) + } catch (error) { + console.info("SUB_MISC_THEME_screenLock_API_Promise_001 test_setScreenLocked : error = " + error); + expect().assertFail(); + done(); + } + + }); + + /* + * @tc.number SUB_MISC_THEME_screenLock_API_Promise_002 + * @tc.name Set to locked screen, query the lock screen state is locked state + * @tc.desc Test ScreenLock API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it("SUB_MISC_THEME_screenLock_API_Promise_002", 0, async function (done) { + console.info("------------------start SUB_MISC_THEME_screenLock_API_Promise_002-------------------"); + try { + screenLock.isScreenLocked().then((data) => { + console.info("SUB_MISC_THEME_screenLock_API_Promise_002 isScreenLocked result is " + data); + expect(data == result).assertTrue(); + console.info("------------------end SUB_MISC_THEME_screenLock_API_Promise_002-------------------"); + done(); + }); + } catch (error) { + console.info("SUB_MISC_THEME_screenLock_API_Promise_002 test_setScreenLocked : error = " + error); + expect().assertFail(); + done(); + } + + }); + + /* + * @tc.number SUB_MISC_THEME_screenLock_API_Promise_003 + * @tc.name Set to locked screen, query the lock screen state is locked state + * @tc.desc Test ScreenLock API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it("SUB_MISC_THEME_screenLock_API_Promise_003", 0, async function (done) { + console.info("------------------start SUB_MISC_THEME_screenLock_API_Promise_003-------------------"); + try { + screenLock.isSecureMode().then((data) => { + console.info("SUB_MISC_THEME_screenLock_API_Promise_003 isScreenLocked result is " + data); + expect(data == false).assertTrue(); + console.info("------------------end SUB_MISC_THEME_screenLock_API_Promise_003-------------------"); + done(); + }); + } catch (error) { + console.info("SUB_MISC_THEME_screenLock_API_Promise_003 isScreenLocked TRUE: error = " + error); + expect().assertFail(); + done(); + } + }); + + /* + * @tc.number SUB_MISC_THEME_screenLock_API_Promise_004 + * @tc.name Set to locked screen, query the lock screen state is locked state + * @tc.desc Test ScreenLock API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it("SUB_MISC_THEME_screenLock_API_Promise_004", 0, async function (done) { + console.info("------------------start SUB_MISC_THEME_screenLock_API_Promise_004-------------------"); + try { + screenLock.unlockScreen().then((data) => { + let currentResult = screenLock.isLocked() + expect(currentResult).assertEqual(false) + console.info("====>SUB_MISC_THEME_screenLock_API_Promise_004 success."); + console.info('====>-------------SUB_MISC_THEME_screenLock_API_Promise_004 end----------------------'); + done(); + }).catch( err => { + console.info("====>SUB_MISC_THEME_screenLock_API_Promise_004 failed because: " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + } catch (error) { + console.info("====>SUB_MISC_THEME_screenLock_API_Promise_004: error = " + error); + expect(true).assertTrue(); + } + console.info("------------------end SUB_MISC_THEME_screenLock_API_Promise_004-------------------"); + done(); + }); + }) +} diff --git a/theme/screenlock_ets/entry/src/main/ets/test/screenLockTest.ets b/theme/screenlock_ets/entry/src/main/ets/test/screenLockTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..c4f6a9db7fe482ee6f1cb16f235491a595ba7489 --- /dev/null +++ b/theme/screenlock_ets/entry/src/main/ets/test/screenLockTest.ets @@ -0,0 +1,306 @@ +/* + * 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 screenLock from '@ohos.screenLock'; +import { describe, expect, it, beforeEach} from "hypium/index"; + +export default function screenLockJSUnit() { + const INTERACTIVE_STATE_END_SLEEP = 0; + const INTERACTIVE_STATE_USERID = 2; + const INTERACTIVE_STATE_BEGIN_SLEEP = 3; + + describe('ScreenLockServiceTest', function () { + console.info("====>-----------------------ScreenlockTest is starting-----------------------"); + + let result = false + beforeEach(async function (done) { + result = await screenLock.isScreenLocked(); + done(); + }); + + /* + * @tc.number SUB_MISC_THEME_screenLock_API_0012 + * @tc.name Test unlock() to Unlocks the screen. + * @tc.desc Function test + * @tc.level 0 + */ + it('SUB_MISC_THEME_screenLock_API_0012', 0, async function (done) { + console.info('====>-------------SUB_MISC_THEME_screenLock_API_0012 start----------------------'); + try{ + screenLock.unlock((err, data) => { + try{ + if (err) { + console.info("====>SUB_MISC_THEME_screenLock_API_0012 failed because: " + JSON.stringify(err)); + expect().assertFail(); + done(); + } + let currentResult = screenLock.isLocked() + expect(currentResult).assertEqual(false) + console.info("====>SUB_MISC_THEME_screenLock_API_0012 success."); + console.info('====>-------------SUB_MISC_THEME_screenLock_API_0012 end----------------------'); + done(); + }catch(err){ + console.info('====>SUB_MISC_THEME_screenLock_API_0012 throw_err : ' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + }); + }catch(err){ + console.info('====>SUB_MISC_THEME_screenLock_API_0012 catch err : ' + JSON.stringify(err)); + expect(err.code).assertEqual(201); + done(); + } + }) + + /* + * @tc.number SUB_MISC_THEME_screenLock_API_0013 + * @tc.name Test unlock() to Unlocks the screen. + * @tc.desc Function test + * @tc.level 0 + */ + it('SUB_MISC_THEME_screenLock_API_0013', 0, async function (done) { + console.info('====>-------------SUB_MISC_THEME_screenLock_API_0013 start----------------------'); + try{ + screenLock.unlock().then((data) => { + let currentResult = screenLock.isLocked() + expect(currentResult).assertEqual(false) + console.info("====>SUB_MISC_THEME_screenLock_API_0013 success."); + console.info('====>-------------SUB_MISC_THEME_screenLock_API_0013 end----------------------'); + done(); + }).catch( err => { + console.info("====>SUB_MISC_THEME_screenLock_API_0013 failed because: " + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + }catch(err){ + console.info('====>SUB_MISC_THEME_screenLock_API_0013 catch err : ' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + }); + + /* + * @tc.number SUB_MISC_THEME_screenLock_API_0001 + * @tc.name Set to locked screen, query the lock screen state is locked state + * @tc.desc Test ScreenLock API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it("SUB_MISC_THEME_screenLock_API_0001", 0, async function (done) { + console.info("====>------------------start SUB_MISC_THEME_screenLock_API_0001-------------------"); + try { + screenLock.isScreenLocked((err, data) => { + try{ + if(err){ + console.info("====>SUB_MISC_THEME_screenLock_API_0001 failed because: " + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info("====>SUB_MISC_THEME_screenLock_API_0001 screen's status is " + data); + expect(data == result).assertTrue(); + console.info("====>------------------end SUB_MISC_THEME_screenLock_API_0001-------------------"); + done(); + + }catch(err){ + console.info("====>logMessage SUB_MISC_THEME_screenLock_API_0001 throw_err = " + err); + expect().assertFail(); + done(); + } + }); + } catch (err) { + console.info("====>logMessage SUB_MISC_THEME_screenLock_API_0001: err = " + err); + expect().assertFail(); + done(); + } + }); + + /* + * @tc.number SUB_MISC_THEME_screenLock_API_0002 + * @tc.name Set to locked screen, query the lock screen state is locked state + * @tc.desc Test ScreenLock API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it("SUB_MISC_THEME_screenLock_API_0002", 0, async function (done) { + console.info("====>------------------start SUB_MISC_THEME_screenLock_API_0002-------------------"); + try { + screenLock.isScreenLocked((err, data) => { + try{ + console.info("====>SUB_MISC_THEME_screenLock_API_0002 screen's status is " + data); + expect(data == result).assertTrue(); + console.info("====>------------------end SUB_MISC_THEME_screenLock_API_0002-------------------"); + done(); + }catch(err){ + console.info("====>logMessage SUB_MISC_THEME_screenLock_API_0002 throw_err = " + err); + expect().assertFail(); + done(); + } + }); + } catch (err) { + console.info("====>logMessage SUB_MISC_THEME_screenLock_API_0002: err = " + err); + expect().assertFail(); + done(); + } + }); + + /* + * @tc.number SUB_MISC_THEME_screenLock_API_0003 + * @tc.name Set to locked screen, query the lock screen state is locked state + * @tc.desc Test ScreenLock API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it("SUB_MISC_THEME_screenLock_API_0003", 0, async function (done) { + console.info("====>------------------start SUB_MISC_THEME_screenLock_API_0003-------------------"); + try { + screenLock.isSecureMode((err, data) => { + try{ + console.info("====>SUB_MISC_THEME_screenLock_API_0003 secureMode's result is " + data); + expect(data == result).assertTrue(); + console.info("====>------------------end SUB_MISC_THEME_screenLock_API_0003-------------------"); + done(); + }catch(err){ + console.info("====>logMessage SUB_MISC_THEME_screenLock_API_0003 throw_err = " + err); + expect().assertFail(); + done(); + } + }); + } catch (err) { + console.info("====>logMessage SUB_MISC_THEME_screenLock_API_0003: err = " + err); + expect().assertFail(); + done(); + } + }); + + /* + * @tc.number SUB_MISC_THEME_screenLock_API_0004 + * @tc.name Set to locked screen, query the lock screen state is locked state + * @tc.desc Test ScreenLock API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it("SUB_MISC_THEME_screenLock_API_0004", 0, async function (done) { + console.info("------------------start SUB_MISC_THEME_screenLock_API_0004-------------------"); + try { + screenLock.unlockScreen((err) => { + console.info("SUB_MISC_THEME_screenLock_API_0004: send unlockScreen issue success"); + try{ + if (err) { + console.info("====>SUB_MISC_THEME_screenLock_API_0004 failed because: " + JSON.stringify(err)); + expect().assertFail(); + done(); + } + let currentResult = screenLock.isLocked() + expect(currentResult).assertEqual(false) + console.info("====>SUB_MISC_THEME_screenLock_API_0004 success."); + console.info('====>-------------SUB_MISC_THEME_screenLock_API_0004 end----------------------'); + done(); + }catch(err){ + console.info('====>SUB_MISC_THEME_screenLock_API_0004 throw_err : ' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + }); + } catch (error) { + console.info("SUB_MISC_THEME_screenLock_API_0004: error = " + error); + expect().assertFail(); + done(); + } + }); + + /* + * @tc.number SUB_MISC_THEME_screenLock_API_0007 + * @tc.name Set to locked screen, query the lock screen state is locked state + * @tc.desc Test ScreenLock API functionality. + * @tc.size : MEDIUM + * @tc.type : Function + * @tc.level : Level 0 + */ + it("SUB_MISC_THEME_screenLock_API_0007", 0, async function (done) { + console.info("====>------------------start SUB_MISC_THEME_screenLock_API_0007-------------------"); + try { + screenLock.isScreenLocked((err, data) => { + try{ + console.info("====>SUB_MISC_THEME_screenLock_API_0007: isScreenLocked is successful, result is " + data); + expect(data == result).assertTrue(); + console.info("====>------------------end SUB_MISC_THEME_screenLock_API_0007-------------------"); + done(); + }catch(err){ + console.info("====>logMessage SUB_MISC_THEME_screenLock_API_0007 throw_err = " + err); + expect().assertFail(); + done(); + } + }); + } catch (err) { + console.info("====>logMessage SUB_MISC_THEME_screenLock_API_0007: err = " + err); + expect().assertFail(); + done(); + } + + }); + + /* + * @tc.number SUB_MISC_THEME_screenLock_API_0010 + * @tc.name Test isLocked() to Checks whether the screen is currently locked. + * @tc.desc Function test + * @tc.level 0 + */ + it('SUB_MISC_THEME_screenLock_API_0010', 0, async function (done) { + console.info('====>-------------SUB_MISC_THEME_screenLock_API_0010 start----------------------'); + let lock = null; + try{ + lock = await screenLock.isLocked() + console.info('====>SUB_MISC_THEME_screenLock_API_0010 data : ' + JSON.stringify(lock)); + expect(lock).assertEqual(result); + console.info('====>-------------SUB_MISC_THEME_screenLock_API_0010 end----------------------'); + done() + }catch(err){ + console.info('====>SUB_MISC_THEME_screenLock_API_0010 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + }); + + /* + * @tc.number SUB_MISC_THEME_screenLock_API_0011 + * @tc.name Test isSecure() to Checks whether the screen lock of the current device is secure. + * @tc.desc Function test + * @tc.level 0 + */ + it('SUB_MISC_THEME_screenLock_API_0011', 0, async function (done) { + console.info('====>-------------SUB_MISC_THEME_screenLock_API_0011 start----------------------'); + let secured = null; + try{ + secured = screenLock.isSecure() + console.info('====>SUB_MISC_THEME_screenLock_API_0011 data : ' + JSON.stringify(secured)); + if (typeof secured == "boolean") { + expect(true).assertTrue(); + console.info('====>-------------SUB_MISC_THEME_screenLock_API_0011 end----------------------'); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('====>SUB_MISC_THEME_screenLock_API_0011 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + }); + }); +} diff --git a/theme/screenlock_ets/entry/src/main/resources/base/element/string.json b/theme/screenlock_ets/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..498677efbde065c36668727190d3613cbf278bfc --- /dev/null +++ b/theme/screenlock_ets/entry/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "entry_MainAbility" + }, + { + "name": "description_mainability", + "value": "ETS_Empty Ability" + }, + { + "name": "TestAbility_desc", + "value": "description" + }, + { + "name": "TestAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/theme/screenlock_ets/entry/src/main/resources/base/media/icon.png b/theme/screenlock_ets/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/theme/screenlock_ets/entry/src/main/resources/base/media/icon.png differ diff --git a/theme/screenlock_ets/signature/openharmony_sx.p7b b/theme/screenlock_ets/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..81e7eb2cf2ebe9a2943002ba33ff0f4876d481d8 Binary files /dev/null and b/theme/screenlock_ets/signature/openharmony_sx.p7b differ diff --git a/theme/wallpaper_ets/BUILD.gn b/theme/wallpaper_ets/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..46487916ac165d2b2c8721b71c570c70934fdd7e --- /dev/null +++ b/theme/wallpaper_ets/BUILD.gn @@ -0,0 +1,39 @@ +# 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("//build/ohos.gni") +import("//test/xts/tools/build/suite.gni") +ohos_js_hap_suite("ActsWallpaperETSApiTest") { + hap_profile = "./entry/src/main/config.json" + deps = [ + ":wallPaper_ets_assets", + ":wallPaper_ets_resources", + ":wallPaper_ets_test_assets", + ] + ets2abc = true + subsystem_name = "theme" + part_name = "wallpaper_mgr" + certificate_profile = "./signature/ActsWallpaperEtsAPITest.p7b" + hap_name = "ActsWallpaperETSApiTest" +} + +ohos_js_assets("wallPaper_ets_assets") { + source_dir = "./entry/src/main/ets/MainAbility" +} +ohos_js_assets("wallPaper_ets_resources") { + source_dir = "./entry/src/main/ets/TestAbility" +} +ohos_resources("wallPaper_ets_test_assets") { + sources = [ "./entry/src/main/resources" ] + hap_profile = "./entry/src/main/config.json" +} diff --git a/theme/wallpaper_ets/Test.json b/theme/wallpaper_ets/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..87fa69645c80f4e9b940727bef3f43c20108a8bc --- /dev/null +++ b/theme/wallpaper_ets/Test.json @@ -0,0 +1,29 @@ +{ + "description": "Configuration for wallpaper js api Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "600000", + "bundle-name": "com.acts.theme.wallpapertest", + "package-name": "com.acts.theme.wallpapertest", + "shell-timeout": "600000" + }, + "kits": [ + { + "test-file-name": [ + "ActsWallpaperETSApiTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + }, + { + "type": "PushKit", + "pre-push": [ + "mount -o rw,remount /", + "mkdir -p /data/app/el2/100/base/com.acts.theme.wallpapertest/haps" + ], + "push": [ + "./resource/wallpaper/wp.png ->/data/app/el2/100/base/com.acts.theme.wallpapertest/haps/wp.png" + ] + } + ] +} diff --git a/theme/wallpaper_ets/entry/src/main/config.json b/theme/wallpaper_ets/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..632ef1bab44c72971aebf16230bda2b990b6dbb7 --- /dev/null +++ b/theme/wallpaper_ets/entry/src/main/config.json @@ -0,0 +1,125 @@ +{ + "app": { + "bundleName": "com.acts.theme.wallpapertest", + "vendor": "open", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 7, + "releaseType": "Release", + "target": 9 + } + }, + "deviceConfig": {}, + "module": { + "package": "com.acts.theme.wallpapertest", + "name": ".MyApplication", + "mainAbility": "com.acts.theme.wallpapertest.MainAbility", + + "deviceType": [ + "tablet", + "default", + "phone", + "tv", + "wearable" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "visible": true, + "srcPath": "MainAbility", + "name": ".MainAbility", + "srcLanguage": "ets", + "icon": "$media:icon", + "description": "$string:description_mainability", + "formsEnabled": false, + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard" + }, + { + "orientation": "unspecified", + "visible": true, + "srcPath": "TestAbility", + "name": ".TestAbility", + "srcLanguage": "ets", + "icon": "$media:icon", + "description": "$string:TestAbility_desc", + "formsEnabled": false, + "label": "$string:TestAbility_label", + "type": "page", + "launchType": "standard" + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.SET_WALLPAPER", + "reason": "need use ohos.permission.SET_WALLPAPER", + "usedScene": { + "ability": [ + "com.acts.theme.wallpapertest.MainAbility" + ], + "when": "inuse" + } + }, + { + "name": "ohos.permission.GET_WALLPAPER", + "reason": "need use ohos.permission.GET_WALLPAPER", + "usedScene": { + "ability": [ + "com.acts.theme.wallpapertest.MainAbility" + ], + "when": "inuse" + } + } + ], + "js": [ + { + "mode": { + "syntax": "ets", + "type": "pageAbility" + }, + "pages": [ + "pages/index" + ], + "name": ".MainAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + }, + { + "mode": { + "syntax": "ets", + "type": "pageAbility" + }, + "pages": [ + "pages/index" + ], + "name": ".TestAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/theme/wallpaper_ets/entry/src/main/ets/MainAbility/app.ets b/theme/wallpaper_ets/entry/src/main/ets/MainAbility/app.ets new file mode 100644 index 0000000000000000000000000000000000000000..2e4e48f739b88cd4fbcc15d4e54b244d5af51d90 --- /dev/null +++ b/theme/wallpaper_ets/entry/src/main/ets/MainAbility/app.ets @@ -0,0 +1,33 @@ +// @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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from 'hypium/index' +import testsuite from '../test/List.test' + +export default { + onCreate() { + console.info('Application onCreate') + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + }, + onDestroy() { + console.info('Application onDestroy') + }, +} \ No newline at end of file diff --git a/theme/wallpaper_ets/entry/src/main/ets/MainAbility/pages/index.ets b/theme/wallpaper_ets/entry/src/main/ets/MainAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..f76e64e54211411bfd8eb003a4743d730669c905 --- /dev/null +++ b/theme/wallpaper_ets/entry/src/main/ets/MainAbility/pages/index.ets @@ -0,0 +1,38 @@ +// @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. + */ + +@Entry +@Component +struct MyComponent { + aboutToAppear() { + } + + + build() { + Flex({ + direction: FlexDirection.Column, + alignItems: ItemAlign.Center, + justifyContent: FlexAlign.Center + }) { + Text('WALLPAPER ETS TEST') + .fontSize(50) + .fontWeight(FontWeight.Bold) + } + .width('100%') + .height('100%') + } +} + diff --git a/theme/wallpaper_ets/entry/src/main/ets/TestAbility/app.ets b/theme/wallpaper_ets/entry/src/main/ets/TestAbility/app.ets new file mode 100644 index 0000000000000000000000000000000000000000..2e4e48f739b88cd4fbcc15d4e54b244d5af51d90 --- /dev/null +++ b/theme/wallpaper_ets/entry/src/main/ets/TestAbility/app.ets @@ -0,0 +1,33 @@ +// @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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from 'hypium/index' +import testsuite from '../test/List.test' + +export default { + onCreate() { + console.info('Application onCreate') + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + }, + onDestroy() { + console.info('Application onDestroy') + }, +} \ No newline at end of file diff --git a/theme/wallpaper_ets/entry/src/main/ets/TestAbility/pages/index.ets b/theme/wallpaper_ets/entry/src/main/ets/TestAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b2497c3b2774b09a40f0db535735f3dbe5e6cb6e --- /dev/null +++ b/theme/wallpaper_ets/entry/src/main/ets/TestAbility/pages/index.ets @@ -0,0 +1,50 @@ +// @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 router from '@system.router'; + +@Entry +@Component +struct Index { + aboutToAppear() { + console.info('TestAbility index aboutToAppear') + } + + @State message: string = 'Hello World' + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(20) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('35%') + .height('5%') + .onClick(()=>{ + }) + } + .width('100%') + } + .height('100%') + } + } \ No newline at end of file diff --git a/theme/wallpaper_ets/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/theme/wallpaper_ets/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..07cb0b784984c6c4cc6d911c3c82643bff9df263 --- /dev/null +++ b/theme/wallpaper_ets/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,78 @@ +// @ts-nocheck +/** + * Copyright (c) 2021 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 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 itName', + '-s level', '-s testType', '-s size', '-s timeout', + '-s package' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams += ' ' + key + ' ' + parameters[key] + } + } + return targetParams.trim() +} + +async function onAbilityCreateCallback() { + console.log('onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + console.info('addAbilityMonitorCallback : ' + JSON.stringify(err)) +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info('OpenHarmonyTestRunner OnPrepare') + } + + onRun() { + console.log('OpenHarmonyTestRunner onRun run') + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.MainAbility' + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }) + console.info('OpenHarmonyTestRunner onRun call abilityDelegator.getAppContext') + var context = abilityDelegator.getAppContext() + console.info('getAppContext : ' + JSON.stringify(context)) + console.info('OpenHarmonyTestRunner onRun end') + } +}; \ No newline at end of file diff --git a/theme/wallpaper_ets/entry/src/main/ets/test/List.test.ets b/theme/wallpaper_ets/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..11551f27afcd509cd044a008546cec7ca9adf953 --- /dev/null +++ b/theme/wallpaper_ets/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,20 @@ +/* + * 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 wallpaperJSUnit from './wallpaperTest'; + +export default function testsuite() { + wallpaperJSUnit(); +} \ No newline at end of file diff --git a/theme/wallpaper_ets/entry/src/main/ets/test/wallpaperTest.ets b/theme/wallpaper_ets/entry/src/main/ets/test/wallpaperTest.ets new file mode 100644 index 0000000000000000000000000000000000000000..d01fd887c163f3b5e858ae8568aa1f37b78ce8b0 --- /dev/null +++ b/theme/wallpaper_ets/entry/src/main/ets/test/wallpaperTest.ets @@ -0,0 +1,1200 @@ +/* + * 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 wallpaper from '@ohos.wallpaper'; +import image from '@ohos.multimedia.image'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'; + +const WALLPAPER_SYSTEM = 0; +const WALLPAPER_LOCKSCREEN = 1; +let imageSourceSystem = '/data/storage/el2/base/haps/wp.png'; +let imageSourceLockscreen = '/data/storage/el2/base/haps/wp.png'; + +export default function wallpaperJSUnit() { + describe('WallpaperJsunitTest', function () { + + /* + * @tc.number testWALLPAPER_SYSTEM + * @tc.name Test WALLPAPER_SYSTEM value + * @tc.desc Function test + * @tc.level 0 + */ + it('testWALLPAPER_SYSTEM', 0, async function (done) { + console.info('--------------testWALLPAPER_SYSTEM start-----------------'); + console.info('wallpaperXTS ===> testWALLPAPER_SYSTEM : ' + + JSON.stringify(wallpaper.WallpaperType.WALLPAPER_SYSTEM)); + expect(wallpaper.WallpaperType.WALLPAPER_SYSTEM == 0).assertTrue(); + done(); + console.info('--------------testWALLPAPER_SYSTEM end-----------------'); + }); + + /* + * @tc.number testWALLPAPER_LOCKSCREEN + * @tc.name Test WALLPAPER_LOCKSCREEN value + * @tc.desc Function test + * @tc.level 0 + */ + it('testWALLPAPER_LOCKSCREEN', 0, async function (done) { + console.info('--------------testWALLPAPER_LOCKSCREEN start-----------------'); + console.info('wallpaperXTS ===> testWALLPAPER_LOCKSCREEN : ' + + JSON.stringify(wallpaper.WallpaperType.WALLPAPER_LOCKSCREEN)); + expect(wallpaper.WallpaperType.WALLPAPER_LOCKSCREEN == 1).assertTrue(); + done(); + console.info('--------------testWALLPAPER_LOCKSCREEN end-----------------'); + }); + + /* + * @tc.number testGetColorsCallbackSystem101 + * @tc.name Test getColors() to obtains the wallpaper colors for the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetColorsCallbackSystem101', 0, async function (done) { + console.info('--------------testGetColorsCallbackSystem101 start-----------------'); + wallpaper.getColors(WALLPAPER_SYSTEM, (err, RgbaColors) => { + let RgbaColor = { + red: 152, + green: 182, + blue: 211, + alpha: 255 + } + try { + if (err) { + console.info('====>testGetColorsCallbackSystem101 fail: ' + JSON.stringify(err)); + expect(null).assertFail(); + done(); + } + console.info('====>testGetColorsCallbackSystem101 succesful RgbaColors: ' + JSON.stringify(RgbaColors)); + expect(Number.isInteger(RgbaColors[0].red)).assertTrue(); + expect(Number.isInteger(RgbaColors[0].green)).assertTrue(); + expect(Number.isInteger(RgbaColors[0].blue)).assertTrue(); + expect(Number.isInteger(RgbaColors[0].alpha)).assertTrue(); + done(); + } catch (err) { + console.info('====>testGetColorsCallbackSystem101 catch err: ' + JSON.stringify(err)); + done(); + }; + }); + console.info('--------------testGetColorsCallbackSystem101 end-----------------'); + }); + + /* + * @tc.number testGetColorsPromiseSystem101 + * @tc.name Test getColors() to obtains the wallpaper colors for the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetColorsPromiseSystem101', 0, async function (done) { + console.info('--------------testGetColorsPromiseSystem101 start-----------------'); + await wallpaper.getColors(WALLPAPER_SYSTEM).then((RgbaColors) => { + console.info('====>testGetColorsPromiseSystem101 succesful RgbaColors: ' + JSON.stringify(RgbaColors)); + expect(Number.isInteger(RgbaColors[0].red)).assertTrue(); + expect(Number.isInteger(RgbaColors[0].green)).assertTrue(); + expect(Number.isInteger(RgbaColors[0].blue)).assertTrue(); + expect(Number.isInteger(RgbaColors[0].alpha)).assertTrue(); + done(); + }).catch((err) => { + console.info('====>testGetColorsPromiseSystem101 fail: ' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info('--------------testGetColorsPromiseSystem101 end-----------------'); + }); + + /* + * @tc.number testGetColorsCallbackLock102 + * @tc.name Test getColors() to obtains the wallpaper colors for the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetColorsCallbackLock102', 0, async function (done) { + console.info('--------------testGetColorsCallbackLock102 start-----------------'); + wallpaper.getColors(WALLPAPER_LOCKSCREEN, (err, RgbaColors) => { + try { + if (err) { + console.info('====>testGetColorsCallbackLock102 fail: ' + JSON.stringify(err)); + expect(null).assertFail(); + done(); + } + console.info('====>testGetColorsCallbackLock102 succesful RgbaColors: ' + JSON.stringify(RgbaColors)); + expect(Number.isInteger(RgbaColors[0].red)).assertTrue(); + expect(Number.isInteger(RgbaColors[0].green)).assertTrue(); + expect(Number.isInteger(RgbaColors[0].blue)).assertTrue(); + expect(Number.isInteger(RgbaColors[0].alpha)).assertTrue(); + done(); + } catch (err) { + console.info('====>testGetColorsCallbackLock102 catch err: ' + JSON.stringify(err)); + done(); + }; + }); + console.info('--------------testGetColorsCallbackLock102 end-----------------'); + }); + + /* + * @tc.number testGetColorsPromiseLock102 + * @tc.name Test getColors() to obtains the wallpaper colors for the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetColorsPromiseLock102', 0, async function (done) { + console.info('--------------testGetColorsPromiseLock102 start-----------------'); + await wallpaper.getColors(WALLPAPER_LOCKSCREEN).then((RgbaColors) => { + console.info('====>testGetColorsPromiseLock102 succesful RgbaColors: ' + JSON.stringify(RgbaColors)); + expect(Number.isInteger(RgbaColors[0].red)).assertTrue(); + expect(Number.isInteger(RgbaColors[0].green)).assertTrue(); + expect(Number.isInteger(RgbaColors[0].blue)).assertTrue(); + expect(Number.isInteger(RgbaColors[0].alpha)).assertTrue(); + done(); + }).catch((err) => { + console.info('====>testGetColorsPromiseLock102 fail: ' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info('--------------testGetColorsPromiseLock102 end-----------------'); + }) + + /* + * @tc.number testGetIdCallbackSystem101 + * @tc.name Test getId() to the ID of the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetIdCallbackSystem101', 0, async function (done) { + console.info('--------------testGetIdCallbackSystem101 start-----------------'); + wallpaper.getId(WALLPAPER_SYSTEM, (err, data) => { + try { + if (err) { + console.info('====>testGetIdCallbackSystem101 err : ' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info('====>testGetIdCallbackSystem101 successful data: ' + JSON.stringify(data)); + expect(Number.isInteger(data)).assertTrue(); + done(); + } catch (err) { + console.info('====>testGetIdCallbackSystem101 catch err : ' + JSON.stringify(err)); + done(); + } + }); + console.info('--------------testGetIdCallbackSystem101 end-----------------'); + }); + + /* + * @tc.number testGetIdPromiseSystem101 + * @tc.name Test getId() to the ID of the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetIdPromiseSystem101', 0, async function (done) { + console.info('--------------testGetIdCallbackSystem101 start-----------------'); + await wallpaper.getId(WALLPAPER_SYSTEM).then((data) => { + console.info('====>testGetIdCallbackSystem101 data : ' + JSON.stringify(data)); + expect(Number.isInteger(data)).assertTrue(); + done(); + }).catch((err) => { + console.info('====>testGetIdCallbackSystem101 fail: ' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info('--------------testGetIdCallbackSystem101 end-----------------'); + }) + + /* + * @tc.number testGetIdCallbackLock102 + * @tc.name Test getId() to the ID of the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetIdCallbackLock102', 0, async function (done) { + console.info('--------------testGetIdCallbackLock102 start-----------------'); + wallpaper.getId(WALLPAPER_LOCKSCREEN, (err, data) => { + try { + if (err) { + console.info('====>testGetIdCallbackLock102 err : ' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info('====>testGetIdCallbackLock102 successful data: ' + JSON.stringify(data)); + expect(Number.isInteger(data)).assertTrue(); + done(); + } catch (err) { + console.info('====>testGetIdCallbackLock102 catch err : ' + JSON.stringify(err)); + done(); + } + }); + console.info('--------------testGetIdCallbackLock102 end-----------------'); + }); + + /* + * @tc.number testGetIdPromiseLock102 + * @tc.name Test getId() to the ID of the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetIdPromiseLock102', 0, async function (done) { + console.info('--------------testGetIdPromiseLock102 start-----------------'); + await wallpaper.getId(WALLPAPER_LOCKSCREEN).then((data) => { + console.info('====>testGetIdPromiseLock102 data : ' + JSON.stringify(data)); + expect(Number.isInteger(data)).assertTrue(); + done(); + }).catch((err) => { + console.info('====>testGetIdPromiseLock102 fail: ' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info('--------------testGetIdPromiseLock102 end-----------------'); + }); + + + + /* + * @tc.number testGetMinHeightCallback101 + * @tc.name Test getMinHeight() to the minimum width of the wallpaper. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetMinHeightCallback101', 0, async function (done) { + console.info('--------------testGetMinHeightCallback101 start-----------------'); + wallpaper.getMinHeight((err, data) => { + try { + if (err) { + console.info('====>testGetMinHeightCallback101 fail: ' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info('====>testGetMinHeightCallback101 successful data: ' + JSON.stringify(data)); + expect(Number.isInteger(data)).assertTrue(); + done(); + } catch (err) { + console.info('====>testGetMinHeightCallback101 catch err : ' + JSON.stringify(err)); + done(); + } + }); + console.info('--------------testGetMinHeightCallback101 end-----------------'); + }); + + /* + * @tc.number testGetMinHeightPromise101 + * @tc.name Test getMinHeight() to the minimum width of the wallpaper. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetMinHeightPromise101', 0, async function (done) { + console.info('--------------testGetMinHeightPromise101 start-----------------'); + await wallpaper.getMinHeight().then((data) => { + console.info('====>testGetMinHeightPromise101 successful data : ' + JSON.stringify(data)); + expect(Number.isInteger(data)).assertTrue(); + done(); + }).catch((err) => { + console.info('====>testGetMinHeightPromise101 err : ' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info('--------------testGetMinHeightPromise101 end-----------------'); + }); + + /* + * @tc.number testGetMinWidthCallback101 + * @tc.name Test getMinHeight() to the minimum width of the wallpaper. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetMinWidthCallback101', 0, async function (done) { + console.info('--------------testGetMinWidthCallback101 start-----------------'); + wallpaper.getMinWidth((err, data) => { + try { + if (err) { + console.info('====>testGetMinWidthCallback101 fail: ' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info('====>testGetMinWidthCallback101 successful data: ' + JSON.stringify(data)); + expect(Number.isInteger(data)).assertTrue(); + done(); + } catch (err) { + console.info('====>testGetMinWidthCallback101 catch err : ' + JSON.stringify(err)); + done(); + } + }); + console.info('--------------testGetMinWidthCallback101 end-----------------'); + }); + + /* + * @tc.number testGetMinWidthPromise101 + * @tc.name Test getMinHeight() to the minimum width of the wallpaper. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetMinWidthPromise101', 0, async function (done) { + console.info('--------------testGetMinWidthPromise101 start-----------------'); + await wallpaper.getMinWidth().then((data) => { + console.info('====>testGetMinWidthPromise101 successful data : ' + JSON.stringify(data)); + expect(Number.isInteger(data)).assertTrue(); + done(); + }).catch((err) => { + console.info('====>testGetMinWidthPromise101 err : ' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info('--------------testGetMinWidthPromise101 end-----------------'); + }); + + /* + * @tc.number testIsChangePermittedCallback101 + * @tc.name Test isChangePermitted() to checks whether to allow the application to change the + wallpaper for the current user. + * @tc.desc Function test + * @tc.level 0 + */ + it('testIsChangePermittedCallback101', 0, async function (done) { + console.info('--------------testIsChangePermittedCallback101 start-----------------'); + wallpaper.isChangePermitted((err, data) => { + try { + if (err) { + console.info('====>testIsChangePermittedCallback101 fail: ' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info('====>testIsChangePermittedCallback101 successful data: ' + JSON.stringify(data)); + expect(typeof data == "boolean").assertTrue(); + done(); + } catch (err) { + console.info('====>testIsChangePermittedCallback101 catch err : ' + JSON.stringify(err)); + done(); + } + }) + console.info('--------------testIsChangePermittedCallback101 end-----------------'); + }); + + /* + * @tc.number testIsChangePermittedPromise101 + * @tc.name Test isChangePermitted() to checks whether to allow the application to change the + wallpaper for the current user. + * @tc.desc Function test + * @tc.level 0 + */ + it('testIsChangePermittedPromise101', 0, async function (done) { + console.info('--------------testIsChangePermittedPromise101 start-----------------'); + await wallpaper.isChangePermitted().then((data) => { + console.info('====>testIsChangePermittedPromise101 successful data : ' + JSON.stringify(data)); + expect(typeof data == "boolean").assertTrue(); + done(); + }).catch((err) => { + console.info('====>testIsChangePermittedPromise101 err : ' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info('--------------testIsChangePermittedPromise101 end-----------------'); + }); + + /* + * @tc.number testIsOperationAllowedCallback101 + * @tc.name Test isOperationAllowed() to checks whether a user is allowed to set wallpapers. + * @tc.desc Function test + * @tc.level 0 + */ + it('testIsOperationAllowedCallback101', 0, async function (done) { + console.info('--------------testIsOperationAllowedCallback101 start-----------------'); + wallpaper.isOperationAllowed((err, data) => { + try { + if (err) { + console.info('====>testIsOperationAllowedCallback101 fail: ' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info('====>testIsOperationAllowedCallback101 successful data: ' + JSON.stringify(data)); + expect(typeof data == "boolean").assertTrue(); + done(); + } catch (err) { + console.info('====>testIsOperationAllowedCallback101 catch err : ' + JSON.stringify(err)); + done(); + } + }) + console.info('--------------testIsOperationAllowedCallback101 end-----------------'); + }); + + /* + * @tc.number testIsOperationAllowedPromise101 + * @tc.name Test isOperationAllowed() to checks whether a user is allowed to set wallpapers. + * @tc.desc Function test + * @tc.level 0 + */ + it('testIsOperationAllowedPromise101', 0, async function (done) { + console.info('--------------testIsOperationAllowedPromise101 start-----------------'); + await wallpaper.isOperationAllowed().then((data) => { + console.info('====>testIsOperationAllowedPromise101 successful data : ' + JSON.stringify(data)); + expect(typeof data == "boolean").assertTrue(); + done(); + }).catch((err) => { + console.info('====>testIsOperationAllowedPromise101 err : ' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info('--------------testIsOperationAllowedPromise101 end-----------------'); + }); + + /* + * @tc.number testResetCallbackSystem101 + * @tc.name Test reset() to removes a wallpaper of the specified type and restores the default one. + * @tc.desc Function test + * @tc.level 0 + */ + it('testResetCallbackSystem101', 0, async function (done) { + console.info('--------------testResetCallbackSystem101 start-----------------'); + wallpaper.reset(WALLPAPER_SYSTEM, (err, data) => { + try { + if (err) { + console.info('====>testResetCallbackSystem101 fail: ' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info('====>testResetCallbackSystem101 successful data: ' + JSON.stringify(data)); + expect(true).assertTrue(); + done(); + } catch (err) { + console.info('====>testResetCallbackSystem101 catch err : ' + JSON.stringify(err)); + done(); + } + }) + console.info('--------------testResetCallbackSystem101 end-----------------'); + }); + + /* + * @tc.number testResetPromiseSystem101 + * @tc.name Test reset() to removes a wallpaper of the specified type and restores the default one. + * @tc.desc Function test + * @tc.level 0 + */ + it('testResetPromiseSystem101', 0, async function (done) { + console.info('--------------testResetPromiseSystem101 start-----------------'); + await wallpaper.reset(WALLPAPER_SYSTEM).then((data) => { + console.info('====>testResetPromiseSystem101 successful data : ' + JSON.stringify(data)); + expect(true).assertTrue(); + done(); + }).catch((err) => { + console.info('====>testResetPromiseSystem101 err : ' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info('--------------testResetPromiseSystem101 end-----------------'); + }); + + /* + * @tc.number testResetCallbackLock102 + * @tc.name Test reset() to removes a wallpaper of the specified type and restores the default one. + * @tc.desc Function test + * @tc.level 0 + */ + it('testResetCallbackLock102', 0, async function (done) { + console.info('--------------testResetCallbackLock102 start-----------------'); + wallpaper.reset(WALLPAPER_LOCKSCREEN, (err, data) => { + try { + if (err) { + console.info('====>testResetCallbackLock102 fail: ' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info('====>testResetCallbackLock102 successful data: ' + JSON.stringify(data)); + expect(true).assertTrue(); + done(); + } catch (err) { + console.info('====>testResetCallbackLock102 catch err : ' + JSON.stringify(err)); + done(); + } + }) + console.info('--------------testResetCallbackLock102 end-----------------'); + }); + + /* + * @tc.number testResetPromiseLock102 + * @tc.name Test reset() to removes a wallpaper of the specified type and restores the default one. + * @tc.desc Function test + * @tc.level 0 + */ + it('testResetPromiseLock102', 0, async function (done) { + console.info('--------------testResetPromiseLock102 start-----------------'); + await wallpaper.reset(WALLPAPER_LOCKSCREEN).then((data) => { + console.info('====>testResetPromiseLock102 successful data : ' + JSON.stringify(data)); + expect(true).assertTrue(); + done(); + }).catch((err) => { + console.info('====>testResetPromiseLock102 err : ' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info('--------------testResetPromiseLock102 end-----------------'); + }); + + /* + * @tc.number testSetWallpaperURLPromiseLock104 + * @tc.name Test setPixelMap() to sets a wallpaper of the specified type based on the uri path from a + JPEG or PNG file or the pixel map of a PNG file. + * @tc.desc Function test + * @tc.level 0 + */ + it('testSetWallpaperURLPromiseLock104', 0, async function (done) { + console.info('--------------------testSetWallpaperURLPromiseLock104 start------------------' ); + await wallpaper.setWallpaper(imageSourceLockscreen, WALLPAPER_LOCKSCREEN).then((data) => { + console.info('====>testSetWallpaperURLPromiseLock104 successful data : ' + data); + expect(true).assertTrue(); + done(); + }).catch((err) => { + console.info('====>testSetWallpaperURLPromiseLock104 fail: ' + err); + expect().assertFail(); + done(); + }); + console.info('--------------------testSetWallpaperURLPromiseLock104 end------------------' ); + }); + + /* + * @tc.number testSetWallpaperURLCallbackSystem103 + * @tc.name Test setWallpaper() to sets a wallpaper of the specified type based on the uri path from a + JPEG or PNG file or the pixel map of a PNG file. + * @tc.desc Function test + * @tc.level 0 + */ + it('testSetWallpaperURLCallbackSystem103', 0, async function (done) { + console.info('--------------------testSetWallpaperURLCallbackSystem103 start------------------' ); + wallpaper.setWallpaper(imageSourceSystem, WALLPAPER_SYSTEM, (err, data) => { + try{ + if (err) { + console.info('====->testSetWallpaperURLCallbackSystem103 err : ' + err); + expect().assertFail(); + done(); + } + console.info('====>testSetWallpaperURLCallbackSystem103 successful data: ' + data); + expect(true).assertTrue(); + done(); + }catch(error){ + console.info('testSetWallpaperURLCallbackSystem103 catch error: ' + error); + done(); + } + }); + console.info('--------------------testSetWallpaperURLCallbackSystem103 end------------------' ); + }); + + /* + * @tc.number testSetWallpaperURLPromiseSystem103 + * @tc.name Test setWallpaper() to sets a wallpaper of the specified type based on the uri path from a + JPEG or PNG file or the pixel map of a PNG file. + * @tc.desc Function test + * @tc.level 0 + */ + it('testSetWallpaperURLPromiseSystem103', 0, async function (done) { + console.info('--------------------testSetWallpaperURLPromiseSystem103 start------------------' ); + await wallpaper.setWallpaper(imageSourceLockscreen, WALLPAPER_LOCKSCREEN).then((data) => { + console.info('====>testSetWallpaperURLPromiseSystem103 successful data : ' + data); + expect(true).assertTrue(); + done(); + }).catch((err) => { + console.info('====>testSetWallpaperURLPromiseSystem103 fail: ' + err); + expect().assertFail(); + done(); + }); + console.info('--------------------testSetWallpaperURLPromiseSystem103 end------------------' ); + }); + + /* + * @tc.number testSetWallpaperURLCallbackLock104 + * @tc.name Test setWallpaper() to sets a wallpaper of the specified type based on the uri path from a + JPEG or PNG file or the pixel map of a PNG file. + * @tc.desc Function test + * @tc.level 0 + */ + it('testSetWallpaperURLCallbackLock104', 0, async function (done) { + console.info('--------------------testSetWallpaperURLCallbackLock104 start------------------' ); + wallpaper.setWallpaper(imageSourceSystem, WALLPAPER_LOCKSCREEN, (err, data) => { + try{ + if (err) { + console.info('====->testSetWallpaperURLCallbackLock104 err : ' + err); + expect().assertFail(); + done(); + } + console.info('====>testSetWallpaperURLCallbackLock104 successful data: ' + data); + expect(true).assertTrue(); + done(); + }catch(error){ + console.info('testSetWallpaperURLCallbackLock104 catch error: ' + error); + done(); + } + }); + console.info('--------------------testSetWallpaperURLCallbackLock104 end------------------' ); + }); + + /* + * @tc.number testOnCallback101 + * @tc.name Test on_colorChange to registers a listener for wallpaper color changes to + receive notifications about the changes. + * @tc.desc Function test + * @tc.level 0 + */ + it('testOnCallback101', 0, async function (done) { + console.info('--------------testOnCallback101 start-----------------'); + let wallpaperPath = "/data/storage/el2/base/haps/wp.png"; + await wallpaper.restore(wallpaper.WallpaperType.WALLPAPER_LOCKSCREEN) + try { + wallpaper.on('colorChange', async (colors, wallpaperType) => { + try { + console.info('====>testOnCallback101 colors: ' + JSON.stringify(colors)); + console.info('====>testOnCallback101 wallpaperType: ' + JSON.stringify(wallpaperType)); + expect(colors != null).assertTrue(); + expect(wallpaperType != null).assertTrue(); + wallpaper.off('colorChange') + console.info('====>testOnCallback101 off'); + done(); + } catch (err) { + console.info('====>testOnCallback101 setImage or other err : ' + JSON.stringify(err)); + done(); + } + }); + } catch (err) { + console.info('====>testOnCallback101 catch err : ' + JSON.stringify(err)); + done(); + } + await wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_LOCKSCREEN) + console.info('====>testOnCallback10 setImage successful'); + console.info('--------------testOnCallback101 end-----------------'); + }); + + /* + * @tc.number testOffCallback101 + * @tc.name Test on_colorChange to registers a listener for wallpaper color changes to + receive notifications about the changes. + * @tc.desc Function test + * @tc.level 0 + */ + it('testOffCallback101', 0, async function (done) { + console.info('--------------testOffCallback101 start-----------------'); + let wallpaperPath = "/data/storage/el2/base/haps/wp.png"; + let callbackTimes = 0; + await wallpaper.restore(wallpaper.WallpaperType.WALLPAPER_SYSTEM) + try { + wallpaper.on('colorChange', async (colors, wallpaperType) => { + try { + console.info('====>testOffCallback101 colors: ' + JSON.stringify(colors)); + console.info('====>testOffCallback101 wallpaperType: ' + JSON.stringify(wallpaperType)); + callbackTimes = callbackTimes + 1; + console.info('====>testOffCallback101 on callbackTime: ' + callbackTimes); + expect(callbackTimes == 1).assertTrue(); + wallpaper.off('colorChange'); + setTimeout(() => { + done(); + }, 3000) + } catch (err) { + console.info('====>testOffCallback101 setImage or other err : ' + JSON.stringify(err)); + done(); + } + }); + } catch (err) { + console.info('====>testOffCallback101 catch err : ' + JSON.stringify(err)); + done(); + } + await wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM) + await wallpaper.restore(wallpaper.WallpaperType.WALLPAPER_SYSTEM) + await wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM) + console.info('====>testOffCallback101 setImage successful'); + console.info('--------------testOffCallback101 end-----------------'); + }); + + /* + * @tc.number testGetFileCallback101 + * @tc.name Obtains a file of the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetFileCallback101', 0, async function (done) { + console.info('--------------testGetFileCallback101 start-----------------'); + wallpaper.getFile(WALLPAPER_SYSTEM, (err, data) => { + try { + if (err) { + console.info('====>testGetFileCallback101 fail: ' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info('====>testGetFileCallback101 successful data: ' + JSON.stringify(data)); + expect(Number.isInteger(data)).assertTrue(); + done(); + } catch (err) { + console.info('====>testGetFileCallback101 catch err : ' + JSON.stringify(err)); + done(); + } + }); + console.info('--------------testGetFileCallback101 end-----------------'); + }); + + /* + * @tc.number testGetFilePromise101 + * @tc.name Obtains a file of the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetFilePromise101', 0, async function (done) { + console.info('--------------testGetFilePromise101 start-----------------'); + await wallpaper.getFile(WALLPAPER_LOCKSCREEN).then((data) => { + console.info('====>testGetFilePromise101 successful data : ' + JSON.stringify(data)); + expect(Number.isInteger(data)).assertTrue(); + done(); + }).catch((err) => { + console.info('====>testGetFilePromise101 err : ' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info('--------------testGetFilePromise101 end-----------------'); + }); + + /* + * @tc.number testGetColorsSync101 + * @tc.name Test getColorsSync() to obtains the wallpaper colors for the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetColorsSync101', 0, async function (done) { + console.info('------------------testGetColorsSync101 start----------------------'); + let colors = null; + try{ + colors = wallpaper.getColorsSync(WALLPAPER_SYSTEM) + console.info('wallpaperXTS ===> testGetColorsSync101 data : ' + JSON.stringify(colors)); + if (colors.length >= 1) { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('wallpaperXTS ===> testGetColorsSync101 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('------------------testGetColorsSync101 end----------------------'); + done() + }) + + /* + * @tc.number testGetColorsSync102 + * @tc.name Test getColorsSync() to obtains the wallpaper colors for the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetColorsSync102', 0, async function (done) { + console.info('------------------testGetColorsSync102 start----------------------'); + let colors = null; + try{ + colors = wallpaper.getColorsSync(WALLPAPER_LOCKSCREEN) + console.info('====>testGetColorsSync102 data : ' + JSON.stringify(colors)); + if (colors.length >= 1) { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('====>testGetColorsSync102 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('------------------testGetColorsSync102 end----------------------'); + }) + + /* + * @tc.number testGetIdSync101 + * @tc.name Test getIdSync() to Obtains the ID of the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetIdSync101', 0, async function (done) { + console.info('------------------testGetIdSync101 start----------------------'); + let number = null; + try{ + number = wallpaper.getIdSync(WALLPAPER_SYSTEM) + console.info('====>testGetIdSync101 data : ' + JSON.stringify(number)); + if (typeof number == "number") { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('====>testGetIdSync101 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('------------------testGetIdSync101 end----------------------'); + }) + + /* + * @tc.number testGetIdSync102 + * @tc.name Test getIdSync() to Obtains the ID of the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetIdSync102', 0, async function (done) { + console.info('------------------testGetIdSync102 start----------------------'); + let number = null; + try{ + number = wallpaper.getIdSync(WALLPAPER_LOCKSCREEN) + console.info('====>testGetIdSync102 data : ' + JSON.stringify(number)); + if (typeof number == "number") { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('====>testGetIdSync102 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('------------------testGetIdSync102 end----------------------'); + }) + + /* + * @tc.number testGetFileSync101 + * @tc.name Test getFileSync() to Obtains a file of the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetFileSync101', 0, async function (done) { + console.info('------------------testGetFileSync101 start----------------------'); + let number = null; + try{ + number = wallpaper.getFileSync(WALLPAPER_SYSTEM) + console.info('====>testGetFileSync101 data : ' + JSON.stringify(number)); + if (typeof number == "number") { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('====>testGetFileSync101 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('------------------testGetFileSync101 end----------------------'); + }) + + /* + * @tc.number testGetFileSync102 + * @tc.name Test getFileSync() to Obtains a file of the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetFileSync102', 0, async function (done) { + console.info('------------------testGetFileSync102 start----------------------'); + let number = null; + try{ + number = wallpaper.getFileSync(WALLPAPER_LOCKSCREEN) + console.info('====>testGetFileSync102 data : ' + JSON.stringify(number)); + if (typeof number == "number") { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('====>testGetFileSync102 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('------------------testGetFileSync102 end----------------------'); + }) + + /* + * @tc.number testGetFileSync103 + * @tc.name Test getFileSync() to Obtains a file of the wallpaper of the specified type. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetFileSync103', 0, async function (done) { + console.info('------------------testGetFileSync103 start----------------------'); + let number = null; + try{ + number = wallpaper.getFileSync(3) + console.info('====>testGetFileSync103 data : ' + JSON.stringify(number)); + if (typeof number == "number") { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('====>testGetFileSync103 err : ' + JSON.stringify(err)); + console.info('====>testGetFileSync103 (err.code : ' + err.code); + expect(err.code == "401").assertTrue(); + done() + } + console.info('------------------testGetFileSync103 end----------------------'); + }) + + /* + * @tc.number testGetMinHeightSync101 + * @tc.name Test getMinHeightSync() to Obtains the minimum height of the wallpaper. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetMinHeightSync101', 0, async function (done) { + console.info('------------------testGetMinHeightSync101 start----------------------'); + let number = null; + try{ + number = wallpaper.getMinHeightSync() + console.info('====>testGetMinHeightSync101 data : ' + JSON.stringify(number)); + if (typeof number == "number") { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('====>testGetMinHeightSync101 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('------------------testGetMinHeightSync101 end----------------------'); + done() + }) + + /* + * @tc.number testGetMinWidthSync101 + * @tc.name Test getMinWidthSync() to Obtains the minimum width of the wallpaper. + * @tc.desc Function test + * @tc.level 0 + */ + it('testGetMinWidthSync101', 0, async function (done) { + console.info('------------------testGetMinWidthSync101 start----------------------'); + let number = null; + try{ + number = wallpaper.getMinWidthSync() + console.info('====>testGetMinWidthSync101 data : ' + JSON.stringify(number)); + if (typeof number == "number") { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('====>testGetMinWidthSync101 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('------------------testGetMinWidthSync101 end----------------------'); + }) + + /* + * @tc.number testIsChangeAllowed101 + * @tc.name Test isChangeAllowed() to Checks whether to allow the application to change the wallpaper for the current user. + * @tc.desc Function test + * @tc.level 0 + */ + it('testIsChangeAllowed101', 0, async function (done) { + console.info('------------------testIsChangeAllowed101 start----------------------'); + let allow = null; + try{ + allow = wallpaper.isChangeAllowed() + console.info('====>testIsChangeAllowed101 data : ' + JSON.stringify(allow)); + if (typeof allow == "boolean") { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('====>testIsChangeAllowed101 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('------------------testIsChangeAllowed101 end----------------------'); + }) + + /* + * @tc.number testIsChangeAllowed101 + * @tc.name Test isUserChangeAllowed() to Checks whether a user is allowed to set wallpapers. + * @tc.desc Function test + * @tc.level 0 + */ + it('testIsUserChangeAllowed101', 0, async function (done) { + console.info('------------------testIsUserChangeAllowed101 start----------------------'); + let allow = null; + try{ + allow = wallpaper.isUserChangeAllowed() + console.info('====>testIsUserChangeAllowed101 data : ' + JSON.stringify(allow)); + if (typeof allow == "boolean") { + expect(true).assertTrue(); + done() + }else{ + expect().assertFail(); + done() + } + }catch(err){ + console.info('====>testIsUserChangeAllowed101 err : ' + JSON.stringify(err)); + expect().assertFail(); + done() + } + console.info('------------------testIsUserChangeAllowed101 end----------------------'); + done() + }) + + /* + * @tc.number testRestoreCallback101 + * @tc.name Test restore() to removes a wallpaper of the specified type and restores the default one. + * @tc.desc Function test + * @tc.level 0 + */ + it('testRestoreCallback101', 0, async function (done) { + console.info('------------------testRestoreCallback101 start----------------------'); + wallpaper.restore(WALLPAPER_LOCKSCREEN, function (err, data) { + try{ + console.info('====>testRestoreCallback101 data : ' + data); + if (err) { + console.info('====>testRestoreCallback101 fail: ' + JSON.stringify(err)); + expect().assertFail(); + done(); + } + console.info('====>testRestoreCallback101 restore success'); + expect(true).assertTrue(); + done(); + }catch(err){ + console.info('====>testRestoreCallback101 catch err : ' + JSON.stringify(err)); + done(); + } + }); + console.info('------------------testRestoreCallback101 end----------------------'); + }) + + /* + * @tc.number testRestorePromise101 + * @tc.name Test restore() to removes a wallpaper of the specified type and restores the default one. + * @tc.desc Function test + * @tc.level 0 + */ + it('testRestorePromise101', 0, async function (done) { + console.info('------------------testRestorePromise101 start----------------------'); + await wallpaper.restore(WALLPAPER_SYSTEM).then((data) => { + console.info('====>testRestorePromise101 data : ' + JSON.stringify(data)); + console.info('====>testRestorePromise101 restore success'); + expect(true).assertTrue(); + done() + }).catch((err) => { + console.info('====>testRestorePromise101 fail: ' + JSON.stringify(err)); + expect().assertFail(); + done(); + }); + console.info('------------------testRestorePromise101 end----------------------'); + }) + + /* + * @tc.number testSetImageCallBack101 + * @tc.name Test setImage() to removes a wallpaper of the specified type and restores the default one. + * @tc.desc Function test + * @tc.level 0 + */ + it('testSetImageCallBack101', 0, async function (done) { + console.info('------------------testSetImageCallBack101 start----------------------'); + let wallpaperPath = "/data/storage/el2/base/haps/wp.png"; + wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => { + try{ + if (error) { + console.error(`====>testSetImageCallBack101 failed to setImage because: ` + JSON.stringify(error)); + expect().assertFail(); + done(); + } + console.log(`====>testSetImageCallBack101 success to setImage.`); + expect(true).assertTrue(); + done(); + }catch(err){ + console.info('====>testSetImageCallBack101 catch err : ' + JSON.stringify(err)); + done(); + } + }); + console.info('------------------testSetImageCallBack101 end----------------------'); + }) + + /* + * @tc.number testSetImageCallBack102 + * @tc.name Test setImage() to removes a wallpaper of the specified type and restores the default one. + * @tc.desc Function test + * @tc.level 0 + */ + it('testSetImageCallBack102', 0, async function (done) { + console.info('------------------testSetImageCallBack102 start----------------------'); + let wallpaperPath = "/data/storage/el2/base/haps/wp.png"; + wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_LOCKSCREEN, (error, data) => { + try{ + if (error) { + console.error(`====>testSetImageCallBack102 failed to setImage because: ` + JSON.stringify(error)); + expect().assertFail(); + done(); + } + console.log(`====>testSetImageCallBack102 success to setImage.`); + expect(true).assertTrue(); + done(); + }catch(err){ + console.info('====>testSetImageCallBack102 catch err : ' + JSON.stringify(err)); + done(); + } + }); + console.info('------------------testSetImageCallBack102 end----------------------'); + }) + + /* + * @tc.number testSetImagePromise101 + * @tc.name Test setImage() to removes a wallpaper of the specified type and restores the default one. + * @tc.desc Function test + * @tc.level 0 + */ + it('testSetImagePromise101', 0, async function (done) { + console.info('------------------testSetImagePromise101 start----------------------'); + let wallpaperPath = "/data/storage/el2/base/haps/wp.png"; + await wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => { + console.log(`====>testSetImagePromise101 success to setImage.`); + expect(true).assertTrue(); + done(); + }).catch(err => { + expect().assertFail(); + console.log(`====>testSetImagePromise101 promise fail: ` + JSON.stringify(err)); + }); + console.info('------------------testSetImagePromise101 end----------------------'); + }) + + /* + * @tc.number testSetImagePromise102 + * @tc.name Test setImage() to removes a wallpaper of the specified type and restores the default one. + * @tc.desc Function test + * @tc.level 0 + */ + it('testSetImagePromise102', 0, async function (done) { + console.info('------------------testSetImagePromise102 start----------------------'); + let wallpaperPath = "/data/storage/el2/base/haps/wp.png"; + await wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_LOCKSCREEN).then((data) => { + console.log(`====>testSetImagePromise102 success to setImage.`); + expect(true).assertTrue(); + done(); + }).catch(err => { + console.log(`====>testSetImagePromise102 promise catch: ` + JSON.stringify(err)); + expect().assertFail(); + done() + }); + console.info('------------------testSetImagePromise102 end----------------------'); + }) + }); +}; diff --git a/theme/wallpaper_ets/entry/src/main/resources/base/element/string.json b/theme/wallpaper_ets/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..498677efbde065c36668727190d3613cbf278bfc --- /dev/null +++ b/theme/wallpaper_ets/entry/src/main/resources/base/element/string.json @@ -0,0 +1,20 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "entry_MainAbility" + }, + { + "name": "description_mainability", + "value": "ETS_Empty Ability" + }, + { + "name": "TestAbility_desc", + "value": "description" + }, + { + "name": "TestAbility_label", + "value": "label" + } + ] +} \ No newline at end of file diff --git a/theme/wallpaper_ets/entry/src/main/resources/base/media/icon.png b/theme/wallpaper_ets/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/theme/wallpaper_ets/entry/src/main/resources/base/media/icon.png differ diff --git a/theme/wallpaper_ets/signature/ActsWallpaperEtsAPITest.p7b b/theme/wallpaper_ets/signature/ActsWallpaperEtsAPITest.p7b new file mode 100644 index 0000000000000000000000000000000000000000..dfff8c6c090c3d1245936bef7e701ec778875aa8 Binary files /dev/null and b/theme/wallpaper_ets/signature/ActsWallpaperEtsAPITest.p7b differ diff --git a/time/BUILD.gn b/time/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..cf1161ba135ee9c2e941f4173b24607f6e80446b --- /dev/null +++ b/time/BUILD.gn @@ -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("//build/ohos_var.gni") +group("time") { + testonly = true + 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 diff --git a/time/timeTest/AppScope/app.json b/time/timeTest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..6802f440a9ba4455a2f1b73aac5670dec2216556 --- /dev/null +++ b/time/timeTest/AppScope/app.json @@ -0,0 +1,15 @@ +{ + "app": { + "bundleName": "com.acts.time.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/timeTest/AppScope/resources/base/element/string.json b/time/timeTest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..066e1ff18115359423b0e6d99014273b2408bdee --- /dev/null +++ b/time/timeTest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "ActsTimeAPITest" + } + ] +} diff --git a/time/timeTest/AppScope/resources/base/media/app_icon.png b/time/timeTest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/time/timeTest/AppScope/resources/base/media/app_icon.png differ diff --git a/time/timeTest/BUILD.gn b/time/timeTest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..c6637e0fa8c7d76932895b2bb1d5a6968786c609 --- /dev/null +++ b/time/timeTest/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("ActsTimeAPITest") { + deps = [ + ":time_assets", + ":time_resources", + ] + ets2abc = true + js_build_mode = "debug" + subsystem_name = "time" + part_name = "time_service" + hap_name = "ActsTimeAPITest" + hap_profile = "entry/src/main/module.json" + certificate_profile = "signature/ActsTimeAPITest.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/timeTest/Test.json b/time/timeTest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..0e91ba878d1edb68beda4b9ebcc32158bbd561bd --- /dev/null +++ b/time/timeTest/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "180000", + "bundle-name": "com.acts.time.test", + "module-name": "entry_test", + "shell-timeout": "180000", + "testcase-timeout": 600000 + }, + "kits": [{ + "test-file-name": [ + "ActsTimeAPITest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + }] +} diff --git a/time/timeTest/entry/src/main/ets/Application/MyAbilityStage.ts b/time/timeTest/entry/src/main/ets/Application/MyAbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..63c0efb17ceebd35073960da80893eb3040b0426 --- /dev/null +++ b/time/timeTest/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/timeTest/entry/src/main/ets/MainAbility/MainAbility.ts b/time/timeTest/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..946c1d8885f831d10bf0d4f0835a7dbfd4aa22a3 --- /dev/null +++ b/time/timeTest/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/timeTest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/time/timeTest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..1b7461ea56b950b1cb879f9269f67e4a441f8ef1 --- /dev/null +++ b/time/timeTest/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/timeTest/entry/src/main/ets/pages/index.ets b/time/timeTest/entry/src/main/ets/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..6a23c90b5265a129db7c8cda8bb2e4978f38d386 --- /dev/null +++ b/time/timeTest/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/timeTest/entry/src/main/ets/test/List.test.ets b/time/timeTest/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c7910c1747476814eb7569b1ea9bca8eaa6f323c --- /dev/null +++ b/time/timeTest/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 systemTimeJsunit from './systemTimeTest'; + +export default function testsuite() { + systemTimeJsunit(); +} \ 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 new file mode 100644 index 0000000000000000000000000000000000000000..2983a27d0c4df09f1d5277748ad3ab235fd8edc6 --- /dev/null +++ b/time/timeTest/entry/src/main/ets/test/systemTimeTest.ets @@ -0,0 +1,541 @@ +// @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 systemTimeJsunit() { + describe('systemTimeTest', function () { + console.info('====>---------------systemTimeTest start-----------------------'); + /** + * beforeEach: Prerequisites at the test case level, which are executed before each test case is executed. + */ + + var dates; + var zone; + beforeEach(async function (done) { + let currentTime = new Date().getTime() + dates = currentTime + console.info("====>beforeEach data " + dates); + + systemTime.getTimezone().then( data => { + console.info("====>beforeEach data " + data); + zone = data + done() + }).catch(error => { + console.info("====>beforeEach error " + error); + }); + }); + + /** + * afterEach: Test case-level clearance conditions, which are executed after each test case is executed. + */ + afterEach(async function (done) { + systemTime.setTimezone(zone).then( data => { + console.info("====>afterEach zone " + zone); + done() + }).catch(error => { + console.info("====>afterEach error " + error); + }); + }); + + /** + * @tc.number SUB_systemTime_getCurrentTime_JS_API_0001 + * @tc.name Test systemTime.getCurrentTime + * @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_systemTime_getCurrentTime_JS_API_0001", 0, async function (done) { + console.info("====>----------UB_systemTime_getCurrentTime_JS_API_0001 start----------------"); + systemTime.getCurrentTime(true, (error, data) => { + try { + if (error) { + console.error('====>UB_systemTime_getCurrentTime_JS_API_0001 fail: ' + JSON.stringify(error)); + expect().assertFail(); + done(); + }; + console.info('====>SystemTime.getCurrentTime success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + } catch (error) { + console.error('====>UB_systemTime_getCurrentTime_JS_API_0001 catch error: ' + JSON.stringify(error)); + done(); + } + console.info("====>----------SUB_systemTime_getRealActiveTime_JS_API_0100 end-----------------"); + }); + }); + + /** + * @tc.number SUB_systemTime_getCurrentTime_JS_API_0002 + * @tc.name Test systemTime.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_systemTime_getCurrentTime_JS_API_0002", 0, async function (done) { + console.info("====>-----SUB_systemTime_getCurrentTime_JS_API_0002 start----------------"); + await systemTime.getCurrentTime(false).then((data) => { + console.info('====>SUB_systemTime_getCurrentTime_JS_API_0002 success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + }).catch(err => { + console.error('====>SUB_systemTime_getCurrentTime_JS_API_0002 fail: ' + JSON.stringify(err)); + expect().assertFail() + done(); + }); + console.info("====>-----SUB_systemTime_getCurrentTime_JS_API_0002 end------------"); + }); + + /** + * @tc.number SUB_systemTime_getRealActiveTime_JS_API_0001 + * @tc.name Test systemTime.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_systemTime_getRealActiveTime_JS_API_0001", 0, async function (done) { + console.info("====>----------SUB_systemTime_getRealActiveTime_JS_API_0001 start----------------"); + systemTime.getRealActiveTime(true, (error, data) => { + try { + if (error) { + console.error('====>SUB_systemTime_getRealActiveTime_JS_API_0001 fail: ' + JSON.stringify(error)); + expect().assertFail() + done(); + }; + console.info('====>SUB_systemTime_getRealActiveTime_JS_API_0001 success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + } catch (error) { + console.error('====>SUB_systemTime_getRealActiveTime_JS_API_0001 catch err: ' + JSON.stringify(error)); + done(); + } + console.info("====>----------SUB_systemTime_getRealActiveTime_JS_API_0001 end-----------------"); + }); + }); + + /** + * @tc.number SUB_systemTime_getRealActiveTime_JS_API_0002 + * @tc.name Test systemTime.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_systemTime_getRealActiveTime_JS_API_0002", 0, async function (done) { + console.info("====>-----SUB_systemTime_getRealActiveTime_JS_API_0002 start----------------"); + await systemTime.getRealActiveTime(false).then((data) => { + console.log('SUB_systemTime_getRealActiveTime_JS_API_0002 success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + }).catch(err => { + console.error('====>SUB_systemTime_getRealActiveTime_JS_API_0002 err: ' + JSON.stringify(err)); + expect().assertFail() + done(); + }); + console.info("====>-----SUB_systemTime_getRealActiveTime_JS_API_0002 end------------"); + }); + + /** + * @tc.number SUB_systemTime_getRealTime_JS_API_0001 + * @tc.name Test systemTime.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_systemTime_getRealTime_JS_API_0001", 0, async function (done) { + console.info("====>----------SUB_systemTime_getRealTime_JS_API_0001 start----------------"); + systemTime.getRealTime(true, (error, data) => { + try { + if (error) { + console.error('SUB_systemTime_getRealTime_JS_API_0001 fail: ' + JSON.stringify(error)); + expect().assertFail(); + done(); + }; + console.info('====>SUB_systemTime_getRealTime_JS_API_0001 success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + } catch (error) { + console.error('====>SUB_systemTime_getRealTime_JS_API_0001 catch err: ' + JSON.stringify(error)); + done(); + } + console.info("====>----------SUB_systemTime_getRealTime_JS_API_0001 end-----------------"); + }); + }); + + /** + * @tc.number SUB_systemTime_getRealTime_JS_API_0002 + * @tc.name Test systemTime.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_systemTime_getRealTime_JS_API_0002", 0, async function (done) { + console.info("====>-----SUB_systemTime_getRealTime_JS_API_0002 start----------------"); + await systemTime.getRealTime(false).then((data) => { + console.info('====>SUB_systemTime_getRealTime_JS_API_0002 success data : ' + JSON.stringify(data)); + expect(data != null).assertEqual(true); + done(); + }).catch(error => { + console.error('====>SUB_systemTime_getRealTime_JS_API_0002 err: ' + JSON.stringify(error)); + expect().assertFail(); + done(); + }); + console.info("====>-----SUB_systemTime_getRealTime_JS_API_0002 end------------"); + }); + + /** + * @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/timeTest/entry/src/main/module.json b/time/timeTest/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..6fe24d93bf4c7dc4fe6e1c9aead29de800b99d0f --- /dev/null +++ b/time/timeTest/entry/src/main/module.json @@ -0,0 +1,55 @@ +{ + "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" + ] + } + ] + } + ], + "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/entry/src/main/resources/base/element/color.json b/time/timeTest/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..62a137a61b90c14f109ed8c81d9d551ea0a5888a --- /dev/null +++ b/time/timeTest/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/timeTest/entry/src/main/resources/base/element/string.json b/time/timeTest/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..03bb7d00f7c5bd5750f08b254e645f0d3f960804 --- /dev/null +++ b/time/timeTest/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": "ActsTimeAPITest" + } + ] +} \ No newline at end of file diff --git a/time/timeTest/entry/src/main/resources/base/media/icon.png b/time/timeTest/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/time/timeTest/entry/src/main/resources/base/media/icon.png differ diff --git a/time/timeTest/entry/src/main/resources/base/profile/main_pages.json b/time/timeTest/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..feec276e105eeb8d621c20aaf838f318b0a94150 --- /dev/null +++ b/time/timeTest/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/index" + ] +} diff --git a/time/timeTest/signature/ActsTimeAPITest.p7b b/time/timeTest/signature/ActsTimeAPITest.p7b new file mode 100644 index 0000000000000000000000000000000000000000..e1caf6086a82e9791735e52954e2d5cdc0d40624 Binary files /dev/null and b/time/timeTest/signature/ActsTimeAPITest.p7b differ