1 /*
2 * Copyright (c) 2022 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_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_laneDepsInterface;
LaneDepsInterfaceMock()24 LaneDepsInterfaceMock::LaneDepsInterfaceMock()
25 {
26 g_laneDepsInterface = reinterpret_cast<void *>(this);
27 }
28
~LaneDepsInterfaceMock()29 LaneDepsInterfaceMock::~LaneDepsInterfaceMock()
30 {
31 g_laneDepsInterface = nullptr;
32 }
33
GetLaneDepsInterface()34 static LaneDepsInterface *GetLaneDepsInterface()
35 {
36 return reinterpret_cast<LaneDepsInterface *>(g_laneDepsInterface);
37 }
38
SetDefaultResult()39 void LaneDepsInterfaceMock::SetDefaultResult()
40 {
41 EXPECT_CALL(*this, LnnGetOnlineStateById).WillRepeatedly(Return(true));
42 EXPECT_CALL(*this, LnnGetLocalStrInfo).WillRepeatedly(Return(SOFTBUS_OK));
43 EXPECT_CALL(*this, LnnGetRemoteStrInfo).WillRepeatedly(Return(SOFTBUS_OK));
44 EXPECT_CALL(*this, SoftBusFrequencyToChannel).WillRepeatedly(Return(1));
45 EXPECT_CALL(*this, LnnVisitPhysicalSubnet).WillRepeatedly(Return(true));
46 EXPECT_CALL(*this, LnnGetNodeInfoById).WillRepeatedly(Return(nullptr));
47 }
48
49 extern "C" {
LnnGetOnlineStateById(const char * id,IdCategory type)50 bool LnnGetOnlineStateById(const char *id, IdCategory type)
51 {
52 return GetLaneDepsInterface()->LnnGetOnlineStateById(id, type);
53 }
54
LnnGetLocalStrInfo(InfoKey key,char * info,uint32_t len)55 int32_t LnnGetLocalStrInfo(InfoKey key, char *info, uint32_t len)
56 {
57 return GetLaneDepsInterface()->LnnGetLocalStrInfo(key, info, len);
58 }
59
LnnGetRemoteStrInfo(const char * netWorkId,InfoKey key,char * info,uint32_t len)60 int32_t LnnGetRemoteStrInfo(const char *netWorkId, InfoKey key, char *info, uint32_t len)
61 {
62 return GetLaneDepsInterface()->LnnGetRemoteStrInfo(netWorkId, key, info, len);
63 }
64
AuthGetPreferConnInfo(const char * uuid,AuthConnInfo * connInfo,bool isMeta)65 int32_t AuthGetPreferConnInfo(const char *uuid, AuthConnInfo *connInfo, bool isMeta)
66 {
67 return GetLaneDepsInterface()->AuthGetPreferConnInfo(uuid, connInfo, isMeta);
68 }
69
AuthOpenConn(const AuthConnInfo * info,uint32_t requestId,const AuthConnCallback * callback,bool isMeta)70 int32_t AuthOpenConn(const AuthConnInfo *info, uint32_t requestId,
71 const AuthConnCallback *callback, bool isMeta)
72 {
73 return GetLaneDepsInterface()->AuthOpenConn(info, requestId, callback, isMeta);
74 }
75
SoftBusFrequencyToChannel(int frequency)76 int SoftBusFrequencyToChannel(int frequency)
77 {
78 return GetLaneDepsInterface()->SoftBusFrequencyToChannel(frequency);
79 }
80
LnnGetLocalNumInfo(InfoKey key,int32_t * info)81 int32_t LnnGetLocalNumInfo(InfoKey key, int32_t *info)
82 {
83 return GetLaneDepsInterface()->LnnGetLocalNumInfo(key, info);
84 }
85
LnnGetRemoteNumInfo(const char * netWorkId,InfoKey key,int32_t * info)86 int32_t LnnGetRemoteNumInfo(const char *netWorkId, InfoKey key, int32_t *info)
87 {
88 return GetLaneDepsInterface()->LnnGetRemoteNumInfo(netWorkId, key, info);
89 }
90
LnnGetNodeInfoById(const char * id,IdCategory type)91 NodeInfo *LnnGetNodeInfoById(const char *id, IdCategory type)
92 {
93 return GetLaneDepsInterface()->LnnGetNodeInfoById(id, type);
94 }
95
LnnGetLocalNodeInfo(void)96 const NodeInfo *LnnGetLocalNodeInfo(void)
97 {
98 return GetLaneDepsInterface()->LnnGetLocalNodeInfo();
99 }
100
P2pLinkGetRequestId(void)101 int32_t P2pLinkGetRequestId(void)
102 {
103 return GetLaneDepsInterface()->P2pLinkGetRequestId();
104 }
105
AuthCloseConn(int64_t authId)106 void AuthCloseConn(int64_t authId)
107 {
108 return GetLaneDepsInterface()->AuthCloseConn(authId);
109 }
110
P2pLinkConnectDevice(const P2pLinkConnectInfo * info)111 int32_t P2pLinkConnectDevice(const P2pLinkConnectInfo *info)
112 {
113 return GetLaneDepsInterface()->P2pLinkConnectDevice(info);
114 }
115
P2pLinkDisconnectDevice(const P2pLinkDisconnectInfo * info)116 int32_t P2pLinkDisconnectDevice(const P2pLinkDisconnectInfo *info)
117 {
118 return GetLaneDepsInterface()->P2pLinkDisconnectDevice(info);
119 }
120
AuthSetP2pMac(int64_t authId,const char * p2pMac)121 int32_t AuthSetP2pMac(int64_t authId, const char *p2pMac)
122 {
123 return GetLaneDepsInterface()->AuthSetP2pMac(authId, p2pMac);
124 }
125
LnnVisitPhysicalSubnet(LnnVisitPhysicalSubnetCallback callback,void * data)126 bool LnnVisitPhysicalSubnet(LnnVisitPhysicalSubnetCallback callback, void *data)
127 {
128 return GetLaneDepsInterface()->LnnVisitPhysicalSubnet(callback, data);
129 }
130 }
131 } // namespace OHOS