diff --git a/bundle.json b/bundle.json index a4dd889..ab96f72 100755 --- a/bundle.json +++ b/bundle.json @@ -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" ] } } diff --git a/dfx_utils/test/dfxtest/BUILD.gn b/dfx_utils/test/dfxtest/BUILD.gn index 2a831e9..b1f25f0 100644 --- a/dfx_utils/test/dfxtest/BUILD.gn +++ b/dfx_utils/test/dfxtest/BUILD.gn @@ -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", ] diff --git a/dfx_utils/test/dfxtest/distributed_input_dfx_test.cpp b/dfx_utils/test/dfxtest/distributed_input_dfx_test.cpp index b7c41e3..a218f4d 100644 --- a/dfx_utils/test/dfxtest/distributed_input_dfx_test.cpp +++ b/dfx_utils/test/dfxtest/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 diff --git a/inputdevicehandler/test/BUILD.gn b/inputdevicehandler/test/BUILD.gn new file mode 100644 index 0000000..8fb7623 --- /dev/null +++ b/inputdevicehandler/test/BUILD.gn @@ -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" ] +} \ No newline at end of file diff --git a/inputdevicehandler/test/inputhandlertest/BUILD.gn b/inputdevicehandler/test/inputhandlertest/BUILD.gn new file mode 100644 index 0000000..cb9955d --- /dev/null +++ b/inputdevicehandler/test/inputhandlertest/BUILD.gn @@ -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 }}} \ No newline at end of file diff --git a/inputdevicehandler/test/inputhandlertest/distributed_input_handler_test.cpp b/inputdevicehandler/test/inputhandlertest/distributed_input_handler_test.cpp new file mode 100644 index 0000000..979a5cd --- /dev/null +++ b/inputdevicehandler/test/inputhandlertest/distributed_input_handler_test.cpp @@ -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(DInputDeviceType::ALL); + std::map datas; + std::vector dhidsVec; + dInputHandler.FindDevicesInfoByType(inputTypes, datas); + dInputHandler.FindDevicesInfoByDhId(dhidsVec, datas); + std::map 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(DInputDeviceType::ALL); + std::map datas; + std::vector 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 ret = dInputHandler.QueryExtraInfo(); + EXPECT_EQ(0, ret.size()); + dInputHandler.inputHub_ = std::make_unique(); + dInputHandler.StartInputMonitorDeviceThread(deviceId); +} +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/inputdevicehandler/test/inputhandlertest/distributed_input_handler_test.h b/inputdevicehandler/test/inputhandlertest/distributed_input_handler_test.h new file mode 100644 index 0000000..972e03b --- /dev/null +++ b/inputdevicehandler/test/inputhandlertest/distributed_input_handler_test.h @@ -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 +#include +#include +#include + +#include +#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 \ No newline at end of file diff --git a/services/sink/inputcollector/test/sinkcollectorunittest/distributed_input_collector_test.cpp b/services/sink/inputcollector/test/sinkcollectorunittest/distributed_input_collector_test.cpp index 3e72272..6568284 100644 --- a/services/sink/inputcollector/test/sinkcollectorunittest/distributed_input_collector_test.cpp +++ b/services/sink/inputcollector/test/sinkcollectorunittest/distributed_input_collector_test.cpp @@ -100,8 +100,17 @@ HWTEST_F(DistributedInputCollectorTest, SetSharingTypes01, testing::ext::TestSiz DistributedInputCollector::GetInstance().inputHub_ = std::make_unique(); bool enabled = true; uint32_t inputType = static_cast(DInputDeviceType::ALL); + AffectDhIds ret = DistributedInputCollector::GetInstance().SetSharingTypes(enabled, inputType); EXPECT_EQ(0, ret.sharingDhIds.size()); + std::vector sharingDhIds; + sharingDhIds.push_back("sharingDhId_test"); + std::vector 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