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 #include "mock_softbus_adapter.h"
16
17 using namespace testing;
18 using namespace testing::ext;
19
20 namespace OHOS {
21 namespace DistributedSchedule {
22 SoftbusMock *SoftbusMock::gMock;
23
SoftbusMock()24 SoftbusMock::SoftbusMock()
25 {
26 gMock = this;
27 }
28
~SoftbusMock()29 SoftbusMock::~SoftbusMock()
30 {
31 gMock = nullptr;
32 }
33
GetMock()34 SoftbusMock& SoftbusMock::GetMock()
35 {
36 return *gMock;
37 }
38
39 extern "C" {
Socket(SocketInfo info)40 int32_t Socket(SocketInfo info)
41 {
42 return SoftbusMock::GetMock().Socket(info);
43 }
44
Listen(int32_t socket,const QosTV qos[],uint32_t qosCount,const ISocketListener * listener)45 int32_t Listen(int32_t socket, const QosTV qos[], uint32_t qosCount, const ISocketListener* listener)
46 {
47 return SoftbusMock::GetMock().Listen(socket, qos, qosCount, listener);
48 }
49
Bind(int32_t socket,const QosTV qos[],uint32_t qosCount,const ISocketListener * listener)50 int32_t Bind(int32_t socket, const QosTV qos[], uint32_t qosCount, const ISocketListener* listener)
51 {
52 return SoftbusMock::GetMock().Bind(socket, qos, qosCount, listener);
53 }
54
SendBytes(int32_t socket,const void * data,uint32_t len)55 int32_t SendBytes(int32_t socket, const void* data, uint32_t len)
56 {
57 return SoftbusMock::GetMock().SendBytes(socket, data, len);
58 }
59
Shutdown(int32_t socket)60 void Shutdown(int32_t socket)
61 {
62 SoftbusMock::GetMock().Shutdown(socket);
63 }
GetSessionOption(int sessionId,SessionOption option,void * optionValue,uint32_t valueSize)64 int GetSessionOption(int sessionId, SessionOption option, void* optionValue, uint32_t valueSize)
65 {
66 return SoftbusMock::GetMock().GetSessionOption(sessionId,
67 option, optionValue, valueSize);
68 }
69 }
70 } // namespace DistributedSchedule
71 } // namespace OHOS
72