1 /*
2 * Copyright (C) 2022 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 #define private public
16 #define protected public
17 #include "full_ime_info_manager.h"
18 #include "ime_cfg_manager.h"
19 #include "ime_info_inquirer.h"
20 #include "input_method_controller.h"
21 #include "input_method_system_ability.h"
22 #include "peruser_session.h"
23 #include "wms_connection_observer.h"
24 #include "settings_data_utils.h"
25 #undef private
26 #include <gtest/gtest.h>
27 #include <sys/time.h>
28 #include <unistd.h>
29
30 #include <string>
31 #include <vector>
32
33 #include "application_info.h"
34 #include "combination_key.h"
35 #include "focus_change_listener.h"
36 #include "global.h"
37 #include "i_input_method_agent.h"
38 #include "i_input_method_core.h"
39 #include "ime_cfg_manager.h"
40 #include "input_method_agent_proxy.h"
41 #include "input_method_agent_stub.h"
42 #include "input_method_core_stub.h"
43 #include "keyboard_event.h"
44 #include "os_account_manager.h"
45 #include "tdd_util.h"
46 #include "user_session_manager.h"
47
48 using namespace testing::ext;
49 namespace OHOS {
50 namespace MiscServices {
51 using namespace AppExecFwk;
52 class InputMethodPrivateMemberTest : public testing::Test {
53 public:
54 static void SetUpTestCase(void);
55 static void TearDownTestCase(void);
56 void SetUp();
57 void TearDown();
58 static sptr<InputMethodSystemAbility> service_;
59 };
60 constexpr std::int32_t MAIN_USER_ID = 100;
61 constexpr std::int32_t INVALID_USER_ID = 10001;
62 constexpr std::int32_t INVALID_PROCESS_ID = -1;
SetUpTestCase(void)63 void InputMethodPrivateMemberTest::SetUpTestCase(void)
64 {
65 IMSA_HILOGI("InputMethodPrivateMemberTest::SetUpTestCase");
66 service_ = new (std::nothrow) InputMethodSystemAbility();
67 if (service_ == nullptr) {
68 return;
69 }
70 service_->OnStart();
71 }
72
TearDownTestCase(void)73 void InputMethodPrivateMemberTest::TearDownTestCase(void)
74 {
75 service_->OnStop();
76 IMSA_HILOGI("InputMethodPrivateMemberTest::TearDownTestCase");
77 }
78
SetUp(void)79 void InputMethodPrivateMemberTest::SetUp(void)
80 {
81 IMSA_HILOGI("InputMethodPrivateMemberTest::SetUp");
82 ImeCfgManager::GetInstance().imeConfigs_.clear();
83 FullImeInfoManager::GetInstance().fullImeInfos_.clear();
84 service_->userId_ = MAIN_USER_ID;
85 }
86
TearDown(void)87 void InputMethodPrivateMemberTest::TearDown(void)
88 {
89 IMSA_HILOGI("InputMethodPrivateMemberTest::TearDown");
90 ImeCfgManager::GetInstance().imeConfigs_.clear();
91 FullImeInfoManager::GetInstance().fullImeInfos_.clear();
92 }
93 sptr<InputMethodSystemAbility> InputMethodPrivateMemberTest::service_;
94
95 /**
96 * @tc.name: SA_TestOnStart
97 * @tc.desc: SA OnStart.
98 * @tc.type: FUNC
99 * @tc.require:
100 */
101 HWTEST_F(InputMethodPrivateMemberTest, SA_TestOnStart, TestSize.Level0)
102 {
103 InputMethodSystemAbility ability;
104 ability.state_ = ServiceRunningState::STATE_RUNNING;
105 ability.OnStart();
106 EXPECT_EQ(ability.identityChecker_, nullptr);
107 }
108
109 /**
110 * @tc.name: SA_GetExtends
111 * @tc.desc: SA GetExtends.
112 * @tc.type: FUNC
113 * @tc.require: issuesI640YZ
114 */
115 HWTEST_F(InputMethodPrivateMemberTest, SA_GetExtends, TestSize.Level0)
116 {
117 constexpr int32_t metaDataNums = 5;
118 ImeInfoInquirer inquirer;
119 std::vector<Metadata> metaData;
120 Metadata metadata[metaDataNums] = {
121 { "language", "english", "" },
122 { "mode", "mode", "" },
123 { "locale", "local", "" },
124 { "icon", "icon", "" },
125 { "", "", "" }
126 };
127 for (auto const &data : metadata) {
128 metaData.emplace_back(data);
129 }
130 auto subProperty = inquirer.GetExtends(metaData);
131 EXPECT_EQ(subProperty.language, "english");
132 EXPECT_EQ(subProperty.mode, "mode");
133 EXPECT_EQ(subProperty.locale, "local");
134 EXPECT_EQ(subProperty.icon, "icon");
135 }
136
137 /**
138 * @tc.name: SA_TestOnUserStarted
139 * @tc.desc: SA_TestOnUserStarted.
140 * @tc.type: FUNC
141 * @tc.require:
142 */
143 HWTEST_F(InputMethodPrivateMemberTest, SA_TestOnUserStarted, TestSize.Level0)
144 {
145 // isScbEnable_ is true
146 service_->isScbEnable_ = true;
147 MessageParcel *parcel = nullptr;
148 auto msg = std::make_shared<Message>(MessageID::MSG_ID_USER_START, parcel);
149 auto ret = service_->OnUserStarted(msg.get());
150 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
151
152 // msg is nullptr
153 service_->isScbEnable_ = false;
154 ret = service_->OnUserStarted(msg.get());
155 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
156
157 // userId is same
158 service_->userId_ = 50;
159 MessageParcel *parcel1 = new MessageParcel();
160 parcel1->WriteInt32(50);
161 auto msg1 = std::make_shared<Message>(MessageID::MSG_ID_USER_START, parcel1);
162 ret = service_->OnUserStarted(msg1.get());
163 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
164
165 // start ime
166 WmsConnectionObserver observer(nullptr);
167 observer.OnConnected(60, 0);
168 // imeStarting_ is true
169 IMSA_HILOGI("InputMethodPrivateMemberTest::imeStarting_ is true");
170 service_->userId_ = 50;
171 MessageParcel *parcel2 = new MessageParcel();
172 parcel2->WriteInt32(60);
173 auto msg2 = std::make_shared<Message>(MessageID::MSG_ID_USER_START, parcel2);
174 ret = service_->OnUserStarted(msg2.get());
175 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
176 // imeStarting_ is false
177 IMSA_HILOGI("InputMethodPrivateMemberTest::imeStarting_ is false");
178 service_->userId_ = 50;
179 MessageParcel *parcel3 = new MessageParcel();
180 observer.OnConnected(333, 0);
181 parcel3->WriteInt32(333);
182 auto msg3 = std::make_shared<Message>(MessageID::MSG_ID_USER_START, parcel3);
183 ret = service_->OnUserStarted(msg3.get());
184 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
185 }
186
187 /**
188 * @tc.name: SA_TestOnUserRemoved
189 * @tc.desc: SA_TestOnUserRemoved.
190 * @tc.type: FUNC
191 * @tc.require:
192 */
193 HWTEST_F(InputMethodPrivateMemberTest, SA_TestOnUserRemoved, TestSize.Level0)
194 {
195 // msg is nullptr
196 auto *msg = new Message(MessageID::MSG_ID_USER_REMOVED, nullptr);
197 auto ret = service_->OnUserRemoved(msg);
198 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
199 MessageHandler::Instance()->SendMessage(msg);
200
201 // move userId
202 MessageParcel *parcel1 = new MessageParcel();
203 parcel1->WriteInt32(60);
204 auto msg1 = std::make_shared<Message>(MessageID::MSG_ID_USER_REMOVED, parcel1);
205 auto ret1 = service_->OnUserRemoved(msg1.get());
206 EXPECT_EQ(ret1, ErrorCode::NO_ERROR);
207 }
208
209 /**
210 * @tc.name: SA_ListInputMethodInfoWithInexistentUserId
211 * @tc.desc: SA ListInputMethodInfo With Inexistent UserId.
212 * @tc.type: FUNC
213 * @tc.require: issuesI669E8
214 */
215 HWTEST_F(InputMethodPrivateMemberTest, SA_ListInputMethodInfoWithInexistentUserId, TestSize.Level0)
216 {
217 ImeInfoInquirer inquirer;
218 constexpr int32_t userId = 1;
219 auto inputMethodInfos = inquirer.ListInputMethodInfo(userId);
220 EXPECT_TRUE(inputMethodInfos.empty());
221 }
222
223 /**
224 * @tc.name: IMC_ListInputMethodCommonWithErrorStatus
225 * @tc.desc: IMC ListInputMethodCommon With Error Status.
226 * @tc.type: FUNC
227 * @tc.require: issuesI669E8
228 */
229 HWTEST_F(InputMethodPrivateMemberTest, IMC_ListInputMethodCommonWithErrorStatus, TestSize.Level0)
230 {
231 std::vector<Property> props;
232 auto ret = InputMethodController::GetInstance()->ListInputMethodCommon(static_cast<InputMethodStatus>(5), props);
233 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
234 EXPECT_TRUE(props.empty());
235 }
236
237 /**
238 * @tc.name: PerUserSessionCoreOrAgentNullptr
239 * @tc.desc: Test PerUserSession with core nullptr.
240 * @tc.type: FUNC
241 * @tc.require: issuesI794QF
242 * @tc.author: Zhaolinglan
243 */
244 HWTEST_F(InputMethodPrivateMemberTest, PerUserSessionCoreOrAgentNullptr, TestSize.Level0)
245 {
246 IMSA_HILOGI("InputMethodPrivateMemberTest PerUserSessionCoreOrAgentNullptr TEST START");
247 auto userSession = std::make_shared<PerUserSession>(MAIN_USER_ID);
248 auto imc = InputMethodController::GetInstance();
249 int32_t ret = userSession->ShowKeyboard(imc->clientInfo_.client);
250 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
251 ret = userSession->HideKeyboard(imc->clientInfo_.client);
252 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
253 ret = userSession->InitInputControlChannel();
254 EXPECT_EQ(ret, ErrorCode::ERROR_IME_NOT_STARTED);
255 userSession->StopCurrentIme();
256 ret = userSession->SwitchSubtype({});
257 EXPECT_EQ(ret, ErrorCode::ERROR_IME_NOT_STARTED);
258 }
259
260 /**
261 * @tc.name: PerUserSessionClientError
262 * @tc.desc: Test PerUserSession with client error.
263 * @tc.type: FUNC
264 * @tc.require: issuesI794QF
265 * @tc.author: Zhaolinglan
266 */
267 HWTEST_F(InputMethodPrivateMemberTest, PerUserSessionClientError, TestSize.Level0)
268 {
269 IMSA_HILOGI("InputMethodPrivateMemberTest PerUserSessionClientError TEST START");
270 auto userSession = std::make_shared<PerUserSession>(MAIN_USER_ID);
271 auto imc = InputMethodController::GetInstance();
272 sptr<InputMethodCoreStub> core = new InputMethodCoreStub();
273
274 auto clientInfo = userSession->GetClientInfo(imc->clientInfo_.client->AsObject());
275 EXPECT_EQ(clientInfo, nullptr);
276
277 clientInfo = userSession->GetCurClientInfo();
278 EXPECT_EQ(clientInfo, nullptr);
279
280 bool clientInfoIsNull = userSession->IsCurClientFocused(INVALID_PROCESS_ID, INVALID_USER_ID);
281 EXPECT_FALSE(clientInfoIsNull);
282
283 clientInfo = userSession->GetClientInfo(INVALID_USER_ID);
284 EXPECT_EQ(clientInfo, nullptr);
285
286 userSession->SetCurrentClient(nullptr);
287 userSession->OnUnfocused(0, 0);
288 int32_t ret = userSession->OnHideCurrentInput();
289 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
290 ret = userSession->OnShowCurrentInput();
291 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
292
293 userSession->SetCurrentClient(imc->clientInfo_.client);
294 ret = userSession->OnShowCurrentInput();
295 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
296 }
297
298 /**
299 * @tc.name: PerUserSessionParameterNullptr001
300 * @tc.desc: Test PerUserSession with parameter client nullptr.
301 * @tc.type: FUNC
302 * @tc.require: issuesI794QF
303 * @tc.author: Zhaolinglan
304 */
305 HWTEST_F(InputMethodPrivateMemberTest, PerUserSessionParameterNullptr001, TestSize.Level0)
306 {
307 IMSA_HILOGI("InputMethodPrivateMemberTest PerUserSessionParameterNullptr001 TEST START");
308 auto userSession = std::make_shared<PerUserSession>(MAIN_USER_ID);
309 sptr<IRemoteObject> agent = nullptr;
310 InputClientInfo clientInfo;
311 clientInfo.client = nullptr;
312 std::pair<int64_t, std::string> imeInfo;
313 int32_t ret = userSession->OnStartInput(clientInfo, agent, imeInfo);
314 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
315 ret = userSession->OnReleaseInput(nullptr);
316 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
317 auto client = userSession->GetClientInfo(nullptr);
318 EXPECT_EQ(client, nullptr);
319 }
320
321 /**
322 * @tc.name: PerUserSessionParameterNullptr003
323 * @tc.desc: Test PerUserSession with parameter nullptr.
324 * @tc.type: FUNC
325 * @tc.require: issuesI794QF
326 * @tc.author: Zhaolinglan
327 */
328 HWTEST_F(InputMethodPrivateMemberTest, PerUserSessionParameterNullptr003, TestSize.Level0)
329 {
330 IMSA_HILOGI("InputMethodPrivateMemberTest PerUserSessionParameterNullptr003 TEST START");
331 auto userSession = std::make_shared<PerUserSession>(MAIN_USER_ID);
332 sptr<InputMethodCoreStub> core = new InputMethodCoreStub();
333 userSession->OnClientDied(nullptr);
334 userSession->OnImeDied(nullptr, ImeType::IME);
335 bool isShowKeyboard = false;
336 userSession->UpdateClientInfo(nullptr,
337 {
338 { UpdateFlag::ISSHOWKEYBOARD, isShowKeyboard }
339 });
340 int32_t ret = userSession->RemoveIme(nullptr, ImeType::IME);
341 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
342 }
343
344 /**
345 * @tc.name: SA_ImeCfgManagerTest_002
346 * @tc.desc: getImeCfg failed
347 * @tc.type: FUNC
348 * @tc.require:
349 * @tc.author: chenyu
350 */
351 HWTEST_F(InputMethodPrivateMemberTest, SA_ImeCfgManagerTest_002, TestSize.Level0)
352 {
353 IMSA_HILOGI("InputMethodPrivateMemberTest SA_ImeCfgManagerTest_002 TEST START");
354 ImeCfgManager cfgManager;
355 auto cfg = cfgManager.GetImeCfg(100);
356 EXPECT_TRUE(cfg.currentSubName.empty());
357 EXPECT_TRUE(cfg.currentIme.empty());
358 }
359
360 /**
361 * @tc.name: SA_SwitchByCombinationKey_001
362 * @tc.desc: keycode = MMI::KeyEvent::KEYCODE_0
363 * @tc.type: FUNC
364 * @tc.require:
365 * @tc.author: chenyu
366 */
367 HWTEST_F(InputMethodPrivateMemberTest, SA_SwitchByCombinationKey_001, TestSize.Level0)
368 {
369 IMSA_HILOGI("InputMethodPrivateMemberTest SA_SwitchByCombinationKey_001 TEST START");
370 ImeCfgManager cfgManager;
371 auto ret = service_->SwitchByCombinationKey(0);
372 EXPECT_EQ(ret, ErrorCode::ERROR_EX_UNSUPPORTED_OPERATION);
373 }
374
375 /**
376 * @tc.name: SA_SwitchByCombinationKey_002
377 * @tc.desc: SwitchLanguage()/SwitchMode():GetImeInfo failed
378 * @tc.type: FUNC
379 * @tc.require:
380 * @tc.author: chenyu
381 */
382 HWTEST_F(InputMethodPrivateMemberTest, SA_SwitchByCombinationKey_002, TestSize.Level0)
383 {
384 IMSA_HILOGI("InputMethodPrivateMemberTest SA_SwitchByCombinationKey_002 TEST START");
385 ImeCfgManager cfgManager;
386 auto ret = service_->SwitchByCombinationKey(KeyboardEvent::SHIFT_RIGHT_MASK);
387 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
388 ret = service_->SwitchByCombinationKey(KeyboardEvent::CAPS_MASK);
389 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
390 }
391
392 /**
393 * @tc.name: SA_SwitchByCombinationKey_003
394 * @tc.desc: SwitchLanguage()/SwitchMode():is newIme
395 * @tc.type: FUNC
396 * @tc.require:
397 * @tc.author: chenyu
398 */
399 HWTEST_F(InputMethodPrivateMemberTest, SA_SwitchByCombinationKey_003, TestSize.Level0)
400 {
401 IMSA_HILOGI("InputMethodPrivateMemberTest SA_SwitchByCombinationKey_003 TEST START");
402 ImeCfgManager cfgManager;
403 FullImeInfo info;
404 info.isNewIme = true;
405 info.prop = { .name = "testBundleName" };
406 info.subProps = { { .id = "testSubName" } };
407 FullImeInfoManager::GetInstance().fullImeInfos_.insert({ MAIN_USER_ID, { info } });
408 ImeCfgManager::GetInstance().imeConfigs_.push_back(
409 { MAIN_USER_ID, "testBundleName/testExtName", "testSubName", false });
410 auto ret = service_->SwitchByCombinationKey(KeyboardEvent::SHIFT_RIGHT_MASK);
411 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
412 ret = service_->SwitchByCombinationKey(KeyboardEvent::CAPS_MASK);
413 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
414 }
415
416 /**
417 * @tc.name: SA_SwitchByCombinationKey_004
418 * @tc.desc: SwitchLanguage():info.subProp.language == "French"
419 * @tc.type: FUNC
420 * @tc.require:
421 * @tc.author: chenyu
422 */
423 HWTEST_F(InputMethodPrivateMemberTest, SA_SwitchByCombinationKey_004, TestSize.Level0)
424 {
425 IMSA_HILOGI("InputMethodPrivateMemberTest SA_SwitchByCombinationKey_004 TEST START");
426 FullImeInfo info;
427 info.prop = { .name = "testBundleName", .id = "testExtName" };
428 info.subProps = {
429 { .name = "testBundleName", .id = "testSubName", .language = "French" }
430 };
431 FullImeInfoManager::GetInstance().fullImeInfos_.insert({ MAIN_USER_ID, { info } });
432 ImeCfgManager::GetInstance().imeConfigs_.push_back(
433 { MAIN_USER_ID, "testBundleName/testExtName", "testSubName", false });
434 auto ret = service_->SwitchByCombinationKey(KeyboardEvent::SHIFT_RIGHT_MASK);
435 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
436 }
437
438 /**
439 * @tc.name: SA_SwitchByCombinationKey_005
440 * @tc.desc: SwitchLanguage()/SwitchMode():FindTargetSubtypeByCondition failed
441 * @tc.type: FUNC
442 * @tc.require:
443 * @tc.author: chenyu
444 */
445 HWTEST_F(InputMethodPrivateMemberTest, SA_SwitchByCombinationKey_005, TestSize.Level0)
446 {
447 IMSA_HILOGI("InputMethodPrivateMemberTest SA_SwitchByCombinationKey_005 TEST START");
448 FullImeInfo info;
449 info.prop = { .name = "testBundleName", .id = "testExtName" };
450 info.subProps = {
451 { .name = "testBundleName", .id = "testSubName", .mode = "upper", .language = "english" }
452 };
453 FullImeInfoManager::GetInstance().fullImeInfos_.insert({ MAIN_USER_ID, { info } });
454 ImeCfgManager::GetInstance().imeConfigs_.push_back(
455 { MAIN_USER_ID, "testBundleName/testExtName", "testSubName", false });
456 auto ret = service_->SwitchByCombinationKey(KeyboardEvent::SHIFT_RIGHT_MASK);
457 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
458 ret = service_->SwitchByCombinationKey(KeyboardEvent::CAPS_MASK);
459 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
460 }
461
462 /**
463 * @tc.name: SA_SwitchByCombinationKey_006
464 * @tc.desc: SwitchLanguage()/SwitchMode():StartInputService() failed
465 * @tc.type: FUNC
466 * @tc.require:
467 * @tc.author: chenyu
468 */
469 HWTEST_F(InputMethodPrivateMemberTest, SA_SwitchByCombinationKey_006, TestSize.Level0)
470 {
471 IMSA_HILOGI("InputMethodPrivateMemberTest SA_SwitchByCombinationKey_006 TEST START");
472 FullImeInfo info;
473 info.prop = { .name = "testBundleName", .id = "testExtName" };
474 info.subProps = {
475 { .name = "testBundleName", .id = "testSubName", .mode = "upper", .language = "english" },
476 { .name = "testBundleName", .id = "testSubName1", .mode = "lower", .language = "chinese" }
477 };
478 FullImeInfoManager::GetInstance().fullImeInfos_.insert({ MAIN_USER_ID, { info } });
479
480 ImeCfgManager::GetInstance().imeConfigs_.push_back(
481 { MAIN_USER_ID, "testBundleName/testExtName", "testSubName", false });
482 // english->chinese
483 auto ret = service_->SwitchByCombinationKey(KeyboardEvent::SHIFT_RIGHT_MASK);
484 EXPECT_EQ(ret, ErrorCode::ERROR_IMSA_REBOOT_OLD_IME_NOT_STOP);
485 // lower->upper
486 ret = service_->SwitchByCombinationKey(KeyboardEvent::CAPS_MASK);
487 EXPECT_EQ(ret, ErrorCode::ERROR_IMSA_REBOOT_OLD_IME_NOT_STOP);
488 }
489
490 /**
491 * @tc.name: SA_SwitchByCombinationKey_007
492 * @tc.desc: SwitchType():StartInputService() failed
493 * @tc.type: FUNC
494 * @tc.require:
495 * @tc.author: chenyu
496 */
497 HWTEST_F(InputMethodPrivateMemberTest, SA_SwitchByCombinationKey_007, TestSize.Level0)
498 {
499 IMSA_HILOGI("InputMethodPrivateMemberTest SA_SwitchByCombinationKey_007 TEST START");
500 auto userId = TddUtil::GetCurrentUserId();
501 service_->userId_ = userId;
502 std::vector<Property> props;
503 InputMethodController::GetInstance()->ListInputMethod(props);
504 if (props.size() == 1) {
505 auto ret = service_->SwitchByCombinationKey(KeyboardEvent::SHIFT_RIGHT_MASK | KeyboardEvent::CTRL_RIGHT_MASK);
506 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
507 }
508 }
509
510 /**
511 * @tc.name: SA_SwitchByCombinationKey_008
512 * @tc.desc: SwitchType():find_if failed
513 * @tc.type: FUNC
514 * @tc.require:
515 * @tc.author: chenyu
516 */
517 HWTEST_F(InputMethodPrivateMemberTest, SA_SwitchByCombinationKey_008, TestSize.Level0)
518 {
519 IMSA_HILOGI("InputMethodPrivateMemberTest SA_SwitchByCombinationKey_008 TEST START");
520 auto userId = TddUtil::GetCurrentUserId();
521 service_->userId_ = userId;
522 auto prop = InputMethodController::GetInstance()->GetCurrentInputMethod();
523 auto subProp = InputMethodController::GetInstance()->GetCurrentInputMethodSubtype();
524 ImeCfgManager::GetInstance().imeConfigs_.push_back({ userId, prop->name + "/" + prop->id, subProp->id, false });
525 std::vector<Property> props;
526 InputMethodController::GetInstance()->ListInputMethod(props);
527 if (props.size() == 1) {
528 auto ret = service_->SwitchByCombinationKey(KeyboardEvent::SHIFT_RIGHT_MASK | KeyboardEvent::CTRL_RIGHT_MASK);
529 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
530 }
531 }
532
533 /**
534 * @tc.name: SA_testReleaseInput_001
535 * @tc.desc: client is nullptr
536 * @tc.type: FUNC
537 * @tc.require:
538 * @tc.author: chenyu
539 */
540 HWTEST_F(InputMethodPrivateMemberTest, SA_testReleaseInput_001, TestSize.Level0)
541 {
542 IMSA_HILOGI("InputMethodPrivateMemberTest SA_testReleaseInput_001 TEST START");
543 auto ret = service_->ReleaseInput(nullptr);
544 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
545 }
546
547 /**
548 * @tc.name: III_TestGetCurrentInputMethodSubtype_001
549 * @tc.desc:
550 * @tc.type: FUNC
551 * @tc.require:
552 * @tc.author: chenyu
553 */
554 HWTEST_F(InputMethodPrivateMemberTest, III_TestGetCurrentSubtype_001, TestSize.Level0)
555 {
556 IMSA_HILOGI("InputMethodPrivateMemberTest III_TestGetCurrentInputMethodSubtype_001 TEST START");
557 // currentIme is empty
558 auto currentUserId = TddUtil::GetCurrentUserId();
559 auto subProp = ImeInfoInquirer::GetInstance().GetCurrentSubtype(currentUserId);
560 EXPECT_TRUE(subProp == nullptr);
561
562 // subName is not find
563 auto currentProp = InputMethodController::GetInstance()->GetCurrentInputMethod();
564 ImeCfgManager::GetInstance().imeConfigs_.push_back(
565 { currentUserId, currentProp->name + "/" + currentProp->id, "tt", false });
566 subProp = ImeInfoInquirer::GetInstance().GetCurrentSubtype(currentUserId);
567 ASSERT_TRUE(subProp != nullptr);
568 EXPECT_TRUE(subProp->name == currentProp->name);
569
570 // get correct subProp
571 auto currentSubProp = InputMethodController::GetInstance()->GetCurrentInputMethodSubtype();
572 ImeCfgManager::GetInstance().imeConfigs_.clear();
573 ImeCfgManager::GetInstance().imeConfigs_.push_back(
574 { currentUserId, currentProp->name + "/" + currentProp->id, currentSubProp->id, false });
575 subProp = ImeInfoInquirer::GetInstance().GetCurrentSubtype(currentUserId);
576 ASSERT_TRUE(subProp != nullptr);
577 EXPECT_TRUE(subProp->id == currentSubProp->id);
578 }
579
580 /**
581 * @tc.name: III_TestGetCurrentInputMethod_001
582 * @tc.desc:
583 * @tc.type: FUNC
584 * @tc.require:
585 * @tc.author: chenyu
586 */
587 HWTEST_F(InputMethodPrivateMemberTest, III_TestGetCurrentIme_001, TestSize.Level0)
588 {
589 IMSA_HILOGI("InputMethodPrivateMemberTest III_TestGetCurrentInputMethod_001 TEST START");
590 // currentIme is empty
591 auto currentUserId = TddUtil::GetCurrentUserId();
592 auto prop = ImeInfoInquirer::GetInstance().GetCurrentInputMethod(currentUserId);
593 EXPECT_TRUE(prop == nullptr);
594
595 // get correct prop
596 auto currentProp = InputMethodController::GetInstance()->GetCurrentInputMethod();
597 ImeCfgManager::GetInstance().imeConfigs_.push_back(
598 { currentUserId, currentProp->name + "/" + currentProp->id, currentProp->id, false });
599 prop = ImeInfoInquirer::GetInstance().GetCurrentInputMethod(currentUserId);
600 ASSERT_TRUE(prop != nullptr);
601 EXPECT_TRUE(prop->id == currentProp->id);
602 }
603
604 /**
605 * @tc.name: III_TestListEnabledInputMethod_001
606 * @tc.desc:
607 * @tc.type: FUNC
608 * @tc.require:
609 * @tc.author: chenyu
610 */
611 HWTEST_F(InputMethodPrivateMemberTest, III_TestListEnabledInputMethod_001, TestSize.Level0)
612 {
613 IMSA_HILOGI("InputMethodPrivateMemberTest III_TestListEnabledInputMethod_001 TEST START");
614 // currentIme is empty
615 std::vector<Property> props;
616 auto currentUserId = TddUtil::GetCurrentUserId();
617 auto ret = ImeInfoInquirer::GetInstance().ListEnabledInputMethod(currentUserId, props, false);
618 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
619 }
620
621 /**
622 * @tc.name: III_TestListCurrentInputMethodSubtype_001
623 * @tc.desc:
624 * @tc.type: FUNC
625 * @tc.require:
626 * @tc.author: chenyu
627 */
628 HWTEST_F(InputMethodPrivateMemberTest, III_TestListCurrentInputMethodSubtype_001, TestSize.Level0)
629 {
630 IMSA_HILOGI("InputMethodPrivateMemberTest III_TestListCurrentInputMethodSubtype_001 TEST START");
631 // currentIme is empty
632 std::vector<SubProperty> subProps;
633 auto currentUserId = TddUtil::GetCurrentUserId();
634 auto ret = ImeInfoInquirer::GetInstance().ListCurrentInputMethodSubtype(currentUserId, subProps);
635 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
636 }
637
638 /**
639 * @tc.name: III_TestListInputMethod_001
640 * @tc.desc: status is error
641 * @tc.type: FUNC
642 * @tc.require:
643 * @tc.author: chenyu
644 */
645 HWTEST_F(InputMethodPrivateMemberTest, III_TestListInputMethod_001, TestSize.Level0)
646 {
647 IMSA_HILOGI("InputMethodPrivateMemberTest III_TestListInputMethod_001 TEST START");
648 std::vector<Property> props;
649 auto ret = ImeInfoInquirer::GetInstance().ListInputMethod(60, InputMethodStatus(10), props, false);
650 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
651 }
652
653 /**
654 * @tc.name: III_TestIsNewExtInfos_001
655 * @tc.desc: has no metadata name = SUBTYPE_PROFILE_METADATA_NAME
656 * @tc.type: FUNC
657 * @tc.require:
658 * @tc.author: chenyu
659 */
660 HWTEST_F(InputMethodPrivateMemberTest, III_TestIsNewExtInfos_001, TestSize.Level0)
661 {
662 IMSA_HILOGI("InputMethodPrivateMemberTest III_TestIsNewExtInfos_001 TEST START");
663 ExtensionAbilityInfo extInfo;
664 std::vector<SubProperty> subProps;
665 auto ret = ImeInfoInquirer::GetInstance().ListInputMethodSubtype(50, extInfo, subProps);
666 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
667 }
668
669 /**
670 * @tc.name: ICM_TestDeleteImeCfg_001
671 * @tc.desc: delete ime cfg correctly
672 * @tc.type: FUNC
673 * @tc.require:
674 * @tc.author: chenyu
675 */
676 HWTEST_F(InputMethodPrivateMemberTest, ICM_TestDeleteImeCfg_001, TestSize.Level0)
677 {
678 IMSA_HILOGI("InputMethodPrivateMemberTest ICM_TestDeleteImeCfg_001 TEST START");
679 ImeCfgManager::GetInstance().imeConfigs_.push_back({ 100, "testBundleName", "testSubName", false });
680 ImeCfgManager::GetInstance().DeleteImeCfg(100);
681 EXPECT_TRUE(ImeCfgManager::GetInstance().imeConfigs_.empty());
682 }
683
684 /**
685 * @tc.name: WMSConnectObserver_001
686 * @tc.desc:
687 * @tc.type: FUNC
688 * @tc.require:
689 * @tc.author: chenyu
690 */
691 HWTEST_F(InputMethodPrivateMemberTest, WMSConnectObserver_001, TestSize.Level0)
692 {
693 IMSA_HILOGI("InputMethodPrivateMemberTest WMSConnectObserver_001 TEST START");
694 WmsConnectionObserver observer(nullptr);
695 WmsConnectionObserver::connectedUserId_.clear();
696 int32_t userId = 100;
697 int32_t screenId = 0;
698
699 observer.OnConnected(userId, screenId);
700 EXPECT_EQ(WmsConnectionObserver::connectedUserId_.size(), 1);
701 EXPECT_TRUE(WmsConnectionObserver::IsWmsConnected(userId));
702
703 int32_t userId1 = 102;
704 observer.OnConnected(userId1, screenId);
705 EXPECT_EQ(WmsConnectionObserver::connectedUserId_.size(), 2);
706 EXPECT_TRUE(WmsConnectionObserver::IsWmsConnected(userId1));
707
708 observer.OnConnected(userId, screenId);
709 EXPECT_EQ(WmsConnectionObserver::connectedUserId_.size(), 2);
710
711 observer.OnDisconnected(userId, screenId);
712 EXPECT_EQ(WmsConnectionObserver::connectedUserId_.size(), 1);
713 EXPECT_FALSE(WmsConnectionObserver::IsWmsConnected(userId));
714 }
715
716 /**
717 * @tc.name: IMC_testDeactivateClient
718 * @tc.desc: DeactivateClient
719 * @tc.type: FUNC
720 * @tc.require:
721 * @tc.author: chenyu
722 */
723 HWTEST_F(InputMethodPrivateMemberTest, IMC_testDeactivateClient, TestSize.Level0)
724 {
725 IMSA_HILOGI("InputMethodPrivateMemberTest IMC_testDeactivateClient Test START");
726 auto imc = InputMethodController::GetInstance();
727 imc->agent_ = std::make_shared<InputMethodAgentStub>();
728 MessageParcel data;
729 data.WriteRemoteObject(imc->agent_->AsObject());
730 imc->agentObject_ = data.ReadRemoteObject();
731 imc->clientInfo_.state = ClientState::ACTIVE;
732 imc->DeactivateClient();
733 EXPECT_EQ(imc->clientInfo_.state, ClientState::INACTIVE);
734 EXPECT_NE(imc->agent_, nullptr);
735 EXPECT_NE(imc->agentObject_, nullptr);
736 }
737
738 /**
739 * @tc.name: testIsPanelShown
740 * @tc.desc: Test Panel Shown.
741 * @tc.type: FUNC
742 */
743 HWTEST_F(InputMethodPrivateMemberTest, testIsPanelShown, TestSize.Level0)
744 {
745 IMSA_HILOGI("InputMethodPrivateMemberTest PerUserSessionParameterNullptr003 TEST START");
746 auto userSession = std::make_shared<PerUserSession>(MAIN_USER_ID);
747 PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
748 bool flag = true;
749 auto ret = userSession->IsPanelShown(panelInfo, flag);
750 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
751 }
752
753 /**
754 * @tc.name: TestGetDefaultInputMethod_001
755 * @tc.desc: TestGetDefaultInputMethod
756 * @tc.type: FUNC
757 * @tc.require:
758 */
759 HWTEST_F(InputMethodPrivateMemberTest, TestGetDefaultInputMethod_001, TestSize.Level0)
760 {
761 IMSA_HILOGI("InputMethodPrivateMemberTest TestGetDefaultInputMethod_001 TEST START");
762 // currentIme is empty
763 std::shared_ptr<Property> prop;
764 auto currentUserId = TddUtil::GetCurrentUserId();
765 auto ret = ImeInfoInquirer::GetInstance().GetDefaultInputMethod(currentUserId, prop, false);
766 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
767 }
768
769 /**
770 * @tc.name: TestGetDefaultInputMethod_002
771 * @tc.desc: TestGetDefaultInputMethod
772 * @tc.type: FUNC
773 * @tc.require:
774 */
775 HWTEST_F(InputMethodPrivateMemberTest, TestGetDefaultInputMethod_002, TestSize.Level0)
776 {
777 IMSA_HILOGI("InputMethodPrivateMemberTest TestGetDefaultInputMethod_002 TEST START");
778 // currentIme is empty
779 std::shared_ptr<Property> prop;
780 auto currentUserId = TddUtil::GetCurrentUserId();
781 auto ret = ImeInfoInquirer::GetInstance().GetDefaultInputMethod(currentUserId, prop, true);
782 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
783 }
784
785 /**
786 * @tc.name: TestGetResMgr
787 * @tc.desc: GetResMgr
788 * @tc.type: FUNC
789 * @tc.require:
790 */
791 HWTEST_F(InputMethodPrivateMemberTest, TestGetResMgr, TestSize.Level0)
792 {
793 IMSA_HILOGI("InputMethodPrivateMemberTest TestGetResMgr TEST START");
794 // currentIme is empty
795 auto ret = ImeInfoInquirer::GetInstance().GetResMgr("/test");
796 EXPECT_TRUE(ret != nullptr);
797 }
798
799 /**
800 * @tc.name: TestQueryFullImeInfo
801 * @tc.desc: QueryFullImeInfo
802 * @tc.type: FUNC
803 * @tc.require:
804 */
805 HWTEST_F(InputMethodPrivateMemberTest, TestQueryFullImeInfo, TestSize.Level0)
806 {
807 IMSA_HILOGI("InputMethodPrivateMemberTest TestQueryFullImeInfo TEST START");
808 auto currentUserId = TddUtil::GetCurrentUserId();
809 std::vector<FullImeInfo> infos;
810 auto ret = ImeInfoInquirer::GetInstance().QueryFullImeInfo(currentUserId, infos);
811 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
812 }
813
814 /**
815 * @tc.name: TestIsInputMethod
816 * @tc.desc: IsInputMethod
817 * @tc.type: FUNC
818 * @tc.require:
819 */
820 HWTEST_F(InputMethodPrivateMemberTest, TestIsInputMethod, TestSize.Level0)
821 {
822 IMSA_HILOGI("InputMethodPrivateMemberTest TestIsInputMethod TEST START");
823 auto currentUserId = TddUtil::GetCurrentUserId();
824 auto bundleName = "testBundleName1";
825 auto ret = ImeInfoInquirer::GetInstance().IsInputMethod(currentUserId, bundleName);
826 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
827 }
828
829 /**
830 @tc.name: TestHandlePackageEvent
831 @tc.desc: TestHandlePackageEvent
832 @tc.type: FUNC
833 @tc.require:
834 */
835 HWTEST_F(InputMethodPrivateMemberTest, TestHandlePackageEvent, TestSize.Level0)
836 {
837 // msg is nullptr
838 auto *msg = new Message(MessageID::MSG_ID_PACKAGE_REMOVED, nullptr);
839 auto ret = service_->HandlePackageEvent(msg);
840 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
841 MessageHandler::Instance()->SendMessage(msg);
842
843 // PARCELABLE failed
844 MessageParcel *parcel1 = new (std::nothrow) MessageParcel();
845 auto bundleName = "testBundleName1";
846 parcel1->WriteString(bundleName);
847 auto msg1 = std::make_shared<Message>(MessageID::MSG_ID_PACKAGE_REMOVED, parcel1);
848 auto ret1 = service_->HandlePackageEvent(msg1.get());
849 EXPECT_EQ(ret1, ErrorCode::ERROR_EX_PARCELABLE);
850
851 // userId is not same
852 auto parcel2 = new (std::nothrow) MessageParcel();
853 auto userId = 50;
854 service_->userId_ = 60;
855 parcel2->WriteInt32(userId);
856 parcel2->WriteString(bundleName);
857 auto msg2 = std::make_shared<Message>(MessageID::MSG_ID_PACKAGE_REMOVED, parcel2);
858 auto ret2 = service_->HandlePackageEvent(msg2.get());
859 EXPECT_EQ(ret2, ErrorCode::NO_ERROR);
860
861 // remove bundle not current ime
862 auto parcel3 = new (std::nothrow) MessageParcel();
863 service_->userId_ = userId;
864 ImeCfgManager::GetInstance().imeConfigs_.push_back({ 60, "testBundleName/testExtName", "testSubName", false });
865 parcel3->WriteInt32(userId);
866 parcel3->WriteString(bundleName);
867 auto msg3 = std::make_shared<Message>(MessageID::MSG_ID_PACKAGE_REMOVED, parcel3);
868 auto ret3 = service_->HandlePackageEvent(msg3.get());
869 EXPECT_EQ(ret3, ErrorCode::NO_ERROR);
870 }
871
872 /**
873 * @tc.name: testGetSubProperty001
874 * @tc.desc: Test testGetSubProperty
875 * @tc.type: FUNC
876 * @tc.require:
877 */
878 HWTEST_F(InputMethodPrivateMemberTest, testGetSubProperty001, TestSize.Level0)
879 {
880 IMSA_HILOGI("InputMethodPrivateMemberTest testGetSubProperty001 START");
881 int32_t userId = 100;
882 const std::string subName = "defaultImeId";
883 SubProperty subProp;
884 const std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> extInfos;
885 auto ret = ImeInfoInquirer::GetInstance().GetSubProperty(userId, subName, extInfos, subProp);
886 EXPECT_EQ(ret, ErrorCode::ERROR_PACKAGE_MANAGER);
887 }
888
889 /**
890 * @tc.name: testGetSubProperty002
891 * @tc.desc: Test testGetSubProperty
892 * @tc.type: FUNC
893 * @tc.require:
894 */
895 HWTEST_F(InputMethodPrivateMemberTest, testGetSubProperty002, TestSize.Level0)
896 {
897 IMSA_HILOGI("InputMethodPrivateMemberTest testGetSubProperty002 START");
898 int32_t userId = 100;
899 const std::string subName = "defaultImeId";
900 SubProperty subProp;
901 ExtensionAbilityInfo extInfo;
902 extInfo.name = "test";
903 const std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> extInfos = { extInfo };
904 auto ret = ImeInfoInquirer::GetInstance().GetSubProperty(userId, subName, extInfos, subProp);
905 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
906 }
907
908 /**
909 * @tc.name: testListInputMethodSubtype
910 * @tc.desc: Test ListInputMethodSubtype
911 * @tc.type: FUNC
912 * @tc.require:
913 */
914 HWTEST_F(InputMethodPrivateMemberTest, testListInputMethodSubtype, TestSize.Level0)
915 {
916 IMSA_HILOGI("InputMethodPrivateMemberTest testListInputMethodSubtype START");
917 int32_t userId = 100;
918 const std::string subName = "defaultImeId";
919 std::vector<SubProperty> subProps;
920 const std::vector<OHOS::AppExecFwk::ExtensionAbilityInfo> extInfos;
921 auto ret = ImeInfoInquirer::GetInstance().ListInputMethodSubtype(userId, extInfos, subProps);
922 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
923 }
924
925 /**
926 * @tc.name: testGetInputMethodConfig
927 * @tc.desc: Test GetInputMethodConfig
928 * @tc.type: FUNC
929 * @tc.require:
930 */
931 HWTEST_F(InputMethodPrivateMemberTest, testGetInputMethodConfig, TestSize.Level0)
932 {
933 IMSA_HILOGI("InputMethodPrivateMemberTest testGetInputMethodConfig START");
934 int32_t userId = 100;
935 AppExecFwk::ElementName inputMethodConfig;
936 auto ret = ImeInfoInquirer::GetInstance().GetInputMethodConfig(userId, inputMethodConfig);
937 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
938 }
939
940 /**
941 * @tc.name: TestOnSecurityChange
942 * @tc.desc: Test OnSecurityChange
943 * @tc.type: FUNC
944 * @tc.require: issuesI794QF
945 */
946 HWTEST_F(InputMethodPrivateMemberTest, TestOnSecurityChange, TestSize.Level0)
947 {
948 IMSA_HILOGI("InputMethodPrivateMemberTest TestOnSecurityChange TEST START");
949 auto userSession = std::make_shared<PerUserSession>(MAIN_USER_ID);
950 auto imc = InputMethodController::GetInstance();
951 int32_t ret = userSession->ShowKeyboard(imc->clientInfo_.client);
952 userSession->OnSecurityChange(10);
953 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
954 ret = userSession->ShowKeyboard(nullptr);
955 EXPECT_EQ(ret, ErrorCode::ERROR_IMSA_NULLPTR);
956 }
957
958 /**
959 * @tc.name: TestServiceStartInputType
960 * @tc.desc: Test ServiceStartInputType
961 * @tc.type: FUNC
962 * @tc.require:
963 */
964 HWTEST_F(InputMethodPrivateMemberTest, TestServiceStartInputType, TestSize.Level0)
965 {
966 auto ret = service_->ExitCurrentInputType();
967 EXPECT_NE(ret, ErrorCode::NO_ERROR);
968 ret = service_->StartInputType(InputType::NONE);
969 EXPECT_NE(ret, ErrorCode::NO_ERROR);
970 const PanelInfo panelInfo;
971 bool isShown = false;
972 ret = service_->IsPanelShown(panelInfo, isShown);
973 EXPECT_EQ(ret, ErrorCode::ERROR_STATUS_SYSTEM_PERMISSION);
974 }
975
976 /**
977 * @tc.name: TestIsSupported
978 * @tc.desc: Test IsSupported
979 * @tc.type: FUNC
980 * @tc.require:
981 */
982 HWTEST_F(InputMethodPrivateMemberTest, TestIsSupported, TestSize.Level0)
983 {
984 auto ret = InputTypeManager::GetInstance().IsSupported(InputType::NONE);
985 EXPECT_FALSE(ret);
986 }
987
988 /**
989 * @tc.name: TestGetImeByInputType
990 * @tc.desc: Test GetImeByInputType
991 * @tc.type: FUNC
992 * @tc.require:
993 */
994 HWTEST_F(InputMethodPrivateMemberTest, TestGetImeByInputType, TestSize.Level0)
995 {
996 ImeIdentification ime;
997 auto ret = InputTypeManager::GetInstance().GetImeByInputType(InputType::NONE, ime);
998 EXPECT_EQ(ret, ErrorCode::ERROR_PARSE_CONFIG_FILE);
999 }
1000
1001 /**
1002 * @tc.name: TestOnUnRegisteredProxyIme
1003 * @tc.desc: Test OnUnRegisteredProxyIme
1004 * @tc.type: FUNC
1005 * @tc.require: issuesI794QF
1006 */
1007 HWTEST_F(InputMethodPrivateMemberTest, TestOnUnRegisteredProxyIme, TestSize.Level0)
1008 {
1009 IMSA_HILOGI("InputMethodPrivateMemberTest TestOnUnRegisteredProxyIme TEST START");
1010 auto userSession = std::make_shared<PerUserSession>(MAIN_USER_ID);
1011 UnRegisteredType type = UnRegisteredType::REMOVE_PROXY_IME;
1012 const sptr<IInputMethodCore> core;
1013 auto ret = userSession->OnUnRegisteredProxyIme(type, core);
1014 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1015 type = UnRegisteredType::SWITCH_PROXY_IME_TO_IME;
1016 ret = userSession->OnUnRegisteredProxyIme(type, core);
1017 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_BOUND);
1018 ret = userSession->RemoveCurrentClient();
1019 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
1020 }
1021
1022 /**
1023 * @tc.name: TestIsInputTypeSupported
1024 * @tc.desc: Test IsInputTypeSupported
1025 * @tc.type: FUNC
1026 * @tc.require: issuesI794QF
1027 */
1028 HWTEST_F(InputMethodPrivateMemberTest, TestIsInputTypeSupported, TestSize.Level0)
1029 {
1030 IMSA_HILOGI("InputMethodPrivateMemberTest TestIsInputTypeSupported TEST START");
1031 InputType type = InputType::SECURITY_INPUT;
1032 auto ret = service_->IsInputTypeSupported(type);
1033 EXPECT_FALSE(ret);
1034 }
1035
1036 /**
1037 * @tc.name: TestStartInputType
1038 * @tc.desc: Test StartInputType
1039 * @tc.type: FUNC
1040 * @tc.require: issuesI794QF
1041 */
1042 HWTEST_F(InputMethodPrivateMemberTest, TestStartInputType, TestSize.Level0)
1043 {
1044 IMSA_HILOGI("InputMethodPrivateMemberTest TestStartInputType TEST START");
1045 InputType type = InputType::NONE;
1046 auto ret = service_->StartInputType(type);
1047 EXPECT_NE(ret, ErrorCode::NO_ERROR);
1048 }
1049
1050 /**
1051 * @tc.name: TestFullImeInfoManager_Update001
1052 * @tc.desc: Test FullImeInfoManager_Update
1053 * @tc.type: FUNC
1054 * @tc.require:
1055 * @tc.author: chenyu
1056 */
1057 HWTEST_F(InputMethodPrivateMemberTest, TestFullImeInfoManager_Update001, TestSize.Level0)
1058 {
1059 IMSA_HILOGI("InputMethodPrivateMemberTest TestFullImeInfoManager_Update001 TEST START");
1060 std::string bundleName = "ttttttttt";
1061 auto ret = FullImeInfoManager::GetInstance().Update(MAIN_USER_ID, bundleName);
1062 EXPECT_EQ(ret, ErrorCode::ERROR_PACKAGE_MANAGER);
1063 }
1064
1065 /**
1066 * @tc.name: TestFullImeInfoManager_Update002
1067 * @tc.desc: Test FullImeInfoManager_Update
1068 * @tc.type: FUNC
1069 * @tc.require:
1070 * @tc.author: chenyu
1071 */
1072 HWTEST_F(InputMethodPrivateMemberTest, TestFullImeInfoManager_Update002, TestSize.Level0)
1073 {
1074 IMSA_HILOGI("InputMethodPrivateMemberTest TestFullImeInfoManager_Update002 TEST START");
1075 std::string bundleName = "testBundleName";
1076 auto ret = FullImeInfoManager::GetInstance().Update(MAIN_USER_ID, bundleName);
1077 EXPECT_EQ(ret, ErrorCode::ERROR_PACKAGE_MANAGER);
1078 }
1079
1080 /**
1081 * @tc.name: TestFullImeInfoManager_Has
1082 * @tc.desc: Test FullImeInfoManager_Has
1083 * @tc.type: FUNC
1084 * @tc.require:
1085 * @tc.author: chenyu
1086 */
1087 HWTEST_F(InputMethodPrivateMemberTest, TestFullImeInfoManager_Has, TestSize.Level0)
1088 {
1089 IMSA_HILOGI("InputMethodPrivateMemberTest TestFullImeInfoManager_Has TEST START");
1090 int32_t userId = 1234567890;
1091 std::string bundleName = "ttttttttttt";
1092 auto ret = FullImeInfoManager::GetInstance().Has(userId, bundleName);
1093 EXPECT_FALSE(ret);
1094 }
1095
1096 /**
1097 * @tc.name: TestFullImeInfoManager_Get
1098 * @tc.desc: Test FullImeInfoManager_Get
1099 * @tc.type: FUNC
1100 * @tc.require:
1101 * @tc.author: chenyu
1102 */
1103 HWTEST_F(InputMethodPrivateMemberTest, TestFullImeInfoManager_Get, TestSize.Level0)
1104 {
1105 IMSA_HILOGI("InputMethodPrivateMemberTest TestFullImeInfoManager_Get TEST START");
1106 FullImeInfo info;
1107 info.isNewIme = true;
1108 info.prop = { .name = "testBundleName" };
1109 info.subProps = { { .id = "testSubName" } };
1110 FullImeInfoManager::GetInstance().fullImeInfos_.insert({ MAIN_USER_ID, { info } });
1111 uint32_t invalidTokenId = 4294967295;
1112 auto ret = FullImeInfoManager::GetInstance().Get(MAIN_USER_ID, invalidTokenId);
1113 EXPECT_EQ(ret, "");
1114 }
1115
1116 /**
1117 * @tc.name: TestIsMatch
1118 * @tc.desc: CombinationKey IsMatch
1119 * @tc.type: FUNC
1120 * @tc.require:
1121 */
1122 HWTEST_F(InputMethodPrivateMemberTest, TestIsMatch, TestSize.Level0)
1123 {
1124 IMSA_HILOGI("InputMethodPrivateMemberTest CombinationKey::IsMatch TEST START");
1125 uint32_t state = 50; // Assuming 50 is a valid state for this combination key.
1126 int32_t value = 100;
1127 CombinationKeyFunction invliadCombinationKey = static_cast<CombinationKeyFunction>(value);
1128 auto ret = CombinationKey::IsMatch(invliadCombinationKey, state);
1129 EXPECT_FALSE(ret);
1130 }
1131
1132 /**
1133 * @tc.name: test_OnFocusedAndOnUnfocused001
1134 * @tc.desc: test OnFocusedAndOnUnfocused
1135 * @tc.type: FUNC
1136 */
1137 HWTEST_F(InputMethodPrivateMemberTest, test_OnFocusedAndOnUnfocused001, TestSize.Level0)
1138 {
1139 IMSA_HILOGI("test_OnFocusedAndOnUnfocused001 TEST START");
1140 const sptr<Rosen::FocusChangeInfo> focusChangeInfo = nullptr;
1141 FocusHandle handle;
1142 FocusChangedListener focusChangedListener(handle);
1143 focusChangedListener.OnFocused(focusChangeInfo);
1144 focusChangedListener.OnUnfocused(focusChangeInfo);
1145 EXPECT_EQ(focusChangeInfo, nullptr);
1146 }
1147
1148 /**
1149 * @tc.name: test_OnFocusedAndOnUnfocused002
1150 * @tc.desc: test KeyEvent Callback.
1151 * @tc.type: FUNC
1152 */
1153 HWTEST_F(InputMethodPrivateMemberTest, test_OnFocusedAndOnUnfocused002, TestSize.Level0)
1154 {
1155 IMSA_HILOGI("test_OnFocusedAndOnUnfocused002 TEST START");
1156 const sptr<Rosen::FocusChangeInfo> focusChangeInfo = new Rosen::FocusChangeInfo();
1157 FocusHandle handle = nullptr;
1158 FocusChangedListener focusChangedListener(handle);
1159 focusChangedListener.OnFocused(focusChangeInfo);
1160 focusChangedListener.OnUnfocused(focusChangeInfo);
1161 EXPECT_EQ(handle, nullptr);
1162 }
1163
1164 /**
1165 * @tc.name: test_WmsConnectionObserver
1166 * @tc.desc: test KeyEvent Callback.
1167 * @tc.type: FUNC
1168 */
1169 HWTEST_F(InputMethodPrivateMemberTest, test_WmsConnectionObserver, TestSize.Level0)
1170 {
1171 IMSA_HILOGI("test_WmsConnectionObserver TEST START");
1172 WmsConnectionObserver observer(nullptr);
1173 int32_t invalidUserId = 1234567890;
1174 observer.Remove(invalidUserId);
1175 ASSERT_EQ(observer.connectedUserId_.find(invalidUserId), observer.connectedUserId_.end());
1176 }
1177
1178 /**
1179 * @tc.name: BranchCoverage001
1180 * @tc.desc: BranchCoverage
1181 * @tc.type: FUNC
1182 */
1183 HWTEST_F(InputMethodPrivateMemberTest, BranchCoverage001, TestSize.Level0)
1184 {
1185 IMSA_HILOGI("InputMethodPrivateMemberTest BranchCoverage001 TEST START");
1186 auto userSession = std::make_shared<PerUserSession>(MAIN_USER_ID);
1187 sptr<IInputMethodCore> core = nullptr;
1188 sptr<IRemoteObject> agent = nullptr;
1189 pid_t pid { -1 };
1190 auto ret = userSession->UpdateImeData(core, agent, pid);
1191 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
1192
1193 InputClientInfo clientInfo;
1194 clientInfo.channel = nullptr;
1195 auto ret2 = service_->PrepareInput(INVALID_USER_ID, clientInfo);
1196 EXPECT_NE(ret2, ErrorCode::NO_ERROR);
1197
1198 clientInfo.config.inputAttribute.inputPattern = 7;
1199 clientInfo.isNotifyInputStart = false;
1200 ret2 = service_->CheckInputTypeOption(INVALID_USER_ID, clientInfo);
1201 EXPECT_NE(ret2, ErrorCode::NO_ERROR);
1202
1203 clientInfo.isNotifyInputStart = true;
1204 ret2 = service_->CheckInputTypeOption(INVALID_USER_ID, clientInfo);
1205 EXPECT_EQ(ret2, ErrorCode::ERROR_IMSA_USER_SESSION_NOT_FOUND);
1206
1207 const std::string bundleName;
1208 const std::string subName;
1209 SwitchTrigger trigger = SwitchTrigger::IMSA;
1210 ret2 = service_->SwitchInputMethod(bundleName, subName, trigger);
1211 EXPECT_EQ(ret2, ErrorCode::ERROR_BAD_PARAMETERS);
1212
1213 const std::shared_ptr<ImeInfo> info = nullptr;
1214 ret2 = service_->SwitchSubType(INVALID_USER_ID, info);
1215 EXPECT_NE(ret2, ErrorCode::NO_ERROR);
1216
1217 const SwitchInfo switchInfo;
1218 ret2 = service_->SwitchInputType(INVALID_USER_ID, switchInfo);
1219 EXPECT_NE(ret2, ErrorCode::NO_ERROR);
1220 }
1221
1222 /**
1223 * @tc.name: BranchCoverage002
1224 * @tc.desc: BranchCoverage
1225 * @tc.type: FUNC
1226 */
1227 HWTEST_F(InputMethodPrivateMemberTest, BranchCoverage002, TestSize.Level0)
1228 {
1229 IMSA_HILOGI("InputMethodPrivateMemberTest BranchCoverage002 TEST START");
1230 auto msgPtr = std::make_shared<Message>(0, nullptr);
1231 const OHOS::MiscServices::Message* msg = msgPtr.get();
1232 auto ret = service_->OnUserRemoved(msg);
1233 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
1234 ret = service_->OnUserStop(msg);
1235 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
1236 ret = service_->OnHideKeyboardSelf(msg);
1237 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
1238 ret = service_->HandlePackageEvent(msg);
1239 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
1240
1241 service_->HandleUserSwitched(INVALID_USER_ID);
1242
1243 const SwitchInfo switchInfo;
1244 UserSessionManager::GetInstance().RemoveUserSession(INVALID_USER_ID);
1245 auto ret2 = service_->OnStartInputType(INVALID_USER_ID, switchInfo, false);
1246 EXPECT_EQ(ret2, ErrorCode::ERROR_IMSA_USER_SESSION_NOT_FOUND);
1247
1248 bool needHide = false;
1249 auto ret3 = service_->IsCurrentIme(INVALID_USER_ID);
1250 service_->NeedHideWhenSwitchInputType(INVALID_USER_ID, needHide);
1251 EXPECT_FALSE(ret3);
1252 }
1253
1254 /**
1255 * @tc.name: BranchCoverage003
1256 * @tc.desc: BranchCoverage
1257 * @tc.type: FUNC
1258 */
1259 HWTEST_F(InputMethodPrivateMemberTest, BranchCoverage003, TestSize.Level0)
1260 {
1261 IMSA_HILOGI("InputMethodPrivateMemberTest BranchCoverage003 TEST START");
1262 UserSessionManager::GetInstance().RemoveUserSession(INVALID_USER_ID);
1263 const std::string bundleName = "";
1264 std::vector<AppExecFwk::ExtensionAbilityInfo> extInfos;
1265 ImeInfoInquirer inquirer;
1266 auto ret = inquirer.GetExtInfosByBundleName(INVALID_USER_ID, bundleName, extInfos);
1267 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
1268
1269 auto ret2 = inquirer.ListInputMethodInfo(INVALID_USER_ID);
1270 EXPECT_TRUE(ret2.empty());
1271
1272 auto ret3 = inquirer.GetDumpInfo(INVALID_USER_ID);
1273 EXPECT_TRUE(ret3 == "");
1274
1275 std::vector<Property> props = {};
1276 ret = inquirer.ListEnabledInputMethod(INVALID_USER_ID, props, false);
1277 EXPECT_NE(ret, ErrorCode::NO_ERROR);
1278
1279 ret = inquirer.ListDisabledInputMethod(INVALID_USER_ID, props, false);
1280 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1281
1282 SwitchInfo switchInfo;
1283 uint32_t cacheCount = -1;
1284 ret = inquirer.GetSwitchInfoBySwitchCount(switchInfo, INVALID_USER_ID, false, cacheCount);
1285 EXPECT_NE(ret, ErrorCode::NO_ERROR);
1286 }
1287
1288 /**
1289 * @tc.name: BranchCoverage004
1290 * @tc.desc: BranchCoverage
1291 * @tc.type: FUNC
1292 */
1293 HWTEST_F(InputMethodPrivateMemberTest, BranchCoverage004, TestSize.Level0)
1294 {
1295 IMSA_HILOGI("InputMethodPrivateMemberTest BranchCoverage003 TEST START");
1296 auto userSession = std::make_shared<PerUserSession>(MAIN_USER_ID);
1297 sptr<SettingsDataObserver> observer;
1298 std::shared_ptr<DataShare::DataShareHelper> helper;
1299 std::string invaildString = "";
1300 pid_t pid { -1 };
1301 auto ret = SettingsDataUtils::GetInstance()->RegisterObserver(observer);
1302 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
1303 ret = SettingsDataUtils::GetInstance()->GetStringValue(invaildString, invaildString, invaildString);
1304 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
1305 ret = userSession->OnHideInput(nullptr);
1306 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOCUSED);
1307 ret = userSession->OnShowInput(nullptr);
1308 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOCUSED);
1309 ret = userSession->RemoveClient(nullptr, false, false, false);
1310 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
1311 ret = userSession->BindClientWithIme(nullptr, ImeType::IME, false);
1312 userSession->UnBindClientWithIme(nullptr, false, false);
1313 EXPECT_EQ(ret, ErrorCode::ERROR_IMSA_NULLPTR);
1314 ret = userSession->OnSetCallingWindow(0, nullptr);
1315 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOCUSED);
1316
1317 auto ret2 = SettingsDataUtils::GetInstance()->ReleaseDataShareHelper(helper);
1318 EXPECT_TRUE(ret2);
1319 ret2 = SettingsDataUtils::GetInstance()->SetStringValue(invaildString, invaildString, invaildString);
1320 EXPECT_FALSE(ret2);
1321 ret2 = SettingsDataUtils::GetInstance()->EnableIme(INVALID_USER_ID, invaildString);
1322 EXPECT_FALSE(ret2);
1323 ret2 = userSession->IsCurClientFocused(-1, -1);
1324 EXPECT_FALSE(ret2);
1325 ret2 = userSession->IsCurClientUnFocused(-1, -1);
1326 EXPECT_FALSE(ret2);
1327 auto startRet = userSession->StartInputService(nullptr);
1328 EXPECT_EQ(startRet, ErrorCode::ERROR_IMSA_IME_TO_START_NULLPTR);
1329 startRet = userSession->StartIme(nullptr, false);
1330 EXPECT_EQ(startRet, ErrorCode::ERROR_IMSA_IME_TO_START_NULLPTR);
1331
1332 auto ret3 = userSession->GetClientInfo(nullptr);
1333 EXPECT_EQ(ret3, nullptr);
1334 ret3 = userSession->GetClientInfo(pid);
1335 EXPECT_EQ(ret3, nullptr);
1336 }
1337 } // namespace MiscServices
1338 } // namespace OHOS