diff --git a/interfaces/ipc/test/BUILD.gn b/interfaces/ipc/test/BUILD.gn index 6a568bb..4989524 100644 --- a/interfaces/ipc/test/BUILD.gn +++ b/interfaces/ipc/test/BUILD.gn @@ -19,6 +19,8 @@ group("test") { "addwhitelistinfoscallbackunittest:addwhitelistinfoscallbackunittest", "delwhitelistinfoscallbackunittest:delwhitelistinfoscallbackunittest", "unpreparedinputcallbackunittest:unpreparedinputcallbackunittest", - "unregisterdinputcallbackunittest:unregisterdinputcallbackunittest" + "unregisterdinputcallbackunittest:unregisterdinputcallbackunittest", + "clientunittest:clientunittest", + "dinputsourcecallbackunittest:dinputsourcecallbackunittest", ] } diff --git a/interfaces/ipc/test/clientunittest/BUILD.gn b/interfaces/ipc/test/clientunittest/BUILD.gn new file mode 100644 index 0000000..49d6eca --- /dev/null +++ b/interfaces/ipc/test/clientunittest/BUILD.gn @@ -0,0 +1,141 @@ +# 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/ipc" + +group("clientunittest") { + testonly = true + + deps = [ ":distributed_input_client_test" ] +} + +## UnitTest distributed_input_client_test {{{ +ohos_unittest("distributed_input_client_test") { + module_out_path = module_out_path + + include_dirs = [ + "${common_path}/include", + "${frameworks_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${fwk_interfaces_path}/include", + "${fwk_interfaces_path}/include/ipc", + "${fwk_utils_path}/include", + "${fwk_utils_path}/include/log", + "${innerkits_path}/include", + "${innerkits_path}/src", + "${ipc_path}/include", + "${ipc_path}/src", + "${utils_path}/include", + "//commonlibrary/c_utils/base/include", + "//third_party/json/include", + "//utils/system/safwk/native/include", + "//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk", + "//foundation/communication/dsoftbus/interfaces/kits/bus_center", + "//foundation/communication/dsoftbus/interfaces/kits/common", + "${services_source_path}/sourcemanager/include", + "${services_source_path}/inputinject/include", + "${services_source_path}/transport/include", + "${service_common}/include", + "${services_sink_path}/transport/include", + "${services_sink_path}/inputcollector/include", + "${services_sink_path}/sinkmanager/include", + "//foundation/window/window_manager/interfaces/innerkits/dm", + "//foundation/window/window_manager/utils/include/", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_base/include", + "//foundation/graphic/graphic_2d/interfaces/inner_api/surface", + "//foundation/graphic/graphic_2d/interfaces/inner_api/common", + "//drivers/peripheral/display/interfaces/include", + "//drivers/peripheral/base", + "//foundation/graphic/graphic_2d/utils/buffer_handle/export", + "${distributedinput_path}/inputdevicehandler/include", + ] + + sources = [ + "distributed_input_client_test.cpp", + "mock_samanager.cpp", + "${common_path}/include/white_list_util.cpp", + "${common_path}/include/input_check_param.cpp", + "${ipc_path}/src/add_white_list_infos_call_back_proxy.cpp", + "${ipc_path}/src/add_white_list_infos_call_back_stub.cpp", + "${ipc_path}/src/del_white_list_infos_call_back_proxy.cpp", + "${ipc_path}/src/del_white_list_infos_call_back_stub.cpp", + "${ipc_path}/src/get_sink_screen_infos_call_back_proxy.cpp", + "${ipc_path}/src/get_sink_screen_infos_call_back_stub.cpp", + "${ipc_path}/src/distributed_input_client.cpp", + "${ipc_path}/src/distributed_input_sink_proxy.cpp", + "${ipc_path}/src/distributed_input_sink_stub.cpp", + "${ipc_path}/src/distributed_input_source_proxy.cpp", + "${ipc_path}/src/distributed_input_source_stub.cpp", + "${ipc_path}/src/input_node_listener_proxy.cpp", + "${ipc_path}/src/input_node_listener_stub.cpp", + "${ipc_path}/src/prepare_d_input_call_back_proxy.cpp", + "${ipc_path}/src/prepare_d_input_call_back_stub.cpp", + "${ipc_path}/src/register_d_input_call_back_proxy.cpp", + "${ipc_path}/src/register_d_input_call_back_stub.cpp", + "${ipc_path}/src/sharing_dhid_listener_proxy.cpp", + "${ipc_path}/src/sharing_dhid_listener_stub.cpp", + "${ipc_path}/src/simulation_event_listener_proxy.cpp", + "${ipc_path}/src/simulation_event_listener_stub.cpp", + "${ipc_path}/src/start_d_input_call_back_proxy.cpp", + "${ipc_path}/src/start_d_input_call_back_stub.cpp", + "${ipc_path}/src/start_stop_d_inputs_call_back_proxy.cpp", + "${ipc_path}/src/start_stop_d_inputs_call_back_stub.cpp", + "${ipc_path}/src/start_stop_result_call_back_proxy.cpp", + "${ipc_path}/src/start_stop_result_call_back_stub.cpp", + "${ipc_path}/src/stop_d_input_call_back_proxy.cpp", + "${ipc_path}/src/stop_d_input_call_back_stub.cpp", + "${ipc_path}/src/unprepare_d_input_call_back_proxy.cpp", + "${ipc_path}/src/unprepare_d_input_call_back_stub.cpp", + "${ipc_path}/src/unregister_d_input_call_back_proxy.cpp", + "${ipc_path}/src/unregister_d_input_call_back_stub.cpp", + ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + "-Dprivate=public", + "-Dprotected=public", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"distributedinpututtest\"", + "LOG_DOMAIN=0xD004100", + ] + + deps = [ + "${dfx_utils_path}:libdinput_dfx_utils", + "${fwk_interfaces_path}:libdhfwk_sdk", + "${fwk_utils_path}:distributedhardwareutils", + "${utils_path}:libdinput_utils", + "//foundation/distributedhardware/distributed_input/services/source/sourcemanager:libdinput_source", + "//foundation/distributedhardware/distributed_input/services/source/inputinject:libdinput_inject", + "//foundation/distributedhardware/distributed_input/services/sink/sinkmanager:libdinput_sink", + "//base/notification/eventhandler/frameworks/eventhandler:libeventhandler", + "//foundation/window/window_manager/dm:libdm", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] + + cflags_cc = [ "-DHILOG_ENABLE" ] +} +## UnitTest distributed_input_client_test }}} diff --git a/interfaces/ipc/test/clientunittest/distributed_input_client_test.cpp b/interfaces/ipc/test/clientunittest/distributed_input_client_test.cpp new file mode 100644 index 0000000..5a8769a --- /dev/null +++ b/interfaces/ipc/test/clientunittest/distributed_input_client_test.cpp @@ -0,0 +1,472 @@ +/* + * 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_client_test.h" + +#include "nlohmann/json.hpp" + +#include "dinput_errcode.h" +#include "add_white_list_infos_call_back_proxy.h" +#include "add_white_list_infos_call_back_stub.h" +#include "distributed_input_inject.h" + +using namespace testing::ext; +using namespace OHOS::DistributedHardware::DistributedInput; +using namespace std; +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +void DistributedInputClientTest::SetUp() +{ +} + +void DistributedInputClientTest::TearDown() +{ +} + +void DistributedInputClientTest::SetUpTestCase() +{ +} + +void DistributedInputClientTest::TearDownTestCase() +{ +} + +int32_t DistributedInputClientTest::StructTransJson(const InputDevice& pBuf, std::string& strDescriptor) const +{ + nlohmann::json tmpJson; + tmpJson["name"] = pBuf.name; + tmpJson["physicalPath"] = pBuf.physicalPath; + tmpJson["uniqueId"] = pBuf.uniqueId; + tmpJson["bus"] = pBuf.bus; + tmpJson["vendor"] = pBuf.vendor; + tmpJson["product"] = pBuf.product; + tmpJson["version"] = pBuf.version; + tmpJson["descriptor"] = pBuf.descriptor; + tmpJson["classes"] = pBuf.classes; + + std::ostringstream stream; + stream << tmpJson.dump(); + strDescriptor = stream.str(); + return DH_SUCCESS; +} + +int32_t DistributedInputClientTest::TestRegisterDInputCallback::OnRegisterResult(const std::string &devId, + const std::string &dhId, int32_t status, const std::string &data) +{ + (void)dhId; + (void)status; + (void)data; + return DH_SUCCESS; +} + +int32_t DistributedInputClientTest::TestUnregisterDInputCallback::OnUnregisterResult(const std::string &devId, + const std::string &dhId, int32_t status, const std::string &data) +{ + (void)dhId; + (void)status; + (void)data; + return DH_SUCCESS; +} + +void DistributedInputClientTest::TestPrepareDInputCallback::OnResult( + const std::string& deviceId, const int32_t& status) +{ + (void)deviceId; + (void)status; + return; +} + +void DistributedInputClientTest::TestUnprepareDInputCallback::OnResult( + const std::string& deviceId, const int32_t& status) +{ + (void)deviceId; + (void)status; + return; +} + +void DistributedInputClientTest::TestStartDInputCallback::OnResult( + const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) +{ + (void)deviceId; + (void)inputTypes; + (void)status; + return; +} + +void DistributedInputClientTest::TestStopDInputCallback::OnResult( + const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) +{ + (void)deviceId; + (void)inputTypes; + (void)status; + return; +} + +void DistributedInputClientTest::TestStartStopDInputCallback::OnResultDhids( + const std::string &devId, const int32_t &status) +{ + (void)devId; + (void)status; + return; +} + +void DistributedInputClientTest::TestInputNodeListener::OnNodeOnLine(const std::string srcDevId, + const std::string sinkDevId, const std::string sinkNodeId, const std::string sinkNodeDesc) +{ + (void)srcDevId; + (void)sinkDevId; + (void)sinkNodeId; + (void)sinkNodeDesc; + return; +} + +void DistributedInputClientTest::TestInputNodeListener::OnNodeOffLine(const std::string srcDevId, + const std::string sinkDevId, const std::string sinkNodeId) +{ + (void)srcDevId; + (void)sinkDevId; + (void)sinkNodeId; + return; +} + +int32_t DistributedInputClientTest::TestSimulationEventListenerStub::OnSimulationEvent( + uint32_t type, uint32_t code, int32_t value) +{ + (void)type; + (void)code; + (void)value; + return DH_SUCCESS; +} + +HWTEST_F(DistributedInputClientTest, InitSource01, testing::ext::TestSize.Level1) +{ + int32_t ret = DistributedInputClient::GetInstance().InitSource(); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_INIT_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, InitSink01, testing::ext::TestSize.Level1) +{ + int32_t ret = DistributedInputClient::GetInstance().InitSink(); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SINK_MANAGER_INIT_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, RegisterDistributedHardware01, testing::ext::TestSize.Level1) +{ + std::string devId; + std::string dhId; + std::string parameters; + std::shared_ptr callback; + int32_t ret = DistributedInputClient::GetInstance().RegisterDistributedHardware(devId, dhId, parameters, callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_REGISTER_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, UnregisterDistributedHardware01, testing::ext::TestSize.Level1) +{ + std::string devId; + std::string dhId; + std::shared_ptr callback; + int32_t ret = DistributedInputClient::GetInstance().UnregisterDistributedHardware(devId, dhId, callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_UNREGISTER_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, UnregisterDistributedHardware02, testing::ext::TestSize.Level1) +{ + std::shared_ptr unregisterDInputCallback = + std::make_shared(); + int32_t ret = DistributedInputClient::GetInstance().UnregisterDistributedHardware("devId", + "dhId", unregisterDInputCallback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, PrepareRemoteInput01, testing::ext::TestSize.Level1) +{ + string deviceId = "PrepareRemoteInput01"; + sptr callback = new TestPrepareDInputCallback(); + int32_t ret = DistributedInputClient::GetInstance().PrepareRemoteInput(deviceId, callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, PrepareRemoteInput02, testing::ext::TestSize.Level1) +{ + string deviceId = ""; + sptr callback = nullptr; + std::shared_ptr unregisterDInputCallback = + std::make_shared(); + int32_t ret = DistributedInputClient::GetInstance().PrepareRemoteInput(deviceId, callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_PREPARE_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, PrepareRemoteInput03, testing::ext::TestSize.Level0) +{ + std::string srcId = "PrepareRemoteInput_test"; + std::string sinkId = "PrepareRemoteInput_test"; + sptr callback = new TestPrepareDInputCallback(); + int32_t ret = DistributedInputClient::GetInstance().PrepareRemoteInput(srcId, sinkId, callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, PrepareRemoteInput04, testing::ext::TestSize.Level0) +{ + std::string srcId = ""; + std::string sinkId = ""; + sptr callback = nullptr; + int32_t ret = DistributedInputClient::GetInstance().PrepareRemoteInput(srcId, sinkId, callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_PREPARE_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, UnprepareRemoteInput01, testing::ext::TestSize.Level0) +{ + string deviceId = "UnprepareRemoteInput01"; + sptr callback = new TestUnprepareDInputCallback(); + int32_t ret = DistributedInputClient::GetInstance().UnprepareRemoteInput(deviceId, callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, UnprepareRemoteInput02, testing::ext::TestSize.Level0) +{ + string deviceId = ""; + sptr callback = nullptr; + int32_t ret = DistributedInputClient::GetInstance().UnprepareRemoteInput(deviceId, callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_UNPREPARE_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, UnprepareRemoteInput03, testing::ext::TestSize.Level0) +{ + std::string srcId = "PrepareRemoteInput_src"; + std::string sinkId = "PrepareRemoteInput_sink"; + sptr callback = new TestUnprepareDInputCallback(); + int32_t ret = DistributedInputClient::GetInstance().UnprepareRemoteInput(srcId, sinkId, callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, UnprepareRemoteInput04, testing::ext::TestSize.Level0) +{ + std::string srcId = ""; + std::string sinkId = ""; + sptr callback = nullptr; + int32_t ret = DistributedInputClient::GetInstance().UnprepareRemoteInput(srcId, sinkId, callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_UNPREPARE_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, StartRemoteInput01, testing::ext::TestSize.Level0) +{ + string deviceId = "StartRemoteInput01"; + sptr callback = new TestStartDInputCallback(); + int32_t ret = DistributedInputClient::GetInstance().StartRemoteInput( + deviceId, static_cast(DInputDeviceType::ALL), callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, StartRemoteInput02, testing::ext::TestSize.Level0) +{ + string deviceId = ""; + sptr callback = nullptr; + int32_t ret = DistributedInputClient::GetInstance().StartRemoteInput( + deviceId, static_cast(DInputDeviceType::ALL), callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_START_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, StartRemoteInput03, testing::ext::TestSize.Level0) +{ + std::string sinkId = "StartRemoteInput_sink"; + std::vector dhIds = {"dhIds_test"}; + sptr callback = new TestStartStopDInputCallback(); + int32_t ret = DistributedInputClient::GetInstance().StartRemoteInput(sinkId, dhIds, callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, StartRemoteInput04, testing::ext::TestSize.Level0) +{ + std::string sinkId = ""; + std::vector dhIds; + sptr callback = nullptr; + int32_t ret = DistributedInputClient::GetInstance().StartRemoteInput(sinkId, dhIds, callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_START_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, StartRemoteInput05, testing::ext::TestSize.Level0) +{ + string srcId = "StartRemoteInput01-src"; + string sinkId = "StartRemoteInput01-sink"; + sptr callback = new TestStartDInputCallback(); + int32_t ret = DistributedInputClient::GetInstance().StartRemoteInput( + srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, StartRemoteInput06, testing::ext::TestSize.Level0) +{ + string srcId = ""; + string sinkId = ""; + sptr callback = nullptr; + int32_t ret = DistributedInputClient::GetInstance().StartRemoteInput( + srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_START_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, StartRemoteInput07, testing::ext::TestSize.Level0) +{ + string srcId = "StartRemoteInput01-src"; + string sinkId = "StartRemoteInput01-sink"; + std::vector dhIds = {"dhIds_test"}; + sptr callback = new TestStartStopDInputCallback(); + int32_t ret = DistributedInputClient::GetInstance().StartRemoteInput(srcId, sinkId, dhIds, callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, StartRemoteInput08, testing::ext::TestSize.Level0) +{ + string srcId = ""; + string sinkId = ""; + std::vector dhIds; + sptr callback = nullptr; + int32_t ret = DistributedInputClient::GetInstance().StartRemoteInput(srcId, sinkId, dhIds, callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_START_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, StopRemoteInput01, testing::ext::TestSize.Level0) +{ + string deviceId = "StopRemoteInput01"; + sptr callback = new TestStopDInputCallback(); + int32_t ret = DistributedInputClient::GetInstance().StopRemoteInput( + deviceId, static_cast(DInputDeviceType::ALL), callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, StopRemoteInput02, testing::ext::TestSize.Level0) +{ + string deviceId = ""; + sptr callback = nullptr; + int32_t ret = DistributedInputClient::GetInstance().StopRemoteInput( + deviceId, static_cast(DInputDeviceType::ALL), callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_STOP_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, StopRemoteInput03, testing::ext::TestSize.Level0) +{ + std::string sinkId = "StartRemoteInput_test"; + std::vector dhIds = {"dhIds_test"}; + sptr callback = new TestStartStopDInputCallback(); + int32_t ret = DistributedInputClient::GetInstance().StopRemoteInput(sinkId, dhIds, callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, StopRemoteInput04, testing::ext::TestSize.Level0) +{ + std::string sinkId = ""; + std::vector dhIds; + sptr callback = nullptr; + int32_t ret = DistributedInputClient::GetInstance().StopRemoteInput(sinkId, dhIds, callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_STOP_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, StopRemoteInput05, testing::ext::TestSize.Level0) +{ + string srcId = "StopRemoteInput03-src"; + string sinkId = "StopRemoteInput03-sink"; + sptr callback = new TestStopDInputCallback(); + int32_t ret = DistributedInputClient::GetInstance().StopRemoteInput( + srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, StopRemoteInput06, testing::ext::TestSize.Level0) +{ + string srcId = ""; + string sinkId = ""; + sptr callback = nullptr; + int32_t ret = DistributedInputClient::GetInstance().StopRemoteInput( + srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_STOP_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, StopRemoteInput07, testing::ext::TestSize.Level0) +{ + string srcId = "StartRemoteInput01-src"; + string sinkId = "StartRemoteInput01-sink"; + std::vector dhIds = {"dhIds_test"}; + sptr callback = new TestStartStopDInputCallback(); + int32_t ret = DistributedInputClient::GetInstance().StopRemoteInput(srcId, sinkId, dhIds, callback); + EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, StopRemoteInput08, testing::ext::TestSize.Level0) +{ + string srcId = ""; + string sinkId = ""; + std::vector dhIds; + sptr callback = nullptr; + int32_t status = 0; + DistributedInputClient::RegisterDInputCb regCb; + regCb.OnResult(srcId, sinkId, status); + DistributedInputClient::UnregisterDInputCb unregCb; + unregCb.OnResult(srcId, sinkId, status); + DistributedInputClient::AddWhiteListInfosCb addCb; + addCb.OnResult(srcId, sinkId); + DistributedInputClient::DelWhiteListInfosCb delCb; + delCb.OnResult(srcId); + DistributedInputClient::GetSinkScreenInfosCb getSinkCb; + getSinkCb.OnResult(srcId); + DistributedInputClient::SharingDhIdListenerCb sharingCb; + sharingCb.OnSharing(srcId); + sharingCb.OnNoSharing(srcId); + + int32_t ret = DistributedInputClient::GetInstance().StopRemoteInput(srcId, sinkId, dhIds, callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_STOP_FAIL, ret); +} + +HWTEST_F(DistributedInputClientTest, ProcessEvent01, testing::ext::TestSize.Level0) +{ + std::shared_ptr runner = AppExecFwk::EventRunner::Create(true); + DistributedInputClient::DInputClientEventHandler eventHandler(runner); + AppExecFwk::InnerEvent::Pointer event = + AppExecFwk::InnerEvent::Get(DINPUT_CLIENT_CHECK_SOURCE_CALLBACK_REGISTER_MSG, 4809); + eventHandler.ProcessEvent(event); + EXPECT_EQ(event->GetInnerEventId(), DINPUT_CLIENT_CHECK_SOURCE_CALLBACK_REGISTER_MSG); +} + +HWTEST_F(DistributedInputClientTest, ProcessEvent02, testing::ext::TestSize.Level0) +{ + std::shared_ptr runner = AppExecFwk::EventRunner::Create(true); + DistributedInputClient::DInputClientEventHandler eventHandler(runner); + AppExecFwk::InnerEvent::Pointer event = + AppExecFwk::InnerEvent::Get(DINPUT_CLIENT_CHECK_SINK_CALLBACK_REGISTER_MSG, 4809); + eventHandler.ProcessEvent(event); + EXPECT_EQ(event->GetInnerEventId(), DINPUT_CLIENT_CHECK_SINK_CALLBACK_REGISTER_MSG); +} + +HWTEST_F(DistributedInputClientTest, ProcessEvent03, testing::ext::TestSize.Level0) +{ + std::shared_ptr runner = AppExecFwk::EventRunner::Create(true); + DistributedInputClient::DInputClientEventHandler eventHandler(runner); + AppExecFwk::InnerEvent::Pointer event = + AppExecFwk::InnerEvent::Get(DINPUT_CLIENT_CLEAR_SOURCE_CALLBACK_REGISTER_MSG, 4809); + eventHandler.ProcessEvent(event); + EXPECT_EQ(event->GetInnerEventId(), DINPUT_CLIENT_CLEAR_SOURCE_CALLBACK_REGISTER_MSG); +} + +HWTEST_F(DistributedInputClientTest, ProcessEvent04, testing::ext::TestSize.Level0) +{ + std::shared_ptr runner = AppExecFwk::EventRunner::Create(true); + DistributedInputClient::DInputClientEventHandler eventHandler(runner); + AppExecFwk::InnerEvent::Pointer event = + AppExecFwk::InnerEvent::Get(DINPUT_CLIENT_CLEAR_SINK_CALLBACK_REGISTER_MSG, 4809); + eventHandler.ProcessEvent(event); + EXPECT_EQ(event->GetInnerEventId(), DINPUT_CLIENT_CLEAR_SINK_CALLBACK_REGISTER_MSG); +} +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/ipc/test/clientunittest/distributed_input_client_test.h b/interfaces/ipc/test/clientunittest/distributed_input_client_test.h new file mode 100644 index 0000000..2119f8d --- /dev/null +++ b/interfaces/ipc/test/clientunittest/distributed_input_client_test.h @@ -0,0 +1,131 @@ +/* + * 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 DISTRIBUTED_INPUT_IPC_TEST_H +#define DISTRIBUTED_INPUT_IPC_TEST_H + +#include +#include +#include +#include + +#include + +#include "constants_dinput.h" +#include "dinput_sa_manager.h" +#include "distributed_input_client.h" +#include "input_node_listener_stub.h" +#include "simulation_event_listener_stub.h" +#include "start_stop_d_inputs_call_back_stub.h" +#include "prepare_d_input_call_back_stub.h" +#include "start_d_input_call_back_stub.h" +#include "stop_d_input_call_back_stub.h" +#include "simulation_event_listener_stub.h" +#include "unprepare_d_input_call_back_stub.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class DistributedInputClientTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; + + class TestRegisterDInputCallback : public OHOS::DistributedHardware::RegisterCallback { + public: + TestRegisterDInputCallback() = default; + virtual ~TestRegisterDInputCallback() = default; + int32_t OnRegisterResult(const std::string &devId, const std::string &dhId, int32_t status, + const std::string &data) override; + }; + + class TestUnregisterDInputCallback : public OHOS::DistributedHardware::UnregisterCallback { + public: + TestUnregisterDInputCallback() = default; + virtual ~TestUnregisterDInputCallback() = default; + int32_t OnUnregisterResult(const std::string &devId, const std::string &dhId, int32_t status, + const std::string &data) override; + }; + + class TestPrepareDInputCallback : public + OHOS::DistributedHardware::DistributedInput::PrepareDInputCallbackStub { + public: + TestPrepareDInputCallback() = default; + virtual ~TestPrepareDInputCallback() = default; + void OnResult(const std::string& deviceId, const int32_t& status); + }; + + class TestUnprepareDInputCallback : public + OHOS::DistributedHardware::DistributedInput::UnprepareDInputCallbackStub { + public: + TestUnprepareDInputCallback() = default; + virtual ~TestUnprepareDInputCallback() = default; + void OnResult(const std::string& deviceId, const int32_t& status); + }; + + class TestStartDInputCallback : public + OHOS::DistributedHardware::DistributedInput::StartDInputCallbackStub { + public: + TestStartDInputCallback() = default; + virtual ~TestStartDInputCallback() = default; + void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status); + }; + + class TestStopDInputCallback : public + OHOS::DistributedHardware::DistributedInput::StopDInputCallbackStub { + public: + TestStopDInputCallback() = default; + virtual ~TestStopDInputCallback() = default; + void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status); + }; + + class TestStartStopDInputCallback : public + OHOS::DistributedHardware::DistributedInput::StartStopDInputsCallbackStub { + public: + TestStartStopDInputCallback() = default; + virtual ~TestStartStopDInputCallback() = default; + void OnResultDhids(const std::string &devId, const int32_t &status); + }; + + class TestInputNodeListener : public + OHOS::DistributedHardware::DistributedInput::InputNodeListenerStub { + public: + TestInputNodeListener() = default; + virtual ~TestInputNodeListener() = default; + void OnNodeOnLine(const std::string srcDevId, const std::string sinkDevId, + const std::string sinkNodeId, const std::string sinkNodeDesc); + + void OnNodeOffLine(const std::string srcDevId, const std::string sinkDevId, + const std::string sinkNodeId); + }; + + class TestSimulationEventListenerStub : public + OHOS::DistributedHardware::DistributedInput::SimulationEventListenerStub { + public: + TestSimulationEventListenerStub() = default; + virtual ~TestSimulationEventListenerStub() = default; + int32_t OnSimulationEvent(uint32_t type, uint32_t code, int32_t value); + }; + +private: + int32_t StructTransJson(const InputDevice& pBuf, std::string& strDescriptor) const; +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS + +#endif // DISTRIBUTED_INPUT_IPC_TEST_H diff --git a/interfaces/ipc/test/clientunittest/mock_samanager.cpp b/interfaces/ipc/test/clientunittest/mock_samanager.cpp new file mode 100644 index 0000000..588c25a --- /dev/null +++ b/interfaces/ipc/test/clientunittest/mock_samanager.cpp @@ -0,0 +1,102 @@ +/* + * 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 "dinput_sa_manager.h" + +#include "distributed_hardware_log.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" + +#include "constants_dinput.h" +#include "distributed_input_source_manager.h" +#include "distributed_input_sink_manager.h" +#include "dinput_errcode.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +IMPLEMENT_SINGLE_INSTANCE(DInputSAManager); + +void DInputSAManager::SystemAbilityListener::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) +{} + +void DInputSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) +{} + +void DInputSAManager::Init() +{} + +void DInputSAManager::RegisterEventHandler(std::shared_ptr handler) +{ + eventHandler_ = handler; +} + +bool DInputSAManager::GetDInputSourceProxy() +{ + int32_t saId = 4809; + bool runOnCreate = false; + + if (dInputSourceProxy_ == nullptr) { + dInputSourceProxy_ = new DistributedInputSourceManager(saId, runOnCreate); + } + return dInputSourceProxy_ != nullptr; +} + +bool DInputSAManager::HasDInputSourceProxy() +{ + return dInputSourceProxy_ != nullptr; +} + +bool DInputSAManager::SetDInputSourceProxy(const sptr &remoteObject) +{ + dInputSourceProxy_ = iface_cast(remoteObject); + + if ((!dInputSourceProxy_) || (!dInputSourceProxy_->AsObject())) { + DHLOGE("Failed to get dinput source proxy."); + return false; + } + return true; +} + +bool DInputSAManager::GetDInputSinkProxy() +{ + int32_t saId = 4810; + bool runOnCreate = false; + + if (dInputSinkProxy_ == nullptr) { + dInputSinkProxy_ = new DistributedInputSinkManager(saId, runOnCreate); + } + + return dInputSinkProxy_ != nullptr; +} + +bool DInputSAManager::HasDInputSinkProxy() +{ + return dInputSinkProxy_ != nullptr; +} + +bool DInputSAManager::SetDInputSinkProxy(const sptr &remoteObject) +{ + dInputSinkProxy_ = iface_cast(remoteObject); + + if ((!dInputSinkProxy_) || (!dInputSinkProxy_->AsObject())) { + DHLOGE("Failed to get dinput sink proxy."); + return false; + } + return true; +} +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/ipc/test/dinputsourcecallbackunittest/BUILD.gn b/interfaces/ipc/test/dinputsourcecallbackunittest/BUILD.gn new file mode 100644 index 0000000..f04d38a --- /dev/null +++ b/interfaces/ipc/test/dinputsourcecallbackunittest/BUILD.gn @@ -0,0 +1,111 @@ +# 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/ipc" + +group("dinputsourcecallbackunittest") { + testonly = true + + deps = [ ":dinput_source_callback_test" ] +} + +## UnitTest dinput_source_callback_test {{{ +ohos_unittest("dinput_source_callback_test") { + module_out_path = module_out_path + + include_dirs = [ + "${common_path}/include", + "${frameworks_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${fwk_interfaces_path}/include", + "${fwk_interfaces_path}/include/ipc", + "${fwk_utils_path}/include", + "${fwk_utils_path}/include/log", + "${innerkits_path}/include", + "${innerkits_path}/src", + "${ipc_path}/include", + "${ipc_path}/src", + "${utils_path}/include", + "//commonlibrary/c_utils/base/include", + "//third_party/json/include", + "//utils/system/safwk/native/include", + "//foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk", + "//foundation/communication/dsoftbus/interfaces/kits/bus_center", + "//foundation/communication/dsoftbus/interfaces/kits/common", + ] + + sources = [ + "dinput_source_callback_unittest.cpp", + "${ipc_path}/src/add_white_list_infos_call_back_proxy.cpp", + "${ipc_path}/src/add_white_list_infos_call_back_stub.cpp", + "${ipc_path}/src/del_white_list_infos_call_back_proxy.cpp", + "${ipc_path}/src/del_white_list_infos_call_back_stub.cpp", + "${ipc_path}/src/get_sink_screen_infos_call_back_proxy.cpp", + "${ipc_path}/src/get_sink_screen_infos_call_back_stub.cpp", + "${ipc_path}/src/distributed_input_source_proxy.cpp", + "${ipc_path}/src/distributed_input_source_stub.cpp", + "${ipc_path}/src/prepare_d_input_call_back_proxy.cpp", + "${ipc_path}/src/prepare_d_input_call_back_stub.cpp", + "${ipc_path}/src/register_d_input_call_back_proxy.cpp", + "${ipc_path}/src/register_d_input_call_back_stub.cpp", + "${ipc_path}/src/start_d_input_call_back_proxy.cpp", + "${ipc_path}/src/start_d_input_call_back_stub.cpp", + "${ipc_path}/src/stop_d_input_call_back_proxy.cpp", + "${ipc_path}/src/stop_d_input_call_back_stub.cpp", + "${ipc_path}/src/unprepare_d_input_call_back_proxy.cpp", + "${ipc_path}/src/unprepare_d_input_call_back_stub.cpp", + "${ipc_path}/src/unregister_d_input_call_back_proxy.cpp", + "${ipc_path}/src/unregister_d_input_call_back_stub.cpp", + "${ipc_path}/src/start_stop_d_inputs_call_back_proxy.cpp", + "${ipc_path}/src/start_stop_d_inputs_call_back_stub.cpp", + "${ipc_path}/src/input_node_listener_proxy.cpp", + "${ipc_path}/src/input_node_listener_stub.cpp", + "${ipc_path}/src/simulation_event_listener_proxy.cpp", + "${ipc_path}/src/simulation_event_listener_stub.cpp", + ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + "-Dprivate=public", + "-Dprotected=public", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"distributedinpututtest\"", + "LOG_DOMAIN=0xD004100", + ] + + deps = [ + "${dfx_utils_path}:libdinput_dfx_utils", + "${fwk_interfaces_path}:libdhfwk_sdk", + "${fwk_utils_path}:distributedhardwareutils", + "${utils_path}:libdinput_utils", + "//base/notification/eventhandler/frameworks/eventhandler:libeventhandler", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] + + cflags_cc = [ "-DHILOG_ENABLE" ] +} +## UnitTest dinput_source_callback_test }}} diff --git a/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp b/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp new file mode 100644 index 0000000..836b349 --- /dev/null +++ b/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.cpp @@ -0,0 +1,605 @@ +/* + * 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 "dinput_source_callback_unittest.h" + +#include +#include "dinput_errcode.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +void DInputSourceCallBackTest::SetUp() +{ +} + +void DInputSourceCallBackTest::TearDown() +{ +} + +void DInputSourceCallBackTest::SetUpTestCase() +{ +} + +void DInputSourceCallBackTest::TearDownTestCase() +{ +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::Init() +{ + return DH_SUCCESS; +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::Release() +{ + return DH_SUCCESS; +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::RegisterDistributedHardware( + const std::string& devId, const std::string& dhId, const std::string& parameters, + sptr callback) +{ + (void)devId; + (void)dhId; + (void)parameters; + (void)callback; + return DH_SUCCESS; +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::UnregisterDistributedHardware( + const std::string& devId, const std::string& dhId, + sptr callback) +{ + (void)devId; + (void)dhId; + (void)callback; + return DH_SUCCESS; +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::PrepareRemoteInput( + const std::string &deviceId, sptr callback) +{ + (void)deviceId; + (void)callback; + return DH_SUCCESS; +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::UnprepareRemoteInput( + const std::string &deviceId, sptr callback) +{ + (void)deviceId; + (void)callback; + return DH_SUCCESS; +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::StartRemoteInput( + const std::string& deviceId, const uint32_t& inputTypes, sptr callback) +{ + (void)deviceId; + (void)inputTypes; + (void)callback; + return DH_SUCCESS; +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::StopRemoteInput( + const std::string& deviceId, const uint32_t& inputTypes, sptr callback) +{ + (void)deviceId; + (void)inputTypes; + (void)callback; + return DH_SUCCESS; +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::StartRemoteInput( + const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, + sptr callback) +{ + (void)srcId; + (void)sinkId; + (void)inputTypes; + (void)callback; + return DH_SUCCESS; +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::StopRemoteInput( + const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, + sptr callback) +{ + (void)srcId; + (void)sinkId; + (void)inputTypes; + (void)callback; + return DH_SUCCESS; +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::PrepareRemoteInput( + const std::string &srcId, const std::string &sinkId, + sptr callback) +{ + (void)srcId; + (void)sinkId; + (void)callback; + return DH_SUCCESS; +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::UnprepareRemoteInput( + const std::string &srcId, const std::string &sinkId, + sptr callback) +{ + (void)srcId; + (void)sinkId; + (void)callback; + return DH_SUCCESS; +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::StartRemoteInput( + const std::string &sinkId, const std::vector &dhIds, + sptr callback) +{ + (void)sinkId; + (void)dhIds; + (void)callback; + return DH_SUCCESS; +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::StopRemoteInput( + const std::string &sinkId, const std::vector &dhIds, + sptr callback) +{ + (void)sinkId; + (void)dhIds; + (void)callback; + return DH_SUCCESS; +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::StartRemoteInput( + const std::string &srcId, const std::string &sinkId, + const std::vector &dhIds, sptr callback) +{ + (void)srcId; + (void)sinkId; + (void)dhIds; + (void)callback; + return DH_SUCCESS; +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::StopRemoteInput( + const std::string &srcId, const std::string &sinkId, + const std::vector &dhIds, sptr callback) +{ + (void)srcId; + (void)sinkId; + (void)dhIds; + (void)callback; + return DH_SUCCESS; +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::RegisterAddWhiteListCallback( + sptr addWhiteListCallback) +{ + (void)addWhiteListCallback; + return DH_SUCCESS; +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::RegisterDelWhiteListCallback( + sptr delWhiteListCallback) +{ + (void)delWhiteListCallback; + return DH_SUCCESS; +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::RegisterInputNodeListener( + sptr listener) +{ + (void)listener; + return DH_SUCCESS; +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::UnregisterInputNodeListener( + sptr listener) +{ + (void)listener; + return DH_SUCCESS; +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::SyncNodeInfoRemoteInput( + const std::string &userDevId, const std::string &dhid, + const std::string &nodeDesc) +{ + (void)userDevId; + (void)dhid; + (void)nodeDesc; + return DH_SUCCESS; +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::RegisterSimulationEventListener( + sptr listener) +{ + (void)listener; + return DH_SUCCESS; +} + +int32_t DInputSourceCallBackTest::TestDInputSourceCallBackStub::UnregisterSimulationEventListener( + sptr listener) +{ + (void)listener; + return DH_SUCCESS; +} + +void DInputSourceCallBackTest::TestDInputSourceCallBackStub::OnResult(const std::string& deviceId, + const std::string& strJson) +{ + deviceId_ = deviceId; + strJson_ = strJson; +} + +void DInputSourceCallBackTest::TestDInputRegisterCallBack::OnResult(const std::string& devId, + const std::string& dhId, const int32_t& status) +{ + (void)devId; + (void)dhId; + (void)status; + return; +} + +void DInputSourceCallBackTest::TestDInputUnregisterCallBack::OnResult(const std::string& devId, + const std::string& dhId, const int32_t& status) +{ + (void)devId; + (void)dhId; + (void)status; + return; +} + +void DInputSourceCallBackTest::TestDInputPrepareCallBack::OnResult( + const std::string& deviceId, const int32_t& status) +{ + (void)deviceId; + (void)status; + return; +} + +void DInputSourceCallBackTest::TestDInputUnprepareCallBack::OnResult( + const std::string& deviceId, const int32_t& status) +{ + (void)deviceId; + (void)status; + return; +} + +void DInputSourceCallBackTest::TestDInputStartCallBack::OnResult( + const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) +{ + (void)deviceId; + (void)inputTypes; + (void)status; + return; +} + +void DInputSourceCallBackTest::TestDInputStopCallBack::OnResult( + const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) +{ + (void)deviceId; + (void)inputTypes; + (void)status; + return; +} + +void DInputSourceCallBackTest::TestVectorStartStopCallBackStub::OnResultDhids(const std::string &devId, + const int32_t &status) +{ + (void)devId; + (void)status; + return; +} + +void DInputSourceCallBackTest::TestAddWhiteListInfosCallBack::OnResult( + const std::string &deviceId, const std::string &strJson) +{ + (void)deviceId; + (void)strJson; + return; +} + +void DInputSourceCallBackTest::TestDelWhiteListInfosCallBack::OnResult( + const std::string& deviceId) +{ + (void)deviceId; + return; +} + +void DInputSourceCallBackTest::TestDInputNodeListenerCallBack::OnNodeOnLine(const std::string srcDevId, + const std::string sinkDevId, const std::string sinkNodeId, const std::string sinkNodeDesc) +{ + (void)srcDevId; + (void)sinkDevId; + (void)sinkNodeId; + (void)sinkNodeDesc; + return; +} + +void DInputSourceCallBackTest::TestDInputNodeListenerCallBack::OnNodeOffLine(const std::string srcDevId, + const std::string sinkDevId, const std::string sinkNodeId) +{ + (void)srcDevId; + (void)sinkDevId; + (void)sinkNodeId; + return; +} + +int32_t DInputSourceCallBackTest::TestDInputSimulationEventCallBack::OnSimulationEvent(uint32_t type, uint32_t code, + int32_t value) +{ + (void)type; + (void)code; + (void)value; + return DH_SUCCESS; +} + +HWTEST_F(DInputSourceCallBackTest, SendRequest01, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + IDistributedSourceInput::MessageCode code = IDistributedSourceInput::MessageCode::INIT; + MessageParcel data; + MessageParcel reply; + bool ret = callBackProxy.SendRequest(code, data, reply); + EXPECT_EQ(false, ret); +} + +HWTEST_F(DInputSourceCallBackTest, Init01, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + int32_t ret = callBackProxy.Init(); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DInputSourceCallBackTest, Release01, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + int32_t ret = callBackProxy.Release(); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DInputSourceCallBackTest, RegisterDistributedHardware01, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + const std::string devId = "d6f4s6d4f6"; + const std::string dhId = "Input_sd4f4s5d4f5s4"; + const std::string parameters = "d4a6s5d46asd"; + sptr callback = new TestDInputRegisterCallBack(); + int32_t ret = callBackProxy.RegisterDistributedHardware(devId, dhId, parameters, callback); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DInputSourceCallBackTest, UnregisterDistributedHardware01, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + const std::string devId = "d6f4s6d4f6"; + const std::string dhId = "Input_sd4f4s5d4f5s4"; + sptr callback = new TestDInputUnregisterCallBack(); + int32_t ret = callBackProxy.UnregisterDistributedHardware(devId, dhId, callback); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DInputSourceCallBackTest, PrepareRemoteInput01, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + const std::string devId = "d6f4s6d4f6"; + sptr callback = new TestDInputPrepareCallBack(); + int32_t ret = callBackProxy.PrepareRemoteInput(devId, callback); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DInputSourceCallBackTest, PrepareRemoteInput02, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + const std::string srcId = "d6f4s6d4f6"; + const std::string sinkId = "5sd45s4d5s4d5"; + sptr callback = new TestDInputPrepareCallBack(); + int32_t ret = callBackProxy.PrepareRemoteInput(srcId, sinkId, callback); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DInputSourceCallBackTest, UnprepareRemoteInput01, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + const std::string devId = "d6f4s6d4f6"; + sptr callback = new TestDInputUnprepareCallBack(); + int32_t ret = callBackProxy.UnprepareRemoteInput(devId, callback); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DInputSourceCallBackTest, UnprepareRemoteInput02, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + const std::string srcId = "d6f4s6d4f6"; + const std::string sinkId = "5sd45s4d5s4d5"; + sptr callback = new TestDInputUnprepareCallBack(); + int32_t ret = callBackProxy.UnprepareRemoteInput(srcId, sinkId, callback); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DInputSourceCallBackTest, StartRemoteInput01, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + const std::string devId = "d6f4s6d4f6"; + uint32_t inputTypes = 1; + sptr callback = new TestDInputStartCallBack(); + int32_t ret = callBackProxy.StartRemoteInput(devId, inputTypes, callback); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DInputSourceCallBackTest, StartRemoteInput02, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + const std::string srcId = "d6f4s6d4f6"; + const std::string sinkId = "5sd45s4d5s4d5"; + uint32_t inputTypes = 1; + sptr callback = new TestDInputStartCallBack(); + int32_t ret = callBackProxy.StartRemoteInput(srcId, sinkId, inputTypes, callback); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DInputSourceCallBackTest, StartRemoteInput03, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + const std::string sinkId = "d6f4s6d4f6"; + std::vector dhIds; + dhIds.push_back("Input_6ds54f6sd4f65sd4fsdf4s"); + sptr callback = new TestVectorStartStopCallBackStub(); + int32_t ret = callBackProxy.StartRemoteInput(sinkId, dhIds, callback); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DInputSourceCallBackTest, StartRemoteInput04, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + const std::string srcId = "d6f4s6d4f6"; + const std::string sinkId = "5sd45s4d5s4d5"; + std::vector dhIds; + dhIds.push_back("Input_6ds54f6sd4f65sd4fsdf4s"); + sptr callback = new TestVectorStartStopCallBackStub(); + int32_t ret = callBackProxy.StartRemoteInput(srcId, sinkId, dhIds, callback); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DInputSourceCallBackTest, StopRemoteInput01, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + const std::string devId = "d6f4s6d4f6"; + uint32_t inputTypes = 1; + sptr callback = new TestDInputStopCallBack(); + int32_t ret = callBackProxy.StopRemoteInput(devId, inputTypes, callback); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DInputSourceCallBackTest, StopRemoteInput02, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + const std::string srcId = "d6f4s6d4f6"; + const std::string sinkId = "5sd45s4d5s4d5"; + uint32_t inputTypes = 1; + sptr callback = new TestDInputStopCallBack(); + int32_t ret = callBackProxy.StopRemoteInput(srcId, sinkId, inputTypes, callback); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DInputSourceCallBackTest, StopRemoteInput03, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + const std::string sinkId = "d6f4s6d4f6"; + std::vector dhIds; + dhIds.push_back("Input_6ds54f6sd4f65sd4fsdf4s"); + sptr callback = new TestVectorStartStopCallBackStub(); + int32_t ret = callBackProxy.StopRemoteInput(sinkId, dhIds, callback); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DInputSourceCallBackTest, StopRemoteInput04, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + const std::string srcId = "d6f4s6d4f6"; + const std::string sinkId = "5sd45s4d5s4d5"; + std::vector dhIds; + dhIds.push_back("Input_6ds54f6sd4f65sd4fsdf4s"); + sptr callback = new TestVectorStartStopCallBackStub(); + int32_t ret = callBackProxy.StopRemoteInput(srcId, sinkId, dhIds, callback); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DInputSourceCallBackTest, RegisterAddWhiteListCallback01, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + sptr callback = new TestAddWhiteListInfosCallBack(); + int32_t ret = callBackProxy.RegisterAddWhiteListCallback(callback); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DInputSourceCallBackTest, RegisterDelWhiteListCallback01, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + sptr callback = new TestDelWhiteListInfosCallBack(); + int32_t ret = callBackProxy.RegisterDelWhiteListCallback(callback); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DInputSourceCallBackTest, RegisterInputNodeListener01, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + sptr listener = new TestDInputNodeListenerCallBack(); + int32_t ret = callBackProxy.RegisterInputNodeListener(listener); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DInputSourceCallBackTest, UnregisterInputNodeListener01, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + sptr listener = new TestDInputNodeListenerCallBack(); + int32_t ret = callBackProxy.UnregisterInputNodeListener(listener); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DInputSourceCallBackTest, SyncNodeInfoRemoteInput01, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + const std::string userDevId = "a4sd654q8w7e9qwe"; + const std::string dhid = "Input_sd65f46df46s54f"; + const std::string nodeDesc = "65d4f6s54f6sd4f665d4sf6"; + int32_t ret = callBackProxy.SyncNodeInfoRemoteInput(userDevId, dhid, nodeDesc); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DInputSourceCallBackTest, RegisterSimulationEventListener01, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + sptr listener = new TestDInputSimulationEventCallBack(); + int32_t ret = callBackProxy.RegisterSimulationEventListener(listener); + EXPECT_EQ(DH_SUCCESS, ret); +} + +HWTEST_F(DInputSourceCallBackTest, UnregisterSimulationEventListener01, testing::ext::TestSize.Level1) +{ + sptr callBackStubPtr = new TestDInputSourceCallBackStub(); + DistributedInputSourceProxy callBackProxy(callBackStubPtr); + sptr listener = new TestDInputSimulationEventCallBack(); + int32_t ret = callBackProxy.UnregisterSimulationEventListener(listener); + EXPECT_EQ(DH_SUCCESS, ret); +} +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.h b/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.h new file mode 100644 index 0000000..c104692 --- /dev/null +++ b/interfaces/ipc/test/dinputsourcecallbackunittest/dinput_source_callback_unittest.h @@ -0,0 +1,207 @@ +/* + * 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 DINPUT_SOURCE_CALLBACK_TEST_H +#define DINPUT_SOURCE_CALLBACK_TEST_H + +#include + +#include "add_white_list_infos_call_back_stub.h" +#include "constants_dinput.h" +#include "del_white_list_infos_call_back_stub.h" +#include "distributed_input_source_proxy.h" +#include "distributed_input_source_stub.h" +#include "input_node_listener_stub.h" +#include "prepare_d_input_call_back_stub.h" +#include "register_d_input_call_back_stub.h" +#include "start_d_input_call_back_stub.h" +#include "stop_d_input_call_back_stub.h" +#include "unprepare_d_input_call_back_stub.h" +#include "unregister_d_input_call_back_stub.h" +#include "start_stop_d_inputs_call_back_stub.h" +#include "start_stop_result_call_back_stub.h" +#include "simulation_event_listener_stub.h" + +namespace OHOS { +namespace DistributedHardware { +namespace DistributedInput { +class DInputSourceCallBackTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; + + class TestDInputSourceCallBackStub : public + OHOS::DistributedHardware::DistributedInput::DistributedInputSourceStub { + public: + TestDInputSourceCallBackStub() = default; + virtual ~TestDInputSourceCallBackStub() = default; + int32_t Init(); + + int32_t Release() ; + + int32_t RegisterDistributedHardware( + const std::string& devId, const std::string& dhId, const std::string& parameters, + sptr callback); + + int32_t UnregisterDistributedHardware( + const std::string& devId, const std::string& dhId, + sptr callback); + + int32_t PrepareRemoteInput(const std::string &deviceId, sptr callback); + + int32_t UnprepareRemoteInput(const std::string &deviceId, sptr callback); + + int32_t StartRemoteInput( + const std::string& deviceId, const uint32_t& inputTypes, sptr callback); + + int32_t StopRemoteInput( + const std::string& deviceId, const uint32_t& inputTypes, sptr callback); + + int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, + sptr callback); + + int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId, const uint32_t &inputTypes, + sptr callback); + + int32_t PrepareRemoteInput(const std::string &srcId, const std::string &sinkId, + sptr callback); + + int32_t UnprepareRemoteInput(const std::string &srcId, const std::string &sinkId, + sptr callback); + + int32_t StartRemoteInput(const std::string &sinkId, const std::vector &dhIds, + sptr callback); + + int32_t StopRemoteInput(const std::string &sinkId, const std::vector &dhIds, + sptr callback); + + int32_t StartRemoteInput(const std::string &srcId, const std::string &sinkId, + const std::vector &dhIds, sptr callback); + + int32_t StopRemoteInput(const std::string &srcId, const std::string &sinkId, + const std::vector &dhIds, sptr callback); + + int32_t RegisterAddWhiteListCallback(sptr addWhiteListCallback); + int32_t RegisterDelWhiteListCallback(sptr delWhiteListCallback); + int32_t RegisterInputNodeListener(sptr listener); + int32_t UnregisterInputNodeListener(sptr listener); + + int32_t SyncNodeInfoRemoteInput(const std::string &userDevId, const std::string &dhid, + const std::string &nodeDesc); + int32_t RegisterSimulationEventListener(sptr listener); + int32_t UnregisterSimulationEventListener(sptr listener); + void OnResult(const std::string& deviceId, const std::string& strJson); + std::string deviceId_; + std::string strJson_; + }; + + class TestDInputRegisterCallBack : public + OHOS::DistributedHardware::DistributedInput::RegisterDInputCallbackStub { + public: + TestDInputRegisterCallBack() = default; + virtual ~TestDInputRegisterCallBack() = default; + void OnResult(const std::string& devId, const std::string& dhId, const int32_t& status); + }; + + class TestDInputUnregisterCallBack : public + OHOS::DistributedHardware::DistributedInput::UnregisterDInputCallbackStub { + public: + TestDInputUnregisterCallBack() = default; + virtual ~TestDInputUnregisterCallBack() = default; + void OnResult(const std::string& devId, const std::string& dhId, const int32_t& status); + }; + + class TestDInputPrepareCallBack : public + OHOS::DistributedHardware::DistributedInput::PrepareDInputCallbackStub { + public: + TestDInputPrepareCallBack() = default; + virtual ~TestDInputPrepareCallBack() = default; + void OnResult(const std::string& deviceId, const int32_t& status); + }; + + class TestDInputUnprepareCallBack : public + OHOS::DistributedHardware::DistributedInput::UnprepareDInputCallbackStub { + public: + TestDInputUnprepareCallBack() = default; + virtual ~TestDInputUnprepareCallBack() = default; + void OnResult(const std::string& deviceId, const int32_t& status); + }; + + class TestDInputStartCallBack : public + OHOS::DistributedHardware::DistributedInput::StartDInputCallbackStub { + public: + TestDInputStartCallBack() = default; + virtual ~TestDInputStartCallBack() = default; + void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status); + }; + + class TestDInputStopCallBack : public + OHOS::DistributedHardware::DistributedInput::StopDInputCallbackStub { + public: + TestDInputStopCallBack() = default; + virtual ~TestDInputStopCallBack() = default; + void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status); + }; + + class TestVectorStartStopCallBackStub + : public OHOS::DistributedHardware::DistributedInput::StartStopDInputsCallbackStub { + public: + TestVectorStartStopCallBackStub() = default; + virtual ~TestVectorStartStopCallBackStub() = default; + void OnResultDhids(const std::string &devId, const int32_t &status); + }; + + class TestAddWhiteListInfosCallBack : public + OHOS::DistributedHardware::DistributedInput::AddWhiteListInfosCallbackStub { + public: + TestAddWhiteListInfosCallBack() = default; + virtual ~TestAddWhiteListInfosCallBack() = default; + void OnResult(const std::string &deviceId, const std::string &strJson); + }; + + class TestDelWhiteListInfosCallBack : public + OHOS::DistributedHardware::DistributedInput::DelWhiteListInfosCallbackStub { + public: + TestDelWhiteListInfosCallBack() = default; + virtual ~TestDelWhiteListInfosCallBack() = default; + void OnResult(const std::string &deviceId); + }; + + class TestDInputNodeListenerCallBack : public + OHOS::DistributedHardware::DistributedInput::InputNodeListenerStub { + public: + TestDInputNodeListenerCallBack() = default; + virtual ~TestDInputNodeListenerCallBack() = default; + void OnNodeOnLine(const std::string srcDevId, const std::string sinkDevId, + const std::string sinkNodeId, const std::string sinkNodeDesc); + + void OnNodeOffLine(const std::string srcDevId, const std::string sinkDevId, + const std::string sinkNodeId); + }; + + class TestDInputSimulationEventCallBack : public + OHOS::DistributedHardware::DistributedInput::SimulationEventListenerStub { + public: + TestDInputSimulationEventCallBack() = default; + virtual ~TestDInputSimulationEventCallBack() = default; + int32_t OnSimulationEvent(uint32_t type, uint32_t code, int32_t value); + }; +}; +} // namespace DistributedInput +} // namespace DistributedHardware +} // namespace OHOS +#endif // DINPUT_SOURCE_CALLBACK_TEST_H \ No newline at end of file diff --git a/interfaces/ipc/test/ipcunittest/distributed_input_ipc_test.cpp b/interfaces/ipc/test/ipcunittest/distributed_input_ipc_test.cpp index ede0117..ec91a32 100644 --- a/interfaces/ipc/test/ipcunittest/distributed_input_ipc_test.cpp +++ b/interfaces/ipc/test/ipcunittest/distributed_input_ipc_test.cpp @@ -15,6 +15,8 @@ #include "distributed_input_ipc_test.h" +#include "nlohmann/json.hpp" + #include "dinput_errcode.h" using namespace testing::ext; @@ -82,6 +84,33 @@ HWTEST_F(DistributedInputIpcTest, CheckSourceRegisterCallback01, testing::ext::T EXPECT_EQ(false, ret); } +HWTEST_F(DistributedInputIpcTest, CheckSinkRegisterCallback01, testing::ext::TestSize.Level1) +{ + std::string deviceId = "46qweqwe46q5qw4e"; + BusinessEvent event; + DistributedInputClient::GetInstance().CheckSinkRegisterCallback(); + bool ret = DistributedInputClient::GetInstance().IsNeedFilterOut(deviceId, event); + EXPECT_EQ(false, ret); +} + +HWTEST_F(DistributedInputIpcTest, CheckSharingDhIdsCallback01, testing::ext::TestSize.Level1) +{ + std::string deviceId = "46qweqwe46q5qw4e"; + BusinessEvent event; + DistributedInputClient::GetInstance().CheckSharingDhIdsCallback(); + bool ret = DistributedInputClient::GetInstance().IsNeedFilterOut(deviceId, event); + EXPECT_EQ(false, ret); +} + +HWTEST_F(DistributedInputIpcTest, CheckSinkScreenInfoCallback01, testing::ext::TestSize.Level1) +{ + std::string deviceId = "46qweqwe46q5qw4e"; + BusinessEvent event; + DistributedInputClient::GetInstance().CheckSinkScreenInfoCallback(); + bool ret = DistributedInputClient::GetInstance().IsNeedFilterOut(deviceId, event); + EXPECT_EQ(false, ret); +} + HWTEST_F(DistributedInputIpcTest, IsNeedFilterOut01, testing::ext::TestSize.Level1) { std::string deviceId = "46qweqwe46q5qw4e"; @@ -98,6 +127,14 @@ HWTEST_F(DistributedInputIpcTest, IsNeedFilterOut02, testing::ext::TestSize.Leve EXPECT_EQ(false, ret); } +HWTEST_F(DistributedInputIpcTest, IsNeedFilterOut03, testing::ext::TestSize.Level1) +{ + std::string deviceId(280, 'e'); + BusinessEvent event; + bool ret = DistributedInputClient::GetInstance().IsNeedFilterOut(deviceId, event); + EXPECT_EQ(false, ret); +} + HWTEST_F(DistributedInputIpcTest, IsTouchEventNeedFilterOut01, testing::ext::TestSize.Level1) { TouchScreenEvent event = {100, 100}; @@ -105,6 +142,56 @@ HWTEST_F(DistributedInputIpcTest, IsTouchEventNeedFilterOut01, testing::ext::Tes EXPECT_EQ(false, ret); } +HWTEST_F(DistributedInputIpcTest, IsTouchEventNeedFilterOut02, testing::ext::TestSize.Level1) +{ + TouchScreenEvent event = {100, 100}; + nlohmann::json jsonObj; + jsonObj = {{10, 10, 100, 100}}; + DistributedInputClient::GetInstance().UpdateSinkScreenInfos(jsonObj.dump()); + bool ret = DistributedInputClient::GetInstance().IsTouchEventNeedFilterOut(event); + EXPECT_EQ(true, ret); +} + +HWTEST_F(DistributedInputIpcTest, IsTouchEventNeedFilterOut03, testing::ext::TestSize.Level1) +{ + TouchScreenEvent event = {100, 100}; + nlohmann::json jsonObj; + jsonObj = {{10, 10, 100, 80}}; + DistributedInputClient::GetInstance().UpdateSinkScreenInfos(jsonObj.dump()); + bool ret = DistributedInputClient::GetInstance().IsTouchEventNeedFilterOut(event); + EXPECT_EQ(false, ret); +} + +HWTEST_F(DistributedInputIpcTest, IsTouchEventNeedFilterOut04, testing::ext::TestSize.Level1) +{ + TouchScreenEvent event = {100, 100}; + nlohmann::json jsonObj; + jsonObj = {{10, 10, 80, 100}}; + DistributedInputClient::GetInstance().UpdateSinkScreenInfos(jsonObj.dump()); + bool ret = DistributedInputClient::GetInstance().IsTouchEventNeedFilterOut(event); + EXPECT_EQ(false, ret); +} + +HWTEST_F(DistributedInputIpcTest, IsTouchEventNeedFilterOut05, testing::ext::TestSize.Level1) +{ + TouchScreenEvent event = {100, 100}; + nlohmann::json jsonObj; + jsonObj = {{110, 10, 100, 100}}; + DistributedInputClient::GetInstance().UpdateSinkScreenInfos(jsonObj.dump()); + bool ret = DistributedInputClient::GetInstance().IsTouchEventNeedFilterOut(event); + EXPECT_EQ(false, ret); +} + +HWTEST_F(DistributedInputIpcTest, IsTouchEventNeedFilterOut06, testing::ext::TestSize.Level1) +{ + TouchScreenEvent event = {100, 100}; + nlohmann::json jsonObj; + jsonObj = {{10, 110, 100, 100}}; + DistributedInputClient::GetInstance().UpdateSinkScreenInfos(jsonObj.dump()); + bool ret = DistributedInputClient::GetInstance().IsTouchEventNeedFilterOut(event); + EXPECT_EQ(false, ret); +} + HWTEST_F(DistributedInputIpcTest, IsStartDistributedInput01, testing::ext::TestSize.Level1) { std::string dhId; @@ -119,6 +206,13 @@ HWTEST_F(DistributedInputIpcTest, IsStartDistributedInput02, testing::ext::TestS EXPECT_EQ(false, ret); } +HWTEST_F(DistributedInputIpcTest, IsStartDistributedInput03, testing::ext::TestSize.Level1) +{ + std::string dhId(280, 'e'); + bool ret = DistributedInputClient::GetInstance().IsStartDistributedInput(dhId); + EXPECT_EQ(false, ret); +} + HWTEST_F(DistributedInputIpcTest, RegisterInputNodeListener01, testing::ext::TestSize.Level1) { sptr listener = nullptr; @@ -227,8 +321,9 @@ HWTEST_F(DistributedInputIpcTest, DelWhiteListInfos01, testing::ext::TestSize.Le HWTEST_F(DistributedInputIpcTest, UpdateSinkScreenInfos01, testing::ext::TestSize.Level1) { - std::string strJson = "[[1080][720][10][10]]"; - DistributedInputClient::GetInstance().UpdateSinkScreenInfos(strJson); + nlohmann::json jsonObj; + jsonObj = {{1080, 720, 10, 10}}; + DistributedInputClient::GetInstance().UpdateSinkScreenInfos(jsonObj.dump()); std::string strData = "{3413"; bool ret = DistributedInputClient::GetInstance().IsJsonData(strData); EXPECT_EQ(false, ret); @@ -251,6 +346,117 @@ HWTEST_F(DistributedInputIpcTest, NotifyStopDScreen01, testing::ext::TestSize.Le EXPECT_EQ(ERR_DH_INPUT_RPC_GET_REMOTE_DINPUT_FAIL, ret); } +HWTEST_F(DistributedInputIpcTest, RegisterDistributedHardware01, testing::ext::TestSize.Level1) +{ + std::string devId; + std::string dhId; + std::string parameters; + std::shared_ptr callback = nullptr; + int32_t ret = DistributedInputClient::GetInstance().RegisterDistributedHardware(devId, dhId, parameters, callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret); +} + +HWTEST_F(DistributedInputIpcTest, UnregisterDistributedHardware01, testing::ext::TestSize.Level1) +{ + std::string devId; + std::string dhId; + std::shared_ptr callback = nullptr; + int32_t ret = DistributedInputClient::GetInstance().UnregisterDistributedHardware(devId, dhId, callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret); +} + +HWTEST_F(DistributedInputIpcTest, PrepareRemoteInput01, testing::ext::TestSize.Level1) +{ + string deviceId = "PrepareRemoteInput01"; + sptr callback = nullptr; + int32_t ret = DistributedInputClient::GetInstance().PrepareRemoteInput(deviceId, callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret); +} + +HWTEST_F(DistributedInputIpcTest, UnprepareRemoteInput01, testing::ext::TestSize.Level0) +{ + string deviceId = "UnprepareRemoteInput01"; + sptr callback = nullptr; + int32_t ret = DistributedInputClient::GetInstance().UnprepareRemoteInput(deviceId, callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret); +} + +HWTEST_F(DistributedInputIpcTest, StartRemoteInput01, testing::ext::TestSize.Level0) +{ + string deviceId = "StartRemoteInput01"; + sptr callback = nullptr; + int32_t ret = DistributedInputClient::GetInstance().StartRemoteInput( + deviceId, static_cast(DInputDeviceType::ALL), callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret); +} + +HWTEST_F(DistributedInputIpcTest, StartRemoteInput02, testing::ext::TestSize.Level0) +{ + std::string sinkId = "StartRemoteInput_sink"; + std::vector dhIds = {"dhIds_test"}; + sptr callback = nullptr; + int32_t ret = DistributedInputClient::GetInstance().StartRemoteInput(sinkId, dhIds, callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret); +} + +HWTEST_F(DistributedInputIpcTest, StartRemoteInput03, testing::ext::TestSize.Level0) +{ + string srcId = "StartRemoteInput01-src"; + string sinkId = "StartRemoteInput01-sink"; + sptr callback = nullptr; + int32_t ret = DistributedInputClient::GetInstance().StartRemoteInput( + srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret); +} + +HWTEST_F(DistributedInputIpcTest, StartRemoteInput04, testing::ext::TestSize.Level0) +{ + string srcId = "StartRemoteInput01-src"; + string sinkId = "StartRemoteInput01-sink"; + std::vector dhIds = {"dhIds_test"}; + sptr callback = nullptr; + int32_t ret = DistributedInputClient::GetInstance().StartRemoteInput(srcId, sinkId, dhIds, callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret); +} + +HWTEST_F(DistributedInputIpcTest, StopRemoteInput01, testing::ext::TestSize.Level0) +{ + string deviceId = "StopRemoteInput01"; + sptr callback = nullptr; + int32_t ret = DistributedInputClient::GetInstance().StopRemoteInput( + deviceId, static_cast(DInputDeviceType::ALL), callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret); +} + +HWTEST_F(DistributedInputIpcTest, StopRemoteInput02, testing::ext::TestSize.Level0) +{ + std::string sinkId = "StartRemoteInput_test"; + std::vector dhIds = {"dhIds_test"}; + sptr callback = nullptr; + int32_t ret = DistributedInputClient::GetInstance().StopRemoteInput(sinkId, dhIds, callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret); +} + +HWTEST_F(DistributedInputIpcTest, StopRemoteInput03, testing::ext::TestSize.Level0) +{ + string srcId = "StopRemoteInput03-src"; + string sinkId = "StopRemoteInput03-sink"; + sptr callback = nullptr; + int32_t ret = DistributedInputClient::GetInstance().StopRemoteInput( + srcId, sinkId, static_cast(DInputDeviceType::ALL), callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret); +} + +HWTEST_F(DistributedInputIpcTest, StopRemoteInput04, testing::ext::TestSize.Level0) +{ + string srcId = "StartRemoteInput01-src"; + string sinkId = "StartRemoteInput01-sink"; + std::vector dhIds = {"dhIds_test"}; + sptr callback = nullptr; + int32_t ret = DistributedInputClient::GetInstance().StopRemoteInput(srcId, sinkId, dhIds, callback); + EXPECT_EQ(ERR_DH_INPUT_CLIENT_GET_SOURCE_PROXY_FAIL, ret); +} + } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp b/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp index 82c0d09..70c222b 100644 --- a/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp +++ b/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp @@ -192,6 +192,8 @@ HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedEvent01, testing:: size_t count = (size_t)(sizeof(writeBuffer) / sizeof(RawEvent)); DistributedInputInject::GetInstance().inputNodeManager_ = std::make_unique(); + DistributedInputInject::GetInstance().StartInjectThread(); + DistributedInputInject::GetInstance().StopInjectThread(); int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(writeBuffer, count); EXPECT_EQ(DH_SUCCESS, ret); }