1 /* 2 * Copyright (c) 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 #ifndef DISTRIBUTED_COLLAB_SOFTBUS_MOCK_TEST_H 16 #define DISTRIBUTED_COLLAB_SOFTBUS_MOCK_TEST_H 17 #include "socket.h" 18 #include "session.h" 19 #include <gmock/gmock.h> 20 #include <cstdint> 21 #include <vector> 22 23 namespace OHOS { 24 namespace DistributedCollab { 25 class MockInterface { 26 public: MockInterface()27 MockInterface() {}; ~MockInterface()28 virtual ~MockInterface() {}; 29 30 virtual int32_t Socket(SocketInfo info) = 0; 31 virtual int32_t Listen(int32_t socket, const QosTV qos[], uint32_t qosCount, const ISocketListener* listener) = 0; 32 virtual int32_t Bind(int32_t socket, const QosTV qos[], uint32_t qosCount, const ISocketListener* listener) = 0; 33 virtual int32_t BindAsync(int32_t socket, const QosTV qos[], uint32_t qosCount, 34 const ISocketListener* listener) = 0; 35 virtual int32_t SendBytes(int32_t socket, const void* data, uint32_t len) = 0; 36 virtual int32_t SendMessage(int32_t socket, const void* data, uint32_t len) = 0; 37 virtual int32_t SendStream(int32_t socket, const StreamData* data, const StreamData* ext, 38 const StreamFrameInfo* param) = 0; 39 virtual int32_t SendFile(int32_t socket, const char* sFileList[], const char* dFileList[], uint32_t fileCnt) = 0; 40 virtual void Shutdown(int32_t socket) = 0; 41 virtual int GetSessionOption(int sessionId, SessionOption option, void* optionValue, uint32_t valueSize) = 0; 42 }; 43 44 class SoftbusMock : public MockInterface { 45 public: 46 SoftbusMock(); 47 ~SoftbusMock() override; 48 49 static SoftbusMock& GetMock(); 50 51 MOCK_METHOD(int32_t, Socket, (SocketInfo info), (override)); 52 MOCK_METHOD(int32_t, Listen, (int32_t socket, const QosTV qos[], uint32_t qosCount, 53 const ISocketListener* listener), (override)); 54 MOCK_METHOD(int32_t, Bind, (int32_t socket, const QosTV qos[], uint32_t qosCount, 55 const ISocketListener* listener), (override)); 56 MOCK_METHOD(int32_t, BindAsync, (int32_t socket, const QosTV qos[], uint32_t qosCount, 57 const ISocketListener* listener), (override)); 58 MOCK_METHOD(int32_t, SendBytes, (int32_t socket, const void* data, uint32_t len), (override)); 59 MOCK_METHOD(int32_t, SendMessage, (int32_t socket, const void* data, uint32_t len), (override)); 60 MOCK_METHOD(int32_t, SendStream, (int32_t socket, const StreamData* data, const StreamData* ext, 61 const StreamFrameInfo* param), (override)); 62 MOCK_METHOD(int32_t, SendFile, (int32_t socket, const char* sFileList[], 63 const char* dFileList[], uint32_t fileCnt), (override)); 64 MOCK_METHOD(void, Shutdown, (int32_t socket), (override)); 65 MOCK_METHOD(int, GetSessionOption, (int sessionId, SessionOption option, void* optionValue, 66 uint32_t valueSize), (override)); 67 private: 68 static SoftbusMock *gMock; 69 }; 70 71 extern "C" { 72 int32_t Socket(SocketInfo info); 73 int32_t Listen(int32_t socket, const QosTV qos[], uint32_t qosCount, const ISocketListener* listener); 74 int32_t Bind(int32_t socket, const QosTV qos[], uint32_t qosCount, const ISocketListener* listener); 75 int32_t BindAsync(int32_t socket, const QosTV qos[], uint32_t qosCount, const ISocketListener* listener); 76 int32_t SendBytes(int32_t socket, const void* data, uint32_t len); 77 int32_t SendMessage(int32_t socket, const void* data, uint32_t len); 78 int32_t SendStream(int32_t socket, const StreamData* data, const StreamData* ext, const StreamFrameInfo* param); 79 int32_t SendFile(int32_t socket, const char* sFileList[], const char* dFileList[], uint32_t fileCnt); 80 void Shutdown(int32_t socket); 81 int GetSessionOption(int sessionId, SessionOption option, void* optionValue, uint32_t valueSize); 82 } 83 } // namespace DistributedCollab 84 } // namespace OHOS 85 #endif