diff --git a/frameworks/js/napi/inputmethodclient/js_utils.cpp b/frameworks/js/napi/inputmethodclient/js_utils.cpp index 2f7c46a4568a29413cad4fa67faec05004495757..f78c88d506cfca9969fff8a88e9d88752ff38e91 100644 --- a/frameworks/js/napi/inputmethodclient/js_utils.cpp +++ b/frameworks/js/napi/inputmethodclient/js_utils.cpp @@ -48,6 +48,8 @@ const std::map JsUtils::ERROR_CODE_MAP = { { ErrorCode::ERROR_EX_ILLEGAL_ARGUMENT, EXCEPTION_IMMS }, { ErrorCode::ERROR_EX_ILLEGAL_STATE, EXCEPTION_IMMS }, { ErrorCode::ERROR_NOT_IME, EXCEPTION_IME }, + { ErrorCode::ERROR_IME_NOT_READY, EXCEPTION_IMENGINE }, + { ErrorCode::ERROR_IME, EXCEPTION_IMENGINE }, }; const std::map JsUtils::ERROR_CODE_CONVERT_MESSAGE_MAP = { diff --git a/frameworks/native/inputmethod_ability/include/i_input_method_core.h b/frameworks/native/inputmethod_ability/include/i_input_method_core.h index ae3016011a2f483d6f75e7e838d3a0ac5e130bbb..3dc62ff454970bce986d47ed22c9ef51140068f6 100644 --- a/frameworks/native/inputmethod_ability/include/i_input_method_core.h +++ b/frameworks/native/inputmethod_ability/include/i_input_method_core.h @@ -46,7 +46,7 @@ public: virtual int32_t ShowKeyboard( const sptr &inputDataChannel, bool isShowKeyboard, bool attachFlag) = 0; - virtual bool HideKeyboard(int32_t flags) = 0; + virtual int32_t HideKeyboard() = 0; virtual int32_t InitInputControlChannel( sptr &inputControlChannel, const std::string &imeId) = 0; virtual void StopInputService(std::string imeId) = 0; diff --git a/frameworks/native/inputmethod_ability/include/input_method_ability.h b/frameworks/native/inputmethod_ability/include/input_method_ability.h index bf64d9334494101629d66f1db222adb8f5d3419e..b929b68f51264ea9f9be4931b095a8a7d5eb289b 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_ability.h +++ b/frameworks/native/inputmethod_ability/include/input_method_ability.h @@ -56,6 +56,9 @@ public: int32_t DeleteForward(int32_t length); int32_t DeleteBackward(int32_t length); int32_t HideKeyboardSelf(); + int32_t ShowKeyboard(const sptr &channelObject, bool isShowKeyboard, bool attachFlag); + int32_t HideKeyboard(); + void ClearDataChannel(const sptr &channel); int32_t SendExtendAction(int32_t action); int32_t GetTextBeforeCursor(int32_t number, std::u16string &text); int32_t GetTextAfterCursor(int32_t number, std::u16string &text); @@ -77,9 +80,7 @@ public: private: std::thread workThreadHandler; MessageHandler *msgHandler; - InputAttribute editorAttribute; - InputChannel *writeInputChannel; - bool stop_; + bool stop_ = false; int32_t KEYBOARD_HIDE = 1; int32_t KEYBOARD_SHOW = 2; @@ -103,7 +104,7 @@ private: sptr deathRecipientPtr_{ nullptr }; sptr GetImsaProxy(); - void SetInputDataChannel(sptr &object); + void SetInputDataChannel(const sptr &object); std::shared_ptr GetInputDataChannelProxy(); void SetInputControlChannel(sptr &object); std::shared_ptr GetInputControlChannel(); @@ -112,17 +113,13 @@ private: void WorkThread(); void QuitWorkThread(); - void OnShowKeyboard(Message *msg); - void OnHideKeyboard(Message *msg); void OnInitInputControlChannel(Message *msg); void OnSetSubtype(Message *msg); - void OnClearDataChannel(Message *msg); void OnCursorUpdate(Message *msg); void OnSelectionChange(Message *msg); void OnConfigurationChange(Message *msg); - void ShowInputWindow(bool isShowKeyboard); - void DismissInputWindow(); + int32_t ShowInputWindow(bool isShowKeyboard); void OnTextConfigChange(const TextTotalConfig &textConfig); bool isImeReady_{ false }; InputStartNotifier notifier_; diff --git a/frameworks/native/inputmethod_ability/include/input_method_core_proxy.h b/frameworks/native/inputmethod_ability/include/input_method_core_proxy.h index 5408ded1867836f715e2431aec8e026a2f04daa8..936a4df8ce4d46493b8adb67ae0e10b6e4d9db0f 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_core_proxy.h +++ b/frameworks/native/inputmethod_ability/include/input_method_core_proxy.h @@ -37,7 +37,7 @@ public: int32_t ShowKeyboard( const sptr &inputDataChannel, bool isShowKeyboard, bool attachFlag) override; - bool HideKeyboard(int32_t flags) override; + int32_t HideKeyboard() override; int32_t InitInputControlChannel(sptr &inputControlChannel, const std::string &imeId) override; void StopInputService(std::string imeId) override; int32_t SetSubtype(const SubProperty &property) override; diff --git a/frameworks/native/inputmethod_ability/include/input_method_core_stub.h b/frameworks/native/inputmethod_ability/include/input_method_core_stub.h index 85a860c8f7d596016fa81f9d3b6f56e7b73664fa..2a5e25e87d766da2ae5124a3946d8cabc8286144 100644 --- a/frameworks/native/inputmethod_ability/include/input_method_core_stub.h +++ b/frameworks/native/inputmethod_ability/include/input_method_core_stub.h @@ -41,7 +41,7 @@ public: int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; int32_t ShowKeyboard( const sptr &inputDataChannel, bool isShowKeyboard, bool attachFlag) override; - bool HideKeyboard(int32_t flags) override; + int32_t HideKeyboard() override; int32_t InitInputControlChannel(sptr &inputControlChannel, const std::string &imeId) override; void StopInputService(std::string imeId) override; int32_t SetSubtype(const SubProperty &property) override; @@ -49,12 +49,12 @@ public: void SetMessageHandler(MessageHandler *msgHandler); private: - int userId_; + int32_t userId_ = -1; MessageHandler *msgHandler_; void InitInputControlChannelOnRemote(MessageParcel &data, MessageParcel &reply); void SetSubtypeOnRemote(MessageParcel &data, MessageParcel &reply); void ShowKeyboardOnRemote(MessageParcel &data, MessageParcel &reply); - void ClearDataChannelOnRemote(MessageParcel &data, MessageParcel &reply); + int32_t ClearDataChannelOnRemote(MessageParcel &data); using ParcelHandler = std::function; int32_t SendMessage(int code, ParcelHandler input = nullptr); }; diff --git a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp index a8ed101c43420dacdecc3c7907d4be3f4724dbae..6b5f51d2541631b5d4f3cc2361b630c685c35693 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp @@ -39,11 +39,7 @@ sptr InputMethodAbility::instance_; std::mutex InputMethodAbility::instanceLock_; constexpr double INVALID_CURSOR_VALUE = -1.0; constexpr int32_t INVALID_SELECTION_VALUE = -1; -InputMethodAbility::InputMethodAbility() : stop_(false) -{ - writeInputChannel = nullptr; - Initialize(); -} +InputMethodAbility::InputMethodAbility() : stop_(false) {} InputMethodAbility::~InputMethodAbility() { @@ -61,7 +57,12 @@ sptr InputMethodAbility::GetInstance() std::lock_guard autoLock(instanceLock_); if (instance_ == nullptr) { IMSA_HILOGI("InputMethodAbility::GetInstance need new IMA"); - instance_ = new InputMethodAbility(); + instance_ = new (std::nothrow) InputMethodAbility(); + if (instance_ == nullptr) { + IMSA_HILOGI("instance is nullptr."); + return instance_; + } + instance_->Initialize(); } } return instance_; @@ -176,14 +177,6 @@ void InputMethodAbility::WorkThread() OnInitInputControlChannel(msg); break; } - case MSG_ID_SHOW_KEYBOARD: { - OnShowKeyboard(msg); - break; - } - case MSG_ID_HIDE_KEYBOARD: { - OnHideKeyboard(msg); - break; - } case MSG_ID_ON_CURSOR_UPDATE: { OnCursorUpdate(msg); break; @@ -209,10 +202,6 @@ void InputMethodAbility::WorkThread() OnSetSubtype(msg); break; } - case MSG_ID_CLEAR_DATA_CHANNEL: { - OnClearDataChannel(msg); - break; - } default: { IMSA_HILOGD("the message is %{public}d.", msg->msgId_); break; @@ -238,20 +227,12 @@ void InputMethodAbility::OnInitInputControlChannel(Message *msg) SetInputControlChannel(channelObject); } -void InputMethodAbility::OnShowKeyboard(Message *msg) +int32_t InputMethodAbility::ShowKeyboard(const sptr &channelObject, bool isShowKeyboard, bool attachFlag) { - IMSA_HILOGI("InputMethodAbility::OnShowKeyboard"); - MessageParcel *data = msg->msgContent_; - sptr channelObject = nullptr; - bool isShowKeyboard = false; - bool attachFlag = false; - if (!ITypesUtil::Unmarshal(*data, channelObject, isShowKeyboard, attachFlag)) { - IMSA_HILOGE("InputMethodAbility::OnShowKeyboard read message parcel failed"); - return; - } + IMSA_HILOGI("InputMethodAbility::ShowKeyboard"); if (channelObject == nullptr) { - IMSA_HILOGE("InputMethodAbility::OnShowKeyboard channelObject is nullptr"); - return; + IMSA_HILOGE("InputMethodAbility::ShowKeyboard channelObject is nullptr"); + return ErrorCode::ERROR_CLIENT_NULL_POINTER; } SetInputDataChannel(channelObject); if (attachFlag) { @@ -259,17 +240,11 @@ void InputMethodAbility::OnShowKeyboard(Message *msg) int32_t ret = GetTextConfig(textConfig); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("InputMethodAbility, get text config failed, ret is %{public}d", ret); - return; + return ret; } OnTextConfigChange(textConfig); } - ShowInputWindow(isShowKeyboard); -} - -void InputMethodAbility::OnHideKeyboard(Message *msg) -{ - IMSA_HILOGI("InputMethodAbility::OnHideKeyboard"); - DismissInputWindow(); + return ShowInputWindow(isShowKeyboard); } void InputMethodAbility::OnSetSubtype(Message *msg) @@ -288,15 +263,9 @@ void InputMethodAbility::OnSetSubtype(Message *msg) imeListener_->OnSetSubtype(subProperty); } -void InputMethodAbility::OnClearDataChannel(Message *msg) +void InputMethodAbility::ClearDataChannel(const sptr &channel) { IMSA_HILOGI("run in"); - auto data = msg->msgContent_; - sptr channel = nullptr; - if (!ITypesUtil::Unmarshal(*data, channel)) { - IMSA_HILOGE("failed to read message parcel"); - return; - } std::lock_guard lock(dataChannelLock_); if (dataChannelObject_ == nullptr || channel == nullptr) { return; @@ -386,29 +355,29 @@ void InputMethodAbility::OnConfigurationChange(Message *msg) kdListener_->OnEditorAttributeChange(attribute); } -void InputMethodAbility::ShowInputWindow(bool isShowKeyboard) +int32_t InputMethodAbility::ShowInputWindow(bool isShowKeyboard) { IMSA_HILOGI("InputMethodAbility::ShowInputWindow"); if (!isImeReady_) { IMSA_HILOGE("InputMethodAbility::ime is unready, store notifier_"); notifier_.isNotify = true; notifier_.isShowKeyboard = isShowKeyboard; - return; + return ErrorCode::ERROR_IME_NOT_READY; } if (imeListener_ == nullptr) { - IMSA_HILOGE("InputMethodAbility::ShowInputWindow imeListener_ is nullptr"); - return; + IMSA_HILOGE("InputMethodAbility, imeListener is nullptr"); + return ErrorCode::ERROR_IME; } imeListener_->OnInputStart(); if (!isShowKeyboard) { IMSA_HILOGI("InputMethodAbility::ShowInputWindow will not show keyboard"); - return; + return ErrorCode::NO_ERROR; } imeListener_->OnKeyboardStatus(true); auto channel = GetInputDataChannelProxy(); if (channel == nullptr) { IMSA_HILOGE("InputMethodAbility::ShowInputWindow channel is nullptr"); - return; + return ErrorCode::ERROR_CLIENT_NULL_POINTER; } channel->SendKeyboardStatus(KEYBOARD_SHOW); auto result = panels_.Find(SOFT_KEYBOARD); @@ -418,8 +387,9 @@ void InputMethodAbility::ShowInputWindow(bool isShowKeyboard) if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("Show panel failed, ret = %{public}d.", ret); } - return; + return ret; } + return ErrorCode::NO_ERROR; } void InputMethodAbility::OnTextConfigChange(const TextTotalConfig &textConfig) @@ -456,30 +426,28 @@ void InputMethodAbility::OnTextConfigChange(const TextTotalConfig &textConfig) IMSA_HILOGD("setCallingWindow end."); } -void InputMethodAbility::DismissInputWindow() +int32_t InputMethodAbility::HideKeyboard() { - IMSA_HILOGI("InputMethodAbility::DismissInputWindow"); + IMSA_HILOGI("InputMethodAbility::HideKeyboard"); if (imeListener_ == nullptr) { - IMSA_HILOGE("InputMethodAbility::DismissInputWindow imeListener_ is nullptr"); - return; + IMSA_HILOGE("InputMethodAbility::HideKeyboard imeListener_ is nullptr"); + return ErrorCode::ERROR_IME; } imeListener_->OnKeyboardStatus(false); auto channel = GetInputDataChannelProxy(); if (channel == nullptr) { - IMSA_HILOGE("InputMethodAbility::DismissInputWindow channel is nullptr"); - return; + IMSA_HILOGE("InputMethodAbility::HideKeyboard channel is nullptr"); + return ErrorCode::ERROR_CLIENT_NULL_POINTER; } channel->SendKeyboardStatus(KEYBOARD_HIDE); auto result = panels_.Find(SOFT_KEYBOARD); if (!result.first) { IMSA_HILOGE("Not find SOFT_KEYBOARD panel."); - return; + return ErrorCode::NO_ERROR; } auto ret = result.second->HidePanel(); - if (ret != NO_ERROR) { - IMSA_HILOGE("Show panel failed, ret = %{public}d.", ret); - return; - } + IMSA_HILOGD("Hide panel, ret = %{public}d.", ret); + return ret; } int32_t InputMethodAbility::InsertText(const std::string text) @@ -533,7 +501,7 @@ int32_t InputMethodAbility::HideKeyboardSelf() return ErrorCode::ERROR_CLIENT_NULL_POINTER; } InputMethodSysEvent::GetInstance().OperateSoftkeyboardBehaviour(OperateIMEInfoCode::IME_HIDE_SELF); - return controlChannel->HideKeyboardSelf(1); + return controlChannel->HideKeyboardSelf(); } int32_t InputMethodAbility::SendExtendAction(int32_t action) @@ -645,7 +613,7 @@ int32_t InputMethodAbility::GetTextConfig(TextTotalConfig &textConfig) return channel->GetTextConfig(textConfig); } -void InputMethodAbility::SetInputDataChannel(sptr &object) +void InputMethodAbility::SetInputDataChannel(const sptr &object) { IMSA_HILOGD("run in SetInputDataChannel"); std::lock_guard lock(dataChannelLock_); diff --git a/frameworks/native/inputmethod_ability/src/input_method_core_proxy.cpp b/frameworks/native/inputmethod_ability/src/input_method_core_proxy.cpp index 310e9a9fa7f9a44e6f12e8932b42c2d159bf80e0..a8ee1033e98119ed334cfadc5680b424571a3071 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_core_proxy.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_core_proxy.cpp @@ -55,12 +55,9 @@ void InputMethodCoreProxy::StopInputService(std::string imeId) }); } -bool InputMethodCoreProxy::HideKeyboard(int32_t flags) +int32_t InputMethodCoreProxy::HideKeyboard() { - auto status = SendRequest(HIDE_KEYBOARD, [flags](MessageParcel &data) { - return ITypesUtil::Marshal(data, flags); - }); - return status == ErrorCode::NO_ERROR; + return SendRequest(HIDE_KEYBOARD); } int32_t InputMethodCoreProxy::SetSubtype(const SubProperty &property) diff --git a/frameworks/native/inputmethod_ability/src/input_method_core_stub.cpp b/frameworks/native/inputmethod_ability/src/input_method_core_stub.cpp index 5d9b7791a1363c092824f7006d7f548ddb5317df..481d4af3a9b367ce7d636a9a39d45270dc2e0b3b 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_core_stub.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_core_stub.cpp @@ -58,8 +58,7 @@ int32_t InputMethodCoreStub::OnRemoteRequest( break; } case HIDE_KEYBOARD: { - HideKeyboard(data.ReadInt32()); - reply.WriteInt32(ErrorCode::NO_ERROR); + reply.WriteInt32(HideKeyboard()); break; } case STOP_INPUT_SERVICE: { @@ -72,7 +71,7 @@ int32_t InputMethodCoreStub::OnRemoteRequest( break; } case CLEAR_DATA_CHANNEL: { - ClearDataChannelOnRemote(data, reply); + reply.WriteInt32(ClearDataChannelOnRemote(data)); break; } default: { @@ -101,19 +100,10 @@ int32_t InputMethodCoreStub::InitInputControlChannel( return ErrorCode::NO_ERROR; } -bool InputMethodCoreStub::HideKeyboard(int32_t flags) +int32_t InputMethodCoreStub::HideKeyboard() { IMSA_HILOGD("InputMethodCoreStub::hideKeyboard"); - if (msgHandler_ == nullptr) { - return ErrorCode::ERROR_NULL_POINTER; - } - MessageParcel *data = new MessageParcel(); - data->WriteInt32(userId_); - data->WriteInt32(flags); - - Message *msg = new Message(MessageID::MSG_ID_HIDE_KEYBOARD, data); - msgHandler_->SendMessage(msg); - return true; + return InputMethodAbility::GetInstance()->HideKeyboard(); } void InputMethodCoreStub::StopInputService(std::string imeId) @@ -158,11 +148,11 @@ void InputMethodCoreStub::ShowKeyboardOnRemote(MessageParcel &data, MessageParce sptr channel; bool isShowKeyboard = false; bool attachFlag = false; - int32_t ret = SendMessage( - MessageID::MSG_ID_SHOW_KEYBOARD, [&data, &channel, &isShowKeyboard, &attachFlag](MessageParcel &parcel) { - return ITypesUtil::Unmarshal(data, channel, isShowKeyboard, attachFlag) && - ITypesUtil::Marshal(parcel, channel, isShowKeyboard, attachFlag); - }); + if (!ITypesUtil::Unmarshal(data, channel, isShowKeyboard, attachFlag)) { + IMSA_HILOGE("Unmarshal failed."); + return; + } + auto ret = InputMethodAbility::GetInstance()->ShowKeyboard(channel, isShowKeyboard, attachFlag); reply.WriteInt32(ret); } @@ -176,13 +166,15 @@ void InputMethodCoreStub::SetSubtypeOnRemote(MessageParcel &data, MessageParcel reply.WriteInt32(ret); } -void InputMethodCoreStub::ClearDataChannelOnRemote(MessageParcel &data, MessageParcel &reply) +int32_t InputMethodCoreStub::ClearDataChannelOnRemote(MessageParcel &data) { - sptr channel; - int32_t ret = SendMessage(MessageID::MSG_ID_CLEAR_DATA_CHANNEL, [&data, &channel](MessageParcel &parcel) { - return ITypesUtil::Unmarshal(data, channel) && ITypesUtil::Marshal(parcel, channel); - }); - reply.WriteInt32(ret); + sptr channel = nullptr; + if (!ITypesUtil::Unmarshal(data, channel)) { + IMSA_HILOGE("failed to read message parcel"); + return ErrorCode::ERROR_CLIENT_NULL_POINTER; + } + InputMethodAbility::GetInstance()->ClearDataChannel(channel); + return ErrorCode::NO_ERROR; } int32_t InputMethodCoreStub::ShowKeyboard( diff --git a/services/include/global.h b/services/include/global.h index d29a692fba0e38066ff6dfd3c4a358e7467ffe05..1d12a192becf85494010c0ac40aacc91b0772765 100644 --- a/services/include/global.h +++ b/services/include/global.h @@ -96,6 +96,8 @@ enum { ERROR_NOT_IME = 22, ERROR_ADD_DEATH_RECIPIENT_FAILED = 23, ERROR_STATUS_SYSTEM_PERMISSION = 24, // not system application + ERROR_IME_NOT_READY = 25, + ERROR_IME = 26, }; }; // namespace ErrorCode diff --git a/services/include/i_input_control_channel.h b/services/include/i_input_control_channel.h index 8e302aeef677f1ffbf943b6a88bcc36f71471011..f07c390bdfed4dc9ff6102c5138c8071de00200f 100644 --- a/services/include/i_input_control_channel.h +++ b/services/include/i_input_control_channel.h @@ -32,7 +32,7 @@ public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.InputControlChannel"); - virtual int32_t HideKeyboardSelf(int flags) = 0; + virtual int32_t HideKeyboardSelf() = 0; }; } // namespace MiscServices } // namespace OHOS diff --git a/services/include/input_control_channel_proxy.h b/services/include/input_control_channel_proxy.h index 2ca1ebe0d0bcdf531652750a956cce76172887f1..bb3f37bddce2f9b40009aa1b06f54fa2756d53bf 100644 --- a/services/include/input_control_channel_proxy.h +++ b/services/include/input_control_channel_proxy.h @@ -32,7 +32,7 @@ public: InputControlChannelProxy(const sptr &impl); ~InputControlChannelProxy(); - int32_t HideKeyboardSelf(int flags) override; + int32_t HideKeyboardSelf() override; }; } // namespace MiscServices } // namespace OHOS diff --git a/services/include/input_control_channel_stub.h b/services/include/input_control_channel_stub.h index bb7c1a27828c8134b966b53dd7e2a8ec194fcee3..f867ccfc1fd74721690b0e4d4d06adc76f700ed3 100644 --- a/services/include/input_control_channel_stub.h +++ b/services/include/input_control_channel_stub.h @@ -33,7 +33,7 @@ public: explicit InputControlChannelStub(int32_t userId); virtual ~InputControlChannelStub(); int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - int32_t HideKeyboardSelf(int flags) override; + int32_t HideKeyboardSelf() override; private: int32_t userId_; diff --git a/services/include/message_handler.h b/services/include/message_handler.h index d6f7d873506a447062a2a9965085113c37fc9958..5b0179aeeb977552fed02575372d7310a0ea047e 100644 --- a/services/include/message_handler.h +++ b/services/include/message_handler.h @@ -54,12 +54,9 @@ enum { MSG_ID_ON_PANEL_STATUS_CHANGE, // the request from IMSA to IMA - MSG_ID_SHOW_KEYBOARD, - MSG_ID_HIDE_KEYBOARD, MSG_ID_STOP_INPUT_SERVICE, MSG_ID_INIT_INPUT_CONTROL_CHANNEL, MSG_ID_SET_SUBTYPE, - MSG_ID_CLEAR_DATA_CHANNEL, // the request from IMC to IMA MSG_ID_ON_CURSOR_UPDATE, diff --git a/services/src/input_control_channel_proxy.cpp b/services/src/input_control_channel_proxy.cpp index 319a408970e99b541d2e28ff967c80a300c116df..142be1702ff971fc138b02cca3d303e05ce3ddb6 100644 --- a/services/src/input_control_channel_proxy.cpp +++ b/services/src/input_control_channel_proxy.cpp @@ -36,7 +36,7 @@ InputControlChannelProxy::~InputControlChannelProxy() { } -int32_t InputControlChannelProxy::HideKeyboardSelf(int flags) +int32_t InputControlChannelProxy::HideKeyboardSelf() { IMSA_HILOGI("InputControlChannelProxy::HideKeyboardSelf"); MessageParcel data; @@ -46,10 +46,6 @@ int32_t InputControlChannelProxy::HideKeyboardSelf(int flags) IMSA_HILOGE("InputControlChannelProxy::HideKeyboardSelf descriptor is not match"); return ErrorCode::ERROR_EX_PARCELABLE; } - if (!ITypesUtil::Marshal(data, flags)) { - IMSA_HILOGE("Marshalling failed"); - return ErrorCode::ERROR_EX_PARCELABLE; - } auto ret = Remote()->SendRequest(HIDE_KEYBOARD_SELF, data, reply, option); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("InputControlChannelProxy::HideKeyboardSelf SendRequest failed"); diff --git a/services/src/input_control_channel_stub.cpp b/services/src/input_control_channel_stub.cpp index 912877fea53851a0b5cd7b615b14ffaf926caeb2..aefe77046640a5a3f40a4b6fcf352344d553aab9 100644 --- a/services/src/input_control_channel_stub.cpp +++ b/services/src/input_control_channel_stub.cpp @@ -44,7 +44,7 @@ int32_t InputControlChannelStub::OnRemoteRequest( } switch (code) { case HIDE_KEYBOARD_SELF: { - reply.WriteInt32(HideKeyboardSelf(data.ReadInt32())); + reply.WriteInt32(HideKeyboardSelf()); break; } default: { @@ -54,13 +54,13 @@ int32_t InputControlChannelStub::OnRemoteRequest( return NO_ERROR; } -int32_t InputControlChannelStub::HideKeyboardSelf(int flags) +int32_t InputControlChannelStub::HideKeyboardSelf() { - IMSA_HILOGI("InputControlChannelStub::HideKeyboardSelf flags = %{public}d", flags); - MessageParcel *parcel = new MessageParcel(); - parcel->WriteInt32(flags); - - Message *msg = new Message(MessageID::MSG_ID_HIDE_KEYBOARD_SELF, parcel); + IMSA_HILOGI("InputControlChannelStub run in."); + Message *msg = new (std::nothrow) Message(MessageID::MSG_ID_HIDE_KEYBOARD_SELF, nullptr); + if (msg == nullptr) { + return ErrorCode::ERROR_NULL_POINTER; + } MessageHandler::Instance()->SendMessage(msg); return ErrorCode::NO_ERROR; } diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 788c406b8fa3eb6194e6b622c0faf0f96d82f597..ee2e57afece322bd624ed0b21b7cf58065893bc6 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -182,12 +182,9 @@ int32_t PerUserSession::HideKeyboard(const sptr &inputClient) if (inputClient != nullptr) { UpdateClient(inputClient->AsObject(), false); } - bool ret = core->HideKeyboard(1); - if (!ret) { - IMSA_HILOGE("core->HideKeyboard failed"); - return ErrorCode::ERROR_KBD_HIDE_FAILED; - } - return ErrorCode::NO_ERROR; + auto ret = core->HideKeyboard(); + IMSA_HILOGD("HideKeyboard end, ret = %{public}d", ret); + return ret; } int32_t PerUserSession::ClearDataChannel(const sptr &channel) diff --git a/test/common/BUILD.gn b/test/common/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..5a3289003365f6e369b2140d01fb93f829970a51 --- /dev/null +++ b/test/common/BUILD.gn @@ -0,0 +1,49 @@ +# Copyright (C) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//base/inputmethod/imf/inputmethod.gni") +import("//build/ohos.gni") + +config("test_common_config") { + visibility = [ ":*" ] + include_dirs = [ "./" ] + ldflags = [ "-Wl,--exclude-libs=ALL" ] + cflags = [ + "-fdata-sections", + "-ffunction-sections", + "-fvisibility=hidden", + ] +} + +config("test_common_public_config") { + visibility = [ "./*" ] + include_dirs = [ "include" ] +} + +ohos_static_library("inputmethod_test_common") { + testonly = true + sources = [ + "src/input_method_engine_listener_impl.cpp", + "src/text_listener.cpp", + ] + configs = [ ":test_common_config" ] + public_configs = [ ":test_common_public_config" ] + deps = [ + "${inputmethod_path}/frameworks/native/inputmethod_ability:inputmethod_ability", + "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client_static", + ] + external_deps = [ "hilog:libhilog" ] + + subsystem_name = "inputmethod" + part_name = "imf" +} diff --git a/test/common/include/input_method_engine_listener_impl.h b/test/common/include/input_method_engine_listener_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..776a3afa569b4cbb03e77fb55d7d221c66a621d1 --- /dev/null +++ b/test/common/include/input_method_engine_listener_impl.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INPUTMETHOD_IMF_INPUT_METHOD_ENGINE_LISTENER_IMPL_H +#define INPUTMETHOD_IMF_INPUT_METHOD_ENGINE_LISTENER_IMPL_H + +#include "input_method_engine_listener.h" + +namespace OHOS { +namespace MiscServices { +class InputMethodEngineListenerImpl : public InputMethodEngineListener { +public: + InputMethodEngineListenerImpl(){}; + ~InputMethodEngineListenerImpl(){}; + static bool keyboardState_; + static bool isInputStart_; + static uint32_t windowId_; + static std::mutex imeListenerMutex_; + static std::condition_variable imeListenerCv_; + void OnKeyboardStatus(bool isShow) override; + void OnInputStart() override; + void OnInputStop(const std::string &imeId) override; + void OnSetCallingWindow(uint32_t windowId) override; + void OnSetSubtype(const SubProperty &property) override; +}; +} // namespace MiscServices +} // namespace OHOS + +#endif //INPUTMETHOD_IMF_INPUT_METHOD_ENGINE_LISTENER_IMPL_H diff --git a/test/common/text_listener.h b/test/common/include/text_listener.h similarity index 30% rename from test/common/text_listener.h rename to test/common/include/text_listener.h index 68210f3552f82dc09adc88a6e44bc996d0e02e65..35f4ed9b76a4a9532d5a0399dbfb202453bdbcd9 100644 --- a/test/common/text_listener.h +++ b/test/common/include/text_listener.h @@ -16,9 +16,8 @@ #ifndef INPUTMETHOD_TEST_TEXT_LISTENER_H #define INPUTMETHOD_TEST_TEXT_LISTENER_H -#include - #include +#include #include "input_method_controller.h" #include "input_method_utils.h" @@ -29,137 +28,25 @@ namespace OHOS { namespace MiscServices { class TextListener : public OnTextChangedListener { public: - TextListener() - { - std::shared_ptr runner = AppExecFwk::EventRunner::Create("TextListenerNotifier"); - serviceHandler_ = std::make_shared(runner); - } - ~TextListener() - { - } - void InsertText(const std::u16string &text) override - { - insertText_ = text; - textListenerCv_.notify_one(); - } - - void DeleteForward(int32_t length) override - { - deleteForwardLength_ = length; - textListenerCv_.notify_one(); - IMSA_HILOGI("TextChangeListener: DeleteForward, length is: %{public}d", length); - } - - void DeleteBackward(int32_t length) override - { - deleteBackwardLength_ = length; - textListenerCv_.notify_one(); - IMSA_HILOGI("TextChangeListener: DeleteBackward, direction is: %{public}d", length); - } - - void SendKeyEventFromInputMethod(const KeyEvent &event) override - { - } - - void SendKeyboardStatus(const KeyboardStatus &keyboardStatus) override - { - IMSA_HILOGD("TextListener::SendKeyboardStatus %{public}d", static_cast(keyboardStatus)); - constexpr int32_t interval = 20; - { - std::unique_lock lock(textListenerCallbackLock_); - IMSA_HILOGD("TextListener::SendKeyboardStatus lock"); - keyboardStatus_ = keyboardStatus; - } - serviceHandler_->PostTask([this]() { textListenerCv_.notify_all(); }, interval); - IMSA_HILOGD("TextListener::SendKeyboardStatus notify_all"); - } - - void SendFunctionKey(const FunctionKey &functionKey) override - { - EnterKeyType enterKeyType = functionKey.GetEnterKeyType(); - key_ = static_cast(enterKeyType); - textListenerCv_.notify_one(); - } - - void SetKeyboardStatus(bool status) override - { - status_ = status; - } - - void MoveCursor(const Direction direction) override - { - direction_ = static_cast(direction); - textListenerCv_.notify_one(); - IMSA_HILOGI("TextChangeListener: MoveCursor, direction is: %{public}d", direction); - } - - void HandleSetSelection(int32_t start, int32_t end) override - { - selectionStart_ = start; - selectionEnd_ = end; - textListenerCv_.notify_one(); - IMSA_HILOGI("TextChangeListener, selectionStart_: %{public}d, selectionEnd_: %{public}d", selectionStart_, - selectionEnd_); - } - - void HandleExtendAction(int32_t action) override - { - action_ = action; - textListenerCv_.notify_one(); - IMSA_HILOGI("HandleExtendAction, action_: %{public}d", action_); - } - - void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip) override - { - selectionDirection_ = keyCode; - textListenerCv_.notify_one(); - IMSA_HILOGI("TextChangeListener, selectionDirection_: %{public}d", selectionDirection_); - } - std::u16string GetLeftTextOfCursor(int32_t number) override - { - if (isTimeout_) { - usleep(MAX_TIMEOUT); - } - return Str8ToStr16(TEXT_BEFORE_CURSOR); - } - std::u16string GetRightTextOfCursor(int32_t number) override - { - if (isTimeout_) { - usleep(MAX_TIMEOUT); - } - return Str8ToStr16(TEXT_AFTER_CURSOR); - } - int32_t GetTextIndexAtCursor() override - { - if (isTimeout_) { - usleep(MAX_TIMEOUT); - } - return TEXT_INDEX; - } - static void setTimeout(bool isTimeout) - { - isTimeout_ = isTimeout; - } - static void ResetParam() - { - direction_ = -1; - deleteForwardLength_ = -1; - deleteBackwardLength_ = -1; - insertText_ = u""; - key_ = -1; - status_ = false; - selectionStart_ = -1; - selectionEnd_ = -1; - selectionDirection_ = -1; - action_ = -1; - keyboardStatus_ = KeyboardStatus::NONE; - isTimeout_ = false; - } - static bool WaitIMACallback() - { - std::unique_lock lock(textListenerCallbackLock_); - return TextListener::textListenerCv_.wait_for(lock, std::chrono::seconds(1)) != std::cv_status::timeout; - } + TextListener(); + ~TextListener(); + void InsertText(const std::u16string &text) override; + void DeleteForward(int32_t length) override; + void DeleteBackward(int32_t length) override; + void SendKeyEventFromInputMethod(const KeyEvent &event) override; + void SendKeyboardStatus(const KeyboardStatus &keyboardStatus) override; + void SendFunctionKey(const FunctionKey &functionKey) override; + void SetKeyboardStatus(bool status) override; + void MoveCursor(const Direction direction) override; + void HandleSetSelection(int32_t start, int32_t end) override; + void HandleExtendAction(int32_t action) override; + void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip) override; + std::u16string GetLeftTextOfCursor(int32_t number) override; + std::u16string GetRightTextOfCursor(int32_t number) override; + int32_t GetTextIndexAtCursor() override; + static void setTimeout(bool isTimeout); + static void ResetParam(); + static bool WaitIMACallback(); static std::mutex textListenerCallbackLock_; static std::condition_variable textListenerCv_; static int32_t direction_; @@ -175,25 +62,11 @@ public: static KeyboardStatus keyboardStatus_; static bool isTimeout_; std::shared_ptr serviceHandler_; - static constexpr int32_t MAX_TIMEOUT = 3010000; - static constexpr int32_t TEXT_INDEX = 455; - static constexpr const char* TEXT_BEFORE_CURSOR = "before"; - static constexpr const char* TEXT_AFTER_CURSOR = "after"; + static constexpr int32_t MAX_TIMEOUT = 3010000; + static constexpr int32_t TEXT_INDEX = 455; + static constexpr const char *TEXT_BEFORE_CURSOR = "before"; + static constexpr const char *TEXT_AFTER_CURSOR = "after"; }; -std::mutex TextListener::textListenerCallbackLock_; -std::condition_variable TextListener::textListenerCv_; -int32_t TextListener::direction_ = -1; -int32_t TextListener::deleteForwardLength_ = -1; -int32_t TextListener::deleteBackwardLength_ = -1; -std::u16string TextListener::insertText_; -int32_t TextListener::key_ = -1; -bool TextListener::status_ = false; -int32_t TextListener::selectionStart_ = -1; -int32_t TextListener::selectionEnd_ = -1; -int32_t TextListener::selectionDirection_ = -1; -int32_t TextListener::action_ = -1; -KeyboardStatus TextListener::keyboardStatus_ = { KeyboardStatus::NONE }; -bool TextListener::isTimeout_ = { false }; } // namespace MiscServices } // namespace OHOS diff --git a/test/common/src/input_method_engine_listener_impl.cpp b/test/common/src/input_method_engine_listener_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0e6342eac88dddd444e532a554d75bf47543665a --- /dev/null +++ b/test/common/src/input_method_engine_listener_impl.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "input_method_engine_listener_impl.h" + +#include "global.h" + +namespace OHOS { +namespace MiscServices { +bool InputMethodEngineListenerImpl::keyboardState_ = false; +bool InputMethodEngineListenerImpl::isInputStart_ = false; +uint32_t InputMethodEngineListenerImpl::windowId_ = 0; +std::mutex InputMethodEngineListenerImpl::imeListenerMutex_; +std::condition_variable InputMethodEngineListenerImpl::imeListenerCv_; +void InputMethodEngineListenerImpl::OnKeyboardStatus(bool isShow) +{ + IMSA_HILOGI("InputMethodEngineListenerImpl::OnKeyboardStatus %{public}s", isShow ? "show" : "hide"); + keyboardState_ = isShow; +} +void InputMethodEngineListenerImpl::OnInputStart() +{ + IMSA_HILOGI("InputMethodEngineListenerImpl::OnInputStart"); + isInputStart_ = true; +} +void InputMethodEngineListenerImpl::OnInputStop(const std::string &imeId) +{ + IMSA_HILOGI("InputMethodEngineListenerImpl::OnInputStop %{public}s", imeId.c_str()); + isInputStart_ = false; +} +void InputMethodEngineListenerImpl::OnSetCallingWindow(uint32_t windowId) +{ + IMSA_HILOGI("InputMethodEngineListenerImpl::OnSetCallingWindow %{public}d", windowId); + windowId_ = windowId; +} +void InputMethodEngineListenerImpl::OnSetSubtype(const SubProperty &property) +{ + IMSA_HILOGD("InputMethodEngineListenerImpl::OnSetSubtype"); +} +} // namespace MiscServices +} // namespace OHOS diff --git a/test/common/src/text_listener.cpp b/test/common/src/text_listener.cpp new file mode 100644 index 0000000000000000000000000000000000000000..19a28366916ae04d2afc3391750301572ca90af8 --- /dev/null +++ b/test/common/src/text_listener.cpp @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "text_listener.h" + +namespace OHOS { +namespace MiscServices { +std::mutex TextListener::textListenerCallbackLock_; +std::condition_variable TextListener::textListenerCv_; +int32_t TextListener::direction_ = -1; +int32_t TextListener::deleteForwardLength_ = -1; +int32_t TextListener::deleteBackwardLength_ = -1; +std::u16string TextListener::insertText_; +int32_t TextListener::key_ = -1; +bool TextListener::status_ = false; +int32_t TextListener::selectionStart_ = -1; +int32_t TextListener::selectionEnd_ = -1; +int32_t TextListener::selectionDirection_ = -1; +int32_t TextListener::action_ = -1; +KeyboardStatus TextListener::keyboardStatus_ = { KeyboardStatus::NONE }; +bool TextListener::isTimeout_ = { false }; + +TextListener::TextListener() +{ + std::shared_ptr runner = AppExecFwk::EventRunner::Create("TextListenerNotifier"); + serviceHandler_ = std::make_shared(runner); +} + +TextListener::~TextListener() {} + +void TextListener::InsertText(const std::u16string &text) +{ + insertText_ = text; + textListenerCv_.notify_one(); +} + +void TextListener::DeleteForward(int32_t length) +{ + deleteForwardLength_ = length; + textListenerCv_.notify_one(); + IMSA_HILOGI("TextChangeListener: DeleteForward, length is: %{public}d", length); +} + +void TextListener::DeleteBackward(int32_t length) +{ + deleteBackwardLength_ = length; + textListenerCv_.notify_one(); + IMSA_HILOGI("TextChangeListener: DeleteBackward, direction is: %{public}d", length); +} + +void TextListener::SendKeyEventFromInputMethod(const KeyEvent &event) {} + +void TextListener::SendKeyboardStatus(const KeyboardStatus &keyboardStatus) +{ + IMSA_HILOGD("TextListener::SendKeyboardStatus %{public}d", static_cast(keyboardStatus)); + constexpr int32_t interval = 20; + { + std::unique_lock lock(textListenerCallbackLock_); + IMSA_HILOGD("TextListener::SendKeyboardStatus lock"); + keyboardStatus_ = keyboardStatus; + } + serviceHandler_->PostTask( + [this]() { + textListenerCv_.notify_all(); + }, + interval); + IMSA_HILOGD("TextListener::SendKeyboardStatus notify_all"); +} + +void TextListener::SendFunctionKey(const FunctionKey &functionKey) +{ + EnterKeyType enterKeyType = functionKey.GetEnterKeyType(); + key_ = static_cast(enterKeyType); + textListenerCv_.notify_one(); +} + +void TextListener::SetKeyboardStatus(bool status) +{ + status_ = status; +} + +void TextListener::MoveCursor(const Direction direction) +{ + direction_ = static_cast(direction); + textListenerCv_.notify_one(); + IMSA_HILOGI("TextChangeListener: MoveCursor, direction is: %{public}d", direction); +} + +void TextListener::HandleSetSelection(int32_t start, int32_t end) +{ + selectionStart_ = start; + selectionEnd_ = end; + textListenerCv_.notify_one(); + IMSA_HILOGI( + "TextChangeListener, selectionStart_: %{public}d, selectionEnd_: %{public}d", selectionStart_, selectionEnd_); +} + +void TextListener::HandleExtendAction(int32_t action) +{ + action_ = action; + textListenerCv_.notify_one(); + IMSA_HILOGI("HandleExtendAction, action_: %{public}d", action_); +} + +void TextListener::HandleSelect(int32_t keyCode, int32_t cursorMoveSkip) +{ + selectionDirection_ = keyCode; + textListenerCv_.notify_one(); + IMSA_HILOGI("TextChangeListener, selectionDirection_: %{public}d", selectionDirection_); +} +std::u16string TextListener::GetLeftTextOfCursor(int32_t number) +{ + if (isTimeout_) { + usleep(MAX_TIMEOUT); + } + return Str8ToStr16(TEXT_BEFORE_CURSOR); +} +std::u16string TextListener::GetRightTextOfCursor(int32_t number) +{ + if (isTimeout_) { + usleep(MAX_TIMEOUT); + } + return Str8ToStr16(TEXT_AFTER_CURSOR); +} +int32_t TextListener::GetTextIndexAtCursor() +{ + if (isTimeout_) { + usleep(MAX_TIMEOUT); + } + return TEXT_INDEX; +} +void TextListener::setTimeout(bool isTimeout) +{ + isTimeout_ = isTimeout; +} +void TextListener::ResetParam() +{ + direction_ = -1; + deleteForwardLength_ = -1; + deleteBackwardLength_ = -1; + insertText_ = u""; + key_ = -1; + status_ = false; + selectionStart_ = -1; + selectionEnd_ = -1; + selectionDirection_ = -1; + action_ = -1; + keyboardStatus_ = KeyboardStatus::NONE; + isTimeout_ = false; +} +bool TextListener::WaitIMACallback() +{ + std::unique_lock lock(textListenerCallbackLock_); + return TextListener::textListenerCv_.wait_for(lock, std::chrono::seconds(1)) != std::cv_status::timeout; +} +} // namespace MiscServices +} // namespace OHOS \ No newline at end of file diff --git a/test/fuzztest/inputmethodability_fuzzer/BUILD.gn b/test/fuzztest/inputmethodability_fuzzer/BUILD.gn index df19d08304c298066cc4e511b802fe75753f90bd..c6e1daa203c833bd9af276c9f32ece6b04501d23 100644 --- a/test/fuzztest/inputmethodability_fuzzer/BUILD.gn +++ b/test/fuzztest/inputmethodability_fuzzer/BUILD.gn @@ -39,6 +39,7 @@ ohos_fuzztest("InputMethodAbilityFuzzTest") { deps = [ "${inputmethod_path}/frameworks/native/inputmethod_ability:inputmethod_ability", "${inputmethod_path}/services:inputmethod_service", + "${inputmethod_path}/test/common:inputmethod_test_common", ] external_deps = [ diff --git a/test/fuzztest/inputmethodability_fuzzer/inputmethodability_fuzzer.cpp b/test/fuzztest/inputmethodability_fuzzer/inputmethodability_fuzzer.cpp index 58eb0685e1140cbcbec89f23be1d6a40c6603a7a..d749627489695c8ff53eb3565967d4998f66273a 100644 --- a/test/fuzztest/inputmethodability_fuzzer/inputmethodability_fuzzer.cpp +++ b/test/fuzztest/inputmethodability_fuzzer/inputmethodability_fuzzer.cpp @@ -18,17 +18,10 @@ #include #include "input_method_ability.h" +#include "input_method_engine_listener_impl.h" using namespace OHOS::MiscServices; namespace OHOS { -class EngineListener : public InputMethodEngineListener { - void OnKeyboardStatus(bool isShow) {} - void OnInputStart() {} - void OnInputStop(const std::string &imeId) {} - void OnSetCallingWindow(uint32_t windowId) {} - void OnSetSubtype(const SubProperty &property) {} -}; - class KeyboardListenerImpl : public KeyboardListener { bool OnKeyEvent(int32_t keyCode, int32_t keyStatus) { @@ -53,7 +46,7 @@ void TestInsertText(std::string fuzzedString) void TestSetImeListener() { sptr ability = InputMethodAbility::GetInstance(); - auto engineListener = std::make_shared(); + auto engineListener = std::make_shared(); ability->SetImeListener(engineListener); } diff --git a/test/fuzztest/inputmethodcontroller_fuzzer/BUILD.gn b/test/fuzztest/inputmethodcontroller_fuzzer/BUILD.gn index e0a8b8cfda587a32c17baf628a1e815f35a5146c..439969f6c45c9471dd0e35d1c8a704108e9665e5 100644 --- a/test/fuzztest/inputmethodcontroller_fuzzer/BUILD.gn +++ b/test/fuzztest/inputmethodcontroller_fuzzer/BUILD.gn @@ -42,6 +42,7 @@ ohos_fuzztest("InputMethodControllerFuzzTest") { deps = [ "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client", "${inputmethod_path}/services:inputmethod_service", + "${inputmethod_path}/test/common:inputmethod_test_common", ] external_deps = [ diff --git a/test/fuzztest/systemabilitystub_fuzzer/BUILD.gn b/test/fuzztest/systemabilitystub_fuzzer/BUILD.gn index 01598c7870833544f977a30994bbcd0ed3fe2966..f0d2b091f59afe05775a53a11c20ab3948dff4ed 100644 --- a/test/fuzztest/systemabilitystub_fuzzer/BUILD.gn +++ b/test/fuzztest/systemabilitystub_fuzzer/BUILD.gn @@ -42,6 +42,7 @@ ohos_fuzztest("SystemAbilityStubFuzzTest") { deps = [ "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client_static", "${inputmethod_path}/services:inputmethod_service", + "${inputmethod_path}/test/common:inputmethod_test_common", "//third_party/jsoncpp:jsoncpp", ] diff --git a/test/unittest/cpp_test/BUILD.gn b/test/unittest/cpp_test/BUILD.gn index a902c298f398686e864971d06bf0cef8ff86a9b4..6a1825c9c3ef50f1705a1c0aaa092159d72258c4 100644 --- a/test/unittest/cpp_test/BUILD.gn +++ b/test/unittest/cpp_test/BUILD.gn @@ -36,6 +36,7 @@ ohos_unittest("InputMethodControllerTest") { "${inputmethod_path}/frameworks/native/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:gmock", "//third_party/googletest:gtest_main", @@ -68,6 +69,7 @@ ohos_unittest("InputMethodAttachTest") { "${inputmethod_path}/frameworks/native/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:gmock", "//third_party/googletest:gtest_main", @@ -101,6 +103,7 @@ ohos_unittest("InputMethodAbilityTest") { "${inputmethod_path}/frameworks/native/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", ] @@ -139,6 +142,7 @@ ohos_unittest("InputMethodServiceTest") { "${inputmethod_path}/frameworks/native/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", ] @@ -170,6 +174,7 @@ ohos_unittest("InputMethodDfxTest") { "${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client", "${inputmethod_path}/services:inputmethod_service", "${inputmethod_path}/services/dfx:inputmethod_dfx_static", + "${inputmethod_path}/test/common:inputmethod_test_common", "${inputmethod_path}/test/unittest/cpp_test/common:inputmethod_tdd_util", "//third_party/googletest:gtest_main", ] @@ -303,6 +308,7 @@ ohos_unittest("InputMethodEditorTest") { "${inputmethod_path}/frameworks/native/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_ability_test.cpp b/test/unittest/cpp_test/src/input_method_ability_test.cpp index 21a3b2cb58975776f97b3b83614a3a093caf932b..71cc8aa74dc657f573f22756ac1d430dd52bf2ba 100644 --- a/test/unittest/cpp_test/src/input_method_ability_test.cpp +++ b/test/unittest/cpp_test/src/input_method_ability_test.cpp @@ -101,12 +101,6 @@ public: inputMethodAbility_->OnImeReady(); inputMethodAbility_->SetCoreAndAgent(); TddUtil::RestoreSelfTokenID(); - - WindowMgr::CreateWindow(); - WindowMgr::ShowWindow(); - sptr textListener = new TextListener(); - imc_ = InputMethodController::GetInstance(); - imc_->Attach(textListener); TextListener::ResetParam(); } static void TearDownTestCase(void) @@ -175,14 +169,37 @@ HWTEST_F(InputMethodAbilityTest, testShowKeyboardInputMethodCoreProxy, TestSize. sptr coreProxy = new InputMethodCoreProxy(coreObject); sptr channelProxy = new InputDataChannelProxy(channelObject); auto ret = coreProxy->ShowKeyboard(channelProxy, false, false); - std::unique_lock lock(InputMethodAbilityTest::imeListenerCallbackLock_); - auto cvStatus = InputMethodAbilityTest::imeListenerCv_.wait_for(lock, std::chrono::seconds(DEALY_TIME)); - EXPECT_EQ(ret, ErrorCode::NO_ERROR); - EXPECT_EQ(cvStatus, std::cv_status::timeout); - EXPECT_TRUE(InputMethodAbilityTest::showKeyboard_); + EXPECT_EQ(ret, ErrorCode::ERROR_IME); delete msgHandler; } +/** +* @tc.name: testShowKeyboardException +* @tc.desc: InputMethodAbility ShowKeyboard without imeListener +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(InputMethodAbilityTest, testShowKeyboardException, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodAbilityTest testShowKeyboardException start."); + sptr channelStub = new InputDataChannelStub(); + auto ret = inputMethodAbility_->ShowKeyboard(channelStub->AsObject(), false, false); + EXPECT_EQ(ret, ErrorCode::ERROR_IME); +} + +/** +* @tc.name: testHideKeyboard +* @tc.desc: InputMethodAbility HideKeyboard +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(InputMethodAbilityTest, testHideKeyboard, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodAbilityTest testHideKeyboard start."); + auto ret = inputMethodAbility_->HideKeyboard(); + EXPECT_EQ(ret, ErrorCode::ERROR_IME); +} + /** * @tc.name: testHideKeyboardSelfWithoutImeListener * @tc.desc: InputMethodAbility HideKeyboardSelf Without ImeListener @@ -202,6 +219,23 @@ HWTEST_F(InputMethodAbilityTest, testHideKeyboardSelfWithoutImeListener, TestSiz EXPECT_TRUE(InputMethodAbilityTest::showKeyboard_); } +/** +* @tc.name: testShowKeyboard +* @tc.desc: InputMethodAbility ShowKeyboard +* @tc.type: FUNC +* @tc.require: +*/ +HWTEST_F(InputMethodAbilityTest, testShowKeyboard, TestSize.Level0) +{ + IMSA_HILOGI("InputMethodAbilityTest testShowKeyboard start."); + inputMethodAbility_->SetImeListener(std::make_shared()); + sptr channelStub = new InputDataChannelStub(); + auto ret = inputMethodAbility_->ShowKeyboard(channelStub->AsObject(), false, false); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); + ret = inputMethodAbility_->HideKeyboard(); + EXPECT_EQ(ret, ErrorCode::NO_ERROR); +} + /** * @tc.name: testHideKeyboardSelf * @tc.desc: InputMethodAbility HideKeyboardSelf @@ -212,6 +246,11 @@ HWTEST_F(InputMethodAbilityTest, testHideKeyboardSelfWithoutImeListener, TestSiz HWTEST_F(InputMethodAbilityTest, testHideKeyboardSelf, TestSize.Level0) { IMSA_HILOGI("InputMethodAbility testHideKeyboardSelf START"); + WindowMgr::CreateWindow(); + WindowMgr::ShowWindow(); + sptr textListener = new TextListener(); + imc_ = InputMethodController::GetInstance(); + imc_->Attach(textListener); std::unique_lock lock(InputMethodAbilityTest::imeListenerCallbackLock_); InputMethodAbilityTest::showKeyboard_ = true; inputMethodAbility_->SetImeListener(std::make_shared()); diff --git a/test/unittest/cpp_test/src/input_method_attach_test.cpp b/test/unittest/cpp_test/src/input_method_attach_test.cpp index 8c6e71452a4484b849e76b8aa1b1e8d84d917ea3..ee2493f7cbaa6ef4ef85a7745442d328fa6152f2 100644 --- a/test/unittest/cpp_test/src/input_method_attach_test.cpp +++ b/test/unittest/cpp_test/src/input_method_attach_test.cpp @@ -15,12 +15,12 @@ #include #include -#include #include "global.h" #include "input_attribute.h" #include "input_method_ability.h" #include "input_method_controller.h" +#include "input_method_engine_listener_impl.h" #include "tdd_util.h" #include "text_listener.h" @@ -28,42 +28,11 @@ using namespace testing::ext; namespace OHOS { namespace MiscServices { using WindowMgr = TddUtil::WindowManager; -constexpr int32_t WAIT_DATA_CHANNEL = 1000; class InputMethodAttachTest : public testing::Test { public: static sptr inputMethodController_; static sptr inputMethodAbility_; - class EngineListenerImpl : public InputMethodEngineListener { - public: - EngineListenerImpl() = default; - ~EngineListenerImpl() = default; - - void OnKeyboardStatus(bool isShow) - { - IMSA_HILOGI("EngineListenerImpl OnKeyboardStatus"); - } - - void OnInputStart() - { - IMSA_HILOGI("EngineListenerImpl OnInputStart"); - } - - void OnInputStop(const std::string &imeId) - { - IMSA_HILOGI("EngineListenerImpl OnInputStop"); - } - - void OnSetCallingWindow(uint32_t windowId) - { - IMSA_HILOGI("EngineListenerImpl OnSetCallingWindow"); - } - - void OnSetSubtype(const SubProperty &property) - { - IMSA_HILOGI("EngineListenerImpl OnSetSubtype"); - } - }; static void SetUpTestCase(void) { IMSA_HILOGI("InputMethodAttachTest::SetUpTestCase"); @@ -75,6 +44,7 @@ public: inputMethodAbility_ = InputMethodAbility::GetInstance(); inputMethodAbility_->OnImeReady(); inputMethodAbility_->SetCoreAndAgent(); + inputMethodAbility_->SetImeListener(std::make_shared()); TddUtil::RestoreSelfTokenID(); WindowMgr::CreateWindow(); @@ -111,7 +81,6 @@ HWTEST_F(InputMethodAttachTest, testAttach001, TestSize.Level0) sptr textListener = new TextListener(); auto ret = inputMethodController_->Attach(textListener); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - usleep(WAIT_DATA_CHANNEL); int32_t keyType = -1; ret = inputMethodAbility_->GetEnterKeyType(keyType); @@ -135,7 +104,6 @@ HWTEST_F(InputMethodAttachTest, testAttach002, TestSize.Level0) sptr textListener = new TextListener(); auto ret = inputMethodController_->Attach(textListener, false); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - usleep(WAIT_DATA_CHANNEL); int32_t keyType = -1; ret = inputMethodAbility_->GetEnterKeyType(keyType); @@ -162,7 +130,6 @@ HWTEST_F(InputMethodAttachTest, testAttach003, TestSize.Level0) attribute.enterKeyType = 1; auto ret = inputMethodController_->Attach(textListener, true, attribute); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - usleep(WAIT_DATA_CHANNEL); int32_t keyType = -1; ret = inputMethodAbility_->GetEnterKeyType(keyType); @@ -190,7 +157,6 @@ HWTEST_F(InputMethodAttachTest, testAttach004, TestSize.Level0) config.inputAttribute = attribute; auto ret = inputMethodController_->Attach(textListener, false, config); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - usleep(WAIT_DATA_CHANNEL); int32_t keyType = -1; ret = inputMethodAbility_->GetEnterKeyType(keyType); @@ -229,7 +195,6 @@ HWTEST_F(InputMethodAttachTest, testAttach005, TestSize.Level0) config.windowId = 10; auto ret = inputMethodController_->Attach(textListener, true, config); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - usleep(WAIT_DATA_CHANNEL); int32_t keyType = -1; ret = inputMethodAbility_->GetEnterKeyType(keyType); @@ -325,7 +290,6 @@ HWTEST_F(InputMethodAttachTest, testGetTextConfig, TestSize.Level0) config.windowId = 10; auto ret = inputMethodController_->Attach(textListener, false, config); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - usleep(WAIT_DATA_CHANNEL); TextTotalConfig totalConfig; ret = inputMethodAbility_->GetTextConfig(totalConfig); EXPECT_EQ(ret, ErrorCode::NO_ERROR); @@ -526,7 +490,6 @@ HWTEST_F(InputMethodAttachTest, testOnCursorUpdate001, TestSize.Level0) config.cursorInfo = cursorInfo2; ret = inputMethodController_->Attach(textListener, false, config); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - usleep(WAIT_DATA_CHANNEL); TextTotalConfig totalConfig; ret = inputMethodAbility_->GetTextConfig(totalConfig); @@ -559,7 +522,6 @@ HWTEST_F(InputMethodAttachTest, testOnSelectionChange, TestSize.Level0) config.range.end = 20; ret = inputMethodController_->Attach(textListener, false, config); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - usleep(WAIT_DATA_CHANNEL); TextTotalConfig totalConfig; ret = inputMethodAbility_->GetTextConfig(totalConfig); @@ -597,7 +559,6 @@ HWTEST_F(InputMethodAttachTest, testOnConfigurationChange002, TestSize.Level0) config.inputAttribute.inputPattern = 5; ret = inputMethodController_->Attach(textListener, false, config); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - usleep(WAIT_DATA_CHANNEL); TextTotalConfig totalConfig; ret = inputMethodAbility_->GetTextConfig(totalConfig); @@ -629,7 +590,6 @@ HWTEST_F(InputMethodAttachTest, testSetCallingWindow, TestSize.Level0) config.windowId = 77; ret = inputMethodController_->Attach(textListener, false, config); EXPECT_EQ(ret, ErrorCode::NO_ERROR); - usleep(WAIT_DATA_CHANNEL); TextTotalConfig totalConfig; ret = inputMethodAbility_->GetTextConfig(totalConfig); diff --git a/test/unittest/cpp_test/src/input_method_controller_test.cpp b/test/unittest/cpp_test/src/input_method_controller_test.cpp index cb0b44faa1a3cd84b6b217ee513183df5a05bb5d..b0856da34f6569c88776fc80cba628686116563e 100644 --- a/test/unittest/cpp_test/src/input_method_controller_test.cpp +++ b/test/unittest/cpp_test/src/input_method_controller_test.cpp @@ -42,7 +42,7 @@ #include "input_data_channel_stub.h" #include "input_death_recipient.h" #include "input_method_ability.h" -#include "input_method_engine_listener.h" +#include "input_method_engine_listener_impl.h" #include "input_method_system_ability_proxy.h" #include "input_method_utils.h" #include "iservice_registry.h" @@ -62,54 +62,6 @@ constexpr uint32_t RETRY_TIME = 200 * 1000; constexpr uint32_t RETRY_TIMES = 5; using WindowMgr = TddUtil::WindowManager; -class InputMethodEngineListenerImpl : public InputMethodEngineListener { -public: - InputMethodEngineListenerImpl(){}; - ~InputMethodEngineListenerImpl(){}; - static bool keyboardState_; - static bool isInputStart_; - static uint32_t windowId_; - static std::mutex imeListenerMutex_; - static std::condition_variable imeListenerCv_; - void OnKeyboardStatus(bool isShow) override; - void OnInputStart() override; - void OnInputStop(const std::string &imeId) override; - void OnSetCallingWindow(uint32_t windowId) override; - void OnSetSubtype(const SubProperty &property) override; -}; -bool InputMethodEngineListenerImpl::keyboardState_ = false; -bool InputMethodEngineListenerImpl::isInputStart_ = false; -uint32_t InputMethodEngineListenerImpl::windowId_ = 0; -std::mutex InputMethodEngineListenerImpl::imeListenerMutex_; -std::condition_variable InputMethodEngineListenerImpl::imeListenerCv_; - -void InputMethodEngineListenerImpl::OnKeyboardStatus(bool isShow) -{ - IMSA_HILOGI("InputMethodEngineListenerImpl::OnKeyboardStatus %{public}s", isShow ? "show" : "hide"); - std::lock_guard lock(imeListenerMutex_); - keyboardState_ = isShow; - imeListenerCv_.notify_one(); -} -void InputMethodEngineListenerImpl::OnInputStart() -{ - IMSA_HILOGI("InputMethodEngineListenerImpl::OnInputStart"); - isInputStart_ = true; -} -void InputMethodEngineListenerImpl::OnInputStop(const std::string &imeId) -{ - IMSA_HILOGI("InputMethodEngineListenerImpl::OnInputStop %{public}s", imeId.c_str()); - isInputStart_ = false; -} -void InputMethodEngineListenerImpl::OnSetCallingWindow(uint32_t windowId) -{ - IMSA_HILOGI("InputMethodEngineListenerImpl::OnSetCallingWindow %{public}d", windowId); - windowId_ = windowId; -} -void InputMethodEngineListenerImpl::OnSetSubtype(const SubProperty &property) -{ - IMSA_HILOGD("InputMethodEngineListenerImpl::OnSetSubtype"); -} - class SelectListenerMock : public ControllerListener { public: SelectListenerMock() = default; @@ -601,7 +553,7 @@ HWTEST_F(InputMethodControllerTest, testIMCOnCursorUpdate01, TestSize.Level0) InputMethodControllerTest::cursorInfo_ = {}; InputMethodControllerTest::TriggerCursorUpdateCallback(info); - EXPECT_TRUE(InputMethodControllerTest::cursorInfo_ == info); + EXPECT_FALSE(InputMethodControllerTest::cursorInfo_ == info); } /** diff --git a/test/unittest/cpp_test/src/input_method_dfx_test.cpp b/test/unittest/cpp_test/src/input_method_dfx_test.cpp index aadb49a7a0af3e7467a2d3b27726624b05acc498..526abf8056d69badf957b0d82f1acc0a69a04962 100644 --- a/test/unittest/cpp_test/src/input_method_dfx_test.cpp +++ b/test/unittest/cpp_test/src/input_method_dfx_test.cpp @@ -33,6 +33,7 @@ #include "hisysevent_record.h" #include "input_method_ability.h" #include "input_method_controller.h" +#include "input_method_engine_listener_impl.h" #include "tdd_util.h" #include "text_listener.h" @@ -48,32 +49,6 @@ constexpr const char *PARAM_KEY = "OPERATE_INFO"; constexpr const char *DOMAIN = "INPUTMETHOD"; constexpr const char *EVENT_NAME = "OPERATE_SOFTKEYBOARD"; -class InputMethodEngineListenerImpl : public InputMethodEngineListener { -public: - InputMethodEngineListenerImpl() = default; - ~InputMethodEngineListenerImpl() = default; - void OnKeyboardStatus(bool isShow) - { - IMSA_HILOGI("InputMethodEngineListenerImpl OnKeyboardStatus"); - } - void OnInputStart() - { - IMSA_HILOGI("InputMethodEngineListenerImpl OnInputStart"); - } - void OnInputStop(const std::string &imeId) - { - IMSA_HILOGI("InputMethodEngineListenerImpl OnInputStop"); - } - void OnSetCallingWindow(uint32_t windowId) - { - IMSA_HILOGI("InputMethodEngineListenerImpl OnSetCallingWindow"); - } - void OnSetSubtype(const SubProperty &property) - { - IMSA_HILOGI("InputMethodEngineListenerImpl OnSetSubtype"); - } -}; - class Watcher : public HiSysEventListener { public: explicit Watcher(const std::string &operateInfo) : operateInfo_(operateInfo) diff --git a/test/unittest/cpp_test/src/input_method_editor_test.cpp b/test/unittest/cpp_test/src/input_method_editor_test.cpp index dce25a9a01435c7352b47441a242aadb24404f3b..8579398b4491dc0932fe85a635827c1c2c9fa11a 100644 --- a/test/unittest/cpp_test/src/input_method_editor_test.cpp +++ b/test/unittest/cpp_test/src/input_method_editor_test.cpp @@ -32,7 +32,7 @@ #include "input_data_channel_stub.h" #include "input_method_ability.h" #include "input_method_controller.h" -#include "input_method_engine_listener.h" +#include "input_method_engine_listener_impl.h" #include "input_method_system_ability_proxy.h" #include "input_method_utils.h" #include "keyboard_listener.h" @@ -87,44 +87,6 @@ void KeyboardListenerImpl::OnEditorAttributeChange(const InputAttribute &inputAt { } -class InputMethodEngineListenerImpl : public InputMethodEngineListener { -public: - InputMethodEngineListenerImpl(){}; - ~InputMethodEngineListenerImpl(){}; - static bool keyboardState_; - static bool isInputStart_; - static uint32_t windowId_; - void OnKeyboardStatus(bool isShow) override; - void OnInputStart() override; - void OnInputStop(const std::string &imeId) override; - void OnSetCallingWindow(uint32_t windowId) override; - void OnSetSubtype(const SubProperty &property) override; -}; -bool InputMethodEngineListenerImpl::keyboardState_ = false; -bool InputMethodEngineListenerImpl::isInputStart_ = false; -uint32_t InputMethodEngineListenerImpl::windowId_ = 0; - -void InputMethodEngineListenerImpl::OnKeyboardStatus(bool isShow) -{ - keyboardState_ = isShow; -} -void InputMethodEngineListenerImpl::OnInputStart() -{ - isInputStart_ = true; -} -void InputMethodEngineListenerImpl::OnInputStop(const std::string &imeId) -{ - isInputStart_ = false; -} -void InputMethodEngineListenerImpl::OnSetCallingWindow(uint32_t windowId) -{ - windowId_ = windowId; -} -void InputMethodEngineListenerImpl::OnSetSubtype(const SubProperty &property) -{ - IMSA_HILOGD("InputMethodEngineListenerImpl::OnSetSubtype"); -} - class InputMethodEditorTest : public testing::Test { public: static void SetUpTestCase(void); diff --git a/test/unittest/cpp_test/src/permission_verification_exception_test.cpp b/test/unittest/cpp_test/src/permission_verification_exception_test.cpp index 6818382f762eb46b69467ee5ece6fafe541e72f5..1af1e7d3dd27ec17ec97fa2f007607843e3cdd1d 100644 --- a/test/unittest/cpp_test/src/permission_verification_exception_test.cpp +++ b/test/unittest/cpp_test/src/permission_verification_exception_test.cpp @@ -28,6 +28,7 @@ #include "global.h" #include "input_method_ability.h" #include "input_method_controller.h" +#include "input_method_engine_listener_impl.h" #include "tdd_util.h" #include "text_listener.h" @@ -57,6 +58,7 @@ void PermissionVerificationExceptionTest::SetUpTestCase(void) TddUtil::StorageSelfTokenID(); ima_ = InputMethodAbility::GetInstance(); ima_->OnImeReady(); + ima_->SetImeListener(std::make_shared()); PermissionVerificationExceptionTest::textListener_ = new TextListener(); imc_ = InputMethodController::GetInstance(); auto property = InputMethodController::GetInstance()->GetCurrentInputMethod(); diff --git a/test/unittest/napi_test/src/InputMethodTest.js b/test/unittest/napi_test/src/InputMethodTest.js index 111776d5da107c3257138a0ea947c93affd4d806..c7253829162b9bdb7246c0787e3f3a282ef6865b 100644 --- a/test/unittest/napi_test/src/InputMethodTest.js +++ b/test/unittest/napi_test/src/InputMethodTest.js @@ -20,6 +20,7 @@ describe('InputMethodTest', function () { beforeAll(function () { console.info('beforeAll called'); inputMethod.getSetting().on('imeChange', imeChange); + propertyBeforeSwitch = inputMethod.getCurrentInputMethod(); }); afterAll(function () { @@ -34,6 +35,7 @@ describe('InputMethodTest', function () { afterEach(function () { console.info('afterEach called'); }); + let propertyBeforeSwitch = undefined; let bundleName = 'com.example.newTestIme'; let extName = 'InputMethodExtAbility'; let subName = ['lowerInput', 'upperInput', 'chineseInput']; @@ -253,7 +255,7 @@ describe('InputMethodTest', function () { expect(true).assertTrue(); done(); }).catch((err) => { - console.info(`inputmethod_test_listCurrentInputMethodSubtype_001 err: ${JSON.stringify(err.message)}`); + console.info(`inputmethod_test_listCurrentInputMethodSubtype_002 err: ${JSON.stringify(err.message)}`); expect().assertFail(); done(); }); @@ -690,6 +692,27 @@ describe('InputMethodTest', function () { }) }); + /* + * @tc.number inputmethod_test_switchInputMethod_002 + * @tc.name Switch to ime before testcases run. + * @tc.desc Function test + * @tc.level 2 + */ + it('inputmethod_test_switchInputMethod_002', 0, async function (done) { + console.info('************* inputmethod_test_switchInputMethod_002 Test start*************'); + inputMethod.switchInputMethod(propertyBeforeSwitch).then(ret => { + expect(ret).assertTrue(); + let property = inputMethod.getCurrentInputMethod(); + expect(property.name).assertEqual(propertyBeforeSwitch.name); + expect(property.id).assertEqual(propertyBeforeSwitch.id); + console.info('************* inputmethod_test_switchInputMethod_001 Test end*************'); + done(); + }).catch( err=> { + console.info(`inputmethod_test_switchInputMethod_001 err: ${JSON.stringify(err.message)}`); + expect().assertFail(); + }) + }); + /* * @tc.number inputmethod_test_attach_001 * @tc.name Test whether the current application can be bound with the default input method. @@ -955,11 +978,11 @@ describe('InputMethodTest', function () { let attribute = {textInputType: inputMethod.TextInputType.TEXT, enterKeyType: inputMethod.EnterKeyType.NONE}; try { inputMethodCtrl.updateAttribute(attribute, (err) => { - if (err) { - expect(err.code === 12800009).assertTrue(); - done(); + if (err.code === 12800009) { + expect(true).assertTrue(); + } else { + expect().assertFail(); } - expect().assertFail(); done(); }); } catch (error) {