• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "input_method_panel.h"
16 
17 #include <gtest/gtest.h>
18 #include <sys/time.h>
19 #include <unistd.h>
20 
21 #include <condition_variable>
22 #include <cstdint>
23 #include <string>
24 
25 #include "display_manager.h"
26 #include "global.h"
27 #include "input_method_ability.h"
28 #include "input_method_controller.h"
29 #include "panel_status_listener.h"
30 #include "tdd_util.h"
31 
32 using namespace testing::ext;
33 namespace OHOS {
34 namespace MiscServices {
35 constexpr uint32_t IMC_WAIT_PANEL_STATUS_LISTEN_TIME = 200;
36 constexpr float FIXED_SOFT_KEYBOARD_PANEL_RATIO = 0.7;
37 constexpr float NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO = 1;
38 constexpr int32_t IMC_WAIT_TIME = 2;
39 enum ListeningStatus : uint32_t { ON, OFF, NONE };
40 class InputMethodPanelTest : public testing::Test {
41 public:
42     static void SetUpTestCase(void);
43     static void TearDownTestCase(void);
44     void SetUp();
45     void TearDown();
46     static std::shared_ptr<InputMethodPanel> CreatePanel();
47     static void TriggerShowCallback(std::shared_ptr<InputMethodPanel> &inputMethodPanel);
48     static void TriggerHideCallback(std::shared_ptr<InputMethodPanel> &inputMethodPanel);
49     static void ImcPanelListeningTestCheck(
50         InputWindowStatus realStatus, InputWindowStatus waitStatus, const InputWindowInfo &windowInfo);
51     static void ImcPanelListeningTestCheck(InputWindowStatus realStatus, InputWindowStatus waitStatus);
52     static void ImcPanelListeningTestPrepare(
53         const std::shared_ptr<InputMethodPanel> &inputMethodPanel, const PanelInfo &info, ListeningStatus status);
54     static void ImcPanelListeningTestRestore(InputWindowStatus status);
55     static void ImcPanelListeningTestClear(const std::shared_ptr<InputMethodPanel> &inputMethodPanel);
56     class PanelStatusListenerImpl : public PanelStatusListener {
57     public:
PanelStatusListenerImpl()58         PanelStatusListenerImpl()
59         {
60             std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create("InputMethodPanelTest");
61             panelHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
62         }
63         ~PanelStatusListenerImpl() = default;
OnPanelStatus(uint32_t windowId,bool isShow)64         void OnPanelStatus(uint32_t windowId, bool isShow)
65         {
66             showPanel_ = isShow;
67             hidePanel_ = !isShow;
68             InputMethodPanelTest::panelListenerCv_.notify_one();
69             IMSA_HILOGI("PanelStatusListenerImpl OnPanelStatus in, isShow is %{public}s", isShow ? "true" : "false");
70         }
71     };
72     static std::mutex imcPanelStatusListenerLock_;
73     static std::condition_variable imcPanelStatusListenerCv_;
74     static InputWindowStatus status_;
75     static std::vector<InputWindowInfo> windowInfo_;
76     static sptr<InputMethodController> imc_;
77     static sptr<InputMethodAbility> ima_;
78     static uint32_t windowWidth_;
79     static uint32_t windowHeight_;
80     static bool showPanel_;
81     static bool hidePanel_;
82     static std::condition_variable panelListenerCv_;
83     static std::mutex panelListenerLock_;
84     static constexpr uint32_t DELAY_TIME = 100;
85     static constexpr int32_t INTERVAL = 10;
86     static std::shared_ptr<AppExecFwk::EventHandler> panelHandler_;
87     static uint64_t tokenId_;
88     static std::string beforeValue;
89     static std::string allEnableIme;
90 };
91 class InputMethodSettingListenerImpl : public InputMethodSettingListener {
92 public:
93     InputMethodSettingListenerImpl() = default;
94     ~InputMethodSettingListenerImpl() = default;
OnImeChange(const Property & property,const SubProperty & subProperty)95     void OnImeChange(const Property &property, const SubProperty &subProperty)
96     {
97     }
OnPanelStatusChange(const InputWindowStatus & status,const std::vector<InputWindowInfo> & windowInfo)98     void OnPanelStatusChange(const InputWindowStatus &status, const std::vector<InputWindowInfo> &windowInfo)
99     {
100         IMSA_HILOGI("InputMethodPanelTest::OnPanelStatusChange");
101         {
102             std::unique_lock<std::mutex> lock(InputMethodPanelTest::imcPanelStatusListenerLock_);
103             InputMethodPanelTest::status_ = status;
104             InputMethodPanelTest::windowInfo_ = windowInfo;
105         }
106         InputMethodPanelTest::imcPanelStatusListenerCv_.notify_one();
107     }
108 };
109 bool InputMethodPanelTest::showPanel_ = false;
110 bool InputMethodPanelTest::hidePanel_ = false;
111 std::condition_variable InputMethodPanelTest::panelListenerCv_;
112 std::mutex InputMethodPanelTest::panelListenerLock_;
113 std::shared_ptr<AppExecFwk::EventHandler> InputMethodPanelTest::panelHandler_{ nullptr };
114 std::condition_variable InputMethodPanelTest::imcPanelStatusListenerCv_;
115 std::mutex InputMethodPanelTest::imcPanelStatusListenerLock_;
116 InputWindowStatus InputMethodPanelTest::status_{ InputWindowStatus::HIDE };
117 std::vector<InputWindowInfo> InputMethodPanelTest::windowInfo_;
118 sptr<InputMethodController> InputMethodPanelTest::imc_;
119 sptr<InputMethodAbility> InputMethodPanelTest::ima_;
120 uint32_t InputMethodPanelTest::windowWidth_ = 0;
121 uint32_t InputMethodPanelTest::windowHeight_ = 0;
122 uint64_t InputMethodPanelTest::tokenId_ = 0;
123 std::string InputMethodPanelTest::beforeValue;
124 std::string InputMethodPanelTest::allEnableIme = "{\"enableImeList\" : {\"100\" : [ \"com.example.testIme\"]}}";
SetUpTestCase(void)125 void InputMethodPanelTest::SetUpTestCase(void)
126 {
127     IMSA_HILOGI("InputMethodPanelTest::SetUpTestCase");
128     TddUtil::StorageSelfTokenID();
129     ima_ = InputMethodAbility::GetInstance();
130     auto listener = std::make_shared<InputMethodSettingListenerImpl>();
131     imc_ = InputMethodController::GetInstance();
132     imc_->SetSettingListener(listener);
133     TddUtil::SetTestTokenID(TddUtil::AllocTestTokenID(true, "undefined", { "ohos.permission.CONNECT_IME_ABILITY" }));
134     TddUtil::GrantNativePermission();
135     TddUtil::GetEnableData(beforeValue);
136     TddUtil::PushEnableImeValue("settings.inputmethod.enable_ime", allEnableIme);
137     auto ret = imc_->SwitchInputMethod(SwitchTrigger::CURRENT_IME, "com.example.testIme");
138     if (ret != ErrorCode::NO_ERROR) {
139         IMSA_HILOGI("SwitchInputMethod failed, ret = %{public}d", ret);
140         return;
141     }
142     TddUtil::RestoreSelfTokenID();
143     std::shared_ptr<Property> property = InputMethodController::GetInstance()->GetCurrentInputMethod();
144     std::string bundleName = property != nullptr ? property->name : "default.inputmethod.unittest";
145     tokenId_ = TddUtil::AllocTestTokenID(true, bundleName, { "ohos.permission.CONNECT_IME_ABILITY" });
146 }
147 
TearDownTestCase(void)148 void InputMethodPanelTest::TearDownTestCase(void)
149 {
150     IMSA_HILOGI("InputMethodPanelTest::TearDownTestCase");
151     TddUtil::GrantNativePermission();
152     TddUtil::PushEnableImeValue("settings.inputmethod.enable_ime", beforeValue);
153 }
154 
SetUp(void)155 void InputMethodPanelTest::SetUp(void)
156 {
157     IMSA_HILOGI("InputMethodPanelTest::SetUp");
158 }
159 
TearDown(void)160 void InputMethodPanelTest::TearDown(void)
161 {
162     IMSA_HILOGI("InputMethodPanelTest::TearDown");
163 }
164 
CreatePanel()165 std::shared_ptr<InputMethodPanel> InputMethodPanelTest::CreatePanel()
166 {
167     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
168     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
169     auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
170     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
171     return inputMethodPanel;
172 }
173 
TriggerShowCallback(std::shared_ptr<InputMethodPanel> & inputMethodPanel)174 void InputMethodPanelTest::TriggerShowCallback(std::shared_ptr<InputMethodPanel> &inputMethodPanel)
175 {
176     panelHandler_->PostTask([&inputMethodPanel]() { inputMethodPanel->ShowPanel(); }, InputMethodPanelTest::INTERVAL);
177     {
178         std::unique_lock<std::mutex> lock(InputMethodPanelTest::panelListenerLock_);
179         InputMethodPanelTest::panelListenerCv_.wait_for(lock,
180             std::chrono::milliseconds(InputMethodPanelTest::DELAY_TIME),
181             [] { return InputMethodPanelTest::showPanel_; });
182     }
183 }
184 
TriggerHideCallback(std::shared_ptr<InputMethodPanel> & inputMethodPanel)185 void InputMethodPanelTest::TriggerHideCallback(std::shared_ptr<InputMethodPanel> &inputMethodPanel)
186 {
187     panelHandler_->PostTask([&inputMethodPanel]() { inputMethodPanel->HidePanel(); }, InputMethodPanelTest::INTERVAL);
188     {
189         std::unique_lock<std::mutex> lock(InputMethodPanelTest::panelListenerLock_);
190         InputMethodPanelTest::panelListenerCv_.wait_for(lock,
191             std::chrono::milliseconds(InputMethodPanelTest::DELAY_TIME),
192             [] { return InputMethodPanelTest::hidePanel_; });
193     }
194 }
195 
ImcPanelListeningTestCheck(InputWindowStatus realStatus,InputWindowStatus waitStatus,const InputWindowInfo & windowInfo)196 void InputMethodPanelTest::ImcPanelListeningTestCheck(
197     InputWindowStatus realStatus, InputWindowStatus waitStatus, const InputWindowInfo &windowInfo)
198 {
199     std::unique_lock<std::mutex> lock(imcPanelStatusListenerLock_);
200     imcPanelStatusListenerCv_.wait_for(lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME),
201         [&waitStatus] { return waitStatus == status_; });
202     EXPECT_EQ(status_, realStatus);
203     ASSERT_EQ(windowInfo_.size(), 1);
204     IMSA_HILOGI("InputMethodPanelTest::name: %{public}s, top: %{public}d, left: %{public}d",
205         windowInfo_[0].name.c_str(), windowInfo_[0].top, windowInfo_[0].left);
206     EXPECT_FALSE(windowInfo_[0].name.empty());
207     EXPECT_EQ(windowInfo_[0].width, windowInfo.width);
208     EXPECT_EQ(windowInfo_[0].height, windowInfo.height);
209 }
210 
ImcPanelListeningTestCheck(InputWindowStatus realStatus,InputWindowStatus waitStatus)211 void InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus realStatus, InputWindowStatus waitStatus)
212 {
213     std::unique_lock<std::mutex> lock(imcPanelStatusListenerLock_);
214     imcPanelStatusListenerCv_.wait_for(lock, std::chrono::milliseconds(IMC_WAIT_PANEL_STATUS_LISTEN_TIME),
215         [&waitStatus] { return waitStatus == status_; });
216     EXPECT_EQ(status_, realStatus);
217     EXPECT_TRUE(windowInfo_.empty());
218 }
219 
ImcPanelListeningTestPrepare(const std::shared_ptr<InputMethodPanel> & inputMethodPanel,const PanelInfo & info,ListeningStatus status)220 void InputMethodPanelTest::ImcPanelListeningTestPrepare(
221     const std::shared_ptr<InputMethodPanel> &inputMethodPanel, const PanelInfo &info, ListeningStatus status)
222 {
223     auto ret = inputMethodPanel->CreatePanel(nullptr, info);
224     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
225     auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
226     ASSERT_TRUE(defaultDisplay != nullptr);
227     windowWidth_ = defaultDisplay->GetWidth();
228     windowHeight_ = 1;
229     ret = inputMethodPanel->Resize(windowWidth_, windowHeight_);
230     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
231     switch (status) {
232         case ListeningStatus::NONE: {
233             break;
234         }
235         case ListeningStatus::ON: {
236             imc_->UpdateListenEventFlag("imeShow", true);
237             imc_->UpdateListenEventFlag("imeHide", true);
238             break;
239         }
240         case ListeningStatus::OFF: {
241             imc_->UpdateListenEventFlag("imeShow", false);
242             imc_->UpdateListenEventFlag("imeHide", false);
243             break;
244         }
245         default:
246             break;
247     }
248 }
249 
ImcPanelListeningTestRestore(InputWindowStatus status)250 void InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus status)
251 {
252     status_ = status;
253     windowInfo_.clear();
254 }
255 
ImcPanelListeningTestClear(const std::shared_ptr<InputMethodPanel> & inputMethodPanel)256 void InputMethodPanelTest::ImcPanelListeningTestClear(const std::shared_ptr<InputMethodPanel> &inputMethodPanel)
257 {
258     inputMethodPanel->DestroyPanel();
259 }
260 
261 /**
262 * @tc.name: testCreatePanel
263 * @tc.desc: Test CreatePanel.
264 * @tc.type: FUNC
265 */
266 HWTEST_F(InputMethodPanelTest, testCreatePanel, TestSize.Level0)
267 {
268     IMSA_HILOGI("InputMethodPanelTest::testCreatePanel start.");
269     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
270     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
271     auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
272     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
273     ret = inputMethodPanel->DestroyPanel();
274     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
275 }
276 
277 /**
278 * @tc.name: testDestroyPanel
279 * @tc.desc: Test DestroyPanel.
280 * @tc.type: FUNC
281 */
282 HWTEST_F(InputMethodPanelTest, testDestroyPanel, TestSize.Level0)
283 {
284     IMSA_HILOGI("InputMethodPanelTest::testDestroyPanel start.");
285     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
286     // not CreatePanel, DestroyPanel failed
287     auto ret = inputMethodPanel->DestroyPanel();
288     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
289 }
290 
291 /**
292 * @tc.name: testResizePanel001
293 * @tc.desc: Test Resize panel. Panels non fixed soft keyboard.
294 * @tc.type: FUNC
295 */
296 HWTEST_F(InputMethodPanelTest, testResizePanel001, TestSize.Level0)
297 {
298     IMSA_HILOGI("InputMethodPanelTest::testResizePanel001 start.");
299     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
300     // not CreatePanel, Resize failed
301     auto ret = inputMethodPanel->Resize(1, 1);
302     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
303 
304     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
305     ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
306     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
307     auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
308     EXPECT_TRUE(defaultDisplay != nullptr);
309     int32_t width = defaultDisplay->GetWidth();
310     int32_t height = defaultDisplay->GetHeight();
311 
312     ret = inputMethodPanel->Resize(width - 1, height * NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1);
313     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
314 
315     ret = inputMethodPanel->Resize(width, height * NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO);
316     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
317 
318     ret = inputMethodPanel->Resize(width + 1, height * NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO);
319     EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
320 
321     ret = inputMethodPanel->Resize(width, height * NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1);
322     EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
323 
324     ret = inputMethodPanel->Resize(width + 1, height * NON_FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1);
325     EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
326 
327     ret = inputMethodPanel->DestroyPanel();
328     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
329 }
330 
331 /**
332 * @tc.name: testResizePanel002
333 * @tc.desc: Test Resize panel. Fixed soft keyboard panel .
334 * @tc.type: FUNC
335 */
336 HWTEST_F(InputMethodPanelTest, testResizePanel002, TestSize.Level0)
337 {
338     IMSA_HILOGI("InputMethodPanelTest::testResizePanel002 start.");
339     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
340     // not CreatePanel, Resize failed
341     auto ret = inputMethodPanel->Resize(1, 1);
342     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
343 
344     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
345     ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
346     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
347     auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
348     EXPECT_TRUE(defaultDisplay != nullptr);
349     int32_t width = defaultDisplay->GetWidth();
350     int32_t height = defaultDisplay->GetHeight();
351 
352     ret = inputMethodPanel->Resize(width - 1, height * FIXED_SOFT_KEYBOARD_PANEL_RATIO - 1);
353     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
354 
355     ret = inputMethodPanel->Resize(width, height * FIXED_SOFT_KEYBOARD_PANEL_RATIO);
356     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
357 
358     ret = inputMethodPanel->Resize(width + 1, height * FIXED_SOFT_KEYBOARD_PANEL_RATIO);
359     EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
360 
361     ret = inputMethodPanel->Resize(width, height * FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1);
362     EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
363 
364     ret = inputMethodPanel->Resize(width + 1, height * FIXED_SOFT_KEYBOARD_PANEL_RATIO + 1);
365     EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
366 
367     ret = inputMethodPanel->DestroyPanel();
368     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
369 }
370 
371 /**
372 * @tc.name: testMovePanel
373 * @tc.desc: Test Move panel. SOFT_KEYBOARD panel with FLG_FIXED can not be moved.
374 * @tc.type: FUNC
375 */
376 HWTEST_F(InputMethodPanelTest, testMovePanel, TestSize.Level0)
377 {
378     IMSA_HILOGI("InputMethodPanelTest::testMovePanel start.");
379     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
380     // not CreatePanel, MoveTo failed
381     auto ret = inputMethodPanel->MoveTo(10, 100);
382     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
383 
384     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
385     ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
386     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
387 
388     ret = inputMethodPanel->MoveTo(10, 100);
389     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
390 
391     ret = inputMethodPanel->ChangePanelFlag(PanelFlag::FLG_FLOATING);
392     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
393     ret = inputMethodPanel->MoveTo(10, 100);
394     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
395 
396     ret = inputMethodPanel->DestroyPanel();
397     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
398 
399     panelInfo.panelType = STATUS_BAR;
400     ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
401     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
402     ret = inputMethodPanel->MoveTo(10, 100);
403     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
404     ret = inputMethodPanel->DestroyPanel();
405     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
406 }
407 
408 /**
409 * @tc.name: testShowPanel
410 * @tc.desc: Test Show panel.
411 * @tc.type: FUNC
412 */
413 HWTEST_F(InputMethodPanelTest, testShowPanel, TestSize.Level0)
414 {
415     IMSA_HILOGI("InputMethodPanelTest::testShowPanel start.");
416     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
417     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
418     // 0、not create panel, show panel failed.
419     auto ret = inputMethodPanel->ShowPanel();
420     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
421     ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
422     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
423     ret = inputMethodPanel->ShowPanel();
424     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
425 
426     auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
427     EXPECT_TRUE(statusListener != nullptr);
428     std::string type = "show";
429     inputMethodPanel->SetPanelStatusListener(statusListener, type);
430     ret = inputMethodPanel->ShowPanel();
431     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
432 
433     // 2、show floating type panel.
434     ret = inputMethodPanel->ChangePanelFlag(PanelFlag::FLG_FLOATING);
435     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
436     ret = inputMethodPanel->ShowPanel();
437     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
438 
439     ret = inputMethodPanel->DestroyPanel();
440     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
441 
442     // 4、show status bar.
443     panelInfo.panelType = STATUS_BAR;
444     ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
445     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
446     ret = inputMethodPanel->ShowPanel();
447     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
448     ret = inputMethodPanel->HidePanel();
449     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
450     ret = inputMethodPanel->DestroyPanel();
451     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
452 }
453 
454 /**
455  * @tc.name: testIsPanelShown_001
456  * @tc.desc: Test is panel shown.
457  * @tc.type: FUNC
458  */
459 HWTEST_F(InputMethodPanelTest, testIsPanelShown_001, TestSize.Level0)
460 {
461     IMSA_HILOGI("InputMethodPanelTest::testIsPanelShown_001 start.");
462     TddUtil::SetTestTokenID(tokenId_);
463     int32_t ret = ima_->SetCoreAndAgent();
464     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
465     bool isShown = false;
466     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
467     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
468     ret = ima_->CreatePanel(nullptr, panelInfo, inputMethodPanel);
469     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
470 
471     // query when fixed soft keyboard is showing
472     ret = inputMethodPanel->ShowPanel();
473     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
474     ret = imc_->IsPanelShown(panelInfo, isShown);
475     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
476     EXPECT_TRUE(isShown);
477 
478     // query when fixed soft keyboard is hidden
479     ret = inputMethodPanel->HidePanel();
480     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
481     ret = imc_->IsPanelShown(panelInfo, isShown);
482     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
483     EXPECT_FALSE(isShown);
484 
485     ret = ima_->DestroyPanel(inputMethodPanel);
486     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
487 }
488 
489 /**
490  * @tc.name: testIsPanelShown_002
491  * @tc.desc: Test is panel shown.
492  * @tc.type: FUNC
493  */
494 HWTEST_F(InputMethodPanelTest, testIsPanelShown_002, TestSize.Level0)
495 {
496     IMSA_HILOGI("InputMethodPanelTest::testIsPanelShown_002 start.");
497     TddUtil::SetTestTokenID(tokenId_);
498     int32_t ret = ima_->SetCoreAndAgent();
499     bool isShown = false;
500     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
501     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
502     ret = ima_->CreatePanel(nullptr, panelInfo, inputMethodPanel);
503     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
504 
505     ret = inputMethodPanel->ChangePanelFlag(PanelFlag::FLG_FLOATING);
506     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
507     ret = inputMethodPanel->ShowPanel();
508     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
509 
510     // query panel with old info when panel changes its flag.
511     ret = imc_->IsPanelShown(panelInfo, isShown);
512     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
513     EXPECT_FALSE(isShown);
514     // query panel with updated shown one's info when panel changes its flag.
515     panelInfo.panelFlag = PanelFlag::FLG_FLOATING;
516     ret = imc_->IsPanelShown(panelInfo, isShown);
517     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
518     EXPECT_TRUE(isShown);
519 
520     ret = ima_->DestroyPanel(inputMethodPanel);
521     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
522 }
523 
524 /**
525  * @tc.name: testIsPanelShown_003
526  * @tc.desc: Test is panel shown.
527  * @tc.type: FUNC
528  */
529 HWTEST_F(InputMethodPanelTest, testIsPanelShown_003, TestSize.Level0)
530 {
531     IMSA_HILOGI("InputMethodPanelTest::testIsPanelShown_003 start.");
532     TddUtil::SetTestTokenID(tokenId_);
533     int32_t ret = ima_->SetCoreAndAgent();
534     bool isShown = false;
535     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
536     PanelInfo panelInfo = { .panelType = STATUS_BAR };
537     ret = ima_->CreatePanel(nullptr, panelInfo, inputMethodPanel);
538     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
539 
540     // query status bar's status when it is showing
541     ret = inputMethodPanel->ShowPanel();
542     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
543     ret = imc_->IsPanelShown(panelInfo, isShown);
544     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
545     EXPECT_TRUE(isShown);
546 
547     // query status bar's status when it is hidden
548     ret = inputMethodPanel->HidePanel();
549     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
550     ret = imc_->IsPanelShown(panelInfo, isShown);
551     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
552     EXPECT_FALSE(isShown);
553 
554     ret = ima_->DestroyPanel(inputMethodPanel);
555     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
556 }
557 
558 /**
559 * @tc.name: testSetPanelStatusListener
560 * @tc.desc: Test SetPanelStatusListener.
561 * @tc.type: FUNC
562 */
563 HWTEST_F(InputMethodPanelTest, testSetPanelStatusListener, TestSize.Level0)
564 {
565     IMSA_HILOGI("InputMethodPanelTest::testSetPanelStatusListener start.");
566     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
567     auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
568     // on('show')->on('hide')->show->hide
569     std::string type = "show";
570     inputMethodPanel->SetPanelStatusListener(statusListener, type);
571     type = "hide";
572     inputMethodPanel->SetPanelStatusListener(statusListener, type);
573 
574     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
575     auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
576     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
577 
578     InputMethodPanelTest::TriggerShowCallback(inputMethodPanel);
579     EXPECT_TRUE(InputMethodPanelTest::showPanel_);
580 
581     InputMethodPanelTest::TriggerHideCallback(inputMethodPanel);
582     EXPECT_TRUE(InputMethodPanelTest::hidePanel_);
583     ret = inputMethodPanel->DestroyPanel();
584     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
585 }
586 
587 /**
588 * @tc.name: testGetPanelType
589 * @tc.desc: Test GetPanelType.
590 * @tc.type: FUNC
591 */
592 HWTEST_F(InputMethodPanelTest, testGetPanelType, TestSize.Level0)
593 {
594     IMSA_HILOGI("InputMethodPanelTest::testGetPanelType start.");
595     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
596     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
597     auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
598     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
599     auto type = inputMethodPanel->GetPanelType();
600     EXPECT_EQ(type, panelInfo.panelType);
601     ret = inputMethodPanel->DestroyPanel();
602     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
603 }
604 
605 /**
606  * @tc.name: testGetPanelFlag
607  * @tc.desc: Test GetPanelFlag.
608  * @tc.type: FUNC
609  */
610 HWTEST_F(InputMethodPanelTest, testGetPanelFlag, TestSize.Level0)
611 {
612     IMSA_HILOGI("InputMethodPanelTest::testGetPanelFlag start.");
613     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
614     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
615     auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
616     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
617     auto flag = inputMethodPanel->GetPanelFlag();
618     EXPECT_EQ(flag, panelInfo.panelFlag);
619 
620     ret = inputMethodPanel->ChangePanelFlag(PanelFlag::FLG_CANDIDATE_COLUMN);
621     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
622     flag = inputMethodPanel->GetPanelFlag();
623     EXPECT_EQ(flag, PanelFlag::FLG_CANDIDATE_COLUMN);
624 
625     ret = inputMethodPanel->DestroyPanel();
626     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
627 }
628 
629 /**
630 * @tc.name: testChangePanelFlag
631 * @tc.desc: Test ChangePanelFlag.
632 * @tc.type: FUNC
633 */
634 HWTEST_F(InputMethodPanelTest, testChangePanelFlag, TestSize.Level0)
635 {
636     IMSA_HILOGI("InputMethodPanelTest::testChangePanelFlag start.");
637     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
638     PanelFlag flag = FLG_FLOATING;
639 
640     // not CreatePanel, ChangePanelFlag failed
641     auto ret = inputMethodPanel->ChangePanelFlag(flag);
642     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
643 
644     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
645     ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
646     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
647 
648     // panelFlag is same with the original
649     ret = inputMethodPanel->ChangePanelFlag(flag);
650     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
651 
652     // panelFlag modify to FLG_FIXED
653     flag = FLG_FIXED;
654     ret = inputMethodPanel->ChangePanelFlag(flag);
655     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
656 
657     inputMethodPanel->DestroyPanel();
658 
659     panelInfo = { .panelType = STATUS_BAR, .panelFlag = FLG_FLOATING };
660     ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
661     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
662     // panelType is STATUS_BAR, not allow ChangePanelFlag
663     ret = inputMethodPanel->ChangePanelFlag(flag);
664     EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
665 
666     inputMethodPanel->DestroyPanel();
667 }
668 
669 /**
670 * @tc.name: testClearPanelListener
671 * @tc.desc: Test ClearPanelListener.
672 * @tc.type: FUNC
673 */
674 HWTEST_F(InputMethodPanelTest, testClearPanelListener, TestSize.Level0)
675 {
676     IMSA_HILOGI("InputMethodPanelTest::testClearPanelListener start.");
677     auto inputMethodPanel = InputMethodPanelTest::CreatePanel();
678 
679     std::string subscribeType = "show";
680     inputMethodPanel->ClearPanelListener(subscribeType);
681     InputMethodPanelTest::TriggerShowCallback(inputMethodPanel);
682     EXPECT_EQ(InputMethodPanelTest::showPanel_, false);
683     InputMethodPanelTest::TriggerHideCallback(inputMethodPanel);
684     EXPECT_EQ(InputMethodPanelTest::hidePanel_, true);
685     InputMethodPanelTest::hidePanel_ = false;
686 
687     subscribeType = "hide";
688     inputMethodPanel->ClearPanelListener(subscribeType);
689 
690     InputMethodPanelTest::TriggerShowCallback(inputMethodPanel);
691     EXPECT_EQ(InputMethodPanelTest::showPanel_, false);
692     InputMethodPanelTest::TriggerHideCallback(inputMethodPanel);
693     EXPECT_EQ(InputMethodPanelTest::hidePanel_, false);
694 
695     auto ret = inputMethodPanel->DestroyPanel();
696     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
697 }
698 
699 /**
700 * @tc.name: testRegisterListener
701 * @tc.desc: Test ClearPanelListener.
702 * @tc.type: FUNC
703 */
704 HWTEST_F(InputMethodPanelTest, testRegisterListener, TestSize.Level0)
705 {
706     // on('show')->on('hide')->show->hide->off('show')->show->hide->on('show')->show
707     IMSA_HILOGI("InputMethodPanelTest::testRegisterListener start.");
708     auto inputMethodPanel = InputMethodPanelTest::CreatePanel();
709 
710     auto statusListener = std::make_shared<InputMethodPanelTest::PanelStatusListenerImpl>();
711     std::string type = "show";
712     inputMethodPanel->SetPanelStatusListener(statusListener, type);
713     type = "hide";
714     inputMethodPanel->SetPanelStatusListener(statusListener, type);
715 
716     InputMethodPanelTest::TriggerShowCallback(inputMethodPanel);
717     EXPECT_TRUE(InputMethodPanelTest::showPanel_);
718 
719     InputMethodPanelTest::TriggerHideCallback(inputMethodPanel);
720     EXPECT_TRUE(InputMethodPanelTest::hidePanel_);
721 
722     type = "show";
723     inputMethodPanel->ClearPanelListener(type);
724 
725     InputMethodPanelTest::TriggerShowCallback(inputMethodPanel);
726     EXPECT_TRUE(!InputMethodPanelTest::showPanel_);
727 
728     InputMethodPanelTest::TriggerHideCallback(inputMethodPanel);
729     EXPECT_TRUE(InputMethodPanelTest::hidePanel_);
730 
731     inputMethodPanel->SetPanelStatusListener(statusListener, type);
732 
733     InputMethodPanelTest::TriggerShowCallback(inputMethodPanel);
734     EXPECT_TRUE(InputMethodPanelTest::showPanel_);
735 
736     auto ret = inputMethodPanel->DestroyPanel();
737     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
738 }
739 
740 /*
741 * @tc.name: testImcPanelListening_001
742 * @tc.desc: SOFT_KEYBOARD  FLG_FIXED  no listening set up  systemApp currentIme
743 * @tc.type: FUNC
744 */
745 HWTEST_F(InputMethodPanelTest, testImcPanelListening_001, TestSize.Level0)
746 {
747     IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_001 start.");
748     TddUtil::SetTestTokenID(tokenId_);
749     InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::HIDE);
750     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
751     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
752     InputMethodPanelTest::ImcPanelListeningTestPrepare(inputMethodPanel, panelInfo, NONE);
753 
754     auto ret = inputMethodPanel->ShowPanel();
755     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
756     InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::HIDE, InputWindowStatus::SHOW);
757 
758     InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::SHOW);
759     ret = inputMethodPanel->HidePanel();
760     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
761     InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::SHOW, InputWindowStatus::HIDE);
762     InputMethodPanelTest::ImcPanelListeningTestClear(inputMethodPanel);
763     TddUtil::RestoreSelfTokenID();
764 }
765 
766 /**
767 * @tc.name: testImcPanelListening_002
768 * @tc.desc: SOFT_KEYBOARD  FLG_FIXED  Set up listening  systemApp currentIme
769 * @tc.type: FUNC
770 */
771 HWTEST_F(InputMethodPanelTest, testImcPanelListening_002, TestSize.Level0)
772 {
773     IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_002 start.");
774     TddUtil::SetTestTokenID(tokenId_);
775     InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::HIDE);
776     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
777     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
778     InputMethodPanelTest::ImcPanelListeningTestPrepare(inputMethodPanel, panelInfo, ON);
779     // need to wait amoment to make sure can get the new window size.
780     sleep(IMC_WAIT_TIME);
781     auto ret = inputMethodPanel->ShowPanel();
782     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
783     InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::SHOW, InputWindowStatus::SHOW,
784         { "", 0, 0, InputMethodPanelTest::windowWidth_, InputMethodPanelTest::windowHeight_ });
785 
786     InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::SHOW);
787     // need to wait amoment to make sure can get the new window size.
788     sleep(IMC_WAIT_TIME);
789     ret = inputMethodPanel->HidePanel();
790     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
791     InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::HIDE, InputWindowStatus::HIDE,
792         { "", 0, 0, InputMethodPanelTest::windowWidth_, InputMethodPanelTest::windowHeight_ });
793     InputMethodPanelTest::ImcPanelListeningTestClear(inputMethodPanel);
794     TddUtil::RestoreSelfTokenID();
795 }
796 
797 /**
798 * @tc.name: testImcPanelListening_003
799 * @tc.desc: SOFT_KEYBOARD  FLG_FIXED  Cancel listening  systemApp currentIme
800 * @tc.type: FUNC
801 */
802 HWTEST_F(InputMethodPanelTest, testImcPanelListening_003, TestSize.Level0)
803 {
804     IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_003 start.");
805     TddUtil::SetTestTokenID(tokenId_);
806     InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::HIDE);
807     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
808     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
809     InputMethodPanelTest::ImcPanelListeningTestPrepare(inputMethodPanel, panelInfo, OFF);
810 
811     auto ret = inputMethodPanel->ShowPanel();
812     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
813     InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::HIDE, InputWindowStatus::SHOW);
814 
815     InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::SHOW);
816     ret = inputMethodPanel->HidePanel();
817     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
818     InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::SHOW, InputWindowStatus::HIDE);
819     InputMethodPanelTest::ImcPanelListeningTestClear(inputMethodPanel);
820     TddUtil::RestoreSelfTokenID();
821 }
822 
823 /**
824 * @tc.name: testImcPanelListening_004
825 * @tc.desc: SOFT_KEYBOARD  FLG_FIXED  Set up listening  not systemApp  currentIme
826 * @tc.type: FUNC
827 */
828 HWTEST_F(InputMethodPanelTest, testImcPanelListening_004, TestSize.Level0)
829 {
830     IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_004 start.");
831     InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::HIDE);
832     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
833     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
834     imc_->UpdateListenEventFlag("imeShow", true);
835     imc_->UpdateListenEventFlag("imeHide", true);
836 
837     TddUtil::SetTestTokenID(tokenId_);
838     auto ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
839     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
840     ret = inputMethodPanel->Resize(windowWidth_, windowHeight_);
841     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
842     ret = inputMethodPanel->ShowPanel();
843     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
844     InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::HIDE, InputWindowStatus::SHOW);
845 
846     InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::SHOW);
847     ret = inputMethodPanel->HidePanel();
848     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
849     InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::SHOW, InputWindowStatus::HIDE);
850     InputMethodPanelTest::ImcPanelListeningTestClear(inputMethodPanel);
851     TddUtil::RestoreSelfTokenID();
852 }
853 
854 /**
855 * @tc.name: testImcPanelListening_005
856 * @tc.desc: SOFT_KEYBOARD  FLG_FIXED  Set up listening   systemApp  not currentIme
857 * @tc.type: FUNC
858 */
859 HWTEST_F(InputMethodPanelTest, testImcPanelListening_005, TestSize.Level0)
860 {
861     IMSA_HILOGI("InputMethodPanelTest::testImcPanelListening_005 start.");
862     TddUtil::SetTestTokenID(tokenId_);
863     InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::HIDE);
864     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
865     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
866 
867     TddUtil::RestoreSelfTokenID();
868     InputMethodPanelTest::ImcPanelListeningTestPrepare(inputMethodPanel, panelInfo, ON);
869     auto ret = inputMethodPanel->ShowPanel();
870     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
871     InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::HIDE, InputWindowStatus::SHOW);
872 
873     InputMethodPanelTest::ImcPanelListeningTestRestore(InputWindowStatus::SHOW);
874     ret = inputMethodPanel->HidePanel();
875     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
876     InputMethodPanelTest::ImcPanelListeningTestCheck(InputWindowStatus::SHOW, InputWindowStatus::HIDE);
877     InputMethodPanelTest::ImcPanelListeningTestClear(inputMethodPanel);
878 }
879 
880 /**
881 * @tc.name: testSetCallingWindow
882 * @tc.desc: test SetCallingWindow
883 * @tc.type: FUNC
884 */
885 HWTEST_F(InputMethodPanelTest, testSetCallingWindow, TestSize.Level0)
886 {
887     IMSA_HILOGI("InputMethodPanelTest::testSetCallingWindow start.");
888     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
889     // not CreatePanel, SetCallingWindow failed
890     uint32_t windowId = 8;
891     auto ret = inputMethodPanel->SetCallingWindow(windowId);
892     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
893 
894     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
895     ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
896     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
897 
898     ret = inputMethodPanel->SetCallingWindow(windowId);
899     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
900 }
901 } // namespace MiscServices
902 } // namespace OHOS