1 /* 2 * Copyright (c) 2021-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef DISRIBUTED_INPUT_SOURCEMANAGER_TEST_H 17 #define DISRIBUTED_INPUT_SOURCEMANAGER_TEST_H 18 19 #include <functional> 20 #include <iostream> 21 #include <thread> 22 23 #include <gtest/gtest.h> 24 #include <refbase.h> 25 26 #include "add_white_list_infos_call_back_stub.h" 27 #include "constants_dinput.h" 28 #include "del_white_list_infos_call_back_stub.h" 29 #include "distributed_input_source_manager.h" 30 #include "prepare_d_input_call_back_stub.h" 31 #include "register_d_input_call_back_stub.h" 32 #include "start_d_input_call_back_stub.h" 33 #include "stop_d_input_call_back_stub.h" 34 #include "unprepare_d_input_call_back_stub.h" 35 #include "unregister_d_input_call_back_stub.h" 36 #include "start_stop_d_inputs_call_back_stub.h" 37 #include "start_stop_result_call_back_stub.h" 38 #include "input_node_listener_stub.h" 39 #include "simulation_event_listener_stub.h" 40 41 #include "dinput_source_trans_callback.h" 42 #include "dinput_source_listener.h" 43 44 namespace OHOS { 45 namespace DistributedHardware { 46 namespace DistributedInput { 47 class DistributedInputSourceManagerTest : public testing::Test { 48 public: 49 static void SetUpTestCase(); 50 static void TearDownTestCase(); 51 void SetUp() override; 52 void TearDown() override; 53 54 class TestPrepareDInputCallback : public 55 OHOS::DistributedHardware::DistributedInput::PrepareDInputCallbackStub { 56 public: 57 TestPrepareDInputCallback() = default; 58 virtual ~TestPrepareDInputCallback() = default; 59 void OnResult(const std::string &deviceId, const int32_t &status); 60 }; 61 62 class TestUnprepareDInputCallback : public 63 OHOS::DistributedHardware::DistributedInput::UnprepareDInputCallbackStub { 64 public: 65 TestUnprepareDInputCallback() = default; 66 virtual ~TestUnprepareDInputCallback() = default; 67 void OnResult(const std::string &deviceId, const int32_t &status); 68 }; 69 70 class TestStartDInputCallback : public 71 OHOS::DistributedHardware::DistributedInput::StartDInputCallbackStub { 72 public: 73 TestStartDInputCallback() = default; 74 virtual ~TestStartDInputCallback() = default; 75 void OnResult(const std::string &deviceId, const uint32_t &inputTypes, const int32_t &status); 76 }; 77 78 class TestStopDInputCallback : public 79 OHOS::DistributedHardware::DistributedInput::StopDInputCallbackStub { 80 public: 81 TestStopDInputCallback() = default; 82 virtual ~TestStopDInputCallback() = default; 83 void OnResult(const std::string &deviceId, const uint32_t &inputTypes, const int32_t &status); 84 }; 85 86 class TestStartStopVectorCallbackStub 87 : public OHOS::DistributedHardware::DistributedInput::StartStopDInputsCallbackStub { 88 public: 89 TestStartStopVectorCallbackStub() = default; 90 virtual ~TestStartStopVectorCallbackStub() = default; 91 void OnResultDhids(const std::string &devId, const int32_t &status); 92 }; 93 94 class TestRegisterDInputCb : public OHOS::DistributedHardware::DistributedInput::RegisterDInputCallbackStub { 95 public: 96 TestRegisterDInputCb() = default; 97 virtual ~TestRegisterDInputCb() = default; 98 void OnResult(const std::string &devId, const std::string &dhId, const int32_t &status); 99 }; 100 101 class TestUnregisterDInputCb : public OHOS::DistributedHardware::DistributedInput::UnregisterDInputCallbackStub { 102 public: 103 TestUnregisterDInputCb() = default; 104 virtual ~TestUnregisterDInputCb() = default; 105 void OnResult(const std::string &devId, const std::string &dhId, const int32_t &status); 106 }; 107 108 class TestAddWhiteListInfosCb : public OHOS::DistributedHardware::DistributedInput::AddWhiteListInfosCallbackStub { 109 public: 110 TestAddWhiteListInfosCb() = default; 111 virtual ~TestAddWhiteListInfosCb() = default; 112 void OnResult(const std::string &deviceId, const std::string &strJson); 113 }; 114 115 class TestDelWhiteListInfosCb : public OHOS::DistributedHardware::DistributedInput::DelWhiteListInfosCallbackStub { 116 public: 117 TestDelWhiteListInfosCb() = default; 118 virtual ~TestDelWhiteListInfosCb() = default; 119 void OnResult(const std::string &deviceId); 120 }; 121 122 class TestStartStopResultCb : public OHOS::DistributedHardware::DistributedInput::StartStopResultCallbackStub { 123 public: 124 TestStartStopResultCb() = default; 125 virtual ~TestStartStopResultCb() = default; 126 void OnStart(const std::string &srcId, const std::string &sinkId, std::vector<std::string> &devData); 127 void OnStop(const std::string &srcId, const std::string &sinkId, std::vector<std::string> &devData); 128 }; 129 130 class TestInputNodeListenerCb : public OHOS::DistributedHardware::DistributedInput::InputNodeListenerStub { 131 public: 132 TestInputNodeListenerCb() = default; 133 virtual ~TestInputNodeListenerCb() = default; 134 void OnNodeOnLine(const std::string &srcDevId, const std::string &sinkDevId, 135 const std::string &sinkNodeId, const std::string &sinkNodeDesc); 136 137 void OnNodeOffLine(const std::string &srcDevId, const std::string &sinkDevId, 138 const std::string &sinkNodeId); 139 }; 140 141 class TestSimulationEventCb : public OHOS::DistributedHardware::DistributedInput::SimulationEventListenerStub { 142 public: 143 TestSimulationEventCb() = default; 144 virtual ~TestSimulationEventCb() = default; 145 int32_t OnSimulationEvent(uint32_t type, uint32_t code, int32_t value); 146 }; 147 148 class TestStartStopDInputsCb : public 149 OHOS::DistributedHardware::DistributedInput::StartStopDInputsCallbackStub { 150 public: 151 TestStartStopDInputsCb() = default; 152 virtual ~TestStartStopDInputsCb() = default; 153 void OnResultDhids(const std::string &devId, const int32_t &status); 154 }; 155 156 void RegisterSourceRespCallback(std::shared_ptr<DInputSourceTransCallback> callback); 157 private: 158 int32_t StructTransJson(const InputDevice &pBuf, std::string &strDescriptor) const; 159 DistributedInputSourceManager* sourceManager_; 160 std::shared_ptr<DInputSourceListener> statuslistener_; 161 std::shared_ptr<DInputSourceTransCallback> callback_; 162 }; 163 } // namespace DistributedInput 164 } // namespace DistributedHardware 165 } // namespace OHOS 166 167 #endif // DISRIBUTED_INPUT_SOURCEMANAGER_TEST_H 168