!785 删除tdd重复代码

Merge pull request !785 from cy7717/master
This commit is contained in:
openharmony_ci 2023-07-06 08:21:17 +00:00 committed by Gitee
commit a00203c58c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
12 changed files with 227 additions and 503 deletions

166
test/common/text_listener.h Normal file
View File

@ -0,0 +1,166 @@
/*
* 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_TEST_TEXT_LISTENER_H
#define INPUTMETHOD_TEST_TEXT_LISTENER_H
#include <condition_variable>
#include "input_method_controller.h"
#include "input_method_utils.h"
#include "key_event.h"
namespace OHOS {
namespace MiscServices {
class TextListener : public OnTextChangedListener {
public:
TextListener()
{
std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create("TextListenerNotifier");
serviceHandler_ = std::make_shared<AppExecFwk::EventHandler>(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<int>(keyboardStatus));
constexpr int32_t interval = 20;
{
std::unique_lock<std::mutex> 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<int32_t>(enterKeyType);
textListenerCv_.notify_one();
}
void SetKeyboardStatus(bool status) override
{
status_ = status;
}
void MoveCursor(const Direction direction) override
{
direction_ = static_cast<int32_t>(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_);
}
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;
}
static bool WaitIMACallback()
{
std::unique_lock<std::mutex> lock(textListenerCallbackLock_);
return TextListener::textListenerCv_.wait_for(lock, std::chrono::seconds(1)) != std::cv_status::timeout;
}
static std::mutex textListenerCallbackLock_;
static std::condition_variable textListenerCv_;
static int32_t direction_;
static int32_t deleteForwardLength_;
static int32_t deleteBackwardLength_;
static std::u16string insertText_;
static int32_t key_;
static bool status_;
static int32_t selectionStart_;
static int32_t selectionEnd_;
static int32_t selectionDirection_;
static int32_t action_;
static KeyboardStatus keyboardStatus_;
std::shared_ptr<AppExecFwk::EventHandler> serviceHandler_;
};
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 };
} // namespace MiscServices
} // namespace OHOS
#endif // INPUTMETHOD_TEST_TEXT_LISTENER_H

View File

@ -25,7 +25,10 @@ ohos_fuzztest("InputMethodControllerFuzzTest") {
fuzz_config_file =
"//base/inputmethod/imf/test/fuzztest/inputmethodcontroller_fuzzer"
include_dirs = [ "${inputmethod_path}/services/include" ]
include_dirs = [
"${inputmethod_path}/services/include",
"${inputmethod_path}/test/common",
]
cflags = [
"-g",
@ -44,6 +47,7 @@ ohos_fuzztest("InputMethodControllerFuzzTest") {
external_deps = [
"ability_runtime:ability_manager",
"c_utils:utils",
"eventhandler:libeventhandler",
"hilog:libhilog",
"input:libmmi-client",
"ipc:ipc_single",

View File

@ -23,26 +23,10 @@
#include "key_event.h"
#include "message_parcel.h"
#include "input_attribute.h"
#include "text_listener.h"
using namespace OHOS::MiscServices;
namespace OHOS {
class TextListener : public OnTextChangedListener {
public:
TextListener() {}
~TextListener() {}
void InsertText(const std::u16string &text) {}
void DeleteBackward(int32_t length) {}
void SetKeyboardStatus(bool status) {}
void DeleteForward(int32_t length) {}
void SendKeyEventFromInputMethod(const KeyEvent &event) {}
void SendKeyboardStatus(const KeyboardStatus &status) {}
void SendFunctionKey(const FunctionKey &functionKey) {}
void MoveCursor(const Direction direction) {}
void HandleSetSelection(int32_t start, int32_t end) {}
void HandleExtendAction(int32_t action) {}
void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip) {}
};
class SettingListener : public InputMethodSettingListener {
void OnImeChange(const Property &property, const SubProperty &subProperty) {}
void OnPanelStatusChange(const InputWindowStatus &status, const std::vector<InputWindowInfo> &windowInfo) {}

View File

@ -25,7 +25,10 @@ ohos_fuzztest("SystemAbilityStubFuzzTest") {
fuzz_config_file =
"//base/inputmethod/imf/test/fuzztest/systemabilitystub_fuzzer"
include_dirs = [ "${inputmethod_path}/services/include" ]
include_dirs = [
"${inputmethod_path}/services/include",
"${inputmethod_path}/test/common",
]
cflags = [
"-g",

View File

@ -32,6 +32,7 @@
#include "message_parcel.h"
#include "nativetoken_kit.h"
#include "system_ability_definition.h"
#include "text_listener.h"
#include "token_setproc.h"
using namespace OHOS::Security::AccessToken;
@ -63,23 +64,6 @@ void GrantNativePermission()
AccessTokenKit::ReloadNativeTokenInfo();
delete[] perms;
}
class TextListener : public OnTextChangedListener {
public:
TextListener() {}
~TextListener() {}
void InsertText(const std::u16string &text) {}
void DeleteBackward(int32_t length) {}
void SetKeyboardStatus(bool status) {}
void DeleteForward(int32_t length) {}
void SendKeyEventFromInputMethod(const KeyEvent &event) {}
void SendKeyboardStatus(const KeyboardStatus &status) {}
void SendFunctionKey(const FunctionKey &functionKey) {}
void MoveCursor(const Direction direction) {}
void HandleSetSelection(int32_t start, int32_t end) {}
void HandleExtendAction(int32_t action) {}
void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip) {}
};
constexpr size_t THRESHOLD = 10;
constexpr int32_t OFFSET = 4;
const std::u16string SYSTEMABILITY_INTERFACE_TOKEN = u"ohos.miscservices.inputmethod.IInputMethodSystemAbility";

View File

@ -17,7 +17,10 @@ import("//build/test.gni")
config("module_private_config") {
visibility = [ ":*" ]
include_dirs = [ "//base/inputmethod/imf/services/include" ]
include_dirs = [
"${inputmethod_path}/services/include",
"${inputmethod_path}/test/common",
]
}
module_output_path = "imf/cpp"
@ -135,6 +138,8 @@ ohos_unittest("InputMethodDfxTest") {
sources = [ "src/input_method_dfx_test.cpp" ]
configs = [ ":module_private_config" ]
deps = [
"${inputmethod_path}/frameworks/native/inputmethod_ability:inputmethod_ability",
"${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client",

View File

@ -38,6 +38,7 @@
#include "input_method_panel.h"
#include "message_handler.h"
#include "tdd_util.h"
#include "text_listener.h"
using namespace testing::ext;
namespace OHOS {
@ -50,18 +51,6 @@ public:
static std::mutex imeListenerCallbackLock_;
static std::condition_variable imeListenerCv_;
static bool showKeyboard_;
static std::mutex textListenerCallbackLock_;
static std::condition_variable textListenerCv_;
static int direction_;
static int deleteForwardLength_;
static int deleteBackwardLength_;
static std::u16string insertText_;
static int key_;
static bool status_;
static int selectionStart_;
static int selectionEnd_;
static int selectionDirection_;
static int32_t action_;
static constexpr int CURSOR_DIRECTION_BASE_VALUE = 2011;
static sptr<InputMethodController> imc_;
static sptr<InputMethodAbility> inputMethodAbility_;
@ -101,78 +90,6 @@ public:
IMSA_HILOGI("InputMethodEngineListenerImpl OnSetSubtype");
}
};
class TextChangeListener : public OnTextChangedListener {
public:
void InsertText(const std::u16string &text) override
{
insertText_ = text;
InputMethodAbilityTest::textListenerCv_.notify_one();
}
void DeleteForward(int32_t length) override
{
deleteForwardLength_ = length;
InputMethodAbilityTest::textListenerCv_.notify_one();
IMSA_HILOGI("TextChangeListener: DeleteForward, length is: %{public}d", length);
}
void DeleteBackward(int32_t length) override
{
deleteBackwardLength_ = length;
InputMethodAbilityTest::textListenerCv_.notify_one();
IMSA_HILOGI("TextChangeListener: DeleteBackward, direction is: %{public}d", length);
}
void SendKeyEventFromInputMethod(const KeyEvent &event) override
{
}
void SendKeyboardStatus(const KeyboardStatus &keyboardStatus) override
{
}
void SendFunctionKey(const FunctionKey &functionKey) override
{
EnterKeyType enterKeyType = functionKey.GetEnterKeyType();
key_ = static_cast<int>(enterKeyType);
InputMethodAbilityTest::textListenerCv_.notify_one();
}
void SetKeyboardStatus(bool status) override
{
status_ = status;
}
void MoveCursor(const Direction direction) override
{
direction_ = (int)direction;
InputMethodAbilityTest::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;
InputMethodAbilityTest::textListenerCv_.notify_one();
IMSA_HILOGI("TextChangeListener, selectionStart_: %{public}d, selectionEnd_: %{public}d", selectionStart_,
selectionEnd_);
}
void HandleExtendAction(int32_t action) override
{
action_ = action;
InputMethodAbilityTest::textListenerCv_.notify_one();
IMSA_HILOGI("HandleExtendAction, action_: %{public}d", action_);
}
void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip) override
{
selectionDirection_ = keyCode;
InputMethodAbilityTest::textListenerCv_.notify_one();
IMSA_HILOGI("TextChangeListener, selectionDirection_: %{public}d", selectionDirection_);
}
};
static void SetUpTestCase(void)
{
// Set the tokenID to the tokenID of the current ime
@ -188,16 +105,18 @@ public:
// Set the uid to the uid of the focus app
TddUtil::StorageSelfUid();
TddUtil::SetTestUid();
sptr<OnTextChangedListener> textListener = new TextChangeListener();
sptr<OnTextChangedListener> textListener = new TextListener();
imc_ = InputMethodController::GetInstance();
imc_->Attach(textListener);
TddUtil::RestoreSelfUid();
TextListener::ResetParam();
}
static void TearDownTestCase(void)
{
IMSA_HILOGI("InputMethodAbilityTest::TearDownTestCase");
imc_->Close();
TddUtil::KillImsaProcess();
TextListener::ResetParam();
}
void SetUp()
{
@ -213,18 +132,6 @@ std::string InputMethodAbilityTest::imeIdStopped_;
std::mutex InputMethodAbilityTest::imeListenerCallbackLock_;
std::condition_variable InputMethodAbilityTest::imeListenerCv_;
bool InputMethodAbilityTest::showKeyboard_ = true;
std::mutex InputMethodAbilityTest::textListenerCallbackLock_;
std::condition_variable InputMethodAbilityTest::textListenerCv_;
int InputMethodAbilityTest::direction_;
int InputMethodAbilityTest::deleteForwardLength_ = 0;
int InputMethodAbilityTest::deleteBackwardLength_ = 0;
std::u16string InputMethodAbilityTest::insertText_;
int InputMethodAbilityTest::key_ = 0;
bool InputMethodAbilityTest::status_;
int InputMethodAbilityTest::selectionStart_ = -1;
int InputMethodAbilityTest::selectionEnd_ = -1;
int InputMethodAbilityTest::selectionDirection_ = 0;
int32_t InputMethodAbilityTest::action_ = 0;
sptr<InputMethodController> InputMethodAbilityTest::imc_;
sptr<InputMethodAbility> InputMethodAbilityTest::inputMethodAbility_;
uint32_t InputMethodAbilityTest::windowId_ = 0;
@ -327,11 +234,11 @@ HWTEST_F(InputMethodAbilityTest, testMoveCursor, TestSize.Level0)
IMSA_HILOGI("InputMethodAbility MoveCursor Test START");
constexpr int32_t keyCode = 4;
auto ret = inputMethodAbility_->MoveCursor(keyCode); // move cursor right
std::unique_lock<std::mutex> lock(InputMethodAbilityTest::textListenerCallbackLock_);
InputMethodAbilityTest::textListenerCv_.wait_for(
lock, std::chrono::seconds(DEALY_TIME), [] { return InputMethodAbilityTest::direction_ == keyCode; });
std::unique_lock<std::mutex> lock(TextListener::textListenerCallbackLock_);
TextListener::textListenerCv_.wait_for(
lock, std::chrono::seconds(DEALY_TIME), [] { return TextListener::direction_ == keyCode; });
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(InputMethodAbilityTest::direction_, keyCode);
EXPECT_EQ(TextListener::direction_, keyCode);
}
/**
@ -347,11 +254,11 @@ HWTEST_F(InputMethodAbilityTest, testInsertText, TestSize.Level0)
std::string text = "text";
std::u16string u16Text = Str8ToStr16(text);
auto ret = inputMethodAbility_->InsertText(text);
std::unique_lock<std::mutex> lock(InputMethodAbilityTest::textListenerCallbackLock_);
InputMethodAbilityTest::textListenerCv_.wait_for(
lock, std::chrono::seconds(DEALY_TIME), [u16Text] { return InputMethodAbilityTest::insertText_ == u16Text; });
std::unique_lock<std::mutex> lock(TextListener::textListenerCallbackLock_);
TextListener::textListenerCv_.wait_for(
lock, std::chrono::seconds(DEALY_TIME), [u16Text] { return TextListener::insertText_ == u16Text; });
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(InputMethodAbilityTest::insertText_, u16Text);
EXPECT_EQ(TextListener::insertText_, u16Text);
}
/**
@ -366,11 +273,11 @@ HWTEST_F(InputMethodAbilityTest, testSendFunctionKey, TestSize.Level0)
IMSA_HILOGI("InputMethodAbility SendFunctionKey Test START");
constexpr int32_t funcKey = 1;
auto ret = inputMethodAbility_->SendFunctionKey(funcKey);
std::unique_lock<std::mutex> lock(InputMethodAbilityTest::textListenerCallbackLock_);
InputMethodAbilityTest::textListenerCv_.wait_for(
lock, std::chrono::seconds(DEALY_TIME), [] { return InputMethodAbilityTest::key_ == funcKey; });
std::unique_lock<std::mutex> lock(TextListener::textListenerCallbackLock_);
TextListener::textListenerCv_.wait_for(
lock, std::chrono::seconds(DEALY_TIME), [] { return TextListener::key_ == funcKey; });
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(InputMethodAbilityTest::key_, funcKey);
EXPECT_EQ(TextListener::key_, funcKey);
}
/**
@ -385,11 +292,11 @@ HWTEST_F(InputMethodAbilityTest, testSendExtendAction, TestSize.Level0)
IMSA_HILOGI("InputMethodAbility SendExtendAction Test START");
constexpr int32_t action = 1;
auto ret = inputMethodAbility_->SendExtendAction(action);
std::unique_lock<std::mutex> lock(InputMethodAbilityTest::textListenerCallbackLock_);
InputMethodAbilityTest::textListenerCv_.wait_for(
lock, std::chrono::seconds(DEALY_TIME), [] { return InputMethodAbilityTest::action_ == action; });
std::unique_lock<std::mutex> lock(TextListener::textListenerCallbackLock_);
TextListener::textListenerCv_.wait_for(
lock, std::chrono::seconds(DEALY_TIME), [] { return TextListener::action_ == action; });
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(InputMethodAbilityTest::action_, action);
EXPECT_EQ(TextListener::action_, action);
}
/**
@ -404,18 +311,18 @@ HWTEST_F(InputMethodAbilityTest, testDeleteText, TestSize.Level0)
IMSA_HILOGI("InputMethodAbility testDelete Test START");
int32_t deleteForwardLenth = 1;
auto ret = inputMethodAbility_->DeleteForward(deleteForwardLenth);
std::unique_lock<std::mutex> lock(InputMethodAbilityTest::textListenerCallbackLock_);
InputMethodAbilityTest::textListenerCv_.wait_for(lock, std::chrono::seconds(DEALY_TIME),
[deleteForwardLenth] { return InputMethodAbilityTest::deleteBackwardLength_ == deleteForwardLenth; });
std::unique_lock<std::mutex> lock(TextListener::textListenerCallbackLock_);
TextListener::textListenerCv_.wait_for(lock, std::chrono::seconds(DEALY_TIME),
[deleteForwardLenth] { return TextListener::deleteBackwardLength_ == deleteForwardLenth; });
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(InputMethodAbilityTest::deleteBackwardLength_, deleteForwardLenth);
EXPECT_EQ(TextListener::deleteBackwardLength_, deleteForwardLenth);
int32_t deleteBackwardLenth = 2;
ret = inputMethodAbility_->DeleteBackward(deleteBackwardLenth);
InputMethodAbilityTest::textListenerCv_.wait_for(lock, std::chrono::seconds(DEALY_TIME),
[deleteBackwardLenth] { return InputMethodAbilityTest::deleteForwardLength_ == deleteBackwardLenth; });
TextListener::textListenerCv_.wait_for(lock, std::chrono::seconds(DEALY_TIME),
[deleteBackwardLenth] { return TextListener::deleteForwardLength_ == deleteBackwardLenth; });
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(InputMethodAbilityTest::deleteForwardLength_, deleteBackwardLenth);
EXPECT_EQ(TextListener::deleteForwardLength_, deleteBackwardLenth);
}
/**
@ -457,13 +364,12 @@ HWTEST_F(InputMethodAbilityTest, testSelectByRange_001, TestSize.Level0)
constexpr int32_t start = 1;
constexpr int32_t end = 2;
auto ret = inputMethodAbility_->SelectByRange(start, end);
std::unique_lock<std::mutex> lock(InputMethodAbilityTest::textListenerCallbackLock_);
InputMethodAbilityTest::textListenerCv_.wait_for(lock, std::chrono::seconds(DEALY_TIME), [] {
return InputMethodAbilityTest::selectionStart_ == start && InputMethodAbilityTest::selectionEnd_ == end;
});
std::unique_lock<std::mutex> lock(TextListener::textListenerCallbackLock_);
TextListener::textListenerCv_.wait_for(lock, std::chrono::seconds(DEALY_TIME),
[] { return TextListener::selectionStart_ == start && TextListener::selectionEnd_ == end; });
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(InputMethodAbilityTest::selectionStart_, start);
EXPECT_EQ(InputMethodAbilityTest::selectionEnd_, end);
EXPECT_EQ(TextListener::selectionStart_, start);
EXPECT_EQ(TextListener::selectionEnd_, end);
}
/**
@ -499,14 +405,12 @@ HWTEST_F(InputMethodAbilityTest, testSelectByMovement, TestSize.Level0)
IMSA_HILOGI("InputMethodAbility testSelectByMovement START");
constexpr int32_t direction = 1;
auto ret = inputMethodAbility_->SelectByMovement(direction);
std::unique_lock<std::mutex> lock(InputMethodAbilityTest::textListenerCallbackLock_);
InputMethodAbilityTest::textListenerCv_.wait_for(lock, std::chrono::seconds(DEALY_TIME), [] {
return InputMethodAbilityTest::selectionDirection_
== direction + InputMethodAbilityTest::CURSOR_DIRECTION_BASE_VALUE;
std::unique_lock<std::mutex> lock(TextListener::textListenerCallbackLock_);
TextListener::textListenerCv_.wait_for(lock, std::chrono::seconds(DEALY_TIME), [] {
return TextListener::selectionDirection_ == direction + InputMethodAbilityTest::CURSOR_DIRECTION_BASE_VALUE;
});
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_EQ(
InputMethodAbilityTest::selectionDirection_, direction + InputMethodAbilityTest::CURSOR_DIRECTION_BASE_VALUE);
EXPECT_EQ(TextListener::selectionDirection_, direction + InputMethodAbilityTest::CURSOR_DIRECTION_BASE_VALUE);
}
/**

View File

@ -52,6 +52,7 @@
#include "system_ability.h"
#include "system_ability_definition.h"
#include "tdd_util.h"
#include "text_listener.h"
using namespace testing;
using namespace testing::ext;
@ -59,96 +60,6 @@ namespace OHOS {
namespace MiscServices {
constexpr uint32_t DEALY_TIME = 1;
constexpr uint32_t KEY_EVENT_DELAY_TIME = 100;
class TextListener : public OnTextChangedListener {
public:
TextListener()
{
std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create("TextListenerNotifier");
serviceHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
}
~TextListener()
{
}
static KeyboardStatus keyboardStatus_;
static std::mutex cvMutex_;
static std::condition_variable cv_;
std::shared_ptr<AppExecFwk::EventHandler> serviceHandler_;
static int32_t direction_;
static int32_t deleteForwardLength_;
static int32_t deleteBackwardLength_;
static std::u16string insertText_;
static int32_t key_;
static bool WaitIMACallback()
{
std::unique_lock<std::mutex> lock(TextListener::cvMutex_);
return TextListener::cv_.wait_for(lock, std::chrono::seconds(1)) != std::cv_status::timeout;
}
void InsertText(const std::u16string &text)
{
IMSA_HILOGI("IMC TEST TextListener InsertText: %{public}s", Str16ToStr8(text).c_str());
insertText_ = text;
}
void DeleteBackward(int32_t length)
{
IMSA_HILOGI("IMC TEST TextListener DeleteBackward length: %{public}d", length);
deleteBackwardLength_ = length;
}
void SetKeyboardStatus(bool status)
{
IMSA_HILOGI("IMC TEST TextListener SetKeyboardStatus %{public}d", status);
}
void DeleteForward(int32_t length)
{
IMSA_HILOGI("IMC TEST TextListener DeleteForward length: %{public}d", length);
deleteForwardLength_ = length;
}
void SendKeyEventFromInputMethod(const KeyEvent &event)
{
IMSA_HILOGI("IMC TEST TextListener sendKeyEventFromInputMethod");
}
void SendKeyboardStatus(const KeyboardStatus &keyboardStatus)
{
IMSA_HILOGD("TextListener::SendKeyboardStatus %{public}d", static_cast<int>(keyboardStatus));
constexpr int32_t interval = 20;
{
std::unique_lock<std::mutex> lock(cvMutex_);
IMSA_HILOGD("TextListener::SendKeyboardStatus lock");
keyboardStatus_ = keyboardStatus;
}
serviceHandler_->PostTask([this]() { cv_.notify_all(); }, interval);
IMSA_HILOGD("TextListener::SendKeyboardStatus notify_all");
}
void SendFunctionKey(const FunctionKey &functionKey)
{
IMSA_HILOGI("IMC TEST TextListener SendFunctionKey");
EnterKeyType enterKeyType = functionKey.GetEnterKeyType();
key_ = static_cast<int32_t>(enterKeyType);
}
void MoveCursor(const Direction direction)
{
IMSA_HILOGI("IMC TEST TextListener MoveCursor");
direction_ = static_cast<int32_t>(direction);
}
void HandleSetSelection(int32_t start, int32_t end)
{
}
void HandleExtendAction(int32_t action)
{
}
void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip)
{
}
};
KeyboardStatus TextListener::keyboardStatus_;
std::mutex TextListener::cvMutex_;
std::condition_variable TextListener::cv_;
int32_t TextListener::direction_ = 0;
int32_t TextListener::deleteForwardLength_ = 0;
int32_t TextListener::deleteBackwardLength_ = 0;
std::u16string TextListener::insertText_;
int32_t TextListener::key_ = 0;
class InputMethodEngineListenerImpl : public InputMethodEngineListener {
public:
@ -347,6 +258,7 @@ constexpr uint32_t KEY_EVENT_DELAY_TIME = 100;
TddUtil::StorageSelfUid();
TddUtil::SetTestUid();
SetInputDeathRecipient();
TextListener::ResetParam();
}
void InputMethodControllerTest::TearDownTestCase(void)
@ -354,6 +266,7 @@ constexpr uint32_t KEY_EVENT_DELAY_TIME = 100;
IMSA_HILOGI("InputMethodControllerTest::TearDownTestCase");
TddUtil::RestoreSelfTokenID();
TddUtil::RestoreSelfUid();
TextListener::ResetParam();
}
void InputMethodControllerTest::SetUp(void)

View File

@ -34,6 +34,7 @@
#include "input_method_ability.h"
#include "input_method_controller.h"
#include "tdd_util.h"
#include "text_listener.h"
using namespace testing::ext;
using namespace OHOS::HiviewDFX;
@ -72,79 +73,6 @@ public:
}
};
class TextListener : public OnTextChangedListener {
public:
TextListener()
{
std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create("TextListenerNotifier");
serviceHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
}
~TextListener()
{
}
static KeyboardStatus keyboardStatus_;
static std::mutex cvMutex_;
static std::condition_variable cv_;
std::shared_ptr<AppExecFwk::EventHandler> serviceHandler_;
static bool WaitIMACallback()
{
std::unique_lock<std::mutex> lock(TextListener::cvMutex_);
return TextListener::cv_.wait_for(lock, std::chrono::seconds(1)) != std::cv_status::timeout;
}
void InsertText(const std::u16string &text)
{
IMSA_HILOGI("IMC TEST TextListener InsertText");
}
void DeleteBackward(int32_t length)
{
IMSA_HILOGI("IMC TEST TextListener DeleteBackward length: %{public}d", length);
}
void SetKeyboardStatus(bool status)
{
IMSA_HILOGI("IMC TEST TextListener SetKeyboardStatus %{public}d", status);
}
void DeleteForward(int32_t length)
{
IMSA_HILOGI("IMC TEST TextListener DeleteForward length: %{public}d", length);
}
void SendKeyEventFromInputMethod(const KeyEvent &event)
{
IMSA_HILOGI("IMC TEST TextListener sendKeyEventFromInputMethod");
}
void SendKeyboardStatus(const KeyboardStatus &keyboardStatus)
{
IMSA_HILOGD("TextListener::SendKeyboardStatus %{public}d", static_cast<int>(keyboardStatus));
constexpr int32_t interval = 20;
{
std::unique_lock<std::mutex> lock(cvMutex_);
IMSA_HILOGD("TextListener::SendKeyboardStatus lock");
keyboardStatus_ = keyboardStatus;
}
serviceHandler_->PostTask([this]() { cv_.notify_all(); }, interval);
IMSA_HILOGD("TextListener::SendKeyboardStatus notify_all");
}
void SendFunctionKey(const FunctionKey &functionKey)
{
IMSA_HILOGI("IMC TEST TextListener SendFunctionKey");
}
void MoveCursor(const Direction direction)
{
IMSA_HILOGI("IMC TEST TextListener MoveCursor");
}
void HandleSetSelection(int32_t start, int32_t end)
{
}
void HandleExtendAction(int32_t action)
{
}
void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip)
{
}
};
KeyboardStatus TextListener::keyboardStatus_;
std::mutex TextListener::cvMutex_;
std::condition_variable TextListener::cv_;
class Watcher : public HiSysEventListener {
public:
explicit Watcher(const std::string &operateInfo) : operateInfo_(operateInfo)

View File

@ -38,85 +38,11 @@
#include "keyboard_listener.h"
#include "message_parcel.h"
#include "tdd_util.h"
#include "text_listener.h"
using namespace testing::ext;
namespace OHOS {
namespace MiscServices {
class TextListener : public OnTextChangedListener {
public:
TextListener()
{
std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create("TextListenerNotifier");
serviceHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
}
~TextListener()
{
}
static KeyboardStatus keyboardStatus_;
static std::mutex cvMutex_;
static std::condition_variable cv_;
std::shared_ptr<AppExecFwk::EventHandler> serviceHandler_;
static bool WaitIMACallback()
{
std::unique_lock<std::mutex> lock(TextListener::cvMutex_);
return TextListener::cv_.wait_for(lock, std::chrono::seconds(1)) != std::cv_status::timeout;
}
void InsertText(const std::u16string &text)
{
IMSA_HILOGI("IMC TEST TextListener InsertText: %{public}s", Str16ToStr8(text).c_str());
}
void DeleteBackward(int32_t length)
{
IMSA_HILOGI("IMC TEST TextListener DeleteBackward length: %{public}d", length);
}
void SetKeyboardStatus(bool status)
{
IMSA_HILOGI("IMC TEST TextListener SetKeyboardStatus %{public}d", status);
}
void DeleteForward(int32_t length)
{
IMSA_HILOGI("IMC TEST TextListener DeleteForward length: %{public}d", length);
}
void SendKeyEventFromInputMethod(const KeyEvent &event)
{
IMSA_HILOGI("IMC TEST TextListener sendKeyEventFromInputMethod");
}
void SendKeyboardStatus(const KeyboardStatus &keyboardStatus)
{
IMSA_HILOGD("TextListener::SendKeyboardStatus %{public}d", static_cast<int>(keyboardStatus));
constexpr int32_t interval = 20;
{
std::unique_lock<std::mutex> lock(cvMutex_);
IMSA_HILOGD("TextListener::SendKeyboardStatus lock");
keyboardStatus_ = keyboardStatus;
}
serviceHandler_->PostTask([this]() { cv_.notify_all(); }, interval);
IMSA_HILOGD("TextListener::SendKeyboardStatus notify_all");
}
void SendFunctionKey(const FunctionKey &functionKey)
{
IMSA_HILOGI("IMC TEST TextListener SendFunctionKey");
}
void MoveCursor(const Direction direction)
{
IMSA_HILOGI("IMC TEST TextListener MoveCursor");
}
void HandleSetSelection(int32_t start, int32_t end)
{
}
void HandleExtendAction(int32_t action)
{
}
void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip)
{
}
};
KeyboardStatus TextListener::keyboardStatus_;
std::mutex TextListener::cvMutex_;
std::condition_variable TextListener::cv_;
class KeyboardListenerImpl : public KeyboardListener {
public:
KeyboardListenerImpl(){};
@ -242,6 +168,7 @@ void InputMethodEditorTest::SetUpTestCase(void)
keyEvent_->SetKeyAction(keyAction);
keyEvent_->SetKeyCode(keyCode);
TddUtil::StorageSelfUid();
TextListener::ResetParam();
}
void InputMethodEditorTest::TearDownTestCase(void)
@ -249,6 +176,7 @@ void InputMethodEditorTest::TearDownTestCase(void)
IMSA_HILOGI("InputMethodEditorTest::TearDownTestCase");
TddUtil::RestoreSelfTokenID();
TddUtil::KillImsaProcess();
TextListener::ResetParam();
}
void InputMethodEditorTest::SetUp(void)

View File

@ -46,50 +46,6 @@ public:
void TearDown();
};
class TextListener : public OnTextChangedListener {
public:
TextListener()
{
}
~TextListener()
{
}
void InsertText(const std::u16string &text)
{
IMSA_HILOGI("SERVICE TEST TextListener InsertText");
}
void DeleteBackward(int32_t length)
{
IMSA_HILOGI("SERVICE TEST TextListener DeleteBackward length: %{public}d", length);
}
void SetKeyboardStatus(bool status)
{
IMSA_HILOGI("SERVICE TEST TextListener SetKeyboardStatus %{public}d", status);
}
void DeleteForward(int32_t length)
{
IMSA_HILOGI("SERVICE TEST TextListener DeleteForward length: %{public}d", length);
}
void SendKeyEventFromInputMethod(const KeyEvent &event)
{
IMSA_HILOGI("SERVICE TEST TextListener sendKeyEventFromInputMethod");
}
void SendKeyboardStatus(const KeyboardStatus &status)
{
IMSA_HILOGI("SERVICE TEST TextListener SendKeyboardStatus");
}
void SendFunctionKey(const FunctionKey &functionKey)
{
IMSA_HILOGI("SERVICE TEST TextListener SendFunctionKey");
}
void MoveCursor(const Direction direction)
{
IMSA_HILOGI("SERVICE TEST TextListener MoveCursor");
}
};
void InputMethodServiceTest::SetUpTestCase(void)
{
IMSA_HILOGI("InputMethodServiceTest::SetUpTestCase");

View File

@ -29,62 +29,11 @@
#include "input_method_ability.h"
#include "input_method_controller.h"
#include "tdd_util.h"
#include "text_listener.h"
using namespace testing::ext;
namespace OHOS {
namespace MiscServices {
class TextListener : public OnTextChangedListener {
public:
TextListener() = default;
~TextListener() override = default;
void InsertText(const std::u16string &text) override;
void DeleteBackward(int32_t length) override;
void SetKeyboardStatus(bool status) override;
void DeleteForward(int32_t length) override;
void SendKeyEventFromInputMethod(const KeyEvent &event) override;
void SendKeyboardStatus(const KeyboardStatus &keyboardStatus) override;
void SendFunctionKey(const FunctionKey &functionKey) 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;
};
void TextListener::InsertText(const std::u16string &text)
{
}
void TextListener::DeleteBackward(int32_t length)
{
}
void TextListener::SetKeyboardStatus(bool status)
{
}
void TextListener::DeleteForward(int32_t length)
{
}
void TextListener::SendKeyEventFromInputMethod(const KeyEvent &event)
{
}
void TextListener::SendKeyboardStatus(const KeyboardStatus &keyboardStatus)
{
}
void TextListener::SendFunctionKey(const FunctionKey &functionKey)
{
}
void TextListener::MoveCursor(const Direction direction)
{
}
void TextListener::HandleSetSelection(int32_t start, int32_t end)
{
}
void TextListener::HandleExtendAction(int32_t action)
{
}
void TextListener::HandleSelect(int32_t keyCode, int32_t cursorMoveSkip)
{
}
class PermissionVerificationExceptionTest : public testing::Test {
public:
static void SetUpTestCase(void);