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 "ime_cfg_manager.h"
18 #include "ime_info_inquirer.h"
19 #include "input_method_controller.h"
20 #include "input_method_system_ability.h"
21 #include "peruser_session.h"
22 #include "wms_connection_observer.h"
23 #undef private
24 #include <gtest/gtest.h>
25 #include <sys/time.h>
26 #include <unistd.h>
27
28 #include <string>
29 #include <vector>
30
31 #include "application_info.h"
32 #include "global.h"
33 #include "i_input_method_agent.h"
34 #include "i_input_method_core.h"
35 #include "ime_cfg_manager.h"
36 #include "input_method_agent_proxy.h"
37 #include "input_method_agent_stub.h"
38 #include "input_method_core_stub.h"
39 #include "keyboard_event.h"
40 #include "os_account_manager.h"
41 #include "tdd_util.h"
42
43 using namespace testing::ext;
44 namespace OHOS {
45 namespace MiscServices {
46 constexpr uint32_t MAX_SUBTYPE_NUM = 256;
47 class InputMethodPrivateMemberTest : public testing::Test {
48 public:
49 static void SetUpTestCase(void);
50 static void TearDownTestCase(void);
51 void SetUp();
52 void TearDown();
53 static sptr<InputMethodSystemAbility> service_;
54 };
55 constexpr std::int32_t MAIN_USER_ID = 100;
SetUpTestCase(void)56 void InputMethodPrivateMemberTest::SetUpTestCase(void)
57 {
58 IMSA_HILOGI("InputMethodPrivateMemberTest::SetUpTestCase");
59 service_ = new InputMethodSystemAbility();
60 service_->OnStart();
61 }
62
TearDownTestCase(void)63 void InputMethodPrivateMemberTest::TearDownTestCase(void)
64 {
65 service_->OnStop();
66 TddUtil::KillImsaProcess();
67 IMSA_HILOGI("InputMethodPrivateMemberTest::TearDownTestCase");
68 }
69
SetUp(void)70 void InputMethodPrivateMemberTest::SetUp(void)
71 {
72 IMSA_HILOGI("InputMethodPrivateMemberTest::SetUp");
73 ImeCfgManager::GetInstance().imeConfigs_.clear();
74 ImeInfoInquirer::GetInstance().SetCurrentImeInfo(nullptr);
75 }
76
TearDown(void)77 void InputMethodPrivateMemberTest::TearDown(void)
78 {
79 IMSA_HILOGI("InputMethodPrivateMemberTest::TearDown");
80 ImeCfgManager::GetInstance().imeConfigs_.clear();
81 ImeInfoInquirer::GetInstance().SetCurrentImeInfo(nullptr);
82 }
83 sptr<InputMethodSystemAbility> InputMethodPrivateMemberTest::service_;
84
85 /**
86 * @tc.name: SA_TestOnStart
87 * @tc.desc: SA OnStart.
88 * @tc.type: FUNC
89 * @tc.require:
90 */
91 HWTEST_F(InputMethodPrivateMemberTest, SA_TestOnStart, TestSize.Level0)
92 {
93 InputMethodSystemAbility ability;
94 ability.state_ = ServiceRunningState::STATE_RUNNING;
95 ability.OnStart();
96 EXPECT_EQ(ability.userSession_, nullptr);
97 }
98
99 /**
100 * @tc.name: SA_GetExtends
101 * @tc.desc: SA GetExtends.
102 * @tc.type: FUNC
103 * @tc.require: issuesI640YZ
104 */
105 HWTEST_F(InputMethodPrivateMemberTest, SA_GetExtends, TestSize.Level0)
106 {
107 constexpr int32_t metaDataNums = 5;
108 ImeInfoInquirer inquirer;
109 std::vector<Metadata> metaData;
110 Metadata metadata[metaDataNums] = { { "language", "english", "" }, { "mode", "mode", "" },
111 { "locale", "local", "" }, { "icon", "icon", "" }, { "", "", "" } };
112 for (auto const &data : metadata) {
113 metaData.emplace_back(data);
114 }
115 auto subProperty = inquirer.GetExtends(metaData);
116 EXPECT_EQ(subProperty.language, "english");
117 EXPECT_EQ(subProperty.mode, "mode");
118 EXPECT_EQ(subProperty.locale, "local");
119 EXPECT_EQ(subProperty.icon, "icon");
120 }
121
122 /**
123 * @tc.name: SA_TestOnPackageRemoved
124 * @tc.desc: SA_TestOnPackageRemoved
125 * @tc.type: FUNC
126 * @tc.require:
127 */
128 HWTEST_F(InputMethodPrivateMemberTest, SA_TestOnPackageRemoved, TestSize.Level0)
129 {
130 // msg is nullptr
131 auto *msg = new Message(MessageID::MSG_ID_PACKAGE_REMOVED, nullptr);
132 auto ret = service_->OnPackageRemoved(msg);
133 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
134 MessageHandler::Instance()->SendMessage(msg);
135
136 // PARCELABLE failed
137 MessageParcel *parcel1 = new (std::nothrow) MessageParcel();
138 auto bundleName = "testBundleName1";
139 parcel1->WriteString(bundleName);
140 auto msg1 = std::make_shared<Message>(MessageID::MSG_ID_PACKAGE_REMOVED, parcel1);
141 auto ret1 = service_->OnPackageRemoved(msg1.get());
142 EXPECT_EQ(ret1, ErrorCode::ERROR_EX_PARCELABLE);
143
144 // userId is not same
145 auto parcel2 = new (std::nothrow) MessageParcel();
146 auto userId = 50;
147 service_->userId_ = 60;
148 parcel2->WriteInt32(userId);
149 parcel2->WriteString(bundleName);
150 auto msg2 = std::make_shared<Message>(MessageID::MSG_ID_PACKAGE_REMOVED, parcel2);
151 auto ret2 = service_->OnPackageRemoved(msg2.get());
152 EXPECT_EQ(ret2, ErrorCode::NO_ERROR);
153
154 //remove bundle not current ime
155 auto parcel3 = new (std::nothrow) MessageParcel();
156 service_->userId_ = userId;
157 ImeCfgManager::GetInstance().imeConfigs_.push_back({ 60, "testBundleName/testExtName", "testSubName" });
158 parcel3->WriteInt32(userId);
159 parcel3->WriteString(bundleName);
160 auto msg3 = std::make_shared<Message>(MessageID::MSG_ID_PACKAGE_REMOVED, parcel3);
161 auto ret3 = service_->OnPackageRemoved(msg3.get());
162 EXPECT_EQ(ret3, ErrorCode::NO_ERROR);
163 }
164
165 /**
166 * @tc.name: SA_TestOnUserStarted
167 * @tc.desc: SA_TestOnUserStarted.
168 * @tc.type: FUNC
169 * @tc.require:
170 */
171 HWTEST_F(InputMethodPrivateMemberTest, SA_TestOnUserStarted, TestSize.Level0)
172 {
173 // msg is nullptr
174 auto *msg = new Message(MessageID::MSG_ID_USER_START, nullptr);
175 auto ret = service_->OnUserStarted(msg);
176 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
177 MessageHandler::Instance()->SendMessage(msg);
178
179 // userId is same
180 service_->userId_ = 50;
181 MessageParcel *parcel1 = new MessageParcel();
182 parcel1->WriteInt32(50);
183 auto msg1 = std::make_shared<Message>(MessageID::MSG_ID_USER_START, parcel1);
184 auto ret1 = service_->OnUserStarted(msg1.get());
185 EXPECT_EQ(ret1, ErrorCode::NO_ERROR);
186
187 //start ime failed
188 service_->userId_ = 50;
189 auto currentUserId = TddUtil::GetCurrentUserId();
190 ImeCfgManager::GetInstance().imeConfigs_.push_back({ currentUserId, "testBundleName/testExtName", "testSubName" });
191 auto parcel2 = new MessageParcel();
192 parcel2->WriteInt32(currentUserId);
193 auto msg2 = std::make_shared<Message>(MessageID::MSG_ID_USER_START, parcel2);
194 WmsConnectionObserver observer(nullptr);
195 observer.OnConnected(100, 0);
196 auto ret2 = service_->OnUserStarted(msg2.get());
197 EXPECT_EQ(ret2, ErrorCode::ERROR_IME_START_FAILED);
198 }
199
200 /**
201 * @tc.name: SA_TestOnUserRemoved
202 * @tc.desc: SA_TestOnUserRemoved.
203 * @tc.type: FUNC
204 * @tc.require:
205 */
206 HWTEST_F(InputMethodPrivateMemberTest, SA_TestOnUserRemoved, TestSize.Level0)
207 {
208 // msg is nullptr
209 auto *msg = new Message(MessageID::MSG_ID_USER_REMOVED, nullptr);
210 auto ret = service_->OnUserRemoved(msg);
211 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
212 MessageHandler::Instance()->SendMessage(msg);
213
214 // move userId
215 MessageParcel *parcel1 = new MessageParcel();
216 parcel1->WriteInt32(60);
217 auto msg1 = std::make_shared<Message>(MessageID::MSG_ID_USER_REMOVED, parcel1);
218 auto ret1 = service_->OnUserRemoved(msg1.get());
219 EXPECT_EQ(ret1, ErrorCode::NO_ERROR);
220 }
221
222 /**
223 * @tc.name: SA_ListInputMethodInfoWithInexistentUserId
224 * @tc.desc: SA ListInputMethodInfo With Inexistent UserId.
225 * @tc.type: FUNC
226 * @tc.require: issuesI669E8
227 */
228 HWTEST_F(InputMethodPrivateMemberTest, SA_ListInputMethodInfoWithInexistentUserId, TestSize.Level0)
229 {
230 ImeInfoInquirer inquirer;
231 constexpr int32_t userId = 1;
232 auto inputMethodInfos = inquirer.ListInputMethodInfo(userId);
233 EXPECT_TRUE(inputMethodInfos.empty());
234 }
235
236 /**
237 * @tc.name: IMC_ListInputMethodCommonWithErrorStatus
238 * @tc.desc: IMC ListInputMethodCommon With Error Status.
239 * @tc.type: FUNC
240 * @tc.require: issuesI669E8
241 */
242 HWTEST_F(InputMethodPrivateMemberTest, IMC_ListInputMethodCommonWithErrorStatus, TestSize.Level0)
243 {
244 std::vector<Property> props;
245 auto ret = InputMethodController::GetInstance()->ListInputMethodCommon(static_cast<InputMethodStatus>(5), props);
246 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
247 EXPECT_TRUE(props.empty());
248 }
249
250 /**
251 * @tc.name: PerUserSessionCoreOrAgentNullptr
252 * @tc.desc: Test PerUserSession with core nullptr.
253 * @tc.type: FUNC
254 * @tc.require: issuesI794QF
255 * @tc.author: Zhaolinglan
256 */
257 HWTEST_F(InputMethodPrivateMemberTest, PerUserSessionCoreOrAgentNullptr, TestSize.Level0)
258 {
259 IMSA_HILOGI("InputMethodPrivateMemberTest PerUserSessionCoreOrAgentNullptr TEST START");
260 auto userSession = std::make_shared<PerUserSession>(MAIN_USER_ID);
261 auto imc = InputMethodController::GetInstance();
262 int32_t ret = userSession->ShowKeyboard(imc->clientInfo_.client);
263 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
264 ret = userSession->HideKeyboard(imc->clientInfo_.client);
265 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
266 ret = userSession->InitInputControlChannel();
267 EXPECT_EQ(ret, ErrorCode::ERROR_IME_NOT_STARTED);
268 userSession->DeactivateIme("", "");
269 userSession->StopCurrentIme();
270 ret = userSession->SwitchSubtype({});
271 EXPECT_EQ(ret, ErrorCode::ERROR_IME_NOT_STARTED);
272 }
273
274 /**
275 * @tc.name: PerUserSessionClientError
276 * @tc.desc: Test PerUserSession with client error.
277 * @tc.type: FUNC
278 * @tc.require: issuesI794QF
279 * @tc.author: Zhaolinglan
280 */
281 HWTEST_F(InputMethodPrivateMemberTest, PerUserSessionClientError, TestSize.Level0)
282 {
283 IMSA_HILOGI("InputMethodPrivateMemberTest PerUserSessionClientError TEST START");
284 auto userSession = std::make_shared<PerUserSession>(MAIN_USER_ID);
285 auto imc = InputMethodController::GetInstance();
286 sptr<InputMethodCoreStub> core = new InputMethodCoreStub();
287
288 auto clientInfo = userSession->GetClientInfo(imc->clientInfo_.client->AsObject());
289 EXPECT_EQ(clientInfo, nullptr);
290
291 userSession->SetCurrentClient(nullptr);
292 userSession->OnUnfocused(0, 0);
293 int32_t ret = userSession->OnHideCurrentInput();
294 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
295 ret = userSession->OnShowCurrentInput();
296 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
297
298 userSession->SetCurrentClient(imc->clientInfo_.client);
299 ret = userSession->OnShowCurrentInput();
300 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
301 }
302
303 /**
304 * @tc.name: PerUserSessionParameterNullptr001
305 * @tc.desc: Test PerUserSession with parameter client nullptr.
306 * @tc.type: FUNC
307 * @tc.require: issuesI794QF
308 * @tc.author: Zhaolinglan
309 */
310 HWTEST_F(InputMethodPrivateMemberTest, PerUserSessionParameterNullptr001, TestSize.Level0)
311 {
312 IMSA_HILOGI("InputMethodPrivateMemberTest PerUserSessionParameterNullptr001 TEST START");
313 auto userSession = std::make_shared<PerUserSession>(MAIN_USER_ID);
314 sptr<IRemoteObject> agent = nullptr;
315 InputClientInfo clientInfo;
316 int32_t ret = userSession->OnStartInput(clientInfo, agent);
317 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
318 ret = userSession->OnReleaseInput(nullptr);
319 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
320 auto client = userSession->GetClientInfo(nullptr);
321 EXPECT_EQ(client, nullptr);
322 bool result = userSession->ActivateIme(nullptr, true);
323 EXPECT_FALSE(result);
324 }
325
326 /**
327 * @tc.name: PerUserSessionParameterNullptr003
328 * @tc.desc: Test PerUserSession with parameter nullptr.
329 * @tc.type: FUNC
330 * @tc.require: issuesI794QF
331 * @tc.author: Zhaolinglan
332 */
333 HWTEST_F(InputMethodPrivateMemberTest, PerUserSessionParameterNullptr003, TestSize.Level0)
334 {
335 IMSA_HILOGI("InputMethodPrivateMemberTest PerUserSessionParameterNullptr003 TEST START");
336 auto userSession = std::make_shared<PerUserSession>(MAIN_USER_ID);
337 sptr<InputMethodCoreStub> core = new InputMethodCoreStub();
338 userSession->OnClientDied(nullptr);
339 userSession->OnImeDied(nullptr, ImeType::IME);
340 bool isShowKeyboard = false;
341 userSession->UpdateClientInfo(nullptr, { { UpdateFlag::ISSHOWKEYBOARD, isShowKeyboard } });
342 int32_t ret = userSession->RemoveIme(nullptr, ImeType::IME);
343 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
344 }
345
346 /**
347 * @tc.name: SA_ImeCfgManagerTest_002
348 * @tc.desc: getImeCfg failed
349 * @tc.type: FUNC
350 * @tc.require:
351 * @tc.author: chenyu
352 */
353 HWTEST_F(InputMethodPrivateMemberTest, SA_ImeCfgManagerTest_002, TestSize.Level0)
354 {
355 IMSA_HILOGI("InputMethodPrivateMemberTest SA_ImeCfgManagerTest_002 TEST START");
356 ImeCfgManager cfgManager;
357 auto cfg = cfgManager.GetImeCfg(100);
358 EXPECT_TRUE(cfg.currentSubName.empty());
359 EXPECT_TRUE(cfg.currentIme.empty());
360 }
361
362 /**
363 * @tc.name: SA_SwitchByCombinationKey_001
364 * @tc.desc: keycode = MMI::KeyEvent::KEYCODE_0
365 * @tc.type: FUNC
366 * @tc.require:
367 * @tc.author: chenyu
368 */
369 HWTEST_F(InputMethodPrivateMemberTest, SA_SwitchByCombinationKey_001, TestSize.Level0)
370 {
371 IMSA_HILOGI("InputMethodPrivateMemberTest SA_SwitchByCombinationKey_001 TEST START");
372 ImeCfgManager cfgManager;
373 auto ret = service_->SwitchByCombinationKey(0);
374 EXPECT_EQ(ret, ErrorCode::ERROR_EX_UNSUPPORTED_OPERATION);
375 }
376
377 /**
378 * @tc.name: SA_SwitchByCombinationKey_002
379 * @tc.desc: SwitchLanguage()/SwitchMode():GetImeInfo failed
380 * @tc.type: FUNC
381 * @tc.require:
382 * @tc.author: chenyu
383 */
384 HWTEST_F(InputMethodPrivateMemberTest, SA_SwitchByCombinationKey_002, TestSize.Level0)
385 {
386 IMSA_HILOGI("InputMethodPrivateMemberTest SA_SwitchByCombinationKey_002 TEST START");
387 ImeCfgManager cfgManager;
388 auto ret = service_->SwitchByCombinationKey(KeyboardEvent::SHIFT_RIGHT_MASK);
389 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
390 ret = service_->SwitchByCombinationKey(KeyboardEvent::CAPS_MASK);
391 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
392 }
393
394 /**
395 * @tc.name: SA_SwitchByCombinationKey_003
396 * @tc.desc: SwitchLanguage()/SwitchMode():is newIme
397 * @tc.type: FUNC
398 * @tc.require:
399 * @tc.author: chenyu
400 */
401 HWTEST_F(InputMethodPrivateMemberTest, SA_SwitchByCombinationKey_003, TestSize.Level0)
402 {
403 IMSA_HILOGI("InputMethodPrivateMemberTest SA_SwitchByCombinationKey_003 TEST START");
404 ImeCfgManager cfgManager;
405 service_->userId_ = 50;
406 auto info = std::make_shared<ImeInfo>();
407 info->isNewIme = true;
408 info->prop = { .name = "testBundleName" };
409 info->subProp = { .id = "testSubName" };
410 ImeInfoInquirer::GetInstance().SetCurrentImeInfo(info);
411 ImeCfgManager::GetInstance().imeConfigs_.push_back({ 50, "testBundleName/testExtName", "testSubName" });
412 auto ret = service_->SwitchByCombinationKey(KeyboardEvent::SHIFT_RIGHT_MASK);
413 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
414 ret = service_->SwitchByCombinationKey(KeyboardEvent::CAPS_MASK);
415 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
416 }
417
418 /**
419 * @tc.name: SA_SwitchByCombinationKey_004
420 * @tc.desc: SwitchLanguage():info.subProp.language == "French"
421 * @tc.type: FUNC
422 * @tc.require:
423 * @tc.author: chenyu
424 */
425 HWTEST_F(InputMethodPrivateMemberTest, SA_SwitchByCombinationKey_004, TestSize.Level0)
426 {
427 IMSA_HILOGI("InputMethodPrivateMemberTest SA_SwitchByCombinationKey_004 TEST START");
428 service_->userId_ = 50;
429 auto info = std::make_shared<ImeInfo>();
430 info->prop = { .name = "testBundleName", .id = "testExtName" };
431 info->subProp = { .name = "testBundleName", .id = "testSubName", .language = "French" };
432 ImeInfoInquirer::GetInstance().SetCurrentImeInfo(info);
433 ImeCfgManager::GetInstance().imeConfigs_.push_back({ 50, "testBundleName/testExtName", "testSubName" });
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 service_->userId_ = 50;
449 auto info = std::make_shared<ImeInfo>();
450 info->prop = { .name = "testBundleName", .id = "testExtName" };
451 info->subProp = {
452 .name = "testBundleName",
453 .id = "testSubName",
454 .mode = "upper",
455 .language = "english",
456 };
457 info->subProps = { { .name = "testBundleName", .id = "testSubName", .mode = "upper", .language = "english" } };
458 ImeInfoInquirer::GetInstance().SetCurrentImeInfo(info);
459 ImeCfgManager::GetInstance().imeConfigs_.push_back({ 50, "testBundleName/testExtName", "testSubName" });
460 auto ret = service_->SwitchByCombinationKey(KeyboardEvent::SHIFT_RIGHT_MASK);
461 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
462 ret = service_->SwitchByCombinationKey(KeyboardEvent::CAPS_MASK);
463 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
464 }
465
466 /**
467 * @tc.name: SA_SwitchByCombinationKey_006
468 * @tc.desc: SwitchLanguage()/SwitchMode():StartInputService() failed
469 * @tc.type: FUNC
470 * @tc.require:
471 * @tc.author: chenyu
472 */
473 HWTEST_F(InputMethodPrivateMemberTest, SA_SwitchByCombinationKey_006, TestSize.Level0)
474 {
475 IMSA_HILOGI("InputMethodPrivateMemberTest SA_SwitchByCombinationKey_006 TEST START");
476 service_->userId_ = 50;
477 auto info = std::make_shared<ImeInfo>();
478 info->prop = { .name = "testBundleName", .id = "testExtName" };
479 info->subProp = { .name = "testBundleName", .id = "testSubName", .mode = "upper", .language = "english" };
480 info->subProps = { { .name = "testBundleName", .id = "testSubName", .mode = "upper", .language = "english" },
481 { .name = "testBundleName", .id = "testSubName1", .mode = "lower", .language = "chinese" } };
482 ImeInfoInquirer::GetInstance().SetCurrentImeInfo(info);
483 ImeCfgManager::GetInstance().imeConfigs_.push_back({ 50, "testBundleName/testExtName", "testSubName" });
484 // english->chinese
485 auto ret = service_->SwitchByCombinationKey(KeyboardEvent::SHIFT_RIGHT_MASK);
486 EXPECT_EQ(ret, ErrorCode::ERROR_IME_START_FAILED);
487 // upper->lower
488 ret = service_->SwitchByCombinationKey(KeyboardEvent::CAPS_MASK);
489 EXPECT_EQ(ret, ErrorCode::ERROR_IME_START_FAILED);
490
491 info->subProp = { .name = "testBundleName", .id = "testSubName1", .mode = "upper", .language = "chinese" };
492 info->subProps = { { .name = "testBundleName", .id = "testSubName", .mode = "lower", .language = "english" },
493 { .name = "testBundleName", .id = "testSubName1", .mode = "lower", .language = "chinese" } };
494 ImeInfoInquirer::GetInstance().SetCurrentImeInfo(info);
495 ImeCfgManager::GetInstance().imeConfigs_.push_back({ 50, "testBundleName/testExtName", "testSubName1" });
496 // chinese->english
497 ret = service_->SwitchByCombinationKey(KeyboardEvent::SHIFT_RIGHT_MASK);
498 EXPECT_EQ(ret, ErrorCode::ERROR_IME_START_FAILED);
499 // lower->upper
500 ret = service_->SwitchByCombinationKey(KeyboardEvent::CAPS_MASK);
501 EXPECT_EQ(ret, ErrorCode::ERROR_IME_START_FAILED);
502 }
503
504 /**
505 * @tc.name: SA_SwitchByCombinationKey_007
506 * @tc.desc: SwitchType():StartInputService() failed
507 * @tc.type: FUNC
508 * @tc.require:
509 * @tc.author: chenyu
510 */
511 HWTEST_F(InputMethodPrivateMemberTest, SA_SwitchByCombinationKey_007, TestSize.Level0)
512 {
513 IMSA_HILOGI("InputMethodPrivateMemberTest SA_SwitchByCombinationKey_007 TEST START");
514 auto userId = TddUtil::GetCurrentUserId();
515 service_->userId_ = userId;
516 std::vector<Property> props;
517 InputMethodController::GetInstance()->ListInputMethod(props);
518 if (props.size() == 1) {
519 auto ret = service_->SwitchByCombinationKey(KeyboardEvent::SHIFT_RIGHT_MASK | KeyboardEvent::CTRL_RIGHT_MASK);
520 EXPECT_EQ(ret, ErrorCode::ERROR_IME_START_FAILED);
521 }
522 }
523
524 /**
525 * @tc.name: SA_SwitchByCombinationKey_008
526 * @tc.desc: SwitchType():find_if failed
527 * @tc.type: FUNC
528 * @tc.require:
529 * @tc.author: chenyu
530 */
531 HWTEST_F(InputMethodPrivateMemberTest, SA_SwitchByCombinationKey_008, TestSize.Level0)
532 {
533 IMSA_HILOGI("InputMethodPrivateMemberTest SA_SwitchByCombinationKey_008 TEST START");
534 auto userId = TddUtil::GetCurrentUserId();
535 service_->userId_ = userId;
536 auto prop = InputMethodController::GetInstance()->GetCurrentInputMethod();
537 auto subProp = InputMethodController::GetInstance()->GetCurrentInputMethodSubtype();
538 ImeCfgManager::GetInstance().imeConfigs_.push_back({ userId, prop->name + "/" + prop->id, subProp->id });
539 std::vector<Property> props;
540 InputMethodController::GetInstance()->ListInputMethod(props);
541 if (props.size() == 1) {
542 auto ret = service_->SwitchByCombinationKey(KeyboardEvent::SHIFT_RIGHT_MASK | KeyboardEvent::CTRL_RIGHT_MASK);
543 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
544 }
545 }
546
547 /**
548 * @tc.name: SA_testReleaseInput_001
549 * @tc.desc: client is nullptr
550 * @tc.type: FUNC
551 * @tc.require:
552 * @tc.author: chenyu
553 */
554 HWTEST_F(InputMethodPrivateMemberTest, SA_testReleaseInput_001, TestSize.Level0)
555 {
556 IMSA_HILOGI("InputMethodPrivateMemberTest SA_testReleaseInput_001 TEST START");
557 auto ret = service_->ReleaseInput(nullptr);
558 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
559 }
560
561 /**
562 * @tc.name: III_TestParseSubProp_001
563 * @tc.desc: json not contain label/id/icon/mode/locale
564 * @tc.type: FUNC
565 * @tc.require:
566 * @tc.author: chenyu
567 */
568 HWTEST_F(InputMethodPrivateMemberTest, III_TestParseSubProp_001, TestSize.Level0)
569 {
570 IMSA_HILOGI("InputMethodPrivateMemberTest III_TestParseSubProp_001 TEST START");
571 nlohmann::json js;
572 js["test"] = "test";
573 SubProperty subProp{};
574 ImeInfoInquirer::GetInstance().ParseSubProp(js, subProp);
575 EXPECT_TRUE(subProp.label.empty());
576 EXPECT_TRUE(subProp.icon.empty());
577 }
578
579 /**
580 * @tc.name: III_TestParseSubProp_002
581 * @tc.desc: json contain label/id/icon/mode/locale,but not correct type
582 * @tc.type: FUNC
583 * @tc.require:
584 * @tc.author: chenyu
585 */
586 HWTEST_F(InputMethodPrivateMemberTest, III_TestParseSubProp_002, TestSize.Level0)
587 {
588 IMSA_HILOGI("InputMethodPrivateMemberTest III_TestParseSubProp_002 TEST START");
589 nlohmann::json js;
590 js["label"] = 100;
591 js["id"] = 100;
592 js["icon"] = 100;
593 js["mode"] = 100;
594 js["locale"] = 100;
595 SubProperty subProp{};
596 ImeInfoInquirer::GetInstance().ParseSubProp(js, subProp);
597 EXPECT_TRUE(subProp.label.empty());
598 EXPECT_TRUE(subProp.icon.empty());
599 EXPECT_TRUE(subProp.id.empty());
600 EXPECT_TRUE(subProp.mode.empty());
601 EXPECT_TRUE(subProp.locale.empty());
602 }
603
604 /**
605 * @tc.name: III_TestParseSubProp_003
606 * @tc.desc: json is array, not contain subtypes
607 * @tc.type: FUNC
608 * @tc.require:
609 * @tc.author: chenyu
610 */
611 HWTEST_F(InputMethodPrivateMemberTest, III_TestParseSubProp_003, TestSize.Level0)
612 {
613 IMSA_HILOGI("InputMethodPrivateMemberTest III_TestParseSubProp_003 TEST START");
614 constexpr int32_t jsNum = 300;
615 nlohmann::json js;
616 for (uint32_t i = 0; i < jsNum; i++) {
617 nlohmann::json temp;
618 temp["label"] = 100;
619 js["test"].push_back(temp);
620 }
621 std::vector<SubProperty> subProps;
622 auto ret = ImeInfoInquirer::GetInstance().ParseSubProp(js, subProps);
623 EXPECT_FALSE(ret);
624 EXPECT_TRUE(subProps.empty());
625 }
626
627 /**
628 * @tc.name: III_TestParseSubProp_004
629 * @tc.desc: json contain subtypes, but not array
630 * @tc.type: FUNC
631 * @tc.require:
632 * @tc.author: chenyu
633 */
634 HWTEST_F(InputMethodPrivateMemberTest, III_TestParseSubProp_004, TestSize.Level0)
635 {
636 IMSA_HILOGI("InputMethodPrivateMemberTest III_TestParseSubProp_004 TEST START");
637 nlohmann::json js;
638 js["subtypes"] = 100;
639 std::vector<SubProperty> subProps;
640 auto ret = ImeInfoInquirer::GetInstance().ParseSubProp(js, subProps);
641 EXPECT_FALSE(ret);
642 EXPECT_TRUE(subProps.empty());
643 }
644
645 /**
646 * @tc.name: III_TestParseSubProp_005
647 * @tc.desc: json contain subtypes, is a empty array
648 * @tc.type: FUNC
649 * @tc.require:
650 * @tc.author: chenyu
651 */
652 HWTEST_F(InputMethodPrivateMemberTest, III_TestParseSubProp_005, TestSize.Level0)
653 {
654 IMSA_HILOGI("InputMethodPrivateMemberTest III_TestParseSubProp_005 TEST START");
655 nlohmann::json js;
656 js["subtypes"] = nlohmann::json::array();
657 std::vector<SubProperty> subProps;
658 auto ret = ImeInfoInquirer::GetInstance().ParseSubProp(js, subProps);
659 EXPECT_FALSE(ret);
660 EXPECT_TRUE(subProps.empty());
661 }
662
663 /**
664 * @tc.name: III_TestParseSubProp_006
665 * @tc.desc: json contain subtypes, is a array
666 * @tc.type: FUNC
667 * @tc.require:
668 * @tc.author: chenyu
669 */
670 HWTEST_F(InputMethodPrivateMemberTest, III_TestParseSubProp_006, TestSize.Level0)
671 {
672 IMSA_HILOGI("InputMethodPrivateMemberTest III_TestParseSubProp_006 TEST START");
673 constexpr int32_t jsNum = 1;
674 nlohmann::json js;
675 for (uint32_t i = 0; i < jsNum; i++) {
676 nlohmann::json temp;
677 temp["label"] = "label";
678 temp["id"] = "id";
679 temp["icon"] = 100;
680 temp["mode"] = "mode";
681 temp["locale"] = "locale";
682 js["subtypes"].push_back(temp);
683 }
684 std::vector<SubProperty> subProps;
685 auto ret = ImeInfoInquirer::GetInstance().ParseSubProp(js, subProps);
686 EXPECT_TRUE(ret);
687 EXPECT_EQ(subProps[0].label, "label");
688 EXPECT_EQ(subProps[0].id, "id");
689 EXPECT_TRUE(subProps[0].icon.empty());
690 EXPECT_EQ(subProps[0].mode, "mode");
691 EXPECT_EQ(subProps[0].locale, "locale");
692 }
693
694 /**
695 * @tc.name: III_TestParseSubProp_007
696 * @tc.desc: json is array, num >MAX_SUBTYPE_NUM
697 * @tc.type: FUNC
698 * @tc.require:
699 * @tc.author: chenyu
700 */
701 HWTEST_F(InputMethodPrivateMemberTest, III_TestParseSubProp_007, TestSize.Level0)
702 {
703 IMSA_HILOGI("InputMethodPrivateMemberTest III_TestParseSubProp_007 TEST START");
704 constexpr int32_t jsNum = 300;
705 nlohmann::json js;
706 for (uint32_t i = 0; i < jsNum; i++) {
707 nlohmann::json temp;
708 temp["label"] = 100;
709 js["subtypes"].push_back(temp);
710 }
711 std::vector<SubProperty> subProps;
712 ImeInfoInquirer::GetInstance().ParseSubProp(js, subProps);
713 EXPECT_EQ(subProps.size(), MAX_SUBTYPE_NUM);
714 }
715
716 /**
717 * @tc.name: III_TestParseSubProp_008
718 * @tc.desc: profiles is abnormal
719 * @tc.type: FUNC
720 * @tc.require:
721 * @tc.author: chenyu
722 */
723 HWTEST_F(InputMethodPrivateMemberTest, III_TestParseSubProp_008, TestSize.Level0)
724 {
725 IMSA_HILOGI("InputMethodPrivateMemberTest III_TestParseSubProp_008 TEST START");
726 std::vector<std::string> profiles;
727 std::vector<SubProperty> subProps;
728 auto ret = ImeInfoInquirer::GetInstance().ParseSubProp(profiles, subProps);
729 EXPECT_FALSE(ret);
730 profiles.emplace_back("AA");
731 profiles.emplace_back("BB");
732 ret = ImeInfoInquirer::GetInstance().ParseSubProp(profiles, subProps);
733 EXPECT_FALSE(ret);
734 }
735
736 /**
737 * @tc.name: III_TestGetCurrentInputMethodSubtype_001
738 * @tc.desc:
739 * @tc.type: FUNC
740 * @tc.require:
741 * @tc.author: chenyu
742 */
743 HWTEST_F(InputMethodPrivateMemberTest, III_TestGetCurrentSubtype_001, TestSize.Level0)
744 {
745 IMSA_HILOGI("InputMethodPrivateMemberTest III_TestGetCurrentInputMethodSubtype_001 TEST START");
746 // currentIme is empty
747 auto currentUserId = TddUtil::GetCurrentUserId();
748 auto subProp = ImeInfoInquirer::GetInstance().GetCurrentSubtype(currentUserId);
749 EXPECT_TRUE(subProp == nullptr);
750
751 // subName is not find
752 auto currentProp = InputMethodController::GetInstance()->GetCurrentInputMethod();
753 ImeCfgManager::GetInstance().imeConfigs_.push_back(
754 { currentUserId, currentProp->name + "/" + currentProp->id, "tt" });
755 subProp = ImeInfoInquirer::GetInstance().GetCurrentSubtype(currentUserId);
756 EXPECT_TRUE(subProp != nullptr);
757 EXPECT_TRUE(subProp->name == currentProp->name);
758
759 // get correct subProp
760 auto currentSubProp = InputMethodController::GetInstance()->GetCurrentInputMethodSubtype();
761 ImeCfgManager::GetInstance().imeConfigs_.push_back(
762 { currentUserId, currentProp->name + "/" + currentProp->id, currentSubProp->id });
763 subProp = ImeInfoInquirer::GetInstance().GetCurrentSubtype(currentUserId);
764 ASSERT_TRUE(subProp != nullptr);
765 EXPECT_TRUE(subProp->id == currentSubProp->id);
766 }
767
768 /**
769 * @tc.name: III_TestGetCurrentInputMethod_001
770 * @tc.desc:
771 * @tc.type: FUNC
772 * @tc.require:
773 * @tc.author: chenyu
774 */
775 HWTEST_F(InputMethodPrivateMemberTest, III_TestGetCurrentIme_001, TestSize.Level0)
776 {
777 IMSA_HILOGI("InputMethodPrivateMemberTest III_TestGetCurrentInputMethod_001 TEST START");
778 // currentIme is empty
779 auto currentUserId = TddUtil::GetCurrentUserId();
780 auto prop = ImeInfoInquirer::GetInstance().GetCurrentInputMethod(currentUserId);
781 EXPECT_TRUE(prop == nullptr);
782
783 // get correct prop
784 auto currentProp = InputMethodController::GetInstance()->GetCurrentInputMethod();
785 ImeCfgManager::GetInstance().imeConfigs_.push_back(
786 { currentUserId, currentProp->name + "/" + currentProp->id, "test" });
787 prop = ImeInfoInquirer::GetInstance().GetCurrentInputMethod(currentUserId);
788 ASSERT_TRUE(prop != nullptr);
789 EXPECT_TRUE(prop->id == currentProp->id);
790 }
791
792 /**
793 * @tc.name: III_TestListEnabledInputMethod_001
794 * @tc.desc:
795 * @tc.type: FUNC
796 * @tc.require:
797 * @tc.author: chenyu
798 */
799 HWTEST_F(InputMethodPrivateMemberTest, III_TestListEnabledInputMethod_001, TestSize.Level0)
800 {
801 IMSA_HILOGI("InputMethodPrivateMemberTest III_TestListEnabledInputMethod_001 TEST START");
802 // currentIme is empty
803 std::vector<Property> props;
804 auto currentUserId = TddUtil::GetCurrentUserId();
805 auto ret = ImeInfoInquirer::GetInstance().ListEnabledInputMethod(currentUserId, props, false);
806 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
807 }
808
809 /**
810 * @tc.name: III_TestListCurrentInputMethodSubtype_001
811 * @tc.desc:
812 * @tc.type: FUNC
813 * @tc.require:
814 * @tc.author: chenyu
815 */
816 HWTEST_F(InputMethodPrivateMemberTest, III_TestListCurrentInputMethodSubtype_001, TestSize.Level0)
817 {
818 IMSA_HILOGI("InputMethodPrivateMemberTest III_TestListCurrentInputMethodSubtype_001 TEST START");
819 // currentIme is empty
820 std::vector<SubProperty> subProps;
821 auto currentUserId = TddUtil::GetCurrentUserId();
822 auto ret = ImeInfoInquirer::GetInstance().ListCurrentInputMethodSubtype(currentUserId, subProps);
823 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
824 }
825
826 /**
827 * @tc.name: III_TestListInputMethod_001
828 * @tc.desc: status is error
829 * @tc.type: FUNC
830 * @tc.require:
831 * @tc.author: chenyu
832 */
833 HWTEST_F(InputMethodPrivateMemberTest, III_TestListInputMethod_001, TestSize.Level0)
834 {
835 IMSA_HILOGI("InputMethodPrivateMemberTest III_TestListInputMethod_001 TEST START");
836 std::vector<Property> props;
837 auto ret = ImeInfoInquirer::GetInstance().ListInputMethod(60, InputMethodStatus(10), props, false);
838 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
839 }
840
841 /**
842 * @tc.name: III_TestIsNewExtInfos_001
843 * @tc.desc: has no metadata name = SUBTYPE_PROFILE_METADATA_NAME
844 * @tc.type: FUNC
845 * @tc.require:
846 * @tc.author: chenyu
847 */
848 HWTEST_F(InputMethodPrivateMemberTest, III_TestIsNewExtInfos_001, TestSize.Level0)
849 {
850 IMSA_HILOGI("InputMethodPrivateMemberTest III_TestIsNewExtInfos_001 TEST START");
851 ExtensionAbilityInfo extInfo;
852 std::vector<SubProperty> subProps;
853 auto ret = ImeInfoInquirer::GetInstance().ListInputMethodSubtype(50, extInfo, subProps);
854 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
855 }
856
857 /**
858 * @tc.name: ICM_TestDeleteImeCfg_001
859 * @tc.desc: delete ime cfg correctly
860 * @tc.type: FUNC
861 * @tc.require:
862 * @tc.author: chenyu
863 */
864 HWTEST_F(InputMethodPrivateMemberTest, ICM_TestDeleteImeCfg_001, TestSize.Level0)
865 {
866 IMSA_HILOGI("InputMethodPrivateMemberTest ICM_TestDeleteImeCfg_001 TEST START");
867 ImeCfgManager::GetInstance().imeConfigs_.push_back({ 100, "testBundleName", "testSubName" });
868 ImeCfgManager::GetInstance().DeleteImeCfg(100);
869 EXPECT_TRUE(ImeCfgManager::GetInstance().imeConfigs_.empty());
870 }
871
872 /**
873 * @tc.name: ICM_TestWriteCacheFile_001
874 * @tc.desc: json is empty
875 * @tc.type: FUNC
876 * @tc.require:
877 * @tc.author: chenyu
878 */
879 HWTEST_F(InputMethodPrivateMemberTest, ICM_TestWriteCacheFile_001, TestSize.Level0)
880 {
881 IMSA_HILOGI("InputMethodPrivateMemberTest ICM_TestDeleteImeCfg_001 TEST START");
882 std::string path;
883 nlohmann::json jsonCfg;
884 auto ret = ImeCfgManager::GetInstance().Write(path, jsonCfg);
885 EXPECT_FALSE(ret);
886 }
887
888 /**
889 * @tc.name: ICM_TestFromJson_001
890 * @tc.desc: json is array, not contain "imeCfg_list"
891 * @tc.type: FUNC
892 * @tc.require:
893 * @tc.author: chenyu
894 */
895 HWTEST_F(InputMethodPrivateMemberTest, ICM_TestFromJson_001, TestSize.Level0)
896 {
897 IMSA_HILOGI("InputMethodPrivateMemberTest ICM_TestFromJson_001 TEST START");
898
899 constexpr int32_t jsNum = 2;
900 nlohmann::json js;
901 for (uint32_t i = 0; i < jsNum; i++) {
902 nlohmann::json temp;
903 temp["userId"] = 100;
904 js["test"].push_back(temp);
905 }
906 std::vector<ImePersistCfg> configs;
907 ImeCfgManager::GetInstance().FromJson(js, configs);
908 EXPECT_TRUE(configs.empty());
909 }
910
911 /**
912 * @tc.name: ICM_TestFromJson_002
913 * @tc.desc: json contain "imeCfg_list", but not array
914 * @tc.type: FUNC
915 * @tc.require:
916 * @tc.author: chenyu
917 */
918 HWTEST_F(InputMethodPrivateMemberTest, ICM_TestFromJson_002, TestSize.Level0)
919 {
920 IMSA_HILOGI("InputMethodPrivateMemberTest ICM_TestFromJson_002 TEST START");
921 nlohmann::json js;
922 js["imeCfg_list"] = 100;
923 std::vector<ImePersistCfg> configs;
924 ImeCfgManager::GetInstance().FromJson(js, configs);
925 EXPECT_TRUE(configs.empty());
926 }
927
928 /**
929 * @tc.name: ICM_TestFromJson_003
930 * @tc.desc: json contain "imeCfg_list", is a empty array
931 * @tc.type: FUNC
932 * @tc.require:
933 * @tc.author: chenyu
934 */
935 HWTEST_F(InputMethodPrivateMemberTest, ICM_TestFromJson_003, TestSize.Level0)
936 {
937 IMSA_HILOGI("InputMethodPrivateMemberTest ICM_TestFromJson_003 TEST START");
938 nlohmann::json js;
939 js["imeCfg_list"] = nlohmann::json::array();
940 std::vector<ImePersistCfg> configs;
941 ImeCfgManager::GetInstance().FromJson(js, configs);
942 EXPECT_TRUE(configs.empty());
943 }
944
945 /**
946 * @tc.name: ICM_TestFromJson_004
947 * @tc.desc: json contain "imeCfg_list", is a array
948 * @tc.type: FUNC
949 * @tc.require:
950 * @tc.author: chenyu
951 */
952 HWTEST_F(InputMethodPrivateMemberTest, ICM_TestFromJson_004, TestSize.Level0)
953 {
954 IMSA_HILOGI("InputMethodPrivateMemberTest ICM_TestFromJson_004 TEST START");
955 constexpr int32_t jsNum = 1;
956 nlohmann::json js;
957 for (uint32_t i = 0; i < jsNum; i++) {
958 nlohmann::json temp;
959 temp["userId"] = "userId";
960 temp["currentIme"] = 60;
961 temp["currentSubName"] = "currentSubName";
962 js["imeCfg_list"].push_back(temp);
963 }
964 std::vector<ImePersistCfg> configs;
965 ImeCfgManager::GetInstance().FromJson(js, configs);
966 EXPECT_EQ(configs.size(), jsNum);
967 EXPECT_EQ(configs[0].userId, ImePersistCfg::INVALID_USERID);
968 EXPECT_EQ(configs[0].currentSubName, "currentSubName");
969 EXPECT_TRUE(configs[0].currentIme.empty());
970 }
971
972 /**
973 * @tc.name: WMSConnectObserver_001
974 * @tc.desc:
975 * @tc.type: FUNC
976 * @tc.require:
977 * @tc.author: chenyu
978 */
979 HWTEST_F(InputMethodPrivateMemberTest, WMSConnectObserver_001, TestSize.Level0)
980 {
981 IMSA_HILOGI("InputMethodPrivateMemberTest WMSConnectObserver_001 TEST START");
982 WmsConnectionObserver observer(nullptr);
983 int32_t userId = 100;
984 int32_t screenId = 0;
985
986 observer.OnConnected(userId, screenId);
987 EXPECT_EQ(WmsConnectionObserver::connectedUserId_.size(), 1);
988 EXPECT_TRUE(WmsConnectionObserver::IsWmsConnected(userId));
989
990 int32_t userId1 = 102;
991 observer.OnConnected(userId1, screenId);
992 EXPECT_EQ(WmsConnectionObserver::connectedUserId_.size(), 2);
993 EXPECT_TRUE(WmsConnectionObserver::IsWmsConnected(userId1));
994
995 observer.OnConnected(userId, screenId);
996 EXPECT_EQ(WmsConnectionObserver::connectedUserId_.size(), 2);
997
998 observer.OnDisconnected(userId, screenId);
999 EXPECT_EQ(WmsConnectionObserver::connectedUserId_.size(), 1);
1000 EXPECT_FALSE(WmsConnectionObserver::IsWmsConnected(userId));
1001 }
1002
1003 /**
1004 * @tc.name: IMC_testDeactivateClient
1005 * @tc.desc: DeactivateClient
1006 * @tc.type: FUNC
1007 * @tc.require:
1008 * @tc.author: chenyu
1009 */
1010 HWTEST_F(InputMethodPrivateMemberTest, IMC_testDeactivateClient, TestSize.Level0)
1011 {
1012 IMSA_HILOGI("InputMethodPrivateMemberTest IMC_testDeactivateClient Test START");
1013 auto imc = InputMethodController::GetInstance();
1014 imc->agent_ = std::make_shared<InputMethodAgentStub>();
1015 MessageParcel data;
1016 data.WriteRemoteObject(imc->agent_->AsObject());
1017 imc->agentObject_ = data.ReadRemoteObject();
1018 imc->clientInfo_.state = ClientState::ACTIVE;
1019 imc->DeactivateClient();
1020 EXPECT_EQ(imc->clientInfo_.state, ClientState::INACTIVE);
1021 EXPECT_EQ(imc->agent_, nullptr);
1022 EXPECT_EQ(imc->agentObject_, nullptr);
1023 }
1024 } // namespace MiscServices
1025 } // namespace OHOS