Signed-off-by: li-tiangang4 <litiangang4@huawei.com>
This commit is contained in:
li-tiangang4
2024-01-24 10:53:47 +08:00
parent 537beb19cd
commit c35ac09144
9 changed files with 385 additions and 6 deletions
+2 -1
View File
@@ -97,7 +97,8 @@
"//foundation/distributedhardware/distributed_input/utils/test:test",
"//foundation/distributedhardware/distributed_input/dfx_utils/test:test",
"//foundation/distributedhardware/distributed_input/interfaces/ipc/test:test",
"//foundation/distributedhardware/distributed_input/inputdevicehandler/test:test"
"//foundation/distributedhardware/distributed_input/inputdevicehandler/test:test",
"//foundation/distributedhardware/distributed_input/services/state/test:test"
]
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@@ -68,6 +68,13 @@ void DistributedInputSourceInjectTest::TestInputNodeListener::OnNodeOffLine(cons
(void)sinkNodeId;
}
void DistributedInputSourceInjectTest::TestRegisterSessionStateCallbackStub::OnResult(const std::string &devId,
const uint32_t status)
{
(void)devId;
(void)status;
}
HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedHardware01, testing::ext::TestSize.Level1)
{
InputDevice pBuffer;
@@ -405,6 +412,53 @@ HWTEST_F(DistributedInputSourceInjectTest, OpenDevicesNode_002, testing::ext::Te
ret = DistributedInputInject::GetInstance().inputNodeManager_->OpenDevicesNode(devId, dhIdtest, param);
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_OPEN_DEVICE_NODE_FAIL, ret);
}
HWTEST_F(DistributedInputSourceInjectTest, RegisterInjectEventCb_001, testing::ext::TestSize.Level1)
{
sptr<ISessionStateCallback> callback = nullptr;
auto ret = DistributedInputInject::GetInstance().RegisterInjectEventCb(callback);
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_INJECT_EVENT_CB_IS_NULL, ret);
}
HWTEST_F(DistributedInputSourceInjectTest, RegisterInjectEventCb_002, testing::ext::TestSize.Level1)
{
sptr<TestRegisterSessionStateCallbackStub> callback(new TestRegisterSessionStateCallbackStub());
auto ret = DistributedInputInject::GetInstance().RegisterInjectEventCb(callback);
EXPECT_EQ(DH_SUCCESS, ret);
}
HWTEST_F(DistributedInputSourceInjectTest, GetVirtualKeyboardPaths_001, testing::ext::TestSize.Level1)
{
std::string devId;
std::vector<std::string> dhIds;
std::vector<std::string> virKeyboardPaths;
DistributedInputInject::GetInstance().inputNodeManager_ = nullptr;
DistributedInputInject::GetInstance().GetVirtualKeyboardPaths(devId, dhIds, virKeyboardPaths);
std::string dhId;
DistributedInputInject::GetInstance().NotifyNodeMgrScanVirNode(devId, dhId);
DistributedInputInject::GetInstance().inputNodeManager_ = std::make_unique<DistributedInputNodeManager>();
DistributedInputInject::GetInstance().NotifyNodeMgrScanVirNode(devId, dhId);
auto ret = DistributedInputInject::GetInstance().UnregisterInjectEventCb();
EXPECT_EQ(DH_SUCCESS, ret);
}
HWTEST_F(DistributedInputSourceInjectTest, MatchAndSavePhysicalPath_001, testing::ext::TestSize.Level1)
{
std::string devicePath = "";
std::string devId = "";
std::string dhId = "";
auto ret =
DistributedInputInject::GetInstance().inputNodeManager_->MatchAndSavePhysicalPath(devicePath, devId, dhId);
EXPECT_EQ(false, ret);
DistributedInputInject::GetInstance().inputNodeManager_->isInjectThreadCreated_.store(true);
DistributedInputInject::GetInstance().inputNodeManager_->StartInjectThread();
DistributedInputInject::GetInstance().inputNodeManager_->isInjectThreadCreated_.store(false);
DistributedInputInject::GetInstance().inputNodeManager_->StopInjectThread();
}
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-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
@@ -27,6 +27,7 @@
#include "distributed_input_inject.h"
#include "distributed_input_node_manager.h"
#include "input_node_listener_stub.h"
#include "register_session_state_callback_stub.h"
namespace OHOS {
namespace DistributedHardware {
@@ -45,6 +46,14 @@ public:
const std::string sinkNodeDesc);
void OnNodeOffLine(const std::string srcDevId, const std::string sinkDevId, const std::string sinkNodeId);
};
class TestRegisterSessionStateCallbackStub :
public OHOS::DistributedHardware::DistributedInput::RegisterSessionStateCallbackStub {
public:
TestRegisterSessionStateCallbackStub() = default;
virtual ~TestRegisterSessionStateCallbackStub() = default;
void OnResult(const std::string &devId, const uint32_t status);
};
private:
sptr<TestInputNodeListener> inputNodelistener_;
};
+18
View File
@@ -0,0 +1,18 @@
# 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.
group("test") {
testonly = true
deps = [ "dinpusinkstatetest:dinpusinkstatetest" ]
}
@@ -0,0 +1,59 @@
# 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.
import("//build/test.gni")
import("../../../../distributedinput.gni")
module_out_path = "distributed_input/state"
group("dinpusinkstatetest") {
testonly = true
deps = [ ":dinput_sink_state_test" ]
}
## UnitTest dinput_sink_state_test {{{
ohos_unittest("dinput_sink_state_test") {
module_out_path = module_out_path
include_dirs = [
"${common_path}/include",
"${fwk_common_path}/utils/include",
"${services_state_path}/include",
]
sources = [ "dinput_sink_state_test.cpp" ]
cflags = [
"-Wall",
"-Werror",
"-g3",
"-Dprivate=public",
]
defines = [
"HI_LOG_ENABLE",
"DH_LOG_TAG=\"distributedinpututtest\"",
"LOG_DOMAIN=0xD004100",
]
deps = [
"${services_state_path}:libdinput_sink_state",
"//third_party/libevdev:libevdev",
]
external_deps = [ "c_utils:utils" ]
cflags_cc = [ "-DHILOG_ENABLE" ]
}
## UnitTest dinput_sink_state_test }}}
@@ -0,0 +1,176 @@
/*
* 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 <gtest/gtest.h>
#include <string>
#include "constants_dinput.h"
#include "dinput_sink_state.h"
#include "dinput_errcode.h"
#include "touchpad_event_fragment_mgr.h"
using namespace testing::ext;
namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
using namespace std;
namespace {
const std::string DHID_1 = "input_159753qazplm";
RawEvent EVENT_1 = {
.when = 0,
.type = EV_KEY,
.code = KEY_D,
.value = 1,
.descriptor = DHID_1
};
RawEvent EVENT_2 = {
.when = 1,
.type = EV_ABS,
.code = KEY_D,
.value = 0,
.descriptor = DHID_1
};
RawEvent EVENT_3 = {
.when = 1,
.type = EV_ABS,
.code = ABS_X,
.value = 0,
.descriptor = DHID_1
};
}
class DinputSinkStateTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void DinputSinkStateTest::SetUpTestCase()
{
}
void DinputSinkStateTest::TearDownTestCase()
{
}
void DinputSinkStateTest::SetUp()
{
}
void DinputSinkStateTest::TearDown()
{
}
HWTEST_F(DinputSinkStateTest, RecordDhIds_001, testing::ext::TestSize.Level0)
{
std::vector<std::string> dhIds;
dhIds.push_back(DHID_1);
DhIdState state = DhIdState::THROUGH_IN;
int32_t sessionId = 1;
int32_t ret = DInputSinkState::GetInstance().RecordDhIds(dhIds, state, sessionId);
EXPECT_EQ(DH_SUCCESS, ret);
}
HWTEST_F(DinputSinkStateTest, RecordDhIds_002, testing::ext::TestSize.Level0)
{
std::vector<std::string> dhIds;
dhIds.push_back(DHID_1);
DhIdState state = DhIdState::THROUGH_OUT;
int32_t sessionId = -1;
DInputSinkState::GetInstance().dhIdStateMap_.clear();
int32_t ret = DInputSinkState::GetInstance().RecordDhIds(dhIds, state, sessionId);
EXPECT_EQ(DH_SUCCESS, ret);
}
HWTEST_F(DinputSinkStateTest, RemoveDhIds_001, testing::ext::TestSize.Level0)
{
std::vector<std::string> dhIds;
dhIds.push_back(DHID_1);
int32_t ret = DInputSinkState::GetInstance().RemoveDhIds(dhIds);
EXPECT_EQ(DH_SUCCESS, ret);
}
HWTEST_F(DinputSinkStateTest, GetStateByDhid_001, testing::ext::TestSize.Level0)
{
DInputSinkState::GetInstance().dhIdStateMap_[DHID_1] = DhIdState::THROUGH_OUT;
DhIdState ret = DInputSinkState::GetInstance().GetStateByDhid(DHID_1);
EXPECT_EQ(DhIdState::THROUGH_OUT, ret);
}
HWTEST_F(DinputSinkStateTest, GetStateByDhid_002, testing::ext::TestSize.Level0)
{
std::string dhId = "dhId_test";
DhIdState ret = DInputSinkState::GetInstance().GetStateByDhid(dhId);
EXPECT_EQ(DhIdState::THROUGH_IN, ret);
}
HWTEST_F(DinputSinkStateTest, SimulateEventInjectToSrc_001, testing::ext::TestSize.Level0)
{
int32_t sessionId = 1;
std::string dhId = "dhId_test";
std::vector<std::string> dhIds;
dhIds.push_back(dhId);
DInputSinkState::GetInstance().Init();
DInputSinkState::GetInstance().AddKeyDownState(EVENT_1);
DInputSinkState::GetInstance().SimulateEventInjectToSrc(sessionId, dhIds);
dhIds.clear();
dhIds.push_back(DHID_1);
DInputSinkState::GetInstance().SimulateEventInjectToSrc(sessionId, dhIds);
EXPECT_EQ(DInputSinkState::GetInstance().keyDownStateMap_.size(), 0);
}
HWTEST_F(DinputSinkStateTest, RemoveKeyDownState_001, testing::ext::TestSize.Level0)
{
DInputSinkState::GetInstance().keyDownStateMap_.clear();
std::string dhId = "dhId_test";
std::vector<std::string> dhIds;
dhIds.push_back(dhId);
DInputSinkState::GetInstance().AddKeyDownState(EVENT_1);
DInputSinkState::GetInstance().RemoveKeyDownState(EVENT_1);
dhIds.clear();
dhIds.push_back(DHID_1);
DInputSinkState::GetInstance().RemoveKeyDownState(EVENT_1);
EXPECT_EQ(DInputSinkState::GetInstance().keyDownStateMap_.size(), 0);
}
HWTEST_F(DinputSinkStateTest, IsPositionEvent_001, testing::ext::TestSize.Level0)
{
DInputSinkState::GetInstance().Init();
auto ret = DInputSinkState::GetInstance().GetTouchPadEventFragMgr()->IsPositionEvent(EVENT_2);
EXPECT_EQ(false, ret);
}
HWTEST_F(DinputSinkStateTest, PushEvent_001, testing::ext::TestSize.Level0)
{
auto ret = DInputSinkState::GetInstance().GetTouchPadEventFragMgr()->PushEvent(DHID_1, EVENT_1);
EXPECT_EQ(false, ret.first);
ret = DInputSinkState::GetInstance().GetTouchPadEventFragMgr()->PushEvent(DHID_1, EVENT_3);
EXPECT_EQ(false, ret.first);
}
HWTEST_F(DinputSinkStateTest, GetAndClearEvents_001, testing::ext::TestSize.Level0)
{
std::string dhId = "dhId_test";
auto ret = DInputSinkState::GetInstance().GetTouchPadEventFragMgr()->GetAndClearEvents(dhId);
EXPECT_EQ(0, ret.size());
}
}
}
}
@@ -1,4 +1,4 @@
# Copyright (c) 2022-2023 Huawei Device Co., Ltd.
# Copyright (c) 2022-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
@@ -45,6 +45,7 @@ ohos_unittest("distributed_input_transbase_test") {
"${distributedinput_path}/inputdevicehandler/include",
"${distributedinput_path}/services/state/include",
"${common_path}/test/mock",
"${ipc_path}/include",
]
sources = [
@@ -73,6 +74,7 @@ ohos_unittest("distributed_input_transbase_test") {
deps = [
"${dfx_utils_path}:libdinput_dfx_utils",
"${innerkits_path}:libdinput_sdk",
"${services_source_path}/inputinject:libdinput_inject",
"${utils_path}:libdinput_utils",
"//third_party/libevdev:libevdev",
@@ -84,6 +86,7 @@ ohos_unittest("distributed_input_transbase_test") {
"eventhandler:libeventhandler",
"hicollie:libhicollie",
"hitrace:hitrace_meter",
"ipc:ipc_core",
]
cflags_cc = [ "-DHILOG_ENABLE" ]
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@@ -55,6 +55,13 @@ void DistributedInputTransbaseTest::TearDownTestCase()
{
}
void DistributedInputTransbaseTest::TestRegisterSessionStateCallbackStub::OnResult(const std::string &devId,
const uint32_t status)
{
(void)devId;
(void)status;
}
HWTEST_F(DistributedInputTransbaseTest, Init01, testing::ext::TestSize.Level0)
{
int32_t ret = DistributedInputTransportBase::GetInstance().Init();
@@ -177,6 +184,49 @@ HWTEST_F(DistributedInputTransbaseTest, Release01, testing::ext::TestSize.Level1
EXPECT_EQ(0, DistributedInputTransportBase::GetInstance().channelStatusMap_.size());
}
HWTEST_F(DistributedInputTransbaseTest, StopSession_001, testing::ext::TestSize.Level1)
{
DistributedInputTransportBase::GetInstance().remoteDevSessionMap_.clear();
std::string remoteDevId = "remoteDevId_test";
DistributedInputTransportBase::GetInstance().StopSession(remoteDevId);
EXPECT_EQ(0, DistributedInputTransportBase::GetInstance().remoteDevSessionMap_.size());
}
HWTEST_F(DistributedInputTransbaseTest, RunSessionStateCallback_001, testing::ext::TestSize.Level1)
{
std::string remoteDevId = "remoteDevId_test";
uint32_t sessionState = 1;
sptr<TestRegisterSessionStateCallbackStub> callback(new TestRegisterSessionStateCallbackStub());
DistributedInputTransportBase::GetInstance().RegisterSessionStateCb(callback);
DistributedInputTransportBase::GetInstance().RunSessionStateCallback(remoteDevId, sessionState);
DistributedInputTransportBase::GetInstance().UnregisterSessionStateCb();
auto ret = DistributedInputTransportBase::GetInstance().CountSession(remoteDevId);
EXPECT_EQ(DH_SUCCESS, ret);
}
HWTEST_F(DistributedInputTransbaseTest, OnSessionClosed_001, testing::ext::TestSize.Level1)
{
int32_t sessionId = 1;
std::string devId = "devId_741258";
ShutdownReason reason = ShutdownReason::SHUTDOWN_REASON_UNKNOWN;
DistributedInputTransportBase::GetInstance().OnSessionClosed(sessionId, reason);
DistributedInputTransportBase::GetInstance().remoteDevSessionMap_[devId] = sessionId;
DistributedInputTransportBase::GetInstance().OnSessionClosed(sessionId, reason);
DistributedInputTransportBase::GetInstance().sinkCallback_ = std::shared_ptr<DInputTransbaseSinkCallback>();
DistributedInputTransportBase::GetInstance().OnSessionClosed(sessionId, reason);
DistributedInputTransportBase::GetInstance().srcCallback_ = std::shared_ptr<DInputTransbaseSourceCallback>();
DistributedInputTransportBase::GetInstance().OnSessionClosed(sessionId, reason);
DistributedInputTransportBase::GetInstance().srcMgrCallback_ = std::shared_ptr<DInputSourceManagerCallback>();
DistributedInputTransportBase::GetInstance().OnSessionClosed(sessionId, reason);
auto ret = DistributedInputTransportBase::GetInstance().CountSession(devId);
EXPECT_EQ(DH_SUCCESS, ret);
}
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-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
@@ -29,6 +29,7 @@
#include "distributed_input_transport_base.h"
#include "dinput_transbase_source_callback.h"
#include "dinput_transbase_sink_callback.h"
#include "register_session_state_callback_stub.h"
namespace OHOS {
namespace DistributedHardware {
@@ -40,6 +41,14 @@ public:
void SetUp() override;
void TearDown() override;
class TestRegisterSessionStateCallbackStub :
public OHOS::DistributedHardware::DistributedInput::RegisterSessionStateCallbackStub {
public:
TestRegisterSessionStateCallbackStub() = default;
virtual ~TestRegisterSessionStateCallbackStub() = default;
void OnResult(const std::string &devId, const uint32_t status);
};
private:
DistributedInputSourceTransport* sourceTransport_;
std::shared_ptr<DistributedInputSourceTransport::DInputTransbaseSourceListener> statusSourceListener_;