mirror of
https://gitee.com/openharmony/inputmethod_imf
synced 2024-11-23 14:49:59 +00:00
!398 输入法框架代码覆盖率——增加部分TDD用例
Merge pull request !398 from Hollokin/master
This commit is contained in:
commit
2dc1fda0b7
@ -43,7 +43,6 @@ public:
|
||||
InputMethodAbility();
|
||||
~InputMethodAbility();
|
||||
static sptr<InputMethodAbility> GetInstance();
|
||||
sptr<IInputMethodCore> OnConnect();
|
||||
int32_t InsertText(const std::string text);
|
||||
void setImeListener(std::shared_ptr<InputMethodEngineListener> imeListener);
|
||||
void setKdListener(std::shared_ptr<KeyboardListener> kdListener);
|
||||
|
@ -13,8 +13,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef INPUTMETHOD_IMF_INPUT_METHOD_ENGINE_LISTENER_H
|
||||
#define INPUTMETHOD_IMF_INPUT_METHOD_ENGINE_LISTENER_H
|
||||
#ifndef INPUTMETHOD_IMF_INPUT_METHOD_SETTING_LISTENER_H
|
||||
#define INPUTMETHOD_IMF_INPUT_METHOD_SETTING_LISTENER_H
|
||||
|
||||
#include "input_method_property.h"
|
||||
|
||||
@ -28,4 +28,4 @@ public:
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // INPUTMETHOD_IMF_INPUT_METHOD_ENGINE_LISTENER_H
|
||||
#endif // INPUTMETHOD_IMF_INPUT_METHOD_SETTING_LISTENER_H
|
||||
|
@ -516,7 +516,7 @@ using namespace MessageID;
|
||||
|
||||
int32_t InputMethodController::GetTextAfterCursor(int32_t number, std::u16string &text)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodController::GetTextBeforeCursor");
|
||||
IMSA_HILOGI("InputMethodController::GetTextAfterCursor");
|
||||
if (!mTextString.empty() && mTextString.size() <= INT_MAX) {
|
||||
int32_t endPos = (mSelectNewEnd + number < static_cast<int32_t>(mTextString.size()))
|
||||
? (mSelectNewEnd + number)
|
||||
|
@ -20,9 +20,7 @@ namespace MiscServices {
|
||||
const std::map<int32_t, int32_t> JsUtils::ERROR_CODE_MAP = {
|
||||
{ ErrorCode::ERROR_STATUS_PERMISSION_DENIED, EXCEPTION_PERMISSION },
|
||||
{ ErrorCode::ERROR_REMOTE_IME_DIED, EXCEPTION_IMENGINE },
|
||||
{ ErrorCode::ERROR_RESTART_IME_FAILED, EXCEPTION_IMENGINE },
|
||||
{ ErrorCode::ERROR_REMOTE_CLIENT_DIED, EXCEPTION_IMCLIENT },
|
||||
{ ErrorCode::ERROR_CLIENT_DUPLICATED, EXCEPTION_IMCLIENT },
|
||||
{ ErrorCode::ERROR_CLIENT_NOT_FOUND, EXCEPTION_IMCLIENT },
|
||||
{ ErrorCode::ERROR_CLIENT_NULL_POINTER, EXCEPTION_IMCLIENT },
|
||||
{ ErrorCode::ERROR_NOT_IME_PACKAGE, EXCEPTION_SETTINGS },
|
||||
@ -42,19 +40,11 @@ const std::map<int32_t, int32_t> JsUtils::ERROR_CODE_MAP = {
|
||||
{ ErrorCode::ERROR_IME_BIND_FAILED, EXCEPTION_IMMS },
|
||||
{ ErrorCode::ERROR_IME_UNBIND_FAILED, EXCEPTION_IMMS },
|
||||
{ ErrorCode::ERROR_IME_START_FAILED, EXCEPTION_IMMS },
|
||||
{ ErrorCode::ERROR_IME_STOP_FAILED, EXCEPTION_IMMS },
|
||||
{ ErrorCode::ERROR_KBD_SHOW_FAILED, EXCEPTION_IMMS },
|
||||
{ ErrorCode::ERROR_KBD_HIDE_FAILED, EXCEPTION_IMMS },
|
||||
{ ErrorCode::ERROR_IME_NOT_STARTED, EXCEPTION_IMMS },
|
||||
{ ErrorCode::ERROR_KBD_IS_OCCUPIED, EXCEPTION_IMMS },
|
||||
{ ErrorCode::ERROR_KBD_IS_NOT_SHOWING, EXCEPTION_IMMS },
|
||||
{ ErrorCode::ERROR_IME_ALREADY_STARTED, EXCEPTION_IMMS },
|
||||
{ ErrorCode::ERROR_NO_NEXT_IME, EXCEPTION_IMMS },
|
||||
{ ErrorCode::ERROR_CLIENTWINDOW_NOT_FOCUSED, EXCEPTION_IMMS },
|
||||
{ ErrorCode::ERROR_CLIENT_NOT_WINDOW, EXCEPTION_IMMS },
|
||||
{ ErrorCode::ERROR_IME_PROPERTY_MARSHALL, EXCEPTION_IMMS },
|
||||
{ ErrorCode::ERROR_GETTING_CURRENT_IME, EXCEPTION_IMMS },
|
||||
{ ErrorCode::ERROR_LIST_IME, EXCEPTION_IMMS },
|
||||
{ ErrorCode::ERROR_EX_NULL_POINTER, EXCEPTION_IMMS },
|
||||
{ ErrorCode::ERROR_PERSIST_CONFIG, EXCEPTION_CONFPERSIST },
|
||||
{ ErrorCode::ERROR_PACKAGE_MANAGER, EXCEPTION_PACKAGEMANAGER },
|
||||
@ -163,5 +153,5 @@ const std::string JsUtils::ToMessage(int32_t code)
|
||||
}
|
||||
return "error is out of definition.";
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
@ -101,64 +101,53 @@ enum {
|
||||
ERROR_STATUS_UNEXPECTED_NULL = ERROR_STATUS_UNKNOWN_ERROR + 8, // unexpected null,
|
||||
|
||||
// binder exception error code from Status.h
|
||||
ERROR_EX_ILLEGAL_ARGUMENT = -3, // illegal argument exception
|
||||
ERROR_EX_NULL_POINTER = -4, // null pointer exception
|
||||
ERROR_EX_ILLEGAL_STATE = -5, // illegal state exception
|
||||
ERROR_EX_NETWORK_MAIN_THREAD = -6, // network main thread exception
|
||||
ERROR_EX_UNSUPPORTED_OPERATION = -7, // unsupported operation exception
|
||||
ERROR_EX_SERVICE_SPECIFIC = -8, // service specific exception
|
||||
ERROR_EX_PARCELABLE = -9, // parcelable exception
|
||||
ERROR_EX_ILLEGAL_ARGUMENT = -3, // illegal argument exception
|
||||
ERROR_EX_NULL_POINTER = -4, // null pointer exception
|
||||
ERROR_EX_ILLEGAL_STATE = -5, // illegal state exception
|
||||
ERROR_EX_NETWORK_MAIN_THREAD = -6, // network main thread exception
|
||||
ERROR_EX_UNSUPPORTED_OPERATION = -7, // unsupported operation exception
|
||||
ERROR_EX_SERVICE_SPECIFIC = -8, // service specific exception
|
||||
ERROR_EX_PARCELABLE = -9, // parcelable exception
|
||||
// no error
|
||||
NO_ERROR = 0, // no error
|
||||
NO_ERROR = 0, // no error
|
||||
|
||||
// system service error
|
||||
ERROR_NULL_POINTER, // null pointer
|
||||
ERROR_BAD_PARAMETERS, // bad parameters
|
||||
ERROR_SERVICE_START_FAILED, // failed to start service
|
||||
ERROR_USER_NOT_STARTED, // user is not started
|
||||
ERROR_USER_ALREADY_STARTED, // user has already started
|
||||
ERROR_USER_NOT_UNLOCKED, // user is not unlocked
|
||||
ERROR_USER_ALREADY_UNLOCKED, // user has already unlocked
|
||||
ERROR_USER_NOT_LOCKED, // user is not locked
|
||||
ERROR_NULL_POINTER = 1, // null pointer
|
||||
ERROR_BAD_PARAMETERS = 2, // bad parameters
|
||||
ERROR_USER_NOT_STARTED = 3, // user is not started
|
||||
ERROR_USER_ALREADY_STARTED = 4, // user has already started
|
||||
ERROR_USER_NOT_UNLOCKED = 5, // user is not unlocked
|
||||
ERROR_USER_ALREADY_UNLOCKED = 6, // user has already unlocked
|
||||
ERROR_USER_NOT_LOCKED = 7, // user is not locked
|
||||
|
||||
ERROR_IME_NOT_AVAILABLE, // input method engine is not available
|
||||
ERROR_SECURITY_IME_NOT_AVAILABLE, // security input method engine is not available
|
||||
ERROR_TOKEN_CREATE_FAILED, // failed to create window token
|
||||
ERROR_TOKEN_DESTROY_FAILED, // failed to destroy window token
|
||||
ERROR_IME_BIND_FAILED, // failed to bind IME service
|
||||
ERROR_IME_UNBIND_FAILED, // failed to unbind IME service
|
||||
ERROR_IME_START_FAILED, // failed to start IME service
|
||||
ERROR_IME_STOP_FAILED, // failed to stop IME service
|
||||
ERROR_KBD_SHOW_FAILED, // failed to show keyboard
|
||||
ERROR_KBD_HIDE_FAILED, // failed to hide keyboard
|
||||
ERROR_IME_NOT_STARTED, // input method service is not started
|
||||
ERROR_KBD_IS_OCCUPIED, // keyboard is showing by other client
|
||||
ERROR_KBD_IS_NOT_SHOWING, // keyboard is not showing
|
||||
ERROR_IME_ALREADY_STARTED, // input method service has already started
|
||||
ERROR_NOT_IME_PACKAGE, // not an IME package
|
||||
ERROR_IME_PACKAGE_DUPLICATED, // duplicated IME package
|
||||
ERROR_SETTING_SAME_VALUE, // same setting value
|
||||
ERROR_NO_NEXT_IME, // no next ime is available
|
||||
ERROR_CLIENTWINDOW_NOT_FOCUSED, // the input client window is not focused
|
||||
ERROR_CLIENT_NOT_WINDOW, // the input client is not from a valid window
|
||||
ERROR_ADD_CLIENT_FAILED,
|
||||
ERROR_IME_PROPERTY_MARSHALL, // failed to marshall the ime property
|
||||
ERROR_GETTING_CURRENT_IME,
|
||||
ERROR_LIST_IME,
|
||||
ERROR_SWITCH_IME,
|
||||
ERROR_IME_NOT_AVAILABLE = 8, // input method engine is not available
|
||||
ERROR_SECURITY_IME_NOT_AVAILABLE = 9, // security input method engine is not available
|
||||
ERROR_TOKEN_CREATE_FAILED = 10, // failed to create window token
|
||||
ERROR_TOKEN_DESTROY_FAILED = 11, // failed to destroy window token
|
||||
ERROR_IME_BIND_FAILED = 12, // failed to bind IME service
|
||||
ERROR_IME_UNBIND_FAILED = 13, // failed to unbind IME service
|
||||
ERROR_IME_START_FAILED = 14, // failed to start IME service
|
||||
ERROR_KBD_SHOW_FAILED = 15, // failed to show keyboard
|
||||
ERROR_KBD_HIDE_FAILED = 16, // failed to hide keyboard
|
||||
ERROR_IME_NOT_STARTED = 17, // input method service is not started
|
||||
ERROR_KBD_IS_OCCUPIED = 18, // keyboard is showing by other client
|
||||
ERROR_KBD_IS_NOT_SHOWING = 19, // keyboard is not showing
|
||||
ERROR_NOT_IME_PACKAGE = 20, // not an IME package
|
||||
ERROR_IME_PACKAGE_DUPLICATED = 21, // duplicated IME package
|
||||
ERROR_SETTING_SAME_VALUE = 22, // same setting value
|
||||
ERROR_ADD_CLIENT_FAILED = 23, // add client failed
|
||||
ERROR_SWITCH_IME = 24,
|
||||
// error from ime
|
||||
ERROR_REMOTE_IME_DIED, // remote input method service died abnormally
|
||||
ERROR_RESTART_IME_FAILED, // failed to restart input method service
|
||||
ERROR_IME_NULL_POINTER, // null pointer
|
||||
ERROR_REMOTE_IME_DIED = 25, // remote input method service died abnormally
|
||||
// error from client
|
||||
ERROR_REMOTE_CLIENT_DIED, // remote client died abnormally
|
||||
ERROR_CLIENT_DUPLICATED, // duplicated client
|
||||
ERROR_CLIENT_NOT_FOUND, // client is not found
|
||||
ERROR_CLIENT_NULL_POINTER, // null pointer
|
||||
ERROR_SUBSCRIBE_KEYBOARD_EVENT,
|
||||
ERROR_CONTROLLER_INVOKING_FAILED,
|
||||
ERROR_PERSIST_CONFIG,
|
||||
ERROR_PACKAGE_MANAGER,
|
||||
ERROR_REMOTE_CLIENT_DIED = 26, // remote client died abnormally
|
||||
ERROR_CLIENT_NOT_FOUND = 27, // client is not found
|
||||
ERROR_CLIENT_NULL_POINTER = 28, // null pointer
|
||||
ERROR_SUBSCRIBE_KEYBOARD_EVENT = 29,
|
||||
ERROR_CONTROLLER_INVOKING_FAILED = 30,
|
||||
ERROR_PERSIST_CONFIG = 31,
|
||||
ERROR_PACKAGE_MANAGER = 32,
|
||||
ERROR_SERVICE_START_FAILED = 33,
|
||||
};
|
||||
const char *ToString(int errorCode);
|
||||
}; // namespace ErrorCode
|
||||
|
@ -82,8 +82,8 @@ const char *ToString(int errorCode)
|
||||
case ERROR_IME_START_FAILED: {
|
||||
return "failed to start input";
|
||||
}
|
||||
case ERROR_IME_STOP_FAILED: {
|
||||
return "failed to stop input";
|
||||
case ERROR_ADD_CLIENT_FAILED: {
|
||||
return "failed fo add client";
|
||||
}
|
||||
case ERROR_KBD_SHOW_FAILED: {
|
||||
return "failed to show keyboard";
|
||||
@ -100,9 +100,6 @@ const char *ToString(int errorCode)
|
||||
case ERROR_KBD_IS_NOT_SHOWING: {
|
||||
return "keyboard is not showing";
|
||||
}
|
||||
case ERROR_IME_ALREADY_STARTED: {
|
||||
return "input method service has already started";
|
||||
}
|
||||
case ERROR_NOT_IME_PACKAGE: {
|
||||
return "not an input method engine package";
|
||||
}
|
||||
@ -112,27 +109,12 @@ const char *ToString(int errorCode)
|
||||
case ERROR_SETTING_SAME_VALUE: {
|
||||
return "same setting value";
|
||||
}
|
||||
case ERROR_NO_NEXT_IME: {
|
||||
return "next input method engine is not available";
|
||||
}
|
||||
case ERROR_CLIENTWINDOW_NOT_FOCUSED: {
|
||||
return "input client window is not focused";
|
||||
}
|
||||
case ERROR_CLIENT_NOT_WINDOW: {
|
||||
return "input client is not from a valid window";
|
||||
}
|
||||
case ERROR_REMOTE_IME_DIED: {
|
||||
return "input method service died";
|
||||
}
|
||||
case ERROR_RESTART_IME_FAILED: {
|
||||
return "failed to restart input method service";
|
||||
}
|
||||
case ERROR_REMOTE_CLIENT_DIED: {
|
||||
return "input client died";
|
||||
}
|
||||
case ERROR_CLIENT_DUPLICATED: {
|
||||
return "duplicated client";
|
||||
}
|
||||
case ERROR_CLIENT_NOT_FOUND: {
|
||||
return "client is not found";
|
||||
}
|
||||
|
@ -76,6 +76,9 @@ ohos_unittest("InputMethodAbilityTest") {
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libnativetoken",
|
||||
"access_token:libtoken_setproc",
|
||||
"c_utils:utils",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
]
|
||||
|
@ -13,15 +13,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <sys/time.h>
|
||||
#include "input_method_ability.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <gtest/gtest.h>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
#include "accesstoken_kit.h"
|
||||
#include "global.h"
|
||||
#include "i_input_data_channel.h"
|
||||
#include "input_attribute.h"
|
||||
@ -29,164 +31,405 @@
|
||||
#include "input_data_channel_proxy.h"
|
||||
#include "input_data_channel_stub.h"
|
||||
#include "input_method_agent_stub.h"
|
||||
#include "input_method_controller.h"
|
||||
#include "input_method_core_proxy.h"
|
||||
#include "input_method_core_stub.h"
|
||||
#include "message_handler.h"
|
||||
#include "nativetoken_kit.h"
|
||||
#include "token_setproc.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::Security::AccessToken;
|
||||
namespace OHOS {
|
||||
namespace MiscServices {
|
||||
class InputMethodAbilityTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase(void);
|
||||
static void TearDownTestCase(void);
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
class InputMethodAbilityTest : public testing::Test {
|
||||
public:
|
||||
static std::string imeIdStopped_;
|
||||
static bool showKeyboard_;
|
||||
static int direction_;
|
||||
static int deleteForwardLength_;
|
||||
static int deleteBackwardLength_;
|
||||
static std::u16string insertText_;
|
||||
static int key_;
|
||||
static int keyboardStatus_;
|
||||
static bool status_;
|
||||
static sptr<InputMethodController> imc_;
|
||||
static sptr<InputMethodAbility> inputMethodAbility_;
|
||||
|
||||
class KeyboardListenerTestImpl : public KeyboardListener {
|
||||
bool OnKeyEvent(int32_t keyCode, int32_t keyStatus)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
void OnCursorUpdate(int32_t positionX, int32_t positionY, int32_t height)
|
||||
{
|
||||
}
|
||||
void OnSelectionChange(int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd)
|
||||
{
|
||||
}
|
||||
void OnTextChange(std::string text)
|
||||
{
|
||||
}
|
||||
};
|
||||
class InputMethodEngineListenerImpl : public InputMethodEngineListener {
|
||||
public:
|
||||
InputMethodEngineListenerImpl() = default;
|
||||
~InputMethodEngineListenerImpl() = default;
|
||||
|
||||
void InputMethodAbilityTest::SetUpTestCase(void)
|
||||
void OnKeyboardStatus(bool isShow)
|
||||
{
|
||||
showKeyboard_ = isShow;
|
||||
IMSA_HILOGI("InputMethodEngineListenerImpl OnKeyboardStatus");
|
||||
}
|
||||
|
||||
void OnInputStart()
|
||||
{
|
||||
IMSA_HILOGI("InputMethodEngineListenerImpl OnInputStart");
|
||||
}
|
||||
|
||||
void OnInputStop(std::string imeId)
|
||||
{
|
||||
imeIdStopped_ = imeId;
|
||||
IMSA_HILOGI("InputMethodEngineListenerImpl OnInputStop");
|
||||
}
|
||||
|
||||
void OnSetCallingWindow(uint32_t windowId)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodEngineListenerImpl OnSetCallingWindow");
|
||||
}
|
||||
|
||||
void OnSetSubtype(const SubProperty &property)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodEngineListenerImpl OnSetSubtype");
|
||||
}
|
||||
};
|
||||
class TextChangeListener : public OnTextChangedListener {
|
||||
public:
|
||||
void InsertText(const std::u16string &text) override
|
||||
{
|
||||
insertText_ = text;
|
||||
}
|
||||
|
||||
void DeleteForward(int32_t length) override
|
||||
{
|
||||
deleteForwardLength_ = length;
|
||||
IMSA_HILOGI("TextChangeListener: DeleteForward, length is: %{public}d", length);
|
||||
}
|
||||
|
||||
void DeleteBackward(int32_t length) override
|
||||
{
|
||||
deleteBackwardLength_ = length;
|
||||
IMSA_HILOGI("TextChangeListener: DeleteBackward, direction is: %{public}d", length);
|
||||
}
|
||||
|
||||
void SendKeyEventFromInputMethod(const KeyEvent &event) override
|
||||
{
|
||||
}
|
||||
|
||||
void SendKeyboardInfo(const KeyboardInfo &info) override
|
||||
{
|
||||
FunctionKey functionKey = info.GetFunctionKey();
|
||||
KeyboardStatus keyboardStatus = info.GetKeyboardStatus();
|
||||
key_ = (int)functionKey;
|
||||
keyboardStatus_ = (int)keyboardStatus;
|
||||
}
|
||||
|
||||
void SetKeyboardStatus(bool status) override
|
||||
{
|
||||
status_ = status;
|
||||
}
|
||||
|
||||
void MoveCursor(const Direction direction) override
|
||||
{
|
||||
direction_ = (int)direction;
|
||||
IMSA_HILOGI("TextChangeListener: MoveCursor, direction is: %{public}d", direction);
|
||||
}
|
||||
};
|
||||
void GrantPermission()
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbilityTest::SetUpTestCase");
|
||||
const char **perms = new const char *[1];
|
||||
perms[0] = "ohos.permission.CONNECT_IME_ABILITY";
|
||||
TokenInfoParams infoInstance = {
|
||||
.dcapsNum = 0,
|
||||
.permsNum = 1,
|
||||
.aclsNum = 0,
|
||||
.dcaps = nullptr,
|
||||
.perms = perms,
|
||||
.acls = nullptr,
|
||||
.processName = "inputmethod_imf",
|
||||
.aplStr = "system_core",
|
||||
};
|
||||
uint64_t tokenId = GetAccessTokenId(&infoInstance);
|
||||
int res = SetSelfTokenID(tokenId);
|
||||
if (res == 0) {
|
||||
IMSA_HILOGI("SetSelfTokenID success!");
|
||||
} else {
|
||||
IMSA_HILOGE("SetSelfTokenID fail!");
|
||||
}
|
||||
AccessTokenKit::ReloadNativeTokenInfo();
|
||||
delete[] perms;
|
||||
}
|
||||
|
||||
void InputMethodAbilityTest::TearDownTestCase(void)
|
||||
static void SetUpTestCase(void)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbilityTest::TearDownTestCase");
|
||||
imc_ = InputMethodController::GetInstance();
|
||||
ASSERT_TRUE(imc_ != nullptr);
|
||||
}
|
||||
|
||||
void InputMethodAbilityTest::SetUp(void)
|
||||
static void TearDownTestCase(void)
|
||||
{
|
||||
}
|
||||
void SetUp()
|
||||
{
|
||||
inputMethodAbility_ = InputMethodAbility::GetInstance();
|
||||
GrantPermission();
|
||||
IMSA_HILOGI("InputMethodAbilityTest::SetUp");
|
||||
sptr<OnTextChangedListener> textListener = new TextChangeListener();
|
||||
imc_->Attach(textListener);
|
||||
}
|
||||
|
||||
void InputMethodAbilityTest::TearDown(void)
|
||||
void TearDown()
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbilityTest::TearDown");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @tc.name: testReadWriteIInputMethodAgent
|
||||
* @tc.desc: Checkout IInputMethodAgent.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5JBR6
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testReadWriteIInputMethodAgent, TestSize.Level0)
|
||||
{
|
||||
sptr<InputMethodAgentStub> mInputMethodAgentStub = new InputMethodAgentStub();
|
||||
MessageParcel data;
|
||||
auto ret = data.WriteRemoteObject(mInputMethodAgentStub->AsObject());
|
||||
EXPECT_TRUE(ret);
|
||||
auto remoteObject = data.ReadRemoteObject();
|
||||
sptr<IInputMethodAgent> iface = iface_cast<IInputMethodAgent>(remoteObject);
|
||||
EXPECT_TRUE(iface != nullptr);
|
||||
}
|
||||
std::string InputMethodAbilityTest::imeIdStopped_;
|
||||
bool InputMethodAbilityTest::showKeyboard_;
|
||||
int InputMethodAbilityTest::direction_;
|
||||
int InputMethodAbilityTest::deleteForwardLength_;
|
||||
int InputMethodAbilityTest::deleteBackwardLength_;
|
||||
std::u16string InputMethodAbilityTest::insertText_;
|
||||
int InputMethodAbilityTest::key_;
|
||||
int InputMethodAbilityTest::keyboardStatus_;
|
||||
bool InputMethodAbilityTest::status_;
|
||||
sptr<InputMethodController> InputMethodAbilityTest::imc_;
|
||||
sptr<InputMethodAbility> InputMethodAbilityTest::inputMethodAbility_;
|
||||
|
||||
/**
|
||||
* @tc.name: testReadWriteIInputMethodCore
|
||||
* @tc.desc: Checkout IInputMethodCore.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testReadWriteIInputMethodCore, TestSize.Level0)
|
||||
{
|
||||
sptr<InputMethodCoreStub> mInputMethodCoreStub = new InputMethodCoreStub(0);
|
||||
MessageParcel data;
|
||||
auto ret = data.WriteRemoteObject(mInputMethodCoreStub->AsObject());
|
||||
EXPECT_TRUE(ret);
|
||||
auto remoteObject = data.ReadRemoteObject();
|
||||
sptr<IInputMethodCore> iface = iface_cast<IInputMethodCore>(remoteObject);
|
||||
EXPECT_TRUE(iface != nullptr);
|
||||
}
|
||||
/**
|
||||
* @tc.name: testShowKeyboardInputMethodCoreProxy
|
||||
* @tc.desc: Test InputMethodCoreProxy ShowKeyboard
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5NXHK
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testShowKeyboardInputMethodCoreProxy, TestSize.Level0)
|
||||
{
|
||||
sptr<InputMethodCoreStub> coreStub = new InputMethodCoreStub(0);
|
||||
sptr<IInputMethodCore> core = coreStub;
|
||||
auto msgHandler = new (std::nothrow) MessageHandler();
|
||||
coreStub->SetMessageHandler(msgHandler);
|
||||
sptr<InputDataChannelStub> channelStub = new InputDataChannelStub();
|
||||
|
||||
/**
|
||||
* @tc.name: testShowKeyboardInputMethodCoreProxy
|
||||
* @tc.desc: Test InputMethodCoreProxy ShowKeyboard
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5NXHK
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testShowKeyboardInputMethodCoreProxy, TestSize.Level0)
|
||||
{
|
||||
sptr<InputMethodCoreStub> coreStub = new InputMethodCoreStub(0);
|
||||
sptr<IInputMethodCore> core = coreStub;
|
||||
auto msgHandler = new (std::nothrow) MessageHandler();
|
||||
coreStub->SetMessageHandler(msgHandler);
|
||||
sptr<InputDataChannelStub> channelStub = new InputDataChannelStub();
|
||||
MessageParcel data;
|
||||
data.WriteRemoteObject(core->AsObject());
|
||||
data.WriteRemoteObject(channelStub->AsObject());
|
||||
sptr<IRemoteObject> coreObject = data.ReadRemoteObject();
|
||||
sptr<IRemoteObject> channelObject = data.ReadRemoteObject();
|
||||
|
||||
MessageParcel data;
|
||||
data.WriteRemoteObject(core->AsObject());
|
||||
data.WriteRemoteObject(channelStub->AsObject());
|
||||
sptr<IRemoteObject> coreObject = data.ReadRemoteObject();
|
||||
sptr<IRemoteObject> channelObject = data.ReadRemoteObject();
|
||||
sptr<InputMethodCoreProxy> coreProxy = new InputMethodCoreProxy(coreObject);
|
||||
sptr<InputDataChannelProxy> channelProxy = new InputDataChannelProxy(channelObject);
|
||||
SubProperty subProperty;
|
||||
auto ret = coreProxy->showKeyboard(channelProxy, true, subProperty);
|
||||
delete msgHandler;
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
}
|
||||
|
||||
sptr<InputMethodCoreProxy> coreProxy = new InputMethodCoreProxy(coreObject);
|
||||
sptr<InputDataChannelProxy> channelProxy = new InputDataChannelProxy(channelObject);
|
||||
SubProperty subProperty;
|
||||
auto ret = coreProxy->showKeyboard(channelProxy, true, subProperty);
|
||||
delete msgHandler;
|
||||
EXPECT_EQ(ret, 0);
|
||||
}
|
||||
/**
|
||||
* @tc.name: testShowKeyboardInputMethodCoreStub
|
||||
* @tc.desc: Test InputMethodCoreStub ShowKeyboard
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5NXHK
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testShowKeyboardInputMethodCoreStub, TestSize.Level0)
|
||||
{
|
||||
sptr<InputMethodCoreStub> coreStub = new InputMethodCoreStub(0);
|
||||
SubProperty subProperty;
|
||||
auto ret = coreStub->showKeyboard(nullptr, true, subProperty);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testShowKeyboardInputMethodCoreStub
|
||||
* @tc.desc: Test InputMethodCoreStub ShowKeyboard
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5NXHK
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testShowKeyboardInputMethodCoreStub, TestSize.Level0)
|
||||
{
|
||||
sptr<InputMethodCoreStub> coreStub = new InputMethodCoreStub(0);
|
||||
SubProperty subProperty;
|
||||
auto ret = coreStub->showKeyboard(nullptr, true, subProperty);
|
||||
EXPECT_EQ(ret, 0);
|
||||
}
|
||||
/**
|
||||
* @tc.name: testSerializedInputAttribute
|
||||
* @tc.desc: Checkout the serialization of InputAttribute.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testSerializedInputAttribute, TestSize.Level0)
|
||||
{
|
||||
InputAttribute inAttribute;
|
||||
inAttribute.inputPattern = InputAttribute::PATTERN_PASSWORD;
|
||||
MessageParcel data;
|
||||
EXPECT_TRUE(InputAttribute::Marshalling(inAttribute, data));
|
||||
InputAttribute outAttribute;
|
||||
EXPECT_TRUE(InputAttribute::Unmarshalling(outAttribute, data));
|
||||
EXPECT_TRUE(outAttribute.GetSecurityFlag());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testReadWriteIInputControlChannel
|
||||
* @tc.desc: Checkout IInputControlChannel.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testReadWriteIInputControlChannel, TestSize.Level0)
|
||||
{
|
||||
sptr<InputControlChannelStub> mInputControlChannelStub = new InputControlChannelStub(0);
|
||||
MessageParcel data;
|
||||
auto ret = data.WriteRemoteObject(mInputControlChannelStub->AsObject());
|
||||
EXPECT_TRUE(ret);
|
||||
auto remoteObject = data.ReadRemoteObject();
|
||||
sptr<IInputControlChannel> iface = iface_cast<IInputControlChannel>(remoteObject);
|
||||
EXPECT_TRUE(iface != nullptr);
|
||||
}
|
||||
/**
|
||||
* @tc.name: testSerializedKeyboardType
|
||||
* @tc.desc: Checkout the serialization of KeyboardType.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testSerializedKeyboardType, TestSize.Level0)
|
||||
{
|
||||
int32_t def_value = 2021;
|
||||
sptr<KeyboardType> mKeyboardType = new KeyboardType();
|
||||
mKeyboardType->setId(def_value);
|
||||
MessageParcel data;
|
||||
auto ret = data.WriteParcelable(mKeyboardType);
|
||||
EXPECT_TRUE(ret);
|
||||
sptr<KeyboardType> deserialization = data.ReadParcelable<KeyboardType>();
|
||||
ASSERT_TRUE(deserialization != nullptr);
|
||||
EXPECT_TRUE(deserialization->getId() == def_value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testSerializedInputAttribute
|
||||
* @tc.desc: Checkout the serialization of InputAttribute.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testSerializedInputAttribute, TestSize.Level0)
|
||||
{
|
||||
InputAttribute inAttribute;
|
||||
inAttribute.inputPattern = InputAttribute::PATTERN_PASSWORD;
|
||||
MessageParcel data;
|
||||
EXPECT_TRUE(InputAttribute::Marshalling(inAttribute, data));
|
||||
InputAttribute outAttribute;
|
||||
EXPECT_TRUE(InputAttribute::Unmarshalling(outAttribute, data));
|
||||
EXPECT_TRUE(outAttribute.GetSecurityFlag());
|
||||
}
|
||||
/**
|
||||
* @tc.name: testMoveCursor
|
||||
* @tc.desc: InputMethodAbility MoveCursor
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author: Hollokin
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testMoveCursor, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbility MoveCursor Test START");
|
||||
auto ret = inputMethodAbility_->MoveCursor(4); // move cursor right
|
||||
usleep(500);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
EXPECT_EQ(direction_, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testSerializedKeyboardType
|
||||
* @tc.desc: Checkout the serialization of KeyboardType.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testSerializedKeyboardType, TestSize.Level0)
|
||||
{
|
||||
int32_t def_value = 2021;
|
||||
sptr<KeyboardType> mKeyboardType = new KeyboardType();
|
||||
mKeyboardType->setId(def_value);
|
||||
MessageParcel data;
|
||||
auto ret = data.WriteParcelable(mKeyboardType);
|
||||
EXPECT_TRUE(ret);
|
||||
sptr<KeyboardType> deserialization = data.ReadParcelable<KeyboardType>();
|
||||
EXPECT_TRUE(deserialization != nullptr);
|
||||
EXPECT_TRUE(deserialization->getId() == def_value);
|
||||
}
|
||||
/**
|
||||
* @tc.name: testInsertText
|
||||
* @tc.desc: InputMethodAbility InsertText
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author: Hollokin
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testInsertText, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbility InsertText Test START");
|
||||
auto ret = inputMethodAbility_->InsertText("text");
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
usleep(500);
|
||||
EXPECT_EQ(insertText_, u"text");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testSetImeListener
|
||||
* @tc.desc: InputMethodAbility SetImeListener
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author: Hollokin
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testSetImeListener, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbility SetImeListener Test START");
|
||||
auto listener = std::make_shared<InputMethodEngineListenerImpl>();
|
||||
inputMethodAbility_->setImeListener(listener);
|
||||
auto ret = imc_->StopInputSession();
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
EXPECT_EQ(imeIdStopped_, "");
|
||||
|
||||
ret = imc_->ShowSoftKeyboard();
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
usleep(500);
|
||||
EXPECT_EQ(showKeyboard_, true);
|
||||
|
||||
ret = imc_->HideSoftKeyboard();
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
EXPECT_EQ(showKeyboard_, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testSetKdListener
|
||||
* @tc.desc: InputMethodAbility SetKdListener
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author: Hollokin
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testSetKdListener, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbility SetKdListener Test START");
|
||||
auto keyBoardListener = std::make_shared<KeyboardListenerTestImpl>();
|
||||
inputMethodAbility_->setKdListener(keyBoardListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testSendFunctionKey
|
||||
* @tc.desc: InputMethodAbility SendFunctionKey
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author: Hollokin
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testSendFunctionKey, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbility SendFunctionKey Test START");
|
||||
auto ret = inputMethodAbility_->SendFunctionKey(0);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testDeleteText
|
||||
* @tc.desc: InputMethodAbility DeleteForward & DeleteBackward
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author: Hollokin
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testDeleteText, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbility testDelete Test START");
|
||||
int32_t deleteForwardLenth = 1;
|
||||
auto ret = inputMethodAbility_->DeleteForward(deleteForwardLenth);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
usleep(500);
|
||||
EXPECT_EQ(deleteForwardLength_, deleteForwardLenth);
|
||||
int32_t deleteBackwardLenth = 2;
|
||||
ret = inputMethodAbility_->DeleteBackward(deleteBackwardLenth);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
usleep(500);
|
||||
EXPECT_EQ(deleteBackwardLength_, deleteBackwardLenth);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testGetText001
|
||||
* @tc.desc: InputMethodAbility GetTextBeforeCursor & GetTextAfterCursor
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author: Hollokin
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testGetText001, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbility testGetText001 START");
|
||||
imc_->OnSelectionChange(u"onselectionchange", 0, 3);
|
||||
std::u16string text;
|
||||
auto ret = inputMethodAbility_->GetTextAfterCursor(8, text);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
EXPECT_EQ(text, u"electioncha");
|
||||
ret = inputMethodAbility_->GetTextBeforeCursor(3, text);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
EXPECT_EQ(text, u"");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testGetEnterKeyType
|
||||
* @tc.desc: InputMethodAbility GetEnterKeyType & GetInputPattern
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
* @tc.author: Hollokin
|
||||
*/
|
||||
HWTEST_F(InputMethodAbilityTest, testGetEnterKeyType, TestSize.Level0)
|
||||
{
|
||||
IMSA_HILOGI("InputMethodAbility testGetEnterKeyType START");
|
||||
Configuration config;
|
||||
EnterKeyType keyType = EnterKeyType::NEXT;
|
||||
config.SetEnterKeyType(keyType);
|
||||
TextInputType textInputType = TextInputType::DATETIME;
|
||||
config.SetTextInputType(textInputType);
|
||||
imc_->OnConfigurationChange(config);
|
||||
int32_t keyType2;
|
||||
auto ret = inputMethodAbility_->GetEnterKeyType(keyType2);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
EXPECT_EQ(keyType2, (int)keyType);
|
||||
int32_t inputPattern;
|
||||
ret = inputMethodAbility_->GetInputPattern(inputPattern);
|
||||
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
|
||||
EXPECT_EQ(inputPattern, (int)textInputType);
|
||||
}
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user