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 #ifndef SOFTBUS_SERVER_STUB_TEST_MOCK_H
17 #define SOFTBUS_SERVER_STUB_TEST_MOCK_H
18 
19 #include "access_token.h"
20 #include "accesstoken_kit.h"
21 #include "ipc_object_stub.h"
22 #include "lnn_bus_center_ipc.h"
23 #include "message_option.h"
24 #include "message_parcel.h"
25 #include "softbus_app_info.h"
26 #include "softbus_permission.h"
27 #include "softbus_trans_def.h"
28 #include "trans_channel_manager.h"
29 #include <gmock/gmock.h>
30 
31 namespace OHOS {
32 class SoftbusServerStubTestInterface {
33 public:
SoftbusServerStubTestInterface()34     SoftbusServerStubTestInterface() {};
~SoftbusServerStubTestInterface()35     virtual ~SoftbusServerStubTestInterface() {};
36     virtual int32_t CheckTransPermission(pid_t callingUid, pid_t callingPid, const char *pkgName,
37         const char *sessionName, uint32_t actions) = 0;
38     virtual int32_t CheckTransSecLevel(const char *mySessionName, const char *peerSessionName) = 0;
39     virtual int32_t TransGetNameByChanId(const TransInfo *info, char *pkgName, char *sessionName,
40         uint16_t pkgLen, uint16_t sessionNameLen) = 0;
41     virtual int32_t TransGetAppInfoByChanId(int32_t channelId, int32_t channelType, AppInfo *appInfo) = 0;
42     virtual int32_t TransGetAndComparePid(pid_t pid, int32_t channelId, int32_t channelType) = 0;
43     virtual int32_t TransGetAndComparePidBySession(pid_t pid, const char *sessionName, int32_t sessionlId) = 0;
44     virtual int32_t LnnIpcGetAllOnlineNodeInfo(const char *pkgName, void **info,
45         uint32_t infoTypeLen, int32_t *infoNum) = 0;
46     virtual int32_t LnnIpcGetLocalDeviceInfo(const char *pkgName, void *info, uint32_t infoTypeLen) = 0;
47     virtual int32_t LnnIpcGetNodeKeyInfo(const char *pkgName, const char *networkId, int32_t key,
48         unsigned char *buf, uint32_t len) = 0;
49     virtual int32_t CheckDynamicPermission() = 0;
50     virtual int32_t LnnIpcActiveMetaNode(const MetaNodeConfigInfo *info, char *metaNodeId) = 0;
51     virtual int32_t LnnIpcDeactiveMetaNode(const char *metaNodeId) = 0;
52     virtual int32_t LnnIpcGetAllMetaNodeInfo(MetaNodeInfo *infos, int32_t *infoNum) = 0;
53     virtual int32_t TransReleaseUdpResources(int32_t channelId) = 0;
54     virtual bool CheckUidAndPid(const char *sessionName, pid_t callingUid, pid_t callingPid) = 0;
55 };
56 class SoftbusServerStubTestInterfaceMock : public SoftbusServerStubTestInterface {
57 public:
58     SoftbusServerStubTestInterfaceMock();
59     ~SoftbusServerStubTestInterfaceMock() override;
60     MOCK_METHOD5(CheckTransPermission, int32_t (pid_t callingUid, pid_t callingPid, const char *pkgName,
61         const char *sessionName, uint32_t actions));
62     MOCK_METHOD2(CheckTransSecLevel, int32_t (const char *mySessionName, const char *peerSessionName));
63     MOCK_METHOD5(TransGetNameByChanId, int32_t (const TransInfo *info, char *pkgName, char *sessionName,
64         uint16_t pkgLen, uint16_t sessionNameLen));
65     MOCK_METHOD3(TransGetAppInfoByChanId, int32_t (int32_t channelId, int32_t channelType, AppInfo *appInfo));
66     MOCK_METHOD3(TransGetAndComparePid, int32_t (pid_t pid, int32_t channelId, int32_t channelType));
67     MOCK_METHOD3(TransGetAndComparePidBySession, int32_t (pid_t pid, const char *sessionName, int32_t sessionlId));
68     MOCK_METHOD4(LnnIpcGetAllOnlineNodeInfo, int32_t (const char *pkgName, void **info,
69         uint32_t infoTypeLen, int32_t *infoNum));
70     MOCK_METHOD3(LnnIpcGetLocalDeviceInfo, int32_t (const char *pkgName, void *info, uint32_t infoTypeLen));
71     MOCK_METHOD5(LnnIpcGetNodeKeyInfo, int32_t (const char *pkgName, const char *networkId, int32_t key,
72         unsigned char *buf, uint32_t len));
73     MOCK_METHOD0(CheckDynamicPermission, int32_t ());
74     MOCK_METHOD2(LnnIpcActiveMetaNode, int32_t (const MetaNodeConfigInfo *info, char *metaNodeId));
75     MOCK_METHOD1(LnnIpcDeactiveMetaNode, int32_t (const char *metaNodeId));
76     MOCK_METHOD2(LnnIpcGetAllMetaNodeInfo, int32_t (MetaNodeInfo *infos, int32_t *infoNum));
77     MOCK_METHOD1(TransReleaseUdpResources, int32_t (int32_t channelId));
78     MOCK_METHOD3(CheckUidAndPid, bool (const char *sessionName, pid_t callingUid, pid_t callingPid));
79 };
80 }
81 
82 #endif