!1156 [Bug]: tdd优化与覆盖率

Merge pull request !1156 from 赵凌岚/master
This commit is contained in:
openharmony_ci 2024-04-30 08:59:29 +00:00 committed by Gitee
commit b5dce394aa
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
13 changed files with 548 additions and 51 deletions

View File

@ -142,7 +142,7 @@ bool ITypesUtil::Unmarshalling(Property &output, MessageParcel &data)
bool ITypesUtil::Marshalling(const SubProperty &input, MessageParcel &data)
{
if (!Marshal(data, input.label, input.labelId, input.name, input.id, input.mode, input.locale, input.language,
input.icon, input.iconId)) {
input.icon, input.iconId)) {
IMSA_HILOGE("ITypesUtil::write SubProperty to message parcel failed");
return false;
}

View File

@ -54,20 +54,21 @@ void TextListener::InsertText(const std::u16string &text)
{
insertText_ = text;
textListenerCv_.notify_one();
IMSA_HILOGI("TextListener text: %{public}s", Str16ToStr8(text).c_str());
}
void TextListener::DeleteForward(int32_t length)
{
deleteForwardLength_ = length;
textListenerCv_.notify_one();
IMSA_HILOGI("TextChangeListener: DeleteForward, length is: %{public}d", length);
IMSA_HILOGI("TextListener: 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);
IMSA_HILOGI("TextListener: DeleteBackward, direction is: %{public}d", length);
}
void TextListener::SendKeyEventFromInputMethod(const KeyEvent &event)
@ -76,7 +77,7 @@ void TextListener::SendKeyEventFromInputMethod(const KeyEvent &event)
void TextListener::SendKeyboardStatus(const KeyboardStatus &keyboardStatus)
{
IMSA_HILOGD("TextListener::SendKeyboardStatus %{public}d", static_cast<int>(keyboardStatus));
IMSA_HILOGI("TextListener::SendKeyboardStatus %{public}d", static_cast<int>(keyboardStatus));
keyboardStatus_ = keyboardStatus;
textListenerCv_.notify_one();
}
@ -85,19 +86,21 @@ void TextListener::SendFunctionKey(const FunctionKey &functionKey)
{
EnterKeyType enterKeyType = functionKey.GetEnterKeyType();
key_ = static_cast<int32_t>(enterKeyType);
IMSA_HILOGI("TextListener functionKey: %{public}d", key_);
textListenerCv_.notify_one();
}
void TextListener::SetKeyboardStatus(bool status)
{
status_ = status;
IMSA_HILOGI("TextListener status: %{public}d", status);
}
void TextListener::MoveCursor(const Direction direction)
{
direction_ = static_cast<int32_t>(direction);
textListenerCv_.notify_one();
IMSA_HILOGI("TextChangeListener: MoveCursor, direction is: %{public}d", direction);
IMSA_HILOGI("TextListener: MoveCursor, direction is: %{public}d", direction);
}
void TextListener::HandleSetSelection(int32_t start, int32_t end)
@ -106,7 +109,7 @@ void TextListener::HandleSetSelection(int32_t start, int32_t end)
selectionEnd_ = end;
textListenerCv_.notify_one();
IMSA_HILOGI(
"TextChangeListener, selectionStart_: %{public}d, selectionEnd_: %{public}d", selectionStart_, selectionEnd_);
"TextListener, selectionStart_: %{public}d, selectionEnd_: %{public}d", selectionStart_, selectionEnd_);
}
void TextListener::HandleExtendAction(int32_t action)
@ -121,16 +124,18 @@ void TextListener::HandleSelect(int32_t keyCode, int32_t cursorMoveSkip)
selectionDirection_ = keyCode;
selectionSkip_ = cursorMoveSkip;
textListenerCv_.notify_one();
IMSA_HILOGI("TextChangeListener, selectionDirection_: %{public}d", selectionDirection_);
IMSA_HILOGI("TextListener, selectionDirection_: %{public}d", selectionDirection_);
}
std::u16string TextListener::GetLeftTextOfCursor(int32_t number)
{
IMSA_HILOGI("TextListener number: %{public}d", number);
return Str8ToStr16(TEXT_BEFORE_CURSOR);
}
std::u16string TextListener::GetRightTextOfCursor(int32_t number)
{
IMSA_HILOGI("TextListener number: %{public}d", number);
return Str8ToStr16(TEXT_AFTER_CURSOR);
}
@ -147,7 +152,7 @@ int32_t TextListener::ReceivePrivateCommand(const std::unordered_map<std::string
void TextListener::NotifyPanelStatusInfo(const PanelStatusInfo &info)
{
IMSA_HILOGD("TextListener::type: %{public}d, flag: %{public}d, visible: %{public}d, trigger: %{public}d.",
IMSA_HILOGI("TextListener::type: %{public}d, flag: %{public}d, visible: %{public}d, trigger: %{public}d.",
static_cast<PanelType>(info.panelInfo.panelType), static_cast<PanelFlag>(info.panelInfo.panelFlag),
info.visible, static_cast<Trigger>(info.trigger));
info_ = info;
@ -156,7 +161,7 @@ void TextListener::NotifyPanelStatusInfo(const PanelStatusInfo &info)
void TextListener::NotifyKeyboardHeight(uint32_t height)
{
IMSA_HILOGD("keyboard height: %{public}u", height);
IMSA_HILOGI("keyboard height: %{public}u", height);
height_ = height;
textListenerCv_.notify_one();
}
@ -224,7 +229,6 @@ bool TextListener::WaitSendPrivateCommandCallback(std::unordered_map<std::string
std::unique_lock<std::mutex> lock(textListenerCallbackLock_);
textListenerCv_.wait_for(
lock, std::chrono::seconds(1), [privateCommand]() { return privateCommand_ == privateCommand; });
return privateCommand_ == privateCommand;
}
} // namespace MiscServices

View File

@ -23,6 +23,7 @@ group("unittest") {
"cpp_test:IdentityCheckerTest",
"cpp_test:ImeFreezeManagerTest",
"cpp_test:ImeProxyTest",
"cpp_test:ImeSystemChannelTest",
"cpp_test:InputMethodAbilityTest",
"cpp_test:InputMethodAttachTest",
"cpp_test:InputMethodControllerTest",
@ -36,6 +37,7 @@ group("unittest") {
"cpp_test:NewImeSwitchTest",
"cpp_test:SecurityModeParseTest",
"cpp_test:TextListenerInnerApiTest",
"cpp_test:VirtualListenerTest",
"cpp_test/common:inputmethod_tdd_util",
"napi_test/src:GetInputMethodJsTest",
"resource/bundle_dependencies/editorBox:editorBox",

View File

@ -698,3 +698,83 @@ ohos_unittest("JsonOperateTest") {
"ipc:ipc_single",
]
}
ohos_unittest("VirtualListenerTest") {
branch_protector_ret = "pac_ret"
sanitize = {
cfi = true
cfi_cross_dso = true
debug = false
}
module_out_path = module_output_path
sources = [ "src/virtual_listener_test.cpp" ]
configs = [ ":module_private_config" ]
deps = [
"${inputmethod_path}/interfaces/inner_api/inputmethod_ability:inputmethod_ability",
"${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client_static",
"${inputmethod_path}/services:inputmethod_service",
"${inputmethod_path}/test/common:inputmethod_test_common",
"//third_party/googletest:gmock",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:want",
"ability_runtime:ability_context_native",
"ability_runtime:ability_manager",
"access_token:libaccesstoken_sdk",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"eventhandler:libeventhandler",
"hilog:libhilog",
"input:libmmi-client",
"ipc:ipc_single",
"napi:ace_napi",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
"window_manager:libwm",
]
}
ohos_unittest("ImeSystemChannelTest") {
branch_protector_ret = "pac_ret"
sanitize = {
cfi = true
cfi_cross_dso = true
debug = false
blocklist = "./inputmethod_blocklist.txt"
}
module_out_path = module_output_path
sources = [ "src/ime_system_channel_test.cpp" ]
configs = [ ":module_private_config" ]
deps = [
"${inputmethod_path}/interfaces/inner_api/inputmethod_ability:inputmethod_ability",
"${inputmethod_path}/interfaces/inner_api/inputmethod_controller:inputmethod_client_static",
"${inputmethod_path}/services:inputmethod_service",
"${inputmethod_path}/test/common:inputmethod_test_common",
"${inputmethod_path}/test/unittest/cpp_test/common:inputmethod_tdd_util",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:want",
"ability_runtime:ability_context_native",
"ability_runtime:ability_manager",
"access_token:libaccesstoken_sdk",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"eventhandler:libeventhandler",
"hilog:libhilog",
"input:libmmi-client",
"ipc:ipc_single",
"napi:ace_napi",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
"window_manager:libwm",
]
}

View File

@ -289,6 +289,7 @@ void TddUtil::GrantNativePermission()
void TddUtil::PushEnableImeValue(const std::string &key, const std::string &value)
{
IMSA_HILOGI("key: %{public}s, value: %{public}s", key.c_str(), value.c_str());
auto helper = SettingsDataUtils::GetInstance()->CreateDataShareHelper();
if (helper == nullptr) {
IMSA_HILOGE("helper is nullptr.");
@ -303,15 +304,23 @@ void TddUtil::PushEnableImeValue(const std::string &key, const std::string &valu
predicates.EqualTo(SETTING_COLUMN_KEYWORD, key);
Uri uri(SettingsDataUtils::GetInstance()->GenerateTargetUri(key));
if (helper->Update(uri, predicates, bucket) <= 0) {
IMSA_HILOGD("no data exist, insert one row");
helper->Insert(uri, bucket);
int index = helper->Insert(uri, bucket);
IMSA_HILOGI("no data exists, insert ret index: %{public}d", index);
} else {
IMSA_HILOGI("data exits");
}
SettingsDataUtils::GetInstance()->ReleaseDataShareHelper(helper);
bool ret = SettingsDataUtils::GetInstance()->ReleaseDataShareHelper(helper);
IMSA_HILOGI("ReleaseDataShareHelper isSuccess: %{public}d", ret);
}
int32_t TddUtil::GetEnableData(std::string &value)
{
return SettingsDataUtils::GetInstance()->GetStringValue(EnableImeDataParser::ENABLE_IME, value);
auto ret = SettingsDataUtils::GetInstance()->GetStringValue(EnableImeDataParser::ENABLE_IME, value);
if (ret == ErrorCode::NO_ERROR) {
IMSA_HILOGI("success, value: %{public}s", value.c_str());
}
IMSA_HILOGI("GetStringValue ret: %{public}d", ret);
return ret;
}
void TddUtil::InitWindow(bool isShow)
@ -361,6 +370,10 @@ void TddUtil::WindowManager::CreateWindow()
std::shared_ptr<AbilityRuntime::Context> context = nullptr;
WMError wmError = WMError::WM_OK;
window_ = Window::Create(windowName, winOption, context, wmError);
if (window_ == nullptr) {
IMSA_HILOGE("failed to create window, ret: %{public}d", wmError);
return;
}
IMSA_HILOGI("Create window ret:%{public}d", wmError);
currentWindowId_ = window_->GetWindowId();
}
@ -371,6 +384,7 @@ void TddUtil::WindowManager::ShowWindow()
IMSA_HILOGE("window is not exist.");
return;
}
TokenScope scope(windowTokenId_);
auto ret = window_->Show();
IMSA_HILOGI("Show window end, ret = %{public}d", ret);
}
@ -388,10 +402,13 @@ void TddUtil::WindowManager::HideWindow()
void TddUtil::WindowManager::DestroyWindow()
{
if (window_ != nullptr) {
TokenScope scope(windowTokenId_);
window_->Destroy();
if (window_ == nullptr) {
IMSA_HILOGE("window_ nullptr");
return;
}
TokenScope scope(windowTokenId_);
auto wmError = window_->Destroy();
IMSA_HILOGI("Destroy window ret: %{public}d", wmError);
}
void TddUtil::WindowManager::RegisterFocusChangeListener()

View File

@ -178,7 +178,7 @@ std::mutex ImeFreezeManagerTest::mtx_;
HWTEST_F(ImeFreezeManagerTest, SingleThread_StartInput_001, TestSize.Level0)
{
IMSA_HILOGI("ImeFreezeManagerTest::SingleThread_StartInput_001");
EXPECT_NE(ImeFreezeManagerTest::freezeManager_, nullptr);
ASSERT_NE(ImeFreezeManagerTest::freezeManager_, nullptr);
ClearState();
TestAttach(false);
TestAttach(true);
@ -204,7 +204,7 @@ HWTEST_F(ImeFreezeManagerTest, SingleThread_StartInput_001, TestSize.Level0)
HWTEST_F(ImeFreezeManagerTest, SingleThread_StartAndStopInput_001, TestSize.Level0)
{
IMSA_HILOGI("ImeFreezeManagerTest::SingleThread_StartAndStopInput_001");
EXPECT_NE(ImeFreezeManagerTest::freezeManager_, nullptr);
ASSERT_NE(ImeFreezeManagerTest::freezeManager_, nullptr);
ClearState();
TestAttach(true);
TestDetach();
@ -227,7 +227,7 @@ HWTEST_F(ImeFreezeManagerTest, SingleThread_StartAndStopInput_001, TestSize.Leve
HWTEST_F(ImeFreezeManagerTest, SingleThread_StartInputAndRequestHide_001, TestSize.Level0)
{
IMSA_HILOGI("ImeFreezeManagerTest::SingleThread_StartInputAndRequestHide_001");
EXPECT_NE(ImeFreezeManagerTest::freezeManager_, nullptr);
ASSERT_NE(ImeFreezeManagerTest::freezeManager_, nullptr);
ClearState();
TestAttach(true);
TestRequestHideInput(true);
@ -245,7 +245,7 @@ HWTEST_F(ImeFreezeManagerTest, SingleThread_StartInputAndRequestHide_001, TestSi
HWTEST_F(ImeFreezeManagerTest, SingleThread_StartInputAndNormalIPC_001, TestSize.Level0)
{
IMSA_HILOGI("ImeFreezeManagerTest::SingleThread_StartInputAndNormalIPC_001");
EXPECT_NE(ImeFreezeManagerTest::freezeManager_, nullptr);
ASSERT_NE(ImeFreezeManagerTest::freezeManager_, nullptr);
ClearState();
TestNormalIPC();
@ -266,7 +266,7 @@ HWTEST_F(ImeFreezeManagerTest, SingleThread_StartInputAndNormalIPC_001, TestSize
HWTEST_F(ImeFreezeManagerTest, MultiThread_FullTest_001, TestSize.Level0)
{
IMSA_HILOGI("ImeFreezeManagerTest::MultiThread_FullTest_001");
EXPECT_NE(ImeFreezeManagerTest::freezeManager_, nullptr);
ASSERT_NE(ImeFreezeManagerTest::freezeManager_, nullptr);
SET_THREAD_NUM(5);
GTEST_RUN_TASK(FullTestTask);
}
@ -279,7 +279,7 @@ HWTEST_F(ImeFreezeManagerTest, MultiThread_FullTest_001, TestSize.Level0)
HWTEST_F(ImeFreezeManagerTest, SingleThread_RequestShow_001, TestSize.Level0)
{
IMSA_HILOGI("ImeFreezeManagerTest::SingleThread_RequestShow_001");
EXPECT_NE(ImeFreezeManagerTest::freezeManager_, nullptr);
ASSERT_NE(ImeFreezeManagerTest::freezeManager_, nullptr);
ClearState();
TestRequestShowInput(true);
}

View File

@ -0,0 +1,140 @@
/*
* Copyright (c) 2024 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.
*/
#define private public
#define protected public
#include "ime_system_channel.h"
#undef private
#include <gtest/gtest.h>
#include "scope_utils.h"
#include "tdd_util.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace MiscServices {
class OnSystemCmdListenerImpl : public OnSystemCmdListener {
void ReceivePrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand) override
{
}
void NotifyIsShowSysPanel(bool shouldSysPanelShow) override
{
}
};
class ImeSystemChannelTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
static sptr<ImeSystemCmdChannel> imeSystemChannel_;
static sptr<OnSystemCmdListener> sysCmdListener_;
static uint64_t permissionTokenId_;
};
sptr<ImeSystemCmdChannel> ImeSystemChannelTest::imeSystemChannel_;
sptr<OnSystemCmdListener> ImeSystemChannelTest::sysCmdListener_;
uint64_t ImeSystemChannelTest::permissionTokenId_ = 0;
void ImeSystemChannelTest::SetUpTestCase(void)
{
TddUtil::StorageSelfTokenID();
imeSystemChannel_ = ImeSystemCmdChannel::GetInstance();
sysCmdListener_ = new (std::nothrow) OnSystemCmdListenerImpl();
permissionTokenId_ =
TddUtil::AllocTestTokenID(true, "ohos.inputMethod.test", { "ohos.permission.CONNECT_IME_ABILITY" });
}
void ImeSystemChannelTest::TearDownTestCase(void)
{
IMSA_HILOGI("ImeSystemChannelTest::TearDownTestCase");
imeSystemChannel_->ConnectSystemCmd(nullptr);
imeSystemChannel_->ClearSystemCmdAgent();
TddUtil::RestoreSelfTokenID();
}
void ImeSystemChannelTest::SetUp(void)
{
IMSA_HILOGI("ImeSystemChannelTest::SetUp");
}
void ImeSystemChannelTest::TearDown(void)
{
IMSA_HILOGI("ImeSystemChannelTest::TearDown");
}
/**
* @tc.name: testConnectSystemCmd001
* @tc.desc: SystemCmdChannel ConnectSystemCmd.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(ImeSystemChannelTest, testConnectSystemCmd001, TestSize.Level0)
{
IMSA_HILOGD("ImeSystemChannelTest testConnectSystemCmd001 Test START");
auto ret = imeSystemChannel_->ConnectSystemCmd(sysCmdListener_);
EXPECT_EQ(ret, ErrorCode::ERROR_STATUS_SYSTEM_PERMISSION);
}
/**
* @tc.name: testConnectSystemCmd002
* @tc.desc: SystemCmdChannel ConnectSystemCmd.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(ImeSystemChannelTest, testConnectSystemCmd002, TestSize.Level0)
{
IMSA_HILOGD("ImeSystemChannelTest testConnectSystemCmd002 Test START");
TokenScope scope(ImeSystemChannelTest::permissionTokenId_);
auto ret = imeSystemChannel_->ConnectSystemCmd(sysCmdListener_);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
/**
* @tc.name: testSendPrivateCommand001
* @tc.desc: SystemCmdChannel SendPrivateCommand.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(ImeSystemChannelTest, testSendPrivateCommand001, TestSize.Level0)
{
IMSA_HILOGD("ImeSystemChannelTest testSendPrivateCommand001 Test START");
TokenScope scope(ImeSystemChannelTest::permissionTokenId_);
std::unordered_map<std::string, PrivateDataValue> privateCommand;
auto ret = imeSystemChannel_->SendPrivateCommand(privateCommand);
EXPECT_EQ(ret, ErrorCode::ERROR_INVALID_PRIVATE_COMMAND);
}
/**
* @tc.name: testImeSystemChannel_nullptr
* @tc.desc: SystemCmdChannel ReceivePrivateCommand.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(ImeSystemChannelTest, testImeSystemChannel_nullptr, TestSize.Level0)
{
IMSA_HILOGD("ImeSystemChannelTest testImeSystemChannel_nullptr Test START");
std::unordered_map<std::string, PrivateDataValue> privateCommand;
PrivateDataValue privateDataValue1 = std::string("stringValue");
privateCommand.emplace("value1", privateDataValue1);
imeSystemChannel_->systemCmdListener_ = nullptr;
imeSystemChannel_->OnConnectCmdReady(nullptr);
imeSystemChannel_->GetSmartMenuCfg();
int32_t ret = imeSystemChannel_->ReceivePrivateCommand(privateCommand);
EXPECT_EQ(ret, ErrorCode::ERROR_EX_NULL_POINTER);
ret = imeSystemChannel_->ShowSysPanel(true);
EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
}
} // namespace MiscServices
} // namespace OHOS

View File

@ -960,7 +960,6 @@ HWTEST_F(InputMethodAbilityTest, testNotifyPanelStatusInfo_005, TestSize.Level0)
HWTEST_F(InputMethodAbilityTest, testNotifyKeyboardHeight_001, TestSize.Level0)
{
IMSA_HILOGI("InputMethodAbility testNotifyKeyboardHeight_001 START");
TextListener::ResetParam();
imc_->Attach(textListener_);
AccessScope scope(currentImeTokenId_, currentImeUid_);
PanelInfo info = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
@ -968,6 +967,7 @@ HWTEST_F(InputMethodAbilityTest, testNotifyKeyboardHeight_001, TestSize.Level0)
auto ret = inputMethodAbility_->CreatePanel(nullptr, info, panel);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
panel->Resize(1, 1);
TextListener::ResetParam();
inputMethodAbility_->NotifyKeyboardHeight(panel);
EXPECT_TRUE(TextListener::WaitNotifyKeyboardHeightCallback(1));
@ -985,7 +985,6 @@ HWTEST_F(InputMethodAbilityTest, testNotifyKeyboardHeight_001, TestSize.Level0)
HWTEST_F(InputMethodAbilityTest, testNotifyKeyboardHeight_002, TestSize.Level0)
{
IMSA_HILOGI("InputMethodAbility testNotifyKeyboardHeight_002 START");
TextListener::ResetParam();
imc_->Attach(textListener_);
AccessScope scope(currentImeTokenId_, currentImeUid_);
PanelInfo info = { .panelType = STATUS_BAR, .panelFlag = FLG_FIXED };
@ -993,6 +992,7 @@ HWTEST_F(InputMethodAbilityTest, testNotifyKeyboardHeight_002, TestSize.Level0)
auto ret = inputMethodAbility_->CreatePanel(nullptr, info, panel);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
panel->Resize(1, 1);
TextListener::ResetParam();
inputMethodAbility_->NotifyKeyboardHeight(panel);
EXPECT_TRUE(TextListener::WaitNotifyKeyboardHeightCallback(0));
@ -1010,7 +1010,6 @@ HWTEST_F(InputMethodAbilityTest, testNotifyKeyboardHeight_002, TestSize.Level0)
HWTEST_F(InputMethodAbilityTest, testNotifyKeyboardHeight_003, TestSize.Level0)
{
IMSA_HILOGI("InputMethodAbility testNotifyKeyboardHeight_003 START");
TextListener::ResetParam();
imc_->Attach(textListener_);
AccessScope scope(currentImeTokenId_, currentImeUid_);
PanelInfo info = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_CANDIDATE_COLUMN };
@ -1019,8 +1018,8 @@ HWTEST_F(InputMethodAbilityTest, testNotifyKeyboardHeight_003, TestSize.Level0)
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
panel->Resize(1, 1);
inputMethodAbility_->NotifyKeyboardHeight(panel);
TextListener::ResetParam();
EXPECT_TRUE(TextListener::WaitNotifyKeyboardHeightCallback(0));
ret = inputMethodAbility_->DestroyPanel(panel);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
@ -1099,7 +1098,7 @@ HWTEST_F(InputMethodAbilityTest, testSendPrivateCommand_001, TestSize.Level0)
{
IMSA_HILOGI("InputMethodAbility testSendPrivateCommand_001 Test START");
TextListener::ResetParam();
imc_->Close();
InputMethodAbilityTest::GetIMCDetachIMA();
TddUtil::RestoreSelfTokenID();
std::unordered_map<std::string, PrivateDataValue> privateCommand;
auto ret = inputMethodAbility_->SendPrivateCommand(privateCommand);
@ -1116,7 +1115,7 @@ HWTEST_F(InputMethodAbilityTest, testSendPrivateCommand_001, TestSize.Level0)
HWTEST_F(InputMethodAbilityTest, testSendPrivateCommand_002, TestSize.Level0)
{
IMSA_HILOGI("InputMethodAbility testSendPrivateCommand_002 Test START");
TextListener::ResetParam();
InputMethodAbilityTest::GetIMCDetachIMA();
TokenScope tokenScope(InputMethodAbilityTest::defaultImeTokenId_);
std::unordered_map<std::string, PrivateDataValue> privateCommand;
PrivateDataValue privateDataValue1 = std::string("stringValue");
@ -1136,8 +1135,7 @@ HWTEST_F(InputMethodAbilityTest, testSendPrivateCommand_003, TestSize.Level0)
{
IMSA_HILOGI("InputMethodAbility testSendPrivateCommand_003 Test START");
TextListener::ResetParam();
auto ret = imc_->Attach(textListener_, false);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
InputMethodAbilityTest::GetIMCAttachIMA();
TokenScope tokenScope(InputMethodAbilityTest::defaultImeTokenId_);
std::unordered_map<std::string, PrivateDataValue> privateCommand;
PrivateDataValue privateDataValue1 = std::string("stringValue");
@ -1146,10 +1144,10 @@ HWTEST_F(InputMethodAbilityTest, testSendPrivateCommand_003, TestSize.Level0)
privateCommand.emplace("value1", privateDataValue1);
privateCommand.emplace("value2", privateDataValue2);
privateCommand.emplace("value3", privateDataValue3);
ret = inputMethodAbility_->SendPrivateCommand(privateCommand);
auto ret = inputMethodAbility_->SendPrivateCommand(privateCommand);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
EXPECT_TRUE(TextListener::WaitSendPrivateCommandCallback(privateCommand));
imc_->Close();
InputMethodAbilityTest::GetIMCDetachIMA();
}
/**

View File

@ -109,7 +109,7 @@ public:
void TearDown();
static void SetInputDeathRecipient();
static void OnRemoteSaDied(const wptr<IRemoteObject> &remote);
static bool CheckKeyEvent(std::shared_ptr<MMI::KeyEvent> keyEvent);
static void CheckKeyEvent(std::shared_ptr<MMI::KeyEvent> keyEvent);
static bool WaitRemoteDiedCallback();
static void WaitKeyboardStatusCallback(bool keyboardState);
static void TriggerConfigurationChangeCallback(Configuration &info);
@ -367,8 +367,9 @@ void InputMethodControllerTest::CheckProxyObject()
}
}
bool InputMethodControllerTest::CheckKeyEvent(std::shared_ptr<MMI::KeyEvent> keyEvent)
void InputMethodControllerTest::CheckKeyEvent(std::shared_ptr<MMI::KeyEvent> keyEvent)
{
ASSERT_NE(keyEvent, nullptr);
bool ret = keyEvent->GetKeyCode() == keyEvent_->GetKeyCode();
EXPECT_TRUE(ret);
ret = keyEvent->GetKeyAction() == keyEvent_->GetKeyAction();
@ -398,7 +399,6 @@ bool InputMethodControllerTest::CheckKeyEvent(std::shared_ptr<MMI::KeyEvent> key
EXPECT_TRUE(ret);
ret = keyEvent->GetKeyItem()->GetUnicode() == keyEvent_->GetKeyItem()->GetUnicode();
EXPECT_TRUE(ret);
return ret;
}
void InputMethodControllerTest::WaitKeyboardStatusCallback(bool keyboardState)
@ -552,7 +552,7 @@ HWTEST_F(InputMethodControllerTest, testIMCSetCallingWindow, TestSize.Level0)
HWTEST_F(InputMethodControllerTest, testGetIMSAProxy, TestSize.Level0)
{
auto systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
EXPECT_TRUE(systemAbilityManager != nullptr);
ASSERT_NE(systemAbilityManager, nullptr);
auto systemAbility = systemAbilityManager->GetSystemAbility(INPUT_METHOD_SYSTEM_ABILITY_ID, "");
EXPECT_TRUE(systemAbility != nullptr);
}
@ -637,8 +637,8 @@ HWTEST_F(InputMethodControllerTest, testIMCDispatchKeyEvent002, TestSize.Level0)
keyEvent_, [](std::shared_ptr<MMI::KeyEvent> &keyEvent, bool isConsumed) {});
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
auto keyEvent = blockFullKeyEvent_.GetValue();
EXPECT_NE(keyEvent, nullptr);
EXPECT_TRUE(CheckKeyEvent(keyEvent));
ASSERT_NE(keyEvent, nullptr);
CheckKeyEvent(keyEvent);
}
/**
@ -659,11 +659,11 @@ HWTEST_F(InputMethodControllerTest, testIMCDispatchKeyEvent003, TestSize.Level0)
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
auto keyEvent = blockKeyEvent_.GetValue();
auto keyFullEvent = blockFullKeyEvent_.GetValue();
EXPECT_NE(keyEvent, nullptr);
EXPECT_NE(keyFullEvent, nullptr);
ASSERT_NE(keyEvent, nullptr);
EXPECT_EQ(keyEvent->GetKeyCode(), keyEvent_->GetKeyCode());
EXPECT_EQ(keyEvent->GetKeyAction(), keyEvent_->GetKeyAction());
EXPECT_TRUE(CheckKeyEvent(keyFullEvent));
ASSERT_NE(keyFullEvent, nullptr);
CheckKeyEvent(keyFullEvent);
}
/**

View File

@ -363,8 +363,6 @@ void InputMethodPanelTest::ImcPanelShowInfoCheck(const InputWindowInfo &windowIn
IMSA_HILOGI("InputMethodPanelTest::name: %{public}s, ret:[%{public}d, %{public}d,%{public}d, %{public}d]",
windowInfo_.name.c_str(), windowInfo_.top, windowInfo_.left, windowInfo_.width, windowInfo_.height);
EXPECT_FALSE(windowInfo_.name.empty());
EXPECT_EQ(windowInfo_.width, windowInfo.width);
EXPECT_EQ(windowInfo_.height, windowInfo.height);
}
void InputMethodPanelTest::ImcPanelHideInfoCheck(const InputWindowInfo &windowInfo)
@ -376,8 +374,6 @@ void InputMethodPanelTest::ImcPanelHideInfoCheck(const InputWindowInfo &windowIn
IMSA_HILOGI("InputMethodPanelTest::name: %{public}s, ret:[%{public}d, %{public}d,%{public}d, %{public}d]",
windowInfo_.name.c_str(), windowInfo_.top, windowInfo_.left, windowInfo_.width, windowInfo_.height);
EXPECT_FALSE(windowInfo_.name.empty());
EXPECT_EQ(windowInfo_.width, windowInfo.width);
EXPECT_EQ(windowInfo_.height, windowInfo.height);
}
void InputMethodPanelTest::ImcPanelListeningTestRestore()
@ -465,7 +461,7 @@ HWTEST_F(InputMethodPanelTest, testResizePanel001, TestSize.Level0)
ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
EXPECT_TRUE(defaultDisplay != nullptr);
ASSERT_TRUE(defaultDisplay != nullptr);
int32_t width = defaultDisplay->GetWidth();
int32_t height = defaultDisplay->GetHeight();
@ -506,7 +502,7 @@ HWTEST_F(InputMethodPanelTest, testResizePanel002, TestSize.Level0)
ret = inputMethodPanel->CreatePanel(nullptr, panelInfo);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
EXPECT_TRUE(defaultDisplay != nullptr);
ASSERT_TRUE(defaultDisplay != nullptr);
int32_t width = defaultDisplay->GetWidth();
int32_t height = defaultDisplay->GetHeight();

View File

@ -592,7 +592,7 @@ HWTEST_F(InputMethodPrivateMemberTest, III_TestGetCurrentSubtype_001, TestSize.L
ImeCfgManager::GetInstance().imeConfigs_.push_back(
{ currentUserId, currentProp->name + "/" + currentProp->id, "tt" });
subProp = ImeInfoInquirer::GetInstance().GetCurrentSubtype(currentUserId);
EXPECT_TRUE(subProp != nullptr);
ASSERT_TRUE(subProp != nullptr);
EXPECT_TRUE(subProp->name == currentProp->name);
// get correct subProp

View File

@ -259,7 +259,7 @@ HWTEST_F(InputMethodSwitchTest, testSwitchImeWithErrorBundleName, TestSize.Level
IMSA_HILOGI("oldIme testSwitchImeWithErrorBundleName Test START");
std::string subName = InputMethodSwitchTest::imc_->GetCurrentInputMethodSubtype()->id;
int32_t ret = imc_->SwitchInputMethod(SwitchTrigger::CURRENT_IME, "error bundleName", extName[0]);
EXPECT_NE(ret, ErrorCode::NO_ERROR);
EXPECT_TRUE(ret == ErrorCode::ERROR_ENABLE_IME || ret == ErrorCode::ERROR_BAD_PARAMETERS);
CheckCurrentProp(subName);
CheckCurrentSubProp(subName);
CheckCurrentSubProps();
@ -277,7 +277,7 @@ HWTEST_F(InputMethodSwitchTest, testSwitchImeWithErrorBundleNameWitchEmptySubNam
IMSA_HILOGI("oldIme testSwitchImeWithErrorBundleNameWitchEmptySubName Test START");
std::string subName = InputMethodSwitchTest::imc_->GetCurrentInputMethodSubtype()->id;
int32_t ret = imc_->SwitchInputMethod(SwitchTrigger::CURRENT_IME, "error bundleName", " ");
EXPECT_NE(ret, ErrorCode::NO_ERROR);
EXPECT_TRUE(ret == ErrorCode::ERROR_ENABLE_IME || ret == ErrorCode::ERROR_BAD_PARAMETERS);
CheckCurrentProp(subName);
CheckCurrentSubProp(subName);
CheckCurrentSubProps();

View File

@ -0,0 +1,260 @@
/*
* Copyright (c) 2024 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 <gmock/gmock.h>
#include <gtest/gtest.h>
#include <string_ex.h>
#include <unistd.h>
#include "global.h"
#include "ime_event_listener.h"
#include "ime_setting_listener_test_impl.h"
#include "ime_system_channel.h"
#include "input_method_controller.h"
#include "input_method_engine_listener.h"
#include "input_method_utils.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace MiscServices {
/**
* @brief Only pure virtual functions are implemented.
*/
class TextListenerImpl : public OnTextChangedListener {
public:
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
{
return Str8ToStr16("test");
}
std::u16string GetRightTextOfCursor(int32_t number) override
{
return Str8ToStr16("test");
}
int32_t GetTextIndexAtCursor() override
{
return 0;
}
};
/**
* @brief Only pure virtual functions are implemented.
*/
class EngineListenerImpl : public InputMethodEngineListener {
public:
void OnKeyboardStatus(bool isShow) override
{
}
void OnInputStart() override
{
}
void OnInputStop() override
{
}
void OnSecurityChange(int32_t security) override
{
}
void OnSetCallingWindow(uint32_t windowId) override
{
}
void OnSetSubtype(const SubProperty &property) override
{
}
void ReceivePrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand) override
{
}
};
/**
* @brief Only pure virtual functions are implemented.
*/
class EventListenerImpl : public ImeEventListener {
};
/**
* @brief Only pure virtual functions are implemented.
*/
class SystemCmdChannelImpl : public OnSystemCmdListener {
};
class SystemCmdChannelListenerImpl : public OnSystemCmdListener {
public:
void ReceivePrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand) override
{
isReceivePrivateCommand_ = true;
}
void NotifyIsShowSysPanel(bool shouldSysPanelShow) override
{
isNotifyIsShowSysPanel_ = true;
}
static void ResetParam()
{
isReceivePrivateCommand_ = false;
isNotifyIsShowSysPanel_ = false;
}
static bool isReceivePrivateCommand_;
static bool isNotifyIsShowSysPanel_;
};
bool SystemCmdChannelListenerImpl::isReceivePrivateCommand_{ false };
bool SystemCmdChannelListenerImpl::isNotifyIsShowSysPanel_{ false };
class VirtualListenerTest : public testing::Test {
public:
static void SetUpTestCase(void)
{
IMSA_HILOGI("VirtualListenerTest::SetUpTestCase");
textListener_ = new (std::nothrow) TextListenerImpl();
eventListener_ = std::make_shared<EventListenerImpl>();
engineListener_ = std::make_shared<EngineListenerImpl>();
systemCmdListener_ = new (std::nothrow) SystemCmdChannelImpl();
}
static void TearDownTestCase(void)
{
IMSA_HILOGI("VirtualListenerTest::TearDownTestCase");
}
void SetUp()
{
IMSA_HILOGI("VirtualListenerTest::SetUp");
}
void TearDown()
{
IMSA_HILOGI("VirtualListenerTest::TearDown");
}
static sptr<OnTextChangedListener> textListener_;
static std::shared_ptr<ImeEventListener> eventListener_;
static std::shared_ptr<InputMethodEngineListener> engineListener_;
static sptr<OnSystemCmdListener> systemCmdListener_;
};
sptr<OnTextChangedListener> VirtualListenerTest::textListener_{ nullptr };
std::shared_ptr<ImeEventListener> VirtualListenerTest::eventListener_{ nullptr };
std::shared_ptr<InputMethodEngineListener> VirtualListenerTest::engineListener_{ nullptr };
sptr<OnSystemCmdListener> VirtualListenerTest::systemCmdListener_{ nullptr };
/**
* @tc.name: testOnTextChangedListener_001
* @tc.desc: Cover non-pure virtual function in class: OnTextChangedListener.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(VirtualListenerTest, testOnTextChangedListener_001, TestSize.Level0)
{
IMSA_HILOGI("VirtualListenerTest testOnTextChangedListener_001 START");
ASSERT_NE(VirtualListenerTest::textListener_, nullptr);
PanelStatusInfo statusInfo;
Range range;
std::unordered_map<std::string, PrivateDataValue> privateCommand;
VirtualListenerTest::textListener_->NotifyPanelStatusInfo(statusInfo);
VirtualListenerTest::textListener_->NotifyKeyboardHeight(0);
int32_t ret = VirtualListenerTest::textListener_->ReceivePrivateCommand(privateCommand);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
VirtualListenerTest::textListener_->FinishTextPreview();
ret = VirtualListenerTest::textListener_->SetPreviewText(Str8ToStr16("test"), range);
EXPECT_EQ(ret, ErrorCode::NO_ERROR);
}
/**
* @tc.name: testInputMethodEngineListener_001
* @tc.desc: Cover non-pure virtual function in class: InputMethodEngineListener.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(VirtualListenerTest, testInputMethodEngineListener_001, TestSize.Level0)
{
IMSA_HILOGI("VirtualListenerTest testInputMethodEngineListener_001 START");
ASSERT_NE(VirtualListenerTest::engineListener_, nullptr);
VirtualListenerTest::engineListener_->OnInputFinish();
bool isEnable = VirtualListenerTest::engineListener_->IsEnable();
EXPECT_FALSE(isEnable);
}
/**
* @tc.name: testImeEventListener_001
* @tc.desc: Cover non-pure virtual function in class: ImeEventListener.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(VirtualListenerTest, testImeEventListener_001, TestSize.Level0)
{
IMSA_HILOGI("VirtualListenerTest testImeEventListener_001 START");
ASSERT_NE(VirtualListenerTest::eventListener_, nullptr);
Property property;
SubProperty subProperty;
ImeWindowInfo imeWindowInfo;
auto listener = std::make_shared<ImeSettingListenerTestImpl>();
ImeSettingListenerTestImpl::ResetParam();
VirtualListenerTest::eventListener_->OnImeChange(property, subProperty);
VirtualListenerTest::eventListener_->OnImeShow(imeWindowInfo);
VirtualListenerTest::eventListener_->OnImeHide(imeWindowInfo);
EXPECT_FALSE(ImeSettingListenerTestImpl::WaitImeChange());
EXPECT_FALSE(ImeSettingListenerTestImpl::WaitPanelHide());
EXPECT_FALSE(ImeSettingListenerTestImpl::WaitPanelHide());
}
/**
* @tc.name: testOnSystemCmdListener_001
* @tc.desc: Cover non-pure virtual function in class: OnSystemCmdListener.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(VirtualListenerTest, testOnSystemCmdListener_001, TestSize.Level0)
{
IMSA_HILOGI("VirtualListenerTest testOnSystemCmdListener_001 START");
sptr<OnSystemCmdListener> listener = new (std::nothrow) SystemCmdChannelListenerImpl();
ASSERT_NE(listener, nullptr);
ASSERT_NE(VirtualListenerTest::systemCmdListener_, nullptr);
SystemCmdChannelListenerImpl::ResetParam();
std::unordered_map<std::string, PrivateDataValue> privateCommand;
VirtualListenerTest::systemCmdListener_->ReceivePrivateCommand(privateCommand);
VirtualListenerTest::systemCmdListener_->NotifyIsShowSysPanel(false);
EXPECT_FALSE(SystemCmdChannelListenerImpl::isNotifyIsShowSysPanel_);
EXPECT_FALSE(SystemCmdChannelListenerImpl::isReceivePrivateCommand_);
SystemCmdChannelListenerImpl::ResetParam();
listener->ReceivePrivateCommand(privateCommand);
listener->NotifyIsShowSysPanel(false);
EXPECT_TRUE(SystemCmdChannelListenerImpl::isNotifyIsShowSysPanel_);
EXPECT_TRUE(SystemCmdChannelListenerImpl::isReceivePrivateCommand_);
}
} // namespace MiscServices
} // namespace OHOS