• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "lnn_service_mock.h"
17 #include "softbus_error_code.h"
18 
19 using namespace testing;
20 using namespace testing::ext;
21 
22 namespace OHOS {
23 void *g_serviceInterface;
LnnServicetInterfaceMock()24 LnnServicetInterfaceMock::LnnServicetInterfaceMock()
25 {
26     g_serviceInterface = reinterpret_cast<void *>(this);
27 }
28 
~LnnServicetInterfaceMock()29 LnnServicetInterfaceMock::~LnnServicetInterfaceMock()
30 {
31     g_serviceInterface = nullptr;
32 }
33 
GetServiceInterface()34 static LnnServiceInterface *GetServiceInterface()
35 {
36     return reinterpret_cast<LnnServiceInterface *>(g_serviceInterface);
37 }
38 
39 extern "C" {
LnnInitBusCenterEvent(void)40 int32_t LnnInitBusCenterEvent(void)
41 {
42     return GetServiceInterface()->LnnInitBusCenterEvent();
43 }
44 
LnnDeinitBusCenterEvent(void)45 void LnnDeinitBusCenterEvent(void)
46 {
47     return GetServiceInterface()->LnnDeinitBusCenterEvent();
48 }
49 
LnnRegisterEventHandler(LnnEventType event,LnnEventHandler handler)50 int32_t LnnRegisterEventHandler(LnnEventType event, LnnEventHandler handler)
51 {
52     return GetServiceInterface()->LnnRegisterEventHandler(event, handler);
53 }
54 
LnnNotifyJoinResult(ConnectionAddr * addr,const char * networkId,int32_t retCode)55 void LnnNotifyJoinResult(ConnectionAddr *addr, const char *networkId, int32_t retCode)
56 {
57     return GetServiceInterface()->LnnNotifyJoinResult(addr, networkId, retCode);
58 }
59 
LnnNotifyLeaveResult(const char * networkId,int32_t retCode)60 void LnnNotifyLeaveResult(const char *networkId, int32_t retCode)
61 {
62     return GetServiceInterface()->LnnNotifyLeaveResult(networkId, retCode);
63 }
64 
LnnNotifyOnlineState(bool isOnline,NodeBasicInfo * info)65 void LnnNotifyOnlineState(bool isOnline, NodeBasicInfo *info)
66 {
67     return GetServiceInterface()->LnnNotifyOnlineState(isOnline, info);
68 }
69 
LnnNotifyBasicInfoChanged(NodeBasicInfo * info,NodeBasicInfoType type)70 void LnnNotifyBasicInfoChanged(NodeBasicInfo *info, NodeBasicInfoType type)
71 {
72     return GetServiceInterface()->LnnNotifyBasicInfoChanged(info, type);
73 }
74 
LnnNotifyWlanStateChangeEvent(SoftBusWifiState state)75 void LnnNotifyWlanStateChangeEvent(SoftBusWifiState state)
76 {
77     return GetServiceInterface()->LnnNotifyWlanStateChangeEvent(state);
78 }
79 
LnnNotifyBtStateChangeEvent(void * state)80 void LnnNotifyBtStateChangeEvent(void *state)
81 {
82     return GetServiceInterface()->LnnNotifyBtStateChangeEvent(state);
83 }
84 
LnnNotifyLnnRelationChanged(const char * udid,ConnectionAddrType type,uint8_t relation,bool isJoin)85 void LnnNotifyLnnRelationChanged(const char *udid, ConnectionAddrType type,
86     uint8_t relation, bool isJoin)
87 {
88     return GetServiceInterface()->LnnNotifyLnnRelationChanged(udid, type, relation, isJoin);
89 }
90 
LnnNotifyMasterNodeChanged(bool isMaster,const char * masterNodeUdid,int32_t weight)91 void LnnNotifyMasterNodeChanged(bool isMaster, const char* masterNodeUdid, int32_t weight)
92 {
93     return GetServiceInterface()->LnnNotifyMasterNodeChanged(isMaster, masterNodeUdid, weight);
94 }
95 
LnnInitGetDeviceName(LnnDeviceNameHandler handler)96 int32_t LnnInitGetDeviceName(LnnDeviceNameHandler handler)
97 {
98     return GetServiceInterface()->LnnInitGetDeviceName(handler);
99 }
100 
RegisterNameMonitor(void)101 void RegisterNameMonitor(void)
102 {
103     return GetServiceInterface()->RegisterNameMonitor();
104 }
105 
LnnUnregisterEventHandler(LnnEventType event,LnnEventHandler handler)106 void LnnUnregisterEventHandler(LnnEventType event, LnnEventHandler handler)
107 {
108     return GetServiceInterface()->LnnUnregisterEventHandler(event, handler);
109 }
110 
LnnOfflineTimingByHeartbeat(const char * networkId,ConnectionAddrType addrType)111 int32_t LnnOfflineTimingByHeartbeat(const char *networkId, ConnectionAddrType addrType)
112 {
113     return GetServiceInterface()->LnnOfflineTimingByHeartbeat(networkId, addrType);
114 }
115 
ActionOfLnnRegisterEventHandler(LnnEventType event,LnnEventHandler handler)116 int32_t LnnServicetInterfaceMock::ActionOfLnnRegisterEventHandler(LnnEventType event, LnnEventHandler handler)
117 {
118     if (event == LNN_EVENT_TYPE_MAX || handler == NULL) {
119         return SOFTBUS_INVALID_PARAM;
120     }
121     g_lnnEventHandlers.emplace(event, handler);
122     return SOFTBUS_OK;
123 }
124 
ActionOfLnnInitGetDeviceName(LnnDeviceNameHandler handler)125 int32_t LnnServicetInterfaceMock::ActionOfLnnInitGetDeviceName(LnnDeviceNameHandler handler)
126 {
127     if (handler == NULL) {
128         return SOFTBUS_INVALID_PARAM;
129     }
130     g_deviceNameHandler = handler;
131     return SOFTBUS_OK;
132 }
133 }
134 }