1 /* 2 * Copyright (c) 2024-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 MOCK_SOFTBUS_ADAPTER_TEST_H 17 #define MOCK_SOFTBUS_ADAPTER_TEST_H 18 19 #include <gmock/gmock.h> 20 21 #include "socket.h" 22 #include "session.h" 23 24 namespace OHOS { 25 namespace DistributedSchedule { 26 class MockInterface { 27 public: MockInterface()28 MockInterface() {}; ~MockInterface()29 virtual ~MockInterface() {}; 30 31 virtual int32_t Socket(SocketInfo info) = 0; 32 virtual int32_t Listen(int32_t socket, const QosTV qos[], uint32_t qosCount, const ISocketListener* listener) = 0; 33 virtual int32_t Bind(int32_t socket, const QosTV qos[], uint32_t qosCount, const ISocketListener* listener) = 0; 34 virtual int32_t SendBytes(int32_t socket, const void* data, uint32_t len) = 0; 35 virtual void Shutdown(int32_t socket) = 0; 36 virtual int GetSessionOption(int sessionId, SessionOption option, void* optionValue, uint32_t valueSize) = 0; 37 }; 38 39 class SoftbusMock : public MockInterface { 40 public: 41 SoftbusMock(); 42 ~SoftbusMock() override; 43 44 static SoftbusMock& GetMock(); 45 46 MOCK_METHOD(int32_t, Socket, (SocketInfo info), (override)); 47 MOCK_METHOD(int32_t, Listen, (int32_t socket, const QosTV qos[], uint32_t qosCount, 48 const ISocketListener* listener), (override)); 49 MOCK_METHOD(int32_t, Bind, (int32_t socket, const QosTV qos[], uint32_t qosCount, 50 const ISocketListener* listener), (override)); 51 MOCK_METHOD(int32_t, SendBytes, (int32_t socket, const void* data, uint32_t len), (override)); 52 MOCK_METHOD(void, Shutdown, (int32_t socket), (override)); 53 MOCK_METHOD(int, GetSessionOption, (int sessionId, SessionOption option, void* optionValue, 54 uint32_t valueSize), (override)); 55 56 private: 57 static SoftbusMock *gMock; 58 }; 59 } // namespace DistributedSchedule 60 } // namespace OHOS 61 #endif // MOCK_SOFTBUS_ADAPTER_TEST_H 62