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