1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include <gtest/gtest.h>
16
17 #include "string_ex.h"
18
19 #include "global.h"
20 #include "native_inputmethod_types.h"
21 #include "mock_input_method_system_ability_proxy.h"
22 #include "input_method_controller.h"
23
24 using namespace testing::ext;
25 using namespace OHOS;
26 using namespace OHOS::MiscServices;
27 using namespace testing;
28 class InputMethodControllerCapiTest : public testing::Test { };
29 namespace {
30 /**
31 * @tc.name: TestCursorInfo_001
32 * @tc.desc: create and destroy TestCursorInfo success
33 * @tc.type: FUNC
34 */
35 HWTEST_F(InputMethodControllerCapiTest, TestCursorInfo_001, TestSize.Level0)
36 {
37 double expLeft = 1.1;
38 double expTop = 2.2;
39 double expWidth = 3.3;
40 double expHeight = 4.4;
41 auto cursorInfo = OH_CursorInfo_Create(expLeft, expTop, expWidth, expHeight);
42 ASSERT_NE(nullptr, cursorInfo);
43
44 double actLeft = 0;
45 double actTop = 0;
46 double actWidth = 0;
47 double actHeight = 0;
48 EXPECT_EQ(IME_ERR_OK, OH_CursorInfo_GetRect(cursorInfo, &actLeft, &actTop, &actWidth, &actHeight));
49 EXPECT_EQ(expLeft, actLeft);
50 EXPECT_EQ(expTop, actTop);
51 EXPECT_EQ(expWidth, actWidth);
52 EXPECT_EQ(expHeight, actHeight);
53
54 // test set rect
55 expLeft = 1;
56 expTop = 2;
57 expWidth = 3;
58 expHeight = 4;
59 EXPECT_EQ(IME_ERR_OK, OH_CursorInfo_SetRect(cursorInfo, expLeft, expTop, expWidth, expHeight));
60 EXPECT_EQ(IME_ERR_OK, OH_CursorInfo_GetRect(cursorInfo, &actLeft, &actTop, &actWidth, &actHeight));
61 EXPECT_EQ(expLeft, actLeft);
62 EXPECT_EQ(expTop, actTop);
63 EXPECT_EQ(expWidth, actWidth);
64 EXPECT_EQ(expHeight, actHeight);
65
66 OH_CursorInfo_Destroy(cursorInfo);
67 }
68
TestCursorInfoOfTextConfig(InputMethod_TextConfig * config)69 static void TestCursorInfoOfTextConfig(InputMethod_TextConfig *config)
70 {
71 InputMethod_CursorInfo *cursorInfo = nullptr;
72 EXPECT_EQ(IME_ERR_OK, OH_TextConfig_GetCursorInfo(config, &cursorInfo));
73 // test set and get cursorInfo rect
74 double expLeft = 1.1;
75 double expTop = 2.2;
76 double expWidth = 3.3;
77 double expHeight = 4.4;
78 EXPECT_EQ(IME_ERR_OK, OH_CursorInfo_SetRect(cursorInfo, expLeft, expTop, expWidth, expHeight));
79 double actLeft = 0.0;
80 double actTop = 0.0;
81 double actWidth = 0.0;
82 double actHeight = 0.0;
83 EXPECT_EQ(IME_ERR_OK, OH_CursorInfo_GetRect(cursorInfo, &actLeft, &actTop, &actWidth, &actHeight));
84 EXPECT_EQ(expLeft, actLeft);
85 EXPECT_EQ(expTop, actTop);
86 EXPECT_EQ(expWidth, actWidth);
87 EXPECT_EQ(expHeight, actHeight);
88 }
89
90 /**
91 * @tc.name: TestTextConfig_001
92 * @tc.desc: create and destroy TestTextConfig success
93 * @tc.type: FUNC
94 */
95 HWTEST_F(InputMethodControllerCapiTest, TestTextConfig_001, TestSize.Level0)
96 {
97 auto config = OH_TextConfig_Create();
98 ASSERT_NE(nullptr, config);
99
100 // test set and get inputType
101 InputMethod_TextInputType expInputType = IME_TEXT_INPUT_TYPE_NUMBER_DECIMAL;
102 InputMethod_TextInputType actInputType = IME_TEXT_INPUT_TYPE_NONE;
103 EXPECT_EQ(IME_ERR_OK, OH_TextConfig_SetInputType(config, expInputType));
104 EXPECT_EQ(IME_ERR_OK, OH_TextConfig_GetInputType(config, &actInputType));
105 EXPECT_EQ(expInputType, actInputType);
106
107 // test set and get enterKeyType
108 InputMethod_EnterKeyType expEnterKeyType = IME_ENTER_KEY_SEARCH;
109 EXPECT_EQ(IME_ERR_OK, OH_TextConfig_SetEnterKeyType(config, expEnterKeyType));
110 InputMethod_EnterKeyType actEnterKeyType = IME_ENTER_KEY_UNSPECIFIED;
111 EXPECT_EQ(IME_ERR_OK, OH_TextConfig_GetEnterKeyType(config, &actEnterKeyType));
112 EXPECT_EQ(expEnterKeyType, actEnterKeyType);
113
114 // test set and get isPreviewTextSupported
115 EXPECT_EQ(IME_ERR_OK, OH_TextConfig_SetPreviewTextSupport(config, true));
116 bool isPreviewTextSupported = false;
117 EXPECT_EQ(IME_ERR_OK, OH_TextConfig_IsPreviewTextSupported(config, &isPreviewTextSupported));
118 EXPECT_TRUE(isPreviewTextSupported);
119
120 // test set and get selection
121 int32_t expStart = 1;
122 int32_t expEnd = 2;
123 EXPECT_EQ(IME_ERR_OK, OH_TextConfig_SetSelection(config, expStart, expEnd));
124 int32_t actStart = 0;
125 int32_t actEnd = 0;
126 EXPECT_EQ(IME_ERR_OK, OH_TextConfig_GetSelection(config, &actStart, &actEnd));
127 EXPECT_EQ(expStart, actStart);
128 EXPECT_EQ(expEnd, actEnd);
129
130 // test set and get windowId
131 int32_t expWindowId = 1;
132 EXPECT_EQ(IME_ERR_OK, OH_TextConfig_SetWindowId(config, expWindowId));
133 int32_t actWindowId = 0;
134 EXPECT_EQ(IME_ERR_OK, OH_TextConfig_GetWindowId(config, &actWindowId));
135 EXPECT_EQ(expWindowId, actWindowId);
136
137 TestCursorInfoOfTextConfig(config);
138
139 InputMethod_TextAvoidInfo *textAvoidInfo = nullptr;
140 EXPECT_EQ(IME_ERR_OK, OH_TextConfig_GetTextAvoidInfo(config, &textAvoidInfo));
141
142 // test set and get text avoid info member
143 double expPositionY = 10.0;
144 double expHeight = 20.0;
145 EXPECT_EQ(IME_ERR_OK, OH_TextAvoidInfo_SetPositionY(textAvoidInfo, expPositionY));
146 EXPECT_EQ(IME_ERR_OK, OH_TextAvoidInfo_SetHeight(textAvoidInfo, expHeight));
147 double actPositionY = 0.0;
148 double actHeight = 0.0;
149 EXPECT_EQ(IME_ERR_OK, OH_TextAvoidInfo_GetPositionY(textAvoidInfo, &actPositionY));
150 EXPECT_EQ(IME_ERR_OK, OH_TextAvoidInfo_GetHeight(textAvoidInfo, &actHeight));
151 EXPECT_EQ(expPositionY, actPositionY);
152 EXPECT_EQ(expHeight, actHeight);
153
154 OH_TextConfig_Destroy(config);
155 }
156
157 /**
158 * @tc.name: TestTextConfig_002
159 * @tc.desc: create and destroy TestTextConfig success
160 * @tc.type: FUNC
161 */
162 HWTEST_F(InputMethodControllerCapiTest, TestTextConfig_002, TestSize.Level0)
163 {
164 auto config = OH_TextConfig_Create();
165 ASSERT_NE(nullptr, config);
166
167 // test set and get inputType
168 InputMethod_TextInputType expInputType = IME_TEXT_INPUT_TYPE_ONE_TIME_CODE;
169 InputMethod_TextInputType actInputType = IME_TEXT_INPUT_TYPE_NONE;
170 EXPECT_EQ(IME_ERR_OK, OH_TextConfig_SetInputType(config, expInputType));
171 EXPECT_EQ(IME_ERR_OK, OH_TextConfig_GetInputType(config, &actInputType));
172 EXPECT_EQ(expInputType, actInputType);
173 OH_TextConfig_Destroy(config);
174 }
175
GetTextConfigFunc(InputMethod_TextEditorProxy * proxy,InputMethod_TextConfig * config)176 void GetTextConfigFunc(InputMethod_TextEditorProxy *proxy, InputMethod_TextConfig *config) { }
InsertTextFunc(InputMethod_TextEditorProxy * proxy,const char16_t * text,size_t length)177 void InsertTextFunc(InputMethod_TextEditorProxy *proxy, const char16_t *text, size_t length) { }
DeleteForwardFunc(InputMethod_TextEditorProxy * proxy,int32_t length)178 void DeleteForwardFunc(InputMethod_TextEditorProxy *proxy, int32_t length) { }
DeleteBackwardFunc(InputMethod_TextEditorProxy * proxy,int32_t length)179 void DeleteBackwardFunc(InputMethod_TextEditorProxy *proxy, int32_t length) { }
SendKeyboardStatusFunc(InputMethod_TextEditorProxy * proxy,InputMethod_KeyboardStatus status)180 void SendKeyboardStatusFunc(InputMethod_TextEditorProxy *proxy, InputMethod_KeyboardStatus status) { }
SendEnterKeyFunc(InputMethod_TextEditorProxy * proxy,InputMethod_EnterKeyType type)181 void SendEnterKeyFunc(InputMethod_TextEditorProxy *proxy, InputMethod_EnterKeyType type) { }
MoveCursorFunc(InputMethod_TextEditorProxy * proxy,InputMethod_Direction direction)182 void MoveCursorFunc(InputMethod_TextEditorProxy *proxy, InputMethod_Direction direction) { }
HandleSetSelectionFunc(InputMethod_TextEditorProxy * proxy,int32_t start,int32_t end)183 void HandleSetSelectionFunc(InputMethod_TextEditorProxy *proxy, int32_t start, int32_t end) { }
HandleExtendActionFunc(InputMethod_TextEditorProxy * proxy,InputMethod_ExtendAction action)184 void HandleExtendActionFunc(InputMethod_TextEditorProxy *proxy, InputMethod_ExtendAction action) { }
GetleftTextOfCursorFunc(InputMethod_TextEditorProxy * proxy,int32_t number,char16_t text[],size_t * length)185 void GetleftTextOfCursorFunc(InputMethod_TextEditorProxy *proxy, int32_t number, char16_t text[], size_t *length) { }
GetRightTextOfCursorFunc(InputMethod_TextEditorProxy * proxy,int32_t number,char16_t text[],size_t * length)186 void GetRightTextOfCursorFunc(InputMethod_TextEditorProxy *proxy, int32_t number, char16_t text[], size_t *length) { }
GetTextIndexAtCursorFunc(InputMethod_TextEditorProxy * proxy)187 int32_t GetTextIndexAtCursorFunc(InputMethod_TextEditorProxy *proxy)
188 {
189 return 0;
190 }
ReceivePrivateCommandFunc(InputMethod_TextEditorProxy * proxy,InputMethod_PrivateCommand * privateCommand[],size_t size)191 int32_t ReceivePrivateCommandFunc(
192 InputMethod_TextEditorProxy *proxy, InputMethod_PrivateCommand *privateCommand[], size_t size)
193 {
194 return 0;
195 }
SetPreviewTextFunc(InputMethod_TextEditorProxy * proxy,const char16_t * text,size_t length,int32_t start,int32_t end)196 int32_t SetPreviewTextFunc(
197 InputMethod_TextEditorProxy *proxy, const char16_t *text, size_t length, int32_t start, int32_t end)
198 {
199 return 0;
200 }
FinishTextPreviewFunc(InputMethod_TextEditorProxy * proxy)201 void FinishTextPreviewFunc(InputMethod_TextEditorProxy *proxy) { }
ConstructTextEditorProxy(InputMethod_TextEditorProxy * textEditorProxy)202 static void ConstructTextEditorProxy(InputMethod_TextEditorProxy *textEditorProxy)
203 {
204 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetGetTextConfigFunc(textEditorProxy, GetTextConfigFunc));
205 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetInsertTextFunc(textEditorProxy, InsertTextFunc));
206 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetDeleteForwardFunc(textEditorProxy, DeleteForwardFunc));
207 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetDeleteBackwardFunc(textEditorProxy, DeleteBackwardFunc));
208 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetSendKeyboardStatusFunc(textEditorProxy, SendKeyboardStatusFunc));
209 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetSendEnterKeyFunc(textEditorProxy, SendEnterKeyFunc));
210 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetMoveCursorFunc(textEditorProxy, MoveCursorFunc));
211 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetHandleSetSelectionFunc(textEditorProxy, HandleSetSelectionFunc));
212 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetHandleExtendActionFunc(textEditorProxy, HandleExtendActionFunc));
213 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetGetLeftTextOfCursorFunc(textEditorProxy, GetleftTextOfCursorFunc));
214 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetGetRightTextOfCursorFunc(textEditorProxy, GetRightTextOfCursorFunc));
215 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetGetTextIndexAtCursorFunc(textEditorProxy, GetTextIndexAtCursorFunc));
216 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetReceivePrivateCommandFunc(textEditorProxy, ReceivePrivateCommandFunc));
217 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetSetPreviewTextFunc(textEditorProxy, SetPreviewTextFunc));
218 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetFinishTextPreviewFunc(textEditorProxy, FinishTextPreviewFunc));
219 }
220
TestGetTextEditorProxyMember(InputMethod_TextEditorProxy * textEditorProxy)221 static void TestGetTextEditorProxyMember(InputMethod_TextEditorProxy *textEditorProxy)
222 {
223 OH_TextEditorProxy_GetTextConfigFunc getTextCOnfigFunc = nullptr;
224 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_GetGetTextConfigFunc(textEditorProxy, &getTextCOnfigFunc));
225 EXPECT_EQ(GetTextConfigFunc, getTextCOnfigFunc);
226
227 OH_TextEditorProxy_InsertTextFunc insertTextFunc = nullptr;
228 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_GetInsertTextFunc(textEditorProxy, &insertTextFunc));
229 EXPECT_EQ(InsertTextFunc, insertTextFunc);
230
231 OH_TextEditorProxy_DeleteForwardFunc deleteForwardFunc = nullptr;
232 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_GetDeleteForwardFunc(textEditorProxy, &deleteForwardFunc));
233 EXPECT_EQ(DeleteForwardFunc, deleteForwardFunc);
234
235 OH_TextEditorProxy_DeleteBackwardFunc deleteBackwardFunc = nullptr;
236 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_GetDeleteBackwardFunc(textEditorProxy, &deleteBackwardFunc));
237 EXPECT_EQ(DeleteBackwardFunc, deleteBackwardFunc);
238
239 OH_TextEditorProxy_SendKeyboardStatusFunc sendKeyboardStatusFunc = nullptr;
240 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_GetSendKeyboardStatusFunc(textEditorProxy, &sendKeyboardStatusFunc));
241 EXPECT_EQ(SendKeyboardStatusFunc, sendKeyboardStatusFunc);
242
243 OH_TextEditorProxy_SendEnterKeyFunc sendEnterKeyFunc = nullptr;
244 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_GetSendEnterKeyFunc(textEditorProxy, &sendEnterKeyFunc));
245 EXPECT_EQ(SendEnterKeyFunc, sendEnterKeyFunc);
246
247 OH_TextEditorProxy_MoveCursorFunc moveCursorFunc = nullptr;
248 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_GetMoveCursorFunc(textEditorProxy, &moveCursorFunc));
249 EXPECT_EQ(MoveCursorFunc, moveCursorFunc);
250
251 OH_TextEditorProxy_HandleSetSelectionFunc handleSetSelectionFunc = nullptr;
252 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_GetHandleSetSelectionFunc(textEditorProxy, &handleSetSelectionFunc));
253 EXPECT_EQ(HandleSetSelectionFunc, handleSetSelectionFunc);
254
255 OH_TextEditorProxy_HandleExtendActionFunc handleExtendActionFunc = nullptr;
256 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_GetHandleExtendActionFunc(textEditorProxy, &handleExtendActionFunc));
257 EXPECT_EQ(HandleExtendActionFunc, handleExtendActionFunc);
258
259 OH_TextEditorProxy_GetLeftTextOfCursorFunc getLeftTextOfCursorFunc = nullptr;
260 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_GetGetLeftTextOfCursorFunc(textEditorProxy, &getLeftTextOfCursorFunc));
261 EXPECT_EQ(GetleftTextOfCursorFunc, getLeftTextOfCursorFunc);
262
263 OH_TextEditorProxy_GetRightTextOfCursorFunc getRightTextOfCursorFunc = nullptr;
264 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_GetGetRightTextOfCursorFunc(textEditorProxy, &getRightTextOfCursorFunc));
265 EXPECT_EQ(GetRightTextOfCursorFunc, getRightTextOfCursorFunc);
266
267 OH_TextEditorProxy_GetTextIndexAtCursorFunc getTextIndexAtCursorFunc = nullptr;
268 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_GetGetTextIndexAtCursorFunc(textEditorProxy, &getTextIndexAtCursorFunc));
269 EXPECT_EQ(GetTextIndexAtCursorFunc, getTextIndexAtCursorFunc);
270
271 OH_TextEditorProxy_ReceivePrivateCommandFunc receivePrivateCommandFunc = nullptr;
272 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_GetReceivePrivateCommandFunc(textEditorProxy, &receivePrivateCommandFunc));
273 EXPECT_EQ(ReceivePrivateCommandFunc, receivePrivateCommandFunc);
274
275 OH_TextEditorProxy_SetPreviewTextFunc setPreviewTextFunc = nullptr;
276 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_GetSetPreviewTextFunc(textEditorProxy, &setPreviewTextFunc));
277 EXPECT_EQ(SetPreviewTextFunc, setPreviewTextFunc);
278
279 OH_TextEditorProxy_FinishTextPreviewFunc finishTextPreviewFunc = nullptr;
280 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_GetFinishTextPreviewFunc(textEditorProxy, &finishTextPreviewFunc));
281 EXPECT_EQ(FinishTextPreviewFunc, finishTextPreviewFunc);
282 }
283
284 /**
285 * @tc.name: TextEditorProxy_001
286 * @tc.desc: create and destroy TextEditorProxy success
287 * @tc.type: FUNC
288 */
289 HWTEST_F(InputMethodControllerCapiTest, TextEditorProxy_001, TestSize.Level0)
290 {
291 auto textEditorProxy = OH_TextEditorProxy_Create();
292 ASSERT_NE(nullptr, textEditorProxy);
293 ConstructTextEditorProxy(textEditorProxy);
294 TestGetTextEditorProxyMember(textEditorProxy);
295 OH_TextEditorProxy_Destroy(textEditorProxy);
296 }
297
298 /**
299 * @tc.name: AttachOptions_001
300 * @tc.desc: create and destroy AttachOptions success
301 * @tc.type: FUNC
302 */
303 HWTEST_F(InputMethodControllerCapiTest, AttachOptions_001, TestSize.Level0)
304 {
305 auto options = OH_AttachOptions_Create(true);
306 ASSERT_NE(nullptr, options);
307
308 bool showKeyboard = false;
309 EXPECT_EQ(IME_ERR_OK, OH_AttachOptions_IsShowKeyboard(options, &showKeyboard));
310 EXPECT_TRUE(showKeyboard);
311 OH_AttachOptions_Destroy(options);
312 }
313
314 /**
315 * @tc.name: TextAvoidInfo_001
316 * @tc.desc: create and destroy TextAvoidInfo success
317 * @tc.type: FUNC
318 */
319 HWTEST_F(InputMethodControllerCapiTest, TextAvoidInfo_001, TestSize.Level0)
320 {
321 double expPositionY = 1.1;
322 double expHeight = 1.2;
323 auto avoidInfo = OH_TextAvoidInfo_Create(expPositionY, expHeight);
324 ASSERT_NE(nullptr, avoidInfo);
325
326 double actPositionY = 0.0;
327 double actHeight = 0.0;
328 EXPECT_EQ(IME_ERR_OK, OH_TextAvoidInfo_GetPositionY(avoidInfo, &actPositionY));
329 EXPECT_EQ(IME_ERR_OK, OH_TextAvoidInfo_GetHeight(avoidInfo, &actHeight));
330 EXPECT_EQ(expPositionY, actPositionY);
331 EXPECT_EQ(expHeight, actHeight);
332
333 // test set positionY and height
334 expPositionY = 2.1;
335 expHeight = 2.2;
336 EXPECT_EQ(IME_ERR_OK, OH_TextAvoidInfo_SetPositionY(avoidInfo, expPositionY));
337 EXPECT_EQ(IME_ERR_OK, OH_TextAvoidInfo_SetHeight(avoidInfo, expHeight));
338 EXPECT_EQ(IME_ERR_OK, OH_TextAvoidInfo_GetPositionY(avoidInfo, &actPositionY));
339 EXPECT_EQ(IME_ERR_OK, OH_TextAvoidInfo_GetHeight(avoidInfo, &actHeight));
340 EXPECT_EQ(expPositionY, actPositionY);
341 EXPECT_EQ(expHeight, actHeight);
342
343 OH_TextAvoidInfo_Destroy(avoidInfo);
344 }
345
346 /**
347 * @tc.name: PrivateCommand_001
348 * @tc.desc: create and destroy PrivateCommand success
349 * @tc.type: FUNC
350 */
351 HWTEST_F(InputMethodControllerCapiTest, PrivateCommand_001, TestSize.Level0)
352 {
353 std::string key = "key";
354 auto privateCommand = OH_PrivateCommand_Create(const_cast<char *>(key.c_str()), key.length());
355 ASSERT_NE(nullptr, privateCommand);
356
357 // test set bool value
358 EXPECT_EQ(IME_ERR_OK, OH_PrivateCommand_SetBoolValue(privateCommand, true));
359 bool actBoolValue = false;
360 EXPECT_EQ(IME_ERR_OK, OH_PrivateCommand_GetBoolValue(privateCommand, &actBoolValue));
361 EXPECT_TRUE(actBoolValue);
362
363 // test set int value
364 int32_t expIntValue = 1;
365 EXPECT_EQ(IME_ERR_OK, OH_PrivateCommand_SetIntValue(privateCommand, expIntValue));
366 int32_t actIntValue = 0;
367 EXPECT_EQ(IME_ERR_OK, OH_PrivateCommand_GetIntValue(privateCommand, &actIntValue));
368 EXPECT_EQ(expIntValue, actIntValue);
369
370 // test set string value
371 std::string expStrValue = "string";
372 EXPECT_EQ(IME_ERR_OK,
373 OH_PrivateCommand_SetStrValue(privateCommand, const_cast<char *>(expStrValue.c_str()), expStrValue.length()));
374 const char *actStrValue = nullptr;
375 size_t actStrValueLength = 0;
376 EXPECT_EQ(IME_ERR_OK, OH_PrivateCommand_GetStrValue(privateCommand, &actStrValue, &actStrValueLength));
377 EXPECT_EQ(expStrValue, std::string(actStrValue, actStrValueLength));
378
379 // test get value type
380 InputMethod_CommandValueType valueType = IME_COMMAND_VALUE_TYPE_NONE;
381 EXPECT_EQ(IME_ERR_OK, OH_PrivateCommand_GetValueType(privateCommand, &valueType));
382 EXPECT_EQ(IME_COMMAND_VALUE_TYPE_STRING, valueType);
383
384 // test get and set key
385 const char *actStrKey = nullptr;
386 size_t actStrKeyLength = 0;
387 EXPECT_EQ(IME_ERR_OK, OH_PrivateCommand_GetKey(privateCommand, &actStrKey, &actStrKeyLength));
388 EXPECT_EQ(key, std::string(actStrKey, actStrKeyLength));
389 std::string newKey = "newKey";
390 EXPECT_EQ(
391 IME_ERR_OK, OH_PrivateCommand_SetKey(privateCommand, const_cast<char *>(newKey.c_str()), newKey.length()));
392 EXPECT_EQ(IME_ERR_OK, OH_PrivateCommand_GetKey(privateCommand, &actStrKey, &actStrKeyLength));
393 EXPECT_EQ(newKey, std::string(actStrKey, actStrKeyLength));
394 OH_PrivateCommand_Destroy(privateCommand);
395 }
396 /**
397 * @tc.name: OH_CursorInfo_SetRect_001
398 * @tc.desc: input parameters is nullptr
399 * @tc.type: FUNC
400 */
401 HWTEST_F(InputMethodControllerCapiTest, OH_CursorInfo_SetRect_001, TestSize.Level0)
402 {
403 double left = 0;
404 double top = 0;
405 double width = 0;
406 double height = 0;
407 auto ret = OH_CursorInfo_SetRect(nullptr, left, top, width, height);
408 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
409 }
410
411 /**
412 * @tc.name: OH_CursorInfo_GetRect_001
413 * @tc.desc: input parameters is nullptr
414 * @tc.type: FUNC
415 */
416 HWTEST_F(InputMethodControllerCapiTest, OH_CursorInfo_GetRect_001, TestSize.Level0)
417 {
418 double left = 0;
419 double top = 0;
420 double width = 0;
421 double height = 0;
422 auto ret = OH_CursorInfo_GetRect(nullptr, nullptr, nullptr, nullptr, nullptr);
423 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
424
425 auto info = OH_CursorInfo_Create(left, top, width, height);
426 ret = OH_CursorInfo_GetRect(info, nullptr, nullptr, nullptr, nullptr);
427 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
428 ret = OH_CursorInfo_GetRect(info, &left, nullptr, nullptr, nullptr);
429 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
430 ret = OH_CursorInfo_GetRect(info, &left, &top, nullptr, nullptr);
431 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
432 ret = OH_CursorInfo_GetRect(info, &left, &top, &width, nullptr);
433 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
434 OH_CursorInfo_Destroy(info);
435 }
436
437 /**
438 * @tc.name: OH_TextConfig_SetInputType_001
439 * @tc.desc: input parameters is nullptr
440 * @tc.type: FUNC
441 */
442 HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetInputType_001, TestSize.Level0)
443 {
444 InputMethod_TextInputType inputType = IME_TEXT_INPUT_TYPE_TEXT;
445 auto ret = OH_TextConfig_SetInputType(nullptr, inputType);
446 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
447 }
448
449 /**
450 * @tc.name: OH_TextConfig_SetEnterKeyType_001
451 * @tc.desc: input parameters is nullptr
452 * @tc.type: FUNC
453 */
454 HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetEnterKeyType_001, TestSize.Level0)
455 {
456 InputMethod_EnterKeyType enterKeyType = IME_ENTER_KEY_UNSPECIFIED;
457 auto ret = OH_TextConfig_SetEnterKeyType(nullptr, enterKeyType);
458 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
459 }
460
461 /**
462 * @tc.name: OH_TextConfig_SetPreviewTextSupport_001
463 * @tc.desc: input parameters is nullptr
464 * @tc.type: FUNC
465 */
466 HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetPreviewTextSupport_001, TestSize.Level0)
467 {
468 bool supported = false;
469 auto ret = OH_TextConfig_SetPreviewTextSupport(nullptr, supported);
470 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
471 }
472
473 /**
474 * @tc.name: OH_TextConfig_SetSelection_001
475 * @tc.desc: input parameters is nullptr
476 * @tc.type: FUNC
477 */
478 HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetSelection_001, TestSize.Level0)
479 {
480 int32_t start = 0;
481 int32_t end = 0;
482 auto ret = OH_TextConfig_SetSelection(nullptr, start, end);
483 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
484 }
485
486 /**
487 * @tc.name: OH_TextConfig_SetWindowId_001
488 * @tc.desc: input parameters is nullptr
489 * @tc.type: FUNC
490 */
491 HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetWindowId_001, TestSize.Level0)
492 {
493 int32_t windowId = 0;
494 auto ret = OH_TextConfig_SetWindowId(nullptr, windowId);
495 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
496 }
497
498 /**
499 * @tc.name: OH_TextConfig_GetInputType_001
500 * @tc.desc: input parameters is nullptr
501 * @tc.type: FUNC
502 */
503 HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_GetInputType_001, TestSize.Level0)
504 {
505 auto ret = OH_TextConfig_GetInputType(nullptr, nullptr);
506 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
507 InputMethod_TextConfig *config = OH_TextConfig_Create();
508 ASSERT_NE(config, nullptr);
509 ret = OH_TextConfig_GetInputType(config, nullptr);
510 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
511 OH_TextConfig_Destroy(config);
512 }
513
514 /**
515 * @tc.name: OH_TextConfig_GetEnterKeyType_001
516 * @tc.desc: input parameters is nullptr
517 * @tc.type: FUNC
518 */
519 HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_GetEnterKeyType_001, TestSize.Level0)
520 {
521 auto ret = OH_TextConfig_GetEnterKeyType(nullptr, nullptr);
522 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
523 InputMethod_TextConfig *config = OH_TextConfig_Create();
524 ASSERT_NE(config, nullptr);
525 ret = OH_TextConfig_GetEnterKeyType(config, nullptr);
526 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
527 OH_TextConfig_Destroy(config);
528 }
529
530 /**
531 * @tc.name: OH_TextConfig_IsPreviewTextSupported_001
532 * @tc.desc: input parameters is nullptr
533 * @tc.type: FUNC
534 */
535 HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_IsPreviewTextSupported_001, TestSize.Level0)
536 {
537 auto ret = OH_TextConfig_IsPreviewTextSupported(nullptr, nullptr);
538 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
539 InputMethod_TextConfig *config = OH_TextConfig_Create();
540 ASSERT_NE(config, nullptr);
541 ret = OH_TextConfig_IsPreviewTextSupported(config, nullptr);
542 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
543 OH_TextConfig_Destroy(config);
544 }
545
546 /**
547 * @tc.name: OH_TextConfig_GetCursorInfo_001
548 * @tc.desc: input parameters is nullptr
549 * @tc.type: FUNC
550 */
551 HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_GetCursorInfo_001, TestSize.Level0)
552 {
553 auto ret = OH_TextConfig_GetCursorInfo(nullptr, nullptr);
554 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
555 InputMethod_TextConfig *config = OH_TextConfig_Create();
556 ASSERT_NE(config, nullptr);
557 ret = OH_TextConfig_GetCursorInfo(config, nullptr);
558 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
559 OH_TextConfig_Destroy(config);
560 }
561
562 /**
563 * @tc.name: OH_TextConfig_GetTextAvoidInfo_001
564 * @tc.desc: input parameters is nullptr
565 * @tc.type: FUNC
566 */
567 HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_GetTextAvoidInfo_001, TestSize.Level0)
568 {
569 auto ret = OH_TextConfig_GetTextAvoidInfo(nullptr, nullptr);
570 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
571 InputMethod_TextConfig *config = OH_TextConfig_Create();
572 ASSERT_NE(config, nullptr);
573 ret = OH_TextConfig_GetTextAvoidInfo(config, nullptr);
574 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
575 OH_TextConfig_Destroy(config);
576 }
577
578 /**
579 * @tc.name: OH_TextConfig_GetSelection_001
580 * @tc.desc: input parameters is nullptr
581 * @tc.type: FUNC
582 */
583 HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_GetSelection_001, TestSize.Level0)
584 {
585 auto ret = OH_TextConfig_GetSelection(nullptr, nullptr, nullptr);
586 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
587 InputMethod_TextConfig *config = OH_TextConfig_Create();
588 ASSERT_NE(config, nullptr);
589 ret = OH_TextConfig_GetSelection(config, nullptr, nullptr);
590 EXPECT_EQ(IME_ERR_NULL_POINTER, ret);
591 int32_t start = 0;
592 ret = OH_TextConfig_GetSelection(config, &start, nullptr);
593 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
594 OH_TextConfig_Destroy(config);
595 }
596
597 /**
598 * @tc.name: OH_TextConfig_GetWindowId_001
599 * @tc.desc: input parameters is nullptr
600 * @tc.type: FUNC
601 */
602 HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_GetWindowId_001, TestSize.Level0)
603 {
604 auto ret = OH_TextConfig_GetWindowId(nullptr, nullptr);
605 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
606 InputMethod_TextConfig *config = OH_TextConfig_Create();
607 ASSERT_NE(config, nullptr);
608 ret = OH_TextConfig_GetWindowId(config, nullptr);
609 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
610 OH_TextConfig_Destroy(config);
611 }
612
613 /**
614 * @tc.name: OH_TextEditorProxy_SetGetTextConfigFunc_001
615 * @tc.desc: input parameters is nullptr
616 * @tc.type: FUNC
617 */
618 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_SetGetTextConfigFunc_001, TestSize.Level0)
619 {
620 auto ret = OH_TextEditorProxy_SetGetTextConfigFunc(nullptr, nullptr);
621 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
622 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
623 ASSERT_NE(proxy, nullptr);
624 ret = OH_TextEditorProxy_SetGetTextConfigFunc(proxy, nullptr);
625 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
626 OH_TextEditorProxy_Destroy(proxy);
627 }
628
629 /**
630 * @tc.name: OH_TextEditorProxy_SetInsertTextFunc_001
631 * @tc.desc: input parameters is nullptr
632 * @tc.type: FUNC
633 */
634 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_SetInsertTextFunc_001, TestSize.Level0)
635 {
636 auto ret = OH_TextEditorProxy_SetInsertTextFunc(nullptr, nullptr);
637 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
638 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
639 ASSERT_NE(proxy, nullptr);
640 ret = OH_TextEditorProxy_SetInsertTextFunc(proxy, nullptr);
641 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
642 OH_TextEditorProxy_Destroy(proxy);
643 }
644
645 /**
646 * @tc.name: OH_TextEditorProxy_SetDeleteForwardFunc_001
647 * @tc.desc: input parameters is nullptr
648 * @tc.type: FUNC
649 */
650 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_SetDeleteForwardFunc_001, TestSize.Level0)
651 {
652 auto ret = OH_TextEditorProxy_SetDeleteForwardFunc(nullptr, nullptr);
653 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
654 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
655 ASSERT_NE(proxy, nullptr);
656 ret = OH_TextEditorProxy_SetDeleteForwardFunc(proxy, nullptr);
657 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
658 OH_TextEditorProxy_Destroy(proxy);
659 }
660
661 /**
662 * @tc.name: OH_TextEditorProxy_SetDeleteBackwardFunc_001
663 * @tc.desc: input parameters is nullptr
664 * @tc.type: FUNC
665 */
666 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_SetDeleteBackwardFunc_001, TestSize.Level0)
667 {
668 auto ret = OH_TextEditorProxy_SetDeleteBackwardFunc(nullptr, nullptr);
669 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
670 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
671 ASSERT_NE(proxy, nullptr);
672 ret = OH_TextEditorProxy_SetDeleteBackwardFunc(proxy, nullptr);
673 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
674 OH_TextEditorProxy_Destroy(proxy);
675 }
676
677 /**
678 * @tc.name: OH_TextEditorProxy_SetSendKeyboardStatusFunc_001
679 * @tc.desc: input parameters is nullptr
680 * @tc.type: FUNC
681 */
682 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_SetSendKeyboardStatusFunc_001, TestSize.Level0)
683 {
684 auto ret = OH_TextEditorProxy_SetSendKeyboardStatusFunc(nullptr, nullptr);
685 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
686 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
687 ASSERT_NE(proxy, nullptr);
688 ret = OH_TextEditorProxy_SetSendKeyboardStatusFunc(proxy, nullptr);
689 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
690 OH_TextEditorProxy_Destroy(proxy);
691 }
692
693 /**
694 * @tc.name: OH_TextEditorProxy_SetSendEnterKeyFunc_001
695 * @tc.desc: input parameters is nullptr
696 * @tc.type: FUNC
697 */
698 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_SetSendEnterKeyFunc_001, TestSize.Level0)
699 {
700 auto ret = OH_TextEditorProxy_SetSendEnterKeyFunc(nullptr, nullptr);
701 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
702 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
703 ASSERT_NE(proxy, nullptr);
704 ret = OH_TextEditorProxy_SetSendEnterKeyFunc(proxy, nullptr);
705 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
706 OH_TextEditorProxy_Destroy(proxy);
707 }
708
709 /**
710 * @tc.name: OH_TextEditorProxy_SetMoveCursorFunc_001
711 * @tc.desc: input parameters is nullptr
712 * @tc.type: FUNC
713 */
714 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_SetMoveCursorFunc_001, TestSize.Level0)
715 {
716 auto ret = OH_TextEditorProxy_SetMoveCursorFunc(nullptr, nullptr);
717 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
718 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
719 ASSERT_NE(proxy, nullptr);
720 ret = OH_TextEditorProxy_SetMoveCursorFunc(proxy, nullptr);
721 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
722 OH_TextEditorProxy_Destroy(proxy);
723 }
724
725 /**
726 * @tc.name: OH_TextEditorProxy_SetHandleSetSelectionFunc_001
727 * @tc.desc: input parameters is nullptr
728 * @tc.type: FUNC
729 */
730 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_SetHandleSetSelectionFunc_001, TestSize.Level0)
731 {
732 auto ret = OH_TextEditorProxy_SetHandleSetSelectionFunc(nullptr, nullptr);
733 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
734 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
735 ASSERT_NE(proxy, nullptr);
736 ret = OH_TextEditorProxy_SetHandleSetSelectionFunc(proxy, nullptr);
737 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
738 OH_TextEditorProxy_Destroy(proxy);
739 }
740
741 /**
742 * @tc.name: OH_TextEditorProxy_SetHandleExtendActionFunc_001
743 * @tc.desc: input parameters is nullptr
744 * @tc.type: FUNC
745 */
746 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_SetHandleExtendActionFunc_001, TestSize.Level0)
747 {
748 auto ret = OH_TextEditorProxy_SetHandleExtendActionFunc(nullptr, nullptr);
749 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
750 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
751 ASSERT_NE(proxy, nullptr);
752 ret = OH_TextEditorProxy_SetHandleExtendActionFunc(proxy, nullptr);
753 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
754 OH_TextEditorProxy_Destroy(proxy);
755 }
756
757 /**
758 * @tc.name: OH_TextEditorProxy_SetGetLeftTextOfCursorFunc_001
759 * @tc.desc: input parameters is nullptr
760 * @tc.type: FUNC
761 */
762 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_SetGetLeftTextOfCursorFunc_001, TestSize.Level0)
763 {
764 auto ret = OH_TextEditorProxy_SetGetLeftTextOfCursorFunc(nullptr, nullptr);
765 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
766 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
767 ASSERT_NE(proxy, nullptr);
768 ret = OH_TextEditorProxy_SetGetLeftTextOfCursorFunc(proxy, nullptr);
769 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
770 OH_TextEditorProxy_Destroy(proxy);
771 }
772
773 /**
774 * @tc.name: OH_TextEditorProxy_SetGetRightTextOfCursorFunc_001
775 * @tc.desc: input parameters is nullptr
776 * @tc.type: FUNC
777 */
778 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_SetGetRightTextOfCursorFunc_001, TestSize.Level0)
779 {
780 auto ret = OH_TextEditorProxy_SetGetRightTextOfCursorFunc(nullptr, nullptr);
781 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
782 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
783 ASSERT_NE(proxy, nullptr);
784 ret = OH_TextEditorProxy_SetGetRightTextOfCursorFunc(proxy, nullptr);
785 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
786 OH_TextEditorProxy_Destroy(proxy);
787 }
788
789 /**
790 * @tc.name: OH_TextEditorProxy_SetGetTextIndexAtCursorFunc_001
791 * @tc.desc: input parameters is nullptr
792 * @tc.type: FUNC
793 */
794 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_SetGetTextIndexAtCursorFunc_001, TestSize.Level0)
795 {
796 auto ret = OH_TextEditorProxy_SetGetTextIndexAtCursorFunc(nullptr, nullptr);
797 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
798 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
799 ASSERT_NE(proxy, nullptr);
800 ret = OH_TextEditorProxy_SetGetTextIndexAtCursorFunc(proxy, nullptr);
801 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
802 OH_TextEditorProxy_Destroy(proxy);
803 }
804
805 /**
806 * @tc.name: OH_TextEditorProxy_SetReceivePrivateCommandFunc_001
807 * @tc.desc: input parameters is nullptr
808 * @tc.type: FUNC
809 */
810 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_SetReceivePrivateCommandFunc_001, TestSize.Level0)
811 {
812 auto ret = OH_TextEditorProxy_SetReceivePrivateCommandFunc(nullptr, nullptr);
813 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
814 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
815 ASSERT_NE(proxy, nullptr);
816 ret = OH_TextEditorProxy_SetReceivePrivateCommandFunc(proxy, nullptr);
817 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
818 OH_TextEditorProxy_Destroy(proxy);
819 }
820
821 /**
822 * @tc.name: OH_TextEditorProxy_SetSetPreviewTextFunc_001
823 * @tc.desc: input parameters is nullptr
824 * @tc.type: FUNC
825 */
826 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_SetSetPreviewTextFunc_001, TestSize.Level0)
827 {
828 auto ret = OH_TextEditorProxy_SetSetPreviewTextFunc(nullptr, nullptr);
829 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
830 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
831 ASSERT_NE(proxy, nullptr);
832 ret = OH_TextEditorProxy_SetSetPreviewTextFunc(proxy, nullptr);
833 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
834 OH_TextEditorProxy_Destroy(proxy);
835 }
836
837 /**
838 * @tc.name: OH_TextEditorProxy_SetFinishTextPreviewFunc_001
839 * @tc.desc: input parameters is nullptr
840 * @tc.type: FUNC
841 */
842 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_SetFinishTextPreviewFunc_001, TestSize.Level0)
843 {
844 auto ret = OH_TextEditorProxy_SetFinishTextPreviewFunc(nullptr, nullptr);
845 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
846 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
847 ASSERT_NE(proxy, nullptr);
848 ret = OH_TextEditorProxy_SetFinishTextPreviewFunc(proxy, nullptr);
849 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
850 OH_TextEditorProxy_Destroy(proxy);
851 }
852
853 /**
854 * @tc.name: OH_TextEditorProxy_GetGetTextConfigFunc_001
855 * @tc.desc: input parameters is nullptr
856 * @tc.type: FUNC
857 */
858 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_GetGetTextConfigFunc_001, TestSize.Level0)
859 {
860 auto ret = OH_TextEditorProxy_GetGetTextConfigFunc(nullptr, nullptr);
861 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
862 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
863 ASSERT_NE(proxy, nullptr);
864 ret = OH_TextEditorProxy_GetGetTextConfigFunc(proxy, nullptr);
865 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
866 OH_TextEditorProxy_Destroy(proxy);
867 }
868
869 /**
870 * @tc.name: OH_TextEditorProxy_GetInsertTextFunc_001
871 * @tc.desc: input parameters is nullptr
872 * @tc.type: FUNC
873 */
874 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_GetInsertTextFunc_001, TestSize.Level0)
875 {
876 auto ret = OH_TextEditorProxy_GetInsertTextFunc(nullptr, nullptr);
877 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
878 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
879 ASSERT_NE(proxy, nullptr);
880 ret = OH_TextEditorProxy_GetInsertTextFunc(proxy, nullptr);
881 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
882 OH_TextEditorProxy_Destroy(proxy);
883 }
884
885 /**
886 * @tc.name: OH_TextEditorProxy_GetDeleteForwardFunc_001
887 * @tc.desc: input parameters is nullptr
888 * @tc.type: FUNC
889 */
890 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_GetDeleteForwardFunc_001, TestSize.Level0)
891 {
892 auto ret = OH_TextEditorProxy_GetDeleteForwardFunc(nullptr, nullptr);
893 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
894 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
895 ASSERT_NE(proxy, nullptr);
896 ret = OH_TextEditorProxy_GetDeleteForwardFunc(proxy, nullptr);
897 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
898 OH_TextEditorProxy_Destroy(proxy);
899 }
900
901 /**
902 * @tc.name: OH_TextEditorProxy_GetDeleteBackwardFunc_001
903 * @tc.desc: input parameters is nullptr
904 * @tc.type: FUNC
905 */
906 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_GetDeleteBackwardFunc_001, TestSize.Level0)
907 {
908 auto ret = OH_TextEditorProxy_GetDeleteBackwardFunc(nullptr, nullptr);
909 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
910 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
911 ASSERT_NE(proxy, nullptr);
912 ret = OH_TextEditorProxy_GetDeleteBackwardFunc(proxy, nullptr);
913 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
914 OH_TextEditorProxy_Destroy(proxy);
915 }
916
917 /**
918 * @tc.name: OH_TextEditorProxy_GetSendKeyboardStatusFunc_001
919 * @tc.desc: input parameters is nullptr
920 * @tc.type: FUNC
921 */
922 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_GetSendKeyboardStatusFunc_001, TestSize.Level0)
923 {
924 auto ret = OH_TextEditorProxy_GetSendKeyboardStatusFunc(nullptr, nullptr);
925 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
926 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
927 ASSERT_NE(proxy, nullptr);
928 ret = OH_TextEditorProxy_GetSendKeyboardStatusFunc(proxy, nullptr);
929 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
930 OH_TextEditorProxy_Destroy(proxy);
931 }
932
933 /**
934 * @tc.name: OH_TextEditorProxy_GetSendEnterKeyFunc_001
935 * @tc.desc: input parameters is nullptr
936 * @tc.type: FUNC
937 */
938 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_GetSendEnterKeyFunc_001, TestSize.Level0)
939 {
940 auto ret = OH_TextEditorProxy_GetSendEnterKeyFunc(nullptr, nullptr);
941 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
942 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
943 ASSERT_NE(proxy, nullptr);
944 ret = OH_TextEditorProxy_GetSendEnterKeyFunc(proxy, nullptr);
945 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
946 OH_TextEditorProxy_Destroy(proxy);
947 }
948
949 /**
950 * @tc.name: OH_TextEditorProxy_GetMoveCursorFunc_001
951 * @tc.desc: input parameters is nullptr
952 * @tc.type: FUNC
953 */
954 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_GetMoveCursorFunc_001, TestSize.Level0)
955 {
956 auto ret = OH_TextEditorProxy_GetMoveCursorFunc(nullptr, nullptr);
957 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
958 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
959 ASSERT_NE(proxy, nullptr);
960 ret = OH_TextEditorProxy_GetMoveCursorFunc(proxy, nullptr);
961 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
962 OH_TextEditorProxy_Destroy(proxy);
963 }
964
965 /**
966 * @tc.name: OH_TextEditorProxy_GetHandleSetSelectionFunc_001
967 * @tc.desc: input parameters is nullptr
968 * @tc.type: FUNC
969 */
970 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_GetHandleSetSelectionFunc_001, TestSize.Level0)
971 {
972 auto ret = OH_TextEditorProxy_GetHandleSetSelectionFunc(nullptr, nullptr);
973 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
974 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
975 ASSERT_NE(proxy, nullptr);
976 ret = OH_TextEditorProxy_GetHandleSetSelectionFunc(proxy, nullptr);
977 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
978 OH_TextEditorProxy_Destroy(proxy);
979 }
980
981 /**
982 * @tc.name: OH_TextEditorProxy_GetHandleExtendActionFunc_001
983 * @tc.desc: input parameters is nullptr
984 * @tc.type: FUNC
985 */
986 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_GetHandleExtendActionFunc_001, TestSize.Level0)
987 {
988 auto ret = OH_TextEditorProxy_GetHandleExtendActionFunc(nullptr, nullptr);
989 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
990 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
991 ASSERT_NE(proxy, nullptr);
992 ret = OH_TextEditorProxy_GetHandleExtendActionFunc(proxy, nullptr);
993 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
994 OH_TextEditorProxy_Destroy(proxy);
995 }
996
997 /**
998 * @tc.name: OH_TextEditorProxy_GetGetLeftTextOfCursorFunc_001
999 * @tc.desc: input parameters is nullptr
1000 * @tc.type: FUNC
1001 */
1002 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_GetGetLeftTextOfCursorFunc_001, TestSize.Level0)
1003 {
1004 auto ret = OH_TextEditorProxy_GetGetLeftTextOfCursorFunc(nullptr, nullptr);
1005 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1006 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
1007 ASSERT_NE(proxy, nullptr);
1008 ret = OH_TextEditorProxy_GetGetLeftTextOfCursorFunc(proxy, nullptr);
1009 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1010 OH_TextEditorProxy_Destroy(proxy);
1011 }
1012
1013 /**
1014 * @tc.name: OH_TextEditorProxy_GetGetRightTextOfCursorFunc_001
1015 * @tc.desc: input parameters is nullptr
1016 * @tc.type: FUNC
1017 */
1018 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_GetGetRightTextOfCursorFunc_001, TestSize.Level0)
1019 {
1020 auto ret = OH_TextEditorProxy_GetGetRightTextOfCursorFunc(nullptr, nullptr);
1021 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1022 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
1023 ASSERT_NE(proxy, nullptr);
1024 ret = OH_TextEditorProxy_GetGetRightTextOfCursorFunc(proxy, nullptr);
1025 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1026 OH_TextEditorProxy_Destroy(proxy);
1027 }
1028
1029 /**
1030 * @tc.name: OH_TextEditorProxy_GetGetTextIndexAtCursorFunc_001
1031 * @tc.desc: input parameters is nullptr
1032 * @tc.type: FUNC
1033 */
1034 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_GetGetTextIndexAtCursorFunc_001, TestSize.Level0)
1035 {
1036 auto ret = OH_TextEditorProxy_GetGetTextIndexAtCursorFunc(nullptr, nullptr);
1037 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1038 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
1039 ASSERT_NE(proxy, nullptr);
1040 ret = OH_TextEditorProxy_GetGetTextIndexAtCursorFunc(proxy, nullptr);
1041 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1042 OH_TextEditorProxy_Destroy(proxy);
1043 }
1044
1045 /**
1046 * @tc.name: OH_TextEditorProxy_GetReceivePrivateCommandFunc_001
1047 * @tc.desc: input parameters is nullptr
1048 * @tc.type: FUNC
1049 */
1050 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_GetReceivePrivateCommandFunc_001, TestSize.Level0)
1051 {
1052 auto ret = OH_TextEditorProxy_GetReceivePrivateCommandFunc(nullptr, nullptr);
1053 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1054 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
1055 ASSERT_NE(proxy, nullptr);
1056 ret = OH_TextEditorProxy_GetReceivePrivateCommandFunc(proxy, nullptr);
1057 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1058 OH_TextEditorProxy_Destroy(proxy);
1059 }
1060
1061 /**
1062 * @tc.name: OH_TextEditorProxy_GetSetPreviewTextFunc_001
1063 * @tc.desc: input parameters is nullptr
1064 * @tc.type: FUNC
1065 */
1066 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_GetSetPreviewTextFunc_001, TestSize.Level0)
1067 {
1068 auto ret = OH_TextEditorProxy_GetSetPreviewTextFunc(nullptr, nullptr);
1069 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1070 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
1071 ASSERT_NE(proxy, nullptr);
1072 ret = OH_TextEditorProxy_GetSetPreviewTextFunc(proxy, nullptr);
1073 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1074 OH_TextEditorProxy_Destroy(proxy);
1075 }
1076
1077 /**
1078 * @tc.name: OH_TextEditorProxy_GetFinishTextPreviewFunc_001
1079 * @tc.desc: input parameters is nullptr
1080 * @tc.type: FUNC
1081 */
1082 HWTEST_F(InputMethodControllerCapiTest, OH_TextEditorProxy_GetFinishTextPreviewFunc_001, TestSize.Level0)
1083 {
1084 auto ret = OH_TextEditorProxy_GetFinishTextPreviewFunc(nullptr, nullptr);
1085 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1086 InputMethod_TextEditorProxy *proxy = OH_TextEditorProxy_Create();
1087 ASSERT_NE(proxy, nullptr);
1088 ret = OH_TextEditorProxy_GetFinishTextPreviewFunc(proxy, nullptr);
1089 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1090 OH_TextEditorProxy_Destroy(proxy);
1091 }
1092
1093 /**
1094 * @tc.name: OH_AttachOptions_IsShowKeyboard_001
1095 * @tc.desc: input parameters is nullptr
1096 * @tc.type: FUNC
1097 */
1098 HWTEST_F(InputMethodControllerCapiTest, OH_AttachOptions_IsShowKeyboard_001, TestSize.Level0)
1099 {
1100 auto ret = OH_AttachOptions_IsShowKeyboard(nullptr, nullptr);
1101 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1102 InputMethod_AttachOptions *options = OH_AttachOptions_Create(true);
1103 ASSERT_NE(options, nullptr);
1104 ret = OH_AttachOptions_IsShowKeyboard(options, nullptr);
1105 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1106 OH_AttachOptions_Destroy(options);
1107 }
1108
1109 /**
1110 * @tc.name: OH_TextAvoidInfo_SetPositionY_001
1111 * @tc.desc: input parameters is nullptr
1112 * @tc.type: FUNC
1113 */
1114 HWTEST_F(InputMethodControllerCapiTest, OH_TextAvoidInfo_SetPositionY_001, TestSize.Level0)
1115 {
1116 double positionY = 0.0;
1117 auto ret = OH_TextAvoidInfo_SetPositionY(nullptr, positionY);
1118 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1119 }
1120
1121 /**
1122 * @tc.name: OH_TextAvoidInfo_SetHeight_001
1123 * @tc.desc: input parameters is nullptr
1124 * @tc.type: FUNC
1125 */
1126 HWTEST_F(InputMethodControllerCapiTest, OH_TextAvoidInfo_SetHeight_001, TestSize.Level0)
1127 {
1128 double positionY = 0.0;
1129 auto ret = OH_TextAvoidInfo_SetHeight(nullptr, positionY);
1130 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1131 }
1132
1133 /**
1134 * @tc.name: OH_TextAvoidInfo_GetPositionY_001
1135 * @tc.desc: input parameters is nullptr
1136 * @tc.type: FUNC
1137 */
1138 HWTEST_F(InputMethodControllerCapiTest, OH_TextAvoidInfo_GetPositionY_001, TestSize.Level0)
1139 {
1140 double positionY = 0.0;
1141 double height = 0.0;
1142 auto ret = OH_TextAvoidInfo_GetPositionY(nullptr, nullptr);
1143 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1144 InputMethod_TextAvoidInfo *info = OH_TextAvoidInfo_Create(positionY, height);
1145 ASSERT_NE(info, nullptr);
1146 ret = OH_TextAvoidInfo_GetPositionY(info, nullptr);
1147 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1148 OH_TextAvoidInfo_Destroy(info);
1149 }
1150
1151 /**
1152 * @tc.name: OH_TextAvoidInfo_GetHeight_001
1153 * @tc.desc: input parameters is nullptr
1154 * @tc.type: FUNC
1155 */
1156 HWTEST_F(InputMethodControllerCapiTest, OH_TextAvoidInfo_GetHeight_001, TestSize.Level0)
1157 {
1158 double positionY = 0.0;
1159 double height = 0.0;
1160 auto ret = OH_TextAvoidInfo_GetHeight(nullptr, nullptr);
1161 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1162 InputMethod_TextAvoidInfo *info = OH_TextAvoidInfo_Create(positionY, height);
1163 ASSERT_NE(info, nullptr);
1164 ret = OH_TextAvoidInfo_GetHeight(info, nullptr);
1165 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1166 OH_TextAvoidInfo_Destroy(info);
1167 }
1168
1169 /**
1170 * @tc.name: OH_PrivateCommand_SetKey_001
1171 * @tc.desc: input parameters is nullptr
1172 * @tc.type: FUNC
1173 */
1174 HWTEST_F(InputMethodControllerCapiTest, OH_PrivateCommand_SetKey_001, TestSize.Level0)
1175 {
1176 char key[] = "example key";
1177 size_t keyLength = strlen(key);
1178 auto ret = OH_PrivateCommand_SetKey(nullptr, nullptr, keyLength);
1179 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1180 InputMethod_PrivateCommand *command = OH_PrivateCommand_Create(key, keyLength);
1181 ASSERT_NE(command, nullptr);
1182 ret = OH_PrivateCommand_SetKey(command, nullptr, keyLength);
1183 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1184 OH_PrivateCommand_Destroy(command);
1185 }
1186
1187 /**
1188 * @tc.name: OH_PrivateCommand_SetBoolValue_001
1189 * @tc.desc: input parameters is nullptr
1190 * @tc.type: FUNC
1191 */
1192 HWTEST_F(InputMethodControllerCapiTest, OH_PrivateCommand_SetBoolValue_001, TestSize.Level0)
1193 {
1194 bool value = false;
1195 auto ret = OH_PrivateCommand_SetBoolValue(nullptr, value);
1196 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1197 }
1198
1199 /**
1200 * @tc.name: OH_PrivateCommand_SetIntValue_001
1201 * @tc.desc: input parameters is nullptr
1202 * @tc.type: FUNC
1203 */
1204 HWTEST_F(InputMethodControllerCapiTest, OH_PrivateCommand_SetIntValue_001, TestSize.Level0)
1205 {
1206 int32_t value = 0;
1207 auto ret = OH_PrivateCommand_SetIntValue(nullptr, value);
1208 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1209 }
1210
1211 /**
1212 * @tc.name: OH_PrivateCommand_SetIntValue_001
1213 * @tc.desc: input parameters is nullptr
1214 * @tc.type: FUNC
1215 */
1216 HWTEST_F(InputMethodControllerCapiTest, OH_PrivateCommand_SetStrValue_001, TestSize.Level0)
1217 {
1218 char value[] = "example value";
1219 size_t valueLength = strlen(value);
1220 auto ret = OH_PrivateCommand_SetStrValue(nullptr, value, valueLength);
1221 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1222 char key[] = "example key";
1223 size_t keyLength = strlen(key);
1224 InputMethod_PrivateCommand *command = OH_PrivateCommand_Create(key, keyLength);
1225 ASSERT_NE(command, nullptr);
1226 ret = OH_PrivateCommand_SetStrValue(command, nullptr, valueLength);
1227 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1228 OH_PrivateCommand_Destroy(command);
1229 }
1230
1231 /**
1232 * @tc.name: OH_PrivateCommand_GetKey_001
1233 * @tc.desc: input parameters is nullptr
1234 * @tc.type: FUNC
1235 */
1236 HWTEST_F(InputMethodControllerCapiTest, OH_PrivateCommand_GetKey_001, TestSize.Level0)
1237 {
1238 char key[] = "example key";
1239 size_t keyLength = strlen(key);
1240 auto ret = OH_PrivateCommand_GetKey(nullptr, nullptr, nullptr);
1241 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1242 InputMethod_PrivateCommand *command = OH_PrivateCommand_Create(key, keyLength);
1243 ASSERT_NE(command, nullptr);
1244 ret = OH_PrivateCommand_GetKey(command, nullptr, nullptr);
1245 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1246 const char *actStrKey = nullptr;
1247 ret = OH_PrivateCommand_GetKey(command, &actStrKey, nullptr);
1248 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1249 OH_PrivateCommand_Destroy(command);
1250 }
1251
1252 /**
1253 * @tc.name: OH_PrivateCommand_GetValueType_001
1254 * @tc.desc: input parameters is nullptr
1255 * @tc.type: FUNC
1256 */
1257 HWTEST_F(InputMethodControllerCapiTest, OH_PrivateCommand_GetValueType_001, TestSize.Level0)
1258 {
1259 auto ret = OH_PrivateCommand_GetValueType(nullptr, nullptr);
1260 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1261 char key[] = "example key";
1262 size_t keyLength = strlen(key);
1263 InputMethod_PrivateCommand *command = OH_PrivateCommand_Create(key, keyLength);
1264 ret = OH_PrivateCommand_GetValueType(command, nullptr);
1265 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1266 OH_PrivateCommand_Destroy(command);
1267 }
1268
1269 /**
1270 * @tc.name: OH_PrivateCommand_GetBoolValue_001
1271 * @tc.desc: input parameters is nullptr
1272 * @tc.type: FUNC
1273 */
1274 HWTEST_F(InputMethodControllerCapiTest, OH_PrivateCommand_GetBoolValue_001, TestSize.Level0)
1275 {
1276 auto ret = OH_PrivateCommand_GetBoolValue(nullptr, nullptr);
1277 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1278 char key[] = "example key";
1279 size_t keyLength = strlen(key);
1280 InputMethod_PrivateCommand *command = OH_PrivateCommand_Create(key, keyLength);
1281 ret = OH_PrivateCommand_GetBoolValue(command, nullptr);
1282 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1283 ret = OH_PrivateCommand_GetBoolValue(command, nullptr);
1284 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1285 int32_t expIntValue = 1;
1286 EXPECT_EQ(IME_ERR_OK, OH_PrivateCommand_SetIntValue(command, expIntValue));
1287 bool value = false;
1288 ret = OH_PrivateCommand_GetBoolValue(command, &value);
1289 EXPECT_EQ(ret, IME_ERR_QUERY_FAILED);
1290 OH_PrivateCommand_Destroy(command);
1291 }
1292
1293 /**
1294 * @tc.name: OH_PrivateCommand_GetIntValue_001
1295 * @tc.desc: input parameters is nullptr
1296 * @tc.type: FUNC
1297 */
1298 HWTEST_F(InputMethodControllerCapiTest, OH_PrivateCommand_GetIntValue_001, TestSize.Level0)
1299 {
1300 auto ret = OH_PrivateCommand_GetIntValue(nullptr, nullptr);
1301 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1302 char key[] = "example key";
1303 size_t keyLength = strlen(key);
1304 InputMethod_PrivateCommand *command = OH_PrivateCommand_Create(key, keyLength);
1305 ret = OH_PrivateCommand_GetIntValue(command, nullptr);
1306 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1307 bool expBoolValue = false;
1308 EXPECT_EQ(IME_ERR_OK, OH_PrivateCommand_SetBoolValue(command, expBoolValue));
1309 int32_t value = 0;
1310 ret = OH_PrivateCommand_GetIntValue(command, &value);
1311 EXPECT_EQ(ret, IME_ERR_QUERY_FAILED);
1312 OH_PrivateCommand_Destroy(command);
1313 }
1314
1315 /**
1316 * @tc.name: OH_PrivateCommand_GetStrValue_001
1317 * @tc.desc: input parameters is nullptr
1318 * @tc.type: FUNC
1319 */
1320 HWTEST_F(InputMethodControllerCapiTest, OH_PrivateCommand_GetStrValue_001, TestSize.Level0)
1321 {
1322 const char *value = nullptr;
1323 size_t valueLength = 0;
1324 auto ret = OH_PrivateCommand_GetStrValue(nullptr, &value, &valueLength);
1325 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1326 char key[] = "example key";
1327 size_t keyLength = strlen(key);
1328 InputMethod_PrivateCommand *command = OH_PrivateCommand_Create(key, keyLength);
1329 ret = OH_PrivateCommand_GetStrValue(command, nullptr, &valueLength);
1330 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1331 ret = OH_PrivateCommand_GetStrValue(command, &value, nullptr);
1332 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1333 bool expBoolValue = false;
1334 EXPECT_EQ(IME_ERR_OK, OH_PrivateCommand_SetBoolValue(command, expBoolValue));
1335 ret = OH_PrivateCommand_GetStrValue(command, &value, &valueLength);
1336 EXPECT_EQ(ret, IME_ERR_QUERY_FAILED);
1337 OH_PrivateCommand_Destroy(command);
1338 }
1339
1340 /**
1341 * @tc.name: OH_InputMethodController_Attach_001
1342 * @tc.desc: input parameters is nullptr
1343 * @tc.type: FUNC
1344 */
1345 HWTEST_F(InputMethodControllerCapiTest, OH_InputMethodController_Attach_001, TestSize.Level0)
1346 {
1347 auto ret = OH_InputMethodController_Attach(nullptr, nullptr, nullptr);
1348 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1349 auto textEditorProxy = OH_TextEditorProxy_Create();
1350 ret = OH_InputMethodController_Attach(textEditorProxy, nullptr, nullptr);
1351 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1352 ConstructTextEditorProxy(textEditorProxy);
1353 ret = OH_InputMethodController_Attach(textEditorProxy, nullptr, nullptr);
1354 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1355 InputMethod_AttachOptions *options = OH_AttachOptions_Create(true);
1356 ret = OH_InputMethodController_Attach(textEditorProxy, options, nullptr);
1357 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1358 OH_AttachOptions_Destroy(options);
1359 OH_TextEditorProxy_Destroy(textEditorProxy);
1360 }
1361
1362 /**
1363 * @tc.name: OH_InputMethodController_Detach_001
1364 * @tc.desc: input parameters is nullptr
1365 * @tc.type: FUNC
1366 */
1367 HWTEST_F(InputMethodControllerCapiTest, OH_InputMethodController_Detach_001, TestSize.Level0)
1368 {
1369 auto ret = OH_InputMethodController_Detach(nullptr);
1370 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1371 }
1372
1373 /**
1374 * @tc.name: OH_InputMethodProxy_ShowKeyboard_001
1375 * @tc.desc: input parameters is nullptr
1376 * @tc.type: FUNC
1377 */
1378 HWTEST_F(InputMethodControllerCapiTest, OH_InputMethodProxy_ShowKeyboard_001, TestSize.Level0)
1379 {
1380 auto ret = OH_InputMethodProxy_ShowKeyboard(nullptr);
1381 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1382 }
1383
1384 /**
1385 * @tc.name: OH_InputMethodProxy_HideKeyboard_001
1386 * @tc.desc: input parameters is nullptr
1387 * @tc.type: FUNC
1388 */
1389 HWTEST_F(InputMethodControllerCapiTest, OH_InputMethodProxy_HideKeyboard_001, TestSize.Level0)
1390 {
1391 auto ret = OH_InputMethodProxy_HideKeyboard(nullptr);
1392 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1393 }
1394
1395 /**
1396 * @tc.name: OH_InputMethodProxy_NotifySelectionChange_001
1397 * @tc.desc: input parameters is nullptr
1398 * @tc.type: FUNC
1399 */
1400 HWTEST_F(InputMethodControllerCapiTest, OH_InputMethodProxy_NotifySelectionChange_001, TestSize.Level0)
1401 {
1402 size_t length = 0;
1403 int start = 0;
1404 int end = 0;
1405 auto ret = OH_InputMethodProxy_NotifySelectionChange(nullptr, nullptr, length, start, end);
1406 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1407 }
1408
1409 /**
1410 * @tc.name: OH_InputMethodProxy_NotifyConfigurationChange_001
1411 * @tc.desc: input parameters is nullptr
1412 * @tc.type: FUNC
1413 */
1414 HWTEST_F(InputMethodControllerCapiTest, OH_InputMethodProxy_NotifyConfigurationChange_001, TestSize.Level0)
1415 {
1416 InputMethod_EnterKeyType enterKey = IME_ENTER_KEY_UNSPECIFIED;
1417 InputMethod_TextInputType expInput = IME_TEXT_INPUT_TYPE_NUMBER_DECIMAL;
1418 auto ret = OH_InputMethodProxy_NotifyConfigurationChange(nullptr, enterKey, expInput);
1419 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1420 }
1421
1422 /**
1423 * @tc.name: OH_InputMethodProxy_NotifyCursorUpdate_001
1424 * @tc.desc: input parameters is nullptr
1425 * @tc.type: FUNC
1426 */
1427 HWTEST_F(InputMethodControllerCapiTest, OH_InputMethodProxy_NotifyCursorUpdate_001, TestSize.Level0)
1428 {
1429 double left = 0;
1430 double top = 1.0;
1431 double width = 2.0;
1432 double height = 3.0;
1433 InputMethod_CursorInfo *cursorInfo = OH_CursorInfo_Create(left, top, width, height);
1434 auto ret = OH_InputMethodProxy_NotifyCursorUpdate(nullptr, nullptr);
1435 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1436 ret = OH_InputMethodProxy_NotifyCursorUpdate(nullptr, cursorInfo);
1437 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1438 }
1439
1440 /**
1441 * @tc.name: OH_InputMethodProxy_SendPrivateCommand_001
1442 * @tc.desc: input parameters is nullptr
1443 * @tc.type: FUNC
1444 */
1445 HWTEST_F(InputMethodControllerCapiTest, OH_InputMethodProxy_SendPrivateCommand_001, TestSize.Level0)
1446 {
1447 char key[] = "example key";
1448 size_t keyLength = strlen(key);
1449 char key1[] = "example key";
1450 size_t keyLength1 = strlen(key);
1451 InputMethod_PrivateCommand *privateCommand[] = { OH_PrivateCommand_Create(key, keyLength),
1452 OH_PrivateCommand_Create(key1, keyLength1), nullptr };
1453 size_t size = 3;
1454 auto ret = OH_InputMethodProxy_SendPrivateCommand(nullptr, nullptr, size);
1455 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1456 ret = OH_InputMethodProxy_SendPrivateCommand(nullptr, privateCommand, size);
1457 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1458 }
1459
1460 /**
1461 * @tc.name: TestAttachWithNullParam_001
1462 * @tc.desc: input parameters is nullptr
1463 * @tc.type: FUNC
1464 */
1465 HWTEST_F(InputMethodControllerCapiTest, TestAttachWithNullParam_001, TestSize.Level0)
1466 {
1467 auto ret = OH_InputMethodController_Attach(nullptr, nullptr, nullptr);
1468 EXPECT_EQ(IME_ERR_NULL_POINTER, ret);
1469
1470 auto textEditorProxy = OH_TextEditorProxy_Create();
1471 EXPECT_NE(nullptr, textEditorProxy);
1472
1473 EXPECT_EQ(IME_ERR_NULL_POINTER, OH_InputMethodController_Attach(textEditorProxy, nullptr, nullptr));
1474
1475 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetGetTextConfigFunc(textEditorProxy, GetTextConfigFunc));
1476 EXPECT_EQ(IME_ERR_NULL_POINTER, OH_InputMethodController_Attach(textEditorProxy, nullptr, nullptr));
1477
1478 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetInsertTextFunc(textEditorProxy, InsertTextFunc));
1479 EXPECT_EQ(IME_ERR_NULL_POINTER, OH_InputMethodController_Attach(textEditorProxy, nullptr, nullptr));
1480
1481 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetDeleteForwardFunc(textEditorProxy, DeleteForwardFunc));
1482 EXPECT_EQ(IME_ERR_NULL_POINTER, OH_InputMethodController_Attach(textEditorProxy, nullptr, nullptr));
1483
1484 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetDeleteBackwardFunc(textEditorProxy, DeleteBackwardFunc));
1485 EXPECT_EQ(IME_ERR_NULL_POINTER, OH_InputMethodController_Attach(textEditorProxy, nullptr, nullptr));
1486
1487 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetSendKeyboardStatusFunc(textEditorProxy, SendKeyboardStatusFunc));
1488 EXPECT_EQ(IME_ERR_NULL_POINTER, OH_InputMethodController_Attach(textEditorProxy, nullptr, nullptr));
1489
1490 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetSendEnterKeyFunc(textEditorProxy, SendEnterKeyFunc));
1491 EXPECT_EQ(IME_ERR_NULL_POINTER, OH_InputMethodController_Attach(textEditorProxy, nullptr, nullptr));
1492
1493 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetMoveCursorFunc(textEditorProxy, MoveCursorFunc));
1494 EXPECT_EQ(IME_ERR_NULL_POINTER, OH_InputMethodController_Attach(textEditorProxy, nullptr, nullptr));
1495
1496 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetHandleSetSelectionFunc(textEditorProxy, HandleSetSelectionFunc));
1497 EXPECT_EQ(IME_ERR_NULL_POINTER, OH_InputMethodController_Attach(textEditorProxy, nullptr, nullptr));
1498
1499 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetHandleExtendActionFunc(textEditorProxy, HandleExtendActionFunc));
1500 EXPECT_EQ(IME_ERR_NULL_POINTER, OH_InputMethodController_Attach(textEditorProxy, nullptr, nullptr));
1501
1502 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetGetLeftTextOfCursorFunc(textEditorProxy, GetleftTextOfCursorFunc));
1503 EXPECT_EQ(IME_ERR_NULL_POINTER, OH_InputMethodController_Attach(textEditorProxy, nullptr, nullptr));
1504
1505 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetGetRightTextOfCursorFunc(textEditorProxy, GetRightTextOfCursorFunc));
1506 EXPECT_EQ(IME_ERR_NULL_POINTER, OH_InputMethodController_Attach(textEditorProxy, nullptr, nullptr));
1507
1508 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetGetTextIndexAtCursorFunc(textEditorProxy, GetTextIndexAtCursorFunc));
1509 EXPECT_EQ(IME_ERR_NULL_POINTER, OH_InputMethodController_Attach(textEditorProxy, nullptr, nullptr));
1510
1511 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetReceivePrivateCommandFunc(textEditorProxy, ReceivePrivateCommandFunc));
1512 EXPECT_EQ(IME_ERR_NULL_POINTER, OH_InputMethodController_Attach(textEditorProxy, nullptr, nullptr));
1513
1514 EXPECT_EQ(IME_ERR_OK, OH_TextEditorProxy_SetSetPreviewTextFunc(textEditorProxy, SetPreviewTextFunc));
1515 EXPECT_EQ(IME_ERR_NULL_POINTER, OH_InputMethodController_Attach(textEditorProxy, nullptr, nullptr));
1516
1517 OH_TextEditorProxy_Destroy(textEditorProxy);
1518 }
1519
1520 /**
1521 * @tc.name: TestAttachWithNorrmalParam_001
1522 * @tc.desc: input parameters is normal
1523 * @tc.type: FUNC
1524 */
1525 HWTEST_F(InputMethodControllerCapiTest, TestAttachWithNorrmalParam_001, TestSize.Level0)
1526 {
1527 auto textEditorProxy = OH_TextEditorProxy_Create();
1528 EXPECT_NE(nullptr, textEditorProxy);
1529 ConstructTextEditorProxy(textEditorProxy);
1530
1531 auto options = OH_AttachOptions_Create(true);
1532 EXPECT_NE(nullptr, options);
1533 InputMethod_InputMethodProxy *inputMethodProxy = nullptr;
1534 EXPECT_EQ(IME_ERR_IMCLIENT, OH_InputMethodController_Attach(textEditorProxy, options, &inputMethodProxy));
1535 EXPECT_EQ(IME_ERR_IMCLIENT, OH_InputMethodController_Attach(textEditorProxy, options, &inputMethodProxy));
1536
1537 auto textEditorProxy2 = OH_TextEditorProxy_Create();
1538 EXPECT_NE(nullptr, textEditorProxy2);
1539 ConstructTextEditorProxy(textEditorProxy2);
1540 EXPECT_EQ(IME_ERR_IMCLIENT, OH_InputMethodController_Attach(textEditorProxy2, options, &inputMethodProxy));
1541 OH_TextEditorProxy_Destroy(textEditorProxy2);
1542
1543 OH_AttachOptions_Destroy(options);
1544 OH_TextEditorProxy_Destroy(textEditorProxy);
1545 }
1546
1547 /**
1548 * @tc.name: TestAttachWithPlaceholderAndAbility_001
1549 * @tc.desc: the input parameter contains the placeholder and ability name
1550 * @tc.type: FUNC
1551 */
1552 HWTEST_F(InputMethodControllerCapiTest, TestAttachWithPlaceholderAndAbility_001, TestSize.Level0)
1553 {
1554 auto options = OH_AttachOptions_Create(true);
1555 auto textEditorProxy2 = OH_TextEditorProxy_Create();
1556 EXPECT_NE(nullptr, textEditorProxy2);
1557 ConstructTextEditorProxy(textEditorProxy2);
1558 auto fnGetTextConfigFunc = [](InputMethod_TextEditorProxy *textEditorProxy,
__anon019bba460202(InputMethod_TextEditorProxy *textEditorProxy, InputMethod_TextConfig *config) 1559 InputMethod_TextConfig *config) {
1560 std::u16string placeholder = u"test placeholder";
1561 std::u16string abilityName = u"test ability name";
1562 OH_TextConfig_SetPlaceholder(config, placeholder.data(), placeholder.size());
1563 OH_TextConfig_SetAbilityName(config, abilityName.data(), abilityName.size());
1564 };
1565 OH_TextEditorProxy_SetGetTextConfigFunc(textEditorProxy2, fnGetTextConfigFunc);
1566 InputMethod_InputMethodProxy *inputMethodProxy = nullptr;
1567 auto ret = OH_InputMethodController_Attach(textEditorProxy2, options, &inputMethodProxy);
1568 EXPECT_NE(ret, IME_ERR_OK);
1569 OH_TextEditorProxy_Destroy(textEditorProxy2);
1570 OH_AttachOptions_Destroy(options);
1571 }
1572
1573 /**
1574 * @tc.name: OH_TextConfig_SetPlaceholder_001
1575 * @tc.desc: Input parameters are valid
1576 * @tc.type: FUNC
1577 */
1578 HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetPlaceholder_001, TestSize.Level0)
1579 {
1580 auto config = OH_TextConfig_Create();
1581 ASSERT_NE(nullptr, config);
1582 std::u16string input= u"test";
1583 auto ret = OH_TextConfig_SetPlaceholder(config, input.data(), input.size());
1584 EXPECT_EQ(ret, IME_ERR_OK);
1585 ret = OH_TextConfig_GetPlaceholder(nullptr, nullptr, nullptr);
1586 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1587 ret = OH_TextConfig_GetPlaceholder(config, nullptr, nullptr);
1588 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1589 size_t outLen = 513;
1590 char16_t pOut[513] = {};
1591 ret = OH_TextConfig_GetPlaceholder(config, pOut, nullptr);
1592 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1593 outLen = 1;
1594 ret = OH_TextConfig_GetPlaceholder(config, pOut, &outLen);
1595 EXPECT_EQ(ret, IME_ERR_PARAMCHECK);
1596 EXPECT_EQ(outLen -1, input.size());
1597 outLen = 513;
1598 ret = OH_TextConfig_GetPlaceholder(config, pOut, &outLen);
1599 EXPECT_EQ(ret, IME_ERR_OK);
1600 EXPECT_EQ(outLen -1, input.size());
1601 outLen = input.size();
1602 ret = OH_TextConfig_GetPlaceholder(config, pOut, &outLen);
1603 EXPECT_EQ(ret, IME_ERR_PARAMCHECK);
1604 std::u16string out(pOut, outLen);
1605 EXPECT_GT(out.size(), input.size());
1606 outLen = 4;
1607 ret = OH_TextConfig_GetPlaceholder(config, pOut, &outLen);
1608 EXPECT_EQ(ret, IME_ERR_PARAMCHECK);
1609 OH_TextConfig_Destroy(config);
1610 }
1611
1612 /**
1613 * @tc.name: OH_TextConfig_SetPlaceholder_002
1614 * @tc.desc: Invalid test input parameter
1615 * @tc.type: FUNC
1616 */
1617 HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetPlaceholder_002, TestSize.Level0) {
1618 auto config = OH_TextConfig_Create();
1619 ASSERT_NE(nullptr, config);
1620 std::u16string input= u"test";
1621 auto ret = OH_TextConfig_SetPlaceholder(config, input.data(), input.size());
1622 EXPECT_EQ(ret, IME_ERR_OK);
1623 ret = OH_TextConfig_SetPlaceholder(config, nullptr, 0);
1624 EXPECT_EQ(ret, IME_ERR_OK);
1625 size_t outLen = 512;
1626 char16_t pOut[512] = {};
1627 ret = OH_TextConfig_GetPlaceholder(config, pOut, &outLen);
1628 EXPECT_EQ(ret, IME_ERR_OK);
1629 EXPECT_EQ(outLen, 1);
1630 OH_TextConfig_Destroy(config);
1631 }
1632
1633 /**
1634 * @tc.name: OH_TextConfig_SetPlaceholder_003
1635 * @tc.desc: Invalid test input parameter
1636 * @tc.type: FUNC
1637 */
1638 HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetPlaceholder_003, TestSize.Level0) {
1639 auto config = OH_TextConfig_Create();
1640 ASSERT_NE(nullptr, config);
1641 auto ret = OH_TextConfig_SetPlaceholder(config, nullptr, 257);
1642 EXPECT_EQ(ret, IME_ERR_OK);
1643 ret = OH_TextConfig_SetPlaceholder(config, nullptr, 1);
1644 EXPECT_EQ(ret, IME_ERR_OK);
1645 ret = OH_TextConfig_SetPlaceholder(nullptr, nullptr, 1);
1646 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1647 std::u16string input = u"";
1648 for (int i = 0; i < MAX_PLACEHOLDER_SIZE; ++i) {
1649 input.append(u"");
1650 }
1651 IMSA_HILOGI("inputLen:%{public}zu,input:%{public}s", input.size(), Str16ToStr8(input).c_str());
1652 ret = OH_TextConfig_SetPlaceholder(config, input.data(), input.size());
1653 EXPECT_EQ(ret, IME_ERR_OK);
1654 std::u16string out(MAX_PLACEHOLDER_INPUT_SIZE, u'\0');
1655 size_t outLen = out.size();
1656 ret = OH_TextConfig_GetPlaceholder(config, out.data(), &outLen);
1657 EXPECT_EQ(ret, IME_ERR_OK);
1658 EXPECT_EQ(out.size(), outLen);
1659 EXPECT_EQ(out[out.size() - 1], 0);
1660 out.pop_back();
1661 EXPECT_EQ(out.compare(input), 0);
1662 input.append(u"a");
1663 IMSA_HILOGI("inputLen:%{public}zu,input:%{public}s", input.size(), Str16ToStr8(input).c_str());
1664 ret = OH_TextConfig_SetPlaceholder(config, input.data(), input.size());
1665 EXPECT_EQ(ret, IME_ERR_OK);
1666 std::u16string out2(MAX_PLACEHOLDER_INPUT_SIZE, u'\0');
1667 outLen = out2.size();
1668 ret = OH_TextConfig_GetPlaceholder(config, out2.data(), &outLen);
1669 EXPECT_EQ(ret, IME_ERR_OK);
1670 EXPECT_EQ(out2[out2.size() - 1], 0);
1671 input[input.size() - 1] = u'\0';
1672 EXPECT_EQ(out2.compare(input), 0);
1673 OH_TextConfig_Destroy(config);
1674 }
1675
1676 /**
1677 * @tc.name: OH_TextConfig_SetAbilityName_001
1678 * @tc.desc: Input parameters are valid
1679 * @tc.type: FUNC
1680 */
1681 HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetAbilityName_001, TestSize.Level0) {
1682 auto config = OH_TextConfig_Create();
1683 ASSERT_NE(nullptr, config);
1684 std::u16string input= u"test";
1685 auto ret = OH_TextConfig_SetAbilityName(config, input.data(), input.size());
1686 EXPECT_EQ(ret, IME_ERR_OK);
1687 ret = OH_TextConfig_GetAbilityName(nullptr, nullptr, nullptr);
1688 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1689 ret = OH_TextConfig_GetAbilityName(config, nullptr, nullptr);
1690 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1691 size_t outLen = 66;
1692 char16_t pOut[66] = {};
1693 ret = OH_TextConfig_GetAbilityName(config, pOut, nullptr);
1694 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1695 outLen = 1;
1696 ret = OH_TextConfig_GetAbilityName(config, pOut, &outLen);
1697 EXPECT_EQ(ret, IME_ERR_PARAMCHECK);
1698 EXPECT_EQ(outLen, 5);
1699 outLen = 65;
1700 ret = OH_TextConfig_GetAbilityName(config, pOut, &outLen);
1701 EXPECT_EQ(ret, IME_ERR_OK);
1702 EXPECT_EQ(outLen, 5);
1703 outLen = 5;
1704 ret = OH_TextConfig_GetAbilityName(config, pOut, &outLen);
1705 EXPECT_EQ(ret, IME_ERR_OK);
1706 std::u16string out(pOut, outLen);
1707 IMSA_HILOGI("outLen:%{public}zu,out:%{public}s,outSize:%{public}zu", outLen,
1708 Str16ToStr8(out).c_str(), out.size());
1709 EXPECT_GT(out.size(), input.size());
1710 outLen = input.size();
1711 ret = OH_TextConfig_GetAbilityName(config, pOut, &outLen);
1712 EXPECT_EQ(ret, IME_ERR_PARAMCHECK);
1713 OH_TextConfig_Destroy(config);
1714 }
1715
1716 /**
1717 * @tc.name: OH_TextConfig_SetAbilityName_002
1718 * @tc.desc: Invalid test input parameter
1719 * @tc.type: FUNC
1720 */
1721 HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetAbilityName_002, TestSize.Level0) {
1722 auto config = OH_TextConfig_Create();
1723 ASSERT_NE(nullptr, config);
1724 std::u16string input= u"test";
1725 auto ret = OH_TextConfig_SetAbilityName(config, input.data(), input.size());
1726 EXPECT_EQ(ret, IME_ERR_OK);
1727 ret = OH_TextConfig_SetAbilityName(config, nullptr, 0);
1728 EXPECT_EQ(ret, IME_ERR_OK);
1729 char16_t *pOut = nullptr;
1730 size_t outLen = 0;
1731 ret = OH_TextConfig_GetAbilityName(config, pOut, &outLen);
1732 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1733 EXPECT_EQ(outLen, 1);
1734 EXPECT_EQ(pOut, nullptr);
1735 OH_TextConfig_Destroy(config);
1736 }
1737
1738 /**
1739 * @tc.name: OH_TextConfig_SetAbilityName_003
1740 * @tc.desc: Invalid test input parameter
1741 * @tc.type: FUNC
1742 */
1743 HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetAbilityName_003, TestSize.Level0) {
1744 auto config = OH_TextConfig_Create();
1745 ASSERT_NE(nullptr, config);
1746 auto ret = OH_TextConfig_SetAbilityName(config, nullptr, 128);
1747 EXPECT_EQ(ret, IME_ERR_OK);
1748 ret = OH_TextConfig_SetAbilityName(config, nullptr, 1);
1749 EXPECT_EQ(ret, IME_ERR_OK);
1750 char16_t input[] = u"0";
1751 ret = OH_TextConfig_SetAbilityName(config, input, 0);
1752 EXPECT_EQ(ret, IME_ERR_OK);
1753 ret = OH_TextConfig_SetAbilityName(config, input, 1);
1754 EXPECT_EQ(ret, IME_ERR_OK);
1755 ret = OH_TextConfig_SetAbilityName(nullptr, nullptr, 1);
1756 EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
1757 OH_TextConfig_Destroy(config);
1758 }
1759
1760 /**
1761 * @tc.name: OH_TextConfig_SetAbilityName_004
1762 * @tc.desc: Invalid test input parameter
1763 * @tc.type: FUNC
1764 */
1765 HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetAbilityName_004, TestSize.Level0) {
1766 auto config = OH_TextConfig_Create();
1767 ASSERT_NE(nullptr, config);
1768 std::u16string input = u"";
1769 for (int i = 0; i < MAX_ABILITY_NAME_SIZE; ++i) {
1770 input.append(u"");
1771 }
1772 IMSA_HILOGI("inputLen:%{public}zu,input:%{public}s", input.size(), Str16ToStr8(input).c_str());
1773 auto ret = OH_TextConfig_SetAbilityName(config, input.data(), input.size());
1774 EXPECT_EQ(ret, IME_ERR_OK);
1775 std::u16string out(MAX_ABILITY_NAME_INPUT_SIZE, u'\0');
1776 size_t outLen = out.size();
1777 ret = OH_TextConfig_GetAbilityName(config, out.data(), &outLen);
1778 EXPECT_EQ(ret, IME_ERR_OK);
1779 IMSA_HILOGI("outLen:%{public}zu,input:%{public}s,outSize:%{public}zu,inputSize:%{public}zu", outLen,
1780 Str16ToStr8(input).c_str(), out.size(), input.size());
1781 EXPECT_GT(out.size(), input.size());
1782 EXPECT_EQ(out[out.size() - 1], 0);
1783 out.pop_back();
1784 EXPECT_EQ(out.compare(input), 0);
1785 input.append(u"a");
1786 IMSA_HILOGI("inputLen:%{public}zu,input:%{public}s", input.size(), Str16ToStr8(input).c_str());
1787 ret = OH_TextConfig_SetAbilityName(config, input.data(), input.size());
1788 EXPECT_EQ(ret, IME_ERR_OK);
1789 std::u16string out2(MAX_ABILITY_NAME_INPUT_SIZE, u'\0');
1790 outLen = out2.size();
1791 ret = OH_TextConfig_GetAbilityName(config, out2.data(), &outLen);
1792 EXPECT_EQ(ret, IME_ERR_OK);
1793 EXPECT_EQ(out2[out2.size() - 1], 0);
1794 input[input.size() -1] = u'\0';
1795 EXPECT_EQ(out2.compare(input), 0);
1796 char16_t charInput[65] = u"123456789\0123456789\0012345678901\023456789";
1797 size_t charInputLen = 32;
1798 IMSA_HILOGI("inputLen:%{public}zu,input:%{public}s", charInputLen, Str16ToStr8(input).c_str());
1799 ret = OH_TextConfig_SetAbilityName(config, charInput, charInputLen);
1800 EXPECT_EQ(ret, IME_ERR_OK);
1801 char16_t outChar[66] = {};
1802 outLen = 33;
1803 ret = OH_TextConfig_GetAbilityName(config, outChar, &outLen);
1804 EXPECT_EQ(ret, IME_ERR_OK);
1805 out = std::u16string(outChar, outLen);
1806 auto utf8Out = Str16ToStr8(outChar);
1807 IMSA_HILOGI("outLen:%{public}zu,out:%{public}s, utf8len:%{public}zu", outLen, utf8Out.c_str(), utf8Out.size());
1808 OH_TextConfig_Destroy(config);
1809 }
1810 } // namespace