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 "softbus_server_stub_test_mock.h"
17
18 using namespace testing;
19 using namespace testing::ext;
20
21 namespace OHOS {
22
23 static void *g_softbusServerStubInterface = nullptr;
SoftbusServerStubTestInterfaceMock()24 SoftbusServerStubTestInterfaceMock::SoftbusServerStubTestInterfaceMock()
25 {
26 g_softbusServerStubInterface = reinterpret_cast<void *>(this);
27 }
28
~SoftbusServerStubTestInterfaceMock()29 SoftbusServerStubTestInterfaceMock::~SoftbusServerStubTestInterfaceMock()
30 {
31 g_softbusServerStubInterface = nullptr;
32 }
33
GetSoftbusServerStubTestInterface()34 static SoftbusServerStubTestInterface *GetSoftbusServerStubTestInterface()
35 {
36 return reinterpret_cast<SoftbusServerStubTestInterface *>(g_softbusServerStubInterface);
37 }
38
39 extern "C" {
CheckTransPermission(pid_t callingUid,pid_t callingPid,const char * pkgName,const char * sessionName,uint32_t actions)40 int32_t CheckTransPermission(pid_t callingUid, pid_t callingPid, const char *pkgName,
41 const char *sessionName, uint32_t actions)
42 {
43 return GetSoftbusServerStubTestInterface()->CheckTransPermission(callingUid, callingPid, pkgName,
44 sessionName, actions);
45 }
CheckTransSecLevel(const char * mySessionName,const char * peerSessionName)46 int32_t CheckTransSecLevel(const char *mySessionName, const char *peerSessionName)
47 {
48 return GetSoftbusServerStubTestInterface()->CheckTransSecLevel(mySessionName, peerSessionName);
49 }
TransGetNameByChanId(const TransInfo * info,char * pkgName,char * sessionName,uint16_t pkgLen,uint16_t sessionNameLen)50 int32_t TransGetNameByChanId(const TransInfo *info, char *pkgName, char *sessionName,
51 uint16_t pkgLen, uint16_t sessionNameLen)
52 {
53 return GetSoftbusServerStubTestInterface()->TransGetNameByChanId(info, pkgName, sessionName,
54 pkgLen, sessionNameLen);
55 }
TransGetAppInfoByChanId(int32_t channelId,int32_t channelType,AppInfo * appInfo)56 int32_t TransGetAppInfoByChanId(int32_t channelId, int32_t channelType, AppInfo *appInfo)
57 {
58 return GetSoftbusServerStubTestInterface()->TransGetAppInfoByChanId(channelId, channelType, appInfo);
59 }
TransGetAndComparePid(pid_t pid,int32_t channelId,int32_t channelType)60 int32_t TransGetAndComparePid(pid_t pid, int32_t channelId, int32_t channelType)
61 {
62 return GetSoftbusServerStubTestInterface()->TransGetAndComparePid(pid, channelId, channelType);
63 }
TransGetAndComparePidBySession(pid_t pid,const char * sessionName,int32_t sessionlId)64 int32_t TransGetAndComparePidBySession(pid_t pid, const char *sessionName, int32_t sessionlId)
65 {
66 return GetSoftbusServerStubTestInterface()->TransGetAndComparePidBySession(pid, sessionName, sessionlId);
67 }
LnnIpcGetAllOnlineNodeInfo(const char * pkgName,void ** info,uint32_t infoTypeLen,int32_t * infoNum)68 int32_t LnnIpcGetAllOnlineNodeInfo(const char *pkgName, void **info, uint32_t infoTypeLen, int32_t *infoNum)
69 {
70 return GetSoftbusServerStubTestInterface()->LnnIpcGetAllOnlineNodeInfo(pkgName, info, infoTypeLen, infoNum);
71 }
LnnIpcGetLocalDeviceInfo(const char * pkgName,void * info,uint32_t infoTypeLen)72 int32_t LnnIpcGetLocalDeviceInfo(const char *pkgName, void *info, uint32_t infoTypeLen)
73 {
74 return GetSoftbusServerStubTestInterface()->LnnIpcGetLocalDeviceInfo(pkgName, info, infoTypeLen);
75 }
LnnIpcGetNodeKeyInfo(const char * pkgName,const char * networkId,int32_t key,unsigned char * buf,uint32_t len)76 int32_t LnnIpcGetNodeKeyInfo(const char *pkgName, const char *networkId, int32_t key,
77 unsigned char *buf, uint32_t len)
78 {
79 return GetSoftbusServerStubTestInterface()->LnnIpcGetNodeKeyInfo(pkgName, networkId, key, buf, len);
80 }
CheckDynamicPermission()81 int32_t CheckDynamicPermission()
82 {
83 return GetSoftbusServerStubTestInterface()->CheckDynamicPermission();
84 }
LnnIpcActiveMetaNode(const MetaNodeConfigInfo * info,char * metaNodeId)85 int32_t LnnIpcActiveMetaNode(const MetaNodeConfigInfo *info, char *metaNodeId)
86 {
87 return GetSoftbusServerStubTestInterface()->LnnIpcActiveMetaNode(info, metaNodeId);
88 }
LnnIpcDeactiveMetaNode(const char * metaNodeId)89 int32_t LnnIpcDeactiveMetaNode(const char *metaNodeId)
90 {
91 return GetSoftbusServerStubTestInterface()->LnnIpcDeactiveMetaNode(metaNodeId);
92 }
LnnIpcGetAllMetaNodeInfo(MetaNodeInfo * infos,int32_t * infoNum)93 int32_t LnnIpcGetAllMetaNodeInfo(MetaNodeInfo *infos, int32_t *infoNum)
94 {
95 return GetSoftbusServerStubTestInterface()->LnnIpcGetAllMetaNodeInfo(infos, infoNum);
96 }
TransReleaseUdpResources(int32_t channelId)97 int32_t TransReleaseUdpResources(int32_t channelId)
98 {
99 return GetSoftbusServerStubTestInterface()->TransReleaseUdpResources(channelId);
100 }
CheckUidAndPid(const char * sessionName,pid_t callingUid,pid_t callingPid)101 bool CheckUidAndPid(const char *sessionName, pid_t callingUid, pid_t callingPid)
102 {
103 return GetSoftbusServerStubTestInterface()->CheckUidAndPid(sessionName, callingUid, callingPid);
104 }
105 }
106 }