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 <securec.h>
17
18 #include "lnn_decision_db_deps_mock.h"
19 #include "softbus_common.h"
20 #include "softbus_error_code.h"
21
22 using namespace testing;
23 using namespace testing::ext;
24 namespace OHOS {
25 void *g_decisionDbDepsInterface;
DecisionDbDepsInterfaceMock()26 DecisionDbDepsInterfaceMock::DecisionDbDepsInterfaceMock()
27 {
28 g_decisionDbDepsInterface = reinterpret_cast<void *>(this);
29 }
30
~DecisionDbDepsInterfaceMock()31 DecisionDbDepsInterfaceMock::~DecisionDbDepsInterfaceMock()
32 {
33 g_decisionDbDepsInterface = nullptr;
34 }
35
GetDecisionDbDepsInterface()36 static DecisionDbDepsInterfaceMock *GetDecisionDbDepsInterface()
37 {
38 return reinterpret_cast<DecisionDbDepsInterfaceMock *>(g_decisionDbDepsInterface);
39 }
40
DecisionDbAsyncCallbackHelper(SoftBusLooper * looper,LnnAsyncCallbackFunc callback,void * para)41 int32_t DecisionDbDepsInterfaceMock::DecisionDbAsyncCallbackHelper(
42 SoftBusLooper *looper, LnnAsyncCallbackFunc callback, void *para)
43 {
44 if (callback != nullptr) {
45 callback(para);
46 return SOFTBUS_OK;
47 }
48 return SOFTBUS_INVALID_PARAM;
49 }
50
51 extern "C" {
LnnGenerateKeyByHuks(struct HksBlob * keyAlias)52 int32_t LnnGenerateKeyByHuks(struct HksBlob *keyAlias)
53 {
54 return GetDecisionDbDepsInterface()->LnnGenerateKeyByHuks(keyAlias);
55 }
56
LnnDeleteKeyByHuks(struct HksBlob * keyAlias)57 int32_t LnnDeleteKeyByHuks(struct HksBlob *keyAlias)
58 {
59 return GetDecisionDbDepsInterface()->LnnDeleteKeyByHuks(keyAlias);
60 }
61
LnnEncryptDataByHuks(const struct HksBlob * keyAlias,const struct HksBlob * inData,struct HksBlob * outData)62 int32_t LnnEncryptDataByHuks(const struct HksBlob *keyAlias, const struct HksBlob *inData, struct HksBlob *outData)
63 {
64 return GetDecisionDbDepsInterface()->LnnEncryptDataByHuks(keyAlias, inData, outData);
65 }
66
LnnDecryptDataByHuks(const struct HksBlob * keyAlias,const struct HksBlob * inData,struct HksBlob * outData)67 int32_t LnnDecryptDataByHuks(const struct HksBlob *keyAlias, const struct HksBlob *inData, struct HksBlob *outData)
68 {
69 return GetDecisionDbDepsInterface()->LnnDecryptDataByHuks(keyAlias, inData, outData);
70 }
71
LnnGenerateRandomByHuks(uint8_t * randomKey,uint32_t len)72 int32_t LnnGenerateRandomByHuks(uint8_t *randomKey, uint32_t len)
73 {
74 return GetDecisionDbDepsInterface()->LnnGenerateRandomByHuks(randomKey, len);
75 }
76
OpenDatabase(DbContext ** ctx)77 int32_t OpenDatabase(DbContext **ctx)
78 {
79 return GetDecisionDbDepsInterface()->OpenDatabase(ctx);
80 }
81
CloseDatabase(DbContext * ctx)82 int32_t CloseDatabase(DbContext *ctx)
83 {
84 return GetDecisionDbDepsInterface()->CloseDatabase(ctx);
85 }
86
CreateTable(DbContext * ctx,TableNameID id)87 int32_t CreateTable(DbContext *ctx, TableNameID id)
88 {
89 return GetDecisionDbDepsInterface()->CreateTable(ctx, id);
90 }
91
CheckTableExist(DbContext * ctx,TableNameID id,bool * isExist)92 int32_t CheckTableExist(DbContext *ctx, TableNameID id, bool *isExist)
93 {
94 return GetDecisionDbDepsInterface()->CheckTableExist(ctx, id, isExist);
95 }
96
RemoveRecordByKey(DbContext * ctx,TableNameID id,uint8_t * data)97 int32_t RemoveRecordByKey(DbContext *ctx, TableNameID id, uint8_t *data)
98 {
99 return GetDecisionDbDepsInterface()->RemoveRecordByKey(ctx, id, data);
100 }
101
GetRecordNumByKey(DbContext * ctx,TableNameID id,uint8_t * data)102 int32_t GetRecordNumByKey(DbContext *ctx, TableNameID id, uint8_t *data)
103 {
104 return GetDecisionDbDepsInterface()->GetRecordNumByKey(ctx, id, data);
105 }
106
EncryptedDb(DbContext * ctx,const uint8_t * password,uint32_t len)107 int32_t EncryptedDb(DbContext *ctx, const uint8_t *password, uint32_t len)
108 {
109 return GetDecisionDbDepsInterface()->EncryptedDb(ctx, password, len);
110 }
111
UpdateDbPassword(DbContext * ctx,const uint8_t * password,uint32_t len)112 int32_t UpdateDbPassword(DbContext *ctx, const uint8_t *password, uint32_t len)
113 {
114 return GetDecisionDbDepsInterface()->UpdateDbPassword(ctx, password, len);
115 }
116
QueryRecordByKey(DbContext * ctx,TableNameID id,uint8_t * data,uint8_t ** replyInfo,int32_t infoNum)117 int32_t QueryRecordByKey(DbContext *ctx, TableNameID id, uint8_t *data, uint8_t **replyInfo, int32_t infoNum)
118 {
119 return GetDecisionDbDepsInterface()->QueryRecordByKey(ctx, id, data, replyInfo, infoNum);
120 }
121
LnnGetFullStoragePath(LnnFileId id,char * path,uint32_t len)122 int32_t LnnGetFullStoragePath(LnnFileId id, char *path, uint32_t len)
123 {
124 return GetDecisionDbDepsInterface()->LnnGetFullStoragePath(id, path, len);
125 }
126
SoftBusReadFullFile(const char * fileName,char * readBuf,uint32_t maxLen)127 int32_t SoftBusReadFullFile(const char *fileName, char *readBuf, uint32_t maxLen)
128 {
129 return GetDecisionDbDepsInterface()->SoftBusReadFullFile(fileName, readBuf, maxLen);
130 }
131
SoftBusWriteFile(const char * fileName,const char * writeBuf,uint32_t len)132 int32_t SoftBusWriteFile(const char *fileName, const char *writeBuf, uint32_t len)
133 {
134 return GetDecisionDbDepsInterface()->SoftBusWriteFile(fileName, writeBuf, len);
135 }
136
SoftBusAccessFile(const char * pathName,int32_t mode)137 int32_t SoftBusAccessFile(const char *pathName, int32_t mode)
138 {
139 return GetDecisionDbDepsInterface()->SoftBusAccessFile(pathName, mode);
140 }
141
LnnAsyncCallbackHelper(SoftBusLooper * looper,LnnAsyncCallbackFunc callback,void * para)142 int32_t LnnAsyncCallbackHelper(SoftBusLooper *looper, LnnAsyncCallbackFunc callback, void *para)
143 {
144 return GetDecisionDbDepsInterface()->LnnAsyncCallbackHelper(looper, callback, para);
145 }
146
LnnGetLocalByteInfo(InfoKey key,uint8_t * info,uint32_t len)147 int32_t LnnGetLocalByteInfo(InfoKey key, uint8_t *info, uint32_t len)
148 {
149 return GetDecisionDbDepsInterface()->LnnGetLocalByteInfo(key, info, len);
150 }
151
ConvertBytesToHexString(char * outBuf,uint32_t outBufLen,const unsigned char * inBuf,uint32_t inLen)152 int32_t ConvertBytesToHexString(char *outBuf, uint32_t outBufLen, const unsigned char *inBuf, uint32_t inLen)
153 {
154 return GetDecisionDbDepsInterface()->ConvertBytesToHexString(outBuf, outBufLen, inBuf, inLen);
155 }
156
LnnNotifyNetworkStateChanged(SoftBusNetworkState state)157 void LnnNotifyNetworkStateChanged(SoftBusNetworkState state)
158 {
159 return GetDecisionDbDepsInterface()->LnnNotifyNetworkStateChanged(state);
160 }
161
AuthHasTrustedRelation(void)162 TrustedReturnType AuthHasTrustedRelation(void)
163 {
164 return GetDecisionDbDepsInterface()->AuthHasTrustedRelation();
165 }
166
IsEnableSoftBusHeartbeat(void)167 bool IsEnableSoftBusHeartbeat(void)
168 {
169 return GetDecisionDbDepsInterface()->IsEnableSoftBusHeartbeat();
170 }
171
LnnNotifyHBRepeat(void)172 void LnnNotifyHBRepeat(void)
173 {
174 return GetDecisionDbDepsInterface()->LnnNotifyHBRepeat();
175 }
176
LnnHbClearRecvList(void)177 void LnnHbClearRecvList(void)
178 {
179 return GetDecisionDbDepsInterface()->LnnHbClearRecvList();
180 }
181
LnnConvertHbTypeToId(LnnHeartbeatType type)182 int32_t LnnConvertHbTypeToId(LnnHeartbeatType type)
183 {
184 return GetDecisionDbDepsInterface()->LnnConvertHbTypeToId(type);
185 }
186
LnnVisitHbTypeSet(VisitHbTypeCb callback,LnnHeartbeatType * typeSet,void * data)187 bool LnnVisitHbTypeSet(VisitHbTypeCb callback, LnnHeartbeatType *typeSet, void *data)
188 {
189 return GetDecisionDbDepsInterface()->LnnVisitHbTypeSet(callback, typeSet, data);
190 }
191
LnnCeEncryptDataByHuks(const struct HksBlob * keyAlias,const struct HksBlob * inData,struct HksBlob * outData)192 int32_t LnnCeEncryptDataByHuks(const struct HksBlob *keyAlias, const struct HksBlob *inData, struct HksBlob *outData)
193 {
194 return GetDecisionDbDepsInterface()->LnnCeEncryptDataByHuks(keyAlias, inData, outData);
195 }
196
LnnCeDecryptDataByHuks(const struct HksBlob * keyAlias,const struct HksBlob * inData,struct HksBlob * outData)197 int32_t LnnCeDecryptDataByHuks(const struct HksBlob *keyAlias, const struct HksBlob *inData, struct HksBlob *outData)
198 {
199 return GetDecisionDbDepsInterface()->LnnCeDecryptDataByHuks(keyAlias, inData, outData);
200 }
201
202 } // extern "C"
203 } // namespace OHOS
204