• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include "auth_interface_mock.h"
17 
18 using namespace testing;
19 using namespace testing::ext;
20 
21 namespace OHOS {
22 void *g_authInterfaceTest;
AuthOtherInterfaceMock()23 AuthOtherInterfaceMock::AuthOtherInterfaceMock()
24 {
25     g_authInterfaceTest = reinterpret_cast<void *>(this);
26 }
27 
~AuthOtherInterfaceMock()28 AuthOtherInterfaceMock::~AuthOtherInterfaceMock()
29 {
30     g_authInterfaceTest = nullptr;
31 }
32 
GetAuthOtherInterfaceMock()33 static AuthOtherInterfaceMock *GetAuthOtherInterfaceMock()
34 {
35     return reinterpret_cast<AuthOtherInterfaceMock *>(g_authInterfaceTest);
36 }
37 
ActionOfLnnGetRemoteNodeInfoByKey(const char * key,NodeInfo * info)38 int32_t AuthOtherInterfaceMock::ActionOfLnnGetRemoteNodeInfoByKey(const char *key, NodeInfo *info)
39 {
40     (void)key;
41     if (info == nullptr) {
42         GTEST_LOG_(ERROR) << "invalid param";
43         return SOFTBUS_INVALID_PARAM;
44     }
45     (void)memset_s(info, sizeof(NodeInfo), 0, sizeof(NodeInfo));
46     info->feature = BIT_SUPPORT_NEGOTIATION_AUTH;
47     return SOFTBUS_OK;
48 }
49 
ActionOfLnnGetRemoteNodeInfoById(const char * id,IdCategory type,NodeInfo * info)50 int32_t AuthOtherInterfaceMock::ActionOfLnnGetRemoteNodeInfoById(const char *id, IdCategory type, NodeInfo *info)
51 {
52     (void)id;
53     (void)type;
54     if (info == nullptr) {
55         GTEST_LOG_(ERROR) << "invalid param";
56         return SOFTBUS_INVALID_PARAM;
57     }
58     (void)memset_s(info, sizeof(NodeInfo), 0, sizeof(NodeInfo));
59     info->feature = BIT_SUPPORT_BR_DUP_BLE;
60     return SOFTBUS_OK;
61 }
62 
63 extern "C" {
RegHichainSaStatusListener(void)64 int32_t RegHichainSaStatusListener(void)
65 {
66     return GetAuthOtherInterfaceMock()->RegHichainSaStatusListener();
67 }
68 
CustomizedSecurityProtocolInit(void)69 int32_t CustomizedSecurityProtocolInit(void)
70 {
71     return GetAuthOtherInterfaceMock()->CustomizedSecurityProtocolInit();
72 }
73 
LnnGetTrustedDevInfoFromDb(char ** udidArray,uint32_t * num)74 int32_t LnnGetTrustedDevInfoFromDb(char **udidArray, uint32_t *num)
75 {
76     return GetAuthOtherInterfaceMock()->LnnGetTrustedDevInfoFromDb(udidArray, num);
77 }
78 
IsSameAccountGroupDevice(void)79 bool IsSameAccountGroupDevice(void)
80 {
81     return GetAuthOtherInterfaceMock()->IsSameAccountGroupDevice();
82 }
83 
LnnIsDefaultOhosAccount()84 bool LnnIsDefaultOhosAccount()
85 {
86     return GetAuthOtherInterfaceMock()->LnnIsDefaultOhosAccount();
87 }
88 
LnnGetLocalByteInfo(InfoKey key,uint8_t * info,uint32_t len)89 int32_t LnnGetLocalByteInfo(InfoKey key, uint8_t *info, uint32_t len)
90 {
91     return GetAuthOtherInterfaceMock()->LnnGetLocalByteInfo(key, info, len);
92 }
93 
IsPotentialTrustedDevice(TrustedRelationIdType idType,const char * deviceId,bool isPrecise,bool isPointToPoint)94 bool IsPotentialTrustedDevice(TrustedRelationIdType idType, const char *deviceId, bool isPrecise, bool isPointToPoint)
95 {
96     return GetAuthOtherInterfaceMock()->IsPotentialTrustedDevice(idType, deviceId, isPrecise, isPointToPoint);
97 }
98 
AuthFindLatestNormalizeKey(const char * udidHash,AuthDeviceKeyInfo * deviceKey,bool clearOldKey)99 int32_t AuthFindLatestNormalizeKey(const char *udidHash, AuthDeviceKeyInfo *deviceKey, bool clearOldKey)
100 {
101     return GetAuthOtherInterfaceMock()->AuthFindLatestNormalizeKey(udidHash, deviceKey, clearOldKey);
102 }
103 
IsCloudSyncEnabled(void)104 bool IsCloudSyncEnabled(void)
105 {
106     return GetAuthOtherInterfaceMock()->IsCloudSyncEnabled();
107 }
108 
IsFeatureSupport(uint64_t feature,FeatureCapability capaBit)109 bool IsFeatureSupport(uint64_t feature, FeatureCapability capaBit)
110 {
111     return GetAuthOtherInterfaceMock()->IsFeatureSupport(feature, capaBit);
112 }
113 
SoftBusGenerateStrHash(const unsigned char * str,uint32_t len,unsigned char * hash)114 int32_t SoftBusGenerateStrHash(const unsigned char *str, uint32_t len, unsigned char *hash)
115 {
116     return GetAuthOtherInterfaceMock()->SoftBusGenerateStrHash(str, len, hash);
117 }
118 
LnnGetRemoteNodeInfoByKey(const char * key,NodeInfo * info)119 int32_t LnnGetRemoteNodeInfoByKey(const char *key, NodeInfo *info)
120 {
121     return GetAuthOtherInterfaceMock()->LnnGetRemoteNodeInfoByKey(key, info);
122 }
123 
LnnGetNetworkIdByUdidHash(const uint8_t * udidHash,uint32_t udidHashLen,char * buf,uint32_t len,bool needOnline)124 int32_t LnnGetNetworkIdByUdidHash(
125     const uint8_t *udidHash, uint32_t udidHashLen, char *buf, uint32_t len, bool needOnline)
126 {
127     return GetAuthOtherInterfaceMock()->LnnGetNetworkIdByUdidHash(udidHash, udidHashLen, buf, len, needOnline);
128 }
129 
LnnGetRemoteNodeInfoById(const char * id,IdCategory type,NodeInfo * info)130 int32_t LnnGetRemoteNodeInfoById(const char *id, IdCategory type, NodeInfo *info)
131 {
132     return GetAuthOtherInterfaceMock()->LnnGetRemoteNodeInfoById(id, type, info);
133 }
134 
ConvertBytesToHexString(char * outBuf,uint32_t outBufLen,const unsigned char * inBuf,uint32_t inLen)135 int32_t ConvertBytesToHexString(char *outBuf, uint32_t outBufLen, const unsigned char *inBuf,
136     uint32_t inLen)
137 {
138     return GetAuthOtherInterfaceMock()->ConvertBytesToHexString(outBuf, outBufLen, inBuf, inLen);
139 }
140 
LnnRetrieveDeviceInfoByNetworkId(const char * networkId,NodeInfo * info)141 int32_t LnnRetrieveDeviceInfoByNetworkId(const char *networkId, NodeInfo *info)
142 {
143     return GetAuthOtherInterfaceMock()->LnnRetrieveDeviceInfoByNetworkId(networkId, info);
144 }
145 
SoftbusGetConfig(ConfigType type,unsigned char * val,uint32_t len)146 int32_t SoftbusGetConfig(ConfigType type, unsigned char *val, uint32_t len)
147 {
148     return GetAuthOtherInterfaceMock()->SoftbusGetConfig(type, val, len);
149 }
150 
AuthDeviceInit(const AuthTransCallback * callback)151 int32_t AuthDeviceInit(const AuthTransCallback *callback)
152 {
153     return GetAuthOtherInterfaceMock()->AuthDeviceInit(callback);
154 }
155 
AuthMetaInit(const AuthTransCallback * callback)156 int32_t AuthMetaInit(const AuthTransCallback *callback)
157 {
158     return GetAuthOtherInterfaceMock()->AuthMetaInit(callback);
159 }
160 
AuthFindDeviceKey(const char * udidHash,int32_t keyType,AuthDeviceKeyInfo * deviceKey)161 int32_t AuthFindDeviceKey(const char *udidHash, int32_t keyType, AuthDeviceKeyInfo *deviceKey)
162 {
163     return GetAuthOtherInterfaceMock()->AuthFindDeviceKey(udidHash, keyType, deviceKey);
164 }
165 
GetAuthManagerByAuthId(int64_t authId)166 AuthManager *GetAuthManagerByAuthId(int64_t authId)
167 {
168     return GetAuthOtherInterfaceMock()->GetAuthManagerByAuthId(authId);
169 }
170 }
171 } // namespace OHOS
172