• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_setCallingWindow', 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_setCallingWindow_Async_0100
76     * @tc.name    When calling the setCallingWindow interface in Async mode, the parameter windowId=5 must be passed in
77     * @tc.desc    Function test
78     */
79    it('SUB_Misc_inputMethod_setCallingWindow_Async_0100',0, async function (done) {
80      const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Async_0100';
81      const WINDOW_ID:any = 5;
82      let CallBack:any = (error,data) => {
83        if (error) {
84          console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`);
85          expectFalse();
86          done();
87          return;
88        }else{
89          console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`);
90          done();
91          return;
92        }
93      };
94      try{
95        inputMethod.getController().setCallingWindow(WINDOW_ID,CallBack);
96      }catch(error){
97        console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`);
98        expectFalse();
99        done();
100        return;
101      };
102    });
103
104    /**
105     * @tc.number  SUB_Misc_inputMethod_setCallingWindow_Async_0200
106     * @tc.name    When calling the setCallingWindow interface in Async mode, the parameter windowId=0 must be passed in
107     * @tc.desc    Function test
108     */
109    it('SUB_Misc_inputMethod_setCallingWindow_Async_0200',0, async function (done) {
110      const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Async_0200';
111      const WINDOW_ID:any = 0;
112      let CallBack:any = (error,data) => {
113        if (error) {
114          console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`);
115          expectFalse();
116          return;
117        }else{
118          console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`);
119          done();
120          return;
121        }
122      };
123      try{
124        inputMethod.getController().setCallingWindow(WINDOW_ID,CallBack);
125      }catch(error){
126        console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`);
127        expectFalse();
128        done();
129        return;
130      };
131    });
132
133    /**
134     * @tc.number  SUB_Misc_inputMethod_setCallingWindow_Async_0300
135     * @tc.name    When calling the setCallingWindow interface in Async mode, the parameter windowId='5' must be
136     *             passed in
137     * @tc.desc    Function test
138     */
139    it('SUB_Misc_inputMethod_setCallingWindow_Async_0300',0, async function (done) {
140      const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Async_0300';
141      const WINDOW_ID:any = '5';
142      let CallBack:any = (error,data) => {
143        if (error) {
144          console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`);
145          expectTrue(error.code === env.INVALID_INPUT_PARAMETER);
146          done();
147          return;
148        }else{
149          console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`);
150          expectFalse();
151          done();
152          return;
153        }
154      };
155      try{
156        inputMethod.getController().setCallingWindow(WINDOW_ID,CallBack);
157      }catch(error){
158        console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`);
159        expectTrue(error.code === env.INVALID_INPUT_PARAMETER);
160        done();
161        return;
162      };
163    });
164
165    /**
166     * @tc.number  SUB_Misc_inputMethod_setCallingWindow_Async_0600
167     * @tc.name    The input method keyboard is not bound, and the setCallingWindow interface is called in Async mode
168     * @tc.desc    Function test
169     */
170    it('SUB_Misc_inputMethod_setCallingWindow_Async_0600',0, async function (done) {
171      const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Async_0600';
172      const WINDOW_ID:any = 5;
173      let CallBack:any = (error,data) => {
174        if (error) {
175          console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`);
176          expectTrue(error.code === env.INVALID_INPUT_METHOD_CLIENT_DETACHED);
177          done();
178          return;
179        }else{
180          console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`);
181          expectFalse();
182          done();
183          return;
184        }
185      };
186      try{
187        let data = await inputMethod.getController().detach();
188        console.info(`${CASE_NAME} clsoe inputMethod success, data: ${JSON.stringify(data)}`);
189      }catch(error){
190        console.info(`${CASE_NAME} clsoe inputMethod fial, error: [${error.code}, ${error.message}]`);
191        expectFalse();
192        done();
193        return;
194      };
195      try{
196        inputMethod.getController().setCallingWindow(WINDOW_ID,CallBack);
197      }catch(error){
198        console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`);
199        expectTrue(error.code === env.INVALID_INPUT_METHOD_CLIENT_DETACHED);
200        done();
201        return;
202      };
203    });
204
205    /**
206     * @tc.number  SUB_Misc_inputMethod_setCallingWindow_Async_0700
207     * @tc.name    Async mode calls the setCallingWindow interface, and an invalid input parameter is passed in
208     * @tc.desc    Function test
209     */
210    it('SUB_Misc_inputMethod_setCallingWindow_Async_0700',0, async function (done) {
211      const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Async_0700';
212      const WINDOW_ID:any = 5;
213      let CallBack:any = (error,data) => {
214        if (error) {
215          console.info(`${CASE_NAME} execution fail,error: [${error.code}, ${error.message}]`);
216          expectFalse();
217          done();
218          return;
219        }else{
220          console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`);
221          done();
222          return;
223        }
224      };
225      try{
226        inputMethod.getController().setCallingWindow(WINDOW_ID,CallBack,env.INVALID_TYPE_STRING_A);
227      }catch(error){
228        console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`);
229        expectFalse();
230        done();
231        return;
232      };
233    });
234
235    /**
236     * @tc.number  SUB_Misc_inputMethod_setCallingWindow_Async_0800
237     * @tc.name    Async method calls the setCallingWindow interface. Missing parameter windowId must be passed in
238     * @tc.desc    Function test
239     */
240    it('SUB_Misc_inputMethod_setCallingWindow_Async_0800',0, async function (done) {
241      const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Async_0800';
242      let CallBack:any = (error,data) => {
243        if (error) {
244          console.info(`${CASE_NAME} execution fail, expect error: [${error.code}, ${error.message}]`);
245          expectTrue(error.code === env.INVALID_INPUT_PARAMETER);
246          done();
247          return;
248        }else{
249          console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`);
250          expectFalse();
251          done();
252          return;
253        }
254      };
255      try{
256        inputMethod.getController().setCallingWindow(CallBack);
257      }catch(error){
258        console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`);
259        expectTrue(error.code === env.INVALID_INPUT_PARAMETER);
260        done();
261        return;
262      };
263    });
264
265    /**
266     * @tc.number  SUB_Misc_inputMethod_setCallingWindow_Promise_0100
267     * @tc.name    When calling the setCallingWindow interface in Promise mode, the parameter
268     *             windowId=5 must be passed in
269     * @tc.desc    Function test
270     */
271    it('SUB_Misc_inputMethod_setCallingWindow_Promise_0100',0, async function (done) {
272      const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Promise_0100';
273      const WINDOW_ID:any = 5;
274      try{
275        let data = await inputMethod.getController().setCallingWindow(WINDOW_ID);
276        console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`);
277        done();
278        return;
279      }catch(error){
280        console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`);
281        expectFalse();
282        done();
283        return;
284      };
285    });
286
287    /**
288     * @tc.number  SUB_Misc_inputMethod_setCallingWindow_Promise_0200
289     * @tc.name    When calling the setCallingWindow interface in Promise mode, the parameter windowId=0 must be
290     *             passed in
291     * @tc.desc    Function test
292     */
293    it('SUB_Misc_inputMethod_setCallingWindow_Promise_0200',0, async function (done) {
294      const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Promise_0200';
295      const WINDOW_ID:any = 0;
296      try{
297        let data = await inputMethod.getController().setCallingWindow(WINDOW_ID);
298        console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`);
299        done();
300        return;
301      }catch(error){
302        console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`);
303        expectFalse();
304        done();
305        return;
306      };
307    });
308
309    /**
310     * @tc.number  SUB_Misc_inputMethod_setCallingWindow_Promise_0300
311     * @tc.name    When calling the setCallingWindow interface in Promise mode, the parameter windowId='5' must be
312     *             passed in
313     * @tc.desc    Function test
314     */
315    it('SUB_Misc_inputMethod_setCallingWindow_Promise_0300',0, async function (done) {
316      const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Promise_0300';
317      const WINDOW_ID:any = '5';
318      try{
319        let data = await inputMethod.getController().setCallingWindow(WINDOW_ID);
320        console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`);
321        expectFalse();
322        done();
323        return;
324      }catch(error){
325        console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`);
326        expectTrue(error.code === env.INVALID_INPUT_PARAMETER);
327        done();
328        return;
329      };
330    });
331
332    /**
333     * @tc.number  SUB_Misc_inputMethod_setCallingWindow_Promise_0600
334     * @tc.name    The input method keyboard is not bound, and the setCallingWindow interface is called in Promise mode
335     * @tc.desc    Function test
336     */
337    it('SUB_Misc_inputMethod_setCallingWindow_Promise_0600',0, async function (done) {
338      const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Promise_0600';
339      const WINDOW_ID:any = 5;
340      try{
341        let data = await inputMethod.getController().detach();
342        console.info(`${CASE_NAME} clsoe inputMethod success, data: ${JSON.stringify(data)}`);
343      }catch(error){
344        console.info(`${CASE_NAME} clsoe inputMethod fial, error: [${error.code}, ${error.message}]`);
345        expectFalse();
346        done();
347        return;
348      };
349      try{
350        let data = await inputMethod.getController().setCallingWindow(WINDOW_ID);
351        console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`);
352        expectFalse();
353        done();
354        return;
355      }catch(error){
356        console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`);
357        expectTrue(error.code === env.INVALID_INPUT_METHOD_CLIENT_DETACHED);
358        done();
359        return;
360      };
361    });
362
363    /**
364     * @tc.number  SUB_Misc_inputMethod_setCallingWindow_Promise_0700
365     * @tc.name    Call setCallingWindow interface in Promise mode, and pass in an invalid input parameter
366     * @tc.desc    Function test
367     */
368    it('SUB_Misc_inputMethod_setCallingWindow_Promise_0700',0, async function (done) {
369      const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Promise_0700';
370      const WINDOW_ID:any = 5;
371      try{
372        let data = await inputMethod.getController().setCallingWindow(WINDOW_ID,env.INVALID_TYPE_STRING_A);
373        console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`);
374        done();
375        return;
376      }catch(error){
377        console.info(`${CASE_NAME} catch error, error: [${error.code}, ${error.message}]`);
378        expectFalse();
379        done();
380        return;
381      };
382    });
383
384    /**
385     * @tc.number  SUB_Misc_inputMethod_setCallingWindow_Promise_0800
386     * @tc.name    The setCallingWindow interface is called in Promise mode, and the parameter windowId must be
387     *             passed in if it is missing
388     * @tc.desc    Function test
389     */
390    it('SUB_Misc_inputMethod_setCallingWindow_Promise_0800',0, async function (done) {
391      const CASE_NAME = 'SUB_Misc_inputMethod_setCallingWindow_Promise_0800';
392      try{
393        let data = await inputMethod.getController().setCallingWindow();
394        console.info(`${CASE_NAME} execution success, data: ${JSON.stringify(data)}`);
395        expectFalse();
396        done();
397        return;
398      }catch(error){
399        console.info(`${CASE_NAME} catch error, except error: [${error.code}, ${error.message}]`);
400        expectTrue(error.code === env.INVALID_INPUT_PARAMETER);
401        done();
402        return;
403      };
404    });
405
406  })
407}