1//@ts-nocheck 2/* 3 * Copyright (c) 2023 Huawei Device Co., Ltd. 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16import inputMethod from '@ohos.inputmethod'; 17import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' 18import * as env from './lib/Const'; 19 20export default function inputMethodTest() { 21 describe('inputMethod_updateAttribute', function () { 22 function expectTrue(data) { 23 try { 24 expect(data).assertTrue(); 25 }catch (err){ 26 console.info('assertion failure'); 27 } 28 }; 29 function expectContain(a,b) { 30 try { 31 expect(a).assertContain(b); 32 }catch (err){ 33 console.info('assertion failure'); 34 } 35 }; 36 function expectFalse() { 37 try { 38 expect().assertFail(); 39 }catch (err){ 40 console.info('assertion failure'); 41 } 42 }; 43 let st = null as any; 44 const sleep = function (timeout) { 45 return new Promise(resolve => { 46 const st = setTimeout(() => { 47 resolve(null); 48 }, timeout); 49 }); 50 }; 51 beforeEach( 52 async function (){ 53 try{ 54 let data = await inputMethod.getController().attach(true,{inputAttribute:{textInputType:1,enterKeyType:2}}); 55 console.info(`attach inputMethod success, data: ${JSON.stringify(data)}`); 56 }catch(error){ 57 console.info(`attach inputMethod fail, error: [${error.code}, ${error.message}]`); 58 }; 59 } 60 ); 61 afterEach( 62 async function (){ 63 try{ 64 await inputMethod.getController().detach(); 65 console.info(`clsoe inputMethod success}`); 66 }catch(error){ 67 console.info(`clsoe inputMethod fial, error: [${error.code}, ${error.message}]`); 68 }; 69 clearTimeout(st); 70 } 71 ); 72 73 74 /** 75 * @tc.number SUB_Misc_inputMethod_updateAttribute_Async_0100 76 * @tc.name When calling the updateAttribute interface in Async mode, the parameter attribute= 77 * {textInputType: 0, enterKeyType: 0} must be passed in 78 * @tc.desc Function test 79 */ 80 it('SUB_Misc_inputMethod_updateAttribute_Async_0100',0, async function (done) { 81 const CASE_NAME = 'SUB_Misc_inputMethod_updateAttribute_Async_0100'; 82 const ATTRIBUTE:any = {textInputType: 0, enterKeyType: 0}; 83 let CallBack:any = (error,data) => { 84 if (error) { 85 console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`); 86 expectFalse(); 87 done(); 88 return; 89 }else{ 90 console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); 91 done(); 92 return; 93 } 94 }; 95 try{ 96 inputMethod.getController().updateAttribute(ATTRIBUTE,CallBack); 97 }catch(error){ 98 console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); 99 expectFalse(); 100 done(); 101 return; 102 }; 103 }); 104 105 /** 106 * @tc.number SUB_Misc_inputMethod_updateAttribute_Async_0200 107 * @tc.name When calling the updateAttribute interface in Async mode, the parameter attribute={} must be 108 * passed in 109 * @tc.desc Function test 110 */ 111 it('SUB_Misc_inputMethod_updateAttribute_Async_0200',0, async function (done) { 112 const CASE_NAME = 'SUB_Misc_inputMethod_updateAttribute_Async_0200'; 113 const ATTRIBUTE:any = {}; 114 let CallBack:any = (error,data) => { 115 if (error) { 116 console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); 117 expectTrue(error.code === env.INVALID_INPUT_PARAMETER); 118 return; 119 }else{ 120 console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); 121 expectFalse(); 122 done(); 123 return; 124 } 125 }; 126 try{ 127 inputMethod.getController().updateAttribute(ATTRIBUTE,CallBack); 128 }catch(error){ 129 console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); 130 expectTrue(error.code === env.INVALID_INPUT_PARAMETER); 131 done(); 132 return; 133 }; 134 }); 135 136 /** 137 * @tc.number SUB_Misc_inputMethod_updateAttribute_Async_0300 138 * @tc.name When calling the updateAttribute interface in Async mode, the parameter attribute='aa' must be 139 * passed in 140 * @tc.desc Function test 141 */ 142 it('SUB_Misc_inputMethod_updateAttribute_Async_0300',0, async function (done) { 143 const CASE_NAME = 'SUB_Misc_inputMethod_updateAttribute_Async_0300'; 144 const ATTRIBUTE:any = 'aa'; 145 let CallBack:any = (error,data) => { 146 if (error) { 147 console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); 148 expectTrue(error.code === env.INVALID_INPUT_PARAMETER); 149 done(); 150 return; 151 }else{ 152 console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); 153 expectFalse(); 154 done(); 155 return; 156 } 157 }; 158 try{ 159 inputMethod.getController().updateAttribute(ATTRIBUTE,CallBack); 160 }catch(error){ 161 console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); 162 expectTrue(error.code === env.INVALID_INPUT_PARAMETER); 163 done(); 164 return; 165 }; 166 }); 167 168 /** 169 * @tc.number SUB_Misc_inputMethod_updateAttribute_Async_0700 170 * @tc.name Async mode calls the updateAttribute interface and passes in an invalid input parameter 171 * @tc.desc Function test 172 */ 173 it('SUB_Misc_inputMethod_updateAttribute_Async_0700',0, async function (done) { 174 const CASE_NAME = 'SUB_Misc_inputMethod_updateAttribute_Async_0700'; 175 const ATTRIBUTE:any = {textInputType: 0, enterKeyType: 0}; 176 let CallBack:any = (error,data) => { 177 if (error) { 178 console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`); 179 expectFalse(); 180 done(); 181 return; 182 }else{ 183 console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); 184 done(); 185 return; 186 } 187 }; 188 try{ 189 inputMethod.getController().updateAttribute(ATTRIBUTE,CallBack,env.INVALID_TYPE_STRING_A); 190 }catch(error){ 191 console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); 192 expectFalse(); 193 done(); 194 return; 195 }; 196 }); 197 198 /** 199 * @tc.number SUB_Misc_inputMethod_updateAttribute_Async_0800 200 * @tc.name Async method calls the updateAttribute interface. Missing parameter attribute must be passed in 201 * @tc.desc Function test 202 */ 203 it('SUB_Misc_inputMethod_updateAttribute_Async_0800',0, async function (done) { 204 const CASE_NAME = 'SUB_Misc_inputMethod_updateAttribute_Async_0800'; 205 let CallBack:any = (error,data) => { 206 if (error) { 207 console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`); 208 expectTrue(error.code === env.INVALID_INPUT_PARAMETER); 209 done(); 210 return; 211 }else{ 212 console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); 213 expectFalse(); 214 done(); 215 return; 216 } 217 }; 218 try{ 219 inputMethod.getController().updateAttribute(CallBack); 220 }catch(error){ 221 console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); 222 expectTrue(error.code === env.INVALID_INPUT_PARAMETER); 223 done(); 224 return; 225 }; 226 }); 227 228 /** 229 * @tc.number SUB_Misc_inputMethod_updateAttribute_Promise_0100 230 * @tc.name When calling the updateAttribute interface in Promise mode, the parameter 231 * attribute={textInputType: 0, enterKeyType: 0} must be passed in 232 * @tc.desc Function test 233 */ 234 it('SUB_Misc_inputMethod_updateAttribute_Promise_0100',0, async function (done) { 235 const CASE_NAME = 'SUB_Misc_inputMethod_updateAttribute_Promise_0100'; 236 const ATTRIBUTE:any = {textInputType: 0, enterKeyType: 0}; 237 try{ 238 let data = await inputMethod.getController().updateAttribute(ATTRIBUTE); 239 console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); 240 done(); 241 return; 242 }catch(error){ 243 console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); 244 expectFalse(); 245 done(); 246 return; 247 }; 248 }); 249 250 /** 251 * @tc.number SUB_Misc_inputMethod_updateAttribute_Promise_0200 252 * @tc.name When calling the updateAttribute interface in Promise mode, the parameter attribute={} must be 253 * passed in 254 * @tc.desc Function test 255 */ 256 it('SUB_Misc_inputMethod_updateAttribute_Promise_0200',0, async function (done) { 257 const CASE_NAME = 'SUB_Misc_inputMethod_updateAttribute_Promise_0200'; 258 const ATTRIBUTE:any = {}; 259 try{ 260 let data = await inputMethod.getController().updateAttribute(ATTRIBUTE); 261 console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); 262 expectFalse(); 263 done(); 264 return; 265 }catch(error){ 266 console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); 267 expectTrue(error.code === env.INVALID_INPUT_PARAMETER); 268 done(); 269 return; 270 }; 271 }); 272 273 /** 274 * @tc.number SUB_Misc_inputMethod_updateAttribute_Promise_0300 275 * @tc.name When calling the updateAttribute interface in Promise mode, the parameter attribute='aa' must be 276 * passed in 277 * @tc.desc Function test 278 */ 279 it('SUB_Misc_inputMethod_updateAttribute_Promise_0300',0, async function (done) { 280 const CASE_NAME = 'SUB_Misc_inputMethod_updateAttribute_Promise_0300'; 281 const ATTRIBUTE:any = 'aa'; 282 try{ 283 let data = await inputMethod.getController().updateAttribute(ATTRIBUTE); 284 console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); 285 expectFalse(); 286 done(); 287 return; 288 }catch(error){ 289 console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); 290 expectTrue(error.code === env.INVALID_INPUT_PARAMETER); 291 done(); 292 return; 293 }; 294 }); 295 296 /** 297 * @tc.number SUB_Misc_inputMethod_updateAttribute_Promise_0700 298 * @tc.name Call the updateAttribute interface in Promise mode, and pass in an invalid input parameter 299 * @tc.desc Function test 300 */ 301 it('SUB_Misc_inputMethod_updateAttribute_Promise_0700',0, async function (done) { 302 const CASE_NAME = 'SUB_Misc_inputMethod_updateAttribute_Promise_0700'; 303 const ATTRIBUTE:any = {textInputType: 0, enterKeyType: 0}; 304 try{ 305 let data = await inputMethod.getController().updateAttribute(ATTRIBUTE,env.INVALID_TYPE_STRING_A); 306 console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); 307 done(); 308 return; 309 }catch(error){ 310 console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`); 311 expectFalse(); 312 done(); 313 return; 314 }; 315 }); 316 317 /** 318 * @tc.number SUB_Misc_inputMethod_updateAttribute_Promise_0800 319 * @tc.name The updateAttribute interface is called in Promise mode. If it is missing, 320 * the parameter attribute must be passed in 321 * @tc.desc Function test 322 */ 323 it('SUB_Misc_inputMethod_updateAttribute_Promise_0800',0, async function (done) { 324 const CASE_NAME = 'SUB_Misc_inputMethod_updateAttribute_Promise_0800'; 325 try{ 326 let data = await inputMethod.getController().updateAttribute(); 327 console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`); 328 expectFalse(); 329 done(); 330 return; 331 }catch(error){ 332 console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`); 333 expectTrue(error.code === env.INVALID_INPUT_PARAMETER); 334 done(); 335 return; 336 }; 337 }); 338 339 }) 340}