1 /* 2 * Copyright (c) 2022 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 23 #include "bus_center_event.h" 24 #include "softbus_common.h" 25 #include "softbus_bus_center.h" 26 #include "lnn_settingdata_event_monitor.h" 27 28 namespace OHOS { 29 class LnnServiceInterface { 30 public: LnnServiceInterface()31 LnnServiceInterface() {}; ~LnnServiceInterface()32 virtual ~LnnServiceInterface() {}; 33 virtual int32_t LnnInitBusCenterEvent(void) = 0; 34 virtual void LnnDeinitBusCenterEvent(void) = 0; 35 virtual int32_t LnnRegisterEventHandler(LnnEventType event, LnnEventHandler handler) = 0; 36 virtual void LnnNotifyJoinResult(ConnectionAddr *addr, 37 const char *networkId, int32_t retCode) = 0; 38 virtual void LnnNotifyLeaveResult(const char *networkId, int32_t retCode) = 0; 39 virtual void LnnNotifyOnlineState(bool isOnline, NodeBasicInfo *info) = 0; 40 virtual void LnnNotifyBasicInfoChanged(NodeBasicInfo *info, NodeBasicInfoType type) = 0; 41 virtual void LnnNotifyWlanStateChangeEvent(SoftBusWifiState state) = 0; 42 virtual void LnnNotifyBtStateChangeEvent(void *state) = 0; 43 virtual void LnnNotifyLnnRelationChanged(const char *udid, ConnectionAddrType type, 44 uint8_t relation, bool isJoin) = 0; 45 virtual void LnnNotifyMasterNodeChanged(bool isMaster, const char* masterNodeUdid, 46 int32_t weight) = 0; 47 virtual int32_t LnnInitGetDeviceName(LnnDeviceNameHandler handler) = 0; 48 virtual void RegisterNameMonitor(void) = 0; 49 virtual void LnnUnregisterEventHandler(LnnEventType event, LnnEventHandler handler) = 0; 50 virtual int32_t LnnOfflineTimingByHeartbeat(const char *networkId, ConnectionAddrType addrType) = 0; 51 }; 52 53 class LnnServicetInterfaceMock : public LnnServiceInterface { 54 public: 55 LnnServicetInterfaceMock(); 56 ~LnnServicetInterfaceMock() override; 57 MOCK_METHOD0(LnnInitBusCenterEvent, int32_t (void)); 58 MOCK_METHOD0(LnnDeinitBusCenterEvent, void (void)); 59 MOCK_METHOD2(LnnRegisterEventHandler, int32_t (LnnEventType, LnnEventHandler)); 60 MOCK_METHOD3(LnnNotifyJoinResult, void (ConnectionAddr *, const char *, int32_t)); 61 MOCK_METHOD2(LnnNotifyLeaveResult, void (const char *, int32_t)); 62 MOCK_METHOD2(LnnNotifyOnlineState, void (bool, NodeBasicInfo *)); 63 MOCK_METHOD2(LnnNotifyBasicInfoChanged, void (NodeBasicInfo *, NodeBasicInfoType)); 64 MOCK_METHOD1(LnnNotifyWlanStateChangeEvent, void (SoftBusWifiState)); 65 MOCK_METHOD1(LnnNotifyBtStateChangeEvent, void (void *)); 66 MOCK_METHOD4(LnnNotifyLnnRelationChanged, void (const char *, ConnectionAddrType, uint8_t, bool)); 67 MOCK_METHOD3(LnnNotifyMasterNodeChanged, void (bool, const char*, int32_t)); 68 MOCK_METHOD1(LnnInitGetDeviceName, int32_t (LnnDeviceNameHandler)); 69 MOCK_METHOD0(RegisterNameMonitor, void (void)); 70 MOCK_METHOD2(LnnUnregisterEventHandler, void (LnnEventType, LnnEventHandler)); 71 MOCK_METHOD2(LnnOfflineTimingByHeartbeat, int32_t (const char *, ConnectionAddrType)); 72 static int32_t ActionOfLnnRegisterEventHandler(LnnEventType event, LnnEventHandler handler); 73 static int32_t ActionOfLnnInitGetDeviceName(LnnDeviceNameHandler handler); 74 static inline std::map<LnnEventType, LnnEventHandler> g_lnnEventHandlers; 75 static inline LnnDeviceNameHandler g_deviceNameHandler; 76 }; 77 } // namespace OHOS 78 #endif // LNN_SERVICE_MOCK_H