• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 
16 #define private public
17 #include "input_data_channel_proxy_wrap.h"
18 #include "input_method_ability.h"
19 #include "task_manager.h"
20 #undef private
21 
22 #include <gtest/gtest.h>
23 
24 #include "ability_manager_client.h"
25 #include "global.h"
26 #include "ime_event_monitor_manager_impl.h"
27 #include "ime_setting_listener_test_impl.h"
28 #include "input_method_ability_interface.h"
29 #include "input_method_controller.h"
30 #include "input_method_engine_listener_impl.h"
31 #include "input_method_types.h"
32 #include "keyboard_listener_test_impl.h"
33 #include "scope_utils.h"
34 #include "tdd_util.h"
35 #include "text_listener.h"
36 #include "variant_util.h"
37 using namespace testing::ext;
38 namespace OHOS {
39 namespace MiscServices {
40 class ImaTextEditTest : public testing::Test {
41 public:
42     static constexpr const char *NORMAL_EDITOR_BOX_BUNDLE_NAME = "com.example.editorbox";
43     static constexpr const char *CLICK_CMD = "uinput -T -d 200 200 -u 200 200";
44     static const std::string INSERT_TEXT;
45     static constexpr int32_t GET_LENGTH = 2;
46     static constexpr int32_t DEL_LENGTH = 1;
47     static constexpr int32_t DIRECTION = static_cast<int32_t>(Direction::LEFT); // 左移
48     static constexpr int32_t LEFT_INDEX = 1;
49     static constexpr int32_t RIGHT_INDEX = 3;
50     static constexpr int32_t MAX_WAIT_TIME = 1;
SetUpTestCase(void)51     static void SetUpTestCase(void)
52     {
53         std::shared_ptr<Property> property = InputMethodController::GetInstance()->GetCurrentInputMethod();
54         std::string bundleName = property != nullptr ? property->name : "default.inputmethod.unittest";
55         auto currentImeTokenId = TddUtil::GetTestTokenID(bundleName);
56         {
57             TokenScope scope(currentImeTokenId);
58             InputMethodAbility::GetInstance().SetCoreAndAgent();
59         }
60         InputMethodAbility::GetInstance().SetImeListener(std::make_shared<InputMethodEngineListenerImpl>());
61         InputMethodAbility::GetInstance().SetKdListener(std::make_shared<KeyboardListenerTestImpl>());
62         TddUtil::StartApp(NORMAL_EDITOR_BOX_BUNDLE_NAME);
63         TddUtil::ClickApp(CLICK_CMD);
64         EXPECT_TRUE(InputMethodEngineListenerImpl::WaitInputStart());
65         EXPECT_TRUE(TddUtil::WaitTaskEmpty());
66     }
TearDownTestCase(void)67     static void TearDownTestCase(void)
68     {
69     }
SetUp()70     void SetUp()
71     {
72         IMSA_HILOGI("ImaTextEditTest::SetUp");
73     }
TearDown()74     void TearDown()
75     {
76         IMSA_HILOGI("ImaTextEditTest::TearDown");
77         KeyboardListenerTestImpl::ResetParam();
78         auto ret = InputMethodAbility::GetInstance().DeleteForward(finalText_.size());
79         if (!finalText_.empty() && ret == ErrorCode::NO_ERROR) {
80             EXPECT_TRUE(KeyboardListenerTestImpl::WaitTextChange(""));
81         }
82         finalText_.clear();
83         ResetParams();
84         InputMethodEngineListenerImpl::ResetParam();
85         KeyboardListenerTestImpl::ResetParam();
86     }
87 
ResetParams()88     static void ResetParams()
89     {
90         dealRet_ = ErrorCode::ERROR_CLIENT_NOT_BOUND;
91         getForwardRspNums_ = 0;
92         getForwardText_ = "";
93         getIndex_ = 0;
94     }
95 
CommonRsp(int32_t ret,const ResponseData & data)96     static void CommonRsp(int32_t ret, const ResponseData &data)
97     {
98         std::lock_guard<std::mutex> lock(retCvLock_);
99         dealRet_ = ret;
100         retCv_.notify_one();
101     }
102 
WaitCommonRsp()103     static bool WaitCommonRsp()
104     {
105         std::unique_lock<std::mutex> lock(retCvLock_);
106         retCv_.wait_for(lock, std::chrono::seconds(MAX_WAIT_TIME), []() { return dealRet_ == ErrorCode::NO_ERROR; });
107         return dealRet_ == ErrorCode::NO_ERROR;
108     }
109 
GetForwardRsp(int32_t ret,const ResponseData & data)110     static void GetForwardRsp(int32_t ret, const ResponseData &data)
111     {
112         std::lock_guard<std::mutex> lock(retCvLock_);
113         getForwardRspNums_++;
114         dealRet_ = ret;
115         VariantUtil::GetValue(data, getForwardText_);
116         retCv_.notify_one();
117     }
118 
WaitGetForwardRspAbnormal(int32_t num)119     static bool WaitGetForwardRspAbnormal(int32_t num)
120     {
121         std::unique_lock<std::mutex> lock(retCvLock_);
122         retCv_.wait_for(lock, std::chrono::seconds(MAX_WAIT_TIME),
123             [&num]() { return getForwardRspNums_ == num && dealRet_ == ErrorCode::ERROR_IMA_DATA_CHANNEL_ABNORMAL; });
124         return getForwardRspNums_ == num && dealRet_ == ErrorCode::ERROR_IMA_DATA_CHANNEL_ABNORMAL;
125     }
126 
WaitGetForwardRsp(const std::string & text)127     static bool WaitGetForwardRsp(const std::string &text)
128     {
129         std::unique_lock<std::mutex> lock(retCvLock_);
130         retCv_.wait_for(lock, std::chrono::seconds(MAX_WAIT_TIME),
131             [&]() { return dealRet_ == ErrorCode::NO_ERROR && text == getForwardText_; });
132         return dealRet_ == ErrorCode::NO_ERROR;
133     }
134 
GetTextIndexAtCursorRsp(int32_t ret,const ResponseData & data)135     static void GetTextIndexAtCursorRsp(int32_t ret, const ResponseData &data)
136     {
137         std::lock_guard<std::mutex> lock(retCvLock_);
138         getForwardRspNums_++;
139         dealRet_ = ret;
140         VariantUtil::GetValue(data, getIndex_);
141         retCv_.notify_one();
142     }
143 
WaitGetTextIndexAtCursorRsp(int32_t index)144     static bool WaitGetTextIndexAtCursorRsp(int32_t index)
145     {
146         std::unique_lock<std::mutex> lock(retCvLock_);
147         retCv_.wait_for(lock, std::chrono::seconds(MAX_WAIT_TIME),
148             [&]() { return dealRet_ == ErrorCode::NO_ERROR && index == getIndex_; });
149         return dealRet_ == ErrorCode::NO_ERROR;
150     }
151 
152     static std::mutex retCvLock_;
153     static std::condition_variable retCv_;
154     static int32_t dealRet_;
155     static int32_t getForwardRspNums_;
156     static std::string getForwardText_;
157     static int32_t getIndex_;
158     static std::string finalText_;
159 };
160 
161 std::mutex ImaTextEditTest::retCvLock_;
162 std::condition_variable ImaTextEditTest::retCv_;
163 int32_t ImaTextEditTest::dealRet_{ ErrorCode::ERROR_CLIENT_NOT_BOUND };
164 const std::string ImaTextEditTest::INSERT_TEXT = "ABCDEFGHIJKMN";
165 std::string ImaTextEditTest::finalText_;
166 int32_t ImaTextEditTest::getForwardRspNums_{ 0 };
167 std::string ImaTextEditTest::getForwardText_;
168 int32_t ImaTextEditTest::getIndex_{ 0 };
169 
170 /**
171  * @tc.name: ImaTextEditTest_GetForward
172  * @tc.desc:
173  * @tc.type: FUNC
174  */
175 HWTEST_F(ImaTextEditTest, ImaTextEditTest_GetForward, TestSize.Level0)
176 {
177     IMSA_HILOGI("ImeProxyTest::ImaTextEditTest_GetForward");
178     finalText_ = INSERT_TEXT;
179     auto ret = InputMethodAbility::GetInstance().InsertText(INSERT_TEXT);
180     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
181     EXPECT_TRUE(KeyboardListenerTestImpl::WaitTextChange(INSERT_TEXT));
182 
183     auto expectText = INSERT_TEXT.substr(INSERT_TEXT.size() - GET_LENGTH);
184     std::u16string syncText;
185     // sync
186     ret = InputMethodAbility::GetInstance().GetTextBeforeCursor(GET_LENGTH, syncText);
187     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
188     EXPECT_EQ(Str16ToStr8(syncText), expectText);
189 
190     // async
191     std::u16string asyncText;
192     ret = InputMethodAbility::GetInstance().GetTextBeforeCursor(GET_LENGTH, asyncText, GetForwardRsp);
193     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
194     EXPECT_TRUE(WaitGetForwardRsp(expectText));
195 }
196 
197 /**
198  * @tc.name: ImaTextEditTest_GetBackward
199  * @tc.desc:
200  * @tc.type: FUNC
201  */
202 HWTEST_F(ImaTextEditTest, ImaTextEditTest_GetBackward, TestSize.Level0)
203 {
204     IMSA_HILOGI("ImeProxyTest::ImaTextEditTest_GetBackward");
205     finalText_ = INSERT_TEXT;
206     auto ret = InputMethodAbility::GetInstance().InsertText(INSERT_TEXT);
207     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
208     EXPECT_TRUE(KeyboardListenerTestImpl::WaitTextChange(INSERT_TEXT));
209 
210     std::string expectText;
211     std::u16string syncText;
212     // sync
213     ret = InputMethodAbility::GetInstance().GetTextAfterCursor(GET_LENGTH, syncText);
214     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
215     EXPECT_EQ(Str16ToStr8(syncText), expectText);
216 
217     // async
218     std::u16string asyncText;
219     ret = InputMethodAbility::GetInstance().GetTextAfterCursor(GET_LENGTH, asyncText, GetForwardRsp);
220     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
221     EXPECT_TRUE(WaitGetForwardRsp(expectText));
222 }
223 
224 /**
225  * @tc.name: ImaTextEditTest_GetTextIndexAtCursor
226  * @tc.desc:
227  * @tc.type: FUNC
228  */
229 HWTEST_F(ImaTextEditTest, ImaTextEditTest_GetTextIndexAtCursor, TestSize.Level0)
230 {
231     IMSA_HILOGI("ImeProxyTest::ImaTextEditTest_GetTextIndexAtCursor");
232     finalText_ = INSERT_TEXT;
233     auto ret = InputMethodAbility::GetInstance().InsertText(INSERT_TEXT);
234     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
235     EXPECT_TRUE(KeyboardListenerTestImpl::WaitTextChange(INSERT_TEXT));
236 
237     int32_t syncIndex = 0;
238     int32_t expectIndex = INSERT_TEXT.size();
239     // sync
240     ret = InputMethodAbility::GetInstance().GetTextIndexAtCursor(syncIndex);
241     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
242     EXPECT_EQ(syncIndex, expectIndex);
243 
244     // async
245     int32_t asyncIndex = 0;
246     ret = InputMethodAbility::GetInstance().GetTextIndexAtCursor(asyncIndex, GetTextIndexAtCursorRsp);
247     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
248     EXPECT_TRUE(WaitGetTextIndexAtCursorRsp(expectIndex));
249 }
250 
251 /**
252  * @tc.name: ImaTextEditTest_InsertText
253  * @tc.desc:
254  * @tc.type: FUNC
255  */
256 HWTEST_F(ImaTextEditTest, ImaTextEditTest_InsertText, TestSize.Level0)
257 {
258     IMSA_HILOGI("ImeProxyTest::ImaTextEditTest_InsertText");
259     // sync
260     auto ret = InputMethodAbility::GetInstance().InsertText(INSERT_TEXT);
261     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
262     EXPECT_TRUE(KeyboardListenerTestImpl::WaitTextChange(INSERT_TEXT));
263     KeyboardListenerTestImpl::ResetParam();
264     // async
265     ret = InputMethodAbility::GetInstance().InsertText(INSERT_TEXT, CommonRsp);
266     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
267     EXPECT_TRUE(WaitCommonRsp());
268     finalText_ = INSERT_TEXT + INSERT_TEXT;
269     EXPECT_TRUE(KeyboardListenerTestImpl::WaitTextChange(finalText_));
270 }
271 
272 /**
273  * @tc.name: ImaTextEditTest_SetPreviewText_FinishTextPreview
274  * @tc.desc:
275  * @tc.type: FUNC
276  */
277 HWTEST_F(ImaTextEditTest, ImaTextEditTest_SetPreviewText_FinishTextPreview, TestSize.Level0)
278 {
279     IMSA_HILOGI("ImeProxyTest::ImaTextEditTest_SetPreviewText_FinishTextPreview");
280     Range range = { -1, -1 };
281     // sync
282     auto ret = InputMethodAbility::GetInstance().SetPreviewText(INSERT_TEXT, range);
283     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
284     ret = InputMethodAbility::GetInstance().FinishTextPreview();
285     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
286     EXPECT_TRUE(KeyboardListenerTestImpl::WaitTextChange(INSERT_TEXT));
287     KeyboardListenerTestImpl::ResetParam();
288 
289     // async
290     ret = InputMethodAbility::GetInstance().SetPreviewText(INSERT_TEXT, range, CommonRsp);
291     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
292     EXPECT_TRUE(WaitCommonRsp());
293     ResetParams();
294     ret = InputMethodAbility::GetInstance().FinishTextPreview(CommonRsp);
295     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
296     EXPECT_TRUE(WaitCommonRsp());
297     finalText_ = INSERT_TEXT + INSERT_TEXT;
298     EXPECT_TRUE(KeyboardListenerTestImpl::WaitTextChange(finalText_));
299 }
300 /**
301  * @tc.name: ImaTextEditTest_DeleteForward
302  * @tc.desc:
303  * @tc.type: FUNC
304  */
305 HWTEST_F(ImaTextEditTest, ImaTextEditTest_DeleteForward, TestSize.Level0)
306 {
307     IMSA_HILOGI("ImeProxyTest::ImaTextEditTest_DeleteForward");
308     // sync
309     auto ret = InputMethodAbility::GetInstance().DeleteForward(DEL_LENGTH);
310     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
311 
312     // async
313     ret = InputMethodAbility::GetInstance().DeleteForward(DEL_LENGTH, CommonRsp);
314     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
315     EXPECT_TRUE(WaitCommonRsp());
316 }
317 
318 /**
319  * @tc.name: ImaTextEditTest_DeleteBackward
320  * @tc.desc:
321  * @tc.type: FUNC
322  */
323 HWTEST_F(ImaTextEditTest, ImaTextEditTest_DeleteBackward, TestSize.Level0)
324 {
325     IMSA_HILOGI("ImeProxyTest::ImaTextEditTest_DeleteBackward");
326     // sync
327     auto ret = InputMethodAbility::GetInstance().DeleteBackward(DEL_LENGTH);
328     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
329 
330     // async
331     ret = InputMethodAbility::GetInstance().DeleteBackward(DEL_LENGTH, CommonRsp);
332     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
333     EXPECT_TRUE(WaitCommonRsp());
334 }
335 
336 /**
337  * @tc.name: ImaTextEditTest_SendExtendAction
338  * @tc.desc:
339  * @tc.type: FUNC
340  */
341 HWTEST_F(ImaTextEditTest, ImaTextEditTest_SendExtendAction, TestSize.Level0)
342 {
343     IMSA_HILOGI("ImeProxyTest::ImaTextEditTest_SendExtendAction");
344     // sync
345     int32_t action = 1;
346     auto ret = InputMethodAbility::GetInstance().SendExtendAction(action);
347     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
348 
349     // async
350     ret = InputMethodAbility::GetInstance().SendExtendAction(action, CommonRsp);
351     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
352     EXPECT_TRUE(WaitCommonRsp());
353 }
354 
355 /**
356  * @tc.name: ImaTextEditTest_MoveCursor
357  * @tc.desc:
358  * @tc.type: FUNC
359  */
360 HWTEST_F(ImaTextEditTest, ImaTextEditTest_MoveCursor, TestSize.Level0)
361 {
362     IMSA_HILOGI("ImeProxyTest::ImaTextEditTest_MoveCursor");
363     // sync
364     int32_t direction = 3;
365     auto ret = InputMethodAbility::GetInstance().MoveCursor(direction);
366     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
367 
368     // async
369     ret = InputMethodAbility::GetInstance().MoveCursor(direction, CommonRsp);
370     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
371     EXPECT_TRUE(WaitCommonRsp());
372 }
373 
374 /**
375  * @tc.name: ImaTextEditTest_SelectByRange
376  * @tc.desc:
377  * @tc.type: FUNC
378  */
379 HWTEST_F(ImaTextEditTest, ImaTextEditTest_SelectByRange, TestSize.Level0)
380 {
381     IMSA_HILOGI("ImeProxyTest::ImaTextEditTest_SelectByRange");
382     // sync
383     int32_t start = 1;
384     int32_t end = 2;
385     auto ret = InputMethodAbility::GetInstance().SelectByRange(start, end);
386     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
387 
388     // async
389     ret = InputMethodAbility::GetInstance().SelectByRange(start, end, CommonRsp);
390     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
391     EXPECT_TRUE(WaitCommonRsp());
392 }
393 
394 /**
395  * @tc.name: ImaTextEditTest_SelectByMovement
396  * @tc.desc:
397  * @tc.type: FUNC
398  */
399 HWTEST_F(ImaTextEditTest, ImaTextEditTest_SelectByMovement, TestSize.Level0)
400 {
401     IMSA_HILOGI("ImeProxyTest::ImaTextEditTest_SelectByMovement");
402     // sync
403     int32_t direction = 1;
404     auto ret = InputMethodAbility::GetInstance().SelectByMovement(direction);
405     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
406 
407     // async
408     ret = InputMethodAbility::GetInstance().SelectByMovement(direction, CommonRsp);
409     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
410     EXPECT_TRUE(WaitCommonRsp());
411 }
412 
413 /**
414  * @tc.name: ImaTextEditTest_SendFunctionKey
415  * @tc.desc:
416  * @tc.type: FUNC
417  */
418 HWTEST_F(ImaTextEditTest, ImaTextEditTest_SendFunctionKey, TestSize.Level0)
419 {
420     IMSA_HILOGI("ImeProxyTest::ImaTextEditTest_SendFunctionKey");
421     int32_t funcKey = 1;
422     // sync
423     auto ret = InputMethodAbility::GetInstance().SendFunctionKey(funcKey);
424     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
425 
426     // async
427     ret = InputMethodAbility::GetInstance().SendFunctionKey(funcKey, CommonRsp);
428     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
429     EXPECT_TRUE(WaitCommonRsp());
430 }
431 
432 /**
433  * @tc.name: ImaTextEditTest_ClearRspHandlers
434  * @tc.desc:
435  * @tc.type: FUNC
436  */
437 HWTEST_F(ImaTextEditTest, ImaTextEditTest_ClearRspHandlers, TestSize.Level0)
438 {
439     IMSA_HILOGI("ImeProxyTest::ImaTextEditTest_ClearRspHandlers");
440     auto channelProxy = std::make_shared<InputDataChannelProxy>(nullptr);
441     auto channelWrap = std::make_shared<InputDataChannelProxyWrap>(channelProxy, nullptr);
__anon7a6905560502() 442     auto delayTask = [&channelWrap]() {
443         usleep(100000);
444         channelWrap->ClearRspHandlers();
445     };
446     std::thread delayThread(delayTask);
447 
448     channelWrap->AddRspHandler(GetForwardRsp, false);
449     channelWrap->AddRspHandler(GetForwardRsp, false);
450     auto handler = channelWrap->AddRspHandler(GetForwardRsp, true);
451     auto ret = channelWrap->WaitResponse(handler, nullptr);
452     EXPECT_EQ(ret, ErrorCode::ERROR_IMA_DATA_CHANNEL_ABNORMAL);
453     EXPECT_TRUE(WaitGetForwardRspAbnormal(2));
454     delayThread.join();
455 }
456 
457 /**
458  * @tc.name: ImaTextEditTest_DeleteRspHandler
459  * @tc.desc:
460  * @tc.type: FUNC
461  */
462 HWTEST_F(ImaTextEditTest, ImaTextEditTest_DeleteRspHandler, TestSize.Level0)
463 {
464     constexpr std::size_t UNANSWERED_MAX_NUMBER = 1000;
465     IMSA_HILOGI("ImeProxyTest::ImaTextEditTest_DeleteRspHandler");
466     auto channelProxy = std::make_shared<InputDataChannelProxy>(nullptr);
467     auto channelWrap = std::make_shared<InputDataChannelProxyWrap>(channelProxy, nullptr);
468 
469     std::shared_ptr<ResponseHandler> firstHandler = nullptr;
470     std::shared_ptr<ResponseHandler> lastHandler = nullptr;
471     firstHandler = channelWrap->AddRspHandler(GetForwardRsp, false);
472     for (int i = 0; i < UNANSWERED_MAX_NUMBER; ++i) {
473         lastHandler = channelWrap->AddRspHandler(GetForwardRsp, false);
474     }
475     ASSERT_NE(firstHandler, nullptr);
476     ASSERT_EQ(lastHandler, nullptr);
477     EXPECT_EQ(channelWrap->DeleteRspHandler(firstHandler->msgId_), ErrorCode::NO_ERROR);
478     EXPECT_EQ(channelWrap->DeleteRspHandler(0), ErrorCode::NO_ERROR);
479 }
480 
481 /**
482  * @tc.name: ImaTextEditTest_HandleResponse
483  * @tc.desc:
484  * @tc.type: FUNC
485  */
486 HWTEST_F(ImaTextEditTest, ImaTextEditTest_HandleResponse, TestSize.Level0)
487 {
488     IMSA_HILOGI("ImeProxyTest::ImaTextEditTest_HandleResponse");
489     auto channelProxy = std::make_shared<InputDataChannelProxy>(nullptr);
490     auto channelWrap = std::make_shared<InputDataChannelProxyWrap>(channelProxy, nullptr);
491 
492     std::shared_ptr<ResponseHandler> handler = nullptr;
493     handler = channelWrap->AddRspHandler(CommonRsp, false);
494     ASSERT_NE(handler, nullptr);
495     ResponseInfo rspInfo = { ErrorCode::NO_ERROR, std::monostate{} };
496     channelWrap->HandleResponse(handler->msgId_, rspInfo);
497     EXPECT_TRUE(WaitCommonRsp());
498 
499     std::shared_ptr<ResponseHandler> handler1 = nullptr;
500     handler1 = channelWrap->AddRspHandler(nullptr, false);
501     ASSERT_NE(handler1, nullptr);
502     EXPECT_EQ(channelWrap->HandleResponse(handler1->msgId_ - 1, rspInfo), ErrorCode::NO_ERROR);
503     EXPECT_EQ(channelWrap->HandleResponse(handler1->msgId_, rspInfo), ErrorCode::NO_ERROR);
504 }
505 } // namespace MiscServices
506 } // namespace OHOS
507