• 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_hichain_mock.h"
17 #include "auth_interface.h"
18 #include "softbus_adapter_log.h"
19 #include "softbus_adapter_mem.h"
20 #include "softbus_log.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 const int32_t GRUOP_NUM1 = 10;
27 const int32_t GRUOP_NUM2 = 12;
28 const int32_t GRUOP_NUM3 = 100;
29 void *g_hichainInterface;
30 
LnnHichainInterfaceMock()31 LnnHichainInterfaceMock::LnnHichainInterfaceMock()
32 {
33     SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "construction");
34     g_hichainInterface = reinterpret_cast<void *>(this);
35 }
36 
~LnnHichainInterfaceMock()37 LnnHichainInterfaceMock::~LnnHichainInterfaceMock()
38 {
39     SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "delete");
40     g_hichainInterface = nullptr;
41 }
42 
GetHichainInterface()43 static LnnHichainInterface *GetHichainInterface()
44 {
45     return reinterpret_cast<LnnHichainInterfaceMock *>(g_hichainInterface);
46 }
47 
48 extern "C" {
InitDeviceAuthService(void)49 int32_t InitDeviceAuthService(void)
50 {
51     return GetHichainInterface()->InitDeviceAuthService();
52 }
53 
DestroyDeviceAuthService(void)54 void DestroyDeviceAuthService(void)
55 {
56     return GetHichainInterface()->DestroyDeviceAuthService();
57 }
58 
GetGaInstance(void)59 const GroupAuthManager *GetGaInstance(void)
60 {
61     return GetHichainInterface()->GetGaInstance();
62 }
63 
GetGmInstance(void)64 const DeviceGroupManager *GetGmInstance(void)
65 {
66     SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "GetGmInstance");
67     return GetHichainInterface()->GetGmInstance();
68 }
69 }
70 
ActionOfProcessData(int64_t authSeq,const uint8_t * data,uint32_t len,const DeviceAuthCallback * gaCallback)71 int32_t LnnHichainInterfaceMock::ActionOfProcessData(
72     int64_t authSeq, const uint8_t *data, uint32_t len, const DeviceAuthCallback *gaCallback)
73 {
74     (void)authSeq;
75     (void)data;
76     (void)len;
77     g_devAuthCb.onTransmit = gaCallback->onTransmit;
78     g_devAuthCb.onSessionKeyReturned = gaCallback->onSessionKeyReturned;
79     g_devAuthCb.onFinish = gaCallback->onFinish;
80     g_devAuthCb.onError = gaCallback->onError;
81     g_devAuthCb.onRequest = gaCallback->onRequest;
82     return HC_SUCCESS;
83 }
84 
InvokeAuthDevice(int32_t osAccountId,int64_t authReqId,const char * authParams,const DeviceAuthCallback * gaCallback)85 int32_t LnnHichainInterfaceMock::InvokeAuthDevice(int32_t osAccountId, int64_t authReqId, const char *authParams,
86     const DeviceAuthCallback *gaCallback)
87 {
88     return HC_SUCCESS;
89 }
90 
AuthDeviceConnSend(int32_t osAccountId,int64_t authReqId,const char * authParams,const DeviceAuthCallback * gaCallback)91 int32_t LnnHichainInterfaceMock::AuthDeviceConnSend(int32_t osAccountId, int64_t authReqId, const char *authParams,
92     const DeviceAuthCallback *gaCallback)
93 {
94     SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "AuthDeviceConnSend");
95     (void)SoftBusCondSignal(&LnnHichainInterfaceMock::cond);
96     return HC_SUCCESS;
97 }
98 
InvokeDataChangeListener(const char * appId,const DataChangeListener * listener)99 int32_t LnnHichainInterfaceMock::InvokeDataChangeListener(const char *appId, const DataChangeListener *listener)
100 {
101     if (appId == nullptr || listener == nullptr) {
102         return SOFTBUS_INVALID_PARAM;
103     }
104     LnnHichainInterfaceMock::g_datachangelistener.emplace(appId, listener);
105     return SOFTBUS_OK;
106 }
107 
InvokeGetJoinedGroups1(int32_t osAccountId,const char * appId,int groupType,char ** returnGroupVec,uint32_t * groupNum)108 int32_t LnnHichainInterfaceMock::InvokeGetJoinedGroups1(int32_t osAccountId, const char *appId, int groupType,
109     char **returnGroupVec, uint32_t *groupNum)
110 {
111     (void)osAccountId;
112     (void)appId;
113     (void)groupType;
114     *groupNum = 1;
115 
116     if (groupType == AUTH_IDENTICAL_ACCOUNT_GROUP) {
117         *groupNum = GRUOP_NUM1;
118     }
119     if (groupType == AUTH_PEER_TO_PEER_GROUP) {
120         *groupNum = GRUOP_NUM2;
121     }
122     *returnGroupVec = reinterpret_cast<char *>(SoftBusCalloc(*groupNum));
123     if (*returnGroupVec == NULL) {
124         return HC_ERR_INVALID_PARAMS;
125     }
126     return HC_SUCCESS;
127 }
128 
InvokeGetJoinedGroups2(int32_t osAccountId,const char * appId,int groupType,char ** returnGroupVec,uint32_t * groupNum)129 int32_t LnnHichainInterfaceMock::InvokeGetJoinedGroups2(int32_t osAccountId, const char *appId, int groupType,
130     char **returnGroupVec, uint32_t *groupNum)
131 {
132     (void)osAccountId;
133     (void)appId;
134     (void)groupType;
135     (void)returnGroupVec;
136     *groupNum = GRUOP_NUM3;
137 
138     return HC_ERR_INVALID_PARAMS;
139 }
ActionofunRegDataChangeListener(const char * appId)140 int32_t LnnHichainInterfaceMock::ActionofunRegDataChangeListener(const char *appId)
141 {
142     (void)appId;
143     LnnHichainInterfaceMock::g_datachangelistener.clear();
144     return SOFTBUS_OK;
145 }
146 } // namespace OHOS