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
16 #include "lnn_ctrl_lane_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_ctrlLaneIf;
CtrlLaneDepsInterfaceMock()24 CtrlLaneDepsInterfaceMock::CtrlLaneDepsInterfaceMock()
25 {
26 g_ctrlLaneIf = static_cast<void *>(this);
27 }
28
~CtrlLaneDepsInterfaceMock()29 CtrlLaneDepsInterfaceMock::~CtrlLaneDepsInterfaceMock()
30 {
31 g_ctrlLaneIf = nullptr;
32 }
33
GetCtrlLaneIf()34 static CtrlLaneDepsInterface *GetCtrlLaneIf()
35 {
36 return static_cast<CtrlLaneDepsInterfaceMock *>(g_ctrlLaneIf);
37 }
38
BuildLinkSuccess(const LinkRequest * reqInfo,uint32_t reqId,const LaneLinkCb * callback)39 int32_t CtrlLaneDepsInterfaceMock::BuildLinkSuccess(const LinkRequest *reqInfo, uint32_t reqId,
40 const LaneLinkCb *callback)
41 {
42 LaneLinkInfo linkInfo = {};
43 linkInfo.type = reqInfo->linkType;
44 callback->onLaneLinkSuccess(reqId, reqInfo->linkType, &linkInfo);
45 return SOFTBUS_OK;
46 }
47
BuildLinkFail(const LinkRequest * reqInfo,uint32_t reqId,const LaneLinkCb * callback)48 int32_t CtrlLaneDepsInterfaceMock::BuildLinkFail(const LinkRequest *reqInfo, uint32_t reqId,
49 const LaneLinkCb *callback)
50 {
51 callback->onLaneLinkFail(reqId, SOFTBUS_LANE_TRIGGER_LINK_FAIL, reqInfo->linkType);
52 return SOFTBUS_OK;
53 }
54
55 extern "C" {
SelectAuthLane(const char * networkId,LanePreferredLinkList * recommendList,LanePreferredLinkList * request)56 int32_t SelectAuthLane(const char *networkId, LanePreferredLinkList *recommendList, LanePreferredLinkList *request)
57 {
58 return GetCtrlLaneIf()->SelectAuthLane(networkId, recommendList, request);
59 }
60
BuildLink(const LinkRequest * reqInfo,uint32_t reqId,const LaneLinkCb * callback)61 int32_t BuildLink(const LinkRequest *reqInfo, uint32_t reqId, const LaneLinkCb *callback)
62 {
63 return GetCtrlLaneIf()->BuildLink(reqInfo, reqId, callback);
64 }
65
DestroyLink(const char * networkId,uint32_t laneReqId,LaneLinkType type)66 int32_t DestroyLink(const char *networkId, uint32_t laneReqId, LaneLinkType type)
67 {
68 return GetCtrlLaneIf()->DestroyLink(networkId, laneReqId, type);
69 }
70
GenerateLaneId(const char * localUdid,const char * remoteUdid,LaneLinkType linkType)71 uint64_t GenerateLaneId(const char *localUdid, const char *remoteUdid, LaneLinkType linkType)
72 {
73 return GetCtrlLaneIf()->GenerateLaneId(localUdid, remoteUdid, linkType);
74 }
75
AddLaneResourceToPool(const LaneLinkInfo * linkInfo,uint64_t laneId,bool isServerSide)76 int32_t AddLaneResourceToPool(const LaneLinkInfo *linkInfo, uint64_t laneId, bool isServerSide)
77 {
78 return GetCtrlLaneIf()->AddLaneResourceToPool(linkInfo, laneId, isServerSide);
79 }
80
DelLaneResourceByLaneId(uint64_t laneId,bool isServerSide)81 int32_t DelLaneResourceByLaneId(uint64_t laneId, bool isServerSide)
82 {
83 return GetCtrlLaneIf()->DelLaneResourceByLaneId(laneId, isServerSide);
84 }
85
FindLaneResourceByLaneId(uint64_t laneId,LaneResource * resourceItem)86 int32_t FindLaneResourceByLaneId(uint64_t laneId, LaneResource *resourceItem)
87 {
88 return GetCtrlLaneIf()->FindLaneResourceByLaneId(laneId, resourceItem);
89 }
90
FindLaneResourceByLinkType(const char * peerUdid,LaneLinkType type,LaneResource * resource)91 int32_t FindLaneResourceByLinkType(const char *peerUdid, LaneLinkType type, LaneResource *resource)
92 {
93 return GetCtrlLaneIf()->FindLaneResourceByLinkType(peerUdid, type, resource);
94 }
95
FreeLaneReqId(uint32_t laneReqId)96 void FreeLaneReqId(uint32_t laneReqId)
97 {
98 GetCtrlLaneIf()->FreeLaneReqId(laneReqId);
99 }
100
LaneInfoProcess(const LaneLinkInfo * linkInfo,LaneConnInfo * connInfo,LaneProfile * profile)101 int32_t LaneInfoProcess(const LaneLinkInfo *linkInfo, LaneConnInfo *connInfo, LaneProfile *profile)
102 {
103 return GetCtrlLaneIf()->LaneInfoProcess(linkInfo, connInfo, profile);
104 }
105 }
106 } // namespace OHOS
107