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 }; 59 class SoftbusServerStubTestInterfaceMock : public SoftbusServerStubTestInterface { 60 public: 61 SoftbusServerStubTestInterfaceMock(); 62 ~SoftbusServerStubTestInterfaceMock() override; 63 MOCK_METHOD5(CheckTransPermission, int32_t (pid_t callingUid, pid_t callingPid, const char *pkgName, 64 const char *sessionName, uint32_t actions)); 65 MOCK_METHOD2(CheckTransSecLevel, int32_t (const char *mySessionName, const char *peerSessionName)); 66 MOCK_METHOD5(TransGetNameByChanId, int32_t (const TransInfo *info, char *pkgName, char *sessionName, 67 uint16_t pkgLen, uint16_t sessionNameLen)); 68 MOCK_METHOD3(TransGetAppInfoByChanId, int32_t (int32_t channelId, int32_t channelType, AppInfo *appInfo)); 69 MOCK_METHOD3(TransGetAndComparePid, int32_t (pid_t pid, int32_t channelId, int32_t channelType)); 70 MOCK_METHOD3(TransGetAndComparePidBySession, int32_t (pid_t pid, const char *sessionName, int32_t sessionlId)); 71 MOCK_METHOD4(LnnIpcGetAllOnlineNodeInfo, int32_t (const char *pkgName, void **info, 72 uint32_t infoTypeLen, int32_t *infoNum)); 73 MOCK_METHOD3(LnnIpcGetLocalDeviceInfo, int32_t (const char *pkgName, void *info, uint32_t infoTypeLen)); 74 MOCK_METHOD5(LnnIpcGetNodeKeyInfo, int32_t (const char *pkgName, const char *networkId, int32_t key, 75 unsigned char *buf, uint32_t len)); 76 MOCK_METHOD1(SoftBusCheckDynamicPermission, int32_t (uint64_t tokenId)); 77 MOCK_METHOD2(LnnIpcActiveMetaNode, int32_t (const MetaNodeConfigInfo *info, char *metaNodeId)); 78 MOCK_METHOD1(LnnIpcDeactiveMetaNode, int32_t (const char *metaNodeId)); 79 MOCK_METHOD2(LnnIpcGetAllMetaNodeInfo, int32_t (MetaNodeInfo *infos, int32_t *infoNum)); 80 MOCK_METHOD1(TransReleaseUdpResources, int32_t (int32_t channelId)); 81 MOCK_METHOD3(CheckUidAndPid, bool (const char *sessionName, pid_t callingUid, pid_t callingPid)); 82 MOCK_METHOD1(SoftBusCheckDmsServerPermission, int32_t (uint64_t tokenId)); 83 }; 84 } 85 86 #endif