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(SoftBusLooper *looper,
42 LnnAsyncCallbackFunc callback, void *para)
43 {
44 if (callback != NULL) {
45 callback(para);
46 return SOFTBUS_OK;
47 }
48 return SOFTBUS_ERR;
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
LnnGenerateCeKeyByHuks(struct HksBlob * keyAlias)62 int32_t LnnGenerateCeKeyByHuks(struct HksBlob *keyAlias)
63 {
64 return GetDecisionDbDepsInterface()->LnnGenerateCeKeyByHuks(keyAlias);
65 }
66
LnnDeleteCeKeyByHuks(struct HksBlob * keyAlias)67 int32_t LnnDeleteCeKeyByHuks(struct HksBlob *keyAlias)
68 {
69 return GetDecisionDbDepsInterface()->LnnDeleteCeKeyByHuks(keyAlias);
70 }
71
LnnEncryptDataByHuks(const struct HksBlob * keyAlias,const struct HksBlob * inData,struct HksBlob * outData)72 int32_t LnnEncryptDataByHuks(const struct HksBlob *keyAlias,
73 const struct HksBlob *inData, struct HksBlob *outData)
74 {
75 return GetDecisionDbDepsInterface()->LnnEncryptDataByHuks(keyAlias, inData, outData);
76 }
77
LnnDecryptDataByHuks(const struct HksBlob * keyAlias,const struct HksBlob * inData,struct HksBlob * outData)78 int32_t LnnDecryptDataByHuks(const struct HksBlob *keyAlias,
79 const struct HksBlob *inData, struct HksBlob *outData)
80 {
81 return GetDecisionDbDepsInterface()->LnnDecryptDataByHuks(keyAlias, inData, outData);
82 }
83
LnnGenerateRandomByHuks(uint8_t * randomKey,uint32_t len)84 int32_t LnnGenerateRandomByHuks(uint8_t *randomKey, uint32_t len)
85 {
86 return GetDecisionDbDepsInterface()->LnnGenerateRandomByHuks(randomKey, len);
87 }
88
OpenDatabase(DbContext ** ctx)89 int32_t OpenDatabase(DbContext **ctx)
90 {
91 return GetDecisionDbDepsInterface()->OpenDatabase(ctx);
92 }
93
CloseDatabase(DbContext * ctx)94 int32_t CloseDatabase(DbContext *ctx)
95 {
96 return GetDecisionDbDepsInterface()->CloseDatabase(ctx);
97 }
98
CreateTable(DbContext * ctx,TableNameID id)99 int32_t CreateTable(DbContext *ctx, TableNameID id)
100 {
101 return GetDecisionDbDepsInterface()->CreateTable(ctx, id);
102 }
103
CheckTableExist(DbContext * ctx,TableNameID id,bool * isExist)104 int32_t CheckTableExist(DbContext *ctx, TableNameID id, bool *isExist)
105 {
106 return GetDecisionDbDepsInterface()->CheckTableExist(ctx, id, isExist);
107 }
108
RemoveRecordByKey(DbContext * ctx,TableNameID id,uint8_t * data)109 int32_t RemoveRecordByKey(DbContext *ctx, TableNameID id, uint8_t *data)
110 {
111 return GetDecisionDbDepsInterface()->RemoveRecordByKey(ctx, id, data);
112 }
113
GetRecordNumByKey(DbContext * ctx,TableNameID id,uint8_t * data)114 int32_t GetRecordNumByKey(DbContext *ctx, TableNameID id, uint8_t *data)
115 {
116 return GetDecisionDbDepsInterface()->GetRecordNumByKey(ctx, id, data);
117 }
118
EncryptedDb(DbContext * ctx,const uint8_t * password,uint32_t len)119 int32_t EncryptedDb(DbContext *ctx, const uint8_t *password, uint32_t len)
120 {
121 return GetDecisionDbDepsInterface()->EncryptedDb(ctx, password, len);
122 }
123
UpdateDbPassword(DbContext * ctx,const uint8_t * password,uint32_t len)124 int32_t UpdateDbPassword(DbContext *ctx, const uint8_t *password, uint32_t len)
125 {
126 return GetDecisionDbDepsInterface()->UpdateDbPassword(ctx, password, len);
127 }
128
QueryRecordByKey(DbContext * ctx,TableNameID id,uint8_t * data,uint8_t ** replyInfo,int infoNum)129 int32_t QueryRecordByKey(DbContext *ctx, TableNameID id, uint8_t *data, uint8_t **replyInfo, int infoNum)
130 {
131 return GetDecisionDbDepsInterface()->QueryRecordByKey(ctx, id, data, replyInfo, infoNum);
132 }
133
LnnGetFullStoragePath(LnnFileId id,char * path,uint32_t len)134 int32_t LnnGetFullStoragePath(LnnFileId id, char *path, uint32_t len)
135 {
136 return GetDecisionDbDepsInterface()->LnnGetFullStoragePath(id, path, len);
137 }
138
SoftBusReadFullFile(const char * fileName,char * readBuf,uint32_t maxLen)139 int32_t SoftBusReadFullFile(const char *fileName, char *readBuf, uint32_t maxLen)
140 {
141 return GetDecisionDbDepsInterface()->SoftBusReadFullFile(fileName, readBuf, maxLen);
142 }
143
SoftBusWriteFile(const char * fileName,const char * writeBuf,uint32_t len)144 int32_t SoftBusWriteFile(const char *fileName, const char *writeBuf, uint32_t len)
145 {
146 return GetDecisionDbDepsInterface()->SoftBusWriteFile(fileName, writeBuf, len);
147 }
148
SoftBusAccessFile(const char * pathName,int32_t mode)149 int32_t SoftBusAccessFile(const char *pathName, int32_t mode)
150 {
151 return GetDecisionDbDepsInterface()->SoftBusAccessFile(pathName, mode);
152 }
153
LnnAsyncCallbackHelper(SoftBusLooper * looper,LnnAsyncCallbackFunc callback,void * para)154 int32_t LnnAsyncCallbackHelper(SoftBusLooper *looper, LnnAsyncCallbackFunc callback, void *para)
155 {
156 return GetDecisionDbDepsInterface()->LnnAsyncCallbackHelper(looper, callback, para);
157 }
158
LnnGetLocalByteInfo(InfoKey key,uint8_t * info,uint32_t len)159 int32_t LnnGetLocalByteInfo(InfoKey key, uint8_t *info, uint32_t len)
160 {
161 return GetDecisionDbDepsInterface()->LnnGetLocalByteInfo(key, info, len);
162 }
163
ConvertBytesToHexString(char * outBuf,uint32_t outBufLen,const unsigned char * inBuf,uint32_t inLen)164 int32_t ConvertBytesToHexString(char *outBuf, uint32_t outBufLen,
165 const unsigned char *inBuf, uint32_t inLen)
166 {
167 return GetDecisionDbDepsInterface()->ConvertBytesToHexString(outBuf, outBufLen, inBuf, inLen);
168 }
169
LnnNotifyNetworkStateChanged(SoftBusNetworkState state)170 void LnnNotifyNetworkStateChanged(SoftBusNetworkState state)
171 {
172 return GetDecisionDbDepsInterface()->LnnNotifyNetworkStateChanged(state);
173 }
174
AuthHasTrustedRelation(void)175 TrustedReturnType AuthHasTrustedRelation(void)
176 {
177 return GetDecisionDbDepsInterface()->AuthHasTrustedRelation();
178 }
179
IsEnableSoftBusHeartbeat(void)180 bool IsEnableSoftBusHeartbeat(void)
181 {
182 return GetDecisionDbDepsInterface()->IsEnableSoftBusHeartbeat();
183 }
184
LnnNotifyHBRepeat(void)185 void LnnNotifyHBRepeat(void)
186 {
187 return GetDecisionDbDepsInterface()->LnnNotifyHBRepeat();
188 }
189
LnnHbClearRecvList(void)190 void LnnHbClearRecvList(void)
191 {
192 return GetDecisionDbDepsInterface()->LnnHbClearRecvList();
193 }
194
LnnConvertHbTypeToId(LnnHeartbeatType type)195 int32_t LnnConvertHbTypeToId(LnnHeartbeatType type)
196 {
197 return GetDecisionDbDepsInterface()->LnnConvertHbTypeToId(type);
198 }
199
LnnVisitHbTypeSet(VisitHbTypeCb callback,LnnHeartbeatType * typeSet,void * data)200 bool LnnVisitHbTypeSet(VisitHbTypeCb callback, LnnHeartbeatType *typeSet, void *data)
201 {
202 return GetDecisionDbDepsInterface()->LnnVisitHbTypeSet(callback, typeSet, data);
203 }
204
LnnCeEncryptDataByHuks(const struct HksBlob * keyAlias,const struct HksBlob * inData,struct HksBlob * outData)205 int32_t LnnCeEncryptDataByHuks(const struct HksBlob *keyAlias,
206 const struct HksBlob *inData, struct HksBlob *outData)
207 {
208 return GetDecisionDbDepsInterface()->LnnCeEncryptDataByHuks(keyAlias, inData, outData);
209 }
210
LnnCeDecryptDataByHuks(const struct HksBlob * keyAlias,const struct HksBlob * inData,struct HksBlob * outData)211 int32_t LnnCeDecryptDataByHuks(const struct HksBlob *keyAlias,
212 const struct HksBlob *inData, struct HksBlob *outData)
213 {
214 return GetDecisionDbDepsInterface()->LnnCeDecryptDataByHuks(keyAlias, inData, outData);
215 }
216
217 } // extern "C"
218 } // namespace OHOS
219