diff --git a/test/unittest/cpp_test/BUILD.gn b/test/unittest/cpp_test/BUILD.gn index cf6371ea4..5e0d00f48 100644 --- a/test/unittest/cpp_test/BUILD.gn +++ b/test/unittest/cpp_test/BUILD.gn @@ -253,6 +253,7 @@ ohos_unittest("InputMethodPanelTest") { "${inputmethod_path}/interfaces/inner_api/inputmethod_ability:inputmethod_ability", "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client_static", "${inputmethod_path}/services:inputmethod_service", + "${inputmethod_path}/test/common:inputmethod_test_common", "${inputmethod_path}/test/unittest/cpp_test/common:inputmethod_tdd_util", "//third_party/googletest:gtest_main", ] diff --git a/test/unittest/cpp_test/src/input_method_panel_test.cpp b/test/unittest/cpp_test/src/input_method_panel_test.cpp index 26c2d5e4f..99acd3334 100644 --- a/test/unittest/cpp_test/src/input_method_panel_test.cpp +++ b/test/unittest/cpp_test/src/input_method_panel_test.cpp @@ -26,6 +26,7 @@ #include "global.h" #include "input_method_ability.h" #include "input_method_controller.h" +#include "input_method_engine_listener_impl.h" #include "panel_status_listener.h" #include "tdd_util.h" #include "text_listener.h" @@ -89,6 +90,7 @@ public: static std::string beforeValue; static std::string allEnableIme; static sptr textListener_; + static std::shared_ptr imeListener_; }; class InputMethodSettingListenerImpl : public InputMethodSettingListener { public: @@ -125,6 +127,7 @@ uint64_t InputMethodPanelTest::tokenId_ = 0; std::string InputMethodPanelTest::beforeValue; std::string InputMethodPanelTest::allEnableIme = "{\"enableImeList\" : {\"100\" : [ \"com.example.testIme\"]}}"; sptr InputMethodPanelTest::textListener_{ nullptr }; +std::shared_ptr InputMethodPanelTest::imeListener_{ nullptr }; void InputMethodPanelTest::SetUpTestCase(void) { IMSA_HILOGI("InputMethodPanelTest::SetUpTestCase"); @@ -147,6 +150,7 @@ void InputMethodPanelTest::SetUpTestCase(void) std::string bundleName = property != nullptr ? property->name : "default.inputmethod.unittest"; tokenId_ = TddUtil::AllocTestTokenID(true, bundleName, { "ohos.permission.CONNECT_IME_ABILITY" }); textListener_ = new (std::nothrow) TextListener(); + imeListener_ = std::make_shared(); } void InputMethodPanelTest::TearDownTestCase(void) @@ -464,6 +468,8 @@ HWTEST_F(InputMethodPanelTest, testIsPanelShown_001, TestSize.Level0) { IMSA_HILOGI("InputMethodPanelTest::testIsPanelShown_001 start."); TddUtil::SetTestTokenID(tokenId_); + TddUtil::InitWindow(true); + InputMethodPanelTest::ima_->SetImeListener(InputMethodPanelTest::imeListener_); int32_t ret = ima_->SetCoreAndAgent(); EXPECT_EQ(ret, ErrorCode::NO_ERROR); ret = InputMethodPanelTest::imc_->Attach(InputMethodPanelTest::textListener_, false); @@ -490,6 +496,7 @@ HWTEST_F(InputMethodPanelTest, testIsPanelShown_001, TestSize.Level0) ret = ima_->DestroyPanel(inputMethodPanel); EXPECT_EQ(ret, ErrorCode::NO_ERROR); + TddUtil::DestroyWindow(); } /** @@ -501,6 +508,8 @@ HWTEST_F(InputMethodPanelTest, testIsPanelShown_002, TestSize.Level0) { IMSA_HILOGI("InputMethodPanelTest::testIsPanelShown_002 start."); TddUtil::SetTestTokenID(tokenId_); + TddUtil::InitWindow(true); + InputMethodPanelTest::ima_->SetImeListener(InputMethodPanelTest::imeListener_); int32_t ret = ima_->SetCoreAndAgent(); EXPECT_EQ(ret, ErrorCode::NO_ERROR); ret = InputMethodPanelTest::imc_->Attach(InputMethodPanelTest::textListener_, false); @@ -528,6 +537,7 @@ HWTEST_F(InputMethodPanelTest, testIsPanelShown_002, TestSize.Level0) ret = ima_->DestroyPanel(inputMethodPanel); EXPECT_EQ(ret, ErrorCode::NO_ERROR); + TddUtil::DestroyWindow(); } /** @@ -539,6 +549,8 @@ HWTEST_F(InputMethodPanelTest, testIsPanelShown_003, TestSize.Level0) { IMSA_HILOGI("InputMethodPanelTest::testIsPanelShown_003 start."); TddUtil::SetTestTokenID(tokenId_); + TddUtil::InitWindow(true); + InputMethodPanelTest::ima_->SetImeListener(InputMethodPanelTest::imeListener_); int32_t ret = ima_->SetCoreAndAgent(); EXPECT_EQ(ret, ErrorCode::NO_ERROR); ret = InputMethodPanelTest::imc_->Attach(InputMethodPanelTest::textListener_, false); @@ -565,6 +577,7 @@ HWTEST_F(InputMethodPanelTest, testIsPanelShown_003, TestSize.Level0) ret = ima_->DestroyPanel(inputMethodPanel); EXPECT_EQ(ret, ErrorCode::NO_ERROR); + TddUtil::DestroyWindow(); } /**