• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 LNN_CONNECTION_FSM_MOCK_H
17 #define LNN_CONNECTION_FSM_MOCK_H
18 
19 #include <gmock/gmock.h>
20 #include <mutex>
21 
22 #include "auth_deviceprofile.h"
23 #include "auth_interface.h"
24 #include "auth_manager.h"
25 #include "auth_request.h"
26 #include "auth_user_common_key.h"
27 #include "bus_center_event.h"
28 #include "bus_center_manager.h"
29 #include "lnn_cipherkey_manager_struct.h"
30 #include "lnn_connection_addr_utils.h"
31 #include "lnn_deviceinfo_to_profile.h"
32 #include "lnn_distributed_net_ledger.h"
33 #include "lnn_feature_capability.h"
34 #include "lnn_heartbeat_ctrl.h"
35 #include "lnn_heartbeat_utils.h"
36 #include "lnn_network_manager.h"
37 #include "softbus_adapter_bt_common.h"
38 
39 namespace OHOS {
40 class LnnConnFsmInterface {
41 public:
LnnConnFsmInterface()42     LnnConnFsmInterface() {};
~LnnConnFsmInterface()43     virtual ~LnnConnFsmInterface() {};
44     virtual void LnnNotifyDeviceVerified(const char *udid) = 0;
45     virtual int32_t SoftBusGetBtState(void) = 0;
46     virtual int32_t LnnGenerateBtMacHash(const char *btMac, int32_t brMacLen, char *brMacHash, int32_t hashLen) = 0;
47     virtual void DeleteFromProfile(const char *udid) = 0;
48     virtual void SendDeviceStateToMlps(void *para) = 0;
49     virtual int32_t LnnUpdateNetworkId(const NodeInfo *newInfo) = 0;
50     virtual int32_t AuthGetServerSide(int64_t authId, bool *isServer) = 0;
51     virtual int32_t LnnRetrieveDeviceInfo(const char *udid, NodeInfo *deviceInfo) = 0;
52     virtual int32_t LnnRetrieveDeviceInfoByNetworkId(const char *networkId, NodeInfo *info) = 0;
53     virtual int32_t AuthRestoreAuthManager(const char *udidHash, const AuthConnInfo *connInfo, uint32_t requestId,
54         NodeInfo *nodeInfo, int64_t *authId) = 0;
55     virtual int32_t LnnLoadLocalBroadcastCipherKey(void) = 0;
56     virtual int32_t LnnGetLocalBroadcastCipherKey(BroadcastCipherKey *broadcastKey) = 0;
57     virtual int32_t LnnSetLocalByteInfo(InfoKey key, const uint8_t *info, uint32_t len) = 0;
58     virtual int32_t LnnInsertLinkFinderInfo(const char *networkId) = 0;
59     virtual int32_t LnnUpdateGroupType(const NodeInfo *info) = 0;
60     virtual void LnnNotifySingleOffLineEvent(const ConnectionAddr *addr, NodeBasicInfo *basicInfo) = 0;
61     virtual void LnnStopOfflineTimingByHeartbeat(const char *networkId, ConnectionAddrType addrType) = 0;
62     virtual int32_t LnnGetLocalNodeInfoSafe(NodeInfo *info) = 0;
63     virtual void SetLpKeepAliveState(void *para) = 0;
64     virtual const char *LnnPrintConnectionAddr(const ConnectionAddr *addr) = 0;
65     virtual bool LnnConvertAddrToAuthConnInfo(const ConnectionAddr *addr, AuthConnInfo *connInfo) = 0;
66     virtual DiscoveryType LnnConvAddrTypeToDiscType(ConnectionAddrType type) = 0;
67     virtual void LnnNotifyOOBEStateChangeEvent(SoftBusOOBEState state) = 0;
68     virtual void LnnNotifyStateForSession(char *udid, int32_t retCode) = 0;
69     virtual void AuthRemoveAuthManagerByAuthHandle(AuthHandle authHandle) = 0;
70     virtual void LnnNotifyHichainProofException(
71         const char *proofInfo, uint32_t proofLen, uint16_t deviceTypeId, int32_t errCode) = 0;
72     virtual void LnnNotifyDeviceTrustedChange(int32_t type, const char *msg, uint32_t msgLen) = 0;
73     virtual int32_t GetAuthRequest(uint32_t requestId, AuthRequest *request) = 0;
74     virtual void UpdateDpSameAccount(
75         UpdateDpAclParams *aclParams, SessionKey sessionKey, bool isNeedUpdateDk, AclWriteState aclState) = 0;
76     virtual int32_t LnnGetAddrTypeByIfName(const char *ifName, ConnectionAddrType *type) = 0;
77     virtual bool LnnConvertAuthConnInfoToAddr(
78         ConnectionAddr *addr, const AuthConnInfo *connInfo, ConnectionAddrType hintType) = 0;
79     virtual int32_t LnnUpdateAccountInfo(const NodeInfo *info) = 0;
80     virtual int32_t LnnUpdateRemoteDeviceName(const NodeInfo *info) = 0;
81     virtual bool LnnIsSameConnectionAddr(const ConnectionAddr *addr1, const ConnectionAddr *addr2, bool isShort) = 0;
82     virtual void DelSessionKeyProfile(int32_t sessionKeyId) = 0;
83     virtual bool GetSessionKeyProfile(int32_t sessionKeyId, uint8_t *sessionKey, uint32_t *length) = 0;
84     virtual int32_t GetLatestSessionKey(
85         const SessionKeyList *list, AuthLinkType type, int32_t *index, SessionKey *key) = 0;
86     virtual void DelDupAuthManager(AuthManager *auth) = 0;
87     virtual void DelUserKeyByNetworkId(const char *networkId) = 0;
88     virtual void LnnNotifyAddRawEnhanceP2pEvent(LnnNotifyRawEnhanceP2pEvent *event) = 0;
89     virtual bool RawLinkNeedUpdateAuthManager(const char *uuid, bool isServer) = 0;
90     virtual AuthManager *GetAuthManagerByAuthId(int64_t authId) = 0;
91     virtual void LnnStopOfflineTimingBySleHb(const char *networkId, ConnectionAddrType addrType) = 0;
92     virtual int32_t LnnCleanTriggerSparkInfo(const char *udid, ConnectionAddrType addrType) = 0;
93     virtual void LnnSetWiFiIp(NodeInfo *info, const char *ip, int32_t ifnameIdx) = 0;
94 };
95 
96 class LnnConnFsmInterfaceMock : public LnnConnFsmInterface {
97 public:
98     LnnConnFsmInterfaceMock();
99     ~LnnConnFsmInterfaceMock() override;
100     MOCK_METHOD1(LnnNotifyDeviceVerified, void(const char *));
101     MOCK_METHOD0(SoftBusGetBtState, int32_t(void));
102     MOCK_METHOD4(LnnGenerateBtMacHash, int32_t(const char *, int32_t, char *, int32_t));
103     MOCK_METHOD1(DeleteFromProfile, void(const char *));
104     MOCK_METHOD1(SendDeviceStateToMlps, void(void *));
105     MOCK_METHOD1(LnnUpdateNetworkId, int32_t(const NodeInfo *));
106     MOCK_METHOD2(AuthGetServerSide, int32_t(int64_t, bool *));
107     MOCK_METHOD2(LnnRetrieveDeviceInfo, int32_t(const char *, NodeInfo *));
108     MOCK_METHOD2(LnnRetrieveDeviceInfoByNetworkId, int32_t(const char *, NodeInfo *));
109     MOCK_METHOD5(AuthRestoreAuthManager, int32_t(const char *, const AuthConnInfo *, uint32_t, NodeInfo *, int64_t *));
110     MOCK_METHOD0(LnnLoadLocalBroadcastCipherKey, int32_t(void));
111     MOCK_METHOD1(LnnGetLocalBroadcastCipherKey, int32_t(BroadcastCipherKey *));
112     MOCK_METHOD3(LnnSetLocalByteInfo, int32_t(InfoKey, const uint8_t *, uint32_t));
113     MOCK_METHOD1(LnnInsertLinkFinderInfo, int32_t(const char *));
114     MOCK_METHOD1(LnnUpdateGroupType, int32_t(const NodeInfo *));
115     MOCK_METHOD2(LnnNotifySingleOffLineEvent, void(const ConnectionAddr *, NodeBasicInfo *));
116     MOCK_METHOD2(LnnStopOfflineTimingByHeartbeat, void(const char *, ConnectionAddrType));
117     MOCK_METHOD1(LnnGetLocalNodeInfoSafe, int32_t(NodeInfo *));
118     MOCK_METHOD1(SetLpKeepAliveState, void(void *));
119     MOCK_METHOD1(LnnPrintConnectionAddr, const char *(const ConnectionAddr *));
120     MOCK_METHOD2(LnnConvertAddrToAuthConnInfo, bool(const ConnectionAddr *, AuthConnInfo *));
121     MOCK_METHOD1(LnnConvAddrTypeToDiscType, DiscoveryType(ConnectionAddrType));
122     MOCK_METHOD1(LnnNotifyOOBEStateChangeEvent, void(SoftBusOOBEState));
123     MOCK_METHOD4(LnnNotifyHichainProofException, void(const char *, uint32_t, uint16_t, int32_t));
124     MOCK_METHOD3(LnnNotifyDeviceTrustedChange, void(int32_t type, const char *msg, uint32_t msgLen));
125     MOCK_METHOD2(LnnNotifyStateForSession, void(char *, int32_t));
126     MOCK_METHOD1(AuthRemoveAuthManagerByAuthHandle, void(AuthHandle));
127     MOCK_METHOD2(GetAuthRequest, int32_t(uint32_t, AuthRequest *));
128     MOCK_METHOD4(UpdateDpSameAccount, void(UpdateDpAclParams *, SessionKey, bool, AclWriteState));
129     MOCK_METHOD2(LnnGetAddrTypeByIfName, int32_t(const char *, ConnectionAddrType *));
130     MOCK_METHOD3(LnnConvertAuthConnInfoToAddr, bool(ConnectionAddr *, const AuthConnInfo *, ConnectionAddrType));
131     MOCK_METHOD1(LnnUpdateAccountInfo, int32_t(const NodeInfo *));
132     MOCK_METHOD1(LnnUpdateRemoteDeviceName, int32_t(const NodeInfo *));
133     MOCK_METHOD3(LnnIsSameConnectionAddr, bool(const ConnectionAddr *, const ConnectionAddr *, bool));
134     MOCK_METHOD1(DelSessionKeyProfile, void(int32_t));
135     MOCK_METHOD3(GetSessionKeyProfile, bool(int32_t, uint8_t *, uint32_t *));
136     MOCK_METHOD4(GetLatestSessionKey, int32_t(const SessionKeyList *, AuthLinkType, int32_t *, SessionKey *));
137     MOCK_METHOD1(DelDupAuthManager, void(AuthManager *));
138     MOCK_METHOD1(DelUserKeyByNetworkId, void(const char *));
139     MOCK_METHOD1(LnnNotifyAddRawEnhanceP2pEvent, void(LnnNotifyRawEnhanceP2pEvent *));
140     MOCK_METHOD2(RawLinkNeedUpdateAuthManager, bool(const char *, bool));
141     MOCK_METHOD1(GetAuthManagerByAuthId, AuthManager *(int64_t));
142     MOCK_METHOD2(LnnStopOfflineTimingBySleHb, void(const char *, ConnectionAddrType));
143     MOCK_METHOD2(LnnCleanTriggerSparkInfo, int32_t(const char *, ConnectionAddrType));
144     MOCK_METHOD3(LnnSetWiFiIp, void(NodeInfo *, const char *, int32_t));
145 };
146 } // namespace OHOS
147 #endif // LNN_CONNECTION_FSM_MOCK_H
148