mirror of
https://github.com/openharmony/distributedhardware_distributed_input.git
synced 2026-07-19 17:43:35 -04:00
Description:add ut
Match-id-824bbc46f87c667fb1f8f9a2be692a0786ba8715
This commit is contained in:
+2
-1
@@ -88,7 +88,8 @@
|
||||
"//foundation/distributedhardware/distributed_input/services/sink/sinkmanager/test:test",
|
||||
"//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/interfaces/ipc/test:test",
|
||||
"//foundation/distributedhardware/distributed_input/inputdevicehandler/test:test"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ ohos_unittest("distributed_input_dfx_test") {
|
||||
|
||||
sources = [
|
||||
"${dfx_utils_path}/src/hidumper.cpp",
|
||||
"${dfx_utils_path}/src/hisysevent_util.cpp",
|
||||
"distributed_input_dfx_test.cpp",
|
||||
]
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "dinput_errcode.h"
|
||||
#include "hidumper.h"
|
||||
#include "hisysevent_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
@@ -77,14 +78,22 @@ HWTEST_F(DInputDfxUtilsTest, GetAllNodeInfos_001, testing::ext::TestSize.Level1)
|
||||
std::string dhId = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8";
|
||||
std::string nodeName = "DistributedInput_123456";
|
||||
HiDumper::GetInstance().SaveNodeInfo(devId, nodeName, dhId);
|
||||
EXPECT_EQ(1, HiDumper::GetInstance().nodeInfos_.size());
|
||||
std::string dhId1 = "dhId1_test";
|
||||
HiDumper::GetInstance().SaveNodeInfo(devId, nodeName, dhId1);
|
||||
EXPECT_EQ(2, HiDumper::GetInstance().nodeInfos_.size());
|
||||
|
||||
std::string result = "";
|
||||
int32_t ret = HiDumper::GetInstance().GetAllNodeInfos(result);
|
||||
EXPECT_EQ(DH_SUCCESS, ret);
|
||||
|
||||
HiDumper::GetInstance().DeleteNodeInfo(devId, dhId1);
|
||||
HiDumper::GetInstance().DeleteNodeInfo(devId, dhId);
|
||||
EXPECT_EQ(0, HiDumper::GetInstance().nodeInfos_.size());
|
||||
std::string status = "status_ok";
|
||||
std::string msg = "msg_test";
|
||||
HisyseventUtil::GetInstance().SysEventWriteBehavior(status, msg);
|
||||
HisyseventUtil::GetInstance().SysEventWriteBehavior(status, devId, msg);
|
||||
HisyseventUtil::GetInstance().SysEventWriteBehavior(status, devId, dhId, msg);
|
||||
}
|
||||
|
||||
HWTEST_F(DInputDfxUtilsTest, GetSessionInfo_001, testing::ext::TestSize.Level1)
|
||||
@@ -100,7 +109,12 @@ HWTEST_F(DInputDfxUtilsTest, GetSessionInfo_001, testing::ext::TestSize.Level1)
|
||||
EXPECT_EQ(1, HiDumper::GetInstance().sessionInfos_.size());
|
||||
|
||||
sessionStatus = SessionStatus::CLOSED;
|
||||
HiDumper::GetInstance().CreateSessionInfo(remoteDevId, sessionId, mySessionName, peerSessionName, sessionStatus);
|
||||
EXPECT_EQ(1, HiDumper::GetInstance().sessionInfos_.size());
|
||||
|
||||
sessionStatus = SessionStatus::CLOSING;
|
||||
HiDumper::GetInstance().SetSessionStatus(remoteDevId1, sessionStatus);
|
||||
HiDumper::GetInstance().SetSessionStatus(remoteDevId, sessionStatus);
|
||||
|
||||
|
||||
HiDumper::GetInstance().DeleteSessionInfo(remoteDevId);
|
||||
@@ -110,6 +124,13 @@ HWTEST_F(DInputDfxUtilsTest, GetSessionInfo_001, testing::ext::TestSize.Level1)
|
||||
|
||||
int32_t ret = HiDumper::GetInstance().GetSessionInfo(result);
|
||||
EXPECT_EQ(DH_SUCCESS, ret);
|
||||
std::string status = "status_ok";
|
||||
std::string msg = "msg_test";
|
||||
int32_t errorCode = 1;
|
||||
std::string dhId = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8";
|
||||
HisyseventUtil::GetInstance().SysEventWriteFault(status, msg);
|
||||
HisyseventUtil::GetInstance().SysEventWriteFault(status, remoteDevId, errorCode, msg);
|
||||
HisyseventUtil::GetInstance().SysEventWriteFault(status, remoteDevId, dhId, errorCode, msg);
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# Copyright (c) 2022 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 = [ "inputhandlertest:inputhandlertest" ]
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
# Copyright (c) 2022 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(
|
||||
"//foundation/distributedhardware/distributed_input/distributedinput.gni")
|
||||
module_out_path = "distributed_input/input_handler"
|
||||
|
||||
group("inputhandlertest") {
|
||||
testonly = true
|
||||
|
||||
deps = [ ":distributed_input_handler_test" ]
|
||||
}
|
||||
|
||||
## HandlerTest distributed_input_handler_test {{{
|
||||
ohos_unittest("distributed_input_handler_test") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
include_dirs = [
|
||||
"${common_path}/include",
|
||||
"//commonlibrary/c_utils/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
"${fwk_common_path}/log/include",
|
||||
"${fwk_common_path}/utils/include",
|
||||
"${fwk_utils_path}/include/log",
|
||||
"${fwk_utils_path}/include",
|
||||
"${service_common}/include",
|
||||
"${frameworks_path}/include",
|
||||
"${utils_path}/include",
|
||||
"//third_party/json/include",
|
||||
"${fwk_interfaces_path}/include",
|
||||
"${fwk_interfaces_path}/include/ipc",
|
||||
"//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk",
|
||||
"//foundation/communication/ipc/interfaces/innerkits/ipc_core/include",
|
||||
"//foundation/systemabilitymgr/samgr/interfaces/innerkits/samgr_proxy/include",
|
||||
"//foundation/distributedhardware/distributed_input/inputdevicehandler/include",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"${common_path}/include/input_hub.cpp",
|
||||
"//foundation/distributedhardware/distributed_input/inputdevicehandler/src/distributed_input_handler.cpp",
|
||||
"distributed_input_handler_test.cpp",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
"-Dprivate=public",
|
||||
"-Dprotected=public",
|
||||
]
|
||||
|
||||
defines = [
|
||||
"HI_LOG_ENABLE",
|
||||
"DH_LOG_TAG=\"distributedinpututtest\"",
|
||||
"LOG_DOMAIN=0xD004100",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${fwk_utils_path}:distributedhardwareutils",
|
||||
"${utils_path}:libdinput_utils",
|
||||
"//third_party/openssl:libcrypto_static",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"dsoftbus:softbus_client",
|
||||
]
|
||||
|
||||
cflags_cc = [ "-DHILOG_ENABLE" ]
|
||||
}
|
||||
## UnitTest distributed_input_handler_test }}}
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 "distributed_input_handler_test.h"
|
||||
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
#include "dinput_errcode.h"
|
||||
#include "distributed_input_handler.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
void DInputHandlerTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void DInputHandlerTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
void DInputHandlerTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void DInputHandlerTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
HWTEST_F(DInputHandlerTest, QueryExtraInfo_001, testing::ext::TestSize.Level1)
|
||||
{
|
||||
DistributedInputHandler dInputHandler;
|
||||
uint32_t inputTypes = static_cast<uint32_t>(DInputDeviceType::ALL);
|
||||
std::map<int32_t, std::string> datas;
|
||||
std::vector<std::string> dhidsVec;
|
||||
dInputHandler.FindDevicesInfoByType(inputTypes, datas);
|
||||
dInputHandler.FindDevicesInfoByDhId(dhidsVec, datas);
|
||||
std::map<std::string, std::string> ret = dInputHandler.QueryExtraInfo();
|
||||
EXPECT_EQ(0, ret.size());
|
||||
}
|
||||
|
||||
HWTEST_F(DInputHandlerTest, FindDevicesInfoByType_001, testing::ext::TestSize.Level1)
|
||||
{
|
||||
DistributedInputHandler dInputHandler;
|
||||
dInputHandler.inputHub_ = nullptr;
|
||||
uint32_t inputTypes = static_cast<uint32_t>(DInputDeviceType::ALL);
|
||||
std::map<int32_t, std::string> datas;
|
||||
std::vector<std::string> dhidsVec;
|
||||
std::string deviceId = "deviceId_test";
|
||||
dInputHandler.FindDevicesInfoByType(inputTypes, datas);
|
||||
dInputHandler.FindDevicesInfoByDhId(dhidsVec, datas);
|
||||
dInputHandler.Query();
|
||||
dInputHandler.StartInputMonitorDeviceThread(deviceId);
|
||||
|
||||
InputDevice inputDevice;
|
||||
dInputHandler.mEventBuffer[0].type = DeviceType::DEVICE_ADDED;
|
||||
dInputHandler.mEventBuffer[0].deviceInfo = inputDevice;
|
||||
dInputHandler.NotifyHardWare(0);
|
||||
dInputHandler.mEventBuffer[1].type = DeviceType::DEVICE_REMOVED;
|
||||
dInputHandler.mEventBuffer[1].deviceInfo = inputDevice;
|
||||
dInputHandler.NotifyHardWare(1);
|
||||
dInputHandler.mEventBuffer[2].type = DeviceType::FINISHED_DEVICE_SCAN;
|
||||
dInputHandler.mEventBuffer[2].deviceInfo = inputDevice;
|
||||
dInputHandler.NotifyHardWare(2);
|
||||
std::map<std::string, std::string> ret = dInputHandler.QueryExtraInfo();
|
||||
EXPECT_EQ(0, ret.size());
|
||||
dInputHandler.inputHub_ = std::make_unique<InputHub>();
|
||||
dInputHandler.StartInputMonitorDeviceThread(deviceId);
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 DISRIBUTED_INPUT_HANDLER_TEST_H
|
||||
#define DISRIBUTED_INPUT_HANDLER_TEST_H
|
||||
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <refbase.h>
|
||||
#include <thread>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
#include "constants_dinput.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedHardware {
|
||||
namespace DistributedInput {
|
||||
class DInputHandlerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp() override;
|
||||
void TearDown() override;
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // DISRIBUTED_INPUT_HANDLER_TEST_H
|
||||
+9
@@ -100,8 +100,17 @@ HWTEST_F(DistributedInputCollectorTest, SetSharingTypes01, testing::ext::TestSiz
|
||||
DistributedInputCollector::GetInstance().inputHub_ = std::make_unique<InputHub>();
|
||||
bool enabled = true;
|
||||
uint32_t inputType = static_cast<uint32_t>(DInputDeviceType::ALL);
|
||||
|
||||
AffectDhIds ret = DistributedInputCollector::GetInstance().SetSharingTypes(enabled, inputType);
|
||||
EXPECT_EQ(0, ret.sharingDhIds.size());
|
||||
std::vector<std::string> sharingDhIds;
|
||||
sharingDhIds.push_back("sharingDhId_test");
|
||||
std::vector<std::string> noSharingDhIds;
|
||||
noSharingDhIds.push_back("noSharingDhId_test");
|
||||
AffectDhIds affectDhIds {sharingDhIds, noSharingDhIds};
|
||||
DistributedInputCollector::GetInstance().ReportDhIdSharingState(affectDhIds);
|
||||
DistributedInputCollector::GetInstance().sharingDhIdListeners_.clear();
|
||||
DistributedInputCollector::GetInstance().ReportDhIdSharingState(affectDhIds);
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
|
||||
Reference in New Issue
Block a user