1 /*
2  * Copyright (c) 2023 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 #include "lnn_lane_link_deps_mock.h"
17 #include "softbus_error_code.h"
18 
19 using namespace testing::ext;
20 using namespace testing;
21 
22 namespace OHOS {
23 void *g_laneLinkDepsInterface;
LaneLinkDepsInterfaceMock()24 LaneLinkDepsInterfaceMock::LaneLinkDepsInterfaceMock()
25 {
26     g_laneLinkDepsInterface = reinterpret_cast<void *>(this);
27 }
28 
~LaneLinkDepsInterfaceMock()29 LaneLinkDepsInterfaceMock::~LaneLinkDepsInterfaceMock()
30 {
31     g_laneLinkDepsInterface = nullptr;
32 }
33 
GetLaneLinkDepsInterface()34 static LaneLinkDepsInterface *GetLaneLinkDepsInterface()
35 {
36     return reinterpret_cast<LaneLinkDepsInterface *>(g_laneLinkDepsInterface);
37 }
38 
ActionOfChannelOpenFailed(int32_t requestId,const char * networkId,const TransProxyPipelineChannelOption * option,const ITransProxyPipelineCallback * callback)39 int32_t LaneLinkDepsInterfaceMock::ActionOfChannelOpenFailed(int32_t requestId, const char *networkId,
40     const TransProxyPipelineChannelOption *option, const ITransProxyPipelineCallback *callback)
41 {
42     callback->onChannelOpenFailed(requestId, SOFTBUS_LANE_GUIDE_BUILD_FAIL);
43     return SOFTBUS_OK;
44 }
45 
ActionOfChannelOpened(int32_t requestId,const char * networkId,const TransProxyPipelineChannelOption * option,const ITransProxyPipelineCallback * callback)46 int32_t LaneLinkDepsInterfaceMock::ActionOfChannelOpened(int32_t requestId, const char *networkId,
47     const TransProxyPipelineChannelOption *option, const ITransProxyPipelineCallback *callback)
48 {
49     callback->onChannelOpened(requestId, 1);
50     return SOFTBUS_OK;
51 }
52 
ActionOfDetectSuccess(uint32_t laneReqId,const LaneLinkInfo * linkInfo,const LaneLinkCb * callback)53 int32_t LaneLinkDepsInterfaceMock::ActionOfDetectSuccess(uint32_t laneReqId, const LaneLinkInfo *linkInfo,
54     const LaneLinkCb *callback)
55 {
56     if (linkInfo == nullptr || callback == nullptr) {
57         GTEST_LOG_(INFO) << "invalid param";
58         return SOFTBUS_INVALID_PARAM;
59     }
60     callback->onLaneLinkSuccess(laneReqId, linkInfo->type, linkInfo);
61     return SOFTBUS_OK;
62 }
63 
64 extern "C" {
GetTransReqInfoByLaneReqId(uint32_t laneReqId,TransOption * reqInfo)65 int32_t GetTransReqInfoByLaneReqId(uint32_t laneReqId, TransOption *reqInfo)
66 {
67     return GetLaneLinkDepsInterface()->GetTransReqInfoByLaneReqId(laneReqId, reqInfo);
68 }
69 
TransProxyPipelineGenRequestId(void)70 int32_t TransProxyPipelineGenRequestId(void)
71 {
72     return GetLaneLinkDepsInterface()->TransProxyPipelineGenRequestId();
73 }
74 
TransProxyPipelineOpenChannel(int32_t requestId,const char * networkId,const TransProxyPipelineChannelOption * option,const ITransProxyPipelineCallback * callback)75 int32_t TransProxyPipelineOpenChannel(int32_t requestId, const char *networkId,
76     const TransProxyPipelineChannelOption *option, const ITransProxyPipelineCallback *callback)
77 {
78     return GetLaneLinkDepsInterface()->TransProxyPipelineOpenChannel(requestId, networkId, option, callback);
79 }
80 
TransProxyPipelineCloseChannel(int32_t channelId)81 int32_t TransProxyPipelineCloseChannel(int32_t channelId)
82 {
83     return GetLaneLinkDepsInterface()->TransProxyPipelineCloseChannel(channelId);
84 }
85 
TransProxyPipelineCloseChannelDelay(int32_t channelId)86 int32_t TransProxyPipelineCloseChannelDelay(int32_t channelId)
87 {
88     return GetLaneLinkDepsInterface()->TransProxyPipelineCloseChannelDelay(channelId);
89 }
90 
FindLaneResourceByLinkType(const char * peerUdid,LaneLinkType type,LaneResource * resource)91 int32_t FindLaneResourceByLinkType(const char *peerUdid, LaneLinkType type, LaneResource *resource)
92 {
93     return GetLaneLinkDepsInterface()->FindLaneResourceByLinkType(peerUdid, type, resource);
94 }
95 
LaneDetectReliability(uint32_t laneReqId,const LaneLinkInfo * linkInfo,const LaneLinkCb * callback)96 int32_t LaneDetectReliability(uint32_t laneReqId, const LaneLinkInfo *linkInfo, const LaneLinkCb *callback)
97 {
98     return GetLaneLinkDepsInterface()->LaneDetectReliability(laneReqId, linkInfo, callback);
99 }
100 
FindLaneResourceByLaneId(uint64_t laneId,LaneResource * resource)101 int32_t FindLaneResourceByLaneId(uint64_t laneId, LaneResource *resource)
102 {
103     return GetLaneLinkDepsInterface()->FindLaneResourceByLaneId(laneId, resource);
104 }
105 
InitLaneLink(void)106 int32_t InitLaneLink(void)
107 {
108     return GetLaneLinkDepsInterface()->InitLaneLink();
109 }
110 
AddLaneResourceToPool(const LaneLinkInfo * linkInfo,uint64_t laneId,bool isServerSide)111 int32_t AddLaneResourceToPool(const LaneLinkInfo *linkInfo, uint64_t laneId, bool isServerSide)
112 {
113     return GetLaneLinkDepsInterface()->AddLaneResourceToPool(linkInfo, laneId, isServerSide);
114 }
115 
DelLaneResourceByLaneId(uint64_t laneId,bool isServerSide)116 int32_t DelLaneResourceByLaneId(uint64_t laneId, bool isServerSide)
117 {
118     return GetLaneLinkDepsInterface()->DelLaneResourceByLaneId(laneId, isServerSide);
119 }
120 
NotifyFreeLaneResult(uint32_t laneReqId,int32_t errCode)121 void NotifyFreeLaneResult(uint32_t laneReqId, int32_t errCode)
122 {
123     GetLaneLinkDepsInterface()->NotifyFreeLaneResult(laneReqId, errCode);
124 }
125 
GetConflictTypeWithErrcode(int32_t conflictErrcode)126 LinkConflictType GetConflictTypeWithErrcode(int32_t conflictErrcode)
127 {
128     return GetLaneLinkDepsInterface()->GetConflictTypeWithErrcode(conflictErrcode);
129 }
130 
FindLinkConflictInfoByDevId(const DevIdentifyInfo * inputInfo,LinkConflictType conflictType,LinkConflictInfo * outputInfo)131 int32_t FindLinkConflictInfoByDevId(const DevIdentifyInfo *inputInfo, LinkConflictType conflictType,
132     LinkConflictInfo *outputInfo)
133 {
134     return GetLaneLinkDepsInterface()->FindLinkConflictInfoByDevId(inputInfo, conflictType, outputInfo);
135 }
136 
RemoveConflictInfoTimelinessMsg(const DevIdentifyInfo * inputInfo,LinkConflictType conflictType)137 void RemoveConflictInfoTimelinessMsg(const DevIdentifyInfo *inputInfo, LinkConflictType conflictType)
138 {
139     GetLaneLinkDepsInterface()->RemoveConflictInfoTimelinessMsg(inputInfo, conflictType);
140 }
141 
DelLinkConflictInfo(const DevIdentifyInfo * inputInfo,LinkConflictType conflictType)142 int32_t DelLinkConflictInfo(const DevIdentifyInfo *inputInfo, LinkConflictType conflictType)
143 {
144     return GetLaneLinkDepsInterface()->DelLinkConflictInfo(inputInfo, conflictType);
145 }
146 
ClearLaneResourceByLaneId(uint64_t laneId)147 int32_t ClearLaneResourceByLaneId(uint64_t laneId)
148 {
149     return GetLaneLinkDepsInterface()->ClearLaneResourceByLaneId(laneId);
150 }
151 
RemoveDelayDestroyMessage(uint64_t laneId)152 void RemoveDelayDestroyMessage(uint64_t laneId)
153 {
154     GetLaneLinkDepsInterface()->RemoveDelayDestroyMessage(laneId);
155 }
156 
DelLogicAndLaneRelationship(uint64_t laneId)157 void DelLogicAndLaneRelationship(uint64_t laneId)
158 {
159     GetLaneLinkDepsInterface()->DelLogicAndLaneRelationship(laneId);
160 }
161 
CheckLinkConflictByReleaseLink(LaneLinkType releaseLink)162 int32_t CheckLinkConflictByReleaseLink(LaneLinkType releaseLink)
163 {
164     return GetLaneLinkDepsInterface()->CheckLinkConflictByReleaseLink(releaseLink);
165 }
166 }
167 } // namespace OHOS
168