diff --git a/inputmethod/BUILD.gn b/inputmethod/BUILD.gn index a9d69edc799a18ec4a64f896fcc18fbff2b6830a..d537ceb7874524aadd86ed47beb585bebfe0e082 100644 --- a/inputmethod/BUILD.gn +++ b/inputmethod/BUILD.gn @@ -16,6 +16,7 @@ group("inputmethod") { testonly = true deps = [ "InputMethodAuthorityTest:ActsInputMethodAuthorityTest", + "InputMethodDrawnControl:ActsInputMethodDrawnControlTest", "InputMethodEngine:ActsInputMethodEngineTest", "InputMethodTest_Stage:ActsImeAbilityTest", "InputMethodTest_ets:ActsInputMethodEtsTest", diff --git a/inputmethod/InputMethodDrawnControl/AppScope/app.json b/inputmethod/InputMethodDrawnControl/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..27e564f0ddc72b40d59b0bb0c9842378fd412b3a --- /dev/null +++ b/inputmethod/InputMethodDrawnControl/AppScope/app.json @@ -0,0 +1,21 @@ +{ + "app":{ + "bundleName":"com.acts.inputmethoddrawncontrol.test", + "vendor":"hw", + "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/InputMethodDrawnControl/AppScope/resources/base/element/string.json b/inputmethod/InputMethodDrawnControl/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..eb1e24bbe87b31c83bd23863a27add57b26370d4 --- /dev/null +++ b/inputmethod/InputMethodDrawnControl/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string":[ + { + "name":"app_name", + "value":"ActsInputMethodDrawnControlTest" + } + ] +} \ No newline at end of file diff --git a/inputmethod/InputMethodDrawnControl/AppScope/resources/base/media/app_icon.png b/inputmethod/InputMethodDrawnControl/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/inputmethod/InputMethodDrawnControl/AppScope/resources/base/media/app_icon.png differ diff --git a/inputmethod/InputMethodDrawnControl/BUILD.gn b/inputmethod/InputMethodDrawnControl/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..9d5b631db80e1cf860166258d106078679dad8fb --- /dev/null +++ b/inputmethod/InputMethodDrawnControl/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("ActsInputMethodDrawnControlTest") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":IMExtAbility_ets_assets", + ":IMExtAbility_resources", + ] + ets2abc = true + certificate_profile = "signature/ActsInputMethodDrawnControlTest.p7b" + hap_name = "ActsInputMethodDrawnControlTest" + 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/InputMethodDrawnControl/Test.json b/inputmethod/InputMethodDrawnControl/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..3e04fc7421f042fe682b3f84859f8d55840368b9 --- /dev/null +++ b/inputmethod/InputMethodDrawnControl/Test.json @@ -0,0 +1,29 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "180000", + "bundle-name": "com.acts.inputmethoddrawncontrol.test", + "module-name": "phone", + "shell-timeout": "600000", + "testcase-timeout": 15000 + }, + "kits": [ + { + "type": "ShellKit", + "run-command": [ + "power-shell wakeup", + "power-shell setmode 602", + "uinput -T -m 300 720 300 360 200", + "uinput -T -m 650 2760 650 1380 200" + ] + }, + { + "test-file-name": [ + "ActsInputMethodDrawnControlTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/inputmethod/InputMethodDrawnControl/entry/src/main/ets/Application/AbilityStage.ts b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..9c01c68aa45f58524d2bb2936deea551c0a96274 --- /dev/null +++ b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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/InputMethodDrawnControl/entry/src/main/ets/MainAbility/MainAbility.ts b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..a27dd9bb672123de68766b9f2c4e5e485efb1e42 --- /dev/null +++ b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023 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/InputMethodDrawnControl/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..b48cf992c955b002abb08443294ada0d603547ab --- /dev/null +++ b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2023 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.inputmethoddrawncontrol.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/InputMethodDrawnControl/entry/src/main/ets/pages/index/index.ets b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/pages/index/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..81f4978d7f1eddd102eb640927066bc59ef1e19e --- /dev/null +++ b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/pages/index/index.ets @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2023 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 { + @State message: string = 'Hello World'; + @State inputValue: string = 'inputMethodEngine1inputMethodEngine2inputMethodEngine3inputMethodEngine' + + 'inputMethodEngine4inputMethodEngine5inputMethodEngine6inputMethodEngine7inputMethodEngine8inputMethodEn' + + 'gine9inputMethodEngine10inputMethodEngine11inputMethodEngine12inputMethodEngine13inputMethodEngine14inputMet' + + 'hodEngine15inputMethodEngine16inputMethodEngine17inputMethodEngine18inputMethodEngine19inputMethodEngine20inputMethodEngine21'; + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + .defaultFocus(true) + TextArea({ text: this.inputValue }) + .onChange((value: string) => { + this.inputValue = value; + }) + 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%') + } + + 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/InputMethodDrawnControl/entry/src/main/ets/pages/second/second.ets b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/pages/second/second.ets new file mode 100644 index 0000000000000000000000000000000000000000..7396425947cd4d9c1016f77855e792bfb6869629 --- /dev/null +++ b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/pages/second/second.ets @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023 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/InputMethodDrawnControl/entry/src/main/ets/test/List.test.ets b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..75096b934ad8596d9ba5c9776e589326883e6164 --- /dev/null +++ b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023 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 inputMethod_attach from './inputMethod_attach.test' +import inputMethod_showTextInput_hideTextInput_detach from './inputMethod_showTextInput_hideTextInput_detach.test' +import inputMethod_updateAttribute from './inputMethod_updateAttribute.test' +import inputMethod_changeSelection from './inputMethod_changeSelection.test' +import inputMethod_updateCursor from './inputMethod_updateCursor.test' +import inputMethod_setCallingWindow from './inputMethod_setCallingWindow.test' + +export default function testsuite() { + inputMethod_attach(); + inputMethod_showTextInput_hideTextInput_detach(); + inputMethod_updateAttribute(); + inputMethod_changeSelection(); + inputMethod_updateCursor(); + inputMethod_setCallingWindow(); +} \ No newline at end of file diff --git a/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/inputMethod_attach.test.ets b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/inputMethod_attach.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..8ae071d64603e65430cf9d0531f456a1e4e21953 --- /dev/null +++ b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/inputMethod_attach.test.ets @@ -0,0 +1,481 @@ +//@ts-nocheck +/* + * Copyright (c) 2023 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 inputMethod from '@ohos.inputmethod'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' +import * as env from './lib/Const'; + +export default function inputMethodTest() { + describe('inputMethod_attach', function () { + function expectTrue(data) { + try { + expect(data).assertTrue(); + }catch (err){ + console.info('assertion failure'); + } + }; + function expectContain(a,b) { + try { + expect(a).assertContain(b); + }catch (err){ + console.info('assertion failure'); + } + }; + function expectFalse() { + try { + expect().assertFail(); + }catch (err){ + console.info('assertion failure'); + } + }; + let st = null as any; + const sleep = function (timeout) { + return new Promise(resolve => { + const st = setTimeout(() => { + resolve(null); + }, timeout); + }); + }; + afterEach(async function(){ + clearTimeout(st); + }); + + /** + * @tc.number SUB_Misc_inputMethod_attach_Async_0100 + * @tc.name Call the attach interface in Async mode. Optional input parameter showkeyboard=true + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_attach_Async_0100',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_attach_Async_0100'; + const ATTRIBUTE:any = {inputAttribute:{textInputType:0,enterKeyType:0}} + let CallBack:any = (error,data)=>{ + if (error) { + console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + } + }; + try{ + inputMethod.getController().attach(true,ATTRIBUTE,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_attach_Async_0200 + * @tc.name Call the attach interface in Async mode. Optional input parameter showkeyboard=false + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_attach_Async_0200',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_attach_Async_0200'; + const ATTRIBUTE:any = {inputAttribute:{textInputType:0,enterKeyType:0}} + let CallBack:any = (error,data)=>{ + if (error) { + console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + } + }; + try{ + inputMethod.getController().attach(false,ATTRIBUTE,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_attach_Async_0300 + * @tc.name Call the attach interface in Async mode. Optional input parameter showkeyboard=0 + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_attach_Async_0300',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_attach_Async_0300'; + const SHOW_KEYBOARD:any = 0; + const ATTRIBUTE:any = {inputAttribute:{textInputType:0,enterKeyType:0}} + let CallBack:any = (error,data)=>{ + if (error) { + console.info(`${CASE_NAME} execution fail,expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + } + }; + try{ + inputMethod.getController().attach(SHOW_KEYBOARD,ATTRIBUTE,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_attach_Async_0400 + * @tc.name Call the attach interface in Async mode. Optional input parameter showkeyboard=1 + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_attach_Async_0400',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_attach_Async_0400'; + const SHOW_KEYBOARD:any = 1; + const ATTRIBUTE:any = {inputAttribute:{textInputType:0,enterKeyType:0}} + let CallBack:any = (error,data)=>{ + if (error) { + console.info(`${CASE_NAME} execution fail,expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + } + }; + try{ + inputMethod.getController().attach(SHOW_KEYBOARD,ATTRIBUTE,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_attach_Async_0500 + * @tc.name Call the attach interface in Async mode. Optional input parameter showkeyboard='aa' + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_attach_Async_0500',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_attach_Async_0500'; + const SHOW_KEYBOARD:any = 'aa'; + const ATTRIBUTE:any = {inputAttribute:{textInputType:0,enterKeyType:0}} + let CallBack:any = (error,data)=>{ + if (error) { + console.info(`${CASE_NAME} execution fail,expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + } + }; + try{ + inputMethod.getController().attach(SHOW_KEYBOARD,ATTRIBUTE,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_attach_Async_0600 + * @tc.name Call the attach interface in Async mode. Optional input parameters showkeyboard=true, attribute={} + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_attach_Async_0600',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_attach_Async_0600'; + const ATTRIBUTE:any = {}; + let CallBack:any = (error,data)=>{ + if (error) { + console.info(`${CASE_NAME} execution fail,expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + } + }; + try{ + inputMethod.getController().attach(true,ATTRIBUTE,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_attach_Async_0700 + * @tc.name Call the attach interface in Async mode. Optional input parameters showkeyboard=true, attribute='aa' + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_attach_Async_0700',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_attach_Async_0700'; + const ATTRIBUTE:any = 'aa'; + let CallBack:any = (error,data)=>{ + if (error) { + console.info(`${CASE_NAME} execution fail,expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + } + }; + try{ + inputMethod.getController().attach(true,ATTRIBUTE,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_attach_Async_1000 + * @tc.name Call the attach interface in Async mode and pass in an invalid input parameter + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_attach_Async_1000',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_attach_Async_1000'; + const ATTRIBUTE:any = {inputAttribute:{textInputType:0,enterKeyType:0}} + let CallBack:any = (error,data)=>{ + if (error) { + console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + } + }; + try{ + inputMethod.getController().attach(true,ATTRIBUTE,CallBack,env.INVALID_TYPE_STRING_A); + }catch(error){ + console.info(`${CASE_NAME} catch error,error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_attach_Promise_0100 + * @tc.name Call the attach interface in Promise mode. Optional input parameter showkeyboard=true + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_attach_Promise_0100',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_attach_Promise_0100'; + const ATTRIBUTE:any = {inputAttribute:{textInputType:0,enterKeyType:0}} + try{ + let data = await inputMethod.getController().attach(true,ATTRIBUTE); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_attach_Promise_0200 + * @tc.name Call the attach interface in Promise mode. Optional input parameter showkeyboard=false + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_attach_Promise_0200',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_attach_Promise_0200'; + const ATTRIBUTE:any = {inputAttribute:{textInputType:0,enterKeyType:0}} + try{ + let data = await inputMethod.getController().attach(false,ATTRIBUTE); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + + /** + * @tc.number SUB_Misc_inputMethod_attach_Promise_0300 + * @tc.name Call the attach interface in Promise mode. Optional input parameter showkeyboard=0 + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_attach_Promise_0300',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_attach_Promise_0300'; + const ATTRIBUTE:any = {inputAttribute:{textInputType:0,enterKeyType:0}} + const SHOW_KEYBOARD:any = 0; + try{ + let data = await inputMethod.getController().attach(SHOW_KEYBOARD,ATTRIBUTE); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_attach_Promise_0400 + * @tc.name Call the attach interface in Promise mode. Optional input parameter showkeyboard=1 + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_attach_Promise_0400',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_attach_Promise_0400'; + const ATTRIBUTE:any = {inputAttribute:{textInputType:0,enterKeyType:0}} + const SHOW_KEYBOARD:any = 1; + try{ + let data = await inputMethod.getController().attach(SHOW_KEYBOARD,ATTRIBUTE); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_attach_Promise_0500 + * @tc.name Call the attach interface in Promise mode. Optional input parameter showkeyboard='aa' + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_attach_Promise_0500',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_attach_Promise_0500'; + const ATTRIBUTE:any = {inputAttribute:{textInputType:0,enterKeyType:0}} + const SHOW_KEYBOARD:any = 'aa'; + try{ + let data = await inputMethod.getController().attach(SHOW_KEYBOARD,ATTRIBUTE); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_attach_Promise_0600 + * @tc.name Call the attach interface in Promise mode. Optional input parameters showkeyboard=true, attribute={} + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_attach_Promise_0600',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_attach_Promise_0600'; + const ATTRIBUTE:any = {}; + try{ + let data = await inputMethod.getController().attach(true,ATTRIBUTE); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_attach_Promise_0700 + * @tc.name Call the attach interface in Promise mode. Optional input parameters showkeyboard=true, attribute='aa' + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_attach_Promise_0700',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_attach_Promise_0700'; + const ATTRIBUTE:any = 'aa'; + try{ + let data = await inputMethod.getController().attach(true,ATTRIBUTE); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_attach_Promise_1000 + * @tc.name Call the attach interface in Promise mode and pass in an invalid input parameter + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_attach_Promise_1000',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_attach_Promise_1000'; + const ATTRIBUTE:any = {inputAttribute:{textInputType:0,enterKeyType:0}} + try{ + let data = await inputMethod.getController().attach(true,ATTRIBUTE,env.INVALID_TYPE_STRING_A); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + }) +} \ No newline at end of file diff --git a/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/inputMethod_changeSelection.test.ets b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/inputMethod_changeSelection.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..69b0581ea7a4a7361dbb229e11abb501a6271f16 --- /dev/null +++ b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/inputMethod_changeSelection.test.ets @@ -0,0 +1,819 @@ +//@ts-nocheck +/* + * Copyright (c) 2023 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 inputMethod from '@ohos.inputmethod'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' +import * as env from './lib/Const'; + +export default function inputMethodTest() { + describe('inputMethod_changeSelection', function () { + function expectTrue(data) { + try { + expect(data).assertTrue(); + }catch (err){ + console.info('assertion failure'); + } + }; + function expectContain(a,b) { + try { + expect(a).assertContain(b); + }catch (err){ + console.info('assertion failure'); + } + }; + function expectFalse() { + try { + expect().assertFail(); + }catch (err){ + console.info('assertion failure'); + } + }; + let st = null as any; + const sleep = function (timeout) { + return new Promise(resolve => { + const st = setTimeout(() => { + resolve(null); + }, timeout); + }); + }; + beforeEach( + async function (){ + try{ + let data = await inputMethod.getController().attach(true,{inputAttribute:{textInputType:1,enterKeyType:2}}); + console.info(`attach inputMethod success, data: ${JSON.stringify(data)}`); + }catch(error){ + console.info(`attach inputMethod fail, error: [${error.code}, ${error.message}]`); + }; + } + ); + afterEach( + async function (){ + try{ + await inputMethod.getController().detach(); + console.info(`clsoe inputMethod success}`); + }catch(error){ + console.info(`clsoe inputMethod fial, error: [${error.code}, ${error.message}]`); + }; + clearTimeout(st); + } + ); + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Async_0100 + * @tc.name Call the changeSelection interface in Async mode, enter the parameter text='Input method keyboard + * test hey hey', start=0, end=5 + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Async_0100',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Async_0100'; + const TEXT = '输入法键盘测试嘿嘿'; + const START = 0; + const END = 5; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + } + }; + try{ + inputMethod.getController().changeSelection(TEXT,START,END,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Async_0200 + * @tc.name Call the changeSelection interface in Async mode, enter the parameter text='Input method keyboard + * test hey hey', start=0, end=10 + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Async_0200',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Async_0200'; + const TEXT = '输入法键盘测试嘿嘿'; + const START = 0; + const END = 10; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + } + }; + try{ + inputMethod.getController().changeSelection(TEXT,START,END,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, expect error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Async_0300 + * @tc.name Call the changeSelection interface in Async mode, enter the parameter text='Input method keyboard + * test hey hey', start=- 1, end=5 + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Async_0300',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Async_0300'; + const TEXT = '输入法键盘测试嘿嘿'; + const START = -1; + const END = 5; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + } + }; + try{ + inputMethod.getController().changeSelection(TEXT,START,END,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, expect error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Async_0400 + * @tc.name Call the changeSelection interface in Async mode, enter the parameter text='Input method keyboard + * test hehe', start=8, end=2 + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Async_0400',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Async_0400'; + const TEXT = '输入法键盘测试嘿嘿'; + const START = 8; + const END = 2; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + } + }; + try{ + inputMethod.getController().changeSelection(TEXT,START,END,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Async_0500 + * @tc.name Async mode calls changeSelection interface, input parameter text=123 + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Async_0500',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Async_0500'; + const START = 0; + const END = 5; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + } + }; + try{ + inputMethod.getController().changeSelection(env.INVALID_TYPE_NUMBER_123,START,END,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Async_0600 + * @tc.name Async mode calls changeSelection interface, input parameter text='' + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Async_0600',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Async_0600'; + const START = 0; + const END = 5; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + } + }; + try{ + inputMethod.getController().changeSelection(env.INVALID_STRING_NULL,START,END,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, expect error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Async_0700 + * @tc.name Async mode calls changeSelection interface, input parameter start='0' + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Async_0700',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Async_0700'; + const TEXT = '输入法键盘测试嘿嘿'; + const START:any = '0'; + const END = 5; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + } + }; + try{ + inputMethod.getController().changeSelection(TEXT,START,END,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Async_0800 + * @tc.name Async mode calls changeSelection interface, input parameter end='5' + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Async_0800',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Async_0800'; + const TEXT = '输入法键盘测试嘿嘿'; + const START = 0; + const END:any = '5'; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + } + }; + try{ + inputMethod.getController().changeSelection(TEXT,START,END,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Async_1100 + * @tc.name The input method keyboard is not bound, and the changeSelection interface is called in Async mode + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Async_1100',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Async_1100'; + const TEXT = '输入法键盘测试嘿嘿'; + const START = 0; + const END:any = 5; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_METHOD_CLIENT_DETACHED); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + } + }; + try{ + let data = await inputMethod.getController().detach(); + console.info(`${CASE_NAME} clsoe inputMethod success, data: ${JSON.stringify(data)}`); + }catch(error){ + console.info(`${CASE_NAME} clsoe inputMethod fial, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + try{ + inputMethod.getController().changeSelection(TEXT,START,END,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_METHOD_CLIENT_DETACHED); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Async_1200 + * @tc.name Async mode calls the changeSelection interface, and an invalid input parameter is passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Async_1200',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Async_1200'; + const TEXT = '输入法键盘测试嘿嘿'; + const START = 0; + const END:any = 5; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + } + }; + try{ + inputMethod.getController().changeSelection(TEXT,START,END,CallBack,env.INVALID_TYPE_STRING_A); + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Async_1300 + * @tc.name Async mode calls changeSelection interface. Missing parameter text must be passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Async_1300',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Async_1300'; + const START:any = 0; + const END:any = 5; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + } + }; + try{ + inputMethod.getController().changeSelection(START,END,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Async_1400 + * @tc.name Async mode calls the changeSelection interface. If it is missing, the parameter start must be passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Async_1400',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Async_1400'; + const TEXT = '输入法键盘测试嘿嘿'; + const END:any = 5; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + } + }; + try{ + inputMethod.getController().changeSelection(TEXT,END,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Async_1500 + * @tc.name Async mode calls the changeSelection interface, and the missing parameter must be passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Async_1500',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Async_1500'; + const TEXT = '输入法键盘测试嘿嘿'; + const START = 0; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + } + }; + try{ + inputMethod.getController().changeSelection(TEXT,START,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Promise_0100 + * @tc.name Call changeSelection interface in Promise mode, enter the parameter text='Input method keyboard + * test hey hey', start=0, end=5 + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Promise_0100',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Promise_0100'; + const TEXT = '输入法键盘测试嘿嘿'; + const START = 0; + const END = 5; + try{ + let data = await inputMethod.getController().changeSelection(TEXT,START,END); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + } + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Promise_0200 + * @tc.name Call changeSelection interface in Promise mode, enter the parameter text='Input method keyboard + * test hey hey', start=0, end=10 + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Promise_0200',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Promise_0200'; + const TEXT = '输入法键盘测试嘿嘿'; + const START = 0; + const END = 10; + try{ + let data = await inputMethod.getController().changeSelection(TEXT,START,END); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + } + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Promise_0300 + * @tc.name Call changeSelection interface in Promise mode, enter text='Input method keyboard test hey hey', + * start=- 1, end=5 + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Promise_0300',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Promise_0300'; + const TEXT = '输入法键盘测试嘿嘿'; + const START = -1; + const END = 5; + try{ + let data = await inputMethod.getController().changeSelection(TEXT,START,END); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + } + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Promise_0400 + * @tc.name Call changeSelection interface in Promise mode, enter the parameter text='Input method keyboard + * test hey hey', start=8, end=2 + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Promise_0400',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Promise_0400'; + const TEXT = '输入法键盘测试嘿嘿'; + const START = 8; + const END = 2; + try{ + let data = await inputMethod.getController().changeSelection(TEXT,START,END); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + } + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Promise_0500 + * @tc.name Call changeSelection interface in Promise mode, input parameter text=123 + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Promise_0500',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Promise_0500'; + const START = 0; + const END = 5; + try{ + let data = await inputMethod.getController().changeSelection(env.INVALID_TYPE_NUMBER_123,START,END); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + } + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Promise_0600 + * @tc.name Promise mode calls changeSelection interface, input parameter text='' + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Promise_0600',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Promise_0600'; + const START = 0; + const END = 5; + try{ + let data = await inputMethod.getController().changeSelection(env.INVALID_STRING_NULL,START,END); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + } + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Promise_0700 + * @tc.name Promise mode calls changeSelection interface, input parameter start='0' + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Promise_0700',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Promise_0700'; + const TEXT = '输入法键盘测试嘿嘿'; + const START:any = '0'; + const END = 5; + try{ + let data = await inputMethod.getController().changeSelection(TEXT,START,END); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + } + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Promise_0800 + * @tc.name Call changeSelection interface in Promise mode, input parameter end='5' + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Promise_0800',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Promise_0800'; + const TEXT = '输入法键盘测试嘿嘿'; + const START = 0; + const END:any = '5'; + try{ + let data = await inputMethod.getController().changeSelection(TEXT,START,END); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + } + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Promise_1100 + * @tc.name Do not bind the input method keyboard, and call the changeSelection interface in Promise mode + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Promise_1100',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Promise_1100'; + const TEXT = '输入法键盘测试嘿嘿'; + const START = 0; + const END:any = 5; + try{ + let data = await inputMethod.getController().detach(); + console.info(`${CASE_NAME} clsoe inputMethod success, data: ${JSON.stringify(data)}`); + }catch(error){ + console.info(`${CASE_NAME} clsoe inputMethod fial, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + try{ + let data = await inputMethod.getController().changeSelection(TEXT,START,END); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_METHOD_CLIENT_DETACHED); + done(); + return; + } + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Promise_1200 + * @tc.name The Promise method calls the changeSelection interface, and an invalid input parameter is passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Promise_1200',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Promise_1200'; + const TEXT = '输入法键盘测试嘿嘿'; + const START = 0; + const END:any = 5; + try{ + let data = await inputMethod.getController().changeSelection(TEXT,START,END,env.INVALID_TYPE_STRING_A); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + } + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Promise_1300 + * @tc.name The promise method calls the changeSelection interface, and the missing parameter text must be + * passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Promise_1300',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Promise_1300'; + const START = 0; + const END:any = 5; + try{ + let data = await inputMethod.getController().changeSelection(START,END); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + } + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Promise_1400 + * @tc.name The promise method calls the changeSelection interface. If it is missing, the parameter start must + * be passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Promise_1400',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Promise_1400'; + const TEXT = '输入法键盘测试嘿嘿'; + const END:any = 5; + try{ + let data = await inputMethod.getController().changeSelection(TEXT,END); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + } + }); + + /** + * @tc.number SUB_Misc_inputMethod_changeSelection_Promise_1500 + * @tc.name The promise method calls the changeSelection interface, and the missing parameter must be passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_changeSelection_Promise_1500',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_changeSelection_Promise_1500'; + const TEXT = '输入法键盘测试嘿嘿'; + const START:any = 0; + try{ + let data = await inputMethod.getController().changeSelection(TEXT,START); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + } + }); + + }) +} \ No newline at end of file diff --git a/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/inputMethod_setCallingWindow.test.ets b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/inputMethod_setCallingWindow.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..07b900d8d28b32931ec93ae6f670ae5a3e41da56 --- /dev/null +++ b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/inputMethod_setCallingWindow.test.ets @@ -0,0 +1,407 @@ +//@ts-nocheck +/* + * Copyright (c) 2023 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 inputMethod from '@ohos.inputmethod'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' +import * as env from './lib/Const'; + +export default function inputMethodTest() { + describe('inputMethod_setCallingWindow', function () { + function expectTrue(data) { + try { + expect(data).assertTrue(); + }catch (err){ + console.info('assertion failure'); + } + }; + function expectContain(a,b) { + try { + expect(a).assertContain(b); + }catch (err){ + console.info('assertion failure'); + } + }; + function expectFalse() { + try { + expect().assertFail(); + }catch (err){ + console.info('assertion failure'); + } + }; + let st = null as any; + const sleep = function (timeout) { + return new Promise(resolve => { + const st = setTimeout(() => { + resolve(null); + }, timeout); + }); + }; + beforeEach( + async function (){ + try{ + let data = await inputMethod.getController().attach(true,{inputAttribute:{textInputType:1,enterKeyType:2}}); + console.info(`attach inputMethod success, data: ${JSON.stringify(data)}`); + }catch(error){ + console.info(`attach inputMethod fail, error: [${error.code}, ${error.message}]`); + }; + } + ); + afterEach( + async function (){ + try{ + await inputMethod.getController().detach(); + console.info(`clsoe inputMethod success}`); + }catch(error){ + console.info(`clsoe inputMethod fial, error: [${error.code}, ${error.message}]`); + }; + clearTimeout(st); + } + ); + + + /** + * @tc.number SUB_Misc_inputMethod_setCallingWindow_Async_0100 + * @tc.name When calling the setCallingWindow interface in Async mode, the parameter windowId=5 must be passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_setCallingWindow_Async_0100',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Async_0100'; + const WINDOW_ID:any = 5; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + } + }; + try{ + inputMethod.getController().setCallingWindow(WINDOW_ID,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_setCallingWindow_Async_0200 + * @tc.name When calling the setCallingWindow interface in Async mode, the parameter windowId=0 must be passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_setCallingWindow_Async_0200',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Async_0200'; + const WINDOW_ID:any = 0; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); + expectFalse(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + } + }; + try{ + inputMethod.getController().setCallingWindow(WINDOW_ID,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_setCallingWindow_Async_0300 + * @tc.name When calling the setCallingWindow interface in Async mode, the parameter windowId='5' must be + * passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_setCallingWindow_Async_0300',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Async_0300'; + const WINDOW_ID:any = '5'; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + } + }; + try{ + inputMethod.getController().setCallingWindow(WINDOW_ID,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_setCallingWindow_Async_0600 + * @tc.name The input method keyboard is not bound, and the setCallingWindow interface is called in Async mode + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_setCallingWindow_Async_0600',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Async_0600'; + const WINDOW_ID:any = 5; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_METHOD_CLIENT_DETACHED); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + } + }; + try{ + let data = await inputMethod.getController().detach(); + console.info(`${CASE_NAME} clsoe inputMethod success, data: ${JSON.stringify(data)}`); + }catch(error){ + console.info(`${CASE_NAME} clsoe inputMethod fial, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + try{ + inputMethod.getController().setCallingWindow(WINDOW_ID,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_METHOD_CLIENT_DETACHED); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_setCallingWindow_Async_0700 + * @tc.name Async mode calls the setCallingWindow interface, and an invalid input parameter is passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_setCallingWindow_Async_0700',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Async_0700'; + const WINDOW_ID:any = 5; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + } + }; + try{ + inputMethod.getController().setCallingWindow(WINDOW_ID,CallBack,env.INVALID_TYPE_STRING_A); + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_setCallingWindow_Async_0800 + * @tc.name Async method calls the setCallingWindow interface. Missing parameter windowId must be passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_setCallingWindow_Async_0800',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Async_0800'; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + } + }; + try{ + inputMethod.getController().setCallingWindow(CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_setCallingWindow_Promise_0100 + * @tc.name When calling the setCallingWindow interface in Promise mode, the parameter + * windowId=5 must be passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_setCallingWindow_Promise_0100',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Promise_0100'; + const WINDOW_ID:any = 5; + try{ + let data = await inputMethod.getController().setCallingWindow(WINDOW_ID); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_setCallingWindow_Promise_0200 + * @tc.name When calling the setCallingWindow interface in Promise mode, the parameter windowId=0 must be + * passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_setCallingWindow_Promise_0200',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Promise_0200'; + const WINDOW_ID:any = 0; + try{ + let data = await inputMethod.getController().setCallingWindow(WINDOW_ID); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_setCallingWindow_Promise_0300 + * @tc.name When calling the setCallingWindow interface in Promise mode, the parameter windowId='5' must be + * passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_setCallingWindow_Promise_0300',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Promise_0300'; + const WINDOW_ID:any = '5'; + try{ + let data = await inputMethod.getController().setCallingWindow(WINDOW_ID); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_setCallingWindow_Promise_0600 + * @tc.name The input method keyboard is not bound, and the setCallingWindow interface is called in Promise mode + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_setCallingWindow_Promise_0600',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Promise_0600'; + const WINDOW_ID:any = 5; + try{ + let data = await inputMethod.getController().detach(); + console.info(`${CASE_NAME} clsoe inputMethod success, data: ${JSON.stringify(data)}`); + }catch(error){ + console.info(`${CASE_NAME} clsoe inputMethod fial, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + try{ + let data = await inputMethod.getController().setCallingWindow(WINDOW_ID); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_METHOD_CLIENT_DETACHED); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_setCallingWindow_Promise_0700 + * @tc.name Call setCallingWindow interface in Promise mode, and pass in an invalid input parameter + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_setCallingWindow_Promise_0700',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Promise_0700'; + const WINDOW_ID:any = 5; + try{ + let data = await inputMethod.getController().setCallingWindow(WINDOW_ID,env.INVALID_TYPE_STRING_A); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_setCallingWindow_Promise_0800 + * @tc.name The setCallingWindow interface is called in Promise mode, and the parameter windowId must be + * passed in if it is missing + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_setCallingWindow_Promise_0800',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Promise_0800'; + try{ + let data = await inputMethod.getController().setCallingWindow(); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + }) +} \ No newline at end of file diff --git a/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/inputMethod_showTextInput_hideTextInput_detach.test.ets b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/inputMethod_showTextInput_hideTextInput_detach.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..35fd74fa469349bc7eca1c6e026ee9a810be1c17 --- /dev/null +++ b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/inputMethod_showTextInput_hideTextInput_detach.test.ets @@ -0,0 +1,514 @@ +//@ts-nocheck +/* + * Copyright (c) 2023 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 inputMethod from '@ohos.inputmethod'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' +import * as env from './lib/Const'; + +export default function inputMethodTest() { + describe('inputMethod_showTextInput_hideTextInput_detach', function () { + function expectTrue(data) { + try { + expect(data).assertTrue(); + }catch (err){ + console.info('assertion failure'); + } + }; + function expectContain(a,b) { + try { + expect(a).assertContain(b); + }catch (err){ + console.info('assertion failure'); + } + }; + function expectFalse() { + try { + expect().assertFail(); + }catch (err){ + console.info('assertion failure'); + } + }; + let st = null as any; + const sleep = function (timeout) { + return new Promise(resolve => { + const st = setTimeout(() => { + resolve(null); + }, timeout); + }); + }; + beforeEach( + async function (){ + try{ + let data = await inputMethod.getController().attach(true,{inputAttribute:{textInputType:1,enterKeyType:2}}); + console.info(`attach inputMethod success, data: ${JSON.stringify(data)}`); + }catch(error){ + console.info(`attach inputMethod fail, error: [${error.code}, ${error.message}]`); + }; + } + ); + afterEach( + async function (){ + try{ + await inputMethod.getController().detach(); + console.info(`clsoe inputMethod success}`); + }catch(error){ + console.info(`clsoe inputMethod fial, error: [${error.code}, ${error.message}]`); + }; + clearTimeout(st); + } + ); + + /** + * @tc.number SUB_Misc_inputMethod_showTextInput_Async_0100 + * @tc.name Async mode calls the showTextInput interface without input parameters + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_showTextInput_Async_0100',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_showTextInput_Async_0100'; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + } + }; + try{ + inputMethod.getController().showTextInput(CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_showTextInput_Async_0400 + * @tc.name Do not bind the input method keyboard, and call the showTextInput interface in Async mode + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_showTextInput_Async_0400',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_showTextInput_Async_0400'; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_METHOD_CLIENT_DETACHED); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + } + }; + try{ + let data = await inputMethod.getController().detach(); + console.info(`${CASE_NAME} clsoe inputMethod success, data: ${JSON.stringify(data)}`); + }catch(error){ + console.info(`${CASE_NAME} clsoe inputMethod fial, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + try{ + inputMethod.getController().showTextInput(CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_METHOD_CLIENT_DETACHED); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_showTextInput_Async_0500 + * @tc.name Async method calls the showTextInput interface, and an invalid input parameter is passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_showTextInput_Async_0500',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_showTextInput_Async_0500'; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + } + }; + try{ + inputMethod.getController().showTextInput(CallBack,env.INVALID_TYPE_STRING_A); + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_showTextInput_Promise_0100 + * @tc.name Promise mode calls the showTextInput interface without input parameters + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_showTextInput_Promise_0100',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_showTextInput_Promise_0100'; + try{ + let data = await inputMethod.getController().showTextInput(); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_showTextInput_Promise_0400 + * @tc.name Do not bind the input method keyboard, and call the showTextInput interface in Promise mode + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_showTextInput_Promise_0400',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_showTextInput_Promise_0400'; + try{ + let data = await inputMethod.getController().detach(); + console.info(`${CASE_NAME} clsoe inputMethod success, data: ${JSON.stringify(data)}`); + }catch(error){ + console.info(`${CASE_NAME} clsoe inputMethod fial, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + try{ + await inputMethod.getController().showTextInput(); + console.info(`${CASE_NAME} execution success`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_METHOD_CLIENT_DETACHED); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_showTextInput_Promise_0500 + * @tc.name Call the showTextInput interface in Promise mode, and pass in an invalid input parameter + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_showTextInput_Promise_0500',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_showTextInput_Promise_0500'; + try{ + await inputMethod.getController().showTextInput(env.INVALID_TYPE_STRING_A); + console.info(`${CASE_NAME} execution success`); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_hideTextInput_Async_0100 + * @tc.name Async mode calls the hideTextInput interface without input parameters + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_hideTextInput_Async_0100',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_hideTextInput_Async_0100'; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + } + }; + try{ + inputMethod.getController().hideTextInput(CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_hideTextInput_Async_0400 + * @tc.name The input method keyboard is not bound, and the hideTextInput interface is called in Async mode + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_hideTextInput_Async_0400',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_hideTextInput_Async_0400'; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_METHOD_CLIENT_DETACHED); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + } + }; + try{ + let data = await inputMethod.getController().detach(); + console.info(`${CASE_NAME} clsoe inputMethod success, data: ${JSON.stringify(data)}`); + }catch(error){ + console.info(`${CASE_NAME} clsoe inputMethod fial, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + try{ + inputMethod.getController().hideTextInput(CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_METHOD_CLIENT_DETACHED); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_hideTextInput_Async_0500 + * @tc.name Call the hideTextInput interface in Async mode, and pass in an invalid input parameter + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_hideTextInput_Async_0500',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_hideTextInput_Async_0500'; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + } + }; + try{ + inputMethod.getController().hideTextInput(CallBack,env.INVALID_TYPE_STRING_A); + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_hideTextInput_Promise_0100 + * @tc.name Promise mode calls the hideTextInput interface without input parameters + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_hideTextInput_Promise_0100',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_hideTextInput_Promise_0100'; + try{ + await inputMethod.getController().hideTextInput(); + }catch(error){ + console.info(`${CASE_NAME} catch error, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_METHOD_CLIENT_DETACHED); + done(); + return; + }; + try{ + let data = await inputMethod.getController().hideTextInput(); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_hideTextInput_Promise_0400 + * @tc.name The input method keyboard is not bound, and the hideTextInput interface is called in Promise mode + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_hideTextInput_Promise_0400',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_hideTextInput_Promise_0400'; + try{ + let data = await inputMethod.getController().detach(); + console.info(`${CASE_NAME} clsoe inputMethod success, data: ${JSON.stringify(data)}`); + }catch(error){ + console.info(`${CASE_NAME} clsoe inputMethod fial, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + try{ + await inputMethod.getController().hideTextInput(); + console.info(`${CASE_NAME} execution success`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_METHOD_CLIENT_DETACHED); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_hideTextInput_Promise_0500 + * @tc.name Call the hideTextInput interface in Promise mode, and pass in an invalid input parameter + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_hideTextInput_Promise_0500',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_hideTextInput_Promise_0500'; + try{ + await inputMethod.getController().hideTextInput(env.INVALID_TYPE_STRING_A); + console.info(`${CASE_NAME} execution success`); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_detach_Async_0100 + * @tc.name Async mode calls the detach interface without input parameters + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_detach_Async_0100',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_detach_Async_0100'; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + } + }; + try{ + inputMethod.getController().detach(CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_detach_Async_0400 + * @tc.name Call the detach interface in Async mode and pass in an invalid input parameter + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_detach_Async_0400',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_detach_Async_0400'; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + } + }; + try{ + inputMethod.getController().detach(CallBack,env.INVALID_TYPE_STRING_A); + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_detach_Promise_0100 + * @tc.name Promise mode calls the detach interface without input parameters + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_detach_Promise_0100',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_detach_Promise_0100'; + try{ + let data = await inputMethod.getController().detach(); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_detach_Promise_0400 + * @tc.name Call the detach interface in Promise mode, and pass in an invalid input parameter + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_detach_Promise_0400',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_detach_Promise_0400'; + try{ + await inputMethod.getController().detach(env.INVALID_TYPE_STRING_A); + console.info(`${CASE_NAME} execution success`); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + }) +} \ No newline at end of file diff --git a/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/inputMethod_updateAttribute.test.ets b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/inputMethod_updateAttribute.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..db04970853ba6c6f4d03a62153ba0f3b84bda91a --- /dev/null +++ b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/inputMethod_updateAttribute.test.ets @@ -0,0 +1,340 @@ +//@ts-nocheck +/* + * Copyright (c) 2023 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 inputMethod from '@ohos.inputmethod'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' +import * as env from './lib/Const'; + +export default function inputMethodTest() { + describe('inputMethod_updateAttribute', function () { + function expectTrue(data) { + try { + expect(data).assertTrue(); + }catch (err){ + console.info('assertion failure'); + } + }; + function expectContain(a,b) { + try { + expect(a).assertContain(b); + }catch (err){ + console.info('assertion failure'); + } + }; + function expectFalse() { + try { + expect().assertFail(); + }catch (err){ + console.info('assertion failure'); + } + }; + let st = null as any; + const sleep = function (timeout) { + return new Promise(resolve => { + const st = setTimeout(() => { + resolve(null); + }, timeout); + }); + }; + beforeEach( + async function (){ + try{ + let data = await inputMethod.getController().attach(true,{inputAttribute:{textInputType:1,enterKeyType:2}}); + console.info(`attach inputMethod success, data: ${JSON.stringify(data)}`); + }catch(error){ + console.info(`attach inputMethod fail, error: [${error.code}, ${error.message}]`); + }; + } + ); + afterEach( + async function (){ + try{ + await inputMethod.getController().detach(); + console.info(`clsoe inputMethod success}`); + }catch(error){ + console.info(`clsoe inputMethod fial, error: [${error.code}, ${error.message}]`); + }; + clearTimeout(st); + } + ); + + + /** + * @tc.number SUB_Misc_inputMethod_updateAttribute_Async_0100 + * @tc.name When calling the updateAttribute interface in Async mode, the parameter attribute= + * {textInputType: 0, enterKeyType: 0} must be passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_updateAttribute_Async_0100',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_updateAttribute_Async_0100'; + const ATTRIBUTE:any = {textInputType: 0, enterKeyType: 0}; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + } + }; + try{ + inputMethod.getController().updateAttribute(ATTRIBUTE,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_updateAttribute_Async_0200 + * @tc.name When calling the updateAttribute interface in Async mode, the parameter attribute={} must be + * passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_updateAttribute_Async_0200',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_updateAttribute_Async_0200'; + const ATTRIBUTE:any = {}; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + } + }; + try{ + inputMethod.getController().updateAttribute(ATTRIBUTE,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_updateAttribute_Async_0300 + * @tc.name When calling the updateAttribute interface in Async mode, the parameter attribute='aa' must be + * passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_updateAttribute_Async_0300',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_updateAttribute_Async_0300'; + const ATTRIBUTE:any = 'aa'; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + } + }; + try{ + inputMethod.getController().updateAttribute(ATTRIBUTE,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_updateAttribute_Async_0700 + * @tc.name Async mode calls the updateAttribute interface and passes in an invalid input parameter + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_updateAttribute_Async_0700',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_updateAttribute_Async_0700'; + const ATTRIBUTE:any = {textInputType: 0, enterKeyType: 0}; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + } + }; + try{ + inputMethod.getController().updateAttribute(ATTRIBUTE,CallBack,env.INVALID_TYPE_STRING_A); + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_updateAttribute_Async_0800 + * @tc.name Async method calls the updateAttribute interface. Missing parameter attribute must be passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_updateAttribute_Async_0800',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_updateAttribute_Async_0800'; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + } + }; + try{ + inputMethod.getController().updateAttribute(CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_updateAttribute_Promise_0100 + * @tc.name When calling the updateAttribute interface in Promise mode, the parameter + * attribute={textInputType: 0, enterKeyType: 0} must be passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_updateAttribute_Promise_0100',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_updateAttribute_Promise_0100'; + const ATTRIBUTE:any = {textInputType: 0, enterKeyType: 0}; + try{ + let data = await inputMethod.getController().updateAttribute(ATTRIBUTE); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_updateAttribute_Promise_0200 + * @tc.name When calling the updateAttribute interface in Promise mode, the parameter attribute={} must be + * passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_updateAttribute_Promise_0200',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_updateAttribute_Promise_0200'; + const ATTRIBUTE:any = {}; + try{ + let data = await inputMethod.getController().updateAttribute(ATTRIBUTE); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_updateAttribute_Promise_0300 + * @tc.name When calling the updateAttribute interface in Promise mode, the parameter attribute='aa' must be + * passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_updateAttribute_Promise_0300',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_updateAttribute_Promise_0300'; + const ATTRIBUTE:any = 'aa'; + try{ + let data = await inputMethod.getController().updateAttribute(ATTRIBUTE); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_updateAttribute_Promise_0700 + * @tc.name Call the updateAttribute interface in Promise mode, and pass in an invalid input parameter + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_updateAttribute_Promise_0700',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_updateAttribute_Promise_0700'; + const ATTRIBUTE:any = {textInputType: 0, enterKeyType: 0}; + try{ + let data = await inputMethod.getController().updateAttribute(ATTRIBUTE,env.INVALID_TYPE_STRING_A); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_updateAttribute_Promise_0800 + * @tc.name The updateAttribute interface is called in Promise mode. If it is missing, + * the parameter attribute must be passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_updateAttribute_Promise_0800',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_updateAttribute_Promise_0800'; + try{ + let data = await inputMethod.getController().updateAttribute(); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + }) +} \ No newline at end of file diff --git a/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/inputMethod_updateCursor.test.ets b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/inputMethod_updateCursor.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..796302f099023da92c28902d30e3d57f4c2a9cb3 --- /dev/null +++ b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/inputMethod_updateCursor.test.ets @@ -0,0 +1,409 @@ +//@ts-nocheck +/* + * Copyright (c) 2023 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 inputMethod from '@ohos.inputmethod'; +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' +import * as env from './lib/Const'; + +export default function inputMethodTest() { + describe('inputMethod_updateCursor', function () { + function expectTrue(data) { + try { + expect(data).assertTrue(); + }catch (err){ + console.info('assertion failure'); + } + }; + function expectContain(a,b) { + try { + expect(a).assertContain(b); + }catch (err){ + console.info('assertion failure'); + } + }; + function expectFalse() { + try { + expect().assertFail(); + }catch (err){ + console.info('assertion failure'); + } + }; + let st = null as any; + const sleep = function (timeout) { + return new Promise(resolve => { + const st = setTimeout(() => { + resolve(null); + }, timeout); + }); + }; + beforeEach( + async function (){ + try{ + let data = await inputMethod.getController().attach(true,{inputAttribute:{textInputType:1,enterKeyType:2}}); + console.info(`attach inputMethod success, data: ${JSON.stringify(data)}`); + }catch(error){ + console.info(`attach inputMethod fail, error: [${error.code}, ${error.message}]`); + }; + } + ); + afterEach( + async function (){ + try{ + await inputMethod.getController().detach(); + console.info(`clsoe inputMethod success}`); + }catch(error){ + console.info(`clsoe inputMethod fial, error: [${error.code}, ${error.message}]`); + }; + clearTimeout(st); + } + ); + + /** + * @tc.number SUB_Misc_inputMethod_updateCursor_Async_0100 + * @tc.name When calling the changeSelection interface in Async mode, the parameter cursorInfo=CursorInfo object + * must be passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_updateCursor_Async_0100',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_updateCursor_Async_0100'; + const CURSOR_INFO = {left: 2, top: 2, width: 2, height: 2}; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + } + }; + try{ + inputMethod.getController().updateCursor(CURSOR_INFO,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_updateCursor_Async_0200 + * @tc.name When calling the changeSelection interface in Async mode, the parameter cursorInfo={} must be + * passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_updateCursor_Async_0200',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_updateCursor_Async_0200'; + const CURSOR_INFO:any = {}; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + } + }; + try{ + inputMethod.getController().updateCursor(CURSOR_INFO,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_updateCursor_Async_0300 + * @tc.name When calling the changeSelection interface in Async mode, the parameter cursorInfo='123 'must be + * passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_updateCursor_Async_0300',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_updateCursor_Async_0300'; + const CURSOR_INFO:any = '123'; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + } + }; + try{ + inputMethod.getController().updateCursor(CURSOR_INFO,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_updateCursor_Async_0600 + * @tc.name The input method keyboard is not bound, and the changeSelection interface is called in Async mode + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_updateCursor_Async_0600',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_updateCursor_Async_0600'; + const CURSOR_INFO = {left: 2, top: 2, width: 2, height: 2}; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_METHOD_CLIENT_DETACHED); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + } + }; + try{ + let data = await inputMethod.getController().detach(); + console.info(`${CASE_NAME} clsoe inputMethod success, data: ${JSON.stringify(data)}`); + }catch(error){ + console.info(`${CASE_NAME} clsoe inputMethod fial, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + try{ + inputMethod.getController().updateCursor(CURSOR_INFO,CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_METHOD_CLIENT_DETACHED); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_updateCursor_Async_0700 + * @tc.name Async mode calls the updateCursor interface, and an invalid input parameter is passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_updateCursor_Async_0700',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_updateCursor_Async_0700'; + const CURSOR_INFO = {left: 2, top: 2, width: 2, height: 2}; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + } + }; + try{ + inputMethod.getController().updateCursor(CURSOR_INFO,CallBack,env.INVALID_TYPE_STRING_A); + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_updateCursor_Async_0800 + * @tc.name Async mode calls the updateCursor interface. If missing, the parameter cursorInfo must be passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_updateCursor_Async_0800',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_updateCursor_Async_0800'; + let CallBack:any = (error,data) => { + if (error) { + console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }else{ + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + } + }; + try{ + inputMethod.getController().updateCursor(CallBack); + }catch(error){ + console.info(`${CASE_NAME} catch error, expect error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_updateCursor_Promise_0100 + * @tc.name To call the changeSelection interface in Promise mode, the parameter cursorInfo=CursorInfo object + * must be passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_updateCursor_Promise_0100',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_updateCursor_Promise_0100'; + const CURSOR_INFO = {left: 2, top: 2, width: 2, height: 2}; + try{ + let data = await inputMethod.getController().updateCursor(CURSOR_INFO); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_updateCursor_Promise_0200 + * @tc.name To call the changeSelection interface in Promise mode, the parameter cursorInfo={} must be passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_updateCursor_Promise_0200',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_updateCursor_Promise_0200'; + const CURSOR_INFO:any = {}; + try{ + let data = await inputMethod.getController().updateCursor(CURSOR_INFO); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_updateCursor_Promise_0300 + * @tc.name To call the changeSelection interface in Promise mode, the parameter cursorInfo='123' must be + * passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_updateCursor_Promise_0300',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_updateCursor_Promise_0300'; + const CURSOR_INFO:any = '123'; + try{ + let data = await inputMethod.getController().updateCursor(CURSOR_INFO); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_updateCursor_Promise_0600 + * @tc.name The input method keyboard is not bound, and the changeSelection interface is called in Promise mode + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_updateCursor_Promise_0600',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_updateCursor_Promise_0600'; + const CURSOR_INFO = {left: 2, top: 2, width: 2, height: 2}; + try{ + let data = await inputMethod.getController().detach(); + console.info(`${CASE_NAME} clsoe inputMethod success, data: ${JSON.stringify(data)}`); + }catch(error){ + console.info(`${CASE_NAME} clsoe inputMethod fial, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + try{ + let data = await inputMethod.getController().updateCursor(CURSOR_INFO); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_METHOD_CLIENT_DETACHED); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_updateCursor_Promise_0700 + * @tc.name Call the updateCursor interface in Promise mode, and pass in an invalid input parameter + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_updateCursor_Promise_0700',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_updateCursor_Promise_0700'; + const CURSOR_INFO = {left: 2, top: 2, width: 2, height: 2}; + try{ + let data = await inputMethod.getController().updateCursor(CURSOR_INFO,env.INVALID_TYPE_STRING_A); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); + expectFalse(); + done(); + return; + }; + }); + + /** + * @tc.number SUB_Misc_inputMethod_updateCursor_Promise_0800 + * @tc.name The Promise method calls the updateCursor interface. If it is missing, + * the parameter cursorInfo must be passed in + * @tc.desc Function test + */ + it('SUB_Misc_inputMethod_updateCursor_Promise_0800',0, async function (done) { + const CASE_NAME = 'SUB_Misc_inputMethod_updateCursor_Promise_0800'; + try{ + let data = await inputMethod.getController().updateCursor(); + console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); + expectFalse(); + done(); + return; + }catch(error){ + console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); + expectTrue(error.code === env.INVALID_INPUT_PARAMETER); + done(); + return; + }; + }); + + }) +} \ No newline at end of file diff --git a/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/lib/Const.ets b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/lib/Const.ets new file mode 100644 index 0000000000000000000000000000000000000000..57eb6b51ec7c7d418fec85045f9dc48711cd5774 --- /dev/null +++ b/inputmethod/InputMethodDrawnControl/entry/src/main/ets/test/lib/Const.ets @@ -0,0 +1,29 @@ +//ts-nocheck +//public invalid +/* + * Copyright (c) 2023 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 const INVALID_OBJ_NULL:any = {}; +export const INVALID_TYPE_NUMBER_123:any = 123; +export const INVALID_TYPE_STRING_123:any = '123'; +export const INVALID_STRING_NULL:any = ''; +export const INVALID_TYPE_STRING_A:any = 'a'; +export const INVALID_NULL:any = null; +export const INVALID_ENUM_N1:any = -1; +export const INVALID_ENUM_2:any = 2; +//---------------------------------------- +export const INVALID_INPUT_PARAMETER = 401; +export const INVALID_INPUT_METHOD_CLIENT_DETACHED = 12800009; + + diff --git a/inputmethod/InputMethodDrawnControl/entry/src/main/module.json b/inputmethod/InputMethodDrawnControl/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..ef30ac2abc527579ad5574353e39151a67782b30 --- /dev/null +++ b/inputmethod/InputMethodDrawnControl/entry/src/main/module.json @@ -0,0 +1,49 @@ +{ + "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", + "abilities": [ + { + "name": "com.acts.inputmethoddrawncontrol.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" + ] + } + ] + } + ], + "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/InputMethodDrawnControl/entry/src/main/resources/base/element/string.json b/inputmethod/InputMethodDrawnControl/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..b8f1600693378a895a417125aff7970d27b95adb --- /dev/null +++ b/inputmethod/InputMethodDrawnControl/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": "ActsInputMethodDrawnControlTest" + }, + { + "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/InputMethodDrawnControl/entry/src/main/resources/base/media/icon.png b/inputmethod/InputMethodDrawnControl/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/inputmethod/InputMethodDrawnControl/entry/src/main/resources/base/media/icon.png differ diff --git a/inputmethod/InputMethodDrawnControl/entry/src/main/resources/base/profile/main_pages.json b/inputmethod/InputMethodDrawnControl/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..6898b31d2085f478ee1ed9d933a5910cbf901d92 --- /dev/null +++ b/inputmethod/InputMethodDrawnControl/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/InputMethodDrawnControl/signature/ActsInputMethodDrawnControlTest.p7b b/inputmethod/InputMethodDrawnControl/signature/ActsInputMethodDrawnControlTest.p7b new file mode 100644 index 0000000000000000000000000000000000000000..ff276fe82651caf0da0c88134135a33eee456f98 Binary files /dev/null and b/inputmethod/InputMethodDrawnControl/signature/ActsInputMethodDrawnControlTest.p7b differ diff --git a/inputmethod/InputMethodEngine/entry/src/main/ets/InputMethodAbility/KeyboardDelegate.ts b/inputmethod/InputMethodEngine/entry/src/main/ets/InputMethodAbility/KeyboardDelegate.ts index 1dbd418fd358d9ccb3574d994e8d25c548169e73..dbed7ee64fd72e4a849559cc43c11409c6a79332 100644 --- a/inputmethod/InputMethodEngine/entry/src/main/ets/InputMethodAbility/KeyboardDelegate.ts +++ b/inputmethod/InputMethodEngine/entry/src/main/ets/InputMethodAbility/KeyboardDelegate.ts @@ -543,7 +543,7 @@ export class KeyboardDelegate { }; commoneventmanager.publish("inputMethodAbility_test_035", commonEventPublishData, this.publishCallback); } else { - let value = InputClient.insertText('test'); + let value = await InputClient.insertText('test'); console.debug(TAG + '====>inputMethodAbility_test_035 insertText value:' + JSON.stringify(value)); if (value) { commonEventPublishData = { @@ -605,7 +605,7 @@ export class KeyboardDelegate { }; commoneventmanager.publish("inputMethodAbility_test_037", commonEventPublishData, this.publishCallback); } else { - let value = InputClient.getForward(1); + let value = await InputClient.getForward(1); console.debug(TAG + '====>inputMethodAbility_test_037 getForward value' + JSON.stringify(value)); if (value) { commonEventPublishData = { @@ -667,7 +667,7 @@ export class KeyboardDelegate { }; commoneventmanager.publish("inputMethodAbility_test_039", commonEventPublishData, this.publishCallback); } else { - let value = InputClient.getEditorAttribute(); + let value = await InputClient.getEditorAttribute(); console.debug(TAG + '====>inputMethodAbility_test_039 getEditorAttribute value:' + JSON.stringify(value)); if (value) { commonEventPublishData = { @@ -787,7 +787,7 @@ export class KeyboardDelegate { }; commoneventmanager.publish("inputMethodAbility_test_043", commonEventPublishData, this.publishCallback); } else { - let value = InputClient.getBackward(1); + let value = await InputClient.getBackward(1); console.debug(TAG + '====>inputMethodAbility_test_043 getBackward value:' + JSON.stringify(value)); commonEventPublishData = { data: "SUCCESS" 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 index 43d444d82fa1a1449e629a23f4e04f3bf085fb14..9582c06acda2dfdfde0a1011774b8e32f5737dc0 100644 --- a/inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/List.test.ets +++ b/inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/List.test.ets @@ -13,8 +13,8 @@ * limitations under the License. */ import imeAbilityTest from './imeAbilityTest.test' -import inputMethodStageJSUnit from './inputMethodStageJSUnit'; -import inputMethodNormalStageJSUnit from './inputMethodNormalStageJSUnit'; +import inputMethodStageJSUnit from './inputMethodStageJSUnit.test'; +import inputMethodNormalStageJSUnit from './inputMethodNormalStageJSUnit.test'; export default function testsuite() { imeAbilityTest(globalThis.abilityContext); diff --git a/inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/inputMethodNormalStageJSUnit.ets b/inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/inputMethodNormalStageJSUnit.test.ets similarity index 100% rename from inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/inputMethodNormalStageJSUnit.ets rename to inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/inputMethodNormalStageJSUnit.test.ets diff --git a/inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/inputMethodStageJSUnit.ets b/inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/inputMethodStageJSUnit.test.ets similarity index 100% rename from inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/inputMethodStageJSUnit.ets rename to inputmethod/InputMethodTest_Stage/entry/src/main/ets/test/inputMethodStageJSUnit.test.ets 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 index 6b78af64c9754d7aad1df92fa865e4c34aebfe8a..4fe059ec1ec0cec05ca15bf6bfa4f92f130b499e 100644 --- a/inputmethod/InputMethodTest_ets/entry/src/main/ets/test/List.test.ets +++ b/inputmethod/InputMethodTest_ets/entry/src/main/ets/test/List.test.ets @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import inputMethodJSUnit from './inputMethodJSUnit'; -import inputMethodNormalJSUnit from './inputMethodNormalJSUnit'; +import inputMethodJSUnit from './inputMethodJSUnit.test'; +import inputMethodNormalJSUnit from './inputMethodNormalJSUnit.test'; export default function testsuite() { inputMethodJSUnit(); diff --git a/inputmethod/InputMethodTest_ets/entry/src/main/ets/test/inputMethodJSUnit.ets b/inputmethod/InputMethodTest_ets/entry/src/main/ets/test/inputMethodJSUnit.test.ets similarity index 100% rename from inputmethod/InputMethodTest_ets/entry/src/main/ets/test/inputMethodJSUnit.ets rename to inputmethod/InputMethodTest_ets/entry/src/main/ets/test/inputMethodJSUnit.test.ets diff --git a/inputmethod/InputMethodTest_ets/entry/src/main/ets/test/inputMethodNormalJSUnit.ets b/inputmethod/InputMethodTest_ets/entry/src/main/ets/test/inputMethodNormalJSUnit.test.ets similarity index 100% rename from inputmethod/InputMethodTest_ets/entry/src/main/ets/test/inputMethodNormalJSUnit.ets rename to inputmethod/InputMethodTest_ets/entry/src/main/ets/test/inputMethodNormalJSUnit.test.ets diff --git a/inputmethod/InputMethodWindManage/entry/src/main/ets/InputMethodWindManage/KeyboardController.ts b/inputmethod/InputMethodWindManage/entry/src/main/ets/InputMethodWindManage/KeyboardController.ts index 1dd313622f8c1b741cca8c80d0fa3c0bcfc57e08..f4c587c11c805acd776b0d5fbccd1c8317607715 100644 --- a/inputmethod/InputMethodWindManage/entry/src/main/ets/InputMethodWindManage/KeyboardController.ts +++ b/inputmethod/InputMethodWindManage/entry/src/main/ets/InputMethodWindManage/KeyboardController.ts @@ -108,14 +108,6 @@ export class KeyboardController { console.debug(TAG + '====>Sub_Misc_inputMethod_Panel_resizePromise_0100 event:' + data.event); that.Sub_Misc_inputMethod_Panel_resizePromise_0100(); break; - case 90: - console.debug(TAG + '====>Sub_Misc_inputMethod_Panel_resizeCallback_0090 event:' + data.event); - that.Sub_Misc_inputMethod_Panel_resizeCallback_0090(); - break; - case 100: - console.debug(TAG + '====>Sub_Misc_inputMethod_Panel_resizePromise_0100 event:' + data.event); - that.Sub_Misc_inputMethod_Panel_resizePromise_0100(); - break; case 110: console.debug(TAG + '====>Sub_Misc_inputMethod_Panel_moveToCallback_0110 event:' + data.event); that.Sub_Misc_inputMethod_Panel_moveToCallback_0110(); @@ -306,7 +298,7 @@ export class KeyboardController { console.info('====>Sub_Misc_inputMethod_Panel_destroyPanelCallback_0030 Succeed in destroying panel.' + JSON.stringify(panel)); } commoneventmanager.publish("Sub_Misc_inputMethod_Panel_destroyPanelCallback_0030", commonEventPublishData, this.publishCallback); - }) + }); }catch(error){ commonEventPublishData = { data: "FAILED" @@ -614,7 +606,7 @@ export class KeyboardController { console.info('====>Sub_Misc_inputMethod_Panel_showCallback_0130 Succeed in showing the panel: ' + JSON.stringify(data)); } commoneventmanager.publish("Sub_Misc_inputMethod_Panel_showCallback_0130", commonEventPublishData, this.publishCallback); - }) + }); }else{ commonEventPublishData = { data: "FAILED" 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 index fd10a4e7cd4177f4a857951272c95969096a84cb..ce3aca631f29c40005d9e178067a799d81e01838 100644 --- a/theme/screenlock_ets/entry/src/main/ets/test/List.test.ets +++ b/theme/screenlock_ets/entry/src/main/ets/test/List.test.ets @@ -13,8 +13,8 @@ * limitations under the License. */ -import screenLockJSUnit from './screenLockTest'; -import ScreenLockPromiseTest from './screenLockPromiseTest'; +import screenLockJSUnit from './screenLockTest.test'; +import ScreenLockPromiseTest from './screenLockPromiseTest.test'; export default function testsuite() { screenLockJSUnit(); diff --git a/theme/screenlock_ets/entry/src/main/ets/test/screenLockPromiseTest.ets b/theme/screenlock_ets/entry/src/main/ets/test/screenLockPromiseTest.test.ets similarity index 100% rename from theme/screenlock_ets/entry/src/main/ets/test/screenLockPromiseTest.ets rename to theme/screenlock_ets/entry/src/main/ets/test/screenLockPromiseTest.test.ets diff --git a/theme/screenlock_ets/entry/src/main/ets/test/screenLockTest.ets b/theme/screenlock_ets/entry/src/main/ets/test/screenLockTest.test.ets similarity index 100% rename from theme/screenlock_ets/entry/src/main/ets/test/screenLockTest.ets rename to theme/screenlock_ets/entry/src/main/ets/test/screenLockTest.test.ets diff --git a/theme/wallpaper_authority_ets/entry/src/main/ets/test/List.test.ets b/theme/wallpaper_authority_ets/entry/src/main/ets/test/List.test.ets index f1269cd76c033ab710089f345ab3e5131f30b356..85b3db1703d57aaf89981256475c62d71966d724 100644 --- a/theme/wallpaper_authority_ets/entry/src/main/ets/test/List.test.ets +++ b/theme/wallpaper_authority_ets/entry/src/main/ets/test/List.test.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import wallpaperAuthorityJSUnit from './wallpaperauthorityTest'; +import wallpaperAuthorityJSUnit from './wallpaperauthorityTest.test'; export default function testsuite() { wallpaperAuthorityJSUnit(); diff --git a/theme/wallpaper_authority_ets/entry/src/main/ets/test/wallpaperauthorityTest.ets b/theme/wallpaper_authority_ets/entry/src/main/ets/test/wallpaperauthorityTest.test.ets similarity index 100% rename from theme/wallpaper_authority_ets/entry/src/main/ets/test/wallpaperauthorityTest.ets rename to theme/wallpaper_authority_ets/entry/src/main/ets/test/wallpaperauthorityTest.test.ets 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 index 7b163c54b99ad5a0ee41599918a6b4f7bf39b41e..7ed6b6eb6491947402558ff56b2f97693257ffee 100644 --- a/theme/wallpaper_ets/entry/src/main/ets/test/List.test.ets +++ b/theme/wallpaper_ets/entry/src/main/ets/test/List.test.ets @@ -13,8 +13,8 @@ * limitations under the License. */ -import wallpaperJSUnit from './wallpaperTest'; -import wallpaperNoPermissionTest from './wallpapernopermissionTest'; +import wallpaperJSUnit from './wallpaperTest.test'; +import wallpaperNoPermissionTest from './wallpapernopermissionTest.test'; export default function testsuite() { wallpaperJSUnit(); diff --git a/theme/wallpaper_ets/entry/src/main/ets/test/wallpaperTest.ets b/theme/wallpaper_ets/entry/src/main/ets/test/wallpaperTest.test.ets similarity index 100% rename from theme/wallpaper_ets/entry/src/main/ets/test/wallpaperTest.ets rename to theme/wallpaper_ets/entry/src/main/ets/test/wallpaperTest.test.ets diff --git a/theme/wallpaper_ets/entry/src/main/ets/test/wallpapernopermissionTest.ets b/theme/wallpaper_ets/entry/src/main/ets/test/wallpapernopermissionTest.test.ets similarity index 100% rename from theme/wallpaper_ets/entry/src/main/ets/test/wallpapernopermissionTest.ets rename to theme/wallpaper_ets/entry/src/main/ets/test/wallpapernopermissionTest.test.ets diff --git a/time/timeTest/entry/src/main/ets/test/List.test.ets b/time/timeTest/entry/src/main/ets/test/List.test.ets index 66ced2dadb5fea0ae1f5fdc868351c3336a73305..2e41e200d8e3d9a68a382a95528d0fe2362a7f4a 100644 --- a/time/timeTest/entry/src/main/ets/test/List.test.ets +++ b/time/timeTest/entry/src/main/ets/test/List.test.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import systemTimeJsunit from './systemTimeTest'; +import systemTimeJsunit from './systemTimeTest.test'; import systemTimeNoPermissionTest from './timeNoPermission.test' export default function testsuite() { diff --git a/time/timeTest/entry/src/main/ets/test/systemTimeTest.ets b/time/timeTest/entry/src/main/ets/test/systemTimeTest.test.ets similarity index 100% rename from time/timeTest/entry/src/main/ets/test/systemTimeTest.ets rename to time/timeTest/entry/src/main/ets/test/systemTimeTest.test.ets