• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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_SERVICE_MOCK_H
17 #define LNN_SERVICE_MOCK_H
18 
19 #include <gmock/gmock.h>
20 #include <mutex>
21 
22 #include "bus_center_event.h"
23 #include "bus_center_manager.h"
24 #include "disc_interface.h"
25 #include "lnn_async_callback_utils.h"
26 #include "lnn_connection_addr_utils.h"
27 #include "lnn_deviceinfo_to_profile.h"
28 #include "lnn_event_monitor_impl.h"
29 #include "lnn_feature_capability.h"
30 #include "lnn_heartbeat_strategy.h"
31 #include "lnn_ohos_account_adapter.h"
32 #include "lnn_settingdata_event_monitor.h"
33 #include "message_handler.h"
34 #include "softbus_adapter_crypto.h"
35 #include "softbus_bus_center.h"
36 #include "softbus_common.h"
37 #include "softbus_feature_config.h"
38 #include "softbus_wifi_api_adapter.h"
39 #include "wifi_direct_manager.h"
40 
41 namespace OHOS {
42 class LnnServiceInterface {
43 public:
LnnServiceInterface()44     LnnServiceInterface() {};
~LnnServiceInterface()45     virtual ~LnnServiceInterface() {};
46     virtual int32_t LnnInitBusCenterEvent(void) = 0;
47     virtual void LnnDeinitBusCenterEvent(void) = 0;
48     virtual int32_t LnnRegisterEventHandler(LnnEventType event, LnnEventHandler handler) = 0;
49     virtual void LnnNotifyJoinResult(ConnectionAddr *addr, const char *networkId, int32_t retCode) = 0;
50     virtual void LnnNotifyLeaveResult(const char *networkId, int32_t retCode) = 0;
51     virtual void LnnNotifyOnlineState(bool isOnline, NodeBasicInfo *info) = 0;
52     virtual void LnnNotifyBasicInfoChanged(NodeBasicInfo *info, NodeBasicInfoType type) = 0;
53     virtual void LnnNotifyWlanStateChangeEvent(void *state) = 0;
54     virtual void LnnNotifyBtStateChangeEvent(void *state) = 0;
55     virtual void LnnNotifyLnnRelationChanged(
56         const char *udid, ConnectionAddrType type, uint8_t relation, bool isJoin) = 0;
57     virtual void LnnNotifyMasterNodeChanged(bool isMaster, const char *masterNodeUdid, int32_t weight) = 0;
58     virtual void LnnUnregisterEventHandler(LnnEventType event, LnnEventHandler handler) = 0;
59     virtual int32_t LnnOfflineTimingByHeartbeat(const char *networkId, ConnectionAddrType addrType) = 0;
60     virtual uint32_t AuthGenRequestId(void) = 0;
61     virtual void AuthHandleLeaveLNN(AuthHandle authHandle) = 0;
62     virtual int32_t AuthGetDeviceUuid(int64_t authId, char *uuid, uint16_t size) = 0;
63     virtual int32_t SoftBusGetWifiDeviceConfig(SoftBusWifiDevConf *configList, uint32_t *num) = 0;
64     virtual int32_t SoftBusConnectToDevice(const SoftBusWifiDevConf *wifiConfig) = 0;
65     virtual int32_t SoftBusDisconnectDevice(void) = 0;
66     virtual ConnectionAddrType LnnDiscTypeToConnAddrType(DiscoveryType type) = 0;
67     virtual void UpdateProfile(const NodeInfo *info) = 0;
68     virtual bool IsFeatureSupport(uint64_t feature, FeatureCapability capaBit) = 0;
69     virtual int32_t LnnStartHbByTypeAndStrategy(
70         LnnHeartbeatType hbType, LnnHeartbeatStrategyType strategy, bool isRelay) = 0;
71     virtual bool SoftBusIsWifiTripleMode(void) = 0;
72     virtual SoftBusBand SoftBusGetLinkBand(void) = 0;
73     virtual SoftBusWifiDetailState SoftBusGetWifiState(void) = 0;
74     virtual bool SoftBusHasWifiDirectCapability(void) = 0;
75     virtual char *SoftBusGetWifiInterfaceCoexistCap(void) = 0;
76     virtual int32_t LnnAsyncCallbackHelper(SoftBusLooper *looper, LnnAsyncCallbackFunc callback, void *para);
77     virtual int32_t LnnAsyncCallbackDelayHelper(
78         SoftBusLooper *looper, LnnAsyncCallbackFunc callback, void *para, uint64_t delayMillis);
79     virtual int32_t SoftBusGenerateRandomArray(unsigned char *randStr, uint32_t len) = 0;
80     virtual int32_t LnnGetDeviceDisplayName(
81         const char *nickName, const char *defaultName, char *deviceName, uint32_t len);
82     virtual int32_t LnnGetUnifiedDeviceName(char *unifiedName, uint32_t len);
83     virtual int32_t LnnGetUnifiedDefaultDeviceName(char *unifiedDefaultName, uint32_t len);
84     virtual int32_t GetCurrentAccount(int64_t *account);
85     virtual int32_t LnnSetLocalUnifiedName(const char *unifiedName);
86     virtual void LnnNotifyLocalNetworkIdChanged(void);
87     virtual int32_t LnnGetSettingNickName(
88         const char *defaultName, const char *unifiedName, char *nickName, uint32_t len);
89     virtual int32_t SoftbusGetConfig(ConfigType type, unsigned char *val, uint32_t len) = 0;
90     virtual int32_t LnnSubscribeAccountBootEvent(AccountEventHandle handle) = 0;
91     virtual void LnnNotifyOnlineNetType(const char *networkId, ConnectionAddrType addrType) = 0;
92     virtual void LnnNotifyDeviceInfoChanged(SoftBusDeviceInfoState state) = 0;
93     virtual bool IsHeartbeatEnable(void) = 0;
94     virtual struct WifiDirectManager *GetWifiDirectManager(void) = 0;
95 };
96 
97 class LnnServicetInterfaceMock : public LnnServiceInterface {
98 public:
99     LnnServicetInterfaceMock();
100     ~LnnServicetInterfaceMock() override;
101     MOCK_METHOD0(LnnInitBusCenterEvent, int32_t(void));
102     MOCK_METHOD0(LnnDeinitBusCenterEvent, void(void));
103     MOCK_METHOD2(LnnRegisterEventHandler, int32_t(LnnEventType, LnnEventHandler));
104     MOCK_METHOD3(LnnNotifyJoinResult, void(ConnectionAddr *, const char *, int32_t));
105     MOCK_METHOD2(LnnNotifyLeaveResult, void(const char *, int32_t));
106     MOCK_METHOD2(LnnNotifyOnlineState, void(bool, NodeBasicInfo *));
107     MOCK_METHOD2(LnnNotifyBasicInfoChanged, void(NodeBasicInfo *, NodeBasicInfoType));
108     MOCK_METHOD1(LnnNotifyWlanStateChangeEvent, void(void *));
109     MOCK_METHOD1(LnnNotifyBtStateChangeEvent, void(void *));
110     MOCK_METHOD4(LnnNotifyLnnRelationChanged, void(const char *, ConnectionAddrType, uint8_t, bool));
111     MOCK_METHOD3(LnnNotifyMasterNodeChanged, void(bool, const char *, int32_t));
112     MOCK_METHOD2(LnnUnregisterEventHandler, void(LnnEventType, LnnEventHandler));
113     MOCK_METHOD2(LnnOfflineTimingByHeartbeat, int32_t(const char *, ConnectionAddrType));
114     MOCK_METHOD0(AuthGenRequestId, uint32_t());
115     MOCK_METHOD1(AuthHandleLeaveLNN, void(AuthHandle));
116     MOCK_METHOD3(AuthGetDeviceUuid, int32_t(int64_t, char *, uint16_t));
117     MOCK_METHOD2(SoftBusGetWifiDeviceConfig, int32_t(SoftBusWifiDevConf *, uint32_t *));
118     MOCK_METHOD1(SoftBusConnectToDevice, int32_t(const SoftBusWifiDevConf *));
119     MOCK_METHOD0(SoftBusDisconnectDevice, int32_t());
120     MOCK_METHOD1(LnnDiscTypeToConnAddrType, ConnectionAddrType(DiscoveryType));
121     MOCK_METHOD1(UpdateProfile, void(const NodeInfo *));
122     MOCK_METHOD2(IsFeatureSupport, bool(uint64_t, FeatureCapability));
123     MOCK_METHOD3(LnnStartHbByTypeAndStrategy, int32_t(LnnHeartbeatType, LnnHeartbeatStrategyType, bool));
124     MOCK_METHOD0(SoftBusIsWifiTripleMode, bool());
125     MOCK_METHOD0(SoftBusGetLinkBand, SoftBusBand());
126     MOCK_METHOD0(SoftBusGetWifiState, SoftBusWifiDetailState());
127     MOCK_METHOD0(SoftBusHasWifiDirectCapability, bool());
128     MOCK_METHOD0(SoftBusGetWifiInterfaceCoexistCap, char *());
129     MOCK_METHOD3(LnnAsyncCallbackHelper, int32_t(SoftBusLooper *, LnnAsyncCallbackFunc, void *));
130     MOCK_METHOD4(LnnAsyncCallbackDelayHelper, int32_t(SoftBusLooper *, LnnAsyncCallbackFunc, void *, uint64_t));
131     MOCK_METHOD2(SoftBusGenerateRandomArray, int32_t(unsigned char *, uint32_t));
132     MOCK_METHOD4(LnnGetDeviceDisplayName, int32_t(const char *, const char *, char *, uint32_t));
133     MOCK_METHOD2(LnnGetUnifiedDeviceName, int32_t(char *, uint32_t));
134     MOCK_METHOD2(LnnGetUnifiedDefaultDeviceName, int32_t(char *, uint32_t));
135     MOCK_METHOD1(GetCurrentAccount, int32_t(int64_t *));
136     MOCK_METHOD1(LnnSetLocalUnifiedName, int32_t(const char *));
137     MOCK_METHOD0(LnnNotifyLocalNetworkIdChanged, void());
138     MOCK_METHOD4(LnnGetSettingNickName, int32_t(const char *, const char *, char *, uint32_t));
139     MOCK_METHOD3(SoftbusGetConfig, int32_t(ConfigType, unsigned char *, uint32_t));
140     MOCK_METHOD1(LnnSubscribeAccountBootEvent, int32_t(AccountEventHandle handle));
141     MOCK_METHOD2(LnnNotifyOnlineNetType, void(const char *, ConnectionAddrType));
142     MOCK_METHOD1(LnnNotifyDeviceInfoChanged, void(SoftBusDeviceInfoState));
143     MOCK_METHOD0(IsHeartbeatEnable, bool());
144     MOCK_METHOD0(GetWifiDirectManager, struct WifiDirectManager *(void));
145     static int32_t ActionOfLnnRegisterEventHandler(LnnEventType event, LnnEventHandler handler);
146     static inline std::map<LnnEventType, LnnEventHandler> g_lnnEventHandlers;
147 };
148 } // namespace OHOS
149 #endif // LNN_SERVICE_MOCK_H