1 /* 2 * Copyright (c) 2022-2024 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 DISTRIBUTED_INPUT_IPC_TEST_H 17 #define DISTRIBUTED_INPUT_IPC_TEST_H 18 19 #include <functional> 20 #include <iostream> 21 #include <refbase.h> 22 #include <thread> 23 24 #include <gtest/gtest.h> 25 26 #include "constants_dinput.h" 27 #include "dinput_sa_manager.h" 28 #include "distributed_input_client.h" 29 #include "input_node_listener_stub.h" 30 #include "simulation_event_listener_stub.h" 31 #include "start_stop_d_inputs_call_back_stub.h" 32 #include "prepare_d_input_call_back_stub.h" 33 #include "start_d_input_call_back_stub.h" 34 #include "stop_d_input_call_back_stub.h" 35 #include "simulation_event_listener_stub.h" 36 #include "unprepare_d_input_call_back_stub.h" 37 38 namespace OHOS { 39 namespace DistributedHardware { 40 namespace DistributedInput { 41 class DistributedInputClientTest : public testing::Test { 42 public: 43 static void SetUpTestCase(); 44 static void TearDownTestCase(); 45 void SetUp() override; 46 void TearDown() override; 47 48 class TestRegisterDInputCallback : public OHOS::DistributedHardware::RegisterCallback { 49 public: 50 TestRegisterDInputCallback() = default; 51 virtual ~TestRegisterDInputCallback() = default; 52 int32_t OnRegisterResult(const std::string &devId, const std::string &dhId, int32_t status, 53 const std::string &data) override; 54 }; 55 56 class TestUnregisterDInputCallback : public OHOS::DistributedHardware::UnregisterCallback { 57 public: 58 TestUnregisterDInputCallback() = default; 59 virtual ~TestUnregisterDInputCallback() = default; 60 int32_t OnUnregisterResult(const std::string &devId, const std::string &dhId, int32_t status, 61 const std::string &data) override; 62 }; 63 64 class TestPrepareDInputCallback : public 65 OHOS::DistributedHardware::DistributedInput::PrepareDInputCallbackStub { 66 public: 67 TestPrepareDInputCallback() = default; 68 virtual ~TestPrepareDInputCallback() = default; 69 void OnResult(const std::string &deviceId, const int32_t &status); 70 }; 71 72 class TestUnprepareDInputCallback : public 73 OHOS::DistributedHardware::DistributedInput::UnprepareDInputCallbackStub { 74 public: 75 TestUnprepareDInputCallback() = default; 76 virtual ~TestUnprepareDInputCallback() = default; 77 void OnResult(const std::string &deviceId, const int32_t &status); 78 }; 79 80 class TestStartDInputCallback : public 81 OHOS::DistributedHardware::DistributedInput::StartDInputCallbackStub { 82 public: 83 TestStartDInputCallback() = default; 84 virtual ~TestStartDInputCallback() = default; 85 void OnResult(const std::string &deviceId, const uint32_t &inputTypes, const int32_t &status); 86 }; 87 88 class TestStopDInputCallback : public 89 OHOS::DistributedHardware::DistributedInput::StopDInputCallbackStub { 90 public: 91 TestStopDInputCallback() = default; 92 virtual ~TestStopDInputCallback() = default; 93 void OnResult(const std::string &deviceId, const uint32_t &inputTypes, const int32_t &status); 94 }; 95 96 class TestStartStopDInputCallback : public 97 OHOS::DistributedHardware::DistributedInput::StartStopDInputsCallbackStub { 98 public: 99 TestStartStopDInputCallback() = default; 100 virtual ~TestStartStopDInputCallback() = default; 101 void OnResultDhids(const std::string &devId, const int32_t &status); 102 }; 103 104 class TestInputNodeListener : public 105 OHOS::DistributedHardware::DistributedInput::InputNodeListenerStub { 106 public: 107 TestInputNodeListener() = default; 108 virtual ~TestInputNodeListener() = default; 109 void OnNodeOnLine(const std::string &srcDevId, const std::string &sinkDevId, 110 const std::string &sinkNodeId, const std::string &sinkNodeDesc); 111 112 void OnNodeOffLine(const std::string &srcDevId, const std::string &sinkDevId, 113 const std::string &sinkNodeId); 114 }; 115 116 class TestSimulationEventListenerStub : public 117 OHOS::DistributedHardware::DistributedInput::SimulationEventListenerStub { 118 public: 119 TestSimulationEventListenerStub() = default; 120 virtual ~TestSimulationEventListenerStub() = default; 121 int32_t OnSimulationEvent(uint32_t type, uint32_t code, int32_t value); 122 }; 123 124 private: 125 int32_t StructTransJson(const InputDevice &pBuf, std::string &strDescriptor) const; 126 }; 127 } // namespace DistributedInput 128 } // namespace DistributedHardware 129 } // namespace OHOS 130 131 #endif // DISTRIBUTED_INPUT_IPC_TEST_H 132